diff --git a/interfaces/kits/ani/distributed_bundle_manager/ets/@ohos.bundle.distributedBundleManager.ets b/interfaces/kits/ani/distributed_bundle_manager/ets/@ohos.bundle.distributedBundleManager.ets index 19515e8dbda96b0fab82db8e421406183d4c39e8..35bb7e71a0c29f2a151fa02fa0cf2e142ef834c9 100644 --- a/interfaces/kits/ani/distributed_bundle_manager/ets/@ohos.bundle.distributedBundleManager.ets +++ b/interfaces/kits/ani/distributed_bundle_manager/ets/@ohos.bundle.distributedBundleManager.ets @@ -25,6 +25,39 @@ import { RemoteAbilityInfo as _RemoteAbilityInfo } from 'bundleManager.RemoteAbi export default namespace distributedBundleManager { loadLibrary("ani_distributed_bundle_manager.z"); + const ERROR_PARAM_CHECK_ERROR: int = 401; + const GET_REMOTE_ABILITY_INFO_MAX_SIZE: int = 10; + const ELEMENT_NAMES_SIZE_ERROR: string = "BusinessError 401: The number of ElementNames is greater than 10"; + const ELEMENT_NAME_ERROR: string = "BusinessError 401: Parameter error. The type of elementName must be object."; + + function createBusinessError(code: int, message: string) { + let err = new BusinessError(); + err.code = code; + err.name = 'Error'; + err.message = message; + return err; + } + + function checkElementName(elementName: ElementName) { + if (elementName.deviceId === undefined) { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, ELEMENT_NAME_ERROR); + } + } + + function checkElementNames(elementNames: Array) { + if (elementNames.length === 0) { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, ELEMENT_NAME_ERROR); + } + for (const elementName of elementNames) { + if (elementName.deviceId === undefined) { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, ELEMENT_NAME_ERROR); + } + } + if (elementNames.length > GET_REMOTE_ABILITY_INFO_MAX_SIZE) { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, ELEMENT_NAMES_SIZE_ERROR); + } + } + export native function getRemoteAbilityInfoNative(elementNames: Array, locale: string): RemoteAbilityInfo; export native function getRemoteAbilityInfosNative(elementNames: Array, locale: string): Array; @@ -35,6 +68,7 @@ export default namespace distributedBundleManager { } function getRemoteAbilityInfo(elementName: ElementName, callback: AsyncCallback): void { + checkElementName(elementName); let cb = (): RemoteAbilityInfo => { return distributedBundleManager.getRemoteAbilityInfoNative(elementName2Array(elementName), ''); }; @@ -48,6 +82,7 @@ export default namespace distributedBundleManager { } function getRemoteAbilityInfo(elementName: ElementName): Promise { + checkElementName(elementName); let p = new Promise((resolve: (remoteAbilityInfo: RemoteAbilityInfo) => void, reject: (error: BusinessError) => void) => { let cb = (): RemoteAbilityInfo => { return distributedBundleManager.getRemoteAbilityInfoNative(elementName2Array(elementName), ''); @@ -64,6 +99,7 @@ export default namespace distributedBundleManager { } function getRemoteAbilityInfo(elementNames: Array, callback: AsyncCallback>): void { + checkElementNames(elementNames); let cb = (): (Array) => { return distributedBundleManager.getRemoteAbilityInfosNative(elementNames, ''); }; @@ -77,6 +113,7 @@ export default namespace distributedBundleManager { } function getRemoteAbilityInfo(elementNames: Array): Promise> { + checkElementNames(elementNames); let p = new Promise>((resolve: (arrRemoteAbilityInfo: Array) => void, reject: (error: BusinessError) => void) => { let cb = (): (Array) => { return distributedBundleManager.getRemoteAbilityInfosNative(elementNames, ''); @@ -93,6 +130,7 @@ export default namespace distributedBundleManager { } function getRemoteAbilityInfo(elementName: ElementName, locale: string, callback: AsyncCallback): void { + checkElementName(elementName); let cb = (): RemoteAbilityInfo => { return distributedBundleManager.getRemoteAbilityInfoNative(elementName2Array(elementName), locale); }; @@ -106,6 +144,7 @@ export default namespace distributedBundleManager { } function getRemoteAbilityInfo(elementName: ElementName, locale: string): Promise { + checkElementName(elementName); let p = new Promise((resolve: (remoteAbilityInfo: RemoteAbilityInfo) => void, reject: (error: BusinessError) => void) => { let cb = (): RemoteAbilityInfo => { return distributedBundleManager.getRemoteAbilityInfoNative(elementName2Array(elementName), locale); @@ -122,6 +161,7 @@ export default namespace distributedBundleManager { } function getRemoteAbilityInfo(elementNames: Array, locale: string, callback: AsyncCallback>): void { + checkElementNames(elementNames); let cb = (): (Array) => { return distributedBundleManager.getRemoteAbilityInfosNative(elementNames, locale); }; @@ -135,6 +175,7 @@ export default namespace distributedBundleManager { } function getRemoteAbilityInfo(elementNames: Array, locale: string): Promise> { + checkElementNames(elementNames); let p = new Promise>((resolve: (arrRemoteAbilityInfo: Array) => void, reject: (error: BusinessError) => void) => { let cb = (): (Array) => { return distributedBundleManager.getRemoteAbilityInfosNative(elementNames, locale);