2021-03-23 22:22:12 +00:00
|
|
|
package com.termux.app.activities;
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.appcompat.app.ActionBar;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import androidx.appcompat.widget.Toolbar;
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
|
|
|
|
import com.termux.R;
|
2021-04-07 06:31:30 +00:00
|
|
|
import com.termux.shared.termux.TermuxConstants;
|
|
|
|
import com.termux.shared.markdown.MarkdownUtils;
|
|
|
|
import com.termux.shared.interact.ShareUtils;
|
2021-03-27 14:08:26 +00:00
|
|
|
import com.termux.app.models.ReportInfo;
|
2021-03-23 22:22:12 +00:00
|
|
|
|
|
|
|
import org.commonmark.node.FencedCodeBlock;
|
|
|
|
|
|
|
|
import io.noties.markwon.Markwon;
|
|
|
|
import io.noties.markwon.recycler.MarkwonAdapter;
|
|
|
|
import io.noties.markwon.recycler.SimpleEntry;
|
|
|
|
|
|
|
|
public class ReportActivity extends AppCompatActivity {
|
|
|
|
|
2021-03-24 01:33:09 +00:00
|
|
|
private static final String EXTRA_REPORT_INFO = "report_info";
|
2021-03-23 22:22:12 +00:00
|
|
|
|
|
|
|
ReportInfo mReportInfo;
|
Implement crash handler and reporting
Now whenever the Termux app crashes, the crash report (stacktrace, app and device info) will be logged to ~/crash_log.md file. When the user will reopen the app, a notification will be shown which when clicked will show the crash report content in the ReportActivity. The activity will have important links like email, reddit, github issues of termux app and packages at which the user can optionally report an issue if necessary after copying the crash report text. The ~/crash_log.md file will be moved to ~/crash_log-backup.md so that a notification is not shown again on next startup and can be viewed again via SAF, etc.
This will allow reports for bugs that are submitted to have complete and useful info, specially in markdown format, making lives of devs a tad bit easier. Also more bugs that are rare might be submitted since users will have the info to report with and know where to report at.
ToDo:
- The TermuxConstants.TERMUX_SUPPORT_EMAIL_URL needs to be updated with a valid support email once its set up. The TermuxUtils.getReportIssueMarkdownString() function currently also has "email" lines commented out which will need to be uncommented.
- Currently, crashes will only be handled for the main app thread, other threads will have to manually hooked into where necessary.
2021-04-06 11:15:00 +00:00
|
|
|
String mReportMarkdownString;
|
2021-03-28 04:06:17 +00:00
|
|
|
String mReportActivityMarkdownString;
|
2021-03-23 22:22:12 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_report);
|
|
|
|
|
|
|
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
|
|
|
if (toolbar != null) {
|
|
|
|
setSupportActionBar(toolbar);
|
|
|
|
}
|
|
|
|
|
|
|
|
Bundle bundle = null;
|
|
|
|
Intent intent = getIntent();
|
2021-04-06 12:17:12 +00:00
|
|
|
if (intent != null)
|
2021-03-23 22:22:12 +00:00
|
|
|
bundle = intent.getExtras();
|
2021-04-06 12:17:12 +00:00
|
|
|
else if (savedInstanceState != null)
|
2021-03-23 22:22:12 +00:00
|
|
|
bundle = savedInstanceState;
|
|
|
|
|
|
|
|
updateUI(bundle);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onNewIntent(Intent intent) {
|
|
|
|
super.onNewIntent(intent);
|
|
|
|
setIntent(intent);
|
|
|
|
|
2021-04-06 12:17:12 +00:00
|
|
|
if (intent != null)
|
2021-03-23 22:22:12 +00:00
|
|
|
updateUI(intent.getExtras());
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateUI(Bundle bundle) {
|
|
|
|
|
|
|
|
if (bundle == null) {
|
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-24 01:33:09 +00:00
|
|
|
mReportInfo = (ReportInfo) bundle.getSerializable(EXTRA_REPORT_INFO);
|
2021-03-23 22:22:12 +00:00
|
|
|
|
|
|
|
if (mReportInfo == null) {
|
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
final ActionBar actionBar = getSupportActionBar();
|
|
|
|
if (actionBar != null) {
|
|
|
|
if (mReportInfo.reportTitle != null)
|
|
|
|
actionBar.setTitle(mReportInfo.reportTitle);
|
|
|
|
else
|
|
|
|
actionBar.setTitle(TermuxConstants.TERMUX_APP_NAME + " App Report");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RecyclerView recyclerView = findViewById(R.id.recycler_view);
|
|
|
|
|
|
|
|
final Markwon markwon = MarkdownUtils.getRecyclerMarkwonBuilder(this);
|
|
|
|
|
|
|
|
final MarkwonAdapter adapter = MarkwonAdapter.builderTextViewIsRoot(R.layout.activity_report_adapter_node_default)
|
2021-03-25 20:26:53 +00:00
|
|
|
.include(FencedCodeBlock.class, SimpleEntry.create(R.layout.activity_report_adapter_node_code_block, R.id.code_text_view))
|
2021-03-23 22:22:12 +00:00
|
|
|
.build();
|
|
|
|
|
|
|
|
recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
|
|
|
recyclerView.setAdapter(adapter);
|
|
|
|
|
2021-03-28 04:06:17 +00:00
|
|
|
|
|
|
|
generateReportActivityMarkdownString();
|
|
|
|
adapter.setMarkdown(markwon, mReportActivityMarkdownString);
|
2021-03-23 22:22:12 +00:00
|
|
|
adapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSaveInstanceState(@NonNull Bundle outState) {
|
|
|
|
super.onSaveInstanceState(outState);
|
|
|
|
|
2021-03-24 01:33:09 +00:00
|
|
|
outState.putSerializable(EXTRA_REPORT_INFO, mReportInfo);
|
2021-03-23 22:22:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(final Menu menu) {
|
|
|
|
final MenuInflater inflater = getMenuInflater();
|
|
|
|
inflater.inflate(R.menu.menu_report, menu);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
|
|
|
// Remove activity from recents menu on back button press
|
|
|
|
finishAndRemoveTask();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(final MenuItem item) {
|
|
|
|
int id = item.getItemId();
|
|
|
|
if (id == R.id.menu_item_share_report) {
|
Implement crash handler and reporting
Now whenever the Termux app crashes, the crash report (stacktrace, app and device info) will be logged to ~/crash_log.md file. When the user will reopen the app, a notification will be shown which when clicked will show the crash report content in the ReportActivity. The activity will have important links like email, reddit, github issues of termux app and packages at which the user can optionally report an issue if necessary after copying the crash report text. The ~/crash_log.md file will be moved to ~/crash_log-backup.md so that a notification is not shown again on next startup and can be viewed again via SAF, etc.
This will allow reports for bugs that are submitted to have complete and useful info, specially in markdown format, making lives of devs a tad bit easier. Also more bugs that are rare might be submitted since users will have the info to report with and know where to report at.
ToDo:
- The TermuxConstants.TERMUX_SUPPORT_EMAIL_URL needs to be updated with a valid support email once its set up. The TermuxUtils.getReportIssueMarkdownString() function currently also has "email" lines commented out which will need to be uncommented.
- Currently, crashes will only be handled for the main app thread, other threads will have to manually hooked into where necessary.
2021-04-06 11:15:00 +00:00
|
|
|
if (mReportMarkdownString != null)
|
|
|
|
ShareUtils.shareText(this, getString(R.string.title_report_text), mReportMarkdownString);
|
2021-03-23 22:22:12 +00:00
|
|
|
} else if (id == R.id.menu_item_copy_report) {
|
Implement crash handler and reporting
Now whenever the Termux app crashes, the crash report (stacktrace, app and device info) will be logged to ~/crash_log.md file. When the user will reopen the app, a notification will be shown which when clicked will show the crash report content in the ReportActivity. The activity will have important links like email, reddit, github issues of termux app and packages at which the user can optionally report an issue if necessary after copying the crash report text. The ~/crash_log.md file will be moved to ~/crash_log-backup.md so that a notification is not shown again on next startup and can be viewed again via SAF, etc.
This will allow reports for bugs that are submitted to have complete and useful info, specially in markdown format, making lives of devs a tad bit easier. Also more bugs that are rare might be submitted since users will have the info to report with and know where to report at.
ToDo:
- The TermuxConstants.TERMUX_SUPPORT_EMAIL_URL needs to be updated with a valid support email once its set up. The TermuxUtils.getReportIssueMarkdownString() function currently also has "email" lines commented out which will need to be uncommented.
- Currently, crashes will only be handled for the main app thread, other threads will have to manually hooked into where necessary.
2021-04-06 11:15:00 +00:00
|
|
|
if (mReportMarkdownString != null)
|
|
|
|
ShareUtils.copyTextToClipboard(this, mReportMarkdownString, null);
|
2021-03-23 22:22:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-03-28 04:06:17 +00:00
|
|
|
* Generate the markdown {@link String} to be shown in {@link ReportActivity}.
|
2021-03-23 22:22:12 +00:00
|
|
|
*/
|
2021-03-28 04:06:17 +00:00
|
|
|
private void generateReportActivityMarkdownString() {
|
Implement crash handler and reporting
Now whenever the Termux app crashes, the crash report (stacktrace, app and device info) will be logged to ~/crash_log.md file. When the user will reopen the app, a notification will be shown which when clicked will show the crash report content in the ReportActivity. The activity will have important links like email, reddit, github issues of termux app and packages at which the user can optionally report an issue if necessary after copying the crash report text. The ~/crash_log.md file will be moved to ~/crash_log-backup.md so that a notification is not shown again on next startup and can be viewed again via SAF, etc.
This will allow reports for bugs that are submitted to have complete and useful info, specially in markdown format, making lives of devs a tad bit easier. Also more bugs that are rare might be submitted since users will have the info to report with and know where to report at.
ToDo:
- The TermuxConstants.TERMUX_SUPPORT_EMAIL_URL needs to be updated with a valid support email once its set up. The TermuxUtils.getReportIssueMarkdownString() function currently also has "email" lines commented out which will need to be uncommented.
- Currently, crashes will only be handled for the main app thread, other threads will have to manually hooked into where necessary.
2021-04-06 11:15:00 +00:00
|
|
|
mReportMarkdownString = ReportInfo.getReportInfoMarkdownString(mReportInfo);
|
|
|
|
|
|
|
|
mReportActivityMarkdownString = "";
|
2021-04-06 12:17:12 +00:00
|
|
|
if (mReportInfo.reportStringPrefix != null)
|
Implement crash handler and reporting
Now whenever the Termux app crashes, the crash report (stacktrace, app and device info) will be logged to ~/crash_log.md file. When the user will reopen the app, a notification will be shown which when clicked will show the crash report content in the ReportActivity. The activity will have important links like email, reddit, github issues of termux app and packages at which the user can optionally report an issue if necessary after copying the crash report text. The ~/crash_log.md file will be moved to ~/crash_log-backup.md so that a notification is not shown again on next startup and can be viewed again via SAF, etc.
This will allow reports for bugs that are submitted to have complete and useful info, specially in markdown format, making lives of devs a tad bit easier. Also more bugs that are rare might be submitted since users will have the info to report with and know where to report at.
ToDo:
- The TermuxConstants.TERMUX_SUPPORT_EMAIL_URL needs to be updated with a valid support email once its set up. The TermuxUtils.getReportIssueMarkdownString() function currently also has "email" lines commented out which will need to be uncommented.
- Currently, crashes will only be handled for the main app thread, other threads will have to manually hooked into where necessary.
2021-04-06 11:15:00 +00:00
|
|
|
mReportActivityMarkdownString += mReportInfo.reportStringPrefix;
|
|
|
|
|
|
|
|
mReportActivityMarkdownString += mReportMarkdownString;
|
|
|
|
|
2021-04-06 12:17:12 +00:00
|
|
|
if (mReportInfo.reportStringSuffix != null)
|
Implement crash handler and reporting
Now whenever the Termux app crashes, the crash report (stacktrace, app and device info) will be logged to ~/crash_log.md file. When the user will reopen the app, a notification will be shown which when clicked will show the crash report content in the ReportActivity. The activity will have important links like email, reddit, github issues of termux app and packages at which the user can optionally report an issue if necessary after copying the crash report text. The ~/crash_log.md file will be moved to ~/crash_log-backup.md so that a notification is not shown again on next startup and can be viewed again via SAF, etc.
This will allow reports for bugs that are submitted to have complete and useful info, specially in markdown format, making lives of devs a tad bit easier. Also more bugs that are rare might be submitted since users will have the info to report with and know where to report at.
ToDo:
- The TermuxConstants.TERMUX_SUPPORT_EMAIL_URL needs to be updated with a valid support email once its set up. The TermuxUtils.getReportIssueMarkdownString() function currently also has "email" lines commented out which will need to be uncommented.
- Currently, crashes will only be handled for the main app thread, other threads will have to manually hooked into where necessary.
2021-04-06 11:15:00 +00:00
|
|
|
mReportActivityMarkdownString += mReportInfo.reportStringSuffix;
|
2021-03-23 22:22:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void startReportActivity(@NonNull final Context context, @NonNull final ReportInfo reportInfo) {
|
|
|
|
context.startActivity(newInstance(context, reportInfo));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Intent newInstance(@NonNull final Context context, @NonNull final ReportInfo reportInfo) {
|
|
|
|
Intent intent = new Intent(context, ReportActivity.class);
|
|
|
|
Bundle bundle = new Bundle();
|
2021-03-24 01:33:09 +00:00
|
|
|
bundle.putSerializable(EXTRA_REPORT_INFO, reportInfo);
|
2021-03-23 22:22:12 +00:00
|
|
|
intent.putExtras(bundle);
|
|
|
|
|
|
|
|
// Note that ReportActivity task has documentLaunchMode="intoExisting" set in AndroidManifest.xml
|
|
|
|
// which has equivalent behaviour to the following. The following dynamic way doesn't seem to
|
|
|
|
// work for notification pending intent, i.e separate task isn't created and activity is
|
|
|
|
// launched in the same task as TermuxActivity.
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
|
|
|
|
return intent;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|