Added crash reporting

This commit is contained in:
M66B 2015-11-20 10:10:22 +01:00
parent b577094a6f
commit 94e8d5c71b
25 changed files with 151 additions and 24 deletions

View File

@ -65,27 +65,23 @@
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes-proguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/debug" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/23.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard-rules" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/release" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/tmp" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>

View File

@ -124,8 +124,8 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
startActivityForResult(prepare, REQUEST_VPN);
} catch (Throwable ex) {
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
Util.sendCrashReport(ex, ActivityMain.this);
onActivityResult(REQUEST_VPN, RESULT_CANCELED, null);
Toast.makeText(ActivityMain.this, ex.toString(), Toast.LENGTH_LONG).show();
}
}
}
@ -476,6 +476,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
}
} catch (Throwable ex) {
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
Util.sendCrashReport(ex, ActivityMain.this);
}
}
});

View File

@ -219,6 +219,7 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
return null;
} catch (Throwable ex) {
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
Util.sendCrashReport(ex, ActivitySettings.this);
return ex;
} finally {
if (out != null)
@ -267,6 +268,7 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
return null;
} catch (Throwable ex) {
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
Util.sendCrashReport(ex, ActivitySettings.this);
return ex;
} finally {
if (in != null)

View File

@ -37,6 +37,7 @@ public class ApplicationEx extends Application {
@Override
public void uncaughtException(Thread thread, Throwable ex) {
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
Util.sendCrashReport(ex, ApplicationEx.this);
if (mPrevHandler != null)
mPrevHandler.uncaughtException(thread, ex);
}

View File

@ -91,6 +91,7 @@ public class IAB implements ServiceConnection {
} catch (Throwable ex) {
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
Util.sendCrashReport(ex, context);
}
}

View File

@ -126,6 +126,7 @@ public class Rule implements Comparable<Rule> {
}
} catch (Throwable ex) {
Log.e(tag, ex.toString() + "\n" + Log.getStackTraceString(ex));
Util.sendCrashReport(ex, context);
}
// Build rule list

View File

@ -94,6 +94,7 @@ public class SinkholeService extends VpnService {
Log.i(TAG, "wakelock=" + wl.isHeld());
} catch (Exception ex) {
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
Util.sendCrashReport(ex, SinkholeService.this);
}
}
}
@ -176,6 +177,7 @@ public class SinkholeService extends VpnService {
builder.addDisallowedApplication(rule.info.packageName);
} catch (PackageManager.NameNotFoundException ex) {
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
Util.sendCrashReport(ex, this);
}
} else
nBlocked++;
@ -209,7 +211,7 @@ public class SinkholeService extends VpnService {
prefs.edit().putBoolean("enabled", false).apply();
// Feedback
Util.toast(ex.toString(), Toast.LENGTH_LONG, this);
Util.sendCrashReport(ex, this);
Widget.updateWidgets(this);
return null;
@ -222,6 +224,7 @@ public class SinkholeService extends VpnService {
pfd.close();
} catch (IOException ex) {
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
Util.sendCrashReport(ex, this);
}
}
@ -275,10 +278,12 @@ public class SinkholeService extends VpnService {
}
} catch (Throwable ex) {
Log.e(TAG, ex.toString());
Util.sendCrashReport(ex, SinkholeService.this);
}
Log.i(TAG, "End receiving");
} catch (Throwable ex) {
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
Util.sendCrashReport(ex, SinkholeService.this);
} finally {
try {
if (in != null)

View File

@ -19,7 +19,10 @@ package eu.faircode.netguard;
Copyright 2015 by Marcel Bokhorst (M66B)
*/
import android.app.AlertDialog;
import android.app.ApplicationErrorReport;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
@ -38,6 +41,9 @@ import android.os.PowerManager;
import android.preference.PreferenceManager;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import java.io.BufferedReader;
@ -45,6 +51,8 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.security.MessageDigest;
import java.util.Map;
import java.util.Set;
@ -102,15 +110,6 @@ public class Util {
return ((context.getApplicationContext().getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0);
}
public static void toast(final String text, final int length, final Context context) {
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
Toast.makeText(context, text, length).show();
}
});
}
public static boolean hasValidFingerprint(String tag, Context context) {
try {
PackageManager pm = context.getPackageManager();
@ -152,6 +151,55 @@ public class Util {
}
}
public static boolean sendCrashReport(Throwable ex, final Context context) {
ApplicationErrorReport report = new ApplicationErrorReport();
report.packageName = report.processName = context.getPackageName();
report.time = System.currentTimeMillis();
report.type = ApplicationErrorReport.TYPE_CRASH;
report.systemApp = false;
ApplicationErrorReport.CrashInfo crash = new ApplicationErrorReport.CrashInfo();
crash.exceptionClassName = ex.getClass().getSimpleName();
crash.exceptionMessage = ex.getMessage();
StringWriter writer = new StringWriter();
PrintWriter printer = new PrintWriter(writer);
ex.printStackTrace(printer);
crash.stackTrace = writer.toString();
StackTraceElement stack = ex.getStackTrace()[0];
crash.throwClassName = stack.getClassName();
crash.throwFileName = stack.getFileName();
crash.throwLineNumber = stack.getLineNumber();
crash.throwMethodName = stack.getMethodName();
report.crashInfo = crash;
final Intent bug = new Intent(Intent.ACTION_APP_ERROR);
bug.putExtra(Intent.EXTRA_BUG_REPORT, report);
if (bug.resolveActivity(context.getPackageManager()) == null) {
Toast.makeText(context, ex.toString(), Toast.LENGTH_LONG).show();
return false;
} else {
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.bug, null);
TextView tvBug = (TextView) view.findViewById(R.id.tvBug);
tvBug.setText(ex.toString());
new AlertDialog.Builder(context)
.setView(view)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
context.startActivity(bug);
}
})
.create()
.show();
return true;
}
}
public static void sendLogcat(final String tag, final Context context) {
AsyncTask task = new AsyncTask<Object, Object, Intent>() {
@Override

View File

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="20dp"
android:paddingEnd="20dp"
android:paddingStart="20dp"
android:paddingTop="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="@mipmap/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="8dp"
android:text="@string/app_name"
android:textAppearance="@android:style/TextAppearance.Material.Large"
android:textStyle="bold" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/msg_bug"
android:textAppearance="@android:style/TextAppearance.Material.Medium" />
<TextView
android:id="@+id/tvBug"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:textAppearance="@android:style/TextAppearance.Material.Small"
android:textStyle="italic" />
</LinearLayout>
</ScrollView>
</LinearLayout>

View File

@ -39,6 +39,7 @@ Since NetGuard has no internet permission, you know your internet traffic is not
<string name="msg_try">Try NetGuard</string>
<string name="msg_voluntary">Donations are completely voluntary and do not unlock any feature. Donations are meant as a way to show your appreciation for the work done.</string>
<string name="msg_dimming">If you cannot press OK in the next dialog, another (screen dimming) application is likely manipulating the screen.</string>
<string name="msg_bug">Something has gone wrong, please describe in the next dialog what you were doing to help improve NetGuard</string>
<string name="title_using">Allow when screen is on</string>
<string name="title_roaming">Block when roaming</string>

View File

@ -36,6 +36,7 @@ Das wird von Fehlern in Android oder in Software vom Hersteller verursacht. Bitt
<string name="msg_try">NetGuard ausprobieren</string>
<string name="msg_voluntary">Spenden sind vollkommen freiwillig und schalten keine Funktionen frei. Spenden helfen, die App weiterzuentwickeln und stellen eine Anerkennung für die Arbeit dar.</string>
<string name="msg_dimming">Falls Sie nicht auf OK im nächsten Fenster tippen können, manipuliert eine andere Anwendung Ihren Bildschirm.</string>
<string name="msg_bug">Something has gone wrong, please describe in the next dialog what you were doing to help improve NetGuard</string>
<string name="title_using">Erlauben, wenn Bildschirm an</string>
<string name="title_roaming">Bei Roaming blockieren</string>

View File

@ -39,6 +39,7 @@ Puesto que NetGuard no tiene permisos de internet, ya sabes que tu tráfico de i
<string name="msg_try">Prueba NetGuard</string>
<string name="msg_voluntary">Las donaciones son completamente voluntarias y no desbloquean ninguna funcionalidad. Las donaciones son una forma de mostrar tu apreciación por el trabajo hecho.</string>
<string name="msg_dimming">If you cannot press OK in the next dialog, another (screen dimming) application is likely manipulating the screen.</string>
<string name="msg_bug">Something has gone wrong, please describe in the next dialog what you were doing to help improve NetGuard</string>
<string name="title_using">Permitir cuando la pantalla esté encendida</string>
<string name="title_roaming">Bloquear cuando se esté en roaming</string>

View File

@ -40,6 +40,7 @@ Netguard n\'a pas access a internet,vous savez que votre trafic Internet n\'est
<string name="msg_try">Essayer NetGuard</string>
<string name="msg_voluntary">Les dons sont completement a votre volonté et ils ne débloqueront aucune nouvelle fonctionalitée.
<string name="msg_dimming">If you cannot press OK in the next dialog, another (screen dimming) application is likely manipulating the screen.</string>
<string name="msg_bug">Something has gone wrong, please describe in the next dialog what you were doing to help improve NetGuard</string>
Faire un don est une de façon de montrer votre soutiens aux développeur et votre appréciation pour le travail accompli.</string>
<string name="title_using">Accepter si l\'ecran est allumé</string>

View File

@ -41,6 +41,7 @@ Ció è causato da alcuni bug contenuti in Android, o in programmi forniti dal p
<string name="msg_try">Prova NetGuard</string>
<string name="msg_voluntary">Le donazioni sono totalmente volontarie e non sbloccano nessuna funzionalitá aggiuntiva. Le donazioni mostrano il tuo apprezzamento per il lavoro svolto.</string>
<string name="msg_dimming">Se non riesci a cliccare OK nella prossima schermata, è probabile che un\'altra applicazione (di oscuramento schermo) stia manipolando lo schermo.</string>
<string name="msg_bug">Something has gone wrong, please describe in the next dialog what you were doing to help improve NetGuard</string>
<string name="title_using">Permetti quando lo schermo è acceso</string>
<string name="title_roaming">Blocca quando in roaming</string>

View File

@ -26,6 +26,7 @@
<string name="msg_try">Try NetGuard</string>
<string name="msg_voluntary">Donations are completely voluntary and do not unlock any feature. Donations are meant as a way to show your appreciation for the work done.</string>
<string name="msg_dimming">If you cannot press OK in the next dialog, another (screen dimming) application is likely manipulating the screen.</string>
<string name="msg_bug">Something has gone wrong, please describe in the next dialog what you were doing to help improve NetGuard</string>
<string name="summary_system">システムアプリケーションのルールを定義します (エキスパート向け)</string>
<string name="summary_metered">Apply mobile network rules to metered (paid, tethered) Wi-Fi networks</string>

View File

@ -39,6 +39,7 @@ Since NetGuard has no internet permission, you know your internet traffic is not
<string name="msg_try">Try NetGuard</string>
<string name="msg_voluntary">Donations are completely voluntary and do not unlock any feature. Donations are meant as a way to show your appreciation for the work done.</string>
<string name="msg_dimming">If you cannot press OK in the next dialog, another (screen dimming) application is likely manipulating the screen.</string>
<string name="msg_bug">Something has gone wrong, please describe in the next dialog what you were doing to help improve NetGuard</string>
<string name="title_using">Allow when screen is on</string>
<string name="title_roaming">Block when roaming</string>

View File

@ -39,6 +39,7 @@ Since NetGuard has no internet permission, you know your internet traffic is not
<string name="msg_try">Probeer NetGuard</string>
<string name="msg_voluntary">Donations are completely voluntary and do not unlock any feature. Donations are meant as a way to show your appreciation for the work done.</string>
<string name="msg_dimming">If you cannot press OK in the next dialog, another (screen dimming) application is likely manipulating the screen.</string>
<string name="msg_bug">Something has gone wrong, please describe in the next dialog what you were doing to help improve NetGuard</string>
<string name="title_using">Sta toe als scherm aan is</string>
<string name="title_roaming">Blokkeer bij roamen</string>

View File

@ -39,6 +39,7 @@ Since NetGuard has no internet permission, you know your internet traffic is not
<string name="msg_try">Spróbuj NetGuard</string>
<string name="msg_voluntary">Donations are completely voluntary and do not unlock any feature. Donations are meant as a way to show your appreciation for the work done.</string>
<string name="msg_dimming">If you cannot press OK in the next dialog, another (screen dimming) application is likely manipulating the screen.</string>
<string name="msg_bug">Something has gone wrong, please describe in the next dialog what you were doing to help improve NetGuard</string>
<string name="title_using">Allow when screen is on</string>
<string name="title_roaming">Blokuj gdy roaming</string>

View File

@ -39,6 +39,7 @@ Cum NetGuard efectiv nu are permisiunea de a accesa internetul, esti sigur ca tr
<string name="msg_try">Incearca NetGuard</string>
<string name="msg_voluntary">Donatiile sunt voluntare si nu deblocheaza vreo functie ascunsa. Donatiile sunt doar un mod de a iti arata aprecierea pentru munca depusa la aceasta aplicatie.</string>
<string name="msg_dimming">Daca in urmatoarea fereastra de dialog nu poti apasa OK inseamna ca o aplicatie ce manipuleaza ecranul (luminozitatea sau nuanta) blocheaza interactiunea.</string>
<string name="msg_bug">Something has gone wrong, please describe in the next dialog what you were doing to help improve NetGuard</string>
<string name="title_using">Permite doar cand ecranul este pornit</string>
<string name="title_roaming">Blocheaza in roaming</string>

View File

@ -37,6 +37,7 @@ NetGuard не имеет разрешения доступа в интернет
<string name="msg_try">Попробуйте новый фаервол NetGuard</string>
<string name="msg_voluntary">Пожертвования являются абсолютно добровольными и не добавляют никаких возможностей в программу. Пожертвования предназначены сугубо для того, чтобы выразить вашу признательность за проделанную работу.</string>
<string name="msg_dimming">Если вам не удается нажать ОК в следующем диалоговом окне (затемнение экрана), то, скорее всего, какое то другое приложение использует экран.</string>
<string name="msg_bug">Something has gone wrong, please describe in the next dialog what you were doing to help improve NetGuard</string>
<string name="title_using">Разрешить сети, когда экран включен</string>
<string name="title_roaming">Блокировать в роуминге</string>

View File

@ -39,6 +39,7 @@ Keďže NetGuard nemá internetové povolenie, vaša sieťová prevádzka nemô
<string name="msg_try">Skúsiť NetGuard</string>
<string name="msg_voluntary">Dary sú úplne dobrovoľné a neodomknú žiadne funkcie. Dary sú určené ako spôsob, akým možete prejaviť vašu vďačnosť za vykonanú prácu.</string>
<string name="msg_dimming">Ak nemôžete stlačiť tlačidlo OK na ďalšom okne, tak iná aplikácia (na ovladanie jasu) prekrýva obrazovkou.</string>
<string name="msg_bug">Something has gone wrong, please describe in the next dialog what you were doing to help improve NetGuard</string>
<string name="title_using">Povoliť pri zapnutej obrazovke</string>
<string name="title_roaming">Blokovať pri roamingu</string>

View File

@ -36,6 +36,7 @@ Since NetGuard has no internet permission, you know your internet traffic is not
<string name="msg_try">Спробуйте NetGuard</string>
<string name="msg_voluntary">Donations are completely voluntary and do not unlock any feature. Donations are meant as a way to show your appreciation for the work done.</string>
<string name="msg_dimming">If you cannot press OK in the next dialog, another (screen dimming) application is likely manipulating the screen.</string>
<string name="msg_bug">Something has gone wrong, please describe in the next dialog what you were doing to help improve NetGuard</string>
<string name="title_using">Дозволити, коли екран увімкнуто</string>
<string name="title_roaming">Блокувати у роумінгу</string>

View File

@ -39,6 +39,7 @@ NetGuard不具有网络访问权限, 所以您无需担心您的网络流量被
<string name="msg_try">试用NetGuard</string>
<string name="msg_voluntary">捐赠完全出于自愿并且不会解锁任何功能. 捐赠仅作为您对开发者付出劳动的感谢.</string>
<string name="msg_dimming">如果您在下一个对话框中无法点击确定, 可能是另一个应用正在控制屏幕(如屏幕亮度调节软件).</string>
<string name="msg_bug">Something has gone wrong, please describe in the next dialog what you were doing to help improve NetGuard</string>
<string name="title_using">亮屏时允许</string>
<string name="title_roaming">漫游时阻止</string>

View File

@ -40,6 +40,7 @@ Since NetGuard has no internet permission, you know your internet traffic is not
<string name="msg_try">Try NetGuard</string>
<string name="msg_voluntary">Donations are completely voluntary and do not unlock any feature. Donations are meant as a way to show your appreciation for the work done.</string>
<string name="msg_dimming">If you cannot press OK in the next dialog, another (screen dimming) application is likely manipulating the screen.</string>
<string name="msg_bug">Something has gone wrong, please describe in the next dialog what you were doing to help improve NetGuard</string>
<string name="title_using">Allow when screen is on</string>
<string name="title_roaming">Block when roaming</string>

View File

@ -1,9 +1,8 @@
#!/bin/bash
grep -RIl "\<string name=\"msg_packages" app/src/main/res | xargs sed -i -e '/msg_packages/d'
grep -RIl "\<string name=\"msg_started" app/src/main/res | xargs sed -i -e '/msg_started/a\
\ \ \ \ <string name="msg_packages">%1$d allowed, %2$d blocked</string>'
grep -RIl "\<string name=\"msg_bug" app/src/main/res | xargs sed -i -e '/msg_bug/d'
grep -RIl "\<string name=\"msg_dimming" app/src/main/res | xargs sed -i -e '/msg_dimming/a\
\ \ \ \ <string name="msg_bug">Something has gone wrong, please describe in the next dialog what you were doing to help improve NetGuard</string>'
#grep -RIl "\<string name=\"title_disabled" app/src/main/res | xargs sed -i -e 's/Is disabled/is disabled/g'
#grep -RIl "\<string name=\"title_internet" app/src/main/res | xargs sed -i -e 's/Has no internet access/has no internet permission/g'