diff --git a/interfaces/kits/ani/bundle_installer/ets/@ohos.bundle.installerInner.ets b/interfaces/kits/ani/bundle_installer/ets/@ohos.bundle.installerInner.ets index fce7386b47bcb614eaed99ad33df870fbfff83d1..89256ca7d9c8286b0a663c14a1df9dc078827447 100644 --- a/interfaces/kits/ani/bundle_installer/ets/@ohos.bundle.installerInner.ets +++ b/interfaces/kits/ani/bundle_installer/ets/@ohos.bundle.installerInner.ets @@ -72,6 +72,54 @@ export class PluginParamInner implements installer.PluginParam { parameters?: Array; } +const SPECIFIED_DISTRIBUTION_TYPE_MAX_SIZE : int = 128; +const ADDITIONAL_INFO_MAX_SIZE: int = 3000; +const ERROR_PARAM_CHECK_ERROR: int = 401; +const SPECIFIED_DISTRIBUTION_TYPE_ERROR: string = "BusinessError 401: The size of specifiedDistributionType is greater than 128"; +const ADDITIONALINFO_ERROR: string = "BusinessError 401: The size of additionalInfo is greater than 3000"; +const PARAMETERTYPE_ERROR: string = "BusinessError 401: Parameter error. The type of parameters must be corresponding type."; + +function createBusinessError(code: int, message: string) { + let err = new BusinessError(); + err.code = code; + err.name = 'Error'; + err.message = message; + return err; +} + +function checkInstallParam(params: installer.InstallParam, needExtras: boolean): void { + + const hashParams = params.hashParams ?? new Array; + const moduleNameSet = new Set(); + for (const hashParam of hashParams) { + if (hashParam.moduleName === "" || hashParam.hashValue === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAMETERTYPE_ERROR); + } + if (moduleNameSet.has(hashParam.moduleName)) { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAMETERTYPE_ERROR); + } + moduleNameSet.add(hashParam.moduleName); + } + + const pgoParams = params.pgoParams ?? new Array; + for (const pgoParam of pgoParams) { + if (pgoParam.moduleName === "" || pgoParam.pgoFilePath === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAMETERTYPE_ERROR); + } + } + if (!needExtras) { + return; + } + let specifiedDistributionType: string = params.specifiedDistributionType ?? ""; + if (specifiedDistributionType.length > SPECIFIED_DISTRIBUTION_TYPE_MAX_SIZE) { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, SPECIFIED_DISTRIBUTION_TYPE_ERROR); + } + let additionalInfo: string = params.additionalInfo ?? ""; + if (additionalInfo.length > ADDITIONAL_INFO_MAX_SIZE) { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, ADDITIONALINFO_ERROR); + } +} + export class BundleInstallerInner implements installer.BundleInstaller { native installNative(hapFilePaths: Array, installParam: installer.InstallParam): void; native uninstallNative(bundleName: string, installParam: installer.InstallParam): void; @@ -88,6 +136,9 @@ export class BundleInstallerInner implements installer.BundleInstaller { native uninstallPluginNative(hostBundleName: string, pluginBundleName: string, pluginParam: installer.PluginParam): void; install(hapFilePaths: Array, installParam?: installer.InstallParam): Promise { + if (installParam) { + checkInstallParam(installParam, true); + } let emptyParam = new InstallParamInner(); let params = installParam ?? emptyParam; let p = new Promise((resolve: (v:undefined) => void, reject: (error: BusinessError) => void):void => { @@ -103,9 +154,9 @@ export class BundleInstallerInner implements installer.BundleInstaller { } install(hapFilePaths: Array, installParam: installer.InstallParam, callback: AsyncCallback): void { + checkInstallParam(installParam, true); let p = new Promise((resolve: (v:undefined) => void, reject: (error: BusinessError) => void):void => { let execFun = ():NullishType=>{ this.installNative(hapFilePaths, installParam); } - let p1 = taskpool.execute(execFun); p1.then(() => { callback(null, undefined); @@ -119,7 +170,6 @@ export class BundleInstallerInner implements installer.BundleInstaller { let emptyParam = new InstallParamInner(); let p = new Promise((resolve: (v:undefined) => void, reject: (error: BusinessError) => void):void => { let execFun = ():NullishType=>{ this.installNative(hapFilePaths, emptyParam); } - let p1 = taskpool.execute(execFun); p1.then(() => { callback(null, undefined); @@ -130,6 +180,9 @@ export class BundleInstallerInner implements installer.BundleInstaller { } uninstall(bundleName: string, installParam?: installer.InstallParam): Promise { + if (installParam) { + checkInstallParam(installParam, false); + } let emptyParam = new InstallParamInner(); let params = installParam ?? emptyParam; let p = new Promise((resolve: (v:undefined) => void, reject: (error: BusinessError) => void):void => { @@ -145,6 +198,7 @@ export class BundleInstallerInner implements installer.BundleInstaller { } uninstall(bundleName: string, installParam: installer.InstallParam, callback: AsyncCallback): void { + checkInstallParam(installParam, false); let p = new Promise((resolve: (v:undefined) => void, reject: (error: BusinessError) => void):void => { let execFun = ():NullishType=>{ this.uninstallNative(bundleName, installParam); } @@ -172,6 +226,9 @@ export class BundleInstallerInner implements installer.BundleInstaller { } recover(bundleName: string, installParam?: installer.InstallParam): Promise { + if (installParam) { + checkInstallParam(installParam, false); + } let emptyParam = new InstallParamInner(); let params = installParam ?? emptyParam; let p = new Promise((resolve: (v:undefined) => void, reject: (error: BusinessError) => void):void => { @@ -187,6 +244,7 @@ export class BundleInstallerInner implements installer.BundleInstaller { } recover(bundleName: string, installParam: installer.InstallParam, callback: AsyncCallback): void { + checkInstallParam(installParam, false); let p = new Promise((resolve: (v:undefined) => void, reject: (error: BusinessError) => void):void => { let execFun = ():NullishType=>{ this.recoverNative(bundleName, installParam); } @@ -238,6 +296,9 @@ export class BundleInstallerInner implements installer.BundleInstaller { } updateBundleForSelf(hapFilePaths: Array, installParam?: installer.InstallParam): Promise { + if (installParam) { + checkInstallParam(installParam, true); + } let emptyParam = new InstallParamInner(); let params = installParam ?? emptyParam; let p = new Promise((resolve: (v:undefined) => void, reject: (error: BusinessError) => void):void => { @@ -253,6 +314,7 @@ export class BundleInstallerInner implements installer.BundleInstaller { } updateBundleForSelf(hapFilePaths: Array, installParam: installer.InstallParam, callback: AsyncCallback): void { + checkInstallParam(installParam, true); let p = new Promise((resolve: (v:undefined) => void, reject: (error: BusinessError) => void):void => { let execFun = ():NullishType=>{ this.updateBundleForSelfNative(hapFilePaths, installParam); } let p1 = taskpool.execute(execFun); @@ -279,6 +341,9 @@ export class BundleInstallerInner implements installer.BundleInstaller { } uninstallUpdates(bundleName: string, installParam?: installer.InstallParam): Promise { + if (installParam) { + checkInstallParam(installParam, false); + } let emptyParam = new InstallParamInner(); let params = installParam ?? emptyParam; let p = new Promise((resolve: (v:undefined) => void, reject: (error: BusinessError) => void):void => { diff --git a/interfaces/kits/ani/bundle_manager/ets/@ohos.bundle.bundleManager.ets b/interfaces/kits/ani/bundle_manager/ets/@ohos.bundle.bundleManager.ets index 330b9f25cea404c7eb3bb3e872a52973df22f063..0291e78efb94ee21cffd1f097bec1ec3d8f2c1fc 100644 --- a/interfaces/kits/ani/bundle_manager/ets/@ohos.bundle.bundleManager.ets +++ b/interfaces/kits/ani/bundle_manager/ets/@ohos.bundle.bundleManager.ets @@ -32,6 +32,22 @@ namespace bundleManager { const EMPTY_VALUE: int = -500; const EMPTY_STRING: string = "ani empty string"; + const MAIN_APP_INDEX: int = 0; + const CLONE_APP_INDEX_MAX: int = 5; + const ERROR_INVALID_APPINDEX_CODE: int = 17700061; + const ERROR_INVALID_APPINDEX_MSG: string = "BusinessError 17700061: The specified app index is invalid."; + const ERROR_PARAM_CHECK_ERROR: int = 401; + const PARAM_BUNDLENAME_EMPTY_ERROR: string = "BusinessError 401: Parameter error. parameter bundleName is empty"; + const ERROR_ABILITY_NOT_EXIST: int = 17700003; + const GETABILITYINFO_ERROR_MSG: string = "BusinessError 17700003: The specified ability is not found."; + + function createBusinessError(code: int, message: string) { + let err = new BusinessError(); + err.code = code; + err.name = 'Error'; + err.message = message; + return err; + } enum BundleFlag { GET_BUNDLE_INFO_DEFAULT = 0x00000000, @@ -1280,6 +1296,9 @@ namespace bundleManager { } function cleanBundleCacheFiles(bundleName: string, appIndex: int): Promise { + if (appIndex < MAIN_APP_INDEX || appIndex > CLONE_APP_INDEX_MAX) { + throw createBusinessError(ERROR_INVALID_APPINDEX_CODE, ERROR_INVALID_APPINDEX_MSG); + } let p = new Promise((resolve: (v:undefined) => void, reject: (error: Error) => void) : void => { let execFun = (): void => { return bundleManager.cleanBundleCacheFilesNative(bundleName, appIndex); @@ -1329,6 +1348,9 @@ namespace bundleManager { } function getAppProvisionInfo(bundleName: string, userId?: int): Promise { + if (bundleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_BUNDLENAME_EMPTY_ERROR); + } let p = new Promise((resolve: (appProvisionInfo: AppProvisionInfo) => void, reject: (error: Error) => void) => { let userIdInfo: int = userId ?? EMPTY_VALUE; @@ -1348,6 +1370,9 @@ namespace bundleManager { } function getAppProvisionInfo(bundleName: string, userId: int, callback: AsyncCallback): void { + if (bundleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_BUNDLENAME_EMPTY_ERROR); + } let execFun = (): AppProvisionInfo => { return bundleManager.getAppProvisionInfoNative(bundleName, userId, false); }; @@ -1361,6 +1386,9 @@ namespace bundleManager { } function getAppProvisionInfo(bundleName: string, callback: AsyncCallback): void { + if (bundleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_BUNDLENAME_EMPTY_ERROR); + } let execFun = (): AppProvisionInfo => { return bundleManager.getAppProvisionInfoNative(bundleName, EMPTY_VALUE, false); }; @@ -1674,6 +1702,9 @@ namespace bundleManager { } function getAbilityInfo(uri: string, abilityFlags: int): Promise> { + if (uri === "") { + throw createBusinessError(ERROR_ABILITY_NOT_EXIST, GETABILITYINFO_ERROR_MSG); + } let p = new Promise>((resolve: (abilityInfos: Array) => void, reject: (error: BusinessError) => void) => { let execFun = (): Array => { diff --git a/interfaces/kits/ani/overlay/ets/@ohos.bundle.overlay.ets b/interfaces/kits/ani/overlay/ets/@ohos.bundle.overlay.ets index 73cd5d7f87263220a1dfac3229bd41d66de2b559..102baeae51e311e87ff17e3250e20dbb59dbcb66 100644 --- a/interfaces/kits/ani/overlay/ets/@ohos.bundle.overlay.ets +++ b/interfaces/kits/ani/overlay/ets/@ohos.bundle.overlay.ets @@ -25,6 +25,20 @@ export default namespace overlay { loadLibrary("ani_overlay.z"); + const ERROR_PARAM_CHECK_ERROR: int = 401; + const PARAM_MODULENAME_EMPTY_ERROR: string = "BusinessError 401: Parameter error. The type of moduleName must be string."; + const PARAM_BUNDLENAME_EMPTY_ERROR: string = "BusinessError 401: Parameter error. The type of bundleName must be string."; + const PARAM_TARGET_MODULENAME_EMPTY_ERROR: string = "BusinessError 401: Parameter error. The type of targetModuleName must be string."; + const PARAM_TARGET_BUNDLENAME_EMPTY_ERROR: string = "BusinessError 401: Parameter error. The type of targetBundleName must be string."; + + function createBusinessError(code: int, message: string) { + let err = new BusinessError(); + err.code = code; + err.name = 'Error'; + err.message = message; + return err; + } + export native function setOverlayEnabledNative(moduleName: string, isEnabled: boolean): void; export native function setOverlayEnabledByBundleNameNative(bundleName: string, moduleName: string, isEnabled: boolean): void; export native function getOverlayModuleInfoNative(moduleName: string): OverlayModuleInfo; @@ -33,6 +47,9 @@ export default namespace overlay { export native function getTargetOverlayModuleInfosByBundleNameNative(targetBundleName: string, moduleName: string): Array; function setOverlayEnabled(moduleName: string, isEnabled: boolean, callback: AsyncCallback): void { + if (moduleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_MODULENAME_EMPTY_ERROR); + } let cb = (): void => { return overlay.setOverlayEnabledNative(moduleName, isEnabled); }; @@ -45,6 +62,9 @@ export default namespace overlay { } function setOverlayEnabled(moduleName: string, isEnabled: boolean): Promise { + if (moduleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_MODULENAME_EMPTY_ERROR); + } let p = new Promise((resolve: (v: PromiseLike) => void, reject: (error: BusinessError) => void) : void => { let cb = (): void => { return overlay.setOverlayEnabledNative(moduleName, isEnabled); @@ -61,6 +81,12 @@ export default namespace overlay { } function setOverlayEnabledByBundleName(bundleName: string, moduleName: string, isEnabled: boolean, callback: AsyncCallback): void { + if (bundleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_BUNDLENAME_EMPTY_ERROR); + } + if (moduleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_MODULENAME_EMPTY_ERROR); + } let cb = (): void => { return overlay.setOverlayEnabledByBundleNameNative(bundleName, moduleName, isEnabled); }; @@ -73,6 +99,12 @@ export default namespace overlay { } function setOverlayEnabledByBundleName(bundleName: string, moduleName: string, isEnabled: boolean): Promise { + if (bundleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_BUNDLENAME_EMPTY_ERROR); + } + if (moduleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_MODULENAME_EMPTY_ERROR); + } let p = new Promise((resolve: (v: PromiseLike) => void, reject: (error: BusinessError) => void) : void => { let cb = (): void => { return overlay.setOverlayEnabledByBundleNameNative(bundleName, moduleName, isEnabled); @@ -89,6 +121,9 @@ export default namespace overlay { } function getOverlayModuleInfo(moduleName: string, callback: AsyncCallback): void { + if (moduleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_MODULENAME_EMPTY_ERROR); + } let cb = (): OverlayModuleInfo => { return overlay.getOverlayModuleInfoNative(moduleName); }; @@ -102,6 +137,9 @@ export default namespace overlay { } function getOverlayModuleInfo(moduleName: string): Promise { + if (moduleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_MODULENAME_EMPTY_ERROR); + } let p = new Promise((resolve: (overlayModuleInfo: OverlayModuleInfo) => void, reject: (error: BusinessError) => void) => { let cb = (): OverlayModuleInfo => { return overlay.getOverlayModuleInfoNative(moduleName); @@ -118,6 +156,9 @@ export default namespace overlay { } function getTargetOverlayModuleInfos(targetModuleName: string, callback: AsyncCallback>): void { + if (targetModuleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_TARGET_MODULENAME_EMPTY_ERROR); + } let cb = (): (Array) => { return overlay.getTargetOverlayModuleInfosNative(targetModuleName); }; @@ -131,6 +172,9 @@ export default namespace overlay { } function getTargetOverlayModuleInfos(targetModuleName: string): Promise> { + if (targetModuleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_TARGET_MODULENAME_EMPTY_ERROR); + } let p = new Promise>((resolve: (arrOverlayModuleInfo: Array) => void, reject: (error: BusinessError) => void) => { let cb = (): (Array) => { return overlay.getTargetOverlayModuleInfosNative(targetModuleName); @@ -147,6 +191,9 @@ export default namespace overlay { } function getOverlayModuleInfoByBundleName(bundleName: string, callback: AsyncCallback>): void { + if (bundleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_BUNDLENAME_EMPTY_ERROR); + } let cb = (): (Array) => { return overlay.getOverlayModuleInfoByBundleNameNative(bundleName, ''); }; @@ -160,6 +207,9 @@ export default namespace overlay { } function getOverlayModuleInfoByBundleName(bundleName: string, moduleName: string, callback: AsyncCallback>): void { + if (bundleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_BUNDLENAME_EMPTY_ERROR); + } let cb = (): (Array) => { return overlay.getOverlayModuleInfoByBundleNameNative(bundleName, moduleName); }; @@ -173,6 +223,9 @@ export default namespace overlay { } function getOverlayModuleInfoByBundleName(bundleName: string, moduleName?: string): Promise> { + if (bundleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_BUNDLENAME_EMPTY_ERROR); + } let moduleNameInfo: string = moduleName ?? ''; let p = new Promise>((resolve: (arrOverlayModuleInfo: Array) => void, reject: (error: BusinessError) => void) => { let cb = (): (Array) => { @@ -190,6 +243,9 @@ export default namespace overlay { } function getTargetOverlayModuleInfosByBundleName(targetBundleName: string, callback: AsyncCallback>): void { + if (targetBundleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_TARGET_BUNDLENAME_EMPTY_ERROR); + } let cb = (): (Array) => { return overlay.getTargetOverlayModuleInfosByBundleNameNative(targetBundleName, ''); }; @@ -203,6 +259,9 @@ export default namespace overlay { } function getTargetOverlayModuleInfosByBundleName(targetBundleName: string, moduleName: string, callback: AsyncCallback>): void { + if (targetBundleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_TARGET_BUNDLENAME_EMPTY_ERROR); + } let cb = (): (Array) => { return overlay.getTargetOverlayModuleInfosByBundleNameNative(targetBundleName, moduleName); }; @@ -216,6 +275,9 @@ export default namespace overlay { } function getTargetOverlayModuleInfosByBundleName(targetBundleName: string, moduleName?: string): Promise> { + if (targetBundleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_TARGET_BUNDLENAME_EMPTY_ERROR); + } let moduleNameInfo: string = moduleName ?? ''; let p = new Promise>((resolve: (arrOverlayModuleInfo: Array) => void, reject: (error: BusinessError) => void) => { let cb = (): (Array) => { diff --git a/interfaces/kits/ani/shortcut_manager/ets/@ohos.bundle.shortcutManager.ets b/interfaces/kits/ani/shortcut_manager/ets/@ohos.bundle.shortcutManager.ets index 4c1ca71cf8e7048ed40ffd581f4cbf9ce718e45a..f55ac27de8aaeb6ca55a8fc6cb4c642e0d6db0d4 100644 --- a/interfaces/kits/ani/shortcut_manager/ets/@ohos.bundle.shortcutManager.ets +++ b/interfaces/kits/ani/shortcut_manager/ets/@ohos.bundle.shortcutManager.ets @@ -20,6 +20,19 @@ namespace shortcutManager { loadLibrary("ani_shortcut_manager.z"); + function createBusinessError(code: int, message: string) { + let err = new BusinessError(); + err.code = code; + err.name = 'Error'; + err.message = message; + return err; + } + + const ERROR_SOURCETYPE : int = -1; + const MAIN_APP_INDEX: int = 0; + const ERROR_PARAM_CHECK_ERROR: int = 401; + const INVALID_SHORTCUT_INFO_ERROR: string = "invalid ShortcutInfo: parameter type error, or appIndex is less than 0"; + export native function addDesktopShortcutInfoNative(shortcutInfo: ShortcutInfo, userId: int): void; export native function deleteDesktopShortcutInfoNative(shortcutInfo: ShortcutInfo, userId: int): void; export native function getAllDesktopShortcutInfoNative(userId: int): Array; @@ -27,6 +40,9 @@ namespace shortcutManager { export native function getAllShortcutInfoForSelfNative(): Array; function addDesktopShortcutInfo(shortcutInfo: ShortcutInfo, userId: int): Promise { + if (shortcutInfo.appIndex < MAIN_APP_INDEX || shortcutInfo?.sourceType === ERROR_SOURCETYPE) { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, INVALID_SHORTCUT_INFO_ERROR); + } let p = new Promise((resolve: (v: PromiseLike) => void, reject: (error: BusinessError) => void): void => { let cb = (): NullishType => { return shortcutManager.addDesktopShortcutInfoNative(shortcutInfo, userId); @@ -42,6 +58,9 @@ namespace shortcutManager { } function deleteDesktopShortcutInfo(shortcutInfo: ShortcutInfo, userId: int): Promise { + if (shortcutInfo.appIndex < MAIN_APP_INDEX || shortcutInfo.sourceType === ERROR_SOURCETYPE) { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, INVALID_SHORTCUT_INFO_ERROR); + } let p = new Promise((resolve: (v: PromiseLike) => void, reject: (error: BusinessError) => void): void => { let cb = (): NullishType => { return shortcutManager.deleteDesktopShortcutInfoNative(shortcutInfo, userId)