Skip to content

Commit

Permalink
Add intents for pausing/resuming VPN (closes schwabe#1460)
Browse files Browse the repository at this point in the history
  • Loading branch information
schwabe committed Mar 16, 2022
1 parent 2ccc153 commit d5d7283
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 21 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------------------
Expand Down
9 changes: 9 additions & 0 deletions main/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@
android:name=".api.DisconnectVPN"
android:exported="true"
android:targetActivity=".api.RemoteAction" />
<activity-alias
android:name=".api.PauseVPN"
android:exported="true"
android:targetActivity=".api.RemoteAction" />
<activity-alias
android:name=".api.ResumeVPN"
android:exported="true"
android:targetActivity=".api.RemoteAction" />

</application>

</manifest>
47 changes: 27 additions & 20 deletions main/src/main/java/de/blinkt/openvpn/api/RemoteAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@
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) {
Expand All @@ -50,8 +49,6 @@ public void onServiceDisconnected(ComponentName arg0) {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

mExtAppDb = new ExternalAppDatabase(this);
}

@Override
Expand All @@ -74,24 +71,34 @@ private void performAction() throws RemoteException {
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
Expand Down

0 comments on commit d5d7283

Please sign in to comment.