-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
transport-crash-report-creation (#383)
Transport implementation of ACRA
- Loading branch information
1 parent
f68fd88
commit c422d9d
Showing
5 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
BundleTransport/app/src/main/java/net/discdd/bundletransport/utils/LocalReportSender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
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()) { | ||
destDir.toFile().mkdir(); | ||
} | ||
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); | ||
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); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
BundleTransport/app/src/main/java/net/discdd/bundletransport/utils/acraUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package net.discdd.bundletransport.utils; | ||
|
||
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) | ||
); | ||
} | ||
} |