diff --git a/zh-cn/application-dev/reference/apis/js-apis-installer.md b/zh-cn/application-dev/reference/apis/js-apis-installer.md index ab0e2ca3dc91878964ed6b2507188084942af394..d9f84bfb6fbbcd441819748261642e7eb54d6e0b 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-installer.md +++ b/zh-cn/application-dev/reference/apis/js-apis-installer.md @@ -21,6 +21,7 @@ import installer from '@ohos.bundle.installer'; | ohos.permission.INSTALL_ENTERPRISE_NORMAL_BUNDLE | system_core | 允许在企业设备上安装企业NORMAL应用包。 | | ohos.permission.UNINSTALL_BUNDLE | system_core | 允许应用卸载应用。 | | ohos.permission.RECOVER_BUNDLE | system_core | 允许应用恢复预置应用。 | +| ohos.permission.INSTALL_SELF_BUNDLE | system_core | 允许企业MDM应用在企业设备上自升级。| 权限等级参考[权限等级说明](../../security/accesstoken-overview.md#权限等级说明) @@ -90,6 +91,34 @@ try { } ``` +## BundleInstaller.getBundleInstallerSync + +getBundleInstallerSync(): BundleInstaller; + +获取并返回BundleInstaller对象。 + +**系统接口:** 此接口为系统接口。 + +**系统能力:** SystemCapability.BundleManager.BundleFramework.Core + +**返回值:** +| 类型 | 说明 | +| ------------------------------------------------------------ | ------------------------------------ | +| [BundleInstaller](js-apis-installer.md#BundleInstaller) | 返回BundleInstaller对象 | + +**示例:** + +```ts +import installer from '@ohos.bundle.installer'; + +try { + let data: BundleInstaller = installer.getBundleInstaller(); + console.info('getBundleInstaller successfully.'); +} catch (error) { + console.error('getBundleInstaller failed. Cause: ' + error.message); +} +``` + ## BundleInstaller.install install(hapFilePaths: Array<string>, installParam: InstallParam, callback: AsyncCallback<void>): void; @@ -338,7 +367,7 @@ uninstall(bundleName: string, installParam: InstallParam, callback: AsyncCallbac **系统接口:** 此接口为系统接口。 -**需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.UNINSTALL_BUNDLE10+ +**需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.UNINSTALL_BUNDLE **系统能力:** SystemCapability.BundleManager.BundleFramework.Core @@ -398,7 +427,7 @@ uninstall(bundleName: string, callback: AsyncCallback<void>): void; **系统接口:** 此接口为系统接口。 -**需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.UNINSTALL_BUNDLE10+ +**需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.UNINSTALL_BUNDLE **系统能力:** SystemCapability.BundleManager.BundleFramework.Core @@ -450,7 +479,7 @@ uninstall(bundleName: string, installParam?: InstallParam) : Promise\; **系统接口:** 此接口为系统接口。 -**需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.UNINSTALL_BUNDLE10+ +**需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.UNINSTALL_BUNDLE **系统能力:** SystemCapability.BundleManager.BundleFramework.Core @@ -513,7 +542,7 @@ recover(bundleName: string, installParam: InstallParam, callback: AsyncCallback& **系统接口:** 此接口为系统接口。 -**需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.RECOVER_BUNDLE10+ +**需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.RECOVER_BUNDLE **系统能力:** SystemCapability.BundleManager.BundleFramework.Core @@ -571,7 +600,7 @@ recover(bundleName: string, callback: AsyncCallback<void>): void; **系统接口:** 此接口为系统接口。 -**需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.RECOVER_BUNDLE10+ +**需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.RECOVER_BUNDLE **系统能力:** SystemCapability.BundleManager.BundleFramework.Core @@ -621,7 +650,7 @@ recover(bundleName: string, installParam?: InstallParam) : Promise\; **系统接口:** 此接口为系统接口。 -**需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.RECOVER_BUNDLE10+ +**需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.RECOVER_BUNDLE **系统能力:** SystemCapability.BundleManager.BundleFramework.Core @@ -681,7 +710,7 @@ uninstall(uninstallParam: UninstallParam, callback : AsyncCallback\) : voi **系统接口:** 此接口为系统接口。 -**需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.UNINSTALL_BUNDLE10+ +**需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.UNINSTALL_BUNDLE **系统能力:** SystemCapability.BundleManager.BundleFramework.Core @@ -735,7 +764,7 @@ uninstall(uninstallParam: UninstallParam) : Promise\; **系统接口:** 此接口为系统接口。 -**需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.UNINSTALL_BUNDLE10+ +**需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.UNINSTALL_BUNDLE **系统能力:** SystemCapability.BundleManager.BundleFramework.Core @@ -786,6 +815,216 @@ try { } ``` +## BundleInstaller.updateBundleForSelf10+ + +updateBundleForSelf(hapFilePaths: Array\, installParam: InstallParam, callback: AsyncCallback\): void; + +以异步方法更新当前应用,仅限企业设备上的企业MDM应用调用,且传入的hapFilePaths中的hap必须都属于当前应用,使用callback形式返回结果。 + +**系统接口:** 此接口为系统接口。 + +**需要权限:** ohos.permission.INSTALL_SELF_BUNDLE + +**系统能力:** SystemCapability.BundleManager.BundleFramework.Core + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| --------------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ | +| hapFilePaths | Array<string> | 是 | 存储应用程序包的路径。路径应该是当前应用程序中存放HAP的数据目录。当传入的路径是一个目录时, 该目录下只能放同一个应用的HAP,且这些HAP的签名需要保持一致。 | +| installParam | [InstallParam](#installparam) | 是 | 指定安装所需的其他参数。 | +| callback | AsyncCallback<void> | 是 | 回调函数,安装应用成功,err为undefined,否则为错误对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 + +| 错误码ID | 错误信息 | +| -------- | ------------------------------------------------------------ | +| 17700004 | The specified user ID is not found. | +| 17700010 | Failed to install the HAP because the HAP fails to be parsed. | +| 17700011 | Failed to install the HAP because the HAP signature fails to be verified. | +| 17700012 | Failed to install the HAP because the HAP path is invalid or the HAP is too large. | +| 17700015 | Failed to install the HAPs because they have different configuration information. | +| 17700016 | Failed to install the HAP because of insufficient system disk space. | +| 17700017 | Failed to install the HAP since the version of the HAP to install is too early. | +| 17700018 | Failed to install because the dependent module does not exist. | +| 17700039 | Failed to install because disallow install a shared bundle by hapFilePaths. | +| 17700041 | Failed to install because enterprise device management disallow install. | +| 17700042 | Failed to install the HAP because of incorrect URI in the data proxy. | +| 17700043 | Failed to install the HAP because of low APL in the non-system data proxy (required APL: system_basic or system_core). | +| 17700044 | Failed to install the HAP because the isolationMode configured is not supported. | +| 17700047 | Failed to install the HAP because the VersionCode to be updated is not greater than the current VersionCode. | +| 17700048 | Failed to install the HAP because the code signature verification is failed. | +| 17700049 | Failed to install the HAP because the bundleName is different from the bundleName of the caller application. | +| 17700050 | Failed to install the HAP because enterprise normal/MDM bundle cannot be installed on non-enterprise device. | +| 17700051 | Failed to install the HAP because the distribution type of caller application is not enterprise_mdm. | + +**示例:** + +```ts +import installer from '@ohos.bundle.installer'; +let hapFilePaths = ['/data/storage/el2/base/haps/entry/files/']; +let installParam = { + userId: 100, + isKeepData: false, + installFlag: 1, +}; + +try { + installer.getBundleInstaller().then(data => { + data.updateBundleForSelf(hapFilePaths, installParam, err => { + if (err) { + console.error('updateBundleForSelf failed:' + err.message); + } else { + console.info('updateBundleForSelf successfully.'); + } + }); + }).catch(error => { + console.error('getBundleInstaller failed. Cause: ' + error.message); + }); +} catch (error) { + console.error('getBundleInstaller failed. Cause: ' + error.message); +} +``` + +## BundleInstaller.updateBundleForSelf10+ + +updateBundleForSelf(hapFilePaths: Array\, callback: AsyncCallback\): void; + +以异步方法更新当前应用,仅限企业设备上的企业MDM应用调用,且传入的hapFilePaths中的hap必须都属于当前应用,使用callback形式返回结果。 + +**系统接口:** 此接口为系统接口。 + +**需要权限:** ohos.permission.INSTALL_SELF_BUNDLE + +**系统能力:** SystemCapability.BundleManager.BundleFramework.Core + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| --------------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ | +| hapFilePaths | Array<string> | 是 | 存储应用程序包的路径。路径应该是当前应用程序中存放HAP的数据目录。当传入的路径是一个目录时, 该目录下只能放同一个应用的HAP,且这些HAP的签名需要保持一致。 | +| callback | AsyncCallback<void> | 是 | 回调函数,安装应用成功,err为undefined,否则为错误对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 + +| 错误码ID | 错误信息 | +| -------- | ------------------------------------------------------------ | +| 17700010 | Failed to install the HAP because the HAP fails to be parsed. | +| 17700011 | Failed to install the HAP because the HAP signature fails to be verified. | +| 17700012 | Failed to install the HAP because the HAP path is invalid or the HAP is too large. | +| 17700015 | Failed to install the HAPs because they have different configuration information. | +| 17700016 | Failed to install the HAP because of insufficient system disk space. | +| 17700017 | Failed to install the HAP since the version of the HAP to install is too early. | +| 17700018 | Failed to install because the dependent module does not exist. | +| 17700039 | Failed to install because disallow install a shared bundle by hapFilePaths. | +| 17700041 | Failed to install because enterprise device management disallow install. | +| 17700042 | Failed to install the HAP because of incorrect URI in the data proxy. | +| 17700043 | Failed to install the HAP because of low APL in the non-system data proxy (required APL: system_basic or system_core). | +| 17700044 | Failed to install the HAP because the isolationMode configured is not supported. | +| 17700047 | Failed to install the HAP because the VersionCode to be updated is not greater than the current VersionCode. | +| 17700048 | Failed to install the HAP because the code signature verification is failed. | +| 17700049 | Failed to install the HAP because the bundleName is different from the bundleName of the caller application. | +| 17700050 | Failed to install the HAP because enterprise normal/MDM bundle cannot be installed on non-enterprise device. | +| 17700051 | Failed to install the HAP because the distribution type of caller application is not enterprise_mdm. | + +**示例:** + +```ts +import installer from '@ohos.bundle.installer'; +let hapFilePaths = ['/data/storage/el2/base/haps/entry/files/']; + +try { + installer.getBundleInstaller().then(data => { + data.updateBundleForSelf(hapFilePaths, err => { + if (err) { + console.error('updateBundleForSelf failed:' + err.message); + } else { + console.info('updateBundleForSelf successfully.'); + } + }); + }).catch(error => { + console.error('getBundleInstaller failed. Cause: ' + error.message); + }); +} catch (error) { + console.error('getBundleInstaller failed. Cause: ' + error.message); +} +``` + +## BundleInstaller.updateBundleForSelf10+ + +updateBundleForSelf(hapFilePaths: Array\, installParam?: InstallParam): Promise\; + +以异步方法更新当前应用,仅限企业设备上的企业MDM应用调用,且传入的hapFilePaths中的hap必须都属于当前应用,使用promise形式返回结果。 + +**系统接口:** 此接口为系统接口。 + +**需要权限:** ohos.permission.INSTALL_SELF_BUNDLE + +**系统能力:** SystemCapability.BundleManager.BundleFramework.Core + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| --------------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ | +| hapFilePaths | Array<string> | 是 | 存储应用程序包的路径。路径应该是当前应用程序中存放HAP的数据目录。当传入的路径是一个目录时, 该目录下只能放同一个应用的HAP,且这些HAP的签名需要保持一致。 | +| installParam | [InstallParam](#installparam) | 否 | 指定安装所需的其他参数,默认值:参照[InstallParam](#installparam)的默认值。 | + +**错误码:** + +以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 + +| 错误码ID | 错误信息 | +| -------- | ------------------------------------------------------------ | +| 17700004 | The specified user ID is not found. | +| 17700010 | Failed to install the HAP because the HAP fails to be parsed. | +| 17700011 | Failed to install the HAP because the HAP signature fails to be verified. | +| 17700012 | Failed to install the HAP because the HAP path is invalid or the HAP is too large. | +| 17700015 | Failed to install the HAPs because they have different configuration information. | +| 17700016 | Failed to install the HAP because of insufficient system disk space. | +| 17700017 | Failed to install the HAP since the version of the HAP to install is too early. | +| 17700018 | Failed to install because the dependent module does not exist. | +| 17700039 | Failed to install because disallow install a shared bundle by hapFilePaths. | +| 17700041 | Failed to install because enterprise device management disallow install. | +| 17700042 | Failed to install the HAP because of incorrect URI in the data proxy. | +| 17700043 | Failed to install the HAP because of low APL in the non-system data proxy (required APL: system_basic or system_core). | +| 17700044 | Failed to install the HAP because the isolationMode configured is not supported. | +| 17700047 | Failed to install the HAP because the VersionCode to be updated is not greater than the current VersionCode. | +| 17700048 | Failed to install the HAP because the code signature verification is failed. | +| 17700049 | Failed to install the HAP because the bundleName is different from the bundleName of the caller application. | +| 17700050 | Failed to install the HAP because enterprise normal/MDM bundle cannot be installed on non-enterprise device. | +| 17700051 | Failed to install the HAP because the distribution type of caller application is not enterprise_mdm. | + +**示例:** + +```ts +import installer from '@ohos.bundle.installer'; +let hapFilePaths = ['/data/storage/el2/base/haps/entry/files/']; +let installParam = { + userId: 100, + isKeepData: false, + installFlag: 1, +}; + +try { + installer.getBundleInstaller().then(data => { + data.updateBundleForSelf(hapFilePaths, installParam) + .then((data) => { + console.info('updateBundleForSelf successfully: ' + JSON.stringify(data)); + }).catch((error) => { + console.error('updateBundleForSelf failed:' + error.message); + }); + }).catch(error => { + console.error('getBundleInstaller failed. Cause: ' + error.message); + }); +} catch (error) { + console.error('getBundleInstaller failed. Cause: ' + error.message); +} +``` + ## HashParam 应用程序安装卸载哈希参数信息。 diff --git a/zh-cn/application-dev/reference/apis/js-apis-launcherBundleManager.md b/zh-cn/application-dev/reference/apis/js-apis-launcherBundleManager.md index c0eee70d41e4a9dd645b472388f8821dc56ca5cb..34fda4809dc9b4d3626e145bedcb5f36751f3f8d 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-launcherBundleManager.md +++ b/zh-cn/application-dev/reference/apis/js-apis-launcherBundleManager.md @@ -115,6 +115,53 @@ try { } ``` +## launcherBundlemanager.getLauncherAbilityInfoSync10+ + +getLauncherAbilityInfoSync(bundleName: string, userId: number) : Array\<[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)>; + +查询指定bundleName及用户的[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)。 + +**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED + +**系统接口:** 此接口为系统接口 + +**系统能力:** SystemCapability.BundleManager.BundleFramework.Launcher + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ---------- | ------ | ---- | -------------- | +| bundleName | string | 是 | 应用Bundle名称。 | +| userId | number | 是 | 被查询的用户id。 | + +**返回值:** + +| 类型 | 说明 | +| ----------------------------- | -------------------------------------------------- | +| Array<[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)> | Array形式返回bundle包含的[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)信息。 | + +**错误码:** + +以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 + +| 错误码ID | 错误信息 | +| -------- | ---------------------------------------- | +| 17700001 | The specified bundle name is not found. | +| 17700004 | The specified user ID is not found. | + +**示例:** + +```typescript +import launcherBundleManager from '@ohos.bundle.launcherBundleManager'; + +try { + let data: Array = launcherBundleManager.getLauncherAbilityInfoSync("com.example.demo", 100); + console.log("data is " + JSON.stringify(data[0])); +} catch (errData) { + console.error(`errData is errCode:${errData.code} message:${errData.message}`); +} +``` + ## launcherBundlemanager.getAllLauncherAbilityInfo9+ getAllLauncherAbilityInfo(userId: number, callback: AsyncCallback>) : void; @@ -305,3 +352,46 @@ try { console.error(`errData is errCode:${errData.code} message:${errData.message}`); } ``` + +## launcherBundlemanager.getShortcutInfoSync10+ + +getShortcutInfoSync(bundleName : string) : Array\<[ShortcutInfo](js-apis-bundleManager-shortcutInfo.md)>; + +查询当前用户下指定应用的[ShortcutInfo](js-apis-bundleManager-shortcutInfo.md)。 + +**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED + +**系统接口:** 此接口为系统接口 + +**系统能力:** SystemCapability.BundleManager.BundleFramework.Launcher + +| 参数名 | 类型 | 必填 | 说明 | +| ---------- | ------ | ---- | -------------- | +| bundleName | string | 是 | 应用Bundle名称。 | + +**返回值:** + +| 类型 | 说明 | +| ---------------------- | ----------------------------------------------- | +| Array<[ShortcutInfo](js-apis-bundleManager-shortcutInfo.md)> | Array形式返回当前用户下指定应用的[ShortcutInfo](js-apis-bundleManager-shortcutInfo.md)。 | + +**错误码:** + +以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 + +| 错误码ID | 错误信息 | +| -------- | ---------------------------------------- | +| 17700001 | The specified bundle name is not found. | + +**示例:** + +```ts +import launcherBundleManager from '@ohos.bundle.launcherBundleManager'; + +try { + let data: Array = launcherBundleManager.getShortcutInfo("com.example.demo"); + console.log("data is " + JSON.stringify(data[0])); +} catch (errData) { + console.error(`errData is errCode:${errData.code} message:${errData.message}`); +} +```