From f729d6682c10c2b1a3eae064a421aa2e475d167c Mon Sep 17 00:00:00 2001 From: Nguyen Van Nam Date: Sun, 17 May 2026 04:30:40 +0700 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20resolve=20#1114=20=E2=80=94=201.9.13?= =?UTF-8?q?=E5=9C=A8android=2026=EF=BC=88=E5=90=AB=EF=BC=89=E4=BB=A5?= =?UTF-8?q?=E4=B8=8A=E6=97=A0=E6=B3=95=E5=90=88=E6=88=90=E8=A1=A5=E4=B8=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #1114 Signed-off-by: Nguyen Van Nam --- .../lib/service/TinkerPatchService.java | 58 ++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/tinker-android/tinker-android-lib/src/main/java/com/tencent/tinker/lib/service/TinkerPatchService.java b/tinker-android/tinker-android-lib/src/main/java/com/tencent/tinker/lib/service/TinkerPatchService.java index d88721705..580e26c31 100644 --- a/tinker-android/tinker-android-lib/src/main/java/com/tencent/tinker/lib/service/TinkerPatchService.java +++ b/tinker-android/tinker-android-lib/src/main/java/com/tencent/tinker/lib/service/TinkerPatchService.java @@ -21,6 +21,8 @@ import android.app.ActivityManager; import android.app.IntentService; import android.app.Notification; +import android.app.NotificationChannel; +import android.app.NotificationManager; import android.app.Service; import android.content.Context; import android.content.Intent; @@ -53,6 +55,15 @@ public class TinkerPatchService extends IntentService { private static AbstractPatch upgradePatchProcessor = null; private static int notificationId = ShareConstants.TINKER_PATCH_SERVICE_NOTIFICATION; private static Class resultServiceClass = null; + private static ForegroundNotificationFactory foregroundNotificationFactory = null; + + public interface ForegroundNotificationFactory { + Notification create(Service service); + } + + public static void setForegroundNotificationFactory(ForegroundNotificationFactory factory) { + foregroundNotificationFactory = factory; + } public TinkerPatchService() { super("TinkerPatchService"); @@ -70,7 +81,11 @@ public static void runPatchService(final Context context, final String path, boo intent.putExtra(PATCH_USE_EMERGENCY_MODE, useEmergencyMode); intent.putExtra(RESULT_CLASS_EXTRA, resultServiceClass.getName()); try { - context.startService(intent); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + context.startForegroundService(intent); + } else { + context.startService(intent); + } } catch (Throwable thr) { ShareTinkerLog.e(TAG, "run patch service fail, exception:" + thr); } @@ -108,6 +123,47 @@ public static String getPatchResultExtra(Intent intent) { return ShareIntentUtil.getStringExtra(intent, RESULT_CLASS_EXTRA); } + @Override + public void onCreate() { + super.onCreate(); + ensureForeground(); + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + ensureForeground(); + return super.onStartCommand(intent, flags, startId); + } + + private void ensureForeground() { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { + return; + } + try { + startForeground(notificationId, createForegroundNotification()); + } catch (Throwable thr) { + ShareTinkerLog.e(TAG, "startForeground fail, exception:" + thr); + } + } + + private Notification createForegroundNotification() { + if (foregroundNotificationFactory != null) { + return foregroundNotificationFactory.create(this); + } + final String channelId = "tinker_patch_service"; + final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + if (nm != null && nm.getNotificationChannel(channelId) == null) { + final NotificationChannel channel = new NotificationChannel(channelId, "TinkerPatchService", NotificationManager.IMPORTANCE_LOW); + nm.createNotificationChannel(channel); + } + return new Notification.Builder(this, channelId) + .setSmallIcon(getApplicationInfo().icon) + .setContentTitle("Tinker") + .setContentText("Applying patch") + .setOngoing(true) + .build(); + } + @Override protected void onHandleIntent(Intent intent) { increasingPriority(); From fda369f782445f7f193c6cc9abba426b04a5d7f4 Mon Sep 17 00:00:00 2001 From: Nguyen Van Nam Date: Sun, 17 May 2026 04:30:41 +0700 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20resolve=20#1114=20=E2=80=94=201.9.13?= =?UTF-8?q?=E5=9C=A8android=2026=EF=BC=88=E5=90=AB=EF=BC=89=E4=BB=A5?= =?UTF-8?q?=E4=B8=8A=E6=97=A0=E6=B3=95=E5=90=88=E6=88=90=E8=A1=A5=E4=B8=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #1114 Signed-off-by: Nguyen Van Nam --- tinker-android/tinker-android-lib/src/main/AndroidManifest.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tinker-android/tinker-android-lib/src/main/AndroidManifest.xml b/tinker-android/tinker-android-lib/src/main/AndroidManifest.xml index b65c036b8..313069575 100644 --- a/tinker-android/tinker-android-lib/src/main/AndroidManifest.xml +++ b/tinker-android/tinker-android-lib/src/main/AndroidManifest.xml @@ -2,6 +2,8 @@ + + Date: Sun, 17 May 2026 04:30:42 +0700 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20resolve=20#1114=20=E2=80=94=201.9.13?= =?UTF-8?q?=E5=9C=A8android=2026=EF=BC=88=E5=90=AB=EF=BC=89=E4=BB=A5?= =?UTF-8?q?=E4=B8=8A=E6=97=A0=E6=B3=95=E5=90=88=E6=88=90=E8=A1=A5=E4=B8=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #1114 Signed-off-by: Nguyen Van Nam --- .../service/DefaultTinkerResultService.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tinker-android/tinker-android-lib/src/main/java/com/tencent/tinker/lib/service/DefaultTinkerResultService.java b/tinker-android/tinker-android-lib/src/main/java/com/tencent/tinker/lib/service/DefaultTinkerResultService.java index 11f24b35e..46681f1ad 100644 --- a/tinker-android/tinker-android-lib/src/main/java/com/tencent/tinker/lib/service/DefaultTinkerResultService.java +++ b/tinker-android/tinker-android-lib/src/main/java/com/tencent/tinker/lib/service/DefaultTinkerResultService.java @@ -17,6 +17,12 @@ package com.tencent.tinker.lib.service; +import android.app.Notification; +import android.app.NotificationChannel; +import android.app.NotificationManager; +import android.content.Context; +import android.os.Build; + import com.tencent.tinker.lib.tinker.Tinker; import com.tencent.tinker.lib.tinker.TinkerLoadResult; import com.tencent.tinker.loader.shareutil.ShareTinkerLog; @@ -102,5 +108,28 @@ public boolean checkIfNeedKill(PatchResult result) { return true; } + public static class DefaultNotificationProvider { + public static final int NOTIFICATION_ID = 0x1; + private static final String CHANNEL_ID = "tinker_patch"; + private static final String CHANNEL_NAME = "Tinker Patch"; + + public static Notification createNotification(Context context) { + final Notification.Builder builder; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + final NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); + if (manager != null) { + manager.createNotificationChannel(new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_LOW)); + } + builder = new Notification.Builder(context, CHANNEL_ID); + } else { + builder = new Notification.Builder(context); + } + return builder.setContentTitle("Tinker") + .setContentText("Applying patch") + .setOngoing(true) + .setSmallIcon(context.getApplicationInfo().icon) + .build(); + } + } }