Merge "Improving proximity state logs" into main
diff --git a/services/core/java/com/android/server/display/DisplayPowerController.java b/services/core/java/com/android/server/display/DisplayPowerController.java
index ab80b14..f48fbea 100644
--- a/services/core/java/com/android/server/display/DisplayPowerController.java
+++ b/services/core/java/com/android/server/display/DisplayPowerController.java
@@ -3311,7 +3311,7 @@
int displayId, SensorManager sensorManager) {
return new DisplayPowerProximityStateController(wakelockController, displayDeviceConfig,
looper, nudgeUpdatePowerState,
- displayId, sensorManager, /* injector= */ null);
+ displayId, sensorManager);
}
AutomaticBrightnessController getAutomaticBrightnessController(
diff --git a/services/core/java/com/android/server/display/DisplayPowerProximityStateController.java b/services/core/java/com/android/server/display/DisplayPowerProximityStateController.java
index 215932c..35455c8 100644
--- a/services/core/java/com/android/server/display/DisplayPowerProximityStateController.java
+++ b/services/core/java/com/android/server/display/DisplayPowerProximityStateController.java
@@ -16,6 +16,8 @@
package com.android.server.display;
+import android.annotation.IntDef;
+import android.annotation.Nullable;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
@@ -34,6 +36,8 @@
import com.android.server.display.utils.SensorUtils;
import java.io.PrintWriter;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
/**
* Maintains the proximity state of the display.
@@ -42,18 +46,26 @@
*/
public final class DisplayPowerProximityStateController {
@VisibleForTesting
- static final int MSG_PROXIMITY_SENSOR_DEBOUNCED = 1;
- @VisibleForTesting
static final int PROXIMITY_UNKNOWN = -1;
+ private static final int PROXIMITY_NEGATIVE = 0;
@VisibleForTesting
static final int PROXIMITY_POSITIVE = 1;
+
+ @IntDef(prefix = { "PROXIMITY_" }, value = {
+ PROXIMITY_UNKNOWN,
+ PROXIMITY_NEGATIVE,
+ PROXIMITY_POSITIVE
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ @interface ProximityState {}
+
+ @VisibleForTesting
+ static final int MSG_PROXIMITY_SENSOR_DEBOUNCED = 1;
@VisibleForTesting
static final int PROXIMITY_SENSOR_POSITIVE_DEBOUNCE_DELAY = 0;
private static final int MSG_IGNORE_PROXIMITY = 2;
- private static final int PROXIMITY_NEGATIVE = 0;
-
private static final boolean DEBUG_PRETEND_PROXIMITY_SENSOR_ABSENT = false;
// Proximity sensor debounce delay in milliseconds for positive transitions.
@@ -73,7 +85,7 @@
private final DisplayPowerProximityStateHandler mHandler;
// A runnable to execute the utility to update the power state.
private final Runnable mNudgeUpdatePowerState;
- private Clock mClock;
+ private final Clock mClock;
// A listener which listen's to the events emitted by the proximity sensor.
private final SensorEventListener mProximitySensorListener = new SensorEventListener() {
@Override
@@ -117,9 +129,6 @@
// with the sensor manager.
private boolean mProximitySensorEnabled;
- // The raw non-debounced proximity sensor state.
- private int mPendingProximity = PROXIMITY_UNKNOWN;
-
// -1 if fully debounced. Else, represents the time in ms when the debounce suspend blocker will
// be removed. Applies for both positive and negative proximity flips.
private long mPendingProximityDebounceTime = -1;
@@ -128,8 +137,11 @@
// When the screen turns on again, we report user activity to the power manager.
private boolean mScreenOffBecauseOfProximity;
+ // The raw non-debounced proximity sensor state.
+ private @ProximityState int mPendingProximity = PROXIMITY_UNKNOWN;
+
// The debounced proximity sensor state.
- private int mProximity = PROXIMITY_UNKNOWN;
+ private @ProximityState int mProximity = PROXIMITY_UNKNOWN;
// The actual proximity sensor threshold value.
private float mProximityThreshold;
@@ -139,7 +151,7 @@
private boolean mSkipRampBecauseOfProximityChangeToNegative = false;
// The DisplayId of the associated Logical Display.
- private int mDisplayId;
+ private final int mDisplayId;
/**
* Create a new instance of DisplayPowerProximityStateController.
@@ -152,11 +164,18 @@
* @param displayId The DisplayId of the associated Logical Display.
* @param sensorManager The manager which lets us access the display's ProximitySensor
*/
- public DisplayPowerProximityStateController(
- WakelockController wakeLockController, DisplayDeviceConfig displayDeviceConfig,
- Looper looper,
+ public DisplayPowerProximityStateController(WakelockController wakeLockController,
+ DisplayDeviceConfig displayDeviceConfig, Looper looper,
+ Runnable nudgeUpdatePowerState, int displayId, SensorManager sensorManager) {
+ this(wakeLockController, displayDeviceConfig, looper, nudgeUpdatePowerState, displayId,
+ sensorManager, new Injector());
+ }
+
+ @VisibleForTesting
+ DisplayPowerProximityStateController(WakelockController wakeLockController,
+ DisplayDeviceConfig displayDeviceConfig, Looper looper,
Runnable nudgeUpdatePowerState, int displayId, SensorManager sensorManager,
- Injector injector) {
+ @Nullable Injector injector) {
if (injector == null) {
injector = new Injector();
}
@@ -437,7 +456,7 @@
if (mProximity != mPendingProximity) {
// if the status of the sensor changed, stop ignoring.
mIgnoreProximityUntilChanged = false;
- Slog.i(mTag, "No longer ignoring proximity [" + mPendingProximity + "]");
+ Slog.i(mTag, "Applying proximity: " + proximityToString(mPendingProximity));
}
// Sensor reading accepted. Apply the change then release the wake lock.
mProximity = mPendingProximity;
@@ -478,7 +497,7 @@
}
}
- private String proximityToString(int state) {
+ private String proximityToString(@ProximityState int state) {
switch (state) {
case PROXIMITY_UNKNOWN:
return "Unknown";
@@ -518,12 +537,12 @@
}
@VisibleForTesting
- int getPendingProximity() {
+ @ProximityState int getPendingProximity() {
return mPendingProximity;
}
@VisibleForTesting
- int getProximity() {
+ @ProximityState int getProximity() {
return mProximity;
}
@@ -550,7 +569,7 @@
@VisibleForTesting
static class Injector {
Clock createClock() {
- return () -> SystemClock.uptimeMillis();
+ return SystemClock::uptimeMillis;
}
}
}