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

huangapple 未分类评论61阅读模式
英文:

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

问题

我在Android 10上遇到了问题。当用户尝试授予“读取电话状态”权限时,我遇到了这个错误。我知道,谷歌现在限制了使用设备ID。另外,我已经阅读了所有关于这些更改的文档,我的问题是其他的。

首先,让我描述一下我如何使用设备ID以及为什么使用它。

在清单文件中:
```xml
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />

在Java代码中:

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;
}

现在,我知道我无法获取设备ID。以下是我的问题。

  1. 即使我从清单中删除了uses_permission行并删除了Java代码,我的应用程序仍然要求“电话状态”权限。为什么?
    以下是我的整个清单。
<?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-permission android:name="android.permission.READ_PHONE_STATE" />

    <application>
        <!-- 应用程序组件 -->
    </application>
</manifest>
  1. 以前,我曾使用设备ID来恢复游戏进度,这意味着我在我的数据库中有设备ID,并且在用户重新安装游戏后使用它们。现在,如果前面的问题得到解决,我该如何避免丢失用户的进度?我的意思是,如果我为用户获取另一个ID,那么它将不再与数据库中的ID相同。

谢谢大家。

=====编辑=====

这是我合并的清单文件的一部分的屏幕截图,我无法导航或删除它。

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

======编辑 2======

我找到了问题所在,我的一些库的minSDKversion小于4,这个权限会自动添加。


<details>
<summary>英文:</summary>

I have a problem with Android 10. I have I&#39;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. 
&lt;uses-permission android:name=&quot;android.permission.READ_PHONE_STATE&quot; /&gt;

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&#39;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" />

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

&lt;permission
    android:name=&quot;mypackagename.permission.C2D_MESSAGE&quot;
    android:protectionLevel=&quot;signature&quot; /&gt;
&lt;uses-permission android:name=&quot;mypackagename.permission.C2D_MESSAGE&quot; /&gt;

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

            &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
        &lt;/intent-filter&gt;
        &lt;intent-filter&gt;
            &lt;action android:name=&quot;android.intent.action.VIEW&quot; /&gt;
            &lt;category android:name=&quot;android.intent.category.DEFAULT&quot; /&gt;
            &lt;category android:name=&quot;android.intent.category.BROWSABLE&quot; /&gt;
            &lt;data android:scheme=&quot;@string/apps_flyer_deep_link&quot; /&gt;
        &lt;/intent-filter&gt;

    &lt;/activity&gt;

    &lt;activity
        android:name=&quot;com.ironsource.sdk.controller.ControllerActivity&quot;
        android:configChanges=&quot;orientation|screenSize&quot;
        android:hardwareAccelerated=&quot;true&quot; /&gt;
    &lt;activity
        android:name=&quot;com.ironsource.sdk.controller.InterstitialActivity&quot;
        android:configChanges=&quot;orientation|screenSize&quot;
        android:hardwareAccelerated=&quot;true&quot;
        android:theme=&quot;@android:style/Theme.Translucent&quot; /&gt;
    &lt;activity
        android:name=&quot;com.ironsource.sdk.controller.OpenUrlActivity&quot;
        android:configChanges=&quot;orientation|screenSize&quot;
        android:hardwareAccelerated=&quot;true&quot;
        android:theme=&quot;@android:style/Theme.Translucent&quot; /&gt;

    &lt;activity
        android:name=&quot;com.vungle.warren.ui.VungleActivity&quot;
        android:configChanges=&quot;keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize&quot;
        android:launchMode=&quot;singleTop&quot;
        android:theme=&quot;@android:style/Theme.NoTitleBar.Fullscreen&quot; /&gt;
    &lt;activity
        android:name=&quot;com.vungle.warren.ui.VungleFlexViewActivity&quot;
        android:configChanges=&quot;keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize&quot;
        android:hardwareAccelerated=&quot;true&quot;
        android:launchMode=&quot;singleTop&quot;
        android:theme=&quot;@android:style/Theme.Translucent.NoTitleBar&quot; /&gt;

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

    &lt;service
        android:name=&quot;mypackagename.notification.service.MyFirebaseMessagingService&quot;
        android:exported=&quot;false&quot;&gt;
        &lt;intent-filter&gt;
            &lt;action android:name=&quot;com.google.firebase.MESSAGING_EVENT&quot; /&gt;
        &lt;/intent-filter&gt;
    &lt;/service&gt;

    &lt;!--End of Google Push Notifications Stuff--&gt;

    &lt;meta-data
        android:name=&quot;com.google.android.gms.games.APP_ID&quot;
        android:value=&quot;@string/google_game_app_id&quot; /&gt;
    &lt;meta-data
        android:name=&quot;com.google.android.gms.appstate.APP_ID&quot;
        android:value=&quot;@string/google_game_app_id&quot; /&gt;

    &lt;meta-data
        android:name=&quot;com.google.android.gms.ads.APPLICATION_ID&quot;
        android:value=&quot;@string/ad_mob_app_id&quot; /&gt;

    &lt;meta-data
        android:name=&quot;applovin.sdk.key&quot;
        android:value=&quot;DpAUIPAz0TKP6geC6ifl0HJdoW6brFg23rXLFhJFAdeGJHTP_78_OScAzknpzSs0HNMW4fnEHQVahz_h48gTaI&quot; /&gt;

    &lt;!-- Facebook Stuff--&gt;

    &lt;meta-data
        android:name=&quot;com.facebook.sdk.ApplicationId&quot;
        android:value=&quot;@string/facebook_app_id&quot; /&gt;

    &lt;activity
        android:name=&quot;com.facebook.FacebookActivity&quot;
        android:configChanges=&quot;keyboard|keyboardHidden|screenLayout|screenSize|orientation&quot;
        android:label=&quot;@string/app_name&quot;
        android:theme=&quot;@android:style/Theme.Translucent.NoTitleBar&quot;
        tools:replace=&quot;android:theme&quot; /&gt;

    &lt;activity
        android:name=&quot;com.facebook.ads.AudienceNetworkActivity&quot;
        android:configChanges=&quot;keyboardHidden|orientation|screenSize&quot; /&gt;

    &lt;activity
        android:name=&quot;com.facebook.CustomTabActivity&quot;
        android:exported=&quot;true&quot;&gt;
        &lt;intent-filter&gt;
            &lt;action android:name=&quot;android.intent.action.VIEW&quot; /&gt;

            &lt;category android:name=&quot;android.intent.category.DEFAULT&quot; /&gt;
            &lt;category android:name=&quot;android.intent.category.BROWSABLE&quot; /&gt;

            &lt;data android:scheme=&quot;@string/fb_login_protocol_scheme&quot; /&gt;
        &lt;/intent-filter&gt;
    &lt;/activity&gt;
    &lt;!-- End of Facebook Stuff--&gt;


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

    &lt;!--Bugsnag Stuff--&gt;
    &lt;meta-data
        android:name=&quot;com.bugsnag.android.API_KEY&quot;
        android:value=&quot;8117a06b5900bdf6c3d33f8150131fbb&quot; /&gt;
    &lt;!--End of Bugsnag Stuff--&gt;

    &lt;!--Ad Stuff--&gt;
    &lt;activity
        android:name=&quot;com.adcolony.sdk.AdColonyInterstitialActivity&quot;
        android:configChanges=&quot;keyboardHidden|orientation|screenSize&quot;
        android:hardwareAccelerated=&quot;true&quot; /&gt;

    &lt;activity
        android:name=&quot;com.applovin.adview.AppLovinInterstitialActivity&quot;
        android:configChanges=&quot;orientation|screenSize&quot;/&gt;

    &lt;service android:name=&quot;.expansion.ExpansionFilesDownloaderService&quot; /&gt;

    &lt;receiver android:name=&quot;.expansion.DownloaderServiceBroadcastReceiver&quot; /&gt;
    &lt;receiver android:name=&quot;.notification.service.NotificationPublisher&quot; /&gt;
    &lt;!--End of Ad Stuff--&gt;

    &lt;receiver
        android:name=&quot;com.appsflyer.SingleInstallBroadcastReceiver&quot;
        android:exported=&quot;true&quot;&gt;
        &lt;intent-filter&gt;
            &lt;action android:name=&quot;com.android.vending.INSTALL_REFERRER&quot; /&gt;
        &lt;/intent-filter&gt;
    &lt;/receiver&gt;
&lt;/application&gt;

</manifest>


2. I used the device Id for the restoring the game progress before, so that means , that I have device id&#39;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&#39;t either navigate or remove it. 

[![Part of merged manifest, where the READ_PHONE_STATE is present][1]][1]


  [1]: https://i.stack.imgur.com/c1nGd.png


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

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

</details>


huangapple
  • 本文由 发表于 2020年4月9日 19:34:27
  • 转载请务必保留本文链接:https://java.coder-hub.com/61120235.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定