Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/main/java/com/google/firebase/messaging/AndroidConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public class AndroidConfig {
@Key("direct_boot_ok")
private final Boolean directBootOk;

@Key("bandwidth_constrained_ok")
private final Boolean bandwidthConstrainedOk;

private AndroidConfig(Builder builder) {
this.collapseKey = builder.collapseKey;
if (builder.priority != null) {
Expand All @@ -79,6 +82,7 @@ private AndroidConfig(Builder builder) {
this.notification = builder.notification;
this.fcmOptions = builder.fcmOptions;
this.directBootOk = builder.directBootOk;
this.bandwidthConstrainedOk = builder.bandwidthConstrainedOk;
}

/**
Expand Down Expand Up @@ -108,6 +112,7 @@ public static class Builder {
private AndroidNotification notification;
private AndroidFcmOptions fcmOptions;
private Boolean directBootOk;
private Boolean bandwidthConstrainedOk;

private Builder() {}

Expand Down Expand Up @@ -218,6 +223,15 @@ public Builder setDirectBootOk(boolean directBootOk) {
return this;
}

/**
* Sets the {@code bandwidth_constrained_ok} flag. If set to true, messages can be delivered
* even when the device is connected through a bandwidth-constrained network.
*/
public Builder setBandwidthConstrainedOk(boolean bandwidthConstrainedOk) {
this.bandwidthConstrainedOk = bandwidthConstrainedOk;
return this;
}

/**
* Creates a new {@link AndroidConfig} instance from the parameters set on this builder.
*
Expand Down
23 changes: 23 additions & 0 deletions src/test/java/com/google/firebase/messaging/MessageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,29 @@ public void testAndroidMessageWithDirectBootOk() throws IOException {
assertJsonEquals(ImmutableMap.of("topic", "test-topic", "android", data), message);
}

@Test
public void testAndroidMessageWithBandwidthConstrainedOk() throws IOException {
Message message = Message.builder()
.setAndroidConfig(AndroidConfig.builder()
.setBandwidthConstrainedOk(true)
.setNotification(AndroidNotification.builder()
.setTitle("android-title")
.setBody("android-body")
.build())
.build())
.setTopic("test-topic")
.build();
Map<String, Object> notification = ImmutableMap.<String, Object>builder()
.put("title", "android-title")
.put("body", "android-body")
.build();
Map<String, Object> data = ImmutableMap.of(
"bandwidth_constrained_ok", true,
"notification", notification
);
assertJsonEquals(ImmutableMap.of("topic", "test-topic", "android", data), message);
}

@Test(expected = IllegalArgumentException.class)
public void testAndroidNotificationWithNegativeCount() throws IllegalArgumentException {
AndroidNotification.builder().setNotificationCount(-1).build();
Expand Down