diff options
Diffstat (limited to 'src/com/android/bluetooth/map/BluetoothMapContentObserver.java')
-rwxr-xr-x | src/com/android/bluetooth/map/BluetoothMapContentObserver.java | 87 |
1 files changed, 78 insertions, 9 deletions
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; } |