return (mShares.size() == 0);
}
+ public int getNumShares() {
+ return mShares.size();
+ }
+
/**
* Get the running status of the batch
* @return
mTransport = transport;
}
- public void start(Handler handler) {
+ public void start(Handler handler, int numShares) {
if (D) Log.d(TAG, "Start!");
mCallback = handler;
- mThread = new ClientThread(mContext, mTransport);
+ mThread = new ClientThread(mContext, mTransport, numShares);
mThread.start();
}
private boolean mConnected = false;
- public ClientThread(Context context, ObexTransport transport) {
+ private int mNumShares;
+
+ public ClientThread(Context context, ObexTransport transport, int initialNumShares) {
super("BtOpp ClientThread");
mContext1 = context;
mTransport1 = transport;
waitingForShare = true;
mWaitingForRemote = false;
-
+ mNumShares = initialNumShares;
PowerManager pm = (PowerManager)mContext1.getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
}
mInterrupted = true;
}
if (!mInterrupted) {
- connect();
+ connect(mNumShares);
}
while (!mInterrupted) {
}
}
- private void connect() {
+ private void connect(int numShares) {
if (D) Log.d(TAG, "Create ClientSession with transport " + mTransport1.toString());
try {
mCs = new ClientSession(mTransport1);
if (mConnected) {
mConnected = false;
HeaderSet hs = new HeaderSet();
+ hs.setHeader(HeaderSet.COUNT, (long) numShares);
synchronized (this) {
mWaitingForRemote = true;
}
/**
* Called from BluetoothOppTransfer to start the "Transfer"
*/
- public void start(Handler handler) {
+ public void start(Handler handler, int numShares) {
if (D) Log.d(TAG, "Start!");
mCallback = handler;
values.put(BluetoothShare.USER_CONFIRMATION,
BluetoothShare.USER_CONFIRMATION_HANDOVER_CONFIRMED);
needConfirm = false;
+
}
Uri contentUri = mContext.getContentResolver().insert(BluetoothShare.CONTENT_URI, values);
if (D) Log.d(TAG, "onConnect");
if (V) Constants.logHeader(request);
+ Long objectCount = null;
try {
byte[] uuid = (byte[])request.getHeader(HeaderSet.TARGET);
if (V) Log.v(TAG, "onConnect(): uuid =" + Arrays.toString(uuid));
if(uuid != null) {
return ResponseCodes.OBEX_HTTP_NOT_ACCEPTABLE;
}
+
+ objectCount = (Long) request.getHeader(HeaderSet.COUNT);
} catch (IOException e) {
Log.e(TAG, e.toString());
return ResponseCodes.OBEX_HTTP_INTERNAL_ERROR;
}
+ String destination;
+ if (mTransport instanceof BluetoothOppRfcommTransport) {
+ destination = ((BluetoothOppRfcommTransport)mTransport).getRemoteAddress();
+ } else {
+ destination = "FF:FF:FF:00:00:00";
+ }
+ boolean isHandover = BluetoothOppManager.getInstance(mContext).
+ isWhitelisted(destination);
+ if (isHandover) {
+ // Notify the handover requester file transfer has started
+ Intent intent = new Intent(Constants.ACTION_HANDOVER_STARTED);
+ if (objectCount != null) {
+ intent.putExtra(Constants.EXTRA_BT_OPP_OBJECT_COUNT, objectCount.intValue());
+ } else {
+ intent.putExtra(Constants.EXTRA_BT_OPP_OBJECT_COUNT,
+ Constants.COUNT_HEADER_UNAVAILABLE);
+ }
+ intent.putExtra(Constants.EXTRA_BT_OPP_ADDRESS, destination);
+ mContext.sendBroadcast(intent, Constants.HANDOVER_STATUS_PERMISSION);
+ }
mTimestamp = System.currentTimeMillis();
return ResponseCodes.OBEX_HTTP_OK;
}
int SESSION_TIMEOUT = 50000;
- void start(Handler sessionHandler);
+ void start(Handler sessionHandler, int numShares);
void stop();
if (V) Log.v(TAG, "Transfer has Server session" + mSession.toString());
}
- mSession.start(mSessionHandler);
+ mSession.start(mSessionHandler, mBatch.getNumShares());
processCurrentShare();
}
public static final String ACTION_HANDOVER_SEND_MULTIPLE =
"android.btopp.intent.action.HANDOVER_SEND_MULTIPLE";
+ /** the intent that is used for indicating an incoming transfer*/
+ public static final String ACTION_HANDOVER_STARTED =
+ "android.btopp.intent.action.BT_OPP_HANDOVER_STARTED";
+
/** intent action used to indicate the progress of a handover transfer */
public static final String ACTION_BT_OPP_TRANSFER_PROGRESS =
"android.btopp.intent.action.BT_OPP_TRANSFER_PROGRESS";
public static final String EXTRA_BT_OPP_ADDRESS =
"android.btopp.intent.extra.BT_OPP_ADDRESS";
+ public static final String EXTRA_BT_OPP_OBJECT_COUNT =
+ "android.btopp.intent.extra.BT_OPP_OBJECT_COUNT";
+
+ public static final int COUNT_HEADER_UNAVAILABLE = -1;
public static final int HANDOVER_TRANSFER_STATUS_SUCCESS = 0;
public static final int HANDOVER_TRANSFER_STATUS_FAILURE = 1;