Convert StorageServiceValues to kotlin.
This commit is contained in:
parent
5930a8133a
commit
2ebf668db4
13 changed files with 71 additions and 92 deletions
|
@ -167,7 +167,7 @@ public abstract class PassphraseRequiredActivity extends BaseActivity implements
|
|||
return STATE_UI_BLOCKING_UPGRADE;
|
||||
} else if (!TextSecurePreferences.hasPromptedPushRegistration(this)) {
|
||||
return STATE_WELCOME_PUSH_SCREEN;
|
||||
} else if (SignalStore.storageService().needsAccountRestore()) {
|
||||
} else if (SignalStore.storageService().getNeedsAccountRestore()) {
|
||||
return STATE_ENTER_SIGNAL_PIN;
|
||||
} else if (userCanTransferOrRestore()) {
|
||||
return STATE_TRANSFER_OR_RESTORE;
|
||||
|
|
|
@ -54,7 +54,7 @@ class MultiDeviceKeysUpdateJob private constructor(parameters: Parameters) : Bas
|
|||
|
||||
val syncMessage = SignalServiceSyncMessage.forKeys(
|
||||
KeysMessage(
|
||||
Optional.of(SignalStore.storageService.getOrCreateStorageKey()),
|
||||
Optional.of(SignalStore.storageService.storageKey),
|
||||
Optional.of(SignalStore.svr.masterKey)
|
||||
)
|
||||
)
|
||||
|
|
|
@ -44,7 +44,7 @@ class StorageAccountRestoreJob private constructor(parameters: Parameters) : Bas
|
|||
@Throws(Exception::class)
|
||||
override fun onRun() {
|
||||
val accountManager = AppDependencies.signalServiceAccountManager
|
||||
val storageServiceKey = SignalStore.storageService.getOrCreateStorageKey()
|
||||
val storageServiceKey = SignalStore.storageService.storageKey
|
||||
|
||||
Log.i(TAG, "Retrieving manifest...")
|
||||
val manifest = accountManager.getStorageManifest(storageServiceKey)
|
||||
|
|
|
@ -61,7 +61,7 @@ class StorageForcePushJob private constructor(parameters: Parameters) : BaseJob(
|
|||
return
|
||||
}
|
||||
|
||||
val storageServiceKey = SignalStore.storageService.getOrCreateStorageKey()
|
||||
val storageServiceKey = SignalStore.storageService.storageKey
|
||||
val accountManager = AppDependencies.signalServiceAccountManager
|
||||
|
||||
val currentVersion = accountManager.storageManifestVersion
|
||||
|
|
|
@ -170,7 +170,7 @@ class StorageSyncJob private constructor(parameters: Parameters) : BaseJob(param
|
|||
AppDependencies.jobManager.add(MultiDeviceStorageSyncRequestJob())
|
||||
}
|
||||
|
||||
SignalStore.storageService.onSyncCompleted()
|
||||
SignalStore.storageService.lastSyncTime = System.currentTimeMillis()
|
||||
} catch (e: InvalidKeyException) {
|
||||
if (SignalStore.account.isPrimaryDevice) {
|
||||
Log.w(TAG, "Failed to decrypt remote storage! Force-pushing and syncing the storage key to linked devices.", e)
|
||||
|
@ -200,7 +200,7 @@ class StorageSyncJob private constructor(parameters: Parameters) : BaseJob(param
|
|||
val stopwatch = Stopwatch("StorageSync")
|
||||
val db = SignalDatabase.rawDatabase
|
||||
val accountManager = AppDependencies.signalServiceAccountManager
|
||||
val storageServiceKey = SignalStore.storageService.getOrCreateStorageKey()
|
||||
val storageServiceKey = SignalStore.storageService.storageKey
|
||||
|
||||
val localManifest = SignalStore.storageService.manifest
|
||||
val remoteManifest = accountManager.getStorageManifestIfDifferentVersion(storageServiceKey, localManifest.version).orElse(localManifest)
|
||||
|
|
|
@ -1,78 +0,0 @@
|
|||
package org.thoughtcrime.securesms.keyvalue;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.whispersystems.signalservice.api.storage.SignalStorageManifest;
|
||||
import org.whispersystems.signalservice.api.storage.StorageKey;
|
||||
import org.whispersystems.signalservice.api.util.Preconditions;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class StorageServiceValues extends SignalStoreValues {
|
||||
|
||||
private static final String LAST_SYNC_TIME = "storage.last_sync_time";
|
||||
private static final String NEEDS_ACCOUNT_RESTORE = "storage.needs_account_restore";
|
||||
private static final String MANIFEST = "storage.manifest";
|
||||
private static final String SYNC_STORAGE_KEY = "storage.syncStorageKey";
|
||||
|
||||
StorageServiceValues(@NonNull KeyValueStore store) {
|
||||
super(store);
|
||||
}
|
||||
|
||||
@Override
|
||||
void onFirstEverAppLaunch() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull List<String> getKeysToIncludeInBackup() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public synchronized StorageKey getOrCreateStorageKey() {
|
||||
if (getStore().containsKey(SYNC_STORAGE_KEY)) {
|
||||
return new StorageKey(getBlob(SYNC_STORAGE_KEY, null));
|
||||
}
|
||||
return SignalStore.svr().getMasterKey().deriveStorageServiceKey();
|
||||
}
|
||||
|
||||
public long getLastSyncTime() {
|
||||
return getLong(LAST_SYNC_TIME, 0);
|
||||
}
|
||||
|
||||
public void onSyncCompleted() {
|
||||
putLong(LAST_SYNC_TIME, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public boolean needsAccountRestore() {
|
||||
return getBoolean(NEEDS_ACCOUNT_RESTORE, false);
|
||||
}
|
||||
|
||||
public void setNeedsAccountRestore(boolean value) {
|
||||
putBoolean(NEEDS_ACCOUNT_RESTORE, value);
|
||||
}
|
||||
|
||||
public void setManifest(@NonNull SignalStorageManifest manifest) {
|
||||
putBlob(MANIFEST, manifest.serialize());
|
||||
}
|
||||
|
||||
public @NonNull SignalStorageManifest getManifest() {
|
||||
byte[] data = getBlob(MANIFEST, null);
|
||||
|
||||
if (data != null) {
|
||||
return SignalStorageManifest.deserialize(data);
|
||||
} else {
|
||||
return SignalStorageManifest.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void setStorageKeyFromPrimary(@NonNull StorageKey storageKey) {
|
||||
Preconditions.checkState(SignalStore.account().isLinkedDevice(), "Can only set storage key directly on linked devices");
|
||||
putBlob(SYNC_STORAGE_KEY, storageKey.serialize());
|
||||
}
|
||||
|
||||
public void clearStorageKeyFromPrimary() {
|
||||
Preconditions.checkState(SignalStore.account().isLinkedDevice(), "Can only clear storage key directly on linked devices");
|
||||
remove(SYNC_STORAGE_KEY);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package org.thoughtcrime.securesms.keyvalue
|
||||
|
||||
import org.whispersystems.signalservice.api.storage.SignalStorageManifest
|
||||
import org.whispersystems.signalservice.api.storage.StorageKey
|
||||
import org.whispersystems.signalservice.api.util.Preconditions
|
||||
|
||||
class StorageServiceValues internal constructor(store: KeyValueStore) : SignalStoreValues(store) {
|
||||
companion object {
|
||||
private const val LAST_SYNC_TIME = "storage.last_sync_time"
|
||||
private const val NEEDS_ACCOUNT_RESTORE = "storage.needs_account_restore"
|
||||
private const val MANIFEST = "storage.manifest"
|
||||
private const val SYNC_STORAGE_KEY = "storage.syncStorageKey"
|
||||
}
|
||||
|
||||
public override fun onFirstEverAppLaunch() = Unit
|
||||
|
||||
public override fun getKeysToIncludeInBackup(): List<String> = emptyList()
|
||||
|
||||
@get:Synchronized
|
||||
val storageKey: StorageKey
|
||||
get() {
|
||||
if (store.containsKey(SYNC_STORAGE_KEY)) {
|
||||
return StorageKey(getBlob(SYNC_STORAGE_KEY, null))
|
||||
}
|
||||
return SignalStore.svr.masterKey.deriveStorageServiceKey()
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun setStorageKeyFromPrimary(storageKey: StorageKey) {
|
||||
Preconditions.checkState(SignalStore.account.isLinkedDevice, "Can only set storage key directly on linked devices")
|
||||
putBlob(SYNC_STORAGE_KEY, storageKey.serialize())
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun clearStorageKeyFromPrimary() {
|
||||
Preconditions.checkState(SignalStore.account.isLinkedDevice, "Can only clear storage key directly on linked devices")
|
||||
remove(SYNC_STORAGE_KEY)
|
||||
}
|
||||
|
||||
var lastSyncTime: Long by longValue(LAST_SYNC_TIME, 0)
|
||||
|
||||
var needsAccountRestore: Boolean by booleanValue(NEEDS_ACCOUNT_RESTORE, false)
|
||||
|
||||
var manifest: SignalStorageManifest
|
||||
get() {
|
||||
val data = getBlob(MANIFEST, null)
|
||||
|
||||
return if (data != null) {
|
||||
SignalStorageManifest.deserialize(data)
|
||||
} else {
|
||||
SignalStorageManifest.EMPTY
|
||||
}
|
||||
}
|
||||
set(manifest) {
|
||||
putBlob(MANIFEST, manifest.serialize())
|
||||
}
|
||||
}
|
|
@ -22,7 +22,7 @@ public class LogSectionPin implements LogSection {
|
|||
.append("Restored via AEP: ").append(SignalStore.svr().getRestoredViaAccountEntropyPool()).append("\n")
|
||||
.append("Opted Out: ").append(SignalStore.svr().hasOptedOut()).append("\n")
|
||||
.append("Last Creation Failed: ").append(SignalStore.svr().lastPinCreateFailed()).append("\n")
|
||||
.append("Needs Account Restore: ").append(SignalStore.storageService().needsAccountRestore()).append("\n")
|
||||
.append("Needs Account Restore: ").append(SignalStore.storageService().getNeedsAccountRestore()).append("\n")
|
||||
.append("PIN Required at Registration: ").append(SignalStore.registration().pinWasRequiredAtRegistration()).append("\n")
|
||||
.append("Registration Complete: ").append(SignalStore.registration().isRegistrationComplete());
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ internal class StorageFixLocalUnknownMigrationJob(
|
|||
|
||||
@Suppress("UsePropertyAccessSyntax")
|
||||
override fun performMigration() {
|
||||
val localStorageIds = SignalStore.storageService.getManifest().storageIds.toSet()
|
||||
val localStorageIds = SignalStore.storageService.manifest.storageIds.toSet()
|
||||
val unknownLocalIds = SignalDatabase.unknownStorageIds.getAllUnknownIds().toSet()
|
||||
val danglingLocalUnknownIds = unknownLocalIds - localStorageIds
|
||||
|
||||
|
|
|
@ -172,7 +172,7 @@ object SvrRepository {
|
|||
SignalStore.svr.isRegistrationLockEnabled = false
|
||||
SignalStore.pin.resetPinReminders()
|
||||
SignalStore.pin.keyboardType = pinKeyboardType
|
||||
SignalStore.storageService.setNeedsAccountRestore(false)
|
||||
SignalStore.storageService.needsAccountRestore = false
|
||||
|
||||
when (implementation.svrVersion) {
|
||||
SvrVersion.SVR2 -> SignalStore.svr.appendSvr2AuthTokenToList(response.authorization.asBasic())
|
||||
|
@ -330,7 +330,7 @@ object SvrRepository {
|
|||
} else if (hasPinToRestore) {
|
||||
Log.i(TAG, "[onRegistrationComplete] Has a PIN to restore.", true)
|
||||
SignalStore.svr.clearRegistrationLockAndPin()
|
||||
SignalStore.storageService.setNeedsAccountRestore(true)
|
||||
SignalStore.storageService.needsAccountRestore = true
|
||||
} else {
|
||||
Log.i(TAG, "[onRegistrationComplete] No registration lock or PIN at all.", true)
|
||||
SignalStore.svr.clearRegistrationLockAndPin()
|
||||
|
@ -347,7 +347,7 @@ object SvrRepository {
|
|||
fun onPinRestoreForgottenOrSkipped() {
|
||||
operationLock.withLock {
|
||||
SignalStore.svr.clearRegistrationLockAndPin()
|
||||
SignalStore.storageService.setNeedsAccountRestore(false)
|
||||
SignalStore.storageService.needsAccountRestore = false
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ class RegistrationActivity : BaseActivity() {
|
|||
SignalStore.misc.shouldShowLinkedDevicesReminder = sharedViewModel.isReregister
|
||||
}
|
||||
|
||||
if (SignalStore.storageService.needsAccountRestore()) {
|
||||
if (SignalStore.storageService.needsAccountRestore) {
|
||||
Log.i(TAG, "Performing pin restore.")
|
||||
startActivity(Intent(this, PinRestoreActivity::class.java))
|
||||
finish()
|
||||
|
|
|
@ -68,7 +68,7 @@ class RegistrationActivity : BaseActivity() {
|
|||
SignalStore.misc.shouldShowLinkedDevicesReminder = sharedViewModel.isReregister
|
||||
}
|
||||
|
||||
if (SignalStore.storageService.needsAccountRestore()) {
|
||||
if (SignalStore.storageService.needsAccountRestore) {
|
||||
Log.i(TAG, "Performing pin restore.")
|
||||
startActivity(Intent(this, PinRestoreActivity::class.java))
|
||||
finish()
|
||||
|
|
|
@ -15,7 +15,7 @@ class StorageServicePlugin : Plugin {
|
|||
val rows = mutableListOf<List<String>>()
|
||||
|
||||
val manager = AppDependencies.signalServiceAccountManager
|
||||
val storageServiceKey = SignalStore.storageService.orCreateStorageKey
|
||||
val storageServiceKey = SignalStore.storageService.storageKey
|
||||
val storageManifestVersion = manager.storageManifestVersion
|
||||
val manifest = manager.getStorageManifestIfDifferentVersion(storageServiceKey, storageManifestVersion - 1).get()
|
||||
val signalStorageRecords = manager.readStorageRecords(storageServiceKey, manifest.storageIds)
|
||||
|
|
Loading…
Add table
Reference in a new issue