|
31 | 31 | public class GmsDozeFix extends BaseHook { |
32 | 32 | @Override |
33 | 33 | public void init() throws NoSuchMethodException { |
34 | | - Class<?> GmsObserver = XposedHelpers.findClassIfExists("com.miui.powerkeeper.utils.GmsObserver", lpparam.classLoader); |
35 | | - findAndHookMethod(GmsObserver, "isGmsControlEnabled", new MethodHook() { |
| 34 | + Class<?> GmsObserver = findClassIfExists("com.miui.powerkeeper.utils.GmsObserver", lpparam.classLoader); |
| 35 | + findAndHookMethod(GmsObserver, "initGmsControl", new MethodHook() { |
36 | 36 | @Override |
37 | | - protected void after(MethodHookParam param) throws Throwable { |
38 | | - param.setResult(false); |
| 37 | + protected void before(MethodHookParam param) { |
| 38 | + param.setResult(null); |
39 | 39 | } |
40 | 40 | }); |
41 | 41 |
|
42 | | - Class<?> Misc = XposedHelpers.findClassIfExists("com.miui.powerkeeper.provider.SimpleSettings$Misc", lpparam.classLoader); |
43 | | - findAndHookMethod(Misc, "getBoolean", Context.class, String.class, boolean.class, new MethodHook() { |
| 42 | + findAndHookMethod(GmsObserver, "updateGmsNetWork", boolean.class, new MethodHook() { |
44 | 43 | @Override |
45 | | - protected void after(MethodHookParam methodHookParam) throws Throwable { |
46 | | - if ("gms_control".equals((String) methodHookParam.args[1])) { |
47 | | - methodHookParam.setResult(false); |
48 | | - } |
| 44 | + protected void before(MethodHookParam param) { |
| 45 | + param.setResult(null); |
49 | 46 | } |
50 | 47 | }); |
51 | 48 |
|
52 | | - Class<?> MilletPolicy = XposedHelpers.findClassIfExists("com.miui.powerkeeper.millet.MilletPolicy", lpparam.classLoader); |
| 49 | + findAndHookMethod(GmsObserver, "onGoogleReachabilityChanged", boolean.class, new MethodHook() { |
| 50 | + @Override |
| 51 | + protected void before(MethodHookParam param) { |
| 52 | + param.args[0] = true; |
| 53 | + } |
| 54 | + }); |
53 | 55 |
|
54 | | - MethodHook methodHook = new MethodHook() { |
55 | | - protected void before(MethodHook.MethodHookParam methodHookParam) throws Throwable { |
56 | | - Field[] declaredFields = null; |
57 | | - super.after(methodHookParam); |
58 | | - boolean mSystemBlackList = false; |
59 | | - boolean whiteApps = false; |
60 | | - boolean mDataWhiteList = false; |
| 56 | + try { |
| 57 | + Class<?> MilletPolicy = findClass("com.miui.powerkeeper.millet.MilletPolicy", lpparam.classLoader); |
| 58 | + findAndHookConstructor("com.miui.powerkeeper.millet.MilletPolicy", Context.class, new MethodHook() { |
| 59 | + protected void before(MethodHookParam methodHookParam) throws Throwable { |
| 60 | + super.after(methodHookParam); |
| 61 | + boolean mSystemBlackList = false; |
| 62 | + boolean whiteApps = false; |
| 63 | + boolean mDataWhiteList = false; |
61 | 64 |
|
62 | | - for (Field field : MilletPolicy.getDeclaredFields()) { |
63 | | - if (field.getName().equals("mSystemBlackList")) { |
64 | | - mSystemBlackList = true; |
65 | | - } else if (field.getName().equals("whiteApps")) { |
66 | | - whiteApps = true; |
67 | | - } else if (field.getName().equals("mDataWhiteList")) { |
68 | | - mDataWhiteList = true; |
| 65 | + for (Field field : MilletPolicy.getDeclaredFields()) { |
| 66 | + if (field.getName().equals("mSystemBlackList")) { |
| 67 | + mSystemBlackList = true; |
| 68 | + } else if (field.getName().equals("whiteApps")) { |
| 69 | + whiteApps = true; |
| 70 | + } else if (field.getName().equals("mDataWhiteList")) { |
| 71 | + mDataWhiteList = true; |
| 72 | + } |
69 | 73 | } |
70 | | - } |
71 | | - |
72 | | - if (mSystemBlackList) { |
73 | | - List blackList = (List) XposedHelpers.getObjectField(methodHookParam.thisObject, "mSystemBlackList"); |
74 | | - blackList.remove("com.google.android.gms"); |
75 | | - XposedHelpers.setObjectField(methodHookParam.thisObject, "mSystemBlackList", blackList); |
76 | | - } |
77 | | - if (whiteApps) { |
78 | | - List whiteAppList = (List) XposedHelpers.getObjectField(methodHookParam.thisObject, "whiteApps"); |
79 | | - whiteAppList.remove("com.google.android.gms"); |
80 | | - whiteAppList.remove("com.google.android.ext.services"); |
81 | | - XposedHelpers.setObjectField(methodHookParam.thisObject, "whiteApps", whiteAppList); |
82 | | - } |
83 | | - if (mDataWhiteList) { |
84 | | - List dataWhiteList = (List) XposedHelpers.getObjectField(methodHookParam.thisObject, "mDataWhiteList"); |
85 | | - dataWhiteList.add("com.google.android.gms"); |
86 | 74 |
|
87 | | - XposedHelpers.setObjectField(methodHookParam.thisObject, "mDataWhiteList", dataWhiteList); |
88 | | - } |
| 75 | + if (mSystemBlackList) { |
| 76 | + List blackList = (List) XposedHelpers.getObjectField(methodHookParam.thisObject, "mSystemBlackList"); |
| 77 | + blackList.remove("com.google.android.gms"); |
| 78 | + XposedHelpers.setObjectField(methodHookParam.thisObject, "mSystemBlackList", blackList); |
| 79 | + } |
| 80 | + if (whiteApps) { |
| 81 | + List whiteAppList = (List) XposedHelpers.getObjectField(methodHookParam.thisObject, "whiteApps"); |
| 82 | + whiteAppList.remove("com.google.android.gms"); |
| 83 | + whiteAppList.remove("com.google.android.ext.services"); |
| 84 | + XposedHelpers.setObjectField(methodHookParam.thisObject, "whiteApps", whiteAppList); |
| 85 | + } |
| 86 | + if (mDataWhiteList) { |
| 87 | + List dataWhiteList = (List) XposedHelpers.getObjectField(methodHookParam.thisObject, "mDataWhiteList"); |
| 88 | + dataWhiteList.add("com.google.android.gms"); |
89 | 89 |
|
90 | | - } |
91 | | - }; |
92 | | - XposedHelpers.findAndHookConstructor(MilletPolicy, new Object[]{Context.class, methodHook}); |
| 90 | + XposedHelpers.setObjectField(methodHookParam.thisObject, "mDataWhiteList", dataWhiteList); |
| 91 | + } |
93 | 92 |
|
| 93 | + } |
| 94 | + }); |
| 95 | + } catch (XposedHelpers.ClassNotFoundError e) { |
| 96 | + logE(TAG, this.lpparam.packageName, "Hook failed: "+ e); |
| 97 | + } |
94 | 98 | } |
95 | 99 | } |
0 commit comments