Open
Description
如题,觉得目前的乖巧模式的不太压得住流氓们,app切换到后台后仍然占用cpu,于是探索使用冻结进程的方式,看作者大神后续能否增强(需要那种前台能用,后台压得死死的,切换回前台又恢复之前的会话)
在全局变量中添加 pause,把要压制的app添加进去;或者在目标应用详情,将电池设置为受限(为了检验效果,脚本与乖巧模式互斥,会自动关闭乖巧)
20220729更新:
1.修复未添加全局变量pause时脚本出错的bug;
2.添加参数自定义调整功能,其中DELAY = 45000,对应实现应用切回后台进入墓碑的等待时长(毫秒);修改为SU_EXE = 1,则使用kill -19命令来压制进程,需打开su插件支持(默认SU_EXE = 0,使用系统api进行压制,无需su插件)。
情景模式脚本
[
{
"name": "ForceIdle: auto pause or continue App",
"description": "通过全局变量[pause]添加应用列表,或设置电池用量为受限,对回到后台的应用强制压制(墓碑)。\nForce pause the app while it switchs to backgroud, you need to pick app list in the global val name [pause].",
"priority": 1,
"condition": "frontPkgChanged == true",
"actions": [
"if(thanos.getActivityManager().isBlockAllService(to)){thanos.getActivityManager().setBlockAllService(to,false)};",
"if(thanos.getActivityManager().isBlockAllReceiver(to)){thanos.getActivityManager().setBlockAllReceiver(to,false)};",
"if(thanos.getActivityManager().isBlockAllProvider(to)){thanos.getActivityManager().setBlockAllProvider(to,false)};",
"if(context.getSystemService(context.APP_OPS_SERVICE).unsafeCheckOp(android.app.AppOpsManager.OPSTR_RUN_ANY_IN_BACKGROUND, thanos.getPkgManager().getUidForPkgName(to), to) == android.app.AppOpsManager.MODE_IGNORED || (thanos.getProfileManager().isGlobalRuleVarByNameExists(\"pause\") && globalVarOf$pause.contains(to))){foreach(proc:context.getSystemService(context.ACTIVITY_SERVICE).getRunningAppProcesses()){if(proc.processName.contains(to)){android.os.Process.sendSignal(proc.pid,18);}}; context.getSystemService(context.APP_OPS_SERVICE).setMode(android.app.AppOpsManager.OP_WAKE_LOCK, thanos.getPkgManager().getUidForPkgName(to), to, android.app.AppOpsManager.MODE_DEFAULT); context.getSystemService(context.USAGE_STATS_SERVICE).setAppStandbyBucket(to,android.app.usage.UsageStatsManager.STANDBY_BUCKET_RARE); if(thanos.getActivityManager().isPkgSmartStandByEnabled(to)){thanos.getActivityManager().setPkgSmartStandByEnabled(to,false)}; if(thanos.getActivityManager().isPkgBgRestricted(to)){thanos.getActivityManager().setPkgBgRestrictEnabled(to,false)}};",
"DELAY = 45000; if(context.getSystemService(context.APP_OPS_SERVICE).unsafeCheckOp(android.app.AppOpsManager.OPSTR_RUN_ANY_IN_BACKGROUND, thanos.getPkgManager().getUidForPkgName(from), from) == android.app.AppOpsManager.MODE_IGNORED || (thanos.getProfileManager().isGlobalRuleVarByNameExists(\"pause\") && globalVarOf$pause.contains(from))){context.getSystemService(context.APP_OPS_SERVICE).setMode(android.app.AppOpsManager.OP_WAKE_LOCK, thanos.getPkgManager().getUidForPkgName(from), from, android.app.AppOpsManager.MODE_IGNORED); thanos.getActivityManager().setBlockAllService(from,true); thanos.getActivityManager().setBlockAllReceiver(from,true); thanos.getActivityManager().setBlockAllProvider(from,true); actor.delayed(DELAY,\"if(activity.getFrontAppPackage()!=from){if(thanos.getActivityManager().isPackageIdle(from)==false){context.getSystemService(context.ACTIVITY_SERVICE).getService().makePackageIdle(from,android.os.UserHandle.USER_ALL)}; if(activity.isInactive(from)==false){activity.setInactive(from)}; context.getSystemService(context.USAGE_STATS_SERVICE).setAppStandbyBucket(from,android.app.usage.UsageStatsManager.STANDBY_BUCKET_RESTRICTED); SU_EXE = 0; foreach(proc:context.getSystemService(context.ACTIVITY_SERVICE).getRunningAppProcesses()){if(proc.processName.contains(from)){if(SU_EXE == 1){su.exe(\\\"kill -19 \\\" + proc.pid);};if(SU_EXE != 1){android.os.Process.sendSignal(proc.pid,20);};}}}\")};"
]
}
]
Metadata
Metadata
Assignees
Labels
Projects
Status
No status