Update the storage service.

This commit is contained in:
Greyson Parrelli
2020-02-10 13:42:43 -05:00
parent 133bd44b85
commit 6184e5f828
44 changed files with 1592 additions and 431 deletions

View File

@@ -14,7 +14,7 @@ public final class RegistrationValues {
this.store = store;
}
public synchronized void onNewInstall() {
public synchronized void onFirstEverAppLaunch() {
store.beginWrite()
.putBoolean(REGISTRATION_COMPLETE, false)
// TODO [greyson] [pins] Maybe re-enable in the future
@@ -23,7 +23,7 @@ public final class RegistrationValues {
}
public synchronized void clearRegistrationComplete() {
onNewInstall();
onFirstEverAppLaunch();
}
public synchronized void setRegistrationComplete() {

View File

@@ -4,6 +4,7 @@ import androidx.annotation.NonNull;
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.thoughtcrime.securesms.logging.SignalUncaughtExceptionHandler;
import org.thoughtcrime.securesms.util.FeatureFlags;
/**
* Simple, encrypted key-value store.
@@ -15,6 +16,11 @@ public final class SignalStore {
private SignalStore() {}
public static void onFirstEverAppLaunch() {
registrationValues().onFirstEverAppLaunch();
storageServiceValues().setFirstStorageSyncCompleted(false);
}
public static @NonNull KbsValues kbsValues() {
return new KbsValues(getStore());
}
@@ -31,6 +37,10 @@ public final class SignalStore {
return new RemoteConfigValues(getStore());
}
public static @NonNull StorageServiceValues storageServiceValues() {
return new StorageServiceValues(getStore());
}
public static long getLastPrekeyRefreshTime() {
return getStore().getLong(LAST_PREKEY_REFRESH_TIME, 0);
}

View File

@@ -0,0 +1,50 @@
package org.thoughtcrime.securesms.keyvalue;
import androidx.annotation.NonNull;
import org.thoughtcrime.securesms.util.FeatureFlags;
import org.whispersystems.signalservice.api.kbs.MasterKey;
import java.security.SecureRandom;
public class StorageServiceValues {
private static final String STORAGE_MASTER_KEY = "storage.storage_master_key";
private static final String FIRST_STORAGE_SYNC_COMPLETED = "storage.first_storage_sync_completed";
private static final String LAST_SYNC_TIME = "storage.last_sync_time";
private final KeyValueStore store;
StorageServiceValues(@NonNull KeyValueStore store) {
this.store = store;
}
public synchronized MasterKey getOrCreateStorageMasterKey() {
byte[] blob = store.getBlob(STORAGE_MASTER_KEY, null);
if (blob == null) {
store.beginWrite()
.putBlob(STORAGE_MASTER_KEY, MasterKey.createNew(new SecureRandom()).serialize())
.commit();
blob = store.getBlob(STORAGE_MASTER_KEY, null);
}
return new MasterKey(blob);
}
public boolean hasFirstStorageSyncCompleted() {
return !FeatureFlags.storageServiceRestore() || store.getBoolean(FIRST_STORAGE_SYNC_COMPLETED, true);
}
public void setFirstStorageSyncCompleted(boolean completed) {
store.beginWrite().putBoolean(FIRST_STORAGE_SYNC_COMPLETED, completed).apply();
}
public long getLastSyncTime() {
return store.getLong(LAST_SYNC_TIME, 0);
}
public void onSyncCompleted() {
store.beginWrite().putLong(LAST_SYNC_TIME, System.currentTimeMillis()).apply();
}
}