diff options
| -rw-r--r-- | core/java/android/app/Activity.java | 6 | ||||
| -rw-r--r-- | core/java/android/app/Instrumentation.java | 27 |
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; } } |