js-apis-osAccount.md 248.9 KB
Newer Older
1
# @ohos.account.osAccount (系统帐号管理)
Z
zhangalong 已提交
2

J
jidong 已提交
3
本模块提供管理系统帐号的基础能力,包括系统帐号的添加、删除、查询、设置、订阅、启动等功能。
L
lichenchen 已提交
4

5 6
> **说明:**
>
Z
zhangalong 已提交
7 8 9 10 11
> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。


## 导入模块

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

## account_osAccount.getAccountManager

getAccountManager(): AccountManager

J
jidong 已提交
20
获取系统帐号管理对象。
Z
zhangalong 已提交
21

Z
zengyawen 已提交
22
**系统能力:** SystemCapability.Account.OsAccount
Z
zhangalong 已提交
23

Z
zengyawen 已提交
24
**返回值:**
25

J
jidong 已提交
26 27 28
| 类型                              | 说明              |
| --------------------------------- | ---------------- |
| [AccountManager](#accountmanager) | 系统帐号管理对象。 |
Z
zengyawen 已提交
29

30
**示例:**
Z
zhangalong 已提交
31
  ```js
F
fanchenxuan 已提交
32
  let accountManager = account_osAccount.getAccountManager();
Z
zhangalong 已提交
33 34 35
  ```

## OsAccountType
Z
zengyawen 已提交
36

J
jidong 已提交
37
表示系统帐号类型的枚举。
Z
zengyawen 已提交
38

J
jidong 已提交
39
**系统能力:** SystemCapability.Account.OsAccount。
Z
zengyawen 已提交
40

41
| 名称   | 值 | 说明         |
J
jidong 已提交
42
| ------ | ------ | ----------- |
Z
zengyawen 已提交
43 44 45
| ADMIN  | 0      | 管理员帐号。 |
| NORMAL | 1      | 普通帐号。   |
| GUEST  | 2      | 访客帐号。   |
Z
zhangalong 已提交
46 47 48

## AccountManager

J
jidong 已提交
49
系统帐号管理类。
Z
zhangalong 已提交
50 51 52 53 54

### activateOsAccount

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

J
jidong 已提交
55
激活指定系统帐号。使用callback异步回调。
Z
zhangalong 已提交
56

J
jidong 已提交
57
**系统接口:** 此接口为系统接口。
Z
zengyawen 已提交
58

Z
zhangalong 已提交
59 60
**需要权限:** ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION

Z
zengyawen 已提交
61
**系统能力:** SystemCapability.Account.OsAccount
Z
zhangalong 已提交
62

Z
zengyawen 已提交
63
**参数:**
Z
zhangalong 已提交
64

J
jidong 已提交
65 66 67 68 69 70 71 72 73
| 参数名   | 类型                       | 必填 | 说明                                                |
| -------- | ------------------------- | ---- | -------------------------------------------------- |
| localId  | number                    | 是   | 系统帐号ID。                  |
| callback | AsyncCallback<void> | 是   | 回调函数。当帐号激活成功时,err为null,否则为错误对象。 |

**错误码:**

| 错误码ID | 错误信息             |
| -------- | ------------------- |
J
jidong 已提交
74
| 12300001 | System service exception. |
J
jidong 已提交
75
| 12300002 | Invalid localId.    |
J
jidong 已提交
76 77 78
| 12300003 | Account not found. |
| 12300008 | Restricted Account. |
| 12300009 | Account has been activated. |
Z
zengyawen 已提交
79

80
**示例:** 激活ID为100的系统帐号
Z
zhangalong 已提交
81
  ```js
82 83
  import { BusinessError } from '@ohos.base';
  let localId: number = 100;
84
  try {
85
    accountManager.activateOsAccount(localId, (err: BusinessError)=>{
J
jidong 已提交
86
      if (err) {
87
        console.error(`activateOsAccount failed, code is ${err.code}, message is ${err.message}`);
J
jidong 已提交
88
      } else {
C
chennian 已提交
89
        console.log('activateOsAccount successfully');
J
jidong 已提交
90
      }
91
    });
J
jidong 已提交
92
  } catch (err) {
93
    console.error(`activateOsAccount failed, code is ${err.code}, message is ${err.message}`);
94
  }
Z
zhangalong 已提交
95 96 97 98 99 100
  ```

### activateOsAccount

activateOsAccount(localId: number): Promise<void>

J
jidong 已提交
101
激活指定系统帐号。使用Promise异步回调。
Z
zhangalong 已提交
102

J
jidong 已提交
103
**系统接口:** 此接口为系统接口。
Z
zengyawen 已提交
104

Z
zhangalong 已提交
105 106
**需要权限:** ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION

Z
zengyawen 已提交
107
**系统能力:** SystemCapability.Account.OsAccount
Z
zhangalong 已提交
108

Z
zengyawen 已提交
109
**参数:**
Z
zhangalong 已提交
110

Z
zengyawen 已提交
111 112
| 参数名  | 类型   | 必填 | 说明                 |
| ------- | ------ | ---- | -------------------- |
J
jidong 已提交
113
| localId | number | 是   | 系统帐号ID。 |
Z
zhangalong 已提交
114

Z
zengyawen 已提交
115
**返回值:**
Z
zhangalong 已提交
116

J
jidong 已提交
117
| 类型                | 说明                                  |
J
jidong 已提交
118
| ------------------- | ------------------------------------ |
A
Annie_wang 已提交
119
| Promise<void> | Promise对象,无返回结果的Promise对象。 |
J
jidong 已提交
120 121 122 123 124

**错误码:**

| 错误码ID | 错误信息             |
| -------- | ------------------- |
J
jidong 已提交
125
| 12300001 | System service exception. |
J
jidong 已提交
126
| 12300002 | Invalid localId.    |
J
jidong 已提交
127 128 129
| 12300003 | Account not found. |
| 12300008 | Restricted Account. |
| 12300009 | Account has been activated. |
Z
zengyawen 已提交
130

131
**示例:** 激活ID为100的系统帐号
Z
zhangalong 已提交
132
  ```js
133
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
134
  let accountManager = account_osAccount.getAccountManager();
135
  let localId: number = 100;
136 137
  try {
    accountManager.activateOsAccount(localId).then(() => {
J
jidong 已提交
138
      console.log('activateOsAccount successfully');
139
    }).catch((err: BusinessError) => {
J
jidong 已提交
140
      console.log('activateOsAccount failed, err:' + JSON.stringify(err));
141 142
    });
  } catch (e) {
C
chennian 已提交
143
    console.log('activateOsAccount exception: ' + JSON.stringify(e));
144 145 146
  }
  ```

J
jidong 已提交
147
### checkMultiOsAccountEnabled<sup>9+</sup>
148

J
jidong 已提交
149
checkMultiOsAccountEnabled(callback: AsyncCallback&lt;boolean&gt;): void
150

J
jidong 已提交
151
判断是否支持多系统帐号。使用callback异步回调。
152 153 154 155 156

**系统能力:** SystemCapability.Account.OsAccount

**参数:**

J
jidong 已提交
157 158 159
| 参数名   | 类型                         | 必填 | 说明                                                     |
| -------- | ---------------------------- | ---- | ------------------------------------------------------ |
| callback | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。返回true表示支持多系统帐号;返回false表示不支持。 |
160

J
jidong 已提交
161 162 163 164 165 166
**错误码:**

| 错误码ID | 错误信息             |
| -------- | ------------------- |
| 12300001 | System service exception. |

167 168 169
**示例:**

  ```js
170
  import { BusinessError } from '@ohos.base';
171 172
  let accountManager = account_osAccount.getAccountManager();
  try {
173
    accountManager.checkMultiOsAccountEnabled((err: BusinessError, isEnabled: boolean) => {
J
jidong 已提交
174
      if (err) {
175
        console.error(`checkMultiOsAccountEnabled failed, code is ${err.code}, message is ${err.message}`);
J
jidong 已提交
176
      } else {
C
chennian 已提交
177
      console.log('checkMultiOsAccountEnabled successfully, isEnabled: ' + isEnabled);
J
jidong 已提交
178
      }
179
    });
J
jidong 已提交
180
  } catch (err) {
181
    console.error(`checkMultiOsAccountEnabled failed, code is ${err.code}, message is ${err.message}`);
182
  }
Z
zhangalong 已提交
183 184
  ```

J
jidong 已提交
185
### checkMultiOsAccountEnabled<sup>9+</sup>
186

J
jidong 已提交
187
checkMultiOsAccountEnabled(): Promise&lt;boolean&gt;
188

J
jidong 已提交
189
判断是否支持多系统帐号。使用Promise异步回调。
190 191 192 193 194

**系统能力:** SystemCapability.Account.OsAccount

**返回值:**

J
jidong 已提交
195 196 197
| 类型                   | 说明                                                        |
| :--------------------- | :--------------------------------------------------------- |
| Promise&lt;boolean&gt; | Promise对象。返回true表示支持多系统帐号;返回false表示不支持。 |
198

J
jidong 已提交
199 200 201 202 203 204
**错误码:**

| 错误码ID | 错误信息             |
| -------- | ------------------- |
| 12300001 | System service exception. |

205 206 207
**示例:**

  ```js
208
  import { BusinessError } from '@ohos.base';
209 210
  try {
    let accountManager = account_osAccount.getAccountManager();
211
    accountManager.checkMultiOsAccountEnabled().then((isEnabled: boolean) => {
J
jidong 已提交
212
      console.log('checkMultiOsAccountEnabled successfully, isEnabled: ' + isEnabled);
213
    }).catch((err: BusinessError) => {
214
      console.error(`checkMultiOsAccountEnabled failed, code is ${err.code}, message is ${err.message}`);
215
    });
J
jidong 已提交
216
  } catch (err) {
217
    console.error(`checkMultiOsAccountEnabled failed, code is ${err.code}, message is ${err.message}`);
218 219 220
  }
  ```

J
jidong 已提交
221
### checkOsAccountActivated<sup>9+</sup>
Z
zhangalong 已提交
222

J
jidong 已提交
223
checkOsAccountActivated(localId: number, callback: AsyncCallback&lt;boolean&gt;): void
Z
zhangalong 已提交
224

J
jidong 已提交
225
判断指定系统帐号是否处于激活状态。使用callback异步回调。
Z
zhangalong 已提交
226

J
jidong 已提交
227
**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
228

Z
zengyawen 已提交
229 230 231
**系统能力:** SystemCapability.Account.OsAccount

**参数:**
Z
zhangalong 已提交
232

J
jidong 已提交
233 234 235 236
| 参数名   | 类型                         | 必填 | 说明                                                     |
| -------- | ---------------------------- | ---- | ------------------------------------------------------ |
| localId  | number                       | 是   | 系统帐号ID。                                             |
| callback | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。返回true表示帐号已激活;返回false表示帐号未激活。 |
Z
zhangalong 已提交
237

J
jidong 已提交
238 239 240 241
**错误码:**

| 错误码ID | 错误信息             |
| -------- | ------------------- |
J
jidong 已提交
242
| 12300001 | System service exception. |
J
jidong 已提交
243
| 12300002 | Invalid localId.    |
J
jidong 已提交
244
| 12300003 | Account not found. |
J
jidong 已提交
245 246

**示例:** 判断ID为100的系统帐号是否处于激活状态
Z
zhangalong 已提交
247

Z
zhangalong 已提交
248
  ```js
249
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
250
  let accountManager = account_osAccount.getAccountManager();
251
  let localId: number = 100;
J
jidong 已提交
252
  try {
253
    accountManager.checkOsAccountActivated(localId, (err: BusinessError, isActivated: boolean) => {
J
jidong 已提交
254 255 256 257 258 259 260
      if (err) {
        console.log('checkOsAccountActivated failed, error:' + JSON.stringify(err));
      } else {
        console.log('checkOsAccountActivated successfully, isActivated:' + isActivated);
      }
    });
  } catch (err) {
C
chennian 已提交
261
    console.log('checkOsAccountActivated exception: ' + JSON.stringify(err));
J
jidong 已提交
262
  }
Z
zhangalong 已提交
263 264
  ```

J
jidong 已提交
265
### checkOsAccountActivated<sup>9+</sup>
Z
zhangalong 已提交
266

J
jidong 已提交
267
checkOsAccountActivated(localId: number): Promise&lt;boolean&gt;
Z
zhangalong 已提交
268

J
jidong 已提交
269
判断指定系统帐号是否处于激活状态。使用Promise异步回调。
Z
zhangalong 已提交
270

J
jidong 已提交
271
**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
272

Z
zengyawen 已提交
273
**系统能力:** SystemCapability.Account.OsAccount
Z
zhangalong 已提交
274

J
jidong 已提交
275 276 277 278 279 280
**参数:**

| 参数名  | 类型   | 必填 | 说明                               |
| ------- | ------ | ---- | --------------------------------- |
| localId | number | 是   | 系统帐号ID。 |

Z
zengyawen 已提交
281
**返回值:**
Z
zhangalong 已提交
282

J
jidong 已提交
283 284 285
| 类型                   | 说明                                                       |
| ---------------------- | ---------------------------------------------------------- |
| Promise&lt;boolean&gt; | Promise对象。返回true表示帐号已激活;返回false表示帐号未激活。 |
Z
zengyawen 已提交
286

J
jidong 已提交
287 288 289 290
**错误码:**

| 错误码ID | 错误信息             |
| -------- | ------------------- |
J
jidong 已提交
291
| 12300001 | System service exception. |
J
jidong 已提交
292
| 12300002 | Invalid localId.    |
J
jidong 已提交
293
| 12300003 | Account not found. |
J
jidong 已提交
294 295

**示例:** 判断ID为100的系统帐号是否处于激活状态
Z
zhangalong 已提交
296

Z
zhangalong 已提交
297
  ```js
298
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
299
  let accountManager = account_osAccount.getAccountManager();
300
  let localId: number = 100;
J
jidong 已提交
301
  try {
302
    accountManager.checkOsAccountActivated(localId).then((isActivated: boolean) => {
J
jidong 已提交
303
      console.log('checkOsAccountActivated successfully, isActivated: ' + isActivated);
304
    }).catch((err: BusinessError) => {
C
chennian 已提交
305
      console.log('checkOsAccountActivated failed, error: ' + JSON.stringify(err));
J
jidong 已提交
306 307
    });
  } catch (err) {
C
chennian 已提交
308
    console.log('checkOsAccountActivated exception: ' + JSON.stringify(err));
J
jidong 已提交
309
  }
Z
zhangalong 已提交
310 311
  ```

C
cclicn 已提交
312
### checkOsAccountConstraintEnabled<sup>9+</sup>
313

C
cclicn 已提交
314
checkOsAccountConstraintEnabled(localId: number, constraint: string, callback: AsyncCallback&lt;boolean&gt;): void
315

J
jidong 已提交
316
判断指定系统帐号是否具有指定约束。使用callback异步回调。
317

C
cclicn 已提交
318
**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
319 320 321 322 323

**系统能力:** SystemCapability.Account.OsAccount

**参数:**

J
jidong 已提交
324 325 326 327 328
| 参数名     | 类型                         | 必填 | 说明                                                               |
| ---------- | ---------------------------- | ---- | ----------------------------------------------------------------- |
| localId    | number                       | 是   | 系统帐号ID。                                 |
| constraint | string                       | 是   | 指定的[约束](#系统帐号约束列表)名称。                                |
| callback   | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。返回true表示已使能指定的约束;返回false表示未使能指定的约束。 |
329

J
jidong 已提交
330 331 332 333
**错误码:**

| 错误码ID | 错误信息             |
| -------- | ------------------- |
C
chennian 已提交
334 335 336
| 12300001 | System service exception. |
| 12300002 | Invalid localId or constraint.    |
| 12300003 | Account not found. |
J
jidong 已提交
337 338

**示例:** 判断ID为100的系统帐号是否有禁止使用Wi-Fi的约束
339 340

  ```js
341
  import { BusinessError } from '@ohos.base';
342
  let accountManager = account_osAccount.getAccountManager();
343 344
  let localId: number = 100;
  let constraint: string = 'constraint.wifi';
345
  try {
346
    accountManager.checkOsAccountConstraintEnabled(localId, constraint, (err: BusinessError, isEnabled: boolean)=>{
J
jidong 已提交
347
      if (err) {
C
chennian 已提交
348
        console.log('checkOsAccountConstraintEnabled failed, error: ' + JSON.stringify(err));
J
jidong 已提交
349
      } else {
C
chennian 已提交
350
        console.log('checkOsAccountConstraintEnabled successfully, isEnabled: ' + isEnabled);
J
jidong 已提交
351
      }
352
    });
J
jidong 已提交
353
  } catch (err) {
C
chennian 已提交
354
    console.log('checkOsAccountConstraintEnabled exception: ' + JSON.stringify(err));
355 356 357
  }
  ```

C
cclicn 已提交
358
### checkOsAccountConstraintEnabled<sup>9+</sup>
359

C
cclicn 已提交
360
checkOsAccountConstraintEnabled(localId: number, constraint: string): Promise&lt;boolean&gt;
361

J
jidong 已提交
362
判断指定系统帐号是否具有指定约束。使用Promise异步回调。
363

C
cclicn 已提交
364
**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
365 366 367 368 369

**系统能力:** SystemCapability.Account.OsAccount

**参数:**

J
jidong 已提交
370 371 372 373
| 参数名     | 类型   | 必填 | 说明                                |
| ---------- | ------ | ---- | ---------------------------------- |
| localId    | number | 是   | 系统帐号ID。  |
| constraint | string | 是   | 指定的[约束](#系统帐号约束列表)名称。 |
374 375 376

**返回值:**

J
jidong 已提交
377 378 379
| 类型                   | 说明                                                                  |
| --------------------- | --------------------------------------------------------------------- |
| Promise&lt;boolean&gt; | Promise对象。返回true表示已使能指定的约束;返回false表示未使能指定的约束。 |
380

J
jidong 已提交
381 382 383 384
**错误码:**

| 错误码ID | 错误信息             |
| -------- | ------------------- |
C
chennian 已提交
385 386 387
| 12300001 | System service exception. |
| 12300002 | Invalid localId or constraint.    |
| 12300003 | Account not found. |
J
jidong 已提交
388 389

**示例:** 判断ID为100的系统帐号是否有禁止使用Wi-Fi的约束
390 391

  ```js
392
  import { BusinessError } from '@ohos.base';
393
  let accountManager = account_osAccount.getAccountManager();
394 395
  let localId: number = 100;
  let constraint: string = 'constraint.wifi';
396
  try {
397
    accountManager.checkOsAccountConstraintEnabled(localId, constraint).then((isEnabled: boolean) => {
C
chennian 已提交
398
      console.log('checkOsAccountConstraintEnabled successfully, isEnabled: ' + isEnabled);
399
    }).catch((err: BusinessError) => {
C
chennian 已提交
400
      console.log('checkOsAccountConstraintEnabled failed, error: ' + JSON.stringify(err));
401
    });
J
jidong 已提交
402
  } catch (err) {
C
chennian 已提交
403
    console.log('checkOsAccountConstraintEnabled exception: ' + JSON.stringify(err));
404 405 406
  }
  ```

J
jidong 已提交
407
### checkOsAccountTestable<sup>9+</sup>
Z
zhangalong 已提交
408

J
jidong 已提交
409
checkOsAccountTestable(callback: AsyncCallback&lt;boolean&gt;): void
410

J
jidong 已提交
411
检查当前系统帐号是否为测试帐号。使用callback异步回调。
Z
zengyawen 已提交
412 413

**系统能力:** SystemCapability.Account.OsAccount
Z
zhangalong 已提交
414

Z
zengyawen 已提交
415
**参数:**
Z
zhangalong 已提交
416

J
jidong 已提交
417 418 419
| 参数名   | 类型                         | 必填 | 说明                                                                   |
| -------- | ---------------------------- | ---- | --------------------------------------------------------------------- |
| callback | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。返回true表示当前帐号为测试帐号;返回false表示当前帐号非测试帐号。 |
Z
zengyawen 已提交
420

J
jidong 已提交
421 422 423 424
**错误码:**

| 错误码ID | 错误信息             |
| -------- | ------------------- |
J
jidong 已提交
425
| 12300001 | System service exception. |
J
jidong 已提交
426 427

**示例:**
Z
zhangalong 已提交
428

Z
zhangalong 已提交
429
  ```js
430
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
431
  let accountManager = account_osAccount.getAccountManager();
J
jidong 已提交
432
  try {
433
    accountManager.checkOsAccountTestable((err: BusinessError, isTestable: boolean) => {
J
jidong 已提交
434
      if (err) {
C
chennian 已提交
435
        console.log('checkOsAccountTestable failed, error: ' + JSON.stringify(err));
J
jidong 已提交
436
      } else {
C
chennian 已提交
437
        console.log('checkOsAccountTestable successfully, isTestable: ' + isTestable);
J
jidong 已提交
438 439 440
      }
    });
  } catch (err) {
C
chennian 已提交
441
    console.log('checkOsAccountTestable error: ' + JSON.stringify(err));
J
jidong 已提交
442
  }
Z
zhangalong 已提交
443 444
  ```

J
jidong 已提交
445
### checkOsAccountTestable<sup>9+</sup>
Z
zhangalong 已提交
446

J
jidong 已提交
447
checkOsAccountTestable(): Promise&lt;boolean&gt;
Z
zhangalong 已提交
448

J
jidong 已提交
449
检查当前系统帐号是否为测试帐号。使用Promise异步回调。
Z
zhangalong 已提交
450

J
jidong 已提交
451 452 453 454 455 456 457 458 459 460 461 462
**系统能力:** SystemCapability.Account.OsAccount

**返回值:**

| 类型                   | 说明                                                                      |
| ---------------------- | ------------------------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise对象。返回true表示当前帐号为测试帐号;返回false表示当前帐号非测试帐号。 |

**错误码:**

| 错误码ID | 错误信息             |
| -------- | ------------------- |
J
jidong 已提交
463
| 12300001 | System service exception. |
J
jidong 已提交
464 465 466 467

**示例:**

  ```js
468
  import { BusinessError } from '@ohos.base';
J
jidong 已提交
469 470
  let accountManager = account_osAccount.getAccountManager();
  try {
471
    accountManager.checkOsAccountTestable().then((isTestable: boolean) => {
C
chennian 已提交
472
      console.log('checkOsAccountTestable successfully, isTestable: ' + isTestable);
473
    }).catch((err: BusinessError) => {
C
chennian 已提交
474
      console.log('checkOsAccountTestable failed, error: ' + JSON.stringify(err));
J
jidong 已提交
475 476 477 478 479 480 481 482 483 484
    });
  } catch (err) {
    console.log('checkOsAccountTestable exception: ' + JSON.stringify(err));
  }
  ```

### checkOsAccountVerified<sup>9+</sup>

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

J
jidong 已提交
485
检查当前系统帐号是否已认证解锁。使用callback异步回调。
486

Z
zengyawen 已提交
487 488 489
**系统能力:** SystemCapability.Account.OsAccount

**参数:**
Z
zhangalong 已提交
490

J
jidong 已提交
491 492
| 参数名   | 类型                         | 必填 | 说明                                                            |
| -------- | ---------------------------- | ---- | ------------------------------------------------------------- |
J
jidong 已提交
493
| callback | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。返回true表示当前帐号已认证解锁;返回false表示当前帐号未认证解锁。 |
Z
zhangalong 已提交
494

J
jidong 已提交
495
**错误码:**
Z
zhangalong 已提交
496

J
jidong 已提交
497 498
| 错误码ID | 错误信息             |
| -------- | ------------------- |
C
chennian 已提交
499
| 12300001 | System service exception. |
Z
zhangalong 已提交
500

J
jidong 已提交
501
**示例:**
Z
zhangalong 已提交
502

Z
zhangalong 已提交
503
  ```js
504
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
505
  let accountManager = account_osAccount.getAccountManager();
J
jidong 已提交
506
  try {
507
    accountManager.checkOsAccountVerified((err: BusinessError, isVerified: boolean) => {
J
jidong 已提交
508
      if (err) {
C
chennian 已提交
509
        console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err));
J
jidong 已提交
510
      } else {
C
chennian 已提交
511
        console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified);
J
jidong 已提交
512 513 514
      }
    });
  } catch (err) {
C
chennian 已提交
515
    console.log('checkOsAccountVerified exception: ' + JSON.stringify(err));
J
jidong 已提交
516
  }
Z
zhangalong 已提交
517 518
  ```

J
jidong 已提交
519
### checkOsAccountVerified<sup>9+</sup>
520

J
jidong 已提交
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541
checkOsAccountVerified(): Promise&lt;boolean&gt;

检查当前系统帐号是否已认证解锁。使用Promise异步回调。

**系统能力:** SystemCapability.Account.OsAccount

**返回值:**

| 类型                   | 说明                                                                      |
| ---------------------- | ------------------------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise对象。返回true表示当前帐号已认证解锁;返回false表示当前帐号未认证解锁。 |

**错误码:**

| 错误码ID | 错误信息             |
| -------- | ------------------- |
| 12300001 | System service exception. |

**示例:**

  ```js
542
  import { BusinessError } from '@ohos.base';
J
jidong 已提交
543 544
  let accountManager = account_osAccount.getAccountManager();
  try {
545
    accountManager.checkOsAccountVerified().then((isVerified: boolean) => {
J
jidong 已提交
546
      console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified);
547
    }).catch((err: BusinessError) => {
J
jidong 已提交
548 549 550 551 552 553 554 555 556
      console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err));
    });
  } catch (err) {
    console.log('checkOsAccountVerified exception: ' + JSON.stringify(err));
  }
  ```

### checkOsAccountVerified<sup>9+</sup>

J
jidong 已提交
557
checkOsAccountVerified(localId: number, callback: AsyncCallback&lt;boolean&gt;): void
558

J
jidong 已提交
559
检查指定系统帐号是否已验证。使用callback异步回调。
560

J
jidong 已提交
561
**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
562 563 564 565 566

**系统能力:** SystemCapability.Account.OsAccount

**参数:**

J
jidong 已提交
567 568
| 参数名   | 类型                         | 必填 | 说明                                                            |
| -------- | ---------------------------- | ---- | ------------------------------------------------------------- |
569
| localId  | number                       | 是   | 系统帐号ID。                              |
J
jidong 已提交
570
| callback | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。返回true表示当前帐号已认证解锁;返回false表示当前帐号未认证解锁。 |
571

J
jidong 已提交
572 573 574 575
**错误码:**

| 错误码ID | 错误信息             |
| -------- | ------------------- |
C
chennian 已提交
576 577 578
| 12300001 | System service exception. |
| 12300002 | Invalid localId.    |
| 12300003 | Account not found. |
J
jidong 已提交
579 580

**示例:**
581 582

  ```js
583
  import { BusinessError } from '@ohos.base';
584
  let accountManager = account_osAccount.getAccountManager();
585
  let localId: number = 100;
586
  try {
587
    accountManager.checkOsAccountVerified(localId, (err: BusinessError, isVerified: boolean) => {
J
jidong 已提交
588
      if (err) {
C
chennian 已提交
589
        console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err));
J
jidong 已提交
590
      } else {
C
chennian 已提交
591
        console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified);
J
jidong 已提交
592
      }
593
    });
J
jidong 已提交
594
  } catch (err) {
C
chennian 已提交
595
    console.log('checkOsAccountVerified exception: ' + err);
596 597 598
  }
  ```

J
jidong 已提交
599
### checkOsAccountVerified<sup>9+</sup>
600

Z
zhouyan 已提交
601
checkOsAccountVerified(localId: number): Promise&lt;boolean&gt;
602

J
jidong 已提交
603
检查指定系统帐号是否已验证。使用Promise异步回调。
604

J
jidong 已提交
605
**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
606 607 608 609 610

**系统能力:** SystemCapability.Account.OsAccount

**参数:**

J
jidong 已提交
611 612
| 参数名  | 类型   | 必填 | 说明                                                              |
| ------- | ------ | ---- | --------------------------------------------------------------- |
Z
zhouyan 已提交
613
| localId | number | 是   | 系统帐号ID。不填则检查当前系统帐号是否已验证。 |
614 615 616

**返回值:**

J
jidong 已提交
617 618
| 类型                   | 说明                                                               |
| ---------------------- | ----------------------------------------------------------------- |
J
jidong 已提交
619
| Promise&lt;boolean&gt; | Promise对象。返回true表示当前帐号已认证解锁;返回false表示当前帐号未认证解锁。 |
620

J
jidong 已提交
621 622 623 624
**错误码:**

| 错误码ID | 错误信息             |
| -------- | ------------------- |
C
chennian 已提交
625 626 627
| 12300001 | System service exception. |
| 12300002 | Invalid localId.    |
| 12300003 | Account not found. |
J
jidong 已提交
628 629

**示例:**
630 631

  ```js
632
  import { BusinessError } from '@ohos.base';
633
  let accountManager = account_osAccount.getAccountManager();
634
  let localId: number = 100;
635
  try {
636
    accountManager.checkOsAccountVerified(localId).then((isVerified: boolean) => {
C
chennian 已提交
637
      console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified);
638
    }).catch((err: BusinessError) => {
C
chennian 已提交
639
      console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err));
640
    });
J
jidong 已提交
641
  } catch (err) {
J
jidong 已提交
642
    console.log('checkOsAccountVerified exception: ' + JSON.stringify(err));
643 644 645
  }
  ```

646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668
### checkOsAccountVerified<sup>9+</sup>

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

检查当前系统帐号是否已验证。使用Promise异步回调。

**系统能力:** SystemCapability.Account.OsAccount

**返回值:**

| 类型                   | 说明                                                               |
| ---------------------- | ----------------------------------------------------------------- |
| Promise&lt;boolean&gt; | Promise对象。返回true表示当前帐号已验证;返回false表示当前帐号未验证。 |

**错误码:**

| 错误码ID | 错误信息             |
| -------- | ------------------- |
| 12300001 | System service exception. |

**示例:**

  ```js
669
  import { BusinessError } from '@ohos.base';
670 671
  let accountManager = account_osAccount.getAccountManager();
  try {
672
    accountManager.checkOsAccountVerified().then((isVerified: boolean) => {
673
      console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified);
674
    }).catch((err: BusinessError) => {
675 676 677 678 679 680 681
      console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err));
    });
  } catch (err) {
    console.log('checkOsAccountVerified exception: ' + JSON.stringify(err));
  }
  ```

J
jidong 已提交
682
### removeOsAccount
Z
zhangalong 已提交
683

J
jidong 已提交
684
removeOsAccount(localId: number, callback: AsyncCallback&lt;void&gt;): void
Z
zhangalong 已提交
685

J
jidong 已提交
686
删除指定系统帐号。使用callback异步回调。
Z
zhangalong 已提交
687

J
jidong 已提交
688
**系统接口:** 此接口为系统接口。
689

Z
zengyawen 已提交
690
**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
Z
zhangalong 已提交
691

Z
zengyawen 已提交
692
**系统能力:** SystemCapability.Account.OsAccount
Z
zhangalong 已提交
693

Z
zengyawen 已提交
694 695
**参数:**

J
jidong 已提交
696 697 698 699
| 参数名   | 类型                      | 必填 | 说明                                                 |
| -------- | ------------------------- | ---- | -------------------------------------------------- |
| localId  | number                    | 是   | 系统帐号ID。                  |
| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。如果删除帐号成功,err为null,否则为错误对象。 |
Z
zengyawen 已提交
700

J
jidong 已提交
701 702 703 704
**错误码:**

| 错误码ID | 错误信息             |
| -------- | ------------------- |
J
jidong 已提交
705
| 12300001 | System service exception. |
J
jidong 已提交
706
| 12300002 | Invalid localId.    |
J
jidong 已提交
707 708
| 12300003 | Account not found. |
| 12300008 | Restricted Account. |
J
jidong 已提交
709 710

**示例:**
Z
zhangalong 已提交
711

Z
zhangalong 已提交
712
  ```js
713
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
714
  let accountManager = account_osAccount.getAccountManager();
715
  let accountName: string = 'testAccountName';
J
jidong 已提交
716
  try {
717 718 719 720 721 722 723 724
    accountManager.createOsAccount(accountName, account_osAccount.OsAccountType.NORMAL,
      (err: BusinessError, osAccountInfo: account_osAccount.OsAccountInfo) => {
        accountManager.removeOsAccount(osAccountInfo.localId, (err: BusinessError)=>{
          if (err) {
            console.log('removeOsAccount failed, error: ' + JSON.stringify(err));
          } else {
            console.log('removeOsAccount successfully');
          }
J
jidong 已提交
725 726 727
      });
    });
  } catch (err) {
C
chennian 已提交
728
    console.log('removeOsAccount exception: ' + JSON.stringify(err));
J
jidong 已提交
729
  }
Z
zhangalong 已提交
730 731
  ```

J
jidong 已提交
732
### removeOsAccount
Z
zhangalong 已提交
733

J
jidong 已提交
734
removeOsAccount(localId: number): Promise&lt;void&gt;
Z
zhangalong 已提交
735

J
jidong 已提交
736
删除指定系统帐号。使用Promise异步回调。
Z
zengyawen 已提交
737

J
jidong 已提交
738
**系统接口:** 此接口为系统接口。
739

Z
zengyawen 已提交
740 741 742
**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS

**系统能力:** SystemCapability.Account.OsAccount
Z
zhangalong 已提交
743

Z
zengyawen 已提交
744
**参数:**
Z
zhangalong 已提交
745

J
jidong 已提交
746 747 748
| 参数名  | 类型   | 必填 | 说明                               |
| ------- | ------ | ---- | --------------------------------- |
| localId | number | 是   | 系统帐号ID。 |
Z
zhangalong 已提交
749

Z
zengyawen 已提交
750
**返回值:**
Z
zhangalong 已提交
751

J
jidong 已提交
752 753
| 类型                | 说明                                  |
| ------------------- | ------------------------------------ |
A
Annie_wang 已提交
754
| Promise&lt;void&gt; | Promise对象,无返回结果的Promise对象。 |
Z
zhangalong 已提交
755

J
jidong 已提交
756 757 758 759
**错误码:**

| 错误码ID | 错误信息             |
| -------- | ------------------- |
J
jidong 已提交
760
| 12300001 | System service exception. |
J
jidong 已提交
761
| 12300002 | Invalid localId.    |
J
jidong 已提交
762 763
| 12300003 | Account not found. |
| 12300008 | Restricted Account. |
J
jidong 已提交
764 765

**示例:**
Z
zhangalong 已提交
766

Z
zhangalong 已提交
767
  ```js
768
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
769
  let accountManager = account_osAccount.getAccountManager();
770
  let accountName: string = 'testAccountName';
J
jidong 已提交
771
  try {
772 773 774 775 776 777 778
    accountManager.createOsAccount(accountName, account_osAccount.OsAccountType.NORMAL,
      (err: BusinessError, osAccountInfo: account_osAccount.OsAccountInfo)=>{
        accountManager.removeOsAccount(osAccountInfo.localId).then(() => {
          console.log('removeOsAccount successfully');
        }).catch((err: BusinessError) => {
            console.log('removeOsAccount failed, error: ' + JSON.stringify(err));
        });
J
jidong 已提交
779 780
    });
  } catch (err) {
C
chennian 已提交
781
    console.log('removeOsAccount exception: ' + JSON.stringify(err));
J
jidong 已提交
782
  }
Z
zhangalong 已提交
783 784
  ```

J
jidong 已提交
785 786 787 788 789
### setOsAccountConstraints

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

为指定系统帐号设置/删除约束。使用callback异步回调。
790

J
jidong 已提交
791
**系统接口:** 此接口为系统接口。
792

J
jidong 已提交
793
**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
794 795 796 797 798

**系统能力:** SystemCapability.Account.OsAccount

**参数:**

J
jidong 已提交
799 800 801 802 803 804
| 参数名      | 类型                      | 必填 | 说明                                             |
| ----------- | ------------------------- | ---- | ----------------------------------------------- |
| localId     | number                    | 是   | 系统帐号ID。               |
| constraints | Array&lt;string&gt;       | 是   | 待设置/删除的[约束](#系统帐号约束列表)列表。        |
| enable      | boolean                   | 是   | 设置(true)/删除(false)                           |
| callback    | AsyncCallback&lt;void&gt; | 是   | 回调函数。如果设置成功,err为null,否则为错误对象。 |
805

J
jidong 已提交
806 807 808 809
**错误码:**

| 错误码ID | 错误信息             |
| -------- | ------------------- |
J
jidong 已提交
810
| 12300001 | System service exception. |
C
chennian 已提交
811
| 12300002 | Invalid localId or constraints.    |
J
jidong 已提交
812 813
| 12300003 | Account not found. |
| 12300008 | Restricted Account. |
J
jidong 已提交
814 815

**示例:** 给ID为100的系统帐号设置禁止使用Wi-Fi的约束
816 817

  ```js
818
  import { BusinessError } from '@ohos.base';
819
  let accountManager = account_osAccount.getAccountManager();
820 821
  let localId: number = 100;
  let constraint: string = 'constraint.wifi';
822
  try {
823
    accountManager.setOsAccountConstraints(localId, [constraint], true, (err: BusinessError) => {
J
jidong 已提交
824
      if (err) {
C
chennian 已提交
825
        console.log('setOsAccountConstraints failed, error: ' + JSON.stringify(err));
J
jidong 已提交
826
      } else {
C
chennian 已提交
827
        console.log('setOsAccountConstraints successfully');
J
jidong 已提交
828
      }
829
    });
J
jidong 已提交
830
  } catch (err) {
C
chennian 已提交
831
    console.log('setOsAccountConstraints exception: ' + JSON.stringify(err));
832 833 834
  }
  ```

J
jidong 已提交
835 836 837 838 839
### setOsAccountConstraints

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

为指定系统帐号设置/删除约束。使用Promise异步回调。
840

J
jidong 已提交
841
**系统接口:** 此接口为系统接口。
842

J
jidong 已提交
843
**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
844 845 846

**系统能力:** SystemCapability.Account.OsAccount

J
jidong 已提交
847 848 849 850 851 852 853 854
**参数:**

| 参数名      | 类型                | 必填 | 说明                                         |
| ----------- | ------------------- | ---- | -------------------------------------------- |
| localId     | number              | 是   | 系统帐号ID。           |
| constraints | Array&lt;string&gt; | 是   | 待设置/删除的[约束](#系统帐号约束列表)列表。    |
| enable      | boolean             | 是   | 设置(true)/删除(false)。                     |

855 856
**返回值:**

J
jidong 已提交
857 858
| 类型                | 说明                                 |
| :------------------ | :----------------------------------- |
A
Annie_wang 已提交
859
| Promise&lt;void&gt; | Promise对象,无返回结果的Promise对象。 |
860

J
jidong 已提交
861 862 863 864
**错误码:**

| 错误码ID | 错误信息             |
| -------- | ------------------- |
J
jidong 已提交
865
| 12300001 | System service exception. |
C
chennian 已提交
866
| 12300002 | Invalid localId or constraints.    |
J
jidong 已提交
867 868
| 12300003 | Account not found. |
| 12300008 | Restricted Account. |
J
jidong 已提交
869 870

**示例:** 删除ID为100的系统帐号的禁止使用Wi-Fi的约束
871 872

  ```js
873
  import { BusinessError } from '@ohos.base';
874
  let accountManager = account_osAccount.getAccountManager();
875
  let localId: number = 100;
876
  try {
J
jidong 已提交
877 878
    accountManager.setOsAccountConstraints(localId, ['constraint.location.set'], false).then(() => {
      console.log('setOsAccountConstraints succsuccessfully');
879
    }).catch((err: BusinessError) => {
C
chennian 已提交
880
      console.log('setOsAccountConstraints failed, error: ' + JSON.stringify(err));
881
    });
J
jidong 已提交
882
  } catch (err) {
C
chennian 已提交
883
    console.log('setOsAccountConstraints exception: ' + JSON.stringify(err));
884 885 886
  }
  ```

J
jidong 已提交
887
### setOsAccountName
Z
zhangalong 已提交
888

J
jidong 已提交
889
setOsAccountName(localId: number, localName: string, callback: AsyncCallback&lt;void&gt;): void
Z
zhangalong 已提交
890

J
jidong 已提交
891
设置指定系统帐号的帐号名。使用callback异步回调。
Z
zhangalong 已提交
892

J
jidong 已提交
893 894 895
**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
896

Z
zengyawen 已提交
897
**系统能力:** SystemCapability.Account.OsAccount
Z
zhangalong 已提交
898

Z
zengyawen 已提交
899
**参数:**
Z
zhangalong 已提交
900

J
jidong 已提交
901 902 903
| 参数名    | 类型                      | 必填 | 说明                                             |
| :-------- | ------------------------- | ---- | ----------------------------------------------- |
| localId   | number                    | 是   | 系统帐号ID。               |
J
jidong 已提交
904
| localName | string                    | 是   | 帐号名,最大长度为1024个字符。                          |
J
jidong 已提交
905
| callback  | AsyncCallback&lt;void&gt; | 是   | 回调函数。如果设置成功,err为null,否则为错误对象。 |
Z
zengyawen 已提交
906

J
jidong 已提交
907 908 909 910
**错误码:**

| 错误码ID | 错误信息             |
| -------- | ------------------- |
J
jidong 已提交
911 912 913 914
| 12300001 | System service exception. |
| 12300002 | Invalid localId or localName. |
| 12300003 | Account not found. |
| 12300008 | Restricted Account. |
J
jidong 已提交
915 916

**示例:** 将ID为100的系统帐号的帐号名设置成demoName
Z
zhangalong 已提交
917

Z
zhangalong 已提交
918
  ```js
919
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
920
  let accountManager = account_osAccount.getAccountManager();
921 922
  let localId: number = 100;
  let name: string = 'demoName';
J
jidong 已提交
923
  try {
924
    accountManager.setOsAccountName(localId, name, (err: BusinessError) => {
J
jidong 已提交
925
      if (err) {
C
chennian 已提交
926
        console.log('setOsAccountName failed, error: ' + JSON.stringify(err));
J
jidong 已提交
927
      } else {
C
chennian 已提交
928
        console.log('setOsAccountName successfully');
J
jidong 已提交
929 930 931
      }
    });
  } catch (err) {
C
chennian 已提交
932
    console.log('setOsAccountName exception: ' + JSON.stringify(err));
J
jidong 已提交
933
  }
Z
zhangalong 已提交
934 935
  ```

J
jidong 已提交
936
### setOsAccountName
Z
zhangalong 已提交
937

J
jidong 已提交
938
setOsAccountName(localId: number, localName: string): Promise&lt;void&gt;
Z
zhangalong 已提交
939

J
jidong 已提交
940
设置指定系统帐号的帐号名。使用Promise异步调用。 
Z
zhangalong 已提交
941

J
jidong 已提交
942 943 944
**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
945

Z
zengyawen 已提交
946 947
**系统能力:** SystemCapability.Account.OsAccount

J
jidong 已提交
948 949 950 951 952 953 954
**参数:**

| 参数名    | 类型   | 必填 | 说明                                |
| --------- | ------ | ---- | --------------------------------- |
| localId   | number | 是   | 系统帐号ID。 |
| localName | string | 是   | 帐号名,最大长度为1024。            |

Z
zengyawen 已提交
955
**返回值:**
Z
zhangalong 已提交
956

J
jidong 已提交
957
| 类型                | 说明                                  |
J
jidong 已提交
958
| ------------------- | ------------------------------------ |
A
Annie_wang 已提交
959
| Promise&lt;void&gt; | Promise对象,无返回结果的Promise对象。 |
Z
zhangalong 已提交
960

J
jidong 已提交
961 962 963 964
**错误码:**

| 错误码ID | 错误信息             |
| -------- | ------------------- |
J
jidong 已提交
965 966 967 968
| 12300001 | System service exception. |
| 12300002 | Invalid localId or localName.    |
| 12300003 | Account not found. |
| 12300008 | Restricted Account. |
J
jidong 已提交
969 970

**示例:** 将ID为100的系统帐号的帐号名设置成demoName
Z
zhangalong 已提交
971

Z
zhangalong 已提交
972
  ```js
973
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
974
  let accountManager = account_osAccount.getAccountManager();
975 976
  let localId: number = 100;
  let name: string = 'testName';
J
jidong 已提交
977 978 979
  try {
    accountManager.setOsAccountName(localId, name).then(() => {
      console.log('setOsAccountName successfully');
980
    }).catch((err: BusinessError) => {
C
chennian 已提交
981
      console.log('setOsAccountName failed, error: ' + JSON.stringify(err));
J
jidong 已提交
982 983
    });
  } catch (err) {
C
chennian 已提交
984
    console.log('setOsAccountName exception: ' + JSON.stringify(err));
J
jidong 已提交
985
  }
Z
zhangalong 已提交
986 987
  ```

J
jidong 已提交
988
### getOsAccountCount<sup>9+</sup>
989

J
jidong 已提交
990
getOsAccountCount(callback: AsyncCallback&lt;number&gt;): void
991

J
jidong 已提交
992
获取已创建的系统帐号数量。使用callback异步回调。
993

J
jidong 已提交
994
**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
995 996 997 998 999

**系统能力:** SystemCapability.Account.OsAccount

**参数:**

J
jidong 已提交
1000 1001 1002
| 参数名   | 类型                        | 必填 | 说明                                                                         |
| -------- | --------------------------- | ---- | -------------------------------------------------------------------------- |
| callback | AsyncCallback&lt;number&gt; | 是   | 回调函数。当获取成功时,err为null,data为已创建的系统帐号的数量;否则为错误对象。 |
1003

J
jidong 已提交
1004 1005 1006 1007 1008 1009
**错误码:**

| 错误码ID | 错误信息             |
| -------- | ------------------- |
| 12300001 | System service exception. |

1010 1011 1012
**示例:**

  ```js
1013
  import { BusinessError } from '@ohos.base';
1014 1015
  let accountManager = account_osAccount.getAccountManager();
  try {
1016
    accountManager.getOsAccountCount((err: BusinessError, count: number) => {
J
jidong 已提交
1017
      if (err) {
C
chennian 已提交
1018
        console.log('getOsAccountCount failed, error: ' + JSON.stringify(err));
J
jidong 已提交
1019
      } else {
C
chennian 已提交
1020
        console.log('getOsAccountCount successfully, count: ' + count);
J
jidong 已提交
1021
      }
1022
    });
J
jidong 已提交
1023
  } catch (err) {
C
chennian 已提交
1024
    console.log('getOsAccountCount exception: ' + JSON.stringify(err));
1025 1026 1027
  }
  ```

J
jidong 已提交
1028
### getOsAccountCount<sup>9+</sup>
1029

J
jidong 已提交
1030
getOsAccountCount(): Promise&lt;number&gt;
1031

J
jidong 已提交
1032
获取已创建的系统帐号数量。使用Promise异步回调。
1033

J
jidong 已提交
1034
**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
1035 1036 1037

**系统能力:** SystemCapability.Account.OsAccount

J
jidong 已提交
1038
**返回值:**
1039

J
jidong 已提交
1040 1041 1042
| 类型                  | 说明                                    |
| --------------------- | -------------------------------------- |
| Promise&lt;number&gt; | Promise对象,返回已创建的系统帐号的数量。 |
1043

J
jidong 已提交
1044 1045 1046 1047 1048 1049
**错误码:**

| 错误码ID | 错误信息             |
| -------- | ------------------- |
| 12300001 | System service exception. |

1050 1051 1052
**示例:**

  ```js
1053
  import { BusinessError } from '@ohos.base';
1054 1055
  let accountManager = account_osAccount.getAccountManager();
  try {
1056
    accountManager.getOsAccountCount().then((count: number) => {
C
chennian 已提交
1057
      console.log('getOsAccountCount successfully, count: ' + count);
1058
    }).catch((err: BusinessError) => {
C
chennian 已提交
1059
      console.log('getOsAccountCount failed, error: ' + JSON.stringify(err));
1060
    });
J
jidong 已提交
1061
  } catch(err) {
C
chennian 已提交
1062
    console.log('getOsAccountCount exception: ' + JSON.stringify(err));
1063 1064 1065
  }
  ```

C
cclicn 已提交
1066
### getOsAccountLocalId<sup>9+</sup>
1067

C
cclicn 已提交
1068
getOsAccountLocalId(callback: AsyncCallback&lt;number&gt;): void
1069

J
jidong 已提交
1070
获取当前进程所属的系统帐号ID,使用callback异步回调。
1071 1072 1073 1074 1075

**系统能力:** SystemCapability.Account.OsAccount

**参数:**

J
jidong 已提交
1076 1077 1078
| 参数名   | 类型                        | 必填 | 说明                                                                           |
| -------- | --------------------------- | ---- | ---------------------------------------------------------------------------- |
| callback | AsyncCallback&lt;number&gt; | 是   | 回调函数。当获取成功时,err为null,data为当前进程所属的系统帐号ID;否则为错误对象。 |
1079

J
jidong 已提交
1080 1081 1082 1083
**错误码:**

| 错误码ID | 错误信息             |
| -------- | ------------------- |
C
chennian 已提交
1084
| 12300001 | System service exception. |
J
jidong 已提交
1085

1086 1087 1088
**示例:**

  ```js
1089
  import { BusinessError } from '@ohos.base';
1090 1091
  let accountManager = account_osAccount.getAccountManager();
  try {
1092
    accountManager.getOsAccountLocalId((err: BusinessError, localId: number) => {
J
jidong 已提交
1093
      if (err) {
C
chennian 已提交
1094
        console.log('getOsAccountLocalId failed, error: ' + JSON.stringify(err));
J
jidong 已提交
1095
      } else {
C
chennian 已提交
1096
        console.log('getOsAccountLocalId successfully, localId: ' + localId);
J
jidong 已提交
1097
      }
1098
    });
J
jidong 已提交
1099
  } catch (err) {
C
chennian 已提交
1100
    console.log('getOsAccountLocalId exception: ' + JSON.stringify(err));
1101 1102 1103
  }
  ```

C
cclicn 已提交
1104
### getOsAccountLocalId<sup>9+</sup>
Z
zhangalong 已提交
1105

C
cclicn 已提交
1106
getOsAccountLocalId(): Promise&lt;number&gt;
Z
zhangalong 已提交
1107

J
jidong 已提交
1108
获取当前进程所属的系统帐号ID,使用Promise异步回调。
1109

Z
zengyawen 已提交
1110
**系统能力:** SystemCapability.Account.OsAccount
Z
zhangalong 已提交
1111

J
jidong 已提交
1112
**返回值:**
Z
zhangalong 已提交
1113

J
jidong 已提交
1114
| 类型                  | 说明                                      |
J
jidong 已提交
1115
| --------------------- | ---------------------------------------- |
J
jidong 已提交
1116
| Promise&lt;number&gt; | Promise对象,返回当前进程所属的系统帐号ID。 |
Z
zengyawen 已提交
1117

J
jidong 已提交
1118 1119 1120 1121
**错误码:**

| 错误码ID | 错误信息             |
| -------- | ------------------- |
C
chennian 已提交
1122
| 12300001 | System service exception. |
J
jidong 已提交
1123

1124
**示例:**
Z
zhangalong 已提交
1125

Z
zhangalong 已提交
1126
  ```js
1127
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
1128
  let accountManager = account_osAccount.getAccountManager();
J
jidong 已提交
1129
  try {
1130
    accountManager.getOsAccountLocalId().then((localId: number) => {
C
chennian 已提交
1131
      console.log('getOsAccountLocalId successfully, localId: ' + localId);
1132
    }).catch((err: BusinessError) => {
C
chennian 已提交
1133
      console.log('getOsAccountLocalId failed, error: ' + JSON.stringify(err));
J
jidong 已提交
1134 1135
    });
  } catch (err) {
C
cclicn 已提交
1136
    console.log('getOsAccountLocalId exception: ' + JSON.stringify(err));
J
jidong 已提交
1137
  }
Z
zhangalong 已提交
1138 1139
  ```

C
cclicn 已提交
1140
### getOsAccountLocalIdForUid<sup>9+</sup>
Z
zhangalong 已提交
1141

C
cclicn 已提交
1142
getOsAccountLocalIdForUid(uid: number, callback: AsyncCallback&lt;number&gt;): void
1143

J
jidong 已提交
1144
根据uid查询对应的系统帐号ID,使用callback异步回调。
Z
zhangalong 已提交
1145

Z
zengyawen 已提交
1146 1147 1148
**系统能力:** SystemCapability.Account.OsAccount

**参数:**
Z
zhangalong 已提交
1149

J
jidong 已提交
1150 1151 1152 1153
| 参数名   | 类型                        | 必填 | 说明                                                                    |
| -------- | --------------------------- | ---- | --------------------------------------------------------------------- |
| uid      | number                      | 是   | 进程uid。                                                              |
| callback | AsyncCallback&lt;number&gt; | 是   | 回调函数。如果查询成功,err为null,data为对应的系统帐号ID;否则为错误对象。 |
Z
zhangalong 已提交
1154

J
jidong 已提交
1155 1156 1157
**错误码:**

| 错误码ID | 错误信息         |
J
jidong 已提交
1158
| -------- | --------------- |
C
chennian 已提交
1159 1160
| 12300001 | System service exception. |
| 12300002 | Invalid uid.    |
J
jidong 已提交
1161 1162

**示例:** 查询值为12345678的uid所属的系统帐号的帐号ID
Z
zhangalong 已提交
1163

Z
zhangalong 已提交
1164
  ```js
1165
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
1166
  let accountManager = account_osAccount.getAccountManager();
1167
  let uid: number = 12345678;
J
jidong 已提交
1168
  try {
1169
    accountManager.getOsAccountLocalIdForUid(uid, (err: BusinessError, localId: number) => {
J
jidong 已提交
1170
      if (err) {
C
chennian 已提交
1171
        console.log('getOsAccountLocalIdForUid failed, error: ' + JSON.stringify(err));
J
jidong 已提交
1172
      }
C
chennian 已提交
1173
      console.log('getOsAccountLocalIdForUid successfully, localId: ' + localId);
J
jidong 已提交
1174 1175
    });
  } catch (err) {
C
chennian 已提交
1176
    console.log('getOsAccountLocalIdForUid exception: ' + JSON.stringify(err));
J
jidong 已提交
1177
  }
Z
zhangalong 已提交
1178 1179
  ```

C
cclicn 已提交
1180
### getOsAccountLocalIdForUid<sup>9+</sup>
Z
zhangalong 已提交
1181

C
cclicn 已提交
1182
getOsAccountLocalIdForUid(uid: number): Promise&lt;number&gt;
1183

J
jidong 已提交
1184
根据uid查询对应的系统帐号ID,使用Promise异步回调。
Z
zhangalong 已提交
1185

Z
zengyawen 已提交
1186
**系统能力:** SystemCapability.Account.OsAccount
Z
zhangalong 已提交
1187

Z
zengyawen 已提交
1188
**参数:**
Z
zhangalong 已提交
1189

J
jidong 已提交
1190 1191 1192
| 参数名 | 类型   | 必填 | 说明      |
| ------ | ------ | ---- | --------- |
| uid    | number | 是   | 进程uid。 |
Z
zhangalong 已提交
1193

Z
zengyawen 已提交
1194
**返回值:**
Z
zhangalong 已提交
1195

J
jidong 已提交
1196 1197 1198
| 类型                  | 说明                                     |
| --------------------- | --------------------------------------- |
| Promise&lt;number&gt; | Promise对象,返回指定uid对应的系统帐号ID。 |
Z
zengyawen 已提交
1199

J
jidong 已提交
1200 1201 1202
**错误码:**

| 错误码ID | 错误信息       |
J
jidong 已提交
1203
| -------- | ------------- |
C
chennian 已提交
1204 1205
| 12300001 | System service exception. |
| 12300002 | Invalid uid. |
J
jidong 已提交
1206 1207

**示例:** 查询值为12345678的uid所属的系统帐号ID
Z
zhangalong 已提交
1208

Z
zhangalong 已提交
1209
  ```js
1210
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
1211
  let accountManager = account_osAccount.getAccountManager();
1212
  let uid: number = 12345678;
J
jidong 已提交
1213
  try {
1214
    accountManager.getOsAccountLocalIdForUid(uid).then((localId: number) => {
C
chennian 已提交
1215
      console.log('getOsAccountLocalIdForUid successfully, localId: ' + localId);
1216
    }).catch((err: BusinessError) => {
C
chennian 已提交
1217
      console.log('getOsAccountLocalIdForUid failed, error: ' + JSON.stringify(err));
J
jidong 已提交
1218 1219
    });
  } catch (err) {
C
cclicn 已提交
1220
    console.log('getOsAccountLocalIdForUid exception: ' + JSON.stringify(err));
J
jidong 已提交
1221
  }
Z
zhangalong 已提交
1222 1223
  ```

C
cclicn 已提交
1224
### getOsAccountLocalIdForDomain<sup>9+</sup>
Z
zhangalong 已提交
1225

C
cclicn 已提交
1226
getOsAccountLocalIdForDomain(domainInfo: DomainAccountInfo, callback: AsyncCallback&lt;number&gt;): void
Z
zhangalong 已提交
1227

J
jidong 已提交
1228
根据域帐号信息,获取与其关联的系统帐号ID。使用callback异步回调。
Z
zengyawen 已提交
1229 1230 1231 1232 1233 1234

**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS

**系统能力:** SystemCapability.Account.OsAccount

**参数:**
Z
zhangalong 已提交
1235

J
jidong 已提交
1236 1237 1238 1239
| 参数名     | 类型                                    | 必填 | 说明                                                                         |
| ---------- | --------------------------------------- | ---- | -------------------------------------------------------------------------- |
| domainInfo | [DomainAccountInfo](#domainaccountinfo8) | 是   | 域帐号信息。                                                                |
| callback   | AsyncCallback&lt;number&gt;             | 是   | 回调函数。如果查询成功,err为null,data为域帐号关联的系统帐号ID;否则为错误对象。 |
Z
zhangalong 已提交
1240

J
jidong 已提交
1241 1242 1243 1244
**错误码:**

| 错误码ID | 错误信息       |
| -------- | ------------- |
C
chennian 已提交
1245 1246
| 12300001 | System service exception. |
| 12300002 | Invalid domainInfo. |
J
jidong 已提交
1247

1248
**示例:**
Z
zhangalong 已提交
1249

Z
zhangalong 已提交
1250
  ```js
1251
  import { BusinessError } from '@ohos.base';
J
jidong 已提交
1252
  let domainInfo = {domain: 'testDomain', accountName: 'testAccountName'};
F
fanchenxuan 已提交
1253
  let accountManager = account_osAccount.getAccountManager();
1254
  try {
1255
    accountManager.getOsAccountLocalIdForDomain(domainInfo, (err: BusinessError, localId: number) => {
J
jidong 已提交
1256
      if (err) {
C
chennian 已提交
1257
        console.log('getOsAccountLocalIdForDomain failed, error: ' + JSON.stringify(err));
J
jidong 已提交
1258
      } else {
C
chennian 已提交
1259
        console.log('getOsAccountLocalIdForDomain successfully, localId: ' + localId);
J
jidong 已提交
1260
      }
J
jidong 已提交
1261
    });
J
jidong 已提交
1262
  } catch (err) {
C
cclicn 已提交
1263
    console.log('getOsAccountLocalIdForDomain exception: ' + JSON.stringify(err));
1264
  }
Z
zhangalong 已提交
1265 1266
  ```

C
cclicn 已提交
1267
### getOsAccountLocalIdForDomain<sup>9+</sup>
Z
zhangalong 已提交
1268

C
cclicn 已提交
1269
getOsAccountLocalIdForDomain(domainInfo: DomainAccountInfo): Promise&lt;number&gt;
Z
zhangalong 已提交
1270

J
jidong 已提交
1271
根据域帐号信息,获取与其关联的系统帐号的帐号ID。使用Promise异步回调。
Z
zengyawen 已提交
1272 1273 1274 1275 1276 1277

**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS

**系统能力:** SystemCapability.Account.OsAccount

**参数:**
Z
zhangalong 已提交
1278

J
jidong 已提交
1279 1280 1281
| 参数名     | 类型                                    | 必填 | 说明         |
| ---------- | --------------------------------------- | ---- | ------------ |
| domainInfo | [DomainAccountInfo](#domainaccountinfo8) | 是   | 域帐号信息。 |
Z
zhangalong 已提交
1282

Z
zengyawen 已提交
1283
**返回值:**
Z
zhangalong 已提交
1284

J
jidong 已提交
1285 1286 1287
| 类型                  | 说明                                    |
| :-------------------- | :------------------------------------- |
| Promise&lt;number&gt; | Promise对象,返回域帐号关联的系统帐号ID。 |
Z
zhangalong 已提交
1288

J
jidong 已提交
1289 1290 1291 1292
**错误码:**

| 错误码ID | 错误信息       |
| -------- | ------------- |
C
chennian 已提交
1293 1294
| 12300001 | System service exception. |
| 12300002 | Invalid domainInfo. |
J
jidong 已提交
1295

1296
**示例:**
Z
zhangalong 已提交
1297

Z
zhangalong 已提交
1298
  ```js
1299
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
1300
  let accountManager = account_osAccount.getAccountManager();
J
jidong 已提交
1301
  let domainInfo = {domain: 'testDomain', accountName: 'testAccountName'};
1302
  try {
1303
    accountManager.getOsAccountLocalIdForDomain(domainInfo).then((localId: number) => {
C
chennian 已提交
1304
      console.log('getOsAccountLocalIdForDomain successfully, localId: ' + localId);
1305
    }).catch((err: BusinessError) => {
C
chennian 已提交
1306
      console.log('getOsAccountLocalIdForDomain failed, error: ' + JSON.stringify(err));
J
jidong 已提交
1307
    });
J
jidong 已提交
1308
  } catch (err) {
C
chennian 已提交
1309
    console.log('getOsAccountLocalIdForDomain exception: ' + JSON.stringify(err));
1310
  }
Z
zhangalong 已提交
1311 1312
  ```

J
jidong 已提交
1313
### queryMaxOsAccountNumber
Z
zhangalong 已提交
1314

J
jidong 已提交
1315
queryMaxOsAccountNumber(callback: AsyncCallback&lt;number&gt;): void
Z
zhangalong 已提交
1316

J
jidong 已提交
1317
查询允许创建的系统帐号的最大数量。使用callback异步回调。
Z
zhangalong 已提交
1318

J
jidong 已提交
1319
**系统接口:** 此接口为系统接口。
Z
zhangalong 已提交
1320

Z
zengyawen 已提交
1321 1322 1323 1324
**系统能力:** SystemCapability.Account.OsAccount

**参数:**

J
jidong 已提交
1325 1326 1327
| 参数名   | 类型                        | 必填 | 说明                                                                              |
| -------- | --------------------------- | ---- | -------------------------------------------------------------------------------- |
| callback | AsyncCallback&lt;number&gt; | 是   | 回调函数,如果查询成功,err为null,data为允许创建的系统帐号的最大数量;否则为错误对象。 |
Z
zengyawen 已提交
1328

J
jidong 已提交
1329 1330 1331 1332 1333 1334
**错误码:**

| 错误码ID | 错误信息       |
| -------- | ------------- |
| 12300001 | System service exception. |

J
jidong 已提交
1335
**示例:**
Z
zhangalong 已提交
1336

Z
zhangalong 已提交
1337
  ```js
1338
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
1339
  let accountManager = account_osAccount.getAccountManager();
1340
  try {
1341
    accountManager.queryMaxOsAccountNumber((err: BusinessError, maxCnt: number) => {
J
jidong 已提交
1342 1343 1344 1345 1346
      if (err) {
        console.log('queryMaxOsAccountNumber failed, error:' + JSON.stringify(err));
      } else {
        console.log('queryMaxOsAccountNumber successfully, maxCnt:' + maxCnt);
      }
1347
    });
J
jidong 已提交
1348
  } catch (err) {
C
chennian 已提交
1349
    console.log('queryMaxOsAccountNumber exception: ' + JSON.stringify(err));
1350
  }
Z
zhangalong 已提交
1351 1352
  ```

J
jidong 已提交
1353
### queryMaxOsAccountNumber
Z
zhangalong 已提交
1354

J
jidong 已提交
1355
queryMaxOsAccountNumber(): Promise&lt;number&gt;
Z
zengyawen 已提交
1356

J
jidong 已提交
1357
查询允许创建的系统帐号的最大数量。使用Promise异步回调。
Z
zhangalong 已提交
1358

J
jidong 已提交
1359
**系统接口:** 此接口为系统接口。
Z
zhangalong 已提交
1360

Z
zengyawen 已提交
1361
**系统能力:** SystemCapability.Account.OsAccount
Z
zhangalong 已提交
1362

Z
zengyawen 已提交
1363 1364
**返回值:**

J
jidong 已提交
1365 1366 1367
| 类型                  | 说明                                         |
| --------------------- | ------------------------------------------- |
| Promise&lt;number&gt; | Promise对象,返回允许创建的系统帐号的最大数量。 |
Z
zengyawen 已提交
1368

J
jidong 已提交
1369 1370 1371 1372 1373 1374
**错误码:**

| 错误码ID | 错误信息       |
| -------- | ------------- |
| 12300001 | System service exception. |

J
jidong 已提交
1375
**示例:**
Z
zhangalong 已提交
1376

Z
zhangalong 已提交
1377
  ```js
1378
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
1379
  let accountManager = account_osAccount.getAccountManager();
1380
  try {
1381
    accountManager.queryMaxOsAccountNumber().then((maxCnt: number) => {
J
jidong 已提交
1382
      console.log('queryMaxOsAccountNumber successfully, maxCnt: ' + maxCnt);
1383
    }).catch((err: BusinessError) => {
C
chennian 已提交
1384
      console.log('queryMaxOsAccountNumber failed, error: ' + JSON.stringify(err));
1385
    });
J
jidong 已提交
1386
  } catch (err) {
C
chennian 已提交
1387
    console.log('queryMaxOsAccountNumber exception: ' + JSON.stringify(err));
1388
  }
Z
zhangalong 已提交
1389 1390
  ```

J
jidong 已提交
1391
### getOsAccountConstraints<sup>9+</sup>
Z
zhangalong 已提交
1392

J
jidong 已提交
1393
getOsAccountConstraints(localId: number, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void
Z
zhangalong 已提交
1394

J
jidong 已提交
1395
获取指定系统帐号的全部约束。使用callback异步回调。
Z
zengyawen 已提交
1396

Z
zhangalong 已提交
1397 1398
**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS

Z
zengyawen 已提交
1399 1400 1401
**系统能力:** SystemCapability.Account.OsAccount

**参数:**
Z
zhangalong 已提交
1402

J
jidong 已提交
1403 1404 1405 1406
| 参数名   | 类型                                     | 必填 | 说明                                                                                           |
| -------- | ---------------------------------------- | ---- | -------------------------------------------------------------------------------------------- |
| localId  | number                                   | 是   | 系统帐号ID。                                                                                  |
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | 是   | 回调函数,如果获取成功,err为null,data为该系统帐号的全部[约束](#系统帐号约束列表);否则为错误对象。 |
Z
zhangalong 已提交
1407

J
jidong 已提交
1408 1409 1410 1411
**错误码:**

| 错误码ID | 错误信息             |
| -------- | ------------------- |
J
jidong 已提交
1412
| 12300001 | System service exception. |
J
jidong 已提交
1413
| 12300002 | Invalid localId.    |
J
jidong 已提交
1414
| 12300003 | Account not found. |
J
jidong 已提交
1415 1416

**示例:** 获取ID为100的系统帐号的全部约束
Z
zhangalong 已提交
1417

Z
zhangalong 已提交
1418
  ```js
1419
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
1420
  let accountManager = account_osAccount.getAccountManager();
1421
  let localId: number = 100;
1422
  try {
1423
    accountManager.getOsAccountConstraints(localId, (err: BusinessError, constraints: string[]) => {
J
jidong 已提交
1424
      if (err) {
C
chennian 已提交
1425
        console.log('getOsAccountConstraints failed, err: ' + JSON.stringify(err));
J
jidong 已提交
1426
      } else {
C
chennian 已提交
1427
        console.log('getOsAccountConstraints successfully, constraints: ' + JSON.stringify(constraints));
J
jidong 已提交
1428
      }
1429
    });
J
jidong 已提交
1430
  } catch (err) {
C
chennian 已提交
1431
    console.log('getOsAccountConstraints exception: ' + JSON.stringify(err));
1432
  }
Z
zhangalong 已提交
1433 1434
  ```

J
jidong 已提交
1435
### getOsAccountConstraints<sup>9+</sup>
Z
zhangalong 已提交
1436

J
jidong 已提交
1437
getOsAccountConstraints(localId: number): Promise&lt;Array&lt;string&gt;&gt;
Z
zhangalong 已提交
1438

J
jidong 已提交
1439
获取指定系统帐号的全部约束。使用Promise异步回调。
Z
zhangalong 已提交
1440

Z
zhangalong 已提交
1441 1442
**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS

Z
zengyawen 已提交
1443
**系统能力:** SystemCapability.Account.OsAccount
Z
zhangalong 已提交
1444

Z
zengyawen 已提交
1445
**参数:**
Z
zhangalong 已提交
1446

J
jidong 已提交
1447 1448 1449
| 参数名  | 类型   | 必填 | 说明         |
| ------- | ------ | ---- | ------------ |
| localId | number | 是   | 系统帐号ID。 |
Z
zhangalong 已提交
1450

Z
zengyawen 已提交
1451 1452
**返回值:**

J
jidong 已提交
1453 1454 1455
| 类型                               | 说明                                                       |
| ---------------------------------- | ---------------------------------------------------------- |
| Promise&lt;Array&lt;string&gt;&gt; | Promise对象,返回指定系统帐号的全部[约束](#系统帐号约束列表)。 |
Z
zengyawen 已提交
1456

J
jidong 已提交
1457 1458 1459 1460
**错误码:**

| 错误码ID | 错误信息             |
| -------- | ------------------- |
J
jidong 已提交
1461
| 12300001 | System service exception. |
J
jidong 已提交
1462
| 12300002 | Invalid localId.    |
J
jidong 已提交
1463
| 12300003 | Account not found. |
J
jidong 已提交
1464 1465

**示例:** 获取ID为100的系统帐号的全部约束
Z
zhangalong 已提交
1466

Z
zhangalong 已提交
1467
  ```js
1468
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
1469
  let accountManager = account_osAccount.getAccountManager();
1470
  let localId: number = 100;
1471
  try {
1472
    accountManager.getOsAccountConstraints(localId).then((constraints: string[]) => {
J
jidong 已提交
1473
      console.log('getOsAccountConstraints, constraints: ' + constraints);
1474
    }).catch((err: BusinessError) => {
C
chennian 已提交
1475
      console.log('getOsAccountConstraints err: ' + JSON.stringify(err));
1476 1477
    });
  } catch (e) {
C
chennian 已提交
1478
    console.log('getOsAccountConstraints exception: ' + JSON.stringify(e));
1479
  }
Z
zhangalong 已提交
1480 1481
  ```

J
jidong 已提交
1482
### queryAllCreatedOsAccounts
1483

J
jidong 已提交
1484
queryAllCreatedOsAccounts(callback: AsyncCallback&lt;Array&lt;OsAccountInfo&gt;&gt;): void
1485

J
jidong 已提交
1486
查询已创建的所有系统帐号的信息列表。使用callback异步回调。
1487

J
jidong 已提交
1488
**系统接口:** 此接口为系统接口。
1489 1490 1491

**系统能力:** SystemCapability.Account.OsAccount

J
jidong 已提交
1492 1493
**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS

1494 1495
**参数:**

J
jidong 已提交
1496 1497 1498
| 参数名   | 类型                                                         | 必填 | 说明                                               |
| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------------- |
| callback | AsyncCallback&lt;Array&lt;[OsAccountInfo](#osaccountinfo)&gt;&gt; | 是   | 回调函数。如果查询成功,err为null,data为已创建的所有系统帐号的信息列表;否则为错误对象。 |
1499

J
jidong 已提交
1500 1501 1502 1503 1504 1505
**错误码:**

| 错误码ID | 错误信息       |
| -------- | ------------- |
| 12300001 | System service exception. |

1506 1507 1508
**示例:**

  ```js
1509
  import { BusinessError } from '@ohos.base';
1510 1511
  let accountManager = account_osAccount.getAccountManager();
  try {
1512
    accountManager.queryAllCreatedOsAccounts((err: BusinessError, accountArr: account_osAccount.OsAccountInfo[])=>{
J
jidong 已提交
1513 1514
      console.log('queryAllCreatedOsAccounts err:' + JSON.stringify(err));
      console.log('queryAllCreatedOsAccounts accountArr:' + JSON.stringify(accountArr));
1515 1516
    });
  } catch (e) {
C
chennian 已提交
1517
    console.log('queryAllCreatedOsAccounts exception: ' + JSON.stringify(e));
1518 1519 1520
  }
  ```

J
jidong 已提交
1521
### queryAllCreatedOsAccounts
1522

J
jidong 已提交
1523
queryAllCreatedOsAccounts(): Promise&lt;Array&lt;OsAccountInfo&gt;&gt;
1524

J
jidong 已提交
1525
查询已创建的所有系统帐号的信息列表。使用Promise异步回调。
1526

J
jidong 已提交
1527
**系统接口:** 此接口为系统接口。
1528 1529 1530

**系统能力:** SystemCapability.Account.OsAccount

J
jidong 已提交
1531 1532
**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS

1533 1534
**返回值:**

J
jidong 已提交
1535 1536 1537
| 类型                                                        | 说明                                           |
| ----------------------------------------------------------- | --------------------------------------------- |
| Promise&lt;Array&lt;[OsAccountInfo](#osaccountinfo)&gt;&gt; | Promise对象,返回已创建的所有系统帐号的信息列表。 |
1538

J
jidong 已提交
1539 1540 1541 1542 1543 1544
**错误码:**

| 错误码ID | 错误信息       |
| -------- | ------------- |
| 12300001 | System service exception. |

1545 1546 1547
**示例:**

  ```js
1548
  import { BusinessError } from '@ohos.base';
1549 1550
  let accountManager = account_osAccount.getAccountManager();
  try {
1551
    accountManager.queryAllCreatedOsAccounts().then((accountArr: account_osAccount.OsAccountInfo[]) => {
J
jidong 已提交
1552
      console.log('queryAllCreatedOsAccounts, accountArr: ' + JSON.stringify(accountArr));
1553
    }).catch((err: BusinessError) => {
C
chennian 已提交
1554
      console.log('queryAllCreatedOsAccounts err: ' + JSON.stringify(err));
1555
    });
J
jidong 已提交
1556
  } catch (e) {
C
chennian 已提交
1557
    console.log('queryAllCreatedOsAccounts exception: ' + JSON.stringify(e));
1558 1559 1560
  }
  ```

C
cclicn 已提交
1561
### getActivatedOsAccountLocalIds<sup>9+</sup>
Z
zhangalong 已提交
1562

C
cclicn 已提交
1563
getActivatedOsAccountLocalIds(callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
1564

J
jidong 已提交
1565
查询当前处于激活状态的系统帐号的ID列表。使用callback异步回调。
Z
zengyawen 已提交
1566 1567 1568 1569

**系统能力:** SystemCapability.Account.OsAccount

**参数:**
Z
zhangalong 已提交
1570

J
jidong 已提交
1571 1572 1573
| 参数名   | 类型                                     | 必填 | 说明                                                   |
| -------- | ---------------------------------------- | ---- | ------------------------------------------------------ |
| callback | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是   | 回调函数。如果查询成功,err为null,data为当前处于激活状态的系统帐号的ID列表;否则为错误对象。 |
Z
zhangalong 已提交
1574

J
jidong 已提交
1575 1576 1577 1578
**错误码:**

| 错误码ID | 错误信息       |
| -------- | ------------- |
C
chennian 已提交
1579
| 12300001 | System service exception. |
J
jidong 已提交
1580

1581
**示例:**
Z
zhangalong 已提交
1582

Z
zhangalong 已提交
1583
  ```js
1584
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
1585
  let accountManager = account_osAccount.getAccountManager();
J
jidong 已提交
1586
  try {
1587
    accountManager.getActivatedOsAccountLocalIds((err: BusinessError, idArray: number[])=>{
C
cclicn 已提交
1588 1589
      console.log('getActivatedOsAccountLocalIds err:' + JSON.stringify(err));
      console.log('getActivatedOsAccountLocalIds idArray length:' + idArray.length);
J
jidong 已提交
1590 1591 1592 1593 1594
      for(let i=0;i<idArray.length;i++) {
        console.info('activated os account id: ' + idArray[i]);
      }
    });
  } catch (e) {
C
chennian 已提交
1595
    console.log('getActivatedOsAccountLocalIds exception: ' + JSON.stringify(e));
J
jidong 已提交
1596
  }
Z
zhangalong 已提交
1597 1598
  ```

C
cclicn 已提交
1599
### getActivatedOsAccountLocalIds<sup>9+</sup>
Z
zhangalong 已提交
1600

C
cclicn 已提交
1601
getActivatedOsAccountLocalIds(): Promise&lt;Array&lt;number&gt;&gt;
1602

J
jidong 已提交
1603
查询当前处于激活状态的系统帐号的ID列表。使用Promise异步回调。
Z
zhangalong 已提交
1604

Z
zengyawen 已提交
1605
**系统能力:** SystemCapability.Account.OsAccount
Z
zhangalong 已提交
1606

Z
zengyawen 已提交
1607 1608
**返回值:**

J
jidong 已提交
1609 1610 1611
| 类型                               | 说明                                               |
| :--------------------------------- | :------------------------------------------------ |
| Promise&lt;Array&lt;number&gt;&gt; | Promise对象,返回当前处于激活状态的系统帐号的ID列表。 |
Z
zengyawen 已提交
1612

J
jidong 已提交
1613 1614 1615 1616
**错误码:**

| 错误码ID | 错误信息       |
| -------- | ------------- |
C
chennian 已提交
1617
| 12300001 | System service exception. |
J
jidong 已提交
1618

1619
**示例:**
Z
zhangalong 已提交
1620

Z
zhangalong 已提交
1621
  ```js
1622
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
1623
  let accountManager = account_osAccount.getAccountManager();
J
jidong 已提交
1624
  try {
1625
    accountManager.getActivatedOsAccountLocalIds().then((idArray: number[]) => {
C
cclicn 已提交
1626
      console.log('getActivatedOsAccountLocalIds, idArray: ' + idArray);
1627
    }).catch((err: BusinessError) => {
C
chennian 已提交
1628
      console.log('getActivatedOsAccountLocalIds err: ' + JSON.stringify(err));
J
jidong 已提交
1629 1630
    });
  } catch (e) {
C
chennian 已提交
1631
    console.log('getActivatedOsAccountLocalIds exception: ' + JSON.stringify(e));
J
jidong 已提交
1632
  }
Z
zhangalong 已提交
1633 1634
  ```

J
jidong 已提交
1635
### createOsAccount
1636

J
jidong 已提交
1637
createOsAccount(localName: string, type: OsAccountType, callback: AsyncCallback&lt;OsAccountInfo&gt;): void
1638

J
jidong 已提交
1639 1640 1641 1642 1643
创建一个系统帐号。使用callback异步回调。

**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
1644 1645 1646 1647 1648

**系统能力:** SystemCapability.Account.OsAccount

**参数:**

J
jidong 已提交
1649 1650 1651 1652 1653 1654 1655
| 参数名    | 类型                                                 | 必填 | 说明                                                                         |
| :-------- | ---------------------------------------------------- | ---- | --------------------------------------------------------------------------- |
| localName | string                                               | 是   | 创建的系统帐号的名称。                                                        |
| type      | [OsAccountType](#osaccounttype)                      | 是   | 创建的系统帐号的类型。                                                        |
| callback  | AsyncCallback&lt;[OsAccountInfo](#osaccountinfo)&gt; | 是   | 回调函数。如果创建成功,err为null,data为新创建的系统帐号的信息;否则为错误对象。 |

**错误码:**
J
jidong 已提交
1656 1657 1658 1659

| 错误码ID  | 错误信息                   |
| -------- | ------------------------- |
| 12300001 | System service exception. |
J
jidong 已提交
1660
| 12300002 | Invalid localName or type. |
J
jidong 已提交
1661 1662
| 12300005 | Multi-user not supported. |
| 12300006 | Unsupported account type. |
1663
| 12300007 | The number of accounts reaches the upper limit. |
1664 1665 1666 1667

**示例:**

  ```js
1668
  import { BusinessError } from '@ohos.base';
1669 1670
  let accountManager = account_osAccount.getAccountManager();
  try {
1671 1672
    accountManager.createOsAccount('testName', account_osAccount.OsAccountType.NORMAL,
      (err: BusinessError, osAccountInfo: account_osAccount.OsAccountInfo)=>{
J
jidong 已提交
1673 1674
      console.log('createOsAccount err:' + JSON.stringify(err));
      console.log('createOsAccount osAccountInfo:' + JSON.stringify(osAccountInfo));
1675 1676
    });
  } catch (e) {
C
chennian 已提交
1677
    console.log('createOsAccount exception: ' + JSON.stringify(e));
1678 1679 1680
  }
  ```

J
jidong 已提交
1681
### createOsAccount
1682

J
jidong 已提交
1683
createOsAccount(localName: string, type: OsAccountType): Promise&lt;OsAccountInfo&gt;
1684

J
jidong 已提交
1685 1686 1687 1688 1689
创建一个系统帐号。使用Promise异步回调。 

**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
1690 1691 1692

**系统能力:** SystemCapability.Account.OsAccount

J
jidong 已提交
1693 1694 1695 1696 1697 1698 1699
**参数:**

| 参数名    | 类型                            | 必填 | 说明                   |
| --------- | ------------------------------- | ---- | ---------------------- |
| localName | string                          | 是   | 创建的系统帐号的名称。 |
| type      | [OsAccountType](#osaccounttype) | 是   | 创建的系统帐号的类型。 |

1700 1701
**返回值:**

J
jidong 已提交
1702 1703
| 类型                                           | 说明                                  |
| ---------------------------------------------- | ------------------------------------- |
A
Annie_wang 已提交
1704
| Promise&lt;[OsAccountInfo](#osaccountinfo)&gt; | Promise对象,返回新创建的系统帐号的信息。 |
J
jidong 已提交
1705 1706

**错误码:**
J
jidong 已提交
1707 1708 1709 1710

| 错误码ID  | 错误信息                   |
| -------- | ------------------------- |
| 12300001 | System service exception. |
J
jidong 已提交
1711
| 12300002 | Invalid localName or type. |
J
jidong 已提交
1712 1713
| 12300005 | Multi-user not supported. |
| 12300006 | Unsupported account type. |
1714
| 12300007 | The number of accounts reaches the upper limit. |
1715 1716 1717 1718

**示例:**

  ```js
1719
  import { BusinessError } from '@ohos.base';
1720 1721
  let accountManager = account_osAccount.getAccountManager();
  try {
1722 1723
    accountManager.createOsAccount('testAccountName', account_osAccount.OsAccountType.NORMAL).then(
      (accountInfo: account_osAccount.OsAccountInfo) => {
J
jidong 已提交
1724
      console.log('createOsAccount, accountInfo: ' + JSON.stringify(accountInfo));
1725
    }).catch((err: BusinessError) => {
C
chennian 已提交
1726
      console.log('createOsAccount err: ' + JSON.stringify(err));
1727 1728
    });
  } catch (e) {
C
chennian 已提交
1729
    console.log('createOsAccount exception: ' + JSON.stringify(e));
1730 1731 1732
  }
  ```

J
jidong 已提交
1733
### createOsAccountForDomain<sup>8+</sup>
Z
zhangalong 已提交
1734

J
jidong 已提交
1735
createOsAccountForDomain(type: OsAccountType, domainInfo: DomainAccountInfo, callback: AsyncCallback&lt;OsAccountInfo&gt;): void
Z
zhangalong 已提交
1736

J
jidong 已提交
1737
根据域帐号信息,创建一个系统帐号并将其与域帐号关联。使用callback异步回调。
Z
zhangalong 已提交
1738

J
jidong 已提交
1739 1740 1741
**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
1742

Z
zengyawen 已提交
1743 1744 1745
**系统能力:** SystemCapability.Account.OsAccount

**参数:**
Z
zhangalong 已提交
1746

J
jidong 已提交
1747
| 参数名     | 类型                                                 | 必填 | 说明                                                                         |
J
jidong 已提交
1748
| ---------- | ---------------------------------------------------- | ---- | -------------------------------------------------------------------------- |
J
jidong 已提交
1749 1750 1751 1752 1753
| type       | [OsAccountType](#osaccounttype)                      | 是   | 创建的系统帐号的类型。                                                       |
| domainInfo | [DomainAccountInfo](#domainaccountinfo8)              | 是   | 域帐号信息。                                                               |
| callback   | AsyncCallback&lt;[OsAccountInfo](#osaccountinfo)&gt; | 是   | 回调函数。如果创建成功,err为null,data为新创建的系统帐号的信息;否则为错误对象。 |

**错误码:**
J
jidong 已提交
1754

J
jidong 已提交
1755
| 错误码ID | 错误信息                     |
J
jidong 已提交
1756 1757
| -------- | ------------------- |
| 12300001 | System service exception. |
J
jidong 已提交
1758
| 12300002 | Invalid type or domainInfo. |
J
jidong 已提交
1759 1760
| 12300005 | Multi-user not supported. |
| 12300006 | Unsupported account type. |
1761
| 12300007 | The number of accounts reaches the upper limit. |
Z
zhangalong 已提交
1762

1763
**示例:**
Z
zhangalong 已提交
1764

Z
zhangalong 已提交
1765
  ```js
1766
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
1767
  let accountManager = account_osAccount.getAccountManager();
J
jidong 已提交
1768 1769
  let domainInfo = {domain: 'testDomain', accountName: 'testAccountName'};
  try {
1770 1771
    accountManager.createOsAccountForDomain(account_osAccount.OsAccountType.NORMAL, domainInfo,
      (err: BusinessError, osAccountInfo: account_osAccount.OsAccountInfo)=>{
J
jidong 已提交
1772 1773 1774 1775
      console.log('createOsAccountForDomain err:' + JSON.stringify(err));
      console.log('createOsAccountForDomain osAccountInfo:' + JSON.stringify(osAccountInfo));
    });
  } catch (e) {
C
chennian 已提交
1776
    console.log('createOsAccountForDomain exception: ' + JSON.stringify(e));
J
jidong 已提交
1777
  }
Z
zhangalong 已提交
1778 1779
  ```

J
jidong 已提交
1780
### createOsAccountForDomain<sup>8+</sup>
Z
zhangalong 已提交
1781

J
jidong 已提交
1782
createOsAccountForDomain(type: OsAccountType, domainInfo: DomainAccountInfo): Promise&lt;OsAccountInfo&gt;
Z
zhangalong 已提交
1783

J
jidong 已提交
1784
根据传入的域帐号信息,创建与其关联的系统帐号。使用Promise异步回调。 
Z
zhangalong 已提交
1785

J
jidong 已提交
1786 1787 1788
**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
1789

Z
zengyawen 已提交
1790
**系统能力:** SystemCapability.Account.OsAccount
Z
zhangalong 已提交
1791

J
jidong 已提交
1792 1793 1794 1795 1796 1797 1798
**参数:**

| 参数名     | 类型                                      | 必填 | 说明                 |
| ---------- | ---------------------------------------- | ---- | -------------------- |
| type       | [OsAccountType](#osaccounttype)          | 是   | 创建的系统帐号的类型。 |
| domainInfo | [DomainAccountInfo](#domainaccountinfo8) | 是   | 域帐号信息。          |

Z
zengyawen 已提交
1799
**返回值:**
Z
zhangalong 已提交
1800

J
jidong 已提交
1801 1802 1803 1804 1805
| 类型                                           | 说明                                    |
| ---------------------------------------------- | -------------------------------------- |
| Promise&lt;[OsAccountInfo](#osaccountinfo)&gt; | Promise对象,返回新创建的系统帐号的信息。 |

**错误码:**
J
jidong 已提交
1806

J
jidong 已提交
1807
| 错误码ID | 错误信息                     |
J
jidong 已提交
1808 1809
| -------- | ------------------- |
| 12300001 | System service exception. |
J
jidong 已提交
1810
| 12300002 | Invalid type or domainInfo. |
J
jidong 已提交
1811 1812
| 12300005 | Multi-user not supported. |
| 12300006 | Unsupported account type. |
1813
| 12300007 | The number of accounts reaches the upper limit. |
Z
zengyawen 已提交
1814

1815
**示例:**
Z
zhangalong 已提交
1816

Z
zhangalong 已提交
1817
  ```js
1818
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
1819
  let accountManager = account_osAccount.getAccountManager();
J
jidong 已提交
1820 1821
  let domainInfo = {domain: 'testDomain', accountName: 'testAccountName'};
  try {
1822 1823
    accountManager.createOsAccountForDomain(account_osAccount.OsAccountType.NORMAL, domainInfo).then(
      (accountInfo: account_osAccount.OsAccountInfo) => {
J
jidong 已提交
1824
      console.log('createOsAccountForDomain, account info: ' + JSON.stringify(accountInfo));
1825
    }).catch((err: BusinessError) => {
C
chennian 已提交
1826
      console.log('createOsAccountForDomain err: ' + JSON.stringify(err));
J
jidong 已提交
1827 1828
    });
  } catch (e) {
C
chennian 已提交
1829
    console.log('createOsAccountForDomain exception: ' + JSON.stringify(e));
J
jidong 已提交
1830
  }
Z
zhangalong 已提交
1831 1832
  ```

J
jidong 已提交
1833
### getCurrentOsAccount<sup>9+</sup>
1834

J
jidong 已提交
1835
getCurrentOsAccount(callback: AsyncCallback&lt;OsAccountInfo&gt;): void
1836

J
jidong 已提交
1837 1838
查询当前进程所属的系统帐号的信息。使用callback异步回调。

1839
**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.GET_LOCAL_ACCOUNTS<sup>10+</sup>
1840 1841 1842 1843 1844

**系统能力:** SystemCapability.Account.OsAccount

**参数:**

J
jidong 已提交
1845 1846 1847
| 参数名   | 类型                                                 | 必填 | 说明                                           |
| -------- | ---------------------------------------------------- | ---- | ---------------------------------------------- |
| callback | AsyncCallback&lt;[OsAccountInfo](#osaccountinfo)&gt; | 是   | 回调函数。如果查询成功,err为null,data为当前进程所属的系统帐号信息;否则为错误对象。 |
1848

J
jidong 已提交
1849 1850 1851 1852 1853 1854
**错误码:**

| 错误码ID | 错误信息             |
| -------- | ------------------- |
| 12300001 | System service exception. |

J
jidong 已提交
1855
**示例:**
1856 1857

  ```js
1858
  import { BusinessError } from '@ohos.base';
1859 1860
  let accountManager = account_osAccount.getAccountManager();
  try {
1861
    accountManager.getCurrentOsAccount((err: BusinessError, curAccountInfo: account_osAccount.OsAccountInfo)=>{
J
jidong 已提交
1862 1863
      console.log('getCurrentOsAccount err:' + JSON.stringify(err));
      console.log('getCurrentOsAccount curAccountInfo:' + JSON.stringify(curAccountInfo));
1864 1865
    });
  } catch (e) {
C
chennian 已提交
1866
    console.log('getCurrentOsAccount exception: ' + JSON.stringify(e));
1867 1868 1869
  }
  ```

J
jidong 已提交
1870
### getCurrentOsAccount<sup>9+</sup>
1871

J
jidong 已提交
1872
getCurrentOsAccount(): Promise&lt;OsAccountInfo&gt;
1873

J
jidong 已提交
1874
查询当前进程所属的系统帐号的信息。使用Promise异步回调。
1875

1876
**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.GET_LOCAL_ACCOUNTS<sup>10+</sup>
1877

J
jidong 已提交
1878
**系统能力:** SystemCapability.Account.OsAccount
1879 1880 1881

**返回值:**

J
jidong 已提交
1882 1883 1884
| 类型                                           | 说明                                       |
| ---------------------------------------------- | ----------------------------------------- |
| Promise&lt;[OsAccountInfo](#osaccountinfo)&gt; | Promise对象,返回当前进程所属的系统帐号信息。 |
1885

J
jidong 已提交
1886 1887 1888 1889 1890 1891
**错误码:**

| 错误码ID | 错误信息             |
| -------- | ------------------- |
| 12300001 | System service exception. |

J
jidong 已提交
1892
**示例:**
1893 1894

  ```js
1895
  import { BusinessError } from '@ohos.base';
1896 1897
  let accountManager = account_osAccount.getAccountManager();
  try {
1898
    accountManager.getCurrentOsAccount().then((accountInfo: account_osAccount.OsAccountInfo) => {
J
jidong 已提交
1899
      console.log('getCurrentOsAccount, accountInfo: ' + JSON.stringify(accountInfo));
1900
    }).catch((err: BusinessError) => {
C
chennian 已提交
1901
      console.log('getCurrentOsAccount err: ' + JSON.stringify(err));
1902 1903
    });
  } catch (e) {
C
chennian 已提交
1904
    console.log('getCurrentOsAccount exception: ' + JSON.stringify(e));
1905 1906 1907
  }
  ```

J
jidong 已提交
1908
### queryOsAccountById
Z
zhangalong 已提交
1909

J
jidong 已提交
1910
queryOsAccountById(localId: number, callback: AsyncCallback&lt;OsAccountInfo&gt;): void
Z
zhangalong 已提交
1911

J
jidong 已提交
1912
查询指定系统帐号的信息。使用callback异步回调。
Z
zhangalong 已提交
1913

J
jidong 已提交
1914 1915 1916
**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION
1917

Z
zengyawen 已提交
1918 1919 1920
**系统能力:** SystemCapability.Account.OsAccount

**参数:**
Z
zhangalong 已提交
1921

J
jidong 已提交
1922 1923 1924 1925
| 参数名   | 类型                                                 | 必填 | 说明                                                                       |
| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------------------ |
| localId  | number                                               | 是   | 要查询的系统帐号的ID。                                                      |
| callback | AsyncCallback&lt;[OsAccountInfo](#osaccountinfo)&gt; | 是   | 回调函数。如果查询成功,err为null,data为查到的系统帐号的信息;否则为错误对象。 |
Z
zhangalong 已提交
1926

J
jidong 已提交
1927
**错误码:**
J
jidong 已提交
1928

J
jidong 已提交
1929 1930
| 错误码ID | 错误信息             |
| -------- | ------------------- |
J
jidong 已提交
1931
| 12300001 | System service exception. |
J
jidong 已提交
1932
| 12300002 | Invalid localId.    |
J
jidong 已提交
1933
| 12300003 | Account not found. |
J
jidong 已提交
1934 1935

**示例:** 查询ID为100的系统帐号信息
Z
zhangalong 已提交
1936

Z
zhangalong 已提交
1937
  ```js
1938
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
1939
  let accountManager = account_osAccount.getAccountManager();
1940
  let localId: number = 100;
J
jidong 已提交
1941
  try {
1942
    accountManager.queryOsAccountById(localId, (err: BusinessError, accountInfo: account_osAccount.OsAccountInfo)=>{
J
jidong 已提交
1943 1944 1945 1946
      console.log('queryOsAccountById err:' + JSON.stringify(err));
      console.log('queryOsAccountById accountInfo:' + JSON.stringify(accountInfo));
    });
  } catch (e) {
C
chennian 已提交
1947
    console.log('queryOsAccountById exception: ' + JSON.stringify(e));
J
jidong 已提交
1948
  }
Z
zhangalong 已提交
1949 1950
  ```

J
jidong 已提交
1951
### queryOsAccountById
Z
zhangalong 已提交
1952

J
jidong 已提交
1953
queryOsAccountById(localId: number): Promise&lt;OsAccountInfo&gt;
Z
zhangalong 已提交
1954

J
jidong 已提交
1955
查询指定系统帐号的信息。使用Promise异步回调。
Z
zhangalong 已提交
1956

J
jidong 已提交
1957 1958 1959
**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION
1960

Z
zengyawen 已提交
1961
**系统能力:** SystemCapability.Account.OsAccount
Z
zhangalong 已提交
1962

Z
zengyawen 已提交
1963
**参数:**
Z
zhangalong 已提交
1964

J
jidong 已提交
1965 1966 1967
| 参数名  | 类型   | 必填 | 说明                 |
| ------- | ------ | ---- | -------------------- |
| localId | number | 是   | 要查询的系统帐号的ID |
Z
zhangalong 已提交
1968

Z
zengyawen 已提交
1969
**返回值:**
Z
zhangalong 已提交
1970

J
jidong 已提交
1971 1972 1973
| 类型                                           | 说明                                 |
| ---------------------------------------------- | ------------------------------------ |
| Promise&lt;[OsAccountInfo](#osaccountinfo)&gt; | Promise对象,返回查到的系统帐号的信息。 |
Z
zengyawen 已提交
1974

J
jidong 已提交
1975
**错误码:**
J
jidong 已提交
1976

J
jidong 已提交
1977 1978
| 错误码ID | 错误信息             |
| -------- | ------------------- |
J
jidong 已提交
1979
| 12300001 | System service exception. |
C
chennian 已提交
1980
| 12300002 | Invalid localId. |
J
jidong 已提交
1981
| 12300003 | Account not found. |
J
jidong 已提交
1982 1983

**示例:** 查询ID为100的系统帐号信息
Z
zhangalong 已提交
1984

Z
zhangalong 已提交
1985
  ```js
1986
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
1987
  let accountManager = account_osAccount.getAccountManager();
1988
  let localId: number = 100;
J
jidong 已提交
1989
  try {
1990
    accountManager.queryOsAccountById(localId).then((accountInfo: account_osAccount.OsAccountInfo) => {
J
jidong 已提交
1991
      console.log('queryOsAccountById, accountInfo: ' + JSON.stringify(accountInfo));
1992
    }).catch((err: BusinessError) => {
C
chennian 已提交
1993
      console.log('queryOsAccountById err: ' + JSON.stringify(err));
J
jidong 已提交
1994 1995
    });
  } catch (e) {
C
chennian 已提交
1996
    console.log('queryOsAccountById exception: ' + JSON.stringify(e));
J
jidong 已提交
1997
  }
Z
zhangalong 已提交
1998 1999
  ```

J
jidong 已提交
2000
### getOsAccountType<sup>9+</sup>
2001

J
jidong 已提交
2002
getOsAccountType(callback: AsyncCallback&lt;OsAccountType&gt;): void
2003

J
jidong 已提交
2004
查询当前进程所属的系统帐号的帐号类型。使用callback异步回调。
2005 2006 2007 2008 2009

**系统能力:** SystemCapability.Account.OsAccount

**参数:**

J
jidong 已提交
2010 2011 2012
| 参数名   | 类型                                                 | 必填 | 说明                                                 |
| -------- | ---------------------------------------------------- | ---- | ---------------------------------------------------- |
| callback | AsyncCallback&lt;[OsAccountType](#osaccounttype)&gt; | 是   | 回调函数。如果查询成功,err为null,data为当前进程所属的系统帐号的帐号类型;否则为错误对象。 |
2013

J
jidong 已提交
2014 2015 2016 2017 2018 2019
**错误码:**

| 错误码ID | 错误信息             |
| -------- | ------------------- |
| 12300001 | System service exception. |

2020 2021 2022
**示例:**

  ```js
2023
  import { BusinessError } from '@ohos.base';
2024 2025
  let accountManager = account_osAccount.getAccountManager();
  try {
2026
    accountManager.getOsAccountType((err: BusinessError, accountType: account_osAccount.OsAccountType) => {
J
jidong 已提交
2027 2028
      console.log('getOsAccountType err: ' + JSON.stringify(err));
      console.log('getOsAccountType accountType: ' + accountType);
2029 2030
    });
  } catch (e) {
J
jidong 已提交
2031
    console.log('getOsAccountType exception: ' + JSON.stringify(e));
2032 2033 2034
  }
  ```

J
jidong 已提交
2035
### getOsAccountType<sup>9+</sup>
2036

J
jidong 已提交
2037
getOsAccountType(): Promise&lt;OsAccountType&gt;
2038

J
jidong 已提交
2039
查询当前进程所属的系统帐号的帐号类型。使用Promise异步回调。
2040 2041 2042 2043 2044

**系统能力:** SystemCapability.Account.OsAccount

**返回值:**

J
jidong 已提交
2045 2046 2047
| 类型                                           | 说明                                             |
| ---------------------------------------------- | ----------------------------------------------- |
| Promise&lt;[OsAccountType](#osaccounttype)&gt; | Promise对象,返回当前进程所属的系统帐号的帐号类型。 |
2048

J
jidong 已提交
2049 2050 2051 2052 2053 2054
**错误码:**

| 错误码ID | 错误信息             |
| -------- | ------------------- |
| 12300001 | System service exception. |

2055 2056 2057
**示例:**

  ```js
2058
  import { BusinessError } from '@ohos.base';
2059 2060
  let accountManager = account_osAccount.getAccountManager();
  try {
2061
    accountManager.getOsAccountType().then((accountType: account_osAccount.OsAccountType) => {
J
jidong 已提交
2062
      console.log('getOsAccountType, accountType: ' + accountType);
2063
    }).catch((err: BusinessError) => {
C
chennian 已提交
2064
      console.log('getOsAccountType err: ' + JSON.stringify(err));
2065 2066
    });
  } catch (e) {
J
jidong 已提交
2067
    console.log('getOsAccountType exception: ' + JSON.stringify(e));
2068 2069 2070
  }
  ```

J
jidong 已提交
2071
### queryDistributedVirtualDeviceId<sup>9+</sup>
Z
zhangalong 已提交
2072

J
jidong 已提交
2073
queryDistributedVirtualDeviceId(callback: AsyncCallback&lt;string&gt;): void
Z
zhangalong 已提交
2074

J
jidong 已提交
2075
获取分布式虚拟设备ID。使用callback异步回调。
2076

J
jidong 已提交
2077
**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC or ohos.permission.MANAGE_LOCAL_ACCOUNTS
Z
zengyawen 已提交
2078 2079

**系统能力:** SystemCapability.Account.OsAccount
Z
zhangalong 已提交
2080

Z
zengyawen 已提交
2081
**参数:**
Z
zhangalong 已提交
2082

J
jidong 已提交
2083 2084 2085
| 参数名   | 类型                        | 必填 | 说明                                                                   |
| -------- | --------------------------- | ---- | --------------------------------------------------------------------- |
| callback | AsyncCallback&lt;string&gt; | 是   | 回调函数。如果获取成功,err为null,data为分布式虚拟设备ID;否则为错误对象。 |
Z
zengyawen 已提交
2086

J
jidong 已提交
2087 2088 2089 2090 2091 2092
**错误码:**

| 错误码ID | 错误信息             |
| -------- | ------------------- |
| 12300001 | System service exception. |

2093
**示例:**
Z
zhangalong 已提交
2094

Z
zhangalong 已提交
2095
  ```js
2096
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
2097
  let accountManager = account_osAccount.getAccountManager();
J
jidong 已提交
2098
  try {
2099
    accountManager.queryDistributedVirtualDeviceId((err: BusinessError, virtualID: string) => {
J
jidong 已提交
2100 2101 2102 2103 2104 2105
      console.log('queryDistributedVirtualDeviceId err: ' + JSON.stringify(err));
      console.log('queryDistributedVirtualDeviceId virtualID: ' + virtualID);
    });
  } catch (e) {
    console.log('queryDistributedVirtualDeviceId exception: ' + JSON.stringify(e));
  }
Z
zhangalong 已提交
2106 2107
  ```

J
jidong 已提交
2108
### queryDistributedVirtualDeviceId<sup>9+</sup>
Z
zhangalong 已提交
2109

J
jidong 已提交
2110
queryDistributedVirtualDeviceId(): Promise&lt;string&gt;
Z
zhangalong 已提交
2111

J
jidong 已提交
2112
获取分布式虚拟设备ID。使用Promise异步回调。
2113

J
jidong 已提交
2114
**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC or ohos.permission.MANAGE_LOCAL_ACCOUNTS
Z
zengyawen 已提交
2115 2116 2117 2118

**系统能力:** SystemCapability.Account.OsAccount

**返回值:**
Z
zhangalong 已提交
2119

J
jidong 已提交
2120 2121 2122
| 类型                  | 说明                              |
| --------------------- | --------------------------------- |
| Promise&lt;string&gt; | Promise对象,返回分布式虚拟设备ID。 |
Z
zhangalong 已提交
2123

J
jidong 已提交
2124 2125 2126 2127 2128 2129
**错误码:**

| 错误码ID | 错误信息             |
| -------- | ------------------- |
| 12300001 | System service exception. |

2130
**示例:**
Z
zhangalong 已提交
2131

Z
zhangalong 已提交
2132
  ```js
2133
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
2134
  let accountManager = account_osAccount.getAccountManager();
J
jidong 已提交
2135
  try {
2136
    accountManager.queryDistributedVirtualDeviceId().then((virtualID: string) => {
J
jidong 已提交
2137
      console.log('queryDistributedVirtualDeviceId, virtualID: ' + virtualID);
2138
    }).catch((err: BusinessError) => {
C
chennian 已提交
2139
      console.log('queryDistributedVirtualDeviceId err: ' + JSON.stringify(err));
J
jidong 已提交
2140 2141 2142 2143
    });
  } catch (e) {
    console.log('queryDistributedVirtualDeviceId exception: ' + JSON.stringify(e));
  }
Z
zhangalong 已提交
2144 2145
  ```

J
jidong 已提交
2146
### getOsAccountProfilePhoto
Z
zhangalong 已提交
2147

J
jidong 已提交
2148
getOsAccountProfilePhoto(localId: number, callback: AsyncCallback&lt;string&gt;): void
Z
zhangalong 已提交
2149

J
jidong 已提交
2150
获取指定系统帐号的头像信息。使用callback异步回调。
Z
zhangalong 已提交
2151

J
jidong 已提交
2152 2153 2154
**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
Z
zhangalong 已提交
2155

Z
zengyawen 已提交
2156
**系统能力:** SystemCapability.Account.OsAccount
Z
zhangalong 已提交
2157

Z
zengyawen 已提交
2158 2159
**参数:**

J
jidong 已提交
2160 2161 2162 2163
| 参数名   | 类型                        | 必填 | 说明                                                                         |
| -------- | --------------------------- | ---- | -------------------------------------------------------------------------- |
| localId  | number                      | 是   | 系统帐号ID。                                                                |
| callback | AsyncCallback&lt;string&gt; | 是   | 回调函数。如果获取成功,err为null,data为指定系统帐号的头像信息;否则为错误对象。 |
Z
zengyawen 已提交
2164

J
jidong 已提交
2165
**错误码:**
J
jidong 已提交
2166

J
jidong 已提交
2167 2168
| 错误码ID | 错误信息             |
| -------- | ------------------- |
J
jidong 已提交
2169
| 12300001 | System service exception. |
J
jidong 已提交
2170
| 12300002 | Invalid localId.    |
J
jidong 已提交
2171
| 12300003 | Account not found. |
J
jidong 已提交
2172 2173

**示例:** 获取ID为100的系统帐号的头像
Z
zhangalong 已提交
2174

Z
zhangalong 已提交
2175
  ```js
2176
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
2177
  let accountManager = account_osAccount.getAccountManager();
2178
  let localId: number = 100;
2179
  try {
2180
    accountManager.getOsAccountProfilePhoto(localId, (err: BusinessError, photo: string)=>{
J
jidong 已提交
2181 2182
      console.log('getOsAccountProfilePhoto err:' + JSON.stringify(err));
      console.log('get photo:' + photo + ' by localId: ' + localId);
2183 2184
    });
  } catch (e) {
C
chennian 已提交
2185
    console.log('getOsAccountProfilePhoto exception: ' + JSON.stringify(e));
2186
  }
Z
zhangalong 已提交
2187 2188
  ```

J
jidong 已提交
2189
### getOsAccountProfilePhoto
Z
zhangalong 已提交
2190

J
jidong 已提交
2191
getOsAccountProfilePhoto(localId: number): Promise&lt;string&gt;
Z
zhangalong 已提交
2192

J
jidong 已提交
2193
获取指定系统帐号的头像信息。使用Promise异步回调。
Z
zhangalong 已提交
2194

J
jidong 已提交
2195 2196 2197
**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
Z
zengyawen 已提交
2198 2199 2200

**系统能力:** SystemCapability.Account.OsAccount

J
jidong 已提交
2201 2202 2203 2204 2205 2206
**参数:**

| 参数名  | 类型   | 必填 | 说明         |
| ------- | ------ | ---- | ------------ |
| localId | number | 是   | 系统帐号ID。 |

Z
zengyawen 已提交
2207
**返回值:**
Z
zhangalong 已提交
2208

J
jidong 已提交
2209 2210 2211
| 类型                  | 说明                                    |
| --------------------- | -------------------------------------- |
| Promise&lt;string&gt; | Promise对象,返回指定系统帐号的头像信息。 |
Z
zhangalong 已提交
2212

J
jidong 已提交
2213
**错误码:**
J
jidong 已提交
2214

J
jidong 已提交
2215 2216
| 错误码ID | 错误信息             |
| -------- | ------------------- |
J
jidong 已提交
2217
| 12300001 | System service exception. |
J
jidong 已提交
2218
| 12300002 | Invalid localId.    |
J
jidong 已提交
2219
| 12300003 | Account not found. |
J
jidong 已提交
2220 2221

**示例:** 获取ID为100的系统帐号的头像
Z
zhangalong 已提交
2222

Z
zhangalong 已提交
2223
  ```js
2224
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
2225
  let accountManager = account_osAccount.getAccountManager();
2226
  let localId: number = 100;
2227
  try {
2228
    accountManager.getOsAccountProfilePhoto(localId).then((photo: string) => {
J
jidong 已提交
2229
      console.log('getOsAccountProfilePhoto: ' + photo);
2230
    }).catch((err: BusinessError) => {
C
chennian 已提交
2231
      console.log('getOsAccountProfilePhoto err: ' + JSON.stringify(err));
2232 2233
    });
  } catch (e) {
C
chennian 已提交
2234
    console.log('getOsAccountProfilePhoto exception: ' + JSON.stringify(e));
2235 2236 2237
  }
  ```

J
jidong 已提交
2238
### setOsAccountProfilePhoto
2239

J
jidong 已提交
2240 2241 2242
setOsAccountProfilePhoto(localId: number, photo: string, callback: AsyncCallback&lt;void&gt;): void

为指定系统帐号设置头像信息。使用callback异步回调。
2243

J
jidong 已提交
2244
**系统接口:** 此接口为系统接口。
2245

J
jidong 已提交
2246
**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
2247 2248 2249 2250 2251

**系统能力:** SystemCapability.Account.OsAccount

**参数:**

J
jidong 已提交
2252 2253 2254 2255
| 参数名   | 类型                      | 必填 | 说明         |
| -------- | ------------------------- | ---- | ------------ |
| localId  | number                    | 是   | 系统帐号ID。 |
| photo    | string                    | 是   | 头像信息。   |
2256
| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。如果设置成功,err为null,否则为错误对象。  |
J
jidong 已提交
2257 2258

**错误码:**
J
jidong 已提交
2259

J
jidong 已提交
2260 2261
| 错误码ID | 错误信息             |
| -------- | ------------------- |
J
jidong 已提交
2262 2263 2264 2265
| 12300001 | System service exception. |
| 12300002 | Invalid localId or photo.    |
| 12300003 | Account not found. |
| 12300008 | Restricted Account. |
2266

J
jidong 已提交
2267
**示例:** 给ID为100的系统帐号设置头像
2268 2269

  ```js
2270
  import { BusinessError } from '@ohos.base';
2271
  let accountManager = account_osAccount.getAccountManager();
2272 2273
  let localId: number = 100;
  let photo: string = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAAPCAYAAAA/I0V3AAAAAXNSR0IArs4c6QAAAARnQU1BAA'+
J
jidong 已提交
2274 2275 2276
  'Cxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACwSURBVDhPvZLBDYMwDEV/ugsXRjAT0EHCOuFIBwkbdIRewi6unbiAyoGgSn1SFH85+Y'+
  'q/4ljARW62X+LHS8uIzjm4dXUYF+utzBikB52Jo5e5iEPKqpACk7R9NM2RvWm5tIkD2czLCUFNKLD6IjdMHFHDzws285MgGrT0xCtp3WOKHo'+
  '+7q0mP0DZW9pNmoEFUzrQjp5cCnaen2kSJXLFD8ghbXyZCMQf/8e8Ns1XVAG/XAgqKzVnJFAAAAABJRU5ErkJggg=='
2277
  try {
2278
    accountManager.setOsAccountProfilePhoto(localId, photo, (err: BusinessError)=>{
J
jidong 已提交
2279
      console.log('setOsAccountProfilePhoto err:' + JSON.stringify(err));
2280 2281
    });
  } catch (e) {
C
chennian 已提交
2282
    console.log('setOsAccountProfilePhoto exception: ' + JSON.stringify(e));
2283 2284 2285
  }
  ```

J
jidong 已提交
2286
### setOsAccountProfilePhoto
2287

J
jidong 已提交
2288 2289 2290
setOsAccountProfilePhoto(localId: number, photo: string): Promise&lt;void&gt;

为指定系统帐号设置头像信息。使用Promise异步回调。
2291

J
jidong 已提交
2292
**系统接口:** 此接口为系统接口。
2293

J
jidong 已提交
2294
**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
2295 2296 2297 2298 2299 2300 2301 2302

**系统能力:** SystemCapability.Account.OsAccount

**参数:**

| 参数名  | 类型   | 必填 | 说明         |
| ------- | ------ | ---- | ------------ |
| localId | number | 是   | 系统帐号ID。 |
J
jidong 已提交
2303
| photo   | string | 是   | 头像信息。   |
2304 2305 2306

**返回值:**

J
jidong 已提交
2307
| 类型                | 说明                                 |
J
jidong 已提交
2308
| ------------------- | ------------------------------------ |
A
Annie_wang 已提交
2309
| Promise&lt;void&gt; | Promise对象,无返回结果的Promise对象。 |
2310

J
jidong 已提交
2311
**错误码:**
J
jidong 已提交
2312

J
jidong 已提交
2313 2314
| 错误码ID | 错误信息             |
| -------- | ------------------- |
J
jidong 已提交
2315 2316 2317 2318
| 12300001 | System service exception. |
| 12300002 | Invalid localId or photo.    |
| 12300003 | Account not found. |
| 12300008 | Restricted Account. |
J
jidong 已提交
2319 2320

**示例:** 给ID为100的系统帐号设置头像
2321 2322

  ```js
2323
  import { BusinessError } from '@ohos.base';
2324
  let accountManager = account_osAccount.getAccountManager();
2325 2326
  let localId: number = 100;
  let photo: string = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAAPCAYAAAA/I0V3AAAAAXNSR0IArs4c6QAAAARnQU1BAA'+
J
jidong 已提交
2327 2328 2329
  'Cxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACwSURBVDhPvZLBDYMwDEV/ugsXRjAT0EHCOuFIBwkbdIRewi6unbiAyoGgSn1SFH85+Y'+
  'q/4ljARW62X+LHS8uIzjm4dXUYF+utzBikB52Jo5e5iEPKqpACk7R9NM2RvWm5tIkD2czLCUFNKLD6IjdMHFHDzws285MgGrT0xCtp3WOKHo'+
  '+7q0mP0DZW9pNmoEFUzrQjp5cCnaen2kSJXLFD8ghbXyZCMQf/8e8Ns1XVAG/XAgqKzVnJFAAAAABJRU5ErkJggg=='
2330
  try {
J
jidong 已提交
2331 2332
    accountManager.setOsAccountProfilePhoto(localId, photo).then(() => {
      console.log('setOsAccountProfilePhoto success');
2333
    }).catch((err: BusinessError) => {
C
chennian 已提交
2334
      console.log('setOsAccountProfilePhoto err: ' + JSON.stringify(err));
2335 2336
    });
  } catch (e) {
C
chennian 已提交
2337
    console.log('setOsAccountProfilePhoto exception: ' + JSON.stringify(e));
2338
  }
Z
zhangalong 已提交
2339 2340
  ```

C
cclicn 已提交
2341
### getOsAccountLocalIdForSerialNumber<sup>9+</sup>
Z
zhangalong 已提交
2342

C
cclicn 已提交
2343
getOsAccountLocalIdForSerialNumber(serialNumber: number, callback: AsyncCallback&lt;number&gt;): void
2344

J
jidong 已提交
2345
通过SN码查询与其关联的系统帐号的帐号ID。使用callback异步回调。
Z
zhangalong 已提交
2346

Z
zengyawen 已提交
2347
**系统能力:** SystemCapability.Account.OsAccount
Z
zhangalong 已提交
2348

Z
zengyawen 已提交
2349 2350
**参数:**

J
jidong 已提交
2351 2352 2353 2354
| 参数名       | 类型                        | 必填 | 说明                                                                           |
| ------------ | --------------------------- | ---- | ---------------------------------------------------------------------------- |
| serialNumber | number                      | 是   | 帐号SN码。                                                                    |
| callback     | AsyncCallback&lt;number&gt; | 是   | 回调函数。如果成功,err为null,data为与SN码关联的系统帐号的帐号ID;否则为错误对象。 |
Z
zengyawen 已提交
2355

J
jidong 已提交
2356
**错误码:**
J
jidong 已提交
2357

J
jidong 已提交
2358
| 错误码ID | 错误信息               |
J
jidong 已提交
2359
| -------- | ------------------- |
C
chennian 已提交
2360 2361 2362
| 12300001 | System service exception. |
| 12300002 | Invalid serialNumber. |
| 12300003 | The account indicated by serialNumber dose not exist. |
J
jidong 已提交
2363 2364

**示例:** 查询与SN码12345关联的系统帐号的ID
Z
zhangalong 已提交
2365

Z
zhangalong 已提交
2366
  ```js
2367
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
2368
  let accountManager = account_osAccount.getAccountManager();
2369
  let serialNumber: number = 12345;
J
jidong 已提交
2370
  try {
2371
    accountManager.getOsAccountLocalIdForSerialNumber(serialNumber, (err: BusinessError, localId: number)=>{
J
jidong 已提交
2372 2373 2374 2375
      console.log('ger localId err:' + JSON.stringify(err));
      console.log('get localId:' + localId + ' by serialNumber: ' + serialNumber);
    });
  } catch (e) {
C
chennian 已提交
2376
    console.log('ger localId exception: ' + JSON.stringify(e));
J
jidong 已提交
2377
  }
Z
zhangalong 已提交
2378 2379
  ```

C
cclicn 已提交
2380
### getOsAccountLocalIdForSerialNumber<sup>9+</sup>
2381

C
cclicn 已提交
2382
getOsAccountLocalIdForSerialNumber(serialNumber: number): Promise&lt;number&gt;
Z
zengyawen 已提交
2383

J
jidong 已提交
2384
通过SN码查询与其关联的系统帐号的帐号ID。使用Promise异步回调。
Z
zhangalong 已提交
2385

Z
zengyawen 已提交
2386
**系统能力:** SystemCapability.Account.OsAccount
Z
zhangalong 已提交
2387

Z
zengyawen 已提交
2388
**参数:**
Z
zhangalong 已提交
2389

J
jidong 已提交
2390 2391 2392
| 参数名       | 类型   | 必填 | 说明       |
| ------------ | ------ | ---- | ---------- |
| serialNumber | number | 是   | 帐号SN码。 |
Z
zhangalong 已提交
2393

Z
zengyawen 已提交
2394
**返回值:**
Z
zhangalong 已提交
2395

J
jidong 已提交
2396
| 类型                  | 说明                                         |
J
jidong 已提交
2397
| --------------------- | -------------------------------------------- |
J
jidong 已提交
2398
| Promise&lt;number&gt; | Promise对象,返回与SN码关联的系统帐号的帐号ID。 |
Z
zengyawen 已提交
2399

J
jidong 已提交
2400
**错误码:**
J
jidong 已提交
2401

J
jidong 已提交
2402
| 错误码ID | 错误信息               |
J
jidong 已提交
2403
| -------- | ------------------- |
C
chennian 已提交
2404 2405 2406
| 12300001 | System service exception. |
| 12300002 | Invalid serialNumber. |
| 12300003 | The account indicated by serialNumber dose not exist. |
J
jidong 已提交
2407 2408

**示例:** 查询与SN码12345关联的系统帐号的ID
Z
zhangalong 已提交
2409

Z
zhangalong 已提交
2410
  ```js
2411
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
2412
  let accountManager = account_osAccount.getAccountManager();
2413
  let serialNumber: number = 12345;
J
jidong 已提交
2414
  try {
2415
    accountManager.getOsAccountLocalIdForSerialNumber(serialNumber).then((localId: number) => {
C
cclicn 已提交
2416
      console.log('getOsAccountLocalIdForSerialNumber localId: ' + localId);
2417
    }).catch((err: BusinessError) => {
C
chennian 已提交
2418
      console.log('getOsAccountLocalIdForSerialNumber err: ' + JSON.stringify(err));
J
jidong 已提交
2419 2420
    });
  } catch (e) {
C
chennian 已提交
2421
    console.log('getOsAccountLocalIdForSerialNumber exception: ' + JSON.stringify(e));
J
jidong 已提交
2422
  }
Z
zhangalong 已提交
2423 2424
  ```

C
cclicn 已提交
2425
### getSerialNumberForOsAccountLocalId<sup>9+</sup>
Z
zhangalong 已提交
2426

C
cclicn 已提交
2427
getSerialNumberForOsAccountLocalId(localId: number, callback: AsyncCallback&lt;number&gt;): void
Z
zhangalong 已提交
2428

J
jidong 已提交
2429
通过系统帐号ID获取与该系统帐号关联的SN码。使用callback异步回调。
Z
zengyawen 已提交
2430 2431

**系统能力:** SystemCapability.Account.OsAccount
Z
zhangalong 已提交
2432

Z
zengyawen 已提交
2433
**参数:**
Z
zhangalong 已提交
2434

J
jidong 已提交
2435 2436 2437 2438
| 参数名   | 类型                        | 必填 | 说明                                                                         |
| -------- | --------------------------- | ---- | -------------------------------------------------------------------------- |
| localId  | number                      | 是   | 系统帐号ID。                                                                 |
| callback | AsyncCallback&lt;number&gt; | 是   | 回调函数。如果获取成功,err为null,data为与该系统帐号关联的SN码;否则为错误对象。 |
Z
zengyawen 已提交
2439

J
jidong 已提交
2440 2441 2442 2443
**错误码:**

| 错误码ID | 错误信息             |
| -------- | ------------------- |
C
chennian 已提交
2444 2445 2446
| 12300001 | System service exception. |
| 12300002 | Invalid localId.    |
| 12300003 | Account not found. |
J
jidong 已提交
2447 2448

**示例:** 获取ID为100的系统帐号关联的SN码
Z
zhangalong 已提交
2449

Z
zhangalong 已提交
2450
  ```js
2451
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
2452
  let accountManager = account_osAccount.getAccountManager();
2453
  let localId: number = 100;
2454
  try {
2455
    accountManager.getSerialNumberForOsAccountLocalId(localId, (err: BusinessError, serialNumber: number)=>{
J
jidong 已提交
2456 2457
      console.log('ger serialNumber err:' + JSON.stringify(err));
      console.log('get serialNumber:' + serialNumber + ' by localId: ' + localId);
2458 2459
    });
  } catch (e) {
C
chennian 已提交
2460
    console.log('ger serialNumber exception: ' + JSON.stringify(e));
2461
  }
Z
zhangalong 已提交
2462 2463
  ```

C
cclicn 已提交
2464
### getSerialNumberForOsAccountLocalId<sup>9+</sup>
Z
zhangalong 已提交
2465

C
cclicn 已提交
2466
getSerialNumberForOsAccountLocalId(localId: number): Promise&lt;number&gt;
Z
zhangalong 已提交
2467

J
jidong 已提交
2468
通过系统帐号ID获取与该系统帐号关联的SN码。使用Promise异步回调。
Z
zengyawen 已提交
2469 2470

**系统能力:** SystemCapability.Account.OsAccount
Z
zhangalong 已提交
2471

J
jidong 已提交
2472 2473 2474 2475 2476
**参数:**

| 参数名  | 类型   | 必填 | 说明          |
| ------- | ------ | ---- | ----------- |
| localId | number | 是   | 系统帐号ID。 |
L
lichenchen 已提交
2477

Z
zengyawen 已提交
2478
**返回值:**
Z
zhangalong 已提交
2479

J
jidong 已提交
2480 2481 2482
| 类型                  | 说明                                    |
| :-------------------- | :------------------------------------- |
| Promise&lt;number&gt; | Promise对象,返回与该系统帐号关联的SN码。 |
Z
zengyawen 已提交
2483

J
jidong 已提交
2484 2485 2486 2487
**错误码:**

| 错误码ID | 错误信息             |
| -------- | ------------------- |
C
chennian 已提交
2488 2489 2490
| 12300001 | System service exception. |
| 12300002 | Invalid localId.    |
| 12300003 | Account not found. |
J
jidong 已提交
2491 2492

**示例:** 获取ID为100的系统帐号关联的SN码
Z
zhangalong 已提交
2493

Z
zhangalong 已提交
2494
  ```js
2495
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
2496
  let accountManager = account_osAccount.getAccountManager();
2497
  let localId: number = 100;
2498
  try {
2499
    accountManager.getSerialNumberForOsAccountLocalId(localId).then((serialNumber: number) => {
C
cclicn 已提交
2500
      console.log('getSerialNumberForOsAccountLocalId serialNumber: ' + serialNumber);
2501
    }).catch((err: BusinessError) => {
C
chennian 已提交
2502
      console.log('getSerialNumberForOsAccountLocalId err: ' + JSON.stringify(err));
2503 2504
    });
  } catch (e) {
C
chennian 已提交
2505
    console.log('getSerialNumberForOsAccountLocalId exception: ' + JSON.stringify(e));
2506 2507 2508
  }
  ```

J
jidong 已提交
2509
### on
2510

J
jidong 已提交
2511 2512
on(type: 'activate' | 'activating', name: string, callback: Callback&lt;number&gt;): void

2513
订阅系统帐号的激活完成与激活中的事件。使用callback异步回调。
2514

J
jidong 已提交
2515 2516 2517
**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION
2518 2519 2520 2521 2522

**系统能力:** SystemCapability.Account.OsAccount

**参数:**

J
jidong 已提交
2523 2524 2525 2526
| 参数名   | 类型                       | 必填 | 说明                                                         |
| -------- | -------------------------- | ---- | ------------------------------------------------------------ |
| type     | 'activate' \| 'activating' | 是   | 订阅类型,activate表示订阅的是帐号已激活完成的事件,activating表示订阅的是帐号正在激活的事件。 |
| name     | string                     | 是   | 订阅名称,可自定义,要求非空且长度不超过1024字节。           |
2527
| callback | Callback&lt;number&gt;     | 是   | 订阅系统帐号激活完成与激活中的事件回调,表示激活完成后或正在激活中的系统帐号ID。    |
2528

J
jidong 已提交
2529 2530 2531 2532 2533 2534 2535
**错误码:**

| 错误码ID | 错误信息       |
| -------- | ------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid type or name. |

2536 2537 2538 2539
**示例:**

  ```js
  let accountManager = account_osAccount.getAccountManager();
2540
  function onCallback(receiveLocalId: number){
J
jidong 已提交
2541 2542
    console.log('receive localId:' + receiveLocalId);
  }
2543
  try {
J
jidong 已提交
2544
    accountManager.on('activating', 'osAccountOnOffNameA', onCallback);
2545
  } catch (e) {
C
chennian 已提交
2546
    console.log('receive localId exception: ' + JSON.stringify(e));
2547 2548 2549
  }
  ```

J
jidong 已提交
2550
### off
2551

J
jidong 已提交
2552 2553
off(type: 'activate' | 'activating', name: string, callback?: Callback&lt;number&gt;): void

2554
取消订阅系统帐号的激活完成与激活中的事件。使用callback异步回调。
2555

J
jidong 已提交
2556 2557 2558
**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION
2559 2560 2561

**系统能力:** SystemCapability.Account.OsAccount

J
jidong 已提交
2562
**参数:**
2563

J
jidong 已提交
2564 2565 2566
| 参数名   | 类型                       | 必填 | 说明                                                         |
| -------- | -------------------------- | ---- | ------------------------------------------------------------ |
| type     | 'activate' \| 'activating' | 是   | 取消订阅类型,activate表示取消订阅帐号已激活完成的事件,activating取消订阅帐号正在激活的事件。 |
C
cclicn 已提交
2567
| name     | string                     | 是   | 订阅名称,可自定义,要求非空且长度不超过1024字节,需要与订阅接口传入的值保持一致。 |
2568
| callback | Callback&lt;number&gt;     | 否   | 取消订阅系统帐号激活完成与激活中的事件回调,默认为空,表示取消该类型事件的所有回调。                      |
2569

J
jidong 已提交
2570 2571 2572 2573 2574 2575 2576
**错误码:**

| 错误码ID | 错误信息       |
| -------- | ------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid type or name. |

2577 2578 2579 2580
**示例:**

  ```js
  let accountManager = account_osAccount.getAccountManager();
J
jidong 已提交
2581 2582 2583
  function offCallback(){
    console.log('off enter')
  }
2584
  try {
J
jidong 已提交
2585
    accountManager.off('activating', 'osAccountOnOffNameA', offCallback);
2586
  } catch (e) {
C
chennian 已提交
2587
    console.log('off exception: ' + JSON.stringify(e));
2588
  }
Z
zhangalong 已提交
2589 2590
  ```

C
cclicn 已提交
2591
### getBundleIdForUid<sup>9+</sup>
Z
zhangalong 已提交
2592

C
cclicn 已提交
2593
getBundleIdForUid(uid: number, callback: AsyncCallback&lt;number&gt;): void;
Z
zhangalong 已提交
2594

J
jidong 已提交
2595
通过uid查询对应的bundleId,使用callback异步回调。
Z
zhangalong 已提交
2596

J
jidong 已提交
2597
**系统接口:** 此接口为系统接口。
2598

Z
zengyawen 已提交
2599 2600 2601
**系统能力:** SystemCapability.Account.OsAccount

**参数:**
Z
zhangalong 已提交
2602

J
jidong 已提交
2603 2604 2605 2606
| 参数名   | 类型                       | 必填 | 说明                                                                        |
| -------- | --------------------------- | ---- | ------------------------------------------------------------------------ |
| uid      | number                      | 是   | 进程uid。                                                                 |
| callback | AsyncCallback&lt;number&gt; | 是   | 回调函数。如果查询成功,err为null,data为与uid对应的bundleId;否则为错误对象。 |
Z
zhangalong 已提交
2607

J
jidong 已提交
2608 2609 2610 2611
**错误码:**

| 错误码ID | 错误信息       |
| -------- | ------------- |
C
chennian 已提交
2612 2613
| 12300001 | System service exception. |
| 12300002 | Invalid uid. |
J
jidong 已提交
2614

2615
**示例:**
Z
zhangalong 已提交
2616

Z
zhangalong 已提交
2617
  ```js
2618
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
2619
  let accountManager = account_osAccount.getAccountManager();
2620
  let testUid: number = 1000000;
J
jidong 已提交
2621
  try {
2622
    accountManager.getBundleIdForUid(testUid, (err: BusinessError, bundleId: number) => {
C
cclicn 已提交
2623 2624
      console.info('getBundleIdForUid errInfo:' + JSON.stringify(err));
      console.info('getBundleIdForUid bundleId:' + JSON.stringify(bundleId));
J
jidong 已提交
2625 2626
    });
  } catch (e) {
C
chennian 已提交
2627
    console.info('getBundleIdForUid exception: ' + JSON.stringify(e));
J
jidong 已提交
2628
  }
Z
zhangalong 已提交
2629
  ```
C
cclicn 已提交
2630
### getBundleIdForUid<sup>9+</sup>
Z
zhangalong 已提交
2631

C
cclicn 已提交
2632
getBundleIdForUid(uid: number): Promise&lt;number&gt;;
Z
zhangalong 已提交
2633

A
Annie_wang 已提交
2634
通过uid查询对应的bundleId,使用Promise异步回调。
2635

J
jidong 已提交
2636
**系统接口:** 此接口为系统接口。
Z
zhangalong 已提交
2637

Z
zengyawen 已提交
2638
**系统能力:** SystemCapability.Account.OsAccount
Z
zhangalong 已提交
2639

J
jidong 已提交
2640 2641 2642 2643 2644 2645
**参数:**

| 参数名  | 类型   | 必填 | 说明         |
| ------- | ------ | ---- | ------------ |
| uid     | number | 是   |  进程uid。 |

Z
zengyawen 已提交
2646
**返回值:**
Z
zhangalong 已提交
2647

J
jidong 已提交
2648 2649 2650
| 类型                  | 说明                                  |
| --------------------- | ------------------------------------ |
| Promise&lt;number&gt; | Promise对象,返回与uid对应的bundleId。 |
Z
zengyawen 已提交
2651

J
jidong 已提交
2652 2653 2654 2655
**错误码:**

| 错误码ID | 错误信息       |
| -------- | ------------- |
C
chennian 已提交
2656 2657
| 12300001 | System service exception. |
| 12300002 | Invalid uid. |
J
jidong 已提交
2658

2659
**示例:**
Z
zhangalong 已提交
2660

Z
zhangalong 已提交
2661
  ```js
2662
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
2663
  let accountManager = account_osAccount.getAccountManager();
2664
  let testUid: number = 1000000;
J
jidong 已提交
2665
  try {
2666
    accountManager.getBundleIdForUid(testUid).then((result: number) => {
C
cclicn 已提交
2667
      console.info('getBundleIdForUid bundleId:' + JSON.stringify(result));
2668
    }).catch((err: BusinessError) => {
C
cclicn 已提交
2669
      console.info('getBundleIdForUid errInfo:' + JSON.stringify(err));
J
jidong 已提交
2670 2671
    });
  } catch (e) {
C
chennian 已提交
2672
    console.info('getBundleIdForUid exception: ' + JSON.stringify(e));
J
jidong 已提交
2673 2674
  }
  ```
Z
zhangalong 已提交
2675

J
jidong 已提交
2676 2677 2678
### isMainOsAccount<sup>9+</sup>

isMainOsAccount(callback: AsyncCallback&lt;boolean&gt;): void;
Z
zhangalong 已提交
2679

J
jidong 已提交
2680
查询当前进程是否处于主用户,使用callback异步回调。
Z
zhangalong 已提交
2681

J
jidong 已提交
2682
**系统接口:** 此接口为系统接口。
Z
zengyawen 已提交
2683 2684

**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
Z
zhangalong 已提交
2685

Z
zengyawen 已提交
2686
**系统能力:** SystemCapability.Account.OsAccount
Z
zhangalong 已提交
2687

Z
zengyawen 已提交
2688 2689
**参数:**

J
jidong 已提交
2690 2691 2692
| 参数名   | 类型                          | 必填 | 说明                                                               |
| -------- | ---------------------------- | ---- | ----------------------------------------------------------------- |
| callback | AsyncCallback&lt;boolean&gt; | 是   | 回调函数,返回true表示当前帐号为主帐号,返回false表示当前帐号非主帐号。 |
Z
zengyawen 已提交
2693

J
jidong 已提交
2694 2695 2696 2697 2698 2699
**错误码:**

| 错误码ID | 错误信息       |
| -------- | ------------- |
| 12300001 | System service exception. |

2700
**示例:**
Z
zhangalong 已提交
2701

Z
zhangalong 已提交
2702
  ```js
2703
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
2704
  let accountManager = account_osAccount.getAccountManager();
2705
  try {
2706
    accountManager.isMainOsAccount((err: BusinessError,result: boolean)=>{
J
jidong 已提交
2707 2708
      console.info('isMainOsAccount errInfo:' + JSON.stringify(err));
      console.info('isMainOsAccount result:' + JSON.stringify(result));
2709 2710
    });
  } catch (e) {
C
chennian 已提交
2711
    console.info('isMainOsAccount exception: ' + JSON.stringify(e));
2712
  }
Z
zhangalong 已提交
2713
  ```
J
jidong 已提交
2714
### isMainOsAccount<sup>9+</sup>
Z
zhangalong 已提交
2715

J
jidong 已提交
2716
isMainOsAccount(): Promise&lt;boolean&gt;;
Z
zhangalong 已提交
2717

J
jidong 已提交
2718
查询当前进程是否处于主用户,使用Promise异步回调。
Z
zhangalong 已提交
2719

J
jidong 已提交
2720
**系统接口:** 此接口为系统接口。
Z
zengyawen 已提交
2721 2722 2723 2724

**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS

**系统能力:** SystemCapability.Account.OsAccount
Z
zhangalong 已提交
2725

Z
zengyawen 已提交
2726
**返回值:**
Z
zhangalong 已提交
2727

J
jidong 已提交
2728 2729 2730
| 类型                   | 说明                                                                  |
| ---------------------- | --------------------------------------------------------------------- |
| Promise&lt;boolean&gt; | Promise对象,返回true表示当前帐号为主帐号,返回false表示当前帐号非主帐号。 |
Z
zengyawen 已提交
2731

J
jidong 已提交
2732 2733 2734 2735 2736 2737
**错误码:**

| 错误码ID | 错误信息       |
| -------- | ------------- |
| 12300001 | System service exception. |

2738
**示例:**
Z
zhangalong 已提交
2739

Z
zhangalong 已提交
2740
  ```js
2741
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
2742
  let accountManager = account_osAccount.getAccountManager();
2743
  try {
2744
    accountManager.isMainOsAccount().then((result: boolean) => {
J
jidong 已提交
2745
      console.info('isMainOsAccount result:' + JSON.stringify(result));
2746
    }).catch((err: BusinessError) => {
J
jidong 已提交
2747
      console.info('isMainOsAccount errInfo:' + JSON.stringify(err));
2748 2749
    });
  } catch (e) {
C
chennian 已提交
2750
    console.info('isMainOsAccount exception: ' + JSON.stringify(e));
2751
  }
Z
zhangalong 已提交
2752
  ```
C
cclicn 已提交
2753
### getOsAccountConstraintSourceTypes<sup>9+</sup>
Z
zhangalong 已提交
2754

C
cclicn 已提交
2755
getOsAccountConstraintSourceTypes(localId: number, constraint: string, callback: AsyncCallback&lt;Array&lt;ConstraintSourceTypeInfo&gt;&gt;): void;
Z
zhangalong 已提交
2756

J
jidong 已提交
2757
查询指定系统帐号的指定约束来源信息,使用callback异步回调。
Z
zhangalong 已提交
2758

J
jidong 已提交
2759
**系统接口:** 此接口为系统接口。
Z
zengyawen 已提交
2760 2761 2762 2763

**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS

**系统能力:** SystemCapability.Account.OsAccount
Z
zhangalong 已提交
2764

Z
zengyawen 已提交
2765
**参数:**
Z
zhangalong 已提交
2766

J
jidong 已提交
2767 2768 2769 2770 2771
| 参数名   | 类型                       | 必填 | 说明                                                         |
| -------- | -------------------------- | ---- | ------------------------------------------------------------ |
| localId     | number | 是   |  要查询的系统帐号ID |
| constraint     | string | 是   |  要查询的[约束](#系统帐号约束列表)名称 |
| callback | AsyncCallback&lt;Array&lt;[ConstraintSourceTypeInfo](#constraintsourcetypeinfo)&gt;&gt;     | 是   | 回调函数。如果成功,err为null,data为指定系统帐号的指定[约束](#系统帐号约束列表)来源信息;否则为错误对象。                      |
Z
zengyawen 已提交
2772

J
jidong 已提交
2773 2774 2775 2776
**错误码:**

| 错误码ID | 错误信息       |
| -------- | ------------- |
C
chennian 已提交
2777 2778 2779
| 12300001 | System service exception. |
| 12300002 | Invalid name or constraint. |
| 12300003 | Account not found. |
J
jidong 已提交
2780

2781
**示例:**
Z
zhangalong 已提交
2782

Z
zhangalong 已提交
2783
  ```js
2784
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
2785
  let accountManager = account_osAccount.getAccountManager();
2786
  try {
2787 2788
    accountManager.getOsAccountConstraintSourceTypes(100, 'constraint.wifi',
      (err: BusinessError,sourceTypeInfos: account_osAccount.ConstraintSourceTypeInfo[])=>{
C
cclicn 已提交
2789 2790
      console.info('getOsAccountConstraintSourceTypes errInfo:' + JSON.stringify(err));
      console.info('getOsAccountConstraintSourceTypes sourceTypeInfos:' + JSON.stringify(sourceTypeInfos));
2791 2792
    });
  } catch (e) {
C
chennian 已提交
2793
    console.info('getOsAccountConstraintSourceTypes exception: ' + JSON.stringify(e));
2794
  }
Z
zhangalong 已提交
2795 2796
  ```

C
cclicn 已提交
2797
### getOsAccountConstraintSourceTypes<sup>9+</sup>
Z
zhangalong 已提交
2798

C
cclicn 已提交
2799
getOsAccountConstraintSourceTypes(localId: number, constraint: string): Promise&lt;Array&lt;ConstraintSourceTypeInfo&gt;&gt;;
Z
zhangalong 已提交
2800

J
jidong 已提交
2801
查询指定系统帐号的指定约束来源信息,使用Promise异步回调。
Z
zhangalong 已提交
2802

J
jidong 已提交
2803
**系统接口:** 此接口为系统接口。
Z
zengyawen 已提交
2804 2805 2806 2807 2808 2809

**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS

**系统能力:** SystemCapability.Account.OsAccount

**参数:**
Z
zhangalong 已提交
2810

J
jidong 已提交
2811 2812 2813 2814
| 参数名  | 类型   | 必填 | 说明         |
| ------- | ------ | ---- | ------------ |
| localId     | number | 是   |  要查询的系统帐号ID |
| constraint     | string | 是   |  要查询的[约束](#系统帐号约束列表)名称 |
Z
zhangalong 已提交
2815

Z
zengyawen 已提交
2816
**返回值:**
Z
zhangalong 已提交
2817

J
jidong 已提交
2818
| 类型                  | 说明                                                         |
J
jidong 已提交
2819
| --------------------- | ------------------------------------------------------------ |
J
jidong 已提交
2820
| Promise&lt;Array&lt;[ConstraintSourceTypeInfo](#constraintsourcetypeinfo)&gt;&gt; | Promise对象,返回指定系统帐号的指定[约束](#系统帐号约束列表)来源信息。 |
Z
zhangalong 已提交
2821

J
jidong 已提交
2822 2823 2824 2825
**错误码:**

| 错误码ID | 错误信息       |
| -------- | ------------- |
C
chennian 已提交
2826 2827 2828
| 12300001 | System service exception. |
| 12300002 | Invalid name or constraint. |
| 12300003 | Account not found. |
J
jidong 已提交
2829

2830
**示例:**
Z
zhangalong 已提交
2831

Z
zhangalong 已提交
2832
  ```js
2833
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
2834
  let accountManager = account_osAccount.getAccountManager();
2835
  try {
2836 2837
    accountManager.getOsAccountConstraintSourceTypes(100, 'constraint.wifi').then(
      (result: account_osAccount.ConstraintSourceTypeInfo[]) => {
C
cclicn 已提交
2838
      console.info('getOsAccountConstraintSourceTypes sourceTypeInfos:' + JSON.stringify(result));
2839
    }).catch((err: BusinessError) => {
C
cclicn 已提交
2840
      console.info('getOsAccountConstraintSourceTypes errInfo:' + JSON.stringify(err));
2841 2842
    });
  } catch (e) {
C
chennian 已提交
2843
    console.info('getOsAccountConstraintSourceTypes exception: ' + JSON.stringify(e));
2844 2845 2846
  }
  ```

J
jidong 已提交
2847
### isMultiOsAccountEnable<sup>(deprecated)</sup>
2848

J
jidong 已提交
2849
isMultiOsAccountEnable(callback: AsyncCallback&lt;boolean&gt;): void
2850

J
jidong 已提交
2851
判断是否支持多系统帐号。使用callback异步回调。
2852

A
Annie_wang 已提交
2853
> **说明:** 
J
jidong 已提交
2854
>
A
Annie_wang 已提交
2855
> 从 API version 7开始支持,从API version 9开始废弃。建议使用[checkMultiOsAccountEnabled](#checkmultiosaccountenabled9)。
2856 2857 2858 2859 2860

**系统能力:** SystemCapability.Account.OsAccount

**参数:**

J
jidong 已提交
2861 2862 2863
| 参数名   | 类型                         | 必填 | 说明                                                     |
| -------- | ---------------------------- | ---- | ------------------------------------------------------ |
| callback | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。返回true表示支持多系统帐号;返回false表示不支持。 |
2864 2865 2866 2867

**示例:**

  ```js
2868
  import { BusinessError } from '@ohos.base';
2869
  let accountManager = account_osAccount.getAccountManager();
2870
  accountManager.isMultiOsAccountEnable((err: BusinessError, isEnabled: boolean) => {
J
jidong 已提交
2871
    if (err) {
C
chennian 已提交
2872
      console.log('isMultiOsAccountEnable failed, error: ' + JSON.stringify(err));
J
jidong 已提交
2873
    } else {
C
chennian 已提交
2874
    console.log('isMultiOsAccountEnable successfully, isEnabled: ' + isEnabled);
J
jidong 已提交
2875 2876
    }
  });
2877 2878
  ```

J
jidong 已提交
2879
### isMultiOsAccountEnable<sup>(deprecated)</sup>
2880

J
jidong 已提交
2881
isMultiOsAccountEnable(): Promise&lt;boolean&gt;
2882

J
jidong 已提交
2883
判断是否支持多系统帐号。使用Promise异步回调。
2884

A
Annie_wang 已提交
2885
> **说明:** 
J
jidong 已提交
2886
>
A
Annie_wang 已提交
2887
> 从 API version 7开始支持,从API version 9开始废弃。建议使用[checkMultiOsAccountEnabled](#checkmultiosaccountenabled9-1)。
2888 2889 2890 2891 2892

**系统能力:** SystemCapability.Account.OsAccount

**返回值:**

J
jidong 已提交
2893 2894 2895
| 类型                   | 说明                                                       |
| :--------------------- | :--------------------------------------------------------- |
| Promise&lt;boolean&gt; | Promise对象。返回true表示支持多系统帐号;返回false表示不支持。 |
2896 2897 2898 2899

**示例:**

  ```js
2900
  import { BusinessError } from '@ohos.base';
2901
  let accountManager = account_osAccount.getAccountManager();
2902
  accountManager.isMultiOsAccountEnable().then((isEnabled: boolean) => {
J
jidong 已提交
2903
    console.log('isMultiOsAccountEnable successfully, isEnabled: ' + isEnabled);
2904
  }).catch((err: BusinessError) => {
C
chennian 已提交
2905
    console.log('isMultiOsAccountEnable failed, error: ' + JSON.stringify(err));
J
jidong 已提交
2906
  });
Z
zhangalong 已提交
2907 2908 2909
  ```


J
jidong 已提交
2910
### isOsAccountActived<sup>(deprecated)</sup>
Z
zhangalong 已提交
2911

J
jidong 已提交
2912
isOsAccountActived(localId: number, callback: AsyncCallback&lt;boolean&gt;): void
Z
zhangalong 已提交
2913

J
jidong 已提交
2914 2915
判断指定系统帐号是否处于激活状态。使用callback异步回调。

A
Annie_wang 已提交
2916
> **说明:** 
2917
>
A
Annie_wang 已提交
2918
> 从 API version 7开始支持从API version 9开始废弃, 建议使用[checkOsAccountActivated](#checkosaccountactivated9)。
2919

J
jidong 已提交
2920
**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
Z
zhangalong 已提交
2921

Z
zengyawen 已提交
2922
**系统能力:** SystemCapability.Account.OsAccount
Z
zhangalong 已提交
2923

Z
zengyawen 已提交
2924 2925
**参数:**

J
jidong 已提交
2926 2927 2928 2929
| 参数名   | 类型                         | 必填 | 说明                                                     |
| -------- | ---------------------------- | ---- | ------------------------------------------------------ |
| localId  | number                       | 是   | 系统帐号ID。                                            |
| callback | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。返回true表示帐号已激活;返回false表示帐号未激活。 |
Z
zengyawen 已提交
2930

J
jidong 已提交
2931
**示例:** 判断ID为100的系统帐号是否处于激活状态
Z
zhangalong 已提交
2932

Z
zhangalong 已提交
2933
  ```js
2934
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
2935
  let accountManager = account_osAccount.getAccountManager();
2936 2937
  let localId: number = 100;
  accountManager.isOsAccountActived(localId, (err: BusinessError, isActived: boolean) => {
J
jidong 已提交
2938 2939 2940 2941 2942
    if (err) {
      console.log('isOsAccountActived failed, err:' + JSON.stringify(err));
    } else {
      console.log('isOsAccountActived successfully, isActived:' + isActived);
    }
Z
zhangalong 已提交
2943 2944 2945
  });
  ```

J
jidong 已提交
2946
### isOsAccountActived<sup>(deprecated)</sup>
Z
zhangalong 已提交
2947

J
jidong 已提交
2948
isOsAccountActived(localId: number): Promise&lt;boolean&gt;
Z
zhangalong 已提交
2949

J
jidong 已提交
2950
判断指定系统帐号是否处于激活状态。使用Promise异步回调。
Z
zhangalong 已提交
2951

A
Annie_wang 已提交
2952
> **说明:** 
2953
>
A
Annie_wang 已提交
2954
> 从 API version 7开始支持从API version 9开始废弃, 建议使用[checkOsAccountActivated](#checkosaccountactivated9-1)。
2955

J
jidong 已提交
2956
**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
Z
zengyawen 已提交
2957 2958 2959

**系统能力:** SystemCapability.Account.OsAccount

J
jidong 已提交
2960 2961 2962 2963 2964 2965
**参数:**

| 参数名  | 类型   | 必填 | 说明                               |
| ------- | ------ | ---- | --------------------------------- |
| localId | number | 是   | 系统帐号ID。 |

Z
zengyawen 已提交
2966
**返回值:**
Z
zhangalong 已提交
2967

J
jidong 已提交
2968 2969 2970
| 类型                   | 说明                                                        |
| --------------------- | ----------------------------------------------------------- |
| Promise&lt;boolean&gt; | Promise对象。返回true表示帐号已激活;返回false表示帐号未激活。 |
Z
zhangalong 已提交
2971

J
jidong 已提交
2972
**示例:** 判断ID为100的系统帐号是否处于激活状态
Z
zhangalong 已提交
2973

Z
zhangalong 已提交
2974
  ```js
2975
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
2976
  let accountManager = account_osAccount.getAccountManager();
2977 2978
  let localId: number = 100;
  accountManager.isOsAccountActived(localId).then((isActived: boolean) => {
J
jidong 已提交
2979
    console.log('isOsAccountActived successfully, isActived: ' + isActived);
2980
  }).catch((err: BusinessError) => {
C
chennian 已提交
2981
    console.log('isOsAccountActived failed, error: ' + JSON.stringify(err));
Z
zhangalong 已提交
2982 2983 2984
  });
  ```

J
jidong 已提交
2985
### isOsAccountConstraintEnable<sup>(deprecated)</sup>
Z
zhangalong 已提交
2986

J
jidong 已提交
2987
isOsAccountConstraintEnable(localId: number, constraint: string, callback: AsyncCallback&lt;boolean&gt;): void
Z
zhangalong 已提交
2988

J
jidong 已提交
2989
判断指定系统帐号是否具有指定约束。使用callback异步回调。
Z
zhangalong 已提交
2990

A
Annie_wang 已提交
2991
> **说明:** 
J
jidong 已提交
2992
>
C
cclicn 已提交
2993
> 从 API version 7开始支持,从API version 9开始废弃。建议使用[checkOsAccountConstraintEnabled](#checkosaccountconstraintenabled9)。
Z
zhangalong 已提交
2994

J
jidong 已提交
2995
**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
Z
zhangalong 已提交
2996

Z
zengyawen 已提交
2997 2998 2999 3000
**系统能力:** SystemCapability.Account.OsAccount

**参数:**

J
jidong 已提交
3001 3002 3003 3004 3005
| 参数名     | 类型                         | 必填 | 说明                                                                |
| ---------- | ---------------------------- | ---- | ----------------------------------------------------------------- |
| localId    | number                       | 是   | 系统帐号ID。                                 |
| constraint | string                       | 是   | 指定的[约束](#系统帐号约束列表)名称。                                |
| callback   | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。返回true表示已使能指定的约束;返回false表示未使能指定的约束。 |
Z
zengyawen 已提交
3006

J
jidong 已提交
3007
**示例:** 判断ID为100的系统帐号是否有禁止使用Wi-Fi的约束
Z
zhangalong 已提交
3008

Z
zhangalong 已提交
3009
  ```js
3010
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
3011
  let accountManager = account_osAccount.getAccountManager();
3012 3013 3014
  let localId: number = 100;
  let constraint: string = 'constraint.wifi';
  accountManager.isOsAccountConstraintEnable(localId, constraint, (err: BusinessError, isEnabled: boolean) => {
J
jidong 已提交
3015
    if (err) {
C
chennian 已提交
3016
      console.log('isOsAccountConstraintEnable failed, error: ' + JSON.stringify(err));
J
jidong 已提交
3017
    } else {
C
chennian 已提交
3018
      console.log('isOsAccountConstraintEnable successfully, isEnabled: ' + isEnabled);
J
jidong 已提交
3019 3020
    }
  });
Z
zhangalong 已提交
3021 3022
  ```

J
jidong 已提交
3023
### isOsAccountConstraintEnable<sup>(deprecated)</sup>
Z
zhangalong 已提交
3024

J
jidong 已提交
3025
isOsAccountConstraintEnable(localId: number, constraint: string): Promise&lt;boolean&gt;
Z
zhangalong 已提交
3026

J
jidong 已提交
3027
判断指定系统帐号是否具有指定约束。使用Promise异步回调。
Z
zhangalong 已提交
3028

A
Annie_wang 已提交
3029
> **说明:** 
J
jidong 已提交
3030
>
C
cclicn 已提交
3031
> 从 API version 7开始支持,从API version 9开始废弃。建议使用[checkOsAccountConstraintEnabled](#checkosaccountconstraintenabled9-1)。
Z
zengyawen 已提交
3032

J
jidong 已提交
3033
**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
Z
zhangalong 已提交
3034

Z
zengyawen 已提交
3035
**系统能力:** SystemCapability.Account.OsAccount
Z
zhangalong 已提交
3036

Z
zengyawen 已提交
3037
**参数:**
Z
zhangalong 已提交
3038

J
jidong 已提交
3039 3040 3041 3042
| 参数名     | 类型   | 必填 | 说明                                 |
| ---------- | ------ | ---- | ---------------------------------- |
| localId    | number | 是   | 系统帐号ID。  |
| constraint | string | 是   | 指定的[约束](#系统帐号约束列表)名称。 |
Z
zhangalong 已提交
3043

Z
zengyawen 已提交
3044 3045
**返回值:**

J
jidong 已提交
3046 3047 3048
| 类型                   | 说明                                                                   |
| ---------------------- | --------------------------------------------------------------------- |
| Promise&lt;boolean&gt; | Promise对象。返回true表示已使能指定的约束;返回false表示未使能指定的约束。 |
Z
zengyawen 已提交
3049

J
jidong 已提交
3050
**示例:** 判断ID为100的系统帐号是否有禁止使用Wi-Fi的约束
3051 3052

  ```js
3053
  import { BusinessError } from '@ohos.base';
3054
  let accountManager = account_osAccount.getAccountManager();
3055 3056 3057
  let localId: number = 100;
  let constraint: string = 'constraint.wifi';
  accountManager.isOsAccountConstraintEnable(localId, constraint).then((isEnabled: boolean) => {
C
chennian 已提交
3058
    console.log('isOsAccountConstraintEnable successfully, isEnabled: ' + isEnabled);
3059
  }).catch((err: BusinessError) => {
C
chennian 已提交
3060
    console.log('isOsAccountConstraintEnable err: ' + JSON.stringify(err));
J
jidong 已提交
3061
  });
3062 3063
  ```

J
jidong 已提交
3064
### isTestOsAccount<sup>(deprecated)</sup>
3065

J
jidong 已提交
3066
isTestOsAccount(callback: AsyncCallback&lt;boolean&gt;): void
3067

J
jidong 已提交
3068 3069
检查当前系统帐号是否为测试帐号。使用callback异步回调。

A
Annie_wang 已提交
3070
> **说明:** 
J
jidong 已提交
3071
>
A
Annie_wang 已提交
3072
> 从 API version 7开始支持,从API version 9开始废弃。建议使用[checkOsAccountTestable](#checkosaccounttestable9)。
3073 3074 3075 3076 3077

**系统能力:** SystemCapability.Account.OsAccount

**参数:**

J
jidong 已提交
3078 3079 3080
| 参数名   | 类型                         | 必填 | 说明                                                                   |
| -------- | ---------------------------- | ---- | --------------------------------------------------------------------- |
| callback | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。返回true表示当前帐号为测试帐号;返回false表示当前帐号非测试帐号。 |
3081 3082 3083 3084

**示例:**

  ```js
3085
  import { BusinessError } from '@ohos.base';
3086
  let accountManager = account_osAccount.getAccountManager();
3087
  accountManager.isTestOsAccount((err: BusinessError, isTestable: boolean) => {
J
jidong 已提交
3088
    if (err) {
C
chennian 已提交
3089
      console.log('isTestOsAccount failed, error: ' + JSON.stringify(err));
J
jidong 已提交
3090
    } else {
C
chennian 已提交
3091
      console.log('isTestOsAccount successfully, isTestable: ' + isTestable);
J
jidong 已提交
3092 3093
    }
  });
3094 3095
  ```

J
jidong 已提交
3096
### isTestOsAccount<sup>(deprecated)</sup>
3097

J
jidong 已提交
3098 3099 3100
isTestOsAccount(): Promise&lt;boolean&gt;

检查当前系统帐号是否为测试帐号。使用Promise异步回调。
3101

A
Annie_wang 已提交
3102
> **说明:** 
J
jidong 已提交
3103
>
A
Annie_wang 已提交
3104
> 从 API version 7开始支持,从API version 9开始废弃。建议使用[checkOsAccountTestable](#checkosaccounttestable9-1)。
3105 3106 3107 3108 3109

**系统能力:** SystemCapability.Account.OsAccount

**返回值:**

J
jidong 已提交
3110 3111 3112
| 类型                   | 说明                                                                      |
| ---------------------- | ------------------------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise对象。返回true表示当前帐号为测试帐号;返回false表示当前帐号非测试帐号。 |
3113 3114 3115 3116

**示例:**

  ```js
3117
  import { BusinessError } from '@ohos.base';
3118
  let accountManager = account_osAccount.getAccountManager();
3119
    accountManager.isTestOsAccount().then((isTestable: boolean) => {
C
chennian 已提交
3120
      console.log('isTestOsAccount successfully, isTestable: ' + isTestable);
3121
    }).catch((err: BusinessError) => {
C
chennian 已提交
3122
      console.log('isTestOsAccount failed, error: ' + JSON.stringify(err));
J
jidong 已提交
3123
  });
3124 3125
  ```

J
jidong 已提交
3126
### isOsAccountVerified<sup>(deprecated)</sup>
3127

J
jidong 已提交
3128
isOsAccountVerified(callback: AsyncCallback&lt;boolean&gt;): void
3129

J
jidong 已提交
3130
检查当前系统帐号是否已验证。使用callback异步回调。
3131

A
Annie_wang 已提交
3132
> **说明:** 
3133
>
A
Annie_wang 已提交
3134
> 从 API version 7开始支持,从API version 9开始废弃。建议使用[checkOsAccountVerified](#checkosaccountverified9)。
3135

J
jidong 已提交
3136 3137
**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS

3138 3139 3140 3141
**系统能力:** SystemCapability.Account.OsAccount

**参数:**

J
jidong 已提交
3142 3143 3144
| 参数名   | 类型                         | 必填 | 说明                                                            |
| -------- | ---------------------------- | ---- | ------------------------------------------------------------- |
| callback | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。返回true表示指定帐号已验证;返回false表示指定帐号未验证。 |
3145 3146 3147 3148

**示例:**

  ```js
3149
  import { BusinessError } from '@ohos.base';
3150
  let accountManager = account_osAccount.getAccountManager();
3151
  accountManager.isOsAccountVerified((err: BusinessError, isVerified: boolean) => {
J
jidong 已提交
3152
    if (err) {
C
chennian 已提交
3153
      console.log('isOsAccountVerified failed, error: ' + JSON.stringify(err));
J
jidong 已提交
3154
    } else {
C
chennian 已提交
3155
      console.log('isOsAccountVerified successfully, isVerified: ' + isVerified);
J
jidong 已提交
3156
    }
3157 3158 3159
  });
  ```

J
jidong 已提交
3160
### isOsAccountVerified<sup>(deprecated)</sup>
3161

J
jidong 已提交
3162
isOsAccountVerified(localId: number, callback: AsyncCallback&lt;boolean&gt;): void
3163

J
jidong 已提交
3164
检查指定系统帐号是否已验证。使用callback异步回调。
3165

A
Annie_wang 已提交
3166
> **说明:** 
3167
>
A
Annie_wang 已提交
3168
> 从 API version 7开始支持,从API version 9开始废弃。建议使用[checkOsAccountVerified](#checkosaccountverified9-1)。
3169

J
jidong 已提交
3170 3171
**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS

3172 3173
**系统能力:** SystemCapability.Account.OsAccount

J
jidong 已提交
3174
**参数:**
3175

J
jidong 已提交
3176 3177
| 参数名   | 类型                         | 必填 | 说明                                                            |
| -------- | ---------------------------- | ---- | ------------------------------------------------------------- |
3178
| localId  | number                       | 是   | 系统帐号ID。                             |
J
jidong 已提交
3179
| callback | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。返回true表示指定帐号已验证;返回false表示指定帐号未验证。 |
3180 3181

**示例:**
Z
zhangalong 已提交
3182

Z
zhangalong 已提交
3183
  ```js
3184
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
3185
  let accountManager = account_osAccount.getAccountManager();
3186 3187
  let localId: number = 100;
  accountManager.isOsAccountVerified(localId, (err: BusinessError, isVerified: boolean) => {
J
jidong 已提交
3188
    if (err) {
C
chennian 已提交
3189
      console.log('isOsAccountVerified failed, error: ' + JSON.stringify(err));
J
jidong 已提交
3190
    } else {
C
chennian 已提交
3191
      console.log('isOsAccountVerified successfully, isVerified: ' + isVerified);
J
jidong 已提交
3192
    }
Z
zhangalong 已提交
3193 3194 3195
  });
  ```

J
jidong 已提交
3196
### isOsAccountVerified<sup>(deprecated)</sup>
Z
zhangalong 已提交
3197

J
jidong 已提交
3198
isOsAccountVerified(localId?: number): Promise&lt;boolean&gt;
Z
zhangalong 已提交
3199

J
jidong 已提交
3200
检查指定系统帐号是否已验证。使用Promise异步回调。
3201

A
Annie_wang 已提交
3202
> **说明:** 
J
jidong 已提交
3203
>
A
Annie_wang 已提交
3204
> 从 API version 7开始支持,从API version 9开始废弃。建议使用[checkOsAccountVerified](#checkosaccountverified9-2)。
J
jidong 已提交
3205 3206

**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
Z
zhangalong 已提交
3207

Z
zengyawen 已提交
3208 3209 3210
**系统能力:** SystemCapability.Account.OsAccount

**参数:**
Z
zhangalong 已提交
3211

J
jidong 已提交
3212 3213 3214
| 参数名  | 类型   | 必填 | 说明                                                              |
| ------- | ------ | ---- | ---------------------------------------------------------------- |
| localId | number | 否   | 系统帐号ID。不填则检查当前系统帐号是否已验证。 |
Z
zhangalong 已提交
3215

Z
zengyawen 已提交
3216
**返回值:**
Z
zhangalong 已提交
3217

J
jidong 已提交
3218 3219 3220
| 类型                   | 说明                                                               |
| ---------------------- | ----------------------------------------------------------------- |
| Promise&lt;boolean&gt; | Promise对象。返回true表示指定帐号已验证;返回false表示指定帐号未验证。 |
Z
zengyawen 已提交
3221

3222
**示例:**
Z
zhangalong 已提交
3223

Z
zhangalong 已提交
3224
  ```js
3225
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
3226
  let accountManager = account_osAccount.getAccountManager();
3227
  accountManager.isOsAccountVerified(localId).then((isVerified: boolean) => {
C
chennian 已提交
3228
    console.log('isOsAccountVerified successfully, isVerified: ' + isVerified);
3229
  }).catch((err: BusinessError) => {
C
chennian 已提交
3230
    console.log('isOsAccountVerified failed, error: ' + JSON.stringify(err));
J
jidong 已提交
3231
  });
Z
zhangalong 已提交
3232 3233
  ```

J
jidong 已提交
3234
### getCreatedOsAccountsCount<sup>(deprecated)</sup>
Z
zhangalong 已提交
3235

J
jidong 已提交
3236
getCreatedOsAccountsCount(callback: AsyncCallback&lt;number&gt;): void
Z
zhangalong 已提交
3237

J
jidong 已提交
3238
获取已创建的系统帐号数量。使用callback异步回调。
Z
zhangalong 已提交
3239

A
Annie_wang 已提交
3240
> **说明:** 
3241
>
A
Annie_wang 已提交
3242
> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getOsAccountCount](#getosaccountcount9)。
3243

J
jidong 已提交
3244
**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
Z
zengyawen 已提交
3245 3246

**系统能力:** SystemCapability.Account.OsAccount
Z
zhangalong 已提交
3247

Z
zengyawen 已提交
3248
**参数:**
Z
zhangalong 已提交
3249

J
jidong 已提交
3250 3251 3252
| 参数名   | 类型                        | 必填 | 说明                                                                         |
| -------- | --------------------------- | ---- | -------------------------------------------------------------------------- |
| callback | AsyncCallback&lt;number&gt; | 是   | 回调函数。当获取成功时,err为null,data为已创建的系统帐号的数量;否则为错误对象。 |
Z
zengyawen 已提交
3253

3254
**示例:**
Z
zhangalong 已提交
3255

Z
zhangalong 已提交
3256
  ```js
3257
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
3258
  let accountManager = account_osAccount.getAccountManager();
3259
  accountManager.getCreatedOsAccountsCount((err: BusinessError, count: number)=>{
J
jidong 已提交
3260
    if (err) {
C
chennian 已提交
3261
      console.log('getCreatedOsAccountsCount failed, error: ' + JSON.stringify(err));
J
jidong 已提交
3262
    } else {
C
chennian 已提交
3263
      console.log('getCreatedOsAccountsCount successfully, count: ' + count);
J
jidong 已提交
3264
    }
Z
zhangalong 已提交
3265 3266 3267
  });
  ```

J
jidong 已提交
3268
### getCreatedOsAccountsCount<sup>(deprecated)</sup>
Z
zhangalong 已提交
3269

J
jidong 已提交
3270
getCreatedOsAccountsCount(): Promise&lt;number&gt;
Z
zhangalong 已提交
3271

J
jidong 已提交
3272
获取已创建的系统帐号数量,使用Promise异步回调。
Z
zhangalong 已提交
3273

A
Annie_wang 已提交
3274
> **说明:** 
3275
>
A
Annie_wang 已提交
3276
> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getOsAccountCount](#getosaccountcount9-1)。
3277

J
jidong 已提交
3278
**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
Z
zengyawen 已提交
3279 3280

**系统能力:** SystemCapability.Account.OsAccount
Z
zhangalong 已提交
3281

Z
zengyawen 已提交
3282
**返回值:**
Z
zhangalong 已提交
3283

J
jidong 已提交
3284 3285 3286
| 类型                  | 说明                                    |
| --------------------- | -------------------------------------- |
| Promise&lt;number&gt; | Promise对象,返回已创建的系统帐号的数量。 |
Z
zengyawen 已提交
3287

3288
**示例:**
Z
zhangalong 已提交
3289

Z
zhangalong 已提交
3290
  ```js
3291
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
3292
  let accountManager = account_osAccount.getAccountManager();
3293
  accountManager.getCreatedOsAccountsCount().then((count: number) => {
C
chennian 已提交
3294
    console.log('getCreatedOsAccountsCount successfully, count: ' + count);
3295
  }).catch((err: BusinessError) => {
C
chennian 已提交
3296
    console.log('getCreatedOsAccountsCount failed, error: ' + JSON.stringify(err));
Z
zhangalong 已提交
3297 3298 3299
  });
  ```

J
jidong 已提交
3300
### getOsAccountLocalIdFromProcess<sup>(deprecated)</sup>
Z
zhangalong 已提交
3301

J
jidong 已提交
3302
getOsAccountLocalIdFromProcess(callback: AsyncCallback&lt;number&gt;): void
Z
zhangalong 已提交
3303

J
jidong 已提交
3304
获取当前进程所属的系统帐号ID,使用callback异步回调。
Z
zengyawen 已提交
3305

A
Annie_wang 已提交
3306
> **说明:** 
J
jidong 已提交
3307
>
C
cclicn 已提交
3308
> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getOsAccountLocalId](#getosaccountlocalid9)。
Z
zengyawen 已提交
3309 3310 3311 3312

**系统能力:** SystemCapability.Account.OsAccount

**参数:**
Z
zhangalong 已提交
3313

J
jidong 已提交
3314 3315 3316
| 参数名   | 类型                        | 必填 | 说明                                                                           |
| -------- | --------------------------- | ---- | ---------------------------------------------------------------------------- |
| callback | AsyncCallback&lt;number&gt; | 是   | 回调函数。当获取成功时,err为null,data为当前进程所属的系统帐号ID;否则为错误对象。 |
Z
zhangalong 已提交
3317

J
jidong 已提交
3318
**示例:**
Z
zhangalong 已提交
3319

Z
zhangalong 已提交
3320
  ```js
3321
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
3322
  let accountManager = account_osAccount.getAccountManager();
3323
  accountManager.getOsAccountLocalIdFromProcess((err: BusinessError, localId: number) => {
J
jidong 已提交
3324
    if (err) {
C
chennian 已提交
3325
      console.log('getOsAccountLocalIdFromProcess failed, error: ' + JSON.stringify(err));
J
jidong 已提交
3326
    } else {
C
chennian 已提交
3327
      console.log('getOsAccountLocalIdFromProcess failed, error: ' + localId);
J
jidong 已提交
3328 3329
    }
  });
Z
zhangalong 已提交
3330 3331
  ```

J
jidong 已提交
3332
### getOsAccountLocalIdFromProcess<sup>(deprecated)</sup>
Z
zhangalong 已提交
3333

J
jidong 已提交
3334
getOsAccountLocalIdFromProcess(): Promise&lt;number&gt;
Z
zhangalong 已提交
3335

J
jidong 已提交
3336
获取当前进程所属的系统帐号ID,使用Promise异步回调。
Z
zhangalong 已提交
3337

A
Annie_wang 已提交
3338
> **说明:**
J
jidong 已提交
3339
>
C
cclicn 已提交
3340
> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getOsAccountLocalId](#getosaccountlocalid9-1)。
Z
zhangalong 已提交
3341

Z
zengyawen 已提交
3342
**系统能力:** SystemCapability.Account.OsAccount
Z
zhangalong 已提交
3343

Z
zengyawen 已提交
3344 3345
**返回值:**

J
jidong 已提交
3346 3347 3348
| 类型                  | 说明                                      |
| :-------------------- | :--------------------------------------- |
| Promise&lt;number&gt; | Promise对象,返回当前进程所属的系统帐号ID。 |
Z
zengyawen 已提交
3349

J
jidong 已提交
3350
**示例:**
Z
zhangalong 已提交
3351

Z
zhangalong 已提交
3352
  ```js
3353
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
3354
  let accountManager = account_osAccount.getAccountManager();
3355
  accountManager.getOsAccountLocalIdFromProcess().then((localId: number) => {
J
jidong 已提交
3356
    console.log('getOsAccountLocalIdFromProcess successfully, localId: ' + localId);
3357
  }).catch((err: BusinessError) => {
C
chennian 已提交
3358
    console.log('getOsAccountLocalIdFromProcess failed, error: ' + JSON.stringify(err));
J
jidong 已提交
3359
  });
Z
zhangalong 已提交
3360 3361
  ```

J
jidong 已提交
3362
### getOsAccountLocalIdFromUid<sup>(deprecated)</sup>
Z
zhangalong 已提交
3363

J
jidong 已提交
3364
getOsAccountLocalIdFromUid(uid: number, callback: AsyncCallback&lt;number&gt;): void
Z
zhangalong 已提交
3365

J
jidong 已提交
3366
根据uid查询对应的系统帐号ID。使用callback异步回调。
Z
zengyawen 已提交
3367

A
Annie_wang 已提交
3368
> **说明:** 
J
jidong 已提交
3369
>
C
cclicn 已提交
3370
> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getOsAccountLocalIdForUid](#getosaccountlocalidforuid9)。
Z
zhangalong 已提交
3371

Z
zengyawen 已提交
3372
**系统能力:** SystemCapability.Account.OsAccount
Z
zhangalong 已提交
3373

Z
zengyawen 已提交
3374 3375
**参数:**

J
jidong 已提交
3376 3377 3378 3379
| 参数名   | 类型                        | 必填 | 说明                                                                    |
| -------- | --------------------------- | ---- | --------------------------------------------------------------------- |
| uid      | number                      | 是   | 进程uid。                                                              |
| callback | AsyncCallback&lt;number&gt; | 是   | 回调函数。如果查询成功,err为null,data为对应的系统帐号ID;否则为错误对象。 |
Z
zengyawen 已提交
3380

J
jidong 已提交
3381
**示例:** 查询值为12345678的uid所属的系统帐号ID
Z
zhangalong 已提交
3382

Z
zhangalong 已提交
3383
  ```js
3384
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
3385
  let accountManager = account_osAccount.getAccountManager();
3386 3387
  let uid: number = 12345678;
  accountManager.getOsAccountLocalIdFromUid(uid, (err: BusinessError, localId: number) => {
J
jidong 已提交
3388
    if (err) {
C
chennian 已提交
3389
      console.log('getOsAccountLocalIdFromUid failed, error: ' + JSON.stringify(err));
J
jidong 已提交
3390
    } else {
C
chennian 已提交
3391
      console.log('getOsAccountLocalIdFromUid successfully, localId: ' + localId);
J
jidong 已提交
3392 3393
    }
  });
Z
zhangalong 已提交
3394 3395
  ```

J
jidong 已提交
3396
### getOsAccountLocalIdFromUid<sup>(deprecated)</sup>
Z
zhangalong 已提交
3397

J
jidong 已提交
3398
getOsAccountLocalIdFromUid(uid: number): Promise&lt;number&gt;
Z
zhangalong 已提交
3399

J
jidong 已提交
3400
根据uid查询对应的系统帐号ID,使用Promise异步回调。
Z
zengyawen 已提交
3401

A
Annie_wang 已提交
3402
> **说明:** 
J
jidong 已提交
3403
>
C
cclicn 已提交
3404
> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getOsAccountLocalIdForUid](#getosaccountlocalidforuid9-1)。
Z
zhangalong 已提交
3405

Z
zengyawen 已提交
3406
**系统能力:** SystemCapability.Account.OsAccount
Z
zhangalong 已提交
3407

Z
zengyawen 已提交
3408
**参数:**
Z
zhangalong 已提交
3409

J
jidong 已提交
3410 3411 3412
| 参数名 | 类型   | 必填 | 说明      |
| ------ | ------ | ---- | --------- |
| uid    | number | 是   | 进程uid。 |
Z
zhangalong 已提交
3413

Z
zengyawen 已提交
3414 3415
**返回值:**

J
jidong 已提交
3416 3417 3418
| 类型                  | 说明                                  |
| :-------------------- | :----------------------------------- |
| Promise&lt;number&gt; | Promise对象,返回uid对应的系统帐号ID。 |
Z
zengyawen 已提交
3419

J
jidong 已提交
3420
**示例:** 查询值为12345678的uid所属的系统帐号ID
Z
zhangalong 已提交
3421

Z
zhangalong 已提交
3422
  ```js
3423
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
3424
  let accountManager = account_osAccount.getAccountManager();
3425 3426
  let uid: number = 12345678;
  accountManager.getOsAccountLocalIdFromUid(uid).then((localId: number) => {
C
chennian 已提交
3427
    console.log('getOsAccountLocalIdFromUid successfully, localId: ' + localId);
3428
  }).catch((err: BusinessError) => {
C
chennian 已提交
3429
    console.log('getOsAccountLocalIdFromUid failed, error: ' + JSON.stringify(err));
J
jidong 已提交
3430
  });
3431 3432
  ```

J
jidong 已提交
3433
### getOsAccountLocalIdFromDomain<sup>(deprecated)</sup>
3434

J
jidong 已提交
3435 3436 3437 3438
getOsAccountLocalIdFromDomain(domainInfo: DomainAccountInfo, callback: AsyncCallback&lt;number&gt;): void

根据域帐号信息,获取与其关联的系统帐号的帐号ID。使用callback异步回调。

A
Annie_wang 已提交
3439
> **说明:** 
J
jidong 已提交
3440
>
C
cclicn 已提交
3441
> 从 API version 8开始支持,从API version 9开始废弃。建议使用[getOsAccountLocalIdForDomain](#getosaccountlocalidfordomain9)。
3442

J
jidong 已提交
3443
**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
3444 3445 3446 3447 3448

**系统能力:** SystemCapability.Account.OsAccount

**参数:**

J
jidong 已提交
3449 3450 3451 3452
| 参数名     | 类型                                    | 必填 | 说明                                                                         |
| ---------- | --------------------------------------- | ---- | --------------------------------------------------------------------------- |
| domainInfo | [DomainAccountInfo](#domainaccountinfo8) | 是   | 域帐号信息。                                                                |
| callback   | AsyncCallback&lt;number&gt;             | 是   | 回调函数,如果获取成功,err为null,data为域帐号关联的系统帐号ID;否则为错误对象。 |
3453

J
jidong 已提交
3454
**示例:**
3455 3456

  ```js
3457
  import { BusinessError } from '@ohos.base';
J
jidong 已提交
3458
  let domainInfo = {domain: 'testDomain', accountName: 'testAccountName'};
3459
  let accountManager = account_osAccount.getAccountManager();
3460
  accountManager.getOsAccountLocalIdFromDomain(domainInfo, (err: BusinessError, localId: number) => {
J
jidong 已提交
3461
    if (err) {
C
chennian 已提交
3462
      console.log('getOsAccountLocalIdFromDomain failed, error: ' + JSON.stringify(err));
J
jidong 已提交
3463
    } else {
C
chennian 已提交
3464
      console.log('getOsAccountLocalIdFromDomain successfully, localId: ' + localId);
J
jidong 已提交
3465 3466
    }
  });
3467 3468
  ```

J
jidong 已提交
3469
### getOsAccountLocalIdFromDomain<sup>(deprecated)</sup>
3470

J
jidong 已提交
3471 3472 3473 3474
getOsAccountLocalIdFromDomain(domainInfo: DomainAccountInfo): Promise&lt;number&gt;

根据域帐号信息,获取与其关联的系统帐号的帐号ID。使用Promise异步回调。

A
Annie_wang 已提交
3475
> **说明:** 
J
jidong 已提交
3476
>
C
cclicn 已提交
3477
> 从 API version 8开始支持,从API version 9开始废弃。建议使用[getOsAccountLocalIdForDomain](#getosaccountlocalidfordomain9-1)。
3478

J
jidong 已提交
3479
**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
3480 3481 3482 3483 3484

**系统能力:** SystemCapability.Account.OsAccount

**参数:**

J
jidong 已提交
3485 3486 3487
| 参数名     | 类型                                    | 必填 | 说明         |
| ---------- | --------------------------------------- | ---- | ------------ |
| domainInfo | [DomainAccountInfo](#domainaccountinfo8) | 是   | 域帐号信息。 |
3488 3489 3490

**返回值:**

J
jidong 已提交
3491 3492 3493
| 类型                  | 说明                                    |
| :-------------------- | :------------------------------------- |
| Promise&lt;number&gt; | Promise对象,返回域帐号关联的系统帐号ID。 |
3494

J
jidong 已提交
3495
**示例:**
3496 3497

  ```js
3498
  import { BusinessError } from '@ohos.base';
3499
  let accountManager = account_osAccount.getAccountManager();
J
jidong 已提交
3500
  let domainInfo = {domain: 'testDomain', accountName: 'testAccountName'};
3501
  accountManager.getOsAccountLocalIdFromDomain(domainInfo).then((localId: number) => {
J
jidong 已提交
3502
    console.log('getOsAccountLocalIdFromDomain successfully, localId: ' + localId);
3503
  }).catch((err: BusinessError) => {
C
chennian 已提交
3504
    console.log('getOsAccountLocalIdFromDomain failed, error: ' + JSON.stringify(err));
J
jidong 已提交
3505
  });
Z
zhangalong 已提交
3506 3507
  ```

J
jidong 已提交
3508
### getOsAccountAllConstraints<sup>(deprecated)</sup>
Z
zhangalong 已提交
3509

J
jidong 已提交
3510
getOsAccountAllConstraints(localId: number, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void
Z
zhangalong 已提交
3511

J
jidong 已提交
3512
获取指定系统帐号的全部约束。使用callback异步回调。
Z
zhangalong 已提交
3513

A
Annie_wang 已提交
3514
> **说明:** 
3515
>
A
Annie_wang 已提交
3516
> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getOsAccountConstraints](#getosaccountconstraints9)。
J
jidong 已提交
3517 3518

**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
3519

Z
zengyawen 已提交
3520
**系统能力:** SystemCapability.Account.OsAccount
Z
zhangalong 已提交
3521

Z
zengyawen 已提交
3522
**参数:**
Z
zhangalong 已提交
3523

J
jidong 已提交
3524 3525 3526 3527
| 参数名   | 类型                                     | 必填 | 说明                                                                                             |
| -------- | ---------------------------------------- | ---- | ---------------------------------------------------------------------------------------------- |
| localId  | number                                   | 是   | 系统帐号ID。                                                                                    |
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | 是   | 回调函数。如果获取成功,err为null,data为指定系统帐号的全部[约束](#系统帐号约束列表);否则为错误对象。 |
Z
zengyawen 已提交
3528

J
jidong 已提交
3529
**示例:** 获取ID为100的系统帐号的全部约束
Z
zhangalong 已提交
3530

Z
zhangalong 已提交
3531
  ```js
3532
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
3533
  let accountManager = account_osAccount.getAccountManager();
3534 3535
  let localId: number = 100;
  accountManager.getOsAccountAllConstraints(localId, (err: BusinessError, constraints: string[])=>{
J
jidong 已提交
3536 3537
    console.log('getOsAccountAllConstraints err:' + JSON.stringify(err));
    console.log('getOsAccountAllConstraints:' + JSON.stringify(constraints));
Z
zhangalong 已提交
3538 3539 3540
  });
  ```

J
jidong 已提交
3541
### getOsAccountAllConstraints<sup>(deprecated)</sup>
Z
zhangalong 已提交
3542

J
jidong 已提交
3543
getOsAccountAllConstraints(localId: number): Promise&lt;Array&lt;string&gt;&gt;
Z
zhangalong 已提交
3544

A
Annie_wang 已提交
3545
> **说明:** 
3546
>
A
Annie_wang 已提交
3547
> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getOsAccountConstraints](#getosaccountconstraints9-1)。
J
jidong 已提交
3548 3549 3550 3551

获取指定系统帐号的全部约束。使用Promise异步回调。

**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
3552

Z
zengyawen 已提交
3553 3554 3555
**系统能力:** SystemCapability.Account.OsAccount

**参数:**
Z
zhangalong 已提交
3556

J
jidong 已提交
3557 3558 3559
| 参数名  | 类型   | 必填 | 说明         |
| ------- | ------ | ---- | ------------ |
| localId | number | 是   | 系统帐号ID。 |
Z
zhangalong 已提交
3560

Z
zengyawen 已提交
3561
**返回值:**
Z
zhangalong 已提交
3562

J
jidong 已提交
3563 3564 3565
| 类型                               | 说明                                                         |
| :--------------------------------- | :----------------------------------------------------------- |
| Promise&lt;Array&lt;string&gt;&gt; | Promise对象,返回指定系统帐号的全部[约束](#系统帐号约束列表)。 |
Z
zhangalong 已提交
3566

J
jidong 已提交
3567
**示例:** 获取ID为100的系统帐号的全部约束
Z
zhangalong 已提交
3568

Z
zhangalong 已提交
3569
  ```js
3570
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
3571
  let accountManager = account_osAccount.getAccountManager();
3572 3573
  let localId: number = 100;
  accountManager.getOsAccountAllConstraints(localId).then((constraints: string[]) => {
J
jidong 已提交
3574
    console.log('getOsAccountAllConstraints, constraints: ' + constraints);
3575
  }).catch((err: BusinessError) => {
C
chennian 已提交
3576
    console.log('getOsAccountAllConstraints err: ' + JSON.stringify(err));
Z
zhangalong 已提交
3577 3578 3579
  });
  ```

J
jidong 已提交
3580
### queryActivatedOsAccountIds<sup>(deprecated)</sup>
3581

J
jidong 已提交
3582 3583 3584
queryActivatedOsAccountIds(callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void

查询当前处于激活状态的系统帐号的ID列表。使用callback异步回调。
3585

A
Annie_wang 已提交
3586
> **说明:** 
J
jidong 已提交
3587
>
C
cclicn 已提交
3588
> 从 API version 8开始支持,从API version 9开始废弃。建议使用[getActivatedOsAccountLocalIds](#getactivatedosaccountlocalids9)。
3589 3590 3591 3592 3593

**系统能力:** SystemCapability.Account.OsAccount

**参数:**

J
jidong 已提交
3594 3595 3596
| 参数名   | 类型                                     | 必填 | 说明                                                   |
| -------- | ---------------------------------------- | ---- | ------------------------------------------------------ |
| callback | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是   | 回调函数。如果查询成功,err为null,data为当前处于激活状态的系统帐号的ID列表;否则为错误对象。 |
3597

J
jidong 已提交
3598
**示例:**
3599 3600

  ```js
3601
  import { BusinessError } from '@ohos.base';
3602
  let accountManager = account_osAccount.getAccountManager();
3603
  accountManager.queryActivatedOsAccountIds((err: BusinessError, idArray: number[])=>{
J
jidong 已提交
3604 3605 3606 3607 3608 3609
    console.log('queryActivatedOsAccountIds err:' + JSON.stringify(err));
    console.log('queryActivatedOsAccountIds idArray length:' + idArray.length);
    for(let i=0;i<idArray.length;i++) {
      console.info('activated os account id: ' + idArray[i]);
    }
  });
3610 3611
  ```

J
jidong 已提交
3612
### queryActivatedOsAccountIds<sup>(deprecated)</sup>
3613

J
jidong 已提交
3614
queryActivatedOsAccountIds(): Promise&lt;Array&lt;number&gt;&gt;
3615

A
Annie_wang 已提交
3616
> **说明:** 
J
jidong 已提交
3617
>
C
cclicn 已提交
3618
> 从 API version 8开始支持,从API version 9开始废弃。建议使用[getActivatedOsAccountLocalIds](#getactivatedosaccountlocalids9-1)。
3619

J
jidong 已提交
3620
查询当前处于激活状态的系统帐号的ID列表。使用Promise异步回调。
3621

J
jidong 已提交
3622
**系统能力:** SystemCapability.Account.OsAccount
3623 3624 3625

**返回值:**

J
jidong 已提交
3626 3627 3628
| 类型                               | 说明                                               |
| ---------------------------------- | ------------------------------------------------- |
| Promise&lt;Array&lt;number&gt;&gt; | Promise对象,返回当前处于激活状态的系统帐号的ID列表。 |
3629

J
jidong 已提交
3630
**示例:**
3631 3632

  ```js
3633
  import { BusinessError } from '@ohos.base';
3634
  let accountManager = account_osAccount.getAccountManager();
3635
  accountManager.queryActivatedOsAccountIds().then((idArray: number[]) => {
J
jidong 已提交
3636
    console.log('queryActivatedOsAccountIds, idArray: ' + idArray);
3637
  }).catch((err: BusinessError) => {
C
chennian 已提交
3638
    console.log('queryActivatedOsAccountIds err: ' + JSON.stringify(err));
J
jidong 已提交
3639
  });
3640 3641
  ```

J
jidong 已提交
3642
### queryCurrentOsAccount<sup>(deprecated)</sup>
Z
zhangalong 已提交
3643

J
jidong 已提交
3644
queryCurrentOsAccount(callback: AsyncCallback&lt;OsAccountInfo&gt;): void
Z
zhangalong 已提交
3645

J
jidong 已提交
3646
查询当前进程所属的系统帐号的信息。使用callback异步回调。
Z
zhangalong 已提交
3647

A
Annie_wang 已提交
3648
> **说明:** 
3649
>
A
Annie_wang 已提交
3650
> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getCurrentOsAccount](#getcurrentosaccount9)。
J
jidong 已提交
3651 3652

**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
3653

Z
zengyawen 已提交
3654
**系统能力:** SystemCapability.Account.OsAccount
Z
zhangalong 已提交
3655

Z
zengyawen 已提交
3656
**参数:**
Z
zhangalong 已提交
3657

J
jidong 已提交
3658 3659 3660
| 参数名   | 类型                                                 | 必填 | 说明                                           |
| -------- | ---------------------------------------------------- | ---- | ---------------------------------------------- |
| callback | AsyncCallback&lt;[OsAccountInfo](#osaccountinfo)&gt; | 是   | 回调函数。如果查询成功,err为null,data为当前进程所属的系统帐号信息;否则为错误对象。 |
Z
zengyawen 已提交
3661

J
jidong 已提交
3662
**示例:**
Z
zhangalong 已提交
3663

Z
zhangalong 已提交
3664
  ```js
3665
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
3666
  let accountManager = account_osAccount.getAccountManager();
3667
  accountManager.queryCurrentOsAccount((err: BusinessError, curAccountInfo: account_osAccount.OsAccountInfo)=>{
J
jidong 已提交
3668 3669
    console.log('queryCurrentOsAccount err:' + JSON.stringify(err));
    console.log('queryCurrentOsAccount curAccountInfo:' + JSON.stringify(curAccountInfo));
Z
zhangalong 已提交
3670 3671 3672
  });
  ```

J
jidong 已提交
3673
### queryCurrentOsAccount<sup>(deprecated)</sup>
Z
zhangalong 已提交
3674

J
jidong 已提交
3675
queryCurrentOsAccount(): Promise&lt;OsAccountInfo&gt;
Z
zhangalong 已提交
3676

J
jidong 已提交
3677
查询当前进程所属的系统帐号的信息。使用Promise异步回调。
Z
zhangalong 已提交
3678

A
Annie_wang 已提交
3679
> **说明:** 
3680
>
A
Annie_wang 已提交
3681
> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getCurrentOsAccount](#getcurrentosaccount9-1)。
Z
zengyawen 已提交
3682

J
jidong 已提交
3683
**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
Z
zhangalong 已提交
3684

J
jidong 已提交
3685
**系统能力:** SystemCapability.Account.OsAccount
Z
zhangalong 已提交
3686

Z
zengyawen 已提交
3687
**返回值:**
Z
zhangalong 已提交
3688

J
jidong 已提交
3689 3690 3691
| 类型                                           | 说明                                       |
| ---------------------------------------------- | ------------------------------------------ |
| Promise&lt;[OsAccountInfo](#osaccountinfo)&gt; | Promise对象,返回当前进程所属的系统帐号信息。 |
Z
zhangalong 已提交
3692

J
jidong 已提交
3693
**示例:**
Z
zhangalong 已提交
3694

Z
zhangalong 已提交
3695
  ```js
3696
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
3697
  let accountManager = account_osAccount.getAccountManager();
3698
  accountManager.queryCurrentOsAccount().then((accountInfo: account_osAccount.OsAccountInfo) => {
J
jidong 已提交
3699
    console.log('queryCurrentOsAccount, accountInfo: ' + JSON.stringify(accountInfo));
3700
  }).catch((err: BusinessError) => {
C
chennian 已提交
3701
    console.log('queryCurrentOsAccount err: ' + JSON.stringify(err));
Z
zhangalong 已提交
3702 3703 3704
  });
  ```

J
jidong 已提交
3705
### getOsAccountTypeFromProcess<sup>(deprecated)</sup>
Z
zhangalong 已提交
3706

J
jidong 已提交
3707
getOsAccountTypeFromProcess(callback: AsyncCallback&lt;OsAccountType&gt;): void
Z
zhangalong 已提交
3708

J
jidong 已提交
3709
查询当前进程所属的系统帐号的帐号类型。使用callback异步回调。
Z
zengyawen 已提交
3710

A
Annie_wang 已提交
3711
> **说明:** 
J
jidong 已提交
3712
>
A
Annie_wang 已提交
3713
> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getOsAccountType](#getosaccounttype9)。
Z
zhangalong 已提交
3714

Z
zengyawen 已提交
3715
**系统能力:** SystemCapability.Account.OsAccount
Z
zhangalong 已提交
3716

Z
zengyawen 已提交
3717 3718
**参数:**

J
jidong 已提交
3719 3720 3721
| 参数名   | 类型                                                 | 必填 | 说明                                                 |
| -------- | ---------------------------------------------------- | ---- | ---------------------------------------------------- |
| callback | AsyncCallback&lt;[OsAccountType](#osaccounttype)&gt; | 是   | 回调函数。如果查询成功,err为null,data为当前进程所属的系统帐号的帐号类型;否则为错误对象。 |
Z
zengyawen 已提交
3722

3723
**示例:**
Z
zhangalong 已提交
3724

Z
zhangalong 已提交
3725
  ```js
3726
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
3727
  let accountManager = account_osAccount.getAccountManager();
3728
  accountManager.getOsAccountTypeFromProcess((err: BusinessError, accountType: account_osAccount.OsAccountType) => {
J
jidong 已提交
3729 3730 3731
    console.log('getOsAccountTypeFromProcess err: ' + JSON.stringify(err));
    console.log('getOsAccountTypeFromProcess accountType: ' + accountType);
  });
Z
zhangalong 已提交
3732 3733
  ```

J
jidong 已提交
3734
### getOsAccountTypeFromProcess<sup>(deprecated)</sup>
Z
zhangalong 已提交
3735

J
jidong 已提交
3736
getOsAccountTypeFromProcess(): Promise&lt;OsAccountType&gt;
Z
zhangalong 已提交
3737

J
jidong 已提交
3738
查询当前进程所属的系统帐号的帐号类型。使用Promise异步回调。
Z
zengyawen 已提交
3739

A
Annie_wang 已提交
3740
> **说明:**
J
jidong 已提交
3741
>
A
Annie_wang 已提交
3742
> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getOsAccountType](#getosaccounttype9-1)。
Z
zengyawen 已提交
3743 3744

**系统能力:** SystemCapability.Account.OsAccount
Z
zhangalong 已提交
3745

J
jidong 已提交
3746
**返回值:**
Z
zhangalong 已提交
3747

J
jidong 已提交
3748 3749 3750
| 类型                                           | 说明                                            |
| ---------------------------------------------- | ----------------------------------------------- |
| Promise&lt;[OsAccountType](#osaccounttype)&gt; | Promise对象,返回当前进程所属的系统帐号的帐号类型。 |
Z
zengyawen 已提交
3751

3752
**示例:**
Z
zhangalong 已提交
3753

Z
zhangalong 已提交
3754
  ```js
3755
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
3756
  let accountManager = account_osAccount.getAccountManager();
3757
  accountManager.getOsAccountTypeFromProcess().then((accountType: account_osAccount.OsAccountType) => {
J
jidong 已提交
3758
    console.log('getOsAccountTypeFromProcess, accountType: ' + accountType);
3759
  }).catch((err: BusinessError) => {
C
chennian 已提交
3760
    console.log('getOsAccountTypeFromProcess err: ' + JSON.stringify(err));
J
jidong 已提交
3761
  });
Z
zhangalong 已提交
3762 3763
  ```

J
jidong 已提交
3764
### getDistributedVirtualDeviceId<sup>(deprecated)</sup>
3765

J
jidong 已提交
3766
getDistributedVirtualDeviceId(callback: AsyncCallback&lt;string&gt;): void
3767

J
jidong 已提交
3768 3769
获取分布式虚拟设备ID。使用callback异步回调。

A
Annie_wang 已提交
3770
> **说明:** 
J
jidong 已提交
3771
>
A
Annie_wang 已提交
3772
> 从 API version 7开始支持,从API version 9开始废弃。建议使用[queryDistributedVirtualDeviceId](#querydistributedvirtualdeviceid9)。
3773

J
jidong 已提交
3774
**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC 或 ohos.permission.MANAGE_LOCAL_ACCOUNTS
3775 3776 3777 3778 3779

**系统能力:** SystemCapability.Account.OsAccount

**参数:**

J
jidong 已提交
3780 3781 3782
| 参数名   | 类型                        | 必填 | 说明                                                                    |
| -------- | --------------------------- | ---- | --------------------------------------------------------------------- |
| callback | AsyncCallback&lt;string&gt; | 是   | 回调函数。如果获取成功,err为null,data为分布式虚拟设备ID;否则为错误对象。 |
3783

3784
**示例:**
3785 3786

  ```js
3787
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
3788
  let accountManager = account_osAccount.getAccountManager();
3789
  accountManager.getDistributedVirtualDeviceId((err: BusinessError, virtualID: string) => {
J
jidong 已提交
3790 3791 3792
    console.log('getDistributedVirtualDeviceId err: ' + JSON.stringify(err));
    console.log('getDistributedVirtualDeviceId virtualID: ' + virtualID);
  });
3793 3794
  ```

J
jidong 已提交
3795
### getDistributedVirtualDeviceId<sup>(deprecated)</sup>
3796

J
jidong 已提交
3797
getDistributedVirtualDeviceId(): Promise&lt;string&gt;
3798

J
jidong 已提交
3799
获取分布式虚拟设备ID。使用Promise异步回调。
3800

A
Annie_wang 已提交
3801
> **说明:** 
J
jidong 已提交
3802
>
A
Annie_wang 已提交
3803
> 从 API version 7开始支持,从API version 9开始废弃。建议使用[queryDistributedVirtualDeviceId](#querydistributedvirtualdeviceid9-1)。
3804

J
jidong 已提交
3805
**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC 或 ohos.permission.MANAGE_LOCAL_ACCOUNTS
3806

J
jidong 已提交
3807
**系统能力:** SystemCapability.Account.OsAccount
3808 3809 3810

**返回值:**

J
jidong 已提交
3811 3812 3813
| 类型                  | 说明                              |
| --------------------- | --------------------------------- |
| Promise&lt;string&gt; | Promise对象,返回分布式虚拟设备ID。 |
3814

3815
**示例:**
3816 3817

  ```js
3818
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
3819
  let accountManager = account_osAccount.getAccountManager();
3820
  accountManager.getDistributedVirtualDeviceId().then((virtualID: string) => {
J
jidong 已提交
3821
    console.log('getDistributedVirtualDeviceId, virtualID: ' + virtualID);
3822
  }).catch((err: BusinessError) => {
C
chennian 已提交
3823
    console.log('getDistributedVirtualDeviceId err: ' + JSON.stringify(err));
J
jidong 已提交
3824
  });
3825 3826
  ```

J
jidong 已提交
3827
### getOsAccountLocalIdBySerialNumber<sup>(deprecated)</sup>
3828

J
jidong 已提交
3829
getOsAccountLocalIdBySerialNumber(serialNumber: number, callback: AsyncCallback&lt;number&gt;): void
3830

J
jidong 已提交
3831
通过SN码查询与其关联的系统帐号的帐号ID。使用callback异步回调。
3832

A
Annie_wang 已提交
3833
> **说明:** 
J
jidong 已提交
3834
>
C
cclicn 已提交
3835
> 从 API version 8开始支持,从API version 9开始废弃。建议使用[getOsAccountLocalIdForSerialNumber](#getosaccountlocalidforserialnumber9)。
3836

3837 3838 3839 3840
**系统能力:** SystemCapability.Account.OsAccount

**参数:**

J
jidong 已提交
3841 3842 3843 3844
| 参数名       | 类型                        | 必填 | 说明                                                                               |
| ------------ | --------------------------- | ---- | -------------------------------------------------------------------------------- |
| serialNumber | number                      | 是   | 帐号SN码。                                                                        |
| callback     | AsyncCallback&lt;number&gt; | 是   | 回调函数。如果查询成功,err为null,data为与SN码关联的系统帐号的帐号ID;否则为错误对象。 |
3845

J
jidong 已提交
3846
**示例:** 查询与SN码12345关联的系统帐号的ID
3847 3848

  ```js
3849
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
3850
  let accountManager = account_osAccount.getAccountManager();
3851 3852
  let serialNumber: number = 12345;
  accountManager.getOsAccountLocalIdBySerialNumber(serialNumber, (err: BusinessError, localId: number)=>{
J
jidong 已提交
3853 3854 3855
    console.log('ger localId err:' + JSON.stringify(err));
    console.log('get localId:' + localId + ' by serialNumber: ' + serialNumber);
  });
3856 3857
  ```

J
jidong 已提交
3858
### getOsAccountLocalIdBySerialNumber<sup>(deprecated)</sup>
3859

J
jidong 已提交
3860
getOsAccountLocalIdBySerialNumber(serialNumber: number): Promise&lt;number&gt;
3861

J
jidong 已提交
3862
通过SN码查询与其关联的系统帐号的帐号ID。使用Promise异步回调。
3863

A
Annie_wang 已提交
3864
> **说明:** 
J
jidong 已提交
3865
>
C
cclicn 已提交
3866
> 从 API version 8开始支持,从API version 9开始废弃。建议使用[getOsAccountLocalIdForSerialNumber](#getosaccountlocalidforserialnumber9-1)。
3867

3868 3869
**系统能力:** SystemCapability.Account.OsAccount

J
jidong 已提交
3870 3871 3872 3873 3874 3875
**参数:**

| 参数名       | 类型   | 必填 | 说明       |
| ------------ | ------ | ---- | ---------- |
| serialNumber | number | 是   | 帐号SN码。 |

3876 3877 3878
**返回值:**

| 类型                  | 说明                                                         |
J
jidong 已提交
3879 3880
| --------------------- | -------------------------------------------- |
| Promise&lt;number&gt; | Promise对象,返回与SN码关联的系统帐号的帐号ID。 |
3881

J
jidong 已提交
3882
**示例:** 查询与SN码12345关联的系统帐号的ID
3883 3884

  ```js
3885
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
3886
  let accountManager = account_osAccount.getAccountManager();
3887 3888
  let serialNumber: number = 12345;
  accountManager.getOsAccountLocalIdBySerialNumber(serialNumber).then((localId: number) => {
J
jidong 已提交
3889
    console.log('getOsAccountLocalIdBySerialNumber localId: ' + localId);
3890
  }).catch((err: BusinessError) => {
C
chennian 已提交
3891
    console.log('getOsAccountLocalIdBySerialNumber err: ' + JSON.stringify(err));
J
jidong 已提交
3892
  });
3893 3894
  ```

J
jidong 已提交
3895
### getSerialNumberByOsAccountLocalId<sup>(deprecated)</sup>
3896

J
jidong 已提交
3897
getSerialNumberByOsAccountLocalId(localId: number, callback: AsyncCallback&lt;number&gt;): void
3898

J
jidong 已提交
3899
通过系统帐号ID获取与该系统帐号关联的SN码。使用callback异步回调。
3900

A
Annie_wang 已提交
3901
> **说明:** 
J
jidong 已提交
3902
>
C
cclicn 已提交
3903
> 从 API version 8开始支持,从API version 9开始废弃。建议使用[getSerialNumberForOsAccountLocalId](#getserialnumberforosaccountlocalid9)。
3904 3905 3906 3907 3908

**系统能力:** SystemCapability.Account.OsAccount

**参数:**

J
jidong 已提交
3909 3910 3911 3912
| 参数名   | 类型                        | 必填 | 说明                                                                         |
| -------- | --------------------------- | ---- | --------------------------------------------------------------------------- |
| localId  | number                      | 是   | 系统帐号ID。                                                                 |
| callback | AsyncCallback&lt;number&gt; | 是   | 回调函数。如果获取成功,err为null,data为与该系统帐号关联的SN码;否则为错误对象。 |
3913

J
jidong 已提交
3914
**示例:** 获取ID为100的系统帐号关联的SN码
3915 3916

  ```js
3917
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
3918
  let accountManager = account_osAccount.getAccountManager();
3919 3920
  let localId: number = 100;
  accountManager.getSerialNumberByOsAccountLocalId(localId, (err: BusinessError, serialNumber: number)=>{
J
jidong 已提交
3921 3922 3923
    console.log('ger serialNumber err:' + JSON.stringify(err));
    console.log('get serialNumber:' + serialNumber + ' by localId: ' + localId);
  });
3924 3925
  ```

J
jidong 已提交
3926
### getSerialNumberByOsAccountLocalId<sup>(deprecated)</sup>
3927

J
jidong 已提交
3928
getSerialNumberByOsAccountLocalId(localId: number): Promise&lt;number&gt;
3929

J
jidong 已提交
3930
通过系统帐号ID获取与该系统帐号关联的SN码。使用Promise异步回调。
3931

A
Annie_wang 已提交
3932
> **说明:** 
J
jidong 已提交
3933
>
C
cclicn 已提交
3934
> 从 API version 8开始支持,从API version 9开始废弃。建议使用[getSerialNumberForOsAccountLocalId](#getserialnumberforosaccountlocalid9-1)。
3935 3936 3937 3938 3939

**系统能力:** SystemCapability.Account.OsAccount

**参数:**

J
jidong 已提交
3940 3941 3942
| 参数名  | 类型   | 必填 | 说明          |
| ------- | ------ | ---- | ----------- |
| localId | number | 是   | 系统帐号ID。 |
3943 3944 3945

**返回值:**

J
jidong 已提交
3946 3947 3948
| 类型                  | 说明                                    |
| --------------------- | -------------------------------------- |
| Promise&lt;number&gt; | Promise对象,返回与该系统帐号关联的SN码。 |
3949

J
jidong 已提交
3950
**示例:** 获取ID为100的系统帐号关联的SN码
3951 3952

  ```js
3953
  import { BusinessError } from '@ohos.base';
F
fanchenxuan 已提交
3954
  let accountManager = account_osAccount.getAccountManager();
3955 3956
  let localId: number = 100;
  accountManager.getSerialNumberByOsAccountLocalId(localId).then((serialNumber: number) => {
J
jidong 已提交
3957
    console.log('getSerialNumberByOsAccountLocalId serialNumber: ' + serialNumber);
3958
  }).catch((err: BusinessError) => {
C
chennian 已提交
3959
    console.log('getSerialNumberByOsAccountLocalId err: ' + JSON.stringify(err));
J
jidong 已提交
3960
  });
3961 3962
  ```

3963 3964 3965 3966
## UserAuth<sup>8+</sup>

用户认证类。

J
jidong 已提交
3967
**系统接口:** 此接口为系统接口。
3968

3969 3970 3971 3972 3973 3974
### constructor<sup>8+</sup>

constructor()

创建用户认证的实例。

J
jidong 已提交
3975
**系统接口:** 此接口为系统接口。
3976

3977 3978
**系统能力**:SystemCapability.Account.OsAccount

3979
**示例:**  
3980
  ```js
J
jidong 已提交
3981
  let userAuth = new account_osAccount.UserAuth();
3982 3983 3984 3985 3986 3987 3988 3989
  ```

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

getVersion(): number;

返回版本信息。

J
jidong 已提交
3990
**系统接口:** 此接口为系统接口。
3991 3992 3993 3994 3995 3996 3997 3998 3999

**系统能力:** SystemCapability.Account.OsAccount

**返回值:**

| 类型   | 说明         |
| :----- | :----------- |
| number | 返回版本信息。|

4000
**示例:**  
4001
  ```js
J
jidong 已提交
4002
  let userAuth = new account_osAccount.UserAuth();
4003
  let version: number = userAuth.getVersion();
F
fanchenxuan 已提交
4004
  console.log('getVersion version = ' + version);
4005 4006 4007 4008 4009 4010
  ```

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

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

J
jidong 已提交
4011
获取指定认证类型和认证可信等级的认证能力的可用状态。
4012

J
jidong 已提交
4013
**系统接口:** 此接口为系统接口。
4014 4015 4016 4017 4018 4019 4020

**系统能力:** SystemCapability.Account.OsAccount

**需要权限:** ohos.permission.ACCESS_USER_AUTH_INTERNAL

**参数:**

J
jidong 已提交
4021 4022 4023 4024
| 参数名           | 类型                               | 必填 | 说明                       |
| --------------- | -----------------------------------| ---- | ------------------------- |
| authType        | [AuthType](#authtype8)             | 是   | 认证类型。     |
| authTrustLevel  | [AuthTrustLevel](#authtrustlevel8) | 是   | 认证的可信等级。 |
4025 4026 4027

**返回值:**

J
jidong 已提交
4028 4029 4030 4031 4032 4033 4034 4035 4036 4037
| 类型   | 说明                           |
| ------ | ----------------------------- |
| number | 返回认证能力的可用状态。 |

**错误码:**

| 错误码ID | 错误信息                     |
| -------- | --------------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid authType or authTrustLevel. |
4038

4039
**示例:**  
4040
  ```js
J
jidong 已提交
4041 4042 4043
  let userAuth = new account_osAccount.UserAuth();
  let authType = account_osAccount.AuthType.PIN;
  let authTrustLevel = account_osAccount.AuthTrustLevel.ATL1;
4044 4045 4046 4047 4048 4049
  try {
    let status = userAuth.getAvailableStatus(authType, authTrustLevel);
    console.log('getAvailableStatus status = ' + status);
  } catch (e) {
    console.log('getAvailableStatus exception = ' + JSON.stringify(e));
  }
4050 4051 4052 4053 4054 4055
  ```

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

getProperty(request: GetPropertyRequest, callback: AsyncCallback&lt;ExecutorProperty&gt;): void;

J
jidong 已提交
4056
基于指定的请求信息获取属性。使用callback异步回调。
4057

J
jidong 已提交
4058
**系统接口:** 此接口为系统接口。
4059 4060 4061 4062 4063 4064 4065 4066

**系统能力:** SystemCapability.Account.OsAccount

**需要权限:** ohos.permission.ACCESS_USER_AUTH_INTERNAL

**参数:**

| 参数名    | 类型                                                                    | 必填 | 说明                                |
J
jidong 已提交
4067
| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------ |
4068
| request  | [GetPropertyRequest](#getpropertyrequest8)                  | 是   | 请求信息,包括认证类型和属性类型列表。 |
J
jidong 已提交
4069 4070 4071 4072 4073 4074 4075 4076
| callback | AsyncCallback&lt;[ExecutorProperty](#executorproperty8)&gt; | 是   | 回调函数。如果获取成功,err为null,data为执行器属性信息;否则为错误对象。|

**错误码:**

| 错误码ID | 错误信息                     |
| -------- | --------------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid request. |
4077

4078
**示例:**
4079
  ```js
4080
  import { BusinessError } from '@ohos.base';
J
jidong 已提交
4081 4082
  let userAuth = new account_osAccount.UserAuth();
  let keys = [
4083
    account_osAccount.GetPropertyType.AUTH_SUB_TYPE,
J
jidong 已提交
4084 4085 4086 4087 4088 4089 4090
    account_osAccount.GetPropertyType.REMAIN_TIMES,
    account_osAccount.GetPropertyType.FREEZING_TIME
  ];
  let request = {
    authType: account_osAccount.AuthType.PIN,
    keys: keys
  };
4091
  try {
4092
    userAuth.getProperty(request, (err: BusinessError, result: account_osAccount.ExecutorProperty) => {
4093 4094 4095 4096 4097 4098
      console.log('getProperty err = ' + JSON.stringify(err));
      console.log('getProperty result = ' + JSON.stringify(result));
    });
  } catch (e) {
    console.log('getProperty exception = ' + JSON.stringify(e));
  }
4099 4100 4101 4102
  ```

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

4103
getProperty(request: GetPropertyRequest): Promise&lt;ExecutorProperty&gt;;
4104

J
jidong 已提交
4105
基于指定的请求信息获取属性。使用Promise异步回调。
4106

J
jidong 已提交
4107
**系统接口:** 此接口为系统接口。
4108 4109 4110 4111 4112 4113 4114 4115 4116

**系统能力:** SystemCapability.Account.OsAccount

**需要权限:** ohos.permission.ACCESS_USER_AUTH_INTERNAL

**参数:**

| 参数名    | 类型                                                   | 必填 | 说明                                |
| -------- | ------------------------------------------------------ | ---- | ---------------------------------- |
4117
| request  | [GetPropertyRequest](#getpropertyrequest8) | 是   | 请求信息,包括认证类型和属性类型列表。 |
4118 4119 4120 4121 4122

**返回值:**

| 类型                                                              | 说明                                                 |
| :---------------------------------------------------------------- | :-------------------------------------------------- |
J
jidong 已提交
4123
| Promise&lt;[ExecutorProperty](#executorproperty8)&gt; | Promise对象,返回执行者属性信息。 |
4124

J
jidong 已提交
4125 4126 4127 4128 4129 4130 4131
**错误码:**

| 错误码ID | 错误信息                     |
| -------- | --------------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid request. |

4132
**示例:**
4133
  ```js
4134
  import { BusinessError } from '@ohos.base';
J
jidong 已提交
4135 4136 4137 4138 4139 4140 4141 4142 4143 4144
  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
  };
4145
  try {
4146
    userAuth.getProperty(request).then((result: account_osAccount.ExecutorProperty) => {
4147
      console.log('getProperty result = ' + JSON.stringify(result));
4148
    }).catch((err: BusinessError) => {
4149 4150 4151 4152 4153
      console.log('getProperty error = ' + JSON.stringify(err));
    });
  } catch (e) {
    console.log('getProperty exception = ' + JSON.stringify(e));
  }
4154 4155 4156 4157
  ```

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

4158
setProperty(request: SetPropertyRequest, callback: AsyncCallback&lt;void&gt;): void;
4159

J
jidong 已提交
4160
设置可用于初始化算法的属性。使用callback异步回调。
4161

J
jidong 已提交
4162
**系统接口:** 此接口为系统接口。
4163 4164 4165 4166 4167 4168 4169 4170 4171

**系统能力:** SystemCapability.Account.OsAccount

**需要权限:** ohos.permission.ACCESS_USER_AUTH_INTERNAL

**参数:**

| 参数名    | 类型                                                  | 必填 | 说明                                                                    |
| -------- | ----------------------------------------------------- | ---- | ---------------------------------------------------------------------- |
4172
| request  | [SetPropertyRequest](#setpropertyrequest8)| 是   | 请求信息,包括认证类型和要设置的密钥值。                                   |
4173
| callback | AsyncCallback&lt;void&gt;                           | 是   | 回调函数。如果设置成功,err为null,否则为错误对象。 |
4174

J
jidong 已提交
4175 4176 4177 4178 4179 4180 4181
**错误码:**

| 错误码ID | 错误信息                     |
| -------- | --------------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid request. |

4182
**示例:**
4183
  ```js
4184
  import { BusinessError } from '@ohos.base';
J
jidong 已提交
4185 4186 4187 4188 4189 4190
  let userAuth = new account_osAccount.UserAuth();
  let request = {
    authType: account_osAccount.AuthType.PIN,
    key: account_osAccount.SetPropertyType.INIT_ALGORITHM,
    setInfo: new Uint8Array([0])
  };
4191
  try {
4192
    userAuth.setProperty(request, (err: BusinessError) => {
4193 4194 4195 4196 4197
      if (err) {
        console.log('setProperty failed, error = ' + JSON.stringify(err));
      } else {
        console.log('setProperty successfully');
      }
4198 4199 4200 4201
    });
  } catch (e) {
    console.log('setProperty exception = ' + JSON.stringify(e));
  }
4202 4203 4204 4205
  ```

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

4206
setProperty(request: SetPropertyRequest): Promise&lt;void&gt;;
4207

J
jidong 已提交
4208
设置可用于初始化算法的属性。使用Promise异步回调。
4209

J
jidong 已提交
4210
**系统接口:** 此接口为系统接口。
4211 4212 4213 4214 4215 4216 4217

**系统能力:** SystemCapability.Account.OsAccount

**需要权限:** ohos.permission.ACCESS_USER_AUTH_INTERNAL

**参数:**

J
jidong 已提交
4218 4219
| 参数名    | 类型                                       | 必填 | 说明                                      |
| -------- | ------------------------------------------ | ---- | ---------------------------------------- |
4220
| request  | [SetPropertyRequest](#setpropertyrequest8) | 是   | 请求信息,包括身份验证类型和要设置的密钥值。 |
4221 4222 4223

**返回值:**

J
jidong 已提交
4224 4225
| 类型                  | 说明                                                           |
| :-------------------- | :------------------------------------------------------------ |
A
Annie_wang 已提交
4226
| Promise&lt;void&gt; | Promise对象,无返回结果的Promise对象。 |
4227

J
jidong 已提交
4228 4229 4230 4231 4232 4233 4234
**错误码:**

| 错误码ID | 错误信息                     |
| -------- | --------------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid request. |

4235
**示例:**
4236
  ```js
4237
  import { BusinessError } from '@ohos.base';
J
jidong 已提交
4238
  let userAuth = new account_osAccount.UserAuth();
4239
  let request2 = {
J
jidong 已提交
4240 4241 4242 4243
    authType: account_osAccount.AuthType.PIN,
    key: account_osAccount.SetPropertyType.INIT_ALGORITHM,
    setInfo: new Uint8Array([0])
  };
4244
  try {
4245
    userAuth.setProperty(request2).then(() => {
4246
      console.log('setProperty successfully');
4247
    }).catch((err: BusinessError) => {
4248
      console.log('setProperty failed, error = ' + JSON.stringify(err));
4249 4250 4251 4252
    });
  } catch (e) {
    console.log('setProperty exception = ' + JSON.stringify(e));
  }
4253 4254 4255 4256 4257 4258
  ```

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

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

J
jidong 已提交
4259
认证当前用户。使用callback异步回调。
4260

J
jidong 已提交
4261
**系统接口:** 此接口为系统接口。
4262 4263 4264 4265 4266 4267 4268

**系统能力:** SystemCapability.Account.OsAccount

**需要权限:** ohos.permission.ACCESS_USER_AUTH_INTERNAL

**参数:**

J
jidong 已提交
4269 4270
| 参数名           | 类型                                     | 必填 | 说明                                |
| --------------- | ---------------------------------------- | --- | ------------------------------------ |
J
jidong 已提交
4271
| challenge       | Uint8Array                               | 是  | 指示挑战值,挑战值为一个随机数,用于提升安全性。|
4272 4273
| authType        | [AuthType](#authtype8)                   | 是  | 指示认证类型。                        |
| authTrustLevel  | [AuthTrustLevel](#authtrustlevel8)       | 是  | 指示认证结果的信任级别。               |
J
jidong 已提交
4274
| callback        | [IUserAuthCallback](#iuserauthcallback8) | 是  | 回调对象,返回认证结果。  |
4275 4276 4277 4278

**返回值:**

| 类型        | 说明               |
J
jidong 已提交
4279
| ---------- | ------------------ |
4280 4281
| Uint8Array | 返回取消的上下文ID。 |

J
jidong 已提交
4282 4283 4284 4285 4286
**错误码:**

| 错误码ID | 错误信息          |
| -------- | --------------------- |
| 12300001 | System service exception. |
J
jidong 已提交
4287
| 12300002 | Invalid challenge, authType or authTrustLevel. |
J
jidong 已提交
4288
| 12300101 | Credential is incorrect. |
4289
| 12300102 | Credential not enrolled. |
J
jidong 已提交
4290 4291
| 12300105 | Unsupported authTrustLevel. |
| 12300106 | Unsupported authType. |
4292
| 12300109 | Authentication is canceled. |
C
chennian 已提交
4293
| 12300110 | Authentication is locked. |
J
jidong 已提交
4294
| 12300111 | Authentication timeout. |
C
chennian 已提交
4295
| 12300112 | Authentication service is busy. |
J
jidong 已提交
4296

4297
**示例:**
4298
  ```js
J
jidong 已提交
4299 4300 4301 4302
  let userAuth = new account_osAccount.UserAuth();
  let challenge = new Uint8Array([0]);
  let authType = account_osAccount.AuthType.PIN;
  let authTrustLevel = account_osAccount.AuthTrustLevel.ATL1;
4303 4304 4305 4306 4307 4308 4309 4310 4311 4312
  try {
    userAuth.auth(challenge, authType, authTrustLevel, {
      onResult: function(result,extraInfo){
          console.log('auth result = ' + result);
          console.log('auth extraInfo = ' + JSON.stringify(extraInfo));
      }
    });
  } catch (e) {
    console.log('auth exception = ' + JSON.stringify(e));
  }
4313 4314 4315 4316 4317 4318
  ```

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

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

J
jidong 已提交
4319
认证指定用户。使用callback异步回调。
4320

J
jidong 已提交
4321
**系统接口:** 此接口为系统接口。
4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332

**系统能力:** SystemCapability.Account.OsAccount

**需要权限:** ohos.permission.ACCESS_USER_AUTH_INTERNAL

**参数:**

| 参数名           | 类型                                                 | 必填 | 说明                                |
| --------------- | ---------------------------------------------------- | --- | ------------------------------------ |
| userId          | number                                               | 是  | 指示用户身份。                        |
| challenge       | Uint8Array                                           | 是  | 指示挑战值,挑战值为一个随机数,用于提升安全性。                          |
4333 4334
| authType        | [AuthType](#authtype8)                   | 是  | 指示认证类型。                        |
| authTrustLevel  | [AuthTrustLevel](#authtrustlevel8)       | 是  | 指示认证结果的信任级别。               |
J
jidong 已提交
4335
| callback        | [IUserAuthCallback](#iuserauthcallback8) | 是  | 回调对象,返回认证结果。  |
4336 4337 4338 4339

**返回值:**

| 类型        | 说明               |
J
jidong 已提交
4340
| ---------- | ------------------ |
4341 4342
| Uint8Array | 返回取消的上下文ID。 |

J
jidong 已提交
4343 4344 4345 4346 4347
**错误码:**

| 错误码ID | 错误信息          |
| -------- | --------------------- |
| 12300001 | System service exception. |
J
jidong 已提交
4348
| 12300002 | Invalid userId, challenge, authType or authTrustLevel. |
J
jidong 已提交
4349
| 12300101 | Credential is incorrect. |
4350
| 12300102 | Credential not enrolled. |
J
jidong 已提交
4351 4352
| 12300105 | Unsupported authTrustLevel. |
| 12300106 | Unsupported authType. |
4353
| 12300109 | Authentication is canceled. |
C
chennian 已提交
4354
| 12300110 | Authentication is locked. |
J
jidong 已提交
4355
| 12300111 | Authentication timeout. |
C
chennian 已提交
4356
| 12300112 | Authentication service is busy. |
J
jidong 已提交
4357

4358
**示例:**
4359
  ```js
J
jidong 已提交
4360
  let userAuth = new account_osAccount.UserAuth();
4361
  let userID: number = 100;
J
jidong 已提交
4362 4363 4364
  let challenge = new Uint8Array([0]);
  let authType = account_osAccount.AuthType.PIN;
  let authTrustLevel = account_osAccount.AuthTrustLevel.ATL1;
4365 4366 4367
  try {
    userAuth.authUser(userID, challenge, authType, authTrustLevel, {
      onResult: function(result,extraInfo){
J
jidong 已提交
4368 4369
        console.log('authUser result = ' + result);
        console.log('authUser extraInfo = ' + JSON.stringify(extraInfo));
4370 4371 4372 4373 4374
      }
    });
  } catch (e) {
    console.log('authUser exception = ' + JSON.stringify(e));
  }
4375 4376 4377 4378
  ```

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

4379
cancelAuth(contextID: Uint8Array): void;
4380

J
jidong 已提交
4381
取消指定的认证操作。
4382

J
jidong 已提交
4383
**系统接口:** 此接口为系统接口。
4384 4385 4386 4387 4388 4389 4390 4391 4392

**系统能力:** SystemCapability.Account.OsAccount

**需要权限:** ohos.permission.ACCESS_USER_AUTH_INTERNAL

**参数:**

| 参数名    | 类型       | 必填  | 说明                                        |
| ----------| ---------- | ---- | ------------------------------------------ |
J
jidong 已提交
4393 4394 4395 4396 4397 4398 4399 4400
| contextId | Uint8Array | 是   | 指示身份验证上下文ID,此ID动态生成没有具体值。 |

**错误码:**

| 错误码ID | 错误信息            |
| -------- | ------------------ |
| 12300001 | System service exception. |
| 12300002 | Invalid contextId. |
4401

4402
**示例:**
4403
  ```js
J
jidong 已提交
4404
  let userAuth = new account_osAccount.UserAuth();
4405
  let pinAuth: account_osAccount.PINAuth = new account_osAccount.PINAuth();
J
jidong 已提交
4406
  let challenge = new Uint8Array([0]);
J
jidong 已提交
4407
  let contextId = userAuth.auth(challenge, account_osAccount.AuthType.PIN, account_osAccount.AuthTrustLevel.ATL1, {
4408
    onResult: (result: number, extraInfo: account_osAccount.AuthResult) => {
F
fanchenxuan 已提交
4409 4410
      console.log('auth result = ' + result);
      console.log('auth extraInfo = ' + JSON.stringify(extraInfo));
J
jidong 已提交
4411 4412
    }
  });
4413
  try {
J
jidong 已提交
4414
    userAuth.cancelAuth(contextId);
4415 4416 4417
  } catch (e) {
    console.log('cancelAuth exception = ' + JSON.stringify(e));
  }
4418 4419 4420 4421
  ```

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

W
wangyihui 已提交
4422
PIN码认证基类。
4423

J
jidong 已提交
4424
**系统接口:** 此接口为系统接口。
4425

4426 4427 4428 4429
### constructor<sup>8+</sup>

constructor()

W
wangyihui 已提交
4430
创建PIN码认证的实例。
4431

J
jidong 已提交
4432
**系统接口:** 此接口为系统接口。
L
lichenchen 已提交
4433

4434 4435
**系统能力**:SystemCapability.Account.OsAccount

4436
**示例:**  
4437
  ```js
4438
  let pinAuth: account_osAccount.PINAuth = new account_osAccount.PINAuth();
4439 4440
  ```

4441
### registerInputer<sup>8+</sup>
4442

J
jidong 已提交
4443
registerInputer(inputer: IInputer): void;
4444

J
jidong 已提交
4445
注册PIN码输入器。
4446

J
jidong 已提交
4447
**系统接口:** 此接口为系统接口。
4448 4449 4450 4451 4452 4453 4454

**系统能力:** SystemCapability.Account.OsAccount

**需要权限:** ohos.permission.ACCESS_PIN_AUTH

**参数:**

J
jidong 已提交
4455 4456 4457
| 参数名    | 类型                     | 必填 | 说明                      |
| ----------| ----------------------- | --- | -------------------------- |
| inputer   | [IInputer](#iinputer8)  | 是  | PIN码输入器,用于获取PIN码。 |
4458

J
jidong 已提交
4459 4460 4461 4462 4463
**错误码:**

| 错误码ID | 错误信息                     |
| -------- | --------------------------- |
| 12300001 | System service exception. |
C
chennian 已提交
4464
| 12300002 | Invalid inputer. |
J
jidong 已提交
4465 4466
| 12300103 | Inputer already registered. |

4467
**示例:**
4468
  ```js
4469
  let pinAuth: account_osAccount.PINAuth = new account_osAccount.PINAuth();
J
jidong 已提交
4470
  let password = new Uint8Array([0, 0, 0, 0, 0]);
4471 4472
  try {
    let result = pinAuth.registerInputer({
4473
        onGetData: (authSubType: account_osAccount.AuthSubType, callback: account_osAccount.IInputData) => {
W
wangyihui 已提交
4474
          callback.onSetData(authSubType, password);
4475 4476 4477 4478 4479 4480
        }
    });
    console.log('registerInputer result = ' + result);
  } catch (e) {
    console.log('registerInputer exception = ' + JSON.stringify(e));
  }
4481 4482
  ```

4483
### unregisterInputer<sup>8+</sup>
4484 4485 4486

unregisterInputer(): void;

J
jidong 已提交
4487
解注册PIN码输入器。
4488

J
jidong 已提交
4489
**系统接口:** 此接口为系统接口。
4490 4491 4492 4493 4494

**系统能力:** SystemCapability.Account.OsAccount

**需要权限:** ohos.permission.ACCESS_PIN_AUTH

4495
**示例:**
4496
  ```js
4497
  let pinAuth: account_osAccount.PINAuth = new account_osAccount.PINAuth();
4498 4499 4500
  pinAuth.unregisterInputer();
  ```

J
jidong 已提交
4501
## InputerManager <sup>9+</sup>
W
wangyihui 已提交
4502 4503 4504

凭据输入管理器。

J
jidong 已提交
4505
### registerInputer<sup>9+</sup>
W
wangyihui 已提交
4506

J
jidong 已提交
4507
static registerInputer(authType: AuthType, inputer: IInputer): void
W
wangyihui 已提交
4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528

注册凭据输入器。

**系统接口:** 此接口为系统接口。

**系统能力:** SystemCapability.Account.OsAccount

**需要权限:** ohos.permission.ACCESS_USER_AUTH_INTERNAL 或 ohos.permission.MANAGE_USER_IDM

**参数:**

| 参数名    | 类型                     | 必填 | 说明                      |
| ----------| ----------------------- | --- | -------------------------- |
| authType   | [AuthType](#authtype8)  | 是  | 认证类型。 |
| inputer   | [IInputer](#iinputer8)  | 是  | 凭据输入器,用于获取凭据。 |

**错误码:**

| 错误码ID | 错误信息                     |
| -------- | --------------------------- |
| 12300001 | System service exception. |
C
chennian 已提交
4529
| 12300002 | Invalid authType or inputer. |
W
wangyihui 已提交
4530 4531 4532 4533 4534 4535
| 12300103 | The credential inputer has been registered. |
| 12300106 | Unsupported authType. |

**示例:**
  ```js
  let authType = account_osAccount.AuthType.DOMAIN;
4536
  let password: Uint8Array = new Uint8Array([0, 0, 0, 0, 0]);
W
wangyihui 已提交
4537
  try {
J
jidong 已提交
4538
    account_osAccount.InputerManager.registerInputer(authType, {
4539
        onGetData: (authSubType: account_osAccount.AuthSubType, callback: account_osAccount.IInputData) => {
W
wangyihui 已提交
4540 4541 4542 4543 4544 4545 4546 4547 4548
          callback.onSetData(authSubType, password);
        }
    });
    console.log('registerInputer success.');
  } catch (e) {
    console.log('registerInputer exception = ' + JSON.stringify(e));
  }
  ```

J
jidong 已提交
4549
### unregisterInputer<sup>9+</sup>
W
wangyihui 已提交
4550

J
jidong 已提交
4551
static unregisterInputer(authType: AuthType): void
W
wangyihui 已提交
4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576

解注册凭据输入器。

**系统接口:** 此接口为系统接口。

**系统能力:** SystemCapability.Account.OsAccount

**需要权限:** ohos.permission.ACCESS_USER_AUTH_INTERNAL 或 ohos.permission.MANAGE_USER_IDM

**参数:**

| 参数名    | 类型                     | 必填 | 说明                      |
| ----------| ----------------------- | --- | -------------------------- |
| authType   | [AuthType](#authtype8)  | 是  | 认证类型。 |

**错误码:**

| 错误码ID | 错误信息                     |
| -------- | --------------------------- |
| 12300002  | Invalid authType. |

**示例:**
  ```js
  let authType = account_osAccount.AuthType.DOMAIN;
  try {
J
jidong 已提交
4577
    account_osAccount.InputerManager.unregisterInputer(authType);
W
wangyihui 已提交
4578 4579
    console.log('unregisterInputer success.');
  } catch(err) {
C
chennian 已提交
4580
    console.log('unregisterInputer err:' + JSON.stringify(err));
W
wangyihui 已提交
4581 4582 4583
  }
  ```

J
jidong 已提交
4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609
## DomainPlugin<sup>9+</sup>

域插件,提供域帐号认证功能。

**系统接口:** 此接口为系统接口。

### auth<sup>9+</sup>

auth(domainAccountInfo: DomainAccountInfo, credential: Uint8Array, callback: IUserAuthCallback): void

认证指定的域帐号。

**系统接口:** 此接口为系统接口。

**系统能力:** SystemCapability.Account.OsAccount

**参数:**

| 参数名      | 类型                                    | 必填 | 说明             |
| ---------- | --------------------------------------- | ---- | --------------- |
| domainAccountInfo   | [DomainAccountInfo](#domainaccountinfo8)  | 是   | 指示域帐号信息。|
| credential   | Uint8Array  | 是   | 指示域帐号的凭据。|
| callback   | [IUserAuthCallback](#iuserauthcallback8)  | 是   | 指示认证结果回调。|

**示例:**
  ```js
4610
  import { AsyncCallback } from './@ohos.base';
J
jidong 已提交
4611
  let plugin = {
4612 4613
    auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array,
          callback: account_osAccount.IUserAuthCallback) => {
J
jidong 已提交
4614
      // mock authentication
J
jidong 已提交
4615 4616 4617 4618 4619 4620 4621
      // notify authentication result
      callback.onResult(0, {
        token: new Uint8Array([0]),
        remainTimes: 5,
        freezingTime: 0
      });
    },
4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635
    authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                    callback: account_osAccount.IUserAuthCallback) => {},
    authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                    callback: account_osAccount.IUserAuthCallback) => {},
    getAccountInfo: (domain: string, accountName: string,
                    callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {},
    getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                      callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {},
    bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number,
                  callback: AsyncCallback<void>) => {},
    unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {},
    isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                          callback: AsyncCallback<boolean>) => {},
    getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {}
J
jidong 已提交
4636 4637 4638 4639
  }
  account_osAccount.DomainAccountManager.registerPlugin(plugin);
  let userAuth = new account_osAccount.UserAuth();
  let challenge = new Uint8Array([0]);
J
jidong 已提交
4640
  let authType = account_osAccount.AuthType.DOMAIN;
J
jidong 已提交
4641 4642 4643
  let authTrustLevel = account_osAccount.AuthTrustLevel.ATL1;
  try {
    userAuth.auth(challenge, authType, authTrustLevel, {
4644
      onResult: (resultCode: number, authResult: account_osAccount.AuthResult) => {
J
jidong 已提交
4645 4646 4647 4648 4649 4650 4651 4652 4653
          console.log('auth resultCode = ' + resultCode);
          console.log('auth authResult = ' + JSON.stringify(authResult));
      }
    });
  } catch (err) {
    console.log('auth exception = ' + JSON.stringify(err));
  }
  ```

J
jidong 已提交
4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672
### authWithPopup<sup>10+</sup>

authWithPopup(domainAccountInfo: DomainAccountInfo, callback: IUserAuthCallback): void

弹窗认证指定的域帐号。

**系统接口:** 此接口为系统接口。

**系统能力:** SystemCapability.Account.OsAccount

**参数:**

| 参数名      | 类型                                    | 必填 | 说明             |
| ---------- | --------------------------------------- | ---- | --------------- |
| domainAccountInfo   | [DomainAccountInfo](#domainaccountinfo8)  | 是   | 指示域帐号信息。|
| callback   | [IUserAuthCallback](#iuserauthcallback8)  | 是   | 指示认证结果回调。|

**示例:**
  ```js
4673
  import { AsyncCallback } from './@ohos.base';
J
jidong 已提交
4674
  let plugin = {
4675 4676 4677 4678
    auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array,
          callback: account_osAccount.IUserAuthCallback) => {},
    authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                    callback: account_osAccount.IUserAuthCallback) => {
J
jidong 已提交
4679 4680 4681 4682 4683 4684 4685 4686
      // mock authentication
      // notify authentication result
      callback.onResult(0, {
        token: new Uint8Array([0]),
        remainTimes: 5,
        freezingTime: 0
      });
    },
4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698
    authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                    callback: account_osAccount.IUserAuthCallback) => {},
    getAccountInfo: (domain: string, accountName: string,
                    callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {},
    getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                        callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {},
    bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number,
                  callback: AsyncCallback<void>) => {},
    unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {},
    isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                          callback: AsyncCallback<boolean>) => {},
    getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {}
J
jidong 已提交
4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722
  }
  account_osAccount.DomainAccountManager.registerPlugin(plugin)
  ```

### authWithToken<sup>10+</sup>

authWithToken(domainAccountInfo: DomainAccountInfo, token: Uint8Array, callback: IUserAuthCallback): void

使用授权令牌认证指定的域帐号。

**系统接口:** 此接口为系统接口。

**系统能力:** SystemCapability.Account.OsAccount

**参数:**

| 参数名      | 类型                                    | 必填 | 说明             |
| ---------- | --------------------------------------- | ---- | --------------- |
| domainAccountInfo   | [DomainAccountInfo](#domainaccountinfo8)  | 是   | 指示域帐号信息。|
| token   | Uint8Array  | 是   | 指示PIN码或生物识别认证成功时生成的授权令牌。|
| callback   | [IUserAuthCallback](#iuserauthcallback8)  | 是   | 指示认证结果回调。|

**示例:**
  ```js
4723
  import { AsyncCallback } from './@ohos.base';
J
jidong 已提交
4724
  let plugin = {
4725 4726 4727 4728 4729 4730
    auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array,
          callback: account_osAccount.IUserAuthCallback) => {},
    authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                    callback: account_osAccount.IUserAuthCallback) => {},
    authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                    callback: account_osAccount.IUserAuthCallback) => {
J
jidong 已提交
4731 4732 4733 4734 4735 4736 4737 4738
      // mock authentication
      // notify authentication result
      callback.onResult(0, {
        token: new Uint8Array([0]),
        remainTimes: 5,
        freezingTime: 0
      });
    },
4739 4740 4741 4742 4743 4744 4745 4746 4747 4748
    getAccountInfo: (domain: string, accountName: string,
                    callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {},
    getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                        callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {},
    bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number,
                  callback: AsyncCallback<void>) => {},
    unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {},
    isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                          callback: AsyncCallback<boolean>) => {},
    getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {}
J
jidong 已提交
4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772
  }
  account_osAccount.DomainAccountManager.registerPlugin(plugin)
  ```

### getAccountInfo<sup>10+</sup>

getAccountInfo(domain: string, accountName: string, callback: AsyncCallback&lt;DomainAccountInfo&gt;): void

查询指定域帐号的信息。

**系统接口:** 此接口为系统接口。

**系统能力:** SystemCapability.Account.OsAccount

**参数:**

| 参数名      | 类型                                    | 必填 | 说明             |
| ---------- | --------------------------------------- | ---- | --------------- |
| domain   | string  | 是   | 指示帐号所属域。|
| accountName   | string  | 是   | 指示帐号的名称。|
| callback   | AsyncCallback&lt;[DomainAccountInfo](#domainaccountinfo8)&gt; | 是   | 指示查询结果回调。|

**示例:**
  ```js
4773
  import { AsyncCallback, BusinessError } from '@ohos.base';
J
jidong 已提交
4774
  let plugin = {
4775 4776 4777 4778 4779 4780 4781 4782
    auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array,
          callback: account_osAccount.IUserAuthCallback) => {},
    authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                    callback: account_osAccount.IUserAuthCallback) => {},
    authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                    callback: account_osAccount.IUserAuthCallback) => {},
    getAccountInfo: (domain: string, accountName: string,
                    callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {
J
jidong 已提交
4783 4784
      // mock getting account information
      // notify result
4785 4786
      let code: BusinessError
      callback(code, {
J
jidong 已提交
4787 4788
        domain: domain,
        accountName: accountName,
C
chennian 已提交
4789
        accountId: 'xxxx'
J
jidong 已提交
4790 4791
      })
    },
4792 4793 4794 4795 4796 4797 4798 4799
    getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                        callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {},
    bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number,
                  callback: AsyncCallback<void>) => {},
    unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {},
    isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                          callback: AsyncCallback<boolean>) => {},
    getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {}
J
jidong 已提交
4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822
  }
  account_osAccount.DomainAccountManager.registerPlugin(plugin)
  ```

### getAuthStatusInfo<sup>10+</sup>

getAuthStatusInfo(domainAccountInfo: DomainAccountInfo, callback: AsyncCallback&lt;AuthStatusInfo&gt;): void

查询指定域帐号的认证状态信息。

**系统接口:** 此接口为系统接口。

**系统能力:** SystemCapability.Account.OsAccount

**参数:**

| 参数名      | 类型                                    | 必填 | 说明             |
| ---------- | --------------------------------------- | ---- | --------------- |
| domainAccountInfo   | [DomainAccountInfo](#domainaccountinfo8)  | 是   | 指示域帐号信息。|
| callback   | AsyncCallback&lt;[AuthStatusInfo](#authstatusinfo10)&gt; | 是   | 指示查询结果回调。|

**示例:**
  ```js
4823
  import { AsyncCallback, BusinessError } from '@ohos.base';
J
jidong 已提交
4824
  let plugin = {
4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836
    auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array,
          callback: account_osAccount.IUserAuthCallback) => {},
    authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                    callback: account_osAccount.IUserAuthCallback) => {},
    authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                    callback: account_osAccount.IUserAuthCallback) => {},
    getAccountInfo: (domain: string, accountName: string,
                    callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {},
    getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                        callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {
      let code: BusinessError;
      callback(code, {
J
jidong 已提交
4837 4838 4839 4840
        remainTimes: 5,
        freezingTime: 0
      })
    },
4841 4842 4843 4844 4845 4846
    bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number,
                  callback: AsyncCallback<void>) => {},
    unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {},
    isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                          callback: AsyncCallback<boolean>) => {},
    getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {}
J
jidong 已提交
4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869
  }
  account_osAccount.DomainAccountManager.registerPlugin(plugin)
  ```

### bindAccount<sup>10+</sup>

bindAccount(domainAccountInfo: DomainAccountInfo, localId: number, callback: AsyncCallback&lt;void&gt;): void

绑定指定的域帐号。

**系统接口:** 此接口为系统接口。

**系统能力:** SystemCapability.Account.OsAccount

**参数:**

| 参数名      | 类型                                    | 必填 | 说明             |
| ---------- | --------------------------------------- | ---- | --------------- |
| domainAccountInfo   | [DomainAccountInfo](#domainaccountinfo8)  | 是   | 指示域帐号信息。|
| callback   | AsyncCallback&lt;void&gt; | 是   | 指示绑定结果回调。|

**示例:**
  ```js
4870
  import { AsyncCallback, BusinessError } from './@ohos.base';
J
jidong 已提交
4871
  let plugin = {
4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883
    auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array,
          callback: account_osAccount.IUserAuthCallback) => {},
    authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                    callback: account_osAccount.IUserAuthCallback) => {},
    authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                    callback: account_osAccount.IUserAuthCallback) => {},
    getAccountInfo: (domain: string, accountName: string,
                    callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {},
    getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                        callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {},
    bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number,
                  callback: AsyncCallback<void>) => {
J
jidong 已提交
4884 4885
      // mock unbinding operation
      // notify binding result
4886 4887
      let code: BusinessError;
      callback(code)
J
jidong 已提交
4888
    },
4889 4890 4891 4892
    unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {},
    isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                          callback: AsyncCallback<boolean>) => {},
    getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {}
J
jidong 已提交
4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915
  }
  account_osAccount.DomainAccountManager.registerPlugin(plugin)
  ```

### unbindAccount<sup>10+</sup>

unbindAccount(domainAccountInfo: DomainAccountInfo, callback: AsyncCallback&lt;void&gt;): void

解绑指定的域帐号。

**系统接口:** 此接口为系统接口。

**系统能力:** SystemCapability.Account.OsAccount

**参数:**

| 参数名      | 类型                                    | 必填 | 说明             |
| ---------- | --------------------------------------- | ---- | --------------- |
| domainAccountInfo   | [DomainAccountInfo](#domainaccountinfo8)  | 是   | 指示域帐号信息。|
| callback   | AsyncCallback&lt;void&gt; | 是   | 指示绑定结果回调。|

**示例:**
  ```js
4916
  import { AsyncCallback, BusinessError } from './@ohos.base';
J
jidong 已提交
4917
  let plugin = {
4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930
    auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array,
          callback: account_osAccount.IUserAuthCallback) => {},
    authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                    callback: account_osAccount.IUserAuthCallback) => {},
    authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                    callback: account_osAccount.IUserAuthCallback) => {},
    getAccountInfo: (domain: string, accountName: string,
                    callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {},
    getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                        callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {},
    bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number,
                  callback: AsyncCallback<void>) => {},
    unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {
J
jidong 已提交
4931 4932
      // mock unbinding operation
      // notify unbinding result
4933 4934
      let code: BusinessError;
      callback(code)
J
jidong 已提交
4935
    },
4936 4937 4938
    isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                          callback: AsyncCallback<boolean>) => {},
    getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {}
J
jidong 已提交
4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962
  }
  account_osAccount.DomainAccountManager.registerPlugin(plugin)
  ```

### isAccountTokenValid<sup>10+</sup>

isAccountTokenValid(domainAccountInfo: DomainAccountInfo, token: Uint8Array, callback: AsyncCallback&lt;boolean&gt;): void

检查指定的域帐号令牌是否有效。

**系统接口:** 此接口为系统接口。

**系统能力:** SystemCapability.Account.OsAccount

**参数:**

| 参数名      | 类型                                    | 必填 | 说明             |
| ---------- | --------------------------------------- | ---- | --------------- |
| domainAccountInfo   | [DomainAccountInfo](#domainaccountinfo8)  | 是   | 指示域帐号信息。|
| token | Uint8Array | 是 | 指示域帐号令牌。 |
| callback   | AsyncCallback&lt;boolean&gt; | 是   | 指示检查结果回调。|

**示例:**
  ```js
4963
  import { AsyncCallback, BusinessError } from './@ohos.base';
J
jidong 已提交
4964
  let plugin = {
4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979
    auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array,
          callback: account_osAccount.IUserAuthCallback) => {},
    authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                    callback: account_osAccount.IUserAuthCallback) => {},
    authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                    callback: account_osAccount.IUserAuthCallback) => {},
    getAccountInfo: (domain: string, accountName: string,
                    callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {},
    getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                        callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {},
    bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number,
                  callback: AsyncCallback<void>) => {},
    unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {},
    isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                          callback: AsyncCallback<boolean>) => {
J
jidong 已提交
4980 4981
      // mock checking operation
      // notify checking result
4982 4983
      let code: BusinessError
      callback(code, true);
J
jidong 已提交
4984
    },
4985
    getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {}
J
jidong 已提交
4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008
  }
  account_osAccount.DomainAccountManager.registerPlugin(plugin)
  ```

### getAccessToken<sup>10+</sup>

getAccessToken(options: GetDomainAccessTokenOptions, callback: AsyncCallback&lt;Uint8Array&gt;): void

根据指定的选项获取域访问令牌。

**系统接口:** 此接口为系统接口。

**系统能力:** SystemCapability.Account.OsAccount

**参数:**

| 参数名      | 类型                                    | 必填 | 说明             |
| ---------- | --------------------------------------- | ---- | --------------- |
| options | [GetDomainAccessTokenOptions](#getdomainaccesstokenoptions10)  | 是   | 指示获取域访问令牌的选项。|
| callback   | AsyncCallback&lt;Uint8Array&gt; | 是   | 指示结果回调。|

**示例:**
  ```js
5009
  import { AsyncCallback, BusinessError } from './@ohos.base';
J
jidong 已提交
5010
  let plugin = {
5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026
    auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array,
          callback: account_osAccount.IUserAuthCallback) => {},
    authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                    callback: account_osAccount.IUserAuthCallback) => {},
    authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                    callback: account_osAccount.IUserAuthCallback) => {},
    getAccountInfo: (domain: string, accountName: string,
                    callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {},
    getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                        callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {},
    bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number,
                  callback: AsyncCallback<void>) => {},
    unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {},
    isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                          callback: AsyncCallback<boolean>) => {},
    getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {
J
jidong 已提交
5027
      // mock getting operation
5028
      //let token = new Uint8Array([0]);
J
jidong 已提交
5029
      // notify result
5030 5031
      let code: BusinessError
      callback(code, token);
J
jidong 已提交
5032 5033 5034 5035 5036
    }
  }
  account_osAccount.DomainAccountManager.registerPlugin(plugin)
  ```

J
jidong 已提交
5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061
## DomainAccountManager <sup>9+</sup>
域帐号管理器类。

### registerPlugin<sup>9+</sup>

static registerPlugin(plugin: DomainPlugin): void

注册域插件。

**系统接口:** 此接口为系统接口。

**系统能力:** SystemCapability.Account.OsAccount

**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS

**参数:**

| 参数名    | 类型                     | 必填 | 说明                      |
| ----------| ----------------------- | --- | -------------------------- |
| plugin   | [DomainPlugin](#domainplugin9)  | 是  | 指示域插件。 |

**错误码:**

| 错误码ID | 错误信息                     |
| -------- | --------------------------- |
C
chennian 已提交
5062
| 12300201 | The domain plugin has been registered. |
J
jidong 已提交
5063 5064 5065

**示例:**
  ```js
5066
  import { AsyncCallback } from './@ohos.base';
J
jidong 已提交
5067
  let plugin = {
5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083
    auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array,
         callback: account_osAccount.IUserAuthCallback) => {},
    authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                  callback: account_osAccount.IUserAuthCallback) => {},
    authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                  callback: account_osAccount.IUserAuthCallback) => {},
    getAccountInfo: (domain: string, accountName: string,
                   callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {},
    getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                        callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {},
    bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number,
                  callback: AsyncCallback<void>) => {},
    unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {},
    isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                        callback: AsyncCallback<boolean>) => {},
    getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {}
J
jidong 已提交
5084 5085 5086 5087 5088
  }
  try {
    account_osAccount.DomainAccountManager.registerPlugin(plugin);
    console.log('registerPlugin success.');
  } catch(err) {
C
chennian 已提交
5089
    console.log('registerPlugin err:' + JSON.stringify(err));
J
jidong 已提交
5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110
  }
  ```

### unregisterPlugin<sup>9+</sup>

static unregisterPlugin(): void

注销域插件。

**系统接口:** 此接口为系统接口。

**系统能力:** SystemCapability.Account.OsAccount

**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS

**示例:**
  ```js
  try {
    account_osAccount.DomainAccountManager.unregisterPlugin();
    console.log('unregisterPlugin success.');
  } catch(err) {
C
chennian 已提交
5111
    console.log('unregisterPlugin err:' + JSON.stringify(err));
J
jidong 已提交
5112 5113 5114
  }
  ```

J
jidong 已提交
5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138
### auth<sup>10+</sup>

auth(domainAccountInfo: DomainAccountInfo, credential: Uint8Array, callback: IUserAuthCallback): void

认证指定的域帐号。

**系统接口:** 此接口为系统接口。

**系统能力:** SystemCapability.Account.OsAccount

**需要权限:** ohos.permission.ACCESS_USER_AUTH_INTERNAL

**参数:**

| 参数名      | 类型                                    | 必填 | 说明             |
| ---------- | --------------------------------------- | ---- | --------------- |
| domainAccountInfo   | [DomainAccountInfo](#domainaccountinfo8)  | 是   | 指示域帐号信息。|
| credential   | Uint8Array  | 是   | 指示域帐号的凭据。|
| callback   | [IUserAuthCallback](#iuserauthcallback8)  | 是   | 指示认证结果回调。|

**错误码:**

| 错误码ID | 错误信息                     |
| -------- | --------------------------- |
C
chennian 已提交
5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149
| 12300001 | System service exception. |
| 12300002 | Invalid domainAccountInfo or credential. |
| 12300003 | Domain account does not exist. |
| 12300013 | Network exception. |
| 12300101 | Authentication failed. |
| 12300109 | Authentication is canceled. |
| 12300110 | Authentication is locked. |
| 12300111 | Authentication timeout. |
| 12300112 | Authentication service is busy. |
| 12300113 | Authentication service does not exist. |
| 12300114 | Authentication service exception. |
J
jidong 已提交
5150 5151 5152 5153

**示例:**
  ```js
  let domainAccountInfo = {
C
chennian 已提交
5154 5155
    domain: 'CHINA',
    accountName: 'zhangsan'
J
jidong 已提交
5156 5157 5158 5159
  }
  let credential = new Uint8Array([0])
  try {
    account_osAccount.DomainAccountManager.auth(domainAccountInfo, credential, {
5160
      onResult: (resultCode: number, authResult: account_osAccount.AuthResult) => {
J
jidong 已提交
5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191
        console.log('auth resultCode = ' + resultCode);
        console.log('auth authResult = ' + JSON.stringify(authResult));
      }
    });
  } catch (err) {
    console.log('auth exception = ' + JSON.stringify(err));
  }
  ```

### authWithPopup<sup>10+</sup>

authWithPopup(callback: IUserAuthCallback): void

弹框认证指定的域帐号。

**系统接口:** 此接口为系统接口。

**系统能力:** SystemCapability.Account.OsAccount

**需要权限:** ohos.permission.ACCESS_USER_AUTH_INTERNAL

**参数:**

| 参数名      | 类型                                    | 必填 | 说明             |
| ---------- | --------------------------------------- | ---- | --------------- |
| callback   | [IUserAuthCallback](#iuserauthcallback8)  | 是   | 指示认证结果回调。|

**错误码:**

| 错误码ID | 错误信息                     |
| -------- | --------------------------- |
C
chennian 已提交
5192 5193 5194 5195 5196 5197 5198 5199 5200 5201
| 12300001 | System service exception. |
| 12300003 | No domain account is bound. |
| 12300013 | Network exception. |
| 12300101 | Authentication failed. |
| 12300109 | Authentication is canceled. |
| 12300110 | Authentication is locked. |
| 12300111 | Authentication timeout. |
| 12300112 | Authentication service is busy. |
| 12300113 | Authentication service does not exist. |
| 12300114 | Authentication service exception. |
J
jidong 已提交
5202 5203 5204 5205 5206

**示例:**
  ```js
  try {
    account_osAccount.DomainAccountManager.authWithPopup({
5207
      onResult: (resultCode: number, authResult: account_osAccount.AuthResult) => {
J
jidong 已提交
5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239
        console.log('auth resultCode = ' + resultCode);
        console.log('auth authResult = ' + JSON.stringify(authResult));
      }
    })
  } catch (err) {
    console.log('auth exception = ' + JSON.stringify(err));
  }
  ```

### authWithPopup<sup>10+</sup>

authWithPopup(localId: number, callback: IUserAuthCallback): void

弹框认证指定的域帐号。

**系统接口:** 此接口为系统接口。

**系统能力:** SystemCapability.Account.OsAccount

**需要权限:** ohos.permission.ACCESS_USER_AUTH_INTERNAL

**参数:**

| 参数名      | 类型                                    | 必填 | 说明             |
| ---------- | --------------------------------------- | ---- | --------------- |
| localId   | number  | 是   | 指示绑定域帐号的系统帐号的本地标识。|
| callback   | [IUserAuthCallback](#iuserauthcallback8)  | 是   | 指示认证结果回调。|

**错误码:**

| 错误码ID | 错误信息                     |
| -------- | --------------------------- |
C
chennian 已提交
5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250
| 12300001 | System service exception. |
| 12300002 | Invalid localId. |
| 12300003 | No domain account is bound. |
| 12300013 | Network exception. |
| 12300101 | Authentication failed. |
| 12300109 | Authentication is canceled. |
| 12300110 | Authentication is locked. |
| 12300111 | Authentication timeout. |
| 12300112 | Authentication service is busy. |
| 12300113 | Authentication service does not exist. |
| 12300114 | Authentication service exception. |
J
jidong 已提交
5251 5252 5253 5254 5255

**示例:**
  ```js
  try {
    account_osAccount.DomainAccountManager.authWithPopup(100, {
5256
      onResult: (resultCode: number, authResult: account_osAccount.AuthResult) => {
J
jidong 已提交
5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288
        console.log('authWithPopup resultCode = ' + resultCode);
        console.log('authWithPopup authResult = ' + JSON.stringify(authResult));
      }
    })
  } catch (err) {
    console.log('authWithPopup exception = ' + JSON.stringify(err));
  }
  ```

### hasAccount<sup>10+</sup>

hasAccount(domainAccountInfo: DomainAccountInfo, callback: AsyncCallback&lt;boolean&gt;): void

检查是否存在指定的域帐号。

**系统接口:** 此接口为系统接口。

**系统能力:** SystemCapability.Account.OsAccount

**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS

**参数:**

| 参数名      | 类型                                    | 必填 | 说明             |
| ---------- | --------------------------------------- | ---- | --------------- |
| domainAccountInfo   | [DomainAccountInfo](#domainaccountinfo8)  | 是   | 指示域帐号信息。|
| callback   | AsyncCallback&lt;boolean&gt;  | 是   | 指示检查结果回调。|

**错误码:**

| 错误码ID | 错误信息                     |
| -------- | --------------------------- |
C
chennian 已提交
5289 5290 5291
| 12300001 | System service exception. |
| 12300002 | Invalid domainAccountInfo. |
| 12300013 | Network exception. |
J
jidong 已提交
5292 5293 5294

**示例:**
  ```js
5295
  import { BusinessError } from '@ohos.base';
J
jidong 已提交
5296
  let domainAccountInfo = {
C
chennian 已提交
5297 5298
    domain: 'CHINA',
    accountName: 'zhangsan'
J
jidong 已提交
5299 5300
  }
  try {
5301
    account_osAccount.DomainAccountManager.hasAccount(domainAccountInfo, (err: BusinessError, result: boolean) => {
J
jidong 已提交
5302
      if (err) {
C
chennian 已提交
5303
        console.log('call hasAccount failed, error: ' + JSON.stringify(err));
J
jidong 已提交
5304
      } else {
C
chennian 已提交
5305
        console.log('hasAccount result: ' + result);
J
jidong 已提交
5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340
      }
    });
  } catch (err) {
    console.log('hasAccount exception = ' + JSON.stringify(err));
  }
  ```

### hasAccount<sup>10+</sup>

hasAccount(domainAccountInfo: DomainAccountInfo): Promise&lt;boolean&gt;

检查是否存在指定的域帐号。

**系统接口:** 此接口为系统接口。

**系统能力:** SystemCapability.Account.OsAccount

**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS

**参数:**

| 参数名      | 类型                                    | 必填 | 说明             |
| ---------- | --------------------------------------- | ---- | --------------- |
| domainAccountInfo   | [DomainAccountInfo](#domainaccountinfo8)  | 是   | 指示域帐号信息。|

**返回值:**

| 类型                      | 说明                     |
| :------------------------ | ----------------------- |
| Promise&lt;boolean&gt; | Promise对象,返回指定的域帐号是否存在。 |

**错误码:**

| 错误码ID | 错误信息                     |
| -------- | --------------------------- |
C
chennian 已提交
5341 5342 5343
| 12300001 | System service exception. |
| 12300002 | Invalid domainAccountInfo. |
| 12300013 | Network exception. |
J
jidong 已提交
5344 5345 5346

**示例:**
  ```js
5347
  import { BusinessError } from '@ohos.base';
J
jidong 已提交
5348
  let domainAccountInfo = {
C
chennian 已提交
5349 5350
    domain: 'CHINA',
    accountName: 'zhangsan'
J
jidong 已提交
5351 5352
  }
  try {
5353
    account_osAccount.DomainAccountManager.hasAccount(domainAccountInfo).then((result: boolean) => {
C
chennian 已提交
5354
      console.log('hasAccount result: ' + result);
5355
    }).catch((err: BusinessError) => {
C
chennian 已提交
5356
        console.log('call hasAccount failed, error: ' + JSON.stringify(err));
J
jidong 已提交
5357 5358 5359 5360 5361 5362
    });
  } catch (err) {
    console.log('hasAccount exception = ' + JSON.stringify(err));
  }
  ```

J
jidong 已提交
5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392
### updateAccountToken<sup>10+</sup>

updateAccountToken(domainAccountInfo: DomainAccountInfo, token: Uint8Array, callback: AsyncCallback&lt;void&gt;): void;

更新指定域帐号的令牌,空令牌表示目标域帐号的令牌失效。使用callback异步回调。

**系统接口:** 此接口为系统接口。

**系统能力:** SystemCapability.Account.OsAccount

**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS

**参数:**

| 参数名      | 类型                                    | 必填 | 说明             |
| ---------- | --------------------------------------- | ---- | --------------- |
| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8)  | 是   | 指示域帐号信息。|
| token | Uint8Array  | 是   | 指示域帐号的令牌。|
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。如果更新成功,err为null,否则为错误对象。|

**错误码:**

| 错误码ID | 错误信息                     |
| -------- | --------------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid token. |
| 12300003 | Account not found. |

**示例:**
  ```js
5393
  import { BusinessError } from '@ohos.base';
J
jidong 已提交
5394
  let domainAccountInfo = {
C
chennian 已提交
5395 5396 5397
    domain: 'CHINA',
    accountName: 'zhangsan',
    accountId: '123456'
J
jidong 已提交
5398 5399 5400
  }
  let token = new Uint8Array([0])
  try {
5401
    account_osAccount.DomainAccountManager.updateAccountToken(domainAccountInfo, token, (err: BusinessError) => {
J
jidong 已提交
5402
      if (err != null) {
C
chennian 已提交
5403
        console.log('updateAccountToken failed, error: ' + JSON.stringify(err));
J
jidong 已提交
5404
      } else {
C
chennian 已提交
5405
        console.log('updateAccountToken successfully');
J
jidong 已提交
5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447
      }
    })
  } catch (err) {
    console.log('updateAccountToken exception = ' + JSON.stringify(err));
  }
  ```

### updateAccountToken<sup>10+</sup>

updateAccountToken(domainAccountInfo: DomainAccountInfo, token: Uint8Array): Promise&lt;void&gt;

更新指定域帐号的令牌,空令牌表示目标域帐号的令牌失效。使用Promise异步回调。

**系统接口:** 此接口为系统接口。

**系统能力:** SystemCapability.Account.OsAccount

**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS

**参数:**

| 参数名      | 类型                                    | 必填 | 说明             |
| ---------- | --------------------------------------- | ---- | --------------- |
| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8)  | 是   | 指示域帐号信息。|
| token | Uint8Array  | 是   | 指示域帐号的令牌。|

**返回值:**

| 类型                      | 说明                     |
| :------------------------ | ----------------------- |
| Promise&lt;void&gt; | Promise对象,无返回结果的Promise对象。 |

**错误码:**

| 错误码ID | 错误信息                     |
| -------- | --------------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid token. |
| 12300003 | Account not found. |

**示例:**
  ```js
5448
  import { BusinessError } from '@ohos.base';
J
jidong 已提交
5449
  let domainAccountInfo = {
C
chennian 已提交
5450 5451 5452
    domain: 'CHINA',
    accountName: 'zhangsan',
    accountId: '123456'
J
jidong 已提交
5453 5454 5455 5456
  }
  let token = new Uint8Array([0])
  try {
    account_osAccount.DomainAccountManager.updateAccountToken(domainAccountInfo, token).then(() => {
C
chennian 已提交
5457
      console.log('updateAccountToken successfully');
5458
    }).catch((err: BusinessError) => {
C
chennian 已提交
5459
        console.log('updateAccountToken failed, error: ' + JSON.stringify(err));
J
jidong 已提交
5460 5461 5462 5463 5464 5465
    });
  } catch (err) {
    console.log('updateAccountToken exception = ' + JSON.stringify(err));
  }
  ```

5466 5467 5468 5469
## UserIdentityManager<sup>8+</sup>

获取用户身份管理类。

J
jidong 已提交
5470
**系统接口:** 此接口为系统接口。
5471

5472 5473 5474 5475
### constructor<sup>8+</sup>

constructor()

J
jidong 已提交
5476
用户身份管理类的默认构造函数。
5477

J
jidong 已提交
5478
**系统接口:** 此接口为系统接口。
5479

5480 5481
**系统能力**:SystemCapability.Account.OsAccount

5482
**示例:**  
5483
  ```js
J
jidong 已提交
5484
  let userIDM = new account_osAccount.UserIdentityManager();
5485 5486 5487 5488 5489 5490
  ```

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

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

J
jidong 已提交
5491
打开会话,获取挑战值。使用callback异步回调。
5492

J
jidong 已提交
5493
**系统接口:** 此接口为系统接口。
5494 5495 5496 5497 5498 5499 5500

**系统能力:** SystemCapability.Account.OsAccount

**需要权限:** ohos.permission.MANAGE_USER_IDM

**参数:**

J
jidong 已提交
5501 5502 5503
| 参数名    | 类型                             | 必填 | 说明                                                            |
| -------- | -------------------------------- | ---- | -------------------------------------------------------------- |
| callback | AsyncCallback&lt;Uint8Array&gt;  | 是   | 回调函数。如果打开会话成功,err为null,data为挑战值;否则为错误对象。|
5504

J
jidong 已提交
5505 5506 5507 5508 5509 5510
**错误码:**

| 错误码ID | 错误信息                     |
| -------- | --------------------------- |
| 12300001 | System service exception. |

5511
**示例:**
5512
  ```js
5513
  import { BusinessError } from '@ohos.base';
J
jidong 已提交
5514
  let userIDM = new account_osAccount.UserIdentityManager();
5515
  try {
5516
    userIDM.openSession((err: BusinessError, challenge: Uint8Array) => {
5517 5518 5519 5520 5521 5522
        console.log('openSession error = ' + JSON.stringify(err));
        console.log('openSession challenge = ' + JSON.stringify(challenge));
    });
  } catch (e) {
    console.log('openSession exception = ' + JSON.stringify(e));
  }
5523 5524 5525 5526 5527 5528
  ```

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

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

J
jidong 已提交
5529
打开会话,获取挑战值。使用Promise异步回调。
5530

J
jidong 已提交
5531
**系统接口:** 此接口为系统接口。
5532 5533 5534 5535 5536 5537 5538

**系统能力:** SystemCapability.Account.OsAccount

**需要权限:** ohos.permission.MANAGE_USER_IDM

**返回值:**

J
jidong 已提交
5539 5540 5541
| 类型                      | 说明                     |
| :------------------------ | ----------------------- |
| Promise&lt;Uint8Array&gt; | Promise对象,返回挑战值。 |
5542

J
jidong 已提交
5543 5544 5545 5546 5547 5548
**错误码:**

| 错误码ID | 错误信息                     |
| -------- | --------------------------- |
| 12300001 | System service exception. |

5549
**示例:**
5550
  ```js
5551
  import { BusinessError } from '@ohos.base';
J
jidong 已提交
5552
  let userIDM = new account_osAccount.UserIdentityManager();
5553
  try {
5554
    userIDM.openSession().then((challengechallenge: Uint8Array) => {
5555
        console.info('openSession challenge = ' + JSON.stringify(challenge));
5556
    }).catch((err: BusinessError) => {
5557 5558 5559 5560 5561
        console.info('openSession error = ' + JSON.stringify(err));
    });
  } catch (e) {
    console.log('openSession exception = ' + JSON.stringify(e));
  }
5562 5563 5564 5565 5566 5567
  ```

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

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

J
jidong 已提交
5568
添加凭据,添加用户凭据信息,传入凭据添加方法和凭据信息(凭据类型,子类,如果添加用户的非密码凭据,则传入密码身份验证令牌),并获取结果/获取信息。
5569

J
jidong 已提交
5570
**系统接口:** 此接口为系统接口。
5571 5572 5573 5574 5575 5576 5577

**系统能力:** SystemCapability.Account.OsAccount

**需要权限:** ohos.permission.MANAGE_USER_IDM

**参数:**

J
jidong 已提交
5578
| 参数名           | 类型                                 | 必填 | 说明                        |
J
jidong 已提交
5579
| --------------- | ------------------------------------ | --- | ---------------------------- |
J
jidong 已提交
5580 5581
| credentialInfo  | [CredentialInfo](#credentialinfo8)   | 是  | 指示凭据信息。                |
| callback        | [IIdmCallback](#iidmcallback8)       | 是  | 回调对象,返回添加凭据的结果。  |
5582

J
jidong 已提交
5583 5584 5585 5586 5587 5588 5589 5590
**错误码:**

| 错误码ID | 错误信息                     |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid credentialInfo, i.e. authType or authSubType. |
| 12300101 | Token is invalid. |
| 12300106 | Unsupported authType. |
5591 5592 5593
| 12300109 | Operation is canceled. |
| 12300111 | Operation timeout. |
| 12300115 | The number of credentials reaches the upper limit. |
J
jidong 已提交
5594

5595
**示例:**
5596
  ```js
5597 5598 5599
  import { BusinessError } from '@ohos.base';
  let password: Uint8Array = new Uint8Array([0, 0, 0, 0, 0, 0]);
  let pinAuth: account_osAccount.PINAuth = new account_osAccount.PINAuth();
J
jidong 已提交
5600
  pinAuth.registerInputer({
5601
    onGetData: (authSubType: account_osAccount.AuthSubType, callback: account_osAccount.IInputData) => {
W
wangyihui 已提交
5602
      callback.onSetData(authSubType, password);
J
jidong 已提交
5603 5604
    }
  });
5605
  let credentialInfo: account_osAccount.CredentialInfo = {
J
jidong 已提交
5606 5607 5608 5609 5610
    credType: account_osAccount.AuthType.PIN,
    credSubType: account_osAccount.AuthSubType.PIN_SIX,
    token: null
  };
  let userIDM = new account_osAccount.UserIdentityManager();
5611
  userIDM.openSession((err: BusinessError, challenge: Uint8Array) => {
5612
    try {
J
jidong 已提交
5613
    userIDM.addCredential(credentialInfo, {
5614
      onResult: (result: number, extraInfo: account_osAccount.RequestResult) => {
W
wangyihui 已提交
5615 5616
        console.log('addCredential result = ' + result);
        console.log('addCredential extraInfo = ' + extraInfo);
5617
      }
J
jidong 已提交
5618
    });
5619
    } catch (e) {
W
wangyihui 已提交
5620
      console.log('addCredential exception = ' + JSON.stringify(e));
5621
    }
J
jidong 已提交
5622
  });
5623 5624 5625 5626 5627 5628
  ```

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

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

J
jidong 已提交
5629
更新凭据。使用callback异步回调。
5630

J
jidong 已提交
5631
**系统接口:** 此接口为系统接口。
5632 5633 5634 5635 5636 5637 5638

**系统能力:** SystemCapability.Account.OsAccount

**需要权限:** ohos.permission.MANAGE_USER_IDM

**参数:**

J
jidong 已提交
5639 5640 5641 5642
| 参数名           | 类型                                  | 必填 | 说明                     |
| --------------- | ------------------------------------- | --- | ------------------------- |
| credentialInfo  | [CredentialInfo](#credentialinfo8)    | 是  | 指示凭据信息。             |
| callback        | [IIdmCallback](#iidmcallback8)        | 是  | 回调对象,返回更新凭据的结果。 |
5643

J
jidong 已提交
5644 5645 5646 5647 5648 5649 5650
**错误码:**

| 错误码ID | 错误信息                     |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid credentialInfo, i.e. authType or authSubType or token. |
| 12300101 | Token is invalid. |
5651
| 12300102 | Credential not enrolled.|
J
jidong 已提交
5652
| 12300106 | Unsupported authType. |
5653 5654
| 12300109 | Operation is canceled. |
| 12300111 | Operation timeout. |
J
jidong 已提交
5655

5656
**示例:**
5657
  ```js
5658
  import { BusinessError } from '@ohos.base';
J
jidong 已提交
5659
  let userIDM = new account_osAccount.UserIdentityManager();
5660 5661 5662
  let userAuth: account_osAccount.UserAuth = new account_osAccount.UserAuth();
  let pinAuth: account_osAccount.PINAuth = new account_osAccount.PINAuth();
  let password: Uint8Array = new Uint8Array([0, 0, 0, 0, 0, 0]);
J
jidong 已提交
5663 5664 5665 5666 5667 5668
  let credentialInfo = {
    credType: account_osAccount.AuthType.PIN,
    credSubType: account_osAccount.AuthSubType.PIN_SIX,
    token: null
  };
  pinAuth.registerInputer({
5669
    onGetData: (authSubType: account_osAccount.AuthSubType, callback: account_osAccount.IInputData) => {
W
wangyihui 已提交
5670
      callback.onSetData(authSubType, password);
J
jidong 已提交
5671 5672
    }
  });
5673
  userIDM.openSession((err: BusinessError, challenge: Uint8Array) => {
J
jidong 已提交
5674
    userAuth.auth(challenge, credentialInfo.credType, account_osAccount.AuthTrustLevel.ATL1, {
5675
      onResult: (result: number, extraInfo: account_osAccount.AuthResult) => {
J
jidong 已提交
5676 5677 5678 5679
        if (result != account_osAccount.ResultCode.SUCCESS) {
          return;
        }
        credentialInfo.token = extraInfo.token;
5680 5681
        try {
          userIDM.updateCredential(credentialInfo, {
5682
            onResult: (result: number, extraInfo: account_osAccount.RequestResult) => {
5683 5684 5685 5686 5687 5688 5689
                console.log('updateCredential result = ' + result);
                console.log('updateCredential extraInfo = ' + extraInfo);
            }
          });
        } catch (e) {
          console.log('updateCredential exception = ' + JSON.stringify(e));
        }
5690
      }
J
jidong 已提交
5691 5692
    });
  });
5693 5694 5695 5696 5697 5698
  ```

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

closeSession(): void;

J
jidong 已提交
5699
关闭会话,结束IDM操作。
5700

J
jidong 已提交
5701
**系统接口:** 此接口为系统接口。
5702 5703 5704 5705 5706

**系统能力:** SystemCapability.Account.OsAccount

**需要权限:** ohos.permission.MANAGE_USER_IDM

5707
**示例:**
5708
  ```js
J
jidong 已提交
5709
  let userIDM = new account_osAccount.UserIdentityManager();
5710 5711 5712 5713 5714
  userIDM.closeSession();
  ```

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

5715
cancel(challenge: Uint8Array): void;
5716 5717 5718

根据挑战值取消条目。

J
jidong 已提交
5719
**系统接口:** 此接口为系统接口。
5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730

**系统能力:** SystemCapability.Account.OsAccount

**需要权限:** ohos.permission.MANAGE_USER_IDM

**参数:**

| 参数名    | 类型        | 必填 | 说明   |
| -------- | ----------- | ---- | ----- |
| challenge | Uint8Array | 是   | 挑战值。 |

J
jidong 已提交
5731 5732 5733 5734 5735 5736
**错误码:**

| 错误码ID | 错误信息            |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid challenge. |
5737

5738
**示例:**
5739
  ```js
J
jidong 已提交
5740
  let userIDM = new account_osAccount.UserIdentityManager();
5741
  let challenge: Uint8Array = new Uint8Array([0]);
5742 5743 5744
  try {
    userIDM.cancel(challenge);
  } catch(err) {
C
chennian 已提交
5745
    console.log('cancel err:' + JSON.stringify(err));
5746
  }
5747 5748 5749 5750 5751 5752 5753 5754
  ```

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

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

删除具有身份验证令牌的用户,使用callback方式异步返回结果。

J
jidong 已提交
5755
**系统接口:** 此接口为系统接口。
5756 5757 5758 5759 5760 5761 5762

**系统能力:** SystemCapability.Account.OsAccount

**需要权限:** ohos.permission.MANAGE_USER_IDM

**参数:**

J
jidong 已提交
5763 5764 5765 5766
| 参数名    | 类型                           | 必填 | 说明                      |
| -------- | ------------------------------ | --- | ------------------------- |
| token    | Uint8Array                     | 是  | 身份验证令牌。             |
| callback | [IIdmCallback](#iidmcallback8) | 是  | 回调对象,返回删除用户的结果。|
5767

J
jidong 已提交
5768 5769 5770 5771 5772 5773 5774
**错误码:**

| 错误码ID | 错误信息        |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300101 | Token is invalid. |

5775
**示例:**
5776
  ```js
J
jidong 已提交
5777
  let userIDM = new account_osAccount.UserIdentityManager();
5778
  let token: Uint8Array = new Uint8Array([0]);
5779 5780
  try {
    userIDM.delUser(token, {
5781
      onResult: (result: number, extraInfo: account_osAccount.RequestResult) => {
5782 5783 5784 5785 5786 5787 5788
        console.log('delUser result = ' + result);
        console.log('delUser extraInfo = ' + JSON.stringify(extraInfo));
      }
    });
  } catch (e) {
    console.log('delUser exception = ' + JSON.stringify(e));
  }
5789 5790 5791 5792 5793 5794
  ```

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

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

J
jidong 已提交
5795
删除用户凭据信息。
5796

J
jidong 已提交
5797
**系统接口:** 此接口为系统接口。
5798 5799 5800 5801 5802 5803 5804 5805

**系统能力:** SystemCapability.Account.OsAccount

**需要权限:** ohos.permission.MANAGE_USER_IDM

**参数:**

| 参数名           | 类型                                            | 必填 | 说明                      |
J
jidong 已提交
5806 5807 5808 5809
| --------------- | ----------------------------------- | --- | ---------------------------|
| credentialId    | Uint8Array                          | 是  | 凭证索引。                  |
| token           | Uint8Array                          | 是  | 身份验证令牌。               |
| callback        | [IIdmCallback](#iidmcallback8)      | 是  | 回调对象,返回删除凭据的结果。 |
5810

J
jidong 已提交
5811 5812 5813 5814 5815 5816 5817
**错误码:**

| 错误码ID | 错误信息             |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid credentialId. |
| 12300101 | Token is invalid. |
5818
| 12300102 | Credential not enrolled. |
J
jidong 已提交
5819

5820
**示例:**
5821
  ```js
J
jidong 已提交
5822
  let userIDM = new account_osAccount.UserIdentityManager();
5823 5824
  let credentialId: Uint8Array = new Uint8Array([0]);
  let token: Uint8Array = new Uint8Array([0]);
5825 5826
  try {
    userIDM.delCred(credentialId, token, {
5827
      onResult: (result: number, extraInfo: account_osAccount.RequestResult) => {
5828 5829 5830 5831 5832 5833 5834
          console.log('delCred result = ' + result);
          console.log('delCred extraInfo = ' + JSON.stringify(extraInfo));
      }
    });
  } catch (e) {
    console.log('delCred exception = ' + JSON.stringify(e));
  }
5835 5836 5837 5838
  ```

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

5839
getAuthInfo(callback: AsyncCallback&lt;Array&lt;EnrolledCredInfo&gt;&gt;): void;
5840

J
jidong 已提交
5841
获取认证信息。使用callback异步回调。
5842

J
jidong 已提交
5843
**系统接口:** 此接口为系统接口。
5844 5845 5846

**系统能力:** SystemCapability.Account.OsAccount

5847
**需要权限:** ohos.permission.USE_USER_IDM
5848 5849 5850

**参数:**

J
jidong 已提交
5851 5852
| 参数名    | 类型                                                                     | 必填 | 说明                                                 |
| -------- | ------------------------------------------------------------------------ | ---- | --------------------------------------------- |
J
jidong 已提交
5853
| callback | AsyncCallback&lt;Array&lt;[EnrolledCredInfo](#enrolledcredinfo8)&gt;&gt; | 是   | 回调函数。如果成功,err为null,data为当前用户的所有已注册凭据信息;否则为错误对象。|
5854

J
jidong 已提交
5855 5856 5857 5858 5859
**错误码:**

| 错误码ID | 错误信息               |
| -------- | --------------------- |
| 12300001 | System service exception. |
5860
| 12300102 | Credential not enrolled. |
5861

5862
**示例:**
5863
  ```js
5864
  import { BusinessError } from '@ohos.base';
J
jidong 已提交
5865
  let userIDM = new account_osAccount.UserIdentityManager();
5866
  try {
5867
    userIDM.getAuthInfo((err: BusinessError, result: account_osAccount.EnrolledCredInfo[]) => {
5868 5869 5870 5871 5872 5873
      console.log('getAuthInfo err = ' + JSON.stringify(err));
      console.log('getAuthInfo result = ' + JSON.stringify(result));
    });
  } catch (e) {
    console.log('getAuthInfo exception = ' + JSON.stringify(e));
  }
5874 5875 5876 5877 5878 5879
  ```

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

getAuthInfo(authType: AuthType, callback: AsyncCallback&lt;Array&lt;EnrolledCredInfo&gt;&gt;): void;

J
jidong 已提交
5880
获取指定类型的认证信息。使用callback异步回调。
5881

J
jidong 已提交
5882
**系统接口:** 此接口为系统接口。
5883 5884 5885

**系统能力:** SystemCapability.Account.OsAccount

5886
**需要权限:** ohos.permission.USE_USER_IDM
5887 5888 5889 5890 5891 5892

**参数:**

| 参数名    | 类型                                               | 必填 | 说明                                                |
| -------- | -------------------------------------------------- | ---- | -------------------------------------------------- |
| authType | [AuthType](#authtype8) | 是   | 认证类型。                                          |
J
jidong 已提交
5893 5894 5895 5896 5897
| callback | AsyncCallback&lt;Array&lt;[EnrolledCredInfo](#enrolledcredinfo8)&gt;&gt; | 是   | 回调函数,如果获取成功,err为null,data为当前用户指定类型的所有已注册凭据信息;否则为错误对象。 |

**错误码:**

| 错误码ID | 错误信息               |
J
jidong 已提交
5898 5899 5900
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid authType. |
5901
| 12300102 | Credential not enrolled. |
5902

5903
**示例:**
5904
  ```js
5905
  import { BusinessError } from '@ohos.base';
J
jidong 已提交
5906
  let userIDM = new account_osAccount.UserIdentityManager();
5907
  try {
5908 5909
    userIDM.getAuthInfo(account_osAccount.AuthType.PIN,
      (err: BusinessError, result: account_osAccount.EnrolledCredInfo[]) => {
5910 5911 5912 5913 5914 5915
      console.log('getAuthInfo err = ' + JSON.stringify(err));
      console.log('getAuthInfo result = ' + JSON.stringify(result));
    });
  } catch (e) {
    console.log('getAuthInfo exception = ' + JSON.stringify(e));
  }
5916 5917 5918 5919 5920 5921
  ```

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

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

J
jidong 已提交
5922
获取认证信息。使用Promise异步回调。
5923

J
jidong 已提交
5924
**系统接口:** 此接口为系统接口。
5925 5926 5927

**系统能力:** SystemCapability.Account.OsAccount

5928
**需要权限:** ohos.permission.USE_USER_IDM
5929 5930 5931 5932 5933

**参数:**

| 参数名    | 类型                                | 必填 | 说明      |
| -------- | ----------------------------------- | ---- | -------- |
5934
| authType | [AuthType](#authtype8)              | 否   | 认证类型,默认为空,表示查询所有认证类型的信息。|
5935 5936 5937

**返回值:**

J
jidong 已提交
5938
| 类型                                         | 说明                                                                     |
J
jidong 已提交
5939
| :------------------------------------------- | :----------------------------------------------------------------------- |
J
jidong 已提交
5940 5941 5942 5943 5944
| Promise&lt;Array&lt;[EnrolledCredInfo](#enrolledcredinfo8)&gt;&gt; | Promise对象,返回当前用户指定类型的所有已注册凭据信息。|

**错误码:**

| 错误码ID | 错误信息               |
J
jidong 已提交
5945 5946 5947
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid authType. |
5948
| 12300102 | Credential not enrolled. |
5949

5950
**示例:**
5951
  ```js
5952
  import { BusinessError } from '@ohos.base';
J
jidong 已提交
5953
  let userIDM = new account_osAccount.UserIdentityManager();
5954
  try {
5955
    userIDM.getAuthInfo(account_osAccount.AuthType.PIN).then((result: account_osAccount.EnrolledCredInfo[]) => {
5956
      console.log('getAuthInfo result = ' + JSON.stringify(result))
5957
    }).catch((err: BusinessError) => {
5958 5959 5960 5961 5962
      console.log('getAuthInfo error = ' + JSON.stringify(err));
    });
  } catch (e) {
    console.log('getAuthInfo exception = ' + JSON.stringify(e));
  }
5963 5964 5965 5966 5967 5968
  ```

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

密码数据回调。

J
jidong 已提交
5969
**系统接口:** 此接口为系统接口。
5970

5971 5972
### onSetData<sup>8+</sup>

W
wangyihui 已提交
5973
onSetData: (authSubType: AuthSubType, data: Uint8Array) => void;
5974

J
jidong 已提交
5975
**系统接口:** 此接口为系统接口。
5976

5977 5978 5979 5980 5981 5982 5983 5984
通知设置数据。

**系统能力:** SystemCapability.Account.OsAccount

**参数:**

| 参数名      | 类型                                     | 必填 | 说明                                            |
| ---------- | ---------------------------------------- | ---- | ----------------------------------------------- |
W
wangyihui 已提交
5985
| authSubType | [AuthSubType](#authsubtype8)             | 是   | 用于认证的凭据子类型。                            |
5986 5987
| data       | Uint8Array                               | 是   | 要设置的数据是凭据,用来在认证、添加、修改凭据操作。 |

C
chennian 已提交
5988 5989 5990 5991 5992 5993
**错误码:**

| 错误码ID | 错误信息               |
| -------- | ------------------- |
| 12300002 | Invalid pinSubType. |

5994
**示例:**
5995
  ```js
5996 5997
  let password: Uint8Array = new Uint8Array([0, 0, 0, 0, 0, 0]);
  let passwordNumber: Uint8Array = new Uint8Array([1, 2, 3, 4]);
J
jidong 已提交
5998
  let inputer = {
5999
    onGetData: (authSubType: account_osAccount.AuthSubType, callback: account_osAccount.IInputData) => {
W
wangyihui 已提交
6000 6001
        if (authSubType == account_osAccount.AuthSubType.PIN_NUMBER) {
          callback.onSetData(authSubType, passwordNumber);
J
jidong 已提交
6002
        } else {
W
wangyihui 已提交
6003
          callback.onSetData(authSubType, password);
J
jidong 已提交
6004 6005 6006
        }
    }
  };
6007 6008 6009 6010
  ```

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

W
wangyihui 已提交
6011
凭据输入器回调。
6012

J
jidong 已提交
6013
**系统接口:** 此接口为系统接口。
6014

6015 6016
### onGetData<sup>8+</sup>

W
wangyihui 已提交
6017
onGetData: (authSubType: AuthSubType, callback: IInputData) => void;
6018 6019 6020

通知获取数据。

J
jidong 已提交
6021
**系统接口:** 此接口为系统接口。
6022

6023 6024 6025 6026 6027 6028
**系统能力:** SystemCapability.Account.OsAccount

**参数:**

| 参数名      | 类型                                    | 必填 | 说明             |
| ---------- | --------------------------------------- | ---- | --------------- |
6029
| callback   | [IInputData](#iinputdata8)  | 是   | 指示密码数据回调。|
6030

6031
**示例:**
6032
  ```js
6033 6034
  let password: Uint8Array = new Uint8Array([0, 0, 0, 0, 0, 0]);
  let passwordNumber: Uint8Array = new Uint8Array([1, 2, 3, 4]);
J
jidong 已提交
6035
  let inputer = {
6036
    onGetData: (authSubType: account_osAccount.AuthSubType, callback: account_osAccount.IInputData) => {
W
wangyihui 已提交
6037 6038
        if (authSubType == account_osAccount.AuthSubType.PIN_NUMBER) {
          callback.onSetData(authSubType, passwordNumber);
J
jidong 已提交
6039
        } else {
W
wangyihui 已提交
6040
          callback.onSetData(authSubType, password);
J
jidong 已提交
6041 6042 6043
        }
    }
  };
6044
  let pinAuth: account_osAccount.PINAuth = new account_osAccount.PINAuth();
J
jidong 已提交
6045
  let result = pinAuth.registerInputer(inputer);
F
fanchenxuan 已提交
6046
  console.log('registerInputer result: ' + result);
6047 6048 6049 6050
  ```

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

J
jidong 已提交
6051
表示用户认证回调类。
6052

J
jidong 已提交
6053
**系统接口:** 此接口为系统接口。
6054

6055 6056 6057 6058
### onResult<sup>8+</sup>

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

J
jidong 已提交
6059
身份认证结果回调函数,返回结果码和认证结果信息。
6060

J
jidong 已提交
6061
**系统接口:** 此接口为系统接口。
6062

6063 6064 6065 6066 6067 6068 6069
**系统能力:** SystemCapability.Account.OsAccount

**参数:**

| 参数名     | 类型                                    | 必填 | 说明                 |
| --------- | --------------------------------------- | ---- | ------------------- |
| result    | number                                   | 是   | 表示身份认证结果代码。|
6070
| extraInfo | [AuthResult](#authresult8)  | 是   | 表示不同情况下的具体信息,如果认证通过,则在extrainfo中返回认证令牌,如果身份验证失败,则在extrainfo中返回剩余的身份验证时间,如果身份验证执行器被锁定,冻结时间将在extrainfo中返回。|
6071

6072
**示例:**
6073
  ```js
J
jidong 已提交
6074
  let authCallback = {
6075
    onResult: (result: account_osAccount.AuthSubType, extraInfo: account_osAccount.IInputData) => {
F
fanchenxuan 已提交
6076 6077
      console.log('auth result = ' + result);
      console.log('auth extraInfo = ' + JSON.stringify(extraInfo));
J
jidong 已提交
6078 6079
    }
  };
6080 6081 6082 6083 6084 6085
  ```

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

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

J
jidong 已提交
6086
身份认证信息获取回调函数。
6087

J
jidong 已提交
6088
**系统接口:** 此接口为系统接口。
6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099

**系统能力:** SystemCapability.Account.OsAccount

**参数:**

| 参数名    | 类型     | 必填 | 说明                           |
| --------- | ------- | ---- | ----------------------------- |
| module    | number  | 是   | 指示用于身份验证的执行器类型。   |
| acquire   | number  | 是   | 指示不同身份验证执行器的tip代码。|
| extraInfo | any     | 是   | 保留参数。                     |

6100
**示例:**
6101
  ```js
J
jidong 已提交
6102
  let authCallback = {
6103
    onResult: (result: account_osAccount.AuthSubType, extraInfo: account_osAccount.IInputData) => {
F
fanchenxuan 已提交
6104 6105
      console.log('auth result = ' + result)
      console.log('auth extraInfo = ' + JSON.stringify(extraInfo));
J
jidong 已提交
6106
    },
6107
    onAcquireInfo: (module: number, acquire: number, extraInfo: account_osAccount.RequestResult) => {
F
fanchenxuan 已提交
6108 6109
      console.log('auth module = ' + module);
      console.log('auth acquire = ' + acquire);
J
jidong 已提交
6110 6111 6112
      console.info('auth extraInfo = ' + JSON.stringify(extraInfo));
    }
  };
6113 6114 6115 6116
  ```

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

J
jidong 已提交
6117
表示身份管理回调类。
6118

J
jidong 已提交
6119
**系统接口:** 此接口为系统接口。
6120

6121 6122
### onResult<sup>8+</sup>

6123
onResult: (result: number, extraInfo: RequestResult) => void;
6124

J
jidong 已提交
6125
身份管理操作结果回调函数,返回结果码和请求结果信息。
6126

J
jidong 已提交
6127
**系统接口:** 此接口为系统接口。
6128 6129 6130 6131 6132 6133 6134 6135

**系统能力:** SystemCapability.Account.OsAccount

**参数:**

| 参数名     | 类型                                    | 必填 | 说明                     |
| --------- | --------------------------------------- | ---- | ----------------------- |
| result    | number                                  | 是   | 表示身份认证结果代码。    |
6136
| extraInfo | [RequestResult](#requestresult8)  | 是   | 针对不同情况传递具体信息。|
6137

6138
**示例:**
6139
  ```js
F
fanchenxuan 已提交
6140
  let idmCallback = {
6141
    onResult: (result: number, extraInfo: account_osAccount.RequestResult) => {
F
fanchenxuan 已提交
6142
      console.log('callback result = ' + result)
J
jidong 已提交
6143 6144 6145
      console.info('callback extraInfo = ' + JSON.stringify(extraInfo));
    }
  };
6146 6147 6148 6149 6150 6151
  ```

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

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

J
jidong 已提交
6152
身份管理信息获取回调函数。
6153

J
jidong 已提交
6154
**系统接口:** 此接口为系统接口。
6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165

**系统能力:** SystemCapability.Account.OsAccount

**参数:**

| 参数名    | 类型     | 必填 | 说明                           |
| --------- | ------- | ---- | ----------------------------- |
| module    | number  | 是   | 指示用于身份验证的执行器类型。   |
| acquire   | number  | 是   | 指示不同身份验证执行器的tip代码。|
| extraInfo | any     | 是   | 保留参数。                     |

6166
**示例:**
6167
  ```js
J
jidong 已提交
6168
  let idmCallback = {
6169
    onResult: (result: number, extraInfo: Object) => {
F
fanchenxuan 已提交
6170 6171
      console.log('callback result = ' + result)
      console.log('callback onResult = ' + JSON.stringify(extraInfo));
J
jidong 已提交
6172
    },
6173
    onAcquireInfo: (module: number, acquire: number, extraInfo: Object) => {
F
fanchenxuan 已提交
6174 6175
      console.log('callback module = ' + module);
      console.log('callback acquire = ' + acquire);
J
jidong 已提交
6176 6177 6178
      console.log('callback onacquireinfo = ' + JSON.stringify(extraInfo));
    }
  };
6179 6180 6181 6182 6183 6184
  ```

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

提供获取属性请求的信息。

J
jidong 已提交
6185
**系统接口:** 此接口为系统接口。
6186

6187 6188
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount

6189
| 名称    | 类型                                                          | 必填   | 说明                   |
6190
| -------- | ------------------------------------------------------------- | ----- | ----------------------- |
6191 6192
| authType | [AuthType](#authtype8)                            | 是    | 身份验证凭据类型。        |
| keys     | Array&lt;[GetPropertyType](#getpropertytype8)&gt; | 是    | 指示要获取的属性类型数组。 |
6193 6194 6195 6196 6197

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

提供设置属性请求的信息。

J
jidong 已提交
6198
**系统接口:** 此接口为系统接口。
6199

6200 6201
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount

6202
| 名称    | 类型                                             | 必填   | 说明                 |
6203
| -------- | ------------------------------------------------ | ----- | -------------------- |
6204 6205
| authType | [AuthType](#authtype8)               | 是    | 身份验证凭据类型。     |
| key     | [SetPropertyType](#setpropertytype8) | 是    | 指示要设置的属性类型。 |
6206 6207 6208 6209 6210 6211
| setInfo  | Uint8Array                                       | 是    | 指示要设置的信息。     |

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

提供执行器的属性。

J
jidong 已提交
6212
**系统接口:** 此接口为系统接口。
6213

6214 6215
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount

6216 6217 6218 6219 6220 6221 6222 6223
| 名称         | 类型                         |  可读 | 可写 | 说明              |
| ------------ | ---------------------------- | ----- | -----|----------------- |
| result       | number                       | 是    | 是   | 指示结果。         |
| authSubType  | [AuthSubType](#authsubtype8) | 是    | 是   | 指示认证凭据子类型。|
| remainTimes  | number                       | 是    | 是   | 指示剩余次数。     |
| freezingTime | number                       | 是    | 是   | 指示冻结时间。     |
| enrollmentProgress<sup>10+</sup> | string   | 是    | 是   | 指示录入进度,默认为空。 |
| sensorInfo<sup>10+</sup> | string           | 是    | 是   | 指示传感器信息,默认为空。 |
6224 6225 6226

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

J
jidong 已提交
6227
表示认证结果的信息。
6228

J
jidong 已提交
6229
**系统接口:** 此接口为系统接口。
6230

6231 6232
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount

6233
| 名称        | 类型        | 必填   | 说明              |
6234
| ------------ | ----------- | ----- | ----------------- |
6235 6236 6237
| token        | Uint8Array  | 否    | 指示认证令牌,默认为空。      |
| remainTimes  | number      | 否    | 指示剩余次数,默认为空。      |
| freezingTime | number      | 否    | 指示冻结时间,默认为空。      |
6238 6239 6240

## CredentialInfo<sup>8+</sup>

J
jidong 已提交
6241
表示凭证信息。
6242

J
jidong 已提交
6243
**系统接口:** 此接口为系统接口。
6244

6245 6246
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount

6247
| 名称        | 类型                                     | 必填   | 说明              |
6248
| ------------ | ---------------------------------------- | ----- | ----------------- |
6249 6250
| credType     | [AuthType](#authtype8)       | 是    | 指示凭据类型。     |
| credSubType  | [AuthSubType](#authsubtype8) | 是    | 指示凭据子类型。   |
J
jidong 已提交
6251
| token        | Uint8Array                           | 是    | 指示认证令牌。     |
6252 6253 6254

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

J
jidong 已提交
6255
表示请求结果的信息。
6256

J
jidong 已提交
6257
**系统接口:** 此接口为系统接口。
6258

6259 6260
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount

6261
| 名称        | 类型        | 必填   | 说明              |
6262
| ------------ | ----------- | ----- | ----------------- |
6263
| credentialId | Uint8Array  | 否    | 指示凭据索引,默认为空。      |
6264 6265 6266

## EnrolledCredInfo<sup>8+</sup>

J
jidong 已提交
6267
表示已注册凭据的信息。
6268

J
jidong 已提交
6269
**系统接口:** 此接口为系统接口。
6270

6271 6272
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount

6273
| 名称        | 类型                                     | 必填   | 说明              |
6274 6275
| ------------ | ---------------------------------------- | ----- | ------------------- |
| credentialId | Uint8Array                               | 是    | 指示凭据索引。       |
6276 6277
| authType     | [AuthType](#authtype8)       | 是    | 指示认证凭据类型。   |
| authSubType  | [AuthSubType](#authsubtype8) | 是    | 指示认证凭据子类型。 |
6278 6279 6280 6281
| templateId   | Uint8Array                               | 是    | 指示凭据模板ID。     |

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

J
jidong 已提交
6282
表示要获取的属性类型的枚举。
6283

J
jidong 已提交
6284
**系统接口:** 此接口为系统接口。
6285

6286 6287
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount

6288
| 名称           | 值 | 说明      |
6289 6290 6291 6292
| ------------- | ------ | --------- |
| AUTH_SUB_TYPE | 1      | 认证子类型。 |
| REMAIN_TIMES  | 2      | 剩余时间。   |
| FREEZING_TIME | 3      | 冻结时间。   |
6293 6294
| ENROLLMENT_PROGRESS<sup>10+</sup> | 4      | 录入进度。   |
| SENSOR_INFO<sup>10+</sup> | 5      | 传感器信息。   |
6295 6296 6297

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

J
jidong 已提交
6298
表示要设置的属性类型的枚举。
6299

J
jidong 已提交
6300
**系统接口:** 此接口为系统接口。
6301

6302 6303
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount

6304
| 名称           | 值 | 说明        |
6305 6306 6307 6308 6309
| -------------- | ----- | ----------- |
| INIT_ALGORITHM | 1     | 初始化算法。 |

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

J
jidong 已提交
6310
表示身份验证的凭据类型的枚举。
6311

J
jidong 已提交
6312
**系统接口:** 此接口为系统接口。
6313

6314 6315
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount

6316
| 名称  | 值 | 说明             |
6317
| ----- | ----- | ---------------- |
W
wangyihui 已提交
6318 6319 6320
| PIN   | 1     | 表示PIN认证类型。 |
| FACE  | 2     | 表示脸部认证类型。|
| FINGERPRINT<sup>10+</sup>   | 4     | 表示指纹认证类型。 |
Z
zhouyan 已提交
6321
| DOMAIN<sup>9+</sup>  | 1024     | 表示域认证类型。|
6322 6323 6324

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

J
jidong 已提交
6325
表示用于认证的凭据子类型的枚举。
6326

J
jidong 已提交
6327
**系统接口:** 此接口为系统接口。
6328

6329 6330
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount

6331
| 名称       | 值 | 说明               |
6332 6333 6334 6335
| ---------- | ----- | ------------------ |
| PIN_SIX    | 10000 | 表示6位凭证。       |
| PIN_NUMBER | 10001 | 表示自定义数字凭证。 |
| PIN_MIXED  | 10002 | 表示自定义混合凭据。 |
W
wangyihui 已提交
6336 6337
| FACE_2D    | 20000 | 表示2D 人脸凭证。   |
| FACE_3D    | 20001 | 表示3D 人脸凭证。   |
6338 6339 6340
| FINGERPRINT_CAPACITIVE<sup>10+</sup>    | 30000 | 表示电容式指纹。   |
| FINGERPRINT_OPTICAL<sup>10+</sup>    | 30001 | 表示光学指纹。   |
| FINGERPRINT_ULTRASONIC<sup>10+</sup>    | 30002 | 表示超声波指纹。   |
Z
zhouyan 已提交
6341
| DOMAIN_MIXED<sup>9+</sup>    | 10240001 | 表示域认证混合凭证。   |
6342 6343 6344

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

J
jidong 已提交
6345
表示认证结果的受信任级别的枚举。
6346

J
jidong 已提交
6347
**系统接口:** 此接口为系统接口。
6348

6349 6350
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount

6351
| 名称  | 值 | 说明        |
6352 6353 6354 6355 6356 6357 6358 6359
| ---- | ------ | ----------- |
| ATL1 | 10000  | 信任级别 1。 |
| ATL2 | 20000  | 信任级别 2。 |
| ATL3 | 30000  | 信任级别 3。 |
| ATL4 | 40000  | 信任级别 4。 |

## Module<sup>8+</sup>

J
jidong 已提交
6360
表示获取信息的模块的枚举。
6361

J
jidong 已提交
6362
**系统接口:** 此接口为系统接口。
6363

6364 6365
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount

6366
| 名称       | 值 | 说明                     |
6367 6368 6369 6370 6371
| --------- | ------ | ------------------------ |
| FACE_AUTH | 1      | 表示从人脸认证获取的信息。 |

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

J
jidong 已提交
6372
表示身份验证结果码。
6373

J
jidong 已提交
6374
**系统接口:** 此接口为系统接口。
6375

6376 6377
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount

6378
| 名称                    | 值 | 说明                                     |
6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393
| ----------------------- | ----- | ---------------------------------------- |
| SUCCESS                 | 0     | 表示身份验证成功或支持此功能。             |
| FAIL                    | 1     | 表示验证器无法识别用户。                   |
| GENERAL_ERROR           | 2     | 表示其他错误。                            |
| CANCELED                | 3     | 表示身份验证已取消。                       |
| TIMEOUT                 | 4     | 表示身份验证已超时。                       |
| TYPE_NOT_SUPPORT        | 5     | 表示不支持此身份验证类型。                 |
| TRUST_LEVEL_NOT_SUPPORT | 6     | 表示不支持身份验证信任级别。               |
| BUSY                    | 7     | 表示身份验证任务正忙。等待几秒钟,然后重试。 |
| INVALID_PARAMETERS      | 8     | 表示参数不正确。                          |
| LOCKED                  | 9     | 指示身份验证器已锁定。                     |
| NOT_ENROLLED            | 10    | 表示用户尚未注册验证器。                   |

## FaceTipsCode<sup>8+</sup>

J
jidong 已提交
6394
表示人脸验证过程中提示的枚举。
6395

J
jidong 已提交
6396
**系统接口:** 此接口为系统接口。
6397

6398 6399
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount

6400
| 名称                          | 值 | 说明                                     |
6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413
| ----------------------------- | ----- | ---------------------------------------- |
| FACE_AUTH_TIP_TOO_BRIGHT      | 1     | 表示由于高照明,获得的面部图像太亮。         |
| FACE_AUTH_TIP_TOO_DARK        | 2     | 表示由于照明度低,获得的面部图像太暗。       |
| FACE_AUTH_TIP_TOO_CLOSE       | 3     | 表示面部离设备太近。                       |
| FACE_AUTH_TIP_TOO_FAR         | 4     | 表示面部离设备太远。                       |
| FACE_AUTH_TIP_TOO_HIGH        | 5     | 表示设备太高,仅捕捉面部上部。              |
| FACE_AUTH_TIP_TOO_LOW         | 6     | 表示设备太低,仅捕捉面部下部。              |
| FACE_AUTH_TIP_TOO_RIGHT       | 7     | 指示设备向右偏移,并且仅捕捉面部的右侧部分。 |
| FACE_AUTH_TIP_TOO_LEFT        | 8     | 指示设备向左偏移,并且仅捕捉面部的左侧部分。 |
| FACE_AUTH_TIP_TOO_MUCH_MOTION | 9     | 表示面部信息收集过程中面部移动过快。         |
| FACE_AUTH_TIP_POOR_GAZE       | 10    | 表示面未朝向设备。                         |
| FACE_AUTH_TIP_NOT_DETECTED    | 11    | 表示未检测到人脸。                         |

Z
zengyawen 已提交
6414
## FingerprintTips<sup>8+</sup>
6415

J
jidong 已提交
6416
表示指纹身份验证过程中提示的枚举。
6417

J
jidong 已提交
6418
**系统接口:** 此接口为系统接口。
6419

6420 6421
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount

6422
| 名称                          | 值 | 说明                                            |
6423
| ----------------------------- | ----- | ----------------------------------------------- |
6424
| FINGERPRINT_TIP_GOOD          | 0     | 表示采集的图像良好。                              |
6425 6426
| FINGERPRINT_TIP_IMAGER_DIRTY  | 1     | 表示由于传感器上可疑或检测到污垢,指纹图像噪声过大。 |
| FINGERPRINT_TIP_INSUFFICIENT  | 2     | 表示由于检测到的情况,指纹图像噪声太大,无法处理。   |
6427
| FINGERPRINT_TIP_PARTIAL       | 3     | 表示仅检测到部分指纹图像。                         |
6428 6429
| FINGERPRINT_TIP_TOO_FAST      | 4     | 表示指纹图像由于快速运动而不完整。                  |
| FINGERPRINT_TIP_TOO_SLOW      | 5     | 表示由于缺少运动,指纹图像无法读取。                |
C
cclicn 已提交
6430 6431
| FINGERPRINT_TIP_FINGER_DOWN<sup>10+</sup>   | 6     | 表示手指落下。                  |
| FINGERPRINT_TIP_FINGER_UP<sup>10+</sup>     | 7     | 表示手指抬起。                |
6432

Z
zhangalong 已提交
6433
## OsAccountInfo
Z
zengyawen 已提交
6434

J
jidong 已提交
6435
表示系统帐号信息。
Z
zengyawen 已提交
6436 6437 6438

**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount。

6439
| 名称                         | 类型                                                         | 必填 | 说明                              |
Z
zengyawen 已提交
6440 6441 6442
| ------------------------------ | ------------------------------------------------------------ | ---- | --------------------------------- |
| localId                        | number                                                       | 是   | 系统帐号ID。                      |
| localName                      | string                                                       | 是   | 系统帐号名称。                    |
6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453
| type                           | [OsAccountType](#osaccounttype)                              | 是   | 系统帐号类型。                      |
| constraints                    | Array&lt;string&gt;                                          | 否   | 系统帐号[约束](#系统帐号约束列表),默认为空。|
| isVerified<sup>8+</sup>        | boolean                                                      | 是   | 帐号是否验证。                      |
| photo<sup>8+</sup>             | string                                                       | 否   | 系统帐号头像,默认为空。                      |
| createTime<sup>8+</sup>        | number                                                       | 是   | 系统帐号创建时间。                  |
| lastLoginTime<sup>8+</sup>     | number                                                       | 否   | 系统帐号最后一次登录时间,默认为空。          |
| serialNumber<sup>8+</sup>      | number                                                       | 是   | 系统帐号SN码。                      |
| isActived<sup>8+</sup>         | boolean                                                      | 是   | 系统帐号激活状态。                  |
| isCreateCompleted<sup>8+</sup> | boolean                                                      | 是   | 系统帐号创建是否完整。              |
| distributedInfo                | [distributedAccount.DistributedInfo](js-apis-distributed-account.md) | 否   | 分布式帐号信息,默认为空。                    |
| domainInfo<sup>8+</sup>        | [DomainAccountInfo](#domainaccountinfo8)                      | 否   | 域帐号信息,默认为空。                        |
Z
zengyawen 已提交
6454 6455

## DomainAccountInfo<sup>8+</sup>
Z
zengyawen 已提交
6456

J
jidong 已提交
6457
表示域帐号信息。
Z
zengyawen 已提交
6458 6459 6460

**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount。

6461
| 名称      | 类型   | 必填 | 说明       |
Z
zengyawen 已提交
6462 6463 6464
| ----------- | ------ | ---- | ---------- |
| domain      | string | 是   | 域名。     |
| accountName | string | 是   | 域帐号名。 |
6465
| accountId<sup>10+</sup> | string | 否   | 域帐号标识。<br>**系统接口:** 此接口为系统接口,默认为空。 |
Z
zhangalong 已提交
6466 6467 6468

## 系统帐号约束列表

Z
zengyawen 已提交
6469 6470
| 约束                                  | 说明                           |
| ------------------------------------- | ------------------------------ |
Z
zengyawen 已提交
6471 6472
| constraint.wifi                       | 禁止使用Wi-Fi                  |
| constraint.wifi.set                   | 禁止配置Wi-Fi                  |
Z
zengyawen 已提交
6473 6474 6475 6476 6477 6478
| constraint.locale.set                 | 禁止配置设备语言               |
| constraint.app.accounts               | 禁止添加和删除应用帐号         |
| constraint.apps.install               | 禁止安装应用                   |
| constraint.apps.uninstall             | 禁止卸载应用                   |
| constraint.location.shared            | 禁止打开位置共享               |
| constraint.unknown.sources.install    | 禁止安装未知来源的应用         |
Z
zhangalong 已提交
6479
| constraint.global.unknown.app.install | 禁止所有用户安装未知来源的应用 |
Z
zengyawen 已提交
6480 6481
| constraint.bluetooth.set              | 禁止配置蓝牙                   |
| constraint.bluetooth | 禁止使用蓝牙 |
Z
zhangalong 已提交
6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500
| constraint.bluetooth.share | 禁止共享使用蓝牙 |
| constraint.usb.file.transfer | 禁止通过USB传输文件 |
| constraint.credentials.set | 禁止配置用户凭据 |
| constraint.os.account.remove | 禁止删除用户 |
| constraint.managed.profile.remove | 禁止删除此用户的托管配置文件 |
| constraint.debug.features.use | J禁止启用或访问调试功能 |
| constraint.vpn.set | 禁止配置VPN |
| constraint.date.time.set | 禁止配置日期时间和时区 |
| constraint.tethering.config | 禁止配置Tethering |
| constraint.network.reset | 禁止重置网络设置 |
| constraint.factory.reset | 禁止出厂设置 |
| constraint.os.account.create | 禁止创建新用户 |
| constraint.add.managed.profile | 禁止添加托管配置文件 |
| constraint.apps.verify.disable | 强制应用程序验证 |
| constraint.cell.broadcasts.set | 禁止配置小区广播 |
| constraint.mobile.networks.set | 禁止配置移动网络 |
| constraint.control.apps | 禁止在设置或启动模块中修改应用程序 |
| constraint.physical.media | 禁止装载物理外部介质 |
| constraint.microphone | 禁止使用麦克风 |
L
lichenchen 已提交
6501 6502
| constraint.microphone.unmute | 禁止取消麦克风静音 |
| constraint.volume.adjust | 禁止调整音量 |
Z
zhangalong 已提交
6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519
| constraint.calls.outgoing | 禁止拨打外呼电话 |
| constraint.sms.use | 禁止发送或接收短信 |
| constraint.fun | 禁止享受乐趣 |
| constraint.windows.create | 禁止创建应用程序窗口以外的窗口 |
| constraint.system.error.dialogs | 禁止显示崩溃或无响应应用程序的系统错误对话框 |
| constraint.cross.profile.copy.paste | 禁止通过将数据粘贴到其他用户或配置文件来导出剪贴板内容 |
| constraint.beam.outgoing | 禁止使用NFC从应用程序传送数据 |
| constraint.wallpaper | 禁止管理壁纸 |
| constraint.safe.boot | 禁止进入安全引导模式 |
| constraint.parent.profile.app.linking | 允许父配置文件中的应用程序处理来自托管配置文件的Web链接 |
| constraint.audio.record | 禁止录制音频 |
| constraint.camera.use | 禁止使用摄像机 |
| constraint.os.account.background.run | 禁止在后台运行 |
| constraint.data.roam | 禁止漫游通话时使用蜂窝数据 |
| constraint.os.account.set.icon | 禁止修改用户头像 |
| constraint.wallpaper.set | 禁止设置壁纸 |
| constraint.oem.unlock | 禁止启用oem解锁 |
L
lichenchen 已提交
6520
| constraint.device.unmute | 禁止取消设备静音 |
Z
zhangalong 已提交
6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532
| constraint.password.unified | 禁止托管配置文件与主用户进行统一锁屏质询 |
| constraint.autofill | 禁止使用自动填充服务 |
| constraint.content.capture | 禁止捕获用户屏幕 |
| constraint.content.suggestions | 禁止接收内容建议 |
| constraint.os.account.start | 禁止切换用户 |
| constraint.location.set | 禁止配置位置服务 |
| constraint.airplane.mode.set | 禁止飞行模式 |
| constraint.brightness.set | 禁止配置亮度 |
| constraint.share.into.profile | 禁止将主要用户的文件/图片/数据共享到托管配置文件中 |
| constraint.ambient.display | 禁止显示环境 |
| constraint.screen.timeout.set | 禁止配置屏幕关闭的超时 |
| constraint.print | 禁止打印 |
6533 6534 6535 6536
| constraint.private.dns.set | 禁止配置专用DNS |

## ConstraintSourceTypeInfo<sup>9+</sup>

J
jidong 已提交
6537
表示约束来源类型信息。
6538

J
jidong 已提交
6539
**系统接口:** 此接口为系统接口。
J
jidong 已提交
6540

6541 6542
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount。

6543
| 名称      | 类型   | 必填 | 说明       |
6544 6545 6546 6547 6548 6549
| ----------- | ------ | ---- | ---------- |
| localId      | number | 是   | 系统帐号ID     |
| type | [ConstraintSourceType](#constraintsourcetype) | 是   | 约束来源类型 |

## ConstraintSourceType<sup>9+</sup>

J
jidong 已提交
6550
表示约束来源类型的枚举。
6551

J
jidong 已提交
6552
**系统接口:** 此接口为系统接口。
J
jidong 已提交
6553

6554 6555
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount。

6556
| 名称   | 值 | 说明         |
6557 6558 6559 6560
| ------ | ------ | ------------ |
| CONSTRAINT_NOT_EXIST  | 0      | 约束不存在 |
| CONSTRAINT_TYPE_BASE | 1      | 约束源自系统设置   |
| CONSTRAINT_TYPE_DEVICE_OWNER  | 2   | 约束源自设备所有者设置   |
J
jidong 已提交
6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574
| CONSTRAINT_TYPE_PROFILE_OWNER  | 3  | 约束源自资料所有者设置   |

## AuthStatusInfo<sup>10+</sup>

表示认证状态信息。

**系统接口:** 此接口为系统接口。

**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount。

| 名称      | 类型   | 必填 | 说明       |
| ----------- | ------ | ---- | ---------- |
| remainTimes  | number | 是   | 剩余次数   |
| freezingTime | number | 是   | 冻结时间 |
J
jidong 已提交
6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589

## GetDomainAccessTokenOptions<sup>10+</sup>

表示获取域访问令牌的选项。

**系统接口:** 此接口为系统接口。

**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount。

| 名称      | 类型   | 必填 | 说明       |
| ----------- | ------ | ---- | ---------- |
| domainAccountInfo  | [DomainAccountInfo](#domainaccountinfo8) | 是   | 域帐号的信息   |
| domainAccountToken | Uint8Array | 是   | 域帐号的令牌 |
| businessParams | { [key: string]: object } | 是   | 业务参数,由业务方根据请求协议自定义 |
| callerUid | number | 是   | 调用方唯一标识符 |