Merge changes from topic "BackportUiAutomatorRetry" am: ff062f6e73
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1471402 Change-Id: I0de90a96abe80db87569aa7a8d53baf0135812e3
This commit is contained in:
@@ -62,6 +62,7 @@ import java.lang.annotation.Retention;
|
|||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for implementing application instrumentation code. When running
|
* Base class for implementing application instrumentation code. When running
|
||||||
@@ -90,6 +91,8 @@ public class Instrumentation {
|
|||||||
|
|
||||||
private static final String TAG = "Instrumentation";
|
private static final String TAG = "Instrumentation";
|
||||||
|
|
||||||
|
private static final long CONNECT_TIMEOUT_MILLIS = 5000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@@ -2125,6 +2128,13 @@ public class Instrumentation {
|
|||||||
* Equivalent to {@code getUiAutomation(0)}. If a {@link UiAutomation} exists with different
|
* Equivalent to {@code getUiAutomation(0)}. If a {@link UiAutomation} exists with different
|
||||||
* flags, the flags on that instance will be changed, and then it will be returned.
|
* flags, the flags on that instance will be changed, and then it will be returned.
|
||||||
* </p>
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* Compatibility mode: This method is infallible for apps targeted for
|
||||||
|
* {@link Build.VERSION_CODES#R} and earlier versions; for apps targeted for later versions, it
|
||||||
|
* will return null if {@link UiAutomation} fails to connect. The caller can check the return
|
||||||
|
* value and retry on error.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
* @return The UI automation instance.
|
* @return The UI automation instance.
|
||||||
*
|
*
|
||||||
* @see UiAutomation
|
* @see UiAutomation
|
||||||
@@ -2152,6 +2162,12 @@ public class Instrumentation {
|
|||||||
* If a {@link UiAutomation} exists with different flags, the flags on that instance will be
|
* If a {@link UiAutomation} exists with different flags, the flags on that instance will be
|
||||||
* changed, and then it will be returned.
|
* changed, and then it will be returned.
|
||||||
* </p>
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* Compatibility mode: This method is infallible for apps targeted for
|
||||||
|
* {@link Build.VERSION_CODES#R} and earlier versions; for apps targeted for later versions, it
|
||||||
|
* will return null if {@link UiAutomation} fails to connect. The caller can check the return
|
||||||
|
* value and retry on error.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @param flags The flags to be passed to the UiAutomation, for example
|
* @param flags The flags to be passed to the UiAutomation, for example
|
||||||
* {@link UiAutomation#FLAG_DONT_SUPPRESS_ACCESSIBILITY_SERVICES}.
|
* {@link UiAutomation#FLAG_DONT_SUPPRESS_ACCESSIBILITY_SERVICES}.
|
||||||
@@ -2173,8 +2189,17 @@ public class Instrumentation {
|
|||||||
} else {
|
} else {
|
||||||
mUiAutomation.disconnect();
|
mUiAutomation.disconnect();
|
||||||
}
|
}
|
||||||
mUiAutomation.connect(flags);
|
if (getTargetContext().getApplicationInfo().targetSdkVersion <= Build.VERSION_CODES.R) {
|
||||||
return mUiAutomation;
|
mUiAutomation.connect(flags);
|
||||||
|
return mUiAutomation;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
mUiAutomation.connectWithTimeout(flags, CONNECT_TIMEOUT_MILLIS);
|
||||||
|
return mUiAutomation;
|
||||||
|
} catch (TimeoutException e) {
|
||||||
|
mUiAutomation.destroy();
|
||||||
|
mUiAutomation = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user