Skip to content

feat(fcm): Support proxy field in FCM AndroidNotification #1084

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 21, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ public class AndroidNotification {
@Key("notification_count")
private final Integer notificationCount;

@Key("proxy")
private final String proxy;

private static final Map<Priority, String> PRIORITY_MAP =
ImmutableMap.<Priority, String>builder()
.put(Priority.MIN, "PRIORITY_MIN")
Expand Down Expand Up @@ -179,6 +182,11 @@ private AndroidNotification(Builder builder) {
checkArgument(builder.notificationCount >= 0,
"notificationCount if specified must be zero or positive valued");
}
if (builder.proxy != null) {
this.proxy = builder.proxy.name();
} else {
this.proxy = null;
}
this.notificationCount = builder.notificationCount;
}

Expand All @@ -194,13 +202,19 @@ public String toString() {
return PRIORITY_MAP.get(this);
}
}

public enum Visibility {
PRIVATE,
PUBLIC,
SECRET,
}

public enum Proxy {
ALLOW,
DENY,
IF_PRIORITY_LOWERED
}

/**
* Creates a new {@link AndroidNotification.Builder}.
*
Expand Down Expand Up @@ -237,6 +251,7 @@ public static class Builder {
private LightSettings lightSettings;
private Boolean defaultLightSettings;
private Visibility visibility;
private Proxy proxy;

private Builder() {}

Expand Down Expand Up @@ -602,6 +617,18 @@ public Builder setNotificationCount(int notificationCount) {
return this;
}

/**
* Sets the proxy of this notification.
*
* @param proxy The proxy value, one of the values in {ALLOW, DENY, IF_PRIORITY_LOWERED}
*
* @return This builder.
*/
public Builder setProxy(Proxy proxy) {
this.proxy = proxy;
return this;
}

/**
* Creates a new {@link AndroidNotification} instance from the parameters set on this builder.
*
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/com/google/firebase/messaging/MessageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,7 @@ public void testExtendedAndroidNotificationParameters() throws IOException {
.setDefaultLightSettings(false)
.setVisibility(AndroidNotification.Visibility.PUBLIC)
.setNotificationCount(10)
.setProxy(AndroidNotification.Proxy.DENY)
.build())
.build())
.setTopic("test-topic")
Expand Down Expand Up @@ -923,6 +924,7 @@ public void testExtendedAndroidNotificationParameters() throws IOException {
.put("default_light_settings", false)
.put("visibility", "public")
.put("notification_count", new BigDecimal(10))
.put("proxy", "DENY")
.build())
.build();
assertJsonEquals(ImmutableMap.of(
Expand Down