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

Commit 21ad9031 authored by Android Build Prod User's avatar Android Build Prod User Committed by Automerger Merge Worker
Browse files

Merge "Add some logging to aid debugging device state transitions." into...

Merge "Add some logging to aid debugging device state transitions." into sc-v2-dev am: d1436f18 am: c2544619

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

Change-Id: I8ccfa36a38e8ab1e25133c7e012fdf8b9fe417d4
parents 79a67bac c2544619
Loading
Loading
Loading
Loading
+40 −0
Original line number Diff line number Diff line
@@ -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;
                }