Change in KeysBackupService: isEnabled
and isStucked
are now fun, and state
has been renamed to getState
and is now a fun.
This commit is contained in:
parent
1ab4ae9eac
commit
ede784684f
@ -113,7 +113,7 @@ class KeysBackupTest : InstrumentedTest {
|
|||||||
|
|
||||||
val stateObserver = StateObserver(keysBackup)
|
val stateObserver = StateObserver(keysBackup)
|
||||||
|
|
||||||
assertFalse(keysBackup.isEnabled)
|
assertFalse(keysBackup.isEnabled())
|
||||||
|
|
||||||
val megolmBackupCreationInfo = testHelper.doSync<MegolmBackupCreationInfo> {
|
val megolmBackupCreationInfo = testHelper.doSync<MegolmBackupCreationInfo> {
|
||||||
keysBackup.prepareKeysBackupVersion(null, null, it)
|
keysBackup.prepareKeysBackupVersion(null, null, it)
|
||||||
@ -143,13 +143,13 @@ class KeysBackupTest : InstrumentedTest {
|
|||||||
|
|
||||||
val stateObserver = StateObserver(keysBackup)
|
val stateObserver = StateObserver(keysBackup)
|
||||||
|
|
||||||
assertFalse(keysBackup.isEnabled)
|
assertFalse(keysBackup.isEnabled())
|
||||||
|
|
||||||
val megolmBackupCreationInfo = testHelper.doSync<MegolmBackupCreationInfo> {
|
val megolmBackupCreationInfo = testHelper.doSync<MegolmBackupCreationInfo> {
|
||||||
keysBackup.prepareKeysBackupVersion(null, null, it)
|
keysBackup.prepareKeysBackupVersion(null, null, it)
|
||||||
}
|
}
|
||||||
|
|
||||||
assertFalse(keysBackup.isEnabled)
|
assertFalse(keysBackup.isEnabled())
|
||||||
|
|
||||||
// Create the version
|
// Create the version
|
||||||
val version = testHelper.doSync<KeysVersion> {
|
val version = testHelper.doSync<KeysVersion> {
|
||||||
@ -157,7 +157,7 @@ class KeysBackupTest : InstrumentedTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Backup must be enable now
|
// Backup must be enable now
|
||||||
assertTrue(keysBackup.isEnabled)
|
assertTrue(keysBackup.isEnabled())
|
||||||
|
|
||||||
// Check that it's signed with MSK
|
// Check that it's signed with MSK
|
||||||
val versionResult = testHelper.doSync<KeysVersionResult?> {
|
val versionResult = testHelper.doSync<KeysVersionResult?> {
|
||||||
@ -441,8 +441,8 @@ class KeysBackupTest : InstrumentedTest {
|
|||||||
|
|
||||||
// - The new device must see the previous backup as not trusted
|
// - The new device must see the previous backup as not trusted
|
||||||
assertNotNull(testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion)
|
assertNotNull(testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion)
|
||||||
assertFalse(testData.aliceSession2.cryptoService().keysBackupService().isEnabled)
|
assertFalse(testData.aliceSession2.cryptoService().keysBackupService().isEnabled())
|
||||||
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().state)
|
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().getState())
|
||||||
|
|
||||||
// - Trust the backup from the new device
|
// - Trust the backup from the new device
|
||||||
testHelper.doSync<Unit> {
|
testHelper.doSync<Unit> {
|
||||||
@ -458,7 +458,7 @@ class KeysBackupTest : InstrumentedTest {
|
|||||||
|
|
||||||
// - Backup must be enabled on the new device, on the same version
|
// - Backup must be enabled on the new device, on the same version
|
||||||
assertEquals(testData.prepareKeysBackupDataResult.version, testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion?.version)
|
assertEquals(testData.prepareKeysBackupDataResult.version, testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion?.version)
|
||||||
assertTrue(testData.aliceSession2.cryptoService().keysBackupService().isEnabled)
|
assertTrue(testData.aliceSession2.cryptoService().keysBackupService().isEnabled())
|
||||||
|
|
||||||
// - Retrieve the last version from the server
|
// - Retrieve the last version from the server
|
||||||
val keysVersionResult = testHelper.doSync<KeysBackupLastVersionResult> {
|
val keysVersionResult = testHelper.doSync<KeysBackupLastVersionResult> {
|
||||||
@ -504,8 +504,8 @@ class KeysBackupTest : InstrumentedTest {
|
|||||||
|
|
||||||
// - The new device must see the previous backup as not trusted
|
// - The new device must see the previous backup as not trusted
|
||||||
assertNotNull(testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion)
|
assertNotNull(testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion)
|
||||||
assertFalse(testData.aliceSession2.cryptoService().keysBackupService().isEnabled)
|
assertFalse(testData.aliceSession2.cryptoService().keysBackupService().isEnabled())
|
||||||
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().state)
|
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().getState())
|
||||||
|
|
||||||
// - Trust the backup from the new device with the recovery key
|
// - Trust the backup from the new device with the recovery key
|
||||||
testHelper.doSync<Unit> {
|
testHelper.doSync<Unit> {
|
||||||
@ -521,7 +521,7 @@ class KeysBackupTest : InstrumentedTest {
|
|||||||
|
|
||||||
// - Backup must be enabled on the new device, on the same version
|
// - Backup must be enabled on the new device, on the same version
|
||||||
assertEquals(testData.prepareKeysBackupDataResult.version, testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion?.version)
|
assertEquals(testData.prepareKeysBackupDataResult.version, testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion?.version)
|
||||||
assertTrue(testData.aliceSession2.cryptoService().keysBackupService().isEnabled)
|
assertTrue(testData.aliceSession2.cryptoService().keysBackupService().isEnabled())
|
||||||
|
|
||||||
// - Retrieve the last version from the server
|
// - Retrieve the last version from the server
|
||||||
val keysVersionResult = testHelper.doSync<KeysBackupLastVersionResult> {
|
val keysVersionResult = testHelper.doSync<KeysBackupLastVersionResult> {
|
||||||
@ -565,8 +565,8 @@ class KeysBackupTest : InstrumentedTest {
|
|||||||
|
|
||||||
// - The new device must see the previous backup as not trusted
|
// - The new device must see the previous backup as not trusted
|
||||||
assertNotNull(testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion)
|
assertNotNull(testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion)
|
||||||
assertFalse(testData.aliceSession2.cryptoService().keysBackupService().isEnabled)
|
assertFalse(testData.aliceSession2.cryptoService().keysBackupService().isEnabled())
|
||||||
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().state)
|
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().getState())
|
||||||
|
|
||||||
// - Try to trust the backup from the new device with a wrong recovery key
|
// - Try to trust the backup from the new device with a wrong recovery key
|
||||||
val latch = CountDownLatch(1)
|
val latch = CountDownLatch(1)
|
||||||
@ -579,8 +579,8 @@ class KeysBackupTest : InstrumentedTest {
|
|||||||
|
|
||||||
// - The new device must still see the previous backup as not trusted
|
// - The new device must still see the previous backup as not trusted
|
||||||
assertNotNull(testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion)
|
assertNotNull(testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion)
|
||||||
assertFalse(testData.aliceSession2.cryptoService().keysBackupService().isEnabled)
|
assertFalse(testData.aliceSession2.cryptoService().keysBackupService().isEnabled())
|
||||||
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().state)
|
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().getState())
|
||||||
|
|
||||||
stateObserver.stopAndCheckStates(null)
|
stateObserver.stopAndCheckStates(null)
|
||||||
testData.cleanUp(testHelper)
|
testData.cleanUp(testHelper)
|
||||||
@ -612,8 +612,8 @@ class KeysBackupTest : InstrumentedTest {
|
|||||||
|
|
||||||
// - The new device must see the previous backup as not trusted
|
// - The new device must see the previous backup as not trusted
|
||||||
assertNotNull(testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion)
|
assertNotNull(testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion)
|
||||||
assertFalse(testData.aliceSession2.cryptoService().keysBackupService().isEnabled)
|
assertFalse(testData.aliceSession2.cryptoService().keysBackupService().isEnabled())
|
||||||
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().state)
|
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().getState())
|
||||||
|
|
||||||
// - Trust the backup from the new device with the password
|
// - Trust the backup from the new device with the password
|
||||||
testHelper.doSync<Unit> {
|
testHelper.doSync<Unit> {
|
||||||
@ -629,7 +629,7 @@ class KeysBackupTest : InstrumentedTest {
|
|||||||
|
|
||||||
// - Backup must be enabled on the new device, on the same version
|
// - Backup must be enabled on the new device, on the same version
|
||||||
assertEquals(testData.prepareKeysBackupDataResult.version, testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion?.version)
|
assertEquals(testData.prepareKeysBackupDataResult.version, testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion?.version)
|
||||||
assertTrue(testData.aliceSession2.cryptoService().keysBackupService().isEnabled)
|
assertTrue(testData.aliceSession2.cryptoService().keysBackupService().isEnabled())
|
||||||
|
|
||||||
// - Retrieve the last version from the server
|
// - Retrieve the last version from the server
|
||||||
val keysVersionResult = testHelper.doSync<KeysBackupLastVersionResult> {
|
val keysVersionResult = testHelper.doSync<KeysBackupLastVersionResult> {
|
||||||
@ -676,8 +676,8 @@ class KeysBackupTest : InstrumentedTest {
|
|||||||
|
|
||||||
// - The new device must see the previous backup as not trusted
|
// - The new device must see the previous backup as not trusted
|
||||||
assertNotNull(testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion)
|
assertNotNull(testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion)
|
||||||
assertFalse(testData.aliceSession2.cryptoService().keysBackupService().isEnabled)
|
assertFalse(testData.aliceSession2.cryptoService().keysBackupService().isEnabled())
|
||||||
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().state)
|
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().getState())
|
||||||
|
|
||||||
// - Try to trust the backup from the new device with a wrong password
|
// - Try to trust the backup from the new device with a wrong password
|
||||||
val latch = CountDownLatch(1)
|
val latch = CountDownLatch(1)
|
||||||
@ -690,8 +690,8 @@ class KeysBackupTest : InstrumentedTest {
|
|||||||
|
|
||||||
// - The new device must still see the previous backup as not trusted
|
// - The new device must still see the previous backup as not trusted
|
||||||
assertNotNull(testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion)
|
assertNotNull(testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion)
|
||||||
assertFalse(testData.aliceSession2.cryptoService().keysBackupService().isEnabled)
|
assertFalse(testData.aliceSession2.cryptoService().keysBackupService().isEnabled())
|
||||||
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().state)
|
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().getState())
|
||||||
|
|
||||||
stateObserver.stopAndCheckStates(null)
|
stateObserver.stopAndCheckStates(null)
|
||||||
testData.cleanUp(testHelper)
|
testData.cleanUp(testHelper)
|
||||||
@ -969,7 +969,7 @@ class KeysBackupTest : InstrumentedTest {
|
|||||||
|
|
||||||
val stateObserver = StateObserver(keysBackup)
|
val stateObserver = StateObserver(keysBackup)
|
||||||
|
|
||||||
assertFalse(keysBackup.isEnabled)
|
assertFalse(keysBackup.isEnabled())
|
||||||
|
|
||||||
// Wait for keys backup to be finished
|
// Wait for keys backup to be finished
|
||||||
val latch0 = CountDownLatch(1)
|
val latch0 = CountDownLatch(1)
|
||||||
@ -993,7 +993,7 @@ class KeysBackupTest : InstrumentedTest {
|
|||||||
// - Make alice back up her keys to her homeserver
|
// - Make alice back up her keys to her homeserver
|
||||||
keysBackupTestHelper.prepareAndCreateKeysBackupData(keysBackup)
|
keysBackupTestHelper.prepareAndCreateKeysBackupData(keysBackup)
|
||||||
|
|
||||||
assertTrue(keysBackup.isEnabled)
|
assertTrue(keysBackup.isEnabled())
|
||||||
|
|
||||||
testHelper.await(latch0)
|
testHelper.await(latch0)
|
||||||
|
|
||||||
@ -1012,8 +1012,8 @@ class KeysBackupTest : InstrumentedTest {
|
|||||||
testHelper.await(latch2)
|
testHelper.await(latch2)
|
||||||
|
|
||||||
// -> That must fail and her backup state must be WrongBackUpVersion
|
// -> That must fail and her backup state must be WrongBackUpVersion
|
||||||
assertEquals(KeysBackupState.WrongBackUpVersion, keysBackup.state)
|
assertEquals(KeysBackupState.WrongBackUpVersion, keysBackup.getState())
|
||||||
assertFalse(keysBackup.isEnabled)
|
assertFalse(keysBackup.isEnabled())
|
||||||
|
|
||||||
stateObserver.stopAndCheckStates(null)
|
stateObserver.stopAndCheckStates(null)
|
||||||
cryptoTestData.cleanUp(testHelper)
|
cryptoTestData.cleanUp(testHelper)
|
||||||
@ -1069,7 +1069,7 @@ class KeysBackupTest : InstrumentedTest {
|
|||||||
// - Try to backup all in aliceSession2, it must fail
|
// - Try to backup all in aliceSession2, it must fail
|
||||||
val keysBackup2 = aliceSession2.cryptoService().keysBackupService()
|
val keysBackup2 = aliceSession2.cryptoService().keysBackupService()
|
||||||
|
|
||||||
assertFalse("Backup should not be enabled", keysBackup2.isEnabled)
|
assertFalse("Backup should not be enabled", keysBackup2.isEnabled())
|
||||||
|
|
||||||
val stateObserver2 = StateObserver(keysBackup2)
|
val stateObserver2 = StateObserver(keysBackup2)
|
||||||
|
|
||||||
@ -1088,8 +1088,8 @@ class KeysBackupTest : InstrumentedTest {
|
|||||||
assertFalse(isSuccessful)
|
assertFalse(isSuccessful)
|
||||||
|
|
||||||
// Backup state must be NotTrusted
|
// Backup state must be NotTrusted
|
||||||
assertEquals("Backup state must be NotTrusted", KeysBackupState.NotTrusted, keysBackup2.state)
|
assertEquals("Backup state must be NotTrusted", KeysBackupState.NotTrusted, keysBackup2.getState())
|
||||||
assertFalse("Backup should not be enabled", keysBackup2.isEnabled)
|
assertFalse("Backup should not be enabled", keysBackup2.isEnabled())
|
||||||
|
|
||||||
// - Validate the old device from the new one
|
// - Validate the old device from the new one
|
||||||
aliceSession2.cryptoService().setDeviceVerification(
|
aliceSession2.cryptoService().setDeviceVerification(
|
||||||
@ -1103,7 +1103,7 @@ class KeysBackupTest : InstrumentedTest {
|
|||||||
keysBackup2.addListener(object : KeysBackupStateListener {
|
keysBackup2.addListener(object : KeysBackupStateListener {
|
||||||
override fun onStateChange(newState: KeysBackupState) {
|
override fun onStateChange(newState: KeysBackupState) {
|
||||||
// Check the backup completes
|
// Check the backup completes
|
||||||
if (keysBackup2.state == KeysBackupState.ReadyToBackUp) {
|
if (keysBackup2.getState() == KeysBackupState.ReadyToBackUp) {
|
||||||
// Remove itself from the list of listeners
|
// Remove itself from the list of listeners
|
||||||
keysBackup2.removeListener(this)
|
keysBackup2.removeListener(this)
|
||||||
|
|
||||||
@ -1121,7 +1121,7 @@ class KeysBackupTest : InstrumentedTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// -> It must success
|
// -> It must success
|
||||||
assertTrue(aliceSession2.cryptoService().keysBackupService().isEnabled)
|
assertTrue(aliceSession2.cryptoService().keysBackupService().isEnabled())
|
||||||
|
|
||||||
stateObserver.stopAndCheckStates(null)
|
stateObserver.stopAndCheckStates(null)
|
||||||
stateObserver2.stopAndCheckStates(null)
|
stateObserver2.stopAndCheckStates(null)
|
||||||
@ -1146,17 +1146,17 @@ class KeysBackupTest : InstrumentedTest {
|
|||||||
|
|
||||||
val stateObserver = StateObserver(keysBackup)
|
val stateObserver = StateObserver(keysBackup)
|
||||||
|
|
||||||
assertFalse(keysBackup.isEnabled)
|
assertFalse(keysBackup.isEnabled())
|
||||||
|
|
||||||
val keyBackupCreationInfo = keysBackupTestHelper.prepareAndCreateKeysBackupData(keysBackup)
|
val keyBackupCreationInfo = keysBackupTestHelper.prepareAndCreateKeysBackupData(keysBackup)
|
||||||
|
|
||||||
assertTrue(keysBackup.isEnabled)
|
assertTrue(keysBackup.isEnabled())
|
||||||
|
|
||||||
// Delete the backup
|
// Delete the backup
|
||||||
testHelper.doSync<Unit> { keysBackup.deleteBackup(keyBackupCreationInfo.version, it) }
|
testHelper.doSync<Unit> { keysBackup.deleteBackup(keyBackupCreationInfo.version, it) }
|
||||||
|
|
||||||
// Backup is now disabled
|
// Backup is now disabled
|
||||||
assertFalse(keysBackup.isEnabled)
|
assertFalse(keysBackup.isEnabled())
|
||||||
|
|
||||||
stateObserver.stopAndCheckStates(null)
|
stateObserver.stopAndCheckStates(null)
|
||||||
cryptoTestData.cleanUp(testHelper)
|
cryptoTestData.cleanUp(testHelper)
|
||||||
|
@ -106,7 +106,7 @@ internal class KeysBackupTestHelper(
|
|||||||
|
|
||||||
Assert.assertNotNull(megolmBackupCreationInfo)
|
Assert.assertNotNull(megolmBackupCreationInfo)
|
||||||
|
|
||||||
Assert.assertFalse("Key backup should not be enabled before creation", keysBackup.isEnabled)
|
Assert.assertFalse("Key backup should not be enabled before creation", keysBackup.isEnabled())
|
||||||
|
|
||||||
// Create the version
|
// Create the version
|
||||||
val keysVersion = testHelper.doSync<KeysVersion> {
|
val keysVersion = testHelper.doSync<KeysVersion> {
|
||||||
@ -116,7 +116,7 @@ internal class KeysBackupTestHelper(
|
|||||||
Assert.assertNotNull("Key backup version should not be null", keysVersion.version)
|
Assert.assertNotNull("Key backup version should not be null", keysVersion.version)
|
||||||
|
|
||||||
// Backup must be enable now
|
// Backup must be enable now
|
||||||
Assert.assertTrue(keysBackup.isEnabled)
|
Assert.assertTrue(keysBackup.isEnabled())
|
||||||
|
|
||||||
stateObserver.stopAndCheckStates(null)
|
stateObserver.stopAndCheckStates(null)
|
||||||
return PrepareKeysBackupDataResult(megolmBackupCreationInfo, keysVersion.version)
|
return PrepareKeysBackupDataResult(megolmBackupCreationInfo, keysVersion.version)
|
||||||
@ -128,7 +128,7 @@ internal class KeysBackupTestHelper(
|
|||||||
*/
|
*/
|
||||||
fun waitForKeysBackupToBeInState(session: Session, state: KeysBackupState) {
|
fun waitForKeysBackupToBeInState(session: Session, state: KeysBackupState) {
|
||||||
// If already in the wanted state, return
|
// If already in the wanted state, return
|
||||||
if (session.cryptoService().keysBackupService().state == state) {
|
if (session.cryptoService().keysBackupService().getState() == state) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,10 +204,13 @@ interface KeysBackupService {
|
|||||||
callback: MatrixCallback<ImportRoomKeysResult>)
|
callback: MatrixCallback<ImportRoomKeysResult>)
|
||||||
|
|
||||||
val keysBackupVersion: KeysVersionResult?
|
val keysBackupVersion: KeysVersionResult?
|
||||||
|
|
||||||
val currentBackupVersion: String?
|
val currentBackupVersion: String?
|
||||||
val isEnabled: Boolean
|
get() = keysBackupVersion?.version
|
||||||
val isStucked: Boolean
|
|
||||||
val state: KeysBackupState
|
fun isEnabled(): Boolean
|
||||||
|
fun isStucked(): Boolean
|
||||||
|
fun getState(): KeysBackupState
|
||||||
|
|
||||||
// For gossiping
|
// For gossiping
|
||||||
fun saveBackupRecoveryKey(recoveryKey: String?, version: String?)
|
fun saveBackupRecoveryKey(recoveryKey: String?, version: String?)
|
||||||
|
@ -137,17 +137,11 @@ internal class DefaultKeysBackupService @Inject constructor(
|
|||||||
|
|
||||||
private var keysBackupStateListener: KeysBackupStateListener? = null
|
private var keysBackupStateListener: KeysBackupStateListener? = null
|
||||||
|
|
||||||
override val isEnabled: Boolean
|
override fun isEnabled(): Boolean = keysBackupStateManager.isEnabled
|
||||||
get() = keysBackupStateManager.isEnabled
|
|
||||||
|
|
||||||
override val isStucked: Boolean
|
override fun isStucked(): Boolean = keysBackupStateManager.isStucked
|
||||||
get() = keysBackupStateManager.isStucked
|
|
||||||
|
|
||||||
override val state: KeysBackupState
|
override fun getState(): KeysBackupState = keysBackupStateManager.state
|
||||||
get() = keysBackupStateManager.state
|
|
||||||
|
|
||||||
override val currentBackupVersion: String?
|
|
||||||
get() = keysBackupVersion?.version
|
|
||||||
|
|
||||||
override fun addListener(listener: KeysBackupStateListener) {
|
override fun addListener(listener: KeysBackupStateListener) {
|
||||||
keysBackupStateManager.addListener(listener)
|
keysBackupStateManager.addListener(listener)
|
||||||
@ -291,7 +285,7 @@ internal class DefaultKeysBackupService @Inject constructor(
|
|||||||
this.callback = object : MatrixCallback<Unit> {
|
this.callback = object : MatrixCallback<Unit> {
|
||||||
private fun eventuallyRestartBackup() {
|
private fun eventuallyRestartBackup() {
|
||||||
// Do not stay in KeysBackupState.Unknown but check what is available on the homeserver
|
// Do not stay in KeysBackupState.Unknown but check what is available on the homeserver
|
||||||
if (state == KeysBackupState.Unknown) {
|
if (getState() == KeysBackupState.Unknown) {
|
||||||
checkAndStartKeysBackup()
|
checkAndStartKeysBackup()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -383,7 +377,7 @@ internal class DefaultKeysBackupService @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If backup is finished, notify the main listener
|
// If backup is finished, notify the main listener
|
||||||
if (state === KeysBackupState.ReadyToBackUp) {
|
if (getState() === KeysBackupState.ReadyToBackUp) {
|
||||||
backupAllGroupSessionsCallback?.onSuccess(Unit)
|
backupAllGroupSessionsCallback?.onSuccess(Unit)
|
||||||
resetBackupAllGroupSessionsListeners()
|
resetBackupAllGroupSessionsListeners()
|
||||||
}
|
}
|
||||||
@ -915,12 +909,12 @@ internal class DefaultKeysBackupService @Inject constructor(
|
|||||||
*/
|
*/
|
||||||
fun maybeBackupKeys() {
|
fun maybeBackupKeys() {
|
||||||
when {
|
when {
|
||||||
isStucked -> {
|
isStucked() -> {
|
||||||
// If not already done, or in error case, check for a valid backup version on the homeserver.
|
// If not already done, or in error case, check for a valid backup version on the homeserver.
|
||||||
// If there is one, maybeBackupKeys will be called again.
|
// If there is one, maybeBackupKeys will be called again.
|
||||||
checkAndStartKeysBackup()
|
checkAndStartKeysBackup()
|
||||||
}
|
}
|
||||||
state == KeysBackupState.ReadyToBackUp -> {
|
getState() == KeysBackupState.ReadyToBackUp -> {
|
||||||
keysBackupStateManager.state = KeysBackupState.WillBackUp
|
keysBackupStateManager.state = KeysBackupState.WillBackUp
|
||||||
|
|
||||||
// Wait between 0 and 10 seconds, to avoid backup requests from
|
// Wait between 0 and 10 seconds, to avoid backup requests from
|
||||||
@ -933,8 +927,8 @@ internal class DefaultKeysBackupService @Inject constructor(
|
|||||||
uiHandler.post { backupKeys() }
|
uiHandler.post { backupKeys() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
Timber.v("maybeBackupKeys: Skip it because state: $state")
|
Timber.v("maybeBackupKeys: Skip it because state: ${getState()}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1018,9 +1012,9 @@ internal class DefaultKeysBackupService @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun checkAndStartKeysBackup() {
|
override fun checkAndStartKeysBackup() {
|
||||||
if (!isStucked) {
|
if (!isStucked()) {
|
||||||
// Try to start or restart the backup only if it is in unknown or bad state
|
// Try to start or restart the backup only if it is in unknown or bad state
|
||||||
Timber.w("checkAndStartKeysBackup: invalid state: $state")
|
Timber.w("checkAndStartKeysBackup: invalid state: ${getState()}")
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -1259,16 +1253,16 @@ internal class DefaultKeysBackupService @Inject constructor(
|
|||||||
Timber.v("backupKeys")
|
Timber.v("backupKeys")
|
||||||
|
|
||||||
// Sanity check, as this method can be called after a delay, the state may have change during the delay
|
// Sanity check, as this method can be called after a delay, the state may have change during the delay
|
||||||
if (!isEnabled || backupOlmPkEncryption == null || keysBackupVersion == null) {
|
if (!isEnabled() || backupOlmPkEncryption == null || keysBackupVersion == null) {
|
||||||
Timber.v("backupKeys: Invalid configuration")
|
Timber.v("backupKeys: Invalid configuration")
|
||||||
backupAllGroupSessionsCallback?.onFailure(IllegalStateException("Invalid configuration"))
|
backupAllGroupSessionsCallback?.onFailure(IllegalStateException("Invalid configuration"))
|
||||||
resetBackupAllGroupSessionsListeners()
|
resetBackupAllGroupSessionsListeners()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state === KeysBackupState.BackingUp) {
|
if (getState() === KeysBackupState.BackingUp) {
|
||||||
// Do nothing if we are already backing up
|
// Do nothing if we are already backing up
|
||||||
Timber.v("backupKeys: Invalid state: $state")
|
Timber.v("backupKeys: Invalid state: ${getState()}")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ class SecurityBootstrapTest : VerificationTestBase() {
|
|||||||
assert(uiSession.cryptoService().crossSigningService().isCrossSigningInitialized())
|
assert(uiSession.cryptoService().crossSigningService().isCrossSigningInitialized())
|
||||||
assert(uiSession.cryptoService().crossSigningService().canCrossSign())
|
assert(uiSession.cryptoService().crossSigningService().canCrossSign())
|
||||||
assert(uiSession.cryptoService().crossSigningService().allPrivateKeysKnown())
|
assert(uiSession.cryptoService().crossSigningService().allPrivateKeysKnown())
|
||||||
assert(uiSession.cryptoService().keysBackupService().isEnabled)
|
assert(uiSession.cryptoService().keysBackupService().isEnabled())
|
||||||
assert(uiSession.cryptoService().keysBackupService().currentBackupVersion != null)
|
assert(uiSession.cryptoService().keysBackupService().currentBackupVersion != null)
|
||||||
assert(uiSession.sharedSecretStorageService().isRecoverySetup())
|
assert(uiSession.sharedSecretStorageService().isRecoverySetup())
|
||||||
assert(uiSession.sharedSecretStorageService().isMegolmKeyInBackup())
|
assert(uiSession.sharedSecretStorageService().isMegolmKeyInBackup())
|
||||||
|
@ -66,7 +66,7 @@ fun Session.startSyncing(context: Context) {
|
|||||||
*/
|
*/
|
||||||
fun Session.hasUnsavedKeys(): Boolean {
|
fun Session.hasUnsavedKeys(): Boolean {
|
||||||
return cryptoService().inboundGroupSessionsCount(false) > 0 &&
|
return cryptoService().inboundGroupSessionsCount(false) > 0 &&
|
||||||
cryptoService().keysBackupService().state != KeysBackupState.ReadyToBackUp
|
cryptoService().keysBackupService().getState() != KeysBackupState.ReadyToBackUp
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Session.cannotLogoutSafely(): Boolean {
|
fun Session.cannotLogoutSafely(): Boolean {
|
||||||
|
@ -60,7 +60,7 @@ class KeysBackupSettingsViewModel @AssistedInject constructor(@Assisted initialS
|
|||||||
init {
|
init {
|
||||||
setState {
|
setState {
|
||||||
this.copy(
|
this.copy(
|
||||||
keysBackupState = keysBackupService.state,
|
keysBackupState = keysBackupService.getState(),
|
||||||
keysBackupVersion = keysBackupService.keysBackupVersion
|
keysBackupVersion = keysBackupService.keysBackupVersion
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -206,7 +206,7 @@ class KeysBackupSettingsViewModel @AssistedInject constructor(@Assisted initialS
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun canExit(): Boolean {
|
fun canExit(): Boolean {
|
||||||
val currentBackupState = keysBackupService.state
|
val currentBackupState = keysBackupService.getState()
|
||||||
|
|
||||||
return currentBackupState == KeysBackupState.Unknown ||
|
return currentBackupState == KeysBackupState.Unknown ||
|
||||||
currentBackupState == KeysBackupState.CheckingBackUpOnHomeserver
|
currentBackupState == KeysBackupState.CheckingBackUpOnHomeserver
|
||||||
|
@ -401,8 +401,8 @@ class MessageActionsViewModel @AssistedInject constructor(
|
|||||||
if (vectorPreferences.developerMode()) {
|
if (vectorPreferences.developerMode()) {
|
||||||
if (timelineEvent.isEncrypted() && timelineEvent.root.mCryptoError != null) {
|
if (timelineEvent.isEncrypted() && timelineEvent.root.mCryptoError != null) {
|
||||||
val keysBackupService = session.cryptoService().keysBackupService()
|
val keysBackupService = session.cryptoService().keysBackupService()
|
||||||
if (keysBackupService.state == KeysBackupState.NotTrusted ||
|
if (keysBackupService.getState() == KeysBackupState.NotTrusted ||
|
||||||
(keysBackupService.state == KeysBackupState.ReadyToBackUp &&
|
(keysBackupService.getState() == KeysBackupState.ReadyToBackUp &&
|
||||||
keysBackupService.canRestoreKeys())
|
keysBackupService.canRestoreKeys())
|
||||||
) {
|
) {
|
||||||
add(EventSharedAction.UseKeyBackup)
|
add(EventSharedAction.UseKeyBackup)
|
||||||
|
@ -81,7 +81,7 @@ class ServerBackupStatusViewModel @AssistedInject constructor(@Assisted initialS
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
session.cryptoService().keysBackupService().addListener(this)
|
session.cryptoService().keysBackupService().addListener(this)
|
||||||
keysBackupState.value = session.cryptoService().keysBackupService().state
|
keysBackupState.value = session.cryptoService().keysBackupService().getState()
|
||||||
val liveUserAccountData = session.flow().liveUserAccountData(setOf(MASTER_KEY_SSSS_NAME, USER_SIGNING_KEY_SSSS_NAME, SELF_SIGNING_KEY_SSSS_NAME))
|
val liveUserAccountData = session.flow().liveUserAccountData(setOf(MASTER_KEY_SSSS_NAME, USER_SIGNING_KEY_SSSS_NAME, SELF_SIGNING_KEY_SSSS_NAME))
|
||||||
val liveCrossSigningInfo = session.flow().liveCrossSigningInfo(session.myUserId)
|
val liveCrossSigningInfo = session.flow().liveCrossSigningInfo(session.myUserId)
|
||||||
val liveCrossSigningPrivateKeys = session.flow().liveCrossSigningPrivateKeys()
|
val liveCrossSigningPrivateKeys = session.flow().liveCrossSigningPrivateKeys()
|
||||||
@ -116,7 +116,7 @@ class ServerBackupStatusViewModel @AssistedInject constructor(@Assisted initialS
|
|||||||
}
|
}
|
||||||
|
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
keyBackupFlow.tryEmit(session.cryptoService().keysBackupService().state)
|
keyBackupFlow.tryEmit(session.cryptoService().keysBackupService().getState())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,7 +148,7 @@ class ServerBackupStatusViewModel @AssistedInject constructor(@Assisted initialS
|
|||||||
|
|
||||||
override fun onStateChange(newState: KeysBackupState) {
|
override fun onStateChange(newState: KeysBackupState) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
keyBackupFlow.tryEmit(session.cryptoService().keysBackupService().state)
|
keyBackupFlow.tryEmit(session.cryptoService().keysBackupService().getState())
|
||||||
}
|
}
|
||||||
keysBackupState.value = newState
|
keysBackupState.value = newState
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ class SignoutCheckViewModel @AssistedInject constructor(
|
|||||||
|
|
||||||
val quad4SIsSetup = session.sharedSecretStorageService().isRecoverySetup()
|
val quad4SIsSetup = session.sharedSecretStorageService().isRecoverySetup()
|
||||||
val allKeysKnown = session.cryptoService().crossSigningService().allPrivateKeysKnown()
|
val allKeysKnown = session.cryptoService().crossSigningService().allPrivateKeysKnown()
|
||||||
val backupState = session.cryptoService().keysBackupService().state
|
val backupState = session.cryptoService().keysBackupService().getState()
|
||||||
setState {
|
setState {
|
||||||
copy(
|
copy(
|
||||||
userId = session.myUserId,
|
userId = session.myUserId,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user