提交 f64cc0dc 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 08263582
......@@ -394,8 +394,10 @@
- [@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)
- 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)
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**
>
......@@ -20,7 +20,7 @@ import EnterpriseAdminExtensionAbility from '@ohos.enterprise.EnterpriseAdminExt
onAdminEnabled(): void
Called when an enterprise administrator is enabled.
Called when a device administrator application is enabled.
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
......@@ -39,7 +39,7 @@ export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbil
onAdminDisabled(): void
Called when an enterprise administrator is disabled.
Called when a device administrator application is disabled.
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
......@@ -66,7 +66,7 @@ Called when a bundle is added.
**Parameters**
| Parameter | Type | Mandatory | Description |
| Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- |
| bundleName | string | Yes | Name of the bundle added.|
......@@ -75,7 +75,7 @@ Called when a bundle is added.
```ts
export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbility {
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.
**Parameters**
| Parameter | Type | Mandatory | Description |
| Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- |
| bundleName | string | Yes | Name of the bundle removed.|
......@@ -100,8 +100,8 @@ Called when a bundle is removed.
```ts
export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbility {
onBundleAdded(bundleName: string) {
console.log("removed bundle name: " + bundleName);
onBundleRemoved(bundleName: string) {
console.info(`Succeeded in calling onBundleRemoved callback, removed bundle name : ${bundleName}`);
}
};
```
......@@ -118,7 +118,7 @@ Called when an application is started.
**Parameters**
| Parameter | Type | Mandatory | Description |
| Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- |
| bundleName | string | Yes | Bundle name of the application started.|
......@@ -127,7 +127,7 @@ Called when an application is started.
```ts
export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbility {
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.
**Parameters**
| Parameter | Type | Mandatory | Description |
| Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- |
| bundleName | string | Yes | Bundle name of the application stopped.|
......@@ -153,7 +153,7 @@ Called when an application is stopped.
```ts
export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbility {
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)
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**
>
> - 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
......@@ -46,13 +47,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
accountManager.disallowAddLocalAccount(wantTemp, true, (error) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
accountManager.disallowAddLocalAccount(wantTemp, true, (err) => {
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
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
accountManager.disallowAddLocalAccount(wantTemp, true).then(() => {
console.log("success");
}).catch(error => {
console.log("error code:" + error.code + " error message:" + error.message);
console.info('Succeeded in disallowing add local account');
}).catch((err) => {
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
> **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
......@@ -47,19 +49,20 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let enterpriseInfo = {
name: "enterprise name",
description: "enterprise description"
name: 'enterprise name',
description: 'enterprise description'
}
adminManager.enableAdmin(wantTemp, enterpriseInfo, adminManager.AdminType.ADMIN_TYPE_SUPER, error => {
if (error != null) {
console.log("error occurs" + error);
adminManager.enableAdmin(wantTemp, enterpriseInfo, adminManager.AdminType.ADMIN_TYPE_SUPER, (err) => {
if (err) {
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
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let enterpriseInfo = {
name: "enterprise name",
description: "enterprise description"
name: 'enterprise name',
description: 'enterprise description'
}
adminManager.enableAdmin(wantTemp, enterpriseInfo, adminManager.AdminType.ADMIN_TYPE_NORMAL, 100, error => {
if (error != null) {
console.log("error occurs" + error);
adminManager.enableAdmin(wantTemp, enterpriseInfo, adminManager.AdminType.ADMIN_TYPE_NORMAL, 100, (err) => {
if (err) {
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
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let enterpriseInfo = {
name: "enterprise name",
description: "enterprise description"
name: 'enterprise name',
description: 'enterprise description'
}
adminManager.enableAdmin(wantTemp, enterpriseInfo, adminManager.AdminType.ADMIN_TYPE_NORMAL, 100)
.catch(error => {
console.log("error occurs" + error);
adminManager.enableAdmin(wantTemp, enterpriseInfo, adminManager.AdminType.ADMIN_TYPE_NORMAL, 100).catch((err) => {
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
```js
let wantTemp = {
bundleName: "bundleName",
abilityName: "abilityName",
bundleName: 'bundleName',
abilityName: 'abilityName',
};
adminManager.disableAdmin(wantTemp, error => {
if (error != null) {
console.log("error occurs" + error);
adminManager.disableAdmin(wantTemp, (err) => {
if (err) {
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
```js
let wantTemp = {
bundleName: "bundleName",
abilityName: "abilityName",
bundleName: 'bundleName',
abilityName: 'abilityName',
};
adminManager.disableAdmin(wantTemp, 100, error => {
if (error != null) {
console.log("error occurs" + error);
adminManager.disableAdmin(wantTemp, 100, (err) => {
if (err) {
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
```js
let wantTemp = {
bundleName: "bundleName",
abilityName: "abilityName",
bundleName: 'bundleName',
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}`);
});
```
......@@ -331,13 +338,14 @@ For details about the error codes, see [Enterprise Device Management Error Codes
**Example**
```js
let bundleName = "com.example.myapplication";
adminManager.disableSuperAdmin(bundleName, error => {
if (error != null) {
console.log("error occurs" + error);
let bundleName = 'com.example.myapplication';
adminManager.disableSuperAdmin(bundleName, (err) => {
if (err) {
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
**Example**
```js
let bundleName = "com.example.myapplication";
adminManager.disableSuperAdmin(bundleName).catch(error => {
console.log("error occurs" + error);
let bundleName = 'com.example.myapplication';
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
```js
let wantTemp = {
bundleName: "bundleName",
abilityName: "abilityName",
bundleName: 'bundleName',
abilityName: 'abilityName',
};
adminManager.isAdminEnabled(wantTemp, (error, result) => {
if (error != null) {
console.log("error occurs" + error);
adminManager.isAdminEnabled(wantTemp, (err, result) => {
if (err) {
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
```js
let wantTemp = {
bundleName: "bundleName",
abilityName: "abilityName",
bundleName: 'bundleName',
abilityName: 'abilityName',
};
adminManager.isAdminEnabled(wantTemp, 100, (error, result) => {
if (error != null) {
console.log("error occurs" + error);
adminManager.isAdminEnabled(wantTemp, 100, (err, result) => {
if (err) {
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
```js
let wantTemp = {
bundleName: "bundleName",
abilityName: "abilityName",
bundleName: 'bundleName',
abilityName: 'abilityName',
};
adminManager.isAdminEnabled(wantTemp, 100).then((result) => {
console.log("result is " + result);
}).catch(error => {
console.log("error occurs" + error);
console.info(`Succeeded in querying admin is enabled or not, result : ${result}`);
}).catch((err) => {
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
**Example**
```js
let bundleName = "com.example.myapplication";
adminManager.isSuperAdmin(bundleName, (error, result) => {
if (error != null) {
console.log("error occurs" + error);
let bundleName = 'com.example.myapplication';
adminManager.isSuperAdmin(bundleName, (err, result) => {
if (err) {
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
**Example**
```js
let bundleName = "com.example.myapplication";
let bundleName = 'com.example.myapplication';
adminManager.isSuperAdmin(bundleName).then((result) => {
console.log("result is " + result);
}).catch(error => {
console.log("error occurs" + error);
console.info(`Succeeded in querying admin is super admin or not, result : ${result}`);
}).catch((err) => {
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
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let enterpriseInfo = {
name: "enterprise name",
description: "enterprise description"
name: 'enterprise name',
description: 'enterprise description'
}
adminManager.setEnterpriseInfo(wantTemp, enterpriseInfo, error => {
if (error != null) {
console.log("error occurs" + error);
adminManager.setEnterpriseInfo(wantTemp, enterpriseInfo, (err) => {
if (err) {
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
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let enterpriseInfo = {
name: "enterprise name",
description: "enterprise description"
name: 'enterprise name',
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
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
adminManager.getEnterpriseInfo(wantTemp, (error, result) => {
if (error != null) {
console.log("error occurs" + error);
adminManager.getEnterpriseInfo(wantTemp, (err, result) => {
if (err) {
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
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
adminManager.getEnterpriseInfo(wantTemp).then((result) => {
console.log(result.name);
console.log(result.description);
}).catch(error => {
console.log("error occurs" + error);
console.info(`Succeeded in getting enterprise info, enterprise name : ${result.name}, enterprise description : ${result.description}`);
}).catch((err) => {
console.error(`Failed to get enterprise info. Code: ${err.code}, message: ${err.message}`);
});
```
......@@ -766,14 +782,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js
let wantTemp = {
bundleName: "bundleName",
abilityName: "abilityName",
bundleName: 'bundleName',
abilityName: 'abilityName',
};
let events = [0, 1];
adminManager.subscribeManagedEvent(wantTemp, events, (error) => {
if (error) {
console.log("error code:" + error.code + " error message:" + error.message);
adminManager.subscribeManagedEvent(wantTemp, events, (err) => {
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
```js
let wantTemp = {
bundleName: "bundleName",
abilityName: "abilityName",
bundleName: 'bundleName',
abilityName: 'abilityName',
};
let events = [0, 1];
adminManager.subscribeManagedEvent(wantTemp, events).then(() => {
}).catch((error) => {
console.log("error code:" + error.code + " error message:" + error.message);
}).catch((err) => {
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
```js
let wantTemp = {
bundleName: "bundleName",
abilityName: "abilityName",
bundleName: 'bundleName',
abilityName: 'abilityName',
};
let events = [0, 1];
adminManager.unsubscribeManagedEvent(wantTemp, events, (error) => {
if (error) {
console.log("error code:" + error.code + " error message:" + error.message);
adminManager.unsubscribeManagedEvent(wantTemp, events, (err) => {
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
```js
let wantTemp = {
bundleName: "bundleName",
abilityName: "abilityName",
bundleName: 'bundleName',
abilityName: 'abilityName',
};
let events = [0, 1];
adminManager.unsubscribeManagedEvent(wantTemp, events).then(() => {
}).catch((error) => {
console.log("error code:" + error.code + " error message:" + error.message);
}).catch((err) => {
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.
**System API**: This is a system API.
| Name | Type | Readable| Writable | Description |
| ----------- | --------| ---- | ----- | ------------------------------- |
| name | string | Yes | No | 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.|
| Name | Type | Mandatory| Description |
| ----------- | --------| ---- | ------------------------------- |
| name | string | Yes | Name 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
......
# @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**
>
> - 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
......@@ -47,15 +48,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let appIds = ["com.example.myapplication"];
let appIds = ['com.example.myapplication'];
applicationManager.addDisallowedRunningBundles(wantTemp, appIds, (error) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
applicationManager.addDisallowedRunningBundles(wantTemp, appIds, (err) => {
if (err) {
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');
});
```
......@@ -93,15 +96,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let appIds = ["com.example.myapplication"];
let appIds = ['com.example.myapplication'];
applicationManager.addDisallowedRunningBundles(wantTemp, appIds, 100, (error) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
applicationManager.addDisallowedRunningBundles(wantTemp, appIds, 100, (err) => {
if (err) {
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');
});
```
......@@ -144,15 +149,15 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let appIds = ["com.example.myapplication"];
let appIds = ['com.example.myapplication'];
applicationManager.addDisallowedRunningBundles(wantTemp, appIds, 100).then(() => {
console.log("success");
}).catch(error => {
console.log("error code:" + error.code + " error message:" + error.message);
console.info('Succeeded in adding disallowed running bundles');
}).catch((err) => {
console.error(`Failed to add disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
});
```
......@@ -189,15 +194,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let appIds = ["com.example.myapplication"];
let appIds = ['com.example.myapplication'];
applicationManager.removeDisallowedRunningBundles(wantTemp, appIds, (error) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
applicationManager.removeDisallowedRunningBundles(wantTemp, appIds, (err) => {
if (err) {
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');
});
```
......@@ -235,15 +242,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let appIds = ["com.example.myapplication"];
let appIds = ['com.example.myapplication'];
applicationManager.removeDisallowedRunningBundles(wantTemp, appIds, 100, (error) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
applicationManager.removeDisallowedRunningBundles(wantTemp, appIds, 100, (err) => {
if (err) {
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');
});
```
......@@ -286,15 +295,15 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let appIds = ["com.example.myapplication"];
let appIds = ['com.example.myapplication'];
applicationManager.removeDisallowedRunningBundles(wantTemp, appIds, 100).then(() => {
console.log("success");
}).catch(error => {
console.log("error code:" + error.code + " error message:" + error.message);
console.info('Succeeded in removing disallowed running bundles');
}).catch((err) => {
console.error(`Failed to remove disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
});
```
......@@ -330,14 +339,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
applicationManager.getDisallowedRunningBundles(wantTemp, (error) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
applicationManager.getDisallowedRunningBundles(wantTemp, (err, result) => {
if (err) {
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)}`);
});
```
......@@ -374,14 +385,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
applicationManager.getDisallowedRunningBundles(wantTemp, 100, (error) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
applicationManager.getDisallowedRunningBundles(wantTemp, 100, (err, result) => {
if (err) {
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)}`);
});
```
......@@ -423,12 +436,13 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
applicationManager.getDisallowedRunningBundles(wantTemp, 100).then(() => {
console.log("success");
}).catch(error => {
console.log("error code:" + error.code + " error message:" + error.message);
applicationManager.getDisallowedRunningBundles(wantTemp, 100).then((result) => {
console.info(`Succeeded in getting disallowed running bundles, result : ${JSON.stringify(result)}`);
}).catch((err) => {
console.error(`Failed to get disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
});
```
# @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**
>
> - 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
......@@ -46,15 +48,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let appIds = ["com.example.myapplication"];
let appIds = ['com.example.myapplication'];
bundleManager.addAllowedInstallBundles(wantTemp, appIds, (error) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
bundleManager.addAllowedInstallBundles(wantTemp, appIds, (err) => {
if (err) {
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
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let appIds = ["com.example.myapplication"];
let appIds = ['com.example.myapplication'];
bundleManager.addAllowedInstallBundles(wantTemp, appIds, 100, (error) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
bundleManager.addAllowedInstallBundles(wantTemp, appIds, 100, (err) => {
if (err) {
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
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let appIds = ["com.example.myapplication"];
let appIds = ['com.example.myapplication'];
bundleManager.addAllowedInstallBundles(wantTemp, appIds, 100).then(() => {
console.log("success");
}).catch(error => {
console.log("error code:" + error.code + " error message:" + error.message);
console.info('Succeeded in adding allowed install bundles');
}).catch((err) => {
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
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let appIds = ["com.example.myapplication"];
let appIds = ['com.example.myapplication'];
bundleManager.removeAllowedInstallBundles(wantTemp, appIds, (error) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
bundleManager.removeAllowedInstallBundles(wantTemp, appIds, (err) => {
if (err) {
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
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let appIds = ["com.example.myapplication"];
let appIds = ['com.example.myapplication'];
bundleManager.removeAllowedInstallBundles(wantTemp, appIds, 100, (error) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
bundleManager.removeAllowedInstallBundles(wantTemp, appIds, 100, (err) => {
if (err) {
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
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let appIds = ["com.example.myapplication"];
let appIds = ['com.example.myapplication'];
bundleManager.removeAllowedInstallBundles(wantTemp, appIds, 100).then(() => {
console.log("success");
}).catch(error => {
console.log("error code:" + error.code + " error message:" + error.message);
console.info('Succeeded in removing allowed install bundles');
}).catch((err) => {
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
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
bundleManager.getAllowedInstallBundles(wantTemp, (error) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
bundleManager.getAllowedInstallBundles(wantTemp, (err, result) => {
if (err) {
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
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
bundleManager.getAllowedInstallBundles(wantTemp, 100, (error) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
bundleManager.getAllowedInstallBundles(wantTemp, 100, (err, result) => {
if (err) {
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
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
bundleManager.getAllowedInstallBundles(wantTemp, 100).then(() => {
console.log("success");
}).catch(error => {
console.log("error code:" + error.code + " error message:" + error.message);
bundleManager.getAllowedInstallBundles(wantTemp, 100).then((result) => {
console.info(`Succeeded in getting allowed install bundles, result : ${JSON.stringify(result)}`);
}).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
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let appIds = ["com.example.myapplication"];
let appIds = ['com.example.myapplication'];
bundleManager.addDisallowedInstallBundles(wantTemp, appIds, (error) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
bundleManager.addDisallowedInstallBundles(wantTemp, appIds, (err) => {
if (err) {
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
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let appIds = ["com.example.myapplication"];
let appIds = ['com.example.myapplication'];
bundleManager.addDisallowedInstallBundles(wantTemp, appIds, 100, (error) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
bundleManager.addDisallowedInstallBundles(wantTemp, appIds, 100, (err) => {
if (err) {
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
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let appIds = ["com.example.myapplication"];
let appIds = ['com.example.myapplication'];
bundleManager.addDisallowedInstallBundles(wantTemp, appIds, 100).then(() => {
console.log("success");
}).catch(error => {
console.log("error code:" + error.code + " error message:" + error.message);
console.info('Succeeded in adding disallowed install bundles');
}).catch((err) => {
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
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let appIds = ["com.example.myapplication"];
let appIds = ['com.example.myapplication'];
bundleManager.removeDisallowedInstallBundles(wantTemp, appIds, (error) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
bundleManager.removeDisallowedInstallBundles(wantTemp, appIds, (err) => {
if (err) {
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
| Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- |
| 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**.|
| 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
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let appIds = ["com.example.myapplication"];
let appIds = ['com.example.myapplication'];
bundleManager.removeDisallowedInstallBundles(wantTemp, appIds, 100, (error) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
bundleManager.removeDisallowedInstallBundles(wantTemp, appIds, 100, (err) => {
if (err) {
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
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let appIds = ["com.example.myapplication"];
let appIds = ['com.example.myapplication'];
bundleManager.removeDisallowedInstallBundles(wantTemp, appIds, 100).then(() => {
console.log("success");
}).catch(error => {
console.log("error code:" + error.code + " error message:" + error.message);
console.info('Succeeded in removing disallowed install bundles');
}).catch((err) => {
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
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
bundleManager.getDisallowedInstallBundles(wantTemp, (error) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
bundleManager.getDisallowedInstallBundles(wantTemp, (err, result) => {
if (err) {
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
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
bundleManager.getDisallowedInstallBundles(wantTemp, 100, (error) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
bundleManager.getDisallowedInstallBundles(wantTemp, 100, (err, result) => {
if (err) {
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
**Example**
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
bundleManager.getDisallowedInstallBundles(wantTemp, 100).then(() => {
console.log("success");
}).catch(error => {
console.log("error code:" + error.code + " error message:" + error.message);
bundleManager.getDisallowedInstallBundles(wantTemp, 100).then((result) => {
console.info(`Succeeded in getting disallowed install bundles, result : ${JSON.stringify(result)}`);
}).catch((err) => {
console.error(`Failed to get disallowed install bundles. Code is ${err.code}, message is ${err.message}`);
});
```
## bundleManager.addDisallowedUninstallBundles
......@@ -882,15 +912,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let appIds = ["com.example.myapplication"];
let appIds = ['com.example.myapplication'];
bundleManager.addDisallowedUninstallBundles(wantTemp, appIds, (error) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
bundleManager.addDisallowedUninstallBundles(wantTemp, appIds, (err) => {
if (err) {
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
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let appIds = ["com.example.myapplication"];
let appIds = ['com.example.myapplication'];
bundleManager.addDisallowedUninstallBundles(wantTemp, appIds, 100, (error) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
bundleManager.addDisallowedUninstallBundles(wantTemp, appIds, 100, (err) => {
if (err) {
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
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let appIds = ["com.example.myapplication"];
let appIds = ['com.example.myapplication'];
bundleManager.addDisallowedUninstallBundles(wantTemp, appIds, 100).then(() => {
console.log("success");
}).catch(error => {
console.log("error code:" + error.code + " error message:" + error.message);
console.info('Succeeded in adding disallowed uninstall bundles');
}).catch((err) => {
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
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------------------- |
| 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.|
**Error codes**
......@@ -1024,15 +1058,17 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let appIds = ["com.example.myapplication"];
let appIds = ['com.example.myapplication'];
bundleManager.removeDisallowedUninstallBundles(wantTemp, appIds, (error) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
bundleManager.removeDisallowedUninstallBundles(wantTemp, appIds, (err) => {
if (err) {
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
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let appIds = ["com.example.myapplication"];
let appIds = ['com.example.myapplication'];
bundleManager.removeDisallowedUninstallBundles(wantTemp, appIds, 100, (error) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
bundleManager.removeDisallowedUninstallBundles(wantTemp, appIds, 100, (err) => {
if (err) {
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
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let appIds = ["com.example.myapplication"];
let appIds = ['com.example.myapplication'];
bundleManager.removeDisallowedUninstallBundles(wantTemp, appIds, 100).then(() => {
console.log("success");
}).catch(error => {
console.log("error code:" + error.code + " error message:" + error.message);
console.info('Succeeded in removing disallowed uninstall bundles');
}).catch((err) => {
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
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
bundleManager.getDisallowedUninstallBundles(wantTemp, (error, data) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
} else {
console.log("success: " + data);
bundleManager.getDisallowedUninstallBundles(wantTemp, (err, result) => {
if (err) {
console.error(`Failed to get disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`);
return;
}
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
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
bundleManager.getDisallowedUninstallBundles(wantTemp, 100, (error, data) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
} else {
console.log("success: " + data);
bundleManager.getDisallowedUninstallBundles(wantTemp, 100, (err, result) => {
if (err) {
console.error(`Failed to get disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`);
return;
}
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
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
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);
}).catch(error => {
console.log("error code:" + error.code + " error message:" + error.message);
bundleManager.uninstall(wantTemp, 'bundleName', 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, 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)
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**
>
> - 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
......@@ -46,13 +47,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js
let wantTemp = {
bundleName: "bundleName",
abilityName: "abilityName",
bundleName: 'bundleName',
abilityName: 'abilityName',
};
dateTimeManager.setDateTime(wantTemp, 1526003846000, (error) => {
if (error) {
console.log("error code:" + error.code + " error message:" + error.message);
dateTimeManager.setDateTime(wantTemp, 1526003846000, (err) => {
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
```js
let wantTemp = {
bundleName: "bundleName",
abilityName: "abilityName",
bundleName: 'bundleName',
abilityName: 'abilityName',
};
dateTimeManager.setDateTime(wantTemp, 1526003846000).then(() => {
}).catch((error) => {
console.log("error code:" + error.code + " error message:" + error.message);
console.info('Succeeded in setting date time');
}).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
```js
let wantTemp = {
bundleName: "bundleName",
abilityName: "abilityName",
bundleName: 'bundleName',
abilityName: 'abilityName',
};
dateTimeManager.disallowModifyDateTime(wantTemp, true, (error) => {
if (error) {
console.log("error code:" + error.code + " error message:" + error.message);
dateTimeManager.disallowModifyDateTime(wantTemp, true, (err) => {
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
```js
let wantTemp = {
bundleName: "bundleName",
abilityName: "abilityName",
bundleName: 'bundleName',
abilityName: 'abilityName',
};
dateTimeManager.disallowModifyDateTime(wantTemp, true).then(() => {
}).catch((error) => {
console.log("error code:" + error.code + " error message:" + error.message);
console.info('Succeeded in disallowing modify date time');
}).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
```js
let wantTemp = {
bundleName: "bundleName",
abilityName: "abilityName",
bundleName: 'bundleName',
abilityName: 'abilityName',
};
dateTimeManager.isModifyDateTimeDisallowed(wantTemp, (error) => {
if (error) {
console.log("error code:" + error.code + " error message:" + error.message);
dateTimeManager.isModifyDateTimeDisallowed(wantTemp, (err, result) => {
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
```js
let wantTemp = {
bundleName: "bundleName",
abilityName: "abilityName",
bundleName: 'bundleName',
abilityName: 'abilityName',
};
dateTimeManager.isModifyDateTimeDisallowed(wantTemp).then(() => {
}).catch((error) => {
console.log("error code:" + error.code + " error message:" + error.message);
dateTimeManager.isModifyDateTimeDisallowed(wantTemp).then((result) => {
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}`);
})
```
......@@ -5,7 +5,9 @@ The **deviceControl** module provides APIs for device control, which can be call
> **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 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
......@@ -17,8 +19,7 @@ import deviceControl from '@ohos.enterprise.deviceControl'
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
......@@ -46,13 +47,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js
let wantTemp = {
bundleName: "bundleName",
abilityName: "abilityName",
bundleName: 'bundleName',
abilityName: 'abilityName',
};
deviceControl.resetFactory(wantTemp, (error) => {
if (error) {
console.log("error code:" + error.code + " error message:" + error.message);
deviceControl.resetFactory(wantTemp, (err) => {
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.
| 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**
......@@ -93,11 +97,12 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js
let wantTemp = {
bundleName: "bundleName",
abilityName: "abilityName",
bundleName: 'bundleName',
abilityName: 'abilityName',
};
deviceControl.resetFactory(wantTemp).then(() => {
}).catch((error) => {
console.log("error code:" + error.code + " error message:" + error.message);
}).catch((err) => {
console.error(`Failed to reset factory. Code is ${err.code}, message is ${err.message}`);
})
```
# @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**
>
> - 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
......@@ -45,15 +46,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
deviceInfo.getDeviceSerial(wantTemp, (error, result) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
deviceInfo.getDeviceSerial(wantTemp, (err, result) => {
if (err) {
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
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
deviceInfo.getDeviceSerial(wantTemp).then((result) => {
console.log(result);
}).catch(error => {
console.log("error code:" + error.code + " error message:" + error.message);
console.info(`Succeeded in getting device serial, result : ${result}`);
}).catch((err) => {
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
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
deviceInfo.getDisplayVersion(wantTemp, (error, result) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
deviceInfo.getDisplayVersion(wantTemp, (err, result) => {
if (err) {
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
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
deviceInfo.getDisplayVersion(wantTemp).then((result) => {
console.log(result);
}).catch(error => {
console.log("error code:" + error.code + " error message:" + error.message);
console.info(`Succeeded in getting display version, result : ${result}`);
}).catch((err) => {
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
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
deviceInfo.getDeviceName(wantTemp, (error, result) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
deviceInfo.getDeviceName(wantTemp, (err, result) => {
if (err) {
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
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
deviceInfo.getDeviceName(wantTemp).then((result) => {
console.log(result);
}).catch(error => {
console.log("error code:" + error.code + " error message:" + error.message);
console.info(`Succeeded in getting device name, result : ${result}`);
}).catch((err) => {
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)
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**
>
> - 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 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
......@@ -29,7 +30,7 @@ Obtains all active network interfaces through the specified device administrator
| 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. |
**Error codes**
......@@ -45,15 +46,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
networkManager.getAllNetworkInterfaces(wantTemp, (error, result) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
networkManager.getAllNetworkInterfaces(wantTemp, (err, result) => {
if (err) {
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
| 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**
......@@ -94,13 +96,14 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
networkManager.getAllNetworkInterfaces(wantTemp).then((result) => {
console.log(JSON.stringify(result));
}).catch(error => {
console.log("error code:" + error.code + " error message:" + error.message);
console.info(`Succeeded in getting all network interfaces, result : ${JSON.stringify(result)}`);
}).catch((err) => {
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
| 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. |
| 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. |
......@@ -137,15 +140,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
networkManager.getIpAddress(wantTemp, "eth0", (error, result) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
networkManager.getIpAddress(wantTemp, 'eth0', (err, result) => {
if (err) {
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
| 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. |
**Return value**
......@@ -187,13 +191,14 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
networkManager.getIpAddress(wantTemp, "eth0").then((result) => {
console.log(result);
}).catch(error => {
console.log("error code:" + error.code + " error message:" + error.message);
networkManager.getIpAddress(wantTemp, 'eth0').then((result) => {
console.info(`Succeeded in getting ip address, result : ${result}`);
}).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
| 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. |
| 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. |
......@@ -230,21 +235,22 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
networkManager.getMac(wantTemp, "eth0", (error, result) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
networkManager.getMac(wantTemp, 'eth0', (err, result) => {
if (err) {
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
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.
......@@ -258,7 +264,7 @@ Obtain the device MAC address based on the given network interface through the s
| 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. |
**Return value**
......@@ -280,13 +286,14 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
networkManager.getMac(wantTemp, "eth0").then((result) => {
console.log(result);
}).catch(error => {
console.log("error code:" + error.code + " error message:" + error.message);
networkManager.getMac(wantTemp, 'eth0').then((result) => {
console.info(`Succeeded in getting mac, result : ${result}`);
}).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
| 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. |
| 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. |
......@@ -323,15 +330,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
networkManager.isNetworkInterfaceDisabled(wantTemp, "eth0", (error, result) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
networkManager.isNetworkInterfaceDisabled(wantTemp, 'eth0', (err, result) => {
if (err) {
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
| 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. |
**Return value**
......@@ -373,13 +381,14 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
networkManager.isNetworkInterfaceDisabled(wantTemp, "eth0").then((result) => {
console.log("result:" + result);
}).catch(error => {
console.log("error code:" + error.code + " error message:" + error.message);
networkManager.isNetworkInterfaceDisabled(wantTemp, 'eth0').then((result) => {
console.info(`Succeeded in querying network interface is disabled or not, result : ${result}`);
}).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.
| 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. |
| 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. |
......@@ -417,15 +426,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
networkManager.setNetworkInterfaceDisabled(wantTemp, "eth0", true, (error) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
networkManager.setNetworkInterfaceDisabled(wantTemp, 'eth0', true, (err) => {
if (err) {
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.
| 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. |
| 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
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
networkManager.setNetworkInterfaceDisabled(wantTemp, 'eth0', true).then(() => {
console.info(`Succeeded in setting network interface disabled`);
}).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',
};
networkManager.setNetworkInterfaceDisabled(wantTemp, "eth0", true).then(() => {
console.log("setNetworkInterfaceDisabled success!");
}).catch(error => {
console.log("error code:" + error.code + " error message:" + error.message);
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)
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**
>
> - 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 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
......@@ -29,7 +30,7 @@ Checks whether Wi-Fi is active through the specified device administrator applic
| 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. |
**Error codes**
......@@ -38,22 +39,23 @@ For details about the error codes, see [Enterprise Device Management Error Codes
| 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. |
| 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",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
wifiManager.isWifiActive(wantTemp, (error, result) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
wifiManager.isWifiActive(wantTemp, (err, result) => {
if (err) {
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
| 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**
......@@ -87,20 +89,21 @@ For details about the error codes, see [Enterprise Device Management Error Codes
| 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. |
| 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",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
wifiManager.isWifiActive(wantTemp).then((result) => {
console.log("result:" + result);
}).catch(error => {
console.log("error code:" + error.code + " error message:" + error.message);
console.info(`Succeeded in query is wifi active or not, result : ${result}`);
}).catch((err) => {
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
| 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. |
| 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. |
......@@ -130,27 +133,28 @@ For details about the error codes, see [Enterprise Device Management Error Codes
| 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. |
| 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",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let profile : wifiManager.WifiProfile = {
"ssid": "name",
"preSharedKey": "passwd",
"securityType": wifiManager.WifiSecurityType.WIFI_SEC_TYPE_PSK
let profile: wifiManager.WifiProfile = {
'ssid': 'name',
'preSharedKey': 'passwd',
'securityType': wifiManager.WifiSecurityType.WIFI_SEC_TYPE_PSK
};
wifiManager.setWifiProfile(wantTemp, profile, (error) => {
if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message);
wifiManager.setWifiProfile(wantTemp, profile, (err) => {
if (err) {
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
| 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. |
**Return value**
......@@ -185,25 +189,26 @@ For details about the error codes, see [Enterprise Device Management Error Codes
| 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. |
| 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",
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let profile : wifiManager.WifiProfile = {
"ssid": "name",
"preSharedKey": "passwd",
"securityType": wifiManager.WifiSecurityType.WIFI_SEC_TYPE_PSK
'ssid': 'name',
'preSharedKey': 'passwd',
'securityType': wifiManager.WifiSecurityType.WIFI_SEC_TYPE_PSK
};
wifiManager.setWifiProfile(wantTemp, profile).then(() => {
console.log("set wifi success");
}).catch(error => {
console.log("error code:" + error.code + " error message:" + error.message);
console.info('Succeeded in setting wifi profile');
}).catch((err) => {
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.
先完成此消息的编辑!
想要评论请 注册