|
| 1 | +package com.kooritea.fcmfix.xposed; |
| 2 | + |
| 3 | +import android.content.pm.PackageManager; |
| 4 | +import android.os.WorkSource; |
| 5 | + |
| 6 | +import com.kooritea.fcmfix.util.XposedUtils; |
| 7 | + |
| 8 | +import de.robv.android.xposed.XC_MethodHook; |
| 9 | +import de.robv.android.xposed.XposedHelpers; |
| 10 | +import de.robv.android.xposed.callbacks.XC_LoadPackage; |
| 11 | + |
| 12 | +public class OplusProxyFix extends XposedModule { |
| 13 | + |
| 14 | + private static Object s_oplusProxyWakeLock = null; |
| 15 | + |
| 16 | + public OplusProxyFix(XC_LoadPackage.LoadPackageParam loadPackageParam) { |
| 17 | + super(loadPackageParam); |
| 18 | + try{ |
| 19 | + this.startHookOplusProxyWakeLock(); |
| 20 | + this.startHookOplusProxyBroadcast(); |
| 21 | + }catch(Throwable e) { |
| 22 | + printLog("hook error OplusProxy:" + e.getMessage()); |
| 23 | + } |
| 24 | + } |
| 25 | + |
| 26 | + private void startHookOplusProxyBroadcast() throws Exception { |
| 27 | + Class<?> oplusProxyBroadcastClass = XposedHelpers.findClass("com.android.server.am.OplusProxyBroadcast", loadPackageParam.classLoader); |
| 28 | + Class<?> resultEnum = XposedHelpers.findClass("com.android.server.am.OplusProxyBroadcast$RESULT", loadPackageParam.classLoader); |
| 29 | + Object notIncludeValue = XposedHelpers.getStaticObjectField(resultEnum, "NOT_INCLUDE"); |
| 30 | + Object proxyValue = XposedHelpers.getStaticObjectField(resultEnum, "PROXY"); |
| 31 | + |
| 32 | + /* |
| 33 | + XXX only tested on OnePlus13T ColorOS 15 |
| 34 | + private RESULT shouldProxy( 8 args |
| 35 | + 00 Intent intent, |
| 36 | + 01 int callingPid, |
| 37 | + 02 int callingUid, |
| 38 | + 03 String callingPkg, |
| 39 | + 04 int uid, |
| 40 | + 05 String pkgName, |
| 41 | + 06 String action, |
| 42 | + 07 int appType) { |
| 43 | + */ |
| 44 | + |
| 45 | + XposedUtils.findAndHookMethod(oplusProxyBroadcastClass, "shouldProxy", 8, new XC_MethodHook() { |
| 46 | + @Override |
| 47 | + protected void beforeHookedMethod(MethodHookParam param) throws Throwable { |
| 48 | + String callingPkg = (String)param.args[3]; |
| 49 | + String pkgName = (String)param.args[5]; |
| 50 | + String action = (String)param.args[6]; |
| 51 | + // positive sample: caller=com.google.android.gms, action=com.google.android.c2dm.intent.RECEIVE |
| 52 | + if (isFCMAction(action) && targetIsAllow(pkgName)) { |
| 53 | + printLog("shouldProxy: bypass pkg="+pkgName+", caller="+callingPkg+", action="+action); |
| 54 | + param.setResult(notIncludeValue); |
| 55 | + } |
| 56 | + } |
| 57 | + }); |
| 58 | + } |
| 59 | + |
| 60 | + private void startHookOplusProxyWakeLock() throws Exception { |
| 61 | + Class<?> oplusWakelockClass = XposedHelpers.findClass("com.android.server.power.OplusProxyWakeLock", loadPackageParam.classLoader); |
| 62 | + |
| 63 | + XposedUtils.findAndHookConstructorAnyParam(oplusWakelockClass, new XC_MethodHook() { |
| 64 | + @Override |
| 65 | + protected void afterHookedMethod(MethodHookParam param) throws Throwable { |
| 66 | + if (s_oplusProxyWakeLock != null) { |
| 67 | + printLog("warn: OplusProxyWakeLock constructed multiple times!"); |
| 68 | + return; |
| 69 | + } |
| 70 | + s_oplusProxyWakeLock = param.thisObject; |
| 71 | + } |
| 72 | + }); |
| 73 | + } |
| 74 | + |
| 75 | + private static int getTargetUidFromPackageName(String packageName) { |
| 76 | + // Convert package name to UID |
| 77 | + if (packageName != null) { |
| 78 | + try { |
| 79 | + PackageManager pm = context.getPackageManager(); |
| 80 | + return pm.getPackageUid(packageName, 0); |
| 81 | + } catch (PackageManager.NameNotFoundException e) { |
| 82 | + printLog("error: Package not found: " + packageName); |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + // Default to an invalid UID if we couldn't determine the target |
| 87 | + return -1; |
| 88 | + } |
| 89 | + |
| 90 | + public static void unfreeze(String target) { |
| 91 | + if (s_oplusProxyWakeLock == null) { |
| 92 | + return; |
| 93 | + } |
| 94 | + |
| 95 | + int uid = getTargetUidFromPackageName(target); |
| 96 | + if (uid < 0) { |
| 97 | + return; |
| 98 | + } |
| 99 | + |
| 100 | + /* |
| 101 | + XXX only tested on OnePlus13T ColorOS 15 |
| 102 | + unfreezeIfNeed: 3 args |
| 103 | + 00 int uid, |
| 104 | + 01 WorkSource ws, |
| 105 | + 02 String tag |
| 106 | + */ |
| 107 | + |
| 108 | + printLog("unfreeze " + target + ", uid=" + uid); |
| 109 | + WorkSource ws = new WorkSource(); |
| 110 | + XposedHelpers.callMethod(s_oplusProxyWakeLock, "unfreezeIfNeed", uid, ws, "FCMXX"); // 5 chars tag |
| 111 | + } |
| 112 | + |
| 113 | +} |
0 commit comments