2016-09-13 23:39:32 +02:00
|
|
|
package org.schabi.newpipe.report;
|
2016-02-25 23:19:43 +01:00
|
|
|
|
2016-02-25 22:02:42 +01:00
|
|
|
import android.app.Activity;
|
2018-05-24 17:10:28 +02:00
|
|
|
import android.app.AlertDialog;
|
2016-02-25 22:02:42 +01:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
2016-02-29 21:21:15 +01:00
|
|
|
import android.graphics.Color;
|
2016-02-25 23:19:43 +01:00
|
|
|
import android.net.Uri;
|
2016-02-25 22:02:42 +01:00
|
|
|
import android.os.Build;
|
2017-02-27 12:55:15 +01:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Handler;
|
2016-09-13 22:36:47 +02:00
|
|
|
import android.os.Parcel;
|
|
|
|
import android.os.Parcelable;
|
2016-02-25 23:19:43 +01:00
|
|
|
import android.util.Log;
|
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
2016-02-25 22:02:42 +01:00
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
2016-02-25 23:19:43 +01:00
|
|
|
import android.widget.Button;
|
2016-02-25 22:02:42 +01:00
|
|
|
import android.widget.EditText;
|
|
|
|
import android.widget.TextView;
|
2020-06-28 16:07:17 +02:00
|
|
|
import android.widget.Toast;
|
2016-02-25 22:02:42 +01:00
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.annotation.StringRes;
|
|
|
|
import androidx.appcompat.app.ActionBar;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import androidx.appcompat.widget.Toolbar;
|
|
|
|
import androidx.core.app.NavUtils;
|
|
|
|
|
|
|
|
import com.google.android.material.snackbar.Snackbar;
|
2020-04-20 11:02:45 +02:00
|
|
|
import com.grack.nanojson.JsonWriter;
|
2020-03-31 19:20:15 +02:00
|
|
|
|
2016-09-13 23:24:49 +02:00
|
|
|
import org.acra.ReportField;
|
2020-05-01 18:26:12 +02:00
|
|
|
import org.acra.data.CrashReportData;
|
2016-09-13 23:39:32 +02:00
|
|
|
import org.schabi.newpipe.ActivityCommunicator;
|
|
|
|
import org.schabi.newpipe.BuildConfig;
|
|
|
|
import org.schabi.newpipe.MainActivity;
|
|
|
|
import org.schabi.newpipe.R;
|
2020-06-28 16:07:17 +02:00
|
|
|
import org.schabi.newpipe.util.Localization;
|
|
|
|
import org.schabi.newpipe.util.ShareUtils;
|
2017-02-27 12:55:15 +01:00
|
|
|
import org.schabi.newpipe.util.ThemeHelper;
|
2016-02-25 22:02:42 +01:00
|
|
|
|
2016-03-25 13:55:05 +01:00
|
|
|
import java.io.PrintWriter;
|
|
|
|
import java.io.StringWriter;
|
2016-02-27 15:02:28 +01:00
|
|
|
import java.text.SimpleDateFormat;
|
2020-04-20 11:02:45 +02:00
|
|
|
import java.util.Arrays;
|
2016-02-27 15:02:28 +01:00
|
|
|
import java.util.Date;
|
2016-02-25 22:02:42 +01:00
|
|
|
import java.util.List;
|
2016-02-27 15:02:28 +01:00
|
|
|
import java.util.TimeZone;
|
2016-02-25 22:02:42 +01:00
|
|
|
import java.util.Vector;
|
|
|
|
|
2020-01-28 20:48:42 +01:00
|
|
|
import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage;
|
2020-01-10 15:50:15 +01:00
|
|
|
|
2017-09-03 08:04:18 +02:00
|
|
|
/*
|
2016-02-25 23:19:43 +01:00
|
|
|
* Created by Christian Schabesberger on 24.10.15.
|
2016-09-12 00:33:11 +02:00
|
|
|
*
|
2016-02-25 23:19:43 +01:00
|
|
|
* Copyright (C) Christian Schabesberger 2016 <chris.schabesberger@mailbox.org>
|
|
|
|
* ErrorActivity.java is part of NewPipe.
|
2016-09-12 00:33:11 +02:00
|
|
|
*
|
2016-02-25 23:19:43 +01:00
|
|
|
* NewPipe is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2016-09-12 00:33:11 +02:00
|
|
|
* <
|
2016-02-25 23:19:43 +01:00
|
|
|
* NewPipe is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2016-09-12 00:33:11 +02:00
|
|
|
* <
|
2016-02-25 23:19:43 +01:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2017-02-27 12:55:15 +01:00
|
|
|
public class ErrorActivity extends AppCompatActivity {
|
2016-09-13 22:36:47 +02:00
|
|
|
// LOG TAGS
|
2016-02-25 22:02:42 +01:00
|
|
|
public static final String TAG = ErrorActivity.class.toString();
|
2016-09-13 22:36:47 +02:00
|
|
|
// BUNDLE TAGS
|
|
|
|
public static final String ERROR_INFO = "error_info";
|
|
|
|
public static final String ERROR_LIST = "error_list";
|
2017-06-28 07:27:32 +02:00
|
|
|
|
2016-02-27 15:57:37 +01:00
|
|
|
public static final String ERROR_EMAIL_ADDRESS = "crashreport@newpipe.schabi.org";
|
2020-03-31 19:20:15 +02:00
|
|
|
public static final String ERROR_EMAIL_SUBJECT
|
|
|
|
= "Exception in NewPipe " + BuildConfig.VERSION_NAME;
|
2020-06-28 16:07:17 +02:00
|
|
|
|
|
|
|
public static final String ERROR_GITHUB_ISSUE_URL
|
|
|
|
= "https://github.com/TeamNewPipe/NewPipe/issues";
|
|
|
|
|
2016-09-13 22:36:47 +02:00
|
|
|
private String[] errorList;
|
2016-02-25 22:02:42 +01:00
|
|
|
private ErrorInfo errorInfo;
|
|
|
|
private Class returnActivity;
|
2016-02-27 15:02:28 +01:00
|
|
|
private String currentTimeStamp;
|
2016-02-25 23:19:43 +01:00
|
|
|
private EditText userCommentBox;
|
2016-02-25 22:02:42 +01:00
|
|
|
|
2017-02-18 21:59:48 +01:00
|
|
|
public static void reportUiError(final AppCompatActivity activity, final Throwable el) {
|
2020-03-31 19:20:15 +02:00
|
|
|
reportError(activity, el, activity.getClass(), null, ErrorInfo.make(UserAction.UI_ERROR,
|
|
|
|
"none", "", R.string.app_ui_crash));
|
2017-02-18 21:59:48 +01:00
|
|
|
}
|
|
|
|
|
2016-08-01 01:56:19 +02:00
|
|
|
public static void reportError(final Context context, final List<Throwable> el,
|
2020-03-31 19:20:15 +02:00
|
|
|
final Class returnActivity, final View rootView,
|
|
|
|
final ErrorInfo errorInfo) {
|
2016-02-27 15:02:28 +01:00
|
|
|
if (rootView != null) {
|
2018-05-04 16:21:36 +02:00
|
|
|
Snackbar.make(rootView, R.string.error_snackbar_message, 3 * 1000)
|
2016-02-29 21:21:15 +01:00
|
|
|
.setActionTextColor(Color.YELLOW)
|
2020-02-07 22:22:27 +01:00
|
|
|
.setAction(context.getString(R.string.error_snackbar_action).toUpperCase(), v ->
|
2018-04-01 21:54:00 +02:00
|
|
|
startErrorActivity(returnActivity, context, errorInfo, el)).show();
|
2016-02-25 22:02:42 +01:00
|
|
|
} else {
|
2017-09-03 08:04:18 +02:00
|
|
|
startErrorActivity(returnActivity, context, errorInfo, el);
|
2016-02-25 22:02:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
private static void startErrorActivity(final Class returnActivity, final Context context,
|
|
|
|
final ErrorInfo errorInfo, final List<Throwable> el) {
|
2020-08-16 10:24:58 +02:00
|
|
|
final ActivityCommunicator ac = ActivityCommunicator.getCommunicator();
|
2020-03-31 19:20:15 +02:00
|
|
|
ac.setReturnActivity(returnActivity);
|
2020-08-16 10:24:58 +02:00
|
|
|
final Intent intent = new Intent(context, ErrorActivity.class);
|
2017-09-03 08:04:18 +02:00
|
|
|
intent.putExtra(ERROR_INFO, errorInfo);
|
|
|
|
intent.putExtra(ERROR_LIST, elToSl(el));
|
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
context.startActivity(intent);
|
|
|
|
}
|
|
|
|
|
2016-08-01 01:56:19 +02:00
|
|
|
public static void reportError(final Context context, final Throwable e,
|
2020-03-31 19:20:15 +02:00
|
|
|
final Class returnActivity, final View rootView,
|
|
|
|
final ErrorInfo errorInfo) {
|
2016-08-01 01:56:19 +02:00
|
|
|
List<Throwable> el = null;
|
2017-09-03 08:04:18 +02:00
|
|
|
if (e != null) {
|
2016-03-11 14:56:41 +01:00
|
|
|
el = new Vector<>();
|
|
|
|
el.add(e);
|
|
|
|
}
|
2017-06-28 07:27:32 +02:00
|
|
|
reportError(context, el, returnActivity, rootView, errorInfo);
|
2016-02-25 22:02:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// async call
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void reportError(final Handler handler, final Context context,
|
|
|
|
final Throwable e, final Class returnActivity,
|
|
|
|
final View rootView, final ErrorInfo errorInfo) {
|
2016-03-11 14:56:41 +01:00
|
|
|
|
2016-08-01 01:56:19 +02:00
|
|
|
List<Throwable> el = null;
|
2017-09-03 08:04:18 +02:00
|
|
|
if (e != null) {
|
2016-03-11 14:56:41 +01:00
|
|
|
el = new Vector<>();
|
|
|
|
el.add(e);
|
|
|
|
}
|
2017-06-28 07:27:32 +02:00
|
|
|
reportError(handler, context, el, returnActivity, rootView, errorInfo);
|
2016-02-25 22:02:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// async call
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void reportError(final Handler handler, final Context context,
|
|
|
|
final List<Throwable> el, final Class returnActivity,
|
|
|
|
final View rootView, final ErrorInfo errorInfo) {
|
2018-02-04 17:50:22 +01:00
|
|
|
handler.post(() -> reportError(context, el, returnActivity, rootView, errorInfo));
|
2016-02-25 22:02:42 +01:00
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void reportError(final Context context, final CrashReportData report,
|
|
|
|
final ErrorInfo errorInfo) {
|
2020-11-18 23:52:30 +01:00
|
|
|
final String[] el = {report.getString(ReportField.STACK_TRACE)};
|
2016-09-13 23:24:49 +02:00
|
|
|
|
2020-08-16 10:24:58 +02:00
|
|
|
final Intent intent = new Intent(context, ErrorActivity.class);
|
2016-09-13 23:24:49 +02:00
|
|
|
intent.putExtra(ERROR_INFO, errorInfo);
|
|
|
|
intent.putExtra(ERROR_LIST, el);
|
2017-04-12 08:07:15 +02:00
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
2016-09-13 23:24:49 +02:00
|
|
|
context.startActivity(intent);
|
|
|
|
}
|
|
|
|
|
2017-02-27 12:55:15 +01:00
|
|
|
private static String getStackTrace(final Throwable throwable) {
|
|
|
|
final StringWriter sw = new StringWriter();
|
|
|
|
final PrintWriter pw = new PrintWriter(sw, true);
|
|
|
|
throwable.printStackTrace(pw);
|
|
|
|
return sw.getBuffer().toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
// errorList to StringList
|
2020-03-31 19:20:15 +02:00
|
|
|
private static String[] elToSl(final List<Throwable> stackTraces) {
|
2020-08-16 10:24:58 +02:00
|
|
|
final String[] out = new String[stackTraces.size()];
|
2017-02-27 12:55:15 +01:00
|
|
|
for (int i = 0; i < stackTraces.size(); i++) {
|
|
|
|
out[i] = getStackTrace(stackTraces.get(i));
|
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2016-02-25 22:02:42 +01:00
|
|
|
@Override
|
2020-03-31 19:20:15 +02:00
|
|
|
protected void onCreate(final Bundle savedInstanceState) {
|
2020-01-28 20:48:42 +01:00
|
|
|
assureCorrectAppLanguage(this);
|
2016-02-25 22:02:42 +01:00
|
|
|
super.onCreate(savedInstanceState);
|
2017-04-26 21:32:20 +02:00
|
|
|
ThemeHelper.setTheme(this);
|
2016-02-25 22:02:42 +01:00
|
|
|
setContentView(R.layout.activity_error);
|
2016-09-13 22:36:47 +02:00
|
|
|
|
2020-08-16 10:24:58 +02:00
|
|
|
final Intent intent = getIntent();
|
2016-09-13 22:36:47 +02:00
|
|
|
|
2020-08-16 10:24:58 +02:00
|
|
|
final Toolbar toolbar = findViewById(R.id.toolbar);
|
2017-04-26 21:32:20 +02:00
|
|
|
setSupportActionBar(toolbar);
|
|
|
|
|
2020-08-16 10:24:58 +02:00
|
|
|
final ActionBar actionBar = getSupportActionBar();
|
2017-04-26 21:32:20 +02:00
|
|
|
if (actionBar != null) {
|
2016-05-25 23:51:22 +02:00
|
|
|
actionBar.setDisplayHomeAsUpEnabled(true);
|
|
|
|
actionBar.setTitle(R.string.error_report_title);
|
|
|
|
actionBar.setDisplayShowTitleEnabled(true);
|
|
|
|
}
|
2016-02-25 22:02:42 +01:00
|
|
|
|
2020-06-28 16:07:17 +02:00
|
|
|
final Button reportEmailButton = findViewById(R.id.errorReportEmailButton);
|
|
|
|
final Button copyButton = findViewById(R.id.errorReportCopyButton);
|
|
|
|
final Button reportGithubButton = findViewById(R.id.errorReportGitHubButton);
|
|
|
|
|
2017-09-03 08:04:18 +02:00
|
|
|
userCommentBox = findViewById(R.id.errorCommentBox);
|
2020-08-16 10:24:58 +02:00
|
|
|
final TextView errorView = findViewById(R.id.errorView);
|
|
|
|
final TextView infoView = findViewById(R.id.errorInfosView);
|
|
|
|
final TextView errorMessageView = findViewById(R.id.errorMessageView);
|
2016-02-25 22:02:42 +01:00
|
|
|
|
2020-08-16 10:24:58 +02:00
|
|
|
final ActivityCommunicator ac = ActivityCommunicator.getCommunicator();
|
2020-03-31 19:20:15 +02:00
|
|
|
returnActivity = ac.getReturnActivity();
|
2016-09-13 22:36:47 +02:00
|
|
|
errorInfo = intent.getParcelableExtra(ERROR_INFO);
|
|
|
|
errorList = intent.getStringArrayExtra(ERROR_LIST);
|
2016-02-25 22:02:42 +01:00
|
|
|
|
2017-06-28 07:27:32 +02:00
|
|
|
// important add guru meditation
|
2020-06-28 16:07:17 +02:00
|
|
|
addGuruMeditation();
|
2016-02-27 15:02:28 +01:00
|
|
|
currentTimeStamp = getCurrentTimeStamp();
|
2016-02-25 23:19:43 +01:00
|
|
|
|
2020-11-20 00:54:27 +01:00
|
|
|
reportEmailButton.setOnClickListener(v ->
|
2020-08-27 22:56:41 +02:00
|
|
|
openPrivacyPolicyDialog(this, "EMAIL"));
|
2018-05-24 17:10:28 +02:00
|
|
|
|
2020-11-20 00:54:27 +01:00
|
|
|
copyButton.setOnClickListener(v -> {
|
2020-06-28 16:07:17 +02:00
|
|
|
ShareUtils.copyToClipboard(this, buildMarkdown());
|
|
|
|
Toast.makeText(this, R.string.msg_copied, Toast.LENGTH_SHORT).show();
|
|
|
|
});
|
2016-02-25 23:19:43 +01:00
|
|
|
|
2020-11-20 00:54:27 +01:00
|
|
|
reportGithubButton.setOnClickListener(v ->
|
2020-08-27 22:56:41 +02:00
|
|
|
openPrivacyPolicyDialog(this, "GITHUB"));
|
2016-02-27 15:02:28 +01:00
|
|
|
|
2020-06-28 16:07:17 +02:00
|
|
|
|
2016-09-13 22:36:47 +02:00
|
|
|
// normal bugreport
|
|
|
|
buildInfo(errorInfo);
|
2017-09-03 08:04:18 +02:00
|
|
|
if (errorInfo.message != 0) {
|
2016-02-29 21:13:02 +01:00
|
|
|
errorMessageView.setText(errorInfo.message);
|
|
|
|
} else {
|
|
|
|
errorMessageView.setVisibility(View.GONE);
|
|
|
|
findViewById(R.id.messageWhatHappenedView).setVisibility(View.GONE);
|
|
|
|
}
|
2016-09-13 22:36:47 +02:00
|
|
|
|
|
|
|
errorView.setText(formErrorText(errorList));
|
2017-02-12 16:45:01 +01:00
|
|
|
|
2020-06-28 16:07:17 +02:00
|
|
|
// print stack trace once again for debugging:
|
2020-08-16 10:24:58 +02:00
|
|
|
for (final String e : errorList) {
|
2017-02-12 16:45:01 +01:00
|
|
|
Log.e(TAG, e);
|
|
|
|
}
|
2016-02-25 23:19:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-03-31 19:20:15 +02:00
|
|
|
public boolean onCreateOptionsMenu(final Menu menu) {
|
2020-08-16 10:24:58 +02:00
|
|
|
final MenuInflater inflater = getMenuInflater();
|
2016-02-25 23:19:43 +01:00
|
|
|
inflater.inflate(R.menu.error_menu, menu);
|
|
|
|
return true;
|
2016-02-25 22:02:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-03-31 19:20:15 +02:00
|
|
|
public boolean onOptionsItemSelected(final MenuItem item) {
|
2020-08-16 10:24:58 +02:00
|
|
|
final int id = item.getItemId();
|
2016-02-27 15:02:28 +01:00
|
|
|
switch (id) {
|
2016-02-25 23:19:43 +01:00
|
|
|
case android.R.id.home:
|
|
|
|
goToReturnActivity();
|
|
|
|
break;
|
2020-03-31 19:20:15 +02:00
|
|
|
case R.id.menu_item_share_error:
|
2020-08-16 10:24:58 +02:00
|
|
|
final Intent intent = new Intent();
|
2016-02-25 23:19:43 +01:00
|
|
|
intent.setAction(Intent.ACTION_SEND);
|
|
|
|
intent.putExtra(Intent.EXTRA_TEXT, buildJson());
|
|
|
|
intent.setType("text/plain");
|
|
|
|
startActivity(Intent.createChooser(intent, getString(R.string.share_dialog_title)));
|
2020-03-31 19:20:15 +02:00
|
|
|
break;
|
2016-02-25 22:02:42 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-06-28 16:07:17 +02:00
|
|
|
private void openPrivacyPolicyDialog(final Context context, final String action) {
|
|
|
|
new AlertDialog.Builder(context)
|
|
|
|
.setIcon(android.R.drawable.ic_dialog_alert)
|
|
|
|
.setTitle(R.string.privacy_policy_title)
|
|
|
|
.setMessage(R.string.start_accept_privacy_policy)
|
|
|
|
.setCancelable(false)
|
2020-08-27 22:56:41 +02:00
|
|
|
.setNeutralButton(R.string.read_privacy_policy, (dialog, which) ->
|
|
|
|
ShareUtils.openUrlInBrowser(context,
|
|
|
|
context.getString(R.string.privacy_policy_url)))
|
2020-06-28 16:07:17 +02:00
|
|
|
.setPositiveButton(R.string.accept, (dialog, which) -> {
|
|
|
|
if (action.equals("EMAIL")) { // send on email
|
|
|
|
final Intent i = new Intent(Intent.ACTION_SENDTO)
|
|
|
|
.setData(Uri.parse("mailto:")) // only email apps should handle this
|
|
|
|
.putExtra(Intent.EXTRA_EMAIL, new String[]{ERROR_EMAIL_ADDRESS})
|
|
|
|
.putExtra(Intent.EXTRA_SUBJECT, ERROR_EMAIL_SUBJECT)
|
|
|
|
.putExtra(Intent.EXTRA_TEXT, buildJson());
|
|
|
|
if (i.resolveActivity(getPackageManager()) != null) {
|
|
|
|
startActivity(i);
|
|
|
|
}
|
|
|
|
} else if (action.equals("GITHUB")) { // open the NewPipe issue page on GitHub
|
|
|
|
ShareUtils.openUrlInBrowser(this, ERROR_GITHUB_ISSUE_URL);
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
.setNegativeButton(R.string.decline, (dialog, which) -> {
|
|
|
|
// do nothing
|
|
|
|
})
|
|
|
|
.show();
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
private String formErrorText(final String[] el) {
|
2020-08-16 10:24:58 +02:00
|
|
|
final StringBuilder text = new StringBuilder();
|
2017-09-03 08:04:18 +02:00
|
|
|
if (el != null) {
|
2020-08-16 10:24:58 +02:00
|
|
|
for (final String e : el) {
|
2018-08-28 20:14:26 +02:00
|
|
|
text.append("-------------------------------------\n").append(e);
|
2016-03-11 14:56:41 +01:00
|
|
|
}
|
2016-02-25 22:02:42 +01:00
|
|
|
}
|
2018-08-28 20:14:26 +02:00
|
|
|
text.append("-------------------------------------");
|
|
|
|
return text.toString();
|
2016-02-25 22:02:42 +01:00
|
|
|
}
|
|
|
|
|
2020-04-02 13:51:10 +02:00
|
|
|
/**
|
|
|
|
* Get the checked activity.
|
|
|
|
*
|
|
|
|
* @param returnActivity the activity to return to
|
|
|
|
* @return the casted return activity or null
|
|
|
|
*/
|
|
|
|
@Nullable
|
|
|
|
static Class<? extends Activity> getReturnActivity(final Class<?> returnActivity) {
|
|
|
|
Class<? extends Activity> checkedReturnActivity = null;
|
|
|
|
if (returnActivity != null) {
|
|
|
|
if (Activity.class.isAssignableFrom(returnActivity)) {
|
|
|
|
checkedReturnActivity = returnActivity.asSubclass(Activity.class);
|
|
|
|
} else {
|
|
|
|
checkedReturnActivity = MainActivity.class;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return checkedReturnActivity;
|
|
|
|
}
|
|
|
|
|
2016-02-25 22:02:42 +01:00
|
|
|
private void goToReturnActivity() {
|
2020-08-16 10:24:58 +02:00
|
|
|
final Class<? extends Activity> checkedReturnActivity = getReturnActivity(returnActivity);
|
2017-06-28 07:27:32 +02:00
|
|
|
if (checkedReturnActivity == null) {
|
2016-02-25 22:02:42 +01:00
|
|
|
super.onBackPressed();
|
|
|
|
} else {
|
2020-08-16 10:24:58 +02:00
|
|
|
final Intent intent = new Intent(this, checkedReturnActivity);
|
2016-02-25 22:02:42 +01:00
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
|
|
NavUtils.navigateUpTo(this, intent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
private void buildInfo(final ErrorInfo info) {
|
2020-08-16 10:24:58 +02:00
|
|
|
final TextView infoLabelView = findViewById(R.id.errorInfoLabelsView);
|
|
|
|
final TextView infoView = findViewById(R.id.errorInfosView);
|
2016-02-25 22:02:42 +01:00
|
|
|
String text = "";
|
|
|
|
|
|
|
|
infoLabelView.setText(getString(R.string.info_labels).replace("\\n", "\n"));
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
text += getUserActionString(info.userAction) + "\n"
|
|
|
|
+ info.request + "\n"
|
2020-06-28 16:07:17 +02:00
|
|
|
+ getContentLanguageString() + "\n"
|
|
|
|
+ getContentCountryString() + "\n"
|
|
|
|
+ getAppLanguage() + "\n"
|
2020-03-31 19:20:15 +02:00
|
|
|
+ info.serviceName + "\n"
|
|
|
|
+ currentTimeStamp + "\n"
|
|
|
|
+ getPackageName() + "\n"
|
|
|
|
+ BuildConfig.VERSION_NAME + "\n"
|
|
|
|
+ getOsString();
|
2016-02-25 22:02:42 +01:00
|
|
|
|
|
|
|
infoView.setText(text);
|
|
|
|
}
|
|
|
|
|
2016-02-25 23:19:43 +01:00
|
|
|
private String buildJson() {
|
|
|
|
try {
|
2020-04-20 11:02:45 +02:00
|
|
|
return JsonWriter.string()
|
|
|
|
.object()
|
|
|
|
.value("user_action", getUserActionString(errorInfo.userAction))
|
|
|
|
.value("request", errorInfo.request)
|
2020-06-28 16:07:17 +02:00
|
|
|
.value("content_language", getContentLanguageString())
|
|
|
|
.value("content_country", getContentCountryString())
|
|
|
|
.value("app_language", getAppLanguage())
|
2020-04-20 11:02:45 +02:00
|
|
|
.value("service", errorInfo.serviceName)
|
|
|
|
.value("package", getPackageName())
|
|
|
|
.value("version", BuildConfig.VERSION_NAME)
|
|
|
|
.value("os", getOsString())
|
|
|
|
.value("time", currentTimeStamp)
|
|
|
|
.array("exceptions", Arrays.asList(errorList))
|
|
|
|
.value("user_comment", userCommentBox.getText().toString())
|
|
|
|
.end()
|
|
|
|
.done();
|
2020-08-16 10:24:58 +02:00
|
|
|
} catch (final Throwable e) {
|
2016-02-25 23:19:43 +01:00
|
|
|
Log.e(TAG, "Error while erroring: Could not build json");
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2020-06-28 16:07:17 +02:00
|
|
|
private String buildMarkdown() {
|
|
|
|
try {
|
|
|
|
final StringBuilder htmlErrorReport = new StringBuilder();
|
|
|
|
|
|
|
|
final String userComment = userCommentBox.getText().toString();
|
|
|
|
if (!userComment.isEmpty()) {
|
|
|
|
htmlErrorReport.append(userComment).append("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
// basic error info
|
|
|
|
htmlErrorReport
|
|
|
|
.append("## Exception")
|
|
|
|
.append("\n* __User Action:__ ")
|
|
|
|
.append(getUserActionString(errorInfo.userAction))
|
|
|
|
.append("\n* __Request:__ ").append(errorInfo.request)
|
|
|
|
.append("\n* __Content Country:__ ").append(getContentCountryString())
|
|
|
|
.append("\n* __Content Language:__ ").append(getContentLanguageString())
|
|
|
|
.append("\n* __App Language:__ ").append(getAppLanguage())
|
|
|
|
.append("\n* __Service:__ ").append(errorInfo.serviceName)
|
|
|
|
.append("\n* __Version:__ ").append(BuildConfig.VERSION_NAME)
|
|
|
|
.append("\n* __OS:__ ").append(getOsString()).append("\n");
|
|
|
|
|
|
|
|
|
|
|
|
// Collapse all logs to a single paragraph when there are more than one
|
|
|
|
// to keep the GitHub issue clean.
|
|
|
|
if (errorList.length > 1) {
|
|
|
|
htmlErrorReport
|
|
|
|
.append("<details><summary><b>Exceptions (")
|
|
|
|
.append(errorList.length)
|
|
|
|
.append(")</b></summary><p>\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
// add the logs
|
|
|
|
for (int i = 0; i < errorList.length; i++) {
|
|
|
|
htmlErrorReport.append("<details><summary><b>Crash log ");
|
|
|
|
if (errorList.length > 1) {
|
|
|
|
htmlErrorReport.append(i + 1);
|
|
|
|
}
|
|
|
|
htmlErrorReport.append("</b>")
|
|
|
|
.append("</summary><p>\n")
|
|
|
|
.append("\n```\n").append(errorList[i]).append("\n```\n")
|
|
|
|
.append("</details>\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
// make sure to close everything
|
|
|
|
if (errorList.length > 1) {
|
|
|
|
htmlErrorReport.append("</p></details>\n");
|
|
|
|
}
|
|
|
|
htmlErrorReport.append("<hr>\n");
|
|
|
|
return htmlErrorReport.toString();
|
2020-08-16 10:24:58 +02:00
|
|
|
} catch (final Throwable e) {
|
2020-06-28 16:07:17 +02:00
|
|
|
Log.e(TAG, "Error while erroring: Could not build markdown");
|
|
|
|
e.printStackTrace();
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
private String getUserActionString(final UserAction userAction) {
|
2017-09-03 08:04:18 +02:00
|
|
|
if (userAction == null) {
|
2017-06-28 07:27:32 +02:00
|
|
|
return "Your description is in another castle.";
|
|
|
|
} else {
|
|
|
|
return userAction.getMessage();
|
2016-02-25 23:19:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-28 16:07:17 +02:00
|
|
|
private String getContentCountryString() {
|
|
|
|
return Localization.getPreferredContentCountry(this).getCountryCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
private String getContentLanguageString() {
|
|
|
|
return Localization.getPreferredLocalization(this).getLocalizationCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
private String getAppLanguage() {
|
|
|
|
return Localization.getAppLocale(getApplicationContext()).toString();
|
2016-02-25 23:19:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private String getOsString() {
|
2020-08-27 22:59:29 +02:00
|
|
|
final String osBase = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
|
|
|
|
? Build.VERSION.BASE_OS : "Android";
|
2016-02-27 15:02:28 +01:00
|
|
|
return System.getProperty("os.name")
|
2016-02-25 23:19:43 +01:00
|
|
|
+ " " + (osBase.isEmpty() ? "Android" : osBase)
|
|
|
|
+ " " + Build.VERSION.RELEASE
|
2020-03-31 19:20:15 +02:00
|
|
|
+ " - " + Build.VERSION.SDK_INT;
|
2016-02-25 23:19:43 +01:00
|
|
|
}
|
|
|
|
|
2020-06-28 16:07:17 +02:00
|
|
|
private void addGuruMeditation() {
|
2016-02-25 22:02:42 +01:00
|
|
|
//just an easter egg
|
2020-08-16 10:24:58 +02:00
|
|
|
final TextView sorryView = findViewById(R.id.errorSorryView);
|
2016-02-25 22:02:42 +01:00
|
|
|
String text = sorryView.getText().toString();
|
|
|
|
text += "\n" + getString(R.string.guru_meditation);
|
|
|
|
sorryView.setText(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
|
|
|
//super.onBackPressed();
|
|
|
|
goToReturnActivity();
|
|
|
|
}
|
2016-02-27 15:02:28 +01:00
|
|
|
|
|
|
|
public String getCurrentTimeStamp() {
|
2020-08-16 10:24:58 +02:00
|
|
|
final SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
2016-02-27 15:02:28 +01:00
|
|
|
df.setTimeZone(TimeZone.getTimeZone("GMT"));
|
|
|
|
return df.format(new Date());
|
|
|
|
}
|
|
|
|
|
2017-02-27 12:55:15 +01:00
|
|
|
public static class ErrorInfo implements Parcelable {
|
2020-03-31 19:20:15 +02:00
|
|
|
public static final Parcelable.Creator<ErrorInfo> CREATOR
|
|
|
|
= new Parcelable.Creator<ErrorInfo>() {
|
2017-02-27 12:55:15 +01:00
|
|
|
@Override
|
2020-03-31 19:20:15 +02:00
|
|
|
public ErrorInfo createFromParcel(final Parcel source) {
|
2017-02-27 12:55:15 +01:00
|
|
|
return new ErrorInfo(source);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-03-31 19:20:15 +02:00
|
|
|
public ErrorInfo[] newArray(final int size) {
|
2017-02-27 12:55:15 +01:00
|
|
|
return new ErrorInfo[size];
|
|
|
|
}
|
|
|
|
};
|
2020-03-31 19:20:15 +02:00
|
|
|
|
|
|
|
final UserAction userAction;
|
|
|
|
public final String request;
|
|
|
|
final String serviceName;
|
2017-06-28 07:27:32 +02:00
|
|
|
@StringRes
|
2020-03-31 19:20:15 +02:00
|
|
|
public final int message;
|
2017-06-28 07:27:32 +02:00
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
private ErrorInfo(final UserAction userAction, final String serviceName,
|
|
|
|
final String request, @StringRes final int message) {
|
2017-06-28 07:27:32 +02:00
|
|
|
this.userAction = userAction;
|
|
|
|
this.serviceName = serviceName;
|
|
|
|
this.request = request;
|
|
|
|
this.message = message;
|
2017-02-27 12:55:15 +01:00
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
protected ErrorInfo(final Parcel in) {
|
2017-06-28 07:27:32 +02:00
|
|
|
this.userAction = UserAction.valueOf(in.readString());
|
2017-02-27 12:55:15 +01:00
|
|
|
this.request = in.readString();
|
|
|
|
this.serviceName = in.readString();
|
|
|
|
this.message = in.readInt();
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static ErrorInfo make(final UserAction userAction, final String serviceName,
|
|
|
|
final String request, @StringRes final int message) {
|
2017-06-28 07:27:32 +02:00
|
|
|
return new ErrorInfo(userAction, serviceName, request, message);
|
2017-02-27 12:55:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int describeContents() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-03-31 19:20:15 +02:00
|
|
|
public void writeToParcel(final Parcel dest, final int flags) {
|
2017-06-28 07:27:32 +02:00
|
|
|
dest.writeString(this.userAction.name());
|
2017-02-27 12:55:15 +01:00
|
|
|
dest.writeString(this.request);
|
|
|
|
dest.writeString(this.serviceName);
|
|
|
|
dest.writeInt(this.message);
|
|
|
|
}
|
|
|
|
}
|
2016-02-25 22:02:42 +01:00
|
|
|
}
|