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

Commit 541b6f8e authored by Beverly's avatar Beverly Committed by Beverly Tai
Browse files

Add dual-display support for aod brightness sensor

Depending on the posture, SystemUI can register for
different brightness sensors on AOD.

Test: manual, atest DozeSensorsTest
Bug: 192805135
Change-Id: I85e458623ae9cf868af80e0c02154fb0be11c615
parent c8d3d1ad
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -148,7 +148,7 @@ public class AmbientDisplayConfiguration {

    /** {@hide} */
    public String tapSensorType(int posture) {
        return getSensorTypeForPosture(
        return getSensorFromPostureMapping(
                mContext.getResources().getStringArray(R.array.config_dozeTapSensorPostureMapping),
                tapSensorType(),
                posture
@@ -252,17 +252,18 @@ public class AmbientDisplayConfiguration {
        return Settings.Secure.getIntForUser(mContext.getContentResolver(), name, def, user) != 0;
    }

    private String getSensorTypeForPosture(
    /** {@hide} */
    public static String getSensorFromPostureMapping(
            String[] postureMapping,
            String defaultSensorType,
            String defaultValue,
            int posture) {
        String sensorType = defaultSensorType;
        String sensorType = defaultValue;
        if (posture < postureMapping.length) {
            sensorType = postureMapping[posture];
        } else {
            Log.e(TAG, "Unsupported doze posture " + posture);
        }

        return TextUtils.isEmpty(sensorType) ? defaultSensorType : sensorType;
        return TextUtils.isEmpty(sensorType) ? defaultValue : sensorType;
    }
}
+10 −0
Original line number Diff line number Diff line
@@ -220,6 +220,16 @@
         always-on display) -->
    <string name="doze_brightness_sensor_type" translatable="false"></string>

    <!-- Name of a sensor per posture state that provides a low-power estimate of the desired
         display brightness, suitable to listen to while the device is asleep (e.g. during
         always-on display) -->
    <string-array name="doze_brightness_sensor_name_posture_mapping" translatable="false">
        <item></item> <!-- UNKNOWN -->
        <item></item> <!-- CLOSED -->
        <item></item> <!-- HALF_OPENED -->
        <item></item> <!-- OPENED -->
    </string-array>

    <!-- Override value to use for proximity sensor.  -->
    <string name="proximity_sensor_type" translatable="false"></string>

+24 −16
Original line number Diff line number Diff line
@@ -148,7 +148,7 @@ public class DozeSensors {
                        false /* requires prox */,
                        dozeLog),
                new TriggerSensor(
                        findSensorWithType(config.doubleTapSensorType()),
                        findSensor(config.doubleTapSensorType()),
                        Settings.Secure.DOZE_DOUBLE_TAP_GESTURE,
                        true /* configured */,
                        DozeLog.REASON_SENSOR_DOUBLE_TAP,
@@ -156,7 +156,7 @@ public class DozeSensors {
                        true /* touchscreen */,
                        dozeLog),
                new TriggerSensor(
                        findSensorWithType(config.tapSensorType(mDevicePosture)),
                        findSensor(config.tapSensorType(mDevicePosture)),
                        Settings.Secure.DOZE_TAP_SCREEN_GESTURE,
                        true /* settingDef */,
                        true /* configured */,
@@ -167,7 +167,7 @@ public class DozeSensors {
                        dozeParameters.singleTapUsesProx(mDevicePosture) /* requiresProx */,
                        dozeLog),
                new TriggerSensor(
                        findSensorWithType(config.longPressSensorType()),
                        findSensor(config.longPressSensorType()),
                        Settings.Secure.DOZE_PULSE_ON_LONG_PRESS,
                        false /* settingDef */,
                        true /* configured */,
@@ -178,7 +178,7 @@ public class DozeSensors {
                        dozeParameters.longPressUsesProx() /* requiresProx */,
                        dozeLog),
                new TriggerSensor(
                        findSensorWithType(config.udfpsLongPressSensorType()),
                        findSensor(config.udfpsLongPressSensorType()),
                        "doze_pulse_on_auth",
                        true /* settingDef */,
                        udfpsEnrolled && (alwaysOn || mScreenOffUdfpsEnabled),
@@ -206,7 +206,7 @@ public class DozeSensors {
                        mConfig.getWakeLockScreenDebounce(),
                        dozeLog),
                new TriggerSensor(
                        findSensorWithType(config.quickPickupSensorType()),
                        findSensor(config.quickPickupSensorType()),
                        Settings.Secure.DOZE_QUICK_PICKUP_GESTURE,
                        true /* setting default */,
                        config.quickPickupSensorEnabled(KeyguardUpdateMonitor.getCurrentUser())
@@ -244,21 +244,29 @@ public class DozeSensors {
        mDebounceFrom = SystemClock.uptimeMillis();
    }

    private Sensor findSensorWithType(String type) {
        return findSensorWithType(mSensorManager, type);
    private Sensor findSensor(String type) {
        return findSensor(mSensorManager, type, null);
    }

    /**
     * Utility method to find a {@link Sensor} for the supplied string type.
     * Utility method to find a {@link Sensor} for the supplied string type and string name.
     *
     * Return the first sensor in the list that matches the specified inputs. Ignores type or name
     * if the input is null or empty.
     *
     * @param type sensorType
     * @parm name sensorName, to differentiate between sensors with the same type
     */
    public static Sensor findSensorWithType(SensorManager sensorManager, String type) {
        if (TextUtils.isEmpty(type)) {
            return null;
    public static Sensor findSensor(SensorManager sensorManager, String type, String name) {
        final boolean isNameSpecified = !TextUtils.isEmpty(name);
        final boolean isTypeSpecified = !TextUtils.isEmpty(type);
        if (isNameSpecified || isTypeSpecified) {
            final List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ALL);
            for (Sensor sensor : sensors) {
                if ((!isNameSpecified || name.equals(sensor.getName()))
                        && (!isTypeSpecified || type.equals(sensor.getStringType()))) {
                    return sensor;
                }
        List<Sensor> sensorList = sensorManager.getSensorList(Sensor.TYPE_ALL);
        for (Sensor s : sensorList) {
            if (type.equals(s.getStringType())) {
                return s;
            }
        }
        return null;
+11 −3
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import com.android.systemui.doze.DozeTriggers;
import com.android.systemui.doze.DozeUi;
import com.android.systemui.doze.DozeWallpaperState;
import com.android.systemui.statusbar.phone.DozeParameters;
import com.android.systemui.statusbar.policy.DevicePostureController;
import com.android.systemui.util.sensors.AsyncSensorManager;
import com.android.systemui.util.wakelock.DelayedWakeLock;
import com.android.systemui.util.wakelock.WakeLock;
@@ -94,8 +95,15 @@ public abstract class DozeModule {
    @Provides
    @BrightnessSensor
    static Optional<Sensor> providesBrightnessSensor(
            AsyncSensorManager sensorManager, Context context) {
        return Optional.ofNullable(DozeSensors.findSensorWithType(sensorManager,
                context.getString(R.string.doze_brightness_sensor_type)));
            AsyncSensorManager sensorManager,
            Context context,
            DozeParameters dozeParameters,
            DevicePostureController devicePostureController) {
        return Optional.ofNullable(
                DozeSensors.findSensor(
                        sensorManager,
                        context.getString(R.string.doze_brightness_sensor_type),
                        dozeParameters.brightnessName(devicePostureController.getDevicePosture())
                ));
    }
}
+11 −0
Original line number Diff line number Diff line
@@ -282,6 +282,17 @@ public class DozeParameters implements
        return mResources.getBoolean(R.bool.doze_long_press_uses_prox);
    }

    /**
     * Sensor to use for brightness changes.
     */
    public String brightnessName(@DevicePostureController.DevicePostureInt int posture) {
        return AmbientDisplayConfiguration.getSensorFromPostureMapping(
                mResources.getStringArray(R.array.doze_brightness_sensor_name_posture_mapping),
                null /* defaultValue */,
                posture
        );
    }

    /**
     * Callback to listen for DozeParameter changes.
     */
Loading