Fix notification sometimes not removed on stop

Fixes #198
This commit is contained in:
emanuele-f 2022-05-31 00:15:04 +02:00
parent e221fad374
commit bd6034b8c6
2 changed files with 11 additions and 1 deletions

View File

@ -681,13 +681,22 @@ public class CaptureService extends VpnService implements Runnable {
* when mCaptureThread terminates. */ * when mCaptureThread terminates. */
public static void stopService() { public static void stopService() {
CaptureService captureService = INSTANCE; CaptureService captureService = INSTANCE;
Log.d(TAG, "stopService called (instance? " + (captureService != null) + ")");
if(captureService == null) if(captureService == null)
return; return;
stopPacketLoop(); stopPacketLoop();
captureService.signalServicesTermination(); captureService.signalServicesTermination();
captureService.stopForeground(true /* remove notification */); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
captureService.stopForeground(STOP_FOREGROUND_REMOVE);
else
captureService.stopForeground(true);
// this fixes notification not removed (reproduced on the Android 12 emulator)
NotificationManagerCompat.from(captureService).deleteNotificationChannel(NOTIFY_CHAN_VPNSERVICE);
captureService.stopSelf(); captureService.stopSelf();
} }

View File

@ -732,6 +732,7 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
intent.setType("*/*"); intent.setType("*/*");
intent.putExtra(Intent.EXTRA_TITLE, "sslkeylogfile.txt"); intent.putExtra(Intent.EXTRA_TITLE, "sslkeylogfile.txt");
Log.d(TAG, "startExportSslkeylogfile: launching dialog");
Utils.launchFileDialog(this, intent, sslkeyfileExportLauncher); Utils.launchFileDialog(this, intent, sslkeyfileExportLauncher);
} }