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

Commit 7c025dd1 authored by Kenneth Ford's avatar Kenneth Ford
Browse files

Re-adds flags for device state manager configuration

Re-adds the ability to process flags in the configuration
files for device state manager. This will allow the aosp
image to be compatible with previous vendor images.

Devices should still be updated to use the updated property
values for their device state configuration, but devices without
an updated vendor image would fail without this change.

Flag: android.hardware.devicestate.feature.flags.device_state_configuration_flag
Bug: 388366842
Test: DeviceStateProviderImplTest
Change-Id: Iafe2a76418173baaf116fdc0e47cc7726f77287f
parent 65644e69
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -39,3 +39,15 @@ flag {
    bug: "372486634"
    is_fixed_read_only: true
}

flag {
    name: "device_state_configuration_flag"
    is_exported: true
    namespace: "windowing_sdk"
    description: "Re-add flag parsing for device_state_configuration.xml configuration for devices that didn't update vendor images."
    bug: "388366842"
    is_fixed_read_only: true
    metadata {
      purpose: PURPOSE_BUGFIX
    }
}
+56 −4
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import com.android.server.devicestate.DeviceStateProvider;
import com.android.server.input.InputManagerInternal;
import com.android.server.policy.devicestate.config.Conditions;
import com.android.server.policy.devicestate.config.DeviceStateConfig;
import com.android.server.policy.devicestate.config.Flags;
import com.android.server.policy.devicestate.config.LidSwitchCondition;
import com.android.server.policy.devicestate.config.NumericRange;
import com.android.server.policy.devicestate.config.Properties;
@@ -140,7 +141,16 @@ public final class DeviceStateProviderImpl implements DeviceStateProvider,
    private static final String PROPERTY_FEATURE_REAR_DISPLAY_OUTER_DEFAULT =
            "com.android.server.policy.PROPERTY_FEATURE_REAR_DISPLAY_OUTER_DEFAULT";


    // Deprecated flag definitions to maintain backwards compatibility.
    private static final String FLAG_CANCEL_OVERRIDE_REQUESTS = "FLAG_CANCEL_OVERRIDE_REQUESTS";
    private static final String FLAG_APP_INACCESSIBLE = "FLAG_APP_INACCESSIBLE";
    private static final String FLAG_EMULATED_ONLY = "FLAG_EMULATED_ONLY";
    private static final String FLAG_CANCEL_WHEN_REQUESTER_NOT_ON_TOP =
            "FLAG_CANCEL_WHEN_REQUESTER_NOT_ON_TOP";
    private static final String FLAG_UNSUPPORTED_WHEN_THERMAL_STATUS_CRITICAL =
            "FLAG_UNSUPPORTED_WHEN_THERMAL_STATUS_CRITICAL";
    private static final String FLAG_UNSUPPORTED_WHEN_POWER_SAVE_MODE =
            "FLAG_UNSUPPORTED_WHEN_POWER_SAVE_MODE";

    /** Interface that allows reading the device state configuration. */
    interface ReadableConfig {
@@ -185,15 +195,29 @@ public final class DeviceStateProviderImpl implements DeviceStateProvider,
                            new HashSet<>();
                    Set<@DeviceState.DeviceStateProperties Integer> physicalProperties =
                            new HashSet<>();
                    final Properties configFlags = stateConfig.getProperties();
                    if (configFlags != null) {
                        List<String> configPropertyStrings = configFlags.getProperty();
                    final Properties configProperties = stateConfig.getProperties();
                    if (configProperties != null) {
                        List<String> configPropertyStrings = configProperties.getProperty();
                        for (int i = 0; i < configPropertyStrings.size(); i++) {
                            final String configPropertyString = configPropertyStrings.get(i);
                            addPropertyByString(configPropertyString, systemProperties,
                                    physicalProperties);
                        }
                    }

                    if (android.hardware.devicestate.feature.flags
                            .Flags.deviceStateConfigurationFlag()) {
                        // Parse through the deprecated flag configuration to keep compatibility.
                        final Flags configFlags = stateConfig.getFlags();
                        if (configFlags != null) {
                            List<String> configFlagStrings = configFlags.getFlag();
                            for (int i = 0; i < configFlagStrings.size(); i++) {
                                final String configFlagString = configFlagStrings.get(i);
                                addFlagByString(configFlagString, systemProperties);
                            }
                        }
                    }

                    DeviceState.Configuration deviceStateConfiguration =
                            new DeviceState.Configuration.Builder(state, name)
                                    .setSystemProperties(systemProperties)
@@ -292,6 +316,34 @@ public final class DeviceStateProviderImpl implements DeviceStateProvider,
        }
    }

    private static void addFlagByString(String flagString,
            Set<@DeviceState.SystemDeviceStateProperties Integer> systemProperties) {
        switch (flagString) {
            case FLAG_APP_INACCESSIBLE:
                systemProperties.add(DeviceState.PROPERTY_APP_INACCESSIBLE);
                break;
            case FLAG_EMULATED_ONLY:
                systemProperties.add(DeviceState.PROPERTY_EMULATED_ONLY);
                break;
            case FLAG_CANCEL_OVERRIDE_REQUESTS:
                systemProperties.add(DeviceState.PROPERTY_POLICY_CANCEL_OVERRIDE_REQUESTS);
                break;
            case FLAG_CANCEL_WHEN_REQUESTER_NOT_ON_TOP:
                systemProperties.add(DeviceState.PROPERTY_POLICY_CANCEL_WHEN_REQUESTER_NOT_ON_TOP);
                break;
            case FLAG_UNSUPPORTED_WHEN_POWER_SAVE_MODE:
                systemProperties.add(DeviceState.PROPERTY_POLICY_UNSUPPORTED_WHEN_POWER_SAVE_MODE);
                break;
            case FLAG_UNSUPPORTED_WHEN_THERMAL_STATUS_CRITICAL:
                systemProperties.add(
                        DeviceState.PROPERTY_POLICY_UNSUPPORTED_WHEN_THERMAL_STATUS_CRITICAL);
                break;
            default:
                Slog.w(TAG, "Parsed unknown flag with name: " + flagString);
                break;
        }
    }

    // Lock for internal state.
    private final Object mLock = new Object();
    private final Context mContext;
+9 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@
                <xs:annotation name="nullable" />
            </xs:element>
            <xs:element name="properties" type="properties" />
            <xs:element name="flags" type="flags" />
            <xs:element name="conditions" type="conditions" />
        </xs:sequence>
    </xs:complexType>
@@ -53,6 +54,14 @@
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="flags">
        <xs:sequence>
            <xs:element name="flag" type="xs:string" minOccurs="0" maxOccurs="unbounded">
                <xs:annotation name="nullable" />
            </xs:element>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="conditions">
        <xs:sequence>
            <xs:element name="lid-switch" type="lidSwitchCondition" minOccurs="0">
+7 −0
Original line number Diff line number Diff line
@@ -11,10 +11,12 @@ package com.android.server.policy.devicestate.config {
  public class DeviceState {
    ctor public DeviceState();
    method public com.android.server.policy.devicestate.config.Conditions getConditions();
    method public com.android.server.policy.devicestate.config.Flags getFlags();
    method public java.math.BigInteger getIdentifier();
    method @Nullable public String getName();
    method public com.android.server.policy.devicestate.config.Properties getProperties();
    method public void setConditions(com.android.server.policy.devicestate.config.Conditions);
    method public void setFlags(com.android.server.policy.devicestate.config.Flags);
    method public void setIdentifier(java.math.BigInteger);
    method public void setName(@Nullable String);
    method public void setProperties(com.android.server.policy.devicestate.config.Properties);
@@ -25,6 +27,11 @@ package com.android.server.policy.devicestate.config {
    method public java.util.List<com.android.server.policy.devicestate.config.DeviceState> getDeviceState();
  }

  public class Flags {
    ctor public Flags();
    method @Nullable public java.util.List<java.lang.String> getFlag();
  }

  public class LidSwitchCondition {
    ctor public LidSwitchCondition();
    method public boolean getOpen();
+40 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.server.policy;


import static android.content.Context.SENSOR_SERVICE;
import static android.hardware.devicestate.feature.flags.Flags.FLAG_DEVICE_STATE_CONFIGURATION_FLAG;

import static com.android.server.devicestate.DeviceStateProvider.SUPPORTED_DEVICE_STATES_CHANGED_INITIALIZED;
import static com.android.server.devicestate.DeviceStateProvider.SUPPORTED_DEVICE_STATES_CHANGED_POWER_SAVE_DISABLED;
@@ -42,6 +43,9 @@ import android.hardware.SensorEvent;
import android.hardware.SensorManager;
import android.hardware.devicestate.DeviceState;
import android.os.PowerManager;
import android.platform.test.annotations.RequiresFlagsEnabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;

import androidx.annotation.NonNull;

@@ -51,6 +55,7 @@ import com.android.server.input.InputManagerInternal;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
@@ -84,6 +89,10 @@ public final class DeviceStateProviderImplTest {
    private Context mContext;
    private SensorManager mSensorManager;

    @Rule
    public final CheckFlagsRule mCheckFlagsRule =
            DeviceFlagsValueProvider.createCheckFlagsRule();

    @Before
    public void setup() {
        LocalServices.addService(InputManagerInternal.class, mock(InputManagerInternal.class));
@@ -605,6 +614,37 @@ public final class DeviceStateProviderImplTest {
        verify(listener, never()).onStateChanged(mIntegerCaptor.capture());
    }

    @RequiresFlagsEnabled(FLAG_DEVICE_STATE_CONFIGURATION_FLAG)
    @Test
    public void test_createConfigWithFlags() {
        String configString = "<device-state-config>\n"
                + "    <device-state>\n"
                + "        <identifier>1</identifier>\n"
                + "        <flags>\n"
                + "            <flag>FLAG_CANCEL_OVERRIDE_REQUESTS</flag>\n"
                + "        </flags>\n"
                + "    </device-state>\n"
                + "    <device-state>\n"
                + "        <identifier>2</identifier>\n"
                + "        <name>CLOSED</name>\n"
                + "    </device-state>\n"
                + "</device-state-config>\n";
        DeviceStateProviderImpl.ReadableConfig config = new TestReadableConfig(configString);
        DeviceStateProviderImpl provider = DeviceStateProviderImpl.createFromConfig(mContext,
                config);

        DeviceStateProvider.Listener listener = mock(DeviceStateProvider.Listener.class);
        provider.setListener(listener);

        verify(listener).onSupportedDeviceStatesChanged(mDeviceStateArrayCaptor.capture(),
                eq(SUPPORTED_DEVICE_STATES_CHANGED_INITIALIZED));
        final DeviceState[] expectedStates = new DeviceState[]{
                createDeviceState(1, "",
                        Set.of(DeviceState.PROPERTY_POLICY_CANCEL_OVERRIDE_REQUESTS)),
                createDeviceState(2, "CLOSED", EMPTY_PROPERTY_SET)};
        assertArrayEquals(expectedStates, mDeviceStateArrayCaptor.getValue());
    }

    private DeviceState createDeviceState(int identifier, @NonNull String name,
            @NonNull Set<@DeviceState.DeviceStateProperties Integer> systemProperties) {
        DeviceState.Configuration configuration = new DeviceState.Configuration.Builder(identifier,