summaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorcyberta <cyberta@riseup.net>2018-02-27 11:12:52 -0800
committercyberta <cyberta@riseup.net>2018-02-27 11:12:52 -0800
commit6d42b38bed78133d200625d8e9242adc0a0f8a28 (patch)
treeb42b84621df2e15ed20f931bab6f470e6795da3d /app/src/main
parent047cbbab96a7eccba08a349b7abb7c8c11538d7c (diff)
parentb047acd0b627c97d4a7a518b4979af8926a4a684 (diff)
Merge branch '8865_cancel_without_internet' into '0.9.8'
8865 - allow disconnect without internet See merge request leap/bitmask_android!50
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/EipFragment.java87
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/EIP.java1
-rw-r--r--app/src/main/res/layout-xlarge/eip_service_fragment.xml26
-rw-r--r--app/src/main/res/layout/eip_service_fragment.xml28
-rw-r--r--app/src/main/res/values/strings.xml1
5 files changed, 90 insertions, 53 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
index 34617af3..34120859 100644
--- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
@@ -29,6 +29,7 @@ import android.os.Bundle;
import android.os.IBinder;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
+import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.AppCompatImageView;
import android.support.v7.widget.AppCompatTextView;
@@ -45,16 +46,22 @@ import java.util.Observer;
import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
+import de.blinkt.openvpn.VpnProfile;
import de.blinkt.openvpn.core.IOpenVPNServiceInternal;
import de.blinkt.openvpn.core.OpenVPNService;
+import de.blinkt.openvpn.core.ProfileManager;
import se.leap.bitmaskclient.eip.EipCommand;
import se.leap.bitmaskclient.eip.EipStatus;
-import se.leap.bitmaskclient.eip.VoidVpnService;
import se.leap.bitmaskclient.views.VpnStateImage;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_NONETWORK;
+import static se.leap.bitmaskclient.Constants.BROADCAST_EIP_EVENT;
+import static se.leap.bitmaskclient.Constants.BROADCAST_RESULT_CODE;
+import static se.leap.bitmaskclient.Constants.BROADCAST_RESULT_KEY;
+import static se.leap.bitmaskclient.Constants.EIP_ACTION_STOP;
+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.REQUEST_CODE_LOG_IN;
@@ -68,7 +75,6 @@ public class EipFragment extends Fragment implements Observer {
public final static String TAG = EipFragment.class.getSimpleName();
- public static final String START_EIP_ON_BOOT = "start on boot";
public static final String ASK_TO_CANCEL_VPN = "ask_to_cancel_vpn";
@@ -101,23 +107,7 @@ public class EipFragment extends Fragment implements Observer {
AlertDialog alertDialog;
private IOpenVPNServiceInternal mService;
- private ServiceConnection openVpnConnection = new ServiceConnection() {
-
-
-
- @Override
- public void onServiceConnected(ComponentName className,
- IBinder service) {
-
- mService = IOpenVPNServiceInternal.Stub.asInterface(service);
- }
-
- @Override
- public void onServiceDisconnected(ComponentName arg0) {
- mService = null;
- }
-
- };
+ private ServiceConnection openVpnConnection;
@Override
public void onAttach(Context context) {
@@ -142,6 +132,7 @@ public class EipFragment extends Fragment implements Observer {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ openVpnConnection = new EipFragmentServiceConnection();
eipStatus = EipStatus.getInstance();
Activity activity = getActivity();
if (activity != null) {
@@ -172,8 +163,8 @@ public class EipFragment extends Fragment implements Observer {
super.onResume();
//FIXME: avoid race conditions while checking certificate an logging in at about the same time
//eipCommand(Constants.EIP_ACTION_CHECK_CERT_VALIDITY);
- handleNewState();
bindOpenVpnService();
+ handleNewState();
}
@Override
@@ -231,7 +222,7 @@ public class EipFragment extends Fragment implements Observer {
}
void handleIcon() {
- if (eipStatus.isConnected() || eipStatus.isConnecting())
+ if (isOpenVpnRunningWithoutNetwork() || eipStatus.isConnected() || eipStatus.isConnecting())
handleSwitchOff();
else
handleSwitchOn();
@@ -267,7 +258,7 @@ public class EipFragment extends Fragment implements Observer {
}
private void handleSwitchOff() {
- if (eipStatus.isConnecting()) {
+ if (isOpenVpnRunningWithoutNetwork() || eipStatus.isConnecting()) {
askPendingStartCancellation();
} else if (eipStatus.isConnected()) {
askToStopEIP();
@@ -291,7 +282,20 @@ public class EipFragment extends Fragment implements Observer {
protected void stopEipIfPossible() {
Context context = getContext();
if (context != null) {
- EipCommand.stopVPN(getContext());
+ if (isOpenVpnRunningWithoutNetwork()) {
+ // TODO move to EIP
+ // TODO see stopEIP function
+ Bundle resultData = new Bundle();
+ resultData.putString(EIP_REQUEST, EIP_ACTION_STOP);
+ Intent intentUpdate = new Intent(BROADCAST_EIP_EVENT);
+ intentUpdate.addCategory(Intent.CATEGORY_DEFAULT);
+ intentUpdate.putExtra(BROADCAST_RESULT_CODE, Activity.RESULT_OK);
+ intentUpdate.putExtra(BROADCAST_RESULT_KEY, resultData);
+ Log.d(TAG, "sending broadcast");
+ LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(intentUpdate);
+ } else {
+ EipCommand.stopVPN(getContext());
+ }
} else {
Log.e(TAG, "context is null when trying to stop EIP");
}
@@ -387,14 +391,24 @@ public class EipFragment extends Fragment implements Observer {
routedText.setVisibility(GONE);
vpnRoute.setVisibility(GONE);
colorBackgroundALittle();
- } else if (eipStatus.isConnected() || isOpenVpnRunningWithoutNetwork()) {
+ } else if (eipStatus.isConnected() ) {
mainButton.setText(activity.getString(R.string.vpn_button_turn_off));
vpnStateImage.setStateIcon(R.drawable.vpn_connected);
vpnStateImage.stopProgress(true);
+ routedText.setText(R.string.vpn_securely_routed);
routedText.setVisibility(VISIBLE);
vpnRoute.setVisibility(VISIBLE);
- vpnRoute.setText(ConfigHelper.getProviderName(preferences));
+ setVpnRouteText();
colorBackground();
+ } else if(isOpenVpnRunningWithoutNetwork()){
+ mainButton.setText(activity.getString(R.string.vpn_button_turn_off));
+ vpnStateImage.setStateIcon(R.drawable.vpn_disconnected);
+ vpnStateImage.stopProgress(true);
+ routedText.setText(R.string.vpn_securely_routed_no_internet);
+ routedText.setVisibility(VISIBLE);
+ vpnRoute.setVisibility(VISIBLE);
+ setVpnRouteText();
+ colorBackgroundALittle();
} else {
mainButton.setText(activity.getString(R.string.vpn_button_turn_on));
vpnStateImage.setStateIcon(R.drawable.vpn_disconnected);
@@ -466,4 +480,27 @@ public class EipFragment extends Fragment implements Observer {
activity.startActivityForResult(intent, REQUEST_CODE_LOG_IN);
}
}
+
+ private void setVpnRouteText() {
+ String vpnRouteString = provider.getName();
+ VpnProfile vpnProfile = ProfileManager.getLastConnectedVpn();
+ if (vpnProfile != null && vpnProfile.mName != null) {
+ vpnRouteString += " (" + vpnProfile.mName + ")";
+ }
+ vpnRoute.setText(vpnRouteString);
+ }
+
+ private class EipFragmentServiceConnection implements ServiceConnection {
+ @Override
+ public void onServiceConnected(ComponentName className,
+ IBinder service) {
+ mService = IOpenVPNServiceInternal.Stub.asInterface(service);
+ handleNewState();
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName arg0) {
+ mService = null;
+ }
+ }
}
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 5cf180d3..665e0ebd 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
@@ -184,6 +184,7 @@ public final class EIP extends IntentService {
private void stopEIP() {
// TODO stop eip from here if possible...
+ // TODO then refactor EipFragment.handleSwitchOff
EipStatus eipStatus = EipStatus.getInstance();
int resultCode = RESULT_CANCELED;
if (eipStatus.isConnected() || eipStatus.isConnecting())
diff --git a/app/src/main/res/layout-xlarge/eip_service_fragment.xml b/app/src/main/res/layout-xlarge/eip_service_fragment.xml
index c09bda2d..2326ffe8 100644
--- a/app/src/main/res/layout-xlarge/eip_service_fragment.xml
+++ b/app/src/main/res/layout-xlarge/eip_service_fragment.xml
@@ -58,11 +58,10 @@
android:id="@+id/eipLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_marginEnd="@dimen/stdpadding"
- android:layout_marginStart="@dimen/stdpadding"
- android:layout_marginTop="@dimen/stdpadding"
- android:layout_marginLeft="@dimen/stdpadding"
- android:layout_marginRight="@dimen/stdpadding"
+ android:paddingLeft="@dimen/stdpadding"
+ android:paddingRight="@dimen/stdpadding"
+ android:paddingStart="@dimen/stdpadding"
+ android:paddingEnd="@dimen/stdpadding"
android:text="@string/eip_service_label"
android:textAppearance="?android:attr/textAppearanceMedium"
android:gravity="center"
@@ -102,11 +101,10 @@
android:id="@+id/routed_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_marginEnd="@dimen/stdpadding"
- android:layout_marginStart="@dimen/stdpadding"
- android:layout_marginTop="@dimen/stdpadding"
- android:layout_marginLeft="@dimen/stdpadding"
- android:layout_marginRight="@dimen/stdpadding"
+ android:paddingLeft="@dimen/stdpadding"
+ android:paddingRight="@dimen/stdpadding"
+ android:paddingStart="@dimen/stdpadding"
+ android:paddingEnd="@dimen/stdpadding"
android:text="@string/vpn_securely_routed"
android:gravity="center"
android:visibility="visible"
@@ -118,10 +116,10 @@
android:id="@+id/vpn_route"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_marginEnd="@dimen/stdpadding"
- android:layout_marginStart="@dimen/stdpadding"
- android:layout_marginLeft="@dimen/stdpadding"
- android:layout_marginRight="@dimen/stdpadding"
+ android:paddingLeft="@dimen/stdpadding"
+ android:paddingRight="@dimen/stdpadding"
+ android:paddingStart="@dimen/stdpadding"
+ android:paddingEnd="@dimen/stdpadding"
android:gravity="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
diff --git a/app/src/main/res/layout/eip_service_fragment.xml b/app/src/main/res/layout/eip_service_fragment.xml
index 30b94de9..e220bf16 100644
--- a/app/src/main/res/layout/eip_service_fragment.xml
+++ b/app/src/main/res/layout/eip_service_fragment.xml
@@ -56,11 +56,11 @@
android:id="@+id/eipLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_marginEnd="@dimen/stdpadding"
- android:layout_marginStart="@dimen/stdpadding"
- android:layout_marginTop="@dimen/stdpadding"
- android:layout_marginLeft="@dimen/stdpadding"
- android:layout_marginRight="@dimen/stdpadding"
+ android:paddingLeft="@dimen/stdpadding"
+ android:paddingRight="@dimen/stdpadding"
+ android:paddingStart="@dimen/stdpadding"
+ android:paddingEnd="@dimen/stdpadding"
+ android:paddingTop="@dimen/stdpadding"
android:text="@string/eip_service_label"
android:textAppearance="?android:attr/textAppearanceMedium"
android:gravity="center"
@@ -102,11 +102,11 @@
android:id="@+id/routed_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_marginEnd="@dimen/stdpadding"
- android:layout_marginStart="@dimen/stdpadding"
- android:layout_marginTop="@dimen/stdpadding"
- android:layout_marginLeft="@dimen/stdpadding"
- android:layout_marginRight="@dimen/stdpadding"
+ android:paddingLeft="@dimen/stdpadding"
+ android:paddingRight="@dimen/stdpadding"
+ android:paddingStart="@dimen/stdpadding"
+ android:paddingEnd="@dimen/stdpadding"
+ android:paddingTop="@dimen/stdpadding"
android:text="@string/vpn_securely_routed"
android:gravity="center"
android:visibility="visible"
@@ -118,10 +118,10 @@
android:id="@+id/vpn_route"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_marginEnd="@dimen/stdpadding"
- android:layout_marginStart="@dimen/stdpadding"
- android:layout_marginLeft="@dimen/stdpadding"
- android:layout_marginRight="@dimen/stdpadding"
+ android:paddingLeft="@dimen/stdpadding"
+ android:paddingRight="@dimen/stdpadding"
+ android:paddingStart="@dimen/stdpadding"
+ android:paddingEnd="@dimen/stdpadding"
android:gravity="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index a0ca00c9..71b6d437 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -85,6 +85,7 @@
<string name="vpn.button.turn.off">Turn off</string>
<string name="vpn_button_turn_off_blocking">Stop blocking</string>
<string name="vpn_securely_routed">Your traffic is securely routed through:</string>
+ <string name="vpn_securely_routed_no_internet">No internet connection. Your traffic will be securely routed through:</string>
<string name="bitmask_log">Bitmask Log</string>
<string name="title_activity_main">Bitmask</string>
<string name="log_fragment_title">Log</string>