summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2014-11-20 19:48:54 +0100
committerParménides GV <parmegv@sdf.org>2014-11-20 19:57:14 +0100
commit8f37e6f940ae4034458a1d9d39dc5ffe4ff70848 (patch)
tree780ef64c3fbcb9433139f13c02a3993a6a1bb632 /app/src/main/java
parent5870156057b9d1f6f0bd8c22824b7e0fd8ec300b (diff)
Update gateways after downloading certificate.
If the certificate is from an authenticated user, autostart eip. If not, show that the certificate has been updated.
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/Dashboard.java53
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/EIP.java3
2 files changed, 34 insertions, 22 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
index 547e4179..49614a6f 100644
--- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
+++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
@@ -135,21 +135,23 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
}
@Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data){
+ protected void onActivityResult(int requestCode, int resultCode, final 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 ){
- preferences.edit().putInt(EIP.PARSED_SERIAL, 0).commit();
- preferences.edit().putBoolean(EIP.AUTHED_EIP, authed_eip).commit();
- Intent updateEIP = new Intent(getApplicationContext(), EIP.class);
- updateEIP.setAction(EIP.ACTION_UPDATE_EIP_SERVICE);
- startService(updateEIP);
- buildDashboard(false);
- invalidateOptionsMenu();
- if(data != null && data.hasExtra(LogInDialog.TAG)) {
- View view = ((ViewGroup)findViewById(android.R.id.content)).getChildAt(0);
- logInDialog(Bundle.EMPTY);
- }
+ if ( resultCode == RESULT_OK ){
+ preferences.edit().putInt(EIP.PARSED_SERIAL, 0).commit();
+ preferences.edit().putBoolean(EIP.AUTHED_EIP, authed_eip).commit();
+
+ Intent updateEIP = new Intent(getApplicationContext(), EIP.class);
+ updateEIP.setAction(EIP.ACTION_UPDATE_EIP_SERVICE);
+ startService(updateEIP);
+
+ buildDashboard(false);
+ invalidateOptionsMenu();
+ if(data != null && data.hasExtra(LogInDialog.TAG)) {
+ View view = ((ViewGroup)findViewById(android.R.id.content)).getChildAt(0);
+ logInDialog(Bundle.EMPTY);
+ }
} else if(resultCode == RESULT_CANCELED && (data == null || data.hasExtra(ACTION_QUIT))) {
finish();
} else
@@ -451,7 +453,22 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
hideProgressBar();
setResult(RESULT_OK);
- eipStart();
+ Intent updateEIP = new Intent(getApplicationContext(), EIP.class);
+ ResultReceiver eip_receiver = new ResultReceiver(new Handler()){
+ protected void onReceiveResult(int resultCode, Bundle resultData){
+ super.onReceiveResult(resultCode, resultData);
+ String request = resultData.getString(EIP.REQUEST_TAG);
+ if (resultCode == Activity.RESULT_OK){
+ if(authed_eip)
+ eipStart();
+ else
+ eipStatus.setText("Certificate updated");
+ }
+ }
+ };
+ updateEIP.putExtra(EIP.RECEIVER_TAG, eip_receiver);
+ updateEIP.setAction(EIP.ACTION_UPDATE_EIP_SERVICE);
+ startService(updateEIP);
} else if(resultCode == ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE) {
changeStatusMessage(resultCode);
hideProgressBar();
@@ -523,13 +540,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
intent.putExtra(Dashboard.REQUEST_CODE, requestCode);
super.startActivityForResult(intent, requestCode);
}
-
- /**
- * Send a command to EIP
- *
- * @param action A valid String constant from EIP class representing an Intent
- * filter for the EIP class
- */
+
private void eipIsRunning(ResultReceiver eip_receiver){
// 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);
diff --git a/app/src/main/java/se/leap/bitmaskclient/EIP.java b/app/src/main/java/se/leap/bitmaskclient/EIP.java
index 00a0afb0..0d11847e 100644
--- a/app/src/main/java/se/leap/bitmaskclient/EIP.java
+++ b/app/src/main/java/se/leap/bitmaskclient/EIP.java
@@ -324,6 +324,7 @@ public final class EIP extends IntentService {
}
deleteAllVpnProfiles();
updateGateways();
+ if(mReceiver != null) mReceiver.send(Activity.RESULT_OK, Bundle.EMPTY);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@@ -394,7 +395,7 @@ public final class EIP extends IntentService {
Calendar offset_date = Calendar.getInstance();
try {
Date date = certificate_date_format.parse(date_string);
- long difference = Math.abs(date.getTime() - certificate.getNotAfter().getTime())/2;
+ long difference = Math.abs(date.getTime() - certificate.getNotAfter().getTime())/2;
long current_date_millis = offset_date.getTimeInMillis();
offset_date.setTimeInMillis(current_date_millis + difference);
Log.d(TAG, "certificate not after = " + certificate.getNotAfter());