From 9cc28e5175e1391646b29469d329c9c1c9311ee1 Mon Sep 17 00:00:00 2001 From: Jae Seo Date: Tue, 12 Aug 2014 16:45:58 -0700 Subject: [PATCH] TIF: Create TvInputState only once per each input Also removed mClientTokens which is no longer used. Bug: 16970763 Change-Id: I4fc276241c33f88ed932ce6c703bdb3f771eb7d4 --- .../android/server/tv/TvInputManagerService.java | 74 +++++++++------------- 1 file changed, 31 insertions(+), 43 deletions(-) diff --git a/services/core/java/com/android/server/tv/TvInputManagerService.java b/services/core/java/com/android/server/tv/TvInputManagerService.java index 0b39598a3721..2de305e48454 100644 --- a/services/core/java/com/android/server/tv/TvInputManagerService.java +++ b/services/core/java/com/android/server/tv/TvInputManagerService.java @@ -212,8 +212,6 @@ public final class TvInputManagerService extends SystemService { private void buildTvInputListLocked(int userId) { UserState userState = getUserStateLocked(userId); - - Map inputMap = new HashMap(); userState.packageSet.clear(); if (DEBUG) Slog.d(TAG, "buildTvInputList"); @@ -229,41 +227,42 @@ public final class TvInputManagerService extends SystemService { + android.Manifest.permission.BIND_TV_INPUT); continue; } - try { - inputList.clear(); - ComponentName component = new ComponentName(si.packageName, si.name); - 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. - serviceState = new ServiceState(component, userId); - userState.serviceStateMap.put(component, serviceState); - } else { - inputList.addAll(serviceState.mInputList); - } + + ComponentName component = new ComponentName(si.packageName, si.name); + 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. + serviceState = new ServiceState(component, userId); + userState.serviceStateMap.put(component, serviceState); } else { - inputList.add(TvInputInfo.createTvInputInfo(mContext, ri)); + inputList.addAll(serviceState.mInputList); } - - for (TvInputInfo info : inputList) { - if (DEBUG) Slog.d(TAG, "add " + info.getId()); - TvInputState state = userState.inputMap.get(info.getId()); - if (state == null) { - state = new TvInputState(); - } - state.mInfo = info; - inputMap.put(info.getId(), state); + } else { + try { + inputList.add(TvInputInfo.createTvInputInfo(mContext, ri)); + } catch (XmlPullParserException | IOException e) { + Slog.e(TAG, "Failed to load TV input " + si.name, e); + continue; } + } - // Reconnect the service if existing input is updated. - updateServiceConnectionLocked(component, userId); + // Reconnect the service if existing input is updated. + updateServiceConnectionLocked(component, userId); + userState.packageSet.add(si.packageName); + } - userState.packageSet.add(si.packageName); - } catch (IOException | XmlPullParserException e) { - Slog.e(TAG, "Can't load TV input " + si.name, e); + Map inputMap = new HashMap(); + for (TvInputInfo info : inputList) { + if (DEBUG) Slog.d(TAG, "add " + info.getId()); + TvInputState state = userState.inputMap.get(info.getId()); + if (state == null) { + state = new TvInputState(); } + state.mInfo = info; + inputMap.put(info.getId(), state); } for (String inputId : inputMap.keySet()) { @@ -338,7 +337,6 @@ public final class TvInputManagerService extends SystemService { Slog.e(TAG, "error in unregisterCallback", e); } } - serviceState.mClientTokens.clear(); mContext.unbindService(serviceState.mConnection); } userState.serviceStateMap.clear(); @@ -401,9 +399,7 @@ public final class TvInputManagerService extends SystemService { } private static boolean shouldMaintainConnection(ServiceState serviceState) { - return !serviceState.mClientTokens.isEmpty() - || !serviceState.mSessionTokens.isEmpty() - || serviceState.mIsHardware; + return !serviceState.mSessionTokens.isEmpty() || serviceState.mIsHardware; // TODO: Find a way to maintain connection only when necessary. } @@ -1611,13 +1607,6 @@ public final class TvInputManagerService extends SystemService { pw.increaseIndent(); - pw.println("mClientTokens:"); - pw.increaseIndent(); - for (IBinder token : service.mClientTokens) { - pw.println("" + token); - } - pw.decreaseIndent(); - pw.println("mSessionTokens:"); pw.increaseIndent(); for (IBinder token : service.mSessionTokens) { @@ -1754,7 +1743,6 @@ public final class TvInputManagerService extends SystemService { } private final class ServiceState { - private final List mClientTokens = new ArrayList(); private final List mSessionTokens = new ArrayList(); private final ServiceConnection mConnection; private final ComponentName mComponent; -- 2.11.0