Skip to content

Commit

Permalink
[优化] 底层代码修改 [修正] 磁贴在部分设备无法使用的bug (#9)
Browse files Browse the repository at this point in the history
Signed-off-by: HChenX <[email protected]>
  • Loading branch information
HChenX authored Oct 31, 2023
1 parent 010c485 commit dcc829b
Show file tree
Hide file tree
Showing 57 changed files with 753 additions and 805 deletions.
1 change: 1 addition & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
-keep class com.sevtinge.hyperceiler.utils.Helpers{boolean isModuleActive;}
-keep class com.sevtinge.hyperceiler.utils.Helpers{int XposedVersion;}
-keep class * extends com.sevtinge.hyperceiler.module.base.BaseHook
-keep class * extends com.sevtinge.hyperceiler.utils.hook.HookUtils
-keep class com.sevtinge.hyperceiler.ui.HideAppActivity
-keep class * extends com.sevtinge.hyperceiler.ui.fragment.base.*
-keep class miui.drm.**{*;}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import android.view.KeyEvent;

import com.sevtinge.hyperceiler.module.base.BaseHook;
import com.sevtinge.hyperceiler.utils.Helpers;
import com.sevtinge.hyperceiler.utils.PrefsUtils;

import de.robv.android.xposed.XposedHelpers;
Expand Down Expand Up @@ -52,11 +51,6 @@ protected void after(MethodHookParam param) {
});
}

public static void proxySystemProperties(String method, String prop, String val, ClassLoader classLoader) {
XposedHelpers.callStaticMethod(XposedHelpers.findClassIfExists("android.os.SystemProperties", classLoader),
method, prop, val);
}

@SuppressLint("UnsafeIntentLaunch")
private final BroadcastReceiver mGlobalReceiver = new BroadcastReceiver() {
@Override
Expand All @@ -70,8 +64,8 @@ public void onReceive(Context context, Intent intent) {
switch (action) {
case ACTION_PREFIX + "ToggleColorInversion" -> {
int opt = Settings.Secure.getInt(context.getContentResolver(), "accessibility_display_inversion_enabled");
int conflictProp = (int) Helpers.proxySystemProperties("getInt", "ro.df.effect.conflict", 0, null);
int conflictProp2 = (int) Helpers.proxySystemProperties("getInt", "ro.vendor.df.effect.conflict", 0, null);
int conflictProp = (int) proxySystemProperties("getInt", "ro.df.effect.conflict", 0, null);
int conflictProp2 = (int) proxySystemProperties("getInt", "ro.vendor.df.effect.conflict", 0, null);
boolean hasConflict = conflictProp == 1 || conflictProp2 == 1;
Object dfMgr = XposedHelpers.callStaticMethod(XposedHelpers.findClass("miui.hardware.display.DisplayFeatureManager", null), "getInstance");
if (hasConflict && opt == 0) {
Expand Down
222 changes: 3 additions & 219 deletions app/src/main/java/com/sevtinge/hyperceiler/module/base/BaseHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,14 @@

import com.sevtinge.hyperceiler.XposedInit;
import com.sevtinge.hyperceiler.utils.ResourcesHook;
import com.sevtinge.hyperceiler.utils.log.XposedLogUtils;
import com.sevtinge.hyperceiler.utils.hook.HookUtils;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;

public abstract class BaseHook extends XposedLogUtils {
public abstract class BaseHook extends HookUtils {
public String TAG = getClass().getSimpleName();

public LoadPackageParam lpparam;
public static final ResourcesHook mResHook = XposedInit.mResHook;

public static final String ACTION_PREFIX = "com.sevtinge.hyperceiler.module.action.";

public abstract void init();
Expand All @@ -34,216 +26,8 @@ public void onCreate(LoadPackageParam lpparam) {
}
}

@Override
public void setLoadPackageParam(LoadPackageParam param) {
lpparam = param;
}

public Class<?> findClass(String className) {
return findClass(className, lpparam.classLoader);
}

public Class<?> findClass(String className, ClassLoader classLoader) {
return XposedHelpers.findClass(className, classLoader);
}

public Class<?> findClassIfExists(String className) {
try {
return findClass(className);
} catch (XposedHelpers.ClassNotFoundError e) {
logE("findClassIfExists", "find " + className + " is Null: " + e);
return null;
}
}

public Class<?> findClassIfExists(String newClassName, String oldClassName) {
try {
return findClass(findClassIfExists(newClassName) != null ? newClassName : oldClassName);
} catch (XposedHelpers.ClassNotFoundError e) {
logE("findClassIfExists", "find " + newClassName + " and " + oldClassName + " is Null: " + e);
return null;
}
}

public Class<?> findClassIfExists(String className, ClassLoader classLoader) {
try {
return findClass(className, classLoader);
} catch (XposedHelpers.ClassNotFoundError e) {
logE("findClassIfExists", "find " + className + " is Null: " + e);
return null;
}
}

public static class MethodHook extends XC_MethodHook {

protected void before(MethodHookParam param) throws Throwable {
}

protected void after(MethodHookParam param) throws Throwable {
}

public MethodHook() {
super();
}

public MethodHook(int priority) {
super(priority);
}


@Override
public void beforeHookedMethod(MethodHookParam param) throws Throwable {
try {
this.before(param);
} catch (Throwable t) {
logE("BeforeHook", t);
}
}

@Override
public void afterHookedMethod(MethodHookParam param) throws Throwable {
try {
this.after(param);
} catch (Throwable t) {
logE("AfterHook", t);
}
}
}


public void findAndHookMethod(Class<?> clazz, String methodName, Object... parameterTypesAndCallback) {
XposedHelpers.findAndHookMethod(clazz, methodName, parameterTypesAndCallback);
}

public void findAndHookMethod(String className, String methodName, Object... parameterTypesAndCallback) {
findAndHookMethod(findClassIfExists(className), methodName, parameterTypesAndCallback);
}

public boolean findAndHookMethodSilently(String className, String methodName, Object... parameterTypesAndCallback) {
try {
findAndHookMethod(className, methodName, parameterTypesAndCallback);
return true;
} catch (Throwable t) {
logE("findAndHookMethodSilently", className + methodName + " is null: " + t);
return false;
}
}

public boolean findAndHookMethodSilently(Class<?> clazz, String methodName, Object... parameterTypesAndCallback) {
try {
findAndHookMethod(clazz, methodName, parameterTypesAndCallback);
return true;
} catch (Throwable t) {
logE("findAndHookMethodSilently", clazz + methodName + " is null: " + t);
return false;
}
}

public void findAndHookConstructor(String className, Object... parameterTypesAndCallback) {
findAndHookConstructor(findClassIfExists(className), parameterTypesAndCallback);
}

public void findAndHookConstructor(Class<?> hookClass, Object... parameterTypesAndCallback) {
XposedHelpers.findAndHookConstructor(hookClass, parameterTypesAndCallback);
}

public void hookMethod(Method method, MethodHook callback) {
XposedBridge.hookMethod(method, callback);
}

public void hookAllMethods(String className, String methodName, XC_MethodHook callback) {
try {
Class<?> hookClass = findClassIfExists(className);
if (hookClass != null) {
XposedBridge.hookAllMethods(hookClass, methodName, callback).size();
}

} catch (Throwable t) {
logE("HookAllMethods", className + " is " + methodName + " abnormal: " + t);
}
}

public void hookAllMethods(Class<?> hookClass, String methodName, XC_MethodHook callback) {
try {
XposedBridge.hookAllMethods(hookClass, methodName, callback).size();
} catch (Throwable t) {
logE("HookAllMethods", hookClass + " is " + methodName + " abnormal: " + t);
}
}

public void hookAllMethodsSilently(String className, String methodName, XC_MethodHook callback) {
try {
Class<?> hookClass = findClassIfExists(className);
if (hookClass != null) {
XposedBridge.hookAllMethods(hookClass, methodName, callback).size();
}
} catch (Throwable ignored) {
}
}

public boolean hookAllMethodsSilently(Class<?> hookClass, String methodName, XC_MethodHook callback) {
try {
if (hookClass != null) {
XposedBridge.hookAllMethods(hookClass, methodName, callback).size();
}
return false;
} catch (Throwable t) {
return false;
}
}

public void hookAllConstructors(String className, MethodHook callback) {
try {
Class<?> hookClass = findClassIfExists(className);
if (hookClass != null) {
XposedBridge.hookAllConstructors(hookClass, callback).size();
}
} catch (Throwable t) {
logE("hookAllConstructors", className + " is abnormal: " + t);
}
}

public void hookAllConstructors(Class<?> hookClass, MethodHook callback) {
try {
XposedBridge.hookAllConstructors(hookClass, callback).size();
} catch (Throwable t) {
logE("hookAllConstructors", hookClass + " is abnormal: " + t);
}
}


public Object getStaticObjectFieldSilently(Class<?> clazz, String fieldName) {
try {
return XposedHelpers.getStaticObjectField(clazz, fieldName);
} catch (Throwable t) {
return null;
}
}

public void setDeclaredField(XC_MethodHook.MethodHookParam param, String iNeedString, Object iNeedTo) {
if (param != null) {
try {
Field setString = param.thisObject.getClass().getDeclaredField(iNeedString);
setString.setAccessible(true);
try {
setString.set(param.thisObject, iNeedTo);
Object result = setString.get(param.thisObject);
checkLast("getDeclaredField", iNeedString, iNeedTo, result);
} catch (IllegalAccessException e) {
logE("IllegalAccessException to: " + iNeedString + " need to: " + iNeedTo + " code: " + e);
}
} catch (NoSuchFieldException e) {
logE("No such the: " + iNeedString + " code: " + e);
}
} else {
logE("Param is null Field: " + iNeedString + " to: " + iNeedTo);
}
}

public void checkLast(String setObject, Object fieldName, Object value, Object last) {
if (value.equals(last)) {
logI(setObject + " Success! set " + fieldName + " to " + value);
} else {
logE(setObject + " Failed! set " + fieldName + " to " + value + " hope: " + value + " but: " + last);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import com.sevtinge.hyperceiler.module.base.BaseHook;

import de.robv.android.xposed.XC_MethodReplacement;

public class FreeFormCountForHome extends BaseHook {

Class<?> mRecentsAndFSGesture;
Expand All @@ -14,10 +12,10 @@ public void init() {

hookAllMethods(mRecentsAndFSGesture,
"canTaskEnterMiniSmallWindow",
XC_MethodReplacement.returnConstant(true));
MethodHook.returnConstant(true));

hookAllMethods(mRecentsAndFSGesture,
"canTaskEnterSmallWindow",
XC_MethodReplacement.returnConstant(true));
MethodHook.returnConstant(true));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.sevtinge.hyperceiler.module.hook.home.gesture;

import static com.sevtinge.hyperceiler.utils.Helpers.findAndHookMethodUseUnhook;

import android.content.Context;
import android.os.Bundle;
Expand All @@ -14,20 +13,22 @@
public class SwipeAndStop extends BaseHook {
@Override
public void init() {
Class<?> VibratorCls = findClassIfExists("android.os.Vibrator", lpparam.classLoader);
hookAllMethods("com.miui.home.recents.GestureBackArrowView", "setReadyFinish", new MethodHook() {
private Unhook vibratorHook = null;
@Override
protected void before(MethodHookParam param) throws Throwable {
vibratorHook = findAndHookMethodUseUnhook(VibratorCls, "vibrate", long.class, XC_MethodReplacement.DO_NOTHING);
}
@Override
protected void after(MethodHookParam param) throws Throwable {
if (vibratorHook != null) {
vibratorHook.unhook();
}
Class<?> VibratorCls = findClassIfExists("android.os.Vibrator", lpparam.classLoader);
hookAllMethods("com.miui.home.recents.GestureBackArrowView", "setReadyFinish", new MethodHook() {
private Unhook vibratorHook = null;

@Override
protected void before(MethodHookParam param) throws Throwable {
vibratorHook = findAndHookMethodUseUnhook(VibratorCls, "vibrate", long.class, XC_MethodReplacement.DO_NOTHING);
}

@Override
protected void after(MethodHookParam param) throws Throwable {
if (vibratorHook != null) {
vibratorHook.unhook();
}
});
}
});

findAndHookMethod("com.miui.home.recents.GestureStubView", "disableQuickSwitch", boolean.class, new MethodHook() {
@Override
Expand All @@ -36,14 +37,14 @@ protected void before(MethodHookParam param) throws Throwable {
}
});
findAndHookMethod("com.miui.home.recents.GestureStubView", "isDisableQuickSwitch", XC_MethodReplacement.returnConstant(false));
findAndHookMethod("com.miui.home.recents.GestureStubView","getNextTask", Context.class, boolean.class, int.class, new MethodHook() {
findAndHookMethod("com.miui.home.recents.GestureStubView", "getNextTask", Context.class, boolean.class, int.class, new MethodHook() {
@Override
protected void before(MethodHookParam param) throws Throwable {
boolean switchApp = (boolean) param.args[1];
if (switchApp) {
Context mContext = (Context) param.args[0];
Bundle bundle = new Bundle();
bundle.putInt("inDirection", (int)param.args[2]);
bundle.putInt("inDirection", (int) param.args[2]);
if (GlobalActions.handleAction(mContext, "pref_key_controls_fsg_swipeandstop")) {
Class<?> Task = findClassIfExists("com.android.systemui.shared.recents.model.Task", lpparam.classLoader);
param.setResult(XposedHelpers.newInstance(Task));
Expand Down
Loading

0 comments on commit dcc829b

Please sign in to comment.