diff options
| -rw-r--r-- | services/core/java/com/android/server/tv/TvInputManagerService.java | 94 |
1 files changed, 61 insertions, 33 deletions
diff --git a/services/core/java/com/android/server/tv/TvInputManagerService.java b/services/core/java/com/android/server/tv/TvInputManagerService.java index ac43d161d48f..27023addd340 100644 --- a/services/core/java/com/android/server/tv/TvInputManagerService.java +++ b/services/core/java/com/android/server/tv/TvInputManagerService.java @@ -180,7 +180,7 @@ public final class TvInputManagerService extends SystemService { try { results = mContentResolver.applyBatch(TvContract.AUTHORITY, operations); } catch (RemoteException | OperationApplicationException e) { - Slog.e(TAG, "error in applyBatch" + e); + Slog.e(TAG, "error in applyBatch", e); } if (DEBUG) { @@ -217,7 +217,9 @@ public final class TvInputManagerService extends SystemService { UserState userState = getUserStateLocked(userId); userState.packageSet.clear(); - if (DEBUG) Slog.d(TAG, "buildTvInputList"); + if (DEBUG) { + Slog.d(TAG, "buildTvInputList"); + } PackageManager pm = mContext.getPackageManager(); List<ResolveInfo> services = pm.queryIntentServices( new Intent(TvInputService.SERVICE_INTERFACE), @@ -247,7 +249,7 @@ public final class TvInputManagerService extends SystemService { try { inputList.add(TvInputInfo.createTvInputInfo(mContext, ri)); } catch (XmlPullParserException | IOException e) { - Slog.e(TAG, "Failed to load TV input " + si.name, e); + Slog.e(TAG, "failed to load TV input " + si.name, e); continue; } } @@ -259,7 +261,9 @@ public final class TvInputManagerService extends SystemService { Map<String, TvInputState> inputMap = new HashMap<String, TvInputState>(); for (TvInputInfo info : inputList) { - if (DEBUG) Slog.d(TAG, "add " + info.getId()); + if (DEBUG) { + Slog.d(TAG, "add " + info.getId()); + } TvInputState state = userState.inputMap.get(info.getId()); if (state == null) { state = new TvInputState(); @@ -348,7 +352,13 @@ public final class TvInputManagerService extends SystemService { } userState.serviceStateMap.clear(); + // Clear everything else. + userState.inputMap.clear(); + userState.packageSet.clear(); + userState.ratingSystemXmlUriSet.clear(); userState.clientStateMap.clear(); + userState.callbackSet.clear(); + userState.mainSessionToken = null; mUserStates.remove(userId); } @@ -475,7 +485,7 @@ public final class TvInputManagerService extends SystemService { try { clientToken.linkToDeath(clientState, 0); } catch (RemoteException e) { - Slog.e(TAG, "Client is already died."); + Slog.e(TAG, "client process has already died", e); } userState.clientStateMap.put(clientToken, clientState); return clientState; @@ -509,7 +519,7 @@ public final class TvInputManagerService extends SystemService { try { session.asBinder().linkToDeath(sessionState, 0); } catch (RemoteException e) { - Slog.e(TAG, "Session is already died."); + Slog.e(TAG, "session process has already died", e); } IBinder clientToken = sessionState.mClient.asBinder(); @@ -543,7 +553,7 @@ public final class TvInputManagerService extends SystemService { // originated from. sessionState.mClient.onChannelRetuned(channelUri, sessionState.mSeq); } catch (RemoteException e) { - Slog.e(TAG, "error in onChannelRetuned"); + Slog.e(TAG, "error in onChannelRetuned", e); } } } @@ -560,7 +570,7 @@ public final class TvInputManagerService extends SystemService { try { sessionState.mClient.onTracksChanged(tracks, sessionState.mSeq); } catch (RemoteException e) { - Slog.e(TAG, "error in onTracksChanged"); + Slog.e(TAG, "error in onTracksChanged", e); } } } @@ -577,7 +587,7 @@ public final class TvInputManagerService extends SystemService { try { sessionState.mClient.onTrackSelected(type, trackId, sessionState.mSeq); } catch (RemoteException e) { - Slog.e(TAG, "error in onTrackSelected"); + Slog.e(TAG, "error in onTrackSelected", e); } } } @@ -594,7 +604,7 @@ public final class TvInputManagerService extends SystemService { try { sessionState.mClient.onVideoAvailable(sessionState.mSeq); } catch (RemoteException e) { - Slog.e(TAG, "error in onVideoAvailable"); + Slog.e(TAG, "error in onVideoAvailable", e); } } } @@ -611,7 +621,7 @@ public final class TvInputManagerService extends SystemService { try { sessionState.mClient.onVideoUnavailable(reason, sessionState.mSeq); } catch (RemoteException e) { - Slog.e(TAG, "error in onVideoUnavailable"); + Slog.e(TAG, "error in onVideoUnavailable", e); } } } @@ -628,7 +638,7 @@ public final class TvInputManagerService extends SystemService { try { sessionState.mClient.onContentAllowed(sessionState.mSeq); } catch (RemoteException e) { - Slog.e(TAG, "error in onContentAllowed"); + Slog.e(TAG, "error in onContentAllowed", e); } } } @@ -645,7 +655,7 @@ public final class TvInputManagerService extends SystemService { try { sessionState.mClient.onContentBlocked(rating, sessionState.mSeq); } catch (RemoteException e) { - Slog.e(TAG, "error in onContentBlocked"); + Slog.e(TAG, "error in onContentBlocked", e); } } } @@ -664,7 +674,7 @@ public final class TvInputManagerService extends SystemService { sessionState.mClient.onLayoutSurface(left, top, right, bottom, sessionState.mSeq); } catch (RemoteException e) { - Slog.e(TAG, "error in onLayoutSurface"); + Slog.e(TAG, "error in onLayoutSurface", e); } } } @@ -682,7 +692,7 @@ public final class TvInputManagerService extends SystemService { sessionState.mClient.onSessionEvent(eventType, eventArgs, sessionState.mSeq); } catch (RemoteException e) { - Slog.e(TAG, "error in onSessionEvent"); + Slog.e(TAG, "error in onSessionEvent", e); } } } @@ -704,8 +714,8 @@ public final class TvInputManagerService extends SystemService { IBinder sessionToken, InputChannel channel, int seq) { try { client.onSessionCreated(inputId, sessionToken, channel, seq); - } catch (RemoteException exception) { - Slog.e(TAG, "error in onSessionCreated", exception); + } catch (RemoteException e) { + Slog.e(TAG, "error in onSessionCreated", e); } } @@ -719,7 +729,7 @@ public final class TvInputManagerService extends SystemService { try { sessionState.mSession.release(); } catch (RemoteException e) { - Slog.w(TAG, "session is already disapeared", e); + Slog.e(TAG, "session process has already died", e); } sessionState.mSession = null; } @@ -749,6 +759,10 @@ public final class TvInputManagerService extends SystemService { clientState.mSessionTokens.remove(sessionToken); if (clientState.isEmpty()) { userState.clientStateMap.remove(sessionState.mClient.asBinder()); + if (userState.clientStateMap.isEmpty()) { + // No longer need to keep the callbacks since there is no client. + userState.callbackSet.clear(); + } } } @@ -789,26 +803,26 @@ public final class TvInputManagerService extends SystemService { private void notifyInputAddedLocked(UserState userState, String inputId) { if (DEBUG) { - Slog.d(TAG, "notifyInputAdded: inputId = " + inputId); + Slog.d(TAG, "notifyInputAddedLocked(inputId=" + inputId + ")"); } for (ITvInputManagerCallback callback : userState.callbackSet) { try { callback.onInputAdded(inputId); } catch (RemoteException e) { - Slog.e(TAG, "Failed to report added input to callback."); + Slog.e(TAG, "failed to report added input to callback", e); } } } private void notifyInputRemovedLocked(UserState userState, String inputId) { if (DEBUG) { - Slog.d(TAG, "notifyInputRemovedLocked: inputId = " + inputId); + Slog.d(TAG, "notifyInputRemovedLocked(inputId=" + inputId + ")"); } for (ITvInputManagerCallback callback : userState.callbackSet) { try { callback.onInputRemoved(inputId); } catch (RemoteException e) { - Slog.e(TAG, "Failed to report removed input to callback."); + Slog.e(TAG, "failed to report removed input to callback", e); } } } @@ -816,22 +830,22 @@ public final class TvInputManagerService extends SystemService { private void notifyInputStateChangedLocked(UserState userState, String inputId, int state, ITvInputManagerCallback targetCallback) { if (DEBUG) { - Slog.d(TAG, "notifyInputStateChangedLocked: inputId = " + inputId - + "; state = " + state); + Slog.d(TAG, "notifyInputStateChangedLocked(inputId=" + inputId + + ", state=" + state + ")"); } if (targetCallback == null) { for (ITvInputManagerCallback callback : userState.callbackSet) { try { callback.onInputStateChanged(inputId, state); } catch (RemoteException e) { - Slog.e(TAG, "Failed to report state change to callback."); + Slog.e(TAG, "failed to report state change to callback", e); } } } else { try { targetCallback.onInputStateChanged(inputId, state); } catch (RemoteException e) { - Slog.e(TAG, "Failed to report state change to callback."); + Slog.e(TAG, "failed to report state change to callback", e); } } } @@ -912,8 +926,22 @@ public final class TvInputManagerService extends SystemService { final long identity = Binder.clearCallingIdentity(); try { synchronized (mLock) { - UserState userState = getUserStateLocked(resolvedUserId); + final UserState userState = getUserStateLocked(resolvedUserId); userState.callbackSet.add(callback); + try { + callback.asBinder().linkToDeath(new IBinder.DeathRecipient() { + @Override + public void binderDied() { + synchronized (mLock) { + if (userState.callbackSet != null) { + userState.callbackSet.remove(callback); + } + } + } + }, 0); + } catch (RemoteException e) { + Slog.e(TAG, "client process has already died", e); + } for (TvInputState state : userState.inputMap.values()) { notifyInputStateChangedLocked(userState, state.mInfo.getId(), state.mState, callback); @@ -1103,7 +1131,7 @@ public final class TvInputManagerService extends SystemService { @Override public void releaseSession(IBinder sessionToken, int userId) { if (DEBUG) { - Slog.d(TAG, "releaseSession(): " + sessionToken); + Slog.d(TAG, "releaseSession(sessionToken=" + sessionToken + ")"); } final int callingUid = Binder.getCallingUid(); final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid, @@ -1121,7 +1149,7 @@ public final class TvInputManagerService extends SystemService { @Override public void setMainSession(IBinder sessionToken, int userId) { if (DEBUG) { - Slog.d(TAG, "setMainSession(): " + sessionToken); + Slog.d(TAG, "setMainSession(sessionToken=" + sessionToken + ")"); } final int callingUid = Binder.getCallingUid(); final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid, @@ -1290,7 +1318,7 @@ public final class TvInputManagerService extends SystemService { getSessionLocked(sessionToken, callingUid, resolvedUserId) .requestUnblockContent(unblockedRating); } catch (RemoteException e) { - Slog.e(TAG, "error in unblockContent", e); + Slog.e(TAG, "error in requestUnblockContent", e); } } } finally { @@ -1351,7 +1379,7 @@ public final class TvInputManagerService extends SystemService { getSessionLocked(sessionToken, callingUid, resolvedUserId) .appPrivateCommand(command, data); } catch (RemoteException e) { - Slog.e(TAG, "error in sendAppPrivateCommand", e); + Slog.e(TAG, "error in appPrivateCommand", e); } } } finally { @@ -1516,7 +1544,7 @@ public final class TvInputManagerService extends SystemService { synchronized (mLock) { UserState userState = getUserStateLocked(resolvedUserId); if (userState.inputMap.get(inputId) == null) { - Slog.e(TAG, "Input not found for " + inputId); + Slog.e(TAG, "input not found for " + inputId); return false; } for (SessionState sessionState : userState.sessionStateMap.values()) { @@ -2004,7 +2032,7 @@ public final class TvInputManagerService extends SystemService { buildTvInputListLocked(mUserId); mTvInputHardwareManager.removeTvInput(inputId); } else { - Slog.e(TAG, "TvInputInfo with inputId=" + inputId + " not found."); + Slog.e(TAG, "failed to remove input " + inputId); } } } |