Merge branch 'disappear-2' of github.com:bemusementpark/session-android into disappear-2

This commit is contained in:
andrew 2023-10-16 11:16:12 +10:30
commit 8145a7d772
4 changed files with 68 additions and 12 deletions

View File

@ -31,8 +31,8 @@ configurations.all {
exclude module: "commons-logging" exclude module: "commons-logging"
} }
def canonicalVersionCode = 358 def canonicalVersionCode = 359
def canonicalVersionName = "1.17.3" def canonicalVersionName = "1.17.4"
def postFixSize = 10 def postFixSize = 10
def abiPostFix = ['armeabi-v7a' : 1, def abiPostFix = ['armeabi-v7a' : 1,

View File

@ -11,16 +11,19 @@ import network.loki.messenger.libsession_util.ConversationVolatileConfig
import network.loki.messenger.libsession_util.util.Contact import network.loki.messenger.libsession_util.util.Contact
import network.loki.messenger.libsession_util.util.Conversation import network.loki.messenger.libsession_util.util.Conversation
import network.loki.messenger.libsession_util.util.ExpiryMode import network.loki.messenger.libsession_util.util.ExpiryMode
import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.CoreMatchers.instanceOf
import org.hamcrest.MatcherAssert.assertThat
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.mockito.kotlin.any
import org.mockito.kotlin.argThat import org.mockito.kotlin.argThat
import org.mockito.kotlin.argWhere import org.mockito.kotlin.argWhere
import org.mockito.kotlin.eq import org.mockito.kotlin.eq
import org.mockito.kotlin.spy import org.mockito.kotlin.spy
import org.mockito.kotlin.verify import org.mockito.kotlin.verify
import org.session.libsession.messaging.MessagingModuleConfiguration import org.session.libsession.messaging.MessagingModuleConfiguration
import org.session.libsession.messaging.messages.ExpirationConfiguration
import org.session.libsession.snode.SnodeAPI import org.session.libsession.snode.SnodeAPI
import org.session.libsession.utilities.Address import org.session.libsession.utilities.Address
import org.session.libsession.utilities.TextSecurePreferences import org.session.libsession.utilities.TextSecurePreferences
@ -110,7 +113,7 @@ class LibSessionTests {
fakePollNewConfig(contacts, newContactMerge) fakePollNewConfig(contacts, newContactMerge)
verify(storageSpy).addLibSessionContacts(argThat { verify(storageSpy).addLibSessionContacts(argThat {
first().let { it.id == newContactId && it.approved } && size == 1 first().let { it.id == newContactId && it.approved } && size == 1
}, 0) }, any())
verify(storageSpy).setRecipientApproved(argThat { address.serialize() == newContactId }, eq(true)) verify(storageSpy).setRecipientApproved(argThat { address.serialize() == newContactId }, eq(true))
} }
@ -135,17 +138,58 @@ class LibSessionTests {
val contacts = MessagingModuleConfiguration.shared.configFactory.contacts!! val contacts = MessagingModuleConfiguration.shared.configFactory.contacts!!
val newContactMerge = buildContactMessage(listOf(newContact)) val newContactMerge = buildContactMessage(listOf(newContact))
val newVolatileMerge = buildVolatileMessage(listOf(newConvo)) val newVolatileMerge = buildVolatileMessage(listOf(newConvo))
val expConfig = ExpirationConfiguration()
val recipientAddress = Address.fromSerialized(randomRecipient)
fakePollNewConfig(contacts, newContactMerge) fakePollNewConfig(contacts, newContactMerge)
fakePollNewConfig(volatiles, newVolatileMerge) fakePollNewConfig(volatiles, newVolatileMerge)
val threadId = storageSpy.getThreadId(recipientAddress)!!
// whenever(storageSpy.getExpirationConfiguration(eq(threadId))).thenReturn(expConfig)
// doNothing().whenever(storageSpy).setExpirationConfiguration(any())
// verify(storageSpy).getExpirationConfiguration(eq(threadId))
verify(storageSpy).setExpirationConfiguration(argWhere { config -> verify(storageSpy).setExpirationConfiguration(argWhere { config ->
config.expiryMode is ExpiryMode.AfterSend config.expiryMode is ExpiryMode.AfterSend
&& config.expiryMode.expirySeconds == 1000L
}) })
val threadId = storageSpy.getThreadId(Address.fromSerialized(randomRecipient))!!
val newExpiry = storageSpy.getExpirationConfiguration(threadId)!!
assertThat(newExpiry.expiryMode, instanceOf(ExpiryMode.AfterSend::class.java))
assertThat(newExpiry.expiryMode.expirySeconds, equalTo(1000))
assertThat(newExpiry.expiryMode.expiryMillis, equalTo(1000000))
}
@Test
fun test_overwrite_config() {
val app = InstrumentationRegistry.getInstrumentation().targetContext.applicationContext as ApplicationContext
val storageSpy = spy(app.storage)
app.storage = storageSpy
// Initial state
val randomRecipient = randomSessionId()
val currentContact = Contact(
id = randomRecipient,
approved = true,
expiryMode = ExpiryMode.NONE
)
val newConvo = Conversation.OneToOne(
randomRecipient,
SnodeAPI.nowWithOffset,
false
)
val volatiles = MessagingModuleConfiguration.shared.configFactory.convoVolatile!!
val contacts = MessagingModuleConfiguration.shared.configFactory.contacts!!
val newContactMerge = buildContactMessage(listOf(currentContact))
val newVolatileMerge = buildVolatileMessage(listOf(newConvo))
fakePollNewConfig(contacts, newContactMerge)
fakePollNewConfig(volatiles, newVolatileMerge)
verify(storageSpy).setExpirationConfiguration(argWhere { config ->
config.expiryMode == ExpiryMode.NONE
})
val threadId = storageSpy.getThreadId(Address.fromSerialized(randomRecipient))!!
val currentExpiryConfig = storageSpy.getExpirationConfiguration(threadId)!!
assertThat(currentExpiryConfig.expiryMode, equalTo(ExpiryMode.NONE))
assertThat(currentExpiryConfig.expiryMode.expirySeconds, equalTo(0))
assertThat(currentExpiryConfig.expiryMode.expiryMillis, equalTo(0))
// Set new state and overwrite
val updatedContact = currentContact.copy(expiryMode = ExpiryMode.AfterSend(1000))
val updateContactMerge = buildContactMessage(listOf(updatedContact))
fakePollNewConfig(contacts, updateContactMerge)
val updatedExpiryConfig = storageSpy.getExpirationConfiguration(threadId)!!
assertThat(updatedExpiryConfig.expiryMode, instanceOf(ExpiryMode.AfterSend::class.java))
assertThat(updatedExpiryConfig.expiryMode.expirySeconds, equalTo(1000))
} }
} }

View File

@ -34,6 +34,8 @@
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" /> <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.USE_FINGERPRINT" /> <uses-permission android:name="android.permission.USE_FINGERPRINT" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE"/>
<uses-permission android:name="network.loki.messenger.ACCESS_SESSION_SECRETS" /> <uses-permission android:name="network.loki.messenger.ACCESS_SESSION_SECRETS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
@ -310,11 +312,15 @@
android:value="org.thoughtcrime.securesms.home.HomeActivity" /> android:value="org.thoughtcrime.securesms.home.HomeActivity" />
</activity> </activity>
<service android:enabled="true" android:name="org.thoughtcrime.securesms.service.WebRtcCallService" <service android:enabled="true" android:name="org.thoughtcrime.securesms.service.WebRtcCallService"
android:foregroundServiceType="microphone"
android:exported="false" /> android:exported="false" />
<service <service
android:name="org.thoughtcrime.securesms.service.KeyCachingService" android:name="org.thoughtcrime.securesms.service.KeyCachingService"
android:enabled="true" android:enabled="true"
android:exported="false" /> android:exported="false" android:foregroundServiceType="specialUse">
<!-- <property android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"-->
<!-- android:value="@string/preferences_app_protection__lock_signal_access_with_android_screen_lock_or_fingerprint"/>-->
</service>
<service <service
android:name="org.thoughtcrime.securesms.service.DirectShareService" android:name="org.thoughtcrime.securesms.service.DirectShareService"
android:exported="true" android:exported="true"

View File

@ -25,8 +25,10 @@ import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.ServiceConnection; import android.content.ServiceConnection;
import android.content.pm.ServiceInfo;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Binder; import android.os.Binder;
import android.os.Build;
import android.os.IBinder; import android.os.IBinder;
import android.os.SystemClock; import android.os.SystemClock;
@ -250,8 +252,12 @@ public class KeyCachingService extends Service {
builder.setContentIntent(buildLaunchIntent()); builder.setContentIntent(buildLaunchIntent());
stopForeground(true); 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()); startForeground(SERVICE_RUNNING_ID, builder.build());
} }
}
private PendingIntent buildLockIntent() { private PendingIntent buildLockIntent() {
Intent intent = new Intent(this, KeyCachingService.class); Intent intent = new Intent(this, KeyCachingService.class);