@Override
public void execute(Context context) throws Throwable {
- if (context.getAccount().getStorageKey() != null) {
- context.getStorageHelper().readDataFromStorage();
- } else if (!context.getAccount().isPrimaryDevice()) {
- context.getSyncHelper().requestSyncKeys();
- }
+ context.getStorageHelper().readDataFromStorage();
}
}
}
public void readDataFromStorage() throws IOException {
+ final var storageKey = account.getOrCreateStorageKey();
+ if (storageKey == null) {
+ logger.debug("Storage key unknown, requesting from primary device.");
+ context.getSyncHelper().requestSyncKeys();
+ return;
+ }
+
logger.debug("Reading data from remote storage");
Optional<SignalStorageManifest> manifest;
try {
manifest = dependencies.getAccountManager()
- .getStorageManifestIfDifferentVersion(account.getStorageKey(), account.getStorageManifestVersion());
+ .getStorageManifestIfDifferentVersion(storageKey, account.getStorageManifestVersion());
} catch (InvalidKeyException e) {
logger.warn("Manifest couldn't be decrypted, ignoring.");
return;
return storageKey;
}
+ public StorageKey getOrCreateStorageKey() {
+ if (isPrimaryDevice()) {
+ return getOrCreatePinMasterKey().deriveStorageServiceKey();
+ }
+ return storageKey;
+ }
+
public void setStorageKey(final StorageKey storageKey) {
if (storageKey.equals(this.storageKey)) {
return;