js-apis-osAccount.md 131.7 KB
Newer Older
Z
zengyawen 已提交
1
# OS Account Management
A
annie_wangli 已提交
2

A
Annie_wang 已提交
3
The **osAccount** module provides basic capabilities for managing operating system (OS) accounts, including adding, deleting, querying, setting, subscribing to, and enabling an OS account, and storing OS account data to disks.
A
Annie_wang 已提交
4 5

> **NOTE**<br>
A
annie_wangli 已提交
6 7 8 9 10
> 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 已提交
11
```js
A
annie_wangli 已提交
12 13 14 15 16 17 18 19 20
import account_osAccount from '@ohos.account.osAccount';
```

## account_osAccount.getAccountManager

getAccountManager(): AccountManager

Obtains an **AccountManager** instance.

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

A
Annie_wang 已提交
23
**Return value**
A
annie_wangli 已提交
24 25 26 27 28
| Type                             | Description                    |
| --------------------------------- | ------------------------ |
| [AccountManager](#accountmanager) | Obtains an **AccountManager** instance.|

**Example**
Z
zhangalong 已提交
29
  ```js
A
annie_wangli 已提交
30 31 32 33
  const accountManager = account_osAccount.getAccountManager();
  ```

## OsAccountType
A
annie_wangli 已提交
34

A
annie_wangli 已提交
35
Enumerates OS account types.
A
annie_wangli 已提交
36 37 38 39 40 41 42 43

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

| Name  | Default Value| Description        |
| ------ | ------ | ------------ |
| ADMIN  | 0      | Administrator account|
| NORMAL | 1      | Normal account  |
| GUEST  | 2      | Guest account  |
A
annie_wangli 已提交
44 45 46 47 48 49 50 51 52

## AccountManager

Provides methods to manage OS accounts.

### activateOsAccount

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

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

A
annie_wangli 已提交
55 56
This is a system API and cannot be called by third-party applications.

A
annie_wangli 已提交
57 58
**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION

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

A
annie_wangli 已提交
61
**Parameters**
A
annie_wangli 已提交
62

A
annie_wangli 已提交
63 64 65 66 67 68
| Name  | Type                     | Mandatory| Description                |
| -------- | ------------------------- | ---- | -------------------- |
| localId  | number                    | Yes  | ID of the OS account to activate.|
| callback | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result.          |

**Example**: Activate OS account 100.
Z
zhangalong 已提交
69
  ```js
A
annie_wangli 已提交
70 71 72 73 74 75 76 77 78 79 80
  const accountManager = account_osAccount.getAccountManager();
  var localId = 100;
  accountManager.activateOsAccount(localId, (err)=>{
    console.log("activateOsAccount err:" + JSON.stringify(err));
  });
  ```

### activateOsAccount

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

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

A
annie_wangli 已提交
83 84
This is a system API and cannot be called by third-party applications.

Z
zhangalong 已提交
85 86
**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION

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

A
annie_wangli 已提交
89
**Parameters**
A
annie_wangli 已提交
90

A
annie_wangli 已提交
91 92 93
| Name | Type  | Mandatory| Description                |
| ------- | ------ | ---- | -------------------- |
| localId | number | Yes  | ID of the OS account to activate.|
A
annie_wangli 已提交
94

A
Annie_wang 已提交
95
**Return value**
A
annie_wangli 已提交
96

A
annie_wangli 已提交
97 98 99 100 101
| Type               | Description                               |
| :------------------ | :---------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|

**Example**: Activate OS account 100.
Z
zhangalong 已提交
102
  ```js
A
annie_wangli 已提交
103 104 105 106 107 108 109 110 111 112 113 114 115
  const accountManager = account_osAccount.getAccountManager();
  var localId = 100;
  accountManager.activateOsAccount(localId).then(() => {
    console.log("activateOsAccount success");
  }).catch((err) => {
    console.log("activateOsAccount err:" + JSON.stringify(err));
  });
  ```

### isMultiOsAccountEnable

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

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

A
annie_wangli 已提交
118 119 120
**System capability**: SystemCapability.Account.OsAccount

**Parameters**
A
annie_wangli 已提交
121

A
annie_wangli 已提交
122 123 124
| Name  | Type                        | Mandatory| Description                                               |
| -------- | ---------------------------- | ---- | --------------------------------------------------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes  | Callback used to return the result. If multiple OS accounts are supported, **true** will be returned. Otherwise, **false** will be returned.|
A
annie_wangli 已提交
125

A
annie_wangli 已提交
126
**Example**
A
annie_wangli 已提交
127

Z
zhangalong 已提交
128
  ```js
A
annie_wangli 已提交
129 130 131 132 133 134 135 136 137 138 139
  const accountManager = account_osAccount.getAccountManager();
  accountManager.isMultiOsAccountEnable((err, isEnabled) => {
    console.log("isMultiOsAccountEnable err: " + JSON.stringify(err));
    console.log('isMultiOsAccountEnable isEnabled: ' + isEnabled);
  });
  ```

### isMultiOsAccountEnable

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

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

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

A
Annie_wang 已提交
144
**Return value**
A
annie_wangli 已提交
145

A
annie_wangli 已提交
146 147 148 149 150
| Type                  | Description                                                        |
| :--------------------- | :----------------------------------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the result. If multiple OS accounts are supported, **true** will be returned. Otherwise, **false** will be returned.|

**Example**
A
annie_wangli 已提交
151

Z
zhangalong 已提交
152
  ```js
A
annie_wangli 已提交
153 154 155 156 157 158 159 160 161 162 163 164
  const accountManager = account_osAccount.getAccountManager();
  accountManager.isMultiOsAccountEnable().then((isEnabled) => {
    console.log('isMultiOsAccountEnable, isEnabled: ' + isEnabled);
  }).catch((err) => {
    console.log("isMultiOsAccountEnable err: "  + JSON.stringify(err));
  });
  ```

### isOsAccountActived

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

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

Z
zhangalong 已提交
167
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
A
annie_wangli 已提交
168 169

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

A
annie_wangli 已提交
171
**Parameters**
A
annie_wangli 已提交
172

A
annie_wangli 已提交
173 174 175 176 177 178
| Name  | Type                        | Mandatory| Description                                             |
| -------- | ---------------------------- | ---- | ------------------------------------------------- |
| localId  | number                       | Yes  | ID of the target OS account.                                     |
| callback | AsyncCallback&lt;boolean&gt; | Yes  | Callback used to return the result. If the OS account is activated, **true** will be returned. Otherwise, **false** will be returned.|

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

Z
zhangalong 已提交
180
  ```js
A
annie_wangli 已提交
181 182 183 184 185 186 187 188 189 190 191 192
  const accountManager = account_osAccount.getAccountManager();
  var osLocalId = 100;
  accountManager.isOsAccountActived(osLocalId, (err, isActive)=>{
    console.log("isOsAccountActived err:" + JSON.stringify(err));
    console.log("isOsAccountActived isActive:" + isActive);
  });
  ```

### isOsAccountActived

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

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

Z
zhangalong 已提交
195
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
A
annie_wangli 已提交
196 197

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

A
annie_wangli 已提交
199
**Parameters**
A
annie_wangli 已提交
200

A
annie_wangli 已提交
201 202 203
| Name | Type  | Mandatory| Description        |
| ------- | ------ | ---- | ------------ |
| localId | number | Yes  | ID of the target OS account.|
A
annie_wangli 已提交
204

A
Annie_wang 已提交
205
**Return value**
A
annie_wangli 已提交
206

A
annie_wangli 已提交
207 208 209 210 211
| Type                  | Description                                                        |
| :--------------------- | :----------------------------------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the result. If the OS account is activated, **true** will be returned. Otherwise, **false** will be returned.|

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

Z
zhangalong 已提交
213
  ```js
A
annie_wangli 已提交
214 215 216 217 218 219 220 221 222 223 224 225 226
  const accountManager = account_osAccount.getAccountManager();
  var osLocalId = 100;
  accountManager.isOsAccountActived(osLocalId).then((isActive) => {
    console.log('isOsAccountActived, isActive: ' + isActive);
  }).catch((err) => {
    console.log("isOsAccountActived err: "  + JSON.stringify(err));
  });
  ```

### isOsAccountConstraintEnable

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

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

A
annie_wangli 已提交
229 230 231
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

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

A
annie_wangli 已提交
233
**Parameters**
A
annie_wangli 已提交
234

A
annie_wangli 已提交
235 236 237 238 239 240
| Name    | Type                        | Mandatory| Description                                             |
| ---------- | ---------------------------- | ---- | ------------------------------------------------- |
| localId    | number                       | Yes  | ID of the target OS account.                               |
| constraint | string                       | Yes  | [Constraint](#constraints) specified.            |
| callback   | AsyncCallback&lt;boolean&gt; | Yes  | Callback used to return the result. If the constraint is enabled for the OS account, **true** will be returned. Otherwise, **false** will be returned.|

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

Z
zhangalong 已提交
243
  ```js
A
annie_wangli 已提交
244 245 246 247 248 249 250 251 252 253 254 255
  const accountManager = account_osAccount.getAccountManager();
  var localId = 100;
  accountManager.isOsAccountConstraintEnable(localId, "constraint.wifi", (err, isConstraintEnabled)=>{
    console.log("isOsAccountConstraintEnable err:" + JSON.stringify(err));
    console.log("isOsAccountConstraintEnable isConstraintEnabled:" + isConstraintEnabled);
  });
  ```

### isOsAccountConstraintEnable

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

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

A
annie_wangli 已提交
258 259 260
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

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

A
annie_wangli 已提交
262
**Parameters**
A
annie_wangli 已提交
263

A
annie_wangli 已提交
264 265 266 267
| Name    | Type  | Mandatory| Description                                 |
| ---------- | ------ | ---- | ------------------------------------- |
| localId    | number | Yes  | ID of the target OS account.                   |
| constraint | string | Yes  | [Constraint](#constraints) specified.|
A
annie_wangli 已提交
268

A
Annie_wang 已提交
269
**Return value**
A
annie_wangli 已提交
270

A
annie_wangli 已提交
271 272 273 274
| Type                  | Description                                                        |
| :--------------------- | :----------------------------------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the result. If the constraint is enabled for the OS account, **true** will be returned. Otherwise, **false** will be returned.|

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

Z
zhangalong 已提交
277
  ```js
A
annie_wangli 已提交
278 279 280 281 282 283 284 285 286 287 288 289 290
  const accountManager = account_osAccount.getAccountManager();
  var localId = 100;
  accountManager.isOsAccountConstraintEnable(localId, "constraint.wifi").then((isConstraintEnabled) => {
    console.log('isOsAccountConstraintEnable, isConstraintEnabled: ' + isConstraintEnabled);
  }).catch((err) => {
    console.log("isOsAccountConstraintEnable err: "  + JSON.stringify(err));
  });
  ```

### isTestOsAccount

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

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

A
annie_wangli 已提交
293 294 295
**System capability**: SystemCapability.Account.OsAccount

**Parameters**
A
annie_wangli 已提交
296

A
annie_wangli 已提交
297 298 299
| Name  | Type                        | Mandatory| Description                                           |
| -------- | ---------------------------- | ---- | ----------------------------------------------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes  | Callback used to return the result. If the account is a test account, **true** will be returned. Otherwise, **false** will be returned.|
A
annie_wangli 已提交
300

A
annie_wangli 已提交
301
**Example**
A
annie_wangli 已提交
302

Z
zhangalong 已提交
303
  ```js
A
annie_wangli 已提交
304 305 306 307 308 309 310 311 312 313 314
  const accountManager = account_osAccount.getAccountManager();
  accountManager.isTestOsAccount((err, isTest) => {
    console.log("isTestOsAccount err: " + JSON.stringify(err));
    console.log('isTestOsAccount isTest: ' + isTest);
  });
  ```

### isTestOsAccount

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

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

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

A
Annie_wang 已提交
319
**Return value**
A
annie_wangli 已提交
320

A
annie_wangli 已提交
321 322 323 324 325
| Type                  | Description                                                        |
| :--------------------- | :----------------------------------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the result. If the account is a test account, **true** will be returned. Otherwise, **false** will be returned.|

**Example**
A
annie_wangli 已提交
326

Z
zhangalong 已提交
327
  ```js
A
annie_wangli 已提交
328 329 330 331 332 333 334 335 336 337 338 339
  const accountManager = account_osAccount.getAccountManager();
  accountManager.isTestOsAccount().then((isTest) => {
    console.log('isTestOsAccount, isTest: ' + isTest);
  }).catch((err) => {
    console.log("isTestOsAccount err: "  + JSON.stringify(err));
  });
  ```

### isOsAccountVerified

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

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

A
annie_wangli 已提交
342 343 344
**System capability**: SystemCapability.Account.OsAccount

**Parameters**
A
annie_wangli 已提交
345

A
annie_wangli 已提交
346 347 348
| Name  | Type                        | Mandatory| Description                                       |
| -------- | ---------------------------- | ---- | ------------------------------------------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes  | Callback used to return the result. If the OS account has been verified, **true** will be returned. Otherwise, **false** will be returned.|
A
annie_wangli 已提交
349

A
annie_wangli 已提交
350
**Example**
A
annie_wangli 已提交
351

Z
zhangalong 已提交
352
  ```js
A
annie_wangli 已提交
353 354 355 356 357 358 359 360 361 362 363
  const accountManager = account_osAccount.getAccountManager();
  accountManager.isOsAccountVerified((err, isVerified) => {
    console.log("isOsAccountVerified err: " + JSON.stringify(err));
    console.log('isOsAccountVerified isVerified: ' + isVerified);
  });
  ```

### isOsAccountVerified

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

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

Z
zhangalong 已提交
366 367
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS

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

A
annie_wangli 已提交
370
**Parameters**
A
annie_wangli 已提交
371

A
annie_wangli 已提交
372 373 374 375 376 377
| Name  | Type                        | Mandatory| Description                                       |
| -------- | ---------------------------- | ---- | ------------------------------------------- |
| localId  | number                       | No  | ID of the target OS account.                         |
| callback | AsyncCallback&lt;boolean&gt; | Yes  | Callback used to return the result. If the OS account has been verified, **true** will be returned. Otherwise, **false** will be returned.|

**Example**
A
annie_wangli 已提交
378

Z
zhangalong 已提交
379
  ```js
A
annie_wangli 已提交
380 381 382 383 384 385 386 387 388
  const accountManager = account_osAccount.getAccountManager();
  accountManager.isOsAccountVerified((err, isVerified) => {
    console.log("isOsAccountVerified err: " + JSON.stringify(err));
    console.log('isOsAccountVerified isVerified: ' + isVerified);
  });
  ```

### isOsAccountVerified

A
annie_wangli 已提交
389
isOsAccountVerified(localId?: number): Promise&lt;boolean&gt;
A
annie_wangli 已提交
390

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

Z
zhangalong 已提交
393 394
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS

A
annie_wangli 已提交
395 396 397
**System capability**: SystemCapability.Account.OsAccount

**Parameters**
A
annie_wangli 已提交
398

A
annie_wangli 已提交
399 400 401
| Name | Type  | Mandatory| Description              |
| ------- | ------ | ---- | ------------------ |
| localId | number | No  | ID of the target OS account.|
A
annie_wangli 已提交
402

A
Annie_wang 已提交
403
**Return value**
A
annie_wangli 已提交
404

A
annie_wangli 已提交
405 406 407
| Type                  | Description                                                        |
| :--------------------- | :----------------------------------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the result. If the OS account has been verified, **true** will be returned. Otherwise, **false** will be returned.|
A
annie_wangli 已提交
408

A
annie_wangli 已提交
409
**Example**
A
annie_wangli 已提交
410

Z
zhangalong 已提交
411
  ```js
A
annie_wangli 已提交
412 413 414 415 416 417 418 419 420 421 422 423
  const accountManager = account_osAccount.getAccountManager();
  accountManager.isOsAccountVerified().then((isVerified) => {
    console.log('isOsAccountVerified, isVerified: ' + isVerified);
  }).catch((err) => {
    console.log("isOsAccountVerified err: "  + JSON.stringify(err));
  });
  ```

### removeOsAccount

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

A
Annie_wang 已提交
424
Removes an OS account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
425

A
annie_wangli 已提交
426
This is a system API and cannot be called by third-party applications.
A
annie_wangli 已提交
427

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

A
annie_wangli 已提交
430 431 432 433 434 435 436 437 438 439
**System capability**: SystemCapability.Account.OsAccount

**Parameters**

| Name  | Type                     | Mandatory| Description                |
| -------- | ------------------------- | ---- | -------------------- |
| localId  | number                    | Yes  | ID of the OS account to remove.|
| callback | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result.          |

**Example**
A
annie_wangli 已提交
440

Z
zhangalong 已提交
441
  ```js
A
annie_wangli 已提交
442
  const accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
443 444 445 446
  accountManager.createOsAccount("testAccountName", account_osAccount.OsAccountType.NORMAL, (err, osAccountInfo) => {
    accountManager.removeOsAccount(osAccountInfo.localId, (err)=>{
      console.log("removeOsAccount err:" + JSON.stringify(err));
    });
A
annie_wangli 已提交
447 448 449 450 451 452 453
  });
  ```

### removeOsAccount

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

A
Annie_wang 已提交
454
Removes an OS account. This API uses a promise to return the result.
A
annie_wangli 已提交
455

A
annie_wangli 已提交
456 457 458 459 460 461 462
This is a system API and cannot be called by third-party applications.

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

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

**Parameters**
A
annie_wangli 已提交
463

A
annie_wangli 已提交
464 465 466
| Name | Type  | Mandatory| Description                |
| ------- | ------ | ---- | -------------------- |
| localId | number | Yes  | ID of the OS account to remove.|
A
annie_wangli 已提交
467

A
Annie_wang 已提交
468
**Return value**
A
annie_wangli 已提交
469

A
annie_wangli 已提交
470 471 472
| Type               | Description                               |
| :------------------ | :---------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
A
annie_wangli 已提交
473

A
annie_wangli 已提交
474
**Example**
A
annie_wangli 已提交
475

Z
zhangalong 已提交
476
  ```js
A
annie_wangli 已提交
477
  const accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
478 479 480 481 482 483
  accountManager.createOsAccount("testAccountName", account_osAccount.OsAccountType.NORMAL, (err, osAccountInfo)=>{
    accountManager.removeOsAccount(osAccountInfo.localId).then(() => {
      console.log('removeOsAccount Success');
    }).catch(() => {
      console.log("removeOsAccount err: "  + JSON.stringify(err));
    });
A
annie_wangli 已提交
484 485 486 487 488 489 490
  });
  ```

### setOsAccountConstraints

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

A
Annie_wang 已提交
491
Sets or removes constraints for an OS account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
492 493 494 495 496 497

This is a system API and cannot be called by third-party applications.

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

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

A
annie_wangli 已提交
499
**Parameters**
A
annie_wangli 已提交
500

A
annie_wangli 已提交
501 502 503 504 505 506
| 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 used to return the result.                                  |
A
annie_wangli 已提交
507

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

Z
zhangalong 已提交
510
  ```js
A
annie_wangli 已提交
511 512 513 514 515 516 517 518 519 520 521
  const accountManager = account_osAccount.getAccountManager();
  var localId = 100;
  accountManager.setOsAccountConstraints(localId, ["constraint.wifi"], true, (err)=>{
    console.log("setOsAccountConstraints err:" + JSON.stringify(err));
  });
  ```

### setOsAccountConstraints

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

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

A
annie_wangli 已提交
524
This is a system API and cannot be called by third-party applications.
A
annie_wangli 已提交
525

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

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

A
annie_wangli 已提交
530
**Parameters**
A
annie_wangli 已提交
531

A
annie_wangli 已提交
532 533 534 535 536 537
| 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.                    |

A
Annie_wang 已提交
538
**Return value**
A
annie_wangli 已提交
539 540 541 542 543 544

| Type               | Description                               |
| :------------------ | :---------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|

**Example**: Remote the constraint on the use of Wi-Fi for OS account 100.
A
annie_wangli 已提交
545

Z
zhangalong 已提交
546
  ```js
A
annie_wangli 已提交
547 548 549 550 551 552 553 554 555 556 557 558 559
  const accountManager = account_osAccount.getAccountManager();
  var localId = 100;
  accountManager.setOsAccountConstraints(localId, ["constraint.location.set"], false).then(() => {
    console.log('setOsAccountConstraints Success');
  }).catch((err) => {
    console.log("setOsAccountConstraints err: "  + JSON.stringify(err));
  });
  ```

### setOsAccountName

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

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

A
annie_wangli 已提交
562 563
This is a system API and cannot be called by third-party applications.

Z
zhangalong 已提交
564 565
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

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

A
annie_wangli 已提交
568
**Parameters**
A
annie_wangli 已提交
569

A
annie_wangli 已提交
570 571 572 573 574 575 576
| Name   | Type                     | Mandatory| Description        |
| :-------- | ------------------------- | ---- | ------------ |
| localId   | number                    | Yes  | ID of the target OS account.|
| localName | string                    | Yes  | Account name to set.    |
| callback  | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result.  |

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

Z
zhangalong 已提交
578
  ```js
A
annie_wangli 已提交
579 580 581 582 583 584 585 586 587 588 589 590
  const accountManager = account_osAccount.getAccountManager();
  var localId = 100;
  var newName = "demoName";
  accountManager.setOsAccountName(localId, newName, (err)=>{
    console.debug("setOsAccountName err:" + JSON.stringify(err));
  });
  ```

### setOsAccountName

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

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

A
annie_wangli 已提交
593 594
This is a system API and cannot be called by third-party applications.

Z
zhangalong 已提交
595 596
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

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

A
annie_wangli 已提交
599
**Parameters**
A
annie_wangli 已提交
600

A
annie_wangli 已提交
601 602 603 604
| Name   | Type  | Mandatory| Description        |
| --------- | ------ | ---- | ------------ |
| localId   | number | Yes  | ID of the target OS account.|
| localName | string | Yes  | Account name to set.    |
A
annie_wangli 已提交
605

A
Annie_wang 已提交
606
**Return value**
A
annie_wangli 已提交
607

A
annie_wangli 已提交
608 609 610 611 612
| Type               | Description                               |
| :------------------ | :---------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|

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

Z
zhangalong 已提交
614
  ```js
A
annie_wangli 已提交
615 616 617 618 619 620 621 622 623 624 625 626 627 628
  const accountManager = account_osAccount.getAccountManager();
  var localId = 100;
  var nameLimit = "demoName";
  accountManager.setOsAccountName(localId, nameLimit).then(() => {
    console.log('setOsAccountName Success');
  }).catch((err) => {
    console.log("setOsAccountName err: "  + JSON.stringify(err));
  });
  ```

### getCreatedOsAccountsCount

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

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

A
annie_wangli 已提交
631 632 633
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

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

A
annie_wangli 已提交
635
**Parameters**
A
annie_wangli 已提交
636

A
annie_wangli 已提交
637 638 639 640 641
| Name  | Type                       | Mandatory| Description                                      |
| -------- | --------------------------- | ---- | ------------------------------------------ |
| callback | AsyncCallback&lt;number&gt; | Yes  | Callback used to return the number of OS accounts created.|

**Example**
A
annie_wangli 已提交
642

Z
zhangalong 已提交
643
  ```js
A
annie_wangli 已提交
644 645 646 647 648 649 650 651 652 653 654
  const accountManager = account_osAccount.getAccountManager();
  accountManager.getCreatedOsAccountsCount((err, accountCnt)=>{
    console.log("obtains the number of all os accounts created err:" + JSON.stringify(err));
    console.log("obtains the number of all os accounts created accountCnt:" + accountCnt);
  });
  ```

### getCreatedOsAccountsCount

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

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

A
annie_wangli 已提交
657 658 659 660
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

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

A
Annie_wang 已提交
661
**Return value**
A
annie_wangli 已提交
662

A
annie_wangli 已提交
663 664 665
| Type                 | Description                                                        |
| :-------------------- | :----------------------------------------------------------- |
| Promise&lt;number&gt; | Promise used to return the number of OS accounts created.|
A
annie_wangli 已提交
666

A
annie_wangli 已提交
667
**Example**
A
annie_wangli 已提交
668

Z
zhangalong 已提交
669
  ```js
A
annie_wangli 已提交
670 671 672 673 674 675 676 677 678 679 680 681
  const accountManager = account_osAccount.getAccountManager();
  accountManager.getCreatedOsAccountsCount().then((accountCnt) => {
    console.log('getCreatedOsAccountsCount, accountCnt: ' + accountCnt);
  }).catch((err) => {
    console.log("getCreatedOsAccountsCount err: "  + JSON.stringify(err));
  });
  ```

### getOsAccountLocalIdFromProcess

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

A
Annie_wang 已提交
682
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 已提交
683

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

A
annie_wangli 已提交
686
**Parameters**
A
annie_wangli 已提交
687

A
annie_wangli 已提交
688 689 690 691 692
| Name  | Type                       | Mandatory| Description                                              |
| -------- | --------------------------- | ---- | -------------------------------------------------- |
| callback | AsyncCallback&lt;number&gt; | Yes  | Callback used to return the account ID obtained.|

**Example**
A
annie_wangli 已提交
693

Z
zhangalong 已提交
694
  ```js
A
annie_wangli 已提交
695 696 697 698 699 700 701 702 703 704 705
  const accountManager = account_osAccount.getAccountManager();
  accountManager.getOsAccountLocalIdFromProcess((err, accountID) => {
    console.log("getOsAccountLocalIdFromProcess err: " + JSON.stringify(err));
    console.log('getOsAccountLocalIdFromProcess accountID: ' + accountID);
  });
  ```

### getOsAccountLocalIdFromProcess

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

A
Annie_wang 已提交
706
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 已提交
707

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

A
Annie_wang 已提交
710
**Return value**
A
annie_wangli 已提交
711

A
annie_wangli 已提交
712 713 714
| Type                 | Description                                                        |
| :-------------------- | :----------------------------------------------------------- |
| Promise&lt;number&gt; | Promise used to return the account ID obtained.|
A
annie_wangli 已提交
715

A
annie_wangli 已提交
716
**Example**
A
annie_wangli 已提交
717

Z
zhangalong 已提交
718
  ```js
A
annie_wangli 已提交
719 720 721 722 723 724 725 726 727 728 729 730
  const accountManager = account_osAccount.getAccountManager();
  accountManager.getOsAccountLocalIdFromProcess().then((accountID) => {
    console.log('getOsAccountLocalIdFromProcess, accountID: ' + accountID);
  }).catch((err) => {
    console.log("getOsAccountLocalIdFromProcess err: "  + JSON.stringify(err));
  });
  ```

### getOsAccountLocalIdFromUid

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

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

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

A
annie_wangli 已提交
735
**Parameters**
A
annie_wangli 已提交
736

A
annie_wangli 已提交
737 738 739 740 741 742
| Name  | Type                       | Mandatory| Description                                         |
| -------- | --------------------------- | ---- | --------------------------------------------- |
| uid      | number                      | Yes  | Process UID.                                    |
| callback | AsyncCallback&lt;number&gt; | Yes  | Callback used to return the OS account ID obtained.|

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

Z
zhangalong 已提交
744
  ```js
A
annie_wangli 已提交
745 746 747 748 749 750 751 752 753 754 755 756
  const accountManager = account_osAccount.getAccountManager();
  let uid = 12345678;
  accountManager.getOsAccountLocalIdFromUid(uid, (err, accountID) => {
    console.log("getOsAccountLocalIdFromUid err: " + JSON.stringify(err));
    console.log('getOsAccountLocalIdFromUid: ' + accountID);
  });
  ```

### getOsAccountLocalIdFromUid

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

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

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

**Parameters**
A
annie_wangli 已提交
762

A
annie_wangli 已提交
763 764 765
| Name| Type  | Mandatory| Description     |
| ------ | ------ | ---- | --------- |
| uid    | number | Yes  | Process UID.|
A
annie_wangli 已提交
766

A
Annie_wang 已提交
767
**Return value**
A
annie_wangli 已提交
768

A
annie_wangli 已提交
769 770 771
| Type                 | Description                                                        |
| :-------------------- | :----------------------------------------------------------- |
| Promise&lt;number&gt; | Promise used to return the OS account ID obtained.|
A
annie_wangli 已提交
772

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

Z
zhangalong 已提交
775
  ```js
A
annie_wangli 已提交
776 777 778 779 780 781 782 783 784
  const accountManager = account_osAccount.getAccountManager();
  let uid = 12345678;
  accountManager.getOsAccountLocalIdFromUid(uid).then((accountID) => {
    console.log('getOsAccountLocalIdFromUid: ' + accountID);
  }).catch((err) => {
    console.log("getOsAccountLocalIdFromUid err: "  + JSON.stringify(err));
  });
  ```

A
annie_wangli 已提交
785
### getOsAccountLocalIdFromDomain<sup>8+</sup>
A
annie_wangli 已提交
786 787 788

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

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

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

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

A
annie_wangli 已提交
795 796 797 798
**Parameters**

| Name    | Type                                   | Mandatory| Description                                        |
| ---------- | --------------------------------------- | ---- | -------------------------------------------- |
A
Annie_wang 已提交
799
| domainInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes  | Domain account information.                                |
A
annie_wangli 已提交
800 801 802
| callback   | AsyncCallback&lt;number&gt;             | Yes  | Callback used to return the ID of the OS account associated with the domain account.|

**Example**
A
annie_wangli 已提交
803

Z
zhangalong 已提交
804
  ```js
A
annie_wangli 已提交
805 806 807 808 809 810 811 812
  var domainInfo = {domain: "testDomain", accountName: "testAccountName"};
  const accountManager = account_osAccount.getAccountManager();
  accountManager.getOsAccountLocalIdFromDomain(domainInfo, (err, accountID) => {
    console.log("getOsAccountLocalIdFromDomain: " + JSON.stringify(err));
    console.log('getOsAccountLocalIdFromDomain: ' + accountID);
  });
  ```

A
annie_wangli 已提交
813
### getOsAccountLocalIdFromDomain<sup>8+</sup>
A
annie_wangli 已提交
814 815 816

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

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

A
annie_wangli 已提交
819 820 821 822 823
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

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

**Parameters**
A
annie_wangli 已提交
824

A
annie_wangli 已提交
825 826
| Name    | Type                                   | Mandatory| Description        |
| ---------- | --------------------------------------- | ---- | ------------ |
A
Annie_wang 已提交
827
| domainInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes  | Domain account information.|
A
annie_wangli 已提交
828

A
Annie_wang 已提交
829
**Return value**
A
annie_wangli 已提交
830

A
annie_wangli 已提交
831 832 833
| Type                 | Description                                                        |
| :-------------------- | :----------------------------------------------------------- |
| Promise&lt;number&gt; | Promise used to return the ID of the OS account associated with the domain account.|
A
annie_wangli 已提交
834

A
annie_wangli 已提交
835
**Example**
A
annie_wangli 已提交
836

Z
zhangalong 已提交
837
  ```js
A
annie_wangli 已提交
838 839 840 841 842 843 844 845 846 847 848 849 850
  const accountManager = account_osAccount.getAccountManager();
  var domainInfo = {domain: "testDomain", accountName: "testAccountName"};
  accountManager.getOsAccountLocalIdFromDomain(domainInfo).then((accountID) => {
    console.log('getOsAccountLocalIdFromDomain: ' + accountID);
  }).catch((err) => {
    console.log("getOsAccountLocalIdFromDomain err: "  + JSON.stringify(err));
  });
  ```

### queryMaxOsAccountNumber

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

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

A
annie_wangli 已提交
853
This is a system API and cannot be called by third-party applications.
A
annie_wangli 已提交
854

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

A
annie_wangli 已提交
857 858 859 860 861 862 863
**Parameters**

| Name  | Type                       | Mandatory| Description                                            |
| -------- | --------------------------- | ---- | ------------------------------------------------ |
| callback | AsyncCallback&lt;number&gt; | Yes  | Callback used to return the maximum number of OS accounts that can be created.|

**Example**
A
annie_wangli 已提交
864

Z
zhangalong 已提交
865
  ```js
A
annie_wangli 已提交
866 867 868 869 870 871 872 873 874 875 876
  const accountManager = account_osAccount.getAccountManager();
  accountManager.queryMaxOsAccountNumber((err, maxCnt)=>{
    console.log("queryMaxOsAccountNumber err:" + JSON.stringify(err));
    console.log("queryMaxOsAccountNumber maxCnt:" + maxCnt);
  });
  ```

### queryMaxOsAccountNumber

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

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

A
annie_wangli 已提交
879 880 881 882
This is a system API and cannot be called by third-party applications.

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

A
Annie_wang 已提交
883
**Return value**
A
annie_wangli 已提交
884

A
annie_wangli 已提交
885 886 887
| Type                 | Description                                                        |
| :-------------------- | :----------------------------------------------------------- |
| Promise&lt;number&gt; | Promise used to return the maximum number of OS accounts that can be created.|
A
annie_wangli 已提交
888

A
annie_wangli 已提交
889
**Example**
A
annie_wangli 已提交
890

Z
zhangalong 已提交
891
  ```js
A
annie_wangli 已提交
892 893 894 895 896 897 898 899 900 901 902 903
  const accountManager = account_osAccount.getAccountManager();
  accountManager.queryMaxOsAccountNumber().then((maxCnt) => {
    console.log('queryMaxOsAccountNumber, maxCnt: ' + maxCnt);
  }).catch((err) => {
    console.log("queryMaxOsAccountNumber err: "  + JSON.stringify(err));
  });
  ```

### getOsAccountAllConstraints

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

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

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

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

A
annie_wangli 已提交
910 911 912 913 914 915 916
**Parameters**

| Name  | Type                                    | Mandatory| Description                                                        |
| -------- | ---------------------------------------- | ---- | ------------------------------------------------------------ |
| localId  | number                                   | Yes  | ID of the target OS account.                                                |
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | Yes  | Callback used to return all [constraints](#constraints) obtained.|

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

Z
zhangalong 已提交
919
  ```js
A
annie_wangli 已提交
920 921 922 923 924 925 926 927 928 929 930 931
  const accountManager = account_osAccount.getAccountManager();
  var localId = 100;
  accountManager.getOsAccountAllConstraints(localId, (err, constraints)=>{
    console.log("getOsAccountAllConstraints err:" + JSON.stringify(err));
    console.log("getOsAccountAllConstraints:" + JSON.stringify(constraints));
  });
  ```

### getOsAccountAllConstraints

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

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

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

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

A
annie_wangli 已提交
938
**Parameters**
A
annie_wangli 已提交
939

A
annie_wangli 已提交
940 941 942
| Name | Type  | Mandatory| Description        |
| ------- | ------ | ---- | ------------ |
| localId | number | Yes  | ID of the target OS account.|
A
annie_wangli 已提交
943

A
Annie_wang 已提交
944
**Return value**
A
annie_wangli 已提交
945

A
annie_wangli 已提交
946 947 948 949
| Type                              | Description                                                        |
| :--------------------------------- | :----------------------------------------------------------- |
| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the [constraints](#constraints) obtained.|

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

Z
zhangalong 已提交
952
  ```js
A
annie_wangli 已提交
953 954 955 956 957 958 959 960 961 962 963 964 965
  const accountManager = account_osAccount.getAccountManager();
  var localId = 100;
  accountManager.getOsAccountAllConstraints(localId).then((constraints) => {
    console.log("getOsAccountAllConstraints, constraints: " + constraints);
  }).catch((err) => {
    console.log("getOsAccountAllConstraints err: "  + JSON.stringify(err));
  });
  ```

### queryAllCreatedOsAccounts

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

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

A
annie_wangli 已提交
968 969 970
This is a system API and cannot be called by third-party applications.

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

A
Annie_wang 已提交
972 973
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

A
annie_wangli 已提交
974
**Parameters**
A
annie_wangli 已提交
975

A
annie_wangli 已提交
976 977 978 979 980
| Name  | Type                                                        | Mandatory| Description                                              |
| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------------- |
| callback | AsyncCallback&lt;Array&lt;[OsAccountInfo](#osaccountinfo)&gt;&gt; | Yes  | Callback used to return information about OS accounts created.|

**Example**
A
annie_wangli 已提交
981

Z
zhangalong 已提交
982
  ```js
A
annie_wangli 已提交
983 984 985 986 987 988 989 990 991 992 993
  const accountManager = account_osAccount.getAccountManager();
  accountManager.queryAllCreatedOsAccounts((err, accountArr)=>{
    console.log("queryAllCreatedOsAccounts err:" + JSON.stringify(err));
    console.log("queryAllCreatedOsAccounts accountArr:" + JSON.stringify(accountArr));
  });
  ```

### queryAllCreatedOsAccounts

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

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

A
annie_wangli 已提交
996 997 998
This is a system API and cannot be called by third-party applications.

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

A
Annie_wang 已提交
1000 1001
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

A
Annie_wang 已提交
1002
**Return value**
A
annie_wangli 已提交
1003

A
annie_wangli 已提交
1004 1005 1006 1007 1008
| Type                                                       | Description                                                        |
| :---------------------------------------------------------- | :----------------------------------------------------------- |
| Promise&lt;Array&lt;[OsAccountInfo](#osaccountinfo)&gt;&gt; | Promise used to return information about OS accounts created.|

**Example**
A
annie_wangli 已提交
1009

Z
zhangalong 已提交
1010
  ```js
A
annie_wangli 已提交
1011 1012 1013 1014 1015 1016 1017 1018
  const accountManager = account_osAccount.getAccountManager();
  accountManager.queryAllCreatedOsAccounts().then((accountArr) => {
    console.log('queryAllCreatedOsAccounts, accountArr: ' + JSON.stringify(accountArr));
  }).catch((err) => {
    console.log("queryAllCreatedOsAccounts err: "  + JSON.stringify(err));
  });
  ```

A
annie_wangli 已提交
1019
### queryActivatedOsAccountIds<sup>8+</sup>
A
annie_wangli 已提交
1020 1021 1022

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

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

A
annie_wangli 已提交
1025 1026 1027
**System capability**: SystemCapability.Account.OsAccount

**Parameters**
A
annie_wangli 已提交
1028

A
annie_wangli 已提交
1029 1030 1031
| Name  | Type                                    | Mandatory| Description                                                  |
| -------- | ---------------------------------------- | ---- | ------------------------------------------------------ |
| callback | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes  | Callback used to return information about activated OS accounts.|
A
annie_wangli 已提交
1032

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

Z
zhangalong 已提交
1035
  ```js
A
annie_wangli 已提交
1036 1037 1038 1039 1040 1041 1042 1043 1044 1045
  const accountManager = account_osAccount.getAccountManager();
  accountManager.queryActivatedOsAccountIds((err, idArray)=>{
    console.log("queryActivatedOsAccountIds err:" + JSON.stringify(err));
    console.log("queryActivatedOsAccountIds idArray length:" + idArray.length);
    for(var i=0;i<idArray.length;i++) {
      console.info("activated os account id: " + idArray[i]);
    }
  });
  ```

A
annie_wangli 已提交
1046
### queryActivatedOsAccountIds<sup>8+</sup>
A
annie_wangli 已提交
1047 1048 1049

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

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

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

A
Annie_wang 已提交
1054
**Return value**
A
annie_wangli 已提交
1055

A
annie_wangli 已提交
1056 1057 1058 1059 1060
| Type                              | Description                                                        |
| :--------------------------------- | :----------------------------------------------------------- |
| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return information about activated OS accounts.|

**Example**
A
annie_wangli 已提交
1061

Z
zhangalong 已提交
1062
  ```js
A
annie_wangli 已提交
1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074
  const accountManager = account_osAccount.getAccountManager();
  accountManager.queryActivatedOsAccountIds().then((idArray) => {
    console.log('queryActivatedOsAccountIds, idArray: ' + idArray);
  }).catch((err) => {
    console.log("queryActivatedOsAccountIds err: "  + JSON.stringify(err));
  });
  ```

### createOsAccount

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

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

A
annie_wangli 已提交
1077 1078 1079
This is a system API and cannot be called by third-party applications.

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

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

A
annie_wangli 已提交
1083 1084 1085 1086 1087 1088 1089 1090 1091
**Parameters**

| 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 used to return the OS account created.|

**Example**
A
annie_wangli 已提交
1092

Z
zhangalong 已提交
1093
  ```js
A
annie_wangli 已提交
1094
  const accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
1095
  accountManager.createOsAccount("testName", account_osAccount.OsAccountType.NORMAL, (err, osAccountInfo)=>{
A
annie_wangli 已提交
1096 1097 1098 1099 1100 1101 1102 1103 1104
    console.log("createOsAccount err:" + JSON.stringify(err));
    console.log("createOsAccount osAccountInfo:" + JSON.stringify(osAccountInfo));
  });
  ```

### createOsAccount

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

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

A
annie_wangli 已提交
1107 1108 1109 1110 1111
This is a system API and cannot be called by third-party applications.

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

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

A
annie_wangli 已提交
1113
**Parameters**
A
annie_wangli 已提交
1114

A
annie_wangli 已提交
1115 1116 1117 1118
| 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 已提交
1119

A
Annie_wang 已提交
1120
**Return value**
A
annie_wangli 已提交
1121

A
annie_wangli 已提交
1122 1123 1124 1125 1126
| Type                                          | Description                                                        |
| :--------------------------------------------- | :----------------------------------------------------------- |
| Promise&lt;[OsAccountInfo](#osaccountinfo)&gt; | Promise used to return the OS account created.|

**Example**
A
annie_wangli 已提交
1127

Z
zhangalong 已提交
1128
  ```js
A
annie_wangli 已提交
1129
  const accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
1130
  accountManager.createOsAccount("testAccountName", account_osAccount.OsAccountType.NORMAL).then((accountInfo) => {
A
annie_wangli 已提交
1131 1132 1133 1134 1135 1136
    console.log("createOsAccount, accountInfo: " + JSON.stringify(accountInfo));
  }).catch((err) => {
    console.log("createOsAccount err: "  + JSON.stringify(err));
  });
  ```

A
annie_wangli 已提交
1137
### createOsAccountForDomain<sup>8+</sup>
A
annie_wangli 已提交
1138 1139 1140

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

A
Annie_wang 已提交
1141
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 已提交
1142

A
annie_wangli 已提交
1143 1144 1145 1146 1147
This is a system API and cannot be called by third-party applications.

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

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

A
annie_wangli 已提交
1149
**Parameters**
A
annie_wangli 已提交
1150

A
annie_wangli 已提交
1151 1152 1153
| Name    | Type                                                | Mandatory| Description                                      |
| :--------- | ---------------------------------------------------- | ---- | ------------------------------------------ |
| type       | [OsAccountType](#osaccounttype)                      | Yes  | Type of the OS account to create.                    |
A
Annie_wang 已提交
1154
| domainInfo | [DomainAccountInfo](#domainaccountinfo8)              | Yes  | Domain account information.                              |
A
annie_wangli 已提交
1155 1156 1157
| callback   | AsyncCallback&lt;[OsAccountInfo](#osaccountinfo)&gt; | Yes  | Callback used to return the OS account created.|

**Example**
A
annie_wangli 已提交
1158

Z
zhangalong 已提交
1159
  ```js
A
annie_wangli 已提交
1160 1161
  const accountManager = account_osAccount.getAccountManager();
  var domainInfo = {domain: "testDomain", accountName: "testAccountName"};
A
Annie_wang 已提交
1162
  accountManager.createOsAccountForDomain(account_osAccount.OsAccountType.NORMAL, domainInfo, (err, osAccountInfo)=>{
A
annie_wangli 已提交
1163 1164 1165 1166 1167
    console.log("createOsAccountForDomain err:" + JSON.stringify(err));
    console.log("createOsAccountForDomain osAccountInfo:" + JSON.stringify(osAccountInfo));
  });
  ```

A
annie_wangli 已提交
1168
### createOsAccountForDomain<sup>8+</sup>
A
annie_wangli 已提交
1169 1170 1171

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

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

A
annie_wangli 已提交
1174 1175 1176 1177 1178 1179 1180
This is a system API and cannot be called by third-party applications.

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

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

**Parameters**
A
annie_wangli 已提交
1181

A
annie_wangli 已提交
1182 1183 1184
| Name    | Type                                   | Mandatory| Description                  |
| ---------- | --------------------------------------- | ---- | ---------------------- |
| type       | [OsAccountType](#osaccounttype)         | Yes  | Type of the OS account to create.|
A
Annie_wang 已提交
1185
| domainInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes  | Domain account information.          |
A
annie_wangli 已提交
1186

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

A
annie_wangli 已提交
1189 1190 1191
| Type                                          | Description                                                        |
| :--------------------------------------------- | :----------------------------------------------------------- |
| Promise&lt;[OsAccountInfo](#osaccountinfo)&gt; | Promise used to return the OS account created.|
A
annie_wangli 已提交
1192

A
annie_wangli 已提交
1193
**Example**
A
annie_wangli 已提交
1194

Z
zhangalong 已提交
1195
  ```js
A
annie_wangli 已提交
1196 1197
  const accountManager = account_osAccount.getAccountManager();
  var domainInfo = {domain: "testDomain", accountName: "testAccountName"};
A
Annie_wang 已提交
1198
  accountManager.createOsAccountForDomain(account_osAccount.OsAccountType.NORMAL, domainInfo).then((accountInfo) => {
A
annie_wangli 已提交
1199 1200 1201 1202 1203 1204 1205 1206 1207 1208
    console.log("createOsAccountForDomain, account info: " + JSON.stringify(accountInfo));
  }).catch((err) => {
    console.log("createOsAccountForDomain err: "  + JSON.stringify(err));
  });
  ```

### queryCurrentOsAccount

queryCurrentOsAccount(callback: AsyncCallback&lt;OsAccountInfo&gt;): void

A
Annie_wang 已提交
1209
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 已提交
1210

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

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

A
annie_wangli 已提交
1215 1216 1217 1218 1219 1220 1221
**Parameters**

| Name  | Type                                                | Mandatory| Description                                          |
| -------- | ---------------------------------------------------- | ---- | ---------------------------------------------- |
| callback | AsyncCallback&lt;[OsAccountInfo](#osaccountinfo)&gt; | Yes  | Callback used to return information about the OS account obtained.|

**Example**
A
annie_wangli 已提交
1222

Z
zhangalong 已提交
1223
  ```js
A
annie_wangli 已提交
1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234
  const accountManager = account_osAccount.getAccountManager();
  accountManager.queryCurrentOsAccount((err, curAccountInfo)=>{
    console.log("queryCurrentOsAccount err:" + JSON.stringify(err));
    console.log("queryCurrentOsAccount curAccountInfo:" + JSON.stringify(curAccountInfo));
  });
  ```

### queryCurrentOsAccount

queryCurrentOsAccount(): Promise&lt;OsAccountInfo&gt;

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

A
annie_wangli 已提交
1237 1238 1239 1240
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

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

A
Annie_wang 已提交
1241
**Return value**
A
annie_wangli 已提交
1242

A
annie_wangli 已提交
1243 1244 1245
| Type                                          | Description                                                        |
| :--------------------------------------------- | :----------------------------------------------------------- |
| Promise&lt;[OsAccountInfo](#osaccountinfo)&gt; | Promise used to return information about the OS account obtained.|
A
annie_wangli 已提交
1246

A
annie_wangli 已提交
1247
**Example**
A
annie_wangli 已提交
1248

Z
zhangalong 已提交
1249
  ```js
A
annie_wangli 已提交
1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261
  const accountManager = account_osAccount.getAccountManager();
  accountManager.queryCurrentOsAccount().then((accountInfo) => {
    console.log("queryCurrentOsAccount, accountInfo: " + JSON.stringify(accountInfo));
  }).catch((err) => {
    console.log("queryCurrentOsAccount err: "  + JSON.stringify(err));
  });
  ```

### queryOsAccountById

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

A
Annie_wang 已提交
1262
Obtains information about an OS account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1263

A
annie_wangli 已提交
1264
This is a system API and cannot be called by third-party applications.
A
annie_wangli 已提交
1265

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

A
annie_wangli 已提交
1268 1269 1270 1271 1272 1273 1274 1275 1276 1277
**System capability**: SystemCapability.Account.OsAccount

**Parameters**

| Name  | Type                                                | Mandatory| Description                                    |
| -------- | ---------------------------------------------------- | ---- | ---------------------------------------- |
| localId  | number                                               | Yes  | ID of the target OS account.                    |
| callback | AsyncCallback&lt;[OsAccountInfo](#osaccountinfo)&gt; | Yes  | Callback used to return the OS account information obtained.|

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

Z
zhangalong 已提交
1279
  ```js
A
annie_wangli 已提交
1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291
  const accountManager = account_osAccount.getAccountManager();
  var localId = 100;
  accountManager.queryOsAccountById(localId, (err, accountInfo)=>{
    console.log("queryOsAccountById err:" + JSON.stringify(err));
    console.log("queryOsAccountById accountInfo:" + JSON.stringify(accountInfo));
  });
  ```

### queryOsAccountById

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

A
Annie_wang 已提交
1292
Obtains information about an OS account. This API uses a promise to return the result.
A
annie_wangli 已提交
1293

A
annie_wangli 已提交
1294 1295
This is a system API and cannot be called by third-party applications.

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

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

A
annie_wangli 已提交
1300
**Parameters**
A
annie_wangli 已提交
1301

A
annie_wangli 已提交
1302 1303 1304
| Name | Type  | Mandatory| Description                |
| ------- | ------ | ---- | -------------------- |
| localId | number | Yes  | ID of the target OS account.|
A
annie_wangli 已提交
1305

A
Annie_wang 已提交
1306
**Return value**
A
annie_wangli 已提交
1307 1308 1309 1310 1311 1312

| Type                                          | Description                                                        |
| :--------------------------------------------- | :----------------------------------------------------------- |
| Promise&lt;[OsAccountInfo](#osaccountinfo)&gt; | Promise used to return the OS account information obtained.|

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

Z
zhangalong 已提交
1314
  ```js
A
annie_wangli 已提交
1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327
  const accountManager = account_osAccount.getAccountManager();
  var localId = 100;
  accountManager.queryOsAccountById(localId).then((accountInfo) => {
    console.log("queryOsAccountById, accountInfo: " + JSON.stringify(accountInfo));
  }).catch((err) => {
    console.log("queryOsAccountById err: "  + JSON.stringify(err));
  });
  ```

### getOsAccountTypeFromProcess

getOsAccountTypeFromProcess(callback: AsyncCallback&lt;OsAccountType&gt;): void

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

A
annie_wangli 已提交
1330 1331 1332
**System capability**: SystemCapability.Account.OsAccount

**Parameters**
A
annie_wangli 已提交
1333

A
annie_wangli 已提交
1334 1335 1336
| Name  | Type                                                | Mandatory| Description                                                |
| -------- | ---------------------------------------------------- | ---- | ---------------------------------------------------- |
| callback | AsyncCallback&lt;[OsAccountType](#osaccounttype)&gt; | Yes  | Callback used to return the OS account type.|
A
annie_wangli 已提交
1337

A
annie_wangli 已提交
1338
**Example**
A
annie_wangli 已提交
1339

Z
zhangalong 已提交
1340
  ```js
A
annie_wangli 已提交
1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351
  const accountManager = account_osAccount.getAccountManager();
  accountManager.getOsAccountTypeFromProcess((err, accountType) => {
    console.log("getOsAccountTypeFromProcess err: " + JSON.stringify(err));
    console.log('getOsAccountTypeFromProcess accountType: ' + accountType);
  });
  ```

### getOsAccountTypeFromProcess

getOsAccountTypeFromProcess(): Promise&lt;OsAccountType&gt;

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

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

A
Annie_wang 已提交
1356
**Return value**
A
annie_wangli 已提交
1357

A
annie_wangli 已提交
1358 1359 1360 1361 1362
| Type                                          | Description                                                        |
| :--------------------------------------------- | :----------------------------------------------------------- |
| Promise&lt;[OsAccountType](#osaccounttype)&gt; | Promise used to return the OS account type.|

**Example**
A
annie_wangli 已提交
1363

Z
zhangalong 已提交
1364
  ```js
A
annie_wangli 已提交
1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376
  const accountManager = account_osAccount.getAccountManager();
  accountManager.getOsAccountTypeFromProcess().then((accountType) => {
    console.log('getOsAccountTypeFromProcess, accountType: ' + accountType);
  }).catch((err) => {
    console.log("getOsAccountTypeFromProcess err: "  + JSON.stringify(err));
  });
  ```

### getDistributedVirtualDeviceId

getDistributedVirtualDeviceId(callback: AsyncCallback&lt;string&gt;): void

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

Z
zhangalong 已提交
1379
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC or ohos.permission.MANAGE_LOCAL_ACCOUNTS
A
annie_wangli 已提交
1380 1381

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

A
annie_wangli 已提交
1383
**Parameters**
A
annie_wangli 已提交
1384

A
annie_wangli 已提交
1385 1386 1387 1388 1389
| Name  | Type                       | Mandatory| Description                                |
| -------- | --------------------------- | ---- | ------------------------------------ |
| callback | AsyncCallback&lt;string&gt; | Yes  | Callback used to return the device ID obtained.|

**Example**
A
annie_wangli 已提交
1390

Z
zhangalong 已提交
1391
  ```js
A
annie_wangli 已提交
1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402
  const accountManager = account_osAccount.getAccountManager();
  accountManager.getDistributedVirtualDeviceId((err, virtualID) => {
    console.log("getDistributedVirtualDeviceId err: " + JSON.stringify(err));
    console.log('getDistributedVirtualDeviceId virtualID: ' + virtualID);
  });
  ```

### getDistributedVirtualDeviceId

getDistributedVirtualDeviceId(): Promise&lt;string&gt;

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

Z
zhangalong 已提交
1405
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC or ohos.permission.MANAGE_LOCAL_ACCOUNTS
A
annie_wangli 已提交
1406 1407

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

A
Annie_wang 已提交
1409
**Return value**
A
annie_wangli 已提交
1410

A
annie_wangli 已提交
1411 1412 1413 1414 1415
| Type                 | Description                                                        |
| :-------------------- | :----------------------------------------------------------- |
| Promise&lt;string&gt; | Promise used to return the device ID obtained.|

**Example**
A
annie_wangli 已提交
1416

Z
zhangalong 已提交
1417
  ```js
A
annie_wangli 已提交
1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429
  const accountManager = account_osAccount.getAccountManager();
  accountManager.getDistributedVirtualDeviceId().then((virtualID) => {
    console.log('getDistributedVirtualDeviceId, virtualID: ' + virtualID);
  }).catch((err) => {
    console.log("getDistributedVirtualDeviceId err: "  + JSON.stringify(err));
  });
  ```

### getOsAccountProfilePhoto

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

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

A
annie_wangli 已提交
1432 1433 1434 1435 1436 1437 1438
This is a system API and cannot be called by third-party applications.

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

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

**Parameters**
A
annie_wangli 已提交
1439

A
annie_wangli 已提交
1440 1441 1442 1443
| Name  | Type                       | Mandatory| Description                                    |
| -------- | --------------------------- | ---- | ---------------------------------------- |
| localId  | number                      | Yes  | ID of the target OS account.                            |
| callback | AsyncCallback&lt;string&gt; | Yes  | Callback used to return the profile photo obtained.|
A
annie_wangli 已提交
1444

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

Z
zhangalong 已提交
1447
  ```js
A
annie_wangli 已提交
1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459
  const accountManager = account_osAccount.getAccountManager();
  var localId = 100;
  accountManager.getOsAccountProfilePhoto(localId, (err, photo)=>{
    console.log("getOsAccountProfilePhoto err:" + JSON.stringify(err));
    console.log("get photo:" + photo + " by localId: " + localId);
  });
  ```

### getOsAccountProfilePhoto

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

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

A
annie_wangli 已提交
1462
This is a system API and cannot be called by third-party applications.
A
annie_wangli 已提交
1463

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

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

A
annie_wangli 已提交
1468
**Parameters**
A
annie_wangli 已提交
1469

A
annie_wangli 已提交
1470 1471 1472 1473
| Name | Type  | Mandatory| Description        |
| ------- | ------ | ---- | ------------ |
| localId | number | Yes  | ID of the target OS account.|

A
Annie_wang 已提交
1474
**Return value**
A
annie_wangli 已提交
1475 1476 1477 1478 1479 1480

| Type                 | Description                                                        |
| :-------------------- | :----------------------------------------------------------- |
| Promise&lt;string&gt; | Promise used to return the profile photo obtained.|

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

Z
zhangalong 已提交
1482
  ```js
A
annie_wangli 已提交
1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495
  const accountManager = account_osAccount.getAccountManager();
  var localId = 100;
  accountManager.getOsAccountProfilePhoto(localId).then((photo) => {
    console.log("getOsAccountProfilePhoto: " + photo);
  }).catch((err) => {
    console.log("getOsAccountProfilePhoto err: "  + JSON.stringify(err));
  });
  ```

### setOsAccountProfilePhoto

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

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

A
annie_wangli 已提交
1498 1499 1500
This is a system API and cannot be called by third-party applications.

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

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

A
annie_wangli 已提交
1504 1505 1506 1507 1508 1509 1510 1511 1512
**Parameters**

| Name  | Type                     | Mandatory| Description        |
| -------- | ------------------------- | ---- | ------------ |
| localId  | number                    | Yes  | ID of the target OS account.|
| photo    | string                    | Yes  | Profile photo information.  |
| callback | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result.  |

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

Z
zhangalong 已提交
1514
  ```js
A
annie_wangli 已提交
1515 1516 1517 1518 1519 1520
  const accountManager = account_osAccount.getAccountManager();
  var localId = 100;
  var photo = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAAPCAYAAAA/I0V3AAAAAXNSR0IArs4c6QAAAARnQU1BAA"+
  "Cxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACwSURBVDhPvZLBDYMwDEV/ugsXRjAT0EHCOuFIBwkbdIRewi6unbiAyoGgSn1SFH85+Y"+
  "q/4ljARW62X+LHS8uIzjm4dXUYF+utzBikB52Jo5e5iEPKqpACk7R9NM2RvWm5tIkD2czLCUFNKLD6IjdMHFHDzws285MgGrT0xCtp3WOKHo"+
  "+7q0mP0DZW9pNmoEFUzrQjp5cCnaen2kSJXLFD8ghbXyZCMQf/8e8Ns1XVAG/XAgqKzVnJFAAAAABJRU5ErkJggg=="
A
Annie_wang 已提交
1521
  accountManager.setOsAccountProfilePhoto(localId, photo, (err)=>{
A
annie_wangli 已提交
1522 1523 1524 1525 1526 1527 1528 1529
    console.log("setOsAccountProfilePhoto err:" + JSON.stringify(err));
  });
  ```

### setOsAccountProfilePhoto

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

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

A
annie_wangli 已提交
1532 1533 1534
This is a system API and cannot be called by third-party applications.

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

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

A
annie_wangli 已提交
1538
**Parameters**
A
annie_wangli 已提交
1539

A
annie_wangli 已提交
1540 1541 1542 1543
| Name | Type  | Mandatory| Description        |
| ------- | ------ | ---- | ------------ |
| localId | number | Yes  | ID of the target OS account.|
| photo   | string | Yes  | Profile photo information.  |
A
annie_wangli 已提交
1544

A
Annie_wang 已提交
1545
**Return value**
A
annie_wangli 已提交
1546 1547 1548 1549 1550 1551

| Type               | Description                               |
| :------------------ | :---------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|

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

Z
zhangalong 已提交
1553
  ```js
A
annie_wangli 已提交
1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566
  const accountManager = account_osAccount.getAccountManager();
  var localId = 100;
  var photo = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAAPCAYAAAA/I0V3AAAAAXNSR0IArs4c6QAAAARnQU1BAA"+
  "Cxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACwSURBVDhPvZLBDYMwDEV/ugsXRjAT0EHCOuFIBwkbdIRewi6unbiAyoGgSn1SFH85+Y"+
  "q/4ljARW62X+LHS8uIzjm4dXUYF+utzBikB52Jo5e5iEPKqpACk7R9NM2RvWm5tIkD2czLCUFNKLD6IjdMHFHDzws285MgGrT0xCtp3WOKHo"+
  "+7q0mP0DZW9pNmoEFUzrQjp5cCnaen2kSJXLFD8ghbXyZCMQf/8e8Ns1XVAG/XAgqKzVnJFAAAAABJRU5ErkJggg=="
  accountManager.setOsAccountProfilePhoto(localId, photo).then(() => {
    console.log("setOsAccountProfilePhoto success");
  }).catch((err) => {
    console.log("setOsAccountProfilePhoto err: "  + JSON.stringify(err));
  });
  ```

A
annie_wangli 已提交
1567
### getOsAccountLocalIdBySerialNumber<sup>8+</sup>
A
annie_wangli 已提交
1568 1569 1570

getOsAccountLocalIdBySerialNumber(serialNumber: number, callback: AsyncCallback&lt;number&gt;): void

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

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

A
annie_wangli 已提交
1575
**Parameters**
A
annie_wangli 已提交
1576

A
annie_wangli 已提交
1577 1578 1579 1580 1581 1582
| Name      | Type                       | Mandatory| Description                                            |
| ------------ | --------------------------- | ---- | ------------------------------------------------ |
| serialNumber | number                      | Yes  | Account SN.                                      |
| callback     | AsyncCallback&lt;number&gt; | Yes  | Callback used to return the OS account ID obtained.|

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

Z
zhangalong 已提交
1584
  ```js
A
annie_wangli 已提交
1585 1586 1587 1588 1589 1590 1591 1592
  const accountManager = account_osAccount.getAccountManager();
  var 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_wangli 已提交
1593
### getOsAccountLocalIdBySerialNumber<sup>8+</sup>
A
annie_wangli 已提交
1594 1595 1596

getOsAccountLocalIdBySerialNumber(serialNumber: number): Promise&lt;number&gt;

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

A
annie_wangli 已提交
1599 1600 1601
**System capability**: SystemCapability.Account.OsAccount

**Parameters**
A
annie_wangli 已提交
1602

A
annie_wangli 已提交
1603 1604 1605
| Name      | Type  | Mandatory| Description      |
| ------------ | ------ | ---- | ---------- |
| serialNumber | number | Yes  | Account SN.|
A
annie_wangli 已提交
1606

A
Annie_wang 已提交
1607
**Return value**
A
annie_wangli 已提交
1608

A
annie_wangli 已提交
1609 1610 1611
| Type                 | Description                                                        |
| :-------------------- | :----------------------------------------------------------- |
| Promise&lt;number&gt; | Promise used to return the OS account ID obtained.|
A
annie_wangli 已提交
1612

A
annie_wangli 已提交
1613
**Example**: Obtain the ID of the OS account whose SN is **12345**.
A
annie_wangli 已提交
1614

Z
zhangalong 已提交
1615
  ```js
A
annie_wangli 已提交
1616 1617 1618 1619 1620 1621 1622 1623 1624
  const accountManager = account_osAccount.getAccountManager();
  var serialNumber = 12345;
  accountManager.getOsAccountLocalIdBySerialNumber(serialNumber).then((localId) => {
    console.log("getOsAccountLocalIdBySerialNumber localId: " + localId);
  }).catch((err) => {
    console.log("getOsAccountLocalIdBySerialNumber err: "  + JSON.stringify(err));
  });
  ```

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

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

A
Annie_wang 已提交
1629
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 已提交
1630

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

A
annie_wangli 已提交
1633
**Parameters**
A
annie_wangli 已提交
1634

A
annie_wangli 已提交
1635 1636 1637 1638 1639 1640
| Name  | Type                       | Mandatory| Description                                      |
| -------- | --------------------------- | ---- | ------------------------------------------ |
| localId  | number                      | Yes  | ID of the target OS account.                              |
| callback | AsyncCallback&lt;number&gt; | Yes  | Callback used to return the account SN obtained.|

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

Z
zhangalong 已提交
1642
  ```js
A
annie_wangli 已提交
1643 1644 1645 1646 1647 1648 1649 1650
  const accountManager = account_osAccount.getAccountManager();
  var 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_wangli 已提交
1651
### getSerialNumberByOsAccountLocalId<sup>8+</sup>
A
annie_wangli 已提交
1652 1653 1654

getSerialNumberByOsAccountLocalId(localId: number): Promise&lt;number&gt;

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

A
annie_wangli 已提交
1657 1658 1659
**System capability**: SystemCapability.Account.OsAccount

**Parameters**
A
annie_wangli 已提交
1660

A
annie_wangli 已提交
1661 1662 1663
| Name | Type  | Mandatory| Description        |
| ------- | ------ | ---- | ------------ |
| localId | number | Yes  | ID of the target OS account.|
A
annie_wangli 已提交
1664

A
Annie_wang 已提交
1665
**Return value**
A
annie_wangli 已提交
1666

A
annie_wangli 已提交
1667 1668 1669
| Type                 | Description                                                        |
| :-------------------- | :----------------------------------------------------------- |
| Promise&lt;number&gt; | Promise used to return the account SN obtained.|
A
annie_wangli 已提交
1670

A
annie_wangli 已提交
1671
**Example**: Obtain the SN of OS account 100.
A
annie_wangli 已提交
1672

Z
zhangalong 已提交
1673
  ```js
A
annie_wangli 已提交
1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686
  const accountManager = account_osAccount.getAccountManager();
  var localId = 100;
  accountManager.getSerialNumberByOsAccountLocalId(localId).then((serialNumber) => {
    console.log("getSerialNumberByOsAccountLocalId serialNumber: " + serialNumber);
  }).catch((err) => {
    console.log("getSerialNumberByOsAccountLocalId err: "  + JSON.stringify(err));
  });
  ```

### on

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

A
Annie_wang 已提交
1687
Subscribes to OS account changes. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1688

A
annie_wangli 已提交
1689 1690 1691 1692 1693
This is a system API and cannot be called by third-party applications.

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

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

A
annie_wangli 已提交
1695
**Parameters**
A
annie_wangli 已提交
1696

A
annie_wangli 已提交
1697 1698 1699 1700 1701 1702 1703
| Name  | Type                      | Mandatory| Description                                                        |
| -------- | -------------------------- | ---- | ------------------------------------------------------------ |
| type     | 'activate' \| 'activating' | Yes  | Type of the event to subscribe to. 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.          |
| callback | Callback&lt;number&gt;     | Yes  | Callback used to return the OS account ID and status changes.  |

**Example**
A
annie_wangli 已提交
1704

Z
zhangalong 已提交
1705
  ```js
A
annie_wangli 已提交
1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716
  const accountManager = account_osAccount.getAccountManager();
  function onCallback(receiveLocalId){
    console.log("receive localId:" + receiveLocalId);
  }
  accountManager.on("activating", "osAccountOnOffNameA", onCallback);
  ```

### off

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

A
Annie_wang 已提交
1717
Unsubscribes from the OS account changes. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1718

A
annie_wangli 已提交
1719 1720 1721 1722 1723 1724 1725
This is a system API and cannot be called by third-party applications.

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

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

**Parameters**
A
annie_wangli 已提交
1726

A
annie_wangli 已提交
1727 1728 1729 1730 1731
| 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()**.|
| callback | Callback&lt;number&gt;     | No  | Callback used to return the OS account changes. By default, **0** is returned.                     |
A
annie_wangli 已提交
1732

A
annie_wangli 已提交
1733
**Example**
A
annie_wangli 已提交
1734

Z
zhangalong 已提交
1735
  ```js
A
annie_wangli 已提交
1736 1737 1738 1739 1740 1741 1742
  const accountManager = account_osAccount.getAccountManager();
  function offCallback(){
    console.log("off enter")
  }
  accountManager.off("activating", "osAccountOnOffNameA", offCallback);
  ```

A
Annie_wang 已提交
1743 1744 1745 1746
### getBundleIdFromUid<sup>9+</sup>

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

A
Annie_wang 已提交
1747
Obtains the bundle ID based on the UID. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
1748 1749 1750 1751 1752 1753 1754 1755 1756 1757

This is a system API and cannot be called by third-party applications.

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

**Parameters**

| Name  | Type                      | Mandatory| Description                                                        |
| -------- | -------------------------- | ---- | ------------------------------------------------------------ |
| uid     | number | Yes  |  Process UID.|
A
Annie_wang 已提交
1758
| callback | AsyncCallback&lt;number&gt;     | Yes  | Callback invoked to return the bundle ID obtained.                     |
A
Annie_wang 已提交
1759 1760 1761 1762

**Example**

  ```js
A
Annie_wang 已提交
1763
  const accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
1764
  var testUid = 1000000;
A
Annie_wang 已提交
1765
  accountManager.getBundleIdFromUid(testUid, (err, bundleId) => {
A
Annie_wang 已提交
1766 1767 1768 1769 1770 1771 1772 1773
    console.info("getBundleIdFromUid errInfo:" + JSON.stringify(err));
    console.info("getBundleIdFromUid bundleId:" + JSON.stringify(bundleId));
  });
  ```
### getBundleIdFromUid<sup>9+</sup>

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

A
Annie_wang 已提交
1774
Obtains the bundle ID based on the UID. This API uses a promise to return the result.
A
Annie_wang 已提交
1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785

This is a system API and cannot be called by third-party applications.

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

**Parameters**

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

A
Annie_wang 已提交
1786
**Return value**
A
Annie_wang 已提交
1787 1788 1789 1790 1791 1792 1793 1794

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

**Example**

  ```js
A
Annie_wang 已提交
1795
  const accountManager = account_osAccount.getAccountManager();
A
Annie_wang 已提交
1796
  var testUid = 1000000;
A
Annie_wang 已提交
1797 1798 1799 1800 1801
  accountManager.getBundleIdFromUid(testUid).then((result) => {
    console.info("getBundleIdFromUid bundleId:" + JSON.stringify(result));
  }).catch((err)=>{
    console.info("getBundleIdFromUid errInfo:" + JSON.stringify(err));
  });
A
Annie_wang 已提交
1802 1803 1804 1805 1806 1807 1808 1809 1810 1811
  ```

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

This is a system API and cannot be called by third-party applications.

A
Annie_wang 已提交
1812 1813
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

A
Annie_wang 已提交
1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824
**System capability**: SystemCapability.Account.OsAccount

**Parameters**

| Name  | Type                      | Mandatory| Description                                                        |
| -------- | -------------------------- | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback&lt;boolean&gt;     | Yes  | Callback used to return the result. If the current process belongs to the main OS account, **true** will be returned. Otherwise, **false** will be returned.                     |

**Example**

  ```js
A
Annie_wang 已提交
1825 1826
  const accountManager = account_osAccount.getAccountManager();
  accountManager.isMainOsAccount((err,result)=>{
A
Annie_wang 已提交
1827 1828 1829 1830 1831 1832 1833 1834
    console.info("isMainOsAccount errInfo:" + JSON.stringify(err));
    console.info("isMainOsAccount result:" + JSON.stringify(result));
  });
  ```
### isMainOsAccount<sup>9+</sup>

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

A
Annie_wang 已提交
1835
Checks whether the current process belongs to the main OS account. This API uses a promise to return the result.
A
Annie_wang 已提交
1836 1837 1838

This is a system API and cannot be called by third-party applications.

A
Annie_wang 已提交
1839 1840
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS

A
Annie_wang 已提交
1841 1842
**System capability**: SystemCapability.Account.OsAccount

A
Annie_wang 已提交
1843
**Return value**
A
Annie_wang 已提交
1844 1845 1846 1847 1848 1849 1850 1851

| Type                 | Description                                                        |
| :-------------------- | :----------------------------------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the result. If the current process belongs to the main OS account, **true** will be returned. Otherwise, **false** will be returned.|

**Example**

  ```js
A
Annie_wang 已提交
1852 1853 1854 1855
  const accountManager = account_osAccount.getAccountManager();
  accountManager.isMainOsAccount().then((result) => {
    console.info("isMainOsAccount result:" + JSON.stringify(result));
  }).catch((err)=>{
A
Annie_wang 已提交
1856 1857 1858 1859 1860 1861 1862
    console.info("isMainOsAccount errInfo:" + JSON.stringify(err));
  });
  ```
### queryOsAccountConstraintSourceTypes<sup>9+</sup>

queryOsAccountConstraintSourceTypes(localId: number, constraint: string, callback: AsyncCallback&lt;Array&lt;ConstraintSourceTypeInfo&gt;&gt;): void;

A
Annie_wang 已提交
1863
Obtains the constraint source information of an OS account. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876

This is a system API and cannot be called by third-party applications.

**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.|
A
Annie_wang 已提交
1877
| callback | AsyncCallback&lt;Array&lt;[ConstraintSourceTypeInfo](#constraintsourcetypeinfo)&gt;&gt;     | Yes  | Callback invoked to return the source information about the specified [constraint](#constraints).                     |
A
Annie_wang 已提交
1878 1879 1880 1881

**Example**

  ```js
A
Annie_wang 已提交
1882 1883
  const accountManager = account_osAccount.getAccountManager();
  accountManager.queryOsAccountConstraintSourceTypes(100, "constraint.wifi",(err,sourceTypeInfos)=>{
A
Annie_wang 已提交
1884 1885 1886 1887 1888 1889 1890 1891 1892
    console.info("queryOsAccountConstraintSourceType errInfo:" + JSON.stringify(err));
    console.info("queryOsAccountConstraintSourceType sourceTypeInfos:" + JSON.stringify(sourceTypeInfos));
  });
  ```

### queryOsAccountConstraintSourceTypes<sup>9+</sup>

queryOsAccountConstraintSourceTypes(localId: number, constraint: string): Promise&lt;Array&lt;ConstraintSourceTypeInfo&gt;&gt;;

A
Annie_wang 已提交
1893
Obtains the constraint source information of an OS account. This API uses a promise to return the result.
A
Annie_wang 已提交
1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907

This is a system API and cannot be called by third-party applications.

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

A
Annie_wang 已提交
1908
**Return value**
A
Annie_wang 已提交
1909 1910 1911

| Type                 | Description                                                        |
| :-------------------- | :----------------------------------------------------------- |
A
Annie_wang 已提交
1912
| Promise&lt;Array&lt;[ConstraintSourceTypeInfo](#constraintsourcetypeinfo)&gt;&gt; | Promise used to return the source information about the specified [constraint](#constraints).|
A
Annie_wang 已提交
1913 1914 1915 1916

**Example**

  ```js
A
Annie_wang 已提交
1917 1918 1919 1920 1921 1922
  const accountManager = account_osAccount.getAccountManager();
  accountManager.queryOsAccountConstraintSourceTypes(100, "constraint.wifi").then((result) => {
    console.info("queryOsAccountConstraintSourceType sourceTypeInfos:" + JSON.stringify(result));
  }).catch((err)=>{
    console.info("queryOsAccountConstraintSourceType errInfo:" + JSON.stringify(err));
  });
A
Annie_wang 已提交
1923 1924
  ```

A
Annie_wang 已提交
1925 1926 1927 1928
## UserAuth<sup>8+</sup>

Provides APIs for user authentication.

A
Annie_wang 已提交
1929 1930
This is a system API and cannot be called by third-party applications.

A
Annie_wang 已提交
1931 1932 1933 1934 1935 1936
### constructor<sup>8+</sup>

constructor()

A constructor used to create an instance for user authentication.

A
Annie_wang 已提交
1937 1938
This is a system API and cannot be called by third-party applications.

A
Annie_wang 已提交
1939 1940 1941 1942
**System capability**: SystemCapability.Account.OsAccount

**Example**
  ```js
A
Annie_wang 已提交
1943
  let userAuth = new account_osAccount.UserAuth();
A
Annie_wang 已提交
1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964
  ```


### getVersion<sup>8+</sup>

getVersion(): number;

Obtains version information.

This is a system API and cannot be called by third-party applications.

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

**Return value**

| Type  | Description        |
| :----- | :----------- |
| number | Version information obtained.|

**Example**
  ```js
A
Annie_wang 已提交
1965 1966 1967
  let userAuth = new account_osAccount.UserAuth();
  let version = userAuth.getVersion();
  console.log("getVersion version = " + version);
A
Annie_wang 已提交
1968 1969 1970 1971 1972 1973
  ```

### getAvailableStatus<sup>8+</sup>

getAvailableStatus(authType: AuthType, authTrustLevel: AuthTrustLevel): number;

A
Annie_wang 已提交
1974
Checks whether the identity authentication feature is available.
A
Annie_wang 已提交
1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985

This is a system API and cannot be called by third-party applications.

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

**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL

**Parameters**

| Name          | Type                                          | Mandatory| Description                      |
| --------------- | -----------------------------------------------| ---- | ------------------------- |
A
Annie_wang 已提交
1986 1987
| authType        | [AuthType](#authtype8)             | Yes  | Authentication credential type.    |
| authTrustLevel  | [AuthTrustLevel](#authtrustlevel8) | Yes  | Trust level of the authentication result.|
A
Annie_wang 已提交
1988 1989 1990 1991 1992

**Return value**

| Type  | Description                                      |
| :----- | :---------------------------------------- |
A
Annie_wang 已提交
1993
| number | [Result code](#resultcode8).| 
A
Annie_wang 已提交
1994 1995 1996

**Example**
  ```js
A
Annie_wang 已提交
1997 1998 1999 2000 2001
  let userAuth = new account_osAccount.UserAuth();
  let authType = account_osAccount.AuthType.PIN;
  let authTrustLevel = account_osAccount.AuthTrustLevel.ATL1;
  let status = userAuth.getAvailableStatus(authType, authTrustLevel);
  console.log("getAvailableStatus status = " + status);
A
Annie_wang 已提交
2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019
  ```

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

This is a system API and cannot be called by third-party applications.

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

**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL

**Parameters**

| Name   | Type                                                                   | Mandatory| Description                               |
| -------- | ----------------------------------------------------------------------- | ---- | ---------------------------------- |
A
Annie_wang 已提交
2020 2021
| request  | [GetPropertyRequest](#getpropertyrequest8)                  | Yes  | Request information, including the authentication credential type and property list.|
| callback | AsyncCallback&lt;[ExecutorProperty](#executorproperty8)&gt; | Yes  | Callback invoked to return the executor property obtained.       |
A
Annie_wang 已提交
2022 2023 2024

**Example**
  ```js
A
Annie_wang 已提交
2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038
  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
  };
  userAuth.getProperty(request, (err, result) => {
    console.log("getProperty err = " + JSON.stringify(err));
    console.log("getProperty result = " + JSON.stringify(result));
  });
A
Annie_wang 已提交
2039 2040 2041 2042
  ```

### getProperty<sup>8+</sup>

A
Annie_wang 已提交
2043
getProperty(request: GetPropertyRequest): Promise&lt;ExecutorProperty&gt;;
A
Annie_wang 已提交
2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056

Obtains the executor property based on the request. This API uses a promise to return the result.

This is a system API and cannot be called by third-party applications.

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

**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL

**Parameters**

| Name   | Type                                                  | Mandatory| Description                               |
| -------- | ------------------------------------------------------ | ---- | ---------------------------------- |
A
Annie_wang 已提交
2057
| request  | [GetPropertyRequest](#getpropertyrequest8) | Yes  | Request information, including the authentication credential type and property list.|
A
Annie_wang 已提交
2058 2059 2060 2061 2062

**Return value**

| Type                                                             | Description                                                |
| :---------------------------------------------------------------- | :-------------------------------------------------- |
A
Annie_wang 已提交
2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080
| Promise&lt;[ExecutorProperty](#executorproperty8)&gt; | Promise used to return the executor property obtained.|

**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
  };
  userAuth.getProperty(request).then((result) => {
    console.log("getProperty result = " + JSON.stringify(result));
  }).catch((err) => {
    console.log("getProperty error = " + JSON.stringify(err));
A
Annie_wang 已提交
2081 2082 2083 2084 2085
  });
  ```

### setProperty<sup>8+</sup>

A
Annie_wang 已提交
2086
setProperty(request: SetPropertyRequest, callback: AsyncCallback&lt;number&gt;): void;
A
Annie_wang 已提交
2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099

Sets the property for the initialization algorithm. This API uses an asynchronous callback to return the result.

This is a system API and cannot be called by third-party applications.

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

**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL

**Parameters**

| Name   | Type                                                 | Mandatory| Description                                                                   |
| -------- | ----------------------------------------------------- | ---- | ---------------------------------------------------------------------- |
A
Annie_wang 已提交
2100 2101
| request  | [SetPropertyRequest](#setpropertyrequest8)| Yes  | Request information, including the authentication credential type and key value to set.                                  |
| callback | AsyncCallback&lt;number&gt;                           | Yes  | Callback invoked to return the [result](#resultcode8).|
A
Annie_wang 已提交
2102 2103 2104

**Example**
  ```js
A
Annie_wang 已提交
2105 2106 2107 2108 2109 2110 2111 2112 2113
  let userAuth = new account_osAccount.UserAuth();
  let request = {
    authType: account_osAccount.AuthType.PIN,
    key: account_osAccount.SetPropertyType.INIT_ALGORITHM,
    setInfo: new Uint8Array([0])
  };
  userAuth.setProperty(request, (err, result) => {
      console.log("setProperty error = " + JSON.stringify(err));
      console.log("setProperty result = " + JSON.stringify(result));
A
Annie_wang 已提交
2114 2115 2116 2117 2118
  });
  ```

### setProperty<sup>8+</sup>

A
Annie_wang 已提交
2119
setProperty(request: SetPropertyRequest): Promise&lt;number&gt;;
A
Annie_wang 已提交
2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132

Sets the property for the initialization algorithm. This API uses a promise to return the result.

This is a system API and cannot be called by third-party applications.

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

**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL

**Parameters**

| Name   | Type                                                  | Mandatory| Description                                     |
| -------- | ------------------------------------------------------ | ---- | ---------------------------------------- |
A
Annie_wang 已提交
2133
| request  | [SetPropertyRequest](#setpropertyrequest8) | Yes  | Request information, including the authentication credential type and the key value to set.|
A
Annie_wang 已提交
2134 2135 2136 2137 2138

**Return value**

| Type                 | Description                                                                                          |
| :-------------------- | :-------------------------------------------------------------------------------------------- |
A
Annie_wang 已提交
2139
| Promise&lt;number&gt; | Promise used to return the [result](#resultcode8).|
A
Annie_wang 已提交
2140 2141 2142

**Example**
  ```js
A
Annie_wang 已提交
2143 2144 2145 2146 2147 2148 2149 2150 2151 2152
  let userAuth = new account_osAccount.UserAuth();
  let request = {
    authType: account_osAccount.AuthType.PIN,
    key: account_osAccount.SetPropertyType.INIT_ALGORITHM,
    setInfo: new Uint8Array([0])
  };
  userAuth.setProperty(request).then((result) => {
    console.log("setProperty result = " + JSON.stringify(result));
  }).catch((err) => {
    console.log("setProperty error = " + JSON.stringify(err));
A
Annie_wang 已提交
2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172
  });
  ```

### auth<sup>8+</sup>

auth(challenge: Uint8Array, authType: AuthType, authTrustLevel: AuthTrustLevel, callback: IUserAuthCallback): Uint8Array;

Performs authentication. This API uses a callback to return the result.

This is a system API and cannot be called by third-party applications.

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

**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL

**Parameters**

| Name          | Type                                                | Mandatory| Description                               |
| --------------- | ---------------------------------------------------- | --- | ------------------------------------ |
| challenge       | Uint8Array                                           | Yes | Challenge value, which is a random number used to improve security.|
A
Annie_wang 已提交
2173 2174 2175
| authType        | [AuthType](#authtype8)                   | Yes | Authentication credential type.                       |
| authTrustLevel  | [AuthTrustLevel](#authtrustlevel8)       | Yes | Trust level of the authentication result.              |
| callback        | [IUserAuthCallback](#iuserauthcallback8) | Yes | Callback invoked to return the authentication result and obtained information. |
A
Annie_wang 已提交
2176 2177 2178 2179 2180 2181 2182 2183 2184 2185


**Return value**

| Type       | Description              |
| :--------- | :----------------- |
| Uint8Array | ID of the context for canceling the authentication.|

**Example**
  ```js
A
Annie_wang 已提交
2186 2187 2188 2189 2190 2191 2192 2193 2194
  let userAuth = new account_osAccount.UserAuth();
  let challenge = new Uint8Array([0]);
  let authType = account_osAccount.AuthType.PIN;
  let authTrustLevel = account_osAccount.AuthTrustLevel.ATL1;
  userAuth.auth(challenge, authType, authTrustLevel, {
    onResult: function(result,extraInfo){
        console.log("auth result = " + result);
        console.log("auth extraInfo = " + JSON.stringify(extraInfo));
    }
A
Annie_wang 已提交
2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215
  });
  ```

### authUser<sup>8+</sup>

authUser(userId: number, challenge: Uint8Array, authType: AuthType, authTrustLevel: AuthTrustLevel, callback: IUserAuthCallback): Uint8Array;

Perform user authentication. This API uses a callback to return the result.

This is a system API and cannot be called by third-party applications.

**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 已提交
2216 2217 2218
| authType        | [AuthType](#authtype8)                   | Yes | Authentication credential type.                       |
| authTrustLevel  | [AuthTrustLevel](#authtrustlevel8)       | Yes | Trust level of the authentication result.              |
| callback        | [IUserAuthCallback](#iuserauthcallback8) | Yes | Callback invoked to return the authentication result and obtained information. |
A
Annie_wang 已提交
2219 2220 2221 2222 2223 2224 2225 2226 2227 2228


**Return value**

| Type       | Description              |
| :--------- | :----------------- |
| Uint8Array | ID of the context for canceling the authentication.|

**Example**
  ```js
A
Annie_wang 已提交
2229
  let userAuth = new account_osAccount.UserAuth();
A
Annie_wang 已提交
2230
  let userID = 100;
A
Annie_wang 已提交
2231 2232 2233
  let challenge = new Uint8Array([0]);
  let authType = account_osAccount.AuthType.PIN;
  let authTrustLevel = account_osAccount.AuthTrustLevel.ATL1;
A
Annie_wang 已提交
2234
  userAuth.authUser(userID, challenge, authType, authTrustLevel, {
A
Annie_wang 已提交
2235 2236 2237 2238
    onResult: function(result,extraInfo){
        console.log("authUser result = " + result);
        console.log("authUser extraInfo = " + JSON.stringify(extraInfo));
    }
A
Annie_wang 已提交
2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263
  });
  ```

### cancelAuth<sup>8+</sup>

cancelAuth(contextID: Uint8Array): number;

Cancels authentication.

This is a system API and cannot be called by third-party applications.

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

**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL

**Parameters**

| Name   | Type      | Mandatory | Description                                       |
| ----------| ---------- | ---- | ------------------------------------------ |
| contextID | Uint8Array | Yes  | ID of the authentication context. The context ID is dynamically generated.|

**Return value**

| Type  | Description                                                      |
| :----- | :-------------------------------------------------------- |
A
Annie_wang 已提交
2264
| number | [Result code](#resultcode8).|
A
Annie_wang 已提交
2265 2266 2267

**Example**
  ```js
A
Annie_wang 已提交
2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278
  let userAuth = new account_osAccount.UserAuth();
  let pinAuth = new account_osAccount.PINAuth();
  let challenge = new Uint8Array([0]);
  let contextID = userAuth.auth(challenge, account_osAccount.AuthType.PIN, account_osAccount.AuthTrustLevel.ATL1, {
    onResult: (result, extraInfo) => {
      console.log("auth result = " + result);
      console.log("auth extraInfo = " + JSON.stringify(extraInfo));
    }
  });
  let result = userAuth.cancelAuth(contextID);
  console.log("cancelAuth result = " + result);
A
Annie_wang 已提交
2279 2280 2281 2282
  ```

## PINAuth<sup>8+</sup>

A
Annie_wang 已提交
2283 2284 2285
Provides APIs for PIN authentication.

This is a system API and cannot be called by third-party applications.
A
Annie_wang 已提交
2286 2287 2288 2289 2290 2291 2292

### constructor<sup>8+</sup>

constructor()

A constructor used to create an instance for PIN authentication.

A
Annie_wang 已提交
2293 2294
This is a system API and cannot be called by third-party applications.

A
Annie_wang 已提交
2295 2296 2297 2298
**System capability**: SystemCapability.Account.OsAccount

**Example**
  ```js
A
Annie_wang 已提交
2299
  let pinAuth = new account_osAccount.PINAuth();
A
Annie_wang 已提交
2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317
  ```

### registerInputer

registerInputer(inputer: IInputer): boolean;

Registers an inputer.

This is a system API and cannot be called by third-party applications.

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

**Required permissions**: ohos.permission.ACCESS_PIN_AUTH

**Parameters**

| Name   | Type                                | Mandatory| Description              |
| ----------| ----------------------------------- | --- | ------------------ |
A
Annie_wang 已提交
2318
| inputer   | [IInputer](#iinputer8)  | Yes | Callback invoked to obtain the PIN.|
A
Annie_wang 已提交
2319 2320 2321 2322 2323 2324 2325 2326 2327

**Return value**

| Type   | Description                                          |
| :------ | :-------------------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Example**
  ```js
A
Annie_wang 已提交
2328 2329 2330 2331 2332
  let pinAuth = new account_osAccount.PINAuth();
  let password = new Uint8Array([0, 0, 0, 0, 0]);
  let result = pinAuth.registerInputer({
      onGetData: (pinSubType, callback) => {
        callback.onSetData(pinSubType, password);
A
Annie_wang 已提交
2333
      }
A
Annie_wang 已提交
2334 2335
  });
  console.log("registerInputer result = " + result);
A
Annie_wang 已提交
2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351
  ```

### unregisterInputer

unregisterInputer(): void;

Unregisters the inputer.

This is a system API and cannot be called by third-party applications.

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

**Required permissions**: ohos.permission.ACCESS_PIN_AUTH

**Example**
  ```js
A
Annie_wang 已提交
2352
  let pinAuth = new account_osAccount.PINAuth();
A
Annie_wang 已提交
2353 2354 2355 2356 2357
  pinAuth.unregisterInputer();
  ```

## UserIdentityManager<sup>8+</sup>

A
Annie_wang 已提交
2358 2359 2360
Provides APIs for user identity management.

This is a system API and cannot be called by third-party applications.
A
Annie_wang 已提交
2361 2362 2363 2364 2365 2366 2367

### constructor<sup>8+</sup>

constructor()

A constructor used to create an instance for user authentication.

A
Annie_wang 已提交
2368 2369
This is a system API and cannot be called by third-party applications.

A
Annie_wang 已提交
2370 2371 2372 2373
**System capability**: SystemCapability.Account.OsAccount

**Example**
  ```js
A
Annie_wang 已提交
2374
  let userIDM = new account_osAccount.UserIdentityManager();
A
Annie_wang 已提交
2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392
  ```

### openSession<sup>8+</sup>

openSession(callback: AsyncCallback&lt;Uint8Array&gt;): void;

Opens a session to start identity management (IDM) so that a challenge value can be obtained. This API uses an asynchronous callback to return the result.

This is a system API and cannot be called by third-party applications.

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

**Required permissions**: ohos.permission.MANAGE_USER_IDM

**Parameters**

| Name   | Type                            | Mandatory| Description                             |
| -------- | -------------------------------- | ---- | -------------------------------- |
A
Annie_wang 已提交
2393
| callback | AsyncCallback&lt;Uint8Array&gt;  | Yes  | Callback invoked to return the challenge value. If **0** is returned, the operation failed.|
A
Annie_wang 已提交
2394 2395 2396

**Example**
  ```js
A
Annie_wang 已提交
2397 2398 2399 2400
  let userIDM = new account_osAccount.UserIdentityManager();
  userIDM.openSession((err, challenge) => {
      console.log("openSession error = " + JSON.stringify(err));
      console.log("openSession challenge = " + JSON.stringify(challenge));
A
Annie_wang 已提交
2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419
  });
  ```

### openSession<sup>8+</sup>

openSession(): Promise&lt;Uint8Array&gt;;

Opens a session to start IDM so that a challenge value can be obtained. This API uses a promise to return the result.

This is a system API and cannot be called by third-party applications.

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

**Required permissions**: ohos.permission.MANAGE_USER_IDM

**Return value**

| Type                     | Description                                                     |
| :------------------------ | :------------------------------------------------------- |
A
Annie_wang 已提交
2420
| Promise&lt;Uint8Array&gt; | Promise used to return the challenge value. If **0** is returned, the operation failed.|
A
Annie_wang 已提交
2421 2422 2423

**Example**
  ```js
A
Annie_wang 已提交
2424 2425 2426 2427 2428 2429
  let userIDM = new account_osAccount.UserIdentityManager();
  userIDM.openSession().then((challenge) => {
      console.info("openSession challenge = " + JSON.stringify(challenge));
  }).catch((err) => {
      console.info("openSession error = " + JSON.stringify(err));
  });
A
Annie_wang 已提交
2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447
  ```

### addCredential<sup>8+</sup>

addCredential(credentialInfo: CredentialInfo, callback: IIdmCallback): void;

Adds credential information, which includes the authentication credential type, subtype, and token (if a non-PIN credential is added). This API uses a callback to return the result.

This is a system API and cannot be called by third-party applications.

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

**Required permissions**: ohos.permission.MANAGE_USER_IDM

**Parameters**

| Name          | Type                                            | Mandatory| Description                           |
| --------------- | ------------------------------------------------ | --- | -------------------------------- |
A
Annie_wang 已提交
2448 2449
| credentialInfo  | [CredentialInfo](#credentialinfo8)   | Yes | Credential information to add. |
| callback        | [IIdmCallback](#iidmcallback8)       | Yes | Callback invoked to return the result and obtained information. |
A
Annie_wang 已提交
2450 2451 2452

**Example**
  ```js
A
Annie_wang 已提交
2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470
  let password = new Uint8Array([0, 0, 0, 0, 0, 0]);
  let pinAuth = new account_osAccount.PINAuth();
  pinAuth.registerInputer({
    onGetData: (pinSubType, callback) => {
      callback.onSetData(pinSubType, password);
    }
  });
  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) => {
    userIDM.addCredential(credentialInfo, {
      onResult: (result, extraInfo) => {
        console.log("updateCredential result = " + result);
        console.log("updateCredential extraInfo = " + extraInfo);
A
Annie_wang 已提交
2471
      }
A
Annie_wang 已提交
2472 2473
    });
  });
A
Annie_wang 已提交
2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491
  ```

### updateCredential<sup>8+</sup>

updateCredential(credentialInfo: CredentialInfo, callback: IIdmCallback): void;

Updates credential information. This API uses a callback to return the result.

This is a system API and cannot be called by third-party applications.

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

**Required permissions**: ohos.permission.MANAGE_USER_IDM

**Parameters**

| Name          | Type                                             | Mandatory| Description                           |
| --------------- | ------------------------------------------------- | --- | -------------------------------- |
A
Annie_wang 已提交
2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521
| credentialInfo  | [CredentialInfo](#credentialinfo8)    | Yes | New credential information.                   |
| callback        | [IIdmCallback](#iidmcallback8)        | Yes | Callback invoked to return the result and obtained information. |

**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({
    onGetData: (pinSubType, callback) => {
      callback.onSetData(pinSubType, password);
    }
  });
  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;
        userIDM.updateCredential(credentialInfo, {
          onResult: (result, extraInfo) => {
              console.log("updateCredential result = " + result);
              console.log("updateCredential extraInfo = " + extraInfo);
A
Annie_wang 已提交
2522
          }
A
Annie_wang 已提交
2523
        });
A
Annie_wang 已提交
2524
      }
A
Annie_wang 已提交
2525 2526
    });
  });
A
Annie_wang 已提交
2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542
  ```

### closeSession<sup>8+</sup>

closeSession(): void;

Closes this session to terminate IDM.

This is a system API and cannot be called by third-party applications.

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

**Required permissions**: ohos.permission.MANAGE_USER_IDM

**Example**
  ```js
A
Annie_wang 已提交
2543
  let userIDM = new account_osAccount.UserIdentityManager();
A
Annie_wang 已提交
2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568
  userIDM.closeSession();
  ```

### cancel<sup>8+</sup>

cancel(challenge: Uint8Array): number;

Cancels an entry based on the challenge value.

This is a system API and cannot be called by third-party applications.

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

**Required permissions**: ohos.permission.MANAGE_USER_IDM

**Parameters**

| Name   | Type       | Mandatory| Description  |
| -------- | ----------- | ---- | ----- |
| challenge | Uint8Array | Yes  | Challenge value.|

**Return value**

| Type  | Description                                                      |
| :----- | :-------------------------------------------------------- |
A
Annie_wang 已提交
2569
| number | [Result code](#resultcode8) indicating whether the operation is successful.|
A
Annie_wang 已提交
2570 2571 2572

**Example**
  ```js
A
Annie_wang 已提交
2573 2574 2575 2576
  let userIDM = new account_osAccount.UserIdentityManager();
  let challenge = new Uint8Array([0]);
  let result = userIDM.cancel(challenge);
  console.log("cancel result: " + result);
A
Annie_wang 已提交
2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595
  ```

### delUser<sup>8+</sup>

delUser(token: Uint8Array, callback: IIdmCallback): void;

Deletes a user based on the authentication token. The API uses a callback to return the result.

This is a system API and cannot be called by third-party applications.

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

**Required permissions**: ohos.permission.MANAGE_USER_IDM

**Parameters**

| Name   | Type                                      | Mandatory| Description                     |
| -------- | ------------------------------------------ | --- | ------------------------- |
| token    | Uint8Array                                 | Yes | Authentication token.            |
A
Annie_wang 已提交
2596
| callback | [IIdmCallback](#iidmcallback8) | Yes | Callback invoked to return the result.|
A
Annie_wang 已提交
2597 2598 2599

**Example**
  ```js
A
Annie_wang 已提交
2600 2601
  let userIDM = new account_osAccount.UserIdentityManager();
  let token = new Uint8Array([0]);
A
Annie_wang 已提交
2602
  userIDM.delUser(token, {
A
Annie_wang 已提交
2603 2604 2605 2606 2607
    onResult: (result, extraInfo) => {
      console.log("delUser result = " + result);
      console.log("delUser extraInfo = " + JSON.stringify(extraInfo));
    }
  });
A
Annie_wang 已提交
2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627
  ```

### delCred<sup>8+</sup>

delCred(credentialId: Uint8Array, token: Uint8Array, callback: IIdmCallback): void;

Deletes user credential information. The API uses a callback to return the result.

This is a system API and cannot be called by third-party applications.

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

**Required permissions**: ohos.permission.MANAGE_USER_IDM

**Parameters**

| Name          | Type                                           | Mandatory| Description                     |
| --------------- | ----------------------------------------------- | --- | ---------------------------|
| credentialId    | Uint8Array                                      | Yes | Credential ID.                 |
| token           | Uint8Array                                      | Yes | Authentication token.             |
A
Annie_wang 已提交
2628
| callback        | [IIdmCallback](#iidmcallback8)      | Yes | Callback invoked to return the result.|
A
Annie_wang 已提交
2629 2630 2631

**Example**
  ```js
A
Annie_wang 已提交
2632 2633 2634 2635 2636 2637 2638 2639 2640
  let userIDM = new account_osAccount.UserIdentityManager();
  let credentialId = new Uint8Array([0]);
  let token = new Uint8Array([0]);
  userIDM.delCred(credentialId, token, {
    onResult: (result, extraInfo) => {
        console.log("delCred result = " + result);
        console.log("delCred extraInfo = " + JSON.stringify(extraInfo));
    }
  });
A
Annie_wang 已提交
2641 2642 2643 2644
  ```

### getAuthInfo<sup>8+</sup>

A
Annie_wang 已提交
2645
getAuthInfo(callback: AsyncCallback&lt;Array&lt;EnrolledCredInfo&gt;&gt;): void;
A
Annie_wang 已提交
2646 2647 2648 2649 2650 2651 2652

Obtains authentication information. This API uses asynchronous callback to return the result.

This is a system API and cannot be called by third-party applications.

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

A
Annie_wang 已提交
2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681
**Required permissions**: ohos.permission.USE_USER_IDM

**Parameters**

| Name   | Type                                              | Mandatory| Description                                               |
| -------- | -------------------------------------------------- | ---- | -------------------------------------------------- |
| callback | AsyncCallback&lt;Array&lt;[EnrolledCredInfo](#enrolledcredinfo8)&gt;&gt; | Yes  | Callback invoked to return information about all enrolled credentials of the specified type.|


**Example**
  ```js
  let userIDM = new account_osAccount.UserIdentityManager();
  userIDM.getAuthInfo((err, result) => {
    console.log("getAuthInfo err = " + JSON.stringify(err));
    console.log("getAuthInfo result = " + JSON.stringify(result));
  });
  ```

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

This is a system API and cannot be called by third-party applications.

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

**Required permissions**: ohos.permission.USE_USER_IDM
A
Annie_wang 已提交
2682 2683 2684 2685 2686

**Parameters**

| Name   | Type                                              | Mandatory| Description                                               |
| -------- | -------------------------------------------------- | ---- | -------------------------------------------------- |
A
Annie_wang 已提交
2687 2688
| authType | [AuthType](#authtype8) | Yes  | Authentication credential type.                                         |
| callback | AsyncCallback&lt;Array&lt;[EnrolledCredInfo](#enrolledcredinfo8)&gt;&gt; | Yes  | Callback invoked to return information about all the user's enrolled credentials of the specified type.|
A
Annie_wang 已提交
2689 2690 2691

**Example**
  ```js
A
Annie_wang 已提交
2692 2693 2694 2695 2696
  let userIDM = new account_osAccount.UserIdentityManager();
  userIDM.getAuthInfo(account_osAccount.AuthType.PIN, (err, result) => {
    console.log("getAuthInfo err = " + JSON.stringify(err));
    console.log("getAuthInfo result = " + JSON.stringify(result));
  });
A
Annie_wang 已提交
2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708
  ```

### getAuthInfo<sup>8+</sup>

getAuthInfo(authType?: AuthType): Promise&lt;Array&lt;EnrolledCredInfo&gt;&gt;;

Obtains authentication information. This API uses a promise to return the result.

This is a system API and cannot be called by third-party applications.

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

A
Annie_wang 已提交
2709
**Required permissions**: ohos.permission.USE_USER_IDM
A
Annie_wang 已提交
2710 2711 2712 2713 2714

**Parameters**

| Name   | Type                               | Mandatory| Description     |
| -------- | ----------------------------------- | ---- | -------- |
A
Annie_wang 已提交
2715
| authType | [AuthType](#authtype8)  | No  | Authentication credential type.|
A
Annie_wang 已提交
2716 2717 2718 2719 2720

**Return value**

| Type                                        | Description                                                                      |
| :------------------------------------------- | :------------------------------------------------------------------------ |
A
Annie_wang 已提交
2721
| Promise&lt;Array&lt;[EnrolledCredInfo](#enrolledcredinfo8)&gt;&gt; | Promise used to return information about all the user's enrolled credentials of the specified type.|
A
Annie_wang 已提交
2722 2723 2724

**Example**
  ```js
A
Annie_wang 已提交
2725 2726 2727 2728 2729 2730
  let userIDM = new account_osAccount.UserIdentityManager();
  userIDM.getAuthInfo(account_osAccount.AuthType.PIN).then((result) => {
    console.log("getAuthInfo result = " + JSON.stringify(result))
  }).catch((err) => {
    console.log("getAuthInfo error = " + JSON.stringify(err));
  });
A
Annie_wang 已提交
2731 2732 2733 2734 2735 2736
  ```

## IInputData<sup>8+</sup>

Provides callbacks for PIN operations.

A
Annie_wang 已提交
2737 2738
This is a system API and cannot be called by third-party applications.

A
Annie_wang 已提交
2739 2740 2741 2742
### onSetData<sup>8+</sup>

onSetData: (pinSubType: AuthSubType, data: Uint8Array) => void;

A
Annie_wang 已提交
2743 2744
This is a system API and cannot be called by third-party applications.

A
Annie_wang 已提交
2745 2746 2747 2748 2749 2750 2751 2752
Called to set data.

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

**Parameters**

| Name     | Type                                    | Mandatory| Description                                           |
| ---------- | ---------------------------------------- | ---- | ----------------------------------------------- |
A
Annie_wang 已提交
2753
| pinSubType | [AuthSubType](#authsubtype8) | Yes  | Credential subtype.                           |
A
Annie_wang 已提交
2754 2755 2756 2757
| 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 已提交
2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768
  let password = new Uint8Array([0, 0, 0, 0, 0, 0]);
  let passwordNumber = new Uint8Array([1, 2, 3, 4]);
  let inputer = {
    onGetData: (pinSubType, callback) => {
        if (pinSubType == account_osAccount.AuthSubType.PIN_NUMBER) {
          callback.onSetData(pinSubType, passwordNumber);
        } else {
          callback.onSetData(pinSubType, password);
        }
    }
  };
A
Annie_wang 已提交
2769 2770 2771 2772 2773 2774
  ```

## IInputer<sup>8+</sup>

Provides callbacks for the PIN input box.

A
Annie_wang 已提交
2775 2776
This is a system API and cannot be called by third-party applications.

A
Annie_wang 已提交
2777 2778
### onGetData<sup>8+</sup>

A
Annie_wang 已提交
2779
onGetData: (pinSubType: AuthSubType, callback: IInputData) => void;
A
Annie_wang 已提交
2780 2781 2782

Called to obtain data.

A
Annie_wang 已提交
2783 2784
This is a system API and cannot be called by third-party applications.

A
Annie_wang 已提交
2785 2786 2787 2788 2789 2790
**System capability**: SystemCapability.Account.OsAccount

**Parameters**

| Name     | Type                                   | Mandatory| Description            |
| ---------- | --------------------------------------- | ---- | --------------- |
A
Annie_wang 已提交
2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808
| 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 = {
    onGetData: (pinSubType, callback) => {
        if (pinSubType == account_osAccount.AuthSubType.PIN_NUMBER) {
          callback.onSetData(pinSubType, passwordNumber);
        } else {
          callback.onSetData(pinSubType, password);
        }
    }
  };
  let pinAuth = new account_osAccount.PINAuth();
  let result = pinAuth.registerInputer(inputer);
  console.log("registerInputer result: " + result);
A
Annie_wang 已提交
2809 2810 2811 2812 2813 2814
  ```

## IUserAuthCallback<sup>8+</sup>

Provides callbacks for user authentication.

A
Annie_wang 已提交
2815 2816
This is a system API and cannot be called by third-party applications.

A
Annie_wang 已提交
2817 2818 2819 2820 2821 2822
### onResult<sup>8+</sup>

onResult: (result: number, extraInfo: AuthResult) => void;

Called to return the authentication result code.

A
Annie_wang 已提交
2823 2824
This is a system API and cannot be called by third-party applications.

A
Annie_wang 已提交
2825 2826 2827 2828 2829 2830 2831
**System capability**: SystemCapability.Account.OsAccount

**Parameters**

| Name    | Type                                   | Mandatory| Description                |
| --------- | --------------------------------------- | ---- | ------------------- |
| result    | number                                   | Yes  | Authentication result code.|
A
Annie_wang 已提交
2832
| 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 已提交
2833 2834 2835

**Example**
  ```js
A
Annie_wang 已提交
2836 2837 2838 2839 2840 2841
  let authCallback = {
    onResult: (result, extraInfo) => {
      console.log("auth result = " + result);
      console.log("auth extraInfo = " + JSON.stringify(extraInfo));
    }
  };
A
Annie_wang 已提交
2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863
  ```

### onAcquireInfo?<sup>8+</sup>

onAcquireInfo?: (module: number, acquire: number, extraInfo: any) => void;

Called to return the **TipsCode** during the authentication process.

This is a system API and cannot be called by third-party applications.

**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 已提交
2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874
  let authCallback = {
    onResult: (result, extraInfo) => {
      console.log("auth result = " + result)
      console.log("auth extraInfo = " + JSON.stringify(extraInfo));
    },
    onAcquireInfo: (module, acquire, extraInfo) => {
      console.log("auth module = " + module);
      console.log("auth acquire = " + acquire);
      console.info('auth extraInfo = ' + JSON.stringify(extraInfo));
    }
  };
A
Annie_wang 已提交
2875 2876 2877 2878 2879 2880
  ```

## IIdmCallback<sup>8+</sup>

Provides callbacks for IDM.

A
Annie_wang 已提交
2881 2882
This is a system API and cannot be called by third-party applications.

A
Annie_wang 已提交
2883 2884
### onResult<sup>8+</sup>

A
Annie_wang 已提交
2885
onResult: (result: number, extraInfo: RequestResult) => void;
A
Annie_wang 已提交
2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897

Called to return the authentication result code.

This is a system API and cannot be called by third-party applications.

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

**Parameters**

| Name    | Type                                   | Mandatory| Description                    |
| --------- | --------------------------------------- | ---- | ----------------------- |
| result    | number                                  | Yes  | Authentication result code.   |
A
Annie_wang 已提交
2898
| extraInfo | [AuthResult](#authresult8)  | Yes  | Specific information to be transferred.|
A
Annie_wang 已提交
2899 2900 2901

**Example**
  ```js
A
Annie_wang 已提交
2902 2903 2904 2905 2906 2907
  var idmCallback = {
    onResult: (result, extraInfo) => {
      console.log("callback result = " + result)
      console.info('callback extraInfo = ' + JSON.stringify(extraInfo));
    }
  };
A
Annie_wang 已提交
2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929
  ```

### onAcquireInfo?<sup>8+</sup>

onAcquireInfo?: (module: number, acquire: number, extraInfo: any) => void;

Called to return the **TipsCode** during the authentication process.

This is a system API and cannot be called by third-party applications.

**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 已提交
2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940
  let idmCallback = {
    onResult: (result, extraInfo) => {
      console.log("callback result = " + result)
      console.log("callback onResult = " + JSON.stringify(extraInfo));
    },
    onAcquireInfo: (module, acquire, extraInfo) => {
      console.log("callback module = " + module);
      console.log("callback acquire = " + acquire);
      console.log('callback onacquireinfo = ' + JSON.stringify(extraInfo));
    }
  };
A
Annie_wang 已提交
2941 2942 2943 2944 2945 2946
  ```

## GetPropertyRequest<sup>8+</sup>

Defines the request for obtaining property information.

A
Annie_wang 已提交
2947 2948
This is a system API and cannot be called by third-party applications.

A
Annie_wang 已提交
2949 2950 2951 2952
**System capability**: SystemCapability.Account.OsAccount

| Name   | Type                                                         | Mandatory  | Description                  |
| -------- | ------------------------------------------------------------- | ----- | ----------------------- |
A
Annie_wang 已提交
2953 2954
| 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 已提交
2955 2956 2957 2958 2959

## SetPropertyRequest<sup>8+</sup>

Defines the request for setting property information.

A
Annie_wang 已提交
2960 2961
This is a system API and cannot be called by third-party applications.

A
Annie_wang 已提交
2962 2963 2964 2965
**System capability**: SystemCapability.Account.OsAccount

| Name   | Type                                            | Mandatory  | Description                |
| -------- | ------------------------------------------------ | ----- | -------------------- |
A
Annie_wang 已提交
2966 2967
| authType | [AuthType](#authtype8)               | Yes   | Authentication credential type.    |
| key     | [SetPropertyType](#setpropertytype8) | Yes   | Type of the property to set.|
A
Annie_wang 已提交
2968 2969 2970 2971 2972 2973
| setInfo  | Uint8Array                                       | Yes   | Information to set.    |

## ExecutorProperty<sup>8+</sup>

Defines the executor property.

A
Annie_wang 已提交
2974 2975
This is a system API and cannot be called by third-party applications.

A
Annie_wang 已提交
2976 2977 2978 2979 2980
**System capability**: SystemCapability.Account.OsAccount

| Name       | Type                                    | Mandatory  | Description             |
| ------------ | ---------------------------------------- | ----- | ----------------- |
| result       | number                                   | Yes   | Result.        |
A
Annie_wang 已提交
2981
| authSubType  | [AuthSubType](#authsubtype8) | Yes   | Authentication credential subtype.|
A
Annie_wang 已提交
2982 2983 2984 2985 2986 2987 2988
| remainTimes  | number                                   | No   | Remaining time.    |
| freezingTime | number                                   | No   | Freezing time.    |

## AuthResult<sup>8+</sup>

Defines the authentication result information.

A
Annie_wang 已提交
2989 2990
This is a system API and cannot be called by third-party applications.

A
Annie_wang 已提交
2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002
**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 已提交
3003 3004
This is a system API and cannot be called by third-party applications.

A
Annie_wang 已提交
3005 3006 3007 3008
**System capability**: SystemCapability.Account.OsAccount

| Name       | Type                                    | Mandatory  | Description             |
| ------------ | ---------------------------------------- | ----- | ----------------- |
A
Annie_wang 已提交
3009 3010
| credType     | [AuthType](#authtype8)       | Yes   | Authentication credential type.    |
| credSubType  | [AuthSubType](#authsubtype8) | Yes   | Authentication credential subtype.  |
A
Annie_wang 已提交
3011 3012 3013 3014 3015 3016
| token        | Uint8Array                               | Yes   | Authentication token.    |

## RequestResult<sup>8+</sup>

Defines the request result information.

A
Annie_wang 已提交
3017 3018
This is a system API and cannot be called by third-party applications.

A
Annie_wang 已提交
3019 3020 3021 3022 3023 3024 3025 3026 3027 3028
**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 已提交
3029 3030
This is a system API and cannot be called by third-party applications.

A
Annie_wang 已提交
3031 3032 3033 3034 3035
**System capability**: SystemCapability.Account.OsAccount

| Name       | Type                                    | Mandatory  | Description             |
| ------------ | ---------------------------------------- | ----- | ------------------- |
| credentialId | Uint8Array                               | Yes   | Credential ID.      |
A
Annie_wang 已提交
3036 3037 3038
| authType     | [AuthType](#authtype8)       | Yes   | Authentication credential type.  |
| authSubType  | [AuthSubType](#authsubtype8) | Yes   | Credential subtype.|
| templateId   | Uint8Array                               | Yes   | Authentication credential template ID.    |
A
Annie_wang 已提交
3039 3040 3041 3042 3043

## GetPropertyType<sup>8+</sup>

Enumerates the types of the properties to obtain.

A
Annie_wang 已提交
3044 3045
This is a system API and cannot be called by third-party applications.

A
Annie_wang 已提交
3046 3047 3048 3049
**System capability**: SystemCapability.Account.OsAccount

| Name          | Default Value| Description     |
| ------------- | ------ | --------- |
A
Annie_wang 已提交
3050
| AUTH_SUB_TYPE | 1      | Authentication credential subtype.|
A
Annie_wang 已提交
3051 3052 3053 3054 3055 3056 3057
| REMAIN_TIMES  | 2      | Remaining time.  |
| FREEZING_TIME | 3      | Freezing time.  |

## SetPropertyType<sup>8+</sup>

Enumerates the types of the properties to set.

A
Annie_wang 已提交
3058 3059
This is a system API and cannot be called by third-party applications.

A
Annie_wang 已提交
3060 3061 3062 3063 3064 3065 3066 3067
**System capability**: SystemCapability.Account.OsAccount

| Name          | Default Value| Description       |
| -------------- | ----- | ----------- |
| INIT_ALGORITHM | 1     | Initialization algorithm.|

## AuthType<sup>8+</sup>

A
Annie_wang 已提交
3068 3069 3070
Enumerates the authentication credential types.

This is a system API and cannot be called by third-party applications.
A
Annie_wang 已提交
3071 3072 3073 3074 3075 3076 3077 3078 3079 3080

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

| Name | Default Value| Description            |
| ----- | ----- | ---------------- |
| PIN   | 1     | PIN authentication.|
| FACE  | 2     | Facial authentication.|

## AuthSubType<sup>8+</sup>

A
Annie_wang 已提交
3081 3082 3083
Enumerates the authentication credential subtypes.

This is a system API and cannot be called by third-party applications.
A
Annie_wang 已提交
3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098

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

| Name      | Default Value| Description              |
| ---------- | ----- | ------------------ |
| PIN_SIX    | 10000 | Six-digit PIN.      |
| PIN_NUMBER | 10001 | Custom PIN.|
| PIN_MIXED  | 10002 | Custom mixed credential.|
| FACE_2D    | 20000 | 2D face credential.  |
| FACE_3D    | 20001 | 3D face credential.  |

## AuthTrustLevel<sup>8+</sup>

Enumerates the trust levels of the authentication result.

A
Annie_wang 已提交
3099 3100
This is a system API and cannot be called by third-party applications.

A
Annie_wang 已提交
3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113
**System capability**: SystemCapability.Account.OsAccount

| Name | Default Value| Description       |
| ---- | ------ | ----------- |
| 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 已提交
3114 3115
This is a system API and cannot be called by third-party applications.

A
Annie_wang 已提交
3116 3117 3118 3119
**System capability**: SystemCapability.Account.OsAccount

| Name      | Default Value| Description                    |
| --------- | ------ | ------------------------ |
A
Annie_wang 已提交
3120
| FACE_AUTH | 1      | Face authentication module.|
A
Annie_wang 已提交
3121 3122 3123 3124 3125

## ResultCode<sup>8+</sup>

Enumerates the authentication result codes.

A
Annie_wang 已提交
3126 3127
This is a system API and cannot be called by third-party applications.

A
Annie_wang 已提交
3128 3129 3130 3131
**System capability**: SystemCapability.Account.OsAccount

| Name                   | Default Value| Description                                    |
| ----------------------- | ----- | ---------------------------------------- |
A
Annie_wang 已提交
3132
| SUCCESS                 | 0     | The authentication is successful or the authentication feature is supported.            |
A
Annie_wang 已提交
3133 3134 3135 3136 3137 3138
| 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 已提交
3139
| BUSY                    | 7     | The authentication executor is busy. Try again after a few seconds.|
A
Annie_wang 已提交
3140 3141 3142 3143 3144 3145 3146 3147
| 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 已提交
3148 3149
This is a system API and cannot be called by third-party applications.

A
Annie_wang 已提交
3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165
**System capability**: SystemCapability.Account.OsAccount

| Name                         | Default Value| Description                                    |
| ----------------------------- | ----- | ---------------------------------------- |
| 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 已提交
3166
## FingerprintTips<sup>8+</sup>
A
Annie_wang 已提交
3167 3168 3169

Enumerates the tip codes for fingerprint authentication.

A
Annie_wang 已提交
3170 3171
This is a system API and cannot be called by third-party applications.

A
Annie_wang 已提交
3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182
**System capability**: SystemCapability.Account.OsAccount

| Name                         | Default Value| Description                                           |
| ----------------------------- | ----- | ----------------------------------------------- |
| 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 已提交
3183
## OsAccountInfo
A
annie_wangli 已提交
3184

A
annie_wangli 已提交
3185
Defines information about an OS account.
A
annie_wangli 已提交
3186 3187 3188

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

A
annie_wangli 已提交
3189 3190 3191 3192 3193 3194
| 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 已提交
3195 3196 3197 3198 3199 3200 3201
| 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 已提交
3202
| distributedInfo                | [distributedAccount.DistributedInfo](js-apis-distributed-account.md) | No  | Distributed account information.                   |
A
Annie_wang 已提交
3203
| domainInfo<sup>8+</sup>        | [DomainAccountInfo](#domainaccountinfo8)                      | No  | Domain account information.                       |
A
annie_wangli 已提交
3204

Z
zhangalong 已提交
3205
## DomainAccountInfo<sup>8+</sup>
A
annie_wangli 已提交
3206

A
annie_wangli 已提交
3207 3208 3209 3210 3211 3212
Domain account information.

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

| Name     | Type  | Mandatory| Description      |
| ----------- | ------ | ---- | ---------- |
A
annie_wangli 已提交
3213
| domain      | string | Yes  | Domain name.    |
A
annie_wangli 已提交
3214
| accountName | string | Yes  | Domain account name.|
A
annie_wangli 已提交
3215 3216 3217

## Constraints

A
annie_wangli 已提交
3218 3219 3220 3221 3222 3223 3224 3225 3226 3227
| Constraint                                 | Description                          |
| ------------------------------------- | ------------------------------ |
| constraint.wifi                       | A user is not allowed to use Wi-Fi.                  |
| constraint.wifi.set                   | A user is not allowed to change Wi-Fi settings.                  |
| 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 已提交
3228
| constraint.global.unknown.app.install | All users are not allowed to install apps from unknown sources.|
A
annie_wangli 已提交
3229 3230
| 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 已提交
3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249
| 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 已提交
3250 3251
| 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 已提交
3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268
| 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 已提交
3269
| constraint.device.unmute | A user is not allowed to unmute the device.|
A
annie_wangli 已提交
3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282
| 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 已提交
3283 3284 3285 3286 3287

## ConstraintSourceTypeInfo<sup>9+</sup>

Defines information about the source of a constraint.

A
Annie_wang 已提交
3288 3289
This is a system API.

A
Annie_wang 已提交
3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300
**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 已提交
3301 3302
This is a system API.

A
Annie_wang 已提交
3303 3304 3305 3306 3307 3308 3309 3310
**System capability**: SystemCapability.Account.OsAccount

| Name  | Default Value| Description        |
| ------ | ------ | ------------ |
| 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.  |