diff --git a/services/core/java/com/android/server/hdmi/DeviceSelectActionFromPlayback.java b/services/core/java/com/android/server/hdmi/DeviceSelectActionFromPlayback.java index b2338e6c76160..1bacca683c052 100644 --- a/services/core/java/com/android/server/hdmi/DeviceSelectActionFromPlayback.java +++ b/services/core/java/com/android/server/hdmi/DeviceSelectActionFromPlayback.java @@ -102,7 +102,7 @@ final class DeviceSelectActionFromPlayback extends HdmiCecFeatureAction { mIsCec20 = isCec20; } - private int getTargetAddress() { + int getTargetAddress() { return mTarget.getLogicalAddress(); } diff --git a/services/core/java/com/android/server/hdmi/HdmiCecController.java b/services/core/java/com/android/server/hdmi/HdmiCecController.java index 6736d2a227dda..cc864307daf10 100644 --- a/services/core/java/com/android/server/hdmi/HdmiCecController.java +++ b/services/core/java/com/android/server/hdmi/HdmiCecController.java @@ -324,7 +324,8 @@ final class HdmiCecController { /** * Return the physical address of the device. * - *
Declared as package-private. accessed by {@link HdmiControlService} only. + *
Declared as package-private. accessed by {@link HdmiControlService} and
+ * {@link HdmiCecNetwork} only.
*
* @return CEC physical address of the device. The range of success address
* is between 0x0000 and 0xFFFF. If failed it returns -1
diff --git a/services/core/java/com/android/server/hdmi/HdmiCecLocalDevice.java b/services/core/java/com/android/server/hdmi/HdmiCecLocalDevice.java
index f94d2207381f0..ab8217a9f9cd9 100755
--- a/services/core/java/com/android/server/hdmi/HdmiCecLocalDevice.java
+++ b/services/core/java/com/android/server/hdmi/HdmiCecLocalDevice.java
@@ -274,6 +274,13 @@ abstract class HdmiCecLocalDevice {
return false;
}
+ // Clear all device info.
+ @ServiceThreadOnly
+ void clearDeviceInfoList() {
+ assertRunOnServiceThread();
+ mService.getHdmiCecNetwork().clearDeviceList();
+ }
+
@ServiceThreadOnly
@Constants.HandleMessageResult
protected final int onMessage(HdmiCecMessage message) {
@@ -787,10 +794,10 @@ abstract class HdmiCecLocalDevice {
byte[] params = message.getParams();
return message.getOpcode() == Constants.MESSAGE_USER_CONTROL_PRESSED
&& (params[0] == HdmiCecKeycode.CEC_KEYCODE_VOLUME_DOWN
- || params[0] == HdmiCecKeycode.CEC_KEYCODE_VOLUME_UP
- || params[0] == HdmiCecKeycode.CEC_KEYCODE_MUTE
- || params[0] == HdmiCecKeycode.CEC_KEYCODE_MUTE_FUNCTION
- || params[0] == HdmiCecKeycode.CEC_KEYCODE_RESTORE_VOLUME_FUNCTION);
+ || params[0] == HdmiCecKeycode.CEC_KEYCODE_VOLUME_UP
+ || params[0] == HdmiCecKeycode.CEC_KEYCODE_MUTE
+ || params[0] == HdmiCecKeycode.CEC_KEYCODE_MUTE_FUNCTION
+ || params[0] == HdmiCecKeycode.CEC_KEYCODE_RESTORE_VOLUME_FUNCTION);
}
@Constants.HandleMessageResult
@@ -1243,13 +1250,13 @@ abstract class HdmiCecLocalDevice {
|| logicalAddress == mDeviceInfo.getLogicalAddress()) {
// Don't send key event to invalid device or itself.
Slog.w(
- TAG,
- "Discard volume key event: "
- + keyCode
- + ", pressed:"
- + isPressed
- + ", receiverAddr="
- + logicalAddress);
+ TAG,
+ "Discard volume key event: "
+ + keyCode
+ + ", pressed:"
+ + isPressed
+ + ", receiverAddr="
+ + logicalAddress);
} else if (!action.isEmpty()) {
action.get(0).processKeyEvent(keyCode, isPressed);
} else if (isPressed) {
diff --git a/services/core/java/com/android/server/hdmi/HdmiCecLocalDevicePlayback.java b/services/core/java/com/android/server/hdmi/HdmiCecLocalDevicePlayback.java
index 744436d41adb1..d6ac25a72a6e4 100644
--- a/services/core/java/com/android/server/hdmi/HdmiCecLocalDevicePlayback.java
+++ b/services/core/java/com/android/server/hdmi/HdmiCecLocalDevicePlayback.java
@@ -105,9 +105,42 @@ public class HdmiCecLocalDevicePlayback extends HdmiCecLocalDeviceSource {
}
});
}
+ launchDeviceDiscovery();
startQueuedActions();
}
+ @ServiceThreadOnly
+ private void launchDeviceDiscovery() {
+ assertRunOnServiceThread();
+ clearDeviceInfoList();
+ DeviceDiscoveryAction action = new DeviceDiscoveryAction(this,
+ new DeviceDiscoveryAction.DeviceDiscoveryCallback() {
+ @Override
+ public void onDeviceDiscoveryDone(List Check all devices every 15 secs except for system audio.
+ * TV checks all devices every 15 secs except for system audio.
* If system audio is on, check hot-plug for audio system every 5 secs.
* For other devices, keep 15 secs period.
+ *
+ * Playback devices check all devices every 1 minute.
*/
// Seq #3
final class HotplugDetectionAction extends HdmiCecFeatureAction {
private static final String TAG = "HotPlugDetectionAction";
- private static final int POLLING_INTERVAL_MS = 5000;
+ private static final int POLLING_INTERVAL_MS_FOR_TV = 5000;
+ public static final int POLLING_INTERVAL_MS_FOR_PLAYBACK = 60000;
private static final int TIMEOUT_COUNT = 3;
private static final int AVR_COUNT_MAX = 3;
@@ -55,6 +58,8 @@ final class HotplugDetectionAction extends HdmiCecFeatureAction {
// is detected {@code AVR_COUNT_MAX} times in a row.
private int mAvrStatusCount = 0;
+ private final boolean mIsTvDevice = localDevice().mService.isTvDevice();
+
/**
* Constructor
*
@@ -64,16 +69,21 @@ final class HotplugDetectionAction extends HdmiCecFeatureAction {
super(source);
}
+ private int getPollingInterval() {
+ return mIsTvDevice ? POLLING_INTERVAL_MS_FOR_TV : POLLING_INTERVAL_MS_FOR_PLAYBACK;
+ }
+
@Override
boolean start() {
- Slog.v(TAG, "Hot-plug dection started.");
+ Slog.v(TAG, "Hot-plug detection started.");
mState = STATE_WAIT_FOR_NEXT_POLLING;
mTimeoutCount = 0;
// Start timer without polling.
- // The first check for all devices will be initiated 15 seconds later.
- addTimer(mState, POLLING_INTERVAL_MS);
+ // The first check for all devices will be initiated 15 seconds later for TV panels and 60
+ // seconds later for playback devices.
+ addTimer(mState, getPollingInterval());
return true;
}
@@ -90,13 +100,24 @@ final class HotplugDetectionAction extends HdmiCecFeatureAction {
}
if (mState == STATE_WAIT_FOR_NEXT_POLLING) {
- mTimeoutCount = (mTimeoutCount + 1) % TIMEOUT_COUNT;
- pollDevices();
+ if (mIsTvDevice) {
+ mTimeoutCount = (mTimeoutCount + 1) % TIMEOUT_COUNT;
+ if (mTimeoutCount == 0) {
+ pollAllDevices();
+ } else if (tv().isSystemAudioActivated()) {
+ pollAudioSystem();
+ }
+ addTimer(mState, POLLING_INTERVAL_MS_FOR_TV);
+ return;
+ }
+ pollAllDevices();
+ addTimer(mState, POLLING_INTERVAL_MS_FOR_PLAYBACK);
}
}
/**
- * Start device polling immediately.
+ * Start device polling immediately. This method is called only by
+ * {@link HdmiCecLocalDeviceTv#onHotplug}.
*/
void pollAllDevicesNow() {
// Clear existing timer to avoid overlapped execution
@@ -106,21 +127,7 @@ final class HotplugDetectionAction extends HdmiCecFeatureAction {
mState = STATE_WAIT_FOR_NEXT_POLLING;
pollAllDevices();
- addTimer(mState, POLLING_INTERVAL_MS);
- }
-
- // This method is called every 5 seconds.
- private void pollDevices() {
- // All device check called every 15 seconds.
- if (mTimeoutCount == 0) {
- pollAllDevices();
- } else {
- if (tv().isSystemAudioActivated()) {
- pollAudioSystem();
- }
- }
-
- addTimer(mState, POLLING_INTERVAL_MS);
+ addTimer(mState, getPollingInterval());
}
private void pollAllDevices() {
@@ -156,7 +163,7 @@ final class HotplugDetectionAction extends HdmiCecFeatureAction {
BitSet removed = complement(currentInfos, polledResult);
int index = -1;
while ((index = removed.nextSetBit(index + 1)) != -1) {
- if (index == Constants.ADDR_AUDIO_SYSTEM) {
+ if (mIsTvDevice && index == Constants.ADDR_AUDIO_SYSTEM) {
HdmiDeviceInfo avr = tv().getAvrDeviceInfo();
if (avr != null && tv().isConnected(avr.getPortId())) {
++mAvrStatusCount;
@@ -221,11 +228,12 @@ final class HotplugDetectionAction extends HdmiCecFeatureAction {
}
private void removeDevice(int removedAddress) {
- mayChangeRoutingPath(removedAddress);
+ if (mIsTvDevice) {
+ mayChangeRoutingPath(removedAddress);
+ mayCancelOneTouchRecord(removedAddress);
+ mayDisableSystemAudioAndARC(removedAddress);
+ }
mayCancelDeviceSelect(removedAddress);
- mayCancelOneTouchRecord(removedAddress);
- mayDisableSystemAudioAndARC(removedAddress);
-
localDevice().mService.getHdmiCecNetwork().removeCecDevice(localDevice(), removedAddress);
}
@@ -237,15 +245,19 @@ final class HotplugDetectionAction extends HdmiCecFeatureAction {
}
private void mayCancelDeviceSelect(int address) {
- List