Skip to content

Commit

Permalink
CHANGELOG: Kill foreground app gesture now goes to home screen
Browse files Browse the repository at this point in the history
  • Loading branch information
siavash79 committed Feb 13, 2024
1 parent 1088fc6 commit b0580bb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
3 changes: 3 additions & 0 deletions app/src/main/java/sh/siava/pixelxpert/modpacks/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@

public final class Constants {
public static final String ACTION_SCREENSHOT = APPLICATION_ID + ".ACTION_SCREENSHOT";

@SuppressWarnings("DeprecatedIsStillUsed")
@Deprecated
public static final String ACTION_INSECURE_SCREENSHOT = APPLICATION_ID + ".ACTION_INSECURE_SCREENSHOT";
public static final String ACTION_HOME = APPLICATION_ID + ".ACTION_HOME";

public static final String ACTION_BACK = APPLICATION_ID + ".ACTION_BACK";
public static final String ACTION_SLEEP = APPLICATION_ID + ".ACTION_SLEEP";
public static final String ACTION_SWITCH_APP_PROFILE = APPLICATION_ID + ".ACTION_SWITCH_APP_PROFILE";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ public void onReceive(Context context, Intent intent) {
callMethod(windowMan, "handleScreenShot", 1, 1); //pre 13 QPR3
}
break;
case Constants.ACTION_HOME:
callMethod(windowMan, "launchHomeFromHotKey", Display.DEFAULT_DISPLAY);
break;
case Constants.ACTION_BACK:
callMethod(windowMan, "backKeyPress");
break;
Expand Down Expand Up @@ -166,6 +169,7 @@ public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Th

IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Constants.ACTION_SCREENSHOT);
intentFilter.addAction(Constants.ACTION_HOME);
intentFilter.addAction(Constants.ACTION_BACK);
intentFilter.addAction(Constants.ACTION_INSECURE_SCREENSHOT);
intentFilter.addAction(Constants.ACTION_SLEEP);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import static de.robv.android.xposed.XposedBridge.hookAllConstructors;
import static de.robv.android.xposed.XposedBridge.hookAllMethods;
import static de.robv.android.xposed.XposedBridge.log;
import static de.robv.android.xposed.XposedHelpers.callMethod;
import static de.robv.android.xposed.XposedHelpers.callStaticMethod;
import static de.robv.android.xposed.XposedHelpers.findClass;
import static de.robv.android.xposed.XposedHelpers.getBooleanField;
import static de.robv.android.xposed.XposedHelpers.getObjectField;
Expand All @@ -14,7 +16,9 @@
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Rect;
import android.hardware.input.InputManager;
import android.os.Process;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.widget.Toast;

Expand Down Expand Up @@ -93,7 +97,7 @@ public boolean listensTo(String packageName) {

@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
if (!lpparam.packageName.equals(listenPackage)) return;
log("wow?");

Class<?> OtherActivityInputConsumerClass = findClass("com.android.quickstep.inputconsumers.OtherActivityInputConsumer", lpparam.classLoader); //When apps are open
Class<?> OverviewInputConsumerClass = findClass("com.android.quickstep.inputconsumers.OverviewInputConsumer", lpparam.classLoader); //When on Home screen and Recents
Expand Down Expand Up @@ -264,6 +268,7 @@ private void runAction(int action) {
toggleNotification();
break;
case ACTION_KILL_APP:
log("kill forg");
killForeground();
break;
case ACTION_ONE_HANDED:
Expand Down Expand Up @@ -304,12 +309,18 @@ private void goToSleep() {
private void killForeground() {
if(currentFocusedTask == null) return;

Toast.makeText(mContext, "App Killed", Toast.LENGTH_SHORT).show();
try
{
Toast.makeText(mContext, "App Killed", Toast.LENGTH_SHORT).show();

callMethod(mContext.getSystemService(Context.ACTIVITY_SERVICE),
"forceStopPackageAsUser",
((ComponentName) getObjectField(currentFocusedTask, "realActivity")).getPackageName(),
getObjectField(currentFocusedTask, "userId"));

callMethod(mContext.getSystemService(Context.ACTIVITY_SERVICE),
"forceStopPackageAsUser",
((ComponentName) getObjectField(currentFocusedTask, "realActivity")).getPackageName(),
getObjectField(currentFocusedTask, "userId"));
goHome();
}
catch (Throwable ignored) {}
}

private void goBack() {
Expand All @@ -329,4 +340,10 @@ private void takeScreenshot() {
broadcast.setAction(Constants.ACTION_SCREENSHOT);
mContext.sendBroadcast(broadcast);
}

private void goHome() {
Intent broadcast = new Intent();
broadcast.setAction(Constants.ACTION_HOME);
mContext.sendBroadcast(broadcast);
}
}

0 comments on commit b0580bb

Please sign in to comment.