diff options
author | fupduck <fupduck@riseup.net> | 2018-02-08 10:45:45 -0800 |
---|---|---|
committer | fupduck <fupduck@riseup.net> | 2018-02-08 10:45:45 -0800 |
commit | 95039d6444fc84908a0d4399947738f0399108c7 (patch) | |
tree | 17dd25e0b17e50358cef4e464fa4bc2503cc2859 /app | |
parent | ae938c20a11b6195936f97eebd32abd35335bceb (diff) | |
parent | 6770f041300fa592dfb93fb4296c55218c05cc45 (diff) |
Merge branch '#8830_onBoot_alwaysOn' into '0.9.8'
#8830 on boot always on
See merge request leap/bitmask_android!39
Diffstat (limited to 'app')
7 files changed, 46 insertions, 30 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/ConfigHelper.java b/app/src/main/java/se/leap/bitmaskclient/ConfigHelper.java index 741a6f56..22965252 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ConfigHelper.java +++ b/app/src/main/java/se/leap/bitmaskclient/ConfigHelper.java @@ -21,7 +21,6 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.util.Log; -import org.jetbrains.annotations.NotNull; import org.json.JSONException; import org.json.JSONObject; import org.spongycastle.util.encoders.Base64; diff --git a/app/src/main/java/se/leap/bitmaskclient/Constants.java b/app/src/main/java/se/leap/bitmaskclient/Constants.java index 7ee3adab..acfddf5d 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Constants.java +++ b/app/src/main/java/se/leap/bitmaskclient/Constants.java @@ -36,7 +36,7 @@ public interface Constants { String EIP_ACTION_STOP = "se.leap.bitmaskclient.EIP.STOP"; String EIP_ACTION_UPDATE = "se.leap.bitmaskclient.EIP.UPDATE"; String EIP_ACTION_IS_RUNNING = "se.leap.bitmaskclient.EIP.IS_RUNNING"; - String EIP_ACTION_START_ALWAYS_ON_EIP = "se.leap.bitmaskclient.START_ALWAYS_ON_EIP"; + String EIP_ACTION_START_ALWAYS_ON_VPN = "se.leap.bitmaskclient.START_ALWAYS_ON_VPN"; String EIP_ACTION_START_BLOCKING_VPN = "se.leap.bitmaskclient.EIP_ACTION_START_BLOCKING_VPN"; String EIP_ACTION_STOP_BLOCKING_VPN = "se.leap.bitmaskclient.EIP_ACTION_STOP_BLOCKING_VPN"; diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java index c0e2c21e..844bfd7d 100644 --- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java @@ -53,7 +53,6 @@ import de.blinkt.openvpn.core.VpnStatus; import se.leap.bitmaskclient.eip.EIP; import se.leap.bitmaskclient.eip.EipStatus; import se.leap.bitmaskclient.eip.VoidVpnService; -import se.leap.bitmaskclient.userstatus.SessionDialog; import static android.view.View.GONE; import static android.view.View.VISIBLE; @@ -145,12 +144,8 @@ public class EipFragment extends Fragment implements Observer { ButterKnife.inject(this, view); Bundle arguments = getArguments(); - if (arguments != null) { - if (arguments.containsKey(START_EIP_ON_BOOT) && arguments.getBoolean(START_EIP_ON_BOOT)) { - startEipFromScratch(); - } else if (arguments.containsKey(ASK_TO_CANCEL_VPN) && arguments.getBoolean(ASK_TO_CANCEL_VPN)) { - askToStopEIP(); - } + if (arguments != null && arguments.containsKey(ASK_TO_CANCEL_VPN) && arguments.getBoolean(ASK_TO_CANCEL_VPN)) { + askToStopEIP(); } return view; } diff --git a/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java b/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java index 2a8aa42f..95828e46 100644 --- a/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java +++ b/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java @@ -35,14 +35,15 @@ public class OnBootReceiver extends BroadcastReceiver { return; } if (startOnBoot) { - Intent dashboardIntent = new Intent(context, Dashboard.class); - dashboardIntent.putExtra(EIP_RESTART_ON_BOOT, true); - dashboardIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - context.startActivity(dashboardIntent); + Log.d("OpenVpn", "start StartActivity!"); + Intent startActivityIntent = new Intent(context, StartActivity.class); + startActivityIntent.putExtra(EIP_RESTART_ON_BOOT, true); + startActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(startActivityIntent); } } else { if (isAlwaysOnConfigured) { - Intent dashboardIntent = new Intent(context, Dashboard.class); + Intent dashboardIntent = new Intent(context, StartActivity.class); dashboardIntent.putExtra(APP_ACTION_CONFIGURE_ALWAYS_ON_PROFILE, true); dashboardIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(dashboardIntent); diff --git a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java index 2d107c27..e4758ac9 100644 --- a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java @@ -13,13 +13,16 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import de.blinkt.openvpn.core.VpnStatus; +import se.leap.bitmaskclient.eip.EIP; import se.leap.bitmaskclient.userstatus.User; -import static android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP; import static se.leap.bitmaskclient.Constants.APP_ACTION_CONFIGURE_ALWAYS_ON_PROFILE; +import static se.leap.bitmaskclient.Constants.EIP_ACTION_START; +import static se.leap.bitmaskclient.Constants.EIP_RESTART_ON_BOOT; import static se.leap.bitmaskclient.Constants.PREFERENCES_APP_VERSION; import static se.leap.bitmaskclient.Constants.REQUEST_CODE_CONFIGURE_LEAP; import static se.leap.bitmaskclient.Constants.SHARED_PREFERENCES; +import static se.leap.bitmaskclient.MainActivity.ACTION_SHOW_VPN_FRAGMENT; /** * Activity shown at startup. Evaluates if App is started for the first time or has been upgraded @@ -27,7 +30,7 @@ import static se.leap.bitmaskclient.Constants.SHARED_PREFERENCES; * */ public class StartActivity extends Activity { - public static final String TAG = Dashboard.class.getSimpleName(); + public static final String TAG = StartActivity.class.getSimpleName(); @Retention(RetentionPolicy.SOURCE) @IntDef({FIRST, NORMAL, UPGRADE, DOWNGRADE}) @@ -151,9 +154,11 @@ public class StartActivity extends Activity { configureLeapProvider(); } else { Log.d(TAG, "vpn provider is configured"); - - //buildDashboard(getIntent().getBooleanExtra(EIP_RESTART_ON_BOOT, false)); -// user_status_fragment.restoreSessionStatus(savedInstanceState); + if (getIntent() != null && getIntent().getBooleanExtra(EIP_RESTART_ON_BOOT, false)) { + eipCommand(EIP_ACTION_START); + finish(); + return; + } showMainActivity(); } } else { @@ -178,7 +183,7 @@ public class StartActivity extends Activity { if (resultCode == RESULT_OK && data.hasExtra(Provider.KEY)) { Provider provider = data.getParcelableExtra(Provider.KEY); ConfigHelper.storeProviderInPreferences(preferences, provider); - + eipCommand(EIP_ACTION_START); showMainActivity(); } else if (resultCode == RESULT_CANCELED) { finish(); @@ -189,9 +194,21 @@ public class StartActivity extends Activity { private void showMainActivity() { Intent intent = new Intent(this, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); - intent.setAction(MainActivity.ACTION_SHOW_VPN_FRAGMENT); + intent.setAction(ACTION_SHOW_VPN_FRAGMENT); startActivity(intent); finish(); } + + /** + * Send a command to EIP + * + * @param action A valid String constant from EIP class representing an Intent + * filter for the EIP class + */ + private void eipCommand(String action) { + Intent vpn_intent = new Intent(this.getApplicationContext(), EIP.class); + vpn_intent.setAction(action); + this.startService(vpn_intent); + } } diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java index 23b4f2de..b8858c1e 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java @@ -35,11 +35,12 @@ import se.leap.bitmaskclient.OnBootReceiver; import static se.leap.bitmaskclient.Constants.EIP_ACTION_CHECK_CERT_VALIDITY; import static se.leap.bitmaskclient.Constants.EIP_ACTION_IS_RUNNING; import static se.leap.bitmaskclient.Constants.EIP_ACTION_START; -import static se.leap.bitmaskclient.Constants.EIP_ACTION_START_ALWAYS_ON_EIP; +import static se.leap.bitmaskclient.Constants.EIP_ACTION_START_ALWAYS_ON_VPN; import static se.leap.bitmaskclient.Constants.EIP_ACTION_STOP; import static se.leap.bitmaskclient.Constants.EIP_ACTION_UPDATE; import static se.leap.bitmaskclient.Constants.EIP_RECEIVER; import static se.leap.bitmaskclient.Constants.EIP_REQUEST; +import static se.leap.bitmaskclient.Constants.EIP_RESTART_ON_BOOT; import static se.leap.bitmaskclient.Constants.PROVIDER_KEY; import static se.leap.bitmaskclient.Constants.PROVIDER_VPN_CERTIFICATE; import static se.leap.bitmaskclient.Constants.SHARED_PREFERENCES; @@ -94,8 +95,8 @@ public final class EIP extends IntentService { case EIP_ACTION_START: startEIP(); break; - case EIP_ACTION_START_ALWAYS_ON_EIP: - startAlwaysOnEIP(); + case EIP_ACTION_START_ALWAYS_ON_VPN: + startEIPAlwaysOnVpn(); break; case EIP_ACTION_STOP: stopEIP(); @@ -118,6 +119,9 @@ public final class EIP extends IntentService { * It also sets up early routes. */ private void startEIP() { + if (!preferences.getBoolean(EIP_RESTART_ON_BOOT, false)){ + preferences.edit().putBoolean(EIP_RESTART_ON_BOOT, true).commit(); + } if (gatewaysManager.isEmpty()) updateEIPService(); if (!EipStatus.getInstance().isBlockingVpnEstablished()) { @@ -136,8 +140,8 @@ public final class EIP extends IntentService { * Tries to start the last used vpn profile when the OS was rebooted and always-on-VPN is enabled. * The {@link OnBootReceiver} will care if there is no profile. */ - private void startAlwaysOnEIP() { - Log.d(TAG, "startAlwaysOnEIP vpn"); + private void startEIPAlwaysOnVpn() { + Log.d(TAG, "startEIPAlwaysOnVpn vpn"); if (gatewaysManager.isEmpty()) updateEIPService(); @@ -145,10 +149,10 @@ public final class EIP extends IntentService { gateway = gatewaysManager.select(); if (gateway != null && gateway.getProfile() != null) { - Log.d(TAG, "startAlwaysOnEIP eip launch avtive gateway vpn"); + Log.d(TAG, "startEIPAlwaysOnVpn eip launch avtive gateway vpn"); launchActiveGateway(); } else { - Log.d(TAG, "startAlwaysOnEIP no active profile available!"); + Log.d(TAG, "startEIPAlwaysOnVpn no active profile available!"); } } diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java index 6d49d83d..76d5fb8e 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java @@ -33,7 +33,7 @@ import de.blinkt.openvpn.core.VpnStatus; import se.leap.bitmaskclient.R; import se.leap.bitmaskclient.VpnNotificationManager; -import static se.leap.bitmaskclient.Constants.EIP_ACTION_START_ALWAYS_ON_EIP; +import static se.leap.bitmaskclient.Constants.EIP_ACTION_START_ALWAYS_ON_VPN; import static se.leap.bitmaskclient.Constants.EIP_ACTION_START_BLOCKING_VPN; import static se.leap.bitmaskclient.Constants.EIP_ACTION_STOP_BLOCKING_VPN; import static se.leap.bitmaskclient.Constants.EIP_IS_ALWAYS_ON; @@ -150,7 +150,7 @@ public class VoidVpnService extends VpnService implements Observer, VpnNotificat private void requestVpnWithLastSelectedProfile() { Intent startEIP = new Intent(getApplicationContext(), EIP.class); - startEIP.setAction(EIP_ACTION_START_ALWAYS_ON_EIP); + startEIP.setAction(EIP_ACTION_START_ALWAYS_ON_VPN); getApplicationContext().startService(startEIP); } |