Skip to content

Commit

Permalink
0.4.0 在MIUI上自动允许自启动
Browse files Browse the repository at this point in the history
  • Loading branch information
kooritea committed Aug 24, 2021
1 parent 8a32a7b commit ddc41fe
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 6 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,32 @@
- 修复在国内网络下出现重连服务出现负数问题(貌似是miui优化的问题)
- 固定心跳间隔(默认117s,更改需要编辑配置文件)

---

## 注意
在国内版miui上,除了在本应用中勾选目标应用之外,还要给予目标应用自启动权限中的允许系统唤醒权限(eu版和国际版则不需要给自启动权限)

~~在国内版miui上,除了在本应用中勾选目标应用之外,还要给予目标应用自启动权限中的允许系统唤醒权限(eu版和国际版则不需要给自启动权限)~~

从0.4.0开始已经不再需要,感谢来自 @MinaMichita 的方法 [https://blog.minamigo.moe/archives/747](https://blog.minamigo.moe/archives/747)

---

## Lsposed
- 唤醒应用和解除miui通知限制需要勾选安卓系统作用(不需要勾选目标应用)
- fcm心跳修复和负数重连问题功能需要勾选com.google.android.gms

---

## 可能出现的问题

### 1、重启之后配置文件被复原
> 一般是你用了mt管理器那个编辑器的问题,可以尝试修改完后删除那个.bak后缀的文件,或者在设置中关闭生成bak文件,或者换一个编辑器 https://play.google.com/store/apps/details?id=in.mfile
### 2、遇到国内版锁屏后连接自动断开的问题请尝试使用针对国内版开发的版本
[https://blog.minamigo.moe/archives/747](https://blog.minamigo.moe/archives/747)

---

## 下面是手动找hook点的方法,从0.3.0版本开始不再需要手动反编译查找hook点了,但不排除会自动查找失败的情况,如果gms频繁崩溃或者gms状态中一直显示无服务,可以先手动找hook点检查或者请带上gms.apk发issues
- 1. 确保xposed模块已经运行,如果存在/data/data/com.google.android.gms/shared_prefs/fcmfix_config.xml则证明模块已经成功运行,这是配置文件,之后都是编辑这个文件的内容。
- 2. 下载MT管理器等可以进行反编译的工具
Expand Down
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 19
versionName "0.3.10"
versionCode 20
versionName "0.4.0"

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

import com.kooritea.fcmfix.xposed.AutoStartFix;
import com.kooritea.fcmfix.xposed.BroadcastFix;
import com.kooritea.fcmfix.xposed.MiuiLocalNotificationFix;
import com.kooritea.fcmfix.xposed.ReconnectManagerFix;
Expand All @@ -23,6 +24,9 @@ public void handleLoadPackage(final XC_LoadPackage.LoadPackageParam loadPackageP

XposedBridge.log("[fcmfix] start hook com.android.server.notification.NotificationManagerServiceInjector");
new MiuiLocalNotificationFix(loadPackageParam);

XposedBridge.log("[fcmfix] com.android.server.am.BroadcastQueueInjector.checkApplicationAutoStart");
new AutoStartFix(loadPackageParam);
}
if(loadPackageParam.packageName.equals("com.google.android.gms") && loadPackageParam.isFirstApplication){
XposedBridge.log("[fcmfix] start hook com.google.android.gms");
Expand Down
58 changes: 58 additions & 0 deletions app/src/main/java/com/kooritea/fcmfix/util/XposedUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.kooritea.fcmfix.util;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

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

public class XposedUtils {
public static XC_MethodHook.Unhook findAndHookConstructorAnyParam(String className, ClassLoader classLoader, XC_MethodHook callbacks, Class<?> ...parameterTypes){
Class<?> clazz = XposedHelpers.findClass(className,classLoader);
Constructor bestMatch = null;
int matchCount = 0;
for(Constructor<?> constructor : clazz.getDeclaredConstructors()){
Class<?>[] constructorParamTypes = constructor.getParameterTypes();
int _matchCount = 0;
for(int i = 0;i<Math.min(constructorParamTypes.length,parameterTypes.length);i++){
if(parameterTypes[i] == constructorParamTypes[i]){
_matchCount++;
}
}
if(_matchCount >= matchCount){
matchCount = _matchCount;
bestMatch = constructor;
}
}
if(bestMatch == null){
throw new NoSuchMethodError(clazz.getName());
}
return XposedBridge.hookMethod(XposedHelpers.findConstructorExact(clazz,bestMatch.getParameterTypes()), callbacks);
}

public static XC_MethodHook.Unhook findAndHookMethodAnyParam(String className, ClassLoader classLoader, String methodName, XC_MethodHook callbacks, Object ...parameterTypes){
Class<?> clazz = XposedHelpers.findClass(className,classLoader);
Method bestMatch = null;
int matchCount = 0;
for(Method method : clazz.getDeclaredMethods()){
if(methodName.equals(method.getName())){
Class<?>[] methodParamTypes = method.getParameterTypes();
int _matchCount = 0;
for(int i = 0;i<Math.min(methodParamTypes.length,parameterTypes.length);i++){
if(parameterTypes[i] == methodParamTypes[i]){
_matchCount++;
}
}
if(_matchCount >= matchCount){
matchCount = _matchCount;
bestMatch = method;
}
}
}
if(bestMatch == null){
throw new NoSuchMethodError(clazz.getName() + '#' + methodName);
}
return XposedBridge.hookMethod(XposedHelpers.findMethodExact(clazz,methodName,bestMatch.getParameterTypes()), callbacks);
}
}
38 changes: 38 additions & 0 deletions app/src/main/java/com/kooritea/fcmfix/xposed/AutoStartFix.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.kooritea.fcmfix.xposed;

import android.content.Intent;

import com.kooritea.fcmfix.util.XposedUtils;

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

public class AutoStartFix extends XposedModule {

public AutoStartFix(XC_LoadPackage.LoadPackageParam loadPackageParam){
super(loadPackageParam);
this.startHook();
}

protected void startHook(){
XposedUtils.findAndHookMethodAnyParam("com.android.server.am.BroadcastQueueInjector",loadPackageParam.classLoader,"checkApplicationAutoStart",new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam methodHookParam) throws Throwable {
Intent intent = (Intent) XposedHelpers.getObjectField(methodHookParam.args[2],"intent");
if("com.google.android.c2dm.intent.RECEIVE".equals(intent.getAction())){
String target;
if (intent.getComponent() != null) {
target = intent.getComponent().getPackageName();
} else {
target = intent.getPackage();
}
if(targetIsAllow(target)){
printLog("Allow Auto Start: " + target);
methodHookParam.setResult(true);
}
}
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ public void onReceive(Context _context, Intent intent) {
if (Intent.ACTION_USER_UNLOCKED.equals(action)) {
try {
context.unregisterReceiver(unlockBroadcastReceive);
} catch (Exception e) {
printLog("注销解锁广播出错: " + e.getMessage());
}
} catch (Exception e) { }
try {
onCanReadConfig();
} catch (Exception e) {
Expand Down

5 comments on commit ddc41fe

@ayanamist
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不需要这么麻烦,把powerkeeper那个app伪装成国际版就可以了,就是这个app有针对gms的一系列定制打压逻辑

@kooritea
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

把整个powerkeeper伪装成国际版会导致其他应用都不可控了

@kooritea
Copy link
Owner Author

@kooritea kooritea commented on ddc41fe Aug 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个提交主要是不用再手动给自启动权限而已,powerkeeper会限制fcm的问题这个得另外解决

@ayanamist
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我只是看到了这个做法,顺手反馈。我自己用xposed模块这么改了,只把这个伪装成国际版,问题不大,反编译看过,它只用是否国际版来控制使用哪些后台压制策略而已。

@kooritea
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个自启动的相关控制是在services.jar里面的,powerkeeper是后台策略的,所以其实关系不大

Please sign in to comment.