Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transport-crash-report-creation #383

Merged
merged 6 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions BundleClient/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@
<string name="usb_device_attached_checking_for_storage_volumes">USB device attached, checking for storage volumes</string>
<string name="usb_connection_detected">USB connection detected</string>
<string name="usb_device_not_connected">USB device not connected</string>
<string name="acra_toast_text">Acra creating crash report!</string>
</resources>
11 changes: 11 additions & 0 deletions BundleTransport/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,15 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.6.1'

//dependencies for ACRA

//version
def acraVersion = '5.12.0'
//custom sender (custom destination)
implementation "ch.acra:acra-core:$acraVersion"
//here's where we could add dialog interaction (user notification and description of crash)
//annotation to load sender onto acra config
annotationProcessor("com.google.auto.service:auto-service:1.1.1")
compileOnly("com.google.auto.service:auto-service-annotations:1.1.1")
}
2 changes: 1 addition & 1 deletion BundleTransport/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>


<application
<application android:name=".utils.acraUtils"
03fernanda-palacios marked this conversation as resolved.
Show resolved Hide resolved
android:icon="@drawable/bundletransport_icon"
android:label="@string/app_name"
android:roundIcon="@drawable/bundletransport_icon"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package net.discdd.bundletransport.utils;

import android.content.Context;

import com.google.auto.service.AutoService;
import org.acra.config.CoreConfiguration;
import org.acra.data.CrashReportData;
import org.acra.sender.ReportSender;
import org.acra.sender.ReportSenderException;
import org.acra.sender.ReportSenderFactory;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.io.FileWriter;
import java.nio.file.Path;

public class LocalReportSender implements ReportSender {
CoreConfiguration config;

public LocalReportSender(CoreConfiguration coreConfiguration) {
config = coreConfiguration;
}

@Override
public void send(Context context, CrashReportData errorContent) throws ReportSenderException {
// Iterate over the CrashReportData instance and do whatever
// you need with each pair of ReportField key / String value

//declare root dir and append target dir (toServer)
Path rootDir = context.getApplicationContext().getExternalFilesDir(null).toPath();
Path destDir = rootDir.resolve("BundleTransmission/server");
if (destDir.toFile().exists()) {
File logFile = new File(String.valueOf(destDir), "crash_report.txt");
03fernanda-palacios marked this conversation as resolved.
Show resolved Hide resolved
} else {
destDir.toFile().mkdir();
File logFile = new File(String.valueOf(destDir), "crash_report.txt");
}
File logFile = new File(String.valueOf(destDir), "crash_report.txt");
try {
// Use the core ReportFormat configuration
String reportText = config.getReportFormat()
.toFormattedString(errorContent,
config.getReportContent(), "\n", "\n\t", false);

// Overwrite last report
FileWriter writer = new FileWriter(logFile, false);
03fernanda-palacios marked this conversation as resolved.
Show resolved Hide resolved
writer.append(reportText);
writer.flush();
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
}

@AutoService(ReportSenderFactory.class)
public static class MySenderFactory implements ReportSenderFactory {
@NotNull
@Override
public ReportSender create(@NotNull Context context, @NotNull CoreConfiguration coreConfiguration) {
return new LocalReportSender(coreConfiguration);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package net.discdd.bundletransport.utils;
03fernanda-palacios marked this conversation as resolved.
Show resolved Hide resolved

import static org.acra.ACRA.log;

import android.app.Application;
import android.content.Context;

import org.acra.ACRA;
import org.acra.BuildConfig;
import org.acra.config.CoreConfigurationBuilder;
import org.acra.data.CrashReportData;
import org.acra.data.StringFormat;
import org.acra.sender.ReportSender;
import org.acra.sender.ReportSenderException;

public class acraUtils extends Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
ACRA.DEV_LOGGING = true;
log.e("ACRA Enabled dev logging", "ACRA OK");
ACRA.init(this, new CoreConfigurationBuilder()
//core configuration:
.withBuildConfigClass(BuildConfig.class)
.withReportFormat(StringFormat.KEY_VALUE_LIST)
);
}
}
Loading