Android 10: java .lang.SecurityException: getDeviceId: пользователь 10222 не соответствует требованиям для доступа к идентификаторам устройств. - PullRequest
1 голос
/ 09 апреля 2020

У меня проблема с Android 10. У меня появляется эта ошибка, когда пользователь пытается дать разрешение на чтение состояния телефона. Я знаю, что сейчас Google ограничивают использование идентификатора устройства. Кроме того, я прочитал всю документацию, касающуюся этих изменений, и мои вопросы другие.

Во-первых, позвольте мне описать, как и для чего я использовал идентификатор устройства.

В манифесте.

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

Теперь я знаю, что не могу получить идентификатор устройства. Вот мои вопросы.

1.Event Если я удаляю строку use_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-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>
Я использовал идентификатор устройства для восстановления прогресса игры, так что это означает, что у меня есть идентификаторы устройства в моей БД и я использую их, если пользователь переустанавливает игру. Теперь, если предыдущая проблема будет решена, как я могу избежать потери прогресса моих пользователей? Я имею в виду, если я получу другой идентификатор для пользователя, то он больше не будет таким же, как в БД.

Спасибо, ребята.

===== РЕДАКТИРОВАТЬ =====

Вот скриншот из моего файла Merged Manifest, и я тоже не могу перейдите или удалите его.

Part of merged manifest, where the READ_PHONE_STATE is present

====== РЕДАКТИРОВАТЬ 2 ======

Я нашел это, некоторые из моих библиотек имеют minSDKversion <4, и это разрешение добавляется автоматически. </p>

...