Skip to content

Commit

Permalink
解除miui对后台应用发送通知的限制
Browse files Browse the repository at this point in the history
  • Loading branch information
kooritea committed May 7, 2021
1 parent dc0c3e0 commit 65d3063
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 14 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
使用xposed让被完全停止的应用响应fcm,让fcm送达率达到100%,不错过任何通知

- 允许fcm唤醒选中的应用来发送通知
- 解除miui12对后台应用的通知限制(非miui系统没影响)
- 修复在国内网络下出现重连服务出现负数问题(貌似是miui优化的问题)(可选)(需要查看自己手机上gms的版本编辑配置文件)
- 固定心跳间隔为117s(可选)(需要查看自己手机上gms的版本编辑配置文件)

Expand Down Expand Up @@ -34,6 +35,8 @@
</map>

```
注: heartbeatInterval 设置为0的话则不固定心跳间隔时间,使用原本的自适应

- 9. 最后将配置文件的enable修改true,保存,重启手机

- 10. 一般来说gms更新改变的只有类名也就是timer_class
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "com.kooritea.fcmfix"
minSdkVersion 29
targetSdkVersion 30
versionCode 6
versionName "0.0.5"
versionCode 7
versionName "0.1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
15 changes: 4 additions & 11 deletions app/src/main/java/com/kooritea/fcmfix/XposedMain.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
package com.kooritea.fcmfix;

import android.app.AndroidAppHelper;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

import com.kooritea.fcmfix.xposed.BroadcastFix;
import com.kooritea.fcmfix.xposed.MiuiLocalNotificationFix;
import com.kooritea.fcmfix.xposed.ReconnectManagerFix;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;

import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
Expand All @@ -22,11 +13,13 @@ public void handleLoadPackage(final XC_LoadPackage.LoadPackageParam loadPackageP
if(loadPackageParam.packageName.equals("android")){
XposedBridge.log("[fcmfix] start hook com.android.server.am.ActivityManagerService");
new BroadcastFix(loadPackageParam);

XposedBridge.log("[fcmfix] start hook com.android.server.notification.NotificationManagerServiceInjector");
new MiuiLocalNotificationFix(loadPackageParam);
}
if(loadPackageParam.packageName.equals("com.google.android.gms")){
XposedBridge.log("[fcmfix] start hook com.google.android.gms");
new ReconnectManagerFix(loadPackageParam);

}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.kooritea.fcmfix.xposed;

import android.app.AndroidAppHelper;
import android.content.Intent;
import android.os.Build;

import com.kooritea.fcmfix.util.ContentProviderHelper;

import java.lang.reflect.Method;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

public class MiuiLocalNotificationFix extends XposedModule {
public MiuiLocalNotificationFix(XC_LoadPackage.LoadPackageParam loadPackageParam) {
super(loadPackageParam);
this.startHook();
}

protected void startHook(){
Class<?> clazz = XposedHelpers.findClass("com.android.server.notification.NotificationManagerServiceInjector",loadPackageParam.classLoader);
final Method[] declareMethods = clazz.getDeclaredMethods();
Method targetMethod = null;
for(Method method : declareMethods){
if(method.getName().equals("isAllowLocalNotification")){
targetMethod = method;
break;
}
}
if(targetMethod != null){
XposedBridge.hookMethod(targetMethod,new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam methodHookParam) throws Throwable {
methodHookParam.setResult(true);
printLog("Allow LocalNotification " + methodHookParam.args[3]);
}
});
}else{
printLog("Not found isAllowLocalNotification in com.android.server.notification.NotificationManagerServiceInjector");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ protected void beforeHookedMethod(final MethodHookParam param) throws Throwable
// 修改心跳间隔
Intent intent = (Intent) XposedHelpers.getObjectField(param.thisObject, sharedPreferences.getString("timer_intent_property", ""));
if ("com.google.android.gms.gcm.HEARTBEAT_ALARM".equals(intent.getAction())) {
param.args[0] = sharedPreferences.getLong("heartbeatInterval", 117000L);
long interval = sharedPreferences.getLong("heartbeatInterval", 0L);
if(interval != 0L){
param.args[0] = interval;
}
}
}

Expand Down

0 comments on commit 65d3063

Please sign in to comment.