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

This commit is contained in:
Adrian Roos
2022-03-31 19:44:18 +00:00
committed by Android (Google) Code Review

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]);
}
}