Skip to content

Commit 2fa81c7

Browse files
authored
Support direct_boot_ok parameter (#329)
1 parent 3485c98 commit 2fa81c7

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/main/java/com/google/firebase/messaging/AndroidConfig.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public class AndroidConfig {
5151

5252
@Key("fcm_options")
5353
private final AndroidFcmOptions fcmOptions;
54+
55+
@Key("direct_boot_ok")
56+
private final Boolean directBootOk;
5457

5558
private AndroidConfig(Builder builder) {
5659
this.collapseKey = builder.collapseKey;
@@ -75,6 +78,7 @@ private AndroidConfig(Builder builder) {
7578
this.data = builder.data.isEmpty() ? null : ImmutableMap.copyOf(builder.data);
7679
this.notification = builder.notification;
7780
this.fcmOptions = builder.fcmOptions;
81+
this.directBootOk = builder.directBootOk;
7882
}
7983

8084
/**
@@ -103,6 +107,7 @@ public static class Builder {
103107
private final Map<String, String> data = new HashMap<>();
104108
private AndroidNotification notification;
105109
private AndroidFcmOptions fcmOptions;
110+
private Boolean directBootOk;
106111

107112
private Builder() {}
108113

@@ -201,6 +206,15 @@ public Builder setFcmOptions(AndroidFcmOptions androidFcmOptions) {
201206
return this;
202207
}
203208

209+
/**
210+
* Sets the direct_boot_ok flag, If set to true, messages will be allowed to be delivered to
211+
* the app while the device is in direct boot mode.
212+
*/
213+
public Builder setDirectBootOk(boolean directBootOk) {
214+
this.directBootOk = directBootOk;
215+
return this;
216+
}
217+
204218
/**
205219
* Creates a new {@link AndroidConfig} instance from the parameters set on this builder.
206220
*

src/test/java/com/google/firebase/messaging/MessageTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,29 @@ public void testAndroidMessageWithNotification() throws IOException {
200200
assertJsonEquals(ImmutableMap.of("topic", "test-topic", "android", data), message);
201201
}
202202

203+
@Test
204+
public void testAndroidMessageWithDirectBootOk() throws IOException {
205+
Message message = Message.builder()
206+
.setAndroidConfig(AndroidConfig.builder()
207+
.setDirectBootOk(true)
208+
.setNotification(AndroidNotification.builder()
209+
.setTitle("android-title")
210+
.setBody("android-body")
211+
.build())
212+
.build())
213+
.setTopic("test-topic")
214+
.build();
215+
Map<String, Object> notification = ImmutableMap.<String, Object>builder()
216+
.put("title", "android-title")
217+
.put("body", "android-body")
218+
.build();
219+
Map<String, Object> data = ImmutableMap.of(
220+
"direct_boot_ok", true,
221+
"notification", notification
222+
);
223+
assertJsonEquals(ImmutableMap.of("topic", "test-topic", "android", data), message);
224+
}
225+
203226
@Test(expected = IllegalArgumentException.class)
204227
public void testAndroidNotificationWithNegativeCount() throws IllegalArgumentException {
205228
AndroidNotification.builder().setNotificationCount(-1).build();

0 commit comments

Comments
 (0)