• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.deviceInfo (设备信息)
2
3本模块提供终端设备信息查询,开发者不可配置。
4
5> **说明:**
6>
7> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8> 部分参数返回值为default的,会在正式发布的版本中配置。
9> 本模块接口返回设备常量信息,建议应用只调用一次,不需要频繁调用。
10
11## 导入模块
12
13```ts
14import { deviceInfo } from '@kit.BasicServicesKit';
15```
16
17## 常量
18> **说明:**
19> 未特殊说明的字段,数据长度最大值为96字节。
20
21**系统能力**:SystemCapability.Startup.SystemInfo22
23**权限**:以下各项所需要的权限有所不同,详见下表。
24
25| 名称 | 类型 | 只读 | 说明 |
26| -------- | -------- | -------- | -------- |
27| deviceType | string | 是 | 设备类型。详细请参考[deviceTypes标签](../../quick-start/module-configuration-file.md#devicetypes标签)。<br/>**原子化服务API**:从API version 11开始,该接口支持在原子化服务中使用。<br/>示例:<!--RP1-->wearable<!--RP1End-->|
28| manufacture | string | 是 | 设备厂家名称。<br/>示例:HUAWEI |
29| brand | string | 是 | 设备品牌名称。<br/>**原子化服务API**:从API version 11开始,该接口支持在原子化服务中使用。<br/>示例:HUAWEI |
30| marketName | string | 是 | 外部产品系列。<br/>示例:<!--RP2-->Mate XX<!--RP2End--> |
31| productSeries | string | 是 | 产品系列。<br/>示例:<!--RP3-->TAS<!--RP3End--> |
32| productModel | string | 是 | 认证型号。<br/>**原子化服务API**:从API version 11开始,该接口支持在原子化服务中使用。<br/>示例:<!--RP4-->TAS-AL00<!--RP4End--> |
33| productModelAlias<sup>14+</sup> | string | 是 | 认证型号别名。<br/>**原子化服务API**:从API version 14开始,该接口支持在原子化服务中使用。<br/>示例:TAS-AL00 |
34| softwareModel | string | 是 | 内部软件子型号。<br/>示例:<!--RP5-->TAS-AL00<!--RP5End--> |
35| hardwareModel | string | 是 | 硬件版本号。<br/>示例:<!--RP6-->TASA00CVN1<!--RP6End--> |
36| hardwareProfile<sup>(deprecated) </sup> | string | 是 | 硬件Profile。<br/>**说明**:<br/>从API version 6 开始支持,从API version 9 开始废弃。<br/>示例:default |
37| serial | string | 是 | 设备序列号SN(Serial Number)。<br/>**说明**:可作为设备唯一识别码。<br/>**需要权限**:ohos.permission.sec.ACCESS_UDID(该权限只允许系统应用及企业定制应用申请) <br/>示例:序列号随设备差异 |
38| bootloaderVersion | string | 是 | Bootloader版本号。<br/>示例:bootloader |
39| abiList | string | 是 | 应用二进制接口(Abi)。<br/>示例:arm64-v8a |
40| securityPatchTag | string | 是 | 安全补丁级别。<br/>示例:<!--RP7-->2021/01/01<!--RP7End--> |
41| displayVersion | string | 是 | 产品版本。<br/>示例:<!--RP8-->XXX X.X.X.X<!--RP8End--> |
42| incrementalVersion | string | 是 | 差异版本号。<br/>示例:default |
43| osReleaseType | string | 是 | 系统的发布类型,取值为:<br/>-&nbsp;Canary:面向特定开发者发布的早期预览版本,不承诺API稳定性。<br/>-&nbsp;Beta:面向开发者公开发布的Beta版本,不承诺API稳定性。<br/>-&nbsp;Release:面向开发者公开发布的正式版本,承诺API稳定性。<br/>示例:<!--RP9-->Canary/Beta/Release<!--RP9End--> |
44| osFullName | string | 是 | 系统版本,版本格式OpenHarmony-x.x.x.x,x为数值。<br/>**原子化服务API**:从API version 11开始,该接口支持在原子化服务中使用。<br/>示例:<!--RP10-->Openharmony-5.0.0.1<!--RP10End--> |
45| majorVersion | number | 是 | Major版本号,随主版本更新增加,值为osFullName中的第一位数值,建议直接使用deviceInfo.majorVersion获取,可提升效率,不建议开发者解析osFullName获取。<br/>示例:5 |
46| seniorVersion | number | 是 | Senior版本号,随局部架构、重大特性增加,值为osFullName中的第二位数值,建议直接使用deviceInfo.seniorVersion获取,可提升效率,不建议开发者自主解析osFullName获取。<br/>示例:0 |
47| featureVersion | number | 是 | Feature版本号,标识规划的新特性版本,值为osFullName中的第三位数值,建议直接使用deviceInfo.featureVersion获取,可提升效率,不建议开发者自主解析osFullName获取。<br/>示例:0 |
48| buildVersion | number | 是 | Build版本号,标识编译构建的版本号,值为osFullName中的第四位数值,建议直接使用deviceInfo.buildVersion获取,可提升效率,不建议开发者自主解析osFullName获取。<br/>示例:1 |
49| sdkApiVersion | number | 是 | 系统软件API版本。<br/>**原子化服务API**:从API version 14开始,该接口支持在原子化服务中使用。<br/>示例:12 |
50| firstApiVersion | number | 是 | 首个版本系统软件API版本。<br/>示例:3 |
51| versionId | string | 是 | 版本ID。由deviceType、manufacture、brand、productSeries、osFullName、productModel、softwareModel、sdkApiVersion、incrementalVersion、buildType拼接组成。<br/>示例:wearable/HUAWEI/HUAWEI/TAS/OpenHarmony-5.0.0.1/TAS-AL00/TAS-AL00/12/default/release:nolog |
52| buildType | string | 是 | 构建类型。<br/>示例:default |
53| buildUser | string | 是 | 构建用户。<br/>示例:default |
54| buildHost | string | 是 | 构建主机。<br/>示例:default |
55| buildTime | string | 是 | 构建时间。<br/>示例:default |
56| buildRootHash | string | 是 | 构建版本Hash。<br/>示例:default |
57| udid<sup>7+</sup> | string | 是 | 设备Udid。<br/>**说明**:数据长度为65字节。可作为设备唯一识别码。<br/>**需要权限**:ohos.permission.sec.ACCESS_UDID(该权限只允许系统应用及企业定制应用申请)<br/>示例:9D6AABD147XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXE5536412  |
58| distributionOSName<sup>10+</sup> | string | 是 | 发行版系统名称<!--Del-->,由发行方定义<!--DelEnd-->。<br/>示例:OpenHarmony |
59| distributionOSVersion<sup>10+</sup> | string | 是 | 发行版系统版本号<!--Del-->,由发行方定义<!--DelEnd-->。<!--RP11--><!--RP11End--><br/>示例:5.0.0  |
60| distributionOSApiVersion<sup>10+</sup> | number| 是 | 发行版系统api版本<!--Del-->,由发行方定义<!--DelEnd-->。<br/>示例:50001 |
61| distributionOSApiName<sup>13+</sup> | string | 是 | 发行版系统api版本名称<!--Del-->,由发行方定义<!--DelEnd-->。 |
62| distributionOSReleaseType<sup>10+</sup> | string | 是 | 发行版系统类型<!--Del-->,由发行方定义<!--DelEnd-->。<br/>示例:Release |
63| ODID<sup>12+</sup> | string | 是 |开发者匿名设备标识符。<br/>**ODID值会在以下场景重新生成**:<br/>手机恢复出厂设置。<br/>同一设备上同一个开发者(developerId相同)的应用全部卸载后重新安装时。<br/>**ODID生成规则**:<br/>根据签名信息里developerId解析出的groupId生成,developerId规则为groupId.developerId,若无groupId则取整个developerId作为groupId。<br/>同一设备上运行的同一个开发者(developerId相同)的应用,ODID相同。<br/>同一个设备上不同开发者(developerId不同)的应用,ODID不同。<br/>不同设备上同一个开发者(developerId相同)的应用,ODID不同。<br/>不同设备上不同开发者(developerId不同)的应用,ODID不同。<br/>**说明**:数据长度为37字节。<br/>示例:1234a567-XXXX-XXXX-XXXX-XXXXXXXXXXXX |
64| diskSN<sup>15+</sup> | string | 是 | 硬盘序列号。<br/> **说明** :该字段只能在2in1上设备进行查询,其他设备查询结果为空。<br/> **需要权限**:ohos.permission.ACCESS_DISK_PHY_INFO <br/> 示例:2502EM400567 |
65| performanceClass<sup>19+</sup> | [PerformanceClassLevel](#performanceclasslevel19) | 是 | 描述设备能力等级。 |
66
67**示例**
68
69```ts
70    import { deviceInfo } from '@kit.BasicServicesKit';
71
72    let deviceTypeInfo: string = deviceInfo.deviceType;
73    // 输出结果:the value of the deviceType is :wearable
74    console.info('the value of the deviceType is :' + deviceTypeInfo);
75
76    let manufactureInfo: string = deviceInfo.manufacture;
77    // 输出结果:the value of the manufacture is :HUAWEI
78    console.info('the value of the manufactureInfo is :' + manufactureInfo);
79
80    let brandInfo: string = deviceInfo.brand;
81    // 输出结果:the value of the brand is :HUAWEI
82    console.info('the value of the device brand is :' + brandInfo);
83
84    let marketNameInfo: string = deviceInfo.marketName;
85    // 输出结果:the value of the marketName is :Mate XX
86    console.info('the value of the deviceInfo marketName is :' + marketNameInfo);
87
88    let productSeriesInfo: string = deviceInfo.productSeries;
89    // 输出结果:the value of the productSeries is :TAS
90    console.info('the value of the deviceInfo productSeries is :' + productSeriesInfo);
91
92    let productModelInfo: string = deviceInfo.productModel;
93    // 输出结果:the value of the productModel is :TAS-AL00
94    console.info('the value of the deviceInfo productModel is :' + productModelInfo);
95
96    let productModelAliasInfo: string = deviceInfo.productModelAlias;
97    console.info('the value of the deviceInfo productModelAlias is :' + productModelAliasInfo);
98
99    let softwareModelInfo: string = deviceInfo.softwareModel;
100    // 输出结果:the value of the softwareModel is :TAS-AL00
101    console.info('the value of the deviceInfo softwareModel is :' + softwareModelInfo);
102
103    let hardwareModelInfo: string = deviceInfo.hardwareModel;
104    // 输出结果:the value of the hardwareModel is :TASA00CVN1
105    console.info('the value of the deviceInfo hardwareModel is :' + hardwareModelInfo);
106
107    let serialInfo: string = deviceInfo.serial;
108    // 输出结果:the value of the serial is :序列号随设备差异
109    console.info('the value of the deviceInfo serial is :' + serialInfo);
110
111    let bootloaderVersionInfo: string = deviceInfo.bootloaderVersion;
112    // 输出结果:the value of the bootloaderVersion is :bootloader
113    console.info('the value of the deviceInfo bootloaderVersion is :' + bootloaderVersionInfo);
114
115    let abiListInfo: string = deviceInfo.abiList;
116    // 输出结果:the value of the abiList is :arm64-v8a
117    console.info('the value of the deviceInfo abiList is :' + abiListInfo);
118
119    let securityPatchTagInfo: string = deviceInfo.securityPatchTag;
120    // 输出结果:the value of the securityPatchTag is :2021/01/01
121    console.info('the value of the deviceInfo securityPatchTag is :' + securityPatchTagInfo);
122
123    let displayVersionInfo: string = deviceInfo.displayVersion;
124    // 输出结果:the value of the displayVersion is :XXX X.X.X.X
125    console.info('the value of the deviceInfo displayVersion is :' + displayVersionInfo);
126
127    let incrementalVersionInfo: string = deviceInfo.incrementalVersion;
128    // 输出结果:the value of the incrementalVersion is :default
129    console.info('the value of the deviceInfo incrementalVersion is :' + incrementalVersionInfo);
130
131    let osReleaseTypeInfo: string = deviceInfo.osReleaseType;
132    // 输出结果:the value of the osReleaseType is :Release
133    console.info('the value of the deviceInfo osReleaseType is :' + osReleaseTypeInfo);
134
135    let osFullNameInfo: string = deviceInfo.osFullName;
136    // 输出结果:the value of the osFullName is :OpenHarmony-5.0.0.1
137    console.info('the value of the deviceInfo osFullName is :' + osFullNameInfo);
138
139    let majorVersionInfo: number = deviceInfo.majorVersion;
140    // 输出结果:the value of the majorVersion is :5
141    console.info('the value of the deviceInfo majorVersion is :' + majorVersionInfo);
142
143    let seniorVersionInfo: number = deviceInfo.seniorVersion;
144    // 输出结果:the value of the seniorVersion is :0
145    console.info('the value of the deviceInfo seniorVersion is :' + seniorVersionInfo);
146
147    let featureVersionInfo: number = deviceInfo.featureVersion;
148    // 输出结果:the value of the featureVersion is :0
149    console.info('the value of the deviceInfo featureVersion is :' + featureVersionInfo);
150
151    let buildVersionInfo: number = deviceInfo.buildVersion;
152    // 输出结果:the value of the buildVersion is :1
153    console.info('the value of the deviceInfo buildVersion is :' + buildVersionInfo);
154
155    let sdkApiVersionInfo: number = deviceInfo.sdkApiVersion;
156    // 输出结果:the value of the sdkApiVersion is :12
157    console.info('the value of the deviceInfo sdkApiVersion is :' + sdkApiVersionInfo);
158
159    let firstApiVersionInfo: number = deviceInfo.firstApiVersion;
160    // 输出结果:the value of the firstApiVersion is :3
161    console.info('the value of the deviceInfo firstApiVersion is :' + firstApiVersionInfo);
162
163    let versionIdInfo: string = deviceInfo.versionId;
164    // 输出结果:the value of the versionId is :wearable/HUAWEI/HUAWEI/TAS/OpenHarmony-5.0.0.1/TAS-AL00/TAS-AL00/12/default/release:nolog
165    console.info('the value of the deviceInfo versionId is :' + versionIdInfo);
166
167    let buildTypeInfo: string = deviceInfo.buildType;
168    // 输出结果:the value of the buildType is :default
169    console.info('the value of the deviceInfo buildType is :' + buildTypeInfo);
170
171    let buildUserInfo: string = deviceInfo.buildUser;
172    // 输出结果:the value of the buildUser is :default
173    console.info('the value of the deviceInfo buildUser is :' + buildUserInfo);
174
175    let buildHostInfo: string = deviceInfo.buildHost;
176    // 输出结果:the value of the buildHost is :default
177    console.info('the value of the deviceInfo buildHost is :' + buildHostInfo);
178
179    let buildTimeInfo: string = deviceInfo.buildTime;
180    // 输出结果:the value of the buildTime is :default
181    console.info('the value of the deviceInfo buildTime is :' + buildTimeInfo);
182
183    let buildRootHashInfo: string = deviceInfo.buildRootHash;
184    // 输出结果:the value of the buildRootHash is :default
185    console.info('the value of the deviceInfo buildRootHash is :' + buildRootHashInfo);
186
187    let udid: string = deviceInfo.udid;
188    // 输出结果:the value of the udid is :9D6AABD147XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXE5536412
189    console.info('the value of the deviceInfo udid is :' + udid);
190
191    let distributionOSName: string = deviceInfo.distributionOSName
192    // 输出结果:the value of the distributionOSName is :OpenHarmony
193    console.info('the value of the deviceInfo distributionOSName is :' + distributionOSName);
194
195    let distributionOSVersion: string = deviceInfo.distributionOSVersion
196    // 输出结果:the value of the distributionOSVersion is :5.0.0
197    console.info('the value of the deviceInfo distributionOSVersion is :' + distributionOSVersion);
198
199    let distributionOSApiVersion: number = deviceInfo.distributionOSApiVersion
200    // 输出结果:the value of the distributionOSApiVersion is :500001
201    console.info('the value of the deviceInfo distributionOSApiVersion is :' + distributionOSApiVersion);
202
203    let distributionOSApiName: string = deviceInfo.distributionOSApiName
204    console.info('the value of the deviceInfo distributionOSApiName is :' + distributionOSApiName);
205
206    let distributionOSReleaseType: string = deviceInfo.distributionOSReleaseType
207    // 输出结果:the value of the distributionOSReleaseType is :Release
208    console.info('the value of the deviceInfo distributionOSReleaseType is :' + distributionOSReleaseType);
209
210    let odid: string = deviceInfo.ODID;
211    // 输出结果:the value of the ODID is :1234a567-XXXX-XXXX-XXXX-XXXXXXXXXXXX
212    console.info('the value of the deviceInfo odid is :' + odid);
213
214    let diskSN: string = deviceInfo.diskSN;
215    // 输出结果:the value of the deviceInfo diskSN is :2502EM400567
216    console.info('the value of the deviceInfo diskSN is :' + diskSN);
217
218    let performanceClass = deviceInfo.performanceClass;
219    // 输出结果:the value of the deviceInfo performanceClass is :0
220    console.info('the value of the deviceInfo performanceClass is :' + performanceClass);
221
222```
223
224## PerformanceClassLevel<sup>19+</sup>
225
226表示设备能力定级的枚举。
227
228**系统能力**:SystemCapability.Startup.SystemInfo
229
230| 名称                  | 值  | 说明           |
231| ---------------------| ---- | -------------- |
232| CLASS_LEVEL_HIGH     | 0    | 表示设备能力定级为高。     |
233| CLASS_LEVEL_MEDIUM   | 1    | 表示设备能力定级为中。   |
234| CLASS_LEVEL_LOW      | 2    | 表示设备能力定级为低。   |
235
236## DeviceTypes<sup>20+</sup>
237
238设备类型枚举值,可用于校验deviceType的返回值。
239
240**原子化服务API**:从API version 20开始,该接口支持在原子化服务中使用。
241
242**系统能力**:SystemCapability.Startup.SystemInfo
243
244| 名称 | 值   | 说明                       |
245| ---- | ---- | -------------------------- |
246| TYPE_DEFAULT | 'default' | 默认设备。 |
247| TYPE_PHONE | 'phone' | 手机。 |
248| TYPE_TABLET | 'tablet' | 平板。 |
249| TYPE_2IN1 | '2in1' | PC/2in1。 |
250| TYPE_TV | 'tv' | 智慧屏。 |
251| TYPE_WEARABLE | 'wearable' | 智能手表。 |
252| TYPE_CAR | 'car' | 车机。 |
253
254**示例**
255
256```ts
257    let deviceTypesInfo: string = deviceInfo.DeviceTypes.TYPE_DEFAULT;
258    // 输出结果:the value of the DeviceTypes is :default
259    console.info('the value of the DeviceTypes is :' + deviceTypesInfo);
260
261    let deviceTypesInfo: string = deviceInfo.DeviceTypes.TYPE_PHONE;
262    // 输出结果:the value of the DeviceTypes is :phone
263    console.info('the value of the DeviceTypes is :' + deviceTypesInfo);
264
265    let deviceTypesInfo: string = deviceInfo.DeviceTypes.TYPE_TABLET;
266    // 输出结果:the value of the DeviceTypes is :tablet
267    console.info('the value of the DeviceTypes is :' + deviceTypesInfo);
268
269    let deviceTypesInfo: string = deviceInfo.DeviceTypes.TYPE_2IN1;
270    // 输出结果:the value of the DeviceTypes is :2in1
271    console.info('the value of the DeviceTypes is :' + deviceTypesInfo);
272
273    let deviceTypesInfo: string = deviceInfo.DeviceTypes.TYPE_TV;
274    // 输出结果:the value of the DeviceTypes is :tv
275    console.info('the value of the DeviceTypes is :' + deviceTypesInfo);
276
277    let deviceTypesInfo: string = deviceInfo.DeviceTypes.TYPE_WEARABLE;
278    // 输出结果:the value of the DeviceTypes is :wearable
279    console.info('the value of the DeviceTypes is :' + deviceTypesInfo);
280
281    let deviceTypesInfo: string = deviceInfo.DeviceTypes.TYPE_CAR;
282    // 输出结果:the value of the DeviceTypes is :car
283    console.info('the value of the DeviceTypes is :' + deviceTypesInfo);
284```
285