Add system shortcuts when long pressing recent icon

We add a floating view for the menu that aligns with the task icon.

If available, the following shortcuts are present:
- Widgets
- App info
- Install (for instant apps)

It is designed to be straightforward to add to this list.

Bug: 70294936

Change-Id: I56c1098353d09fc564e0e92e59e4fcf692e486ba
diff --git a/src/com/android/launcher3/AbstractFloatingView.java b/src/com/android/launcher3/AbstractFloatingView.java
index da464c0..9a6be0b 100644
--- a/src/com/android/launcher3/AbstractFloatingView.java
+++ b/src/com/android/launcher3/AbstractFloatingView.java
@@ -43,7 +43,8 @@
             TYPE_WIDGET_RESIZE_FRAME,
             TYPE_WIDGETS_FULL_SHEET,
             TYPE_QUICKSTEP_PREVIEW,
-            TYPE_ON_BOARD_POPUP
+            TYPE_ON_BOARD_POPUP,
+            TYPE_TASK_MENU
     })
     @Retention(RetentionPolicy.SOURCE)
     public @interface FloatingViewType {}
@@ -54,10 +55,11 @@
     public static final int TYPE_WIDGETS_FULL_SHEET = 1 << 4;
     public static final int TYPE_QUICKSTEP_PREVIEW = 1 << 5;
     public static final int TYPE_ON_BOARD_POPUP = 1 << 6;
+    public static final int TYPE_TASK_MENU = 1 << 7;
 
     public static final int TYPE_ALL = TYPE_FOLDER | TYPE_ACTION_POPUP
             | TYPE_WIDGETS_BOTTOM_SHEET | TYPE_WIDGET_RESIZE_FRAME | TYPE_WIDGETS_FULL_SHEET
-            | TYPE_QUICKSTEP_PREVIEW | TYPE_ON_BOARD_POPUP;
+            | TYPE_QUICKSTEP_PREVIEW | TYPE_ON_BOARD_POPUP | TYPE_TASK_MENU;
 
     // Type of popups which should be kept open during launcher rebind
     public static final int TYPE_REBIND_SAFE = TYPE_WIDGETS_FULL_SHEET
diff --git a/src/com/android/launcher3/popup/SystemShortcut.java b/src/com/android/launcher3/popup/SystemShortcut.java
index c398aaa..42aa12b 100644
--- a/src/com/android/launcher3/popup/SystemShortcut.java
+++ b/src/com/android/launcher3/popup/SystemShortcut.java
@@ -1,5 +1,8 @@
 package com.android.launcher3.popup;
 
+import static com.android.launcher3.userevent.nano.LauncherLogProto.Action;
+import static com.android.launcher3.userevent.nano.LauncherLogProto.ControlType;
+
 import android.content.Intent;
 import android.graphics.Rect;
 import android.os.Bundle;
@@ -19,9 +22,6 @@
 
 import java.util.List;
 
-import static com.android.launcher3.userevent.nano.LauncherLogProto.Action;
-import static com.android.launcher3.userevent.nano.LauncherLogProto.ControlType;
-
 /**
  * Represents a system shortcut for a given app. The shortcut should have a static label and
  * icon, and an onClickListener that depends on the item that the shortcut services.
@@ -110,14 +110,15 @@
             if (!enabled) {
                 return null;
             }
-            return new View.OnClickListener() {
-                @Override
-                public void onClick(View view) {
-                    Intent intent = PackageManagerHelper.getMarketIntent(itemInfo
-                            .getTargetComponent().getPackageName());
-                    launcher.startActivitySafely(view, intent, itemInfo);
-                    AbstractFloatingView.closeAllOpenViews(launcher);
-                }
+            return createOnClickListener(launcher, itemInfo);
+        }
+
+        public View.OnClickListener createOnClickListener(Launcher launcher, ItemInfo itemInfo) {
+            return view -> {
+                Intent intent = PackageManagerHelper.getMarketIntent(itemInfo
+                        .getTargetComponent().getPackageName());
+                launcher.startActivitySafely(view, intent, itemInfo);
+                AbstractFloatingView.closeAllOpenViews(launcher);
             };
         }
     }
diff --git a/src/com/android/launcher3/util/InstantAppResolver.java b/src/com/android/launcher3/util/InstantAppResolver.java
index 99ce7ca..601a5ab 100644
--- a/src/com/android/launcher3/util/InstantAppResolver.java
+++ b/src/com/android/launcher3/util/InstantAppResolver.java
@@ -18,8 +18,11 @@
 
 import android.content.Context;
 import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.util.Log;
 
 import com.android.launcher3.AppInfo;
+import com.android.launcher3.Launcher;
 import com.android.launcher3.R;
 import com.android.launcher3.Utilities;
 
@@ -44,6 +47,17 @@
         return false;
     }
 
+    public boolean isInstantApp(Launcher launcher, String packageName) {
+        PackageManager packageManager = launcher.getPackageManager();
+        try {
+            return isInstantApp(packageManager.getPackageInfo(packageName, 0).applicationInfo);
+        } catch (PackageManager.NameNotFoundException e) {
+            Log.e("InstantAppResolver", "Failed to determine whether package is instant app "
+                    + packageName, e);
+        }
+        return false;
+    }
+
     public List<ApplicationInfo> getInstantApps() {
         return Collections.emptyList();
     }