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

Commit 405dfa29 authored by jasonwshsu's avatar jasonwshsu
Browse files

Stops hiding a11y services with the same package+label as an activity in shortcut logic.

Root Cause: We change the logic in Accessibility Settings to show all a11y services and activities,
hand over to developer to judge whether they want to show service type and activity type at the same
time.

Solution: Change the logic to show all a11y services and a11y activities in shortcut logic

Bug: 362190010
Test: Install poc APKs from the bug, observe both shortcuts can be seen on the screen
Flag: EXEMPT small bugfix
Change-Id: Ib0eced2e3d010c1ecacc44496f471518f4b6669d
parent ebf8e0c8
Loading
Loading
Loading
Loading
+2 −34
Original line number Original line Diff line number Diff line
@@ -109,45 +109,13 @@ public final class AccessibilityTargetHelper {
    public static List<AccessibilityTarget> getInstalledTargets(Context context,
    public static List<AccessibilityTarget> getInstalledTargets(Context context,
            @UserShortcutType int shortcutType) {
            @UserShortcutType int shortcutType) {
        final List<AccessibilityTarget> targets = new ArrayList<>();
        final List<AccessibilityTarget> targets = new ArrayList<>();
        targets.addAll(getAccessibilityFilteredTargets(context, shortcutType));
        targets.addAll(getAccessibilityServiceTargets(context, shortcutType));
        targets.addAll(getAccessibilityActivityTargets(context, shortcutType));
        targets.addAll(getAllowListingFeatureTargets(context, shortcutType));
        targets.addAll(getAllowListingFeatureTargets(context, shortcutType));


        return targets;
        return targets;
    }
    }


    private static List<AccessibilityTarget> getAccessibilityFilteredTargets(Context context,
            @UserShortcutType int shortcutType) {
        final List<AccessibilityTarget> serviceTargets =
                getAccessibilityServiceTargets(context, shortcutType);
        final List<AccessibilityTarget> activityTargets =
                getAccessibilityActivityTargets(context, shortcutType);

        for (AccessibilityTarget activityTarget : activityTargets) {
            serviceTargets.removeIf(
                    serviceTarget -> arePackageNameAndLabelTheSame(serviceTarget, activityTarget));
        }

        final List<AccessibilityTarget> targets = new ArrayList<>();
        targets.addAll(serviceTargets);
        targets.addAll(activityTargets);

        return targets;
    }

    private static boolean arePackageNameAndLabelTheSame(@NonNull AccessibilityTarget serviceTarget,
            @NonNull AccessibilityTarget activityTarget) {
        final ComponentName serviceComponentName =
                ComponentName.unflattenFromString(serviceTarget.getId());
        final ComponentName activityComponentName =
                ComponentName.unflattenFromString(activityTarget.getId());
        final boolean isSamePackageName = activityComponentName.getPackageName().equals(
                serviceComponentName.getPackageName());
        final boolean isSameLabel = activityTarget.getLabel().equals(
                serviceTarget.getLabel());

        return isSamePackageName && isSameLabel;
    }

    private static List<AccessibilityTarget> getAccessibilityServiceTargets(Context context,
    private static List<AccessibilityTarget> getAccessibilityServiceTargets(Context context,
            @UserShortcutType int shortcutType) {
            @UserShortcutType int shortcutType) {
        final AccessibilityManager am = (AccessibilityManager) context.getSystemService(
        final AccessibilityManager am = (AccessibilityManager) context.getSystemService(