From d5d728338694cac72c145017de4f7b969d974e65 Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Wed, 16 Mar 2022 11:45:30 +0100 Subject: Add intents for pausing/resuming VPN (closes #1460) --- README.md | 10 ++++- main/src/main/AndroidManifest.xml | 9 +++++ .../java/de/blinkt/openvpn/api/RemoteAction.java | 47 +++++++++++++--------- 3 files changed, 45 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 23d92204..2a2e2e06 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,15 @@ You can find the FAQ here (same as in app): https://ics-openvpn.blinkt.de/FAQ.ht Controlling from external apps ------------------------------ -There is the AIDL API for real controlling (see developing section). Due to high demand also the Activities `de.blinkt.openvpn.api.DisconnectVPN` and `de.blinkt.openvpn.api.ConnectVPN` exist. It uses `de.blinkt.openvpn.api.profileName` as extra for the name of the VPN profile. +There is the AIDL API for real controlling (see developing section). Due to high demand also +acitvies to start/stop, pause/resume (like a user would with the notification) exists + + - `de.blinkt.openvpn.api.DisconnectVPN` + - `de.blinkt.openvpn.api.ConnectVPN` + - `de.blinkt.openvpn.api.PauseVPN` + - `de.blinkt.openvpn.api.ResumeVPN` + +They use `de.blinkt.openvpn.api.profileName` as extra for the name of the VPN profile.. Note to administrators ------------------------ diff --git a/main/src/main/AndroidManifest.xml b/main/src/main/AndroidManifest.xml index 7ff33676..6cfbfffa 100644 --- a/main/src/main/AndroidManifest.xml +++ b/main/src/main/AndroidManifest.xml @@ -126,6 +126,15 @@ android:name=".api.DisconnectVPN" android:exported="true" android:targetActivity=".api.RemoteAction" /> + + + \ No newline at end of file diff --git a/main/src/main/java/de/blinkt/openvpn/api/RemoteAction.java b/main/src/main/java/de/blinkt/openvpn/api/RemoteAction.java index ebd2fe44..0554b88c 100644 --- a/main/src/main/java/de/blinkt/openvpn/api/RemoteAction.java +++ b/main/src/main/java/de/blinkt/openvpn/api/RemoteAction.java @@ -24,10 +24,9 @@ import de.blinkt.openvpn.core.ProfileManager; public class RemoteAction extends Activity { public static final String EXTRA_NAME = "de.blinkt.openvpn.api.profileName"; - private ExternalAppDatabase mExtAppDb; private boolean mDoDisconnect; private IOpenVPNServiceInternal mService; - private ServiceConnection mConnection = new ServiceConnection() { + private final ServiceConnection mConnection = new ServiceConnection() { @Override public void onServiceConnected(ComponentName className, IBinder service) { @@ -50,8 +49,6 @@ public class RemoteAction extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - - mExtAppDb = new ExternalAppDatabase(this); } @Override @@ -74,24 +71,34 @@ public class RemoteAction extends Activity { Intent intent = getIntent(); setIntent(null); ComponentName component = intent.getComponent(); - if (component.getShortClassName().equals(".api.DisconnectVPN")) { - mService.stopVPN(false); - } else if (component.getShortClassName().equals(".api.ConnectVPN")) { - String vpnName = intent.getStringExtra(EXTRA_NAME); - VpnProfile profile = ProfileManager.getInstance(this).getProfileByName(vpnName); - if (profile == null) { - Toast.makeText(this, String.format("Vpn profile %s from API call not found", vpnName), Toast.LENGTH_LONG).show(); - } else { - Intent startVPN = new Intent(this, LaunchVPN.class); - startVPN.putExtra(LaunchVPN.EXTRA_KEY, profile.getUUID().toString()); - startVPN.setAction(Intent.ACTION_MAIN); - startActivity(startVPN); - } - } - finish(); - + if (component == null) + return; + switch (component.getShortClassName()) { + case ".api.DisconnectVPN": + mService.stopVPN(false); + break; + case ".api.PauseVPN": + mService.userPause(true); + break; + case ".api.ResumeVPN": + mService.userPause(false); + break; + case ".api.ConnectVPN": + String vpnName = intent.getStringExtra(EXTRA_NAME); + VpnProfile profile = ProfileManager.getInstance(this).getProfileByName(vpnName); + if (profile == null) { + Toast.makeText(this, String.format("Vpn profile %s from API call not found", vpnName), Toast.LENGTH_LONG).show(); + } else { + Intent startVPN = new Intent(this, LaunchVPN.class); + startVPN.putExtra(LaunchVPN.EXTRA_KEY, profile.getUUID().toString()); + startVPN.setAction(Intent.ACTION_MAIN); + startActivity(startVPN); + } + break; + } + finish(); } @Override -- cgit v1.2.3