harmony 鸿蒙@ohos.account.osAccount (System Account Management)

  • 2025-06-12
  • 浏览 (3)

@ohos.account.osAccount (System Account Management)

The osAccount module provides basic capabilities for managing system (OS) accounts, including adding, deleting, querying, setting, subscribing to, and enabling a system account.

NOTE

The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.

Modules to Import

import { osAccount } from '@kit.BasicServicesKit';

osAccount.getAccountManager

getAccountManager(): AccountManager

Obtains an AccountManager instance.

System capability: SystemCapability.Account.OsAccount

Return value

Type Description
AccountManager AccountManager instance obtained.

Example

  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();

OsAccountType

Enumerates the system account types.

System capability: SystemCapability.Account.OsAccount

Name Value Description
ADMIN 0 Administrator account.
NORMAL 1 Normal account.
GUEST 2 Guest account.

AccountManager

Provides APIs for managing system accounts.

checkMultiOsAccountEnabled9+

checkMultiOsAccountEnabled(callback: AsyncCallback<boolean>): void

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

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
callback AsyncCallback<boolean> Yes Callback used to return the result. The value true means multiple system accounts are supported; the value false means the opposite.

Error codes

ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
12300001 The system service works abnormally.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  try {
    accountManager.checkMultiOsAccountEnabled((err: BusinessError, isEnabled: boolean) => {
      if (err) {
        console.error(`checkMultiOsAccountEnabled failed, code is ${err.code}, message is ${err.message}`);
      } else {
      console.log('checkMultiOsAccountEnabled successfully, isEnabled: ' + isEnabled);
      }
    });
  } catch (err) {
    console.log('checkMultiOsAccountEnabled failed, error:' + JSON.stringify(err));
  }

checkMultiOsAccountEnabled9+

checkMultiOsAccountEnabled(): Promise<boolean>

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

System capability: SystemCapability.Account.OsAccount

Return value

Type Description
Promise<boolean> Promise used to return the result. The value true means multiple system accounts are supported; the value false means the opposite.

Error codes

ID Error Message
12300001 The system service works abnormally.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  try {
    let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
    accountManager.checkMultiOsAccountEnabled().then((isEnabled: boolean) => {
      console.log('checkMultiOsAccountEnabled successfully, isEnabled: ' + isEnabled);
    }).catch((err: BusinessError) => {
      console.error(`checkMultiOsAccountEnabled failed, code is ${err.code}, message is ${err.message}`);
    });
  } catch (err) {
    console.log('checkMultiOsAccountEnabled failed, error:' + JSON.stringify(err));
  }

checkOsAccountActivated(deprecated)

checkOsAccountActivated(localId: number, callback: AsyncCallback<boolean>): void

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

NOTE

This API is supported since API version 9 and deprecated since API version 11. The substitute API is available only to system applications.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS (available only for system applications)

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
localId number Yes ID of the target system account.
callback AsyncCallback<boolean> Yes Callback used to return the result. The value true means the account is activated; the value false means the opposite.

Error codes

ID Error Message
201 Permission denied.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
12300001 The system service works abnormally.
12300002 Invalid localId.
12300003 Account not found.

Example: Check whether system account 100 is activated.

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  let localId: number = 100;
  try {
    accountManager.checkOsAccountActivated(localId, (err: BusinessError, isActivated: boolean) => {
      if (err) {
        console.log('checkOsAccountActivated failed, error:' + JSON.stringify(err));
      } else {
        console.log('checkOsAccountActivated successfully, isActivated:' + isActivated);
      }
    });
  } catch (err) {
    console.log('checkOsAccountActivated exception: ' + JSON.stringify(err));
  }

checkOsAccountActivated(deprecated)

checkOsAccountActivated(localId: number): Promise<boolean>

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

NOTE

This API is supported since API version 9 and deprecated since API version 11. The substitute API is available only to system applications.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS (available only for system applications)

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
localId number Yes ID of the target system account.

Return value

Type Description
Promise<boolean> Promise used to return the result. The value true means the account is activated; the value false means the opposite.

Error codes

ID Error Message
201 Permission denied.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
12300001 The system service works abnormally.
12300002 Invalid localId.
12300003 Account not found.

Example: Check whether system account 100 is activated.

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  let localId: number = 100;
  try {
    accountManager.checkOsAccountActivated(localId).then((isActivated: boolean) => {
      console.log('checkOsAccountActivated successfully, isActivated: ' + isActivated);
    }).catch((err: BusinessError) => {
      console.log('checkOsAccountActivated failed, error: ' + JSON.stringify(err));
    });
  } catch (err) {
    console.log('checkOsAccountActivated exception: ' + JSON.stringify(err));
  }

isOsAccountConstraintEnabled11+

isOsAccountConstraintEnabled(constraint: string): Promise<boolean>

Checks whether a constraint is enabled for this system account. This API uses a promise to return the result.

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
constraint string Yes Constraint to check.

Return value

Type Description
Promise<boolean> Promise used to return the result. The value true means the specified constraint is enabled; the value false means the opposite.

Error codes

ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
12300001 The system service works abnormally.

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

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  let constraint: string = 'constraint.wifi';
  try {
    accountManager.isOsAccountConstraintEnabled(constraint).then((isEnabled: boolean) => {
      console.log('isOsAccountConstraintEnabled successfully, isEnabled: ' + isEnabled);
    }).catch((err: BusinessError) => {
      console.log('isOsAccountConstraintEnabled failed, error: ' + JSON.stringify(err));
    });
  } catch (err) {
    console.log('isOsAccountConstraintEnabled exception: ' + JSON.stringify(err));
  }

checkOsAccountConstraintEnabled(deprecated)

checkOsAccountConstraintEnabled(localId: number, constraint: string, callback: AsyncCallback<boolean>): void

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

NOTE

This API is supported since API version 9 and deprecated since API version 11. The substitute API is available only to system applications.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS (available only for system applications)

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
localId number Yes ID of the target system account.
constraint string Yes Constraint to check.
callback AsyncCallback<boolean> Yes Callback used to return the result. The value true means the specified constraint is enabled; the value false means the opposite.

Error codes

ID Error Message
201 Permission denied.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
12300001 The system service works abnormally.
12300002 Invalid localId or constraint.
12300003 Account not found.

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

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  let localId: number = 100;
  let constraint: string = 'constraint.wifi';
  try {
    accountManager.checkOsAccountConstraintEnabled(localId, constraint, (err: BusinessError, isEnabled: boolean)=>{
      if (err) {
        console.log('checkOsAccountConstraintEnabled failed, error: ' + JSON.stringify(err));
      } else {
        console.log('checkOsAccountConstraintEnabled successfully, isEnabled: ' + isEnabled);
      }
    });
  } catch (err) {
    console.log('checkOsAccountConstraintEnabled exception: ' + JSON.stringify(err));
  }

checkOsAccountConstraintEnabled(deprecated)

checkOsAccountConstraintEnabled(localId: number, constraint: string): Promise<boolean>

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

NOTE

This API is supported since API version 9 and deprecated since API version 11. The substitute API is available only to system applications.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS (available only for system applications)

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
localId number Yes ID of the target system account.
constraint string Yes Constraint to check.

Return value

Type Description
Promise<boolean> Promise used to return the result. The value true means the specified constraint is enabled; the value false means the opposite.

Error codes

ID Error Message
201 Permission denied.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
12300001 The system service works abnormally.
12300002 Invalid localId or constraint.
12300003 Account not found.

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

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  let localId: number = 100;
  let constraint: string = 'constraint.wifi';
  try {
    accountManager.checkOsAccountConstraintEnabled(localId, constraint).then((isEnabled: boolean) => {
      console.log('checkOsAccountConstraintEnabled successfully, isEnabled: ' + isEnabled);
    }).catch((err: BusinessError) => {
      console.log('checkOsAccountConstraintEnabled failed, error: ' + JSON.stringify(err));
    });
  } catch (err) {
    console.log('checkOsAccountConstraintEnabled exception: ' + JSON.stringify(err));
  }

checkOsAccountTestable9+

checkOsAccountTestable(callback: AsyncCallback<boolean>): void

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

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
callback AsyncCallback<boolean> Yes Callback used to return the result. The value true means the account is a test account; the value false means the opposite.

Error codes

ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
12300001 The system service works abnormally.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  try {
    accountManager.checkOsAccountTestable((err: BusinessError, isTestable: boolean) => {
      if (err) {
        console.log('checkOsAccountTestable failed, error: ' + JSON.stringify(err));
      } else {
        console.log('checkOsAccountTestable successfully, isTestable: ' + isTestable);
      }
    });
  } catch (err) {
    console.log('checkOsAccountTestable error: ' + JSON.stringify(err));
  }

checkOsAccountTestable9+

checkOsAccountTestable(): Promise<boolean>

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

System capability: SystemCapability.Account.OsAccount

Return value

Type Description
Promise<boolean> Promise used to return the result. The value true means the account is a test account; the value false means the opposite.

Error codes

ID Error Message
12300001 The system service works abnormally.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  try {
    accountManager.checkOsAccountTestable().then((isTestable: boolean) => {
      console.log('checkOsAccountTestable successfully, isTestable: ' + isTestable);
    }).catch((err: BusinessError) => {
      console.log('checkOsAccountTestable failed, error: ' + JSON.stringify(err));
    });
  } catch (err) {
    console.log('checkOsAccountTestable exception: ' + JSON.stringify(err));
  }

isOsAccountUnlocked11+

isOsAccountUnlocked(): Promise<boolean>

Checks whether this system account is unlocked. This API uses a promise to return the result.

System capability: SystemCapability.Account.OsAccount

Return value

Type Description
Promise<boolean> Promise used to return the result. The value true means the system account is unlocked; the value false means the opposite.

Error codes

ID Error Message
12300001 The system service works abnormally.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  try {
    accountManager.isOsAccountUnlocked().then((isVerified: boolean) => {
      console.log('isOsAccountUnlocked successfully, isVerified: ' + isVerified);
    }).catch((err: BusinessError) => {
      console.log('isOsAccountUnlocked failed, error: ' + JSON.stringify(err));
    });
  } catch (err) {
    console.log('isOsAccountUnlocked exception: ' + JSON.stringify(err));
  }

checkOsAccountVerified(deprecated)

checkOsAccountVerified(callback: AsyncCallback<boolean>): void

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

NOTE

This API is supported since API version 9 and deprecated since API version 11. Use isOsAccountUnlocked instead.

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
callback AsyncCallback<boolean> Yes Callback used to return the result. The value true means the system account has been verified; the value false means the opposite.

Error codes

ID Error Message
12300001 The system service works abnormally.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  try {
    accountManager.checkOsAccountVerified((err: BusinessError, isVerified: boolean) => {
      if (err) {
        console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err));
      } else {
        console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified);
      }
    });
  } catch (err) {
    console.log('checkOsAccountVerified exception: ' + JSON.stringify(err));
  }

checkOsAccountVerified(deprecated)

checkOsAccountVerified(): Promise<boolean>

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

NOTE

This API is supported since API version 9 and deprecated since API version 11. Use isOsAccountUnlocked instead.

System capability: SystemCapability.Account.OsAccount

Return value

Type Description
Promise<boolean> Promise used to return the result. The value true means the system account has been verified; the value false means the opposite.

Error codes

ID Error Message
12300001 The system service works abnormally.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  try {
    accountManager.checkOsAccountVerified().then((isVerified: boolean) => {
      console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified);
    }).catch((err: BusinessError) => {
      console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err));
    });
  } catch (err) {
    console.log('checkOsAccountVerified exception: ' + JSON.stringify(err));
  }

checkOsAccountVerified(deprecated)

checkOsAccountVerified(localId: number, callback: AsyncCallback<boolean>): void

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

NOTE

This API is supported since API version 9 and deprecated since API version 11. The substitute API is available only to system applications.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS (available only for system applications)

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
localId number Yes ID of the target system account.
callback AsyncCallback<boolean> Yes Callback used to return the result. The value true means the system account has been verified; the value false means the opposite.

Error codes

ID Error Message
201 Permission denied.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
12300001 The system service works abnormally.
12300002 Invalid localId.
12300003 Account not found.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  let localId: number = 100;
  try {
    accountManager.checkOsAccountVerified(localId, (err: BusinessError, isVerified: boolean) => {
      if (err) {
        console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err));
      } else {
        console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified);
      }
    });
  } catch (err) {
    console.log('checkOsAccountVerified exception: ' + err);
  }

checkOsAccountVerified(deprecated)

checkOsAccountVerified(localId: number): Promise<boolean>

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

NOTE

This API is supported since API version 9 and deprecated since API version 11. The substitute API is available only to system applications.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS (available only for system applications)

System capability: SystemCapability.Account.OsAccount

Parameters

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

Return value

Type Description
Promise<boolean> Promise used to return the result. The value true means the system account has been verified; the value false means the opposite.

Error codes

ID Error Message
201 Permission denied.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
12300001 The system service works abnormally.
12300002 Invalid localId.
12300003 Account not found.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  let localId: number = 100;
  try {
    accountManager.checkOsAccountVerified(localId).then((isVerified: boolean) => {
      console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified);
    }).catch((err: BusinessError) => {
      console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err));
    });
  } catch (err) {
    console.log('checkOsAccountVerified exception: ' + JSON.stringify(err));
  }

getOsAccountCount9+

getOsAccountCount(callback: AsyncCallback<number>): void

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

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS (available only for system applications)

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
callback AsyncCallback<number> Yes Callback used to return the result. If the operation is successful, err is null and data is the number of created system accounts. If the operation fails, err is an error object.

Error codes

ID Error Message
201 Permission denied.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
12300001 The system service works abnormally.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  try {
    accountManager.getOsAccountCount((err: BusinessError, count: number) => {
      if (err) {
        console.log('getOsAccountCount failed, error: ' + JSON.stringify(err));
      } else {
        console.log('getOsAccountCount successfully, count: ' + count);
      }
    });
  } catch (err) {
    console.log('getOsAccountCount exception: ' + JSON.stringify(err));
  }

getOsAccountCount9+

getOsAccountCount(): Promise<number>

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

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS (available only for system applications)

System capability: SystemCapability.Account.OsAccount

Return value

Type Description
Promise<number> Promise used to return the number of created system accounts.

Error codes

ID Error Message
201 Permission denied.
12300001 The system service works abnormally.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  try {
    accountManager.getOsAccountCount().then((count: number) => {
      console.log('getOsAccountCount successfully, count: ' + count);
    }).catch((err: BusinessError) => {
      console.log('getOsAccountCount failed, error: ' + JSON.stringify(err));
    });
  } catch(err) {
    console.log('getOsAccountCount exception: ' + JSON.stringify(err));
  }

getOsAccountLocalId9+

getOsAccountLocalId(callback: AsyncCallback<number>): void

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

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
callback AsyncCallback<number> Yes Callback used to return the result. If the operation is successful, err is null and data is the system account ID obtained. Otherwise, err is an error object.

Error codes

ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
12300001 The system service works abnormally.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  try {
    accountManager.getOsAccountLocalId((err: BusinessError, localId: number) => {
      if (err) {
        console.log('getOsAccountLocalId failed, error: ' + JSON.stringify(err));
      } else {
        console.log('getOsAccountLocalId successfully, localId: ' + localId);
      }
    });
  } catch (err) {
    console.log('getOsAccountLocalId exception: ' + JSON.stringify(err));
  }

getOsAccountLocalId9+

getOsAccountLocalId(): Promise<number>

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

System capability: SystemCapability.Account.OsAccount

Return value

Type Description
Promise<number> Promise used to return the system account ID obtained.

Error codes

ID Error Message
12300001 The system service works abnormally.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  try {
    accountManager.getOsAccountLocalId().then((localId: number) => {
      console.log('getOsAccountLocalId successfully, localId: ' + localId);
    }).catch((err: BusinessError) => {
      console.log('getOsAccountLocalId failed, error: ' + JSON.stringify(err));
    });
  } catch (err) {
    console.log('getOsAccountLocalId exception: ' + JSON.stringify(err));
  }

getOsAccountLocalIdForUid9+

getOsAccountLocalIdForUid(uid: number, callback: AsyncCallback<number>): void

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

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
uid number Yes Process UID.
callback AsyncCallback<number> Yes Callback used to return the result. If the operation is successful, err is null and data is the system account ID obtained. Otherwise, data is an error object.

Error codes

ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
12300001 The system service works abnormally.
12300002 Invalid uid.

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

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  let uid: number = 12345678;
  try {
    accountManager.getOsAccountLocalIdForUid(uid, (err: BusinessError, localId: number) => {
      if (err) {
        console.log('getOsAccountLocalIdForUid failed, error: ' + JSON.stringify(err));
      }
      console.log('getOsAccountLocalIdForUid successfully, localId: ' + localId);
    });
  } catch (err) {
    console.log('getOsAccountLocalIdForUid exception: ' + JSON.stringify(err));
  }

getOsAccountLocalIdForUid9+

getOsAccountLocalIdForUid(uid: number): Promise<number>

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

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
uid number Yes Process UID.

Return value

Type Description
Promise<number> Promise used to return the system account ID obtained.

Error codes

ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
12300001 The system service works abnormally.
12300002 Invalid uid.

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

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  let uid: number = 12345678;
  try {
    accountManager.getOsAccountLocalIdForUid(uid).then((localId: number) => {
      console.log('getOsAccountLocalIdForUid successfully, localId: ' + localId);
    }).catch((err: BusinessError) => {
      console.log('getOsAccountLocalIdForUid failed, error: ' + JSON.stringify(err));
    });
  } catch (err) {
    console.log('getOsAccountLocalIdForUid exception: ' + JSON.stringify(err));
  }

getOsAccountLocalIdForUidSync10+

getOsAccountLocalIdForUidSync(uid: number): number

Obtains the system account ID based on the process UID. The API returns the result synchronously.

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
uid number Yes Process UID.

Return value

Type Description
number System account ID obtained.

Error codes

ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
12300002 Invalid uid.

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

  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  let uid: number = 12345678;
  try {
    let localId : number = accountManager.getOsAccountLocalIdForUidSync(uid);
    console.log('getOsAccountLocalIdForUidSync successfully, localId: ' + localId);
  } catch (err) {
    console.log('getOsAccountLocalIdForUidSync exception: ' + JSON.stringify(err));
  }

getOsAccountLocalIdForDomain9+

getOsAccountLocalIdForDomain(domainInfo: DomainAccountInfo, callback: AsyncCallback<number>): void

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

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS (available only for system applications)

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
domainInfo DomainAccountInfo Yes Domain account information.
callback AsyncCallback<number> Yes Callback used to return the result. If the operation is successful, err is null and data is the ID of the system account associated with the domain account. Otherwise, err is an error object.

Error codes

ID Error Message
201 Permission denied.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
12300001 The system service works abnormally.
12300002 Invalid domainInfo.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let domainInfo: osAccount.DomainAccountInfo = {domain: 'testDomain', accountName: 'testAccountName'};
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  try {
    accountManager.getOsAccountLocalIdForDomain(domainInfo, (err: BusinessError, localId: number) => {
      if (err) {
        console.log('getOsAccountLocalIdForDomain failed, error: ' + JSON.stringify(err));
      } else {
        console.log('getOsAccountLocalIdForDomain successfully, localId: ' + localId);
      }
    });
  } catch (err) {
    console.log('getOsAccountLocalIdForDomain exception: ' + JSON.stringify(err));
  }

getOsAccountLocalIdForDomain9+

getOsAccountLocalIdForDomain(domainInfo: DomainAccountInfo): Promise<number>

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

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS (available only for system applications)

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
domainInfo DomainAccountInfo Yes Domain account information.

Return value

Type Description
Promise<number> Promise used to return the ID of the system account associated with the domain account.

Error codes

ID Error Message
201 Permission denied.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
12300001 The system service works abnormally.
12300002 Invalid domainInfo.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  let domainInfo: osAccount.DomainAccountInfo = {domain: 'testDomain', accountName: 'testAccountName'};
  try {
    accountManager.getOsAccountLocalIdForDomain(domainInfo).then((localId: number) => {
      console.log('getOsAccountLocalIdForDomain successfully, localId: ' + localId);
    }).catch((err: BusinessError) => {
      console.log('getOsAccountLocalIdForDomain failed, error: ' + JSON.stringify(err));
    });
  } catch (err) {
    console.log('getOsAccountLocalIdForDomain exception: ' + JSON.stringify(err));
  }

getOsAccountConstraints(deprecated)

getOsAccountConstraints(localId: number, callback: AsyncCallback<Array<string>>): void

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

NOTE

This API is supported since API version 9 and deprecated since API version 11. The substitute API is available only to system applications.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS (available only for system applications)

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
localId number Yes ID of the target system account.
callback AsyncCallback<Array<string>> Yes Callback used to return the result. If the operation is successful, err is null and data is all constraints obtained. Otherwise, err is an error object.

Error codes

ID Error Message
201 Permission denied.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
12300001 The system service works abnormally.
12300002 Invalid localId.
12300003 Account not found.

Example: Obtain all constraints of system account 100.

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  let localId: number = 100;
  try {
    accountManager.getOsAccountConstraints(localId, (err: BusinessError, constraints: string[]) => {
      if (err) {
        console.log('getOsAccountConstraints failed, err: ' + JSON.stringify(err));
      } else {
        console.log('getOsAccountConstraints successfully, constraints: ' + JSON.stringify(constraints));
      }
    });
  } catch (err) {
    console.log('getOsAccountConstraints exception: ' + JSON.stringify(err));
  }

getOsAccountConstraints(deprecated)

getOsAccountConstraints(localId: number): Promise<Array<string>>

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

NOTE

This API is supported since API version 9 and deprecated since API version 11. The substitute API is available only to system applications.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS (available only for system applications)

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
localId number Yes ID of the target system account.

Return value

Type Description
Promise<Array<string>> Promise used to return all the constraints enabled for the system account.

Error codes

ID Error Message
201 Permission denied.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
12300001 The system service works abnormally.
12300002 Invalid localId.
12300003 Account not found.

Example: Obtain all constraints of system account 100.

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  let localId: number = 100;
  try {
    accountManager.getOsAccountConstraints(localId).then((constraints: string[]) => {
      console.log('getOsAccountConstraints, constraints: ' + constraints);
    }).catch((err: BusinessError) => {
      console.log('getOsAccountConstraints err: ' + JSON.stringify(err));
    });
  } catch (e) {
    console.log('getOsAccountConstraints exception: ' + JSON.stringify(e));
  }

getActivatedOsAccountLocalIds9+

getActivatedOsAccountLocalIds(callback: AsyncCallback<Array<number>>): void

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

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
callback AsyncCallback<Array<number>> Yes Callback used to return the result. If the operation is successful, err is null and data is a list of activated system accounts. Otherwise, data is an error object.

Error codes

ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
12300001 The system service works abnormally.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  try {
    accountManager.getActivatedOsAccountLocalIds((err: BusinessError, idArray: number[])=>{
      console.log('getActivatedOsAccountLocalIds err:' + JSON.stringify(err));
      console.log('getActivatedOsAccountLocalIds idArray length:' + idArray.length);
      for(let i=0;i<idArray.length;i++) {
        console.info('activated os account id: ' + idArray[i]);
      }
    });
  } catch (e) {
    console.log('getActivatedOsAccountLocalIds exception: ' + JSON.stringify(e));
  }

getActivatedOsAccountLocalIds9+

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

Obtains information about all activated system accounts. This API uses a promise to return the result.

System capability: SystemCapability.Account.OsAccount

Return value

Type Description
Promise&lt;Array&lt;number&gt;&gt; Promise used to return the information about all activated system accounts.

Error codes

ID Error Message
12300001 The system service works abnormally.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  try {
    accountManager.getActivatedOsAccountLocalIds().then((idArray: number[]) => {
      console.log('getActivatedOsAccountLocalIds, idArray: ' + idArray);
    }).catch((err: BusinessError) => {
      console.log('getActivatedOsAccountLocalIds err: ' + JSON.stringify(err));
    });
  } catch (e) {
    console.log('getActivatedOsAccountLocalIds exception: ' + JSON.stringify(e));
  }

getCurrentOsAccount(deprecated)

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

Obtains information about the system account to which the current process belongs. This API uses an asynchronous callback to return the result.

NOTE

This API is supported since API version 9 and deprecated since API version 11. The substitute API is available only to system applications.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.GET_LOCAL_ACCOUNTS10+ (available only for system applications)

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
callback AsyncCallback&lt;OsAccountInfo&gt; Yes Callback used to return the result. If the operation is successful, err is null and data is the system account information obtained. Otherwise, data is an error object.

Error codes

ID Error Message
201 Permission denied.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
12300001 The system service works abnormally.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  try {
    accountManager.getCurrentOsAccount((err: BusinessError, curAccountInfo: osAccount.OsAccountInfo)=>{
      console.log('getCurrentOsAccount err:' + JSON.stringify(err));
      console.log('getCurrentOsAccount curAccountInfo:' + JSON.stringify(curAccountInfo));
    });
  } catch (e) {
    console.log('getCurrentOsAccount exception: ' + JSON.stringify(e));
  }

getCurrentOsAccount(deprecated)

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

Obtains information about the system account to which the current process belongs. This API uses a promise to return the result.

NOTE

This API is supported since API version 9 and deprecated since API version 11. The substitute API is available only to system applications.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.GET_LOCAL_ACCOUNTS10+ (available only for system applications)

System capability: SystemCapability.Account.OsAccount

Return value

Type Description
Promise&lt;OsAccountInfo&gt; Promise used to return the system account information obtained.

Error codes

ID Error Message
201 Permission denied.
12300001 The system service works abnormally.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  try {
    accountManager.getCurrentOsAccount().then((accountInfo: osAccount.OsAccountInfo) => {
      console.log('getCurrentOsAccount, accountInfo: ' + JSON.stringify(accountInfo));
    }).catch((err: BusinessError) => {
      console.log('getCurrentOsAccount err: ' + JSON.stringify(err));
    });
  } catch (e) {
    console.log('getCurrentOsAccount exception: ' + JSON.stringify(e));
  }

getOsAccountType9+

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

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

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
callback AsyncCallback&lt;OsAccountType&gt; Yes Callback used to return the result. If the operation is successful, err is null and data is the system account type obtained. Otherwise, err is an error object.

Error codes

ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
12300001 The system service works abnormally.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  try {
    accountManager.getOsAccountType((err: BusinessError, accountType: osAccount.OsAccountType) => {
      console.log('getOsAccountType err: ' + JSON.stringify(err));
      console.log('getOsAccountType accountType: ' + accountType);
    });
  } catch (e) {
    console.log('getOsAccountType exception: ' + JSON.stringify(e));
  }

getOsAccountType9+

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

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

System capability: SystemCapability.Account.OsAccount

Return value

Type Description
Promise&lt;OsAccountType&gt; Promise used to return the system account type obtained.

Error codes

ID Error Message
12300001 The system service works abnormally.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  try {
    accountManager.getOsAccountType().then((accountType: osAccount.OsAccountType) => {
      console.log('getOsAccountType, accountType: ' + accountType);
    }).catch((err: BusinessError) => {
      console.log('getOsAccountType err: ' + JSON.stringify(err));
    });
  } catch (e) {
    console.log('getOsAccountType exception: ' + JSON.stringify(e));
  }

queryDistributedVirtualDeviceId9+

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

Queries the ID of the distributed virtual device. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS (available only for system applications) or ohos.permission.DISTRIBUTED_DATASYNC

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
callback AsyncCallback&lt;string&gt; Yes Callback used to return the result. If the operation is successful, err is null and data is the distributed virtual device ID obtained. Otherwise, data is an error object.

Error codes

ID Error Message
201 Permission denied.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
12300001 The system service works abnormally.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  try {
    accountManager.queryDistributedVirtualDeviceId((err: BusinessError, virtualID: string) => {
      console.log('queryDistributedVirtualDeviceId err: ' + JSON.stringify(err));
      console.log('queryDistributedVirtualDeviceId virtualID: ' + virtualID);
    });
  } catch (e) {
    console.log('queryDistributedVirtualDeviceId exception: ' + JSON.stringify(e));
  }

queryDistributedVirtualDeviceId9+

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

Queries the ID of the distributed virtual device. This API uses a promise to return the result.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS (available only for system applications) or ohos.permission.DISTRIBUTED_DATASYNC

System capability: SystemCapability.Account.OsAccount

Return value

Type Description
Promise&lt;string&gt; Promise used to return the distributed virtual device ID obtained.

Error codes

ID Error Message
201 Permission denied.
12300001 The system service works abnormally.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  try {
    accountManager.queryDistributedVirtualDeviceId().then((virtualID: string) => {
      console.log('queryDistributedVirtualDeviceId, virtualID: ' + virtualID);
    }).catch((err: BusinessError) => {
      console.log('queryDistributedVirtualDeviceId err: ' + JSON.stringify(err));
    });
  } catch (e) {
    console.log('queryDistributedVirtualDeviceId exception: ' + JSON.stringify(e));
  }

getOsAccountLocalIdForSerialNumber9+

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

Obtains the system account ID based on the SN. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
serialNumber number Yes Account SN.
callback AsyncCallback&lt;number&gt; Yes Callback used to return the result. If the operation is successful, err is null and data is the system account ID obtained. Otherwise, err is an error object.

Error codes

ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
12300001 The system service works abnormally.
12300002 Invalid serialNumber.
12300003 The account indicated by serialNumber dose not exist.

Example: Obtain the ID of the system account whose SN is 12345.

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  let serialNumber: number = 12345;
  try {
    accountManager.getOsAccountLocalIdForSerialNumber(serialNumber, (err: BusinessError, localId: number)=>{
      console.log('ger localId err:' + JSON.stringify(err));
      console.log('get localId:' + localId + ' by serialNumber: ' + serialNumber);
    });
  } catch (e) {
    console.log('ger localId exception: ' + JSON.stringify(e));
  }

getOsAccountLocalIdForSerialNumber9+

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

Obtains the system account ID based on the SN. This API uses a promise to return the result.

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
serialNumber number Yes Account SN.

Return value

Type Description
Promise&lt;number&gt; Promise used to return the system account ID obtained.

Error codes

ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
12300001 The system service works abnormally.
12300002 Invalid serialNumber.
12300003 The account indicated by serialNumber dose not exist.

Example: Obtain the ID of the system account whose SN is 12345.

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  let serialNumber: number = 12345;
  try {
    accountManager.getOsAccountLocalIdForSerialNumber(serialNumber).then((localId: number) => {
      console.log('getOsAccountLocalIdForSerialNumber localId: ' + localId);
    }).catch((err: BusinessError) => {
      console.log('getOsAccountLocalIdForSerialNumber err: ' + JSON.stringify(err));
    });
  } catch (e) {
    console.log('getOsAccountLocalIdForSerialNumber exception: ' + JSON.stringify(e));
  }

getSerialNumberForOsAccountLocalId9+

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

Obtains the SN of a system account based on the account ID. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
localId number Yes ID of the target system account.
callback AsyncCallback&lt;number&gt; Yes Callback used to return the result. If the operation is successful, err is null and data is the SN obtained. Otherwise, err is an error object.

Error codes

ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
12300001 The system service works abnormally.
12300002 Invalid localId.
12300003 Account not found.

Example: Obtain the SN of the system account 100.

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  let localId: number = 100;
  try {
    accountManager.getSerialNumberForOsAccountLocalId(localId, (err: BusinessError, serialNumber: number)=>{
      console.log('ger serialNumber err:' + JSON.stringify(err));
      console.log('get serialNumber:' + serialNumber + ' by localId: ' + localId);
    });
  } catch (e) {
    console.log('ger serialNumber exception: ' + JSON.stringify(e));
  }

getSerialNumberForOsAccountLocalId9+

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

Obtains the SN of a system account based on the account ID. This API uses a promise to return the result.

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
localId number Yes ID of the target system account.

Return value

Type Description
Promise&lt;number&gt; Promise used to return the SN obtained.

Error codes

ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
12300001 The system service works abnormally.
12300002 Invalid localId.
12300003 Account not found.

Example: Obtain the SN of the system account 100.

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  let localId: number = 100;
  try {
    accountManager.getSerialNumberForOsAccountLocalId(localId).then((serialNumber: number) => {
      console.log('getSerialNumberForOsAccountLocalId serialNumber: ' + serialNumber);
    }).catch((err: BusinessError) => {
      console.log('getSerialNumberForOsAccountLocalId err: ' + JSON.stringify(err));
    });
  } catch (e) {
    console.log('getSerialNumberForOsAccountLocalId exception: ' + JSON.stringify(e));
  }

isMultiOsAccountEnable(deprecated)

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

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

NOTE

This API is supported since API version 7 and deprecated since API version 9. Use checkMultiOsAccountEnabled instead.

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
callback AsyncCallback&lt;boolean&gt; Yes Callback used to return the result. The value true means multiple system accounts are supported; the value false means the opposite.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  accountManager.isMultiOsAccountEnable((err: BusinessError, isEnabled: boolean) => {
    if (err) {
      console.log('isMultiOsAccountEnable failed, error: ' + JSON.stringify(err));
    } else {
    console.log('isMultiOsAccountEnable successfully, isEnabled: ' + isEnabled);
    }
  });

isMultiOsAccountEnable(deprecated)

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

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

NOTE

This API is supported since API version 7 and deprecated since API version 9. Use checkMultiOsAccountEnabled instead.

System capability: SystemCapability.Account.OsAccount

Return value

Type Description
Promise&lt;boolean&gt; Promise used to return the result. The value true means multiple system accounts are supported; the value false means the opposite.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  accountManager.isMultiOsAccountEnable().then((isEnabled: boolean) => {
    console.log('isMultiOsAccountEnable successfully, isEnabled: ' + isEnabled);
  }).catch((err: BusinessError) => {
    console.log('isMultiOsAccountEnable failed, error: ' + JSON.stringify(err));
  });

isOsAccountActived(deprecated)

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

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

NOTE

This API is supported since API version 7 and deprecated since API version 9. The substitute API is available only to system applications.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS (available only for system applications)

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
localId number Yes ID of the target system account.
callback AsyncCallback&lt;boolean&gt; Yes Callback used to return the result. The value true means the account is activated; the value false means the opposite.

Example: Check whether system account 100 is activated.

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  let localId: number = 100;
  accountManager.isOsAccountActived(localId, (err: BusinessError, isActived: boolean) => {
    if (err) {
      console.log('isOsAccountActived failed, err:' + JSON.stringify(err));
    } else {
      console.log('isOsAccountActived successfully, isActived:' + isActived);
    }
  });

isOsAccountActived(deprecated)

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

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

NOTE

This API is supported since API version 7 and deprecated since API version 9. The substitute API is available only to system applications.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS (available only for system applications)

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
localId number Yes ID of the target system account.

Return value

Type Description
Promise&lt;boolean&gt; Promise used to return the result. The value true means the account is activated; the value false means the opposite.

Example: Check whether system account 100 is activated.

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  let localId: number = 100;
  accountManager.isOsAccountActived(localId).then((isActived: boolean) => {
    console.log('isOsAccountActived successfully, isActived: ' + isActived);
  }).catch((err: BusinessError) => {
    console.log('isOsAccountActived failed, error: ' + JSON.stringify(err));
  });

isOsAccountConstraintEnable(deprecated)

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

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

NOTE

This API is supported since API version 7 and deprecated since API version 9. The substitute API is available only to system applications.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS (available only for system applications)

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
localId number Yes ID of the target system account.
constraint string Yes Constraint to check.
callback AsyncCallback&lt;boolean&gt; Yes Callback used to return the result. The value true means the specified constraint is enabled; the value false means the opposite.

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

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  let localId: number = 100;
  let constraint: string = 'constraint.wifi';
  accountManager.isOsAccountConstraintEnable(localId, constraint, (err: BusinessError, isEnabled: boolean) => {
    if (err) {
      console.log('isOsAccountConstraintEnable failed, error: ' + JSON.stringify(err));
    } else {
      console.log('isOsAccountConstraintEnable successfully, isEnabled: ' + isEnabled);
    }
  });

isOsAccountConstraintEnable(deprecated)

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

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

NOTE

This API is supported since API version 7 and deprecated since API version 9. The substitute API is available only to system applications.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS (available only for system applications)

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
localId number Yes ID of the target system account.
constraint string Yes Constraint to check.

Return value

Type Description
Promise&lt;boolean&gt; Promise used to return the result. The value true means the specified constraint is enabled; the value false means the opposite.

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

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  let localId: number = 100;
  let constraint: string = 'constraint.wifi';
  accountManager.isOsAccountConstraintEnable(localId, constraint).then((isEnabled: boolean) => {
    console.log('isOsAccountConstraintEnable successfully, isEnabled: ' + isEnabled);
  }).catch((err: BusinessError) => {
    console.log('isOsAccountConstraintEnable err: ' + JSON.stringify(err));
  });

isTestOsAccount(deprecated)

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

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

NOTE

This API is supported since API version 7 and deprecated since API version 9. Use checkOsAccountTestable instead.

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
callback AsyncCallback&lt;boolean&gt; Yes Callback used to return the result. The value true means the account is a test account; the value false means the opposite.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  accountManager.isTestOsAccount((err: BusinessError, isTestable: boolean) => {
    if (err) {
      console.log('isTestOsAccount failed, error: ' + JSON.stringify(err));
    } else {
      console.log('isTestOsAccount successfully, isTestable: ' + isTestable);
    }
  });

isTestOsAccount(deprecated)

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

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

NOTE

This API is supported since API version 7 and deprecated since API version 9. Use checkOsAccountTestable instead.

System capability: SystemCapability.Account.OsAccount

Return value

Type Description
Promise&lt;boolean&gt; Promise used to return the result. The value true means the account is a test account; the value false means the opposite.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
    accountManager.isTestOsAccount().then((isTestable: boolean) => {
      console.log('isTestOsAccount successfully, isTestable: ' + isTestable);
    }).catch((err: BusinessError) => {
      console.log('isTestOsAccount failed, error: ' + JSON.stringify(err));
  });

isOsAccountVerified(deprecated)

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

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

NOTE

This API is supported since API version 7 and deprecated since API version 9. You are advised to use checkOsAccountVerified.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS (available only for system applications)

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
callback AsyncCallback&lt;boolean&gt; Yes Callback used to return the result. The value true means the system account has been verified; the value false means the opposite.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  accountManager.isOsAccountVerified((err: BusinessError, isVerified: boolean) => {
    if (err) {
      console.log('isOsAccountVerified failed, error: ' + JSON.stringify(err));
    } else {
      console.log('isOsAccountVerified successfully, isVerified: ' + isVerified);
    }
  });

isOsAccountVerified(deprecated)

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

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

NOTE

This API is supported since API version 7 and deprecated since API version 9. The substitute API is available only to system applications.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS (available only for system applications)

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
localId number Yes ID of the target system account.
callback AsyncCallback&lt;boolean&gt; Yes Callback used to return the result. The value true means the system account has been verified; the value false means the opposite.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  let localId: number = 100;
  accountManager.isOsAccountVerified(localId, (err: BusinessError, isVerified: boolean) => {
    if (err) {
      console.log('isOsAccountVerified failed, error: ' + JSON.stringify(err));
    } else {
      console.log('isOsAccountVerified successfully, isVerified: ' + isVerified);
    }
  });

isOsAccountVerified(deprecated)

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

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

NOTE

This API is supported since API version 7 and deprecated since API version 9. The substitute API is available only to system applications.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS (available only for system applications)

System capability: SystemCapability.Account.OsAccount

Parameters

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

Return value

Type Description
Promise&lt;boolean&gt; Promise used to return the result. The value true means the system account has been verified; the value false means the opposite.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  accountManager.isOsAccountVerified().then((isVerified: boolean) => {
    console.log('isOsAccountVerified successfully, isVerified: ' + isVerified);
  }).catch((err: BusinessError) => {
    console.log('isOsAccountVerified failed, error: ' + JSON.stringify(err));
  });

getCreatedOsAccountsCount(deprecated)

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

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

NOTE

This API is supported since API version 7 and deprecated since API version 9. Use getOsAccountCount instead.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS (available only for system applications)

System capability: SystemCapability.Account.OsAccount

Parameters

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

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  accountManager.getCreatedOsAccountsCount((err: BusinessError, count: number)=>{
    if (err) {
      console.log('getCreatedOsAccountsCount failed, error: ' + JSON.stringify(err));
    } else {
      console.log('getCreatedOsAccountsCount successfully, count: ' + count);
    }
  });

getCreatedOsAccountsCount(deprecated)

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

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

NOTE

This API is supported since API version 7 and deprecated since API version 9. Use getOsAccountCount instead.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS (available only for system applications)

System capability: SystemCapability.Account.OsAccount

Return value

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

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  accountManager.getCreatedOsAccountsCount().then((count: number) => {
    console.log('getCreatedOsAccountsCount successfully, count: ' + count);
  }).catch((err: BusinessError) => {
    console.log('getCreatedOsAccountsCount failed, error: ' + JSON.stringify(err));
  });

getOsAccountLocalIdFromProcess(deprecated)

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

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

NOTE

This API is supported since API version 7 and deprecated since API version 9. Use getOsAccountLocalId instead.

System capability: SystemCapability.Account.OsAccount

Parameters

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

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  accountManager.getOsAccountLocalIdFromProcess((err: BusinessError, localId: number) => {
    if (err) {
      console.log('getOsAccountLocalIdFromProcess failed, error: ' + JSON.stringify(err));
    } else {
      console.log('getOsAccountLocalIdFromProcess failed, error: ' + localId);
    }
  });

getOsAccountLocalIdFromProcess(deprecated)

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

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

NOTE

This API is supported since API version 7 and deprecated since API version 9. Use getOsAccountLocalId instead.

System capability: SystemCapability.Account.OsAccount

Return value

Type Description
Promise&lt;number&gt; Promise used to return the system account ID obtained.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  accountManager.getOsAccountLocalIdFromProcess().then((localId: number) => {
    console.log('getOsAccountLocalIdFromProcess successfully, localId: ' + localId);
  }).catch((err: BusinessError) => {
    console.log('getOsAccountLocalIdFromProcess failed, error: ' + JSON.stringify(err));
  });

getOsAccountLocalIdFromUid(deprecated)

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

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

NOTE

This API is supported since API version 7 and deprecated since API version 9. Use getOsAccountLocalIdForUid instead.

System capability: SystemCapability.Account.OsAccount

Parameters

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

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

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  let uid: number = 12345678;
  accountManager.getOsAccountLocalIdFromUid(uid, (err: BusinessError, localId: number) => {
    if (err) {
      console.log('getOsAccountLocalIdFromUid failed, error: ' + JSON.stringify(err));
    } else {
      console.log('getOsAccountLocalIdFromUid successfully, localId: ' + localId);
    }
  });

getOsAccountLocalIdFromUid(deprecated)

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

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

NOTE

This API is supported since API version 7 and deprecated since API version 9. Use getOsAccountLocalIdForUid instead.

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
uid number Yes Process UID.

Return value

Type Description
Promise&lt;number&gt; Promise used to return the system account ID obtained.

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

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  let uid: number = 12345678;
  accountManager.getOsAccountLocalIdFromUid(uid).then((localId: number) => {
    console.log('getOsAccountLocalIdFromUid successfully, localId: ' + localId);
  }).catch((err: BusinessError) => {
    console.log('getOsAccountLocalIdFromUid failed, error: ' + JSON.stringify(err));
  });

getOsAccountLocalIdFromDomain(deprecated)

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

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

NOTE

This API is supported since API version 8 and deprecated since API version 9. Use getOsAccountLocalIdForDomain instead.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS (available only for system applications)

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
domainInfo DomainAccountInfo Yes Domain account information.
callback AsyncCallback&lt;number&gt; Yes Callback used to return the result. If the operation is successful, err is null and data is the system account ID obtained. Otherwise, err is an error object.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let domainInfo: osAccount.DomainAccountInfo = {domain: 'testDomain', accountName: 'testAccountName'};
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  accountManager.getOsAccountLocalIdFromDomain(domainInfo, (err: BusinessError, localId: number) => {
    if (err) {
      console.log('getOsAccountLocalIdFromDomain failed, error: ' + JSON.stringify(err));
    } else {
      console.log('getOsAccountLocalIdFromDomain successfully, localId: ' + localId);
    }
  });

getOsAccountLocalIdFromDomain(deprecated)

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

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

NOTE

This API is supported since API version 8 and deprecated since API version 9. Use getOsAccountLocalIdForDomain instead.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS (available only for system applications)

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
domainInfo DomainAccountInfo Yes Domain account information.

Return value

Type Description
Promise&lt;number&gt; Promise used to return the ID of the system account associated with the domain account.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  let domainInfo: osAccount.DomainAccountInfo = {domain: 'testDomain', accountName: 'testAccountName'};
  accountManager.getOsAccountLocalIdFromDomain(domainInfo).then((localId: number) => {
    console.log('getOsAccountLocalIdFromDomain successfully, localId: ' + localId);
  }).catch((err: BusinessError) => {
    console.log('getOsAccountLocalIdFromDomain failed, error: ' + JSON.stringify(err));
  });

getOsAccountAllConstraints(deprecated)

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

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

NOTE

This API is supported since API version 7 and deprecated since API version 9. The substitute API is available only to system applications.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS (available only for system applications)

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
localId number Yes ID of the target system account.
callback AsyncCallback&lt;Array&lt;string&gt;&gt; Yes Callback used to return the result. If the operation is successful, err is null and data is a list of all constraints enabled for the system account. Otherwise, err is an error object.

Example: Obtain all constraints of system account 100.

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  let localId: number = 100;
  accountManager.getOsAccountAllConstraints(localId, (err: BusinessError, constraints: string[])=>{
    console.log('getOsAccountAllConstraints err:' + JSON.stringify(err));
    console.log('getOsAccountAllConstraints:' + JSON.stringify(constraints));
  });

getOsAccountAllConstraints(deprecated)

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

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

NOTE

This API is supported since API version 7 and deprecated since API version 9. The substitute API is available only to system applications.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS (available only for system applications)

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
localId number Yes ID of the target system account.

Return value

Type Description
Promise&lt;Array&lt;string&gt;&gt; Promise used to return all the constraints enabled for the system account.

Example: Obtain all constraints of system account 100.

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  let localId: number = 100;
  accountManager.getOsAccountAllConstraints(localId).then((constraints: string[]) => {
    console.log('getOsAccountAllConstraints, constraints: ' + constraints);
  }).catch((err: BusinessError) => {
    console.log('getOsAccountAllConstraints err: ' + JSON.stringify(err));
  });

queryActivatedOsAccountIds(deprecated)

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

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

NOTE

This API is supported since API version 8 and deprecated since API version 9. Use getActivatedOsAccountLocalIds instead.

System capability: SystemCapability.Account.OsAccount

Parameters

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

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  accountManager.queryActivatedOsAccountIds((err: BusinessError, idArray: number[])=>{
    console.log('queryActivatedOsAccountIds err:' + JSON.stringify(err));
    console.log('queryActivatedOsAccountIds idArray length:' + idArray.length);
    for(let i=0;i<idArray.length;i++) {
      console.info('activated os account id: ' + idArray[i]);
    }
  });

queryActivatedOsAccountIds(deprecated)

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

NOTE

This API is supported since API version 8 and deprecated since API version 9. Use getActivatedOsAccountLocalIds instead.

Obtains information about all activated system accounts. This API uses a promise to return the result.

System capability: SystemCapability.Account.OsAccount

Return value

Type Description
Promise&lt;Array&lt;number&gt;&gt; Promise used to return the information about all activated system accounts.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  accountManager.queryActivatedOsAccountIds().then((idArray: number[]) => {
    console.log('queryActivatedOsAccountIds, idArray: ' + idArray);
  }).catch((err: BusinessError) => {
    console.log('queryActivatedOsAccountIds err: ' + JSON.stringify(err));
  });

queryCurrentOsAccount(deprecated)

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

Obtains information about the system account to which the current process belongs. This API uses an asynchronous callback to return the result.

NOTE

This API is supported since API version 7 and deprecated since API version 9. The substitute API is available only to system applications.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS (available only for system applications)

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
callback AsyncCallback&lt;OsAccountInfo&gt; Yes Callback used to return the result. If the operation is successful, err is null and data is the system account information obtained. Otherwise, data is an error object.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  accountManager.queryCurrentOsAccount((err: BusinessError, curAccountInfo: osAccount.OsAccountInfo)=>{
    console.log('queryCurrentOsAccount err:' + JSON.stringify(err));
    console.log('queryCurrentOsAccount curAccountInfo:' + JSON.stringify(curAccountInfo));
  });

queryCurrentOsAccount(deprecated)

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

Obtains information about the system account to which the current process belongs. This API uses a promise to return the result.

NOTE

This API is supported since API version 7 and deprecated since API version 9. The substitute API is available only to system applications.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS (available only for system applications)

System capability: SystemCapability.Account.OsAccount

Return value

Type Description
Promise&lt;OsAccountInfo&gt; Promise used to return the system account information obtained.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  accountManager.queryCurrentOsAccount().then((accountInfo: osAccount.OsAccountInfo) => {
    console.log('queryCurrentOsAccount, accountInfo: ' + JSON.stringify(accountInfo));
  }).catch((err: BusinessError) => {
    console.log('queryCurrentOsAccount err: ' + JSON.stringify(err));
  });

getOsAccountTypeFromProcess(deprecated)

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

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

NOTE

This API is supported since API version 7 and deprecated since API version 9. Use getOsAccountType instead.

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
callback AsyncCallback&lt;OsAccountType&gt; Yes Callback used to return the result. If the operation is successful, err is null and data is the system account type obtained. Otherwise, err is an error object.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  accountManager.getOsAccountTypeFromProcess((err: BusinessError, accountType: osAccount.OsAccountType) => {
    console.log('getOsAccountTypeFromProcess err: ' + JSON.stringify(err));
    console.log('getOsAccountTypeFromProcess accountType: ' + accountType);
  });

getOsAccountTypeFromProcess(deprecated)

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

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

NOTE

This API is supported since API version 7 and deprecated since API version 9. Use getOsAccountType instead.

System capability: SystemCapability.Account.OsAccount

Return value

Type Description
Promise&lt;OsAccountType&gt; Promise used to return the system account type obtained.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  accountManager.getOsAccountTypeFromProcess().then((accountType: osAccount.OsAccountType) => {
    console.log('getOsAccountTypeFromProcess, accountType: ' + accountType);
  }).catch((err: BusinessError) => {
    console.log('getOsAccountTypeFromProcess err: ' + JSON.stringify(err));
  });

getDistributedVirtualDeviceId(deprecated)

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

Obtains the ID of this distributed virtual device. This API uses an asynchronous callback to return the result.

NOTE

This API is supported since API version 7 and deprecated since API version 9. Use queryDistributedVirtualDeviceId instead.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS (available only for system applications) or ohos.permission.DISTRIBUTED_DATASYNC

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
callback AsyncCallback&lt;string&gt; Yes Callback used to return the result. If the operation is successful, err is null and data is the distributed virtual device ID obtained. Otherwise, data is an error object.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  accountManager.getDistributedVirtualDeviceId((err: BusinessError, virtualID: string) => {
    console.log('getDistributedVirtualDeviceId err: ' + JSON.stringify(err));
    console.log('getDistributedVirtualDeviceId virtualID: ' + virtualID);
  });

getDistributedVirtualDeviceId(deprecated)

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

Obtains the ID of this distributed virtual device. This API uses a promise to return the result.

NOTE

This API is supported since API version 7 and deprecated since API version 9. Use queryDistributedVirtualDeviceId instead.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS (available only for system applications) or ohos.permission.DISTRIBUTED_DATASYNC

System capability: SystemCapability.Account.OsAccount

Return value

Type Description
Promise&lt;string&gt; Promise used to return the distributed virtual device ID obtained.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  accountManager.getDistributedVirtualDeviceId().then((virtualID: string) => {
    console.log('getDistributedVirtualDeviceId, virtualID: ' + virtualID);
  }).catch((err: BusinessError) => {
    console.log('getDistributedVirtualDeviceId err: ' + JSON.stringify(err));
  });

getOsAccountLocalIdBySerialNumber(deprecated)

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

Obtains the system account ID based on the SN. This API uses an asynchronous callback to return the result.

NOTE

This API is supported since API version 8 and deprecated since API version 9. Use getOsAccountLocalIdForSerialNumber instead.

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
serialNumber number Yes Account SN.
callback AsyncCallback&lt;number&gt; Yes Callback used to return the result. If the operation is successful, err is null and data is the system account ID obtained. Otherwise, err is an error object.

Example: Obtain the ID of the system account whose SN is 12345.

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  let serialNumber: number = 12345;
  accountManager.getOsAccountLocalIdBySerialNumber(serialNumber, (err: BusinessError, localId: number)=>{
    console.log('ger localId err:' + JSON.stringify(err));
    console.log('get localId:' + localId + ' by serialNumber: ' + serialNumber);
  });

getOsAccountLocalIdBySerialNumber(deprecated)

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

Obtains the system account ID based on the SN. This API uses a promise to return the result.

NOTE

This API is supported since API version 8 and deprecated since API version 9. Use getOsAccountLocalIdForSerialNumber instead.

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
serialNumber number Yes Account SN.

Return value

Type Description
Promise&lt;number&gt; Promise used to return the system account ID obtained.

Example: Obtain the ID of the system account whose SN is 12345.

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  let serialNumber: number = 12345;
  accountManager.getOsAccountLocalIdBySerialNumber(serialNumber).then((localId: number) => {
    console.log('getOsAccountLocalIdBySerialNumber localId: ' + localId);
  }).catch((err: BusinessError) => {
    console.log('getOsAccountLocalIdBySerialNumber err: ' + JSON.stringify(err));
  });

getSerialNumberByOsAccountLocalId(deprecated)

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

Obtains the SN of a system account based on the account ID. This API uses an asynchronous callback to return the result.

NOTE

This API is supported since API version 8 and deprecated since API version 9. Use getSerialNumberForOsAccountLocalId instead.

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
localId number Yes ID of the target system account.
callback AsyncCallback&lt;number&gt; Yes Callback used to return the result. If the operation is successful, err is null and data is the SN obtained. Otherwise, err is an error object.

Example: Obtain the SN of the system account 100.

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  let localId: number = 100;
  accountManager.getSerialNumberByOsAccountLocalId(localId, (err: BusinessError, serialNumber: number)=>{
    console.log('ger serialNumber err:' + JSON.stringify(err));
    console.log('get serialNumber:' + serialNumber + ' by localId: ' + localId);
  });

getSerialNumberByOsAccountLocalId(deprecated)

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

Obtains the SN of a system account based on the account ID. This API uses a promise to return the result.

NOTE

This API is supported since API version 8 and deprecated since API version 9. Use getSerialNumberForOsAccountLocalId instead.

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
localId number Yes ID of the target system account.

Return value

Type Description
Promise&lt;number&gt; Promise used to return the SN obtained.

Example: Obtain the SN of the system account 100.

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  let localId: number = 100;
  accountManager.getSerialNumberByOsAccountLocalId(localId).then((serialNumber: number) => {
    console.log('getSerialNumberByOsAccountLocalId serialNumber: ' + serialNumber);
  }).catch((err: BusinessError) => {
    console.log('getSerialNumberByOsAccountLocalId err: ' + JSON.stringify(err));
  });

getOsAccountName12+

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

Obtains the name of the system account of the caller. This API uses a promise to return the result.

System capability: SystemCapability.Account.OsAccount

Return value

Type Description
Promise&lt;string&gt; Promise used to return the system account name obtained.

Error codes

ID Error Message
12300001 The system service works abnormally.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  try {
    accountManager.getOsAccountName().then((name: string) => {
      console.log('getOsAccountName, name: ' + name);
    }).catch((err: BusinessError) => {
      console.log('getOsAccountName err: ' + err);
    });
  } catch (e) {
    console.log('getOsAccountName exception: ' + e);
  }

getForegroundOsAccountLocalId15+

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

Obtains the ID of the foreground system account.

System capability: SystemCapability.Account.OsAccount

Return value

Type Description
Promise&lt;number&gt; Promise used to return the result.

Error codes

ID Error Message
12300001 The system service works abnormally.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  try {
    accountManager.getForegroundOsAccountLocalId().then((localId: number) => {
      console.log('getForegroundOsAccountLocalId, localId: ' + localId);
    }).catch((err: BusinessError) => {
      console.log('getForegroundOsAccountLocalId err: ' + JSON.stringify(err));
    });
  } catch (e) {
    console.log('getForegroundOsAccountLocalId exception: ' + JSON.stringify(e));
  }

getOsAccountDomainInfo15+

getOsAccountDomainInfo(localId: number): Promise&lt;DomainAccountInfo&gt;;

Obtains the domain account information associated with a specified system account.

Required permissions: ohos.permission.GET_DOMAIN_ACCOUNTS and ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS (available to system applications and enterprise applications)

System capability: SystemCapability.Account.OsAccount

Return value

Type Description
Promise&lt;DomainAccountInfo&gt; Promise used to return the result.

Error codes

ID Error Message
201 Permission denied.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
12300001 The system service works abnormally.
12300003 OS account not found.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
  let localId: number = 100;
  accountManager.getOsAccountDomainInfo(localId).then((domainAccountInfo: osAccount.DomainAccountInfo) => {
    if (domainAccountInfo === null) {
      console.log('The target OS account is not a domain account.')
    } else {
      console.log('getOsAccountDomainInfo domain: ' + domainAccountInfo.domain);
      console.log('getOsAccountDomainInfo accountName: ' + domainAccountInfo.accountName);
    }
  }).catch((err: BusinessError) => {
    console.log('getOsAccountDomainInfo err: ' + JSON.stringify(err));
  })

updateAccountInfo18+

updateAccountInfo(oldAccountInfo: DomainAccountInfo, newAccountInfo: DomainAccountInfo): Promise&lt;void&gt;

Updates information of a domain account. This API uses a promise to return the result.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.MANAGE_DOMAIN_ACCOUNTS

System capability: SystemCapability.Account.OsAccount

Parameters

Name Type Mandatory Description
oldAccountInfo DomainAccountInfo Yes Domain account information.
newAccountInfo DomainAccountInfo Yes New domain account information.

Return value

Type Description
Promise&lt;void&gt; Promise that returns no value.

Error codes

ID Error Message
201 Permission denied.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
801 Capability not supported.
12300001 The system service works abnormally.
12300002 The new account info is invalid.
12300003 The old account not found.
12300004 The new account already exists.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let oldDomainInfo: osAccount.DomainAccountInfo =
    {domain: 'testDomain', accountName: 'oldtestAccountName'};
  let newDomainInfo: osAccount.DomainAccountInfo =
    {domain: 'testDomain', accountName: 'newtestAccountName'};
  try {
    osAccount.DomainAccountManager.updateAccountInfo(oldDomainInfo, newDomainInfo).then(() => {
      console.log('updateAccountInfo, success');
    }).catch((err: BusinessError) => {
      console.log('updateAccountInfo err: ' + err);
    });
  } catch (e) {
    console.log('updateAccountInfo exception: ' + e);
  }

OsAccountInfo

Represents information about a system account.

System capability: SystemCapability.Account.OsAccount

Name Type Mandatory Description
localId number Yes ID of the system account.
localName string Yes Name of the system account.
type OsAccountType Yes Type of the system account.
constraints Array&lt;string&gt; Yes Constraints of the system account. By default, no value is passed in.
isVerified(deprecated) boolean Yes Whether the account has been verified. The value true means the specified account has been verified; the value false means the opposite.
NOTE
This parameter is supported since API version 7 and deprecated since API version 11.
isUnlocked11+ boolean Yes Whether the account is unlocked (whether the el2/ directory is decrypted). The value true means the specified account is unlocked; the value false means the opposite.
photo8+ string Yes Avatar of the system account. By default, no value is passed in.
createTime8+ number Yes Time when the system account was created.
lastLoginTime8+ number Yes Last login time of the system account. By default, no value is passed in.
serialNumber8+ number Yes SN of the system account.
isActived(deprecated) boolean Yes Whether the system account is activated. The value true means that the specified account is activated; the value false means the opposite.
NOTE
This parameter is supported since API version 7 and deprecated since API version 11.
isActivated11+ boolean Yes Whether the system account is activated. The value true indicates that the specified account is activated; the value false means the opposite.
isCreateCompleted8+ boolean Yes Whether the system account information is complete. The value true means that the specified account is complete; the value false indicates the opposite.
distributedInfo distributedAccount.DistributedInfo Yes Distributed account information. By default, no value is passed in.
domainInfo8+ DomainAccountInfo Yes Domain account information. By default, no value is passed in.

DomainAccountInfo8+

Represents the domain account information.

System capability: SystemCapability.Account.OsAccount

Name Type Mandatory Description
domain string Yes Domain name.
accountName string Yes Domain account name.
serverConfigId18+ string No Domain account configuration ID.

DomainServerConfig18+

Represents the configuration of a domain server.

System capability: SystemCapability.Account.OsAccount

Name Type Mandatory Description
parameters Record Yes Server configuration parameters.
id string Yes Server configuration ID.
domain string Yes Domain to which the server belongs.

DomainServerConfigManager18+

Provides APIs for domain server configuration and management.

addServerConfig18+

static addServerConfig(parameters: Record&lt;string, Object&gt;): Promise&lt;DomainServerConfig&gt;

Adds domain server configuration. This API uses a promise to return the result.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.MANAGE_DOMAIN_ACCOUNT_SERVER_CONFIGS

Parameters

Name Type Mandatory Description
parameters Record Yes Configuration parameters of the domain server.

Return value

Type Description
Promise&lt;DomainServerConfig&gt; Promise used to return the configuration of the newly added domain server.

Error codes

ID Error Message
201 Permission denied.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
801 Capability not supported.
12300001 The system service works abnormally.
12300002 - Invalid server config parameters.
12300211 - Server unreachable.
12300213 - Server config already exists.
12300215 - The number of server config reaches the upper limit.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let configParams: Record<string, Object> = {
    'uri': 'test.example.com',
    'port': 100
  };
  osAccount.DomainServerConfigManager.addServerConfig(configParams).then((
    serverConfig: osAccount.DomainServerConfig) => {
    console.log('add server configuration successfully, the return config: ' + JSON.stringify(serverConfig));
  }).catch((err: BusinessError) => {
    console.log('add server configuration failed, error: ' + JSON.stringify(err));
  });

removeServerConfig18+

static removeServerConfig(configId: string): Promise&lt;void&gt;

Removes domain server configuration. This API uses a promise to return the result.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.MANAGE_DOMAIN_ACCOUNT_SERVER_CONFIGS

Parameters

Name Type Mandatory Description
configId string Yes Server configuration ID.

Return value

Type Description
Promise&lt;void&gt; Promise that returns no value.

Error codes

ID Error Message
201 Permission denied.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
801 Capability not supported.
12300001 The system service works abnormally.
12300212 - Server config not found.
12300214 - Server config has been associated with an account.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let configParams: Record<string, Object> = {
    'uri': 'test.example.com',
    'port': 100
  };
  osAccount.DomainServerConfigManager.addServerConfig(configParams).then((
    serverConfig: osAccount.DomainServerConfig) => {
    console.log('add domain server configuration successfully, the added config: ' + JSON.stringify(serverConfig));
    osAccount.DomainServerConfigManager.removeServerConfig(serverConfig.id);
    console.log('remove domain server configuration successfully');
  }).catch((err: BusinessError) => {
    console.log('add server configuration failed, error: ' + JSON.stringify(err));
  });

updateServerConfig18+

static updateServerConfig(configId: string, parameters: Record&lt;string, Object&gt;): Promise&lt;DomainServerConfig&gt;

Updates the domain server configuration. This API uses a promise to return the result.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.MANAGE_DOMAIN_ACCOUNT_SERVER_CONFIGS

Parameters

Name Type Mandatory Description
configId string Yes Server configuration ID.
parameters Record&lt;string, Object&gt; Yes Configuration parameters of the domain server.

Return value

Type Description
Promise&lt;DomainServerConfig&gt; Promise used to return the updated domain server configuration.

Error codes

ID Error Message
201 Permission denied.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
801 Capability not supported.
12300001 The system service works abnormally.
12300002 Invalid server config parameters.
12300211 - Server unreachable.
12300212 - Server config not found.
12300213 - Server config already exists.
12300214 - Server config has been associated with an account.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let configParams: Record<string, Object> = {
    'uri': 'test.example.com',
    'port': 100
  };
  osAccount.DomainServerConfigManager.addServerConfig(configParams).then((
    serverConfig: osAccount.DomainServerConfig) => {
    console.log('add domain server configuration successfully, the added config: ' + JSON.stringify(serverConfig));
    osAccount.DomainServerConfigManager.updateServerConfig(serverConfig.id, configParams).then((data) => {
      console.log('update domain server configuration successfully, return config: ' + JSON.stringify(data));
    }).catch((err: BusinessError) => {
      console.log('update domain server configuration failed, error: ' + JSON.stringify(err));
    });
  }).catch((err: BusinessError) => {
    console.log('add server configuration failed, error: ' + JSON.stringify(err));
  });

getServerConfig18+

static getServerConfig(configId: string): Promise&lt;DomainServerConfig&gt;

Obtains the domain server configuration. This API uses a promise to return the result.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.MANAGE_DOMAIN_ACCOUNT_SERVER_CONFIGS

Parameters

Name Type Mandatory Description
configId string Yes Server configuration ID.

Return value

Type Description
Promise&lt;DomainServerConfig&gt; Promise used to return the domain server configuration obtained.

Error codes

ID Error Message
201 Permission denied.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
801 Capability not supported.
12300001 The system service works abnormally.
12300212 Server config not found.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let configParams: Record<string, Object> = {
    'uri': 'test.example.com',
    'port': 100
  };
  osAccount.DomainServerConfigManager.addServerConfig(configParams).then((
    serverConfig: osAccount.DomainServerConfig) => {
    console.log('add domain server configuration successfully, the added config: ' + JSON.stringify(serverConfig));
    osAccount.DomainServerConfigManager.getServerConfig(serverConfig.id).then((data: osaccount.DomainServerConfig) => {
      console.log('get domain server configuration successfully, return config: ' + JSON.stringify(data));
    }).catch((err: BusinessError) => {
      console.log('get domain server configuration failed, error: ' + JSON.stringify(err));
    });
  }).catch((err: BusinessError) => {
    console.log('add server configuration failed, error: ' + JSON.stringify(err));
  });

getAllServerConfigs18+

static getAllServerConfigs(): Promise&lt;Array&lt;DomainServerConfig&gt;&gt;

Obtains the configurations of all domain servers. This API uses a promise to return the result.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.MANAGE_DOMAIN_ACCOUNT_SERVER_CONFIGS

Return value

Type Description
Promise&lt;Array&lt;DomainServerConfig&gt;&gt; Promise used to return the domain server configuration obtained.

Error codes

ID Error Message
201 Permission denied.
801 Capability not supported.
12300001 The system service works abnormally.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let configParams: Record<string, Object> = {
    'uri': 'test.example.com',
    'port': 100
  };
  osAccount.DomainServerConfigManager.addServerConfig(configParams).then((
    serverConfig: osAccount.DomainServerConfig) => {
    console.log('add domain server configuration successfully, the added config: ' + JSON.stringify(serverConfig));
    osAccount.DomainServerConfigManager.getAllServerConfigs().then((data: Array<osaccount.DomainServerConfig>) => {
      console.log('get all domain server configuration successfully, return config: ' + JSON.stringfy(data));
    }).catch((err: BusinessError) => {
      console.log('get all domain server configuration failed, error: ' + JSON.stringfy(err));
    });
  }).catch((err: BusinessError) => {
    console.log('add server configuration failed, error: ' + JSON.stringify(err));
  });

getAccountServerConfig18+

static getAccountServerConfig(domainAccountInfo: DomainAccountInfo): Promise&lt;DomainServerConfig&gt;

Obtains the server configuration of a domain account. This API uses a promise to return the result.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.MANAGE_DOMAIN_ACCOUNT_SERVER_CONFIGS

Parameters

Name Type Mandatory Description
domainAccountInfo DomainAccountInfo Yes Information of the domain account.

Return value

Type Description
Promise&lt;DomainServerConfig&gt; Promise used to return the domain server configuration of the account.

Error codes

ID Error Message
201 Permission denied.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
801 Capability not supported.
12300001 The system service works abnormally.
12300003 Domain account not found.

Example

  import { BusinessError } from '@kit.BasicServicesKit';
  let accountInfo: osAccount.DomainAccountInfo = {
    'accountName': 'demoName',
    'accountId': 'demoId',
    'domain': 'demoDomain'
  };
  osAccount.DomainServerConfigManager.getAccountServerConfig(accountInfo).then((
    serverConfig: osAccount.DomainServerConfig) => {
    console.log('get account server configuration successfully, the return config: ' + JSON.stringify(serverConfig));
  }).catch((err: BusinessError) => {
    console.log('add server configuration failed, error: ' + JSON.stringify(err));
  });

Constraints

Constraint Description
constraint.wifi Disallow the use of Wi-Fi.
constraint.wifi.set Disallow setting of Wi-Fi.
constraint.locale.set Disallow setting of the language to use.
constraint.app.accounts Disallow adding or deletion of app accounts.
constraint.apps.install Disallow app installation.
constraint.apps.uninstall Disallow app uninstallation.
constraint.location.shared Disallow location sharing.
constraint.unknown.sources.install Disallow installation of apps from unknown sources.
constraint.global.unknown.app.install Disallow installation of apps from unknown sources for all users.
constraint.bluetooth.set Disallow setting of Bluetooth.
constraint.bluetooth Disallow the use of Bluetooth.
constraint.bluetooth.share Disallow Bluetooth sharing.
constraint.usb.file.transfer Disallow file transfer over USB.
constraint.credentials.set Disallow setting of user credentials.
constraint.os.account.remove Disallow removal of users.
constraint.managed.profile.remove Disallow removal of the managed profiles of this user.
constraint.debug.features.use Disallow the use of debugging features.
constraint.vpn.set Disallow setting of VPN.
constraint.date.time.set Disallow setting of date, time, or time zone.
constraint.tethering.config Disallow setting of Tethering.
constraint.network.reset Disallow reset of network settings.
constraint.factory.reset Disallow reset to factory settings.
constraint.os.account.create Disallow creation of new users.
constraint.add.managed.profile Disallow addition of managed profiles.
constraint.apps.verify.disable Disallow app verification from being disabled.
constraint.cell.broadcasts.set Disallow setting of cell broadcasts.
constraint.mobile.networks.set Disallow setting of mobile networks.
constraint.control.apps Disallow modification of apps in Settings or the boot module.
constraint.physical.media Disallow mounting of external physical media.
constraint.microphone Disallow the use of microphones.
constraint.microphone.unmute Disallow unmuting of the microphone.
constraint.volume.adjust Disallow adjustment of the volume.
constraint.calls.outgoing Disallow outgoing calls.
constraint.sms.use Disallow the use of the short message service (SMS).
constraint.fun Disallow the use of entertainment features.
constraint.windows.create Disallow creation of the windows other than app windows.
constraint.system.error.dialogs Disallow display of error dialogs for crashed or unresponsive apps.
constraint.cross.profile.copy.paste Disallow pasting of clipboard content to other users or profiles.
constraint.beam.outgoing Disallow the use of Near Field Communications (NFC) to transfer data from apps.
constraint.wallpaper Disallow wallpaper management.
constraint.safe.boot Disallow reboot of the device in safe boot mode.
constraint.parent.profile.app.linking Disallow the app in the parent profile from handling web links from the managed profiles.
constraint.audio.record Disallow audio recording.
constraint.camera.use Disallow the use of cameras.
constraint.os.account.background.run Disallow background system accounts.
constraint.data.roam Disallow the use of cellular data when roaming.
constraint.os.account.set.icon Disallow setting of user icons.
constraint.wallpaper.set Disallow setting of wallpapers.
constraint.oem.unlock Disallow the use of OEM unlock.
constraint.device.unmute Disallow unmuting of the device.
constraint.password.unified Disallow the use of the unified lock screen challenge for the managed profile with the primary user.
constraint.autofill Disallow the use of the autofill service.
constraint.content.capture Disallow capturing of the screen content.
constraint.content.suggestions Disallow receiving of content suggestions.
constraint.os.account.activate Disallow activating of system accounts in the foreground.
constraint.location.set Disallow setting of the location service.
constraint.airplane.mode.set Disallow setting of the airplane mode.
constraint.brightness.set Disallow setting of the brightness.
constraint.share.into.profile Disallow sharing of files, images, and data of the primary user to the managed profiles.
constraint.ambient.display Disallow display of the ambient environment.
constraint.screen.timeout.set Disallow setting of the screen-off timeout.
constraint.print Disallow printing.
constraint.private.dns.set Disallow setting of the private domain name server (DNS).

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Basic Services Kit

harmony 鸿蒙DeviceInfo

harmony 鸿蒙InitSync

harmony 鸿蒙OH_Print

harmony 鸿蒙OsAccount

harmony 鸿蒙Pasteboard

harmony 鸿蒙Print_Margin

harmony 鸿蒙Print_PageSize

harmony 鸿蒙Print_PrintAttributes

harmony 鸿蒙Print_PrintDocCallback

0  赞