diff options
6 files changed, 58 insertions, 35 deletions
diff --git a/services/core/java/com/android/server/hdmi/HdmiCecController.java b/services/core/java/com/android/server/hdmi/HdmiCecController.java index a79fb88ea8b6..f6dfc9ea76d7 100644 --- a/services/core/java/com/android/server/hdmi/HdmiCecController.java +++ b/services/core/java/com/android/server/hdmi/HdmiCecController.java @@ -528,15 +528,17 @@ final class HdmiCecController { */ @ServiceThreadOnly void pollDevices(DevicePollingCallback callback, int sourceAddress, int pickStrategy, - int retryCount) { + int retryCount, long pollingMessageInterval) { assertRunOnServiceThread(); // Extract polling candidates. No need to poll against local devices. List<Integer> pollingCandidates = pickPollCandidates(pickStrategy); ArrayList<Integer> allocated = new ArrayList<>(); + // pollStarted indication to avoid polling delay for the first message mControlHandler.postDelayed( - () -> runDevicePolling( - sourceAddress, pollingCandidates, retryCount, callback, allocated), + () + -> runDevicePolling(sourceAddress, pollingCandidates, retryCount, callback, + allocated, pollingMessageInterval, /**pollStarted**/ false), mPollDevicesDelay); } @@ -576,9 +578,10 @@ final class HdmiCecController { } @ServiceThreadOnly - private void runDevicePolling(final int sourceAddress, - final List<Integer> candidates, final int retryCount, - final DevicePollingCallback callback, final List<Integer> allocated) { + private void runDevicePolling(final int sourceAddress, final List<Integer> candidates, + final int retryCount, final DevicePollingCallback callback, + final List<Integer> allocated, final long pollingMessageInterval, + final boolean pollStarted) { assertRunOnServiceThread(); if (candidates.isEmpty()) { if (callback != null) { @@ -587,11 +590,10 @@ final class HdmiCecController { } return; } - final Integer candidate = candidates.remove(0); // Proceed polling action for the next address once polling action for the // previous address is done. - runOnIoThread(new Runnable() { + mIoHandler.postDelayed(new Runnable() { @Override public void run() { if (sendPollMessage(sourceAddress, candidate, retryCount)) { @@ -600,12 +602,12 @@ final class HdmiCecController { runOnServiceThread(new Runnable() { @Override public void run() { - runDevicePolling(sourceAddress, candidates, retryCount, callback, - allocated); + runDevicePolling(sourceAddress, candidates, retryCount, callback, allocated, + pollingMessageInterval, /**pollStarted**/ true); } }); } - }); + }, pollStarted ? pollingMessageInterval : 0); } @IoThreadOnly diff --git a/services/core/java/com/android/server/hdmi/HdmiCecFeatureAction.java b/services/core/java/com/android/server/hdmi/HdmiCecFeatureAction.java index 5db114b9c2eb..234d6d323838 100644 --- a/services/core/java/com/android/server/hdmi/HdmiCecFeatureAction.java +++ b/services/core/java/com/android/server/hdmi/HdmiCecFeatureAction.java @@ -229,7 +229,13 @@ abstract class HdmiCecFeatureAction { protected final void pollDevices(DevicePollingCallback callback, int pickStrategy, int retryCount) { - mService.pollDevices(callback, getSourceAddress(), pickStrategy, retryCount); + pollDevices(callback, pickStrategy, retryCount, 0); + } + + protected final void pollDevices(DevicePollingCallback callback, int pickStrategy, + int retryCount, long pollingMessageInterval) { + mService.pollDevices( + callback, getSourceAddress(), pickStrategy, retryCount, pollingMessageInterval); } /** diff --git a/services/core/java/com/android/server/hdmi/HdmiControlService.java b/services/core/java/com/android/server/hdmi/HdmiControlService.java index d0532b995deb..91e35e9960e1 100644 --- a/services/core/java/com/android/server/hdmi/HdmiControlService.java +++ b/services/core/java/com/android/server/hdmi/HdmiControlService.java @@ -1823,10 +1823,10 @@ public class HdmiControlService extends SystemService { */ @ServiceThreadOnly void pollDevices(DevicePollingCallback callback, int sourceAddress, int pickStrategy, - int retryCount) { + int retryCount, long pollingMessageInterval) { assertRunOnServiceThread(); mCecController.pollDevices(callback, sourceAddress, checkPollStrategy(pickStrategy), - retryCount); + retryCount, pollingMessageInterval); } private int checkPollStrategy(int pickStrategy) { diff --git a/services/core/java/com/android/server/hdmi/HotplugDetectionAction.java b/services/core/java/com/android/server/hdmi/HotplugDetectionAction.java index da40ce5954e9..30842b24fc50 100644 --- a/services/core/java/com/android/server/hdmi/HotplugDetectionAction.java +++ b/services/core/java/com/android/server/hdmi/HotplugDetectionAction.java @@ -38,8 +38,10 @@ import java.util.List; final class HotplugDetectionAction extends HdmiCecFeatureAction { private static final String TAG = "HotPlugDetectionAction"; - public static final int POLLING_INTERVAL_MS_FOR_TV = 5000; - public static final int POLLING_INTERVAL_MS_FOR_PLAYBACK = 60000; + public static final long POLLING_MESSAGE_INTERVAL_MS_FOR_TV = 0; + public static final long POLLING_MESSAGE_INTERVAL_MS_FOR_PLAYBACK = 500; + public static final int POLLING_BATCH_INTERVAL_MS_FOR_TV = 5000; + public static final int POLLING_BATCH_INTERVAL_MS_FOR_PLAYBACK = 60000; public static final int TIMEOUT_COUNT = 3; private static final int AVR_COUNT_MAX = 3; @@ -69,8 +71,9 @@ final class HotplugDetectionAction extends HdmiCecFeatureAction { super(source); } - private int getPollingInterval() { - return mIsTvDevice ? POLLING_INTERVAL_MS_FOR_TV : POLLING_INTERVAL_MS_FOR_PLAYBACK; + private int getPollingBatchInterval() { + return mIsTvDevice ? POLLING_BATCH_INTERVAL_MS_FOR_TV + : POLLING_BATCH_INTERVAL_MS_FOR_PLAYBACK; } @Override @@ -83,7 +86,7 @@ final class HotplugDetectionAction extends HdmiCecFeatureAction { // Start timer without polling. // 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()); + addTimer(mState, getPollingBatchInterval()); return true; } @@ -107,11 +110,11 @@ final class HotplugDetectionAction extends HdmiCecFeatureAction { } else if (tv().isSystemAudioActivated()) { pollAudioSystem(); } - addTimer(mState, POLLING_INTERVAL_MS_FOR_TV); + addTimer(mState, POLLING_BATCH_INTERVAL_MS_FOR_TV); return; } pollAllDevices(); - addTimer(mState, POLLING_INTERVAL_MS_FOR_PLAYBACK); + addTimer(mState, POLLING_BATCH_INTERVAL_MS_FOR_PLAYBACK); } } @@ -127,19 +130,24 @@ final class HotplugDetectionAction extends HdmiCecFeatureAction { mState = STATE_WAIT_FOR_NEXT_POLLING; pollAllDevices(); - addTimer(mState, getPollingInterval()); + addTimer(mState, getPollingBatchInterval()); } private void pollAllDevices() { Slog.v(TAG, "Poll all devices."); - pollDevices(new DevicePollingCallback() { - @Override - public void onPollingFinished(List<Integer> ackedAddress) { - checkHotplug(ackedAddress, false); - } - }, Constants.POLL_ITERATION_IN_ORDER - | Constants.POLL_STRATEGY_REMOTES_DEVICES, HdmiConfig.HOTPLUG_DETECTION_RETRY); + pollDevices( + new DevicePollingCallback() { + @Override + public void onPollingFinished(List<Integer> ackedAddress) { + checkHotplug(ackedAddress, false); + Slog.v(TAG, "Finish poll all devices."); + } + }, + Constants.POLL_ITERATION_IN_ORDER | Constants.POLL_STRATEGY_REMOTES_DEVICES, + HdmiConfig.HOTPLUG_DETECTION_RETRY, + mIsTvDevice ? POLLING_MESSAGE_INTERVAL_MS_FOR_TV + : POLLING_MESSAGE_INTERVAL_MS_FOR_PLAYBACK); } private void pollAudioSystem() { diff --git a/services/tests/servicestests/src/com/android/server/hdmi/HdmiCecLocalDevicePlaybackTest.java b/services/tests/servicestests/src/com/android/server/hdmi/HdmiCecLocalDevicePlaybackTest.java index 1bd6e29a7f21..b7175bc8c9ff 100644 --- a/services/tests/servicestests/src/com/android/server/hdmi/HdmiCecLocalDevicePlaybackTest.java +++ b/services/tests/servicestests/src/com/android/server/hdmi/HdmiCecLocalDevicePlaybackTest.java @@ -58,7 +58,9 @@ import java.util.concurrent.TimeUnit; public class HdmiCecLocalDevicePlaybackTest { private static final int TIMEOUT_MS = HdmiConfig.TIMEOUT_MS + 1; private static final int HOTPLUG_INTERVAL = - HotplugDetectionAction.POLLING_INTERVAL_MS_FOR_PLAYBACK; + HotplugDetectionAction.POLLING_BATCH_INTERVAL_MS_FOR_PLAYBACK; + private static final long POLLING_DELAY = + HotplugDetectionAction.POLLING_MESSAGE_INTERVAL_MS_FOR_PLAYBACK; private static final int PORT_1 = 1; private static final HdmiDeviceInfo INFO_TV = HdmiDeviceInfo.cecDeviceBuilder() @@ -1867,9 +1869,14 @@ public class HdmiCecLocalDevicePlaybackTest { mNativeWrapper.setPollAddressResponse(otherPlaybackLogicalAddress, SendMessageResult.SUCCESS); + // Moving forward to skip hotplug interval for polling to start mTestLooper.moveTimeForward(HOTPLUG_INTERVAL); mTestLooper.dispatchAll(); - + // Skipping each polling delay and dispatch each polling message + for (int i = 0; i < 14; i++) { + mTestLooper.moveTimeForward(POLLING_DELAY); + mTestLooper.dispatchAll(); + } // Check for <Give Physical Address> being sent to the newly discovered device. // This message is sent as part of the HotplugDetectionAction to available devices. HdmiCecMessage givePhysicalAddress = HdmiCecMessageBuilder.buildGivePhysicalAddress( diff --git a/services/tests/servicestests/src/com/android/server/hdmi/HdmiCecLocalDeviceTvTest.java b/services/tests/servicestests/src/com/android/server/hdmi/HdmiCecLocalDeviceTvTest.java index 67ae9984266f..902ffed50d94 100644 --- a/services/tests/servicestests/src/com/android/server/hdmi/HdmiCecLocalDeviceTvTest.java +++ b/services/tests/servicestests/src/com/android/server/hdmi/HdmiCecLocalDeviceTvTest.java @@ -829,8 +829,8 @@ public class HdmiCecLocalDeviceTvTest { // Playback 1 begins ACKing polls, allowing detection by HotplugDetectionAction mNativeWrapper.setPollAddressResponse(ADDR_PLAYBACK_1, SendMessageResult.SUCCESS); for (int pollCount = 0; pollCount < HotplugDetectionAction.TIMEOUT_COUNT; pollCount++) { - mTestLooper.moveTimeForward( - TimeUnit.SECONDS.toMillis(HotplugDetectionAction.POLLING_INTERVAL_MS_FOR_TV)); + mTestLooper.moveTimeForward(TimeUnit.SECONDS.toMillis( + HotplugDetectionAction.POLLING_BATCH_INTERVAL_MS_FOR_TV)); mTestLooper.dispatchAll(); } @@ -872,7 +872,7 @@ public class HdmiCecLocalDeviceTvTest { // Assert that this device is removed from the list of devices. mNativeWrapper.setPollAddressResponse(Constants.ADDR_PLAYBACK_2, SendMessageResult.NACK); for (int pollCount = 0; pollCount < HotplugDetectionAction.TIMEOUT_COUNT; pollCount++) { - mTestLooper.moveTimeForward(HotplugDetectionAction.POLLING_INTERVAL_MS_FOR_TV); + mTestLooper.moveTimeForward(HotplugDetectionAction.POLLING_BATCH_INTERVAL_MS_FOR_TV); mTestLooper.dispatchAll(); } @@ -920,7 +920,7 @@ public class HdmiCecLocalDeviceTvTest { // Assert that this device is removed from the list of devices. mNativeWrapper.setPollAddressResponse(ADDR_AUDIO_SYSTEM, SendMessageResult.NACK); for (int pollCount = 0; pollCount < HotplugDetectionAction.TIMEOUT_COUNT; pollCount++) { - mTestLooper.moveTimeForward(HotplugDetectionAction.POLLING_INTERVAL_MS_FOR_TV); + mTestLooper.moveTimeForward(HotplugDetectionAction.POLLING_BATCH_INTERVAL_MS_FOR_TV); mTestLooper.dispatchAll(); } |