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

Commit 6117d617 authored by Nathalie Le Clair's avatar Nathalie Le Clair Committed by Android (Google) Code Review
Browse files

Merge "CEC Standby messages when going to sleep"

parents 154341cb 348f4982
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.annotation.RequiresFeature;
import android.annotation.RequiresPermission;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.StringDef;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.annotation.SystemService;
@@ -39,6 +40,8 @@ import android.util.Log;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.ConcurrentUtils;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@@ -318,6 +321,37 @@ public final class HdmiControlManager {
    /** The HdmiControlService will be disabled to standby. */
    public static final int CONTROL_STATE_CHANGED_REASON_STANDBY = 3;

    // -- Which devices the playback device can send a <Standby> message to upon going to sleep.
    /**
     * Send <Standby> to TV only.
     *
     * @hide
     */
    public static final String SEND_STANDBY_ON_SLEEP_TO_TV = "to_tv";
    /**
     * Broadcast <Standby> to all devices in the network.
     *
     * @hide
     */
    public static final String SEND_STANDBY_ON_SLEEP_BROADCAST = "broadcast";
    /**
     * Don't send any <Standby> message.
     *
     * @hide
     */
    public static final String SEND_STANDBY_ON_SLEEP_NONE = "none";
    /**
     * @hide
     */
    @StringDef({
            SEND_STANDBY_ON_SLEEP_TO_TV,
            SEND_STANDBY_ON_SLEEP_BROADCAST,
            SEND_STANDBY_ON_SLEEP_NONE
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface StandbyBehavior {
    }

    // True if we have a logical device of type playback hosted in the system.
    private final boolean mHasPlaybackDevice;
    // True if we have a logical device of type TV hosted in the system.
+15 −0
Original line number Diff line number Diff line
@@ -9793,6 +9793,21 @@ public final class Settings {
        public static final String HDMI_CONTROL_AUTO_DEVICE_OFF_ENABLED =
                "hdmi_control_auto_device_off_enabled";
        /**
         * Property to decide which devices the playback device can send a <Standby> message to upon
         * going to sleep. Supported values are:
         * <ul>
         * <li>{@link HdmiControlManager#SEND_STANDBY_ON_SLEEP_TO_TV} to TV only.</li>
         * <li>{@link HdmiControlManager#SEND_STANDBY_ON_SLEEP_BROADCAST} to all devices in the
         * network.</li>
         * <li>{@link HdmiControlManager#SEND_STANDBY_ON_SLEEP_NONE} no <Standby> message sent.</li>
         * </ul>
         *
         * @hide
         */
        public static final String HDMI_CONTROL_SEND_STANDBY_ON_SLEEP =
                "hdmi_control_send_standby_on_sleep";
        /**
         * Whether or not media is shown automatically when bypassing as a heads up.
         * @hide
+1 −0
Original line number Diff line number Diff line
@@ -297,6 +297,7 @@ public class SettingsBackupTest {
                    Settings.Global.HDMI_CONTROL_AUTO_DEVICE_OFF_ENABLED,
                    Settings.Global.HDMI_CONTROL_AUTO_WAKEUP_ENABLED,
                    Settings.Global.HDMI_CONTROL_ENABLED,
                    Settings.Global.HDMI_CONTROL_SEND_STANDBY_ON_SLEEP,
                    Settings.Global.HDMI_CONTROL_VOLUME_CONTROL_ENABLED,
                    Settings.Global.HDMI_SYSTEM_AUDIO_CONTROL_ENABLED,
                    Settings.Global.HEADS_UP_NOTIFICATIONS_ENABLED,
+28 −2
Original line number Diff line number Diff line
@@ -85,6 +85,14 @@ 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
@@ -188,9 +196,27 @@ public class HdmiCecLocalDevicePlayback extends HdmiCecLocalDeviceSource {
        }
        switch (standbyAction) {
            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());
                switch (sendStandbyOnSleep) {
                    case HdmiControlManager.SEND_STANDBY_ON_SLEEP_TO_TV:
                        mService.sendCecCommand(
                                HdmiCecMessageBuilder.buildStandby(mAddress, Constants.ADDR_TV));
                        break;
                    case HdmiControlManager.SEND_STANDBY_ON_SLEEP_BROADCAST:
                        mService.sendCecCommand(
                                HdmiCecMessageBuilder.buildStandby(mAddress,
                                        Constants.ADDR_BROADCAST));
                        break;
                    case HdmiControlManager.SEND_STANDBY_ON_SLEEP_NONE:
                        break;
                }
                break;
            case HdmiControlService.STANDBY_SHUTDOWN:
                // ACTION_SHUTDOWN is taken as a signal to power off all the devices.
                mService.sendCecCommand(
+5 −0
Original line number Diff line number Diff line
@@ -772,6 +772,11 @@ public class HdmiControlService extends SystemService {
        return content;
    }

    void writeStringSetting(String key, String value) {
        ContentResolver cr = getContext().getContentResolver();
        Global.putString(cr, key, value);
    }

    private void initializeCec(int initiatedBy) {
        mAddressAllocated = false;
        mCecController.setOption(OptionKey.SYSTEM_CEC_CONTROL, true);
Loading