Merge "Minor improvements on a11y and instrumentation classes:" into udc-dev am: 7a7583ca31
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/21939023 Change-Id: I70b6ad65a8a003b4d79bb6a1f07021655fc7be00 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -2878,9 +2878,7 @@ public abstract class AccessibilityService extends Service {
|
|||||||
|
|
||||||
public IAccessibilityServiceClientWrapper(Context context, Looper looper,
|
public IAccessibilityServiceClientWrapper(Context context, Looper looper,
|
||||||
Callbacks callback) {
|
Callbacks callback) {
|
||||||
mCallback = callback;
|
this(context, new HandlerExecutor(new Handler(looper)), callback);
|
||||||
mContext = context;
|
|
||||||
mExecutor = new HandlerExecutor(new Handler(looper));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(IAccessibilityServiceConnection connection, int connectionId,
|
public void init(IAccessibilityServiceConnection connection, int connectionId,
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ import android.os.RemoteException;
|
|||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.util.ArraySet;
|
import android.util.ArraySet;
|
||||||
|
import android.util.DebugUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
import android.view.Display;
|
import android.view.Display;
|
||||||
@@ -111,6 +112,7 @@ public final class UiAutomation {
|
|||||||
private static final String LOG_TAG = UiAutomation.class.getSimpleName();
|
private static final String LOG_TAG = UiAutomation.class.getSimpleName();
|
||||||
|
|
||||||
private static final boolean DEBUG = false;
|
private static final boolean DEBUG = false;
|
||||||
|
private static final boolean VERBOSE = false;
|
||||||
|
|
||||||
private static final int CONNECTION_ID_UNDEFINED = -1;
|
private static final int CONNECTION_ID_UNDEFINED = -1;
|
||||||
|
|
||||||
@@ -321,11 +323,18 @@ public final class UiAutomation {
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public void connectWithTimeout(int flags, long timeoutMillis) throws TimeoutException {
|
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) {
|
synchronized (mLock) {
|
||||||
throwIfConnectedLocked();
|
throwIfConnectedLocked();
|
||||||
if (mConnectionState == ConnectionState.CONNECTING) {
|
if (mConnectionState == ConnectionState.CONNECTING) {
|
||||||
|
if (DEBUG) Log.d(LOG_TAG, "already connecting");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (DEBUG) Log.d(LOG_TAG, "setting state to CONNECTING");
|
||||||
mConnectionState = ConnectionState.CONNECTING;
|
mConnectionState = ConnectionState.CONNECTING;
|
||||||
mRemoteCallbackThread = new HandlerThread("UiAutomation");
|
mRemoteCallbackThread = new HandlerThread("UiAutomation");
|
||||||
mRemoteCallbackThread.start();
|
mRemoteCallbackThread.start();
|
||||||
@@ -341,6 +350,7 @@ public final class UiAutomation {
|
|||||||
// If UiAutomation is not allowed to use the accessibility subsystem, the
|
// If UiAutomation is not allowed to use the accessibility subsystem, the
|
||||||
// connection state should keep disconnected and not to start the client connection.
|
// connection state should keep disconnected and not to start the client connection.
|
||||||
if (!useAccessibility()) {
|
if (!useAccessibility()) {
|
||||||
|
if (DEBUG) Log.d(LOG_TAG, "setting state to DISCONNECTED");
|
||||||
mConnectionState = ConnectionState.DISCONNECTED;
|
mConnectionState = ConnectionState.DISCONNECTED;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -357,6 +367,7 @@ public final class UiAutomation {
|
|||||||
final long elapsedTimeMillis = SystemClock.uptimeMillis() - startTimeMillis;
|
final long elapsedTimeMillis = SystemClock.uptimeMillis() - startTimeMillis;
|
||||||
final long remainingTimeMillis = timeoutMillis - elapsedTimeMillis;
|
final long remainingTimeMillis = timeoutMillis - elapsedTimeMillis;
|
||||||
if (remainingTimeMillis <= 0) {
|
if (remainingTimeMillis <= 0) {
|
||||||
|
if (DEBUG) Log.d(LOG_TAG, "setting state to FAILED");
|
||||||
mConnectionState = ConnectionState.FAILED;
|
mConnectionState = ConnectionState.FAILED;
|
||||||
throw new TimeoutException("Timeout while connecting " + this);
|
throw new TimeoutException("Timeout while connecting " + this);
|
||||||
}
|
}
|
||||||
@@ -1367,7 +1378,8 @@ public final class UiAutomation {
|
|||||||
UserHandle userHandle) {
|
UserHandle userHandle) {
|
||||||
try {
|
try {
|
||||||
if (DEBUG) {
|
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.
|
// Calling out without a lock held.
|
||||||
mUiAutomationConnection.grantRuntimePermission(packageName,
|
mUiAutomationConnection.grantRuntimePermission(packageName,
|
||||||
@@ -1592,7 +1604,7 @@ public final class UiAutomation {
|
|||||||
private class IAccessibilityServiceClientImpl extends IAccessibilityServiceClientWrapper {
|
private class IAccessibilityServiceClientImpl extends IAccessibilityServiceClientWrapper {
|
||||||
|
|
||||||
public IAccessibilityServiceClientImpl(Looper looper, int generationId) {
|
public IAccessibilityServiceClientImpl(Looper looper, int generationId) {
|
||||||
super(null, looper, new Callbacks() {
|
super(/* context= */ null, looper, new Callbacks() {
|
||||||
private final int mGenerationId = generationId;
|
private final int mGenerationId = generationId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1606,10 +1618,21 @@ public final class UiAutomation {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(int connectionId, IBinder windowToken) {
|
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) {
|
synchronized (mLock) {
|
||||||
if (isGenerationChangedLocked()) {
|
if (isGenerationChangedLocked()) {
|
||||||
|
if (DEBUG) {
|
||||||
|
Log.d(LOG_TAG, "init(): returning because generation id changed");
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (DEBUG) Log.d(LOG_TAG, "setting state to CONNECTED");
|
||||||
mConnectionState = ConnectionState.CONNECTED;
|
mConnectionState = ConnectionState.CONNECTED;
|
||||||
mConnectionId = connectionId;
|
mConnectionId = connectionId;
|
||||||
mLock.notifyAll();
|
mLock.notifyAll();
|
||||||
@@ -1662,9 +1685,20 @@ public final class UiAutomation {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAccessibilityEvent(AccessibilityEvent event) {
|
public void onAccessibilityEvent(AccessibilityEvent event) {
|
||||||
|
if (VERBOSE) {
|
||||||
|
Log.v(LOG_TAG, "onAccessibilityEvent(" + Process.myUserHandle() + "): "
|
||||||
|
+ event);
|
||||||
|
}
|
||||||
|
|
||||||
final OnAccessibilityEventListener listener;
|
final OnAccessibilityEventListener listener;
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
if (isGenerationChangedLocked()) {
|
if (isGenerationChangedLocked()) {
|
||||||
|
if (VERBOSE) {
|
||||||
|
Log.v(LOG_TAG, "onAccessibilityEvent(): returning because "
|
||||||
|
+ "generation id changed (from "
|
||||||
|
+ UiAutomation.this.mGenerationId + " to "
|
||||||
|
+ mGenerationId + ")");
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// It is not guaranteed that the accessibility framework sends events by the
|
// It is not guaranteed that the accessibility framework sends events by the
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ public final class UiAutomationConnection extends IUiAutomationConnection.Stub {
|
|||||||
|
|
||||||
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
|
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
|
||||||
public UiAutomationConnection() {
|
public UiAutomationConnection() {
|
||||||
|
Log.d(TAG, "Created on user " + Process.myUserHandle());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -976,6 +976,7 @@ public class AccessibilityRecord {
|
|||||||
append(builder, "AddedCount", mAddedCount);
|
append(builder, "AddedCount", mAddedCount);
|
||||||
append(builder, "RemovedCount", mRemovedCount);
|
append(builder, "RemovedCount", mRemovedCount);
|
||||||
append(builder, "ParcelableData", mParcelableData);
|
append(builder, "ParcelableData", mParcelableData);
|
||||||
|
append(builder, "DisplayId", mSourceDisplayId);
|
||||||
builder.append(" ]");
|
builder.append(" ]");
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import android.annotation.Nullable;
|
|||||||
import android.app.UiAutomation;
|
import android.app.UiAutomation;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.os.Binder;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.IBinder.DeathRecipient;
|
import android.os.IBinder.DeathRecipient;
|
||||||
@@ -34,6 +35,7 @@ import android.view.Display;
|
|||||||
import android.view.accessibility.AccessibilityEvent;
|
import android.view.accessibility.AccessibilityEvent;
|
||||||
|
|
||||||
import com.android.internal.util.DumpUtils;
|
import com.android.internal.util.DumpUtils;
|
||||||
|
import com.android.server.utils.Slogf;
|
||||||
import com.android.server.wm.WindowManagerInternal;
|
import com.android.server.wm.WindowManagerInternal;
|
||||||
|
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
@@ -51,12 +53,8 @@ class UiAutomationManager {
|
|||||||
|
|
||||||
private UiAutomationService mUiAutomationService;
|
private UiAutomationService mUiAutomationService;
|
||||||
|
|
||||||
private AccessibilityServiceInfo mUiAutomationServiceInfo;
|
|
||||||
|
|
||||||
private AbstractAccessibilityServiceConnection.SystemSupport mSystemSupport;
|
private AbstractAccessibilityServiceConnection.SystemSupport mSystemSupport;
|
||||||
|
|
||||||
private AccessibilityTrace mTrace;
|
|
||||||
|
|
||||||
private int mUiAutomationFlags;
|
private int mUiAutomationFlags;
|
||||||
|
|
||||||
UiAutomationManager(Object lock) {
|
UiAutomationManager(Object lock) {
|
||||||
@@ -97,9 +95,10 @@ class UiAutomationManager {
|
|||||||
WindowManagerInternal windowManagerInternal,
|
WindowManagerInternal windowManagerInternal,
|
||||||
SystemActionPerformer systemActionPerformer,
|
SystemActionPerformer systemActionPerformer,
|
||||||
AccessibilityWindowManager awm, int flags) {
|
AccessibilityWindowManager awm, int flags) {
|
||||||
synchronized (mLock) {
|
|
||||||
accessibilityServiceInfo.setComponentName(COMPONENT_NAME);
|
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) {
|
if (mUiAutomationService != null) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"UiAutomationService " + mUiAutomationService.mServiceInterface
|
"UiAutomationService " + mUiAutomationService.mServiceInterface
|
||||||
@@ -116,7 +115,6 @@ class UiAutomationManager {
|
|||||||
|
|
||||||
mUiAutomationFlags = flags;
|
mUiAutomationFlags = flags;
|
||||||
mSystemSupport = systemSupport;
|
mSystemSupport = systemSupport;
|
||||||
mTrace = trace;
|
|
||||||
// Ignore registering UiAutomation if it is not allowed to use the accessibility
|
// Ignore registering UiAutomation if it is not allowed to use the accessibility
|
||||||
// subsystem.
|
// subsystem.
|
||||||
if (!useAccessibility()) {
|
if (!useAccessibility()) {
|
||||||
@@ -126,7 +124,6 @@ class UiAutomationManager {
|
|||||||
mainHandler, mLock, securityPolicy, systemSupport, trace, windowManagerInternal,
|
mainHandler, mLock, securityPolicy, systemSupport, trace, windowManagerInternal,
|
||||||
systemActionPerformer, awm);
|
systemActionPerformer, awm);
|
||||||
mUiAutomationServiceOwner = owner;
|
mUiAutomationServiceOwner = owner;
|
||||||
mUiAutomationServiceInfo = accessibilityServiceInfo;
|
|
||||||
mUiAutomationService.mServiceInterface = serviceClient;
|
mUiAutomationService.mServiceInterface = serviceClient;
|
||||||
try {
|
try {
|
||||||
mUiAutomationService.mServiceInterface.asBinder().linkToDeath(mUiAutomationService,
|
mUiAutomationService.mServiceInterface.asBinder().linkToDeath(mUiAutomationService,
|
||||||
|
|||||||
Reference in New Issue
Block a user