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

Commit 2f0d41b1 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Disable main looper holding"

parents e022a155 759e9121
Loading
Loading
Loading
Loading
+15 −11
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ public class TestableInstrumentation extends AndroidJUnitRunner {

    @Override
    public void onCreate(Bundle arguments) {
        if (TestableLooper.HOLD_MAIN_THREAD) {
            sManager = new MainLooperManager();
            Log.setWtfHandler((tag, what, system) -> {
                if (system) {
@@ -48,12 +49,15 @@ public class TestableInstrumentation extends AndroidJUnitRunner {
                    throw new RuntimeException(what);
                }
            });
        }
        super.onCreate(arguments);
    }

    @Override
    public void finish(int resultCode, Bundle results) {
        if (TestableLooper.HOLD_MAIN_THREAD) {
            sManager.destroy();
        }
        super.finish(resultCode, results);
    }

+9 −3
Original line number Diff line number Diff line
@@ -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();
                    }
                }