diff options
| author | yingying <yingying@codeaurora.org> | 2014-03-24 15:29:51 +0800 |
|---|---|---|
| committer | Adnan <adnan@cyngn.com> | 2014-09-03 15:39:08 -0700 |
| commit | f53340c64877ac59a80254769dc596012e389836 (patch) | |
| tree | 437ec587858396e0ce9214ccc9f157f237c1a63e | |
| parent | 58ff9fbea50e6281e569a35399e8ddd5b45f406d (diff) | |
| download | android_packages_apps_Email-f53340c64877ac59a80254769dc596012e389836.tar.gz android_packages_apps_Email-f53340c64877ac59a80254769dc596012e389836.tar.bz2 android_packages_apps_Email-f53340c64877ac59a80254769dc596012e389836.zip | |
Email: New a receiver to handle the checking mail action.
As the recevier need protect the checking mail action by a permission,
but the receiver also handle the secret code action which couldn't
protected by the permission. So we need move the checking mail action
to a new receiver and handle it.
Change-Id: I5e3a5f36ba2512ac8970d3f7650cee16d58d768f
| -rw-r--r-- | AndroidManifest.xml | 19 | ||||
| -rw-r--r-- | src/com/android/email/service/EmailBroadcastReceiver.java | 85 | ||||
| -rw-r--r-- | src/com/android/email/service/EmailServiceStub.java | 75 | ||||
| -rw-r--r-- | src/com/android/email/service/ImapService.java | 85 | ||||
| -rw-r--r-- | src/com/android/email/service/Pop3Service.java | 37 |
5 files changed, 157 insertions, 144 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index c5b3279d4..6f73c15f7 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -413,14 +413,12 @@ <receiver android:name=".service.EmailBroadcastReceiver" - android:enabled="true" - android:permission="com.android.email.permission.ACCESS_PROVIDER"> + android:enabled="true"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.DEVICE_STORAGE_LOW" /> <action android:name="android.intent.action.DEVICE_STORAGE_OK" /> <action android:name="android.accounts.LOGIN_ACCOUNTS_CHANGED" /> - <action android:name="com.android.email.intent.action.MAIL_SERVICE_WAKEUP" /> </intent-filter> <!-- To handle new message notifications --> <intent-filter> @@ -438,6 +436,14 @@ android:host="36245" /> </intent-filter> </receiver> + <receiver + android:name=".service.EmailBroadcastReceiver$ServiceWakeupReceiver" + android:permission="com.android.email.permission.ACCESS_PROVIDER"> + <intent-filter> + <action android:name="com.android.email.intent.action.MAIL_SERVICE_WAKEUP" /> + </intent-filter> + </receiver> + <service android:name=".service.EmailBroadcastProcessorService" /> @@ -548,19 +554,14 @@ <action android:name="com.android.email.IMAP_INTENT" /> </intent-filter> + <!-- ImapService could handle these actions which send from BT now. --> <intent-filter> <action android:name="org.codeaurora.email.intent.action.MAIL_SERVICE_DELETE_MESSAGE" /> - </intent-filter> - <intent-filter> <action android:name="org.codeaurora.email.intent.action.MAIL_SERVICE_MOVE_MESSAGE" /> - </intent-filter> - <intent-filter> <action android:name="org.codeaurora.email.intent.action.MAIL_SERVICE_MESSAGE_READ" /> - </intent-filter> - <intent-filter> <action android:name="org.codeaurora.email.intent.action.MAIL_SERVICE_SEND_PENDING" /> </intent-filter> diff --git a/src/com/android/email/service/EmailBroadcastReceiver.java b/src/com/android/email/service/EmailBroadcastReceiver.java index cc005af3f..1396d7cf8 100644 --- a/src/com/android/email/service/EmailBroadcastReceiver.java +++ b/src/com/android/email/service/EmailBroadcastReceiver.java @@ -19,59 +19,60 @@ package com.android.email.service; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; -import com.android.email.Preferences; + import com.android.email.R; -import com.android.email.SecurityPolicy; -import com.android.email.activity.setup.AccountSettings; -import com.android.email.provider.AccountReconciler; -import com.android.email.provider.EmailProvider; -import com.android.emailcommon.Logging; -import com.android.emailcommon.VendorPolicyLoader; import com.android.emailcommon.provider.Account; -import com.android.emailcommon.provider.EmailContent; -import com.android.emailcommon.provider.EmailContent.AccountColumns; -import com.android.emailcommon.provider.HostAuth; import com.android.emailcommon.provider.Mailbox; import com.android.mail.utils.LogUtils; -import android.util.Log; - /** - * The broadcast receiver. The actual job is done in EmailBroadcastProcessor on a worker thread. + * The broadcast receiver. The actual job is done in EmailBroadcastProcessor on a worker thread. */ public class EmailBroadcastReceiver extends BroadcastReceiver { -private static final String ACTION_CHECK_MAIL = "com.android.email.intent.action.MAIL_SERVICE_WAKEUP"; -private static final String EXTRA_ACCOUNT = "com.android.email.intent.extra.ACCOUNT"; -private static final String TAG = "EmailBroadcastReceiver"; - @Override public void onReceive(Context context, Intent intent) { - Log.d(TAG,"Received " + intent.getAction()); - if(ACTION_CHECK_MAIL.equals(intent.getAction())) { - Intent i; - final long accountId = intent.getLongExtra(EXTRA_ACCOUNT, -1); - Log.d(TAG,"accountId is " + accountId); - final long inboxId = Mailbox.findMailboxOfType(context, accountId, - Mailbox.TYPE_INBOX); - Log.d(TAG,"inboxId is " + inboxId); - Mailbox mailbox = Mailbox.restoreMailboxWithId(context, inboxId); - if (mailbox == null) return; - Account account = Account.restoreAccountWithId(context, mailbox.mAccountKey); + EmailBroadcastProcessorService.processBroadcastIntent(context, intent); + } + + public static class ServiceWakeupReceiver extends BroadcastReceiver { + private static final String TAG = "ServiceWakeupReceiver"; + private static final String EXTRA_ACCOUNT = "com.android.email.intent.extra.ACCOUNT"; + private static final String ACTION_CHECK_MAIL = + "com.android.email.intent.action.MAIL_SERVICE_WAKEUP"; + + @Override + public void onReceive(Context context, Intent intent) { + if (ACTION_CHECK_MAIL.equals(intent.getAction())) { + final long accountId = intent.getLongExtra(EXTRA_ACCOUNT, -1); + final long inboxId = Mailbox.findMailboxOfType(context, accountId, + Mailbox.TYPE_INBOX); + final Mailbox mailbox = Mailbox.restoreMailboxWithId(context, inboxId); + LogUtils.d(TAG, "account id is: " + accountId + ", inbox id is: " + inboxId); + if (mailbox == null) { + LogUtils.w(TAG, "Inbox do not exist, do nothing."); + return; + } + + Account account = Account.restoreAccountWithId(context, accountId); + String protocol = account.getProtocol(context); + LogUtils.d(TAG, "protocol is " + protocol); - String protocol = account.getProtocol(context); - Log.d(TAG,"protocol is "+protocol); - String legacyImapProtocol = context.getString(R.string.protocol_legacy_imap); - if (protocol.equals(legacyImapProtocol)) { - i = new Intent(context, ImapService.class); - } else { - i = new Intent(context, Pop3Service.class); - } - i.setAction(intent.getAction()); - i.putExtra("com.android.email.intent.extra.ACCOUNT", intent.getLongExtra(EXTRA_ACCOUNT, -1)); - context.startService(i); - } else { - EmailBroadcastProcessorService.processBroadcastIntent(context, intent); + Intent i; + String legacyImapProtocol = context.getString(R.string.protocol_legacy_imap); + String pop3Protocol = context.getString(R.string.protocol_pop3); + if (legacyImapProtocol.equals(protocol)) { + i = new Intent(context, ImapService.class); + } else if (pop3Protocol.equals(protocol)) { + i = new Intent(context, Pop3Service.class); + } else { + // Do not support the Exchange account now. + return; + } + i.setAction(intent.getAction()); + i.putExtra("com.android.email.intent.extra.ACCOUNT", accountId); + context.startService(i); + } } - } + } } diff --git a/src/com/android/email/service/EmailServiceStub.java b/src/com/android/email/service/EmailServiceStub.java index 7fdcecee9..e1cdb7227 100644 --- a/src/com/android/email/service/EmailServiceStub.java +++ b/src/com/android/email/service/EmailServiceStub.java @@ -120,21 +120,19 @@ public abstract class EmailServiceStub extends IEmailService.Stub implements IEm /** * Delete a single message by moving it to the trash, or really delete it if it's already in - * trash or a draft message. - * - * This function has no callback, no result reporting, because the desired outcome - * is reflected entirely by changes to one or more cursors. + * trash or a draft message. This function has no callback, no result reporting, because the + * desired outcome is reflected entirely by changes to one or more cursors. * * @param messageId The id of the message to "delete". */ - public void deleteMessage(long messageId) { - + public void deleteMessage(long messageId) { final EmailContent.Message message = - EmailContent.Message.restoreMessageWithId(mContext, messageId); - if (message == null) { + EmailContent.Message.restoreMessageWithId(mContext, messageId); + if (message == null) { if (Logging.LOGD) LogUtils.v(Logging.LOG_TAG, "dletMsg message NULL"); return; - } + } + // 1. Get the message's account final Account account = Account.restoreAccountWithId(mContext, message.mAccountKey); // 2. Get the message's original mailbox @@ -143,60 +141,67 @@ public abstract class EmailServiceStub extends IEmailService.Stub implements IEm if (Logging.LOGD) LogUtils.v(Logging.LOG_TAG, "dletMsg account or mailbox NULL"); return; } - if(Logging.LOGD) - LogUtils.d(Logging.LOG_TAG, "AccountKey "+account.mId + "oirigMailbix: "+mailbox.mId); - // 3. Confirm that there is a trash mailbox available. If not, create one - Mailbox trashFolder = Mailbox.restoreMailboxOfType(mContext, account.mId, Mailbox.TYPE_TRASH); + if (Logging.LOGD) { + LogUtils.d(Logging.LOG_TAG, "AccountKey " + account.mId + "oirigMailbix: " + + mailbox.mId); + } + + // 3. Confirm that there is a trash mailbox available. If not, create one + Mailbox trashFolder = Mailbox.restoreMailboxOfType(mContext, account.mId, + Mailbox.TYPE_TRASH); if (trashFolder == null) { if (Logging.LOGD) LogUtils.v(Logging.LOG_TAG, "dletMsg Trash mailbox NULL"); - }else - LogUtils.d(Logging.LOG_TAG, "TrasMailbix: "+ trashFolder.mId); - // 4. Drop non-essential data for the message (e.g. attachment files) + } else { + LogUtils.d(Logging.LOG_TAG, "TrasMailbix: " + trashFolder.mId); + } + + // 4. Drop non-essential data for the message (e.g. attachment files) AttachmentUtilities.deleteAllAttachmentFiles(mContext, account.mId, messageId); + // 5. Perform "delete" as appropriate Uri uri = ContentUris.withAppendedId(EmailContent.Message.SYNCED_CONTENT_URI, messageId); - - // 5. Perform "delete" as appropriate if ((mailbox.mId == trashFolder.mId) || (mailbox.mType == Mailbox.TYPE_DRAFTS)) { // 5a. Really delete it - mContext.getContentResolver().delete(uri, null, null); + mContext.getContentResolver().delete(uri, null, null); } else { // 5b. Move to trash ContentValues cv = new ContentValues(); cv.put(EmailContent.MessageColumns.MAILBOX_KEY, trashFolder.mId); - mContext.getContentResolver().update(uri, cv, null, null); + mContext.getContentResolver().update(uri, cv, null, null); } - requestSync(mailbox.mId,true,0); + + requestSync(mailbox.mId, true, 0); } -/** - * Moves messages to a new mailbox. - * - * This function has no callback, no result reporting, because the desired outcome - * is reflected entirely by changes to one or more cursors. - * - * Note this method assumes all of the given message and mailbox IDs belong to the same - * account. + + /** + * Moves messages to a new mailbox. This function has no callback, no result reporting, because + * the desired outcome is reflected entirely by changes to one or more cursors. Note this method + * assumes all of the given message and mailbox IDs belong to the same account. * * @param messageIds IDs of the messages that are to be moved * @param newMailboxId ID of the new mailbox that the messages will be moved to * @return an asynchronous task that executes the move (for testing only) */ - public void MoveMessages(long messageId, long newMailboxId) { + public void MoveMessages(long messageId, long newMailboxId) { Account account = Account.getAccountForMessageId(mContext, messageId); if (account != null) { - if (Logging.LOGD) - LogUtils.d(Logging.LOG_TAG, "moveMessage Acct "+account.mId + "messageId:" + messageId); + if (Logging.LOGD) { + LogUtils.d(Logging.LOG_TAG, "moveMessage Acct " + account.mId + "messageId:" + + messageId); + } ContentValues cv = new ContentValues(); cv.put(EmailContent.MessageColumns.MAILBOX_KEY, newMailboxId); ContentResolver resolver = mContext.getContentResolver(); Uri uri = ContentUris.withAppendedId( - EmailContent.Message.SYNCED_CONTENT_URI, messageId); + EmailContent.Message.SYNCED_CONTENT_URI, messageId); resolver.update(uri, cv, null, null); - } else + } else { LogUtils.d(Logging.LOG_TAG, "moveMessage Cannot find account"); - } + } + } + /** * Set/clear boolean columns of a message * diff --git a/src/com/android/email/service/ImapService.java b/src/com/android/email/service/ImapService.java index c8d659917..a9896b9f3 100644 --- a/src/com/android/email/service/ImapService.java +++ b/src/com/android/email/service/ImapService.java @@ -106,18 +106,24 @@ public class ImapService extends Service { * We write this into the serverId field of messages that will never be upsynced. */ private static final String LOCAL_SERVERID_PREFIX = "Local-"; - private static final String ACTION_CHECK_MAIL = "com.android.email.intent.action.MAIL_SERVICE_WAKEUP"; - private static final String EXTRA_ACCOUNT = "com.android.email.intent.extra.ACCOUNT"; + + private static final String EXTRA_ACCOUNT = + "com.android.email.intent.extra.ACCOUNT"; + private static final String EXTRA_MESSAGE_ID = + "org.codeaurora.email.intent.extra.MESSAGE_ID"; + private static final String EXTRA_MESSAGE_INFO = + "org.codeaurora.email.intent.extra.MESSAGE_INFO"; + + private static final String ACTION_CHECK_MAIL = + "com.android.email.intent.action.MAIL_SERVICE_WAKEUP"; private static final String ACTION_DELETE_MESSAGE = - "org.codeaurora.email.intent.action.MAIL_SERVICE_DELETE_MESSAGE"; + "org.codeaurora.email.intent.action.MAIL_SERVICE_DELETE_MESSAGE"; private static final String ACTION_MOVE_MESSAGE = - "org.codeaurora.email.intent.action.MAIL_SERVICE_MOVE_MESSAGE"; + "org.codeaurora.email.intent.action.MAIL_SERVICE_MOVE_MESSAGE"; private static final String ACTION_MESSAGE_READ = - "org.codeaurora.email.intent.action.MAIL_SERVICE_MESSAGE_READ"; + "org.codeaurora.email.intent.action.MAIL_SERVICE_MESSAGE_READ"; private static final String ACTION_SEND_PENDING_MAIL = - "org.codeaurora.email.intent.action.MAIL_SERVICE_SEND_PENDING"; - private static final String EXTRA_MESSAGE_ID = "org.codeaurora.email.intent.extra.MESSAGE_ID"; - private static final String EXTRA_MESSAGE_INFO = "org.codeaurora.email.intent.extra.MESSAGE_INFO"; + "org.codeaurora.email.intent.action.MAIL_SERVICE_SEND_PENDING"; @Override public int onStartCommand(Intent intent, int flags, int startId) { @@ -129,83 +135,84 @@ public class ImapService extends Service { Context context = getApplicationContext(); if (ACTION_CHECK_MAIL.equals(action)) { final long inboxId = Mailbox.findMailboxOfType(context, accountId, - Mailbox.TYPE_INBOX); + Mailbox.TYPE_INBOX); if (Logging.LOGD) { - LogUtils.d(Logging.LOG_TAG,"accountId is " + accountId); - LogUtils.d(Logging.LOG_TAG,"inboxId is " + inboxId); + LogUtils.d(Logging.LOG_TAG, "accountId is " + accountId); + LogUtils.d(Logging.LOG_TAG, "inboxId is " + inboxId); } - if (accountId <= -1 || inboxId <= -1 ){ - return START_NOT_STICKY; + if (accountId <= -1 || inboxId <= -1) { + return START_NOT_STICKY; } mBinder.init(context); - mBinder.requestSync(inboxId,true,0); + mBinder.requestSync(inboxId, true, 0); } else if (ACTION_DELETE_MESSAGE.equals(action)) { final long messageId = intent.getLongExtra(EXTRA_MESSAGE_ID, -1); if (Logging.LOGD) { LogUtils.d(Logging.LOG_TAG, "action: Delete Message mail"); - LogUtils.d(Logging.LOG_TAG, "action: delmsg "+messageId); + LogUtils.d(Logging.LOG_TAG, "action: delmsg " + messageId); } - if (accountId <= -1 || messageId <= -1 ){ - return START_NOT_STICKY; + if (accountId <= -1 || messageId <= -1) { + return START_NOT_STICKY; } try { mBinder.init(context); mBinder.deleteMessage(messageId); processPendingActionsSynchronous(context, - Account.getAccountForMessageId(context, messageId)); - } catch (Exception e){ - LogUtils.d(Logging.LOG_TAG,"RemoteException " +e); + Account.getAccountForMessageId(context, messageId)); + } catch (Exception e) { + LogUtils.d(Logging.LOG_TAG, "RemoteException " + e); } } else if (ACTION_MESSAGE_READ.equals(action)) { final long messageId = intent.getLongExtra(EXTRA_MESSAGE_ID, -1); final int flagRead = intent.getIntExtra(EXTRA_MESSAGE_INFO, 0); if (Logging.LOGD) { LogUtils.d(Logging.LOG_TAG, "action: Message Mark Read or UnRead "); - LogUtils.d(Logging.LOG_TAG, "action: delmsg "+messageId); + LogUtils.d(Logging.LOG_TAG, "action: delmsg " + messageId); } - if (accountId <= -1 || messageId <= -1 ) { + if (accountId <= -1 || messageId <= -1) { return START_NOT_STICKY; } try { - mBinder.init(context); - mBinder.setMessageRead(messageId, (flagRead == 1)? true:false); - processPendingActionsSynchronous(context, - Account.getAccountForMessageId(context, messageId)); - } catch (Exception e){ - LogUtils.d(Logging.LOG_TAG,"RemoteException " +e); + mBinder.init(context); + mBinder.setMessageRead(messageId, (flagRead == 1) ? true : false); + processPendingActionsSynchronous(context, + Account.getAccountForMessageId(context, messageId)); + } catch (Exception e) { + LogUtils.d(Logging.LOG_TAG, "RemoteException " + e); } } else if (ACTION_MOVE_MESSAGE.equals(action)) { final long messageId = intent.getLongExtra(EXTRA_MESSAGE_ID, -1); - final int mailboxType = intent.getIntExtra(EXTRA_MESSAGE_INFO, Mailbox.TYPE_INBOX); + final int mailboxType = intent.getIntExtra(EXTRA_MESSAGE_INFO, Mailbox.TYPE_INBOX); final long mailboxId = Mailbox.findMailboxOfType(context, accountId, mailboxType); if (Logging.LOGD) { LogUtils.d(Logging.LOG_TAG, "action: Move Message mail"); - LogUtils.d(Logging.LOG_TAG, "action: movemsg "+ messageId + "mailbox: " + mailboxType + - "accountId: "+accountId + " mailboxId: " + mailboxId); + LogUtils.d(Logging.LOG_TAG, "action: movemsg " + messageId + "mailbox: " + + mailboxType + + "accountId: " + accountId + " mailboxId: " + mailboxId); } - if (accountId <= -1 || messageId <= -1 || mailboxId <= -1){ + if (accountId <= -1 || messageId <= -1 || mailboxId <= -1) { return START_NOT_STICKY; } try { mBinder.init(context); mBinder.MoveMessages(messageId, mailboxId); processPendingActionsSynchronous(context, - Account.getAccountForMessageId(context, messageId)); - } catch (Exception e){ - LogUtils.d(Logging.LOG_TAG,"RemoteException " +e); + Account.getAccountForMessageId(context, messageId)); + } catch (Exception e) { + LogUtils.d(Logging.LOG_TAG, "RemoteException " + e); } } else if (ACTION_SEND_PENDING_MAIL.equals(action)) { if (Logging.LOGD) { - LogUtils.d(Logging.LOG_TAG, "action: Send Pending Mail "+accountId); + LogUtils.d(Logging.LOG_TAG, "action: Send Pending Mail " + accountId); } - if (accountId <= -1 ) { - return START_NOT_STICKY; + if (accountId <= -1) { + return START_NOT_STICKY; } try { mBinder.init(context); mBinder.sendMail(accountId); } catch (Exception e) { - LogUtils.e(Logging.LOG_TAG,"RemoteException " +e); + LogUtils.e(Logging.LOG_TAG, "RemoteException " + e); } } diff --git a/src/com/android/email/service/Pop3Service.java b/src/com/android/email/service/Pop3Service.java index c4669db85..5bb6c080c 100644 --- a/src/com/android/email/service/Pop3Service.java +++ b/src/com/android/email/service/Pop3Service.java @@ -67,32 +67,31 @@ import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; -import android.util.Log; public class Pop3Service extends Service { private static final String TAG = "Pop3Service"; private static final int DEFAULT_SYNC_COUNT = 100; - private static final String ACTION_CHECK_MAIL = "com.android.email.intent.action.MAIL_SERVICE_WAKEUP"; - private static final String EXTRA_ACCOUNT = "com.android.email.intent.extra.ACCOUNT"; - private static final String EXTRA_MSGID = "com.android.email.intent.extra.MSGID"; + + private static final String ACTION_CHECK_MAIL = + "com.android.email.intent.action.MAIL_SERVICE_WAKEUP"; + private static final String EXTRA_ACCOUNT = + "com.android.email.intent.extra.ACCOUNT"; @Override public int onStartCommand(Intent intent, int flags, int startId) { - Log.d(TAG,"Inside onStartCommand"); - final String action = intent.getAction(); - Log.d(TAG,"action is " + action); - Context context = getApplicationContext(); - if (ACTION_CHECK_MAIL.equals(action)) { - final long accountId = intent.getLongExtra(EXTRA_ACCOUNT, -1); - Log.d(TAG,"accountId is " + accountId); - final long inboxId = Mailbox.findMailboxOfType(context, accountId, - Mailbox.TYPE_INBOX); - Log.d(TAG,"inboxId is " + inboxId); - mBinder.init(context); - mBinder.requestSync(inboxId,true,0); - } - - return Service.START_STICKY; + final String action = intent.getAction(); + LogUtils.d(TAG, "Start with command, action: " + action); + Context context = getApplicationContext(); + if (ACTION_CHECK_MAIL.equals(action)) { + final long accountId = intent.getLongExtra(EXTRA_ACCOUNT, -1); + final long inboxId = Mailbox.findMailboxOfType(context, accountId, + Mailbox.TYPE_INBOX); + LogUtils.d(TAG, "account id is: " + accountId + ", inbox id is: " + inboxId); + mBinder.init(context); + mBinder.requestSync(inboxId, true, 0); + } + + return Service.START_STICKY; } /** |
