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
(cherry picked from commit 60c80bb295
)
This commit is contained in:
@@ -16,8 +16,10 @@
|
||||
|
||||
package com.android.settings.development;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.provider.DeviceConfig;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.SwitchPreference;
|
||||
@@ -32,8 +34,30 @@ public class DeviceIdentifierAccessRestrictionsPreferenceController
|
||||
private static final String DEVICE_IDENTIFIER_ACCESS_RESTRICTIONS_KEY =
|
||||
"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) {
|
||||
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
|
||||
@@ -48,16 +72,20 @@ public class DeviceIdentifierAccessRestrictionsPreferenceController
|
||||
}
|
||||
|
||||
private void writeSetting(boolean isEnabled) {
|
||||
DeviceConfig.setProperty(DeviceConfig.Privacy.NAMESPACE,
|
||||
DeviceConfig.Privacy.PROPERTY_DEVICE_IDENTIFIER_ACCESS_RESTRICTIONS_DISABLED,
|
||||
String.valueOf(isEnabled), false);
|
||||
for (String relaxCheckSetting : RELAX_DEVICE_IDENTIFIER_CHECK_SETTINGS) {
|
||||
Settings.Global.putInt(mContentResolver, relaxCheckSetting, isEnabled ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
boolean isEnabled = Boolean.parseBoolean(
|
||||
DeviceConfig.getProperty(DeviceConfig.Privacy.NAMESPACE,
|
||||
DeviceConfig.Privacy.PROPERTY_DEVICE_IDENTIFIER_ACCESS_RESTRICTIONS_DISABLED));
|
||||
boolean isEnabled = true;
|
||||
for (String relaxCheckSetting : RELAX_DEVICE_IDENTIFIER_CHECK_SETTINGS) {
|
||||
if (Settings.Global.getInt(mContentResolver, relaxCheckSetting, 0) == 0) {
|
||||
isEnabled = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
((SwitchPreference) mPreference).setChecked(isEnabled);
|
||||
}
|
||||
|
||||
@@ -65,6 +93,6 @@ public class DeviceIdentifierAccessRestrictionsPreferenceController
|
||||
protected void onDeveloperOptionsSwitchDisabled() {
|
||||
super.onDeveloperOptionsSwitchDisabled();
|
||||
writeSetting(false);
|
||||
((SwitchPreference) mPreference).setChecked(true);
|
||||
((SwitchPreference) mPreference).setChecked(false);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user