mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2026-04-05 15:36:02 +00:00
Improve decoder crash reporting reliability
This commit is contained in:
@@ -13,18 +13,18 @@ public class Dialog implements Runnable {
|
||||
private final String title;
|
||||
private final String message;
|
||||
private final Activity activity;
|
||||
private final boolean endAfterDismiss;
|
||||
private final Runnable runOnDismiss;
|
||||
|
||||
private AlertDialog alert;
|
||||
|
||||
private static final ArrayList<Dialog> rundownDialogs = new ArrayList<>();
|
||||
|
||||
private Dialog(Activity activity, String title, String message, boolean endAfterDismiss)
|
||||
private Dialog(Activity activity, String title, String message, Runnable runOnDismiss)
|
||||
{
|
||||
this.activity = activity;
|
||||
this.title = title;
|
||||
this.message = message;
|
||||
this.endAfterDismiss = endAfterDismiss;
|
||||
this.runOnDismiss = runOnDismiss;
|
||||
}
|
||||
|
||||
public static void closeDialogs()
|
||||
@@ -40,9 +40,21 @@ public class Dialog implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
public static void displayDialog(Activity activity, String title, String message, boolean endAfterDismiss)
|
||||
public static void displayDialog(final Activity activity, String title, String message, final boolean endAfterDismiss)
|
||||
{
|
||||
activity.runOnUiThread(new Dialog(activity, title, message, endAfterDismiss));
|
||||
activity.runOnUiThread(new Dialog(activity, title, message, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (endAfterDismiss) {
|
||||
activity.finish();
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public static void displayDialog(Activity activity, String title, String message, Runnable runOnDismiss)
|
||||
{
|
||||
activity.runOnUiThread(new Dialog(activity, title, message, runOnDismiss));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -65,9 +77,7 @@ public class Dialog implements Runnable {
|
||||
alert.dismiss();
|
||||
}
|
||||
|
||||
if (endAfterDismiss) {
|
||||
activity.finish();
|
||||
}
|
||||
runOnDismiss.run();
|
||||
}
|
||||
});
|
||||
alert.setButton(AlertDialog.BUTTON_NEUTRAL, activity.getResources().getText(R.string.help), new DialogInterface.OnClickListener() {
|
||||
@@ -77,9 +87,7 @@ public class Dialog implements Runnable {
|
||||
alert.dismiss();
|
||||
}
|
||||
|
||||
if (endAfterDismiss) {
|
||||
activity.finish();
|
||||
}
|
||||
runOnDismiss.run();
|
||||
|
||||
HelpLauncher.launchTroubleshooting(activity);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.app.AlertDialog;
|
||||
import android.app.UiModeManager;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.view.View;
|
||||
|
||||
@@ -58,6 +59,44 @@ public class UiHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public static void showDecoderCrashDialog(Activity activity) {
|
||||
final SharedPreferences prefs = activity.getSharedPreferences("DecoderTombstone", 0);
|
||||
final int crashCount = prefs.getInt("CrashCount", 0);
|
||||
int lastNotifiedCrashCount = prefs.getInt("LastNotifiedCrashCount", 0);
|
||||
|
||||
// Remember the last crash count we notified at, so we don't
|
||||
// display the crash dialog every time the app is started until
|
||||
// they stream again
|
||||
if (crashCount != 0 && crashCount != lastNotifiedCrashCount) {
|
||||
if (crashCount % 3 == 0) {
|
||||
// At 3 consecutive crashes, we'll forcefully reset their settings
|
||||
PreferenceConfiguration.resetStreamingSettings(activity);
|
||||
Dialog.displayDialog(activity,
|
||||
activity.getResources().getString(R.string.title_decoding_reset),
|
||||
activity.getResources().getString(R.string.message_decoding_reset),
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Mark notification as acknowledged on dismissal
|
||||
prefs.edit().putInt("LastNotifiedCrashCount", crashCount).apply();
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
Dialog.displayDialog(activity,
|
||||
activity.getResources().getString(R.string.title_decoding_error),
|
||||
activity.getResources().getString(R.string.message_decoding_error),
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Mark notification as acknowledged on dismissal
|
||||
prefs.edit().putInt("LastNotifiedCrashCount", crashCount).apply();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void displayQuitConfirmationDialog(Activity parent, final Runnable onYes, final Runnable onNo) {
|
||||
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user