Fields Summary |
---|
private static final String | TAG |
private static final int | RFCOMM_CONNECTED |
private static final int | RFCOMM_FAILED |
public static final int | REQUEST_COMPLETED |
public static final int | REQUEST_FAILED |
public static final int | SESSION_CONNECTING |
public static final int | SESSION_CONNECTED |
public static final int | SESSION_DISCONNECTED |
public static final int | AUTH_REQUESTED |
public static final int | AUTH_TIMEOUT |
public static final int | ACTION_LISTING |
public static final int | ACTION_VCARD |
public static final int | ACTION_PHONEBOOK_SIZE |
private static final String | PBAP_UUID |
private final android.bluetooth.BluetoothAdapter | mAdapter |
private final android.bluetooth.BluetoothDevice | mDevice |
private final android.os.Handler | mParentHandler |
private final android.os.HandlerThread | mHandlerThread |
private final android.os.Handler | mSessionHandler |
private RfcommConnectThread | mConnectThread |
private BluetoothPbapObexTransport | mTransport |
private BluetoothPbapObexSession | mObexSession |
private BluetoothPbapRequest | mPendingRequest |
Methods Summary |
---|
public void | abort()
Log.d(TAG, "abort");
/* fail pending request immediately */
if (mPendingRequest != null) {
mParentHandler.obtainMessage(REQUEST_FAILED, mPendingRequest).sendToTarget();
mPendingRequest = null;
}
if (mObexSession != null) {
mObexSession.abort();
}
|
public boolean | handleMessage(android.os.Message msg)
Log.d(TAG, "Handler: msg: " + msg.what);
switch (msg.what) {
case RFCOMM_FAILED:
mConnectThread = null;
mParentHandler.obtainMessage(SESSION_DISCONNECTED).sendToTarget();
if (mPendingRequest != null) {
mParentHandler.obtainMessage(REQUEST_FAILED, mPendingRequest).sendToTarget();
mPendingRequest = null;
}
break;
case RFCOMM_CONNECTED:
mConnectThread = null;
mTransport = (BluetoothPbapObexTransport) msg.obj;
startObexSession();
break;
case BluetoothPbapObexSession.OBEX_SESSION_FAILED:
stopObexSession();
mParentHandler.obtainMessage(SESSION_DISCONNECTED).sendToTarget();
if (mPendingRequest != null) {
mParentHandler.obtainMessage(REQUEST_FAILED, mPendingRequest).sendToTarget();
mPendingRequest = null;
}
break;
case BluetoothPbapObexSession.OBEX_SESSION_CONNECTED:
mParentHandler.obtainMessage(SESSION_CONNECTED).sendToTarget();
if (mPendingRequest != null) {
mObexSession.schedule(mPendingRequest);
mPendingRequest = null;
}
break;
case BluetoothPbapObexSession.OBEX_SESSION_DISCONNECTED:
mParentHandler.obtainMessage(SESSION_DISCONNECTED).sendToTarget();
stopRfcomm();
break;
case BluetoothPbapObexSession.OBEX_SESSION_REQUEST_COMPLETED:
/* send to parent, process there */
mParentHandler.obtainMessage(REQUEST_COMPLETED, msg.obj).sendToTarget();
break;
case BluetoothPbapObexSession.OBEX_SESSION_REQUEST_FAILED:
/* send to parent, process there */
mParentHandler.obtainMessage(REQUEST_FAILED, msg.obj).sendToTarget();
break;
case BluetoothPbapObexSession.OBEX_SESSION_AUTHENTICATION_REQUEST:
/* send to parent, process there */
mParentHandler.obtainMessage(AUTH_REQUESTED).sendToTarget();
mSessionHandler
.sendMessageDelayed(
mSessionHandler
.obtainMessage(BluetoothPbapObexSession.OBEX_SESSION_AUTHENTICATION_TIMEOUT),
30000);
break;
case BluetoothPbapObexSession.OBEX_SESSION_AUTHENTICATION_TIMEOUT:
/* stop authentication */
setAuthResponse(null);
mParentHandler.obtainMessage(AUTH_TIMEOUT).sendToTarget();
break;
default:
return false;
}
return true;
|
public boolean | makeRequest(BluetoothPbapRequest request)
Log.v(TAG, "makeRequest: " + request.getClass().getSimpleName());
if (mPendingRequest != null) {
Log.w(TAG, "makeRequest: request already queued, exiting");
return false;
}
if (mObexSession == null) {
mPendingRequest = request;
/*
* since there is no pending request and no session it's safe to
* assume that RFCOMM does not exist either and we should start
* connecting it
*/
startRfcomm();
return true;
}
return mObexSession.schedule(request);
|
public boolean | setAuthResponse(java.lang.String key)
Log.d(TAG, "setAuthResponse key=" + key);
mSessionHandler
.removeMessages(BluetoothPbapObexSession.OBEX_SESSION_AUTHENTICATION_TIMEOUT);
/* does not make sense to set auth response when OBEX session is down */
if (mObexSession == null) {
return false;
}
return mObexSession.setAuthReply(key);
|
public void | start()
Log.d(TAG, "start");
startRfcomm();
|
private void | startObexSession()
Log.d(TAG, "startObexSession");
mObexSession = new BluetoothPbapObexSession(mTransport);
mObexSession.start(mSessionHandler);
|
private void | startRfcomm()
Log.d(TAG, "startRfcomm");
if (mConnectThread == null && mObexSession == null) {
mParentHandler.obtainMessage(SESSION_CONNECTING).sendToTarget();
mConnectThread = new RfcommConnectThread();
mConnectThread.start();
}
/*
* don't care if mConnectThread is not null - it means RFCOMM is being
* connected anyway
*/
|
public void | stop()
Log.d(TAG, "Stop");
stopObexSession();
stopRfcomm();
|
private void | stopObexSession()
Log.d(TAG, "stopObexSession");
if (mObexSession != null) {
mObexSession.stop();
mObexSession = null;
}
|
private void | stopRfcomm()
Log.d(TAG, "stopRfcomm");
if (mConnectThread != null) {
try {
mConnectThread.join();
} catch (InterruptedException e) {
}
mConnectThread = null;
}
if (mTransport != null) {
try {
mTransport.close();
} catch (IOException e) {
}
mTransport = null;
}
|