From a305b779e8feb15d8254a8c95fc808d0a10859b9 Mon Sep 17 00:00:00 2001 From: Felipe Leme Date: Mon, 30 Jul 2018 09:27:36 -0700 Subject: [PATCH] Fixed AutofillPreferenceCategory so it's UI is properly refreshed. 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 --- .../development/autofill/AutofillPreferenceCategory.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/com/android/settings/development/autofill/AutofillPreferenceCategory.java b/src/com/android/settings/development/autofill/AutofillPreferenceCategory.java index ed07f62907..711100d286 100644 --- a/src/com/android/settings/development/autofill/AutofillPreferenceCategory.java +++ b/src/com/android/settings/development/autofill/AutofillPreferenceCategory.java @@ -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(); -- 2.11.0