Use shared model for non-system overlay toggle

Allows settings applications on other platforms to re-use values by
migrating to Settings.secure and moving HideNonSystemOverlayMixin to
SettingsLib.

Bug: 184967544
Test: atest SettingsUnitTests
Change-Id: If9aaeca29ebb8b481d75622934503e368d7435d3
This commit is contained in:
Alex Stetson
2021-05-05 08:49:15 -07:00
parent f9ebf6600f
commit aff80d1e14
12 changed files with 24 additions and 202 deletions

View File

@@ -16,8 +16,10 @@
package com.android.settings.development;
import static com.android.settingslib.core.lifecycle.HideNonSystemOverlayMixin.SECURE_OVERLAY_SETTINGS;
import android.content.Context;
import android.content.SharedPreferences;
import android.provider.Settings;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
@@ -33,7 +35,6 @@ import com.android.settingslib.development.DeveloperOptionsPreferenceController;
public class OverlaySettingsPreferenceController extends DeveloperOptionsPreferenceController
implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
public static final String SHARE_PERFS = "overlay_settings";
private static final String KEY_OVERLAY_SETTINGS = "overlay_settings";
public OverlaySettingsPreferenceController(Context context) {
@@ -64,10 +65,10 @@ public class OverlaySettingsPreferenceController extends DeveloperOptionsPrefere
/**
* Check if this setting is enabled or not.
*/
public static boolean isOverlaySettingsEnabled(Context context) {
final SharedPreferences editor = context.getSharedPreferences(SHARE_PERFS,
Context.MODE_PRIVATE);
return editor.getBoolean(SHARE_PERFS, false /* defValue */);
@VisibleForTesting
static boolean isOverlaySettingsEnabled(Context context) {
return Settings.Secure.getInt(context.getContentResolver(),
SECURE_OVERLAY_SETTINGS, 0 /* defValue */) != 0;
}
/**
@@ -75,9 +76,8 @@ public class OverlaySettingsPreferenceController extends DeveloperOptionsPrefere
*/
@VisibleForTesting
static void setOverlaySettingsEnabled(Context context, boolean enabled) {
final SharedPreferences editor = context.getSharedPreferences(SHARE_PERFS,
Context.MODE_PRIVATE);
editor.edit().putBoolean(SHARE_PERFS, enabled).apply();
Settings.Secure.putInt(context.getContentResolver(),
SECURE_OVERLAY_SETTINGS, enabled ? 1 : 0);
}
@Override