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

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

Merge changes from topics "CecConfigPowerStateChangeOnActiveSourceLost",...

Merge changes from topics "CecConfigPowerStateChangeOnActiveSourceLost", "CecConfigSendStandbyOnSleep", "CecConfigSystemAudioModeMuting"

* changes:
  [CEC Configuration] Port 'system_audio_mode_muting'
  [CEC Configuration] Port 'power_state_change_on_active_source_lost'
  [CEC Configuration] Use CEC Config API in the 'send_standby_on_sleep' option
parents 71d21ecd 56ed615d
Loading
Loading
Loading
Loading
+53 −25
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.StringDef;
import android.content.Context;
import android.content.SharedPreferences;
import android.hardware.hdmi.HdmiControlManager;
import android.os.Environment;
import android.os.SystemProperties;
@@ -59,15 +60,19 @@ public class HdmiCecConfig {

    private static final String ETC_DIR = "etc";
    private static final String CONFIG_FILE = "cec_config.xml";
    private static final String SHARED_PREFS_DIR = "shared_prefs";
    private static final String SHARED_PREFS_NAME = "cec_config.xml";

    @IntDef({
        STORAGE_SYSPROPS,
        STORAGE_GLOBAL_SETTINGS,
        STORAGE_SHARED_PREFS,
    })
    private @interface Storage {}

    private static final int STORAGE_SYSPROPS = 0;
    private static final int STORAGE_GLOBAL_SETTINGS = 1;
    private static final int STORAGE_SHARED_PREFS = 2;

    private static final String VALUE_TYPE_STRING = "string";
    private static final String VALUE_TYPE_INT = "int";
@@ -78,18 +83,6 @@ public class HdmiCecConfig {
    })
    private @interface ValueType {}

    /**
     * System property key for Power State Change on Active Source Lost.
     */
    public static final String SYSPROP_POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST =
            "ro.hdmi.cec.source.power_state_change_on_active_source_lost";

    /**
     * System property key for Audio Mode Muting.
     */
    public static final String SYSPROP_SYSTEM_AUDIO_MODE_MUTING =
            "ro.hdmi.cec.audio.system_audio_mode_muting.enabled";

    @NonNull private final Context mContext;
    @NonNull private final StorageAdapter mStorageAdapter;
    @Nullable private final CecSettings mSystemConfig;
@@ -99,6 +92,20 @@ public class HdmiCecConfig {
     * Setting storage input/output helper class.
     */
    public static class StorageAdapter {
        @NonNull private final Context mContext;
        @NonNull private final SharedPreferences mSharedPrefs;

        StorageAdapter(@NonNull Context context) {
            mContext = context;
            // The package info in the context isn't initialized in the way it is for normal apps,
            // so the standard, name-based context.getSharedPreferences doesn't work. Instead, we
            // build the path manually below using the same policy that appears in ContextImpl.
            final Context deviceContext = mContext.createDeviceProtectedStorageContext();
            final File prefsFile = new File(new File(Environment.getDataSystemDirectory(),
                                                     SHARED_PREFS_DIR), SHARED_PREFS_NAME);
            mSharedPrefs = deviceContext.getSharedPreferences(prefsFile, Context.MODE_PRIVATE);
        }

        /**
         * Read the value from a system property.
         * Returns the given default value if the system property is not set.
@@ -120,20 +127,35 @@ public class HdmiCecConfig {
         * Read the value from a global setting.
         * Returns the given default value if the system property is not set.
         */
        public String retrieveGlobalSetting(@NonNull Context context,
                                            @NonNull String storageKey,
        public String retrieveGlobalSetting(@NonNull String storageKey,
                                            @NonNull String defaultValue) {
            String value = Global.getString(context.getContentResolver(), storageKey);
            String value = Global.getString(mContext.getContentResolver(), storageKey);
            return value != null ? value : defaultValue;
        }

        /**
         * Write the value to a global setting.
         */
        public void storeGlobalSetting(@NonNull Context context,
                                       @NonNull String storageKey,
        public void storeGlobalSetting(@NonNull String storageKey,
                                       @NonNull String value) {
            Global.putString(mContext.getContentResolver(), storageKey, value);
        }

        /**
         * Read the value from a shared preference.
         * Returns the given default value if the preference is not set.
         */
        public String retrieveSharedPref(@NonNull String storageKey,
                                         @NonNull String defaultValue) {
            return mSharedPrefs.getString(storageKey, defaultValue);
        }

        /**
         * Write the value to a shared preference.
         */
        public void storeSharedPref(@NonNull String storageKey,
                                    @NonNull String value) {
            Global.putString(context.getContentResolver(), storageKey, value);
            mSharedPrefs.edit().putString(storageKey, value).apply();
        }
    }

@@ -155,7 +177,7 @@ public class HdmiCecConfig {
    }

    HdmiCecConfig(@NonNull Context context) {
        this(context, new StorageAdapter(),
        this(context, new StorageAdapter(context),
             readSettingsFromFile(Environment.buildPath(Environment.getRootDirectory(),
                                                        ETC_DIR, CONFIG_FILE)),
             readSettingsFromFile(Environment.buildPath(Environment.getVendorDirectory(),
@@ -234,9 +256,9 @@ public class HdmiCecConfig {
            case HdmiControlManager.CEC_SETTING_NAME_SEND_STANDBY_ON_SLEEP:
                return STORAGE_GLOBAL_SETTINGS;
            case HdmiControlManager.CEC_SETTING_NAME_POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST:
                return STORAGE_SYSPROPS;
                return STORAGE_SHARED_PREFS;
            case HdmiControlManager.CEC_SETTING_NAME_SYSTEM_AUDIO_MODE_MUTING:
                return STORAGE_SYSPROPS;
                return STORAGE_SHARED_PREFS;
            default:
                throw new RuntimeException("Invalid CEC setting '" + setting.getName()
                        + "' storage.");
@@ -252,9 +274,9 @@ public class HdmiCecConfig {
            case HdmiControlManager.CEC_SETTING_NAME_SEND_STANDBY_ON_SLEEP:
                return Global.HDMI_CONTROL_SEND_STANDBY_ON_SLEEP;
            case HdmiControlManager.CEC_SETTING_NAME_POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST:
                return SYSPROP_POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST;
                return setting.getName();
            case HdmiControlManager.CEC_SETTING_NAME_SYSTEM_AUDIO_MODE_MUTING:
                return SYSPROP_SYSTEM_AUDIO_MODE_MUTING;
                return setting.getName();
            default:
                throw new RuntimeException("Invalid CEC setting '" + setting.getName()
                    + "' storage key.");
@@ -269,7 +291,10 @@ public class HdmiCecConfig {
            return mStorageAdapter.retrieveSystemProperty(storageKey, defaultValue);
        } else if (storage == STORAGE_GLOBAL_SETTINGS) {
            Slog.d(TAG, "Reading '" + storageKey + "' global setting.");
            return mStorageAdapter.retrieveGlobalSetting(mContext, storageKey, defaultValue);
            return mStorageAdapter.retrieveGlobalSetting(storageKey, defaultValue);
        } else if (storage == STORAGE_SHARED_PREFS) {
            Slog.d(TAG, "Reading '" + storageKey + "' shared preference.");
            return mStorageAdapter.retrieveSharedPref(storageKey, defaultValue);
        }
        return null;
    }
@@ -282,7 +307,10 @@ public class HdmiCecConfig {
            mStorageAdapter.storeSystemProperty(storageKey, value);
        } else if (storage == STORAGE_GLOBAL_SETTINGS) {
            Slog.d(TAG, "Setting '" + storageKey + "' global setting.");
            mStorageAdapter.storeGlobalSetting(mContext, storageKey, value);
            mStorageAdapter.storeGlobalSetting(storageKey, value);
        } else if (storage == STORAGE_SHARED_PREFS) {
            Slog.d(TAG, "Setting '" + storageKey + "' shared pref.");
            mStorageAdapter.storeSharedPref(storageKey, value);
        }
    }

+6 −3
Original line number Diff line number Diff line
@@ -778,11 +778,14 @@ public class HdmiCecLocalDeviceAudioSystem extends HdmiCecLocalDeviceSource {
            switchToAudioInput();
        }
        // Mute device when feature is turned off and unmute device when feature is turned on.
        // PROPERTY_SYSTEM_AUDIO_MODE_MUTING_ENABLE is false when device never needs to be muted.
        // CEC_SETTING_NAME_SYSTEM_AUDIO_MODE_MUTING is false when device never needs to be muted.
        boolean systemAudioModeMutingEnabled = mService.getHdmiCecConfig().getIntValue(
                    HdmiControlManager.CEC_SETTING_NAME_SYSTEM_AUDIO_MODE_MUTING)
                        == HdmiControlManager.SYSTEM_AUDIO_MODE_MUTING_ENABLED;
        boolean currentMuteStatus =
                mService.getAudioManager().isStreamMute(AudioManager.STREAM_MUSIC);
        if (currentMuteStatus == newSystemAudioMode) {
            if (HdmiProperties.system_audio_mode_muting().orElse(true) || newSystemAudioMode) {
            if (systemAudioModeMutingEnabled || newSystemAudioMode) {
                mService.getAudioManager()
                        .adjustStreamVolume(
                                AudioManager.STREAM_MUSIC,
@@ -806,7 +809,7 @@ public class HdmiCecLocalDeviceAudioSystem extends HdmiCecLocalDeviceSource {
        // Audio Mode is off even without terminating the ARC. This can stop the current
        // audio device from playing audio when system audio mode is off.
        if (mArcIntentUsed
                && !HdmiProperties.system_audio_mode_muting().orElse(true)
                && !systemAudioModeMutingEnabled
                && !newSystemAudioMode
                && getLocalActivePort() == Constants.CEC_SWITCH_ARC) {
            routeToInputFromPortId(getRoutingPort());
+6 −23
Original line number Diff line number Diff line
@@ -66,13 +66,6 @@ public class HdmiCecLocalDevicePlayback extends HdmiCecLocalDeviceSource {
                    .playback_device_action_on_routing_control()
                    .orElse(HdmiProperties.playback_device_action_on_routing_control_values.NONE);

    // Behaviour of the device when <Active Source> is lost in favor of another device.
    @VisibleForTesting
    protected HdmiProperties.power_state_change_on_active_source_lost_values
            mPowerStateChangeOnActiveSourceLost = HdmiProperties
                    .power_state_change_on_active_source_lost()
                    .orElse(HdmiProperties.power_state_change_on_active_source_lost_values.NONE);

    HdmiCecLocalDevicePlayback(HdmiControlService service) {
        super(service, HdmiDeviceInfo.DEVICE_PLAYBACK);

@@ -81,14 +74,6 @@ public class HdmiCecLocalDevicePlayback extends HdmiCecLocalDeviceSource {
        // The option is false by default. Update settings db as well to have the right
        // initial setting on UI.
        mService.writeBooleanSetting(Global.HDMI_CONTROL_AUTO_DEVICE_OFF_ENABLED, mAutoTvOff);

        // Initialize settings database with System Property value. This will be the initial
        // setting on the UI. If no System Property is set, the option is set to to_tv by default.
        mService.writeStringSetting(Global.HDMI_CONTROL_SEND_STANDBY_ON_SLEEP,
                mService.readStringSetting(Global.HDMI_CONTROL_SEND_STANDBY_ON_SLEEP,
                        HdmiProperties.send_standby_on_sleep().orElse(
                                HdmiProperties.send_standby_on_sleep_values.TO_TV).name()
                                .toLowerCase()));
    }

    @Override
@@ -195,11 +180,8 @@ public class HdmiCecLocalDevicePlayback extends HdmiCecLocalDeviceSource {
            case HdmiControlService.STANDBY_SCREEN_OFF:
                // Get latest setting value
                @HdmiControlManager.StandbyBehavior
                String sendStandbyOnSleep = mService.readStringSetting(
                        Global.HDMI_CONTROL_SEND_STANDBY_ON_SLEEP,
                        HdmiProperties.send_standby_on_sleep().orElse(
                                HdmiProperties.send_standby_on_sleep_values.TO_TV).name()
                                .toLowerCase());
                String sendStandbyOnSleep = mService.getHdmiCecConfig().getStringValue(
                        HdmiControlManager.CEC_SETTING_NAME_SEND_STANDBY_ON_SLEEP);
                switch (sendStandbyOnSleep) {
                    case HdmiControlManager.SEND_STANDBY_ON_SLEEP_TO_TV:
                        mService.sendCecCommand(
@@ -290,11 +272,12 @@ public class HdmiCecLocalDevicePlayback extends HdmiCecLocalDeviceSource {
    @ServiceThreadOnly
    protected void onActiveSourceLost() {
        assertRunOnServiceThread();
        switch (mPowerStateChangeOnActiveSourceLost) {
            case STANDBY_NOW:
        switch (mService.getHdmiCecConfig().getStringValue(
                    HdmiControlManager.CEC_SETTING_NAME_POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST)) {
            case HdmiControlManager.POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST_STANDBY_NOW:
                mService.standby();
                return;
            case NONE:
            case HdmiControlManager.POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST_NONE:
                return;
        }
    }
+3 −3
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ import android.hardware.hdmi.HdmiControlManager;
import android.hardware.hdmi.HdmiPlaybackClient.OneTouchPlayCallback;
import android.hardware.hdmi.IHdmiControlCallback;
import android.os.RemoteException;
import android.provider.Settings.Global;
import android.util.Slog;

import java.util.ArrayList;
@@ -166,8 +165,9 @@ final class OneTouchPlayAction extends HdmiCecFeatureAction {
        if (service.isAudioSystemDevice()) {
            return false;
        }
        String sendStandbyOnSleep = service.readStringSetting(
                Global.HDMI_CONTROL_SEND_STANDBY_ON_SLEEP, "");
        @HdmiControlManager.StandbyBehavior String sendStandbyOnSleep =
                service.getHdmiCecConfig().getStringValue(
                        HdmiControlManager.CEC_SETTING_NAME_SEND_STANDBY_ON_SLEEP);
        return sendStandbyOnSleep.equals(HdmiControlManager.SEND_STANDBY_ON_SLEEP_BROADCAST);
    }
}
+19 −1
Original line number Diff line number Diff line
@@ -50,6 +50,15 @@ final class FakeHdmiCecConfig extends HdmiCecConfig {
                    + "    </allowed-values>"
                    + "    <default-value string-value=\"to_tv\" />"
                    + "  </setting>"
                    + "  <setting name=\"power_state_change_on_active_source_lost\""
                    + "           value-type=\"string\""
                    + "           user-configurable=\"true\">"
                    + "    <allowed-values>"
                    + "      <value string-value=\"none\" />"
                    + "      <value string-value=\"standby_now\" />"
                    + "    </allowed-values>"
                    + "    <default-value string-value=\"none\" />"
                    + "  </setting>"
                    + "  <setting name=\"hdmi_cec_version\""
                    + "           value-type=\"int\""
                    + "           user-configurable=\"true\">"
@@ -59,10 +68,19 @@ final class FakeHdmiCecConfig extends HdmiCecConfig {
                    + "    </allowed-values>"
                    + "    <default-value int-value=\"0x05\" />"
                    + "  </setting>"
                    + "  <setting name=\"system_audio_mode_muting\""
                    + "           value-type=\"int\""
                    + "           user-configurable=\"true\">"
                    + "    <allowed-values>"
                    + "      <value int-value=\"0\" />"
                    + "      <value int-value=\"1\" />"
                    + "    </allowed-values>"
                    + "    <default-value int-value=\"1\" />"
                    + "  </setting>"
                    + "</cec-settings>";

    FakeHdmiCecConfig(@NonNull Context context) {
        super(context, new StorageAdapter(), parseFromString(SYSTEM_CONFIG_XML), null);
        super(context, new StorageAdapter(context), parseFromString(SYSTEM_CONFIG_XML), null);
    }

    private static CecSettings parseFromString(@NonNull String configXml) {
Loading