summaryrefslogtreecommitdiff
path: root/remoteExample/src/main/java
diff options
context:
space:
mode:
authorcyberta <cyberta@riseup.net>2026-03-09 23:59:50 +0100
committercyberta <cyberta@riseup.net>2026-03-09 23:59:50 +0100
commit733d1ae5bbb5356a228e42a013660743db1c7073 (patch)
tree550f2285ef072e7dcc482d648fccc09222a35791 /remoteExample/src/main/java
parentb1c21e7e1fbc0d09e3d121b89651482a0bb02efd (diff)
parent73ce3c99dde39207990d66c21be8201228cd1f09 (diff)
Merge branch 'schwabe_master' into ssh_new_master
Diffstat (limited to 'remoteExample/src/main/java')
-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
2 files changed, 69 insertions, 56 deletions
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 {