From e11d9e9ef3f53def5ef85e0655cbc18f3478309a Mon Sep 17 00:00:00 2001 From: Stanley Wang Date: Tue, 1 Mar 2022 19:28:30 +0800 Subject: [PATCH] Fix the problem that the autofill could be searched. PreferenceCategory will not be indexed by default. The auto fill category use the AutofillPreferenceCategory class in the xml so it will be indexed. The solution is to create a controller to replace AutofillPreferenceCategory. Fix: 185914894 Test: manual adb test to see the log Change-Id: Id0e3bcc33a3132434a6bd1fe91e1c6915116d06d --- res/xml/development_settings.xml | 4 +- .../DevelopmentSettingsDashboardFragment.java | 2 + ...y.java => AutofillCategoryController.java} | 73 ++++++++++++------- 3 files changed, 49 insertions(+), 30 deletions(-) rename src/com/android/settings/development/autofill/{AutofillPreferenceCategory.java => AutofillCategoryController.java} (54%) diff --git a/res/xml/development_settings.xml b/res/xml/development_settings.xml index f29930c8bd4..86544cd7b72 100644 --- a/res/xml/development_settings.xml +++ b/res/xml/development_settings.xml @@ -648,7 +648,7 @@ android:title="@string/reset_shortcut_manager_throttling" /> - - + notifyDependencyChange(shouldDisableDependents()), + mHandler.postDelayed( + () -> mPreference.notifyDependencyChange(shouldDisableDependents()), DELAYED_MESSAGE_TIME_MS); } }; @@ -53,32 +69,33 @@ public final class AutofillPreferenceCategory extends PreferenceCategory { } @Override - public void onAttached() { - super.onAttached(); - - mContentResolver.registerContentObserver( - Settings.Secure.getUriFor(Settings.Secure.AUTOFILL_SERVICE), false, - mSettingsObserver); + public String getPreferenceKey() { + return CATEGORY_KEY; } @Override - public void onDetached() { - mContentResolver.unregisterContentObserver(mSettingsObserver); + public void onStart() { + mContentResolver.registerContentObserver( + Settings.Secure.getUriFor(Settings.Secure.AUTOFILL_SERVICE), false, + mSettingsObserver); - super.onDetached(); + } + + @Override + public void onStop() { + mContentResolver.unregisterContentObserver(mSettingsObserver); } // PreferenceCategory.isEnabled() always return false, so we rather not change that logic // decide whether the children should be shown using isAutofillEnabled() instead. private boolean isAutofillEnabled() { - final AutofillManager afm = getContext().getSystemService(AutofillManager.class); + final AutofillManager afm = mContext.getSystemService(AutofillManager.class); final boolean enabled = afm != null && afm.isEnabled(); Log.v(TAG, "isAutofillEnabled(): " + enabled); return enabled; } - @Override - public boolean shouldDisableDependents() { + private boolean shouldDisableDependents() { final boolean shouldIt = !isAutofillEnabled(); Log.v(TAG, "shouldDisableDependents(): " + shouldIt); return shouldIt;