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

Commit 426c9a40 authored by Dongwon Kang's avatar Dongwon Kang
Browse files

TIF: clean up pending createSession requests when a package is removed.

Pending createSession request for the package removed led to the tune request
with invalid channel URI. This change prevents crash from invalid URI by cleaning
up the pending requests on the package removal.

Bug: 17214114
Change-Id: I26fdf9eb45a5fec9032926a1c2994831c07b4fbe
parent 0dedb722
Loading
Loading
Loading
Loading
+30 −11
Original line number Diff line number Diff line
@@ -146,6 +146,7 @@ public final class TvInputManagerService extends SystemService {
        PackageMonitor monitor = new PackageMonitor() {
            @Override
            public void onSomePackagesChanged() {
                if (DEBUG) Slog.d(TAG, "onSomePackagesChanged()");
                synchronized (mLock) {
                    buildTvInputListLocked(mCurrentUserId);
                }
@@ -275,6 +276,11 @@ public final class TvInputManagerService extends SystemService {

        for (String inputId : userState.inputMap.keySet()) {
            if (!inputMap.containsKey(inputId)) {
                TvInputInfo info = userState.inputMap.get(inputId).mInfo;
                ServiceState serviceState = userState.serviceStateMap.get(info.getComponent());
                if (serviceState != null) {
                    abortPendingCreateSessionRequestsLocked(serviceState, inputId, userId);
                }
                notifyInputRemovedLocked(userState, inputId);
            }
        }
@@ -447,6 +453,22 @@ public final class TvInputManagerService extends SystemService {
        }
    }

    private void abortPendingCreateSessionRequestsLocked(ServiceState serviceState,
            String inputId, int userId) {
        // Let clients know the create session requests are failed.
        UserState userState = getUserStateLocked(userId);
        for (IBinder sessionToken : serviceState.mSessionTokens) {
            SessionState sessionState = userState.sessionStateMap.get(sessionToken);
            if (sessionState.mSession == null && (inputId == null
                    || sessionState.mInfo.getId().equals(inputId))) {
                removeSessionStateLocked(sessionToken, sessionState.mUserId);
                sendSessionTokenToClientLocked(sessionState.mClient,
                        sessionState.mInfo.getId(), null, null, sessionState.mSeq);
            }
        }
        updateServiceConnectionLocked(serviceState.mComponent, userId);
    }

    private ClientState createClientStateLocked(IBinder clientToken, int userId) {
        UserState userState = getUserStateLocked(userId);
        ClientState clientState = new ClientState(clientToken, userId);
@@ -1038,7 +1060,13 @@ public final class TvInputManagerService extends SystemService {
            try {
                synchronized (mLock) {
                    UserState userState = getUserStateLocked(resolvedUserId);
                    TvInputInfo info = userState.inputMap.get(inputId).mInfo;
                    TvInputState inputState = userState.inputMap.get(inputId);
                    if (inputState == null) {
                        Slog.w(TAG, "Failed to find input state for inputId=" + inputId);
                        sendSessionTokenToClientLocked(client, inputId, null, null, seq);
                        return;
                    }
                    TvInputInfo info = inputState.mInfo;
                    ServiceState serviceState = userState.serviceStateMap.get(info.getComponent());
                    if (serviceState == null) {
                        serviceState = new ServiceState(info.getComponent(), resolvedUserId);
@@ -1898,15 +1926,7 @@ public final class TvInputManagerService extends SystemService {
                    serviceState.mService = null;
                    serviceState.mCallback = null;

                    // Send null tokens for not finishing create session events.
                    for (IBinder sessionToken : serviceState.mSessionTokens) {
                        SessionState sessionState = userState.sessionStateMap.get(sessionToken);
                        if (sessionState.mSession == null) {
                            removeSessionStateLocked(sessionToken, sessionState.mUserId);
                            sendSessionTokenToClientLocked(sessionState.mClient,
                                    sessionState.mInfo.getId(), null, null, sessionState.mSeq);
                        }
                    }
                    abortPendingCreateSessionRequestsLocked(serviceState, null, mUserId);

                    for (TvInputState inputState : userState.inputMap.values()) {
                        if (inputState.mInfo.getComponent().equals(component)) {
@@ -1914,7 +1934,6 @@ public final class TvInputManagerService extends SystemService {
                                    INPUT_STATE_DISCONNECTED, null);
                        }
                    }
                    updateServiceConnectionLocked(mComponent, mUserId);
                }
            }
        }