From 77929094851d5b5c46c3ff37b227a3b7994797ab Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Wed, 4 Dec 2024 19:21:06 +0100 Subject: Add toast when service connection cannot be established (closes #1757) This is just an example app that should give an example of a happy path. It shouldn't require handle all the errors... Signed-off-by: Arne Schwabe --- .../src/main/java/de/blinkt/openvpn/remote/MainFragment.java | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'remoteExample/src/main/java') 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..d98fdedd 100644 --- a/remoteExample/src/main/java/de/blinkt/openvpn/remote/MainFragment.java +++ b/remoteExample/src/main/java/de/blinkt/openvpn/remote/MainFragment.java @@ -233,6 +233,10 @@ public class MainFragment extends Fragment implements View.OnClickListener, Hand @Override public void onClick(View v) { + if (mService == null) { + Toast.makeText(getActivity(), "No service connection to OpenVPN for Android. App not installed?", Toast.LENGTH_LONG).show(); + return; + } switch (v.getId()) { case R.id.startVPN: try { -- cgit v1.2.3 From 1f1dae89983ed10b7913638e2153d4d3bcb3ac75 Mon Sep 17 00:00:00 2001 From: Ted Romer Date: Fri, 26 Sep 2025 02:22:57 -0700 Subject: Add setDefaultProfile and getDefaultProfile methods to API. Also: * add corresponding setDefaultVPN intent * add sample usage to remoteExample * bring remoteExample/.../IOpenVPNAPIService.aidl into sync with main/... * make APIVpnProfile.java in remoteExample/ and main/ identical. --- .../java/de/blinkt/openvpn/api/APIVpnProfile.java | 6 ++++-- .../java/de/blinkt/openvpn/remote/MainFragment.java | 21 ++++++++++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) (limited to 'remoteExample/src/main/java') 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 d98fdedd..c4e92f27 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 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) @@ -253,6 +258,14 @@ public class MainFragment extends Fragment implements View.OnClickListener, Hand e.printStackTrace(); } break; + case R.id.setDefaultProfile: + try { + prepareStartProfile(SET_DEFAULT_PROFILE_BYUUID); + } catch (RemoteException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + break; case R.id.getMyIP: // Socket handling is not allowed on main thread @@ -317,6 +330,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 { -- cgit v1.2.3 From 040eb6067528361ad444270900d26317f94c2463 Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Fri, 30 Jan 2026 13:20:36 +0100 Subject: Update gradle/AGP version Signed-off-by: Arne Schwabe --- .../de/blinkt/openvpn/remote/MainFragment.java | 110 +++++++++------------ 1 file changed, 49 insertions(+), 61 deletions(-) (limited to 'remoteExample/src/main/java') 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 c4e92f27..50954558 100644 --- a/remoteExample/src/main/java/de/blinkt/openvpn/remote/MainFragment.java +++ b/remoteExample/src/main/java/de/blinkt/openvpn/remote/MainFragment.java @@ -242,70 +242,58 @@ public class MainFragment extends Fragment implements View.OnClickListener, Hand Toast.makeText(getActivity(), "No service connection to OpenVPN for Android. App not installed?", Toast.LENGTH_LONG).show(); return; } - 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.setDefaultProfile: - try { - prepareStartProfile(SET_DEFAULT_PROFILE_BYUUID); - } 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(); - } - + 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(); + } } } -- cgit v1.2.3