Allow MAP to accept and list draft messages without recipients
Bug: 28970268
Change-Id: I5bdef6cd67708036352ed37ea35b027d6a54af03
diff --git a/src/com/android/bluetooth/map/BluetoothMapContent.java b/src/com/android/bluetooth/map/BluetoothMapContent.java
index d14666f..326f9eb 100644
--- a/src/com/android/bluetooth/map/BluetoothMapContent.java
+++ b/src/com/android/bluetooth/map/BluetoothMapContent.java
@@ -949,10 +949,14 @@
address = c.getString(c.getColumnIndex(Sms.ADDRESS));
}
if ((address == null) && msgType == Sms.MESSAGE_TYPE_DRAFT) {
- //Fetch address for Drafts folder from "canonical_address" table
+ // Fetch address for Drafts folder from "canonical_address" table
int threadIdInd = c.getColumnIndex(Sms.THREAD_ID);
String threadIdStr = c.getString(threadIdInd);
- address = getCanonicalAddressSms(mResolver, Integer.valueOf(threadIdStr));
+ // If a draft message has no recipient, it has no thread ID
+ // hence threadIdStr could possibly be null
+ if (threadIdStr != null) {
+ address = getCanonicalAddressSms(mResolver, Integer.valueOf(threadIdStr));
+ }
if(V) Log.v(TAG, "threadId = " + threadIdStr + " adress:" + address +"\n");
}
} else if (fi.mMsgType == FilterInfo.TYPE_MMS) {
@@ -960,7 +964,7 @@
address = getAddressMms(mResolver, id, MMS_TO);
} else if (fi.mMsgType == FilterInfo.TYPE_EMAIL) {
/* Might be another way to handle addresses */
- address = getRecipientAddressingEmail(e, c,fi);
+ address = getRecipientAddressingEmail(e, c, fi);
}
if (V) Log.v(TAG, "setRecipientAddressing: " + address);
if(address == null)
@@ -1601,7 +1605,8 @@
} else if (BluetoothMapContract.FOLDER_NAME_SENT.equalsIgnoreCase(folder)) {
where = Sms.TYPE + " = 2 AND " + Sms.THREAD_ID + " <> -1";
} else if (BluetoothMapContract.FOLDER_NAME_DRAFT.equalsIgnoreCase(folder)) {
- where = Sms.TYPE + " = 3 AND " + Sms.THREAD_ID + " <> -1";
+ where = Sms.TYPE + " = 3 AND " +
+ "(" + Sms.THREAD_ID + " IS NULL OR " + Sms.THREAD_ID + " <> -1 )";
} else if (BluetoothMapContract.FOLDER_NAME_DELETED.equalsIgnoreCase(folder)) {
where = Sms.THREAD_ID + " = -1";
}
@@ -1618,7 +1623,8 @@
} else if (BluetoothMapContract.FOLDER_NAME_SENT.equalsIgnoreCase(folder)) {
where = Mms.MESSAGE_BOX + " = 2 AND " + Mms.THREAD_ID + " <> -1";
} else if (BluetoothMapContract.FOLDER_NAME_DRAFT.equalsIgnoreCase(folder)) {
- where = Mms.MESSAGE_BOX + " = 3 AND " + Mms.THREAD_ID + " <> -1";
+ where = Mms.MESSAGE_BOX + " = 3 AND " +
+ "(" + Mms.THREAD_ID + " IS NULL OR " + Mms.THREAD_ID + " <> -1 )";
} else if (BluetoothMapContract.FOLDER_NAME_DELETED.equalsIgnoreCase(folder)) {
where = Mms.THREAD_ID + " = -1";
}
diff --git a/src/com/android/bluetooth/map/BluetoothMapContentObserver.java b/src/com/android/bluetooth/map/BluetoothMapContentObserver.java
index a68298a..b7d8f3a 100644
--- a/src/com/android/bluetooth/map/BluetoothMapContentObserver.java
+++ b/src/com/android/bluetooth/map/BluetoothMapContentObserver.java
@@ -2442,8 +2442,16 @@
long folderId = -1;
if (recipientList == null) {
- if (D) Log.d(TAG, "empty recipient list");
- return -1;
+ if (folderElement.getName().equalsIgnoreCase(BluetoothMapContract.FOLDER_NAME_DRAFT)) {
+ BluetoothMapbMessage.vCard empty =
+ new BluetoothMapbMessage.vCard("", "", null, null, 0);
+ recipientList = new ArrayList<BluetoothMapbMessage.vCard>();
+ recipientList.add(empty);
+ Log.w(TAG, "Added empty recipient to draft message");
+ } else {
+ Log.e(TAG, "Trying to send a message with no recipients");
+ return -1;
+ }
}
if ( msg.getType().equals(TYPE.EMAIL) ) {
diff --git a/src/com/android/bluetooth/map/BluetoothMapObexServer.java b/src/com/android/bluetooth/map/BluetoothMapObexServer.java
index dc9bc43..be14559 100644
--- a/src/com/android/bluetooth/map/BluetoothMapObexServer.java
+++ b/src/com/android/bluetooth/map/BluetoothMapObexServer.java
@@ -993,8 +993,8 @@
return ResponseCodes.OBEX_HTTP_BAD_REQUEST;
}
Log.v(TAG,"sendMessageListingRsp: has sms " + folderToList.hasSmsMmsContent() +
- "has email " + folderToList.hasEmailContent() +
- "has IM " + folderToList.hasImContent() );
+ ", has email " + folderToList.hasEmailContent() +
+ ", has IM " + folderToList.hasImContent() );
}
try {