Refactor SystemPropPoker

Bug: 62442606
Test: SystemPropPokerTest
Change-Id: I07d3e80938c7861cde074d8968a1c95b92981231
This commit is contained in:
Tony Mantler
2017-07-31 10:57:43 -07:00
parent 3d84d56336
commit 2d3dec6096
2 changed files with 21 additions and 50 deletions

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;
@@ -99,6 +98,7 @@ 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.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;
@@ -839,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()) {
@@ -863,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() {
@@ -1175,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() {
@@ -1184,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() {
@@ -1208,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();
} }
@@ -1234,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();
} }
@@ -1246,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() {
@@ -1257,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() {
@@ -1281,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();
} }
@@ -1306,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();
} }
@@ -1318,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() {
@@ -1384,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();
} }
@@ -1605,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();
} }
@@ -1652,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;
} }
} }
@@ -1664,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 {
@@ -1721,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)
@@ -2551,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);
@@ -2669,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) {
@@ -2716,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;

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