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

Commit 37f58660 authored by Eric Rahm's avatar Eric Rahm
Browse files

Workaround a robelectric related NPE in SurfaceSyncGroup.addTimer

Robolectric mocks out `HandlerThread` in such a way that in certain instances `HandlerThread.getLooper` returns null. Since adding the null check is small enough, we can opt to make this change to allow robolectric tests to run.

Test: atest ClockworkSettingsRobotests
Bug: 237804605
Change-Id: Ib28f80413265a770cfac44cf451714f1b66dfbc8
parent 32f42bf9
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.os.Debug;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
import android.os.Looper;
import android.os.RemoteException;
import android.os.Trace;
import android.util.ArraySet;
@@ -800,22 +801,25 @@ public final class SurfaceSyncGroup {
    }

    private void addTimeout() {
        Looper looper = null;
        synchronized (sHandlerThreadLock) {
            if (sHandlerThread == null) {
                sHandlerThread = new HandlerThread("SurfaceSyncGroupTimer");
                sHandlerThread.start();
            }

            looper = sHandlerThread.getLooper();
        }

        synchronized (mLock) {
            if (mTimeoutAdded || mTimeoutDisabled) {
            if (mTimeoutAdded || mTimeoutDisabled || looper == null) {
                // We only need one timeout for the entire SurfaceSyncGroup since we just want to
                // ensure it doesn't stay stuck forever.
                return;
            }

            if (mHandler == null) {
                mHandler = new Handler(sHandlerThread.getLooper());
                mHandler = new Handler(looper);
            }

            mTimeoutAdded = true;