Updated ExceptionHandler to use the new ExceptionHandler Library

This commit is contained in:
2012-02-03 14:57:51 -05:00
parent d5e5d8d0f9
commit 0fda6cd43a
10 changed files with 67 additions and 241 deletions

View File

@@ -4,5 +4,7 @@
<classpathentry kind="src" path="gen"/> <classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="lib" path="libs/admob-sdk-android.jar"/> <classpathentry kind="lib" path="libs/admob-sdk-android.jar"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="lib" path="/app/android-sdk-linux_86/extras/google/admob_ads_sdk/GoogleAdMobAdsSdk-4.3.1.jar"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath> </classpath>

View File

@@ -1,26 +1,35 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.TwentyCode.android.ExaltedDice" android:installLocation="auto"
android:versionName="1.0.1" android:installLocation="auto" android:versionCode="15"> package="com.TwentyCode.android.ExaltedDice"
<application android:icon="@drawable/icon" android:label="@string/app_name"> android:versionCode="15"
<activity android:name=".ExaltedDice" android:versionName="1.0.1" >
android:label="@string/app_name"> <application
android:icon="@drawable/icon"
android:label="@string/app_name" >
<activity
android:name=".ExaltedDice"
android:label="@string/app_name" >
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<meta-data android:value="a14bad63772f7d3" android:name="ADMOB_PUBLISHER_ID" /> <meta-data
android:name="ADMOB_PUBLISHER_ID"
android:value="a14bad63772f7d3" />
<activity android:name="com.TwentyCodes.android.exception.ExceptionReportActivity" >
</activity>
</application> </application>
<uses-sdk android:minSdkVersion="3" /> <uses-sdk android:minSdkVersion="3" />
<uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_LOGS" /> <uses-permission android:name="android.permission.READ_LOGS" />
</manifest> </manifest><!-- android:screenOrientation="portrait" -->
<!-- android:screenOrientation="portrait" -->

View File

@@ -0,0 +1,19 @@
# exceptionhandler.properties
# This is the default Twenty Codes, LLC Exception Handler properties file
#
# @author Twenty Codes, LLC
# @author ricky barrette
# The following is for using our custom server based exception handler web application
# HTTP ONLY
# server is the physical web address for your server
# file is the path to your filing script
# get is the path to your json retrieval script
server = http://powers.doesntexist.com:666/testing
file = /index.php?post=1
#get = /index.php?get=1
# uncomment the following if you want your application to use email to file reports.
# if this is uncommented, email will always be used.
#email = twentycodes@gmail.com

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

12
ExaltedDice/default.properties Executable file → Normal file
View File

@@ -1,13 +1,5 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "build.properties", and override values to adapt the script to your
# project structure.
# Indicates whether an apk should be generated for each density. # Indicates whether an apk should be generated for each density.
split.density=false split.density=false
# Project target. # Project target.
target=android-8 target=android-15
android.library.reference.1=../../exception_handler_library/ExceptionHandlerLib

3
ExaltedDice/lint.xml Normal file
View File

@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<lint>
</lint>

View File

@@ -0,0 +1,12 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "ant.properties", and override values to adapt the script to your
# project structure.
# Indicates whether an apk should be generated for each density.
# Project target.
target=android-15

View File

@@ -3,6 +3,8 @@ package com.TwentyCode.android.ExaltedDice;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Random; import java.util.Random;
import com.TwentyCodes.android.exception.ExceptionHandler;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
@@ -48,7 +50,6 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
private int mEnd = 999; private int mEnd = 999;
private static final int MENU_QUIT = Menu.FIRST; private static final int MENU_QUIT = Menu.FIRST;
private static final int MENU_CLEAR = Menu.FIRST + 1; private static final int MENU_CLEAR = Menu.FIRST + 1;
protected PostMortemReportExceptionHandler mDamageReport = new PostMortemReportExceptionHandler(this);
private static final String TAG = "ExaltedDice"; private static final String TAG = "ExaltedDice";
private Handler mHandler; private Handler mHandler;
//this runnable will be used to increment or decrement the amount of dice being rolled //this runnable will be used to increment or decrement the amount of dice being rolled
@@ -229,9 +230,8 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
*/ */
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
mDamageReport.run(); Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this));
Thread.setDefaultUncaughtExceptionHandler(mDamageReport);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Log.i(TAG, "onCreate()"); Log.i(TAG, "onCreate()");
setContentView(R.layout.main); setContentView(R.layout.main);

View File

@@ -1,211 +0,0 @@
package com.TwentyCode.android.ExaltedDice;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.Thread.UncaughtExceptionHandler;
import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.Date;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Build;
/**
* dont forget the manifest tag
* <uses-permission android:name="android.permission.READ_LOGS" />
* @author ricky
*/
public class PostMortemReportExceptionHandler implements UncaughtExceptionHandler, Runnable {
public static final String ExceptionReportFilename = "postmortem.trace";
private static final String MSG_SUBJECT_TAG = "Exception Report"; //"app title + this tag" = email subject
private static final String MSG_SENDTO = "twentycodes@gmail.com"; //email will be sent to this account
//the following may be something you wish to consider localizing
private static final String MSG_BODY = "Just click send to help make this application better. "+
"No personal information is being sent (you can check by reading the rest of the email).";
private Thread.UncaughtExceptionHandler mDefaultUEH;
private Activity mApp = null;
public PostMortemReportExceptionHandler(Activity aApp) {
mDefaultUEH = Thread.getDefaultUncaughtExceptionHandler();
mApp = aApp;
}
public String getDebugReport(Throwable aException) {
// NumberFormat theFormatter = new DecimalFormat("#0.");
//stack trace
StackTraceElement[] theStackTrace = aException.getStackTrace();
StringBuffer report = new StringBuffer();
report.append("--------- Application ---------\n\n");
report.append(mApp.getPackageName()+" generated the following exception:\n\n");
report.append(aException.toString() + "\n\n");
report.append("-------------------------------\n\n");
report.append("--------- Stack trace ---------\n\n");
for (int i = 0; i < theStackTrace.length; i++) {
report.append(" " + theStackTrace[i].toString() + "\n");
}
report.append("-------------------------------\n\n");
//app environment
PackageManager pm = mApp.getPackageManager();
PackageInfo pi;
try {
pi = pm.getPackageInfo(mApp.getPackageName(), 0);
} catch (NameNotFoundException eNnf) {
//doubt this will ever run since we want info about our own package
pi = new PackageInfo();
pi.versionName = "unknown";
pi.versionCode = 69;
}
Date theDate = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd_HH.mm.ss_zzz");
report.append("-------- Environment --------\n");
report.append("Time\t="+sdf.format(theDate)+"\n");
report.append("Device\t="+Build.FINGERPRINT+"\n");
try {
Field theMfrField = Build.class.getField("MANUFACTURER");
report.append("Make\t="+theMfrField.get(null)+"\n");
} catch (SecurityException e) {
} catch (NoSuchFieldException e) {
} catch (IllegalArgumentException e) {
} catch (IllegalAccessException e) {
}
report.append("Device: " + Build.DEVICE + "\n");
report.append("Brand: " + Build.BRAND + "\n");
report.append("Model: "+Build.MODEL+"\n");
report.append("Product: "+Build.PRODUCT+"\n");
report.append("App:\t "+mApp.getPackageName()+", version "+pi.versionName+" (build "+pi.versionCode+")\n");
report.append("Locale: "+mApp.getResources().getConfiguration().locale.getDisplayName()+"\n");
report.append("-----------------------------\n\n");
report.append("--------- Firmware ---------\n\n");
report.append("SDK: " + Build.VERSION.SDK + "\n");
report.append("Release: " + Build.VERSION.RELEASE + "\n");
report.append("Incremental: " + Build.VERSION.INCREMENTAL + "\n");
report.append("Build Id: " + Build.ID + "\n");
report.append("-------------------------------\n\n");
// If the exception was thrown in a background thread inside
// AsyncTask, then the actual exception can be found with getCause
report.append("--------- Cause ---------\n\n");
Throwable cause = aException.getCause();
if (cause != null) {
report.append(cause.toString() + "\n\n");
theStackTrace = cause.getStackTrace();
for (int i = 0; i < theStackTrace.length; i++) {
report.append(" " + theStackTrace[i].toString() + "\n");
}
}
report.append("-------------------------------\n\n");
report.append("--------- Complete Logcat ---------\n\n");
report.append(getLog().toString());
report.append("-------------------------------\n\n");
report.append("END REPORT");
return report.toString();
}
protected StringBuilder getLog(){
final StringBuilder log = new StringBuilder();
try{
Process process = Runtime.getRuntime().exec("logcat -d");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = bufferedReader.readLine()) != null){
log.append(line);
log.append("\n");
}
}
catch (IOException e){
}
return log;
}
public void run() {
sendDebugReportToAuthor();
}
protected void saveDebugReport(String aReport) {
//save report to file
try {
FileOutputStream theFile = mApp.openFileOutput(ExceptionReportFilename, Context.MODE_PRIVATE);
theFile.write(aReport.getBytes());
theFile.close();
} catch(IOException ioe) {
//error during error report needs to be ignored, do not wish to start infinite loop
}
}
public void sendDebugReportToAuthor() {
String theLine = "";
StringBuffer theTrace = new StringBuffer();
try {
BufferedReader theReader = new BufferedReader(
new InputStreamReader(mApp.openFileInput(ExceptionReportFilename)));
while ((theLine = theReader.readLine())!=null) {
theTrace.append(theLine+"\n");
}
if (sendDebugReportToAuthor(theTrace.toString())) {
mApp.deleteFile(ExceptionReportFilename);
}
} catch (FileNotFoundException eFnf) {
// nothing to do
} catch(IOException eIo) {
// not going to report
}
}
public Boolean sendDebugReportToAuthor(String aReport) {
if (aReport!=null) {
Intent theIntent = new Intent(Intent.ACTION_SEND);
String theSubject = mApp.getTitle()+" "+MSG_SUBJECT_TAG;
String theBody = "\n"+MSG_BODY+"\n\n"+aReport+"\n\n";
theIntent.putExtra(Intent.EXTRA_EMAIL,new String[] {MSG_SENDTO});
theIntent.putExtra(Intent.EXTRA_TEXT, theBody);
theIntent.putExtra(Intent.EXTRA_SUBJECT, theSubject);
theIntent.setType("message/rfc822");
Boolean hasSendRecipients = (mApp.getPackageManager().queryIntentActivities(theIntent,0).size()>0);
if (hasSendRecipients) {
mApp.startActivity(theIntent);
return true;
} else {
return false;
}
} else {
return true;
}
}
public void submit(Throwable e) {
String theErrReport = getDebugReport(e);
saveDebugReport(theErrReport);
//try to send file contents via email (need to do so via the UI thread)
mApp.runOnUiThread(this);
}
public void uncaughtException(Thread t, Throwable e) {
submit(e);
//do not forget to pass this exception through up the chain
mDefaultUEH.uncaughtException(t,e);
}
}