Skip to content

Commit 6e50583

Browse files
feat(fcm): Support proxy field in FCM AndroidNotification (#1084)
* add 'proxy' to AndroidNotification * fix: removed PROXY_UNSPECIFIED from AndroidNotification.Proxy * Update src/main/java/com/google/firebase/messaging/AndroidNotification.java fix comment AndroidNotification.setProxy Co-authored-by: Jonathan Edey <145066863+jonathanedey@users.noreply.github.com> --------- Co-authored-by: Jonathan Edey <145066863+jonathanedey@users.noreply.github.com>
1 parent c811733 commit 6e50583

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

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

+28-1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ public class AndroidNotification {
112112
@Key("notification_count")
113113
private final Integer notificationCount;
114114

115+
@Key("proxy")
116+
private final String proxy;
117+
115118
private static final Map<Priority, String> PRIORITY_MAP =
116119
ImmutableMap.<Priority, String>builder()
117120
.put(Priority.MIN, "PRIORITY_MIN")
@@ -179,6 +182,11 @@ private AndroidNotification(Builder builder) {
179182
checkArgument(builder.notificationCount >= 0,
180183
"notificationCount if specified must be zero or positive valued");
181184
}
185+
if (builder.proxy != null) {
186+
this.proxy = builder.proxy.name();
187+
} else {
188+
this.proxy = null;
189+
}
182190
this.notificationCount = builder.notificationCount;
183191
}
184192

@@ -194,13 +202,19 @@ public String toString() {
194202
return PRIORITY_MAP.get(this);
195203
}
196204
}
197-
205+
198206
public enum Visibility {
199207
PRIVATE,
200208
PUBLIC,
201209
SECRET,
202210
}
203211

212+
public enum Proxy {
213+
ALLOW,
214+
DENY,
215+
IF_PRIORITY_LOWERED
216+
}
217+
204218
/**
205219
* Creates a new {@link AndroidNotification.Builder}.
206220
*
@@ -237,6 +251,7 @@ public static class Builder {
237251
private LightSettings lightSettings;
238252
private Boolean defaultLightSettings;
239253
private Visibility visibility;
254+
private Proxy proxy;
240255

241256
private Builder() {}
242257

@@ -602,6 +617,18 @@ public Builder setNotificationCount(int notificationCount) {
602617
return this;
603618
}
604619

620+
/**
621+
* Sets the proxy of this notification.
622+
*
623+
* @param proxy The proxy value, one of the values in {ALLOW, DENY, IF_PRIORITY_LOWERED}
624+
*
625+
* @return This builder.
626+
*/
627+
public Builder setProxy(Proxy proxy) {
628+
this.proxy = proxy;
629+
return this;
630+
}
631+
605632
/**
606633
* Creates a new {@link AndroidNotification} instance from the parameters set on this builder.
607634
*

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

+2
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,7 @@ public void testExtendedAndroidNotificationParameters() throws IOException {
890890
.setDefaultLightSettings(false)
891891
.setVisibility(AndroidNotification.Visibility.PUBLIC)
892892
.setNotificationCount(10)
893+
.setProxy(AndroidNotification.Proxy.DENY)
893894
.build())
894895
.build())
895896
.setTopic("test-topic")
@@ -923,6 +924,7 @@ public void testExtendedAndroidNotificationParameters() throws IOException {
923924
.put("default_light_settings", false)
924925
.put("visibility", "public")
925926
.put("notification_count", new BigDecimal(10))
927+
.put("proxy", "DENY")
926928
.build())
927929
.build();
928930
assertJsonEquals(ImmutableMap.of(

0 commit comments

Comments
 (0)