diff options
author | cyBerta <cyberta@riseup.net> | 2017-10-02 17:53:35 +0200 |
---|---|---|
committer | cyBerta <cyberta@riseup.net> | 2017-10-13 12:47:11 +0200 |
commit | 11a11f25e0981d51dd19ee3e7849de1a9f563ec4 (patch) | |
tree | 823938fd9a505bea03582cadcf6790646204a4be | |
parent | adc6f7672c380d534fc963d868fe5aebcab54b4a (diff) |
#8759 one cancellation dialog should be sufficient
-rw-r--r-- | app/src/main/AndroidManifest.xml | 2 | ||||
-rw-r--r-- | app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java | 8 | ||||
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/Dashboard.java | 26 | ||||
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/VpnFragment.java | 64 | ||||
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/eip/EIP.java | 2 | ||||
m--------- | ics-openvpn | 0 |
6 files changed, 84 insertions, 18 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 025c98f0..67fd0a1a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -85,7 +85,7 @@ android:name="se.leap.bitmaskclient.Dashboard" android:label="@string/title_activity_dashboard" android:uiOptions="splitActionBarWhenNarrow" - android:launchMode="singleTask" + android:launchMode="singleTop" > <intent-filter android:label="@string/app_name"> diff --git a/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java b/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java index 5faa1de4..835e69b3 100644 --- a/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java +++ b/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java @@ -322,9 +322,11 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac } - Intent disconnectVPN = new Intent(this, DisconnectVPN.class); - disconnectVPN.setAction(DISCONNECT_VPN); - PendingIntent disconnectPendingIntent = PendingIntent.getActivity(this, 0, disconnectVPN, 0); + Intent disconnectVPN = new Intent(this, Dashboard.class); + disconnectVPN.putExtra(Dashboard.ACTION_ASK_TO_CANCEL_VPN, true); + disconnectVPN.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | + Intent.FLAG_ACTIVITY_SINGLE_TOP); + PendingIntent disconnectPendingIntent = PendingIntent.getActivity(this, 0, disconnectVPN, PendingIntent.FLAG_CANCEL_CURRENT); nbuilder.addAction(R.drawable.ic_menu_close_clear_cancel, getString(R.string.cancel_connection), disconnectPendingIntent); diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java index dbdf0a51..a6a3717b 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java +++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java @@ -66,9 +66,11 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec public static final String TAG = Dashboard.class.getSimpleName(); public static final String SHARED_PREFERENCES = "LEAPPreferences"; public static final String ACTION_QUIT = "quit"; + public static final String ACTION_ASK_TO_CANCEL_VPN = "ask to cancel vpn"; 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"; + //FIXME: remove OR FIX ON_BOOT public static final String ON_BOOT = "dashboard on boot"; public static final String APP_VERSION = "bitmask version"; @@ -116,6 +118,12 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec } } + @Override + protected void onResume() { + super.onResume(); + handleVPNCancellation(getIntent()); + } + private boolean previousProviderExists(Bundle savedInstanceState) { return providerInSavedInstance(savedInstanceState) || providerInSharedPreferences(); } @@ -176,6 +184,13 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec } @Override + protected void onNewIntent(Intent intent) { + super.onNewIntent(intent); + setIntent(intent); + handleVPNCancellation(intent); + } + + @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == CONFIGURE_LEAP || requestCode == SWITCH_PROVIDER) { if (resultCode == RESULT_OK && data.hasExtra(Provider.KEY)) { @@ -192,8 +207,13 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec finish(); } else configErrorDialog(); - } else if (requestCode == EIP.DISCONNECT) { - EipStatus.getInstance().setConnectedOrDisconnected(); + } + } + + private void handleVPNCancellation(Intent intent) { + if (intent.hasExtra(Dashboard.ACTION_ASK_TO_CANCEL_VPN)) { + eip_fragment.askToStopEIP(); + intent.removeExtra(ACTION_ASK_TO_CANCEL_VPN); } } @@ -247,7 +267,9 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec eip_fragment = new VpnFragment(); if (hide_and_turn_on_eip) { + //TODO: remove line below if not in use anymore... preferences.edit().remove(Dashboard.START_ON_BOOT).apply(); + //FIXME: always start on Boot? Why do we keep shared preferences then? Bundle arguments = new Bundle(); arguments.putBoolean(VpnFragment.START_ON_BOOT, true); if (eip_fragment != null) eip_fragment.setArguments(arguments); diff --git a/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java b/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java index 9e9adef1..8cd9fa0f 100644 --- a/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java @@ -19,7 +19,6 @@ package se.leap.bitmaskclient; import android.app.*; import android.content.*; import android.os.*; -import android.util.Log; import android.view.*; import android.widget.*; @@ -28,7 +27,10 @@ import org.jetbrains.annotations.*; import java.util.*; import butterknife.*; -import de.blinkt.openvpn.activities.*; +import de.blinkt.openvpn.core.IOpenVPNServiceInternal; +import de.blinkt.openvpn.core.OpenVPNService; +import de.blinkt.openvpn.core.ProfileManager; +import de.blinkt.openvpn.core.VpnStatus; import mbanje.kurt.fabbutton.*; import se.leap.bitmaskclient.eip.*; @@ -50,15 +52,31 @@ public class VpnFragment extends Fragment implements Observer { private static EipStatus eip_status; private boolean wants_to_connect; + 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; + } + + }; + //FIXME: replace with onAttach(Context context) public void onAttach(Activity activity) { super.onAttach(activity); dashboard = (Dashboard) activity; - ProviderAPIResultReceiver provider_api_receiver = new ProviderAPIResultReceiver(new Handler(), dashboard); - - if(eip_receiver != null) - ProviderAPICommand.execute(Bundle.EMPTY, ProviderAPI.DOWNLOAD_EIP_SERVICE, provider_api_receiver); + downloadEIPServiceConfig(); } @Override @@ -95,6 +113,13 @@ public class VpnFragment extends Fragment implements Observer { //FIXME: avoid race conditions while checking certificate an logging in at about the same time //eipCommand(Constants.ACTION_CHECK_CERT_VALIDITY); handleNewState(eip_status); + bindOpenVpnService(); + } + + @Override + public void onPause() { + super.onPause(); + dashboard.unbindService(openVpnConnection); } @Override @@ -104,7 +129,7 @@ public class VpnFragment extends Fragment implements Observer { super.onSaveInstanceState(outState); } - protected void saveStatus() { + private void saveStatus() { boolean is_on = eip_status.isConnected() || eip_status.isConnecting(); Dashboard.preferences.edit().putBoolean(Dashboard.START_ON_BOOT, is_on).commit(); } @@ -184,16 +209,29 @@ public class VpnFragment extends Fragment implements Observer { } private void disconnect() { - Intent disconnect_vpn = new Intent(dashboard, DisconnectVPN.class); - dashboard.startActivityForResult(disconnect_vpn, EIP.DISCONNECT); eip_status.setDisconnecting(); + ProfileManager.setConntectedVpnProfileDisconnected(dashboard); + if (mService != null) { + try { + mService.stopVPN(false); + eip_status.setConnectedOrDisconnected(); + } catch (RemoteException e) { + VpnStatus.logException(e); + } + } } protected void stopEipIfPossible() { eipCommand(Constants.ACTION_STOP_EIP); } - private void askToStopEIP() { + private void downloadEIPServiceConfig() { + ProviderAPIResultReceiver provider_api_receiver = new ProviderAPIResultReceiver(new Handler(), dashboard); + if(eip_receiver != null) + ProviderAPICommand.execute(Bundle.EMPTY, ProviderAPI.DOWNLOAD_EIP_SERVICE, provider_api_receiver); + } + + protected void askToStopEIP() { AlertDialog.Builder alertBuilder = new AlertDialog.Builder(dashboard); alertBuilder.setTitle(dashboard.getString(R.string.eip_cancel_connect_title)) .setMessage(dashboard.getString(R.string.eip_warning_browser_inconsistency)) @@ -282,6 +320,12 @@ public class VpnFragment extends Fragment implements Observer { } } + private void bindOpenVpnService() { + Intent intent = new Intent(dashboard, OpenVPNService.class); + intent.setAction(OpenVPNService.START_SERVICE); + dashboard.bindService(intent, openVpnConnection, Context.BIND_AUTO_CREATE); + } + protected class EIPReceiver extends ResultReceiver { protected EIPReceiver(Handler handler) { 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 5b72a4e7..428ac706 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java @@ -42,8 +42,6 @@ public final class EIP extends IntentService { public final static String TAG = EIP.class.getSimpleName(); public final static String SERVICE_API_PATH = "config/eip-service.json"; - public static final int DISCONNECT = 15; - private static Context context; private static ResultReceiver mReceiver; private static SharedPreferences preferences; diff --git a/ics-openvpn b/ics-openvpn -Subproject 05b9a9ce15dc139a7ff97b3052dec8fd2e3207e +Subproject 455ec6337157118b6d2e49808f25fd80d164956 |