Merge "Restrict voicemail access in Airplane mode."
diff --git a/res/values/strings.xml b/res/values/strings.xml
index e927ee9..fa67483 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1781,15 +1781,17 @@
     <!-- Button label to prompt the user to add another account (when there are already existing accounts on the device) [CHAR LIMIT=30] -->
     <string name="add_new_account">Add new account</string>
 
-    <!-- Dialog title which is shown when the user tries to make a phone call
-         to prohibited phone numbers [CHAR LIMIT=40] -->
-    <string name="dialog_phone_call_prohibited_title" msgid="4313552620858880999">Call not sent</string>
-
-    <!-- Dialog title which is shown when the user tries to check voicemail
-         while the system isn't ready for the access. [CHAR LIMIT=40] -->
-    <string name="dialog_voicemail_not_ready_title">Voicemail number unavailable</string>
+    <!-- Dialog message which is shown when the user tries to make a phone call
+         to prohibited phone numbers [CHAR LIMIT=NONE] -->
+    <string name="dialog_phone_call_prohibited_message" msgid="4313552620858880999">Call not sent</string>
 
     <!-- Dialog message which is shown when the user tries to check voicemail
          while the system isn't ready for the access. [CHAR LIMIT=NONE] -->
     <string name="dialog_voicemail_not_ready_message">To set up voicemail, go to Menu &gt; Settings.</string>
+
+    <!-- Dialog message which is shown when the user tries to check voicemail
+         while the system is in airplane mode. The user cannot access to
+         voicemail service in Airplane mode. [CHAR LIMI=NONE] -->
+    <string name="dialog_voicemail_airplane_mode_message">To call voicemail, first turn off Airplane mode.</string>
+
 </resources>
diff --git a/src/com/android/contacts/dialpad/DialpadFragment.java b/src/com/android/contacts/dialpad/DialpadFragment.java
index fb80120..0cefe2d 100644
--- a/src/com/android/contacts/dialpad/DialpadFragment.java
+++ b/src/com/android/contacts/dialpad/DialpadFragment.java
@@ -882,10 +882,21 @@
                     if (isVoicemailAvailable()) {
                         callVoicemail();
                     } else if (getActivity() != null) {
-                        DialogFragment dialogFragment = ErrorDialogFragment.newInstance(
-                                R.string.dialog_voicemail_not_ready_title,
-                                R.string.dialog_voicemail_not_ready_message);
-                        dialogFragment.show(getFragmentManager(), "voicemail_not_ready");
+                        // Voicemail is unavailable maybe because Airplane mode is turned on.
+                        // Check the current status and show the most appropriate error message.
+                        final boolean isAirplaneModeOn =
+                                Settings.System.getInt(getActivity().getContentResolver(),
+                                Settings.System.AIRPLANE_MODE_ON, 0) != 0;
+                        if (isAirplaneModeOn) {
+                            DialogFragment dialogFragment = ErrorDialogFragment.newInstance(
+                                    R.string.dialog_voicemail_airplane_mode_message);
+                            dialogFragment.show(getFragmentManager(),
+                                    "voicemail_request_during_airplane_mode");
+                        } else {
+                            DialogFragment dialogFragment = ErrorDialogFragment.newInstance(
+                                    R.string.dialog_voicemail_not_ready_message);
+                            dialogFragment.show(getFragmentManager(), "voicemail_not_ready");
+                        }
                     }
                     return true;
                 }
@@ -924,27 +935,20 @@
 
     public static class ErrorDialogFragment extends DialogFragment {
         private int mTitleResId;
-        private Integer mMessageResId;  // can be null
+        private int mMessageResId;
 
         private static final String ARG_TITLE_RES_ID = "argTitleResId";
         private static final String ARG_MESSAGE_RES_ID = "argMessageResId";
 
-        public static ErrorDialogFragment newInstance(int titleResId) {
-            return newInstanceInter(titleResId, null);
+        public static ErrorDialogFragment newInstance(int messageResId) {
+            return newInstance(0, messageResId);
         }
 
         public static ErrorDialogFragment newInstance(int titleResId, int messageResId) {
-            return newInstanceInter(titleResId, messageResId);
-        }
-
-        private static ErrorDialogFragment newInstanceInter(
-                int titleResId, Integer messageResId) {
             final ErrorDialogFragment fragment = new ErrorDialogFragment();
             final Bundle args = new Bundle();
             args.putInt(ARG_TITLE_RES_ID, titleResId);
-            if (messageResId != null) {
-                args.putInt(ARG_MESSAGE_RES_ID, messageResId);
-            }
+            args.putInt(ARG_MESSAGE_RES_ID, messageResId);
             fragment.setArguments(args);
             return fragment;
         }
@@ -953,25 +957,25 @@
         public void onCreate(Bundle savedInstanceState) {
             super.onCreate(savedInstanceState);
             mTitleResId = getArguments().getInt(ARG_TITLE_RES_ID);
-            if (getArguments().containsKey(ARG_MESSAGE_RES_ID)) {
-                mMessageResId = getArguments().getInt(ARG_MESSAGE_RES_ID);
-            }
+            mMessageResId = getArguments().getInt(ARG_MESSAGE_RES_ID);
         }
 
         @Override
         public Dialog onCreateDialog(Bundle savedInstanceState) {
             AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
-            builder.setTitle(mTitleResId)
-                    .setPositiveButton(android.R.string.ok,
-                            new DialogInterface.OnClickListener() {
-                                @Override
-                                public void onClick(DialogInterface dialog, int which) {
-                                    dismiss();
-                                }
-                            });
-            if (mMessageResId != null) {
+            if (mTitleResId != 0) {
+                builder.setTitle(mTitleResId);
+            }
+            if (mMessageResId != 0) {
                 builder.setMessage(mMessageResId);
             }
+            builder.setPositiveButton(android.R.string.ok,
+                    new DialogInterface.OnClickListener() {
+                            @Override
+                            public void onClick(DialogInterface dialog, int which) {
+                                dismiss();
+                            }
+                    });
             return builder.create();
         }
     }
@@ -1039,7 +1043,7 @@
                 Log.i(TAG, "The phone number is prohibited explicitly by a rule.");
                 if (getActivity() != null) {
                     DialogFragment dialogFragment = ErrorDialogFragment.newInstance(
-                                    R.string.dialog_phone_call_prohibited_title);
+                            R.string.dialog_phone_call_prohibited_message);
                     dialogFragment.show(getFragmentManager(), "phone_prohibited_dialog");
                 }