@@ -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