Merge "Show mini-resolver for messages" into udc-dev
diff --git a/src/com/android/phone/ErrorDialogActivity.java b/src/com/android/phone/ErrorDialogActivity.java
index ab096ff..b85a0f3 100644
--- a/src/com/android/phone/ErrorDialogActivity.java
+++ b/src/com/android/phone/ErrorDialogActivity.java
@@ -69,12 +69,10 @@
                     .getSystemService(RoleManager.class)
                     .getSmsRoleHolder(managedProfileUserId);
 
-        Intent smsIntent = new Intent(Intent.ACTION_MAIN)
+        Intent smsIntent = new Intent(Intent.ACTION_SENDTO)
                 .addCategory(Intent.CATEGORY_DEFAULT)
-                .addCategory(Intent.CATEGORY_LAUNCHER)
-                .addCategory(Intent.CATEGORY_APP_MESSAGING)
                 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
-                .setPackage(defaultMessagesAppPackage);
+                .setData(Uri.parse("smsto:"));
         Intent marketIntent =
                 new Intent(
                         Intent.ACTION_VIEW,
@@ -87,7 +85,7 @@
         // Failing that, we simply omit the positive action button as the user has no mechanism
         // to send the message.
         if (defaultMessagesAppPackage != null
-                && canStartActivityAsUser(
+                || canStartActivityAsUser(
                 smsIntent,
                 managedProfileUserId)) {
             positiveButtonText = R.string.send_from_work_profile_action_str;
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index 6e6f799..0107b1c 100644
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -39,6 +39,7 @@
 import android.app.role.RoleManager;
 import android.compat.annotation.ChangeId;
 import android.compat.annotation.EnabledSince;
+import android.content.ActivityNotFoundException;
 import android.content.ComponentName;
 import android.content.ContentResolver;
 import android.content.Context;
@@ -10227,11 +10228,21 @@
     @Override
     public void showSwitchToManagedProfileDialog() {
         enforceModifyPermission();
-
-        Intent intent = new Intent();
-        intent.setClass(mApp, ErrorDialogActivity.class);
-        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-        mApp.startActivity(intent);
+        try {
+            // Note: This intent is constructed to ensure that the IntentForwarderActivity is
+            // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
+            // for work telephony.
+            Intent intent = new Intent(Intent.ACTION_SENDTO);
+            intent.setData(Uri.parse("smsto:"));
+            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+            mApp.startActivity(intent);
+        } catch (ActivityNotFoundException e) {
+            Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
+            Intent intent = new Intent();
+            intent.setClass(mApp, ErrorDialogActivity.class);
+            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+            mApp.startActivity(intent);
+        }
     }
 
     @Override