summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcyBerta <richy@cyborgsociety.org>2013-11-23 03:23:05 +0100
committerParménides GV <parmegv@sdf.org>2013-12-04 16:00:48 +0100
commite60be47e5a46b794846b166993260f17a54a19ad (patch)
tree8964645cc720e5edb2880747699651920b54d415
parentdc417fbfc67d8edaad58effde3a6a73fbeeab1da (diff)
switch provider part 1
-rw-r--r--src/se/leap/bitmaskclient/ConfigurationWizard.java55
-rw-r--r--src/se/leap/bitmaskclient/Dashboard.java38
-rw-r--r--src/se/leap/bitmaskclient/EipServiceFragment.java5
-rw-r--r--src/se/leap/bitmaskclient/Provider.java2
4 files changed, 91 insertions, 9 deletions
diff --git a/src/se/leap/bitmaskclient/ConfigurationWizard.java b/src/se/leap/bitmaskclient/ConfigurationWizard.java
index 28a8a44a..5babf9a6 100644
--- a/src/se/leap/bitmaskclient/ConfigurationWizard.java
+++ b/src/se/leap/bitmaskclient/ConfigurationWizard.java
@@ -25,7 +25,6 @@ import org.json.JSONObject;
import se.leap.bitmaskclient.R;
import se.leap.bitmaskclient.ProviderAPIResultReceiver.Receiver;
import se.leap.bitmaskclient.ProviderListContent.ProviderItem;
-
import android.app.Activity;
import android.app.DialogFragment;
import android.app.Fragment;
@@ -37,6 +36,7 @@ import android.content.Intent;
import android.content.res.AssetManager;
import android.os.Bundle;
import android.os.Handler;
+import android.util.Log;
import android.view.Display;
import android.view.Menu;
import android.view.MenuItem;
@@ -68,6 +68,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
private ProviderListFragment provider_list_fragment;
private Intent mConfigState = new Intent();
+ final public static String TAG = "se.leap.bitmaskclient.ConfigurationWizard";
final public static String TYPE_OF_CERTIFICATE = "type_of_certificate";
final public static String ANON_CERTIFICATE = "anon_certificate";
final public static String AUTHED_CERTIFICATE = "authed_certificate";
@@ -101,6 +102,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
Bundle arguments = new Bundle();
int configuration_wizard_request_code = getIntent().getIntExtra(Dashboard.REQUEST_CODE, -1);
if(configuration_wizard_request_code == Dashboard.SWITCH_PROVIDER) {
+ Log.d(TAG, "onCreate - Request_Code: Switch Provider");
arguments.putBoolean(ProviderListFragment.SHOW_ALL_PROVIDERS, true);
}
provider_list_fragment.setArguments(arguments);
@@ -231,10 +233,12 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
@Override
public void onItemSelected(String id) {
//TODO Code 2 pane view
+ // resetOldConnection();
ProviderItem selected_provider = getProvider(id);
int provider_index = getProviderIndex(id);
startProgressBar(provider_index);
mSelectedProvider = selected_provider;
+
saveProviderJson(mSelectedProvider);
}
@@ -365,6 +369,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
downloadJSONFiles(mSelectedProvider);
}
} catch (JSONException e) {
+ Log.d(TAG, "saveProviderJson("+provider.id + " = " + provider.name + ") failed");
setResult(RESULT_CANCELED);
finish();
}
@@ -484,8 +489,9 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
* @param danger_on tells if HTTPS client should bypass certificate errors
*/
public void updateProviderDotJson(String provider_name, String provider_json_url, boolean danger_on) {
+
+
Intent provider_API_command = new Intent(this, ProviderAPI.class);
-
Bundle parameters = new Bundle();
parameters.putString(Provider.NAME, provider_name);
parameters.putString(Provider.DOT_JSON_URL, provider_json_url);
@@ -494,9 +500,18 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
provider_API_command.setAction(ProviderAPI.UPDATE_PROVIDER_DOTJSON);
provider_API_command.putExtra(ProviderAPI.PARAMETERS, parameters);
provider_API_command.putExtra(ProviderAPI.RECEIVER_KEY, providerAPI_result_receiver);
-
+ Log.d(TAG, "updateProviderDotJson... right after resetting old connection, starts Service ");
+
startService(provider_API_command);
}
+ /*private void resetOldConnection(){
+ Log.d(TAG, "resetOldConnection... EIPStop()");
+ if (Provider.getInstance().hasEIP()){
+ Log.d(TAG, "resetOldConnection... Provider has EIP");
+ eipStop();
+ }
+
+ }*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
@@ -535,6 +550,14 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
}
}
+/* private void eipStop(){
+ // TODO validate "action"...how do we get the list of intent-filters for a class via Android API?
+ Intent eip_intent = new Intent(this, EIP.class);
+ eip_intent.setAction(EIP.ACTION_STOP_EIP);
+ // eip_intent.putExtra(EIP.RECEIVER_TAG, eip_receiver);
+ startService(eip_intent);
+ }
+*/
public void showAllProviders() {
provider_list_fragment = (ProviderListFragment) getFragmentManager().findFragmentByTag(ProviderListFragment.TAG);
if(provider_list_fragment != null)
@@ -543,15 +566,39 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
@Override
public void login() {
+
+
Intent ask_login = new Intent();
ask_login.putExtra(LogInDialog.VERB, LogInDialog.VERB);
+
+ if (Provider.getInstance().hasEIP()){
+ if (ConfigHelper.getBoolFromSharedPref(EIP.AUTHED_EIP)){
+ ask_login.putExtra(Dashboard.LOGOUT_FIRST, Dashboard.LOGOUT_FIRST);
+ Log.d(TAG, "login() -> there was an authed EIP authed before");
+ }
+ Log.d(TAG, "use_anonymously() -> STOP_FIRST!");
+ ask_login.putExtra(Dashboard.STOP_FIRST, Dashboard.STOP_FIRST);
+ Log.d(TAG, "use_anonymously() -> ask_login has: " + ask_login.getExtras());
+
+ }
setResult(RESULT_OK, ask_login);
finish();
}
@Override
public void use_anonymously() {
- setResult(RESULT_OK);
+ Intent stopFirst = new Intent();
+ if (Provider.getInstance().hasEIP()){
+ if (ConfigHelper.getBoolFromSharedPref(EIP.AUTHED_EIP)){
+ stopFirst.putExtra(Dashboard.LOGOUT_FIRST, Dashboard.LOGOUT_FIRST);
+ Log.d(TAG, "use_anonymously() -> there was an authed EIP before");
+ }
+ Log.d(TAG, "use_anonymously() -> STOP_FIRST!");
+ stopFirst.putExtra(Dashboard.STOP_FIRST, Dashboard.STOP_FIRST);
+
+ }
+ Log.d(TAG, "use_anonymously() ");
+ setResult(RESULT_OK, stopFirst);
finish();
}
}
diff --git a/src/se/leap/bitmaskclient/Dashboard.java b/src/se/leap/bitmaskclient/Dashboard.java
index ca619e9f..116d043b 100644
--- a/src/se/leap/bitmaskclient/Dashboard.java
+++ b/src/se/leap/bitmaskclient/Dashboard.java
@@ -40,6 +40,7 @@ import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.ResultReceiver;
+import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@@ -63,12 +64,17 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
protected static final int CONFIGURE_LEAP = 0;
protected static final int SWITCH_PROVIDER = 1;
+
private static final String TAG_EIP_FRAGMENT = "EIP_DASHBOARD_FRAGMENT";
final public static String SHARED_PREFERENCES = "LEAPPreferences";
final public static String ACTION_QUIT = "quit";
public static final String REQUEST_CODE = "request_code";
+ public static final String LOGOUT_FIRST = "logout_first";
+ public static final String STOP_FIRST = "stop_first";
+
+
private ProgressBar mProgressBar;
private TextView eipStatus;
private ProviderAPIBroadcastReceiver_Update providerAPI_broadcast_receiver_update;
@@ -89,8 +95,9 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
app = this;
PRNGFixes.apply();
- //mProgressBar = (ProgressBar) findViewById(R.id.progressbar_dashboard);
-
+ // mProgressBar = (ProgressBar) findViewById(R.id.progressbar_dashboard);
+ // 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);
@@ -116,8 +123,16 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
if ( requestCode == CONFIGURE_LEAP || requestCode == SWITCH_PROVIDER) {
+ // It should be equivalent: if ( (requestCode == CONFIGURE_LEAP) || (data!= null && data.hasExtra(STOP_FIRST))) {
if ( resultCode == RESULT_OK ){
ConfigHelper.saveSharedPref(EIP.AUTHED_EIP, authed_eip);
+ if ((data != null) && (data.hasExtra(STOP_FIRST))){
+ Log.d(TAG_EIP_FRAGMENT, "onActivityResult() -> eipStop!");
+ eipStop();
+ }else{
+ Log.d(TAG_EIP_FRAGMENT, "onActivityResult() -> has no Extra STOP_FIRST");
+ }
+
startService( new Intent(EIP.ACTION_UPDATE_EIP_SERVICE) );
buildDashboard();
if(data != null && data.hasExtra(LogInDialog.VERB)) {
@@ -299,14 +314,13 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
provider_API_command.putExtra(ProviderAPI.PARAMETERS, parameters);
provider_API_command.putExtra(ProviderAPI.RECEIVER_KEY, providerAPI_result_receiver);
- //if(mProgressDialog != null) mProgressDialog.dismiss();
- //mProgressDialog = ProgressDialog.show(this, getResources().getString(R.string.logout_title), getResources().getString(R.string.logout_message), true);
if(mProgressBar == null) mProgressBar = (ProgressBar) findViewById(R.id.eipProgress);
mProgressBar.setVisibility(ProgressBar.VISIBLE);
if(eipStatus == null) eipStatus = (TextView) findViewById(R.id.eipStatus);
eipStatus.setText("Starting to logout");
- //mProgressBar.setMax(1);
startService(provider_API_command);
+ //mProgressBar.setMax(1);
+
}
/**
@@ -456,7 +470,21 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
eip_intent.putExtra(EIP.RECEIVER_TAG, eip_receiver);
startService(eip_intent);
}
+
+ /**
+ * Send a command to EIP
+ *
+ */
+ private void eipStop(){
+ // TODO validate "action"...how do we get the list of intent-filters for a class via Android API?
+ Intent eip_intent = new Intent(this, EIP.class);
+ eip_intent.setAction(EIP.ACTION_STOP_EIP);
+ // eip_intent.putExtra(EIP.RECEIVER_TAG, eip_receiver);
+ startService(eip_intent);
+ Log.d(TAG_EIP_FRAGMENT, "eipStop() -> service started to stop");
+ }
+
public class ProviderAPIBroadcastReceiver_Update extends BroadcastReceiver {
@Override
diff --git a/src/se/leap/bitmaskclient/EipServiceFragment.java b/src/se/leap/bitmaskclient/EipServiceFragment.java
index 4d778b1a..ba6bf561 100644
--- a/src/se/leap/bitmaskclient/EipServiceFragment.java
+++ b/src/se/leap/bitmaskclient/EipServiceFragment.java
@@ -57,6 +57,8 @@ public class EipServiceFragment extends Fragment implements StateListener, OnCli
eipStatus.setOnClickListener(this);
eipSwitch = (Switch) eipFragment.findViewById(R.id.eipSwitch);
+
+
eipSwitch.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
@@ -66,6 +68,7 @@ public class EipServiceFragment extends Fragment implements StateListener, OnCli
});
eipSwitch.setOnCheckedChangeListener(this);
+
return eipFragment;
}
@@ -152,6 +155,8 @@ public class EipServiceFragment extends Fragment implements StateListener, OnCli
eipAutoSwitched = true;
}
+
+
/**
* Send a command to EIP
*
diff --git a/src/se/leap/bitmaskclient/Provider.java b/src/se/leap/bitmaskclient/Provider.java
index e462829f..f36e5946 100644
--- a/src/se/leap/bitmaskclient/Provider.java
+++ b/src/se/leap/bitmaskclient/Provider.java
@@ -166,6 +166,8 @@ public final class Provider implements Serializable {
// Walk the EIP types array looking for matches in provider's service definitions
if ( Arrays.asList(API_EIP_TYPES).contains( services.getString(i) ) )
return true;
+ } catch (NullPointerException e){
+ e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();