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

Commit

Permalink
Fixed Android P crash reporter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Sep 24, 2018
1 parent c525bdc commit 125fc03
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
package org.mozilla.vrbrowser;

import android.app.ActivityManager;
import android.app.IntentService;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Build;
import android.os.Process;
import android.os.SystemClock;
import android.support.annotation.Nullable;
import android.support.annotation.NonNull;
import android.support.v4.app.JobIntentService;
import android.util.Log;
import org.mozilla.geckoview.GeckoRuntime;

public class CrashReporterService extends IntentService {
public class CrashReporterService extends JobIntentService {

private static final String LOGTAG = "VRB";

public static final String CRASH_ACTION = "org.mozilla.vrbrowser.CRASH_ACTION";
public static final String DATA_TAG = "intent";
private static final int PID_CHECK_INTERVAL = 10;

private Handler mHandler;
private static final int PID_CHECK_INTERVAL = 100;
private static final int JOB_ID = 1000;

public CrashReporterService() {
super("CrashReporterService");
mHandler = new Handler();
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d(LOGTAG, "======> onStartCommand");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
enqueueWork(this, CrashReporterService.class, JOB_ID, intent);
}

return super.onStartCommand(intent, flags, startId);
}

@Override
protected void onHandleIntent(@Nullable final Intent intent) {
protected void onHandleWork(@NonNull Intent intent) {
boolean fatal = false;
if (GeckoRuntime.ACTION_CRASHED.equals(intent.getAction())) {
fatal = intent.getBooleanExtra(GeckoRuntime.EXTRA_CRASH_FATAL, false);
Expand All @@ -40,29 +44,41 @@ protected void onHandleIntent(@Nullable final Intent intent) {
if (activityManager == null) {
return;
}
while (true) {

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;
}
Log.e(LOGTAG, "Found PID " + info.pid);
}

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

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

} 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));
}

Log.d(LOGTAG, "======> Crash reporter job finished");
}

}
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
<service
android:name=".CrashReporterService"
android:exported="false"
android:process=":crash">
android:process=":crash"
android:permission="android.permission.BIND_JOB_SERVICE">
</service>
</application>
</manifest>

0 comments on commit 125fc03

Please sign in to comment.