summaryrefslogtreecommitdiff
path: root/remoteExample
diff options
context:
space:
mode:
Diffstat (limited to 'remoteExample')
-rw-r--r--remoteExample/build.gradle3
-rw-r--r--remoteExample/proguard-rules.pro26
-rw-r--r--remoteExample/src/main/aidl/de/blinkt/openvpn/api/IOpenVPNAPIService.aidl28
-rw-r--r--remoteExample/src/main/java/de/blinkt/openvpn/api/APIVpnProfile.java6
-rw-r--r--remoteExample/src/main/java/de/blinkt/openvpn/remote/MainFragment.java119
-rw-r--r--remoteExample/src/main/res/layout/fragment_main.xml8
-rw-r--r--remoteExample/src/main/res/values/strings.xml1
7 files changed, 129 insertions, 62 deletions
diff --git a/remoteExample/build.gradle b/remoteExample/build.gradle
index 179555bb..019fa10f 100644
--- a/remoteExample/build.gradle
+++ b/remoteExample/build.gradle
@@ -8,6 +8,9 @@ plugins {
}
android {
+ buildFeatures {
+ buildConfig true
+ }
compileSdkVersion 33
defaultConfig {
diff --git a/remoteExample/proguard-rules.pro b/remoteExample/proguard-rules.pro
new file mode 100644
index 00000000..61d69340
--- /dev/null
+++ b/remoteExample/proguard-rules.pro
@@ -0,0 +1,26 @@
+# Add project specific ProGuard rules here.
+# You can control the set of applied configuration files using the
+# proguardFiles setting in build.gradle.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
+
+# Uncomment this to preserve the line number information for
+# debugging stack traces.
+#-keepattributes SourceFile,LineNumberTable
+
+# If you keep the line number information, uncomment this to
+# hide the original source file name.
+#-renamesourcefileattribute SourceFile
+
+# Untested but reported to work (https://github.com/schwabe/ics-openvpn/issues/1755#issuecomment-2325652081)
+-keep interface de.blinkt.openvpn.api.IOpenVPNAPIService { *; }
+-keep interface de.blinkt.openvpn.api.IOpenVPNStatusCallback { *; }
+-keep class de.blinkt.openvpn.api.APIVpnProfile { *; } \ No newline at end of file
diff --git a/remoteExample/src/main/aidl/de/blinkt/openvpn/api/IOpenVPNAPIService.aidl b/remoteExample/src/main/aidl/de/blinkt/openvpn/api/IOpenVPNAPIService.aidl
index 273a0046..5e259d29 100644
--- a/remoteExample/src/main/aidl/de/blinkt/openvpn/api/IOpenVPNAPIService.aidl
+++ b/remoteExample/src/main/aidl/de/blinkt/openvpn/api/IOpenVPNAPIService.aidl
@@ -18,14 +18,14 @@ interface IOpenVPNAPIService {
boolean addVPNProfile (String name, String config);
/** start a profile using a config as inline string. Make sure that all needed data is inlined,
- * e.g., using <ca>...</ca> or <auth-user-data>...</auth-user-data>
+ * e.g., using <ca>...</ca> or <auth-user-pass>...</auth-user-pass>
* See the OpenVPN manual page for more on inlining files */
- void startVPN (String inlineconfig);
+ void startVPN (in String inlineconfig);
/** This permission framework is used to avoid confused deputy style attack to the VPN
* calling this will give null if the app is allowed to use the external API and an Intent
* that can be launched to request permissions otherwise */
- Intent prepare (String packagename);
+ Intent prepare (in String packagename);
/** Used to trigger to the Android VPN permission dialog (VPNService.prepare()) in advance,
* if this return null OpenVPN for ANdroid already has the permissions otherwise you can start the returned Intent
@@ -44,15 +44,15 @@ interface IOpenVPNAPIService {
/**
* Registers to receive OpenVPN Status Updates
*/
- void registerStatusCallback(IOpenVPNStatusCallback cb);
+ void registerStatusCallback(in IOpenVPNStatusCallback cb);
/**
* Remove a previously registered callback interface.
*/
- void unregisterStatusCallback(IOpenVPNStatusCallback cb);
+ void unregisterStatusCallback(in IOpenVPNStatusCallback cb);
/** Remove a profile by UUID */
- void removeProfile (String profileUUID);
+ void removeProfile (in String profileUUID);
/** Request a socket to be protected as a VPN socket would be. Useful for creating
* a helper socket for an app controlling OpenVPN
@@ -63,4 +63,20 @@ interface IOpenVPNAPIService {
/** Use a profile with all certificates etc. embedded */
APIVpnProfile addNewVPNProfile (String name, boolean userEditable, String config);
+
+ /** Same as startVPN(String), but also takes a Bundle with extra parameters,
+ * which will be applied to the created VPNProfile (e.g. allow vpn bypass). */
+ void startVPNwithExtras(in String inlineconfig, in Bundle extras);
+
+ /** Same as addNewVPNProfile(String, boolean, String) but giving possibility to pass a Bundle like
+ * in startVPNwithExtras(String, Bundle) to apply e.g. "allow vpn bypass" to profile.
+ * up to now the only extra that can be put is a boolean "de.blinkt.openvpn.api.ALLOW_VPN_BYPASS"
+ */
+ APIVpnProfile addNewVPNProfileWithExtras (String name, boolean userEditable, String config, in Bundle extras);
+
+ /** Get the current default profile, or null if there is no default */
+ @nullable APIVpnProfile getDefaultProfile();
+
+ /** Set the default profile by UUID */
+ void setDefaultProfile (String profileUUID);
} \ No newline at end of file
diff --git a/remoteExample/src/main/java/de/blinkt/openvpn/api/APIVpnProfile.java b/remoteExample/src/main/java/de/blinkt/openvpn/api/APIVpnProfile.java
index 65c6ad57..cf310dbc 100644
--- a/remoteExample/src/main/java/de/blinkt/openvpn/api/APIVpnProfile.java
+++ b/remoteExample/src/main/java/de/blinkt/openvpn/api/APIVpnProfile.java
@@ -1,6 +1,8 @@
/*
- * Copyright (c) 2012-2015 Arne Schwabe
- * Distributed under the GNU GPL v2 with additional terms. For full terms see the file doc/LICENSE.txt
+ * Copyright (c) 2012-2016 Arne Schwabe
+ * This file is used for implementing the external API and this file like the AIDL and is exempted
+ * from the GPLv2.
+ *
*/
package de.blinkt.openvpn.api;
diff --git a/remoteExample/src/main/java/de/blinkt/openvpn/remote/MainFragment.java b/remoteExample/src/main/java/de/blinkt/openvpn/remote/MainFragment.java
index 14fa3887..50954558 100644
--- a/remoteExample/src/main/java/de/blinkt/openvpn/remote/MainFragment.java
+++ b/remoteExample/src/main/java/de/blinkt/openvpn/remote/MainFragment.java
@@ -52,6 +52,7 @@ public class MainFragment extends Fragment implements View.OnClickListener, Hand
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_main, container, false);
v.findViewById(R.id.disconnect).setOnClickListener(this);
+ v.findViewById(R.id.setDefaultProfile).setOnClickListener(this);
v.findViewById(R.id.getMyIP).setOnClickListener(this);
v.findViewById(R.id.startembedded).setOnClickListener(this);
v.findViewById(R.id.addNewProfile).setOnClickListener(this);
@@ -70,6 +71,7 @@ public class MainFragment extends Fragment implements View.OnClickListener, Hand
private static final int MSG_UPDATE_MYIP = 1;
private static final int START_PROFILE_EMBEDDED = 2;
private static final int START_PROFILE_BYUUID = 3;
+ private static final int SET_DEFAULT_PROFILE_BYUUID = 4;
private static final int ICS_OPENVPN_PERMISSION = 7;
private static final int PROFILE_ADD_NEW = 8;
private static final int PROFILE_ADD_NEW_EDIT = 9;
@@ -195,9 +197,12 @@ public class MainFragment extends Fragment implements View.OnClickListener, Hand
try {
List<APIVpnProfile> list = mService.getProfiles();
+ APIVpnProfile defaultProfile = mService.getDefaultProfile();
+ String defaultUUID = defaultProfile != null ? defaultProfile.mUUID : null;
String all="List:";
for(APIVpnProfile vp:list.subList(0, Math.min(5, list.size()))) {
- all = all + vp.mName + ":" + vp.mUUID + "\n";
+ String suffix = (vp.mUUID.equals(defaultUUID)) ? " (default)" : "";
+ all = all + vp.mName + ":" + vp.mUUID + suffix + "\n";
}
if (list.size() > 5)
@@ -233,62 +238,62 @@ public class MainFragment extends Fragment implements View.OnClickListener, Hand
@Override
public void onClick(View v) {
- switch (v.getId()) {
- case R.id.startVPN:
- try {
- prepareStartProfile(START_PROFILE_BYUUID);
- } catch (RemoteException e) {
- e.printStackTrace();
- }
- break;
- case R.id.disconnect:
- try {
- mService.disconnect();
- } catch (RemoteException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- break;
- case R.id.getMyIP:
-
- // Socket handling is not allowed on main thread
- new Thread() {
-
- @Override
- public void run() {
- try {
- String myip = getMyOwnIP();
- Message msg = Message.obtain(mHandler,MSG_UPDATE_MYIP,myip);
- msg.sendToTarget();
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
+ if (mService == null) {
+ Toast.makeText(getActivity(), "No service connection to OpenVPN for Android. App not installed?", Toast.LENGTH_LONG).show();
+ return;
+ }
+ int id = v.getId();
+ if (id == R.id.startVPN) {
+ try {
+ prepareStartProfile(START_PROFILE_BYUUID);
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ } else if (id == R.id.disconnect) {
+ try {
+ mService.disconnect();
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ } else if (id == R.id.setDefaultProfile) {
+ try {
+ prepareStartProfile(SET_DEFAULT_PROFILE_BYUUID);
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ } else if (id == R.id.getMyIP) {// Socket handling is not allowed on main thread
+ new Thread() {
+
+ @Override
+ public void run() {
+ try {
+ String myip = getMyOwnIP();
+ Message msg = Message.obtain(mHandler, MSG_UPDATE_MYIP, myip);
+ msg.sendToTarget();
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
}
- }.start();
-
- break;
- case R.id.startembedded:
- try {
- prepareStartProfile(START_PROFILE_EMBEDDED);
- } catch (RemoteException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- break;
- case R.id.addNewProfile:
- case R.id.addNewProfileEdit:
- int action = (v.getId() == R.id.addNewProfile) ? PROFILE_ADD_NEW : PROFILE_ADD_NEW_EDIT;
- try {
- prepareStartProfile(action);
- } catch (RemoteException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
}
- default:
- break;
+ }.start();
+ } else if (id == R.id.startembedded) {
+ try {
+ prepareStartProfile(START_PROFILE_EMBEDDED);
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ } else if (id == R.id.addNewProfile || id == R.id.addNewProfileEdit) {
+ int action = (v.getId() == R.id.addNewProfile) ? PROFILE_ADD_NEW : PROFILE_ADD_NEW_EDIT;
+ try {
+ prepareStartProfile(action);
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
}
@@ -313,6 +318,12 @@ public class MainFragment extends Fragment implements View.OnClickListener, Hand
} catch (RemoteException e) {
e.printStackTrace();
}
+ if(requestCode==SET_DEFAULT_PROFILE_BYUUID)
+ try {
+ mService.setDefaultProfile(mStartUUID);
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
if (requestCode == ICS_OPENVPN_PERMISSION) {
listVPNs();
try {
diff --git a/remoteExample/src/main/res/layout/fragment_main.xml b/remoteExample/src/main/res/layout/fragment_main.xml
index 6b8102e2..0780bba4 100644
--- a/remoteExample/src/main/res/layout/fragment_main.xml
+++ b/remoteExample/src/main/res/layout/fragment_main.xml
@@ -64,6 +64,14 @@
android:text="@string/disconnect" />
<Button
+ android:id="@+id/setDefaultProfile"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignBottom="@+id/disconnect"
+ android:layout_toRightOf="@+id/disconnect"
+ android:text="@string/set_default" />
+
+ <Button
android:id="@+id/startembedded"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
diff --git a/remoteExample/src/main/res/values/strings.xml b/remoteExample/src/main/res/values/strings.xml
index 971f7de5..44c9ecc8 100644
--- a/remoteExample/src/main/res/values/strings.xml
+++ b/remoteExample/src/main/res/values/strings.xml
@@ -14,6 +14,7 @@
<string name="no_now">Not now</string>
<string name="show_my_ip">Show my IP</string>
<string name="disconnect">Disconnect</string>
+ <string name="set_default">Set Default</string>
<string name="start_embedded">Start embedded profile</string>
<string name="addNew">Add new Profile</string>
<string name="addNewEdit">Add editable profile</string>