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

Commit c7988a90 authored by Bernardo Rufino's avatar Bernardo Rufino
Browse files

Allow sysUI to send a11y events for other package and user

As discussed, we:
* Allow apps with INTERACT_ACCROSS_USERS(_FULL) to specify an explicit
user (instead of just USER_CURRENT).
* Introduce new signature permission ACT_AS_PACKAGE_FOR_ACCESSIBILITY
and grant it to sysUI. This permissions allow holders to specify another
package on behalf of which they can perform a11y operations.

This is for toasts since now sysUI renders toasts on behalf of the app
for apps targeting R+.

Bug: 152839254
Test: atest FrameworksServicesTests:AccessibilitySecurityPolicyTest
      FrameworksServicesTests:AccessibilityWindowManagerTest
      android.widget.cts.ToastTest
Change-Id: I3541045d574518571f348051d53e24ff1a4a67ef
parent 6d5625c5
Loading
Loading
Loading
Loading
+5 −0
Original line number Original line Diff line number Diff line
@@ -3201,6 +3201,11 @@
    <permission android:name="android.permission.MODIFY_ACCESSIBILITY_DATA"
    <permission android:name="android.permission.MODIFY_ACCESSIBILITY_DATA"
                android:protectionLevel="signature" />
                android:protectionLevel="signature" />


    <!-- @hide Allows an application to perform accessibility operations (e.g. send events) on
         behalf of another package. -->
    <permission android:name="android.permission.ACT_AS_PACKAGE_FOR_ACCESSIBILITY"
                android:protectionLevel="signature" />

    <!-- @hide Allows an application to change the accessibility volume. -->
    <!-- @hide Allows an application to change the accessibility volume. -->
    <permission android:name="android.permission.CHANGE_ACCESSIBILITY_VOLUME"
    <permission android:name="android.permission.CHANGE_ACCESSIBILITY_VOLUME"
                android:protectionLevel="signature" />
                android:protectionLevel="signature" />
+1 −0
Original line number Original line Diff line number Diff line
@@ -219,6 +219,7 @@
    <!-- accessibility -->
    <!-- accessibility -->
    <uses-permission android:name="android.permission.MODIFY_ACCESSIBILITY_DATA" />
    <uses-permission android:name="android.permission.MODIFY_ACCESSIBILITY_DATA" />
    <uses-permission android:name="android.permission.MANAGE_ACCESSIBILITY" />
    <uses-permission android:name="android.permission.MANAGE_ACCESSIBILITY" />
    <uses-permission android:name="android.permission.ACT_AS_PACKAGE_FOR_ACCESSIBILITY" />


    <!-- to control accessibility volume -->
    <!-- to control accessibility volume -->
    <uses-permission android:name="android.permission.CHANGE_ACCESSIBILITY_VOLUME" />
    <uses-permission android:name="android.permission.CHANGE_ACCESSIBILITY_VOLUME" />
+2 −1
Original line number Original line Diff line number Diff line
@@ -599,7 +599,8 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub


            // Make sure the reported package is one the caller has access to.
            // Make sure the reported package is one the caller has access to.
            event.setPackageName(mSecurityPolicy.resolveValidReportedPackageLocked(
            event.setPackageName(mSecurityPolicy.resolveValidReportedPackageLocked(
                    event.getPackageName(), UserHandle.getCallingAppId(), resolvedUserId));
                    event.getPackageName(), UserHandle.getCallingAppId(), resolvedUserId,
                    getCallingPid()));


            // This method does nothing for a background user.
            // This method does nothing for a background user.
            if (resolvedUserId == mCurrentUserId) {
            if (resolvedUserId == mCurrentUserId) {
+8 −3
Original line number Original line Diff line number Diff line
@@ -167,11 +167,12 @@ public class AccessibilitySecurityPolicy {
     * @param packageName The package name the app wants to expose
     * @param packageName The package name the app wants to expose
     * @param appId The app's id
     * @param appId The app's id
     * @param userId The app's user id
     * @param userId The app's user id
     * @param pid The app's process pid that requested this
     * @return A package name that is valid to report
     * @return A package name that is valid to report
     */
     */
    @Nullable
    @Nullable
    public String resolveValidReportedPackageLocked(
    public String resolveValidReportedPackageLocked(
            @Nullable CharSequence packageName, int appId, int userId) {
            @Nullable CharSequence packageName, int appId, int userId, int pid) {
        // Okay to pass no package
        // Okay to pass no package
        if (packageName == null) {
        if (packageName == null) {
            return null;
            return null;
@@ -191,6 +192,11 @@ public class AccessibilitySecurityPolicy {
                .getHostedWidgetPackages(resolvedUid), packageNameStr)) {
                .getHostedWidgetPackages(resolvedUid), packageNameStr)) {
            return packageName.toString();
            return packageName.toString();
        }
        }
        // If app has the targeted permission to act as another package
        if (mContext.checkPermission(Manifest.permission.ACT_AS_PACKAGE_FOR_ACCESSIBILITY,
                pid, resolvedUid) == PackageManager.PERMISSION_GRANTED) {
            return packageName.toString();
        }
        // Otherwise, set the package to the first one in the UID
        // Otherwise, set the package to the first one in the UID
        final String[] packageNames = mPackageManager.getPackagesForUid(resolvedUid);
        final String[] packageNames = mPackageManager.getPackagesForUid(resolvedUid);
        if (ArrayUtils.isEmpty(packageNames)) {
        if (ArrayUtils.isEmpty(packageNames)) {
@@ -403,8 +409,7 @@ public class AccessibilitySecurityPolicy {
                || userId == UserHandle.USER_CURRENT_OR_SELF) {
                || userId == UserHandle.USER_CURRENT_OR_SELF) {
            return currentUserId;
            return currentUserId;
        }
        }
        throw new IllegalArgumentException("Calling user can be changed to only "
        return resolveProfileParentLocked(userId);
                + "UserHandle.USER_CURRENT or UserHandle.USER_CURRENT_OR_SELF.");
    }
    }


    /**
    /**
+2 −1
Original line number Original line Diff line number Diff line
@@ -955,7 +955,8 @@ public class AccessibilityWindowManager {


            // Makes sure the reported package is one the caller has access to.
            // Makes sure the reported package is one the caller has access to.
            packageName = mSecurityPolicy.resolveValidReportedPackageLocked(
            packageName = mSecurityPolicy.resolveValidReportedPackageLocked(
                    packageName, UserHandle.getCallingAppId(), resolvedUserId);
                    packageName, UserHandle.getCallingAppId(), resolvedUserId,
                    Binder.getCallingPid());


            windowId = sNextWindowId++;
            windowId = sNextWindowId++;
            // If the window is from a process that runs across users such as
            // If the window is from a process that runs across users such as
Loading