diff options
author | 2015-05-12 21:34:29 +0000 | |
---|---|---|
committer | 2015-05-12 21:34:31 +0000 | |
commit | 6dda58e7acb13f8a9c3fab385055eedf7d5c9416 (patch) | |
tree | 1a394332bad96b37c973c2bd6cd792073c4d7290 | |
parent | 20e16f4f762ddaf8a3574ad03c3f3a9f97a44637 (diff) | |
parent | e6e8f3d589f42393cf02a2bd766d678d80dad874 (diff) |
Merge "CEC: Let playback device send <Standby> upon power off" into mnc-dev
4 files changed, 68 insertions, 9 deletions
diff --git a/services/core/java/com/android/server/hdmi/HdmiCecLocalDevice.java b/services/core/java/com/android/server/hdmi/HdmiCecLocalDevice.java index 8031c058c4ce..77b800e9fba9 100644 --- a/services/core/java/com/android/server/hdmi/HdmiCecLocalDevice.java +++ b/services/core/java/com/android/server/hdmi/HdmiCecLocalDevice.java @@ -737,6 +737,9 @@ abstract class HdmiCecLocalDevice { } } + void setAutoDeviceOff(boolean enabled) { + } + /** * Called when a hot-plug event issued. * @@ -829,8 +832,11 @@ abstract class HdmiCecLocalDevice { * * @param initiatedByCec true if this power sequence is initiated * by the reception the CEC messages like <Standby> + * @param standbyAction Intent action that drives the standby process, + * either {@link HdmiControlService#STANDBY_SCREEN_OFF} or + * {@link HdmiControlService#STANDBY_SHUTDOWN} */ - protected void onStandby(boolean initiatedByCec) {} + protected void onStandby(boolean initiatedByCec, int standbyAction) {} /** * Disable device. {@code callback} is used to get notified when all pending diff --git a/services/core/java/com/android/server/hdmi/HdmiCecLocalDevicePlayback.java b/services/core/java/com/android/server/hdmi/HdmiCecLocalDevicePlayback.java index fd3364a6034b..30a9b43c5de1 100644 --- a/services/core/java/com/android/server/hdmi/HdmiCecLocalDevicePlayback.java +++ b/services/core/java/com/android/server/hdmi/HdmiCecLocalDevicePlayback.java @@ -23,6 +23,7 @@ import android.os.PowerManager; import android.os.PowerManager.WakeLock; import android.os.RemoteException; import android.os.SystemProperties; +import android.provider.Settings.Global; import android.util.Slog; import com.android.internal.util.IndentingPrintWriter; @@ -47,8 +48,17 @@ final class HdmiCecLocalDevicePlayback extends HdmiCecLocalDevice { // Lazily initialized - should call getWakeLock() to get the instance. private ActiveWakeLock mWakeLock; + // If true, turn off TV upon standby. False by default. + private boolean mAutoTvOff; + HdmiCecLocalDevicePlayback(HdmiControlService service) { super(service, HdmiDeviceInfo.DEVICE_PLAYBACK); + + mAutoTvOff = mService.readBooleanSetting(Global.HDMI_CONTROL_AUTO_DEVICE_OFF_ENABLED, false); + + // 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); } @Override @@ -141,6 +151,35 @@ final class HdmiCecLocalDevicePlayback extends HdmiCecLocalDevice { } } + @Override + @ServiceThreadOnly + protected void onStandby(boolean initiatedByCec, int standbyAction) { + assertRunOnServiceThread(); + if (!mService.isControlEnabled() || initiatedByCec) { + return; + } + switch (standbyAction) { + case HdmiControlService.STANDBY_SCREEN_OFF: + if (mAutoTvOff) { + mService.sendCecCommand( + HdmiCecMessageBuilder.buildStandby(mAddress, Constants.ADDR_TV)); + } + break; + case HdmiControlService.STANDBY_SHUTDOWN: + // ACTION_SHUTDOWN is taken as a signal to power off all the devices. + mService.sendCecCommand( + HdmiCecMessageBuilder.buildStandby(mAddress, Constants.ADDR_BROADCAST)); + break; + } + } + + @Override + @ServiceThreadOnly + void setAutoDeviceOff(boolean enabled) { + assertRunOnServiceThread(); + mAutoTvOff = enabled; + } + @ServiceThreadOnly void setActiveSource(boolean on) { assertRunOnServiceThread(); @@ -295,6 +334,7 @@ final class HdmiCecLocalDevicePlayback extends HdmiCecLocalDevice { protected void dump(final IndentingPrintWriter pw) { super.dump(pw); pw.println("mIsActiveSource: " + mIsActiveSource); + pw.println("mAutoTvOff:" + mAutoTvOff); } // Wrapper interface over PowerManager.WakeLock diff --git a/services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceTv.java b/services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceTv.java index 51ba32d3b597..96cb51c0982a 100644 --- a/services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceTv.java +++ b/services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceTv.java @@ -1583,6 +1583,7 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice { } } + @Override @ServiceThreadOnly void setAutoDeviceOff(boolean enabled) { assertRunOnServiceThread(); @@ -1659,7 +1660,7 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice { @Override @ServiceThreadOnly - protected void onStandby(boolean initiatedByCec) { + protected void onStandby(boolean initiatedByCec, int standbyAction) { assertRunOnServiceThread(); // Seq #11 if (!mService.isControlEnabled()) { diff --git a/services/core/java/com/android/server/hdmi/HdmiControlService.java b/services/core/java/com/android/server/hdmi/HdmiControlService.java index 2cbc1b9cdd77..66f7861e30c0 100644 --- a/services/core/java/com/android/server/hdmi/HdmiControlService.java +++ b/services/core/java/com/android/server/hdmi/HdmiControlService.java @@ -106,6 +106,12 @@ public final class HdmiControlService extends SystemService { static final int INITIATED_BY_WAKE_UP_MESSAGE = 3; static final int INITIATED_BY_HOTPLUG = 4; + // The reason code representing the intent action that drives the standby + // procedure. The procedure starts either by Intent.ACTION_SCREEN_OFF or + // Intent.ACTION_SHUTDOWN. + static final int STANDBY_SCREEN_OFF = 0; + static final int STANDBY_SHUTDOWN = 1; + /** * Interface to report send result. */ @@ -143,7 +149,7 @@ public final class HdmiControlService extends SystemService { switch (intent.getAction()) { case Intent.ACTION_SCREEN_OFF: if (isPowerOnOrTransient()) { - onStandby(); + onStandby(STANDBY_SCREEN_OFF); } break; case Intent.ACTION_SCREEN_ON: @@ -157,6 +163,11 @@ public final class HdmiControlService extends SystemService { onLanguageChanged(language); } break; + case Intent.ACTION_SHUTDOWN: + if (isPowerOnOrTransient()) { + onStandby(STANDBY_SHUTDOWN); + } + break; } } @@ -510,8 +521,9 @@ public final class HdmiControlService extends SystemService { setCecOption(OPTION_CEC_AUTO_WAKEUP, toInt(enabled)); break; case Global.HDMI_CONTROL_AUTO_DEVICE_OFF_ENABLED: - if (isTvDeviceEnabled()) { - tv().setAutoDeviceOff(enabled); + for (int type : mLocalDevices) { + HdmiCecLocalDevice localDevice = mCecController.getLocalDevice(type); + localDevice.setAutoDeviceOff(enabled); } // No need to propagate to HAL. break; @@ -1994,7 +2006,7 @@ public final class HdmiControlService extends SystemService { } @ServiceThreadOnly - private void onStandby() { + private void onStandby(final int standbyAction) { assertRunOnServiceThread(); if (!canGoToStandby()) return; mPowerStatus = HdmiControlManager.POWER_STATUS_TRANSIENT_TO_STANDBY; @@ -2008,7 +2020,7 @@ public final class HdmiControlService extends SystemService { Slog.v(TAG, "On standby-action cleared:" + device.mDeviceType); devices.remove(device); if (devices.isEmpty()) { - onStandbyCompleted(); + onStandbyCompleted(standbyAction); // We will not clear local devices here, since some OEM/SOC will keep passing // the received packets until the application processor enters to the sleep // actually. @@ -2062,7 +2074,7 @@ public final class HdmiControlService extends SystemService { } @ServiceThreadOnly - private void onStandbyCompleted() { + private void onStandbyCompleted(int standbyAction) { assertRunOnServiceThread(); Slog.v(TAG, "onStandbyCompleted"); @@ -2071,7 +2083,7 @@ public final class HdmiControlService extends SystemService { } mPowerStatus = HdmiControlManager.POWER_STATUS_STANDBY; for (HdmiCecLocalDevice device : mCecController.getLocalDeviceList()) { - device.onStandby(mStandbyMessageReceived); + device.onStandby(mStandbyMessageReceived, standbyAction); } mStandbyMessageReceived = false; mAddressAllocated = false; |