Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Added a Java global exception handler #602

Merged
merged 1 commit into from
Oct 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.support.annotation.NonNull;
import android.support.v4.app.JobIntentService;
import android.util.Log;

import org.mozilla.geckoview.GeckoRuntime;

public class CrashReporterService extends JobIntentService {
Expand All @@ -32,50 +33,50 @@ public int onStartCommand(Intent intent, int flags, int startId) {

@Override
protected void onHandleWork(@NonNull Intent intent) {
boolean fatal = false;
if (GeckoRuntime.ACTION_CRASHED.equals(intent.getAction())) {
fatal = intent.getBooleanExtra(GeckoRuntime.EXTRA_CRASH_FATAL, false);
}
String action = intent.getAction();
if (GeckoRuntime.ACTION_CRASHED.equals(action)) {
boolean fatal = intent.getBooleanExtra(GeckoRuntime.EXTRA_CRASH_FATAL, false);

if (fatal) {
Log.d(LOGTAG, "======> NATIVE CRASH PARENT" + intent);
final int pid = Process.myPid();
final ActivityManager activityManager = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
if (activityManager == null) {
return;
}

if (fatal) {
Log.d(LOGTAG, "======> PARENT CRASH " + intent);
final int pid = Process.myPid();
final ActivityManager activityManager = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
if (activityManager == null) {
return;
}
do {
boolean otherProcessesFound = false;
for (final ActivityManager.RunningAppProcessInfo info : activityManager.getRunningAppProcesses()) {
if (pid != info.pid) {
otherProcessesFound = true;
Log.e(LOGTAG, "======> Found PID " + info.pid);
break;
}
}

do {
boolean otherProcessesFound = false;
for (final ActivityManager.RunningAppProcessInfo info : activityManager.getRunningAppProcesses()) {
if (pid != info.pid) {
otherProcessesFound = true;
Log.e(LOGTAG, "======> Found PID " + info.pid);
if (!otherProcessesFound) {
intent.setClass(CrashReporterService.this, VRBrowserActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
break;
}
}

if (!otherProcessesFound) {
intent.setClass(CrashReporterService.this, VRBrowserActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
break;

} else {
try {
Thread.sleep(PID_CHECK_INTERVAL);
} catch (InterruptedException e) {
e.printStackTrace();
} else {
try {
Thread.sleep(PID_CHECK_INTERVAL);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}

} while (true);
} while (true);

} else {
Log.d(LOGTAG, "======> CONTENT CRASH " + intent);
Intent broadcastIntent = new Intent(CRASH_ACTION);
broadcastIntent.putExtra(DATA_TAG, intent);
sendBroadcast(broadcastIntent, getString(R.string.app_permission_name));
} else {
Log.d(LOGTAG, "======> NATIVE CRASH CONTENT" + intent);
Intent broadcastIntent = new Intent(CRASH_ACTION);
broadcastIntent.putExtra(DATA_TAG, intent);
sendBroadcast(broadcastIntent, getString(R.string.app_permission_name));
}
}

Log.d(LOGTAG, "======> Crash reporter job finished");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.mozilla.vrbrowser;

import android.support.annotation.NonNull;
import android.util.Log;

import org.mozilla.gecko.CrashHandler;

public class GlobalExceptionHandler {

private static final String LOGTAG = "VRB";

private static GlobalExceptionHandler mInstance;

public static synchronized @NonNull
GlobalExceptionHandler register() {
if (mInstance == null) {
mInstance = new GlobalExceptionHandler();
mInstance.mCrashHandler = new CrashHandler(CrashReporterService.class);
Log.d(LOGTAG, "======> GlobalExceptionHandler registered");
}

return mInstance;
}

private CrashHandler mCrashHandler;
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ public void run() {

@Override
protected void onCreate(Bundle savedInstanceState) {
// Set a global exception handler as soon as possible
GlobalExceptionHandler.register();

if (BuildConfig.FLAVOR_platform == "oculusvr") {
workaroundGeckoSigAction();
}
Expand Down