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

Commit aec75f67 authored by Kenneth Ford's avatar Kenneth Ford
Browse files

Pass DeviceState objects from DeviceStateManagerService to the client

Returns DeviceState objects from the system server to clients that
are listening to DeviceStateManager

Bug: 293636629
Test: DeviceStateInfoTest
Test: DeviceStateManagerGlobalTest
Change-Id: I4e33a32fd65a9059a2136492179029ee218b26a1
parent d48642dc
Loading
Loading
Loading
Loading
+61 −12
Original line number Diff line number Diff line
@@ -25,6 +25,9 @@ import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.ArraySet;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@@ -35,8 +38,7 @@ import java.util.Objects;
import java.util.Set;

/**
 * A state of the device defined by the {@link DeviceStateProvider} and managed by the
 * {@link DeviceStateManagerService}.
 * A state of the device managed by {@link DeviceStateManager}.
 * <p>
 * Device state is an abstract concept that allows mapping the current state of the device to the
 * state of the system. This is useful for variable-state devices, like foldable or rollable
@@ -298,13 +300,14 @@ public final class DeviceState {
    public @interface SystemDeviceStateProperties {}

    @NonNull
    private DeviceState.Configuration mDeviceStateConfiguration;
    private final DeviceState.Configuration mDeviceStateConfiguration;

    @DeviceStateFlags
    private final int mFlags;

    /** @hide */
    public DeviceState(@NonNull DeviceState.Configuration deviceStateConfiguration) {
        Objects.requireNonNull(deviceStateConfiguration, "Device StateConfiguration is null");
        mDeviceStateConfiguration = deviceStateConfiguration;
        mFlags = 0;
    }
@@ -408,8 +411,7 @@ public final class DeviceState {
     */
    public boolean hasProperties(@NonNull @DeviceStateProperties int... properties) {
        for (int i = 0; i < properties.length; i++) {
            if (!mDeviceStateConfiguration.mSystemProperties.contains(properties[i])
                    || !mDeviceStateConfiguration.mPhysicalProperties.contains(properties[i])) {
            if (!hasProperty(properties[i])) {
                return false;
            }
        }
@@ -436,7 +438,7 @@ public final class DeviceState {
     * @see DeviceStateManager
     * @hide
     */
    public static class Configuration {
    public static final class Configuration implements Parcelable {
        /** Unique identifier for the device state. */
        @IntRange(from = MINIMUM_DEVICE_STATE_IDENTIFIER, to = MAXIMUM_DEVICE_STATE_IDENTIFIER)
        private final int mIdentifier;
@@ -445,21 +447,23 @@ public final class DeviceState {
        @NonNull
        private final String mName;

        /** {@link Set} of system properties that apply to this state. */
        /** {@link ArraySet} of system properties that apply to this state. */
        @NonNull
        private final Set<@SystemDeviceStateProperties Integer> mSystemProperties;
        private final ArraySet<@SystemDeviceStateProperties Integer> mSystemProperties;

        /** {@link Set} of physical device properties that apply to this state. */
        /** {@link ArraySet} of physical device properties that apply to this state. */
        @NonNull
        private final Set<@PhysicalDeviceStateProperties Integer> mPhysicalProperties;
        private final ArraySet<@PhysicalDeviceStateProperties Integer> mPhysicalProperties;

        private Configuration(int identifier, @NonNull String name,
                @NonNull Set<@SystemDeviceStateProperties Integer> systemProperties,
                @NonNull Set<@PhysicalDeviceStateProperties Integer> physicalProperties) {
            mIdentifier = identifier;
            mName = name;
            mSystemProperties = systemProperties;
            mPhysicalProperties = physicalProperties;
            mSystemProperties = new ArraySet<@SystemDeviceStateProperties Integer>(
                    systemProperties);
            mPhysicalProperties = new ArraySet<@PhysicalDeviceStateProperties Integer>(
                    physicalProperties);
        }

        /** Returns the unique identifier for the device state. */
@@ -511,6 +515,51 @@ public final class DeviceState {
            return Objects.hash(mIdentifier, mName, mSystemProperties, mPhysicalProperties);
        }

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(@NonNull Parcel dest, int flags) {
            dest.writeInt(mIdentifier);
            dest.writeString8(mName);

            dest.writeInt(mSystemProperties.size());
            for (int i = 0; i < mSystemProperties.size(); i++) {
                dest.writeInt(mSystemProperties.valueAt(i));
            }

            dest.writeInt(mPhysicalProperties.size());
            for (int i = 0; i < mPhysicalProperties.size(); i++) {
                dest.writeInt(mPhysicalProperties.valueAt(i));
            }
        }

        @NonNull
        public static final Creator<DeviceState.Configuration> CREATOR = new Creator<>() {
            @Override
            public DeviceState.Configuration createFromParcel(Parcel source) {
                int identifier = source.readInt();
                String name = source.readString8();
                ArraySet<@DeviceStateProperties Integer> systemProperties = new ArraySet<>();
                for (int i = 0; i < source.readInt(); i++) {
                    systemProperties.add(source.readInt());
                }
                ArraySet<@DeviceStateProperties Integer> physicalProperties = new ArraySet<>();
                for (int j = 0; j < source.readInt(); j++) {
                    physicalProperties.add(source.readInt());
                }
                return new DeviceState.Configuration(identifier, name, systemProperties,
                        physicalProperties);
            }

            @Override
            public DeviceState.Configuration[] newArray(int size) {
                return new DeviceState.Configuration[size];
            }
        };

        /** @hide */
        public static class Builder {
            private final int mIdentifier;
+31 −25
Original line number Diff line number Diff line
@@ -24,7 +24,8 @@ import android.os.Parcelable;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Executor;

@@ -56,19 +57,19 @@ public final class DeviceStateInfo implements Parcelable {
     * The list of states supported by the device.
     */
    @NonNull
    public final int[] supportedStates;
    public final ArrayList<DeviceState> supportedStates;

    /**
     * The base (non-override) state of the device. The base state is the state of the device
     * ignoring any override requests made through a call to {@link DeviceStateManager#requestState(
     * DeviceStateRequest, Executor, DeviceStateRequest.Callback)}.
     */
    public final int baseState;
    public final DeviceState baseState;

    /**
     * The state of the device.
     */
    public final int currentState;
    public final DeviceState currentState;

    /**
     * Creates a new instance of {@link DeviceStateInfo}.
@@ -76,8 +77,9 @@ public final class DeviceStateInfo implements Parcelable {
     * NOTE: Unlike {@link #DeviceStateInfo(DeviceStateInfo)}, this constructor does not copy the
     * supplied parameters.
     */
    public DeviceStateInfo(@NonNull int[] supportedStates, int baseState, int state) {
        this.supportedStates = supportedStates;
    public DeviceStateInfo(@NonNull List<DeviceState> supportedStates, DeviceState baseState,
            DeviceState state) {
        this.supportedStates = new ArrayList<>(supportedStates);
        this.baseState = baseState;
        this.currentState = state;
    }
@@ -87,8 +89,7 @@ public final class DeviceStateInfo implements Parcelable {
     * the fields of the returned instance.
     */
    public DeviceStateInfo(@NonNull DeviceStateInfo info) {
        this(Arrays.copyOf(info.supportedStates, info.supportedStates.length),
                info.baseState, info.currentState);
        this(List.copyOf(info.supportedStates), info.baseState, info.currentState);
    }

    @Override
@@ -96,15 +97,15 @@ public final class DeviceStateInfo implements Parcelable {
        if (this == other) return true;
        if (other == null || getClass() != other.getClass()) return false;
        DeviceStateInfo that = (DeviceStateInfo) other;
        return baseState == that.baseState
                &&  currentState == that.currentState
                && Arrays.equals(supportedStates, that.supportedStates);
        return baseState.equals(that.baseState)
                &&  currentState.equals(that.currentState)
                && Objects.equals(supportedStates, that.supportedStates);
    }

    @Override
    public int hashCode() {
        int result = Objects.hash(baseState, currentState);
        result = 31 * result + Arrays.hashCode(supportedStates);
        result = 31 * result + supportedStates.hashCode();
        return result;
    }

@@ -112,13 +113,13 @@ public final class DeviceStateInfo implements Parcelable {
    @ChangeFlags
    public int diff(@NonNull DeviceStateInfo other) {
        int diff = 0;
        if (!Arrays.equals(supportedStates, other.supportedStates)) {
        if (!supportedStates.equals(other.supportedStates)) {
            diff |= CHANGED_SUPPORTED_STATES;
        }
        if (baseState != other.baseState) {
        if (!baseState.equals(other.baseState)) {
            diff |= CHANGED_BASE_STATE;
        }
        if (currentState != other.currentState) {
        if (!currentState.equals(other.currentState)) {
            diff |= CHANGED_CURRENT_STATE;
        }
        return diff;
@@ -126,13 +127,13 @@ public final class DeviceStateInfo implements Parcelable {

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(supportedStates.length);
        for (int i = 0; i < supportedStates.length; i++) {
            dest.writeInt(supportedStates[i]);
        dest.writeInt(supportedStates.size());
        for (int i = 0; i < supportedStates.size(); i++) {
            dest.writeTypedObject(supportedStates.get(i).getConfiguration(), flags);
        }

        dest.writeInt(baseState);
        dest.writeInt(currentState);
        dest.writeTypedObject(baseState.getConfiguration(), flags);
        dest.writeTypedObject(currentState.getConfiguration(), flags);
    }

    @Override
@@ -140,16 +141,21 @@ public final class DeviceStateInfo implements Parcelable {
        return 0;
    }

    public static final @NonNull Creator<DeviceStateInfo> CREATOR = new Creator<DeviceStateInfo>() {
    public static final @NonNull Creator<DeviceStateInfo> CREATOR = new Creator<>() {
        @Override
        public DeviceStateInfo createFromParcel(Parcel source) {
            final int numberOfSupportedStates = source.readInt();
            final int[] supportedStates = new int[numberOfSupportedStates];
            final ArrayList<DeviceState> supportedStates = new ArrayList<>(numberOfSupportedStates);
            for (int i = 0; i < numberOfSupportedStates; i++) {
                supportedStates[i] = source.readInt();
                DeviceState.Configuration configuration = source.readTypedObject(
                        DeviceState.Configuration.CREATOR);
                supportedStates.add(i, new DeviceState(configuration));
            }
            final int baseState = source.readInt();
            final int currentState = source.readInt();

            final DeviceState baseState = new DeviceState(
                    source.readTypedObject(DeviceState.Configuration.CREATOR));
            final DeviceState currentState = new DeviceState(
                    source.readTypedObject(DeviceState.Configuration.CREATOR));

            return new DeviceStateInfo(supportedStates, baseState, currentState);
        }
+27 −68
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package android.hardware.devicestate;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.app.ActivityThread;
import android.content.Context;
import android.hardware.devicestate.DeviceStateManager.DeviceStateCallback;
import android.os.Binder;
@@ -33,13 +32,9 @@ import android.util.ArrayMap;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting.Visibility;
import com.android.internal.util.ArrayUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Executor;

/**
@@ -55,18 +50,12 @@ public final class DeviceStateManagerGlobal {
    private static final String TAG = "DeviceStateManagerGlobal";
    private static final boolean DEBUG = Build.IS_DEBUGGABLE;

    // TODO(b/325124054): Remove when system server refactor is completed
    private static int[] sFoldedDeviceStates = new int[0];

    /**
     * Returns an instance of {@link DeviceStateManagerGlobal}. May return {@code null} if a
     * connection with the device state service couldn't be established.
     */
    @Nullable
    public static DeviceStateManagerGlobal getInstance() {
        // TODO(b/325124054): Remove when system server refactor is completed
        instantiateFoldedStateArray();

        synchronized (DeviceStateManagerGlobal.class) {
            if (sInstance == null) {
                IBinder b = ServiceManager.getService(Context.DEVICE_STATE_SERVICE);
@@ -79,16 +68,6 @@ public final class DeviceStateManagerGlobal {
        }
    }

    // TODO(b/325124054): Remove when system server refactor is completed
    // TODO(b/325330654): Investigate if we need a Context passed in to DSMGlobal
    private static void instantiateFoldedStateArray() {
        Context context = ActivityThread.currentApplication();
        if (context != null) {
            sFoldedDeviceStates = context.getResources().getIntArray(
                    com.android.internal.R.array.config_foldedDeviceStates);
        }
    }

    private final Object mLock = new Object();
    @NonNull
    private final IDeviceStateManager mDeviceStateManager;
@@ -115,6 +94,7 @@ public final class DeviceStateManagerGlobal {
     *
     * @see DeviceStateManager#getSupportedStates()
     */
    // TODO(b/325124054): Remove unused methods when clients are migrated.
    public int[] getSupportedStates() {
        synchronized (mLock) {
            final DeviceStateInfo currentInfo;
@@ -132,12 +112,12 @@ public final class DeviceStateManagerGlobal {
                }
            }

            return Arrays.copyOf(currentInfo.supportedStates, currentInfo.supportedStates.length);
            return getSupportedStateIdentifiersLocked(currentInfo.supportedStates);
        }
    }

    /**
     * Returns the {@link List} of supported device states.
     * Returns {@link List} of supported {@link DeviceState}s.
     *
     * @see DeviceStateManager#getSupportedDeviceStates()
     */
@@ -158,7 +138,7 @@ public final class DeviceStateManagerGlobal {
                }
            }

            return createDeviceStateList(currentInfo.supportedStates);
            return List.copyOf(currentInfo.supportedStates);
        }
    }

@@ -285,13 +265,14 @@ public final class DeviceStateManagerGlobal {

            if (mLastReceivedInfo != null) {
                // Copy the array to prevent the callback from modifying the internal state.
                final int[] supportedStates = Arrays.copyOf(mLastReceivedInfo.supportedStates,
                        mLastReceivedInfo.supportedStates.length);
                final int[] supportedStates = getSupportedStateIdentifiersLocked(
                        mLastReceivedInfo.supportedStates);
                wrapper.notifySupportedStatesChanged(supportedStates);
                wrapper.notifySupportedDeviceStatesChanged(createDeviceStateList(supportedStates));
                wrapper.notifyBaseStateChanged(mLastReceivedInfo.baseState);
                wrapper.notifyStateChanged(mLastReceivedInfo.currentState);
                wrapper.notifyDeviceStateChanged(createDeviceState(mLastReceivedInfo.currentState));
                wrapper.notifySupportedDeviceStatesChanged(
                        List.copyOf(mLastReceivedInfo.supportedStates));
                wrapper.notifyBaseStateChanged(mLastReceivedInfo.baseState.getIdentifier());
                wrapper.notifyStateChanged(mLastReceivedInfo.currentState.getIdentifier());
                wrapper.notifyDeviceStateChanged(mLastReceivedInfo.currentState);
            }
        }
    }
@@ -349,6 +330,15 @@ public final class DeviceStateManagerGlobal {
        return -1;
    }

    @GuardedBy("mLock")
    private int[] getSupportedStateIdentifiersLocked(List<DeviceState> states) {
        int[] identifiers = new int[states.size()];
        for (int i = 0; i < states.size(); i++) {
            identifiers[i] = states.get(i).getIdentifier();
        }
        return identifiers;
    }

    @Nullable
    private IBinder findRequestTokenLocked(@NonNull DeviceStateRequest request) {
        for (int i = 0; i < mRequests.size(); i++) {
@@ -363,32 +353,31 @@ public final class DeviceStateManagerGlobal {
    private void handleDeviceStateInfoChanged(@NonNull DeviceStateInfo info) {
        ArrayList<DeviceStateCallbackWrapper> callbacks;
        DeviceStateInfo oldInfo;
        int[] supportedStateIdentifiers;
        synchronized (mLock) {
            oldInfo = mLastReceivedInfo;
            mLastReceivedInfo = info;
            callbacks = new ArrayList<>(mCallbacks);
            supportedStateIdentifiers = getSupportedStateIdentifiersLocked(info.supportedStates);
        }

        final int diff = oldInfo == null ? ~0 : info.diff(oldInfo);
        if ((diff & DeviceStateInfo.CHANGED_SUPPORTED_STATES) > 0) {
            for (int i = 0; i < callbacks.size(); i++) {
                // Copy the array to prevent callbacks from modifying the internal state.
                final int[] supportedStates = Arrays.copyOf(info.supportedStates,
                        info.supportedStates.length);
                callbacks.get(i).notifySupportedStatesChanged(supportedStates);
                callbacks.get(i).notifySupportedDeviceStatesChanged(
                        createDeviceStateList(supportedStates));
                        List.copyOf(info.supportedStates));
                callbacks.get(i).notifySupportedStatesChanged(supportedStateIdentifiers);
            }
        }
        if ((diff & DeviceStateInfo.CHANGED_BASE_STATE) > 0) {
            for (int i = 0; i < callbacks.size(); i++) {
                callbacks.get(i).notifyBaseStateChanged(info.baseState);
                callbacks.get(i).notifyBaseStateChanged(info.baseState.getIdentifier());
            }
        }
        if ((diff & DeviceStateInfo.CHANGED_CURRENT_STATE) > 0) {
            for (int i = 0; i < callbacks.size(); i++) {
                callbacks.get(i).notifyStateChanged(info.currentState);
                callbacks.get(i).notifyDeviceStateChanged(createDeviceState(info.currentState));
                callbacks.get(i).notifyDeviceStateChanged(info.currentState);
                callbacks.get(i).notifyStateChanged(info.currentState.getIdentifier());
            }
        }
    }
@@ -421,36 +410,6 @@ public final class DeviceStateManagerGlobal {
        }
    }

    /**
     * Creates a {@link DeviceState} object from a device state identifier, with the
     * {@link DeviceState} property that corresponds to what display is primary.
     *
     */
    // TODO(b/325124054): Remove when system server refactor is completed
    @NonNull
    private DeviceState createDeviceState(int stateIdentifier) {
        final Set<@DeviceState.DeviceStateProperties Integer> properties = new HashSet<>();
        if (ArrayUtils.contains(sFoldedDeviceStates, stateIdentifier)) {
            properties.add(DeviceState.PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY);
        } else {
            properties.add(DeviceState.PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY);
        }
        return new DeviceState(stateIdentifier, "" /* name */, properties);
    }

    /**
     * Creates a list of {@link DeviceState} objects from an array of state identifiers.
     */
    // TODO(b/325124054): Remove when system server refactor is completed
    @NonNull
    private List<DeviceState> createDeviceStateList(int[] supportedStates) {
        List<DeviceState> deviceStateList = new ArrayList<>();
        for (int i = 0; i < supportedStates.length; i++) {
            deviceStateList.add(createDeviceState(supportedStates[i]));
        }
        return deviceStateList;
    }

    private final class DeviceStateManagerCallback extends IDeviceStateManagerCallback.Stub {
        @Override
        public void onDeviceStateInfoChanged(DeviceStateInfo info) {
+45 −22
Original line number Diff line number Diff line
@@ -20,16 +20,20 @@ import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;

import android.os.Parcel;

import androidx.test.filters.SmallTest;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.util.List;

/**
 * Unit tests for {@link DeviceStateInfo}.
 * <p/>
@@ -38,11 +42,20 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
@SmallTest
public final class DeviceStateInfoTest {

    private static final DeviceState DEVICE_STATE_0 = new DeviceState(
            new DeviceState.Configuration.Builder(0, "STATE_0").build());
    private static final DeviceState DEVICE_STATE_1 = new DeviceState(
            new DeviceState.Configuration.Builder(1, "STATE_1").build());
    private static final DeviceState DEVICE_STATE_2 = new DeviceState(
            new DeviceState.Configuration.Builder(2, "STATE_2").build());

    @Test
    public void create() {
        final int[] supportedStates = new int[] { 0, 1, 2 };
        final int baseState = 0;
        final int currentState = 2;
        final List<DeviceState> supportedStates = List.of(DEVICE_STATE_0, DEVICE_STATE_1,
                DEVICE_STATE_2);
        final DeviceState baseState = DEVICE_STATE_0;
        final DeviceState currentState = DEVICE_STATE_2;

        final DeviceStateInfo info = new DeviceStateInfo(supportedStates, baseState, currentState);
        assertNotNull(info.supportedStates);
@@ -53,27 +66,30 @@ public final class DeviceStateInfoTest {

    @Test
    public void equals() {
        final int[] supportedStates = new int[] { 0, 1, 2 };
        final int baseState = 0;
        final int currentState = 2;
        final List<DeviceState> supportedStates = List.of(DEVICE_STATE_0, DEVICE_STATE_1,
                DEVICE_STATE_2);
        final DeviceState baseState = DEVICE_STATE_0;
        final DeviceState currentState = DEVICE_STATE_2;

        final DeviceStateInfo info = new DeviceStateInfo(supportedStates, baseState, currentState);
        assertTrue(info.equals(info));
        Assert.assertEquals(info, info);

        final DeviceStateInfo sameInfo = new DeviceStateInfo(supportedStates, baseState,
                currentState);
        assertTrue(info.equals(sameInfo));
        Assert.assertEquals(info, sameInfo);

        final DeviceStateInfo differentInfo = new DeviceStateInfo(new int[]{ 0, 2}, baseState,
        final DeviceStateInfo differentInfo = new DeviceStateInfo(
                List.of(DEVICE_STATE_0, DEVICE_STATE_2), baseState,
                currentState);
        assertFalse(info.equals(differentInfo));
        assertNotEquals(info, differentInfo);
    }

    @Test
    public void diff_sameObject() {
        final int[] supportedStates = new int[] { 0, 1, 2 };
        final int baseState = 0;
        final int currentState = 2;
        final List<DeviceState> supportedStates = List.of(DEVICE_STATE_0, DEVICE_STATE_1,
                DEVICE_STATE_2);
        final DeviceState baseState = DEVICE_STATE_0;
        final DeviceState currentState = DEVICE_STATE_2;

        final DeviceStateInfo info = new DeviceStateInfo(supportedStates, baseState, currentState);
        assertEquals(0, info.diff(info));
@@ -81,8 +97,10 @@ public final class DeviceStateInfoTest {

    @Test
    public void diff_differentSupportedStates() {
        final DeviceStateInfo info = new DeviceStateInfo(new int[] { 1 }, 0, 0);
        final DeviceStateInfo otherInfo = new DeviceStateInfo(new int[] { 2 }, 0, 0);
        final DeviceStateInfo info = new DeviceStateInfo(List.of(DEVICE_STATE_1), DEVICE_STATE_0,
                DEVICE_STATE_0);
        final DeviceStateInfo otherInfo = new DeviceStateInfo(List.of(DEVICE_STATE_2),
                DEVICE_STATE_0, DEVICE_STATE_0);
        final int diff = info.diff(otherInfo);
        assertTrue((diff & DeviceStateInfo.CHANGED_SUPPORTED_STATES) > 0);
        assertFalse((diff & DeviceStateInfo.CHANGED_BASE_STATE) > 0);
@@ -91,8 +109,10 @@ public final class DeviceStateInfoTest {

    @Test
    public void diff_differentNonOverrideState() {
        final DeviceStateInfo info = new DeviceStateInfo(new int[] { 1 }, 1, 0);
        final DeviceStateInfo otherInfo = new DeviceStateInfo(new int[] { 1 }, 2, 0);
        final DeviceStateInfo info = new DeviceStateInfo(List.of(DEVICE_STATE_1), DEVICE_STATE_1,
                DEVICE_STATE_0);
        final DeviceStateInfo otherInfo = new DeviceStateInfo(List.of(DEVICE_STATE_1),
                DEVICE_STATE_2, DEVICE_STATE_0);
        final int diff = info.diff(otherInfo);
        assertFalse((diff & DeviceStateInfo.CHANGED_SUPPORTED_STATES) > 0);
        assertTrue((diff & DeviceStateInfo.CHANGED_BASE_STATE) > 0);
@@ -101,8 +121,10 @@ public final class DeviceStateInfoTest {

    @Test
    public void diff_differentState() {
        final DeviceStateInfo info = new DeviceStateInfo(new int[] { 1 }, 0, 1);
        final DeviceStateInfo otherInfo = new DeviceStateInfo(new int[] { 1 }, 0, 2);
        final DeviceStateInfo info = new DeviceStateInfo(List.of(DEVICE_STATE_1), DEVICE_STATE_0,
                DEVICE_STATE_1);
        final DeviceStateInfo otherInfo = new DeviceStateInfo(List.of(DEVICE_STATE_1),
                DEVICE_STATE_0, DEVICE_STATE_2);
        final int diff = info.diff(otherInfo);
        assertFalse((diff & DeviceStateInfo.CHANGED_SUPPORTED_STATES) > 0);
        assertFalse((diff & DeviceStateInfo.CHANGED_BASE_STATE) > 0);
@@ -111,9 +133,10 @@ public final class DeviceStateInfoTest {

    @Test
    public void writeToParcel() {
        final int[] supportedStates = new int[] { 0, 1, 2 };
        final int nonOverrideState = 0;
        final int state = 2;
        final List<DeviceState> supportedStates = List.of(DEVICE_STATE_0, DEVICE_STATE_1,
                DEVICE_STATE_2);
        final DeviceState nonOverrideState = DEVICE_STATE_0;
        final DeviceState state = DEVICE_STATE_2;
        final DeviceStateInfo originalInfo =
                new DeviceStateInfo(supportedStates, nonOverrideState, state);

+60 −57

File changed.

Preview size limit exceeded, changes collapsed.

Loading