Fix reference leak on TvInputManagerService

Fix reference leak when TV input changed.

Test: 1. Modify to call android.os.Debug.dumpReferenceTables() in
TvInputManagerService#onServiceConnected
2. Build and run
3. Repeat to launch and finish TV player application with logcat output
4. Confirm Global Reference Table information on logcat whether
reference increase

Change-Id: I9b9896115088d8b179a9cf29ddca88e8a8fa529a
This commit is contained in:
Kyeongkab.Nam
2019-01-16 10:44:37 +09:00
parent 1cbb20b2df
commit 8d6b71aa1d

View File

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