cmsdk: cmhw: Add UniqueDeviceId support

It's sometimes useful to know what physical device you're using.

CMHW SerialNumber and an "ro.serialno" property already exists, but
are not guaranteed to be unique. Different OEM may use overlapping
numbering schemes, and sometimes placeholder like "012345ABCDE" are
used.

Attempt to work around these shortcomings by defining a new
UniqueDeviceId class that provides a globally unique device ID that
is both deterministic for a given device and designed not to overlap
with IDs of any other devices.

Change-Id: I3f426972558394ba8e78261273ac8521aa603327
This commit is contained in:
Matt Wagantall 2016-02-02 11:32:18 -08:00 committed by Gerrit Code Review
parent ee703e74fa
commit eb82dbf050
6 changed files with 66 additions and 3 deletions

View File

@ -420,6 +420,7 @@ package cyanogenmod.hardware {
method public java.lang.String getSerialNumber();
method public int getSupportedFeatures();
method public int getThermalState();
method public java.lang.String getUniqueDeviceId();
method public int getVibratorDefaultIntensity();
method public int getVibratorIntensity();
method public int getVibratorMaxIntensity();
@ -456,6 +457,7 @@ package cyanogenmod.hardware {
field public static final int FEATURE_TAP_TO_WAKE = 512; // 0x200
field public static final int FEATURE_THERMAL_MONITOR = 32768; // 0x8000
field public static final int FEATURE_TOUCH_HOVERING = 2048; // 0x800
field public static final int FEATURE_UNIQUE_DEVICE_ID = 65536; // 0x10000
field public static final int FEATURE_VIBRATOR = 1024; // 0x400
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 The CyanogenMod Project
* Copyright (C) 2015-2016 The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -50,6 +50,7 @@ import org.cyanogenmod.hardware.TapToWake;
import org.cyanogenmod.hardware.ThermalMonitor;
import org.cyanogenmod.hardware.ThermalUpdateCallback;
import org.cyanogenmod.hardware.TouchscreenHovering;
import org.cyanogenmod.hardware.UniqueDeviceId;
import org.cyanogenmod.hardware.VibratorHW;
/** @hide */
@ -83,6 +84,7 @@ public class CMHardwareService extends SystemService implements ThermalUpdateCal
public long getLtoDownloadInterval();
public String getSerialNumber();
public String getUniqueDeviceId();
public boolean requireAdaptiveBacklightForSunlightEnhancement();
public boolean isSunlightEnhancementSelfManaged();
@ -133,6 +135,8 @@ public class CMHardwareService extends SystemService implements ThermalUpdateCal
mSupportedFeatures |= CMHardwareManager.FEATURE_PERSISTENT_STORAGE;
if (ThermalMonitor.isSupported())
mSupportedFeatures |= CMHardwareManager.FEATURE_THERMAL_MONITOR;
if (UniqueDeviceId.isSupported())
mSupportedFeatures |= CMHardwareManager.FEATURE_UNIQUE_DEVICE_ID;
}
public int getSupportedFeatures() {
@ -295,6 +299,10 @@ public class CMHardwareService extends SystemService implements ThermalUpdateCal
return SerialNumber.getSerialNumber();
}
public String getUniqueDeviceId() {
return UniqueDeviceId.getUniqueDeviceId();
}
public boolean requireAdaptiveBacklightForSunlightEnhancement() {
return SunlightEnhancement.isAdaptiveBacklightRequired();
}
@ -523,6 +531,17 @@ public class CMHardwareService extends SystemService implements ThermalUpdateCal
return mCmHwImpl.getSerialNumber();
}
@Override
public String getUniqueDeviceId() {
mContext.enforceCallingOrSelfPermission(
cyanogenmod.platform.Manifest.permission.HARDWARE_ABSTRACTION_ACCESS, null);
if (!isSupported(CMHardwareManager.FEATURE_UNIQUE_DEVICE_ID)) {
Log.e(TAG, "Unique device ID is not supported");
return null;
}
return mCmHwImpl.getUniqueDeviceId();
}
@Override
public boolean requireAdaptiveBacklightForSunlightEnhancement() {
mContext.enforceCallingOrSelfPermission(

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 The CyanogenMod Project
* Copyright (C) 2015-2016 The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -124,6 +124,11 @@ public final class CMHardwareManager {
*/
public static final int FEATURE_THERMAL_MONITOR = 0x8000;
/**
* Unique device ID
*/
public static final int FEATURE_UNIQUE_DEVICE_ID = 0x10000;
private static final List<Integer> BOOLEAN_FEATURES = Arrays.asList(
FEATURE_ADAPTIVE_BACKLIGHT,
FEATURE_COLOR_ENHANCEMENT,
@ -699,6 +704,19 @@ public final class CMHardwareManager {
return null;
}
/**
* @return an id that's both unique and deterministic for the device
*/
public String getUniqueDeviceId() {
try {
if (checkService()) {
return sService.getUniqueDeviceId();
}
} catch (RemoteException e) {
}
return null;
}
/**
* @return true if adaptive backlight should be enabled when sunlight enhancement
* is enabled.

View File

@ -56,4 +56,6 @@ interface ICMHardwareService {
boolean registerThermalListener(IThermalListenerCallback callback);
boolean unRegisterThermalListener(IThermalListenerCallback callback);
boolean isSunlightEnhancementSelfManaged();
String getUniqueDeviceId();
}

View File

@ -420,6 +420,7 @@ package cyanogenmod.hardware {
method public java.lang.String getSerialNumber();
method public int getSupportedFeatures();
method public int getThermalState();
method public java.lang.String getUniqueDeviceId();
method public int getVibratorDefaultIntensity();
method public int getVibratorIntensity();
method public int getVibratorMaxIntensity();
@ -456,6 +457,7 @@ package cyanogenmod.hardware {
field public static final int FEATURE_TAP_TO_WAKE = 512; // 0x200
field public static final int FEATURE_THERMAL_MONITOR = 32768; // 0x8000
field public static final int FEATURE_TOUCH_HOVERING = 2048; // 0x800
field public static final int FEATURE_UNIQUE_DEVICE_ID = 65536; // 0x10000
field public static final int FEATURE_VIBRATOR = 1024; // 0x400
}

View File

@ -1,5 +1,5 @@
/**
* Copyright (c) 2015, The CyanogenMod Project
* Copyright (c) 2015-2016, The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -118,6 +118,16 @@ public class CMHardwareTest extends TestActivity {
}
}
private boolean uniqueDeviceIdSupported() {
if (mHardwareManager.isSupported(CMHardwareManager.FEATURE_UNIQUE_DEVICE_ID)) {
return true;
} else {
Toast.makeText(CMHardwareTest.this, "Unique device ID not supported",
Toast.LENGTH_SHORT).show();
return false;
}
}
private boolean displayModesSupported() {
if (mHardwareManager.isSupported(CMHardwareManager.FEATURE_DISPLAY_MODES)) {
return true;
@ -312,6 +322,16 @@ public class CMHardwareTest extends TestActivity {
}
}
},
new Test("Test Get Unique Device ID") {
@Override
protected void run() {
if (uniqueDeviceIdSupported()) {
Toast.makeText(CMHardwareTest.this, "Unique Device ID " +
mHardwareManager.getUniqueDeviceId(),
Toast.LENGTH_SHORT).show();
}
}
},
new Test("Test Get Display Modes") {
@Override
protected void run() {