OSDN Git Service

Fixed AutofillPreferenceCategory so it's UI is properly refreshed.
authorFelipe Leme <felipeal@google.com>
Mon, 30 Jul 2018 16:27:36 +0000 (09:27 -0700)
committerFelipe Leme <felipeal@google.com>
Mon, 30 Jul 2018 16:58:59 +0000 (09:58 -0700)
Test: manual verification
Test: runtest --path packages/apps/Settings/tests/unit/src/com/android/settings/core/PreferenceControllerContractTest.java
Bug: 65700540
Bug: 111838239

Change-Id: If4e80a47d65aea34b94271e43ac38612373f4fa2

src/com/android/settings/development/autofill/AutofillPreferenceCategory.java

index ed07f62..711100d 100644 (file)
@@ -19,6 +19,7 @@ import android.content.Context;
 import android.database.ContentObserver;
 import android.net.Uri;
 import android.os.Handler;
+import android.os.Looper;
 import android.os.UserHandle;
 import android.provider.Settings;
 import android.util.AttributeSet;
@@ -30,22 +31,23 @@ import androidx.preference.PreferenceCategory;
 public final class AutofillPreferenceCategory extends PreferenceCategory {
 
     private static final String TAG = "AutofillPreferenceCategory";
+    private static final long DELAYED_MESSAGE_TIME_MS = 2000;
 
     private final ContentResolver mContentResolver;
     private final ContentObserver mSettingsObserver;
+    private final Handler mHandler = new Handler(Looper.getMainLooper());
 
     public AutofillPreferenceCategory(Context context, AttributeSet attrs) {
         super(context, attrs);
 
-        mSettingsObserver = new ContentObserver(new Handler()) {
+        mSettingsObserver = new ContentObserver(mHandler) {
             @Override
             public void onChange(boolean selfChange, Uri uri, int userId) {
-                Log.w(TAG, "Autofill Service changed, but UI cannot be refreshed");
-                // TODO(b/111838239): we cannot update the UI because AFM.isEnabled() will return
-                // the previous value. Once that's fixed, we'll need to call one of the 2 callbacks
-                // below:
-                // notifyChanged();
-                // notifyDependencyChange(shouldDisableDependents());
+                // We cannot apply the change yet because AutofillManager.isEnabled() state is
+                // updated by a ContentObserver as well and there's no guarantee of which observer
+                // is called first - hence, it's possible that the state didn't change here yet.
+                mHandler.postDelayed(() -> notifyDependencyChange(shouldDisableDependents()),
+                        DELAYED_MESSAGE_TIME_MS);
             }
         };
         mContentResolver = context.getContentResolver();