Skip to content

Commit

Permalink
[Refactor] Wrap XposedHelpers for catching exceptions.
Browse files Browse the repository at this point in the history
[Fix] Bug fixes: dual mobile signal invalid issue before 9.5.7.
  • Loading branch information
tianma8023 committed May 27, 2019
1 parent 5f4a190 commit c5edfd9
Show file tree
Hide file tree
Showing 15 changed files with 622 additions and 660 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ android {
minSdkVersion 21
targetSdkVersion 27
versionCode 8
versionName "1.0.7"
versionName "1.0.8 beta"

buildConfigField("String", "LOG_TAG", "\"XMiuiClock\"")
buildConfigField("boolean", "LOG_TO_XPOSED", "true")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
import com.tianma.tweaks.miui.BuildConfig;
import com.tianma.tweaks.miui.utils.ModuleUtils;
import com.tianma.tweaks.miui.utils.XLog;
import com.tianma.tweaks.miui.xp.wrapper.MethodHookWrapper;

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

import static com.tianma.tweaks.miui.xp.wrapper.XposedWrapper.findAndHookMethod;

/**
* Hook class com.github.tianma8023.xposed.smscode.utils.ModuleUtils
*/
Expand All @@ -32,11 +33,11 @@ public void onLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwa
private void hookModuleUtils(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
String className = ModuleUtils.class.getName();

XposedHelpers.findAndHookMethod(className, lpparam.classLoader,
findAndHookMethod(className, lpparam.classLoader,
"isModuleActive",
new XC_MethodHook() {
new MethodHookWrapper() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
protected void before(MethodHookParam param) {
param.setResult(true);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
import com.tianma.tweaks.miui.utils.XLog;
import com.tianma.tweaks.miui.utils.XSPUtils;
import com.tianma.tweaks.miui.xp.hook.BaseSubHook;
import com.tianma.tweaks.miui.xp.wrapper.MethodHookWrapper;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XSharedPreferences;
import de.robv.android.xposed.XposedHelpers;

import static com.tianma.tweaks.miui.xp.wrapper.XposedWrapper.findAndHookMethod;

public class WorkSpaceHook extends BaseSubHook {

private static final String CLASS_WORK_SPACE = "com.miui.home.launcher.Workspace";

private boolean mAlwaysShowStatusBarClock;

public WorkSpaceHook(ClassLoader classLoader, XSharedPreferences xsp) {
super(classLoader, xsp);

Expand All @@ -34,13 +35,13 @@ public void startHook() {

// #isScreenHasClockGadget()
private void hookIsScreenHasClockGadgets() {
XposedHelpers.findAndHookMethod(CLASS_WORK_SPACE,
findAndHookMethod(CLASS_WORK_SPACE,
mClassLoader,
"isScreenHasClockGadget",
long.class,
new XC_MethodHook() {
new MethodHookWrapper() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
protected void before(MethodHookParam param) {
param.setResult(false);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void onLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwa
new KeyguardClockContainerHook(classLoader, xsp).startHook();

new CollapsedStatusBarFragmentHook(classLoader, xsp, miuiVersion).startHook();
new SignalClusterViewHook(classLoader, xsp).startHook();
new SignalClusterViewHook(classLoader, xsp, miuiVersion).startHook();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
import com.tianma.tweaks.miui.utils.XLog;
import com.tianma.tweaks.miui.utils.XSPUtils;
import com.tianma.tweaks.miui.xp.hook.BaseSubHook;
import com.tianma.tweaks.miui.xp.wrapper.MethodHookWrapper;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XSharedPreferences;
import de.robv.android.xposed.XposedHelpers;

import static com.tianma.tweaks.miui.xp.wrapper.XposedWrapper.findAndHookMethod;

/**
* MIUI设置页面 - 选择锁屏时钟界面 Hook
Expand Down Expand Up @@ -45,19 +46,15 @@ public void startHook() {

// com.android.keyguard.setting.ChooseKeyguardClockActivity#onStop()
private void hookOnStop() {
XposedHelpers.findAndHookMethod(CLASS_CHOOSE_KEYGUARD_CLOCK_ACTIVITY,
findAndHookMethod(CLASS_CHOOSE_KEYGUARD_CLOCK_ACTIVITY,
mClassLoader,
"onStop",
new XC_MethodHook() {
new MethodHookWrapper() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
try {
Context context = (Context) param.thisObject;
Intent intent = new Intent(IntentAction.KEYGUARD_STOP_TIME_TICK);
context.sendBroadcast(intent);
} catch (Throwable t) {
XLog.e("", t);
}
protected void before(MethodHookParam param) {
Context context = (Context) param.thisObject;
Intent intent = new Intent(IntentAction.KEYGUARD_STOP_TIME_TICK);
context.sendBroadcast(intent);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
import com.tianma.tweaks.miui.utils.XLog;
import com.tianma.tweaks.miui.utils.XSPUtils;
import com.tianma.tweaks.miui.xp.hook.BaseSubHook;
import com.tianma.tweaks.miui.xp.wrapper.MethodHookWrapper;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XSharedPreferences;
import de.robv.android.xposed.XposedHelpers;

import static com.tianma.tweaks.miui.xp.wrapper.XposedWrapper.findAndHookMethod;
import static de.robv.android.xposed.XposedHelpers.callMethod;
import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;
import static de.robv.android.xposed.XposedHelpers.findClass;
import static de.robv.android.xposed.XposedHelpers.getObjectField;
import static de.robv.android.xposed.XposedHelpers.getStaticObjectField;
Expand Down Expand Up @@ -60,40 +60,36 @@ public void startHook() {
private void hookOnAttachedToWindow() {
findAndHookMethod(mKeyguardClockContainerClass,
"onAttachedToWindow",
new XC_MethodHook() {
new MethodHookWrapper() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
try {
FrameLayout clockContainer = (FrameLayout) param.thisObject;
ViewParent parent = clockContainer.getParent();
XposedHelpers.callMethod(parent, "onAttachedToWindow");

IntentFilter filter = new IntentFilter();
// filter.addAction("android.intent.action.TIME_TICK");
filter.addAction("android.intent.action.TIME_SET");
filter.addAction("android.intent.action.TIMEZONE_CHANGED");

BroadcastReceiver mIntentReceiver = (BroadcastReceiver) getObjectField(clockContainer, "mIntentReceiver");
Object USER_HANDLE_ALL = getStaticObjectField(UserHandle.class, "ALL");
Class<?> dependencyClass = findClass(CLASS_DEPENDENCY, mClassLoader);
Object TIME_TICK_HANDLER = getStaticObjectField(dependencyClass, "TIME_TICK_HANDLER");
Object handler = XposedHelpers.callStaticMethod(dependencyClass, "get", TIME_TICK_HANDLER);

callMethod(clockContainer.getContext(),
"registerReceiverAsUser",
mIntentReceiver,
USER_HANDLE_ALL,
filter,
null,
handler);

callMethod(clockContainer, "registerDualClockObserver");
callMethod(clockContainer, "registerClockPositionObserver");

param.setResult(null);
} catch (Throwable t) {
XLog.e("", t);
}
protected void before(MethodHookParam param) {
FrameLayout clockContainer = (FrameLayout) param.thisObject;
ViewParent parent = clockContainer.getParent();
XposedHelpers.callMethod(parent, "onAttachedToWindow");

IntentFilter filter = new IntentFilter();
// filter.addAction("android.intent.action.TIME_TICK");
filter.addAction("android.intent.action.TIME_SET");
filter.addAction("android.intent.action.TIMEZONE_CHANGED");

BroadcastReceiver mIntentReceiver = (BroadcastReceiver) getObjectField(clockContainer, "mIntentReceiver");
Object USER_HANDLE_ALL = getStaticObjectField(UserHandle.class, "ALL");
Class<?> dependencyClass = findClass(CLASS_DEPENDENCY, mClassLoader);
Object TIME_TICK_HANDLER = getStaticObjectField(dependencyClass, "TIME_TICK_HANDLER");
Object handler = XposedHelpers.callStaticMethod(dependencyClass, "get", TIME_TICK_HANDLER);

callMethod(clockContainer.getContext(),
"registerReceiverAsUser",
mIntentReceiver,
USER_HANDLE_ALL,
filter,
null,
handler);

callMethod(clockContainer, "registerDualClockObserver");
callMethod(clockContainer, "registerClockPositionObserver");

param.setResult(null);
}
});
}
Expand Down
Loading

0 comments on commit c5edfd9

Please sign in to comment.