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