From 2d2d8c28545c687dbb105006ef4554eac8480313 Mon Sep 17 00:00:00 2001 From: Mathias Jeppsson Date: Tue, 6 Aug 2013 11:41:55 +0200 Subject: [PATCH] Dont call close in in BluetoothA2dp finalize The close in finalize() is pointless, as finalize() will only be called if there are no references to BluetoothA2dp. Until close() is called, BluetoothManagerService will have a reference to BluetoothA2dp, preventing garbage collection and finalize() to be called. This means finalize() is not serving its purpose of cleaning up in cases close() is not called, as finalize() is only called if close() has already been called. Actually calling close in finalize here means unregistering the already unregistered mBluetoothStateChangeCallback which can lead to crashes when pairing/unpairing BTH. A typical crash would look like: *** FATAL EXCEPTION IN SYSTEM PROCESS: BluetoothManager java.lang.NullPointerException at android.os.RemoteCallbackList.unregister(RemoteCallbackList.java:143) at com.android.server.BluetoothManagerService$BluetoothHandler.handleMessage(BluetoothManagerService.java:780) at android.os.Handler.dispatchMessage(Handler.java:99) Change-Id: Ib65962917ecbacf7900d7fe540057e6915f0532d --- core/java/android/bluetooth/BluetoothA2dp.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/java/android/bluetooth/BluetoothA2dp.java b/core/java/android/bluetooth/BluetoothA2dp.java index 51754901163de..0450150f871f1 100644 --- a/core/java/android/bluetooth/BluetoothA2dp.java +++ b/core/java/android/bluetooth/BluetoothA2dp.java @@ -199,7 +199,8 @@ public final class BluetoothA2dp implements BluetoothProfile { } public void finalize() { - close(); + // The empty finalize needs to be kept or the + // cts signature tests would fail. } /** * Initiate connection to a profile of the remote bluetooth device.