summaryrefslogtreecommitdiff
path: root/src/se
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2013-10-14 17:05:06 +0200
committerParménides GV <parmegv@sdf.org>2013-12-10 18:12:07 +0100
commit50c88ad133c6bac39cb68332f1f56cd27f568205 (patch)
tree237ef2d89b0c4f9196db864e3f9e55436f56f259 /src/se
parent19cc4e83eb26374620c5f712a4f7f10d79eeb217 (diff)
ProviderAPI broadcasts progress to CW.
Setting up a provider makes the progressbar move according to the number of files downloaded (1/3, 2/3, 3/3). Next step: recover from download errors individually. That means that if a download fails but the others went OK, the user will be prompted to retry that individual failing download.
Diffstat (limited to 'src/se')
-rw-r--r--src/se/leap/bitmaskclient/ConfigurationWizard.java78
-rw-r--r--src/se/leap/bitmaskclient/Dashboard.java21
-rw-r--r--src/se/leap/bitmaskclient/ProviderAPI.java38
-rw-r--r--src/se/leap/bitmaskclient/ProviderListAdapter.java1
-rw-r--r--src/se/leap/bitmaskclient/ProviderListFragment.java8
5 files changed, 61 insertions, 85 deletions
diff --git a/src/se/leap/bitmaskclient/ConfigurationWizard.java b/src/se/leap/bitmaskclient/ConfigurationWizard.java
index ee42bae9..b35123b0 100644
--- a/src/se/leap/bitmaskclient/ConfigurationWizard.java
+++ b/src/se/leap/bitmaskclient/ConfigurationWizard.java
@@ -30,8 +30,10 @@ import android.app.DialogFragment;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
+import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
+import android.content.IntentFilter;
import android.content.res.AssetManager;
import android.os.Bundle;
import android.os.Handler;
@@ -61,7 +63,6 @@ import android.widget.TextView;
public class ConfigurationWizard extends Activity
implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogInterface, ProviderDetailFragment.ProviderDetailFragmentInterface, Receiver {
- private ProviderItem mSelectedProvider;
private ProgressBar mProgressBar;
private TextView progressbar_description;
private ProviderListFragment provider_list_fragment;
@@ -76,6 +77,8 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
final protected static String SERVICES_RETRIEVED = "SERVICES RETRIEVED";
public ProviderAPIResultReceiver providerAPI_result_receiver;
+ private ProviderAPIBroadcastReceiver_Update providerAPI_broadcast_receiver_update;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -88,7 +91,11 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
progressbar_description.setVisibility(TextView.INVISIBLE);
providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler());
providerAPI_result_receiver.setReceiver(this);
-
+ providerAPI_broadcast_receiver_update = new ProviderAPIBroadcastReceiver_Update();
+ IntentFilter update_intent_filter = new IntentFilter(ProviderAPI.UPDATE_PROGRESSBAR);
+ update_intent_filter.addCategory(Intent.CATEGORY_DEFAULT);
+ registerReceiver(providerAPI_broadcast_receiver_update, update_intent_filter);
+
ConfigHelper.setSharedPreferences(getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE));
loadPreseededProviders();
@@ -114,6 +121,12 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
// TODO: If exposing deep links into your app, handle intents here.
}
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ unregisterReceiver(providerAPI_broadcast_receiver_update);
+ }
+
public void refreshProviderList(int top_padding) {
ProviderListFragment new_provider_list_fragment = new ProviderListFragment();
Bundle top_padding_bundle = new Bundle();
@@ -133,29 +146,8 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
try {
provider_json = new JSONObject(resultData.getString(Provider.KEY));
boolean danger_on = resultData.getBoolean(ProviderItem.DANGER_ON);
- ConfigHelper.saveSharedPref(Provider.KEY, provider_json);
- ConfigHelper.saveSharedPref(ProviderItem.DANGER_ON, danger_on);
- ConfigHelper.saveSharedPref(EIP.ALLOWED_ANON, provider_json.getJSONObject(Provider.SERVICE).getBoolean(EIP.ALLOWED_ANON));
mConfigState.setAction(PROVIDER_SET);
- if(resultData.containsKey(Provider.NAME)) {
- String provider_id = resultData.getString(Provider.NAME);
- mSelectedProvider = getProvider(provider_id);
- //provider_list_fragment.addItem(mSelectedProvider);
- //ProviderListContent.removeItem(mSelectedProvider);
-
- //refreshProviderList(0);
-
- if(!mProgressBar.isShown()) {
- int provider_index = getProviderIndex(provider_id);
- startProgressBar(provider_index);
- provider_list_fragment.hide(provider_index-2);
- //setProviderList(provider_list_fragment);
- }
- mProgressBar.incrementProgressBy(1);
- }
-
-
if (ConfigHelper.getBoolFromSharedPref(EIP.ALLOWED_ANON)){
mConfigState.putExtra(SERVICES_RETRIEVED, true);
downloadAnonCert();
@@ -163,14 +155,10 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
mProgressBar.incrementProgressBy(1);
mProgressBar.setVisibility(ProgressBar.GONE);
progressbar_description.setVisibility(TextView.GONE);
- //refreshProviderList(0);
- //Toast.makeText(getApplicationContext(), R.string.success, Toast.LENGTH_LONG).show();
setResult(RESULT_OK);
showProviderDetails(getCurrentFocus());
}
- //downloadJSONFiles(provider_json, danger_on);
} catch (JSONException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
mProgressBar.setVisibility(ProgressBar.GONE);
progressbar_description.setVisibility(TextView.GONE);
@@ -214,8 +202,8 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
ProviderItem selected_provider = getProvider(id);
int provider_index = getProviderIndex(id);
startProgressBar(provider_index);
- mSelectedProvider = selected_provider;
- setUpProvider(mSelectedProvider.providerMainUrl(), true);
+ provider_list_fragment.hideAllBut(provider_index);
+ setUpProvider(selected_provider.providerMainUrl(), true);
}
@Override
@@ -238,16 +226,27 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
setResult(RESULT_CANCELED, ask_quit);
}
- private ProviderItem getProvider(String id) {
+ private ProviderItem getProvider(String name) {
Iterator<ProviderItem> providers_iterator = ProviderListContent.ITEMS.iterator();
while(providers_iterator.hasNext()) {
ProviderItem provider = providers_iterator.next();
- if(provider.name().equalsIgnoreCase(id)) {
+ if(provider.name().equalsIgnoreCase(name)) {
return provider;
}
}
return null;
}
+
+ private String getId(String provider_main_url) {
+ Iterator<ProviderItem> providers_iterator = ProviderListContent.ITEMS.iterator();
+ while(providers_iterator.hasNext()) {
+ ProviderItem provider = providers_iterator.next();
+ if(provider.providerMainUrl().equalsIgnoreCase(provider_main_url)) {
+ return provider.name();
+ }
+ }
+ return "";
+ }
private void startProgressBar(int list_item_index) {
mProgressBar.setVisibility(ProgressBar.VISIBLE);
@@ -264,10 +263,10 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
Iterator<ProviderItem> providers_iterator = ProviderListContent.ITEMS.iterator();
while(providers_iterator.hasNext()) {
ProviderItem provider = providers_iterator.next();
- index++;
if(provider.name().equalsIgnoreCase(id)) {
break;
}
+ index++;
}
return index;
}
@@ -391,7 +390,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
public void showAndSelectProvider(String provider_main_url, boolean danger_on) {
showProvider(provider_main_url, danger_on);
- setUpProvider(provider_main_url, danger_on);
+ autoSelectProvider(provider_main_url, danger_on);
}
private void showProvider(final String provider_main_url, final boolean danger_on) {
@@ -400,6 +399,10 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
provider_list_fragment.addItem(added_provider);
}
+ private void autoSelectProvider(String provider_main_url, boolean danger_on) {
+ onItemSelected(getId(provider_main_url));
+ }
+
/**
* Asks ProviderAPI to download a new provider.json file
* @param provider_name
@@ -475,4 +478,13 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
setResult(RESULT_OK);
finish();
}
+
+ public class ProviderAPIBroadcastReceiver_Update extends BroadcastReceiver {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ int update = intent.getIntExtra(ProviderAPI.CURRENT_PROGRESS, 0);
+ mProgressBar.setProgress(update);
+ }
+ }
}
diff --git a/src/se/leap/bitmaskclient/Dashboard.java b/src/se/leap/bitmaskclient/Dashboard.java
index 0ae7085a..8c7c495d 100644
--- a/src/se/leap/bitmaskclient/Dashboard.java
+++ b/src/se/leap/bitmaskclient/Dashboard.java
@@ -16,8 +16,6 @@
*/
package se.leap.bitmaskclient;
-import org.apache.http.cookie.Cookie;
-import org.apache.http.impl.cookie.BasicClientCookie;
import org.json.JSONException;
import org.json.JSONObject;
@@ -30,12 +28,9 @@ import android.app.DialogFragment;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
-import android.app.ProgressDialog;
-import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
-import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
@@ -45,11 +40,7 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
-import android.view.ViewStub;
-import android.widget.CompoundButton;
import android.widget.ProgressBar;
-import android.widget.RelativeLayout;
-import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
@@ -76,7 +67,6 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
private ProgressBar mProgressBar;
private TextView eipStatus;
- private ProviderAPIBroadcastReceiver_Update providerAPI_broadcast_receiver_update;
private static Context app;
private static SharedPreferences preferences;
private static Provider provider;
@@ -98,10 +88,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
// mProgressBar = (ProgressBar) findViewById(R.id.eipProgress);
// eipStatus = (TextView) findViewById(R.id.eipStatus);
- providerAPI_broadcast_receiver_update = new ProviderAPIBroadcastReceiver_Update();
- IntentFilter update_intent_filter = new IntentFilter(ProviderAPI.UPDATE_ACTION);
- update_intent_filter.addCategory(Intent.CATEGORY_DEFAULT);
- registerReceiver(providerAPI_broadcast_receiver_update, update_intent_filter);
+ mProgressBar = (ProgressBar) findViewById(R.id.eipProgress);
ConfigHelper.setSharedPreferences(getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE));
preferences = ConfigHelper.shared_preferences;
@@ -116,7 +103,6 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
@Override
protected void onDestroy() {
super.onDestroy();
- unregisterReceiver(providerAPI_broadcast_receiver_update);
}
@Override
@@ -176,11 +162,6 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
provider.init( this );
setContentView(R.layout.client_dashboard);
-
- providerAPI_broadcast_receiver_update = new ProviderAPIBroadcastReceiver_Update();
- IntentFilter update_intent_filter = new IntentFilter(ProviderAPI.UPDATE_ACTION);
- update_intent_filter.addCategory(Intent.CATEGORY_DEFAULT);
- registerReceiver(providerAPI_broadcast_receiver_update, update_intent_filter);
providerNameTV = (TextView) findViewById(R.id.providerName);
providerNameTV.setText(provider.getDomain());
diff --git a/src/se/leap/bitmaskclient/ProviderAPI.java b/src/se/leap/bitmaskclient/ProviderAPI.java
index 60ed1e1f..27081df2 100644
--- a/src/se/leap/bitmaskclient/ProviderAPI.java
+++ b/src/se/leap/bitmaskclient/ProviderAPI.java
@@ -97,8 +97,8 @@ public class ProviderAPI extends IntentService {
SESSION_ID_COOKIE_KEY = "session_id_cookie_key",
SESSION_ID_KEY = "session_id",
ERRORS = "errors",
- UPDATE_ACTION = "update_action",
- UPDATE_DATA = "update data",
+ UPDATE_PROGRESSBAR = "update_action",
+ CURRENT_PROGRESS = "update data",
TAG = "provider_api_tag"
;
@@ -266,9 +266,9 @@ public class ProviderAPI extends IntentService {
*/
private void broadcast_progress(int progress) {
Intent intentUpdate = new Intent();
- intentUpdate.setAction(UPDATE_ACTION);
+ intentUpdate.setAction(UPDATE_PROGRESSBAR);
intentUpdate.addCategory(Intent.CATEGORY_DEFAULT);
- intentUpdate.putExtra(UPDATE_DATA, progress);
+ intentUpdate.putExtra(CURRENT_PROGRESS, progress);
sendBroadcast(intentUpdate);
}
@@ -421,38 +421,18 @@ public class ProviderAPI extends IntentService {
*/
private Bundle setUpProvider(Bundle task) {
Bundle result = new Bundle();
+ int progress = 0;
boolean danger_on = task.getBoolean(ProviderItem.DANGER_ON);
String provider_main_url = task.getString(Provider.MAIN_URL);
if(downloadCACert(provider_main_url, danger_on)) {
+ broadcast_progress(progress++);
result.putBoolean(RESULT_KEY, true);
- if(getAndSetProviderJson(provider_main_url))
+ if(getAndSetProviderJson(provider_main_url)) {
+ broadcast_progress(progress++);
if(getAndSetEipServiceJson())
- ;
- }
- /*
- try {
- String provider_dot_json_string = downloadWithCommercialCA(provider_json_url, danger_on);
- if(provider_dot_json_string.isEmpty()) {
- result.putBoolean(RESULT_KEY, false);
- } else {
- JSONObject provider_json = new JSONObject(provider_dot_json_string);
- if(provider_json.has(ERRORS)) {
- String reason_to_fail = provider_json.getString(ERRORS);
- result.putString(ERRORS, reason_to_fail);
- result.putBoolean(RESULT_KEY, false);
- } else {
- ConfigHelper.saveSharedPref(EIP.ALLOWED_ANON, provider_json.getJSONObject(Provider.SERVICE).getBoolean(EIP.ALLOWED_ANON));
-
- result.putString(Provider.NAME, added_provider.name());
- result.putBoolean(RESULT_KEY, true);
- result.putString(Provider.KEY, provider_json.toString());
- result.putBoolean(ProviderItem.DANGER_ON, danger_on);
+ broadcast_progress(progress++);
}
- } catch (JSONException e) {
- result.putBoolean(RESULT_KEY, false);
- result.putString(ERRORS, "Corrupt download");
}
- */
return result;
}
diff --git a/src/se/leap/bitmaskclient/ProviderListAdapter.java b/src/se/leap/bitmaskclient/ProviderListAdapter.java
index bb1318fc..4abf15a2 100644
--- a/src/se/leap/bitmaskclient/ProviderListAdapter.java
+++ b/src/se/leap/bitmaskclient/ProviderListAdapter.java
@@ -1,6 +1,5 @@
package se.leap.bitmaskclient;
-import java.lang.reflect.Array;
import java.util.List;
import android.content.Context;
diff --git a/src/se/leap/bitmaskclient/ProviderListFragment.java b/src/se/leap/bitmaskclient/ProviderListFragment.java
index 6a0f2a05..862177a2 100644
--- a/src/se/leap/bitmaskclient/ProviderListFragment.java
+++ b/src/se/leap/bitmaskclient/ProviderListFragment.java
@@ -202,8 +202,12 @@ public class ProviderListFragment extends ListFragment {
content_adapter.notifyDataSetChanged();
}
- public void hide(int position) {
- content_adapter.hide(position);
+ public void hideAllBut(int position) {
+ for(int i = 0; i < content_adapter.getCount(); i++)
+ if(i != position)
+ content_adapter.hide(i);
+ else
+ content_adapter.unHide(i);
}
public void unhideAll() {