diff options
| -rw-r--r-- | services/core/java/com/android/server/policy/DeviceStateProviderImpl.java | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/policy/DeviceStateProviderImpl.java b/services/core/java/com/android/server/policy/DeviceStateProviderImpl.java index ff6511f06577..27a16e9bfdda 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 @@ import javax.xml.datatype.DatatypeConfigurationException; 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 @@ public final class DeviceStateProviderImpl implements DeviceStateProvider, 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 @@ public final class DeviceStateProviderImpl implements DeviceStateProvider, 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 @@ public final class DeviceStateProviderImpl implements DeviceStateProvider, 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 @@ public final class DeviceStateProviderImpl implements DeviceStateProvider, 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 @@ public final class DeviceStateProviderImpl implements DeviceStateProvider, // 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 @@ public final class DeviceStateProviderImpl implements DeviceStateProvider, synchronized (mLock) { mIsLidOpen = lidOpen; } + if (DEBUG) { + Slog.d(TAG, "Lid switch state: " + (lidOpen ? "open" : "closed")); + } notifyDeviceStateChangedIfNeeded(); } @@ -460,6 +486,9 @@ public final class DeviceStateProviderImpl implements DeviceStateProvider, 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 @@ public final class DeviceStateProviderImpl implements DeviceStateProvider, 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 @@ public final class DeviceStateProviderImpl implements DeviceStateProvider, 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 @@ public final class DeviceStateProviderImpl implements DeviceStateProvider, 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; } |