harmony 鸿蒙Account Subsystem Changelog

  • 2023-02-17
  • 浏览 (589)

Account Subsystem Changelog

cl.account_os_account.1 OsAccountInfo.type Value Type Change

Changed the value type of OsAccountInfo.type from object to OsAccountType enum.

Change Impact

The mode for reading the OsAccountInfo.type value needs to be changed for the application developed based on earlier versions. Otherwise, the original service logic will be affected.

Key API/Component Changes

The following APIs are involved: - AccountManager - queryAllCreatedOsAccounts(callback: AsyncCallback<Array<OsAccountInfo>>): void; - queryAllCreatedOsAccounts(): Promise<Array<OsAccountInfo>>; - createOsAccount(localName: string, type: OsAccountType, callback: AsyncCallback<OsAccountInfo>): void; - createOsAccount(localName: string, type: OsAccountType): Promise<OsAccountInfo>; - createOsAccountForDomain(type: OsAccountType, domainInfo: DomainAccountInfo, callback: AsyncCallback<OsAccountInfo>): void; - createOsAccountForDomain(type: OsAccountType, domainInfo: DomainAccountInfo): Promise<OsAccountInfo>; - queryCurrentOsAccount(callback: AsyncCallback<OsAccountInfo>): void; - queryCurrentOsAccount(): Promise<OsAccountInfo>; - getCurrentOsAccount(callback: AsyncCallback<OsAccountInfo>): void; - getCurrentOsAccount(): Promise<OsAccountInfo>; - queryOsAccountById(localId: number, callback: AsyncCallback<OsAccountInfo>): void; - queryOsAccountById(localId: number): Promise<OsAccountInfo>;

  • getOsAccountTypeFromProcess(callback: AsyncCallback<OsAccountType>): void;
  • getOsAccountTypeFromProcess(): Promise<OsAccountType>;
  • getOsAccountType(callback: AsyncCallback<OsAccountType>): void;
  • getOsAccountType(): Promise<OsAccountType>;

Adaptation Guide

import account_osAccount from "@ohos.account.osAccount"

let accountMgr = account_osAccount.getAccountManager();
accountMgr.createOsAccount("account_test", account_osAccount.OsAccountType.GUEST).then((accountInfo) => {
  if (accountInfo.type == account_osAccount.OsAccountType.GUEST) {
    console.log("createOsAccount successfully");
  }
  accountMgr.activateOsAccount(accountInfo.localId).then(() => {
    console.log("activateOsAccount successfully");
    accountMgr.getOsAccountTypeFromProcess().then((accountType) => {
      if (accountType == account_osAccount.OsAccountType.GUEST) {
        console.log("getOsAccountTypeFromProcess successfully");
      }
    }).catch((err) => {
      console.log("activateOsAccount err: " + JSON.stringify(err));
    });
  }).catch((err) => {
    console.log("activateOsAccount err: " + JSON.stringify(err));
  });
}).catch((err) => {
  console.log("createOsAccount err: " + JSON.stringify(err));
});

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Updates (OpenHarmony 3.1 Beta -> OpenHarmony 3.1 Release)

0  赞