Skip to content

Commit

Permalink
fix: Crash when starting starting PersistentWebsocketService (WPB-107…
Browse files Browse the repository at this point in the history
…12) - cherrypick RC (#3353)
  • Loading branch information
ohassine authored Aug 22, 2024
1 parent 8bd27f1 commit b95dbbb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@
<service
android:name=".services.PersistentWebSocketService"
android:exported="false"
android:foregroundServiceType="specialUse"></service>
android:foregroundServiceType="specialUse"/>

<service
android:name=".services.OngoingCallService"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import androidx.core.app.NotificationCompat
import androidx.core.app.ServiceCompat
import com.wire.android.R
import com.wire.android.appLogger
import com.wire.android.di.CurrentSessionFlowService
import com.wire.android.di.KaliumCoreLogic
import com.wire.android.notification.NotificationChannelsManager
import com.wire.android.notification.NotificationConstants.WEB_SOCKET_CHANNEL_ID
Expand All @@ -39,7 +38,6 @@ import com.wire.android.notification.openAppPendingIntent
import com.wire.android.util.dispatchers.DispatcherProvider
import com.wire.kalium.logic.CoreLogic
import com.wire.kalium.logic.data.sync.ConnectionPolicy
import com.wire.kalium.logic.feature.session.CurrentSessionFlowUseCase
import com.wire.kalium.logic.feature.user.webSocketStatus.ObservePersistentWebSocketConnectionStatusUseCase
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.CoroutineScope
Expand All @@ -65,11 +63,6 @@ class PersistentWebSocketService : Service() {
@Inject
lateinit var notificationManager: WireNotificationManager

// TODO: remove since it is not used
@Inject
@CurrentSessionFlowService
lateinit var currentSessionFlow: CurrentSessionFlowUseCase

@Inject
lateinit var notificationChannelsManager: NotificationChannelsManager

Expand All @@ -84,6 +77,15 @@ class PersistentWebSocketService : Service() {
}

override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
/**
* When service is restarted by system onCreate lifecycle method is not guaranteed to be called
* so we need to check if service is already started and if not generate notification and call startForeground()
* https://issuetracker.google.com/issues/307329994#comment100
*/
if (!isServiceStarted) {
isServiceStarted = true
generateForegroundNotification()
}
scope.launch {
coreLogic.getGlobalScope().observePersistentWebSocketConnectionStatus().let { result ->
when (result) {
Expand Down

0 comments on commit b95dbbb

Please sign in to comment.