DeviceUtil.ets
2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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.displayVersion;
}
/**
* 返回设备sdk版本
* 12
* @returns
*/
static getOsVersion(): string {
return deviceInfo.sdkApiVersion + '';
}
/**
* 获取平台标识,暂手机,后续适配tv、笔记本、pad,再扩展
*/
static getPlat() {
return 'Phone';
}
/**
* 获取设备型号: HUAWEI Mate 60 Pro
*/
static getMarketName() {
return deviceInfo.marketName
}
/**
* 客户端日志链路追踪traceid生成:在每个请求头加上参数Key:EagleEye-TraceID ,value为32位生成随机值
*/
static getRandomUUIDForTraceID(): string {
return util.generateRandomUUID().toUpperCase().replace(/-/g, '')
}
/**
* 是否为phone设备(可折叠手机即便完全展开状态也返回true)
* @returns
*/
static isPhone(): boolean {
return deviceInfo.deviceType == 'phone' || deviceInfo.deviceType == 'default';
}
static isNotPhone(): boolean {
return !DeviceUtil.isPhone();
}
static isTablet(): boolean {
return deviceInfo.deviceType == 'tablet';
}
static is2in1(): boolean {
return deviceInfo.deviceType == '2in1';
}
}