summaryrefslogtreecommitdiff
path: root/src/de/blinkt
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2013-12-15 16:42:28 +0100
committerArne Schwabe <arne@rfc2549.org>2013-12-15 16:42:28 +0100
commit1e710399e226b4b18ea29e20c32c1aa7d5293dd4 (patch)
tree09788ce775856dfff2315efa4990fc2788b5af9f /src/de/blinkt
parenta51eda3d7de8387316814cadddc1f5fde3c8b3aa (diff)
Always log Exception to log
Diffstat (limited to 'src/de/blinkt')
-rw-r--r--src/de/blinkt/openvpn/FileProvider.java5
-rw-r--r--src/de/blinkt/openvpn/LaunchVPN.java5
-rw-r--r--src/de/blinkt/openvpn/VpnProfile.java6
-rw-r--r--src/de/blinkt/openvpn/api/ExternalOpenVPNService.java5
-rw-r--r--src/de/blinkt/openvpn/core/OpenVPNThread.java5
-rw-r--r--src/de/blinkt/openvpn/core/OpenVpnManagementThread.java15
-rw-r--r--src/de/blinkt/openvpn/core/OpenVpnService.java10
-rw-r--r--src/de/blinkt/openvpn/core/ProfileManager.java8
-rw-r--r--src/de/blinkt/openvpn/core/VPNLaunchHelper.java6
-rw-r--r--src/de/blinkt/openvpn/core/VpnStatus.java32
-rw-r--r--src/de/blinkt/openvpn/core/X509Utils.java13
-rw-r--r--src/de/blinkt/openvpn/fragments/AboutFragment.java9
12 files changed, 68 insertions, 51 deletions
diff --git a/src/de/blinkt/openvpn/FileProvider.java b/src/de/blinkt/openvpn/FileProvider.java
index 671d6446..9ffd6545 100644
--- a/src/de/blinkt/openvpn/FileProvider.java
+++ b/src/de/blinkt/openvpn/FileProvider.java
@@ -18,6 +18,7 @@ import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.provider.OpenableColumns;
import android.util.Log;
+import de.blinkt.openvpn.core.VpnStatus;
/**
* A very simple content provider that can serve arbitrary asset files from
@@ -51,8 +52,8 @@ implements PipeDataWriter<InputStream> {
c.addRow(row);
return c;
} catch (FileNotFoundException e) {
- e.printStackTrace();
- return null;
+ VpnStatus.logException(e);
+ return null;
}
diff --git a/src/de/blinkt/openvpn/LaunchVPN.java b/src/de/blinkt/openvpn/LaunchVPN.java
index 10dd3e99..20683805 100644
--- a/src/de/blinkt/openvpn/LaunchVPN.java
+++ b/src/de/blinkt/openvpn/LaunchVPN.java
@@ -273,9 +273,10 @@ public class LaunchVPN extends Activity {
if(ret ==0)
mCmfixed=true;
} catch (InterruptedException e) {
- e.printStackTrace();
+ VpnStatus.logException("SU command", e);
+
} catch (IOException e) {
- e.printStackTrace();
+ VpnStatus.logException("SU command", e);
}
}
diff --git a/src/de/blinkt/openvpn/VpnProfile.java b/src/de/blinkt/openvpn/VpnProfile.java
index abf8d87c..f4389f0b 100644
--- a/src/de/blinkt/openvpn/VpnProfile.java
+++ b/src/de/blinkt/openvpn/VpnProfile.java
@@ -421,7 +421,7 @@ public class VpnProfile implements Serializable {
PackageInfo packageinfo = c.getPackageManager().getPackageInfo(c.getPackageName(), 0);
version = packageinfo.versionName;
} catch (PackageManager.NameNotFoundException e) {
- e.printStackTrace();
+ VpnStatus.logException(e);
}
return String.format(Locale.US, "setenv IV_OPENVPN_GUI_VERSION \"%s %s\"\n", c.getPackageName(), version);
@@ -543,7 +543,7 @@ public class VpnProfile implements Serializable {
cfg.flush();
cfg.close();
} catch (IOException e) {
- e.printStackTrace();
+ VpnStatus.logException(e);
}
return intent;
@@ -651,7 +651,7 @@ public class VpnProfile implements Serializable {
try {
Thread.sleep(3000);
} catch (InterruptedException e1) {
- e1.printStackTrace();
+ VpnStatus.logException(e1);
}
return getKeyStoreCertificates(context, tries-1);
}
diff --git a/src/de/blinkt/openvpn/api/ExternalOpenVPNService.java b/src/de/blinkt/openvpn/api/ExternalOpenVPNService.java
index 765bc23d..c42ac065 100644
--- a/src/de/blinkt/openvpn/api/ExternalOpenVPNService.java
+++ b/src/de/blinkt/openvpn/api/ExternalOpenVPNService.java
@@ -90,7 +90,6 @@ public class ExternalOpenVPNService extends Service implements StateListener {
} catch (NameNotFoundException e) {
// App not found. Remove it from the list
mExtAppDb.removeApp(apppackage);
- e.printStackTrace();
}
}
@@ -156,10 +155,10 @@ public class ExternalOpenVPNService extends Service implements StateListener {
ProfileManager pm = ProfileManager.getInstance(getBaseContext());
pm.addProfile(vp);
} catch (IOException e) {
- e.printStackTrace();
+ VpnStatus.logException(e);
return false;
} catch (ConfigParseError e) {
- e.printStackTrace();
+ VpnStatus.logException(e);
return false;
}
diff --git a/src/de/blinkt/openvpn/core/OpenVPNThread.java b/src/de/blinkt/openvpn/core/OpenVPNThread.java
index f814ff29..dacd41c9 100644
--- a/src/de/blinkt/openvpn/core/OpenVPNThread.java
+++ b/src/de/blinkt/openvpn/core/OpenVPNThread.java
@@ -48,7 +48,7 @@ public class OpenVPNThread implements Runnable {
startOpenVPNThreadArgs(mArgv, mProcessEnv);
Log.i(TAG, "Giving up");
} catch (Exception e) {
- e.printStackTrace();
+ VpnStatus.logException("Starting OpenVPN Thread" ,e);
Log.e(TAG, "OpenVPNThread Got " + e.toString());
} finally {
int exitvalue = 0;
@@ -149,8 +149,7 @@ public class OpenVPNThread implements Runnable {
} catch (IOException e) {
- VpnStatus.logError("Error reading from output of OpenVPN process" + e.getLocalizedMessage());
- e.printStackTrace();
+ VpnStatus.logException("Error reading from output of OpenVPN process" , e);
stopProcess();
}
diff --git a/src/de/blinkt/openvpn/core/OpenVpnManagementThread.java b/src/de/blinkt/openvpn/core/OpenVpnManagementThread.java
index abca275a..59c9dfa2 100644
--- a/src/de/blinkt/openvpn/core/OpenVpnManagementThread.java
+++ b/src/de/blinkt/openvpn/core/OpenVpnManagementThread.java
@@ -73,7 +73,6 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement {
// wait 300 ms before retrying
try { Thread.sleep(300);
} catch (InterruptedException e1) {
- e1.printStackTrace();
}
}
@@ -85,7 +84,7 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement {
mServerSocket = new LocalServerSocket(mServerSocketLocal.getFileDescriptor());
return true;
} catch (IOException e) {
- e.printStackTrace();
+ VpnStatus.logException(e);
}
return false;
@@ -131,8 +130,7 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement {
try {
fds = mSocket.getAncillaryFileDescriptors();
} catch (IOException e) {
- VpnStatus.logError("Error reading fds from socket" + e.getLocalizedMessage());
- e.printStackTrace();
+ VpnStatus.logException("Error reading fds from socket", e);
}
if(fds!=null){
Collections.addAll(mFDList, fds);
@@ -148,7 +146,7 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement {
}
} catch (IOException e) {
- e.printStackTrace();
+ VpnStatus.logException(e);
}
active.remove(this);
}
@@ -180,9 +178,8 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement {
exp =e;
}
- exp.printStackTrace();
Log.d("Openvpn", "Failed to retrieve fd from socket: " + fd);
- VpnStatus.logError("Failed to retrieve fd from socket: " + exp.getLocalizedMessage());
+ VpnStatus.logException("Failed to retrieve fd from socket", exp);
}
private String processInput(String pendingInput) {
@@ -297,7 +294,6 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
- e.printStackTrace();
}
}
@@ -457,8 +453,7 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement {
} catch (IOException e) {
exp =e;
}
- VpnStatus.logError("Could not send fd over socket:" + exp.getLocalizedMessage());
- exp.printStackTrace();
+ VpnStatus.logException("Could not send fd over socket" , exp);
return false;
}
diff --git a/src/de/blinkt/openvpn/core/OpenVpnService.java b/src/de/blinkt/openvpn/core/OpenVpnService.java
index 43bf702b..3de701b1 100644
--- a/src/de/blinkt/openvpn/core/OpenVpnService.java
+++ b/src/de/blinkt/openvpn/core/OpenVpnService.java
@@ -209,13 +209,13 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac
//ignore exception
} catch (NoSuchMethodException nsm) {
- nsm.printStackTrace();
+ VpnStatus.logException(nsm);
} catch (IllegalArgumentException e) {
- e.printStackTrace();
+ VpnStatus.logException(e);
} catch (IllegalAccessException e) {
- e.printStackTrace();
+ VpnStatus.logException(e);
} catch (InvocationTargetException e) {
- e.printStackTrace();
+ VpnStatus.logException(e);
}
}
@@ -312,7 +312,6 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
- e.printStackTrace();
}
@@ -321,7 +320,6 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
- e.printStackTrace();
}
}
// An old running VPN should now be exited
diff --git a/src/de/blinkt/openvpn/core/ProfileManager.java b/src/de/blinkt/openvpn/core/ProfileManager.java
index 27b64b90..a1dd8da5 100644
--- a/src/de/blinkt/openvpn/core/ProfileManager.java
+++ b/src/de/blinkt/openvpn/core/ProfileManager.java
@@ -145,13 +145,11 @@ public class ProfileManager {
vpnfile.close();
} catch (FileNotFoundException e) {
- e.printStackTrace();
+ VpnStatus.logException("saving VPN profile", e);
throw new RuntimeException(e);
} catch (IOException e) {
-
- e.printStackTrace();
+ VpnStatus.logException("saving VPN profile", e);
throw new RuntimeException(e);
-
}
}
@@ -186,7 +184,7 @@ public class ProfileManager {
exp=e;
}
if(exp!=null) {
- exp.printStackTrace();
+ VpnStatus.logException("Loading VPN List",exp);
}
}
}
diff --git a/src/de/blinkt/openvpn/core/VPNLaunchHelper.java b/src/de/blinkt/openvpn/core/VPNLaunchHelper.java
index a8770a69..5f1efb5f 100644
--- a/src/de/blinkt/openvpn/core/VPNLaunchHelper.java
+++ b/src/de/blinkt/openvpn/core/VPNLaunchHelper.java
@@ -53,9 +53,9 @@ public class VPNLaunchHelper {
return true;
} catch (IOException e) {
if(e2!=null)
- VpnStatus.logError( e2.getLocalizedMessage());
- VpnStatus.logError(e.getLocalizedMessage());
- e.printStackTrace();
+ VpnStatus.logException(e2);
+ VpnStatus.logException(e);
+
return false;
}
}
diff --git a/src/de/blinkt/openvpn/core/VpnStatus.java b/src/de/blinkt/openvpn/core/VpnStatus.java
index d6a86246..f1445f77 100644
--- a/src/de/blinkt/openvpn/core/VpnStatus.java
+++ b/src/de/blinkt/openvpn/core/VpnStatus.java
@@ -12,6 +12,9 @@ import android.os.Parcelable;
import de.blinkt.openvpn.R;
import java.io.ByteArrayInputStream;
+import java.io.FileNotFoundException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
@@ -41,6 +44,25 @@ public class VpnStatus {
private static long mlastByteCount[]={0,0,0,0};
+ public static void logException(LogLevel ll, String context, Exception e) {
+ StringWriter sw = new StringWriter();
+ e.printStackTrace(new PrintWriter(sw));
+ LogItem li;
+ if (context !=null) {
+ li = new LogItem(ll, R.string.unhandled_exception_context, e.getMessage(), sw.toString(), context);
+ } else {
+ li = new LogItem(ll, R.string.unhandled_exception, e.getMessage(), sw.toString());
+ }
+ newLogItem(li);
+ }
+
+ public static void logException(Exception e) {
+ logException(LogLevel.ERROR, null, e);
+ }
+
+ public static void logException(String context, Exception e) {
+ logException(LogLevel.ERROR, context, e);
+ }
public enum ConnectionStatus {
@@ -154,11 +176,11 @@ public class VpnStatus {
}
};
- public LogItem(LogLevel loglevel,int ressourceId, Object[] args) {
- mRessourceId = ressourceId;
- mArgs = args;
- mLevel = loglevel;
- }
+ public LogItem(LogLevel loglevel,int ressourceId, Object... args) {
+ mRessourceId = ressourceId;
+ mArgs =args;
+ mLevel = loglevel;
+ }
public LogItem(LogLevel loglevel, String msg) {
diff --git a/src/de/blinkt/openvpn/core/X509Utils.java b/src/de/blinkt/openvpn/core/X509Utils.java
index f6bd7774..5781cbf5 100644
--- a/src/de/blinkt/openvpn/core/X509Utils.java
+++ b/src/de/blinkt/openvpn/core/X509Utils.java
@@ -79,6 +79,7 @@ public class X509Utils {
String friendlyName=null;
/* Hack so we do not have to ship a whole Spongy/bouncycastle */
+ Exception exp=null;
try {
Class X509NameClass = Class.forName("com.android.org.bouncycastle.asn1.x509.X509Name");
Method getInstance = X509NameClass.getMethod("getInstance",Object.class);
@@ -95,16 +96,18 @@ public class X509Utils {
friendlyName= (String) toString.invoke(subjectName,true,defaultSymbols);
} catch (ClassNotFoundException e) {
- e.printStackTrace();
+ exp =e ;
} catch (NoSuchMethodException e) {
- e.printStackTrace();
+ exp =e;
} catch (InvocationTargetException e) {
- e.printStackTrace();
+ exp =e;
} catch (IllegalAccessException e) {
- e.printStackTrace();
+ exp =e;
} catch (NoSuchFieldException e) {
- e.printStackTrace();
+ exp =e;
}
+ if (exp!=null)
+ VpnStatus.logException("Getting X509 Name from certificate", exp);
/* Fallback if the reflection method did not work */
if(friendlyName==null)
diff --git a/src/de/blinkt/openvpn/fragments/AboutFragment.java b/src/de/blinkt/openvpn/fragments/AboutFragment.java
index ac7943db..61fcb581 100644
--- a/src/de/blinkt/openvpn/fragments/AboutFragment.java
+++ b/src/de/blinkt/openvpn/fragments/AboutFragment.java
@@ -23,6 +23,7 @@ import android.webkit.WebView;
import android.widget.TextView;
import com.android.vending.billing.IInAppBillingService;
import de.blinkt.openvpn.R;
+import de.blinkt.openvpn.core.VpnStatus;
import org.json.JSONException;
import org.json.JSONObject;
@@ -123,7 +124,7 @@ public class AboutFragment extends Fragment implements View.OnClickListener {
}
} catch (RemoteException e) {
- e.printStackTrace();
+ VpnStatus.logException(e);
}
}
@@ -196,7 +197,7 @@ public class AboutFragment extends Fragment implements View.OnClickListener {
}
} catch (JSONException e) {
- e.printStackTrace();
+ VpnStatus.logException("Parsing Play Store IAP",e);
}
}
@@ -230,9 +231,9 @@ public class AboutFragment extends Fragment implements View.OnClickListener {
}
} catch (RemoteException e) {
- e.printStackTrace();
+ VpnStatus.logException(e);
} catch (IntentSender.SendIntentException e) {
- e.printStackTrace();
+ VpnStatus.logException(e);
}
}