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
18 changes: 16 additions & 2 deletions src/main/java/com/google/firebase/messaging/AndroidConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public class AndroidConfig {
@Key("bandwidth_constrained_ok")
private final Boolean bandwidthConstrainedOk;

@Key("restricted_satellite_ok")
private final Boolean restrictedSatelliteOk;

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

/**
Expand Down Expand Up @@ -113,6 +117,7 @@ public static class Builder {
private AndroidFcmOptions fcmOptions;
private Boolean directBootOk;
private Boolean bandwidthConstrainedOk;
private Boolean restrictedSatelliteOk;

private Builder() {}

Expand Down Expand Up @@ -224,14 +229,23 @@ public Builder setDirectBootOk(boolean directBootOk) {
}

/**
* 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.
* Sets the {@code bandwidth_constrained_ok} flag. If set to true, messages will be allowed
* to be delivered to the app while the device is on a bandwidth constrained network.
*/
public Builder setBandwidthConstrainedOk(boolean bandwidthConstrainedOk) {
this.bandwidthConstrainedOk = bandwidthConstrainedOk;
return this;
}

/**
* Sets the {@code restricted_satellite_ok} flag. If set to true, messages will be allowed
* to be delivered to the app while the device is on a restricted satellite network.
*/
public Builder setRestrictedSatelliteOk(boolean restrictedSatelliteOk) {
this.restrictedSatelliteOk = restrictedSatelliteOk;
return this;
}

/**
* Creates a new {@link AndroidConfig} instance from the parameters set on this builder.
*
Expand Down
26 changes: 24 additions & 2 deletions src/test/java/com/google/firebase/messaging/MessageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail;

import com.google.api.client.googleapis.util.Utils;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.JsonParser;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -247,6 +246,29 @@ public void testAndroidMessageWithBandwidthConstrainedOk() throws IOException {
assertJsonEquals(ImmutableMap.of("topic", "test-topic", "android", data), message);
}

@Test
public void testAndroidMessageWithRestrictedSatelliteOk() throws IOException {
Message message = Message.builder()
.setAndroidConfig(AndroidConfig.builder()
.setRestrictedSatelliteOk(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(
"restricted_satellite_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 Expand Up @@ -991,7 +1013,7 @@ public void testExtendedAndroidNotificationParameters() throws IOException {
}

private static void assertJsonEquals(
Map expected, Object actual) throws IOException {
Map<String, Object> expected, Object actual) throws IOException {
assertEquals(expected, toMap(actual));
}

Expand Down
Loading