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

Commit c839cfe0 authored by Ben Murdoch's avatar Ben Murdoch
Browse files

Add some logging to aid debugging device state transitions.

Bug: 186165695
Test: Check logcat while debugging.
Change-Id: Id6be6ccc1d6d4f0efbab0f08e9515665e7d44b91
parent 5082dcb7
Loading
Loading
Loading
Loading
+40 −0
Original line number Original line Diff line number Diff line
@@ -82,6 +82,7 @@ import javax.xml.datatype.DatatypeConfigurationException;
public final class DeviceStateProviderImpl implements DeviceStateProvider,
public final class DeviceStateProviderImpl implements DeviceStateProvider,
        InputManagerInternal.LidSwitchCallback, SensorEventListener {
        InputManagerInternal.LidSwitchCallback, SensorEventListener {
    private static final String TAG = "DeviceStateProviderImpl";
    private static final String TAG = "DeviceStateProviderImpl";
    private static final boolean DEBUG = false;


    private static final BooleanSupplier TRUE_BOOLEAN_SUPPLIER = () -> true;
    private static final BooleanSupplier TRUE_BOOLEAN_SUPPLIER = () -> true;
    private static final BooleanSupplier FALSE_BOOLEAN_SUPPLIER = () -> false;
    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++) {
        for (int i = 0; i < stateConditions.size(); i++) {
            final int state = deviceStates.get(i).getIdentifier();
            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);
            final Conditions conditions = stateConditions.get(i);
            if (conditions == null) {
            if (conditions == null) {
                mStateConditions.put(state, TRUE_BOOLEAN_SUPPLIER);
                mStateConditions.put(state, TRUE_BOOLEAN_SUPPLIER);
@@ -233,6 +238,9 @@ public final class DeviceStateProviderImpl implements DeviceStateProvider,
            if (lidSwitchCondition != null) {
            if (lidSwitchCondition != null) {
                suppliers.add(new LidSwitchBooleanSupplier(lidSwitchCondition.getOpen()));
                suppliers.add(new LidSwitchBooleanSupplier(lidSwitchCondition.getOpen()));
                lidSwitchRequired = true;
                lidSwitchRequired = true;
                if (DEBUG) {
                    Slog.d(TAG, "Lid switch required");
                }
            }
            }


            List<SensorCondition> sensorConditions = conditions.getSensor();
            List<SensorCondition> sensorConditions = conditions.getSensor();
@@ -249,6 +257,11 @@ public final class DeviceStateProviderImpl implements DeviceStateProvider,
                    break;
                    break;
                }
                }


                if (DEBUG) {
                    Slog.d(TAG, "Found sensor with type: " + expectedSensorType
                            + " (" + expectedSensorName + ")");
                }

                suppliers.add(new SensorBooleanSupplier(foundSensor, sensorCondition.getValue()));
                suppliers.add(new SensorBooleanSupplier(foundSensor, sensorCondition.getValue()));
                sensorsRequired.add(foundSensor);
                sensorsRequired.add(foundSensor);
            }
            }
@@ -343,6 +356,10 @@ public final class DeviceStateProviderImpl implements DeviceStateProvider,
            int newState = mOrderedStates[0].getIdentifier();
            int newState = mOrderedStates[0].getIdentifier();
            for (int i = 0; i < mOrderedStates.length; i++) {
            for (int i = 0; i < mOrderedStates.length; i++) {
                int state = mOrderedStates[i].getIdentifier();
                int state = mOrderedStates[i].getIdentifier();
                if (DEBUG) {
                    Slog.d(TAG, "Checking conditions for " + mOrderedStates[i].getName() + "("
                            + i + ")");
                }
                boolean conditionSatisfied;
                boolean conditionSatisfied;
                try {
                try {
                    conditionSatisfied = mStateConditions.get(state).getAsBoolean();
                    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
                    // Failed to compute the current state based on current available data. Return
                    // with the expectation that notifyDeviceStateChangedIfNeeded() will be called
                    // with the expectation that notifyDeviceStateChangedIfNeeded() will be called
                    // when a callback with the missing data is triggered.
                    // when a callback with the missing data is triggered.
                    if (DEBUG) {
                        Slog.d(TAG, "Unable to check current state", e);
                    }
                    return;
                    return;
                }
                }


                if (conditionSatisfied) {
                if (conditionSatisfied) {
                    if (DEBUG) {
                        Slog.d(TAG, "Device State conditions satisfied, transition to " + state);
                    }
                    newState = state;
                    newState = state;
                    break;
                    break;
                }
                }
@@ -375,6 +398,9 @@ public final class DeviceStateProviderImpl implements DeviceStateProvider,
        synchronized (mLock) {
        synchronized (mLock) {
            mIsLidOpen = lidOpen;
            mIsLidOpen = lidOpen;
        }
        }
        if (DEBUG) {
            Slog.d(TAG, "Lid switch state: " + (lidOpen ? "open" : "closed"));
        }
        notifyDeviceStateChangedIfNeeded();
        notifyDeviceStateChangedIfNeeded();
    }
    }


@@ -460,6 +486,9 @@ public final class DeviceStateProviderImpl implements DeviceStateProvider,
        private boolean adheresToRange(float value, @NonNull NumericRange range) {
        private boolean adheresToRange(float value, @NonNull NumericRange range) {
            final BigDecimal min = range.getMin_optional();
            final BigDecimal min = range.getMin_optional();
            if (min != null) {
            if (min != null) {
                if (DEBUG) {
                    Slog.d(TAG, "value: " + value + ", constraint min: " + min.floatValue());
                }
                if (value <= min.floatValue()) {
                if (value <= min.floatValue()) {
                    return false;
                    return false;
                }
                }
@@ -467,6 +496,10 @@ public final class DeviceStateProviderImpl implements DeviceStateProvider,


            final BigDecimal minInclusive = range.getMinInclusive_optional();
            final BigDecimal minInclusive = range.getMinInclusive_optional();
            if (minInclusive != null) {
            if (minInclusive != null) {
                if (DEBUG) {
                    Slog.d(TAG, "value: " + value + ", constraint min-inclusive: "
                            + minInclusive.floatValue());
                }
                if (value < minInclusive.floatValue()) {
                if (value < minInclusive.floatValue()) {
                    return false;
                    return false;
                }
                }
@@ -474,6 +507,9 @@ public final class DeviceStateProviderImpl implements DeviceStateProvider,


            final BigDecimal max = range.getMax_optional();
            final BigDecimal max = range.getMax_optional();
            if (max != null) {
            if (max != null) {
                if (DEBUG) {
                    Slog.d(TAG, "value: " + value + ", constraint max: " + max.floatValue());
                }
                if (value >= max.floatValue()) {
                if (value >= max.floatValue()) {
                    return false;
                    return false;
                }
                }
@@ -481,6 +517,10 @@ public final class DeviceStateProviderImpl implements DeviceStateProvider,


            final BigDecimal maxInclusive = range.getMaxInclusive_optional();
            final BigDecimal maxInclusive = range.getMaxInclusive_optional();
            if (maxInclusive != null) {
            if (maxInclusive != null) {
                if (DEBUG) {
                    Slog.d(TAG, "value: " + value + ", constraint max-inclusive: "
                            + maxInclusive.floatValue());
                }
                if (value > maxInclusive.floatValue()) {
                if (value > maxInclusive.floatValue()) {
                    return false;
                    return false;
                }
                }