private void markBatchFailed(int failReason) {
    synchronized (this) {
      try {
        wait(1000);
      } catch (InterruptedException e) {
        if (V) Log.v(TAG, "Interrupted waiting for markBatchFailed");
      }
    }

    if (D) Log.d(TAG, "Mark all ShareInfo in the batch as failed");
    if (mCurrentShare != null) {
      if (V) Log.v(TAG, "Current share has status " + mCurrentShare.mStatus);
      if (BluetoothShare.isStatusError(mCurrentShare.mStatus)) {
        failReason = mCurrentShare.mStatus;
      }
      if (mCurrentShare.mDirection == BluetoothShare.DIRECTION_INBOUND
          && mCurrentShare.mFilename != null) {
        new File(mCurrentShare.mFilename).delete();
      }
    }

    BluetoothOppShareInfo info = null;
    if (mBatch == null) {
      return;
    }
    info = mBatch.getPendingShare();
    while (info != null) {
      if (info.mStatus < 200) {
        info.mStatus = failReason;
        Uri contentUri = Uri.parse(BluetoothShare.CONTENT_URI + "/" + info.mId);
        ContentValues updateValues = new ContentValues();
        updateValues.put(BluetoothShare.STATUS, info.mStatus);
        /* Update un-processed outbound transfer to show some info */
        if (info.mDirection == BluetoothShare.DIRECTION_OUTBOUND) {
          BluetoothOppSendFileInfo fileInfo = BluetoothOppUtility.getSendFileInfo(info.mUri);
          BluetoothOppUtility.closeSendFileInfo(info.mUri);
          if (fileInfo.mFileName != null) {
            updateValues.put(BluetoothShare.FILENAME_HINT, fileInfo.mFileName);
            updateValues.put(BluetoothShare.TOTAL_BYTES, fileInfo.mLength);
            updateValues.put(BluetoothShare.MIMETYPE, fileInfo.mMimetype);
          }
        } else {
          if (info.mStatus < 200 && info.mFilename != null) {
            new File(info.mFilename).delete();
          }
        }
        mContext.getContentResolver().update(contentUri, updateValues, null, null);
        Constants.sendIntentIfCompleted(mContext, contentUri, info.mStatus);
      }
      info = mBatch.getPendingShare();
    }
  }
 /**
  * Open the selected finished transfer. mDownloadCursor must be moved to appropriate position
  * before calling this function
  */
 private void openCompleteTransfer() {
   int sessionId = mTransferCursor.getInt(mIdColumnId);
   Uri contentUri = Uri.parse(BluetoothShare.CONTENT_URI + "/" + sessionId);
   BluetoothOppTransferInfo transInfo = BluetoothOppUtility.queryRecord(this, contentUri);
   if (transInfo == null) {
     Log.e(TAG, "Error: Can not get data from db");
     return;
   }
   if (transInfo.mDirection == BluetoothShare.DIRECTION_INBOUND
       && BluetoothShare.isStatusSuccess(transInfo.mStatus)) {
     // if received file successfully, open this file
     BluetoothOppUtility.updateVisibilityToHidden(this, contentUri);
     BluetoothOppUtility.openReceivedFile(
         this, transInfo.mFileName, transInfo.mFileType, transInfo.mTimeStamp, contentUri);
   } else {
     Intent in = new Intent(this, BluetoothOppTransferActivity.class);
     in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
     in.setDataAndNormalize(contentUri);
     this.startActivity(in);
   }
 }
  /** Get the number of finished transfers, including error and success. */
  private int getClearableCount() {
    Log.i(TAG, "getClearableCount ++");
    int count = 0;
    try {
      if (mTransferCursor.moveToFirst()) {
        while (!mTransferCursor.isAfterLast()) {
          int statusColumnId = mTransferCursor.getColumnIndexOrThrow(BluetoothShare.STATUS);
          int status = mTransferCursor.getInt(statusColumnId);
          if (BluetoothShare.isStatusCompleted(status)) {
            count++;
          }
          mTransferCursor.moveToNext();
        }
      }
    } catch (Exception e) {
      // TODO: handle exception
      e.printStackTrace();
    }

    Log.i(TAG, "getClearableCount return " + count);
    return count;
  }