OSDN Git Service

Add sanity check inside ServiceMonitor's setting observer.
authorJohn Spurlock <jspurlock@google.com>
Thu, 27 Jun 2013 14:15:19 +0000 (10:15 -0400)
committerJohn Spurlock <jspurlock@google.com>
Thu, 27 Jun 2013 14:21:39 +0000 (10:21 -0400)
When registering for a specific setting key uri, the observer
can also be called back for "parent uri" updates.  e.g.
adb shell content update --uri content://settings/secure will
trigger onChange with uri=content://settings/secure.

Add a quick setting value recheck, and avoid restarting if
the setting value change will have no impact.

Bug: 9595731
Change-Id: I4c71f6a4be3b655b31d2535e809bb42edd931cd6

packages/SystemUI/src/com/android/systemui/statusbar/ServiceMonitor.java

index f763f03..aea9ec6 100644 (file)
@@ -98,6 +98,11 @@ public class ServiceMonitor {
 
         public void onChange(boolean selfChange, Uri uri) {
             if (mDebug) Log.d(mTag, "onChange selfChange=" + selfChange + " uri=" + uri);
+            ComponentName cn = getComponentNameFromSetting();
+            if (cn == null && mServiceName == null || cn != null && cn.equals(mServiceName)) {
+                if (mDebug) Log.d(mTag, "skipping no-op restart");
+                return;
+            }
             if (mBound) {
                 mHandler.sendEmptyMessage(MSG_STOP_SERVICE);
             }
@@ -178,6 +183,12 @@ public class ServiceMonitor {
         mHandler.sendEmptyMessage(MSG_START_SERVICE);
     }
 
+    private ComponentName getComponentNameFromSetting() {
+        String cn = Settings.Secure.getStringForUser(mContext.getContentResolver(),
+                mSettingKey, UserHandle.USER_CURRENT);
+        return cn == null ? null : ComponentName.unflattenFromString(cn);
+    }
+
     // everything below is called on the handler
 
     private void packageIntent(Intent intent) {
@@ -210,9 +221,7 @@ public class ServiceMonitor {
     }
 
     private void startService() {
-        String cn = Settings.Secure.getStringForUser(mContext.getContentResolver(),
-                mSettingKey, UserHandle.USER_CURRENT);
-        mServiceName = cn == null ? null : ComponentName.unflattenFromString(cn);
+        mServiceName = getComponentNameFromSetting();
         if (mDebug) Log.d(mTag, "startService mServiceName=" + mServiceName);
         if (mServiceName == null) {
             mBound = false;