Exit most activities when accounts are deleted

This resolves cases like this:  You are in the inbox of an Exchange
account.  You click home, settings, accounts & sync, and you delete
the account.  Now re-enter the Email app.  You'll be left in a strangely
empty inbox, for an account that no longer exists.

* Set a flag any time the reconciler deletes an account
* Check that flag in onResume of any activity that depends on the account
    list and could be left in an "empty" state if account(s) are deleted.
* The Activities in which we check it are:
  * AccountFolderList
  * AccountSettings
  * MailboxList
  * MessageCompose
  * MessageList
  * MessageView
* Clear the flag any time we come in through Welcome, which will dispatch
    to other activities properly based on the number of accounts found.

Bug: 2563998
Change-Id: I00fc542581c2bed92d744a4c2e48a88f83737f11
This commit is contained in:
Andrew Stadler 2010-04-14 09:28:04 -07:00
parent 383b7dd29d
commit 5e354cd1db
9 changed files with 75 additions and 0 deletions

View File

@ -143,6 +143,12 @@ public class Email extends Application {
private static HashMap<Long, Long> sMailboxSyncTimes = new HashMap<Long, Long>();
private static final long UPDATE_INTERVAL = 5 * DateUtils.MINUTE_IN_MILLIS;
/**
* This is used to force stacked UI to return to the "welcome" screen any time we change
* the accounts list (e.g. deleting accounts in the Account Manager preferences.)
*/
private static boolean sAccountsChangedNotification = false;
public static final String EXCHANGE_ACCOUNT_MANAGER_TYPE = "com.android.exchange";
// The color chip resources and the RGB color values in the array below must be kept in sync
@ -296,4 +302,21 @@ public class Email extends Application {
> UPDATE_INTERVAL);
}
}
/**
* Called by the accounts reconciler to notify that accounts have changed, or by "Welcome"
* to clear the flag.
* @param setFlag true to set the notification flag, false to clear it
*/
public static synchronized void setNotifyUiAccountsChanged(boolean setFlag) {
sAccountsChangedNotification = setFlag;
}
/**
* Called from activity onResume() functions to check for an accounts-changed condition, at
* which point they should finish() and jump to the Welcome activity.
*/
public static synchronized boolean getNotifyUiAccountsChanged() {
return sAccountsChangedNotification;
}
}

View File

@ -197,6 +197,13 @@ public class AccountFolderList extends ListActivity implements OnItemClickListen
Controller.getInstance(getApplication()).addResultCallback(mControllerCallback);
// Exit immediately if the accounts list has changed (e.g. externally deleted)
if (Email.getNotifyUiAccountsChanged()) {
Welcome.actionStart(this);
finish();
return;
}
updateAccounts();
// TODO: What updates do we need to auto-trigger, now that we have mailboxes in view?
}

View File

@ -182,6 +182,14 @@ public class MailboxList extends ListActivity implements OnItemClickListener, On
public void onResume() {
super.onResume();
Controller.getInstance(getApplication()).addResultCallback(mControllerCallback);
// Exit immediately if the accounts list has changed (e.g. externally deleted)
if (Email.getNotifyUiAccountsChanged()) {
Welcome.actionStart(this);
finish();
return;
}
updateMessageCount();
// TODO: may need to clear notifications here

View File

@ -368,6 +368,13 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
public void onResume() {
super.onResume();
mController.addResultCallback(mListener);
// Exit immediately if the accounts list has changed (e.g. externally deleted)
if (Email.getNotifyUiAccountsChanged()) {
Welcome.actionStart(this);
finish();
return;
}
}
@Override

View File

@ -317,6 +317,14 @@ public class MessageList extends ListActivity implements OnItemClickListener, On
NotificationManager notificationManager = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(MailService.NOTIFICATION_ID_NEW_MESSAGES);
// Exit immediately if the accounts list has changed (e.g. externally deleted)
if (Email.getNotifyUiAccountsChanged()) {
Welcome.actionStart(this);
finish();
return;
}
restoreListPosition();
autoRefreshStaleMailbox();
}

View File

@ -448,6 +448,14 @@ public class MessageView extends Activity implements OnClickListener {
super.onResume();
mWaitForLoadMessageId = -1;
mController.addResultCallback(mControllerCallback);
// Exit immediately if the accounts list has changed (e.g. externally deleted)
if (Email.getNotifyUiAccountsChanged()) {
Welcome.actionStart(this);
finish();
return;
}
if (mMessage != null) {
startPresenceCheck();

View File

@ -17,6 +17,7 @@
package com.android.email.activity;
import com.android.email.AccountBackupRestore;
import com.android.email.Email;
import com.android.email.ExchangeUtils;
import com.android.email.activity.setup.AccountSetupBasics;
import com.android.email.provider.EmailContent;
@ -48,6 +49,9 @@ public class Welcome extends Activity {
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// Reset the "accounts changed" notification, now that we're here
Email.setNotifyUiAccountsChanged(false);
// Quickly check for bulk upgrades (from older app versions) and switch to the
// upgrade activity if necessary
if (UpgradeAccounts.doBulkUpgradeIfNecessary(this)) {

View File

@ -18,6 +18,7 @@ package com.android.email.activity.setup;
import com.android.email.Email;
import com.android.email.R;
import com.android.email.activity.Welcome;
import com.android.email.mail.MessagingException;
import com.android.email.mail.Sender;
import com.android.email.mail.Store;
@ -313,6 +314,14 @@ public class AccountSettings extends PreferenceActivity {
@Override
public void onResume() {
super.onResume();
// Exit immediately if the accounts list has changed (e.g. externally deleted)
if (Email.getNotifyUiAccountsChanged()) {
Welcome.actionStart(this);
finish();
return;
}
if (mAccountDirty) {
// if we are coming back from editing incoming or outgoing settings,
// we need to refresh them here so we don't accidentally overwrite the

View File

@ -1551,6 +1551,7 @@ public class SyncManager extends Service implements Runnable {
if (!blockExternalChanges && accountsDeleted) {
AccountBackupRestore.backupAccounts(context);
SecurityPolicy.getInstance(context).reducePolicies();
Email.setNotifyUiAccountsChanged(true);
}
}