diff options
author | Arne Schwabe <arne@rfc2549.org> | 2012-05-04 00:28:52 +0200 |
---|---|---|
committer | Arne Schwabe <arne@rfc2549.org> | 2012-05-04 00:28:52 +0200 |
commit | 3a1284b0635257df99840614c153e23ff3d99e80 (patch) | |
tree | 119750363771382ea684ed0f8cff6ac7c767ca1b | |
parent | 815eb143e98b57b6cd1f43c7c3007416ed4b1a91 (diff) |
Get vpn list working again, not yet perfect but at least delete works
http://code.google.com/p/android/issues/detail?id=3414 is hunting me :(
-rw-r--r-- | openvpn/config.h | 4 | ||||
-rw-r--r-- | openvpn/src/openvpn/jniglue.c | 9 | ||||
-rw-r--r-- | openvpn/src/openvpn/tun.c | 3 | ||||
-rw-r--r-- | res/layout/vpn_list_item.xml | 70 | ||||
-rw-r--r-- | res/menu/vpn_context.xml | 10 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/LaunchVPN.java | 6 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/ProfileManager.java | 31 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/Settings_Obscure.java | 4 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/VPNProfileList.java | 27 |
9 files changed, 138 insertions, 26 deletions
diff --git a/openvpn/config.h b/openvpn/config.h index 3dfeffc..65193a6 100644 --- a/openvpn/config.h +++ b/openvpn/config.h @@ -24,7 +24,7 @@ #define EMPTY_ARRAY_SIZE 0 /* Enable client capability only */ -/* #undef ENABLE_CLIENT_ONLY */ +#define ENABLE_CLIENT_ONLY 1 /* Enable client/server capability */ #define ENABLE_CLIENT_SERVER 1 @@ -42,7 +42,7 @@ #define ENABLE_MANAGEMENT 1 /* Enable multi-homed UDP server capability */ -#define ENABLE_MULTIHOME 1 +#define ENABLE_MULTIHOME 0 /* Allow --askpass and --auth-user-pass passwords to be read from a file */ #define ENABLE_PASSWORD_SAVE 1 diff --git a/openvpn/src/openvpn/jniglue.c b/openvpn/src/openvpn/jniglue.c index c0fff12..b716705 100644 --- a/openvpn/src/openvpn/jniglue.c +++ b/openvpn/src/openvpn/jniglue.c @@ -136,6 +136,15 @@ int android_open_tun () { } + +unsigned char android_protect_socket(int sockfd) { + jmethodID aMethodID = (*openvpnjenv)->GetStaticMethodID(openvpnjenv, openvpnclass, "protectSocket", + "(I)Z"); + return (*openvpnjenv)->CallStaticBooleanMethod(openvpnjenv,openvpnclass,aMethodID,sockfd); + +} + + void android_set_dns(const char* dns) { jmethodID aMethodID = (*openvpnjenv)->GetStaticMethodID(openvpnjenv, openvpnclass, "addDns", "(Ljava/lang/String;)V"); diff --git a/openvpn/src/openvpn/tun.c b/openvpn/src/openvpn/tun.c index 14ec2b8..238d9fb 100644 --- a/openvpn/src/openvpn/tun.c +++ b/openvpn/src/openvpn/tun.c @@ -1386,7 +1386,8 @@ open_tun (const char *dev, const char *dev_type, const char *dev_node, struct tu if(tt->options.domain) android_set_domain(tt->options.domain); - if((tt->fd = android_open_tun()< 0){ + + if((tt->fd = android_open_tun())< 0){ msg (M_ERR, "ERROR: Cannot open TUN"); } } diff --git a/res/layout/vpn_list_item.xml b/res/layout/vpn_list_item.xml new file mode 100644 index 0000000..dc6254e --- /dev/null +++ b/res/layout/vpn_list_item.xml @@ -0,0 +1,70 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2011 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:gravity="center_vertical" + android:focusable="false" + android:minHeight="?android:attr/listPreferredItemHeight" > + + <LinearLayout + android:id="@+id/vpnconfig_pref" + android:layout_width="wrap_content" + android:layout_height="match_parent" + android:layout_weight="1" + android:background="?android:attr/selectableItemBackground" + android:gravity="center_vertical" > + + <LinearLayout + android:id="@android:id/widget_frame" + android:layout_width="wrap_content" + android:layout_height="match_parent" + android:gravity="center_vertical" + android:orientation="vertical" /> + + <TextView + android:id="@+android:id/vpn_item_title" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:ellipsize="marquee" + android:fadingEdge="horizontal" + android:singleLine="true" + android:textAppearance="?android:attr/textAppearanceMedium" /> + + </LinearLayout> + + <View + android:layout_width="2dip" + android:layout_height="match_parent" + android:layout_marginBottom="5dip" + android:layout_marginTop="5dip" + android:background="@android:drawable/divider_horizontal_dark" /> + + <ImageView + android:id="@+id/quickedit_settings" + android:layout_width="wrap_content" + android:layout_height="fill_parent" + android:layout_gravity="center" + android:focusable="true" + android:background="?android:attr/selectableItemBackground" + android:contentDescription="@string/configure_the_vpn" + android:paddingLeft="15dip" + android:paddingRight="?android:attr/scrollbarSize" + android:src="@drawable/ic_sysbar_quicksettings" /> + +</LinearLayout>
\ No newline at end of file diff --git a/res/menu/vpn_context.xml b/res/menu/vpn_context.xml index ab68137..477c6a8 100644 --- a/res/menu/vpn_context.xml +++ b/res/menu/vpn_context.xml @@ -3,18 +3,24 @@ <item android:id="@+id/edit_vpn" + android:alphabeticShortcut="e" android:icon="@android:drawable/ic_menu_edit" android:showAsAction="withText|ifRoom" android:title="@string/edit_vpn"/> <item android:id="@+id/remove_vpn" + android:alphabeticShortcut="d" android:icon="@android:drawable/ic_menu_delete" android:showAsAction="withText|ifRoom" android:title="@string/remove_vpn"/> - <item + + <!-- does not look good on phone portrait with 3 items :( --> + <!-- <item android:id="@+id/connect_vpn" + android:alphabeticShortcut="c" + android: android:icon="@android:drawable/ic_media_play" android:showAsAction="withText|ifRoom" android:title="@string/connect"/> - + --> </menu>
\ No newline at end of file diff --git a/src/de/blinkt/openvpn/LaunchVPN.java b/src/de/blinkt/openvpn/LaunchVPN.java index 7a034e4..e0832f2 100644 --- a/src/de/blinkt/openvpn/LaunchVPN.java +++ b/src/de/blinkt/openvpn/LaunchVPN.java @@ -80,10 +80,8 @@ public class LaunchVPN extends ListActivity implements OnItemClickListener { final Intent intent = getIntent(); final String action = intent.getAction(); - mPM =ProfileManager.getInstance(); - if(mPM.getNumberOfProfiles() == 0) { - mPM.loadVPNList(this); - } + mPM =ProfileManager.getInstance(this); + // If the intent is a request to create a shortcut, we'll do that and exit diff --git a/src/de/blinkt/openvpn/ProfileManager.java b/src/de/blinkt/openvpn/ProfileManager.java index 9e5b160..f819300 100644 --- a/src/de/blinkt/openvpn/ProfileManager.java +++ b/src/de/blinkt/openvpn/ProfileManager.java @@ -24,20 +24,25 @@ public class ProfileManager { private HashMap<String,VpnProfile> profiles=new HashMap<String, VpnProfile>(); public static VpnProfile get(String key) { - checkInstance(); + if(instance==null) + return null; return instance.profiles.get(key); } + + private ProfileManager() { } - private static void checkInstance() { - if(instance == null) + private static void checkInstance(Context context) { + if(instance == null) { instance = new ProfileManager(); + instance.loadVPNList(context); + } } - public static ProfileManager getInstance() { - checkInstance(); + public static ProfileManager getInstance(Context context) { + checkInstance(context); return instance; } @@ -56,8 +61,8 @@ public class ProfileManager { return null; } - public void saveProfileList(Activity activity) { - SharedPreferences sharedprefs = activity.getSharedPreferences(PREFS_NAME,Activity.MODE_PRIVATE); + public void saveProfileList(Context context) { + SharedPreferences sharedprefs = context.getSharedPreferences(PREFS_NAME,Activity.MODE_PRIVATE); Editor editor = sharedprefs.edit(); editor.putStringSet("vpnlist", profiles.keySet()); editor.commit(); @@ -89,7 +94,7 @@ public class ProfileManager { } - void loadVPNList(Context context) { + private void loadVPNList(Context context) { profiles = new HashMap<String, VpnProfile>(); SharedPreferences settings =context.getSharedPreferences(PREFS_NAME,Activity.MODE_PRIVATE); Set<String> vlist = settings.getStringSet("vpnlist", null); @@ -120,4 +125,14 @@ public class ProfileManager { return profiles.size(); } + + + public void removeProfile(Context context,VpnProfile profile) { + String vpnentry = profile.getUUID().toString(); + profiles.remove(vpnentry); + saveProfileList(context); + context.deleteFile(vpnentry + ".vp"); + + } + } diff --git a/src/de/blinkt/openvpn/Settings_Obscure.java b/src/de/blinkt/openvpn/Settings_Obscure.java index 65d1c40..91c6170 100644 --- a/src/de/blinkt/openvpn/Settings_Obscure.java +++ b/src/de/blinkt/openvpn/Settings_Obscure.java @@ -67,6 +67,10 @@ public class Settings_Obscure extends PreferenceFragment implements OnPreference @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if(preference==mLogverbosity) { + // Catch old version problem + if(newValue==null){ + newValue=1; + } mLogverbosity.setDefaultValue(newValue); //This is idiotic. int i =Integer.parseInt((String) newValue); diff --git a/src/de/blinkt/openvpn/VPNProfileList.java b/src/de/blinkt/openvpn/VPNProfileList.java index c9ff980..56cc7ae 100644 --- a/src/de/blinkt/openvpn/VPNProfileList.java +++ b/src/de/blinkt/openvpn/VPNProfileList.java @@ -21,11 +21,22 @@ import android.widget.ListView; import android.widget.Toast; public class VPNProfileList extends ListFragment { + class VPNArrayAdapter extends ArrayAdapter<VpnProfile> { + + public VPNArrayAdapter(Context context, int resource, + int textViewResourceId) { + super(context, resource, textViewResourceId); + + } + + } + + + private static final int MENU_ADD_PROFILE = Menu.FIRST; private static final int START_VPN_CONFIG = 92; - private ArrayAdapter<VpnProfile> mArrayadapter; protected Object mActionMode; @@ -78,12 +89,10 @@ public class VPNProfileList extends ListFragment { }); - if(getPM().getNumberOfProfiles() == 0) { - getPM().loadVPNList(getActivity()); - } - +// mArrayadapter = new ArrayAdapter<VpnProfile>(getActivity(),R.layout.vpn_list_item,R.id.vpn_item_title); mArrayadapter = new ArrayAdapter<VpnProfile>(getActivity(),android.R.layout.simple_list_item_activated_1); mArrayadapter.addAll(getPM().getProfiles()); + setListAdapter(mArrayadapter); } @@ -127,7 +136,7 @@ public class VPNProfileList extends ListFragment { protected void removeProfile(VpnProfile profile) { mArrayadapter.remove(profile); - + getPM().removeProfile(getActivity(),profile); } private void onAddProfileClicked() { @@ -181,7 +190,7 @@ public class VPNProfileList extends ListFragment { private ProfileManager getPM() { - return ProfileManager.getInstance(); + return ProfileManager.getInstance(getActivity()); } @@ -240,10 +249,10 @@ public class VPNProfileList extends ListFragment { askProfileRemoval(); mode.finish(); // Action picked, so close the CAB return true; - case R.id.connect_vpn: +/* case R.id.connect_vpn: startVPN(mEditProfile); mode.finish(); - return true; + return true; */ case R.id.edit_vpn: editVPN(mEditProfile); mode.finish(); |