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

Commit a7b918c3 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[CEC Configuration] Introduce 'int' type to the API"

parents 0857a642 2c780403
Loading
Loading
Loading
Loading
+50 −21
Original line number Diff line number Diff line
@@ -42,9 +42,11 @@ import com.android.internal.util.ConcurrentUtils;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Executor;
import java.util.stream.Collectors;

/**
 * The {@link HdmiControlManager} class is used to send HDMI control messages
@@ -325,17 +327,17 @@ public final class HdmiControlManager {
     *
     * @hide
     */
    public static final String HDMI_CEC_CONTROL_ENABLED = "1";
    public static final int HDMI_CEC_CONTROL_ENABLED = 1;
    /**
     * HDMI CEC disabled.
     *
     * @hide
     */
    public static final String HDMI_CEC_CONTROL_DISABLED = "0";
    public static final int HDMI_CEC_CONTROL_DISABLED = 0;
    /**
     * @hide
     */
    @StringDef({
    @IntDef({
            HDMI_CEC_CONTROL_ENABLED,
            HDMI_CEC_CONTROL_DISABLED
    })
@@ -401,17 +403,17 @@ public final class HdmiControlManager {
     *
     * @hide
     */
    public static final String SYSTEM_AUDIO_MODE_MUTING_ENABLED = "1";
    public static final int SYSTEM_AUDIO_MODE_MUTING_ENABLED = 1;
    /**
     * System Audio Mode muting disabled.
     *
     * @hide
     */
    public static final String SYSTEM_AUDIO_MODE_MUTING_DISABLED = "0";
    public static final int SYSTEM_AUDIO_MODE_MUTING_DISABLED = 0;
    /**
     * @hide
     */
    @StringDef({
    @IntDef({
            SYSTEM_AUDIO_MODE_MUTING_ENABLED,
            SYSTEM_AUDIO_MODE_MUTING_DISABLED
    })
@@ -1317,24 +1319,51 @@ public final class HdmiControlManager {
    }

    /**
     * Get a set of allowed values for a settings.
     * Get a set of allowed values for a setting (string value-type).
     *
     * @param name name of the setting
     * @return a set of allowed values for a settings. {@code null} on failure.
     * @throws IllegalArgumentException when setting {@code name} does not exist.
     * @throws IllegalArgumentException when setting {@code name} value type is invalid.
     * @throws RuntimeException when the HdmiControlService is not available.
     *
     * @hide
     */
    @NonNull
    @RequiresPermission(android.Manifest.permission.HDMI_CEC)
    public List<String> getAllowedCecSettingStringValues(@NonNull @CecSettingName String name) {
        if (mService == null) {
            Log.e(TAG, "HdmiControlService is not available");
            throw new RuntimeException("HdmiControlService is not available");
        }
        try {
            return mService.getAllowedCecSettingStringValues(name);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Get a set of allowed values for a setting (int value-type).
     *
     * @param name name of the setting
     * @return a set of allowed values for a settings. {@code null} on failure.
     * @throws IllegalArgumentException when setting {@code name} does not exist.
     * @throws IllegalArgumentException when setting {@code name} value type is invalid.
     * @throws RuntimeException when the HdmiControlService is not available.
     *
     * @hide
     */
    @NonNull
    @RequiresPermission(android.Manifest.permission.HDMI_CEC)
    public List<String> getAllowedCecSettingValues(@NonNull @CecSettingName String name) {
    public List<Integer> getAllowedCecSettingIntValues(@NonNull @CecSettingName String name) {
        if (mService == null) {
            Log.e(TAG, "HdmiControlService is not available");
            throw new RuntimeException("HdmiControlService is not available");
        }
        try {
            return mService.getAllowedCecSettingValues(name);
            int[] allowedValues = mService.getAllowedCecSettingIntValues(name);
            return Arrays.stream(allowedValues).boxed().collect(Collectors.toList());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -1350,13 +1379,13 @@ public final class HdmiControlManager {
     * @hide
     */
    @RequiresPermission(android.Manifest.permission.HDMI_CEC)
    public void setHdmiCecEnabled(@NonNull @HdmiCecControl String value) {
    public void setHdmiCecEnabled(@NonNull @HdmiCecControl int value) {
        if (mService == null) {
            Log.e(TAG, "HdmiControlService is not available");
            throw new RuntimeException("HdmiControlService is not available");
        }
        try {
            mService.setCecSettingValue(CEC_SETTING_NAME_HDMI_CEC_ENABLED, value);
            mService.setCecSettingIntValue(CEC_SETTING_NAME_HDMI_CEC_ENABLED, value);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -1373,13 +1402,13 @@ public final class HdmiControlManager {
    @NonNull
    @HdmiCecControl
    @RequiresPermission(android.Manifest.permission.HDMI_CEC)
    public String getHdmiCecEnabled() {
    public int getHdmiCecEnabled() {
        if (mService == null) {
            Log.e(TAG, "HdmiControlService is not available");
            throw new RuntimeException("HdmiControlService is not available");
        }
        try {
            return mService.getCecSettingValue(CEC_SETTING_NAME_HDMI_CEC_ENABLED);
            return mService.getCecSettingIntValue(CEC_SETTING_NAME_HDMI_CEC_ENABLED);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -1401,7 +1430,7 @@ public final class HdmiControlManager {
            throw new RuntimeException("HdmiControlService is not available");
        }
        try {
            mService.setCecSettingValue(CEC_SETTING_NAME_SEND_STANDBY_ON_SLEEP, value);
            mService.setCecSettingStringValue(CEC_SETTING_NAME_SEND_STANDBY_ON_SLEEP, value);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -1424,7 +1453,7 @@ public final class HdmiControlManager {
            throw new RuntimeException("HdmiControlService is not available");
        }
        try {
            return mService.getCecSettingValue(CEC_SETTING_NAME_SEND_STANDBY_ON_SLEEP);
            return mService.getCecSettingStringValue(CEC_SETTING_NAME_SEND_STANDBY_ON_SLEEP);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -1447,7 +1476,7 @@ public final class HdmiControlManager {
            throw new RuntimeException("HdmiControlService is not available");
        }
        try {
            mService.setCecSettingValue(
            mService.setCecSettingStringValue(
                    CEC_SETTING_NAME_POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST, value);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
@@ -1471,7 +1500,7 @@ public final class HdmiControlManager {
            throw new RuntimeException("HdmiControlService is not available");
        }
        try {
            return mService.getCecSettingValue(
            return mService.getCecSettingStringValue(
                    CEC_SETTING_NAME_POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
@@ -1488,13 +1517,13 @@ public final class HdmiControlManager {
     * @hide
     */
    @RequiresPermission(android.Manifest.permission.HDMI_CEC)
    public void setSystemAudioModeMuting(@NonNull @SystemAudioModeMuting String value) {
    public void setSystemAudioModeMuting(@NonNull @SystemAudioModeMuting int value) {
        if (mService == null) {
            Log.e(TAG, "HdmiControlService is not available");
            throw new RuntimeException("HdmiControlService is not available");
        }
        try {
            mService.setCecSettingValue(CEC_SETTING_NAME_SYSTEM_AUDIO_MODE_MUTING, value);
            mService.setCecSettingIntValue(CEC_SETTING_NAME_SYSTEM_AUDIO_MODE_MUTING, value);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -1511,13 +1540,13 @@ public final class HdmiControlManager {
    @NonNull
    @SystemAudioModeMuting
    @RequiresPermission(android.Manifest.permission.HDMI_CEC)
    public String getSystemAudioModeMuting() {
    public int getSystemAudioModeMuting() {
        if (mService == null) {
            Log.e(TAG, "HdmiControlService is not available");
            throw new RuntimeException("HdmiControlService is not available");
        }
        try {
            return mService.getCecSettingValue(CEC_SETTING_NAME_SYSTEM_AUDIO_MODE_MUTING);
            return mService.getCecSettingIntValue(CEC_SETTING_NAME_SYSTEM_AUDIO_MODE_MUTING);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+39 −9
Original line number Diff line number Diff line
@@ -301,18 +301,33 @@ public final class HdmiControlServiceWrapper {
        }

        @Override
        public List<String> getAllowedCecSettingValues(String name) {
            return HdmiControlServiceWrapper.this.getAllowedCecSettingValues(name);
        public List<String> getAllowedCecSettingStringValues(String name) {
            return HdmiControlServiceWrapper.this.getAllowedCecSettingStringValues(name);
        }

        @Override
        public String getCecSettingValue(String name) {
            return HdmiControlServiceWrapper.this.getCecSettingValue(name);
        public int[] getAllowedCecSettingIntValues(String name) {
            return HdmiControlServiceWrapper.this.getAllowedCecSettingIntValues(name);
        }

        @Override
        public void setCecSettingValue(String name, String value) {
            HdmiControlServiceWrapper.this.setCecSettingValue(name, value);
        public String getCecSettingStringValue(String name) {
            return HdmiControlServiceWrapper.this.getCecSettingStringValue(name);
        }

        @Override
        public void setCecSettingStringValue(String name, String value) {
            HdmiControlServiceWrapper.this.setCecSettingStringValue(name, value);
        }

        @Override
        public int getCecSettingIntValue(String name) {
            return HdmiControlServiceWrapper.this.getCecSettingIntValue(name);
        }

        @Override
        public void setCecSettingIntValue(String name, int value) {
            HdmiControlServiceWrapper.this.setCecSettingIntValue(name, value);
        }
    };

@@ -494,15 +509,30 @@ public final class HdmiControlServiceWrapper {
    }

    /** @hide */
    public List<String> getAllowedCecSettingValues(String name) {
    public List<String> getAllowedCecSettingStringValues(String name) {
        return new ArrayList<>();
    }

    /** @hide */
    public String getCecSettingValue(String name) {
    public int[] getAllowedCecSettingIntValues(String name) {
        return new int[0];
    }

    /** @hide */
    public String getCecSettingStringValue(String name) {
        return "";
    }

    /** @hide */
    public void setCecSettingValue(String name, String value) {}
    public void setCecSettingStringValue(String name, String value) {
    }

    /** @hide */
    public int getCecSettingIntValue(String name) {
        return 0;
    }

    /** @hide */
    public void setCecSettingIntValue(String name, int value) {
    }
}
+6 −3
Original line number Diff line number Diff line
@@ -88,7 +88,10 @@ interface IHdmiControlService {
    void reportAudioStatus(int deviceType, int volume, int maxVolume, boolean isMute);
    void setSystemAudioModeOnForAudioOnlySource();
    List<String> getUserCecSettings();
    List<String> getAllowedCecSettingValues(String name);
    String getCecSettingValue(String name);
    void setCecSettingValue(String name, String value);
    List<String> getAllowedCecSettingStringValues(String name);
    int[] getAllowedCecSettingIntValues(String name);
    String getCecSettingStringValue(String name);
    void setCecSettingStringValue(String name, String value);
    int getCecSettingIntValue(String name);
    void setCecSettingIntValue(String name, int value);
}
+17 −3
Original line number Diff line number Diff line
@@ -381,17 +381,31 @@ public class HdmiAudioSystemClientTest {
        }

        @Override
        public List<String> getAllowedCecSettingValues(String name) {
        public List<String> getAllowedCecSettingStringValues(String name) {
            return new ArrayList<>();
        }

        @Override
        public String getCecSettingValue(String name) {
        public int[] getAllowedCecSettingIntValues(String name) {
            return new int[0];
        }

        @Override
        public String getCecSettingStringValue(String name) {
            return "";
        }

        @Override
        public void setCecSettingValue(String name, String value) {
        public void setCecSettingStringValue(String name, String value) {
        }

        @Override
        public int getCecSettingIntValue(String name) {
            return 0;
        }

        @Override
        public void setCecSettingIntValue(String name, int value) {
        }
    }

+138 −15
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static android.hardware.hdmi.HdmiControlManager.CecSettingName;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.StringDef;
import android.content.Context;
import android.hardware.hdmi.HdmiControlManager;
import android.os.Environment;
@@ -68,6 +69,15 @@ public class HdmiCecConfig {
    private static final int STORAGE_SYSPROPS = 0;
    private static final int STORAGE_GLOBAL_SETTINGS = 1;

    private static final String VALUE_TYPE_STRING = "string";
    private static final String VALUE_TYPE_INT = "int";

    @StringDef({
        VALUE_TYPE_STRING,
        VALUE_TYPE_INT,
    })
    private @interface ValueType {}

    /**
     * System property key for Power State Change on Active Source Lost.
     */
@@ -247,17 +257,15 @@ public class HdmiCecConfig {
        }
    }

    private String retrieveValue(@NonNull Setting setting) {
    private String retrieveValue(@NonNull Setting setting, @NonNull String defaultValue) {
        @Storage int storage = getStorage(setting);
        String storageKey = getStorageKey(setting);
        if (storage == STORAGE_SYSPROPS) {
            Slog.d(TAG, "Reading '" + storageKey + "' sysprop.");
            return mStorageAdapter.retrieveSystemProperty(storageKey,
                    setting.getDefaultValue().getStringValue());
            return mStorageAdapter.retrieveSystemProperty(storageKey, defaultValue);
        } else if (storage == STORAGE_GLOBAL_SETTINGS) {
            Slog.d(TAG, "Reading '" + storageKey + "' global setting.");
            return mStorageAdapter.retrieveGlobalSetting(mContext, storageKey,
                    setting.getDefaultValue().getStringValue());
            return mStorageAdapter.retrieveGlobalSetting(mContext, storageKey, defaultValue);
        }
        return null;
    }
@@ -316,13 +324,41 @@ public class HdmiCecConfig {
    }

    /**
     * For a given setting name returns values that are allowed for that setting.
     * For a given setting name returns true if and only if the value type of that
     * setting is a string.
     */
    public boolean isStringValueType(@NonNull @CecSettingName String name) {
        Setting setting = getSetting(name);
        if (setting == null) {
            throw new IllegalArgumentException("Setting '" + name + "' does not exist.");
        }
        return getSetting(name).getValueType().equals(VALUE_TYPE_STRING);
    }

    /**
     * For a given setting name returns true if and only if the value type of that
     * setting is an int.
     */
    public List<String> getAllowedValues(@NonNull @CecSettingName String name) {
    public boolean isIntValueType(@NonNull @CecSettingName String name) {
        Setting setting = getSetting(name);
        if (setting == null) {
            throw new IllegalArgumentException("Setting '" + name + "' does not exist.");
        }
        return getSetting(name).getValueType().equals(VALUE_TYPE_INT);
    }

    /**
     * For a given setting name returns values that are allowed for that setting (string).
     */
    public List<String> getAllowedStringValues(@NonNull @CecSettingName String name) {
        Setting setting = getSetting(name);
        if (setting == null) {
            throw new IllegalArgumentException("Setting '" + name + "' does not exist.");
        }
        if (!setting.getValueType().equals(VALUE_TYPE_STRING)) {
            throw new IllegalArgumentException("Setting '" + name
                    + "' is not a string-type setting.");
        }
        List<String> allowedValues = new ArrayList<String>();
        for (Value allowedValue : setting.getAllowedValues().getValue()) {
            allowedValues.add(allowedValue.getStringValue());
@@ -331,32 +367,92 @@ public class HdmiCecConfig {
    }

    /**
     * For a given setting name returns the default value for that setting.
     * For a given setting name returns values that are allowed for that setting (string).
     */
    public String getDefaultValue(@NonNull @CecSettingName String name) {
    public List<Integer> getAllowedIntValues(@NonNull @CecSettingName String name) {
        Setting setting = getSetting(name);
        if (setting == null) {
            throw new IllegalArgumentException("Setting '" + name + "' does not exist.");
        }
        if (!setting.getValueType().equals(VALUE_TYPE_INT)) {
            throw new IllegalArgumentException("Setting '" + name
                    + "' is not a string-type setting.");
        }
        List<Integer> allowedValues = new ArrayList<Integer>();
        for (Value allowedValue : setting.getAllowedValues().getValue()) {
            allowedValues.add(allowedValue.getIntValue());
        }
        return allowedValues;
    }

    /**
     * For a given setting name returns the default value for that setting (string).
     */
    public String getDefaultStringValue(@NonNull @CecSettingName String name) {
        Setting setting = getSetting(name);
        if (setting == null) {
            throw new IllegalArgumentException("Setting '" + name + "' does not exist.");
        }
        if (!setting.getValueType().equals(VALUE_TYPE_STRING)) {
            throw new IllegalArgumentException("Setting '" + name
                    + "' is not a string-type setting.");
        }
        return getSetting(name).getDefaultValue().getStringValue();
    }

    /**
     * For a given setting name returns the current value of that setting.
     * For a given setting name returns the default value for that setting (int).
     */
    public int getDefaultIntValue(@NonNull @CecSettingName String name) {
        Setting setting = getSetting(name);
        if (setting == null) {
            throw new IllegalArgumentException("Setting '" + name + "' does not exist.");
        }
        if (!setting.getValueType().equals(VALUE_TYPE_INT)) {
            throw new IllegalArgumentException("Setting '" + name
                    + "' is not a string-type setting.");
        }
        return getSetting(name).getDefaultValue().getIntValue();
    }

    /**
     * For a given setting name returns the current value of that setting (string).
     */
    public String getStringValue(@NonNull @CecSettingName String name) {
        Setting setting = getSetting(name);
        if (setting == null) {
            throw new IllegalArgumentException("Setting '" + name + "' does not exist.");
        }
        if (!setting.getValueType().equals(VALUE_TYPE_STRING)) {
            throw new IllegalArgumentException("Setting '" + name
                    + "' is not a string-type setting.");
        }
        Slog.d(TAG, "Getting CEC setting value '" + name + "'.");
        return retrieveValue(setting, setting.getDefaultValue().getStringValue());
    }

    /**
     * For a given setting name returns the current value of that setting (int).
     */
    public String getValue(@NonNull @CecSettingName String name) {
    public int getIntValue(@NonNull @CecSettingName String name) {
        Setting setting = getSetting(name);
        if (setting == null) {
            throw new IllegalArgumentException("Setting '" + name + "' does not exist.");
        }
        if (!setting.getValueType().equals(VALUE_TYPE_INT)) {
            throw new IllegalArgumentException("Setting '" + name
                    + "' is not a int-type setting.");
        }
        Slog.d(TAG, "Getting CEC setting value '" + name + "'.");
        return retrieveValue(setting);
        String defaultValue = Integer.toString(setting.getDefaultValue().getIntValue());
        String value = retrieveValue(setting, defaultValue);
        return Integer.parseInt(value);
    }

    /**
     * For a given setting name and value sets the current value of that setting.
     * For a given setting name and value sets the current value of that setting (string).
     */
    public void setValue(@NonNull @CecSettingName String name, @NonNull String value) {
    public void setStringValue(@NonNull @CecSettingName String name, @NonNull String value) {
        Setting setting = getSetting(name);
        if (setting == null) {
            throw new IllegalArgumentException("Setting '" + name + "' does not exist.");
@@ -364,11 +460,38 @@ public class HdmiCecConfig {
        if (!setting.getUserConfigurable()) {
            throw new IllegalArgumentException("Updating CEC setting '" + name + "' prohibited.");
        }
        if (!getAllowedValues(name).contains(value)) {
        if (!setting.getValueType().equals(VALUE_TYPE_STRING)) {
            throw new IllegalArgumentException("Setting '" + name
                    + "' is not a string-type setting.");
        }
        if (!getAllowedStringValues(name).contains(value)) {
            throw new IllegalArgumentException("Invalid CEC setting '" + name
                                               + "' value: '" + value + "'.");
        }
        Slog.d(TAG, "Updating CEC setting '" + name + "' to '" + value + "'.");
        storeValue(setting, value);
    }

    /**
     * For a given setting name and value sets the current value of that setting (int).
     */
    public void setIntValue(@NonNull @CecSettingName String name, int value) {
        Setting setting = getSetting(name);
        if (setting == null) {
            throw new IllegalArgumentException("Setting '" + name + "' does not exist.");
        }
        if (!setting.getUserConfigurable()) {
            throw new IllegalArgumentException("Updating CEC setting '" + name + "' prohibited.");
        }
        if (!setting.getValueType().equals(VALUE_TYPE_INT)) {
            throw new IllegalArgumentException("Setting '" + name
                    + "' is not a int-type setting.");
        }
        if (!getAllowedIntValues(name).contains(value)) {
            throw new IllegalArgumentException("Invalid CEC setting '" + name
                                               + "' value: '" + value + "'.");
        }
        Slog.d(TAG, "Updating CEC setting '" + name + "' to '" + value + "'.");
        storeValue(setting, Integer.toString(value));
    }
}
Loading