Skip to content

Instantly share code, notes, and snippets.

@Dil3mm4
Created November 20, 2020 21:15
Show Gist options
  • Save Dil3mm4/f400577b240a6c308956238134975c11 to your computer and use it in GitHub Desktop.
Save Dil3mm4/f400577b240a6c308956238134975c11 to your computer and use it in GitHub Desktop.
From 339230d6363391480158529da0dd7ca84cb5583f Mon Sep 17 00:00:00 2001
From: Dil3mm4 <dil3mm4.dev@gmail.com>
Date: Fri, 20 Nov 2020 21:05:29 +0000
Subject: [PATCH] Recents: add kill app button
While at it, rework the layout to be suitable for more than 2 buttons
diff --git a/quickstep/AndroidManifest.xml b/quickstep/AndroidManifest.xml
index e49f2ecdc..470ddae1b 100644
--- a/quickstep/AndroidManifest.xml
+++ b/quickstep/AndroidManifest.xml
@@ -31,6 +31,7 @@
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
<uses-permission android:name="${packageName}.permission.HOTSEAT_EDU" />
+ <uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/>
<application
android:backupAgent="com.android.launcher3.LauncherBackupAgent"
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/OverviewActionsView.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/OverviewActionsView.java
index a2da39855..5242c011a 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/OverviewActionsView.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/OverviewActionsView.java
@@ -113,7 +113,6 @@ public class OverviewActionsView<T extends OverlayUICallbacks> extends FrameLayo
findViewById(R.id.action_screenshot).setOnClickListener(this);
if (ENABLE_OVERVIEW_SHARE.get()) {
share.setVisibility(VISIBLE);
- findViewById(R.id.share_space).setVisibility(VISIBLE);
}
}
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java
index 29306c732..39b7c2fff 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java
@@ -56,6 +56,7 @@ import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.annotation.TargetApi;
import android.app.ActivityManager;
+import android.app.IActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -232,6 +233,7 @@ public abstract class RecentsView<T extends StatefulActivity> extends PagedView
private final RecentsModel mModel;
private final int mTaskTopMargin;
private Button mClearAllButton;
+ private Button mKillAppButton;
private final Rect mTaskViewDeadZoneRect = new Rect();
private final ScrollState mScrollState = new ScrollState();
@@ -503,6 +505,8 @@ public abstract class RecentsView<T extends StatefulActivity> extends PagedView
mActionsView.updateHiddenFlags(HIDDEN_NO_TASKS, getTaskViewCount() == 0);
mClearAllButton = (Button) mActionsView.findViewById(R.id.clear_all);
mClearAllButton.setOnClickListener(this::dismissAllTasks);
+ mKillAppButton = (Button) mActionsView.findViewById(R.id.kill_app);
+ mKillAppButton.setOnClickListener(this::killTask);
}
@Override
@@ -1534,6 +1538,22 @@ public abstract class RecentsView<T extends StatefulActivity> extends PagedView
mActivity.getUserEventDispatcher().logActionOnControl(TAP, CLEAR_ALL_BUTTON);
}
+ @SuppressWarnings("unused")
+ private void killTask(View view) {
+ IActivityManager am = ActivityManager.getService();
+ TaskView tv = getNextPageTaskView();
+ Task task = tv.getTask();
+ String pkgname = task.key.getPackageName();
+ if (task != null) {
+ try {
+ am.killBackgroundProcesses(pkgname, UserHandle.USER_CURRENT);
+ } catch (Throwable t) {
+ //TODO: handle exception
+ }
+ dismissTask(tv, true, true);
+ }
+ }
+
private void dismissCurrentTask() {
TaskView taskView = getNextPageTaskView();
if (taskView != null) {
diff --git a/quickstep/res/drawable/ic_kill_app_recents.xml b/quickstep/res/drawable/ic_kill_app_recents.xml
new file mode 100644
index 000000000..e0a509358
--- /dev/null
+++ b/quickstep/res/drawable/ic_kill_app_recents.xml
@@ -0,0 +1,13 @@
+<vector
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:name="vector"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
+ <path
+ android:name="path"
+ android:pathData="M 4.707 3.293 L 3.293 4.707 L 10.586 12 L 3.293 19.293 L 4.707 20.707 L 12 13.414 L 19.293 20.707 L 20.707 19.293 L 13.414 12 L 20.707 4.707 L 19.293 3.293 L 12 10.586 L 4.707 3.293 Z"
+ android:fillColor="#ff000000"
+ android:strokeWidth="1"/>
+</vector>
diff --git a/quickstep/res/layout/overview_actions_container.xml b/quickstep/res/layout/overview_actions_container.xml
index be1599546..6eb2de8de 100644
--- a/quickstep/res/layout/overview_actions_container.xml
+++ b/quickstep/res/layout/overview_actions_container.xml
@@ -28,13 +28,9 @@
android:layout_gravity="center"
android:orientation="horizontal">
- <Space
- android:layout_width="0dp"
- android:layout_height="1dp"
- android:layout_weight="1" />
-
<Button
android:id="@+id/action_screenshot"
+ android:layout_weight="1"
style="@style/OverviewActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@@ -42,13 +38,9 @@
android:text="@string/action_screenshot"
android:theme="@style/ThemeControlHighlightWorkspaceColor" />
- <Space
- android:layout_width="0dp"
- android:layout_height="1dp"
- android:layout_weight="1" />
-
<Button
style="@style/OverviewActionButton"
+ android:layout_weight="1"
android:id="@+id/clear_all"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@@ -57,13 +49,20 @@
android:drawableStart="@drawable/ic_clear_all_recents"
/>
- <Space
- android:layout_width="0dp"
- android:layout_height="1dp"
- android:layout_weight="1" />
+ <Button
+ style="@style/OverviewActionButton"
+ android:layout_weight="1"
+ android:id="@+id/kill_app"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/recents_kill_app"
+ android:theme="@style/ThemeControlHighlightWorkspaceColor"
+ android:drawableStart="@drawable/ic_kill_app_recents"
+ />
<Button
android:id="@+id/action_share"
+ android:layout_weight="1"
style="@style/OverviewActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@@ -72,12 +71,6 @@
android:theme="@style/ThemeControlHighlightWorkspaceColor"
android:visibility="gone" />
- <Space
- android:id="@+id/share_space"
- android:layout_width="0dp"
- android:layout_height="1dp"
- android:layout_weight="1"
- android:visibility="gone" />
</LinearLayout>
</com.android.quickstep.views.OverviewActionsView>
diff --git a/quickstep/res/values/descendant-strings.xml b/quickstep/res/values/descendant-strings.xml
new file mode 100644
index 000000000..e5b404477
--- /dev/null
+++ b/quickstep/res/values/descendant-strings.xml
@@ -0,0 +1,5 @@
+<resources>
+
+ <string name="recents_kill_app">Kill app</string>
+
+</resources>
--
2.20.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment