Skip to content

Commit

Permalink
[Recent Tasks] Swipe right to kill on slim recent panel, works on RR …
Browse files Browse the repository at this point in the history
…ROM.
  • Loading branch information
bluesky139 committed Jun 27, 2018
1 parent 25255aa commit 91c13f3
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/src/main/java/li/lingfeng/ltweaks/prefs/ClassNames.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public class ClassNames {
public static final String CONSTRAINT_LAYOUT = "android.support.constraint.ConstraintLayout";
public static final String BOTTOM_NAV_VIEW = "android.support.design.widget.BottomNavigationView";
public static final String DRAWER_LAYOUT = "android.support.v4.widget.DrawerLayout";
public static final String RECYCLER_VIEW_HOLDER = "android.support.v7.widget.RecyclerView$ViewHolder";
public static final String ITEM_TOUCH_HELPER = "android.support.v7.widget.helper.ItemTouchHelper";
public static final String ITEM_TOUCH_HELPER_CALLBACK = "android.support.v7.widget.helper.ItemTouchHelper$Callback";

public static final String ACTIVITY_MANAGER_SERVICE = "com.android.server.am.ActivityManagerService";
public static final String ALARM_MANAGER_SERVICE = "com.android.server.AlarmManagerService";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package li.lingfeng.ltweaks.xposed.system;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
Expand All @@ -24,6 +25,8 @@ public class XposedRecentTaskSwipeToKill extends XposedBase {
private static final String SWIPE_HELPER = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ?
"com.android.systemui.SwipeHelper" : "com.android.systemui.recents.views.SwipeHelper";
private static final String TASK_VIEW = "com.android.systemui.recents.views.TaskView";
private static final String SLIM_RECENT_PANEL_VIEW = "com.android.systemui.slimrecent.RecentPanelView";
private XC_MethodHook.Unhook mSlimItemTouchHelperHook;

@Override
protected void handleLoadPackage() throws Throwable {
Expand All @@ -44,6 +47,11 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
return;
}

handleAOSP();
handleSlim();
}

private void handleAOSP() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
findAndHookMethod(SWIPE_HELPER, "dismissChild", View.class, float.class, boolean.class, new XC_MethodHook() {
@Override
Expand Down Expand Up @@ -79,4 +87,47 @@ private void hookDismissChild(XC_MethodHook.MethodHookParam param) throws Throwa
String packageName = intent.getComponent().getPackageName();
PackageUtils.killPackage(taskView.getContext(), packageName);
}

private void handleSlim() {
try {
findClass(SLIM_RECENT_PANEL_VIEW);
} catch (Throwable e) {
return;
}

mSlimItemTouchHelperHook = findAndHookConstructor(ClassNames.ITEM_TOUCH_HELPER, ClassNames.ITEM_TOUCH_HELPER_CALLBACK, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
if (mSlimItemTouchHelperHook == null) {
return;
}
Class cls = param.args[0].getClass();
if (cls.getName().startsWith(SLIM_RECENT_PANEL_VIEW)) {
mSlimItemTouchHelperHook = null;
hookSlimTouchHelper(cls);
}
}
});
}

private void hookSlimTouchHelper(Class cls) {
Logger.d("hookSlimTouchHelper " + cls);
findAndHookMethod(cls, "onSwiped", findClass(ClassNames.RECYCLER_VIEW_HOLDER), int.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
int direction = (int) param.args[1];
if (direction == 32) {
Logger.i("Slim recent swipe right to kill.");
int pos = (int) XposedHelpers.callMethod(param.args[0], "getAdapterPosition");
Object panelView = XposedHelpers.getSurroundingThis(param.thisObject);
Object cardAdapter = XposedHelpers.getObjectField(panelView, "mCardAdapter");
Object card = XposedHelpers.callMethod(cardAdapter, "getCard", pos);
Object task = XposedHelpers.getObjectField(card, "task");
String packageName = (String) XposedHelpers.getObjectField(task, "packageName");
Context context = (Context) XposedHelpers.getObjectField(panelView, "mContext");
PackageUtils.killPackage(context, packageName);
}
}
});
}
}

0 comments on commit 91c13f3

Please sign in to comment.