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

Commit eba996dc authored by Beverly Tai's avatar Beverly Tai Committed by Android (Google) Code Review
Browse files

Merge "AOD: selectively register sensors that use prox" into sc-dev

parents 456fb2e7 78386ab1
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -174,6 +174,23 @@
    <!-- Doze: check proximity sensor before pulsing? -->
    <bool name="doze_proximity_check_before_pulse">true</bool>

    <!-- Doze: only register sensors that use prox when device is in certain Display states. This
     delays registering sensors when device first shows dozing UI but the
     Display & Power state hasn't changed to low-power mode yet. -->
    <bool name="doze_selectively_register_prox">false</bool>

    <!-- Doze: whether the single tap sensor uses the proximity sensor.
     If both this parameter and doze_selectively_register_prox are true, registration for the
     sensor will be delayed when the device first enters dozing but the device has not entered its
     low powered state yet. -->
    <bool name="doze_single_tap_uses_prox">true</bool>

    <!-- Doze: whether the long press sensor uses the proximity sensor.
     If both this parameter and doze_selectively_register_prox are true, registration for the
     sensor will be delayed when the device first enters dozing but the device has not entered its
     low powered state yet. -->
    <bool name="doze_long_press_uses_prox">true</bool>

    <!-- Doze: should notifications be used as a pulse signal? -->
    <bool name="doze_pulse_on_notifications">true</bool>

+41 −3
Original line number Diff line number Diff line
@@ -81,6 +81,10 @@ public class DozeSensors {
    private boolean mSettingRegistered;
    private boolean mListening;
    private boolean mListeningTouchScreenSensors;
    private boolean mListeningProxSensors;

    // whether to only register sensors that use prox when the display state is dozing or off
    private boolean mSelectivelyRegisterProxSensors;

    @VisibleForTesting
    public enum DozeSensorsUiEvent implements UiEventLogger.UiEventEnum {
@@ -112,6 +116,8 @@ public class DozeSensors {
        mSecureSettings = secureSettings;
        mCallback = callback;
        mProximitySensor = proximitySensor;
        mSelectivelyRegisterProxSensors = dozeParameters.getSelectivelyRegisterSensorsUsingProx();
        mListeningProxSensors = !mSelectivelyRegisterProxSensors;

        boolean udfpsEnrolled =
                authController.isUdfpsEnrolled(KeyguardUpdateMonitor.getCurrentUser());
@@ -131,6 +137,7 @@ public class DozeSensors {
                        DozeLog.REASON_SENSOR_PICKUP, false /* touchCoords */,
                        false /* touchscreen */,
                        false /* ignoresSetting */,
                        false /* requires prox */,
                        dozeLog),
                new TriggerSensor(
                        findSensorWithType(config.doubleTapSensorType()),
@@ -143,10 +150,13 @@ public class DozeSensors {
                new TriggerSensor(
                        findSensorWithType(config.tapSensorType()),
                        Settings.Secure.DOZE_TAP_SCREEN_GESTURE,
                        true /* settingDef */,
                        true /* configured */,
                        DozeLog.REASON_SENSOR_TAP,
                        false /* reports touch coordinates */,
                        true /* touchscreen */,
                        false /* ignoresSetting */,
                        dozeParameters.singleTapUsesProx() /* requiresProx */,
                        dozeLog),
                new TriggerSensor(
                        findSensorWithType(config.longPressSensorType()),
@@ -156,6 +166,8 @@ public class DozeSensors {
                        DozeLog.PULSE_REASON_SENSOR_LONG_PRESS,
                        true /* reports touch coordinates */,
                        true /* touchscreen */,
                        false /* ignoresSetting */,
                        dozeParameters.longPressUsesProx() /* requiresProx */,
                        dozeLog),
                new TriggerSensor(
                        findSensorWithType(config.udfpsLongPressSensorType()),
@@ -165,6 +177,8 @@ public class DozeSensors {
                        DozeLog.REASON_SENSOR_UDFPS_LONG_PRESS,
                        true /* reports touch coordinates */,
                        true /* touchscreen */,
                        false /* ignoresSetting */,
                        dozeParameters.longPressUsesProx(),
                        dozeLog),
                new PluginSensor(
                        new SensorManagerPlugin.Sensor(TYPE_WAKE_DISPLAY),
@@ -254,6 +268,23 @@ public class DozeSensors {
        updateListening();
    }

    /**
     * If sensors should be registered and sending signals.
     */
    public void setListening(boolean listen, boolean includeTouchScreenSensors,
            boolean lowPowerStateOrOff) {
        final boolean shouldRegisterProxSensors =
                !mSelectivelyRegisterProxSensors || lowPowerStateOrOff;
        if (mListening == listen && mListeningTouchScreenSensors == includeTouchScreenSensors
                && mListeningProxSensors == shouldRegisterProxSensors) {
            return;
        }
        mListening = listen;
        mListeningTouchScreenSensors = includeTouchScreenSensors;
        mListeningProxSensors = shouldRegisterProxSensors;
        updateListening();
    }

    /**
     * Registers/unregisters sensors based on internal state.
     */
@@ -261,7 +292,8 @@ public class DozeSensors {
        boolean anyListening = false;
        for (TriggerSensor s : mSensors) {
            boolean listen = mListening
                    && (!s.mRequiresTouchscreen || mListeningTouchScreenSensors);
                    && (!s.mRequiresTouchscreen || mListeningTouchScreenSensors)
                    && (!s.mRequiresProx || mListeningProxSensors);
            s.setListening(listen);
            if (listen) {
                anyListening = true;
@@ -337,6 +369,8 @@ public class DozeSensors {
    public void dump(PrintWriter pw) {
        pw.println("mListening=" + mListening);
        pw.println("mListeningTouchScreenSensors=" + mListeningTouchScreenSensors);
        pw.println("mSelectivelyRegisterProxSensors=" + mSelectivelyRegisterProxSensors);
        pw.println("mListeningProxSensors=" + mListeningProxSensors);
        IndentingPrintWriter idpw = new IndentingPrintWriter(pw);
        idpw.increaseIndent();
        for (TriggerSensor s : mSensors) {
@@ -361,6 +395,7 @@ public class DozeSensors {
        private final boolean mReportsTouchCoordinates;
        private final boolean mSettingDefault;
        private final boolean mRequiresTouchscreen;
        private final boolean mRequiresProx;

        protected boolean mRequested;
        protected boolean mRegistered;
@@ -378,12 +413,14 @@ public class DozeSensors {
                boolean configured, int pulseReason, boolean reportsTouchCoordinates,
                boolean requiresTouchscreen, DozeLog dozeLog) {
            this(sensor, setting, settingDef, configured, pulseReason, reportsTouchCoordinates,
                    requiresTouchscreen, false /* ignoresSetting */, dozeLog);
                    requiresTouchscreen, false /* ignoresSetting */,
                    false /* requiresProx */, dozeLog);
        }

        private TriggerSensor(Sensor sensor, String setting, boolean settingDef,
                boolean configured, int pulseReason, boolean reportsTouchCoordinates,
                boolean requiresTouchscreen, boolean ignoresSetting, DozeLog dozeLog) {
                boolean requiresTouchscreen, boolean ignoresSetting, boolean requiresProx,
                DozeLog dozeLog) {
            mSensor = sensor;
            mSetting = setting;
            mSettingDefault = settingDef;
@@ -392,6 +429,7 @@ public class DozeSensors {
            mReportsTouchCoordinates = reportsTouchCoordinates;
            mRequiresTouchscreen = requiresTouchscreen;
            mIgnoresSetting = ignoresSetting;
            mRequiresProx = requiresProx;
            mDozeLog = dozeLog;
        }

+15 −17
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package com.android.systemui.doze;

import android.annotation.Nullable;
import android.app.AlarmManager;
import android.app.UiModeManager;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -42,7 +41,6 @@ import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.systemui.Dependency;
import com.android.systemui.biometrics.AuthController;
import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.dagger.qualifiers.Background;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.dock.DockManager;
import com.android.systemui.doze.dagger.DozeScope;
@@ -101,15 +99,16 @@ public class DozeTriggers implements DozeMachine.Part {
    private final BroadcastDispatcher mBroadcastDispatcher;
    private final AuthController mAuthController;
    private final DelayableExecutor mMainExecutor;
    private final DelayableExecutor mBgExecutor;

    private long mNotificationPulseTime;
    private boolean mPulsePending;

    private final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class);
    private boolean mWantProx;
    private boolean mWantSensors;

    /** see {@link #onProximityFar} prox for callback */
    private boolean mWantProxSensor;
    private boolean mWantTouchScreenSensors;
    private boolean mWantSensors;

    @VisibleForTesting
    public enum DozingUpdateUiEvent implements UiEventLogger.UiEventEnum {
@@ -177,13 +176,13 @@ public class DozeTriggers implements DozeMachine.Part {

    @Inject
    public DozeTriggers(Context context, DozeHost dozeHost,
            AlarmManager alarmManager, AmbientDisplayConfiguration config,
            AmbientDisplayConfiguration config,
            DozeParameters dozeParameters, AsyncSensorManager sensorManager,
            WakeLock wakeLock, DockManager dockManager,
            ProximitySensor proximitySensor, ProximitySensor.ProximityCheck proxCheck,
            DozeLog dozeLog, BroadcastDispatcher broadcastDispatcher,
            SecureSettings secureSettings, AuthController authController,
            @Main DelayableExecutor mainExecutor, @Background DelayableExecutor bgExecutor) {
            @Main DelayableExecutor mainExecutor) {
        mContext = context;
        mDozeHost = dozeHost;
        mConfig = config;
@@ -201,7 +200,6 @@ public class DozeTriggers implements DozeMachine.Part {
        mBroadcastDispatcher = broadcastDispatcher;
        mAuthController = authController;
        mMainExecutor = mainExecutor;
        mBgExecutor = bgExecutor;
    }

    @Override
@@ -459,7 +457,7 @@ public class DozeTriggers implements DozeMachine.Part {
                break;
            case DOZE:
            case DOZE_AOD:
                mWantProx = newState != DozeMachine.State.DOZE;
                mWantProxSensor = newState != DozeMachine.State.DOZE;
                mWantSensors = true;
                mWantTouchScreenSensors = true;
                if (newState == DozeMachine.State.DOZE_AOD && !sWakeDisplaySensorState) {
@@ -468,15 +466,15 @@ public class DozeTriggers implements DozeMachine.Part {
                break;
            case DOZE_AOD_PAUSED:
            case DOZE_AOD_PAUSING:
                mWantProx = true;
                mWantProxSensor = true;
                break;
            case DOZE_PULSING:
            case DOZE_PULSING_BRIGHT:
                mWantProx = true;
                mWantProxSensor = true;
                mWantTouchScreenSensors = false;
                break;
            case DOZE_AOD_DOCKED:
                mWantProx = false;
                mWantProxSensor = false;
                mWantTouchScreenSensors = false;
                break;
            case DOZE_PULSE_DONE:
@@ -490,7 +488,7 @@ public class DozeTriggers implements DozeMachine.Part {
                mDozeSensors.setListening(false, false);
                mDozeSensors.setProxListening(false);
                mWantSensors = false;
                mWantProx = false;
                mWantProxSensor = false;
                mWantTouchScreenSensors = false;
                break;
            default:
@@ -501,10 +499,10 @@ public class DozeTriggers implements DozeMachine.Part {
    @Override
    public void onScreenState(int state) {
        mDozeSensors.onScreenState(state);
        mDozeSensors.setProxListening(mWantProx && (state == Display.STATE_DOZE
                || state == Display.STATE_DOZE_SUSPEND
                || state == Display.STATE_OFF));
        mDozeSensors.setListening(mWantSensors, mWantTouchScreenSensors);
        final boolean lowPowerStateOrOff = state == Display.STATE_DOZE
                || state == Display.STATE_DOZE_SUSPEND || state == Display.STATE_OFF;
        mDozeSensors.setProxListening(mWantProxSensor && lowPowerStateOrOff);
        mDozeSensors.setListening(mWantSensors, mWantTouchScreenSensors, lowPowerStateOrOff);
    }

    /**
+48 −15
Original line number Diff line number Diff line
@@ -24,15 +24,20 @@ import android.os.UserHandle;
import android.provider.Settings;
import android.util.MathUtils;

import androidx.annotation.NonNull;

import com.android.systemui.Dumpable;
import com.android.systemui.R;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.doze.AlwaysOnDisplayPolicy;
import com.android.systemui.doze.DozeScreenState;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.statusbar.FeatureFlags;
import com.android.systemui.statusbar.policy.BatteryController;
import com.android.systemui.tuner.TunerService;

import java.io.FileDescriptor;
import java.io.PrintWriter;

import javax.inject.Inject;
@@ -42,7 +47,7 @@ import javax.inject.Inject;
 */
@SysUISingleton
public class DozeParameters implements TunerService.Tunable,
        com.android.systemui.plugins.statusbar.DozeParameters {
        com.android.systemui.plugins.statusbar.DozeParameters, Dumpable {
    private static final int MAX_DURATION = 60 * 1000;
    public static final boolean FORCE_NO_BLANKING =
            SystemProperties.getBoolean("debug.force_no_blanking", false);
@@ -68,11 +73,13 @@ public class DozeParameters implements TunerService.Tunable,
            PowerManager powerManager,
            BatteryController batteryController,
            TunerService tunerService,
            DumpManager dumpManager,
            FeatureFlags featureFlags) {
        mResources = resources;
        mAmbientDisplayConfiguration = ambientDisplayConfiguration;
        mAlwaysOnPolicy = alwaysOnDisplayPolicy;
        mBatteryController = batteryController;
        dumpManager.registerDumpable("DozeParameters", this);

        mControlScreenOffAnimation = !getDisplayNeedsBlanking();
        mPowerManager = powerManager;
@@ -85,20 +92,6 @@ public class DozeParameters implements TunerService.Tunable,
                Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED);
    }

    public void dump(PrintWriter pw) {
        pw.println("  DozeParameters:");
        pw.print("    getDisplayStateSupported(): "); pw.println(getDisplayStateSupported());
        pw.print("    getPulseDuration(): "); pw.println(getPulseDuration());
        pw.print("    getPulseInDuration(): "); pw.println(getPulseInDuration());
        pw.print("    getPulseInVisibleDuration(): "); pw.println(getPulseVisibleDuration());
        pw.print("    getPulseOutDuration(): "); pw.println(getPulseOutDuration());
        pw.print("    getPulseOnSigMotion(): "); pw.println(getPulseOnSigMotion());
        pw.print("    getVibrateOnSigMotion(): "); pw.println(getVibrateOnSigMotion());
        pw.print("    getVibrateOnPickup(): "); pw.println(getVibrateOnPickup());
        pw.print("    getProxCheckBeforePulse(): "); pw.println(getProxCheckBeforePulse());
        pw.print("    getPickupVibrationThreshold(): "); pw.println(getPickupVibrationThreshold());
    }

    public boolean getDisplayStateSupported() {
        return getBoolean("doze.display.supported", R.bool.doze_display_state_supported);
    }
@@ -144,6 +137,16 @@ public class DozeParameters implements TunerService.Tunable,
        return getBoolean("doze.pulse.proxcheck", R.bool.doze_proximity_check_before_pulse);
    }

    /**
     * @return true if we should only register for sensors that use the proximity sensor when the
     * display state is {@link android.view.Display.STATE_OFF},
     * {@link android.view.Display.STATE_DOZE} or {@link android.view.Display.STATE_DOZE_SUSPEND}
     */
    public boolean getSelectivelyRegisterSensorsUsingProx() {
        return getBoolean("doze.prox.selectively_register",
                R.bool.doze_selectively_register_prox);
    }

    public int getPickupVibrationThreshold() {
        return getInt("doze.pickup.vibration.threshold", R.integer.doze_pickup_vibration_threshold);
    }
@@ -233,8 +236,38 @@ public class DozeParameters implements TunerService.Tunable,
        return mResources.getBoolean(R.bool.doze_double_tap_reports_touch_coordinates);
    }

    /**
     * Whether the single tap sensor uses the proximity sensor.
     */
    public boolean singleTapUsesProx() {
        return mResources.getBoolean(R.bool.doze_single_tap_uses_prox);
    }

    /**
     * Whether the long press sensor uses the proximity sensor.
     */
    public boolean longPressUsesProx() {
        return mResources.getBoolean(R.bool.doze_long_press_uses_prox);
    }

    @Override
    public void onTuningChanged(String key, String newValue) {
        mDozeAlwaysOn = mAmbientDisplayConfiguration.alwaysOnEnabled(UserHandle.USER_CURRENT);
    }

    @Override
    public void dump(@NonNull FileDescriptor fd, @NonNull PrintWriter pw, @NonNull String[] args) {
        pw.print("getDisplayStateSupported(): "); pw.println(getDisplayStateSupported());
        pw.print("getPulseDuration(): "); pw.println(getPulseDuration());
        pw.print("getPulseInDuration(): "); pw.println(getPulseInDuration());
        pw.print("getPulseInVisibleDuration(): "); pw.println(getPulseVisibleDuration());
        pw.print("getPulseOutDuration(): "); pw.println(getPulseOutDuration());
        pw.print("getPulseOnSigMotion(): "); pw.println(getPulseOnSigMotion());
        pw.print("getVibrateOnSigMotion(): "); pw.println(getVibrateOnSigMotion());
        pw.print("getVibrateOnPickup(): "); pw.println(getVibrateOnPickup());
        pw.print("getProxCheckBeforePulse(): "); pw.println(getProxCheckBeforePulse());
        pw.print("getPickupVibrationThreshold(): "); pw.println(getPickupVibrationThreshold());
        pw.print("getSelectivelyRegisterSensorsUsingProx(): ");
        pw.println(getSelectivelyRegisterSensorsUsingProx());
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -39,6 +39,9 @@ public class DozeConfigurationUtil {
        when(params.getProxCheckBeforePulse()).thenReturn(true);
        when(params.doubleTapReportsTouchCoordinates()).thenReturn(false);
        when(params.getDisplayNeedsBlanking()).thenReturn(false);
        when(params.getSelectivelyRegisterSensorsUsingProx()).thenReturn(false);
        when(params.singleTapUsesProx()).thenReturn(true);
        when(params.longPressUsesProx()).thenReturn(true);

        doneHolder[0] = true;
        return params;
Loading