Merge "Fix reference leak on TvInputManagerService"

This commit is contained in:
nchalko
2019-02-06 16:33:19 +00:00
committed by Gerrit Code Review

View File

@@ -128,6 +128,8 @@ public final class TvInputManagerService extends SystemService {
private final WatchLogHandler mWatchLogHandler; private final WatchLogHandler mWatchLogHandler;
private IBinder.DeathRecipient mDeathRecipient;
public TvInputManagerService(Context context) { public TvInputManagerService(Context context) {
super(context); super(context);
@@ -672,6 +674,7 @@ public final class TvInputManagerService extends SystemService {
if (sessionToken == userState.mainSessionToken) { if (sessionToken == userState.mainSessionToken) {
setMainLocked(sessionToken, false, callingUid, userId); setMainLocked(sessionToken, false, callingUid, userId);
} }
sessionState.session.asBinder().unlinkToDeath(sessionState, 0);
sessionState.session.release(); sessionState.session.release();
} }
} catch (RemoteException | SessionNotFoundException e) { } catch (RemoteException | SessionNotFoundException e) {
@@ -707,6 +710,7 @@ public final class TvInputManagerService extends SystemService {
clientState.sessionTokens.remove(sessionToken); clientState.sessionTokens.remove(sessionToken);
if (clientState.isEmpty()) { if (clientState.isEmpty()) {
userState.clientStateMap.remove(sessionState.client.asBinder()); userState.clientStateMap.remove(sessionState.client.asBinder());
sessionState.client.asBinder().unlinkToDeath(clientState, 0);
} }
} }
@@ -1000,8 +1004,7 @@ public final class TvInputManagerService extends SystemService {
synchronized (mLock) { synchronized (mLock) {
final UserState userState = getOrCreateUserStateLocked(resolvedUserId); final UserState userState = getOrCreateUserStateLocked(resolvedUserId);
userState.callbackSet.add(callback); userState.callbackSet.add(callback);
try { mDeathRecipient = new IBinder.DeathRecipient() {
callback.asBinder().linkToDeath(new IBinder.DeathRecipient() {
@Override @Override
public void binderDied() { public void binderDied() {
synchronized (mLock) { synchronized (mLock) {
@@ -1010,7 +1013,10 @@ public final class TvInputManagerService extends SystemService {
} }
} }
} }
}, 0); };
try {
callback.asBinder().linkToDeath(mDeathRecipient, 0);
} catch (RemoteException e) { } catch (RemoteException e) {
Slog.e(TAG, "client process has already died", e); Slog.e(TAG, "client process has already died", e);
} }
@@ -1029,6 +1035,7 @@ public final class TvInputManagerService extends SystemService {
synchronized (mLock) { synchronized (mLock) {
UserState userState = getOrCreateUserStateLocked(resolvedUserId); UserState userState = getOrCreateUserStateLocked(resolvedUserId);
userState.callbackSet.remove(callback); userState.callbackSet.remove(callback);
callback.asBinder().unlinkToDeath(mDeathRecipient, 0);
} }
} finally { } finally {
Binder.restoreCallingIdentity(identity); Binder.restoreCallingIdentity(identity);