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

Commit fd5b72f1 authored by Dongwon Kang's avatar Dongwon Kang
Browse files

Handle the failure of session creation request in TvInputManagerService.

Bug: 14073508
Change-Id: Idc9da323bb0000300faf662c7db031214ae6136c
parent 5b7edc59
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);