From 22b81f8c46cb586ba8c4fc2fdd8179977933c25d Mon Sep 17 00:00:00 2001 From: Matthew Date: Wed, 7 May 2025 17:32:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=87=8D=E5=90=AF=E8=BF=90?= =?UTF-8?q?=E7=BB=B4=E7=9A=84=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/xypower/mpapp/MicroPhotoService.java | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java index a9d8734c..850ffad7 100644 --- a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java +++ b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java @@ -33,7 +33,6 @@ import android.net.NetworkInfo; import android.net.NetworkRequest; import android.net.Uri; import android.net.wifi.WifiManager; -import android.os.BatteryManager; import android.os.Build; import android.os.Bundle; import android.os.Handler; @@ -79,13 +78,11 @@ import java.io.Reader; import java.lang.reflect.Method; import java.net.Inet4Address; import java.net.InetAddress; -import java.nio.channels.FileLock; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.concurrent.atomic.AtomicInteger; public class MicroPhotoService extends Service { public static final String TAG = "MPLOG"; @@ -502,7 +499,7 @@ public class MicroPhotoService extends Service { boolean mpmstAlive = isMpMasterAlive(context); if (!mpmstAlive) { Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(MicroPhotoContext.PACKAGE_NAME_MPMASTER); - // launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); + launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); if (launchIntent != null) { context.startActivity(launchIntent); } @@ -558,6 +555,25 @@ public class MicroPhotoService extends Service { } catch (Exception ex) { ex.printStackTrace(); } + + try { + boolean mpmstAlive = isMpMasterAlive(context); + if (!mpmstAlive) { + if (Build.TIME >= 1744905600000L) { + int pid = MicroPhotoContext.getProcessIdOfService(context, MicroPhotoContext.PACKAGE_NAME_MPMASTER, MicroPhotoContext.SERVICE_NAME_MPMASTER); + if (pid != 0) { + android.os.Process.killProcess(pid); + } + } + Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(MicroPhotoContext.PACKAGE_NAME_MPMASTER); + if (launchIntent != null) { + launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); + mService.startActivity(launchIntent); + } + } + } catch (Exception ex) { + ex.printStackTrace(); + } } } }