diff options
-rw-r--r-- | AndroidManifest.xml | 4 | ||||
-rw-r--r-- | res/menu/logmenu.xml | 2 | ||||
-rw-r--r-- | res/values/strings.xml | 2 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/LogWindow.java | 105 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/OpenVpnService.java | 9 |
5 files changed, 85 insertions, 37 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 7b600181..3541f6c5 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -17,8 +17,8 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="de.blinkt.openvpn" - android:versionCode="13" - android:versionName="0.4.5" > + android:versionCode="14" + android:versionName="0.4.6" > <uses-permission android:name="android.permission.INTERNET" /> diff --git a/res/menu/logmenu.xml b/res/menu/logmenu.xml index f97418a1..5fcadae0 100644 --- a/res/menu/logmenu.xml +++ b/res/menu/logmenu.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/clearlog"
- android:icon="@android:drawable/ic_delete"
+ android:icon="@android:drawable/ic_menu_crop"
android:title="clear log"
android:showAsAction="ifRoom"
/>
diff --git a/res/values/strings.xml b/res/values/strings.xml index 58137810..7bc7ab95 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -111,4 +111,6 @@ <string name="random_host_summary">adds 6 random chars in front of hostname</string> <string name="custom_config_title">Enable Custom Options</string> <string name="custom_config_summary">Specify custom options. Use with care!</string> + <string name="route_rejected">Route rejected by Android</string> + <string formatted="false" name="ip_not_cidr">Cannot make sense of %s and %s as IP and CIDR netmask, assuming P2P for local address (/32)</string> </resources> diff --git a/src/de/blinkt/openvpn/LogWindow.java b/src/de/blinkt/openvpn/LogWindow.java index 16f54b12..f6004882 100644 --- a/src/de/blinkt/openvpn/LogWindow.java +++ b/src/de/blinkt/openvpn/LogWindow.java @@ -10,6 +10,7 @@ import android.os.Handler.Callback; import android.os.Message; import android.view.Menu; import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.ListAdapter; @@ -18,33 +19,42 @@ import android.widget.TextView; import de.blinkt.openvpn.OpenVPN.LogListener; public class LogWindow extends ListActivity { - + class LogWindowListAdapter implements ListAdapter,LogListener, Callback { + private static final int MESSAGE_NEWLOG = 0; + + private static final int MESSAGE_CLEARLOG = 1; + private Vector<String> myEntries=new Vector<String>(); - + private Handler mHandler; private Vector<DataSetObserver> observers=new Vector<DataSetObserver>(); public LogWindowListAdapter() { + initLogBuffer(); + + if (mHandler == null) { + mHandler = new Handler(this); + } + + OpenVPN.addLogListener(this); + } + + private void initLogBuffer() { + myEntries.clear(); for (String litem : OpenVPN.getlogbuffer()) { myEntries.add(litem); } - - if (mHandler == null) { - mHandler = new Handler(this); - } - - OpenVPN.addLogListener(this); } - + @Override public void registerDataSetObserver(DataSetObserver observer) { observers.add(observer); - + } - + @Override public void unregisterDataSetObserver(DataSetObserver observer) { observers.remove(observer); @@ -94,7 +104,7 @@ public class LogWindow extends ListActivity { @Override public boolean isEmpty() { return myEntries.isEmpty(); - + } @Override @@ -110,6 +120,7 @@ public class LogWindow extends ListActivity { @Override public void newLog(String logmessage) { Message msg = Message.obtain(); + msg.what=MESSAGE_NEWLOG; Bundle mbundle=new Bundle(); mbundle.putString("logmessage", logmessage); msg.setData(mbundle); @@ -119,39 +130,67 @@ public class LogWindow extends ListActivity { @Override public boolean handleMessage(Message msg) { // We have been called - String logmessage = msg.getData().getString("logmessage"); - myEntries.add(logmessage); + if(msg.what==MESSAGE_NEWLOG) { + + String logmessage = msg.getData().getString("logmessage"); + myEntries.add(logmessage); - for (DataSetObserver observer : observers) { - observer.onChanged(); + for (DataSetObserver observer : observers) { + observer.onChanged(); + } + } else if (msg.what == MESSAGE_CLEARLOG) { + initLogBuffer(); + for (DataSetObserver observer : observers) { + observer.onInvalidated(); + } } - - + return true; } - + + void clearLog() { + OpenVPN.clearLog(); + OpenVPN.logMessage(0,"","Log cleared."); + mHandler.sendEmptyMessage(MESSAGE_CLEARLOG); + } + + } + + + + private LogWindowListAdapter ladapter; + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if(item.getItemId()==R.id.clearlog) { + ladapter.clearLog(); + return true; + } + + return super.onOptionsItemSelected(item); + } @Override public boolean onCreateOptionsMenu(Menu menu) { - MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.logmenu, menu); - return true; + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.logmenu, menu); + return true; } - - + + @Override public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - ListView lv = getListView(); - //lv.setTextFilterEnabled(true); - LogWindowListAdapter adapter = new LogWindowListAdapter(); - lv.setAdapter(adapter); + super.onCreate(savedInstanceState); + + ListView lv = getListView(); + //lv.setTextFilterEnabled(true); + ladapter = new LogWindowListAdapter(); + lv.setAdapter(ladapter); + + } + - } - - } diff --git a/src/de/blinkt/openvpn/OpenVpnService.java b/src/de/blinkt/openvpn/OpenVpnService.java index 8da49bad..442fd94c 100644 --- a/src/de/blinkt/openvpn/OpenVpnService.java +++ b/src/de/blinkt/openvpn/OpenVpnService.java @@ -202,7 +202,11 @@ public class OpenVpnService extends VpnService implements Handler.Callback { for (CIDRIP route:mRoutes) { - builder.addRoute(route.mIp, route.len); + try { + builder.addRoute(route.mIp, route.len); + } catch (IllegalArgumentException ia) { + OpenVPN.logMessage(0, "", getString(R.string.route_rejected) + route + " " + ia.getLocalizedMessage()); + } } if(mDomain!=null) @@ -243,6 +247,9 @@ public class OpenVpnService extends VpnService implements Handler.Callback { public void setLocalIP(String local, String netmask) { mLocalIP = new CIDRIP(local, netmask); + if(mLocalIP.len == 32 && !netmask.equals("255.255.255.255")) { + OpenVPN.logMessage(0, "", String.format(getString(R.string.ip_not_cidr, local,netmask))); + } } |