Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Debugger #495

Merged
merged 3 commits into from
Sep 6, 2016
Merged
Changes from 2 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
26 changes: 22 additions & 4 deletions src/main/java/org/acra/builder/ReportExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Debug;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
Expand Down Expand Up @@ -166,6 +167,20 @@ public void run() {
// We will wait a few seconds at the end of the method to be sure
// that the Toast can be read by the user.
}
//we cannot kill the process if a debugger is connected, as this would kill the whole application
if (Debug.isDebuggerConnected() && reportBuilder.isEndApplication()) {
final String warning = "Warning: Acra may behave differently with a debugger attached";
new Thread() {
@Override
public void run() {
Looper.prepare();
Toast.makeText(context, warning, Toast.LENGTH_LONG).show();
sentToastTimeMillis.setInitialTimeMillis(System.currentTimeMillis());
Looper.loop();
}
}.start();
ACRA.log.w(LOG_TAG, warning);
}

final CrashReportData crashReportData = crashReportDataFactory.createCrashData(reportBuilder);

Expand Down Expand Up @@ -247,7 +262,8 @@ private void endApplication(@Nullable Thread uncaughtExceptionThread, Throwable
final boolean letDefaultHandlerEndApplication = config.alsoReportToAndroidFramework();

final boolean handlingUncaughtException = uncaughtExceptionThread != null;
if (handlingUncaughtException && letDefaultHandlerEndApplication && defaultExceptionHandler != null) {
//defaultExceptionHandler kills the application, so don't do this if a debugger is connected
if (!Debug.isDebuggerConnected() && handlingUncaughtException && letDefaultHandlerEndApplication && defaultExceptionHandler != null) {
// Let the system default handler do it's job and display the force close dialog.
if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "Handing Exception on to default ExceptionHandler");
defaultExceptionHandler.uncaughtException(uncaughtExceptionThread, th);
Expand Down Expand Up @@ -276,9 +292,11 @@ public void run() {
}
lastActivityManager.clearLastActivity();
}

android.os.Process.killProcess(android.os.Process.myPid());
System.exit(10);
//prevent process kill if a debugger is attached, as this would kill the whole application
if (!Debug.isDebuggerConnected()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should only be checking for !Debug.isDebuggerConnected() once, one either line#266 or line#296, not both.

If the Debugger is connected, do you just want to not kill the process?
Or do you also not want it to call the defaultExceptionHandler and clear the last Activity

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can not hand the exception to the defaultExceptionHandler. It will also kill the process. Clearing the last activity is okay though (and as this is the only thing we can do to minimize inconsistent states I think this should definetly be done).

android.os.Process.killProcess(android.os.Process.myPid());
System.exit(10);
}
}
}

Expand Down