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

Commit da3e632b authored by Daniel Norman's avatar Daniel Norman Committed by Android (Google) Code Review
Browse files

Merge "Includes AccessibilityMenu-in-System in interaction controls category."

parents 561e8793 322fc449
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -64,8 +64,9 @@ public class AccessibilitySettings extends DashboardFragment {
    private static final String CATEGORY_CAPTIONS = "captions_category";
    private static final String CATEGORY_AUDIO = "audio_category";
    private static final String CATEGORY_DISPLAY = "display_category";
    private static final String CATEGORY_INTERACTION_CONTROL = "interaction_control_category";
    private static final String CATEGORY_DOWNLOADED_SERVICES = "user_installed_services_category";
    @VisibleForTesting
    static final String CATEGORY_INTERACTION_CONTROL = "interaction_control_category";

    private static final String[] CATEGORIES = new String[]{
            CATEGORY_SCREEN_READER, CATEGORY_CAPTIONS, CATEGORY_AUDIO, CATEGORY_DISPLAY,
@@ -144,7 +145,8 @@ public class AccessibilitySettings extends DashboardFragment {

    private final Map<String, PreferenceCategory> mCategoryToPrefCategoryMap =
            new ArrayMap<>();
    private final Map<Preference, PreferenceCategory> mServicePreferenceToPreferenceCategoryMap =
    @VisibleForTesting
    final Map<Preference, PreferenceCategory> mServicePreferenceToPreferenceCategoryMap =
            new ArrayMap<>();
    private final Map<ComponentName, PreferenceCategory> mPreBundledServiceComponentToCategoryMap =
            new ArrayMap<>();
@@ -352,6 +354,12 @@ public class AccessibilitySettings extends DashboardFragment {
        initializePreBundledServicesMapFromArray(CATEGORY_INTERACTION_CONTROL,
                R.array.config_preinstalled_interaction_control_services);

        // ACCESSIBILITY_MENU_IN_SYSTEM is a default pre-bundled interaction control service.
        // If the device opts out of including this service then this is a no-op.
        mPreBundledServiceComponentToCategoryMap.put(
                AccessibilityManager.ACCESSIBILITY_MENU_IN_SYSTEM,
                mCategoryToPrefCategoryMap.get(CATEGORY_INTERACTION_CONTROL));

        final List<RestrictedPreference> preferenceList = getInstalledAccessibilityList(
                getPrefContext());

+34 −4
Original line number Diff line number Diff line
@@ -328,13 +328,43 @@ public class AccessibilitySettingsTest {

    }

    @Test
    @Config(shadows = {ShadowFragment.class, ShadowUserManager.class})
    public void testAccessibilityMenuInSystem_IncludedInInteractionControl() {
        mShadowAccessibilityManager.setInstalledAccessibilityServiceList(
                List.of(getMockAccessibilityServiceInfo(
                        AccessibilityManager.ACCESSIBILITY_MENU_IN_SYSTEM)));
        setupFragment();

        final RestrictedPreference pref = mFragment.getPreferenceScreen().findPreference(
                AccessibilityManager.ACCESSIBILITY_MENU_IN_SYSTEM.flattenToString());
        final String prefCategory = mFragment.mServicePreferenceToPreferenceCategoryMap.get(
                pref).getKey();
        assertThat(prefCategory).isEqualTo(AccessibilitySettings.CATEGORY_INTERACTION_CONTROL);
    }

    @Test
    @Config(shadows = {ShadowFragment.class, ShadowUserManager.class})
    public void testAccessibilityMenuInSystem_NoPrefWhenNotInstalled() {
        mShadowAccessibilityManager.setInstalledAccessibilityServiceList(List.of());
        setupFragment();

        final RestrictedPreference pref = mFragment.getPreferenceScreen().findPreference(
                AccessibilityManager.ACCESSIBILITY_MENU_IN_SYSTEM.flattenToString());
        assertThat(pref).isNull();
    }

    private AccessibilityServiceInfo getMockAccessibilityServiceInfo(String packageName,
            String className) {
        return getMockAccessibilityServiceInfo(new ComponentName(packageName, className));
    }

    private AccessibilityServiceInfo getMockAccessibilityServiceInfo(ComponentName componentName) {
        final ApplicationInfo applicationInfo = new ApplicationInfo();
        final ServiceInfo serviceInfo = new ServiceInfo();
        applicationInfo.packageName = packageName;
        serviceInfo.packageName = packageName;
        serviceInfo.name = className;
        applicationInfo.packageName = componentName.getPackageName();
        serviceInfo.packageName = componentName.getPackageName();
        serviceInfo.name = componentName.getClassName();
        serviceInfo.applicationInfo = applicationInfo;

        final ResolveInfo resolveInfo = new ResolveInfo();
@@ -342,7 +372,7 @@ public class AccessibilitySettingsTest {
        try {
            final AccessibilityServiceInfo info = new AccessibilityServiceInfo(resolveInfo,
                    mContext);
            info.setComponentName(new ComponentName(packageName, className));
            info.setComponentName(componentName);
            return info;
        } catch (XmlPullParserException | IOException e) {
            // Do nothing