Loading res/xml/development_settings.xml +2 −2 Original line number Diff line number Diff line Loading @@ -648,7 +648,7 @@ android:title="@string/reset_shortcut_manager_throttling" /> </PreferenceCategory> <com.android.settings.development.autofill.AutofillPreferenceCategory <PreferenceCategory android:key="debug_autofill_category" android:title="@string/debug_autofill_category" settings:searchable="false" Loading @@ -672,7 +672,7 @@ android:key="autofill_reset_developer_options" android:title="@string/autofill_reset_developer_options" /> </com.android.settings.development.autofill.AutofillPreferenceCategory> </PreferenceCategory> <PreferenceCategory android:key="storage_category" Loading src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java +2 −0 Original line number Diff line number Diff line Loading @@ -47,6 +47,7 @@ import com.android.settings.SettingsActivity; import com.android.settings.Utils; import com.android.settings.core.SubSettingLauncher; import com.android.settings.dashboard.RestrictedDashboardFragment; import com.android.settings.development.autofill.AutofillCategoryController; import com.android.settings.development.autofill.AutofillLoggingLevelPreferenceController; import com.android.settings.development.autofill.AutofillResetOptionsPreferenceController; import com.android.settings.development.bluetooth.AbstractBluetoothDialogPreferenceController; Loading Loading @@ -566,6 +567,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra controllers.add(new DefaultLaunchPreferenceController(context, "density")); controllers.add(new DefaultLaunchPreferenceController(context, "background_check")); controllers.add(new DefaultLaunchPreferenceController(context, "inactive_apps")); controllers.add(new AutofillCategoryController(context, lifecycle)); controllers.add(new AutofillLoggingLevelPreferenceController(context, lifecycle)); controllers.add(new AutofillResetOptionsPreferenceController(context)); controllers.add(new BluetoothCodecDialogPreferenceController(context, lifecycle, Loading src/com/android/settings/development/autofill/AutofillPreferenceCategory.java→src/com/android/settings/development/autofill/AutofillCategoryController.java +41 −24 Original line number Diff line number Diff line /* * Copyright (C) 2018 The Android Open Source Project * Copyright (C) 2022 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of the License at * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the specific language governing * permissions and limitations under the License. * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.settings.development.autofill; Loading @@ -21,23 +23,36 @@ import android.net.Uri; import android.os.Handler; import android.os.Looper; import android.provider.Settings; import android.util.AttributeSet; import android.util.Log; import android.view.autofill.AutofillManager; import androidx.preference.PreferenceCategory; import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.android.settingslib.core.lifecycle.events.OnStart; import com.android.settingslib.core.lifecycle.events.OnStop; import com.android.settingslib.development.DeveloperOptionsPreferenceController; public final class AutofillPreferenceCategory extends PreferenceCategory { /** * Controller class for observing the state of AutofillManager. */ public class AutofillCategoryController extends DeveloperOptionsPreferenceController implements LifecycleObserver, OnStart, OnStop { private static final String TAG = "AutofillCategoryController"; private static final String TAG = "AutofillPreferenceCategory"; private static final String CATEGORY_KEY = "debug_autofill_category"; private static final long DELAYED_MESSAGE_TIME_MS = 2000; private final ContentResolver mContentResolver; private final ContentObserver mSettingsObserver; private ContentResolver mContentResolver; private ContentObserver mSettingsObserver; private final Handler mHandler = new Handler(Looper.getMainLooper()); public AutofillPreferenceCategory(Context context, AttributeSet attrs) { super(context, attrs); public AutofillCategoryController(Context context, Lifecycle lifecycle) { super(context); if (lifecycle != null) { lifecycle.addObserver(this); } mSettingsObserver = new ContentObserver(mHandler) { @Override Loading @@ -45,7 +60,8 @@ public final class AutofillPreferenceCategory extends PreferenceCategory { // 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()), mHandler.postDelayed( () -> mPreference.notifyDependencyChange(shouldDisableDependents()), DELAYED_MESSAGE_TIME_MS); } }; Loading @@ -53,32 +69,33 @@ public final class AutofillPreferenceCategory extends PreferenceCategory { } @Override public void onAttached() { super.onAttached(); public String getPreferenceKey() { return CATEGORY_KEY; } @Override public void onStart() { mContentResolver.registerContentObserver( Settings.Secure.getUriFor(Settings.Secure.AUTOFILL_SERVICE), false, mSettingsObserver); } @Override public void onDetached() { public void onStop() { mContentResolver.unregisterContentObserver(mSettingsObserver); super.onDetached(); } // 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; Loading Loading
res/xml/development_settings.xml +2 −2 Original line number Diff line number Diff line Loading @@ -648,7 +648,7 @@ android:title="@string/reset_shortcut_manager_throttling" /> </PreferenceCategory> <com.android.settings.development.autofill.AutofillPreferenceCategory <PreferenceCategory android:key="debug_autofill_category" android:title="@string/debug_autofill_category" settings:searchable="false" Loading @@ -672,7 +672,7 @@ android:key="autofill_reset_developer_options" android:title="@string/autofill_reset_developer_options" /> </com.android.settings.development.autofill.AutofillPreferenceCategory> </PreferenceCategory> <PreferenceCategory android:key="storage_category" Loading
src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java +2 −0 Original line number Diff line number Diff line Loading @@ -47,6 +47,7 @@ import com.android.settings.SettingsActivity; import com.android.settings.Utils; import com.android.settings.core.SubSettingLauncher; import com.android.settings.dashboard.RestrictedDashboardFragment; import com.android.settings.development.autofill.AutofillCategoryController; import com.android.settings.development.autofill.AutofillLoggingLevelPreferenceController; import com.android.settings.development.autofill.AutofillResetOptionsPreferenceController; import com.android.settings.development.bluetooth.AbstractBluetoothDialogPreferenceController; Loading Loading @@ -566,6 +567,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra controllers.add(new DefaultLaunchPreferenceController(context, "density")); controllers.add(new DefaultLaunchPreferenceController(context, "background_check")); controllers.add(new DefaultLaunchPreferenceController(context, "inactive_apps")); controllers.add(new AutofillCategoryController(context, lifecycle)); controllers.add(new AutofillLoggingLevelPreferenceController(context, lifecycle)); controllers.add(new AutofillResetOptionsPreferenceController(context)); controllers.add(new BluetoothCodecDialogPreferenceController(context, lifecycle, Loading
src/com/android/settings/development/autofill/AutofillPreferenceCategory.java→src/com/android/settings/development/autofill/AutofillCategoryController.java +41 −24 Original line number Diff line number Diff line /* * Copyright (C) 2018 The Android Open Source Project * Copyright (C) 2022 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of the License at * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the specific language governing * permissions and limitations under the License. * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.settings.development.autofill; Loading @@ -21,23 +23,36 @@ import android.net.Uri; import android.os.Handler; import android.os.Looper; import android.provider.Settings; import android.util.AttributeSet; import android.util.Log; import android.view.autofill.AutofillManager; import androidx.preference.PreferenceCategory; import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.android.settingslib.core.lifecycle.events.OnStart; import com.android.settingslib.core.lifecycle.events.OnStop; import com.android.settingslib.development.DeveloperOptionsPreferenceController; public final class AutofillPreferenceCategory extends PreferenceCategory { /** * Controller class for observing the state of AutofillManager. */ public class AutofillCategoryController extends DeveloperOptionsPreferenceController implements LifecycleObserver, OnStart, OnStop { private static final String TAG = "AutofillCategoryController"; private static final String TAG = "AutofillPreferenceCategory"; private static final String CATEGORY_KEY = "debug_autofill_category"; private static final long DELAYED_MESSAGE_TIME_MS = 2000; private final ContentResolver mContentResolver; private final ContentObserver mSettingsObserver; private ContentResolver mContentResolver; private ContentObserver mSettingsObserver; private final Handler mHandler = new Handler(Looper.getMainLooper()); public AutofillPreferenceCategory(Context context, AttributeSet attrs) { super(context, attrs); public AutofillCategoryController(Context context, Lifecycle lifecycle) { super(context); if (lifecycle != null) { lifecycle.addObserver(this); } mSettingsObserver = new ContentObserver(mHandler) { @Override Loading @@ -45,7 +60,8 @@ public final class AutofillPreferenceCategory extends PreferenceCategory { // 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()), mHandler.postDelayed( () -> mPreference.notifyDependencyChange(shouldDisableDependents()), DELAYED_MESSAGE_TIME_MS); } }; Loading @@ -53,32 +69,33 @@ public final class AutofillPreferenceCategory extends PreferenceCategory { } @Override public void onAttached() { super.onAttached(); public String getPreferenceKey() { return CATEGORY_KEY; } @Override public void onStart() { mContentResolver.registerContentObserver( Settings.Secure.getUriFor(Settings.Secure.AUTOFILL_SERVICE), false, mSettingsObserver); } @Override public void onDetached() { public void onStop() { mContentResolver.unregisterContentObserver(mSettingsObserver); super.onDetached(); } // 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; Loading