]> iEval git - fonbot.git/blobdiff - src/ro/ieval/fonbot/PollServerAsyncTask.java
Remove the global FonBotApplication instance.
[fonbot.git] / src / ro / ieval / fonbot / PollServerAsyncTask.java
index 2a4a21d60fe73661bdc9b652f3647eb4a7d791bd..1be09c36a1730857fc4c1749daf2127090ae5f51 100644 (file)
@@ -17,8 +17,12 @@ import org.json.JSONObject;
 import ro.ieval.fonbot.Address.Protocol;
 import android.content.Context;
 import android.os.AsyncTask;
+import android.preference.PreferenceManager;
+import android.util.Base64;
 import android.util.Log;
 
+import com.google.android.gcm.GCMRegistrar;
+
 /*
  * Copyright © 2013 Marius Gavrilescu
  * 
@@ -96,7 +100,14 @@ public final class PollServerAsyncTask extends AsyncTask<Void, Void, List<PollSe
                try {
                        final URL url=Utils.getServerURL(toNonNull(context),"/get");
                        final HttpURLConnection conn=(HttpURLConnection) url.openConnection();
-                       conn.setRequestProperty("X-ID", FonBotApplication.instance.regID);
+                       conn.setRequestProperty("X-ID", GCMRegistrar.getRegistrationId(context));
+                       final String user=PreferenceManager.getDefaultSharedPreferences(context).getString("username", null);
+                       final String password=PreferenceManager.getDefaultSharedPreferences(context).getString("password", null);
+                       if(user == null || password == null)
+                               return commands;
+
+                       conn.setRequestProperty("Authorization", "Basic "+Base64.encodeToString(
+                                       (user+':'+password).getBytes(), Base64.NO_WRAP));
                        conn.connect();
                        final byte[] buf=new byte[4096*1024];
                        Log.d(getClass().getName(), "Server poll got response code "+conn.getResponseCode()+" and message "+conn.getResponseMessage());
@@ -137,7 +148,7 @@ public final class PollServerAsyncTask extends AsyncTask<Void, Void, List<PollSe
                        Log.d(getClass().getName(), "Poll got command "+command.command+" with "+((command.args.length==0)?"no args":"args "+Utils.join(
                                        " ",toNonNull(command.args))));
                        Utils.processCommand(
-                                       toNonNull(FonBotApplication.instance),
+                                       toNonNull(context),
                                        toNonNull(command.command),
                                        toNonNull(command.args),
                                        new Address(toNonNull(Protocol.HTTP), command.replyto));//NOPMD address depends on command
This page took 0.025921 seconds and 4 git commands to generate.