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

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

Change-Id: I4026bb1cd47fa0fd95b9397b020742483131e66b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Adrian Roos
2022-03-31 20:21:37 +00:00
committed by Automerger Merge Worker

View File

@@ -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();
}
}
};
synchronized (waiter) {
mHandler.post(runnable);
mHandler.post(waiter);
final Throwable[] thrown = new Throwable[1];
assertTrue("Timed out", mHandler.runWithScissors(() -> {
try {
waiter.wait(TIMEOUT);
} catch (InterruptedException ex) {
runnable.run();
} catch (Throwable t) {
t.printStackTrace();
thrown[0] = t;
}
}, TIMEOUT));
if (thrown[0] != null) {
if (thrown[0] instanceof RuntimeException) {
throw (RuntimeException) thrown[0];
}
if (thrown[0] instanceof Error) {
throw (Error) thrown[0];
}
throw new RuntimeException(thrown[0]);
}
}