Skip to content

Commit 481fe19

Browse files
committed
Add support for new bandwidthConstrainedOk flag used to deliver notifications to sat networks
1 parent 800298c commit 481fe19

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
@@ -55,6 +55,9 @@ public class AndroidConfig {
5555
@Key("direct_boot_ok")
5656
private final Boolean directBootOk;
5757

58+
@Key("bandwidth_constrained_ok")
59+
private final Boolean bandwidthConstrainedOk;
60+
5861
private AndroidConfig(Builder builder) {
5962
this.collapseKey = builder.collapseKey;
6063
if (builder.priority != null) {
@@ -79,6 +82,7 @@ private AndroidConfig(Builder builder) {
7982
this.notification = builder.notification;
8083
this.fcmOptions = builder.fcmOptions;
8184
this.directBootOk = builder.directBootOk;
85+
this.bandwidthConstrainedOk = builder.bandwidthConstrainedOk;
8286
}
8387

8488
/**
@@ -108,6 +112,7 @@ public static class Builder {
108112
private AndroidNotification notification;
109113
private AndroidFcmOptions fcmOptions;
110114
private Boolean directBootOk;
115+
private Boolean bandwidthConstrainedOk;
111116

112117
private Builder() {}
113118

@@ -218,6 +223,15 @@ public Builder setDirectBootOk(boolean directBootOk) {
218223
return this;
219224
}
220225

226+
/**
227+
* Sets the {@code bandwidth_constrained_ok} flag. If set to true, messages can be delivered
228+
* even when the device is connected through a bandwidth-constrained network.
229+
*/
230+
public Builder setBandwidthConstrainedOk(boolean bandwidthConstrainedOk) {
231+
this.bandwidthConstrainedOk = bandwidthConstrainedOk;
232+
return this;
233+
}
234+
221235
/**
222236
* Creates a new {@link AndroidConfig} instance from the parameters set on this builder.
223237
*

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,29 @@ public void testAndroidMessageWithDirectBootOk() throws IOException {
224224
assertJsonEquals(ImmutableMap.of("topic", "test-topic", "android", data), message);
225225
}
226226

227+
@Test
228+
public void testAndroidMessageWithBandwidthConstrainedOk() throws IOException {
229+
Message message = Message.builder()
230+
.setAndroidConfig(AndroidConfig.builder()
231+
.setBandwidthConstrainedOk(true)
232+
.setNotification(AndroidNotification.builder()
233+
.setTitle("android-title")
234+
.setBody("android-body")
235+
.build())
236+
.build())
237+
.setTopic("test-topic")
238+
.build();
239+
Map<String, Object> notification = ImmutableMap.<String, Object>builder()
240+
.put("title", "android-title")
241+
.put("body", "android-body")
242+
.build();
243+
Map<String, Object> data = ImmutableMap.of(
244+
"bandwidth_constrained_ok", true,
245+
"notification", notification
246+
);
247+
assertJsonEquals(ImmutableMap.of("topic", "test-topic", "android", data), message);
248+
}
249+
227250
@Test(expected = IllegalArgumentException.class)
228251
public void testAndroidNotificationWithNegativeCount() throws IllegalArgumentException {
229252
AndroidNotification.builder().setNotificationCount(-1).build();

0 commit comments

Comments
 (0)