title: Android 10: java.lang.SecurityException: getDeviceId: The user 10222 does not meet the requirements to access device identifiers
body: <p>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. </p>
  
  <p>Firstly, let me describe how and for what I used the device id. </p>
  
  <p>In the manifest. </p>
  
  <pre><code>    &lt;uses-permission android:name="android.permission.READ_PHONE_STATE" /&gt;
  </code></pre>
  
  <p>And in the Java code.</p>
  
  <pre><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;
      }
  </code></pre>
  
  <p>Now , I know that I can't get the device id.
  Here are my questions.</p>
  
  <p>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.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt;
  &lt;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"&gt;
      &lt;uses-feature android:glEsVersion="0x00020000" android:required="true" /&gt;
      &lt;supports-screens
          android:anyDensity="true"
          android:largeScreens="true"
          android:normalScreens="true"
          android:smallScreens="true"
          android:xlargeScreens="true" /&gt;
  
      &lt;uses-permission android:name="com.android.vending.CHECK_LICENSE" /&gt;
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&gt;
      &lt;uses-permission android:name="android.permission.READ_PHONE_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
      &lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.VIBRATE" /&gt;
      &lt;uses-permission android:name="com.android.vending.BILLING" /&gt;
      &lt;uses-permission android:name="org.onepf.openiab.permission.BILLING" /&gt;
      &lt;uses-permission android:name="com.sec.android.iap.permission.BILLING" /&gt;
      &lt;uses-permission android:name="com.nokia.payment.BILLING" /&gt;
      &lt;uses-permission android:name="com.slideme.sam.manager.inapp.permission.BILLING" /&gt;
  
      &lt;permission
          android:name="mypackagename.permission.C2D_MESSAGE"
          android:protectionLevel="signature" /&gt;
      &lt;uses-permission android:name="mypackagename.permission.C2D_MESSAGE" /&gt;
  
      &lt;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"&gt;
          &lt;activity
              android:name="mypackagename.MainActivity"
              android:configChanges="orientation|keyboardHidden|locale|screenSize"
              android:label="@string/app_name"
              android:screenOrientation="landscape"
              android:windowSoftInputMode="stateAlwaysHidden"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.VIEW" /&gt;
                  &lt;category android:name="android.intent.category.DEFAULT" /&gt;
                  &lt;category android:name="android.intent.category.BROWSABLE" /&gt;
                  &lt;data android:scheme="@string/apps_flyer_deep_link" /&gt;
              &lt;/intent-filter&gt;
  
          &lt;/activity&gt;
  
          &lt;activity
              android:name="com.ironsource.sdk.controller.ControllerActivity"
              android:configChanges="orientation|screenSize"
              android:hardwareAccelerated="true" /&gt;
          &lt;activity
              android:name="com.ironsource.sdk.controller.InterstitialActivity"
              android:configChanges="orientation|screenSize"
              android:hardwareAccelerated="true"
              android:theme="@android:style/Theme.Translucent" /&gt;
          &lt;activity
              android:name="com.ironsource.sdk.controller.OpenUrlActivity"
              android:configChanges="orientation|screenSize"
              android:hardwareAccelerated="true"
              android:theme="@android:style/Theme.Translucent" /&gt;
  
          &lt;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" /&gt;
          &lt;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" /&gt;
  
          &lt;!-- Amazon Payment Stuff --&gt;
          &lt;receiver
              android:name="com.amazon.device.iap.ResponseReceiver"
              tools:ignore="ExportedReceiver,InvalidPermission"&gt;
              &lt;intent-filter&gt;
                  &lt;action
                      android:name="com.amazon.inapp.purchasing.NOTIFY"
                      android:permission="com.amazon.inapp.purchasing.Permission.NOTIFY" /&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
          &lt;!--Google Push Notifications Stuff--&gt;
          &lt;meta-data
              android:name="com.google.android.gms.version"
              android:value="@integer/google_play_services_version" /&gt;
  
          &lt;service
              android:name="mypackagename.notification.service.MyFirebaseMessagingService"
              android:exported="false"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="com.google.firebase.MESSAGING_EVENT" /&gt;
              &lt;/intent-filter&gt;
          &lt;/service&gt;
  
          &lt;!--End of Google Push Notifications Stuff--&gt;
  
          &lt;meta-data
              android:name="com.google.android.gms.games.APP_ID"
              android:value="@string/google_game_app_id" /&gt;
          &lt;meta-data
              android:name="com.google.android.gms.appstate.APP_ID"
              android:value="@string/google_game_app_id" /&gt;
  
          &lt;meta-data
              android:name="com.google.android.gms.ads.APPLICATION_ID"
              android:value="@string/ad_mob_app_id" /&gt;
  
          &lt;meta-data
              android:name="applovin.sdk.key"
              android:value="DpAUIPAz0TKP6geC6ifl0HJdoW6brFg23rXLFhJFAdeGJHTP_78_OScAzknpzSs0HNMW4fnEHQVahz_h48gTaI" /&gt;
  
          &lt;!-- Facebook Stuff--&gt;
  
          &lt;meta-data
              android:name="com.facebook.sdk.ApplicationId"
              android:value="@string/facebook_app_id" /&gt;
  
          &lt;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" /&gt;
  
          &lt;activity
              android:name="com.facebook.ads.AudienceNetworkActivity"
              android:configChanges="keyboardHidden|orientation|screenSize" /&gt;
  
          &lt;activity
              android:name="com.facebook.CustomTabActivity"
              android:exported="true"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.VIEW" /&gt;
  
                  &lt;category android:name="android.intent.category.DEFAULT" /&gt;
                  &lt;category android:name="android.intent.category.BROWSABLE" /&gt;
  
                  &lt;data android:scheme="@string/fb_login_protocol_scheme" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;!-- End of Facebook Stuff--&gt;
  
  
          &lt;!-- Tapjoy Stuff--&gt;
          &lt;activity
              android:name="com.tapjoy.TJAdUnitActivity"
              android:configChanges="orientation|keyboardHidden"
              android:hardwareAccelerated="true"
              android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" /&gt;
          &lt;activity
              android:name="com.tapjoy.mraid.view.ActionHandler"
              android:configChanges="orientation|keyboardHidden" /&gt;
          &lt;activity
              android:name="com.tapjoy.mraid.view.Browser"
              android:configChanges="orientation|keyboardHidden" /&gt;
          &lt;!-- For SDK 11.3+ --&gt;
          &lt;activity
              android:name="com.tapjoy.TJContentActivity"
              android:configChanges="orientation|keyboardHidden"
              android:hardwareAccelerated="true"
              android:theme="@android:style/Theme.Translucent.NoTitleBar" /&gt;
          &lt;!--End of Tapjoy Stuff--&gt;
  
          &lt;!--Bugsnag Stuff--&gt;
          &lt;meta-data
              android:name="com.bugsnag.android.API_KEY"
              android:value="8117a06b5900bdf6c3d33f8150131fbb" /&gt;
          &lt;!--End of Bugsnag Stuff--&gt;
  
          &lt;!--Ad Stuff--&gt;
          &lt;activity
              android:name="com.adcolony.sdk.AdColonyInterstitialActivity"
              android:configChanges="keyboardHidden|orientation|screenSize"
              android:hardwareAccelerated="true" /&gt;
  
          &lt;activity
              android:name="com.applovin.adview.AppLovinInterstitialActivity"
              android:configChanges="orientation|screenSize"/&gt;
  
          &lt;service android:name=".expansion.ExpansionFilesDownloaderService" /&gt;
  
          &lt;receiver android:name=".expansion.DownloaderServiceBroadcastReceiver" /&gt;
          &lt;receiver android:name=".notification.service.NotificationPublisher" /&gt;
          &lt;!--End of Ad Stuff--&gt;
  
          &lt;receiver
              android:name="com.appsflyer.SingleInstallBroadcastReceiver"
              android:exported="true"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="com.android.vending.INSTALL_REFERRER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <ol start="2">
  <li>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. </li>
  </ol>
  
  <p>Thanks guys.</p>
  
  <p>=====EDIT=====</p>
  
  <p>Here is screenshot from my Merged Manifest file, and I can't either navigate or remove it. </p>
  
  <p><a href="https://i.stack.imgur.com/c1nGd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/c1nGd.png" alt="Part of merged manifest, where the READ_PHONE_STATE is present"></a></p>
  
  <p>======EDIT 2======</p>
  
  <p>I found it, some of my libs have minSDKversion &lt; 4, and this permission added automatically. </p>