Add some logging to aid debugging device state transitions.

Bug: 186165695
Test: Check logcat while debugging.
Change-Id: Id6be6ccc1d6d4f0efbab0f08e9515665e7d44b91
diff --git a/services/core/java/com/android/server/policy/DeviceStateProviderImpl.java b/services/core/java/com/android/server/policy/DeviceStateProviderImpl.java
index ff6511f..27a16e9 100644
--- a/services/core/java/com/android/server/policy/DeviceStateProviderImpl.java
+++ b/services/core/java/com/android/server/policy/DeviceStateProviderImpl.java
@@ -82,6 +82,7 @@
 public final class DeviceStateProviderImpl implements DeviceStateProvider,
         InputManagerInternal.LidSwitchCallback, SensorEventListener {
     private static final String TAG = "DeviceStateProviderImpl";
+    private static final boolean DEBUG = false;
 
     private static final BooleanSupplier TRUE_BOOLEAN_SUPPLIER = () -> true;
     private static final BooleanSupplier FALSE_BOOLEAN_SUPPLIER = () -> false;
@@ -213,6 +214,10 @@
 
         for (int i = 0; i < stateConditions.size(); i++) {
             final int state = deviceStates.get(i).getIdentifier();
+            if (DEBUG) {
+                Slog.d(TAG, "Evaluating conditions for device state " + state
+                        + " (" + deviceStates.get(i).getName() + ")");
+            }
             final Conditions conditions = stateConditions.get(i);
             if (conditions == null) {
                 mStateConditions.put(state, TRUE_BOOLEAN_SUPPLIER);
@@ -233,6 +238,9 @@
             if (lidSwitchCondition != null) {
                 suppliers.add(new LidSwitchBooleanSupplier(lidSwitchCondition.getOpen()));
                 lidSwitchRequired = true;
+                if (DEBUG) {
+                    Slog.d(TAG, "Lid switch required");
+                }
             }
 
             List<SensorCondition> sensorConditions = conditions.getSensor();
@@ -249,6 +257,11 @@
                     break;
                 }
 
+                if (DEBUG) {
+                    Slog.d(TAG, "Found sensor with type: " + expectedSensorType
+                            + " (" + expectedSensorName + ")");
+                }
+
                 suppliers.add(new SensorBooleanSupplier(foundSensor, sensorCondition.getValue()));
                 sensorsRequired.add(foundSensor);
             }
@@ -343,6 +356,10 @@
             int newState = mOrderedStates[0].getIdentifier();
             for (int i = 0; i < mOrderedStates.length; i++) {
                 int state = mOrderedStates[i].getIdentifier();
+                if (DEBUG) {
+                    Slog.d(TAG, "Checking conditions for " + mOrderedStates[i].getName() + "("
+                            + i + ")");
+                }
                 boolean conditionSatisfied;
                 try {
                     conditionSatisfied = mStateConditions.get(state).getAsBoolean();
@@ -350,10 +367,16 @@
                     // Failed to compute the current state based on current available data. Return
                     // with the expectation that notifyDeviceStateChangedIfNeeded() will be called
                     // when a callback with the missing data is triggered.
+                    if (DEBUG) {
+                        Slog.d(TAG, "Unable to check current state", e);
+                    }
                     return;
                 }
 
                 if (conditionSatisfied) {
+                    if (DEBUG) {
+                        Slog.d(TAG, "Device State conditions satisfied, transition to " + state);
+                    }
                     newState = state;
                     break;
                 }
@@ -375,6 +398,9 @@
         synchronized (mLock) {
             mIsLidOpen = lidOpen;
         }
+        if (DEBUG) {
+            Slog.d(TAG, "Lid switch state: " + (lidOpen ? "open" : "closed"));
+        }
         notifyDeviceStateChangedIfNeeded();
     }
 
@@ -460,6 +486,9 @@
         private boolean adheresToRange(float value, @NonNull NumericRange range) {
             final BigDecimal min = range.getMin_optional();
             if (min != null) {
+                if (DEBUG) {
+                    Slog.d(TAG, "value: " + value + ", constraint min: " + min.floatValue());
+                }
                 if (value <= min.floatValue()) {
                     return false;
                 }
@@ -467,6 +496,10 @@
 
             final BigDecimal minInclusive = range.getMinInclusive_optional();
             if (minInclusive != null) {
+                if (DEBUG) {
+                    Slog.d(TAG, "value: " + value + ", constraint min-inclusive: "
+                            + minInclusive.floatValue());
+                }
                 if (value < minInclusive.floatValue()) {
                     return false;
                 }
@@ -474,6 +507,9 @@
 
             final BigDecimal max = range.getMax_optional();
             if (max != null) {
+                if (DEBUG) {
+                    Slog.d(TAG, "value: " + value + ", constraint max: " + max.floatValue());
+                }
                 if (value >= max.floatValue()) {
                     return false;
                 }
@@ -481,6 +517,10 @@
 
             final BigDecimal maxInclusive = range.getMaxInclusive_optional();
             if (maxInclusive != null) {
+                if (DEBUG) {
+                    Slog.d(TAG, "value: " + value + ", constraint max-inclusive: "
+                            + maxInclusive.floatValue());
+                }
                 if (value > maxInclusive.floatValue()) {
                     return false;
                 }