Skip to content

Move firebase messaging and directboot to github #1792

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 1 commit into from
Jul 21, 2020
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
27 changes: 27 additions & 0 deletions firebase-messaging-directboot/api.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Signature format: 2.0
package com.google.firebase.messaging.directboot.threads {

public interface ExecutorFactory {
method public void executeOneOff(String, String, com.google.firebase.messaging.directboot.threads.ThreadPriority, Runnable);
method public java.util.concurrent.ScheduledExecutorService newScheduledThreadPool(int, com.google.firebase.messaging.directboot.threads.ThreadPriority);
method public java.util.concurrent.ScheduledExecutorService newScheduledThreadPool(int, java.util.concurrent.ThreadFactory, com.google.firebase.messaging.directboot.threads.ThreadPriority);
method public java.util.concurrent.ExecutorService newSingleThreadExecutor(com.google.firebase.messaging.directboot.threads.ThreadPriority);
method public java.util.concurrent.ExecutorService newSingleThreadExecutor(java.util.concurrent.ThreadFactory, com.google.firebase.messaging.directboot.threads.ThreadPriority);
method public java.util.concurrent.ExecutorService newThreadPool(com.google.firebase.messaging.directboot.threads.ThreadPriority);
method public java.util.concurrent.ExecutorService newThreadPool(java.util.concurrent.ThreadFactory, com.google.firebase.messaging.directboot.threads.ThreadPriority);
method public java.util.concurrent.ExecutorService newThreadPool(int, com.google.firebase.messaging.directboot.threads.ThreadPriority);
method public java.util.concurrent.ExecutorService newThreadPool(int, java.util.concurrent.ThreadFactory, com.google.firebase.messaging.directboot.threads.ThreadPriority);
method public java.util.concurrent.Future<?> submitOneOff(String, String, com.google.firebase.messaging.directboot.threads.ThreadPriority, Runnable);
}

public class PoolableExecutors {
method public static com.google.firebase.messaging.directboot.threads.ExecutorFactory factory();
}

public enum ThreadPriority {
enum_constant public static final com.google.firebase.messaging.directboot.threads.ThreadPriority HIGH_SPEED;
enum_constant public static final com.google.firebase.messaging.directboot.threads.ThreadPriority LOW_POWER;
}

}

71 changes: 71 additions & 0 deletions firebase-messaging-directboot/firebase-messaging-directboot.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

plugins {
id 'firebase-library'
}

firebaseLibrary {
testLab.enabled = false
}

android {
adbOptions {
timeOutInMs 60 * 1000
}

lintOptions {
abortOnError false
}

compileSdkVersion project.targetSdkVersion
defaultConfig {
minSdkVersion 16
targetSdkVersion project.targetSdkVersion
versionName version

multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
implementation project(':firebase-common')
implementation project(':firebase-components')
implementation project(':firebase-installations-interop')
implementation project(':firebase-datatransport')
implementation project(':transport:transport-api')
implementation project(':transport:transport-runtime')
implementation project(':transport:transport-backend-cct')
implementation project(':encoders:firebase-encoders-json')

implementation 'androidx.annotation:annotation:1.1.0'
implementation "com.google.android.gms:play-services-tasks:17.0.2"
implementation "com.google.android.gms:play-services-basement:17.2.1"
implementation 'com.google.android.gms:play-services-base:17.2.1'
implementation ("com.google.firebase:firebase-iid:20.2.3") {
exclude group: "com.google.firebase", module: "firebase-common"
exclude group: "com.google.firebase", module: "firebase-components"
exclude group: "com.google.firebase", module: "firebase-installations-interop"
}
implementation 'com.google.firebase:firebase-measurement-connector:18.0.0'
implementation "com.google.firebase:firebase-iid-interop:17.0.0"
implementation ("com.google.api-client:google-api-client:1.30.9") {
exclude group: "org.apache.httpcomponents", module: "httpclient"
}
}
3 changes: 3 additions & 0 deletions firebase-messaging-directboot/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
version=20.2.1
latestReleasedVersion=20.2.0
android.enableUnitTestBinaryResources=true
37 changes: 37 additions & 0 deletions firebase-messaging-directboot/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2012 The Android Open Source Project

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.firebase.messaging.directboot">
<uses-sdk android:minSdkVersion="16"/>

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

<application>

<receiver
android:name="com.google.firebase.messaging.directboot.FirebaseMessagingDirectBootReceiver"
android:directBootAware="true"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.firebase.messaging.RECEIVE_DIRECT_BOOT" />
</intent-filter>
</receiver>

</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.firebase.messaging.directboot;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import androidx.legacy.content.WakefulBroadcastReceiver;
import com.google.android.gms.common.util.concurrent.NamedThreadFactory;
import com.google.firebase.iid.FcmBroadcastProcessor;
import com.google.firebase.iid.ServiceStarter;
import com.google.firebase.messaging.directboot.threads.PoolableExecutors;
import com.google.firebase.messaging.directboot.threads.ThreadPriority;
import java.util.concurrent.ExecutorService;

/**
* WakefulBroadcastReceiver that receives FirebaseMessaging events and delivers them to the
* application-specific {@link com.google.firebase.iid.FirebaseInstanceIdService} subclass in direct
* boot mode.
*
* <p>This receiver is automatically added to your application's manifest file via manifest merge.
* If necessary it can be manually declared via:
*
* <pre>
* {@literal
* <receiver
* android:name="com.google.firebase.messaging.directboot.FirebaseMessagingDirectBootReceiver"
* android:directBootAware="true"
* android:exported="true"
* android:permission="com.google.android.c2dm.permission.SEND" >
* <intent-filter>
* <action android:name="com.google.firebase.messaging.RECEIVE_DIRECT_BOOT" />
* </intent-filter>
* </receiver>}</pre>
*
* <p>The {@code com.google.android.c2dm.permission.SEND} permission is held by Google Play
* services. This prevents other apps from invoking the broadcast receiver.
*
* @hide
*/
public final class FirebaseMessagingDirectBootReceiver extends WakefulBroadcastReceiver {

/** TAG for log statements coming from FCM */
static final String TAG = "FCM";

/** Action for FCM direct boot message intents */
private static final String ACTION_DIRECT_BOOT_REMOTE_INTENT =
"com.google.firebase.messaging.RECEIVE_DIRECT_BOOT";

/** All broadcasts get processed on this executor. */
private final ExecutorService processorExecutor =
PoolableExecutors.factory()
.newSingleThreadExecutor(
new NamedThreadFactory("fcm-db-intent-handle"), ThreadPriority.LOW_POWER);

@Override
public void onReceive(Context context, Intent intent) {
if (intent == null) {
return;
}
if (!ACTION_DIRECT_BOOT_REMOTE_INTENT.equals(intent.getAction())) {
Log.d(TAG, "Unexpected intent: " + intent.getAction());
return;
}

// Just pass the intent to the service mostly unchanged.
// Clear the component and ensure package name is set so that the standard dispatching
// mechanism will find the right service in the app.
intent.setComponent(null);
intent.setPackage(context.getPackageName());

// We don't actually want to process this broadcast on the main thread, so we're going to use
// goAsync to deal with this in the background. Unfortunately, we need to check whether the
// broadcast was ordered (and thus needs a result) before calling goAsync, because once we've
// called goAsync then isOrderedBroadcast will always return false.
boolean needsResult = isOrderedBroadcast();
PendingResult pendingBroadcastResult = goAsync();

new FcmBroadcastProcessor(context, processorExecutor)
.process(intent)
.addOnCompleteListener(
processorExecutor,
resultCodeTask -> {
// If we call setResultCode on a non-ordered broadcast it'll throw, so only set the
// result if the broadcast was ordered
if (needsResult) {
pendingBroadcastResult.setResultCode(
resultCodeTask.isSuccessful()
? resultCodeTask.getResult()
: ServiceStarter.ERROR_UNKNOWN);
}
pendingBroadcastResult.finish();
});
}
}
Loading