From da1200371e8c61f5701734c4f970a6d210651466 Mon Sep 17 00:00:00 2001 From: xsz233 Date: Thu, 10 Aug 2023 11:35:05 +0800 Subject: [PATCH] add BundleInstaller.updateBundleForSelf Signed-off-by: xsz233 --- .../reference/apis/js-apis-installer.md | 214 ++++++++++++++++++ 1 file changed, 214 insertions(+) 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 ee690cbd2b..c0f70a5e96 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-installer.md +++ b/zh-cn/application-dev/reference/apis/js-apis-installer.md @@ -769,6 +769,220 @@ 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. | +| 17700031 | Failed to install the HAP because the overlay check of the HAP is failed. | +| 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 | 错误信息 | +| -------- | ------------------------------------------------------------ | +| 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. | +| 17700031 | Failed to install the HAP because the overlay check of the HAP is failed. | +| 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. | +| 17700031 | Failed to install the HAP because the overlay check of the HAP is failed. | +| 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 应用程序安装卸载哈希参数信息。 -- GitLab