/* * Copyright 2014-2015 GameUp * * 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 io.gameup.android.push; import android.app.IntentService; import android.content.Intent; /** * This {@code IntentService} does the actual handling of the GCM message. * {@code GcmBroadcastReceiver} (a {@code WakefulBroadcastReceiver}) holds a * partial wake lock for this service while the service does its work. When the * service is finished, it calls {@code completeWakefulIntent()} to release the * wake lock. */ public class GcmIntentService extends IntentService { private static final String GCM_RECIEVE = "com.google.android.c2dm.intent.RECEIVE"; private static final String GCM_TYPE = "gcm"; public GcmIntentService() { super("GcmIntentService"); } // Only react to incoming GCM messages. private static boolean isGcmMessage(final Intent intent) { if (GCM_RECIEVE.equals(intent.getAction())) { final String messageType = intent.getStringExtra("message_type"); return (messageType == null || GCM_TYPE.equals(messageType)); } return false; } @Override protected void onHandleIntent(final Intent intent) { if (isGcmMessage(intent)) { NotificationBundleProcessor.process(this, intent.getExtras()); } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); } }