From f1754050ceaadb4603aaaa0b1f0b193a305834af Mon Sep 17 00:00:00 2001 From: Matthew Xie Date: Wed, 14 Sep 2011 09:05:27 -0700 Subject: [PATCH] Keep Binder reference in the mServiceRecordToPid hashmap so that the Binder object does not get destroyed when the thread that registers the service record ends. bug 5276332 Change-Id: Id17a4c279e03aa6928dca5bf048c7c90862bd9cf --- core/java/android/server/BluetoothService.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/core/java/android/server/BluetoothService.java b/core/java/android/server/BluetoothService.java index 00d33316e2cbc..f0fb4e003bcdd 100755 --- a/core/java/android/server/BluetoothService.java +++ b/core/java/android/server/BluetoothService.java @@ -145,7 +145,7 @@ public class BluetoothService extends IBluetooth.Stub { private final ArrayList mUuidIntentTracker; private final HashMap mUuidCallbackTracker; - private final HashMap mServiceRecordToPid; + private final HashMap> mServiceRecordToPid; private final HashMap mDeviceProfileState; private final BluetoothProfileState mA2dpProfileState; @@ -221,7 +221,7 @@ public class BluetoothService extends IBluetooth.Stub { mDeviceOobData = new HashMap>(); mUuidIntentTracker = new ArrayList(); mUuidCallbackTracker = new HashMap(); - mServiceRecordToPid = new HashMap(); + mServiceRecordToPid = new HashMap>(); mDeviceProfileState = new HashMap(); mA2dpProfileState = new BluetoothProfileState(mContext, BluetoothProfileState.A2DP); mHfpProfileState = new BluetoothProfileState(mContext, BluetoothProfileState.HFP); @@ -1516,10 +1516,10 @@ public class BluetoothService extends IBluetooth.Stub { } int pid = Binder.getCallingPid(); - mServiceRecordToPid.put(new Integer(handle), new Integer(pid)); + mServiceRecordToPid.put(new Integer(handle), new Pair(pid, b)); try { b.linkToDeath(new Reaper(handle, pid, RFCOMM_RECORD_REAPER), 0); - } catch (RemoteException e) {} + } catch (RemoteException e) {Log.e(TAG, "", e);} return handle; } @@ -1532,12 +1532,12 @@ public class BluetoothService extends IBluetooth.Stub { } private synchronized void checkAndRemoveRecord(int handle, int pid) { - Integer handleInt = new Integer(handle); - Integer owner = mServiceRecordToPid.get(handleInt); + Pair pidPair = mServiceRecordToPid.get(handle); + Integer owner = pidPair.first; if (owner != null && pid == owner.intValue()) { if (DBG) Log.d(TAG, "Removing service record " + Integer.toHexString(handle) + " for pid " + pid); - mServiceRecordToPid.remove(handleInt); + mServiceRecordToPid.remove(handle); removeServiceRecordNative(handle); } } @@ -1593,6 +1593,7 @@ public class BluetoothService extends IBluetooth.Stub { try { binder.linkToDeath(new Reaper(pid, STATE_CHANGE_REAPER), 0); } catch (RemoteException e) { + Log.e(TAG, "", e); return false; } } @@ -1867,7 +1868,7 @@ public class BluetoothService extends IBluetooth.Stub { private void dumpApplicationServiceRecords(PrintWriter pw) { pw.println("\n--Application Service Records--"); for (Integer handle : mServiceRecordToPid.keySet()) { - Integer pid = mServiceRecordToPid.get(handle); + Integer pid = mServiceRecordToPid.get(handle).first; pw.println("\tpid " + pid + " handle " + Integer.toHexString(handle)); } mAdapter.closeProfileProxy(BluetoothProfile.PAN, mBluetoothHeadset);