cordova-plugin-sim icon indicating copy to clipboard operation
cordova-plugin-sim copied to clipboard

unable to fetch IMEI number on android 10

Open Amal8906 opened this issue 4 years ago • 5 comments

Expected behaviour

Fetch IMEI number on android 10

Actual behaviour

IMEI number return null

I'm seeing this behaviour on

Remove this hint: these checkboxes can be checked like this: [x]

  • [ ] iOS device
  • [ ] iOS simulator
  • [ x] Android device
  • [ ] Android emulator

I am using

  • [x ] cordova
  • [ x] ionic
  • [ ] PhoneGap
  • [ ] PhoneGap Developer App
  • [ ] Intel XDK
  • [ ] Intel App Preview
  • [ ] Telerik
  • [ ] Other:

Hardware models

Example: Samsung Galaxy S6, iPhone 6s

OS versions

Example: Android 4.4.2, iOS 9.2

I've checked these

  • [ ] It happens on a fresh Cordova CLI project as well.
  • [ ] I'm waiting for deviceready to fire.
  • [ ] My JavaScript has no errors (window.onerror catches nothing).
  • [x ] I'm using the latest cordova library, Android SDK, Xcode, etc.

So how can we reproduce this?

Provide the used components versions (cordova, ionic, etc).

Provide the steps to reproduce the issue.

Provide files, sources if available.

Amal8906 avatar Aug 26 '20 17:08 Amal8906

That is an OS limitation, nothing can be done about it : https://developer.android.com/about/versions/10/privacy/changes#non-resettable-device-ids

Restriction on non-resettable device identifiers Starting in Android 10, apps must have the READ_PRIVILEGED_PHONE_STATE privileged permission in order to access the device's non-resettable identifiers, which include both IMEI and serial number. Caution: Third-party apps installed from the Google Play Store cannot declare privileged permissions.

If your app doesn't have the permission and you try asking for information about non-resettable identifiers anyway, the platform's response varies based on target SDK version: If your app targets Android 10 or higher, a SecurityException occurs. If your app targets Android 9 (API level 28) or lower, the method returns null or placeholder data if the app has the READ_PHONE_STATE permission. Otherwise, a SecurityException occurs.

faugusztin avatar Aug 26 '20 17:08 faugusztin

In Android 10 IEMI No is encrypted with Android App Id.

try {

if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
    deviceId = Settings.Secure.getString(
            getContentResolver(),
            Settings.Secure.ANDROID_ID);
} else {
    final TelephonyManager mTelephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    if (ActivityCompat.checkSelfPermission(this, permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
        // TODO: Consider calling
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
        return;
    }
    if (mTelephony.getDeviceId() != null) {
        deviceId = mTelephony.getDeviceId();
    } else {
        deviceId = Settings.Secure.getString(
                getContentResolver(),
                Settings.Secure.ANDROID_ID);
    }
}

} catch (Exception ex) {

String erro = ex.getMessage();

}

Amal8906 avatar Aug 27 '20 09:08 Amal8906

Native developer can access with the above code snippet.

Amal8906 avatar Aug 27 '20 09:08 Amal8906

Settings.Secure.ANDROID_ID is not IMEI. It is a unique ID, but not IMEI. https://developer.android.com/reference/android/provider/Settings.Secure#ANDROID_ID

On Android 8.0 (API level 26) and higher versions of the platform, a 64-bit number (expressed as a hexadecimal string), unique to each combination of app-signing key, user, and device.

Also the value of ANDROID_ID is available via cordova-plugin-device in the device.uuid value, there is no point in duplicating functionality. Relevant line of cordova-plugin-device : https://github.com/apache/cordova-plugin-device/blob/master/src/android/Device.java#L111

faugusztin avatar Aug 30 '20 09:08 faugusztin

is there going to be updated soon ? at the moment the plugin cannot work in android 10

eliadAfeka avatar Sep 11 '20 18:09 eliadAfeka