Merge pull request #4313 from nextcloud/exceptionHandler

Use ExceptionHandler not on debug builds
This commit is contained in:
Andy Scherzinger 2019-08-12 18:59:05 +02:00 committed by GitHub
commit 27d360eb18
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 10 deletions

View file

@ -34,4 +34,6 @@ public interface AppInfo {
*/
String getFormattedVersionCode();
boolean isDebugBuild();
}

View file

@ -27,4 +27,9 @@ class AppInfoImpl implements AppInfo {
public String getFormattedVersionCode() {
return Integer.toString(BuildConfig.VERSION_CODE);
}
@Override
public boolean isDebugBuild() {
return BuildConfig.DEBUG;
}
}

View file

@ -44,6 +44,7 @@ import android.view.WindowManager;
import com.evernote.android.job.JobManager;
import com.evernote.android.job.JobRequest;
import com.nextcloud.client.account.UserAccountManager;
import com.nextcloud.client.appinfo.AppInfo;
import com.nextcloud.client.device.PowerManagementService;
import com.nextcloud.client.di.ActivityInjector;
import com.nextcloud.client.di.DaggerAppComponent;
@ -144,6 +145,9 @@ public class MainApp extends MultiDexApplication implements HasAndroidInjector {
@Inject
Logger logger;
@Inject
AppInfo appInfo;
private PassCodeManager passCodeManager;
@SuppressWarnings("unused")
@ -196,21 +200,23 @@ public class MainApp extends MultiDexApplication implements HasAndroidInjector {
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
// we don't want to handle crashes occuring inside crash reporter activity/process;
// let the platform deal with those
final boolean isCrashReportingProcess = getAppProcessName().endsWith(":crash");
if (!isCrashReportingProcess) {
Thread.UncaughtExceptionHandler defaultPlatformHandler = Thread.getDefaultUncaughtExceptionHandler();
final ExceptionHandler crashReporter = new ExceptionHandler(this,
defaultPlatformHandler);
Thread.setDefaultUncaughtExceptionHandler(crashReporter);
}
initGlobalContext(this);
DaggerAppComponent.builder()
.application(this)
.build()
.inject(this);
// we don't want to handle crashes occurring inside crash reporter activity/process;
// let the platform deal with those
final boolean isCrashReportingProcess = getAppProcessName().endsWith(":crash");
final boolean useExceptionHandler = !appInfo.isDebugBuild();
if (!isCrashReportingProcess && useExceptionHandler) {
Thread.UncaughtExceptionHandler defaultPlatformHandler = Thread.getDefaultUncaughtExceptionHandler();
final ExceptionHandler crashReporter = new ExceptionHandler(this,
defaultPlatformHandler);
Thread.setDefaultUncaughtExceptionHandler(crashReporter);
}
}
@SuppressFBWarnings("ST")