Install long-click action for apps that are not installed.

Bug: 65059282
Change-Id: Ifec3ac15c9cf52c456e695846eb91024b07fe333
diff --git a/res/drawable/ic_install_no_shadow.xml b/res/drawable/ic_install_no_shadow.xml
new file mode 100644
index 0000000..ffce22a
--- /dev/null
+++ b/res/drawable/ic_install_no_shadow.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2017 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+        http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:width="24dp"
+    android:height="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24">
+
+    <path
+        android:fillColor="?android:attr/textColorPrimary"
+        android:pathData="M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z" />
+    <path
+        android:pathData="M0 0h24v24H0z" />
+</vector>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 1197b1c..e9b00f6 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -90,6 +90,8 @@
     <string name="uninstall_drop_target_label">Uninstall</string>
     <!-- Label for app info drop target. [CHAR_LIMIT=20] -->
     <string name="app_info_drop_target_label">App info</string>
+    <!-- Label for install drop target. [CHAR_LIMIT=20] -->
+    <string name="install_drop_target_label">Install</string>
 
     <!-- Permissions: -->
     <skip />
diff --git a/src/com/android/launcher3/popup/PopupDataProvider.java b/src/com/android/launcher3/popup/PopupDataProvider.java
index de9f25e..c921b4b 100644
--- a/src/com/android/launcher3/popup/PopupDataProvider.java
+++ b/src/com/android/launcher3/popup/PopupDataProvider.java
@@ -53,6 +53,7 @@
     private static final SystemShortcut[] SYSTEM_SHORTCUTS = new SystemShortcut[] {
             new SystemShortcut.AppInfo(),
             new SystemShortcut.Widgets(),
+            new SystemShortcut.Install()
     };
 
     private final Launcher mLauncher;
diff --git a/src/com/android/launcher3/popup/SystemShortcut.java b/src/com/android/launcher3/popup/SystemShortcut.java
index 6254d2d..a342500 100644
--- a/src/com/android/launcher3/popup/SystemShortcut.java
+++ b/src/com/android/launcher3/popup/SystemShortcut.java
@@ -1,6 +1,7 @@
 package com.android.launcher3.popup;
 
 import android.content.Context;
+import android.content.Intent;
 import android.graphics.Rect;
 import android.graphics.drawable.Drawable;
 import android.os.Bundle;
@@ -11,7 +12,10 @@
 import com.android.launcher3.ItemInfo;
 import com.android.launcher3.Launcher;
 import com.android.launcher3.R;
+import com.android.launcher3.ShortcutInfo;
 import com.android.launcher3.model.WidgetItem;
+import com.android.launcher3.util.InstantAppResolver;
+import com.android.launcher3.util.PackageManagerHelper;
 import com.android.launcher3.util.PackageUserKey;
 import com.android.launcher3.widget.WidgetsBottomSheet;
 
@@ -95,4 +99,35 @@
             };
         }
     }
+
+    public static class Install extends SystemShortcut {
+        public Install() {
+            super(R.drawable.ic_install_no_shadow, R.string.install_drop_target_label);
+        }
+
+        @Override
+        public View.OnClickListener getOnClickListener(final Launcher launcher,
+                final ItemInfo itemInfo) {
+            boolean supportsWebUI = (itemInfo instanceof ShortcutInfo) &&
+                    ((ShortcutInfo) itemInfo).hasStatusFlag(ShortcutInfo.FLAG_SUPPORTS_WEB_UI);
+            boolean isInstantApp = false;
+            if (itemInfo instanceof com.android.launcher3.AppInfo) {
+                com.android.launcher3.AppInfo appInfo = (com.android.launcher3.AppInfo) itemInfo;
+                isInstantApp = InstantAppResolver.newInstance(launcher).isInstantApp(appInfo);
+            }
+            boolean enabled = supportsWebUI || isInstantApp;
+            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);
+                }
+            };
+        }
+    }
 }
diff --git a/src/com/android/launcher3/util/InstantAppResolver.java b/src/com/android/launcher3/util/InstantAppResolver.java
index e60d768..99ce7ca 100644
--- a/src/com/android/launcher3/util/InstantAppResolver.java
+++ b/src/com/android/launcher3/util/InstantAppResolver.java
@@ -19,6 +19,7 @@
 import android.content.Context;
 import android.content.pm.ApplicationInfo;
 
+import com.android.launcher3.AppInfo;
 import com.android.launcher3.R;
 import com.android.launcher3.Utilities;
 
@@ -39,6 +40,10 @@
         return false;
     }
 
+    public boolean isInstantApp(AppInfo info) {
+        return false;
+    }
+
     public List<ApplicationInfo> getInstantApps() {
         return Collections.emptyList();
     }