diff options
Diffstat (limited to 'src/com/android/bluetooth/map')
5 files changed, 134 insertions, 19 deletions
diff --git a/src/com/android/bluetooth/map/BluetoothMapContent.java b/src/com/android/bluetooth/map/BluetoothMapContent.java index 2370a4d35..4f42bfb58 100755 --- a/src/com/android/bluetooth/map/BluetoothMapContent.java +++ b/src/com/android/bluetooth/map/BluetoothMapContent.java @@ -950,10 +950,14 @@ public class BluetoothMapContent { 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) { @@ -961,7 +965,7 @@ public class BluetoothMapContent { 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) @@ -1603,7 +1607,8 @@ public class BluetoothMapContent { } 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"; } @@ -1620,7 +1625,8 @@ public class BluetoothMapContent { } 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 878f5bedf..c70408ccb 100755 --- a/src/com/android/bluetooth/map/BluetoothMapContentObserver.java +++ b/src/com/android/bluetooth/map/BluetoothMapContentObserver.java @@ -37,6 +37,7 @@ import android.os.Message; import android.os.ParcelFileDescriptor; import android.os.Process; import android.os.RemoteException; +import android.os.UserManager; import android.provider.Telephony; import android.provider.Telephony.Mms; import android.provider.Telephony.MmsSms; @@ -172,7 +173,9 @@ public class BluetoothMapContentObserver { public static final String EXTRA_MESSAGE_SENT_TIMESTAMP = "timestamp"; private SmsBroadcastReceiver mSmsBroadcastReceiver = new SmsBroadcastReceiver(); + private CeBroadcastReceiver mCeBroadcastReceiver = new CeBroadcastReceiver(); + private boolean mStorageUnlocked = false; private boolean mInitialized = false; @@ -480,6 +483,12 @@ public class BluetoothMapContentObserver { Log.w(TAG, "onChange() with URI == null - not handled."); return; } + + if (!mStorageUnlocked) { + Log.v(TAG, "Ignore events until storage is completely unlocked"); + return; + } + if (V) Log.d(TAG, "onChange on thread: " + Thread.currentThread().getId() + " Uri: " + uri.toString() + " selfchange: " + selfChange); @@ -1184,9 +1193,10 @@ public class BluetoothMapContentObserver { private void initMsgList() throws RemoteException { if (V) Log.d(TAG, "initMsgList"); + UserManager manager = UserManager.get(mContext); + if (manager == null || !manager.isUserUnlocked()) return; - if(mEnableSmsMms) { - + if (mEnableSmsMms) { HashMap<Long, Msg> msgListSms = new HashMap<Long, Msg>(); Cursor c = mResolver.query(Sms.CONTENT_URI, @@ -2361,21 +2371,19 @@ public class BluetoothMapContentObserver { /* Approved MAP spec errata 3445 states that read status initiated * by the MCE shall change the MSE read status. */ if (type == TYPE.SMS_GSM || type == TYPE.SMS_CDMA) { - Uri uri = Sms.Inbox.CONTENT_URI; + Uri uri = ContentUris.withAppendedId(Sms.CONTENT_URI, handle); ContentValues contentValues = new ContentValues(); contentValues.put(Sms.READ, statusValue); contentValues.put(Sms.SEEN, statusValue); - String where = Sms._ID+"="+handle; String values = contentValues.toString(); - if (D) Log.d(TAG, " -> SMS Uri: " + uri.toString() + - " Where " + where + " values " + values); + if (D) Log.d(TAG, " -> SMS Uri: " + uri.toString() + " values " + values); synchronized(getMsgListSms()) { Msg msg = getMsgListSms().get(handle); if(msg != null) { // This will always be the case msg.flagRead = statusValue; } } - count = mResolver.update(uri, contentValues, where, null); + count = mResolver.update(uri, contentValues, null, null); if (D) Log.d(TAG, " -> "+count +" rows updated!"); } else if (type == TYPE.MMS) { @@ -2455,8 +2463,16 @@ public class BluetoothMapContentObserver { 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) ) { @@ -3190,6 +3206,52 @@ public class BluetoothMapContentObserver { } } + private class CeBroadcastReceiver extends BroadcastReceiver { + public void register() { + UserManager manager = UserManager.get(mContext); + if (manager == null || manager.isUserUnlocked()) { + mStorageUnlocked = true; + return; + } + + Handler handler = new Handler(Looper.getMainLooper()); + IntentFilter intentFilter = new IntentFilter(); + intentFilter.addAction(Intent.ACTION_BOOT_COMPLETED); + mContext.registerReceiver(this, intentFilter, null, handler); + } + + public void unregister() { + try { + mContext.unregisterReceiver(this); + } catch (IllegalArgumentException e) { + /* do nothing */ + } + } + + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + Log.d(TAG, "onReceive: action" + action); + + if (action.equals(Intent.ACTION_BOOT_COMPLETED)) { + try { + initMsgList(); + } catch (RemoteException e) { + Log.e(TAG, "Error initializing SMS/MMS message lists."); + } + + for (String folder : FOLDER_SMS_MAP.values()) { + Event evt = new Event(EVENT_TYPE_NEW, -1, folder, mSmsType); + sendEvent(evt); + } + mStorageUnlocked = true; + /* After unlock this BroadcastReceiver is never needed */ + unregister(); + } else { + Log.d(TAG, "onReceive: Unknown action " + action); + } + } + } + /** * Handle MMS sent intents in disconnected(MNS) state, where we do not need to send any * notifications. @@ -3331,6 +3393,8 @@ public class BluetoothMapContentObserver { private void resendPendingMessages() { /* Send pending messages in outbox */ String where = "type = " + Sms.MESSAGE_TYPE_OUTBOX; + UserManager manager = UserManager.get(mContext); + if (manager == null || !manager.isUserUnlocked()) return; Cursor c = mResolver.query(Sms.CONTENT_URI, SMS_PROJECTION, where, null, null); try { @@ -3398,6 +3462,11 @@ public class BluetoothMapContentObserver { if (mSmsBroadcastReceiver != null) { mSmsBroadcastReceiver.register(); } + + if (mCeBroadcastReceiver != null) { + mCeBroadcastReceiver.register(); + } + registerPhoneServiceStateListener(); mInitialized = true; } diff --git a/src/com/android/bluetooth/map/BluetoothMapMessageListingElement.java b/src/com/android/bluetooth/map/BluetoothMapMessageListingElement.java index 88e5605de..832060e86 100644 --- a/src/com/android/bluetooth/map/BluetoothMapMessageListingElement.java +++ b/src/com/android/bluetooth/map/BluetoothMapMessageListingElement.java @@ -27,6 +27,7 @@ import android.util.Log; import android.util.Xml; import com.android.bluetooth.map.BluetoothMapUtils.TYPE; +import com.android.bluetooth.util.Interop; public class BluetoothMapMessageListingElement implements Comparable<BluetoothMapMessageListingElement> { @@ -276,9 +277,17 @@ public class BluetoothMapMessageListingElement BluetoothMapUtils.getMapHandle(mCpHandle, mType)); if(mSubject != null){ String stripped = BluetoothMapUtils.stripInvalidChars(mSubject); + + if (Interop.matchByAddress(Interop.INTEROP_MAP_ASCIIONLY, + BluetoothMapService.getRemoteDevice().getAddress())) { + stripped = stripped.replaceAll("[\\P{ASCII}&\"><]", ""); + if (stripped.isEmpty()) stripped = "---"; + } + xmlMsgElement.attribute(null, "subject", stripped.substring(0, stripped.length() < 256 ? stripped.length() : 256)); } + if(mDateTime != 0) xmlMsgElement.attribute(null, "datetime", this.getDateTimeString()); if(mSenderName != null) diff --git a/src/com/android/bluetooth/map/BluetoothMapObexServer.java b/src/com/android/bluetooth/map/BluetoothMapObexServer.java index f0c26b0de..00b290215 100644 --- a/src/com/android/bluetooth/map/BluetoothMapObexServer.java +++ b/src/com/android/bluetooth/map/BluetoothMapObexServer.java @@ -24,6 +24,7 @@ import android.os.Handler; import android.os.Message; import android.os.ParcelUuid; import android.os.RemoteException; +import android.os.UserManager; import android.text.format.DateUtils; import android.util.Log; @@ -402,6 +403,11 @@ public class BluetoothMapObexServer extends ServerRequestHandler { return ResponseCodes.OBEX_HTTP_OK; } + private boolean isUserUnlocked() { + UserManager manager = UserManager.get(mContext); + return (manager == null || manager.isUserUnlocked()); + } + @Override public int onPut(final Operation op) { if (D) Log.d(TAG, "onPut(): enter"); @@ -431,26 +437,34 @@ public class BluetoothMapObexServer extends ServerRequestHandler { return ResponseCodes.OBEX_HTTP_OK; } return updateInbox(); - }else if(type.equals(TYPE_SET_NOTIFICATION_REGISTRATION)) { + } else if (type.equals(TYPE_SET_NOTIFICATION_REGISTRATION)) { if(V) { Log.d(TAG,"TYPE_SET_NOTIFICATION_REGISTRATION: NotificationStatus: " + appParams.getNotificationStatus()); } return mObserver.setNotificationRegistration(appParams.getNotificationStatus()); - }else if(type.equals(TYPE_SET_NOTIFICATION_FILTER)) { + } else if (type.equals(TYPE_SET_NOTIFICATION_FILTER)) { if(V) { Log.d(TAG,"TYPE_SET_NOTIFICATION_FILTER: NotificationFilter: " + appParams.getNotificationFilter()); } + if (!isUserUnlocked()) { + Log.e(TAG, "Storage locked, " + type + " failed"); + return ResponseCodes.OBEX_HTTP_UNAVAILABLE; + } mObserver.setNotificationFilter(appParams.getNotificationFilter()); return ResponseCodes.OBEX_HTTP_OK; - } else if(type.equals(TYPE_SET_MESSAGE_STATUS)) { + } else if (type.equals(TYPE_SET_MESSAGE_STATUS)) { if(V) { Log.d(TAG,"TYPE_SET_MESSAGE_STATUS: " + "StatusIndicator: " + appParams.getStatusIndicator() + ", StatusValue: " + appParams.getStatusValue() + ", ExtentedData: " + "" ); // TODO: appParams.getExtendedImData()); } + if (!isUserUnlocked()) { + Log.e(TAG, "Storage locked, " + type + " failed"); + return ResponseCodes.OBEX_HTTP_UNAVAILABLE; + } return setMessageStatus(name, appParams); } else if (type.equals(TYPE_MESSAGE)) { if(V) { @@ -458,6 +472,10 @@ public class BluetoothMapObexServer extends ServerRequestHandler { + ", retry: " + appParams.getRetry() + ", charset: " + appParams.getCharset()); } + if (!isUserUnlocked()) { + Log.e(TAG, "Storage locked, " + type + " failed"); + return ResponseCodes.OBEX_HTTP_UNAVAILABLE; + } return pushMessage(op, name, appParams, mMessageVersion); } else if (type.equals(TYPE_SET_OWNER_STATUS)) { if(V) { @@ -916,6 +934,10 @@ public class BluetoothMapObexServer extends ServerRequestHandler { Log.d(TAG,"FilterConvoId = " + ((tmpLongLong == null) ? "" : Long.toHexString(tmpLongLong.getLeastSignificantBits()) ) ); } + if (!isUserUnlocked()) { + Log.e(TAG, "Storage locked, " + type + " failed"); + return ResponseCodes.OBEX_HTTP_UNAVAILABLE; + } // Block until all packets have been send. return sendMessageListingRsp(op, appParams, name); @@ -930,6 +952,10 @@ public class BluetoothMapObexServer extends ServerRequestHandler { Log.d(TAG,"FilterReadStatus = " + appParams.getFilterReadStatus()); Log.d(TAG,"FilterRecipient = " + appParams.getFilterRecipient()); } + if (!isUserUnlocked()) { + Log.e(TAG, "Storage locked, " + type + " failed"); + return ResponseCodes.OBEX_HTTP_UNAVAILABLE; + } // Block until all packets have been send. return sendConvoListingRsp(op, appParams,name); } else if (type.equals(TYPE_GET_MAS_INSTANCE_INFORMATION)) { @@ -947,6 +973,10 @@ public class BluetoothMapObexServer extends ServerRequestHandler { ", Charset = " + appParams.getCharset() + ", FractionRequest = " + appParams.getFractionRequest()); } + if (!isUserUnlocked()) { + Log.e(TAG, "Storage locked, " + type + " failed"); + return ResponseCodes.OBEX_HTTP_UNAVAILABLE; + } // Block until all packets have been send. return sendGetMessageRsp(op, name, appParams, mMessageVersion); } else { @@ -1028,8 +1058,8 @@ public class BluetoothMapObexServer extends ServerRequestHandler { 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 { diff --git a/src/com/android/bluetooth/map/BluetoothMapService.java b/src/com/android/bluetooth/map/BluetoothMapService.java index 552bb09eb..addebf0c5 100755 --- a/src/com/android/bluetooth/map/BluetoothMapService.java +++ b/src/com/android/bluetooth/map/BluetoothMapService.java @@ -867,6 +867,7 @@ public class BluetoothMapService extends ProfileService { sendShutdownMessage(); } mStartError = true; + setState(BluetoothMap.STATE_DISCONNECTED, BluetoothMap.RESULT_CANCELED); return true; } |