@@ -60,18 +60,22 @@ class PassPhrasesInRAMService : BaseLifecycleService() {
6060 }
6161
6262 else -> {
63- val notification = prepareNotification(
64- useActionButton = keysStorage.hasNonEmptyPassphrase(KeyEntity .PassphraseType .RAM )
65- )
6663 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .UPSIDE_DOWN_CAKE ) {
67- startForeground(
68- R .id.notification_id_passphrase_service, notification,
69- // https://developer.android.com/about/versions/14/changes/fgs-types-required#permission-for-fgs-type
70- ServiceInfo .FOREGROUND_SERVICE_TYPE_SPECIAL_USE
71- )
64+ if (intent != null ) {
65+ // checking intent != null will prevent recreating the service after the system killed it
66+ startForeground(
67+ R .id.notification_id_passphrase_service,
68+ prepareNotification(keysStorage.hasNonEmptyPassphrase(KeyEntity .PassphraseType .RAM )),
69+ // https://developer.android.com/about/versions/14/changes/fgs-types-required#permission-for-fgs-type
70+ ServiceInfo .FOREGROUND_SERVICE_TYPE_SPECIAL_USE
71+ )
72+ } else {
73+ stopSelf()
74+ }
7275 } else {
7376 startForeground(
74- R .id.notification_id_passphrase_service, notification
77+ R .id.notification_id_passphrase_service,
78+ prepareNotification(keysStorage.hasNonEmptyPassphrase(KeyEntity .PassphraseType .RAM ))
7579 )
7680 }
7781 }
@@ -82,6 +86,16 @@ class PassPhrasesInRAMService : BaseLifecycleService() {
8286 private fun subscribeToPassphrasesUpdates () {
8387 lifecycleScope.launch {
8488 keysStorage.getPassPhrasesUpdatesFlow().collect {
89+ if (
90+ Build .VERSION .SDK_INT >= Build .VERSION_CODES .UPSIDE_DOWN_CAKE &&
91+ foregroundServiceType != ServiceInfo .FOREGROUND_SERVICE_TYPE_SPECIAL_USE
92+ ) {
93+ NotificationManagerCompat .from(applicationContext).cancel(
94+ R .id.notification_id_passphrase_service
95+ )
96+ return @collect
97+ }
98+
8599 updateNotification(keysStorage.hasNonEmptyPassphrase(KeyEntity .PassphraseType .RAM ))
86100 }
87101 }
0 commit comments