Include user handle for uninstall intents.

Add support for uninstalling apps from other profiles.

Bug: 14127299

Change-Id: I1a3724a45c95cf93b958d23a57829efcedfc4291
diff --git a/src/com/android/launcher3/DeleteDropTarget.java b/src/com/android/launcher3/DeleteDropTarget.java
index 20546b8..3d45432 100644
--- a/src/com/android/launcher3/DeleteDropTarget.java
+++ b/src/com/android/launcher3/DeleteDropTarget.java
@@ -187,11 +187,6 @@
         if (!willAcceptDrop(info) || isAllAppsWidget(source, info)) {
             isVisible = false;
         }
-        if (useUninstallLabel &&
-                !(((ItemInfo) info).user.equals(UserHandleCompat.myUserHandle()))) {
-            // Don't support uninstall for apps from other profiles.
-            isVisible = false;
-        }
 
         if (useUninstallLabel) {
             setCompoundDrawablesRelativeWithIntrinsicBounds(mUninstallDrawable, null, null, null);
@@ -287,19 +282,16 @@
         if (isAllAppsApplication(d.dragSource, item)) {
             // Uninstall the application if it is being dragged from AppsCustomize
             AppInfo appInfo = (AppInfo) item;
-            // We don't support uninstalling apps from other profiles.
-            if (item.user.equals(UserHandleCompat.myUserHandle())) {
-                mLauncher.startApplicationUninstallActivity(appInfo.componentName, appInfo.flags);
-            }
+            mLauncher.startApplicationUninstallActivity(appInfo.componentName, appInfo.flags,
+                    appInfo.user);
         } else if (isUninstallFromWorkspace(d)) {
             ShortcutInfo shortcut = (ShortcutInfo) item;
-            // We don't support uninstalling apps from other profiles.
-            if (shortcut.intent != null && shortcut.intent.getComponent() != null &&
-                    shortcut.user.equals(UserHandleCompat.myUserHandle())) {
+            if (shortcut.intent != null && shortcut.intent.getComponent() != null) {
                 final ComponentName componentName = shortcut.intent.getComponent();
                 final DragSource dragSource = d.dragSource;
-                mWaitingForUninstall =
-                        mLauncher.startApplicationUninstallActivity(componentName, shortcut.flags);
+                final UserHandleCompat user = shortcut.user;
+                mWaitingForUninstall = mLauncher.startApplicationUninstallActivity(
+                        componentName, shortcut.flags, user);
                 if (mWaitingForUninstall) {
                     final Runnable checkIfUninstallWasSuccess = new Runnable() {
                         @Override
@@ -307,7 +299,7 @@
                             mWaitingForUninstall = false;
                             String packageName = componentName.getPackageName();
                             boolean uninstallSuccessful = !AllAppsList.packageHasActivities(
-                                    getContext(), packageName, UserHandleCompat.myUserHandle());
+                                    getContext(), packageName, user);
                             if (dragSource instanceof Folder) {
                                 ((Folder) dragSource).
                                     onUninstallActivityReturned(uninstallSuccessful);
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index a85b5b1..0b07968 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -2718,7 +2718,8 @@
     }
 
     // returns true if the activity was started
-    boolean startApplicationUninstallActivity(ComponentName componentName, int flags) {
+    boolean startApplicationUninstallActivity(ComponentName componentName, int flags,
+            UserHandleCompat user) {
         if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
             // System applications cannot be installed. For now, show a toast explaining that.
             // We may give them the option of disabling apps this way.
@@ -2732,6 +2733,9 @@
                     Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
             intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
                     Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
+            if (user != null) {
+                user.addToIntent(intent, Intent.EXTRA_USER);
+            }
             startActivity(intent);
             return true;
         }
diff --git a/src/com/android/launcher3/compat/UserHandleCompat.java b/src/com/android/launcher3/compat/UserHandleCompat.java
index 8f5dda2..4baf052 100644
--- a/src/com/android/launcher3/compat/UserHandleCompat.java
+++ b/src/com/android/launcher3/compat/UserHandleCompat.java
@@ -16,6 +16,7 @@
 
 package com.android.launcher3.compat;
 
+import android.content.Intent;
 import android.os.Build;
 import android.os.UserHandle;
 
@@ -78,4 +79,16 @@
             return 0;
         }
     }
+
+    /**
+     * Adds {@link UserHandle} to the intent in for L or above.
+     * Pre-L the launcher doesn't support showing apps for multiple
+     * profiles so this is a no-op.
+     */
+    public void addToIntent(Intent intent, String name) {
+        // TODO change this to use api version once L gets an API number.
+        if ("L".equals(Build.VERSION.CODENAME) && mUser != null) {
+            intent.putExtra(name, mUser);
+        }
+    }
 }
\ No newline at end of file