diff options
Diffstat (limited to 'app/src/main/java/se/leap/bitmaskclient')
4 files changed, 80 insertions, 17 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java index 292434c7..3c17ebb8 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java +++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java @@ -57,7 +57,11 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf 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 REQUEST_CODE = "request_code"; + public static final String PARAMETERS = "dashboard parameters"; + public static final String START_ON_BOOT = "dashboard start on boot"; + final public static String ON_BOOT = "dashboard on boot"; + private ProgressBar mProgressBar; private TextView eipStatus; @@ -90,14 +94,18 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf if (preferences.getString(Provider.KEY, "").isEmpty()) startActivityForResult(new Intent(this,ConfigurationWizard.class),CONFIGURE_LEAP); else - buildDashboard(); + buildDashboard(getIntent().getBooleanExtra(ON_BOOT, false)); } @Override protected void onDestroy() { super.onDestroy(); } - + + protected void onPause() { + super.onPause(); + } + @Override protected void onActivityResult(int requestCode, int resultCode, Intent data){ if ( requestCode == CONFIGURE_LEAP || requestCode == SWITCH_PROVIDER) { @@ -108,7 +116,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf Intent updateEIP = new Intent(getApplicationContext(), EIP.class); updateEIP.setAction(EIP.ACTION_UPDATE_EIP_SERVICE); startService(updateEIP); - buildDashboard(); + buildDashboard(false); invalidateOptionsMenu(); if(data != null && data.hasExtra(LogInDialog.VERB)) { View view = ((ViewGroup)findViewById(android.R.id.content)).getChildAt(0); @@ -152,7 +160,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf * Inflates permanent UI elements of the View and contains logic for what * service dependent UI elements to include. */ - private void buildDashboard() { + private void buildDashboard(boolean hide_and_turn_on_eip) { provider = Provider.getInstance(); provider.init( this ); @@ -167,7 +175,17 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf FragmentManager fragMan = getFragmentManager(); if ( provider.hasEIP()){ EipServiceFragment eipFragment = new EipServiceFragment(); + if (hide_and_turn_on_eip) { + getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE).edit().remove(Dashboard.START_ON_BOOT).commit(); + Bundle arguments = new Bundle(); + arguments.putBoolean(EipServiceFragment.START_ON_BOOT, true); + eipFragment.setArguments(arguments); + } fragMan.beginTransaction().replace(R.id.servicesCollection, eipFragment, EipServiceFragment.TAG).commit(); + + if (hide_and_turn_on_eip) { + onBackPressed(); + } } } @@ -464,9 +482,9 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf // 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); + // eip_intent.putExtra(EIP.RECEIVER_TAG, eip_receiver);fi startService(eip_intent); - + } private void eipStart(){ diff --git a/app/src/main/java/se/leap/bitmaskclient/EIP.java b/app/src/main/java/se/leap/bitmaskclient/EIP.java index e773e3b9..68688b90 100644 --- a/app/src/main/java/se/leap/bitmaskclient/EIP.java +++ b/app/src/main/java/se/leap/bitmaskclient/EIP.java @@ -108,11 +108,12 @@ public final class EIP extends IntentService { @Override public void onDestroy() { - unbindService(mVpnServiceConn); - mBound = false; - - super.onDestroy(); + unbindService(mVpnServiceConn); + mBound = false; + + super.onDestroy(); } + @Override protected void onHandleIntent(Intent intent) { diff --git a/app/src/main/java/se/leap/bitmaskclient/EipServiceFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipServiceFragment.java index b4cb541a..4341c9dc 100644 --- a/app/src/main/java/se/leap/bitmaskclient/EipServiceFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/EipServiceFragment.java @@ -27,6 +27,7 @@ import android.widget.TextView; public class EipServiceFragment extends Fragment implements StateListener, OnCheckedChangeListener { protected static final String IS_EIP_PENDING = "is_eip_pending"; + public static final String START_ON_BOOT = "start on boot"; private View eipFragment; private static Switch eipSwitch; @@ -73,6 +74,8 @@ public class EipServiceFragment extends Fragment implements StateListener, OnChe }); eipSwitch.setOnCheckedChangeListener(this); + if(getArguments() != null && getArguments().containsKey(START_ON_BOOT) && getArguments().getBoolean(START_ON_BOOT)) + startEipFromScratch(); return eipFragment; } @@ -108,24 +111,32 @@ public class EipServiceFragment extends Fragment implements StateListener, OnChe OpenVPN.removeStateListener(this); } - + @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putBoolean(IS_EIP_PENDING, mEipStartPending); } - + + protected void saveEipStatus() { + boolean eip_is_on = false; + Log.d("bitmask", "saveEipStatus"); + if(eipSwitch.isChecked()) { + eip_is_on = true; + } + + if(getActivity() != null) + getActivity().getSharedPreferences(Dashboard.SHARED_PREFERENCES, Activity.MODE_PRIVATE).edit().putBoolean(Dashboard.START_ON_BOOT, eip_is_on).commit(); + } @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + Log.d("bitmask", "onCheckChanged"); if (buttonView.equals(eipSwitch) && !eipAutoSwitched){ boolean allowed_anon = getActivity().getSharedPreferences(Dashboard.SHARED_PREFERENCES, Activity.MODE_PRIVATE).getBoolean(EIP.ALLOWED_ANON, false); String certificate = getActivity().getSharedPreferences(Dashboard.SHARED_PREFERENCES, Activity.MODE_PRIVATE).getString(EIP.CERTIFICATE, ""); if(allowed_anon || !certificate.isEmpty()) { if (isChecked){ - mEipStartPending = true; - eipFragment.findViewById(R.id.eipProgress).setVisibility(View.VISIBLE); - ((TextView) eipFragment.findViewById(R.id.eipStatus)).setText(R.string.eip_status_start_pending); - eipCommand(EIP.ACTION_START_EIP); + startEipFromScratch(); } else { if (mEipStartPending){ AlertDialog.Builder alertBuilder = new AlertDialog.Builder(getActivity()); @@ -165,9 +176,18 @@ public class EipServiceFragment extends Fragment implements StateListener, OnChe eipStatus.setText(R.string.state_noprocess); } eipAutoSwitched = true; + saveEipStatus(); } + public void startEipFromScratch() { + mEipStartPending = true; + eipFragment.findViewById(R.id.eipProgress).setVisibility(View.VISIBLE); + ((TextView) eipFragment.findViewById(R.id.eipStatus)).setText(R.string.eip_status_start_pending); + eipSwitch.setChecked(true); + saveEipStatus(); + eipCommand(EIP.ACTION_START_EIP); + } /** * Send a command to EIP diff --git a/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java b/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java new file mode 100644 index 00000000..eb196d46 --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java @@ -0,0 +1,24 @@ +package se.leap.bitmaskclient; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.util.Log; + + +public class OnBootReceiver extends BroadcastReceiver { + + // Debug: am broadcast -a android.intent.action.BOOT_COMPLETED + @Override + public void onReceive(Context context, Intent intent) { + if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) { + if (!context.getSharedPreferences(Dashboard.SHARED_PREFERENCES, Context.MODE_PRIVATE).getString(Provider.KEY, "").isEmpty() && context.getSharedPreferences(Dashboard.SHARED_PREFERENCES, Context.MODE_PRIVATE).getBoolean(Dashboard.START_ON_BOOT, false)) { + Intent dashboard_intent = new Intent(context, Dashboard.class); + dashboard_intent.setAction(EIP.ACTION_START_EIP); + dashboard_intent.putExtra(Dashboard.ON_BOOT, true); + dashboard_intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(dashboard_intent); + } + } + } +} |