// Path: org.hive2hive.mobile/app/src/main/java/org/hive2hive/mobile/H2HApplication.java
// public class H2HApplication extends Application implements IPeerHolder {
// 
// 	private BufferRequestListener bufferListener;
// 	private IH2HNode h2hNode;
// 	private RelayMode relayMode;
// 	private INetworkConfiguration networkConfig;
// 	private AndroidFile treeRoot;
// 	private ConnectionMode lastMode;
// 	private String userId;
// 
// 	@Override
// 	public void onCreate() {
// 		super.onCreate();
// 
// 		// Prevent using IPv6, prefer IPv4
// 		System.setProperty("java.net.preferIPv4Stack", "true");
// 
// 		lastMode = ApplicationHelper.getConnectionMode(this);
// 
// //		ConnectionChangeListener connectionChangeListener = new ConnectionChangeListener(this);
// //		IntentFilter filter = new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE");
// //		registerReceiver(connectionChangeListener, filter);
// 
// 		// increase timeouts
// 		ConnectionBean.DEFAULT_CONNECTION_TIMEOUT_TCP = 20000;
// 		ConnectionBean.DEFAULT_TCP_IDLE_SECONDS = 12;
// 		ConnectionBean.DEFAULT_UDP_IDLE_SECONDS = 12;
// 	}
// 
// 	@Override
// 	protected void attachBaseContext(Context base) {
// 		super.attachBaseContext(base);
// 		// enable multidex
// //		MultiDex.install(this);
// 	}
// 
// 	/**
// 	 * Singleton-like application data that needs to be present in the whole application.
// 	 * Note that the content of this data is removed once the process is killed.
// 	 */
// 
// 	public void relayMode(RelayMode relayMode) {
// 		this.relayMode = relayMode;
// 	}
// 
// 	public RelayMode relayMode() {
// 		return relayMode;
// 	}
// 
// 	public void bufferListener(BufferRequestListener bufferListener) {
// 		this.bufferListener = bufferListener;
// 	}
// 
// 	public BufferRequestListener bufferListener() {
// 		return bufferListener;
// 	}
// 
// 	public void h2hNode(IH2HNode h2hNode) {
// 		this.h2hNode = h2hNode;
// 	}
// 
// 	public IH2HNode h2hNode() {
// 		return h2hNode;
// 	}
// 
// 	public void networkConfig(INetworkConfiguration networkConfig) {
// 		this.networkConfig = networkConfig;
// 	}
// 
// 	public INetworkConfiguration networkConfig() {
// 		return networkConfig;
// 	}
// 
// 
// 	public void logout() {
// 		treeRoot = null;
// 		userId = null;
// 	}
// 
// 	/**
// 	 * Holds the latest file list of the currently logged in user
// 	 *
// 	 * @param treeRoot
// 	 */
// 	public void currentTree(AndroidFile treeRoot) {
// 		this.treeRoot = treeRoot;
// 	}
// 
// 	/**
// 	 * @return the last file taste list or <code>null</code> if not fetched yet
// 	 */
// 	public AndroidFile currentTree() {
// 		return treeRoot;
// 	}
// 
// 	public void currentUser(String userId) {
// 		this.userId = userId;
// 	}
// 
// 	public String currentUser() {
// 		return userId;
// 	}
// 
// 	@Override
// 	public PeerDHT getPeer() {
// 		if (h2hNode == null) {
// 			return null;
// 		}
// 		return h2hNode.getPeer();
// 	}
// 
// 	/**
// 	 * @return the last connection mode
// 	 */
// 	public ConnectionMode lastMode() {
// 		return lastMode;
// 	}
// 
// 	/**
// 	 * Set the last mode in order to detect changes when the {@link org.hive2hive.mobile.connection.ConnectionChangeListener} is triggered
// 	 */
// 	public void lastMode(ConnectionMode lastMode) {
// 		this.lastMode = lastMode;
// 	}
// }


import android.app.IntentService;
import android.content.Intent;
import android.os.Bundle;
import com.google.android.gms.gcm.GoogleCloudMessaging;
import net.tomp2p.relay.buffer.BufferRequestListener;
import org.hive2hive.mobile.H2HApplication;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package org.hive2hive.mobile.gcm;





/**
 * Created by Nico Rutishauser on 08.09.14.
 * Handles incoming GCM messages
 */
public class GCMIntentService extends IntentService {

	private static final Logger LOG = LoggerFactory.getLogger(GCMIntentService.class);

	public GCMIntentService() {
		super("GCMIntentService");
	}

	@Override
	protected void onHandleIntent(Intent intent) {
		GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
		// the message type is in the intent
		String messageType = gcm.getMessageType(intent);

		Bundle extras = intent.getExtras();
		if (extras.isEmpty()) {
			LOG.warn("Received empty GCM message of type {}", messageType);
			return;
		}

		LOG.debug("Received message of type {} with extras {}", messageType, extras.toString());

// Path: org.hive2hive.mobile/app/src/main/java/org/hive2hive/mobile/H2HApplication.java
// public class H2HApplication extends Application implements IPeerHolder {
// 
// 	private BufferRequestListener bufferListener;
// 	private IH2HNode h2hNode;
// 	private RelayMode relayMode;
// 	private INetworkConfiguration networkConfig;
// 	private AndroidFile treeRoot;
// 	private ConnectionMode lastMode;
// 	private String userId;
// 
// 	@Override
// 	public void onCreate() {
// 		super.onCreate();
// 
// 		// Prevent using IPv6, prefer IPv4
// 		System.setProperty("java.net.preferIPv4Stack", "true");
// 
// 		lastMode = ApplicationHelper.getConnectionMode(this);
// 
// //		ConnectionChangeListener connectionChangeListener = new ConnectionChangeListener(this);
// //		IntentFilter filter = new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE");
// //		registerReceiver(connectionChangeListener, filter);
// 
// 		// increase timeouts
// 		ConnectionBean.DEFAULT_CONNECTION_TIMEOUT_TCP = 20000;
// 		ConnectionBean.DEFAULT_TCP_IDLE_SECONDS = 12;
// 		ConnectionBean.DEFAULT_UDP_IDLE_SECONDS = 12;
// 	}
// 
// 	@Override
// 	protected void attachBaseContext(Context base) {
// 		super.attachBaseContext(base);
// 		// enable multidex
// //		MultiDex.install(this);
// 	}
// 
// 	/**
// 	 * Singleton-like application data that needs to be present in the whole application.
// 	 * Note that the content of this data is removed once the process is killed.
// 	 */
// 
// 	public void relayMode(RelayMode relayMode) {
// 		this.relayMode = relayMode;
// 	}
// 
// 	public RelayMode relayMode() {
// 		return relayMode;
// 	}
// 
// 	public void bufferListener(BufferRequestListener bufferListener) {
// 		this.bufferListener = bufferListener;
// 	}
// 
// 	public BufferRequestListener bufferListener() {
// 		return bufferListener;
// 	}
// 
// 	public void h2hNode(IH2HNode h2hNode) {
// 		this.h2hNode = h2hNode;
// 	}
// 
// 	public IH2HNode h2hNode() {
// 		return h2hNode;
// 	}
// 
// 	public void networkConfig(INetworkConfiguration networkConfig) {
// 		this.networkConfig = networkConfig;
// 	}
// 
// 	public INetworkConfiguration networkConfig() {
// 		return networkConfig;
// 	}
// 
// 
// 	public void logout() {
// 		treeRoot = null;
// 		userId = null;
// 	}
// 
// 	/**
// 	 * Holds the latest file list of the currently logged in user
// 	 *
// 	 * @param treeRoot
// 	 */
// 	public void currentTree(AndroidFile treeRoot) {
// 		this.treeRoot = treeRoot;
// 	}
// 
// 	/**
// 	 * @return the last file taste list or <code>null</code> if not fetched yet
// 	 */
// 	public AndroidFile currentTree() {
// 		return treeRoot;
// 	}
// 
// 	public void currentUser(String userId) {
// 		this.userId = userId;
// 	}
// 
// 	public String currentUser() {
// 		return userId;
// 	}
// 
// 	@Override
// 	public PeerDHT getPeer() {
// 		if (h2hNode == null) {
// 			return null;
// 		}
// 		return h2hNode.getPeer();
// 	}
// 
// 	/**
// 	 * @return the last connection mode
// 	 */
// 	public ConnectionMode lastMode() {
// 		return lastMode;
// 	}
// 
// 	/**
// 	 * Set the last mode in order to detect changes when the {@link org.hive2hive.mobile.connection.ConnectionChangeListener} is triggered
// 	 */
// 	public void lastMode(ConnectionMode lastMode) {
// 		this.lastMode = lastMode;
// 	}
// }


// Path: org.hive2hive.mobile/app/src/main/java/org/hive2hive/mobile/gcm/GCMIntentService.java
import android.app.IntentService;
import android.content.Intent;
import android.os.Bundle;
import com.google.android.gms.gcm.GoogleCloudMessaging;
import net.tomp2p.relay.buffer.BufferRequestListener;
import org.hive2hive.mobile.H2HApplication;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

package org.hive2hive.mobile.gcm;





/**
 * Created by Nico Rutishauser on 08.09.14.
 * Handles incoming GCM messages
 */
public class GCMIntentService extends IntentService {

	private static final Logger LOG = LoggerFactory.getLogger(GCMIntentService.class);

	public GCMIntentService() {
		super("GCMIntentService");
	}

	@Override
	protected void onHandleIntent(Intent intent) {
		GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
		// the message type is in the intent
		String messageType = gcm.getMessageType(intent);

		Bundle extras = intent.getExtras();
		if (extras.isEmpty()) {
			LOG.warn("Received empty GCM message of type {}", messageType);
			return;
		}

		LOG.debug("Received message of type {} with extras {}", messageType, extras.toString());

		H2HApplication application = (H2HApplication) getApplicationContext();