From 0291c756696f9ef5a8e2a23ed3b4b1ff79e91e08 Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Fri, 11 May 2012 01:17:01 +0200 Subject: CLeanups Fix backtrace from market console, I suspect someone tried IPv6 and I failed him/her :( --- src/de/blinkt/openvpn/MainActivity.java | 2 -- src/de/blinkt/openvpn/OpenVPN.java | 33 ++-------------------- src/de/blinkt/openvpn/OpenVPNThread.java | 6 +--- src/de/blinkt/openvpn/OpenVpnService.java | 18 ++++++++---- src/de/blinkt/openvpn/Settings_Authentication.java | 3 +- 5 files changed, 18 insertions(+), 44 deletions(-) (limited to 'src/de/blinkt/openvpn') diff --git a/src/de/blinkt/openvpn/MainActivity.java b/src/de/blinkt/openvpn/MainActivity.java index 86c1d73f..d9169284 100644 --- a/src/de/blinkt/openvpn/MainActivity.java +++ b/src/de/blinkt/openvpn/MainActivity.java @@ -10,8 +10,6 @@ public class MainActivity extends PreferenceActivity { @Override public void onBuildHeaders(List
target) { loadHeadersFromResource(R.xml.main_headers, target); - //debug - OpenVPN.foo(); } @Override diff --git a/src/de/blinkt/openvpn/OpenVPN.java b/src/de/blinkt/openvpn/OpenVPN.java index 71df887f..24281d13 100644 --- a/src/de/blinkt/openvpn/OpenVPN.java +++ b/src/de/blinkt/openvpn/OpenVPN.java @@ -4,15 +4,11 @@ import java.util.LinkedList; import java.util.Vector; public class OpenVPN { - private static OpenVpnService mOpenVpnService; - private static final int MAXLOGENTRIES = 500; - //public static native int startOpenVPNThreadArgs(String argv[]); - private static final String TAG = "OpenVpn"; + private static final int MAXLOGENTRIES = 200; public static LinkedList logbuffer = new LinkedList(); - private static int counter=0; - + private static Vector logListener=new Vector(); private static String[] mBconfig; @@ -20,27 +16,13 @@ public class OpenVPN { void newLog(String logmessage); } - /* - static { - System.loadLibrary("crypto"); - System.loadLibrary("ssl"); - System.loadLibrary("lzo"); - System.loadLibrary("openvpn"); - }*/ synchronized static void logMessage(int level,String prefix, String message) { logbuffer.addLast(prefix + message); if(logbuffer.size()>MAXLOGENTRIES) logbuffer.removeFirst(); - - // The garbage collector does not collect the String from native - // but kills me for logging 100 messages with too many references :( - // Force GC how and then to kill loose ends - if(counter++ % 50==0) { - //System.gc(); - } - + for (LogListener ll : logListener) { ll.newLog(prefix + message); } @@ -60,15 +42,6 @@ public class OpenVPN { } - - - public static void setCallback(OpenVpnService openVpnService) { - mOpenVpnService = openVpnService; - } - - //! Dummy method being called to force loading of JNI Libraries - public static void foo() { } - synchronized public static String[] getlogbuffer() { // The stoned way of java to return an array from a vector diff --git a/src/de/blinkt/openvpn/OpenVPNThread.java b/src/de/blinkt/openvpn/OpenVPNThread.java index a24abb8b..ce332677 100644 --- a/src/de/blinkt/openvpn/OpenVPNThread.java +++ b/src/de/blinkt/openvpn/OpenVPNThread.java @@ -27,11 +27,7 @@ public class OpenVPNThread implements Runnable { @Override public void run() { try { - Log.i(TAG, "Starting o"); - - - OpenVPN.setCallback(mService); - + Log.i(TAG, "Starting openvpn"); // We try to create the tunnel for several times. The better way // is to work with ConnectivityManager, such as trying only when diff --git a/src/de/blinkt/openvpn/OpenVpnService.java b/src/de/blinkt/openvpn/OpenVpnService.java index 9030d29a..ad20737b 100644 --- a/src/de/blinkt/openvpn/OpenVpnService.java +++ b/src/de/blinkt/openvpn/OpenVpnService.java @@ -45,7 +45,7 @@ public class OpenVpnService extends VpnService implements Handler.Callback { private Vector mRoutes=new Vector(); - private CIDRIP mLocalIP; + private CIDRIP mLocalIP=null; private OpenVpnManagementThread mSocketManager; @@ -253,7 +253,12 @@ public class OpenVpnService extends VpnService implements Handler.Callback { public ParcelFileDescriptor openTun() { Builder builder = new Builder(); - + + if(mLocalIP==null) { + OpenVPN.logMessage(0, "", getString(R.string.opentun_no_ipaddr)); + return null; + } + builder.addAddress(mLocalIP.mIp, mLocalIP.len); for (String dns : mDnslist ) { @@ -282,15 +287,16 @@ public class OpenVpnService extends VpnService implements Handler.Callback { bconfig[3] = String.format(getString(R.string.dns_domain_info, mDomain)); bconfig[4] = String.format(getString(R.string.routes_info, joinString(mRoutes))); + builder.setSession(mProfile.mName + " - " + mLocalIP); + OpenVPN.logBuilderConfig(bconfig); + // Reset information mDnslist.clear(); mRoutes.clear(); - - - builder.setSession(mProfile.mName + " - " + mLocalIP); - + mLocalIP=null; + // Let the configure Button show the Log Intent intent = new Intent(getBaseContext(),LogWindow.class); PendingIntent startLW = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0); diff --git a/src/de/blinkt/openvpn/Settings_Authentication.java b/src/de/blinkt/openvpn/Settings_Authentication.java index 003a26dd..5849923d 100644 --- a/src/de/blinkt/openvpn/Settings_Authentication.java +++ b/src/de/blinkt/openvpn/Settings_Authentication.java @@ -106,7 +106,7 @@ public class Settings_Authentication extends PreferenceFragment implements OnPre return true; } void startFileDialog() { - Intent startFC = new Intent(getActivity(),FileSelectionFragment.class); + Intent startFC = new Intent(getActivity(),FileSelect.class); startFC.putExtra(FileSelect.START_DATA, "/sdcard"); startActivityForResult(startFC,SELECT_TLS_FILE); @@ -130,6 +130,7 @@ public class Settings_Authentication extends PreferenceFragment implements OnPre } private void setTlsAuthSummary(String result) { + if(result==null) result = getString(R.string.no_certificate); if(result.startsWith(FileSelect.INLINE_TAG)) mTLSAuthFile.setSummary(R.string.inline_file_data); else -- cgit v1.2.3