Skip to content

Converted RegistrationIntentService to a JobIntentService #436

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 2 commits into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions messaging/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
</service>

<service android:name="com.google.firebase.messaging.cpp.RegistrationIntentService"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="false" >
</service>
</application>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ public final class JobIds {
private JobIds() {}

public static final int MESSAGE_FORWARDING_SERVICE = 1000;
public static final int REGISTRATION_INTENT_SERVICE = 1001;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

package com.google.firebase.messaging.cpp;

import android.app.IntentService;
import android.content.Context;
import android.content.Intent;
import com.google.firebase.iid.FirebaseInstanceId;
Expand All @@ -28,7 +27,7 @@
* A class that manages Registration Token generation and passes the generated tokens to the native
* OnTokenReceived function.
*/
public class RegistrationIntentService extends IntentService {
public class RegistrationIntentService extends JobIntentService {
private static final String TAG = "FirebaseRegService";

public RegistrationIntentService() {
Expand All @@ -37,11 +36,20 @@ public RegistrationIntentService() {
super(TAG);
}

/**
* Convenience wrapper over enqueueWork to either directly start the service (when running on
* pre-O platforms) or enqueue work for it as a job (when running on Android O and later).
*/
public static void enqueueWork(Context context, Intent intent) {
enqueueWork(
context, RegistrationIntentService.class, JobIds.REGISTRATION_INTENT_SERVICE, intent);
}

// Fetch the latest registration token and notify the C++ layer.
@Override
protected void onHandleIntent(Intent intent) {
protected void onHandleWork(@NonNull Intent intent) {
String token = FirebaseInstanceId.getInstance().getToken();
DebugLogging.log(TAG, String.format("onHandleIntent token=%s", token));
DebugLogging.log(TAG, String.format("onHandleWork token=%s", token));
if (token != null) {
writeTokenToInternalStorage(this, token);
}
Expand Down