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