From 38feae971c43700c9cb15aafbf8bd37340675a50 Mon Sep 17 00:00:00 2001 From: Wonsik Kim Date: Mon, 21 Jul 2014 21:35:50 +0900 Subject: [PATCH] TIF: fix indexOfValue usage SparseArray.indexOfValue() was used in place where comparison using equals() on value was desired, but the method actually uses == instead of equals(). Change-Id: Id9fb3317d1e0f0cb60ce6512f6d0c0a7bcf2fb20 --- .../server/tv/TvInputHardwareManager.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/services/core/java/com/android/server/tv/TvInputHardwareManager.java b/services/core/java/com/android/server/tv/TvInputHardwareManager.java index 0a9c6465a44b9..885486948c2f8 100644 --- a/services/core/java/com/android/server/tv/TvInputHardwareManager.java +++ b/services/core/java/com/android/server/tv/TvInputHardwareManager.java @@ -235,14 +235,23 @@ class TvInputHardwareManager implements TvInputHal.Callback { } } + private static int indexOfEqualValue(SparseArray map, T value) { + for (int i = 0; i < map.size(); ++i) { + if (map.valueAt(i).equals(value)) { + return i; + } + } + return -1; + } + public void addHdmiCecTvInput(int logicalAddress, TvInputInfo info) { if (info.getType() != TvInputInfo.TYPE_HDMI) { throw new IllegalArgumentException("info (" + info + ") has non-HDMI type."); } synchronized (mLock) { String parentId = info.getParentId(); - int parentIndex = mHardwareInputIdMap.indexOfValue(parentId); - if (parentIndex < 0 || !parentId.equals(mHardwareInputIdMap.valueAt(parentIndex))) { + int parentIndex = indexOfEqualValue(mHardwareInputIdMap, parentId); + if (parentIndex < 0) { throw new IllegalArgumentException("info (" + info + ") has invalid parentId."); } String oldInputId = mHdmiCecInputIdMap.get(logicalAddress); @@ -259,11 +268,11 @@ class TvInputHardwareManager implements TvInputHal.Callback { public void removeTvInput(String inputId) { synchronized (mLock) { mInputMap.remove(inputId); - int hardwareIndex = mHardwareInputIdMap.indexOfValue(inputId); + int hardwareIndex = indexOfEqualValue(mHardwareInputIdMap, inputId); if (hardwareIndex >= 0) { mHardwareInputIdMap.removeAt(hardwareIndex); } - int cecIndex = mHdmiCecInputIdMap.indexOfValue(inputId); + int cecIndex = indexOfEqualValue(mHdmiCecInputIdMap, inputId); if (cecIndex >= 0) { mHdmiCecInputIdMap.removeAt(cecIndex); }