Skip to content

Commit 56c3826

Browse files
Add app and device info too for crash notification shown when bootstrap installation or setup storage fails
1 parent 2cf21c8 commit 56c3826

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

app/src/main/java/com/termux/app/TermuxInstaller.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public static void showBootstrapErrorDialog(Activity activity, String PREFIX_FIL
196196
Logger.logErrorExtended(LOG_TAG, "Bootstrap Error:\n" + message);
197197

198198
// Send a notification with the exception so that the user knows why bootstrap setup failed
199-
CrashUtils.sendCrashReportNotification(activity, LOG_TAG, "## Bootstrap Error\n\n" + message, true);
199+
CrashUtils.sendCrashReportNotification(activity, LOG_TAG, "## Bootstrap Error\n\n" + message, true, true);
200200

201201
activity.runOnUiThread(() -> {
202202
try {
@@ -231,7 +231,7 @@ public void run() {
231231
if (error != null) {
232232
Logger.logErrorAndShowToast(context, LOG_TAG, error.getMessage());
233233
Logger.logErrorExtended(LOG_TAG, "Setup Storage Error\n" + error.toString());
234-
CrashUtils.sendCrashReportNotification(context, LOG_TAG, "## Setup Storage Error\n\n" + Error.getErrorMarkdownString(error), true);
234+
CrashUtils.sendCrashReportNotification(context, LOG_TAG, "## Setup Storage Error\n\n" + Error.getErrorMarkdownString(error), true, true);
235235
return;
236236
}
237237

@@ -270,7 +270,7 @@ public void run() {
270270
} catch (Exception e) {
271271
Logger.logErrorAndShowToast(context, LOG_TAG, e.getMessage());
272272
Logger.logStackTraceWithMessage(LOG_TAG, "Setup Storage Error: Error setting up link", e);
273-
CrashUtils.sendCrashReportNotification(context, LOG_TAG, "## Setup Storage Error\n\n" + Logger.getStackTracesMarkdownString(null, Logger.getStackTracesStringArray(e)), true);
273+
CrashUtils.sendCrashReportNotification(context, LOG_TAG, "## Setup Storage Error\n\n" + Logger.getStackTracesMarkdownString(null, Logger.getStackTracesStringArray(e)), true, true);
274274
}
275275
}
276276
}.start();

app/src/main/java/com/termux/app/utils/CrashUtils.java

+14-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.termux.shared.settings.preferences.TermuxPreferenceConstants;
2121
import com.termux.shared.data.DataUtils;
2222
import com.termux.shared.logger.Logger;
23+
import com.termux.shared.termux.AndroidUtils;
2324
import com.termux.shared.termux.TermuxUtils;
2425

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

8788
Logger.logDebug(logTag, "A crash log file found at \"" + TermuxConstants.TERMUX_CRASH_LOG_FILE_PATH + "\".");
8889

89-
sendCrashReportNotification(context, logTag, reportString, false);
90+
sendCrashReportNotification(context, logTag, reportString, false, false);
9091
}
9192
}.start();
9293
}
@@ -97,13 +98,15 @@ public void run() {
9798
*
9899
* @param context The {@link Context} for operations.
99100
* @param logTag The log tag to use for logging.
100-
* @param reportString The text for the crash report.
101+
* @param message The message for the crash report.
101102
* @param forceNotification If set to {@code true}, then a notification will be shown
102103
* regardless of if pending intent is {@code null} or
103104
* {@link TermuxPreferenceConstants.TERMUX_APP#KEY_CRASH_REPORT_NOTIFICATIONS_ENABLED}
104105
* is {@code false}.
106+
* @param addAppAndDeviceInfo If set to {@code true}, then app and device info will be appended
107+
* to the message.
105108
*/
106-
public static void sendCrashReportNotification(final Context context, String logTag, String reportString, boolean forceNotification) {
109+
public static void sendCrashReportNotification(final Context context, String logTag, String message, boolean forceNotification, boolean addAppAndDeviceInfo) {
107110
if (context == null) return;
108111

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

122125
Logger.logDebug(logTag, "Sending \"" + title + "\" notification.");
123126

124-
Intent notificationIntent = ReportActivity.newInstance(context, new ReportInfo(UserAction.CRASH_REPORT.getName(), logTag, title, null, reportString, "\n\n" + TermuxUtils.getReportIssueMarkdownString(context), true));
127+
StringBuilder reportString = new StringBuilder(message);
128+
129+
if (addAppAndDeviceInfo) {
130+
reportString.append("\n\n").append(TermuxUtils.getAppInfoMarkdownString(context, true));
131+
reportString.append("\n\n").append(AndroidUtils.getDeviceInfoMarkdownString(context));
132+
}
133+
134+
Intent notificationIntent = ReportActivity.newInstance(context, new ReportInfo(UserAction.CRASH_REPORT.getName(), logTag, title, null, reportString.toString(), "\n\n" + TermuxUtils.getReportIssueMarkdownString(context), true));
125135
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
126136

127137
// Setup the notification channel if not already set up

0 commit comments

Comments
 (0)