Let playback device send a command <Standby> based on the setting.
ACTION_SHUTDOWN leads to broadcast command to put all the devices
to sleep, and ACTION_SCREEN_OFF optionally turns off TV only.
Change-Id: Id458b23ce86b0c3179efa21cce85b721a47001be
}
}
+ void setAutoDeviceOff(boolean enabled) {
+ }
+
/**
* Called when a hot-plug event issued.
*
*
* @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
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;
// 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
}
}
+ @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();
protected void dump(final IndentingPrintWriter pw) {
super.dump(pw);
pw.println("mIsActiveSource: " + mIsActiveSource);
+ pw.println("mAutoTvOff:" + mAutoTvOff);
}
// Wrapper interface over PowerManager.WakeLock
}
}
+ @Override
@ServiceThreadOnly
void setAutoDeviceOff(boolean enabled) {
assertRunOnServiceThread();
@Override
@ServiceThreadOnly
- protected void onStandby(boolean initiatedByCec) {
+ protected void onStandby(boolean initiatedByCec, int standbyAction) {
assertRunOnServiceThread();
// Seq #11
if (!mService.isControlEnabled()) {
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.
*/
switch (intent.getAction()) {
case Intent.ACTION_SCREEN_OFF:
if (isPowerOnOrTransient()) {
- onStandby();
+ onStandby(STANDBY_SCREEN_OFF);
}
break;
case Intent.ACTION_SCREEN_ON:
onLanguageChanged(language);
}
break;
+ case Intent.ACTION_SHUTDOWN:
+ if (isPowerOnOrTransient()) {
+ onStandby(STANDBY_SHUTDOWN);
+ }
+ break;
}
}
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;
}
@ServiceThreadOnly
- private void onStandby() {
+ private void onStandby(final int standbyAction) {
assertRunOnServiceThread();
if (!canGoToStandby()) return;
mPowerStatus = HdmiControlManager.POWER_STATUS_TRANSIENT_TO_STANDBY;
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.
}
@ServiceThreadOnly
- private void onStandbyCompleted() {
+ private void onStandbyCompleted(int standbyAction) {
assertRunOnServiceThread();
Slog.v(TAG, "onStandbyCompleted");
}
mPowerStatus = HdmiControlManager.POWER_STATUS_STANDBY;
for (HdmiCecLocalDevice device : mCecController.getLocalDeviceList()) {
- device.onStandby(mStandbyMessageReceived);
+ device.onStandby(mStandbyMessageReceived, standbyAction);
}
mStandbyMessageReceived = false;
mAddressAllocated = false;