FileDocCategorySizeDatePackage
BluetoothMnsService.javaAPI DocAndroid 5.1 API6396Thu Mar 12 22:22:50 GMT 2015android.bluetooth.client.map

BluetoothMnsService

public class BluetoothMnsService extends Object

Fields Summary
private static final String
TAG
private static final android.os.ParcelUuid
MAP_MNS
static final int
MSG_EVENT
static final int
EVENT_REPORT
private static android.util.SparseArray
mCallbacks
private static SocketAcceptThread
mAcceptThread
private static android.os.Handler
mSessionHandler
private static android.bluetooth.BluetoothServerSocket
mServerSocket
Constructors Summary
BluetoothMnsService()

        Log.v(TAG, "BluetoothMnsService()");

        if (mCallbacks == null) {
            Log.v(TAG, "BluetoothMnsService(): allocating callbacks");
            mCallbacks = new SparseArray<Handler>();
        }

        if (mSessionHandler == null) {
            Log.v(TAG, "BluetoothMnsService(): allocating session handler");
            mSessionHandler = new SessionHandler(this);
        }
    
Methods Summary
public voidregisterCallback(int instanceId, android.os.Handler callback)

        Log.v(TAG, "registerCallback()");

        synchronized (mCallbacks) {
            mCallbacks.put(instanceId, callback);

            if (mAcceptThread == null) {
                Log.v(TAG, "registerCallback(): starting MNS server");
                mAcceptThread = new SocketAcceptThread();
                mAcceptThread.setName("BluetoothMnsAcceptThread");
                mAcceptThread.start();
            }
        }
    
public voidunregisterCallback(int instanceId)

        Log.v(TAG, "unregisterCallback()");

        synchronized (mCallbacks) {
            mCallbacks.remove(instanceId);

            if (mCallbacks.size() == 0) {
                Log.v(TAG, "unregisterCallback(): shutting down MNS server");

                if (mServerSocket != null) {
                    try {
                        mServerSocket.close();
                    } catch (IOException e) {
                    }

                    mServerSocket = null;
                }

                mAcceptThread.interrupt();

                try {
                    mAcceptThread.join(5000);
                } catch (InterruptedException e) {
                }

                mAcceptThread = null;
            }
        }