Provide error message when no available account to place a call.

When there is no available phone account to place a call, ensure call
generates an appropriate error message.

Test: Manual
Bug: 120441065
Change-Id: Id46ef60d808ebab03fcf01c27ff871e518a58f99
diff --git a/res/values/strings.xml b/res/values/strings.xml
index eff68a0..da61da8 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -249,6 +249,12 @@
     <!-- The "decline" button for an incoming call. [CHAR LIMIT=60] -->
     <string name="decline_incoming_call">Decline</string>
 
+    <!-- Error message shown to the user when an outgoing call cannot be placed because there no
+         calling service is present on the device which supports this call type.
+         This is typically encountered when the user tries to dial a SIP/VOIP call, but there are
+         no calling services present which support SIP calling. [CHAR LIMIT=none] -->
+    <string name="cant_call_due_to_no_supported_service">Call cannot be placed because there are no calling accounts which support calls of this type.</string>
+
     <!-- Error message shown to the user when an outgoing call cannot be placed due to an ongoing
          phone call in a third-party app.  For example:
          Call cannot be placed due to your Duo call. [CHAR LIMIT=none] -->
diff --git a/src/com/android/server/telecom/CallsManager.java b/src/com/android/server/telecom/CallsManager.java
index 7093c40..ff25484 100644
--- a/src/com/android/server/telecom/CallsManager.java
+++ b/src/com/android/server/telecom/CallsManager.java
@@ -1417,6 +1417,7 @@
                             if (accountSuggestions == null || accountSuggestions.isEmpty()) {
                                 Log.i(CallsManager.this, "Aborting call since there are no"
                                         + " available accounts.");
+                                showErrorMessage(R.string.cant_call_due_to_no_supported_service);
                                 return CompletableFuture.completedFuture(null);
                             }
                             boolean needsAccountSelection = accountSuggestions.size() > 1
@@ -4469,4 +4470,16 @@
         return mCalls.stream().filter(c -> c.isEmergencyCall()
                 || c.isNetworkIdentifiedEmergencyCall()).count() > 0;
     }
+
+    /**
+     * Trigger display of an error message to the user; we do this outside of dialer for calls which
+     * fail to be created and added to Dialer.
+     * @param messageId The string resource id.
+     */
+    private void showErrorMessage(int messageId) {
+        final Intent errorIntent = new Intent(mContext, ErrorDialogActivity.class);
+        errorIntent.putExtra(ErrorDialogActivity.ERROR_MESSAGE_ID_EXTRA, messageId);
+        errorIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        mContext.startActivityAsUser(errorIntent, UserHandle.CURRENT);
+    }
 }