use intent system to pass errors to error activity

This commit is contained in:
Christian Schabesberger 2016-09-13 22:36:47 +02:00
parent a2effef346
commit 14eaedd73a
7 changed files with 149 additions and 26 deletions

View File

@ -32,10 +32,10 @@ android {
dependencies {
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.android.support:support-v4:24.2.0'
compile 'com.android.support:design:24.2.0'
compile 'com.android.support:recyclerview-v7:24.2.0'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:support-v4:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.android.support:recyclerview-v7:24.2.1'
compile 'org.jsoup:jsoup:1.8.3'
compile 'org.mozilla:rhino:1.7.7'
compile 'info.guardianproject.netcipher:netcipher:1.2'
@ -46,4 +46,5 @@ dependencies {
compile 'com.google.code.gson:gson:2.4'
compile 'com.nononsenseapps:filepicker:3.0.0'
testCompile 'junit:junit:4.12'
compile 'ch.acra:acra:4.9.0'
}

View File

@ -0,0 +1,26 @@
package org.schabi.newpipe;
import android.content.Context;
import android.util.Log;
import org.acra.collector.CrashReportData;
import org.acra.sender.ReportSender;
import org.acra.sender.ReportSenderException;
/**
* Created by the-scrabi on 13.09.16.
*/
public class AcraReportSender implements ReportSender {
@Override
public void send(Context context, CrashReportData report) throws ReportSenderException {
Log.e("Newpipe UI ERROR", report.toString());
try {
((String)null).length();
} catch(Exception e) {
ErrorActivity.reportError(context, e, null, null,
ErrorActivity.ErrorInfo.make(ErrorActivity.SEARCHED,"none",
"App crash, UI failure", R.string.app_ui_crash));
}
}
}

View File

@ -0,0 +1,16 @@
package org.schabi.newpipe;
import android.content.Context;
import org.acra.config.ACRAConfiguration;
import org.acra.sender.ReportSender;
import org.acra.sender.ReportSenderFactory;
/**
* Created by the-scrabi on 13.09.16.
*/
public class AcraReportSenderFactory implements ReportSenderFactory {
public ReportSender create(Context context, ACRAConfiguration config) {
return new AcraReportSender();
}
}

View File

@ -42,8 +42,5 @@ public class ActivityCommunicator {
// Thumbnail send from VideoItemDetailFragment to BackgroundPlayer
public volatile Bitmap backgroundPlayerThumbnail;
// Sent from any activity to ErrorActivity.
public volatile List<Throwable> errorList;
public volatile Class returnActivity;
public volatile ErrorActivity.ErrorInfo errorInfo;
}

View File

@ -2,10 +2,17 @@ package org.schabi.newpipe;
import android.app.Application;
import android.content.Context;
import android.util.Log;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import org.acra.ACRA;
import org.acra.config.ACRAConfiguration;
import org.acra.config.ACRAConfigurationException;
import org.acra.config.ConfigurationBuilder;
import org.acra.sender.ReportSenderFactory;
import org.schabi.newpipe.extractor.ServiceList;
import org.schabi.newpipe.settings.SettingsActivity;
import info.guardianproject.netcipher.NetCipher;
@ -30,12 +37,28 @@ import info.guardianproject.netcipher.proxy.OrbotHelper;
*/
public class App extends Application {
private static final String TAG = App.class.toString();
private static boolean useTor;
final Class<? extends ReportSenderFactory>[] reportSenderFactoryClasses
= new Class[]{AcraReportSenderFactory.class};
@Override
public void onCreate() {
super.onCreate();
// init crashreport
try {
final ACRAConfiguration acraConfig = new ConfigurationBuilder(this)
.setReportSenderFactoryClasses(reportSenderFactoryClasses)
.build();
ACRA.init(this, acraConfig);
} catch(ACRAConfigurationException ace) {
ace.printStackTrace();
ErrorActivity.reportError(this, ace, null, null,
ErrorActivity.ErrorInfo.make(ErrorActivity.SEARCHED,"none",
"Could not initialize ACRA crash report", R.string.app_ui_crash));
}
// Initialize image loader
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this).build();

View File

@ -8,6 +8,8 @@ import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;
import android.preference.PreferenceManager;
import android.support.design.widget.Snackbar;
import android.support.v4.app.NavUtils;
@ -57,7 +59,7 @@ import java.util.Vector;
*/
public class ErrorActivity extends AppCompatActivity {
public static class ErrorInfo {
public static class ErrorInfo implements Parcelable {
public int userAction;
public String request;
public String serviceName;
@ -71,15 +73,59 @@ public class ErrorActivity extends AppCompatActivity {
info.message = message;
return info;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(this.userAction);
dest.writeString(this.request);
dest.writeString(this.serviceName);
dest.writeInt(this.message);
}
public ErrorInfo() {
}
protected ErrorInfo(Parcel in) {
this.userAction = in.readInt();
this.request = in.readString();
this.serviceName = in.readString();
this.message = in.readInt();
}
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];
}
};
}
// LOG TAGS
public static final String TAG = ErrorActivity.class.toString();
// BUNDLE TAGS
public static final String ERROR_INFO = "error_info";
public static final String ERROR_LIST = "error_list";
// MESSAGE ID
public static final int SEARCHED = 0;
public static final int REQUESTED_STREAM = 1;
public static final int GET_SUGGESTIONS = 2;
public static final int SOMETHING_ELSE = 3;
public static final int USER_REPORT = 4;
public static final int LOAD_IMAGE = 5;
// MESSAGE STRING
public static final String SEARCHED_STRING = "searched";
public static final String REQUESTED_STREAM_STRING = "requested stream";
public static final String GET_SUGGESTIONS_STRING = "get suggestions";
@ -91,7 +137,7 @@ public class ErrorActivity extends AppCompatActivity {
public static final String ERROR_EMAIL_ADDRESS = "crashreport@newpipe.schabi.org";
public static final String ERROR_EMAIL_SUBJECT = "Exception in NewPipe " + BuildConfig.VERSION_NAME;
private List<Throwable> errorList;
private String[] errorList;
private ErrorInfo errorInfo;
private Class returnActivity;
private String currentTimeStamp;
@ -115,19 +161,19 @@ public class ErrorActivity extends AppCompatActivity {
@Override
public void onClick(View v) {
ActivityCommunicator ac = ActivityCommunicator.getCommunicator();
ac.errorList = el;
ac.returnActivity = returnAcitivty;
ac.errorInfo = errorInfo;
Intent intent = new Intent(context, ErrorActivity.class);
intent.putExtra(ERROR_INFO, errorInfo);
intent.putExtra(ERROR_LIST, elToSl(el));
context.startActivity(intent);
}
}).show();
} else {
ActivityCommunicator ac = ActivityCommunicator.getCommunicator();
ac.errorList = el;
ac.returnActivity = returnAcitivty;
ac.errorInfo = errorInfo;
Intent intent = new Intent(context, ErrorActivity.class);
intent.putExtra(ERROR_INFO, errorInfo);
intent.putExtra(ERROR_LIST, elToSl(el));
context.startActivity(intent);
}
}
@ -169,6 +215,9 @@ public class ErrorActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_error);
Intent intent = getIntent();
try {
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
@ -179,23 +228,20 @@ public class ErrorActivity extends AppCompatActivity {
e.printStackTrace();
}
ActivityCommunicator ac = ActivityCommunicator.getCommunicator();
errorList = ac.errorList;
returnActivity = ac.returnActivity;
errorInfo = ac.errorInfo;
reportButton = (Button) findViewById(R.id.errorReportButton);
userCommentBox = (EditText) findViewById(R.id.errorCommentBox);
errorView = (TextView) findViewById(R.id.errorView);
infoView = (TextView) findViewById(R.id.errorInfosView);
errorMessageView = (TextView) findViewById(R.id.errorMessageView);
errorView.setText(formErrorText(errorList));
ActivityCommunicator ac = ActivityCommunicator.getCommunicator();
returnActivity = ac.returnActivity;
errorInfo = intent.getParcelableExtra(ERROR_INFO);
errorList = intent.getStringArrayExtra(ERROR_LIST);
//importand add gurumeditaion
//importand add gurumeditaion
addGuruMeditaion();
currentTimeStamp = getCurrentTimeStamp();
buildInfo(errorInfo);
reportButton.setOnClickListener(new View.OnClickListener() {
@Override
@ -214,12 +260,16 @@ public class ErrorActivity extends AppCompatActivity {
globIpRangeThread = new Thread(new IpRagneRequester());
globIpRangeThread.start();
// normal bugreport
buildInfo(errorInfo);
if(errorInfo.message != 0) {
errorMessageView.setText(errorInfo.message);
} else {
errorMessageView.setVisibility(View.GONE);
findViewById(R.id.messageWhatHappenedView).setVisibility(View.GONE);
}
errorView.setText(formErrorText(errorList));
}
@Override
@ -255,12 +305,12 @@ public class ErrorActivity extends AppCompatActivity {
return sw.getBuffer().toString();
}
private String formErrorText(List<Throwable> el) {
private String formErrorText(String[] el) {
String text = "";
if(el != null) {
for (Throwable e : el) {
for (String e : el) {
text += "-------------------------------------\n"
+ getStackTrace(e);
+ e;
}
}
text += "-------------------------------------";
@ -316,8 +366,8 @@ public class ErrorActivity extends AppCompatActivity {
JSONArray exceptionArray = new JSONArray();
if(errorList != null) {
for (Throwable e : errorList) {
exceptionArray.put(getStackTrace(e));
for (String e : errorList) {
exceptionArray.put(e);
}
}
@ -421,4 +471,13 @@ public class ErrorActivity extends AppCompatActivity {
}
}
}
// 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;
}
}

View File

@ -97,6 +97,7 @@
<string name="live_streams_not_supported">This is a LIVE STREAM. These are not yet supported.</string>
<string name="could_not_get_stream">Could not get any stream.</string>
<string name="could_not_load_image">Could not load Image</string>
<string name="app_ui_crash">App/UI crashed</string>
<!-- error activity -->
<string name="sorry_string">Sorry that should not happen.</string>
<string name="guru_meditation" translatable="false">Guru Meditation.</string>