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

Commit 2d8bdb14 authored by Rhed Jao's avatar Rhed Jao
Browse files

Removes shortcut target when an a11y service is unbound

The accessibility button and shortcut target is updated by
the Settings app when the user turn on/off the a11y service.
It worked fine before an a11y service disables and turns off
itself using disableSelf api. The accessibility button and
shortcut settings can not get update in this case. Removes
shortcut target if an a11y service is unbound to fix this
issue.

Bug: 156237174
Test: atest AccessibilityShortcutTest
Change-Id: Ie15f7fe06644bd35d30d87383b25df81bf29056d
parent 4b510ab9
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -1540,6 +1540,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
            } else {
                if (service != null) {
                    service.unbindLocked();
                    removeShortcutTargetForUnboundServiceLocked(userState, service);
                }
            }
        }
@@ -2314,6 +2315,36 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
        scheduleNotifyClientsOfServicesStateChangeLocked(userState);
    }

    /**
     * Remove the shortcut target for the unbound service which is requesting accessibility button
     * and targeting sdk > Q from the accessibility button and shortcut.
     *
     * @param userState The accessibility user state.
     * @param service The unbound service.
     */
    private void removeShortcutTargetForUnboundServiceLocked(AccessibilityUserState userState,
            AccessibilityServiceConnection service) {
        if (!service.mRequestAccessibilityButton
                || service.getServiceInfo().getResolveInfo().serviceInfo.applicationInfo
                .targetSdkVersion <= Build.VERSION_CODES.Q) {
            return;
        }
        final ComponentName serviceName = service.getComponentName();
        if (userState.removeShortcutTargetLocked(ACCESSIBILITY_SHORTCUT_KEY, serviceName)) {
            final Set<String> currentTargets = userState.getShortcutTargetsLocked(
                    ACCESSIBILITY_SHORTCUT_KEY);
            persistColonDelimitedSetToSettingLocked(
                    Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE,
                    userState.mUserId, currentTargets, str -> str);
        }
        if (userState.removeShortcutTargetLocked(ACCESSIBILITY_BUTTON, serviceName)) {
            final Set<String> currentTargets = userState.getShortcutTargetsLocked(
                    ACCESSIBILITY_BUTTON);
            persistColonDelimitedSetToSettingLocked(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS,
                    userState.mUserId, currentTargets, str -> str);
        }
    }

    private void updateRecommendedUiTimeoutLocked(AccessibilityUserState userState) {
        int newNonInteractiveUiTimeout = userState.getUserNonInteractiveUiTimeoutLocked();
        int newInteractiveUiTimeout = userState.getUserInteractiveUiTimeoutLocked();
+19 −0
Original line number Diff line number Diff line
@@ -630,6 +630,25 @@ class AccessibilityUserState {
        return false;
    }

    /**
     * Removes given shortcut target in the list.
     *
     * @param shortcutType The shortcut type.
     * @param target The component name of the shortcut target.
     * @return true if the shortcut target is removed.
     */
    public boolean removeShortcutTargetLocked(@ShortcutType int shortcutType,
            ComponentName target) {
        return getShortcutTargetsLocked(shortcutType).removeIf(name -> {
            ComponentName componentName;
            if (name == null
                    || (componentName = ComponentName.unflattenFromString(name)) == null) {
                return false;
            }
            return componentName.equals(target);
        });
    }

    /**
     * Returns installed accessibility service info by the given service component name.
     */