“a89e1b85fef04d35da0672b40d5d10d85b2487bb”上不存在“...concepts/git@gitcode.net:s920243400/PaddleDetection.git”
提交 f64cc0dc 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 08263582
...@@ -394,8 +394,10 @@ ...@@ -394,8 +394,10 @@
- [@ohos.enterprise.dateTimeManager (System Time Management)](js-apis-enterprise-dateTimeManager.md) - [@ohos.enterprise.dateTimeManager (System Time Management)](js-apis-enterprise-dateTimeManager.md)
- [@ohos.enterprise.deviceControl (Device Control Management)](js-apis-enterprise-deviceControl.md) - [@ohos.enterprise.deviceControl (Device Control Management)](js-apis-enterprise-deviceControl.md)
- [@ohos.enterprise.deviceInfo (Device Information Management)](js-apis-enterprise-deviceInfo.md) - [@ohos.enterprise.deviceInfo (Device Information Management)](js-apis-enterprise-deviceInfo.md)
- [@ohos.enterprise.deviceSettings (Device Settings Management)](js-apis-enterprise-deviceSettings.md)
- [@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)](js-apis-EnterpriseAdminExtensionAbility.md) - [@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)](js-apis-EnterpriseAdminExtensionAbility.md)
- [@ohos.enterprise.networkManager (Network Management)](js-apis-enterprise-networkManager.md) - [@ohos.enterprise.networkManager (Network Management)](js-apis-enterprise-networkManager.md)
- [@ohos.enterprise.restrictions (Restrictions)](js-apis-enterprise-restrictions.md)
- [@ohos.enterprise.wifiManager (Wi-Fi Management)](js-apis-enterprise-wifiManager.md) - [@ohos.enterprise.wifiManager (Wi-Fi Management)](js-apis-enterprise-wifiManager.md)
- Common Library - Common Library
......
# Enterprise Device Management Overview (Available Only for System Applications)
## Overview
OpenHarmony provides Enterprise Device Management APIs to support enterprise APIs. You can use the APIs to implement system-level management and configuration of employee devices. For example, the IT personnel need to install enterprise applications, set security policies, set enterprise email addresses, access enterprise networks, and remotely restore factory settings (to clear lost or stolen device data).
## Developing Enterprise Management Applications
### Basic Concepts
- Device administrator application: a system application that has the [EnterpriseAdminExtensionAbility](../../application-models/enterprise-extensionAbility.md).
### Constraints
- Only the stage model is supported.
### Environment Setup
- [Download DevEco Studio](https://developer.harmonyos.com/en/develop/deveco-studio#download) and set it up as instructed on the official website.
- [Download ohos-sdk-full](../../../release-notes/OpenHarmony-v3.2-beta2.md#acquiring-source-code-from-mirrors).
### How to Develop
1. Use DevEco Studio to create a project and [switch to full-sdk](../../faqs/full-sdk-switch-guide.md).
2. In the [HarmonyAppProvision file](../../security/accesstoken-overview.md#application-apls), set the **app-feature** field to **hos_system_app**.
3. Create [EnterpriseAdminExtensionAbility](../../application-models/enterprise-extensionAbility.md).
4. Declare the permissions required. Before requesting permissions, ensure that the [basic principles for permission management](../../security/accesstoken-overview.md#basic-principles-for-permission-management) are met. Then, [declare the permissions](../../security/accesstoken-guidelines.md#acl).
### API Reference
To implement network management and Wi-Fi management, see:
- [@ohos.enterprise.accountManager (Account Management)](js-apis-enterprise-accountManager.md)
- [@ohos.enterprise.adminManager (Enterprise Device Management)](js-apis-enterprise-adminManager.md)
- [@ohos.enterprise.applicationManager (Application Management)](js-apis-enterprise-applicationManager.md)
- [@ohos.enterprise.bundleManager (Bundle Management)](js-apis-enterprise-bundleManager.md)
- [@ohos.enterprise.dateTimeManager (System Time Management)](js-apis-enterprise-dateTimeManager.md)
- [@ohos.enterprise.deviceControl (Device Control Management)](js-apis-enterprise-deviceControl.md)
- [@ohos.enterprise.deviceInfo (Device Information Management)](js-apis-enterprise-deviceInfo.md)
- [@ohos.enterprise.deviceSettings (Device Settings Management](js-apis-enterprise-deviceSettings.md)
- [@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)](js-apis-EnterpriseAdminExtensionAbility.md)
- [@ohos.enterprise.networkManager (Network Management)](js-apis-enterprise-networkManager.md)
- [@ohos.enterprise.restrictions (Restrictions)](js-apis-enterprise-restrictions.md)
- [@ohos.enterprise.wifiManager (Wi-Fi Management)](js-apis-enterprise-wifiManager.md)
# @ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility) # @ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)
The **EnterpriseAdminExtensionAbility** module provides Extension abilities for enterprise administrators. The **EnterpriseAdminExtensionAbility** module provides extended enterprise device management capabilities.
To have the capabilities provided by the module, for example, receiving the application activation or deactivation notification sent by the system, an enterprise administrator application must have an **EnterpriseAdminExtensionAbility** instance and override the APIs in it. To have the capabilities provided by this module, for example, to receive a notification when a device administrator application is enabled or disabled, you need to create an **EnterpriseAdminExtensionAbility** instance for the enterprise administrator application and overload related APIs.
> **NOTE** > **NOTE**
> >
...@@ -20,7 +20,7 @@ import EnterpriseAdminExtensionAbility from '@ohos.enterprise.EnterpriseAdminExt ...@@ -20,7 +20,7 @@ import EnterpriseAdminExtensionAbility from '@ohos.enterprise.EnterpriseAdminExt
onAdminEnabled(): void onAdminEnabled(): void
Called when an enterprise administrator is enabled. Called when a device administrator application is enabled.
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager **System capability**: SystemCapability.Customization.EnterpriseDeviceManager
...@@ -39,7 +39,7 @@ export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbil ...@@ -39,7 +39,7 @@ export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbil
onAdminDisabled(): void onAdminDisabled(): void
Called when an enterprise administrator is disabled. Called when a device administrator application is disabled.
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager **System capability**: SystemCapability.Customization.EnterpriseDeviceManager
...@@ -66,7 +66,7 @@ Called when a bundle is added. ...@@ -66,7 +66,7 @@ Called when a bundle is added.
**Parameters** **Parameters**
| Parameter | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- | | ----- | ----------------------------------- | ---- | ------- |
| bundleName | string | Yes | Name of the bundle added.| | bundleName | string | Yes | Name of the bundle added.|
...@@ -75,7 +75,7 @@ Called when a bundle is added. ...@@ -75,7 +75,7 @@ Called when a bundle is added.
```ts ```ts
export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbility { export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbility {
onBundleAdded(bundleName: string) { onBundleAdded(bundleName: string) {
console.log("added bundle name: " + bundleName); console.info(`Succeeded in calling onBundleAdded callback, added bundle name : ${bundleName}`);
} }
}; };
``` ```
...@@ -92,7 +92,7 @@ Called when a bundle is removed. ...@@ -92,7 +92,7 @@ Called when a bundle is removed.
**Parameters** **Parameters**
| Parameter | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- | | ----- | ----------------------------------- | ---- | ------- |
| bundleName | string | Yes | Name of the bundle removed.| | bundleName | string | Yes | Name of the bundle removed.|
...@@ -100,8 +100,8 @@ Called when a bundle is removed. ...@@ -100,8 +100,8 @@ Called when a bundle is removed.
```ts ```ts
export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbility { export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbility {
onBundleAdded(bundleName: string) { onBundleRemoved(bundleName: string) {
console.log("removed bundle name: " + bundleName); console.info(`Succeeded in calling onBundleRemoved callback, removed bundle name : ${bundleName}`);
} }
}; };
``` ```
...@@ -118,7 +118,7 @@ Called when an application is started. ...@@ -118,7 +118,7 @@ Called when an application is started.
**Parameters** **Parameters**
| Parameter | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- | | ----- | ----------------------------------- | ---- | ------- |
| bundleName | string | Yes | Bundle name of the application started.| | bundleName | string | Yes | Bundle name of the application started.|
...@@ -127,7 +127,7 @@ Called when an application is started. ...@@ -127,7 +127,7 @@ Called when an application is started.
```ts ```ts
export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbility { export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbility {
onAppStart(bundleName: string) { onAppStart(bundleName: string) {
console.log("started bundle name: " + bundleName); console.info(`Succeeded in calling onAppStart callback, started bundle name : ${bundleName}`);
} }
}; };
``` ```
...@@ -144,7 +144,7 @@ Called when an application is stopped. ...@@ -144,7 +144,7 @@ Called when an application is stopped.
**Parameters** **Parameters**
| Parameter | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- | | ----- | ----------------------------------- | ---- | ------- |
| bundleName | string | Yes | Bundle name of the application stopped.| | bundleName | string | Yes | Bundle name of the application stopped.|
...@@ -153,7 +153,7 @@ Called when an application is stopped. ...@@ -153,7 +153,7 @@ Called when an application is stopped.
```ts ```ts
export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbility { export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbility {
onAppStop(bundleName: string) { onAppStop(bundleName: string) {
console.log("stopped bundle name: " + bundleName); console.info(`Succeeded in calling onAppStop callback, stopped bundle name : ${bundleName}`);
} }
}; };
``` ```
# @ohos.enterprise.accountManager (Account Management) # @ohos.enterprise.accountManager (Account Management)
The **accountManager** module provides APIs for account management of enterprise devices. Only the device administrator applications can call the APIs provided by this module. The **accountManager** module provides APIs for account management of enterprise devices.
> **NOTE** > **NOTE**
> >
> - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. > - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The APIs of this module can be called only after a [device administrator application](js-apis-enterprise-adminManager.md#adminmanagerenableadmin) is enabled. >
> - The APIs provided by this module can be called only by a [device administrator application](enterpriseDeviceManagement-overview.md#basic-concepts) that is [enabled](js-apis-enterprise-adminManager.md#adminmanagerenableadmin).
## Modules to Import ## Modules to Import
...@@ -46,13 +47,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -46,13 +47,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
accountManager.disallowAddLocalAccount(wantTemp, true, (error) => {
if (error != null) { accountManager.disallowAddLocalAccount(wantTemp, true, (err) => {
console.log("error code:" + error.code + " error message:" + error.message); if (err) {
} console.error(`Failed to disallow add local account. Code: ${err.code}, message: ${err.message}`);
return;
}
console.info('Succeeded in disallowing add local account');
}); });
``` ```
...@@ -94,12 +98,13 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -94,12 +98,13 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
accountManager.disallowAddLocalAccount(wantTemp, true).then(() => { accountManager.disallowAddLocalAccount(wantTemp, true).then(() => {
console.log("success"); console.info('Succeeded in disallowing add local account');
}).catch(error => { }).catch((err) => {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to disallow add local account. Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -4,7 +4,9 @@ The **adminManager** module provides enterprise device management capabilities s ...@@ -4,7 +4,9 @@ The **adminManager** module provides enterprise device management capabilities s
> **NOTE** > **NOTE**
> >
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. > - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> - The APIs provided by this module can be called only by a [device administrator application](enterpriseDeviceManagement-overview.md#basic-concepts).
## Modules to Import ## Modules to Import
...@@ -47,19 +49,20 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -47,19 +49,20 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
let enterpriseInfo = { let enterpriseInfo = {
name: "enterprise name", name: 'enterprise name',
description: "enterprise description" description: 'enterprise description'
} }
adminManager.enableAdmin(wantTemp, enterpriseInfo, adminManager.AdminType.ADMIN_TYPE_SUPER, error => {
if (error != null) { adminManager.enableAdmin(wantTemp, enterpriseInfo, adminManager.AdminType.ADMIN_TYPE_SUPER, (err) => {
console.log("error occurs" + error); if (err) {
return; console.error(`Failed to enable admin. Code: ${err.code}, message: ${err.message}`);
} return;
console.log("enableAdmin success"); }
console.info('Succeeded in enabling admin');
}); });
``` ```
...@@ -99,19 +102,20 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -99,19 +102,20 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
let enterpriseInfo = { let enterpriseInfo = {
name: "enterprise name", name: 'enterprise name',
description: "enterprise description" description: 'enterprise description'
} }
adminManager.enableAdmin(wantTemp, enterpriseInfo, adminManager.AdminType.ADMIN_TYPE_NORMAL, 100, error => {
if (error != null) { adminManager.enableAdmin(wantTemp, enterpriseInfo, adminManager.AdminType.ADMIN_TYPE_NORMAL, 100, (err) => {
console.log("error occurs" + error); if (err) {
return; console.error(`Failed to enable admin. Code: ${err.code}, message: ${err.message}`);
} return;
console.log("enableAdmin success"); }
console.info('Succeeded in enabling admin');
}); });
``` ```
...@@ -156,16 +160,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -156,16 +160,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
let enterpriseInfo = { let enterpriseInfo = {
name: "enterprise name", name: 'enterprise name',
description: "enterprise description" description: 'enterprise description'
} }
adminManager.enableAdmin(wantTemp, enterpriseInfo, adminManager.AdminType.ADMIN_TYPE_NORMAL, 100)
.catch(error => { adminManager.enableAdmin(wantTemp, enterpriseInfo, adminManager.AdminType.ADMIN_TYPE_NORMAL, 100).catch((err) => {
console.log("error occurs" + error); console.error(`Failed to enable admin. Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -200,15 +204,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -200,15 +204,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "bundleName", bundleName: 'bundleName',
abilityName: "abilityName", abilityName: 'abilityName',
}; };
adminManager.disableAdmin(wantTemp, error => {
if (error != null) { adminManager.disableAdmin(wantTemp, (err) => {
console.log("error occurs" + error); if (err) {
return; console.error(`Failed to disable admin. Code: ${err.code}, message: ${err.message}`);
} return;
console.log("disableAdmin success "); }
console.info('Succeeded in disabling admin');
}); });
``` ```
...@@ -244,15 +249,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -244,15 +249,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "bundleName", bundleName: 'bundleName',
abilityName: "abilityName", abilityName: 'abilityName',
}; };
adminManager.disableAdmin(wantTemp, 100, error => {
if (error != null) { adminManager.disableAdmin(wantTemp, 100, (err) => {
console.log("error occurs" + error); if (err) {
return; console.error(`Failed to disable admin. Code: ${err.code}, message: ${err.message}`);
} return;
console.log("disableAdmin success "); }
console.info('Succeeded in disabling admin');
}); });
``` ```
...@@ -293,11 +299,12 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -293,11 +299,12 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "bundleName", bundleName: 'bundleName',
abilityName: "abilityName", abilityName: 'abilityName',
}; };
adminManager.disableAdmin(wantTemp, 100).catch(error => {
console.log("error occurs" + error); adminManager.disableAdmin(wantTemp, 100).catch((err) => {
console.error(`Failed to disable admin. Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -324,20 +331,21 @@ Disables a super device administrator application based on the specified bundle ...@@ -324,20 +331,21 @@ Disables a super device administrator application based on the specified bundle
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ----------------------------------------------------------------- | | ------- | ----------------------------------------------------------------- |
| 9200005 | failed to disable the administrator application of the device. | | 9200005 | failed to disable the administrator application of the device. |
**Example** **Example**
```js ```js
let bundleName = "com.example.myapplication"; let bundleName = 'com.example.myapplication';
adminManager.disableSuperAdmin(bundleName, error => {
if (error != null) { adminManager.disableSuperAdmin(bundleName, (err) => {
console.log("error occurs" + error); if (err) {
return; console.error(`Failed to disable super admin. Code: ${err.code}, message: ${err.message}`);
} return;
console.log("disableSuperAdmin success"); }
console.info('Succeeded in disabling super admin');
}); });
``` ```
...@@ -376,9 +384,10 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -376,9 +384,10 @@ For details about the error codes, see [Enterprise Device Management Error Codes
**Example** **Example**
```js ```js
let bundleName = "com.example.myapplication"; let bundleName = 'com.example.myapplication';
adminManager.disableSuperAdmin(bundleName).catch(error => {
console.log("error occurs" + error); adminManager.disableSuperAdmin(bundleName).catch((err) => {
console.error(`Failed to disable super admin. Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -403,15 +412,16 @@ Checks whether a device administrator application of the current user is enabled ...@@ -403,15 +412,16 @@ Checks whether a device administrator application of the current user is enabled
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "bundleName", bundleName: 'bundleName',
abilityName: "abilityName", abilityName: 'abilityName',
}; };
adminManager.isAdminEnabled(wantTemp, (error, result) => {
if (error != null) { adminManager.isAdminEnabled(wantTemp, (err, result) => {
console.log("error occurs" + error); if (err) {
return; console.error(`Failed to query admin is enabled or not. Code: ${err.code}, message: ${err.message}`);
} return;
console.log("result is " + result); }
console.info(`Succeeded in querying admin is enabled or not, result : ${result}`);
}); });
``` ```
...@@ -437,15 +447,16 @@ Checks whether a device administrator application of the user specified by **use ...@@ -437,15 +447,16 @@ Checks whether a device administrator application of the user specified by **use
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "bundleName", bundleName: 'bundleName',
abilityName: "abilityName", abilityName: 'abilityName',
}; };
adminManager.isAdminEnabled(wantTemp, 100, (error, result) => {
if (error != null) { adminManager.isAdminEnabled(wantTemp, 100, (err, result) => {
console.log("error occurs" + error); if (err) {
return; console.error(`Failed to query admin is enabled. Code: ${err.code}, message: ${err.message}`);
} return;
console.log("result is " + result); }
console.info(`Succeeded in querying admin is enabled or not, result : ${result}`);
}); });
``` ```
...@@ -476,13 +487,14 @@ Checks whether a device administrator application of the specified user (if **us ...@@ -476,13 +487,14 @@ Checks whether a device administrator application of the specified user (if **us
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "bundleName", bundleName: 'bundleName',
abilityName: "abilityName", abilityName: 'abilityName',
}; };
adminManager.isAdminEnabled(wantTemp, 100).then((result) => { adminManager.isAdminEnabled(wantTemp, 100).then((result) => {
console.log("result is " + result); console.info(`Succeeded in querying admin is enabled or not, result : ${result}`);
}).catch(error => { }).catch((err) => {
console.log("error occurs" + error); console.error(`Failed to query admin is enabled or not. Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -506,13 +518,14 @@ Checks whether a super device administrator application is enabled based on the ...@@ -506,13 +518,14 @@ Checks whether a super device administrator application is enabled based on the
**Example** **Example**
```js ```js
let bundleName = "com.example.myapplication"; let bundleName = 'com.example.myapplication';
adminManager.isSuperAdmin(bundleName, (error, result) => {
if (error != null) { adminManager.isSuperAdmin(bundleName, (err, result) => {
console.log("error occurs" + error); if (err) {
return; console.error(`Failed to query admin is super admin or not. Code: ${err.code}, message: ${err.message}`);
} return;
console.log("result is " + result); }
console.info(`Succeeded in querying admin is super admin or not, result : ${result}`);
}); });
``` ```
...@@ -541,11 +554,12 @@ Checks whether a super device administrator application is enabled based on the ...@@ -541,11 +554,12 @@ Checks whether a super device administrator application is enabled based on the
**Example** **Example**
```js ```js
let bundleName = "com.example.myapplication"; let bundleName = 'com.example.myapplication';
adminManager.isSuperAdmin(bundleName).then((result) => { adminManager.isSuperAdmin(bundleName).then((result) => {
console.log("result is " + result); console.info(`Succeeded in querying admin is super admin or not, result : ${result}`);
}).catch(error => { }).catch((err) => {
console.log("error occurs" + error); console.error(`Failed to query admin is super admin or not. Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -581,19 +595,20 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -581,19 +595,20 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
let enterpriseInfo = { let enterpriseInfo = {
name: "enterprise name", name: 'enterprise name',
description: "enterprise description" description: 'enterprise description'
} }
adminManager.setEnterpriseInfo(wantTemp, enterpriseInfo, error => {
if (error != null) { adminManager.setEnterpriseInfo(wantTemp, enterpriseInfo, (err) => {
console.log("error occurs" + error); if (err) {
return; console.error(`Failed to set enterprise info. Code: ${err.code}, message: ${err.message}`);
} return;
console.log("setEnterpriseInfo success"); }
console.info('Succeeded in setting enterprise info');
}); });
``` ```
...@@ -634,15 +649,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -634,15 +649,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
let enterpriseInfo = { let enterpriseInfo = {
name: "enterprise name", name: 'enterprise name',
description: "enterprise description" description: 'enterprise description'
} }
adminManager.setEnterpriseInfo(wantTemp, enterpriseInfo).catch(error => {
console.log("error occurs" + error); adminManager.setEnterpriseInfo(wantTemp, enterpriseInfo).catch((err) => {
console.error(`Failed to set enterprise info. Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -675,16 +691,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -675,16 +691,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
adminManager.getEnterpriseInfo(wantTemp, (error, result) => {
if (error != null) { adminManager.getEnterpriseInfo(wantTemp, (err, result) => {
console.log("error occurs" + error); if (err) {
return; console.error(`Failed to get enterprise info. Code: ${err.code}, message: ${err.message}`);
} return;
console.log(result.name); }
console.log(result.description); console.info(`Succeeded in getting enterprise info, enterprise name : ${result.name}, enterprise description : ${result.description}`);
}); });
``` ```
...@@ -722,14 +738,14 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -722,14 +738,14 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
adminManager.getEnterpriseInfo(wantTemp).then((result) => { adminManager.getEnterpriseInfo(wantTemp).then((result) => {
console.log(result.name); console.info(`Succeeded in getting enterprise info, enterprise name : ${result.name}, enterprise description : ${result.description}`);
console.log(result.description); }).catch((err) => {
}).catch(error => { console.error(`Failed to get enterprise info. Code: ${err.code}, message: ${err.message}`);
console.log("error occurs" + error);
}); });
``` ```
...@@ -766,14 +782,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -766,14 +782,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "bundleName", bundleName: 'bundleName',
abilityName: "abilityName", abilityName: 'abilityName',
}; };
let events = [0, 1]; let events = [0, 1];
adminManager.subscribeManagedEvent(wantTemp, events, (error) => {
if (error) { adminManager.subscribeManagedEvent(wantTemp, events, (err) => {
console.log("error code:" + error.code + " error message:" + error.message); if (err) {
} console.error(`Failed to subscribe managed event. Code: ${err.code}, message: ${err.message}`);
return;
}
console.info('Succeeded in subscribe managed event');
}); });
``` ```
...@@ -815,13 +834,14 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -815,13 +834,14 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "bundleName", bundleName: 'bundleName',
abilityName: "abilityName", abilityName: 'abilityName',
}; };
let events = [0, 1]; let events = [0, 1];
adminManager.subscribeManagedEvent(wantTemp, events).then(() => { adminManager.subscribeManagedEvent(wantTemp, events).then(() => {
}).catch((error) => { }).catch((err) => {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to subscribe managed event. Code: ${err.code}, message: ${err.message}`);
}) })
``` ```
...@@ -858,14 +878,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -858,14 +878,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "bundleName", bundleName: 'bundleName',
abilityName: "abilityName", abilityName: 'abilityName',
}; };
let events = [0, 1]; let events = [0, 1];
adminManager.unsubscribeManagedEvent(wantTemp, events, (error) => {
if (error) { adminManager.unsubscribeManagedEvent(wantTemp, events, (err) => {
console.log("error code:" + error.code + " error message:" + error.message); if (err) {
} console.error(`Failed to unsubscribe managed event. Code: ${err.code}, message: ${err.message}`);
return;
}
console.info('Succeeded in unsubscribe managed event');
}); });
``` ```
...@@ -907,13 +930,14 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -907,13 +930,14 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "bundleName", bundleName: 'bundleName',
abilityName: "abilityName", abilityName: 'abilityName',
}; };
let events = [0, 1]; let events = [0, 1];
adminManager.unsubscribeManagedEvent(wantTemp, events).then(() => { adminManager.unsubscribeManagedEvent(wantTemp, events).then(() => {
}).catch((error) => { }).catch((err) => {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to unsubscribe managed event. Code: ${err.code}, message: ${err.message}`);
}) })
``` ```
...@@ -925,10 +949,10 @@ Defines the enterprise information of a device administrator application. ...@@ -925,10 +949,10 @@ Defines the enterprise information of a device administrator application.
**System API**: This is a system API. **System API**: This is a system API.
| Name | Type | Readable| Writable | Description | | Name | Type | Mandatory| Description |
| ----------- | --------| ---- | ----- | ------------------------------- | | ----------- | --------| ---- | ------------------------------- |
| name | string | Yes | No | Name of the enterprise to which the device administrator application belongs.| | name | string | Yes | Name of the enterprise to which the device administrator application belongs.|
| description | string | Yes | No | Description of the enterprise to which the device administrator application belongs.| | description | string | Yes | Description of the enterprise to which the device administrator application belongs.|
## AdminType ## AdminType
......
# @ohos.enterprise.applicationManager (Application Management) # @ohos.enterprise.applicationManager (Application Management)
The **applicationManager** module provides application management capabilities, including adding, removing, and obtaining the applications that are forbidden to run. Only the enterprise device administrator applications can call the APIs provided by this module. The **applicationManager** module provides application management capabilities, including adding, removing, and obtaining the applications that are forbidden to run.
> **NOTE** > **NOTE**
> >
> - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. > - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The APIs of this module can be called only after a [device administrator application](js-apis-enterprise-adminManager.md#adminmanagerenableadmin) is enabled. >
> - The APIs provided by this module can be called only by a [device administrator application](enterpriseDeviceManagement-overview.md#basic-concepts) that is [enabled](js-apis-enterprise-adminManager.md#adminmanagerenableadmin).
## Modules to Import ## Modules to Import
...@@ -37,7 +38,7 @@ Adds a list of applications that are forbidden to run by the current user throug ...@@ -37,7 +38,7 @@ Adds a list of applications that are forbidden to run by the current user throug
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ---------------------------------------------------------------------------- | | ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device. | | 9200001 | the application is not an administrator of the device. |
| 9200002 | the administrator application does not have permission to manage the device. | | 9200002 | the administrator application does not have permission to manage the device. |
...@@ -47,15 +48,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -47,15 +48,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
let appIds = ["com.example.myapplication"]; let appIds = ['com.example.myapplication'];
applicationManager.addDisallowedRunningBundles(wantTemp, appIds, (error) => { applicationManager.addDisallowedRunningBundles(wantTemp, appIds, (err) => {
if (error != null) { if (err) {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to add disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
} return;
}
console.info('Succeeded in adding disallowed running bundles');
}); });
``` ```
...@@ -84,7 +87,7 @@ Adds a list of applications that are forbidden to run by a given user through th ...@@ -84,7 +87,7 @@ Adds a list of applications that are forbidden to run by a given user through th
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ---------------------------------------------------------------------------- | | ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device. | | 9200001 | the application is not an administrator of the device. |
| 9200002 | the administrator application does not have permission to manage the device. | | 9200002 | the administrator application does not have permission to manage the device. |
...@@ -93,15 +96,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -93,15 +96,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
let appIds = ["com.example.myapplication"]; let appIds = ['com.example.myapplication'];
applicationManager.addDisallowedRunningBundles(wantTemp, appIds, 100, (error) => { applicationManager.addDisallowedRunningBundles(wantTemp, appIds, 100, (err) => {
if (error != null) { if (err) {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to add disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
} return;
}
console.info('Succeeded in adding disallowed running bundles');
}); });
``` ```
...@@ -135,7 +140,7 @@ Adds a list of applications that are forbiddedn to run by the specified user (if ...@@ -135,7 +140,7 @@ Adds a list of applications that are forbiddedn to run by the specified user (if
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ---------------------------------------------------------------------------- | | ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device. | | 9200001 | the application is not an administrator of the device. |
| 9200002 | the administrator application does not have permission to manage the device. | | 9200002 | the administrator application does not have permission to manage the device. |
...@@ -144,15 +149,15 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -144,15 +149,15 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
let appIds = ["com.example.myapplication"]; let appIds = ['com.example.myapplication'];
applicationManager.addDisallowedRunningBundles(wantTemp, appIds, 100).then(() => { applicationManager.addDisallowedRunningBundles(wantTemp, appIds, 100).then(() => {
console.log("success"); console.info('Succeeded in adding disallowed running bundles');
}).catch(error => { }).catch((err) => {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to add disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
}); });
``` ```
...@@ -180,7 +185,7 @@ Removes a list of applications that are forbiddedn to run by the current user th ...@@ -180,7 +185,7 @@ Removes a list of applications that are forbiddedn to run by the current user th
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ---------------------------------------------------------------------------- | | ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device. | | 9200001 | the application is not an administrator of the device. |
| 9200002 | the administrator application does not have permission to manage the device. | | 9200002 | the administrator application does not have permission to manage the device. |
...@@ -189,15 +194,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -189,15 +194,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
let appIds = ["com.example.myapplication"]; let appIds = ['com.example.myapplication'];
applicationManager.removeDisallowedRunningBundles(wantTemp, appIds, (error) => { applicationManager.removeDisallowedRunningBundles(wantTemp, appIds, (err) => {
if (error != null) { if (err) {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to remove disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
} return;
}
console.info('Succeeded in removing disallowed running bundles');
}); });
``` ```
...@@ -226,7 +233,7 @@ Removes a list of applications that are forbiddedn to run by the specified user ...@@ -226,7 +233,7 @@ Removes a list of applications that are forbiddedn to run by the specified user
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ---------------------------------------------------------------------------- | | ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device. | | 9200001 | the application is not an administrator of the device. |
| 9200002 | the administrator application does not have permission to manage the device. | | 9200002 | the administrator application does not have permission to manage the device. |
...@@ -235,15 +242,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -235,15 +242,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
let appIds = ["com.example.myapplication"]; let appIds = ['com.example.myapplication'];
applicationManager.removeDisallowedRunningBundles(wantTemp, appIds, 100, (error) => { applicationManager.removeDisallowedRunningBundles(wantTemp, appIds, 100, (err) => {
if (error != null) { if (err) {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to remove disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
} return;
}
console.info('Succeeded in removing disallowed running bundles');
}); });
``` ```
...@@ -277,7 +286,7 @@ Removes a list of applications that are forbiddedn to run by the specified user ...@@ -277,7 +286,7 @@ Removes a list of applications that are forbiddedn to run by the specified user
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ---------------------------------------------------------------------------- | | ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device. | | 9200001 | the application is not an administrator of the device. |
| 9200002 | the administrator application does not have permission to manage the device. | | 9200002 | the administrator application does not have permission to manage the device. |
...@@ -286,15 +295,15 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -286,15 +295,15 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
let appIds = ["com.example.myapplication"]; let appIds = ['com.example.myapplication'];
applicationManager.removeDisallowedRunningBundles(wantTemp, appIds, 100).then(() => { applicationManager.removeDisallowedRunningBundles(wantTemp, appIds, 100).then(() => {
console.log("success"); console.info('Succeeded in removing disallowed running bundles');
}).catch(error => { }).catch((err) => {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to remove disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
}); });
``` ```
...@@ -321,7 +330,7 @@ Obtains the list of applications that are firbidded to run by the current user t ...@@ -321,7 +330,7 @@ Obtains the list of applications that are firbidded to run by the current user t
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ---------------------------------------------------------------------------- | | ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device. | | 9200001 | the application is not an administrator of the device. |
| 9200002 | the administrator application does not have permission to manage the device. | | 9200002 | the administrator application does not have permission to manage the device. |
...@@ -330,14 +339,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -330,14 +339,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
applicationManager.getDisallowedRunningBundles(wantTemp, (error) => { applicationManager.getDisallowedRunningBundles(wantTemp, (err, result) => {
if (error != null) { if (err) {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to get disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
} return;
}
console.info(`Succeeded in getting disallowed running bundles, result : ${JSON.stringify(result)}`);
}); });
``` ```
...@@ -365,7 +376,7 @@ Obtains the list of applications that are firbidded to run by the specified user ...@@ -365,7 +376,7 @@ Obtains the list of applications that are firbidded to run by the specified user
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ---------------------------------------------------------------------------- | | ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device. | | 9200001 | the application is not an administrator of the device. |
| 9200002 | the administrator application does not have permission to manage the device. | | 9200002 | the administrator application does not have permission to manage the device. |
...@@ -374,14 +385,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -374,14 +385,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
applicationManager.getDisallowedRunningBundles(wantTemp, 100, (error) => { applicationManager.getDisallowedRunningBundles(wantTemp, 100, (err, result) => {
if (error != null) { if (err) {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to get disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
} return;
}
console.info(`Succeeded in getting disallowed running bundles, result : ${JSON.stringify(result)}`);
}); });
``` ```
...@@ -414,7 +427,7 @@ Obtains the list of applications that are firbidded to run by the specified user ...@@ -414,7 +427,7 @@ Obtains the list of applications that are firbidded to run by the specified user
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ---------------------------------------------------------------------------- | | ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device. | | 9200001 | the application is not an administrator of the device. |
| 9200002 | the administrator application does not have permission to manage the device. | | 9200002 | the administrator application does not have permission to manage the device. |
...@@ -423,12 +436,13 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -423,12 +436,13 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
applicationManager.getDisallowedRunningBundles(wantTemp, 100).then(() => {
console.log("success"); applicationManager.getDisallowedRunningBundles(wantTemp, 100).then((result) => {
}).catch(error => { console.info(`Succeeded in getting disallowed running bundles, result : ${JSON.stringify(result)}`);
console.log("error code:" + error.code + " error message:" + error.message); }).catch((err) => {
console.error(`Failed to get disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
}); });
``` ```
# @ohos.enterprise.bundleManager (Bundle Management) # @ohos.enterprise.bundleManager (Bundle Management)
The **bundleManager** module provides APIs for bundle management, including adding, obtaining, and removing a list of bundles that are allowed to install. Only the enterprise device administrator applications can call the APIs provided by this module. The **bundleManager** module provides APIs for bundle management, including adding, obtaining, and removing a list of bundles that are allowed to install.
> **NOTE** > **NOTE**
> >
> - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. > - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The APIs of this module can be called only after a [device administrator application](js-apis-enterprise-adminManager.md#adminmanagerenableadmin) is enabled. >
>
> - The APIs provided by this module can be called only by a [device administrator application](enterpriseDeviceManagement-overview.md#basic-concepts) that is [enabled](js-apis-enterprise-adminManager.md#adminmanagerenableadmin).
## Modules to Import ## Modules to Import
...@@ -46,15 +48,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -46,15 +48,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
let appIds = ["com.example.myapplication"]; let appIds = ['com.example.myapplication'];
bundleManager.addAllowedInstallBundles(wantTemp, appIds, (error) => { bundleManager.addAllowedInstallBundles(wantTemp, appIds, (err) => {
if (error != null) { if (err) {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to add allowed install bundles. Code is ${err.code}, message is ${err.message}`);
} return;
}
console.info('Succeeded in adding allowed install bundles');
}); });
``` ```
...@@ -92,15 +96,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -92,15 +96,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
let appIds = ["com.example.myapplication"]; let appIds = ['com.example.myapplication'];
bundleManager.addAllowedInstallBundles(wantTemp, appIds, 100, (error) => { bundleManager.addAllowedInstallBundles(wantTemp, appIds, 100, (err) => {
if (error != null) { if (err) {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to add allowed install bundles. Code is ${err.code}, message is ${err.message}`);
} return;
}
console.info('Succeeded in adding allowed install bundles');
}); });
``` ```
...@@ -143,15 +149,15 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -143,15 +149,15 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
let appIds = ["com.example.myapplication"]; let appIds = ['com.example.myapplication'];
bundleManager.addAllowedInstallBundles(wantTemp, appIds, 100).then(() => { bundleManager.addAllowedInstallBundles(wantTemp, appIds, 100).then(() => {
console.log("success"); console.info('Succeeded in adding allowed install bundles');
}).catch(error => { }).catch((err) => {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to add allowed install bundles. Code is ${err.code}, message is ${err.message}`);
}); });
``` ```
...@@ -188,15 +194,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -188,15 +194,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
let appIds = ["com.example.myapplication"]; let appIds = ['com.example.myapplication'];
bundleManager.removeAllowedInstallBundles(wantTemp, appIds, (error) => { bundleManager.removeAllowedInstallBundles(wantTemp, appIds, (err) => {
if (error != null) { if (err) {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to remove allowed install bundles. Code is ${err.code}, message is ${err.message}`);
} return;
}
console.info('Succeeded in removing allowed install bundles');
}); });
``` ```
...@@ -234,15 +242,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -234,15 +242,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
let appIds = ["com.example.myapplication"]; let appIds = ['com.example.myapplication'];
bundleManager.removeAllowedInstallBundles(wantTemp, appIds, 100, (error) => { bundleManager.removeAllowedInstallBundles(wantTemp, appIds, 100, (err) => {
if (error != null) { if (err) {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to remove allowed install bundles. Code is ${err.code}, message is ${err.message}`);
} return;
}
console.info('Succeeded in removing allowed install bundles');
}); });
``` ```
...@@ -285,15 +295,15 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -285,15 +295,15 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
let appIds = ["com.example.myapplication"]; let appIds = ['com.example.myapplication'];
bundleManager.removeAllowedInstallBundles(wantTemp, appIds, 100).then(() => { bundleManager.removeAllowedInstallBundles(wantTemp, appIds, 100).then(() => {
console.log("success"); console.info('Succeeded in removing allowed install bundles');
}).catch(error => { }).catch((err) => {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to remove allowed install bundles. Code is ${err.code}, message is ${err.message}`);
}); });
``` ```
...@@ -329,14 +339,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -329,14 +339,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
bundleManager.getAllowedInstallBundles(wantTemp, (error) => { bundleManager.getAllowedInstallBundles(wantTemp, (err, result) => {
if (error != null) { if (err) {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to get allowed install bundles. Code is ${err.code}, message is ${err.message}`);
} return;
}
console.info(`Succeeded in getting allowed install bundles, result : ${JSON.stringify(result)}`);
}); });
``` ```
...@@ -373,14 +385,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -373,14 +385,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
bundleManager.getAllowedInstallBundles(wantTemp, 100, (error) => { bundleManager.getAllowedInstallBundles(wantTemp, 100, (err, result) => {
if (error != null) { if (err) {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to get allowed install bundles. Code is ${err.code}, message is ${err.message}`);
} return;
}
console.info(`Succeeded in getting allowed install bundles, result : ${JSON.stringify(result)}`);
}); });
``` ```
...@@ -422,13 +436,14 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -422,13 +436,14 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
bundleManager.getAllowedInstallBundles(wantTemp, 100).then(() => {
console.log("success"); bundleManager.getAllowedInstallBundles(wantTemp, 100).then((result) => {
}).catch(error => { console.info(`Succeeded in getting allowed install bundles, result : ${JSON.stringify(result)}`);
console.log("error code:" + error.code + " error message:" + error.message); }).catch((err) => {
console.error(`Failed to get allowed install bundles. Code is ${err.code}, message is ${err.message}`);
}); });
``` ```
...@@ -465,15 +480,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -465,15 +480,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
let appIds = ["com.example.myapplication"]; let appIds = ['com.example.myapplication'];
bundleManager.addDisallowedInstallBundles(wantTemp, appIds, (error) => { bundleManager.addDisallowedInstallBundles(wantTemp, appIds, (err) => {
if (error != null) { if (err) {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to add disallowed install bundles. Code is ${err.code}, message is ${err.message}`);
} return;
}
console.info('Succeeded in adding disallowed install bundles');
}); });
``` ```
...@@ -511,15 +528,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -511,15 +528,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
let appIds = ["com.example.myapplication"]; let appIds = ['com.example.myapplication'];
bundleManager.addDisallowedInstallBundles(wantTemp, appIds, 100, (error) => { bundleManager.addDisallowedInstallBundles(wantTemp, appIds, 100, (err) => {
if (error != null) { if (err) {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to add disallowed install bundles. Code is ${err.code}, message is ${err.message}`);
} return;
}
console.info('Succeeded in adding disallowed install bundles');
}); });
``` ```
...@@ -562,15 +581,15 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -562,15 +581,15 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
let appIds = ["com.example.myapplication"]; let appIds = ['com.example.myapplication'];
bundleManager.addDisallowedInstallBundles(wantTemp, appIds, 100).then(() => { bundleManager.addDisallowedInstallBundles(wantTemp, appIds, 100).then(() => {
console.log("success"); console.info('Succeeded in adding disallowed install bundles');
}).catch(error => { }).catch((err) => {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to add disallowed install bundles. Code is ${err.code}, message is ${err.message}`);
}); });
``` ```
...@@ -607,15 +626,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -607,15 +626,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
let appIds = ["com.example.myapplication"]; let appIds = ['com.example.myapplication'];
bundleManager.removeDisallowedInstallBundles(wantTemp, appIds, (error) => { bundleManager.removeDisallowedInstallBundles(wantTemp, appIds, (err) => {
if (error != null) { if (err) {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to remove disallowed install bundles. Code is ${err.code}, message is ${err.message}`);
} return;
}
console.info('Succeeded in removing disallowed install bundles');
}); });
``` ```
...@@ -636,7 +657,7 @@ Removes a list of bundles that are not allowed to be installed by the given user ...@@ -636,7 +657,7 @@ Removes a list of bundles that are not allowed to be installed by the given user
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- | | ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. | | admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. |
| appIds | Array&lt;string&gt; | Yes | Bundles to be removed. | | appIds | Array&lt;string&gt; | Yes | Bundles to be added. |
| userId | number | Yes | User ID. The default value is the user ID of the caller. The user ID must be greater than or equal to **0**.| | userId | number | Yes | User ID. The default value is the user ID of the caller. The user ID must be greater than or equal to **0**.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|
...@@ -653,15 +674,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -653,15 +674,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
let appIds = ["com.example.myapplication"]; let appIds = ['com.example.myapplication'];
bundleManager.removeDisallowedInstallBundles(wantTemp, appIds, 100, (error) => { bundleManager.removeDisallowedInstallBundles(wantTemp, appIds, 100, (err) => {
if (error != null) { if (err) {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to remove disallowed install bundles. Code is ${err.code}, message is ${err.message}`);
} return;
}
console.info('Succeeded in removing disallowed install bundles');
}); });
``` ```
...@@ -704,15 +727,15 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -704,15 +727,15 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
let appIds = ["com.example.myapplication"]; let appIds = ['com.example.myapplication'];
bundleManager.removeDisallowedInstallBundles(wantTemp, appIds, 100).then(() => { bundleManager.removeDisallowedInstallBundles(wantTemp, appIds, 100).then(() => {
console.log("success"); console.info('Succeeded in removing disallowed install bundles');
}).catch(error => { }).catch((err) => {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to remove disallowed install bundles. Code is ${err.code}, message is ${err.message}`);
}); });
``` ```
...@@ -748,14 +771,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -748,14 +771,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
bundleManager.getDisallowedInstallBundles(wantTemp, (error) => { bundleManager.getDisallowedInstallBundles(wantTemp, (err, result) => {
if (error != null) { if (err) {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to get disallowed install bundles. Code is ${err.code}, message is ${err.message}`);
} return;
}
console.info(`Succeeded in getting disallowed install bundles, result : ${JSON.stringify(result)}`);
}); });
``` ```
...@@ -792,14 +817,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -792,14 +817,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
bundleManager.getDisallowedInstallBundles(wantTemp, 100, (error) => { bundleManager.getDisallowedInstallBundles(wantTemp, 100, (err, result) => {
if (error != null) { if (err) {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to get disallowed install bundles. Code is ${err.code}, message is ${err.message}`);
} return;
}
console.info(`Succeeded in getting disallowed install bundles, result : ${JSON.stringify(result)}`);
}); });
``` ```
...@@ -839,15 +866,18 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -839,15 +866,18 @@ For details about the error codes, see [Enterprise Device Management Error Codes
**Example** **Example**
```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
bundleManager.getDisallowedInstallBundles(wantTemp, 100).then(() => {
console.log("success"); bundleManager.getDisallowedInstallBundles(wantTemp, 100).then((result) => {
}).catch(error => { console.info(`Succeeded in getting disallowed install bundles, result : ${JSON.stringify(result)}`);
console.log("error code:" + error.code + " error message:" + error.message); }).catch((err) => {
console.error(`Failed to get disallowed install bundles. Code is ${err.code}, message is ${err.message}`);
}); });
```
## bundleManager.addDisallowedUninstallBundles ## bundleManager.addDisallowedUninstallBundles
...@@ -882,15 +912,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -882,15 +912,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
let appIds = ["com.example.myapplication"]; let appIds = ['com.example.myapplication'];
bundleManager.addDisallowedUninstallBundles(wantTemp, appIds, (error) => { bundleManager.addDisallowedUninstallBundles(wantTemp, appIds, (err) => {
if (error != null) { if (err) {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to add disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`);
} return;
}
console.info('Succeeded in adding disallowed uninstall bundles');
}); });
``` ```
...@@ -928,15 +960,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -928,15 +960,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
let appIds = ["com.example.myapplication"]; let appIds = ['com.example.myapplication'];
bundleManager.addDisallowedUninstallBundles(wantTemp, appIds, 100, (error) => { bundleManager.addDisallowedUninstallBundles(wantTemp, appIds, 100, (err) => {
if (error != null) { if (err) {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to add disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`);
} return;
}
console.info('Succeeded in adding disallowed uninstall bundles');
}); });
``` ```
...@@ -979,15 +1013,15 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -979,15 +1013,15 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
let appIds = ["com.example.myapplication"]; let appIds = ['com.example.myapplication'];
bundleManager.addDisallowedUninstallBundles(wantTemp, appIds, 100).then(() => { bundleManager.addDisallowedUninstallBundles(wantTemp, appIds, 100).then(() => {
console.log("success"); console.info('Succeeded in adding disallowed uninstall bundles');
}).catch(error => { }).catch((err) => {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to add disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`);
}); });
``` ```
...@@ -1008,7 +1042,7 @@ Removes a list of bundles that are not allowed to be uninstalled by the current ...@@ -1008,7 +1042,7 @@ Removes a list of bundles that are not allowed to be uninstalled by the current
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------------------- | | -------- | ---------------------------------------- | ---- | ------------------------------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. | | admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. |
| appIds | Array&lt;string&gt; | Yes | Bundles to be removed. | | appIds | Array&lt;string&gt; | Yes | Bundles to be added. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|
**Error codes** **Error codes**
...@@ -1024,15 +1058,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -1024,15 +1058,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
let appIds = ["com.example.myapplication"]; let appIds = ['com.example.myapplication'];
bundleManager.removeDisallowedUninstallBundles(wantTemp, appIds, (error) => { bundleManager.removeDisallowedUninstallBundles(wantTemp, appIds, (err) => {
if (error != null) { if (err) {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to remove disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`);
} return;
}
console.info('Succeeded in removing disallowed uninstall bundles');
}); });
``` ```
...@@ -1070,15 +1106,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -1070,15 +1106,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
let appIds = ["com.example.myapplication"]; let appIds = ['com.example.myapplication'];
bundleManager.removeDisallowedUninstallBundles(wantTemp, appIds, 100, (error) => { bundleManager.removeDisallowedUninstallBundles(wantTemp, appIds, 100, (err) => {
if (error != null) { if (err) {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to remove disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`);
} return;
}
console.info('Succeeded in removing disallowed uninstall bundles');
}); });
``` ```
...@@ -1121,15 +1159,15 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -1121,15 +1159,15 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
let appIds = ["com.example.myapplication"]; let appIds = ['com.example.myapplication'];
bundleManager.removeDisallowedUninstallBundles(wantTemp, appIds, 100).then(() => { bundleManager.removeDisallowedUninstallBundles(wantTemp, appIds, 100).then(() => {
console.log("success"); console.info('Succeeded in removing disallowed uninstall bundles');
}).catch(error => { }).catch((err) => {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to remove disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`);
}); });
``` ```
...@@ -1165,16 +1203,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -1165,16 +1203,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
bundleManager.getDisallowedUninstallBundles(wantTemp, (error, data) => { bundleManager.getDisallowedUninstallBundles(wantTemp, (err, result) => {
if (error != null) { if (err) {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to get disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`);
} else { return;
console.log("success: " + data); }
} console.info(`Succeeded in getting disallowed uninstall bundles, result : ${JSON.stringify(result)}`);
}); });
``` ```
...@@ -1211,16 +1249,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -1211,16 +1249,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
bundleManager.getDisallowedUninstallBundles(wantTemp, 100, (error, data) => { bundleManager.getDisallowedUninstallBundles(wantTemp, 100, (err, result) => {
if (error != null) { if (err) {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to get disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`);
} else { return;
console.log("success: " + data); }
} console.info(`Succeeded in getting disallowed uninstall bundles, result : ${JSON.stringify(result)}`);
}); });
``` ```
...@@ -1262,13 +1300,248 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -1262,13 +1300,248 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
};
bundleManager.getDisallowedUninstallBundles(wantTemp, 100).then((result) => {
console.info(`Succeeded in getting disallowed uninstall bundles, result : ${JSON.stringify(result)}`);
}).catch((err) => {
console.error(`Failed to get disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`);
});
```
## bundleManager.uninstall
uninstall(admin: Want, bundleName: string, callback: AsyncCallback&lt;void&gt;): void
Uninstalls the given bundle of the current user without retaining the bundle data through the specified device administrator application. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.ENTERPRISE_INSTALL_BUNDLE
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------------------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. |
| bundleName | string | Yes | Bundle name.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. |
**Error codes**
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device. |
| 9200002 | the administrator application does not have permission to manage the device. |
**Example**
```js
let wantTemp = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
bundleManager.uninstall(wantTemp, 'bundleName', (err) => {
if (err) {
console.error(`Failed to uninstall bundles. Code is ${err.code}, message is ${err.message}`);
}
console.info('Succeeded in uninstalling bundles');
});
```
## bundleManager.uninstall
uninstall(admin: Want, bundleName: string, userId: number, callback: AsyncCallback&lt;void&gt;): void
Uninstalls the given bundle of the user specified by **userId** without retaining the bundle data through the specified device administrator application. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.ENTERPRISE_INSTALL_BUNDLE
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------------------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. |
| bundleName | string | Yes | Bundle name.|
| userId | number | Yes | User ID. The default value is the user ID of the caller. The user ID must be greater than or equal to **0**.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. |
**Error codes**
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device. |
| 9200002 | the administrator application does not have permission to manage the device. |
**Example**
```js
let wantTemp = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
bundleManager.uninstall(wantTemp, 'bundleName', 100, (err) => {
if (err) {
console.error(`Failed to uninstall bundles. Code is ${err.code}, message is ${err.message}`);
}
console.info('Succeeded in uninstalling bundles');
});
```
## bundleManager.uninstall
uninstall(admin: Want, bundleName: string, isKeepData: boolean, callback: AsyncCallback&lt;void&gt;): void
Uninstalls the given bundle of the current user through the specified device administrator application. This API uses an asynchronous callback to return the result. If **isKeepData** is **false**, the bundle data is not retained.
**Required permissions**: ohos.permission.ENTERPRISE_INSTALL_BUNDLE
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------------------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. |
| bundleName | string | Yes | Bundle name.|
| isKeepData | boolean | Yes | Whether to retain the bundle data. The value **true** means to retain the bundle data; the value **false** means the opposite.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. |
**Error codes**
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device. |
| 9200002 | the administrator application does not have permission to manage the device. |
**Example**
```js
let wantTemp = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
}; };
bundleManager.getDisallowedUninstallBundles(wantTemp, 100).then((data) => {
console.log("success: " + data); bundleManager.uninstall(wantTemp, 'bundleName', true, (err) => {
}).catch(error => { if (err) {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to uninstall bundles. Code is ${err.code}, message is ${err.message}`);
}
console.info('Succeeded in uninstalling bundles');
}); });
```
## bundleManager.uninstall
uninstall(admin: Want, bundleName: string, userId: number, isKeepData: boolean, callback: AsyncCallback&lt;void&gt;): void
Uninstalls the given bundle of the user specified by **userId** through the specified device administrator application. This API uses an asynchronous callback to return the result. If **isKeepData** is **false**, the bundle data is not retained.
**Required permissions**: ohos.permission.ENTERPRISE_INSTALL_BUNDLE
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------------------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. |
| bundleName | string | Yes | Bundle name.|
| userId | number | Yes | User ID. The default value is the user ID of the caller. The user ID must be greater than or equal to **0**.|
| isKeepData | boolean | Yes | Whether to retain the bundle data. The value **true** means to retain the bundle data; the value **false** means the opposite.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. |
**Error codes**
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device. |
| 9200002 | the administrator application does not have permission to manage the device. |
**Example**
```js
let wantTemp = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
bundleManager.uninstall(wantTemp, 'bundleName', 100, true, (err) => {
if (err) {
console.error(`Failed to uninstall bundles. Code is ${err.code}, message is ${err.message}`);
}
console.info('Succeeded in uninstalling bundles');
});
```
## bundleManager.uninstall
uninstall(admin: Want, bundleName: string, userId?: number, isKeepData?: boolean): Promise&lt;void&gt;
Uninstalls the given bundle of the current user (if **userId** is not passed in) or the given user (if **userId** is passed in) through the specified device administrator application. This API uses a promise to return the result. If **isKeepData** is not passed in, the default value **false** is used, which means the bundle data will not be retained.
**Required permissions**: ohos.permission.ENTERPRISE_INSTALL_BUNDLE
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.|
| bundleName | string | Yes | Bundle name.|
| userId | number | No | User ID. The default value is the user ID of the caller. The user ID must be greater than or equal to **0**.|
| isKeepData | boolean | No | Whether to retain the bundle data. The value **true** means to retain the bundle data; the value **false** means the opposite.|
**Return value**
| Type | Description |
| --------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value. An error object will be thrown if the bundle fails to be uninstalled.|
**Error codes**
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device. |
| 9200002 | the administrator application does not have permission to manage the device. |
**Example**
```js
let wantTemp = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
bundleManager.uninstall(wantTemp, 'bundleName', 100, true).then(() => {
console.info('Succeeded in uninstalling bundles');
}).catch((err) => {
console.error(`Failed to uninstall bundles. Code is ${err.code}, message is ${err.message}`);
});
``` ```
# @ohos.enterprise.dateTimeManager (System Time Management) # @ohos.enterprise.dateTimeManager (System Time Management)
The **dateTimeManager** module provides APIs for system time management. Only the enterprise device administrator applications can call the APIs provided by this module. The **dateTimeManager** module provides APIs for system time management.
> **NOTE** > **NOTE**
> >
> - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. > - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The APIs of this module can be called only after a [device administrator application](js-apis-enterprise-adminManager.md#adminmanagerenableadmin) is enabled. >
> - The APIs provided by this module can be called only by a [device administrator application](enterpriseDeviceManagement-overview.md#basic-concepts) that is [enabled](js-apis-enterprise-adminManager.md#adminmanagerenableadmin).
## Modules to Import ## Modules to Import
...@@ -46,13 +47,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -46,13 +47,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "bundleName", bundleName: 'bundleName',
abilityName: "abilityName", abilityName: 'abilityName',
}; };
dateTimeManager.setDateTime(wantTemp, 1526003846000, (error) => {
if (error) { dateTimeManager.setDateTime(wantTemp, 1526003846000, (err) => {
console.log("error code:" + error.code + " error message:" + error.message); if (err) {
} console.error(`Failed to set date time. Code is ${err.code}, message is ${err.message}`);
return;
}
console.info('Succeeded in setting date time');
}) })
``` ```
...@@ -94,12 +98,14 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -94,12 +98,14 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "bundleName", bundleName: 'bundleName',
abilityName: "abilityName", abilityName: 'abilityName',
}; };
dateTimeManager.setDateTime(wantTemp, 1526003846000).then(() => { dateTimeManager.setDateTime(wantTemp, 1526003846000).then(() => {
}).catch((error) => { console.info('Succeeded in setting date time');
console.log("error code:" + error.code + " error message:" + error.message); }).catch((err) => {
console.error(`Failed to set date time. Code is ${err.code}, message is ${err.message}`);
}) })
``` ```
...@@ -136,13 +142,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -136,13 +142,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "bundleName", bundleName: 'bundleName',
abilityName: "abilityName", abilityName: 'abilityName',
}; };
dateTimeManager.disallowModifyDateTime(wantTemp, true, (error) => {
if (error) { dateTimeManager.disallowModifyDateTime(wantTemp, true, (err) => {
console.log("error code:" + error.code + " error message:" + error.message); if (err) {
} console.error(`Failed to disallow modify date time. Code is ${err.code}, message is ${err.message}`);
return;
}
console.info('Succeeded in disallowing modify date time');
}) })
``` ```
...@@ -184,12 +193,14 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -184,12 +193,14 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "bundleName", bundleName: 'bundleName',
abilityName: "abilityName", abilityName: 'abilityName',
}; };
dateTimeManager.disallowModifyDateTime(wantTemp, true).then(() => { dateTimeManager.disallowModifyDateTime(wantTemp, true).then(() => {
}).catch((error) => { console.info('Succeeded in disallowing modify date time');
console.log("error code:" + error.code + " error message:" + error.message); }).catch((err) => {
console.error(`Failed to disallow modify date time. Code is ${err.code}, message is ${err.message}`);
}) })
``` ```
...@@ -225,13 +236,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -225,13 +236,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "bundleName", bundleName: 'bundleName',
abilityName: "abilityName", abilityName: 'abilityName',
}; };
dateTimeManager.isModifyDateTimeDisallowed(wantTemp, (error) => {
if (error) { dateTimeManager.isModifyDateTimeDisallowed(wantTemp, (err, result) => {
console.log("error code:" + error.code + " error message:" + error.message); if (err) {
} console.error(`Failed to query modify date time is disallowed or not. Code is ${err.code}, message is ${err.message}`);
return;
}
console.info(`Succeeded in querying modify date time is disallowed : ${result}`);
}) })
``` ```
...@@ -272,11 +286,13 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -272,11 +286,13 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "bundleName", bundleName: 'bundleName',
abilityName: "abilityName", abilityName: 'abilityName',
}; };
dateTimeManager.isModifyDateTimeDisallowed(wantTemp).then(() => {
}).catch((error) => { dateTimeManager.isModifyDateTimeDisallowed(wantTemp).then((result) => {
console.log("error code:" + error.code + " error message:" + error.message); console.info(`Succeeded in querying modify date time is disallowed : ${result}`);
}).catch((err) => {
console.error(`Failed to query modify date time is disallowed or not. Code is ${err.code}, message is ${err.message}`);
}) })
``` ```
...@@ -3,9 +3,11 @@ ...@@ -3,9 +3,11 @@
The **deviceControl** module provides APIs for device control, which can be called only by device administrator applications. The **deviceControl** module provides APIs for device control, which can be called only by device administrator applications.
> **NOTE** > **NOTE**
> >
> - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. > - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The APIs of this module can be called only after a [device administrator application](js-apis-enterprise-adminManager.md#adminmanagerenableadmin) is enabled. >
>
> - The APIs provided by this module can be called only by a [device administrator application](enterpriseDeviceManagement-overview.md#basic-concepts) that is [enabled](js-apis-enterprise-adminManager.md#adminmanagerenableadmin).
## Modules to Import ## Modules to Import
...@@ -17,8 +19,7 @@ import deviceControl from '@ohos.enterprise.deviceControl' ...@@ -17,8 +19,7 @@ import deviceControl from '@ohos.enterprise.deviceControl'
resetFactory(admin: Want, callback: AsyncCallback\<void>): void resetFactory(admin: Want, callback: AsyncCallback\<void>): void
Restores factory settings. This API uses an asynchronous callback to return the result. Restores factory settings through the specified device administrator application. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.ENTERPRISE_RESET_DEVICE **Required permissions**: ohos.permission.ENTERPRISE_RESET_DEVICE
...@@ -46,13 +47,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -46,13 +47,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "bundleName", bundleName: 'bundleName',
abilityName: "abilityName", abilityName: 'abilityName',
}; };
deviceControl.resetFactory(wantTemp, (error) => {
if (error) { deviceControl.resetFactory(wantTemp, (err) => {
console.log("error code:" + error.code + " error message:" + error.message); if (err) {
} console.error(`Failed to reset factory. Code is ${err.code}, message is ${err.message}`);
return;
}
console.log('Succeeded in resetting factory');
}) })
``` ```
...@@ -78,7 +82,7 @@ Restores factory settings. This API uses a promise to return the result. ...@@ -78,7 +82,7 @@ Restores factory settings. This API uses a promise to return the result.
| Type | Description | | Type | Description |
| ----- | ----------------------------------- | | ----- | ----------------------------------- |
| Promise\<void> | Promise that returns no value. If the operation fails, an error object is thrown.| | Promise\<void> | Promise that returns no value. If the operation fails, an error object will be thrown.|
**Error codes** **Error codes**
...@@ -93,11 +97,12 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -93,11 +97,12 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "bundleName", bundleName: 'bundleName',
abilityName: "abilityName", abilityName: 'abilityName',
}; };
deviceControl.resetFactory(wantTemp).then(() => { deviceControl.resetFactory(wantTemp).then(() => {
}).catch((error) => { }).catch((err) => {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to reset factory. Code is ${err.code}, message is ${err.message}`);
}) })
``` ```
# @ohos.enterprise.deviceInfo (Device Information Management) # @ohos.enterprise.deviceInfo (Device Information Management)
The **deviceInfo** module provides APIs for enterprise device information management, including the API for obtaining device serial numbers. Only the enterprise device administrator applications can call the APIs provided by this module. The **deviceInfo** module provides APIs for enterprise device information management, including the API for obtaining device serial numbers.
> **NOTE** > **NOTE**
> >
> - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. > - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The APIs of this module can be called only after a [device administrator application](js-apis-enterprise-adminManager.md#adminmanagerenableadmin) is enabled. >
> - The APIs provided by this module can be called only by a [device administrator application](enterpriseDeviceManagement-overview.md#basic-concepts) that is [enabled](js-apis-enterprise-adminManager.md#adminmanagerenableadmin).
## Modules to Import ## Modules to Import
...@@ -45,15 +46,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -45,15 +46,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
deviceInfo.getDeviceSerial(wantTemp, (error, result) => {
if (error != null) { deviceInfo.getDeviceSerial(wantTemp, (err, result) => {
console.log("error code:" + error.code + " error message:" + error.message); if (err) {
return; console.error(`Failed to get device serial. Code: ${err.code}, message: ${err.message}`);
} return;
console.log(result); }
console.info(`Succeeded in getting device serial, result : ${result}`);
}); });
``` ```
...@@ -94,13 +96,14 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -94,13 +96,14 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
deviceInfo.getDeviceSerial(wantTemp).then((result) => { deviceInfo.getDeviceSerial(wantTemp).then((result) => {
console.log(result); console.info(`Succeeded in getting device serial, result : ${result}`);
}).catch(error => { }).catch((err) => {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to get device serial. Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -136,15 +139,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -136,15 +139,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
deviceInfo.getDisplayVersion(wantTemp, (error, result) => {
if (error != null) { deviceInfo.getDisplayVersion(wantTemp, (err, result) => {
console.log("error code:" + error.code + " error message:" + error.message); if (err) {
return; console.error(`Failed to get display version. Code: ${err.code}, message: ${err.message}`);
} return;
console.log(result); }
console.info(`Succeeded in getting display version, result : ${result}`);
}); });
``` ```
...@@ -185,13 +189,14 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -185,13 +189,14 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
deviceInfo.getDisplayVersion(wantTemp).then((result) => { deviceInfo.getDisplayVersion(wantTemp).then((result) => {
console.log(result); console.info(`Succeeded in getting display version, result : ${result}`);
}).catch(error => { }).catch((err) => {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to get display version. Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -227,15 +232,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -227,15 +232,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
deviceInfo.getDeviceName(wantTemp, (error, result) => {
if (error != null) { deviceInfo.getDeviceName(wantTemp, (err, result) => {
console.log("error code:" + error.code + " error message:" + error.message); if (err) {
return; console.error(`Failed to get device name. Code: ${err.code}, message: ${err.message}`);
} return;
console.log(result); }
console.info(`Succeeded in getting device name, result : ${result}`);
}); });
``` ```
...@@ -276,12 +282,13 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -276,12 +282,13 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
deviceInfo.getDeviceName(wantTemp).then((result) => { deviceInfo.getDeviceName(wantTemp).then((result) => {
console.log(result); console.info(`Succeeded in getting device name, result : ${result}`);
}).catch(error => { }).catch((err) => {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to get device name. Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
# @ohos.enterprise.deviceSettings (Device Settings Management)
The **deviceSettings** module provides APIs for setting enterprise devices, including obtaining the screen-off time of a device.
> **NOTE**
>
> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> The APIs provided by this module apply only to the [device administrator applications](enterpriseDeviceManagement-overview.md#basic-concepts). Before calling the APIs, you must enable the device administrator application(js-apis-enterprise-adminManager.md#adminmanagerenableadmin).
## Modules to Import
```js
import deviceSettings from '@ohos.enterprise.deviceSettings';
```
## deviceSettings.getScreenOffTime
getScreenOffTime(admin: Want, callback: AsyncCallback&lt;number&gt;): void
Obtains the screen-off time of a device through the specified device administrator application. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.ENTERPRISE_GET_SETTINGS
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------------------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the device screen-off time obtained. Otherwise, **err** is an error object. |
**Error codes**
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device. |
| 9200002 | the administrator application does not have permission to manage the device. |
**Example**
```js
let wantTemp = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
deviceSettings.getScreenOffTime(wantTemp, (err, result) => {
if (err) {
console.error(`Failed to get screen off time. Code: ${err.code}, message: ${err.message}`);
return;
}
console.info(`Succeeded in getting screen off time, result : ${result}`);
});
```
## deviceSettings.getScreenOffTime
getScreenOffTime(admin: Want): Promise&lt;number&gt;
Obtains the screen-off time of a device through the specified device administrator application. This API uses a promise to return the result.
**Required permissions**: ohos.permission.ENTERPRISE_GET_SETTINGS
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.|
**Return value**
| Type | Description |
| --------------------- | ------------------------- |
| Promise&lt;number&gt; | Promise used to return the device screen-off time. |
**Error codes**
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device. |
| 9200002 | the administrator application does not have permission to manage the device. |
**Example**
```js
let wantTemp = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
deviceSettings.getScreenOffTime(wantTemp).then((result) => {
console.info(`Succeeded in getting screen off time, result : ${result}`);
}).catch((err) => {
console.error(`Failed to get screen off time. Code: ${err.code}, message: ${err.message}`);
});
```
# @ohos.enterprise.networkManager (Network Management) # @ohos.enterprise.networkManager (Network Management)
The **networkManager** module provides APIs for network management of enterprise devices, including obtaining the device IP address and MAC address. Only the device administrator applications can call the APIs provided by this module. The **networkManager** module provides APIs for network management of enterprise devices, including obtaining the device IP address and MAC address.
> **NOTE** > **NOTE**
> >
> - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The APIs of this module can be called only after a [device administrator application](js-apis-enterprise-adminManager.md#adminmanagerenableadmin) is enabled. >
> The APIs provided by this module can be called only by a [device administrator application](enterpriseDeviceManagement-overview.md#basic-concepts) that is [enabled](js-apis-enterprise-adminManager.md#adminmanagerenableadmin).
## Modules to Import ## Modules to Import
...@@ -29,14 +30,14 @@ Obtains all active network interfaces through the specified device administrator ...@@ -29,14 +30,14 @@ Obtains all active network interfaces through the specified device administrator
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------------------- | | -------- | ---------------------------------------- | ---- | ------------------------------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application that obtains the information. | | admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. |
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is an array of network interfaces obtained. If the operation fails, **err** is an error object. | | callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is an array of network interfaces obtained. If the operation fails, **err** is an error object. |
**Error codes** **Error codes**
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ---------------------------------------------------------------------------- | | ------- | ---------------------------------------------------------------------------- |
| 9200001 | The application is not an administrator application of the device. | | 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device.| | 9200002 | The administrator application does not have permission to manage the device.|
...@@ -45,15 +46,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -45,15 +46,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
networkManager.getAllNetworkInterfaces(wantTemp, (error, result) => {
if (error != null) { networkManager.getAllNetworkInterfaces(wantTemp, (err, result) => {
console.log("error code:" + error.code + " error message:" + error.message); if (err) {
return; console.error(`Failed to get all network interfaces. Code: ${err.code}, message: ${err.message}`);
} return;
console.log(JSON.stringify(result)); }
console.info(`Succeeded in getting all network interfaces, result : ${JSON.stringify(result)}`);
}); });
``` ```
...@@ -73,7 +75,7 @@ Obtains all active network interfaces through the specified device administrator ...@@ -73,7 +75,7 @@ Obtains all active network interfaces through the specified device administrator
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- | | ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application that obtains the information.| | admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.|
**Return value** **Return value**
...@@ -85,7 +87,7 @@ Obtains all active network interfaces through the specified device administrator ...@@ -85,7 +87,7 @@ Obtains all active network interfaces through the specified device administrator
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ---------------------------------------------------------------------------- | | ------- | ---------------------------------------------------------------------------- |
| 9200001 | The application is not an administrator application of the device. | | 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device.| | 9200002 | The administrator application does not have permission to manage the device.|
...@@ -94,13 +96,14 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -94,13 +96,14 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
networkManager.getAllNetworkInterfaces(wantTemp).then((result) => { networkManager.getAllNetworkInterfaces(wantTemp).then((result) => {
console.log(JSON.stringify(result)); console.info(`Succeeded in getting all network interfaces, result : ${JSON.stringify(result)}`);
}).catch(error => { }).catch((err) => {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to get all network interfaces. Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -120,7 +123,7 @@ Obtains the device IP address based on the given network interface through the s ...@@ -120,7 +123,7 @@ Obtains the device IP address based on the given network interface through the s
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------------------- | | -------- | ---------------------------------------- | ---- | ------------------------------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application that obtains the information. | | admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. |
| networkInterface | string | Yes | Network interface. | | networkInterface | string | Yes | Network interface. |
| callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the IP address obtained. If the operation fails, **err** is an error object. | | callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the IP address obtained. If the operation fails, **err** is an error object. |
...@@ -128,7 +131,7 @@ Obtains the device IP address based on the given network interface through the s ...@@ -128,7 +131,7 @@ Obtains the device IP address based on the given network interface through the s
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ---------------------------------------------------------------------------- | | ------- | ---------------------------------------------------------------------------- |
| 9200001 | The application is not an administrator application of the device. | | 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device.| | 9200002 | The administrator application does not have permission to manage the device.|
...@@ -137,15 +140,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -137,15 +140,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
networkManager.getIpAddress(wantTemp, "eth0", (error, result) => {
if (error != null) { networkManager.getIpAddress(wantTemp, 'eth0', (err, result) => {
console.log("error code:" + error.code + " error message:" + error.message); if (err) {
return; console.error(`Failed to get ip address. Code: ${err.code}, message: ${err.message}`);
} return;
console.log(result); }
console.info(`Succeeded in getting ip address, result : ${result}`);
}); });
``` ```
...@@ -165,7 +169,7 @@ Obtains the device IP address based on the given network interface through the s ...@@ -165,7 +169,7 @@ Obtains the device IP address based on the given network interface through the s
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- | | ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application that obtains the information.| | admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.|
| networkInterface | string | Yes | Network interface. | | networkInterface | string | Yes | Network interface. |
**Return value** **Return value**
...@@ -178,7 +182,7 @@ Obtains the device IP address based on the given network interface through the s ...@@ -178,7 +182,7 @@ Obtains the device IP address based on the given network interface through the s
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ---------------------------------------------------------------------------- | | ------- | ---------------------------------------------------------------------------- |
| 9200001 | The application is not an administrator application of the device. | | 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device.| | 9200002 | The administrator application does not have permission to manage the device.|
...@@ -187,13 +191,14 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -187,13 +191,14 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
networkManager.getIpAddress(wantTemp, "eth0").then((result) => {
console.log(result); networkManager.getIpAddress(wantTemp, 'eth0').then((result) => {
}).catch(error => { console.info(`Succeeded in getting ip address, result : ${result}`);
console.log("error code:" + error.code + " error message:" + error.message); }).catch((err) => {
console.error(`Failed to get ip address. Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -213,7 +218,7 @@ Obtains the device MAC address based on the given network interface through the ...@@ -213,7 +218,7 @@ Obtains the device MAC address based on the given network interface through the
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------------------- | | -------- | ---------------------------------------- | ---- | ------------------------------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application that obtains the information. | | admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. |
| networkInterface | string | Yes | Network interface. | | networkInterface | string | Yes | Network interface. |
| callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the MAC address obtained. If the operation fails, **err** is an error object. | | callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the MAC address obtained. If the operation fails, **err** is an error object. |
...@@ -221,7 +226,7 @@ Obtains the device MAC address based on the given network interface through the ...@@ -221,7 +226,7 @@ Obtains the device MAC address based on the given network interface through the
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ---------------------------------------------------------------------------- | | ------- | ---------------------------------------------------------------------------- |
| 9200001 | The application is not an administrator application of the device. | | 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device.| | 9200002 | The administrator application does not have permission to manage the device.|
...@@ -230,21 +235,22 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -230,21 +235,22 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
networkManager.getMac(wantTemp, "eth0", (error, result) => {
if (error != null) { networkManager.getMac(wantTemp, 'eth0', (err, result) => {
console.log("error code:" + error.code + " error message:" + error.message); if (err) {
return; console.error(`Failed to get mac. Code: ${err.code}, message: ${err.message}`);
} return;
console.log(result); }
console.info(`Succeeded in getting mac, result : ${result}`);
}); });
``` ```
## networkManager.getMac ## networkManager.getMac
getIpAddress(admin: Want, networkInterface: string): Promise&lt;string&gt; getMac(admin: Want, networkInterface: string): Promise\<string>;
Obtain the device MAC address based on the given network interface through the specified device administrator application. This API uses a promise to return the result. Obtain the device MAC address based on the given network interface through the specified device administrator application. This API uses a promise to return the result.
...@@ -258,7 +264,7 @@ Obtain the device MAC address based on the given network interface through the s ...@@ -258,7 +264,7 @@ Obtain the device MAC address based on the given network interface through the s
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- | | ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application that obtains the information.| | admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.|
| networkInterface | string | Yes | Network interface. | | networkInterface | string | Yes | Network interface. |
**Return value** **Return value**
...@@ -271,7 +277,7 @@ Obtain the device MAC address based on the given network interface through the s ...@@ -271,7 +277,7 @@ Obtain the device MAC address based on the given network interface through the s
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ---------------------------------------------------------------------------- | | ------- | ---------------------------------------------------------------------------- |
| 9200001 | The application is not an administrator application of the device. | | 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device.| | 9200002 | The administrator application does not have permission to manage the device.|
...@@ -280,13 +286,14 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -280,13 +286,14 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
networkManager.getMac(wantTemp, "eth0").then((result) => {
console.log(result); networkManager.getMac(wantTemp, 'eth0').then((result) => {
}).catch(error => { console.info(`Succeeded in getting mac, result : ${result}`);
console.log("error code:" + error.code + " error message:" + error.message); }).catch((err) => {
console.error(`Failed to get mac. Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -306,7 +313,7 @@ Checks whether a network interface is disabled through the specified device admi ...@@ -306,7 +313,7 @@ Checks whether a network interface is disabled through the specified device admi
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------------------- | | -------- | ---------------------------------------- | ---- | ------------------------------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application that obtains the information. | | admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. |
| networkInterface | string | Yes | Network interface. | | networkInterface | string | Yes | Network interface. |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**, and **data** indicates whether the network interface is disabled. The value **true** means the network interface is disabled; and **false** means the opposite. If the operation fails, **err** is an error object. | | callback | AsyncCallback&lt;boolean&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**, and **data** indicates whether the network interface is disabled. The value **true** means the network interface is disabled; and **false** means the opposite. If the operation fails, **err** is an error object. |
...@@ -314,7 +321,7 @@ Checks whether a network interface is disabled through the specified device admi ...@@ -314,7 +321,7 @@ Checks whether a network interface is disabled through the specified device admi
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ---------------------------------------------------------------------------- | | ------- | ---------------------------------------------------------------------------- |
| 9200001 | The application is not an administrator application of the device. | | 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device.| | 9200002 | The administrator application does not have permission to manage the device.|
...@@ -323,15 +330,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -323,15 +330,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
networkManager.isNetworkInterfaceDisabled(wantTemp, "eth0", (error, result) => {
if (error != null) { networkManager.isNetworkInterfaceDisabled(wantTemp, 'eth0', (err, result) => {
console.log("error code:" + error.code + " error message:" + error.message); if (err) {
return; console.error(`Failed to query network interface is disabled or not. Code: ${err.code}, message: ${err.message}`);
} return;
console.log("result:" + result); }
console.info(`Succeeded in querying network interface is disabled or not, result : ${result}`);
}); });
``` ```
...@@ -351,7 +359,7 @@ Checks whether a network interface is disabled through the specified device admi ...@@ -351,7 +359,7 @@ Checks whether a network interface is disabled through the specified device admi
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- | | ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application that obtains the information.| | admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.|
| networkInterface | string | Yes | Network interface. | | networkInterface | string | Yes | Network interface. |
**Return value** **Return value**
...@@ -364,7 +372,7 @@ Checks whether a network interface is disabled through the specified device admi ...@@ -364,7 +372,7 @@ Checks whether a network interface is disabled through the specified device admi
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ---------------------------------------------------------------------------- | | ------- | ---------------------------------------------------------------------------- |
| 9200001 | The application is not an administrator application of the device. | | 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device.| | 9200002 | The administrator application does not have permission to manage the device.|
...@@ -373,13 +381,14 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -373,13 +381,14 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
networkManager.isNetworkInterfaceDisabled(wantTemp, "eth0").then((result) => {
console.log("result:" + result); networkManager.isNetworkInterfaceDisabled(wantTemp, 'eth0').then((result) => {
}).catch(error => { console.info(`Succeeded in querying network interface is disabled or not, result : ${result}`);
console.log("error code:" + error.code + " error message:" + error.message); }).catch((err) => {
console.error(`Failed to query network interface is disabled or not. Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -399,7 +408,7 @@ Sets a network interface through the specified device administrator application. ...@@ -399,7 +408,7 @@ Sets a network interface through the specified device administrator application.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------------------- | | -------- | ---------------------------------------- | ---- | ------------------------------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application that obtains the information. | | admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. |
| networkInterface | string | Yes | Network interface. | | networkInterface | string | Yes | Network interface. |
| isDisabled | boolean | Yes | Network interface status to set. The value **true** means to disable the network interface, and **false** means to enable the network interface. | | isDisabled | boolean | Yes | Network interface status to set. The value **true** means to disable the network interface, and **false** means to enable the network interface. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. |
...@@ -417,15 +426,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -417,15 +426,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
networkManager.setNetworkInterfaceDisabled(wantTemp, "eth0", true, (error) => {
if (error != null) { networkManager.setNetworkInterfaceDisabled(wantTemp, 'eth0', true, (err) => {
console.log("error code:" + error.code + " error message:" + error.message); if (err) {
return; console.error(`Failed to set network interface disabled. Code: ${err.code}, message: ${err.message}`);
} return;
console.log("setNetworkInterfaceDisabled success!"); }
console.info(`Succeeded in setting network interface disabled`);
}); });
``` ```
...@@ -445,7 +455,7 @@ Sets a network interface through the specified device administrator application. ...@@ -445,7 +455,7 @@ Sets a network interface through the specified device administrator application.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- | | ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application that obtains the information.| | admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.|
| networkInterface | string | Yes | Network interface. | | networkInterface | string | Yes | Network interface. |
| isDisabled | boolean | Yes | Network interface status to set. The value **true** means to disable the network interface, and **false** means to enable the network interface. | | isDisabled | boolean | Yes | Network interface status to set. The value **true** means to disable the network interface, and **false** means to enable the network interface. |
...@@ -468,12 +478,434 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -468,12 +478,434 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
networkManager.setNetworkInterfaceDisabled(wantTemp, "eth0", true).then(() => {
console.log("setNetworkInterfaceDisabled success!"); networkManager.setNetworkInterfaceDisabled(wantTemp, 'eth0', true).then(() => {
}).catch(error => { console.info(`Succeeded in setting network interface disabled`);
console.log("error code:" + error.code + " error message:" + error.message); }).catch((err) => {
console.error(`Failed to set network interface disabled. Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
## networkManager.addIptablesFilterRule
addIptablesFilterRule(admin: Want, filterRule: AddFilterRule, callback: AsyncCallback\<void>): void
Adds a network packet filtering rule through the specified device administrator application. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------------------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. |
| filterRule | [AddFilterRule](#addfilterrule) | Yes | Network packet filtering rule to add. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. |
**Error codes**
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device.|
**Example**
```js
let wantTemp = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let filterRule = {
"ruleNo": 1,
"srcAddr": "192.168.1.1-192.188.22.66",
"destAddr": "10.1.1.1",
"srcPort": "8080",
"destPort": "8080",
"uid": "9696",
"method": networkManager.AddMethod.APPEND,
"direction": networkManager.Direction.OUTPUT,
"action": networkManager.Action.DENY,
"protocol": networkManager.Protocol.UDP,
}
networkManager.addIptablesFilterRule(wantTemp, filterRule, (err) => {
if (err) {
console.error(`Failed to set iptables filter rule. Code: ${err.code}, message: ${err.message}`);
return;
}
console.info(`Succeeded in setting iptables filter rule`);
});
```
## networkManager.addIptablesFilterRule
addIptablesFilterRule(admin: Want, filterRule: AddFilterRule): Promise\<void>
Adds a network packet filtering rule through the specified device administrator application. This API uses a promise to return the result.
**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.|
| filterRule | [AddFilterRule](#addfilterrule) | Yes | Network packet filtering rule to add. |
**Return value**
| Type | Description |
| --------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value. If the operation fails, an error object will be thrown. |
**Error codes**
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device.|
**Example**
```js
let wantTemp = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let filterRule = {
"ruleNo": 1,
"srcAddr": "192.168.1.1-192.188.22.66",
"destAddr": "10.1.1.1",
"srcPort": "8080",
"destPort": "8080",
"uid": "9696",
"method": networkManager.AddMethod.APPEND,
"direction": networkManager.Direction.OUTPUT,
"action": networkManager.Action.DENY,
"protocol": networkManager.Protocol.UDP,
}
networkManager.addIptablesFilterRule(wantTemp, filterRule).then(() => {
console.info(`Succeeded in setting iptables filter rule`);
}).catch((err) => {
console.error(`Failed to set iptables filter rule. Code: ${err.code}, message: ${err.message}`);
});
```
## networkManager.removeIptablesFilterRule
removeIptablesFilterRule(admin: Want, filterRule: RemoveFilterRule, callback: AsyncCallback\<void>): void
Removes a network packet filtering rule through the specified device administrator application. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------------------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. |
| filterRule | [RemoveFilterRule](#removefilterrule) | Yes | Network packet filtering rule to remove. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. |
**Error codes**
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device.|
**Example**
```js
let wantTemp = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let filterRule = {
"srcAddr": "192.168.1.1-192.188.22.66",
"destAddr": "10.1.1.1",
"srcPort": "8080",
"destPort": "8080",
"uid": "9696",
"direction": networkManager.Direction.OUTPUT,
"action": networkManager.Action.DENY,
"protocol": networkManager.Protocol.UDP,
}
networkManager.removeIptablesFilterRule(wantTemp, filterRule, (err) => {
if (err) {
console.error(`Failed to remove iptables filter rule. Code: ${err.code}, message: ${err.message}`);
return;
}
console.info(`Succeeded in removing iptables filter rule`);
});
```
## networkManager.removeIptablesFilterRule
removeIptablesFilterRule(admin: Want, filterRule: RemoveFilterRule): Promise\<void>
Removes a network packet filtering rule through the specified device administrator application. This API uses a promise to return the result.
**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.|
| filterRule | [RemoveFilterRule](#removefilterrule) | Yes | Network packet filtering rule to remove. |
**Return value**
| Type | Description |
| --------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value. If the operation fails, an error object will be thrown. |
**Error codes**
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device.|
**Example**
```js
let wantTemp = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let filterRule = {
"srcAddr": "192.168.1.1-192.188.22.66",
"destAddr": "10.1.1.1",
"srcPort": "8080",
"destPort": "8080",
"uid": "9696",
"direction": networkManager.Direction.OUTPUT,
"action": networkManager.Action.DENY,
"protocol": networkManager.Protocol.UDP,
}
networkManager.removeIptablesFilterRule(wantTemp, filterRule).then(() => {
console.info(`Succeeded in removing iptables filter rule`);
}).catch((err) => {
console.error(`Failed to remove iptables filter rule. Code: ${err.code}, message: ${err.message}`);
});
```
## networkManager.listIptablesFilterRules
listIptablesFilterRules(admin: Want, callback: AsyncCallback\<string>): void
Obtain the network packet filtering rules through the specified device administrator application. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------------------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. |
| callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. |
**Error codes**
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device.|
**Example**
```js
let wantTemp = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
networkManager.listIptablesFilterRules(wantTemp, (err, result) => {
if (err) {
console.error(`Failed to get iptables filter rule. Code: ${err.code}, message: ${err.message}`);
return;
}
console.info(`Succeeded in getting iptables filter rule, result : ${result}`);
});
```
## networkManager.listIptablesFilterRules
listIptablesFilterRules(admin: Want): Promise\<string>
Obtain the network packet filtering rules through the specified device administrator application. This API uses a promise to return the result.
**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.|
**Return value**
| Type | Description |
| --------------------- | ------------------------- |
| Promise&lt;string&gt; | Promise used to return the network packet filtering rules obtained. |
**Error codes**
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device.|
**Example**
```js
let wantTemp = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
networkManager.listIptablesFilterRules(wantTemp).then((result) => {
console.info(`Succeeded in getting iptables filter rule, result: ${result}`);
}).catch((err) => {
console.error(`Failed to remove iptables filter rule. Code: ${err.code}, message: ${err.message}`);
});
```
## AddFilterRule
Defines the network packet filtering rule to add.
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
| Name | Type | Mandatory| Description |
| ----------- | --------| ---- | ------------------------------- |
| ruleNo | number | No | Sequence number of the rule.|
| srcAddr | string | No | Source IP address.|
| destAddr | string | No | Destination IP address.|
| srcPort | string | No | Port of the source IP address.|
| destPort | string | No | Port of the destination IP address.|
| uid | string | No | UID of the application.|
| method | [AddMethod](#addmethod) | Yes | Method used to add the data packets.|
| direction | [Direction](#direction) | Yes | Direction for which the rule applies.|
| action | [Action](#action) | Yes | Action to take, that is, receive or discard the data packets.|
| protocol | [Protocol](#protocol) | No | Network protocol.|
## RemoveFilterRule
Defines the network packet filtering rule to remove.
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
| Name | Type | Mandatory| Description |
| ----------- | --------| ---- | ------------------------------- |
| srcAddr | string | No | Source IP address.|
| destAddr | string | No | Destination IP address.|
| srcPort | string | No | Port of the source IP address.|
| destPort | string | No | Port of the destination IP address.|
| uid | string | No | UID of the application.|
| direction | [Direction](#direction) | Yes | Direction for which the rule applies.|
| action | [Action](#action) | No | Action to take, that is, receive or discard the data packets.|
| protocol | [Protocol](#protocol) | No | Network protocol.|
## AddMethod
Enumerates the methods used to add the network packets.
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
| Name| Value| Description|
| -------- | -------- | -------- |
| APPEND | 0 | Append the packet.|
| INSERT | 1 | Insert the packet.|
## Direction
Enumerates the directions to which the rule applies.
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
| Name| Value| Description|
| -------- | -------- | -------- |
| INPUT | 0 | Input.|
| OUTPUT | 1 | Output.|
## Action
Enumerates the actions that can be taken for the data packets.
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
| Name| Value| Description|
| -------- | -------- | -------- |
| ALLOW | 0 | Receive the data packets.|
| DENY | 1 | Discard the data packets.|
## Protocol
Enumerates the network protocols supported.
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
| Name| Value| Description|
| -------- | -------- | -------- |
| ALL | 0 | All network protocols.|
| TCP | 1 | TCP.|
| UDP | 2 | UDP.|
| ICMP | 3 | ICMP.|
# @ohos.enterprise.restrictions (Restrictions)
This **restrictions** module provides APIs for setting general restriction policies, including disabling or enabling device printing and HDC.
> **NOTE**
>
> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> The APIs provided by this module can be called only by a [device administrator application](enterpriseDeviceManagement-overview.md#basic-concepts) that is [enabled](js-apis-enterprise-adminManager.md#adminmanagerenableadmin).
## Modules to Import
```js
import restrictions from '@ohos.enterprise.restrictions'
```
## restrictions.setPrinterDisabled
setPrinterDisabled(admin: Want, disabled: boolean, callback: AsyncCallback\<void>): void
Enables or disables device printing through the specified device administrator application. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.ENTERPRISE_RESTRICT_POLICY
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.|
| disabled | boolean | Yes| Whether to disable device printing. The value **true** means to disable device printing; the value **false** means the opposite.|
| callback | AsyncCallback\<void> | Yes| Callback invoked to return the result.<br> If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device. |
| 9200002 | the administrator application does not have permission to manage the device. |
**Example**
```js
let wantTemp = {
bundleName: 'bundleName',
abilityName: 'abilityName',
};
restrictions.setPrinterDisabled(wantTemp, true, (err) => {
if (err) {
console.error(`Failed to set printer disabled. Code is ${err.code}, message is ${err.message}`);
return;
}
console.info('Succeeded in setting printer disabled');
})
```
## restrictions.setPrinterDisabled
setPrinterDisabled(admin: Want, disabled: boolean): Promise\<void>
Enables or disables device printing through the specified device administrator application. This API uses a promise to return the result.
**Required permissions**: ohos.permission.ENTERPRISE_RESTRICT_POLICY
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.|
| disabled | boolean | Yes| Whether to disable device printing. The value **true** means to disable device printing; the value **false** means the opposite.|
**Return value**
| Type | Description |
| ----- | ----------------------------------- |
| Promise\<void> | Promise that returns no value. An error object will be thrown if the specified device administrator application fails to disable or enable the device printing function.|
**Error codes**
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device. |
| 9200002 | the administrator application does not have permission to manage the device. |
**Example**
```js
let wantTemp = {
bundleName: 'bundleName',
abilityName: 'abilityName',
};
restrictions.setPrinterDisabled(wantTemp, true).then(() => {
console.info('Succeeded in setting printer disabled');
}).catch((err) => {
console.error(`Failed to set printer disabled. Code is ${err.code}, message is ${err.message}`);
})
```
## restrictions.isPrinterDisabled
isPrinterDisabled(admin: Want, callback: AsyncCallback\<boolean>): void
Checks whether printing is disabled for devices through the specified device administrator application. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.ENTERPRISE_RESTRICT_POLICY
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.|
| callback | AsyncCallback\<boolean> | Yes| Callback invoked to return the result. The value **true** means that device printing is disabled; the value **false** means the opposite.|
**Error codes**
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device. |
| 9200002 | the administrator application does not have permission to manage the device. |
**Example**
```js
let wantTemp = {
bundleName: 'bundleName',
abilityName: 'abilityName',
};
restrictions.isPrinterDisabled(wantTemp, (err, result) => {
if (err) {
console.error(`Failed to query is the printing function disabled or not. Code is ${err.code}, message is ${err.message}`);
return;
}
console.info(`Succeeded in querying is the printing function disabled : ${result}`);
})
```
## restrictions.isPrinterDisabled
isPrinterDisabled(admin: Want): Promise\<boolean>
Checks whether printing is disabled for devices through the specified device administrator application. This API uses a promise to return the result.
**Required permissions**: ohos.permission.ENTERPRISE_RESTRICT_POLICY
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.|
**Return value**
| Type | Description |
| ----- | ----------------------------------- |
| Promise\<boolean> | Promise used to return the result. The value **true** means that device printing is disabled; the value **false** means the opposite.|
**Error codes**
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device. |
| 9200002 | the administrator application does not have permission to manage the device. |
**Example**
```js
let wantTemp = {
bundleName: 'bundleName',
abilityName: 'abilityName',
};
restrictions.isPrinterDisabled(wantTemp).then((result) => {
console.info(`Succeeded in querying is the printing function disabled : ${result}`);
}).catch((err) => {
console.error(`Failed to query is the printing function disabled or not. Code is ${err.code}, message is ${err.message}`);
})
```
## restrictions.setHdcDisabled
setHdcDisabled(admin: Want, disabled: boolean, callback: AsyncCallback\<void>): void
Enables or disables HDC through the specified device administrator application. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.ENTERPRISE_RESTRICT_POLICY
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.|
| disabled | boolean | Yes| Whether to disable HDC. The value **true** means to disable HDC; the value **false** means the opposite.|
| callback | AsyncCallback\<void> | Yes| Callback invoked to return the result.<br> If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device. |
| 9200002 | the administrator application does not have permission to manage the device. |
**Example**
```js
let wantTemp = {
bundleName: 'bundleName',
abilityName: 'abilityName',
};
restrictions.setHdcDisabled(wantTemp, true, (err) => {
if (err) {
console.error(`Failed to set hdc disabled. Code is ${err.code}, message is ${err.message}`);
return;
}
console.info('Succeeded in setting hdc disabled');
})
```
## restrictions.setHdcDisabled
setHdcDisabled(admin: Want, disabled: boolean): Promise\<void>
Enables or disables HDC through the specified device administrator application. This API uses a promise to return the result.
**Required permissions**: ohos.permission.ENTERPRISE_RESTRICT_POLICY
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.|
| disabled | boolean | Yes| Whether to disable HDC. The value **true** means to disable HDC; the value **false** means the opposite.|
**Return value**
| Type | Description |
| ----- | ----------------------------------- |
| Promise\<void> | Promise that returns no value. An error object will be thrown if the specified device administrator application fails to disable or enable HDC.|
**Error codes**
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device. |
| 9200002 | the administrator application does not have permission to manage the device. |
**Example**
```js
let wantTemp = {
bundleName: 'bundleName',
abilityName: 'abilityName',
};
restrictions.setHdcDisabled(wantTemp, true).then(() => {
console.info('Succeeded in setting hdc disabled');
}).catch((err) => {
console.error(`Failed to set hdc disabled. Code is ${err.code}, message is ${err.message}`);
})
```
## restrictions.isHdcDisabled
isHdcDisabled(admin: Want, callback: AsyncCallback\<boolean>): void
Checks whether HDC is disabled through the specified device administrator application. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.ENTERPRISE_RESTRICT_POLICY
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.|
| callback | AsyncCallback\<boolean> | Yes| Callback invoked to return the result. The value **true** means HDC is disabled; the value **false** means the opposite.|
**Error codes**
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device. |
| 9200002 | the administrator application does not have permission to manage the device. |
**Example**
```js
let wantTemp = {
bundleName: 'bundleName',
abilityName: 'abilityName',
};
restrictions.isHdcDisabled(wantTemp, (err, result) => {
if (err) {
console.error(`Failed to query is hdc disabled or not. Code is ${err.code}, message is ${err.message}`);
return;
}
console.info(`Succeeded in querying is hdc disabled : ${result}`);
})
```
## restrictions.isHdcDisabled
isHdcDisabled(admin: Want): Promise\<boolean>
Checks whether HDC is disabled through the specified device administrator application. This API uses a promise to return the result.
**Required permissions**: ohos.permission.ENTERPRISE_RESTRICT_POLICY
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.|
**Return value**
| Type | Description |
| ----- | ----------------------------------- |
| Promise\<boolean> | Promise used to return the result. The value **true** means HDC is disabled; the value **false** means the opposite.|
**Error codes**
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device. |
| 9200002 | the administrator application does not have permission to manage the device. |
**Example**
```js
let wantTemp = {
bundleName: 'bundleName',
abilityName: 'abilityName',
};
restrictions.isHdcDisabled(wantTemp).then((result) => {
console.info(`Succeeded in querying is hdc disabled : ${result}`);
}).catch((err) => {
console.error(`Failed to query is hdc disabled or not. Code is ${err.code}, message is ${err.message}`);
})
```
# @ohos.enterprise.wifiManager (Wi-Fi Management) # @ohos.enterprise.wifiManager (Wi-Fi Management)
The **wifiManager** module provides APIs for Wi-Fi management of enterprise devices. Only the device administrator applications can call the APIs provided by this module. The **wifiManager** module provides APIs for Wi-Fi management of enterprise devices.
> **NOTE** > **NOTE**
> >
> - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The APIs of this module can be called only after a [device administrator application](js-apis-enterprise-adminManager.md#adminmanagerenableadmin) is enabled. >
> The APIs provided by this module can be called only by a [device administrator application](enterpriseDeviceManagement-overview.md#basic-concepts) that is [enabled](js-apis-enterprise-adminManager.md#adminmanagerenableadmin).
## Modules to Import ## Modules to Import
...@@ -29,31 +30,32 @@ Checks whether Wi-Fi is active through the specified device administrator applic ...@@ -29,31 +30,32 @@ Checks whether Wi-Fi is active through the specified device administrator applic
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------------------- | | -------- | ---------------------------------------- | ---- | ------------------------------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application that checks the Wi-Fi status. | | admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is a Boolean value (**true** indicates that Wi-Fi is active; and **false** indicates that Wi-Fi is inactive). If the operation fails, **err** is an error object. | | callback | AsyncCallback&lt;boolean&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is a Boolean value (**true** indicates that Wi-Fi is active; and **false** indicates that Wi-Fi is inactive). If the operation fails, **err** is an error object. |
**Error codes** **Error codes**
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ---------------------------------------------------------------------------- | | ------- | ---------------------------------------------------------------------------- |
| 9200001 | The application is not an administrator application of the device. | | 9200001 | the application is not an administrator of the device. |
| 9200002 | The administrator application does not have permission to manage the device. | | 9200002 | the administrator application does not have permission to manage the device. |
**Example** **Example**
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
wifiManager.isWifiActive(wantTemp, (error, result) => {
if (error != null) { wifiManager.isWifiActive(wantTemp, (err, result) => {
console.log("error code:" + error.code + " error message:" + error.message); if (err) {
return; console.error(`Failed to query is wifi active or not. Code: ${err.code}, message: ${err.message}`);
} return;
console.log("result:" + result); }
console.info(`Succeeded in query is wifi active or not, result : ${result}`);
}); });
``` ```
...@@ -73,7 +75,7 @@ Checks whether Wi-Fi is active through the specified device administrator applic ...@@ -73,7 +75,7 @@ Checks whether Wi-Fi is active through the specified device administrator applic
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- | | ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application that checks the Wi-Fi status.| | admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.|
**Return value** **Return value**
...@@ -85,22 +87,23 @@ Checks whether Wi-Fi is active through the specified device administrator applic ...@@ -85,22 +87,23 @@ Checks whether Wi-Fi is active through the specified device administrator applic
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ---------------------------------------------------------------------------- | | ------- | ---------------------------------------------------------------------------- |
| 9200001 | The application is not an administrator application of the device. | | 9200001 | the application is not an administrator of the device. |
| 9200002 | The administrator application does not have permission to manage the device. | | 9200002 | the administrator application does not have permission to manage the device. |
**Example** **Example**
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
wifiManager.isWifiActive(wantTemp).then((result) => { wifiManager.isWifiActive(wantTemp).then((result) => {
console.log("result:" + result); console.info(`Succeeded in query is wifi active or not, result : ${result}`);
}).catch(error => { }).catch((err) => {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to query is wifi active or not. Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -120,7 +123,7 @@ Sets Wi-Fi to connect to the specified network. This API uses an asynchronous ca ...@@ -120,7 +123,7 @@ Sets Wi-Fi to connect to the specified network. This API uses an asynchronous ca
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------------------- | | -------- | ---------------------------------------- | ---- | ------------------------------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application that sets the Wi-Fi profile. | | admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. |
| profile | [WifiProfile](#wifiprofile) | Yes | WLAN configuration. | | profile | [WifiProfile](#wifiprofile) | Yes | WLAN configuration. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. |
...@@ -128,29 +131,30 @@ Sets Wi-Fi to connect to the specified network. This API uses an asynchronous ca ...@@ -128,29 +131,30 @@ Sets Wi-Fi to connect to the specified network. This API uses an asynchronous ca
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ---------------------------------------------------------------------------- | | ------- | ---------------------------------------------------------------------------- |
| 9200001 | The application is not an administrator application of the device. | | 9200001 | the application is not an administrator of the device. |
| 9200002 | The administrator application does not have permission to manage the device. | | 9200002 | the administrator application does not have permission to manage the device. |
**Example** **Example**
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
let profile : wifiManager.WifiProfile = { let profile: wifiManager.WifiProfile = {
"ssid": "name", 'ssid': 'name',
"preSharedKey": "passwd", 'preSharedKey': 'passwd',
"securityType": wifiManager.WifiSecurityType.WIFI_SEC_TYPE_PSK 'securityType': wifiManager.WifiSecurityType.WIFI_SEC_TYPE_PSK
}; };
wifiManager.setWifiProfile(wantTemp, profile, (error) => {
if (error != null) { wifiManager.setWifiProfile(wantTemp, profile, (err) => {
console.log("error code:" + error.code + " error message:" + error.message); if (err) {
return; console.error(`Failed to set wifi profile. Code: ${err.code}, message: ${err.message}`);
} return;
console.log("set wifi success"); }
console.info('Succeeded in setting wifi profile');
}); });
``` ```
...@@ -170,7 +174,7 @@ Sets Wi-Fi to connect to the specified network. This API uses a promise to retur ...@@ -170,7 +174,7 @@ Sets Wi-Fi to connect to the specified network. This API uses a promise to retur
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- | | ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application that sets the Wi-Fi profile.| | admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.|
| profile | [WifiProfile](#wifiprofile) | Yes | WLAN configuration. | | profile | [WifiProfile](#wifiprofile) | Yes | WLAN configuration. |
**Return value** **Return value**
...@@ -183,27 +187,28 @@ Sets Wi-Fi to connect to the specified network. This API uses a promise to retur ...@@ -183,27 +187,28 @@ Sets Wi-Fi to connect to the specified network. This API uses a promise to retur
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ---------------------------------------------------------------------------- | | ------- | ---------------------------------------------------------------------------- |
| 9200001 | The application is not an administrator application of the device. | | 9200001 | the application is not an administrator of the device. |
| 9200002 | The administrator application does not have permission to manage the device. | | 9200002 | the administrator application does not have permission to manage the device. |
**Example** **Example**
```js ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "EntryAbility", abilityName: 'EntryAbility',
}; };
let profile : wifiManager.WifiProfile = { let profile : wifiManager.WifiProfile = {
"ssid": "name", 'ssid': 'name',
"preSharedKey": "passwd", 'preSharedKey': 'passwd',
"securityType": wifiManager.WifiSecurityType.WIFI_SEC_TYPE_PSK 'securityType': wifiManager.WifiSecurityType.WIFI_SEC_TYPE_PSK
}; };
wifiManager.setWifiProfile(wantTemp, profile).then(() => { wifiManager.setWifiProfile(wantTemp, profile).then(() => {
console.log("set wifi success"); console.info('Succeeded in setting wifi profile');
}).catch(error => { }).catch((err) => {
console.log("error code:" + error.code + " error message:" + error.message); console.error(`Failed to set wifi profile. Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册