mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-23 02:10:44 +01:00
Include additional settings in backup.
This commit is contained in:
committed by
Greyson Parrelli
parent
1f9afb6c6e
commit
faa19acf81
@@ -4,6 +4,9 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public final class CertificateValues extends SignalStoreValues {
|
||||
|
||||
private static final String UD_CERTIFICATE_UUID_AND_E164 = "certificate.uuidAndE164";
|
||||
@@ -17,6 +20,11 @@ public final class CertificateValues extends SignalStoreValues {
|
||||
void onFirstEverAppLaunch() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull List<String> getKeysToIncludeInBackup() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
public void setUnidentifiedAccessCertificate(@NonNull CertificateType certificateType,
|
||||
@Nullable byte[] certificate)
|
||||
|
||||
@@ -4,6 +4,9 @@ import androidx.annotation.NonNull;
|
||||
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiUtil;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class EmojiValues extends SignalStoreValues {
|
||||
|
||||
private static final String PREFIX = "emojiPref__";
|
||||
@@ -17,6 +20,11 @@ public class EmojiValues extends SignalStoreValues {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull List<String> getKeysToIncludeInBackup() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public void setPreferredVariation(@NonNull String emoji) {
|
||||
String canonical = EmojiUtil.getCanonicalRepresentation(emoji);
|
||||
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
package org.thoughtcrime.securesms.keyvalue;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.thoughtcrime.securesms.util.FeatureFlags;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public final class InternalValues extends SignalStoreValues {
|
||||
|
||||
public static final String GV2_DO_NOT_CREATE_GV2 = "internal.gv2.do_not_create_gv2";
|
||||
@@ -21,6 +26,11 @@ public final class InternalValues extends SignalStoreValues {
|
||||
void onFirstEverAppLaunch() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull List<String> getKeysToIncludeInBackup() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not attempt to create GV2 groups, i.e. will force creation of GV1 or MMS groups.
|
||||
*/
|
||||
|
||||
@@ -11,6 +11,8 @@ import org.whispersystems.signalservice.internal.contacts.entities.TokenResponse
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public final class KbsValues extends SignalStoreValues {
|
||||
|
||||
@@ -30,6 +32,11 @@ public final class KbsValues extends SignalStoreValues {
|
||||
void onFirstEverAppLaunch() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull List<String> getKeysToIncludeInBackup() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deliberately does not clear the {@link #MASTER_KEY}.
|
||||
*
|
||||
|
||||
@@ -106,7 +106,8 @@ public class KeyValueDataSet implements KeyValueReader {
|
||||
}
|
||||
}
|
||||
|
||||
boolean containsKey(@NonNull String key) {
|
||||
@Override
|
||||
public boolean containsKey(@NonNull String key) {
|
||||
return values.containsKey(key);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,4 +9,5 @@ interface KeyValueReader {
|
||||
int getInteger(@NonNull String key, int defaultValue);
|
||||
long getLong(@NonNull String key, long defaultValue);
|
||||
String getString(@NonNull String key, String defaultValue);
|
||||
boolean containsKey(@NonNull String key);
|
||||
}
|
||||
|
||||
@@ -87,6 +87,13 @@ public final class KeyValueStore implements KeyValueReader {
|
||||
return dataSet.getString(key, defaultValue);
|
||||
}
|
||||
|
||||
@AnyThread
|
||||
@Override
|
||||
public synchronized boolean containsKey(@NonNull String key) {
|
||||
initializeIfNecessary();
|
||||
return dataSet.containsKey(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A writer that allows writing and removing multiple entries in a single atomic
|
||||
* transaction.
|
||||
|
||||
@@ -2,6 +2,9 @@ package org.thoughtcrime.securesms.keyvalue;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public final class MiscellaneousValues extends SignalStoreValues {
|
||||
|
||||
private static final String LAST_PREKEY_REFRESH_TIME = "last_prekey_refresh_time";
|
||||
@@ -21,6 +24,11 @@ public final class MiscellaneousValues extends SignalStoreValues {
|
||||
putLong(MESSAGE_REQUEST_ENABLE_TIME, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull List<String> getKeysToIncludeInBackup() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public long getLastPrekeyRefreshTime() {
|
||||
return getLong(LAST_PREKEY_REFRESH_TIME, 0);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,9 @@ import androidx.annotation.NonNull;
|
||||
import org.thoughtcrime.securesms.phonenumbers.PhoneNumberFormatter;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public final class OnboardingValues extends SignalStoreValues {
|
||||
|
||||
private static final String SHOW_NEW_GROUP = "onboarding.new_group";
|
||||
@@ -24,6 +27,11 @@ public final class OnboardingValues extends SignalStoreValues {
|
||||
putBoolean(SHOW_SMS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull List<String> getKeysToIncludeInBackup() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public void clearAll() {
|
||||
setShowNewGroup(false);
|
||||
setShowInviteFriends(false);
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.thoughtcrime.securesms.util.FeatureFlags;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public final class PhoneNumberPrivacyValues extends SignalStoreValues {
|
||||
|
||||
@@ -29,6 +30,11 @@ public final class PhoneNumberPrivacyValues extends SignalStoreValues {
|
||||
// .apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull List<String> getKeysToIncludeInBackup() {
|
||||
return Arrays.asList(SHARING_MODE, LISTING_MODE);
|
||||
}
|
||||
|
||||
public @NonNull PhoneNumberSharingMode getPhoneNumberSharingMode() {
|
||||
if (!FeatureFlags.phoneNumberPrivacy()) return PhoneNumberSharingMode.EVERYONE;
|
||||
return PhoneNumberSharingMode.values()[getInteger(SHARING_MODE, PhoneNumberSharingMode.EVERYONE.ordinal())];
|
||||
|
||||
@@ -9,6 +9,9 @@ import org.thoughtcrime.securesms.lock.SignalPinReminders;
|
||||
import org.thoughtcrime.securesms.lock.v2.PinKeyboardType;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Specifically handles just the UI/UX state around PINs. For actual keys, see {@link KbsValues}.
|
||||
*/
|
||||
@@ -30,6 +33,11 @@ public final class PinValues extends SignalStoreValues {
|
||||
void onFirstEverAppLaunch() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull List<String> getKeysToIncludeInBackup() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public void onEntrySuccess(@NonNull String pin) {
|
||||
long nextInterval = SignalPinReminders.getNextInterval(getCurrentInterval());
|
||||
Log.i(TAG, "onEntrySuccess() nextInterval: " + nextInterval);
|
||||
|
||||
@@ -6,6 +6,9 @@ import androidx.annotation.Nullable;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.whispersystems.signalservice.internal.configuration.SignalProxy;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public final class ProxyValues extends SignalStoreValues {
|
||||
|
||||
private static final String KEY_PROXY_ENABLED = "proxy.enabled";
|
||||
@@ -20,6 +23,11 @@ public final class ProxyValues extends SignalStoreValues {
|
||||
void onFirstEverAppLaunch() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull List<String> getKeysToIncludeInBackup() {
|
||||
return Arrays.asList(KEY_PROXY_ENABLED, KEY_HOST, KEY_PORT);
|
||||
}
|
||||
|
||||
public void enableProxy(@NonNull SignalProxy proxy) {
|
||||
if (Util.isEmpty(proxy.getHost())) {
|
||||
throw new IllegalArgumentException("Empty host!");
|
||||
|
||||
@@ -3,6 +3,9 @@ package org.thoughtcrime.securesms.keyvalue;
|
||||
import androidx.annotation.CheckResult;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public final class RegistrationValues extends SignalStoreValues {
|
||||
|
||||
private static final String REGISTRATION_COMPLETE = "registration.complete";
|
||||
@@ -19,6 +22,11 @@ public final class RegistrationValues extends SignalStoreValues {
|
||||
.commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull List<String> getKeysToIncludeInBackup() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public synchronized void clearRegistrationComplete() {
|
||||
onFirstEverAppLaunch();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@ import androidx.annotation.NonNull;
|
||||
|
||||
import org.signal.core.util.logging.Log;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public final class RemoteConfigValues extends SignalStoreValues {
|
||||
|
||||
private static final String TAG = Log.tag(RemoteConfigValues.class);
|
||||
@@ -20,6 +23,11 @@ public final class RemoteConfigValues extends SignalStoreValues {
|
||||
void onFirstEverAppLaunch() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull List<String> getKeysToIncludeInBackup() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public String getCurrentConfig() {
|
||||
return getString(CURRENT_CONFIG, null);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@ import androidx.annotation.Nullable;
|
||||
|
||||
import org.thoughtcrime.securesms.webrtc.CallBandwidthMode;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public final class SettingsValues extends SignalStoreValues {
|
||||
|
||||
public static final String LINK_PREVIEWS = "settings.link_previews";
|
||||
@@ -29,9 +32,21 @@ public final class SettingsValues extends SignalStoreValues {
|
||||
|
||||
@Override
|
||||
void onFirstEverAppLaunch() {
|
||||
getStore().beginWrite()
|
||||
.putBoolean(LINK_PREVIEWS, true)
|
||||
.apply();
|
||||
if (!getStore().containsKey(LINK_PREVIEWS)) {
|
||||
getStore().beginWrite()
|
||||
.putBoolean(LINK_PREVIEWS, true)
|
||||
.apply();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull List<String> getKeysToIncludeInBackup() {
|
||||
return Arrays.asList(LINK_PREVIEWS,
|
||||
KEEP_MESSAGES_DURATION,
|
||||
PREFER_SYSTEM_CONTACT_PHOTOS,
|
||||
CALL_BANDWIDTH_MODE,
|
||||
THREAD_TRIM_LENGTH,
|
||||
THREAD_TRIM_ENABLED);
|
||||
}
|
||||
|
||||
public boolean isLinkPreviewsEnabled() {
|
||||
|
||||
@@ -7,6 +7,9 @@ import androidx.preference.PreferenceDataStore;
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.util.SignalUncaughtExceptionHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Simple, encrypted key-value store.
|
||||
*/
|
||||
@@ -62,6 +65,7 @@ public final class SignalStore {
|
||||
tooltips().onFirstEverAppLaunch();
|
||||
misc().onFirstEverAppLaunch();
|
||||
internalValues().onFirstEverAppLaunch();
|
||||
emojiValues().onFirstEverAppLaunch();
|
||||
settings().onFirstEverAppLaunch();
|
||||
certificateValues().onFirstEverAppLaunch();
|
||||
phoneNumberPrivacy().onFirstEverAppLaunch();
|
||||
@@ -70,6 +74,27 @@ public final class SignalStore {
|
||||
proxy().onFirstEverAppLaunch();
|
||||
}
|
||||
|
||||
public static List<String> getKeysToIncludeInBackup() {
|
||||
List<String> keys = new ArrayList<>();
|
||||
keys.addAll(kbsValues().getKeysToIncludeInBackup());
|
||||
keys.addAll(registrationValues().getKeysToIncludeInBackup());
|
||||
keys.addAll(pinValues().getKeysToIncludeInBackup());
|
||||
keys.addAll(remoteConfigValues().getKeysToIncludeInBackup());
|
||||
keys.addAll(storageServiceValues().getKeysToIncludeInBackup());
|
||||
keys.addAll(uiHints().getKeysToIncludeInBackup());
|
||||
keys.addAll(tooltips().getKeysToIncludeInBackup());
|
||||
keys.addAll(misc().getKeysToIncludeInBackup());
|
||||
keys.addAll(internalValues().getKeysToIncludeInBackup());
|
||||
keys.addAll(emojiValues().getKeysToIncludeInBackup());
|
||||
keys.addAll(settings().getKeysToIncludeInBackup());
|
||||
keys.addAll(certificateValues().getKeysToIncludeInBackup());
|
||||
keys.addAll(phoneNumberPrivacy().getKeysToIncludeInBackup());
|
||||
keys.addAll(onboarding().getKeysToIncludeInBackup());
|
||||
keys.addAll(wallpaper().getKeysToIncludeInBackup());
|
||||
keys.addAll(proxy().getKeysToIncludeInBackup());
|
||||
return keys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces the store to re-fetch all of it's data from the database.
|
||||
* Should only be used for testing!
|
||||
|
||||
@@ -2,6 +2,8 @@ package org.thoughtcrime.securesms.keyvalue;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
abstract class SignalStoreValues {
|
||||
|
||||
private final KeyValueStore store;
|
||||
@@ -16,6 +18,8 @@ abstract class SignalStoreValues {
|
||||
|
||||
abstract void onFirstEverAppLaunch();
|
||||
|
||||
abstract @NonNull List<String> getKeysToIncludeInBackup();
|
||||
|
||||
String getString(String key, String defaultValue) {
|
||||
return store.getString(key, defaultValue);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@ import androidx.annotation.NonNull;
|
||||
|
||||
import org.whispersystems.signalservice.api.storage.StorageKey;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class StorageServiceValues extends SignalStoreValues {
|
||||
|
||||
private static final String LAST_SYNC_TIME = "storage.last_sync_time";
|
||||
@@ -17,6 +20,11 @@ public class StorageServiceValues extends SignalStoreValues {
|
||||
void onFirstEverAppLaunch() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull List<String> getKeysToIncludeInBackup() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public synchronized StorageKey getOrCreateStorageKey() {
|
||||
return SignalStore.kbsValues().getOrCreateMasterKey().deriveStorageServiceKey();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,9 @@ package org.thoughtcrime.securesms.keyvalue;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class TooltipValues extends SignalStoreValues {
|
||||
|
||||
private static final int GROUP_CALLING_MAX_TOOLTIP_DISPLAY_COUNT = 3;
|
||||
@@ -19,6 +22,11 @@ public class TooltipValues extends SignalStoreValues {
|
||||
public void onFirstEverAppLaunch() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull List<String> getKeysToIncludeInBackup() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public boolean hasSeenBlurHudIconTooltip() {
|
||||
return getBoolean(BLUR_HUD_ICON, false);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,9 @@ package org.thoughtcrime.securesms.keyvalue;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class UiHints extends SignalStoreValues {
|
||||
|
||||
private static final String HAS_SEEN_GROUP_SETTINGS_MENU_TOAST = "uihints.has_seen_group_settings_menu_toast";
|
||||
@@ -16,6 +19,11 @@ public class UiHints extends SignalStoreValues {
|
||||
markHasSeenGroupSettingsMenuToast();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull List<String> getKeysToIncludeInBackup() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public void markHasSeenGroupSettingsMenuToast() {
|
||||
putBoolean(HAS_SEEN_GROUP_SETTINGS_MENU_TOAST, true);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,9 @@ import org.thoughtcrime.securesms.wallpaper.ChatWallpaper;
|
||||
import org.thoughtcrime.securesms.wallpaper.ChatWallpaperFactory;
|
||||
import org.thoughtcrime.securesms.wallpaper.WallpaperStorage;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public final class WallpaperValues extends SignalStoreValues {
|
||||
|
||||
private static final String TAG = Log.tag(WallpaperValues.class);
|
||||
@@ -29,6 +32,11 @@ public final class WallpaperValues extends SignalStoreValues {
|
||||
void onFirstEverAppLaunch() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull List<String> getKeysToIncludeInBackup() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public void setWallpaper(@NonNull Context context, @Nullable ChatWallpaper wallpaper) {
|
||||
Wallpaper currentWallpaper = getCurrentWallpaper();
|
||||
Uri currentUri = null;
|
||||
|
||||
Reference in New Issue
Block a user