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

Commit d223db31 authored by Svet Ganov's avatar Svet Ganov Committed by Svetoslav Ganov
Browse files

Add infrastructure for running a11y tests in instant mode

This change adds a special flag when binding to a service to request
instant apps to be considered as well (assuming the caller has the
permission to see instant apps). This flag is scoped only for the
platform to use and is intended only for development and testing.
Specifically, we have a class of CTS tests that has tests plus service
in the same APK (accessibility, printing, autofill, any other plugin
based sub-system).

Instead of doing the tediuous work split all these into one APK with
tests and one with the services where the latter exposes a remote
interface to the former, we will be adding shell commands to the
dedicated sub-system to allow temporary binding to plugins provided
by instant apps. The goal is not validating the plugin behavious,
rather a working plugin is required to test app side funcionality.

This change adds a shell command to allow the a11y manager serivce
to bind to plugins provided by instant apps. This is required to
be able to run relevant CTS test cases in instant mode.

Test: cts-tradefed run cts-dev -m CtsAccessibilityTestCases
      cts-tradefed run cts-dev -m CtsAccessibilityServiceTestCases

Bug: 70978575

Change-Id: Ifced735a9a6e495747372dd8b00fdd64933a09c7
parent 3cb35f37
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -323,6 +323,15 @@ public abstract class Context {
     */
    public static final int BIND_ADJUST_WITH_ACTIVITY = 0x0080;

    /**
     * @hide Flag for {@link #bindService}: allows binding to a service provided
     * by an instant app. Note that the caller may not have access to the instant
     * app providing the service which is a violation of the instant app sandbox.
     * This flag is intended ONLY for development/testing and should be used with
     * great care. Only the system is allowed to use this flag.
     */
    public static final int BIND_ALLOW_INSTANT = 0x00400000;

    /**
     * @hide Flag for {@link #bindService}: like {@link #BIND_NOT_FOREGROUND}, but puts it
     * up in to the important background state (instead of transient).
+9 −1
Original line number Diff line number Diff line
@@ -3534,12 +3534,20 @@
    @hide -->
    <permission android:name="android.permission.ACCESS_INSTANT_APPS"
            android:protectionLevel="signature|installer|verifier" />
    <uses-permission android:name="android.permission.ACCESS_INSTANT_APPS"/>

    <!-- Allows the holder to view the instant applications on the device.
    @hide -->
    <permission android:name="android.permission.VIEW_INSTANT_APPS"
                android:protectionLevel="signature|preinstalled" />

    <!-- Allows the holder to manage whether the system can bind to services
         provided by instant apps. This permission is intended to protect
         test/development fucntionality and should be used only in such cases.
    @hide -->
    <permission android:name="android.permission.MANAGE_BIND_INSTANT_SERVICE"
                android:protectionLevel="signature" />

    <!-- Allows receiving the usage of media resource e.g. video/audio codec and
         graphic memory.
         @hide -->
+1 −0
Original line number Diff line number Diff line
@@ -132,6 +132,7 @@
    <uses-permission android:name="android.permission.CHANGE_OVERLAY_PACKAGES" />
    <!-- Permission needed to access privileged VR APIs -->
    <uses-permission android:name="android.permission.RESTRICTED_VR_ACCESS" />
    <uses-permission android:name="android.permission.MANAGE_BIND_INSTANT_SERVICE" />

    <application android:label="@string/app_label"
                 android:defaultToDeviceProtectedStorage="true"
+4 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.content.pm.ParceledListSlice;
import android.graphics.Region;
import android.os.Binder;
@@ -740,6 +741,9 @@ abstract class AbstractAccessibilityServiceConnection extends IAccessibilityServ

    @Override
    public boolean isFingerprintGestureDetectionAvailable() {
        if (!mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)) {
            return false;
        }
        if (isCapturingFingerprintGestures()) {
            FingerprintGestureDispatcher dispatcher =
                    mSystemSupport.getFingerprintGestureDispatcher();
+57 −7
Original line number Diff line number Diff line
@@ -64,7 +64,9 @@ import android.os.PowerManager;
import android.os.Process;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
import android.os.ResultReceiver;
import android.os.ServiceManager;
import android.os.ShellCallback;
import android.os.SystemClock;
import android.os.UserHandle;
import android.os.UserManager;
@@ -299,6 +301,14 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
        return state;
    }

    boolean getBindInstantServiceAllowed(int userId) {
        return  mSecurityPolicy.getBindInstantServiceAllowed(userId);
    }

    void setBindInstantServiceAllowed(int userId, boolean allowed) {
        mSecurityPolicy.setBindInstantServiceAllowed(userId, allowed);
    }

    private void registerBroadcastReceivers() {
        PackageMonitor monitor = new PackageMonitor() {
            @Override
@@ -1218,14 +1228,18 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
    private boolean readInstalledAccessibilityServiceLocked(UserState userState) {
        mTempAccessibilityServiceInfoList.clear();

        List<ResolveInfo> installedServices = mPackageManager.queryIntentServicesAsUser(
                new Intent(AccessibilityService.SERVICE_INTERFACE),
                PackageManager.GET_SERVICES
        int flags = PackageManager.GET_SERVICES
                | PackageManager.GET_META_DATA
                | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
                | PackageManager.MATCH_DIRECT_BOOT_AWARE
                        | PackageManager.MATCH_DIRECT_BOOT_UNAWARE,
                mCurrentUserId);
                | PackageManager.MATCH_DIRECT_BOOT_UNAWARE;

        if (userState.mBindInstantServiceAllowed) {
            flags |= PackageManager.MATCH_INSTANT;
        }

        List<ResolveInfo> installedServices = mPackageManager.queryIntentServicesAsUser(
                new Intent(AccessibilityService.SERVICE_INTERFACE), flags, mCurrentUserId);

        for (int i = 0, count = installedServices.size(); i < count; i++) {
            ResolveInfo resolveInfo = installedServices.get(i);
@@ -2709,6 +2723,14 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
        }
    }

    @Override
    public void onShellCommand(FileDescriptor in, FileDescriptor out,
            FileDescriptor err, String[] args, ShellCallback callback,
            ResultReceiver resultReceiver) {
        new AccessibilityShellCommand(this).exec(this, in, out, err, args,
                callback, resultReceiver);
    }

    final class WindowsForAccessibilityCallback implements
            WindowManagerInternal.WindowsForAccessibilityCallback {

@@ -3076,6 +3098,32 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
            return uidPackages;
        }

        private boolean getBindInstantServiceAllowed(int userId) {
            mContext.enforceCallingOrSelfPermission(
                    Manifest.permission.MANAGE_BIND_INSTANT_SERVICE,
                    "getBindInstantServiceAllowed");
            UserState state = mUserStates.get(userId);
            return (state != null) && state.mBindInstantServiceAllowed;
        }

        private void setBindInstantServiceAllowed(int userId, boolean allowed) {
            mContext.enforceCallingOrSelfPermission(
                    Manifest.permission.MANAGE_BIND_INSTANT_SERVICE,
                    "setBindInstantServiceAllowed");
            UserState state = mUserStates.get(userId);
            if (state == null) {
                if (!allowed) {
                    return;
                }
                state = new UserState(userId);
                mUserStates.put(userId, state);
            }
            if (state.mBindInstantServiceAllowed != allowed) {
                state.mBindInstantServiceAllowed = allowed;
                onUserStateChangedLocked(state);
            }
        }

        public void clearWindowsLocked() {
            List<WindowInfo> windows = Collections.emptyList();
            final int activeWindowId = mActiveWindowId;
@@ -3558,6 +3606,8 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
        public boolean mIsFilterKeyEventsEnabled;
        public boolean mAccessibilityFocusOnlyInActiveWindow;

        public boolean mBindInstantServiceAllowed;

        public UserState(int userId) {
            mUserId = userId;
        }
Loading