Disallow making a call to emergency numbers

Show an error toast instead since ACTION_CALL intent cannot be used to
call emergency numbers.

Test: Make a call to an emergency number.

Signed-off-by: Taesu Lee <taesu82.lee@samsung.com>
Change-Id: Ia42c588848b643def068dec1d73e2e917a4b8214
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 70e567f..e5c442d 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -979,4 +979,7 @@
     <string name="selected_sim_content_message"><xliff:g id="selected_sim">%s</xliff:g> selected</string>
 
     <string name="work_directory_display_name">Work Profile contacts</string>
+
+    <!-- When making a call to emergency numbers, show this toast -->
+    <string name="disallow_emergency_call">Can\'t make a voice call to emergency services here.</string>
 </resources>
diff --git a/src/com/android/messaging/ui/conversation/ConversationFragment.java b/src/com/android/messaging/ui/conversation/ConversationFragment.java
index 5c97c1c..6eb7089 100644
--- a/src/com/android/messaging/ui/conversation/ConversationFragment.java
+++ b/src/com/android/messaging/ui/conversation/ConversationFragment.java
@@ -51,6 +51,7 @@
 import androidx.recyclerview.widget.LinearLayoutManager;
 import androidx.recyclerview.widget.RecyclerView;
 import androidx.recyclerview.widget.RecyclerView.ViewHolder;
+import android.telephony.PhoneNumberUtils;
 import android.text.TextUtils;
 import android.view.ActionMode;
 import android.view.Display;
@@ -774,20 +775,27 @@
             case R.id.action_call:
                 final String phoneNumber = mBinding.getData().getParticipantPhoneNumber();
                 Assert.notNull(phoneNumber);
-                final View targetView = getActivity().findViewById(R.id.action_call);
-                Point centerPoint;
-                if (targetView != null) {
-                    final int screenLocation[] = new int[2];
-                    targetView.getLocationOnScreen(screenLocation);
-                    final int centerX = screenLocation[0] + targetView.getWidth() / 2;
-                    final int centerY = screenLocation[1] + targetView.getHeight() / 2;
-                    centerPoint = new Point(centerX, centerY);
+                // Can't make a call to emergency numbers using ACTION_CALL.
+                if (PhoneNumberUtils.isEmergencyNumber(phoneNumber)) {
+                    UiUtils.showToast(R.string.disallow_emergency_call);
                 } else {
-                    // In the overflow menu, just use the center of the screen.
-                    final Display display = getActivity().getWindowManager().getDefaultDisplay();
-                    centerPoint = new Point(display.getWidth() / 2, display.getHeight() / 2);
+                    final View targetView = getActivity().findViewById(R.id.action_call);
+                    Point centerPoint;
+                    if (targetView != null) {
+                        final int screenLocation[] = new int[2];
+                        targetView.getLocationOnScreen(screenLocation);
+                        final int centerX = screenLocation[0] + targetView.getWidth() / 2;
+                        final int centerY = screenLocation[1] + targetView.getHeight() / 2;
+                        centerPoint = new Point(centerX, centerY);
+                    } else {
+                        // In the overflow menu, just use the center of the screen.
+                        final Display display =
+                                getActivity().getWindowManager().getDefaultDisplay();
+                        centerPoint = new Point(display.getWidth() / 2, display.getHeight() / 2);
+                    }
+                    UIIntents.get()
+                            .launchPhoneCallActivity(getActivity(), phoneNumber, centerPoint);
                 }
-                UIIntents.get().launchPhoneCallActivity(getActivity(), phoneNumber, centerPoint);
                 return true;
 
             case R.id.action_archive: