summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Chavi Weingarten <chaviw@google.com> 2018-12-27 17:55:53 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2018-12-27 17:55:53 +0000
commit89000d068725a46250dfa6ae68c3fda8d366925c (patch)
tree1792a19bdb43831a2936bf471271364307552192
parent561ba9eae287b57c44dace901f794644a05397e1 (diff)
parentfeb2e1e0b46926f79904fc0fde505552276f168b (diff)
Merge "Wait for enter animation to complete when calling startActivitySync"
-rw-r--r--core/java/android/app/Activity.java6
-rw-r--r--core/java/android/app/Instrumentation.java27
2 files changed, 33 insertions, 0 deletions
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java
index 48a767bee341..3561f71b23af 100644
--- a/core/java/android/app/Activity.java
+++ b/core/java/android/app/Activity.java
@@ -924,6 +924,9 @@ public class Activity extends ContextThemeWrapper
private AutofillPopupWindow mAutofillPopupWindow;
+ /** @hide */
+ boolean mEnterAnimationComplete;
+
private static native String getDlWarning();
/** Return the intent that started this activity. */
@@ -2328,6 +2331,7 @@ public class Activity extends ContextThemeWrapper
}
notifyContentCaptureManagerIfNeeded(CONTENT_CAPTURE_STOP);
}
+ mEnterAnimationComplete = false;
}
/**
@@ -7085,6 +7089,8 @@ public class Activity extends ContextThemeWrapper
* @hide
*/
public void dispatchEnterAnimationComplete() {
+ mEnterAnimationComplete = true;
+ mInstrumentation.onEnterAnimationComplete();
onEnterAnimationComplete();
if (getWindow() != null && getWindow().getDecorView() != null) {
getWindow().getDecorView().getViewTreeObserver().dispatchOnEnterAnimationComplete();
diff --git a/core/java/android/app/Instrumentation.java b/core/java/android/app/Instrumentation.java
index 015bc6c4bb07..d7c7f3c8a937 100644
--- a/core/java/android/app/Instrumentation.java
+++ b/core/java/android/app/Instrumentation.java
@@ -110,6 +110,7 @@ public class Instrumentation {
private PerformanceCollector mPerformanceCollector;
private Bundle mPerfMetrics = new Bundle();
private UiAutomation mUiAutomation;
+ private final Object mAnimationCompleteLock = new Object();
public Instrumentation() {
}
@@ -397,6 +398,31 @@ public class Instrumentation {
idler.waitForIdle();
}
+ private void waitForEnterAnimationComplete(Activity activity) {
+ synchronized (mAnimationCompleteLock) {
+ long timeout = 5000;
+ try {
+ // We need to check that this specified Activity completed the animation, not just
+ // any Activity. If it was another Activity, then decrease the timeout by how long
+ // it's already waited and wait for the thread to wakeup again.
+ while (timeout > 0 && !activity.mEnterAnimationComplete) {
+ long startTime = System.currentTimeMillis();
+ mAnimationCompleteLock.wait(timeout);
+ long totalTime = System.currentTimeMillis() - startTime;
+ timeout -= totalTime;
+ }
+ } catch (InterruptedException e) {
+ }
+ }
+ }
+
+ /** @hide */
+ public void onEnterAnimationComplete() {
+ synchronized (mAnimationCompleteLock) {
+ mAnimationCompleteLock.notifyAll();
+ }
+ }
+
/**
* Execute a call on the application's main thread, blocking until it is
* complete. Useful for doing things that are not thread-safe, such as
@@ -499,6 +525,7 @@ public class Instrumentation {
}
} while (mWaitingActivities.contains(aw));
+ waitForEnterAnimationComplete(aw.activity);
return aw.activity;
}
}