GATT: Fix FD leak caused by GATT profile
Use case: BT ON/OFF with one BLE APP active
Failure: FD leak is observed with ON/OFF stress test
which eventually lead to crash due to unavailability
of FDs.
Steps:
BT ON/OFF with one BLE APP active to retain the
same Bluetooth process ID to check the FD leak issue.
Root Cause: As the Advertisementi manager and Scan
Manager are not cleaning up the looper instances as
part of cleanup, it causes FD leak.
Fix: Cleanup the handler threads in Advertisementmanager
and ScanManager so that there are no resource leaks.
Change-Id: Ia51899f449d57c1ef68a9516b8472d1fd492572b
diff --git a/src/com/android/bluetooth/gatt/AdvertiseManager.java b/src/com/android/bluetooth/gatt/AdvertiseManager.java
index 91932bb..058bf4b 100644
--- a/src/com/android/bluetooth/gatt/AdvertiseManager.java
+++ b/src/com/android/bluetooth/gatt/AdvertiseManager.java
@@ -89,6 +89,16 @@
void cleanup() {
logd("advertise clients cleared");
mAdvertiseClients.clear();
+
+ if (mHandler != null) {
+ // Shut down the thread
+ mHandler.removeCallbacksAndMessages(null);
+ Looper looper = mHandler.getLooper();
+ if (looper != null) {
+ looper.quit();
+ }
+ mHandler = null;
+ }
}
/**
diff --git a/src/com/android/bluetooth/gatt/ScanManager.java b/src/com/android/bluetooth/gatt/ScanManager.java
index dca74c4..24b14b3 100644
--- a/src/com/android/bluetooth/gatt/ScanManager.java
+++ b/src/com/android/bluetooth/gatt/ScanManager.java
@@ -109,6 +109,16 @@
mRegularScanClients.clear();
mBatchClients.clear();
mScanNative.cleanup();
+
+ if (mHandler != null) {
+ // Shut down the thread
+ mHandler.removeCallbacksAndMessages(null);
+ Looper looper = mHandler.getLooper();
+ if (looper != null) {
+ looper.quit();
+ }
+ mHandler = null;
+ }
}
/**