android: update service (#792)

This commit is contained in:
Evgeny Poberezkin
2022-07-07 23:00:42 +01:00
committed by GitHub
parent 2b7de2a7a6
commit fdad58b0ee
3 changed files with 4 additions and 3 deletions

View File

@@ -74,6 +74,7 @@ class SimplexApp: Application(), LifecycleEventObserver {
if (chatModel.onboardingStage.value == OnboardingStage.OnboardingComplete) {
chatController.showBackgroundServiceNoticeIfNeeded()
}
else -> {}
}
}
}

View File

@@ -7,6 +7,7 @@ import android.util.Log
import androidx.core.app.NotificationCompat
import androidx.core.content.ContextCompat
import androidx.work.*
import chat.simplex.app.model.AppPreferences
import chat.simplex.app.views.helpers.withApi
import chat.simplex.app.views.onboarding.OnboardingStage
import kotlinx.coroutines.Dispatchers
@@ -48,7 +49,6 @@ class SimplexService: Service() {
val text = getString(R.string.simplex_service_notification_text)
notificationManager = createNotificationChannel()
serviceNotification = createNotification(title, text)
startForeground(SIMPLEX_SERVICE_ID, serviceNotification)
}
@@ -88,7 +88,7 @@ class SimplexService: Service() {
private fun stopService() {
Log.d(TAG, "Stopping foreground service")
if (!isServiceStarted || isStoppingService) return
if (isStoppingService) return
isStoppingService = true
try {
wakeLock?.let {
@@ -215,6 +215,7 @@ class SimplexService: Service() {
suspend fun stop(context: Context) = serviceAction(context, Action.STOP)
private suspend fun serviceAction(context: Context, action: Action) {
if (!AppPreferences(context).runServiceInBackground.get()) { return }
Log.d(TAG, "SimplexService serviceAction: ${action.name}")
withContext(Dispatchers.IO) {
Intent(context, SimplexService::class.java).also {

View File

@@ -113,7 +113,6 @@ class AppPreferences(val context: Context) {
private const val SHARED_PREFS_PRIVACY_ACCEPT_IMAGES = "PrivacyAcceptImages"
private const val SHARED_PREFS_PRIVACY_LINK_PREVIEWS = "PrivacyLinkPreviews"
private const val SHARED_PREFS_EXPERIMENTAL_CALLS = "ExperimentalCalls"
}
}