diff options
author | Parménides GV <parmegv@sdf.org> | 2013-03-13 21:01:53 +0100 |
---|---|---|
committer | Parménides GV <parmegv@sdf.org> | 2013-03-13 21:01:53 +0100 |
commit | 929fa9a3b7621e0a956ed8d7beffb87ed7f16249 (patch) | |
tree | 26e3dbb8c9662b63e72c096bf0a0e54edefcd49a /src/se/leap | |
parent | a8274e8b2649481f22bfc6d205d2ca7599fea065 (diff) |
ConfigurationWizard sets provider.json correctly for Dashboard once a
custom provider is selected.
Tested using https://bitmask.net as url for custom provider.
Diffstat (limited to 'src/se/leap')
-rw-r--r-- | src/se/leap/leapclient/ConfigHelper.java | 15 | ||||
-rw-r--r-- | src/se/leap/leapclient/ConfigurationWizard.java | 26 | ||||
-rw-r--r-- | src/se/leap/leapclient/ProviderAPI.java | 8 | ||||
-rw-r--r-- | src/se/leap/leapclient/ProviderListContent.java | 6 |
4 files changed, 40 insertions, 15 deletions
diff --git a/src/se/leap/leapclient/ConfigHelper.java b/src/se/leap/leapclient/ConfigHelper.java index 5301209c..f5800a0e 100644 --- a/src/se/leap/leapclient/ConfigHelper.java +++ b/src/se/leap/leapclient/ConfigHelper.java @@ -17,6 +17,8 @@ import android.os.Environment; import android.util.Log; public class ConfigHelper { + + public static SharedPreferences shared_preferences; final static String downloadJsonFilesBundleExtra = "downloadJSONFiles"; final static String downloadNewProviderDotJSON = "downloadNewProviderDotJSON"; @@ -28,11 +30,13 @@ public class ConfigHelper { public static String provider_key_url = "provider_main_url"; final public static String eip_service_api_path = "/config/eip-service.json"; - final public static int CUSTOM_PROVIDER_ADDED = 0; + final public static int CUSTOM_PROVIDER_ADDED = 0; + final public static int CORRECTLY_DOWNLOADED_JSON_FILES = 1; + final public static int INCORRECTLY_DOWNLOADED_JSON_FILES = 2; static void saveSharedPref(String shared_preferences_key, JSONObject content) { - SharedPreferences.Editor shared_preferences_editor = ConfigurationWizard.shared_preferences + SharedPreferences.Editor shared_preferences_editor = shared_preferences .edit(); shared_preferences_editor.putString(shared_preferences_key, content.toString()); @@ -40,7 +44,7 @@ public class ConfigHelper { System.out.println("Shared preferences updated: key = " + shared_preferences_key + " Content = " - + ConfigurationWizard.shared_preferences.getString( + + shared_preferences.getString( shared_preferences_key, "Default")); } @@ -81,4 +85,9 @@ public class ConfigHelper { } return input_stream; } + + public static void setSharedPreferences( + SharedPreferences shared_preferences) { + ConfigHelper.shared_preferences = shared_preferences; + } } diff --git a/src/se/leap/leapclient/ConfigurationWizard.java b/src/se/leap/leapclient/ConfigurationWizard.java index e252fa6b..dcefb271 100644 --- a/src/se/leap/leapclient/ConfigurationWizard.java +++ b/src/se/leap/leapclient/ConfigurationWizard.java @@ -59,7 +59,7 @@ public class ConfigurationWizard extends Activity setContentView(R.layout.activity_configuration_wizard);
- shared_preferences = getSharedPreferences(ConfigHelper.PREFERENCES_KEY,MODE_PRIVATE);
+ ConfigHelper.setSharedPreferences(getSharedPreferences(ConfigHelper.PREFERENCES_KEY,MODE_PRIVATE));
loadPreseededProviders();
@@ -118,10 +118,9 @@ public class ConfigurationWizard extends Activity if(current_provider_item.id.equalsIgnoreCase(id))
{
try {
- if(!current_provider_item.custom)
- processAssetsFiles(current_provider_item);
- // TODO ask Provider class to save provider.json, setResult(OK), finish() to ConfigurationWizard
- downloadJSONFiles(current_provider_item);
+ saveProviderJson(current_provider_item);
+ downloadJSONFiles(current_provider_item);
+
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@@ -136,11 +135,15 @@ public class ConfigurationWizard extends Activity }
}
- private void processAssetsFiles(ProviderItem current_provider_item) {
+ private void saveProviderJson(ProviderItem current_provider_item) {
AssetManager assets_manager = getAssets();
JSONObject provider_json = new JSONObject();
try {
- String provider_contents = new Scanner(new InputStreamReader(assets_manager.open(current_provider_item.provider_json_assets))).useDelimiter("\\A").next();
+ String provider_contents = "";
+ if(!current_provider_item.custom)
+ provider_contents = new Scanner(new InputStreamReader(assets_manager.open(current_provider_item.provider_json_filename))).useDelimiter("\\A").next();
+ else
+ provider_contents = new Scanner(ConfigHelper.openFileInputStream(current_provider_item.provider_json_filename)).useDelimiter("\\A").next();
provider_json = new JSONObject(provider_contents);
} catch (IOException e) {
// TODO Auto-generated catch block
@@ -152,16 +155,20 @@ public class ConfigurationWizard extends Activity }
private void downloadJSONFiles(ProviderItem current_provider_item) throws IOException {
+ providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler());
+ providerAPI_result_receiver.setReceiver(this);
+
Intent provider_API_command = new Intent(this, ProviderAPI.class);
Bundle method_and_parameters = new Bundle();
+
+ method_and_parameters.putString(ConfigHelper.provider_key, current_provider_item.name);
method_and_parameters.putString(ConfigHelper.cert_key, current_provider_item.cert_json_url);
method_and_parameters.putString(ConfigHelper.eip_service_key, current_provider_item.eip_service_json_url);
provider_API_command.putExtra(ConfigHelper.downloadJsonFilesBundleExtra, method_and_parameters);
-
+ provider_API_command.putExtra("receiver", providerAPI_result_receiver);
startService(provider_API_command);
-
}
public void addNewProvider(View view) {
@@ -193,7 +200,6 @@ public class ConfigurationWizard extends Activity @Override
public void onReceiveResult(int resultCode, Bundle resultData) {
- // TODO Auto-generated method stub
if(resultCode == ConfigHelper.CUSTOM_PROVIDER_ADDED){
ProviderListFragment providerList = new ProviderListFragment();
diff --git a/src/se/leap/leapclient/ProviderAPI.java b/src/se/leap/leapclient/ProviderAPI.java index 583eea06..1dc7c9f6 100644 --- a/src/se/leap/leapclient/ProviderAPI.java +++ b/src/se/leap/leapclient/ProviderAPI.java @@ -32,21 +32,28 @@ public class ProviderAPI extends IntentService { Bundle task; System.out.println("onHandleIntent called"); if((task = task_for.getBundleExtra(ConfigHelper.downloadJsonFilesBundleExtra)) != null) { + String provider_name = (String) task.get(ConfigHelper.provider_key); String cert_url = (String) task.get(ConfigHelper.cert_key); String eip_service_json_url = (String) task.get(ConfigHelper.eip_service_key); try { + JSONObject provider_json = new JSONObject("{ \"provider\" : \"" + provider_name + "\"}"); + ConfigHelper.saveSharedPref(ConfigHelper.provider_key, provider_json); String cert_string = getStringFromProvider(cert_url); JSONObject cert_json = new JSONObject("{ \"certificate\" : \"" + cert_string + "\"}"); ConfigHelper.saveSharedPref(ConfigHelper.cert_key, cert_json); JSONObject eip_service_json = getJSONFromProvider(eip_service_json_url); ConfigHelper.saveSharedPref(ConfigHelper.eip_service_key, eip_service_json); + receiver.send(ConfigHelper.CORRECTLY_DOWNLOADED_JSON_FILES, Bundle.EMPTY); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); + receiver.send(ConfigHelper.INCORRECTLY_DOWNLOADED_JSON_FILES, Bundle.EMPTY); } catch (JSONException e) { ConfigHelper.rescueJSONException(e); + receiver.send(ConfigHelper.INCORRECTLY_DOWNLOADED_JSON_FILES, Bundle.EMPTY); } catch(Exception e) { e.printStackTrace(); + receiver.send(ConfigHelper.INCORRECTLY_DOWNLOADED_JSON_FILES, Bundle.EMPTY); } } else if ((task = task_for.getBundleExtra(ConfigHelper.downloadNewProviderDotJSON)) != null) { @@ -58,6 +65,7 @@ public class ProviderAPI extends IntentService { JSONObject provider_json = getJSONFromProvider(provider_json_url); String filename = provider_name + "_provider.json".replaceFirst("__", "_"); ConfigHelper.saveFile(filename, provider_json.toString()); + ProviderListContent.addItem(new ProviderItem(provider_name, ConfigHelper.openFileInputStream(filename), custom)); receiver.send(ConfigHelper.CUSTOM_PROVIDER_ADDED, Bundle.EMPTY); } catch (IOException e) { diff --git a/src/se/leap/leapclient/ProviderListContent.java b/src/se/leap/leapclient/ProviderListContent.java index d475d368..dd227bfd 100644 --- a/src/se/leap/leapclient/ProviderListContent.java +++ b/src/se/leap/leapclient/ProviderListContent.java @@ -41,7 +41,7 @@ public class ProviderListContent { public String id;
public String name;
public String provider_json_url;
- public String provider_json_assets;
+ public String provider_json_filename;
public String eip_service_json_url;
public String cert_json_url;
@@ -63,7 +63,7 @@ public class ProviderListContent { id = name;
this.name = name;
provider_json_url = (String) file_contents.get("json_provider");
- provider_json_assets = (String) file_contents.get("assets_json_provider");
+ provider_json_filename = (String) file_contents.get("assets_json_provider");
eip_service_json_url = (String) file_contents.get("json_eip_service");
cert_json_url = (String) file_contents.get("cert");
this.custom = custom;
@@ -88,6 +88,8 @@ public class ProviderListContent { eip_service_json_url = (String) file_contents.get("api_uri") + ConfigHelper.eip_service_api_path;
cert_json_url = (String) file_contents.get("ca_cert_uri");
this.custom = custom;
+ if(custom)
+ provider_json_filename = name + "_provider.json".replaceFirst("__", "_");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
|