Loading services/core/java/com/android/server/hdmi/DeviceDiscoveryAction.java +25 −13 Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ import java.util.List; * <li>Gather "OSD (display) name" of all acknowledge devices * <li>Gather "Vendor id" of all acknowledge devices * </ol> * We attempt to get OSD name/vendor ID up to 5 times in case the communication fails. */ final class DeviceDiscoveryAction extends HdmiCecFeatureAction { private static final String TAG = "DeviceDiscoveryAction"; Loading Loading @@ -87,6 +88,7 @@ final class DeviceDiscoveryAction extends HdmiCecFeatureAction { private final ArrayList<DeviceInfo> mDevices = new ArrayList<>(); private final DeviceDiscoveryCallback mCallback; private int mProcessedDeviceCount = 0; private int mTimeoutRetry = 0; /** * Constructor. Loading Loading @@ -309,6 +311,7 @@ final class DeviceDiscoveryAction extends HdmiCecFeatureAction { private void increaseProcessedDeviceCount() { mProcessedDeviceCount++; mTimeoutRetry = 0; } private void removeDevice(int index) { Loading Loading @@ -353,6 +356,11 @@ final class DeviceDiscoveryAction extends HdmiCecFeatureAction { return; } } else { sendQueryCommand(); } } private void sendQueryCommand() { int address = mDevices.get(mProcessedDeviceCount).mLogicalAddress; switch (mState) { case STATE_WAITING_FOR_PHYSICAL_ADDRESS: Loading @@ -367,7 +375,6 @@ final class DeviceDiscoveryAction extends HdmiCecFeatureAction { return; } } } @Override void handleTimerEvent(int state) { Loading @@ -375,6 +382,11 @@ final class DeviceDiscoveryAction extends HdmiCecFeatureAction { return; } if (++mTimeoutRetry < HdmiConfig.TIMEOUT_RETRY) { sendQueryCommand(); return; } mTimeoutRetry = 0; Slog.v(TAG, "Timeout[State=" + mState + ", Processed=" + mProcessedDeviceCount); removeDevice(mProcessedDeviceCount); checkAndProceedStage(); Loading services/core/java/com/android/server/hdmi/HdmiConfig.java +4 −0 Original line number Diff line number Diff line Loading @@ -39,6 +39,10 @@ final class HdmiConfig { // Number of retries for polling each device in address allocation mechanism. static final int ADDRESS_ALLOCATION_RETRY = 3; // Number of retries for sendCommand in actions related to new device discovery. // Number 5 comes from 10 seconds for Chromecast preparation time. static final int TIMEOUT_RETRY = 5; // CEC spec said that it should try retransmission at least once. // The actual number of send request for a single command will be at most // RETRANSMISSION_COUNT + 1. Note that it affects only to normal commands Loading services/core/java/com/android/server/hdmi/NewDeviceAction.java +25 −6 Original line number Diff line number Diff line Loading @@ -51,6 +51,7 @@ final class NewDeviceAction extends HdmiCecFeatureAction { private int mVendorId; private String mDisplayName; private int mTimeoutRetry; /** * Constructor. Loading @@ -71,15 +72,22 @@ final class NewDeviceAction extends HdmiCecFeatureAction { @Override public boolean start() { requestOsdName(true); return true; } private void requestOsdName(boolean firstTry) { if (firstTry) { mTimeoutRetry = 0; } mState = STATE_WAITING_FOR_SET_OSD_NAME; if (mayProcessCommandIfCached(mDeviceLogicalAddress, Constants.MESSAGE_SET_OSD_NAME)) { return true; return; } sendCommand(HdmiCecMessageBuilder.buildGiveOsdNameCommand(getSourceAddress(), mDeviceLogicalAddress)); addTimer(mState, HdmiConfig.TIMEOUT_MS); return true; } @Override Loading @@ -103,12 +111,12 @@ final class NewDeviceAction extends HdmiCecFeatureAction { } catch (UnsupportedEncodingException e) { Slog.e(TAG, "Failed to get OSD name: " + e.getMessage()); } requestVendorId(); requestVendorId(true); return true; } else if (opcode == Constants.MESSAGE_FEATURE_ABORT) { int requestOpcode = params[0] & 0xFF; if (requestOpcode == Constants.MESSAGE_GIVE_OSD_NAME) { requestVendorId(); requestVendorId(true); return true; } } Loading Loading @@ -138,7 +146,10 @@ final class NewDeviceAction extends HdmiCecFeatureAction { return false; } private void requestVendorId() { private void requestVendorId(boolean firstTry) { if (firstTry) { mTimeoutRetry = 0; } // At first, transit to waiting status for <Device Vendor Id>. mState = STATE_WAITING_FOR_DEVICE_VENDOR_ID; // If the message is already in cache, process it. Loading Loading @@ -176,9 +187,17 @@ final class NewDeviceAction extends HdmiCecFeatureAction { return; } if (state == STATE_WAITING_FOR_SET_OSD_NAME) { if (++mTimeoutRetry < HdmiConfig.TIMEOUT_RETRY) { requestOsdName(false); return; } // Osd name request timed out. Try vendor id requestVendorId(); requestVendorId(true); } else if (state == STATE_WAITING_FOR_DEVICE_VENDOR_ID) { if (++mTimeoutRetry < HdmiConfig.TIMEOUT_RETRY) { requestVendorId(false); return; } // vendor id timed out. Go ahead creating the device info what we've got so far. addDeviceInfo(); finish(); Loading Loading
services/core/java/com/android/server/hdmi/DeviceDiscoveryAction.java +25 −13 Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ import java.util.List; * <li>Gather "OSD (display) name" of all acknowledge devices * <li>Gather "Vendor id" of all acknowledge devices * </ol> * We attempt to get OSD name/vendor ID up to 5 times in case the communication fails. */ final class DeviceDiscoveryAction extends HdmiCecFeatureAction { private static final String TAG = "DeviceDiscoveryAction"; Loading Loading @@ -87,6 +88,7 @@ final class DeviceDiscoveryAction extends HdmiCecFeatureAction { private final ArrayList<DeviceInfo> mDevices = new ArrayList<>(); private final DeviceDiscoveryCallback mCallback; private int mProcessedDeviceCount = 0; private int mTimeoutRetry = 0; /** * Constructor. Loading Loading @@ -309,6 +311,7 @@ final class DeviceDiscoveryAction extends HdmiCecFeatureAction { private void increaseProcessedDeviceCount() { mProcessedDeviceCount++; mTimeoutRetry = 0; } private void removeDevice(int index) { Loading Loading @@ -353,6 +356,11 @@ final class DeviceDiscoveryAction extends HdmiCecFeatureAction { return; } } else { sendQueryCommand(); } } private void sendQueryCommand() { int address = mDevices.get(mProcessedDeviceCount).mLogicalAddress; switch (mState) { case STATE_WAITING_FOR_PHYSICAL_ADDRESS: Loading @@ -367,7 +375,6 @@ final class DeviceDiscoveryAction extends HdmiCecFeatureAction { return; } } } @Override void handleTimerEvent(int state) { Loading @@ -375,6 +382,11 @@ final class DeviceDiscoveryAction extends HdmiCecFeatureAction { return; } if (++mTimeoutRetry < HdmiConfig.TIMEOUT_RETRY) { sendQueryCommand(); return; } mTimeoutRetry = 0; Slog.v(TAG, "Timeout[State=" + mState + ", Processed=" + mProcessedDeviceCount); removeDevice(mProcessedDeviceCount); checkAndProceedStage(); Loading
services/core/java/com/android/server/hdmi/HdmiConfig.java +4 −0 Original line number Diff line number Diff line Loading @@ -39,6 +39,10 @@ final class HdmiConfig { // Number of retries for polling each device in address allocation mechanism. static final int ADDRESS_ALLOCATION_RETRY = 3; // Number of retries for sendCommand in actions related to new device discovery. // Number 5 comes from 10 seconds for Chromecast preparation time. static final int TIMEOUT_RETRY = 5; // CEC spec said that it should try retransmission at least once. // The actual number of send request for a single command will be at most // RETRANSMISSION_COUNT + 1. Note that it affects only to normal commands Loading
services/core/java/com/android/server/hdmi/NewDeviceAction.java +25 −6 Original line number Diff line number Diff line Loading @@ -51,6 +51,7 @@ final class NewDeviceAction extends HdmiCecFeatureAction { private int mVendorId; private String mDisplayName; private int mTimeoutRetry; /** * Constructor. Loading @@ -71,15 +72,22 @@ final class NewDeviceAction extends HdmiCecFeatureAction { @Override public boolean start() { requestOsdName(true); return true; } private void requestOsdName(boolean firstTry) { if (firstTry) { mTimeoutRetry = 0; } mState = STATE_WAITING_FOR_SET_OSD_NAME; if (mayProcessCommandIfCached(mDeviceLogicalAddress, Constants.MESSAGE_SET_OSD_NAME)) { return true; return; } sendCommand(HdmiCecMessageBuilder.buildGiveOsdNameCommand(getSourceAddress(), mDeviceLogicalAddress)); addTimer(mState, HdmiConfig.TIMEOUT_MS); return true; } @Override Loading @@ -103,12 +111,12 @@ final class NewDeviceAction extends HdmiCecFeatureAction { } catch (UnsupportedEncodingException e) { Slog.e(TAG, "Failed to get OSD name: " + e.getMessage()); } requestVendorId(); requestVendorId(true); return true; } else if (opcode == Constants.MESSAGE_FEATURE_ABORT) { int requestOpcode = params[0] & 0xFF; if (requestOpcode == Constants.MESSAGE_GIVE_OSD_NAME) { requestVendorId(); requestVendorId(true); return true; } } Loading Loading @@ -138,7 +146,10 @@ final class NewDeviceAction extends HdmiCecFeatureAction { return false; } private void requestVendorId() { private void requestVendorId(boolean firstTry) { if (firstTry) { mTimeoutRetry = 0; } // At first, transit to waiting status for <Device Vendor Id>. mState = STATE_WAITING_FOR_DEVICE_VENDOR_ID; // If the message is already in cache, process it. Loading Loading @@ -176,9 +187,17 @@ final class NewDeviceAction extends HdmiCecFeatureAction { return; } if (state == STATE_WAITING_FOR_SET_OSD_NAME) { if (++mTimeoutRetry < HdmiConfig.TIMEOUT_RETRY) { requestOsdName(false); return; } // Osd name request timed out. Try vendor id requestVendorId(); requestVendorId(true); } else if (state == STATE_WAITING_FOR_DEVICE_VENDOR_ID) { if (++mTimeoutRetry < HdmiConfig.TIMEOUT_RETRY) { requestVendorId(false); return; } // vendor id timed out. Go ahead creating the device info what we've got so far. addDeviceInfo(); finish(); Loading