Merge changes from topics 'SystemPropPoker', 'DevSettingsPrefsFile'

* changes:
  Refactor SystemPropPoker
  Remove development settings prefs file
This commit is contained in:
Tony Mantler
2017-08-01 16:12:14 +00:00
committed by Android (Google) Code Review
9 changed files with 70 additions and 293 deletions

View File

@@ -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()),

View File

@@ -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);

View File

@@ -44,7 +44,6 @@ import android.content.res.Resources;
import android.hardware.usb.IUsbManager; import android.hardware.usb.IUsbManager;
import android.hardware.usb.UsbManager; import android.hardware.usb.UsbManager;
import android.net.wifi.WifiManager; import android.net.wifi.WifiManager;
import android.os.AsyncTask;
import android.os.BatteryManager; import android.os.BatteryManager;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
@@ -98,6 +97,8 @@ 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.development.SystemPropPoker;
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();
@@ -844,7 +839,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
} }
private void resetDangerousOptions() { private void resetDangerousOptions() {
mDontPokeProperties = true; SystemPropPoker.getInstance().blockPokes();
for (int i = 0; i < mResetSwitchPrefs.size(); i++) { for (int i = 0; i < mResetSwitchPrefs.size(); i++) {
SwitchPreference cb = mResetSwitchPrefs.get(i); SwitchPreference cb = mResetSwitchPrefs.get(i);
if (cb.isChecked()) { if (cb.isChecked()) {
@@ -868,8 +863,8 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
writeAppProcessLimitOptions(null); writeAppProcessLimitOptions(null);
mHaveDebugSettings = false; mHaveDebugSettings = false;
updateAllOptions(); updateAllOptions();
mDontPokeProperties = false; SystemPropPoker.getInstance().unblockPokes();
pokeSystemProperties(); SystemPropPoker.getInstance().poke();
} }
private void updateHdcpValues() { private void updateHdcpValues() {
@@ -1180,7 +1175,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
private void writeHardwareUiOptions() { private void writeHardwareUiOptions() {
SystemProperties.set(HARDWARE_UI_PROPERTY, mForceHardwareUi.isChecked() ? "true" : "false"); SystemProperties.set(HARDWARE_UI_PROPERTY, mForceHardwareUi.isChecked() ? "true" : "false");
pokeSystemProperties(); SystemPropPoker.getInstance().poke();
} }
private void updateMsaaOptions() { private void updateMsaaOptions() {
@@ -1189,7 +1184,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
private void writeMsaaOptions() { private void writeMsaaOptions() {
SystemProperties.set(MSAA_PROPERTY, mForceMsaa.isChecked() ? "true" : "false"); SystemProperties.set(MSAA_PROPERTY, mForceMsaa.isChecked() ? "true" : "false");
pokeSystemProperties(); SystemPropPoker.getInstance().poke();
} }
private void updateTrackFrameTimeOptions() { private void updateTrackFrameTimeOptions() {
@@ -1213,7 +1208,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
private void writeTrackFrameTimeOptions(Object newValue) { private void writeTrackFrameTimeOptions(Object newValue) {
SystemProperties.set(ThreadedRenderer.PROFILE_PROPERTY, SystemProperties.set(ThreadedRenderer.PROFILE_PROPERTY,
newValue == null ? "" : newValue.toString()); newValue == null ? "" : newValue.toString());
pokeSystemProperties(); SystemPropPoker.getInstance().poke();
updateTrackFrameTimeOptions(); updateTrackFrameTimeOptions();
} }
@@ -1239,7 +1234,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
private void writeShowNonRectClipOptions(Object newValue) { private void writeShowNonRectClipOptions(Object newValue) {
SystemProperties.set(ThreadedRenderer.DEBUG_SHOW_NON_RECTANGULAR_CLIP_PROPERTY, SystemProperties.set(ThreadedRenderer.DEBUG_SHOW_NON_RECTANGULAR_CLIP_PROPERTY,
newValue == null ? "" : newValue.toString()); newValue == null ? "" : newValue.toString());
pokeSystemProperties(); SystemPropPoker.getInstance().poke();
updateShowNonRectClipOptions(); updateShowNonRectClipOptions();
} }
@@ -1251,7 +1246,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
private void writeShowHwScreenUpdatesOptions() { private void writeShowHwScreenUpdatesOptions() {
SystemProperties.set(ThreadedRenderer.DEBUG_DIRTY_REGIONS_PROPERTY, SystemProperties.set(ThreadedRenderer.DEBUG_DIRTY_REGIONS_PROPERTY,
mShowHwScreenUpdates.isChecked() ? "true" : null); mShowHwScreenUpdates.isChecked() ? "true" : null);
pokeSystemProperties(); SystemPropPoker.getInstance().poke();
} }
private void updateShowHwLayersUpdatesOptions() { private void updateShowHwLayersUpdatesOptions() {
@@ -1262,7 +1257,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
private void writeShowHwLayersUpdatesOptions() { private void writeShowHwLayersUpdatesOptions() {
SystemProperties.set(ThreadedRenderer.DEBUG_SHOW_LAYERS_UPDATES_PROPERTY, SystemProperties.set(ThreadedRenderer.DEBUG_SHOW_LAYERS_UPDATES_PROPERTY,
mShowHwLayersUpdates.isChecked() ? "true" : null); mShowHwLayersUpdates.isChecked() ? "true" : null);
pokeSystemProperties(); SystemPropPoker.getInstance().poke();
} }
private void updateDebugHwOverdrawOptions() { private void updateDebugHwOverdrawOptions() {
@@ -1286,7 +1281,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
private void writeDebugHwOverdrawOptions(Object newValue) { private void writeDebugHwOverdrawOptions(Object newValue) {
SystemProperties.set(ThreadedRenderer.DEBUG_OVERDRAW_PROPERTY, SystemProperties.set(ThreadedRenderer.DEBUG_OVERDRAW_PROPERTY,
newValue == null ? "" : newValue.toString()); newValue == null ? "" : newValue.toString());
pokeSystemProperties(); SystemPropPoker.getInstance().poke();
updateDebugHwOverdrawOptions(); updateDebugHwOverdrawOptions();
} }
@@ -1311,7 +1306,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
private void writeDebugHwRendererOptions(Object newValue) { private void writeDebugHwRendererOptions(Object newValue) {
SystemProperties.set(ThreadedRenderer.DEBUG_RENDERER_PROPERTY, SystemProperties.set(ThreadedRenderer.DEBUG_RENDERER_PROPERTY,
newValue == null ? "" : newValue.toString()); newValue == null ? "" : newValue.toString());
pokeSystemProperties(); SystemPropPoker.getInstance().poke();
updateDebugHwRendererOptions(); updateDebugHwRendererOptions();
} }
@@ -1323,7 +1318,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
private void writeDebugLayoutOptions() { private void writeDebugLayoutOptions() {
SystemProperties.set(View.DEBUG_LAYOUT_PROPERTY, SystemProperties.set(View.DEBUG_LAYOUT_PROPERTY,
mDebugLayout.isChecked() ? "true" : "false"); mDebugLayout.isChecked() ? "true" : "false");
pokeSystemProperties(); SystemPropPoker.getInstance().poke();
} }
private void updateSimulateColorSpace() { private void updateSimulateColorSpace() {
@@ -1389,7 +1384,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
private void writeColorTemperature() { private void writeColorTemperature() {
SystemProperties.set(COLOR_TEMPERATURE_PROPERTY, SystemProperties.set(COLOR_TEMPERATURE_PROPERTY,
mColorTemperaturePreference.isChecked() ? "1" : "0"); mColorTemperaturePreference.isChecked() ? "1" : "0");
pokeSystemProperties(); SystemPropPoker.getInstance().poke();
Toast.makeText(getActivity(), R.string.color_temperature_toast, Toast.LENGTH_LONG).show(); Toast.makeText(getActivity(), R.string.color_temperature_toast, Toast.LENGTH_LONG).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);
} }
} }
@@ -1610,7 +1605,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
newValue.toString() : defaultValue; newValue.toString() : defaultValue;
SystemProperties.set(SELECT_LOGD_SIZE_PROPERTY, defaultValue.equals(size) ? "" : size); SystemProperties.set(SELECT_LOGD_SIZE_PROPERTY, defaultValue.equals(size) ? "" : size);
SystemProperties.set("ctl.start", "logd-reinit"); SystemProperties.set("ctl.start", "logd-reinit");
pokeSystemProperties(); SystemPropPoker.getInstance().poke();
updateLogdSizeValues(); updateLogdSizeValues();
} }
@@ -1657,7 +1652,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
} else if (!mLogpersistCleared) { } else if (!mLogpersistCleared) {
// would File.delete() directly but need to switch uid/gid to access // would File.delete() directly but need to switch uid/gid to access
SystemProperties.set(ACTUAL_LOGPERSIST_PROPERTY, SELECT_LOGPERSIST_PROPERTY_CLEAR); SystemProperties.set(ACTUAL_LOGPERSIST_PROPERTY, SELECT_LOGPERSIST_PROPERTY_CLEAR);
pokeSystemProperties(); SystemPropPoker.getInstance().poke();
mLogpersistCleared = true; mLogpersistCleared = true;
} }
} }
@@ -1669,7 +1664,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
SystemProperties.set(SELECT_LOGPERSIST_PROPERTY, ""); SystemProperties.set(SELECT_LOGPERSIST_PROPERTY, "");
SystemProperties.set(ACTUAL_LOGPERSIST_PROPERTY, SystemProperties.set(ACTUAL_LOGPERSIST_PROPERTY,
update ? "" : SELECT_LOGPERSIST_PROPERTY_STOP); update ? "" : SELECT_LOGPERSIST_PROPERTY_STOP);
pokeSystemProperties(); SystemPropPoker.getInstance().poke();
if (update) { if (update) {
updateLogpersistValues(); updateLogpersistValues();
} else { } else {
@@ -1726,7 +1721,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
} }
SystemProperties.set(SELECT_LOGPERSIST_PROPERTY_BUFFER, newValue.toString()); SystemProperties.set(SELECT_LOGPERSIST_PROPERTY_BUFFER, newValue.toString());
SystemProperties.set(SELECT_LOGPERSIST_PROPERTY, SELECT_LOGPERSIST_PROPERTY_SERVICE); SystemProperties.set(SELECT_LOGPERSIST_PROPERTY, SELECT_LOGPERSIST_PROPERTY_SERVICE);
pokeSystemProperties(); SystemPropPoker.getInstance().poke();
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
String currentValue = SystemProperties.get(ACTUAL_LOGPERSIST_PROPERTY); String currentValue = SystemProperties.get(ACTUAL_LOGPERSIST_PROPERTY);
if ((currentValue != null) if ((currentValue != null)
@@ -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);
} }
} }
@@ -2555,7 +2551,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
if (HDCP_CHECKING_KEY.equals(preference.getKey())) { if (HDCP_CHECKING_KEY.equals(preference.getKey())) {
SystemProperties.set(HDCP_CHECKING_PROPERTY, newValue.toString()); SystemProperties.set(HDCP_CHECKING_PROPERTY, newValue.toString());
updateHdcpValues(); updateHdcpValues();
pokeSystemProperties(); SystemPropPoker.getInstance().poke();
return true; return true;
} else if (preference == mBluetoothSelectAvrcpVersion) { } else if (preference == mBluetoothSelectAvrcpVersion) {
writeBluetoothAvrcpVersion(newValue); writeBluetoothAvrcpVersion(newValue);
@@ -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
@@ -2673,13 +2669,6 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
super.onDestroy(); super.onDestroy();
} }
void pokeSystemProperties() {
if (!mDontPokeProperties) {
//noinspection unchecked
(new SystemPropPoker()).execute();
}
}
private BroadcastReceiver mUsbReceiver = new BroadcastReceiver() { private BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
@@ -2720,28 +2709,6 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
} }
}; };
public static class SystemPropPoker extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
String[] services = ServiceManager.listServices();
for (String service : services) {
IBinder obj = ServiceManager.checkService(service);
if (obj != null) {
Parcel data = Parcel.obtain();
try {
obj.transact(IBinder.SYSPROPS_TRANSACTION, data, null, 0);
} catch (RemoteException e) {
} catch (Exception e) {
Log.i(TAG, "Someone wrote a bad service '" + service
+ "' that doesn't like to be poked: " + e);
}
data.recycle();
}
}
return null;
}
}
private static boolean isPackageInstalled(Context context, String packageName) { private static boolean isPackageInstalled(Context context, String packageName) {
try { try {
return context.getPackageManager().getPackageInfo(packageName, 0) != null; return context.getPackageManager().getPackageInfo(packageName, 0) != null;
@@ -2759,10 +2726,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

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;
}
}

View File

@@ -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();
} }

View File

@@ -27,7 +27,7 @@ import android.view.View;
import android.view.WindowManagerGlobal; import android.view.WindowManagerGlobal;
import com.android.internal.app.LocalePicker; import com.android.internal.app.LocalePicker;
import com.android.settings.development.DevelopmentSettings; import com.android.settingslib.development.SystemPropPoker;
public abstract class DevelopmentTiles extends TileService { public abstract class DevelopmentTiles extends TileService {
@@ -49,7 +49,7 @@ public abstract class DevelopmentTiles extends TileService {
@Override @Override
public void onClick() { public void onClick() {
setIsEnabled(getQsTile().getState() == Tile.STATE_INACTIVE); setIsEnabled(getQsTile().getState() == Tile.STATE_INACTIVE);
new DevelopmentSettings.SystemPropPoker().execute(); // Settings app magic SystemPropPoker.getInstance().poke(); // Settings app magic
refresh(); refresh();
} }

View File

@@ -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);
}
}

View File

@@ -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);

View File

@@ -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();
} }
} }