Disable main looper holding
It might make failures more clear Test: runtest systemui Bug: 110417074 Change-Id: I9880998af42016b9d625cc3e890a94b282f49df0
This commit is contained in:
@@ -38,22 +38,26 @@ public class TestableInstrumentation extends AndroidJUnitRunner {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle arguments) {
|
||||
sManager = new MainLooperManager();
|
||||
Log.setWtfHandler((tag, what, system) -> {
|
||||
if (system) {
|
||||
Log.e(TAG, "WTF!!", what);
|
||||
} else {
|
||||
// These normally kill the app, but we don't want that in a test, instead we want
|
||||
// it to throw.
|
||||
throw new RuntimeException(what);
|
||||
}
|
||||
});
|
||||
if (TestableLooper.HOLD_MAIN_THREAD) {
|
||||
sManager = new MainLooperManager();
|
||||
Log.setWtfHandler((tag, what, system) -> {
|
||||
if (system) {
|
||||
Log.e(TAG, "WTF!!", what);
|
||||
} else {
|
||||
// These normally kill the app, but we don't want that in a test, instead we want
|
||||
// it to throw.
|
||||
throw new RuntimeException(what);
|
||||
}
|
||||
});
|
||||
}
|
||||
super.onCreate(arguments);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish(int resultCode, Bundle results) {
|
||||
sManager.destroy();
|
||||
if (TestableLooper.HOLD_MAIN_THREAD) {
|
||||
sManager.destroy();
|
||||
}
|
||||
super.finish(resultCode, results);
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,12 @@ import java.util.Map;
|
||||
*/
|
||||
public class TestableLooper {
|
||||
|
||||
/**
|
||||
* Whether to hold onto the main thread through all tests in an attempt to
|
||||
* catch crashes.
|
||||
*/
|
||||
public static final boolean HOLD_MAIN_THREAD = false;
|
||||
|
||||
private Looper mLooper;
|
||||
private MessageQueue mQueue;
|
||||
private MessageHandler mMessageHandler;
|
||||
@@ -77,7 +83,7 @@ public class TestableLooper {
|
||||
*/
|
||||
public void destroy() {
|
||||
mQueueWrapper.release();
|
||||
if (mLooper == Looper.getMainLooper()) {
|
||||
if (HOLD_MAIN_THREAD && mLooper == Looper.getMainLooper()) {
|
||||
TestableInstrumentation.releaseMain();
|
||||
}
|
||||
}
|
||||
@@ -199,7 +205,7 @@ public class TestableLooper {
|
||||
}
|
||||
|
||||
private static TestLooperManager acquireLooperManager(Looper l) {
|
||||
if (l == Looper.getMainLooper()) {
|
||||
if (HOLD_MAIN_THREAD && l == Looper.getMainLooper()) {
|
||||
TestableInstrumentation.acquireMain();
|
||||
}
|
||||
return InstrumentationRegistry.getInstrumentation().acquireLooperManager(l);
|
||||
@@ -291,7 +297,7 @@ public class TestableLooper {
|
||||
if (set) {
|
||||
mTestableLooper.mQueueWrapper.release();
|
||||
mTestableLooper.mQueueWrapper = null;
|
||||
if (mLooper == Looper.getMainLooper()) {
|
||||
if (HOLD_MAIN_THREAD && mLooper == Looper.getMainLooper()) {
|
||||
TestableInstrumentation.releaseMain();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user