From 33b68936ea257bfb6305ba08cd17b3ac032a1ae2 Mon Sep 17 00:00:00 2001 From: emanuele-f Date: Wed, 1 Jun 2022 15:46:27 +0200 Subject: [PATCH] Fix developer warning notification on Android 32 Bug introduced in bd6034b. Now notification is correctly removed --- .../com/emanuelef/remote_capture/CaptureService.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/emanuelef/remote_capture/CaptureService.java b/app/src/main/java/com/emanuelef/remote_capture/CaptureService.java index 034045b6..cd9b2936 100644 --- a/app/src/main/java/com/emanuelef/remote_capture/CaptureService.java +++ b/app/src/main/java/com/emanuelef/remote_capture/CaptureService.java @@ -130,6 +130,7 @@ public class CaptureService extends VpnService implements Runnable { private boolean mDnsEncrypted; private boolean mStrictDnsNoticeShown; private boolean mQueueFull; + private boolean mStopping; private Blacklists mBlacklists; private MatchList mBlocklist; private MatchList mWhitelist; @@ -196,6 +197,8 @@ public class CaptureService extends VpnService implements Runnable { @Override public int onStartCommand(@Nullable Intent intent, int flags, int startId) { + mStopping = false; + // startForeground must always be called since the Service is being started with // ContextCompat.startForegroundService. // NOTE: since Android 12, startForeground cannot be called when the app is in background @@ -516,6 +519,9 @@ public class CaptureService extends VpnService implements Runnable { } private void updateNotification() { + if(mStopping) + return; + Notification notification = getStatusNotification(); NotificationManagerCompat.from(this).notify(NOTIFY_ID_VPNSERVICE, notification); } @@ -693,6 +699,8 @@ public class CaptureService extends VpnService implements Runnable { if(captureService == null) return; + captureService.mStopping = true; + stopPacketLoop(); captureService.signalServicesTermination(); @@ -701,9 +709,6 @@ public class CaptureService extends VpnService implements Runnable { else captureService.stopForeground(true); - // this fixes notification not removed (reproduced on the Android 12 emulator) - NotificationManagerCompat.from(captureService).deleteNotificationChannel(NOTIFY_CHAN_VPNSERVICE); - captureService.stopSelf(); }