Remove development settings prefs file
Move DevelopmentSettingsEnabler to SettingsLib Bug: 64159590 Test: DevelopmentSettingsEnablerTest Change-Id: Id609266019e05a3e06b4ee3bc10de9c019628a42
This commit is contained in:
@@ -39,6 +39,7 @@ import android.os.UserHandle;
|
|||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.support.annotation.VisibleForTesting;
|
import android.support.annotation.VisibleForTesting;
|
||||||
import android.support.v14.preference.PreferenceFragment;
|
import android.support.v14.preference.PreferenceFragment;
|
||||||
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.support.v7.preference.PreferenceManager;
|
import android.support.v7.preference.PreferenceManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@@ -63,6 +64,7 @@ import com.android.settings.search.DynamicIndexableContentMonitor;
|
|||||||
import com.android.settings.search.SearchActivity;
|
import com.android.settings.search.SearchActivity;
|
||||||
import com.android.settings.wfd.WifiDisplaySettings;
|
import com.android.settings.wfd.WifiDisplaySettings;
|
||||||
import com.android.settings.widget.SwitchBar;
|
import com.android.settings.widget.SwitchBar;
|
||||||
|
import com.android.settingslib.development.DevelopmentSettingsEnabler;
|
||||||
import com.android.settingslib.drawer.DashboardCategory;
|
import com.android.settingslib.drawer.DashboardCategory;
|
||||||
import com.android.settingslib.drawer.SettingsDrawerActivity;
|
import com.android.settingslib.drawer.SettingsDrawerActivity;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -164,8 +166,7 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
"android.settings.APPLICATION_DETAILS_SETTINGS"
|
"android.settings.APPLICATION_DETAILS_SETTINGS"
|
||||||
};
|
};
|
||||||
|
|
||||||
private SharedPreferences mDevelopmentPreferences;
|
private BroadcastReceiver mDevelopmentSettingsListener;
|
||||||
private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
|
|
||||||
|
|
||||||
private boolean mBatteryPresent = true;
|
private boolean mBatteryPresent = true;
|
||||||
private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
|
private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
|
||||||
@@ -274,9 +275,6 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
|
getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
|
|
||||||
Context.MODE_PRIVATE);
|
|
||||||
|
|
||||||
// Getting Intent properties can only be done after the super.onCreate(...)
|
// Getting Intent properties can only be done after the super.onCreate(...)
|
||||||
final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
|
final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
|
||||||
|
|
||||||
@@ -530,9 +528,14 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
mDevelopmentPreferencesListener = (sharedPreferences, key) -> updateTilesList();
|
mDevelopmentSettingsListener = new BroadcastReceiver() {
|
||||||
mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
|
@Override
|
||||||
mDevelopmentPreferencesListener);
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
updateTilesList();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
LocalBroadcastManager.getInstance(this).registerReceiver(mDevelopmentSettingsListener,
|
||||||
|
new IntentFilter(DevelopmentSettingsEnabler.DEVELOPMENT_SETTINGS_CHANGED_ACTION));
|
||||||
|
|
||||||
registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
||||||
if (mDynamicIndexableContentMonitor == null) {
|
if (mDynamicIndexableContentMonitor == null) {
|
||||||
@@ -546,9 +549,8 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
|
LocalBroadcastManager.getInstance(this).unregisterReceiver(mDevelopmentSettingsListener);
|
||||||
mDevelopmentPreferencesListener);
|
mDevelopmentSettingsListener = null;
|
||||||
mDevelopmentPreferencesListener = null;
|
|
||||||
unregisterReceiver(mBatteryInfoReceiver);
|
unregisterReceiver(mBatteryInfoReceiver);
|
||||||
if (mDynamicIndexableContentMonitor != null) {
|
if (mDynamicIndexableContentMonitor != null) {
|
||||||
mDynamicIndexableContentMonitor.unregister(this, LOADER_ID_INDEXABLE_CONTENT_MONITOR);
|
mDynamicIndexableContentMonitor.unregister(this, LOADER_ID_INDEXABLE_CONTENT_MONITOR);
|
||||||
@@ -839,8 +841,7 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin)
|
pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin)
|
||||||
|| somethingChanged;
|
|| somethingChanged;
|
||||||
|
|
||||||
final boolean showDev = mDevelopmentPreferences.getBoolean(
|
final boolean showDev = DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(this)
|
||||||
DevelopmentSettings.PREF_SHOW, android.os.Build.TYPE.equals("eng"))
|
|
||||||
&& !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES);
|
&& !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES);
|
||||||
somethingChanged = setTileEnabled(new ComponentName(packageName,
|
somethingChanged = setTileEnabled(new ComponentName(packageName,
|
||||||
Settings.DevelopmentSettingsActivity.class.getName()),
|
Settings.DevelopmentSettingsActivity.class.getName()),
|
||||||
|
@@ -86,7 +86,6 @@ import com.android.settings.applications.instantapps.InstantAppButtonsController
|
|||||||
import com.android.settings.datausage.AppDataUsage;
|
import com.android.settings.datausage.AppDataUsage;
|
||||||
import com.android.settings.datausage.DataUsageList;
|
import com.android.settings.datausage.DataUsageList;
|
||||||
import com.android.settings.datausage.DataUsageUtils;
|
import com.android.settings.datausage.DataUsageUtils;
|
||||||
import com.android.settings.development.DevelopmentSettingsEnabler;
|
|
||||||
import com.android.settings.fuelgauge.AdvancedPowerUsageDetail;
|
import com.android.settings.fuelgauge.AdvancedPowerUsageDetail;
|
||||||
import com.android.settings.fuelgauge.BatteryEntry;
|
import com.android.settings.fuelgauge.BatteryEntry;
|
||||||
import com.android.settings.fuelgauge.BatteryStatsHelperLoader;
|
import com.android.settings.fuelgauge.BatteryStatsHelperLoader;
|
||||||
@@ -104,6 +103,7 @@ import com.android.settingslib.applications.PermissionsSummaryHelper;
|
|||||||
import com.android.settingslib.applications.PermissionsSummaryHelper.PermissionsResultCallback;
|
import com.android.settingslib.applications.PermissionsSummaryHelper.PermissionsResultCallback;
|
||||||
import com.android.settingslib.applications.StorageStatsSource;
|
import com.android.settingslib.applications.StorageStatsSource;
|
||||||
import com.android.settingslib.applications.StorageStatsSource.AppStorageStats;
|
import com.android.settingslib.applications.StorageStatsSource.AppStorageStats;
|
||||||
|
import com.android.settingslib.development.DevelopmentSettingsEnabler;
|
||||||
import com.android.settingslib.net.ChartData;
|
import com.android.settingslib.net.ChartData;
|
||||||
import com.android.settingslib.net.ChartDataLoader;
|
import com.android.settingslib.net.ChartDataLoader;
|
||||||
|
|
||||||
@@ -178,7 +178,6 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
private Preference mMemoryPreference;
|
private Preference mMemoryPreference;
|
||||||
private Preference mVersionPreference;
|
private Preference mVersionPreference;
|
||||||
private AppDomainsPreference mInstantAppDomainsPreference;
|
private AppDomainsPreference mInstantAppDomainsPreference;
|
||||||
private DevelopmentSettingsEnabler mDevelopmentSettingsEnabler;
|
|
||||||
private boolean mDisableAfterUninstall;
|
private boolean mDisableAfterUninstall;
|
||||||
|
|
||||||
// Used for updating notification preference.
|
// Used for updating notification preference.
|
||||||
@@ -392,8 +391,6 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
removePreference(KEY_DATA);
|
removePreference(KEY_DATA);
|
||||||
}
|
}
|
||||||
mBatteryUtils = BatteryUtils.getInstance(getContext());
|
mBatteryUtils = BatteryUtils.getInstance(getContext());
|
||||||
mDevelopmentSettingsEnabler = new DevelopmentSettingsEnabler(
|
|
||||||
activity, null /* lifecycle */);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -417,7 +414,7 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
loaderManager.restartLoader(LOADER_STORAGE, Bundle.EMPTY, this);
|
loaderManager.restartLoader(LOADER_STORAGE, Bundle.EMPTY, this);
|
||||||
}
|
}
|
||||||
restartBatteryStatsLoader();
|
restartBatteryStatsLoader();
|
||||||
if (mDevelopmentSettingsEnabler.getLastEnabledState()) {
|
if (DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(getContext())) {
|
||||||
new MemoryUpdater().execute();
|
new MemoryUpdater().execute();
|
||||||
}
|
}
|
||||||
updateDynamicPrefs();
|
updateDynamicPrefs();
|
||||||
@@ -473,7 +470,8 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
mBatteryPreference.setOnPreferenceClickListener(this);
|
mBatteryPreference.setOnPreferenceClickListener(this);
|
||||||
mMemoryPreference = findPreference(KEY_MEMORY);
|
mMemoryPreference = findPreference(KEY_MEMORY);
|
||||||
mMemoryPreference.setOnPreferenceClickListener(this);
|
mMemoryPreference.setOnPreferenceClickListener(this);
|
||||||
mMemoryPreference.setVisible(mDevelopmentSettingsEnabler.getLastEnabledState());
|
mMemoryPreference.setVisible(
|
||||||
|
DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(getContext()));
|
||||||
mVersionPreference = findPreference(KEY_VERSION);
|
mVersionPreference = findPreference(KEY_VERSION);
|
||||||
mInstantAppDomainsPreference =
|
mInstantAppDomainsPreference =
|
||||||
(AppDomainsPreference) findPreference(KEY_INSTANT_APP_SUPPORTED_LINKS);
|
(AppDomainsPreference) findPreference(KEY_INSTANT_APP_SUPPORTED_LINKS);
|
||||||
|
@@ -98,6 +98,7 @@ import com.android.settingslib.RestrictedLockUtils;
|
|||||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||||
import com.android.settingslib.RestrictedSwitchPreference;
|
import com.android.settingslib.RestrictedSwitchPreference;
|
||||||
import com.android.settingslib.development.AbstractEnableAdbPreferenceController;
|
import com.android.settingslib.development.AbstractEnableAdbPreferenceController;
|
||||||
|
import com.android.settingslib.development.DevelopmentSettingsEnabler;
|
||||||
import com.android.settingslib.drawer.CategoryKey;
|
import com.android.settingslib.drawer.CategoryKey;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -113,11 +114,6 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
|||||||
OnPreferenceChangeListener, SwitchBar.OnSwitchChangeListener, Indexable {
|
OnPreferenceChangeListener, SwitchBar.OnSwitchChangeListener, Indexable {
|
||||||
private static final String TAG = "DevelopmentSettings";
|
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.
|
* 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 boolean mLogpersistCleared;
|
||||||
private Dialog mLogpersistClearDialog;
|
private Dialog mLogpersistClearDialog;
|
||||||
private DashboardFeatureProvider mDashboardFeatureProvider;
|
private DashboardFeatureProvider mDashboardFeatureProvider;
|
||||||
private DevelopmentSettingsEnabler mSettingsEnabler;
|
|
||||||
private DevelopmentSwitchBarController mSwitchBarController;
|
private DevelopmentSwitchBarController mSwitchBarController;
|
||||||
private BugReportPreferenceController mBugReportController;
|
private BugReportPreferenceController mBugReportController;
|
||||||
private BugReportInPowerPreferenceController mBugReportInPowerController;
|
private BugReportInPowerPreferenceController mBugReportInPowerController;
|
||||||
@@ -374,7 +369,6 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
|||||||
@Override
|
@Override
|
||||||
public void onAttach(Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
mSettingsEnabler = new DevelopmentSettingsEnabler(context, getLifecycle());
|
|
||||||
mDashboardFeatureProvider = FeatureFactory.getFactory(context)
|
mDashboardFeatureProvider = FeatureFactory.getFactory(context)
|
||||||
.getDashboardFeatureProvider(context);
|
.getDashboardFeatureProvider(context);
|
||||||
}
|
}
|
||||||
@@ -681,18 +675,19 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
|||||||
mDisabledPrefs.add(mKeepScreenOn);
|
mDisabledPrefs.add(mKeepScreenOn);
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean lastEnabledState = mSettingsEnabler.getLastEnabledState();
|
final boolean developmentEnabledState =
|
||||||
mSwitchBar.setChecked(lastEnabledState);
|
DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(getContext());
|
||||||
setPrefsEnabledState(lastEnabledState);
|
mSwitchBar.setChecked(developmentEnabledState);
|
||||||
|
setPrefsEnabledState(developmentEnabledState);
|
||||||
|
|
||||||
if (mHaveDebugSettings && !lastEnabledState) {
|
if (mHaveDebugSettings && !developmentEnabledState) {
|
||||||
// Overall debugging is disabled, but there are some debug
|
// Overall debugging is disabled, but there are some debug
|
||||||
// settings that are enabled. This is an invalid state. Switch
|
// settings that are enabled. This is an invalid state. Switch
|
||||||
// to debug settings being enabled, so the user knows there is
|
// to debug settings being enabled, so the user knows there is
|
||||||
// stuff enabled and can turn it all off if they want.
|
// stuff enabled and can turn it all off if they want.
|
||||||
mSettingsEnabler.enableDevelopmentSettings();
|
DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(getContext(), true);
|
||||||
mSwitchBar.setChecked(lastEnabledState);
|
mSwitchBar.setChecked(true);
|
||||||
setPrefsEnabledState(lastEnabledState);
|
setPrefsEnabledState(true);
|
||||||
}
|
}
|
||||||
mSwitchBar.show();
|
mSwitchBar.show();
|
||||||
|
|
||||||
@@ -1543,7 +1538,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
|||||||
|| currentValue.equals(SELECT_LOGD_OFF_SIZE_MARKER_VALUE)) {
|
|| currentValue.equals(SELECT_LOGD_OFF_SIZE_MARKER_VALUE)) {
|
||||||
writeLogpersistOption(null, true);
|
writeLogpersistOption(null, true);
|
||||||
mLogpersist.setEnabled(false);
|
mLogpersist.setEnabled(false);
|
||||||
} else if (mSettingsEnabler.getLastEnabledState()) {
|
} else if (DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(getContext())) {
|
||||||
mLogpersist.setEnabled(true);
|
mLogpersist.setEnabled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2359,8 +2354,9 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
|||||||
if (switchView != mSwitchBar.getSwitch()) {
|
if (switchView != mSwitchBar.getSwitch()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final boolean lastEnabledState = mSettingsEnabler.getLastEnabledState();
|
final boolean developmentEnabledState =
|
||||||
if (isChecked != lastEnabledState) {
|
DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(getContext());
|
||||||
|
if (isChecked != developmentEnabledState) {
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
mDialogClicked = false;
|
mDialogClicked = false;
|
||||||
if (mEnableDialog != null) dismissDialogs();
|
if (mEnableDialog != null) dismissDialogs();
|
||||||
@@ -2374,7 +2370,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
|||||||
mEnableDialog.setOnDismissListener(this);
|
mEnableDialog.setOnDismissListener(this);
|
||||||
} else {
|
} else {
|
||||||
resetDangerousOptions();
|
resetDangerousOptions();
|
||||||
mSettingsEnabler.disableDevelopmentSettings();
|
DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(getContext(), false);
|
||||||
setPrefsEnabledState(false);
|
setPrefsEnabledState(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2640,7 +2636,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
|||||||
} else if (dialog == mEnableDialog) {
|
} else if (dialog == mEnableDialog) {
|
||||||
if (which == DialogInterface.BUTTON_POSITIVE) {
|
if (which == DialogInterface.BUTTON_POSITIVE) {
|
||||||
mDialogClicked = true;
|
mDialogClicked = true;
|
||||||
mSettingsEnabler.enableDevelopmentSettings();
|
DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(getContext(), true);
|
||||||
setPrefsEnabledState(true);
|
setPrefsEnabledState(true);
|
||||||
} else {
|
} else {
|
||||||
// Reset the toggle
|
// Reset the toggle
|
||||||
@@ -2759,10 +2755,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isPageSearchEnabled(Context context) {
|
protected boolean isPageSearchEnabled(Context context) {
|
||||||
return context.getSharedPreferences(DevelopmentSettings.PREF_FILE,
|
return DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(context);
|
||||||
Context.MODE_PRIVATE).getBoolean(
|
|
||||||
DevelopmentSettings.PREF_SHOW,
|
|
||||||
android.os.Build.TYPE.equals("eng"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -36,7 +36,6 @@ import com.android.settings.Utils;
|
|||||||
import com.android.settings.core.PreferenceControllerMixin;
|
import com.android.settings.core.PreferenceControllerMixin;
|
||||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||||
import com.android.settings.development.DevelopmentSettings;
|
import com.android.settings.development.DevelopmentSettings;
|
||||||
import com.android.settings.development.DevelopmentSettingsEnabler;
|
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settings.password.ChooseLockSettingsHelper;
|
import com.android.settings.password.ChooseLockSettingsHelper;
|
||||||
import com.android.settingslib.RestrictedLockUtils;
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
@@ -44,6 +43,7 @@ import com.android.settingslib.core.AbstractPreferenceController;
|
|||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||||
import com.android.settingslib.core.lifecycle.events.OnResume;
|
import com.android.settingslib.core.lifecycle.events.OnResume;
|
||||||
|
import com.android.settingslib.development.DevelopmentSettingsEnabler;
|
||||||
|
|
||||||
public class BuildNumberPreferenceController extends AbstractPreferenceController implements
|
public class BuildNumberPreferenceController extends AbstractPreferenceController implements
|
||||||
PreferenceControllerMixin, LifecycleObserver, OnResume {
|
PreferenceControllerMixin, LifecycleObserver, OnResume {
|
||||||
@@ -106,9 +106,8 @@ public class BuildNumberPreferenceController extends AbstractPreferenceControlle
|
|||||||
mContext, UserManager.DISALLOW_DEBUGGING_FEATURES, UserHandle.myUserId());
|
mContext, UserManager.DISALLOW_DEBUGGING_FEATURES, UserHandle.myUserId());
|
||||||
mDebuggingFeaturesDisallowedBySystem = RestrictedLockUtils.hasBaseUserRestriction(
|
mDebuggingFeaturesDisallowedBySystem = RestrictedLockUtils.hasBaseUserRestriction(
|
||||||
mContext, UserManager.DISALLOW_DEBUGGING_FEATURES, UserHandle.myUserId());
|
mContext, UserManager.DISALLOW_DEBUGGING_FEATURES, UserHandle.myUserId());
|
||||||
mDevHitCountdown = mContext.getSharedPreferences(DevelopmentSettings.PREF_FILE,
|
mDevHitCountdown = DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(mContext)
|
||||||
Context.MODE_PRIVATE).getBoolean(DevelopmentSettings.PREF_SHOW,
|
? -1 : TAPS_TO_BE_A_DEVELOPER;
|
||||||
android.os.Build.TYPE.equals("eng")) ? -1 : TAPS_TO_BE_A_DEVELOPER;
|
|
||||||
mDevHitToast = null;
|
mDevHitToast = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,9 +214,7 @@ public class BuildNumberPreferenceController extends AbstractPreferenceControlle
|
|||||||
private void enableDevelopmentSettings() {
|
private void enableDevelopmentSettings() {
|
||||||
mDevHitCountdown = 0;
|
mDevHitCountdown = 0;
|
||||||
mProcessingLastDevHit = false;
|
mProcessingLastDevHit = false;
|
||||||
DevelopmentSettingsEnabler.enableDevelopmentSettings(mContext,
|
DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(mContext, true);
|
||||||
mContext.getSharedPreferences(DevelopmentSettings.PREF_FILE,
|
|
||||||
Context.MODE_PRIVATE));
|
|
||||||
if (mDevHitToast != null) {
|
if (mDevHitToast != null) {
|
||||||
mDevHitToast.cancel();
|
mDevHitToast.cancel();
|
||||||
}
|
}
|
||||||
|
@@ -1,105 +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 static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.provider.Settings;
|
|
||||||
|
|
||||||
import com.android.settings.TestConfig;
|
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.Answers;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
import org.robolectric.RuntimeEnvironment;
|
|
||||||
import org.robolectric.annotation.Config;
|
|
||||||
import org.robolectric.util.ReflectionHelpers;
|
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
|
||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
|
||||||
public class DevelopmentSettingsEnablerTest {
|
|
||||||
|
|
||||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
|
||||||
private SharedPreferences mDevelopmentPreferences;
|
|
||||||
private Context mContext;
|
|
||||||
private DevelopmentSettingsEnabler mEnabler;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
mContext = RuntimeEnvironment.application;
|
|
||||||
mEnabler = new DevelopmentSettingsEnabler(mContext, null);
|
|
||||||
ReflectionHelpers.setField(mEnabler, "mDevelopmentPreferences", mDevelopmentPreferences);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void constructor_shouldInitEnabledState() {
|
|
||||||
Settings.Global.putInt(mContext.getContentResolver(),
|
|
||||||
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
|
|
||||||
|
|
||||||
mEnabler = new DevelopmentSettingsEnabler(mContext, null);
|
|
||||||
|
|
||||||
assertThat(mEnabler.getLastEnabledState()).isTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void onResume_shouldReadStateFromSettingProvider() {
|
|
||||||
Settings.Global.putInt(mContext.getContentResolver(),
|
|
||||||
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
|
|
||||||
|
|
||||||
mEnabler.onResume();
|
|
||||||
|
|
||||||
assertThat(mEnabler.getLastEnabledState()).isTrue();
|
|
||||||
|
|
||||||
Settings.Global.putInt(mContext.getContentResolver(),
|
|
||||||
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
|
|
||||||
|
|
||||||
mEnabler.onResume();
|
|
||||||
|
|
||||||
assertThat(mEnabler.getLastEnabledState()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void disable_shouldChangeSettingProviderValue() {
|
|
||||||
Settings.Global.putInt(mContext.getContentResolver(),
|
|
||||||
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
|
|
||||||
|
|
||||||
mEnabler.disableDevelopmentSettings();
|
|
||||||
|
|
||||||
assertThat(mEnabler.getLastEnabledState()).isFalse();
|
|
||||||
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
|
||||||
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1)).isEqualTo(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void enable_shouldChangeSettingProviderValue() {
|
|
||||||
Settings.Global.putInt(mContext.getContentResolver(),
|
|
||||||
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
|
|
||||||
|
|
||||||
mEnabler.enableDevelopmentSettings();
|
|
||||||
|
|
||||||
assertThat(mEnabler.getLastEnabledState()).isTrue();
|
|
||||||
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
|
||||||
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0)).isEqualTo(1);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -28,6 +28,7 @@ import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
|||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||||
|
import com.android.settingslib.development.DevelopmentSettingsEnabler;
|
||||||
import com.android.settingslib.drawer.CategoryKey;
|
import com.android.settingslib.drawer.CategoryKey;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -113,8 +114,7 @@ public class DevelopmentSettingsTest {
|
|||||||
@Test
|
@Test
|
||||||
public void searchIndex_pageDisabled_shouldAddAllKeysToNonIndexable() {
|
public void searchIndex_pageDisabled_shouldAddAllKeysToNonIndexable() {
|
||||||
final Context appContext = RuntimeEnvironment.application;
|
final Context appContext = RuntimeEnvironment.application;
|
||||||
new DevelopmentSettingsEnabler(appContext, null /* lifecycle */)
|
DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(appContext, false);
|
||||||
.disableDevelopmentSettings();
|
|
||||||
|
|
||||||
final List<String> nonIndexableKeys =
|
final List<String> nonIndexableKeys =
|
||||||
DevelopmentSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(appContext);
|
DevelopmentSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(appContext);
|
||||||
@@ -125,8 +125,7 @@ public class DevelopmentSettingsTest {
|
|||||||
@Test
|
@Test
|
||||||
public void searchIndex_pageEnabled_shouldNotAddKeysToNonIndexable() {
|
public void searchIndex_pageEnabled_shouldNotAddKeysToNonIndexable() {
|
||||||
final Context appContext = RuntimeEnvironment.application;
|
final Context appContext = RuntimeEnvironment.application;
|
||||||
new DevelopmentSettingsEnabler(appContext, null /* lifecycle */)
|
DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(appContext, true);
|
||||||
.enableDevelopmentSettings();
|
|
||||||
|
|
||||||
final List<String> nonIndexableKeys =
|
final List<String> nonIndexableKeys =
|
||||||
DevelopmentSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(appContext);
|
DevelopmentSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(appContext);
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
package com.android.settings.deviceinfo;
|
package com.android.settings.deviceinfo;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
|
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
@@ -38,12 +39,12 @@ import android.text.BidiFormatter;
|
|||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto;
|
import com.android.internal.logging.nano.MetricsProto;
|
||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
import com.android.settings.development.DevelopmentSettings;
|
|
||||||
import com.android.settings.search.DatabaseIndexingManager;
|
import com.android.settings.search.DatabaseIndexingManager;
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
import com.android.settings.testutils.shadow.ShadowUtils;
|
import com.android.settings.testutils.shadow.ShadowUtils;
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
import com.android.settingslib.development.DevelopmentSettingsEnabler;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -176,8 +177,8 @@ public class BuildNumberPreferenceControllerTest {
|
|||||||
null);
|
null);
|
||||||
|
|
||||||
assertThat(activityResultHandled).isFalse();
|
assertThat(activityResultHandled).isFalse();
|
||||||
verify(mContext, never())
|
assertThat(DevelopmentSettingsEnabler
|
||||||
.getSharedPreferences(DevelopmentSettings.PREF_FILE, Context.MODE_PRIVATE);
|
.isDevelopmentSettingsEnabled(RuntimeEnvironment.application)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -188,8 +189,8 @@ public class BuildNumberPreferenceControllerTest {
|
|||||||
null);
|
null);
|
||||||
|
|
||||||
assertThat(activityResultHandled).isTrue();
|
assertThat(activityResultHandled).isTrue();
|
||||||
verify(mContext, never())
|
assertThat(DevelopmentSettingsEnabler
|
||||||
.getSharedPreferences(DevelopmentSettings.PREF_FILE, Context.MODE_PRIVATE);
|
.isDevelopmentSettingsEnabled(RuntimeEnvironment.application)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -208,9 +209,8 @@ public class BuildNumberPreferenceControllerTest {
|
|||||||
null);
|
null);
|
||||||
|
|
||||||
assertThat(activityResultHandled).isTrue();
|
assertThat(activityResultHandled).isTrue();
|
||||||
assertThat(context.getSharedPreferences(DevelopmentSettings.PREF_FILE,
|
assertThat(DevelopmentSettingsEnabler
|
||||||
Context.MODE_PRIVATE).getBoolean(DevelopmentSettings.PREF_SHOW, false))
|
.isDevelopmentSettingsEnabled(RuntimeEnvironment.application)).isTrue();
|
||||||
.isTrue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user