summaryrefslogtreecommitdiff
path: root/src/se/leap/leapclient/ProviderAPI.java
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2013-02-01 00:13:09 +0100
committerParménides GV <parmegv@sdf.org>2013-02-01 00:13:09 +0100
commit7b9e22e765a1e5eda05ad121684e63c20ff5f049 (patch)
tree48d8713ac48a309b356dcb9414a69a4af9ecf9e8 /src/se/leap/leapclient/ProviderAPI.java
parent92c32b0b96938009af55ed28920472f22a4614ee (diff)
I have a handshake failing within an HTTP connection in order to get the
eip-service.json file. provider.json downloads and parses itself OK to SharedPreferences. It also does not link OK to the Dashboard, I do not know how to do it properly and I'm so tired (eyes hurting). Beginning with security things :) Happy to have gotten around DownloadManager problem with a simple HTTP connection.
Diffstat (limited to 'src/se/leap/leapclient/ProviderAPI.java')
-rw-r--r--src/se/leap/leapclient/ProviderAPI.java64
1 files changed, 58 insertions, 6 deletions
diff --git a/src/se/leap/leapclient/ProviderAPI.java b/src/se/leap/leapclient/ProviderAPI.java
index 6d52e44f..aefb87fc 100644
--- a/src/se/leap/leapclient/ProviderAPI.java
+++ b/src/se/leap/leapclient/ProviderAPI.java
@@ -1,15 +1,67 @@
package se.leap.leapclient;
-import android.app.Service;
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.Scanner;
+
+import android.app.IntentService;
import android.content.Intent;
-import android.os.IBinder;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.util.Log;
+
+public class ProviderAPI extends IntentService {
-public class ProviderAPI extends Service {
+ public ProviderAPI() {
+ super("ProviderAPI");
+ Log.v("ClassName", "Provider API");
+ // TODO Auto-generated constructor stub
+ }
@Override
- public IBinder onBind(Intent arg0) {
- // TODO Auto-generated method stub
- return null;
+ protected void onHandleIntent(Intent task_for) {
+ Bundle task ;
+ System.out.println("onHandleIntent called");
+ if(!(task = task_for.getBundleExtra("downloadJSONFiles")).isEmpty())
+ {
+ String provider_key = "provider";
+ String eip_service_key = "eip";
+ String provider_json_url = (String) task.get(provider_key);
+ String eip_service_json_url = (String) task.get(eip_service_key);
+ try {
+ getAndParseSharedPref(provider_key, provider_json_url);
+ getAndParseSharedPref(eip_service_key, eip_service_json_url);
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private void getAndParseSharedPref(String shared_preferences_key,
+ String json_url) throws IOException {
+ URL url = new URL(json_url);
+ HttpURLConnection urlConnection = (HttpURLConnection) url
+ .openConnection();
+ try {
+ InputStream in = new BufferedInputStream(
+ urlConnection.getInputStream());
+ String json_file_content = new Scanner(in).useDelimiter("\\A")
+ .next();
+
+ SharedPreferences.Editor shared_preferences_editor = ProviderListActivity.shared_preferences
+ .edit();
+ shared_preferences_editor.putString(shared_preferences_key,
+ json_file_content);
+ shared_preferences_editor.commit();
+ System.out.println("Shared preferences updated: " + ProviderListActivity.shared_preferences.getString(shared_preferences_key, "Default"));
+ } finally {
+ urlConnection.disconnect();
+ }
+
}
}