Skip to content

Commit fdac4d0

Browse files
authored
Make FirebaseMessagingServices not exported (#850)
* Set FirebaseMessagingServices to exported="false" to explicitly prevent other apps from being able to send messages to it. * Fixed documentation to indicate to remove the Kotlin service intent filter for Java now that the Kotlin service is first in the manifest.
2 parents d307afe + e41f039 commit fdac4d0

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

messaging/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ However, there can only be one service in each app that receives FCM
2222
messages. If multiple are declared in the Manifest then the first
2323
one will be chosen.
2424

25-
In order to make the Kotlin messaging sample functional, you must
26-
remove the following from the `.java.MyFirebaseMessagingService` entry
25+
In order to make the Java messaging sample functional, you must
26+
remove the following from the `.kotlin.MyFirebaseMessagingService` entry
2727
in the `AndroidManifest.xml`:
2828

2929
```

messaging/app/src/main/AndroidManifest.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,18 @@
3838
<activity android:name=".kotlin.MainActivity" />
3939
<activity android:name=".java.MainActivity" />
4040

41-
<service android:name=".kotlin.MyFirebaseMessagingService">
41+
<service
42+
android:name=".kotlin.MyFirebaseMessagingService"
43+
android:exported="false">
4244
<intent-filter>
4345
<action android:name="com.google.firebase.MESSAGING_EVENT" />
4446
</intent-filter>
4547
</service>
4648

4749
<!-- [START firebase_service] -->
48-
<service android:name=".java.MyFirebaseMessagingService">
50+
<service
51+
android:name=".java.MyFirebaseMessagingService"
52+
android:exported="false">
4953
<intent-filter>
5054
<action android:name="com.google.firebase.MESSAGING_EVENT" />
5155
</intent-filter>

messaging/app/src/main/java/com/google/firebase/quickstart/fcm/java/MyFirebaseMessagingService.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@
3434
import androidx.work.OneTimeWorkRequest;
3535
import androidx.work.WorkManager;
3636

37+
/**
38+
* NOTE: There can only be one service in each app that receives FCM messages. If multiple
39+
* are declared in the Manifest then the first one will be chosen.
40+
*
41+
* In order to make this Java sample functional, you must remove the following from the Kotlin messaging
42+
* service in the AndroidManifest.xml:
43+
*
44+
* <intent-filter>
45+
* <action android:name="com.google.firebase.MESSAGING_EVENT" />
46+
* </intent-filter>
47+
*/
3748
public class MyFirebaseMessagingService extends FirebaseMessagingService {
3849

3950
private static final String TAG = "MyFirebaseMsgService";

messaging/app/src/main/java/com/google/firebase/quickstart/fcm/kotlin/MyFirebaseMessagingService.kt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,6 @@ import com.google.firebase.messaging.FirebaseMessagingService
1515
import com.google.firebase.messaging.RemoteMessage
1616
import com.google.firebase.quickstart.fcm.R
1717

18-
/**
19-
* NOTE: There can only be one service in each app that receives FCM messages. If multiple
20-
* are declared in the Manifest then the first one will be chosen.
21-
*
22-
* In order to make this Kotlin sample functional, you must remove the following from the Java messaging
23-
* service in the AndroidManifest.xml:
24-
*
25-
* <intent-filter>
26-
* <action android:name="com.google.firebase.MESSAGING_EVENT" />
27-
* </intent-filter>
28-
*/
2918
class MyFirebaseMessagingService : FirebaseMessagingService() {
3019

3120
/**

0 commit comments

Comments
 (0)