Skip to content

Commit 5a64e17

Browse files
backups: Pull the latest backups proto in and update the tests
1 parent db7d35e commit 5a64e17

28 files changed

+266
-39
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
v0.86.4
22

3+
backups: Support latest backup.proto definitions

rust/message-backup/benches/generation/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,17 @@ pub fn generate_frames(
102102
hasCompletedUsernameOnboarding: true,
103103
phoneNumberSharingMode: proto::account_data::PhoneNumberSharingMode::EVERYBODY.into(),
104104
defaultSentMediaQuality: proto::account_data::SentMediaQuality::STANDARD.into(),
105+
appTheme: proto::account_data::AppTheme::SYSTEM.into(),
106+
callsUseLessDataSetting: proto::account_data::CallsUseLessDataSetting::MOBILE_DATA_ONLY
107+
.into(),
108+
..Default::default()
109+
})
110+
.into(),
111+
androidSpecificSettings: Some(proto::account_data::AndroidSpecificSettings {
112+
useSystemEmoji: true,
113+
screenshotSecurity: true,
114+
navigationBarSize:
115+
proto::account_data::android_specific_settings::NavigationBarSize::COMPACT.into(),
105116
..Default::default()
106117
})
107118
.into(),

rust/message-backup/src/backup/account_data.rs

Lines changed: 84 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ pub enum IapSubscriptionId {
112112
M::Value<SentMediaQuality>: PartialEq,
113113
M::Value<Option<AutoDownloadSettings>>: PartialEq,
114114
M::Value<Option<Duration>>: PartialEq,
115+
M::Value<AppTheme>: PartialEq,
116+
M::Value<CallsUseLessDataSetting>: PartialEq,
115117
))]
116118
pub struct AccountSettings<M: Method + ReferencedTypes> {
117119
pub phone_number_sharing: M::Value<PhoneSharing>,
@@ -135,11 +137,12 @@ pub struct AccountSettings<M: Method + ReferencedTypes> {
135137
pub custom_chat_colors: CustomColorMap<M>,
136138
pub optimize_on_device_storage: M::Value<bool>,
137139
pub backup_level: M::Value<Option<BackupLevel>>,
138-
pub show_sealed_sender_indicators: M::Value<bool>,
139140
pub default_sent_media_quality: M::Value<SentMediaQuality>,
140141
pub auto_download_settings: M::Value<Option<AutoDownloadSettings>>,
141142
pub screen_lock_timeout: M::Value<Option<Duration>>,
142143
pub pin_reminders: M::Value<Option<bool>>,
144+
pub app_theme: M::Value<AppTheme>,
145+
pub calls_use_less_data_setting: M::Value<CallsUseLessDataSetting>,
143146
}
144147

145148
#[derive(Copy, Clone, Debug, PartialEq, serde::Serialize)]
@@ -154,11 +157,18 @@ pub enum SentMediaQuality {
154157
High,
155158
}
156159

160+
#[derive(Copy, Clone, Debug, PartialEq, serde::Serialize)]
161+
pub enum NavigationBarSize {
162+
Normal,
163+
Compact,
164+
}
165+
157166
#[derive(Debug, serde::Serialize)]
158167
#[cfg_attr(test, derive(PartialEq))]
159168
pub struct AndroidSpecificSettings {
160169
pub use_system_emoji: bool,
161170
pub screenshot_security: bool,
171+
pub navigation_bar_size: NavigationBarSize,
162172
}
163173

164174
#[derive(Copy, Clone, Debug, PartialEq, serde::Serialize)]
@@ -178,6 +188,20 @@ pub struct AutoDownloadSettings {
178188
pub documents: AutoDownloadOption,
179189
}
180190

191+
#[derive(Copy, Clone, Debug, PartialEq, serde::Serialize)]
192+
pub enum AppTheme {
193+
System,
194+
Light,
195+
Dark,
196+
}
197+
198+
#[derive(Copy, Clone, Debug, PartialEq, serde::Serialize)]
199+
pub enum CallsUseLessDataSetting {
200+
Never,
201+
MobileDataOnly,
202+
WifiAndMobileData,
203+
}
204+
181205
#[derive(Debug, displaydoc::Display, thiserror::Error)]
182206
#[cfg_attr(test, derive(PartialEq))]
183207
pub enum AccountDataError {
@@ -211,6 +235,12 @@ pub enum AccountDataError {
211235
UnknownSentMediaQuality,
212236
/// auto download option is UNKNOWN
213237
UnknownAutoDownloadOption,
238+
/// navigation bar size in Android specific settings is UNKNOWN
239+
UnknownAndroidNavigationBarSize,
240+
/// app theme is UNKNOWN
241+
UnknownAppTheme,
242+
/// calls use less data setting is UNKNOWN
243+
UnknownCallsUseLessDataSetting,
214244
}
215245

216246
#[derive(Debug, displaydoc::Display, thiserror::Error)]
@@ -278,7 +308,8 @@ impl<M: Method + ReferencedTypes, C: ReportUnusualTimestamp> TryIntoWith<Account
278308

279309
let android_specific_settings = androidSpecificSettings
280310
.into_option()
281-
.map(AndroidSpecificSettings::from);
311+
.map(AndroidSpecificSettings::try_from)
312+
.transpose()?;
282313

283314
Ok(AccountData {
284315
profile_key: M::value(profile_key),
@@ -426,11 +457,12 @@ impl<M: Method + ReferencedTypes, C: ReportUnusualTimestamp> TryIntoWith<Account
426457
customChatColors,
427458
optimizeOnDeviceStorage,
428459
backupTier,
429-
showSealedSenderIndicators,
430460
defaultSentMediaQuality,
431461
autoDownloadSettings,
432462
screenLockTimeoutMinutes,
433463
pinReminders,
464+
appTheme,
465+
callsUseLessDataSetting,
434466
special_fields: _,
435467
} = self;
436468

@@ -482,6 +514,26 @@ impl<M: Method + ReferencedTypes, C: ReportUnusualTimestamp> TryIntoWith<Account
482514
let screen_lock_timeout =
483515
screenLockTimeoutMinutes.map(|mins| Duration::from_mins(mins as u64));
484516

517+
use proto::account_data::AppTheme as AppThemeProto;
518+
let app_theme = match appTheme.enum_value_or_default() {
519+
AppThemeProto::UNKNOWN_APP_THEME => {
520+
return Err(AccountDataError::UnknownAppTheme);
521+
}
522+
AppThemeProto::SYSTEM => AppTheme::System,
523+
AppThemeProto::LIGHT => AppTheme::Light,
524+
AppThemeProto::DARK => AppTheme::Dark,
525+
};
526+
527+
use proto::account_data::CallsUseLessDataSetting as CallDataProto;
528+
let calls_use_less_data_setting = match callsUseLessDataSetting.enum_value_or_default() {
529+
CallDataProto::UNKNOWN_CALL_DATA_SETTING => {
530+
return Err(AccountDataError::UnknownCallsUseLessDataSetting);
531+
}
532+
CallDataProto::NEVER => CallsUseLessDataSetting::Never,
533+
CallDataProto::MOBILE_DATA_ONLY => CallsUseLessDataSetting::MobileDataOnly,
534+
CallDataProto::WIFI_AND_MOBILE_DATA => CallsUseLessDataSetting::WifiAndMobileData,
535+
};
536+
485537
Ok(AccountSettings {
486538
phone_number_sharing: M::value(phone_number_sharing),
487539
default_chat_style: M::value(default_chat_style),
@@ -505,10 +557,11 @@ impl<M: Method + ReferencedTypes, C: ReportUnusualTimestamp> TryIntoWith<Account
505557
optimize_on_device_storage: M::value(optimizeOnDeviceStorage),
506558
backup_level: M::value(backup_level),
507559
auto_download_settings: M::value(auto_download_settings),
508-
show_sealed_sender_indicators: M::value(showSealedSenderIndicators),
509560
pin_reminders: M::value(pinReminders),
510561
default_sent_media_quality: M::value(default_sent_media_quality),
511562
screen_lock_timeout: M::value(screen_lock_timeout),
563+
app_theme: M::value(app_theme),
564+
calls_use_less_data_setting: M::value(calls_use_less_data_setting),
512565
})
513566
}
514567
}
@@ -554,18 +607,30 @@ impl TryFrom<proto::account_data::AutoDownloadSettings> for AutoDownloadSettings
554607
}
555608
}
556609

557-
impl From<proto::account_data::AndroidSpecificSettings> for AndroidSpecificSettings {
558-
fn from(value: proto::account_data::AndroidSpecificSettings) -> Self {
610+
impl TryFrom<proto::account_data::AndroidSpecificSettings> for AndroidSpecificSettings {
611+
type Error = AccountDataError;
612+
613+
fn try_from(value: proto::account_data::AndroidSpecificSettings) -> Result<Self, Self::Error> {
559614
use proto::account_data::AndroidSpecificSettings as SettingsProto;
560615
let SettingsProto {
561616
useSystemEmoji,
562617
screenshotSecurity,
618+
navigationBarSize,
563619
special_fields: _,
564620
} = value;
565-
Self {
621+
use proto::account_data::android_specific_settings::NavigationBarSize as BarSizeProto;
622+
let navigation_bar_size = match navigationBarSize.enum_value_or_default() {
623+
BarSizeProto::UNKNOWN_BAR_SIZE => {
624+
return Err(AccountDataError::UnknownAndroidNavigationBarSize);
625+
}
626+
BarSizeProto::NORMAL => NavigationBarSize::Normal,
627+
BarSizeProto::COMPACT => NavigationBarSize::Compact,
628+
};
629+
Ok(Self {
566630
use_system_emoji: useSystemEmoji,
567631
screenshot_security: screenshotSecurity,
568-
}
632+
navigation_bar_size,
633+
})
569634
}
570635
}
571636

@@ -629,6 +694,9 @@ mod test {
629694
.into(),
630695
screenLockTimeoutMinutes: Some(42),
631696
defaultSentMediaQuality: proto::account_data::SentMediaQuality::STANDARD.into(),
697+
appTheme: proto::account_data::AppTheme::SYSTEM.into(),
698+
callsUseLessDataSetting:
699+
proto::account_data::CallsUseLessDataSetting::MOBILE_DATA_ONLY.into(),
632700
..Default::default()
633701
}
634702
}
@@ -659,14 +727,19 @@ mod test {
659727
Self {
660728
useSystemEmoji: true,
661729
screenshotSecurity: false,
730+
navigationBarSize:
731+
proto::account_data::android_specific_settings::NavigationBarSize::COMPACT
732+
.into(),
662733
..Default::default()
663734
}
664735
}
665736
}
666737

667738
impl AndroidSpecificSettings {
668739
pub(crate) fn from_proto_test_data() -> Self {
669-
proto::account_data::AndroidSpecificSettings::test_data().into()
740+
proto::account_data::AndroidSpecificSettings::test_data()
741+
.try_into()
742+
.expect("valid data")
670743
}
671744
}
672745

@@ -744,10 +817,11 @@ mod test {
744817
optimize_on_device_storage: false,
745818
backup_level: Some(BackupLevel::Paid),
746819
auto_download_settings: Some(AutoDownloadSettings::from_proto_test_data()),
747-
show_sealed_sender_indicators: false,
748820
pin_reminders: None,
749821
default_sent_media_quality: SentMediaQuality::Standard,
750822
screen_lock_timeout: Some(Duration::from_mins(42)),
823+
app_theme: AppTheme::System,
824+
calls_use_less_data_setting: CallsUseLessDataSetting::MobileDataOnly,
751825
},
752826
avatar_url_path: "".to_string(),
753827
backup_subscription: Some(IapSubscriberData {

rust/message-backup/src/backup/expected_serialized_backup.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
},
5656
"optimize_on_device_storage": false,
5757
"backup_level": 201,
58-
"show_sealed_sender_indicators": false,
5958
"default_sent_media_quality": "Standard",
6059
"auto_download_settings": {
6160
"images": "Never",
@@ -64,7 +63,9 @@
6463
"documents": "WifiAndCellular"
6564
},
6665
"screen_lock_timeout": 2520000,
67-
"pin_reminders": null
66+
"pin_reminders": null,
67+
"app_theme": "System",
68+
"calls_use_less_data_setting": "MobileDataOnly"
6869
},
6970
"avatar_url_path": "",
7071
"donation_subscription": null,
@@ -77,7 +78,8 @@
7778
"svr_pin": "",
7879
"android_specific_settings": {
7980
"use_system_emoji": true,
80-
"screenshot_security": false
81+
"screenshot_security": false,
82+
"navigation_bar_size": "Compact"
8183
},
8284
"bio_text": "",
8385
"bio_emoji": ""

rust/message-backup/src/proto/backup.proto

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,20 @@ message AccountData {
8888
AutoDownloadOption documents = 4;
8989
}
9090

91+
enum AppTheme {
92+
UNKNOWN_APP_THEME = 0; // Interpret as "System"
93+
SYSTEM = 1;
94+
LIGHT = 2;
95+
DARK = 3;
96+
}
97+
98+
enum CallsUseLessDataSetting {
99+
UNKNOWN_CALL_DATA_SETTING = 0; // Interpret as "Never"
100+
NEVER = 1;
101+
MOBILE_DATA_ONLY = 2;
102+
WIFI_AND_MOBILE_DATA = 3;
103+
}
104+
91105
message AccountSettings {
92106
bool readReceipts = 1;
93107
bool sealedSenderIndicators = 2;
@@ -111,12 +125,14 @@ message AccountData {
111125
bool optimizeOnDeviceStorage = 20;
112126
// See zkgroup for integer particular values. Unset if backups are not enabled.
113127
optional uint64 backupTier = 21;
114-
bool showSealedSenderIndicators = 22;
128+
reserved /* showSealedSenderIndicators */ 22;
115129
SentMediaQuality defaultSentMediaQuality = 23;
116130
AutoDownloadSettings autoDownloadSettings = 24;
117131
reserved /* wifiAutoDownloadSettings */ 25;
118132
optional uint32 screenLockTimeoutMinutes = 26; // If unset, consider screen lock to be disabled.
119133
optional bool pinReminders = 27; // If unset, consider pin reminders to be enabled.
134+
AppTheme appTheme = 28; // If unset, treat the same as "Unknown" case
135+
CallsUseLessDataSetting callsUseLessDataSetting = 29; // If unset, treat the same as "Unknown" case
120136
}
121137

122138
message SubscriberData {
@@ -138,8 +154,15 @@ message AccountData {
138154
}
139155

140156
message AndroidSpecificSettings {
157+
enum NavigationBarSize {
158+
UNKNOWN_BAR_SIZE = 0; // Intepret as "Normal"
159+
NORMAL = 1;
160+
COMPACT = 2;
161+
}
162+
141163
bool useSystemEmoji = 1;
142164
bool screenshotSecurity = 2;
165+
NavigationBarSize navigationBarSize = 3; // If unset, treat the same as "Unknown" case
143166
}
144167

145168
bytes profileKey = 1;

rust/message-backup/src/scramble.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,12 +303,13 @@ impl Visit<Scrambler> for proto::account_data::AccountSettings {
303303
customChatColors,
304304
optimizeOnDeviceStorage: _,
305305
backupTier: _,
306-
special_fields: _,
307-
showSealedSenderIndicators: _,
306+
appTheme: _,
307+
callsUseLessDataSetting: _,
308308
defaultSentMediaQuality: _,
309309
autoDownloadSettings: _,
310310
screenLockTimeoutMinutes: _,
311311
pinReminders: _,
312+
special_fields: _,
312313
} = self;
313314

314315
defaultChatStyle.accept(visitor);
14 Bytes
Binary file not shown.

rust/message-backup/tests/res/canonical-backup.expected.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@
4141
"custom_chat_colors": {},
4242
"optimize_on_device_storage": false,
4343
"backup_level": null,
44-
"show_sealed_sender_indicators": false,
4544
"default_sent_media_quality": "Standard",
4645
"auto_download_settings": null,
4746
"screen_lock_timeout": null,
48-
"pin_reminders": null
47+
"pin_reminders": null,
48+
"app_theme": "System",
49+
"calls_use_less_data_setting": "MobileDataOnly"
4950
},
5051
"avatar_url_path": "",
5152
"donation_subscription": {
@@ -55,7 +56,11 @@
5556
},
5657
"backup_subscription": null,
5758
"svr_pin": "",
58-
"android_specific_settings": null,
59+
"android_specific_settings": {
60+
"use_system_emoji": true,
61+
"screenshot_security": true,
62+
"navigation_bar_size": "Normal"
63+
},
5964
"bio_text": "",
6065
"bio_emoji": ""
6166
},

rust/message-backup/tests/res/canonical-backup.scrambled.expected.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@
4141
"custom_chat_colors": {},
4242
"optimize_on_device_storage": false,
4343
"backup_level": null,
44-
"show_sealed_sender_indicators": false,
4544
"default_sent_media_quality": "Standard",
4645
"auto_download_settings": null,
4746
"screen_lock_timeout": null,
48-
"pin_reminders": null
47+
"pin_reminders": null,
48+
"app_theme": "System",
49+
"calls_use_less_data_setting": "MobileDataOnly"
4950
},
5051
"avatar_url_path": "",
5152
"donation_subscription": {
@@ -55,7 +56,11 @@
5556
},
5657
"backup_subscription": null,
5758
"svr_pin": "",
58-
"android_specific_settings": null,
59+
"android_specific_settings": {
60+
"use_system_emoji": true,
61+
"screenshot_security": true,
62+
"navigation_bar_size": "Normal"
63+
},
5964
"bio_text": "",
6065
"bio_emoji": ""
6166
},

0 commit comments

Comments
 (0)