Loading services/core/java/com/android/server/hdmi/DeviceDiscoveryAction.java +7 −2 Original line number Diff line number Diff line Loading @@ -140,7 +140,13 @@ final class DeviceDiscoveryAction extends HdmiCecFeatureAction { wrapUpAndFinish(); return; } // Check if the action was finished before the callback was called. // See {@link HdmiCecFeatureAction#finish}. if (mState == STATE_NONE) { Slog.v(TAG, "Action was already finished before the callback was called."); wrapUpAndFinish(); return; } Slog.v(TAG, "Device detected: " + ackedAddress); allocateDevices(ackedAddress); if (mDelayPeriod > 0) { Loading Loading @@ -453,7 +459,6 @@ final class DeviceDiscoveryAction extends HdmiCecFeatureAction { wrapUpAndFinish(); return; } // If finished current stage, move on to next stage. if (mProcessedDeviceCount == mDevices.size()) { mProcessedDeviceCount = 0; Loading services/core/java/com/android/server/hdmi/HdmiCecController.java +15 −1 Original line number Diff line number Diff line Loading @@ -160,6 +160,9 @@ final class HdmiCecController { // This variable is used for testing, in order to delay the logical address allocation. private long mLogicalAddressAllocationDelay = 0; // This variable is used for testing, in order to delay polling devices. private long mPollDevicesDelay = 0; // Private constructor. Use HdmiCecController.create(). private HdmiCecController( HdmiControlService service, NativeWrapper nativeWrapper, HdmiCecAtomWriter atomWriter) { Loading Loading @@ -462,6 +465,14 @@ final class HdmiCecController { mLogicalAddressAllocationDelay = delay; } /** * This method is used for testing, in order to delay polling devices. */ @VisibleForTesting void setPollDevicesDelay(long delay) { mPollDevicesDelay = delay; } /** * Returns true if the language code is well-formed. */ Loading Loading @@ -523,7 +534,10 @@ final class HdmiCecController { // Extract polling candidates. No need to poll against local devices. List<Integer> pollingCandidates = pickPollCandidates(pickStrategy); ArrayList<Integer> allocated = new ArrayList<>(); runDevicePolling(sourceAddress, pollingCandidates, retryCount, callback, allocated); mControlHandler.postDelayed( () -> runDevicePolling( sourceAddress, pollingCandidates, retryCount, callback, allocated), mPollDevicesDelay); } private List<Integer> pickPollCandidates(int pickStrategy) { Loading services/tests/servicestests/src/com/android/server/hdmi/HdmiCecLocalDevicePlaybackTest.java +13 −0 Original line number Diff line number Diff line Loading @@ -1775,6 +1775,11 @@ public class HdmiCecLocalDevicePlaybackTest { @Test public void wakeUp_hotPlugIn_invokesDeviceDiscoveryOnce() { // There might be a leftover HotplugDetectionAction that can interfere with the test. mHdmiCecLocalDevicePlayback.removeAction(HotplugDetectionAction.class); long pollingDelay = TimeUnit.SECONDS.toMillis(60); mHdmiCecController.setPollDevicesDelay(pollingDelay); mNativeWrapper.setPollAddressResponse(Constants.ADDR_PLAYBACK_2, SendMessageResult.SUCCESS); mHdmiControlService.onWakeUp(HdmiControlService.WAKE_UP_SCREEN_ON); mTestLooper.dispatchAll(); Loading @@ -1783,6 +1788,14 @@ public class HdmiCecLocalDevicePlaybackTest { mTestLooper.dispatchAll(); assertThat(mHdmiCecLocalDevicePlayback.getActions(DeviceDiscoveryAction.class)).hasSize(1); mTestLooper.moveTimeForward(pollingDelay); mTestLooper.dispatchAll(); HdmiCecMessage givePhysicalAddress = HdmiCecMessageBuilder.buildGivePhysicalAddress( Constants.ADDR_PLAYBACK_1, Constants.ADDR_PLAYBACK_2); assertThat(mNativeWrapper.getResultMessages().stream() .filter(message -> message.equals(givePhysicalAddress)).count()).isEqualTo(1); } @Test Loading Loading
services/core/java/com/android/server/hdmi/DeviceDiscoveryAction.java +7 −2 Original line number Diff line number Diff line Loading @@ -140,7 +140,13 @@ final class DeviceDiscoveryAction extends HdmiCecFeatureAction { wrapUpAndFinish(); return; } // Check if the action was finished before the callback was called. // See {@link HdmiCecFeatureAction#finish}. if (mState == STATE_NONE) { Slog.v(TAG, "Action was already finished before the callback was called."); wrapUpAndFinish(); return; } Slog.v(TAG, "Device detected: " + ackedAddress); allocateDevices(ackedAddress); if (mDelayPeriod > 0) { Loading Loading @@ -453,7 +459,6 @@ final class DeviceDiscoveryAction extends HdmiCecFeatureAction { wrapUpAndFinish(); return; } // If finished current stage, move on to next stage. if (mProcessedDeviceCount == mDevices.size()) { mProcessedDeviceCount = 0; Loading
services/core/java/com/android/server/hdmi/HdmiCecController.java +15 −1 Original line number Diff line number Diff line Loading @@ -160,6 +160,9 @@ final class HdmiCecController { // This variable is used for testing, in order to delay the logical address allocation. private long mLogicalAddressAllocationDelay = 0; // This variable is used for testing, in order to delay polling devices. private long mPollDevicesDelay = 0; // Private constructor. Use HdmiCecController.create(). private HdmiCecController( HdmiControlService service, NativeWrapper nativeWrapper, HdmiCecAtomWriter atomWriter) { Loading Loading @@ -462,6 +465,14 @@ final class HdmiCecController { mLogicalAddressAllocationDelay = delay; } /** * This method is used for testing, in order to delay polling devices. */ @VisibleForTesting void setPollDevicesDelay(long delay) { mPollDevicesDelay = delay; } /** * Returns true if the language code is well-formed. */ Loading Loading @@ -523,7 +534,10 @@ final class HdmiCecController { // Extract polling candidates. No need to poll against local devices. List<Integer> pollingCandidates = pickPollCandidates(pickStrategy); ArrayList<Integer> allocated = new ArrayList<>(); runDevicePolling(sourceAddress, pollingCandidates, retryCount, callback, allocated); mControlHandler.postDelayed( () -> runDevicePolling( sourceAddress, pollingCandidates, retryCount, callback, allocated), mPollDevicesDelay); } private List<Integer> pickPollCandidates(int pickStrategy) { Loading
services/tests/servicestests/src/com/android/server/hdmi/HdmiCecLocalDevicePlaybackTest.java +13 −0 Original line number Diff line number Diff line Loading @@ -1775,6 +1775,11 @@ public class HdmiCecLocalDevicePlaybackTest { @Test public void wakeUp_hotPlugIn_invokesDeviceDiscoveryOnce() { // There might be a leftover HotplugDetectionAction that can interfere with the test. mHdmiCecLocalDevicePlayback.removeAction(HotplugDetectionAction.class); long pollingDelay = TimeUnit.SECONDS.toMillis(60); mHdmiCecController.setPollDevicesDelay(pollingDelay); mNativeWrapper.setPollAddressResponse(Constants.ADDR_PLAYBACK_2, SendMessageResult.SUCCESS); mHdmiControlService.onWakeUp(HdmiControlService.WAKE_UP_SCREEN_ON); mTestLooper.dispatchAll(); Loading @@ -1783,6 +1788,14 @@ public class HdmiCecLocalDevicePlaybackTest { mTestLooper.dispatchAll(); assertThat(mHdmiCecLocalDevicePlayback.getActions(DeviceDiscoveryAction.class)).hasSize(1); mTestLooper.moveTimeForward(pollingDelay); mTestLooper.dispatchAll(); HdmiCecMessage givePhysicalAddress = HdmiCecMessageBuilder.buildGivePhysicalAddress( Constants.ADDR_PLAYBACK_1, Constants.ADDR_PLAYBACK_2); assertThat(mNativeWrapper.getResultMessages().stream() .filter(message -> message.equals(givePhysicalAddress)).count()).isEqualTo(1); } @Test Loading