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

Commit 89000d06 authored by Chavi Weingarten's avatar Chavi Weingarten Committed by Android (Google) Code Review
Browse files

Merge "Wait for enter animation to complete when calling startActivitySync"

parents 561ba9ea feb2e1e0
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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();
+27 −0
Original line number Diff line number Diff line
@@ -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;
        }
    }