From 60c111d30ac12dc2a01971e91922932ff78d812e Mon Sep 17 00:00:00 2001 From: ThomasSession Date: Thu, 1 Aug 2024 09:01:56 +1000 Subject: [PATCH 1/9] Removing the snodes version patch --- .../thoughtcrime/securesms/ApplicationContext.java | 10 ---------- .../org/session/libsession/snode/OnionRequestAPI.kt | 11 ----------- .../libsession/utilities/TextSecurePreferences.kt | 12 ------------ 3 files changed, 33 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java b/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java index d306db50b5..1870cf6260 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java +++ b/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java @@ -215,16 +215,6 @@ public class ApplicationContext extends Application implements DefaultLifecycleO MessagingModuleConfiguration.configure(this); super.onCreate(); - // we need to clear the snode and onionrequest databases once on first launch - // in order to apply a patch that adds a version number to the Snode objects. - if(!TextSecurePreferences.hasAppliedPatchSnodeVersion(this)) { - ThreadUtils.queue(() -> { - lokiAPIDatabase.clearSnodePool(); - lokiAPIDatabase.clearOnionRequestPaths(); - TextSecurePreferences.setHasAppliedPatchSnodeVersion(this, true); - }); - } - messagingModuleConfiguration = new MessagingModuleConfiguration( this, storage, diff --git a/libsession/src/main/java/org/session/libsession/snode/OnionRequestAPI.kt b/libsession/src/main/java/org/session/libsession/snode/OnionRequestAPI.kt index 3dcfc5b958..ead454eb44 100644 --- a/libsession/src/main/java/org/session/libsession/snode/OnionRequestAPI.kt +++ b/libsession/src/main/java/org/session/libsession/snode/OnionRequestAPI.kt @@ -193,17 +193,6 @@ object OnionRequestAPI { val result = listOf( guardSnode ) + (0 until (pathSize - 1)).mapIndexed() { index, _ -> var pathSnode = unusedSnodes.getRandomElement() - // For the last node: We need to make sure the version is >= 2.8.0 - // to help with an issue that will disappear once the nodes are all updated - if(index == pathSize - 2) { - val suitableSnodes = unusedSnodes.filter { Util.compareVersions(it.version, "2.8.0") >= 0 } - pathSnode = if (suitableSnodes.isNotEmpty()) { - suitableSnodes.random() - } else { - throw InsufficientSnodesException() - } - } - // remove the snode from the unused list and return it unusedSnodes = unusedSnodes.minus(pathSnode) pathSnode diff --git a/libsession/src/main/java/org/session/libsession/utilities/TextSecurePreferences.kt b/libsession/src/main/java/org/session/libsession/utilities/TextSecurePreferences.kt index 4d35a89de2..12fdd4ceaf 100644 --- a/libsession/src/main/java/org/session/libsession/utilities/TextSecurePreferences.kt +++ b/libsession/src/main/java/org/session/libsession/utilities/TextSecurePreferences.kt @@ -296,8 +296,6 @@ interface TextSecurePreferences { const val ALLOW_MESSAGE_REQUESTS = "libsession.ALLOW_MESSAGE_REQUESTS" - const val PATCH_SNODE_VERSION_2024_07_23 = "libsession.patch_snode_version_2024_07_23" - @JvmStatic fun getLastConfigurationSyncTime(context: Context): Long { return getLongPreference(context, LAST_CONFIGURATION_SYNC_TIME, 0) @@ -982,16 +980,6 @@ interface TextSecurePreferences { fun clearAll(context: Context) { getDefaultSharedPreferences(context).edit().clear().commit() } - - @JvmStatic - fun hasAppliedPatchSnodeVersion(context: Context): Boolean { - return getBooleanPreference(context, PATCH_SNODE_VERSION_2024_07_23, false) - } - - @JvmStatic - fun setHasAppliedPatchSnodeVersion(context: Context, applied: Boolean) { - setBooleanPreference(context, PATCH_SNODE_VERSION_2024_07_23, applied) - } } } From 137a26c3bf1e8ae074410b2fbd823df6627f8dca Mon Sep 17 00:00:00 2001 From: ThomasSession Date: Thu, 1 Aug 2024 11:25:35 +1000 Subject: [PATCH 2/9] KeepAliveService doesn't seem to be used anywhere --- app/src/main/AndroidManifest.xml | 4 +--- .../jobmanager/KeepAliveService.java | 24 ------------------- app/src/main/res/values-v26/values.xml | 1 - app/src/main/res/values/values.xml | 1 - libsession/src/main/res/values/values.xml | 1 - 5 files changed, 1 insertion(+), 30 deletions(-) delete mode 100644 app/src/main/java/org/thoughtcrime/securesms/jobmanager/KeepAliveService.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 7e04ad44ca..2d06893ca0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -440,9 +440,7 @@ - + diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobmanager/KeepAliveService.java b/app/src/main/java/org/thoughtcrime/securesms/jobmanager/KeepAliveService.java deleted file mode 100644 index 121686671c..0000000000 --- a/app/src/main/java/org/thoughtcrime/securesms/jobmanager/KeepAliveService.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.thoughtcrime.securesms.jobmanager; - -import android.app.Service; -import android.content.Intent; -import android.os.IBinder; -import androidx.annotation.Nullable; - -/** - * Service that keeps the application in memory while the app is closed. - * - * Important: Should only be used on API < 26. - */ -public class KeepAliveService extends Service { - - @Override - public @Nullable IBinder onBind(Intent intent) { - return null; - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - return START_STICKY; - } -} diff --git a/app/src/main/res/values-v26/values.xml b/app/src/main/res/values-v26/values.xml index dc6b4b7941..c9cf9e837c 100644 --- a/app/src/main/res/values-v26/values.xml +++ b/app/src/main/res/values-v26/values.xml @@ -1,5 +1,4 @@ - false true diff --git a/app/src/main/res/values/values.xml b/app/src/main/res/values/values.xml index c87ba9badd..384c8df05b 100644 --- a/app/src/main/res/values/values.xml +++ b/app/src/main/res/values/values.xml @@ -1,6 +1,5 @@ - true false diff --git a/libsession/src/main/res/values/values.xml b/libsession/src/main/res/values/values.xml index f493249a83..899d189687 100644 --- a/libsession/src/main/res/values/values.xml +++ b/libsession/src/main/res/values/values.xml @@ -1,6 +1,5 @@ - true false true From 33f23e5fa1b3f4ac5b74082334dbef39222431fe Mon Sep 17 00:00:00 2001 From: ThomasSession Date: Thu, 1 Aug 2024 11:27:43 +1000 Subject: [PATCH 3/9] Another unused or referenced service --- app/src/main/AndroidManifest.xml | 1 - .../service/GenericForegroundService.java | 128 ------------------ 2 files changed, 129 deletions(-) delete mode 100644 app/src/main/java/org/thoughtcrime/securesms/service/GenericForegroundService.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 2d06893ca0..e1a2e79694 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -328,7 +328,6 @@ - Date: Thu, 1 Aug 2024 16:50:20 +1000 Subject: [PATCH 4/9] Cleaning up foreground service calls --- .../securesms/service/KeyCachingService.java | 18 +++++++++++++----- .../securesms/service/WebRtcCallService.kt | 13 +++++++++++-- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/KeyCachingService.java b/app/src/main/java/org/thoughtcrime/securesms/service/KeyCachingService.java index f919af7ad6..47b5c52f16 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/service/KeyCachingService.java +++ b/app/src/main/java/org/thoughtcrime/securesms/service/KeyCachingService.java @@ -35,6 +35,7 @@ import android.os.SystemClock; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.app.NotificationCompat; +import androidx.core.app.ServiceCompat; import org.session.libsession.utilities.ServiceUtil; import org.session.libsession.utilities.TextSecurePreferences; @@ -122,7 +123,7 @@ public class KeyCachingService extends Service { KeyCachingService.masterSecret = masterSecret; foregroundService(); - + new AsyncTask() { @Override protected Void doInBackground(Void... params) { @@ -252,11 +253,18 @@ public class KeyCachingService extends Service { builder.setContentIntent(buildLaunchIntent()); stopForeground(true); - if (Build.VERSION.SDK_INT >= 34) { - startForeground(SERVICE_RUNNING_ID, builder.build(), ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE); - } else { - startForeground(SERVICE_RUNNING_ID, builder.build()); + + int type = 0; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + type = ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE; } + + ServiceCompat.startForeground( + this, + SERVICE_RUNNING_ID, + builder.build(), + type + ); } private PendingIntent buildLockIntent() { diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/WebRtcCallService.kt b/app/src/main/java/org/thoughtcrime/securesms/service/WebRtcCallService.kt index f40a075d8d..6ee33721e8 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/service/WebRtcCallService.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/service/WebRtcCallService.kt @@ -7,9 +7,12 @@ import android.content.Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT import android.content.Intent.FLAG_ACTIVITY_NEW_TASK import android.content.IntentFilter import android.content.pm.PackageManager +import android.content.pm.ServiceInfo import android.media.AudioManager +import android.os.Build import android.os.ResultReceiver import android.telephony.TelephonyManager +import androidx.core.app.ServiceCompat import androidx.core.content.ContextCompat import androidx.core.os.bundleOf import androidx.lifecycle.LifecycleService @@ -723,9 +726,15 @@ class WebRtcCallService : LifecycleService(), CallManager.WebRtcListener { private fun setCallInProgressNotification(type: Int, recipient: Recipient?) { try { - startForeground( + ServiceCompat.startForeground( + this, CallNotificationBuilder.WEBRTC_NOTIFICATION, - CallNotificationBuilder.getCallInProgressNotification(this, type, recipient) + CallNotificationBuilder.getCallInProgressNotification(this, type, recipient), + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE + } else { + 0 + } ) } catch (e: IllegalStateException) { Log.e(TAG, "Failed to setCallInProgressNotification as a foreground service for type: ${type}, trying to update instead", e) From d8bcb83de5115d065ce7de78370ab962884f7942 Mon Sep 17 00:00:00 2001 From: bemusementpark Date: Sat, 27 Jul 2024 16:12:03 +0930 Subject: [PATCH 5/9] Fix app exit after Lock Screen --- app/src/main/AndroidManifest.xml | 2 +- .../main/java/org/thoughtcrime/securesms/home/HomeActivity.kt | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e1a2e79694..91d9572f90 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -125,7 +125,7 @@ Date: Thu, 1 Aug 2024 19:36:38 +1000 Subject: [PATCH 6/9] Fix crashes on conversation screen (#1590) * Fixed onion request crashes * Use kotlin.Result instead --------- Co-authored-by: fanchao --- .../repository/ConversationRepository.kt | 63 +++++++++---------- .../securesms/repository/ResultOf.kt | 43 ------------- .../v2/ConversationViewModelTest.kt | 19 +++--- 3 files changed, 38 insertions(+), 87 deletions(-) delete mode 100644 app/src/main/java/org/thoughtcrime/securesms/repository/ResultOf.kt diff --git a/app/src/main/java/org/thoughtcrime/securesms/repository/ConversationRepository.kt b/app/src/main/java/org/thoughtcrime/securesms/repository/ConversationRepository.kt index 2a00440dda..7f10b1eb20 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/repository/ConversationRepository.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/repository/ConversationRepository.kt @@ -8,7 +8,6 @@ import app.cash.copper.Query import app.cash.copper.flow.observeQuery import dagger.hilt.android.qualifiers.ApplicationContext import kotlin.coroutines.resume -import kotlin.coroutines.resumeWithException import kotlin.coroutines.suspendCoroutine import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map @@ -59,15 +58,15 @@ interface ConversationRepository { fun deleteLocally(recipient: Recipient, message: MessageRecord) fun deleteAllLocalMessagesInThreadFromSenderOfMessage(messageRecord: MessageRecord) fun setApproved(recipient: Recipient, isApproved: Boolean) - suspend fun deleteForEveryone(threadId: Long, recipient: Recipient, message: MessageRecord): ResultOf + suspend fun deleteForEveryone(threadId: Long, recipient: Recipient, message: MessageRecord): Result fun buildUnsendRequest(recipient: Recipient, message: MessageRecord): UnsendRequest? - suspend fun deleteMessageWithoutUnsendRequest(threadId: Long, messages: Set): ResultOf - suspend fun banUser(threadId: Long, recipient: Recipient): ResultOf - suspend fun banAndDeleteAll(threadId: Long, recipient: Recipient): ResultOf - suspend fun deleteThread(threadId: Long): ResultOf - suspend fun deleteMessageRequest(thread: ThreadRecord): ResultOf - suspend fun clearAllMessageRequests(block: Boolean): ResultOf - suspend fun acceptMessageRequest(threadId: Long, recipient: Recipient): ResultOf + suspend fun deleteMessageWithoutUnsendRequest(threadId: Long, messages: Set): Result + suspend fun banUser(threadId: Long, recipient: Recipient): Result + suspend fun banAndDeleteAll(threadId: Long, recipient: Recipient): Result + suspend fun deleteThread(threadId: Long): Result + suspend fun deleteMessageRequest(thread: ThreadRecord): Result + suspend fun clearAllMessageRequests(block: Boolean): Result + suspend fun acceptMessageRequest(threadId: Long, recipient: Recipient): Result fun declineMessageRequest(threadId: Long) fun hasReceived(threadId: Long): Boolean } @@ -185,7 +184,7 @@ class DefaultConversationRepository @Inject constructor( threadId: Long, recipient: Recipient, message: MessageRecord - ): ResultOf = suspendCoroutine { continuation -> + ): Result = suspendCoroutine { continuation -> buildUnsendRequest(recipient, message)?.let { unsendRequest -> MessageSender.send(unsendRequest, recipient.address) } @@ -196,10 +195,10 @@ class DefaultConversationRepository @Inject constructor( OpenGroupApi.deleteMessage(messageServerID, openGroup.room, openGroup.server) .success { messageDataProvider.deleteMessage(message.id, !message.isMms) - continuation.resume(ResultOf.Success(Unit)) + continuation.resume(Result.success(Unit)) }.fail { error -> Log.w("TAG", "Call to OpenGroupApi.deleteForEveryone failed - attempting to resume..") - continuation.resumeWithException(error) + continuation.resume(Result.failure(error)) } } @@ -229,10 +228,10 @@ class DefaultConversationRepository @Inject constructor( } SnodeAPI.deleteMessage(publicKey, listOf(serverHash)) .success { - continuation.resume(ResultOf.Success(Unit)) + continuation.resume(Result.success(Unit)) }.fail { error -> Log.w("ConversationRepository", "Call to SnodeAPI.deleteMessage failed - attempting to resume..") - continuation.resumeWithException(error) + continuation.resume(Result.failure(error)) } } } @@ -250,7 +249,7 @@ class DefaultConversationRepository @Inject constructor( override suspend fun deleteMessageWithoutUnsendRequest( threadId: Long, messages: Set - ): ResultOf = suspendCoroutine { continuation -> + ): Result = suspendCoroutine { continuation -> val openGroup = lokiThreadDb.getOpenGroupChat(threadId) if (openGroup != null) { val messageServerIDs = mutableMapOf() @@ -264,7 +263,7 @@ class DefaultConversationRepository @Inject constructor( .success { messageDataProvider.deleteMessage(message.id, !message.isMms) }.fail { error -> - continuation.resumeWithException(error) + continuation.resume(Result.failure(error)) } } } else { @@ -276,22 +275,22 @@ class DefaultConversationRepository @Inject constructor( } } } - continuation.resume(ResultOf.Success(Unit)) + continuation.resume(Result.success(Unit)) } - override suspend fun banUser(threadId: Long, recipient: Recipient): ResultOf = + override suspend fun banUser(threadId: Long, recipient: Recipient): Result = suspendCoroutine { continuation -> val accountID = recipient.address.toString() val openGroup = lokiThreadDb.getOpenGroupChat(threadId)!! OpenGroupApi.ban(accountID, openGroup.room, openGroup.server) .success { - continuation.resume(ResultOf.Success(Unit)) + continuation.resume(Result.success(Unit)) }.fail { error -> - continuation.resumeWithException(error) + continuation.resume(Result.failure(error)) } } - override suspend fun banAndDeleteAll(threadId: Long, recipient: Recipient): ResultOf = + override suspend fun banAndDeleteAll(threadId: Long, recipient: Recipient): Result = suspendCoroutine { continuation -> // Note: This accountId could be the blinded Id val accountID = recipient.address.toString() @@ -299,25 +298,25 @@ class DefaultConversationRepository @Inject constructor( OpenGroupApi.banAndDeleteAll(accountID, openGroup.room, openGroup.server) .success { - continuation.resume(ResultOf.Success(Unit)) + continuation.resume(Result.success(Unit)) }.fail { error -> - continuation.resumeWithException(error) + continuation.resume(Result.failure(error)) } } - override suspend fun deleteThread(threadId: Long): ResultOf { + override suspend fun deleteThread(threadId: Long): Result { sessionJobDb.cancelPendingMessageSendJobs(threadId) storage.deleteConversation(threadId) - return ResultOf.Success(Unit) + return Result.success(Unit) } - override suspend fun deleteMessageRequest(thread: ThreadRecord): ResultOf { + override suspend fun deleteMessageRequest(thread: ThreadRecord): Result { sessionJobDb.cancelPendingMessageSendJobs(thread.threadId) storage.deleteConversation(thread.threadId) - return ResultOf.Success(Unit) + return Result.success(Unit) } - override suspend fun clearAllMessageRequests(block: Boolean): ResultOf { + override suspend fun clearAllMessageRequests(block: Boolean): Result { threadDb.readerFor(threadDb.unapprovedConversationList).use { reader -> while (reader.next != null) { deleteMessageRequest(reader.current) @@ -325,18 +324,18 @@ class DefaultConversationRepository @Inject constructor( if (block) { setBlocked(recipient, true) } } } - return ResultOf.Success(Unit) + return Result.success(Unit) } - override suspend fun acceptMessageRequest(threadId: Long, recipient: Recipient): ResultOf = suspendCoroutine { continuation -> + override suspend fun acceptMessageRequest(threadId: Long, recipient: Recipient): Result = suspendCoroutine { continuation -> storage.setRecipientApproved(recipient, true) val message = MessageRequestResponse(true) MessageSender.send(message, Destination.from(recipient.address), isSyncMessage = recipient.isLocalNumber) .success { threadDb.setHasSent(threadId, true) - continuation.resume(ResultOf.Success(Unit)) + continuation.resume(Result.success(Unit)) }.fail { error -> - continuation.resumeWithException(error) + continuation.resume(Result.failure(error)) } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/repository/ResultOf.kt b/app/src/main/java/org/thoughtcrime/securesms/repository/ResultOf.kt deleted file mode 100644 index 96ae97e510..0000000000 --- a/app/src/main/java/org/thoughtcrime/securesms/repository/ResultOf.kt +++ /dev/null @@ -1,43 +0,0 @@ -package org.thoughtcrime.securesms.repository - -import kotlinx.coroutines.CancellationException - -sealed class ResultOf { - - data class Success(val value: R) : ResultOf() - - data class Failure(val throwable: Throwable) : ResultOf() - - inline fun onFailure(block: (throwable: Throwable) -> Unit) = this.also { - if (this is Failure) { - block(throwable) - } - } - - inline fun onSuccess(block: (value: T) -> Unit) = this.also { - if (this is Success) { - block(value) - } - } - - inline fun flatMap(mapper: (T) -> R): ResultOf = when (this) { - is Success -> wrap { mapper(value) } - is Failure -> Failure(throwable) - } - - fun getOrThrow(): T = when (this) { - is Success -> value - is Failure -> throw throwable - } - - companion object { - inline fun wrap(block: () -> T): ResultOf = - try { - Success(block()) - } catch (e: CancellationException) { - throw e - } catch (e: Exception) { - Failure(e) - } - } -} diff --git a/app/src/test/java/org/thoughtcrime/securesms/conversation/v2/ConversationViewModelTest.kt b/app/src/test/java/org/thoughtcrime/securesms/conversation/v2/ConversationViewModelTest.kt index 7f4db828e4..1bd6a63c7f 100644 --- a/app/src/test/java/org/thoughtcrime/securesms/conversation/v2/ConversationViewModelTest.kt +++ b/app/src/test/java/org/thoughtcrime/securesms/conversation/v2/ConversationViewModelTest.kt @@ -3,14 +3,12 @@ package org.thoughtcrime.securesms.conversation.v2 import com.goterl.lazysodium.utils.KeyPair import kotlinx.coroutines.flow.emptyFlow import kotlinx.coroutines.flow.first -import kotlinx.coroutines.runBlocking import org.hamcrest.CoreMatchers.endsWith import org.hamcrest.CoreMatchers.equalTo import org.hamcrest.CoreMatchers.notNullValue import org.hamcrest.CoreMatchers.nullValue import org.hamcrest.MatcherAssert.assertThat import org.junit.Before -import org.junit.BeforeClass import org.junit.Test import org.mockito.Mockito import org.mockito.Mockito.anyLong @@ -20,14 +18,11 @@ import org.mockito.kotlin.any import org.mockito.kotlin.mock import org.mockito.kotlin.whenever import org.session.libsession.utilities.recipients.Recipient -import org.session.libsignal.utilities.Log import org.thoughtcrime.securesms.BaseViewModelTest -import org.thoughtcrime.securesms.NoOpLogger import org.thoughtcrime.securesms.database.MmsDatabase import org.thoughtcrime.securesms.database.Storage import org.thoughtcrime.securesms.database.model.MessageRecord import org.thoughtcrime.securesms.repository.ConversationRepository -import org.thoughtcrime.securesms.repository.ResultOf class ConversationViewModelTest: BaseViewModelTest() { @@ -107,7 +102,7 @@ class ConversationViewModelTest: BaseViewModelTest() { val message = mock() val error = Throwable() whenever(repository.deleteForEveryone(anyLong(), any(), any())) - .thenReturn(ResultOf.Failure(error)) + .thenReturn(Result.failure(error)) viewModel.deleteForEveryone(message) @@ -120,7 +115,7 @@ class ConversationViewModelTest: BaseViewModelTest() { val message = mock() val error = Throwable() whenever(repository.deleteMessageWithoutUnsendRequest(anyLong(), anySet())) - .thenReturn(ResultOf.Failure(error)) + .thenReturn(Result.failure(error)) viewModel.deleteMessagesWithoutUnsendRequest(setOf(message)) @@ -130,7 +125,7 @@ class ConversationViewModelTest: BaseViewModelTest() { @Test fun `should emit error message on ban user failure`() = runBlockingTest { val error = Throwable() - whenever(repository.banUser(anyLong(), any())).thenReturn(ResultOf.Failure(error)) + whenever(repository.banUser(anyLong(), any())).thenReturn(Result.failure(error)) viewModel.banUser(recipient) @@ -139,7 +134,7 @@ class ConversationViewModelTest: BaseViewModelTest() { @Test fun `should emit a message on ban user success`() = runBlockingTest { - whenever(repository.banUser(anyLong(), any())).thenReturn(ResultOf.Success(Unit)) + whenever(repository.banUser(anyLong(), any())).thenReturn(Result.success(Unit)) viewModel.banUser(recipient) @@ -152,7 +147,7 @@ class ConversationViewModelTest: BaseViewModelTest() { @Test fun `should emit error message on ban user and delete all failure`() = runBlockingTest { val error = Throwable() - whenever(repository.banAndDeleteAll(anyLong(), any())).thenReturn(ResultOf.Failure(error)) + whenever(repository.banAndDeleteAll(anyLong(), any())).thenReturn(Result.failure(error)) viewModel.banAndDeleteAll(messageRecord) @@ -161,7 +156,7 @@ class ConversationViewModelTest: BaseViewModelTest() { @Test fun `should emit a message on ban user and delete all success`() = runBlockingTest { - whenever(repository.banAndDeleteAll(anyLong(), any())).thenReturn(ResultOf.Success(Unit)) + whenever(repository.banAndDeleteAll(anyLong(), any())).thenReturn(Result.success(Unit)) viewModel.banAndDeleteAll(messageRecord) @@ -188,7 +183,7 @@ class ConversationViewModelTest: BaseViewModelTest() { @Test fun `should remove shown message`() = runBlockingTest { // Given that a message is generated - whenever(repository.banUser(anyLong(), any())).thenReturn(ResultOf.Success(Unit)) + whenever(repository.banUser(anyLong(), any())).thenReturn(Result.success(Unit)) viewModel.banUser(recipient) assertThat(viewModel.uiState.value.uiMessages.size, equalTo(1)) // When the message is shown From fb7c24a26d38876cc3b25161836907e5bfee3850 Mon Sep 17 00:00:00 2001 From: ThomasSession Date: Fri, 2 Aug 2024 08:43:48 +1000 Subject: [PATCH 7/9] Update app/src/main/java/org/thoughtcrime/securesms/service/KeyCachingService.java Co-authored-by: Andrew --- .../org/thoughtcrime/securesms/service/KeyCachingService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/KeyCachingService.java b/app/src/main/java/org/thoughtcrime/securesms/service/KeyCachingService.java index 47b5c52f16..14b2c43af4 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/service/KeyCachingService.java +++ b/app/src/main/java/org/thoughtcrime/securesms/service/KeyCachingService.java @@ -255,7 +255,7 @@ public class KeyCachingService extends Service { stopForeground(true); int type = 0; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + if (Build.VERSION.SDK_INT >= 34) { type = ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE; } From 7dcfba49324b18fe7635548343b6b65611b1f087 Mon Sep 17 00:00:00 2001 From: ThomasSession Date: Fri, 2 Aug 2024 08:44:30 +1000 Subject: [PATCH 8/9] Update app/src/main/java/org/thoughtcrime/securesms/service/KeyCachingService.java Co-authored-by: Andrew --- .../securesms/service/KeyCachingService.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/KeyCachingService.java b/app/src/main/java/org/thoughtcrime/securesms/service/KeyCachingService.java index 14b2c43af4..cf250665ef 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/service/KeyCachingService.java +++ b/app/src/main/java/org/thoughtcrime/securesms/service/KeyCachingService.java @@ -260,11 +260,11 @@ public class KeyCachingService extends Service { } ServiceCompat.startForeground( - this, - SERVICE_RUNNING_ID, - builder.build(), - type - ); + this, + SERVICE_RUNNING_ID, + builder.build(), + type + ); } private PendingIntent buildLockIntent() { From e71f650dc0c9dd67d7b05278704bfcaae8b6a397 Mon Sep 17 00:00:00 2001 From: ThomasSession Date: Fri, 2 Aug 2024 08:44:39 +1000 Subject: [PATCH 9/9] Update app/src/main/java/org/thoughtcrime/securesms/service/WebRtcCallService.kt Co-authored-by: Andrew --- .../org/thoughtcrime/securesms/service/WebRtcCallService.kt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/WebRtcCallService.kt b/app/src/main/java/org/thoughtcrime/securesms/service/WebRtcCallService.kt index 6ee33721e8..78f1a55470 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/service/WebRtcCallService.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/service/WebRtcCallService.kt @@ -730,11 +730,7 @@ class WebRtcCallService : LifecycleService(), CallManager.WebRtcListener { this, CallNotificationBuilder.WEBRTC_NOTIFICATION, CallNotificationBuilder.getCallInProgressNotification(this, type, recipient), - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { - ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE - } else { - 0 - } + if (Build.VERSION.SDK_INT >= 30) ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE else 0 ) } catch (e: IllegalStateException) { Log.e(TAG, "Failed to setCallInProgressNotification as a foreground service for type: ${type}, trying to update instead", e)