• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.deviceInfo (Device Information)
2
3The **deviceInfo** module provides terminal device information query, which cannot be configured by developers.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8> Some parameters whose return value is the default value are not yet available.
9> The APIs of this module return information about device constants. You are not expected to call these APIs frequently.
10
11## Modules to Import
12
13```ts
14import { deviceInfo } from '@kit.BasicServicesKit';
15```
16
17## Attributes
18> **NOTE**
19> Unless otherwise specified, the maximum data length is 96 bytes.
20
21**System capability**: SystemCapability.Startup.SystemInfo
22
23**Required permissions**: The items in the table below require different system capabilities.
24
25| Name| Type| Readable| Writable| Description|
26| -------- | -------- | -------- | -------- | -------- |
27| deviceType | string | Yes| No| Device type. For details, see [deviceTypes tag](../../quick-start/module-configuration-file.md#devicetypes).<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br>Example: <!--RP1-->wearable<!--RP1End-->|
28| manufacture | string | Yes| No| Device manufacturer.<br>Example: HUAWEI|
29| brand | string | Yes| No| Device brand.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br>Example: HUAWEI|
30| marketName | string | Yes| No| Marketing name.<br>Example: <!--RP2-->Mate XX<!--RP2End--> |
31| productSeries | string | Yes| No| Product series.<br>Example: <!--RP3-->TAS<!--RP3End--> |
32| productModel | string | Yes| No| Product model.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br>Example: <!--RP4-->TAS-AL00<!--RP4End--> |
33| productModelAlias<sup>14+</sup> | string | Yes| No| Product model alias.<br>**Atomic service API**: This API can be used in atomic services since API version 14.<br>Example: TAS-AL00|
34| softwareModel | string | Yes| No| Software model.<br>Example: <!--RP5-->TAS-AL00<!--RP5End--> |
35| hardwareModel | string | Yes| No| Hardware model.<br>Example: <!--RP6-->TASA00CVN1<!--RP6End--> |
36| hardwareProfile<sup>(deprecated) </sup> | string | Yes| No| Hardware profile.<br>**NOTE**<br>This API is supported since API version 6 and deprecated since API version 9.<br>Example: default|
37| serial | string | Yes| No| Device SN.<br>**NOTE**<br>The device SN can be used as the unique identifier of a device.<br>**Required permissions**: ohos.permission.sec.ACCESS_UDID<br>Example: The SN varies with the device.|
38| bootloaderVersion | string | Yes| No| Bootloader version.<br>Example: bootloader|
39| abiList | string | Yes| No| Application binary interface (Abi) list.<br>Example: arm64-v8a|
40| securityPatchTag | string | Yes| No| Security patch tag.<br>Example: <!--RP7-->2021-01-01<!--RP7End--> |
41| displayVersion | string | Yes| No| Product version.<br>Example: <!--RP8-->XXX X.X.X.X<!--RP8End--> |
42| incrementalVersion | string | Yes| No| Incremental version.<br>Example: default|
43| osReleaseType | string | Yes| No| OS release type. The options are as follows:<br>- **Canary**: Preliminary release open only to specific developers. This release does not promise API stability and may require tolerance of instability.<br>- **Beta**: Release open to all developers. This release does not promise API stability and may require tolerance of instability.<br>- **Release**: Official release open to all developers. This release promises that all APIs are stable.<br>Example: <!--RP9-->Canary/Beta/Release<!--RP9End--> |
44| osFullName | string | Yes| No| System version. The version number is in the format of **OpenHarmony-x.x.x.x**, where **x** is a digit.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br>Example: <!--RP10-->Openharmony-5.0.0.1<!--RP10End--> |
45| majorVersion | number | Yes| No| Major version number, which increments with the main version. The value is the first digit in **osFullName**. You are advised to use **deviceInfo.majorVersion** instead of parsing **osFullName** to obtain the value, facilitating efficiency improvement.<br>Example: 5|
46| seniorVersion | number | Yes| No| Senior version number, which increments with architecture and feature updates. The value is the second digit in **osFullName**. You are advised to use **deviceInfo.seniorVersion** instead of parsing **osFullName** to obtain the value, facilitating efficiency improvement.<br>Example: 0|
47| featureVersion | number | Yes| No| Feature version number. The value is the third digit in **osFullName**. You are advised to use **deviceInfo.featureVersion** instead of parsing **osFullName** to obtain the value, facilitating efficiency improvement.<br>Example: 0|
48| buildVersion | number | Yes| No| Build version number. The value is the fourth digit in **osFullName**. You are advised to use **deviceInfo.buildVersion** instead of parsing **osFullName** to obtain the value, facilitating efficiency improvement.<br>Example: 1|
49| sdkApiVersion | number | Yes| No| SDK API version.<br>**Atomic service API**: This API can be used in atomic services since API version 14.<br>Example: 12|
50| firstApiVersion | number | Yes| No| First API version.<br>Example: 3|
51| versionId | string | Yes| No| Version ID. It consists of the following fields: **deviceType**, **manufacture**, **brand**, **productSeries**, **osFullName**, **productModel**, **softwareModel**, **sdkApiVersion**, **incrementalVersion**, and **buildType**.<br>Example: wearable/HUAWEI/HUAWEI/TAS/OpenHarmony-5.0.0.1/TAS-AL00/TAS-AL00/12/default/release:nolog|
52| buildType | string | Yes| No| Build type.<br>Example: release:nolog|
53| buildUser | string | Yes| No| Build user.<br>Example: default|
54| buildHost | string | Yes| No| Build host.<br>Example: default|
55| buildTime | string | Yes| No| Build time.<br>Example: default|
56| buildRootHash | string | Yes| No| Build root hash.<br>Example: default|
57| udid<sup>7+</sup> | string | Yes| No| Device UDID.<br>**NOTE**<br>The data length is 65 bytes. The UDID can be used as the unique identifier of a device.<br>**Required permissions**: ohos.permission.sec.ACCESS_UDID<br>Example: 9D6AABD147XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXE5536412 |
58| distributionOSName<sup>10+</sup> | string | Yes| No| Distribution OS name.<!--Del--> It is defined by the issuer.<!--DelEnd-->.<br>Example: OpenHarmony|
59| distributionOSVersion<sup>10+</sup> | string | Yes| No| Distribution OS version.<!--Del--> It is defined by the issuer.<!--DelEnd-->.<!--RP11--><!--RP11End--><br>Example: 5.0.0.1 |
60| distributionOSApiVersion<sup>10+</sup> | number| Yes| No| Distribution OS API version.<!--Del--> It is defined by the issuer.<!--DelEnd-->.<br>Example: 50001|
61| distributionOSApiName<sup>13+</sup> | string | Yes| No| Distribution OS API name.<!--Del--> It is defined by the issuer.<!--DelEnd-->.|
62| distributionOSReleaseType<sup>10+</sup> | string | Yes| No| Distribution OS release type.<!--Del--> It is defined by the issuer.<!--DelEnd-->.<br>Example: Release|
63| ODID<sup>12+</sup> | string | Yes| No|Open device identifier.<br>An ODID will be regenerated in the following scenarios:<br>Restore a phone to its factory settings.<br>Uninstall and reinstall all applications with the same **developerId** on one device.<br>An ODID is generated based on the following rules:<br>The value is generated based on the **groupId** parsed from the **developerId** in the signature information. As **groupId.developerId** is the rule, if no **groupId** exists, the **developerId** is used as the **groupId**.<br>Applications with the same **developerId** use the same ODID on one device.<br>Applications with different **developerId**s use different ODIDs on one device.<br>Applications with the same **developerId** use different ODIDs on different devices.<br>Applications with different **developerId**s use different ODIDs on different devices.<br>**NOTE**<br>The data length is 37 bytes.<br>Example: 1234a567-XXXX-XXXX-XXXX-XXXXXXXXXXXX|
64| diskSN<sup>15+</sup> | string | Yes| No| Disk SN.<br>**NOTE**<br>This field can be queried only on the 2-in-1 device. For other devices, the query result is empty.<br> **Required permissions**: ohos.permission.ACCESS_DISK_PHY_INFO<br> Example: 2502EM400567 |
65
66**Example**
67
68```ts
69    import { deviceInfo } from '@kit.BasicServicesKit';
70
71    let deviceTypeInfo: string = deviceInfo.deviceType;
72    // Output: the value of the deviceType is: wearable
73    console.info('the value of the deviceType is :' + deviceTypeInfo);
74
75    let manufactureInfo: string = deviceInfo.manufacture;
76    // Output: the value of the manufactureInfo is: HUAWEI
77    console.info('the value of the manufactureInfo is :' + manufactureInfo);
78
79    let brandInfo: string = deviceInfo.brand;
80    // Output: the value of the device brand is: HUAWEI
81    console.info('the value of the device brand is :' + brandInfo);
82
83    let marketNameInfo: string = deviceInfo.marketName;
84    // Output: the value of the deviceInfo marketName is: Mate XX
85    console.info('the value of the deviceInfo marketName is :' + marketNameInfo);
86
87    let productSeriesInfo: string = deviceInfo.productSeries;
88    // Output: the value of the deviceInfo productSeries is: TAS
89    console.info('the value of the deviceInfo productSeries is :' + productSeriesInfo);
90
91    let productModelInfo: string = deviceInfo.productModel;
92    // Output: the value of the deviceInfo productModel is: TAS-AL00
93    console.info('the value of the deviceInfo productModel is :' + productModelInfo);
94
95    let productModelAliasInfo: string = deviceInfo.productModelAlias;
96    console.info('the value of the deviceInfo productModelAlias is :' + productModelAliasInfo);
97
98    let softwareModelInfo: string = deviceInfo.softwareModel;
99    // Output result: the value of the deviceInfo softwareModel is: TAS-AL00
100    console.info('the value of the deviceInfo softwareModel is :' + softwareModelInfo);
101
102    let hardwareModelInfo: string = deviceInfo.hardwareModel;
103    // Output: the value of the deviceInfo hardwareModel is: TASA00CVN1
104    console.info('the value of the deviceInfo hardwareModel is :' + hardwareModelInfo);
105
106    let serialInfo: string = deviceInfo.serial;
107    // Output: the value of the deviceInfo serial is: ABC123456789
108    console.info('the value of the deviceInfo serial is :' + serialInfo);
109
110    let bootloaderVersionInfo: string = deviceInfo.bootloaderVersion;
111    // Output: the value of the deviceInfo bootloaderVersion is: bootloader
112    console.info('the value of the deviceInfo bootloaderVersion is :' + bootloaderVersionInfo);
113
114    let abiListInfo: string = deviceInfo.abiList;
115    // Output: the value of the deviceInfo abiList is: arm64-v8a
116    console.info('the value of the deviceInfo abiList is :' + abiListInfo);
117
118    let securityPatchTagInfo: string = deviceInfo.securityPatchTag;
119    // Output: the value of the deviceInfo securityPatchTag is: 2021-01-01
120    console.info('the value of the deviceInfo securityPatchTag is :' + securityPatchTagInfo);
121
122    let displayVersionInfo: string = deviceInfo.displayVersion;
123    // Output: the value of the deviceInfo displayVersion is: XXX X.X.X.X
124    console.info('the value of the deviceInfo displayVersion is :' + displayVersionInfo);
125
126    let incrementalVersionInfo: string = deviceInfo.incrementalVersion;
127    // Output: the value of the deviceInfo incrementalVersion is: default
128    console.info('the value of the deviceInfo incrementalVersion is :' + incrementalVersionInfo);
129
130    let osReleaseTypeInfo: string = deviceInfo.osReleaseType;
131    // Output: the value of the deviceInfo osReleaseType is: Release
132    console.info('the value of the deviceInfo osReleaseType is :' + osReleaseTypeInfo);
133
134    let osFullNameInfo: string = deviceInfo.osFullName;
135    // Output: the value of the osFullName is: OpenHarmony-5.0.0.1
136    console.info('the value of the deviceInfo osFullName is :' + osFullNameInfo);
137
138    let majorVersionInfo: number = deviceInfo.majorVersion;
139    // Output: the value of the deviceInfo majorVersion is: 5
140    console.info('the value of the deviceInfo majorVersion is :' + majorVersionInfo);
141
142    let seniorVersionInfo: number = deviceInfo.seniorVersion;
143    // Output: the value of the deviceInfo seniorVersion is: 0
144    console.info('the value of the deviceInfo seniorVersion is :' + seniorVersionInfo);
145
146    let featureVersionInfo: number = deviceInfo.featureVersion;
147    // Output: the value of the deviceInfo featureVersion is: 0
148    console.info('the value of the deviceInfo featureVersion is :' + featureVersionInfo);
149
150    let buildVersionInfo: number = deviceInfo.buildVersion;
151    // Output: the value of the deviceInfo buildVersion is: 1
152    console.info('the value of the deviceInfo buildVersion is :' + buildVersionInfo);
153
154    let sdkApiVersionInfo: number = deviceInfo.sdkApiVersion;
155    // Output: the value of the deviceInfo sdkApiVersion is: 12
156    console.info('the value of the deviceInfo sdkApiVersion is :' + sdkApiVersionInfo);
157
158    let firstApiVersionInfo: number = deviceInfo.firstApiVersion;
159    // Output: the value of the deviceInfo firstApiVersion is: 3
160    console.info('the value of the deviceInfo firstApiVersion is :' + firstApiVersionInfo);
161
162    let versionIdInfo: string = deviceInfo.versionId;
163    // Output result: the value of the deviceInfo versionId is: wearable/HUAWEI/HUAWEI/TAS/OpenHarmony-5.0.0.1/TAS-AL00/TAS-AL00/12/default/release:nolog
164    console.info('the value of the deviceInfo versionId is :' + versionIdInfo);
165
166    let buildTypeInfo: string = deviceInfo.buildType;
167    // Output: the value of the deviceInfo buildUser is: release:nolog
168    console.info('the value of the deviceInfo buildType is :' + buildTypeInfo);
169
170    let buildUserInfo: string = deviceInfo.buildUser;
171    // Output: the value of the deviceInfo buildUser is: default
172    console.info('the value of the deviceInfo buildUser is :' + buildUserInfo);
173
174    let buildHostInfo: string = deviceInfo.buildHost;
175    // Output: the value of the deviceInfo buildHost is: default
176    console.info('the value of the deviceInfo buildHost is :' + buildHostInfo);
177
178    let buildTimeInfo: string = deviceInfo.buildTime;
179    // Output result: the value of the deviceInfo buildTime is: default
180    console.info('the value of the deviceInfo buildTime is :' + buildTimeInfo);
181
182    let buildRootHashInfo: string = deviceInfo.buildRootHash;
183    // Output result: the value of the deviceInfo buildRootHash is: default
184    console.info('the value of the deviceInfo buildRootHash is :' + buildRootHashInfo);
185
186    let udid: string = deviceInfo.udid;
187    // Output: the value of the deviceInfo udid is: 1234567890
188    console.info('the value of the deviceInfo udid is :' + udid);
189
190    let distributionOSName: string = deviceInfo.distributionOSName
191    // Output: the value of the deviceInfo distributionOSName is: OpenHarmony
192    console.info('the value of the deviceInfo distributionOSName is :' + distributionOSName);
193
194    let distributionOSVersion: string = deviceInfo.distributionOSVersion
195    // Output: the value of the deviceInfo distributionOSVersion is: 5.0.0
196    console.info('the value of the deviceInfo distributionOSVersion is :' + distributionOSVersion);
197
198    let distributionOSApiVersion: number = deviceInfo.distributionOSApiVersion
199    // Output: the value of the deviceInfo distributionOSApiVersion is: 500001
200    console.info('the value of the deviceInfo distributionOSApiVersion is :' + distributionOSApiVersion);
201
202    let distributionOSApiName: string = deviceInfo.distributionOSApiName
203    console.info('the value of the deviceInfo distributionOSApiName is :' + distributionOSApiName);
204
205    let distributionOSReleaseType: string = deviceInfo.distributionOSReleaseType
206    // Output: the value of the deviceInfo distributionOSReleaseType is: Release
207    console.info('the value of the deviceInfo distributionOSReleaseType is :' + distributionOSReleaseType);
208
209    let odid: string = deviceInfo.ODID;
210    // Output: the value of the deviceInfo odid is: 1234a567-XXXX-XXXX-XXXX-XXXXXXXXXXXX
211    console.info('the value of the deviceInfo odid is :' + odid);
212
213    let diskSN: string = deviceInfo.diskSN;
214    // Output: the value of the deviceInfo diskSN is: 2502EM400567
215    console.info('the value of the deviceInfo diskSN is :' + diskSN);
216
217```
218