VMS
VMS

Reputation: 139

Unique Identifier in Android Q

Android Q has restricted to access for both IMEI and serial no. It is available only for platform and apps with special carrier permission. Also the permission READ_PRIVILEGED_PHONE_STATE is not available for non platform apps.

Existing version(Android P, Android O, Android M) we have used the serial no for uniquely identified the device. Now we have faced the below Exception while tried to access the device identifier.

Android Q has restricted to access for both IMEI and serial no.

getSerial() in android.os.Build Class

06-21 12:37:07.460  1250  2555 W DevicePolicyManager: Package com.nagra.nmp.corepaktest (uid=10201, pid=32694) cannot access Device IDs
06-21 12:37:07.460  1250  2555 W TelephonyPermissions: reportAccessDeniedToReadIdentifiers:com.nagra.nmp.corepaktest:getSerial:isPreinstalled=false:isPrivApp=false
06-21 12:37:07.464 32694 32718 W System.err: java.lang.SecurityException: getSerial: The user 10201 does not meet the requirements to access device identifiers.
06-21 12:37:07.464 32694 32718 W System.err:    at android.os.Parcel.createException(Parcel.java:2069)
06-21 12:37:07.464 32694 32718 W System.err:    at android.os.Parcel.readException(Parcel.java:2037)
06-21 12:37:07.465 32694 32718 W System.err:    at android.os.Parcel.readException(Parcel.java:1986)
06-21 12:37:07.465 32694 32718 W System.err:    at android.os.IDeviceIdentifiersPolicyService$Stub$Proxy.getSerialForPackage(IDeviceIdentifiersPolicyService.java:159)
06-21 12:37:07.465 32694 32718 W System.err:    at android.os.Build.getSerial(Build.java:149)
06-21 12:37:07.465 32694 32718 W System.err:    at com.nagra.CppUnitForAndroid.TestBridge.start(Native Method)
06-21 12:37:07.466 32694 32718 W System.err:    at com.nagra.CppUnitForAndroid.TestWrapper.start(TestWrapper.java:111)
06-21 12:37:07.466 32694 32718 W System.err:    at com.nagra.CppUnitForAndroid.TestWrapper.access$200(TestWrapper.java:58)
06-21 12:37:07.466 32694 32718 W System.err:    at com.nagra.CppUnitForAndroid.TestWrapper$WrapperThread.run(TestWrapper.java:427)

getDeviceId() in android.telephony.TelephonyManager Class

06-21 12:37:07.472  1250  2555 W DevicePolicyManager: Package com.nagra.nmp.corepaktest (uid=10201, pid=32694) cannot access Device IDs
06-21 12:37:07.472  2744  2764 W TelephonyPermissions: reportAccessDeniedToReadIdentifiers:com.nagra.nmp.corepaktest:getDeviceId:isPreinstalled=false:isPrivApp=false
06-21 12:37:07.473 32694 32718 W System.err: java.lang.SecurityException: getDeviceId: The user 10201 does not meet the requirements to access device identifiers.
06-21 12:37:07.474 32694 32718 W System.err:    at android.os.Parcel.createException(Parcel.java:2069)
06-21 12:37:07.474 32694 32718 W System.err:    at android.os.Parcel.readException(Parcel.java:2037)
06-21 12:37:07.474 32694 32718 W System.err:    at android.os.Parcel.readException(Parcel.java:1986)
06-21 12:37:07.474 32694 32718 W System.err:    at com.android.internal.telephony.ITelephony$Stub$Proxy.getDeviceId(ITelephony.java:10278)
06-21 12:37:07.474 32694 32718 W System.err:    at android.telephony.TelephonyManager.getDeviceId(TelephonyManager.java:1565)
06-21 12:37:07.474 32694 32718 W System.err:    at com.nagra.CppUnitForAndroid.TestBridge.start(Native Method)
06-21 12:37:07.474 32694 32718 W System.err:    at com.nagra.CppUnitForAndroid.TestWrapper.start(TestWrapper.java:111)
06-21 12:37:07.474 32694 32718 W System.err:    at com.nagra.CppUnitForAndroid.TestWrapper.access$200(TestWrapper.java:58)
06-21 12:37:07.474 32694 32718 W System.err:    at com.nagra.CppUnitForAndroid.TestWrapper$WrapperThread.run(TestWrapper.java:427)

Which one(Property/API) used for Uniquely identify the device?

Upvotes: 5

Views: 9122

Answers (2)

Sdghasemi
Sdghasemi

Reputation: 5598

Since hardware ids are restricted, you can use an almost reliable software id like ANDROID_ID:

Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID)

I used almost since it can be changed on a rooted phone, but reliable on non-rooted devices.

Upvotes: 4

Vahid Amiri
Vahid Amiri

Reputation: 11117

Only system apps will have access to hardware IDs. If your app needs to identify unique instances of your app running on different devices, you should use an API such as Firebase InstanceID service but there are similar options available from different providers as well.

It's worth noting that Google discouraged using Hardware ID features even in older Android versions.

Upvotes: 0

Related Questions