fix launching with account intent every which way

Don't require the 'color' attribute (missing => default/0).
Don't NPE on restoring invalid account (and log this).
Don't continue intent processing if account is invalid.

also remove some unnecessary boxing/unboxing.

Bug: 6521470
Change-Id: Ia662b3462cce364921a4db0158babfe17bfda553
diff --git a/src/com/android/mail/providers/Account.java b/src/com/android/mail/providers/Account.java
index 3261022..b0cb6ce 100644
--- a/src/com/android/mail/providers/Account.java
+++ b/src/com/android/mail/providers/Account.java
@@ -225,9 +225,9 @@
     private Account(String name, String type, String jsonAccount) throws JSONException {
         super(name, type);
         final JSONObject json = new JSONObject(jsonAccount);
-        providerVersion = Integer.valueOf(json.getInt(UIProvider.AccountColumns.PROVIDER_VERSION));
+        providerVersion = json.getInt(UIProvider.AccountColumns.PROVIDER_VERSION);
         uri = Uri.parse(json.optString(UIProvider.AccountColumns.URI));
-        capabilities = Integer.valueOf(json.getInt(UIProvider.AccountColumns.CAPABILITIES));
+        capabilities = json.getInt(UIProvider.AccountColumns.CAPABILITIES);
         folderListUri = getValidUri(json.optString(UIProvider.AccountColumns.FOLDER_LIST_URI));
         searchUri = getValidUri(json.optString(UIProvider.AccountColumns.SEARCH_URI));
         accountFromAddresses = UIProvider.AccountColumns.ACCOUNT_FROM_ADDRESSES;
@@ -241,12 +241,12 @@
         helpIntentUri = getValidUri(json.optString(UIProvider.AccountColumns.HELP_INTENT_URI));
         sendFeedbackIntentUri =
                 getValidUri(json.optString(UIProvider.AccountColumns.SEND_FEEDBACK_INTENT_URI));
-        syncStatus = Integer.valueOf(json.optInt(UIProvider.AccountColumns.SYNC_STATUS));
+        syncStatus = json.optInt(UIProvider.AccountColumns.SYNC_STATUS);
         composeIntentUri = getValidUri(json.optString(UIProvider.AccountColumns.COMPOSE_URI));
         mimeType = json.optString(UIProvider.AccountColumns.MIME_TYPE);
         recentFolderListUri = getValidUri(
                 json.optString(UIProvider.AccountColumns.RECENT_FOLDER_LIST_URI));
-        color = Integer.valueOf(json.getInt(UIProvider.AccountColumns.COLOR));
+        color = json.optInt(UIProvider.AccountColumns.COLOR, 0);
 
         final Settings jsonSettings = Settings.newInstance(json.optJSONObject(SETTINGS_KEY));
         if (jsonSettings != null) {
diff --git a/src/com/android/mail/ui/AbstractActivityController.java b/src/com/android/mail/ui/AbstractActivityController.java
index 5b50c8f..5e9fac1 100644
--- a/src/com/android/mail/ui/AbstractActivityController.java
+++ b/src/com/android/mail/ui/AbstractActivityController.java
@@ -872,6 +872,12 @@
     }
 
     private void setAccount(Account account) {
+        if (account == null) {
+            LogUtils.w(LOG_TAG, new Error(),
+                    "AAC ignoring null (presumably invalid) account restoration");
+            return;
+        }
+
         mAccount = account;
         LogUtils.d(LOG_TAG, "AbstractActivityController.setAccount(): mAccount = %s", mAccount.uri);
         dispatchSettingsChange(mAccount.settings);
@@ -919,9 +925,10 @@
                 setAccount(Account.newinstance(intent
                         .getStringExtra(Utils.EXTRA_ACCOUNT_STRING)));
             }
-            if (mAccount != null) {
-                mActivity.invalidateOptionsMenu();
+            if (mAccount == null) {
+                return;
             }
+            mActivity.invalidateOptionsMenu();
 
             Folder folder = null;
             if (intent.hasExtra(Utils.EXTRA_FOLDER)) {