Skip to Content
OSAndroidThanox 情景模式

Thanox 情景模式

情景模式官方文档:https://tornaco.github.io/Thanox-Docs/zh/guide/profile.html 

记录一些自己写的模式,方便自己使用,尽量避开使用 su API,使用 MVEL 表达式 语法 调用 Andrid SDK  API。

GPS开关

使用全局变量 GPSApp 控制自动 GPS。

  • pkg:主进程精确存活期间一直开启 GPS
  • pkg/activity:仅当前台 Activity 精确命中时开启 GPS
  • 两者同时存在时取并集
  • 重复项自动去重,非法项自动忽略
  • 固定延迟 10 秒关闭,pkgKilled 立即关闭
  • 只关闭脚本自己开启的 GPS,手动开启的GPS不做处理
[ { "name": "Auto GPS Pro", "description": "根据 GPSApp 自动开启或关闭 GPS", "priority": 1, "condition": "frontPkgChanged || frontActivityChanged || pkgKilled || (shortcutLaunched == true && shortcutValue == \"autoGPSOff\")", "actions": [ "delayMs=10000;callbackMode=(shortcutLaunched==true&&shortcutValue=='autoGPSOff');if(callbackMode){savedTaskId=ruleKV.get('AutoGPS_DelayTaskId');if(args==null||args.length==0||savedTaskId==null||savedTaskId.length()==0||args[0].equals(savedTaskId)==false){return;}if('1'.equals(ruleKV.get('AutoGPS_GPSOwned'))==false){ruleKV.put('AutoGPS_DelayTaskId','');return;}if(!hw.isLocationEnabled()){ruleKV.put('AutoGPS_GPSOwned','');ruleKV.put('AutoGPS_DelayTaskId','');return;}hw.disableLocation();ruleKV.put('AutoGPS_GPSOwned','');ruleKV.put('AutoGPS_DelayTaskId','');return;}gpsRules=(globalVarOf$GPSApp); if(gpsRules==null){return;}cfgStamp=gpsRules.toString();if(cfgStamp.equals(ruleKV.get('AutoGPS_CacheStamp'))==false||ruleKV.get('AutoGPS_PkgRules')==null){oldPkgs=ruleKV.get('AutoGPS_AllPkgs');if(oldPkgs!=null){for(oldPkg:oldPkgs.split(';')){if(oldPkg!=null&&oldPkg.length()>0){ruleKV.put('AutoGPS_ACT_'+oldPkg,'');}}}pkgRules=';';allPkgs=';';for(raw:gpsRules){if(raw!=null){item=raw.trim();if(item.length()>0&&item.indexOf(' ')==-1){splitAt=item.indexOf('/');if(splitAt==-1){pkg=item;pkgMark=';'+pkg+';';if(pkgRules.indexOf(pkgMark)==-1){pkgRules=pkgRules+pkg+';';}if(allPkgs.indexOf(pkgMark)==-1){allPkgs=allPkgs+pkg+';';}}else if(splitAt>0&&splitAt<item.length()-1&&splitAt==item.lastIndexOf('/')){pkg=item.substring(0,splitAt);pkgMark=';'+pkg+';';if(allPkgs.indexOf(pkgMark)==-1){allPkgs=allPkgs+pkg+';';}actKey='AutoGPS_ACT_'+pkg;actList=ruleKV.get(actKey);if(actList==null||actList.length()==0){actList=';';}itemMark=';'+item+';';if(actList.indexOf(itemMark)==-1){ruleKV.put(actKey,actList+item+';');}}}}}ruleKV.put('AutoGPS_CacheStamp',cfgStamp);ruleKV.put('AutoGPS_PkgRules',pkgRules);ruleKV.put('AutoGPS_AllPkgs',allPkgs);}pkgRules=ruleKV.get('AutoGPS_PkgRules');if(pkgRules==null){pkgRules=';';}allPkgs=ruleKV.get('AutoGPS_AllPkgs');if(allPkgs==null){allPkgs=';';}if('1'.equals(ruleKV.get('AutoGPS_InitDone'))==false){ruleKV.put('AutoGPS_InitDone','1');ruleKV.put('AutoGPS_DelayTaskId','');ruleKV.put('AutoGPS_GPSOwned','');}currentActivity=null;currentPkg=null;needTop=false;if(frontActivityChanged==true&&toActivity!=null){currentActivity=toActivity.flattenToString();currentPkg=toActivity.getPackageName();}else if(frontPkgChanged==true){currentPkg=to;if(currentPkg==null){needTop=true;}else{actList=ruleKV.get('AutoGPS_ACT_'+currentPkg);if(actList!=null&&actList.length()>1){needTop=true;}}}if((needTop||currentPkg==null)&&pkgKilled==false){topActivities=thanos.activityManager.getTopVisibleActivities();if(topActivities!=null&&!topActivities.isEmpty()){topActivity=topActivities.get(0);if(topActivity!=null){currentActivity=topActivity.flattenToString();if(currentPkg==null||needTop){currentPkg=topActivity.getPackageName();}}}}shouldEnable=false;if(currentPkg!=null&&pkgRules.indexOf(';'+currentPkg+';')!=-1){shouldEnable=true;}if(shouldEnable==false&&currentPkg!=null&&currentActivity!=null){actList=ruleKV.get('AutoGPS_ACT_'+currentPkg);if(actList!=null&&actList.indexOf(';'+currentActivity+';')!=-1){shouldEnable=true;}}if(shouldEnable){ruleKV.put('AutoGPS_DelayTaskId','');if(!hw.isLocationEnabled()){hw.enableLocation();ruleKV.put('AutoGPS_GPSOwned','1');}return;}owned=('1'.equals(ruleKV.get('AutoGPS_GPSOwned')));if(owned==false){return;}if(!hw.isLocationEnabled()){ruleKV.put('AutoGPS_GPSOwned','');ruleKV.put('AutoGPS_DelayTaskId','');return;}if(pkgKilled==true){killedPkg=pkgName;if(killedPkg==null||allPkgs.indexOf(';'+killedPkg+';')==-1){return;}killedAlive=false;processes=thanos.activityManager.getRunningAppProcessForPackage(killedPkg);if(processes!=null){for(process:processes){if(killedAlive==false&&process!=null&&killedPkg.equals(process.processName)){killedAlive=true;}}}if(killedAlive){return;}currentActivity=null;currentPkg=null;topActivities=thanos.activityManager.getTopVisibleActivities();if(topActivities!=null&&!topActivities.isEmpty()){topActivity=topActivities.get(0);if(topActivity!=null){currentActivity=topActivity.flattenToString();currentPkg=topActivity.getPackageName();}}shouldEnable=false;if(currentPkg!=null&&pkgRules.indexOf(';'+currentPkg+';')!=-1){shouldEnable=true;}if(shouldEnable==false&&currentPkg!=null&&currentActivity!=null){actList=ruleKV.get('AutoGPS_ACT_'+currentPkg);if(actList!=null&&actList.indexOf(';'+currentActivity+';')!=-1){shouldEnable=true;}}if(shouldEnable==false){for(pkg:pkgRules.split(';')){if(shouldEnable==false&&pkg!=null&&pkg.length()>0&&pkg.equals(killedPkg)==false){processes=thanos.activityManager.getRunningAppProcessForPackage(pkg);if(processes!=null){for(process:processes){if(shouldEnable==false&&process!=null&&pkg.equals(process.processName)){shouldEnable=true;}}}}}}if(shouldEnable){ruleKV.put('AutoGPS_DelayTaskId','');return;}ruleKV.put('AutoGPS_DelayTaskId','');hw.disableLocation();ruleKV.put('AutoGPS_GPSOwned','');return;}for(pkg:pkgRules.split(';')){if(shouldEnable==false&&pkg!=null&&pkg.length()>0){processes=thanos.activityManager.getRunningAppProcessForPackage(pkg);if(processes!=null){for(process:processes){if(shouldEnable==false&&process!=null&&pkg.equals(process.processName)){shouldEnable=true;}}}}}if(shouldEnable){ruleKV.put('AutoGPS_DelayTaskId','');return;}pendingTaskId=ruleKV.get('AutoGPS_DelayTaskId');if(pendingTaskId!=null&&pendingTaskId.length()>0){return;}taskId=Long.toString(System.currentTimeMillis());ruleKV.put('AutoGPS_DelayTaskId',taskId);thanos.profileManager.publishStringFact(1,'autoGPSOff',delayMs,new String[]{taskId});" ] } ]

GPSApp 示例:

[ "com.tencent.mm/com.tencent.mm.plugin.location_soso.SoSoProxyUI", "com.sankuai.meituan", "com.eg.android.AlipayGphone/com.alipay.android.phone.xriver.bundlex.CSGAPushActivity", "com.eg.android.AlipayGphone/com.alipay.mobile.nebulax.xriver.activity.XRiverActivity", "com.autonavi.minimap" ]

监听wifi变化,打开或者关闭移动流量

[ { "name": "keepOnline", "description": "监听wifi变化,打开或者关闭移动流量", "priority": 2, "condition": "wifiStateChanged", "actions": [ "if (wifiState.ssid == null) { data.setDataEnabled(true) } else { data.setDataEnabled(false) }" ] } ]

使用快捷方式启动 Lsposed manager

新增一个快捷方式,名字自定义,值为 Open Lsposed manager

[ { "name": "Open Lsposed", "description": "启动 Lsposed manager", "priority": 2, "condition": "shortcutLaunched == true && shortcutValue == \"Open Lsposed manager\"", "actions": [ "context.sendBroadcast(new android.content.Intent(android.os.Build.VERSION.SDK_INT >= 29 ? \"android.telephony.action.SECRET_CODE\" : \"android.provider.Telephony.SECRET_CODE\").setData(android.net.Uri.parse(\"android_secret_code://5776733\")));" ] } ]

QQ音乐进程优化

[ { "name": "QQ音乐进程优化", "description": "优化保留QQPlayerService,杀死其他进程", "priority": 1, "condition": "frontPkgChanged == true && from == \"com.tencent.qqmusic\"", "delay": 10000, "actions": [ "if (activity.getFrontAppPackage() != \"com.tencent.qqmusic\") { for (process : thanos.activityManager.getRunningAppProcessForPackage(\"com.tencent.qqmusic\")) { if (!process.processName.contains(\"QQPlayerService\")) { thanos.activityManager.killProcessByName(process.processName); } } }" ] } ]

QQ后台进程优化

[ { "name": "QQ后台进程优化", "description": "利用Thanos自动清理QQ后台进程,保留通话和小程序,可自行更改 delay 来选择何时判定执行。", "priority": 1, "condition": "frontPkgChanged && \"com.tencent.mobileqq\".equals(from)", "delay": 10000, "actions": [ "if(activity.getFrontAppPackage()!=\"com.tencent.mobileqq\"){var allowedProcesses = [\"com.tencent.mobileqq\", \"com.tencent.mobileqq:video\", \"com.tencent.mobileqq:mini\"]; for (process : thanos.activityManager.getRunningAppProcessForPackage(\"com.tencent.mobileqq\")) { if (!allowedProcesses.contains(process.processName)) { thanos.activityManager.killProcessByName(process.processName); } };}" ] } ]

微信进程优化

[ { "name": "微信进程优化", "description": "前台应用切换时,60s杀掉微信其他进程,仅保留push进程, 但60s内回到微信啥也不杀,可自行更改 delay 来选择何时判定执行。", "priority": 2, "condition": "frontPkgChanged == true && from == \"com.tencent.mm\"", "delay": 60000, "actions": [ "if(activity.getFrontAppPackage()!=\"com.tencent.mm\"){for (process : thanos.activityManager.getRunningAppProcessForPackage(\"com.tencent.mm\")) { if (!process.processName.endsWith(\":push\")) { thanos.activityManager.killProcessByName(process.processName); } };}" ] } ]
Last updated on