MAP: fix problem with MNS not disconnecting correctly
MNS is needed to disconnect with the MSE but did not.
This patch fixes that by re-adding a disconnect() that was wrongfully removed during review.
Patch set 2:
-----------
- Split disconnect and shutdown for MNS connection
bug: 11161674
Change-Id: Idd09fc774584dfdb171b0d00be0f7711ae57b853
diff --git a/src/com/android/bluetooth/map/BluetoothMapService.java b/src/com/android/bluetooth/map/BluetoothMapService.java
index 446a681..c5c03ef 100644
--- a/src/com/android/bluetooth/map/BluetoothMapService.java
+++ b/src/com/android/bluetooth/map/BluetoothMapService.java
@@ -263,7 +263,7 @@
}
if (mBluetoothMnsObexClient != null) {
- mBluetoothMnsObexClient.disconnect();
+ mBluetoothMnsObexClient.shutdown();
mBluetoothMnsObexClient = null;
}
@@ -324,7 +324,7 @@
mAcceptThread = null;
if(mBluetoothMnsObexClient != null) {
- mBluetoothMnsObexClient.disconnect();
+ mBluetoothMnsObexClient.shutdown();
mBluetoothMnsObexClient = null;
}
closeConnectionSocket();
@@ -515,7 +515,7 @@
mServerSession = null;
}
if(mBluetoothMnsObexClient != null) {
- mBluetoothMnsObexClient.disconnect(); //FIXME should use shutdown when implemented
+ mBluetoothMnsObexClient.shutdown();
mBluetoothMnsObexClient = null;
}
closeConnectionSocket();
diff --git a/src/com/android/bluetooth/map/BluetoothMnsObexClient.java b/src/com/android/bluetooth/map/BluetoothMnsObexClient.java
index f419bdd..c57a089 100644
--- a/src/com/android/bluetooth/map/BluetoothMnsObexClient.java
+++ b/src/com/android/bluetooth/map/BluetoothMnsObexClient.java
@@ -112,19 +112,11 @@
return mConnected;
}
+ /**
+ * Disconnect the connection to MNS server.
+ * Call this when the MAS client requests a de-registration on events.
+ */
public void disconnect() {
- /* should shutdown handler thread first to make sure
- * handleRegistration won't be called when disconnet
- */
- if (mHandler != null) {
- // Shut down the thread
- mHandler.removeCallbacksAndMessages(null);
- Looper looper = mHandler.getLooper();
- if (looper != null) {
- looper.quit();
- }
- mHandler = null;
- }
try {
if (mClientSession != null) {
mClientSession.disconnect(null);
@@ -154,6 +146,28 @@
Log.e(TAG, "mTransport.close error: " + e.getMessage());
}
}
+ }
+
+ /**
+ * Shutdown the MNS.
+ */
+ public void shutdown() {
+ /* should shutdown handler thread first to make sure
+ * handleRegistration won't be called when disconnet
+ */
+ if (mHandler != null) {
+ // Shut down the thread
+ mHandler.removeCallbacksAndMessages(null);
+ Looper looper = mHandler.getLooper();
+ if (looper != null) {
+ looper.quit();
+ }
+ mHandler = null;
+ }
+
+ /* Disconnect if connected */
+ disconnect();
+
if(mObserverRegistered) {
mObserver.unregisterObserver();
mObserverRegistered = false;
@@ -180,6 +194,7 @@
if(mObserverRegistered == true) {
mObserver.unregisterObserver();
mObserverRegistered = false;
+ disconnect();
}
} else if(notificationStatus == BluetoothMapAppParams.NOTIFICATION_STATUS_YES) {
/* Connect if we do not have a connection, and start the content observers providing