-
-
Notifications
You must be signed in to change notification settings - Fork 6k
/
SignalStore.java
107 lines (81 loc) · 3.15 KB
/
SignalStore.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package org.thoughtcrime.securesms.keyvalue;
import androidx.annotation.NonNull;
import androidx.preference.PreferenceDataStore;
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.thoughtcrime.securesms.logging.SignalUncaughtExceptionHandler;
/**
* Simple, encrypted key-value store.
*/
public final class SignalStore {
private static final String LAST_PREKEY_REFRESH_TIME = "last_prekey_refresh_time";
private static final String MESSAGE_REQUEST_ENABLE_TIME = "message_request_enable_time";
private SignalStore() {}
public static void onFirstEverAppLaunch() {
registrationValues().onFirstEverAppLaunch();
uiHints().onFirstEverAppLaunch();
}
public static @NonNull KbsValues kbsValues() {
return new KbsValues(getStore());
}
public static @NonNull RegistrationValues registrationValues() {
return new RegistrationValues(getStore());
}
public static @NonNull PinValues pinValues() {
return new PinValues(getStore());
}
public static @NonNull RemoteConfigValues remoteConfigValues() {
return new RemoteConfigValues(getStore());
}
public static @NonNull StorageServiceValues storageServiceValues() {
return new StorageServiceValues(getStore());
}
public static @NonNull GroupsV2AuthorizationSignalStoreCache groupsV2AuthorizationCache() {
return new GroupsV2AuthorizationSignalStoreCache(getStore());
}
public static long getLastPrekeyRefreshTime() {
return getStore().getLong(LAST_PREKEY_REFRESH_TIME, 0);
}
public static void setLastPrekeyRefreshTime(long time) {
putLong(LAST_PREKEY_REFRESH_TIME, time);
}
public static long getMessageRequestEnableTime() {
return getStore().getLong(MESSAGE_REQUEST_ENABLE_TIME, 0);
}
public static void setMessageRequestEnableTime(long time) {
putLong(MESSAGE_REQUEST_ENABLE_TIME, time);
}
public static UiHints uiHints() {
return new UiHints(getStore());
}
public static @NonNull PreferenceDataStore getPreferenceDataStore() {
return new SignalPreferenceDataStore(getStore());
}
/**
* Ensures any pending writes are finished. Only intended to be called by
* {@link SignalUncaughtExceptionHandler}.
*/
public static void blockUntilAllWritesFinished() {
getStore().blockUntilAllWritesFinished();
}
private static @NonNull KeyValueStore getStore() {
return ApplicationDependencies.getKeyValueStore();
}
private static void putBlob(@NonNull String key, byte[] value) {
getStore().beginWrite().putBlob(key, value).apply();
}
private static void putBoolean(@NonNull String key, boolean value) {
getStore().beginWrite().putBoolean(key, value).apply();
}
private static void putFloat(@NonNull String key, float value) {
getStore().beginWrite().putFloat(key, value).apply();
}
private static void putInteger(@NonNull String key, int value) {
getStore().beginWrite().putInteger(key, value).apply();
}
private static void putLong(@NonNull String key, long value) {
getStore().beginWrite().putLong(key, value).apply();
}
private static void putString(@NonNull String key, String value) {
getStore().beginWrite().putString(key, value).apply();
}
}