Xposed-我可以打印内部类方法,但是方法挂钩不起作用

时间:2019-09-17 04:15:01

标签: android xposed

我试图将一个方法挂接到内部类中,但是什么也没发生,尽管我可以打印该类的所有方法。

所有打印的日志,除了replaceHookedMethod中。

public class Keyguard implements IXposedHookLoadPackage {

    @Override
    public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {

        if (!lpparam.packageName.equals("com.android.keyguard"))
            return;
        XposedBridge.log("we are in keyguard!");

        Class HwClockView = XposedHelpers.findClass("com.android.keyguard.AbsClockView$HwClockView",
                lpparam.classLoader);
        for (Method m : HwClockView.getDeclaredMethods()) {
            XposedBridge.log("method: " + m.getName());
        }

        XposedHelpers.findAndHookMethod(HwClockView, "getDateString",
                TimeZone.class, new XC_MethodReplacement() {
            @Override
            protected Object replaceHookedMethod(MethodHookParam param) throws Throwable {
                XposedBridge.log("we are in getDateString!");
                return String.format("%s", Utils.getPersianDateShort());
            }
        });
}

更新: 在第二次注释之后,将代码更改为此,但是与之前没有任何反应一样:

public class Keyguard implements IXposedHookLoadPackage {

    @Override
    public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) {

        if (!lpparam.packageName.equals("com.android.keyguard"))
            return;
        XposedBridge.log("we are in keyguard!");

        Class HwClockView = XposedHelpers.findClass("com.android.keyguard.AbsClockView$HwClockView",
                lpparam.classLoader);
        for (Method m : HwClockView.getDeclaredMethods()) {
            XposedBridge.log("method: " + m.getName());
            if ("getDateString".equalsIgnoreCase(m.getName())) {
                XposedBridge.hookMethod(m, new XC_MethodReplacement() {
                    @Override
                    protected Object replaceHookedMethod(MethodHookParam param) {
                        XposedBridge.log("we are in getDateString!");
                        return String.format("%s", Utils.getPersianDateShort());
                    }
                });
            }
        }
}

目标类别:

public class AbsClockView extends RelativeLayout {
    protected Calendar mCalendar;
    private HwCustKeyguardStatusViewEx mCustKeyguardStatusViewEx;
    protected TextView mDateView;
    protected TextView mDescriptionView;
    protected Factory mFactory;
    protected final AtomicBoolean mFixedTimeZone;
    protected FrameLayout mTimeParent;
    protected TextView mTimeView;

    public interface Factory {
        void refreshDate();

        void setHwDateFormat();

        void updateHwTimeStyle();
    }

    private class HwClockView implements Factory {
        protected Context mContext;

        public HwClockView(Context context) {
            ...
        }

        private CharSequence getDateString(TimeZone timeZone) {
            return someString;
        }
    }

    public AbsClockView(Context context) {
        this(context, null);
    }
}

0 个答案:

没有答案