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

Commit 6526e0e0 authored by Kenneth Ford's avatar Kenneth Ford Committed by Android Build Coastguard Worker
Browse files

Revert "Pass DeviceState objects from DeviceStateManagerService to the client"

This reverts commit aec75f67.

Reason for revert: Possible failure for Felix face-auth b/329015609
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:4618b4e4f089446bc35259468a191d2496f6a6e0)
Merged-In: Ib3a9fd5b517a279e4b0e245c78a306db803381dd
Change-Id: Ib3a9fd5b517a279e4b0e245c78a306db803381dd
parent 0672c615
Loading
Loading
Loading
Loading
+12 −61
Original line number Diff line number Diff line
@@ -25,9 +25,6 @@ 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;
@@ -38,7 +35,8 @@ import java.util.Objects;
import java.util.Set;

/**
 * A state of the device managed by {@link DeviceStateManager}.
 * A state of the device defined by the {@link DeviceStateProvider} and managed by the
 * {@link DeviceStateManagerService}.
 * <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
@@ -300,14 +298,13 @@ public final class DeviceState {
    public @interface SystemDeviceStateProperties {}

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

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

        /** {@link ArraySet} of physical device properties that apply to this state. */
        /** {@link Set} of physical device properties that apply to this state. */
        @NonNull
        private final ArraySet<@PhysicalDeviceStateProperties Integer> mPhysicalProperties;
        private final Set<@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 = new ArraySet<@SystemDeviceStateProperties Integer>(
                    systemProperties);
            mPhysicalProperties = new ArraySet<@PhysicalDeviceStateProperties Integer>(
                    physicalProperties);
            mSystemProperties = systemProperties;
            mPhysicalProperties = physicalProperties;
        }

        /** Returns the unique identifier for the device state. */
@@ -515,51 +511,6 @@ 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;
+25 −31
Original line number Diff line number Diff line
@@ -24,8 +24,7 @@ import android.os.Parcelable;

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

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

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

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

    @Override
@@ -97,15 +96,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.equals(that.baseState)
                &&  currentState.equals(that.currentState)
                && Objects.equals(supportedStates, that.supportedStates);
        return baseState == that.baseState
                &&  currentState == that.currentState
                && Arrays.equals(supportedStates, that.supportedStates);
    }

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

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

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

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

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

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

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

            return new DeviceStateInfo(supportedStates, baseState, currentState);
        }
+68 −27
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ 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;
@@ -32,9 +33,13 @@ 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;

/**
@@ -50,12 +55,18 @@ 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);
@@ -68,6 +79,16 @@ 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;
@@ -94,7 +115,6 @@ 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;
@@ -112,12 +132,12 @@ public final class DeviceStateManagerGlobal {
                }
            }

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

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

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

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

            if (mLastReceivedInfo != null) {
                // Copy the array to prevent the callback from modifying the internal state.
                final int[] supportedStates = getSupportedStateIdentifiersLocked(
                        mLastReceivedInfo.supportedStates);
                final int[] supportedStates = Arrays.copyOf(mLastReceivedInfo.supportedStates,
                        mLastReceivedInfo.supportedStates.length);
                wrapper.notifySupportedStatesChanged(supportedStates);
                wrapper.notifySupportedDeviceStatesChanged(
                        List.copyOf(mLastReceivedInfo.supportedStates));
                wrapper.notifyBaseStateChanged(mLastReceivedInfo.baseState.getIdentifier());
                wrapper.notifyStateChanged(mLastReceivedInfo.currentState.getIdentifier());
                wrapper.notifyDeviceStateChanged(mLastReceivedInfo.currentState);
                wrapper.notifySupportedDeviceStatesChanged(createDeviceStateList(supportedStates));
                wrapper.notifyBaseStateChanged(mLastReceivedInfo.baseState);
                wrapper.notifyStateChanged(mLastReceivedInfo.currentState);
                wrapper.notifyDeviceStateChanged(createDeviceState(mLastReceivedInfo.currentState));
            }
        }
    }
@@ -330,15 +349,6 @@ 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++) {
@@ -353,31 +363,32 @@ 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(
                        List.copyOf(info.supportedStates));
                callbacks.get(i).notifySupportedStatesChanged(supportedStateIdentifiers);
                        createDeviceStateList(supportedStates));
            }
        }
        if ((diff & DeviceStateInfo.CHANGED_BASE_STATE) > 0) {
            for (int i = 0; i < callbacks.size(); i++) {
                callbacks.get(i).notifyBaseStateChanged(info.baseState.getIdentifier());
                callbacks.get(i).notifyBaseStateChanged(info.baseState);
            }
        }
        if ((diff & DeviceStateInfo.CHANGED_CURRENT_STATE) > 0) {
            for (int i = 0; i < callbacks.size(); i++) {
                callbacks.get(i).notifyDeviceStateChanged(info.currentState);
                callbacks.get(i).notifyStateChanged(info.currentState.getIdentifier());
                callbacks.get(i).notifyStateChanged(info.currentState);
                callbacks.get(i).notifyDeviceStateChanged(createDeviceState(info.currentState));
            }
        }
    }
@@ -410,6 +421,36 @@ 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) {
+22 −45
Original line number Diff line number Diff line
@@ -20,20 +20,16 @@ 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/>
@@ -42,20 +38,11 @@ import java.util.List;
@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 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 int[] supportedStates = new int[] { 0, 1, 2 };
        final int baseState = 0;
        final int currentState = 2;

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

    @Test
    public void equals() {
        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 int[] supportedStates = new int[] { 0, 1, 2 };
        final int baseState = 0;
        final int currentState = 2;

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

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

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

    @Test
    public void diff_sameObject() {
        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 int[] supportedStates = new int[] { 0, 1, 2 };
        final int baseState = 0;
        final int currentState = 2;

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

    @Test
    public void diff_differentSupportedStates() {
        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 DeviceStateInfo info = new DeviceStateInfo(new int[] { 1 }, 0, 0);
        final DeviceStateInfo otherInfo = new DeviceStateInfo(new int[] { 2 }, 0, 0);
        final int diff = info.diff(otherInfo);
        assertTrue((diff & DeviceStateInfo.CHANGED_SUPPORTED_STATES) > 0);
        assertFalse((diff & DeviceStateInfo.CHANGED_BASE_STATE) > 0);
@@ -109,10 +91,8 @@ public final class DeviceStateInfoTest {

    @Test
    public void diff_differentNonOverrideState() {
        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 DeviceStateInfo info = new DeviceStateInfo(new int[] { 1 }, 1, 0);
        final DeviceStateInfo otherInfo = new DeviceStateInfo(new int[] { 1 }, 2, 0);
        final int diff = info.diff(otherInfo);
        assertFalse((diff & DeviceStateInfo.CHANGED_SUPPORTED_STATES) > 0);
        assertTrue((diff & DeviceStateInfo.CHANGED_BASE_STATE) > 0);
@@ -121,10 +101,8 @@ public final class DeviceStateInfoTest {

    @Test
    public void diff_differentState() {
        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 DeviceStateInfo info = new DeviceStateInfo(new int[] { 1 }, 0, 1);
        final DeviceStateInfo otherInfo = new DeviceStateInfo(new int[] { 1 }, 0, 2);
        final int diff = info.diff(otherInfo);
        assertFalse((diff & DeviceStateInfo.CHANGED_SUPPORTED_STATES) > 0);
        assertFalse((diff & DeviceStateInfo.CHANGED_BASE_STATE) > 0);
@@ -133,10 +111,9 @@ public final class DeviceStateInfoTest {

    @Test
    public void writeToParcel() {
        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 int[] supportedStates = new int[] { 0, 1, 2 };
        final int nonOverrideState = 0;
        final int state = 2;
        final DeviceStateInfo originalInfo =
                new DeviceStateInfo(supportedStates, nonOverrideState, state);

+57 −60

File changed.

Preview size limit exceeded, changes collapsed.

Loading