1e41f4b71Sopenharmony_ci# @ohos.deviceInfo (设备信息) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci本模块提供终端设备信息查询,开发者不可配置。 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **说明:** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8e41f4b71Sopenharmony_ci> 部分参数返回值为default的,会在正式发布的版本中配置。 9e41f4b71Sopenharmony_ci> 本模块接口返回设备常量信息,建议应用只调用一次,不需要频繁调用。 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci## 导入模块 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci```ts 14e41f4b71Sopenharmony_ciimport { deviceInfo } from '@kit.BasicServicesKit'; 15e41f4b71Sopenharmony_ci``` 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci## 属性 18e41f4b71Sopenharmony_ci> **说明:** 19e41f4b71Sopenharmony_ci> 未特殊说明的字段,数据长度最大值为96字节。 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Startup.SystemInfo。 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci**权限**:以下各项所需要的权限有所不同,详见下表。 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci| 名称 | 类型 | 可读 | 可写 | 说明 | 26e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 27e41f4b71Sopenharmony_ci| deviceType | string | 是 | 否 | 设备类型。详细请参考[deviceTypes标签](../../quick-start/module-configuration-file.md#devicetypes标签)。<br/>**原子化服务API**:从API version 11开始,该接口支持在原子化服务中使用。<br/>示例:wearable| 28e41f4b71Sopenharmony_ci| manufacture | string | 是 | 否 | 设备厂家名称。<br/>示例:HUAWEI | 29e41f4b71Sopenharmony_ci| brand | string | 是 | 否 | 设备品牌名称。<br/>**原子化服务API**:从API version 11开始,该接口支持在原子化服务中使用。<br/>示例:HUAWEI | 30e41f4b71Sopenharmony_ci| marketName | string | 是 | 否 | 外部产品系列。<br/>示例:Mate XX | 31e41f4b71Sopenharmony_ci| productSeries | string | 是 | 否 | 产品系列。<br/>示例:TAS | 32e41f4b71Sopenharmony_ci| productModel | string | 是 | 否 | 认证型号。<br/>**原子化服务API**:从API version 11开始,该接口支持在原子化服务中使用。<br/>示例:TAS-AL00 | 33e41f4b71Sopenharmony_ci| softwareModel | string | 是 | 否 | 内部软件子型号。<br/>示例:TAS-AL00 | 34e41f4b71Sopenharmony_ci| hardwareModel | string | 是 | 否 | 硬件版本号。<br/>示例:TASA00CVN1 | 35e41f4b71Sopenharmony_ci| hardwareProfile<sup>(deprecated) </sup> | string | 是 | 否 | 硬件Profile。<br/>**说明**:<br/>从API version 6 开始支持,从API version 9 开始废弃。 | 36e41f4b71Sopenharmony_ci| serial | string | 是 | 否 | 设备序列号,仅限系统应用使用。<br/>**说明**:可作为设备唯一识别码。<br/>**需要权限**:ohos.permission.sec.ACCESS_UDID <br/>示例:序列号随设备差异 | 37e41f4b71Sopenharmony_ci| bootloaderVersion | string | 是 | 否 | Bootloader版本号。<br/>示例:bootloater | 38e41f4b71Sopenharmony_ci| abiList | string | 是 | 否 | 应用二进制接口(Abi)。<br/>示例:arm64-v8a | 39e41f4b71Sopenharmony_ci| securityPatchTag | string | 是 | 否 | 安全补丁级别。<br/>示例:2021-01-01 | 40e41f4b71Sopenharmony_ci| displayVersion | string | 是 | 否 | 产品版本。<br/>示例:XXX X.X.X.X | 41e41f4b71Sopenharmony_ci| incrementalVersion | string | 是 | 否 | 差异版本号。 | 42e41f4b71Sopenharmony_ci| osReleaseType | string | 是 | 否 | 系统的发布类型,取值为:<br/>- Canary:面向特定开发者发布的早期预览版本,不承诺API稳定性。<br/>- Beta:面向开发者公开发布的Beta版本,不承诺API稳定性。<br/>- Release:面向开发者公开发布的正式版本,承诺API稳定性。<br/>示例:Canary\\Beta\\Release | 43e41f4b71Sopenharmony_ci| osFullName | string | 是 | 否 | 系统版本,版本格式OpenHarmony-x.x.x.x,x为数值。<br/>**原子化服务API**:从API version 11开始,该接口支持在原子化服务中使用。<br/>示例:Openharmony-5.0.0.1 | 44e41f4b71Sopenharmony_ci| majorVersion | number | 是 | 否 | Major版本号,随主版本更新增加,值为osFullName中的第一位数值,建议直接使用deviceInfo.majorVersion获取,不建议开发者解析osFullName获取。<br/>示例:5 | 45e41f4b71Sopenharmony_ci| seniorVersion | number | 是 | 否 | Senior版本号,随局部架构、重大特性增加,值为osFullName中的第二位数值,建议直接使用deviceInfo.seniorVersion获取,不建议开发者自主解析osFullName获取。<br/>示例:0 | 46e41f4b71Sopenharmony_ci| featureVersion | number | 是 | 否 | Feature版本号,标识规划的新特性版本,值为osFullName中的第三位数值,建议直接使用deviceInfo.featureVersion获取,不建议开发者自主解析osFullName获取。<br/>示例:0 | 47e41f4b71Sopenharmony_ci| buildVersion | number | 是 | 否 | Build版本号,标识编译构建的版本号,值为osFullName中的第四位数值,建议直接使用deviceInfo.buildVersion获取,不建议开发者自主解析osFullName获取。<br/>示例:1 | 48e41f4b71Sopenharmony_ci| sdkApiVersion | number | 是 | 否 | 系统软件API版本。<br/>示例:12 | 49e41f4b71Sopenharmony_ci| firstApiVersion | number | 是 | 否 | 首个版本系统软件API版本。<br/>示例:3 | 50e41f4b71Sopenharmony_ci| versionId | string | 是 | 否 | 版本ID。由deviceType、manufacture、brand、productSeries、osFullName、productModel、softwareModel、sdkApiVersion、incrementalVersion、buildType拼接组成。 | 51e41f4b71Sopenharmony_ci| buildType | string | 是 | 否 | 构建类型。<br/>示例:release:nolog | 52e41f4b71Sopenharmony_ci| buildUser | string | 是 | 否 | 构建用户。 | 53e41f4b71Sopenharmony_ci| buildHost | string | 是 | 否 | 构建主机。 | 54e41f4b71Sopenharmony_ci| buildTime | string | 是 | 否 | 构建时间。 | 55e41f4b71Sopenharmony_ci| buildRootHash | string | 是 | 否 | 构建版本Hash。 | 56e41f4b71Sopenharmony_ci| udid<sup>7+</sup> | string | 是 | 否 | 设备Udid,仅限系统应用使用。<br/>**说明**:数据长度为65字节。可作为设备唯一识别码。<br/>**需要权限**:ohos.permission.sec.ACCESS_UDID | 57e41f4b71Sopenharmony_ci| distributionOSName<sup>10+</sup> | String | 是 | 否 | 发行版系统名称<!--Del-->,由发行方定义<!--DelEnd-->。 | 58e41f4b71Sopenharmony_ci| distributionOSVersion<sup>10+</sup> | String | 是 | 否 | 发行版系统版本号<!--Del-->,由发行方定义<!--DelEnd-->。<!--RP1--><!--RP1End--> | 59e41f4b71Sopenharmony_ci| distributionOSApiVersion<sup>10+</sup> | number| 是 | 否 | 发行版系统api版本<!--Del-->,由发行方定义<!--DelEnd-->。 | 60e41f4b71Sopenharmony_ci| distributionOSApiName<sup>13+</sup> | String | 是 | 否 | 发行版系统api版本名称<!--Del-->,由发行方定义<!--DelEnd-->。 | 61e41f4b71Sopenharmony_ci| distributionOSReleaseType<sup>10+</sup> | String | 是 | 否 | 发行版系统类型<!--Del-->,由发行方定义<!--DelEnd-->。 | 62e41f4b71Sopenharmony_ci| ODID<sup>12+</sup> | String | 是 | 否 |开发者匿名设备标识符。<br/>**ODID值会在以下场景重新生成**:<br/>手机恢复出厂设置。<br/>同一设备上同一个开发者的应用全部卸载后重新安装时。<br/>**ODID生成规则**:<br/>同一设备上运行的同一个开发者的应用,ODID相同。<br/>同一个设备上不同开发者的应用,ODID不同。<br/>不同设备上同一个开发者的应用,ODID不同。<br/>不同设备上不同开发者的应用,ODID不同。<br/>**说明**:数据长度为37字节。 | 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ci**示例** 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_ci```ts 67e41f4b71Sopenharmony_ci import { deviceInfo } from '@kit.BasicServicesKit'; 68e41f4b71Sopenharmony_ci 69e41f4b71Sopenharmony_ci let deviceTypeInfo: string = deviceInfo.deviceType; 70e41f4b71Sopenharmony_ci console.info('the value of the deviceType is :' + deviceTypeInfo); 71e41f4b71Sopenharmony_ci 72e41f4b71Sopenharmony_ci let manufactureInfo: string = deviceInfo.manufacture; 73e41f4b71Sopenharmony_ci console.info('the value of the manufactureInfo is :' + manufactureInfo); 74e41f4b71Sopenharmony_ci 75e41f4b71Sopenharmony_ci let brandInfo: string = deviceInfo.brand; 76e41f4b71Sopenharmony_ci console.info('the value of the device brand is :' + brandInfo); 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ci let marketNameInfo: string = deviceInfo.marketName; 79e41f4b71Sopenharmony_ci console.info('the value of the deviceInfo marketName is :' + marketNameInfo); 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ci let productSeriesInfo: string = deviceInfo.productSeries; 82e41f4b71Sopenharmony_ci console.info('the value of the deviceInfo productSeries is :' + productSeriesInfo); 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ci let productModelInfo: string = deviceInfo.productModel; 85e41f4b71Sopenharmony_ci console.info('the value of the deviceInfo productModel is :' + productModelInfo); 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ci let softwareModelInfo: string = deviceInfo.softwareModel; 88e41f4b71Sopenharmony_ci console.info('the value of the deviceInfo softwareModel is :' + softwareModelInfo); 89e41f4b71Sopenharmony_ci 90e41f4b71Sopenharmony_ci let hardwareModelInfo: string = deviceInfo.hardwareModel; 91e41f4b71Sopenharmony_ci console.info('the value of the deviceInfo hardwareModel is :' + hardwareModelInfo); 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ci let serialInfo: string = deviceInfo.serial; 94e41f4b71Sopenharmony_ci console.info('the value of the deviceInfo serial is :' + serialInfo); 95e41f4b71Sopenharmony_ci 96e41f4b71Sopenharmony_ci let bootloaderVersionInfo: string = deviceInfo.bootloaderVersion; 97e41f4b71Sopenharmony_ci console.info('the value of the deviceInfo bootloaderVersion is :' + bootloaderVersionInfo); 98e41f4b71Sopenharmony_ci 99e41f4b71Sopenharmony_ci let abiListInfo: string = deviceInfo.abiList; 100e41f4b71Sopenharmony_ci console.info('the value of the deviceInfo abiList is :' + abiListInfo); 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ci let securityPatchTagInfo: string = deviceInfo.securityPatchTag; 103e41f4b71Sopenharmony_ci console.info('the value of the deviceInfo securityPatchTag is :' + securityPatchTagInfo); 104e41f4b71Sopenharmony_ci 105e41f4b71Sopenharmony_ci let displayVersionInfo: string = deviceInfo.displayVersion; 106e41f4b71Sopenharmony_ci console.info('the value of the deviceInfo displayVersion is :' + displayVersionInfo); 107e41f4b71Sopenharmony_ci 108e41f4b71Sopenharmony_ci let incrementalVersionInfo: string = deviceInfo.incrementalVersion; 109e41f4b71Sopenharmony_ci console.info('the value of the deviceInfo incrementalVersion is :' + incrementalVersionInfo); 110e41f4b71Sopenharmony_ci 111e41f4b71Sopenharmony_ci let osReleaseTypeInfo: string = deviceInfo.osReleaseType; 112e41f4b71Sopenharmony_ci console.info('the value of the deviceInfo osReleaseType is :' + osReleaseTypeInfo); 113e41f4b71Sopenharmony_ci 114e41f4b71Sopenharmony_ci let osFullNameInfo: string = deviceInfo.osFullName; 115e41f4b71Sopenharmony_ci console.info('the value of the deviceInfo osFullName is :' + osFullNameInfo); 116e41f4b71Sopenharmony_ci 117e41f4b71Sopenharmony_ci let majorVersionInfo: number = deviceInfo.majorVersion; 118e41f4b71Sopenharmony_ci console.info('the value of the deviceInfo majorVersion is :' + majorVersionInfo); 119e41f4b71Sopenharmony_ci 120e41f4b71Sopenharmony_ci let seniorVersionInfo: number = deviceInfo.seniorVersion; 121e41f4b71Sopenharmony_ci console.info('the value of the deviceInfo seniorVersion is :' + seniorVersionInfo); 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_ci let featureVersionInfo: number = deviceInfo.featureVersion; 124e41f4b71Sopenharmony_ci console.info('the value of the deviceInfo featureVersion is :' + featureVersionInfo); 125e41f4b71Sopenharmony_ci 126e41f4b71Sopenharmony_ci let buildVersionInfo: number = deviceInfo.buildVersion; 127e41f4b71Sopenharmony_ci console.info('the value of the deviceInfo buildVersion is :' + buildVersionInfo); 128e41f4b71Sopenharmony_ci 129e41f4b71Sopenharmony_ci let sdkApiVersionInfo: number = deviceInfo.sdkApiVersion; 130e41f4b71Sopenharmony_ci console.info('the value of the deviceInfo sdkApiVersion is :' + sdkApiVersionInfo); 131e41f4b71Sopenharmony_ci 132e41f4b71Sopenharmony_ci let firstApiVersionInfo: number = deviceInfo.firstApiVersion; 133e41f4b71Sopenharmony_ci console.info('the value of the deviceInfo firstApiVersion is :' + firstApiVersionInfo); 134e41f4b71Sopenharmony_ci 135e41f4b71Sopenharmony_ci let versionIdInfo: string = deviceInfo.versionId; 136e41f4b71Sopenharmony_ci console.info('the value of the deviceInfo versionId is :' + versionIdInfo); 137e41f4b71Sopenharmony_ci 138e41f4b71Sopenharmony_ci let buildTypeInfo: string = deviceInfo.buildType; 139e41f4b71Sopenharmony_ci console.info('the value of the deviceInfo buildType is :' + buildTypeInfo); 140e41f4b71Sopenharmony_ci 141e41f4b71Sopenharmony_ci let buildUserInfo: string = deviceInfo.buildUser; 142e41f4b71Sopenharmony_ci console.info('the value of the deviceInfo buildUser is :' + buildUserInfo); 143e41f4b71Sopenharmony_ci 144e41f4b71Sopenharmony_ci let buildHostInfo: string = deviceInfo.buildHost; 145e41f4b71Sopenharmony_ci console.info('the value of the deviceInfo buildHost is :' + buildHostInfo); 146e41f4b71Sopenharmony_ci 147e41f4b71Sopenharmony_ci let buildTimeInfo: string = deviceInfo.buildTime; 148e41f4b71Sopenharmony_ci console.info('the value of the deviceInfo buildTime is :' + buildTimeInfo); 149e41f4b71Sopenharmony_ci 150e41f4b71Sopenharmony_ci let buildRootHashInfo: string = deviceInfo.buildRootHash; 151e41f4b71Sopenharmony_ci console.info('the value of the deviceInfo buildRootHash is :' + buildRootHashInfo); 152e41f4b71Sopenharmony_ci 153e41f4b71Sopenharmony_ci let udid: string = deviceInfo.udid; 154e41f4b71Sopenharmony_ci console.info('the value of the deviceInfo udid is :' + udid); 155e41f4b71Sopenharmony_ci 156e41f4b71Sopenharmony_ci let distributionOSName: string = deviceInfo.distributionOSName 157e41f4b71Sopenharmony_ci console.info('the value of the deviceInfo distributionOSName is :' + distributionOSName); 158e41f4b71Sopenharmony_ci 159e41f4b71Sopenharmony_ci let distributionOSVersion: string = deviceInfo.distributionOSVersion 160e41f4b71Sopenharmony_ci console.info('the value of the deviceInfo distributionOSVersion is :' + distributionOSVersion); 161e41f4b71Sopenharmony_ci 162e41f4b71Sopenharmony_ci let distributionOSApiVersion: number = deviceInfo.distributionOSApiVersion 163e41f4b71Sopenharmony_ci console.info('the value of the deviceInfo distributionOSApiVersion is :' + distributionOSApiVersion); 164e41f4b71Sopenharmony_ci 165e41f4b71Sopenharmony_ci let distributionOSApiName: number = deviceInfo.distributionOSApiName 166e41f4b71Sopenharmony_ci console.info('the value of the deviceInfo distributionOSApiName is :' + distributionOSApiName); 167e41f4b71Sopenharmony_ci 168e41f4b71Sopenharmony_ci let distributionOSReleaseType: string = deviceInfo.distributionOSReleaseType 169e41f4b71Sopenharmony_ci console.info('the value of the deviceInfo distributionOSReleaseType is :' + distributionOSReleaseType); 170e41f4b71Sopenharmony_ci 171e41f4b71Sopenharmony_ci let odid: string = deviceInfo.ODID; 172e41f4b71Sopenharmony_ci console.info('the value of the deviceInfo odid is :' + odid); 173e41f4b71Sopenharmony_ci 174e41f4b71Sopenharmony_ci``` 175