Perform the correct actions when account is set.

Fix b/6877387 and b/6995218

The two methods switchAccount and setAccount need to be
resolved. Filed b/7019552 to track this issue.

Change-Id: I447de4775567c4245f709c5192199d24fed6fac9
diff --git a/src/com/android/mail/ui/AbstractActivityController.java b/src/com/android/mail/ui/AbstractActivityController.java
index 04c7649..d8d26d6 100644
--- a/src/com/android/mail/ui/AbstractActivityController.java
+++ b/src/com/android/mail/ui/AbstractActivityController.java
@@ -1118,6 +1118,12 @@
         }
     }
 
+    /**
+     * Set the account, and carry out all the account-related changes that rely on this.
+     * @param account
+     */
+    // TODO(viki): Two different methods do the same thing. Resolve
+    // {@link #setAccount(Account)} and {@link #switchAccount(Account, boolean)}
     private void setAccount(Account account) {
         if (account == null) {
             LogUtils.w(LOG_TAG, new Error(),
@@ -1126,6 +1132,14 @@
         }
         LogUtils.d(LOG_TAG, "AbstractActivityController.setAccount(): account = %s", account.uri);
         mAccount = account;
+        // Only change AAC state here. Do *not* modify any other object's state. The object
+        // should listen on account changes.
+        restartOptionalLoader(LOADER_RECENT_FOLDERS);
+        mActivity.invalidateOptionsMenu();
+        disableNotificationsOnAccountChange(mAccount);
+        restartOptionalLoader(LOADER_ACCOUNT_UPDATE_CURSOR);
+        MailAppProvider.getInstance().setLastViewedAccount(mAccount.uri.toString());
+
         if (account.settings == null) {
             LogUtils.w(LOG_TAG, new Error(), "AAC ignoring account with null settings.");
             return;