diff options
author | Jeff Sharkey <jsharkey@android.com> | 2021-05-24 10:00:23 -0600 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2021-06-03 15:38:17 -0600 |
commit | db38eb73db2ffef87bcab51aa8ceb7d6fa6a3ca0 (patch) | |
tree | e504c5569493bf95a0e7e7b000bca16ae0f6d854 /framework/java/android/bluetooth/BluetoothProfileConnector.java | |
parent | 0cc9fe2cb3763a0f76e3d6078724edc73c3a9a40 (diff) |
CloseGuard for more Bluetooth components.
We've seen evidence of IBluetoothProfileServiceConnection and
IBluetoothStateChangeCallback references being leaked, so attempt to
unregister them when an object is finalized without closing.
Bug: 189091551
Test: manual
Change-Id: I23792d48d94578acd7fc7a5164a95171801ee721
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothProfileConnector.java')
-rw-r--r-- | framework/java/android/bluetooth/BluetoothProfileConnector.java | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/framework/java/android/bluetooth/BluetoothProfileConnector.java b/framework/java/android/bluetooth/BluetoothProfileConnector.java index beff841f2f..a254291f57 100644 --- a/framework/java/android/bluetooth/BluetoothProfileConnector.java +++ b/framework/java/android/bluetooth/BluetoothProfileConnector.java @@ -26,6 +26,7 @@ import android.os.Build; import android.os.IBinder; import android.os.RemoteException; import android.os.UserHandle; +import android.util.CloseGuard; import android.util.Log; /** @@ -36,6 +37,7 @@ import android.util.Log; */ @SuppressLint("AndroidFrameworkBluetoothPermission") public abstract class BluetoothProfileConnector<T> { + private final CloseGuard mCloseGuard = new CloseGuard(); private final int mProfileId; private BluetoothProfile.ServiceListener mServiceListener; private final BluetoothProfile mProfileProxy; @@ -82,11 +84,19 @@ public abstract class BluetoothProfileConnector<T> { mServiceName = serviceName; } + /** {@hide} */ + @Override + public void finalize() { + mCloseGuard.warnIfOpen(); + doUnbind(); + } + @SuppressLint("AndroidFrameworkRequiresPermission") private boolean doBind() { synchronized (mConnection) { if (mService == null) { logDebug("Binding service..."); + mCloseGuard.open("doUnbind"); try { Intent intent = new Intent(mServiceName); ComponentName comp = intent.resolveSystemService( @@ -110,6 +120,7 @@ public abstract class BluetoothProfileConnector<T> { synchronized (mConnection) { if (mService != null) { logDebug("Unbinding service..."); + mCloseGuard.close(); try { mContext.unbindService(mConnection); } catch (IllegalArgumentException ie) { |