harmony 鸿蒙帐号子系统changeLog

  • 2022-12-22
  • 浏览 (715)

帐号子系统changeLog

cl.account_os_account.1 变更错误码定义及其返回方式

针对帐号子系统API存在错误码定义不统一和抛出方式不符合OpenHarmony错误码规范的问题,从API9开始作以下变更:

  • 新增统一的错误码定义:

  • 按以下方式返回错误码:

    • 异步接口:错误信息通过AsyncCallback或Promise的error对象返回。其中,参数类型和数量错误信息,通过抛出异常的方式返回。
    • 同步接口:错误信息通过抛出异常的方式返回。

变更影响

基于此前版本开发的应用,需适配变更后的新错误码和错误信息返回方式,否则会影响原有业务逻辑。

关键接口/组件变更

以下接口涉及新错误码和错误信息返回方式变更: - 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;

适配指导

异步接口的错误信息处理逻辑以activateOsAccount为例,示例代码如下:

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

同步接口的错误信息处理以registerInputer为例,示例代码如下:

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

你可能感兴趣的鸿蒙文章

harmony 鸿蒙媒体子系统JS API变更Changelog

harmony 鸿蒙设备管理changeLog

harmony 鸿蒙USB管理 changeLog

harmony 鸿蒙软总线子系统Changelog

harmony 鸿蒙文件管理子系统ChangeLog

harmony 鸿蒙全球化子系统ChangeLog

harmony 鸿蒙输入法框架changeLog

harmony 鸿蒙多模输入changeLog

harmony 鸿蒙电源子系统ChangeLog

harmony 鸿蒙上传下载子系统ChangeLog

0  赞