Skip to content

Commit d62a15e

Browse files
authored
feat(fcm): Add support for bandwidth constrained and restricted satellite APIs (#940)
* feat(fcm): Add support for bandwidth constrained and restricted satellite APIs * chore: Add type hints to `AndroidConfig`
1 parent 581ef26 commit d62a15e

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
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: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
# limitations under the License.
1414

1515
"""Types and utilities used by the messaging (FCM) module."""
16+
from __future__ import annotations
17+
import datetime
18+
from typing import Dict, Optional, Union
1619

1720
from firebase_admin import exceptions
1821

@@ -51,10 +54,25 @@ class AndroidConfig:
5154
fcm_options: A ``messaging.AndroidFCMOptions`` to be included in the message (optional).
5255
direct_boot_ok: A boolean indicating whether messages will be allowed to be delivered to
5356
the app while the device is in direct boot mode (optional).
57+
bandwidth_constrained_ok: A boolean indicating whether messages will be allowed to be
58+
delivered to the app while the device is on a bandwidth constrained network (optional).
59+
restricted_satellite_ok: A boolean indicating whether messages will be allowed to be
60+
delivered to the app while the device is on a restricted satellite network (optional).
5461
"""
5562

56-
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):
63+
def __init__(
64+
self,
65+
collapse_key: Optional[str] = None,
66+
priority: Optional[str] = None,
67+
ttl: Optional[Union[int, float, datetime.timedelta]] = None,
68+
restricted_package_name: Optional[str] = None,
69+
data: Optional[Dict[str, str]] = None,
70+
notification: Optional[AndroidNotification] = None,
71+
fcm_options: Optional[AndroidFCMOptions] = None,
72+
direct_boot_ok: Optional[bool] = None,
73+
bandwidth_constrained_ok: Optional[bool] = None,
74+
restricted_satellite_ok: Optional[bool] = None
75+
):
5876
self.collapse_key = collapse_key
5977
self.priority = priority
6078
self.ttl = ttl
@@ -63,6 +81,8 @@ def __init__(self, collapse_key=None, priority=None, ttl=None, restricted_packag
6381
self.notification = notification
6482
self.fcm_options = fcm_options
6583
self.direct_boot_ok = direct_boot_ok
84+
self.bandwidth_constrained_ok = bandwidth_constrained_ok
85+
self.restricted_satellite_ok = restricted_satellite_ok
6686

6787

6888
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)