summaryrefslogtreecommitdiffstats
path: root/src/com/android/bluetooth/map
diff options
context:
space:
mode:
authorSudhir Sharma <sudhshar@codeaurora.org>2015-03-10 01:21:10 -0700
committerSudhir Sharma <sudhshar@codeaurora.org>2015-03-10 15:27:58 -0700
commit9d81dc62517d86b1fccc65bcf87193819ce7c66d (patch)
tree6f7aa485047446c6cd41ea9d7f2617a4270cab1e /src/com/android/bluetooth/map
parentbb5835ad23b6357bb98848a481c971cc169739a9 (diff)
parent2ab3133a5c3a70fe1184ba8ff63ac3365f648a4e (diff)
downloadandroid_packages_apps_Bluetooth-9d81dc62517d86b1fccc65bcf87193819ce7c66d.tar.gz
android_packages_apps_Bluetooth-9d81dc62517d86b1fccc65bcf87193819ce7c66d.tar.bz2
android_packages_apps_Bluetooth-9d81dc62517d86b1fccc65bcf87193819ce7c66d.zip
Merge tag 'android-5.1.0_r1' into HEAD
Android 5.1.0 release 1 Conflicts: src/com/android/bluetooth/btservice/AdapterService.java src/com/android/bluetooth/gatt/AdvertiseManager.java src/com/android/bluetooth/gatt/ScanManager.java src/com/android/bluetooth/hfp/HeadsetPhoneState.java src/com/android/bluetooth/hfp/HeadsetStateMachine.java src/com/android/bluetooth/map/BluetoothMapContent.java src/com/android/bluetooth/map/BluetoothMapContentObserver.java src/com/android/bluetooth/map/BluetoothMapEmailSettingsLoader.java src/com/android/bluetooth/map/BluetoothMapObexServer.java src/com/android/bluetooth/map/BluetoothMapService.java src/com/android/bluetooth/opp/BluetoothOppIncomingFileConfirmActivity.java src/com/android/bluetooth/opp/BluetoothOppService.java src/com/android/bluetooth/pbap/BluetoothPbapVcardManager.java Change-Id: Ic7a754ea29d6124d7e53b6f13eed181d3f7e64e5
Diffstat (limited to 'src/com/android/bluetooth/map')
-rw-r--r--src/com/android/bluetooth/map/BluetoothMapContent.java283
-rw-r--r--src/com/android/bluetooth/map/BluetoothMapContentObserver.java224
-rwxr-xr-xsrc/com/android/bluetooth/map/BluetoothMapObexServer.java20
-rw-r--r--src/com/android/bluetooth/map/BluetoothMapService.java22
-rw-r--r--src/com/android/bluetooth/map/BluetoothMapSmsPdu.java2
5 files changed, 324 insertions, 227 deletions
diff --git a/src/com/android/bluetooth/map/BluetoothMapContent.java b/src/com/android/bluetooth/map/BluetoothMapContent.java
index 05cd7c46c..df15f66d8 100644
--- a/src/com/android/bluetooth/map/BluetoothMapContent.java
+++ b/src/com/android/bluetooth/map/BluetoothMapContent.java
@@ -56,6 +56,20 @@ import com.android.bluetooth.map.BluetoothMapUtils.TYPE;
import com.google.android.mms.pdu.CharacterSets;
import com.google.android.mms.pdu.PduHeaders;
import android.database.sqlite.SQLiteException;
+import com.android.bluetooth.map.BluetoothMapAppParams;
+
+import java.io.ByteArrayOutputStream;
+import java.io.Closeable;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
import java.util.List;
import java.util.ArrayList;
import java.util.*;
@@ -311,8 +325,15 @@ public class BluetoothMapContent {
if (D) Log.d(TAG, sb.toString());
} catch (IOException e) {
- // do nothing for now
- e.printStackTrace();
+ // do nothing for now
+ e.printStackTrace();
+ }
+ }
+
+ private static void close(Closeable c) {
+ try {
+ if (c != null) c.close();
+ } catch (IOException e) {
}
}
@@ -929,10 +950,6 @@ public class BluetoothMapContent {
}
}
- if( name ==null) {
- //set empty value
- name = "";
- }
if (D) Log.d(TAG, "setSenderName: " + name);
e.setSenderName(name);
}
@@ -973,7 +990,7 @@ public class BluetoothMapContent {
Uri uriAddress = Uri.parse(uriStr);
Cursor c = mResolver.query(uriAddress, null, selection,
null, null);
-
+ // TODO: maybe use a projection with only "ct" and "text"
if (c != null && c.moveToFirst()) {
do {
String ct = c.getString(c.getColumnIndex("ct"));
@@ -1103,14 +1120,13 @@ public class BluetoothMapContent {
String orderBy = Contacts.DISPLAY_NAME + " ASC";
Cursor c = mResolver.query(uri, projection, selection, null, orderBy);
-
- if (c != null && c.getCount() >= 1) {
- c.moveToFirst();
- name = c.getString(c.getColumnIndex(Contacts.DISPLAY_NAME));
- }
-
- if (c != null) {
- c.close();
+ try {
+ if (c != null && c.getCount() >= 1) {
+ c.moveToFirst();
+ name = c.getString(c.getColumnIndex(Contacts.DISPLAY_NAME));
+ };
+ } finally {
+ close(c);
}
return name;
}
@@ -1120,15 +1136,16 @@ public class BluetoothMapContent {
String uriStr = String.format("content://mms/%d/addr", id);
Uri uriAddress = Uri.parse(uriStr);
String addr = null;
- Cursor c = r.query(uriAddress, null, selection, null, null);
- if (c != null && c.moveToFirst()) {
- addr = c.getString(c.getColumnIndex("address"));
+ Cursor c = r.query(uriAddress, null, selection, null, null);
+ try {
+ if (c != null && c.moveToFirst()) {
+ addr = c.getString(c.getColumnIndex(Mms.Addr.ADDRESS));
+ }
+ } finally {
+ close(c);
}
- if (c != null) {
- c.close();
- }
return addr;
}
@@ -1511,32 +1528,31 @@ public class BluetoothMapContent {
new String[]{str},
ContactsContract.Contacts.DISPLAY_NAME + " ASC");
- while (c != null && c.moveToNext()) {
- String contactId = c.getString(c.getColumnIndex(ContactsContract.Contacts._ID));
+ try {
+ while (c != null && c.moveToNext()) {
+ String contactId = c.getString(c.getColumnIndex(ContactsContract.Contacts._ID));
- Cursor p = mResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
- ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?",
- new String[]{contactId},
- null);
+ Cursor p = mResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
+ ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?",
+ new String[]{contactId},
+ null);
- while (p != null && p.moveToNext()) {
- String number = p.getString(
- p.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
+ try {
+ while (p != null && p.moveToNext()) {
+ String number = p.getString(
+ p.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
- where += " address = " + "'" + number + "'";
- if (!p.isLast()) {
- where += " OR ";
+ where += " address = " + "'" + number + "'";
+ if (!p.isLast()) where += " OR ";
+ }
+ } finally {
+ close(p);
}
+
+ if (!c.isLast()) where += " OR ";
}
- if (!c.isLast()) {
- where += " OR ";
- }
- if (p != null) {
- p.close();
- }
- }
- if (c != null) {
- c.close();
+ } finally {
+ close(c);
}
if (str != null && str.length() > 0) {
@@ -2217,16 +2233,7 @@ public class BluetoothMapContent {
fi.msgType = FilterInfo.TYPE_EMAIL;
String where = setWhereFilter(folder, fi, ap);
- where+= " AND "+ Message.FLAG_LOADED_SELECTION;
- where+= " order by timeStamp desc ";
- //Fetch only maxListCount emails from startOffset
- if(ap.getMaxListCount() > 0 && ap.getMaxListCount() < 65536) {
- where+=" LIMIT "+ap.getMaxListCount();
- }
- if(ap.getStartOffset() > 0 && ap.getStartOffset() < 65536) {
- where+=" OFFSET "+ap.getStartOffset();
- }
- if (V) Log.d(TAG, "where clause is = " + where);
+ Log.d(TAG, "where clause is = " + where);
try {
Cursor c = mResolver.query(uriEmail,
EMAIL_PROJECTION, where + " AND " + Message.FLAG_LOADED_SELECTION, null, "timeStamp desc");
@@ -2252,8 +2259,7 @@ public class BluetoothMapContent {
/* Enable this if post sorting and segmenting needed */
bmList.sort();
- //Handle OFFSET and MAXLISTCOUNT from DB query
- //bmList.segment(ap.getMaxListCount(), ap.getStartOffset());
+ bmList.segment(ap.getMaxListCount(), ap.getStartOffset());
return bmList;
}
@@ -2334,23 +2340,14 @@ public class BluetoothMapContent {
/* Cache some info used throughout filtering */
FilterInfo fi = new FilterInfo();
setFilterInfo(fi);
-
if (smsSelected(fi, ap)) {
fi.msgType = FilterInfo.TYPE_SMS;
if(ap.getFilterPriority() != 1){ /*SMS cannot have high priority*/
String where = setWhereFilter(folder, fi, ap);
- Cursor c =null;
- //Fetch only maxListCount messages from startOffset
- if(ap.getStartOffset() > 0 && ap.getStartOffset() < 65536) {
- c = mResolver.query(Sms.CONTENT_URI,
- SMS_PROJECTION, where, null, "date DESC" + " limit " +
- ap.getMaxListCount()+" offset "+ ap.getStartOffset());
- }else {
- c = mResolver.query(Sms.CONTENT_URI,
- SMS_PROJECTION, where, null, "date DESC" + " limit " +
- ap.getMaxListCount());
- }
- if (V) Log.d(TAG, "where clause is = " + where);
+
+ Cursor c = mResolver.query(Sms.CONTENT_URI,
+ SMS_PROJECTION, where, null, "date DESC");
+
if (c != null) {
while (c.moveToNext()) {
if (matchAddresses(c, fi, ap)) {
@@ -2366,20 +2363,12 @@ public class BluetoothMapContent {
if (mmsSelected(fi, ap)) {
fi.msgType = FilterInfo.TYPE_MMS;
+
String where = setWhereFilter(folder, fi, ap);
where += " AND " + INTERESTED_MESSAGE_TYPE_CLAUSE;
- Cursor c =null;
- //Fetch only maxListCount messages from startOffset
- if(ap.getStartOffset() > 0 && ap.getStartOffset() < 65536) {
- c = mResolver.query(Mms.CONTENT_URI,
- MMS_PROJECTION, where, null, "date DESC" + " limit " +
- ap.getMaxListCount()+" offset "+ ap.getStartOffset());
- } else {
- c = mResolver.query(Mms.CONTENT_URI,
- MMS_PROJECTION, where, null, "date DESC" + " limit " +
- ap.getMaxListCount());
- }
- if (V) Log.d(TAG, "where clause is = " + where);
+ Cursor c = mResolver.query(Mms.CONTENT_URI,
+ MMS_PROJECTION, where, null, "date DESC");
+
if (c != null) {
int cnt = 0;
while (c.moveToNext()) {
@@ -2392,10 +2381,10 @@ public class BluetoothMapContent {
c.close();
}
}
+
/* Enable this if post sorting and segmenting needed */
bmList.sort();
- //Handle OFFSET and MAXLISTCOUNT from DB query
- //bmList.segment(ap.getMaxListCount(), ap.getStartOffset());
+ bmList.segment(ap.getMaxListCount(), ap.getStartOffset());
return bmList;
}
@@ -2415,8 +2404,8 @@ public class BluetoothMapContent {
SMS_PROJECTION, where, null, "date DESC");
if (c != null) {
- cnt = c.getCount();
- c.close();
+ cnt = c.getCount();
+ c.close();
}
}
@@ -2458,10 +2447,8 @@ public class BluetoothMapContent {
Cursor c = mResolver.query(Sms.CONTENT_URI,
SMS_PROJECTION, where, null, "date DESC");
- if (c != null) {
- cnt = c.getCount();
- c.close();
- }
+ if (c != null) cnt += c.getCount();
+ c.close();
}
if (mmsSelected(fi, ap)) {
@@ -2473,8 +2460,8 @@ public class BluetoothMapContent {
MMS_PROJECTION, where, null, "date DESC");
if (c != null) {
- cnt += c.getCount();
- c.close();
+ cnt += c.getCount();
+ c.close();
}
}
@@ -2568,7 +2555,6 @@ public class BluetoothMapContent {
String contactId = null, contactName = null;
String[] phoneNumbers = null;
String[] emailAddresses = null;
- Cursor p;
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
Uri.encode(phone));
@@ -2578,53 +2564,42 @@ public class BluetoothMapContent {
String orderBy = Contacts._ID + " ASC";
// Get the contact _ID and name
- p = mResolver.query(uri, projection, selection, null, orderBy);
- if (p != null && p.getCount() >= 1) {
- p.moveToFirst();
- contactId = p.getString(p.getColumnIndex(Contacts._ID));
- contactName = p.getString(p.getColumnIndex(Contacts.DISPLAY_NAME));
- }
- if (p != null)
- p.close();
-
- // Add only original sender's contact number in VCARD.
- phoneNumbers = new String[1];
- phoneNumbers[0] = phone;
- if(contactId != null) {
- // Do not fetch and add all the contacts in vcard to avoid IOT issues with carkits
- /*
- // Fetch all contact phone numbers
- p = mResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
- ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?",
- new String[]{contactId},
- null);
- if(p != null) {
- int i = 0;
- phoneNumbers = new String[p.getCount()];
- while (p != null && p.moveToNext()) {
- String number = p.getString(
- p.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
- phoneNumbers[i++] = number;
- }
- p.close();
+ Cursor p = mResolver.query(uri, projection, selection, null, orderBy);
+
+ try {
+ if (p != null && p.getCount() >= 1) {
+ p.moveToFirst();
+ contactId = p.getString(p.getColumnIndex(Contacts._ID));
+ contactName = p.getString(p.getColumnIndex(Contacts.DISPLAY_NAME));
}
- */
- // Fetch contact e-mail addresses
- p = mResolver.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, null,
- ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?",
- new String[]{contactId},
- null);
- if(p != null) {
- int i = 0;
- emailAddresses = new String[p.getCount()];
- while (p != null && p.moveToNext()) {
- String emailAddress = p.getString(
- p.getColumnIndex(ContactsContract.CommonDataKinds.Email.ADDRESS));
- emailAddresses[i++] = emailAddress;
+ // Bail out if we are unable to find a contact, based on the phone number
+ if(contactId == null) {
+ phoneNumbers = new String[1];
+ phoneNumbers[0] = phone;
+ } else {
+ // use only actual phone number
+ phoneNumbers = new String[1];
+ phoneNumbers[0] = phone;
+
+ // Fetch contact e-mail addresses
+ close (p);
+ p = mResolver.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, null,
+ ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?",
+ new String[]{contactId},
+ null);
+ if (p != null) {
+ int i = 0;
+ emailAddresses = new String[p.getCount()];
+ while (p != null && p.moveToNext()) {
+ String emailAddress = p.getString(
+ p.getColumnIndex(ContactsContract.CommonDataKinds.Email.ADDRESS));
+ emailAddresses[i++] = emailAddress;
+ }
}
- p.close();
}
+ } finally {
+ close(p);
}
if(incoming == true)
message.addOriginator(contactName, contactName, phoneNumbers, emailAddresses); // Use version 3.0 as we only have a formatted name
@@ -2641,11 +2616,13 @@ public class BluetoothMapContent {
String msgBody;
BluetoothMapbMessageSms message = new BluetoothMapbMessageSms();
TelephonyManager tm = (TelephonyManager)mContext.getSystemService(Context.TELEPHONY_SERVICE);
- Cursor c = mResolver.query(Sms.CONTENT_URI, SMS_PROJECTION, "_ID = " + id, null, null);
- if(c != null && c.moveToFirst())
- {
+ Cursor c = mResolver.query(Sms.CONTENT_URI, SMS_PROJECTION, "_ID = " + id, null, null);
+ if (c == null || !c.moveToFirst()) {
+ throw new IllegalArgumentException("SMS handle not found");
+ }
+ try {
if(V) Log.v(TAG,"c.count: " + c.getCount());
if (tm.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) {
@@ -2685,12 +2662,11 @@ public class BluetoothMapContent {
} else /*if (charset == MAP_MESSAGE_CHARSET_UTF8)*/ {
message.setSmsBody(msgBody);
}
-
- c.close();
-
- return message.encode();
+ } finally {
+ close(c);
}
- throw new IllegalArgumentException("SMS handle not found");
+
+ return message.encode();
}
private void extractMmsAddresses(long id, BluetoothMapbMessageMmsEmail message) {
@@ -2850,6 +2826,7 @@ public class BluetoothMapContent {
} while(c.moveToNext());
c.close();
}
+
message.updateCharset();
}
@@ -2865,8 +2842,11 @@ public class BluetoothMapContent {
int msgBox, threadId;
BluetoothMapbMessageMmsEmail message = new BluetoothMapbMessageMmsEmail();
Cursor c = mResolver.query(Mms.CONTENT_URI, MMS_PROJECTION, "_ID = " + id, null, null);
- if(c != null && c.moveToFirst())
- {
+ if (c == null || !c.moveToFirst()) {
+ throw new IllegalArgumentException("MMS handle not found");
+ }
+
+ try {
message.setType(TYPE.MMS);
// The MMS info:
@@ -2886,24 +2866,13 @@ public class BluetoothMapContent {
message.setDate(c.getLong(c.getColumnIndex(Mms.DATE)) * 1000L);
message.setTextOnly(c.getInt(c.getColumnIndex(Mms.TEXT_ONLY)) == 0 ? false : true); // - TODO: Do we need this - yes, if we have only text, we should not make this a multipart message
message.setIncludeAttachments(appParams.getAttachment() == 0 ? false : true);
- // c.getLong(c.getColumnIndex(Mms.DATE_SENT)); - this is never used
- // c.getInt(c.getColumnIndex(Mms.STATUS)); - don't know what this is
- // The parts
extractMmsParts(id, message);
-
- // The addresses
extractMmsAddresses(id, message);
-
- c.close();
-
- return message.encode();
- }
- else if(c != null) {
- c.close();
+ } finally {
+ close(c);
}
- throw new IllegalArgumentException("MMS handle not found");
+ return message.encode();
}
-
}
diff --git a/src/com/android/bluetooth/map/BluetoothMapContentObserver.java b/src/com/android/bluetooth/map/BluetoothMapContentObserver.java
index 4a8caaafb..e746ce927 100644
--- a/src/com/android/bluetooth/map/BluetoothMapContentObserver.java
+++ b/src/com/android/bluetooth/map/BluetoothMapContentObserver.java
@@ -14,7 +14,10 @@
*/
package com.android.bluetooth.map;
+
import java.io.ByteArrayInputStream;
+import java.io.Closeable;
+
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
@@ -83,6 +86,13 @@ public class BluetoothMapContentObserver {
private TYPE mSmsType;
+ private static void close(Closeable c) {
+ try {
+ if (c != null) c.close();
+ } catch (IOException e) {
+ }
+ }
+
static final String[] SMS_PROJECTION = new String[] {
BaseColumns._ID,
Sms.THREAD_ID,
@@ -362,41 +372,53 @@ public class BluetoothMapContentObserver {
mMsgListSms.clear();
mMsgListMms.clear();
+
HashMap<Long, Msg> msgListSms = new HashMap<Long, Msg>();
Cursor c = mResolver.query(Sms.CONTENT_URI,
SMS_PROJECTION, null, null, null);
- if (c != null && c.moveToFirst()) {
- do {
- long id = c.getLong(c.getColumnIndex(BaseColumns._ID));
- int type = c.getInt(c.getColumnIndex(Sms.TYPE));
- Msg msg = new Msg(id, type);
- msgListSms.put(id, msg);
- } while (c.moveToNext());
- c.close();
- }
+ try {
+ while (c != null && c.moveToNext()) {
+ long id = c.getLong(c.getColumnIndex(Sms._ID));
+ int type = c.getInt(c.getColumnIndex(Sms.TYPE));
+
+
+ Msg msg = new Msg(id, type);
+ msgListSms.put(id, msg);
+ }
+ } finally {
+ close(c);
+ }
+
+ synchronized(mMsgListSms) {
+ mMsgListSms.clear();
+ mMsgListSms = msgListSms;
+ }
+
+
- mMsgListSms = msgListSms;
HashMap<Long, Msg> msgListMms = new HashMap<Long, Msg>();
- c = mResolver.query(Mms.CONTENT_URI,
- MMS_PROJECTION, null, null, null);
+ try {
+ while (c != null && c.moveToNext()) {
+ long id = c.getLong(c.getColumnIndex(Mms._ID));
+ int type = c.getInt(c.getColumnIndex(Mms.MESSAGE_BOX));
- if (c != null && c.moveToFirst()) {
- do {
- long id = c.getLong(c.getColumnIndex(BaseColumns._ID));
- int type = c.getInt(c.getColumnIndex(Mms.MESSAGE_BOX));
- Msg msg = new Msg(id, type);
- msgListMms.put(id, msg);
- } while (c.moveToNext());
- c.close();
- }
+ Msg msg = new Msg(id, type );
+ msgListMms.put(id, msg);
+ }
+ } finally {
+ close(c);
+ }
- mMsgListMms = msgListMms;
+ synchronized(mMsgListMms) {
+ mMsgListMms.clear();
+ mMsgListMms = msgListMms;
+ }
}
private void handleMsgListChangesSms() {
@@ -535,7 +557,9 @@ public class BluetoothMapContentObserver {
mResolver.update(uri, contentValues, null, null);
} else {
/* Delete from observer message list to avoid delete notifications */
- mMsgListMms.remove(handle);
+ synchronized(mMsgListMms) {
+ mMsgListMms.remove(handle);
+ }
/* Delete message */
mResolver.delete(uri, null, null);
}
@@ -544,6 +568,7 @@ public class BluetoothMapContentObserver {
if (c != null) {
c.close();
}
+
return res;
}
@@ -603,7 +628,9 @@ public class BluetoothMapContentObserver {
mResolver.update(uri, contentValues, null, null);
} else {
/* Delete from observer message list to avoid delete notifications */
- mMsgListSms.remove(handle);
+ synchronized(mMsgListSms) {
+ mMsgListSms.remove(handle);
+ }
/* Delete message */
mResolver.delete(uri, null, null);
}
@@ -757,15 +784,39 @@ public class BluetoothMapContentObserver {
case SMS_CDMA:
{
/* Add the message to the database */
+
String phone = recipient.getFirstPhoneNumber();
+
String msgBody = ((BluetoothMapbMessageSms) msg).getSmsBody();
- Uri contentUri = Uri.parse("content://sms/" + folder);
- Uri uri = Sms.addMessageToUri(mResolver, contentUri, phone, msgBody,
- "", System.currentTimeMillis(), read, deliveryReport);
- if (uri == null) {
- Log.d(TAG, "pushMessage - failure on add to uri " + contentUri);
- return -1;
+ /* We need to lock the SMS list while updating the database, to avoid sending
+ * events on MCE initiated operation. */
+ Uri contentUri = Uri.parse(Sms.CONTENT_URI+ "/" + folder);
+ Uri uri;
+ synchronized(mMsgListSms) {
+ uri = Sms.addMessageToUri(mResolver, contentUri, phone, msgBody,
+ "", System.currentTimeMillis(), read, deliveryReport);
+
+ if(V) Log.v(TAG, "Sms.addMessageToUri() returned: " + uri);
+ if (uri == null) {
+ if (D) Log.d(TAG, "pushMessage - failure on add to uri " + contentUri);
+ return -1;
+ }
+ Cursor c = mResolver.query(uri, SMS_PROJECTION, null, null, null);
+ try {
+ /* Extract the data for the inserted message, and store in local mirror, to
+ * avoid sending a NewMessage Event. */
+ if (c != null && c.moveToFirst()) {
+ long id = c.getLong(c.getColumnIndex(Sms._ID));
+ int type = c.getInt(c.getColumnIndex(Sms.TYPE));
+ Msg newMsg = new Msg(id, type );
+ mMsgListSms.put(id, newMsg);
+ } else {
+ return -1; // This can only happen, if the message is deleted just as it is added
+ }
+ } finally {
+ close(c);
+ }
}
handle = Long.parseLong(uri.getLastPathSegment());
@@ -836,7 +887,6 @@ public class BluetoothMapContentObserver {
}
-
private void moveDraftToOutbox(long handle) {
ContentResolver contentResolver = mContext.getContentResolver();
/*Move message by changing the msg_box value in the content provider database */
@@ -844,7 +894,8 @@ public class BluetoothMapContentObserver {
String whereClause = " _id= " + handle;
Uri uri = Uri.parse("content://mms");
Cursor queryResult = contentResolver.query(uri, null, whereClause, null, null);
- if (queryResult != null) {
+ try {
+ if (queryResult != null) {
if (queryResult.getCount() > 0) {
queryResult.moveToFirst();
ContentValues data = new ContentValues();
@@ -853,10 +904,14 @@ public class BluetoothMapContentObserver {
contentResolver.update(uri, data, whereClause, null);
Log.d(TAG, "moved draft MMS to outbox");
}
- queryResult.close();
+
addMceInitiatedOperation(Long.toString(handle));
- }else {
+ } else {
Log.d(TAG, "Could not move draft to outbox ");
+
+ }
+ } finally {
+ queryResult.close();
}
}
}
@@ -894,26 +949,51 @@ public class BluetoothMapContentObserver {
// Get thread id
Set<String> recipients = new HashSet<String>();
recipients.addAll(Arrays.asList(to_address));
- values.put("thread_id", Telephony.Threads.getOrCreateThreadId(mContext, recipients));
- Uri uri = Uri.parse("content://mms");
+ values.put(Mms.THREAD_ID, Telephony.Threads.getOrCreateThreadId(mContext, recipients));
+ Uri uri = Mms.CONTENT_URI;
- ContentResolver cr = mContext.getContentResolver();
- uri = cr.insert(uri, values);
+ synchronized (mMsgListMms) {
+ uri = mResolver.insert(uri, values);
- if (uri == null) {
- // unable to insert MMS
- Log.e(TAG, "Unabled to insert MMS " + values + "Uri: " + uri);
- return -1;
- }
+ if (uri == null) {
+ // unable to insert MMS
+ Log.e(TAG, "Unabled to insert MMS " + values + "Uri: " + uri);
+ return -1;
+ }
+ /* As we already have all the values we need, we could skip the query, but
+ doing the query ensures we get any changes made by the content provider
+ at insert. */
+ Cursor c = mResolver.query(uri, MMS_PROJECTION, null, null, null);
+ try {
+ if (c != null && c.moveToFirst()) {
+ long id = c.getLong(c.getColumnIndex(Mms._ID));
+ int type = c.getInt(c.getColumnIndex(Mms.MESSAGE_BOX));
+
+
+ /* We must filter out any actions made by the MCE. Add the new message to
+ * the list of known messages. */
+
+ Msg newMsg = new Msg(id, type);
+ mMsgListMms.put(id, newMsg);
+ }
+ } finally {
+ close(c);
+ }
+ } // Done adding changes, unlock access to mMsgListMms to allow sending MMS events again
long handle = Long.parseLong(uri.getLastPathSegment());
- ArrayList<MimePart> parts = msg.getMimeParts();
- if (parts != null) {
- Log.v(TAG, " NEW URI " + uri.toString());
- try {
- for(MimePart part : parts) {
- int count = 0;
- count++;
+ if (V) Log.v(TAG, " NEW URI " + uri.toString());
+
+ try {
+ if(msg.getMimeParts() == null) {
+ /* Perhaps this message have been deleted, and no longer have any content, but only headers */
+ Log.w(TAG, "No MMS parts present...");
+ } else {
+ if(V) Log.v(TAG, "Adding " + msg.getMimeParts().size() + " parts to the data base.");
+ int count = 0;
+ for(MimePart part : msg.getMimeParts()) {
+ ++count;
+
values.clear();
if(part.contentType != null &&
part.contentType.toUpperCase().contains("TEXT")) {
@@ -936,7 +1016,7 @@ public class BluetoothMapContentObserver {
values.put("cd", part.contentDisposition);
values.put("text", new String(part.data, "UTF-8"));
uri = Uri.parse("content://mms/" + handle + "/part");
- uri = cr.insert(uri, values);
+ uri = mResolver.insert(uri, values);
if(V) Log.v(TAG, "Added TEXT part");
} else if (part.contentType != null &&
part.contentType.toUpperCase().contains("SMIL")) {
@@ -953,7 +1033,7 @@ public class BluetoothMapContentObserver {
values.put("text", new String(part.data, "UTF-8"));
uri = Uri.parse("content://mms/" + handle + "/part");
- uri = cr.insert(uri, values);
+ uri = mResolver.insert(uri, values);
if(V) Log.v(TAG, "Added SMIL part");
} else /*VIDEO/AUDIO/IMAGE*/ {
writeMmsDataPart(handle, part, count);
@@ -965,12 +1045,13 @@ public class BluetoothMapContentObserver {
}
}
addMceInitiatedOperation("+");
- } catch (UnsupportedEncodingException e) {
+ }
+ }
+ catch (UnsupportedEncodingException e) {
Log.w(TAG, e);
} catch (IOException e) {
Log.w(TAG, e);
}
- }
values.clear();
values.put("contact_id", "null");
values.put("address", "insert-address-token");
@@ -978,7 +1059,7 @@ public class BluetoothMapContentObserver {
values.put("charset", 106);
uri = Uri.parse("content://mms/" + handle + "/addr");
- uri = cr.insert(uri, values);
+ uri = mResolver.insert(uri, values);
if (uri != null && V){
Log.v(TAG, " NEW URI " + uri.toString());
}
@@ -990,7 +1071,7 @@ public class BluetoothMapContentObserver {
values.put("charset", 106);
uri = Uri.parse("content://mms/" + handle + "/addr");
- uri = cr.insert(uri, values);
+ uri = mResolver.insert(uri, values);
if (uri != null && V){
Log.v(TAG, " NEW URI " + uri.toString());
}
@@ -1235,30 +1316,34 @@ public class BluetoothMapContentObserver {
String where = "type = " + Sms.MESSAGE_TYPE_OUTBOX;
Cursor c = mResolver.query(Sms.CONTENT_URI, SMS_PROJECTION, where, null,
null);
+ if (c == null) return;
+ try {
+ while (c!= null && c.moveToNext()) {
+ long id = c.getLong(c.getColumnIndex(Sms._ID));
- if (c != null && c.moveToFirst()) {
- do {
- long id = c.getLong(c.getColumnIndex(BaseColumns._ID));
String msgBody = c.getString(c.getColumnIndex(Sms.BODY));
PushMsgInfo msgInfo = mPushMsgList.get(id);
if (msgInfo == null || msgInfo.resend == false) {
continue;
}
sendMessage(msgInfo, msgBody);
- } while (c.moveToNext());
- c.close();
+ }
+ } finally {
+ close(c);
}
}
private void failPendingMessages() {
/* Move pending messages from outbox to failed */
String where = "type = " + Sms.MESSAGE_TYPE_OUTBOX;
- Cursor c = mResolver.query(Sms.CONTENT_URI, SMS_PROJECTION, where, null,
- null);
+ Cursor c = mResolver.query(Sms.CONTENT_URI, SMS_PROJECTION, where, null, null);
+ if (c == null) return;
+
+
+ try {
+ while (c!= null && c.moveToNext()) {
+ long id = c.getLong(c.getColumnIndex(Sms._ID));
- if (c != null && c.moveToFirst()) {
- do {
- long id = c.getLong(c.getColumnIndex(BaseColumns._ID));
String msgBody = c.getString(c.getColumnIndex(Sms.BODY));
PushMsgInfo msgInfo = mPushMsgList.get(id);
if (msgInfo == null || msgInfo.resend == false) {
@@ -1266,9 +1351,10 @@ public class BluetoothMapContentObserver {
}
Sms.moveMessageToFolder(mContext, msgInfo.uri,
Sms.MESSAGE_TYPE_FAILED, 0);
- } while (c.moveToNext());
+ }
+ } finally {
+ close(c);
}
- if (c != null) c.close();
}
private void removeDeletedMessages() {
@@ -1277,7 +1363,7 @@ public class BluetoothMapContentObserver {
"thread_id = " + DELETED_THREAD_ID, null);
}
- private PhoneStateListener mPhoneListener = new PhoneStateListener (Long.MAX_VALUE - 1,
+ private PhoneStateListener mPhoneListener = new PhoneStateListener (Integer.MAX_VALUE - 1,
Looper.getMainLooper()) {
@Override
public void onServiceStateChanged(ServiceState serviceState) {
diff --git a/src/com/android/bluetooth/map/BluetoothMapObexServer.java b/src/com/android/bluetooth/map/BluetoothMapObexServer.java
index 644191f80..bcb3bcc0a 100755
--- a/src/com/android/bluetooth/map/BluetoothMapObexServer.java
+++ b/src/com/android/bluetooth/map/BluetoothMapObexServer.java
@@ -148,6 +148,26 @@ public class BluetoothMapObexServer extends ServerRequestHandler {
tmpFolder.addFolder("drafts");
}
+ private void addEmailFolders(BluetoothMapFolderElement parentFolder) throws RemoteException {
+ // Select all parent folders
+ BluetoothMapFolderElement newFolder;
+
+ String where = BluetoothMapContract.FolderColumns.PARENT_FOLDER_ID +
+ " = " + parentFolder.getEmailFolderId();
+ Cursor c = mProviderClient.query(mEmailFolderUri,
+ BluetoothMapContract.BT_FOLDER_PROJECTION, where, null, null);
+ try {
+ while (c != null && c.moveToNext()) {
+ String name = c.getString(c.getColumnIndex(BluetoothMapContract.FolderColumns.NAME));
+ long id = c.getLong(c.getColumnIndex(BluetoothMapContract.FolderColumns._ID));
+ newFolder = parentFolder.addEmailFolder(name, id);
+ addEmailFolders(newFolder); // Use recursion to add any sub folders
+ }
+ } finally {
+ if (c != null) c.close();
+ }
+ }
+
@Override
public int onConnect(final HeaderSet request, HeaderSet reply) {
if (D) Log.d(TAG, "onConnect():");
diff --git a/src/com/android/bluetooth/map/BluetoothMapService.java b/src/com/android/bluetooth/map/BluetoothMapService.java
index 73963b48d..672079822 100644
--- a/src/com/android/bluetooth/map/BluetoothMapService.java
+++ b/src/com/android/bluetooth/map/BluetoothMapService.java
@@ -1205,4 +1205,26 @@ public class BluetoothMapService extends ProfileService {
return service.getPriority(device);
}
};
+
+ @Override
+ public void dump(StringBuilder sb) {
+ super.dump(sb);
+ println(sb, "mRemoteDevice: " + mRemoteDevice);
+ println(sb, "sRemoteDeviceName: " + sRemoteDeviceName);
+ println(sb, "mState: " + mState);
+ println(sb, "mAppObserver: " + mAppObserver);
+ println(sb, "mIsWaitingAuthorization: " + mIsWaitingAuthorization);
+ println(sb, "mRemoveTimeoutMsg: " + mRemoveTimeoutMsg);
+ println(sb, "mPermission: " + mPermission);
+ println(sb, "mAccountChanged: " + mAccountChanged);
+ println(sb, "mBluetoothMnsObexClient: " + mBluetoothMnsObexClient);
+ println(sb, "mMasInstanceMap:");
+ for (BluetoothMapEmailSettingsItem key : mMasInstanceMap.keySet()) {
+ println(sb, " " + key + " : " + mMasInstanceMap.get(key));
+ }
+ println(sb, "mEnabledAccounts:");
+ for (BluetoothMapEmailSettingsItem account : mEnabledAccounts) {
+ println(sb, " " + account);
+ }
+ }
}
diff --git a/src/com/android/bluetooth/map/BluetoothMapSmsPdu.java b/src/com/android/bluetooth/map/BluetoothMapSmsPdu.java
index caf8b02e3..bf91a56de 100644
--- a/src/com/android/bluetooth/map/BluetoothMapSmsPdu.java
+++ b/src/com/android/bluetooth/map/BluetoothMapSmsPdu.java
@@ -471,7 +471,7 @@ public class BluetoothMapSmsPdu {
int activePhone = TelephonyManager.getDefault().getCurrentPhoneType(); // TODO: Change to use: ((TelephonyManager)myContext.getSystemService(Context.TELEPHONY_SERVICE))
int phoneType;
GsmAlphabet.TextEncodingDetails ted = (PHONE_TYPE_CDMA == activePhone) ?
- com.android.internal.telephony.cdma.SmsMessage.calculateLength((CharSequence)messageText, false) :
+ com.android.internal.telephony.cdma.SmsMessage.calculateLength((CharSequence)messageText, false, true) :
com.android.internal.telephony.gsm.SmsMessage.calculateLength((CharSequence)messageText, false);
SmsPdu newPdu;