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

Commit 178bdd4c authored by Riley Jones's avatar Riley Jones
Browse files

Cleanup of AccessibilityUtil#hasValueInSettings

Settings should now be able to directly use the equivalent ShortcutUtils functions,
so the unnecessary code is being removed from AccessibilityUtil.
This does cause much behavior to depend on A11yManager instead of Settings.Secure,
so several tests need their conditions updated.

Test: atest com.android.settings.accessibility
Flag: EXEMPT internal refactoring
Bug: 367414968

Change-Id: I95f81f7d78b074def0fe2d1e01f60ceb7e142dac
parent 74b1086f
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;

import com.android.internal.accessibility.common.ShortcutConstants;
import com.android.internal.accessibility.util.ShortcutUtils;
import com.android.settings.R;
import com.android.settings.accessibility.shortcuts.EditShortcutsPreferenceFragment;
import com.android.settings.dashboard.RestrictedDashboardFragment;
@@ -308,8 +309,8 @@ public abstract class AccessibilityShortcutPreferenceFragment extends Restricted

        final int shortcutTypes = getUserPreferredShortcutTypes();
        mShortcutPreference.setChecked(
                AccessibilityUtil.hasValuesInSettings(getPrefContext(), shortcutTypes,
                        getComponentName()));
                ShortcutUtils.isShortcutContained(
                        getPrefContext(), shortcutTypes, getComponentName().flattenToString()));
        mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
    }

+3 −50
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import static android.view.WindowInsets.Type.displayCutout;
import static android.view.WindowInsets.Type.systemBars;
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;

import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.DEFAULT;
import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.GESTURE;
import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.HARDWARE;
import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.QUICK_SETTINGS;
@@ -37,7 +36,6 @@ import android.graphics.Insets;
import android.graphics.Rect;
import android.icu.text.CaseMap;
import android.os.Build;
import android.os.UserHandle;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.TypedValue;
@@ -194,52 +192,6 @@ public final class AccessibilityUtil {
                : AccessibilityServiceFragmentType.TOGGLE;
    }

    /**
     * Returns if component name existed in one of {@code shortcutTypes} string in Settings.
     *
     * @param context The current context.
     * @param shortcutTypes A combination of {@link UserShortcutType}.
     * @param componentName The component name that need to be checked existed in Settings.
     * @return {@code true} if componentName existed in Settings.
     */
    static boolean hasValuesInSettings(Context context, int shortcutTypes,
            @NonNull ComponentName componentName) {
        for (int shortcutType : AccessibilityUtil.SHORTCUTS_ORDER_IN_UI) {
            if (!android.provider.Flags.a11yStandaloneGestureEnabled()) {
                if ((shortcutType & GESTURE) == GESTURE) {
                    continue;
                }
            }
            if ((shortcutTypes & shortcutType) == shortcutType
                    && hasValueInSettings(context, shortcutType, componentName)) {
                return true;
            }
        }
        return false;
    }

    /**
     * Returns if component name existed in {@code shortcutType} string Settings.
     *
     * @param context The current context.
     * @param shortcutType The preferred shortcut type user selected.
     * @param componentName The component name that need to be checked existed in Settings.
     * @return {@code true} if componentName existed in Settings.
     *
     * @deprecated use
     * {@link ShortcutUtils#isShortcutContained(Context, int, String)} instead.
     *
     * (TODO 367414968: finish removal.)
     */
    @Deprecated
    @VisibleForTesting
    static boolean hasValueInSettings(Context context, @UserShortcutType int shortcutType,
            @NonNull ComponentName componentName) {
        return ShortcutUtils.getShortcutTargetsFromSettings(
                context, shortcutType, UserHandle.myUserId()
        ).contains(componentName.flattenToString());
    }

    /**
     * Gets the corresponding user shortcut type of a given accessibility service.
     *
@@ -250,14 +202,15 @@ public final class AccessibilityUtil {
     */
    static int getUserShortcutTypesFromSettings(Context context,
            @NonNull ComponentName componentName) {
        int shortcutTypes = DEFAULT;
        int shortcutTypes = UserShortcutType.DEFAULT;
        for (int shortcutType : AccessibilityUtil.SHORTCUTS_ORDER_IN_UI) {
            if (!android.provider.Flags.a11yStandaloneGestureEnabled()) {
                if ((shortcutType & GESTURE) == GESTURE) {
                    continue;
                }
            }
            if (hasValueInSettings(context, shortcutType, componentName)) {
            if (ShortcutUtils.isShortcutContained(
                    context, shortcutType, componentName.flattenToString())) {
                shortcutTypes |= shortcutType;
            }
        }
+3 −2
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ import androidx.preference.PreferenceScreen;
import androidx.recyclerview.widget.RecyclerView;

import com.android.internal.accessibility.common.ShortcutConstants;
import com.android.internal.accessibility.util.ShortcutUtils;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType;
@@ -630,8 +631,8 @@ public abstract class ToggleFeaturePreferenceFragment extends DashboardFragment

        final int shortcutTypes = getUserPreferredShortcutTypes();
        mShortcutPreference.setChecked(
                AccessibilityUtil.hasValuesInSettings(getPrefContext(), shortcutTypes,
                        mComponentName));
                ShortcutUtils.isShortcutContained(
                        getPrefContext(), shortcutTypes, mComponentName.flattenToString()));
        mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
    }

+1 −0
Original line number Diff line number Diff line
sdk=NEWEST_SDK
shadows=\
   com.android.settings.testutils.shadow.ShadowThreadUtils \
   com.android.settings.testutils.shadow.ShadowAccessibilityManager \
   com.android.settings.network.ShadowServiceManagerExtend
instrumentedPackages=androidx.preference
sqliteMode=native
 No newline at end of file
+4 −3
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.settings.accessibility;

import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.SOFTWARE;

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.ArgumentMatchers.any;
@@ -564,9 +566,8 @@ public class AccessibilitySettingsTest {
    }

    private void setShortcutEnabled(ComponentName componentName, boolean enabled) {
        Settings.Secure.putString(mContext.getContentResolver(),
                Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS,
                enabled ? componentName.flattenToString() : "");
        mShadowAccessibilityManager.setAccessibilityShortcutTargets(
                SOFTWARE, (enabled) ? List.of(componentName.flattenToString()) : List.of());
    }

    private BooleanSubject assertUriObserversContainsClazz(
Loading