Skip to content

Commit 1f8f984

Browse files
authored
fix #222 (coloros proxied wakelock/broadcast) (#226)
* BroadcastFix: update condition * add ColorOS15 wakelock/broadcast proxy fix
1 parent 175c73c commit 1f8f984

4 files changed

Lines changed: 125 additions & 3 deletions

File tree

app/src/main/java/com/kooritea/fcmfix/XposedMain.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.kooritea.fcmfix.xposed.GMSRestrictFix;
88
import com.kooritea.fcmfix.xposed.KeepNotification;
99
import com.kooritea.fcmfix.xposed.MiuiLocalNotificationFix;
10+
import com.kooritea.fcmfix.xposed.OplusProxyFix;
1011
import com.kooritea.fcmfix.xposed.PowerkeeperFix;
1112
import com.kooritea.fcmfix.xposed.ReconnectManagerFix;
1213
import com.kooritea.fcmfix.xposed.XposedModule;
@@ -41,6 +42,9 @@ public void handleLoadPackage(final XC_LoadPackage.LoadPackageParam loadPackageP
4142

4243
XposedBridge.log("[fcmfix] com.android.server.notification.NotificationManagerService");
4344
new KeepNotification(loadPackageParam);
45+
46+
XposedBridge.log("[fcmfix] start hook com.android.server.power.OplusProxyWakeLock");
47+
new OplusProxyFix(loadPackageParam);
4448
}
4549

4650
if(loadPackageParam.packageName.equals("com.google.android.gms") && loadPackageParam.isFirstApplication){
@@ -54,7 +58,6 @@ public void handleLoadPackage(final XC_LoadPackage.LoadPackageParam loadPackageP
5458
XposedBridge.log("[fcmfix] start hook com.miui.powerkeeper");
5559
new PowerkeeperFix(loadPackageParam);
5660
}
57-
5861
}
5962
private boolean fileIsExists(String strFile) {
6063
try {

app/src/main/java/com/kooritea/fcmfix/xposed/BroadcastFix.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ protected void beforeHookedMethod(MethodHookParam methodHookParam) {
181181
}else{
182182
printLog("Send Forced Start Broadcast: " + target, true);
183183
}
184+
// cos15 unfreeze
185+
OplusProxyFix.unfreeze(target);
184186
}
185187
}
186188
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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+
}

app/src/main/java/com/kooritea/fcmfix/xposed/XposedModule.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,13 +309,17 @@ protected void createFcmfixChannel(NotificationManagerCompat notificationManager
309309
}
310310
}
311311

312-
protected boolean isFCMIntent(Intent intent) {
313-
String action = intent.getAction();
312+
protected boolean isFCMAction(String action) {
314313
return action != null && (action.endsWith(".android.c2dm.intent.RECEIVE") ||
315314
"com.google.firebase.MESSAGING_EVENT".equals(action) ||
316315
"com.google.firebase.INSTANCE_ID_EVENT".equals(action));
317316
}
318317

318+
protected boolean isFCMIntent(Intent intent) {
319+
String action = intent.getAction();
320+
return isFCMAction(action);
321+
}
322+
319323
protected static String getSelfPackageName() {
320324
return staticLoadPackageParam == null ? "UNKNOWN":staticLoadPackageParam.packageName;
321325
}

0 commit comments

Comments
 (0)