summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAli B <abittin@gmail.com>2021-01-30 22:36:40 +0300
committeralk3pInjection <webmaster@raspii.tech>2021-09-27 21:17:05 +0800
commit6d4484b66f2a2a839d9487375f1627483d29176e (patch)
treeac85d6b79848204b4193695f467978ee59476da4
parentbbc8bdeee011b1a437c487285fef103ec3a91ea4 (diff)
Trebuchet: Add uninstall button to system shortcuts
Change-Id: I005d676d9a98f65296c330e5e13fd0d849df6fe5
-rw-r--r--quickstep/recents_ui_overrides/src/com/android/quickstep/TaskOverlayFactory.java1
-rw-r--r--quickstep/recents_ui_overrides/src/com/android/quickstep/TaskShortcutFactory.java6
-rw-r--r--src/com/android/launcher3/Launcher.java3
-rw-r--r--src/com/android/launcher3/popup/SystemShortcut.java23
-rw-r--r--src/com/android/launcher3/util/PackageManagerHelper.java37
5 files changed, 60 insertions, 10 deletions
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/TaskOverlayFactory.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/TaskOverlayFactory.java
index 1f9dcc557..fc7262604 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/TaskOverlayFactory.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/TaskOverlayFactory.java
@@ -109,6 +109,7 @@ public class TaskOverlayFactory implements ResourceBasedOverride {
TaskShortcutFactory.APP_INFO,
TaskShortcutFactory.KILL_APP,
TaskShortcutFactory.SPLIT_SCREEN,
+ TaskShortcutFactory.UNINSTALL,
TaskShortcutFactory.PIN,
TaskShortcutFactory.INSTALL,
TaskShortcutFactory.FREE_FORM,
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/TaskShortcutFactory.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/TaskShortcutFactory.java
index f9495a5c9..43f2cf84d 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/TaskShortcutFactory.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/TaskShortcutFactory.java
@@ -48,6 +48,7 @@ import com.android.launcher3.popup.SystemShortcut.AppInfo;
import com.android.launcher3.userevent.nano.LauncherLogProto;
import com.android.launcher3.util.Executors;
import com.android.launcher3.util.InstantAppResolver;
+import com.android.launcher3.util.PackageManagerHelper;
import com.android.quickstep.views.RecentsView;
import com.android.quickstep.views.TaskThumbnailView;
import com.android.quickstep.views.TaskView;
@@ -73,6 +74,11 @@ public interface TaskShortcutFactory {
TaskShortcutFactory APP_INFO = (activity, view) -> new AppInfo(activity, view.getItemInfo());
+ TaskShortcutFactory UNINSTALL = (activity, view) ->
+ PackageManagerHelper.isSystemApp(activity,
+ view.getTask().getTopComponent().getPackageName())
+ ? null : new SystemShortcut.UnInstall(activity, view.getItemInfo());
+
abstract class MultiWindowFactory implements TaskShortcutFactory {
private final int mIconRes;
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index b03f31d1a..68502d7c2 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -46,6 +46,7 @@ import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCH
import static com.android.launcher3.logging.StatsLogManager.containerTypeToAtomState;
import static com.android.launcher3.popup.SystemShortcut.APP_INFO;
import static com.android.launcher3.popup.SystemShortcut.INSTALL;
+import static com.android.launcher3.popup.SystemShortcut.UNINSTALL;
import static com.android.launcher3.popup.SystemShortcut.WIDGETS;
import static com.android.launcher3.states.RotationHelper.REQUEST_LOCK;
import static com.android.launcher3.states.RotationHelper.REQUEST_NONE;
@@ -2736,7 +2737,7 @@ public class Launcher extends StatefulActivity<LauncherState> implements Launche
}
public Stream<SystemShortcut.Factory> getSupportedShortcuts() {
- return Stream.of(APP_INFO, WIDGETS, INSTALL);
+ return Stream.of(APP_INFO, WIDGETS, INSTALL, UNINSTALL);
}
diff --git a/src/com/android/launcher3/popup/SystemShortcut.java b/src/com/android/launcher3/popup/SystemShortcut.java
index 3fb5ea136..dfe344211 100644
--- a/src/com/android/launcher3/popup/SystemShortcut.java
+++ b/src/com/android/launcher3/popup/SystemShortcut.java
@@ -181,6 +181,29 @@ public abstract class SystemShortcut<T extends BaseDraggingActivity> extends Ite
}
}
+ public static final Factory<BaseDraggingActivity> UNINSTALL = (activity, itemInfo) ->
+ PackageManagerHelper.isSystemApp(activity,
+ itemInfo.getTargetComponent().getPackageName())
+ ? null : new UnInstall(activity, itemInfo);
+
+
+ public static class UnInstall extends SystemShortcut {
+
+ public UnInstall(BaseDraggingActivity target, ItemInfo itemInfo) {
+ super(R.drawable.ic_uninstall_no_shadow, R.string.uninstall_drop_target_label,
+ target, itemInfo);
+ }
+
+ @Override
+ public void onClick(View view) {
+ String packageName = mItemInfo.getTargetComponent().getPackageName();
+ Intent intent = new PackageManagerHelper(
+ view.getContext()).getUninstallIntent(packageName);
+ mTarget.startActivitySafely(view, intent, mItemInfo, null);
+ AbstractFloatingView.closeAllOpenViews(mTarget);
+ }
+ }
+
public static void dismissTaskMenuView(BaseDraggingActivity activity) {
AbstractFloatingView.closeOpenViews(activity, true,
AbstractFloatingView.TYPE_ALL & ~AbstractFloatingView.TYPE_REBIND_SAFE);
diff --git a/src/com/android/launcher3/util/PackageManagerHelper.java b/src/com/android/launcher3/util/PackageManagerHelper.java
index 86f3431b5..8234ee0bf 100644
--- a/src/com/android/launcher3/util/PackageManagerHelper.java
+++ b/src/com/android/launcher3/util/PackageManagerHelper.java
@@ -200,6 +200,12 @@ public class PackageManagerHelper {
.authority(mContext.getPackageName()).build());
}
+ public Intent getUninstallIntent(String packageName) {
+ return new Intent(Intent.ACTION_UNINSTALL_PACKAGE)
+ .setData(Uri.parse("package:" + packageName))
+ .putExtra(Intent.EXTRA_RETURN_RESULT, true);
+ }
+
/**
* Creates a new market search intent.
*/
@@ -264,21 +270,34 @@ public class PackageManagerHelper {
return packageFilter;
}
+ public static boolean isSystemApp(Context context, String pkgName) {
+ return isSystemApp(context, null, pkgName);
+ }
+
public static boolean isSystemApp(Context context, Intent intent) {
+ return isSystemApp(context, intent, null);
+ }
+
+ public static boolean isSystemApp(Context context, Intent intent, String pkgName) {
PackageManager pm = context.getPackageManager();
- ComponentName cn = intent.getComponent();
String packageName = null;
- if (cn == null) {
- ResolveInfo info = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
- if ((info != null) && (info.activityInfo != null)) {
- packageName = info.activityInfo.packageName;
+ // If the intent is not null, let's get the package name from the intent.
+ if (intent != null) {
+ ComponentName cn = intent.getComponent();
+ if (cn == null) {
+ ResolveInfo info = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
+ if ((info != null) && (info.activityInfo != null)) {
+ packageName = info.activityInfo.packageName;
+ }
+ } else {
+ packageName = cn.getPackageName();
}
- } else {
- packageName = cn.getPackageName();
}
- if (packageName == null) {
- packageName = intent.getPackage();
+ // Otherwise we have the package name passed from the method.
+ else {
+ packageName = pkgName;
}
+ // Check if the provided package is a system app.
if (packageName != null) {
try {
PackageInfo info = pm.getPackageInfo(packageName, 0);