Bug 1101031 - Report UpdateService crashes; r=snorp

This commit is contained in:
Jim Chen 2014-11-25 15:02:32 -08:00
parent 747f7c15d0
commit e95f778e74
2 changed files with 39 additions and 2 deletions

View File

@ -27,7 +27,7 @@ import android.os.Bundle;
import android.os.Process;
import android.util.Log;
class CrashHandler implements Thread.UncaughtExceptionHandler {
public class CrashHandler implements Thread.UncaughtExceptionHandler {
private static final String LOGTAG = "GeckoCrashHandler";
private static final Thread MAIN_THREAD = Thread.currentThread();
@ -234,7 +234,7 @@ class CrashHandler implements Thread.UncaughtExceptionHandler {
final PackageInfo pkgInfo = pkgMgr.getPackageInfo(pkgName, 0);
extras.putString("Version", pkgInfo.versionName);
extras.putInt("BuildID", pkgInfo.versionCode);
extras.putLong("InstallTime", pkgInfo.firstInstallTime / 1000);
extras.putLong("InstallTime", pkgInfo.lastUpdateTime / 1000);
} catch (final PackageManager.NameNotFoundException e) {
Log.i(LOGTAG, "Error getting package info", e);
}
@ -439,4 +439,30 @@ class CrashHandler implements Thread.UncaughtExceptionHandler {
terminateProcess();
}
}
public static CrashHandler createDefaultCrashHandler(final Context context) {
return new CrashHandler(context) {
@Override
protected Bundle getCrashExtras(final Thread thread, final Throwable exc) {
final Bundle extras = super.getCrashExtras(thread, exc);
extras.putString("ProductName", AppConstants.MOZ_APP_BASENAME);
extras.putString("ProductID", AppConstants.MOZ_APP_ID);
extras.putString("Version", AppConstants.MOZ_APP_VERSION);
extras.putString("BuildID", AppConstants.MOZ_APP_BUILDID);
extras.putString("Vendor", AppConstants.MOZ_APP_VENDOR);
extras.putString("ReleaseChannel", AppConstants.MOZ_UPDATE_CHANNEL);
return extras;
}
@Override
public boolean reportException(final Thread thread, final Throwable exc) {
if (AppConstants.MOZ_CRASHREPORTER && AppConstants.MOZILLA_OFFICIAL) {
// Only use Java crash reporter if enabled on official build.
return super.reportException(thread, exc);
}
return false;
}
};
}
}

View File

@ -6,6 +6,7 @@
package org.mozilla.gecko.updater;
import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.CrashHandler;
import org.mozilla.gecko.R;
import org.mozilla.apache.commons.codec.binary.Hex;
@ -80,12 +81,16 @@ public class UpdateService extends IntentService {
private boolean mCancelDownload;
private boolean mApplyImmediately;
private CrashHandler mCrashHandler;
public UpdateService() {
super("updater");
}
@Override
public void onCreate () {
mCrashHandler = CrashHandler.createDefaultCrashHandler(getApplicationContext());
super.onCreate();
mPrefs = getSharedPreferences(PREFS_NAME, 0);
@ -94,6 +99,12 @@ public class UpdateService extends IntentService {
mCancelDownload = false;
}
@Override
public void onDestroy() {
mCrashHandler.unregister();
mCrashHandler = null;
}
@Override
public synchronized int onStartCommand (Intent intent, int flags, int startId) {
// If we are busy doing a download, the new Intent here would normally be queued for