Separate set-voicemail-only scenarios.

Simplify the logic for voicemail/call forwarding in call settings
and make it easier to understand. Much of the complexity seems to
be because of merged code paths for setting voicemail and call
forwarding, so make this more explicit by directly setting the
voicemail number if we don't need to change call forwarding. That
is, the code is slightly more linear now.

+ If the new forwarding settings are NO_FORWARDING, skip reading
the forwarding settings and just set the voicemail number. Stage2
used to only set the voicemail number in this case, so now we skip
reading and just save the number.

The only tangible difference in skipping this seems to be that we
we don't read/save the default voicemail provider's settings. Based
off the documentation, this is so if we know if we need to update
the settings in Stage2. But, we never execute the code path which
checks for updates anyways if the new settings are NO_FORWARDING.

+ If reading the call forwarding fails, but the user wants to
proceed with setting voicemail anyways, directly call the method
which sets voicemail. A reading of the call forwarding settings
already failed anyways.

Bug: 17019623
Change-Id: I747b65cae630990255f6283795b3f431ef39cd7b
diff --git a/src/com/android/phone/CallFeaturesSetting.java b/src/com/android/phone/CallFeaturesSetting.java
index 6d3b252..d6bb030 100644
--- a/src/com/android/phone/CallFeaturesSetting.java
+++ b/src/com/android/phone/CallFeaturesSetting.java
@@ -683,7 +683,10 @@
         mVMOrFwdSetError = 0;
 
         // Don't read call forwarding settings if CDMA. Call forwarding is not supported by CDMA.
-        if (!key.equals(mPreviousVMProviderKey) && !isCdma) {
+        if (isCdma || mNewFwdSettings == VoicemailProviderSettings.NO_FORWARDING) {
+            if (DBG) log("Not touching fwd #");
+            setVoicemailNumberWithCarrier();
+        } else {
             mReadingSettingsForDefaultProvider =
                     mPreviousVMProviderKey.equals(VoicemailProviderListPreference.DEFAULT_KEY);
             if (DBG) log("Reading current forwarding settings");
@@ -695,8 +698,6 @@
                         mGetOptionComplete.obtainMessage(EVENT_FORWARDING_GET_COMPLETED, i, 0));
             }
             showDialogIfForeground(VoicemailDialogUtil.VM_FWD_READING_DIALOG);
-        } else {
-            saveVoiceMailAndForwardingNumberStage2();
         }
 
         // Refresh the MWI indicator if it is already showing.
@@ -780,33 +781,30 @@
     private void saveVoiceMailAndForwardingNumberStage2() {
         mForwardingChangeResults = null;
         mVoicemailChangeResult = null;
-        if (mNewFwdSettings != VoicemailProviderSettings.NO_FORWARDING) {
-            resetForwardingChangeState();
-            for (int i = 0; i < mNewFwdSettings.length; i++) {
-                CallForwardInfo fi = mNewFwdSettings[i];
-                CallForwardInfo fiForReason =
-                        CallForwardInfoUtil.infoForReason(mForwardingReadResults, fi.reason);
-                final boolean doUpdate = CallForwardInfoUtil.isUpdateRequired(fiForReason, fi);
 
-                if (doUpdate) {
-                    if (DBG) log("Setting fwd #: " + i + ": " + fi.toString());
-                    mExpectedChangeResultReasons.add(i);
+        resetForwardingChangeState();
+        for (int i = 0; i < mNewFwdSettings.length; i++) {
+            CallForwardInfo fi = mNewFwdSettings[i];
+            CallForwardInfo fiForReason =
+                    CallForwardInfoUtil.infoForReason(mForwardingReadResults, fi.reason);
+            final boolean doUpdate = CallForwardInfoUtil.isUpdateRequired(fiForReason, fi);
 
-                    CallForwardInfoUtil.setCallForwardingOption(mPhone, fi,
-                            mSetOptionComplete.obtainMessage(
-                                    EVENT_FORWARDING_CHANGED, fi.reason, 0));
-                }
+            if (doUpdate) {
+                if (DBG) log("Setting fwd #: " + i + ": " + fi.toString());
+                mExpectedChangeResultReasons.add(i);
+
+                CallForwardInfoUtil.setCallForwardingOption(mPhone, fi,
+                        mSetOptionComplete.obtainMessage(
+                                EVENT_FORWARDING_CHANGED, fi.reason, 0));
             }
-            showDialogIfForeground(VoicemailDialogUtil.VM_FWD_SAVING_DIALOG);
-        } else {
-            if (DBG) log("Not touching fwd #");
-            setVMNumberWithCarrier();
         }
+        showDialogIfForeground(VoicemailDialogUtil.VM_FWD_SAVING_DIALOG);
     }
 
-    private void setVMNumberWithCarrier() {
+    private void setVoicemailNumberWithCarrier() {
         if (DBG) log("save voicemail #: " + mNewVMNumber);
 
+        mVoicemailChangeResult = null;
         mPhone.setVoiceMailNumber(
                 mPhone.getVoiceMailAlphaTag().toString(),
                 mNewVMNumber,
@@ -836,7 +834,7 @@
                     if (isForwardingCompleted()) {
                         if (isFwdChangeSuccess()) {
                             if (DBG) log("Overall fwd changes completed ok, starting vm change");
-                            setVMNumberWithCarrier();
+                            setVoicemailNumberWithCarrier();
                         } else {
                             Log.w(LOG_TAG, "Overall fwd changes completed in failure. " +
                                     "Check if we need to try rollback for some settings.");
@@ -1054,7 +1052,7 @@
                 if (mCurrentDialogId == VoicemailDialogUtil.FWD_GET_RESPONSE_ERROR_DIALOG) {
                     // We failed to get current forwarding settings but the user
                     // wishes to continue changing settings to the new vm provider
-                    saveVoiceMailAndForwardingNumberStage2();
+                    setVoicemailNumberWithCarrier();
                 } else {
                     finish();
                 }