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

2022-08-09 浏览 (901)

@ohos.account.osAccount (OS Account Management)

The osAccount module provides basic capabilities for managing OS accounts, including adding, deleting, querying, setting, subscribing to, and enabling an OS 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 account_osAccount from '@ohos.account.osAccount';

account_osAccount.getAccountManager

getAccountManager(): AccountManager

Obtains an AccountManager instance.

System capability: SystemCapability.Account.OsAccount

Return value

TypeDescription
AccountManagerAccountManager instance obtained.

Example

let accountManager = account_osAccount.getAccountManager();

OsAccountType

Enumerates the OS account types.

System capability: SystemCapability.Account.OsAccount

NameValueDescription
ADMIN0Administrator account
NORMAL1Normal account
GUEST2Guest account

AccountManager

Provides APIs for managing OS accounts.

activateOsAccount

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

Activates an OS account. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
localIdnumberYesID of the target OS account.
callbackAsyncCallback<void>YesCallback invoked to return the result. If the operation is successful, err is null. Otherwise, err is an error object.

Error codes

IDError Message
12300001System service exception.
12300002Invalid localId.
12300003Account not found.
12300008Restricted Account.
12300009Account has been activated.

Example: Activate OS account 100.

import { BusinessError } from '@ohos.base';
let localId: number = 100;
try {
  accountManager.activateOsAccount(localId, (err: BusinessError)=>{
    if (err) {
      console.error(`activateOsAccount failed, code is ${err.code}, message is ${err.message}`);
    } else {
      console.log('activateOsAccount successfully');
    }
  });
} catch (err) {
  console.log('activateOsAccount failed, error:' + JSON.stringify(err));
}

activateOsAccount

activateOsAccount(localId: number): Promise<void>

Activates an OS account. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
localIdnumberYesID of the target OS account.

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

IDError Message
12300001System service exception.
12300002Invalid localId.
12300003Account not found.
12300008Restricted Account.
12300009Account has been activated.

Example: Activate OS account 100.

import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager();
let localId: number = 100;
try {
  accountManager.activateOsAccount(localId).then(() => {
    console.log('activateOsAccount successfully');
  }).catch((err: BusinessError) => {
    console.log('activateOsAccount failed, err:' + JSON.stringify(err));
  });
} catch (e) {
  console.log('activateOsAccount exception: ' + JSON.stringify(e));
}

checkMultiOsAccountEnabled9+

checkMultiOsAccountEnabled(callback: AsyncCallback<boolean>): void

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

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<boolean>YesCallback invoked to return the result. The value true means multiple OS accounts are supported; the value false means the opposite.

Error codes

IDError Message
12300001System service exception.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_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 OS accounts are supported. This API uses a promise to return the result.

System capability: SystemCapability.Account.OsAccount

Return value

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

Error codes

IDError Message
12300001System service exception.

Example

import { BusinessError } from '@ohos.base';
try {
  let accountManager = account_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));
}

checkOsAccountActivated9+

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

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

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

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
localIdnumberYesID of the target OS account.
callbackAsyncCallback<boolean>YesCallback invoked to return the result. The value true means the account is activated; the value false means the opposite.

Error codes

IDError Message
12300001System service exception.
12300002Invalid localId.
12300003Account not found.

Example: Check whether OS account 100 is activated.

import { BusinessError } from '@ohos.base';
let accountManager = account_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));
}

checkOsAccountActivated9+

checkOsAccountActivated(localId: number): Promise<boolean>

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

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

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
localIdnumberYesID of the target OS account.

Return value

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

Error codes

IDError Message
12300001System service exception.
12300002Invalid localId.
12300003Account not found.

Example: Check whether OS account 100 is activated.

import { BusinessError } from '@ohos.base';
let accountManager = account_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));
}

checkOsAccountConstraintEnabled9+

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

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

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

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
localIdnumberYesID of the target OS account.
constraintstringYesConstraint to check.
callbackAsyncCallback<boolean>YesCallback invoked to return the result. The value true means the specified constraint is enabled; the value false means the opposite.

Error codes

IDError Message
12300001System service exception.
12300002Invalid localId or constraint.
12300003Account not found.

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

import { BusinessError } from '@ohos.base';
let accountManager = account_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));
}

checkOsAccountConstraintEnabled9+

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

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

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

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
localIdnumberYesID of the target OS account.
constraintstringYesConstraint to check.

Return value

TypeDescription
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

IDError Message
12300001System service exception.
12300002Invalid localId or constraint.
12300003Account not found.

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

import { BusinessError } from '@ohos.base';
let accountManager = account_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 OS account is a test account. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<boolean>YesCallback invoked to return the result. The value true means the account is a test account; the value false means the opposite.

Error codes

IDError Message
12300001System service exception.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_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 OS account is a test account. This API uses a promise to return the result.

System capability: SystemCapability.Account.OsAccount

Return value

TypeDescription
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

IDError Message
12300001System service exception.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_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));
}

checkOsAccountVerified9+

checkOsAccountVerified(callback: AsyncCallback<boolean>): void

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

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<boolean>YesCallback invoked to return the result. The value true means the OS account has been verified; the value false means the opposite.

Error codes

IDError Message
12300001System service exception.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_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));
}

checkOsAccountVerified9+

checkOsAccountVerified(): Promise<boolean>

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

System capability: SystemCapability.Account.OsAccount

Return value

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

Error codes

IDError Message
12300001System service exception.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_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));
}

checkOsAccountVerified9+

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

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

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

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
localIdnumberYesID of the target OS account.
callbackAsyncCallback<boolean>YesCallback invoked to return the result. The value true means the OS account has been verified; the value false means the opposite.

Error codes

IDError Message
12300001System service exception.
12300002Invalid localId.
12300003Account not found.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_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);
}

checkOsAccountVerified9+

checkOsAccountVerified(localId: number): Promise<boolean>

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

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

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
localIdnumberYesID of the target OS account. If this parameter is not specified, this API checks whether the current OS account has been verified.

Return value

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

Error codes

IDError Message
12300001System service exception.
12300002Invalid localId.
12300003Account not found.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_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));
}

checkOsAccountVerified9+

checkOsAccountVerified(): Promise<boolean>

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

System capability: SystemCapability.Account.OsAccount

Return value

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

Error codes

IDError Message
12300001System service exception.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_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));
}

removeOsAccount

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

Deletes an OS account. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
localIdnumberYesID of the target OS account.
callbackAsyncCallback<void>YesCallback invoked to return the result. If the operation is successful, err is null. Otherwise, err is an error object.

Error codes

IDError Message
12300001System service exception.
12300002Invalid localId.
12300003Account not found.
12300008Restricted Account.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager();
let accountName: string = 'testAccountName';
try {
  accountManager.createOsAccount(accountName, account_osAccount.OsAccountType.NORMAL,
    (err: BusinessError, osAccountInfo: account_osAccount.OsAccountInfo) => {
      accountManager.removeOsAccount(osAccountInfo.localId, (err: BusinessError)=>{
        if (err) {
          console.log('removeOsAccount failed, error: ' + JSON.stringify(err));
        } else {
          console.log('removeOsAccount successfully');
        }
    });
  });
} catch (err) {
  console.log('removeOsAccount exception: ' + JSON.stringify(err));
}

removeOsAccount

removeOsAccount(localId: number): Promise<void>

Deletes an OS account. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
localIdnumberYesID of the target OS account.

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

IDError Message
12300001System service exception.
12300002Invalid localId.
12300003Account not found.
12300008Restricted Account.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager();
let accountName: string = 'testAccountName';
try {
  accountManager.createOsAccount(accountName, account_osAccount.OsAccountType.NORMAL,
    (err: BusinessError, osAccountInfo: account_osAccount.OsAccountInfo)=>{
      accountManager.removeOsAccount(osAccountInfo.localId).then(() => {
        console.log('removeOsAccount successfully');
      }).catch((err: BusinessError) => {
          console.log('removeOsAccount failed, error: ' + JSON.stringify(err));
      });
  });
} catch (err) {
  console.log('removeOsAccount exception: ' + JSON.stringify(err));
}

setOsAccountConstraints

setOsAccountConstraints(localId: number, constraints: Array<string>, enable: boolean,callback: AsyncCallback<void>): void

Sets or removes constraints for an OS account. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
localIdnumberYesID of the target OS account.
constraintsArray<string>YesList of constraints to set or remove.
enablebooleanYesSet or remove constraints. The value true means to set constraints, and false means to remove constraints.
callbackAsyncCallback<void>YesCallback invoked to return the result. If the operation is successful, err is null. Otherwise, err is an error object.

Error codes

IDError Message
12300001System service exception.
12300002Invalid localId or constraints.
12300003Account not found.
12300008Restricted Account.

Example: Disable Wi-Fi for OS account 100.

import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager();
let localId: number = 100;
let constraint: string = 'constraint.wifi';
try {
  accountManager.setOsAccountConstraints(localId, [constraint], true, (err: BusinessError) => {
    if (err) {
      console.log('setOsAccountConstraints failed, error: ' + JSON.stringify(err));
    } else {
      console.log('setOsAccountConstraints successfully');
    }
  });
} catch (err) {
  console.log('setOsAccountConstraints exception: ' + JSON.stringify(err));
}

setOsAccountConstraints

setOsAccountConstraints(localId: number, constraints: Array<string>, enable: boolean): Promise<void>

Sets or removes constraints for an OS account. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
localIdnumberYesID of the target OS account.
constraintsArray<string>YesList of constraints to set or remove.
enablebooleanYesSet or remove constraints. The value true means to set constraints, and false means to remove constraints.

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

IDError Message
12300001System service exception.
12300002Invalid localId or constraints.
12300003Account not found.
12300008Restricted Account.

Example: Remove the constraint on the use of Wi-Fi for OS account 100.

import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager();
let localId: number = 100;
try {
  accountManager.setOsAccountConstraints(localId, ['constraint.location.set'], false).then(() => {
    console.log('setOsAccountConstraints succsuccessfully');
  }).catch((err: BusinessError) => {
    console.log('setOsAccountConstraints failed, error: ' + JSON.stringify(err));
  });
} catch (err) {
  console.log('setOsAccountConstraints exception: ' + JSON.stringify(err));
}

setOsAccountName

setOsAccountName(localId: number, localName: string, callback: AsyncCallback<void>): void

Sets a name for an OS account. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
localIdnumberYesID of the target OS account.
localNamestringYesAccount name. The value cannot exceed 1024 characters.
callbackAsyncCallback<void>YesCallback invoked to return the result. If the operation is successful, err is null. Otherwise, err is an error object.

Error codes

IDError Message
12300001System service exception.
12300002Invalid localId or localName.
12300003Account not found.
12300008Restricted Account.

Example: Set the name of OS account 100 to demoName.

import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager();
let localId: number = 100;
let name: string = 'demoName';
try {
  accountManager.setOsAccountName(localId, name, (err: BusinessError) => {
    if (err) {
      console.log('setOsAccountName failed, error: ' + JSON.stringify(err));
    } else {
      console.log('setOsAccountName successfully');
    }
  });
} catch (err) {
  console.log('setOsAccountName exception: ' + JSON.stringify(err));
}

setOsAccountName

setOsAccountName(localId: number, localName: string): Promise<void>

Sets a name for an OS account. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
localIdnumberYesID of the target OS account.
localNamestringYesAccount name to set. The value cannot exceed 1024 characters.

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

IDError Message
12300001System service exception.
12300002Invalid localId or localName.
12300003Account not found.
12300008Restricted Account.

Example: Set the name of OS account 100 to demoName.

import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager();
let localId: number = 100;
let name: string = 'testName';
try {
  accountManager.setOsAccountName(localId, name).then(() => {
    console.log('setOsAccountName successfully');
  }).catch((err: BusinessError) => {
    console.log('setOsAccountName failed, error: ' + JSON.stringify(err));
  });
} catch (err) {
  console.log('setOsAccountName exception: ' + JSON.stringify(err));
}

getOsAccountCount9+

getOsAccountCount(callback: AsyncCallback<number>): void

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

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<number>YesCallback invoked to return the result. If the operation is successful, err is null and data is the number of created OS accounts. If the operation fails, err is an error object.

Error codes

IDError Message
12300001System service exception.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_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 OS accounts created. This API uses a promise to return the result.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

System capability: SystemCapability.Account.OsAccount

Return value

TypeDescription
Promise<number>Promise used to return the number of created OS accounts.

Error codes

IDError Message
12300001System service exception.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_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 OS account to which the current process belongs. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<number>YesCallback invoked to return the result. If the operation is successful, err is null and data is the OS account ID obtained. Otherwise, err is an error object.

Error codes

IDError Message
12300001System service exception.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_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 OS account to which the current process belongs. This API uses a promise to return the result.

System capability: SystemCapability.Account.OsAccount

Return value

TypeDescription
Promise<number>Promise used to return the OS account ID obtained.

Error codes

IDError Message
12300001System service exception.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_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 OS account ID based on the process UID. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
uidnumberYesProcess UID.
callbackAsyncCallback<number>YesCallback invoked to return the result. If the operation is successful, err is null and data is the OS account ID obtained. Otherwise, data is an error object.

Error codes

IDError Message
12300001System service exception.
12300002Invalid uid.

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

import { BusinessError } from '@ohos.base';
let accountManager = account_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 OS account ID based on the process UID. This API uses a promise to return the result.

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
uidnumberYesProcess UID.

Return value

TypeDescription
Promise<number>Promise used to return the OS account ID obtained.

Error codes

IDError Message
12300001System service exception.
12300002Invalid uid.

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

import { BusinessError } from '@ohos.base';
let accountManager = account_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 OS account ID based on the process UID. The API returns the result synchronously.

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
uidnumberYesProcess UID.

Return value

TypeDescription
numberOS account ID obtained.

Error codes

IDError Message
12300002Invalid uid.

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

let accountManager = account_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 OS 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

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
domainInfoDomainAccountInfoYesDomain account information.
callbackAsyncCallback<number>YesCallback invoked to return the result. If the operation is successful, err is null and data is the ID of the OS account associated with the domain account. Otherwise, err is an error object.

Error codes

IDError Message
12300001System service exception.
12300002Invalid domainInfo.

Example

import { BusinessError } from '@ohos.base';
let domainInfo: account_osAccount.DomainAccountInfo = {domain: 'testDomain', accountName: 'testAccountName'};
let accountManager = account_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 OS account ID based on the domain account information. This API uses a promise to return the result.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
domainInfoDomainAccountInfoYesDomain account information.

Return value

TypeDescription
Promise<number>Promise used to return the ID of the OS account associated with the domain account.

Error codes

IDError Message
12300001System service exception.
12300002Invalid domainInfo.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager();
let domainInfo: account_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));
}

queryMaxOsAccountNumber

queryMaxOsAccountNumber(callback: AsyncCallback<number>): void

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

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<number>YesCallback invoked to return the result. If the operation is successful, err is null and data is the maximum number of OS accounts that can be created. Otherwise, err is an error object.

Error codes

IDError Message
12300001System service exception.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager();
try {
  accountManager.queryMaxOsAccountNumber((err: BusinessError, maxCnt: number) => {
    if (err) {
      console.log('queryMaxOsAccountNumber failed, error:' + JSON.stringify(err));
    } else {
      console.log('queryMaxOsAccountNumber successfully, maxCnt:' + maxCnt);
    }
  });
} catch (err) {
  console.log('queryMaxOsAccountNumber exception: ' + JSON.stringify(err));
}

queryMaxOsAccountNumber

queryMaxOsAccountNumber(): Promise<number>

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

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Return value

TypeDescription
Promise<number>Promise used to return the maximum number of OS accounts that can be created.

Error codes

IDError Message
12300001System service exception.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager();
try {
  accountManager.queryMaxOsAccountNumber().then((maxCnt: number) => {
    console.log('queryMaxOsAccountNumber successfully, maxCnt: ' + maxCnt);
  }).catch((err: BusinessError) => {
    console.log('queryMaxOsAccountNumber failed, error: ' + JSON.stringify(err));
  });
} catch (err) {
  console.log('queryMaxOsAccountNumber exception: ' + JSON.stringify(err));
}

getOsAccountConstraints9+

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

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

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
localIdnumberYesID of the target OS account.
callbackAsyncCallback<Array<string>>YesCallback invoked 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

IDError Message
12300001System service exception.
12300002Invalid localId.
12300003Account not found.

Example: Obtain all constraints of OS account 100.

import { BusinessError } from '@ohos.base';
let accountManager = account_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));
}

getOsAccountConstraints9+

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

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

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
localIdnumberYesID of the target OS account.

Return value

TypeDescription
Promise<Array<string>>Promise used to return all the constraints enabled for the OS account.

Error codes

IDError Message
12300001System service exception.
12300002Invalid localId.
12300003Account not found.

Example: Obtain all constraints of OS account 100.

import { BusinessError } from '@ohos.base';
let accountManager = account_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));
}

queryAllCreatedOsAccounts

queryAllCreatedOsAccounts(callback: AsyncCallback<Array<OsAccountInfo>>): void

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

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<Array<OsAccountInfo>>YesCallback invoked to return the result. If the operation is successful, err is null and data is a list of all created OS accounts. Otherwise, data is an error object.

Error codes

IDError Message
12300001System service exception.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager();
try {
  accountManager.queryAllCreatedOsAccounts((err: BusinessError, accountArr: account_osAccount.OsAccountInfo[])=>{
    console.log('queryAllCreatedOsAccounts err:' + JSON.stringify(err));
    console.log('queryAllCreatedOsAccounts accountArr:' + JSON.stringify(accountArr));
  });
} catch (e) {
  console.log('queryAllCreatedOsAccounts exception: ' + JSON.stringify(e));
}

queryAllCreatedOsAccounts

queryAllCreatedOsAccounts(): Promise<Array<OsAccountInfo>>

Obtains information about all the OS accounts created. This API uses a promise to return the result.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

Return value

TypeDescription
Promise<Array<OsAccountInfo>>Promise used to return the information about all the OS accounts created.

Error codes

IDError Message
12300001System service exception.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager();
try {
  accountManager.queryAllCreatedOsAccounts().then((accountArr: account_osAccount.OsAccountInfo[]) => {
    console.log('queryAllCreatedOsAccounts, accountArr: ' + JSON.stringify(accountArr));
  }).catch((err: BusinessError) => {
    console.log('queryAllCreatedOsAccounts err: ' + JSON.stringify(err));
  });
} catch (e) {
  console.log('queryAllCreatedOsAccounts exception: ' + JSON.stringify(e));
}

getActivatedOsAccountLocalIds9+

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

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

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<Array<number>>YesCallback invoked to return the result. If the operation is successful, err is null and data is a list of activated OS accounts. Otherwise, data is an error object.

Error codes

IDError Message
12300001System service exception.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_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<Array<number>>

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

System capability: SystemCapability.Account.OsAccount

Return value

TypeDescription
Promise<Array<number>>Promise used to return the information about all activated OS accounts.

Error codes

IDError Message
12300001System service exception.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_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));
}

createOsAccount

createOsAccount(localName: string, type: OsAccountType, callback: AsyncCallback<OsAccountInfo>): void

Creates an OS account. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
localNamestringYesName of the OS account to create.
typeOsAccountTypeYesType of the OS account to create.
callbackAsyncCallback<OsAccountInfo>YesCallback invoked to return the result. If the operation is successful, err is null and data is the created OS account. Otherwise, err is an error object.

Error codes

IDError Message
12300001System service exception.
12300002Invalid localName or type.
12300005Multi-user not supported.
12300006Unsupported account type.
12300007The number of accounts reaches the upper limit.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager();
try {
  accountManager.createOsAccount('testName', account_osAccount.OsAccountType.NORMAL,
    (err: BusinessError, osAccountInfo: account_osAccount.OsAccountInfo)=>{
    console.log('createOsAccount err:' + JSON.stringify(err));
    console.log('createOsAccount osAccountInfo:' + JSON.stringify(osAccountInfo));
  });
} catch (e) {
  console.log('createOsAccount exception: ' + JSON.stringify(e));
}

createOsAccount

createOsAccount(localName: string, type: OsAccountType): Promise<OsAccountInfo>

Creates an OS account. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
localNamestringYesName of the OS account to create.
typeOsAccountTypeYesType of the OS account to create.

Return value

TypeDescription
Promise<OsAccountInfo>Promise used to return the information about the created OS account.

Error codes

IDError Message
12300001System service exception.
12300002Invalid localName or type.
12300005Multi-user not supported.
12300006Unsupported account type.
12300007The number of accounts reaches the upper limit.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager();
try {
  accountManager.createOsAccount('testAccountName', account_osAccount.OsAccountType.NORMAL).then(
    (accountInfo: account_osAccount.OsAccountInfo) => {
    console.log('createOsAccount, accountInfo: ' + JSON.stringify(accountInfo));
  }).catch((err: BusinessError) => {
    console.log('createOsAccount err: ' + JSON.stringify(err));
  });
} catch (e) {
  console.log('createOsAccount exception: ' + JSON.stringify(e));
}

createOsAccountForDomain8+

createOsAccountForDomain(type: OsAccountType, domainInfo: DomainAccountInfo, callback: AsyncCallback<OsAccountInfo>): void

Creates an OS account and associates it with the specified domain account. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
typeOsAccountTypeYesType of the OS account to create.
domainInfoDomainAccountInfoYesDomain account information.
callbackAsyncCallback<OsAccountInfo>YesCallback invoked to return the result. If the operation is successful, err is null and data is the created OS account. Otherwise, err is an error object.

Error codes

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

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager();
let domainInfo: account_osAccount.DomainAccountInfo =
  {domain: 'testDomain', accountName: 'testAccountName'};
try {
  accountManager.createOsAccountForDomain(account_osAccount.OsAccountType.NORMAL, domainInfo,
    (err: BusinessError, osAccountInfo: account_osAccount.OsAccountInfo)=>{
    console.log('createOsAccountForDomain err:' + JSON.stringify(err));
    console.log('createOsAccountForDomain osAccountInfo:' + JSON.stringify(osAccountInfo));
  });
} catch (e) {
  console.log('createOsAccountForDomain exception: ' + JSON.stringify(e));
}

createOsAccountForDomain8+

createOsAccountForDomain(type: OsAccountType, domainInfo: DomainAccountInfo): Promise<OsAccountInfo>

Creates an OS account and associates it with the specified domain account. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
typeOsAccountTypeYesType of the OS account to create.
domainInfoDomainAccountInfoYesDomain account information.

Return value

TypeDescription
Promise<OsAccountInfo>Promise used to return the information about the created OS account.

Error codes

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

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager();
let domainInfo: account_osAccount.DomainAccountInfo =
  {domain: 'testDomain', accountName: 'testAccountName'};
try {
  accountManager.createOsAccountForDomain(account_osAccount.OsAccountType.NORMAL, domainInfo).then(
    (accountInfo: account_osAccount.OsAccountInfo) => {
    console.log('createOsAccountForDomain, account info: ' + JSON.stringify(accountInfo));
  }).catch((err: BusinessError) => {
    console.log('createOsAccountForDomain err: ' + JSON.stringify(err));
  });
} catch (e) {
  console.log('createOsAccountForDomain exception: ' + JSON.stringify(e));
}

getCurrentOsAccount9+

getCurrentOsAccount(callback: AsyncCallback<OsAccountInfo>): void

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

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.GET_LOCAL_ACCOUNTS10+

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<OsAccountInfo>YesCallback invoked to return the result. If the operation is successful, err is null and data is the OS account information obtained. Otherwise, data is an error object.

Error codes

IDError Message
12300001System service exception.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager();
try {
  accountManager.getCurrentOsAccount((err: BusinessError, curAccountInfo: account_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));
}

getCurrentOsAccount9+

getCurrentOsAccount(): Promise<OsAccountInfo>

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

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.GET_LOCAL_ACCOUNTS10+

System capability: SystemCapability.Account.OsAccount

Return value

TypeDescription
Promise<OsAccountInfo>Promise used to return the OS account information obtained.

Error codes

IDError Message
12300001System service exception.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager();
try {
  accountManager.getCurrentOsAccount().then((accountInfo: account_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));
}

queryOsAccountById

queryOsAccountById(localId: number, callback: AsyncCallback<OsAccountInfo>): void

Obtains information about the OS account of the given ID. This API uses an asynchronous callback to return the result.

System API: This is a system API.

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

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
localIdnumberYesID of the target OS account.
callbackAsyncCallback<OsAccountInfo>YesCallback invoked to return the result. If the operation is successful, err is null and data is the OS account information obtained. Otherwise, data is an error object.

Error codes

IDError Message
12300001System service exception.
12300002Invalid localId.
12300003Account not found.

Example: Query information about OS account 100.

import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager();
let localId: number = 100;
try {
  accountManager.queryOsAccountById(localId, (err: BusinessError, accountInfo: account_osAccount.OsAccountInfo)=>{
    console.log('queryOsAccountById err:' + JSON.stringify(err));
    console.log('queryOsAccountById accountInfo:' + JSON.stringify(accountInfo));
  });
} catch (e) {
  console.log('queryOsAccountById exception: ' + JSON.stringify(e));
}

queryOsAccountById

queryOsAccountById(localId: number): Promise<OsAccountInfo>

Obtains information about the OS account of the given ID. This API uses a promise to return the result.

System API: This is a system API.

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

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
localIdnumberYesID of the target OS account.

Return value

TypeDescription
Promise<OsAccountInfo>Promise used to return the OS account information obtained.

Error codes

IDError Message
12300001System service exception.
12300002Invalid localId.
12300003Account not found.

Example: Query information about OS account 100.

import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager();
let localId: number = 100;
try {
  accountManager.queryOsAccountById(localId).then((accountInfo: account_osAccount.OsAccountInfo) => {
    console.log('queryOsAccountById, accountInfo: ' + JSON.stringify(accountInfo));
  }).catch((err: BusinessError) => {
    console.log('queryOsAccountById err: ' + JSON.stringify(err));
  });
} catch (e) {
  console.log('queryOsAccountById exception: ' + JSON.stringify(e));
}

getOsAccountType9+

getOsAccountType(callback: AsyncCallback<OsAccountType>): 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

NameTypeMandatoryDescription
callbackAsyncCallback<OsAccountType>YesCallback invoked to return the result. If the operation is successful, err is null and data is the OS account type obtained. Otherwise, err is an error object.

Error codes

IDError Message
12300001System service exception.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager();
try {
  accountManager.getOsAccountType((err: BusinessError, accountType: account_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<OsAccountType>

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

TypeDescription
Promise<OsAccountType>Promise used to return the OS account type obtained.

Error codes

IDError Message
12300001System service exception.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager();
try {
  accountManager.getOsAccountType().then((accountType: account_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<string>): void

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

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

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<string>YesCallback invoked to return the result. If the operation is successful, err is null and data is the distributed virtual device ID obtained. Otherwise, data is an error object.

Error codes

IDError Message
12300001System service exception.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_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<string>

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

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

System capability: SystemCapability.Account.OsAccount

Return value

TypeDescription
Promise<string>Promise used to return the distributed virtual device ID obtained.

Error codes

IDError Message
12300001System service exception.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_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));
}

getOsAccountProfilePhoto

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

Obtains the profile photo of an OS account. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
localIdnumberYesID of the target OS account.
callbackAsyncCallback<string>YesCallback invoked to return the result. If the operation is successful, err is null and data is the profile photo information obtained. Otherwise, err is an error object.

Error codes

IDError Message
12300001System service exception.
12300002Invalid localId.
12300003Account not found.

Example: Obtain the profile photo of OS account 100.

import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager();
let localId: number = 100;
try {
  accountManager.getOsAccountProfilePhoto(localId, (err: BusinessError, photo: string)=>{
    console.log('getOsAccountProfilePhoto err:' + JSON.stringify(err));
    console.log('get photo:' + photo + ' by localId: ' + localId);
  });
} catch (e) {
  console.log('getOsAccountProfilePhoto exception: ' + JSON.stringify(e));
}

getOsAccountProfilePhoto

getOsAccountProfilePhoto(localId: number): Promise<string>

Obtains the profile photo of an OS account. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
localIdnumberYesID of the target OS account.

Return value

TypeDescription
Promise<string>Promise used to return the profile photo information obtained.

Error codes

IDError Message
12300001System service exception.
12300002Invalid localId.
12300003Account not found.

Example: Obtain the profile photo of OS account 100.

import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager();
let localId: number = 100;
try {
  accountManager.getOsAccountProfilePhoto(localId).then((photo: string) => {
    console.log('getOsAccountProfilePhoto: ' + photo);
  }).catch((err: BusinessError) => {
    console.log('getOsAccountProfilePhoto err: ' + JSON.stringify(err));
  });
} catch (e) {
  console.log('getOsAccountProfilePhoto exception: ' + JSON.stringify(e));
}

setOsAccountProfilePhoto

setOsAccountProfilePhoto(localId: number, photo: string, callback: AsyncCallback<void>): void

Sets a profile photo for an OS account. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
localIdnumberYesID of the target OS account.
photostringYesProfile photo information.
callbackAsyncCallback<void>YesCallback invoked to return the result. If the operation is successful, err is null. Otherwise, err is an error object.

Error codes

IDError Message
12300001System service exception.
12300002Invalid localId or photo.
12300003Account not found.
12300008Restricted Account.

Example: Set a profile photo for OS account 100.

import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager();
let localId: number = 100;
let photo: string = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAAPCAYAAAA/I0V3AAAAAXNSR0IArs4c6QAAAARnQU1BAA'+
'Cxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACwSURBVDhPvZLBDYMwDEV/ugsXRjAT0EHCOuFIBwkbdIRewi6unbiAyoGgSn1SFH85+Y'+
'q/4ljARW62X+LHS8uIzjm4dXUYF+utzBikB52Jo5e5iEPKqpACk7R9NM2RvWm5tIkD2czLCUFNKLD6IjdMHFHDzws285MgGrT0xCtp3WOKHo'+
'+7q0mP0DZW9pNmoEFUzrQjp5cCnaen2kSJXLFD8ghbXyZCMQf/8e8Ns1XVAG/XAgqKzVnJFAAAAABJRU5ErkJggg=='
try {
  accountManager.setOsAccountProfilePhoto(localId, photo, (err: BusinessError)=>{
    console.log('setOsAccountProfilePhoto err:' + JSON.stringify(err));
  });
} catch (e) {
  console.log('setOsAccountProfilePhoto exception: ' + JSON.stringify(e));
}

setOsAccountProfilePhoto

setOsAccountProfilePhoto(localId: number, photo: string): Promise<void>

Sets a profile photo for an OS account. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
localIdnumberYesID of the target OS account.
photostringYesProfile photo information.

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

IDError Message
12300001System service exception.
12300002Invalid localId or photo.
12300003Account not found.
12300008Restricted Account.

Example: Set a profile photo for OS account 100.

import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager();
let localId: number = 100;
let photo: string = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAAPCAYAAAA/I0V3AAAAAXNSR0IArs4c6QAAAARnQU1BAA'+
'Cxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACwSURBVDhPvZLBDYMwDEV/ugsXRjAT0EHCOuFIBwkbdIRewi6unbiAyoGgSn1SFH85+Y'+
'q/4ljARW62X+LHS8uIzjm4dXUYF+utzBikB52Jo5e5iEPKqpACk7R9NM2RvWm5tIkD2czLCUFNKLD6IjdMHFHDzws285MgGrT0xCtp3WOKHo'+
'+7q0mP0DZW9pNmoEFUzrQjp5cCnaen2kSJXLFD8ghbXyZCMQf/8e8Ns1XVAG/XAgqKzVnJFAAAAABJRU5ErkJggg=='
try {
  accountManager.setOsAccountProfilePhoto(localId, photo).then(() => {
    console.log('setOsAccountProfilePhoto success');
  }).catch((err: BusinessError) => {
    console.log('setOsAccountProfilePhoto err: ' + JSON.stringify(err));
  });
} catch (e) {
  console.log('setOsAccountProfilePhoto exception: ' + JSON.stringify(e));
}

getOsAccountLocalIdForSerialNumber9+

getOsAccountLocalIdForSerialNumber(serialNumber: number, callback: AsyncCallback<number>): void

Obtains the OS account ID based on the serial number (SN). This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
serialNumbernumberYesAccount SN.
callbackAsyncCallback<number>YesCallback invoked to return the result. If the operation is successful, err is null and data is the OS account ID obtained. Otherwise, err is an error object.

Error codes

IDError Message
12300001System service exception.
12300002Invalid serialNumber.
12300003The account indicated by serialNumber dose not exist.

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

import { BusinessError } from '@ohos.base';
let accountManager = account_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<number>

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

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
serialNumbernumberYesAccount SN.

Return value

TypeDescription
Promise<number>Promise used to return the OS account ID obtained.

Error codes

IDError Message
12300001System service exception.
12300002Invalid serialNumber.
12300003The account indicated by serialNumber dose not exist.

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

import { BusinessError } from '@ohos.base';
let accountManager = account_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<number>): void

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

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
localIdnumberYesID of the target OS account.
callbackAsyncCallback<number>YesCallback invoked to return the result. If the operation is successful, err is null and data is the SN obtained. Otherwise, err is an error object.

Error codes

IDError Message
12300001System service exception.
12300002Invalid localId.
12300003Account not found.

Example: Obtain the SN of the OS account 100.

import { BusinessError } from '@ohos.base';
let accountManager = account_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<number>

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

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
localIdnumberYesID of the target OS account.

Return value

TypeDescription
Promise<number>Promise used to return the SN obtained.

Error codes

IDError Message
12300001System service exception.
12300002Invalid localId.
12300003Account not found.

Example: Obtain the SN of the OS account 100.

import { BusinessError } from '@ohos.base';
let accountManager = account_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));
}

on

on(type: 'activate'|'activating', name: string, callback: Callback<number>): void

Subscribes to the OS account activation states, including the states of the account being activated and the account with activation completed. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
type'activate' |'activating'YesType of the event to subscribe to. The value activate indicates an event reported when the OS account activation is complete, and activating indicates an event reported when OS account is being activated.
namestringYesSubscription name, which can be customized. The value cannot be empty or exceed 1024 bytes.
callbackCallback<number>YesCallback invoked to return the ID of the OS account being activated or activated.

Error codes

IDError Message
12300001System service exception.
12300002Invalid type or name.

Example

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

off

off(type: 'activate'|'activating', name: string, callback?: Callback<number>): void

Unsubscribes from the OS account activation states, including the states of the account being activated and the account with activation completed. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
type'activate' |'activating'YesType of the event to unsubscribe from. The value activate means an event indicating that an OS account is activated, and activating means an event indicating that an OS account is being activated.
namestringYesSubscription name, which can be customized. The value cannot be empty or exceed 1024 bytes, and must be the same as the value passed by on().
callbackCallback<number>NoCallback for the OS account activation state events. By default, this parameter is left empty, which unsubscribes from all the callbacks for the OS account activation state events.

Error codes

IDError Message
12300001System service exception.
12300002Invalid type or name.

Example

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

getBundleIdForUid9+

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

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

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
uidnumberYesProcess UID.
callbackAsyncCallback<number>YesCallback invoked to return the result. If the operation is successful, err is null and data is the bundle ID obtained. Otherwise, data is an error object.

Error codes

IDError Message
12300001System service exception.
12300002Invalid uid.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager();
let testUid: number = 1000000;
try {
  accountManager.getBundleIdForUid(testUid, (err: BusinessError, bundleId: number) => {
    console.info('getBundleIdForUid errInfo:' + JSON.stringify(err));
    console.info('getBundleIdForUid bundleId:' + JSON.stringify(bundleId));
  });
} catch (e) {
  console.info('getBundleIdForUid exception: ' + JSON.stringify(e));
}

getBundleIdForUid9+

getBundleIdForUid(uid: number): Promise<number>

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

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
uidnumberYesProcess UID.

Return value

TypeDescription
Promise<number>Promise used to return the bundle ID obtained.

Error codes

IDError Message
12300001System service exception.
12300002Invalid uid.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager();
let testUid: number = 1000000;
try {
  accountManager.getBundleIdForUid(testUid).then((result: number) => {
    console.info('getBundleIdForUid bundleId:' + JSON.stringify(result));
  }).catch((err: BusinessError) => {
    console.info('getBundleIdForUid errInfo:' + JSON.stringify(err));
  });
} catch (e) {
  console.info('getBundleIdForUid exception: ' + JSON.stringify(e));
}

getBundleIdForUidSync10+

getBundleIdForUidSync(uid: number): number

Obtains the bundle ID based on the specified UID. The API returns the result synchronously.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
uidnumberYesProcess UID.

Return value

TypeDescription
numberBundle ID obtained.

Error codes

IDError Message
12300002Invalid uid.

Example

let accountManager = account_osAccount.getAccountManager();
let testUid: number = 1000000;
try {
  let bundleId : number = accountManager.getBundleIdForUidSync(testUid);
  console.info('getBundleIdForUidSync bundleId:' + bundleId);
} catch (e) {
  console.info('getBundleIdForUidSync exception: ' + JSON.stringify(e));
}

isMainOsAccount9+

isMainOsAccount(callback: AsyncCallback<boolean>): void;

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

System API: This is a system API.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<boolean>YesCallback invoked to return the result. If true is returned, the current process belongs to the main OS account. If false is returned, the current process does not belong to the main OS account.

Error codes

IDError Message
12300001System service exception.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager();
try {
  accountManager.isMainOsAccount((err: BusinessError,result: boolean)=>{
    console.info('isMainOsAccount errInfo:' + JSON.stringify(err));
    console.info('isMainOsAccount result:' + JSON.stringify(result));
  });
} catch (e) {
  console.info('isMainOsAccount exception: ' + JSON.stringify(e));
}

isMainOsAccount9+

isMainOsAccount(): Promise<boolean>;

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

System API: This is a system API.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

System capability: SystemCapability.Account.OsAccount

Return value

TypeDescription
Promise<boolean>Promise used to return the result. If true is returned, the current process belongs to the main OS account. If false is returned, the current process does not belong to the main OS account.

Error codes

IDError Message
12300001System service exception.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager();
try {
  accountManager.isMainOsAccount().then((result: boolean) => {
    console.info('isMainOsAccount result:' + JSON.stringify(result));
  }).catch((err: BusinessError) => {
    console.info('isMainOsAccount errInfo:' + JSON.stringify(err));
  });
} catch (e) {
  console.info('isMainOsAccount exception: ' + JSON.stringify(e));
}

getOsAccountConstraintSourceTypes9+

getOsAccountConstraintSourceTypes(localId: number, constraint: string, callback: AsyncCallback<Array<ConstraintSourceTypeInfo>>): void;

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

System API: This is a system API.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
localIdnumberYesID of the target OS account.
constraintstringYesName of the constraint to query.
callbackAsyncCallback<Array<ConstraintSourceTypeInfo>>YesCallback invoked to return the result. If the operation is successful, err is null and data is the constraint source information obtained. Otherwise, err is an error object.

Error codes

IDError Message
12300001System service exception.
12300002Invalid name or constraint.
12300003Account not found.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager();
try {
  accountManager.getOsAccountConstraintSourceTypes(100, 'constraint.wifi',
    (err: BusinessError,sourceTypeInfos: account_osAccount.ConstraintSourceTypeInfo[])=>{
    console.info('getOsAccountConstraintSourceTypes errInfo:' + JSON.stringify(err));
    console.info('getOsAccountConstraintSourceTypes sourceTypeInfos:' + JSON.stringify(sourceTypeInfos));
  });
} catch (e) {
  console.info('getOsAccountConstraintSourceTypes exception: ' + JSON.stringify(e));
}

getOsAccountConstraintSourceTypes9+

getOsAccountConstraintSourceTypes(localId: number, constraint: string): Promise<Array<ConstraintSourceTypeInfo>>;

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

System API: This is a system API.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
localIdnumberYesID of the target OS account.
constraintstringYesName of the constraint to query.

Return value

TypeDescription
Promise<Array<ConstraintSourceTypeInfo>>Promise used to return the constraint source information obtained.

Error codes

IDError Message
12300001System service exception.
12300002Invalid name or constraint.
12300003Account not found.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager();
try {
  accountManager.getOsAccountConstraintSourceTypes(100, 'constraint.wifi').then(
    (result: account_osAccount.ConstraintSourceTypeInfo[]) => {
    console.info('getOsAccountConstraintSourceTypes sourceTypeInfos:' + JSON.stringify(result));
  }).catch((err: BusinessError) => {
    console.info('getOsAccountConstraintSourceTypes errInfo:' + JSON.stringify(err));
  });
} catch (e) {
  console.info('getOsAccountConstraintSourceTypes exception: ' + JSON.stringify(e));
}

isMultiOsAccountEnable(deprecated)

isMultiOsAccountEnable(callback: AsyncCallback<boolean>): void

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

NOTE

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

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<boolean>YesCallback invoked to return the result. The value true means multiple OS accounts are supported; the value false means the opposite.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_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<boolean>

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

NOTE

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

System capability: SystemCapability.Account.OsAccount

Return value

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

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_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<boolean>): void

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

NOTE

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

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

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
localIdnumberYesID of the target OS account.
callbackAsyncCallback<boolean>YesCallback invoked to return the result. The value true means the account is activated; the value false means the opposite.

Example: Check whether OS account 100 is activated.

import { BusinessError } from '@ohos.base';
let accountManager = account_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<boolean>

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

NOTE

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

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

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
localIdnumberYesID of the target OS account.

Return value

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

Example: Check whether OS account 100 is activated.

import { BusinessError } from '@ohos.base';
let accountManager = account_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<boolean>): void

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

NOTE

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

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
localIdnumberYesID of the target OS account.
constraintstringYesConstraint to check.
callbackAsyncCallback<boolean>YesCallback invoked to return the result. The value true means the specified constraint is enabled; the value false means the opposite.

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

import { BusinessError } from '@ohos.base';
let accountManager = account_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<boolean>

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

NOTE

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

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
localIdnumberYesID of the target OS account.
constraintstringYesConstraint to check.

Return value

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

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

import { BusinessError } from '@ohos.base';
let accountManager = account_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<boolean>): void

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

NOTE

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

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<boolean>YesCallback invoked to return the result. The value true means the account is a test account; the value false means the opposite.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_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<boolean>

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

NOTE

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

System capability: SystemCapability.Account.OsAccount

Return value

TypeDescription
Promise<boolean>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 '@ohos.base';
let accountManager = account_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<boolean>): void

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

NOTE

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

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

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<boolean>YesCallback invoked to return the result. The value true means the OS account has been verified; the value false means the opposite.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_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<boolean>): void

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

NOTE

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

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

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
localIdnumberYesID of the target OS account.
callbackAsyncCallback<boolean>YesCallback invoked to return the result. The value true means the OS account has been verified; the value false means the opposite.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_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<boolean>

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

NOTE

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

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

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
localIdnumberNoID of the target OS account. If this parameter is not specified, this API checks whether the current OS account has been verified.

Return value

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

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager();
accountManager.isOsAccountVerified(localId).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<number>): void

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

NOTE

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

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<number>YesCallback invoked to return the result. If the operation is successful, err is null and data is the number of created OS accounts. If the operation fails, err is an error object.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_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<number>

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

NOTE

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

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

System capability: SystemCapability.Account.OsAccount

Return value

TypeDescription
Promise<number>Promise used to return the number of created OS accounts.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_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<number>): void

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

NOTE

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

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<number>YesCallback invoked to return the result. If the operation is successful, err is null and data is the OS account ID obtained. Otherwise, err is an error object.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_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<number>

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

NOTE

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

System capability: SystemCapability.Account.OsAccount

Return value

TypeDescription
Promise<number>Promise used to return the OS account ID obtained.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_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<number>): void

Obtains the OS 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. You are advised to use getOsAccountLocalIdForUid.

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
uidnumberYesProcess UID.
callbackAsyncCallback<number>YesCallback invoked to return the result. If the operation is successful, err is null and data is the OS account ID obtained. Otherwise, data is an error object.

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

import { BusinessError } from '@ohos.base';
let accountManager = account_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<number>

Obtains the OS 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. You are advised to use getOsAccountLocalIdForUid.

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
uidnumberYesProcess UID.

Return value

TypeDescription
Promise<number>Promise used to return the OS account ID obtained.

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

import { BusinessError } from '@ohos.base';
let accountManager = account_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<number>): void

Obtains the OS 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. You are advised to use getOsAccountLocalIdForDomain.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
domainInfoDomainAccountInfoYesDomain account information.
callbackAsyncCallback<number>YesCallback invoked to return the result. If the operation is successful, err is null and data is the OS account ID obtained. Otherwise, err is an error object.

Example

import { BusinessError } from '@ohos.base';
let domainInfo: account_osAccount.DomainAccountInfo = {domain: 'testDomain', accountName: 'testAccountName'};
let accountManager = account_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<number>

Obtains the OS 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. You are advised to use getOsAccountLocalIdForDomain.

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
domainInfoDomainAccountInfoYesDomain account information.

Return value

TypeDescription
Promise<number>Promise used to return the ID of the OS account associated with the domain account.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager();
let domainInfo: account_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<Array<string>>): void

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

NOTE

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

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
localIdnumberYesID of the target OS account.
callbackAsyncCallback<Array<string>>YesCallback invoked to return the result. If the operation is successful, err is null and data is a list of all constraints enabled for the OS account. Otherwise, err is an error object.

Example: Obtain all constraints of OS account 100.

import { BusinessError } from '@ohos.base';
let accountManager = account_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<Array<string>>

NOTE

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

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

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
localIdnumberYesID of the target OS account.

Return value

TypeDescription
Promise<Array<string>>Promise used to return all the constraints enabled for the OS account.

Example: Obtain all constraints of OS account 100.

import { BusinessError } from '@ohos.base';
let accountManager = account_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<Array<number>>): void

Obtains information about all activated OS 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. You are advised to use getActivatedOsAccountLocalIds.

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<Array<number>>YesCallback invoked to return the result. If the operation is successful, err is null and data is a list of activated OS accounts. Otherwise, data is an error object.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_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<Array<number>>

NOTE

This API is supported since API version 8 and deprecated since API version 9. You are advised to use getActivatedOsAccountLocalIds.

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

System capability: SystemCapability.Account.OsAccount

Return value

TypeDescription
Promise<Array<number>>Promise used to return the information about all activated OS accounts.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_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<OsAccountInfo>): void

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

NOTE

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

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<OsAccountInfo>YesCallback invoked to return the result. If the operation is successful, err is null and data is the OS account information obtained. Otherwise, data is an error object.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager();
accountManager.queryCurrentOsAccount((err: BusinessError, curAccountInfo: account_osAccount.OsAccountInfo)=>{
  console.log('queryCurrentOsAccount err:' + JSON.stringify(err));
  console.log('queryCurrentOsAccount curAccountInfo:' + JSON.stringify(curAccountInfo));
});

queryCurrentOsAccount(deprecated)

queryCurrentOsAccount(): Promise<OsAccountInfo>

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

NOTE

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

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

System capability: SystemCapability.Account.OsAccount

Return value

TypeDescription
Promise<OsAccountInfo>Promise used to return the OS account information obtained.

Example

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

getOsAccountTypeFromProcess(deprecated)

getOsAccountTypeFromProcess(callback: AsyncCallback<OsAccountType>): 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. You are advised to use getOsAccountType.

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<OsAccountType>YesCallback invoked to return the result. If the operation is successful, err is null and data is the OS account type obtained. Otherwise, err is an error object.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager();
accountManager.getOsAccountTypeFromProcess((err: BusinessError, accountType: account_osAccount.OsAccountType) => {
  console.log('getOsAccountTypeFromProcess err: ' + JSON.stringify(err));
  console.log('getOsAccountTypeFromProcess accountType: ' + accountType);
});

getOsAccountTypeFromProcess(deprecated)

getOsAccountTypeFromProcess(): Promise<OsAccountType>

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. You are advised to use getOsAccountType.

System capability: SystemCapability.Account.OsAccount

Return value

TypeDescription
Promise<OsAccountType>Promise used to return the OS account type obtained.

Example

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

getDistributedVirtualDeviceId(deprecated)

getDistributedVirtualDeviceId(callback: AsyncCallback<string>): 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. You are advised to use queryDistributedVirtualDeviceId.

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

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<string>YesCallback invoked to return the result. If the operation is successful, err is null and data is the distributed virtual device ID obtained. Otherwise, data is an error object.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_osAccount.getAccountManager();
accountManager.getDistributedVirtualDeviceId((err: BusinessError, virtualID: string) => {
  console.log('getDistributedVirtualDeviceId err: ' + JSON.stringify(err));
  console.log('getDistributedVirtualDeviceId virtualID: ' + virtualID);
});

getDistributedVirtualDeviceId(deprecated)

getDistributedVirtualDeviceId(): Promise<string>

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. You are advised to use queryDistributedVirtualDeviceId.

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

System capability: SystemCapability.Account.OsAccount

Return value

TypeDescription
Promise<string>Promise used to return the distributed virtual device ID obtained.

Example

import { BusinessError } from '@ohos.base';
let accountManager = account_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<number>): void

Obtains the OS 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. You are advised to use getOsAccountLocalIdForSerialNumber.

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
serialNumbernumberYesAccount SN.
callbackAsyncCallback<number>YesCallback invoked to return the result. If the operation is successful, err is null and data is the OS account ID obtained. Otherwise, err is an error object.

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

import { BusinessError } from '@ohos.base';
let accountManager = account_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<number>

Obtains the OS 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. You are advised to use getOsAccountLocalIdForSerialNumber.

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
serialNumbernumberYesAccount SN.

Return value

TypeDescription
Promise<number>Promise used to return the OS account ID obtained.

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

import { BusinessError } from '@ohos.base';
let accountManager = account_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<number>): void

Obtains the SN of an OS 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. You are advised to use getSerialNumberForOsAccountLocalId.

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
localIdnumberYesID of the target OS account.
callbackAsyncCallback<number>YesCallback invoked to return the result. If the operation is successful, err is null and data is the SN obtained. Otherwise, err is an error object.

Example: Obtain the SN of the OS account 100.

import { BusinessError } from '@ohos.base';
let accountManager = account_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<number>

Obtains the SN of an OS 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. You are advised to use getSerialNumberForOsAccountLocalId.

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
localIdnumberYesID of the target OS account.

Return value

TypeDescription
Promise<number>Promise used to return the SN obtained.

Example: Obtain the SN of the OS account 100.

import { BusinessError } from '@ohos.base';
let accountManager = account_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));
});

UserAuth8+

Provides APIs for user authentication.

System API: This is a system API.

constructor8+

constructor()

A constructor used to create an instance for user authentication.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Example

let userAuth = new account_osAccount.UserAuth();

getVersion8+

getVersion(): number;

Obtains version information.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Return value

TypeDescription
numberVersion information obtained.

Example

let userAuth = new account_osAccount.UserAuth();
let version: number = userAuth.getVersion();
console.log('getVersion version = ' + version);

getAvailableStatus8+

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

Obtains the available status of the authentication capability corresponding to the specified authentication type and trust level.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.ACCESS_USER_AUTH_INTERNAL

Parameters

NameTypeMandatoryDescription
authTypeAuthTypeYesAuthentication credential type.
authTrustLevelAuthTrustLevelYesTrust level of the authentication.

Return value

TypeDescription
numberAvailable status of the authentication capability.

Error codes

IDError Message
12300001System service exception.
12300002Invalid authType or authTrustLevel.

Example

let userAuth = new account_osAccount.UserAuth();
let authType: account_osAccount.AuthType = account_osAccount.AuthType.PIN;
let authTrustLevel: account_osAccount.AuthTrustLevel = account_osAccount.AuthTrustLevel.ATL1;
try {
  let status: number = userAuth.getAvailableStatus(authType, authTrustLevel);
  console.log('getAvailableStatus status = ' + status);
} catch (e) {
  console.log('getAvailableStatus exception = ' + JSON.stringify(e));
}

getProperty8+

getProperty(request: GetPropertyRequest, callback: AsyncCallback<ExecutorProperty>): void;

Obtains the executor property based on the request. This API uses an asynchronous callback to return the result.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.ACCESS_USER_AUTH_INTERNAL

Parameters

NameTypeMandatoryDescription
requestGetPropertyRequestYesRequest information, including the authentication credential type and property list.
callbackAsyncCallback<ExecutorProperty>YesCallback invoked to return the result. If the operation is successful, err is null and data is the executor property information obtained. Otherwise, err is an error object.

Error codes

IDError Message
12300001System service exception.
12300002Invalid request.

Example

import { BusinessError } from '@ohos.base';
let userAuth = new account_osAccount.UserAuth();
let keys: Array<account_osAccount.GetPropertyType>  = [
  account_osAccount.GetPropertyType.AUTH_SUB_TYPE,
  account_osAccount.GetPropertyType.REMAIN_TIMES,
  account_osAccount.GetPropertyType.FREEZING_TIME
];
let request: account_osAccount.GetPropertyRequest = {
  authType: account_osAccount.AuthType.PIN,
  keys: keys
};
try {
  userAuth.getProperty(request, (err: BusinessError, result: account_osAccount.ExecutorProperty) => {
    console.log('getProperty err = ' + JSON.stringify(err));
    console.log('getProperty result = ' + JSON.stringify(result));
  });
} catch (e) {
  console.log('getProperty exception = ' + JSON.stringify(e));
}

getProperty8+

getProperty(request: GetPropertyRequest): Promise<ExecutorProperty>;

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

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.ACCESS_USER_AUTH_INTERNAL

Parameters

NameTypeMandatoryDescription
requestGetPropertyRequestYesRequest information, including the authentication credential type and property list.

Return value

TypeDescription
Promise<ExecutorProperty>Promise used to return the executor property information obtained.

Error codes

IDError Message
12300001System service exception.
12300002Invalid request.

Example

import { BusinessError } from '@ohos.base';
let userAuth = new account_osAccount.UserAuth();
let keys: Array<account_osAccount.GetPropertyType> = [
  account_osAccount.GetPropertyType.AUTH_SUB_TYPE, 
  account_osAccount.GetPropertyType.REMAIN_TIMES,
  account_osAccount.GetPropertyType.FREEZING_TIME
];
let request: account_osAccount.GetPropertyRequest = {
  authType: account_osAccount.AuthType.PIN,
  keys: keys
};
try {
  userAuth.getProperty(request).then((result: account_osAccount.ExecutorProperty) => {
    console.log('getProperty result = ' + JSON.stringify(result));
  }).catch((err: BusinessError) => {
    console.log('getProperty error = ' + JSON.stringify(err));
  });
} catch (e) {
  console.log('getProperty exception = ' + JSON.stringify(e));
}

setProperty8+

setProperty(request: SetPropertyRequest, callback: AsyncCallback<void>): void;

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

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.ACCESS_USER_AUTH_INTERNAL

Parameters

NameTypeMandatoryDescription
requestSetPropertyRequestYesRequest information, including the authentication credential type and the key value to set.
callbackAsyncCallback<void>YesCallback invoked to return the result. If the operation is successful, err is null. Otherwise, err is an error object.

Error codes

IDError Message
12300001System service exception.
12300002Invalid request.

Example

import { BusinessError } from '@ohos.base';
let userAuth = new account_osAccount.UserAuth();
let request: account_osAccount.SetPropertyRequest = {
  authType: account_osAccount.AuthType.PIN,
  key: account_osAccount.SetPropertyType.INIT_ALGORITHM,
  setInfo: new Uint8Array([0])
};
try {
  userAuth.setProperty(request, (err: BusinessError) => {
    if (err) {
      console.log('setProperty failed, error = ' + JSON.stringify(err));
    } else {
      console.log('setProperty successfully');
    }
  });
} catch (e) {
  console.log('setProperty exception = ' + JSON.stringify(e));
}

setProperty8+

setProperty(request: SetPropertyRequest): Promise<void>;

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

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.ACCESS_USER_AUTH_INTERNAL

Parameters

NameTypeMandatoryDescription
requestSetPropertyRequestYesRequest information, including the authentication credential type and the key value to set.

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

IDError Message
12300001System service exception.
12300002Invalid request.

Example

import { BusinessError } from '@ohos.base';
let userAuth = new account_osAccount.UserAuth();
let request: account_osAccount.SetPropertyRequest = {
  authType: account_osAccount.AuthType.PIN,
  key: account_osAccount.SetPropertyType.INIT_ALGORITHM,
  setInfo: new Uint8Array([0])
};
try {
  userAuth.setProperty(request).then(() => {
    console.log('setProperty successfully');
  }).catch((err: BusinessError) => {
    console.log('setProperty failed, error = ' + JSON.stringify(err));
  });
} catch (e) {
  console.log('setProperty exception = ' + JSON.stringify(e));
}

auth8+

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

Performs authentication of the current user. This API uses an asynchronous callback to return the result.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.ACCESS_USER_AUTH_INTERNAL

Parameters

NameTypeMandatoryDescription
challengeUint8ArrayYesChallenge value, which is a random number used to improve security.
authTypeAuthTypeYesAuthentication credential type.
authTrustLevelAuthTrustLevelYesTrust level of the authentication result.
callbackIUserAuthCallbackYesCallback invoked to return the authentication result.

Return value

TypeDescription
Uint8ArrayID of the context for canceling the authentication.

Error codes

IDError Message
12300001System service exception.
12300002Invalid challenge, authType, or authTrustLevel.
12300101Credential is incorrect.
12300102Credential not enrolled.
12300105Unsupported authTrustLevel.
12300106Unsupported authType.
12300109Authentication is canceled.
12300110Authentication is locked.
12300111Authentication timeout.
12300112Authentication service is busy.

Example

let userAuth = new account_osAccount.UserAuth();
let challenge: Uint8Array = new Uint8Array([0]);
let authType: account_osAccount.AuthType = account_osAccount.AuthType.PIN;
let authTrustLevel: account_osAccount.AuthTrustLevel = account_osAccount.AuthTrustLevel.ATL1;
try {
  userAuth.auth(challenge, authType, authTrustLevel, {
    onResult: (result: number, extraInfo: account_osAccount.AuthResult) => {
        console.log('auth result = ' + result);
        console.log('auth extraInfo = ' + JSON.stringify(extraInfo));
    }
  });
} catch (e) {
  console.log('auth exception = ' + JSON.stringify(e));
}

authUser8+

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

Performs authentication of the specified user. This API uses an asynchronous callback to return the result.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.ACCESS_USER_AUTH_INTERNAL

Parameters

NameTypeMandatoryDescription
userIdnumberYesUser ID.
challengeUint8ArrayYesChallenge value, which is a random number used to improve security.
authTypeAuthTypeYesAuthentication credential type.
authTrustLevelAuthTrustLevelYesTrust level of the authentication result.
callbackIUserAuthCallbackYesCallback invoked to return the authentication result.

Return value

TypeDescription
Uint8ArrayID of the context for canceling the authentication.

Error codes

IDError Message
12300001System service exception.
12300002Invalid userId, challenge, authType, or authTrustLevel.
12300101Credential is incorrect.
12300102Credential not enrolled.
12300105Unsupported authTrustLevel.
12300106Unsupported authType.
12300109Authentication is canceled.
12300110Authentication is locked.
12300111Authentication timeout.
12300112Authentication service is busy.

Example

let userAuth = new account_osAccount.UserAuth();
let userID: number = 100;
let challenge: Uint8Array = new Uint8Array([0]);
let authType: account_osAccount.AuthType = account_osAccount.AuthType.PIN;
let authTrustLevel: account_osAccount.AuthTrustLevel = account_osAccount.AuthTrustLevel.ATL1;
try {
  userAuth.authUser(userID, challenge, authType, authTrustLevel, {
    onResult: (result,extraInfo) => {
      console.log('authUser result = ' + result);
      console.log('authUser extraInfo = ' + JSON.stringify(extraInfo));
    }
  });
} catch (e) {
  console.log('authUser exception = ' + JSON.stringify(e));
}

cancelAuth8+

cancelAuth(contextID: Uint8Array): void;

Cancels an authentication.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.ACCESS_USER_AUTH_INTERNAL

Parameters

NameTypeMandatoryDescription
contextIdUint8ArrayYesID of the authentication context. The context ID is dynamically generated.

Error codes

IDError Message
12300001System service exception.
12300002Invalid contextId.

Example

let userAuth = new account_osAccount.UserAuth();
let pinAuth: account_osAccount.PINAuth = new account_osAccount.PINAuth();
let challenge = new Uint8Array([0]);
let contextId: Uint8Array = userAuth.auth(challenge, account_osAccount.AuthType.PIN, account_osAccount.AuthTrustLevel.ATL1, {
  onResult: (result: number, extraInfo: account_osAccount.AuthResult) => {
    console.log('auth result = ' + result);
    console.log('auth extraInfo = ' + JSON.stringify(extraInfo));
  }
});
try {
  userAuth.cancelAuth(contextId);
} catch (e) {
  console.log('cancelAuth exception = ' + JSON.stringify(e));
}

PINAuth8+

Provides APIs for PIN authentication.

System API: This is a system API.

constructor8+

constructor()

A constructor used to create an instance for PIN authentication.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Example

let pinAuth: account_osAccount.PINAuth = new account_osAccount.PINAuth();

registerInputer8+

registerInputer(inputer: IInputer): void;

Register a PIN inputer.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.ACCESS_PIN_AUTH

Parameters

NameTypeMandatoryDescription
inputerIInputerYesPIN inputer, which is used to obtain the PIN.

Error codes

IDError Message
12300001System service exception.
12300002Invalid inputer.
12300103Inputer already registered.

Example

let pinAuth: account_osAccount.PINAuth = new account_osAccount.PINAuth();
let password = new Uint8Array([0, 0, 0, 0, 0]);
try {
  let result = pinAuth.registerInputer({
      onGetData: (authSubType: account_osAccount.AuthSubType, callback: account_osAccount.IInputData) => {
        callback.onSetData(authSubType, password);
      }
  });
  console.log('registerInputer result = ' + result);
} catch (e) {
  console.log('registerInputer exception = ' + JSON.stringify(e));
}

unregisterInputer8+

unregisterInputer(): void;

Unregisters this PIN inputer.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.ACCESS_PIN_AUTH

Example

let pinAuth: account_osAccount.PINAuth = new account_osAccount.PINAuth();
pinAuth.unregisterInputer();

InputerManager 9+

Provides APIs for managing credential inputers.

registerInputer9+

static registerInputer(authType: AuthType, inputer: IInputer): void

Register a credential inputer.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.ACCESS_USER_AUTH_INTERNAL or ohos.permission.MANAGE_USER_IDM

Parameters

NameTypeMandatoryDescription
authTypeAuthTypeYesAuthentication credential type.
inputerIInputerYesCredential inputer to register.

Error codes

IDError Message
12300001System service exception.
12300002Invalid authType or inputer.
12300103The credential inputer has been registered.
12300106Unsupported authType.

Example

let authType: account_osAccount.AuthType = account_osAccount.AuthType.DOMAIN;
let password: Uint8Array = new Uint8Array([0, 0, 0, 0, 0]);
try {
  account_osAccount.InputerManager.registerInputer(authType, {
      onGetData: (authSubType: account_osAccount.AuthSubType, callback: account_osAccount.IInputData) => {
        callback.onSetData(authSubType, password);
      }
  });
  console.log('registerInputer success.');
} catch (e) {
  console.log('registerInputer exception = ' + JSON.stringify(e));
}

unregisterInputer9+

static unregisterInputer(authType: AuthType): void

Unregisters this credential inputer.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.ACCESS_USER_AUTH_INTERNAL or ohos.permission.MANAGE_USER_IDM

Parameters

NameTypeMandatoryDescription
authTypeAuthTypeYesAuthentication credential type.

Error codes

IDError Message
12300002Invalid authType.

Example

let authType: account_osAccount.AuthType = account_osAccount.AuthType.DOMAIN;
try {
  account_osAccount.InputerManager.unregisterInputer(authType);
  console.log('unregisterInputer success.');
} catch(err) {
  console.log('unregisterInputer err:' + JSON.stringify(err));
}

DomainPlugin9+

Provides APIs for domain account authentication.

System API: This is a system API.

auth9+

auth(domainAccountInfo: DomainAccountInfo, credential: Uint8Array, callback: IUserAuthCallback): void

Authenticates a domain account.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
domainAccountInfoDomainAccountInfoYesDomain account information.
credentialUint8ArrayYesCredentials of the domain account.
callbackIUserAuthCallbackYesCallback invoked to return the authentication result.

Example

import { AsyncCallback } from './@ohos.base';
let plugin: account_osAccount.DomainPlugin = {
  auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array,
        callback: account_osAccount.IUserAuthCallback) => {
    // mock authentication
    // notify authentication result
    let result: account_osAccount.AuthResult = {
      token: new Uint8Array([0]),
      remainTimes: 5,
      freezingTime: 0
    };
    callback.onResult(0, result);
  },
  authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                  callback: account_osAccount.IUserAuthCallback) => {},
  authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                  callback: account_osAccount.IUserAuthCallback) => {},
  getAccountInfo: (options: account_osAccount.GetDomainAccountInfoPluginOptions,
                  callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {},
  getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                    callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {},
  bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number,
                callback: AsyncCallback<void>) => {},
  unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {},
  isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                        callback: AsyncCallback<boolean>) => {},
  getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {}
}
account_osAccount.DomainAccountManager.registerPlugin(plugin);
let userAuth = new account_osAccount.UserAuth();
let challenge: Uint8Array = new Uint8Array([0]);
let authType: account_osAccount.AuthType = account_osAccount.AuthType.DOMAIN;
let authTrustLevel: account_osAccount.AuthTrustLevel = account_osAccount.AuthTrustLevel.ATL1;
try {
  userAuth.auth(challenge, authType, authTrustLevel, {
    onResult: (resultCode: number, authResult: account_osAccount.AuthResult) => {
        console.log('auth resultCode = ' + resultCode);
        console.log('auth authResult = ' + JSON.stringify(authResult));
    }
  });
} catch (err) {
  console.log('auth exception = ' + JSON.stringify(err));
}

authWithPopup10+

authWithPopup(domainAccountInfo: DomainAccountInfo, callback: IUserAuthCallback): void

Authenticates a domain account in a pop-up window.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
domainAccountInfoDomainAccountInfoYesDomain account information.
callbackIUserAuthCallbackYesCallback invoked to return the authentication result.

Example

import { AsyncCallback } from './@ohos.base';
let plugin: account_osAccount.DomainPlugin = {
  auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array,
        callback: account_osAccount.IUserAuthCallback) => {},
  authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                  callback: account_osAccount.IUserAuthCallback) => {
    // mock authentication
    // notify authentication result
    let result: account_osAccount.AuthResult = {
      token: new Uint8Array([0]),
      remainTimes: 5,
      freezingTime: 0
    };
    callback.onResult(0, result);
  },
  authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                  callback: account_osAccount.IUserAuthCallback) => {},
  getAccountInfo: (options: account_osAccount.GetDomainAccountInfoPluginOptions,
                  callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {},
  getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                      callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {},
  bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number,
                callback: AsyncCallback<void>) => {},
  unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {},
  isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                        callback: AsyncCallback<boolean>) => {},
  getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {}
}
account_osAccount.DomainAccountManager.registerPlugin(plugin)

authWithToken10+

authWithToken(domainAccountInfo: DomainAccountInfo, token: Uint8Array, callback: IUserAuthCallback): void

Authenticates a domain account by the authorization token.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
domainAccountInfoDomainAccountInfoYesDomain account information.
tokenUint8ArrayYesAuthorization token generated when the PIN or biometric authentication is successful.
callbackIUserAuthCallbackYesCallback invoked to return the authentication result.

Example

import { AsyncCallback } from './@ohos.base';
let plugin: account_osAccount.DomainPlugin = {
  auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array,
        callback: account_osAccount.IUserAuthCallback) => {},
  authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                  callback: account_osAccount.IUserAuthCallback) => {},
  authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                  callback: account_osAccount.IUserAuthCallback) => {
    // mock authentication
    // notify authentication result
    let result: account_osAccount.AuthResult = {
      token: new Uint8Array([0]),
      remainTimes: 5,
      freezingTime: 0
    };
    callback.onResult(0, result);
  },
  getAccountInfo: (options: account_osAccount.GetDomainAccountInfoPluginOptions,
                  callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {},
  getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                      callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {},
  bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number,
                callback: AsyncCallback<void>) => {},
  unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {},
  isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                        callback: AsyncCallback<boolean>) => {},
  getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {}
}
account_osAccount.DomainAccountManager.registerPlugin(plugin)

getAccountInfo10+

getAccountInfo(options: GetDomainAccountInfoPluginOptions, callback: AsyncCallback<DomainAccountInfo>): void

Obtains information about a domain account.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
optionsGetDomainAccountInfoPluginOptionsYesOptions for obtaining the domain account information.
callbackAsyncCallback<DomainAccountInfo>YesCallback invoked to return the result.

Example

import { AsyncCallback, BusinessError } from '@ohos.base';
let plugin: account_osAccount.DomainPlugin = {
  auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array,
        callback: account_osAccount.IUserAuthCallback) => {},
  authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                  callback: account_osAccount.IUserAuthCallback) => {},
  authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                  callback: account_osAccount.IUserAuthCallback) => {},
  getAccountInfo: (options: account_osAccount.GetDomainAccountInfoPluginOptions,
                  callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {
    // mock getting account information
    // notify result
    let code: BusinessError = {
      code: 0,
      name: "",
      message: ""
    };
    let accountInfo: account_osAccount.DomainAccountInfo = {
      domain: options.domain,
      accountName: options.accountName,
      accountId: 'xxxx'
    };
    callback(code, accountInfo);
  },
  getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                      callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {},
  bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number,
                callback: AsyncCallback<void>) => {},
  unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {},
  isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                        callback: AsyncCallback<boolean>) => {},
  getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {}
}
account_osAccount.DomainAccountManager.registerPlugin(plugin)

getAuthStatusInfo10+

getAuthStatusInfo(domainAccountInfo: DomainAccountInfo, callback: AsyncCallback<AuthStatusInfo>): void

Obtains the authentication status of a domain account.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
domainAccountInfoDomainAccountInfoYesDomain account information.
callbackAsyncCallback<AuthStatusInfo>YesCallback invoked to return the result.

Example

import { AsyncCallback, BusinessError } from '@ohos.base';
let plugin: account_osAccount.DomainPlugin = {
  auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array,
        callback: account_osAccount.IUserAuthCallback) => {},
  authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                  callback: account_osAccount.IUserAuthCallback) => {},
  authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                  callback: account_osAccount.IUserAuthCallback) => {},
  getAccountInfo: (options: account_osAccount.GetDomainAccountInfoPluginOptions,
                  callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {},
  getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                      callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {
    let code: BusinessError = {
      code: 0,
      name: "",
      message: ""
    };
    let statusInfo: account_osAccount.AuthStatusInfo = {
      remainTimes: 5,
      freezingTime: 0
    };
    callback(code, statusInfo);
  },
  bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number,
                callback: AsyncCallback<void>) => {},
  unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {},
  isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                        callback: AsyncCallback<boolean>) => {},
  getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {}
}
account_osAccount.DomainAccountManager.registerPlugin(plugin)

bindAccount10+

bindAccount(domainAccountInfo: DomainAccountInfo, localId: number, callback: AsyncCallback<void>): void

Binds a domain account.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
domainAccountInfoDomainAccountInfoYesDomain account information.
callbackAsyncCallback<void>YesCallback invoked to return the result.

Example

import { AsyncCallback, BusinessError } from './@ohos.base';
let plugin: account_osAccount.DomainPlugin = {
  auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array,
        callback: account_osAccount.IUserAuthCallback) => {},
  authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                  callback: account_osAccount.IUserAuthCallback) => {},
  authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                  callback: account_osAccount.IUserAuthCallback) => {},
  getAccountInfo: (options: account_osAccount.GetDomainAccountInfoPluginOptions,
                  callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {},
  getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                      callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {},
  bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number,
                callback: AsyncCallback<void>) => {
    // mock unbinding operation
    // notify binding result
    let code: BusinessError = {
      code: 0,
      name: "",
      message: ""
    };
    callback(code);
  },
  unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {},
  isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                        callback: AsyncCallback<boolean>) => {},
  getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {}
}
account_osAccount.DomainAccountManager.registerPlugin(plugin)

unbindAccount10+

unbindAccount(domainAccountInfo: DomainAccountInfo, callback: AsyncCallback<void>): void

Unbinds a domain account.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
domainAccountInfoDomainAccountInfoYesDomain account information.
callbackAsyncCallback<void>YesCallback invoked to return the result.

Example

import { AsyncCallback, BusinessError } from './@ohos.base';
let plugin: account_osAccount.DomainPlugin = {
  auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array,
        callback: account_osAccount.IUserAuthCallback) => {},
  authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                  callback: account_osAccount.IUserAuthCallback) => {},
  authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                  callback: account_osAccount.IUserAuthCallback) => {},
  getAccountInfo: (options: account_osAccount.GetDomainAccountInfoPluginOptions,
                  callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {},
  getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                      callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {},
  bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number,
                callback: AsyncCallback<void>) => {},
  unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {
    // mock unbinding operation
    // notify unbinding result
    let code: BusinessError = {
      code: 0,
      name: "",
      message: ""
    };
    callback(code);
  },
  isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                        callback: AsyncCallback<boolean>) => {},
  getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {}
}
account_osAccount.DomainAccountManager.registerPlugin(plugin)

isAccountTokenValid10+

isAccountTokenValid(domainAccountInfo: DomainAccountInfo, token: Uint8Array, callback: AsyncCallback<boolean>): void

Checks whether the specified domain account token is valid.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
domainAccountInfoDomainAccountInfoYesDomain account information.
tokenUint8ArrayYesDomain account token to check.
callbackAsyncCallback<boolean>YesCallback invoked to return the result.

Example

import { AsyncCallback, BusinessError } from './@ohos.base';
let plugin: account_osAccount.DomainPlugin = {
  auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array,
        callback: account_osAccount.IUserAuthCallback) => {},
  authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                  callback: account_osAccount.IUserAuthCallback) => {},
  authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                  callback: account_osAccount.IUserAuthCallback) => {},
  getAccountInfo: (options: account_osAccount.GetDomainAccountInfoPluginOptions,
                  callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {},
  getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                      callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {},
  bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number,
                callback: AsyncCallback<void>) => {},
  unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {},
  isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                        callback: AsyncCallback<boolean>) => {
    // mock checking operation
    // notify checking result
    let code: BusinessError = {
      code: 0,
      name: "",
      message: ""
    };
    callback(code, true);
  },
  getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {}
}
account_osAccount.DomainAccountManager.registerPlugin(plugin)

getAccessToken10+

getAccessToken(options: GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>): void

Obtains the domain access token based on the specified conditions.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
optionsGetDomainAccessTokenOptionsYesOptions specified for obtaining the domain access token.
callbackAsyncCallback<Uint8Array>YesCallback invoked to return the result.

Example

import { AsyncCallback, BusinessError } from './@ohos.base';
let plugin: account_osAccount.DomainPlugin = {
  auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array,
        callback: account_osAccount.IUserAuthCallback) => {},
  authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                  callback: account_osAccount.IUserAuthCallback) => {},
  authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                  callback: account_osAccount.IUserAuthCallback) => {},
  getAccountInfo: (options: account_osAccount.GetDomainAccountInfoPluginOptions,
                  callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {},
  getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                      callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {},
  bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number,
                callback: AsyncCallback<void>) => {},
  unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {},
  isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                        callback: AsyncCallback<boolean>) => {},
  getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {
    // mock getting operation
    // notify result
    let code: BusinessError = {
      code: 0,
      name: "",
      message: ""
    };
    let token: Uint8Array = new Uint8Array([0]);
    callback(code, token);
  }
}
account_osAccount.DomainAccountManager.registerPlugin(plugin)

DomainAccountManager 9+

Provides APIs for domain account management.

registerPlugin9+

static registerPlugin(plugin: DomainPlugin): void

Registers a domain plug-in.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

Parameters

NameTypeMandatoryDescription
pluginDomainPluginYesDomain plug-in to register.

Error codes

IDError Message
12300201The domain plugin has been registered.

Example

import { AsyncCallback } from './@ohos.base';
let plugin: account_osAccount.DomainPlugin = {
  auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array,
       callback: account_osAccount.IUserAuthCallback) => {},
  authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                callback: account_osAccount.IUserAuthCallback) => {},
  authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                callback: account_osAccount.IUserAuthCallback) => {},
  getAccountInfo: (options: account_osAccount.GetDomainAccountInfoPluginOptions,
                 callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {},
  getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo,
                      callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {},
  bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number,
                callback: AsyncCallback<void>) => {},
  unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {},
  isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array,
                      callback: AsyncCallback<boolean>) => {},
  getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {}
}
try {
  account_osAccount.DomainAccountManager.registerPlugin(plugin);
  console.log('registerPlugin success.');
} catch(err) {
  console.log('registerPlugin err:' + JSON.stringify(err));
}

unregisterPlugin9+

static unregisterPlugin(): void

Unregisters this domain plug-in.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

Example

try {
  account_osAccount.DomainAccountManager.unregisterPlugin();
  console.log('unregisterPlugin success.');
} catch(err) {
  console.log('unregisterPlugin err:' + JSON.stringify(err));
}

auth10+

auth(domainAccountInfo: DomainAccountInfo, credential: Uint8Array, callback: IUserAuthCallback): void

Authenticates a domain account.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.ACCESS_USER_AUTH_INTERNAL

Parameters

NameTypeMandatoryDescription
domainAccountInfoDomainAccountInfoYesDomain account information.
credentialUint8ArrayYesCredentials of the domain account.
callbackIUserAuthCallbackYesCallback invoked to return the authentication result.

Error codes

IDError Message
12300001System service exception.
12300002Invalid domainAccountInfo or credential.
12300003Domain account does not exist.
12300013Network exception.
12300101Authentication failed.
12300109Authentication is canceled.
12300110Authentication is locked.
12300111Authentication timeout.
12300112Authentication service is busy.
12300113Authentication service does not exist.
12300114Authentication service exception.

Example

let domainAccountInfo: account_osAccount.DomainAccountInfo = {
  domain: 'CHINA',
  accountName: 'zhangsan'
}
let credential = new Uint8Array([0])
try {
  account_osAccount.DomainAccountManager.auth(domainAccountInfo, credential, {
    onResult: (resultCode: number, authResult: account_osAccount.AuthResult) => {
      console.log('auth resultCode = ' + resultCode);
      console.log('auth authResult = ' + JSON.stringify(authResult));
    }
  });
} catch (err) {
  console.log('auth exception = ' + JSON.stringify(err));
}

authWithPopup10+

authWithPopup(callback: IUserAuthCallback): void

Authenticates this domain account in a pop-up window.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.ACCESS_USER_AUTH_INTERNAL

Parameters

NameTypeMandatoryDescription
callbackIUserAuthCallbackYesCallback invoked to return the authentication result.

Error codes

IDError Message
12300001System service exception.
12300003No domain account is bound.
12300013Network exception.
12300101Authentication failed.
12300109Authentication is canceled.
12300110Authentication is locked.
12300111Authentication timeout.
12300112Authentication service is busy.
12300113Authentication service does not exist.
12300114Authentication service exception.

Example

try {
  account_osAccount.DomainAccountManager.authWithPopup({
    onResult: (resultCode: number, authResult: account_osAccount.AuthResult) => {
      console.log('auth resultCode = ' + resultCode);
      console.log('auth authResult = ' + JSON.stringify(authResult));
    }
  })
} catch (err) {
  console.log('auth exception = ' + JSON.stringify(err));
}

authWithPopup10+

authWithPopup(localId: number, callback: IUserAuthCallback): void

Authenticates a domain account in a pop-up window.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.ACCESS_USER_AUTH_INTERNAL

Parameters

NameTypeMandatoryDescription
localIdnumberYesLocal ID of the OS account bound to the domain account.
callbackIUserAuthCallbackYesCallback invoked to return the authentication result.

Error codes

IDError Message
12300001System service exception.
12300002Invalid localId.
12300003No domain account is bound.
12300013Network exception.
12300101Authentication failed.
12300109Authentication is canceled.
12300110Authentication is locked.
12300111Authentication timeout.
12300112Authentication service is busy.
12300113Authentication service does not exist.
12300114Authentication service exception.

Example

try {
  account_osAccount.DomainAccountManager.authWithPopup(100, {
    onResult: (resultCode: number, authResult: account_osAccount.AuthResult) => {
      console.log('authWithPopup resultCode = ' + resultCode);
      console.log('authWithPopup authResult = ' + JSON.stringify(authResult));
    }
  })
} catch (err) {
  console.log('authWithPopup exception = ' + JSON.stringify(err));
}

hasAccount10+

hasAccount(domainAccountInfo: DomainAccountInfo, callback: AsyncCallback<boolean>): void

Checks whether a domain account exists.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

Parameters

NameTypeMandatoryDescription
domainAccountInfoDomainAccountInfoYesDomain account information.
callbackAsyncCallback<boolean>YesCallback invoked to return the result.

Error codes

IDError Message
12300001System service exception.
12300002Invalid domainAccountInfo.
12300013Network exception.
12300111Operation timeout.

Example

import { BusinessError } from '@ohos.base';
let domainAccountInfo: account_osAccount.DomainAccountInfo = {
  domain: 'CHINA',
  accountName: 'zhangsan'
}
try {
  account_osAccount.DomainAccountManager.hasAccount(domainAccountInfo, (err: BusinessError, result: boolean) => {
    if (err) {
      console.log('call hasAccount failed, error: ' + JSON.stringify(err));
    } else {
      console.log('hasAccount result: ' + result);
    }
  });
} catch (err) {
  console.log('hasAccount exception = ' + JSON.stringify(err));
}

hasAccount10+

hasAccount(domainAccountInfo: DomainAccountInfo): Promise<boolean>

Checks whether a domain account exists.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

Parameters

NameTypeMandatoryDescription
domainAccountInfoDomainAccountInfoYesDomain account information.

Return value

TypeDescription
Promise<boolean>Promise used to return the result.

Error codes

IDError Message
12300001System service exception.
12300002Invalid domainAccountInfo.
12300013Network exception.
12300111Operation timeout.

Example

import { BusinessError } from '@ohos.base';
let domainAccountInfo: account_osAccount.DomainAccountInfo = {
  domain: 'CHINA',
  accountName: 'zhangsan'
}
try {
  account_osAccount.DomainAccountManager.hasAccount(domainAccountInfo).then((result: boolean) => {
    console.log('hasAccount result: ' + result);
  }).catch((err: BusinessError) => {
      console.log('call hasAccount failed, error: ' + JSON.stringify(err));
  });
} catch (err) {
  console.log('hasAccount exception = ' + JSON.stringify(err));
}

updateAccountToken10+

updateAccountToken(domainAccountInfo: DomainAccountInfo, token: Uint8Array, callback: AsyncCallback<void>): void;

Updates the token of a domain account. An empty token means an invalid token. This API uses an asynchronous callback to return the result.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

Parameters

NameTypeMandatoryDescription
domainAccountInfoDomainAccountInfoYesDomain account information.
tokenUint8ArrayYesNew token of the domain account.
callbackAsyncCallback<void>YesCallback invoked to return the result. If the token is successfully updated, err is null. Otherwise, err is an error object.

Error codes

IDError Message
12300001System service exception.
12300002Invalid token.
12300003Account not found.

Example

import { BusinessError } from '@ohos.base';
let domainAccountInfo: account_osAccount.DomainAccountInfo = {
  domain: 'CHINA',
  accountName: 'zhangsan',
  accountId: '123456'
}
let token = new Uint8Array([0])
try {
  account_osAccount.DomainAccountManager.updateAccountToken(domainAccountInfo, token, (err: BusinessError) => {
    if (err != null) {
      console.log('updateAccountToken failed, error: ' + JSON.stringify(err));
    } else {
      console.log('updateAccountToken successfully');
    }
  })
} catch (err) {
  console.log('updateAccountToken exception = ' + JSON.stringify(err));
}

updateAccountToken10+

updateAccountToken(domainAccountInfo: DomainAccountInfo, token: Uint8Array): Promise<void>

Updates the token of a domain account. An empty token means an invalid token. This API uses a promise to return the result.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.MANAGE_LOCAL_ACCOUNTS

Parameters

NameTypeMandatoryDescription
domainAccountInfoDomainAccountInfoYesDomain account information.
tokenUint8ArrayYesNew token of the domain account.

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

IDError Message
12300001System service exception.
12300002Invalid token.
12300003Account not found.

Example

import { BusinessError } from '@ohos.base';
let domainAccountInfo: account_osAccount.DomainAccountInfo = {
  domain: 'CHINA',
  accountName: 'zhangsan',
  accountId: '123456'
}
let token = new Uint8Array([0])
try {
  account_osAccount.DomainAccountManager.updateAccountToken(domainAccountInfo, token).then(() => {
    console.log('updateAccountToken successfully');
  }).catch((err: BusinessError) => {
      console.log('updateAccountToken failed, error: ' + JSON.stringify(err));
  });
} catch (err) {
  console.log('updateAccountToken exception = ' + JSON.stringify(err));
}

getAccountInfo10+

getAccountInfo(options: GetDomainAccountInfoOptions, callback: AsyncCallback<DomainAccountInfo>): void

Obtains information about the specified domain account. This API uses an asynchronous callback to return the result.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.GET_DOMAIN_ACCOUNTS

Parameters

NameTypeMandatoryDescription
optionsGetDomainAccountInfoOptionsYesOptions for obtaining the domain account information.
callbackAsyncCallback<DomainAccountInfo>YesCallback invoked to return the result.

Error codes

IDError Message
12300001System service exception.
12300003Account not found.
12300013Network exception.
12300111Operation timeout.

Example

import { BusinessError } from '@ohos.base';
let domainAccountInfo: account_osAccount.GetDomainAccountInfoOptions = {
  domain: 'CHINA',
  accountName: 'zhangsan'
}
try {
  account_osAccount.DomainAccountManager.getAccountInfo(domainAccountInfo,
    (err: BusinessError, result: account_osAccount.DomainAccountInfo) => {
    if (err) {
      console.log('call getAccountInfo failed, error: ' + JSON.stringify(err));
    } else {
      console.log('getAccountInfo result: ' + result);
    }
  });
} catch (err) {
  console.log('getAccountInfo exception = ' + JSON.stringify(err));
}

getAccountInfo10+

getAccountInfo(options: GetDomainAccountInfoOptions): Promise<DomainAccountInfo>

Obtains information about the specified domain account. This API uses a promise to return the result.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.GET_DOMAIN_ACCOUNTS

Parameters

NameTypeMandatoryDescription
optionsGetDomainAccountInfoOptionsYesOptions for obtaining the domain account information.

Return value

TypeDescription
Promise<DomainAccountInfo>Promise used to return the domain account information obtained.

Error codes

IDError Message
12300001System service exception.
12300003Account not found.
12300013Network exception.
12300111Operation timeout.

Example

import { BusinessError } from '@ohos.base';
let domainAccountInfo: account_osAccount.GetDomainAccountInfoOptions = {
  domain: 'CHINA',
  accountName: 'zhangsan'
}
try {
  account_osAccount.DomainAccountManager.getAccountInfo(domainAccountInfo)
    .then((result: account_osAccount.DomainAccountInfo) => {
    console.log('getAccountInfo result: ' + result);
  }).catch((err: BusinessError) => {
    console.log('call getAccountInfo failed, error: ' + JSON.stringify(err));
  });
} catch (err) {
  console.log('getAccountInfo exception = ' + JSON.stringify(err));
}

UserIdentityManager8+

Provides APIs for user identity management (IDM).

System API: This is a system API.

constructor8+

constructor()

A constructor used to create an instance for user IDM.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Example

let userIDM = new account_osAccount.UserIdentityManager();

openSession8+

openSession(callback: AsyncCallback<Uint8Array>): void;

Opens a session to obtain the challenge value. This API uses an asynchronous callback to return the result.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.MANAGE_USER_IDM

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<Uint8Array>YesCallback invoked to return the result. If the operation is successful, err is null and data is the challenge value obtained. Otherwise, err is an error object.

Error codes

IDError Message
12300001System service exception.

Example

import { BusinessError } from '@ohos.base';
let userIDM = new account_osAccount.UserIdentityManager();
try {
  userIDM.openSession((err: BusinessError, challenge: Uint8Array) => {
      console.log('openSession error = ' + JSON.stringify(err));
      console.log('openSession challenge = ' + JSON.stringify(challenge));
  });
} catch (e) {
  console.log('openSession exception = ' + JSON.stringify(e));
}

openSession8+

openSession(): Promise<Uint8Array>;

Opens a session to obtain the challenge value. This API uses a promise to return the result.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.MANAGE_USER_IDM

Return value

TypeDescription
Promise<Uint8Array>Promise used to return the challenge value obtained.

Error codes

IDError Message
12300001System service exception.

Example

import { BusinessError } from '@ohos.base';
let userIDM = new account_osAccount.UserIdentityManager();
try {
  userIDM.openSession().then((challenge: Uint8Array) => {
      console.info('openSession challenge = ' + JSON.stringify(challenge));
  }).catch((err: BusinessError) => {
      console.info('openSession error = ' + JSON.stringify(err));
  });
} catch (e) {
  console.log('openSession exception = ' + JSON.stringify(e));
}

addCredential8+

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

Adds credential information, including the credential type, subtype, and token (if a non-PIN credential is added).

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.MANAGE_USER_IDM

Parameters

NameTypeMandatoryDescription
credentialInfoCredentialInfoYesCredential information to add.
callbackIIdmCallbackYesCallback invoked to return the result.

Error codes

IDError Message
12300001System service exception.
12300002Invalid credentialInfo, i.e. authType or authSubType.
12300101Token is invalid.
12300106Unsupported authType.
12300109Operation is canceled.
12300111Operation timeout.
12300115The number of credentials reaches the upper limit.

Example

import { BusinessError } from '@ohos.base';
let password: Uint8Array = new Uint8Array([0, 0, 0, 0, 0, 0]);
let pinAuth: account_osAccount.PINAuth = new account_osAccount.PINAuth();
pinAuth.registerInputer({
  onGetData: (authSubType: account_osAccount.AuthSubType, callback: account_osAccount.IInputData) => {
    callback.onSetData(authSubType, password);
  }
});
let credentialInfo: account_osAccount.CredentialInfo = {
  credType: account_osAccount.AuthType.PIN,
  credSubType: account_osAccount.AuthSubType.PIN_SIX,
  token: new Uint8Array([]),
};
let userIDM = new account_osAccount.UserIdentityManager();
userIDM.openSession((err: BusinessError, challenge: Uint8Array) => {
  try {
  userIDM.addCredential(credentialInfo, {
    onResult: (result: number, extraInfo: account_osAccount.RequestResult) => {
      console.log('addCredential result = ' + result);
      console.log('addCredential extraInfo = ' + extraInfo);
    }
  });
  } catch (e) {
    console.log('addCredential exception = ' + JSON.stringify(e));
  }
});

updateCredential8+

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

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

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.MANAGE_USER_IDM

Parameters

NameTypeMandatoryDescription
credentialInfoCredentialInfoYesNew credential information.
callbackIIdmCallbackYesCallback invoked to return the new credential information.

Error codes

IDError Message
12300001System service exception.
12300002Invalid credentialInfo, i.e. authType or authSubType or token.
12300101Token is invalid.
12300102Credential not enrolled.
12300106Unsupported authType.
12300109Operation is canceled.
12300111Operation timeout.

Example

import { BusinessError } from '@ohos.base';
let userIDM = new account_osAccount.UserIdentityManager();
let userAuth: account_osAccount.UserAuth = new account_osAccount.UserAuth();
let pinAuth: account_osAccount.PINAuth = new account_osAccount.PINAuth();
let password: Uint8Array = new Uint8Array([0, 0, 0, 0, 0, 0]);
let credentialInfo: account_osAccount.CredentialInfo = {
  credType: account_osAccount.AuthType.PIN,
  credSubType: account_osAccount.AuthSubType.PIN_SIX,
  token: new Uint8Array([]),
};
pinAuth.registerInputer({
  onGetData: (authSubType: account_osAccount.AuthSubType, callback: account_osAccount.IInputData) => {
    callback.onSetData(authSubType, password);
  }
});
userIDM.openSession((err: BusinessError, challenge: Uint8Array) => {
  userAuth.auth(challenge, credentialInfo.credType, account_osAccount.AuthTrustLevel.ATL1, {
    onResult: (result: number, extraInfo: account_osAccount.AuthResult) => {
      if (result != account_osAccount.ResultCode.SUCCESS) {
        return;
      }
      if (extraInfo.token != null) {
        credentialInfo.token = extraInfo.token;
      }
      try {
        userIDM.updateCredential(credentialInfo, {
          onResult: (result: number, extraInfo: account_osAccount.RequestResult) => {
              console.log('updateCredential result = ' + result);
              console.log('updateCredential extraInfo = ' + extraInfo);
          }
        });
      } catch (e) {
        console.log('updateCredential exception = ' + JSON.stringify(e));
      }
    }
  });
});

closeSession8+

closeSession(): void;

Closes this session to terminate IDM.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.MANAGE_USER_IDM

Example

let userIDM = new account_osAccount.UserIdentityManager();
userIDM.closeSession();

cancel8+

cancel(challenge: Uint8Array): void;

Cancels an entry based on the challenge value.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.MANAGE_USER_IDM

Parameters

NameTypeMandatoryDescription
challengeUint8ArrayYesChallenge value.

Error codes

IDError Message
12300001System service exception.
12300002Invalid challenge.

Example

let userIDM = new account_osAccount.UserIdentityManager();
let challenge: Uint8Array = new Uint8Array([0]);
try {
  userIDM.cancel(challenge);
} catch(err) {
  console.log('cancel err:' + JSON.stringify(err));
}

delUser8+

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

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

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.MANAGE_USER_IDM

Parameters

NameTypeMandatoryDescription
tokenUint8ArrayYesAuthentication token.
callbackIIdmCallbackYesCallback invoked to return the result.

Error codes

IDError Message
12300001System service exception.
12300101Token is invalid.

Example

let userIDM = new account_osAccount.UserIdentityManager();
let token: Uint8Array = new Uint8Array([0]);
try {
  userIDM.delUser(token, {
    onResult: (result: number, extraInfo: account_osAccount.RequestResult) => {
      console.log('delUser result = ' + result);
      console.log('delUser extraInfo = ' + JSON.stringify(extraInfo));
    }
  });
} catch (e) {
  console.log('delUser exception = ' + JSON.stringify(e));
}

delCred8+

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

Deletes user credential information.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.MANAGE_USER_IDM

Parameters

NameTypeMandatoryDescription
credentialIdUint8ArrayYesCredential ID.
tokenUint8ArrayYesAuthentication token.
callbackIIdmCallbackYesCallback invoked to return the result.

Error codes

IDError Message
12300001System service exception.
12300002Invalid credentialId.
12300101Token is invalid.
12300102Credential not enrolled.

Example

let userIDM = new account_osAccount.UserIdentityManager();
let credentialId: Uint8Array = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0]);
let token: Uint8Array = new Uint8Array([0]);
try {
  userIDM.delCred(credentialId, token, {
    onResult: (result: number, extraInfo: account_osAccount.RequestResult) => {
        console.log('delCred result = ' + result);
        console.log('delCred extraInfo = ' + JSON.stringify(extraInfo));
    }
  });
} catch (e) {
  console.log('delCred exception = ' + JSON.stringify(e));
}

getAuthInfo8+

getAuthInfo(callback: AsyncCallback<Array<EnrolledCredInfo>>): void;

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

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.USE_USER_IDM

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<Array<EnrolledCredInfo>>YesCallback invoked to return the result. If the operation is successful, err is null and data is information about all registered credentials of the user. Otherwise, err is an error object.

Error codes

IDError Message
12300001System service exception.
12300102Credential not enrolled.

Example

import { BusinessError } from '@ohos.base';
let userIDM = new account_osAccount.UserIdentityManager();
try {
  userIDM.getAuthInfo((err: BusinessError, result: account_osAccount.EnrolledCredInfo[]) => {
    console.log('getAuthInfo err = ' + JSON.stringify(err));
    console.log('getAuthInfo result = ' + JSON.stringify(result));
  });
} catch (e) {
  console.log('getAuthInfo exception = ' + JSON.stringify(e));
}

getAuthInfo8+

getAuthInfo(authType: AuthType, callback: AsyncCallback<Array<EnrolledCredInfo>>): void;

Obtains authentication information of the specified type. This API uses an asynchronous callback to return the result.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.USE_USER_IDM

Parameters

NameTypeMandatoryDescription
authTypeAuthTypeYesAuthentication credential type.
callbackAsyncCallback<Array<EnrolledCredInfo>>YesCallback invoked to return the result. If the operation is successful, err is null and data is the information about all enrolled credentials of the specified type. Otherwise, err is an error object.

Error codes

IDError Message
12300001System service exception.
12300002Invalid authType.
12300102Credential not enrolled.

Example

import { BusinessError } from '@ohos.base';
let userIDM = new account_osAccount.UserIdentityManager();
try {
  userIDM.getAuthInfo(account_osAccount.AuthType.PIN,
    (err: BusinessError, result: account_osAccount.EnrolledCredInfo[]) => {
    console.log('getAuthInfo err = ' + JSON.stringify(err));
    console.log('getAuthInfo result = ' + JSON.stringify(result));
  });
} catch (e) {
  console.log('getAuthInfo exception = ' + JSON.stringify(e));
}

getAuthInfo8+

getAuthInfo(authType?: AuthType): Promise<Array<EnrolledCredInfo>>;

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

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Required permissions: ohos.permission.USE_USER_IDM

Parameters

NameTypeMandatoryDescription
authTypeAuthTypeNoAuthentication type. By default, this parameter is left blank, which means to obtain information about all authentication types.

Return value

TypeDescription
Promise<Array<EnrolledCredInfo>>Promise used to return the information about all the enrolled credentials of the specified type.

Error codes

IDError Message
12300001System service exception.
12300002Invalid authType.
12300102Credential not enrolled.

Example

import { BusinessError } from '@ohos.base';
let userIDM = new account_osAccount.UserIdentityManager();
try {
  userIDM.getAuthInfo(account_osAccount.AuthType.PIN).then((result: account_osAccount.EnrolledCredInfo[]) => {
    console.log('getAuthInfo result = ' + JSON.stringify(result))
  }).catch((err: BusinessError) => {
    console.log('getAuthInfo error = ' + JSON.stringify(err));
  });
} catch (e) {
  console.log('getAuthInfo exception = ' + JSON.stringify(e));
}

IInputData8+

Provides callbacks for PIN operations.

System API: This is a system API.

onSetData8+

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

System API: This is a system API.

Called to set data in a PIN operation.

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
authSubTypeAuthSubTypeYesCredential subtype.
dataUint8ArrayYesData (credential) to set. The data is used for authentication and operations for adding and modifying credentials.

Error codes

IDError Message
12300002Invalid pinSubType.

Example

let password: Uint8Array = new Uint8Array([0, 0, 0, 0, 0, 0]);
let passwordNumber: Uint8Array = new Uint8Array([1, 2, 3, 4]);
let inputer: account_osAccount.IInputer = {
  onGetData: (authSubType: account_osAccount.AuthSubType, callback: account_osAccount.IInputData) => {
      if (authSubType == account_osAccount.AuthSubType.PIN_NUMBER) {
        callback.onSetData(authSubType, passwordNumber);
      } else {
        callback.onSetData(authSubType, password);
      }
  }
};

IInputer8+

Provides callbacks for credential inputers.

System API: This is a system API.

onGetData8+

onGetData: (authSubType: AuthSubType, callback: IInputData) => void;

Called to obtain data.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
callbackIInputDataYesCalled to input the PIN.

Example

let password: Uint8Array = new Uint8Array([0, 0, 0, 0, 0, 0]);
let passwordNumber: Uint8Array = new Uint8Array([1, 2, 3, 4]);
let inputer: account_osAccount.IInputer = {
  onGetData: (authSubType: account_osAccount.AuthSubType, callback: account_osAccount.IInputData) => {
      if (authSubType == account_osAccount.AuthSubType.PIN_NUMBER) {
        callback.onSetData(authSubType, passwordNumber);
      } else {
        callback.onSetData(authSubType, password);
      }
  }
};
let pinAuth: account_osAccount.PINAuth = new account_osAccount.PINAuth();
let result = pinAuth.registerInputer(inputer);
console.log('registerInputer result: ' + result);

IUserAuthCallback8+

Provides callbacks for user authentication.

System API: This is a system API.

onResult8+

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

Called to return the result code and authentication result.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
resultnumberYesAuthentication result code.
extraInfoAuthResultYesSpecific authentication result information. If the authentication is successful, the authentication token is returned in extrainfo. If the authentication fails, the remaining authentication time is returned. If the authentication executor is locked, the freezing time is returned.

Example

let authCallback: account_osAccount.IUserAuthCallback = {
  onResult: (result: number, extraInfo: account_osAccount.AuthResult) => {
    console.log('auth result = ' + result);
    console.log('auth extraInfo = ' + JSON.stringify(extraInfo));
  }
};

onAcquireInfo?8+

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

Called to acquire identity authentication information.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
modulenumberYesType of authentication executor.
acquirenumberYesTip code of the authentication executor.
extraInfoanyYesReserved.

Example

let authCallback: account_osAccount.IUserAuthCallback = {
  onResult: (result: number, extraInfo: account_osAccount.AuthResult) => {
    console.log('auth result = ' + result)
    console.log('auth extraInfo = ' + JSON.stringify(extraInfo));
  },
  onAcquireInfo: (module: number, acquire: number, extraInfo: account_osAccount.RequestResult) => {
    console.log('auth module = ' + module);
    console.log('auth acquire = ' + acquire);
    console.info('auth extraInfo = ' + JSON.stringify(extraInfo));
  }
};

IIdmCallback8+

Provides callbacks for IDM.

System API: This is a system API.

onResult8+

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

Called to return the result code and request result information.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
resultnumberYesAuthentication result code.
extraInfoRequestResultYesSpecific information to be transferred.

Example

let idmCallback: account_osAccount.IIdmCallback = {
  onResult: (result: number, extraInfo: account_osAccount.RequestResult) => {
    console.log('callback result = ' + result)
    console.info('callback extraInfo = ' + JSON.stringify(extraInfo));
  }
};

onAcquireInfo?8+

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

Called to acquire IDM information.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

Parameters

NameTypeMandatoryDescription
modulenumberYesType of authentication executor.
acquirenumberYesTip code of the authentication executor.
extraInfoanyYesReserved.

Example

let idmCallback: account_osAccount.IIdmCallback = {
  onResult: (result: number, extraInfo: Object) => {
    console.log('callback result = ' + result)
    console.log('callback onResult = ' + JSON.stringify(extraInfo));
  },
  onAcquireInfo: (module: number, acquire: number, extraInfo: Object) => {
    console.log('callback module = ' + module);
    console.log('callback acquire = ' + acquire);
    console.log('callback onacquireinfo = ' + JSON.stringify(extraInfo));
  }
};

GetPropertyRequest8+

Defines the request for obtaining property information.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

NameTypeMandatoryDescription
authTypeAuthTypeYesAuthentication credential type.
keysArray<GetPropertyType>YesAn array of the types of the properties to obtain.

SetPropertyRequest8+

Defines the request for setting property information.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

NameTypeMandatoryDescription
authTypeAuthTypeYesAuthentication credential type.
keySetPropertyTypeYesType of the property to set.
setInfoUint8ArrayYesInformation to set.

ExecutorProperty8+

Defines the executor property.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

NameTypeReadableWritableDescription
resultnumberYesYesResult.
authSubTypeAuthSubTypeYesYesAuthentication credential subtype.
remainTimesnumberYesYesNumber of remaining authentication times.
freezingTimenumberYesYesFreezing time.
enrollmentProgress10+stringYesYesEnrollment progress. By default, no value is passed.
sensorInfo10+stringYesYesSensor information. By default, no value is passed.

AuthResult8+

Defines the authentication result information.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

NameTypeMandatoryDescription
tokenUint8ArrayNoAuthentication token. By default, no value is passed.
remainTimesnumberNoNumber of remaining authentication times. By default, no value is passed.
freezingTimenumberNoFreezing time. By default, no value is passed.

CredentialInfo8+

Defines the credential information.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

NameTypeMandatoryDescription
credTypeAuthTypeYesAuthentication credential type.
credSubTypeAuthSubTypeYesAuthentication credential subtype.
tokenUint8ArrayYesAuthentication token.

RequestResult8+

Defines the request result information.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

NameTypeMandatoryDescription
credentialIdUint8ArrayNoCredential ID. By default, no value is passed.

EnrolledCredInfo8+

Defines enrolled credential information.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

NameTypeMandatoryDescription
credentialIdUint8ArrayYesCredential ID.
authTypeAuthTypeYesAuthentication credential type.
authSubTypeAuthSubTypeYesCredential subtype.
templateIdUint8ArrayYesAuthentication credential template ID.

GetPropertyType8+

Enumerates the types of properties to obtain.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

NameValueDescription
AUTH_SUB_TYPE1Authentication credential subtype.
REMAIN_TIMES2Remaining time.
FREEZING_TIME3Freezing time.
ENROLLMENT_PROGRESS10+4Enrollment progress.
SENSOR_INFO10+5Sensor information.

SetPropertyType8+

Enumerates the types of properties to set.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

NameValueDescription
INIT_ALGORITHM1Initialization algorithm.

AuthType8+

Enumerates the authentication credential types.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

NameValueDescription
PIN1PIN authentication.
FACE2Facial authentication.
FINGERPRINT10+4Fingerprint authentication.
DOMAIN9+1024Domain authentication.

AuthSubType8+

Enumerates the authentication credential subtypes.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

NameValueDescription
PIN_SIX10000Six-digit PIN.
PIN_NUMBER10001Custom PIN.
PIN_MIXED10002Custom mixed credentials.
FACE_2D200002D face credential.
FACE_3D200013D face credential.
FINGERPRINT_CAPACITIVE10+30000Capacitive fingerprint.
FINGERPRINT_OPTICAL10+30001Optical fingerprint.
FINGERPRINT_ULTRASONIC10+30002Ultrasonic fingerprint.
DOMAIN_MIXED9+10240001Mixed domain authentication credentials.

AuthTrustLevel8+

Enumerates the trust levels of the authentication result.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

NameValueDescription
ATL110000Trust level 1.
ATL220000Trust level 2.
ATL330000Trust level 3.
ATL440000Trust level 4.

Module8+

Enumerates the modules from which information is obtained.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

NameValueDescription
FACE_AUTH1Facial authentication module.

ResultCode8+

Enumerates the authentication result codes.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

NameValueDescription
SUCCESS0The authentication is successful or the authentication feature is supported.
FAIL1The authentication executor failed to identify the user.
GENERAL_ERROR2Other errors.
CANCELED3The authentication is canceled.
TIMEOUT4The authentication timed out.
TYPE_NOT_SUPPORT5The authentication credential type is not supported.
TRUST_LEVEL_NOT_SUPPORT6The authentication trust level is not supported.
BUSY7The authentication executor is busy. Try again after a few seconds.
INVALID_PARAMETERS8Incorrect parameters are detected.
LOCKED9The authentication executor is locked.
NOT_ENROLLED10The authentication executor is not enrolled.

FaceTipsCode8+

Enumerates the tip codes for facial authentication.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

NameValueDescription
FACE_AUTH_TIP_TOO_BRIGHT1The obtained face image is too bright.
FACE_AUTH_TIP_TOO_DARK2The obtained face image is too dark.
FACE_AUTH_TIP_TOO_CLOSE3The face is too close to the device.
FACE_AUTH_TIP_TOO_FAR4The face is too far away from the device.
FACE_AUTH_TIP_TOO_HIGH5Only the upper part of the face is captured because the device is angled too high.
FACE_AUTH_TIP_TOO_LOW6Only the lower part of the face is captured because the device is angled too low.
FACE_AUTH_TIP_TOO_RIGHT7Only the right part of the face is captured because the device is angled too much to the right.
FACE_AUTH_TIP_TOO_LEFT8Only the left part of the face is captured because the device is angled too much to the left.
FACE_AUTH_TIP_TOO_MUCH_MOTION9The face moves too fast during facial information collection.
FACE_AUTH_TIP_POOR_GAZE10The face is not facing the device.
FACE_AUTH_TIP_NOT_DETECTED11No face is detected.

FingerprintTips8+

Enumerates the tip codes for fingerprint authentication.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

NameValueDescription
FINGERPRINT_TIP_GOOD0The captured image is clear.
FINGERPRINT_TIP_IMAGER_DIRTY1The fingerprint image has big noise due to dirt on the sensor.
FINGERPRINT_TIP_INSUFFICIENT2Failed to process the fingerprint image due to big noise.
FINGERPRINT_TIP_PARTIAL3Only part of the fingerprint image is detected.
FINGERPRINT_TIP_TOO_FAST4The fingerprint image is incomplete due to quick motion.
FINGERPRINT_TIP_TOO_SLOW5Failed to read the fingerprint image due to lack of motion.
FINGERPRINT_TIP_FINGER_DOWN10+6Press your finger.
FINGERPRINT_TIP_FINGER_UP10+7Lift your finger.

OsAccountInfo

Defines the OS account information.

System capability: SystemCapability.Account.OsAccount

NameTypeMandatoryDescription
localIdnumberYesID of the target OS account.
localNamestringYesOS account name.
typeOsAccountTypeYesOS account type.
constraintsArray<string>NoOS account Constraints. By default, no value is passed.
isVerified8+booleanYesWhether to verify the OS account.
photo8+stringNoOS account avatar. By default, no value is passed.
createTime8+numberYesTime when the OS account was created.
lastLoginTime8+numberNoLast login time of the OS account. By default, no value is passed.
serialNumber8+numberYesSN of the OS account.
isActived8+booleanYesWhether the OS account is activated.
isCreateCompleted8+booleanYesWhether the OS account information is complete.
distributedInfodistributedAccount.DistributedInfoNoDistributed account information. By default, no value is passed.
domainInfo8+DomainAccountInfoNoDomain account information. By default, no value is passed.

DomainAccountInfo8+

Defines the domain account information.

System capability: SystemCapability.Account.OsAccount

NameTypeMandatoryDescription
domainstringYesDomain name.
accountNamestringYesDomain account name.
accountId10+stringNoDomain account ID.
System API: It is a system API and is left blank by default.

Constraints

ConstraintDescription
constraint.wifiA user is not allowed to use Wi-Fi.
constraint.wifi.setA user is not allowed to set Wi-Fi.
constraint.locale.setA user is not allowed to change the device language.
constraint.app.accountsA user is not allowed to add or delete app accounts.
constraint.apps.installA user is not allowed to install apps.
constraint.apps.uninstallA user is not allowed to uninstall apps.
constraint.location.sharedA user is not allowed to enable location sharing.
constraint.unknown.sources.installA user is not allowed to install apps from unknown sources.
constraint.global.unknown.app.installAll users are not allowed to install apps from unknown sources.
constraint.bluetooth.setA user is not allowed to configure Bluetooth.
constraint.bluetoothThe use of Bluetooth is prohibited on the device.
constraint.bluetooth.shareBluetooth sharing is prohibited.
constraint.usb.file.transferA user is not allowed to transfer files over USB.
constraint.credentials.setA user is not allowed to configure user credentials.
constraint.os.account.removeAn admin user is not allowed to remove users or a non-admin user is not allowed to remove itself.
constraint.managed.profile.removeThe managed profiles of this user cannot be removed.
constraint.debug.features.useA user is not allowed to enable or access debugging features.
constraint.vpn.setA user is not allowed to configure a VPN.
constraint.date.time.setA user is not allowed to set date, time, or time zone.
constraint.tethering.configA user is not allowed to configure Tethering.
constraint.network.resetA user is not allowed to reset network settings.
constraint.factory.resetA user is not allowed to reset factory settings.
constraint.os.account.createA user is not allowed to create users.
constraint.add.managed.profileA user is not allowed to add managed profiles.
constraint.apps.verify.disableA user is not allowed to disable app verification.
constraint.cell.broadcasts.setA user is not allowed to configure cell broadcasts.
constraint.mobile.networks.setA user is not allowed to configure radio networks.
constraint.control.appsA user is not allowed to modify apps in Settings or the boot module.
constraint.physical.mediaA user is not allowed to mount external physical media.
constraint.microphoneA user is not allowed to use microphones.
constraint.microphone.unmuteA user is not allowed to unmute the microphone.
constraint.volume.adjustA user is not allowed to adjust the volume.
constraint.calls.outgoingA user is not allowed to make outgoing calls.
constraint.sms.useA user is not allowed to send or receive SMS messages.
constraint.funA user is not allowed to have entertainment.
constraint.windows.createWindows other than app windows cannot be created.
constraint.system.error.dialogsError dialogs for crashed or unresponsive apps are prohibited.
constraint.cross.profile.copy.pastePasting clipboard content to other users or profiles is prohibited.
constraint.beam.outgoingA user is not allowed to use Near Field Communications (NFC) to transfer data from apps.
constraint.wallpaperA user is not allowed to manage wallpapers.
constraint.safe.bootA user is not allowed to reboot the device in safe boot mode.
constraint.parent.profile.app.linkingThe apps in the parent profile are allowed to handle web links from the managed profile.
constraint.audio.recordAudio recording is prohibited.
constraint.camera.useThe use of cameras is prohibited.
constraint.os.account.background.runRunning in the background is prohibited.
constraint.data.roamA user is not allowed to use cellular data when roaming.
constraint.os.account.set.iconA user is not allowed to change their icon.
constraint.wallpaper.setA user is not allowed to set a wallpaper.
constraint.oem.unlockA user is not allowed to enable OEM unlock.
constraint.device.unmuteA user is not allowed to unmute the device.
constraint.password.unifiedThe managed profile is not allowed to have unified lock screen challenge with the primary user.
constraint.autofillA user is not allowed to use the autofill service.
constraint.content.captureCapturing the content of a user's screen is prohibited.
constraint.content.suggestionsA user is not allowed to receive content suggestions.
constraint.os.account.startUser switching is blocked.
constraint.location.setA user is not allowed to configure the location service.
constraint.airplane.mode.setThe airplane mode is prohibited on the device.
constraint.brightness.setA user is not allowed to configure brightness.
constraint.share.into.profileA user is not allowed to share files, images, or data from the primary user to the managed profile.
constraint.ambient.displayAmbient display is prohibited for the user.
constraint.screen.timeout.setA user is not allowed to configure the screen off timeout.
constraint.printA user is not allowed to print.
constraint.private.dns.setA user is not allowed to configure a private domain name server (DNS).

ConstraintSourceTypeInfo9+

Defines the constraint source type.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

NameTypeMandatoryDescription
localIdnumberYesID of the OS account.
typeConstraintSourceTypeYesType of the constrain source.

ConstraintSourceType9+

Enumerates the constraint sources.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

NameValueDescription
CONSTRAINT_NOT_EXIST0The constraint does not exist.
CONSTRAINT_TYPE_BASE1Constraint from system settings.
CONSTRAINT_TYPE_DEVICE_OWNER2Constraint from the device owners' settings.
CONSTRAINT_TYPE_PROFILE_OWNER3Constraint from the profile owners' settings.

AuthStatusInfo10+

Presents the authentication status information.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

NameTypeMandatoryDescription
remainTimesnumberYesNumber of remaining authentication times.
freezingTimenumberYesFreezing time.

GetDomainAccessTokenOptions10+

Defines the options for obtaining a domain access token.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

NameTypeMandatoryDescription
domainAccountInfoDomainAccountInfoYesDomain account information.
domainAccountTokenUint8ArrayYesToken of the domain account.
businessParams{ [key: string]: object }YesService parameters customized by the service party based on the request protocol.
callerUidnumberYesUnique identifier of the caller.

GetDomainAccountInfoOptions10+

Defines the options for obtaining domain account information.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

NameTypeMandatoryDescription
accountNamestringYesDomain account name.
domainstringNoDomain name.

GetDomainAccountInfoPluginOptions10+

Defines the options for the domain plug-in to obtain the domain account information. The GetDomainAccountInfoPluginOptions class inherits from GetDomainAccountInfoOptions.

System API: This is a system API.

System capability: SystemCapability.Account.OsAccount

NameTypeMandatoryDescription
callerUidnumberYesUnique identifier of the caller.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙APIs

harmony 鸿蒙System Common Events (To Be Deprecated Soon)

harmony 鸿蒙System Common Events

harmony 鸿蒙API Reference Document Description

harmony 鸿蒙Enterprise Device Management Overview (for System Applications Only)

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager)

harmony 鸿蒙@ohos.distributedBundle (Distributed Bundle Management)

harmony 鸿蒙@ohos.bundle (Bundle)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/6e0e067c37ed4c1890fcb20c462af784