Skip to content

Commit

Permalink
(fixes #75) fix ACRA!!
Browse files Browse the repository at this point in the history
  • Loading branch information
VishnuSanal committed Aug 12, 2024
1 parent 3f57696 commit 8e2c32f
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 38 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ dependencies {
annotationProcessor "androidx.room:room-compiler:$room_version"

implementation "ch.acra:acra-core:5.11.3"
implementation "ch.acra:acra-dialog:5.11.3"

implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))

Expand Down
6 changes: 5 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@

<activity
android:name=".acra.ACRAErrorActivity"
android:exported="true"
android:parentActivityName=".activity.SplashActivity"
android:excludeFromRecents="true"
android:exported="true"
android:finishOnTaskLaunch="true"
android:launchMode="singleTop"
android:process=":acra"
android:screenOrientation="portrait">

<meta-data
Expand Down
76 changes: 40 additions & 36 deletions app/src/main/java/phone/vishnu/quotes/acra/ACRAErrorActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,14 @@
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.material.textfield.TextInputEditText;
import com.google.gson.GsonBuilder;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Date;
import org.acra.ReportField;
import org.acra.data.CrashReportData;
import phone.vishnu.quotes.BuildConfig;
import phone.vishnu.quotes.R;
import phone.vishnu.quotes.activity.SplashActivity;
import phone.vishnu.quotes.helper.Constants;
Expand Down Expand Up @@ -87,6 +93,9 @@ private static String checkNullity(String s) {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

if (!checkIntent(getIntent())) moveToSplash();

setContentView(R.layout.activity_acra_error);
setTitle(
String.format(
Expand All @@ -104,43 +113,38 @@ protected void onCreate(Bundle savedInstanceState) {
telegramButton = findViewById(R.id.errorActivityTelegramReportTV);
userCommentTIE = findViewById(R.id.errorActivityUserCommentTIE);

Intent intent = getIntent();

if (checkIntent(intent)) {

packageNameTV.setText(
String.format(
"%s %s",
getString(R.string.package_name),
checkNullity(intent.getStringExtra(Constants.ACRA_PACKAGE_NAME))));
versionNameTV.setText(
String.format(
"%s %s",
getString(R.string.app_version),
checkNullity(intent.getStringExtra(Constants.ACRA_APP_VERSION_NAME))));
versionCodeTV.setText(
String.format(
"%s %s",
getString(R.string.version_code),
checkNullity(intent.getStringExtra(Constants.ACRA_APP_VERSION_CODE))));
androidVersionTV.setText(
String.format(
"%s %s",
getString(R.string.android_version),
checkNullity(intent.getStringExtra(Constants.ACRA_ANDROID_VERSION))));
appStartDateTV.setText(
String.format(
"%s %s",
getString(R.string.app_start_date),
checkNullity(
intent.getStringExtra(Constants.ACRA_USER_APP_START_DATE))));
stackTraceTV.setText(
String.format(
"%s\n\n%s",
getString(R.string.stack_trace),
checkNullity(intent.getStringExtra(Constants.ACRA_STACK_TRACE))));
File reportFile = (File) getIntent().getSerializableExtra(Constants.ACRA_REPORT_FILE_KEY);

String stackTrace = "Could not load stack trace";

try {
ACRALogFileModel acraLogFileModel =
new GsonBuilder()
.setLenient()
.create()
.fromJson(new FileReader(reportFile), ACRALogFileModel.class);

stackTrace = acraLogFileModel.getStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
}

packageNameTV.setText(
String.format(
"%s %s", getString(R.string.package_name), BuildConfig.APPLICATION_ID));
versionNameTV.setText(
String.format("%s %s", getString(R.string.app_version), BuildConfig.VERSION_NAME));
versionCodeTV.setText(
String.format("%s %s", getString(R.string.version_code), BuildConfig.VERSION_CODE));
androidVersionTV.setText(
String.format(
"%s %s",
getString(R.string.android_version), android.os.Build.VERSION.SDK_INT));
appStartDateTV.setText(
String.format("%s %s", getString(R.string.app_start_date), new Date()));
stackTraceTV.setText(
String.format("%s\n\n%s", getString(R.string.stack_trace), stackTrace));

telegramButton.setOnClickListener(
view -> {
generateReport();
Expand Down Expand Up @@ -194,7 +198,7 @@ private void openLink(String s) {
private boolean checkIntent(Intent intent) {
return intent != null
&& intent.getExtras() != null
&& intent.getExtras().containsKey(Constants.ACRA_STACK_TRACE);
&& intent.getExtras().containsKey(Constants.ACRA_REPORT_FILE_KEY);
}

@Override
Expand Down
57 changes: 57 additions & 0 deletions app/src/main/java/phone/vishnu/quotes/acra/ACRALogFileModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (C) 2019 - 2024 Vishnu Sanal. T
*
* This file is part of Quotes Status Creator.
*
* Quotes Status Creator 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.
*
* This program 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package phone.vishnu.quotes.acra;

public class ACRALogFileModel {

private String STACK_TRACE, LOGCAT;

public ACRALogFileModel(String STACK_TRACE, String LOGCAT) {
this.STACK_TRACE = STACK_TRACE;
this.LOGCAT = LOGCAT;
}

public String getStackTrace() {
return STACK_TRACE;
}

public void setStackTrace(String STACK_TRACE) {
this.STACK_TRACE = STACK_TRACE;
}

public String getLogcat() {
return LOGCAT;
}

public void setLogcat(String LOGCAT) {
this.LOGCAT = LOGCAT;
}

@Override
public String toString() {
return "\nACRALogFileModel:\n\n"
+ "STACK_TRACE: "
+ STACK_TRACE
+ '\n'
+ "LOGCAT: "
+ LOGCAT
+ '\n';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
import com.android.volley.toolbox.Volley;
import org.acra.ACRA;
import org.acra.config.CoreConfigurationBuilder;
import org.acra.config.DialogConfigurationBuilder;
import org.acra.data.StringFormat;
import phone.vishnu.quotes.BuildConfig;
import phone.vishnu.quotes.acra.ACRAErrorActivity;

public class AppController extends Application {

Expand All @@ -53,7 +55,11 @@ protected void attachBaseContext(Context base) {
this,
new CoreConfigurationBuilder()
.withBuildConfigClass(BuildConfig.class)
.withReportFormat(StringFormat.JSON));
.withReportFormat(StringFormat.JSON)
.withPluginConfigurations(
new DialogConfigurationBuilder()
.withReportDialogClass(ACRAErrorActivity.class)
.build()));
}

private RequestQueue getRequestQueue() {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/phone/vishnu/quotes/helper/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ object Constants {
const val ACRA_APP_VERSION_NAME = "ACRA_APP_VERSION_NAME"
const val ACRA_PACKAGE_NAME = "ACRA_PACKAGE_NAME"
const val ACRA_USER_APP_START_DATE = "ACRA_USER_APP_START_DATE"
const val ACRA_REPORT_FILE_KEY = "REPORT_FILE"

const val DATA = "data"
const val QUOTE = "quote"
Expand Down

0 comments on commit 8e2c32f

Please sign in to comment.