DeviceUtil.ets 1.04 KB
import util from '@ohos.util';
import deviceInfo from '@ohos.deviceInfo';
import { SPHelper } from './SPHelper';

const TAG = 'DeviceUtil';

/**
 * 与(硬件)设备相关(不可改变或不可升级)属性或操作
 */
export class DeviceUtil {
  static clientId() {
    let uuid = SPHelper.default.getSync("clientId", '');
    if (uuid == '') {
      uuid = util.generateRandomUUID();
      SPHelper.default.saveSync("clientId", uuid);
    }
    return uuid.toString();
  }

  /**
   * 返回设备厂家名称
   * HUAWEI
   * @returns
   */
  static getManufacture(): string {
    return deviceInfo.manufacture;
  }

  /**
   * 返回设备品牌名称
   * HUAWEI MATE 40 PRO
   * @returns
   */
  static getBrand(): string {
    return deviceInfo.brand;
  }

  /**
   * 返回认证型号
   * LIO-AL00
   * @returns
   */
  static getProductModel(): string {
    return deviceInfo.productModel;
  }

  /**
   * 返回产品版本
   * OpenHarmony-3.2.6.5(Beta2)
   * @returns
   */
  static getDisplayVersion(): string {
    return deviceInfo.productModel;
  }
}