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

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

Fix bug by re-reading int from parcel in DeviceState

Bug: 329015609
Bug: 329043261
Test: DeviceStateTest
Test: DeviceStateInfoTest
Change-Id: I8fff1da3e7f0c147f7ebaa4e0c4cd74eba9b2847
parent 6d31e865
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -543,11 +543,13 @@ public final class DeviceState {
                int identifier = source.readInt();
                String name = source.readString8();
                ArraySet<@DeviceStateProperties Integer> systemProperties = new ArraySet<>();
                for (int i = 0; i < source.readInt(); i++) {
                int systemPropertySize = source.readInt();
                for (int i = 0; i < systemPropertySize; i++) {
                    systemProperties.add(source.readInt());
                }
                ArraySet<@DeviceStateProperties Integer> physicalProperties = new ArraySet<>();
                for (int j = 0; j < source.readInt(); j++) {
                int physicalPropertySize = source.readInt();
                for (int j = 0; j < physicalPropertySize; j++) {
                    physicalProperties.add(source.readInt());
                }
                return new DeviceState.Configuration(identifier, name, systemProperties,
+24 −3
Original line number Diff line number Diff line
@@ -16,6 +16,12 @@

package android.hardware.devicestate;

import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY;
import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY;
import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_CLOSED;
import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_HALF_OPEN;
import static android.hardware.devicestate.DeviceState.PROPERTY_POLICY_CANCEL_OVERRIDE_REQUESTS;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;

@@ -33,6 +39,7 @@ import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

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

/**
 * Unit tests for {@link DeviceStateInfo}.
@@ -44,11 +51,25 @@ import java.util.List;
public final class DeviceStateInfoTest {

    private static final DeviceState DEVICE_STATE_0 = new DeviceState(
            new DeviceState.Configuration.Builder(0, "STATE_0").build());
            new DeviceState.Configuration.Builder(0, "STATE_0")
                    .setSystemProperties(
                            Set.of(PROPERTY_POLICY_CANCEL_OVERRIDE_REQUESTS,
                                    PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY))
                    .setPhysicalProperties(
                            Set.of(PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_CLOSED))
                    .build());
    private static final DeviceState DEVICE_STATE_1 = new DeviceState(
            new DeviceState.Configuration.Builder(1, "STATE_1").build());
            new DeviceState.Configuration.Builder(1, "STATE_1")
                    .setSystemProperties(
                            Set.of(PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY))
                    .setPhysicalProperties(
                            Set.of(PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_HALF_OPEN))
                    .build());
    private static final DeviceState DEVICE_STATE_2 = new DeviceState(
            new DeviceState.Configuration.Builder(2, "STATE_2").build());
            new DeviceState.Configuration.Builder(2, "STATE_2")
                    .setSystemProperties(
                            Set.of(PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY))
                    .build());

    @Test
    public void create() {
+18 −0
Original line number Diff line number Diff line
@@ -93,4 +93,22 @@ public final class DeviceStateTest {

        Assert.assertEquals(originalState, new DeviceState(stateConfiguration));
    }

    @Test
    public void writeToParcel_noPhysicalProperties() {
        final DeviceState originalState = new DeviceState(
                new DeviceState.Configuration.Builder(0, "TEST_STATE")
                        .setSystemProperties(Set.of(PROPERTY_POLICY_CANCEL_OVERRIDE_REQUESTS,
                                PROPERTY_POLICY_AVAILABLE_FOR_APP_REQUEST))
                        .build());

        final Parcel parcel = Parcel.obtain();
        originalState.getConfiguration().writeToParcel(parcel, 0 /* flags */);
        parcel.setDataPosition(0);

        final DeviceState.Configuration stateConfiguration =
                DeviceState.Configuration.CREATOR.createFromParcel(parcel);

        Assert.assertEquals(originalState, new DeviceState(stateConfiguration));
    }
}