-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathTextSecurePreferences.kt
More file actions
1357 lines (1128 loc) · 56.3 KB
/
TextSecurePreferences.kt
File metadata and controls
1357 lines (1128 loc) · 56.3 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package org.session.libsession.utilities
import android.content.Context
import android.hardware.Camera
import androidx.annotation.StyleRes
import androidx.camera.core.CameraSelector
import androidx.core.content.edit
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.update
import kotlinx.serialization.json.Json
import network.loki.messenger.BuildConfig
import network.loki.messenger.R
import network.loki.messenger.libsession_util.protocol.ProFeature
import network.loki.messenger.libsession_util.protocol.ProMessageFeature
import network.loki.messenger.libsession_util.protocol.ProProfileFeature
import network.loki.messenger.libsession_util.util.toBitSet
import org.session.libsession.messaging.file_server.FileServer
import org.session.libsession.utilities.TextSecurePreferences.Companion.AUTOPLAY_AUDIO_MESSAGES
import org.session.libsession.utilities.TextSecurePreferences.Companion.CALL_NOTIFICATIONS_ENABLED
import org.session.libsession.utilities.TextSecurePreferences.Companion.CLASSIC_DARK
import org.session.libsession.utilities.TextSecurePreferences.Companion.CLASSIC_LIGHT
import org.session.libsession.utilities.TextSecurePreferences.Companion.DEBUG_HAS_COPIED_DONATION_URL
import org.session.libsession.utilities.TextSecurePreferences.Companion.DEBUG_HAS_DONATED
import org.session.libsession.utilities.TextSecurePreferences.Companion.DEBUG_SEEN_DONATION_CTA_AMOUNT
import org.session.libsession.utilities.TextSecurePreferences.Companion.DEBUG_SHOW_DONATION_CTA_FROM_POSITIVE_REVIEW
import org.session.libsession.utilities.TextSecurePreferences.Companion.ENVIRONMENT
import org.session.libsession.utilities.TextSecurePreferences.Companion.FOLLOW_SYSTEM_SETTINGS
import org.session.libsession.utilities.TextSecurePreferences.Companion.FORCED_SHORT_TTL
import org.session.libsession.utilities.TextSecurePreferences.Companion.HAS_COPIED_DONATION_URL
import org.session.libsession.utilities.TextSecurePreferences.Companion.HAS_DONATED
import org.session.libsession.utilities.TextSecurePreferences.Companion.HAS_SEEN_PRO_EXPIRED
import org.session.libsession.utilities.TextSecurePreferences.Companion.HAS_SEEN_PRO_EXPIRING
import org.session.libsession.utilities.TextSecurePreferences.Companion.HAVE_SHOWN_A_NOTIFICATION_ABOUT_TOKEN_PAGE
import org.session.libsession.utilities.TextSecurePreferences.Companion.HIDE_PASSWORD
import org.session.libsession.utilities.TextSecurePreferences.Companion.LAST_PATH_ROTATION
import org.session.libsession.utilities.TextSecurePreferences.Companion.LAST_SEEN_DONATION_CTA
import org.session.libsession.utilities.TextSecurePreferences.Companion.LAST_SNODE_POOL_REFRESH
import org.session.libsession.utilities.TextSecurePreferences.Companion.LAST_VACUUM_TIME
import org.session.libsession.utilities.TextSecurePreferences.Companion.LAST_VERSION_CHECK
import org.session.libsession.utilities.TextSecurePreferences.Companion.LEGACY_PREF_KEY_SELECTED_UI_MODE
import org.session.libsession.utilities.TextSecurePreferences.Companion.OCEAN_DARK
import org.session.libsession.utilities.TextSecurePreferences.Companion.OCEAN_LIGHT
import org.session.libsession.utilities.TextSecurePreferences.Companion.SEEN_DONATION_CTA_AMOUNT
import org.session.libsession.utilities.TextSecurePreferences.Companion.SELECTED_ACCENT_COLOR
import org.session.libsession.utilities.TextSecurePreferences.Companion.SELECTED_STYLE
import org.session.libsession.utilities.TextSecurePreferences.Companion.SEND_WITH_ENTER
import org.session.libsession.utilities.TextSecurePreferences.Companion.SET_FORCE_CURRENT_USER_PRO
import org.session.libsession.utilities.TextSecurePreferences.Companion.SET_FORCE_INCOMING_MESSAGE_PRO
import org.session.libsession.utilities.TextSecurePreferences.Companion.SET_FORCE_OTHER_USERS_PRO
import org.session.libsession.utilities.TextSecurePreferences.Companion.SET_FORCE_POST_PRO
import org.session.libsession.utilities.TextSecurePreferences.Companion.SHOWN_CALL_NOTIFICATION
import org.session.libsession.utilities.TextSecurePreferences.Companion.SHOWN_CALL_WARNING
import org.session.libsession.utilities.TextSecurePreferences.Companion.SHOW_DONATION_CTA_FROM_POSITIVE_REVIEW
import org.session.libsession.utilities.TextSecurePreferences.Companion._events
import org.session.libsignal.utilities.Log
import org.thoughtcrime.securesms.debugmenu.DebugMenuViewModel
import org.thoughtcrime.securesms.pro.toProMessageFeatures
import org.thoughtcrime.securesms.pro.toProProfileFeatures
import java.io.IOException
import java.time.ZonedDateTime
import javax.inject.Inject
import javax.inject.Singleton
interface TextSecurePreferences {
fun getConfigurationMessageSynced(): Boolean
fun setConfigurationMessageSynced(value: Boolean)
fun isScreenLockEnabled(): Boolean
fun setScreenLockEnabled(value: Boolean)
fun getScreenLockTimeout(): Long
fun setScreenLockTimeout(value: Long)
fun setBackupPassphrase(passphrase: String?)
fun getBackupPassphrase(): String?
fun setEncryptedBackupPassphrase(encryptedPassphrase: String?)
fun getEncryptedBackupPassphrase(): String?
fun setBackupEnabled(value: Boolean)
fun isBackupEnabled(): Boolean
fun setNextBackupTime(time: Long)
fun getNextBackupTime(): Long
fun setBackupSaveDir(dirUri: String?)
fun getBackupSaveDir(): String?
fun getNeedsSqlCipherMigration(): Boolean
fun isIncognitoKeyboardEnabled(): Boolean
fun setIncognitoKeyboardEnabled(enabled : Boolean)
fun isTypingIndicatorsEnabled(): Boolean
fun setTypingIndicatorsEnabled(enabled: Boolean)
fun isLinkPreviewsEnabled(): Boolean
fun setLinkPreviewsEnabled(enabled: Boolean)
fun hasSeenGIFMetaDataWarning(): Boolean
fun setHasSeenGIFMetaDataWarning()
fun isGifSearchInGridLayout(): Boolean
fun setIsGifSearchInGridLayout(isGrid: Boolean)
fun getMessageBodyTextSize(): Int
fun setPreferredCameraDirection(value: CameraSelector)
fun getPreferredCameraDirection(): CameraSelector
fun getRepeatAlertsCount(): Int
fun isInThreadNotifications(): Boolean
fun isUniversalUnidentifiedAccess(): Boolean
fun getUpdateApkRefreshTime(): Long
fun setUpdateApkRefreshTime(value: Long)
fun setUpdateApkDownloadId(value: Long)
fun getUpdateApkDownloadId(): Long
fun setUpdateApkDigest(value: String?)
fun getUpdateApkDigest(): String?
fun getHasLegacyConfig(): Boolean
fun setHasLegacyConfig(newValue: Boolean)
fun isPasswordDisabled(): Boolean
fun setPasswordDisabled(disabled: Boolean)
fun getLastVersionCode(): Int
fun setLastVersionCode(versionCode: Int)
fun isPassphraseTimeoutEnabled(): Boolean
fun getPassphraseTimeoutInterval(): Int
fun getLanguage(): String?
fun setThreadLengthTrimmingEnabled(enabled : Boolean)
fun isThreadLengthTrimmingEnabled(): Boolean
fun getBooleanPreference(key: String?, defaultValue: Boolean): Boolean
fun setBooleanPreference(key: String?, value: Boolean)
fun getStringPreference(key: String, defaultValue: String?): String?
fun setStringPreference(key: String?, value: String?)
fun getIntegerPreference(key: String, defaultValue: Int): Int
fun setIntegerPreference(key: String, value: Int)
fun setIntegerPreferenceBlocking(key: String, value: Int): Boolean
fun getLongPreference(key: String, defaultValue: Long): Long
fun setLongPreference(key: String, value: Long)
fun removePreference(key: String)
fun getStringSetPreference(key: String, defaultValues: Set<String>): Set<String>?
fun setStringSetPreference(key: String, value: Set<String>)
fun getLastOpenTimeDate(): Long
fun setLastOpenDate()
fun hasSeenLinkPreviewSuggestionDialog(): Boolean
fun setHasSeenLinkPreviewSuggestionDialog()
fun forceCurrentUserAsPro(): Boolean
fun setForceCurrentUserAsPro(isPro: Boolean)
fun forceOtherUsersAsPro(): Boolean
fun setForceOtherUsersAsPro(isPro: Boolean)
fun forceIncomingMessagesAsPro(): Boolean
fun setForceIncomingMessagesAsPro(isPro: Boolean)
fun forcePostPro(): Boolean
fun setForcePostPro(postPro: Boolean)
fun hasSeenProExpiring(): Boolean
fun setHasSeenProExpiring()
fun hasSeenProExpired(): Boolean
fun setHasSeenProExpired()
fun clearProExpiryView()
fun watchPostProStatus(): StateFlow<Boolean>
fun hasSeenSlowModeCallWarning(): Boolean
fun setHasSeenSlowModeCallWarning(value: Boolean)
fun setShownCallWarning(): Boolean
fun setShownCallNotification(): Boolean
fun setCallNotificationsEnabled(enabled : Boolean)
fun isCallNotificationsEnabled(): Boolean
fun getLastVacuum(): Long
fun setLastVacuumNow()
fun getFingerprintKeyGenerated(): Boolean
fun setFingerprintKeyGenerated()
fun getSelectedAccentColor(): String?
@StyleRes fun getAccentColorStyle(): Int?
fun setAccentColorStyle(@StyleRes newColorStyle: Int?)
fun getThemeStyle(): String
fun getFollowSystemSettings(): Boolean
fun setThemeStyle(themeStyle: String)
fun setFollowSystemSettings(followSystemSettings: Boolean)
fun setAutoplayAudioMessages(enabled : Boolean)
fun isAutoplayAudioMessagesEnabled(): Boolean
fun hasForcedNewConfig(): Boolean
fun hasPreference(key: String): Boolean
fun clearAll()
fun getHidePassword(): Boolean
fun setHidePassword(value: Boolean)
fun watchHidePassword(): StateFlow<Boolean>
fun getLastVersionCheck(): Long
fun setLastVersionCheck()
fun getEnvironment(): Environment
fun setEnvironment(value: Environment)
fun hasSeenTokenPageNotification(): Boolean
fun setHasSeenTokenPageNotification(value: Boolean)
fun forcedShortTTL(): Boolean
fun setForcedShortTTL(value: Boolean)
fun getDebugMessageFeatures(): Set<ProFeature>
fun setDebugMessageFeatures(features: Set<ProFeature>)
fun getDebugSubscriptionType(): DebugMenuViewModel.DebugSubscriptionStatus?
fun setDebugSubscriptionType(status: DebugMenuViewModel.DebugSubscriptionStatus?)
fun getDebugProPlanStatus(): DebugMenuViewModel.DebugProPlanStatus?
fun setDebugProPlanStatus(status: DebugMenuViewModel.DebugProPlanStatus?)
fun getDebugForceNoBilling(): Boolean
fun setDebugForceNoBilling(hasBilling: Boolean)
fun getDebugIsWithinQuickRefund(): Boolean
fun setDebugIsWithinQuickRefund(isWithin: Boolean)
fun setSubscriptionProvider(provider: String)
fun getSubscriptionProvider(): String?
fun hasDonated(): Boolean
fun setHasDonated(hasDonated: Boolean)
fun hasCopiedDonationURL(): Boolean
fun setHasCopiedDonationURL(hasCopied: Boolean)
fun seenDonationCTAAmount(): Int
fun setSeenDonationCTAAmount(amount: Int)
fun lastSeenDonationCTA(): Long
fun setLastSeenDonationCTA(timestamp: Long)
fun showDonationCTAFromPositiveReview(): Boolean
fun setShowDonationCTAFromPositiveReview(show: Boolean)
fun hasDonatedDebug(): String?
fun setHasDonatedDebug(hasDonated: String?)
fun hasCopiedDonationURLDebug(): String?
fun setHasCopiedDonationURLDebug(hasCopied: String?)
fun seenDonationCTAAmountDebug(): String?
fun setSeenDonationCTAAmountDebug(amount: String?)
fun showDonationCTAFromPositiveReviewDebug(): String?
fun setShowDonationCTAFromPositiveReviewDebug(show: String?)
fun getLastSnodePoolRefresh(): Long
fun setLastSnodePoolRefresh(epochMs: Long)
fun getLastPathRotation(): Long
fun setLastPathRotation(epochMs: Long)
fun setSendWithEnterEnabled(enabled: Boolean)
fun isSendWithEnterEnabled() : Boolean
fun updateBooleanFromKey(key : String, value : Boolean)
var deprecationStateOverride: String?
var deprecatedTimeOverride: ZonedDateTime?
var deprecatingStartTimeOverride: ZonedDateTime?
var migratedToGroupV2Config: Boolean
var migratedToDisablingKDF: Boolean
var selectedActivityAliasName: String?
var inAppReviewState: String?
var forcesDeterministicAttachmentEncryption: Boolean
var debugAvatarReupload: Boolean
var alternativeFileServer: FileServer?
companion object {
val TAG = TextSecurePreferences::class.simpleName
internal val _events = MutableSharedFlow<String>(0, 64, BufferOverflow.DROP_OLDEST)
val events get() = _events.asSharedFlow()
const val DISABLE_PASSPHRASE_PREF = "pref_disable_passphrase"
const val LANGUAGE_PREF = "pref_language"
const val LAST_VERSION_CODE_PREF = "last_version_code"
const val PASSPHRASE_TIMEOUT_INTERVAL_PREF = "pref_timeout_interval"
const val PASSPHRASE_TIMEOUT_PREF = "pref_timeout_passphrase"
const val THREAD_TRIM_ENABLED = "pref_trim_threads"
const val UPDATE_APK_REFRESH_TIME_PREF = "pref_update_apk_refresh_time"
const val UPDATE_APK_DOWNLOAD_ID = "pref_update_apk_download_id"
const val UPDATE_APK_DIGEST = "pref_update_apk_digest"
const val IN_THREAD_NOTIFICATION_PREF = "pref_key_inthread_notifications"
const val MESSAGE_BODY_TEXT_SIZE_PREF = "pref_message_body_text_size"
@Deprecated("No longer used, kept for migration purposes")
const val REPEAT_ALERTS_PREF = "pref_repeat_alerts"
const val DIRECT_CAPTURE_CAMERA_ID = "pref_direct_capture_camera_id"
const val INCOGNITO_KEYBOARD_PREF = "pref_incognito_keyboard"
const val NEEDS_SQLCIPHER_MIGRATION = "pref_needs_sql_cipher_migration"
const val BACKUP_ENABLED = "pref_backup_enabled_v3"
const val BACKUP_PASSPHRASE = "pref_backup_passphrase"
const val ENCRYPTED_BACKUP_PASSPHRASE = "pref_encrypted_backup_passphrase"
const val BACKUP_TIME = "pref_backup_next_time"
const val BACKUP_SAVE_DIR = "pref_save_dir"
const val SCREEN_LOCK = "pref_android_screen_lock"
const val SCREEN_LOCK_TIMEOUT = "pref_android_screen_lock_timeout"
const val UNIVERSAL_UNIDENTIFIED_ACCESS = "pref_universal_unidentified_access"
const val TYPING_INDICATORS = "pref_typing_indicators"
const val LINK_PREVIEWS = "pref_link_previews"
const val GIF_METADATA_WARNING = "has_seen_gif_metadata_warning"
const val GIF_GRID_LAYOUT = "pref_gif_grid_layout"
const val CONFIGURATION_SYNCED = "pref_configuration_synced"
const val PROFILE_PIC_EXPIRY = "profile_pic_expiry"
const val LAST_OPEN_DATE = "pref_last_open_date"
const val SET_FORCE_CURRENT_USER_PRO = "pref_force_current_user_pro"
const val SET_FORCE_OTHER_USERS_PRO = "pref_force_other_users_pro"
const val SET_FORCE_INCOMING_MESSAGE_PRO = "pref_force_incoming_message_pro"
const val SET_FORCE_POST_PRO = "pref_force_post_pro"
const val HAS_SEEN_PRO_EXPIRING = "has_seen_pro_expiring"
const val HAS_SEEN_PRO_EXPIRED = "has_seen_pro_expired"
const val SHOWN_SLOW_MODE_CALL_WARNING = "has_seen_slow_mode_call_warning"
const val CALL_NOTIFICATIONS_ENABLED = "pref_call_notifications_enabled"
const val SHOWN_CALL_WARNING = "pref_shown_call_warning" // call warning is user-facing warning of enabling calls
const val SHOWN_CALL_NOTIFICATION = "pref_shown_call_notification" // call notification is a prompt to check privacy settings
const val LAST_VACUUM_TIME = "pref_last_vacuum_time"
const val AUTOPLAY_AUDIO_MESSAGES = "pref_autoplay_audio"
const val SEND_WITH_ENTER = "pref_enter_sends"
const val FINGERPRINT_KEY_GENERATED = "fingerprint_key_generated"
const val SELECTED_ACCENT_COLOR = "selected_accent_color"
const val LAST_VERSION_CHECK = "pref_last_version_check"
const val ENVIRONMENT = "debug_environment"
const val MIGRATED_TO_GROUP_V2_CONFIG = "migrated_to_group_v2_config"
const val MIGRATED_TO_DISABLING_KDF = "migrated_to_disabling_kdf"
const val HAS_RECEIVED_LEGACY_CONFIG = "has_received_legacy_config"
const val HAS_FORCED_NEW_CONFIG = "has_forced_new_config"
const val GREEN_ACCENT = "accent_green"
const val BLUE_ACCENT = "accent_blue"
const val PURPLE_ACCENT = "accent_purple"
const val PINK_ACCENT = "accent_pink"
const val RED_ACCENT = "accent_red"
const val ORANGE_ACCENT = "accent_orange"
const val YELLOW_ACCENT = "accent_yellow"
const val SELECTED_STYLE = "pref_selected_style" // classic_dark/light, ocean_dark/light
const val FOLLOW_SYSTEM_SETTINGS = "pref_follow_system" // follow system day/night
const val HIDE_PASSWORD = "pref_hide_password"
const val LEGACY_PREF_KEY_SELECTED_UI_MODE = "SELECTED_UI_MODE" // this will be cleared upon launching app, for users migrating to theming build
const val CLASSIC_DARK = "classic.dark"
const val CLASSIC_LIGHT = "classic.light"
const val OCEAN_DARK = "ocean.dark"
const val OCEAN_LIGHT = "ocean.light"
const val ALLOW_MESSAGE_REQUESTS = "libsession.ALLOW_MESSAGE_REQUESTS"
const val DEPRECATED_STATE_OVERRIDE = "deprecation_state_override"
const val DEPRECATED_TIME_OVERRIDE = "deprecated_time_override"
const val DEPRECATING_START_TIME_OVERRIDE = "deprecating_start_time_override"
// Key name for if we've warned the user that saving attachments will allow other apps to access them.
// Note: We only ever display this once - and when the user has accepted the warning we never show it again
// for the lifetime of the Session installation.
const val HAVE_WARNED_USER_ABOUT_SAVING_ATTACHMENTS = "libsession.HAVE_WARNED_USER_ABOUT_SAVING_ATTACHMENTS"
// As we will have an incoming push notification to inform the user about the new token page, but we
// will also schedule instigating a local notification, we need to keep track of whether ANY notification
// has been shown to the user, and if so we don't show another.
const val HAVE_SHOWN_A_NOTIFICATION_ABOUT_TOKEN_PAGE = "pref_shown_a_notification_about_token_page"
// Key name for the user's preferred date format string
const val DATE_FORMAT_PREF = "libsession.DATE_FORMAT_PREF"
// Key name for the user's preferred time format string
const val TIME_FORMAT_PREF = "libsession.TIME_FORMAT_PREF"
const val FORCED_SHORT_TTL = "forced_short_ttl"
const val IN_APP_REVIEW_STATE = "in_app_review_state"
const val DEBUG_PRO_MESSAGE_FEATURES = "debug_pro_message_features"
const val DEBUG_PRO_PROFILE_FEATURES = "debug_pro_profile_features"
const val DEBUG_SUBSCRIPTION_STATUS = "debug_subscription_status"
const val DEBUG_PRO_PLAN_STATUS = "debug_pro_plan_status"
const val DEBUG_FORCE_NO_BILLING = "debug_pro_has_billing"
const val DEBUG_WITHIN_QUICK_REFUND = "debug_within_quick_refund"
const val SUBSCRIPTION_PROVIDER = "session_subscription_provider"
const val DEBUG_AVATAR_REUPLOAD = "debug_avatar_reupload"
// Donation
const val HAS_DONATED = "has_donated_v3"
const val HAS_COPIED_DONATION_URL = "has_copied_donation_url_v3"
const val SEEN_DONATION_CTA_AMOUNT = "seen_donation_cta_amount_v3"
const val LAST_SEEN_DONATION_CTA = "last_seen_donation_cta_v3"
const val SHOW_DONATION_CTA_FROM_POSITIVE_REVIEW = "show_donation_cta_from_positive_review_v3"
const val DEBUG_HAS_DONATED = "debug_has_donated"
const val DEBUG_HAS_COPIED_DONATION_URL = "debug_has_copied_donation_url"
const val DEBUG_SEEN_DONATION_CTA_AMOUNT = "debug_seen_donation_cta_amount"
const val DEBUG_SHOW_DONATION_CTA_FROM_POSITIVE_REVIEW = "debug_show_donation_cta_from_positive_review"
const val LAST_SNODE_POOL_REFRESH = "last_snode_pool_refresh"
const val LAST_PATH_ROTATION = "last_path_rotation"
// endregion
@JvmStatic
fun isScreenLockEnabled(context: Context): Boolean {
return getBooleanPreference(context, SCREEN_LOCK, false)
}
@JvmStatic
fun setScreenLockEnabled(context: Context, value: Boolean) {
setBooleanPreference(context, SCREEN_LOCK, value)
}
@JvmStatic
fun getScreenLockTimeout(context: Context): Long {
return getLongPreference(context, SCREEN_LOCK_TIMEOUT, 0)
}
@JvmStatic
fun setScreenLockTimeout(context: Context, value: Long) {
setLongPreference(context, SCREEN_LOCK_TIMEOUT, value)
}
@JvmStatic
fun isIncognitoKeyboardEnabled(context: Context): Boolean {
return getBooleanPreference(context, INCOGNITO_KEYBOARD_PREF, true)
}
@JvmStatic
fun isGifSearchInGridLayout(context: Context): Boolean {
return getBooleanPreference(context, GIF_GRID_LAYOUT, false)
}
@JvmStatic
fun setIsGifSearchInGridLayout(context: Context, isGrid: Boolean) {
setBooleanPreference(context, GIF_GRID_LAYOUT, isGrid)
}
@JvmStatic
fun isPasswordDisabled(context: Context): Boolean {
return getBooleanPreference(context, DISABLE_PASSPHRASE_PREF, true)
}
fun setPasswordDisabled(context: Context, disabled: Boolean) {
setBooleanPreference(context, DISABLE_PASSPHRASE_PREF, disabled)
_events.tryEmit(DISABLE_PASSPHRASE_PREF)
}
fun getLastVersionCode(context: Context): Int {
return getIntegerPreference(context, LAST_VERSION_CODE_PREF, 0)
}
@Throws(IOException::class)
fun setLastVersionCode(context: Context, versionCode: Int) {
if (!setIntegerPreferenceBlocking(context, LAST_VERSION_CODE_PREF, versionCode)) {
throw IOException("couldn't write version code to sharedpreferences")
}
}
@JvmStatic
fun isPassphraseTimeoutEnabled(context: Context): Boolean {
return getBooleanPreference(context, PASSPHRASE_TIMEOUT_PREF, false)
}
@JvmStatic
fun getPassphraseTimeoutInterval(context: Context): Int {
return getIntegerPreference(context, PASSPHRASE_TIMEOUT_INTERVAL_PREF, 5 * 60)
}
@JvmStatic
fun isThreadLengthTrimmingEnabled(context: Context): Boolean {
return getBooleanPreference(context, THREAD_TRIM_ENABLED, true)
}
@JvmStatic
fun getBooleanPreference(context: Context, key: String?, defaultValue: Boolean): Boolean {
return getDefaultSharedPreferences(context).getBoolean(key, defaultValue)
}
@JvmStatic
fun setBooleanPreference(context: Context, key: String?, value: Boolean) {
getDefaultSharedPreferences(context).edit().putBoolean(key, value).apply()
}
@JvmStatic
fun getStringPreference(context: Context, key: String, defaultValue: String?): String? {
return getDefaultSharedPreferences(context).getString(key, defaultValue)
}
@JvmStatic
fun setStringPreference(context: Context, key: String?, value: String?) {
getDefaultSharedPreferences(context).edit().putString(key, value).apply()
}
fun getIntegerPreference(context: Context, key: String, defaultValue: Int): Int {
return getDefaultSharedPreferences(context).getInt(key, defaultValue)
}
private fun setIntegerPreference(context: Context, key: String, value: Int) {
getDefaultSharedPreferences(context).edit().putInt(key, value).apply()
}
private fun setIntegerPreferenceBlocking(context: Context, key: String, value: Int): Boolean {
return getDefaultSharedPreferences(context).edit().putInt(key, value).commit()
}
private fun getLongPreference(context: Context, key: String, defaultValue: Long): Long {
return getDefaultSharedPreferences(context).getLong(key, defaultValue)
}
private fun setLongPreference(context: Context, key: String, value: Long) {
getDefaultSharedPreferences(context).edit().putLong(key, value).apply()
}
private fun removePreference(context: Context, key: String) {
getDefaultSharedPreferences(context).edit().remove(key).apply()
}
private fun getStringSetPreference(context: Context, key: String, defaultValues: Set<String>): Set<String>? {
val prefs = getDefaultSharedPreferences(context)
return if (prefs.contains(key)) {
prefs.getStringSet(key, emptySet())
} else {
defaultValues
}
}
@Deprecated("We no longer keep the profile expiry in prefs, we write them in the file instead. Keeping it here for migration purposes")
@JvmStatic
fun getProfileExpiry(context: Context): Long{
return getLongPreference(context, PROFILE_PIC_EXPIRY, 0)
}
@JvmStatic
fun isCallNotificationsEnabled(context: Context): Boolean {
return getBooleanPreference(context, CALL_NOTIFICATIONS_ENABLED, false)
}
@JvmStatic
fun getLastVacuumTime(context: Context): Long {
return getLongPreference(context, LAST_VACUUM_TIME, 0)
}
@JvmStatic
fun setLastVacuumNow(context: Context) {
setLongPreference(context, LAST_VACUUM_TIME, System.currentTimeMillis())
}
@JvmStatic
fun getFingerprintKeyGenerated(context: Context): Boolean {
return getBooleanPreference(context, FINGERPRINT_KEY_GENERATED, false)
}
@JvmStatic
fun setFingerprintKeyGenerated(context: Context) {
setBooleanPreference(context, FINGERPRINT_KEY_GENERATED, true)
}
// ----- Get / set methods for if we have already warned the user that saving attachments will allow other apps to access them -----
// Note: We only ever show the warning dialog about this ONCE - when the user accepts this fact we write true to the flag & never show again.
@JvmStatic
fun getHaveWarnedUserAboutSavingAttachments(context: Context): Boolean {
return getBooleanPreference(context, HAVE_WARNED_USER_ABOUT_SAVING_ATTACHMENTS, false)
}
@JvmStatic
fun setHaveWarnedUserAboutSavingAttachments(context: Context) {
setBooleanPreference(context, HAVE_WARNED_USER_ABOUT_SAVING_ATTACHMENTS, true)
}
}
}
@Singleton
class AppTextSecurePreferences @Inject constructor(
@param:ApplicationContext private val context: Context,
private val json: Json,
): TextSecurePreferences {
private val postProLaunchState = MutableStateFlow(getBooleanPreference(SET_FORCE_POST_PRO, if (BuildConfig.BUILD_TYPE != "release") true else false))
private val hiddenPasswordState = MutableStateFlow(getBooleanPreference(HIDE_PASSWORD, false))
override var migratedToGroupV2Config: Boolean
get() = getBooleanPreference(TextSecurePreferences.MIGRATED_TO_GROUP_V2_CONFIG, false)
set(value) = setBooleanPreference(TextSecurePreferences.MIGRATED_TO_GROUP_V2_CONFIG, value)
override var migratedToDisablingKDF: Boolean
get() = getBooleanPreference(TextSecurePreferences.MIGRATED_TO_DISABLING_KDF, false)
set(value) = getDefaultSharedPreferences(context).edit(commit = true) {
putBoolean(TextSecurePreferences.MIGRATED_TO_DISABLING_KDF, value)
}
override fun getConfigurationMessageSynced(): Boolean {
return getBooleanPreference(TextSecurePreferences.CONFIGURATION_SYNCED, false)
}
override var selectedActivityAliasName: String?
get() = getStringPreference("selected_activity_alias_name", null)
set(value) {
setStringPreference("selected_activity_alias_name", value)
}
override fun setConfigurationMessageSynced(value: Boolean) {
setBooleanPreference(TextSecurePreferences.CONFIGURATION_SYNCED, value)
_events.tryEmit(TextSecurePreferences.CONFIGURATION_SYNCED)
}
override fun isScreenLockEnabled(): Boolean {
return getBooleanPreference(TextSecurePreferences.SCREEN_LOCK, false)
}
override fun setScreenLockEnabled(value: Boolean) {
setBooleanPreference(TextSecurePreferences.SCREEN_LOCK, value)
_events.tryEmit(TextSecurePreferences.SCREEN_LOCK,)
}
override fun getScreenLockTimeout(): Long {
return getLongPreference(TextSecurePreferences.SCREEN_LOCK_TIMEOUT, 0)
}
override fun setScreenLockTimeout(value: Long) {
setLongPreference(TextSecurePreferences.SCREEN_LOCK_TIMEOUT, value)
}
override fun setBackupPassphrase(passphrase: String?) {
setStringPreference(TextSecurePreferences.BACKUP_PASSPHRASE, passphrase)
}
override fun getBackupPassphrase(): String? {
return getStringPreference(TextSecurePreferences.BACKUP_PASSPHRASE, null)
}
override fun setEncryptedBackupPassphrase(encryptedPassphrase: String?) {
setStringPreference(TextSecurePreferences.ENCRYPTED_BACKUP_PASSPHRASE, encryptedPassphrase)
}
override fun getEncryptedBackupPassphrase(): String? {
return getStringPreference(TextSecurePreferences.ENCRYPTED_BACKUP_PASSPHRASE, null)
}
override fun setBackupEnabled(value: Boolean) {
setBooleanPreference(TextSecurePreferences.BACKUP_ENABLED, value)
}
override fun isBackupEnabled(): Boolean {
return getBooleanPreference(TextSecurePreferences.BACKUP_ENABLED, false)
}
override fun setNextBackupTime(time: Long) {
setLongPreference(TextSecurePreferences.BACKUP_TIME, time)
}
override fun getNextBackupTime(): Long {
return getLongPreference(TextSecurePreferences.BACKUP_TIME, -1)
}
override fun setBackupSaveDir(dirUri: String?) {
setStringPreference(TextSecurePreferences.BACKUP_SAVE_DIR, dirUri)
}
override fun getBackupSaveDir(): String? {
return getStringPreference(TextSecurePreferences.BACKUP_SAVE_DIR, null)
}
override fun getNeedsSqlCipherMigration(): Boolean {
return getBooleanPreference(TextSecurePreferences.NEEDS_SQLCIPHER_MIGRATION, false)
}
override fun isIncognitoKeyboardEnabled(): Boolean {
return getBooleanPreference(TextSecurePreferences.INCOGNITO_KEYBOARD_PREF, true)
}
override fun setIncognitoKeyboardEnabled(enabled: Boolean) {
setBooleanPreference(TextSecurePreferences.INCOGNITO_KEYBOARD_PREF, enabled)
_events.tryEmit(TextSecurePreferences.INCOGNITO_KEYBOARD_PREF)
}
override fun isTypingIndicatorsEnabled(): Boolean {
return getBooleanPreference(TextSecurePreferences.TYPING_INDICATORS, false)
}
override fun setTypingIndicatorsEnabled(enabled: Boolean) {
setBooleanPreference(TextSecurePreferences.TYPING_INDICATORS, enabled)
_events.tryEmit(TextSecurePreferences.TYPING_INDICATORS)
}
override fun isLinkPreviewsEnabled(): Boolean {
return getBooleanPreference(TextSecurePreferences.LINK_PREVIEWS, false)
}
override fun setLinkPreviewsEnabled(enabled: Boolean) {
setBooleanPreference(TextSecurePreferences.LINK_PREVIEWS, enabled)
_events.tryEmit(TextSecurePreferences.LINK_PREVIEWS)
}
override fun hasSeenGIFMetaDataWarning(): Boolean {
return getBooleanPreference(TextSecurePreferences.GIF_METADATA_WARNING, false)
}
override fun setHasSeenGIFMetaDataWarning() {
setBooleanPreference(TextSecurePreferences.GIF_METADATA_WARNING, true)
}
override fun isGifSearchInGridLayout(): Boolean {
return getBooleanPreference(TextSecurePreferences.GIF_GRID_LAYOUT, false)
}
override fun setIsGifSearchInGridLayout(isGrid: Boolean) {
setBooleanPreference(TextSecurePreferences.GIF_GRID_LAYOUT, isGrid)
}
override fun getMessageBodyTextSize(): Int {
return getStringPreference(TextSecurePreferences.MESSAGE_BODY_TEXT_SIZE_PREF, "16")!!.toInt()
}
override fun setPreferredCameraDirection(value: CameraSelector) {
setIntegerPreference(TextSecurePreferences.DIRECT_CAPTURE_CAMERA_ID,
when(value){
CameraSelector.DEFAULT_FRONT_CAMERA -> Camera.CameraInfo.CAMERA_FACING_FRONT
else -> Camera.CameraInfo.CAMERA_FACING_BACK
})
}
override fun getPreferredCameraDirection(): CameraSelector {
return when(getIntegerPreference(TextSecurePreferences.DIRECT_CAPTURE_CAMERA_ID, Camera.CameraInfo.CAMERA_FACING_BACK)){
Camera.CameraInfo.CAMERA_FACING_FRONT -> CameraSelector.DEFAULT_FRONT_CAMERA
else -> CameraSelector.DEFAULT_BACK_CAMERA
}
}
override fun getRepeatAlertsCount(): Int {
return try {
getStringPreference(TextSecurePreferences.REPEAT_ALERTS_PREF, "0")!!.toInt()
} catch (e: NumberFormatException) {
Log.w(TextSecurePreferences.TAG, e)
0
}
}
override fun isInThreadNotifications(): Boolean {
return getBooleanPreference(TextSecurePreferences.IN_THREAD_NOTIFICATION_PREF, true)
}
override fun isUniversalUnidentifiedAccess(): Boolean {
return getBooleanPreference(TextSecurePreferences.UNIVERSAL_UNIDENTIFIED_ACCESS, false)
}
override fun getUpdateApkRefreshTime(): Long {
return getLongPreference(TextSecurePreferences.UPDATE_APK_REFRESH_TIME_PREF, 0L)
}
override fun setUpdateApkRefreshTime(value: Long) {
setLongPreference(TextSecurePreferences.UPDATE_APK_REFRESH_TIME_PREF, value)
}
override fun setUpdateApkDownloadId(value: Long) {
setLongPreference(TextSecurePreferences.UPDATE_APK_DOWNLOAD_ID, value)
}
override fun getUpdateApkDownloadId(): Long {
return getLongPreference(TextSecurePreferences.UPDATE_APK_DOWNLOAD_ID, -1)
}
override fun setUpdateApkDigest(value: String?) {
setStringPreference(TextSecurePreferences.UPDATE_APK_DIGEST, value)
}
override fun getUpdateApkDigest(): String? {
return getStringPreference(TextSecurePreferences.UPDATE_APK_DIGEST, null)
}
override fun getHasLegacyConfig(): Boolean {
return getBooleanPreference(TextSecurePreferences.HAS_RECEIVED_LEGACY_CONFIG, false)
}
override fun setHasLegacyConfig(newValue: Boolean) {
setBooleanPreference(TextSecurePreferences.HAS_RECEIVED_LEGACY_CONFIG, newValue)
_events.tryEmit(TextSecurePreferences.HAS_RECEIVED_LEGACY_CONFIG)
}
override fun isPasswordDisabled(): Boolean {
return getBooleanPreference(TextSecurePreferences.DISABLE_PASSPHRASE_PREF, true)
}
override fun setPasswordDisabled(disabled: Boolean) {
setBooleanPreference(TextSecurePreferences.DISABLE_PASSPHRASE_PREF, disabled)
}
override fun getLastVersionCode(): Int {
return getIntegerPreference(TextSecurePreferences.LAST_VERSION_CODE_PREF, 0)
}
@Throws(IOException::class)
override fun setLastVersionCode(versionCode: Int) {
if (!setIntegerPreferenceBlocking(TextSecurePreferences.LAST_VERSION_CODE_PREF, versionCode)) {
throw IOException("couldn't write version code to sharedpreferences")
}
}
override fun isPassphraseTimeoutEnabled(): Boolean {
return getBooleanPreference(TextSecurePreferences.PASSPHRASE_TIMEOUT_PREF, false)
}
override fun getPassphraseTimeoutInterval(): Int {
return getIntegerPreference(TextSecurePreferences.PASSPHRASE_TIMEOUT_INTERVAL_PREF, 5 * 60)
}
override fun getLanguage(): String? {
return getStringPreference(TextSecurePreferences.LANGUAGE_PREF, "zz")
}
override fun setThreadLengthTrimmingEnabled(enabled: Boolean) {
setBooleanPreference(TextSecurePreferences.THREAD_TRIM_ENABLED, enabled)
_events.tryEmit(TextSecurePreferences.THREAD_TRIM_ENABLED)
}
override fun isThreadLengthTrimmingEnabled(): Boolean {
return getBooleanPreference(TextSecurePreferences.THREAD_TRIM_ENABLED, true)
}
override fun hasForcedNewConfig(): Boolean =
getBooleanPreference(TextSecurePreferences.HAS_FORCED_NEW_CONFIG, false)
override fun getBooleanPreference(key: String?, defaultValue: Boolean): Boolean {
return getDefaultSharedPreferences(context).getBoolean(key, defaultValue)
}
override fun setBooleanPreference(key: String?, value: Boolean) {
getDefaultSharedPreferences(context).edit().putBoolean(key, value).apply()
}
override fun getStringPreference(key: String, defaultValue: String?): String? {
return getDefaultSharedPreferences(context).getString(key, defaultValue)
}
override fun setStringPreference(key: String?, value: String?) {
getDefaultSharedPreferences(context).edit().putString(key, value).apply()
}
override fun getIntegerPreference(key: String, defaultValue: Int): Int {
return getDefaultSharedPreferences(context).getInt(key, defaultValue)
}
override fun setIntegerPreference(key: String, value: Int) {
getDefaultSharedPreferences(context).edit().putInt(key, value).apply()
}
override fun setIntegerPreferenceBlocking(key: String, value: Int): Boolean {
return getDefaultSharedPreferences(context).edit().putInt(key, value).commit()
}
override fun getLongPreference(key: String, defaultValue: Long): Long {
return getDefaultSharedPreferences(context).getLong(key, defaultValue)
}
override fun setLongPreference(key: String, value: Long) {
getDefaultSharedPreferences(context).edit().putLong(key, value).apply()
}
override fun hasPreference(key: String): Boolean {
return getDefaultSharedPreferences(context).contains(key)
}
override fun removePreference(key: String) {
getDefaultSharedPreferences(context).edit().remove(key).apply()
}
override fun getStringSetPreference(key: String, defaultValues: Set<String>): Set<String>? {
val prefs = getDefaultSharedPreferences(context)
return if (prefs.contains(key)) {
prefs.getStringSet(key, emptySet())
} else {
defaultValues
}
}
override fun setStringSetPreference(key: String, value: Set<String>) {
getDefaultSharedPreferences(context).edit { putStringSet(key, value) }
}
override fun getLastSnodePoolRefresh(): Long {
return getLongPreference(LAST_SNODE_POOL_REFRESH, 0)
}
override fun setLastSnodePoolRefresh(epochMs: Long) {
setLongPreference(LAST_SNODE_POOL_REFRESH, epochMs)
}
override fun getLastPathRotation(): Long {
return getLongPreference(LAST_PATH_ROTATION, 0)
}
override fun setLastPathRotation(epochMs: Long) {
setLongPreference(LAST_PATH_ROTATION, epochMs)
}
override fun getLastOpenTimeDate(): Long {
return getLongPreference(TextSecurePreferences.LAST_OPEN_DATE, 0)
}
override fun setLastOpenDate() {
setLongPreference(TextSecurePreferences.LAST_OPEN_DATE, System.currentTimeMillis())
}
override fun hasSeenLinkPreviewSuggestionDialog(): Boolean {
return getBooleanPreference("has_seen_link_preview_suggestion_dialog", false)
}
override fun setHasSeenLinkPreviewSuggestionDialog() {
setBooleanPreference("has_seen_link_preview_suggestion_dialog", true)
}
override fun setCallNotificationsEnabled(enabled: Boolean) {
setBooleanPreference(CALL_NOTIFICATIONS_ENABLED, enabled)
_events.tryEmit(CALL_NOTIFICATIONS_ENABLED)
}
override fun isCallNotificationsEnabled(): Boolean {
return getBooleanPreference(CALL_NOTIFICATIONS_ENABLED, false)
}
override fun hasSeenSlowModeCallWarning(): Boolean {
return getBooleanPreference(TextSecurePreferences.SHOWN_SLOW_MODE_CALL_WARNING, false)
}
override fun setHasSeenSlowModeCallWarning(value: Boolean) {
setBooleanPreference(TextSecurePreferences.SHOWN_SLOW_MODE_CALL_WARNING, value)
}
override fun getLastVacuum(): Long {
return getLongPreference(LAST_VACUUM_TIME, 0)
}
override fun setLastVacuumNow() {
setLongPreference(LAST_VACUUM_TIME, System.currentTimeMillis())
}
override fun getLastVersionCheck(): Long {
return getLongPreference(LAST_VERSION_CHECK, 0)
}
override fun setLastVersionCheck() {
setLongPreference(LAST_VERSION_CHECK, System.currentTimeMillis())
}
override fun getEnvironment(): Environment {
val environment = getStringPreference(ENVIRONMENT, null)
return if (environment != null) {
Environment.valueOf(environment)
} else BuildConfig.DEFAULT_ENVIRONMENT
}
override fun setEnvironment(value: Environment) {
setStringPreference(ENVIRONMENT, value.name)
}
override fun setShownCallNotification(): Boolean {
val previousValue = getBooleanPreference(SHOWN_CALL_NOTIFICATION, false)
if (previousValue) return false
val setValue = true
setBooleanPreference(SHOWN_CALL_NOTIFICATION, setValue)
return previousValue != setValue
}
/**
* Set the SHOWN_CALL_WARNING preference to `true`
* Return `true` if the value did update (it was previously unset)
*/
override fun setShownCallWarning() : Boolean {
val previousValue = getBooleanPreference(SHOWN_CALL_WARNING, false)
if (previousValue) {
return false
}
val setValue = true
setBooleanPreference(SHOWN_CALL_WARNING, setValue)
return previousValue != setValue
}
override fun forceCurrentUserAsPro(): Boolean {
return getBooleanPreference(SET_FORCE_CURRENT_USER_PRO, false)
}
override fun setForceCurrentUserAsPro(isPro: Boolean) {
setBooleanPreference(SET_FORCE_CURRENT_USER_PRO, isPro)
_events.tryEmit(SET_FORCE_CURRENT_USER_PRO)
}
override fun forceOtherUsersAsPro(): Boolean {
return getBooleanPreference(SET_FORCE_OTHER_USERS_PRO, false)
}
override fun setForceOtherUsersAsPro(isPro: Boolean) {
setBooleanPreference(SET_FORCE_OTHER_USERS_PRO, isPro)
_events.tryEmit(SET_FORCE_OTHER_USERS_PRO)
}
override fun forceIncomingMessagesAsPro(): Boolean {
return getBooleanPreference(SET_FORCE_INCOMING_MESSAGE_PRO, false)
}
override fun setForceIncomingMessagesAsPro(isPro: Boolean) {
setBooleanPreference(SET_FORCE_INCOMING_MESSAGE_PRO, isPro)
}
override fun forcePostPro(): Boolean {
return postProLaunchState.value
}
override fun setForcePostPro(postPro: Boolean) {
setBooleanPreference(SET_FORCE_POST_PRO, postPro)
postProLaunchState.update { postPro }
_events.tryEmit(SET_FORCE_POST_PRO)
}
override fun hasSeenProExpiring(): Boolean {
return getBooleanPreference(HAS_SEEN_PRO_EXPIRING, false)
}
override fun setHasSeenProExpiring() {
setBooleanPreference(HAS_SEEN_PRO_EXPIRING, true)
}