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

Commit ed45cc9d authored by Daniel Norman's avatar Daniel Norman Committed by Android Build Coastguard Worker
Browse files

RESTRICT AUTOMERGE Stops hiding a11y services with the same package+label as an activity.

Bug: 353700779
Test: Install poc APKs from the bug, observe issue not reproducible
Test: (automated tests on 'main' branch)
Flag: NONE security fix
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:15aca5e3cebb991a830f80b1ea3a636edcdc9e78)
Merged-In: Ia8d43229d277dd4442173166ae0402f05096da4b
Change-Id: Ia8d43229d277dd4442173166ae0402f05096da4b
parent c154b677
Loading
Loading
Loading
Loading
+1 −26
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import android.accessibilityservice.AccessibilityShortcutInfo;
import android.app.settings.SettingsEnums;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ServiceInfo;
import android.hardware.input.InputManager;
import android.os.Bundle;
import android.os.Handler;
@@ -29,7 +28,6 @@ import android.os.UserHandle;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.Pair;
import android.view.InputDevice;
import android.view.accessibility.AccessibilityManager;

@@ -57,8 +55,6 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/** Activity with the accessibility settings. */
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
@@ -458,20 +454,9 @@ public class AccessibilitySettings extends DashboardFragment implements
                        UserHandle.myUserId());
        final List<AccessibilityActivityPreference> activityList =
                preferenceHelper.createAccessibilityActivityPreferenceList(installedShortcutList);
        final Set<Pair<String, CharSequence>> packageLabelPairs =
                activityList.stream()
                        .map(a11yActivityPref -> new Pair<>(
                                a11yActivityPref.getPackageName(), a11yActivityPref.getLabel())
                        ).collect(Collectors.toSet());

        // Remove duplicate item here, new a ArrayList to copy unmodifiable list result
        // (getInstalledAccessibilityServiceList).

        final List<AccessibilityServiceInfo> installedServiceList = new ArrayList<>(
                a11yManager.getInstalledAccessibilityServiceList());
        if (!packageLabelPairs.isEmpty()) {
            installedServiceList.removeIf(
                    target -> containsPackageAndLabelInList(packageLabelPairs, target));
        }
        final List<RestrictedPreference> serviceList =
                preferenceHelper.createAccessibilityServicePreferenceList(installedServiceList);

@@ -482,16 +467,6 @@ public class AccessibilitySettings extends DashboardFragment implements
        return preferenceList;
    }

    private boolean containsPackageAndLabelInList(
            Set<Pair<String, CharSequence>> packageLabelPairs,
            AccessibilityServiceInfo targetServiceInfo) {
        final ServiceInfo serviceInfo = targetServiceInfo.getResolveInfo().serviceInfo;
        final String servicePackageName = serviceInfo.packageName;
        final CharSequence serviceLabel = serviceInfo.loadLabel(getPackageManager());

        return packageLabelPairs.contains(new Pair<>(servicePackageName, serviceLabel));
    }

    private void initializePreBundledServicesMapFromArray(String categoryKey, int key) {
        String[] services = getResources().getStringArray(key);
        PreferenceCategory category = mCategoryToPrefCategoryMap.get(categoryKey);