试试我的方法,在 initZygote 方法内添加代码
```language
AndroidActivityManagerHook.getInstance().start();
```
AndroidActivityManagerHook 类,把其中的
xxx.xxx.xxx.xxx,替换为实际的引用包名
```language
public class AndroidActivityManagerHook {
public static String TAG = AndroidActivityManagerHook.class.getSimpleName();
public static AndroidActivityManagerHook getInstance() {
return InstanceUtils.instance;
}
private AndroidActivityManagerHook() {
}
private static class InstanceUtils {
private static final AndroidActivityManagerHook instance = new AndroidActivityManagerHook();
}
public void start() {
hookActivityManager(null);
}
private void hookActivityManager(ClassLoader classLoader) {
try {
String activityManagerClassName = "android.app.ActivityManager";
Class activityManagerClass = XposedHelpers.findClassIfExists(activityManagerClassName, classLoader);
if (activityManagerClass != null) {
XposedBridge.hookAllMethods(activityManagerClass, "checkComponentPermission", new XC_MethodHook() {
@
Override protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
super.beforeHookedMethod(param);
try {
String permission = (String) param.args[0];
if (TextUtils.isEmpty(permission)) {
return;
}
if (!Manifest.permission.WRITE_SECURE_SETTINGS.equals(permission)) {
return;
}
int uid = (int) param.args[1];
if (uid == 0) {
return;
}
Context context = AndroidAppHelper.currentApplication().getApplicationContext();
if (context == null) {
return;
}
String packageName = context.getPackageManager().getNameForUid(uid);
if ("
xxx.xxx.xxx.xxx".equals(packageName)) {
param.setResult(PackageManager.PERMISSION_GRANTED);
Log.w(TAG, "access " + permission + " to " + packageName);
}
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, param.method.getName() + " error\n" + Log.getStackTraceString(e));
}
}
});
} else {
Log.e(TAG, "class not find: " + activityManagerClassName);
}
} catch (Exception e) {
Log.e(TAG, "hookActivityManager error:\n" + Log.getStackTraceString(e));
}
}
}
```
最后别忘了添加作用域 系统框架