@@ -145,7 +145,12 @@ public class BluetoothService extends IBluetooth.Stub {
145145 private final ArrayList <String > mUuidIntentTracker ;
146146 private final HashMap <RemoteService , IBluetoothCallback > mUuidCallbackTracker ;
147147
148- private final HashMap <Integer , Pair <Integer , IBinder >> mServiceRecordToPid ;
148+ private static class ServiceRecordClient {
149+ int pid ;
150+ IBinder binder ;
151+ IBinder .DeathRecipient death ;
152+ }
153+ private final HashMap <Integer , ServiceRecordClient > mServiceRecordToPid ;
149154
150155 private final HashMap <String , BluetoothDeviceProfileState > mDeviceProfileState ;
151156 private final BluetoothProfileState mA2dpProfileState ;
@@ -221,7 +226,7 @@ public BluetoothService(Context context) {
221226 mDeviceOobData = new HashMap <String , Pair <byte [], byte []>>();
222227 mUuidIntentTracker = new ArrayList <String >();
223228 mUuidCallbackTracker = new HashMap <RemoteService , IBluetoothCallback >();
224- mServiceRecordToPid = new HashMap <Integer , Pair < Integer , IBinder > >();
229+ mServiceRecordToPid = new HashMap <Integer , ServiceRecordClient >();
225230 mDeviceProfileState = new HashMap <String , BluetoothDeviceProfileState >();
226231 mA2dpProfileState = new BluetoothProfileState (mContext , BluetoothProfileState .A2DP );
227232 mHfpProfileState = new BluetoothProfileState (mContext , BluetoothProfileState .HFP );
@@ -1528,11 +1533,17 @@ public synchronized int addRfcommServiceRecord(String serviceName, ParcelUuid uu
15281533 return -1 ;
15291534 }
15301535
1531- int pid = Binder .getCallingPid ();
1532- mServiceRecordToPid .put (new Integer (handle ), new Pair <Integer , IBinder >(pid , b ));
1536+ ServiceRecordClient client = new ServiceRecordClient ();
1537+ client .pid = Binder .getCallingPid ();
1538+ client .binder = b ;
1539+ client .death = new Reaper (handle , client .pid , RFCOMM_RECORD_REAPER );
1540+ mServiceRecordToPid .put (new Integer (handle ), client );
15331541 try {
1534- b .linkToDeath (new Reaper (handle , pid , RFCOMM_RECORD_REAPER ), 0 );
1535- } catch (RemoteException e ) {Log .e (TAG , "" , e );}
1542+ b .linkToDeath (client .death , 0 );
1543+ } catch (RemoteException e ) {
1544+ Log .e (TAG , "" , e );
1545+ client .death = null ;
1546+ }
15361547 return handle ;
15371548 }
15381549
@@ -1547,10 +1558,15 @@ public void removeServiceRecord(int handle) {
15471558 }
15481559
15491560 private synchronized void checkAndRemoveRecord (int handle , int pid ) {
1550- Pair < Integer , IBinder > pidPair = mServiceRecordToPid .get (handle );
1551- if (pidPair != null && pid == pidPair . first ) {
1561+ ServiceRecordClient client = mServiceRecordToPid .get (handle );
1562+ if (client != null && pid == client . pid ) {
15521563 if (DBG ) Log .d (TAG , "Removing service record " +
15531564 Integer .toHexString (handle ) + " for pid " + pid );
1565+
1566+ if (client .death != null ) {
1567+ client .binder .unlinkToDeath (client .death , 0 );
1568+ }
1569+
15541570 mServiceRecordToPid .remove (handle );
15551571 removeServiceRecordNative (handle );
15561572 }
@@ -1880,7 +1896,7 @@ private void dumpHeadsetConnectionState(PrintWriter pw,
18801896 private void dumpApplicationServiceRecords (PrintWriter pw ) {
18811897 pw .println ("\n --Application Service Records--" );
18821898 for (Integer handle : mServiceRecordToPid .keySet ()) {
1883- Integer pid = mServiceRecordToPid .get (handle ).first ;
1899+ Integer pid = mServiceRecordToPid .get (handle ).pid ;
18841900 pw .println ("\t pid " + pid + " handle " + Integer .toHexString (handle ));
18851901 }
18861902 }
0 commit comments