Skip to content

Commit 379e391

Browse files
authored
feat(fcm): Add DirectBootOk field to AndroidConfig (#431)
1 parent fa540bd commit 379e391

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

FirebaseAdmin/FirebaseAdmin.IntegrationTests/FirebaseMessagingTest.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public async Task Send()
4545
Priority = Priority.Normal,
4646
TimeToLive = TimeSpan.FromHours(1),
4747
RestrictedPackageName = "com.google.firebase.testing",
48+
DirectBootOk = true,
4849
},
4950
};
5051
var id = await FirebaseMessaging.DefaultInstance.SendAsync(message, dryRun: true);
@@ -69,6 +70,7 @@ public async Task SendEach()
6970
Priority = Priority.Normal,
7071
TimeToLive = TimeSpan.FromHours(1),
7172
RestrictedPackageName = "com.google.firebase.testing",
73+
DirectBootOk = false,
7274
},
7375
};
7476
var message2 = new Message()
@@ -84,6 +86,7 @@ public async Task SendEach()
8486
Priority = Priority.Normal,
8587
TimeToLive = TimeSpan.FromHours(1),
8688
RestrictedPackageName = "com.google.firebase.testing",
89+
DirectBootOk = true,
8790
},
8891
};
8992
var response = await FirebaseMessaging.DefaultInstance.SendEachAsync(new[] { message1, message2 }, dryRun: true);

FirebaseAdmin/FirebaseAdmin.Tests/Messaging/MessageTest.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ public void AndroidConfig()
260260
{ "k1", "v1" },
261261
{ "k2", "v2" },
262262
},
263+
DirectBootOk = true,
263264
Notification = new AndroidNotification()
264265
{
265266
Title = "title",
@@ -310,6 +311,7 @@ public void AndroidConfig()
310311
{ "ttl", "0.010000000s" },
311312
{ "restricted_package_name", "test-pkg-name" },
312313
{ "data", new JObject() { { "k1", "v1" }, { "k2", "v2" } } },
314+
{ "direct_boot_ok", true },
313315
{
314316
"notification", new JObject()
315317
{
@@ -424,6 +426,7 @@ public void AndroidConfigDeserialization()
424426
{
425427
{ "key", "value" },
426428
},
429+
DirectBootOk = false,
427430
Notification = new AndroidNotification()
428431
{
429432
Title = "title",
@@ -437,6 +440,7 @@ public void AndroidConfigDeserialization()
437440
Assert.Equal(original.Priority, copy.Priority);
438441
Assert.Equal(original.TimeToLive, copy.TimeToLive);
439442
Assert.Equal(original.Data, copy.Data);
443+
Assert.Equal(original.DirectBootOk, copy.DirectBootOk);
440444
Assert.Equal(original.Notification.Title, copy.Notification.Title);
441445
}
442446

FirebaseAdmin/FirebaseAdmin/Messaging/AndroidConfig.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ public sealed class AndroidConfig
6060
[JsonProperty("data")]
6161
public IReadOnlyDictionary<string, string> Data { get; set; }
6262

63+
/// <summary>
64+
/// Gets or sets a boolean indicating whether messages will be allowed to be delivered to
65+
/// the app while the device is in direct boot mode.
66+
/// </summary>
67+
[JsonProperty("direct_boot_ok")]
68+
public bool? DirectBootOk { get; set; }
69+
6370
/// <summary>
6471
/// Gets or sets the Android notification to be included in the message.
6572
/// </summary>
@@ -165,6 +172,7 @@ internal AndroidConfig CopyAndValidate()
165172
TimeToLive = this.TimeToLive,
166173
RestrictedPackageName = this.RestrictedPackageName,
167174
Data = this.Data?.Copy(),
175+
DirectBootOk = this.DirectBootOk,
168176
FcmOptions = this.FcmOptions?.CopyAndValidate(),
169177
};
170178
var totalSeconds = copy.TimeToLive?.TotalSeconds ?? 0;

0 commit comments

Comments
 (0)