Merge "Cleanup deprecated functions in AccessibilityUtil" into main
This commit is contained in:
@@ -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()));
|
||||
}
|
||||
|
@@ -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.
|
||||
*
|
||||
|
@@ -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);
|
||||
|
@@ -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()));
|
||||
}
|
||||
|
@@ -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();
|
||||
|
@@ -30,8 +30,6 @@ import static com.android.internal.accessibility.common.ShortcutConstants.UserSh
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
import android.accessibilityservice.AccessibilityServiceInfo;
|
||||
import android.content.ComponentName;
|
||||
@@ -40,19 +38,16 @@ import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.os.Build;
|
||||
import android.os.UserHandle;
|
||||
import android.platform.test.annotations.DisableFlags;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.provider.Settings;
|
||||
import android.view.accessibility.AccessibilityManager;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType;
|
||||
import com.android.internal.accessibility.util.ShortcutUtils;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.AccessibilityTestUtils;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
@@ -62,7 +57,6 @@ import org.robolectric.RobolectricTestRunner;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@@ -217,71 +211,6 @@ public final class AccessibilityUtilTest {
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void optInAllValuesToSettings_optInValue_callsA11yManager() {
|
||||
AccessibilityManager a11yManager =
|
||||
AccessibilityTestUtils.setupMockAccessibilityManager(mContext);
|
||||
Set<String> shortcutTargets = Set.of(MOCK_COMPONENT_NAME.flattenToString());
|
||||
int shortcutTypes = SOFTWARE | HARDWARE
|
||||
| QUICK_SETTINGS;
|
||||
|
||||
AccessibilityUtil.optInAllValuesToSettings(mContext, shortcutTypes, MOCK_COMPONENT_NAME);
|
||||
|
||||
verify(a11yManager).enableShortcutsForTargets(
|
||||
/* enable= */ true, shortcutTypes,
|
||||
shortcutTargets, UserHandle.myUserId());
|
||||
verifyNoMoreInteractions(a11yManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void optInValueToSettings_optInValue_callsA11yManager() {
|
||||
AccessibilityManager a11yManager =
|
||||
AccessibilityTestUtils.setupMockAccessibilityManager(mContext);
|
||||
Set<String> shortcutTargets = Set.of(MOCK_COMPONENT_NAME2.flattenToString());
|
||||
|
||||
AccessibilityUtil.optInValueToSettings(
|
||||
mContext, HARDWARE, MOCK_COMPONENT_NAME2);
|
||||
|
||||
verify(a11yManager).enableShortcutsForTargets(
|
||||
/* enable= */ true, HARDWARE,
|
||||
shortcutTargets, UserHandle.myUserId());
|
||||
verifyNoMoreInteractions(a11yManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void optOutAllValuesToSettings_optOutValue_callsA1yManager() {
|
||||
AccessibilityManager a11yManager =
|
||||
AccessibilityTestUtils.setupMockAccessibilityManager(mContext);
|
||||
int shortcutTypes =
|
||||
SOFTWARE | HARDWARE
|
||||
| QUICK_SETTINGS;
|
||||
Set<String> shortcutTargets = Set.of(MOCK_COMPONENT_NAME.flattenToString());
|
||||
|
||||
AccessibilityUtil.optOutAllValuesFromSettings(mContext, shortcutTypes,
|
||||
MOCK_COMPONENT_NAME);
|
||||
|
||||
verify(a11yManager).enableShortcutsForTargets(
|
||||
/* enable= */ false,
|
||||
shortcutTypes,
|
||||
shortcutTargets, UserHandle.myUserId());
|
||||
verifyNoMoreInteractions(a11yManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void optOutValueFromSettings_optOutValue_callsA11yManager() {
|
||||
AccessibilityManager a11yManager =
|
||||
AccessibilityTestUtils.setupMockAccessibilityManager(mContext);
|
||||
Set<String> shortcutTargets = Set.of(MOCK_COMPONENT_NAME.flattenToString());
|
||||
|
||||
AccessibilityUtil.optOutValueFromSettings(
|
||||
mContext, QUICK_SETTINGS, MOCK_COMPONENT_NAME);
|
||||
|
||||
verify(a11yManager).enableShortcutsForTargets(
|
||||
/* enable= */ false, QUICK_SETTINGS,
|
||||
shortcutTargets, UserHandle.myUserId());
|
||||
verifyNoMoreInteractions(a11yManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertKeyFromSettings_shortcutTypeSoftware() {
|
||||
assertThat(AccessibilityUtil.convertKeyFromSettings(SOFTWARE))
|
||||
|
@@ -317,7 +317,7 @@ public class ToggleFeaturePreferenceFragmentTest {
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowFragment.class)
|
||||
public void showQuickSettingsTooltipIfNeeded_qsFlagOn_dontShowTooltipView() {
|
||||
public void showQuickSettingsTooltipIfNeeded_dontShowTooltipView() {
|
||||
mFragment.showQuickSettingsTooltipIfNeeded(QuickSettingsTooltipType.GUIDE_TO_EDIT);
|
||||
|
||||
assertThat(getLatestPopupWindow()).isNull();
|
||||
|
Reference in New Issue
Block a user