package de.bitdroid.flooding.ods;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.PowerManager;

import com.google.android.gms.gcm.GoogleCloudMessaging;


public final class GcmBroadcastReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {

		PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
		PowerManager.WakeLock wl = null;
		try {
			wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "");
			wl.acquire();

			String messageType = GoogleCloudMessaging.getInstance(context).getMessageType(intent);

			if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
				// work
			}

		} finally {
			wl.release();
		}
	}
}

@@ -133,16 +133,42 @@
 Intent;%0A
+import android.os.Bundle;%0A
 import a
@@ -249,16 +249,56 @@
 aging;%0A%0A
+import de.bitdroid.flooding.utils.Log;%0A%0A
 %0Apublic 
@@ -359,16 +359,106 @@
 iver %7B%0A%0A
+%09private final static String %0A%09%09DATA_KEY_SOURCE = %22source%22,%0A%09%09DATA_KEY_DEBUG = %22debug%22;%0A%0A%0A
 %09@Overri
@@ -894,56 +894,603 @@
 %09%09%09%09
-// work%0A%09%09%09%7D%0A%0A%09%09%7D finally %7B%0A%09%09%09wl.release();%0A%09%09%7D
+String debug = intent.getStringExtra(DATA_KEY_DEBUG);%0A%09%09%09%09if (debug != null && !debug.equals(%22%22) && Boolean.valueOf(debug)) %7B%0A%09%09%09%09%09handleDebug(context, intent);%0A%09%09%09%09%09return;%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%0A%09%09%7D finally %7B%0A%09%09%09wl.release();%0A%09%09%7D%0A%09%7D%0A%0A%0A%09private void handleDebug(Context context, Intent intent) %7B%0A%09%09StringBuilder builder = new StringBuilder();%0A%09%09builder.append(%22Push Notification received: %5Cn%5Cn%22);%0A%0A%09%09Bundle extras = intent.getExtras();%0A%09%09for (String key : extras.keySet()) %7B%0A%09%09%09Object value = extras.get(key);%0A%09%09%09builder.append(key + %22:%5Ct%22 + value.toString() + %22%5Cn%22);%0A%09%09%7D%0A%0A%09%09Log.debug(builder.toString());
 %0A%09%7D%0A

handle gcm debug msg in GcmBroadcastReceiver