Add app and device info too for crash notification shown when bootstrap installation or setup storage fails

This commit is contained in:
agnostic-apollo
2021-07-08 08:49:32 +05:00
parent 2cf21c8409
commit 56c3826680
2 changed files with 17 additions and 7 deletions

View File

@@ -196,7 +196,7 @@ final class TermuxInstaller {
Logger.logErrorExtended(LOG_TAG, "Bootstrap Error:\n" + message); Logger.logErrorExtended(LOG_TAG, "Bootstrap Error:\n" + message);
// Send a notification with the exception so that the user knows why bootstrap setup failed // Send a notification with the exception so that the user knows why bootstrap setup failed
CrashUtils.sendCrashReportNotification(activity, LOG_TAG, "## Bootstrap Error\n\n" + message, true); CrashUtils.sendCrashReportNotification(activity, LOG_TAG, "## Bootstrap Error\n\n" + message, true, true);
activity.runOnUiThread(() -> { activity.runOnUiThread(() -> {
try { try {
@@ -231,7 +231,7 @@ final class TermuxInstaller {
if (error != null) { if (error != null) {
Logger.logErrorAndShowToast(context, LOG_TAG, error.getMessage()); Logger.logErrorAndShowToast(context, LOG_TAG, error.getMessage());
Logger.logErrorExtended(LOG_TAG, "Setup Storage Error\n" + error.toString()); Logger.logErrorExtended(LOG_TAG, "Setup Storage Error\n" + error.toString());
CrashUtils.sendCrashReportNotification(context, LOG_TAG, "## Setup Storage Error\n\n" + Error.getErrorMarkdownString(error), true); CrashUtils.sendCrashReportNotification(context, LOG_TAG, "## Setup Storage Error\n\n" + Error.getErrorMarkdownString(error), true, true);
return; return;
} }
@@ -270,7 +270,7 @@ final class TermuxInstaller {
} catch (Exception e) { } catch (Exception e) {
Logger.logErrorAndShowToast(context, LOG_TAG, e.getMessage()); Logger.logErrorAndShowToast(context, LOG_TAG, e.getMessage());
Logger.logStackTraceWithMessage(LOG_TAG, "Setup Storage Error: Error setting up link", e); Logger.logStackTraceWithMessage(LOG_TAG, "Setup Storage Error: Error setting up link", e);
CrashUtils.sendCrashReportNotification(context, LOG_TAG, "## Setup Storage Error\n\n" + Logger.getStackTracesMarkdownString(null, Logger.getStackTracesStringArray(e)), true); CrashUtils.sendCrashReportNotification(context, LOG_TAG, "## Setup Storage Error\n\n" + Logger.getStackTracesMarkdownString(null, Logger.getStackTracesStringArray(e)), true, true);
} }
} }
}.start(); }.start();

View File

@@ -20,6 +20,7 @@ import com.termux.shared.settings.preferences.TermuxAppSharedPreferences;
import com.termux.shared.settings.preferences.TermuxPreferenceConstants; import com.termux.shared.settings.preferences.TermuxPreferenceConstants;
import com.termux.shared.data.DataUtils; import com.termux.shared.data.DataUtils;
import com.termux.shared.logger.Logger; import com.termux.shared.logger.Logger;
import com.termux.shared.termux.AndroidUtils;
import com.termux.shared.termux.TermuxUtils; import com.termux.shared.termux.TermuxUtils;
import com.termux.shared.termux.TermuxConstants; import com.termux.shared.termux.TermuxConstants;
@@ -86,7 +87,7 @@ public class CrashUtils {
Logger.logDebug(logTag, "A crash log file found at \"" + TermuxConstants.TERMUX_CRASH_LOG_FILE_PATH + "\"."); Logger.logDebug(logTag, "A crash log file found at \"" + TermuxConstants.TERMUX_CRASH_LOG_FILE_PATH + "\".");
sendCrashReportNotification(context, logTag, reportString, false); sendCrashReportNotification(context, logTag, reportString, false, false);
} }
}.start(); }.start();
} }
@@ -97,13 +98,15 @@ public class CrashUtils {
* *
* @param context The {@link Context} for operations. * @param context The {@link Context} for operations.
* @param logTag The log tag to use for logging. * @param logTag The log tag to use for logging.
* @param reportString The text for the crash report. * @param message The message for the crash report.
* @param forceNotification If set to {@code true}, then a notification will be shown * @param forceNotification If set to {@code true}, then a notification will be shown
* regardless of if pending intent is {@code null} or * regardless of if pending intent is {@code null} or
* {@link TermuxPreferenceConstants.TERMUX_APP#KEY_CRASH_REPORT_NOTIFICATIONS_ENABLED} * {@link TermuxPreferenceConstants.TERMUX_APP#KEY_CRASH_REPORT_NOTIFICATIONS_ENABLED}
* is {@code false}. * is {@code false}.
* @param addAppAndDeviceInfo If set to {@code true}, then app and device info will be appended
* to the message.
*/ */
public static void sendCrashReportNotification(final Context context, String logTag, String reportString, boolean forceNotification) { public static void sendCrashReportNotification(final Context context, String logTag, String message, boolean forceNotification, boolean addAppAndDeviceInfo) {
if (context == null) return; if (context == null) return;
TermuxAppSharedPreferences preferences = TermuxAppSharedPreferences.build(context); TermuxAppSharedPreferences preferences = TermuxAppSharedPreferences.build(context);
@@ -121,7 +124,14 @@ public class CrashUtils {
Logger.logDebug(logTag, "Sending \"" + title + "\" notification."); Logger.logDebug(logTag, "Sending \"" + title + "\" notification.");
Intent notificationIntent = ReportActivity.newInstance(context, new ReportInfo(UserAction.CRASH_REPORT.getName(), logTag, title, null, reportString, "\n\n" + TermuxUtils.getReportIssueMarkdownString(context), true)); StringBuilder reportString = new StringBuilder(message);
if (addAppAndDeviceInfo) {
reportString.append("\n\n").append(TermuxUtils.getAppInfoMarkdownString(context, true));
reportString.append("\n\n").append(AndroidUtils.getDeviceInfoMarkdownString(context));
}
Intent notificationIntent = ReportActivity.newInstance(context, new ReportInfo(UserAction.CRASH_REPORT.getName(), logTag, title, null, reportString.toString(), "\n\n" + TermuxUtils.getReportIssueMarkdownString(context), true));
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
// Setup the notification channel if not already set up // Setup the notification channel if not already set up