Skip to content

Commit 87708e4

Browse files
committed
opt codes
1 parent 10eaf3d commit 87708e4

11 files changed

Lines changed: 214 additions & 313 deletions

File tree

library/libhook/src/main/java/com/sevtinge/hyperceiler/libhook/rules/gallery/ChangeBackupServer.java

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -27,35 +27,39 @@
2727

2828

2929
public class ChangeBackupServer extends BaseHook {
30+
private static final ThreadLocal<Boolean> sOverrideIsInternational = new ThreadLocal<>();
31+
3032
@Override
3133
public void init() {
3234
int backupServer = PrefsBridge.getStringAsInt("gallery_backup_server", 0);
3335
boolean isXiaomi = backupServer == 1;
3436
boolean isGoogle = backupServer == 2;
3537
boolean isOneDrive = backupServer == 3;
3638

37-
if (isOneDrive) {
38-
findAndHookMethod("com.miui.gallery.ui.GallerySettingsFragment", "initGlobalBackupPreference", new IMethodHook() {
39-
XposedInterface.HookHandle isInternationalHook;
40-
41-
@Override
42-
public void before(HookParam param) {
43-
isInternationalHook = findAndHookMethod("com.miui.gallery.util.BaseBuildUtil", "isInternational", new IMethodHook() {
44-
@Override
45-
public void before(HookParam param) {
46-
param.setResult(true);
47-
}
48-
});
39+
if (isOneDrive || isXiaomi) {
40+
findAndChainMethod("com.miui.gallery.util.BaseBuildUtil", "isInternational",
41+
chain -> {
42+
Boolean override = sOverrideIsInternational.get();
43+
if (override != null) {
44+
return override;
45+
}
46+
return chain.proceed();
4947
}
48+
);
49+
}
5050

51-
@Override
52-
public void after(HookParam param) {
53-
if (isInternationalHook != null) {
54-
isInternationalHook.unhook();
55-
isInternationalHook = null;
51+
if (isOneDrive) {
52+
findAndChainMethod("com.miui.gallery.ui.GallerySettingsFragment",
53+
"initGlobalBackupPreference",
54+
chain -> {
55+
sOverrideIsInternational.set(true);
56+
try {
57+
return chain.proceed();
58+
} finally {
59+
sOverrideIsInternational.remove();
5660
}
5761
}
58-
});
62+
);
5963
findAndHookMethod("com.miui.gallery.util.PhotoModelTypeUtil", "isSupportOneDrive", new IMethodHook() {
6064
@Override
6165
public void before(HookParam param) {
@@ -64,27 +68,17 @@ public void before(HookParam param) {
6468
});
6569
} else {
6670
if (isXiaomi) {
67-
findAndHookMethod("com.miui.gallery.ui.GallerySettingsFragment", "initGlobalBackupPreference", new IMethodHook() {
68-
XposedInterface.HookHandle isInternationalHook;
69-
70-
@Override
71-
public void before(HookParam param) {
72-
isInternationalHook = findAndHookMethod("com.miui.gallery.util.BaseBuildUtil", "isInternational", new IMethodHook() {
73-
@Override
74-
public void before(HookParam param) {
75-
param.setResult(false);
76-
}
77-
});
78-
}
79-
80-
@Override
81-
public void after(HookParam param) {
82-
if (isInternationalHook != null) {
83-
isInternationalHook.unhook();
84-
isInternationalHook = null;
71+
findAndChainMethod("com.miui.gallery.ui.GallerySettingsFragment",
72+
"initGlobalBackupPreference",
73+
(XposedInterface.Hooker) chain -> {
74+
sOverrideIsInternational.set(false);
75+
try {
76+
return chain.proceed();
77+
} finally {
78+
sOverrideIsInternational.remove();
8579
}
8680
}
87-
});
81+
);
8882
}
8983
try {
9084
findAndHookMethod("com.miui.gallery.transfer.GoogleSyncHelper", "isCloudServiceOffLine", new IMethodHook() {

library/libhook/src/main/java/com/sevtinge/hyperceiler/libhook/rules/gallery/EnablePdf.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@
2222
import com.sevtinge.hyperceiler.libhook.callback.IMethodHook;
2323

2424
import io.github.kyuubiran.ezxhelper.xposed.common.HookParam;
25-
import io.github.libxposed.api.XposedInterface;
2625

2726
public class EnablePdf extends BaseHook {
28-
XposedInterface.HookHandle isGlobal;
27+
private static final ThreadLocal<Boolean> sBypassIsGlobal = new ThreadLocal<>();
2928

3029
@Override
3130
public void init() {
@@ -37,23 +36,24 @@ public void before(HookParam param) {
3736
}
3837
});
3938
} catch (Throwable e) {
40-
hookAllConstructors("com.miui.gallery.ui.ProduceCreationDialogWithMediaEditorConfig", new IMethodHook() {
39+
findAndChainMethod("com.miui.gallery.util.BuildUtil", "isGlobal",
40+
chain -> {
41+
if (Boolean.TRUE.equals(sBypassIsGlobal.get())) {
42+
return false;
43+
}
44+
return chain.proceed();
45+
}
46+
);
47+
48+
hookAllConstructors("com.miui.gallery.ui.ProduceCreationDialogWithMediaEditorConfig", new IMethodHook() {
4149
@Override
4250
public void before(HookParam param) {
43-
isGlobal = findAndHookMethod("com.miui.gallery.util.BuildUtil", "isGlobal", new IMethodHook() {
44-
@Override
45-
public void before(HookParam param) {
46-
param.setResult(false);
47-
}
48-
});
51+
sBypassIsGlobal.set(true);
4952
}
5053

5154
@Override
5255
public void after(HookParam param) {
53-
if (isGlobal != null) {
54-
isGlobal.unhook();
55-
}
56-
isGlobal = null;
56+
sBypassIsGlobal.remove();
5757
}
5858
});
5959
}

library/libhook/src/main/java/com/sevtinge/hyperceiler/libhook/rules/home/ToastSlideAgain.java

Lines changed: 23 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -21,65 +21,45 @@
2121
import android.view.MotionEvent;
2222

2323
import com.sevtinge.hyperceiler.libhook.base.BaseHook;
24-
import com.sevtinge.hyperceiler.libhook.callback.IMethodHook;
2524

26-
import io.github.kyuubiran.ezxhelper.xposed.common.HookParam;
27-
import io.github.libxposed.api.XposedInterface.HookHandle;
25+
import io.github.libxposed.api.XposedInterface;
2826

2927
public class ToastSlideAgain extends BaseHook {
30-
public HookHandle unhook = null;
28+
private static final ThreadLocal<Boolean> sSuppressToast = new ThreadLocal<>();
3129

3230
@Override
3331
public void init() {
34-
findAndHookMethod("com.miui.home.recents.NavStubView",
35-
"onPointerEvent", MotionEvent.class,
36-
new IMethodHook() {
37-
@Override
38-
public void before(HookParam param) {
39-
unhook = hookToast();
40-
// logI("im hook onPointerEvent");
41-
}
42-
43-
@Override
44-
public void after(HookParam param) {
45-
unHook(unhook);
32+
findAndChainMethod(findClassIfExists("android.widget.Toast"), "show",
33+
chain -> {
34+
if (Boolean.TRUE.equals(sSuppressToast.get())) {
35+
return null;
4636
}
37+
return chain.proceed();
4738
}
4839
);
4940

50-
findAndHookMethod("com.miui.home.recents.GestureModeApp",
51-
"onStartGesture", new IMethodHook() {
52-
@Override
53-
public void before(HookParam param) {
54-
unhook = hookToast();
55-
// logI("im hook onStartGesture");
56-
}
57-
58-
@Override
59-
public void after(HookParam param) {
60-
unHook(unhook);
41+
findAndChainMethod("com.miui.home.recents.NavStubView",
42+
"onPointerEvent", MotionEvent.class,
43+
(XposedInterface.Hooker) chain -> {
44+
sSuppressToast.set(true);
45+
try {
46+
return chain.proceed();
47+
} finally {
48+
sSuppressToast.remove();
6149
}
6250
}
6351
);
64-
}
6552

66-
public HookHandle hookToast() {
67-
return findAndHookMethod(findClassIfExists("android.widget.Toast"),
68-
"show", new IMethodHook() {
69-
@Override
70-
public void before(HookParam param) {
71-
param.setResult(null);
72-
// logI("im hook Toast show");
53+
findAndChainMethod("com.miui.home.recents.GestureModeApp",
54+
"onStartGesture",
55+
chain -> {
56+
sSuppressToast.set(true);
57+
try {
58+
return chain.proceed();
59+
} finally {
60+
sSuppressToast.remove();
7361
}
7462
}
7563
);
7664
}
77-
78-
public void unHook(HookHandle unhook) {
79-
if (unhook != null) {
80-
unhook.unhook();
81-
// logI("the unhook is: " + unhook);
82-
} // logE("the unhook is: null");
83-
84-
}
8565
}

library/libhook/src/main/java/com/sevtinge/hyperceiler/libhook/rules/home/folder/FolderAnimation.kt

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ package com.sevtinge.hyperceiler.libhook.rules.home.folder
2020

2121
import com.sevtinge.hyperceiler.common.utils.PrefsBridge
2222
import com.sevtinge.hyperceiler.libhook.base.BaseHook
23-
import com.sevtinge.hyperceiler.libhook.utils.hookapi.tool.afterHookMethod
24-
import com.sevtinge.hyperceiler.libhook.utils.hookapi.tool.beforeHookMethod
25-
import io.github.kyuubiran.ezxhelper.core.finder.MethodFinder.`-Static`.methodFinder
23+
import com.sevtinge.hyperceiler.libhook.utils.hookapi.tool.chainMethod
2624
import io.github.kyuubiran.ezxhelper.core.util.ClassUtil.loadClassOrNull
27-
import io.github.kyuubiran.ezxhelper.xposed.dsl.HookFactory.`-Static`.createHook
28-
import io.github.libxposed.api.XposedInterface.HookHandle
2925
import kotlin.math.abs
3026

3127
class FolderAnimation : BaseHook() {
28+
companion object {
29+
private val sOverrideDampingResponse = ThreadLocal<FloatArray>()
30+
}
31+
3232
var mLauncher: Class<*>? = null
3333
private var value1: Float? = null
3434
private var value2: Float? = null
@@ -41,8 +41,17 @@ class FolderAnimation : BaseHook() {
4141
value3 = abs(PrefsBridge.getInt("home_folder_anim_3", 99).toFloat() - 200) / 100
4242
value4 = PrefsBridge.getInt("home_folder_anim_4", 24).toFloat() / 100
4343
val mSpringAnimator = findClassIfExists("com.miui.home.launcher.animate.SpringAnimator")
44-
var hook1: HookHandle? = null
45-
var hook2: HookHandle? = null
44+
45+
mSpringAnimator.chainMethod(
46+
"setDampingResponse"
47+
) {
48+
val override = sOverrideDampingResponse.get()
49+
if (override != null) {
50+
args[0] = override[0]
51+
args[1] = override[1]
52+
}
53+
proceed()
54+
}
4655

4756
for (i in 47..60) {
4857
val launcherClass = findClassIfExists("com.miui.home.launcher.Launcher$$i")
@@ -56,47 +65,33 @@ class FolderAnimation : BaseHook() {
5665
if (child.name != $$"val$folderInfo")
5766
continue
5867

59-
mLauncherClass.methodFinder()
60-
.filterByName("run")
61-
.first().createHook {
62-
before {
63-
hook1 = mSpringAnimator.methodFinder()
64-
.filterByName("setDampingResponse")
65-
.filterByParamTypes {
66-
it[0] == Float::class.javaPrimitiveType &&
67-
it[1] == Float::class.javaPrimitiveType
68-
}.single().createHook {
69-
before {
70-
it.args[0] = value1
71-
it.args[1] = value2
72-
}
73-
}
74-
}
75-
after {
76-
hook1?.unhook()
77-
}
68+
mLauncherClass.chainMethod("run") {
69+
sOverrideDampingResponse.set(floatArrayOf(value1!!, value2!!))
70+
try {
71+
proceed()
72+
} finally {
73+
sOverrideDampingResponse.remove()
7874
}
75+
}
7976
break
8077
}
8178
}
8279
}
8380
}
8481
}
8582

86-
findClass("com.miui.home.launcher.Launcher").beforeHookMethod("closeFolder", Boolean::class.java) {
87-
if (it.args[0] == true) {
88-
hook2 = mSpringAnimator.beforeHookMethod(
89-
"setDampingResponse",
90-
Float::class.java,
91-
Float::class.java
92-
) { hookParam ->
93-
hookParam.args[0] = value3
94-
hookParam.args[1] = value4
95-
}
83+
findClass("com.miui.home.launcher.Launcher").chainMethod(
84+
"closeFolder",
85+
Boolean::class.java
86+
) {
87+
if (args[0] == true) {
88+
sOverrideDampingResponse.set(floatArrayOf(value3!!, value4!!))
89+
}
90+
try {
91+
proceed()
92+
} finally {
93+
sOverrideDampingResponse.remove()
9694
}
97-
}
98-
findClass("com.miui.home.launcher.Launcher").afterHookMethod("closeFolder", Boolean::class.java) {
99-
hook2?.unhook()
10095
}
10196

10297
}

library/libhook/src/main/java/com/sevtinge/hyperceiler/libhook/rules/home/gesture/SwipeAndStop.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,27 @@
3232
import io.github.libxposed.api.XposedInterface;
3333

3434
public class SwipeAndStop extends BaseHook {
35+
private static final ThreadLocal<Boolean> sSuppressVibrate = new ThreadLocal<>();
36+
3537
@Override
3638
public void init() {
3739
Class<?> VibratorCls = findClassIfExists("android.os.Vibrator");
38-
hookAllMethods("com.miui.home.recents.GestureBackArrowView", "setReadyFinish", new IMethodHook() {
39-
private XposedInterface.HookHandle vibratorHook = null;
40-
41-
@Override
42-
public void before(HookParam param) {
43-
vibratorHook = findAndHookMethod(VibratorCls, "vibrate", long.class, doNothing());
40+
findAndChainMethod(VibratorCls, "vibrate", long.class,
41+
(XposedInterface.Hooker) chain -> {
42+
if (Boolean.TRUE.equals(sSuppressVibrate.get())) {
43+
return null;
44+
}
45+
return chain.proceed();
4446
}
47+
);
4548

46-
@Override
47-
public void after(HookParam param) {
48-
if (vibratorHook != null) {
49-
vibratorHook.unhook();
50-
}
49+
chainAllMethods("com.miui.home.recents.GestureBackArrowView", "setReadyFinish", chain -> {
50+
sSuppressVibrate.set(true);
51+
52+
try {
53+
return chain.proceed();
54+
} finally {
55+
sSuppressVibrate.remove();
5156
}
5257
});
5358

0 commit comments

Comments
 (0)