Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 47177b04 authored by John Spurlock's avatar John Spurlock Committed by The Android Automerger
Browse files

Add sanity check inside ServiceMonitor's setting observer.

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
parent 3b25917b
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -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;