From 62374c672f29cff4030ec6ac5ffbc523ae7ab46a Mon Sep 17 00:00:00 2001 From: SessionHero01 <180888785+SessionHero01@users.noreply.github.com> Date: Mon, 17 Mar 2025 15:00:59 +1100 Subject: [PATCH] Fix a potential crash when handling member removal offline (#1025) * Fix a potential crash handling member removal * Change how the class is instantiated * Additional GH triggers --- .../securesms/ApplicationContext.java | 3 +-- .../groups/handler/RemoveGroupMemberHandler.kt | 18 +++++++++--------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java b/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java index c31a371ce9..5935035b65 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java +++ b/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java @@ -170,7 +170,7 @@ public class ApplicationContext extends Application implements DefaultLifecycleO @Inject ConfigUploader configUploader; @Inject AdminStateSync adminStateSync; @Inject DestroyedGroupSync destroyedGroupSync; - @Inject RemoveGroupMemberHandler removeGroupMemberHandler; + @Inject RemoveGroupMemberHandler removeGroupMemberHandler; // Exists here only to start upon app starts @Inject SnodeClock snodeClock; @Inject ExpiringMessageManager expiringMessageManager; @Inject TypingStatusRepository typingStatusRepository; @@ -302,7 +302,6 @@ public class ApplicationContext extends Application implements DefaultLifecycleO snodeClock.start(); pushRegistrationHandler.run(); configUploader.start(); - removeGroupMemberHandler.start(); destroyedGroupSync.start(); adminStateSync.start(); cleanupInvitationHandler.start(); diff --git a/app/src/main/java/org/thoughtcrime/securesms/groups/handler/RemoveGroupMemberHandler.kt b/app/src/main/java/org/thoughtcrime/securesms/groups/handler/RemoveGroupMemberHandler.kt index 0c4ebe63d4..24117ec952 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/groups/handler/RemoveGroupMemberHandler.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/groups/handler/RemoveGroupMemberHandler.kt @@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.groups.handler import android.content.Context import com.google.protobuf.ByteString import dagger.hilt.android.qualifiers.ApplicationContext +import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.Job @@ -49,6 +50,7 @@ private const val TAG = "RemoveGroupMemberHandler" * * It automatically does so by listening to the config updates changes and checking for any pending removals. */ +@OptIn(DelicateCoroutinesApi::class, ExperimentalCoroutinesApi::class) @Singleton class RemoveGroupMemberHandler @Inject constructor( @ApplicationContext private val context: Context, @@ -59,13 +61,8 @@ class RemoveGroupMemberHandler @Inject constructor( private val storage: StorageProtocol, private val groupScope: GroupScope, ) { - private var job: Job? = null - - @OptIn(ExperimentalCoroutinesApi::class) - fun start() { - require(job == null) { "Already started" } - - job = GlobalScope.launch { + init { + GlobalScope.launch { textSecurePreferences .watchLocalNumber() .flatMapLatest { localNumber -> @@ -80,14 +77,17 @@ class RemoveGroupMemberHandler @Inject constructor( val adminKey = configFactory.getGroup(update.groupId)?.adminKey if (adminKey != null) { groupScope.launch(update.groupId, "Handle possible group removals") { - processPendingRemovalsForGroup(update.groupId, adminKey) + try { + processPendingRemovalsForGroup(update.groupId, adminKey) + } catch (ec: Exception) { + Log.e("RemoveGroupMemberHandler", "Error processing pending removals", ec) + } } } } } } - private suspend fun processPendingRemovalsForGroup( groupAccountId: AccountId, adminKey: ByteArray