# Device Information

# Interface Declaration

{ "name": "system.device" }

# Importing the Module

import device from '@system.device' 
// or 
const device = require('@system.device')

# Interface Definitions

# device.getInfo(OBJECT)

Obtains device information.

# Parameters:

Parameter Type Required Description
success Function No Success callback
fail Function No Failure callback
complete Function No Callback invoked when the execution is complete

# Return Value of success:

Parameter Type Description
brand string Device brand
manufacturer string Device manufacturer
model string Device model
product string Device code name
osType string Operating system name
osVersionName string Operating system version name
osVersionCode number Operating system version number
platformVersionName string Runtime platform version name
platformVersionCode number Runtime platform version number
language string System language
region string System region
APILevel2+ number Framework API version
screenWidth number Screen width
screenHeight number Screen height
screenDensity3+ number Screen density, that is, the device pixel ratio (DPR), which is the ratio of the device's physical pixels to logical pixels (DP). The calculation formula is: DPR = device PPI / 160, where PPI (pixels per inch) indicates the number of pixels per inch.
screenShape string Screen shape. The value can be: rect (rectangular screen), circle (circular screen), or pill-shaped3+ (capsule-shaped screen).
deviceType2+ string Device type. The value can be: watch, band, or smartspeaker.

# Example:

device.getInfo({
  success: function(ret) {
    console.log(`handling success, brand = ${ret.brand}`)
  }
})

# device.getDeviceId(OBJECT)

Obtains the unique device identifier.

# Permission Requirements

Obtaining device information

Developers need to configure the permission in manifest.json:

{
  "permissions": [
    { "name": "hapjs.permission.DEVICE_INFO" }
  ]
}

# Parameters:

Parameter Type Required Description
success Function No Success callback
fail Function No Failure callback
complete Function No Callback invoked when the execution is complete

# Return Value of success:

Parameter Type Description
deviceId String Unique device identifier

# Example:

device.getDeviceId({
  success: function (data) {
    console.log(`handling success: ${data.deviceId}`)
  },
  fail: function (data, code) {
    console.log(`handling fail, code = ${code}`)
  },
})

# device.getSerial(OBJECT)

Obtains the device serial number.

# Permission Requirements

Obtaining device information

Developers need to configure the permission in manifest.json:

{
  "permissions": [
    { "name": "hapjs.permission.DEVICE_INFO" }
  ]
}

# Parameters:

Parameter Type Required Description
success Function No Success callback
fail Function No Failure callback
complete Function No Callback invoked when the execution is complete

# Return Value of success:

Parameter Type Description
serial String Device serial number
device.getSerial({
    success: (data) => {
        console.log(`handling success: ${data.serial}`)
    },
    fail: (data, code) => {
        console.log(`handling fail, code = ${code}`)
    }
})

# device.getTotalStorage(OBJECT)

Obtains the total size of the storage space.

# Parameters:

Parameter Type Required Description
success Function No Success callback
fail Function No Failure callback
complete Function No Callback invoked when the execution is complete

# Return Value of success:

Parameter Type Description
totalStorage Number Total size of the storage space, in bytes
device.getTotalStorage({
    success: (data) => {
        console.log(`handling success: ${data.totalStorage}`)
    },
    fail: (data, code) => {
        console.log(`handling fail, code = ${code}`)
    }
})

# device.getAvailableStorage(OBJECT)

Obtains the available size of the storage space.

# Parameters:

Parameter Type Required Description
success Function No Success callback
fail Function No Failure callback
complete Function No Callback invoked when the execution is complete

# Return Value of success:

Parameter Type Description
availableStorage Number Available size of the storage space, in bytes
device.getAvailableStorage({
    success: (data) => {
        console.log(`handling success: ${data.availableStorage}`)
    },
    fail: (data, code) => {
        console.log(`handling fail, code = ${code}`)
    }
})