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;
|
|
|
|
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 22:02:42 +01:00
|
|
|
import android.preference.PreferenceManager;
|
2017-06-28 07:27:32 +02:00
|
|
|
import android.support.annotation.Nullable;
|
|
|
|
import android.support.annotation.StringRes;
|
2016-02-25 22:02:42 +01:00
|
|
|
import android.support.design.widget.Snackbar;
|
|
|
|
import android.support.v4.app.NavUtils;
|
2016-05-25 23:51:22 +02:00
|
|
|
import android.support.v7.app.ActionBar;
|
2017-02-18 21:59:48 +01:00
|
|
|
import android.support.v7.app.AppCompatActivity;
|
2017-04-26 21:32:20 +02:00
|
|
|
import android.support.v7.widget.Toolbar;
|
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;
|
|
|
|
|
2016-09-13 23:24:49 +02:00
|
|
|
import org.acra.ReportField;
|
|
|
|
import org.acra.collector.CrashReportData;
|
2016-02-25 23:19:43 +01:00
|
|
|
import org.json.JSONArray;
|
|
|
|
import org.json.JSONObject;
|
2016-09-13 23:39:32 +02:00
|
|
|
import org.schabi.newpipe.ActivityCommunicator;
|
|
|
|
import org.schabi.newpipe.BuildConfig;
|
|
|
|
import org.schabi.newpipe.Downloader;
|
|
|
|
import org.schabi.newpipe.MainActivity;
|
|
|
|
import org.schabi.newpipe.R;
|
2017-09-03 08:04:18 +02:00
|
|
|
import org.schabi.newpipe.extractor.utils.Parser;
|
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;
|
|
|
|
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;
|
|
|
|
|
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";
|
2016-02-27 15:02:28 +01:00
|
|
|
public static final String ERROR_EMAIL_SUBJECT = "Exception in NewPipe " + BuildConfig.VERSION_NAME;
|
2017-02-27 12:55:15 +01:00
|
|
|
Thread globIpRangeThread;
|
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;
|
|
|
|
private String globIpRange;
|
2016-02-25 22:02:42 +01:00
|
|
|
// views
|
|
|
|
private TextView errorView;
|
2016-02-25 23:19:43 +01:00
|
|
|
private EditText userCommentBox;
|
2016-02-27 15:02:28 +01:00
|
|
|
private Button reportButton;
|
|
|
|
private TextView infoView;
|
2016-02-29 19:23:01 +01:00
|
|
|
private TextView errorMessageView;
|
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) {
|
2017-06-28 07:27:32 +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,
|
2017-06-28 07:27:32 +02:00
|
|
|
final Class returnActivity, View rootView, final ErrorInfo errorInfo) {
|
2016-02-27 15:02:28 +01:00
|
|
|
if (rootView != null) {
|
2017-09-03 08:04:18 +02:00
|
|
|
Snackbar.make(rootView, R.string.error_snackbar_message, 15 * 1000)
|
2016-02-29 21:21:15 +01:00
|
|
|
.setActionTextColor(Color.YELLOW)
|
2016-02-25 22:02:42 +01:00
|
|
|
.setAction(R.string.error_snackbar_action, new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2017-09-03 08:04:18 +02:00
|
|
|
startErrorActivity(returnActivity, context, errorInfo, el);
|
2016-02-25 22:02:42 +01:00
|
|
|
}
|
|
|
|
}).show();
|
|
|
|
} else {
|
2017-09-03 08:04:18 +02:00
|
|
|
startErrorActivity(returnActivity, context, errorInfo, el);
|
2016-02-25 22:02:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-03 08:04:18 +02:00
|
|
|
private static void startErrorActivity(Class returnActivity, Context context, ErrorInfo errorInfo, List<Throwable> el) {
|
|
|
|
ActivityCommunicator ac = ActivityCommunicator.getCommunicator();
|
|
|
|
ac.returnActivity = returnActivity;
|
|
|
|
Intent intent = new Intent(context, ErrorActivity.class);
|
|
|
|
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,
|
2017-06-28 07:27:32 +02:00
|
|
|
final Class returnActivity, 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
|
2016-08-01 01:56:19 +02:00
|
|
|
public static void reportError(Handler handler, final Context context, final Throwable e,
|
2017-06-28 07:27:32 +02:00
|
|
|
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
|
2016-08-01 01:56:19 +02:00
|
|
|
public static void reportError(Handler handler, final Context context, final List<Throwable> el,
|
2017-06-28 07:27:32 +02:00
|
|
|
final Class returnActivity, final View rootView, final ErrorInfo errorInfo) {
|
2016-02-25 22:02:42 +01:00
|
|
|
handler.post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2017-06-28 07:27:32 +02:00
|
|
|
reportError(context, el, returnActivity, rootView, errorInfo);
|
2016-02-25 22:02:42 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-09-13 23:24:49 +02:00
|
|
|
public static void reportError(final Context context, final CrashReportData report, final ErrorInfo errorInfo) {
|
|
|
|
// get key first (don't ask about this solution)
|
|
|
|
ReportField key = null;
|
2017-09-03 08:04:18 +02:00
|
|
|
for (ReportField k : report.keySet()) {
|
|
|
|
if (k.toString().equals("STACK_TRACE")) {
|
2016-09-13 23:24:49 +02:00
|
|
|
key = k;
|
|
|
|
}
|
|
|
|
}
|
2017-11-10 15:36:13 +01:00
|
|
|
String[] el = new String[]{report.get(key).toString()};
|
2016-09-13 23:24:49 +02:00
|
|
|
|
|
|
|
Intent intent = new Intent(context, ErrorActivity.class);
|
|
|
|
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
|
|
|
|
private static String[] elToSl(List<Throwable> stackTraces) {
|
|
|
|
String[] out = new String[stackTraces.size()];
|
|
|
|
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
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
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
|
|
|
|
|
|
|
Intent intent = getIntent();
|
|
|
|
|
2017-09-03 08:04:18 +02:00
|
|
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
2017-04-26 21:32:20 +02:00
|
|
|
setSupportActionBar(toolbar);
|
|
|
|
|
|
|
|
ActionBar actionBar = getSupportActionBar();
|
|
|
|
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
|
|
|
|
2017-09-03 08:04:18 +02:00
|
|
|
reportButton = findViewById(R.id.errorReportButton);
|
|
|
|
userCommentBox = findViewById(R.id.errorCommentBox);
|
|
|
|
errorView = findViewById(R.id.errorView);
|
|
|
|
infoView = findViewById(R.id.errorInfosView);
|
|
|
|
errorMessageView = findViewById(R.id.errorMessageView);
|
2016-02-25 22:02:42 +01:00
|
|
|
|
2016-09-13 22:36:47 +02:00
|
|
|
ActivityCommunicator ac = ActivityCommunicator.getCommunicator();
|
|
|
|
returnActivity = ac.returnActivity;
|
|
|
|
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
|
2016-02-25 22:02:42 +01:00
|
|
|
addGuruMeditaion();
|
2016-02-27 15:02:28 +01:00
|
|
|
currentTimeStamp = getCurrentTimeStamp();
|
2016-02-25 23:19:43 +01:00
|
|
|
|
|
|
|
reportButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
|
|
Intent intent = new Intent(Intent.ACTION_SENDTO);
|
|
|
|
intent.setData(Uri.parse("mailto:" + ERROR_EMAIL_ADDRESS))
|
|
|
|
.putExtra(Intent.EXTRA_SUBJECT, ERROR_EMAIL_SUBJECT)
|
|
|
|
.putExtra(Intent.EXTRA_TEXT, buildJson());
|
|
|
|
|
|
|
|
startActivity(Intent.createChooser(intent, "Send Email"));
|
|
|
|
}
|
|
|
|
});
|
2016-02-27 15:02:28 +01:00
|
|
|
reportButton.setEnabled(false);
|
|
|
|
|
2017-06-28 07:27:32 +02:00
|
|
|
globIpRangeThread = new Thread(new IpRangeRequester());
|
2016-02-27 15:02:28 +01:00
|
|
|
globIpRangeThread.start();
|
2016-02-27 17:02:38 +01: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
|
|
|
|
|
|
|
//print stack trace once again for debugging:
|
2017-09-03 08:04:18 +02:00
|
|
|
for (String e : errorList) {
|
2017-02-12 16:45:01 +01:00
|
|
|
Log.e(TAG, e);
|
|
|
|
}
|
2016-02-25 23:19:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
MenuInflater inflater = getMenuInflater();
|
|
|
|
inflater.inflate(R.menu.error_menu, menu);
|
|
|
|
return true;
|
2016-02-25 22:02:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
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;
|
|
|
|
case R.id.menu_item_share_error: {
|
|
|
|
Intent intent = new Intent();
|
|
|
|
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)));
|
|
|
|
}
|
2016-02-27 15:02:28 +01:00
|
|
|
break;
|
2016-02-25 22:02:42 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-13 22:36:47 +02:00
|
|
|
private String formErrorText(String[] el) {
|
2016-02-25 22:02:42 +01:00
|
|
|
String text = "";
|
2017-09-03 08:04:18 +02:00
|
|
|
if (el != null) {
|
2016-09-13 22:36:47 +02:00
|
|
|
for (String e : el) {
|
2016-03-11 14:56:41 +01:00
|
|
|
text += "-------------------------------------\n"
|
2016-09-13 22:36:47 +02:00
|
|
|
+ e;
|
2016-03-11 14:56:41 +01:00
|
|
|
}
|
2016-02-25 22:02:42 +01:00
|
|
|
}
|
|
|
|
text += "-------------------------------------";
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2017-06-28 07:27:32 +02:00
|
|
|
/**
|
|
|
|
* Get the checked activity.
|
2017-09-03 08:04:18 +02:00
|
|
|
*
|
2017-06-28 07:27:32 +02:00
|
|
|
* @param returnActivity the activity to return to
|
|
|
|
* @return the casted return activity or null
|
|
|
|
*/
|
|
|
|
@Nullable
|
|
|
|
static Class<? extends Activity> getReturnActivity(Class<?> returnActivity) {
|
|
|
|
Class<? extends Activity> checkedReturnActivity = null;
|
2017-09-03 08:04:18 +02:00
|
|
|
if (returnActivity != null) {
|
2017-06-28 07:27:32 +02:00
|
|
|
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() {
|
2017-06-28 07:27:32 +02:00
|
|
|
Class<? extends Activity> checkedReturnActivity = getReturnActivity(returnActivity);
|
|
|
|
if (checkedReturnActivity == null) {
|
2016-02-25 22:02:42 +01:00
|
|
|
super.onBackPressed();
|
|
|
|
} else {
|
2017-06-28 07:27:32 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void buildInfo(ErrorInfo info) {
|
2017-09-03 08:04:18 +02:00
|
|
|
TextView infoLabelView = findViewById(R.id.errorInfoLabelsView);
|
|
|
|
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"));
|
|
|
|
|
2016-02-25 23:19:43 +01:00
|
|
|
text += getUserActionString(info.userAction)
|
2016-02-25 22:02:42 +01:00
|
|
|
+ "\n" + info.request
|
2016-02-25 23:19:43 +01:00
|
|
|
+ "\n" + getContentLangString()
|
2016-02-25 22:02:42 +01:00
|
|
|
+ "\n" + info.serviceName
|
2016-02-27 15:02:28 +01:00
|
|
|
+ "\n" + currentTimeStamp
|
2016-09-13 23:31:06 +02:00
|
|
|
+ "\n" + getPackageName()
|
2016-02-25 22:02:42 +01:00
|
|
|
+ "\n" + BuildConfig.VERSION_NAME
|
2016-02-25 23:19:43 +01:00
|
|
|
+ "\n" + getOsString();
|
2016-02-25 22:02:42 +01:00
|
|
|
|
|
|
|
infoView.setText(text);
|
|
|
|
}
|
|
|
|
|
2016-02-25 23:19:43 +01:00
|
|
|
private String buildJson() {
|
|
|
|
JSONObject errorObject = new JSONObject();
|
|
|
|
|
|
|
|
try {
|
|
|
|
errorObject.put("user_action", getUserActionString(errorInfo.userAction))
|
|
|
|
.put("request", errorInfo.request)
|
|
|
|
.put("content_language", getContentLangString())
|
|
|
|
.put("service", errorInfo.serviceName)
|
2016-09-13 23:31:06 +02:00
|
|
|
.put("package", getPackageName())
|
2016-02-25 23:19:43 +01:00
|
|
|
.put("version", BuildConfig.VERSION_NAME)
|
2016-02-27 15:02:28 +01:00
|
|
|
.put("os", getOsString())
|
|
|
|
.put("time", currentTimeStamp)
|
|
|
|
.put("ip_range", globIpRange);
|
2016-02-25 23:19:43 +01:00
|
|
|
|
|
|
|
JSONArray exceptionArray = new JSONArray();
|
2017-09-03 08:04:18 +02:00
|
|
|
if (errorList != null) {
|
2016-09-13 22:36:47 +02:00
|
|
|
for (String e : errorList) {
|
|
|
|
exceptionArray.put(e);
|
2016-03-11 14:56:41 +01:00
|
|
|
}
|
2016-02-25 23:19:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
errorObject.put("exceptions", exceptionArray);
|
|
|
|
errorObject.put("user_comment", userCommentBox.getText().toString());
|
|
|
|
|
|
|
|
return errorObject.toString(3);
|
2016-08-01 01:56:19 +02:00
|
|
|
} catch (Throwable e) {
|
2016-02-25 23:19:43 +01:00
|
|
|
Log.e(TAG, "Error while erroring: Could not build json");
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2017-06-28 07:27:32 +02:00
|
|
|
private String getUserActionString(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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private String getContentLangString() {
|
|
|
|
return PreferenceManager.getDefaultSharedPreferences(this)
|
|
|
|
.getString(this.getString(R.string.search_language_key), "none");
|
|
|
|
}
|
|
|
|
|
|
|
|
private String getOsString() {
|
|
|
|
String osBase = Build.VERSION.SDK_INT >= 23 ? 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
|
|
|
|
+ " - " + Integer.toString(Build.VERSION.SDK_INT);
|
|
|
|
}
|
|
|
|
|
2016-02-25 22:02:42 +01:00
|
|
|
private void addGuruMeditaion() {
|
|
|
|
//just an easter egg
|
2017-09-03 08:04:18 +02:00
|
|
|
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() {
|
|
|
|
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
|
|
|
df.setTimeZone(TimeZone.getTimeZone("GMT"));
|
|
|
|
return df.format(new Date());
|
|
|
|
}
|
|
|
|
|
2017-02-27 12:55:15 +01:00
|
|
|
public static class ErrorInfo implements Parcelable {
|
|
|
|
public static final Parcelable.Creator<ErrorInfo> CREATOR = new Parcelable.Creator<ErrorInfo>() {
|
|
|
|
@Override
|
|
|
|
public ErrorInfo createFromParcel(Parcel source) {
|
|
|
|
return new ErrorInfo(source);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ErrorInfo[] newArray(int size) {
|
|
|
|
return new ErrorInfo[size];
|
|
|
|
}
|
|
|
|
};
|
2017-06-28 07:27:32 +02:00
|
|
|
final public UserAction userAction;
|
|
|
|
final public String request;
|
|
|
|
final public String serviceName;
|
|
|
|
@StringRes
|
|
|
|
final public int message;
|
|
|
|
|
|
|
|
private ErrorInfo(UserAction userAction, String serviceName, String request, @StringRes int message) {
|
|
|
|
this.userAction = userAction;
|
|
|
|
this.serviceName = serviceName;
|
|
|
|
this.request = request;
|
|
|
|
this.message = message;
|
2017-02-27 12:55:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected ErrorInfo(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();
|
|
|
|
}
|
|
|
|
|
2017-06-28 07:27:32 +02:00
|
|
|
public static ErrorInfo make(UserAction userAction, String serviceName, String request, @StringRes int message) {
|
|
|
|
return new ErrorInfo(userAction, serviceName, request, message);
|
2017-02-27 12:55:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int describeContents() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeToParcel(Parcel dest, 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-28 07:27:32 +02:00
|
|
|
private class IpRangeRequester implements Runnable {
|
2016-02-27 15:02:28 +01:00
|
|
|
Handler h = new Handler();
|
2017-09-03 08:04:18 +02:00
|
|
|
|
2016-02-27 15:02:28 +01:00
|
|
|
public void run() {
|
|
|
|
String ipRange = "none";
|
|
|
|
try {
|
2016-12-07 22:09:24 +01:00
|
|
|
Downloader dl = Downloader.getInstance();
|
2016-12-25 19:30:42 +01:00
|
|
|
String ip = dl.download("https://ipv4.icanhazip.com");
|
2016-02-27 15:02:28 +01:00
|
|
|
|
|
|
|
ipRange = Parser.matchGroup1("([0-9]*\\.[0-9]*\\.)[0-9]*\\.[0-9]*", ip)
|
|
|
|
+ "0.0";
|
2017-09-03 08:04:18 +02:00
|
|
|
} catch (Throwable e) {
|
2017-06-28 07:27:32 +02:00
|
|
|
Log.w(TAG, "Error while error: could not get iprange", e);
|
2016-02-27 15:02:28 +01:00
|
|
|
} finally {
|
2017-06-28 07:27:32 +02:00
|
|
|
h.post(new IpRangeReturnRunnable(ipRange));
|
2016-02-27 15:02:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-28 07:27:32 +02:00
|
|
|
private class IpRangeReturnRunnable implements Runnable {
|
2016-02-27 15:02:28 +01:00
|
|
|
String ipRange;
|
2017-09-03 08:04:18 +02:00
|
|
|
|
2017-06-28 07:27:32 +02:00
|
|
|
public IpRangeReturnRunnable(String ipRange) {
|
2016-02-27 15:02:28 +01:00
|
|
|
this.ipRange = ipRange;
|
|
|
|
}
|
2017-09-03 08:04:18 +02:00
|
|
|
|
2016-02-27 15:02:28 +01:00
|
|
|
public void run() {
|
|
|
|
globIpRange = ipRange;
|
2017-09-03 08:04:18 +02:00
|
|
|
if (infoView != null) {
|
2016-02-27 15:02:28 +01:00
|
|
|
String text = infoView.getText().toString();
|
|
|
|
text += "\n" + globIpRange;
|
|
|
|
infoView.setText(text);
|
|
|
|
reportButton.setEnabled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-02-25 22:02:42 +01:00
|
|
|
}
|