diff --git a/firebase_admin/_messaging_encoder.py b/firebase_admin/_messaging_encoder.py index 48a3dd3cd..725db45cc 100644 --- a/firebase_admin/_messaging_encoder.py +++ b/firebase_admin/_messaging_encoder.py @@ -160,6 +160,15 @@ def check_analytics_label(cls, label, value): raise ValueError('Malformed {}.'.format(label)) return value + @classmethod + def check_boolean(cls, label, value): + """Checks if the given value is boolean.""" + if value is None: + return None + if not isinstance(value, bool): + raise ValueError('{0} must be a boolean.'.format(label)) + return value + @classmethod def check_datetime(cls, label, value): """Checks if the given value is a datetime.""" @@ -214,6 +223,8 @@ def encode_android_fcm_options(cls, fcm_options): result = { 'analytics_label': _Validators.check_analytics_label( 'AndroidFCMOptions.analytics_label', fcm_options.analytics_label), + 'direct_boot_ok': _Validators.check_boolean( + 'AndroidFCMOptions.direct_boot_ok', fcm_options.direct_boot_ok) } result = cls.remove_null_values(result) return result diff --git a/firebase_admin/_messaging_utils.py b/firebase_admin/_messaging_utils.py index 64930f1b8..e10b869bd 100644 --- a/firebase_admin/_messaging_utils.py +++ b/firebase_admin/_messaging_utils.py @@ -203,10 +203,13 @@ class AndroidFCMOptions: Args: analytics_label: contains additional options for features provided by the FCM Android SDK (optional). + direct_boot_ok: A boolean indicating whether messages will be allowed to be delivered to + the app while the device is in direct boot mode. """ - def __init__(self, analytics_label=None): + def __init__(self, analytics_label=None, direct_boot_ok=None): self.analytics_label = analytics_label + self.direct_boot_ok = direct_boot_ok class WebpushConfig: