未验证 提交 f514c00b 编写于 作者: O openharmony_ci 提交者: Gitee

!16777 【EDM】新增包管理文档

Merge pull request !16777 from 李兀立/master
......@@ -352,6 +352,7 @@
- 定制管理
- [@ohos.configPolicy (配置策略)](js-apis-configPolicy.md)
- [@ohos.enterprise.accountManager (帐户管理)](js-apis-enterprise-accountManager.md)
- [@ohos.enterprise.bundleManager (包管理)](js-apis-enterprise-bundleManager.md)
- [@ohos.enterprise.adminManager (企业设备管理)](js-apis-enterprise-adminManager.md)
- [@ohos.enterprise.dateTimeManager (系统时间管理)](js-apis-enterprise-dateTimeManager.md)
- [@ohos.enterprise.deviceControl (设备控制管理)](js-apis-enterprise-deviceControl.md)
......
# @ohos.enterprise.bundleManager(包管理)
本模块提供包管理能力,包括添加包安装白名单、获取包安装白名单、移除包安装白名单等。仅企业设备管理员应用才能调用。
> **说明:**
>
> 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块
```js
import bundleManager from '@ohos.enterprise.bundleManager';
```
## bundleManager.addAllowedInstallBundles
addAllowedInstallBundles(admin: Want, appIds: Array\<string>, callback: AsyncCallback&lt;void&gt;): void;
添加包安装白名单接口,使用callback异步回调。
**需要权限:** ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY
**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
**系统API**: 此接口为系统接口。
**参数:**
| 参数 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | ------------------------------- |
| admin | [Want](js-apis-app-ability-want.md) | 是 | 设备管理员应用 |
| appIds | Array&lt;string&gt; | 是 | 允许安装包的白名单 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当接口调用成功err为null,否则为错误对象。 |
**错误码**
以下的错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)
| 错误码ID | 错误信息 |
| ------- | ---------------------------------------------------------------------------- |
| 9200003 | the administrator ability component is invalid. |
| 9200007 | the system ability work abnormally. |
**示例:**
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
};
let appIds = {"com.example.myapplication"};
bundleManager.AddAllowedInstallBundles(wantTemp, appIds, (error) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
}
});
```
## bundleManager.addAllowedInstallBundles
addAllowedInstallBundles(admin: Want, appIds: Array\<string>, userId: number, callback: AsyncCallback&lt;void&gt;): void;
添加包安装白名单接口,使用callback异步回调。
**需要权限:** ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY
**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
**系统API**: 此接口为系统接口。
**参数:**
| 参数 | 类型 | 必填 | 说明 |
| ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-app-ability-want.md) | 是 | 设备管理员应用 |
| appIds | Array&lt;string&gt; | 是 | 允许安装包的白名单 |
| userId | number | 是 | 用户ID。默认值:调用方所在用户,取值范围:大于等于0。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当接口调用成功err为null,否则为错误对象。 |
**错误码**
以下的错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)
| 错误码ID | 错误信息 |
| ------- | ---------------------------------------------------------------------------- |
| 9200003 | the administrator ability component is invalid. |
| 9200007 | the system ability work abnormally. |
**示例:**
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
};
let appIds = {"com.example.myapplication"};
bundleManager.AddAllowedInstallBundles(wantTemp, appIds, 100, (error) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
}
});
```
## bundleManager.addAllowedInstallBundles
addAllowedInstallBundles(admin: Want, appIds: Array\<string>, userId?: number): Promise&lt;void&gt;;
添加包安装白名单接口,使用promise异步回调。
**需要权限:** ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY
**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
**系统API**: 此接口为系统接口。
**参数:**
| 参数 | 类型 | 必填 | 说明 |
| ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-app-ability-want.md) | 是 | 设备管理员应用 |
| appIds | Array&lt;string&gt; | 是 | 允许安装包的白名单 |
| userId | number | 否 | 用户ID。默认值:调用方所在用户,取值范围:大于等于0。 |
**返回值:**
| 类型 | 说明 |
| --------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**错误码**
以下的错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)
| 错误码ID | 错误信息 |
| ------- | ---------------------------------------------------------------------------- |
| 9200003 | the administrator ability component is invalid. |
| 9200007 | the system ability work abnormally. |
**示例:**
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
};
let appIds = {"com.example.myapplication"};
bundleManager.addAllowedInstallBundles(wantTemp, appIds, 100).then(() => {
console.log("success");
}).catch(error => {
console.log("error code:" + error.code + " error message:" + error.message);
});
```
## bundleManager.removeAllowedInstallBundles
removeAllowedInstallBundles(admin: Want, appIds: Array\<string>, callback: AsyncCallback&lt;void&gt;): void;
移除包安装白名单接口,使用callback异步回调。
**需要权限:** ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY
**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
**系统API**: 此接口为系统接口。
**参数:**
| 参数 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | ------------------------------- |
| admin | [Want](js-apis-app-ability-want.md) | 是 | 设备管理员应用 |
| appIds | Array&lt;string&gt; | 是 | 移除允许安装包的白名单 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当接口调用成功err为null,否则为错误对象。 |
**错误码**
以下的错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)
| 错误码ID | 错误信息 |
| ------- | ---------------------------------------------------------------------------- |
| 9200003 | the administrator ability component is invalid. |
| 9200007 | the system ability work abnormally. |
**示例:**
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
};
let appIds = {"com.example.myapplication"};
bundleManager.removeAllowedInstallBundles(wantTemp, appIds, (error) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
}
});
```
## bundleManager.removeAllowedInstallBundles
removeAllowedInstallBundles(admin: Want, appIds: Array\<string>, userId: number, callback: AsyncCallback&lt;void&gt;): void;
移除包安装白名单接口,使用callback异步回调。
**需要权限:** ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY
**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
**系统API**: 此接口为系统接口。
**参数:**
| 参数 | 类型 | 必填 | 说明 |
| ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-app-ability-want.md) | 是 | 设备管理员应用 |
| appIds | Array&lt;string&gt; | 是 | 允许安装包的白名单 |
| userId | number | 是 | 用户ID。默认值:调用方所在用户,取值范围:大于等于0。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当接口调用成功err为null,否则为错误对象。 |
**错误码**
以下的错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)
| 错误码ID | 错误信息 |
| ------- | ---------------------------------------------------------------------------- |
| 9200003 | the administrator ability component is invalid. |
| 9200007 | the system ability work abnormally. |
**示例:**
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
};
let appIds = {"com.example.myapplication"};
bundleManager.removeAllowedInstallBundles(wantTemp, appIds, 100, (error) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
}
});
```
## bundleManager.removeAllowedInstallBundles
removeAllowedInstallBundles(admin: Want, appIds: Array\<string>, userId?: number): Promise&lt;void&gt;;
移除包安装白名单接口,使用promise异步回调。
**需要权限:** ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY
**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
**系统API**: 此接口为系统接口。
**参数:**
| 参数 | 类型 | 必填 | 说明 |
| ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-app-ability-want.md) | 是 | 设备管理员应用 |
| appIds | Array\&lt;string&gt; | 是 | 允许安装包的白名单 |
| userId | number | 否 | 用户ID。默认值:调用方所在用户,取值范围:大于等于0。 |
**返回值:**
| 类型 | 说明 |
| --------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**错误码**
以下的错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)
| 错误码ID | 错误信息 |
| ------- | ---------------------------------------------------------------------------- |
| 9200003 | the administrator ability component is invalid. |
| 9200007 | the system ability work abnormally. |
**示例:**
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
};
let appIds = {"com.example.myapplication"};
bundleManager.removeAllowedInstallBundles(wantTemp, appIds, 100).then(() => {
console.log("success");
}).catch(error => {
console.log("error code:" + error.code + " error message:" + error.message);
});
```
## bundleManager.getAllowedInstallBundles
getAllowedInstallBundles(admin: Want, userId: number, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void;
获取包安装白名单接口,使用callback异步回调。
**需要权限:** ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY
**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
**系统API**: 此接口为系统接口。
**参数:**
| 参数 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | ------------------------------- |
| admin | [Want](js-apis-app-ability-want.md) | 是 | 设备管理员应用 |
| userId | number | 是 | 用户ID。默认值:调用方所在用户,取值范围:大于等于0。 |
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | 是 | 回调函数。当接口调用成功err为null,否则为错误对象。 |
**错误码**
以下的错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)
| 错误码ID | 错误信息 |
| ------- | ---------------------------------------------------------------------------- |
| 9200003 | the administrator ability component is invalid. |
| 9200007 | the system ability work abnormally. |
**示例:**
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
};
bundleManager.getAllowedInstallBundles(wantTemp, 100, (error) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
}
});
```
## bundleManager.getAllowedInstallBundles
getAllowedInstallBundles(admin: Want, userId?: number): Promise&lt;Array&lt;string&gt;&gt;;
获取包安装白名单接口,使用promise异步回调。
**需要权限:** ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY
**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
**系统API**: 此接口为系统接口。
**参数:**
| 参数 | 类型 | 必填 | 说明 |
| ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-app-ability-want.md) | 是 | 设备管理员应用 |
| userId | number | 否 | 用户ID。默认值:调用方所在用户,取值范围:大于等于0。 |
**返回值:**
| 类型 | 说明 |
| --------------------- | ------------------------- |
| Promise&lt;void&gt; | 返回结果为String类型数组的Promise对象。 |
**错误码**
以下的错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)
| 错误码ID | 错误信息 |
| ------- | ---------------------------------------------------------------------------- |
| 9200003 | the administrator ability component is invalid. |
| 9200007 | the system ability work abnormally. |
**示例:**
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
};
bundleManager.getAllowedInstallBundles(wantTemp, 100).then(() => {
console.log("success");
}).catch(error => {
console.log("error code:" + error.code + " error message:" + error.message);
});
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册