pbakondy / cordova-plugin-sim

:cherries: A cordova plugin to get the device's SIM data (carrier name, mcc mnc, country code, telephonenumber, etc)
MIT License
163 stars 100 forks source link

unable to fetch IMEI number on android 10 #91

Open Amal8906 opened 4 years ago

Amal8906 commented 4 years ago

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]

I am using

Hardware models

Example: Samsung Galaxy S6, iPhone 6s

OS versions

Example: Android 4.4.2, iOS 9.2

I've checked these

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.

faugusztin commented 4 years ago

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.

Amal8906 commented 4 years ago

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 commented 4 years ago

Native developer can access with the above code snippet.

faugusztin commented 4 years ago

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

eliadAfeka commented 4 years ago

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