Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 60c80bb2 authored by Michael Groover's avatar Michael Groover
Browse files

Use Settings instead of DeviceConfig to relax device ID dev option

The 'Disable device identifier restrictions' developer option
currently uses DeviceConfig to set whether the new access
restrictions should be disabled. However this API now requires
the WRITE_DEVICE_CONFIG permission and should only be used from
the server side. This change modifies the developer option to use the
Settings to relax the device identifier check, and the option will
be hidden if the new restrictions have been disabled from the server.

Bug: 129888611
Test: Manually verified device ID check was relaxed with option
      enabled. Also verified option is not displayed if DeiviceConfig
      option is set.

Change-Id: Id8759f2219e702c1f93a638d45ac99bce685383b
parent 1dea3972
Loading
Loading
Loading
Loading
+35 −7
Original line number Original line Diff line number Diff line
@@ -16,8 +16,10 @@


package com.android.settings.development;
package com.android.settings.development;


import android.content.ContentResolver;
import android.content.Context;
import android.content.Context;
import android.provider.DeviceConfig;
import android.provider.DeviceConfig;
import android.provider.Settings;


import androidx.preference.Preference;
import androidx.preference.Preference;
import androidx.preference.SwitchPreference;
import androidx.preference.SwitchPreference;
@@ -32,8 +34,30 @@ public class DeviceIdentifierAccessRestrictionsPreferenceController
    private static final String DEVICE_IDENTIFIER_ACCESS_RESTRICTIONS_KEY =
    private static final String DEVICE_IDENTIFIER_ACCESS_RESTRICTIONS_KEY =
            "device_identifier_access_restrictions";
            "device_identifier_access_restrictions";


    // The settings that should be set when the new device identifier access restrictions are
    // disabled.
    private static final String[] RELAX_DEVICE_IDENTIFIER_CHECK_SETTINGS = {
            Settings.Global.PRIVILEGED_DEVICE_IDENTIFIER_3P_CHECK_RELAXED,
            Settings.Global.PRIVILEGED_DEVICE_IDENTIFIER_NON_PRIV_CHECK_RELAXED,
            Settings.Global.PRIVILEGED_DEVICE_IDENTIFIER_PRIV_CHECK_RELAXED
    };

    private ContentResolver mContentResolver;

    public DeviceIdentifierAccessRestrictionsPreferenceController(Context context) {
    public DeviceIdentifierAccessRestrictionsPreferenceController(Context context) {
        super(context);
        super(context);
        mContentResolver = context.getContentResolver();
    }

    @Override
    public boolean isAvailable() {
        // If the new access restrictions have been disabled from the server side then do not
        // display the option.
        boolean disabledFromServerSide = Boolean.parseBoolean(
                DeviceConfig.getProperty(DeviceConfig.Privacy.NAMESPACE,
                        DeviceConfig.Privacy.
                                PROPERTY_DEVICE_IDENTIFIER_ACCESS_RESTRICTIONS_DISABLED));
        return !disabledFromServerSide;
    }
    }


    @Override
    @Override
@@ -48,16 +72,20 @@ public class DeviceIdentifierAccessRestrictionsPreferenceController
    }
    }


    private void writeSetting(boolean isEnabled) {
    private void writeSetting(boolean isEnabled) {
        DeviceConfig.setProperty(DeviceConfig.Privacy.NAMESPACE,
        for (String relaxCheckSetting : RELAX_DEVICE_IDENTIFIER_CHECK_SETTINGS) {
                DeviceConfig.Privacy.PROPERTY_DEVICE_IDENTIFIER_ACCESS_RESTRICTIONS_DISABLED,
            Settings.Global.putInt(mContentResolver, relaxCheckSetting, isEnabled ? 1 : 0);
                String.valueOf(isEnabled), false);
        }
    }
    }


    @Override
    @Override
    public void updateState(Preference preference) {
    public void updateState(Preference preference) {
        boolean isEnabled = Boolean.parseBoolean(
        boolean isEnabled = true;
                DeviceConfig.getProperty(DeviceConfig.Privacy.NAMESPACE,
        for (String relaxCheckSetting : RELAX_DEVICE_IDENTIFIER_CHECK_SETTINGS) {
                        DeviceConfig.Privacy.PROPERTY_DEVICE_IDENTIFIER_ACCESS_RESTRICTIONS_DISABLED));
            if (Settings.Global.getInt(mContentResolver, relaxCheckSetting, 0) == 0) {
                isEnabled = false;
                break;
            }
        }
        ((SwitchPreference) mPreference).setChecked(isEnabled);
        ((SwitchPreference) mPreference).setChecked(isEnabled);
    }
    }


@@ -65,6 +93,6 @@ public class DeviceIdentifierAccessRestrictionsPreferenceController
    protected void onDeveloperOptionsSwitchDisabled() {
    protected void onDeveloperOptionsSwitchDisabled() {
        super.onDeveloperOptionsSwitchDisabled();
        super.onDeveloperOptionsSwitchDisabled();
        writeSetting(false);
        writeSetting(false);
        ((SwitchPreference) mPreference).setChecked(true);
        ((SwitchPreference) mPreference).setChecked(false);
    }
    }
}
}