diff options
author | Nitin Shivpure <nshivpur@codeaurora.org> | 2014-11-21 18:44:35 +0530 |
---|---|---|
committer | Linux Build Service Account <lnxbuild@localhost> | 2015-10-06 03:23:56 -0600 |
commit | e5b6f5cef135835f96104e67005743a8b1f14deb (patch) | |
tree | e9bba53218202550ae6033d1b3dd90a5127a2fee | |
parent | 4231be1e03b7c5e563fea1fa7c56abfe2a1e61dd (diff) | |
download | android_frameworks_opt_bluetooth-e5b6f5cef135835f96104e67005743a8b1f14deb.tar.gz android_frameworks_opt_bluetooth-e5b6f5cef135835f96104e67005743a8b1f14deb.tar.bz2 android_frameworks_opt_bluetooth-e5b6f5cef135835f96104e67005743a8b1f14deb.zip |
Bluetooth: Add support for Map client over L2cap
- Add support for Map client(MAP1.2) over L2cap.
- Add support to parse Extended Map-Event-report 1.1
on MCE.
Change-Id: Iec1aa98555399bfa7ad51b8386124b1fb1ef5d44
CRs-Fixed: 754956
-rw-r--r-- | src/android/bluetooth/client/map/BluetoothMapEventReport.java | 85 | ||||
-rw-r--r-- | src/android/bluetooth/client/map/BluetoothMapTransport.java (renamed from src/android/bluetooth/client/map/BluetoothMapRfcommTransport.java) | 22 | ||||
-rw-r--r-- | src/android/bluetooth/client/map/BluetoothMasClient.java | 55 | ||||
-rw-r--r-- | src/android/bluetooth/client/map/BluetoothMasObexClientSession.java | 25 | ||||
-rw-r--r-- | src/android/bluetooth/client/map/BluetoothMasRequest.java | 7 | ||||
-rw-r--r-- | src/android/bluetooth/client/map/BluetoothMnsService.java | 230 |
6 files changed, 356 insertions, 68 deletions
diff --git a/src/android/bluetooth/client/map/BluetoothMapEventReport.java b/src/android/bluetooth/client/map/BluetoothMapEventReport.java index 5963db4..0a403b5 100644 --- a/src/android/bluetooth/client/map/BluetoothMapEventReport.java +++ b/src/android/bluetooth/client/map/BluetoothMapEventReport.java @@ -37,13 +37,14 @@ import java.util.HashMap; public class BluetoothMapEventReport { private final static String TAG = "BluetoothMapEventReport"; + public final static String EXTENDED_EVENT_REPORT_1_1 = "1.1"; public enum Type { NEW_MESSAGE("NewMessage"), DELIVERY_SUCCESS("DeliverySuccess"), SENDING_SUCCESS("SendingSuccess"), DELIVERY_FAILURE("DeliveryFailure"), SENDING_FAILURE("SendingFailure"), MEMORY_FULL("MemoryFull"), MEMORY_AVAILABLE("MemoryAvailable"), MESSAGE_DELETED("MessageDeleted"), - MESSAGE_SHIFT("MessageShift"); + MESSAGE_SHIFT("MessageShift"), READ_STATUS_CHANGED("ReadStatusChanged"); private final String mSpecName; @@ -57,6 +58,8 @@ public class BluetoothMapEventReport { } } + private final String mVersion; + private final Type mType; private final String mHandle; @@ -67,7 +70,18 @@ public class BluetoothMapEventReport { private final BluetoothMapBmessage.Type mMsgType; + private final String mSubject; + + private final String mDatetime; + + private final String mSenderName; + + private final String mPriority; + private BluetoothMapEventReport(HashMap<String, String> attrs) throws IllegalArgumentException { + + mVersion = attrs.get("version"); + mType = parseType(attrs.get("type")); if (mType != Type.MEMORY_FULL && mType != Type.MEMORY_AVAILABLE) { @@ -102,6 +116,22 @@ public class BluetoothMapEventReport { } else { mMsgType = null; } + + if (mType == Type.NEW_MESSAGE && mVersion.equals(EXTENDED_EVENT_REPORT_1_1)) { + mSubject = attrs.get("subject"); + mDatetime = attrs.get("datetime"); + mSenderName = attrs.get("sender_name"); + mPriority = attrs.get("priority"); + + Log.d(TAG, "received extended event report 1.1 for new message" + + " Subject: " + mSubject + " Datetime: " + mDatetime + + " sender_name: " + mSenderName + " Priority: " + mPriority); + } else { + mSubject = null; + mDatetime = null; + mSenderName = null; + mPriority = null; + } } private Type parseType(String type) throws IllegalArgumentException { @@ -125,6 +155,14 @@ public class BluetoothMapEventReport { } /** + * @return value corresponding to <code>version</code> parameter in MAP + * specification + */ + public String getVersion() { + return mVersion; + } + + /** * @return {@link BluetoothMapEventReport.Type} object corresponding to * <code>type</code> application parameter in MAP specification */ @@ -164,16 +202,53 @@ public class BluetoothMapEventReport { return mMsgType; } + /** + * @return value corresponding to <code>subject</code> parameter in MAP + * specification + */ + public String getSubject() { + return mSubject; + } + + /** + * @return value corresponding to <code>datetime"</code> parameter in MAP + * specification + */ + public String getDatetime() { + return mDatetime; + } + + /** + * @return value corresponding to <code>sender_name"</code> parameter in MAP + * specification + */ + public String getSenderName() { + return mSenderName; + } + + /** + * @return value corresponding to <code>priority"</code> parameter in MAP + * specification + */ + public String getPriority() { + return mPriority; + } + @Override public String toString() { JSONObject json = new JSONObject(); try { + json.put("version", mVersion); json.put("type", mType); json.put("handle", mHandle); json.put("folder", mFolder); json.put("old_folder", mOldFolder); json.put("msg_type", mMsgType); + json.put("subject", mSubject); + json.put("datetime", mDatetime); + json.put("sender_name", mSenderName); + json.put("priority", mPriority); } catch (JSONException e) { // do nothing } @@ -188,13 +263,17 @@ public class BluetoothMapEventReport { XmlPullParser xpp = XmlPullParserFactory.newInstance().newPullParser(); xpp.setInput(in, "utf-8"); + HashMap<String, String> attrs = new HashMap<String, String>(); int event = xpp.getEventType(); while (event != XmlPullParser.END_DOCUMENT) { switch (event) { case XmlPullParser.START_TAG: - if (xpp.getName().equals("event")) { - HashMap<String, String> attrs = new HashMap<String, String>(); + if (xpp.getName().equals("MAP-event-report")) { + Log.d(TAG, "MAP-event-report version: " + xpp.getAttributeValue(0)); + attrs.put(xpp.getAttributeName(0), xpp.getAttributeValue(0)); + } + if (xpp.getName().equals("event")) { for (int i = 0; i < xpp.getAttributeCount(); i++) { attrs.put(xpp.getAttributeName(i), xpp.getAttributeValue(i)); } diff --git a/src/android/bluetooth/client/map/BluetoothMapRfcommTransport.java b/src/android/bluetooth/client/map/BluetoothMapTransport.java index 5bec982..38fd471 100644 --- a/src/android/bluetooth/client/map/BluetoothMapRfcommTransport.java +++ b/src/android/bluetooth/client/map/BluetoothMapTransport.java @@ -25,13 +25,17 @@ import java.io.InputStream; import java.io.OutputStream; import javax.obex.ObexTransport; +import javax.obex.ObexHelper; -class BluetoothMapRfcommTransport implements ObexTransport { +class BluetoothMapTransport implements ObexTransport { + private static final String TAG = "BluetoothMapTransport"; private final BluetoothSocket mSocket; + public final int mType; - public BluetoothMapRfcommTransport(BluetoothSocket socket) { + public BluetoothMapTransport(BluetoothSocket socket, int type) { super(); - mSocket = socket; + this.mSocket = socket; + this.mType = type; } @Override @@ -77,16 +81,22 @@ class BluetoothMapRfcommTransport implements ObexTransport { @Override public int getMaxTransmitPacketSize() { - return -1; + if (mSocket.getConnectionType() != BluetoothSocket.TYPE_L2CAP) { + return -1; + } + return mSocket.getMaxTransmitPacketSize(); } @Override public int getMaxReceivePacketSize() { - return -1; + if (mSocket.getConnectionType() != BluetoothSocket.TYPE_L2CAP) { + return -1; + } + return mSocket.getMaxReceivePacketSize(); } @Override public boolean isSrmSupported() { - return false; + return mType == BluetoothSocket.TYPE_L2CAP; } } diff --git a/src/android/bluetooth/client/map/BluetoothMasClient.java b/src/android/bluetooth/client/map/BluetoothMasClient.java index 7f71693..ea24db3 100644 --- a/src/android/bluetooth/client/map/BluetoothMasClient.java +++ b/src/android/bluetooth/client/map/BluetoothMasClient.java @@ -45,6 +45,8 @@ public class BluetoothMasClient { private static final int SOCKET_ERROR = 11; + private static final int L2CAP_INVALID_PSM = -1; + /** * Callback message sent when connection state changes * <p> @@ -323,7 +325,7 @@ public class BluetoothMasClient { if (client == null) { return; } - Log.v(TAG, "handleMessage "+msg.what); + Log.v(TAG, "handleMessage " + msg.what); switch (msg.what) { case SOCKET_ERROR: @@ -348,6 +350,10 @@ public class BluetoothMasClient { break; case BluetoothMasObexClientSession.MSG_OBEX_DISCONNECTED: + if (client.mMnsService != null) { + //Special case, when Mas session is disconnected before Mns Session + client.mMnsService.unregisterCallback(client.mMas.getMasInstanceId()); + } client.mConnectionState = ConnectionState.DISCONNECTED; client.mNotificationEnabled = false; client.mObexSession = null; @@ -467,20 +473,53 @@ public class BluetoothMasClient { @Override public void run() { + int btMasTransportType; + if (connectL2capSocket()) + btMasTransportType = BluetoothSocket.TYPE_L2CAP; + else if (connectRfcommSocket()) + btMasTransportType = BluetoothSocket.TYPE_RFCOMM; + else + { + Log.e(TAG, "Error when creating/connecting L2CAP/RFCOMM socket"); + return; + } + BluetoothMapTransport transport; + transport = new BluetoothMapTransport(socket, btMasTransportType); + + mSessionHandler.obtainMessage(SOCKET_CONNECTED, transport).sendToTarget(); + } + + private boolean connectL2capSocket() { try { - socket = mDevice.createRfcommSocket(mMas.getRfcommCannelNumber()); - socket.connect(); + /* Use BluetoothSocket to connect */ + Log.v(TAG,"connectL2capSocket: PSM: " + mMas.getL2capPsm()); + if (mMas.getL2capPsm() != L2CAP_INVALID_PSM) { + socket = mDevice.createL2capSocket(mMas.getL2capPsm()); + socket.connect(); + } else { + return false; + } - BluetoothMapRfcommTransport transport; - transport = new BluetoothMapRfcommTransport(socket); + } catch (IOException e) { + Log.e(TAG, "Error when creating/connecting L2cap socket", e); + return false; + } + return true; + } - mSessionHandler.obtainMessage(SOCKET_CONNECTED, transport).sendToTarget(); + private boolean connectRfcommSocket() { + try { + /* Use BluetoothSocket to connect */ + Log.v(TAG,"connectRfcommSocket: channel: " + mMas.getRfcommCannelNumber()); + socket = mDevice.createRfcommSocket(mMas.getRfcommCannelNumber()); + socket.connect(); } catch (IOException e) { Log.e(TAG, "Error when creating/connecting socket", e); - closeSocket(); mSessionHandler.obtainMessage(SOCKET_ERROR).sendToTarget(); + return false; } + return true; } @Override @@ -674,7 +713,7 @@ public class BluetoothMasClient { } private boolean disableNotifications() { - Log.v(TAG, "enableNotifications()"); + Log.v(TAG, "disableNotifications()"); if (mMnsService != null) { mMnsService.unregisterCallback(mMas.getMasInstanceId()); diff --git a/src/android/bluetooth/client/map/BluetoothMasObexClientSession.java b/src/android/bluetooth/client/map/BluetoothMasObexClientSession.java index f949b8d..025bd7a 100644 --- a/src/android/bluetooth/client/map/BluetoothMasObexClientSession.java +++ b/src/android/bluetooth/client/map/BluetoothMasObexClientSession.java @@ -25,6 +25,7 @@ import java.io.IOException; import javax.obex.ClientSession; import javax.obex.HeaderSet; import javax.obex.ObexTransport; +import javax.obex.ObexHelper; import javax.obex.ResponseCodes; class BluetoothMasObexClientSession { @@ -109,6 +110,7 @@ class BluetoothMasObexClientSession { private void connect() { try { + Log.w(TAG, "connect:"); mSession = new ClientSession(mTransport); HeaderSet headerset = new HeaderSet(); @@ -122,10 +124,12 @@ class BluetoothMasObexClientSession { disconnect(); } } catch (IOException e) { + Log.w(TAG, "handled connect exception: ", e); } } private void disconnect() { + Log.w(TAG, "disconnect: "); try { mSession.disconnect(null); } catch (IOException e) { @@ -134,6 +138,7 @@ class BluetoothMasObexClientSession { try { mSession.close(); } catch (IOException e) { + Log.w(TAG, "handled disconnect exception:", e); } mConnected = false; @@ -187,6 +192,26 @@ class BluetoothMasObexClientSession { return false; } + if (((BluetoothMapTransport)mTransport).isSrmSupported()) { + Log.d(TAG, "Client is srm capable"); + if (request instanceof BluetoothMasRequestGetFolderListing || + request instanceof BluetoothMasRequestGetFolderListingSize || + request instanceof BluetoothMasRequestGetMessagesListing || + request instanceof BluetoothMasRequestGetMessage || + request instanceof BluetoothMasRequestPushMessage || + request instanceof BluetoothMasRequestGetMessagesListingSize) { + mClientThread.mSession.setLocalSrmStatus(true); + } + + if (request instanceof BluetoothMasRequestSetMessageStatus || + request instanceof BluetoothMasRequestUpdateInbox|| + request instanceof BluetoothMasRequestSetNotificationRegistration) { + mClientThread.mSession.setLocalSrmStatus(false); + } + } else { + Log.d(TAG, "Client is not srm capable"); + } + return mClientThread.schedule(request); } } diff --git a/src/android/bluetooth/client/map/BluetoothMasRequest.java b/src/android/bluetooth/client/map/BluetoothMasRequest.java index 0c9c29c..2a8abfe 100644 --- a/src/android/bluetooth/client/map/BluetoothMasRequest.java +++ b/src/android/bluetooth/client/map/BluetoothMasRequest.java @@ -25,8 +25,10 @@ import javax.obex.ClientSession; import javax.obex.HeaderSet; import javax.obex.Operation; import javax.obex.ResponseCodes; +import android.util.Log; abstract class BluetoothMasRequest { + private final static String TAG = "BluetoothMasRequest"; protected static final byte OAP_TAGID_MAX_LIST_COUNT = 0x01; protected static final byte OAP_TAGID_START_OFFSET = 0x02; @@ -120,7 +122,7 @@ abstract class BluetoothMasRequest { mResponseCode = op.getResponseCode(); } catch (IOException e) { mResponseCode = ResponseCodes.OBEX_HTTP_INTERNAL_ERROR; - + Log.w(TAG, "executeGet: ", e); throw e; } } @@ -143,12 +145,13 @@ abstract class BluetoothMasRequest { mResponseCode = op.getResponseCode(); } catch (IOException e) { mResponseCode = ResponseCodes.OBEX_HTTP_INTERNAL_ERROR; - + Log.w(TAG, "executePut: ", e); throw e; } } final public boolean isSuccess() { + Log.w(TAG, "isSuccess: " + mResponseCode); return (mResponseCode == ResponseCodes.OBEX_HTTP_OK); } diff --git a/src/android/bluetooth/client/map/BluetoothMnsService.java b/src/android/bluetooth/client/map/BluetoothMnsService.java index 42175e0..c95b794 100644 --- a/src/android/bluetooth/client/map/BluetoothMnsService.java +++ b/src/android/bluetooth/client/map/BluetoothMnsService.java @@ -45,9 +45,15 @@ class BluetoothMnsService { /* these are shared across instances */ static private SparseArray<Handler> mCallbacks = null; - static private SocketAcceptThread mAcceptThread = null; + static private RfcommSocketAcceptThread mRfcommAcceptThread = null; + static private L2capSocketAcceptThread mL2capAcceptThread = null; static private Handler mSessionHandler = null; - static private BluetoothServerSocket mServerSocket = null; + static private BluetoothServerSocket mRfcommServerSocket = null; + static private BluetoothServerSocket mL2capServerSocket = null; + static private ServerSession mMnsServerSession = null; + private static final int SDP_MAP_MNS_VERSION = 0x0102; + private static final int SDP_MAP_MNS_FEATURES = 0x0000007F; + private int mMnsSdpHandle = -1;; private static class SessionHandler extends Handler { @@ -81,55 +87,80 @@ class BluetoothMnsService { } } - private static class SocketAcceptThread extends Thread { + private static class RfcommSocketAcceptThread extends Thread { private boolean mInterrupted = false; @Override public void run() { - if (mServerSocket != null) { - Log.w(TAG, "Socket already created, exiting"); - return; + while (!mInterrupted) { + try { + Log.v(TAG, "waiting to accept connection on Rfcomm socket..."); + + BluetoothSocket sock = mRfcommServerSocket.accept(); + + Log.v(TAG, "new incoming connection from " + + sock.getRemoteDevice().getName() + " on rfcomm socket"); + + // session will live until closed by remote + BluetoothMnsObexServer srv = new BluetoothMnsObexServer(mSessionHandler); + BluetoothMapTransport transport = new BluetoothMapTransport( + sock, BluetoothSocket.TYPE_RFCOMM); + mMnsServerSession = new ServerSession(transport, srv, null); + } catch (IOException ex) { + Log.v(TAG, "I/O exception when waiting to accept (aborted)"); + mInterrupted = true; + } } - try { - BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); - mServerSocket = adapter.listenUsingEncryptedRfcommWithServiceRecord( - "MAP Message Notification Service", MAP_MNS.getUuid()); - } catch (IOException e) { - mInterrupted = true; - Log.e(TAG, "I/O exception when trying to create server socket", e); + if (mRfcommServerSocket != null) { + try { + mRfcommServerSocket.close(); + } catch (IOException e) { + Log.v(TAG, "I/O exception while closing rfcomm socket", e); + } + + mRfcommServerSocket = null; } + } + } + + private static class L2capSocketAcceptThread extends Thread { + + private boolean mInterrupted = false; + + @Override + public void run() { while (!mInterrupted) { try { - Log.v(TAG, "waiting to accept connection..."); + Log.v(TAG, "waiting to accept connection on l2cap socket..."); - BluetoothSocket sock = mServerSocket.accept(); + BluetoothSocket sock = mL2capServerSocket.accept(); Log.v(TAG, "new incoming connection from " - + sock.getRemoteDevice().getName()); + + sock.getRemoteDevice().getName() + " on l2cap socket"); // session will live until closed by remote BluetoothMnsObexServer srv = new BluetoothMnsObexServer(mSessionHandler); - BluetoothMapRfcommTransport transport = new BluetoothMapRfcommTransport( - sock); - new ServerSession(transport, srv, null); + BluetoothMapTransport transport = new BluetoothMapTransport( + sock, BluetoothSocket.TYPE_L2CAP); + mMnsServerSession = new ServerSession(transport, srv, null); } catch (IOException ex) { - Log.v(TAG, "I/O exception when waiting to accept (aborted?)"); + Log.v(TAG, "I/O exception when waiting to accept (aborted)"); mInterrupted = true; } } - if (mServerSocket != null) { + if (mL2capServerSocket != null) { try { - mServerSocket.close(); + mL2capServerSocket.close(); } catch (IOException e) { - // do nothing + Log.v(TAG, "I/O exception while closing l2cap socket", e); } - mServerSocket = null; + mL2capServerSocket = null; } } } @@ -148,47 +179,148 @@ class BluetoothMnsService { } } + private void startServerSocketsListener() { + BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); + int socketChannel = BluetoothAdapter.SOCKET_CHANNEL_AUTO_STATIC_NO_SDP; + boolean initSocketOK = true; + String createSocketType = new String("rfcomm server socket"); + + Log.v(TAG, "startServerSocketsListener: mRfcommServerSocket: " + mRfcommServerSocket + + " mL2capServerSocket: " + mL2capServerSocket); + + try { + if (mRfcommServerSocket == null) { + mRfcommServerSocket = adapter.listenUsingRfcommOn(socketChannel); + } + + createSocketType = "l2cap server socket"; + if (mL2capServerSocket == null) { + mL2capServerSocket = adapter.listenUsingL2capOn(socketChannel); + } + } catch (IOException e) { + Log.e(TAG, "I/O exception when trying to create " + createSocketType, e); + initSocketOK =false; + } + + if (initSocketOK) { + startAcceptThread(); + if(mMnsSdpHandle >= 0) { + Log.d(TAG, "Removing Mns SDP record: " + mMnsSdpHandle); + adapter.removeSdpRecord(mMnsSdpHandle); + mMnsSdpHandle = -1; + } + mMnsSdpHandle = adapter.createMapMnsSdpRecord("MAP Message Notification Service", + mRfcommServerSocket.getChannel(), mL2capServerSocket.getChannel(), + SDP_MAP_MNS_VERSION, SDP_MAP_MNS_FEATURES); + } + } + + private void startAcceptThread() { + Log.v(TAG, "startAcceptThread: mRfcommAcceptThread: " + mRfcommAcceptThread + + "mL2capAcceptThread: " + mL2capAcceptThread); + if (mRfcommAcceptThread == null) { + mRfcommAcceptThread = new RfcommSocketAcceptThread(); + mRfcommAcceptThread.setName("BluetoothMnsRfcommAcceptThread"); + mRfcommAcceptThread.start(); + } + + if (mL2capAcceptThread == null) { + mL2capAcceptThread = new L2capSocketAcceptThread(); + mL2capAcceptThread.setName("BluetoothMnsL2capAcceptThread"); + mL2capAcceptThread.start(); + } + } + + public void closeServerSockets() { + closeRfcommSocket(); + closeL2capSocket(); + } + + public void closeRfcommSocket() + { + Log.v(TAG, "closeRfcommSocket(): mRfcommServerSocket: " + mRfcommServerSocket + + " mRfcommAcceptThread: " + mRfcommAcceptThread); + if (mRfcommServerSocket != null) { + try { + mRfcommServerSocket.close(); + } catch (IOException e) { + Log.v(TAG, "closeRfcommSocket(): " + e); + } + + mRfcommServerSocket = null; + } + + if (mRfcommAcceptThread != null) { + + mRfcommAcceptThread.interrupt(); + + try { + mRfcommAcceptThread.join(2000); + } catch (InterruptedException e) { + Log.v(TAG, "closeRfcommSocket(): " + e); + } + + mRfcommAcceptThread = null; + } + } + + public void closeL2capSocket() + { + Log.v(TAG, "closeL2capSocket(): mL2capServerSocket: " + mL2capServerSocket + + " mL2capAcceptThread: " + mL2capAcceptThread); + if (mL2capServerSocket != null) { + try { + mL2capServerSocket.close(); + } catch (IOException e) { + Log.v(TAG, "closeL2capSocket(): " + e); + } + + mL2capServerSocket = null; + } + + if (mL2capAcceptThread != null) { + + mL2capAcceptThread.interrupt(); + + try { + mL2capAcceptThread.join(2000); + } catch (InterruptedException e) { + Log.v(TAG, "closeL2capSocket(): " + e); + } + + mL2capAcceptThread = null; + } + } + public void registerCallback(int instanceId, Handler callback) { - Log.v(TAG, "registerCallback()"); synchronized (mCallbacks) { - mCallbacks.put(instanceId, callback); - - if (mAcceptThread == null) { + Log.v(TAG, "registerCallback(): cb: " + mCallbacks.size()); + if (mCallbacks.size() == 0) { Log.v(TAG, "registerCallback(): starting MNS server"); - mAcceptThread = new SocketAcceptThread(); - mAcceptThread.setName("BluetoothMnsAcceptThread"); - mAcceptThread.start(); + startServerSocketsListener(); } + mCallbacks.put(instanceId, callback); } } public void unregisterCallback(int instanceId) { - Log.v(TAG, "unregisterCallback()"); synchronized (mCallbacks) { + Log.v(TAG, "unregisterCallback(): instanceId: " + instanceId + + " cb: " + mCallbacks.size()); mCallbacks.remove(instanceId); if (mCallbacks.size() == 0) { - Log.v(TAG, "unregisterCallback(): shutting down MNS server"); - - if (mServerSocket != null) { - try { - mServerSocket.close(); - } catch (IOException e) { - } + Log.v(TAG, "unregisterCallback(): shutting down MNS server: mMnsServerSession: " + + mMnsServerSession); - mServerSocket = null; + if(mMnsSdpHandle >= 0) { + Log.d(TAG, "Removing Mns SDP record: " + mMnsSdpHandle); + BluetoothAdapter.getDefaultAdapter().removeSdpRecord(mMnsSdpHandle); + mMnsSdpHandle = -1; } - - mAcceptThread.interrupt(); - - try { - mAcceptThread.join(5000); - } catch (InterruptedException e) { - } - - mAcceptThread = null; + closeServerSockets(); } } } |