diff --git a/en/application-dev/reference/apis/Readme-EN.md b/en/application-dev/reference/apis/Readme-EN.md index 5d3b4b8ea4893b3784b0589e63ff12f808fc82ff..b85ef4f7720cafff83c67fe2aee848dcd046c23c 100644 --- a/en/application-dev/reference/apis/Readme-EN.md +++ b/en/application-dev/reference/apis/Readme-EN.md @@ -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 diff --git a/en/application-dev/reference/apis/enterpriseDeviceManagement-overview.md b/en/application-dev/reference/apis/enterpriseDeviceManagement-overview.md new file mode 100644 index 0000000000000000000000000000000000000000..0d7d9171f2076a92283f9631dd8985c358bebdfd --- /dev/null +++ b/en/application-dev/reference/apis/enterpriseDeviceManagement-overview.md @@ -0,0 +1,43 @@ +# 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) diff --git a/en/application-dev/reference/apis/js-apis-EnterpriseAdminExtensionAbility.md b/en/application-dev/reference/apis/js-apis-EnterpriseAdminExtensionAbility.md index 3b42c32bc9e19c19810017a2a7d7cab637619dc6..a08c17b91dcbbaaaddeb605b69bdc192275588c4 100644 --- a/en/application-dev/reference/apis/js-apis-EnterpriseAdminExtensionAbility.md +++ b/en/application-dev/reference/apis/js-apis-EnterpriseAdminExtensionAbility.md @@ -1,8 +1,8 @@ # @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}`); } }; ``` diff --git a/en/application-dev/reference/apis/js-apis-enterprise-accountManager.md b/en/application-dev/reference/apis/js-apis-enterprise-accountManager.md index 9fb44e3c6a4a5f05502cd215b26001f11cbed717..6fad182e98274663af3ded60c01fa955649ebfb4 100644 --- a/en/application-dev/reference/apis/js-apis-enterprise-accountManager.md +++ b/en/application-dev/reference/apis/js-apis-enterprise-accountManager.md @@ -1,11 +1,12 @@ # @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}`); }); ``` diff --git a/en/application-dev/reference/apis/js-apis-enterprise-adminManager.md b/en/application-dev/reference/apis/js-apis-enterprise-adminManager.md index 6ce6b0456e491339c1d698eeda38e8aab0c4100c..b3ae186cc47031f89fae5b14d4280c6d1d687d0f 100644 --- a/en/application-dev/reference/apis/js-apis-enterprise-adminManager.md +++ b/en/application-dev/reference/apis/js-apis-enterprise-adminManager.md @@ -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); - return; - } - console.log("enableAdmin success"); + +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.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); - return; - } - console.log("enableAdmin success"); + +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.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); - return; - } - console.log("disableAdmin success "); + +adminManager.disableAdmin(wantTemp, (err) => { + if (err) { + console.error(`Failed to disable admin. Code: ${err.code}, message: ${err.message}`); + return; + } + 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); - return; - } - console.log("disableAdmin success "); + +adminManager.disableAdmin(wantTemp, 100, (err) => { + if (err) { + console.error(`Failed to disable admin. Code: ${err.code}, message: ${err.message}`); + return; + } + 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}`); }); ``` @@ -324,20 +331,21 @@ Disables a super device administrator application based on the specified bundle For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). -| ID| Error Message | +| ID| Error Message | | ------- | ----------------------------------------------------------------- | | 9200005 | failed to disable the administrator application of the device. | **Example** ```js -let bundleName = "com.example.myapplication"; -adminManager.disableSuperAdmin(bundleName, error => { - if (error != null) { - console.log("error occurs" + error); - return; - } - console.log("disableSuperAdmin success"); +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.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); - return; - } - console.log("result is " + result); + +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.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); - return; - } - console.log("result is " + result); + +adminManager.isAdminEnabled(wantTemp, 100, (err, result) => { + if (err) { + console.error(`Failed to query admin is enabled. Code: ${err.code}, message: ${err.message}`); + return; + } + 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); - return; - } - console.log("result is " + result); +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.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); - return; - } - console.log("setEnterpriseInfo success"); + +adminManager.setEnterpriseInfo(wantTemp, enterpriseInfo, (err) => { + if (err) { + console.error(`Failed to set enterprise info. Code: ${err.code}, message: ${err.message}`); + return; + } + 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); - return; - } - console.log(result.name); - console.log(result.description); + +adminManager.getEnterpriseInfo(wantTemp, (err, result) => { + if (err) { + console.error(`Failed to get enterprise info. Code: ${err.code}, message: ${err.message}`); + return; + } + 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 diff --git a/en/application-dev/reference/apis/js-apis-enterprise-applicationManager.md b/en/application-dev/reference/apis/js-apis-enterprise-applicationManager.md index 529777b2e18e3533c433b1aecb236284daa6340a..b2d127f28df7434b9bc3f2fad33f520109358178 100644 --- a/en/application-dev/reference/apis/js-apis-enterprise-applicationManager.md +++ b/en/application-dev/reference/apis/js-apis-enterprise-applicationManager.md @@ -1,11 +1,12 @@ # @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 @@ -37,7 +38,7 @@ Adds a list of applications that are forbidden to run by the current user throug For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). -| ID| Error Message | +| 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. | @@ -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"]; - -applicationManager.addDisallowedRunningBundles(wantTemp, appIds, (error) => { - if (error != null) { - console.log("error code:" + error.code + " error message:" + error.message); - } +let appIds = ['com.example.myapplication']; + +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'); }); ``` @@ -84,7 +87,7 @@ Adds a list of applications that are forbidden to run by a given user through th For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). -| ID| Error Message | +| 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. | @@ -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"]; - -applicationManager.addDisallowedRunningBundles(wantTemp, appIds, 100, (error) => { - if (error != null) { - console.log("error code:" + error.code + " error message:" + error.message); - } +let appIds = ['com.example.myapplication']; + +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'); }); ``` @@ -135,7 +140,7 @@ Adds a list of applications that are forbiddedn to run by the specified user (if For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). -| ID| Error Message | +| 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. | @@ -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}`); }); ``` @@ -180,7 +185,7 @@ Removes a list of applications that are forbiddedn to run by the current user th For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). -| ID| Error Message | +| 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. | @@ -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"]; - -applicationManager.removeDisallowedRunningBundles(wantTemp, appIds, (error) => { - if (error != null) { - console.log("error code:" + error.code + " error message:" + error.message); - } +let appIds = ['com.example.myapplication']; + +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'); }); ``` @@ -226,7 +233,7 @@ Removes a list of applications that are forbiddedn to run by the specified user For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). -| ID| Error Message | +| 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. | @@ -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"]; - -applicationManager.removeDisallowedRunningBundles(wantTemp, appIds, 100, (error) => { - if (error != null) { - console.log("error code:" + error.code + " error message:" + error.message); - } +let appIds = ['com.example.myapplication']; + +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'); }); ``` @@ -277,7 +286,7 @@ Removes a list of applications that are forbiddedn to run by the specified user For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). -| ID| Error Message | +| 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. | @@ -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}`); }); ``` @@ -321,7 +330,7 @@ Obtains the list of applications that are firbidded to run by the current user t For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). -| ID| Error Message | +| 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. | @@ -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)}`); }); ``` @@ -365,7 +376,7 @@ Obtains the list of applications that are firbidded to run by the specified user For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). -| ID| Error Message | +| 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. | @@ -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)}`); }); ``` @@ -414,7 +427,7 @@ Obtains the list of applications that are firbidded to run by the specified user For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). -| ID| Error Message | +| 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. | @@ -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}`); }); ``` diff --git a/en/application-dev/reference/apis/js-apis-enterprise-bundleManager.md b/en/application-dev/reference/apis/js-apis-enterprise-bundleManager.md index 0fe49e5a2a77937a3e12077f3efee6449be19557..5eea933ded9cbe5cbd3c82aa477c1ff4ea32b923 100644 --- a/en/application-dev/reference/apis/js-apis-enterprise-bundleManager.md +++ b/en/application-dev/reference/apis/js-apis-enterprise-bundleManager.md @@ -1,11 +1,13 @@ # @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"]; - -bundleManager.addAllowedInstallBundles(wantTemp, appIds, (error) => { - if (error != null) { - console.log("error code:" + error.code + " error message:" + error.message); - } +let appIds = ['com.example.myapplication']; + +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"]; - -bundleManager.addAllowedInstallBundles(wantTemp, appIds, 100, (error) => { - if (error != null) { - console.log("error code:" + error.code + " error message:" + error.message); - } +let appIds = ['com.example.myapplication']; + +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"]; - -bundleManager.removeAllowedInstallBundles(wantTemp, appIds, (error) => { - if (error != null) { - console.log("error code:" + error.code + " error message:" + error.message); - } +let appIds = ['com.example.myapplication']; + +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"]; - -bundleManager.removeAllowedInstallBundles(wantTemp, appIds, 100, (error) => { - if (error != null) { - console.log("error code:" + error.code + " error message:" + error.message); - } +let appIds = ['com.example.myapplication']; + +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"]; - -bundleManager.addDisallowedInstallBundles(wantTemp, appIds, (error) => { - if (error != null) { - console.log("error code:" + error.code + " error message:" + error.message); - } +let appIds = ['com.example.myapplication']; + +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"]; - -bundleManager.addDisallowedInstallBundles(wantTemp, appIds, 100, (error) => { - if (error != null) { - console.log("error code:" + error.code + " error message:" + error.message); - } +let appIds = ['com.example.myapplication']; + +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"]; - -bundleManager.removeDisallowedInstallBundles(wantTemp, appIds, (error) => { - if (error != null) { - console.log("error code:" + error.code + " error message:" + error.message); - } +let appIds = ['com.example.myapplication']; + +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<string> | Yes | Bundles to be removed. | +| appIds | Array<string> | 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<void> | 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"]; - -bundleManager.removeDisallowedInstallBundles(wantTemp, appIds, 100, (error) => { - if (error != null) { - console.log("error code:" + error.code + " error message:" + error.message); - } +let appIds = ['com.example.myapplication']; + +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"]; - -bundleManager.addDisallowedUninstallBundles(wantTemp, appIds, (error) => { - if (error != null) { - console.log("error code:" + error.code + " error message:" + error.message); - } +let appIds = ['com.example.myapplication']; + +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"]; - -bundleManager.addDisallowedUninstallBundles(wantTemp, appIds, 100, (error) => { - if (error != null) { - console.log("error code:" + error.code + " error message:" + error.message); - } +let appIds = ['com.example.myapplication']; + +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<string> | Yes | Bundles to be removed. | +| appIds | Array<string> | Yes | Bundles to be added. | | callback | AsyncCallback<void> | 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"]; - -bundleManager.removeDisallowedUninstallBundles(wantTemp, appIds, (error) => { - if (error != null) { - console.log("error code:" + error.code + " error message:" + error.message); - } +let appIds = ['com.example.myapplication']; + +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"]; - -bundleManager.removeDisallowedUninstallBundles(wantTemp, appIds, 100, (error) => { - if (error != null) { - console.log("error code:" + error.code + " error message:" + error.message); - } +let appIds = ['com.example.myapplication']; + +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<void>): 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<void> | 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<void>): 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<void> | 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<void>): 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<void> | 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<void>): 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<void> | 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<void> + +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<void> | 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}`); +}); ``` diff --git a/en/application-dev/reference/apis/js-apis-enterprise-dateTimeManager.md b/en/application-dev/reference/apis/js-apis-enterprise-dateTimeManager.md index f6f44a72f085df41e86616029201934e9b3c5c09..68d3434970c426586a344a76d16bc3516a26f628 100644 --- a/en/application-dev/reference/apis/js-apis-enterprise-dateTimeManager.md +++ b/en/application-dev/reference/apis/js-apis-enterprise-dateTimeManager.md @@ -1,11 +1,12 @@ # @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}`); }) ``` diff --git a/en/application-dev/reference/apis/js-apis-enterprise-deviceControl.md b/en/application-dev/reference/apis/js-apis-enterprise-deviceControl.md index 7079f0abcd7ab0a16440f8b491fd9c31517f2ef7..86b7381381b5710e4b4acc046e545f37b10e1c96 100644 --- a/en/application-dev/reference/apis/js-apis-enterprise-deviceControl.md +++ b/en/application-dev/reference/apis/js-apis-enterprise-deviceControl.md @@ -3,9 +3,11 @@ The **deviceControl** module provides APIs for device control, which can be called only by device administrator applications. > **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 -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\ | Promise that returns no value. If the operation fails, an error object is thrown.| +| Promise\ | 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}`); }) ``` diff --git a/en/application-dev/reference/apis/js-apis-enterprise-deviceInfo.md b/en/application-dev/reference/apis/js-apis-enterprise-deviceInfo.md index 260d7cd7ff7a53649c355461228aab8759740ba5..e859dd3af41f7cb97e7a204b80b2d0d98f4af9c3 100644 --- a/en/application-dev/reference/apis/js-apis-enterprise-deviceInfo.md +++ b/en/application-dev/reference/apis/js-apis-enterprise-deviceInfo.md @@ -1,11 +1,12 @@ # @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); - return; - } - console.log(result); + +deviceInfo.getDeviceSerial(wantTemp, (err, result) => { + if (err) { + console.error(`Failed to get device serial. Code: ${err.code}, message: ${err.message}`); + return; + } + 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); - return; - } - console.log(result); + +deviceInfo.getDisplayVersion(wantTemp, (err, result) => { + if (err) { + console.error(`Failed to get display version. Code: ${err.code}, message: ${err.message}`); + return; + } + 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); - return; - } - console.log(result); + +deviceInfo.getDeviceName(wantTemp, (err, result) => { + if (err) { + console.error(`Failed to get device name. Code: ${err.code}, message: ${err.message}`); + return; + } + 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}`); }); ``` diff --git a/en/application-dev/reference/apis/js-apis-enterprise-deviceSettings.md b/en/application-dev/reference/apis/js-apis-enterprise-deviceSettings.md new file mode 100644 index 0000000000000000000000000000000000000000..132c1d44b5e5c24150592c8bfabf73b61043df96 --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-enterprise-deviceSettings.md @@ -0,0 +1,108 @@ +# @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<number>): 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<number> | 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<number> + +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<number> | 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}`); +}); +``` diff --git a/en/application-dev/reference/apis/js-apis-enterprise-networkManager.md b/en/application-dev/reference/apis/js-apis-enterprise-networkManager.md index b60b2519e1035536d22c65154a0403b12bab7b5a..5b85d76cec32c66bab620e377f669a473e93ac75 100644 --- a/en/application-dev/reference/apis/js-apis-enterprise-networkManager.md +++ b/en/application-dev/reference/apis/js-apis-enterprise-networkManager.md @@ -1,11 +1,12 @@ # @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,14 +30,14 @@ 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<Array<string>> | 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** For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). -| ID| Error Message | +| ID| Error Message | | ------- | ---------------------------------------------------------------------------- | | 9200001 | The application is not an administrator application of the device. | | 9200002 | The administrator application does not have permission to manage the device.| @@ -45,15 +46,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes ```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); - return; - } - console.log(JSON.stringify(result)); + +networkManager.getAllNetworkInterfaces(wantTemp, (err, result) => { + if (err) { + console.error(`Failed to get all network interfaces. Code: ${err.code}, message: ${err.message}`); + return; + } + 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** @@ -85,7 +87,7 @@ Obtains all active network interfaces through the specified device administrator For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). -| ID| Error Message | +| 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.| @@ -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<string> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the IP address obtained. If the operation fails, **err** is an error object. | @@ -128,7 +131,7 @@ Obtains the device IP address based on the given network interface through the s For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). -| ID| Error Message | +| ID| Error Message | | ------- | ---------------------------------------------------------------------------- | | 9200001 | The application is not an administrator application of the device. | | 9200002 | The administrator application does not have permission to manage the device.| @@ -137,15 +140,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes ```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); - return; - } - console.log(result); + +networkManager.getIpAddress(wantTemp, 'eth0', (err, result) => { + if (err) { + console.error(`Failed to get ip address. Code: ${err.code}, message: ${err.message}`); + return; + } + 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** @@ -178,7 +182,7 @@ Obtains the device IP address based on the given network interface through the s For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). -| ID| Error Message | +| 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.| @@ -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<string> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the MAC address obtained. If the operation fails, **err** is an error object. | @@ -221,7 +226,7 @@ Obtains the device MAC address based on the given network interface through the For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). -| ID| Error Message | +| ID| Error Message | | ------- | ---------------------------------------------------------------------------- | | 9200001 | The application is not an administrator application of the device. | | 9200002 | The administrator application does not have permission to manage the device.| @@ -230,21 +235,22 @@ For details about the error codes, see [Enterprise Device Management Error Codes ```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); - return; - } - console.log(result); + +networkManager.getMac(wantTemp, 'eth0', (err, result) => { + if (err) { + console.error(`Failed to get mac. Code: ${err.code}, message: ${err.message}`); + return; + } + console.info(`Succeeded in getting mac, result : ${result}`); }); ``` ## networkManager.getMac -getIpAddress(admin: Want, networkInterface: string): Promise<string> +getMac(admin: Want, networkInterface: string): Promise\; 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** @@ -271,7 +277,7 @@ Obtain the device MAC address based on the given network interface through the s For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). -| ID| Error Message | +| 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.| @@ -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<boolean> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**, and **data** indicates whether the network interface is disabled. The value **true** means the network interface is disabled; and **false** means the opposite. If the operation fails, **err** is an error object. | @@ -314,7 +321,7 @@ Checks whether a network interface is disabled through the specified device admi For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). -| ID| Error Message | +| ID| Error Message | | ------- | ---------------------------------------------------------------------------- | | 9200001 | The application is not an administrator application of the device. | | 9200002 | The administrator application does not have permission to manage the device.| @@ -323,15 +330,16 @@ For details about the error codes, see [Enterprise Device Management Error Codes ```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); - return; - } - console.log("result:" + result); + +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.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** @@ -364,7 +372,7 @@ Checks whether a network interface is disabled through the specified device admi For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). -| ID| Error Message | +| 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.| @@ -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<void> | 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); - return; - } - console.log("setNetworkInterfaceDisabled success!"); + +networkManager.setNetworkInterfaceDisabled(wantTemp, 'eth0', true, (err) => { + if (err) { + console.error(`Failed to set network interface disabled. Code: ${err.code}, message: ${err.message}`); + return; + } + 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.log("setNetworkInterfaceDisabled success!"); -}).catch(error => { - console.log("error code:" + error.code + " error message:" + error.message); + +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 + +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<void> | 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\ + +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<void> | Promise that returns no value. If the operation fails, an error object will be thrown. | + +**Error codes** + +For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). + +| ID| Error Message | +| ------- | ---------------------------------------------------------------------------- | +| 9200001 | The application is not an administrator application of the device. | +| 9200002 | The administrator application does not have permission to manage the device.| + +**Example** + +```js +let wantTemp = { + bundleName: 'com.example.myapplication', + abilityName: 'EntryAbility', +}; +let filterRule = { + "ruleNo": 1, + "srcAddr": "192.168.1.1-192.188.22.66", + "destAddr": "10.1.1.1", + "srcPort": "8080", + "destPort": "8080", + "uid": "9696", + "method": networkManager.AddMethod.APPEND, + "direction": networkManager.Direction.OUTPUT, + "action": networkManager.Action.DENY, + "protocol": networkManager.Protocol.UDP, +} + +networkManager.addIptablesFilterRule(wantTemp, filterRule).then(() => { + console.info(`Succeeded in setting iptables filter rule`); +}).catch((err) => { + console.error(`Failed to set iptables filter rule. Code: ${err.code}, message: ${err.message}`); +}); +``` + +## networkManager.removeIptablesFilterRule + +removeIptablesFilterRule(admin: Want, filterRule: RemoveFilterRule, callback: AsyncCallback\): void + +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<void> | 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\ + +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<void> | 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\): 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<string> | 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\ + +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<string> | 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.| diff --git a/en/application-dev/reference/apis/js-apis-enterprise-restrictions.md b/en/application-dev/reference/apis/js-apis-enterprise-restrictions.md new file mode 100644 index 0000000000000000000000000000000000000000..be0db395fcec22420373aaf4aa650c9746959a92 --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-enterprise-restrictions.md @@ -0,0 +1,391 @@ +# @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 + +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\ | 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: '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\ + +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\ | 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\): 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\ | 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\ + +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\ | 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 + +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\ | 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: '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\ + +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\ | 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\): 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\ | 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\ + +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\ | 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}`); +}) +``` diff --git a/en/application-dev/reference/apis/js-apis-enterprise-wifiManager.md b/en/application-dev/reference/apis/js-apis-enterprise-wifiManager.md index 6990aa1fa577b600a2eeb9bafd5d0725f922ccb3..3d57b7d8be42df4e4b560b36885c7eccf885bbe7 100644 --- a/en/application-dev/reference/apis/js-apis-enterprise-wifiManager.md +++ b/en/application-dev/reference/apis/js-apis-enterprise-wifiManager.md @@ -1,11 +1,12 @@ # @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,31 +30,32 @@ 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<boolean> | 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** For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). -| ID| Error Message | +| ID| Error Message | | ------- | ---------------------------------------------------------------------------- | -| 9200001 | The application is not an administrator application of the device. | -| 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); - return; - } - console.log("result:" + result); + +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.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** @@ -85,22 +87,23 @@ Checks whether Wi-Fi is active through the specified device administrator applic For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). -| ID| Error Message | +| 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<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | @@ -128,29 +131,30 @@ Sets Wi-Fi to connect to the specified network. This API uses an asynchronous ca For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). -| ID| Error Message | +| ID| Error Message | | ------- | ---------------------------------------------------------------------------- | -| 9200001 | The application is not an administrator application of the device. | -| 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); - return; - } - console.log("set wifi success"); + +wifiManager.setWifiProfile(wantTemp, profile, (err) => { + if (err) { + console.error(`Failed to set wifi profile. Code: ${err.code}, message: ${err.message}`); + return; + } + 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** @@ -183,27 +187,28 @@ Sets Wi-Fi to connect to the specified network. This API uses a promise to retur For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). -| ID| Error Message | +| 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}`); }); ```