Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 781c55fd authored by Dongwon Kang's avatar Dongwon Kang Committed by Android (Google) Code Review
Browse files

Merge "Handle the failure of session creation request in TvInputManagerService."

parents 8b53023a fd5b72f1
Loading
Loading
Loading
Loading
+23 −13
Original line number Diff line number Diff line
@@ -277,10 +277,16 @@ public final class TvInputManagerService extends SystemService {
                }
                synchronized (mLock) {
                    sessionState.session = session;
                    if (session == null) {
                        removeSessionStateLocked(sessionToken, userId);
                        sendSessionTokenToClientLocked(sessionState.client, sessionState.name, null,
                                sessionState.seq, userId);
                    } else {
                        sendSessionTokenToClientLocked(sessionState.client, sessionState.name,
                                sessionToken, sessionState.seq, userId);
                    }
                }
            }
        };

        // Create a session. When failed, send a null token immediately.
@@ -288,6 +294,7 @@ public final class TvInputManagerService extends SystemService {
            service.createSession(callback);
        } catch (RemoteException e) {
            Log.e(TAG, "error in createSession", e);
            removeSessionStateLocked(sessionToken, userId);
            sendSessionTokenToClientLocked(sessionState.client, sessionState.name, null,
                    sessionState.seq, userId);
        }
@@ -307,6 +314,19 @@ public final class TvInputManagerService extends SystemService {
        }
    }

    private void removeSessionStateLocked(IBinder sessionToken, int userId) {
        // Remove the session state from the global session state map of the current user.
        UserState userState = getUserStateLocked(userId);
        SessionState sessionState = userState.sessionStateMap.remove(sessionToken);

        // Also remove the session state from the session state map of the current service.
        ServiceState serviceState = userState.serviceStateMap.get(sessionState.name);
        if (serviceState != null) {
            serviceState.sessionStateMap.remove(sessionToken);
        }
        updateServiceConnectionLocked(sessionState.name, userId);
    }

    private final class BinderService extends ITvInputManager.Stub {
        @Override
        public List<TvInputInfo> getTvInputList(int userId) {
@@ -474,17 +494,7 @@ public final class TvInputManagerService extends SystemService {
                        Log.e(TAG, "error in release", e);
                    }

                    // Remove its state from the global session state map of the current user.
                    UserState userState = getUserStateLocked(resolvedUserId);
                    SessionState sessionState = userState.sessionStateMap.remove(sessionToken);

                    // Also remove it from the session state map of the current service.
                    ServiceState serviceState = userState.serviceStateMap.get(sessionState.name);
                    if (serviceState != null) {
                        serviceState.sessionStateMap.remove(sessionToken);
                    }

                    updateServiceConnectionLocked(sessionState.name, resolvedUserId);
                    removeSessionStateLocked(sessionToken, resolvedUserId);
                }
            } finally {
                Binder.restoreCallingIdentity(identity);