]> iEval git - fonbot.git/blobdiff - src/ro/ieval/fonbot/PollServerAsyncTask.java
Upgrade to the latest server protocol.
[fonbot.git] / src / ro / ieval / fonbot / PollServerAsyncTask.java
index 7e95303090df4f2a6cfc5d58006d211cd0d222c9..15bf9cc093e6a0932b1bb568d38b2a2c25d074b0 100644 (file)
@@ -15,7 +15,10 @@ import org.json.JSONException;
 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;
 
 /*
@@ -76,14 +79,33 @@ public final class PollServerAsyncTask extends AsyncTask<Void, Void, List<PollSe
                }
        }
 
+       /** Context instance */
+       private final Context context;
+
+       /**
+        * Constructs a PollServerAsyncTask.
+        *
+        * @param context Context instance
+        */
+       public PollServerAsyncTask(final Context context) {
+               this.context=context;
+       }
+
        @Override
        protected List<Command> doInBackground(final @Nullable Void... params) {
                Log.d(getClass().getName(), "Polling server");
                final List<Command> commands=new ArrayList<Command>(10);
                try {
-                       final URL url=new URL("http://ieval.ro:7777/get");
+                       final URL url=Utils.getServerURL(toNonNull(context),"/get");
                        final HttpURLConnection conn=(HttpURLConnection) url.openConnection();
                        conn.setRequestProperty("X-ID", FonBotApplication.instance.regID);
+                       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());
This page took 0.02382 seconds and 4 git commands to generate.