mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-26 03:40:56 +01:00
Convert StorageServiceValues to kotlin.
This commit is contained in:
@@ -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())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user