Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jun 29, 2022. It is now read-only.

Commit62ac3fc

Browse files
Add support for analytics_label to be specified (firebase#285)
1 parent6e507af commit62ac3fc

File tree

9 files changed

+421
-0
lines changed

9 files changed

+421
-0
lines changed

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#Unreleased
22

3+
-[added] Added`FcmOptions`,`ApnsFcmOptions` and`AndroidFcmOptions` to the
4+
`FirebaseMessaging` API, which all provides a`setAnalyticsLabel()` method.
35
-[changed] Upgraded the Cloud Firestore client to 1.9.0.
46
-[changed] Upgraded the Cloud Storage client to 1.79.0.
57
-[changed] Upgraded the Google API client to 1.30.1.

‎src/main/java/com/google/firebase/messaging/AndroidConfig.java‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public class AndroidConfig {
4949
@Key("notification")
5050
privatefinalAndroidNotificationnotification;
5151

52+
@Key("fcm_options")
53+
privatefinalAndroidFcmOptionsfcmOptions;
54+
5255
privateAndroidConfig(Builderbuilder) {
5356
this.collapseKey =builder.collapseKey;
5457
if (builder.priority !=null) {
@@ -71,6 +74,7 @@ private AndroidConfig(Builder builder) {
7174
this.restrictedPackageName =builder.restrictedPackageName;
7275
this.data =builder.data.isEmpty() ?null :ImmutableMap.copyOf(builder.data);
7376
this.notification =builder.notification;
77+
this.fcmOptions =builder.fcmOptions;
7478
}
7579

7680
/**
@@ -98,6 +102,7 @@ public static class Builder {
98102
privateStringrestrictedPackageName;
99103
privatefinalMap<String,String>data =newHashMap<>();
100104
privateAndroidNotificationnotification;
105+
privateAndroidFcmOptionsfcmOptions;
101106

102107
privateBuilder() {}
103108

@@ -187,6 +192,15 @@ public Builder setNotification(AndroidNotification notification) {
187192
returnthis;
188193
}
189194

195+
/**
196+
* Sets the {@link AndroidFcmOptions}, which will override values set in the {@link FcmOptions}
197+
* for Android messages.
198+
*/
199+
publicBuildersetFcmOptions(AndroidFcmOptionsandroidFcmOptions) {
200+
this.fcmOptions =androidFcmOptions;
201+
returnthis;
202+
}
203+
190204
/**
191205
* Creates a new {@link AndroidConfig} instance from the parameters set on this builder.
192206
*
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
packagecom.google.firebase.messaging;
16+
17+
importcom.google.api.client.util.Key;
18+
19+
/**
20+
* Represents the Android-specific FCM options that can be included in an {@link AndroidConfig}.
21+
* Instances of this class are thread-safe and immutable.
22+
*/
23+
publicfinalclassAndroidFcmOptions {
24+
25+
@Key("analytics_label")
26+
privatefinalStringanalyticsLabel;
27+
28+
privateAndroidFcmOptions(Builderbuilder) {
29+
FcmOptionsUtil.checkAnalyticsLabel(builder.analyticsLabel);
30+
this.analyticsLabel =builder.analyticsLabel;
31+
}
32+
33+
/**
34+
* Creates a new {@link AndroidFcmOptions} with the specified analytics label.
35+
*
36+
* @param analyticsLabel An analytics label
37+
* @return An AndroidFcmOptions with the analytics label set to the supplied value.
38+
*/
39+
publicstaticAndroidFcmOptionswithAnalyticsLabel(StringanalyticsLabel) {
40+
returnbuilder().setAnalyticsLabel(analyticsLabel).build();
41+
}
42+
43+
/**
44+
* Creates a new {@link AndroidFcmOptions.Builder}.
45+
*
46+
* @return A {@link AndroidFcmOptions.Builder} instance.
47+
*/
48+
publicstaticBuilderbuilder() {
49+
returnnewBuilder();
50+
}
51+
52+
publicstaticclassBuilder {
53+
54+
privateStringanalyticsLabel;
55+
56+
privateBuilder() {}
57+
58+
/**
59+
* @param analyticsLabel A string representing the analytics label used for Android messages.
60+
* @return This builder
61+
*/
62+
publicBuildersetAnalyticsLabel(StringanalyticsLabel) {
63+
this.analyticsLabel =analyticsLabel;
64+
returnthis;
65+
}
66+
67+
/**
68+
* Creates a new {@link AndroidFcmOptions} instance from the parameters set on this builder.
69+
*
70+
* @return A new {@link AndroidFcmOptions} instance.
71+
* @throws IllegalArgumentException If any of the parameters set on the builder are invalid.
72+
*/
73+
publicAndroidFcmOptionsbuild() {
74+
returnnewAndroidFcmOptions(this);
75+
}
76+
}
77+
}

‎src/main/java/com/google/firebase/messaging/ApnsConfig.java‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ public class ApnsConfig {
3838
@Key("payload")
3939
privatefinalMap<String,Object>payload;
4040

41+
@Key("fcm_options")
42+
privatefinalApnsFcmOptionsfcmOptions;
43+
4144
privateApnsConfig(Builderbuilder) {
4245
checkArgument(builder.aps !=null,"aps must be specified");
4346
checkArgument(!builder.customData.containsKey("aps"),
@@ -47,6 +50,7 @@ private ApnsConfig(Builder builder) {
4750
.putAll(builder.customData)
4851
.put("aps",builder.aps.getFields())
4952
.build();
53+
this.fcmOptions =builder.fcmOptions;
5054
}
5155

5256
/**
@@ -63,6 +67,7 @@ public static class Builder {
6367
privatefinalMap<String,String>headers =newHashMap<>();
6468
privatefinalMap<String,Object>customData =newHashMap<>();
6569
privateApsaps;
70+
privateApnsFcmOptionsfcmOptions;
6671

6772
privateBuilder() {}
6873

@@ -123,6 +128,15 @@ public Builder putAllCustomData(@NonNull Map<String, Object> map) {
123128
returnthis;
124129
}
125130

131+
/**
132+
* Sets the {@link ApnsFcmOptions}, which will override values set in the {@link FcmOptions} for
133+
* APNS messages.
134+
*/
135+
publicBuildersetFcmOptions(ApnsFcmOptionsapnsFcmOptions) {
136+
this.fcmOptions =apnsFcmOptions;
137+
returnthis;
138+
}
139+
126140
/**
127141
* Creates a new {@link ApnsConfig} instance from the parameters set on this builder.
128142
*
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
packagecom.google.firebase.messaging;
16+
17+
importcom.google.api.client.util.Key;
18+
19+
/**
20+
* Represents the APNS-specific FCM options that can be included in an {@link ApnsConfig}. Instances
21+
* of this class are thread-safe and immutable.
22+
*/
23+
publicfinalclassApnsFcmOptions {
24+
25+
@Key("analytics_label")
26+
privatefinalStringanalyticsLabel;
27+
28+
privateApnsFcmOptions(Builderbuilder) {
29+
FcmOptionsUtil.checkAnalyticsLabel(builder.analyticsLabel);
30+
this.analyticsLabel =builder.analyticsLabel;
31+
}
32+
33+
/**
34+
* Creates a new {@link ApnsFcmOptions} with the specified analytics label.
35+
*
36+
* @param analyticsLabel An analytics label
37+
* @return An ApnsFcmOptions with the analytics label set to the supplied value.
38+
*/
39+
publicstaticApnsFcmOptionswithAnalyticsLabel(StringanalyticsLabel) {
40+
returnbuilder().setAnalyticsLabel(analyticsLabel).build();
41+
}
42+
43+
/**
44+
* Creates a new {@link ApnsFcmOptions.Builder}.
45+
*
46+
* @return An {@link ApnsFcmOptions.Builder} instance.
47+
*/
48+
publicstaticBuilderbuilder() {
49+
returnnewBuilder();
50+
}
51+
52+
publicstaticclassBuilder {
53+
54+
privateStringanalyticsLabel;
55+
56+
privateBuilder() {}
57+
58+
/**
59+
* @param analyticsLabel A string representing the analytics label used for APNS messages.
60+
* @return This builder
61+
*/
62+
publicBuildersetAnalyticsLabel(StringanalyticsLabel) {
63+
this.analyticsLabel =analyticsLabel;
64+
returnthis;
65+
}
66+
67+
/**
68+
* Creates a new {@link ApnsFcmOptions} instance from the parameters set on this builder.
69+
*
70+
* @return A new {@link ApnsFcmOptions} instance.
71+
* @throws IllegalArgumentException If any of the parameters set on the builder are invalid.
72+
*/
73+
publicApnsFcmOptionsbuild() {
74+
returnnewApnsFcmOptions(this);
75+
}
76+
}
77+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
packagecom.google.firebase.messaging;
16+
17+
importcom.google.api.client.util.Key;
18+
19+
/**
20+
* Represents the platform-independent FCM options that can be included in a {@link Message}.
21+
* Instances of this class are thread-safe and immutable.
22+
*/
23+
publicfinalclassFcmOptions {
24+
25+
@Key("analytics_label")
26+
privatefinalStringanalyticsLabel;
27+
28+
privateFcmOptions(Builderbuilder) {
29+
FcmOptionsUtil.checkAnalyticsLabel(builder.analyticsLabel);
30+
this.analyticsLabel =builder.analyticsLabel;
31+
}
32+
33+
/**
34+
* Creates a new {@link FcmOptions} with the specified analytics label.
35+
*
36+
* @param analyticsLabel An analytics label
37+
* @return An FcmOptions with the analytics label set to the supplied value.
38+
*/
39+
publicstaticFcmOptionswithAnalyticsLabel(StringanalyticsLabel) {
40+
returnnewBuilder().setAnalyticsLabel(analyticsLabel).build();
41+
}
42+
43+
/**
44+
* Creates a new {@link FcmOptions.Builder}.
45+
*
46+
* @return An {@link FcmOptions.Builder} instance.
47+
*/
48+
publicstaticBuilderbuilder() {
49+
returnnewBuilder();
50+
}
51+
52+
publicstaticclassBuilder {
53+
54+
privateStringanalyticsLabel;
55+
56+
privateBuilder() {}
57+
58+
/**
59+
* @param analyticsLabel A string representing the analytics label used for messages where no
60+
* platform-specific analytics label has been specified.
61+
* @return This builder
62+
*/
63+
publicBuildersetAnalyticsLabel(StringanalyticsLabel) {
64+
this.analyticsLabel =analyticsLabel;
65+
returnthis;
66+
}
67+
68+
/**
69+
* Creates a new {@link FcmOptions} instance from the parameters set on this builder.
70+
*
71+
* @return A new {@link FcmOptions} instance.
72+
* @throws IllegalArgumentException If any of the parameters set on the builder are invalid.
73+
*/
74+
publicFcmOptionsbuild() {
75+
returnnewFcmOptions(this);
76+
}
77+
}
78+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
packagecom.google.firebase.messaging;
16+
17+
importstaticcom.google.common.base.Preconditions.checkArgument;
18+
19+
importjava.util.regex.Pattern;
20+
21+
finalclassFcmOptionsUtil {
22+
23+
/**
24+
* Pattern matching a valid analytics labels.
25+
*/
26+
privatestaticfinalPatternANALYTICS_LABEL_REGEX =Pattern.compile("^[a-zA-Z0-9-_.~%]{0,50}$");
27+
28+
/**
29+
* Returns false if the supplied {@code analyticsLabel} has a disallowed format.
30+
*/
31+
privatestaticbooleanisValid(StringanalyticsLabel) {
32+
returnANALYTICS_LABEL_REGEX.matcher(analyticsLabel).matches();
33+
}
34+
35+
/**
36+
* Validates the format of the supplied label.
37+
*
38+
* @throws IllegalArgumentException If the label is non-null and has a disallowed format.
39+
*/
40+
staticvoidcheckAnalyticsLabel(StringanalyticsLabel) {
41+
checkArgument(
42+
analyticsLabel ==null ||isValid(analyticsLabel),
43+
"Analytics label must have format matching'^[a-zA-Z0-9-_.~%]{1,50}$");
44+
}
45+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp