/** Start the transfer */ public void start() { /* check Bluetooth enable status */ /* * normally it's impossible to reach here if BT is disabled. Just check * for safety */ if (!mAdapter.isEnabled()) { Log.e(TAG, "Can't start transfer when Bluetooth is disabled for " + mBatch.mId); markBatchFailed(); mBatch.mStatus = Constants.BATCH_STATUS_FAILED; return; } if (mHandlerThread == null) { if (V) Log.v(TAG, "Create handler thread for batch " + mBatch.mId); mHandlerThread = new HandlerThread("BtOpp Transfer Handler", Process.THREAD_PRIORITY_BACKGROUND); mHandlerThread.start(); mSessionHandler = new EventHandler(mHandlerThread.getLooper()); if (mBatch.mDirection == BluetoothShare.DIRECTION_OUTBOUND) { /* for outbound transfer, we do connect first */ startConnectSession(); } else if (mBatch.mDirection == BluetoothShare.DIRECTION_INBOUND) { /* * for inbound transfer, it's already connected, so we start * OBEX session directly */ startObexSession(); } } }
private void startObexSession() { mBatch.mStatus = Constants.BATCH_STATUS_RUNNING; mCurrentShare = mBatch.getPendingShare(); if (mCurrentShare == null) { /* * TODO catch this error */ Log.e(TAG, "Unexpected error happened !"); return; } if (V) Log.v(TAG, "Start session for info " + mCurrentShare.mId + " for batch " + mBatch.mId); if (mBatch.mDirection == BluetoothShare.DIRECTION_OUTBOUND) { if (V) Log.v(TAG, "Create Client session with transport " + mTransport.toString()); mSession = new BluetoothOppObexClientSession(mContext, mTransport); } else if (mBatch.mDirection == BluetoothShare.DIRECTION_INBOUND) { /* * For inbounds transfer, a server session should already exists * before BluetoothOppTransfer is initialized. We should pass in a * mSession instance. */ if (mSession == null) { /** set current share as error */ Log.e(TAG, "Unexpected error happened !"); markBatchFailed(); mBatch.mStatus = Constants.BATCH_STATUS_FAILED; return; } if (V) Log.v(TAG, "Transfer has Server session" + mSession.toString()); } mSession.start(mSessionHandler, mBatch.getNumShares()); processCurrentShare(); }
/** Process when current transfer is canceled */ public void onBatchCanceled() { if (V) Log.v(TAG, "Transfer on Batch canceled"); this.stop(); mBatch.mStatus = Constants.BATCH_STATUS_FINISHED; }