diff options
Diffstat (limited to 'remoteExample/src/main/java')
-rw-r--r-- | remoteExample/src/main/java/de/blinkt/openvpn/api/APIVpnProfile.java | 87 | ||||
-rw-r--r-- | remoteExample/src/main/java/de/blinkt/openvpn/remote/MainFragment.java | 30 |
2 files changed, 69 insertions, 48 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 f5591764..9d7e3b8e 100644 --- a/remoteExample/src/main/java/de/blinkt/openvpn/api/APIVpnProfile.java +++ b/remoteExample/src/main/java/de/blinkt/openvpn/api/APIVpnProfile.java @@ -1,3 +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
+ */
+
package de.blinkt.openvpn.api;
import android.os.Parcel;
@@ -5,47 +10,51 @@ import android.os.Parcelable; public class APIVpnProfile implements Parcelable {
- public final String mUUID;
- public final String mName;
- public final boolean mUserEditable;
+ public final String mUUID;
+ public final String mName;
+ public final boolean mUserEditable;
+ public final String mProfileCreator;
- public APIVpnProfile(Parcel in) {
- mUUID = in.readString();
- mName = in.readString();
+ public APIVpnProfile(Parcel in) {
+ mUUID = in.readString();
+ mName = in.readString();
mUserEditable = in.readInt() != 0;
- }
-
- public APIVpnProfile(String uuidString, String name, boolean userEditable) {
- mUUID=uuidString;
- mName = name;
- mUserEditable=userEditable;
- }
-
- @Override
- public int describeContents() {
- return 0;
- }
-
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- dest.writeString(mUUID);
- dest.writeString(mName);
- if(mUserEditable)
- dest.writeInt(0);
- else
- dest.writeInt(1);
- }
-
- public static final Parcelable.Creator<APIVpnProfile> CREATOR
- = new Parcelable.Creator<APIVpnProfile>() {
- public APIVpnProfile createFromParcel(Parcel in) {
- return new APIVpnProfile(in);
- }
-
- public APIVpnProfile[] newArray(int size) {
- return new APIVpnProfile[size];
- }
- };
+ mProfileCreator = in.readString();
+ }
+
+ public APIVpnProfile(String uuidString, String name, boolean userEditable, String profileCreator) {
+ mUUID = uuidString;
+ mName = name;
+ mUserEditable = userEditable;
+ mProfileCreator = profileCreator;
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeString(mUUID);
+ dest.writeString(mName);
+ if (mUserEditable)
+ dest.writeInt(0);
+ else
+ dest.writeInt(1);
+ dest.writeString(mProfileCreator);
+ }
+
+ public static final Creator<APIVpnProfile> CREATOR
+ = new Creator<APIVpnProfile>() {
+ public APIVpnProfile createFromParcel(Parcel in) {
+ return new APIVpnProfile(in);
+ }
+
+ public APIVpnProfile[] newArray(int size) {
+ return new APIVpnProfile[size];
+ }
+ };
}
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 4f6481b0..a6d2baf5 100644 --- a/remoteExample/src/main/java/de/blinkt/openvpn/remote/MainFragment.java +++ b/remoteExample/src/main/java/de/blinkt/openvpn/remote/MainFragment.java @@ -44,6 +44,7 @@ public class MainFragment extends Fragment implements View.OnClickListener, Hand v.findViewById(R.id.disconnect).setOnClickListener(this); v.findViewById(R.id.getMyIP).setOnClickListener(this); v.findViewById(R.id.startembedded).setOnClickListener(this); + v.findViewById(R.id.addNewProfile).setOnClickListener(this); mHelloWorld = (TextView) v.findViewById(R.id.helloworld); mStartVpn = (Button) v.findViewById(R.id.startVPN); mStatus = (TextView) v.findViewById(R.id.status); @@ -59,6 +60,8 @@ public class MainFragment extends Fragment implements View.OnClickListener, Hand private static final int START_PROFILE_EMBEDDED = 2; private static final int START_PROFILE_BYUUID = 3; private static final int ICS_OPENVPN_PERMISSION = 7; + private static final int PROFILE_ADD_NEW = 8; + protected IOpenVPNAPIService mService=null; private Handler mHandler; @@ -66,7 +69,7 @@ public class MainFragment extends Fragment implements View.OnClickListener, Hand - private void startEmbeddedProfile() + private void startEmbeddedProfile(boolean addNew) { try { InputStream conf = getActivity().getAssets().open("test.conf"); @@ -82,12 +85,11 @@ public class MainFragment extends Fragment implements View.OnClickListener, Hand } br.readLine(); - // mService.addVPNProfile("test", config); - mService.startVPN(config); - } catch (IOException e) { - e.printStackTrace(); - } catch (RemoteException e) { - // TODO Auto-generated catch block + if (addNew) + mService.addNewVPNProfile("nonEditable", false, config); + else + mService.startVPN(config); + } catch (IOException | RemoteException e) { e.printStackTrace(); } } @@ -252,6 +254,14 @@ public class MainFragment extends Fragment implements View.OnClickListener, Hand e.printStackTrace(); } break; + + case R.id.addNewProfile: + try { + prepareStartProfile(PROFILE_ADD_NEW); + } catch (RemoteException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } default: break; } @@ -271,12 +281,11 @@ public class MainFragment extends Fragment implements View.OnClickListener, Hand public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK) { if(requestCode==START_PROFILE_EMBEDDED) - startEmbeddedProfile(); + startEmbeddedProfile(false); if(requestCode==START_PROFILE_BYUUID) try { mService.startProfile(mStartUUID); } catch (RemoteException e) { - // TODO Auto-generated catch block e.printStackTrace(); } if (requestCode == ICS_OPENVPN_PERMISSION) { @@ -288,6 +297,9 @@ public class MainFragment extends Fragment implements View.OnClickListener, Hand } } + if (requestCode == PROFILE_ADD_NEW) { + startEmbeddedProfile(true); + } } }; |