Skip to content

Commit fe51be9

Browse files
authored
update messaging (#1792)
1 parent 3f4b32d commit fe51be9

File tree

80 files changed

+15692
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+15692
-0
lines changed

firebase-messaging-directboot/api.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Signature format: 2.0
2+
package com.google.firebase.messaging.directboot.threads {
3+
4+
public interface ExecutorFactory {
5+
method public void executeOneOff(String, String, com.google.firebase.messaging.directboot.threads.ThreadPriority, Runnable);
6+
method public java.util.concurrent.ScheduledExecutorService newScheduledThreadPool(int, com.google.firebase.messaging.directboot.threads.ThreadPriority);
7+
method public java.util.concurrent.ScheduledExecutorService newScheduledThreadPool(int, java.util.concurrent.ThreadFactory, com.google.firebase.messaging.directboot.threads.ThreadPriority);
8+
method public java.util.concurrent.ExecutorService newSingleThreadExecutor(com.google.firebase.messaging.directboot.threads.ThreadPriority);
9+
method public java.util.concurrent.ExecutorService newSingleThreadExecutor(java.util.concurrent.ThreadFactory, com.google.firebase.messaging.directboot.threads.ThreadPriority);
10+
method public java.util.concurrent.ExecutorService newThreadPool(com.google.firebase.messaging.directboot.threads.ThreadPriority);
11+
method public java.util.concurrent.ExecutorService newThreadPool(java.util.concurrent.ThreadFactory, com.google.firebase.messaging.directboot.threads.ThreadPriority);
12+
method public java.util.concurrent.ExecutorService newThreadPool(int, com.google.firebase.messaging.directboot.threads.ThreadPriority);
13+
method public java.util.concurrent.ExecutorService newThreadPool(int, java.util.concurrent.ThreadFactory, com.google.firebase.messaging.directboot.threads.ThreadPriority);
14+
method public java.util.concurrent.Future<?> submitOneOff(String, String, com.google.firebase.messaging.directboot.threads.ThreadPriority, Runnable);
15+
}
16+
17+
public class PoolableExecutors {
18+
method public static com.google.firebase.messaging.directboot.threads.ExecutorFactory factory();
19+
}
20+
21+
public enum ThreadPriority {
22+
enum_constant public static final com.google.firebase.messaging.directboot.threads.ThreadPriority HIGH_SPEED;
23+
enum_constant public static final com.google.firebase.messaging.directboot.threads.ThreadPriority LOW_POWER;
24+
}
25+
26+
}
27+
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
plugins {
16+
id 'firebase-library'
17+
}
18+
19+
firebaseLibrary {
20+
testLab.enabled = false
21+
}
22+
23+
android {
24+
adbOptions {
25+
timeOutInMs 60 * 1000
26+
}
27+
28+
lintOptions {
29+
abortOnError false
30+
}
31+
32+
compileSdkVersion project.targetSdkVersion
33+
defaultConfig {
34+
minSdkVersion 16
35+
targetSdkVersion project.targetSdkVersion
36+
versionName version
37+
38+
multiDexEnabled true
39+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
40+
}
41+
compileOptions {
42+
sourceCompatibility JavaVersion.VERSION_1_8
43+
targetCompatibility JavaVersion.VERSION_1_8
44+
}
45+
}
46+
47+
dependencies {
48+
implementation project(':firebase-common')
49+
implementation project(':firebase-components')
50+
implementation project(':firebase-installations-interop')
51+
implementation project(':firebase-datatransport')
52+
implementation project(':transport:transport-api')
53+
implementation project(':transport:transport-runtime')
54+
implementation project(':transport:transport-backend-cct')
55+
implementation project(':encoders:firebase-encoders-json')
56+
57+
implementation 'androidx.annotation:annotation:1.1.0'
58+
implementation "com.google.android.gms:play-services-tasks:17.0.2"
59+
implementation "com.google.android.gms:play-services-basement:17.2.1"
60+
implementation 'com.google.android.gms:play-services-base:17.2.1'
61+
implementation ("com.google.firebase:firebase-iid:20.2.3") {
62+
exclude group: "com.google.firebase", module: "firebase-common"
63+
exclude group: "com.google.firebase", module: "firebase-components"
64+
exclude group: "com.google.firebase", module: "firebase-installations-interop"
65+
}
66+
implementation 'com.google.firebase:firebase-measurement-connector:18.0.0'
67+
implementation "com.google.firebase:firebase-iid-interop:17.0.0"
68+
implementation ("com.google.api-client:google-api-client:1.30.9") {
69+
exclude group: "org.apache.httpcomponents", module: "httpclient"
70+
}
71+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version=20.2.1
2+
latestReleasedVersion=20.2.0
3+
android.enableUnitTestBinaryResources=true
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright (C) 2012 The Android Open Source Project
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
17+
package="com.google.firebase.messaging.directboot">
18+
<uses-sdk android:minSdkVersion="16"/>
19+
20+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
21+
<uses-permission android:name="android.permission.INTERNET" />
22+
<uses-permission android:name="android.permission.WAKE_LOCK" />
23+
24+
<application>
25+
26+
<receiver
27+
android:name="com.google.firebase.messaging.directboot.FirebaseMessagingDirectBootReceiver"
28+
android:directBootAware="true"
29+
android:exported="true"
30+
android:permission="com.google.android.c2dm.permission.SEND" >
31+
<intent-filter>
32+
<action android:name="com.google.firebase.messaging.RECEIVE_DIRECT_BOOT" />
33+
</intent-filter>
34+
</receiver>
35+
36+
</application>
37+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
package com.google.firebase.messaging.directboot;
15+
16+
import android.content.Context;
17+
import android.content.Intent;
18+
import android.util.Log;
19+
import androidx.legacy.content.WakefulBroadcastReceiver;
20+
import com.google.android.gms.common.util.concurrent.NamedThreadFactory;
21+
import com.google.firebase.iid.FcmBroadcastProcessor;
22+
import com.google.firebase.iid.ServiceStarter;
23+
import com.google.firebase.messaging.directboot.threads.PoolableExecutors;
24+
import com.google.firebase.messaging.directboot.threads.ThreadPriority;
25+
import java.util.concurrent.ExecutorService;
26+
27+
/**
28+
* WakefulBroadcastReceiver that receives FirebaseMessaging events and delivers them to the
29+
* application-specific {@link com.google.firebase.iid.FirebaseInstanceIdService} subclass in direct
30+
* boot mode.
31+
*
32+
* <p>This receiver is automatically added to your application's manifest file via manifest merge.
33+
* If necessary it can be manually declared via:
34+
*
35+
* <pre>
36+
* {@literal
37+
* <receiver
38+
* android:name="com.google.firebase.messaging.directboot.FirebaseMessagingDirectBootReceiver"
39+
* android:directBootAware="true"
40+
* android:exported="true"
41+
* android:permission="com.google.android.c2dm.permission.SEND" >
42+
* <intent-filter>
43+
* <action android:name="com.google.firebase.messaging.RECEIVE_DIRECT_BOOT" />
44+
* </intent-filter>
45+
* </receiver>}</pre>
46+
*
47+
* <p>The {@code com.google.android.c2dm.permission.SEND} permission is held by Google Play
48+
* services. This prevents other apps from invoking the broadcast receiver.
49+
*
50+
* @hide
51+
*/
52+
public final class FirebaseMessagingDirectBootReceiver extends WakefulBroadcastReceiver {
53+
54+
/** TAG for log statements coming from FCM */
55+
static final String TAG = "FCM";
56+
57+
/** Action for FCM direct boot message intents */
58+
private static final String ACTION_DIRECT_BOOT_REMOTE_INTENT =
59+
"com.google.firebase.messaging.RECEIVE_DIRECT_BOOT";
60+
61+
/** All broadcasts get processed on this executor. */
62+
private final ExecutorService processorExecutor =
63+
PoolableExecutors.factory()
64+
.newSingleThreadExecutor(
65+
new NamedThreadFactory("fcm-db-intent-handle"), ThreadPriority.LOW_POWER);
66+
67+
@Override
68+
public void onReceive(Context context, Intent intent) {
69+
if (intent == null) {
70+
return;
71+
}
72+
if (!ACTION_DIRECT_BOOT_REMOTE_INTENT.equals(intent.getAction())) {
73+
Log.d(TAG, "Unexpected intent: " + intent.getAction());
74+
return;
75+
}
76+
77+
// Just pass the intent to the service mostly unchanged.
78+
// Clear the component and ensure package name is set so that the standard dispatching
79+
// mechanism will find the right service in the app.
80+
intent.setComponent(null);
81+
intent.setPackage(context.getPackageName());
82+
83+
// We don't actually want to process this broadcast on the main thread, so we're going to use
84+
// goAsync to deal with this in the background. Unfortunately, we need to check whether the
85+
// broadcast was ordered (and thus needs a result) before calling goAsync, because once we've
86+
// called goAsync then isOrderedBroadcast will always return false.
87+
boolean needsResult = isOrderedBroadcast();
88+
PendingResult pendingBroadcastResult = goAsync();
89+
90+
new FcmBroadcastProcessor(context, processorExecutor)
91+
.process(intent)
92+
.addOnCompleteListener(
93+
processorExecutor,
94+
resultCodeTask -> {
95+
// If we call setResultCode on a non-ordered broadcast it'll throw, so only set the
96+
// result if the broadcast was ordered
97+
if (needsResult) {
98+
pendingBroadcastResult.setResultCode(
99+
resultCodeTask.isSuccessful()
100+
? resultCodeTask.getResult()
101+
: ServiceStarter.ERROR_UNKNOWN);
102+
}
103+
pendingBroadcastResult.finish();
104+
});
105+
}
106+
}

0 commit comments

Comments
 (0)