Skip to content

Commit 880ba95

Browse files
committed
feat(fcm): Add support for bandwidth constrained and restricted satellite APIs
1 parent 581ef26 commit 880ba95

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

firebase_admin/_messaging_encoder.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ def encode_android(cls, android):
207207
'fcm_options': cls.encode_android_fcm_options(android.fcm_options),
208208
'direct_boot_ok': _Validators.check_boolean(
209209
'AndroidConfig.direct_boot_ok', android.direct_boot_ok),
210+
'bandwidth_constrained_ok': _Validators.check_boolean(
211+
'AndroidConfig.bandwidth_constrained_ok', android.bandwidth_constrained_ok),
212+
'restricted_satellite_ok': _Validators.check_boolean(
213+
'AndroidConfig.restricted_satellite_ok', android.restricted_satellite_ok),
210214
}
211215
result = cls.remove_null_values(result)
212216
priority = result.get('priority')

firebase_admin/_messaging_utils.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,15 @@ class AndroidConfig:
5151
fcm_options: A ``messaging.AndroidFCMOptions`` to be included in the message (optional).
5252
direct_boot_ok: A boolean indicating whether messages will be allowed to be delivered to
5353
the app while the device is in direct boot mode (optional).
54+
bandwidth_constrained_ok: A boolean indicating whether messages will be allowed to be
55+
delivered to the app while the device is on a bandwidth constrained network (optional).
56+
restricted_satellite_ok: A boolean indicating whether messages will be allowed to be
57+
delivered to the app while the device is on a restricted satellite network (optional).
5458
"""
5559

5660
def __init__(self, collapse_key=None, priority=None, ttl=None, restricted_package_name=None,
57-
data=None, notification=None, fcm_options=None, direct_boot_ok=None):
61+
data=None, notification=None, fcm_options=None, direct_boot_ok=None,
62+
bandwidth_constrained_ok=None, restricted_satellite_ok=None):
5863
self.collapse_key = collapse_key
5964
self.priority = priority
6065
self.ttl = ttl
@@ -63,6 +68,8 @@ def __init__(self, collapse_key=None, priority=None, ttl=None, restricted_packag
6368
self.notification = notification
6469
self.fcm_options = fcm_options
6570
self.direct_boot_ok = direct_boot_ok
71+
self.bandwidth_constrained_ok = bandwidth_constrained_ok
72+
self.restricted_satellite_ok = restricted_satellite_ok
6673

6774

6875
class AndroidNotification:

tests/test_messaging.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,18 @@ def test_invalid_direct_boot_ok(self, data):
335335
check_encoding(messaging.Message(
336336
topic='topic', android=messaging.AndroidConfig(direct_boot_ok=data)))
337337

338+
@pytest.mark.parametrize('data', NON_BOOL_ARGS)
339+
def test_invalid_bandwidth_constrained_ok(self, data):
340+
with pytest.raises(ValueError):
341+
check_encoding(messaging.Message(
342+
topic='topic', android=messaging.AndroidConfig(bandwidth_constrained_ok=data)))
343+
344+
@pytest.mark.parametrize('data', NON_BOOL_ARGS)
345+
def test_invalid_restricted_satellite_ok(self, data):
346+
with pytest.raises(ValueError):
347+
check_encoding(messaging.Message(
348+
topic='topic', android=messaging.AndroidConfig(restricted_satellite_ok=data)))
349+
338350

339351
def test_android_config(self):
340352
msg = messaging.Message(
@@ -347,6 +359,8 @@ def test_android_config(self):
347359
data={'k1': 'v1', 'k2': 'v2'},
348360
fcm_options=messaging.AndroidFCMOptions('analytics_label_v1'),
349361
direct_boot_ok=True,
362+
bandwidth_constrained_ok=True,
363+
restricted_satellite_ok=True,
350364
)
351365
)
352366
expected = {
@@ -364,6 +378,8 @@ def test_android_config(self):
364378
'analytics_label': 'analytics_label_v1',
365379
},
366380
'direct_boot_ok': True,
381+
'bandwidth_constrained_ok': True,
382+
'restricted_satellite_ok': True,
367383
},
368384
}
369385
check_encoding(msg, expected)

0 commit comments

Comments
 (0)