diff --git a/core/java/android/app/ActivityView.java b/core/java/android/app/ActivityView.java index 91f8a3c7be85a..aaab6b4099e54 100644 --- a/core/java/android/app/ActivityView.java +++ b/core/java/android/app/ActivityView.java @@ -22,11 +22,14 @@ import android.annotation.TestApi; import android.content.ComponentName; import android.content.Context; import android.content.Intent; +import android.content.pm.LauncherApps; +import android.content.pm.ShortcutInfo; import android.graphics.Insets; import android.graphics.Matrix; import android.graphics.Point; import android.graphics.Rect; import android.graphics.Region; +import android.os.Bundle; import android.os.UserHandle; import android.util.AttributeSet; import android.util.Log; @@ -208,6 +211,32 @@ public class ActivityView extends ViewGroup implements TaskEmbedder.Host { return mSurfaceView.getClipBounds(outRect); } + /** + * Launch an activity represented by {@link ShortcutInfo} into this container. + *

The owner of this container must be allowed to access the shortcut information, + * as defined in {@link LauncherApps#hasShortcutHostPermission()} to use this method. + *

Activity resolved by the provided {@link ShortcutInfo} must have + * {@link android.R.attr#resizeableActivity} attribute set to {@code true} in order to be + * launched here. Also, if activity is not owned by the owner of this container, it must allow + * embedding and the caller must have permission to embed. + *

Note: This class must finish initializing and + * {@link StateCallback#onActivityViewReady(ActivityView)} callback must be triggered before + * this method can be called. + * + * @param shortcut the shortcut used to launch the activity. + * @param options for the activity. + * @param sourceBounds the rect containing the source bounds of the clicked icon to open + * this shortcut. + * @see StateCallback + * @see LauncherApps#startShortcut(ShortcutInfo, Rect, Bundle) + * + * @hide + */ + public void startShortcutActivity(@NonNull ShortcutInfo shortcut, + @NonNull ActivityOptions options, @Nullable Rect sourceBounds) { + mTaskEmbedder.startShortcutActivity(shortcut, options, sourceBounds); + } + /** * Launch a new activity into this container. *

Activity resolved by the provided {@link Intent} must have diff --git a/core/java/android/app/TaskEmbedder.java b/core/java/android/app/TaskEmbedder.java index a8dc7bc13821c..79d88fd897166 100644 --- a/core/java/android/app/TaskEmbedder.java +++ b/core/java/android/app/TaskEmbedder.java @@ -25,9 +25,12 @@ import android.annotation.Nullable; import android.content.ComponentName; import android.content.Context; import android.content.Intent; +import android.content.pm.LauncherApps; +import android.content.pm.ShortcutInfo; import android.graphics.Insets; import android.graphics.Matrix; import android.graphics.Point; +import android.graphics.Rect; import android.graphics.Region; import android.hardware.display.DisplayManager; import android.hardware.display.VirtualDisplay; @@ -345,6 +348,26 @@ public class TaskEmbedder { } } + /** + * Launch an activity represented by {@link ShortcutInfo} into this container. + *

The owner of this container must be allowed to access the shortcut information, + * as defined in {@link LauncherApps#hasShortcutHostPermission()} to use this method. + * + * @param shortcut the shortcut used to launch the activity. + * @param options options for the activity. + * @param sourceBounds the rect containing the source bounds of the clicked icon to open + * this shortcut. + * + * @see #startActivity(Intent) + */ + public void startShortcutActivity(@NonNull ShortcutInfo shortcut, + @NonNull ActivityOptions options, @Nullable Rect sourceBounds) { + LauncherApps service = + (LauncherApps) mContext.getSystemService(Context.LAUNCHER_APPS_SERVICE); + options.setLaunchDisplayId(mVirtualDisplay.getDisplay().getDisplayId()); + service.startShortcut(shortcut, sourceBounds, options.toBundle()); + } + /** * Check if container is ready to launch and create {@link ActivityOptions} to target the * virtual display.