summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuffin Alex Varghese <jalex@codeaurora.org>2014-02-19 11:45:27 +0530
committerSteve Kondik <shade@chemlab.org>2014-10-11 16:31:43 -0700
commitf9d645bad2608c2282291de6fcf8652a2334f486 (patch)
tree8dc5e71850e3d4236454fe813176ed93d3a06dcd
parentaa3137b28025d809189cc0e34d4fab6a51209f18 (diff)
downloadandroid_packages_apps_Bluetooth-f9d645bad2608c2282291de6fcf8652a2334f486.tar.gz
android_packages_apps_Bluetooth-f9d645bad2608c2282291de6fcf8652a2334f486.tar.bz2
android_packages_apps_Bluetooth-f9d645bad2608c2282291de6fcf8652a2334f486.zip
Bluetooth-OPP: Cleanup pending share while BT turn OFF
This will ensure that pending OPP shares will be removed from database while BT is turning OFF. Otherwise, BT turned back ON if there are some pending share in database it will start sending automatically. CRs-Fixed: 611970 Change-Id: Ibc2664840f11bfeaefb5984e8ac18a171d515129
-rw-r--r--src/com/android/bluetooth/opp/BluetoothOppManager.java14
-rw-r--r--src/com/android/bluetooth/opp/BluetoothOppService.java89
2 files changed, 100 insertions, 3 deletions
diff --git a/src/com/android/bluetooth/opp/BluetoothOppManager.java b/src/com/android/bluetooth/opp/BluetoothOppManager.java
index 849abf36a..b9c0a8a60 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppManager.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppManager.java
@@ -77,6 +77,8 @@ public class BluetoothOppManager {
private String mUriOfSendingFile;
+ private String mNameOfSendingFile;
+
private String mMimeTypeOfSendingFiles;
private ArrayList<Uri> mUrisOfSendingFiles;
@@ -260,6 +262,7 @@ public class BluetoothOppManager {
uri = BluetoothOppUtility.generateUri(uri, sendFileInfo);
BluetoothOppUtility.putSendFileInfo(uri, sendFileInfo);
mUriOfSendingFile = uri.toString();
+ mNameOfSendingFile = sendFileInfo.mFileName;
storeApplicationData();
}
}
@@ -357,7 +360,7 @@ public class BluetoothOppManager {
return;
}
insertThread = new InsertShareInfoThread(device, mMultipleFlag, mMimeTypeOfSendingFile,
- mUriOfSendingFile, mMimeTypeOfSendingFiles, mUrisOfSendingFiles,
+ mUriOfSendingFile, mNameOfSendingFile, mMimeTypeOfSendingFiles, mUrisOfSendingFiles,
mIsHandoverInitiated);
if (mMultipleFlag) {
mfileNumInBatch = mUrisOfSendingFiles.size();
@@ -382,6 +385,8 @@ public class BluetoothOppManager {
private final String mUri;
+ private final String mNameOfSingleFile;
+
private final String mTypeOfMultipleFiles;
private final ArrayList<Uri> mUris;
@@ -391,13 +396,15 @@ public class BluetoothOppManager {
private final boolean mIsHandoverInitiated;
public InsertShareInfoThread(BluetoothDevice device, boolean multiple,
- String typeOfSingleFile, String uri, String typeOfMultipleFiles,
- ArrayList<Uri> uris, boolean handoverInitiated) {
+ String typeOfSingleFile, String uri, String nameOfSingleFile,
+ String typeOfMultipleFiles, ArrayList<Uri> uris,
+ boolean handoverInitiated) {
super("Insert ShareInfo Thread");
this.mRemoteDevice = device;
this.mIsMultiple = multiple;
this.mTypeOfSingleFile = typeOfSingleFile;
this.mUri = uri;
+ this.mNameOfSingleFile = nameOfSingleFile;
this.mTypeOfMultipleFiles = typeOfMultipleFiles;
this.mUris = uris;
this.mIsHandoverInitiated = handoverInitiated;
@@ -467,6 +474,7 @@ public class BluetoothOppManager {
private void insertSingleShare() {
ContentValues values = new ContentValues();
values.put(BluetoothShare.URI, mUri);
+ values.put(BluetoothShare.FILENAME_HINT, mNameOfSingleFile);
values.put(BluetoothShare.MIMETYPE, mTypeOfSingleFile);
values.put(BluetoothShare.DESTINATION, mRemoteDevice.getAddress());
if (mIsHandoverInitiated) {
diff --git a/src/com/android/bluetooth/opp/BluetoothOppService.java b/src/com/android/bluetooth/opp/BluetoothOppService.java
index 945d5475c..f38736513 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppService.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppService.java
@@ -393,6 +393,7 @@ public class BluetoothOppService extends Service {
break;
case BluetoothAdapter.STATE_TURNING_OFF:
if (V) Log.v(TAG, "Receiver DISABLED_ACTION ");
+ removePendingTransfer();
mNotifier.updateNotifier();
//FIX: Don't block main thread
/*
@@ -867,6 +868,94 @@ public class BluetoothOppService extends Service {
}
}
+ private void removePendingTransfer() {
+ if (V) Log.v(TAG, "Remove pending share");
+ Cursor cursor = null;
+ try {
+ cursor = getContentResolver().query(BluetoothShare.CONTENT_URI, null, null,
+ null, BluetoothShare._ID);
+ } catch (SQLiteException e) {
+ if (cursor != null){
+ cursor.close();
+ }
+ cursor = null;
+ Log.e(TAG, "UpdateThread: " + e);
+ } catch (CursorWindowAllocationException e) {
+ cursor = null;
+ Log.e(TAG, "UpdateThread: " + e);
+ }
+
+ if (cursor == null) {
+ return;
+ }
+
+ cursor.moveToFirst();
+ int arrayPos = 0;
+ boolean isAfterLast = cursor.isAfterLast();
+
+ while (!isAfterLast || arrayPos < mShares.size()) {
+ String uriString = cursor.getString(cursor.getColumnIndexOrThrow(BluetoothShare.URI));
+ Uri uri;
+ if (uriString != null) {
+ uri = Uri.parse(uriString);
+ Log.d(TAG, "removeShare parsed URI: " + uri);
+ } else {
+ uri = null;
+ Log.e(TAG, "removeShare found null URI at cursor!");
+ }
+ BluetoothOppShareInfo info = new BluetoothOppShareInfo(
+ cursor.getInt(cursor.getColumnIndexOrThrow(BluetoothShare._ID)),
+ uri,
+ cursor.getString(cursor.getColumnIndexOrThrow(BluetoothShare.FILENAME_HINT)),
+ cursor.getString(cursor.getColumnIndexOrThrow(BluetoothShare._DATA)),
+ cursor.getString(cursor.getColumnIndexOrThrow(BluetoothShare.MIMETYPE)),
+ cursor.getInt(cursor.getColumnIndexOrThrow(BluetoothShare.DIRECTION)),
+ cursor.getString(cursor.getColumnIndexOrThrow(BluetoothShare.DESTINATION)),
+ cursor.getInt(cursor.getColumnIndexOrThrow(BluetoothShare.VISIBILITY)),
+ cursor.getInt(cursor.getColumnIndexOrThrow(BluetoothShare.USER_CONFIRMATION)),
+ cursor.getInt(cursor.getColumnIndexOrThrow(BluetoothShare.STATUS)),
+ cursor.getLong(cursor.getColumnIndexOrThrow(BluetoothShare.TOTAL_BYTES)),
+ cursor.getLong(cursor.getColumnIndexOrThrow(BluetoothShare.CURRENT_BYTES)),
+ cursor.getLong(cursor.getColumnIndexOrThrow(BluetoothShare.TIMESTAMP)),
+ cursor.getInt(cursor.getColumnIndexOrThrow(Constants.MEDIA_SCANNED)) != Constants.MEDIA_SCANNED_NOT_SCANNED);
+
+ if (V) {
+ Log.v(TAG, "Service remove entry");
+ Log.v(TAG, "ID : " + info.mId);
+ // Log.v(TAG, "URI : " + ((info.mUri != null) ? "yes" : "no"));
+ Log.v(TAG, "URI : " + info.mUri);
+ Log.v(TAG, "HINT : " + info.mHint);
+ Log.v(TAG, "FILENAME: " + info.mFilename);
+ Log.v(TAG, "MIMETYPE: " + info.mMimetype);
+ Log.v(TAG, "DIRECTION: " + info.mDirection);
+ Log.v(TAG, "DESTINAT: " + info.mDestination);
+ Log.v(TAG, "VISIBILI: " + info.mVisibility);
+ Log.v(TAG, "CONFIRM : " + info.mConfirm);
+ Log.v(TAG, "STATUS : " + info.mStatus);
+ Log.v(TAG, "TOTAL : " + info.mTotalBytes);
+ Log.v(TAG, "CURRENT : " + info.mCurrentBytes);
+ Log.v(TAG, "TIMESTAMP : " + info.mTimestamp);
+ Log.v(TAG, "SCANNED : " + info.mMediaScanned);
+ }
+
+ if (info.isReadyToStart()) {
+ if (info.mDirection == BluetoothShare.DIRECTION_OUTBOUND) {
+ BluetoothOppSendFileInfo sendFileInfo = BluetoothOppUtility.getSendFileInfo(
+ info.mUri);
+ Constants.updateShareStatus(this, info.mId, BluetoothShare.STATUS_BAD_REQUEST);
+ BluetoothOppUtility.closeSendFileInfo(info.mUri);
+ }
+ }
+
+ ++arrayPos;
+ cursor.moveToNext();
+ isAfterLast = cursor.isAfterLast();
+ }
+ cursor.close();
+ if (V) Log.v(TAG, "Freeing cursor: " + cursor);
+ cursor = null;
+ }
+
/**
* Removes the local copy of the info about a share.
*/