Merge changes from topics 'SystemPropPoker', 'DevSettingsPrefsFile'
* changes: Refactor SystemPropPoker Remove development settings prefs file
This commit is contained in:
@@ -39,6 +39,7 @@ import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v14.preference.PreferenceFragment;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceManager;
|
||||
import android.text.TextUtils;
|
||||
@@ -63,6 +64,7 @@ import com.android.settings.search.DynamicIndexableContentMonitor;
|
||||
import com.android.settings.search.SearchActivity;
|
||||
import com.android.settings.wfd.WifiDisplaySettings;
|
||||
import com.android.settings.widget.SwitchBar;
|
||||
import com.android.settingslib.development.DevelopmentSettingsEnabler;
|
||||
import com.android.settingslib.drawer.DashboardCategory;
|
||||
import com.android.settingslib.drawer.SettingsDrawerActivity;
|
||||
import java.util.ArrayList;
|
||||
@@ -164,8 +166,7 @@ public class SettingsActivity extends SettingsDrawerActivity
|
||||
"android.settings.APPLICATION_DETAILS_SETTINGS"
|
||||
};
|
||||
|
||||
private SharedPreferences mDevelopmentPreferences;
|
||||
private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
|
||||
private BroadcastReceiver mDevelopmentSettingsListener;
|
||||
|
||||
private boolean mBatteryPresent = true;
|
||||
private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
|
||||
@@ -274,9 +275,6 @@ public class SettingsActivity extends SettingsDrawerActivity
|
||||
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(...)
|
||||
final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
|
||||
|
||||
@@ -530,9 +528,14 @@ public class SettingsActivity extends SettingsDrawerActivity
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
mDevelopmentPreferencesListener = (sharedPreferences, key) -> updateTilesList();
|
||||
mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
|
||||
mDevelopmentPreferencesListener);
|
||||
mDevelopmentSettingsListener = new BroadcastReceiver() {
|
||||
@Override
|
||||
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));
|
||||
if (mDynamicIndexableContentMonitor == null) {
|
||||
@@ -546,9 +549,8 @@ public class SettingsActivity extends SettingsDrawerActivity
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
|
||||
mDevelopmentPreferencesListener);
|
||||
mDevelopmentPreferencesListener = null;
|
||||
LocalBroadcastManager.getInstance(this).unregisterReceiver(mDevelopmentSettingsListener);
|
||||
mDevelopmentSettingsListener = null;
|
||||
unregisterReceiver(mBatteryInfoReceiver);
|
||||
if (mDynamicIndexableContentMonitor != null) {
|
||||
mDynamicIndexableContentMonitor.unregister(this, LOADER_ID_INDEXABLE_CONTENT_MONITOR);
|
||||
@@ -839,8 +841,7 @@ public class SettingsActivity extends SettingsDrawerActivity
|
||||
pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin)
|
||||
|| somethingChanged;
|
||||
|
||||
final boolean showDev = mDevelopmentPreferences.getBoolean(
|
||||
DevelopmentSettings.PREF_SHOW, android.os.Build.TYPE.equals("eng"))
|
||||
final boolean showDev = DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(this)
|
||||
&& !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES);
|
||||
somethingChanged = setTileEnabled(new ComponentName(packageName,
|
||||
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.DataUsageList;
|
||||
import com.android.settings.datausage.DataUsageUtils;
|
||||
import com.android.settings.development.DevelopmentSettingsEnabler;
|
||||
import com.android.settings.fuelgauge.AdvancedPowerUsageDetail;
|
||||
import com.android.settings.fuelgauge.BatteryEntry;
|
||||
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.StorageStatsSource;
|
||||
import com.android.settingslib.applications.StorageStatsSource.AppStorageStats;
|
||||
import com.android.settingslib.development.DevelopmentSettingsEnabler;
|
||||
import com.android.settingslib.net.ChartData;
|
||||
import com.android.settingslib.net.ChartDataLoader;
|
||||
|
||||
@@ -178,7 +178,6 @@ public class InstalledAppDetails extends AppInfoBase
|
||||
private Preference mMemoryPreference;
|
||||
private Preference mVersionPreference;
|
||||
private AppDomainsPreference mInstantAppDomainsPreference;
|
||||
private DevelopmentSettingsEnabler mDevelopmentSettingsEnabler;
|
||||
private boolean mDisableAfterUninstall;
|
||||
|
||||
// Used for updating notification preference.
|
||||
@@ -392,8 +391,6 @@ public class InstalledAppDetails extends AppInfoBase
|
||||
removePreference(KEY_DATA);
|
||||
}
|
||||
mBatteryUtils = BatteryUtils.getInstance(getContext());
|
||||
mDevelopmentSettingsEnabler = new DevelopmentSettingsEnabler(
|
||||
activity, null /* lifecycle */);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -417,7 +414,7 @@ public class InstalledAppDetails extends AppInfoBase
|
||||
loaderManager.restartLoader(LOADER_STORAGE, Bundle.EMPTY, this);
|
||||
}
|
||||
restartBatteryStatsLoader();
|
||||
if (mDevelopmentSettingsEnabler.getLastEnabledState()) {
|
||||
if (DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(getContext())) {
|
||||
new MemoryUpdater().execute();
|
||||
}
|
||||
updateDynamicPrefs();
|
||||
@@ -473,7 +470,8 @@ public class InstalledAppDetails extends AppInfoBase
|
||||
mBatteryPreference.setOnPreferenceClickListener(this);
|
||||
mMemoryPreference = findPreference(KEY_MEMORY);
|
||||
mMemoryPreference.setOnPreferenceClickListener(this);
|
||||
mMemoryPreference.setVisible(mDevelopmentSettingsEnabler.getLastEnabledState());
|
||||
mMemoryPreference.setVisible(
|
||||
DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(getContext()));
|
||||
mVersionPreference = findPreference(KEY_VERSION);
|
||||
mInstantAppDomainsPreference =
|
||||
(AppDomainsPreference) findPreference(KEY_INSTANT_APP_SUPPORTED_LINKS);
|
||||
|
@@ -44,7 +44,6 @@ import android.content.res.Resources;
|
||||
import android.hardware.usb.IUsbManager;
|
||||
import android.hardware.usb.UsbManager;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
@@ -98,6 +97,8 @@ 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.development.SystemPropPoker;
|
||||
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();
|
||||
|
||||
@@ -844,7 +839,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
}
|
||||
|
||||
private void resetDangerousOptions() {
|
||||
mDontPokeProperties = true;
|
||||
SystemPropPoker.getInstance().blockPokes();
|
||||
for (int i = 0; i < mResetSwitchPrefs.size(); i++) {
|
||||
SwitchPreference cb = mResetSwitchPrefs.get(i);
|
||||
if (cb.isChecked()) {
|
||||
@@ -868,8 +863,8 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
writeAppProcessLimitOptions(null);
|
||||
mHaveDebugSettings = false;
|
||||
updateAllOptions();
|
||||
mDontPokeProperties = false;
|
||||
pokeSystemProperties();
|
||||
SystemPropPoker.getInstance().unblockPokes();
|
||||
SystemPropPoker.getInstance().poke();
|
||||
}
|
||||
|
||||
private void updateHdcpValues() {
|
||||
@@ -1180,7 +1175,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
|
||||
private void writeHardwareUiOptions() {
|
||||
SystemProperties.set(HARDWARE_UI_PROPERTY, mForceHardwareUi.isChecked() ? "true" : "false");
|
||||
pokeSystemProperties();
|
||||
SystemPropPoker.getInstance().poke();
|
||||
}
|
||||
|
||||
private void updateMsaaOptions() {
|
||||
@@ -1189,7 +1184,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
|
||||
private void writeMsaaOptions() {
|
||||
SystemProperties.set(MSAA_PROPERTY, mForceMsaa.isChecked() ? "true" : "false");
|
||||
pokeSystemProperties();
|
||||
SystemPropPoker.getInstance().poke();
|
||||
}
|
||||
|
||||
private void updateTrackFrameTimeOptions() {
|
||||
@@ -1213,7 +1208,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
private void writeTrackFrameTimeOptions(Object newValue) {
|
||||
SystemProperties.set(ThreadedRenderer.PROFILE_PROPERTY,
|
||||
newValue == null ? "" : newValue.toString());
|
||||
pokeSystemProperties();
|
||||
SystemPropPoker.getInstance().poke();
|
||||
updateTrackFrameTimeOptions();
|
||||
}
|
||||
|
||||
@@ -1239,7 +1234,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
private void writeShowNonRectClipOptions(Object newValue) {
|
||||
SystemProperties.set(ThreadedRenderer.DEBUG_SHOW_NON_RECTANGULAR_CLIP_PROPERTY,
|
||||
newValue == null ? "" : newValue.toString());
|
||||
pokeSystemProperties();
|
||||
SystemPropPoker.getInstance().poke();
|
||||
updateShowNonRectClipOptions();
|
||||
}
|
||||
|
||||
@@ -1251,7 +1246,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
private void writeShowHwScreenUpdatesOptions() {
|
||||
SystemProperties.set(ThreadedRenderer.DEBUG_DIRTY_REGIONS_PROPERTY,
|
||||
mShowHwScreenUpdates.isChecked() ? "true" : null);
|
||||
pokeSystemProperties();
|
||||
SystemPropPoker.getInstance().poke();
|
||||
}
|
||||
|
||||
private void updateShowHwLayersUpdatesOptions() {
|
||||
@@ -1262,7 +1257,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
private void writeShowHwLayersUpdatesOptions() {
|
||||
SystemProperties.set(ThreadedRenderer.DEBUG_SHOW_LAYERS_UPDATES_PROPERTY,
|
||||
mShowHwLayersUpdates.isChecked() ? "true" : null);
|
||||
pokeSystemProperties();
|
||||
SystemPropPoker.getInstance().poke();
|
||||
}
|
||||
|
||||
private void updateDebugHwOverdrawOptions() {
|
||||
@@ -1286,7 +1281,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
private void writeDebugHwOverdrawOptions(Object newValue) {
|
||||
SystemProperties.set(ThreadedRenderer.DEBUG_OVERDRAW_PROPERTY,
|
||||
newValue == null ? "" : newValue.toString());
|
||||
pokeSystemProperties();
|
||||
SystemPropPoker.getInstance().poke();
|
||||
updateDebugHwOverdrawOptions();
|
||||
}
|
||||
|
||||
@@ -1311,7 +1306,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
private void writeDebugHwRendererOptions(Object newValue) {
|
||||
SystemProperties.set(ThreadedRenderer.DEBUG_RENDERER_PROPERTY,
|
||||
newValue == null ? "" : newValue.toString());
|
||||
pokeSystemProperties();
|
||||
SystemPropPoker.getInstance().poke();
|
||||
updateDebugHwRendererOptions();
|
||||
}
|
||||
|
||||
@@ -1323,7 +1318,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
private void writeDebugLayoutOptions() {
|
||||
SystemProperties.set(View.DEBUG_LAYOUT_PROPERTY,
|
||||
mDebugLayout.isChecked() ? "true" : "false");
|
||||
pokeSystemProperties();
|
||||
SystemPropPoker.getInstance().poke();
|
||||
}
|
||||
|
||||
private void updateSimulateColorSpace() {
|
||||
@@ -1389,7 +1384,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
private void writeColorTemperature() {
|
||||
SystemProperties.set(COLOR_TEMPERATURE_PROPERTY,
|
||||
mColorTemperaturePreference.isChecked() ? "1" : "0");
|
||||
pokeSystemProperties();
|
||||
SystemPropPoker.getInstance().poke();
|
||||
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)) {
|
||||
writeLogpersistOption(null, true);
|
||||
mLogpersist.setEnabled(false);
|
||||
} else if (mSettingsEnabler.getLastEnabledState()) {
|
||||
} else if (DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(getContext())) {
|
||||
mLogpersist.setEnabled(true);
|
||||
}
|
||||
}
|
||||
@@ -1610,7 +1605,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
newValue.toString() : defaultValue;
|
||||
SystemProperties.set(SELECT_LOGD_SIZE_PROPERTY, defaultValue.equals(size) ? "" : size);
|
||||
SystemProperties.set("ctl.start", "logd-reinit");
|
||||
pokeSystemProperties();
|
||||
SystemPropPoker.getInstance().poke();
|
||||
updateLogdSizeValues();
|
||||
}
|
||||
|
||||
@@ -1657,7 +1652,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
} else if (!mLogpersistCleared) {
|
||||
// would File.delete() directly but need to switch uid/gid to access
|
||||
SystemProperties.set(ACTUAL_LOGPERSIST_PROPERTY, SELECT_LOGPERSIST_PROPERTY_CLEAR);
|
||||
pokeSystemProperties();
|
||||
SystemPropPoker.getInstance().poke();
|
||||
mLogpersistCleared = true;
|
||||
}
|
||||
}
|
||||
@@ -1669,7 +1664,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
SystemProperties.set(SELECT_LOGPERSIST_PROPERTY, "");
|
||||
SystemProperties.set(ACTUAL_LOGPERSIST_PROPERTY,
|
||||
update ? "" : SELECT_LOGPERSIST_PROPERTY_STOP);
|
||||
pokeSystemProperties();
|
||||
SystemPropPoker.getInstance().poke();
|
||||
if (update) {
|
||||
updateLogpersistValues();
|
||||
} else {
|
||||
@@ -1726,7 +1721,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
}
|
||||
SystemProperties.set(SELECT_LOGPERSIST_PROPERTY_BUFFER, newValue.toString());
|
||||
SystemProperties.set(SELECT_LOGPERSIST_PROPERTY, SELECT_LOGPERSIST_PROPERTY_SERVICE);
|
||||
pokeSystemProperties();
|
||||
SystemPropPoker.getInstance().poke();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
String currentValue = SystemProperties.get(ACTUAL_LOGPERSIST_PROPERTY);
|
||||
if ((currentValue != null)
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -2555,7 +2551,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
if (HDCP_CHECKING_KEY.equals(preference.getKey())) {
|
||||
SystemProperties.set(HDCP_CHECKING_PROPERTY, newValue.toString());
|
||||
updateHdcpValues();
|
||||
pokeSystemProperties();
|
||||
SystemPropPoker.getInstance().poke();
|
||||
return true;
|
||||
} else if (preference == mBluetoothSelectAvrcpVersion) {
|
||||
writeBluetoothAvrcpVersion(newValue);
|
||||
@@ -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
|
||||
@@ -2673,13 +2669,6 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
void pokeSystemProperties() {
|
||||
if (!mDontPokeProperties) {
|
||||
//noinspection unchecked
|
||||
(new SystemPropPoker()).execute();
|
||||
}
|
||||
}
|
||||
|
||||
private BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
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) {
|
||||
try {
|
||||
return context.getPackageManager().getPackageInfo(packageName, 0) != null;
|
||||
@@ -2759,10 +2726,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
|
||||
|
@@ -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.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settings.development.DevelopmentSettings;
|
||||
import com.android.settings.development.DevelopmentSettingsEnabler;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.password.ChooseLockSettingsHelper;
|
||||
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.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnResume;
|
||||
import com.android.settingslib.development.DevelopmentSettingsEnabler;
|
||||
|
||||
public class BuildNumberPreferenceController extends AbstractPreferenceController implements
|
||||
PreferenceControllerMixin, LifecycleObserver, OnResume {
|
||||
@@ -106,9 +106,8 @@ public class BuildNumberPreferenceController extends AbstractPreferenceControlle
|
||||
mContext, UserManager.DISALLOW_DEBUGGING_FEATURES, UserHandle.myUserId());
|
||||
mDebuggingFeaturesDisallowedBySystem = RestrictedLockUtils.hasBaseUserRestriction(
|
||||
mContext, UserManager.DISALLOW_DEBUGGING_FEATURES, UserHandle.myUserId());
|
||||
mDevHitCountdown = mContext.getSharedPreferences(DevelopmentSettings.PREF_FILE,
|
||||
Context.MODE_PRIVATE).getBoolean(DevelopmentSettings.PREF_SHOW,
|
||||
android.os.Build.TYPE.equals("eng")) ? -1 : TAPS_TO_BE_A_DEVELOPER;
|
||||
mDevHitCountdown = DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(mContext)
|
||||
? -1 : TAPS_TO_BE_A_DEVELOPER;
|
||||
mDevHitToast = null;
|
||||
}
|
||||
|
||||
@@ -215,9 +214,7 @@ public class BuildNumberPreferenceController extends AbstractPreferenceControlle
|
||||
private void enableDevelopmentSettings() {
|
||||
mDevHitCountdown = 0;
|
||||
mProcessingLastDevHit = false;
|
||||
DevelopmentSettingsEnabler.enableDevelopmentSettings(mContext,
|
||||
mContext.getSharedPreferences(DevelopmentSettings.PREF_FILE,
|
||||
Context.MODE_PRIVATE));
|
||||
DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(mContext, true);
|
||||
if (mDevHitToast != null) {
|
||||
mDevHitToast.cancel();
|
||||
}
|
||||
|
@@ -27,7 +27,7 @@ import android.view.View;
|
||||
import android.view.WindowManagerGlobal;
|
||||
|
||||
import com.android.internal.app.LocalePicker;
|
||||
import com.android.settings.development.DevelopmentSettings;
|
||||
import com.android.settingslib.development.SystemPropPoker;
|
||||
|
||||
public abstract class DevelopmentTiles extends TileService {
|
||||
|
||||
@@ -49,7 +49,7 @@ public abstract class DevelopmentTiles extends TileService {
|
||||
@Override
|
||||
public void onClick() {
|
||||
setIsEnabled(getQsTile().getState() == Tile.STATE_INACTIVE);
|
||||
new DevelopmentSettings.SystemPropPoker().execute(); // Settings app magic
|
||||
SystemPropPoker.getInstance().poke(); // Settings app magic
|
||||
refresh();
|
||||
}
|
||||
|
||||
|
@@ -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.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
import com.android.settingslib.development.DevelopmentSettingsEnabler;
|
||||
import com.android.settingslib.drawer.CategoryKey;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -113,8 +114,7 @@ public class DevelopmentSettingsTest {
|
||||
@Test
|
||||
public void searchIndex_pageDisabled_shouldAddAllKeysToNonIndexable() {
|
||||
final Context appContext = RuntimeEnvironment.application;
|
||||
new DevelopmentSettingsEnabler(appContext, null /* lifecycle */)
|
||||
.disableDevelopmentSettings();
|
||||
DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(appContext, false);
|
||||
|
||||
final List<String> nonIndexableKeys =
|
||||
DevelopmentSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(appContext);
|
||||
@@ -125,8 +125,7 @@ public class DevelopmentSettingsTest {
|
||||
@Test
|
||||
public void searchIndex_pageEnabled_shouldNotAddKeysToNonIndexable() {
|
||||
final Context appContext = RuntimeEnvironment.application;
|
||||
new DevelopmentSettingsEnabler(appContext, null /* lifecycle */)
|
||||
.enableDevelopmentSettings();
|
||||
DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(appContext, true);
|
||||
|
||||
final List<String> nonIndexableKeys =
|
||||
DevelopmentSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(appContext);
|
||||
|
@@ -17,6 +17,7 @@
|
||||
package com.android.settings.deviceinfo;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
@@ -38,12 +39,12 @@ import android.text.BidiFormatter;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.development.DevelopmentSettings;
|
||||
import com.android.settings.search.DatabaseIndexingManager;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowUtils;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.development.DevelopmentSettingsEnabler;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -176,8 +177,8 @@ public class BuildNumberPreferenceControllerTest {
|
||||
null);
|
||||
|
||||
assertThat(activityResultHandled).isFalse();
|
||||
verify(mContext, never())
|
||||
.getSharedPreferences(DevelopmentSettings.PREF_FILE, Context.MODE_PRIVATE);
|
||||
assertThat(DevelopmentSettingsEnabler
|
||||
.isDevelopmentSettingsEnabled(RuntimeEnvironment.application)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -188,8 +189,8 @@ public class BuildNumberPreferenceControllerTest {
|
||||
null);
|
||||
|
||||
assertThat(activityResultHandled).isTrue();
|
||||
verify(mContext, never())
|
||||
.getSharedPreferences(DevelopmentSettings.PREF_FILE, Context.MODE_PRIVATE);
|
||||
assertThat(DevelopmentSettingsEnabler
|
||||
.isDevelopmentSettingsEnabled(RuntimeEnvironment.application)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -208,9 +209,8 @@ public class BuildNumberPreferenceControllerTest {
|
||||
null);
|
||||
|
||||
assertThat(activityResultHandled).isTrue();
|
||||
assertThat(context.getSharedPreferences(DevelopmentSettings.PREF_FILE,
|
||||
Context.MODE_PRIVATE).getBoolean(DevelopmentSettings.PREF_SHOW, false))
|
||||
.isTrue();
|
||||
assertThat(DevelopmentSettingsEnabler
|
||||
.isDevelopmentSettingsEnabled(RuntimeEnvironment.application)).isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user