mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-08-06 05:14:50 +01:00
Add tests for AppRegistrationStorageController.
This commit is contained in:
@@ -133,6 +133,14 @@ class SignalStore(context: Application, private val store: KeyValueStore) {
|
||||
instance!!.store.resetCache()
|
||||
}
|
||||
|
||||
/**
|
||||
* Swaps out the singleton for a test instance. Pass null to clear it. Should only be used for testing!
|
||||
*/
|
||||
@VisibleForTesting
|
||||
fun testInject(instance: SignalStore?) {
|
||||
Companion.instance = instance
|
||||
}
|
||||
|
||||
/**
|
||||
* Restoring a backup changes the underlying disk values, so the cache needs to be reset.
|
||||
*/
|
||||
|
||||
+14
-4
@@ -8,6 +8,7 @@ package org.thoughtcrime.securesms.registration.v2
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
import androidx.core.net.toUri
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
@@ -104,6 +105,16 @@ import kotlin.time.Duration.Companion.seconds
|
||||
*/
|
||||
class AppRegistrationStorageController(private val context: Context) : StorageController {
|
||||
|
||||
/**
|
||||
* Restarts the process-wide network stack after account data is applied. Overridable only so tests can avoid
|
||||
* touching the real, suite-shared network module; production must never replace it.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
internal var restartNetwork: () -> Unit = {
|
||||
AppDependencies.resetNetwork()
|
||||
AppDependencies.startNetwork()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG = Log.tag(AppRegistrationStorageController::class)
|
||||
private const val TEMP_PROTO_FILENAME = "registration-in-progress.proto"
|
||||
@@ -689,7 +700,7 @@ class AppRegistrationStorageController(private val context: Context) : StorageCo
|
||||
|
||||
val profileKey = getOrCreateProfileKey(accountData.e164)
|
||||
val recipientTable = SignalDatabase.recipients
|
||||
val selfId = Recipient.trustedPush(aci, pni, accountData.e164).id
|
||||
val selfId = recipientTable.getAndPossiblyMergePnpVerified(aci, pni, accountData.e164)
|
||||
|
||||
recipientTable.setProfileSharing(selfId, true)
|
||||
recipientTable.markRegisteredOrThrow(selfId, aci)
|
||||
@@ -722,8 +733,7 @@ class AppRegistrationStorageController(private val context: Context) : StorageCo
|
||||
restoredAEP = SignalStore.account.restoredAccountEntropyPool
|
||||
)
|
||||
|
||||
AppDependencies.resetNetwork()
|
||||
AppDependencies.startNetwork()
|
||||
restartNetwork()
|
||||
PreKeysSyncJob.enqueue()
|
||||
|
||||
recipientTable.clearSelfKeyTransparencyData()
|
||||
@@ -749,7 +759,7 @@ class AppRegistrationStorageController(private val context: Context) : StorageCo
|
||||
}
|
||||
|
||||
private fun getOrCreateProfileKey(e164: String): ProfileKey {
|
||||
val existing = SignalDatabase.recipients.getByE164(e164).getOrNull()?.let { ProfileKeyUtil.profileKeyOrNull(Recipient.resolved(it).profileKey) }
|
||||
val existing = SignalDatabase.recipients.getByE164(e164).getOrNull()?.let { ProfileKeyUtil.profileKeyOrNull(SignalDatabase.recipients.getRecord(it).profileKey) }
|
||||
return existing ?: ProfileKeyUtil.createNew().also { Log.i(TAG, "[commitRegistrationData] No profile key found, created a new one") }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user