From a82697028bbb1b12c9371686064982d83bebb4a4 Mon Sep 17 00:00:00 2001 From: TKaxv_7S <954067342@qq.com> Date: Wed, 8 May 2024 21:26:58 +0800 Subject: [PATCH 01/10] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E9=97=AA=E5=B1=8F?= =?UTF-8?q?=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pansong291/xposed/quickenergy/hook/XposedHook.java | 2 +- .../pansong291/xposed/quickenergy/util/FileUtils.java | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/pansong291/xposed/quickenergy/hook/XposedHook.java b/app/src/main/java/pansong291/xposed/quickenergy/hook/XposedHook.java index a3c706e8d..d9b365896 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/hook/XposedHook.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/hook/XposedHook.java @@ -147,7 +147,7 @@ private void hookService(ClassLoader loader) { protected void afterHookedMethod(MethodHookParam param) { Log.i(TAG, "Activity onResume"); RpcUtil.isInterrupted = false; - PermissionUtil.requestPermissions((Activity) param.thisObject); + //PermissionUtil.requestPermissions((Activity) param.thisObject); AntForestNotification.setContentText("运行中..."); String targetUid = RpcUtil.getUserId(loader); if (targetUid == null || targetUid.equals(FriendIdMap.getCurrentUid())) { diff --git a/app/src/main/java/pansong291/xposed/quickenergy/util/FileUtils.java b/app/src/main/java/pansong291/xposed/quickenergy/util/FileUtils.java index b38ecabf1..6e03233df 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/util/FileUtils.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/util/FileUtils.java @@ -54,12 +54,9 @@ public static File getMainDirectoryFile() { if (!storageDir.exists()) { storageDir.mkdirs(); } - File useMedia = new File(storageDir, "useMedia"); - if (useMedia.exists()) { - String storageDirStr = Environment.getExternalStorageDirectory() + File.separator + "Android" + - File.separator + "media" + File.separator + ClassMember.PACKAGE_NAME; - storageDir = new File(storageDirStr); - } + String storageDirStr = Environment.getExternalStorageDirectory() + File.separator + "Android" + + File.separator + "media" + File.separator + ClassMember.PACKAGE_NAME; + storageDir = new File(storageDirStr); mainDirectory = new File(storageDir, "xqe"); if (!mainDirectory.exists()) { From ccda5d8e8594150a39955d4e73cdddbfad167916 Mon Sep 17 00:00:00 2001 From: TKaxv_7S <954067342@qq.com> Date: Wed, 29 May 2024 16:37:39 +0800 Subject: [PATCH 02/10] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xposed/quickenergy/AncientTree.java | 3 +- .../xposed/quickenergy/AntCooperate.java | 3 +- .../xposed/quickenergy/AntFarm.java | 45 ++++++++++++++----- .../xposed/quickenergy/AntMember.java | 3 +- .../xposed/quickenergy/AntOcean.java | 3 +- .../xposed/quickenergy/AntSports.java | 3 +- .../xposed/quickenergy/Reserve.java | 3 +- .../xposed/quickenergy/hook/XposedHook.java | 42 +++++++++++++---- .../xposed/quickenergy/util/FriendIdMap.java | 19 ++++++-- 9 files changed, 90 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/pansong291/xposed/quickenergy/AncientTree.java b/app/src/main/java/pansong291/xposed/quickenergy/AncientTree.java index 5b4dac69a..f70a005d5 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/AncientTree.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/AncientTree.java @@ -22,8 +22,7 @@ public static void start() { @Override public void run() { try { - while (FriendIdMap.getCurrentUid() == null || FriendIdMap.getCurrentUid().isEmpty()) - Thread.sleep(101); + FriendIdMap.waitingCurrentUid(); ancientTree(Config.getAncientTreeCityCodeList()); // 二次检查 有时会返回繁忙漏保护 } catch (Throwable t) { Log.i(TAG, "start.run err:"); diff --git a/app/src/main/java/pansong291/xposed/quickenergy/AntCooperate.java b/app/src/main/java/pansong291/xposed/quickenergy/AntCooperate.java index 7c81213fa..09c08e370 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/AntCooperate.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/AntCooperate.java @@ -21,8 +21,7 @@ public static void start() { @Override public void run() { try { - while (FriendIdMap.getCurrentUid() == null || FriendIdMap.getCurrentUid().isEmpty()) - Thread.sleep(100); + FriendIdMap.waitingCurrentUid(); String s = AntCooperateRpcCall.queryUserCooperatePlantList(); if (s == null) { Thread.sleep(RandomUtils.delay()); diff --git a/app/src/main/java/pansong291/xposed/quickenergy/AntFarm.java b/app/src/main/java/pansong291/xposed/quickenergy/AntFarm.java index c43c70c93..6e44b9b78 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/AntFarm.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/AntFarm.java @@ -2,14 +2,22 @@ import org.json.JSONArray; import org.json.JSONObject; -import pansong291.xposed.quickenergy.hook.AntFarmRpcCall; -import pansong291.xposed.quickenergy.util.*; -import pansong291.xposed.quickenergy.hook.DadaDailyRpcCall; -import java.util.HashSet; -import java.util.Set; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; + +import pansong291.xposed.quickenergy.hook.AntFarmRpcCall; +import pansong291.xposed.quickenergy.hook.DadaDailyRpcCall; +import pansong291.xposed.quickenergy.util.Config; +import pansong291.xposed.quickenergy.util.FriendIdMap; +import pansong291.xposed.quickenergy.util.Log; +import pansong291.xposed.quickenergy.util.PluginUtils; +import pansong291.xposed.quickenergy.util.RandomUtils; +import pansong291.xposed.quickenergy.util.Statistics; +import pansong291.xposed.quickenergy.util.StringUtil; +import pansong291.xposed.quickenergy.util.TimeUtil; public class AntFarm { private static final String TAG = AntFarm.class.getCanonicalName(); @@ -124,13 +132,30 @@ public static void start() { @Override public void run() { try { - while (FriendIdMap.getCurrentUid() == null || FriendIdMap.getCurrentUid().isEmpty()) - Thread.sleep(100); - String s = AntFarmRpcCall.enterFarm("", FriendIdMap.getCurrentUid()); - if (s == null) { - Thread.sleep(RandomUtils.delay()); + FriendIdMap.waitingCurrentUid(); + String s = null; + try { s = AntFarmRpcCall.enterFarm("", FriendIdMap.getCurrentUid()); + } catch (Exception e) { + Log.i(TAG, "first AntFarmRpcCall.enterFarm err:"); + Log.printStackTrace(TAG, e); + } + int count = 1; + while (s == null) { + if (count > 5) { + throw new RuntimeException("庄园加载失败"); + } + count++; + //Thread.sleep(RandomUtils.delay()); + Thread.sleep(1000); + try { + s = AntFarmRpcCall.enterFarm("", FriendIdMap.getCurrentUid()); + } catch (Exception e) { + Log.i(TAG, "AntFarmRpcCall.enterFarm err:"); + Log.printStackTrace(TAG, e); + } } + Log.i(TAG, "AntFarmRpcCall.enterFarm success"); JSONObject jo = new JSONObject(s); if ("SUCCESS".equals(jo.getString("memo"))) { rewardProductNum = jo.getJSONObject("dynamicGlobalConfig").getString("rewardProductNum"); diff --git a/app/src/main/java/pansong291/xposed/quickenergy/AntMember.java b/app/src/main/java/pansong291/xposed/quickenergy/AntMember.java index b6d18a6e3..7a19244ba 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/AntMember.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/AntMember.java @@ -20,8 +20,7 @@ public static void receivePoint() { @Override public void run() { try { - while (FriendIdMap.getCurrentUid() == null || FriendIdMap.getCurrentUid().isEmpty()) - Thread.sleep(100); + FriendIdMap.waitingCurrentUid(); if (Statistics.canMemberSignInToday(FriendIdMap.getCurrentUid())) { String s = AntMemberRpcCall.queryMemberSigninCalendar(); JSONObject jo = new JSONObject(s); diff --git a/app/src/main/java/pansong291/xposed/quickenergy/AntOcean.java b/app/src/main/java/pansong291/xposed/quickenergy/AntOcean.java index 0504655fc..f6824e01a 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/AntOcean.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/AntOcean.java @@ -24,8 +24,7 @@ public static void start() { @Override public void run() { try { - while (FriendIdMap.getCurrentUid() == null || FriendIdMap.getCurrentUid().isEmpty()) - Thread.sleep(100); + FriendIdMap.waitingCurrentUid(); String s = AntOceanRpcCall.queryOceanStatus(); JSONObject jo = new JSONObject(s); if ("SUCCESS".equals(jo.getString("resultCode"))) { diff --git a/app/src/main/java/pansong291/xposed/quickenergy/AntSports.java b/app/src/main/java/pansong291/xposed/quickenergy/AntSports.java index 0392bdf02..67daef65b 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/AntSports.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/AntSports.java @@ -27,8 +27,7 @@ public Thread setData(ClassLoader cl) { @Override public void run() { try { - while (FriendIdMap.getCurrentUid() == null || FriendIdMap.getCurrentUid().isEmpty()) - Thread.sleep(100); + FriendIdMap.waitingCurrentUid(); if (Config.openTreasureBox()) queryMyHomePage(loader); diff --git a/app/src/main/java/pansong291/xposed/quickenergy/Reserve.java b/app/src/main/java/pansong291/xposed/quickenergy/Reserve.java index 7383c7e4f..a706ba821 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/Reserve.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/Reserve.java @@ -32,8 +32,7 @@ public static void start() { @Override public void run() { try { - while (FriendIdMap.getCurrentUid() == null || FriendIdMap.getCurrentUid().isEmpty()) - Thread.sleep(100); + FriendIdMap.waitingCurrentUid(); if (Config.reserve()) { animalReserve(); } diff --git a/app/src/main/java/pansong291/xposed/quickenergy/hook/XposedHook.java b/app/src/main/java/pansong291/xposed/quickenergy/hook/XposedHook.java index d9b365896..0e41ea339 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/hook/XposedHook.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/hook/XposedHook.java @@ -1,7 +1,6 @@ package pansong291.xposed.quickenergy.hook; import android.annotation.SuppressLint; -import android.app.Activity; import android.app.AlarmManager; import android.app.PendingIntent; import android.app.Service; @@ -12,18 +11,39 @@ import android.os.Build; import android.os.Handler; import android.os.PowerManager; + +import java.util.Calendar; +import java.util.Map; + import de.robv.android.xposed.IXposedHookLoadPackage; import de.robv.android.xposed.XC_MethodHook; import de.robv.android.xposed.XC_MethodReplacement; import de.robv.android.xposed.XposedHelpers; import de.robv.android.xposed.callbacks.XC_LoadPackage; -import pansong291.xposed.quickenergy.*; +import pansong291.xposed.quickenergy.AncientTree; +import pansong291.xposed.quickenergy.AntBookRead; +import pansong291.xposed.quickenergy.AntCooperate; +import pansong291.xposed.quickenergy.AntFarm; +import pansong291.xposed.quickenergy.AntForest; +import pansong291.xposed.quickenergy.AntForestNotification; +import pansong291.xposed.quickenergy.AntForestToast; +import pansong291.xposed.quickenergy.AntMember; +import pansong291.xposed.quickenergy.AntOcean; +import pansong291.xposed.quickenergy.AntOrchard; +import pansong291.xposed.quickenergy.AntSports; +import pansong291.xposed.quickenergy.AntStall; +import pansong291.xposed.quickenergy.ConsumeGold; +import pansong291.xposed.quickenergy.GreenFinance; +import pansong291.xposed.quickenergy.OmegakoiTown; +import pansong291.xposed.quickenergy.Reserve; import pansong291.xposed.quickenergy.data.RuntimeInfo; import pansong291.xposed.quickenergy.ui.MainActivity; -import pansong291.xposed.quickenergy.util.*; - -import java.util.Calendar; -import java.util.Map; +import pansong291.xposed.quickenergy.util.Config; +import pansong291.xposed.quickenergy.util.FriendIdMap; +import pansong291.xposed.quickenergy.util.Log; +import pansong291.xposed.quickenergy.util.PluginUtils; +import pansong291.xposed.quickenergy.util.Statistics; +import pansong291.xposed.quickenergy.util.TimeUtil; public class XposedHook implements IXposedHookLoadPackage { private static final String TAG = XposedHook.class.getCanonicalName(); @@ -92,6 +112,12 @@ public void run() { if (TimeUtil.getTimeStr().compareTo("0700") < 0 || TimeUtil.getTimeStr().compareTo("0730") > 0) { + try { + Thread.sleep(500); + } catch (InterruptedException e) { + Log.i(TAG, "sleep err:"); + Log.printStackTrace(TAG, e); + } AntCooperate.start(); AntFarm.start(); Reserve.start(); @@ -265,7 +291,7 @@ protected void afterHookedMethod(MethodHookParam param) { public static void restartHook(Context context, boolean force) { try { Intent intent; - if (force || Config.stayAwakeTarget() == StayAwakeTarget.ACTIVITY) { + if (Config.stayAwakeTarget() == StayAwakeTarget.ACTIVITY) { intent = new Intent(Intent.ACTION_VIEW); intent.setClassName(ClassMember.PACKAGE_NAME, ClassMember.CURRENT_USING_ACTIVITY); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); @@ -305,7 +331,7 @@ public static void alarmHook(Context context, long delayTime, boolean force) { try { AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); PendingIntent pi; - if (force || Config.stayAwakeTarget() == StayAwakeTarget.ACTIVITY) { + if (Config.stayAwakeTarget() == StayAwakeTarget.ACTIVITY) { Intent it = new Intent(); it.setClassName(ClassMember.PACKAGE_NAME, ClassMember.CURRENT_USING_ACTIVITY); pi = PendingIntent.getActivity(context, 1, it, getPendingIntentFlag()); diff --git a/app/src/main/java/pansong291/xposed/quickenergy/util/FriendIdMap.java b/app/src/main/java/pansong291/xposed/quickenergy/util/FriendIdMap.java index ee047facb..e732b81da 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/util/FriendIdMap.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/util/FriendIdMap.java @@ -1,15 +1,14 @@ package pansong291.xposed.quickenergy.util; -import pansong291.xposed.quickenergy.AntFarm; -import pansong291.xposed.quickenergy.hook.FriendManager; -import pansong291.xposed.quickenergy.hook.XposedHook; - import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import pansong291.xposed.quickenergy.hook.FriendManager; +import pansong291.xposed.quickenergy.hook.XposedHook; + public class FriendIdMap { private static final String TAG = FriendIdMap.class.getCanonicalName(); @@ -142,4 +141,16 @@ public static Map getIdMap() { return idMap; } + public static void waitingCurrentUid() throws InterruptedException { + int count = 1; + while (getCurrentUid() == null || getCurrentUid().isEmpty()) { + if (count > 3) { + throw new InterruptedException("获取当前用户超时"); + } else { + count++; + Thread.sleep(1000); + } + } + } + } From 3718ddfebd1bd85b771f1f31724cc0becca623cd Mon Sep 17 00:00:00 2001 From: TKaxv_7S <954067342@qq.com> Date: Wed, 29 May 2024 17:54:29 +0800 Subject: [PATCH 03/10] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xposed/quickenergy/AntFarm.java | 4 ++-- .../quickenergy/hook/AntFarmRpcCall.java | 7 ++++++- .../xposed/quickenergy/hook/RpcUtil.java | 20 ++++++++++++------- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/pansong291/xposed/quickenergy/AntFarm.java b/app/src/main/java/pansong291/xposed/quickenergy/AntFarm.java index 6e44b9b78..f010220dc 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/AntFarm.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/AntFarm.java @@ -135,7 +135,7 @@ public void run() { FriendIdMap.waitingCurrentUid(); String s = null; try { - s = AntFarmRpcCall.enterFarm("", FriendIdMap.getCurrentUid()); + s = AntFarmRpcCall.enterFarm("", FriendIdMap.getCurrentUid(), true); } catch (Exception e) { Log.i(TAG, "first AntFarmRpcCall.enterFarm err:"); Log.printStackTrace(TAG, e); @@ -149,7 +149,7 @@ public void run() { //Thread.sleep(RandomUtils.delay()); Thread.sleep(1000); try { - s = AntFarmRpcCall.enterFarm("", FriendIdMap.getCurrentUid()); + s = AntFarmRpcCall.enterFarm("", FriendIdMap.getCurrentUid(), true); } catch (Exception e) { Log.i(TAG, "AntFarmRpcCall.enterFarm err:"); Log.printStackTrace(TAG, e); diff --git a/app/src/main/java/pansong291/xposed/quickenergy/hook/AntFarmRpcCall.java b/app/src/main/java/pansong291/xposed/quickenergy/hook/AntFarmRpcCall.java index e2dc41026..970991960 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/hook/AntFarmRpcCall.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/hook/AntFarmRpcCall.java @@ -3,16 +3,21 @@ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.UUID; + import pansong291.xposed.quickenergy.util.RandomUtils; public class AntFarmRpcCall { private static final String VERSION = "1.8.2302070202.46"; public static String enterFarm(String farmId, String userId) { + return enterFarm(farmId, userId, false); + } + + public static String enterFarm(String farmId, String userId, boolean failNull) { return RpcUtil.request("com.alipay.antfarm.enterFarm", "[{\"animalId\":\"\",\"farmId\":\"" + farmId + "\",\"gotoneScene\":\"\",\"gotoneTemplateId\":\"\",\"masterFarmId\":\"\",\"queryLastRecordNum\":true,\"recall\":false,\"requestType\":\"NORMAL\",\"sceneCode\":\"ANTFARM\",\"source\":\"ANTFOREST\",\"touchRecordId\":\"\",\"userId\":\"" - + userId + "\",\"version\":\"" + VERSION + "\"}]"); + + userId + "\",\"version\":\"" + VERSION + "\"}]", failNull); } public static String syncAnimalStatus(String farmId) { diff --git a/app/src/main/java/pansong291/xposed/quickenergy/hook/RpcUtil.java b/app/src/main/java/pansong291/xposed/quickenergy/hook/RpcUtil.java index ac5f4e518..26b5d3674 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/hook/RpcUtil.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/hook/RpcUtil.java @@ -1,7 +1,12 @@ package pansong291.xposed.quickenergy.hook; -import de.robv.android.xposed.XposedHelpers; import org.json.JSONObject; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.text.DateFormat; + +import de.robv.android.xposed.XposedHelpers; import pansong291.xposed.quickenergy.AntForestNotification; import pansong291.xposed.quickenergy.AntForestToast; import pansong291.xposed.quickenergy.data.RuntimeInfo; @@ -9,10 +14,6 @@ import pansong291.xposed.quickenergy.util.Log; import pansong291.xposed.quickenergy.util.StringUtil; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.text.DateFormat; - public class RpcUtil { private static final String TAG = RpcUtil.class.getCanonicalName(); private static Method rpcCallMethod; @@ -62,6 +63,10 @@ public static String getUserId(ClassLoader classLoader) { } public static String request(String args0, String args1) { + return request(args0, args1, false); + } + + public static String request(String args0, String args1, boolean failNull) { if (isInterrupted) { return null; } @@ -90,6 +95,7 @@ public static String request(String args0, String args1) { } catch (Throwable t) { Log.i(TAG, "invoke err:"); Log.printStackTrace(TAG, t); + String result = null; if (t instanceof InvocationTargetException) { String msg = t.getCause().getMessage(); if (!StringUtil.isEmpty(msg)) { @@ -114,12 +120,12 @@ public static String request(String args0, String args1) { Log.recordLog("触发异常,等待至" + DateFormat.getDateTimeInstance().format(waitTime)); } } else if (msg.contains("MMTPException")) { - return "{\"resultCode\":\"FAIL\",\"memo\":\"MMTPException\",\"resultDesc\":\"MMTPException\"}"; + result = "{\"resultCode\":\"FAIL\",\"memo\":\"MMTPException\",\"resultDesc\":\"MMTPException\"}"; } } } + return failNull ? null : result; } - return null; } public static String getResponse(Object resp) throws Throwable { From 8cbf241aba241e3d792296f8fc0a017676ff0352 Mon Sep 17 00:00:00 2001 From: TKaxv_7S <954067342@qq.com> Date: Wed, 29 May 2024 23:08:11 +0800 Subject: [PATCH 04/10] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xposed/quickenergy/hook/XposedHook.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/pansong291/xposed/quickenergy/hook/XposedHook.java b/app/src/main/java/pansong291/xposed/quickenergy/hook/XposedHook.java index 0e41ea339..62675b69b 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/hook/XposedHook.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/hook/XposedHook.java @@ -1,6 +1,7 @@ package pansong291.xposed.quickenergy.hook; import android.annotation.SuppressLint; +import android.app.Activity; import android.app.AlarmManager; import android.app.PendingIntent; import android.app.Service; @@ -57,6 +58,8 @@ public class XposedHook implements IXposedHookLoadPackage { private static boolean isHooked = false; + private static boolean isRestart = false; + public enum StayAwakeType { BROADCAST, ALARM, NONE; @@ -173,6 +176,11 @@ private void hookService(ClassLoader loader) { protected void afterHookedMethod(MethodHookParam param) { Log.i(TAG, "Activity onResume"); RpcUtil.isInterrupted = false; + if (isRestart) { + ((Activity) param.thisObject).finish(); + isRestart = false; + return; + } //PermissionUtil.requestPermissions((Activity) param.thisObject); AntForestNotification.setContentText("运行中..."); String targetUid = RpcUtil.getUserId(loader); @@ -291,11 +299,12 @@ protected void afterHookedMethod(MethodHookParam param) { public static void restartHook(Context context, boolean force) { try { Intent intent; - if (Config.stayAwakeTarget() == StayAwakeTarget.ACTIVITY) { + if (force || Config.stayAwakeTarget() == StayAwakeTarget.ACTIVITY) { intent = new Intent(Intent.ACTION_VIEW); intent.setClassName(ClassMember.PACKAGE_NAME, ClassMember.CURRENT_USING_ACTIVITY); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); + isRestart = true; } else { intent = new Intent(); intent.setClassName(ClassMember.PACKAGE_NAME, ClassMember.CURRENT_USING_SERVICE); @@ -331,10 +340,11 @@ public static void alarmHook(Context context, long delayTime, boolean force) { try { AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); PendingIntent pi; - if (Config.stayAwakeTarget() == StayAwakeTarget.ACTIVITY) { + if (force || Config.stayAwakeTarget() == StayAwakeTarget.ACTIVITY) { Intent it = new Intent(); it.setClassName(ClassMember.PACKAGE_NAME, ClassMember.CURRENT_USING_ACTIVITY); pi = PendingIntent.getActivity(context, 1, it, getPendingIntentFlag()); + isRestart = true; } else { Intent it = new Intent(); it.setClassName(ClassMember.PACKAGE_NAME, ClassMember.CURRENT_USING_SERVICE); From 5fac7786b2ce38c4b6b42892642cc73e11747f56 Mon Sep 17 00:00:00 2001 From: TKaxv_7S <954067342@qq.com> Date: Wed, 29 May 2024 23:42:34 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pansong291/xposed/quickenergy/hook/XposedHook.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/pansong291/xposed/quickenergy/hook/XposedHook.java b/app/src/main/java/pansong291/xposed/quickenergy/hook/XposedHook.java index 62675b69b..62a7a967e 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/hook/XposedHook.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/hook/XposedHook.java @@ -304,7 +304,9 @@ public static void restartHook(Context context, boolean force) { intent.setClassName(ClassMember.PACKAGE_NAME, ClassMember.CURRENT_USING_ACTIVITY); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); - isRestart = true; + if (force) { + isRestart = true; + } } else { intent = new Intent(); intent.setClassName(ClassMember.PACKAGE_NAME, ClassMember.CURRENT_USING_SERVICE); @@ -344,7 +346,9 @@ public static void alarmHook(Context context, long delayTime, boolean force) { Intent it = new Intent(); it.setClassName(ClassMember.PACKAGE_NAME, ClassMember.CURRENT_USING_ACTIVITY); pi = PendingIntent.getActivity(context, 1, it, getPendingIntentFlag()); - isRestart = true; + if (force) { + isRestart = true; + } } else { Intent it = new Intent(); it.setClassName(ClassMember.PACKAGE_NAME, ClassMember.CURRENT_USING_SERVICE); From 4c14f1d473bd598dbeda230810c4321d9d6f639e Mon Sep 17 00:00:00 2001 From: TKaxv_7S <954067342@qq.com> Date: Thu, 30 May 2024 14:31:15 +0800 Subject: [PATCH 06/10] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xposed/quickenergy/hook/XposedHook.java | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/pansong291/xposed/quickenergy/hook/XposedHook.java b/app/src/main/java/pansong291/xposed/quickenergy/hook/XposedHook.java index 62a7a967e..78ec4d29e 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/hook/XposedHook.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/hook/XposedHook.java @@ -115,12 +115,6 @@ public void run() { if (TimeUtil.getTimeStr().compareTo("0700") < 0 || TimeUtil.getTimeStr().compareTo("0730") > 0) { - try { - Thread.sleep(500); - } catch (InterruptedException e) { - Log.i(TAG, "sleep err:"); - Log.printStackTrace(TAG, e); - } AntCooperate.start(); AntFarm.start(); Reserve.start(); @@ -176,11 +170,6 @@ private void hookService(ClassLoader loader) { protected void afterHookedMethod(MethodHookParam param) { Log.i(TAG, "Activity onResume"); RpcUtil.isInterrupted = false; - if (isRestart) { - ((Activity) param.thisObject).finish(); - isRestart = false; - return; - } //PermissionUtil.requestPermissions((Activity) param.thisObject); AntForestNotification.setContentText("运行中..."); String targetUid = RpcUtil.getUserId(loader); @@ -191,6 +180,11 @@ protected void afterHookedMethod(MethodHookParam param) { if (handler != null) { initHandler(); } + if (isRestart) { + isRestart = false; + Log.i(TAG, "Activity isRestart"); + ((Activity) param.thisObject).finish(); + } } }); Log.i(TAG, "hook login successfully"); @@ -303,10 +297,10 @@ public static void restartHook(Context context, boolean force) { intent = new Intent(Intent.ACTION_VIEW); intent.setClassName(ClassMember.PACKAGE_NAME, ClassMember.CURRENT_USING_ACTIVITY); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - context.startActivity(intent); if (force) { isRestart = true; } + context.startActivity(intent); } else { intent = new Intent(); intent.setClassName(ClassMember.PACKAGE_NAME, ClassMember.CURRENT_USING_SERVICE); From 820133035c30155ee257142efb0d19d791fd79a2 Mon Sep 17 00:00:00 2001 From: TKaxv_7S <954067342@qq.com> Date: Thu, 30 May 2024 17:10:04 +0800 Subject: [PATCH 07/10] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xposed/quickenergy/hook/XposedHook.java | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/pansong291/xposed/quickenergy/hook/XposedHook.java b/app/src/main/java/pansong291/xposed/quickenergy/hook/XposedHook.java index 78ec4d29e..a88ff686a 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/hook/XposedHook.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/hook/XposedHook.java @@ -63,13 +63,13 @@ public class XposedHook implements IXposedHookLoadPackage { public enum StayAwakeType { BROADCAST, ALARM, NONE; - public static final CharSequence[] nickNames = { "广播", "闹钟", "不重启" }; + public static final CharSequence[] nickNames = {"广播", "闹钟", "不重启"}; } public enum StayAwakeTarget { SERVICE, ACTIVITY; - public static final CharSequence[] nickNames = { "Service", "Activity" }; + public static final CharSequence[] nickNames = {"Service", "Activity"}; } @Override @@ -98,6 +98,16 @@ protected void beforeHookedMethod(MethodHookParam param) { } } + private static void restartHandler() { + if (handler != null && runnable != null) { + handler.removeCallbacks(runnable); + AntForest.stop(); + AntForestNotification.stop(service, false); + AntForestNotification.start(service); + handler.post(runnable); + } + } + private static void initHandler() { Log.recordLog("尝试初始化"); if (runnable == null) { @@ -150,12 +160,8 @@ public void run() { Config.setAlarm7(AntForestToast.context); } } + restartHandler(); AntForestToast.show("芝麻粒加载成功"); - handler.removeCallbacks(runnable); - AntForest.stop(); - AntForestNotification.stop(service, false); - AntForestNotification.start(service); - handler.post(runnable); } catch (Throwable th) { Log.i(TAG, "initHandler err:"); Log.printStackTrace(TAG, th); @@ -173,17 +179,21 @@ protected void afterHookedMethod(MethodHookParam param) { //PermissionUtil.requestPermissions((Activity) param.thisObject); AntForestNotification.setContentText("运行中..."); String targetUid = RpcUtil.getUserId(loader); - if (targetUid == null || targetUid.equals(FriendIdMap.getCurrentUid())) { + if (targetUid == null) { return; } - FriendIdMap.setCurrentUid(targetUid); - if (handler != null) { - initHandler(); + if (!targetUid.equals(FriendIdMap.getCurrentUid())) { + FriendIdMap.setCurrentUid(targetUid); + } else if (!isRestart) { + return; } if (isRestart) { - isRestart = false; Log.i(TAG, "Activity isRestart"); + isRestart = false; + restartHandler(); ((Activity) param.thisObject).finish(); + } else if (handler != null) { + initHandler(); } } }); From 585b79e855c93f4d6d735fd2c700a119f30ab02d Mon Sep 17 00:00:00 2001 From: TKaxv_7S <954067342@qq.com> Date: Thu, 30 May 2024 17:50:20 +0800 Subject: [PATCH 08/10] =?UTF-8?q?=E4=BC=98=E5=8C=96=20=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xposed/quickenergy/AntFarm.java | 25 +--- .../quickenergy/hook/AntFarmRpcCall.java | 6 +- .../xposed/quickenergy/hook/RpcUtil.java | 110 ++++++++++-------- 3 files changed, 65 insertions(+), 76 deletions(-) diff --git a/app/src/main/java/pansong291/xposed/quickenergy/AntFarm.java b/app/src/main/java/pansong291/xposed/quickenergy/AntFarm.java index f010220dc..c4a281660 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/AntFarm.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/AntFarm.java @@ -133,29 +133,10 @@ public static void start() { public void run() { try { FriendIdMap.waitingCurrentUid(); - String s = null; - try { - s = AntFarmRpcCall.enterFarm("", FriendIdMap.getCurrentUid(), true); - } catch (Exception e) { - Log.i(TAG, "first AntFarmRpcCall.enterFarm err:"); - Log.printStackTrace(TAG, e); + String s = AntFarmRpcCall.enterFarm("", FriendIdMap.getCurrentUid()); + if (s == null) { + throw new RuntimeException("庄园加载失败"); } - int count = 1; - while (s == null) { - if (count > 5) { - throw new RuntimeException("庄园加载失败"); - } - count++; - //Thread.sleep(RandomUtils.delay()); - Thread.sleep(1000); - try { - s = AntFarmRpcCall.enterFarm("", FriendIdMap.getCurrentUid(), true); - } catch (Exception e) { - Log.i(TAG, "AntFarmRpcCall.enterFarm err:"); - Log.printStackTrace(TAG, e); - } - } - Log.i(TAG, "AntFarmRpcCall.enterFarm success"); JSONObject jo = new JSONObject(s); if ("SUCCESS".equals(jo.getString("memo"))) { rewardProductNum = jo.getJSONObject("dynamicGlobalConfig").getString("rewardProductNum"); diff --git a/app/src/main/java/pansong291/xposed/quickenergy/hook/AntFarmRpcCall.java b/app/src/main/java/pansong291/xposed/quickenergy/hook/AntFarmRpcCall.java index 970991960..bb74e5022 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/hook/AntFarmRpcCall.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/hook/AntFarmRpcCall.java @@ -10,14 +10,10 @@ public class AntFarmRpcCall { private static final String VERSION = "1.8.2302070202.46"; public static String enterFarm(String farmId, String userId) { - return enterFarm(farmId, userId, false); - } - - public static String enterFarm(String farmId, String userId, boolean failNull) { return RpcUtil.request("com.alipay.antfarm.enterFarm", "[{\"animalId\":\"\",\"farmId\":\"" + farmId + "\",\"gotoneScene\":\"\",\"gotoneTemplateId\":\"\",\"masterFarmId\":\"\",\"queryLastRecordNum\":true,\"recall\":false,\"requestType\":\"NORMAL\",\"sceneCode\":\"ANTFARM\",\"source\":\"ANTFOREST\",\"touchRecordId\":\"\",\"userId\":\"" - + userId + "\",\"version\":\"" + VERSION + "\"}]", failNull); + + userId + "\",\"version\":\"" + VERSION + "\"}]"); } public static String syncAnimalStatus(String farmId) { diff --git a/app/src/main/java/pansong291/xposed/quickenergy/hook/RpcUtil.java b/app/src/main/java/pansong291/xposed/quickenergy/hook/RpcUtil.java index 26b5d3674..b13f28fe4 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/hook/RpcUtil.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/hook/RpcUtil.java @@ -12,6 +12,7 @@ import pansong291.xposed.quickenergy.data.RuntimeInfo; import pansong291.xposed.quickenergy.util.Config; import pansong291.xposed.quickenergy.util.Log; +import pansong291.xposed.quickenergy.util.RandomUtils; import pansong291.xposed.quickenergy.util.StringUtil; public class RpcUtil { @@ -63,69 +64,80 @@ public static String getUserId(ClassLoader classLoader) { } public static String request(String args0, String args1) { - return request(args0, args1, false); - } - - public static String request(String args0, String args1, boolean failNull) { if (isInterrupted) { return null; } - try { - Object o; - if (rpcCallMethod.getParameterTypes().length == 12) { - o = rpcCallMethod.invoke( - null, args0, args1, "", true, null, null, false, curH5PageImpl, 0, "", false, -1); - } else { - o = rpcCallMethod.invoke( - null, args0, args1, "", true, null, null, false, curH5PageImpl, 0, "", false, -1, ""); - } - String str = getResponse(o); - Log.i(TAG, "argument: " + args0 + ", " + args1); - Log.i(TAG, "response: " + str); + String result = null; + int count = 0; + while (count < 3) { + count++; try { - JSONObject jo = new JSONObject(str); - if (jo.optString("memo", "").contains("系统繁忙")) { - isInterrupted = true; - AntForestNotification.setContentText("系统繁忙,可能需要滑动验证"); - Log.recordLog("系统繁忙,可能需要滑动验证"); - return str; + Object o; + if (rpcCallMethod.getParameterTypes().length == 12) { + o = rpcCallMethod.invoke( + null, args0, args1, "", true, null, null, false, curH5PageImpl, 0, "", false, -1); + } else { + o = rpcCallMethod.invoke( + null, args0, args1, "", true, null, null, false, curH5PageImpl, 0, "", false, -1, ""); } - } catch (Throwable ignored) { } - return str; - } catch (Throwable t) { - Log.i(TAG, "invoke err:"); - Log.printStackTrace(TAG, t); - String result = null; - if (t instanceof InvocationTargetException) { - String msg = t.getCause().getMessage(); - if (!StringUtil.isEmpty(msg)) { - if (msg.contains("登录超时")) { + String str = getResponse(o); + Log.i(TAG, "argument: " + args0 + ", " + args1); + Log.i(TAG, "response: " + str); + try { + JSONObject jo = new JSONObject(str); + if (jo.optString("memo", "").contains("系统繁忙")) { isInterrupted = true; - AntForestNotification.setContentText("登录超时"); - if (AntForestToast.context != null) { - if (Config.timeoutRestart()) { - Log.recordLog("尝试重启!"); - if (Config.timeoutType() == XposedHook.StayAwakeType.ALARM) { - XposedHook.alarmHook(AntForestToast.context, 3000, true); - } else { - XposedHook.alarmBroadcast(AntForestToast.context, 3000, true); + AntForestNotification.setContentText("系统繁忙,可能需要滑动验证"); + Log.recordLog("系统繁忙,可能需要滑动验证"); + return str; + } + } catch (Throwable ignored) { + } + return str; + } catch (Throwable t) { + Log.i(TAG, "rpc [" + args0 + "] err:"); + Log.printStackTrace(TAG, t); + result = null; + if (t instanceof InvocationTargetException) { + String msg = t.getCause().getMessage(); + if (!StringUtil.isEmpty(msg)) { + if (msg.contains("登录超时")) { + isInterrupted = true; + AntForestNotification.setContentText("登录超时"); + if (AntForestToast.context != null) { + if (Config.timeoutRestart()) { + Log.recordLog("尝试重启!"); + if (Config.timeoutType() == XposedHook.StayAwakeType.ALARM) { + XposedHook.alarmHook(AntForestToast.context, 3000, true); + } else { + XposedHook.alarmBroadcast(AntForestToast.context, 3000, true); + } } } + } else if (msg.contains("[1004]") && "alipay.antmember.forest.h5.collectEnergy".equals(args0)) { + if (Config.waitWhenException() > 0) { + long waitTime = System.currentTimeMillis() + Config.waitWhenException(); + RuntimeInfo.getInstance().put(RuntimeInfo.RuntimeInfoKey.ForestPauseTime, waitTime); + AntForestNotification.setContentText("触发异常,等待至" + DateFormat.getDateTimeInstance().format(waitTime)); + Log.recordLog("触发异常,等待至" + DateFormat.getDateTimeInstance().format(waitTime)); + } + } else if (msg.contains("MMTPException")) { + result = "{\"resultCode\":\"FAIL\",\"memo\":\"MMTPException\",\"resultDesc\":\"MMTPException\"}"; + } else { + return result; } - } else if (msg.contains("[1004]") && "alipay.antmember.forest.h5.collectEnergy".equals(args0)) { - if (Config.waitWhenException() > 0) { - long waitTime = System.currentTimeMillis() + Config.waitWhenException(); - RuntimeInfo.getInstance().put(RuntimeInfo.RuntimeInfoKey.ForestPauseTime, waitTime); - AntForestNotification.setContentText("触发异常,等待至" + DateFormat.getDateTimeInstance().format(waitTime)); - Log.recordLog("触发异常,等待至" + DateFormat.getDateTimeInstance().format(waitTime)); + try { + Thread.sleep(900 + RandomUtils.delay()); + } catch (InterruptedException e) { + throw new RuntimeException(e); } - } else if (msg.contains("MMTPException")) { - result = "{\"resultCode\":\"FAIL\",\"memo\":\"MMTPException\",\"resultDesc\":\"MMTPException\"}"; + continue; } } + return result; } - return failNull ? null : result; } + return result; } public static String getResponse(Object resp) throws Throwable { From 3c0cb46968936726aaee3819952a56d10d6b9c49 Mon Sep 17 00:00:00 2001 From: TKaxv_7S <954067342@qq.com> Date: Thu, 30 May 2024 18:30:17 +0800 Subject: [PATCH 09/10] =?UTF-8?q?=E4=BC=98=E5=8C=96=20=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xposed/quickenergy/hook/RpcUtil.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/pansong291/xposed/quickenergy/hook/RpcUtil.java b/app/src/main/java/pansong291/xposed/quickenergy/hook/RpcUtil.java index b13f28fe4..3243b30e6 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/hook/RpcUtil.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/hook/RpcUtil.java @@ -121,17 +121,21 @@ public static String request(String args0, String args1) { AntForestNotification.setContentText("触发异常,等待至" + DateFormat.getDateTimeInstance().format(waitTime)); Log.recordLog("触发异常,等待至" + DateFormat.getDateTimeInstance().format(waitTime)); } + try { + Thread.sleep(900 + RandomUtils.delay()); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + continue; } else if (msg.contains("MMTPException")) { result = "{\"resultCode\":\"FAIL\",\"memo\":\"MMTPException\",\"resultDesc\":\"MMTPException\"}"; - } else { - return result; - } - try { - Thread.sleep(900 + RandomUtils.delay()); - } catch (InterruptedException e) { - throw new RuntimeException(e); + try { + Thread.sleep(900 + RandomUtils.delay()); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + continue; } - continue; } } return result; From c821ad85a38394770663e560ee29ff434a678fc6 Mon Sep 17 00:00:00 2001 From: TKaxv_7S <954067342@qq.com> Date: Fri, 31 May 2024 01:32:33 +0800 Subject: [PATCH 10/10] =?UTF-8?q?=E4=BC=98=E5=8C=96=20=E9=87=8D=E5=90=AF?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E9=81=BF=E5=85=8D=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E4=B8=AD=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xposed/quickenergy/AntForest.java | 1 + .../xposed/quickenergy/hook/RpcUtil.java | 22 +++++++++++-------- .../xposed/quickenergy/hook/XposedHook.java | 18 ++++++++++----- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/pansong291/xposed/quickenergy/AntForest.java b/app/src/main/java/pansong291/xposed/quickenergy/AntForest.java index 6e777dc25..b60abc31f 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/AntForest.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/AntForest.java @@ -360,6 +360,7 @@ private static void canCollectSelfEnergy() { try { boolean hasMore = false; long start = System.currentTimeMillis(); + //TODO 修复 6秒拼手速活动导致数据错误,目前只能关闭该活动 String s = AntForestRpcCall.queryHomePage(); long end = System.currentTimeMillis(); if (s == null) { diff --git a/app/src/main/java/pansong291/xposed/quickenergy/hook/RpcUtil.java b/app/src/main/java/pansong291/xposed/quickenergy/hook/RpcUtil.java index 3243b30e6..df7cffe8c 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/hook/RpcUtil.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/hook/RpcUtil.java @@ -102,18 +102,22 @@ public static String request(String args0, String args1) { String msg = t.getCause().getMessage(); if (!StringUtil.isEmpty(msg)) { if (msg.contains("登录超时")) { - isInterrupted = true; - AntForestNotification.setContentText("登录超时"); - if (AntForestToast.context != null) { - if (Config.timeoutRestart()) { - Log.recordLog("尝试重启!"); - if (Config.timeoutType() == XposedHook.StayAwakeType.ALARM) { - XposedHook.alarmHook(AntForestToast.context, 3000, true); - } else { - XposedHook.alarmBroadcast(AntForestToast.context, 3000, true); + if (!isInterrupted && !XposedHook.getIsRestart()) { + isInterrupted = true; + AntForestNotification.setContentText("登录超时"); + if (AntForestToast.context != null) { + if (Config.timeoutRestart()) { + Log.recordLog("尝试重启!"); + XposedHook.restartHook(AntForestToast.context, Config.timeoutType(), 500, true); } } } + try { + Thread.sleep(3000 + RandomUtils.delay()); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + continue; } else if (msg.contains("[1004]") && "alipay.antmember.forest.h5.collectEnergy".equals(args0)) { if (Config.waitWhenException() > 0) { long waitTime = System.currentTimeMillis() + Config.waitWhenException(); diff --git a/app/src/main/java/pansong291/xposed/quickenergy/hook/XposedHook.java b/app/src/main/java/pansong291/xposed/quickenergy/hook/XposedHook.java index a88ff686a..ad46c7796 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/hook/XposedHook.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/hook/XposedHook.java @@ -72,6 +72,10 @@ public enum StayAwakeTarget { public static final CharSequence[] nickNames = {"Service", "Activity"}; } + public static boolean getIsRestart() { + return isRestart; + } + @Override public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) { if ("pansong291.xposed.quickenergy.repair".equals(lpparam.packageName)) { @@ -225,11 +229,7 @@ protected void afterHookedMethod(MethodHookParam param) { wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, service.getClass().getName()); wakeLock.acquire(); - if (Config.stayAwakeType() == StayAwakeType.BROADCAST) { - alarmBroadcast(AntForestToast.context, 30 * 60 * 1000, false); - } else if (Config.stayAwakeType() == StayAwakeType.ALARM) { - alarmHook(AntForestToast.context, 30 * 60 * 1000, false); - } + restartHook(AntForestToast.context, Config.stayAwakeType(), 30 * 60 * 1000, false); } initHandler(); } @@ -300,6 +300,14 @@ protected void afterHookedMethod(MethodHookParam param) { } + public static void restartHook(Context context, StayAwakeType stayAwakeType, long delayTime, boolean force) { + if (stayAwakeType == StayAwakeType.ALARM) { + alarmHook(context, delayTime, force); + } else { + alarmBroadcast(context, delayTime, force); + } + } + public static void restartHook(Context context, boolean force) { try { Intent intent;