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

Commit 6107fd85 authored by Riley Jones's avatar Riley Jones
Browse files

Cleanup deprecated functions in AccessibilityUtil

Flag: EXEMPT code cleanup
Bug: 367414968
Test: atest com.android.settings.accessibility
Change-Id: If69a964720fc91ce0ad3661f956c4818f4f2f9dd
parent 1b53ae56
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import static com.android.settings.accessibility.AccessibilityUtil.getShortcutSu
import static com.android.settings.accessibility.ToggleFeaturePreferenceFragment.KEY_GENERAL_CATEGORY;
import static com.android.settings.accessibility.ToggleFeaturePreferenceFragment.KEY_SAVED_QS_TOOLTIP_TYPE;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.app.settings.SettingsEnums;
@@ -51,6 +52,7 @@ import com.google.android.setupcompat.util.WizardManagerHelper;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * Base class for accessibility fragments shortcut functions and dialog management.
@@ -232,6 +234,7 @@ public abstract class AccessibilityShortcutPreferenceFragment extends Restricted
        );
    }

    @SuppressLint("MissingPermission")
    @Override
    public void onToggleClicked(ShortcutPreference preference) {
        if (getComponentName() == null) {
@@ -239,13 +242,12 @@ public abstract class AccessibilityShortcutPreferenceFragment extends Restricted
        }

        final int shortcutTypes = getUserPreferredShortcutTypes();
        if (preference.isChecked()) {
            AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes,
                    getComponentName());
        final boolean isChecked = preference.isChecked();
        getPrefContext().getSystemService(AccessibilityManager.class).enableShortcutsForTargets(
                isChecked, shortcutTypes,
                Set.of(getComponentName().flattenToString()), getPrefContext().getUserId());
        if (isChecked) {
            showDialog(DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL);
        } else {
            AccessibilityUtil.optOutAllValuesFromSettings(getPrefContext(), shortcutTypes,
                    getComponentName());
        }
        mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
    }
+0 −109
Original line number Diff line number Diff line
@@ -60,7 +60,6 @@ import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Set;

/** Provides utility methods to accessibility settings only. */
public final class AccessibilityUtil {
@@ -195,114 +194,6 @@ public final class AccessibilityUtil {
                : AccessibilityServiceFragmentType.TOGGLE;
    }

    /**
     * Opts in component name into multiple {@code shortcutTypes} colon-separated string in
     * Settings.
     *
     * @param context       The current context.
     * @param shortcutTypes A combination of {@link UserShortcutType}.
     * @param componentName The component name that need to be opted in Settings.
     *
     * @deprecated use
     * {@link AccessibilityManager#enableShortcutsForTargets(boolean, int, Set, int)} instead.
     *
     * (TODO 367414968: finish removal.)
     */
    @Deprecated
    static void optInAllValuesToSettings(Context context, int shortcutTypes,
            @NonNull ComponentName componentName) {
        AccessibilityManager a11yManager = context.getSystemService(AccessibilityManager.class);
        if (a11yManager != null) {
            a11yManager.enableShortcutsForTargets(
                    /* enable= */ true,
                    shortcutTypes,
                    Set.of(componentName.flattenToString()),
                    UserHandle.myUserId()
            );
        }
    }

    /**
     * Opts in component name into {@code shortcutType} colon-separated string in Settings.
     *
     * @param context       The current context.
     * @param shortcutType  The preferred shortcut type user selected.
     * @param componentName The component name that need to be opted in Settings.
     *
     * @deprecated use
     * {@link AccessibilityManager#enableShortcutsForTargets(boolean, int, Set, int)} instead.
     *
     * (TODO 367414968: finish removal.)
     */
    @Deprecated
    @VisibleForTesting
    static void optInValueToSettings(Context context, @UserShortcutType int shortcutType,
            @NonNull ComponentName componentName) {
        AccessibilityManager a11yManager = context.getSystemService(AccessibilityManager.class);
        if (a11yManager != null) {
            a11yManager.enableShortcutsForTargets(
                    /* enable= */ true,
                    shortcutType,
                    Set.of(componentName.flattenToString()),
                    UserHandle.myUserId()
            );
        }
    }

    /**
     * Opts out component name into multiple {@code shortcutTypes} colon-separated string in
     * Settings.
     *
     * @param context       The current context.
     * @param shortcutTypes A combination of {@link UserShortcutType}.
     * @param componentName The component name that need to be opted out from Settings.
     *
     * @deprecated use
     * {@link AccessibilityManager#enableShortcutsForTargets(boolean, int, Set, int)} instead.
     *
     * (TODO 367414968: finish removal.)
     */
    @Deprecated
    static void optOutAllValuesFromSettings(Context context, int shortcutTypes,
            @NonNull ComponentName componentName) {
        AccessibilityManager a11yManager = context.getSystemService(AccessibilityManager.class);
        if (a11yManager != null) {
            a11yManager.enableShortcutsForTargets(
                    /* enable= */ false,
                    shortcutTypes,
                    Set.of(componentName.flattenToString()),
                    UserHandle.myUserId()
            );
        }
    }

    /**
     * Opts out component name into {@code shortcutType} colon-separated string in Settings.
     *
     * @param context       The current context.
     * @param shortcutType  The preferred shortcut type user selected.
     * @param componentName The component name that need to be opted out from Settings.
     *
     * @deprecated use
     * {@link AccessibilityManager#enableShortcutsForTargets(boolean, int, Set, int)} instead.
     *
     * (TODO 367414968: finish removal.)
     */
    @Deprecated
    @VisibleForTesting
    static void optOutValueFromSettings(Context context, @UserShortcutType int shortcutType,
            @NonNull ComponentName componentName) {
        AccessibilityManager a11yManager = context.getSystemService(AccessibilityManager.class);
        if (a11yManager != null) {
            a11yManager.enableShortcutsForTargets(
                    /* enable= */ false,
                    shortcutType,
                    Set.of(componentName.flattenToString()),
                    UserHandle.myUserId()
            );
        }
    }

    /**
     * Returns if component name existed in one of {@code shortcutTypes} string in Settings.
     *
+11 −3
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static com.android.settings.accessibility.AccessibilityDialogUtils.Dialog
import static com.android.settings.accessibility.AccessibilityStatsLogUtils.logAccessibilityServiceEnabled;

import android.accessibilityservice.AccessibilityServiceInfo;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.settings.SettingsEnums;
@@ -53,6 +54,7 @@ import com.android.settingslib.accessibility.AccessibilityUtils;

import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;

/** Fragment for providing toggle bar and basic accessibility service setup. */
@@ -323,6 +325,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends
        }
    }

    @SuppressLint("MissingPermission")
    @Override
    public void onToggleClicked(ShortcutPreference preference) {
        final int shortcutTypes = getUserPreferredShortcutTypes();
@@ -337,8 +340,10 @@ public class ToggleAccessibilityServicePreferenceFragment extends
                onAllowButtonFromShortcutToggleClicked();
            }
        } else {
            AccessibilityUtil.optOutAllValuesFromSettings(getPrefContext(), shortcutTypes,
                    mComponentName);
            getPrefContext().getSystemService(AccessibilityManager.class)
                            .enableShortcutsForTargets(false, shortcutTypes,
                                    Set.of(mComponentName.flattenToString()),
                                    getPrefContext().getUserId());
        }
        mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
    }
@@ -475,11 +480,14 @@ public class ToggleAccessibilityServicePreferenceFragment extends
        mWarningDialog.dismiss();
    }

    @SuppressLint("MissingPermission")
    void onAllowButtonFromShortcutToggleClicked() {
        mShortcutPreference.setChecked(true);

        final int shortcutTypes = getUserPreferredShortcutTypes();
        AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes, mComponentName);
        getPrefContext().getSystemService(AccessibilityManager.class)
                .enableShortcutsForTargets(true, shortcutTypes,
                        Set.of(mComponentName.flattenToString()), getPrefContext().getUserId());

        mIsDialogShown.set(false);
        showPopupDialog(DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL);
+6 −6
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ import com.google.android.setupcompat.util.WizardManagerHelper;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * Base class for accessibility fragments with toggle, shortcut, some helper functions
@@ -685,13 +686,12 @@ public abstract class ToggleFeaturePreferenceFragment extends DashboardFragment
        }

        final int shortcutTypes = getUserPreferredShortcutTypes();
        if (preference.isChecked()) {
            AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes,
                    mComponentName);
        final boolean isChecked = preference.isChecked();
        getPrefContext().getSystemService(AccessibilityManager.class).enableShortcutsForTargets(
                isChecked, shortcutTypes,
                Set.of(mComponentName.flattenToString()), getPrefContext().getUserId());
        if (isChecked) {
            showDialog(DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL);
        } else {
            AccessibilityUtil.optOutAllValuesFromSettings(getPrefContext(), shortcutTypes,
                    mComponentName);
        }
        mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
    }
+1 −1
Original line number Diff line number Diff line
@@ -153,7 +153,7 @@ public class AccessibilityShortcutPreferenceFragmentTest {

    @Test
    @Config(shadows = ShadowFragment.class)
    public void showQuickSettingsTooltipIfNeeded_qsFlagOn_dontShowTooltipView() {
    public void showQuickSettingsTooltipIfNeeded_dontShowTooltipView() {
        mFragment.showQuickSettingsTooltipIfNeeded(QuickSettingsTooltipType.GUIDE_TO_EDIT);

        assertThat(getLatestPopupWindow()).isNull();
Loading