Add uninstall button and it's fixes (#2840)

* Lawnchair: Add uninstall button to system shortcuts

[ghostrider-reborn] updated for android 12
[marshmello61] adapt for Lawnchair
Change-Id: I005d676d9a98f65296c330e5e13fd0d849df6fe5
Signed-off-by: Adithya <gh0strider.2k18.reborn@gmail.com>
Signed-off-by: Mayur <ultramayur123@gmail.com>

* Lawnchair: Fix NPE in SystemShortcut

[marshmello61] adapt for Lawnchair
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
Signed-off-by: Mayur <ultramayur123@gmail.com>

* Lawnchair: Use standard launcher method for uninstalling

[marshmello61] adapt for Lawnchair
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
Signed-off-by: Mayur <ultramayur123@gmail.com>

* Fix PR issues

Co-authored-by: Ali B <abittin@gmail.com>
Co-authored-by: Pranav Vashi <neobuddy89@gmail.com>
Co-authored-by: Yasan Ghaffarian <y.ghafarian@dariahamrah.ir>
This commit is contained in:
Mayur Varde
2022-09-05 14:14:22 +05:30
committed by GitHub
parent 08031573ff
commit bf7e4d562c
5 changed files with 59 additions and 11 deletions

View File

@@ -169,6 +169,7 @@ public class TaskOverlayFactory implements ResourceBasedOverride {
private static final TaskShortcutFactory[] MENU_OPTIONS = new TaskShortcutFactory[]{
TaskShortcutFactory.APP_INFO,
TaskShortcutFactory.SPLIT_SCREEN,
TaskShortcutFactory.UNINSTALL,
TaskShortcutFactory.PIN,
TaskShortcutFactory.INSTALL,
TaskShortcutFactory.FREE_FORM,

View File

@@ -42,6 +42,7 @@ import com.android.launcher3.popup.SystemShortcut;
import com.android.launcher3.popup.SystemShortcut.AppInfo;
import com.android.launcher3.util.InstantAppResolver;
import com.android.launcher3.util.SplitConfigurationOptions.SplitPositionOption;
import com.android.launcher3.util.PackageManagerHelper;
import com.android.quickstep.views.RecentsView;
import com.android.quickstep.views.TaskThumbnailView;
import com.android.quickstep.views.TaskView;
@@ -88,6 +89,11 @@ public interface TaskShortcutFactory {
}
};
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;

View File

@@ -56,6 +56,7 @@ import static com.android.launcher3.model.ItemInstallQueue.FLAG_ACTIVITY_PAUSED;
import static com.android.launcher3.model.ItemInstallQueue.FLAG_DRAG_AND_DROP;
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;
@@ -3081,7 +3082,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);
}
protected LauncherAccessibilityDelegate createAccessibilityDelegate() {

View File

@@ -7,6 +7,7 @@ import android.app.ActivityOptions;
import android.content.Context;
import android.content.Intent;
import android.graphics.Rect;
import android.net.Uri;
import android.view.View;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.ImageView;
@@ -29,6 +30,7 @@ import com.android.launcher3.views.ActivityContext;
import com.android.launcher3.widget.WidgetsBottomSheet;
import com.patrykmichalik.opto.core.PreferenceExtensionsKt;
import java.net.URISyntaxException;
import java.util.List;
import app.lawnchair.preferences2.PreferenceManager2;
@@ -237,6 +239,38 @@ public abstract class SystemShortcut<T extends Context & ActivityContext> extend
}
}
public static final Factory<BaseDraggingActivity> UNINSTALL = (activity, itemInfo) -> {
if (itemInfo.getTargetComponent() == null) {
return null;
}
if (PackageManagerHelper.isSystemApp(activity,
itemInfo.getTargetComponent().getPackageName())) {
return null;
}
return new UnInstall(activity, itemInfo);
};
public static class UnInstall extends SystemShortcut<BaseDraggingActivity> {
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) {
try {
Intent intent = Intent.parseUri(view.getContext().getString(R.string.delete_package_intent), 0)
.setData(Uri.fromParts("package", mItemInfo.getTargetComponent().getPackageName(),
mItemInfo.getTargetComponent().getClassName())).putExtra(Intent.EXTRA_USER, mItemInfo.user);
mTarget.startActivitySafely(view, intent, mItemInfo);
AbstractFloatingView.closeAllOpenViews(mTarget);
} catch (URISyntaxException e) {
// Do nothing.
}
}
}
public static <T extends Context & ActivityContext> void dismissTaskMenuView(T activity) {
AbstractFloatingView.closeOpenViews(activity, true,
AbstractFloatingView.TYPE_ALL & ~AbstractFloatingView.TYPE_REBIND_SAFE);

View File

@@ -258,19 +258,25 @@ public class PackageManagerHelper {
public static boolean isSystemApp(Context context, Intent intent) {
PackageManager pm = context.getPackageManager();
ComponentName cn = intent.getComponent();
// Get the package name for intent
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 (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();
}
return isSystemApp(context, packageName);
}
public static boolean isSystemApp(Context context, String packageName) {
PackageManager pm = context.getPackageManager();
// Check if the provided package is a system app.
if (packageName != null) {
try {
PackageInfo info = pm.getPackageInfo(packageName, 0);