Add anr watch dog

This commit is contained in:
seven332 committed 2016-04-14 19:10:38 +08:00
1 parent b4d8168457
commit fbeaf3d5ea
2 files changed
+18

No files matched your search

+1
View File
@@ -81,6 +81,7 @@ dependencies {
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:design:23.3.0'
compile 'com.github.amlcurran.showcaseview:library:5.4.1'
compile 'com.github.anrwatchdog:anrwatchdog:1.2.0'
compile 'com.github.seven332:unifile:0.1.2'
compile 'com.github.seven332:drawerLayout:0.1.0'
compile 'com.github.seven332:refreshlayout:0.1.0'
@@ -29,6 +29,8 @@ import android.support.annotation.Nullable;
import android.support.v4.util.LruCache;
import android.util.Log;
import com.github.anrwatchdog.ANRError;
import com.github.anrwatchdog.ANRWatchDog;
import com.hippo.beerbelly.SimpleDiskCache;
import com.hippo.conaco.Conaco;
import com.hippo.ehviewer.client.EhClient;
@@ -91,6 +93,15 @@ public class EhApplication extends SceneApplication implements Thread.UncaughtEx
mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(this);
// Start anr watch dog
new ANRWatchDog().setANRListener(new ANRWatchDog.ANRListener() {
@Override
public void onAppNotResponding(ANRError error) {
// Throw RuntimeException, let crash handler do it
throw new RuntimeException(error.getCause());
}
}).start();
super.onCreate();
GetText.initialize(this);
@@ -344,6 +355,12 @@ public class EhApplication extends SceneApplication implements Thread.UncaughtEx
if (!handleException(ex) && mDefaultHandler != null) {
mDefaultHandler.uncaughtException(thread, ex);
}
Activity activity = getTopActivity();
if (activity != null) {
activity.finish();
}
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(1);
}