Android 10: java.lang.SecurityException: getDeviceId: The user 10222 does not meet the requirements to access device identifiers

Viewed 5388

I have a problem with Android 10. I have I'm getting this error when the user tries to give the Read Phone state permission. I know , that now Google restrict using the device id. Also , I have read all documentation regarding these changes, and my questions are other.

Firstly, let me describe how and for what I used the device id.

In the manifest.

    <uses-permission android:name="android.permission.READ_PHONE_STATE" />

And in the Java code.

 public String getDeviceId(boolean encrypt) {
        @SuppressLint("HardwareIds") String deviceId = android.provider.Settings.Secure.getString(activity.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
        String encryptedDeviceId = "";
        if (encrypt) {
            try {
                encryptedDeviceId = MCrypt.bytesToHex(MCrypt.$().encrypt(deviceId));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        return encryptedDeviceId;
    }

Now , I know that I can't get the device id. Here are my questions.

1.Event If I remove the uses_permission row in manifest and remove the java code, my app continues to want the Phone State permission. Why? Here is my whole manifest.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="myoackagenamehere"
    android:installLocation="preferExternal"
    android:versionCode="151"
    android:versionName="1.5.1">
    <uses-feature android:glEsVersion="0x00020000" android:required="true" />
    <supports-screens
        android:anyDensity="true"
        android:largeScreens="true"
        android:normalScreens="true"
        android:smallScreens="true"
        android:xlargeScreens="true" />

    <uses-permission android:name="com.android.vending.CHECK_LICENSE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="com.android.vending.BILLING" />
    <uses-permission android:name="org.onepf.openiab.permission.BILLING" />
    <uses-permission android:name="com.sec.android.iap.permission.BILLING" />
    <uses-permission android:name="com.nokia.payment.BILLING" />
    <uses-permission android:name="com.slideme.sam.manager.inapp.permission.BILLING" />

    <permission
        android:name="mypackagename.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission android:name="mypackagename.permission.C2D_MESSAGE" />

    <application
        android:name="androidx.multidex.MultiDexApplication"
        android:icon="@drawable/ic_launcher"
        android:roundIcon="@drawable/ic_launcher_round"
        android:label="@string/app_name"
        android:allowBackup="true"
        android:fullBackupContent="true"
        tools:replace="android:name,android:fullBackupContent"
        android:networkSecurityConfig="@xml/network_security_config"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
        <activity
            android:name="mypackagename.MainActivity"
            android:configChanges="orientation|keyboardHidden|locale|screenSize"
            android:label="@string/app_name"
            android:screenOrientation="landscape"
            android:windowSoftInputMode="stateAlwaysHidden">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="@string/apps_flyer_deep_link" />
            </intent-filter>

        </activity>

        <activity
            android:name="com.ironsource.sdk.controller.ControllerActivity"
            android:configChanges="orientation|screenSize"
            android:hardwareAccelerated="true" />
        <activity
            android:name="com.ironsource.sdk.controller.InterstitialActivity"
            android:configChanges="orientation|screenSize"
            android:hardwareAccelerated="true"
            android:theme="@android:style/Theme.Translucent" />
        <activity
            android:name="com.ironsource.sdk.controller.OpenUrlActivity"
            android:configChanges="orientation|screenSize"
            android:hardwareAccelerated="true"
            android:theme="@android:style/Theme.Translucent" />

        <activity
            android:name="com.vungle.warren.ui.VungleActivity"
            android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize"
            android:launchMode="singleTop"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />
        <activity
            android:name="com.vungle.warren.ui.VungleFlexViewActivity"
            android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize"
            android:hardwareAccelerated="true"
            android:launchMode="singleTop"
            android:theme="@android:style/Theme.Translucent.NoTitleBar" />

        <!-- Amazon Payment Stuff -->
        <receiver
            android:name="com.amazon.device.iap.ResponseReceiver"
            tools:ignore="ExportedReceiver,InvalidPermission">
            <intent-filter>
                <action
                    android:name="com.amazon.inapp.purchasing.NOTIFY"
                    android:permission="com.amazon.inapp.purchasing.Permission.NOTIFY" />
            </intent-filter>
        </receiver>
        <!--Google Push Notifications Stuff-->
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

        <service
            android:name="mypackagename.notification.service.MyFirebaseMessagingService"
            android:exported="false">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>

        <!--End of Google Push Notifications Stuff-->

        <meta-data
            android:name="com.google.android.gms.games.APP_ID"
            android:value="@string/google_game_app_id" />
        <meta-data
            android:name="com.google.android.gms.appstate.APP_ID"
            android:value="@string/google_game_app_id" />

        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="@string/ad_mob_app_id" />

        <meta-data
            android:name="applovin.sdk.key"
            android:value="DpAUIPAz0TKP6geC6ifl0HJdoW6brFg23rXLFhJFAdeGJHTP_78_OScAzknpzSs0HNMW4fnEHQVahz_h48gTaI" />

        <!-- Facebook Stuff-->

        <meta-data
            android:name="com.facebook.sdk.ApplicationId"
            android:value="@string/facebook_app_id" />

        <activity
            android:name="com.facebook.FacebookActivity"
            android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.Translucent.NoTitleBar"
            tools:replace="android:theme" />

        <activity
            android:name="com.facebook.ads.AudienceNetworkActivity"
            android:configChanges="keyboardHidden|orientation|screenSize" />

        <activity
            android:name="com.facebook.CustomTabActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data android:scheme="@string/fb_login_protocol_scheme" />
            </intent-filter>
        </activity>
        <!-- End of Facebook Stuff-->


        <!-- Tapjoy Stuff-->
        <activity
            android:name="com.tapjoy.TJAdUnitActivity"
            android:configChanges="orientation|keyboardHidden"
            android:hardwareAccelerated="true"
            android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
        <activity
            android:name="com.tapjoy.mraid.view.ActionHandler"
            android:configChanges="orientation|keyboardHidden" />
        <activity
            android:name="com.tapjoy.mraid.view.Browser"
            android:configChanges="orientation|keyboardHidden" />
        <!-- For SDK 11.3+ -->
        <activity
            android:name="com.tapjoy.TJContentActivity"
            android:configChanges="orientation|keyboardHidden"
            android:hardwareAccelerated="true"
            android:theme="@android:style/Theme.Translucent.NoTitleBar" />
        <!--End of Tapjoy Stuff-->

        <!--Bugsnag Stuff-->
        <meta-data
            android:name="com.bugsnag.android.API_KEY"
            android:value="8117a06b5900bdf6c3d33f8150131fbb" />
        <!--End of Bugsnag Stuff-->

        <!--Ad Stuff-->
        <activity
            android:name="com.adcolony.sdk.AdColonyInterstitialActivity"
            android:configChanges="keyboardHidden|orientation|screenSize"
            android:hardwareAccelerated="true" />

        <activity
            android:name="com.applovin.adview.AppLovinInterstitialActivity"
            android:configChanges="orientation|screenSize"/>

        <service android:name=".expansion.ExpansionFilesDownloaderService" />

        <receiver android:name=".expansion.DownloaderServiceBroadcastReceiver" />
        <receiver android:name=".notification.service.NotificationPublisher" />
        <!--End of Ad Stuff-->

        <receiver
            android:name="com.appsflyer.SingleInstallBroadcastReceiver"
            android:exported="true">
            <intent-filter>
                <action android:name="com.android.vending.INSTALL_REFERRER" />
            </intent-filter>
        </receiver>
    </application>

</manifest>
  1. I used the device Id for the restoring the game progress before, so that means , that I have device id's in my DB and use them , if user reinstall the game. Now , if the previous problem will be resolved, how can I avoid loosing my users progress? I mean if I will get another id for user , then it will no longer the same as in DB.

Thanks guys.

=====EDIT=====

Here is screenshot from my Merged Manifest file, and I can't either navigate or remove it.

Part of merged manifest, where the READ_PHONE_STATE is present

======EDIT 2======

I found it, some of my libs have minSDKversion < 4, and this permission added automatically.

0 Answers
Related