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

Commit 82ccba16 authored by Adrian Roos's avatar Adrian Roos Committed by Automerger Merge Worker
Browse files

Merge "VirtualDisplayTest: Rethrow runOnUiThread exceptions on test thread"...

Merge "VirtualDisplayTest: Rethrow runOnUiThread exceptions on test thread" into tm-dev am: 424c5a18

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17523153



Change-Id: I4026bb1cd47fa0fd95b9397b020742483131e66b
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 1d84351c 424c5a18
Loading
Loading
Loading
Loading
+15 −13
Original line number Diff line number Diff line
@@ -332,21 +332,23 @@ public class VirtualDisplayTest extends AndroidTestCase {
    }

    private void runOnUiThread(Runnable runnable) {
        Runnable waiter = new Runnable() {
            @Override
            public void run() {
                synchronized (this) {
                    notifyAll();
        final Throwable[] thrown = new Throwable[1];
        assertTrue("Timed out", mHandler.runWithScissors(() -> {
            try {
                runnable.run();
            } catch (Throwable t) {
                t.printStackTrace();
                thrown[0] = t;
            }
        }, TIMEOUT));
        if (thrown[0] != null) {
            if (thrown[0] instanceof RuntimeException) {
                throw (RuntimeException) thrown[0];
            }
        };
        synchronized (waiter) {
            mHandler.post(runnable);
            mHandler.post(waiter);
            try {
                waiter.wait(TIMEOUT);
            } catch (InterruptedException ex) {
            if (thrown[0] instanceof Error) {
                throw (Error) thrown[0];
            }
            throw new RuntimeException(thrown[0]);
        }
    }