Skip to content

Commit

Permalink
Add app and device info too for crash notification shown when bootstr…
Browse files Browse the repository at this point in the history
…ap installation or setup storage fails
  • Loading branch information
agnostic-apollo committed Jul 8, 2021
1 parent 2cf21c8 commit 56c3826
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
6 changes: 3 additions & 3 deletions app/src/main/java/com/termux/app/TermuxInstaller.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public static void showBootstrapErrorDialog(Activity activity, String PREFIX_FIL
Logger.logErrorExtended(LOG_TAG, "Bootstrap Error:\n" + message);

// 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(() -> {
try {
Expand Down Expand Up @@ -231,7 +231,7 @@ public void run() {
if (error != null) {
Logger.logErrorAndShowToast(context, LOG_TAG, error.getMessage());
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;
}

Expand Down Expand Up @@ -270,7 +270,7 @@ public void run() {
} catch (Exception e) {
Logger.logErrorAndShowToast(context, LOG_TAG, e.getMessage());
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();
Expand Down
18 changes: 14 additions & 4 deletions app/src/main/java/com/termux/app/utils/CrashUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.termux.shared.settings.preferences.TermuxPreferenceConstants;
import com.termux.shared.data.DataUtils;
import com.termux.shared.logger.Logger;
import com.termux.shared.termux.AndroidUtils;
import com.termux.shared.termux.TermuxUtils;

import com.termux.shared.termux.TermuxConstants;
Expand Down Expand Up @@ -86,7 +87,7 @@ public void run() {

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();
}
Expand All @@ -97,13 +98,15 @@ public void run() {
*
* @param context The {@link Context} for operations.
* @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
* regardless of if pending intent is {@code null} or
* {@link TermuxPreferenceConstants.TERMUX_APP#KEY_CRASH_REPORT_NOTIFICATIONS_ENABLED}
* 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;

TermuxAppSharedPreferences preferences = TermuxAppSharedPreferences.build(context);
Expand All @@ -121,7 +124,14 @@ public static void sendCrashReportNotification(final Context context, String log

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);

// Setup the notification channel if not already set up
Expand Down

0 comments on commit 56c3826

Please sign in to comment.