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

Commit 0f65a72e authored by Kenneth Ford's avatar Kenneth Ford Committed by Android (Google) Code Review
Browse files

Merge "Passes in more specific types to DeviceState and DeviceStateInfo" into main

parents c3bab320 c9f0cbbf
Loading
Loading
Loading
Loading
+6 −8
Original line number Diff line number Diff line
@@ -333,14 +333,12 @@ public final class DeviceState {
        private final ArraySet<@PhysicalDeviceStateProperties Integer> mPhysicalProperties;

        private Configuration(int identifier, @NonNull String name,
                @NonNull Set<@SystemDeviceStateProperties Integer> systemProperties,
                @NonNull Set<@PhysicalDeviceStateProperties Integer> physicalProperties) {
                @NonNull ArraySet<@SystemDeviceStateProperties Integer> systemProperties,
                @NonNull ArraySet<@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. */
@@ -479,8 +477,8 @@ public final class DeviceState {
             */
            @NonNull
            public DeviceState.Configuration build() {
                return new DeviceState.Configuration(mIdentifier, mName, mSystemProperties,
                        mPhysicalProperties);
                return new DeviceState.Configuration(mIdentifier, mName,
                        new ArraySet<>(mSystemProperties), new ArraySet<>(mPhysicalProperties));
            }
        }
    }
+6 −5
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ 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.Objects;
import java.util.concurrent.Executor;

@@ -77,9 +76,11 @@ 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,
    // Using the specific types to avoid virtual method calls in binder transactions
    @SuppressWarnings("NonApiType")
    public DeviceStateInfo(@NonNull ArrayList<DeviceState> supportedStates, DeviceState baseState,
            DeviceState state) {
        this.supportedStates = new ArrayList<>(supportedStates);
        this.supportedStates = supportedStates;
        this.baseState = baseState;
        this.currentState = state;
    }
@@ -89,13 +90,13 @@ 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(new ArrayList<>(info.supportedStates), info.baseState, info.currentState);
    }

    @Override
    public boolean equals(@Nullable Object other) {
        if (this == other) return true;
        if (other == null || getClass() != other.getClass()) return false;
        if (other == null || (getClass() != other.getClass())) return false;
        DeviceStateInfo that = (DeviceStateInfo) other;
        return baseState.equals(that.baseState)
                &&  currentState.equals(that.currentState)
+21 −21
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

@@ -73,8 +74,8 @@ public final class DeviceStateInfoTest {

    @Test
    public void create() {
        final List<DeviceState> supportedStates = List.of(DEVICE_STATE_0, DEVICE_STATE_1,
                DEVICE_STATE_2);
        final ArrayList<DeviceState> supportedStates = new ArrayList<>(
                List.of(DEVICE_STATE_0, DEVICE_STATE_1, DEVICE_STATE_2));
        final DeviceState baseState = DEVICE_STATE_0;
        final DeviceState currentState = DEVICE_STATE_2;

@@ -87,8 +88,8 @@ public final class DeviceStateInfoTest {

    @Test
    public void equals() {
        final List<DeviceState> supportedStates = List.of(DEVICE_STATE_0, DEVICE_STATE_1,
                DEVICE_STATE_2);
        final ArrayList<DeviceState> supportedStates = new ArrayList<>(
                List.of(DEVICE_STATE_0, DEVICE_STATE_1, DEVICE_STATE_2));
        final DeviceState baseState = DEVICE_STATE_0;
        final DeviceState currentState = DEVICE_STATE_2;

@@ -100,15 +101,14 @@ public final class DeviceStateInfoTest {
        Assert.assertEquals(info, sameInfo);

        final DeviceStateInfo differentInfo = new DeviceStateInfo(
                List.of(DEVICE_STATE_0, DEVICE_STATE_2), baseState,
                currentState);
                new ArrayList<>(List.of(DEVICE_STATE_0, DEVICE_STATE_2)), baseState, currentState);
        assertNotEquals(info, differentInfo);
    }

    @Test
    public void diff_sameObject() {
        final List<DeviceState> supportedStates = List.of(DEVICE_STATE_0, DEVICE_STATE_1,
                DEVICE_STATE_2);
        final ArrayList<DeviceState> supportedStates = new ArrayList<>(
                List.of(DEVICE_STATE_0, DEVICE_STATE_1, DEVICE_STATE_2));
        final DeviceState baseState = DEVICE_STATE_0;
        final DeviceState currentState = DEVICE_STATE_2;

@@ -118,10 +118,10 @@ 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),
        final DeviceStateInfo info = new DeviceStateInfo(new ArrayList<>(List.of(DEVICE_STATE_1)),
                DEVICE_STATE_0, DEVICE_STATE_0);
        final DeviceStateInfo otherInfo = new DeviceStateInfo(
                new ArrayList<>(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);
@@ -130,10 +130,10 @@ 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 ArrayList<>(List.of(DEVICE_STATE_1)),
                DEVICE_STATE_1, DEVICE_STATE_0);
        final DeviceStateInfo otherInfo = new DeviceStateInfo(
                new ArrayList<>(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);
@@ -142,10 +142,10 @@ 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 ArrayList<>(List.of(DEVICE_STATE_1)),
                DEVICE_STATE_0, DEVICE_STATE_1);
        final DeviceStateInfo otherInfo = new DeviceStateInfo(
                new ArrayList<>(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);
@@ -154,8 +154,8 @@ public final class DeviceStateInfoTest {

    @Test
    public void writeToParcel() {
        final List<DeviceState> supportedStates = List.of(DEVICE_STATE_0, DEVICE_STATE_1,
                DEVICE_STATE_2);
        final ArrayList<DeviceState> supportedStates = new ArrayList<>(
                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 =
+2 −1
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -276,7 +277,7 @@ public final class DeviceStateManagerGlobalTest {
                    new DeviceState.Configuration.Builder(mergedBaseState, "" /* name */).build());
            final DeviceState state = new DeviceState(
                    new DeviceState.Configuration.Builder(mergedState, "" /* name */).build());
            return new DeviceStateInfo(mSupportedDeviceStates, baseState, state);
            return new DeviceStateInfo(new ArrayList<>(mSupportedDeviceStates), baseState, state);
        }

        private void notifyDeviceStateInfoChanged() {
+1 −1
Original line number Diff line number Diff line
@@ -399,7 +399,7 @@ public final class DeviceStateManagerService extends SystemService {
        final DeviceState baseState = mBaseState.orElse(INVALID_DEVICE_STATE);
        final DeviceState currentState = mCommittedState.orElse(INVALID_DEVICE_STATE);

        return new DeviceStateInfo(supportedStates, baseState,
        return new DeviceStateInfo(new ArrayList<>(supportedStates), baseState,
                createMergedDeviceState(currentState, baseState));
    }