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

BluetoothMasClient

public class BluetoothMasClient extends Object

Fields Summary
private static final String
TAG
private static final int
SOCKET_CONNECTED
private static final int
SOCKET_ERROR
public static final int
EVENT_CONNECT
Callback message sent when connection state changes

arg1 is set to {@link #STATUS_OK} when connection is established successfully and {@link #STATUS_FAILED} when connection either failed or was disconnected (depends on request from application)

public static final int
EVENT_UPDATE_INBOX
Callback message sent when MSE accepted update inbox request
public static final int
EVENT_SET_PATH
Callback message sent when path is changed

obj is set to path currently set on MSE

public static final int
EVENT_GET_FOLDER_LISTING
Callback message sent when folder listing is received

obj contains ArrayList of sub-folder names

public static final int
EVENT_GET_FOLDER_LISTING_SIZE
Callback message sent when folder listing size is received

obj contains number of items in folder listing

public static final int
EVENT_GET_MESSAGES_LISTING
Callback message sent when messages listing is received

obj contains ArrayList of {@link BluetoothMapBmessage}

public static final int
EVENT_GET_MESSAGE
Callback message sent when message is received

obj contains {@link BluetoothMapBmessage}

public static final int
EVENT_SET_MESSAGE_STATUS
Callback message sent when message status is changed
public static final int
EVENT_PUSH_MESSAGE
Callback message sent when message is pushed to MSE

obj contains handle of message as allocated by MSE

public static final int
EVENT_SET_NOTIFICATION_REGISTRATION
Callback message sent when notification status is changed

obj contains 1 if notifications are enabled and 0 otherwise

public static final int
EVENT_EVENT_REPORT
Callback message sent when event report is received from MSE to MNS

obj contains {@link BluetoothMapEventReport}

public static final int
EVENT_GET_MESSAGES_LISTING_SIZE
Callback message sent when messages listing size is received

obj contains number of items in messages listing

public static final int
STATUS_OK
Status for callback message when request is successful
public static final int
STATUS_FAILED
Status for callback message when request is not successful
public static final int
PARAMETER_DEFAULT
Constant corresponding to ParameterMask application parameter value in MAP specification
public static final int
PARAMETER_SUBJECT
Constant corresponding to ParameterMask application parameter value in MAP specification
public static final int
PARAMETER_DATETIME
Constant corresponding to ParameterMask application parameter value in MAP specification
public static final int
PARAMETER_SENDER_NAME
Constant corresponding to ParameterMask application parameter value in MAP specification
public static final int
PARAMETER_SENDER_ADDRESSING
Constant corresponding to ParameterMask application parameter value in MAP specification
public static final int
PARAMETER_RECIPIENT_NAME
Constant corresponding to ParameterMask application parameter value in MAP specification
public static final int
PARAMETER_RECIPIENT_ADDRESSING
Constant corresponding to ParameterMask application parameter value in MAP specification
public static final int
PARAMETER_TYPE
Constant corresponding to ParameterMask application parameter value in MAP specification
public static final int
PARAMETER_SIZE
Constant corresponding to ParameterMask application parameter value in MAP specification
public static final int
PARAMETER_RECEPTION_STATUS
Constant corresponding to ParameterMask application parameter value in MAP specification
public static final int
PARAMETER_TEXT
Constant corresponding to ParameterMask application parameter value in MAP specification
public static final int
PARAMETER_ATTACHMENT_SIZE
Constant corresponding to ParameterMask application parameter value in MAP specification
public static final int
PARAMETER_PRIORITY
Constant corresponding to ParameterMask application parameter value in MAP specification
public static final int
PARAMETER_READ
Constant corresponding to ParameterMask application parameter value in MAP specification
public static final int
PARAMETER_SENT
Constant corresponding to ParameterMask application parameter value in MAP specification
public static final int
PARAMETER_PROTECTED
Constant corresponding to ParameterMask application parameter value in MAP specification
public static final int
PARAMETER_REPLYTO_ADDRESSING
Constant corresponding to ParameterMask application parameter value in MAP specification
private final android.bluetooth.BluetoothDevice
mDevice
device associated with client
private final android.bluetooth.BluetoothMasInstance
mMas
MAS instance associated with client
private final android.os.Handler
mCallback
callback handler to application
private ConnectionState
mConnectionState
private boolean
mNotificationEnabled
private SocketConnectThread
mConnectThread
private javax.obex.ObexTransport
mObexTransport
private BluetoothMasObexClientSession
mObexSession
private SessionHandler
mSessionHandler
private BluetoothMnsService
mMnsService
private ArrayDeque
mPath
Constructors Summary
public BluetoothMasClient(android.bluetooth.BluetoothDevice device, android.bluetooth.BluetoothMasInstance mas, android.os.Handler callback)
Constructs client object to communicate with single MAS instance on MSE

param
device {@link BluetoothDevice} corresponding to remote device acting as MSE
param
mas {@link BluetoothMasInstance} object describing MAS instance on remote device
param
callback {@link Handler} object to which callback messages will be sent Each message will have arg1 set to either {@link #STATUS_OK} or {@link #STATUS_FAILED} and arg2 to MAS instance ID. obj in message is event specific.

        mDevice = device;
        mMas = mas;
        mCallback = callback;

        mPath = new ArrayDeque<String>();
    
Methods Summary
public voidconnect()
Connects to MAS instance

Upon completion callback handler will receive {@link #EVENT_CONNECT}

        if (mSessionHandler == null) {
            mSessionHandler = new SessionHandler(this);
        }

        if (mConnectThread == null && mObexSession == null) {
            mConnectionState = ConnectionState.CONNECTING;

            mConnectThread = new SocketConnectThread();
            mConnectThread.start();
        }
    
private booleandisableNotifications()

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

        if (mMnsService != null) {
            mMnsService.unregisterCallback(mMas.getId());
        }

        mMnsService = null;

        BluetoothMasRequest request = new BluetoothMasRequestSetNotificationRegistration(false);
        return mObexSession.makeRequest(request);
    
public voiddisconnect()
Disconnects from MAS instance

Upon completion callback handler will receive {@link #EVENT_CONNECT}

        if (mConnectThread == null && mObexSession == null) {
            return;
        }

        mConnectionState = ConnectionState.DISCONNECTING;

        if (mConnectThread != null) {
            mConnectThread.interrupt();
        }

        if (mObexSession != null) {
            mObexSession.stop();
        }
    
private booleanenableNotifications()

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

        if (mMnsService == null) {
            mMnsService = new BluetoothMnsService();
        }

        mMnsService.registerCallback(mMas.getId(), mSessionHandler);

        BluetoothMasRequest request = new BluetoothMasRequestSetNotificationRegistration(true);
        return mObexSession.makeRequest(request);
    
public voidfinalize()

        disconnect();
    
public java.lang.StringgetCurrentPath()
Gets current path in folder hierarchy

return
current path

        if (mPath.size() == 0) {
            return "";
        }

        Iterator<String> iter = mPath.iterator();

        StringBuilder sb = new StringBuilder(iter.next());

        while (iter.hasNext()) {
            sb.append("/").append(iter.next());
        }

        return sb.toString();
    
public booleangetFolderListing()
Gets list of sub-folders in current folder

Upon completion callback handler will receive {@link #EVENT_GET_FOLDER_LISTING}

return
true if request has been sent, false otherwise

        return getFolderListing((short) 0, (short) 0);
    
public booleangetFolderListing(int maxListCount, int listStartOffset)
Gets list of sub-folders in current folder

Upon completion callback handler will receive {@link #EVENT_GET_FOLDER_LISTING}

param
maxListCount maximum number of items returned or 0 for default value
param
listStartOffset index of first item returned or 0 for default value
return
true if request has been sent, false otherwise
throws
IllegalArgumentException if either maxListCount or listStartOffset are outside allowed range [0..65535]

        if (mObexSession == null) {
            return false;
        }

        BluetoothMasRequest request = new BluetoothMasRequestGetFolderListing(maxListCount,
                listStartOffset);
        return mObexSession.makeRequest(request);
    
public booleangetFolderListingSize()
Gets number of sub-folders in current folder

Upon completion callback handler will receive {@link #EVENT_GET_FOLDER_LISTING_SIZE}

return
true if request has been sent, false otherwise

        if (mObexSession == null) {
            return false;
        }

        BluetoothMasRequest request = new BluetoothMasRequestGetFolderListingSize();
        return mObexSession.makeRequest(request);
    
public android.bluetooth.BluetoothMasInstancegetInstanceData()
Retrieves MAS instance data associated with client

return
instance data object

        return mMas;
    
public booleangetMessage(java.lang.String handle, android.bluetooth.client.map.BluetoothMasClient$CharsetType charset, boolean attachment)
Retrieves message from MSE

Upon completion callback handler will receive {@link #EVENT_GET_MESSAGE}

param
handle handle of message to retrieve
param
charset {@link CharsetType} object corresponding to Charset application parameter in MAP specification
param
attachment corresponds to Attachment application parameter in MAP specification
return
true if request has been sent, false otherwise

        if (mObexSession == null) {
            return false;
        }

        try {
            /* just to validate */
            new BigInteger(handle, 16);
        } catch (NumberFormatException e) {
            return false;
        }

        BluetoothMasRequest request = new BluetoothMasRequestGetMessage(handle, charset,
                attachment);
        return mObexSession.makeRequest(request);
    
public booleangetMessagesListing(java.lang.String folder, int parameters)
Gets list of messages in specified sub-folder

Upon completion callback handler will receive {@link #EVENT_GET_MESSAGES_LISTING}

param
folder name of sub-folder or null for current folder
param
parameters bit-mask specifying requested parameters in listing or 0 for default value
return
true if request has been sent, false otherwise

        return getMessagesListing(folder, parameters, null, (byte) 0, 0, 0);
    
public booleangetMessagesListing(java.lang.String folder, int parameters, android.bluetooth.client.map.BluetoothMasClient$MessagesFilter filter, int subjectLength)
Gets list of messages in specified sub-folder

Upon completion callback handler will receive {@link #EVENT_GET_MESSAGES_LISTING}

param
folder name of sub-folder or null for current folder
param
parameters corresponds to ParameterMask application parameter in MAP specification
param
filter {@link MessagesFilter} object describing filters to be applied on listing by MSE
param
subjectLength maximum length of message subject in returned listing or 0 for default value
return
true if request has been sent, false otherwise
throws
IllegalArgumentException if subjectLength is outside allowed range [0..255]


        return getMessagesListing(folder, parameters, filter, subjectLength, 0, 0);
    
public booleangetMessagesListing(java.lang.String folder, int parameters, android.bluetooth.client.map.BluetoothMasClient$MessagesFilter filter, int subjectLength, int maxListCount, int listStartOffset)
Gets list of messages in specified sub-folder

Upon completion callback handler will receive {@link #EVENT_GET_MESSAGES_LISTING}

param
folder name of sub-folder or null for current folder
param
parameters corresponds to ParameterMask application parameter in MAP specification
param
filter {@link MessagesFilter} object describing filters to be applied on listing by MSE
param
subjectLength maximum length of message subject in returned listing or 0 for default value
param
maxListCount maximum number of items returned or 0 for default value
param
listStartOffset index of first item returned or 0 for default value
return
true if request has been sent, false otherwise
throws
IllegalArgumentException if subjectLength is outside allowed range [0..255] or either maxListCount or listStartOffset are outside allowed range [0..65535]


        if (mObexSession == null) {
            return false;
        }

        BluetoothMasRequest request = new BluetoothMasRequestGetMessagesListing(folder,
                parameters, filter, subjectLength, maxListCount, listStartOffset);
        return mObexSession.makeRequest(request);
    
public booleangetMessagesListingSize()
Gets number of messages in current folder

Upon completion callback handler will receive {@link #EVENT_GET_MESSAGES_LISTING_SIZE}

return
true if request has been sent, false otherwise

        if (mObexSession == null) {
            return false;
        }

        BluetoothMasRequest request = new BluetoothMasRequestGetMessagesListingSize();
        return mObexSession.makeRequest(request);
    
public booleangetNotificationRegistration()
Gets current state of notifications for MAS instance

return
true if notifications are enabled, false otherwise

        return mNotificationEnabled;
    
public android.bluetooth.client.map.BluetoothMasClient$ConnectionStategetState()
Gets current connection state

return
current connection state
see
ConnectionState

        return mConnectionState;
    
public booleanpushMessage(java.lang.String folder, BluetoothMapBmessage bmsg, android.bluetooth.client.map.BluetoothMasClient$CharsetType charset)
Pushes new message to MSE

Upon completion callback handler will receive {@link #EVENT_PUSH_MESSAGE}

param
folder name of sub-folder to push to or null for current folder
param
charset {@link CharsetType} object corresponding to Charset application parameter in MAP specification
return
true if request has been sent, false otherwise

        return pushMessage(folder, bmsg, charset, false, false);
    
public booleanpushMessage(java.lang.String folder, BluetoothMapBmessage bmsg, android.bluetooth.client.map.BluetoothMasClient$CharsetType charset, boolean transparent, boolean retry)
Pushes new message to MSE

Upon completion callback handler will receive {@link #EVENT_PUSH_MESSAGE}

param
folder name of sub-folder to push to or null for current folder
param
bmsg {@link BluetoothMapBmessage} object representing message to be pushed
param
charset {@link CharsetType} object corresponding to Charset application parameter in MAP specification
param
transparent corresponds to Transparent application parameter in MAP specification
param
retry corresponds to Transparent application parameter in MAP specification
return
true if request has been sent, false otherwise

        if (mObexSession == null) {
            return false;
        }

        String bmsgString = BluetoothMapBmessageBuilder.createBmessage(bmsg);

        BluetoothMasRequest request =
                new BluetoothMasRequestPushMessage(folder, bmsgString, charset, transparent, retry);
        return mObexSession.makeRequest(request);
    
private voidsendToClient(int event, boolean success)

        sendToClient(event, success, null);
    
private voidsendToClient(int event, boolean success, int param)

        sendToClient(event, success, Integer.valueOf(param));
    
private voidsendToClient(int event, boolean success, java.lang.Object param)

        if (success) {
            mCallback.obtainMessage(event, STATUS_OK, mMas.getId(), param).sendToTarget();
        } else {
            mCallback.obtainMessage(event, STATUS_FAILED, mMas.getId(), null).sendToTarget();
        }
    
public booleansetFolderDown(java.lang.String name)
Goes down to specified sub-folder in folder hierarchy

Upon completion callback handler will receive {@link #EVENT_SET_PATH}

param
name name of sub-folder
return
true if request has been sent, false otherwise

        if (mObexSession == null) {
            return false;
        }

        if (name == null || name.isEmpty() || name.contains("/")) {
            return false;
        }

        BluetoothMasRequest request = new BluetoothMasRequestSetPath(name);
        return mObexSession.makeRequest(request);
    
public booleansetFolderRoot()
Goes back to root of folder hierarchy

Upon completion callback handler will receive {@link #EVENT_SET_PATH}

return
true if request has been sent, false otherwise

        if (mObexSession == null) {
            return false;
        }

        BluetoothMasRequest request = new BluetoothMasRequestSetPath(true);
        return mObexSession.makeRequest(request);
    
public booleansetFolderUp()
Goes back to parent folder in folder hierarchy

Upon completion callback handler will receive {@link #EVENT_SET_PATH}

return
true if request has been sent, false otherwise

        if (mObexSession == null) {
            return false;
        }

        BluetoothMasRequest request = new BluetoothMasRequestSetPath(false);
        return mObexSession.makeRequest(request);
    
public booleansetMessageDeletedStatus(java.lang.String handle, boolean deleted)
Sets deleted status of message on MSE

Upon completion callback handler will receive {@link #EVENT_SET_MESSAGE_STATUS}

param
handle handle of message
param
deleted true for "deleted", false for "undeleted"
return
true if request has been sent, false otherwise

        if (mObexSession == null) {
            return false;
        }

        try {
            /* just to validate */
            new BigInteger(handle, 16);
        } catch (NumberFormatException e) {
            return false;
        }

        BluetoothMasRequest request = new BluetoothMasRequestSetMessageStatus(handle,
                StatusIndicator.DELETED, deleted);
        return mObexSession.makeRequest(request);
    
public booleansetMessageReadStatus(java.lang.String handle, boolean read)
Sets read status of message on MSE

Upon completion callback handler will receive {@link #EVENT_SET_MESSAGE_STATUS}

param
handle handle of message
param
read true for "read", false for "unread"
return
true if request has been sent, false otherwise

        if (mObexSession == null) {
            return false;
        }

        try {
            /* just to validate */
            new BigInteger(handle, 16);
        } catch (NumberFormatException e) {
            return false;
        }

        BluetoothMasRequest request = new BluetoothMasRequestSetMessageStatus(handle,
                StatusIndicator.READ, read);
        return mObexSession.makeRequest(request);
    
public booleansetNotificationRegistration(boolean status)
Sets state of notifications for MAS instance

Once notifications are enabled, callback handler will receive {@link #EVENT_EVENT_REPORT} when new notification is received

Upon completion callback handler will receive {@link #EVENT_SET_NOTIFICATION_REGISTRATION}

param
status true if notifications shall be enabled, false otherwise
return
true if request has been sent, false otherwise

        if (mObexSession == null) {
            return false;
        }

        if (status) {
            return enableNotifications();
        } else {
            return disableNotifications();
        }
    
public booleanupdateInbox()
Requests MSE to initiate ubdate of inbox

Upon completion callback handler will receive {@link #EVENT_UPDATE_INBOX}

return
true if request has been sent, false otherwise

        if (mObexSession == null) {
            return false;
        }

        BluetoothMasRequest request = new BluetoothMasRequestUpdateInbox();
        return mObexSession.makeRequest(request);