js-apis-enterprise-accountManager.md 4.5 KB
Newer Older
A
Annie_wang 已提交
1 2
# @ohos.enterprise.accountManager (Account Management)

A
Annie_wang 已提交
3
The **accountManager** module provides APIs for account management of enterprise devices. Only the device administrator applications can call the APIs provided by this module.
A
Annie_wang 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

> **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.

## Modules to Import

```js
import accountManager from '@ohos.enterprise.accountManager';
```

## accountManager.disallowAddLocalAccount

disallowAddLocalAccount(admin: Want, disallow: boolean, callback: AsyncCallback<void>): void

A
Annie_wang 已提交
19
Forbids a device administrator application to create local user accounts. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
20 21 22 23 24 25 26 27 28 29 30

**Required permissions**: ohos.permission.ENTERPRISE_SET_ACCOUNT_POLICY

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

**System API**: This is a system API.

**Parameters**

| Name     | Type                                      | Mandatory  | Description                      |
| -------- | ---------------------------------------- | ---- | ------------------------------- |
A
Annie_wang 已提交
31 32
| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Enterprise device administrator application.                 |
| disallow    | boolean     | Yes   | Whether to forbid the creation of local user accounts. The value **true** means that local user accounts cannot be created; the value **false** means the opposite.                 |
A
Annie_wang 已提交
33 34 35 36 37 38
| 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).

A
Annie_wang 已提交
39
| ID| Error Message                                                                      |
A
Annie_wang 已提交
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| ------- | ---------------------------------------------------------------------------- |
| 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",
};
accountManager.disallowAddLocalAccount(admin, true, (error) => {
    if (error != null) {
        console.log("error code:" + error.code + " error message:" + error.message);
    }
});
```

## accountManager.disallowAddLocalAccount

disallowAddLocalAccount(admin: Want, disallow: boolean): Promise<void>

A
Annie_wang 已提交
62
Forbids a device administrator application to create local user accounts. This API uses a promise to return the result.
A
Annie_wang 已提交
63 64 65 66 67 68 69 70 71 72 73

**Required permissions**: ohos.permission.ENTERPRISE_SET_ACCOUNT_POLICY

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

**System API**: This is a system API.

**Parameters**

| Name  | Type                                 | Mandatory  | Description     |
| ----- | ----------------------------------- | ---- | ------- |
A
Annie_wang 已提交
74 75
| admin | [Want](js-apis-app-ability-want.md) | Yes   | Enterprise device administrator application.|
| disallow    | boolean     | Yes   | Whether to forbid the creation of local user accounts. The value **true** means that local user accounts cannot be created; the value **false** means the opposite.                 |
A
Annie_wang 已提交
76 77 78 79 80

**Return value**

| Type                  | Description                     |
| --------------------- | ------------------------- |
A
Annie_wang 已提交
81
| Promise<void> | Promise that returns no value. An error object will be thrown if the operation fails.|
A
Annie_wang 已提交
82 83 84 85 86

**Error codes**

For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).

A
Annie_wang 已提交
87
| ID| Error Message                                                                    |
A
Annie_wang 已提交
88
| ------- | ---------------------------------------------------------------------------- |
A
Annie_wang 已提交
89 90
| 9200001 | The application is not an administrator application of the device.                       |
| 9200002 | The administrator application does not have permission to manage the device.|
A
Annie_wang 已提交
91 92 93 94 95 96 97 98 99 100 101 102 103 104

**Example**

```js
let wantTemp = {
    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);
});
```