diff options
| author | 2023-04-24 15:58:52 -0700 | |
|---|---|---|
| committer | 2023-04-26 01:18:43 +0000 | |
| commit | bdcd9257765ba26a09d23b7ceacd88e39571f9b3 (patch) | |
| tree | fe703831aee4e735acfedefb2fe8fc12ab0a461c | |
| parent | fa88b4502d92563c0a1a5444c044ba9248ed4fb1 (diff) | |
Fix connection enumeration not accounting for discontinuous IDs
The data structure that contains mConnections is a sparse array. This means that you are allowed to insert devices with unique input IDs that are not continuous. However, when trying to perform the search for a specific input ID, the current logic assumes that the IDs are numerically continuous, causing issues (see ag/22753602).
Bug: 278628657
Test: atest TvInputService
Change-Id: I0311ac994feca73e4216744a49f1731c8e353ca1
| -rwxr-xr-x | services/core/java/com/android/server/tv/TvInputHardwareManager.java | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/services/core/java/com/android/server/tv/TvInputHardwareManager.java b/services/core/java/com/android/server/tv/TvInputHardwareManager.java index 98dfb009e4ef..3cb183fe07e2 100755 --- a/services/core/java/com/android/server/tv/TvInputHardwareManager.java +++ b/services/core/java/com/android/server/tv/TvInputHardwareManager.java @@ -459,9 +459,11 @@ class TvInputHardwareManager implements TvInputHal.Callback { private int findDeviceIdForInputIdLocked(String inputId) { for (int i = 0; i < mConnections.size(); ++i) { - Connection connection = mConnections.get(i); - if (connection.getInfoLocked().getId().equals(inputId)) { - return i; + int key = mConnections.keyAt(i); + Connection connection = mConnections.get(key); + if (connection != null && connection.getInfoLocked() != null + && connection.getInfoLocked().getId().equals(inputId)) { + return key; } } return -1; |