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

Commit f4ba7c39 authored by Beverly's avatar Beverly
Browse files

Use UiBackgroundExecutor to set doze screen brightness

Move the IPC to a background thread that can occur on transition
to AOD.

Test: change brightness of room and see brightness still
changes in AOD
Fixes: 210877065

Change-Id: I745a25b7a1eb55909ff121d58aa15a667e4e9eaa
parent ec06f834
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.systemui.doze;

import java.util.concurrent.Executor;

/**
 * Forwards the currently used brightness to {@link DozeHost}.
 */
@@ -23,8 +25,9 @@ public class DozeBrightnessHostForwarder extends DozeMachine.Service.Delegate {

    private final DozeHost mHost;

    public DozeBrightnessHostForwarder(DozeMachine.Service wrappedService, DozeHost host) {
        super(wrappedService);
    public DozeBrightnessHostForwarder(DozeMachine.Service wrappedService, DozeHost host,
            Executor bgExecutor) {
        super(wrappedService, bgExecutor);
        mHost = host;
    }

+7 −3
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import com.android.systemui.util.wakelock.WakeLock;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.concurrent.Executor;

import javax.inject.Inject;

@@ -150,7 +151,6 @@ public class DozeMachine {
    private final DockManager mDockManager;
    private final Part[] mParts;
    private final UserTracker mUserTracker;

    private final ArrayList<State> mQueuedRequests = new ArrayList<>();
    private State mState = State.UNINITIALIZED;
    private int mPulseReason;
@@ -512,9 +512,11 @@ public class DozeMachine {

        class Delegate implements Service {
            private final Service mDelegate;
            private final Executor mBgExecutor;

            public Delegate(Service delegate) {
            public Delegate(Service delegate, Executor bgExecutor) {
                mDelegate = delegate;
                mBgExecutor = bgExecutor;
            }

            @Override
@@ -534,7 +536,9 @@ public class DozeMachine {

            @Override
            public void setDozeScreenBrightness(int brightness) {
                mBgExecutor.execute(() -> {
                    mDelegate.setDozeScreenBrightness(brightness);
                });
            }
        }
    }
+6 −4
Original line number Diff line number Diff line
@@ -22,14 +22,16 @@ import androidx.annotation.VisibleForTesting;

import com.android.systemui.statusbar.phone.DozeParameters;

import java.util.concurrent.Executor;

/**
 * Prevents usage of doze screen states on devices that don't support them.
 */
public class DozeScreenStatePreventingAdapter extends DozeMachine.Service.Delegate {

    @VisibleForTesting
    DozeScreenStatePreventingAdapter(DozeMachine.Service inner) {
        super(inner);
    DozeScreenStatePreventingAdapter(DozeMachine.Service inner, Executor bgExecutor) {
        super(inner, bgExecutor);
    }

    @Override
@@ -47,8 +49,8 @@ public class DozeScreenStatePreventingAdapter extends DozeMachine.Service.Delega
     * return a new instance of {@link DozeScreenStatePreventingAdapter} wrapping {@code inner}.
     */
    public static DozeMachine.Service wrapIfNeeded(DozeMachine.Service inner,
            DozeParameters params) {
        return isNeeded(params) ? new DozeScreenStatePreventingAdapter(inner) : inner;
            DozeParameters params, Executor bgExecutor) {
        return isNeeded(params) ? new DozeScreenStatePreventingAdapter(inner, bgExecutor) : inner;
    }

    private static boolean isNeeded(DozeParameters params) {
+7 −4
Original line number Diff line number Diff line
@@ -22,14 +22,16 @@ import androidx.annotation.VisibleForTesting;

import com.android.systemui.statusbar.phone.DozeParameters;

import java.util.concurrent.Executor;

/**
 * Prevents usage of doze screen states on devices that don't support them.
 */
public class DozeSuspendScreenStatePreventingAdapter extends DozeMachine.Service.Delegate {

    @VisibleForTesting
    DozeSuspendScreenStatePreventingAdapter(DozeMachine.Service inner) {
        super(inner);
    DozeSuspendScreenStatePreventingAdapter(DozeMachine.Service inner, Executor bgExecutor) {
        super(inner, bgExecutor);
    }

    @Override
@@ -45,8 +47,9 @@ public class DozeSuspendScreenStatePreventingAdapter extends DozeMachine.Service
     * return a new instance of {@link DozeSuspendScreenStatePreventingAdapter} wrapping {@code inner}.
     */
    public static DozeMachine.Service wrapIfNeeded(DozeMachine.Service inner,
            DozeParameters params) {
        return isNeeded(params) ? new DozeSuspendScreenStatePreventingAdapter(inner) : inner;
            DozeParameters params, Executor bgExecutor) {
        return isNeeded(params) ? new DozeSuspendScreenStatePreventingAdapter(inner, bgExecutor)
                : inner;
    }

    private static boolean isNeeded(DozeParameters params) {
+9 −7
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.os.Handler;

import com.android.systemui.R;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.dagger.qualifiers.UiBackground;
import com.android.systemui.doze.DozeAuthRemover;
import com.android.systemui.doze.DozeBrightnessHostForwarder;
import com.android.systemui.doze.DozeDockHandler;
@@ -45,13 +46,14 @@ import com.android.systemui.util.sensors.AsyncSensorManager;
import com.android.systemui.util.wakelock.DelayedWakeLock;
import com.android.systemui.util.wakelock.WakeLock;

import dagger.Module;
import dagger.Provides;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

import dagger.Module;
import dagger.Provides;
import java.util.concurrent.Executor;

/** Dagger module for use with {@link com.android.systemui.doze.dagger.DozeComponent}. */
@Module
@@ -60,13 +62,13 @@ public abstract class DozeModule {
    @DozeScope
    @WrappedService
    static DozeMachine.Service providesWrappedService(DozeMachine.Service dozeMachineService,
            DozeHost dozeHost, DozeParameters dozeParameters) {
            DozeHost dozeHost, DozeParameters dozeParameters, @UiBackground Executor bgExecutor) {
        DozeMachine.Service wrappedService = dozeMachineService;
        wrappedService = new DozeBrightnessHostForwarder(wrappedService, dozeHost);
        wrappedService = new DozeBrightnessHostForwarder(wrappedService, dozeHost, bgExecutor);
        wrappedService = DozeScreenStatePreventingAdapter.wrapIfNeeded(
                wrappedService, dozeParameters);
                wrappedService, dozeParameters, bgExecutor);
        wrappedService = DozeSuspendScreenStatePreventingAdapter.wrapIfNeeded(
                wrappedService, dozeParameters);
                wrappedService, dozeParameters, bgExecutor);

        return wrappedService;
    }
Loading