mirror of
https://github.com/whyorean/AuroraStore.git
synced 2026-06-20 13:39:36 -04:00
Fixed crash reporter - it was hanging after dismissing the dialog
This commit is contained in:
@@ -139,6 +139,7 @@
|
||||
<activity android:name=".AboutActivity" android:launchMode="singleInstance" android:configChanges="keyboardHidden|orientation|screenSize" >
|
||||
<meta-data android:name="android.app.default_searchable" android:value=".SearchResultActivity" />
|
||||
</activity>
|
||||
<activity android:name=".CrashLetterActivity" android:process=":report_process" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
||||
@@ -29,7 +29,10 @@ public class AboutActivity extends YalpStoreActivity {
|
||||
findViewById(R.id.developer_email).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
new YalpStoreUncaughtExceptionHandler(AboutActivity.this).send(null);
|
||||
CrashLetterActivity.send(
|
||||
AboutActivity.this,
|
||||
new CrashLetterBuilder(AboutActivity.this).build(null)
|
||||
);
|
||||
}
|
||||
});
|
||||
if (hasPermission()) {
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.github.yeriomin.yalpstore;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.text.ClipboardManager;
|
||||
|
||||
public class CrashLetterActivity extends Activity {
|
||||
|
||||
static public void send(Context activity, String letter) {
|
||||
Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
|
||||
emailIntent.setData(Uri.fromParts("mailto", activity.getString(R.string.about_developer_email), null));
|
||||
emailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
emailIntent.putExtra(Intent.EXTRA_SUBJECT, activity.getPackageName() + " Crash Report");
|
||||
emailIntent.putExtra(Intent.EXTRA_TEXT, letter);
|
||||
if (emailIntent.resolveActivity(activity.getPackageManager()) != null) {
|
||||
activity.startActivity(emailIntent);
|
||||
} else {
|
||||
((ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE)).setText(letter);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
showCrashDialog();
|
||||
}
|
||||
|
||||
private AlertDialog showCrashDialog() {
|
||||
return new AlertDialog.Builder(this)
|
||||
.setTitle(getString(R.string.dialog_title_application_crashed))
|
||||
.setMessage(getString(R.string.dialog_message_application_crashed))
|
||||
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
finish();
|
||||
}
|
||||
})
|
||||
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
send(
|
||||
CrashLetterActivity.this,
|
||||
getIntent().getExtras().getString(YalpStoreUncaughtExceptionHandler.INTENT_MESSAGE)
|
||||
);
|
||||
dialog.dismiss();
|
||||
finish();
|
||||
}
|
||||
})
|
||||
.show()
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,12 @@
|
||||
package com.github.yeriomin.yalpstore;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Looper;
|
||||
import android.text.ClipboardManager;
|
||||
import android.util.Log;
|
||||
|
||||
class YalpStoreUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
|
||||
|
||||
static public final String INTENT_MESSAGE = "INTENT_MESSAGE";
|
||||
|
||||
private Activity activity;
|
||||
|
||||
public YalpStoreUncaughtExceptionHandler(Activity activity) {
|
||||
@@ -21,56 +16,11 @@ class YalpStoreUncaughtExceptionHandler implements Thread.UncaughtExceptionHandl
|
||||
@Override
|
||||
public void uncaughtException(Thread t, final Throwable e) {
|
||||
e.printStackTrace();
|
||||
Thread thread = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
Looper.prepare();
|
||||
showCrashDialog(e);
|
||||
Looper.loop();
|
||||
}
|
||||
};
|
||||
try {
|
||||
thread.start();
|
||||
} catch (Throwable ee) {
|
||||
Log.e(getClass().getName(), "Failed to process an uncaught exception: " + ee.getMessage());
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public AlertDialog showCrashDialog(final Throwable e) {
|
||||
return new AlertDialog.Builder(activity)
|
||||
.setTitle(activity.getString(R.string.dialog_title_application_crashed))
|
||||
.setMessage(activity.getString(R.string.dialog_message_application_crashed))
|
||||
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
System.exit(1);
|
||||
}
|
||||
})
|
||||
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
send(e);
|
||||
dialog.dismiss();
|
||||
System.exit(1);
|
||||
}
|
||||
})
|
||||
.show()
|
||||
;
|
||||
}
|
||||
|
||||
public void send(Throwable e) {
|
||||
String letter = new CrashLetterBuilder(activity).build(e);
|
||||
Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
|
||||
emailIntent.setData(Uri.fromParts("mailto", activity.getString(R.string.about_developer_email), null));
|
||||
emailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
emailIntent.putExtra(Intent.EXTRA_SUBJECT, activity.getPackageName() + " Crash Report");
|
||||
emailIntent.putExtra(Intent.EXTRA_TEXT, letter);
|
||||
if (emailIntent.resolveActivity(activity.getPackageManager()) != null) {
|
||||
activity.startActivity(emailIntent);
|
||||
} else {
|
||||
((ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE)).setText(letter);
|
||||
}
|
||||
Intent errorIntent = new Intent(activity.getApplicationContext(), CrashLetterActivity.class);
|
||||
errorIntent.putExtra(INTENT_MESSAGE, new CrashLetterBuilder(activity).build(e));
|
||||
errorIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
activity.getApplicationContext().startActivity(errorIntent);
|
||||
android.os.Process.killProcess(android.os.Process.myPid());
|
||||
System.exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user