Skip to content

Commit a950973

Browse files
committed
Fix 5615747 Don't leak remote control client death handlers
Whenever a remote control stack entry is GC'd or removed from the stack, unlink its death handler. Change-Id: Ia4ed6667351849fd388272591e24ffc16959beaf
1 parent 258576a commit a950973

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

media/java/android/media/AudioService.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3062,13 +3062,20 @@ public void unlinkToRcClientDeath() {
30623062
if ((mRcClientDeathHandler != null) && (mRcClientDeathHandler.mCb != null)) {
30633063
try {
30643064
mRcClientDeathHandler.mCb.unlinkToDeath(mRcClientDeathHandler, 0);
3065+
mRcClientDeathHandler = null;
30653066
} catch (java.util.NoSuchElementException e) {
30663067
// not much we can do here
30673068
Log.e(TAG, "Encountered " + e + " in unlinkToRcClientDeath()");
30683069
e.printStackTrace();
30693070
}
30703071
}
30713072
}
3073+
3074+
@Override
3075+
protected void finalize() throws Throwable {
3076+
unlinkToRcClientDeath();// unlink exception handled inside method
3077+
super.finalize();
3078+
}
30723079
}
30733080

30743081
/**
@@ -3115,6 +3122,7 @@ private void removeMediaButtonReceiverForPackage(String packageName) {
31153122
if (packageName.equalsIgnoreCase(rcse.mReceiverComponent.getPackageName())) {
31163123
// a stack entry is from the package being removed, remove it from the stack
31173124
stackIterator.remove();
3125+
rcse.unlinkToRcClientDeath();
31183126
}
31193127
}
31203128
if (mRCStack.empty()) {
@@ -3195,6 +3203,7 @@ private void removeMediaButtonReceiver(PendingIntent pi) {
31953203
RemoteControlStackEntry rcse = (RemoteControlStackEntry)stackIterator.next();
31963204
if(rcse.mMediaIntent.equals(pi)) {
31973205
stackIterator.remove();
3206+
rcse.unlinkToRcClientDeath();
31983207
break;
31993208
}
32003209
}
@@ -3456,7 +3465,7 @@ public void registerRemoteControlClient(PendingIntent mediaIntent,
34563465
rcse.mCallingPackageName = callingPackageName;
34573466
rcse.mCallingUid = Binder.getCallingUid();
34583467
if (rcClient == null) {
3459-
rcse.mRcClientDeathHandler = null;
3468+
// here rcse.mRcClientDeathHandler is null;
34603469
break;
34613470
}
34623471

@@ -3512,7 +3521,6 @@ public void unregisterRemoteControlClient(PendingIntent mediaIntent,
35123521
rcse.unlinkToRcClientDeath();
35133522
// reset the client-related fields
35143523
rcse.mRcClient = null;
3515-
rcse.mRcClientDeathHandler = null;
35163524
rcse.mCallingPackageName = null;
35173525
}
35183526
}

0 commit comments

Comments
 (0)