Loading android/app/src/com/android/bluetooth/mapclient/MnsService.java +26 −3 Original line number Original line Diff line number Diff line Loading @@ -50,26 +50,49 @@ class MnsService { private static MapClientService mContext; private static MapClientService mContext; private volatile boolean mShutdown = false; // Used to interrupt socket accept thread private volatile boolean mShutdown = false; // Used to interrupt socket accept thread private int mSdpHandle = -1; MnsService(MapClientService context) { MnsService(MapClientService context) { if (VDBG) Log.v(TAG, "MnsService()"); if (VDBG) Log.v(TAG, "MnsService()"); mContext = context; mContext = context; mAcceptThread = new SocketAcceptor(); mAcceptThread = new SocketAcceptor(); mServerSockets = ObexServerSockets.create(mAcceptThread); mServerSockets = ObexServerSockets.create(mAcceptThread); SdpManager.getDefaultManager().createMapMnsRecord( SdpManager sdpManager = SdpManager.getDefaultManager(); "MAP Message Notification Service", mServerSockets.getRfcommChannel(), -1, if (sdpManager == null) { MNS_VERSION, MNS_FEATURE_BITS); Log.e(TAG, "SdpManager is null"); return; } mSdpHandle = sdpManager.createMapMnsRecord("MAP Message Notification Service", mServerSockets.getRfcommChannel(), -1, MNS_VERSION, MNS_FEATURE_BITS); } } void stop() { void stop() { if (VDBG) Log.v(TAG, "stop()"); if (VDBG) Log.v(TAG, "stop()"); mShutdown = true; mShutdown = true; cleanUpSdpRecord(); if (mServerSockets != null) { if (mServerSockets != null) { mServerSockets.shutdown(false); mServerSockets.shutdown(false); mServerSockets = null; mServerSockets = null; } } } } private void cleanUpSdpRecord() { if (mSdpHandle < 0) { Log.e(TAG, "cleanUpSdpRecord, SDP record never created"); return; } int sdpHandle = mSdpHandle; mSdpHandle = -1; SdpManager sdpManager = SdpManager.getDefaultManager(); if (sdpManager == null) { Log.e(TAG, "cleanUpSdpRecord failed, sdpManager is null, sdpHandle=" + sdpHandle); return; } Log.i(TAG, "cleanUpSdpRecord, mSdpHandle=" + sdpHandle); if (!sdpManager.removeSdpRecord(sdpHandle)) { Log.e(TAG, "cleanUpSdpRecord, removeSdpRecord failed, sdpHandle=" + sdpHandle); } } private class SocketAcceptor implements IObexConnectionHandler { private class SocketAcceptor implements IObexConnectionHandler { Loading Loading
android/app/src/com/android/bluetooth/mapclient/MnsService.java +26 −3 Original line number Original line Diff line number Diff line Loading @@ -50,26 +50,49 @@ class MnsService { private static MapClientService mContext; private static MapClientService mContext; private volatile boolean mShutdown = false; // Used to interrupt socket accept thread private volatile boolean mShutdown = false; // Used to interrupt socket accept thread private int mSdpHandle = -1; MnsService(MapClientService context) { MnsService(MapClientService context) { if (VDBG) Log.v(TAG, "MnsService()"); if (VDBG) Log.v(TAG, "MnsService()"); mContext = context; mContext = context; mAcceptThread = new SocketAcceptor(); mAcceptThread = new SocketAcceptor(); mServerSockets = ObexServerSockets.create(mAcceptThread); mServerSockets = ObexServerSockets.create(mAcceptThread); SdpManager.getDefaultManager().createMapMnsRecord( SdpManager sdpManager = SdpManager.getDefaultManager(); "MAP Message Notification Service", mServerSockets.getRfcommChannel(), -1, if (sdpManager == null) { MNS_VERSION, MNS_FEATURE_BITS); Log.e(TAG, "SdpManager is null"); return; } mSdpHandle = sdpManager.createMapMnsRecord("MAP Message Notification Service", mServerSockets.getRfcommChannel(), -1, MNS_VERSION, MNS_FEATURE_BITS); } } void stop() { void stop() { if (VDBG) Log.v(TAG, "stop()"); if (VDBG) Log.v(TAG, "stop()"); mShutdown = true; mShutdown = true; cleanUpSdpRecord(); if (mServerSockets != null) { if (mServerSockets != null) { mServerSockets.shutdown(false); mServerSockets.shutdown(false); mServerSockets = null; mServerSockets = null; } } } } private void cleanUpSdpRecord() { if (mSdpHandle < 0) { Log.e(TAG, "cleanUpSdpRecord, SDP record never created"); return; } int sdpHandle = mSdpHandle; mSdpHandle = -1; SdpManager sdpManager = SdpManager.getDefaultManager(); if (sdpManager == null) { Log.e(TAG, "cleanUpSdpRecord failed, sdpManager is null, sdpHandle=" + sdpHandle); return; } Log.i(TAG, "cleanUpSdpRecord, mSdpHandle=" + sdpHandle); if (!sdpManager.removeSdpRecord(sdpHandle)) { Log.e(TAG, "cleanUpSdpRecord, removeSdpRecord failed, sdpHandle=" + sdpHandle); } } private class SocketAcceptor implements IObexConnectionHandler { private class SocketAcceptor implements IObexConnectionHandler { Loading