summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuffin Alex Varghese <jalex@codeaurora.org>2014-10-16 10:39:03 +0530
committerLinux Build Service Account <lnxbuild@localhost>2014-11-04 08:26:28 -0700
commitaac988ce6f02bbb3f34ac59acc36b386a45ac8e5 (patch)
treed9b271d032d46fdad3b85237bb5ba0991e3d1ed9
parentbb953a37da10a5ac0025c4532e54eb8668af0eaf (diff)
downloadandroid_packages_apps_Bluetooth-aac988ce6f02bbb3f34ac59acc36b386a45ac8e5.tar.gz
android_packages_apps_Bluetooth-aac988ce6f02bbb3f34ac59acc36b386a45ac8e5.tar.bz2
android_packages_apps_Bluetooth-aac988ce6f02bbb3f34ac59acc36b386a45ac8e5.zip
Bluetooth-OPP: Klocwork OPP fixes
This changes contains fixes for sql resource leak and null pointer exceptions report by klocwork tool. CRs-Fixed: 741003 Change-Id: I85dbdf4a0cdbee64413865c334946c2301e9ef53
-rw-r--r--src/com/android/bluetooth/opp/BluetoothOppNotification.java163
-rw-r--r--src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java8
-rw-r--r--src/com/android/bluetooth/opp/BluetoothOppReceiver.java30
-rw-r--r--src/com/android/bluetooth/opp/BluetoothOppService.java37
-rw-r--r--src/com/android/bluetooth/opp/BluetoothOppTransfer.java20
-rw-r--r--src/com/android/bluetooth/opp/BluetoothOppTransport.java3
-rw-r--r--src/com/android/bluetooth/opp/BluetoothOppUtility.java81
7 files changed, 219 insertions, 123 deletions
diff --git a/src/com/android/bluetooth/opp/BluetoothOppNotification.java b/src/com/android/bluetooth/opp/BluetoothOppNotification.java
index 2688f021d..cd4b58344 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppNotification.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppNotification.java
@@ -42,6 +42,7 @@ import android.content.Intent;
import android.database.Cursor;
import android.database.CursorWindowAllocationException;
import android.database.sqlite.SQLiteException;
+import android.content.res.Resources.NotFoundException;
import android.net.Uri;
import android.util.Log;
import android.os.Handler;
@@ -282,66 +283,84 @@ class BluetoothOppNotification {
}
// Collate the notifications
- final int timestampIndex = cursor.getColumnIndexOrThrow(BluetoothShare.TIMESTAMP);
- final int directionIndex = cursor.getColumnIndexOrThrow(BluetoothShare.DIRECTION);
- final int idIndex = cursor.getColumnIndexOrThrow(BluetoothShare._ID);
- final int totalBytesIndex = cursor.getColumnIndexOrThrow(BluetoothShare.TOTAL_BYTES);
- final int currentBytesIndex = cursor.getColumnIndexOrThrow(BluetoothShare.CURRENT_BYTES);
- final int dataIndex = cursor.getColumnIndexOrThrow(BluetoothShare._DATA);
- final int filenameHintIndex = cursor.getColumnIndexOrThrow(BluetoothShare.FILENAME_HINT);
- final int confirmIndex = cursor.getColumnIndexOrThrow(BluetoothShare.USER_CONFIRMATION);
- final int destinationIndex = cursor.getColumnIndexOrThrow(BluetoothShare.DESTINATION);
+ final int timestampIndex;
+ final int directionIndex;
+ final int idIndex;
+ final int totalBytesIndex;
+ final int currentBytesIndex;
+ final int dataIndex;
+ final int filenameHintIndex;
+ final int confirmIndex;
+ final int destinationIndex;
+ try {
+ timestampIndex = cursor.getColumnIndexOrThrow(BluetoothShare.TIMESTAMP);
+ directionIndex = cursor.getColumnIndexOrThrow(BluetoothShare.DIRECTION);
+ idIndex = cursor.getColumnIndexOrThrow(BluetoothShare._ID);
+ totalBytesIndex = cursor.getColumnIndexOrThrow(BluetoothShare.TOTAL_BYTES);
+ currentBytesIndex = cursor.getColumnIndexOrThrow(BluetoothShare.CURRENT_BYTES);
+ dataIndex = cursor.getColumnIndexOrThrow(BluetoothShare._DATA);
+ filenameHintIndex = cursor.getColumnIndexOrThrow(BluetoothShare.FILENAME_HINT);
+ confirmIndex = cursor.getColumnIndexOrThrow(BluetoothShare.USER_CONFIRMATION);
+ destinationIndex = cursor.getColumnIndexOrThrow(BluetoothShare.DESTINATION);
+ } catch (IllegalArgumentException e) {
+ cursor.close();
+ cursor = null;
+ Log.e(TAG, "Invalid share info");
+ return;
+ }
mNotifications.clear();
- for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
- long timeStamp = cursor.getLong(timestampIndex);
- int dir = cursor.getInt(directionIndex);
- int id = cursor.getInt(idIndex);
- long total = cursor.getLong(totalBytesIndex);
- long current = cursor.getLong(currentBytesIndex);
- int confirmation = cursor.getInt(confirmIndex);
-
- String destination = cursor.getString(destinationIndex);
- String fileName = cursor.getString(dataIndex);
- if (fileName == null) {
- fileName = cursor.getString(filenameHintIndex);
- }
- if (fileName == null) {
- fileName = mContext.getString(R.string.unknown_file);
- }
+ if (cursor != null) {
+ for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
+ long timeStamp = cursor.getLong(timestampIndex);
+ int dir = cursor.getInt(directionIndex);
+ int id = cursor.getInt(idIndex);
+ long total = cursor.getLong(totalBytesIndex);
+ long current = cursor.getLong(currentBytesIndex);
+ int confirmation = cursor.getInt(confirmIndex);
+
+ String destination = cursor.getString(destinationIndex);
+ String fileName = cursor.getString(dataIndex);
+ if (fileName == null) {
+ fileName = cursor.getString(filenameHintIndex);
+ }
+ if (fileName == null) {
+ fileName = mContext.getString(R.string.unknown_file);
+ }
- String batchID = Long.toString(timeStamp);
+ String batchID = Long.toString(timeStamp);
- // sending objects in one batch has same timeStamp
- if (mNotifications.containsKey(batchID)) {
- // NOTE: currently no such case
- // Batch sending case
- } else {
- NotificationItem item = new NotificationItem();
- item.timeStamp = timeStamp;
- item.id = id;
- item.direction = dir;
- if (item.direction == BluetoothShare.DIRECTION_OUTBOUND) {
- item.description = mContext.getString(R.string.notification_sending, fileName);
- } else if (item.direction == BluetoothShare.DIRECTION_INBOUND) {
- item.description = mContext
- .getString(R.string.notification_receiving, fileName);
+ // sending objects in one batch has same timeStamp
+ if (mNotifications.containsKey(batchID)) {
+ // NOTE: currently no such case
+ // Batch sending case
} else {
- if (V) Log.v(TAG, "mDirection ERROR!");
- }
- item.totalCurrent = current;
- item.totalTotal = total;
- item.handoverInitiated =
+ NotificationItem item = new NotificationItem();
+ item.timeStamp = timeStamp;
+ item.id = id;
+ item.direction = dir;
+ if (item.direction == BluetoothShare.DIRECTION_OUTBOUND) {
+ item.description = mContext.getString(R.string.notification_sending, fileName);
+ } else if (item.direction == BluetoothShare.DIRECTION_INBOUND) {
+ item.description = mContext
+ .getString(R.string.notification_receiving, fileName);
+ } else {
+ if (V) Log.v(TAG, "mDirection ERROR!");
+ }
+ item.totalCurrent = current;
+ item.totalTotal = total;
+ item.handoverInitiated =
confirmation == BluetoothShare.USER_CONFIRMATION_HANDOVER_CONFIRMED;
- item.destination = destination;
- mNotifications.put(batchID, item);
+ item.destination = destination;
+ mNotifications.put(batchID, item);
- if (V) Log.v(TAG, "ID=" + item.id + "; batchID=" + batchID + "; totoalCurrent"
+ if (V) Log.v(TAG, "ID=" + item.id + "; batchID=" + batchID + "; totoalCurrent"
+ item.totalCurrent + "; totalTotal=" + item.totalTotal);
+ }
}
+ cursor.close();
+ cursor = null;
}
- cursor.close();
- cursor = null;
// Add the notifications
for (NotificationItem item : mNotifications.values()) {
@@ -452,8 +471,17 @@ class BluetoothOppNotification {
return;
}
- final int timestampIndex = cursor.getColumnIndexOrThrow(BluetoothShare.TIMESTAMP);
- final int statusIndex = cursor.getColumnIndexOrThrow(BluetoothShare.STATUS);
+ final int timestampIndex;
+ final int statusIndex;
+ try {
+ timestampIndex = cursor.getColumnIndexOrThrow(BluetoothShare.TIMESTAMP);
+ statusIndex = cursor.getColumnIndexOrThrow(BluetoothShare.STATUS);
+ } catch (IllegalArgumentException e) {
+ cursor.close();
+ cursor = null;
+ Log.e(TAG, "Invalid share info");
+ return;
+ }
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
if (cursor.isFirst()) {
@@ -474,7 +502,7 @@ class BluetoothOppNotification {
outboundNum = outboundSuccNumber + outboundFailNumber;
// create the outbound notification
- if (outboundNum > 0) {
+ if ((outboundNum > 0) && (mNotificationMgr != null)) {
Notification outNoti = new Notification();
outNoti.icon = android.R.drawable.stat_sys_upload_done;
title = mContext.getString(R.string.outbound_noti_title);
@@ -530,7 +558,7 @@ class BluetoothOppNotification {
inboundNum = inboundSuccNumber + inboundFailNumber;
// create the inbound notification
- if (inboundNum > 0) {
+ if ((inboundNum > 0) && (mNotificationMgr != null)) {
Notification inNoti = new Notification();
inNoti.icon = android.R.drawable.stat_sys_download_done;
title = mContext.getString(R.string.inbound_noti_title);
@@ -574,8 +602,15 @@ class BluetoothOppNotification {
mContext.getText(R.string.incoming_file_confirm_Notification_title);
CharSequence caption = mContext
.getText(R.string.incoming_file_confirm_Notification_caption);
- int id = cursor.getInt(cursor.getColumnIndexOrThrow(BluetoothShare._ID));
- long timeStamp = cursor.getLong(cursor.getColumnIndexOrThrow(BluetoothShare.TIMESTAMP));
+ int id;
+ long timeStamp;
+ try {
+ id = cursor.getInt(cursor.getColumnIndexOrThrow(BluetoothShare._ID));
+ timeStamp = cursor.getLong(cursor.getColumnIndexOrThrow(BluetoothShare.TIMESTAMP));
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "Invalid share info");
+ continue;
+ }
Uri contentUri = Uri.parse(BluetoothShare.CONTENT_URI + "/" + id);
if (mIncomingShownId != id) {
@@ -591,8 +626,12 @@ class BluetoothOppNotification {
intent.setDataAndNormalize(contentUri);
n.when = timeStamp;
- n.color = mContext.getResources().getColor(
- com.android.internal.R.color.system_notification_accent_color);
+ try {
+ n.color = mContext.getResources().getColor(
+ com.android.internal.R.color.system_notification_accent_color);
+ } catch (NotFoundException e) {
+ Log.e(TAG, "Resource not found");
+ }
n.setLatestEventInfo(mContext, title, caption, PendingIntent.getBroadcast(mContext, 0,
intent, 0));
@@ -630,7 +669,13 @@ class BluetoothOppNotification {
}
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
- int id = cursor.getInt(cursor.getColumnIndexOrThrow(BluetoothShare._ID));
+ int id;
+ try {
+ id = cursor.getInt(cursor.getColumnIndexOrThrow(BluetoothShare._ID));
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "Invalid share info");
+ continue;
+ }
if (V) Log.v(TAG, "Cancelling incoming notification " + id);
mNotificationMgr.cancel(id);
diff --git a/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java b/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java
index d9777862d..110305804 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java
@@ -312,7 +312,7 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen
((ServerOperation)op).mSrmServerSession.setLocalSrmStatus(ObexHelper.LOCAL_SRM_DISABLED);
}
- if (length == null || length == 0) {
+ if (length == null || length == 0) {
if (D) Log.w(TAG, "length is 0, reject the transfer");
pre_reject = true;
obexResponse = ResponseCodes.OBEX_HTTP_LENGTH_REQUIRED;
@@ -380,7 +380,11 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen
ContentValues values = new ContentValues();
values.put(BluetoothShare.FILENAME_HINT, name);
- values.put(BluetoothShare.TOTAL_BYTES, length.intValue());
+
+ if (length != null) {
+ values.put(BluetoothShare.TOTAL_BYTES, length.intValue());
+ }
+
values.put(BluetoothShare.MIMETYPE, mimeType);
values.put(BluetoothShare.DESTINATION, destination);
diff --git a/src/com/android/bluetooth/opp/BluetoothOppReceiver.java b/src/com/android/bluetooth/opp/BluetoothOppReceiver.java
index 35d6c73a1..dc29fcbdd 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppReceiver.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppReceiver.java
@@ -215,20 +215,24 @@ public class BluetoothOppReceiver extends BroadcastReceiver {
if (cursor != null) {
if (cursor.moveToFirst()) {
- int statusColumn = cursor.getColumnIndexOrThrow(BluetoothShare.STATUS);
- int status = cursor.getInt(statusColumn);
- int visibilityColumn = cursor.getColumnIndexOrThrow(BluetoothShare.VISIBILITY);
- int visibility = cursor.getInt(visibilityColumn);
- int userConfirmationColumn = cursor
- .getColumnIndexOrThrow(BluetoothShare.USER_CONFIRMATION);
- int userConfirmation = cursor.getInt(userConfirmationColumn);
- if (((userConfirmation == BluetoothShare.USER_CONFIRMATION_PENDING))
- && visibility == BluetoothShare.VISIBILITY_VISIBLE) {
- ContentValues values = new ContentValues();
- values.put(BluetoothShare.VISIBILITY, BluetoothShare.VISIBILITY_HIDDEN);
- context.getContentResolver().update(intent.getData(), values, null, null);
- if (V) Log.v(TAG, "Action_hide received and db updated");
+ try {
+ int statusColumn = cursor.getColumnIndexOrThrow(BluetoothShare.STATUS);
+ int status = cursor.getInt(statusColumn);
+ int visibilityColumn = cursor.getColumnIndexOrThrow(BluetoothShare.VISIBILITY);
+ int visibility = cursor.getInt(visibilityColumn);
+ int userConfirmationColumn = cursor
+ .getColumnIndexOrThrow(BluetoothShare.USER_CONFIRMATION);
+ int userConfirmation = cursor.getInt(userConfirmationColumn);
+ if (((userConfirmation == BluetoothShare.USER_CONFIRMATION_PENDING))
+ && visibility == BluetoothShare.VISIBILITY_VISIBLE) {
+ ContentValues values = new ContentValues();
+ values.put(BluetoothShare.VISIBILITY, BluetoothShare.VISIBILITY_HIDDEN);
+ context.getContentResolver().update(intent.getData(), values, null, null);
+ if (V) Log.v(TAG, "Action_hide received and db updated");
}
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "Invalid share info");
+ }
}
cursor.close();
cursor = null;
diff --git a/src/com/android/bluetooth/opp/BluetoothOppService.java b/src/com/android/bluetooth/opp/BluetoothOppService.java
index 6dfddb6da..ad99c7e29 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppService.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppService.java
@@ -182,7 +182,10 @@ public class BluetoothOppService extends Service {
startListener();
}
}
- if (V) BluetoothOppPreference.getInstance(this).dump();
+ if (V) {
+ BluetoothOppPreference mPreference = BluetoothOppPreference.getInstance(this);
+ if (mPreference != null) mPreference.dump();
+ }
updateFromProvider();
}
@@ -496,7 +499,15 @@ public class BluetoothOppService extends Service {
keepService = false;
boolean isAfterLast = cursor.isAfterLast();
- int idColumn = cursor.getColumnIndexOrThrow(BluetoothShare._ID);
+ int idColumn;
+ try {
+ idColumn = cursor.getColumnIndexOrThrow(BluetoothShare._ID);
+ } catch (IllegalArgumentException e) {
+ cursor.close();
+ cursor = null;
+ Log.e (TAG, "Invalid share ID");
+ return;
+ }
/*
* Walk the cursor and the local array to keep them in sync. The
* key to the algorithm is that the ids are unique and sorted
@@ -808,10 +819,11 @@ public class BluetoothOppService extends Service {
&& (BluetoothShare.isStatusCompleted(newStatus))) {
if (V) Log.v(TAG," UpdateShare: Share Completed: oldStatus = " + oldStatus + " newStatus = " + newStatus);
try {
- if(info.mDirection == BluetoothShare.DIRECTION_OUTBOUND)
+ if((info.mDirection == BluetoothShare.DIRECTION_OUTBOUND) && (mTransfer != null)) {
mTransfer.markShareComplete(newStatus);
- else
+ } else if (mServerTransfer != null) {
mServerTransfer.markShareComplete(newStatus);
+ }
} catch (Exception e) {
Log.e(TAG, "Exception: updateShare: oldStatus: " + oldStatus + " newStatus: " + newStatus);
}
@@ -971,8 +983,9 @@ public class BluetoothOppService extends Service {
mServerTransfer = new BluetoothOppTransfer(this, mPowerManager, nextBatch,
mServerSession);
mServerTransfer.start();
- if (nextBatch.getPendingShare().mConfirm ==
- BluetoothShare.USER_CONFIRMATION_CONFIRMED) {
+ BluetoothOppShareInfo mPendingShare = nextBatch.getPendingShare();
+ if ((mPendingShare != null) && (mPendingShare.mConfirm ==
+ BluetoothShare.USER_CONFIRMATION_CONFIRMED)) {
mServerTransfer.setConfirmed();
}
return;
@@ -1071,6 +1084,8 @@ public class BluetoothOppService extends Service {
WHERE_INBOUND_INTERRUPTED_ON_POWER_OFF, null);
if (V) Log.v(TAG, "Delete aborted inbound share, number = " + delNum);
}
+ cursorToFile.close();
+ cursorToFile = null;
}
// on boot : remove unconfirmed inbound shares.
@@ -1105,7 +1120,15 @@ public class BluetoothOppService extends Service {
int numToDelete = recordNum - Constants.MAX_RECORDS_IN_DATABASE;
if (cursor.moveToPosition(numToDelete)) {
- int columnId = cursor.getColumnIndexOrThrow(BluetoothShare._ID);
+ int columnId;
+ try {
+ columnId = cursor.getColumnIndexOrThrow(BluetoothShare._ID);
+ } catch (IllegalArgumentException e) {
+ cursor.close();
+ cursor = null;
+ Log.e(TAG, "Invalid share ID");
+ return;
+ }
long id = cursor.getLong(columnId);
delNum = contentResolver.delete(BluetoothShare.CONTENT_URI,
BluetoothShare._ID + " < " + id, null);
diff --git a/src/com/android/bluetooth/opp/BluetoothOppTransfer.java b/src/com/android/bluetooth/opp/BluetoothOppTransfer.java
index 1b8eb9ffe..55d116f73 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppTransfer.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppTransfer.java
@@ -487,7 +487,7 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
if (V) Log.v(TAG, "Start session for info " + mCurrentShare.mId + " for batch " +
mBatch.mId);
- if (mBatch.mDirection == BluetoothShare.DIRECTION_OUTBOUND) {
+ if ((mBatch.mDirection == BluetoothShare.DIRECTION_OUTBOUND) && (mTransport != null)) {
if (V) Log.v(TAG, "Create Client session with transport " + mTransport.toString());
mSession = new BluetoothOppObexClientSession(mContext, mTransport);
} else if (mBatch.mDirection == BluetoothShare.DIRECTION_INBOUND) {
@@ -506,8 +506,10 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
if (V) Log.v(TAG, "Transfer has Server session" + mSession.toString());
}
- mSession.start(mSessionHandler, mBatch.getNumShares());
- processCurrentShare();
+ if (mSession != null) {
+ mSession.start(mSessionHandler, mBatch.getNumShares());
+ processCurrentShare();
+ }
/* OBEX channel need to be monitored for unexpected ACL disconnection
* such as Remote Battery removal
@@ -692,7 +694,10 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
if (V) Log.v(TAG, "BluetoothSocket connection attempt took " +
(System.currentTimeMillis() - timestamp) + " ms");
BluetoothOppTransport transport= new BluetoothOppTransport(btSocket, btOppTransportType);
- BluetoothOppPreference.getInstance(mContext).setName(device, device.getName());
+ BluetoothOppPreference mPreference = BluetoothOppPreference.getInstance(mContext);
+ if (mPreference != null) {
+ mPreference.setName(device, device.getName());
+ }
if (V) Log.v(TAG, "Send RFCOMM transport message " + transport.toString());
mSessionHandler.obtainMessage(TRANSPORT_CONNECTED, transport).sendToTarget();
} catch (IOException e) {
@@ -786,7 +791,10 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
(System.currentTimeMillis() - timestamp) + " ms");
BluetoothOppTransport transport= new BluetoothOppTransport(btSocket, btOppTransportType);
- BluetoothOppPreference.getInstance(mContext).setName(device, device.getName());
+ BluetoothOppPreference mPreference = BluetoothOppPreference.getInstance(mContext);
+ if (mPreference != null) {
+ mPreference.setName(device, device.getName());
+ }
if (V) Log.v(TAG, "Send transport message " + transport.toString());
mSessionHandler.obtainMessage(TRANSPORT_CONNECTED, transport).sendToTarget();
} catch (IOException e2) {
@@ -846,7 +854,7 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
*/
public void onShareAdded(int id) {
BluetoothOppShareInfo info = mBatch.getPendingShare();
- if (info.mDirection == BluetoothShare.DIRECTION_INBOUND) {
+ if ((info != null) && (info.mDirection == BluetoothShare.DIRECTION_INBOUND)) {
mCurrentShare = mBatch.getPendingShare();
/*
* TODO what if it's not auto confirmed?
diff --git a/src/com/android/bluetooth/opp/BluetoothOppTransport.java b/src/com/android/bluetooth/opp/BluetoothOppTransport.java
index 635fe794e..25c66fc7e 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppTransport.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppTransport.java
@@ -47,6 +47,7 @@ import javax.btobex.ObexHelper;
public class BluetoothOppTransport implements ObexTransport {
+ private static final String TAG = "BluetoothOppTransport";
public static final int TYPE_RFCOMM = 0;
public static final int TYPE_L2CAP = 1;
@@ -87,7 +88,7 @@ public class BluetoothOppTransport implements ObexTransport {
public int setPutSockMTUSize(int size) throws IOException {
ByteBuffer bb = ByteBuffer.allocate(4);
int status;
- Log.v("srinu", "Interrupted waiting for size"+ size);
+ Log.v(TAG, "Interrupted waiting for size "+ size);
bb.order(ByteOrder.LITTLE_ENDIAN);
bb.putInt(0, size);
try {
diff --git a/src/com/android/bluetooth/opp/BluetoothOppUtility.java b/src/com/android/bluetooth/opp/BluetoothOppUtility.java
index 53498d277..283783b8d 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppUtility.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppUtility.java
@@ -79,49 +79,60 @@ public class BluetoothOppUtility {
if (cursor != null) {
if (cursor.moveToFirst()) {
- info.mID = cursor.getInt(cursor.getColumnIndexOrThrow(BluetoothShare._ID));
- info.mStatus = cursor.getInt(cursor.getColumnIndexOrThrow(BluetoothShare.STATUS));
- info.mDirection = cursor.getInt(cursor
- .getColumnIndexOrThrow(BluetoothShare.DIRECTION));
- info.mTotalBytes = cursor.getLong(cursor
- .getColumnIndexOrThrow(BluetoothShare.TOTAL_BYTES));
- info.mCurrentBytes = cursor.getLong(cursor
- .getColumnIndexOrThrow(BluetoothShare.CURRENT_BYTES));
- info.mTimeStamp = cursor.getLong(cursor
- .getColumnIndexOrThrow(BluetoothShare.TIMESTAMP));
- info.mDestAddr = cursor.getString(cursor
- .getColumnIndexOrThrow(BluetoothShare.DESTINATION));
-
- info.mFileName = cursor.getString(cursor
- .getColumnIndexOrThrow(BluetoothShare._DATA));
- if (info.mFileName == null) {
- info.mFileName = cursor.getString(cursor
- .getColumnIndexOrThrow(BluetoothShare.FILENAME_HINT));
- }
- if (info.mFileName == null) {
- info.mFileName = context.getString(R.string.unknown_file);
- }
+ int confirmationType;
+ try {
+ info.mID = cursor.getInt(cursor.getColumnIndexOrThrow(BluetoothShare._ID));
+ info.mStatus = cursor.getInt(cursor.getColumnIndexOrThrow(BluetoothShare.STATUS));
+ info.mDirection = cursor.getInt(cursor
+ .getColumnIndexOrThrow(BluetoothShare.DIRECTION));
+ info.mTotalBytes = cursor.getLong(cursor
+ .getColumnIndexOrThrow(BluetoothShare.TOTAL_BYTES));
+ info.mCurrentBytes = cursor.getLong(cursor
+ .getColumnIndexOrThrow(BluetoothShare.CURRENT_BYTES));
+ info.mTimeStamp = cursor.getLong(cursor
+ .getColumnIndexOrThrow(BluetoothShare.TIMESTAMP));
+ info.mDestAddr = cursor.getString(cursor
+ .getColumnIndexOrThrow(BluetoothShare.DESTINATION));
- info.mFileUri = cursor.getString(cursor.getColumnIndexOrThrow(BluetoothShare.URI));
+ info.mFileName = cursor.getString(cursor
+ .getColumnIndexOrThrow(BluetoothShare._DATA));
+ if (info.mFileName == null) {
+ info.mFileName = cursor.getString(cursor
+ .getColumnIndexOrThrow(BluetoothShare.FILENAME_HINT));
+ }
+ if (info.mFileName == null) {
+ info.mFileName = context.getString(R.string.unknown_file);
+ }
+
+ info.mFileUri = cursor.getString(cursor.getColumnIndexOrThrow(BluetoothShare.URI));
+
+ if (info.mFileUri != null) {
+ Uri u = originalUri(Uri.parse(info.mFileUri));
+ info.mFileType = context.getContentResolver().getType(u);
+ } else {
+ Uri u = Uri.parse(info.mFileName);
+ info.mFileType = context.getContentResolver().getType(u);
+ }
+
+ if (info.mFileType == null) {
+ info.mFileType = cursor.getString(cursor
+ .getColumnIndexOrThrow(BluetoothShare.MIMETYPE));
+ }
+
+ confirmationType = cursor.getInt(
+ cursor.getColumnIndexOrThrow(BluetoothShare.USER_CONFIRMATION));
- if (info.mFileUri != null) {
- Uri u = originalUri(Uri.parse(info.mFileUri));
- info.mFileType = context.getContentResolver().getType(u);
- } else {
- Uri u = Uri.parse(info.mFileName);
- info.mFileType = context.getContentResolver().getType(u);
- }
- if (info.mFileType == null) {
- info.mFileType = cursor.getString(cursor
- .getColumnIndexOrThrow(BluetoothShare.MIMETYPE));
+ } catch (IllegalArgumentException e) {
+ cursor.close();
+ cursor = null;
+ Log.e(TAG, "Invalid share info");
+ return null;
}
BluetoothDevice remoteDevice = adapter.getRemoteDevice(info.mDestAddr);
info.mDeviceName =
BluetoothOppManager.getInstance(context).getDeviceName(remoteDevice);
- int confirmationType = cursor.getInt(
- cursor.getColumnIndexOrThrow(BluetoothShare.USER_CONFIRMATION));
info.mHandoverInitiated =
confirmationType == BluetoothShare.USER_CONFIRMATION_HANDOVER_CONFIRMED;