Remove development settings prefs file

Move DevelopmentSettingsEnabler to SettingsLib

Bug: 64159590
Test: DevelopmentSettingsEnablerTest
Change-Id: Id609266019e05a3e06b4ee3bc10de9c019628a42
This commit is contained in:
Tony Mantler
2017-07-31 10:48:55 -07:00
parent 3eb22656eb
commit 3d84d56336
8 changed files with 49 additions and 243 deletions

View File

@@ -98,6 +98,7 @@ import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import com.android.settingslib.RestrictedSwitchPreference;
import com.android.settingslib.development.AbstractEnableAdbPreferenceController;
import com.android.settingslib.development.DevelopmentSettingsEnabler;
import com.android.settingslib.drawer.CategoryKey;
import java.util.ArrayList;
@@ -113,11 +114,6 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
OnPreferenceChangeListener, SwitchBar.OnSwitchChangeListener, Indexable {
private static final String TAG = "DevelopmentSettings";
/**
* Preference file were development settings prefs are stored.
*/
public static final String PREF_FILE = "development";
/**
* Whether to show the development settings to the user. Default is false.
*/
@@ -353,7 +349,6 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
private boolean mLogpersistCleared;
private Dialog mLogpersistClearDialog;
private DashboardFeatureProvider mDashboardFeatureProvider;
private DevelopmentSettingsEnabler mSettingsEnabler;
private DevelopmentSwitchBarController mSwitchBarController;
private BugReportPreferenceController mBugReportController;
private BugReportInPowerPreferenceController mBugReportInPowerController;
@@ -374,7 +369,6 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
@Override
public void onAttach(Context context) {
super.onAttach(context);
mSettingsEnabler = new DevelopmentSettingsEnabler(context, getLifecycle());
mDashboardFeatureProvider = FeatureFactory.getFactory(context)
.getDashboardFeatureProvider(context);
}
@@ -681,18 +675,19 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
mDisabledPrefs.add(mKeepScreenOn);
}
final boolean lastEnabledState = mSettingsEnabler.getLastEnabledState();
mSwitchBar.setChecked(lastEnabledState);
setPrefsEnabledState(lastEnabledState);
final boolean developmentEnabledState =
DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(getContext());
mSwitchBar.setChecked(developmentEnabledState);
setPrefsEnabledState(developmentEnabledState);
if (mHaveDebugSettings && !lastEnabledState) {
if (mHaveDebugSettings && !developmentEnabledState) {
// Overall debugging is disabled, but there are some debug
// settings that are enabled. This is an invalid state. Switch
// to debug settings being enabled, so the user knows there is
// stuff enabled and can turn it all off if they want.
mSettingsEnabler.enableDevelopmentSettings();
mSwitchBar.setChecked(lastEnabledState);
setPrefsEnabledState(lastEnabledState);
DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(getContext(), true);
mSwitchBar.setChecked(true);
setPrefsEnabledState(true);
}
mSwitchBar.show();
@@ -1543,7 +1538,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|| currentValue.equals(SELECT_LOGD_OFF_SIZE_MARKER_VALUE)) {
writeLogpersistOption(null, true);
mLogpersist.setEnabled(false);
} else if (mSettingsEnabler.getLastEnabledState()) {
} else if (DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(getContext())) {
mLogpersist.setEnabled(true);
}
}
@@ -2359,8 +2354,9 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
if (switchView != mSwitchBar.getSwitch()) {
return;
}
final boolean lastEnabledState = mSettingsEnabler.getLastEnabledState();
if (isChecked != lastEnabledState) {
final boolean developmentEnabledState =
DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(getContext());
if (isChecked != developmentEnabledState) {
if (isChecked) {
mDialogClicked = false;
if (mEnableDialog != null) dismissDialogs();
@@ -2374,7 +2370,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
mEnableDialog.setOnDismissListener(this);
} else {
resetDangerousOptions();
mSettingsEnabler.disableDevelopmentSettings();
DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(getContext(), false);
setPrefsEnabledState(false);
}
}
@@ -2640,7 +2636,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
} else if (dialog == mEnableDialog) {
if (which == DialogInterface.BUTTON_POSITIVE) {
mDialogClicked = true;
mSettingsEnabler.enableDevelopmentSettings();
DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(getContext(), true);
setPrefsEnabledState(true);
} else {
// Reset the toggle
@@ -2759,10 +2755,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
@Override
protected boolean isPageSearchEnabled(Context context) {
return context.getSharedPreferences(DevelopmentSettings.PREF_FILE,
Context.MODE_PRIVATE).getBoolean(
DevelopmentSettings.PREF_SHOW,
android.os.Build.TYPE.equals("eng"));
return DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(context);
}
@Override

View File

@@ -1,77 +0,0 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.development;
import android.content.Context;
import android.content.SharedPreferences;
import android.provider.Settings;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnResume;
public class DevelopmentSettingsEnabler implements LifecycleObserver, OnResume {
private final Context mContext;
private final SharedPreferences mDevelopmentPreferences;
private boolean mLastEnabledState;
public DevelopmentSettingsEnabler(Context context, Lifecycle lifecycle) {
mContext = context;
mDevelopmentPreferences = context.getSharedPreferences(DevelopmentSettings.PREF_FILE,
Context.MODE_PRIVATE);
updateEnabledState();
if (lifecycle != null) {
lifecycle.addObserver(this);
}
}
@Override
public void onResume() {
updateEnabledState();
}
public static boolean enableDevelopmentSettings(Context context, SharedPreferences prefs) {
prefs.edit()
.putBoolean(DevelopmentSettings.PREF_SHOW, true)
.commit();
return Settings.Global.putInt(context.getContentResolver(),
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
}
private void updateEnabledState() {
mLastEnabledState = Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0;
}
public boolean getLastEnabledState() {
return mLastEnabledState;
}
public void enableDevelopmentSettings() {
mLastEnabledState = enableDevelopmentSettings(mContext, mDevelopmentPreferences);
}
public void disableDevelopmentSettings() {
mDevelopmentPreferences.edit()
.putBoolean(DevelopmentSettings.PREF_SHOW, false)
.commit();
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
mLastEnabledState = false;
}
}