Fix issues w/ security-related account data deletion

* Stop running syncs
* Delete all EmailProvider data except the account itself (with
  cleared sync key) and the account mailbox (necessary for syncing
  to sync after security hold is lifted

Bug: 3245779
Bug: 3253952
Change-Id: Idc208ef5ed85808b085ebab9c26a428fb0451e34
This commit is contained in:
Marc Blank 2011-01-07 16:31:31 -08:00
parent 2f1a7e8d0a
commit 69af769688
3 changed files with 20 additions and 13 deletions

View File

@ -98,8 +98,9 @@ public class Controller {
private static final String WHERE_MESSAGE_KEY = Body.MESSAGE_KEY + "=?";
private static final String MAILBOXES_FOR_ACCOUNT_SELECTION = MailboxColumns.ACCOUNT_KEY + "=?";
private static final String MAILBOXES_FOR_ACCOUNT_NOT_INBOX_SELECTION =
MAILBOXES_FOR_ACCOUNT_SELECTION + " AND " + MailboxColumns.TYPE + "!=" + Mailbox.TYPE_INBOX;
private static final String MAILBOXES_FOR_ACCOUNT_EXCEPT_ACCOUNT_MAILBOX_SELECTION =
MAILBOXES_FOR_ACCOUNT_SELECTION + " AND " + MailboxColumns.TYPE + "!=" +
Mailbox.TYPE_EAS_ACCOUNT_MAILBOX;
private static final String MESSAGES_FOR_ACCOUNT_SELECTION = MessageColumns.ACCOUNT_KEY + "=?";
// Service callbacks as set up via setCallback
@ -985,8 +986,8 @@ public class Controller {
* policy requirements are not met, and we don't want to reveal any synced data, but we do
* wish to keep the account configured (e.g. to accept remote wipe commands).
*
* Also, leave behind an empty inbox, which simplifies things for the UI.
* Also, clear the sync keys on the remaining account & mailbox, since the data is gone.
* The only mailbox not deleted is the account mailbox (if any)
* Also, clear the sync keys on the remaining account, since the data is gone.
*
* SYNCHRONOUS - do not call from UI thread.
*
@ -1002,7 +1003,8 @@ public class Controller {
// 2. Delete all remaining messages (which will be the inbox messages)
ContentResolver resolver = mProviderContext.getContentResolver();
String[] accountIdArgs = new String[] { Long.toString(accountId) };
resolver.delete(Mailbox.CONTENT_URI, MAILBOXES_FOR_ACCOUNT_NOT_INBOX_SELECTION,
resolver.delete(Mailbox.CONTENT_URI,
MAILBOXES_FOR_ACCOUNT_EXCEPT_ACCOUNT_MAILBOX_SELECTION,
accountIdArgs);
resolver.delete(Message.CONTENT_URI, MESSAGES_FOR_ACCOUNT_SELECTION, accountIdArgs);
@ -1015,7 +1017,7 @@ public class Controller {
resolver.update(Mailbox.CONTENT_URI, cv,
MAILBOXES_FOR_ACCOUNT_SELECTION, accountIdArgs);
// Delete PIM data (contacts, calendar) if applicable
// Delete PIM data (contacts, calendar), stop syncs, etc. if applicable
IEmailService service = getServiceForAccount(accountId);
if (service != null) {
service.deleteAccountPIMData(accountId);

View File

@ -464,6 +464,8 @@ public class ExchangeService extends Service implements Runnable {
public void deleteAccountPIMData(long accountId) throws RemoteException {
ExchangeService exchangeService = INSTANCE;
if (exchangeService == null) return;
// Stop any running syncs
exchangeService.stopAccountSyncs(accountId, true);
Mailbox mailbox =
Mailbox.restoreMailboxOfType(exchangeService, accountId, Mailbox.TYPE_CONTACTS);
if (mailbox != null) {

View File

@ -18,13 +18,13 @@ package com.android.email;
import com.android.email.provider.ContentCache;
import com.android.email.provider.EmailContent;
import com.android.email.provider.EmailProvider;
import com.android.email.provider.ProviderTestUtils;
import com.android.email.provider.EmailContent.Account;
import com.android.email.provider.EmailContent.Body;
import com.android.email.provider.EmailContent.HostAuth;
import com.android.email.provider.EmailContent.Mailbox;
import com.android.email.provider.EmailContent.Message;
import com.android.email.provider.EmailProvider;
import com.android.email.provider.ProviderTestUtils;
import android.content.Context;
import android.net.Uri;
@ -397,6 +397,10 @@ public class ControllerProviderOpsTests extends ProviderTestCase2<EmailProvider>
long box1Id = box1.mId;
Mailbox box2 = ProviderTestUtils.setupMailbox("box2", account1Id, true, mProviderContext);
long box2Id = box2.mId;
// An EAS account mailbox
Mailbox eas = ProviderTestUtils.setupMailbox("eas", account1Id, false, mProviderContext);
eas.mType = Mailbox.TYPE_EAS_ACCOUNT_MAILBOX;
eas.save(mProviderContext);
Account account2 = ProviderTestUtils.setupAccount("wipe-synced-2", false, mProviderContext);
account2.mSyncKey = "account-2-sync-key";
@ -410,7 +414,7 @@ public class ControllerProviderOpsTests extends ProviderTestCase2<EmailProvider>
Mailbox box4 = ProviderTestUtils.setupMailbox("box4", account2Id, true, mProviderContext);
long box4Id = box4.mId;
// Now populate all 4 with messages
// Now populate the 4 non-account boxes with messages
Message message = ProviderTestUtils.setupMessage("message1", account1Id, box1Id, false,
true, mProviderContext);
long message1Id = message.mId;
@ -427,11 +431,10 @@ public class ControllerProviderOpsTests extends ProviderTestCase2<EmailProvider>
// Now wipe account 1's data
mTestController.deleteSyncedDataSync(account1Id);
// Confirm: Mailboxes gone (except Inbox), all messages gone, account survives
box1 = Mailbox.restoreMailboxWithId(mProviderContext, box1Id);
assertNotNull(box1);
assertNull(box1.mSyncKey);
// Confirm: Mailboxes gone (except account box), all messages gone, account survives
assertNull(Mailbox.restoreMailboxWithId(mProviderContext, box1Id));
assertNull(Mailbox.restoreMailboxWithId(mProviderContext, box2Id));
assertNotNull(Mailbox.restoreMailboxWithId(mProviderContext, eas.mId));
assertNull(Message.restoreMessageWithId(mProviderContext, message1Id));
assertNull(Message.restoreMessageWithId(mProviderContext, message2Id));
account1 = Account.restoreAccountWithId(mProviderContext, account1Id);