js-apis-osAccount.md 209.7 KB
Newer Older
A
Annie_wang 已提交
1
# @ohos.account.osAccount (OS Account Management)
A
annie_wangli 已提交
2

A
Annie_wang 已提交
3
The **osAccount** module provides basic capabilities for managing OS accounts, including adding, deleting, querying, setting, subscribing to, and enabling an OS account.
A
Annie_wang 已提交
4

A
Annie_wang 已提交
5 6
> **NOTE**
>
A
annie_wangli 已提交
7 8 9 10 11
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.


## Modules to Import

Z
zhangalong 已提交
12
```js
A
annie_wangli 已提交
13 14 15 16 17 18 19 20 21
import account_osAccount from '@ohos.account.osAccount';
```

## account_osAccount.getAccountManager

getAccountManager(): AccountManager

Obtains an **AccountManager** instance.

A
annie_wangli 已提交
22
**System capability**: SystemCapability.Account.OsAccount
A
annie_wangli 已提交
23

A
Annie_wang 已提交
24
**Return value**
A
Annie_wang 已提交
25

A
Annie_wang 已提交
26 27 28
| Type                             | Description             |
| --------------------------------- | ---------------- |
| [AccountManager](#accountmanager) | **AccountManager** instance obtained.|
A
annie_wangli 已提交
29 30

**Example**
Z
zhangalong 已提交
31
  ```js
A
Annie_wang 已提交
32
  let accountManager = account_osAccount.getAccountManager();
A
annie_wangli 已提交
33 34 35
  ```

## OsAccountType
A
annie_wangli 已提交
36

A
Annie_wang 已提交
37
Enumerates the OS account types.
A
annie_wangli 已提交
38 39 40

**System capability**: SystemCapability.Account.OsAccount

A
Annie_wang 已提交
41
| Name  | Value| Description        |
A
Annie_wang 已提交
42
| ------ | ------ | ----------- |
A
annie_wangli 已提交
43 44 45
| ADMIN  | 0      | Administrator account|
| NORMAL | 1      | Normal account  |
| GUEST  | 2      | Guest account  |
A
annie_wangli 已提交
46 47 48

## AccountManager

A
Annie_wang 已提交
49
Provides APIs for managing OS accounts.
A
annie_wangli 已提交
50 51 52 53 54

### activateOsAccount

activateOsAccount(localId: number, callback: AsyncCallback<void>): void

A
Annie_wang 已提交
55
Activates an OS account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
56

A
Annie_wang 已提交
57
**System API**: This is a system API.
A
annie_wangli 已提交
58

A
annie_wangli 已提交
59 60
**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION

A
annie_wangli 已提交
61
**System capability**: SystemCapability.Account.OsAccount
A
annie_wangli 已提交
62

A
annie_wangli 已提交
63
**Parameters**
A
annie_wangli 已提交
64

A
Annie_wang 已提交
65 66 67 68 69 70 71 72 73 74 75 76 77 78
| Name  | Type                      | Mandatory| Description                                               |
| -------- | ------------------------- | ---- | -------------------------------------------------- |
| localId  | number                    | Yes  | ID of the target OS account.                 |
| 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**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid localId.    |
| 12300003 | Account not found. |
| 12300008 | Restricted Account. |
| 12300009 | Account has been activated. |
A
annie_wangli 已提交
79 80

**Example**: Activate OS account 100.
Z
zhangalong 已提交
81
  ```js
A
Annie_wang 已提交
82 83
  let accountManager = account_osAccount.getAccountManager();
  let localId = 100;
A
Annie_wang 已提交
84 85 86
  try {
    accountManager.activateOsAccount(localId, (err)=>{
      if (err) {
A
Annie_wang 已提交
87
        console.error(`activateOsAccount failed, code is ${err.code}, message is ${err.message}`);
A
Annie_wang 已提交
88 89 90 91 92
      } else {
        console.log("activateOsAccount successfully");
      }
    });
  } catch (err) {
A
Annie_wang 已提交
93
    console.error(`activateOsAccount failed, code is ${err.code}, message is ${err.message}`);
A
Annie_wang 已提交
94
  }
A
annie_wangli 已提交
95 96 97 98 99 100
  ```

### activateOsAccount

activateOsAccount(localId: number): Promise<void>

A
Annie_wang 已提交
101
Activates an OS account. This API uses a promise to return the result.
A
annie_wangli 已提交
102

A
Annie_wang 已提交
103
**System API**: This is a system API.
A
annie_wangli 已提交
104

Z
zhangalong 已提交
105 106
**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION

A
annie_wangli 已提交
107
**System capability**: SystemCapability.Account.OsAccount
A
annie_wangli 已提交
108

A
annie_wangli 已提交
109
**Parameters**
A
annie_wangli 已提交
110

A
annie_wangli 已提交
111 112
| Name | Type  | Mandatory| Description                |
| ------- | ------ | ---- | -------------------- |
A
Annie_wang 已提交
113
| localId | number | Yes  | ID of the target OS account.|
A
annie_wangli 已提交
114

A
Annie_wang 已提交
115
**Return value**
A
annie_wangli 已提交
116

A
Annie_wang 已提交
117 118 119 120 121 122 123 124 125 126 127 128 129
| Type               | Description                                 |
| ------------------- | ------------------------------------ |
| Promise<void> | Promise that returns no value.|

**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid localId.    |
| 12300003 | Account not found. |
| 12300008 | Restricted Account. |
| 12300009 | Account has been activated. |
A
annie_wangli 已提交
130 131

**Example**: Activate OS account 100.
Z
zhangalong 已提交
132
  ```js
A
Annie_wang 已提交
133 134
  let accountManager = account_osAccount.getAccountManager();
  let localId = 100;
A
Annie_wang 已提交
135 136 137 138 139 140 141 142 143
  try {
    accountManager.activateOsAccount(localId).then(() => {
      console.log('activateOsAccount successfully');
    }).catch((err) => {
      console.log('activateOsAccount failed, err:' + JSON.stringify(err));
    });
  } catch (e) {
    console.log('activateOsAccount exception:' + JSON.stringify(e));
  }
A
annie_wangli 已提交
144 145
  ```

A
Annie_wang 已提交
146
### checkMultiOsAccountEnabled<sup>9+</sup>
A
annie_wangli 已提交
147

A
Annie_wang 已提交
148
checkMultiOsAccountEnabled(callback: AsyncCallback&lt;boolean&gt;): void
A
annie_wangli 已提交
149

A
Annie_wang 已提交
150
Checks whether multiple OS accounts are supported. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
151

A
annie_wangli 已提交
152 153 154
**System capability**: SystemCapability.Account.OsAccount

**Parameters**
A
annie_wangli 已提交
155

A
Annie_wang 已提交
156 157
| Name  | Type                        | Mandatory| Description                                                    |
| -------- | ---------------------------- | ---- | ------------------------------------------------------ |
A
Annie_wang 已提交
158
| callback | AsyncCallback&lt;boolean&gt; | Yes  | Callback invoked to return the result. The value **true** means multiple OS accounts are supported; the value **false** means the opposite.|
A
Annie_wang 已提交
159 160 161 162 163 164

**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
A
annie_wangli 已提交
165

A
annie_wangli 已提交
166
**Example**
A
annie_wangli 已提交
167

Z
zhangalong 已提交
168
  ```js
A
Annie_wang 已提交
169
  let accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
170 171 172
  try {
    accountManager.checkMultiOsAccountEnabled((err, isEnabled) => {
      if (err) {
A
Annie_wang 已提交
173
        console.error(`checkMultiOsAccountEnabled failed, code is ${err.code}, message is ${err.message}`);
A
Annie_wang 已提交
174 175 176 177 178
      } else {
      console.log("checkMultiOsAccountEnabled successfully, isEnabled: " + isEnabled);
      }
    });
  } catch (err) {
A
Annie_wang 已提交
179
    console.error(`checkMultiOsAccountEnabled failed, code is ${err.code}, message is ${err.message}`);
A
Annie_wang 已提交
180
  }
A
annie_wangli 已提交
181 182
  ```

A
Annie_wang 已提交
183
### checkMultiOsAccountEnabled<sup>9+</sup>
A
annie_wangli 已提交
184

A
Annie_wang 已提交
185
checkMultiOsAccountEnabled(): Promise&lt;boolean&gt;
A
annie_wangli 已提交
186

A
Annie_wang 已提交
187
Checks whether multiple OS accounts are supported. This API uses a promise to return the result.
A
annie_wangli 已提交
188

A
annie_wangli 已提交
189
**System capability**: SystemCapability.Account.OsAccount
A
annie_wangli 已提交
190

A
Annie_wang 已提交
191
**Return value**
A
annie_wangli 已提交
192

A
Annie_wang 已提交
193 194
| Type                  | Description                                                       |
| :--------------------- | :--------------------------------------------------------- |
A
Annie_wang 已提交
195
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means multiple OS accounts are supported; the value **false** means the opposite.|
A
Annie_wang 已提交
196 197 198 199 200 201

**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
A
annie_wangli 已提交
202 203

**Example**
A
annie_wangli 已提交
204

Z
zhangalong 已提交
205
  ```js
A
Annie_wang 已提交
206 207 208 209 210
  try {
    let accountManager = account_osAccount.getAccountManager();
    accountManager.checkMultiOsAccountEnabled().then((isEnabled) => {
      console.log('checkMultiOsAccountEnabled successfully, isEnabled: ' + isEnabled);
    }).catch((err) => {
A
Annie_wang 已提交
211
      console.error(`checkMultiOsAccountEnabled failed, code is ${err.code}, message is ${err.message}`);
A
Annie_wang 已提交
212 213
    });
  } catch (err) {
A
Annie_wang 已提交
214
    console.error(`checkMultiOsAccountEnabled failed, code is ${err.code}, message is ${err.message}`);
A
Annie_wang 已提交
215
  }
A
annie_wangli 已提交
216 217
  ```

A
Annie_wang 已提交
218
### checkOsAccountActivated<sup>9+</sup>
A
annie_wangli 已提交
219

A
Annie_wang 已提交
220
checkOsAccountActivated(localId: number, callback: AsyncCallback&lt;boolean&gt;): void
A
annie_wangli 已提交
221

A
Annie_wang 已提交
222
Checks whether an OS account is activated. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
223

A
Annie_wang 已提交
224
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
A
annie_wangli 已提交
225 226

**System capability**: SystemCapability.Account.OsAccount
A
annie_wangli 已提交
227

A
annie_wangli 已提交
228
**Parameters**
A
annie_wangli 已提交
229

A
Annie_wang 已提交
230 231 232
| Name  | Type                        | Mandatory| Description                                                    |
| -------- | ---------------------------- | ---- | ------------------------------------------------------ |
| localId  | number                       | Yes  | ID of the target OS account.                                            |
A
Annie_wang 已提交
233
| callback | AsyncCallback&lt;boolean&gt; | Yes  | Callback invoked to return the result. The value **true** means the account is activated; the value **false** means the opposite.|
A
Annie_wang 已提交
234 235 236 237 238 239 240 241

**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid localId.    |
| 12300003 | Account not found. |
A
annie_wangli 已提交
242 243

**Example**: Check whether OS account 100 is activated.
A
annie_wangli 已提交
244

Z
zhangalong 已提交
245
  ```js
A
Annie_wang 已提交
246
  let accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
247 248 249 250 251 252 253 254 255 256 257 258
  let localId = 100;
  try {
    accountManager.checkOsAccountActivated(localId, (err, isActivated) => {
      if (err) {
        console.log('checkOsAccountActivated failed, error:' + JSON.stringify(err));
      } else {
        console.log('checkOsAccountActivated successfully, isActivated:' + isActivated);
      }
    });
  } catch (err) {
    console.log('checkOsAccountActivated exception:' + JSON.stringify(err));
  }
A
annie_wangli 已提交
259 260
  ```

A
Annie_wang 已提交
261
### checkOsAccountActivated<sup>9+</sup>
A
annie_wangli 已提交
262

A
Annie_wang 已提交
263
checkOsAccountActivated(localId: number): Promise&lt;boolean&gt;
A
annie_wangli 已提交
264

A
Annie_wang 已提交
265
Checks whether an OS account is activated. This API uses a promise to return the result.
A
annie_wangli 已提交
266

Z
zhangalong 已提交
267
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
A
annie_wangli 已提交
268 269

**System capability**: SystemCapability.Account.OsAccount
A
annie_wangli 已提交
270

A
annie_wangli 已提交
271
**Parameters**
A
annie_wangli 已提交
272

A
Annie_wang 已提交
273 274
| Name | Type  | Mandatory| Description                              |
| ------- | ------ | ---- | --------------------------------- |
A
annie_wangli 已提交
275
| localId | number | Yes  | ID of the target OS account.|
A
annie_wangli 已提交
276

A
Annie_wang 已提交
277
**Return value**
A
annie_wangli 已提交
278

A
Annie_wang 已提交
279 280
| Type                  | Description                                                      |
| ---------------------- | ---------------------------------------------------------- |
A
Annie_wang 已提交
281
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means the account is activated; the value **false** means the opposite.|
A
Annie_wang 已提交
282 283 284 285 286 287 288 289

**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid localId.    |
| 12300003 | Account not found. |
A
annie_wangli 已提交
290 291

**Example**: Check whether OS account 100 is activated.
A
annie_wangli 已提交
292

Z
zhangalong 已提交
293
  ```js
A
Annie_wang 已提交
294
  let accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
295 296 297 298 299 300 301 302 303 304
  let localId = 100;
  try {
    accountManager.checkOsAccountActivated(localId).then((isActivated) => {
      console.log('checkOsAccountActivated successfully, isActivated: ' + isActivated);
    }).catch((err) => {
      console.log('checkOsAccountActivated failed, error: '  + JSON.stringify(err));
    });
  } catch (err) {
    console.log('checkOsAccountActivated exception:' + JSON.stringify(err));
  }
A
annie_wangli 已提交
305 306
  ```

A
Annie_wang 已提交
307
### checkOsAccountConstraintEnabled<sup>9+</sup>
A
annie_wangli 已提交
308

A
Annie_wang 已提交
309
checkOsAccountConstraintEnabled(localId: number, constraint: string, callback: AsyncCallback&lt;boolean&gt;): void
A
annie_wangli 已提交
310

A
Annie_wang 已提交
311
Checks whether the specified constraint is enabled for an OS account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
312

A
Annie_wang 已提交
313
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
A
annie_wangli 已提交
314 315

**System capability**: SystemCapability.Account.OsAccount
A
annie_wangli 已提交
316

A
annie_wangli 已提交
317
**Parameters**
A
annie_wangli 已提交
318

A
Annie_wang 已提交
319 320 321 322
| Name    | Type                        | Mandatory| Description                                                              |
| ---------- | ---------------------------- | ---- | ----------------------------------------------------------------- |
| localId    | number                       | Yes  | ID of the target OS account.                                |
| constraint | string                       | Yes  | [Constraint](#constraints) to check.                               |
A
Annie_wang 已提交
323
| callback   | AsyncCallback&lt;boolean&gt; | Yes  | Callback invoked to return the result. The value **true** means the specified constraint is enabled; the value **false** means the opposite.|
A
Annie_wang 已提交
324 325 326 327 328 329 330 331

**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid localId.    |
| 12300003 | Account not found. |
A
annie_wangli 已提交
332

Z
zhangalong 已提交
333
**Example**: Check whether OS account 100 is forbidden to use Wi-Fi.
A
annie_wangli 已提交
334

Z
zhangalong 已提交
335
  ```js
A
Annie_wang 已提交
336 337
  let accountManager = account_osAccount.getAccountManager();
  let localId = 100;
A
Annie_wang 已提交
338 339
  let constraint = "constraint.wifi";
  try {
A
Annie_wang 已提交
340
    accountManager.checkOsAccountConstraintEnabled(localId, constraint, (err, isEnabled)=>{
A
Annie_wang 已提交
341
      if (err) {
A
Annie_wang 已提交
342
        console.log("checkOsAccountConstraintEnabled failed, error: " + JSON.stringify(err));
A
Annie_wang 已提交
343
      } else {
A
Annie_wang 已提交
344
        console.log("checkOsAccountConstraintEnabled successfully, isEnabled: " + isEnabled);
A
Annie_wang 已提交
345 346 347
      }
    });
  } catch (err) {
A
Annie_wang 已提交
348
    console.log("checkOsAccountConstraintEnabled exception: " + JSON.stringify(err));
A
Annie_wang 已提交
349
  }
A
annie_wangli 已提交
350 351
  ```

A
Annie_wang 已提交
352
### checkOsAccountConstraintEnabled<sup>9+</sup>
A
annie_wangli 已提交
353

A
Annie_wang 已提交
354
checkOsAccountConstraintEnabled(localId: number, constraint: string): Promise&lt;boolean&gt;
A
annie_wangli 已提交
355

A
Annie_wang 已提交
356
Checks whether the specified constraint is enabled for an OS account. This API uses a promise to return the result.
A
annie_wangli 已提交
357

A
Annie_wang 已提交
358
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
A
annie_wangli 已提交
359 360

**System capability**: SystemCapability.Account.OsAccount
A
annie_wangli 已提交
361

A
annie_wangli 已提交
362
**Parameters**
A
annie_wangli 已提交
363

A
Annie_wang 已提交
364 365 366 367
| Name    | Type  | Mandatory| Description                               |
| ---------- | ------ | ---- | ---------------------------------- |
| localId    | number | Yes  | ID of the target OS account. |
| constraint | string | Yes  | [Constraint](#constraints) to check.|
A
annie_wangli 已提交
368

A
Annie_wang 已提交
369
**Return value**
A
annie_wangli 已提交
370

A
Annie_wang 已提交
371 372
| Type                  | Description                                                                 |
| --------------------- | --------------------------------------------------------------------- |
A
Annie_wang 已提交
373
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means the specified constraint is enabled; the value **false** means the opposite.|
A
Annie_wang 已提交
374 375 376 377 378 379 380 381

**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid localId.    |
| 12300003 | Account not found. |
A
annie_wangli 已提交
382

Z
zhangalong 已提交
383
**Example**: Check whether OS account 100 is forbidden to use Wi-Fi.
A
annie_wangli 已提交
384

Z
zhangalong 已提交
385
  ```js
A
Annie_wang 已提交
386 387
  let accountManager = account_osAccount.getAccountManager();
  let localId = 100;
A
Annie_wang 已提交
388 389
  let constraint = "constraint.wifi";
  try {
A
Annie_wang 已提交
390 391
    accountManager.checkOsAccountConstraintEnabled(localId, constraint).then((isEnabled) => {
      console.log("checkOsAccountConstraintEnabled successfully, isEnabled: " + isEnabled);
A
Annie_wang 已提交
392
    }).catch((err) => {
A
Annie_wang 已提交
393
      console.log("checkOsAccountConstraintEnabled failed, error: "  + JSON.stringify(err));
A
Annie_wang 已提交
394 395
    });
  } catch (err) {
A
Annie_wang 已提交
396
    console.log("checkOsAccountConstraintEnabled exception: " + JSON.stringify(err));
A
Annie_wang 已提交
397
  }
A
annie_wangli 已提交
398 399
  ```

A
Annie_wang 已提交
400
### checkOsAccountTestable<sup>9+</sup>
A
annie_wangli 已提交
401

A
Annie_wang 已提交
402
checkOsAccountTestable(callback: AsyncCallback&lt;boolean&gt;): void
A
annie_wangli 已提交
403

A
Annie_wang 已提交
404
Checks whether this OS account is a test account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
405

A
annie_wangli 已提交
406 407 408
**System capability**: SystemCapability.Account.OsAccount

**Parameters**
A
annie_wangli 已提交
409

A
Annie_wang 已提交
410 411
| Name  | Type                        | Mandatory| Description                                                                  |
| -------- | ---------------------------- | ---- | --------------------------------------------------------------------- |
A
Annie_wang 已提交
412
| callback | AsyncCallback&lt;boolean&gt; | Yes  | Callback invoked to return the result. The value **true** means the account is a test account; the value **false** means the opposite.|
A
Annie_wang 已提交
413 414 415 416 417 418

**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
A
annie_wangli 已提交
419

A
annie_wangli 已提交
420
**Example**
A
annie_wangli 已提交
421

Z
zhangalong 已提交
422
  ```js
A
Annie_wang 已提交
423
  let accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
424 425 426 427 428 429 430 431 432 433 434
  try {
    accountManager.checkOsAccountTestable((err, isTestable) => {
      if (err) {
        console.log("checkOsAccountTestable failed, error: " + JSON.stringify(err));
      } else {
        console.log("checkOsAccountTestable successfully, isTestable: " + isTestable);
      }
    });
  } catch (err) {
    console.log("checkOsAccountTestable error: " + JSON.stringify(err));
  }
A
annie_wangli 已提交
435 436
  ```

A
Annie_wang 已提交
437
### checkOsAccountTestable<sup>9+</sup>
A
annie_wangli 已提交
438

A
Annie_wang 已提交
439
checkOsAccountTestable(): Promise&lt;boolean&gt;
A
annie_wangli 已提交
440

A
Annie_wang 已提交
441
Checks whether this OS account is a test account. This API uses a promise to return the result.
A
annie_wangli 已提交
442

A
annie_wangli 已提交
443
**System capability**: SystemCapability.Account.OsAccount
A
annie_wangli 已提交
444

A
Annie_wang 已提交
445
**Return value**
A
annie_wangli 已提交
446

A
Annie_wang 已提交
447 448
| Type                  | Description                                                                     |
| ---------------------- | ------------------------------------------------------------------------ |
A
Annie_wang 已提交
449
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means the account is a test account; the value **false** means the opposite.|
A
Annie_wang 已提交
450 451 452 453 454 455

**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
A
annie_wangli 已提交
456 457

**Example**
A
annie_wangli 已提交
458

Z
zhangalong 已提交
459
  ```js
A
Annie_wang 已提交
460
  let accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
461 462 463 464 465 466 467 468 469
  try {
    accountManager.checkOsAccountTestable().then((isTestable) => {
      console.log("checkOsAccountTestable successfully, isTestable: " + isTestable);
    }).catch((err) => {
      console.log("checkOsAccountTestable failed, error: "  + JSON.stringify(err));
    });
  } catch (err) {
    console.log('checkOsAccountTestable exception: ' + JSON.stringify(err));
  }
A
annie_wangli 已提交
470 471
  ```

A
Annie_wang 已提交
472
### checkOsAccountVerified<sup>9+</sup>
A
annie_wangli 已提交
473

A
Annie_wang 已提交
474
checkOsAccountVerified(callback: AsyncCallback&lt;boolean&gt;): void
A
annie_wangli 已提交
475

A
Annie_wang 已提交
476
Checks whether this OS account has been verified. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
477

A
Annie_wang 已提交
478 479
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS

A
annie_wangli 已提交
480 481 482
**System capability**: SystemCapability.Account.OsAccount

**Parameters**
A
annie_wangli 已提交
483

A
Annie_wang 已提交
484 485
| Name  | Type                        | Mandatory| Description                                                           |
| -------- | ---------------------------- | ---- | ------------------------------------------------------------- |
A
Annie_wang 已提交
486
| callback | AsyncCallback&lt;boolean&gt; | Yes  | Callback invoked to return the result. The value **true** means the OS account has been verified; the value **false** means the opposite.|
A
Annie_wang 已提交
487 488 489 490 491 492 493 494

**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid localId.    |
| 12300003 | Account not found. |
A
annie_wangli 已提交
495

A
annie_wangli 已提交
496
**Example**
A
annie_wangli 已提交
497

Z
zhangalong 已提交
498
  ```js
A
Annie_wang 已提交
499
  let accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
500 501 502 503 504 505 506 507 508 509 510
  try {
    accountManager.checkOsAccountVerified((err, isVerified) => {
      if (err) {
        console.log("checkOsAccountVerified failed, error: " + JSON.stringify(err));
      } else {
        console.log("checkOsAccountVerified successfully, isVerified: " + isVerified);
      }
    });
  } catch (err) {
    console.log("checkOsAccountVerified exception: " + JSON.stringify(err));
  }
A
annie_wangli 已提交
511 512
  ```

A
Annie_wang 已提交
513
### checkOsAccountVerified<sup>9+</sup>
A
annie_wangli 已提交
514

A
Annie_wang 已提交
515
checkOsAccountVerified(localId: number, callback: AsyncCallback&lt;boolean&gt;): void
A
annie_wangli 已提交
516

A
Annie_wang 已提交
517
Checks whether an OS account has been verified. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
518

Z
zhangalong 已提交
519 520
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS

A
annie_wangli 已提交
521
**System capability**: SystemCapability.Account.OsAccount
A
annie_wangli 已提交
522

A
annie_wangli 已提交
523
**Parameters**
A
annie_wangli 已提交
524

A
Annie_wang 已提交
525 526
| Name  | Type                        | Mandatory| Description                                                           |
| -------- | ---------------------------- | ---- | ------------------------------------------------------------- |
A
Annie_wang 已提交
527 528
| localId  | number                       | Yes  | ID of the target OS account.                             |
| callback | AsyncCallback&lt;boolean&gt; | Yes  | Callback invoked to return the result. The value **true** means the OS account has been verified; the value **false** means the opposite.|
A
Annie_wang 已提交
529 530 531 532 533 534 535 536

**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid localId.    |
| 12300003 | Account not found. |
A
annie_wangli 已提交
537 538

**Example**
A
annie_wangli 已提交
539

Z
zhangalong 已提交
540
  ```js
A
Annie_wang 已提交
541
  let accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
542 543 544 545 546 547 548 549 550 551 552 553
  let localId = 100;
  try {
    accountManager.checkOsAccountVerified(localId, (err, isVerified) => {
      if (err) {
        console.log("checkOsAccountVerified failed, error: " + JSON.stringify(err));
      } else {
        console.log("checkOsAccountVerified successfully, isVerified: " + isVerified);
      }
    });
  } catch (err) {
    console.log("checkOsAccountVerified exception: " + err);
  }
A
annie_wangli 已提交
554 555
  ```

A
Annie_wang 已提交
556
### checkOsAccountVerified<sup>9+</sup>
A
annie_wangli 已提交
557

A
Annie_wang 已提交
558
checkOsAccountVerified(localId?: number): Promise&lt;boolean&gt;
A
annie_wangli 已提交
559

A
Annie_wang 已提交
560
Checks whether an OS account has been verified. This API uses a promise to return the result.
A
annie_wangli 已提交
561

Z
zhangalong 已提交
562 563
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS

A
annie_wangli 已提交
564 565 566
**System capability**: SystemCapability.Account.OsAccount

**Parameters**
A
annie_wangli 已提交
567

A
Annie_wang 已提交
568 569 570
| Name | Type  | Mandatory| Description                                                             |
| ------- | ------ | ---- | --------------------------------------------------------------- |
| localId | number | No  | ID of the target OS account. If this parameter is not specified, this API checks whether the current OS account has been verified.|
A
annie_wangli 已提交
571

A
Annie_wang 已提交
572
**Return value**
A
annie_wangli 已提交
573

A
Annie_wang 已提交
574 575
| Type                  | Description                                                              |
| ---------------------- | ----------------------------------------------------------------- |
A
Annie_wang 已提交
576
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means the OS account has been verified; the value **false** means the opposite.|
A
Annie_wang 已提交
577 578 579 580 581 582 583 584

**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid localId.    |
| 12300003 | Account not found. |
A
annie_wangli 已提交
585

A
annie_wangli 已提交
586
**Example**
A
annie_wangli 已提交
587

Z
zhangalong 已提交
588
  ```js
A
Annie_wang 已提交
589
  let accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
590 591 592 593 594 595 596 597 598 599
  let localId = 100;
  try {
    accountManager.checkOsAccountVerified(localId).then((isVerified) => {
      console.log("checkOsAccountVerified successfully, isVerified: " + isVerified);
    }).catch((err) => {
      console.log("checkOsAccountVerified failed, error: " + JSON.stringify(err));
    });
  } catch (err) {
    console.log('checkOsAccountVerified exception: ' + JSON.stringify(err));
  }
A
annie_wangli 已提交
600 601 602 603 604 605
  ```

### removeOsAccount

removeOsAccount(localId: number, callback: AsyncCallback&lt;void&gt;): void

A
Annie_wang 已提交
606
Deletes an OS account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
607

A
Annie_wang 已提交
608
**System API**: This is a system API.
A
annie_wangli 已提交
609

A
annie_wangli 已提交
610
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS
A
annie_wangli 已提交
611

A
annie_wangli 已提交
612 613 614 615
**System capability**: SystemCapability.Account.OsAccount

**Parameters**

A
Annie_wang 已提交
616 617 618 619 620 621 622 623 624 625 626 627 628
| Name  | Type                     | Mandatory| Description                                                |
| -------- | ------------------------- | ---- | -------------------------------------------------- |
| localId  | number                    | Yes  | ID of the target OS account.                 |
| callback | AsyncCallback&lt;void&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|

**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid localId.    |
| 12300003 | Account not found. |
| 12300008 | Restricted Account. |
A
annie_wangli 已提交
629 630

**Example**
A
annie_wangli 已提交
631

Z
zhangalong 已提交
632
  ```js
A
Annie_wang 已提交
633
  let accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
634 635 636 637 638 639 640 641 642 643
  let accountName = "testAccountName";
  try {
    accountManager.createOsAccount(accountName, account_osAccount.OsAccountType.NORMAL, (err, osAccountInfo) => {
      accountManager.removeOsAccount(osAccountInfo.localId, (err)=>{
        if (err) {
          console.log("removeOsAccount failed, error: " + JSON.stringify(err));
        } else {
          console.log("removeOsAccount successfully");
        }
      });
A
Annie_wang 已提交
644
    });
A
Annie_wang 已提交
645 646 647
  } catch (err) {
    console.log('removeOsAccount exception:' + JSON.stringify(err));
  }
A
annie_wangli 已提交
648 649 650 651 652 653
  ```

### removeOsAccount

removeOsAccount(localId: number): Promise&lt;void&gt;

A
Annie_wang 已提交
654
Deletes an OS account. This API uses a promise to return the result.
A
annie_wangli 已提交
655

A
Annie_wang 已提交
656
**System API**: This is a system API.
A
annie_wangli 已提交
657 658 659 660 661 662

**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

**System capability**: SystemCapability.Account.OsAccount

**Parameters**
A
annie_wangli 已提交
663

A
Annie_wang 已提交
664 665 666
| Name | Type  | Mandatory| Description                              |
| ------- | ------ | ---- | --------------------------------- |
| localId | number | Yes  | ID of the target OS account.|
A
annie_wangli 已提交
667

A
Annie_wang 已提交
668
**Return value**
A
annie_wangli 已提交
669

A
Annie_wang 已提交
670 671 672 673 674 675 676 677 678 679 680 681
| Type               | Description                                 |
| ------------------- | ------------------------------------ |
| Promise&lt;void&gt; | Promise that returns no value.|

**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid localId.    |
| 12300003 | Account not found. |
| 12300008 | Restricted Account. |
A
annie_wangli 已提交
682

A
annie_wangli 已提交
683
**Example**
A
annie_wangli 已提交
684

Z
zhangalong 已提交
685
  ```js
A
Annie_wang 已提交
686
  let accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
687 688 689 690 691 692 693 694
  let accountName = "testAccountName";
  try {
    accountManager.createOsAccount(accountName, account_osAccount.OsAccountType.NORMAL, (err, osAccountInfo)=>{
      accountManager.removeOsAccount(osAccountInfo.localId).then(() => {
        console.log("removeOsAccount successfully");
      }).catch((err) => {
          console.log("removeOsAccount failed, error: " + JSON.stringify(err));
      });
A
Annie_wang 已提交
695
    });
A
Annie_wang 已提交
696 697 698
  } catch (err) {
    console.log("removeOsAccount exception: " + JSON.stringify(err));
  }
A
annie_wangli 已提交
699 700 701 702 703 704
  ```

### setOsAccountConstraints

setOsAccountConstraints(localId: number, constraints: Array&lt;string&gt;, enable: boolean,callback: AsyncCallback&lt;void&gt;): void

A
Annie_wang 已提交
705
Sets or removes constraints for an OS account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
706

A
Annie_wang 已提交
707
**System API**: This is a system API.
A
annie_wangli 已提交
708 709 710 711

**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

**System capability**: SystemCapability.Account.OsAccount
A
annie_wangli 已提交
712

A
annie_wangli 已提交
713
**Parameters**
A
annie_wangli 已提交
714

A
Annie_wang 已提交
715 716 717 718 719 720 721 722 723 724 725 726 727 728 729
| Name     | Type                     | Mandatory| Description                                            |
| ----------- | ------------------------- | ---- | ----------------------------------------------- |
| localId     | number                    | Yes  | ID of the target OS account.              |
| constraints | Array&lt;string&gt;       | Yes  | List of [constraints](#constraints) to set or remove.       |
| enable      | boolean                   | Yes  | Set or remove constraints. The value **true** means to set constraints, and **false** means to remove constraints.                          |
| callback    | AsyncCallback&lt;void&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|

**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid localId.    |
| 12300003 | Account not found. |
| 12300008 | Restricted Account. |
A
annie_wangli 已提交
730

Z
zhangalong 已提交
731
**Example**: Disable Wi-Fi for OS account 100.
A
annie_wangli 已提交
732

Z
zhangalong 已提交
733
  ```js
A
Annie_wang 已提交
734 735
  let accountManager = account_osAccount.getAccountManager();
  let localId = 100;
A
Annie_wang 已提交
736 737 738 739 740 741 742 743 744 745 746 747
  let constraint = "constraint.wifi";
  try {
    accountManager.setOsAccountConstraints(localId, [constraint], true, (err) => {
      if (err) {
        console.log("setOsAccountConstraints failed, error:" + JSON.stringify(err));
      } else {
        console.log("setOsAccountConstraints successfully");
      }
    });
  } catch (err) {
    console.log("setOsAccountConstraints exception: " + JSON.stringify(err));
  }
A
annie_wangli 已提交
748 749 750 751 752 753
  ```

### setOsAccountConstraints

setOsAccountConstraints(localId: number, constraints: Array&lt;string&gt;, enable: boolean): Promise&lt;void&gt;

A
Annie_wang 已提交
754
Sets or removes constraints for an OS account. This API uses a promise to return the result.
A
annie_wangli 已提交
755

A
Annie_wang 已提交
756
**System API**: This is a system API.
A
annie_wangli 已提交
757

A
annie_wangli 已提交
758
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS
A
annie_wangli 已提交
759

A
annie_wangli 已提交
760
**System capability**: SystemCapability.Account.OsAccount
A
annie_wangli 已提交
761

A
annie_wangli 已提交
762
**Parameters**
A
annie_wangli 已提交
763

A
annie_wangli 已提交
764 765
| Name     | Type               | Mandatory| Description                                        |
| ----------- | ------------------- | ---- | -------------------------------------------- |
A
Annie_wang 已提交
766 767
| localId     | number              | Yes  | ID of the target OS account.          |
| constraints | Array&lt;string&gt; | Yes  | List of [constraints](#constraints) to set or remove.   |
A
annie_wangli 已提交
768 769
| enable      | boolean             | Yes  | Set or remove constraints. The value **true** means to set constraints, and **false** means to remove constraints.                    |

A
Annie_wang 已提交
770
**Return value**
A
annie_wangli 已提交
771

A
Annie_wang 已提交
772 773 774 775 776 777 778 779 780 781 782 783
| Type               | Description                                |
| :------------------ | :----------------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|

**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid localId.    |
| 12300003 | Account not found. |
| 12300008 | Restricted Account. |
A
annie_wangli 已提交
784

A
Annie_wang 已提交
785
**Example**: Remove the constraint on the use of Wi-Fi for OS account 100.
A
annie_wangli 已提交
786

Z
zhangalong 已提交
787
  ```js
A
Annie_wang 已提交
788 789
  let accountManager = account_osAccount.getAccountManager();
  let localId = 100;
A
Annie_wang 已提交
790 791 792 793 794 795 796 797 798
  try {
    accountManager.setOsAccountConstraints(localId, ['constraint.location.set'], false).then(() => {
      console.log('setOsAccountConstraints succsuccessfully');
    }).catch((err) => {
      console.log('setOsAccountConstraints failed, error: '  + JSON.stringify(err));
    });
  } catch (err) {
    console.log('setOsAccountConstraints exception:' + JSON.stringify(err));
  }
A
annie_wangli 已提交
799 800 801 802 803 804
  ```

### setOsAccountName

setOsAccountName(localId: number, localName: string, callback: AsyncCallback&lt;void&gt;): void

A
Annie_wang 已提交
805
Sets a name for an OS account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
806

A
Annie_wang 已提交
807
**System API**: This is a system API.
A
annie_wangli 已提交
808

Z
zhangalong 已提交
809 810
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

A
annie_wangli 已提交
811
**System capability**: SystemCapability.Account.OsAccount
A
annie_wangli 已提交
812

A
annie_wangli 已提交
813
**Parameters**
A
annie_wangli 已提交
814

A
Annie_wang 已提交
815 816 817
| Name   | Type                     | Mandatory| Description                                            |
| :-------- | ------------------------- | ---- | ----------------------------------------------- |
| localId   | number                    | Yes  | ID of the target OS account.              |
A
Annie_wang 已提交
818
| localName | string                    | Yes  | Account name. The value cannot exceed 1024 characters.                         |
A
Annie_wang 已提交
819 820 821 822 823 824 825 826 827 828
| callback  | AsyncCallback&lt;void&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|

**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid localId or localName. |
| 12300003 | Account not found. |
| 12300008 | Restricted Account. |
A
annie_wangli 已提交
829 830

**Example**: Set the name of OS account 100 to **demoName**.
A
annie_wangli 已提交
831

Z
zhangalong 已提交
832
  ```js
A
Annie_wang 已提交
833 834
  let accountManager = account_osAccount.getAccountManager();
  let localId = 100;
A
Annie_wang 已提交
835 836 837 838 839 840 841 842 843 844 845 846
  let name = "demoName";
  try {
    accountManager.setOsAccountName(localId, name, (err) => {
      if (err) {
        console.log("setOsAccountName failed, error: " + JSON.stringify(err));
      } else {
        console.log("setOsAccountName successfully");
      }
    });
  } catch (err) {
    console.log('setOsAccountName exception:' + JSON.stringify(err));
  }
A
annie_wangli 已提交
847 848 849 850 851 852
  ```

### setOsAccountName

setOsAccountName(localId: number, localName: string): Promise&lt;void&gt;

A
Annie_wang 已提交
853
Sets a name for an OS account. This API uses a promise to return the result.
A
annie_wangli 已提交
854

A
Annie_wang 已提交
855
**System API**: This is a system API.
A
annie_wangli 已提交
856

Z
zhangalong 已提交
857 858
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

A
annie_wangli 已提交
859
**System capability**: SystemCapability.Account.OsAccount
A
annie_wangli 已提交
860

A
annie_wangli 已提交
861
**Parameters**
A
annie_wangli 已提交
862

A
Annie_wang 已提交
863 864
| Name   | Type  | Mandatory| Description                               |
| --------- | ------ | ---- | --------------------------------- |
A
annie_wangli 已提交
865
| localId   | number | Yes  | ID of the target OS account.|
A
Annie_wang 已提交
866
| localName | string | Yes  | Account name to set. The value cannot exceed 1024 characters.           |
A
annie_wangli 已提交
867

A
Annie_wang 已提交
868
**Return value**
A
annie_wangli 已提交
869

A
Annie_wang 已提交
870 871 872 873 874 875 876 877 878 879 880 881
| Type               | Description                                 |
| ------------------- | ------------------------------------ |
| Promise&lt;void&gt; | Promise that returns no value.|

**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid localId or localName.    |
| 12300003 | Account not found. |
| 12300008 | Restricted Account. |
A
annie_wangli 已提交
882 883

**Example**: Set the name of OS account 100 to **demoName**.
A
annie_wangli 已提交
884

Z
zhangalong 已提交
885
  ```js
A
Annie_wang 已提交
886 887
  let accountManager = account_osAccount.getAccountManager();
  let localId = 100;
A
Annie_wang 已提交
888 889 890 891 892 893 894 895 896 897
  let name = 'testName';
  try {
    accountManager.setOsAccountName(localId, name).then(() => {
      console.log('setOsAccountName successfully');
    }).catch((err) => {
      console.log('setOsAccountName failed, error: '  + JSON.stringify(err));
    });
  } catch (err) {
    console.log('setOsAccountName exception:' + JSON.stringify(err));
  }
A
annie_wangli 已提交
898 899
  ```

A
Annie_wang 已提交
900
### getOsAccountCount<sup>9+</sup>
A
annie_wangli 已提交
901

A
Annie_wang 已提交
902
getOsAccountCount(callback: AsyncCallback&lt;number&gt;): void
A
annie_wangli 已提交
903

A
Annie_wang 已提交
904
Obtains the number of OS accounts created. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
905

A
annie_wangli 已提交
906 907 908
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

**System capability**: SystemCapability.Account.OsAccount
A
annie_wangli 已提交
909

A
annie_wangli 已提交
910
**Parameters**
A
annie_wangli 已提交
911

A
Annie_wang 已提交
912 913 914 915 916 917 918 919 920
| Name  | Type                       | Mandatory| Description                                                                        |
| -------- | --------------------------- | ---- | -------------------------------------------------------------------------- |
| callback | AsyncCallback&lt;number&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the number of created OS accounts. If the operation fails, **err** is an error object.|

**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
A
annie_wangli 已提交
921 922

**Example**
A
annie_wangli 已提交
923

Z
zhangalong 已提交
924
  ```js
A
Annie_wang 已提交
925
  let accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
926 927 928 929 930 931 932 933 934 935 936
  try {
    accountManager.getOsAccountCount((err, count) => {
      if (err) {
        console.log("getOsAccountCount failed, error: " + JSON.stringify(err));
      } else {
        console.log("getOsAccountCount successfully, count: " + count);
      }
    });
  } catch (err) {
    console.log("getOsAccountCount exception: " + JSON.stringify(err));
  }
A
annie_wangli 已提交
937 938
  ```

A
Annie_wang 已提交
939
### getOsAccountCount<sup>9+</sup>
A
annie_wangli 已提交
940

A
Annie_wang 已提交
941
getOsAccountCount(): Promise&lt;number&gt;
A
annie_wangli 已提交
942

A
Annie_wang 已提交
943
Obtains the number of OS accounts created. This API uses a promise to return the result.
A
annie_wangli 已提交
944

A
annie_wangli 已提交
945 946 947 948
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

**System capability**: SystemCapability.Account.OsAccount

A
Annie_wang 已提交
949
**Return value**
A
annie_wangli 已提交
950

A
Annie_wang 已提交
951 952 953 954 955 956 957 958 959
| Type                 | Description                                   |
| --------------------- | -------------------------------------- |
| Promise&lt;number&gt; | Promise used to return the number of created OS accounts.|

**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
A
annie_wangli 已提交
960

A
annie_wangli 已提交
961
**Example**
A
annie_wangli 已提交
962

Z
zhangalong 已提交
963
  ```js
A
Annie_wang 已提交
964
  let accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
965 966 967 968 969 970 971 972 973
  try {
    accountManager.getOsAccountCount().then((count) => {
      console.log("getOsAccountCount successfully, count: " + count);
    }).catch((err) => {
      console.log("getOsAccountCount failed, error: " + JSON.stringify(err));
    });
  } catch(err) {
    console.log('getOsAccountCount exception:' + JSON.stringify(err));
  }
A
annie_wangli 已提交
974 975
  ```

A
Annie_wang 已提交
976
### getOsAccountLocalId<sup>9+</sup>
A
annie_wangli 已提交
977

A
Annie_wang 已提交
978
getOsAccountLocalId(callback: AsyncCallback&lt;number&gt;): void
A
annie_wangli 已提交
979

A
Annie_wang 已提交
980
Obtains the ID of the OS account to which the current process belongs. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
981

A
annie_wangli 已提交
982
**System capability**: SystemCapability.Account.OsAccount
A
annie_wangli 已提交
983

A
annie_wangli 已提交
984
**Parameters**
A
annie_wangli 已提交
985

A
Annie_wang 已提交
986 987 988 989 990 991 992 993 994
| Name  | Type                       | Mandatory| Description                                                                          |
| -------- | --------------------------- | ---- | ---------------------------------------------------------------------------- |
| callback | AsyncCallback&lt;number&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the OS account ID obtained. Otherwise, **err** is an error object.|

**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
A
annie_wangli 已提交
995 996

**Example**
A
annie_wangli 已提交
997

Z
zhangalong 已提交
998
  ```js
A
Annie_wang 已提交
999
  let accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
1000
  try {
A
Annie_wang 已提交
1001
    accountManager.getOsAccountLocalId((err, localId) => {
A
Annie_wang 已提交
1002
      if (err) {
A
Annie_wang 已提交
1003
        console.log("getOsAccountLocalId failed, error: " + JSON.stringify(err));
A
Annie_wang 已提交
1004
      } else {
A
Annie_wang 已提交
1005
        console.log("getOsAccountLocalId successfully, localId: " + localId);
A
Annie_wang 已提交
1006 1007 1008
      }
    });
  } catch (err) {
A
Annie_wang 已提交
1009
    console.log("getOsAccountLocalId exception: " + JSON.stringify(err));
A
Annie_wang 已提交
1010
  }
A
annie_wangli 已提交
1011 1012
  ```

A
Annie_wang 已提交
1013
### getOsAccountLocalId<sup>9+</sup>
A
annie_wangli 已提交
1014

A
Annie_wang 已提交
1015
getOsAccountLocalId(): Promise&lt;number&gt;
A
annie_wangli 已提交
1016

A
Annie_wang 已提交
1017
Obtains the ID of the OS account to which the current process belongs. This API uses a promise to return the result.
A
annie_wangli 已提交
1018

A
annie_wangli 已提交
1019 1020
**System capability**: SystemCapability.Account.OsAccount

A
Annie_wang 已提交
1021
**Return value**
A
annie_wangli 已提交
1022

A
Annie_wang 已提交
1023 1024 1025 1026 1027 1028 1029 1030 1031
| Type                 | Description                                     |
| --------------------- | ---------------------------------------- |
| Promise&lt;number&gt; | Promise used to return the OS account ID obtained.|

**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
A
annie_wangli 已提交
1032

A
annie_wangli 已提交
1033
**Example**
A
annie_wangli 已提交
1034

Z
zhangalong 已提交
1035
  ```js
A
Annie_wang 已提交
1036
  let accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
1037
  try {
A
Annie_wang 已提交
1038 1039
    accountManager.getOsAccountLocalId().then((localId) => {
      console.log("getOsAccountLocalId successfully, localId: " + localId);
A
Annie_wang 已提交
1040
    }).catch((err) => {
A
Annie_wang 已提交
1041
      console.log("getOsAccountLocalId failed, error: "  + JSON.stringify(err));
A
Annie_wang 已提交
1042 1043
    });
  } catch (err) {
A
Annie_wang 已提交
1044
    console.log('getOsAccountLocalId exception: ' + JSON.stringify(err));
A
Annie_wang 已提交
1045
  }
A
annie_wangli 已提交
1046 1047
  ```

A
Annie_wang 已提交
1048
### getOsAccountLocalIdForUid<sup>9+</sup>
A
annie_wangli 已提交
1049

A
Annie_wang 已提交
1050
getOsAccountLocalIdForUid(uid: number, callback: AsyncCallback&lt;number&gt;): void
A
annie_wangli 已提交
1051

A
Annie_wang 已提交
1052
Obtains the OS account ID based on the process UID. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1053

A
annie_wangli 已提交
1054
**System capability**: SystemCapability.Account.OsAccount
A
annie_wangli 已提交
1055

A
annie_wangli 已提交
1056
**Parameters**
A
annie_wangli 已提交
1057

A
Annie_wang 已提交
1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068
| Name  | Type                       | Mandatory| Description                                                                   |
| -------- | --------------------------- | ---- | --------------------------------------------------------------------- |
| uid      | number                      | Yes  | Process UID.                                                             |
| callback | AsyncCallback&lt;number&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the OS account ID obtained. Otherwise, **data** is an error object.|

**Error codes**

| ID| Error Message        |
| -------- | --------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid uid.    |
A
annie_wangli 已提交
1069 1070

**Example**: Obtain the ID of the OS account whose process UID is **12345678**.
A
annie_wangli 已提交
1071

Z
zhangalong 已提交
1072
  ```js
A
Annie_wang 已提交
1073
  let accountManager = account_osAccount.getAccountManager();
A
annie_wangli 已提交
1074
  let uid = 12345678;
A
Annie_wang 已提交
1075
  try {
A
Annie_wang 已提交
1076
    accountManager.getOsAccountLocalIdForUid(uid, (err, localId) => {
A
Annie_wang 已提交
1077
      if (err) {
A
Annie_wang 已提交
1078
        console.log("getOsAccountLocalIdForUid failed, error: " + JSON.stringify(err));
A
Annie_wang 已提交
1079
      }
A
Annie_wang 已提交
1080
      console.log("getOsAccountLocalIdForUid successfully, localId: " + localId);
A
Annie_wang 已提交
1081 1082
    });
  } catch (err) {
A
Annie_wang 已提交
1083
    console.log("getOsAccountLocalIdForUid exception: " + JSON.stringify(err));
A
Annie_wang 已提交
1084
  }
A
annie_wangli 已提交
1085 1086
  ```

A
Annie_wang 已提交
1087
### getOsAccountLocalIdForUid<sup>9+</sup>
A
annie_wangli 已提交
1088

A
Annie_wang 已提交
1089
getOsAccountLocalIdForUid(uid: number): Promise&lt;number&gt;
A
annie_wangli 已提交
1090

A
Annie_wang 已提交
1091
Obtains the OS account ID based on the process UID. This API uses a promise to return the result.
A
annie_wangli 已提交
1092

A
annie_wangli 已提交
1093 1094 1095
**System capability**: SystemCapability.Account.OsAccount

**Parameters**
A
annie_wangli 已提交
1096

A
annie_wangli 已提交
1097 1098 1099
| Name| Type  | Mandatory| Description     |
| ------ | ------ | ---- | --------- |
| uid    | number | Yes  | Process UID.|
A
annie_wangli 已提交
1100

A
Annie_wang 已提交
1101
**Return value**
A
annie_wangli 已提交
1102

A
Annie_wang 已提交
1103 1104
| Type                 | Description                                    |
| --------------------- | --------------------------------------- |
A
annie_wangli 已提交
1105
| Promise&lt;number&gt; | Promise used to return the OS account ID obtained.|
A
annie_wangli 已提交
1106

A
Annie_wang 已提交
1107 1108 1109 1110 1111 1112 1113
**Error codes**

| ID| Error Message      |
| -------- | ------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid uid. |

A
annie_wangli 已提交
1114
**Example**: Obtain the ID of the OS account whose process UID is **12345678**.
A
annie_wangli 已提交
1115

Z
zhangalong 已提交
1116
  ```js
A
Annie_wang 已提交
1117
  let accountManager = account_osAccount.getAccountManager();
A
annie_wangli 已提交
1118
  let uid = 12345678;
A
Annie_wang 已提交
1119
  try {
A
Annie_wang 已提交
1120 1121
    accountManager.getOsAccountLocalIdForUid(uid).then((localId) => {
      console.log("getOsAccountLocalIdForUid successfully, localId: " + localId);
A
Annie_wang 已提交
1122
    }).catch((err) => {
A
Annie_wang 已提交
1123
      console.log("getOsAccountLocalIdForUid failed, error: " + JSON.stringify(err));
A
Annie_wang 已提交
1124 1125
    });
  } catch (err) {
A
Annie_wang 已提交
1126
    console.log('getOsAccountLocalIdForUid exception: ' + JSON.stringify(err));
A
Annie_wang 已提交
1127
  }
A
annie_wangli 已提交
1128 1129
  ```

A
Annie_wang 已提交
1130
### getOsAccountLocalIdForDomain<sup>9+</sup>
A
annie_wangli 已提交
1131

A
Annie_wang 已提交
1132
getOsAccountLocalIdForDomain(domainInfo: DomainAccountInfo, callback: AsyncCallback&lt;number&gt;): void
A
annie_wangli 已提交
1133

A
Annie_wang 已提交
1134
Obtains the OS account ID based on the domain account information. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1135

A
annie_wangli 已提交
1136
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS
A
annie_wangli 已提交
1137

A
annie_wangli 已提交
1138
**System capability**: SystemCapability.Account.OsAccount
A
annie_wangli 已提交
1139

A
annie_wangli 已提交
1140 1141
**Parameters**

A
Annie_wang 已提交
1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152
| Name    | Type                                   | Mandatory| Description                                                                        |
| ---------- | --------------------------------------- | ---- | -------------------------------------------------------------------------- |
| domainInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes  | Domain account information.                                                               |
| callback   | AsyncCallback&lt;number&gt;             | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the ID of the OS account associated with the domain account. Otherwise, **err** is an error object.|

**Error codes**

| ID| Error Message      |
| -------- | ------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid domainInfo. |
A
annie_wangli 已提交
1153 1154

**Example**
A
annie_wangli 已提交
1155

Z
zhangalong 已提交
1156
  ```js
A
Annie_wang 已提交
1157 1158
  let domainInfo = {domain: 'testDomain', accountName: 'testAccountName'};
  let accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
1159
  try {
A
Annie_wang 已提交
1160
    accountManager.getOsAccountLocalIdForDomain(domainInfo, (err, localId) => {
A
Annie_wang 已提交
1161
      if (err) {
A
Annie_wang 已提交
1162
        console.log("getOsAccountLocalIdForDomain failed, error: " + JSON.stringify(err));
A
Annie_wang 已提交
1163
      } else {
A
Annie_wang 已提交
1164
        console.log("getOsAccountLocalIdForDomain successfully, localId: " + localId);
A
Annie_wang 已提交
1165 1166 1167
      }
    });
  } catch (err) {
A
Annie_wang 已提交
1168
    console.log('getOsAccountLocalIdForDomain exception: ' + JSON.stringify(err));
A
Annie_wang 已提交
1169
  }
A
annie_wangli 已提交
1170 1171
  ```

A
Annie_wang 已提交
1172
### getOsAccountLocalIdForDomain<sup>9+</sup>
A
annie_wangli 已提交
1173

A
Annie_wang 已提交
1174
getOsAccountLocalIdForDomain(domainInfo: DomainAccountInfo): Promise&lt;number&gt;
A
annie_wangli 已提交
1175

A
Annie_wang 已提交
1176
Obtains the OS account ID based on the domain account information. This API uses a promise to return the result.
A
annie_wangli 已提交
1177

A
annie_wangli 已提交
1178 1179 1180 1181 1182
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

**System capability**: SystemCapability.Account.OsAccount

**Parameters**
A
annie_wangli 已提交
1183

A
annie_wangli 已提交
1184 1185
| Name    | Type                                   | Mandatory| Description        |
| ---------- | --------------------------------------- | ---- | ------------ |
A
Annie_wang 已提交
1186
| domainInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes  | Domain account information.|
A
annie_wangli 已提交
1187

A
Annie_wang 已提交
1188
**Return value**
A
annie_wangli 已提交
1189

A
Annie_wang 已提交
1190 1191
| Type                 | Description                                   |
| :-------------------- | :------------------------------------- |
A
annie_wangli 已提交
1192
| Promise&lt;number&gt; | Promise used to return the ID of the OS account associated with the domain account.|
A
annie_wangli 已提交
1193

A
Annie_wang 已提交
1194 1195 1196 1197 1198 1199 1200
**Error codes**

| ID| Error Message      |
| -------- | ------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid domainInfo. |

A
annie_wangli 已提交
1201
**Example**
A
annie_wangli 已提交
1202

Z
zhangalong 已提交
1203
  ```js
A
Annie_wang 已提交
1204 1205
  let accountManager = account_osAccount.getAccountManager();
  let domainInfo = {domain: 'testDomain', accountName: 'testAccountName'};
A
Annie_wang 已提交
1206
  try {
A
Annie_wang 已提交
1207 1208
    accountManager.getOsAccountLocalIdForDomain(domainInfo).then((localId) => {
      console.log("getOsAccountLocalIdForDomain successfully, localId: " + localId);
A
Annie_wang 已提交
1209
    }).catch((err) => {
A
Annie_wang 已提交
1210
      console.log("getOsAccountLocalIdForDomain failed, error: "  + JSON.stringify(err));
A
Annie_wang 已提交
1211 1212
    });
  } catch (err) {
A
Annie_wang 已提交
1213
    console.log("getOsAccountLocalIdForDomain exception: " + JSON.stringify(err));
A
Annie_wang 已提交
1214
  }
A
annie_wangli 已提交
1215 1216 1217 1218 1219 1220
  ```

### queryMaxOsAccountNumber

queryMaxOsAccountNumber(callback: AsyncCallback&lt;number&gt;): void

A
Annie_wang 已提交
1221
Obtains the maximum number of OS accounts that can be created. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1222

A
Annie_wang 已提交
1223
**System API**: This is a system API.
A
annie_wangli 已提交
1224

A
annie_wangli 已提交
1225
**System capability**: SystemCapability.Account.OsAccount
A
annie_wangli 已提交
1226

A
annie_wangli 已提交
1227 1228
**Parameters**

A
Annie_wang 已提交
1229 1230 1231 1232 1233 1234 1235 1236 1237
| Name  | Type                       | Mandatory| Description                                                                             |
| -------- | --------------------------- | ---- | -------------------------------------------------------------------------------- |
| callback | AsyncCallback&lt;number&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the maximum number of OS accounts that can be created. Otherwise, **err** is an error object.|

**Error codes**

| ID| Error Message      |
| -------- | ------------- |
| 12300001 | System service exception. |
A
annie_wangli 已提交
1238 1239

**Example**
A
annie_wangli 已提交
1240

Z
zhangalong 已提交
1241
  ```js
A
Annie_wang 已提交
1242
  let accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253
  try {
    accountManager.queryMaxOsAccountNumber((err, maxCnt) => {
      if (err) {
        console.log('queryMaxOsAccountNumber failed, error:' + JSON.stringify(err));
      } else {
        console.log('queryMaxOsAccountNumber successfully, maxCnt:' + maxCnt);
      }
    });
  } catch (err) {
    console.log('queryMaxOsAccountNumber exception:' + JSON.stringify(err));
  }
A
annie_wangli 已提交
1254 1255 1256 1257 1258 1259
  ```

### queryMaxOsAccountNumber

queryMaxOsAccountNumber(): Promise&lt;number&gt;

A
Annie_wang 已提交
1260
Obtains the maximum number of OS accounts that can be created. This API uses a promise to return the result.
A
annie_wangli 已提交
1261

A
Annie_wang 已提交
1262
**System API**: This is a system API.
A
annie_wangli 已提交
1263 1264 1265

**System capability**: SystemCapability.Account.OsAccount

A
Annie_wang 已提交
1266
**Return value**
A
annie_wangli 已提交
1267

A
Annie_wang 已提交
1268 1269
| Type                 | Description                                        |
| --------------------- | ------------------------------------------- |
A
annie_wangli 已提交
1270
| Promise&lt;number&gt; | Promise used to return the maximum number of OS accounts that can be created.|
A
annie_wangli 已提交
1271

A
Annie_wang 已提交
1272 1273 1274 1275 1276 1277
**Error codes**

| ID| Error Message      |
| -------- | ------------- |
| 12300001 | System service exception. |

A
annie_wangli 已提交
1278
**Example**
A
annie_wangli 已提交
1279

Z
zhangalong 已提交
1280
  ```js
A
Annie_wang 已提交
1281
  let accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
1282 1283 1284 1285 1286 1287 1288 1289 1290
  try {
    accountManager.queryMaxOsAccountNumber().then((maxCnt) => {
      console.log('queryMaxOsAccountNumber successfully, maxCnt: ' + maxCnt);
    }).catch((err) => {
      console.log('queryMaxOsAccountNumber failed, error: '  + JSON.stringify(err));
    });
  } catch (err) {
    console.log('queryMaxOsAccountNumber exception:' + JSON.stringify(err));
  }
A
annie_wangli 已提交
1291 1292
  ```

A
Annie_wang 已提交
1293
### getOsAccountConstraints<sup>9+</sup>
A
annie_wangli 已提交
1294

A
Annie_wang 已提交
1295
getOsAccountConstraints(localId: number, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void
A
annie_wangli 已提交
1296

A
Annie_wang 已提交
1297
Obtains all constraints enabled for an OS account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1298

A
annie_wangli 已提交
1299
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS
A
annie_wangli 已提交
1300

A
annie_wangli 已提交
1301
**System capability**: SystemCapability.Account.OsAccount
A
annie_wangli 已提交
1302

A
annie_wangli 已提交
1303 1304
**Parameters**

A
Annie_wang 已提交
1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316
| Name  | Type                                    | Mandatory| Description                                                                                          |
| -------- | ---------------------------------------- | ---- | -------------------------------------------------------------------------------------------- |
| localId  | number                                   | Yes  | ID of the target OS account.                                                                                 |
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is all [constraints](#constraints) obtained. Otherwise, **err** is an error object.|

**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid localId.    |
| 12300003 | Account not found. |
A
annie_wangli 已提交
1317

Z
zhangalong 已提交
1318
**Example**: Obtain all constraints of OS account 100.
A
annie_wangli 已提交
1319

Z
zhangalong 已提交
1320
  ```js
A
Annie_wang 已提交
1321 1322
  let accountManager = account_osAccount.getAccountManager();
  let localId = 100;
A
Annie_wang 已提交
1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333
  try {
    accountManager.getOsAccountConstraints(localId, (err, constraints) => {
      if (err) {
        console.log("getOsAccountConstraints failed, err: " + JSON.stringify(err));
      } else {
        console.log("getOsAccountConstraints successfully, constraints: " + JSON.stringify(constraints));
      }
    });
  } catch (err) {
    console.log('getOsAccountConstraints exception:' + JSON.stringify(err));
  }
A
annie_wangli 已提交
1334 1335
  ```

A
Annie_wang 已提交
1336
### getOsAccountConstraints<sup>9+</sup>
A
annie_wangli 已提交
1337

A
Annie_wang 已提交
1338
getOsAccountConstraints(localId: number): Promise&lt;Array&lt;string&gt;&gt;
A
annie_wangli 已提交
1339

A
Annie_wang 已提交
1340
Obtains all constraints enabled for an OS account. This API uses a promise to return the result.
A
annie_wangli 已提交
1341 1342

**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS
A
annie_wangli 已提交
1343

A
annie_wangli 已提交
1344
**System capability**: SystemCapability.Account.OsAccount
A
annie_wangli 已提交
1345

A
annie_wangli 已提交
1346
**Parameters**
A
annie_wangli 已提交
1347

A
annie_wangli 已提交
1348 1349 1350
| Name | Type  | Mandatory| Description        |
| ------- | ------ | ---- | ------------ |
| localId | number | Yes  | ID of the target OS account.|
A
annie_wangli 已提交
1351

A
Annie_wang 已提交
1352
**Return value**
A
annie_wangli 已提交
1353

A
Annie_wang 已提交
1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364
| Type                              | Description                                                      |
| ---------------------------------- | ---------------------------------------------------------- |
| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return all the [constraints](#constraints) enabled for the OS account.|

**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid localId.    |
| 12300003 | Account not found. |
A
annie_wangli 已提交
1365

Z
zhangalong 已提交
1366
**Example**: Obtain all constraints of OS account 100.
A
annie_wangli 已提交
1367

Z
zhangalong 已提交
1368
  ```js
A
Annie_wang 已提交
1369 1370
  let accountManager = account_osAccount.getAccountManager();
  let localId = 100;
A
Annie_wang 已提交
1371 1372 1373 1374 1375 1376 1377 1378 1379
  try {
    accountManager.getOsAccountConstraints(localId).then((constraints) => {
      console.log('getOsAccountConstraints, constraints: ' + constraints);
    }).catch((err) => {
      console.log('getOsAccountConstraints err: '  + JSON.stringify(err));
    });
  } catch (e) {
    console.log('getOsAccountConstraints exception:' + JSON.stringify(e));
  }
A
annie_wangli 已提交
1380 1381 1382 1383 1384 1385
  ```

### queryAllCreatedOsAccounts

queryAllCreatedOsAccounts(callback: AsyncCallback&lt;Array&lt;OsAccountInfo&gt;&gt;): void

A
Annie_wang 已提交
1386
Obtains information about all the OS accounts created. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1387

A
Annie_wang 已提交
1388
**System API**: This is a system API.
A
annie_wangli 已提交
1389 1390

**System capability**: SystemCapability.Account.OsAccount
A
annie_wangli 已提交
1391

A
Annie_wang 已提交
1392 1393
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

A
annie_wangli 已提交
1394
**Parameters**
A
annie_wangli 已提交
1395

A
annie_wangli 已提交
1396 1397
| Name  | Type                                                        | Mandatory| Description                                              |
| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------------- |
A
Annie_wang 已提交
1398 1399 1400 1401 1402 1403 1404
| callback | AsyncCallback&lt;Array&lt;[OsAccountInfo](#osaccountinfo)&gt;&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is a list of all created OS accounts. Otherwise, **data** is an error object.|

**Error codes**

| ID| Error Message      |
| -------- | ------------- |
| 12300001 | System service exception. |
A
annie_wangli 已提交
1405 1406

**Example**
A
annie_wangli 已提交
1407

Z
zhangalong 已提交
1408
  ```js
A
Annie_wang 已提交
1409
  let accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
1410 1411 1412 1413 1414 1415 1416 1417
  try {
    accountManager.queryAllCreatedOsAccounts((err, accountArr)=>{
      console.log('queryAllCreatedOsAccounts err:' + JSON.stringify(err));
      console.log('queryAllCreatedOsAccounts accountArr:' + JSON.stringify(accountArr));
    });
  } catch (e) {
    console.log('queryAllCreatedOsAccounts exception:' + JSON.stringify(e));
  }
A
annie_wangli 已提交
1418 1419 1420 1421 1422 1423
  ```

### queryAllCreatedOsAccounts

queryAllCreatedOsAccounts(): Promise&lt;Array&lt;OsAccountInfo&gt;&gt;

A
Annie_wang 已提交
1424
Obtains information about all the OS accounts created. This API uses a promise to return the result.
A
annie_wangli 已提交
1425

A
Annie_wang 已提交
1426
**System API**: This is a system API.
A
annie_wangli 已提交
1427 1428

**System capability**: SystemCapability.Account.OsAccount
A
annie_wangli 已提交
1429

A
Annie_wang 已提交
1430 1431
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

A
Annie_wang 已提交
1432
**Return value**
A
annie_wangli 已提交
1433

A
Annie_wang 已提交
1434 1435 1436 1437 1438 1439 1440 1441 1442
| Type                                                       | Description                                          |
| ----------------------------------------------------------- | --------------------------------------------- |
| Promise&lt;Array&lt;[OsAccountInfo](#osaccountinfo)&gt;&gt; | Promise used to return the information about all the OS accounts created.|

**Error codes**

| ID| Error Message      |
| -------- | ------------- |
| 12300001 | System service exception. |
A
annie_wangli 已提交
1443 1444

**Example**
A
annie_wangli 已提交
1445

Z
zhangalong 已提交
1446
  ```js
A
Annie_wang 已提交
1447
  let accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
1448 1449 1450 1451 1452 1453 1454 1455 1456
  try {
    accountManager.queryAllCreatedOsAccounts().then((accountArr) => {
      console.log('queryAllCreatedOsAccounts, accountArr: ' + JSON.stringify(accountArr));
    }).catch((err) => {
      console.log('queryAllCreatedOsAccounts err: '  + JSON.stringify(err));
    });
  } catch (e) {
    console.log('queryAllCreatedOsAccounts exception:' + JSON.stringify(e));
  }
A
annie_wangli 已提交
1457 1458
  ```

A
Annie_wang 已提交
1459
### getActivatedOsAccountLocalIds<sup>9+</sup>
A
annie_wangli 已提交
1460

A
Annie_wang 已提交
1461
getActivatedOsAccountLocalIds(callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
A
annie_wangli 已提交
1462

A
Annie_wang 已提交
1463
Obtains information about all activated OS accounts. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1464

A
annie_wangli 已提交
1465 1466 1467
**System capability**: SystemCapability.Account.OsAccount

**Parameters**
A
annie_wangli 已提交
1468

A
annie_wangli 已提交
1469 1470
| Name  | Type                                    | Mandatory| Description                                                  |
| -------- | ---------------------------------------- | ---- | ------------------------------------------------------ |
A
Annie_wang 已提交
1471 1472 1473 1474 1475 1476 1477
| callback | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is a list of activated OS accounts. Otherwise, **data** is an error object.|

**Error codes**

| ID| Error Message      |
| -------- | ------------- |
| 12300001 | System service exception. |
A
annie_wangli 已提交
1478

A
annie_wangli 已提交
1479
**Example**
A
annie_wangli 已提交
1480

Z
zhangalong 已提交
1481
  ```js
A
Annie_wang 已提交
1482
  let accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
1483
  try {
A
Annie_wang 已提交
1484 1485 1486
    accountManager.getActivatedOsAccountLocalIds((err, idArray)=>{
      console.log('getActivatedOsAccountLocalIds err:' + JSON.stringify(err));
      console.log('getActivatedOsAccountLocalIds idArray length:' + idArray.length);
A
Annie_wang 已提交
1487 1488 1489 1490 1491
      for(let i=0;i<idArray.length;i++) {
        console.info('activated os account id: ' + idArray[i]);
      }
    });
  } catch (e) {
A
Annie_wang 已提交
1492
    console.log('getActivatedOsAccountLocalIds exception:' + JSON.stringify(e));
A
Annie_wang 已提交
1493
  }
A
annie_wangli 已提交
1494 1495
  ```

A
Annie_wang 已提交
1496
### getActivatedOsAccountLocalIds<sup>9+</sup>
A
annie_wangli 已提交
1497

A
Annie_wang 已提交
1498
getActivatedOsAccountLocalIds(): Promise&lt;Array&lt;number&gt;&gt;
A
annie_wangli 已提交
1499

A
Annie_wang 已提交
1500
Obtains information about all activated OS accounts. This API uses a promise to return the result.
A
annie_wangli 已提交
1501

A
annie_wangli 已提交
1502
**System capability**: SystemCapability.Account.OsAccount
A
annie_wangli 已提交
1503

A
Annie_wang 已提交
1504
**Return value**
A
annie_wangli 已提交
1505

A
Annie_wang 已提交
1506 1507 1508 1509 1510 1511 1512 1513 1514
| Type                              | Description                                              |
| :--------------------------------- | :------------------------------------------------ |
| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the information about all activated OS accounts.|

**Error codes**

| ID| Error Message      |
| -------- | ------------- |
| 12300001 | System service exception. |
A
annie_wangli 已提交
1515 1516

**Example**
A
annie_wangli 已提交
1517

Z
zhangalong 已提交
1518
  ```js
A
Annie_wang 已提交
1519
  let accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
1520
  try {
A
Annie_wang 已提交
1521 1522
    accountManager.getActivatedOsAccountLocalIds().then((idArray) => {
      console.log('getActivatedOsAccountLocalIds, idArray: ' + idArray);
A
Annie_wang 已提交
1523
    }).catch((err) => {
A
Annie_wang 已提交
1524
      console.log('getActivatedOsAccountLocalIds err: '  + JSON.stringify(err));
A
Annie_wang 已提交
1525 1526
    });
  } catch (e) {
A
Annie_wang 已提交
1527
    console.log('getActivatedOsAccountLocalIds exception:' + JSON.stringify(e));
A
Annie_wang 已提交
1528
  }
A
annie_wangli 已提交
1529 1530 1531 1532 1533 1534
  ```

### createOsAccount

createOsAccount(localName: string, type: OsAccountType, callback: AsyncCallback&lt;OsAccountInfo&gt;): void

A
Annie_wang 已提交
1535
Creates an OS account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1536

A
Annie_wang 已提交
1537
**System API**: This is a system API.
A
annie_wangli 已提交
1538 1539

**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS
A
annie_wangli 已提交
1540

A
annie_wangli 已提交
1541
**System capability**: SystemCapability.Account.OsAccount
A
annie_wangli 已提交
1542

A
annie_wangli 已提交
1543 1544
**Parameters**

A
Annie_wang 已提交
1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559
| Name   | Type                                                | Mandatory| Description                                                                        |
| :-------- | ---------------------------------------------------- | ---- | --------------------------------------------------------------------------- |
| localName | string                                               | Yes  | Name of the OS account to create.                                                       |
| type      | [OsAccountType](#osaccounttype)                      | Yes  | Type of the OS account to create.                                                       |
| callback  | AsyncCallback&lt;[OsAccountInfo](#osaccountinfo)&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the created OS account. Otherwise, **err** is an error object.|

**Error codes**

| ID | Error Message                  |
| -------- | ------------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid localName or type. |
| 12300005 | Multi-user not supported. |
| 12300006 | Unsupported account type. |
| 12300007 | The number of account reaches the upper limit. |
A
annie_wangli 已提交
1560 1561

**Example**
A
annie_wangli 已提交
1562

Z
zhangalong 已提交
1563
  ```js
A
Annie_wang 已提交
1564
  let accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
1565 1566 1567 1568 1569 1570 1571 1572
  try {
    accountManager.createOsAccount('testName', account_osAccount.OsAccountType.NORMAL, (err, osAccountInfo)=>{
      console.log('createOsAccount err:' + JSON.stringify(err));
      console.log('createOsAccount osAccountInfo:' + JSON.stringify(osAccountInfo));
    });
  } catch (e) {
    console.log('createOsAccount exception:' + JSON.stringify(e));
  }
A
annie_wangli 已提交
1573 1574 1575 1576 1577 1578
  ```

### createOsAccount

createOsAccount(localName: string, type: OsAccountType): Promise&lt;OsAccountInfo&gt;

A
Annie_wang 已提交
1579
Creates an OS account. This API uses a promise to return the result.
A
annie_wangli 已提交
1580

A
Annie_wang 已提交
1581
**System API**: This is a system API.
A
annie_wangli 已提交
1582 1583 1584 1585

**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

**System capability**: SystemCapability.Account.OsAccount
A
annie_wangli 已提交
1586

A
annie_wangli 已提交
1587
**Parameters**
A
annie_wangli 已提交
1588

A
annie_wangli 已提交
1589 1590 1591 1592
| Name   | Type                           | Mandatory| Description                  |
| --------- | ------------------------------- | ---- | ---------------------- |
| localName | string                          | Yes  | Name of the OS account to create.|
| type      | [OsAccountType](#osaccounttype) | Yes  | Type of the OS account to create.|
A
annie_wangli 已提交
1593

A
Annie_wang 已提交
1594
**Return value**
A
annie_wangli 已提交
1595

A
Annie_wang 已提交
1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608
| Type                                          | Description                                 |
| ---------------------------------------------- | ------------------------------------- |
| Promise&lt;[OsAccountInfo](#osaccountinfo)&gt; | Promise used to return the information about the created OS account.|

**Error codes**

| ID | Error Message                  |
| -------- | ------------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid localName or type. |
| 12300005 | Multi-user not supported. |
| 12300006 | Unsupported account type. |
| 12300007 | The number of account reaches the upper limit. |
A
annie_wangli 已提交
1609 1610

**Example**
A
annie_wangli 已提交
1611

Z
zhangalong 已提交
1612
  ```js
A
Annie_wang 已提交
1613
  let accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
1614 1615 1616 1617 1618 1619 1620 1621 1622
  try {
    accountManager.createOsAccount('testAccountName', account_osAccount.OsAccountType.NORMAL).then((accountInfo) => {
      console.log('createOsAccount, accountInfo: ' + JSON.stringify(accountInfo));
    }).catch((err) => {
      console.log('createOsAccount err: '  + JSON.stringify(err));
    });
  } catch (e) {
    console.log('createOsAccount exception:' + JSON.stringify(e));
  }
A
annie_wangli 已提交
1623 1624
  ```

A
annie_wangli 已提交
1625
### createOsAccountForDomain<sup>8+</sup>
A
annie_wangli 已提交
1626 1627 1628

createOsAccountForDomain(type: OsAccountType, domainInfo: DomainAccountInfo, callback: AsyncCallback&lt;OsAccountInfo&gt;): void

A
Annie_wang 已提交
1629
Creates an OS account and associates it with the specified domain account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1630

A
Annie_wang 已提交
1631
**System API**: This is a system API.
A
annie_wangli 已提交
1632 1633 1634 1635

**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

**System capability**: SystemCapability.Account.OsAccount
A
annie_wangli 已提交
1636

A
annie_wangli 已提交
1637
**Parameters**
A
annie_wangli 已提交
1638

A
Annie_wang 已提交
1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653
| Name    | Type                                                | Mandatory| Description                                                                        |
| ---------- | ---------------------------------------------------- | ---- | -------------------------------------------------------------------------- |
| type       | [OsAccountType](#osaccounttype)                      | Yes  | Type of the OS account to create.                                                      |
| domainInfo | [DomainAccountInfo](#domainaccountinfo8)              | Yes  | Domain account information.                                                              |
| callback   | AsyncCallback&lt;[OsAccountInfo](#osaccountinfo)&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the created OS account. Otherwise, **err** is an error object.|

**Error codes**

| ID| Error Message                    |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid type or domainInfo. |
| 12300005 | Multi-user not supported. |
| 12300006 | Unsupported account type. |
| 12300007 | The number of account reaches the upper limit. |
A
annie_wangli 已提交
1654 1655

**Example**
A
annie_wangli 已提交
1656

Z
zhangalong 已提交
1657
  ```js
A
Annie_wang 已提交
1658 1659
  let accountManager = account_osAccount.getAccountManager();
  let domainInfo = {domain: 'testDomain', accountName: 'testAccountName'};
A
Annie_wang 已提交
1660 1661 1662 1663 1664 1665 1666 1667
  try {
    accountManager.createOsAccountForDomain(account_osAccount.OsAccountType.NORMAL, domainInfo, (err, osAccountInfo)=>{
      console.log('createOsAccountForDomain err:' + JSON.stringify(err));
      console.log('createOsAccountForDomain osAccountInfo:' + JSON.stringify(osAccountInfo));
    });
  } catch (e) {
    console.log('createOsAccountForDomain exception:' + JSON.stringify(e));
  }
A
annie_wangli 已提交
1668 1669
  ```

A
annie_wangli 已提交
1670
### createOsAccountForDomain<sup>8+</sup>
A
annie_wangli 已提交
1671 1672 1673

createOsAccountForDomain(type: OsAccountType, domainInfo: DomainAccountInfo): Promise&lt;OsAccountInfo&gt;

A
Annie_wang 已提交
1674
Creates an OS account and associates it with the specified domain account. This API uses a promise to return the result.
A
annie_wangli 已提交
1675

A
Annie_wang 已提交
1676
**System API**: This is a system API.
A
annie_wangli 已提交
1677 1678 1679 1680 1681 1682

**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

**System capability**: SystemCapability.Account.OsAccount

**Parameters**
A
annie_wangli 已提交
1683

A
Annie_wang 已提交
1684 1685 1686 1687
| Name    | Type                                     | Mandatory| Description                |
| ---------- | ---------------------------------------- | ---- | -------------------- |
| type       | [OsAccountType](#osaccounttype)          | Yes  | Type of the OS account to create.|
| domainInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes  | Domain account information.         |
A
annie_wangli 已提交
1688

A
Annie_wang 已提交
1689
**Return value**
A
annie_wangli 已提交
1690

A
Annie_wang 已提交
1691 1692
| Type                                          | Description                                   |
| ---------------------------------------------- | -------------------------------------- |
A
Annie_wang 已提交
1693
| Promise&lt;[OsAccountInfo](#osaccountinfo)&gt; | Promise used to return the information about the created OS account.|
A
annie_wangli 已提交
1694

A
Annie_wang 已提交
1695 1696 1697 1698 1699 1700 1701 1702 1703 1704
**Error codes**

| ID| Error Message                    |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid type or domainInfo. |
| 12300005 | Multi-user not supported. |
| 12300006 | Unsupported account type. |
| 12300007 | The number of account reaches the upper limit. |

A
annie_wangli 已提交
1705
**Example**
A
annie_wangli 已提交
1706

Z
zhangalong 已提交
1707
  ```js
A
Annie_wang 已提交
1708 1709
  let accountManager = account_osAccount.getAccountManager();
  let domainInfo = {domain: 'testDomain', accountName: 'testAccountName'};
A
Annie_wang 已提交
1710 1711 1712 1713 1714 1715 1716 1717 1718
  try {
    accountManager.createOsAccountForDomain(account_osAccount.OsAccountType.NORMAL, domainInfo).then((accountInfo) => {
      console.log('createOsAccountForDomain, account info: ' + JSON.stringify(accountInfo));
    }).catch((err) => {
      console.log('createOsAccountForDomain err: '  + JSON.stringify(err));
    });
  } catch (e) {
    console.log('createOsAccountForDomain exception:' + JSON.stringify(e));
  }
A
annie_wangli 已提交
1719 1720
  ```

A
Annie_wang 已提交
1721
### getCurrentOsAccount<sup>9+</sup>
A
annie_wangli 已提交
1722

A
Annie_wang 已提交
1723
getCurrentOsAccount(callback: AsyncCallback&lt;OsAccountInfo&gt;): void
A
annie_wangli 已提交
1724

A
Annie_wang 已提交
1725
Obtains information about the OS account to which the current process belongs. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1726

A
annie_wangli 已提交
1727
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS
A
annie_wangli 已提交
1728

A
annie_wangli 已提交
1729
**System capability**: SystemCapability.Account.OsAccount
A
annie_wangli 已提交
1730

A
annie_wangli 已提交
1731 1732 1733 1734
**Parameters**

| Name  | Type                                                | Mandatory| Description                                          |
| -------- | ---------------------------------------------------- | ---- | ---------------------------------------------- |
A
Annie_wang 已提交
1735 1736 1737 1738 1739 1740 1741
| callback | AsyncCallback&lt;[OsAccountInfo](#osaccountinfo)&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the OS account information obtained. Otherwise, **data** is an error object.|

**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
A
annie_wangli 已提交
1742 1743

**Example**
A
annie_wangli 已提交
1744

Z
zhangalong 已提交
1745
  ```js
A
Annie_wang 已提交
1746
  let accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
1747 1748 1749 1750 1751 1752 1753 1754
  try {
    accountManager.getCurrentOsAccount((err, curAccountInfo)=>{
      console.log('getCurrentOsAccount err:' + JSON.stringify(err));
      console.log('getCurrentOsAccount curAccountInfo:' + JSON.stringify(curAccountInfo));
    });
  } catch (e) {
    console.log('getCurrentOsAccount exception:' + JSON.stringify(e));
  }
A
annie_wangli 已提交
1755 1756
  ```

A
Annie_wang 已提交
1757
### getCurrentOsAccount<sup>9+</sup>
A
annie_wangli 已提交
1758

A
Annie_wang 已提交
1759
getCurrentOsAccount(): Promise&lt;OsAccountInfo&gt;
A
annie_wangli 已提交
1760

A
Annie_wang 已提交
1761
Obtains information about the OS account to which the current process belongs. This API uses a promise to return the result.
A
annie_wangli 已提交
1762

A
annie_wangli 已提交
1763 1764 1765 1766
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

**System capability**: SystemCapability.Account.OsAccount

A
Annie_wang 已提交
1767
**Return value**
A
annie_wangli 已提交
1768

A
Annie_wang 已提交
1769 1770 1771 1772 1773 1774 1775 1776 1777
| Type                                          | Description                                      |
| ---------------------------------------------- | ----------------------------------------- |
| Promise&lt;[OsAccountInfo](#osaccountinfo)&gt; | Promise used to return the OS account information obtained.|

**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
A
annie_wangli 已提交
1778

A
annie_wangli 已提交
1779
**Example**
A
annie_wangli 已提交
1780

Z
zhangalong 已提交
1781
  ```js
A
Annie_wang 已提交
1782
  let accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
1783 1784 1785 1786 1787 1788 1789 1790 1791
  try {
    accountManager.getCurrentOsAccount().then((accountInfo) => {
      console.log('getCurrentOsAccount, accountInfo: ' + JSON.stringify(accountInfo));
    }).catch((err) => {
      console.log('getCurrentOsAccount err: '  + JSON.stringify(err));
    });
  } catch (e) {
    console.log('getCurrentOsAccount exception:' + JSON.stringify(e));
  }
A
annie_wangli 已提交
1792 1793 1794 1795 1796 1797
  ```

### queryOsAccountById

queryOsAccountById(localId: number, callback: AsyncCallback&lt;OsAccountInfo&gt;): void

A
Annie_wang 已提交
1798
Obtains information about the OS account of the given ID. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1799

A
Annie_wang 已提交
1800
**System API**: This is a system API.
A
annie_wangli 已提交
1801

Z
zhangalong 已提交
1802
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION
A
annie_wangli 已提交
1803

A
annie_wangli 已提交
1804 1805 1806 1807
**System capability**: SystemCapability.Account.OsAccount

**Parameters**

A
Annie_wang 已提交
1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819
| Name  | Type                                                | Mandatory| Description                                                                      |
| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------------------ |
| localId  | number                                               | Yes  | ID of the target OS account.                                                     |
| callback | AsyncCallback&lt;[OsAccountInfo](#osaccountinfo)&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the OS account information obtained. Otherwise, **data** is an error object.|

**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid localId.    |
| 12300003 | Account not found. |
A
annie_wangli 已提交
1820 1821

**Example**: Query information about OS account 100.
A
annie_wangli 已提交
1822

Z
zhangalong 已提交
1823
  ```js
A
Annie_wang 已提交
1824 1825
  let accountManager = account_osAccount.getAccountManager();
  let localId = 100;
A
Annie_wang 已提交
1826 1827 1828 1829 1830 1831 1832 1833
  try {
    accountManager.queryOsAccountById(localId, (err, accountInfo)=>{
      console.log('queryOsAccountById err:' + JSON.stringify(err));
      console.log('queryOsAccountById accountInfo:' + JSON.stringify(accountInfo));
    });
  } catch (e) {
    console.log('queryOsAccountById exception:' + JSON.stringify(e));
  }
A
annie_wangli 已提交
1834 1835 1836 1837 1838 1839
  ```

### queryOsAccountById

queryOsAccountById(localId: number): Promise&lt;OsAccountInfo&gt;

A
Annie_wang 已提交
1840
Obtains information about the OS account of the given ID. This API uses a promise to return the result.
A
annie_wangli 已提交
1841

A
Annie_wang 已提交
1842
**System API**: This is a system API.
A
annie_wangli 已提交
1843

Z
zhangalong 已提交
1844
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION
A
annie_wangli 已提交
1845

A
annie_wangli 已提交
1846
**System capability**: SystemCapability.Account.OsAccount
A
annie_wangli 已提交
1847

A
annie_wangli 已提交
1848
**Parameters**
A
annie_wangli 已提交
1849

A
annie_wangli 已提交
1850 1851 1852
| Name | Type  | Mandatory| Description                |
| ------- | ------ | ---- | -------------------- |
| localId | number | Yes  | ID of the target OS account.|
A
annie_wangli 已提交
1853

A
Annie_wang 已提交
1854
**Return value**
A
annie_wangli 已提交
1855

A
Annie_wang 已提交
1856 1857
| Type                                          | Description                                |
| ---------------------------------------------- | ------------------------------------ |
A
annie_wangli 已提交
1858 1859
| Promise&lt;[OsAccountInfo](#osaccountinfo)&gt; | Promise used to return the OS account information obtained.|

A
Annie_wang 已提交
1860 1861 1862 1863 1864 1865 1866 1867
**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid localId.    |
| 12300003 | Account not found. |

A
annie_wangli 已提交
1868
**Example**: Query information about OS account 100.
A
annie_wangli 已提交
1869

Z
zhangalong 已提交
1870
  ```js
A
Annie_wang 已提交
1871 1872
  let accountManager = account_osAccount.getAccountManager();
  let localId = 100;
A
Annie_wang 已提交
1873 1874 1875 1876 1877 1878 1879 1880 1881
  try {
    accountManager.queryOsAccountById(localId).then((accountInfo) => {
      console.log('queryOsAccountById, accountInfo: ' + JSON.stringify(accountInfo));
    }).catch((err) => {
      console.log('queryOsAccountById err: '  + JSON.stringify(err));
    });
  } catch (e) {
    console.log('queryOsAccountById exception:' + JSON.stringify(e));
  }
A
annie_wangli 已提交
1882 1883
  ```

A
Annie_wang 已提交
1884
### getOsAccountType<sup>9+</sup>
A
annie_wangli 已提交
1885

A
Annie_wang 已提交
1886
getOsAccountType(callback: AsyncCallback&lt;OsAccountType&gt;): void
A
annie_wangli 已提交
1887

A
Annie_wang 已提交
1888
Obtains the type of the account to which the current process belongs. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1889

A
annie_wangli 已提交
1890 1891 1892
**System capability**: SystemCapability.Account.OsAccount

**Parameters**
A
annie_wangli 已提交
1893

A
annie_wangli 已提交
1894 1895
| Name  | Type                                                | Mandatory| Description                                                |
| -------- | ---------------------------------------------------- | ---- | ---------------------------------------------------- |
A
Annie_wang 已提交
1896 1897 1898 1899 1900 1901 1902
| callback | AsyncCallback&lt;[OsAccountType](#osaccounttype)&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the OS account type obtained. Otherwise, **err** is an error object.|

**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
A
annie_wangli 已提交
1903

A
annie_wangli 已提交
1904
**Example**
A
annie_wangli 已提交
1905

Z
zhangalong 已提交
1906
  ```js
A
Annie_wang 已提交
1907
  let accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
1908 1909 1910 1911 1912 1913 1914 1915
  try {
    accountManager.getOsAccountType((err, accountType) => {
      console.log('getOsAccountType err: ' + JSON.stringify(err));
      console.log('getOsAccountType accountType: ' + accountType);
    });
  } catch (e) {
    console.log('getOsAccountType exception: ' + JSON.stringify(e));
  }
A
annie_wangli 已提交
1916 1917
  ```

A
Annie_wang 已提交
1918
### getOsAccountType<sup>9+</sup>
A
annie_wangli 已提交
1919

A
Annie_wang 已提交
1920
getOsAccountType(): Promise&lt;OsAccountType&gt;
A
annie_wangli 已提交
1921

A
Annie_wang 已提交
1922
Obtains the type of the account to which the current process belongs. This API uses a promise to return the result.
A
annie_wangli 已提交
1923

A
annie_wangli 已提交
1924
**System capability**: SystemCapability.Account.OsAccount
A
annie_wangli 已提交
1925

A
Annie_wang 已提交
1926
**Return value**
A
annie_wangli 已提交
1927

A
Annie_wang 已提交
1928 1929 1930 1931 1932 1933 1934 1935 1936
| Type                                          | Description                                            |
| ---------------------------------------------- | ----------------------------------------------- |
| Promise&lt;[OsAccountType](#osaccounttype)&gt; | Promise used to return the OS account type obtained.|

**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
A
annie_wangli 已提交
1937 1938

**Example**
A
annie_wangli 已提交
1939

Z
zhangalong 已提交
1940
  ```js
A
Annie_wang 已提交
1941
  let accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
1942 1943 1944 1945 1946 1947 1948 1949 1950
  try {
    accountManager.getOsAccountType().then((accountType) => {
      console.log('getOsAccountType, accountType: ' + accountType);
    }).catch((err) => {
      console.log('getOsAccountType err: '  + JSON.stringify(err));
    });
  } catch (e) {
    console.log('getOsAccountType exception: ' + JSON.stringify(e));
  }
A
annie_wangli 已提交
1951 1952
  ```

A
Annie_wang 已提交
1953
### queryDistributedVirtualDeviceId<sup>9+</sup>
A
annie_wangli 已提交
1954

A
Annie_wang 已提交
1955
queryDistributedVirtualDeviceId(callback: AsyncCallback&lt;string&gt;): void
A
annie_wangli 已提交
1956

A
Annie_wang 已提交
1957
Obtains the ID of this distributed virtual device. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1958

Z
zhangalong 已提交
1959
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC or ohos.permission.MANAGE_LOCAL_ACCOUNTS
A
annie_wangli 已提交
1960 1961

**System capability**: SystemCapability.Account.OsAccount
A
annie_wangli 已提交
1962

A
annie_wangli 已提交
1963
**Parameters**
A
annie_wangli 已提交
1964

A
Annie_wang 已提交
1965 1966 1967 1968 1969 1970 1971 1972 1973
| Name  | Type                       | Mandatory| Description                                                                  |
| -------- | --------------------------- | ---- | --------------------------------------------------------------------- |
| callback | AsyncCallback&lt;string&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the distributed virtual device ID obtained. Otherwise, **data** is an error object.|

**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
A
annie_wangli 已提交
1974 1975

**Example**
A
annie_wangli 已提交
1976

Z
zhangalong 已提交
1977
  ```js
A
Annie_wang 已提交
1978
  let accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
1979 1980 1981 1982 1983 1984 1985 1986
  try {
    accountManager.queryDistributedVirtualDeviceId((err, virtualID) => {
      console.log('queryDistributedVirtualDeviceId err: ' + JSON.stringify(err));
      console.log('queryDistributedVirtualDeviceId virtualID: ' + virtualID);
    });
  } catch (e) {
    console.log('queryDistributedVirtualDeviceId exception: ' + JSON.stringify(e));
  }
A
annie_wangli 已提交
1987 1988
  ```

A
Annie_wang 已提交
1989
### queryDistributedVirtualDeviceId<sup>9+</sup>
A
annie_wangli 已提交
1990

A
Annie_wang 已提交
1991
queryDistributedVirtualDeviceId(): Promise&lt;string&gt;
A
annie_wangli 已提交
1992

A
Annie_wang 已提交
1993
Obtains the ID of this distributed virtual device. This API uses a promise to return the result.
A
annie_wangli 已提交
1994

Z
zhangalong 已提交
1995
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC or ohos.permission.MANAGE_LOCAL_ACCOUNTS
A
annie_wangli 已提交
1996 1997

**System capability**: SystemCapability.Account.OsAccount
A
annie_wangli 已提交
1998

A
Annie_wang 已提交
1999
**Return value**
A
annie_wangli 已提交
2000

A
Annie_wang 已提交
2001 2002 2003 2004 2005 2006 2007 2008 2009
| Type                 | Description                             |
| --------------------- | --------------------------------- |
| Promise&lt;string&gt; | Promise used to return the distributed virtual device ID obtained.|

**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
A
annie_wangli 已提交
2010 2011

**Example**
A
annie_wangli 已提交
2012

Z
zhangalong 已提交
2013
  ```js
A
Annie_wang 已提交
2014
  let accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
2015 2016 2017 2018 2019 2020 2021 2022 2023
  try {
    accountManager.queryDistributedVirtualDeviceId().then((virtualID) => {
      console.log('queryDistributedVirtualDeviceId, virtualID: ' + virtualID);
    }).catch((err) => {
      console.log('queryDistributedVirtualDeviceId err: '  + JSON.stringify(err));
    });
  } catch (e) {
    console.log('queryDistributedVirtualDeviceId exception: ' + JSON.stringify(e));
  }
A
annie_wangli 已提交
2024 2025 2026 2027 2028 2029
  ```

### getOsAccountProfilePhoto

getOsAccountProfilePhoto(localId: number, callback: AsyncCallback&lt;string&gt;): void

A
Annie_wang 已提交
2030
Obtains the profile photo of an OS account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
2031

A
Annie_wang 已提交
2032
**System API**: This is a system API.
A
annie_wangli 已提交
2033 2034 2035 2036 2037 2038

**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

**System capability**: SystemCapability.Account.OsAccount

**Parameters**
A
annie_wangli 已提交
2039

A
Annie_wang 已提交
2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051
| Name  | Type                       | Mandatory| Description                                                                        |
| -------- | --------------------------- | ---- | -------------------------------------------------------------------------- |
| localId  | number                      | Yes  | ID of the target OS account.                                                               |
| callback | AsyncCallback&lt;string&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the profile photo information obtained. Otherwise, **err** is an error object.|

**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid localId.    |
| 12300003 | Account not found. |
A
annie_wangli 已提交
2052

A
annie_wangli 已提交
2053
**Example**: Obtain the profile photo of OS account 100.
A
annie_wangli 已提交
2054

Z
zhangalong 已提交
2055
  ```js
A
Annie_wang 已提交
2056 2057
  let accountManager = account_osAccount.getAccountManager();
  let localId = 100;
A
Annie_wang 已提交
2058 2059 2060 2061 2062 2063 2064 2065
  try {
    accountManager.getOsAccountProfilePhoto(localId, (err, photo)=>{
      console.log('getOsAccountProfilePhoto err:' + JSON.stringify(err));
      console.log('get photo:' + photo + ' by localId: ' + localId);
    });
  } catch (e) {
    console.log('getOsAccountProfilePhoto exception:' + JSON.stringify(e));
  }
A
annie_wangli 已提交
2066 2067 2068 2069 2070 2071
  ```

### getOsAccountProfilePhoto

getOsAccountProfilePhoto(localId: number): Promise&lt;string&gt;

A
Annie_wang 已提交
2072
Obtains the profile photo of an OS account. This API uses a promise to return the result.
A
annie_wangli 已提交
2073

A
Annie_wang 已提交
2074
**System API**: This is a system API.
A
annie_wangli 已提交
2075

A
annie_wangli 已提交
2076
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS
A
annie_wangli 已提交
2077

A
annie_wangli 已提交
2078
**System capability**: SystemCapability.Account.OsAccount
A
annie_wangli 已提交
2079

A
annie_wangli 已提交
2080
**Parameters**
A
annie_wangli 已提交
2081

A
annie_wangli 已提交
2082 2083 2084 2085
| Name | Type  | Mandatory| Description        |
| ------- | ------ | ---- | ------------ |
| localId | number | Yes  | ID of the target OS account.|

A
Annie_wang 已提交
2086
**Return value**
A
annie_wangli 已提交
2087

A
Annie_wang 已提交
2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098
| Type                 | Description                                   |
| --------------------- | -------------------------------------- |
| Promise&lt;string&gt; | Promise used to return the profile photo information obtained.|

**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid localId.    |
| 12300003 | Account not found. |
A
annie_wangli 已提交
2099 2100

**Example**: Obtain the profile photo of OS account 100.
A
annie_wangli 已提交
2101

Z
zhangalong 已提交
2102
  ```js
A
Annie_wang 已提交
2103 2104
  let accountManager = account_osAccount.getAccountManager();
  let localId = 100;
A
Annie_wang 已提交
2105 2106 2107 2108 2109 2110 2111 2112 2113
  try {
    accountManager.getOsAccountProfilePhoto(localId).then((photo) => {
      console.log('getOsAccountProfilePhoto: ' + photo);
    }).catch((err) => {
      console.log('getOsAccountProfilePhoto err: '  + JSON.stringify(err));
    });
  } catch (e) {
    console.log('getOsAccountProfilePhoto exception:' + JSON.stringify(e));
  }
A
annie_wangli 已提交
2114 2115 2116 2117 2118 2119
  ```

### setOsAccountProfilePhoto

setOsAccountProfilePhoto(localId: number, photo: string, callback: AsyncCallback&lt;void&gt;): void

A
Annie_wang 已提交
2120
Sets a profile photo for an OS account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
2121

A
Annie_wang 已提交
2122
**System API**: This is a system API.
A
annie_wangli 已提交
2123 2124

**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS
A
annie_wangli 已提交
2125

A
annie_wangli 已提交
2126
**System capability**: SystemCapability.Account.OsAccount
A
annie_wangli 已提交
2127

A
annie_wangli 已提交
2128 2129 2130 2131 2132 2133
**Parameters**

| Name  | Type                     | Mandatory| Description        |
| -------- | ------------------------- | ---- | ------------ |
| localId  | number                    | Yes  | ID of the target OS account.|
| photo    | string                    | Yes  | Profile photo information.  |
A
Annie_wang 已提交
2134
| callback | AsyncCallback&lt;void&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. |
A
Annie_wang 已提交
2135 2136 2137 2138 2139 2140 2141 2142 2143

**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid localId or photo.    |
| 12300003 | Account not found. |
| 12300008 | Restricted Account. |
A
annie_wangli 已提交
2144 2145

**Example**: Set a profile photo for OS account 100.
A
annie_wangli 已提交
2146

Z
zhangalong 已提交
2147
  ```js
A
Annie_wang 已提交
2148 2149 2150 2151 2152 2153
  let accountManager = account_osAccount.getAccountManager();
  let localId = 100;
  let photo = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAAPCAYAAAA/I0V3AAAAAXNSR0IArs4c6QAAAARnQU1BAA'+
  'Cxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACwSURBVDhPvZLBDYMwDEV/ugsXRjAT0EHCOuFIBwkbdIRewi6unbiAyoGgSn1SFH85+Y'+
  'q/4ljARW62X+LHS8uIzjm4dXUYF+utzBikB52Jo5e5iEPKqpACk7R9NM2RvWm5tIkD2czLCUFNKLD6IjdMHFHDzws285MgGrT0xCtp3WOKHo'+
  '+7q0mP0DZW9pNmoEFUzrQjp5cCnaen2kSJXLFD8ghbXyZCMQf/8e8Ns1XVAG/XAgqKzVnJFAAAAABJRU5ErkJggg=='
A
Annie_wang 已提交
2154 2155 2156 2157 2158 2159 2160
  try {
    accountManager.setOsAccountProfilePhoto(localId, photo, (err)=>{
      console.log('setOsAccountProfilePhoto err:' + JSON.stringify(err));
    });
  } catch (e) {
    console.log('setOsAccountProfilePhoto exception:' + JSON.stringify(e));
  }
A
annie_wangli 已提交
2161 2162 2163 2164 2165 2166
  ```

### setOsAccountProfilePhoto

setOsAccountProfilePhoto(localId: number, photo: string): Promise&lt;void&gt;

A
Annie_wang 已提交
2167
Sets a profile photo for an OS account. This API uses a promise to return the result.
A
annie_wangli 已提交
2168

A
Annie_wang 已提交
2169
**System API**: This is a system API.
A
annie_wangli 已提交
2170 2171

**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS
A
annie_wangli 已提交
2172

A
annie_wangli 已提交
2173
**System capability**: SystemCapability.Account.OsAccount
A
annie_wangli 已提交
2174

A
annie_wangli 已提交
2175
**Parameters**
A
annie_wangli 已提交
2176

A
annie_wangli 已提交
2177 2178 2179 2180
| Name | Type  | Mandatory| Description        |
| ------- | ------ | ---- | ------------ |
| localId | number | Yes  | ID of the target OS account.|
| photo   | string | Yes  | Profile photo information.  |
A
annie_wangli 已提交
2181

A
Annie_wang 已提交
2182
**Return value**
A
annie_wangli 已提交
2183

A
Annie_wang 已提交
2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195
| Type               | Description                                |
| ------------------- | ------------------------------------ |
| Promise&lt;void&gt; | Promise that returns no value.|

**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid localId or photo.    |
| 12300003 | Account not found. |
| 12300008 | Restricted Account. |
A
annie_wangli 已提交
2196 2197

**Example**: Set a profile photo for OS account 100.
A
annie_wangli 已提交
2198

Z
zhangalong 已提交
2199
  ```js
A
Annie_wang 已提交
2200 2201 2202 2203 2204 2205
  let accountManager = account_osAccount.getAccountManager();
  let localId = 100;
  let photo = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAAPCAYAAAA/I0V3AAAAAXNSR0IArs4c6QAAAARnQU1BAA'+
  'Cxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACwSURBVDhPvZLBDYMwDEV/ugsXRjAT0EHCOuFIBwkbdIRewi6unbiAyoGgSn1SFH85+Y'+
  'q/4ljARW62X+LHS8uIzjm4dXUYF+utzBikB52Jo5e5iEPKqpACk7R9NM2RvWm5tIkD2czLCUFNKLD6IjdMHFHDzws285MgGrT0xCtp3WOKHo'+
  '+7q0mP0DZW9pNmoEFUzrQjp5cCnaen2kSJXLFD8ghbXyZCMQf/8e8Ns1XVAG/XAgqKzVnJFAAAAABJRU5ErkJggg=='
A
Annie_wang 已提交
2206 2207 2208 2209 2210 2211 2212 2213 2214
  try {
    accountManager.setOsAccountProfilePhoto(localId, photo).then(() => {
      console.log('setOsAccountProfilePhoto success');
    }).catch((err) => {
      console.log('setOsAccountProfilePhoto err: '  + JSON.stringify(err));
    });
  } catch (e) {
    console.log('setOsAccountProfilePhoto exception:' + JSON.stringify(e));
  }
A
annie_wangli 已提交
2215 2216
  ```

A
Annie_wang 已提交
2217
### getOsAccountLocalIdForSerialNumber<sup>9+</sup>
A
annie_wangli 已提交
2218

A
Annie_wang 已提交
2219
getOsAccountLocalIdForSerialNumber(serialNumber: number, callback: AsyncCallback&lt;number&gt;): void
A
annie_wangli 已提交
2220

A
Annie_wang 已提交
2221
Obtains the OS account ID based on the serial number (SN). This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
2222

A
annie_wangli 已提交
2223
**System capability**: SystemCapability.Account.OsAccount
A
annie_wangli 已提交
2224

A
annie_wangli 已提交
2225
**Parameters**
A
annie_wangli 已提交
2226

A
Annie_wang 已提交
2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238
| Name      | Type                       | Mandatory| Description                                                                          |
| ------------ | --------------------------- | ---- | ---------------------------------------------------------------------------- |
| serialNumber | number                      | Yes  | Account SN.                                                                   |
| callback     | AsyncCallback&lt;number&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the OS account ID obtained. Otherwise, **err** is an error object.|

**Error codes**

| ID| Error Message              |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid serialNumber. |
| 12300003 | Account not found. |
A
annie_wangli 已提交
2239

A
Annie_wang 已提交
2240
**Example**: Obtain the ID of the OS account whose SN is 12345.
A
annie_wangli 已提交
2241

Z
zhangalong 已提交
2242
  ```js
A
Annie_wang 已提交
2243 2244
  let accountManager = account_osAccount.getAccountManager();
  let serialNumber = 12345;
A
Annie_wang 已提交
2245
  try {
A
Annie_wang 已提交
2246
    accountManager.getOsAccountLocalIdForSerialNumber(serialNumber, (err, localId)=>{
A
Annie_wang 已提交
2247 2248 2249 2250 2251 2252
      console.log('ger localId err:' + JSON.stringify(err));
      console.log('get localId:' + localId + ' by serialNumber: ' + serialNumber);
    });
  } catch (e) {
    console.log('ger localId exception:' + JSON.stringify(e));
  }
A
annie_wangli 已提交
2253 2254
  ```

A
Annie_wang 已提交
2255
### getOsAccountLocalIdForSerialNumber<sup>9+</sup>
A
annie_wangli 已提交
2256

A
Annie_wang 已提交
2257
getOsAccountLocalIdForSerialNumber(serialNumber: number): Promise&lt;number&gt;
A
annie_wangli 已提交
2258

A
Annie_wang 已提交
2259
Obtains the OS account ID based on the SN. This API uses a promise to return the result.
A
annie_wangli 已提交
2260

A
annie_wangli 已提交
2261 2262 2263
**System capability**: SystemCapability.Account.OsAccount

**Parameters**
A
annie_wangli 已提交
2264

A
annie_wangli 已提交
2265 2266 2267
| Name      | Type  | Mandatory| Description      |
| ------------ | ------ | ---- | ---------- |
| serialNumber | number | Yes  | Account SN.|
A
annie_wangli 已提交
2268

A
Annie_wang 已提交
2269
**Return value**
A
annie_wangli 已提交
2270

A
Annie_wang 已提交
2271 2272
| Type                 | Description                                        |
| --------------------- | -------------------------------------------- |
A
annie_wangli 已提交
2273
| Promise&lt;number&gt; | Promise used to return the OS account ID obtained.|
A
annie_wangli 已提交
2274

A
Annie_wang 已提交
2275 2276 2277 2278 2279 2280 2281 2282
**Error codes**

| ID| Error Message              |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid serialNumber. |
| 12300003 | Account not found. |

A
Annie_wang 已提交
2283
**Example**: Obtain the ID of the OS account whose SN is 12345.
A
annie_wangli 已提交
2284

Z
zhangalong 已提交
2285
  ```js
A
Annie_wang 已提交
2286 2287
  let accountManager = account_osAccount.getAccountManager();
  let serialNumber = 12345;
A
Annie_wang 已提交
2288
  try {
A
Annie_wang 已提交
2289 2290
    accountManager.getOsAccountLocalIdForSerialNumber(serialNumber).then((localId) => {
      console.log('getOsAccountLocalIdForSerialNumber localId: ' + localId);
A
Annie_wang 已提交
2291
    }).catch((err) => {
A
Annie_wang 已提交
2292
      console.log('getOsAccountLocalIdForSerialNumber err: '  + JSON.stringify(err));
A
Annie_wang 已提交
2293 2294
    });
  } catch (e) {
A
Annie_wang 已提交
2295
    console.log('getOsAccountLocalIdForSerialNumber exception: '  + JSON.stringify(e));
A
Annie_wang 已提交
2296
  }
A
annie_wangli 已提交
2297 2298
  ```

A
Annie_wang 已提交
2299
### getSerialNumberForOsAccountLocalId<sup>9+</sup>
A
annie_wangli 已提交
2300

A
Annie_wang 已提交
2301
getSerialNumberForOsAccountLocalId(localId: number, callback: AsyncCallback&lt;number&gt;): void
A
annie_wangli 已提交
2302

A
Annie_wang 已提交
2303
Obtains the SN of an OS account based on the account ID. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
2304

A
annie_wangli 已提交
2305
**System capability**: SystemCapability.Account.OsAccount
A
annie_wangli 已提交
2306

A
annie_wangli 已提交
2307
**Parameters**
A
annie_wangli 已提交
2308

A
Annie_wang 已提交
2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320
| Name  | Type                       | Mandatory| Description                                                                        |
| -------- | --------------------------- | ---- | -------------------------------------------------------------------------- |
| localId  | number                      | Yes  | ID of the target OS account.                                                                |
| callback | AsyncCallback&lt;number&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the SN obtained. Otherwise, **err** is an error object.|

**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid localId.    |
| 12300003 | Account not found. |
A
annie_wangli 已提交
2321

A
Annie_wang 已提交
2322
**Example**: Obtain the SN of the OS account 100.
A
annie_wangli 已提交
2323

Z
zhangalong 已提交
2324
  ```js
A
Annie_wang 已提交
2325 2326
  let accountManager = account_osAccount.getAccountManager();
  let localId = 100;
A
Annie_wang 已提交
2327
  try {
A
Annie_wang 已提交
2328
    accountManager.getSerialNumberForOsAccountLocalId(localId, (err, serialNumber)=>{
A
Annie_wang 已提交
2329 2330 2331 2332 2333 2334
      console.log('ger serialNumber err:' + JSON.stringify(err));
      console.log('get serialNumber:' + serialNumber + ' by localId: ' + localId);
    });
  } catch (e) {
    console.log('ger serialNumber exception:' + JSON.stringify(e));
  }
A
annie_wangli 已提交
2335 2336
  ```

A
Annie_wang 已提交
2337
### getSerialNumberForOsAccountLocalId<sup>9+</sup>
A
annie_wangli 已提交
2338

A
Annie_wang 已提交
2339
getSerialNumberForOsAccountLocalId(localId: number): Promise&lt;number&gt;
A
annie_wangli 已提交
2340

A
Annie_wang 已提交
2341
Obtains the SN of an OS account based on the account ID. This API uses a promise to return the result.
A
annie_wangli 已提交
2342

A
annie_wangli 已提交
2343 2344 2345
**System capability**: SystemCapability.Account.OsAccount

**Parameters**
A
annie_wangli 已提交
2346

A
Annie_wang 已提交
2347 2348
| Name | Type  | Mandatory| Description         |
| ------- | ------ | ---- | ----------- |
A
annie_wangli 已提交
2349
| localId | number | Yes  | ID of the target OS account.|
A
annie_wangli 已提交
2350

A
Annie_wang 已提交
2351
**Return value**
A
annie_wangli 已提交
2352

A
Annie_wang 已提交
2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363
| Type                 | Description                                   |
| :-------------------- | :------------------------------------- |
| Promise&lt;number&gt; | Promise used to return the SN obtained.|

**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid localId.    |
| 12300003 | Account not found. |
A
annie_wangli 已提交
2364

A
Annie_wang 已提交
2365
**Example**: Obtain the SN of the OS account 100.
A
annie_wangli 已提交
2366

Z
zhangalong 已提交
2367
  ```js
A
Annie_wang 已提交
2368 2369
  let accountManager = account_osAccount.getAccountManager();
  let localId = 100;
A
Annie_wang 已提交
2370
  try {
A
Annie_wang 已提交
2371 2372
    accountManager.getSerialNumberForOsAccountLocalId(localId).then((serialNumber) => {
      console.log('getSerialNumberForOsAccountLocalId serialNumber: ' + serialNumber);
A
Annie_wang 已提交
2373
    }).catch((err) => {
A
Annie_wang 已提交
2374
      console.log('getSerialNumberForOsAccountLocalId err: '  + JSON.stringify(err));
A
Annie_wang 已提交
2375 2376
    });
  } catch (e) {
A
Annie_wang 已提交
2377
    console.log('getSerialNumberForOsAccountLocalId exception:' + JSON.stringify(e));
A
Annie_wang 已提交
2378 2379 2380 2381 2382 2383 2384
  }
  ```

### on

on(type: 'activate' | 'activating', name: string, callback: Callback&lt;number&gt;): void

A
Annie_wang 已提交
2385
Subscribes to the OS account activation states, including the states of the account being activated and the account with activation completed. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396

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

**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION

**System capability**: SystemCapability.Account.OsAccount

**Parameters**

| Name  | Type                      | Mandatory| Description                                                        |
| -------- | -------------------------- | ---- | ------------------------------------------------------------ |
A
Annie_wang 已提交
2397
| type     | 'activate' \| 'activating' | Yes  | Type of the event to subscribe to. The value **activate** indicates an event reported when the OS account activation is complete, and **activating** indicates an event reported when OS account is being activated.|
A
Annie_wang 已提交
2398
| name     | string                     | Yes  | Subscription name, which can be customized. The value cannot be empty or exceed 1024 bytes.          |
A
Annie_wang 已提交
2399
| callback | Callback&lt;number&gt;     | Yes  | Callback invoked to return the ID of the OS account being activated or activated.   |
A
Annie_wang 已提交
2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426

**Error codes**

| ID| Error Message      |
| -------- | ------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid type or name. |
| 12300011 | Callback has been registered. |

**Example**

  ```js
  let accountManager = account_osAccount.getAccountManager();
  function onCallback(receiveLocalId){
    console.log('receive localId:' + receiveLocalId);
  }
  try {
    accountManager.on('activating', 'osAccountOnOffNameA', onCallback);
  } catch (e) {
    console.log('receive localId exception:' + JSON.stringify(e));
  }
  ```

### off

off(type: 'activate' | 'activating', name: string, callback?: Callback&lt;number&gt;): void

A
Annie_wang 已提交
2427
Unsubscribes from the OS account activation states, including the states of the account being activated and the account with activation completed. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440

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

**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION

**System capability**: SystemCapability.Account.OsAccount

**Parameters**

| Name  | Type                      | Mandatory| Description                                                        |
| -------- | -------------------------- | ---- | ------------------------------------------------------------ |
| type     | 'activate' \| 'activating' | Yes  | Type of the event to unsubscribe from. The value **activate** means an event indicating that an OS account is activated, and **activating** means an event indicating that an OS account is being activated.|
| name     | string                     | Yes  | Subscription name, which can be customized. The value cannot be empty or exceed 1024 bytes, and must be the same as the value passed by **on()**.|
A
Annie_wang 已提交
2441
| callback | Callback&lt;number&gt;     | No  | Callback to unregister. By default, **0** is returned.                     |
A
Annie_wang 已提交
2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464

**Error codes**

| ID| Error Message      |
| -------- | ------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid type or name. |
| 12300012 | Callback has not been registered. |

**Example**

  ```js
  let accountManager = account_osAccount.getAccountManager();
  function offCallback(){
    console.log('off enter')
  }
  try {
    accountManager.off('activating', 'osAccountOnOffNameA', offCallback);
  } catch (e) {
    console.log('off exception:' + JSON.stringify(e));
  }
  ```

A
Annie_wang 已提交
2465
### getBundleIdForUid<sup>9+</sup>
A
Annie_wang 已提交
2466

A
Annie_wang 已提交
2467
getBundleIdForUid(uid: number, callback: AsyncCallback&lt;number&gt;): void;
A
Annie_wang 已提交
2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494

Obtains the bundle ID based on the UID. This API uses an asynchronous callback to return the result.

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

**System capability**: SystemCapability.Account.OsAccount

**Parameters**

| Name  | Type                      | Mandatory| Description                                                                       |
| -------- | --------------------------- | ---- | ------------------------------------------------------------------------ |
| uid      | number                      | Yes  | Process UID.                                                                |
| callback | AsyncCallback&lt;number&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the bundle ID obtained. Otherwise, **data** is an error object.|

**Error codes**

| ID| Error Message      |
| -------- | ------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid uid. |

**Example**

  ```js
  let accountManager = account_osAccount.getAccountManager();
  let testUid = 1000000;
  try {
A
Annie_wang 已提交
2495 2496 2497
    accountManager.getBundleIdForUid(testUid, (err, bundleId) => {
      console.info('getBundleIdForUid errInfo:' + JSON.stringify(err));
      console.info('getBundleIdForUid bundleId:' + JSON.stringify(bundleId));
A
Annie_wang 已提交
2498 2499
    });
  } catch (e) {
A
Annie_wang 已提交
2500
    console.info('getBundleIdForUid exception:' + JSON.stringify(e));
A
Annie_wang 已提交
2501 2502
  }
  ```
A
Annie_wang 已提交
2503
### getBundleIdForUid<sup>9+</sup>
A
Annie_wang 已提交
2504

A
Annie_wang 已提交
2505
getBundleIdForUid(uid: number): Promise&lt;number&gt;;
A
Annie_wang 已提交
2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537

Obtains the bundle ID based on the UID. This API uses a promise to return the result.

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

**System capability**: SystemCapability.Account.OsAccount

**Parameters**

| Name | Type  | Mandatory| Description        |
| ------- | ------ | ---- | ------------ |
| uid     | number | Yes  |  Process UID.|

**Return value**

| Type                 | Description                                 |
| --------------------- | ------------------------------------ |
| Promise&lt;number&gt; | Promise used to return the bundle ID obtained.|

**Error codes**

| ID| Error Message      |
| -------- | ------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid uid. |

**Example**

  ```js
  let accountManager = account_osAccount.getAccountManager();
  let testUid = 1000000;
  try {
A
Annie_wang 已提交
2538 2539
    accountManager.getBundleIdForUid(testUid).then((result) => {
      console.info('getBundleIdForUid bundleId:' + JSON.stringify(result));
A
Annie_wang 已提交
2540
    }).catch((err)=>{
A
Annie_wang 已提交
2541
      console.info('getBundleIdForUid errInfo:' + JSON.stringify(err));
A
Annie_wang 已提交
2542 2543
    });
  } catch (e) {
A
Annie_wang 已提交
2544
    console.info('getBundleIdForUid exception:' + JSON.stringify(e));
A
Annie_wang 已提交
2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622
  }
  ```

### isMainOsAccount<sup>9+</sup>

isMainOsAccount(callback: AsyncCallback&lt;boolean&gt;): void;

Checks whether the current process belongs to the main OS account. This API uses an asynchronous callback to return the result.

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

**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

**System capability**: SystemCapability.Account.OsAccount

**Parameters**

| Name  | Type                         | Mandatory| Description                                                              |
| -------- | ---------------------------- | ---- | ----------------------------------------------------------------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes  | Callback invoked to return the result. If **true** is returned, the current process belongs to the main OS account. If **false** is returned, the current process does not belong to the main OS account.|

**Error codes**

| ID| Error Message      |
| -------- | ------------- |
| 12300001 | System service exception. |

**Example**

  ```js
  let accountManager = account_osAccount.getAccountManager();
  try {
    accountManager.isMainOsAccount((err,result)=>{
      console.info('isMainOsAccount errInfo:' + JSON.stringify(err));
      console.info('isMainOsAccount result:' + JSON.stringify(result));
    });
  } catch (e) {
    console.info('isMainOsAccount exception:' + JSON.stringify(e));
  }
  ```
### isMainOsAccount<sup>9+</sup>

isMainOsAccount(): Promise&lt;boolean&gt;;

Checks whether the current process belongs to the main OS account. This API uses a promise to return the result.

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

**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

**System capability**: SystemCapability.Account.OsAccount

**Return value**

| Type                  | Description                                                                 |
| ---------------------- | --------------------------------------------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the result. If **true** is returned, the current process belongs to the main OS account. If **false** is returned, the current process does not belong to the main OS account.|

**Error codes**

| ID| Error Message      |
| -------- | ------------- |
| 12300001 | System service exception. |

**Example**

  ```js
  let accountManager = account_osAccount.getAccountManager();
  try {
    accountManager.isMainOsAccount().then((result) => {
      console.info('isMainOsAccount result:' + JSON.stringify(result));
    }).catch((err)=>{
      console.info('isMainOsAccount errInfo:' + JSON.stringify(err));
    });
  } catch (e) {
    console.info('isMainOsAccount exception:' + JSON.stringify(e));
  }
  ```
A
Annie_wang 已提交
2623
### getOsAccountConstraintSourceTypes<sup>9+</sup>
A
Annie_wang 已提交
2624

A
Annie_wang 已提交
2625
getOsAccountConstraintSourceTypes(localId: number, constraint: string, callback: AsyncCallback&lt;Array&lt;ConstraintSourceTypeInfo&gt;&gt;): void;
A
Annie_wang 已提交
2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655

Obtains the constraint source information of an OS account. This API uses an asynchronous callback to return the result.

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

**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

**System capability**: SystemCapability.Account.OsAccount

**Parameters**

| Name  | Type                      | Mandatory| Description                                                        |
| -------- | -------------------------- | ---- | ------------------------------------------------------------ |
| localId     | number | Yes  |  ID of the target OS account.|
| constraint     | string | Yes  |  Name of the [constraint](#constraints) to query.|
| callback | AsyncCallback&lt;Array&lt;[ConstraintSourceTypeInfo](#constraintsourcetypeinfo)&gt;&gt;     | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the [constraint](#constraints) source information obtained. Otherwise, **err** is an error object.                     |

**Error codes**

| ID| Error Message      |
| -------- | ------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid localId or constraint. |
| 12300003 | Account not found. |

**Example**

  ```js
  let accountManager = account_osAccount.getAccountManager();
  try {
A
Annie_wang 已提交
2656 2657 2658
    accountManager.getOsAccountConstraintSourceTypes(100, 'constraint.wifi',(err,sourceTypeInfos)=>{
      console.info('getOsAccountConstraintSourceTypes errInfo:' + JSON.stringify(err));
      console.info('getOsAccountConstraintSourceTypes sourceTypeInfos:' + JSON.stringify(sourceTypeInfos));
A
Annie_wang 已提交
2659 2660
    });
  } catch (e) {
A
Annie_wang 已提交
2661
    console.info('getOsAccountConstraintSourceTypes exception:' + JSON.stringify(e));
A
Annie_wang 已提交
2662 2663 2664
  }
  ```

A
Annie_wang 已提交
2665
### getOsAccountConstraintSourceTypes<sup>9+</sup>
A
Annie_wang 已提交
2666

A
Annie_wang 已提交
2667
getOsAccountConstraintSourceTypes(localId: number, constraint: string): Promise&lt;Array&lt;ConstraintSourceTypeInfo&gt;&gt;;
A
Annie_wang 已提交
2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702

Obtains the constraint source information of an OS account. This API uses a promise to return the result.

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

**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

**System capability**: SystemCapability.Account.OsAccount

**Parameters**

| Name | Type  | Mandatory| Description        |
| ------- | ------ | ---- | ------------ |
| localId     | number | Yes  |  ID of the target OS account.|
| constraint     | string | Yes  |  Name of the [constraint](#constraints) to query.|

**Return value**

| Type                 | Description                                                        |
| --------------------- | ------------------------------------------------------------ |
| Promise&lt;Array&lt;[ConstraintSourceTypeInfo](#constraintsourcetypeinfo)&gt;&gt; | Promise used to return the [constraint](#constraints) source information obtained.|

**Error codes**

| ID| Error Message      |
| -------- | ------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid localId or constraint. |
| 12300003 | Account not found. |

**Example**

  ```js
  let accountManager = account_osAccount.getAccountManager();
  try {
A
Annie_wang 已提交
2703 2704
    accountManager.getOsAccountConstraintSourceTypes(100, 'constraint.wifi').then((result) => {
      console.info('getOsAccountConstraintSourceTypes sourceTypeInfos:' + JSON.stringify(result));
A
Annie_wang 已提交
2705
    }).catch((err)=>{
A
Annie_wang 已提交
2706
      console.info('getOsAccountConstraintSourceTypes errInfo:' + JSON.stringify(err));
A
Annie_wang 已提交
2707 2708
    });
  } catch (e) {
A
Annie_wang 已提交
2709
    console.info('getOsAccountConstraintSourceTypes exception:' + JSON.stringify(e));
A
Annie_wang 已提交
2710 2711
  }
  ```
A
Annie_wang 已提交
2712

A
Annie_wang 已提交
2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728
### isMultiOsAccountEnable<sup>(deprecated)</sup>

isMultiOsAccountEnable(callback: AsyncCallback&lt;boolean&gt;): void

Checks whether multiple OS accounts are supported. This API uses an asynchronous callback to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [checkMultiOsAccountEnabled](#checkmultiosaccountenabled9).

**System capability**: SystemCapability.Account.OsAccount

**Parameters**

| Name  | Type                        | Mandatory| Description                                                    |
| -------- | ---------------------------- | ---- | ------------------------------------------------------ |
A
Annie_wang 已提交
2729
| callback | AsyncCallback&lt;boolean&gt; | Yes  | Callback invoked to return the result. The value **true** means multiple OS accounts are supported; the value **false** means the opposite.|
A
Annie_wang 已提交
2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759

**Example**

  ```js
  let accountManager = account_osAccount.getAccountManager();
  accountManager.isMultiOsAccountEnable((err, isEnabled) => {
    if (err) {
      console.log("isMultiOsAccountEnable failed, error: " + JSON.stringify(err));
    } else {
    console.log("isMultiOsAccountEnable successfully, isEnabled: " + isEnabled);
    }
  });
  ```

### isMultiOsAccountEnable<sup>(deprecated)</sup>

isMultiOsAccountEnable(): Promise&lt;boolean&gt;

Checks whether multiple OS accounts are supported. This API uses a promise to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [checkMultiOsAccountEnabled](#checkmultiosaccountenabled9-1).

**System capability**: SystemCapability.Account.OsAccount

**Return value**

| Type                  | Description                                                      |
| :--------------------- | :--------------------------------------------------------- |
A
Annie_wang 已提交
2760
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means multiple OS accounts are supported; the value **false** means the opposite.|
A
Annie_wang 已提交
2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792

**Example**

  ```js
  let accountManager = account_osAccount.getAccountManager();
  accountManager.isMultiOsAccountEnable().then((isEnabled) => {
    console.log('isMultiOsAccountEnable successfully, isEnabled: ' + isEnabled);
  }).catch((err) => {
    console.log('isMultiOsAccountEnable failed, error: '  + JSON.stringify(err));
  });
  ```


### isOsAccountActived<sup>(deprecated)</sup>

isOsAccountActived(localId: number, callback: AsyncCallback&lt;boolean&gt;): void

Checks whether an OS account is activated. This API uses an asynchronous callback to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [checkOsAccountActivated](#checkosaccountactivated9).

**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS

**System capability**: SystemCapability.Account.OsAccount

**Parameters**

| Name  | Type                        | Mandatory| Description                                                    |
| -------- | ---------------------------- | ---- | ------------------------------------------------------ |
| localId  | number                       | Yes  | ID of the target OS account.                                           |
A
Annie_wang 已提交
2793
| callback | AsyncCallback&lt;boolean&gt; | Yes  | Callback invoked to return the result. The value **true** means the account is activated; the value **false** means the opposite.|
A
Annie_wang 已提交
2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832

**Example**: Check whether OS account 100 is activated.

  ```js
  let accountManager = account_osAccount.getAccountManager();
  let localId = 100;
  accountManager.isOsAccountActived(localId, (err, isActived) => {
    if (err) {
      console.log('isOsAccountActived failed, err:' + JSON.stringify(err));
    } else {
      console.log('isOsAccountActived successfully, isActived:' + isActived);
    }
  });
  ```

### isOsAccountActived<sup>(deprecated)</sup>

isOsAccountActived(localId: number): Promise&lt;boolean&gt;

Checks whether an OS account is activated. This API uses a promise to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [checkOsAccountActivated](#checkosaccountactivated9-1).

**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS

**System capability**: SystemCapability.Account.OsAccount

**Parameters**

| Name | Type  | Mandatory| Description                              |
| ------- | ------ | ---- | --------------------------------- |
| localId | number | Yes  | ID of the target OS account.|

**Return value**

| Type                  | Description                                                       |
| --------------------- | ----------------------------------------------------------- |
A
Annie_wang 已提交
2833
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means the account is activated; the value **false** means the opposite.|
A
Annie_wang 已提交
2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854

**Example**: Check whether OS account 100 is activated.

  ```js
  let accountManager = account_osAccount.getAccountManager();
  let localId = 100;
  accountManager.isOsAccountActived(localId).then((isActived) => {
    console.log('isOsAccountActived successfully, isActived: ' + isActived);
  }).catch((err) => {
    console.log('isOsAccountActived failed, error: '  + JSON.stringify(err));
  });
  ```

### isOsAccountConstraintEnable<sup>(deprecated)</sup>

isOsAccountConstraintEnable(localId: number, constraint: string, callback: AsyncCallback&lt;boolean&gt;): void

Checks whether the specified constraint is enabled for an OS account. This API uses an asynchronous callback to return the result.

> **NOTE**
>
A
Annie_wang 已提交
2855
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [checkOsAccountConstraintEnabled](#checkosaccountconstraintenabled9).
A
Annie_wang 已提交
2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866

**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

**System capability**: SystemCapability.Account.OsAccount

**Parameters**

| Name    | Type                        | Mandatory| Description                                                               |
| ---------- | ---------------------------- | ---- | ----------------------------------------------------------------- |
| localId    | number                       | Yes  | ID of the target OS account.                                |
| constraint | string                       | Yes  | [Constraint](#constraints) to check.                               |
A
Annie_wang 已提交
2867
| callback   | AsyncCallback&lt;boolean&gt; | Yes  | Callback invoked to return the result. The value **true** means the specified constraint is enabled; the value **false** means the opposite.|
A
Annie_wang 已提交
2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891

**Example**: Check whether OS account 100 is forbidden to use Wi-Fi.

  ```js
  let accountManager = account_osAccount.getAccountManager();
  let localId = 100;
  let constraint = "constraint.wifi";
  accountManager.isOsAccountConstraintEnable(localId, constraint, (err, isEnabled) => {
    if (err) {
      console.log("isOsAccountConstraintEnable failed, error:" + JSON.stringify(err));
    } else {
      console.log("isOsAccountConstraintEnable successfully, isEnabled:" + isEnabled);
    }
  });
  ```

### isOsAccountConstraintEnable<sup>(deprecated)</sup>

isOsAccountConstraintEnable(localId: number, constraint: string): Promise&lt;boolean&gt;

Checks whether the specified constraint is enabled for an OS account. This API uses a promise to return the result.

> **NOTE**
>
A
Annie_wang 已提交
2892
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [checkOsAccountConstraintEnabled](#checkosaccountconstraintenabled9-1).
A
Annie_wang 已提交
2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908

**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

**System capability**: SystemCapability.Account.OsAccount

**Parameters**

| Name    | Type  | Mandatory| Description                                |
| ---------- | ------ | ---- | ---------------------------------- |
| localId    | number | Yes  | ID of the target OS account. |
| constraint | string | Yes  | [Constraint](#constraints) to check.|

**Return value**

| Type                  | Description                                                                  |
| ---------------------- | --------------------------------------------------------------------- |
A
Annie_wang 已提交
2909
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means the specified constraint is enabled; the value **false** means the opposite.|
A
Annie_wang 已提交
2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939

**Example**: Check whether OS account 100 is forbidden to use Wi-Fi.

  ```js
  let accountManager = account_osAccount.getAccountManager();
  let localId = 100;
  let constraint = "constraint.wifi";
  accountManager.isOsAccountConstraintEnable(localId, constraint).then((isEnabled) => {
    console.log("isOsAccountConstraintEnable successfully, isEnabled: " + isEnabled);
  }).catch((err) => {
    console.log("isOsAccountConstraintEnable err: "  + JSON.stringify(err));
  });
  ```

### isTestOsAccount<sup>(deprecated)</sup>

isTestOsAccount(callback: AsyncCallback&lt;boolean&gt;): void

Checks whether this OS account is a test account. This API uses an asynchronous callback to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [checkOsAccountTestable](#checkosaccounttestable9).

**System capability**: SystemCapability.Account.OsAccount

**Parameters**

| Name  | Type                        | Mandatory| Description                                                                  |
| -------- | ---------------------------- | ---- | --------------------------------------------------------------------- |
A
Annie_wang 已提交
2940
| callback | AsyncCallback&lt;boolean&gt; | Yes  | Callback invoked to return the result. The value **true** means the account is a test account; the value **false** means the opposite.|
A
Annie_wang 已提交
2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970

**Example**

  ```js
  let accountManager = account_osAccount.getAccountManager();
  accountManager.isTestOsAccount((err, isTestable) => {
    if (err) {
      console.log("isTestOsAccount failed, error: " + JSON.stringify(err));
    } else {
      console.log("isTestOsAccount successfully, isTestable: " + isTestable);
    }
  });
  ```

### isTestOsAccount<sup>(deprecated)</sup>

isTestOsAccount(): Promise&lt;boolean&gt;

Checks whether this OS account is a test account. This API uses a promise to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [checkOsAccountTestable](#checkosaccounttestable9-1).

**System capability**: SystemCapability.Account.OsAccount

**Return value**

| Type                  | Description                                                                     |
| ---------------------- | ------------------------------------------------------------------------ |
A
Annie_wang 已提交
2971
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means the account is a test account; the value **false** means the opposite.|
A
Annie_wang 已提交
2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001

**Example**

  ```js
  let accountManager = account_osAccount.getAccountManager();
  accountManager.isTestOsAccount().then((isTestable) => {
      console.log("isTestOsAccount successfully, isTestable: " + isTestable);
  }).catch((err) => {
      console.log("isTestOsAccount failed, error: " + JSON.stringify(err));
  });
  ```

### isOsAccountVerified<sup>(deprecated)</sup>

isOsAccountVerified(callback: AsyncCallback&lt;boolean&gt;): void

Checks whether this OS account has been verified. This API uses an asynchronous callback to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [checkOsAccountVerified](#checkosaccountverified9).

**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS

**System capability**: SystemCapability.Account.OsAccount

**Parameters**

| Name  | Type                        | Mandatory| Description                                                           |
| -------- | ---------------------------- | ---- | ------------------------------------------------------------- |
A
Annie_wang 已提交
3002
| callback | AsyncCallback&lt;boolean&gt; | Yes  | Callback invoked to return the result. The value **true** means the OS account has been verified; the value **false** means the opposite.|
A
Annie_wang 已提交
3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034

**Example**

  ```js
  let accountManager = account_osAccount.getAccountManager();
  accountManager.isOsAccountVerified((err, isVerified) => {
    if (err) {
      console.log("isOsAccountVerified failed, error: " + JSON.stringify(err));
    } else {
      console.log("isOsAccountVerified successfully, isVerified: " + isVerified);
    }
  });
  ```

### isOsAccountVerified<sup>(deprecated)</sup>

isOsAccountVerified(localId: number, callback: AsyncCallback&lt;boolean&gt;): void

Checks whether an OS account has been verified. This API uses an asynchronous callback to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [checkOsAccountVerified](#checkosaccountverified9-1).

**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS

**System capability**: SystemCapability.Account.OsAccount

**Parameters**

| Name  | Type                        | Mandatory| Description                                                           |
| -------- | ---------------------------- | ---- | ------------------------------------------------------------- |
A
Annie_wang 已提交
3035 3036
| localId  | number                       | Yes  | ID of the target OS account.                            |
| callback | AsyncCallback&lt;boolean&gt; | Yes  | Callback invoked to return the result. The value **true** means the OS account has been verified; the value **false** means the opposite.|
A
Annie_wang 已提交
3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075

**Example**

  ```js
  let accountManager = account_osAccount.getAccountManager();
  let localId = 100;
  accountManager.isOsAccountVerified(localId, (err, isVerified) => {
    if (err) {
      console.log("isOsAccountVerified failed, error: " + JSON.stringify(err));
    } else {
      console.log("isOsAccountVerified successfully, isVerified: " + isVerified);
    }
  });
  ```

### isOsAccountVerified<sup>(deprecated)</sup>

isOsAccountVerified(localId?: number): Promise&lt;boolean&gt;

Checks whether an OS account has been verified. This API uses a promise to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [checkOsAccountVerified](#checkosaccountverified9-2).

**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS

**System capability**: SystemCapability.Account.OsAccount

**Parameters**

| Name | Type  | Mandatory| Description                                                             |
| ------- | ------ | ---- | ---------------------------------------------------------------- |
| localId | number | No  | ID of the target OS account. If this parameter is not specified, this API checks whether the current OS account has been verified.|

**Return value**

| Type                  | Description                                                              |
| ---------------------- | ----------------------------------------------------------------- |
A
Annie_wang 已提交
3076
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means the OS account has been verified; the value **false** means the opposite.|
A
Annie_wang 已提交
3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160

**Example**

  ```js
  let accountManager = account_osAccount.getAccountManager();
  accountManager.isOsAccountVerified(localId).then((isVerified) => {
    console.log("isOsAccountVerified successfully, isVerified: " + isVerified);
  }).catch((err) => {
    console.log("isOsAccountVerified failed, error: " + JSON.stringify(err));
  });
  ```

### getCreatedOsAccountsCount<sup>(deprecated)</sup>

getCreatedOsAccountsCount(callback: AsyncCallback&lt;number&gt;): void

Obtains the number of OS accounts created. This API uses an asynchronous callback to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getOsAccountCount](#getosaccountcount9).

**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

**System capability**: SystemCapability.Account.OsAccount

**Parameters**

| Name  | Type                       | Mandatory| Description                                                                        |
| -------- | --------------------------- | ---- | -------------------------------------------------------------------------- |
| callback | AsyncCallback&lt;number&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the number of created OS accounts. If the operation fails, **err** is an error object.|

**Example**

  ```js
  let accountManager = account_osAccount.getAccountManager();
  accountManager.getCreatedOsAccountsCount((err, count)=>{
    if (err) {
      console.log("getCreatedOsAccountsCount failed, error: " + JSON.stringify(err));
    } else {
      console.log("getCreatedOsAccountsCount successfully, count: " + count);
    }
  });
  ```

### getCreatedOsAccountsCount<sup>(deprecated)</sup>

getCreatedOsAccountsCount(): Promise&lt;number&gt;

Obtains the number of OS accounts created. This API uses a promise to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getOsAccountCount](#getosaccountcount9-1).

**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

**System capability**: SystemCapability.Account.OsAccount

**Return value**

| Type                 | Description                                   |
| --------------------- | -------------------------------------- |
| Promise&lt;number&gt; | Promise used to return the number of created OS accounts.|

**Example**

  ```js
  let accountManager = account_osAccount.getAccountManager();
  accountManager.getCreatedOsAccountsCount().then((count) => {
    console.log("getCreatedOsAccountsCount successfully, count: " + count);
  }).catch((err) => {
    console.log("getCreatedOsAccountsCount failed, error: "  + JSON.stringify(err));
  });
  ```

### getOsAccountLocalIdFromProcess<sup>(deprecated)</sup>

getOsAccountLocalIdFromProcess(callback: AsyncCallback&lt;number&gt;): void

Obtains the ID of the OS account to which the current process belongs. This API uses an asynchronous callback to return the result.

> **NOTE**
>
A
Annie_wang 已提交
3161
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getOsAccountLocalId](#getosaccountlocalid9).
A
Annie_wang 已提交
3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191

**System capability**: SystemCapability.Account.OsAccount

**Parameters**

| Name  | Type                       | Mandatory| Description                                                                          |
| -------- | --------------------------- | ---- | ---------------------------------------------------------------------------- |
| callback | AsyncCallback&lt;number&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the OS account ID obtained. Otherwise, **err** is an error object.|

**Example**

  ```js
  let accountManager = account_osAccount.getAccountManager();
  accountManager.getOsAccountLocalIdFromProcess((err, localId) => {
    if (err) {
      console.log("getOsAccountLocalIdFromProcess failed, error: " + JSON.stringify(err));
    } else {
      console.log("getOsAccountLocalIdFromProcess successfully, localId: " + localId);
    }
  });
  ```

### getOsAccountLocalIdFromProcess<sup>(deprecated)</sup>

getOsAccountLocalIdFromProcess(): Promise&lt;number&gt;

Obtains the ID of the OS account to which the current process belongs. This API uses a promise to return the result.

> **NOTE**
>
A
Annie_wang 已提交
3192
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getOsAccountLocalId](#getosaccountlocalid9-1).
A
Annie_wang 已提交
3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220

**System capability**: SystemCapability.Account.OsAccount

**Return value**

| Type                 | Description                                     |
| :-------------------- | :--------------------------------------- |
| Promise&lt;number&gt; | Promise used to return the OS account ID obtained.|

**Example**

  ```js
  let accountManager = account_osAccount.getAccountManager();
  accountManager.getOsAccountLocalIdFromProcess().then((localId) => {
    console.log('getOsAccountLocalIdFromProcess successfully, localId: ' + localId);
  }).catch((err) => {
    console.log('getOsAccountLocalIdFromProcess failed, error: '  + JSON.stringify(err));
  });
  ```

### getOsAccountLocalIdFromUid<sup>(deprecated)</sup>

getOsAccountLocalIdFromUid(uid: number, callback: AsyncCallback&lt;number&gt;): void

Obtains the OS account ID based on the process UID. This API uses an asynchronous callback to return the result.

> **NOTE**
>
A
Annie_wang 已提交
3221
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getOsAccountLocalIdForUid](#getosaccountlocalidforuid9).
A
Annie_wang 已提交
3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253

**System capability**: SystemCapability.Account.OsAccount

**Parameters**

| Name  | Type                       | Mandatory| Description                                                                   |
| -------- | --------------------------- | ---- | --------------------------------------------------------------------- |
| uid      | number                      | Yes  | Process UID.                                                             |
| callback | AsyncCallback&lt;number&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the OS account ID obtained. Otherwise, **data** is an error object.|

**Example**: Obtain the ID of the OS account whose process UID is **12345678**.

  ```js
  let accountManager = account_osAccount.getAccountManager();
  let uid = 12345678;
  accountManager.getOsAccountLocalIdFromUid(uid, (err, localId) => {
    if (err) {
      console.log("getOsAccountLocalIdFromUid failed, error: " + JSON.stringify(err));
    } else {
      console.log("getOsAccountLocalIdFromUid successfully, localId: " + localId);
    }
  });
  ```

### getOsAccountLocalIdFromUid<sup>(deprecated)</sup>

getOsAccountLocalIdFromUid(uid: number): Promise&lt;number&gt;

Obtains the OS account ID based on the process UID. This API uses a promise to return the result.

> **NOTE**
>
A
Annie_wang 已提交
3254
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getOsAccountLocalIdForUid](#getosaccountlocalidforuid9-1).
A
Annie_wang 已提交
3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289

**System capability**: SystemCapability.Account.OsAccount

**Parameters**

| Name| Type  | Mandatory| Description     |
| ------ | ------ | ---- | --------- |
| uid    | number | Yes  | Process UID.|

**Return value**

| Type                 | Description                                 |
| :-------------------- | :----------------------------------- |
| Promise&lt;number&gt; | Promise used to return the OS account ID obtained.|

**Example**: Obtain the ID of the OS account whose process UID is **12345678**.

  ```js
  let accountManager = account_osAccount.getAccountManager();
  let uid = 12345678;
  accountManager.getOsAccountLocalIdFromUid(uid).then((localId) => {
    console.log("getOsAccountLocalIdFromUid successfully, localId: " + localId);
  }).catch((err) => {
    console.log("getOsAccountLocalIdFromUid failed, error: "  + JSON.stringify(err));
  });
  ```

### getOsAccountLocalIdFromDomain<sup>(deprecated)</sup>

getOsAccountLocalIdFromDomain(domainInfo: DomainAccountInfo, callback: AsyncCallback&lt;number&gt;): void

Obtains the OS account ID based on the domain account information. This API uses an asynchronous callback to return the result.

> **NOTE**
>
A
Annie_wang 已提交
3290
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getOsAccountLocalIdForDomain](#getosaccountlocalidfordomain9).
A
Annie_wang 已提交
3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324

**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

**System capability**: SystemCapability.Account.OsAccount

**Parameters**

| Name    | Type                                   | Mandatory| Description                                                                        |
| ---------- | --------------------------------------- | ---- | --------------------------------------------------------------------------- |
| domainInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes  | Domain account information.                                                               |
| callback   | AsyncCallback&lt;number&gt;             | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the OS account ID obtained. Otherwise, **err** is an error object.|

**Example**

  ```js
  let domainInfo = {domain: 'testDomain', accountName: 'testAccountName'};
  let accountManager = account_osAccount.getAccountManager();
  accountManager.getOsAccountLocalIdFromDomain(domainInfo, (err, localId) => {
    if (err) {
      console.log("getOsAccountLocalIdFromDomain failed, error: " + JSON.stringify(err));
    } else {
      console.log("getOsAccountLocalIdFromDomain successfully, localId: " + localId);
    }
  });
  ```

### getOsAccountLocalIdFromDomain<sup>(deprecated)</sup>

getOsAccountLocalIdFromDomain(domainInfo: DomainAccountInfo): Promise&lt;number&gt;

Obtains the OS account ID based on the domain account information. This API uses a promise to return the result.

> **NOTE**
>
A
Annie_wang 已提交
3325
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getOsAccountLocalIdForDomain](#getosaccountlocalidfordomain9-1).
A
Annie_wang 已提交
3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340

**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

**System capability**: SystemCapability.Account.OsAccount

**Parameters**

| Name    | Type                                   | Mandatory| Description        |
| ---------- | --------------------------------------- | ---- | ------------ |
| domainInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes  | Domain account information.|

**Return value**

| Type                 | Description                                   |
| :-------------------- | :------------------------------------- |
A
Annie_wang 已提交
3341
| Promise&lt;number&gt; | Promise used to return the ID of the OS account associated with the domain account.|
A
Annie_wang 已提交
3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432

**Example**

  ```js
  let accountManager = account_osAccount.getAccountManager();
  let domainInfo = {domain: 'testDomain', accountName: 'testAccountName'};
  accountManager.getOsAccountLocalIdFromDomain(domainInfo).then((localId) => {
    console.log('getOsAccountLocalIdFromDomain successfully, localId: ' + localId);
  }).catch((err) => {
    console.log('getOsAccountLocalIdFromDomain failed, error: '  + JSON.stringify(err));
  });
  ```

### getOsAccountAllConstraints<sup>(deprecated)</sup>

getOsAccountAllConstraints(localId: number, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void

Obtains all constraints enabled for an OS account. This API uses an asynchronous callback to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getOsAccountConstraints](#getosaccountconstraints9).

**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

**System capability**: SystemCapability.Account.OsAccount

**Parameters**

| Name  | Type                                    | Mandatory| Description                                                                                            |
| -------- | ---------------------------------------- | ---- | ---------------------------------------------------------------------------------------------- |
| localId  | number                                   | Yes  | ID of the target OS account.                                                                                   |
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is a list of all [constraints](#constraints) enabled for the OS account. Otherwise, **err** is an error object.|

**Example**: Obtain all constraints of OS account 100.

  ```js
  let accountManager = account_osAccount.getAccountManager();
  let localId = 100;
  accountManager.getOsAccountAllConstraints(localId, (err, constraints)=>{
    console.log('getOsAccountAllConstraints err:' + JSON.stringify(err));
    console.log('getOsAccountAllConstraints:' + JSON.stringify(constraints));
  });
  ```

### getOsAccountAllConstraints<sup>(deprecated)</sup>

getOsAccountAllConstraints(localId: number): Promise&lt;Array&lt;string&gt;&gt;

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getOsAccountConstraints](#getosaccountconstraints9-1).

Obtains all constraints enabled for an OS account. This API uses a promise to return the result.

**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

**System capability**: SystemCapability.Account.OsAccount

**Parameters**

| Name | Type  | Mandatory| Description        |
| ------- | ------ | ---- | ------------ |
| localId | number | Yes  | ID of the target OS account.|

**Return value**

| Type                              | Description                                                        |
| :--------------------------------- | :----------------------------------------------------------- |
| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return all the [constraints](#constraints) enabled for the OS account.|

**Example**: Obtain all constraints of OS account 100.

  ```js
  let accountManager = account_osAccount.getAccountManager();
  let localId = 100;
  accountManager.getOsAccountAllConstraints(localId).then((constraints) => {
    console.log('getOsAccountAllConstraints, constraints: ' + constraints);
  }).catch((err) => {
    console.log('getOsAccountAllConstraints err: '  + JSON.stringify(err));
  });
  ```

### queryActivatedOsAccountIds<sup>(deprecated)</sup>

queryActivatedOsAccountIds(callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void

Obtains information about all activated OS accounts. This API uses an asynchronous callback to return the result.

> **NOTE**
>
A
Annie_wang 已提交
3433
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getActivatedOsAccountLocalIds](#getactivatedosaccountlocalids9).
A
Annie_wang 已提交
3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461

**System capability**: SystemCapability.Account.OsAccount

**Parameters**

| Name  | Type                                    | Mandatory| Description                                                  |
| -------- | ---------------------------------------- | ---- | ------------------------------------------------------ |
| callback | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is a list of activated OS accounts. Otherwise, **data** is an error object.|

**Example**

  ```js
  let accountManager = account_osAccount.getAccountManager();
  accountManager.queryActivatedOsAccountIds((err, idArray)=>{
    console.log('queryActivatedOsAccountIds err:' + JSON.stringify(err));
    console.log('queryActivatedOsAccountIds idArray length:' + idArray.length);
    for(let i=0;i<idArray.length;i++) {
      console.info('activated os account id: ' + idArray[i]);
    }
  });
  ```

### queryActivatedOsAccountIds<sup>(deprecated)</sup>

queryActivatedOsAccountIds(): Promise&lt;Array&lt;number&gt;&gt;

> **NOTE**
>
A
Annie_wang 已提交
3462
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getActivatedOsAccountLocalIds](#getactivatedosaccountlocalids9-1).
A
Annie_wang 已提交
3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540

Obtains information about all activated OS accounts. This API uses a promise to return the result.

**System capability**: SystemCapability.Account.OsAccount

**Return value**

| Type                              | Description                                              |
| ---------------------------------- | ------------------------------------------------- |
| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the information about all activated OS accounts.|

**Example**

  ```js
  let accountManager = account_osAccount.getAccountManager();
  accountManager.queryActivatedOsAccountIds().then((idArray) => {
    console.log('queryActivatedOsAccountIds, idArray: ' + idArray);
  }).catch((err) => {
    console.log('queryActivatedOsAccountIds err: '  + JSON.stringify(err));
  });
  ```

### queryCurrentOsAccount<sup>(deprecated)</sup>

queryCurrentOsAccount(callback: AsyncCallback&lt;OsAccountInfo&gt;): void

Obtains information about the OS account to which the current process belongs. This API uses an asynchronous callback to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getCurrentOsAccount](#getcurrentosaccount9).

**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

**System capability**: SystemCapability.Account.OsAccount

**Parameters**

| Name  | Type                                                | Mandatory| Description                                          |
| -------- | ---------------------------------------------------- | ---- | ---------------------------------------------- |
| callback | AsyncCallback&lt;[OsAccountInfo](#osaccountinfo)&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the OS account information obtained. Otherwise, **data** is an error object.|

**Example**

  ```js
  let accountManager = account_osAccount.getAccountManager();
  accountManager.queryCurrentOsAccount((err, curAccountInfo)=>{
    console.log('queryCurrentOsAccount err:' + JSON.stringify(err));
    console.log('queryCurrentOsAccount curAccountInfo:' + JSON.stringify(curAccountInfo));
  });
  ```

### queryCurrentOsAccount<sup>(deprecated)</sup>

queryCurrentOsAccount(): Promise&lt;OsAccountInfo&gt;

Obtains information about the OS account to which the current process belongs. This API uses a promise to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getCurrentOsAccount](#getcurrentosaccount9-1).

**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

**System capability**: SystemCapability.Account.OsAccount

**Return value**

| Type                                          | Description                                      |
| ---------------------------------------------- | ------------------------------------------ |
| Promise&lt;[OsAccountInfo](#osaccountinfo)&gt; | Promise used to return the OS account information obtained.|

**Example**

  ```js
  let accountManager = account_osAccount.getAccountManager();
  accountManager.queryCurrentOsAccount().then((accountInfo) => {
    console.log('queryCurrentOsAccount, accountInfo: ' + JSON.stringify(accountInfo));
A
annie_wangli 已提交
3541
  }).catch((err) => {
A
Annie_wang 已提交
3542
    console.log('queryCurrentOsAccount err: '  + JSON.stringify(err));
A
annie_wangli 已提交
3543 3544 3545
  });
  ```

A
Annie_wang 已提交
3546
### getOsAccountTypeFromProcess<sup>(deprecated)</sup>
A
annie_wangli 已提交
3547

A
Annie_wang 已提交
3548
getOsAccountTypeFromProcess(callback: AsyncCallback&lt;OsAccountType&gt;): void
A
annie_wangli 已提交
3549

A
Annie_wang 已提交
3550
Obtains the type of the account to which the current process belongs. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
3551

A
Annie_wang 已提交
3552 3553 3554
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getOsAccountType](#getosaccounttype9).
A
annie_wangli 已提交
3555 3556

**System capability**: SystemCapability.Account.OsAccount
A
annie_wangli 已提交
3557

A
annie_wangli 已提交
3558
**Parameters**
A
annie_wangli 已提交
3559

A
Annie_wang 已提交
3560 3561 3562
| Name  | Type                                                | Mandatory| Description                                                |
| -------- | ---------------------------------------------------- | ---- | ---------------------------------------------------- |
| callback | AsyncCallback&lt;[OsAccountType](#osaccounttype)&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the OS account type obtained. Otherwise, **err** is an error object.|
A
annie_wangli 已提交
3563 3564

**Example**
A
annie_wangli 已提交
3565

Z
zhangalong 已提交
3566
  ```js
A
Annie_wang 已提交
3567
  let accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
3568 3569 3570 3571
  accountManager.getOsAccountTypeFromProcess((err, accountType) => {
    console.log('getOsAccountTypeFromProcess err: ' + JSON.stringify(err));
    console.log('getOsAccountTypeFromProcess accountType: ' + accountType);
  });
A
annie_wangli 已提交
3572 3573
  ```

A
Annie_wang 已提交
3574
### getOsAccountTypeFromProcess<sup>(deprecated)</sup>
A
annie_wangli 已提交
3575

A
Annie_wang 已提交
3576
getOsAccountTypeFromProcess(): Promise&lt;OsAccountType&gt;
A
annie_wangli 已提交
3577

A
Annie_wang 已提交
3578
Obtains the type of the account to which the current process belongs. This API uses a promise to return the result.
A
annie_wangli 已提交
3579

A
Annie_wang 已提交
3580 3581 3582
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getOsAccountType](#getosaccounttype9-1).
A
annie_wangli 已提交
3583 3584 3585

**System capability**: SystemCapability.Account.OsAccount

A
Annie_wang 已提交
3586
**Return value**
A
annie_wangli 已提交
3587

A
Annie_wang 已提交
3588 3589 3590
| Type                                          | Description                                           |
| ---------------------------------------------- | ----------------------------------------------- |
| Promise&lt;[OsAccountType](#osaccounttype)&gt; | Promise used to return the OS account type obtained.|
A
annie_wangli 已提交
3591

A
annie_wangli 已提交
3592
**Example**
A
annie_wangli 已提交
3593

Z
zhangalong 已提交
3594
  ```js
A
Annie_wang 已提交
3595
  let accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
3596 3597 3598 3599 3600
  accountManager.getOsAccountTypeFromProcess().then((accountType) => {
    console.log('getOsAccountTypeFromProcess, accountType: ' + accountType);
  }).catch((err) => {
    console.log('getOsAccountTypeFromProcess err: '  + JSON.stringify(err));
  });
A
annie_wangli 已提交
3601 3602
  ```

A
Annie_wang 已提交
3603
### getDistributedVirtualDeviceId<sup>(deprecated)</sup>
A
Annie_wang 已提交
3604

A
Annie_wang 已提交
3605
getDistributedVirtualDeviceId(callback: AsyncCallback&lt;string&gt;): void
A
Annie_wang 已提交
3606

A
Annie_wang 已提交
3607
Obtains the ID of this distributed virtual device. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
3608 3609 3610 3611

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [queryDistributedVirtualDeviceId](#querydistributedvirtualdeviceid9).
A
Annie_wang 已提交
3612

A
Annie_wang 已提交
3613
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC or ohos.permission.MANAGE_LOCAL_ACCOUNTS
A
Annie_wang 已提交
3614 3615 3616 3617 3618

**System capability**: SystemCapability.Account.OsAccount

**Parameters**

A
Annie_wang 已提交
3619 3620 3621
| Name  | Type                       | Mandatory| Description                                                                   |
| -------- | --------------------------- | ---- | --------------------------------------------------------------------- |
| callback | AsyncCallback&lt;string&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the distributed virtual device ID obtained. Otherwise, **data** is an error object.|
A
Annie_wang 已提交
3622 3623 3624 3625

**Example**

  ```js
A
Annie_wang 已提交
3626
  let accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
3627 3628 3629
  accountManager.getDistributedVirtualDeviceId((err, virtualID) => {
    console.log('getDistributedVirtualDeviceId err: ' + JSON.stringify(err));
    console.log('getDistributedVirtualDeviceId virtualID: ' + virtualID);
A
Annie_wang 已提交
3630 3631 3632
  });
  ```

A
Annie_wang 已提交
3633
### getDistributedVirtualDeviceId<sup>(deprecated)</sup>
A
Annie_wang 已提交
3634

A
Annie_wang 已提交
3635
getDistributedVirtualDeviceId(): Promise&lt;string&gt;
A
Annie_wang 已提交
3636

A
Annie_wang 已提交
3637
Obtains the ID of this distributed virtual device. This API uses a promise to return the result.
A
Annie_wang 已提交
3638

A
Annie_wang 已提交
3639 3640 3641
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [queryDistributedVirtualDeviceId](#querydistributedvirtualdeviceid9-1).
A
Annie_wang 已提交
3642

A
Annie_wang 已提交
3643
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC or ohos.permission.MANAGE_LOCAL_ACCOUNTS
A
Annie_wang 已提交
3644

A
Annie_wang 已提交
3645
**System capability**: SystemCapability.Account.OsAccount
A
Annie_wang 已提交
3646

A
Annie_wang 已提交
3647
**Return value**
A
Annie_wang 已提交
3648

A
Annie_wang 已提交
3649 3650 3651
| Type                 | Description                             |
| --------------------- | --------------------------------- |
| Promise&lt;string&gt; | Promise used to return the distributed virtual device ID obtained.|
A
Annie_wang 已提交
3652 3653 3654 3655

**Example**

  ```js
A
Annie_wang 已提交
3656
  let accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
3657 3658 3659 3660
  accountManager.getDistributedVirtualDeviceId().then((virtualID) => {
    console.log('getDistributedVirtualDeviceId, virtualID: ' + virtualID);
  }).catch((err) => {
    console.log('getDistributedVirtualDeviceId err: '  + JSON.stringify(err));
A
Annie_wang 已提交
3661
  });
A
Annie_wang 已提交
3662 3663
  ```

A
Annie_wang 已提交
3664
### getOsAccountLocalIdBySerialNumber<sup>(deprecated)</sup>
A
Annie_wang 已提交
3665

A
Annie_wang 已提交
3666
getOsAccountLocalIdBySerialNumber(serialNumber: number, callback: AsyncCallback&lt;number&gt;): void
A
Annie_wang 已提交
3667

A
Annie_wang 已提交
3668
Obtains the OS account ID based on the SN. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
3669

A
Annie_wang 已提交
3670 3671
> **NOTE**
>
A
Annie_wang 已提交
3672
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getOsAccountLocalIdForSerialNumber](#getosaccountlocalidforserialnumber9).
A
Annie_wang 已提交
3673

A
Annie_wang 已提交
3674 3675 3676 3677
**System capability**: SystemCapability.Account.OsAccount

**Parameters**

A
Annie_wang 已提交
3678 3679 3680 3681
| Name      | Type                       | Mandatory| Description                                                                              |
| ------------ | --------------------------- | ---- | -------------------------------------------------------------------------------- |
| serialNumber | number                      | Yes  | Account SN.                                                                       |
| callback     | AsyncCallback&lt;number&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the OS account ID obtained. Otherwise, **err** is an error object.|
A
Annie_wang 已提交
3682

A
Annie_wang 已提交
3683
**Example**: Obtain the ID of the OS account whose SN is 12345.
A
Annie_wang 已提交
3684 3685

  ```js
A
Annie_wang 已提交
3686
  let accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
3687 3688 3689 3690
  let serialNumber = 12345;
  accountManager.getOsAccountLocalIdBySerialNumber(serialNumber, (err, localId)=>{
    console.log('ger localId err:' + JSON.stringify(err));
    console.log('get localId:' + localId + ' by serialNumber: ' + serialNumber);
A
Annie_wang 已提交
3691 3692 3693
  });
  ```

A
Annie_wang 已提交
3694
### getOsAccountLocalIdBySerialNumber<sup>(deprecated)</sup>
A
Annie_wang 已提交
3695

A
Annie_wang 已提交
3696
getOsAccountLocalIdBySerialNumber(serialNumber: number): Promise&lt;number&gt;
A
Annie_wang 已提交
3697

A
Annie_wang 已提交
3698
Obtains the OS account ID based on the SN. This API uses a promise to return the result.
A
Annie_wang 已提交
3699

A
Annie_wang 已提交
3700 3701
> **NOTE**
>
A
Annie_wang 已提交
3702
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getOsAccountLocalIdForSerialNumber](#getosaccountlocalidforserialnumber9-1).
A
Annie_wang 已提交
3703

A
Annie_wang 已提交
3704 3705
**System capability**: SystemCapability.Account.OsAccount

A
Annie_wang 已提交
3706 3707 3708 3709 3710 3711
**Parameters**

| Name      | Type  | Mandatory| Description      |
| ------------ | ------ | ---- | ---------- |
| serialNumber | number | Yes  | Account SN.|

A
Annie_wang 已提交
3712
**Return value**
A
Annie_wang 已提交
3713 3714

| Type                 | Description                                                        |
A
Annie_wang 已提交
3715 3716
| --------------------- | -------------------------------------------- |
| Promise&lt;number&gt; | Promise used to return the OS account ID obtained.|
A
Annie_wang 已提交
3717

A
Annie_wang 已提交
3718
**Example**: Obtain the ID of the OS account whose SN is 12345.
A
Annie_wang 已提交
3719 3720

  ```js
A
Annie_wang 已提交
3721
  let accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
3722 3723 3724 3725 3726
  let serialNumber = 12345;
  accountManager.getOsAccountLocalIdBySerialNumber(serialNumber).then((localId) => {
    console.log('getOsAccountLocalIdBySerialNumber localId: ' + localId);
  }).catch((err) => {
    console.log('getOsAccountLocalIdBySerialNumber err: '  + JSON.stringify(err));
A
Annie_wang 已提交
3727 3728 3729
  });
  ```

A
Annie_wang 已提交
3730
### getSerialNumberByOsAccountLocalId<sup>(deprecated)</sup>
A
Annie_wang 已提交
3731

A
Annie_wang 已提交
3732
getSerialNumberByOsAccountLocalId(localId: number, callback: AsyncCallback&lt;number&gt;): void
A
Annie_wang 已提交
3733

A
Annie_wang 已提交
3734
Obtains the SN of an OS account based on the account ID. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
3735

A
Annie_wang 已提交
3736 3737
> **NOTE**
>
A
Annie_wang 已提交
3738
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getSerialNumberForOsAccountLocalId](#getserialnumberforosaccountlocalid9).
A
Annie_wang 已提交
3739 3740 3741 3742 3743

**System capability**: SystemCapability.Account.OsAccount

**Parameters**

A
Annie_wang 已提交
3744 3745 3746 3747
| Name  | Type                       | Mandatory| Description                                                                        |
| -------- | --------------------------- | ---- | --------------------------------------------------------------------------- |
| localId  | number                      | Yes  | ID of the target OS account.                                                                |
| callback | AsyncCallback&lt;number&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the SN obtained. Otherwise, **err** is an error object.|
A
Annie_wang 已提交
3748

A
Annie_wang 已提交
3749
**Example**: Obtain the SN of the OS account 100.
A
Annie_wang 已提交
3750 3751

  ```js
A
Annie_wang 已提交
3752
  let accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
3753 3754 3755 3756
  let localId = 100;
  accountManager.getSerialNumberByOsAccountLocalId(localId, (err, serialNumber)=>{
    console.log('ger serialNumber err:' + JSON.stringify(err));
    console.log('get serialNumber:' + serialNumber + ' by localId: ' + localId);
A
Annie_wang 已提交
3757 3758 3759
  });
  ```

A
Annie_wang 已提交
3760
### getSerialNumberByOsAccountLocalId<sup>(deprecated)</sup>
A
Annie_wang 已提交
3761

A
Annie_wang 已提交
3762
getSerialNumberByOsAccountLocalId(localId: number): Promise&lt;number&gt;
A
Annie_wang 已提交
3763

A
Annie_wang 已提交
3764
Obtains the SN of an OS account based on the account ID. This API uses a promise to return the result.
A
Annie_wang 已提交
3765

A
Annie_wang 已提交
3766 3767
> **NOTE**
>
A
Annie_wang 已提交
3768
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getSerialNumberForOsAccountLocalId](#getserialnumberforosaccountlocalid9-1).
A
Annie_wang 已提交
3769 3770 3771 3772 3773

**System capability**: SystemCapability.Account.OsAccount

**Parameters**

A
Annie_wang 已提交
3774 3775 3776
| Name | Type  | Mandatory| Description         |
| ------- | ------ | ---- | ----------- |
| localId | number | Yes  | ID of the target OS account.|
A
Annie_wang 已提交
3777

A
Annie_wang 已提交
3778
**Return value**
A
Annie_wang 已提交
3779

A
Annie_wang 已提交
3780 3781 3782
| Type                 | Description                                   |
| --------------------- | -------------------------------------- |
| Promise&lt;number&gt; | Promise used to return the SN obtained.|
A
Annie_wang 已提交
3783

A
Annie_wang 已提交
3784
**Example**: Obtain the SN of the OS account 100.
A
Annie_wang 已提交
3785 3786

  ```js
A
Annie_wang 已提交
3787
  let accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
3788 3789 3790 3791 3792
  let localId = 100;
  accountManager.getSerialNumberByOsAccountLocalId(localId).then((serialNumber) => {
    console.log('getSerialNumberByOsAccountLocalId serialNumber: ' + serialNumber);
  }).catch((err) => {
    console.log('getSerialNumberByOsAccountLocalId err: '  + JSON.stringify(err));
A
Annie_wang 已提交
3793
  });
A
Annie_wang 已提交
3794 3795
  ```

A
Annie_wang 已提交
3796 3797 3798 3799
## UserAuth<sup>8+</sup>

Provides APIs for user authentication.

A
Annie_wang 已提交
3800
**System API**: This is a system API.
A
Annie_wang 已提交
3801

A
Annie_wang 已提交
3802 3803 3804 3805 3806 3807
### constructor<sup>8+</sup>

constructor()

A constructor used to create an instance for user authentication.

A
Annie_wang 已提交
3808
**System API**: This is a system API.
A
Annie_wang 已提交
3809

A
Annie_wang 已提交
3810 3811
**System capability**: SystemCapability.Account.OsAccount

A
Annie_wang 已提交
3812
**Example** 
A
Annie_wang 已提交
3813
  ```js
A
Annie_wang 已提交
3814
  let userAuth = new account_osAccount.UserAuth();
A
Annie_wang 已提交
3815 3816 3817 3818 3819 3820 3821 3822
  ```

### getVersion<sup>8+</sup>

getVersion(): number;

Obtains version information.

A
Annie_wang 已提交
3823
**System API**: This is a system API.
A
Annie_wang 已提交
3824 3825 3826 3827 3828 3829 3830 3831 3832

**System capability**: SystemCapability.Account.OsAccount

**Return value**

| Type  | Description        |
| :----- | :----------- |
| number | Version information obtained.|

A
Annie_wang 已提交
3833
**Example** 
A
Annie_wang 已提交
3834
  ```js
A
Annie_wang 已提交
3835 3836
  let userAuth = new account_osAccount.UserAuth();
  let version = userAuth.getVersion();
A
Annie_wang 已提交
3837
  console.log('getVersion version = ' + version);
A
Annie_wang 已提交
3838 3839 3840 3841 3842 3843
  ```

### getAvailableStatus<sup>8+</sup>

getAvailableStatus(authType: AuthType, authTrustLevel: AuthTrustLevel): number;

A
Annie_wang 已提交
3844
Obtains the available status of the authentication capability corresponding to the specified authentication type and trust level.
A
Annie_wang 已提交
3845

A
Annie_wang 已提交
3846
**System API**: This is a system API.
A
Annie_wang 已提交
3847 3848 3849 3850 3851 3852 3853

**System capability**: SystemCapability.Account.OsAccount

**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL

**Parameters**

A
Annie_wang 已提交
3854 3855
| Name          | Type                              | Mandatory| Description                      |
| --------------- | -----------------------------------| ---- | ------------------------- |
A
Annie_wang 已提交
3856
| authType        | [AuthType](#authtype8)             | Yes  | Authentication credential type.    |
A
Annie_wang 已提交
3857
| authTrustLevel  | [AuthTrustLevel](#authtrustlevel8) | Yes  | Trust level of the authentication.|
A
Annie_wang 已提交
3858 3859 3860

**Return value**

A
Annie_wang 已提交
3861 3862 3863 3864 3865 3866 3867 3868 3869 3870
| Type  | Description                          |
| ------ | ----------------------------- |
| number | Available status of the authentication capability.|

**Error codes**

| ID| Error Message                    |
| -------- | --------------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid authType or authTrustLevel. |
A
Annie_wang 已提交
3871

A
Annie_wang 已提交
3872
**Example** 
A
Annie_wang 已提交
3873
  ```js
A
Annie_wang 已提交
3874 3875 3876
  let userAuth = new account_osAccount.UserAuth();
  let authType = account_osAccount.AuthType.PIN;
  let authTrustLevel = account_osAccount.AuthTrustLevel.ATL1;
A
Annie_wang 已提交
3877 3878 3879 3880 3881 3882
  try {
    let status = userAuth.getAvailableStatus(authType, authTrustLevel);
    console.log('getAvailableStatus status = ' + status);
  } catch (e) {
    console.log('getAvailableStatus exception = ' + JSON.stringify(e));
  }
A
Annie_wang 已提交
3883 3884 3885 3886 3887 3888 3889 3890
  ```

### getProperty<sup>8+</sup>

getProperty(request: GetPropertyRequest, callback: AsyncCallback&lt;ExecutorProperty&gt;): void;

Obtains the executor property based on the request. This API uses an asynchronous callback to return the result.

A
Annie_wang 已提交
3891
**System API**: This is a system API.
A
Annie_wang 已提交
3892 3893 3894 3895 3896 3897 3898 3899

**System capability**: SystemCapability.Account.OsAccount

**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL

**Parameters**

| Name   | Type                                                                   | Mandatory| Description                               |
A
Annie_wang 已提交
3900
| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------ |
A
Annie_wang 已提交
3901
| request  | [GetPropertyRequest](#getpropertyrequest8)                  | Yes  | Request information, including the authentication credential type and property list.|
A
Annie_wang 已提交
3902 3903 3904 3905 3906 3907 3908 3909
| callback | AsyncCallback&lt;[ExecutorProperty](#executorproperty8)&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the executor property information obtained. Otherwise, **err** is an error object.|

**Error codes**

| ID| Error Message                    |
| -------- | --------------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid request. |
A
Annie_wang 已提交
3910 3911 3912

**Example**
  ```js
A
Annie_wang 已提交
3913 3914 3915 3916 3917 3918 3919 3920 3921 3922
  let userAuth = new account_osAccount.UserAuth();
  let keys = [
    account_osAccount.GetPropertyType.AUTH_SUB_TYPE, 
    account_osAccount.GetPropertyType.REMAIN_TIMES,
    account_osAccount.GetPropertyType.FREEZING_TIME
  ];
  let request = {
    authType: account_osAccount.AuthType.PIN,
    keys: keys
  };
A
Annie_wang 已提交
3923 3924 3925 3926 3927 3928 3929 3930
  try {
    userAuth.getProperty(request, (err, result) => {
      console.log('getProperty err = ' + JSON.stringify(err));
      console.log('getProperty result = ' + JSON.stringify(result));
    });
  } catch (e) {
    console.log('getProperty exception = ' + JSON.stringify(e));
  }
A
Annie_wang 已提交
3931 3932 3933 3934
  ```

### getProperty<sup>8+</sup>

A
Annie_wang 已提交
3935
getProperty(request: GetPropertyRequest): Promise&lt;ExecutorProperty&gt;;
A
Annie_wang 已提交
3936 3937 3938

Obtains the executor property based on the request. This API uses a promise to return the result.

A
Annie_wang 已提交
3939
**System API**: This is a system API.
A
Annie_wang 已提交
3940 3941 3942 3943 3944 3945 3946 3947 3948

**System capability**: SystemCapability.Account.OsAccount

**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL

**Parameters**

| Name   | Type                                                  | Mandatory| Description                               |
| -------- | ------------------------------------------------------ | ---- | ---------------------------------- |
A
Annie_wang 已提交
3949
| request  | [GetPropertyRequest](#getpropertyrequest8) | Yes  | Request information, including the authentication credential type and property list.|
A
Annie_wang 已提交
3950 3951 3952 3953 3954

**Return value**

| Type                                                             | Description                                                |
| :---------------------------------------------------------------- | :-------------------------------------------------- |
A
Annie_wang 已提交
3955 3956 3957 3958 3959 3960 3961 3962
| Promise&lt;[ExecutorProperty](#executorproperty8)&gt; | Promise used to return the executor property information obtained.|

**Error codes**

| ID| Error Message                    |
| -------- | --------------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid request. |
A
Annie_wang 已提交
3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975

**Example**
  ```js
  let userAuth = new account_osAccount.UserAuth();
  let keys = [
    account_osAccount.GetPropertyType.AUTH_SUB_TYPE, 
    account_osAccount.GetPropertyType.REMAIN_TIMES,
    account_osAccount.GetPropertyType.FREEZING_TIME
  ];
  let request = {
    authType: account_osAccount.AuthType.PIN,
    keys: keys
  };
A
Annie_wang 已提交
3976 3977 3978 3979 3980 3981 3982 3983 3984
  try {
    userAuth.getProperty(request).then((result) => {
      console.log('getProperty result = ' + JSON.stringify(result));
    }).catch((err) => {
      console.log('getProperty error = ' + JSON.stringify(err));
    });
  } catch (e) {
    console.log('getProperty exception = ' + JSON.stringify(e));
  }
A
Annie_wang 已提交
3985 3986 3987 3988
  ```

### setProperty<sup>8+</sup>

A
Annie_wang 已提交
3989
setProperty(request: SetPropertyRequest, callback: AsyncCallback&lt;void&gt;): void;
A
Annie_wang 已提交
3990 3991 3992

Sets the property for the initialization algorithm. This API uses an asynchronous callback to return the result.

A
Annie_wang 已提交
3993
**System API**: This is a system API.
A
Annie_wang 已提交
3994 3995 3996 3997 3998 3999 4000 4001 4002

**System capability**: SystemCapability.Account.OsAccount

**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL

**Parameters**

| Name   | Type                                                 | Mandatory| Description                                                                   |
| -------- | ----------------------------------------------------- | ---- | ---------------------------------------------------------------------- |
A
Annie_wang 已提交
4003
| request  | [SetPropertyRequest](#setpropertyrequest8)| Yes  | Request information, including the authentication credential type and the key value to set.                                  |
A
Annie_wang 已提交
4004
| callback | AsyncCallback&lt;void&gt;                           | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|
A
Annie_wang 已提交
4005 4006 4007 4008 4009 4010 4011

**Error codes**

| ID| Error Message                    |
| -------- | --------------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid request. |
A
Annie_wang 已提交
4012 4013 4014

**Example**
  ```js
A
Annie_wang 已提交
4015 4016 4017 4018 4019 4020
  let userAuth = new account_osAccount.UserAuth();
  let request = {
    authType: account_osAccount.AuthType.PIN,
    key: account_osAccount.SetPropertyType.INIT_ALGORITHM,
    setInfo: new Uint8Array([0])
  };
A
Annie_wang 已提交
4021
  try {
A
Annie_wang 已提交
4022 4023 4024 4025 4026 4027
    userAuth.setProperty(request, (err) => {
      if (err) {
        console.log('setProperty failed, error = ' + JSON.stringify(err));
      } else {
        console.log('setProperty successfully');
      }
A
Annie_wang 已提交
4028 4029 4030 4031
    });
  } catch (e) {
    console.log('setProperty exception = ' + JSON.stringify(e));
  }
A
Annie_wang 已提交
4032 4033 4034 4035
  ```

### setProperty<sup>8+</sup>

A
Annie_wang 已提交
4036
setProperty(request: SetPropertyRequest): Promise&lt;void&gt;;
A
Annie_wang 已提交
4037 4038 4039

Sets the property for the initialization algorithm. This API uses a promise to return the result.

A
Annie_wang 已提交
4040
**System API**: This is a system API.
A
Annie_wang 已提交
4041 4042 4043 4044 4045 4046 4047

**System capability**: SystemCapability.Account.OsAccount

**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL

**Parameters**

A
Annie_wang 已提交
4048 4049
| Name   | Type                                      | Mandatory| Description                                     |
| -------- | ------------------------------------------ | ---- | ---------------------------------------- |
A
Annie_wang 已提交
4050
| request  | [SetPropertyRequest](#setpropertyrequest8) | Yes  | Request information, including the authentication credential type and the key value to set.|
A
Annie_wang 已提交
4051 4052 4053

**Return value**

A
Annie_wang 已提交
4054 4055
| Type                 | Description                                                          |
| :-------------------- | :------------------------------------------------------------ |
A
Annie_wang 已提交
4056
| Promise&lt;void&gt; | Promise that returns no value.|
A
Annie_wang 已提交
4057 4058 4059 4060 4061 4062 4063

**Error codes**

| ID| Error Message                    |
| -------- | --------------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid request. |
A
Annie_wang 已提交
4064 4065 4066

**Example**
  ```js
A
Annie_wang 已提交
4067 4068 4069 4070 4071 4072
  let userAuth = new account_osAccount.UserAuth();
  let request = {
    authType: account_osAccount.AuthType.PIN,
    key: account_osAccount.SetPropertyType.INIT_ALGORITHM,
    setInfo: new Uint8Array([0])
  };
A
Annie_wang 已提交
4073
  try {
A
Annie_wang 已提交
4074 4075
    userAuth.setProperty(request).then(() => {
      console.log('setProperty successfully');
A
Annie_wang 已提交
4076
    }).catch((err) => {
A
Annie_wang 已提交
4077
      console.log('setProperty failed, error = ' + JSON.stringify(err));
A
Annie_wang 已提交
4078 4079 4080 4081
    });
  } catch (e) {
    console.log('setProperty exception = ' + JSON.stringify(e));
  }
A
Annie_wang 已提交
4082 4083 4084 4085 4086 4087
  ```

### auth<sup>8+</sup>

auth(challenge: Uint8Array, authType: AuthType, authTrustLevel: AuthTrustLevel, callback: IUserAuthCallback): Uint8Array;

A
Annie_wang 已提交
4088
Performs authentication of the current user. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
4089

A
Annie_wang 已提交
4090
**System API**: This is a system API.
A
Annie_wang 已提交
4091 4092 4093 4094 4095 4096 4097

**System capability**: SystemCapability.Account.OsAccount

**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL

**Parameters**

A
Annie_wang 已提交
4098 4099 4100
| Name          | Type                                    | Mandatory| Description                               |
| --------------- | ---------------------------------------- | --- | ------------------------------------ |
| challenge       | Uint8Array                               | Yes | Challenge value, which is a random number used to improve security.|
A
Annie_wang 已提交
4101 4102
| authType        | [AuthType](#authtype8)                   | Yes | Authentication credential type.                       |
| authTrustLevel  | [AuthTrustLevel](#authtrustlevel8)       | Yes | Trust level of the authentication result.              |
A
Annie_wang 已提交
4103
| callback        | [IUserAuthCallback](#iuserauthcallback8) | Yes | Callback invoked to return the authentication result. |
A
Annie_wang 已提交
4104 4105 4106 4107

**Return value**

| Type       | Description              |
A
Annie_wang 已提交
4108
| ---------- | ------------------ |
A
Annie_wang 已提交
4109 4110
| Uint8Array | ID of the context for canceling the authentication.|

A
Annie_wang 已提交
4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123
**Error codes**

| ID| Error Message         |
| -------- | --------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid challenge or authType or authTrustLevel. |
| 12300101 | Credential is incorrect. |
| 12300105 | Unsupported authTrustLevel. |
| 12300106 | Unsupported authType. |
| 12300110 | Authentication locked. |
| 12300111 | Authentication timeout. |
| 12300112 | Authentication service busy. |

A
Annie_wang 已提交
4124 4125
**Example**
  ```js
A
Annie_wang 已提交
4126 4127 4128 4129
  let userAuth = new account_osAccount.UserAuth();
  let challenge = new Uint8Array([0]);
  let authType = account_osAccount.AuthType.PIN;
  let authTrustLevel = account_osAccount.AuthTrustLevel.ATL1;
A
Annie_wang 已提交
4130 4131 4132 4133 4134 4135 4136 4137 4138 4139
  try {
    userAuth.auth(challenge, authType, authTrustLevel, {
      onResult: function(result,extraInfo){
          console.log('auth result = ' + result);
          console.log('auth extraInfo = ' + JSON.stringify(extraInfo));
      }
    });
  } catch (e) {
    console.log('auth exception = ' + JSON.stringify(e));
  }
A
Annie_wang 已提交
4140 4141 4142 4143 4144 4145
  ```

### authUser<sup>8+</sup>

authUser(userId: number, challenge: Uint8Array, authType: AuthType, authTrustLevel: AuthTrustLevel, callback: IUserAuthCallback): Uint8Array;

A
Annie_wang 已提交
4146
Performs authentication of the specified user. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
4147

A
Annie_wang 已提交
4148
**System API**: This is a system API.
A
Annie_wang 已提交
4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159

**System capability**: SystemCapability.Account.OsAccount

**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL

**Parameters**

| Name          | Type                                                | Mandatory| Description                               |
| --------------- | ---------------------------------------------------- | --- | ------------------------------------ |
| userId          | number                                               | Yes | User ID.                       |
| challenge       | Uint8Array                                           | Yes | Challenge value, which is a random number used to improve security.                         |
A
Annie_wang 已提交
4160 4161
| authType        | [AuthType](#authtype8)                   | Yes | Authentication credential type.                       |
| authTrustLevel  | [AuthTrustLevel](#authtrustlevel8)       | Yes | Trust level of the authentication result.              |
A
Annie_wang 已提交
4162
| callback        | [IUserAuthCallback](#iuserauthcallback8) | Yes | Callback invoked to return the authentication result. |
A
Annie_wang 已提交
4163 4164 4165 4166

**Return value**

| Type       | Description              |
A
Annie_wang 已提交
4167
| ---------- | ------------------ |
A
Annie_wang 已提交
4168 4169
| Uint8Array | ID of the context for canceling the authentication.|

A
Annie_wang 已提交
4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182
**Error codes**

| ID| Error Message         |
| -------- | --------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid userId or challenge or authType or authTrustLevel. |
| 12300101 | Credential is incorrect. |
| 12300105 | Unsupported authTrustLevel. |
| 12300106 | Unsupported authType. |
| 12300110 | Authentication locked. |
| 12300111 | Authentication timeout. |
| 12300112 | Authentication service busy. |

A
Annie_wang 已提交
4183 4184
**Example**
  ```js
A
Annie_wang 已提交
4185
  let userAuth = new account_osAccount.UserAuth();
A
Annie_wang 已提交
4186
  let userID = 100;
A
Annie_wang 已提交
4187 4188 4189
  let challenge = new Uint8Array([0]);
  let authType = account_osAccount.AuthType.PIN;
  let authTrustLevel = account_osAccount.AuthTrustLevel.ATL1;
A
Annie_wang 已提交
4190 4191 4192
  try {
    userAuth.authUser(userID, challenge, authType, authTrustLevel, {
      onResult: function(result,extraInfo){
A
Annie_wang 已提交
4193 4194
        console.log('authUser result = ' + result);
        console.log('authUser extraInfo = ' + JSON.stringify(extraInfo));
A
Annie_wang 已提交
4195 4196 4197 4198 4199
      }
    });
  } catch (e) {
    console.log('authUser exception = ' + JSON.stringify(e));
  }
A
Annie_wang 已提交
4200 4201 4202 4203
  ```

### cancelAuth<sup>8+</sup>

A
Annie_wang 已提交
4204
cancelAuth(contextID: Uint8Array): void;
A
Annie_wang 已提交
4205

A
Annie_wang 已提交
4206
Cancels an authentication.
A
Annie_wang 已提交
4207

A
Annie_wang 已提交
4208
**System API**: This is a system API.
A
Annie_wang 已提交
4209 4210 4211 4212 4213 4214 4215 4216 4217

**System capability**: SystemCapability.Account.OsAccount

**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL

**Parameters**

| Name   | Type      | Mandatory | Description                                       |
| ----------| ---------- | ---- | ------------------------------------------ |
A
Annie_wang 已提交
4218
| contextId | Uint8Array | Yes  | ID of the authentication context. The context ID is dynamically generated.|
A
Annie_wang 已提交
4219

A
Annie_wang 已提交
4220
**Error codes**
A
Annie_wang 已提交
4221

A
Annie_wang 已提交
4222 4223 4224 4225
| ID| Error Message           |
| -------- | ------------------ |
| 12300001 | System service exception. |
| 12300002 | Invalid contextId. |
A
Annie_wang 已提交
4226 4227 4228

**Example**
  ```js
A
Annie_wang 已提交
4229 4230 4231
  let userAuth = new account_osAccount.UserAuth();
  let pinAuth = new account_osAccount.PINAuth();
  let challenge = new Uint8Array([0]);
A
Annie_wang 已提交
4232
  let contextId = userAuth.auth(challenge, account_osAccount.AuthType.PIN, account_osAccount.AuthTrustLevel.ATL1, {
A
Annie_wang 已提交
4233
    onResult: (result, extraInfo) => {
A
Annie_wang 已提交
4234 4235
      console.log('auth result = ' + result);
      console.log('auth extraInfo = ' + JSON.stringify(extraInfo));
A
Annie_wang 已提交
4236 4237
    }
  });
A
Annie_wang 已提交
4238 4239 4240 4241 4242
  try {
    userAuth.cancelAuth(contextId);
  } catch (e) {
    console.log('cancelAuth exception = ' + JSON.stringify(e));
  }
A
Annie_wang 已提交
4243 4244 4245 4246
  ```

## PINAuth<sup>8+</sup>

A
Annie_wang 已提交
4247 4248
Provides APIs for PIN authentication.

A
Annie_wang 已提交
4249
**System API**: This is a system API.
A
Annie_wang 已提交
4250 4251 4252 4253 4254 4255 4256

### constructor<sup>8+</sup>

constructor()

A constructor used to create an instance for PIN authentication.

A
Annie_wang 已提交
4257
**System API**: This is a system API.
A
Annie_wang 已提交
4258

A
Annie_wang 已提交
4259 4260
**System capability**: SystemCapability.Account.OsAccount

A
Annie_wang 已提交
4261
**Example** 
A
Annie_wang 已提交
4262
  ```js
A
Annie_wang 已提交
4263
  let pinAuth = new account_osAccount.PINAuth();
A
Annie_wang 已提交
4264 4265
  ```

A
Annie_wang 已提交
4266
### registerInputer<sup>8+</sup>
A
Annie_wang 已提交
4267

A
Annie_wang 已提交
4268
registerInputer(inputer: IInputer): void;
A
Annie_wang 已提交
4269

A
Annie_wang 已提交
4270
Register a PIN inputer.
A
Annie_wang 已提交
4271

A
Annie_wang 已提交
4272
**System API**: This is a system API.
A
Annie_wang 已提交
4273 4274 4275 4276 4277 4278 4279

**System capability**: SystemCapability.Account.OsAccount

**Required permissions**: ohos.permission.ACCESS_PIN_AUTH

**Parameters**

A
Annie_wang 已提交
4280 4281 4282
| Name   | Type                    | Mandatory| Description                     |
| ----------| ----------------------- | --- | -------------------------- |
| inputer   | [IInputer](#iinputer8)  | Yes | PIN inputer, which is used to obtain the PIN.|
A
Annie_wang 已提交
4283

A
Annie_wang 已提交
4284 4285 4286 4287 4288
**Error codes**

| ID| Error Message                    |
| -------- | --------------------------- |
| 12300001 | System service exception. |
A
Annie_wang 已提交
4289
| 12300102 | Invalid inputer. |
A
Annie_wang 已提交
4290 4291
| 12300103 | Inputer already registered. |

A
Annie_wang 已提交
4292 4293
**Example**
  ```js
A
Annie_wang 已提交
4294 4295
  let pinAuth = new account_osAccount.PINAuth();
  let password = new Uint8Array([0, 0, 0, 0, 0]);
A
Annie_wang 已提交
4296 4297
  try {
    let result = pinAuth.registerInputer({
A
Annie_wang 已提交
4298 4299
        onGetData: (authSubType, callback) => {
          callback.onSetData(authSubType, password);
A
Annie_wang 已提交
4300 4301 4302 4303 4304 4305
        }
    });
    console.log('registerInputer result = ' + result);
  } catch (e) {
    console.log('registerInputer exception = ' + JSON.stringify(e));
  }
A
Annie_wang 已提交
4306 4307
  ```

A
Annie_wang 已提交
4308
### unregisterInputer<sup>8+</sup>
A
Annie_wang 已提交
4309 4310 4311

unregisterInputer(): void;

A
Annie_wang 已提交
4312
Unregisters this PIN inputer.
A
Annie_wang 已提交
4313

A
Annie_wang 已提交
4314
**System API**: This is a system API.
A
Annie_wang 已提交
4315 4316 4317 4318 4319 4320 4321

**System capability**: SystemCapability.Account.OsAccount

**Required permissions**: ohos.permission.ACCESS_PIN_AUTH

**Example**
  ```js
A
Annie_wang 已提交
4322
  let pinAuth = new account_osAccount.PINAuth();
A
Annie_wang 已提交
4323 4324 4325
  pinAuth.unregisterInputer();
  ```

A
Annie_wang 已提交
4326
## InputerManager <sup>9+</sup>
A
Annie_wang 已提交
4327 4328 4329

Provides APIs for managing credential inputers.

A
Annie_wang 已提交
4330
### registerInputer<sup>9+</sup>
A
Annie_wang 已提交
4331

A
Annie_wang 已提交
4332
static registerInputer(authType: AuthType, inputer: IInputer): void
A
Annie_wang 已提交
4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362

Register a credential inputer.

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

**System capability**: SystemCapability.Account.OsAccount

**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL or ohos.permission.MANAGE_USER_IDM

**Parameters**

| Name   | Type                    | Mandatory| Description                     |
| ----------| ----------------------- | --- | -------------------------- |
| authType   | [AuthType](#authtype8)  | Yes | Authentication credential type.|
| inputer   | [IInputer](#iinputer8)  | Yes | Credential inputer to register.|

**Error codes**

| ID| Error Message                    |
| -------- | --------------------------- |
| 12300001 | System service exception. |
| 12300102 | Invalid authType or inputer. |
| 12300103 | The credential inputer has been registered. |
| 12300106 | Unsupported authType. |

**Example**
  ```js
  let authType = account_osAccount.AuthType.DOMAIN;
  let password = new Uint8Array([0, 0, 0, 0, 0]);
  try {
A
Annie_wang 已提交
4363
    account_osAccount.InputerManager.registerInputer(authType, {
A
Annie_wang 已提交
4364 4365 4366 4367 4368 4369 4370 4371 4372 4373
        onGetData: (authSubType, callback) => {
          callback.onSetData(authSubType, password);
        }
    });
    console.log('registerInputer success.');
  } catch (e) {
    console.log('registerInputer exception = ' + JSON.stringify(e));
  }
  ```

A
Annie_wang 已提交
4374
### unregisterInputer<sup>9+</sup>
A
Annie_wang 已提交
4375

A
Annie_wang 已提交
4376
static unregisterInputer(authType: AuthType): void
A
Annie_wang 已提交
4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401

Unregisters this credential inputer.

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

**System capability**: SystemCapability.Account.OsAccount

**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL or ohos.permission.MANAGE_USER_IDM

**Parameters**

| Name   | Type                    | Mandatory| Description                     |
| ----------| ----------------------- | --- | -------------------------- |
| authType   | [AuthType](#authtype8)  | Yes | Authentication credential type.|

**Error codes**

| ID| Error Message                    |
| -------- | --------------------------- |
| 12300002  | Invalid authType. |

**Example**
  ```js
  let authType = account_osAccount.AuthType.DOMAIN;
  try {
A
Annie_wang 已提交
4402
    account_osAccount.InputerManager.unregisterInputer(authType);
A
Annie_wang 已提交
4403 4404 4405 4406 4407 4408
    console.log('unregisterInputer success.');
  } catch(err) {
    console.log("unregisterInputer err:" + JSON.stringify(err));
  }
  ```

A
Annie_wang 已提交
4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522
## DomainPlugin<sup>9+</sup>

Provides APIs for domain account authentication.

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

### auth<sup>9+</sup>

auth(domainAccountInfo: DomainAccountInfo, credential: Uint8Array, callback: IUserAuthCallback): void

Authenticates a domain account.

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

**System capability**: SystemCapability.Account.OsAccount

**Parameters**

| Name     | Type                                   | Mandatory| Description            |
| ---------- | --------------------------------------- | ---- | --------------- |
| domainAccountInfo   | [DomainAccountInfo](#domainaccountinfo8)  | Yes  | Domain account information.|
| credential   | Uint8Array  | Yes  | Credentials of the domain account.|
| callback   | [IUserAuthCallback](#iuserauthcallback8)  | Yes  | Callback invoked to return the authentication result.|

**Example**
  ```js
  let plugin = {
    auth: (domainInfo, credential, callback) => {
      // mock authentication
      callback.onResult(0, {});
    }
  }
  account_osAccount.DomainAccountManager.registerPlugin(plugin);
  let userAuth = new account_osAccount.UserAuth();
  let challenge = new Uint8Array([0]);
  let authType = account_osAccount.AuthType.PIN;
  let authTrustLevel = account_osAccount.AuthTrustLevel.ATL1;
  try {
    userAuth.auth(challenge, authType, authTrustLevel, {
      onResult: (resultCode, authResult) => {
          console.log('auth resultCode = ' + resultCode);
          console.log('auth authResult = ' + JSON.stringify(authResult));
      }
    });
  } catch (err) {
    console.log('auth exception = ' + JSON.stringify(err));
  }
  ```

## DomainAccountManager <sup>9+</sup>
Provides APIs for domain account management.

### registerPlugin<sup>9+</sup>

static registerPlugin(plugin: DomainPlugin): void

Registers a domain plug-in.

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

**System capability**: SystemCapability.Account.OsAccount

**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

**Parameters**

| Name   | Type                    | Mandatory| Description                     |
| ----------| ----------------------- | --- | -------------------------- |
| plugin   | [DomainPlugin](#domainplugin9)  | Yes | Domain plug-in to register.|

**Error codes**

| ID| Error Message                    |
| -------- | --------------------------- |
| 12300201 | The domain plugin has been registered. |

**Example**
  ```js
  let plugin = {
    auth: (domainInfo, credential, callback) => {
      // mock authentication
      callback.onResult(0, {});
    }
  }
  try {
    account_osAccount.DomainAccountManager.registerPlugin(plugin);
    console.log('registerPlugin success.');
  } catch(err) {
    console.log("registerPlugin err:" + JSON.stringify(err));
  }
  ```

### unregisterPlugin<sup>9+</sup>

static unregisterPlugin(): void

Unregisters this domain plug-in.

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

**System capability**: SystemCapability.Account.OsAccount

**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

**Example**
  ```js
  try {
    account_osAccount.DomainAccountManager.unregisterPlugin();
    console.log('unregisterPlugin success.');
  } catch(err) {
    console.log("unregisterPlugin err:" + JSON.stringify(err));
  }
  ```

A
Annie_wang 已提交
4523 4524
## UserIdentityManager<sup>8+</sup>

A
Annie_wang 已提交
4525
Provides APIs for user identity management (IDM).
A
Annie_wang 已提交
4526

A
Annie_wang 已提交
4527
**System API**: This is a system API.
A
Annie_wang 已提交
4528 4529 4530 4531 4532

### constructor<sup>8+</sup>

constructor()

A
Annie_wang 已提交
4533
A constructor used to create an instance for user IDM.
A
Annie_wang 已提交
4534

A
Annie_wang 已提交
4535
**System API**: This is a system API.
A
Annie_wang 已提交
4536

A
Annie_wang 已提交
4537 4538
**System capability**: SystemCapability.Account.OsAccount

A
Annie_wang 已提交
4539
**Example** 
A
Annie_wang 已提交
4540
  ```js
A
Annie_wang 已提交
4541
  let userIDM = new account_osAccount.UserIdentityManager();
A
Annie_wang 已提交
4542 4543 4544 4545 4546 4547
  ```

### openSession<sup>8+</sup>

openSession(callback: AsyncCallback&lt;Uint8Array&gt;): void;

A
Annie_wang 已提交
4548
Opens a session to obtain the challenge value. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
4549

A
Annie_wang 已提交
4550
**System API**: This is a system API.
A
Annie_wang 已提交
4551 4552 4553 4554 4555 4556 4557

**System capability**: SystemCapability.Account.OsAccount

**Required permissions**: ohos.permission.MANAGE_USER_IDM

**Parameters**

A
Annie_wang 已提交
4558 4559 4560 4561 4562 4563 4564 4565 4566
| Name   | Type                            | Mandatory| Description                                                           |
| -------- | -------------------------------- | ---- | -------------------------------------------------------------- |
| callback | AsyncCallback&lt;Uint8Array&gt;  | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the challenge value obtained. Otherwise, **err** is an error object.|

**Error codes**

| ID| Error Message                    |
| -------- | --------------------------- |
| 12300001 | System service exception. |
A
Annie_wang 已提交
4567 4568 4569

**Example**
  ```js
A
Annie_wang 已提交
4570
  let userIDM = new account_osAccount.UserIdentityManager();
A
Annie_wang 已提交
4571 4572 4573 4574 4575 4576 4577 4578
  try {
    userIDM.openSession((err, challenge) => {
        console.log('openSession error = ' + JSON.stringify(err));
        console.log('openSession challenge = ' + JSON.stringify(challenge));
    });
  } catch (e) {
    console.log('openSession exception = ' + JSON.stringify(e));
  }
A
Annie_wang 已提交
4579 4580 4581 4582 4583 4584
  ```

### openSession<sup>8+</sup>

openSession(): Promise&lt;Uint8Array&gt;;

A
Annie_wang 已提交
4585
Opens a session to obtain the challenge value. This API uses a promise to return the result.
A
Annie_wang 已提交
4586

A
Annie_wang 已提交
4587
**System API**: This is a system API.
A
Annie_wang 已提交
4588 4589 4590 4591 4592 4593 4594

**System capability**: SystemCapability.Account.OsAccount

**Required permissions**: ohos.permission.MANAGE_USER_IDM

**Return value**

A
Annie_wang 已提交
4595 4596 4597 4598 4599 4600 4601 4602 4603
| Type                     | Description                    |
| :------------------------ | ----------------------- |
| Promise&lt;Uint8Array&gt; | Promise used to return the challenge value obtained.|

**Error codes**

| ID| Error Message                    |
| -------- | --------------------------- |
| 12300001 | System service exception. |
A
Annie_wang 已提交
4604 4605 4606

**Example**
  ```js
A
Annie_wang 已提交
4607
  let userIDM = new account_osAccount.UserIdentityManager();
A
Annie_wang 已提交
4608 4609 4610 4611 4612 4613 4614 4615 4616
  try {
    userIDM.openSession().then((challenge) => {
        console.info('openSession challenge = ' + JSON.stringify(challenge));
    }).catch((err) => {
        console.info('openSession error = ' + JSON.stringify(err));
    });
  } catch (e) {
    console.log('openSession exception = ' + JSON.stringify(e));
  }
A
Annie_wang 已提交
4617 4618 4619 4620 4621 4622
  ```

### addCredential<sup>8+</sup>

addCredential(credentialInfo: CredentialInfo, callback: IIdmCallback): void;

A
Annie_wang 已提交
4623
Adds credential information, including the credential type, subtype, and token (if a non-PIN credential is added).
A
Annie_wang 已提交
4624

A
Annie_wang 已提交
4625
**System API**: This is a system API.
A
Annie_wang 已提交
4626 4627 4628 4629 4630 4631 4632

**System capability**: SystemCapability.Account.OsAccount

**Required permissions**: ohos.permission.MANAGE_USER_IDM

**Parameters**

A
Annie_wang 已提交
4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645
| Name          | Type                                | Mandatory| Description                       |
| --------------- | ------------------------------------ | --- | ---------------------------- |
| credentialInfo  | [CredentialInfo](#credentialinfo8)   | Yes | Credential information to add.               |
| callback        | [IIdmCallback](#iidmcallback8)       | Yes | Callback invoked to return the result. |

**Error codes**

| ID| Error Message                    |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid credentialInfo, i.e. authType or authSubType. |
| 12300101 | Token is invalid. |
| 12300106 | Unsupported authType. |
A
Annie_wang 已提交
4646 4647 4648

**Example**
  ```js
A
Annie_wang 已提交
4649 4650 4651
  let password = new Uint8Array([0, 0, 0, 0, 0, 0]);
  let pinAuth = new account_osAccount.PINAuth();
  pinAuth.registerInputer({
A
Annie_wang 已提交
4652 4653
    onGetData: (authSubType, callback) => {
      callback.onSetData(authSubType, password);
A
Annie_wang 已提交
4654 4655 4656 4657 4658 4659 4660 4661 4662
    }
  });
  let credentialInfo = {
    credType: account_osAccount.AuthType.PIN,
    credSubType: account_osAccount.AuthSubType.PIN_SIX,
    token: null
  };
  let userIDM = new account_osAccount.UserIdentityManager();
  userIDM.openSession((err, challenge) => {
A
Annie_wang 已提交
4663
    try {
A
Annie_wang 已提交
4664 4665
    userIDM.addCredential(credentialInfo, {
      onResult: (result, extraInfo) => {
A
Annie_wang 已提交
4666 4667
        console.log('addCredential result = ' + result);
        console.log('addCredential extraInfo = ' + extraInfo);
A
Annie_wang 已提交
4668
      }
A
Annie_wang 已提交
4669
    });
A
Annie_wang 已提交
4670
    } catch (e) {
A
Annie_wang 已提交
4671
      console.log('addCredential exception = ' + JSON.stringify(e));
A
Annie_wang 已提交
4672
    }
A
Annie_wang 已提交
4673
  });
A
Annie_wang 已提交
4674 4675 4676 4677 4678 4679 4680 4681
  ```

### updateCredential<sup>8+</sup>

updateCredential(credentialInfo: CredentialInfo, callback: IIdmCallback): void;

Updates credential information. This API uses a callback to return the result.

A
Annie_wang 已提交
4682
**System API**: This is a system API.
A
Annie_wang 已提交
4683 4684 4685 4686 4687 4688 4689

**System capability**: SystemCapability.Account.OsAccount

**Required permissions**: ohos.permission.MANAGE_USER_IDM

**Parameters**

A
Annie_wang 已提交
4690 4691
| Name          | Type                                 | Mandatory| Description                    |
| --------------- | ------------------------------------- | --- | ------------------------- |
A
Annie_wang 已提交
4692
| credentialInfo  | [CredentialInfo](#credentialinfo8)    | Yes | New credential information.            |
A
Annie_wang 已提交
4693 4694 4695 4696 4697 4698 4699 4700 4701 4702
| callback        | [IIdmCallback](#iidmcallback8)        | Yes | Callback invoked to return the new credential information.|

**Error codes**

| ID| Error Message                    |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid credentialInfo, i.e. authType or authSubType or token. |
| 12300101 | Token is invalid. |
| 12300106 | Unsupported authType. |
A
Annie_wang 已提交
4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715

**Example**
  ```js
  let userIDM = new account_osAccount.UserIdentityManager();
  let userAuth = new account_osAccount.UserAuth();
  let pinAuth = new account_osAccount.PINAuth();
  let password = new Uint8Array([0, 0, 0, 0, 0, 0]);
  let credentialInfo = {
    credType: account_osAccount.AuthType.PIN,
    credSubType: account_osAccount.AuthSubType.PIN_SIX,
    token: null
  };
  pinAuth.registerInputer({
A
Annie_wang 已提交
4716 4717
    onGetData: (authSubType, callback) => {
      callback.onSetData(authSubType, password);
A
Annie_wang 已提交
4718 4719 4720 4721 4722 4723 4724 4725 4726
    }
  });
  userIDM.openSession((err, challenge) => {
    userAuth.auth(challenge, credentialInfo.credType, account_osAccount.AuthTrustLevel.ATL1, {
      onResult: (result, extraInfo) => {
        if (result != account_osAccount.ResultCode.SUCCESS) {
          return;
        }
        credentialInfo.token = extraInfo.token;
A
Annie_wang 已提交
4727 4728 4729 4730 4731 4732 4733 4734 4735 4736
        try {
          userIDM.updateCredential(credentialInfo, {
            onResult: (result, extraInfo) => {
                console.log('updateCredential result = ' + result);
                console.log('updateCredential extraInfo = ' + extraInfo);
            }
          });
        } catch (e) {
          console.log('updateCredential exception = ' + JSON.stringify(e));
        }
A
Annie_wang 已提交
4737
      }
A
Annie_wang 已提交
4738 4739
    });
  });
A
Annie_wang 已提交
4740 4741 4742 4743 4744 4745 4746 4747
  ```

### closeSession<sup>8+</sup>

closeSession(): void;

Closes this session to terminate IDM.

A
Annie_wang 已提交
4748
**System API**: This is a system API.
A
Annie_wang 已提交
4749 4750 4751 4752 4753 4754 4755

**System capability**: SystemCapability.Account.OsAccount

**Required permissions**: ohos.permission.MANAGE_USER_IDM

**Example**
  ```js
A
Annie_wang 已提交
4756
  let userIDM = new account_osAccount.UserIdentityManager();
A
Annie_wang 已提交
4757 4758 4759 4760 4761
  userIDM.closeSession();
  ```

### cancel<sup>8+</sup>

A
Annie_wang 已提交
4762
cancel(challenge: Uint8Array): void;
A
Annie_wang 已提交
4763 4764 4765

Cancels an entry based on the challenge value.

A
Annie_wang 已提交
4766
**System API**: This is a system API.
A
Annie_wang 已提交
4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777

**System capability**: SystemCapability.Account.OsAccount

**Required permissions**: ohos.permission.MANAGE_USER_IDM

**Parameters**

| Name   | Type       | Mandatory| Description  |
| -------- | ----------- | ---- | ----- |
| challenge | Uint8Array | Yes  | Challenge value.|

A
Annie_wang 已提交
4778
**Error codes**
A
Annie_wang 已提交
4779

A
Annie_wang 已提交
4780 4781 4782 4783
| ID| Error Message           |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid challenge. |
A
Annie_wang 已提交
4784 4785 4786

**Example**
  ```js
A
Annie_wang 已提交
4787 4788
  let userIDM = new account_osAccount.UserIdentityManager();
  let challenge = new Uint8Array([0]);
A
Annie_wang 已提交
4789 4790 4791 4792 4793
  try {
    userIDM.cancel(challenge);
  } catch(err) {
    console.log("cancel err:" + JSON.stringify(err));
  }
A
Annie_wang 已提交
4794 4795 4796 4797 4798 4799
  ```

### delUser<sup>8+</sup>

delUser(token: Uint8Array, callback: IIdmCallback): void;

A
Annie_wang 已提交
4800
Deletes a user based on the authentication token. This API uses a callback to return the result.
A
Annie_wang 已提交
4801

A
Annie_wang 已提交
4802
**System API**: This is a system API.
A
Annie_wang 已提交
4803 4804 4805 4806 4807 4808 4809

**System capability**: SystemCapability.Account.OsAccount

**Required permissions**: ohos.permission.MANAGE_USER_IDM

**Parameters**

A
Annie_wang 已提交
4810 4811 4812
| Name   | Type                          | Mandatory| Description                     |
| -------- | ------------------------------ | --- | ------------------------- |
| token    | Uint8Array                     | Yes | Authentication token.            |
A
Annie_wang 已提交
4813
| callback | [IIdmCallback](#iidmcallback8) | Yes | Callback invoked to return the result.|
A
Annie_wang 已提交
4814

A
Annie_wang 已提交
4815 4816 4817 4818 4819 4820 4821
**Error codes**

| ID| Error Message       |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300101 | Token is invalid. |

A
Annie_wang 已提交
4822 4823
**Example**
  ```js
A
Annie_wang 已提交
4824 4825
  let userIDM = new account_osAccount.UserIdentityManager();
  let token = new Uint8Array([0]);
A
Annie_wang 已提交
4826 4827 4828 4829 4830 4831 4832 4833 4834 4835
  try {
    userIDM.delUser(token, {
      onResult: (result, extraInfo) => {
        console.log('delUser result = ' + result);
        console.log('delUser extraInfo = ' + JSON.stringify(extraInfo));
      }
    });
  } catch (e) {
    console.log('delUser exception = ' + JSON.stringify(e));
  }
A
Annie_wang 已提交
4836 4837 4838 4839 4840 4841
  ```

### delCred<sup>8+</sup>

delCred(credentialId: Uint8Array, token: Uint8Array, callback: IIdmCallback): void;

A
Annie_wang 已提交
4842
Deletes user credential information.
A
Annie_wang 已提交
4843

A
Annie_wang 已提交
4844
**System API**: This is a system API.
A
Annie_wang 已提交
4845 4846 4847 4848 4849 4850 4851 4852

**System capability**: SystemCapability.Account.OsAccount

**Required permissions**: ohos.permission.MANAGE_USER_IDM

**Parameters**

| Name          | Type                                           | Mandatory| Description                     |
A
Annie_wang 已提交
4853 4854 4855
| --------------- | ----------------------------------- | --- | ---------------------------|
| credentialId    | Uint8Array                          | Yes | Credential ID.                 |
| token           | Uint8Array                          | Yes | Authentication token.              |
A
Annie_wang 已提交
4856
| callback        | [IIdmCallback](#iidmcallback8)      | Yes | Callback invoked to return the result.|
A
Annie_wang 已提交
4857

A
Annie_wang 已提交
4858 4859 4860 4861 4862 4863 4864 4865 4866
**Error codes**

| ID| Error Message            |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid credentialId. |
| 12300101 | Token is invalid. |
| 12300102 | Credential not found. |

A
Annie_wang 已提交
4867 4868
**Example**
  ```js
A
Annie_wang 已提交
4869 4870 4871
  let userIDM = new account_osAccount.UserIdentityManager();
  let credentialId = new Uint8Array([0]);
  let token = new Uint8Array([0]);
A
Annie_wang 已提交
4872 4873 4874 4875 4876 4877 4878 4879 4880 4881
  try {
    userIDM.delCred(credentialId, token, {
      onResult: (result, extraInfo) => {
          console.log('delCred result = ' + result);
          console.log('delCred extraInfo = ' + JSON.stringify(extraInfo));
      }
    });
  } catch (e) {
    console.log('delCred exception = ' + JSON.stringify(e));
  }
A
Annie_wang 已提交
4882 4883 4884 4885
  ```

### getAuthInfo<sup>8+</sup>

A
Annie_wang 已提交
4886
getAuthInfo(callback: AsyncCallback&lt;Array&lt;EnrolledCredInfo&gt;&gt;): void;
A
Annie_wang 已提交
4887

A
Annie_wang 已提交
4888
Obtains authentication information. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
4889

A
Annie_wang 已提交
4890
**System API**: This is a system API.
A
Annie_wang 已提交
4891 4892 4893

**System capability**: SystemCapability.Account.OsAccount

A
Annie_wang 已提交
4894 4895 4896 4897
**Required permissions**: ohos.permission.USE_USER_IDM

**Parameters**

A
Annie_wang 已提交
4898 4899
| Name   | Type                                                                    | Mandatory| Description                                                |
| -------- | ------------------------------------------------------------------------ | ---- | --------------------------------------------- |
A
Annie_wang 已提交
4900
| callback | AsyncCallback&lt;Array&lt;[EnrolledCredInfo](#enrolledcredinfo8)&gt;&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is information about all registered credentials of the user. Otherwise, **err** is an error object.|
A
Annie_wang 已提交
4901

A
Annie_wang 已提交
4902 4903 4904 4905 4906 4907
**Error codes**

| ID| Error Message              |
| -------- | --------------------- |
| 12300001 | System service exception. |
| 12300102 | Credential not found. |
A
Annie_wang 已提交
4908 4909 4910 4911

**Example**
  ```js
  let userIDM = new account_osAccount.UserIdentityManager();
A
Annie_wang 已提交
4912 4913 4914 4915 4916 4917 4918 4919
  try {
    userIDM.getAuthInfo((err, result) => {
      console.log('getAuthInfo err = ' + JSON.stringify(err));
      console.log('getAuthInfo result = ' + JSON.stringify(result));
    });
  } catch (e) {
    console.log('getAuthInfo exception = ' + JSON.stringify(e));
  }
A
Annie_wang 已提交
4920 4921 4922 4923 4924 4925 4926 4927
  ```

### getAuthInfo<sup>8+</sup>

getAuthInfo(authType: AuthType, callback: AsyncCallback&lt;Array&lt;EnrolledCredInfo&gt;&gt;): void;

Obtains authentication information of the specified type. This API uses an asynchronous callback to return the result.

A
Annie_wang 已提交
4928
**System API**: This is a system API.
A
Annie_wang 已提交
4929 4930 4931 4932

**System capability**: SystemCapability.Account.OsAccount

**Required permissions**: ohos.permission.USE_USER_IDM
A
Annie_wang 已提交
4933 4934 4935 4936 4937

**Parameters**

| Name   | Type                                              | Mandatory| Description                                               |
| -------- | -------------------------------------------------- | ---- | -------------------------------------------------- |
A
Annie_wang 已提交
4938
| authType | [AuthType](#authtype8) | Yes  | Authentication credential type.                                         |
A
Annie_wang 已提交
4939 4940 4941 4942 4943 4944 4945 4946 4947
| callback | AsyncCallback&lt;Array&lt;[EnrolledCredInfo](#enrolledcredinfo8)&gt;&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the information about all enrolled credentials of the specified type. Otherwise, **err** is an error object.|

**Error codes**

| ID| Error Message              |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid authType. |
| 12300102 | Credential not found. |
A
Annie_wang 已提交
4948 4949 4950

**Example**
  ```js
A
Annie_wang 已提交
4951
  let userIDM = new account_osAccount.UserIdentityManager();
A
Annie_wang 已提交
4952 4953 4954 4955 4956 4957 4958 4959
  try {
    userIDM.getAuthInfo(account_osAccount.AuthType.PIN, (err, result) => {
      console.log('getAuthInfo err = ' + JSON.stringify(err));
      console.log('getAuthInfo result = ' + JSON.stringify(result));
    });
  } catch (e) {
    console.log('getAuthInfo exception = ' + JSON.stringify(e));
  }
A
Annie_wang 已提交
4960 4961 4962 4963 4964 4965
  ```

### getAuthInfo<sup>8+</sup>

getAuthInfo(authType?: AuthType): Promise&lt;Array&lt;EnrolledCredInfo&gt;&gt;;

A
Annie_wang 已提交
4966
Obtains authentication information of the specified type. This API uses a promise to return the result.
A
Annie_wang 已提交
4967

A
Annie_wang 已提交
4968
**System API**: This is a system API.
A
Annie_wang 已提交
4969 4970 4971

**System capability**: SystemCapability.Account.OsAccount

A
Annie_wang 已提交
4972
**Required permissions**: ohos.permission.USE_USER_IDM
A
Annie_wang 已提交
4973 4974 4975 4976 4977

**Parameters**

| Name   | Type                               | Mandatory| Description     |
| -------- | ----------------------------------- | ---- | -------- |
A
Annie_wang 已提交
4978
| authType | [AuthType](#authtype8)              | No  | Authentication credential type.|
A
Annie_wang 已提交
4979 4980 4981

**Return value**

A
Annie_wang 已提交
4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992
| Type                                        | Description                                                                    |
| :------------------------------------------- | :----------------------------------------------------------------------- |
| Promise&lt;Array&lt;[EnrolledCredInfo](#enrolledcredinfo8)&gt;&gt; | Promise used to return the information about all the enrolled credentials of the specified type.|

**Error codes**

| ID| Error Message              |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid authType. |
| 12300102 | Credential not found. |
A
Annie_wang 已提交
4993 4994 4995

**Example**
  ```js
A
Annie_wang 已提交
4996
  let userIDM = new account_osAccount.UserIdentityManager();
A
Annie_wang 已提交
4997 4998 4999 5000 5001 5002 5003 5004 5005
  try {
    userIDM.getAuthInfo(account_osAccount.AuthType.PIN).then((result) => {
      console.log('getAuthInfo result = ' + JSON.stringify(result))
    }).catch((err) => {
      console.log('getAuthInfo error = ' + JSON.stringify(err));
    });
  } catch (e) {
    console.log('getAuthInfo exception = ' + JSON.stringify(e));
  }
A
Annie_wang 已提交
5006 5007 5008 5009 5010 5011
  ```

## IInputData<sup>8+</sup>

Provides callbacks for PIN operations.

A
Annie_wang 已提交
5012
**System API**: This is a system API.
A
Annie_wang 已提交
5013

A
Annie_wang 已提交
5014 5015
### onSetData<sup>8+</sup>

A
Annie_wang 已提交
5016
onSetData: (authSubType: AuthSubType, data: Uint8Array) => void;
A
Annie_wang 已提交
5017

A
Annie_wang 已提交
5018
**System API**: This is a system API.
A
Annie_wang 已提交
5019

A
Annie_wang 已提交
5020
Called to set data in a PIN operation.
A
Annie_wang 已提交
5021 5022 5023 5024 5025 5026 5027

**System capability**: SystemCapability.Account.OsAccount

**Parameters**

| Name     | Type                                    | Mandatory| Description                                           |
| ---------- | ---------------------------------------- | ---- | ----------------------------------------------- |
A
Annie_wang 已提交
5028
| authSubType | [AuthSubType](#authsubtype8)             | Yes  | Credential subtype.                           |
A
Annie_wang 已提交
5029 5030 5031 5032
| data       | Uint8Array                               | Yes  | Data (credential) to set. The data is used for authentication and operations for adding and modifying credentials.|

**Example**
  ```js
A
Annie_wang 已提交
5033 5034 5035
  let password = new Uint8Array([0, 0, 0, 0, 0, 0]);
  let passwordNumber = new Uint8Array([1, 2, 3, 4]);
  let inputer = {
A
Annie_wang 已提交
5036 5037 5038
    onGetData: (authSubType, callback) => {
        if (authSubType == account_osAccount.AuthSubType.PIN_NUMBER) {
          callback.onSetData(authSubType, passwordNumber);
A
Annie_wang 已提交
5039
        } else {
A
Annie_wang 已提交
5040
          callback.onSetData(authSubType, password);
A
Annie_wang 已提交
5041 5042 5043
        }
    }
  };
A
Annie_wang 已提交
5044 5045 5046 5047
  ```

## IInputer<sup>8+</sup>

A
Annie_wang 已提交
5048
Provides callbacks for credential inputers.
A
Annie_wang 已提交
5049

A
Annie_wang 已提交
5050
**System API**: This is a system API.
A
Annie_wang 已提交
5051

A
Annie_wang 已提交
5052 5053
### onGetData<sup>8+</sup>

A
Annie_wang 已提交
5054
onGetData: (authSubType: AuthSubType, callback: IInputData) => void;
A
Annie_wang 已提交
5055 5056 5057

Called to obtain data.

A
Annie_wang 已提交
5058
**System API**: This is a system API.
A
Annie_wang 已提交
5059

A
Annie_wang 已提交
5060 5061 5062 5063 5064 5065
**System capability**: SystemCapability.Account.OsAccount

**Parameters**

| Name     | Type                                   | Mandatory| Description            |
| ---------- | --------------------------------------- | ---- | --------------- |
A
Annie_wang 已提交
5066 5067 5068 5069 5070 5071 5072
| callback   | [IInputData](#iinputdata8)  | Yes  | Called to input the PIN.|

**Example**
  ```js
  let password = new Uint8Array([0, 0, 0, 0, 0, 0]);
  let passwordNumber = new Uint8Array([1, 2, 3, 4]);
  let inputer = {
A
Annie_wang 已提交
5073 5074 5075
    onGetData: (authSubType, callback) => {
        if (authSubType == account_osAccount.AuthSubType.PIN_NUMBER) {
          callback.onSetData(authSubType, passwordNumber);
A
Annie_wang 已提交
5076
        } else {
A
Annie_wang 已提交
5077
          callback.onSetData(authSubType, password);
A
Annie_wang 已提交
5078 5079 5080 5081 5082
        }
    }
  };
  let pinAuth = new account_osAccount.PINAuth();
  let result = pinAuth.registerInputer(inputer);
A
Annie_wang 已提交
5083
  console.log('registerInputer result: ' + result);
A
Annie_wang 已提交
5084 5085 5086 5087 5088 5089
  ```

## IUserAuthCallback<sup>8+</sup>

Provides callbacks for user authentication.

A
Annie_wang 已提交
5090
**System API**: This is a system API.
A
Annie_wang 已提交
5091

A
Annie_wang 已提交
5092 5093 5094 5095
### onResult<sup>8+</sup>

onResult: (result: number, extraInfo: AuthResult) => void;

A
Annie_wang 已提交
5096
Called to return the result code and authentication result.
A
Annie_wang 已提交
5097

A
Annie_wang 已提交
5098
**System API**: This is a system API.
A
Annie_wang 已提交
5099

A
Annie_wang 已提交
5100 5101 5102 5103 5104 5105 5106
**System capability**: SystemCapability.Account.OsAccount

**Parameters**

| Name    | Type                                   | Mandatory| Description                |
| --------- | --------------------------------------- | ---- | ------------------- |
| result    | number                                   | Yes  | Authentication result code.|
A
Annie_wang 已提交
5107
| extraInfo | [AuthResult](#authresult8)  | Yes  | Specific authentication result information. If the authentication is successful, the authentication token is returned in **extrainfo**. If the authentication fails, the remaining authentication time is returned. If the authentication executor is locked, the freezing time is returned.|
A
Annie_wang 已提交
5108 5109 5110

**Example**
  ```js
A
Annie_wang 已提交
5111 5112
  let authCallback = {
    onResult: (result, extraInfo) => {
A
Annie_wang 已提交
5113 5114
      console.log('auth result = ' + result);
      console.log('auth extraInfo = ' + JSON.stringify(extraInfo));
A
Annie_wang 已提交
5115 5116
    }
  };
A
Annie_wang 已提交
5117 5118 5119 5120 5121 5122
  ```

### onAcquireInfo?<sup>8+</sup>

onAcquireInfo?: (module: number, acquire: number, extraInfo: any) => void;

A
Annie_wang 已提交
5123
Called to acquire identity authentication information.
A
Annie_wang 已提交
5124

A
Annie_wang 已提交
5125
**System API**: This is a system API.
A
Annie_wang 已提交
5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138

**System capability**: SystemCapability.Account.OsAccount

**Parameters**

| Name   | Type    | Mandatory| Description                          |
| --------- | ------- | ---- | ----------------------------- |
| module    | number  | Yes  | Type of authentication executor.  |
| acquire   | number  | Yes  | Tip code of the authentication executor.|
| extraInfo | any     | Yes  | Reserved.                    |

**Example**
  ```js
A
Annie_wang 已提交
5139 5140
  let authCallback = {
    onResult: (result, extraInfo) => {
A
Annie_wang 已提交
5141 5142
      console.log('auth result = ' + result)
      console.log('auth extraInfo = ' + JSON.stringify(extraInfo));
A
Annie_wang 已提交
5143 5144
    },
    onAcquireInfo: (module, acquire, extraInfo) => {
A
Annie_wang 已提交
5145 5146
      console.log('auth module = ' + module);
      console.log('auth acquire = ' + acquire);
A
Annie_wang 已提交
5147 5148 5149
      console.info('auth extraInfo = ' + JSON.stringify(extraInfo));
    }
  };
A
Annie_wang 已提交
5150 5151 5152 5153 5154 5155
  ```

## IIdmCallback<sup>8+</sup>

Provides callbacks for IDM.

A
Annie_wang 已提交
5156
**System API**: This is a system API.
A
Annie_wang 已提交
5157

A
Annie_wang 已提交
5158 5159
### onResult<sup>8+</sup>

A
Annie_wang 已提交
5160
onResult: (result: number, extraInfo: RequestResult) => void;
A
Annie_wang 已提交
5161

A
Annie_wang 已提交
5162
Called to return the result code and request result information.
A
Annie_wang 已提交
5163

A
Annie_wang 已提交
5164
**System API**: This is a system API.
A
Annie_wang 已提交
5165 5166 5167 5168 5169 5170 5171 5172

**System capability**: SystemCapability.Account.OsAccount

**Parameters**

| Name    | Type                                   | Mandatory| Description                    |
| --------- | --------------------------------------- | ---- | ----------------------- |
| result    | number                                  | Yes  | Authentication result code.   |
A
Annie_wang 已提交
5173
| extraInfo | [RequestResult](#requestresult8)  | Yes  | Specific information to be transferred.|
A
Annie_wang 已提交
5174 5175 5176

**Example**
  ```js
A
Annie_wang 已提交
5177
  let idmCallback = {
A
Annie_wang 已提交
5178
    onResult: (result, extraInfo) => {
A
Annie_wang 已提交
5179
      console.log('callback result = ' + result)
A
Annie_wang 已提交
5180 5181 5182
      console.info('callback extraInfo = ' + JSON.stringify(extraInfo));
    }
  };
A
Annie_wang 已提交
5183 5184 5185 5186 5187 5188
  ```

### onAcquireInfo?<sup>8+</sup>

onAcquireInfo?: (module: number, acquire: number, extraInfo: any) => void;

A
Annie_wang 已提交
5189
Called to acquire IDM information.
A
Annie_wang 已提交
5190

A
Annie_wang 已提交
5191
**System API**: This is a system API.
A
Annie_wang 已提交
5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204

**System capability**: SystemCapability.Account.OsAccount

**Parameters**

| Name   | Type    | Mandatory| Description                          |
| --------- | ------- | ---- | ----------------------------- |
| module    | number  | Yes  | Type of authentication executor.  |
| acquire   | number  | Yes  | Tip code of the authentication executor.|
| extraInfo | any     | Yes  | Reserved.                    |

**Example**
  ```js
A
Annie_wang 已提交
5205 5206
  let idmCallback = {
    onResult: (result, extraInfo) => {
A
Annie_wang 已提交
5207 5208
      console.log('callback result = ' + result)
      console.log('callback onResult = ' + JSON.stringify(extraInfo));
A
Annie_wang 已提交
5209 5210
    },
    onAcquireInfo: (module, acquire, extraInfo) => {
A
Annie_wang 已提交
5211 5212
      console.log('callback module = ' + module);
      console.log('callback acquire = ' + acquire);
A
Annie_wang 已提交
5213 5214 5215
      console.log('callback onacquireinfo = ' + JSON.stringify(extraInfo));
    }
  };
A
Annie_wang 已提交
5216 5217 5218 5219 5220 5221
  ```

## GetPropertyRequest<sup>8+</sup>

Defines the request for obtaining property information.

A
Annie_wang 已提交
5222
**System API**: This is a system API.
A
Annie_wang 已提交
5223

A
Annie_wang 已提交
5224 5225 5226 5227
**System capability**: SystemCapability.Account.OsAccount

| Name   | Type                                                         | Mandatory  | Description                  |
| -------- | ------------------------------------------------------------- | ----- | ----------------------- |
A
Annie_wang 已提交
5228 5229
| authType | [AuthType](#authtype8)                            | Yes   | Authentication credential type.       |
| keys     | Array&lt;[GetPropertyType](#getpropertytype8)&gt; | Yes   | An array of the types of the properties to obtain.|
A
Annie_wang 已提交
5230 5231 5232 5233 5234

## SetPropertyRequest<sup>8+</sup>

Defines the request for setting property information.

A
Annie_wang 已提交
5235
**System API**: This is a system API.
A
Annie_wang 已提交
5236

A
Annie_wang 已提交
5237 5238 5239 5240
**System capability**: SystemCapability.Account.OsAccount

| Name   | Type                                            | Mandatory  | Description                |
| -------- | ------------------------------------------------ | ----- | -------------------- |
A
Annie_wang 已提交
5241 5242
| authType | [AuthType](#authtype8)               | Yes   | Authentication credential type.    |
| key     | [SetPropertyType](#setpropertytype8) | Yes   | Type of the property to set.|
A
Annie_wang 已提交
5243 5244 5245 5246 5247 5248
| setInfo  | Uint8Array                                       | Yes   | Information to set.    |

## ExecutorProperty<sup>8+</sup>

Defines the executor property.

A
Annie_wang 已提交
5249
**System API**: This is a system API.
A
Annie_wang 已提交
5250

A
Annie_wang 已提交
5251 5252 5253 5254 5255
**System capability**: SystemCapability.Account.OsAccount

| Name       | Type                                    | Mandatory  | Description             |
| ------------ | ---------------------------------------- | ----- | ----------------- |
| result       | number                                   | Yes   | Result.        |
A
Annie_wang 已提交
5256
| authSubType  | [AuthSubType](#authsubtype8) | Yes   | Authentication credential subtype.|
A
Annie_wang 已提交
5257 5258 5259 5260 5261 5262 5263
| remainTimes  | number                                   | No   | Remaining time.    |
| freezingTime | number                                   | No   | Freezing time.    |

## AuthResult<sup>8+</sup>

Defines the authentication result information.

A
Annie_wang 已提交
5264
**System API**: This is a system API.
A
Annie_wang 已提交
5265

A
Annie_wang 已提交
5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277
**System capability**: SystemCapability.Account.OsAccount

| Name       | Type       | Mandatory  | Description             |
| ------------ | ----------- | ----- | ----------------- |
| token        | Uint8Array  | No   | Authentication token.    |
| remainTimes  | number      | No   | Remaining time.    |
| freezingTime | number      | No   | Freezing time.    |

## CredentialInfo<sup>8+</sup>

Defines the credential information.

A
Annie_wang 已提交
5278
**System API**: This is a system API.
A
Annie_wang 已提交
5279

A
Annie_wang 已提交
5280 5281 5282 5283
**System capability**: SystemCapability.Account.OsAccount

| Name       | Type                                    | Mandatory  | Description             |
| ------------ | ---------------------------------------- | ----- | ----------------- |
A
Annie_wang 已提交
5284 5285
| credType     | [AuthType](#authtype8)       | Yes   | Authentication credential type.    |
| credSubType  | [AuthSubType](#authsubtype8) | Yes   | Authentication credential subtype.  |
A
Annie_wang 已提交
5286
| token        | Uint8Array                           | Yes   | Authentication token.    |
A
Annie_wang 已提交
5287 5288 5289 5290 5291

## RequestResult<sup>8+</sup>

Defines the request result information.

A
Annie_wang 已提交
5292
**System API**: This is a system API.
A
Annie_wang 已提交
5293

A
Annie_wang 已提交
5294 5295 5296 5297 5298 5299 5300 5301 5302 5303
**System capability**: SystemCapability.Account.OsAccount

| Name       | Type       | Mandatory  | Description             |
| ------------ | ----------- | ----- | ----------------- |
| credentialId | Uint8Array  | No   | Credential ID.    |

## EnrolledCredInfo<sup>8+</sup>

Defines enrolled credential information.

A
Annie_wang 已提交
5304
**System API**: This is a system API.
A
Annie_wang 已提交
5305

A
Annie_wang 已提交
5306 5307 5308 5309 5310
**System capability**: SystemCapability.Account.OsAccount

| Name       | Type                                    | Mandatory  | Description             |
| ------------ | ---------------------------------------- | ----- | ------------------- |
| credentialId | Uint8Array                               | Yes   | Credential ID.      |
A
Annie_wang 已提交
5311 5312 5313
| authType     | [AuthType](#authtype8)       | Yes   | Authentication credential type.  |
| authSubType  | [AuthSubType](#authsubtype8) | Yes   | Credential subtype.|
| templateId   | Uint8Array                               | Yes   | Authentication credential template ID.    |
A
Annie_wang 已提交
5314 5315 5316

## GetPropertyType<sup>8+</sup>

A
Annie_wang 已提交
5317
Enumerates the types of properties to obtain.
A
Annie_wang 已提交
5318

A
Annie_wang 已提交
5319
**System API**: This is a system API.
A
Annie_wang 已提交
5320

A
Annie_wang 已提交
5321 5322
**System capability**: SystemCapability.Account.OsAccount

A
Annie_wang 已提交
5323
| Name          | Value| Description     |
A
Annie_wang 已提交
5324
| ------------- | ------ | --------- |
A
Annie_wang 已提交
5325
| AUTH_SUB_TYPE | 1      | Authentication credential subtype.|
A
Annie_wang 已提交
5326 5327 5328 5329 5330
| REMAIN_TIMES  | 2      | Remaining time.  |
| FREEZING_TIME | 3      | Freezing time.  |

## SetPropertyType<sup>8+</sup>

A
Annie_wang 已提交
5331
Enumerates the types of properties to set.
A
Annie_wang 已提交
5332

A
Annie_wang 已提交
5333
**System API**: This is a system API.
A
Annie_wang 已提交
5334

A
Annie_wang 已提交
5335 5336
**System capability**: SystemCapability.Account.OsAccount

A
Annie_wang 已提交
5337
| Name          | Value| Description       |
A
Annie_wang 已提交
5338 5339 5340 5341 5342
| -------------- | ----- | ----------- |
| INIT_ALGORITHM | 1     | Initialization algorithm.|

## AuthType<sup>8+</sup>

A
Annie_wang 已提交
5343 5344
Enumerates the authentication credential types.

A
Annie_wang 已提交
5345
**System API**: This is a system API.
A
Annie_wang 已提交
5346 5347 5348

**System capability**: SystemCapability.Account.OsAccount

A
Annie_wang 已提交
5349
| Name | Value| Description            |
A
Annie_wang 已提交
5350 5351 5352
| ----- | ----- | ---------------- |
| PIN   | 1     | PIN authentication.|
| FACE  | 2     | Facial authentication.|
A
Annie_wang 已提交
5353 5354
| FINGERPRINT<sup>10+</sup>   | 4     | Fingerprint authentication.|
| DOMAIN<sup>10+</sup>  | 1024     | Domain authentication.|
A
Annie_wang 已提交
5355 5356 5357

## AuthSubType<sup>8+</sup>

A
Annie_wang 已提交
5358 5359
Enumerates the authentication credential subtypes.

A
Annie_wang 已提交
5360
**System API**: This is a system API.
A
Annie_wang 已提交
5361 5362 5363

**System capability**: SystemCapability.Account.OsAccount

A
Annie_wang 已提交
5364
| Name      | Value| Description              |
A
Annie_wang 已提交
5365 5366 5367
| ---------- | ----- | ------------------ |
| PIN_SIX    | 10000 | Six-digit PIN.      |
| PIN_NUMBER | 10001 | Custom PIN.|
A
Annie_wang 已提交
5368
| PIN_MIXED  | 10002 | Custom mixed credentials.|
A
Annie_wang 已提交
5369 5370
| FACE_2D    | 20000 | 2D face credential.  |
| FACE_3D    | 20001 | 3D face credential.  |
A
Annie_wang 已提交
5371
| DOMAIN_MIXED<sup>10+</sup>    | 10240001 | Mixed domain authentication credentials.  |
A
Annie_wang 已提交
5372 5373 5374 5375 5376

## AuthTrustLevel<sup>8+</sup>

Enumerates the trust levels of the authentication result.

A
Annie_wang 已提交
5377
**System API**: This is a system API.
A
Annie_wang 已提交
5378

A
Annie_wang 已提交
5379 5380
**System capability**: SystemCapability.Account.OsAccount

A
Annie_wang 已提交
5381
| Name | Value| Description       |
A
Annie_wang 已提交
5382 5383 5384 5385 5386 5387 5388 5389 5390 5391
| ---- | ------ | ----------- |
| ATL1 | 10000  | Trust level 1.|
| ATL2 | 20000  | Trust level 2.|
| ATL3 | 30000  | Trust level 3.|
| ATL4 | 40000  | Trust level 4.|

## Module<sup>8+</sup>

Enumerates the modules from which information is obtained.

A
Annie_wang 已提交
5392
**System API**: This is a system API.
A
Annie_wang 已提交
5393

A
Annie_wang 已提交
5394 5395
**System capability**: SystemCapability.Account.OsAccount

A
Annie_wang 已提交
5396
| Name      | Value| Description                    |
A
Annie_wang 已提交
5397
| --------- | ------ | ------------------------ |
A
Annie_wang 已提交
5398
| FACE_AUTH | 1      | Facial authentication module.|
A
Annie_wang 已提交
5399 5400 5401 5402 5403

## ResultCode<sup>8+</sup>

Enumerates the authentication result codes.

A
Annie_wang 已提交
5404
**System API**: This is a system API.
A
Annie_wang 已提交
5405

A
Annie_wang 已提交
5406 5407
**System capability**: SystemCapability.Account.OsAccount

A
Annie_wang 已提交
5408
| Name                   | Value| Description                                    |
A
Annie_wang 已提交
5409
| ----------------------- | ----- | ---------------------------------------- |
A
Annie_wang 已提交
5410
| SUCCESS                 | 0     | The authentication is successful or the authentication feature is supported.            |
A
Annie_wang 已提交
5411 5412 5413 5414 5415 5416
| FAIL                    | 1     | The authentication executor failed to identify the user.                  |
| GENERAL_ERROR           | 2     | Other errors.                           |
| CANCELED                | 3     | The authentication is canceled.                      |
| TIMEOUT                 | 4     | The authentication timed out.                      |
| TYPE_NOT_SUPPORT        | 5     | The authentication credential type is not supported.                |
| TRUST_LEVEL_NOT_SUPPORT | 6     | The authentication trust level is not supported.              |
A
Annie_wang 已提交
5417
| BUSY                    | 7     | The authentication executor is busy. Try again after a few seconds.|
A
Annie_wang 已提交
5418 5419 5420 5421 5422 5423 5424 5425
| INVALID_PARAMETERS      | 8     | Incorrect parameters are detected.                         |
| LOCKED                  | 9     | The authentication executor is locked.                    |
| NOT_ENROLLED            | 10    | The authentication executor is not enrolled.                  |

## FaceTipsCode<sup>8+</sup>

Enumerates the tip codes for facial authentication.

A
Annie_wang 已提交
5426
**System API**: This is a system API.
A
Annie_wang 已提交
5427

A
Annie_wang 已提交
5428 5429
**System capability**: SystemCapability.Account.OsAccount

A
Annie_wang 已提交
5430
| Name                         | Value| Description                                    |
A
Annie_wang 已提交
5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443
| ----------------------------- | ----- | ---------------------------------------- |
| FACE_AUTH_TIP_TOO_BRIGHT      | 1     | The obtained face image is too bright.        |
| FACE_AUTH_TIP_TOO_DARK        | 2     | The obtained face image is too dark.      |
| FACE_AUTH_TIP_TOO_CLOSE       | 3     | The face is too close to the device.                      |
| FACE_AUTH_TIP_TOO_FAR         | 4     | The face is too far away from the device.                      |
| FACE_AUTH_TIP_TOO_HIGH        | 5     | Only the upper part of the face is captured because the device is angled too high.             |
| FACE_AUTH_TIP_TOO_LOW         | 6     | Only the lower part of the face is captured because the device is angled too low.             |
| FACE_AUTH_TIP_TOO_RIGHT       | 7     | Only the right part of the face is captured because the device is angled too much to the right.|
| FACE_AUTH_TIP_TOO_LEFT        | 8     | Only the left part of the face is captured because the device is angled too much to the left.|
| FACE_AUTH_TIP_TOO_MUCH_MOTION | 9     | The face moves too fast during facial information collection.        |
| FACE_AUTH_TIP_POOR_GAZE       | 10    | The face is not facing the device.                        |
| FACE_AUTH_TIP_NOT_DETECTED    | 11    | No face is detected.                        |

Z
zengyawen 已提交
5444
## FingerprintTips<sup>8+</sup>
A
Annie_wang 已提交
5445 5446 5447

Enumerates the tip codes for fingerprint authentication.

A
Annie_wang 已提交
5448
**System API**: This is a system API.
A
Annie_wang 已提交
5449

A
Annie_wang 已提交
5450 5451
**System capability**: SystemCapability.Account.OsAccount

A
Annie_wang 已提交
5452
| Name                         | Value| Description                                           |
A
Annie_wang 已提交
5453 5454 5455 5456 5457 5458 5459 5460
| ----------------------------- | ----- | ----------------------------------------------- |
| FINGERPRINT_TIP_GOOD          | 0     | The captured image is clear.                             |
| FINGERPRINT_TIP_IMAGER_DIRTY  | 1     | The fingerprint image has big noise due to dirt on the sensor.|
| FINGERPRINT_TIP_INSUFFICIENT  | 2     | Failed to process the fingerprint image due to big noise.  |
| FINGERPRINT_TIP_PARTIAL       | 3     | Only part of the fingerprint image is detected.                        |
| FINGERPRINT_TIP_TOO_FAST      | 4     | The fingerprint image is incomplete due to quick motion.                 |
| FINGERPRINT_TIP_TOO_SLOW      | 5     | Failed to read the fingerprint image due to lack of motion.               |

A
annie_wangli 已提交
5461
## OsAccountInfo
A
annie_wangli 已提交
5462

A
Annie_wang 已提交
5463
Defines the OS account information.
A
annie_wangli 已提交
5464 5465 5466

**System capability**: SystemCapability.Account.OsAccount

A
annie_wangli 已提交
5467 5468 5469 5470 5471 5472
| Name                        | Type                                                        | Mandatory| Description                             |
| ------------------------------ | ------------------------------------------------------------ | ---- | --------------------------------- |
| localId                        | number                                                       | Yes  | ID of the target OS account.                     |
| localName                      | string                                                       | Yes  | OS account name.                   |
| type                           | [OsAccountType](#osaccounttype)                              | Yes  | OS account type.                     |
| constraints                    | Array&lt;string&gt;                                          | No  | [Constraints](#constraints) on the OS account.|
Z
zhangalong 已提交
5473 5474 5475 5476 5477 5478 5479
| isVerified<sup>8+</sup>        | boolean                                                      | Yes  | Whether the OS account is verified.                     |
| photo<sup>8+</sup>             | string                                                       | No  | Profile photo of the OS account.                     |
| createTime<sup>8+</sup>        | number                                                       | Yes  | Time when the OS account was created.                 |
| lastLoginTime<sup>8+</sup>     | number                                                       | No  | Last login time of the OS account.         |
| serialNumber<sup>8+</sup>      | number                                                       | Yes  | SN of the OS account.                     |
| isActived<sup>8+</sup>         | boolean                                                      | Yes  | Whether the OS account is activated.                 |
| isCreateCompleted<sup>8+</sup> | boolean                                                      | Yes  | Whether the OS account information is complete.             |
A
annie_wangli 已提交
5480
| distributedInfo                | [distributedAccount.DistributedInfo](js-apis-distributed-account.md) | No  | Distributed account information.                   |
A
Annie_wang 已提交
5481
| domainInfo<sup>8+</sup>        | [DomainAccountInfo](#domainaccountinfo8)                      | No  | Domain account information.                       |
A
annie_wangli 已提交
5482

Z
zhangalong 已提交
5483
## DomainAccountInfo<sup>8+</sup>
A
annie_wangli 已提交
5484

A
Annie_wang 已提交
5485
Defines the domain account information.
A
annie_wangli 已提交
5486 5487 5488 5489 5490

**System capability**: SystemCapability.Account.OsAccount

| Name     | Type  | Mandatory| Description      |
| ----------- | ------ | ---- | ---------- |
A
annie_wangli 已提交
5491
| domain      | string | Yes  | Domain name.    |
A
annie_wangli 已提交
5492
| accountName | string | Yes  | Domain account name.|
A
annie_wangli 已提交
5493 5494 5495

## Constraints

A
annie_wangli 已提交
5496 5497
| Constraint                                 | Description                          |
| ------------------------------------- | ------------------------------ |
A
Annie_wang 已提交
5498 5499
| constraint.wifi                       | A user is not allowed to use Wi-Fi.                 |
| constraint.wifi.set                   | A user is not allowed to set Wi-Fi.                 |
A
annie_wangli 已提交
5500 5501 5502 5503 5504 5505
| constraint.locale.set                 | A user is not allowed to change the device language.              |
| constraint.app.accounts               | A user is not allowed to add or delete app accounts.        |
| constraint.apps.install               | A user is not allowed to install apps.                  |
| constraint.apps.uninstall             | A user is not allowed to uninstall apps.                  |
| constraint.location.shared            | A user is not allowed to enable location sharing.              |
| constraint.unknown.sources.install    | A user is not allowed to install apps from unknown sources.        |
A
annie_wangli 已提交
5506
| constraint.global.unknown.app.install | All users are not allowed to install apps from unknown sources.|
A
annie_wangli 已提交
5507 5508
| constraint.bluetooth.set              | A user is not allowed to configure Bluetooth.                  |
| constraint.bluetooth | The use of Bluetooth is prohibited on the device.|
A
annie_wangli 已提交
5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527
| constraint.bluetooth.share | Bluetooth sharing is prohibited.|
| constraint.usb.file.transfer | A user is not allowed to transfer files over USB.|
| constraint.credentials.set | A user is not allowed to configure user credentials.|
| constraint.os.account.remove | An admin user is not allowed to remove users or a non-admin user is not allowed to remove itself.|
| constraint.managed.profile.remove | The managed profiles of this user cannot be removed.|
| constraint.debug.features.use | A user is not allowed to enable or access debugging features.|
| constraint.vpn.set | A user is not allowed to configure a VPN.|
| constraint.date.time.set | A user is not allowed to set date, time, or time zone.|
| constraint.tethering.config | A user is not allowed to configure Tethering.|
| constraint.network.reset | A user is not allowed to reset network settings.|
| constraint.factory.reset | A user is not allowed to reset factory settings.|
| constraint.os.account.create | A user is not allowed to create users.|
| constraint.add.managed.profile | A user is not allowed to add managed profiles.|
| constraint.apps.verify.disable | A user is not allowed to disable app verification.|
| constraint.cell.broadcasts.set | A user is not allowed to configure cell broadcasts.|
| constraint.mobile.networks.set | A user is not allowed to configure radio networks.|
| constraint.control.apps | A user is not allowed to modify apps in **Settings** or the boot module.|
| constraint.physical.media | A user is not allowed to mount external physical media.|
| constraint.microphone | A user is not allowed to use microphones.|
A
annie_wangli 已提交
5528 5529
| constraint.microphone.unmute | A user is not allowed to unmute the microphone.|
| constraint.volume.adjust | A user is not allowed to adjust the volume.|
A
annie_wangli 已提交
5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546
| constraint.calls.outgoing | A user is not allowed to make outgoing calls.|
| constraint.sms.use | A user is not allowed to send or receive SMS messages.|
| constraint.fun | A user is not allowed to have entertainment.|
| constraint.windows.create | Windows other than app windows cannot be created.|
| constraint.system.error.dialogs | Error dialogs for crashed or unresponsive apps are prohibited.|
| constraint.cross.profile.copy.paste | Pasting clipboard content to other users or profiles is prohibited.|
| constraint.beam.outgoing | A user is not allowed to use Near Field Communications (NFC) to transfer data from apps.|
| constraint.wallpaper | A user is not allowed to manage wallpapers.|
| constraint.safe.boot | A user is not allowed to reboot the device in safe boot mode.|
| constraint.parent.profile.app.linking | The apps in the parent profile are allowed to handle web links from the managed profile.|
| constraint.audio.record | Audio recording is prohibited.|
| constraint.camera.use | The use of cameras is prohibited.|
| constraint.os.account.background.run | Running in the background is prohibited.|
| constraint.data.roam | A user is not allowed to use cellular data when roaming.|
| constraint.os.account.set.icon | A user is not allowed to change their icon.|
| constraint.wallpaper.set | A user is not allowed to set a wallpaper.|
| constraint.oem.unlock | A user is not allowed to enable OEM unlock.|
A
annie_wangli 已提交
5547
| constraint.device.unmute | A user is not allowed to unmute the device.|
A
annie_wangli 已提交
5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560
| constraint.password.unified | The managed profile is not allowed to have unified lock screen challenge with the primary user.|
| constraint.autofill | A user is not allowed to use the autofill service.|
| constraint.content.capture | Capturing the content of a user's screen is prohibited.|
| constraint.content.suggestions | A user is not allowed to receive content suggestions.|
| constraint.os.account.start | User switching is blocked.|
| constraint.location.set | A user is not allowed to configure the location service.|
| constraint.airplane.mode.set | The airplane mode is prohibited on the device.|
| constraint.brightness.set | A user is not allowed to configure brightness.|
| constraint.share.into.profile | A user is not allowed to share files, images, or data from the primary user to the managed profile.|
| constraint.ambient.display | Ambient display is prohibited for the user.|
| constraint.screen.timeout.set | A user is not allowed to configure the screen off timeout.|
| constraint.print | A user is not allowed to print.|
| constraint.private.dns.set | A user is not allowed to configure a private domain name server (DNS).|
A
Annie_wang 已提交
5561 5562 5563

## ConstraintSourceTypeInfo<sup>9+</sup>

A
Annie_wang 已提交
5564
Defines the constraint source type.
A
Annie_wang 已提交
5565

A
Annie_wang 已提交
5566
**System API**: This is a system API.
A
Annie_wang 已提交
5567

A
Annie_wang 已提交
5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578
**System capability**: SystemCapability.Account.OsAccount

| Name     | Type  | Mandatory| Description      |
| ----------- | ------ | ---- | ---------- |
| localId      | number | Yes  | ID of the OS account.    |
| type | [ConstraintSourceType](#constraintsourcetype) | Yes  | Type of the constrain source.|

## ConstraintSourceType<sup>9+</sup>

Enumerates the constraint sources.

A
Annie_wang 已提交
5579
**System API**: This is a system API.
A
Annie_wang 已提交
5580

A
Annie_wang 已提交
5581 5582
**System capability**: SystemCapability.Account.OsAccount

A
Annie_wang 已提交
5583
| Name  | Value| Description        |
A
Annie_wang 已提交
5584 5585 5586 5587 5588
| ------ | ------ | ------------ |
| CONSTRAINT_NOT_EXIST  | 0      | The constraint does not exist.|
| CONSTRAINT_TYPE_BASE | 1      | Constraint from system settings.  |
| CONSTRAINT_TYPE_DEVICE_OWNER  | 2   | Constraint from the device owners' settings.  |
| CONSTRAINT_TYPE_PROFILE_OWNER  | 3  | Constraint from the profile owners' settings.  |