From dda255a66410f0b06b6b8af9cb81121642cc8191 Mon Sep 17 00:00:00 2001 From: ezio84 Date: Wed, 7 Nov 2018 23:48:51 +0100 Subject: [PATCH] Launcher3: Add kill action to app shortcuts popup Squashed: Launcher3: Dismiss task from recents when killed Change-Id: I25f37484a444346bf08e6960893892cc4bf25ada Launcher3: Add FORCE_STOP_PACKAGES permission Change-Id: I20dd0287c47269ccfdd02a8eae2a3da1de96e206 Launcher3: Update kill app button drawable Change-Id: Iff78ae0528b8ed9c7b11952352e4b6d43507e233 Co-authored-by: Ali B Co-authored-by: Pranav Vashi Co-authored-by: Alexandru Scurtu [mickaelmendes50: Improve 'kill' action string] [ghostrider-reborn: Add privapp permissions, adapt to Sv2, 13] Signed-off-by: Adithya R Change-Id: Iff78ae0528b8ed9c7b11952352e4b6d43507e233 --- Android.bp | 26 ++++++++-- AndroidManifest-common.xml | 2 + privapp_whitelist_aospa_launcher3.xml | 13 +++++ quickstep/res/drawable/ic_kill_app.xml | 29 +++++++++++ quickstep/res/values/aospa_strings.xml | 24 +++++++++ .../android/quickstep/TaskOverlayFactory.java | 1 + .../quickstep/TaskShortcutFactory.java | 49 +++++++++++++++++++ 7 files changed, 140 insertions(+), 4 deletions(-) create mode 100644 privapp_whitelist_aospa_launcher3.xml create mode 100644 quickstep/res/drawable/ic_kill_app.xml create mode 100644 quickstep/res/values/aospa_strings.xml diff --git a/Android.bp b/Android.bp index 3a36daa4fb..df366dde87 100644 --- a/Android.bp +++ b/Android.bp @@ -228,7 +228,10 @@ android_app { "Home", "Launcher2", ], - required: ["privapp_whitelist_com.android.launcher3"], + required: [ + "privapp_whitelist_com.android.launcher3", + "privapp_whitelist_aospa_launcher3.xml", + ], jacoco: { include_filter: ["com.android.launcher3.**"], @@ -357,7 +360,10 @@ android_app { "Launcher3", "Launcher3QuickStep", ], - required: ["privapp_whitelist_com.android.launcher3"], + required: [ + "privapp_whitelist_com.android.launcher3", + "privapp_whitelist_aospa_launcher3.xml", + ], additional_manifests: [ "AndroidManifest.xml", @@ -392,7 +398,10 @@ android_app { "Launcher2", "Launcher3", ], - required: ["privapp_whitelist_com.android.launcher3"], + required: [ + "privapp_whitelist_com.android.launcher3", + "privapp_whitelist_aospa_launcher3.xml", + ], resource_dirs: ["quickstep/res"], @@ -443,7 +452,10 @@ android_app { "Launcher3", "Launcher3QuickStep", ], - required: ["privapp_whitelist_com.android.launcher3"], + required: [ + "privapp_whitelist_com.android.launcher3", + "privapp_whitelist_aospa_launcher3.xml", + ], additional_manifests: [ "go/AndroidManifest.xml", @@ -458,3 +470,9 @@ android_app { } +prebuilt_etc { + name: "privapp_whitelist_aospa_launcher3.xml", + src: "privapp_whitelist_aospa_launcher3.xml", + system_ext_specific: true, + sub_dir: "permissions", +} diff --git a/AndroidManifest-common.xml b/AndroidManifest-common.xml index 6ef64a4acc..fb58411596 100644 --- a/AndroidManifest-common.xml +++ b/AndroidManifest-common.xml @@ -46,6 +46,8 @@ + + + + + + + + + + diff --git a/quickstep/res/drawable/ic_kill_app.xml b/quickstep/res/drawable/ic_kill_app.xml new file mode 100644 index 0000000000..bb7036a6ac --- /dev/null +++ b/quickstep/res/drawable/ic_kill_app.xml @@ -0,0 +1,29 @@ + + + + + + diff --git a/quickstep/res/values/aospa_strings.xml b/quickstep/res/values/aospa_strings.xml new file mode 100644 index 0000000000..8c11ae256a --- /dev/null +++ b/quickstep/res/values/aospa_strings.xml @@ -0,0 +1,24 @@ + + + + + + Force close + App closed + diff --git a/quickstep/src/com/android/quickstep/TaskOverlayFactory.java b/quickstep/src/com/android/quickstep/TaskOverlayFactory.java index fdf2235f7d..fdc0d4a40f 100644 --- a/quickstep/src/com/android/quickstep/TaskOverlayFactory.java +++ b/quickstep/src/com/android/quickstep/TaskOverlayFactory.java @@ -120,6 +120,7 @@ public class TaskOverlayFactory implements ResourceBasedOverride { /** Note that these will be shown in order from top to bottom, if available for the task. */ private static final TaskShortcutFactory[] MENU_OPTIONS = new TaskShortcutFactory[]{ TaskShortcutFactory.APP_INFO, + TaskShortcutFactory.KILL_APP, TaskShortcutFactory.SPLIT_SELECT, TaskShortcutFactory.UNINSTALL, TaskShortcutFactory.PIN, diff --git a/quickstep/src/com/android/quickstep/TaskShortcutFactory.java b/quickstep/src/com/android/quickstep/TaskShortcutFactory.java index 34eeef504c..511786bc99 100644 --- a/quickstep/src/com/android/quickstep/TaskShortcutFactory.java +++ b/quickstep/src/com/android/quickstep/TaskShortcutFactory.java @@ -22,7 +22,9 @@ import static com.android.launcher3.config.FeatureFlags.ENABLE_OVERVIEW_SELECTIO import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_SYSTEM_SHORTCUT_FREE_FORM_TAP; import android.app.Activity; +import android.app.ActivityManagerNative; import android.app.ActivityOptions; +import android.app.IActivityManager; import android.graphics.Bitmap; import android.graphics.Color; import android.graphics.Rect; @@ -30,11 +32,13 @@ import android.os.Handler; import android.os.Looper; import android.os.RemoteException; import android.os.SystemProperties; +import android.os.UserHandle; import android.util.Log; import android.view.View; import android.view.WindowInsets; import android.view.WindowManagerGlobal; import android.window.SplashScreen; +import android.widget.Toast; import androidx.annotation.Nullable; @@ -410,4 +414,49 @@ public interface TaskShortcutFactory { return null; } }; + + TaskShortcutFactory KILL_APP = new TaskShortcutFactory() { + public List getShortcuts(BaseDraggingActivity activity, + TaskIdAttributeContainer taskContainer) { + String packageName = taskContainer.getTaskView() + .getItemInfo().getTargetComponent().getPackageName(); + return Collections.singletonList(new KillSystemShortcut(activity, taskContainer, packageName)); + + } + }; + + class KillSystemShortcut extends SystemShortcut { + private static final String TAG = "KillSystemShortcut"; + private final TaskView mTaskView; + private final BaseDraggingActivity mActivity; + private final String mPackageName; + + public KillSystemShortcut(BaseDraggingActivity activity, + TaskIdAttributeContainer taskContainer, String packageName) { + super(R.drawable.ic_kill_app, R.string.recent_task_option_kill_app, + activity, taskContainer.getItemInfo(), taskContainer.getTaskView()); + mTaskView = taskContainer.getTaskView(); + mActivity = activity; + mPackageName = packageName; + } + + @Override + public void onClick(View view) { + if (mPackageName != null) { + IActivityManager iam = ActivityManagerNative.getDefault(); + Task task = mTaskView.getTask(); + if (task != null) { + try { + iam.forceStopPackage(mPackageName, UserHandle.USER_CURRENT); + Toast appKilled = Toast.makeText(mActivity, R.string.recents_app_killed, + Toast.LENGTH_SHORT); + appKilled.show(); + ((RecentsView)mActivity.getOverviewPanel()) + .dismissTask(mTaskView, true /* animate */, true /* removeTask */); + } catch (RemoteException e) { } + } + } + dismissTaskMenuView(mActivity); + } + } }