Support the managed profile deep links for large screen

Homepage is not allowed to be started as a non-primary user.

In the managed profile deep link case, we create a bridge to start the
homepage as the primary user, and then start the target page as the
given managed user.

Bug: 222447112
Test: manual, robotest
Change-Id: I07dbec3b7eaff983f9860480a0a2f7b0e6f1fb43
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index 4e2088e..f5fb26c 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -34,6 +34,7 @@
 import android.content.pm.ActivityInfo;
 import android.content.pm.PackageManager;
 import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.pm.UserInfo;
 import android.content.res.Resources;
 import android.content.res.Resources.Theme;
 import android.graphics.drawable.Icon;
@@ -152,6 +153,8 @@
      */
     public static final String EXTRA_IS_FROM_SLICE = "is_from_slice";
 
+    public static final String EXTRA_USER_HANDLE = "user_handle";
+
     /**
      * Personal or Work profile tab of {@link ProfileSelectFragment}
      * <p>0: Personal tab.
@@ -427,7 +430,14 @@
         }
 
         try {
-            startActivity(trampolineIntent);
+            final UserManager um = getSystemService(UserManager.class);
+            final UserInfo userInfo = um.getUserInfo(getUser().getIdentifier());
+            if (userInfo.isManagedProfile()) {
+                trampolineIntent.putExtra(EXTRA_USER_HANDLE, getUser());
+                startActivityAsUser(trampolineIntent, um.getPrimaryUser().getUserHandle());
+            } else {
+                startActivity(trampolineIntent);
+            }
         } catch (ActivityNotFoundException e) {
             Log.e(LOG_TAG, "Deep link homepage is not available to show 2-pane UI");
             return false;