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

Commit 028023b9 authored by Amy Zhang's avatar Amy Zhang
Browse files

Use a randomly generated UUID as the TvInputSessionId

The current implementation uses uid, pid and the resolvedUser to create
the sessionId. But it's not unique when the same app uses the same
TvInputService to create multiple input sessions.

Also this leaks pid/uid information.

Fix this by using a randomly generated UUID instead.

Test: make
Bug: 163855754
Change-Id: I4369e2645b50d44803f2d393798fa5ea6d1c22bd
parent 3cfbdd8a
Loading
Loading
Loading
Loading
+5 −6
Original line number Diff line number Diff line
@@ -99,6 +99,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@@ -1177,7 +1178,8 @@ public final class TvInputManagerService extends SystemService {
            final int resolvedUserId = resolveCallingUserId(callingPid, callingUid,
                    userId, "createSession");
            final long identity = Binder.clearCallingIdentity();
            StringBuilder sessionId = new StringBuilder();
            // Generate a unique session id with a random UUID.
            String uniqueSessionId = UUID.randomUUID().toString();
            try {
                synchronized (mLock) {
                    if (userId != mCurrentUserId && !isRecordingSession) {
@@ -1206,20 +1208,17 @@ public final class TvInputManagerService extends SystemService {
                        return;
                    }

                    // Create a unique session id with pid, uid and resolved user id
                    sessionId.append(callingUid).append(callingPid).append(resolvedUserId);

                    // Create a new session token and a session state.
                    IBinder sessionToken = new Binder();
                    SessionState sessionState = new SessionState(sessionToken, info.getId(),
                            info.getComponent(), isRecordingSession, client, seq, callingUid,
                            callingPid, resolvedUserId, sessionId.toString());
                            callingPid, resolvedUserId, uniqueSessionId);

                    // Add them to the global session state map of the current user.
                    userState.sessionStateMap.put(sessionToken, sessionState);

                    // Map the session id to the sessionStateMap in the user state
                    mSessionIdToSessionStateMap.put(sessionId.toString(), sessionState);
                    mSessionIdToSessionStateMap.put(uniqueSessionId, sessionState);

                    // Also, add them to the session state map of the current service.
                    serviceState.sessionTokens.add(sessionToken);