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

Commit ac0da156 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Update DozeSensors and DozeBrightnessSensor on posture changes" into...

Merge "Update DozeSensors and DozeBrightnessSensor on posture changes" into sc-v2-dev am: 22314d89

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15983468

Change-Id: I2513907077181517855ec80de4dad9e53ade562a
parents 59bd397a 22314d89
Loading
Loading
Loading
Loading
+19 −32
Original line number Diff line number Diff line
@@ -22,11 +22,9 @@ import android.os.Build;
import android.os.SystemProperties;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;

import java.util.Arrays;

import com.android.internal.R;
import com.android.internal.util.ArrayUtils;

/**
 * AmbientDisplayConfiguration encapsulates reading access to the configuration of ambient display.
@@ -90,7 +88,12 @@ public class AmbientDisplayConfiguration {

    /** {@hide} */
    public boolean tapSensorAvailable() {
        return !TextUtils.isEmpty(tapSensorType());
        for (String tapType : tapSensorTypeMapping()) {
            if (!TextUtils.isEmpty(tapType)) {
                return true;
            }
        }
        return false;
    }

    /** {@hide} */
@@ -143,18 +146,18 @@ public class AmbientDisplayConfiguration {
        return mContext.getResources().getString(R.string.config_dozeDoubleTapSensorType);
    }

    /** {@hide} */
    private String tapSensorType() {
        return mContext.getResources().getString(R.string.config_dozeTapSensorType);
    /** {@hide}
     * May support multiple postures.
     */
    public String[] tapSensorTypeMapping() {
        String[] postureMapping =
                mContext.getResources().getStringArray(R.array.config_dozeTapSensorPostureMapping);
        if (ArrayUtils.isEmpty(postureMapping)) {
            return new String[] {
                    mContext.getResources().getString(R.string.config_dozeTapSensorType)
            };
        }

    /** {@hide} */
    public String tapSensorType(int posture) {
        return getSensorFromPostureMapping(
                mContext.getResources().getStringArray(R.array.config_dozeTapSensorPostureMapping),
                tapSensorType(),
                posture
        );
        return postureMapping;
    }

    /** {@hide} */
@@ -253,20 +256,4 @@ public class AmbientDisplayConfiguration {
    private boolean boolSetting(String name, int user, int def) {
        return Settings.Secure.getIntForUser(mContext.getContentResolver(), name, def, user) != 0;
    }

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

        return TextUtils.isEmpty(sensorType) ? defaultValue : sensorType;
    }
}
+17 −6
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import com.android.keyguard.KeyguardUpdateMonitorCallback;
import com.android.systemui.Dumpable;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.statusbar.policy.DevicePostureController;

import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -267,6 +268,16 @@ public class DozeLog implements Dumpable {
        }
    }

    /**
     * Appends doze updates due to a posture change.
     */
    public void tracePostureChanged(
            @DevicePostureController.DevicePostureInt int posture,
            String partUpdated
    ) {
        mLogger.logPostureChanged(posture, partUpdated);
    }

    /**
     * Appends pulse dropped event to logs
     */
@@ -391,8 +402,8 @@ public class DozeLog implements Dumpable {
            case REASON_SENSOR_DOUBLE_TAP: return "doubletap";
            case PULSE_REASON_SENSOR_LONG_PRESS: return "longpress";
            case PULSE_REASON_DOCKING: return "docking";
            case PULSE_REASON_SENSOR_WAKE_LOCK_SCREEN: return "reach-wakelockscreen";
            case REASON_SENSOR_WAKE_UP: return "presence-wakeup";
            case PULSE_REASON_SENSOR_WAKE_REACH: return "reach-wakelockscreen";
            case REASON_SENSOR_WAKE_UP_PRESENCE: return "presence-wakeup";
            case REASON_SENSOR_TAP: return "tap";
            case REASON_SENSOR_UDFPS_LONG_PRESS: return "udfps";
            case REASON_SENSOR_QUICK_PICKUP: return "quickPickup";
@@ -403,8 +414,8 @@ public class DozeLog implements Dumpable {
    @Retention(RetentionPolicy.SOURCE)
    @IntDef({PULSE_REASON_NONE, PULSE_REASON_INTENT, PULSE_REASON_NOTIFICATION,
            PULSE_REASON_SENSOR_SIGMOTION, REASON_SENSOR_PICKUP, REASON_SENSOR_DOUBLE_TAP,
            PULSE_REASON_SENSOR_LONG_PRESS, PULSE_REASON_DOCKING, REASON_SENSOR_WAKE_UP,
            PULSE_REASON_SENSOR_WAKE_LOCK_SCREEN, REASON_SENSOR_TAP,
            PULSE_REASON_SENSOR_LONG_PRESS, PULSE_REASON_DOCKING, REASON_SENSOR_WAKE_UP_PRESENCE,
            PULSE_REASON_SENSOR_WAKE_REACH, REASON_SENSOR_TAP,
            REASON_SENSOR_UDFPS_LONG_PRESS, REASON_SENSOR_QUICK_PICKUP})
    public @interface Reason {}
    public static final int PULSE_REASON_NONE = -1;
@@ -415,8 +426,8 @@ public class DozeLog implements Dumpable {
    public static final int REASON_SENSOR_DOUBLE_TAP = 4;
    public static final int PULSE_REASON_SENSOR_LONG_PRESS = 5;
    public static final int PULSE_REASON_DOCKING = 6;
    public static final int REASON_SENSOR_WAKE_UP = 7;
    public static final int PULSE_REASON_SENSOR_WAKE_LOCK_SCREEN = 8;
    public static final int REASON_SENSOR_WAKE_UP_PRESENCE = 7;
    public static final int PULSE_REASON_SENSOR_WAKE_REACH = 8;
    public static final int REASON_SENSOR_TAP = 9;
    public static final int REASON_SENSOR_UDFPS_LONG_PRESS = 10;
    public static final int REASON_SENSOR_QUICK_PICKUP = 11;
+11 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import com.android.systemui.log.LogLevel.DEBUG
import com.android.systemui.log.LogLevel.ERROR
import com.android.systemui.log.LogLevel.INFO
import com.android.systemui.log.dagger.DozeLog
import com.android.systemui.statusbar.policy.DevicePostureController
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
@@ -195,6 +196,16 @@ class DozeLogger @Inject constructor(
        })
    }

    fun logPostureChanged(posture: Int, partUpdated: String) {
        buffer.log(TAG, INFO, {
            int1 = posture
            str1 = partUpdated
        }, {
            "Posture changed, posture=${DevicePostureController.devicePostureToString(int1)}" +
                    " partUpdated=$str1"
        })
    }

    fun logPulseDropped(pulsePending: Boolean, state: DozeMachine.State, blocked: Boolean) {
        buffer.log(TAG, INFO, {
            bool1 = pulsePending
+82 −11
Original line number Diff line number Diff line
@@ -29,16 +29,18 @@ import android.os.SystemProperties;
import android.os.Trace;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.IndentingPrintWriter;

import com.android.systemui.dock.DockManager;
import com.android.systemui.doze.dagger.BrightnessSensor;
import com.android.systemui.doze.dagger.DozeScope;
import com.android.systemui.doze.dagger.WrappedService;
import com.android.systemui.keyguard.WakefulnessLifecycle;
import com.android.systemui.statusbar.phone.DozeParameters;
import com.android.systemui.statusbar.policy.DevicePostureController;
import com.android.systemui.util.sensors.AsyncSensorManager;

import java.io.PrintWriter;
import java.util.Objects;
import java.util.Optional;

import javax.inject.Inject;
@@ -60,14 +62,17 @@ public class DozeScreenBrightness extends BroadcastReceiver implements DozeMachi
    private final DozeHost mDozeHost;
    private final Handler mHandler;
    private final SensorManager mSensorManager;
    private final Optional<Sensor> mLightSensorOptional;
    private final Optional<Sensor>[] mLightSensorOptional; // light sensors to use per posture
    private final WakefulnessLifecycle mWakefulnessLifecycle;
    private final DozeParameters mDozeParameters;
    private final DockManager mDockManager;
    private final DevicePostureController mDevicePostureController;
    private final DozeLog mDozeLog;
    private final int[] mSensorToBrightness;
    private final int[] mSensorToScrimOpacity;
    private final int mScreenBrightnessDim;

    @DevicePostureController.DevicePostureInt
    private int mDevicePosture;
    private boolean mRegistered;
    private int mDefaultDozeBrightness;
    private boolean mPaused = false;
@@ -83,27 +88,36 @@ public class DozeScreenBrightness extends BroadcastReceiver implements DozeMachi
    private int mDebugBrightnessBucket = -1;

    @Inject
    public DozeScreenBrightness(Context context, @WrappedService DozeMachine.Service service,
    public DozeScreenBrightness(
            Context context,
            @WrappedService DozeMachine.Service service,
            AsyncSensorManager sensorManager,
            @BrightnessSensor Optional<Sensor> lightSensorOptional, DozeHost host, Handler handler,
            @BrightnessSensor Optional<Sensor>[] lightSensorOptional,
            DozeHost host, Handler handler,
            AlwaysOnDisplayPolicy alwaysOnDisplayPolicy,
            WakefulnessLifecycle wakefulnessLifecycle,
            DozeParameters dozeParameters,
            DockManager dockManager) {
            DevicePostureController devicePostureController,
            DozeLog dozeLog
    ) {
        mContext = context;
        mDozeService = service;
        mSensorManager = sensorManager;
        mLightSensorOptional = lightSensorOptional;
        mDevicePostureController = devicePostureController;
        mDevicePosture = mDevicePostureController.getDevicePosture();
        mWakefulnessLifecycle = wakefulnessLifecycle;
        mDozeParameters = dozeParameters;
        mDozeHost = host;
        mHandler = handler;
        mDockManager = dockManager;
        mDozeLog = dozeLog;

        mDefaultDozeBrightness = alwaysOnDisplayPolicy.defaultDozeBrightness;
        mScreenBrightnessDim = alwaysOnDisplayPolicy.dimBrightness;
        mSensorToBrightness = alwaysOnDisplayPolicy.screenBrightnessArray;
        mSensorToScrimOpacity = alwaysOnDisplayPolicy.dimmingScrimArray;

        mDevicePostureController.addCallback(mDevicePostureCallback);
    }

    @Override
@@ -133,6 +147,7 @@ public class DozeScreenBrightness extends BroadcastReceiver implements DozeMachi

    private void onDestroy() {
        setLightSensorEnabled(false);
        mDevicePostureController.removeCallback(mDevicePostureCallback);
    }

    @Override
@@ -159,7 +174,7 @@ public class DozeScreenBrightness extends BroadcastReceiver implements DozeMachi
            }

            int scrimOpacity = -1;
            if (!mLightSensorOptional.isPresent()) {
            if (!isLightSensorPresent()) {
                // No light sensor, scrims are always transparent.
                scrimOpacity = 0;
            } else if (brightnessReady) {
@@ -172,6 +187,27 @@ public class DozeScreenBrightness extends BroadcastReceiver implements DozeMachi
        }
    }

    private boolean lightSensorSupportsCurrentPosture() {
        return mLightSensorOptional != null
                && mDevicePosture < mLightSensorOptional.length;
    }

    private boolean isLightSensorPresent() {
        if (!lightSensorSupportsCurrentPosture()) {
            return mLightSensorOptional != null && mLightSensorOptional[0].isPresent();
        }

        return mLightSensorOptional[mDevicePosture].isPresent();
    }

    private Sensor getLightSensor() {
        if (!lightSensorSupportsCurrentPosture()) {
            return null;
        }

        return mLightSensorOptional[mDevicePosture].get();
    }

    private int computeScrimOpacity(int sensorValue) {
        if (sensorValue < 0 || sensorValue >= mSensorToScrimOpacity.length) {
            return -1;
@@ -220,9 +256,9 @@ public class DozeScreenBrightness extends BroadcastReceiver implements DozeMachi
    }

    private void setLightSensorEnabled(boolean enabled) {
        if (enabled && !mRegistered && mLightSensorOptional.isPresent()) {
        if (enabled && !mRegistered && isLightSensorPresent()) {
            // Wait until we get an event from the sensor until indicating ready.
            mRegistered = mSensorManager.registerListener(this, mLightSensorOptional.get(),
            mRegistered = mSensorManager.registerListener(this, getLightSensor(),
                    SensorManager.SENSOR_DELAY_NORMAL, mHandler);
            mLastSensorValue = -1;
        } else if (!enabled && mRegistered) {
@@ -255,6 +291,41 @@ public class DozeScreenBrightness extends BroadcastReceiver implements DozeMachi

    /** Dump current state */
    public void dump(PrintWriter pw) {
        pw.println("DozeScreenBrightnessSensorRegistered=" + mRegistered);
        pw.println("DozeScreenBrightness:");
        IndentingPrintWriter idpw = new IndentingPrintWriter(pw);
        idpw.increaseIndent();
        idpw.println("registered=" + mRegistered);
        idpw.println("posture=" + DevicePostureController.devicePostureToString(mDevicePosture));
    }

    private final DevicePostureController.Callback mDevicePostureCallback =
            new DevicePostureController.Callback() {
        @Override
        public void onPostureChanged(int posture) {
            if (mDevicePosture == posture
                    || mLightSensorOptional.length < 2
                    || posture >= mLightSensorOptional.length) {
                return;
            }

            final Sensor oldSensor = mLightSensorOptional[mDevicePosture].get();
            final Sensor newSensor = mLightSensorOptional[posture].get();
            if (Objects.equals(oldSensor, newSensor)) {
                mDevicePosture = posture;
                // uses the same sensor for the new posture
                return;
            }

            // cancel the previous sensor:
            if (mRegistered) {
                setLightSensorEnabled(false);
                mDevicePosture = posture;
                setLightSensorEnabled(true);
            } else {
                mDevicePosture = posture;
            }
            mDozeLog.tracePostureChanged(mDevicePosture, "DozeScreenBrightness swap "
                    + "{" + oldSensor + "} => {" + newSensor + "}, mRegistered=" + mRegistered);
        }
    };
}
+235 −82

File changed.

Preview size limit exceeded, changes collapsed.

Loading