-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run Notification Processing via JobScheduler API (#946)
* run notification processing via job scheduler * lint
- Loading branch information
1 parent
71e40ff
commit ac96cae
Showing
7 changed files
with
79 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 4 additions & 10 deletions
14
android/src/main/java/com/thebluealliance/androidclient/gcm/GCMBroadcastReceiver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,16 @@ | ||
package com.thebluealliance.androidclient.gcm; | ||
|
||
import android.app.Activity; | ||
import android.content.ComponentName; | ||
import android.content.BroadcastReceiver; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import androidx.legacy.content.WakefulBroadcastReceiver; | ||
|
||
import com.thebluealliance.androidclient.TbaLogger; | ||
|
||
public class GCMBroadcastReceiver extends WakefulBroadcastReceiver { | ||
public class GCMBroadcastReceiver extends BroadcastReceiver { | ||
|
||
@Override | ||
public void onReceive(Context context, Intent intent) { | ||
TbaLogger.d("Got GCM Message. " + intent); | ||
// Explicitly specify that GcmIntentService will handle the intent. | ||
ComponentName comp = new ComponentName(context.getPackageName(), | ||
GCMMessageHandler.class.getName()); | ||
// Start the service, keeping the device awake while it is launching. | ||
startWakefulService(context, intent.setComponent(comp)); | ||
setResultCode(Activity.RESULT_OK); | ||
GCMMessageHandler.enqueueWork(context, intent); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
android/src/test/java/com/thebluealliance/androidclient/gcm/TestGCMBroadcastReceiver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.thebluealliance.androidclient.gcm; | ||
|
||
import android.app.job.JobInfo; | ||
import android.app.job.JobScheduler; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
|
||
import com.google.gson.JsonObject; | ||
import com.thebluealliance.androidclient.datafeed.framework.ModelMaker; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import androidx.test.core.app.ApplicationProvider; | ||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
public class TestGCMBroadcastReceiver { | ||
|
||
private Context mApplicationContext; | ||
private JobScheduler mJobScheduler; | ||
|
||
@Before | ||
public void setUp() { | ||
mApplicationContext = ApplicationProvider.getApplicationContext(); | ||
mJobScheduler = (JobScheduler) mApplicationContext.getSystemService(Context.JOB_SCHEDULER_SERVICE); | ||
} | ||
|
||
@Test | ||
public void testSchedulesJob() { | ||
Intent intent = buildIntent(); | ||
mApplicationContext.sendBroadcast(intent); | ||
|
||
@Nullable JobInfo job = mJobScheduler.getPendingJob(GCMMessageHandler.JOB_ID); | ||
assertNotNull(job); | ||
} | ||
|
||
private Intent buildIntent() { | ||
JsonObject notificationData = ModelMaker.getModel(JsonObject.class, "notification_upcoming_match"); | ||
Intent intent = new Intent("com.google.android.c2dm.intent.RECEIVE"); | ||
intent.putExtra("notification_type", "upcoming_match"); | ||
intent.putExtra("message_data", notificationData.toString()); | ||
return intent; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters