1# @ohos.enterprise.deviceInfo (Device Information Management) (System API) 2 3The **deviceInfo** module provides APIs for enterprise device information management, including obtaining device serial numbers and device names. 4 5> **NOTE** 6> 7> - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> 9> - The APIs of this module can be used only in the stage model. 10> 11> - The APIs of this module can be called only by a [device administrator application](../../mdm/mdm-kit-guide.md#introduction) that is [enabled](js-apis-enterprise-adminManager-sys.md#adminmanagerenableadmin-2). 12> 13> - This topic describes only the system APIs provided by the module. For details about its public APIs, see [@ohos.enterprise.deviceInfo](js-apis-enterprise-deviceInfo.md). 14 15## Modules to Import 16 17```ts 18import { deviceInfo } from '@kit.MDMKit'; 19``` 20 21## deviceInfo.getDeviceSerial 22 23getDeviceSerial(admin: Want, callback: AsyncCallback<string>): void 24 25Obtains the device serial number. This API uses an asynchronous callback to return the result. 26 27**Required permissions**: ohos.permission.ENTERPRISE_GET_DEVICE_INFO 28 29**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 30 31**Parameters** 32 33| Name | Type | Mandatory | Description | 34| -------- | ---------------------------------------- | ---- | ------------------------------- | 35| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 36| callback | AsyncCallback<string> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the device serial number obtained. If the operation fails, **err** is an error object. | 37 38**Error codes** 39 40For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 41 42| ID| Error Message | 43| ------- | ---------------------------------------------------------------------------- | 44| 9200001 | The application is not an administrator application of the device. | 45| 9200002 | The administrator application does not have permission to manage the device. | 46| 201 | Permission verification failed. The application does not have the permission required to call the API. | 47| 202 | Permission verification failed. A non-system application calls a system API. | 48| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 49 50**Example** 51 52```ts 53import { Want } from '@kit.AbilityKit'; 54 55let wantTemp: Want = { 56 bundleName: 'com.example.myapplication', 57 abilityName: 'EntryAbility', 58}; 59 60deviceInfo.getDeviceSerial(wantTemp, (err, result) => { 61 if (err) { 62 console.error(`Failed to get device serial. Code: ${err.code}, message: ${err.message}`); 63 return; 64 } 65 console.info(`Succeeded in getting device serial, result : ${result}`); 66}); 67``` 68 69## deviceInfo.getDeviceSerial 70 71getDeviceSerial(admin: Want): Promise<string> 72 73Obtains the device serial number. This API uses a promise to return the result. 74 75**Required permissions**: ohos.permission.ENTERPRISE_GET_DEVICE_INFO 76 77**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 78 79**Parameters** 80 81| Name | Type | Mandatory | Description | 82| ----- | ----------------------------------- | ---- | ------- | 83| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility.| 84 85**Return value** 86 87| Type | Description | 88| --------------------- | ------------------------- | 89| Promise<string> | Promise used to return the device serial number. | 90 91**Error codes** 92 93For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 94 95| ID| Error Message | 96| ------- | ---------------------------------------------------------------------------- | 97| 9200001 | The application is not an administrator application of the device. | 98| 9200002 | The administrator application does not have permission to manage the device. | 99| 201 | Permission verification failed. The application does not have the permission required to call the API. | 100| 202 | Permission verification failed. A non-system application calls a system API. | 101| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 102 103**Example** 104 105```ts 106import { Want } from '@kit.AbilityKit'; 107import { BusinessError } from '@kit.BasicServicesKit'; 108 109let wantTemp: Want = { 110 bundleName: 'com.example.myapplication', 111 abilityName: 'EntryAbility', 112}; 113 114deviceInfo.getDeviceSerial(wantTemp).then((result) => { 115 console.info(`Succeeded in getting device serial, result : ${result}`); 116}).catch((err: BusinessError) => { 117 console.error(`Failed to get device serial. Code: ${err.code}, message: ${err.message}`); 118}); 119``` 120 121## deviceInfo.getDisplayVersion 122 123getDisplayVersion(admin: Want, callback: AsyncCallback<string>): void 124 125Obtains the device version number. This API uses an asynchronous callback to return the result. 126 127**Required permissions**: ohos.permission.ENTERPRISE_GET_DEVICE_INFO 128 129**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 130 131**Parameters** 132 133| Name | Type | Mandatory | Description | 134| -------- | ---------------------------------------- | ---- | ------------------------------- | 135| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 136| callback | AsyncCallback<string> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the device version number obtained. If the operation fails, **err** is an error object. | 137 138**Error codes** 139 140For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 141 142| ID| Error Message | 143| ------- | ---------------------------------------------------------------------------- | 144| 9200001 | The application is not an administrator application of the device. | 145| 9200002 | The administrator application does not have permission to manage the device. | 146| 201 | Permission verification failed. The application does not have the permission required to call the API. | 147| 202 | Permission verification failed. A non-system application calls a system API. | 148| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 149 150**Example** 151 152```ts 153import { Want } from '@kit.AbilityKit'; 154 155let wantTemp: Want = { 156 bundleName: 'com.example.myapplication', 157 abilityName: 'EntryAbility', 158}; 159 160deviceInfo.getDisplayVersion(wantTemp, (err, result) => { 161 if (err) { 162 console.error(`Failed to get display version. Code: ${err.code}, message: ${err.message}`); 163 return; 164 } 165 console.info(`Succeeded in getting display version, result : ${result}`); 166}); 167``` 168 169## deviceInfo.getDisplayVersion 170 171getDisplayVersion(admin: Want): Promise<string> 172 173Obtains the device version number. This API uses a promise to return the result. 174 175**Required permissions**: ohos.permission.ENTERPRISE_GET_DEVICE_INFO 176 177**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 178 179**Parameters** 180 181| Name | Type | Mandatory | Description | 182| ----- | ----------------------------------- | ---- | ------- | 183| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility.| 184 185**Return value** 186 187| Type | Description | 188| --------------------- | ------------------------- | 189| Promise<string> | Promise used to return the device version number.| 190 191**Error codes** 192 193For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 194 195| ID| Error Message | 196| ------- | ---------------------------------------------------------------------------- | 197| 9200001 | The application is not an administrator application of the device. | 198| 9200002 | The administrator application does not have permission to manage the device. | 199| 201 | Permission verification failed. The application does not have the permission required to call the API. | 200| 202 | Permission verification failed. A non-system application calls a system API. | 201| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 202 203**Example** 204 205```ts 206import { Want } from '@kit.AbilityKit'; 207import { BusinessError } from '@kit.BasicServicesKit'; 208 209let wantTemp: Want = { 210 bundleName: 'com.example.myapplication', 211 abilityName: 'EntryAbility', 212}; 213 214deviceInfo.getDisplayVersion(wantTemp).then((result) => { 215 console.info(`Succeeded in getting display version, result : ${result}`); 216}).catch((err: BusinessError) => { 217 console.error(`Failed to get display version. Code: ${err.code}, message: ${err.message}`); 218}); 219``` 220 221## deviceInfo.getDeviceName 222 223getDeviceName(admin: Want, callback: AsyncCallback<string>): void 224 225Obtains the device name. This API uses an asynchronous callback to return the result. 226 227**Required permissions**: ohos.permission.ENTERPRISE_GET_DEVICE_INFO 228 229**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 230 231**Parameters** 232 233| Name | Type | Mandatory | Description | 234| -------- | ---------------------------------------- | ---- | ------------------------------- | 235| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 236| callback | AsyncCallback<string> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the device name obtained. If the operation fails, **err** is an error object. | 237 238**Error codes** 239 240For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 241 242| ID| Error Message | 243| ------- | ---------------------------------------------------------------------------- | 244| 9200001 | The application is not an administrator application of the device. | 245| 9200002 | The administrator application does not have permission to manage the device. | 246| 201 | Permission verification failed. The application does not have the permission required to call the API. | 247| 202 | Permission verification failed. A non-system application calls a system API. | 248| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 249 250**Example** 251 252```ts 253import { Want } from '@kit.AbilityKit'; 254 255let wantTemp: Want = { 256 bundleName: 'com.example.myapplication', 257 abilityName: 'EntryAbility', 258}; 259 260deviceInfo.getDeviceName(wantTemp, (err, result) => { 261 if (err) { 262 console.error(`Failed to get device name. Code: ${err.code}, message: ${err.message}`); 263 return; 264 } 265 console.info(`Succeeded in getting device name, result : ${result}`); 266}); 267``` 268 269## deviceInfo.getDeviceName 270 271getDeviceName(admin: Want): Promise<string> 272 273Obtains the device name. This API uses a promise to return the result. 274 275**Required permissions**: ohos.permission.ENTERPRISE_GET_DEVICE_INFO 276 277**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 278 279**Parameters** 280 281| Name | Type | Mandatory | Description | 282| ----- | ----------------------------------- | ---- | ------- | 283| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility.| 284 285**Return value** 286 287| Type | Description | 288| --------------------- | ------------------------- | 289| Promise<string> | Promise used to return the device name.| 290 291**Error codes** 292 293For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 294 295| ID| Error Message | 296| ------- | ---------------------------------------------------------------------------- | 297| 9200001 | The application is not an administrator application of the device. | 298| 9200002 | The administrator application does not have permission to manage the device. | 299| 201 | Permission verification failed. The application does not have the permission required to call the API. | 300| 202 | Permission verification failed. A non-system application calls a system API. | 301| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 302 303**Example** 304 305```ts 306import { Want } from '@kit.AbilityKit'; 307import { BusinessError } from '@kit.BasicServicesKit'; 308 309let wantTemp: Want = { 310 bundleName: 'com.example.myapplication', 311 abilityName: 'EntryAbility', 312}; 313 314deviceInfo.getDeviceName(wantTemp).then((result) => { 315 console.info(`Succeeded in getting device name, result : ${result}`); 316}).catch((err: BusinessError) => { 317 console.error(`Failed to get device name. Code: ${err.code}, message: ${err.message}`); 318}); 319``` 320