mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-23 10:20:25 +01:00
Update the storage service.
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user