Merge "Include user handle for uninstall intents." into ub-now-master

This commit is contained in:
Kenny Guy
2014-07-16 17:14:40 +00:00
committed by Android (Google) Code Review
3 changed files with 25 additions and 16 deletions

View File

@@ -187,11 +187,6 @@ public class DeleteDropTarget extends ButtonDropTarget {
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 @@ public class DeleteDropTarget extends ButtonDropTarget {
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 @@ public class DeleteDropTarget extends ButtonDropTarget {
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);

View File

@@ -2721,7 +2721,8 @@ public class Launcher extends Activity
}
// 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.
@@ -2735,6 +2736,9 @@ public class Launcher extends Activity
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;
}

View File

@@ -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 @@ public class UserHandleCompat {
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);
}
}
}