<commit_before>package de.bitdroid.flooding.ods;

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

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

import de.bitdroid.flooding.utils.Log;


public final class GcmBroadcastReceiver extends BroadcastReceiver {

	private final static String 
		DATA_KEY_SOURCE = "source",
		DATA_KEY_DEBUG = "debug";


	@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)) {
				String debug = intent.getStringExtra(DATA_KEY_DEBUG);
				if (debug != null && !debug.equals("") && Boolean.valueOf(debug)) {
					handleDebug(context, intent);
				}
			}

		} finally {
			wl.release();
		}
	}


	private void handleDebug(Context context, Intent intent) {
		StringBuilder builder = new StringBuilder();
		builder.append("Push Notification received: \n\n");

		Bundle extras = intent.getExtras();<commit_msg>ods: GcmBroadcastReceiver triggers sync on msg receive<commit_after>package de.bitdroid.flooding.ods;

import java.util.Set;

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

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

import de.bitdroid.flooding.utils.Log;


public final class GcmBroadcastReceiver extends BroadcastReceiver {

	private final static String 
		DATA_KEY_SOURCE = "source",
		DATA_KEY_DEBUG = "debug";


	@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)) {

				// sync sources
				String sourceString = intent.getStringExtra(DATA_KEY_SOURCE);
				if (sourceString != null) {
					OdsSourceManager manager = OdsSourceManager.getInstance(context);
					Set<OdsSource> sources = manager.getPushNotificationSources();
					for (OdsSource source : sources) {
						if (!source.getSourceId().equals(sourceString)) continue;
						manager.startManualSync(source);
					}
				}


				// debug output
				String debug = intent.getStringExtra(DATA_KEY_DEBUG);
				if (debug != null && !debug.equals("") && Boolean.valueOf(debug)) {
					handleDebug(context, intent);
				}
			}

		} finally {
			wl.release();
		}
	}


	private void handleDebug(Context context, Intent intent) {
		StringBuilder builder = new StringBuilder();
		builder.append("Push Notification received: \n\n");

		Bundle extras = intent.getExtras();
{'fraction_non_alphanumeric': 0.10781841109709962, 'fraction_numerical': 0.0, 'mean_word_length': 4.706834532374101, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '526940', 'n_tokens_mistral': 1078, 'n_tokens_neox': 930, 'n_words': 195}