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

Commit f0edb9d6 authored by Matt Pietal's avatar Matt Pietal
Browse files

Remove DozeUI binder call from main thread

Put on background instead

Fixes: 331918317
Test: DozeUiTest
Flag: ACONFIG com.android.systemui.migrate_clocks_to_blueprint
TEAMFOOD

Change-Id: I0b8b3d5341fe001ef14e28fce151a527956733ae
parent dc08c200
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -208,6 +208,15 @@ public class DozeLog implements Dumpable {
        mLogger.logTimeTickScheduled(when, triggerAt);
    }

    /**
     * Logs cancelation requests for time ticks
     * @param isPending is an unschedule request pending?
     * @param isTimeTickScheduled is a time tick request scheduled
     */
    public void tracePendingUnscheduleTimeTick(boolean isPending, boolean isTimeTickScheduled) {
        mLogger.logPendingUnscheduleTimeTick(isPending, isTimeTickScheduled);
    }

    /**
     * Appends keyguard visibility change event to the logs
     * @param showing whether the keyguard is now showing
+9 −0
Original line number Diff line number Diff line
@@ -162,6 +162,15 @@ class DozeLogger @Inject constructor(
        })
    }

    fun logPendingUnscheduleTimeTick(isPending: Boolean, isTimeTickScheduled: Boolean) {
        buffer.log(TAG, INFO, {
            bool1 = isPending
            bool2 = isTimeTickScheduled
        }, {
            "Pending unschedule time tick, isPending=$bool1, isTimeTickScheduled:$bool2"
        })
    }

    fun logDozeStateChanged(state: DozeMachine.State) {
        buffer.log(TAG, INFO, {
            str1 = state.name
+12 −6
Original line number Diff line number Diff line
@@ -26,11 +26,12 @@ import android.os.SystemClock;
import android.text.format.Formatter;
import android.util.Log;

import com.android.systemui.DejankUtils;
import com.android.systemui.dagger.qualifiers.Background;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.doze.dagger.DozeScope;
import com.android.systemui.statusbar.phone.DozeParameters;
import com.android.systemui.util.AlarmTimeout;
import com.android.systemui.util.concurrency.DelayableExecutor;
import com.android.systemui.util.wakelock.WakeLock;

import java.util.Calendar;
@@ -52,26 +53,31 @@ public class DozeUi implements DozeMachine.Part {
    private final boolean mCanAnimateTransition;
    private final DozeParameters mDozeParameters;
    private final DozeLog mDozeLog;

    private final DelayableExecutor mBgExecutor;
    private long mLastTimeTickElapsed = 0;
    // If time tick is scheduled and there's not a pending runnable to cancel:
    private boolean mTimeTickScheduled;
    private volatile boolean mTimeTickScheduled;
    private final Runnable mCancelTimeTickerRunnable =  new Runnable() {
        @Override
        public void run() {
            mDozeLog.tracePendingUnscheduleTimeTick(false, mTimeTickScheduled);
            if (!mTimeTickScheduled) {
                mTimeTicker.cancel();
            }
        }
    };

    @Inject
    public DozeUi(Context context, AlarmManager alarmManager,
            WakeLock wakeLock, DozeHost host, @Main Handler handler,
            DozeParameters params,
            @Background DelayableExecutor bgExecutor,
            DozeLog dozeLog) {
        mContext = context;
        mWakeLock = wakeLock;
        mHost = host;
        mHandler = handler;
        mBgExecutor = bgExecutor;
        mCanAnimateTransition = !params.getDisplayNeedsBlanking();
        mDozeParameters = params;
        mTimeTicker = new AlarmTimeout(alarmManager, this::onTimeTick, "doze_time_tick", handler);
@@ -166,7 +172,6 @@ public class DozeUi implements DozeMachine.Part {
            return;
        }
        mTimeTickScheduled = true;
        DejankUtils.removeCallbacks(mCancelTimeTickerRunnable);

        long time = System.currentTimeMillis();
        long delta = roundToNextMinute(time) - System.currentTimeMillis();
@@ -182,7 +187,8 @@ public class DozeUi implements DozeMachine.Part {
            return;
        }
        mTimeTickScheduled = false;
        DejankUtils.postAfterTraversal(mCancelTimeTickerRunnable);
        mDozeLog.tracePendingUnscheduleTimeTick(true, mTimeTickScheduled);
        mBgExecutor.execute(mCancelTimeTickerRunnable);
    }

    private void verifyLastTimeTick() {
+5 −2
Original line number Diff line number Diff line
@@ -41,6 +41,8 @@ import androidx.test.runner.AndroidJUnit4;
import com.android.systemui.DejankUtils;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.statusbar.phone.DozeParameters;
import com.android.systemui.util.concurrency.FakeExecutor;
import com.android.systemui.util.time.FakeSystemClock;
import com.android.systemui.util.wakelock.WakeLockFake;

import org.junit.After;
@@ -69,6 +71,7 @@ public class DozeUiTest extends SysuiTestCase {
    private Handler mHandler;
    private HandlerThread mHandlerThread;
    private DozeUi mDozeUi;
    private FakeExecutor mFakeExecutor;

    @Before
    public void setUp() throws Exception {
@@ -80,9 +83,9 @@ public class DozeUiTest extends SysuiTestCase {
        mHandlerThread.start();
        mWakeLock = new WakeLockFake();
        mHandler = mHandlerThread.getThreadHandler();

        mFakeExecutor = new FakeExecutor(new FakeSystemClock());
        mDozeUi = new DozeUi(mContext, mAlarmManager, mWakeLock, mHost, mHandler,
                mDozeParameters, mDozeLog);
                mDozeParameters, mFakeExecutor, mDozeLog);
        mDozeUi.setDozeMachine(mMachine);
    }