Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,22 @@ class PassPhrasesInRAMService : BaseLifecycleService() {
}

else -> {
val notification = prepareNotification(
useActionButton = keysStorage.hasNonEmptyPassphrase(KeyEntity.PassphraseType.RAM)
)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
startForeground(
R.id.notification_id_passphrase_service, notification,
//https://developer.android.com/about/versions/14/changes/fgs-types-required#permission-for-fgs-type
ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE
)
if (intent != null) {
//checking intent != null will prevent recreating the service after the system killed it
startForeground(
R.id.notification_id_passphrase_service,
prepareNotification(keysStorage.hasNonEmptyPassphrase(KeyEntity.PassphraseType.RAM)),
//https://developer.android.com/about/versions/14/changes/fgs-types-required#permission-for-fgs-type
ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE
)
} else {
stopSelf()
}
} else {
startForeground(
R.id.notification_id_passphrase_service, notification
R.id.notification_id_passphrase_service,
prepareNotification(keysStorage.hasNonEmptyPassphrase(KeyEntity.PassphraseType.RAM))
)
}
}
Expand All @@ -82,6 +86,16 @@ class PassPhrasesInRAMService : BaseLifecycleService() {
private fun subscribeToPassphrasesUpdates() {
lifecycleScope.launch {
keysStorage.getPassPhrasesUpdatesFlow().collect {
if (
Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE &&
foregroundServiceType != ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE
) {
NotificationManagerCompat.from(applicationContext).cancel(
R.id.notification_id_passphrase_service
)
return@collect
}

updateNotification(keysStorage.hasNonEmptyPassphrase(KeyEntity.PassphraseType.RAM))
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com
* Contributors: DenBond7
* Contributors: denbond7
*/

package com.flowcrypt.email.ui.activity
Expand All @@ -21,6 +21,7 @@ import androidx.appcompat.widget.Toolbar
import androidx.core.view.MenuProvider
import androidx.core.view.allViews
import androidx.drawerlayout.widget.DrawerLayout
import androidx.lifecycle.Lifecycle
import androidx.navigation.NavController
import androidx.navigation.NavDestination
import androidx.navigation.fragment.NavHostFragment
Expand Down Expand Up @@ -206,7 +207,9 @@ abstract class BaseActivity<T : ViewBinding> : AppCompatActivity() {
val hasTemporaryPassPhrases =
keysStorage.getRawKeys().any { it.passphraseType == KeyEntity.PassphraseType.RAM }
if (hasTemporaryPassPhrases) {
PassPhrasesInRAMService.start(this)
if (lifecycle.currentState in listOf(Lifecycle.State.STARTED, Lifecycle.State.RESUMED)) {
PassPhrasesInRAMService.start(this@BaseActivity)
}
} else {
PassPhrasesInRAMService.stop(this)
}
Expand Down