Skip to content

Commit 26b3d1f

Browse files
committed
Fix bug 5357295 NPE on display when remote control client dies
When a IRemoteControlClient dies, that client is set to null in the stack of remote control entries (mRCStack). This is done by calling registerRemoteControlClient() with a null client. The bug is that registerRemoteControlClient(), after storing the new client, uses it to let it know what the current remote control display is. When that display is non null, the client is sent the current display. So when a client died when there was a display, the client reference was accessed in the part of the method where we haven't yet checked whether it is null or not. The fix consists in moving the setting of the display on the client (method plugRemoteControlDisplay) only after having checked that the client is non-null. Change-Id: Ic74d6cba9e3a3a16e78cd80a1ae5901abfeb3905
1 parent 2b2adbd commit 26b3d1f

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

media/java/android/media/AudioService.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2958,7 +2958,7 @@ public void binderDied() {
29582958
Log.w(TAG, " RemoteControlClient died");
29592959
// remote control client died, make sure the displays don't use it anymore
29602960
// by setting its remote control client to null
2961-
registerRemoteControlClient(mMediaIntent, null, null/*ignored*/);
2961+
registerRemoteControlClient(mMediaIntent, null/*rcClient*/, null/*ignored*/);
29622962
}
29632963

29642964
public IBinder getBinder() {
@@ -3366,7 +3366,12 @@ public void unregisterMediaButtonIntent(PendingIntent mediaIntent, ComponentName
33663366
}
33673367
}
33683368

3369-
/** see AudioManager.registerRemoteControlClient(ComponentName eventReceiver, ...) */
3369+
/**
3370+
* see AudioManager.registerRemoteControlClient(ComponentName eventReceiver, ...)
3371+
* Note: using this method with rcClient == null is a way to "disable" the IRemoteControlClient
3372+
* without modifying the RC stack, but while still causing the display to refresh (will
3373+
* become blank as a result of this)
3374+
*/
33703375
public void registerRemoteControlClient(PendingIntent mediaIntent,
33713376
IRemoteControlClient rcClient, String callingPackageName) {
33723377
if (DEBUG_RC) Log.i(TAG, "Register remote control client rcClient="+rcClient);
@@ -3384,6 +3389,15 @@ public void registerRemoteControlClient(PendingIntent mediaIntent,
33843389
}
33853390
// save the new remote control client
33863391
rcse.mRcClient = rcClient;
3392+
rcse.mCallingPackageName = callingPackageName;
3393+
rcse.mCallingUid = Binder.getCallingUid();
3394+
if (rcClient == null) {
3395+
rcse.mRcClientDeathHandler = null;
3396+
break;
3397+
}
3398+
3399+
// there is a new (non-null) client:
3400+
// 1/ give the new client the current display (if any)
33873401
if (mRcDisplay != null) {
33883402
try {
33893403
rcse.mRcClient.plugRemoteControlDisplay(mRcDisplay);
@@ -3392,14 +3406,8 @@ public void registerRemoteControlClient(PendingIntent mediaIntent,
33923406
e.printStackTrace();
33933407
}
33943408
}
3395-
rcse.mCallingPackageName = callingPackageName;
3396-
rcse.mCallingUid = Binder.getCallingUid();
3397-
if (rcClient == null) {
3398-
rcse.mRcClientDeathHandler = null;
3399-
break;
3400-
}
3401-
// monitor the new client's death
3402-
IBinder b = rcClient.asBinder();
3409+
// 2/ monitor the new client's death
3410+
IBinder b = rcse.mRcClient.asBinder();
34033411
RcClientDeathHandler rcdh =
34043412
new RcClientDeathHandler(b, rcse.mMediaIntent);
34053413
try {

0 commit comments

Comments
 (0)