Merge "Remove vvm dependence on AccountManager, save values in shared prefs." into mnc-dev
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 688beb1..9b3dee9 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -897,6 +897,9 @@
     <string name="pin2_attempts">\nYou have <xliff:g id="number">%d</xliff:g> remaining attempts.</string>
     <!-- SIM PIN screen: status message displayed in a popup (toast) -->
     <string name="pin2_unblocked">PIN2 no longer blocked</string>
+    <!-- SIM PIN screen: error message shown in dialog when there is a network or sim error.
+         [CHAR LIMIT=NONE] -->
+    <string name="pin2_error_exception">Network or SIM card error</string>
 
     <!-- SIM PIN screen: button label -->
     <string name="doneButton">Done</string>
diff --git a/src/com/android/phone/settings/fdn/FdnSetting.java b/src/com/android/phone/settings/fdn/FdnSetting.java
index b825f7a..134d8e6 100644
--- a/src/com/android/phone/settings/fdn/FdnSetting.java
+++ b/src/com/android/phone/settings/fdn/FdnSetting.java
@@ -247,25 +247,29 @@
                 // a toast, or just update the UI.
                 case EVENT_PIN2_ENTRY_COMPLETE: {
                         AsyncResult ar = (AsyncResult) msg.obj;
-                        if (ar.exception != null && ar.exception instanceof CommandException) {
-                            int attemptsRemaining = msg.arg1;
-                            // see if PUK2 is requested and alert the user accordingly.
-                            CommandException.Error e =
-                                    ((CommandException) ar.exception).getCommandError();
-                            switch (e) {
-                                case SIM_PUK2:
-                                    // make sure we set the PUK2 state so that we can skip
-                                    // some redundant behaviour.
-                                    displayMessage(R.string.fdn_enable_puk2_requested,
-                                            attemptsRemaining);
-                                    resetPinChangeStateForPUK2();
-                                    break;
-                                case PASSWORD_INCORRECT:
-                                    displayMessage(R.string.pin2_invalid, attemptsRemaining);
-                                    break;
-                                default:
-                                    displayMessage(R.string.fdn_failed, attemptsRemaining);
-                                    break;
+                        if (ar.exception != null) {
+                            if (ar.exception instanceof CommandException) {
+                                int attemptsRemaining = msg.arg1;
+                                // see if PUK2 is requested and alert the user accordingly.
+                                CommandException.Error e =
+                                        ((CommandException) ar.exception).getCommandError();
+                                switch (e) {
+                                    case SIM_PUK2:
+                                        // make sure we set the PUK2 state so that we can skip
+                                        // some redundant behaviour.
+                                        displayMessage(R.string.fdn_enable_puk2_requested,
+                                                attemptsRemaining);
+                                        resetPinChangeStateForPUK2();
+                                        break;
+                                    case PASSWORD_INCORRECT:
+                                        displayMessage(R.string.pin2_invalid, attemptsRemaining);
+                                        break;
+                                    default:
+                                        displayMessage(R.string.fdn_failed, attemptsRemaining);
+                                        break;
+                                }
+                            } else {
+                                displayMessage(R.string.pin2_error_exception);
                             }
                         }
                         updateEnableFDN();
@@ -280,32 +284,36 @@
                             log("Handle EVENT_PIN2_CHANGE_COMPLETE");
                         AsyncResult ar = (AsyncResult) msg.obj;
                         if (ar.exception != null) {
-                            int attemptsRemaining = msg.arg1;
-                            log("Handle EVENT_PIN2_CHANGE_COMPLETE attemptsRemaining="
-                                    + attemptsRemaining);
-                            CommandException ce = (CommandException) ar.exception;
-                            if (ce.getCommandError() == CommandException.Error.SIM_PUK2) {
-                                // throw an alert dialog on the screen, displaying the
-                                // request for a PUK2.  set the cancel listener to
-                                // FdnSetting.onCancel().
-                                AlertDialog a = new AlertDialog.Builder(FdnSetting.this)
-                                    .setMessage(R.string.puk2_requested)
-                                    .setCancelable(true)
-                                    .setOnCancelListener(FdnSetting.this)
-                                    .create();
-                                a.getWindow().addFlags(
-                                        WindowManager.LayoutParams.FLAG_DIM_BEHIND);
-                                a.show();
-                            } else {
-                                // set the correct error message depending upon the state.
-                                // Reset the state depending upon or knowledge of the PUK state.
-                                if (!mIsPuk2Locked) {
-                                    displayMessage(R.string.badPin2, attemptsRemaining);
-                                    resetPinChangeState();
+                            if (ar.exception instanceof CommandException) {
+                                int attemptsRemaining = msg.arg1;
+                                log("Handle EVENT_PIN2_CHANGE_COMPLETE attemptsRemaining="
+                                        + attemptsRemaining);
+                                CommandException ce = (CommandException) ar.exception;
+                                if (ce.getCommandError() == CommandException.Error.SIM_PUK2) {
+                                    // throw an alert dialog on the screen, displaying the
+                                    // request for a PUK2.  set the cancel listener to
+                                    // FdnSetting.onCancel().
+                                    AlertDialog a = new AlertDialog.Builder(FdnSetting.this)
+                                        .setMessage(R.string.puk2_requested)
+                                        .setCancelable(true)
+                                        .setOnCancelListener(FdnSetting.this)
+                                        .create();
+                                    a.getWindow().addFlags(
+                                            WindowManager.LayoutParams.FLAG_DIM_BEHIND);
+                                    a.show();
                                 } else {
-                                    displayMessage(R.string.badPuk2, attemptsRemaining);
-                                    resetPinChangeStateForPUK2();
+                                    // set the correct error message depending upon the state.
+                                    // Reset the state depending upon or knowledge of the PUK state.
+                                    if (!mIsPuk2Locked) {
+                                        displayMessage(R.string.badPin2, attemptsRemaining);
+                                        resetPinChangeState();
+                                    } else {
+                                        displayMessage(R.string.badPuk2, attemptsRemaining);
+                                        resetPinChangeStateForPUK2();
+                                    }
                                 }
+                            } else {
+                                displayMessage(R.string.pin2_error_exception);
                             }
                         } else {
                             if (mPinChangeState == PIN_CHANGE_PUK) {