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

Commit 1888d500 authored by Felipe Leme's avatar Felipe Leme Committed by Automerger Merge Worker
Browse files

Merge "Minor improvements on a11y and instrumentation classes:" into udc-dev...

Merge "Minor improvements on a11y and instrumentation classes:" into udc-dev am: 7a7583ca am: e891b202

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/21939023



Change-Id: Ief9bc69a4fb88f116fdd12dc8c8c8530e9a6e2a8
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents db3a339c e891b202
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -2878,9 +2878,7 @@ public abstract class AccessibilityService extends Service {

        public IAccessibilityServiceClientWrapper(Context context, Looper looper,
                Callbacks callback) {
            mCallback = callback;
            mContext = context;
            mExecutor = new HandlerExecutor(new Handler(looper));
            this(context, new HandlerExecutor(new Handler(looper)), callback);
        }

        public void init(IAccessibilityServiceConnection connection, int connectionId,
+36 −2
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import android.os.RemoteException;
import android.os.SystemClock;
import android.os.UserHandle;
import android.util.ArraySet;
import android.util.DebugUtils;
import android.util.Log;
import android.util.SparseArray;
import android.view.Display;
@@ -111,6 +112,7 @@ public final class UiAutomation {
    private static final String LOG_TAG = UiAutomation.class.getSimpleName();

    private static final boolean DEBUG = false;
    private static final boolean VERBOSE = false;

    private static final int CONNECTION_ID_UNDEFINED = -1;

@@ -321,11 +323,18 @@ public final class UiAutomation {
     * @hide
     */
    public void connectWithTimeout(int flags, long timeoutMillis) throws TimeoutException {
        if (DEBUG) {
            Log.d(LOG_TAG, "connectWithTimeout: user=" + Process.myUserHandle().getIdentifier()
                    + ", flags=" + DebugUtils.flagsToString(UiAutomation.class, "FLAG_", flags)
                    + ", timeout=" + timeoutMillis + "ms");
        }
        synchronized (mLock) {
            throwIfConnectedLocked();
            if (mConnectionState == ConnectionState.CONNECTING) {
                if (DEBUG) Log.d(LOG_TAG, "already connecting");
                return;
            }
            if (DEBUG) Log.d(LOG_TAG, "setting state to CONNECTING");
            mConnectionState = ConnectionState.CONNECTING;
            mRemoteCallbackThread = new HandlerThread("UiAutomation");
            mRemoteCallbackThread.start();
@@ -341,6 +350,7 @@ public final class UiAutomation {
            // If UiAutomation is not allowed to use the accessibility subsystem, the
            // connection state should keep disconnected and not to start the client connection.
            if (!useAccessibility()) {
                if (DEBUG) Log.d(LOG_TAG, "setting state to DISCONNECTED");
                mConnectionState = ConnectionState.DISCONNECTED;
                return;
            }
@@ -357,6 +367,7 @@ public final class UiAutomation {
                final long elapsedTimeMillis = SystemClock.uptimeMillis() - startTimeMillis;
                final long remainingTimeMillis = timeoutMillis - elapsedTimeMillis;
                if (remainingTimeMillis <= 0) {
                    if (DEBUG) Log.d(LOG_TAG, "setting state to FAILED");
                    mConnectionState = ConnectionState.FAILED;
                    throw new TimeoutException("Timeout while connecting " + this);
                }
@@ -1367,7 +1378,8 @@ public final class UiAutomation {
            UserHandle userHandle) {
        try {
            if (DEBUG) {
                Log.i(LOG_TAG, "Granting runtime permission");
                Log.i(LOG_TAG, "Granting runtime permission (" + permission + ") to package "
                        + packageName + " on user " + userHandle);
            }
            // Calling out without a lock held.
            mUiAutomationConnection.grantRuntimePermission(packageName,
@@ -1592,7 +1604,7 @@ public final class UiAutomation {
    private class IAccessibilityServiceClientImpl extends IAccessibilityServiceClientWrapper {

        public IAccessibilityServiceClientImpl(Looper looper, int generationId) {
            super(null, looper, new Callbacks() {
            super(/* context= */ null, looper, new Callbacks() {
                private final int mGenerationId = generationId;

                /**
@@ -1606,10 +1618,21 @@ public final class UiAutomation {

                @Override
                public void init(int connectionId, IBinder windowToken) {
                    if (DEBUG) {
                        Log.d(LOG_TAG, "init(): connectionId=" + connectionId + ", windowToken="
                                + windowToken + ", user=" + Process.myUserHandle()
                                + ", mGenerationId=" + mGenerationId
                                + ", UiAutomation.mGenerationId="
                                + UiAutomation.this.mGenerationId);
                    }
                    synchronized (mLock) {
                        if (isGenerationChangedLocked()) {
                            if (DEBUG) {
                                Log.d(LOG_TAG, "init(): returning because generation id changed");
                            }
                            return;
                        }
                        if (DEBUG) Log.d(LOG_TAG, "setting state to CONNECTED");
                        mConnectionState = ConnectionState.CONNECTED;
                        mConnectionId = connectionId;
                        mLock.notifyAll();
@@ -1662,9 +1685,20 @@ public final class UiAutomation {

                @Override
                public void onAccessibilityEvent(AccessibilityEvent event) {
                    if (VERBOSE) {
                        Log.v(LOG_TAG, "onAccessibilityEvent(" + Process.myUserHandle() + "): "
                                + event);
                    }

                    final OnAccessibilityEventListener listener;
                    synchronized (mLock) {
                        if (isGenerationChangedLocked()) {
                            if (VERBOSE) {
                                Log.v(LOG_TAG, "onAccessibilityEvent(): returning because "
                                        + "generation id changed (from "
                                        + UiAutomation.this.mGenerationId + " to "
                                        + mGenerationId + ")");
                            }
                            return;
                        }
                        // It is not guaranteed that the accessibility framework sends events by the
+1 −0
Original line number Diff line number Diff line
@@ -103,6 +103,7 @@ public final class UiAutomationConnection extends IUiAutomationConnection.Stub {

    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    public UiAutomationConnection() {
        Log.d(TAG, "Created on user " + Process.myUserHandle());
    }

    @Override
+1 −0
Original line number Diff line number Diff line
@@ -975,6 +975,7 @@ public class AccessibilityRecord {
        append(builder, "AddedCount", mAddedCount);
        append(builder, "RemovedCount", mRemovedCount);
        append(builder, "ParcelableData", mParcelableData);
        append(builder, "DisplayId", mSourceDisplayId);
        builder.append(" ]");
        return builder;
    }
+5 −8
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.annotation.Nullable;
import android.app.UiAutomation;
import android.content.ComponentName;
import android.content.Context;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
import android.os.IBinder.DeathRecipient;
@@ -34,6 +35,7 @@ import android.view.Display;
import android.view.accessibility.AccessibilityEvent;

import com.android.internal.util.DumpUtils;
import com.android.server.utils.Slogf;
import com.android.server.wm.WindowManagerInternal;

import java.io.FileDescriptor;
@@ -51,12 +53,8 @@ class UiAutomationManager {

    private UiAutomationService mUiAutomationService;

    private AccessibilityServiceInfo mUiAutomationServiceInfo;

    private AbstractAccessibilityServiceConnection.SystemSupport mSystemSupport;

    private AccessibilityTrace mTrace;

    private int mUiAutomationFlags;

    UiAutomationManager(Object lock) {
@@ -97,9 +95,10 @@ class UiAutomationManager {
            WindowManagerInternal windowManagerInternal,
            SystemActionPerformer systemActionPerformer,
            AccessibilityWindowManager awm, int flags) {
        synchronized (mLock) {
        accessibilityServiceInfo.setComponentName(COMPONENT_NAME);

        Slogf.i(LOG_TAG, "Registering UiTestAutomationService (id=%s) when called by user %d",
                accessibilityServiceInfo.getId(), Binder.getCallingUserHandle().getIdentifier());
        synchronized (mLock) {
            if (mUiAutomationService != null) {
                throw new IllegalStateException(
                        "UiAutomationService " + mUiAutomationService.mServiceInterface
@@ -116,7 +115,6 @@ class UiAutomationManager {

            mUiAutomationFlags = flags;
            mSystemSupport = systemSupport;
            mTrace = trace;
            // Ignore registering UiAutomation if it is not allowed to use the accessibility
            // subsystem.
            if (!useAccessibility()) {
@@ -126,7 +124,6 @@ class UiAutomationManager {
                    mainHandler, mLock, securityPolicy, systemSupport, trace, windowManagerInternal,
                    systemActionPerformer, awm);
            mUiAutomationServiceOwner = owner;
            mUiAutomationServiceInfo = accessibilityServiceInfo;
            mUiAutomationService.mServiceInterface = serviceClient;
            try {
                mUiAutomationService.mServiceInterface.asBinder().linkToDeath(mUiAutomationService,