• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.account.osAccount (系统帐号管理)
2
3本模块提供管理系统帐号的基础能力,包括系统帐号的添加、删除、查询、设置、订阅、启动等功能。
4
5> **说明:**
6>
7> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8
9## 导入模块
10
11```ts
12import account_osAccount from '@ohos.account.osAccount';
13```
14
15## account_osAccount.getAccountManager
16
17getAccountManager(): AccountManager
18
19获取系统帐号管理对象。
20
21**系统能力:** SystemCapability.Account.OsAccount
22
23**返回值:**
24
25| 类型                              | 说明              |
26| --------------------------------- | ---------------- |
27| [AccountManager](#accountmanager) | 系统帐号管理对象。 |
28
29**示例:**
30
31  ```ts
32  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
33  ```
34
35## OsAccountType
36
37表示系统帐号类型的枚举。
38
39**系统能力:** SystemCapability.Account.OsAccount40
41| 名称   | 值 | 说明         |
42| ------ | ------ | ----------- |
43| ADMIN  | 0      | 管理员帐号。 |
44| NORMAL | 1      | 普通帐号。   |
45| GUEST  | 2      | 访客帐号。   |
46
47## AccountManager
48
49系统帐号管理类。
50
51### checkMultiOsAccountEnabled<sup>9+</sup>
52
53checkMultiOsAccountEnabled(callback: AsyncCallback&lt;boolean&gt;): void
54
55判断是否支持多系统帐号。使用callback异步回调。
56
57**系统能力:** SystemCapability.Account.OsAccount
58
59**参数:**
60
61| 参数名   | 类型                         | 必填 | 说明                                                     |
62| -------- | ---------------------------- | ---- | ------------------------------------------------------ |
63| callback | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。返回true表示支持多系统帐号;返回false表示不支持。 |
64
65**错误码:**
66
67| 错误码ID | 错误信息             |
68| -------- | ------------------- |
69| 12300001 | System service exception. |
70
71**示例:**
72
73  ```ts
74  import { BusinessError } from '@ohos.base';
75  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
76  try {
77    accountManager.checkMultiOsAccountEnabled((err: BusinessError, isEnabled: boolean) => {
78      if (err) {
79        console.error(`checkMultiOsAccountEnabled failed, code is ${err.code}, message is ${err.message}`);
80      } else {
81      console.log('checkMultiOsAccountEnabled successfully, isEnabled: ' + isEnabled);
82      }
83    });
84  } catch (err) {
85    console.log('checkMultiOsAccountEnabled failed, error:' + JSON.stringify(err));
86  }
87  ```
88
89### checkMultiOsAccountEnabled<sup>9+</sup>
90
91checkMultiOsAccountEnabled(): Promise&lt;boolean&gt;
92
93判断是否支持多系统帐号。使用Promise异步回调。
94
95**系统能力:** SystemCapability.Account.OsAccount
96
97**返回值:**
98
99| 类型                   | 说明                                                        |
100| :--------------------- | :--------------------------------------------------------- |
101| Promise&lt;boolean&gt; | Promise对象。返回true表示支持多系统帐号;返回false表示不支持。 |
102
103**错误码:**
104
105| 错误码ID | 错误信息             |
106| -------- | ------------------- |
107| 12300001 | System service exception. |
108
109**示例:**
110
111  ```ts
112  import { BusinessError } from '@ohos.base';
113  try {
114    let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
115    accountManager.checkMultiOsAccountEnabled().then((isEnabled: boolean) => {
116      console.log('checkMultiOsAccountEnabled successfully, isEnabled: ' + isEnabled);
117    }).catch((err: BusinessError) => {
118      console.error(`checkMultiOsAccountEnabled failed, code is ${err.code}, message is ${err.message}`);
119    });
120  } catch (err) {
121    console.log('checkMultiOsAccountEnabled failed, error:' + JSON.stringify(err));
122  }
123  ```
124
125### checkOsAccountActivated<sup>(deprecated)</sup>
126
127checkOsAccountActivated(localId: number, callback: AsyncCallback&lt;boolean&gt;): void
128
129判断指定系统帐号是否处于激活状态。使用callback异步回调。
130
131> **说明:**
132>
133> 从 API version 9开始支持,从API version 11开始废弃。替代方法仅向系统应用开放。
134
135**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTSohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
136
137**系统能力:** SystemCapability.Account.OsAccount
138
139**参数:**
140
141| 参数名   | 类型                         | 必填 | 说明                                                     |
142| -------- | ---------------------------- | ---- | ------------------------------------------------------ |
143| localId  | number                       | 是   | 系统帐号ID。                                             |
144| callback | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。返回true表示帐号已激活;返回false表示帐号未激活。 |
145
146**错误码:**
147
148| 错误码ID | 错误信息             |
149| -------- | ------------------- |
150| 12300001 | System service exception. |
151| 12300002 | Invalid localId.    |
152| 12300003 | Account not found. |
153
154**示例:** 判断ID为100的系统帐号是否处于激活状态
155
156  ```ts
157  import { BusinessError } from '@ohos.base';
158  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
159  let localId: number = 100;
160  try {
161    accountManager.checkOsAccountActivated(localId, (err: BusinessError, isActivated: boolean) => {
162      if (err) {
163        console.log('checkOsAccountActivated failed, error:' + JSON.stringify(err));
164      } else {
165        console.log('checkOsAccountActivated successfully, isActivated:' + isActivated);
166      }
167    });
168  } catch (err) {
169    console.log('checkOsAccountActivated exception: ' + JSON.stringify(err));
170  }
171  ```
172
173### checkOsAccountActivated<sup>(deprecated)</sup>
174
175checkOsAccountActivated(localId: number): Promise&lt;boolean&gt;
176
177判断指定系统帐号是否处于激活状态。使用Promise异步回调。
178
179> **说明:**
180>
181> 从 API version 9开始支持,从API version 11开始废弃。替代方法仅向系统应用开放。
182
183**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTSohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
184
185**系统能力:** SystemCapability.Account.OsAccount
186
187**参数:**
188
189| 参数名  | 类型   | 必填 | 说明                               |
190| ------- | ------ | ---- | --------------------------------- |
191| localId | number | 是   | 系统帐号ID。 |
192
193**返回值:**
194
195| 类型                   | 说明                                                       |
196| ---------------------- | ---------------------------------------------------------- |
197| Promise&lt;boolean&gt; | Promise对象。返回true表示帐号已激活;返回false表示帐号未激活。 |
198
199**错误码:**
200
201| 错误码ID | 错误信息             |
202| -------- | ------------------- |
203| 12300001 | System service exception. |
204| 12300002 | Invalid localId.    |
205| 12300003 | Account not found. |
206
207**示例:** 判断ID为100的系统帐号是否处于激活状态
208
209  ```ts
210  import { BusinessError } from '@ohos.base';
211  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
212  let localId: number = 100;
213  try {
214    accountManager.checkOsAccountActivated(localId).then((isActivated: boolean) => {
215      console.log('checkOsAccountActivated successfully, isActivated: ' + isActivated);
216    }).catch((err: BusinessError) => {
217      console.log('checkOsAccountActivated failed, error: ' + JSON.stringify(err));
218    });
219  } catch (err) {
220    console.log('checkOsAccountActivated exception: ' + JSON.stringify(err));
221  }
222  ```
223
224### isOsAccountConstraintEnabled<sup>11+</sup>
225
226isOsAccountConstraintEnabled(constraint: string): Promise&lt;boolean&gt;
227
228判断当前系统帐号是否使能指定约束。使用Promise异步回调。
229
230**系统能力:** SystemCapability.Account.OsAccount
231
232**参数:**
233
234| 参数名     | 类型   | 必填 | 说明                                |
235| ---------- | ------ | ---- | ---------------------------------- |
236| constraint | string | 是   | 指定的[约束](#系统帐号约束列表)名称。 |
237
238**返回值:**
239
240| 类型                   | 说明                                                                  |
241| --------------------- | --------------------------------------------------------------------- |
242| Promise&lt;boolean&gt; | Promise对象。返回true表示已使能指定的约束;返回false表示未使能指定的约束。 |
243
244**错误码:**
245
246| 错误码ID | 错误信息             |
247| -------- | ------------------- |
248| 12300001 | System service exception. |
249
250**示例:** 判断ID为100的系统帐号是否有禁止使用Wi-Fi的约束
251
252  ```ts
253  import { BusinessError } from '@ohos.base';
254  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
255  let constraint: string = 'constraint.wifi';
256  try {
257    accountManager.isOsAccountConstraintEnabled(constraint).then((isEnabled: boolean) => {
258      console.log('isOsAccountConstraintEnabled successfully, isEnabled: ' + isEnabled);
259    }).catch((err: BusinessError) => {
260      console.log('isOsAccountConstraintEnabled failed, error: ' + JSON.stringify(err));
261    });
262  } catch (err) {
263    console.log('isOsAccountConstraintEnabled exception: ' + JSON.stringify(err));
264  }
265  ```
266
267### checkOsAccountConstraintEnabled<sup>(deprecated)</sup>
268
269checkOsAccountConstraintEnabled(localId: number, constraint: string, callback: AsyncCallback&lt;boolean&gt;): void
270
271判断指定系统帐号是否具有指定约束。使用callback异步回调。
272
273> **说明:**
274>
275> 从 API version 9开始支持,从API version 11开始废弃。替代方法仅向系统应用开放。
276
277**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTSohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
278
279**系统能力:** SystemCapability.Account.OsAccount
280
281**参数:**
282
283| 参数名     | 类型                         | 必填 | 说明                                                               |
284| ---------- | ---------------------------- | ---- | ----------------------------------------------------------------- |
285| localId    | number                       | 是   | 系统帐号ID。                                 |
286| constraint | string                       | 是   | 指定的[约束](#系统帐号约束列表)名称。                                |
287| callback   | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。返回true表示已使能指定的约束;返回false表示未使能指定的约束。 |
288
289**错误码:**
290
291| 错误码ID | 错误信息             |
292| -------- | ------------------- |
293| 12300001 | System service exception. |
294| 12300002 | Invalid localId or constraint.    |
295| 12300003 | Account not found. |
296
297**示例:** 判断ID为100的系统帐号是否有禁止使用Wi-Fi的约束
298
299  ```ts
300  import { BusinessError } from '@ohos.base';
301  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
302  let localId: number = 100;
303  let constraint: string = 'constraint.wifi';
304  try {
305    accountManager.checkOsAccountConstraintEnabled(localId, constraint, (err: BusinessError, isEnabled: boolean)=>{
306      if (err) {
307        console.log('checkOsAccountConstraintEnabled failed, error: ' + JSON.stringify(err));
308      } else {
309        console.log('checkOsAccountConstraintEnabled successfully, isEnabled: ' + isEnabled);
310      }
311    });
312  } catch (err) {
313    console.log('checkOsAccountConstraintEnabled exception: ' + JSON.stringify(err));
314  }
315  ```
316
317### checkOsAccountConstraintEnabled<sup>(deprecated)</sup>
318
319checkOsAccountConstraintEnabled(localId: number, constraint: string): Promise&lt;boolean&gt;
320
321判断指定系统帐号是否具有指定约束。使用Promise异步回调。
322
323> **说明:**
324>
325> 从 API version 9开始支持,从API version 11开始废弃。替代方法仅向系统应用开放。
326
327**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTSohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
328
329**系统能力:** SystemCapability.Account.OsAccount
330
331**参数:**
332
333| 参数名     | 类型   | 必填 | 说明                                |
334| ---------- | ------ | ---- | ---------------------------------- |
335| localId    | number | 是   | 系统帐号ID。  |
336| constraint | string | 是   | 指定的[约束](#系统帐号约束列表)名称。 |
337
338**返回值:**
339
340| 类型                   | 说明                                                                  |
341| --------------------- | --------------------------------------------------------------------- |
342| Promise&lt;boolean&gt; | Promise对象。返回true表示已使能指定的约束;返回false表示未使能指定的约束。 |
343
344**错误码:**
345
346| 错误码ID | 错误信息             |
347| -------- | ------------------- |
348| 12300001 | System service exception. |
349| 12300002 | Invalid localId or constraint.    |
350| 12300003 | Account not found. |
351
352**示例:** 判断ID为100的系统帐号是否有禁止使用Wi-Fi的约束
353
354  ```ts
355  import { BusinessError } from '@ohos.base';
356  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
357  let localId: number = 100;
358  let constraint: string = 'constraint.wifi';
359  try {
360    accountManager.checkOsAccountConstraintEnabled(localId, constraint).then((isEnabled: boolean) => {
361      console.log('checkOsAccountConstraintEnabled successfully, isEnabled: ' + isEnabled);
362    }).catch((err: BusinessError) => {
363      console.log('checkOsAccountConstraintEnabled failed, error: ' + JSON.stringify(err));
364    });
365  } catch (err) {
366    console.log('checkOsAccountConstraintEnabled exception: ' + JSON.stringify(err));
367  }
368  ```
369
370### checkOsAccountTestable<sup>9+</sup>
371
372checkOsAccountTestable(callback: AsyncCallback&lt;boolean&gt;): void
373
374检查当前系统帐号是否为测试帐号。使用callback异步回调。
375
376**系统能力:** SystemCapability.Account.OsAccount
377
378**参数:**
379
380| 参数名   | 类型                         | 必填 | 说明                                                                   |
381| -------- | ---------------------------- | ---- | --------------------------------------------------------------------- |
382| callback | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。返回true表示当前帐号为测试帐号;返回false表示当前帐号非测试帐号。 |
383
384**错误码:**
385
386| 错误码ID | 错误信息             |
387| -------- | ------------------- |
388| 12300001 | System service exception. |
389
390**示例:**
391
392  ```ts
393  import { BusinessError } from '@ohos.base';
394  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
395  try {
396    accountManager.checkOsAccountTestable((err: BusinessError, isTestable: boolean) => {
397      if (err) {
398        console.log('checkOsAccountTestable failed, error: ' + JSON.stringify(err));
399      } else {
400        console.log('checkOsAccountTestable successfully, isTestable: ' + isTestable);
401      }
402    });
403  } catch (err) {
404    console.log('checkOsAccountTestable error: ' + JSON.stringify(err));
405  }
406  ```
407
408### checkOsAccountTestable<sup>9+</sup>
409
410checkOsAccountTestable(): Promise&lt;boolean&gt;
411
412检查当前系统帐号是否为测试帐号。使用Promise异步回调。
413
414**系统能力:** SystemCapability.Account.OsAccount
415
416**返回值:**
417
418| 类型                   | 说明                                                                      |
419| ---------------------- | ------------------------------------------------------------------------ |
420| Promise&lt;boolean&gt; | Promise对象。返回true表示当前帐号为测试帐号;返回false表示当前帐号非测试帐号。 |
421
422**错误码:**
423
424| 错误码ID | 错误信息             |
425| -------- | ------------------- |
426| 12300001 | System service exception. |
427
428**示例:**
429
430  ```ts
431  import { BusinessError } from '@ohos.base';
432  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
433  try {
434    accountManager.checkOsAccountTestable().then((isTestable: boolean) => {
435      console.log('checkOsAccountTestable successfully, isTestable: ' + isTestable);
436    }).catch((err: BusinessError) => {
437      console.log('checkOsAccountTestable failed, error: ' + JSON.stringify(err));
438    });
439  } catch (err) {
440    console.log('checkOsAccountTestable exception: ' + JSON.stringify(err));
441  }
442  ```
443
444### isOsAccountUnlocked<sup>11+</sup>
445
446isOsAccountUnlocked(): Promise&lt;boolean&gt;
447
448检查当前系统帐号是否已认证解锁。使用Promise异步回调。
449
450**系统能力:** SystemCapability.Account.OsAccount
451
452**返回值:**
453
454| 类型                   | 说明                                                                      |
455| ---------------------- | ------------------------------------------------------------------------ |
456| Promise&lt;boolean&gt; | Promise对象。返回true表示当前帐号已认证解锁;返回false表示当前帐号未认证解锁。 |
457
458**错误码:**
459
460| 错误码ID | 错误信息             |
461| -------- | ------------------- |
462| 12300001 | System service exception. |
463
464**示例:**
465
466  ```ts
467  import { BusinessError } from '@ohos.base';
468  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
469  try {
470    accountManager.isOsAccountUnlocked().then((isVerified: boolean) => {
471      console.log('isOsAccountUnlocked successfully, isVerified: ' + isVerified);
472    }).catch((err: BusinessError) => {
473      console.log('isOsAccountUnlocked failed, error: ' + JSON.stringify(err));
474    });
475  } catch (err) {
476    console.log('isOsAccountUnlocked exception: ' + JSON.stringify(err));
477  }
478  ```
479
480### checkOsAccountVerified<sup>(deprecated)</sup>
481
482checkOsAccountVerified(callback: AsyncCallback&lt;boolean&gt;): void
483
484检查当前系统帐号是否已认证解锁。使用callback异步回调。
485
486> **说明:**
487>
488> 从 API version 9开始支持,从API version 11开始废弃。建议使用[isOsAccountUnlocked](#isosaccountunlocked11)替代。
489
490**系统能力:** SystemCapability.Account.OsAccount
491
492**参数:**
493
494| 参数名   | 类型                         | 必填 | 说明                                                            |
495| -------- | ---------------------------- | ---- | ------------------------------------------------------------- |
496| callback | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。返回true表示当前帐号已认证解锁;返回false表示当前帐号未认证解锁。 |
497
498**错误码:**
499
500| 错误码ID | 错误信息             |
501| -------- | ------------------- |
502| 12300001 | System service exception. |
503
504**示例:**
505
506  ```ts
507  import { BusinessError } from '@ohos.base';
508  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
509  try {
510    accountManager.checkOsAccountVerified((err: BusinessError, isVerified: boolean) => {
511      if (err) {
512        console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err));
513      } else {
514        console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified);
515      }
516    });
517  } catch (err) {
518    console.log('checkOsAccountVerified exception: ' + JSON.stringify(err));
519  }
520  ```
521
522### checkOsAccountVerified<sup>(deprecated)</sup>
523
524checkOsAccountVerified(): Promise&lt;boolean&gt;
525
526检查当前系统帐号是否已认证解锁。使用Promise异步回调。
527
528> **说明:**
529>
530> 从 API version 9开始支持,从API version 11开始废弃。建议使用[isOsAccountUnlocked](#isosaccountunlocked11)替代。
531
532**系统能力:** SystemCapability.Account.OsAccount
533
534**返回值:**
535
536| 类型                   | 说明                                                                      |
537| ---------------------- | ------------------------------------------------------------------------ |
538| Promise&lt;boolean&gt; | Promise对象。返回true表示当前帐号已认证解锁;返回false表示当前帐号未认证解锁。 |
539
540**错误码:**
541
542| 错误码ID | 错误信息             |
543| -------- | ------------------- |
544| 12300001 | System service exception. |
545
546**示例:**
547
548  ```ts
549  import { BusinessError } from '@ohos.base';
550  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
551  try {
552    accountManager.checkOsAccountVerified().then((isVerified: boolean) => {
553      console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified);
554    }).catch((err: BusinessError) => {
555      console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err));
556    });
557  } catch (err) {
558    console.log('checkOsAccountVerified exception: ' + JSON.stringify(err));
559  }
560  ```
561
562### checkOsAccountVerified<sup>(deprecated)</sup>
563
564checkOsAccountVerified(localId: number, callback: AsyncCallback&lt;boolean&gt;): void
565
566检查指定系统帐号是否已验证。使用callback异步回调。
567
568> **说明:**
569>
570> 从 API version 9开始支持,从API version 11开始废弃。替代方法仅向系统应用开放。
571
572**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTSohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
573
574**系统能力:** SystemCapability.Account.OsAccount
575
576**参数:**
577
578| 参数名   | 类型                         | 必填 | 说明                                                            |
579| -------- | ---------------------------- | ---- | ------------------------------------------------------------- |
580| localId  | number                       | 是   | 系统帐号ID。                              |
581| callback | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。返回true表示当前帐号已认证解锁;返回false表示当前帐号未认证解锁。 |
582
583**错误码:**
584
585| 错误码ID | 错误信息             |
586| -------- | ------------------- |
587| 12300001 | System service exception. |
588| 12300002 | Invalid localId.    |
589| 12300003 | Account not found. |
590
591**示例:**
592
593  ```ts
594  import { BusinessError } from '@ohos.base';
595  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
596  let localId: number = 100;
597  try {
598    accountManager.checkOsAccountVerified(localId, (err: BusinessError, isVerified: boolean) => {
599      if (err) {
600        console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err));
601      } else {
602        console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified);
603      }
604    });
605  } catch (err) {
606    console.log('checkOsAccountVerified exception: ' + err);
607  }
608  ```
609
610### checkOsAccountVerified<sup>(deprecated)</sup>
611
612checkOsAccountVerified(localId: number): Promise&lt;boolean&gt;
613
614检查指定系统帐号是否已验证。使用Promise异步回调。
615
616> **说明:**
617>
618> 从 API version 9开始支持,从API version 11开始废弃。替代方法仅向系统应用开放。
619
620**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTSohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
621
622**系统能力:** SystemCapability.Account.OsAccount
623
624**参数:**
625
626| 参数名  | 类型   | 必填 | 说明                                                              |
627| ------- | ------ | ---- | --------------------------------------------------------------- |
628| localId | number | 是   | 系统帐号ID。不填则检查当前系统帐号是否已验证。 |
629
630**返回值:**
631
632| 类型                   | 说明                                                               |
633| ---------------------- | ----------------------------------------------------------------- |
634| Promise&lt;boolean&gt; | Promise对象。返回true表示当前帐号已认证解锁;返回false表示当前帐号未认证解锁。 |
635
636**错误码:**
637
638| 错误码ID | 错误信息             |
639| -------- | ------------------- |
640| 12300001 | System service exception. |
641| 12300002 | Invalid localId.    |
642| 12300003 | Account not found. |
643
644**示例:**
645
646  ```ts
647  import { BusinessError } from '@ohos.base';
648  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
649  let localId: number = 100;
650  try {
651    accountManager.checkOsAccountVerified(localId).then((isVerified: boolean) => {
652      console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified);
653    }).catch((err: BusinessError) => {
654      console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err));
655    });
656  } catch (err) {
657    console.log('checkOsAccountVerified exception: ' + JSON.stringify(err));
658  }
659  ```
660
661### checkOsAccountVerified<sup>9+</sup>
662
663checkOsAccountVerified(): Promise&lt;boolean&gt;
664
665检查当前系统帐号是否已验证。使用Promise异步回调。
666
667**系统能力:** SystemCapability.Account.OsAccount
668
669**返回值:**
670
671| 类型                   | 说明                                                               |
672| ---------------------- | ----------------------------------------------------------------- |
673| Promise&lt;boolean&gt; | Promise对象。返回true表示当前帐号已验证;返回false表示当前帐号未验证。 |
674
675**错误码:**
676
677| 错误码ID | 错误信息             |
678| -------- | ------------------- |
679| 12300001 | System service exception. |
680
681**示例:**
682
683  ```ts
684  import { BusinessError } from '@ohos.base';
685  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
686  try {
687    accountManager.checkOsAccountVerified().then((isVerified: boolean) => {
688      console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified);
689    }).catch((err: BusinessError) => {
690      console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err));
691    });
692  } catch (err) {
693    console.log('checkOsAccountVerified exception: ' + JSON.stringify(err));
694  }
695  ```
696
697### getOsAccountCount<sup>9+</sup>
698
699getOsAccountCount(callback: AsyncCallback&lt;number&gt;): void
700
701获取已创建的系统帐号数量。使用callback异步回调。
702
703**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
704
705**系统能力:** SystemCapability.Account.OsAccount
706
707**参数:**
708
709| 参数名   | 类型                        | 必填 | 说明                                                                         |
710| -------- | --------------------------- | ---- | -------------------------------------------------------------------------- |
711| callback | AsyncCallback&lt;number&gt; | 是   | 回调函数。当获取成功时,err为null,data为已创建的系统帐号的数量;否则为错误对象。 |
712
713**错误码:**
714
715| 错误码ID | 错误信息             |
716| -------- | ------------------- |
717| 12300001 | System service exception. |
718
719**示例:**
720
721  ```ts
722  import { BusinessError } from '@ohos.base';
723  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
724  try {
725    accountManager.getOsAccountCount((err: BusinessError, count: number) => {
726      if (err) {
727        console.log('getOsAccountCount failed, error: ' + JSON.stringify(err));
728      } else {
729        console.log('getOsAccountCount successfully, count: ' + count);
730      }
731    });
732  } catch (err) {
733    console.log('getOsAccountCount exception: ' + JSON.stringify(err));
734  }
735  ```
736
737### getOsAccountCount<sup>9+</sup>
738
739getOsAccountCount(): Promise&lt;number&gt;
740
741获取已创建的系统帐号数量。使用Promise异步回调。
742
743**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
744
745**系统能力:** SystemCapability.Account.OsAccount
746
747**返回值:**
748
749| 类型                  | 说明                                    |
750| --------------------- | -------------------------------------- |
751| Promise&lt;number&gt; | Promise对象,返回已创建的系统帐号的数量。 |
752
753**错误码:**
754
755| 错误码ID | 错误信息             |
756| -------- | ------------------- |
757| 12300001 | System service exception. |
758
759**示例:**
760
761  ```ts
762  import { BusinessError } from '@ohos.base';
763  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
764  try {
765    accountManager.getOsAccountCount().then((count: number) => {
766      console.log('getOsAccountCount successfully, count: ' + count);
767    }).catch((err: BusinessError) => {
768      console.log('getOsAccountCount failed, error: ' + JSON.stringify(err));
769    });
770  } catch(err) {
771    console.log('getOsAccountCount exception: ' + JSON.stringify(err));
772  }
773  ```
774
775### getOsAccountLocalId<sup>9+</sup>
776
777getOsAccountLocalId(callback: AsyncCallback&lt;number&gt;): void
778
779获取当前进程所属的系统帐号ID,使用callback异步回调。
780
781**系统能力:** SystemCapability.Account.OsAccount
782
783**参数:**
784
785| 参数名   | 类型                        | 必填 | 说明                                                                           |
786| -------- | --------------------------- | ---- | ---------------------------------------------------------------------------- |
787| callback | AsyncCallback&lt;number&gt; | 是   | 回调函数。当获取成功时,err为null,data为当前进程所属的系统帐号ID;否则为错误对象。 |
788
789**错误码:**
790
791| 错误码ID | 错误信息             |
792| -------- | ------------------- |
793| 12300001 | System service exception. |
794
795**示例:**
796
797  ```ts
798  import { BusinessError } from '@ohos.base';
799  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
800  try {
801    accountManager.getOsAccountLocalId((err: BusinessError, localId: number) => {
802      if (err) {
803        console.log('getOsAccountLocalId failed, error: ' + JSON.stringify(err));
804      } else {
805        console.log('getOsAccountLocalId successfully, localId: ' + localId);
806      }
807    });
808  } catch (err) {
809    console.log('getOsAccountLocalId exception: ' + JSON.stringify(err));
810  }
811  ```
812
813### getOsAccountLocalId<sup>9+</sup>
814
815getOsAccountLocalId(): Promise&lt;number&gt;
816
817获取当前进程所属的系统帐号ID,使用Promise异步回调。
818
819**系统能力:** SystemCapability.Account.OsAccount
820
821**返回值:**
822
823| 类型                  | 说明                                      |
824| --------------------- | ---------------------------------------- |
825| Promise&lt;number&gt; | Promise对象,返回当前进程所属的系统帐号ID。 |
826
827**错误码:**
828
829| 错误码ID | 错误信息             |
830| -------- | ------------------- |
831| 12300001 | System service exception. |
832
833**示例:**
834
835  ```ts
836  import { BusinessError } from '@ohos.base';
837  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
838  try {
839    accountManager.getOsAccountLocalId().then((localId: number) => {
840      console.log('getOsAccountLocalId successfully, localId: ' + localId);
841    }).catch((err: BusinessError) => {
842      console.log('getOsAccountLocalId failed, error: ' + JSON.stringify(err));
843    });
844  } catch (err) {
845    console.log('getOsAccountLocalId exception: ' + JSON.stringify(err));
846  }
847  ```
848
849### getOsAccountLocalIdForUid<sup>9+</sup>
850
851getOsAccountLocalIdForUid(uid: number, callback: AsyncCallback&lt;number&gt;): void
852
853根据uid查询对应的系统帐号ID,使用callback异步回调。
854
855**系统能力:** SystemCapability.Account.OsAccount
856
857**参数:**
858
859| 参数名   | 类型                        | 必填 | 说明                                                                    |
860| -------- | --------------------------- | ---- | --------------------------------------------------------------------- |
861| uid      | number                      | 是   | 进程uid。                                                              |
862| callback | AsyncCallback&lt;number&gt; | 是   | 回调函数。如果查询成功,err为null,data为对应的系统帐号ID;否则为错误对象。 |
863
864**错误码:**
865
866| 错误码ID | 错误信息         |
867| -------- | --------------- |
868| 12300001 | System service exception. |
869| 12300002 | Invalid uid.    |
870
871**示例:** 查询值为12345678的uid所属的系统帐号的帐号ID
872
873  ```ts
874  import { BusinessError } from '@ohos.base';
875  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
876  let uid: number = 12345678;
877  try {
878    accountManager.getOsAccountLocalIdForUid(uid, (err: BusinessError, localId: number) => {
879      if (err) {
880        console.log('getOsAccountLocalIdForUid failed, error: ' + JSON.stringify(err));
881      }
882      console.log('getOsAccountLocalIdForUid successfully, localId: ' + localId);
883    });
884  } catch (err) {
885    console.log('getOsAccountLocalIdForUid exception: ' + JSON.stringify(err));
886  }
887  ```
888
889### getOsAccountLocalIdForUid<sup>9+</sup>
890
891getOsAccountLocalIdForUid(uid: number): Promise&lt;number&gt;
892
893根据uid查询对应的系统帐号ID,使用Promise异步回调。
894
895**系统能力:** SystemCapability.Account.OsAccount
896
897**参数:**
898
899| 参数名 | 类型   | 必填 | 说明      |
900| ------ | ------ | ---- | --------- |
901| uid    | number | 是   | 进程uid。 |
902
903**返回值:**
904
905| 类型                  | 说明                                     |
906| --------------------- | --------------------------------------- |
907| Promise&lt;number&gt; | Promise对象,返回指定uid对应的系统帐号ID。 |
908
909**错误码:**
910
911| 错误码ID | 错误信息       |
912| -------- | ------------- |
913| 12300001 | System service exception. |
914| 12300002 | Invalid uid. |
915
916**示例:** 查询值为12345678的uid所属的系统帐号ID
917
918  ```ts
919  import { BusinessError } from '@ohos.base';
920  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
921  let uid: number = 12345678;
922  try {
923    accountManager.getOsAccountLocalIdForUid(uid).then((localId: number) => {
924      console.log('getOsAccountLocalIdForUid successfully, localId: ' + localId);
925    }).catch((err: BusinessError) => {
926      console.log('getOsAccountLocalIdForUid failed, error: ' + JSON.stringify(err));
927    });
928  } catch (err) {
929    console.log('getOsAccountLocalIdForUid exception: ' + JSON.stringify(err));
930  }
931  ```
932
933### getOsAccountLocalIdForUidSync<sup>10+</sup>
934
935getOsAccountLocalIdForUidSync(uid: number): number
936
937根据uid查询对应的系统帐号ID。使用同步方式返回结果。
938
939**系统能力:** SystemCapability.Account.OsAccount
940
941**参数:**
942
943| 参数名 | 类型   | 必填 | 说明      |
944| ------ | ------ | ---- | --------- |
945| uid    | number | 是   | 进程uid。 |
946
947**返回值:**
948
949| 类型                  | 说明                                     |
950| --------------------- | --------------------------------------- |
951| number | 返回指定uid对应的系统帐号ID。 |
952
953**错误码:**
954
955| 错误码ID | 错误信息       |
956| -------- | ------------- |
957| 12300002 | Invalid uid. |
958
959**示例:** 查询值为12345678的uid所属的系统帐号ID
960
961  ```ts
962  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
963  let uid: number = 12345678;
964  try {
965    let localId : number = accountManager.getOsAccountLocalIdForUidSync(uid);
966    console.log('getOsAccountLocalIdForUidSync successfully, localId: ' + localId);
967  } catch (err) {
968    console.log('getOsAccountLocalIdForUidSync exception: ' + JSON.stringify(err));
969  }
970  ```
971
972### getOsAccountLocalIdForDomain<sup>9+</sup>
973
974getOsAccountLocalIdForDomain(domainInfo: DomainAccountInfo, callback: AsyncCallback&lt;number&gt;): void
975
976根据域帐号信息,获取与其关联的系统帐号ID。使用callback异步回调。
977
978**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
979
980**系统能力:** SystemCapability.Account.OsAccount
981
982**参数:**
983
984| 参数名     | 类型                                    | 必填 | 说明                                                                         |
985| ---------- | --------------------------------------- | ---- | -------------------------------------------------------------------------- |
986| domainInfo | [DomainAccountInfo](#domainaccountinfo8) | 是   | 域帐号信息。                                                                |
987| callback   | AsyncCallback&lt;number&gt;             | 是   | 回调函数。如果查询成功,err为null,data为域帐号关联的系统帐号ID;否则为错误对象。 |
988
989**错误码:**
990
991| 错误码ID | 错误信息       |
992| -------- | ------------- |
993| 12300001 | System service exception. |
994| 12300002 | Invalid domainInfo. |
995
996**示例:**
997
998  ```ts
999  import { BusinessError } from '@ohos.base';
1000  let domainInfo: account_osAccount.DomainAccountInfo = {domain: 'testDomain', accountName: 'testAccountName'};
1001  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
1002  try {
1003    accountManager.getOsAccountLocalIdForDomain(domainInfo, (err: BusinessError, localId: number) => {
1004      if (err) {
1005        console.log('getOsAccountLocalIdForDomain failed, error: ' + JSON.stringify(err));
1006      } else {
1007        console.log('getOsAccountLocalIdForDomain successfully, localId: ' + localId);
1008      }
1009    });
1010  } catch (err) {
1011    console.log('getOsAccountLocalIdForDomain exception: ' + JSON.stringify(err));
1012  }
1013  ```
1014
1015### getOsAccountLocalIdForDomain<sup>9+</sup>
1016
1017getOsAccountLocalIdForDomain(domainInfo: DomainAccountInfo): Promise&lt;number&gt;
1018
1019根据域帐号信息,获取与其关联的系统帐号的帐号ID。使用Promise异步回调。
1020
1021**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
1022
1023**系统能力:** SystemCapability.Account.OsAccount
1024
1025**参数:**
1026
1027| 参数名     | 类型                                    | 必填 | 说明         |
1028| ---------- | --------------------------------------- | ---- | ------------ |
1029| domainInfo | [DomainAccountInfo](#domainaccountinfo8) | 是   | 域帐号信息。 |
1030
1031**返回值:**
1032
1033| 类型                  | 说明                                    |
1034| :-------------------- | :------------------------------------- |
1035| Promise&lt;number&gt; | Promise对象,返回域帐号关联的系统帐号ID。 |
1036
1037**错误码:**
1038
1039| 错误码ID | 错误信息       |
1040| -------- | ------------- |
1041| 12300001 | System service exception. |
1042| 12300002 | Invalid domainInfo. |
1043
1044**示例:**
1045
1046  ```ts
1047  import { BusinessError } from '@ohos.base';
1048  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
1049  let domainInfo: account_osAccount.DomainAccountInfo = {domain: 'testDomain', accountName: 'testAccountName'};
1050  try {
1051    accountManager.getOsAccountLocalIdForDomain(domainInfo).then((localId: number) => {
1052      console.log('getOsAccountLocalIdForDomain successfully, localId: ' + localId);
1053    }).catch((err: BusinessError) => {
1054      console.log('getOsAccountLocalIdForDomain failed, error: ' + JSON.stringify(err));
1055    });
1056  } catch (err) {
1057    console.log('getOsAccountLocalIdForDomain exception: ' + JSON.stringify(err));
1058  }
1059  ```
1060
1061### getOsAccountConstraints<sup>(deprecated)</sup>
1062
1063getOsAccountConstraints(localId: number, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void
1064
1065获取指定系统帐号的全部约束。使用callback异步回调。
1066
1067> **说明:**
1068>
1069> 从 API version 9开始支持,从API version 11开始废弃。替代方法仅向系统应用开放。
1070
1071**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
1072
1073**系统能力:** SystemCapability.Account.OsAccount
1074
1075**参数:**
1076
1077| 参数名   | 类型                                     | 必填 | 说明                                                                                           |
1078| -------- | ---------------------------------------- | ---- | -------------------------------------------------------------------------------------------- |
1079| localId  | number                                   | 是   | 系统帐号ID。                                                                                  |
1080| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | 是   | 回调函数,如果获取成功,err为null,data为该系统帐号的全部[约束](#系统帐号约束列表);否则为错误对象。 |
1081
1082**错误码:**
1083
1084| 错误码ID | 错误信息             |
1085| -------- | ------------------- |
1086| 12300001 | System service exception. |
1087| 12300002 | Invalid localId.    |
1088| 12300003 | Account not found. |
1089
1090**示例:** 获取ID为100的系统帐号的全部约束
1091
1092  ```ts
1093  import { BusinessError } from '@ohos.base';
1094  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
1095  let localId: number = 100;
1096  try {
1097    accountManager.getOsAccountConstraints(localId, (err: BusinessError, constraints: string[]) => {
1098      if (err) {
1099        console.log('getOsAccountConstraints failed, err: ' + JSON.stringify(err));
1100      } else {
1101        console.log('getOsAccountConstraints successfully, constraints: ' + JSON.stringify(constraints));
1102      }
1103    });
1104  } catch (err) {
1105    console.log('getOsAccountConstraints exception: ' + JSON.stringify(err));
1106  }
1107  ```
1108
1109### getOsAccountConstraints<sup>(deprecated)</sup>
1110
1111getOsAccountConstraints(localId: number): Promise&lt;Array&lt;string&gt;&gt;
1112
1113获取指定系统帐号的全部约束。使用Promise异步回调。
1114
1115> **说明:**
1116>
1117> 从 API version 9开始支持,从API version 11开始废弃。替代方法仅向系统应用开放。
1118
1119**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
1120
1121**系统能力:** SystemCapability.Account.OsAccount
1122
1123**参数:**
1124
1125| 参数名  | 类型   | 必填 | 说明         |
1126| ------- | ------ | ---- | ------------ |
1127| localId | number | 是   | 系统帐号ID。 |
1128
1129**返回值:**
1130
1131| 类型                               | 说明                                                       |
1132| ---------------------------------- | ---------------------------------------------------------- |
1133| Promise&lt;Array&lt;string&gt;&gt; | Promise对象,返回指定系统帐号的全部[约束](#系统帐号约束列表)。 |
1134
1135**错误码:**
1136
1137| 错误码ID | 错误信息             |
1138| -------- | ------------------- |
1139| 12300001 | System service exception. |
1140| 12300002 | Invalid localId.    |
1141| 12300003 | Account not found. |
1142
1143**示例:** 获取ID为100的系统帐号的全部约束
1144
1145  ```ts
1146  import { BusinessError } from '@ohos.base';
1147  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
1148  let localId: number = 100;
1149  try {
1150    accountManager.getOsAccountConstraints(localId).then((constraints: string[]) => {
1151      console.log('getOsAccountConstraints, constraints: ' + constraints);
1152    }).catch((err: BusinessError) => {
1153      console.log('getOsAccountConstraints err: ' + JSON.stringify(err));
1154    });
1155  } catch (e) {
1156    console.log('getOsAccountConstraints exception: ' + JSON.stringify(e));
1157  }
1158  ```
1159
1160### getActivatedOsAccountLocalIds<sup>9+</sup>
1161
1162getActivatedOsAccountLocalIds(callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
1163
1164查询当前处于激活状态的系统帐号的ID列表。使用callback异步回调。
1165
1166**系统能力:** SystemCapability.Account.OsAccount
1167
1168**参数:**
1169
1170| 参数名   | 类型                                     | 必填 | 说明                                                   |
1171| -------- | ---------------------------------------- | ---- | ------------------------------------------------------ |
1172| callback | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是   | 回调函数。如果查询成功,err为null,data为当前处于激活状态的系统帐号的ID列表;否则为错误对象。 |
1173
1174**错误码:**
1175
1176| 错误码ID | 错误信息       |
1177| -------- | ------------- |
1178| 12300001 | System service exception. |
1179
1180**示例:**
1181
1182  ```ts
1183  import { BusinessError } from '@ohos.base';
1184  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
1185  try {
1186    accountManager.getActivatedOsAccountLocalIds((err: BusinessError, idArray: number[])=>{
1187      console.log('getActivatedOsAccountLocalIds err:' + JSON.stringify(err));
1188      console.log('getActivatedOsAccountLocalIds idArray length:' + idArray.length);
1189      for(let i=0;i<idArray.length;i++) {
1190        console.info('activated os account id: ' + idArray[i]);
1191      }
1192    });
1193  } catch (e) {
1194    console.log('getActivatedOsAccountLocalIds exception: ' + JSON.stringify(e));
1195  }
1196  ```
1197
1198### getActivatedOsAccountLocalIds<sup>9+</sup>
1199
1200getActivatedOsAccountLocalIds(): Promise&lt;Array&lt;number&gt;&gt;
1201
1202查询当前处于激活状态的系统帐号的ID列表。使用Promise异步回调。
1203
1204**系统能力:** SystemCapability.Account.OsAccount
1205
1206**返回值:**
1207
1208| 类型                               | 说明                                               |
1209| :--------------------------------- | :------------------------------------------------ |
1210| Promise&lt;Array&lt;number&gt;&gt; | Promise对象,返回当前处于激活状态的系统帐号的ID列表。 |
1211
1212**错误码:**
1213
1214| 错误码ID | 错误信息       |
1215| -------- | ------------- |
1216| 12300001 | System service exception. |
1217
1218**示例:**
1219
1220  ```ts
1221  import { BusinessError } from '@ohos.base';
1222  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
1223  try {
1224    accountManager.getActivatedOsAccountLocalIds().then((idArray: number[]) => {
1225      console.log('getActivatedOsAccountLocalIds, idArray: ' + idArray);
1226    }).catch((err: BusinessError) => {
1227      console.log('getActivatedOsAccountLocalIds err: ' + JSON.stringify(err));
1228    });
1229  } catch (e) {
1230    console.log('getActivatedOsAccountLocalIds exception: ' + JSON.stringify(e));
1231  }
1232  ```
1233
1234### getCurrentOsAccount<sup>(deprecated)</sup>
1235
1236getCurrentOsAccount(callback: AsyncCallback&lt;OsAccountInfo&gt;): void
1237
1238查询当前进程所属的系统帐号的信息。使用callback异步回调。
1239
1240> **说明:**
1241>
1242> 从 API version 9开始支持,从API version 11开始废弃。替代方法仅向系统应用开放。
1243
1244**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTSohos.permission.GET_LOCAL_ACCOUNTS<sup>10+</sup>
1245
1246**系统能力:** SystemCapability.Account.OsAccount
1247
1248**参数:**
1249
1250| 参数名   | 类型                                                 | 必填 | 说明                                           |
1251| -------- | ---------------------------------------------------- | ---- | ---------------------------------------------- |
1252| callback | AsyncCallback&lt;[OsAccountInfo](#osaccountinfo)&gt; | 是   | 回调函数。如果查询成功,err为null,data为当前进程所属的系统帐号信息;否则为错误对象。 |
1253
1254**错误码:**
1255
1256| 错误码ID | 错误信息             |
1257| -------- | ------------------- |
1258| 12300001 | System service exception. |
1259
1260**示例:**
1261
1262  ```ts
1263  import { BusinessError } from '@ohos.base';
1264  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
1265  try {
1266    accountManager.getCurrentOsAccount((err: BusinessError, curAccountInfo: account_osAccount.OsAccountInfo)=>{
1267      console.log('getCurrentOsAccount err:' + JSON.stringify(err));
1268      console.log('getCurrentOsAccount curAccountInfo:' + JSON.stringify(curAccountInfo));
1269    });
1270  } catch (e) {
1271    console.log('getCurrentOsAccount exception: ' + JSON.stringify(e));
1272  }
1273  ```
1274
1275### getCurrentOsAccount<sup>(deprecated)</sup>
1276
1277getCurrentOsAccount(): Promise&lt;OsAccountInfo&gt;
1278
1279查询当前进程所属的系统帐号的信息。使用Promise异步回调。
1280
1281> **说明:**
1282>
1283> 从 API version 9开始支持,从API version 11开始废弃。替代方法仅向系统应用开放。
1284
1285**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTSohos.permission.GET_LOCAL_ACCOUNTS<sup>10+</sup>
1286
1287**系统能力:** SystemCapability.Account.OsAccount
1288
1289**返回值:**
1290
1291| 类型                                           | 说明                                       |
1292| ---------------------------------------------- | ----------------------------------------- |
1293| Promise&lt;[OsAccountInfo](#osaccountinfo)&gt; | Promise对象,返回当前进程所属的系统帐号信息。 |
1294
1295**错误码:**
1296
1297| 错误码ID | 错误信息             |
1298| -------- | ------------------- |
1299| 12300001 | System service exception. |
1300
1301**示例:**
1302
1303  ```ts
1304  import { BusinessError } from '@ohos.base';
1305  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
1306  try {
1307    accountManager.getCurrentOsAccount().then((accountInfo: account_osAccount.OsAccountInfo) => {
1308      console.log('getCurrentOsAccount, accountInfo: ' + JSON.stringify(accountInfo));
1309    }).catch((err: BusinessError) => {
1310      console.log('getCurrentOsAccount err: ' + JSON.stringify(err));
1311    });
1312  } catch (e) {
1313    console.log('getCurrentOsAccount exception: ' + JSON.stringify(e));
1314  }
1315  ```
1316
1317### getOsAccountType<sup>9+</sup>
1318
1319getOsAccountType(callback: AsyncCallback&lt;OsAccountType&gt;): void
1320
1321查询当前进程所属的系统帐号的帐号类型。使用callback异步回调。
1322
1323**系统能力:** SystemCapability.Account.OsAccount
1324
1325**参数:**
1326
1327| 参数名   | 类型                                                 | 必填 | 说明                                                 |
1328| -------- | ---------------------------------------------------- | ---- | ---------------------------------------------------- |
1329| callback | AsyncCallback&lt;[OsAccountType](#osaccounttype)&gt; | 是   | 回调函数。如果查询成功,err为null,data为当前进程所属的系统帐号的帐号类型;否则为错误对象。 |
1330
1331**错误码:**
1332
1333| 错误码ID | 错误信息             |
1334| -------- | ------------------- |
1335| 12300001 | System service exception. |
1336
1337**示例:**
1338
1339  ```ts
1340  import { BusinessError } from '@ohos.base';
1341  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
1342  try {
1343    accountManager.getOsAccountType((err: BusinessError, accountType: account_osAccount.OsAccountType) => {
1344      console.log('getOsAccountType err: ' + JSON.stringify(err));
1345      console.log('getOsAccountType accountType: ' + accountType);
1346    });
1347  } catch (e) {
1348    console.log('getOsAccountType exception: ' + JSON.stringify(e));
1349  }
1350  ```
1351
1352### getOsAccountType<sup>9+</sup>
1353
1354getOsAccountType(): Promise&lt;OsAccountType&gt;
1355
1356查询当前进程所属的系统帐号的帐号类型。使用Promise异步回调。
1357
1358**系统能力:** SystemCapability.Account.OsAccount
1359
1360**返回值:**
1361
1362| 类型                                           | 说明                                             |
1363| ---------------------------------------------- | ----------------------------------------------- |
1364| Promise&lt;[OsAccountType](#osaccounttype)&gt; | Promise对象,返回当前进程所属的系统帐号的帐号类型。 |
1365
1366**错误码:**
1367
1368| 错误码ID | 错误信息             |
1369| -------- | ------------------- |
1370| 12300001 | System service exception. |
1371
1372**示例:**
1373
1374  ```ts
1375  import { BusinessError } from '@ohos.base';
1376  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
1377  try {
1378    accountManager.getOsAccountType().then((accountType: account_osAccount.OsAccountType) => {
1379      console.log('getOsAccountType, accountType: ' + accountType);
1380    }).catch((err: BusinessError) => {
1381      console.log('getOsAccountType err: ' + JSON.stringify(err));
1382    });
1383  } catch (e) {
1384    console.log('getOsAccountType exception: ' + JSON.stringify(e));
1385  }
1386  ```
1387
1388### queryDistributedVirtualDeviceId<sup>9+</sup>
1389
1390queryDistributedVirtualDeviceId(callback: AsyncCallback&lt;string&gt;): void
1391
1392获取分布式虚拟设备ID。使用callback异步回调。
1393
1394**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC or ohos.permission.MANAGE_LOCAL_ACCOUNTS
1395
1396**系统能力:** SystemCapability.Account.OsAccount
1397
1398**参数:**
1399
1400| 参数名   | 类型                        | 必填 | 说明                                                                   |
1401| -------- | --------------------------- | ---- | --------------------------------------------------------------------- |
1402| callback | AsyncCallback&lt;string&gt; | 是   | 回调函数。如果获取成功,err为null,data为分布式虚拟设备ID;否则为错误对象。 |
1403
1404**错误码:**
1405
1406| 错误码ID | 错误信息             |
1407| -------- | ------------------- |
1408| 12300001 | System service exception. |
1409
1410**示例:**
1411
1412  ```ts
1413  import { BusinessError } from '@ohos.base';
1414  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
1415  try {
1416    accountManager.queryDistributedVirtualDeviceId((err: BusinessError, virtualID: string) => {
1417      console.log('queryDistributedVirtualDeviceId err: ' + JSON.stringify(err));
1418      console.log('queryDistributedVirtualDeviceId virtualID: ' + virtualID);
1419    });
1420  } catch (e) {
1421    console.log('queryDistributedVirtualDeviceId exception: ' + JSON.stringify(e));
1422  }
1423  ```
1424
1425### queryDistributedVirtualDeviceId<sup>9+</sup>
1426
1427queryDistributedVirtualDeviceId(): Promise&lt;string&gt;
1428
1429获取分布式虚拟设备ID。使用Promise异步回调。
1430
1431**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC or ohos.permission.MANAGE_LOCAL_ACCOUNTS
1432
1433**系统能力:** SystemCapability.Account.OsAccount
1434
1435**返回值:**
1436
1437| 类型                  | 说明                              |
1438| --------------------- | --------------------------------- |
1439| Promise&lt;string&gt; | Promise对象,返回分布式虚拟设备ID。 |
1440
1441**错误码:**
1442
1443| 错误码ID | 错误信息             |
1444| -------- | ------------------- |
1445| 12300001 | System service exception. |
1446
1447**示例:**
1448
1449  ```ts
1450  import { BusinessError } from '@ohos.base';
1451  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
1452  try {
1453    accountManager.queryDistributedVirtualDeviceId().then((virtualID: string) => {
1454      console.log('queryDistributedVirtualDeviceId, virtualID: ' + virtualID);
1455    }).catch((err: BusinessError) => {
1456      console.log('queryDistributedVirtualDeviceId err: ' + JSON.stringify(err));
1457    });
1458  } catch (e) {
1459    console.log('queryDistributedVirtualDeviceId exception: ' + JSON.stringify(e));
1460  }
1461  ```
1462
1463### getOsAccountLocalIdForSerialNumber<sup>9+</sup>
1464
1465getOsAccountLocalIdForSerialNumber(serialNumber: number, callback: AsyncCallback&lt;number&gt;): void
1466
1467通过SN码查询与其关联的系统帐号的帐号ID。使用callback异步回调。
1468
1469**系统能力:** SystemCapability.Account.OsAccount
1470
1471**参数:**
1472
1473| 参数名       | 类型                        | 必填 | 说明                                                                           |
1474| ------------ | --------------------------- | ---- | ---------------------------------------------------------------------------- |
1475| serialNumber | number                      | 是   | 帐号SN码。                                                                    |
1476| callback     | AsyncCallback&lt;number&gt; | 是   | 回调函数。如果成功,err为null,data为与SN码关联的系统帐号的帐号ID;否则为错误对象。 |
1477
1478**错误码:**
1479
1480| 错误码ID | 错误信息               |
1481| -------- | ------------------- |
1482| 12300001 | System service exception. |
1483| 12300002 | Invalid serialNumber. |
1484| 12300003 | The account indicated by serialNumber dose not exist. |
1485
1486**示例:** 查询与SN码12345关联的系统帐号的ID
1487
1488  ```ts
1489  import { BusinessError } from '@ohos.base';
1490  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
1491  let serialNumber: number = 12345;
1492  try {
1493    accountManager.getOsAccountLocalIdForSerialNumber(serialNumber, (err: BusinessError, localId: number)=>{
1494      console.log('ger localId err:' + JSON.stringify(err));
1495      console.log('get localId:' + localId + ' by serialNumber: ' + serialNumber);
1496    });
1497  } catch (e) {
1498    console.log('ger localId exception: ' + JSON.stringify(e));
1499  }
1500  ```
1501
1502### getOsAccountLocalIdForSerialNumber<sup>9+</sup>
1503
1504getOsAccountLocalIdForSerialNumber(serialNumber: number): Promise&lt;number&gt;
1505
1506通过SN码查询与其关联的系统帐号的帐号ID。使用Promise异步回调。
1507
1508**系统能力:** SystemCapability.Account.OsAccount
1509
1510**参数:**
1511
1512| 参数名       | 类型   | 必填 | 说明       |
1513| ------------ | ------ | ---- | ---------- |
1514| serialNumber | number | 是   | 帐号SN码。 |
1515
1516**返回值:**
1517
1518| 类型                  | 说明                                         |
1519| --------------------- | -------------------------------------------- |
1520| Promise&lt;number&gt; | Promise对象,返回与SN码关联的系统帐号的帐号ID。 |
1521
1522**错误码:**
1523
1524| 错误码ID | 错误信息               |
1525| -------- | ------------------- |
1526| 12300001 | System service exception. |
1527| 12300002 | Invalid serialNumber. |
1528| 12300003 | The account indicated by serialNumber dose not exist. |
1529
1530**示例:** 查询与SN码12345关联的系统帐号的ID
1531
1532  ```ts
1533  import { BusinessError } from '@ohos.base';
1534  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
1535  let serialNumber: number = 12345;
1536  try {
1537    accountManager.getOsAccountLocalIdForSerialNumber(serialNumber).then((localId: number) => {
1538      console.log('getOsAccountLocalIdForSerialNumber localId: ' + localId);
1539    }).catch((err: BusinessError) => {
1540      console.log('getOsAccountLocalIdForSerialNumber err: ' + JSON.stringify(err));
1541    });
1542  } catch (e) {
1543    console.log('getOsAccountLocalIdForSerialNumber exception: ' + JSON.stringify(e));
1544  }
1545  ```
1546
1547### getSerialNumberForOsAccountLocalId<sup>9+</sup>
1548
1549getSerialNumberForOsAccountLocalId(localId: number, callback: AsyncCallback&lt;number&gt;): void
1550
1551通过系统帐号ID获取与该系统帐号关联的SN码。使用callback异步回调。
1552
1553**系统能力:** SystemCapability.Account.OsAccount
1554
1555**参数:**
1556
1557| 参数名   | 类型                        | 必填 | 说明                                                                         |
1558| -------- | --------------------------- | ---- | -------------------------------------------------------------------------- |
1559| localId  | number                      | 是   | 系统帐号ID。                                                                 |
1560| callback | AsyncCallback&lt;number&gt; | 是   | 回调函数。如果获取成功,err为null,data为与该系统帐号关联的SN码;否则为错误对象。 |
1561
1562**错误码:**
1563
1564| 错误码ID | 错误信息             |
1565| -------- | ------------------- |
1566| 12300001 | System service exception. |
1567| 12300002 | Invalid localId.    |
1568| 12300003 | Account not found. |
1569
1570**示例:** 获取ID为100的系统帐号关联的SN码
1571
1572  ```ts
1573  import { BusinessError } from '@ohos.base';
1574  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
1575  let localId: number = 100;
1576  try {
1577    accountManager.getSerialNumberForOsAccountLocalId(localId, (err: BusinessError, serialNumber: number)=>{
1578      console.log('ger serialNumber err:' + JSON.stringify(err));
1579      console.log('get serialNumber:' + serialNumber + ' by localId: ' + localId);
1580    });
1581  } catch (e) {
1582    console.log('ger serialNumber exception: ' + JSON.stringify(e));
1583  }
1584  ```
1585
1586### getSerialNumberForOsAccountLocalId<sup>9+</sup>
1587
1588getSerialNumberForOsAccountLocalId(localId: number): Promise&lt;number&gt;
1589
1590通过系统帐号ID获取与该系统帐号关联的SN码。使用Promise异步回调。
1591
1592**系统能力:** SystemCapability.Account.OsAccount
1593
1594**参数:**
1595
1596| 参数名  | 类型   | 必填 | 说明          |
1597| ------- | ------ | ---- | ----------- |
1598| localId | number | 是   | 系统帐号ID。 |
1599
1600**返回值:**
1601
1602| 类型                  | 说明                                    |
1603| :-------------------- | :------------------------------------- |
1604| Promise&lt;number&gt; | Promise对象,返回与该系统帐号关联的SN码。 |
1605
1606**错误码:**
1607
1608| 错误码ID | 错误信息             |
1609| -------- | ------------------- |
1610| 12300001 | System service exception. |
1611| 12300002 | Invalid localId.    |
1612| 12300003 | Account not found. |
1613
1614**示例:** 获取ID为100的系统帐号关联的SN码
1615
1616  ```ts
1617  import { BusinessError } from '@ohos.base';
1618  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
1619  let localId: number = 100;
1620  try {
1621    accountManager.getSerialNumberForOsAccountLocalId(localId).then((serialNumber: number) => {
1622      console.log('getSerialNumberForOsAccountLocalId serialNumber: ' + serialNumber);
1623    }).catch((err: BusinessError) => {
1624      console.log('getSerialNumberForOsAccountLocalId err: ' + JSON.stringify(err));
1625    });
1626  } catch (e) {
1627    console.log('getSerialNumberForOsAccountLocalId exception: ' + JSON.stringify(e));
1628  }
1629  ```
1630
1631### isMultiOsAccountEnable<sup>(deprecated)</sup>
1632
1633isMultiOsAccountEnable(callback: AsyncCallback&lt;boolean&gt;): void
1634
1635判断是否支持多系统帐号。使用callback异步回调。
1636
1637> **说明:**
1638>
1639> 从 API version 7开始支持,从API version 9开始废弃。建议使用[checkMultiOsAccountEnabled](#checkmultiosaccountenabled9)。
1640
1641**系统能力:** SystemCapability.Account.OsAccount
1642
1643**参数:**
1644
1645| 参数名   | 类型                         | 必填 | 说明                                                     |
1646| -------- | ---------------------------- | ---- | ------------------------------------------------------ |
1647| callback | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。返回true表示支持多系统帐号;返回false表示不支持。 |
1648
1649**示例:**
1650
1651  ```ts
1652  import { BusinessError } from '@ohos.base';
1653  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
1654  accountManager.isMultiOsAccountEnable((err: BusinessError, isEnabled: boolean) => {
1655    if (err) {
1656      console.log('isMultiOsAccountEnable failed, error: ' + JSON.stringify(err));
1657    } else {
1658    console.log('isMultiOsAccountEnable successfully, isEnabled: ' + isEnabled);
1659    }
1660  });
1661  ```
1662
1663### isMultiOsAccountEnable<sup>(deprecated)</sup>
1664
1665isMultiOsAccountEnable(): Promise&lt;boolean&gt;
1666
1667判断是否支持多系统帐号。使用Promise异步回调。
1668
1669> **说明:**
1670>
1671> 从 API version 7开始支持,从API version 9开始废弃。建议使用[checkMultiOsAccountEnabled](#checkmultiosaccountenabled9-1)。
1672
1673**系统能力:** SystemCapability.Account.OsAccount
1674
1675**返回值:**
1676
1677| 类型                   | 说明                                                       |
1678| :--------------------- | :--------------------------------------------------------- |
1679| Promise&lt;boolean&gt; | Promise对象。返回true表示支持多系统帐号;返回false表示不支持。 |
1680
1681**示例:**
1682
1683  ```ts
1684  import { BusinessError } from '@ohos.base';
1685  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
1686  accountManager.isMultiOsAccountEnable().then((isEnabled: boolean) => {
1687    console.log('isMultiOsAccountEnable successfully, isEnabled: ' + isEnabled);
1688  }).catch((err: BusinessError) => {
1689    console.log('isMultiOsAccountEnable failed, error: ' + JSON.stringify(err));
1690  });
1691  ```
1692
1693### isOsAccountActived<sup>(deprecated)</sup>
1694
1695isOsAccountActived(localId: number, callback: AsyncCallback&lt;boolean&gt;): void
1696
1697判断指定系统帐号是否处于激活状态。使用callback异步回调。
1698
1699> **说明:**
1700>
1701> 从 API version 7开始支持从API version 9开始废弃。替代方法仅向系统应用开放。
1702
1703**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTSohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
1704
1705**系统能力:** SystemCapability.Account.OsAccount
1706
1707**参数:**
1708
1709| 参数名   | 类型                         | 必填 | 说明                                                     |
1710| -------- | ---------------------------- | ---- | ------------------------------------------------------ |
1711| localId  | number                       | 是   | 系统帐号ID。                                            |
1712| callback | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。返回true表示帐号已激活;返回false表示帐号未激活。 |
1713
1714**示例:** 判断ID为100的系统帐号是否处于激活状态
1715
1716  ```ts
1717  import { BusinessError } from '@ohos.base';
1718  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
1719  let localId: number = 100;
1720  accountManager.isOsAccountActived(localId, (err: BusinessError, isActived: boolean) => {
1721    if (err) {
1722      console.log('isOsAccountActived failed, err:' + JSON.stringify(err));
1723    } else {
1724      console.log('isOsAccountActived successfully, isActived:' + isActived);
1725    }
1726  });
1727  ```
1728
1729### isOsAccountActived<sup>(deprecated)</sup>
1730
1731isOsAccountActived(localId: number): Promise&lt;boolean&gt;
1732
1733判断指定系统帐号是否处于激活状态。使用Promise异步回调。
1734
1735> **说明:**
1736>
1737> 从 API version 7开始支持从API version 9开始废弃。替代方法仅向系统应用开放。
1738
1739**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTSohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
1740
1741**系统能力:** SystemCapability.Account.OsAccount
1742
1743**参数:**
1744
1745| 参数名  | 类型   | 必填 | 说明                               |
1746| ------- | ------ | ---- | --------------------------------- |
1747| localId | number | 是   | 系统帐号ID。 |
1748
1749**返回值:**
1750
1751| 类型                   | 说明                                                        |
1752| --------------------- | ----------------------------------------------------------- |
1753| Promise&lt;boolean&gt; | Promise对象。返回true表示帐号已激活;返回false表示帐号未激活。 |
1754
1755**示例:** 判断ID为100的系统帐号是否处于激活状态
1756
1757  ```ts
1758  import { BusinessError } from '@ohos.base';
1759  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
1760  let localId: number = 100;
1761  accountManager.isOsAccountActived(localId).then((isActived: boolean) => {
1762    console.log('isOsAccountActived successfully, isActived: ' + isActived);
1763  }).catch((err: BusinessError) => {
1764    console.log('isOsAccountActived failed, error: ' + JSON.stringify(err));
1765  });
1766  ```
1767
1768### isOsAccountConstraintEnable<sup>(deprecated)</sup>
1769
1770isOsAccountConstraintEnable(localId: number, constraint: string, callback: AsyncCallback&lt;boolean&gt;): void
1771
1772判断指定系统帐号是否具有指定约束。使用callback异步回调。
1773
1774> **说明:**
1775>
1776> 从 API version 7开始支持,从API version 9开始废弃。替代方法仅向系统应用开放。
1777
1778**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
1779
1780**系统能力:** SystemCapability.Account.OsAccount
1781
1782**参数:**
1783
1784| 参数名     | 类型                         | 必填 | 说明                                                                |
1785| ---------- | ---------------------------- | ---- | ----------------------------------------------------------------- |
1786| localId    | number                       | 是   | 系统帐号ID。                                 |
1787| constraint | string                       | 是   | 指定的[约束](#系统帐号约束列表)名称。                                |
1788| callback   | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。返回true表示已使能指定的约束;返回false表示未使能指定的约束。 |
1789
1790**示例:** 判断ID为100的系统帐号是否有禁止使用Wi-Fi的约束
1791
1792  ```ts
1793  import { BusinessError } from '@ohos.base';
1794  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
1795  let localId: number = 100;
1796  let constraint: string = 'constraint.wifi';
1797  accountManager.isOsAccountConstraintEnable(localId, constraint, (err: BusinessError, isEnabled: boolean) => {
1798    if (err) {
1799      console.log('isOsAccountConstraintEnable failed, error: ' + JSON.stringify(err));
1800    } else {
1801      console.log('isOsAccountConstraintEnable successfully, isEnabled: ' + isEnabled);
1802    }
1803  });
1804  ```
1805
1806### isOsAccountConstraintEnable<sup>(deprecated)</sup>
1807
1808isOsAccountConstraintEnable(localId: number, constraint: string): Promise&lt;boolean&gt;
1809
1810判断指定系统帐号是否具有指定约束。使用Promise异步回调。
1811
1812> **说明:**
1813>
1814> 从 API version 7开始支持,从API version 9开始废弃。替代方法仅向系统应用开放。
1815
1816**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
1817
1818**系统能力:** SystemCapability.Account.OsAccount
1819
1820**参数:**
1821
1822| 参数名     | 类型   | 必填 | 说明                                 |
1823| ---------- | ------ | ---- | ---------------------------------- |
1824| localId    | number | 是   | 系统帐号ID。  |
1825| constraint | string | 是   | 指定的[约束](#系统帐号约束列表)名称。 |
1826
1827**返回值:**
1828
1829| 类型                   | 说明                                                                   |
1830| ---------------------- | --------------------------------------------------------------------- |
1831| Promise&lt;boolean&gt; | Promise对象。返回true表示已使能指定的约束;返回false表示未使能指定的约束。 |
1832
1833**示例:** 判断ID为100的系统帐号是否有禁止使用Wi-Fi的约束
1834
1835  ```ts
1836  import { BusinessError } from '@ohos.base';
1837  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
1838  let localId: number = 100;
1839  let constraint: string = 'constraint.wifi';
1840  accountManager.isOsAccountConstraintEnable(localId, constraint).then((isEnabled: boolean) => {
1841    console.log('isOsAccountConstraintEnable successfully, isEnabled: ' + isEnabled);
1842  }).catch((err: BusinessError) => {
1843    console.log('isOsAccountConstraintEnable err: ' + JSON.stringify(err));
1844  });
1845  ```
1846
1847### isTestOsAccount<sup>(deprecated)</sup>
1848
1849isTestOsAccount(callback: AsyncCallback&lt;boolean&gt;): void
1850
1851检查当前系统帐号是否为测试帐号。使用callback异步回调。
1852
1853> **说明:**
1854>
1855> 从 API version 7开始支持,从API version 9开始废弃。建议使用[checkOsAccountTestable](#checkosaccounttestable9)。
1856
1857**系统能力:** SystemCapability.Account.OsAccount
1858
1859**参数:**
1860
1861| 参数名   | 类型                         | 必填 | 说明                                                                   |
1862| -------- | ---------------------------- | ---- | --------------------------------------------------------------------- |
1863| callback | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。返回true表示当前帐号为测试帐号;返回false表示当前帐号非测试帐号。 |
1864
1865**示例:**
1866
1867  ```ts
1868  import { BusinessError } from '@ohos.base';
1869  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
1870  accountManager.isTestOsAccount((err: BusinessError, isTestable: boolean) => {
1871    if (err) {
1872      console.log('isTestOsAccount failed, error: ' + JSON.stringify(err));
1873    } else {
1874      console.log('isTestOsAccount successfully, isTestable: ' + isTestable);
1875    }
1876  });
1877  ```
1878
1879### isTestOsAccount<sup>(deprecated)</sup>
1880
1881isTestOsAccount(): Promise&lt;boolean&gt;
1882
1883检查当前系统帐号是否为测试帐号。使用Promise异步回调。
1884
1885> **说明:**
1886>
1887> 从 API version 7开始支持,从API version 9开始废弃。建议使用[checkOsAccountTestable](#checkosaccounttestable9-1)。
1888
1889**系统能力:** SystemCapability.Account.OsAccount
1890
1891**返回值:**
1892
1893| 类型                   | 说明                                                                      |
1894| ---------------------- | ------------------------------------------------------------------------ |
1895| Promise&lt;boolean&gt; | Promise对象。返回true表示当前帐号为测试帐号;返回false表示当前帐号非测试帐号。 |
1896
1897**示例:**
1898
1899  ```ts
1900  import { BusinessError } from '@ohos.base';
1901  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
1902    accountManager.isTestOsAccount().then((isTestable: boolean) => {
1903      console.log('isTestOsAccount successfully, isTestable: ' + isTestable);
1904    }).catch((err: BusinessError) => {
1905      console.log('isTestOsAccount failed, error: ' + JSON.stringify(err));
1906  });
1907  ```
1908
1909### isOsAccountVerified<sup>(deprecated)</sup>
1910
1911isOsAccountVerified(callback: AsyncCallback&lt;boolean&gt;): void
1912
1913检查当前系统帐号是否已验证。使用callback异步回调。
1914
1915> **说明:**
1916>
1917> 从 API version 7开始支持,从API version 9开始废弃。建议使用[checkOsAccountVerified](#checkosaccountverified9)。
1918
1919**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTSohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
1920
1921**系统能力:** SystemCapability.Account.OsAccount
1922
1923**参数:**
1924
1925| 参数名   | 类型                         | 必填 | 说明                                                            |
1926| -------- | ---------------------------- | ---- | ------------------------------------------------------------- |
1927| callback | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。返回true表示指定帐号已验证;返回false表示指定帐号未验证。 |
1928
1929**示例:**
1930
1931  ```ts
1932  import { BusinessError } from '@ohos.base';
1933  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
1934  accountManager.isOsAccountVerified((err: BusinessError, isVerified: boolean) => {
1935    if (err) {
1936      console.log('isOsAccountVerified failed, error: ' + JSON.stringify(err));
1937    } else {
1938      console.log('isOsAccountVerified successfully, isVerified: ' + isVerified);
1939    }
1940  });
1941  ```
1942
1943### isOsAccountVerified<sup>(deprecated)</sup>
1944
1945isOsAccountVerified(localId: number, callback: AsyncCallback&lt;boolean&gt;): void
1946
1947检查指定系统帐号是否已验证。使用callback异步回调。
1948
1949> **说明:**
1950>
1951> 从 API version 7开始支持,从API version 9开始废弃。建议使用[checkOsAccountVerified](#checkosaccountverified9-1)。
1952
1953**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTSohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
1954
1955**系统能力:** SystemCapability.Account.OsAccount
1956
1957**参数:**
1958
1959| 参数名   | 类型                         | 必填 | 说明                                                            |
1960| -------- | ---------------------------- | ---- | ------------------------------------------------------------- |
1961| localId  | number                       | 是   | 系统帐号ID。                             |
1962| callback | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。返回true表示指定帐号已验证;返回false表示指定帐号未验证。 |
1963
1964**示例:**
1965
1966  ```ts
1967  import { BusinessError } from '@ohos.base';
1968  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
1969  let localId: number = 100;
1970  accountManager.isOsAccountVerified(localId, (err: BusinessError, isVerified: boolean) => {
1971    if (err) {
1972      console.log('isOsAccountVerified failed, error: ' + JSON.stringify(err));
1973    } else {
1974      console.log('isOsAccountVerified successfully, isVerified: ' + isVerified);
1975    }
1976  });
1977  ```
1978
1979### isOsAccountVerified<sup>(deprecated)</sup>
1980
1981isOsAccountVerified(localId?: number): Promise&lt;boolean&gt;
1982
1983检查指定系统帐号是否已验证。使用Promise异步回调。
1984
1985> **说明:**
1986>
1987> 从 API version 7开始支持,从API version 9开始废弃。建议使用[checkOsAccountVerified](#checkosaccountverified9-2)。
1988
1989**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTSohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
1990
1991**系统能力:** SystemCapability.Account.OsAccount
1992
1993**参数:**
1994
1995| 参数名  | 类型   | 必填 | 说明                                                              |
1996| ------- | ------ | ---- | ---------------------------------------------------------------- |
1997| localId | number | 否   | 系统帐号ID。不填则检查当前系统帐号是否已验证。 |
1998
1999**返回值:**
2000
2001| 类型                   | 说明                                                               |
2002| ---------------------- | ----------------------------------------------------------------- |
2003| Promise&lt;boolean&gt; | Promise对象。返回true表示指定帐号已验证;返回false表示指定帐号未验证。 |
2004
2005**示例:**
2006
2007  ```ts
2008  import { BusinessError } from '@ohos.base';
2009  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
2010  accountManager.isOsAccountVerified().then((isVerified: boolean) => {
2011    console.log('isOsAccountVerified successfully, isVerified: ' + isVerified);
2012  }).catch((err: BusinessError) => {
2013    console.log('isOsAccountVerified failed, error: ' + JSON.stringify(err));
2014  });
2015  ```
2016
2017### getCreatedOsAccountsCount<sup>(deprecated)</sup>
2018
2019getCreatedOsAccountsCount(callback: AsyncCallback&lt;number&gt;): void
2020
2021获取已创建的系统帐号数量。使用callback异步回调。
2022
2023> **说明:**
2024>
2025> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getOsAccountCount](#getosaccountcount9)。
2026
2027**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
2028
2029**系统能力:** SystemCapability.Account.OsAccount
2030
2031**参数:**
2032
2033| 参数名   | 类型                        | 必填 | 说明                                                                         |
2034| -------- | --------------------------- | ---- | -------------------------------------------------------------------------- |
2035| callback | AsyncCallback&lt;number&gt; | 是   | 回调函数。当获取成功时,err为null,data为已创建的系统帐号的数量;否则为错误对象。 |
2036
2037**示例:**
2038
2039  ```ts
2040  import { BusinessError } from '@ohos.base';
2041  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
2042  accountManager.getCreatedOsAccountsCount((err: BusinessError, count: number)=>{
2043    if (err) {
2044      console.log('getCreatedOsAccountsCount failed, error: ' + JSON.stringify(err));
2045    } else {
2046      console.log('getCreatedOsAccountsCount successfully, count: ' + count);
2047    }
2048  });
2049  ```
2050
2051### getCreatedOsAccountsCount<sup>(deprecated)</sup>
2052
2053getCreatedOsAccountsCount(): Promise&lt;number&gt;
2054
2055获取已创建的系统帐号数量,使用Promise异步回调。
2056
2057> **说明:**
2058>
2059> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getOsAccountCount](#getosaccountcount9-1)。
2060
2061**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
2062
2063**系统能力:** SystemCapability.Account.OsAccount
2064
2065**返回值:**
2066
2067| 类型                  | 说明                                    |
2068| --------------------- | -------------------------------------- |
2069| Promise&lt;number&gt; | Promise对象,返回已创建的系统帐号的数量。 |
2070
2071**示例:**
2072
2073  ```ts
2074  import { BusinessError } from '@ohos.base';
2075  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
2076  accountManager.getCreatedOsAccountsCount().then((count: number) => {
2077    console.log('getCreatedOsAccountsCount successfully, count: ' + count);
2078  }).catch((err: BusinessError) => {
2079    console.log('getCreatedOsAccountsCount failed, error: ' + JSON.stringify(err));
2080  });
2081  ```
2082
2083### getOsAccountLocalIdFromProcess<sup>(deprecated)</sup>
2084
2085getOsAccountLocalIdFromProcess(callback: AsyncCallback&lt;number&gt;): void
2086
2087获取当前进程所属的系统帐号ID,使用callback异步回调。
2088
2089> **说明:**
2090>
2091> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getOsAccountLocalId](#getosaccountlocalid9)。
2092
2093**系统能力:** SystemCapability.Account.OsAccount
2094
2095**参数:**
2096
2097| 参数名   | 类型                        | 必填 | 说明                                                                           |
2098| -------- | --------------------------- | ---- | ---------------------------------------------------------------------------- |
2099| callback | AsyncCallback&lt;number&gt; | 是   | 回调函数。当获取成功时,err为null,data为当前进程所属的系统帐号ID;否则为错误对象。 |
2100
2101**示例:**
2102
2103  ```ts
2104  import { BusinessError } from '@ohos.base';
2105  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
2106  accountManager.getOsAccountLocalIdFromProcess((err: BusinessError, localId: number) => {
2107    if (err) {
2108      console.log('getOsAccountLocalIdFromProcess failed, error: ' + JSON.stringify(err));
2109    } else {
2110      console.log('getOsAccountLocalIdFromProcess failed, error: ' + localId);
2111    }
2112  });
2113  ```
2114
2115### getOsAccountLocalIdFromProcess<sup>(deprecated)</sup>
2116
2117getOsAccountLocalIdFromProcess(): Promise&lt;number&gt;
2118
2119获取当前进程所属的系统帐号ID,使用Promise异步回调。
2120
2121> **说明:**
2122>
2123> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getOsAccountLocalId](#getosaccountlocalid9-1)。
2124
2125**系统能力:** SystemCapability.Account.OsAccount
2126
2127**返回值:**
2128
2129| 类型                  | 说明                                      |
2130| :-------------------- | :--------------------------------------- |
2131| Promise&lt;number&gt; | Promise对象,返回当前进程所属的系统帐号ID。 |
2132
2133**示例:**
2134
2135  ```ts
2136  import { BusinessError } from '@ohos.base';
2137  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
2138  accountManager.getOsAccountLocalIdFromProcess().then((localId: number) => {
2139    console.log('getOsAccountLocalIdFromProcess successfully, localId: ' + localId);
2140  }).catch((err: BusinessError) => {
2141    console.log('getOsAccountLocalIdFromProcess failed, error: ' + JSON.stringify(err));
2142  });
2143  ```
2144
2145### getOsAccountLocalIdFromUid<sup>(deprecated)</sup>
2146
2147getOsAccountLocalIdFromUid(uid: number, callback: AsyncCallback&lt;number&gt;): void
2148
2149根据uid查询对应的系统帐号ID。使用callback异步回调。
2150
2151> **说明:**
2152>
2153> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getOsAccountLocalIdForUid](#getosaccountlocalidforuid9)。
2154
2155**系统能力:** SystemCapability.Account.OsAccount
2156
2157**参数:**
2158
2159| 参数名   | 类型                        | 必填 | 说明                                                                    |
2160| -------- | --------------------------- | ---- | --------------------------------------------------------------------- |
2161| uid      | number                      | 是   | 进程uid。                                                              |
2162| callback | AsyncCallback&lt;number&gt; | 是   | 回调函数。如果查询成功,err为null,data为对应的系统帐号ID;否则为错误对象。 |
2163
2164**示例:** 查询值为12345678的uid所属的系统帐号ID
2165
2166  ```ts
2167  import { BusinessError } from '@ohos.base';
2168  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
2169  let uid: number = 12345678;
2170  accountManager.getOsAccountLocalIdFromUid(uid, (err: BusinessError, localId: number) => {
2171    if (err) {
2172      console.log('getOsAccountLocalIdFromUid failed, error: ' + JSON.stringify(err));
2173    } else {
2174      console.log('getOsAccountLocalIdFromUid successfully, localId: ' + localId);
2175    }
2176  });
2177  ```
2178
2179### getOsAccountLocalIdFromUid<sup>(deprecated)</sup>
2180
2181getOsAccountLocalIdFromUid(uid: number): Promise&lt;number&gt;
2182
2183根据uid查询对应的系统帐号ID,使用Promise异步回调。
2184
2185> **说明:**
2186>
2187> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getOsAccountLocalIdForUid](#getosaccountlocalidforuid9-1)。
2188
2189**系统能力:** SystemCapability.Account.OsAccount
2190
2191**参数:**
2192
2193| 参数名 | 类型   | 必填 | 说明      |
2194| ------ | ------ | ---- | --------- |
2195| uid    | number | 是   | 进程uid。 |
2196
2197**返回值:**
2198
2199| 类型                  | 说明                                  |
2200| :-------------------- | :----------------------------------- |
2201| Promise&lt;number&gt; | Promise对象,返回uid对应的系统帐号ID。 |
2202
2203**示例:** 查询值为12345678的uid所属的系统帐号ID
2204
2205  ```ts
2206  import { BusinessError } from '@ohos.base';
2207  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
2208  let uid: number = 12345678;
2209  accountManager.getOsAccountLocalIdFromUid(uid).then((localId: number) => {
2210    console.log('getOsAccountLocalIdFromUid successfully, localId: ' + localId);
2211  }).catch((err: BusinessError) => {
2212    console.log('getOsAccountLocalIdFromUid failed, error: ' + JSON.stringify(err));
2213  });
2214  ```
2215
2216### getOsAccountLocalIdFromDomain<sup>(deprecated)</sup>
2217
2218getOsAccountLocalIdFromDomain(domainInfo: DomainAccountInfo, callback: AsyncCallback&lt;number&gt;): void
2219
2220根据域帐号信息,获取与其关联的系统帐号的帐号ID。使用callback异步回调。
2221
2222> **说明:**
2223>
2224> 从 API version 8开始支持,从API version 9开始废弃。建议使用[getOsAccountLocalIdForDomain](#getosaccountlocalidfordomain9)。
2225
2226**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
2227
2228**系统能力:** SystemCapability.Account.OsAccount
2229
2230**参数:**
2231
2232| 参数名     | 类型                                    | 必填 | 说明                                                                         |
2233| ---------- | --------------------------------------- | ---- | --------------------------------------------------------------------------- |
2234| domainInfo | [DomainAccountInfo](#domainaccountinfo8) | 是   | 域帐号信息。                                                                |
2235| callback   | AsyncCallback&lt;number&gt;             | 是   | 回调函数,如果获取成功,err为null,data为域帐号关联的系统帐号ID;否则为错误对象。 |
2236
2237**示例:**
2238
2239  ```ts
2240  import { BusinessError } from '@ohos.base';
2241  let domainInfo: account_osAccount.DomainAccountInfo = {domain: 'testDomain', accountName: 'testAccountName'};
2242  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
2243  accountManager.getOsAccountLocalIdFromDomain(domainInfo, (err: BusinessError, localId: number) => {
2244    if (err) {
2245      console.log('getOsAccountLocalIdFromDomain failed, error: ' + JSON.stringify(err));
2246    } else {
2247      console.log('getOsAccountLocalIdFromDomain successfully, localId: ' + localId);
2248    }
2249  });
2250  ```
2251
2252### getOsAccountLocalIdFromDomain<sup>(deprecated)</sup>
2253
2254getOsAccountLocalIdFromDomain(domainInfo: DomainAccountInfo): Promise&lt;number&gt;
2255
2256根据域帐号信息,获取与其关联的系统帐号的帐号ID。使用Promise异步回调。
2257
2258> **说明:**
2259>
2260> 从 API version 8开始支持,从API version 9开始废弃。建议使用[getOsAccountLocalIdForDomain](#getosaccountlocalidfordomain9-1)。
2261
2262**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
2263
2264**系统能力:** SystemCapability.Account.OsAccount
2265
2266**参数:**
2267
2268| 参数名     | 类型                                    | 必填 | 说明         |
2269| ---------- | --------------------------------------- | ---- | ------------ |
2270| domainInfo | [DomainAccountInfo](#domainaccountinfo8) | 是   | 域帐号信息。 |
2271
2272**返回值:**
2273
2274| 类型                  | 说明                                    |
2275| :-------------------- | :------------------------------------- |
2276| Promise&lt;number&gt; | Promise对象,返回域帐号关联的系统帐号ID。 |
2277
2278**示例:**
2279
2280  ```ts
2281  import { BusinessError } from '@ohos.base';
2282  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
2283  let domainInfo: account_osAccount.DomainAccountInfo = {domain: 'testDomain', accountName: 'testAccountName'};
2284  accountManager.getOsAccountLocalIdFromDomain(domainInfo).then((localId: number) => {
2285    console.log('getOsAccountLocalIdFromDomain successfully, localId: ' + localId);
2286  }).catch((err: BusinessError) => {
2287    console.log('getOsAccountLocalIdFromDomain failed, error: ' + JSON.stringify(err));
2288  });
2289  ```
2290
2291### getOsAccountAllConstraints<sup>(deprecated)</sup>
2292
2293getOsAccountAllConstraints(localId: number, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void
2294
2295获取指定系统帐号的全部约束。使用callback异步回调。
2296
2297> **说明:**
2298>
2299> 从 API version 7开始支持,从API version 9开始废弃。替代方法仅向系统应用开放。
2300
2301**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
2302
2303**系统能力:** SystemCapability.Account.OsAccount
2304
2305**参数:**
2306
2307| 参数名   | 类型                                     | 必填 | 说明                                                                                             |
2308| -------- | ---------------------------------------- | ---- | ---------------------------------------------------------------------------------------------- |
2309| localId  | number                                   | 是   | 系统帐号ID。                                                                                    |
2310| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | 是   | 回调函数。如果获取成功,err为null,data为指定系统帐号的全部[约束](#系统帐号约束列表);否则为错误对象。 |
2311
2312**示例:** 获取ID为100的系统帐号的全部约束
2313
2314  ```ts
2315  import { BusinessError } from '@ohos.base';
2316  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
2317  let localId: number = 100;
2318  accountManager.getOsAccountAllConstraints(localId, (err: BusinessError, constraints: string[])=>{
2319    console.log('getOsAccountAllConstraints err:' + JSON.stringify(err));
2320    console.log('getOsAccountAllConstraints:' + JSON.stringify(constraints));
2321  });
2322  ```
2323
2324### getOsAccountAllConstraints<sup>(deprecated)</sup>
2325
2326getOsAccountAllConstraints(localId: number): Promise&lt;Array&lt;string&gt;&gt;
2327
2328> **说明:**
2329>
2330> 从 API version 7开始支持,从API version 9开始废弃。替代方法仅向系统应用开放。
2331
2332获取指定系统帐号的全部约束。使用Promise异步回调。
2333
2334**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
2335
2336**系统能力:** SystemCapability.Account.OsAccount
2337
2338**参数:**
2339
2340| 参数名  | 类型   | 必填 | 说明         |
2341| ------- | ------ | ---- | ------------ |
2342| localId | number | 是   | 系统帐号ID。 |
2343
2344**返回值:**
2345
2346| 类型                               | 说明                                                         |
2347| :--------------------------------- | :----------------------------------------------------------- |
2348| Promise&lt;Array&lt;string&gt;&gt; | Promise对象,返回指定系统帐号的全部[约束](#系统帐号约束列表)。 |
2349
2350**示例:** 获取ID为100的系统帐号的全部约束
2351
2352  ```ts
2353  import { BusinessError } from '@ohos.base';
2354  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
2355  let localId: number = 100;
2356  accountManager.getOsAccountAllConstraints(localId).then((constraints: string[]) => {
2357    console.log('getOsAccountAllConstraints, constraints: ' + constraints);
2358  }).catch((err: BusinessError) => {
2359    console.log('getOsAccountAllConstraints err: ' + JSON.stringify(err));
2360  });
2361  ```
2362
2363### queryActivatedOsAccountIds<sup>(deprecated)</sup>
2364
2365queryActivatedOsAccountIds(callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
2366
2367查询当前处于激活状态的系统帐号的ID列表。使用callback异步回调。
2368
2369> **说明:**
2370>
2371> 从 API version 8开始支持,从API version 9开始废弃。建议使用[getActivatedOsAccountLocalIds](#getactivatedosaccountlocalids9)。
2372
2373**系统能力:** SystemCapability.Account.OsAccount
2374
2375**参数:**
2376
2377| 参数名   | 类型                                     | 必填 | 说明                                                   |
2378| -------- | ---------------------------------------- | ---- | ------------------------------------------------------ |
2379| callback | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是   | 回调函数。如果查询成功,err为null,data为当前处于激活状态的系统帐号的ID列表;否则为错误对象。 |
2380
2381**示例:**
2382
2383  ```ts
2384  import { BusinessError } from '@ohos.base';
2385  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
2386  accountManager.queryActivatedOsAccountIds((err: BusinessError, idArray: number[])=>{
2387    console.log('queryActivatedOsAccountIds err:' + JSON.stringify(err));
2388    console.log('queryActivatedOsAccountIds idArray length:' + idArray.length);
2389    for(let i=0;i<idArray.length;i++) {
2390      console.info('activated os account id: ' + idArray[i]);
2391    }
2392  });
2393  ```
2394
2395### queryActivatedOsAccountIds<sup>(deprecated)</sup>
2396
2397queryActivatedOsAccountIds(): Promise&lt;Array&lt;number&gt;&gt;
2398
2399> **说明:**
2400>
2401> 从 API version 8开始支持,从API version 9开始废弃。建议使用[getActivatedOsAccountLocalIds](#getactivatedosaccountlocalids9-1)。
2402
2403查询当前处于激活状态的系统帐号的ID列表。使用Promise异步回调。
2404
2405**系统能力:** SystemCapability.Account.OsAccount
2406
2407**返回值:**
2408
2409| 类型                               | 说明                                               |
2410| ---------------------------------- | ------------------------------------------------- |
2411| Promise&lt;Array&lt;number&gt;&gt; | Promise对象,返回当前处于激活状态的系统帐号的ID列表。 |
2412
2413**示例:**
2414
2415  ```ts
2416  import { BusinessError } from '@ohos.base';
2417  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
2418  accountManager.queryActivatedOsAccountIds().then((idArray: number[]) => {
2419    console.log('queryActivatedOsAccountIds, idArray: ' + idArray);
2420  }).catch((err: BusinessError) => {
2421    console.log('queryActivatedOsAccountIds err: ' + JSON.stringify(err));
2422  });
2423  ```
2424
2425### queryCurrentOsAccount<sup>(deprecated)</sup>
2426
2427queryCurrentOsAccount(callback: AsyncCallback&lt;OsAccountInfo&gt;): void
2428
2429查询当前进程所属的系统帐号的信息。使用callback异步回调。
2430
2431> **说明:**
2432>
2433> 从 API version 7开始支持,从API version 9开始废弃。替代方法仅向系统应用开放。
2434
2435**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
2436
2437**系统能力:** SystemCapability.Account.OsAccount
2438
2439**参数:**
2440
2441| 参数名   | 类型                                                 | 必填 | 说明                                           |
2442| -------- | ---------------------------------------------------- | ---- | ---------------------------------------------- |
2443| callback | AsyncCallback&lt;[OsAccountInfo](#osaccountinfo)&gt; | 是   | 回调函数。如果查询成功,err为null,data为当前进程所属的系统帐号信息;否则为错误对象。 |
2444
2445**示例:**
2446
2447  ```ts
2448  import { BusinessError } from '@ohos.base';
2449  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
2450  accountManager.queryCurrentOsAccount((err: BusinessError, curAccountInfo: account_osAccount.OsAccountInfo)=>{
2451    console.log('queryCurrentOsAccount err:' + JSON.stringify(err));
2452    console.log('queryCurrentOsAccount curAccountInfo:' + JSON.stringify(curAccountInfo));
2453  });
2454  ```
2455
2456### queryCurrentOsAccount<sup>(deprecated)</sup>
2457
2458queryCurrentOsAccount(): Promise&lt;OsAccountInfo&gt;
2459
2460查询当前进程所属的系统帐号的信息。使用Promise异步回调。
2461
2462> **说明:**
2463>
2464> 从 API version 7开始支持,从API version 9开始废弃。替代方法仅向系统应用开放。
2465
2466**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS
2467
2468**系统能力:** SystemCapability.Account.OsAccount
2469
2470**返回值:**
2471
2472| 类型                                           | 说明                                       |
2473| ---------------------------------------------- | ------------------------------------------ |
2474| Promise&lt;[OsAccountInfo](#osaccountinfo)&gt; | Promise对象,返回当前进程所属的系统帐号信息。 |
2475
2476**示例:**
2477
2478  ```ts
2479  import { BusinessError } from '@ohos.base';
2480  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
2481  accountManager.queryCurrentOsAccount().then((accountInfo: account_osAccount.OsAccountInfo) => {
2482    console.log('queryCurrentOsAccount, accountInfo: ' + JSON.stringify(accountInfo));
2483  }).catch((err: BusinessError) => {
2484    console.log('queryCurrentOsAccount err: ' + JSON.stringify(err));
2485  });
2486  ```
2487
2488### getOsAccountTypeFromProcess<sup>(deprecated)</sup>
2489
2490getOsAccountTypeFromProcess(callback: AsyncCallback&lt;OsAccountType&gt;): void
2491
2492查询当前进程所属的系统帐号的帐号类型。使用callback异步回调。
2493
2494> **说明:**
2495>
2496> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getOsAccountType](#getosaccounttype9)。
2497
2498**系统能力:** SystemCapability.Account.OsAccount
2499
2500**参数:**
2501
2502| 参数名   | 类型                                                 | 必填 | 说明                                                 |
2503| -------- | ---------------------------------------------------- | ---- | ---------------------------------------------------- |
2504| callback | AsyncCallback&lt;[OsAccountType](#osaccounttype)&gt; | 是   | 回调函数。如果查询成功,err为null,data为当前进程所属的系统帐号的帐号类型;否则为错误对象。 |
2505
2506**示例:**
2507
2508  ```ts
2509  import { BusinessError } from '@ohos.base';
2510  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
2511  accountManager.getOsAccountTypeFromProcess((err: BusinessError, accountType: account_osAccount.OsAccountType) => {
2512    console.log('getOsAccountTypeFromProcess err: ' + JSON.stringify(err));
2513    console.log('getOsAccountTypeFromProcess accountType: ' + accountType);
2514  });
2515  ```
2516
2517### getOsAccountTypeFromProcess<sup>(deprecated)</sup>
2518
2519getOsAccountTypeFromProcess(): Promise&lt;OsAccountType&gt;
2520
2521查询当前进程所属的系统帐号的帐号类型。使用Promise异步回调。
2522
2523> **说明:**
2524>
2525> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getOsAccountType](#getosaccounttype9-1)。
2526
2527**系统能力:** SystemCapability.Account.OsAccount
2528
2529**返回值:**
2530
2531| 类型                                           | 说明                                            |
2532| ---------------------------------------------- | ----------------------------------------------- |
2533| Promise&lt;[OsAccountType](#osaccounttype)&gt; | Promise对象,返回当前进程所属的系统帐号的帐号类型。 |
2534
2535**示例:**
2536
2537  ```ts
2538  import { BusinessError } from '@ohos.base';
2539  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
2540  accountManager.getOsAccountTypeFromProcess().then((accountType: account_osAccount.OsAccountType) => {
2541    console.log('getOsAccountTypeFromProcess, accountType: ' + accountType);
2542  }).catch((err: BusinessError) => {
2543    console.log('getOsAccountTypeFromProcess err: ' + JSON.stringify(err));
2544  });
2545  ```
2546
2547### getDistributedVirtualDeviceId<sup>(deprecated)</sup>
2548
2549getDistributedVirtualDeviceId(callback: AsyncCallback&lt;string&gt;): void
2550
2551获取分布式虚拟设备ID。使用callback异步回调。
2552
2553> **说明:**
2554>
2555> 从 API version 7开始支持,从API version 9开始废弃。建议使用[queryDistributedVirtualDeviceId](#querydistributedvirtualdeviceid9)。
2556
2557**需要权限:** ohos.permission.DISTRIBUTED_DATASYNCohos.permission.MANAGE_LOCAL_ACCOUNTS
2558
2559**系统能力:** SystemCapability.Account.OsAccount
2560
2561**参数:**
2562
2563| 参数名   | 类型                        | 必填 | 说明                                                                    |
2564| -------- | --------------------------- | ---- | --------------------------------------------------------------------- |
2565| callback | AsyncCallback&lt;string&gt; | 是   | 回调函数。如果获取成功,err为null,data为分布式虚拟设备ID;否则为错误对象。 |
2566
2567**示例:**
2568
2569  ```ts
2570  import { BusinessError } from '@ohos.base';
2571  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
2572  accountManager.getDistributedVirtualDeviceId((err: BusinessError, virtualID: string) => {
2573    console.log('getDistributedVirtualDeviceId err: ' + JSON.stringify(err));
2574    console.log('getDistributedVirtualDeviceId virtualID: ' + virtualID);
2575  });
2576  ```
2577
2578### getDistributedVirtualDeviceId<sup>(deprecated)</sup>
2579
2580getDistributedVirtualDeviceId(): Promise&lt;string&gt;
2581
2582获取分布式虚拟设备ID。使用Promise异步回调。
2583
2584> **说明:**
2585>
2586> 从 API version 7开始支持,从API version 9开始废弃。建议使用[queryDistributedVirtualDeviceId](#querydistributedvirtualdeviceid9-1)。
2587
2588**需要权限:** ohos.permission.DISTRIBUTED_DATASYNCohos.permission.MANAGE_LOCAL_ACCOUNTS
2589
2590**系统能力:** SystemCapability.Account.OsAccount
2591
2592**返回值:**
2593
2594| 类型                  | 说明                              |
2595| --------------------- | --------------------------------- |
2596| Promise&lt;string&gt; | Promise对象,返回分布式虚拟设备ID。 |
2597
2598**示例:**
2599
2600  ```ts
2601  import { BusinessError } from '@ohos.base';
2602  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
2603  accountManager.getDistributedVirtualDeviceId().then((virtualID: string) => {
2604    console.log('getDistributedVirtualDeviceId, virtualID: ' + virtualID);
2605  }).catch((err: BusinessError) => {
2606    console.log('getDistributedVirtualDeviceId err: ' + JSON.stringify(err));
2607  });
2608  ```
2609
2610### getOsAccountLocalIdBySerialNumber<sup>(deprecated)</sup>
2611
2612getOsAccountLocalIdBySerialNumber(serialNumber: number, callback: AsyncCallback&lt;number&gt;): void
2613
2614通过SN码查询与其关联的系统帐号的帐号ID。使用callback异步回调。
2615
2616> **说明:**
2617>
2618> 从 API version 8开始支持,从API version 9开始废弃。建议使用[getOsAccountLocalIdForSerialNumber](#getosaccountlocalidforserialnumber9)。
2619
2620**系统能力:** SystemCapability.Account.OsAccount
2621
2622**参数:**
2623
2624| 参数名       | 类型                        | 必填 | 说明                                                                               |
2625| ------------ | --------------------------- | ---- | -------------------------------------------------------------------------------- |
2626| serialNumber | number                      | 是   | 帐号SN码。                                                                        |
2627| callback     | AsyncCallback&lt;number&gt; | 是   | 回调函数。如果查询成功,err为null,data为与SN码关联的系统帐号的帐号ID;否则为错误对象。 |
2628
2629**示例:** 查询与SN码12345关联的系统帐号的ID
2630
2631  ```ts
2632  import { BusinessError } from '@ohos.base';
2633  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
2634  let serialNumber: number = 12345;
2635  accountManager.getOsAccountLocalIdBySerialNumber(serialNumber, (err: BusinessError, localId: number)=>{
2636    console.log('ger localId err:' + JSON.stringify(err));
2637    console.log('get localId:' + localId + ' by serialNumber: ' + serialNumber);
2638  });
2639  ```
2640
2641### getOsAccountLocalIdBySerialNumber<sup>(deprecated)</sup>
2642
2643getOsAccountLocalIdBySerialNumber(serialNumber: number): Promise&lt;number&gt;
2644
2645通过SN码查询与其关联的系统帐号的帐号ID。使用Promise异步回调。
2646
2647> **说明:**
2648>
2649> 从 API version 8开始支持,从API version 9开始废弃。建议使用[getOsAccountLocalIdForSerialNumber](#getosaccountlocalidforserialnumber9-1)。
2650
2651**系统能力:** SystemCapability.Account.OsAccount
2652
2653**参数:**
2654
2655| 参数名       | 类型   | 必填 | 说明       |
2656| ------------ | ------ | ---- | ---------- |
2657| serialNumber | number | 是   | 帐号SN码。 |
2658
2659**返回值:**
2660
2661| 类型                  | 说明                                                         |
2662| --------------------- | -------------------------------------------- |
2663| Promise&lt;number&gt; | Promise对象,返回与SN码关联的系统帐号的帐号ID。 |
2664
2665**示例:** 查询与SN码12345关联的系统帐号的ID
2666
2667  ```ts
2668  import { BusinessError } from '@ohos.base';
2669  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
2670  let serialNumber: number = 12345;
2671  accountManager.getOsAccountLocalIdBySerialNumber(serialNumber).then((localId: number) => {
2672    console.log('getOsAccountLocalIdBySerialNumber localId: ' + localId);
2673  }).catch((err: BusinessError) => {
2674    console.log('getOsAccountLocalIdBySerialNumber err: ' + JSON.stringify(err));
2675  });
2676  ```
2677
2678### getSerialNumberByOsAccountLocalId<sup>(deprecated)</sup>
2679
2680getSerialNumberByOsAccountLocalId(localId: number, callback: AsyncCallback&lt;number&gt;): void
2681
2682通过系统帐号ID获取与该系统帐号关联的SN码。使用callback异步回调。
2683
2684> **说明:**
2685>
2686> 从 API version 8开始支持,从API version 9开始废弃。建议使用[getSerialNumberForOsAccountLocalId](#getserialnumberforosaccountlocalid9)。
2687
2688**系统能力:** SystemCapability.Account.OsAccount
2689
2690**参数:**
2691
2692| 参数名   | 类型                        | 必填 | 说明                                                                         |
2693| -------- | --------------------------- | ---- | --------------------------------------------------------------------------- |
2694| localId  | number                      | 是   | 系统帐号ID。                                                                 |
2695| callback | AsyncCallback&lt;number&gt; | 是   | 回调函数。如果获取成功,err为null,data为与该系统帐号关联的SN码;否则为错误对象。 |
2696
2697**示例:** 获取ID为100的系统帐号关联的SN码
2698
2699  ```ts
2700  import { BusinessError } from '@ohos.base';
2701  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
2702  let localId: number = 100;
2703  accountManager.getSerialNumberByOsAccountLocalId(localId, (err: BusinessError, serialNumber: number)=>{
2704    console.log('ger serialNumber err:' + JSON.stringify(err));
2705    console.log('get serialNumber:' + serialNumber + ' by localId: ' + localId);
2706  });
2707  ```
2708
2709### getSerialNumberByOsAccountLocalId<sup>(deprecated)</sup>
2710
2711getSerialNumberByOsAccountLocalId(localId: number): Promise&lt;number&gt;
2712
2713通过系统帐号ID获取与该系统帐号关联的SN码。使用Promise异步回调。
2714
2715> **说明:**
2716>
2717> 从 API version 8开始支持,从API version 9开始废弃。建议使用[getSerialNumberForOsAccountLocalId](#getserialnumberforosaccountlocalid9-1)。
2718
2719**系统能力:** SystemCapability.Account.OsAccount
2720
2721**参数:**
2722
2723| 参数名  | 类型   | 必填 | 说明          |
2724| ------- | ------ | ---- | ----------- |
2725| localId | number | 是   | 系统帐号ID。 |
2726
2727**返回值:**
2728
2729| 类型                  | 说明                                    |
2730| --------------------- | -------------------------------------- |
2731| Promise&lt;number&gt; | Promise对象,返回与该系统帐号关联的SN码。 |
2732
2733**示例:** 获取ID为100的系统帐号关联的SN码
2734
2735  ```ts
2736  import { BusinessError } from '@ohos.base';
2737  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
2738  let localId: number = 100;
2739  accountManager.getSerialNumberByOsAccountLocalId(localId).then((serialNumber: number) => {
2740    console.log('getSerialNumberByOsAccountLocalId serialNumber: ' + serialNumber);
2741  }).catch((err: BusinessError) => {
2742    console.log('getSerialNumberByOsAccountLocalId err: ' + JSON.stringify(err));
2743  });
2744  ```
2745
2746## OsAccountInfo
2747
2748表示系统帐号信息。
2749
2750**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount2751
2752| 名称                         | 类型                                                         | 必填 | 说明                              |
2753| ------------------------------ | ------------------------------------------------------------ | ---- | --------------------------------- |
2754| localId                        | number                                                       | 是   | 系统帐号ID。                      |
2755| localName                      | string                                                       | 是   | 系统帐号名称。                    |
2756| type                           | [OsAccountType](#osaccounttype)                              | 是   | 系统帐号类型。                      |
2757| constraints                    | Array&lt;string&gt;                                          | 否   | 系统帐号[约束](#系统帐号约束列表),默认为空。|
2758| isVerified<sup>(deprecated)</sup> | boolean                                                   | 是   | 帐号是否验证。<br>**说明**: 从API version 7开始支持,从API version 11开始废弃。                     |
2759| isUnlocked<sup>11+</sup>      | boolean                                                       | 是   | 帐号是否已解锁(EL2级别目录是否解密)。                      |
2760| photo<sup>8+</sup>             | string                                                       | 否   | 系统帐号头像,默认为空。                      |
2761| createTime<sup>8+</sup>        | number                                                       | 是   | 系统帐号创建时间。                  |
2762| lastLoginTime<sup>8+</sup>     | number                                                       | 否   | 系统帐号最后一次登录时间,默认为空。          |
2763| serialNumber<sup>8+</sup>      | number                                                       | 是   | 系统帐号SN码。                      |
2764| isActived<sup>(deprecated)</sup>         | boolean                                            | 是   | 系统帐号激活状态。<br>**说明**: 从API version 7开始支持,从API version 11开始废弃。                  |
2765| isActivated<sup>11+</sup>         | boolean                                                   | 是   | 系统帐号激是否激活。                  |
2766| isCreateCompleted<sup>8+</sup> | boolean                                                      | 是   | 系统帐号创建是否完整。              |
2767| distributedInfo                | [distributedAccount.DistributedInfo](js-apis-distributed-account.md#distributedinfo) | 否   | 分布式帐号信息,默认为空。                    |
2768| domainInfo<sup>8+</sup>        | [DomainAccountInfo](#domainaccountinfo8)                      | 否   | 域帐号信息,默认为空。                        |
2769
2770## DomainAccountInfo<sup>8+</sup>
2771
2772表示域帐号信息。
2773
2774**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount2775
2776| 名称      | 类型   | 必填 | 说明       |
2777| ----------- | ------ | ---- | ---------- |
2778| domain      | string | 是   | 域名。     |
2779| accountName | string | 是   | 域帐号名。 |
2780
2781## 系统帐号约束列表
2782
2783| 约束                                  | 说明                           |
2784| ------------------------------------- | ------------------------------ |
2785| constraint.wifi                       | 禁止使用Wi-Fi                  |
2786| constraint.wifi.set                   | 禁止配置Wi-Fi                  |
2787| constraint.locale.set                 | 禁止配置设备语言               |
2788| constraint.app.accounts               | 禁止添加和删除应用帐号         |
2789| constraint.apps.install               | 禁止安装应用                   |
2790| constraint.apps.uninstall             | 禁止卸载应用                   |
2791| constraint.location.shared            | 禁止打开位置共享               |
2792| constraint.unknown.sources.install    | 禁止安装未知来源的应用         |
2793| constraint.global.unknown.app.install | 禁止所有用户安装未知来源的应用 |
2794| constraint.bluetooth.set              | 禁止配置蓝牙                   |
2795| constraint.bluetooth | 禁止使用蓝牙 |
2796| constraint.bluetooth.share | 禁止共享使用蓝牙 |
2797| constraint.usb.file.transfer | 禁止通过USB传输文件 |
2798| constraint.credentials.set | 禁止配置用户凭据 |
2799| constraint.os.account.remove | 禁止删除用户 |
2800| constraint.managed.profile.remove | 禁止删除此用户的托管配置文件 |
2801| constraint.debug.features.use | 禁止启用或访问调试功能 |
2802| constraint.vpn.set | 禁止配置VPN |
2803| constraint.date.time.set | 禁止配置日期时间和时区 |
2804| constraint.tethering.config | 禁止配置Tethering |
2805| constraint.network.reset | 禁止重置网络设置 |
2806| constraint.factory.reset | 禁止出厂设置 |
2807| constraint.os.account.create | 禁止创建新用户 |
2808| constraint.add.managed.profile | 禁止添加托管配置文件 |
2809| constraint.apps.verify.disable | 强制应用程序验证 |
2810| constraint.cell.broadcasts.set | 禁止配置小区广播 |
2811| constraint.mobile.networks.set | 禁止配置移动网络 |
2812| constraint.control.apps | 禁止在设置或启动模块中修改应用程序 |
2813| constraint.physical.media | 禁止装载物理外部介质 |
2814| constraint.microphone | 禁止使用麦克风 |
2815| constraint.microphone.unmute | 禁止取消麦克风静音 |
2816| constraint.volume.adjust | 禁止调整音量 |
2817| constraint.calls.outgoing | 禁止拨打外呼电话 |
2818| constraint.sms.use | 禁止发送或接收短信 |
2819| constraint.fun | 禁止享受乐趣 |
2820| constraint.windows.create | 禁止创建应用程序窗口以外的窗口 |
2821| constraint.system.error.dialogs | 禁止显示崩溃或无响应应用程序的系统错误对话框 |
2822| constraint.cross.profile.copy.paste | 禁止通过将数据粘贴到其他用户或配置文件来导出剪贴板内容 |
2823| constraint.beam.outgoing | 禁止使用NFC从应用程序传送数据 |
2824| constraint.wallpaper | 禁止管理壁纸 |
2825| constraint.safe.boot | 禁止进入安全引导模式 |
2826| constraint.parent.profile.app.linking | 允许父配置文件中的应用程序处理来自托管配置文件的Web链接 |
2827| constraint.audio.record | 禁止录制音频 |
2828| constraint.camera.use | 禁止使用摄像机 |
2829| constraint.os.account.background.run | 禁止在后台运行 |
2830| constraint.data.roam | 禁止漫游通话时使用蜂窝数据 |
2831| constraint.os.account.set.icon | 禁止修改用户头像 |
2832| constraint.wallpaper.set | 禁止设置壁纸 |
2833| constraint.oem.unlock | 禁止启用oem解锁 |
2834| constraint.device.unmute | 禁止取消设备静音 |
2835| constraint.password.unified | 禁止托管配置文件与主用户进行统一锁屏质询 |
2836| constraint.autofill | 禁止使用自动填充服务 |
2837| constraint.content.capture | 禁止捕获用户屏幕 |
2838| constraint.content.suggestions | 禁止接收内容建议 |
2839| constraint.os.account.start | 禁止切换用户 |
2840| constraint.location.set | 禁止配置位置服务 |
2841| constraint.airplane.mode.set | 禁止飞行模式 |
2842| constraint.brightness.set | 禁止配置亮度 |
2843| constraint.share.into.profile | 禁止将主要用户的文件/图片/数据共享到托管配置文件中 |
2844| constraint.ambient.display | 禁止显示环境 |
2845| constraint.screen.timeout.set | 禁止配置屏幕关闭的超时 |
2846| constraint.print | 禁止打印 |
2847| constraint.private.dns.set | 禁止配置专用DNS |
2848