From 824929471ee80476e6d6774eedac9f30c5623eb2 Mon Sep 17 00:00:00 2001 From: Zhihai Xu Date: Tue, 22 Oct 2013 17:48:06 -0700 Subject: [PATCH] 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 --- .../android/bluetooth/map/BluetoothMapService.java | 6 ++-- .../bluetooth/map/BluetoothMnsObexClient.java | 39 +++++++++++++++------- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/com/android/bluetooth/map/BluetoothMapService.java b/src/com/android/bluetooth/map/BluetoothMapService.java index 446a6816..c5c03ef0 100644 --- a/src/com/android/bluetooth/map/BluetoothMapService.java +++ b/src/com/android/bluetooth/map/BluetoothMapService.java @@ -263,7 +263,7 @@ public class BluetoothMapService extends ProfileService { } if (mBluetoothMnsObexClient != null) { - mBluetoothMnsObexClient.disconnect(); + mBluetoothMnsObexClient.shutdown(); mBluetoothMnsObexClient = null; } @@ -324,7 +324,7 @@ public class BluetoothMapService extends ProfileService { mAcceptThread = null; if(mBluetoothMnsObexClient != null) { - mBluetoothMnsObexClient.disconnect(); + mBluetoothMnsObexClient.shutdown(); mBluetoothMnsObexClient = null; } closeConnectionSocket(); @@ -515,7 +515,7 @@ public class BluetoothMapService extends ProfileService { 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 f419bddb..c57a0892 100644 --- a/src/com/android/bluetooth/map/BluetoothMnsObexClient.java +++ b/src/com/android/bluetooth/map/BluetoothMnsObexClient.java @@ -112,19 +112,11 @@ public class BluetoothMnsObexClient { 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 @@ public class BluetoothMnsObexClient { 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 @@ public class BluetoothMnsObexClient { 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 -- 2.11.0