5

我正在尝试制作一个 Xposed 模块。我首先阅读了一个教程,其中有操作时钟的说明。代码如下:

package de.robv.android.xposed.mods.tutorial;

import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;
import android.graphics.Color;
import android.widget.TextView;
import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;

public class Tutorial implements IXposedHookLoadPackage {
    public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable {
        if (!lpparam.packageName.equals("com.android.systemui"))
            return;

        findAndHookMethod("com.android.systemui.statusbar.policy.Clock", lpparam.classLoader, "updateClock", new XC_MethodHook() {
            @Override
            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                TextView tv = (TextView) param.thisObject;
                String text = tv.getText().toString();
                tv.setText(text + " :)");
                tv.setTextColor(Color.RED);
            }
        });
    }
}

我现在想制作自己的模块,在输入模式锁定后我必须在其中执行一些操作。输入模式后,我想读取模式并根据模式执行一些操作。请在这方面帮助我。我什至无法识别挂钩的方法。我试图在以下位置找到它: http: //grepcode.com/project/repository.grepcode.com/java/ext/com.google.android/android/

谢谢!

4

1 回答 1

6

我在 android git 上的 keyguard 源中搜索了一下,我发现这个方法具有你应该挂钩的这个方法。在这种方法中,您可以在正确的时间直接访问该模式。

findAndHookMethod("com.android.internal.widget.LockPatternUtils", lpparam.classLoader, "checkPattern", List.class /*You need to name the attribute's data type, I'm still not sure if List.class is enough, as the type is List<LockPatternView.Cell>*/, new XC_MethodHook() {
@Override
        protected void afterHookedMethod(MethodHookParam param) throws Throwable {
            List<?> pattern = param.args[0];
            // Proceed…
        }
});

另外,我发现了一种静态方法,可用于将模式转换为字符串以获得更好的可用性:LockPatternUtils.patternToString()

Class[] c = new Class[1];
c[0] = List.class;
XposedHelpers.callStaticMethod(XposedHelpers.findClass("com.android.internal.widget.LockPatternUtils", lpparam.classLoader), "patternToString", c, pattern);
于 2015-05-04T14:12:51.153 回答