TIF: Clean the hardware input list when the input service is reconnected
Needed to avoid adding duplicate TvInputInfo objects when the hardware
TV input service is killed and reconnected.
Bug: 26503803
Change-Id: I9265219678cb8594d43dac561f1e69c21d9c2733
(cherry picked from commit 6657e292a57e600669b3102d27f69497c45f899d)
diff --git a/services/core/java/com/android/server/tv/TvInputManagerService.java b/services/core/java/com/android/server/tv/TvInputManagerService.java
index 55de061..c0b4e69 100644
--- a/services/core/java/com/android/server/tv/TvInputManagerService.java
+++ b/services/core/java/com/android/server/tv/TvInputManagerService.java
@@ -305,9 +305,8 @@
if (hasHardwarePermission(pm, component)) {
ServiceState serviceState = userState.serviceStateMap.get(component);
if (serviceState == null) {
- // We see this hardware TV input service for the first time; we need to
- // prepare the ServiceState object so that we can connect to the service and
- // let it add TvInputInfo objects to mInputList if there's any.
+ // New hardware input found. Create a new ServiceState and connect to the
+ // service to populate the hardware list.
serviceState = new ServiceState(component, userId);
userState.serviceStateMap.put(component, serviceState);
updateServiceConnectionLocked(component, userId);
@@ -2134,21 +2133,17 @@
}
if (serviceState.isHardware) {
- List<TvInputHardwareInfo> hardwareInfoList =
- mTvInputHardwareManager.getHardwareList();
- for (TvInputHardwareInfo hardwareInfo : hardwareInfoList) {
+ serviceState.hardwareInputList.clear();
+ for (TvInputHardwareInfo hardware : mTvInputHardwareManager.getHardwareList()) {
try {
- serviceState.service.notifyHardwareAdded(hardwareInfo);
+ serviceState.service.notifyHardwareAdded(hardware);
} catch (RemoteException e) {
Slog.e(TAG, "error in notifyHardwareAdded", e);
}
}
-
- List<HdmiDeviceInfo> deviceInfoList =
- mTvInputHardwareManager.getHdmiDeviceList();
- for (HdmiDeviceInfo deviceInfo : deviceInfoList) {
+ for (HdmiDeviceInfo device : mTvInputHardwareManager.getHdmiDeviceList()) {
try {
- serviceState.service.notifyHdmiDeviceAdded(deviceInfo);
+ serviceState.service.notifyHdmiDeviceAdded(device);
} catch (RemoteException e) {
Slog.e(TAG, "error in notifyHdmiDeviceAdded", e);
}