harmony 鸿蒙Account Subsystem ChangeLog

  • 2023-02-03
  • 浏览 (719)

Account Subsystem ChangeLog

cl.account_os_account.1 Change of Definition and Return Mode of Error Codes

To solve the issues that error code definitions of the account subsystem APIs were inconsistent and that the return mode of the error codes did not comply with relevant specifications of OpenHarmony, the following changes are made and take effect in API version 9 and later:

  • Added the following unified error code definitions:

  • Returned an error code in either of the following ways, according to the API type:

    • Asynchronous API: An error message is returned via AsyncCallback or the error object of Promise. An error message related to the parameter type or quantity is returned via an exception.
    • Synchronous API: An error message is returned via an exception.

Change Impacts

The application developed based on earlier versions needs to adapt the method for returning API error information. Otherwise, the original service logic will be affected.

Key API/Component Changes

The mentioned changes involve the following APIs: - class AccountManager - activateOsAccount(localId: number, callback: AsyncCallback<void>): void; - removeOsAccount(localId: number, callback: AsyncCallback<void>): void; - setOsAccountConstraints(localId: number, constraints: Array<string>, enable: boolean, callback: AsyncCallback<void>): void; - setOsAccountName(localId: number, localName: string, callback: AsyncCallback<void>): void; - queryMaxOsAccountNumber(callback: AsyncCallback<number>): void; - queryAllCreatedOsAccounts(callback: AsyncCallback<Array<OsAccountInfo>>): void; - createOsAccount(localName: string, type: OsAccountType, callback: AsyncCallback<OsAccountInfo>): void; - createOsAccountForDomain(type: OsAccountType, domainInfo: DomainAccountInfo, callback: AsyncCallback<OsAccountInfo>): void; - queryOsAccountById(localId: number, callback: AsyncCallback<OsAccountInfo>): void; - getOsAccountProfilePhoto(localId: number, callback: AsyncCallback<string>): void; - setOsAccountProfilePhoto(localId: number, photo: string, callback: AsyncCallback<void>): void; - on(type: ‘activate’|‘activating’, name: string, callback: Callback<number>): void; - off(type: ‘activate’|‘activating’, name: string, callback?: Callback<number>): void; - isMainOsAccount(callback: AsyncCallback<boolean>): void; - queryOsAccountConstraintSourceTypes(localId: number, constraint: string, callback: AsyncCallback<Array<ConstraintSourceTypeInfo>>): void; - class UserAuth - constructor(); - getVersion(): number; - getAvailableStatus(authType: AuthType, authTrustLevel: AuthTrustLevel): number; - getProperty(request: GetPropertyRequest, callback: AsyncCallback<ExecutorProperty>): void; - setProperty(request: SetPropertyRequest, callback: AsyncCallback<number>): void; - auth(challenge: Uint8Array, authType: AuthType, authTrustLevel: AuthTrustLevel, callback: IUserAuthCallback): Uint8Array; - authUser(userId: number, challenge: Uint8Array, authType: AuthType, authTrustLevel: AuthTrustLevel, callback: IUserAuthCallback): Uint8Array; - cancelAuth(contextID: Uint8Array): number; - class PINAuth - constructor(); - registerInputer(inputer: IInputer): boolean; - unregisterInputer(authType: AuthType): void; - class UserIdentityManager - constructor(); - openSession(callback: AsyncCallback<Uint8Array>): void; - addCredential(credentialInfo: CredentialInfo, callback: IIdmCallback): void; - updateCredential(credentialInfo: CredentialInfo, callback: IIdmCallback): void; - closeSession(): void; - cancel(challenge: Uint8Array): number; - delUser(token: Uint8Array, callback: IIdmCallback): void; - delCred(credentialId: Uint8Array, token: Uint8Array, callback: IIdmCallback): void; - getAuthInfo(callback: AsyncCallback<Array<EnrolledCredInfo>>): void; - interface IInputData - onSetData: (authSubType: AuthSubType, data: Uint8Array) => void;

Adaptation Guide

The following uses activateOsAccount as an example to illustrate the error information processing logic of an asynchronous API:

import account_osAccount from "@ohos.account.osAccount"
let accountMgr = account_osAccount.getAccountManager()
let callbackFunc = (err) => {
  if (err != null) {  // Handle the business error.
    console.log("account_osAccount failed, error: " + JSON.stringify(err));
  } else {
    console.log("account_osAccount successfully");
  }
}
try {
  accountMgr.activateOsAccount("100", callbackFunc);
} catch (err) {  // Process the error that is related to the parameter type.
  console.log("account_osAccount failed for incorrect parameter type, error: " + JSON.stringify(err));
}
try {
  accountMgr.activateOsAccount();
} catch (err) {  // Process the error that is related to the parameter quantity.
  console.log("account_osAccount failed for incorrect parameter number, error: " + JSON.stringify(err));
}

The following uses registerInputer as an example to illustrate the error information processing logic of a synchronous API:

import account_osAccount from "@ohos.account.osAccount"
let pinAuth = new account_osAccount.PINAuth()
try {
    pinAuth.registerInputer({})
} catch (err) {  // Process the error that is related to the parameter type.
  console.log("account_osAccount failed for incorrect parameter type, error: " + JSON.stringify(err));
}
try {
    pinAuth.registerInputer()
} catch (err) {  // Process the error that is related to the parameter quantity.
  console.log("account_osAccount failed for incorrect parameter number, error: " + JSON.stringify(err));
}

你可能感兴趣的鸿蒙文章

harmony 鸿蒙ChangeLog of JS API Changes in the Multimedia Subsystem

harmony 鸿蒙Device Manager ChangeLog

harmony 鸿蒙USB Manager ChangeLog

harmony 鸿蒙DSoftBus Subsystem ChangeLog

harmony 鸿蒙File Management Subsystem ChangeLog

harmony 鸿蒙Globalization Subsystem ChangeLog

harmony 鸿蒙Input Method Framework ChangeLog

harmony 鸿蒙Multimodal Input ChangeLog

harmony 鸿蒙Power Subsystem ChangeLog

harmony 鸿蒙Upload and Download Subsystem ChangeLog

0  赞