OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.browser.services.gcm; |
| 6 |
| 7 import android.annotation.TargetApi; |
| 8 import android.app.job.JobParameters; |
| 9 import android.app.job.JobService; |
| 10 import android.os.Build; |
| 11 import android.os.PersistableBundle; |
| 12 |
| 13 import org.chromium.base.Log; |
| 14 import org.chromium.components.gcm_driver.GCMMessage; |
| 15 |
| 16 /** |
| 17 * Processes jobs that have been scheduled for delivering GCM messages to the na
tive GCM Driver, |
| 18 * processing for which may exceed the lifetime of the GcmListenerService. |
| 19 */ |
| 20 @TargetApi(Build.VERSION_CODES.N) |
| 21 public class GCMJobService extends JobService { |
| 22 private static final String TAG = "GCMJobService"; |
| 23 |
| 24 /** |
| 25 * Called when a GCM message is ready to be delivered to the GCM Driver cons
umer. |
| 26 * |
| 27 * @param params The parameters that define the job that is to be started. |
| 28 * @return True if the service has remaining asynchronous work and will use
{@link #jobFinished} |
| 29 * when done. (So the system will hold a wakelock.) False otherwise. |
| 30 */ |
| 31 @Override |
| 32 public boolean onStartJob(JobParameters params) { |
| 33 PersistableBundle extras = params.getExtras(); |
| 34 if (!GCMMessage.validatePersistableBundle(extras)) { |
| 35 Log.e(TAG, "The received bundle containing message data could not be
validated."); |
| 36 return false; |
| 37 } |
| 38 |
| 39 ChromeGcmListenerService.dispatchMessageToDriver(this, new GCMMessage(pa
rams.getExtras())); |
| 40 return false; |
| 41 } |
| 42 |
| 43 /** |
| 44 * Called when the system has determined that processing the GCM message mus
t be stopped. |
| 45 * |
| 46 * @param params The parameters that define the job that is to be stopped. |
| 47 * @return True if the job has finished and the wakelock is ready to be rele
ased. False if there |
| 48 * is remaining (asynchronous) work to be done. |
| 49 */ |
| 50 @Override |
| 51 public boolean onStopJob(JobParameters params) { |
| 52 // The GCM Driver has no mechanism for aborting previously dispatched me
ssages. |
| 53 return false; |
| 54 } |
| 55 } |
OLD | NEW |