From 8ab04d4c8480b12d74625b1a5bdc9dde2f9d21da Mon Sep 17 00:00:00 2001 From: Evan Laird Date: Thu, 9 Nov 2017 15:53:01 -0500 Subject: Don't send PLUGIN_CHANGED broadcast unless something changed If a plugin changes the layout (e.g., CameraCutout changing status bar height), the preference screen will call persistBoolean, which would always cause PLUGIN_CHANGED to be broadcasted. This causes bad infinite loops. Test: install CameraCutout plugin and navigate to Settings > Sysui tuner > Plugins and watch it loop a lot Change-Id: Id340bbfb0864508f1895bbd1e6cb2849a839bad8 --- .../com/android/systemui/tuner/PluginFragment.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/tuner/PluginFragment.java b/packages/SystemUI/src/com/android/systemui/tuner/PluginFragment.java index f91e45d05e79..27bf534c290e 100644 --- a/packages/SystemUI/src/com/android/systemui/tuner/PluginFragment.java +++ b/packages/SystemUI/src/com/android/systemui/tuner/PluginFragment.java @@ -169,16 +169,23 @@ public class PluginFragment extends PreferenceFragment { protected boolean persistBoolean(boolean value) { final int desiredState = value ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED; + boolean shouldSendBroadcast = false; for (int i = 0; i < mInfo.services.length; i++) { ComponentName componentName = new ComponentName(mInfo.packageName, mInfo.services[i].name); - mPm.setComponentEnabledSetting(componentName, desiredState, - PackageManager.DONT_KILL_APP); + + if (mPm.getComponentEnabledSetting(componentName) != desiredState) { + mPm.setComponentEnabledSetting(componentName, desiredState, + PackageManager.DONT_KILL_APP); + shouldSendBroadcast = true; + } + } + if (shouldSendBroadcast) { + final String pkg = mInfo.packageName; + final Intent intent = new Intent(PluginManager.PLUGIN_CHANGED, + pkg != null ? Uri.fromParts("package", pkg, null) : null); + getContext().sendBroadcast(intent); } - final String pkg = mInfo.packageName; - final Intent intent = new Intent(PluginManager.PLUGIN_CHANGED, - pkg != null ? Uri.fromParts("package", pkg, null) : null); - getContext().sendBroadcast(intent); return true; } -- cgit v1.2.3-59-g8ed1b