Skip to content

Commit

Permalink
Verify package name before initializing ACRA and ErrorActivity
Browse files Browse the repository at this point in the history
Fixes #2641.

Implementation is a bit primitive, and given the source code is publicly available, we can only slow down, but not prohibiting others from pirating without a decent code signing mechanism that will work across github, f-droid and derivatives, and google play.
  • Loading branch information
TranceLove committed Jun 20, 2021
1 parent 524aac5 commit 6ad477e
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ public void onCreate() {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
initACRA();
if (base.getPackageName().equals(BuildConfig.APPLICATION_ID)) {
initACRA();
}
}

@Override
Expand Down
146 changes: 78 additions & 68 deletions app/src/main/java/com/amaze/filemanager/crashreport/ErrorActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,13 @@ public static void reportError(

private static void startErrorActivity(
final Context context, final ErrorInfo errorInfo, final List<Throwable> el) {
final 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);
if (context.getPackageName().equals(BuildConfig.APPLICATION_ID)) {
final 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);
}
}

public static void reportError(
Expand All @@ -149,6 +151,7 @@ public static void reportError(
final String[] el = new String[] {report.getString(ReportField.STACK_TRACE)};

final Intent intent = new Intent(context, ErrorActivity.class);
intent.setPackage("context.getPackageName()");
intent.putExtra(ERROR_INFO, errorInfo);
intent.putExtra(ERROR_LIST, el);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Expand All @@ -174,74 +177,77 @@ private static String[] elToSl(final List<Throwable> stackTraces) {
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_error);
final Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

final Intent intent = getIntent();

final ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle(R.string.error_report_title);
actionBar.setDisplayShowTitleEnabled(true);
}

final Button reportEmailButton = findViewById(R.id.errorReportEmailButton);
final Button reportTelegramButton = findViewById(R.id.errorReportTelegramButton);
final Button copyButton = findViewById(R.id.errorReportCopyButton);
final Button reportGithubButton = findViewById(R.id.errorReportGitHubButton);

userCommentBox = findViewById(R.id.errorCommentBox);
final TextView errorView = findViewById(R.id.errorView);
final TextView errorMessageView = findViewById(R.id.errorMessageView);

returnActivity = MainActivity.class;
errorInfo = intent.getParcelableExtra(ERROR_INFO);
errorList = intent.getStringArrayExtra(ERROR_LIST);

// important add guru meditation
addGuruMeditation();
currentTimeStamp = getCurrentTimeStamp();

reportEmailButton.setOnClickListener((View v) -> sendReportEmail());

reportTelegramButton.setOnClickListener(
(View v) -> {
FileUtils.copyToClipboard(this, buildMarkdown());
Toast.makeText(this, R.string.crash_report_copied, Toast.LENGTH_SHORT).show();
Utils.openTelegramURL(this);
});

copyButton.setOnClickListener(
(View v) -> {
FileUtils.copyToClipboard(this, buildMarkdown());
Toast.makeText(this, R.string.crash_report_copied, Toast.LENGTH_SHORT).show();
});

reportGithubButton.setOnClickListener(
(View v) -> {
FileUtils.copyToClipboard(this, buildMarkdown());
Toast.makeText(this, R.string.crash_report_copied, Toast.LENGTH_SHORT).show();
Utils.openURL(ERROR_GITHUB_ISSUE_URL, this);
});

// normal bugreport
buildInfo(errorInfo);
if (errorInfo.message != 0) {
errorMessageView.setText(errorInfo.message);
if (ErrorInfo.comparePackageInfo(intent.getPackage()) != 0) {
finish();
} else {
errorMessageView.setVisibility(View.GONE);
findViewById(R.id.messageWhatHappenedView).setVisibility(View.GONE);
}
setContentView(R.layout.activity_error);
final Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

final ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle(R.string.error_report_title);
actionBar.setDisplayShowTitleEnabled(true);
}

final Button reportEmailButton = findViewById(R.id.errorReportEmailButton);
final Button reportTelegramButton = findViewById(R.id.errorReportTelegramButton);
final Button copyButton = findViewById(R.id.errorReportCopyButton);
final Button reportGithubButton = findViewById(R.id.errorReportGitHubButton);

userCommentBox = findViewById(R.id.errorCommentBox);
final TextView errorView = findViewById(R.id.errorView);
final TextView errorMessageView = findViewById(R.id.errorMessageView);

returnActivity = MainActivity.class;
errorInfo = intent.getParcelableExtra(ERROR_INFO);
errorList = intent.getStringArrayExtra(ERROR_LIST);

// important add guru meditation
addGuruMeditation();
currentTimeStamp = getCurrentTimeStamp();

reportEmailButton.setOnClickListener((View v) -> sendReportEmail());

reportTelegramButton.setOnClickListener(
(View v) -> {
FileUtils.copyToClipboard(this, buildMarkdown());
Toast.makeText(this, R.string.crash_report_copied, Toast.LENGTH_SHORT).show();
Utils.openTelegramURL(this);
});

copyButton.setOnClickListener(
(View v) -> {
FileUtils.copyToClipboard(this, buildMarkdown());
Toast.makeText(this, R.string.crash_report_copied, Toast.LENGTH_SHORT).show();
});

reportGithubButton.setOnClickListener(
(View v) -> {
FileUtils.copyToClipboard(this, buildMarkdown());
Toast.makeText(this, R.string.crash_report_copied, Toast.LENGTH_SHORT).show();
Utils.openURL(ERROR_GITHUB_ISSUE_URL, this);
});

// 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));
errorView.setText(formErrorText(errorList));

// print stack trace once again for debugging:
for (final String e : errorList) {
Log.e(TAG, e);
// print stack trace once again for debugging:
for (final String e : errorList) {
Log.e(TAG, e);
}
initStatusBarResources(findViewById(R.id.parent_view));
}
initStatusBarResources(findViewById(R.id.parent_view));
}

@Override
Expand Down Expand Up @@ -496,5 +502,9 @@ public void writeToParcel(final Parcel dest, final int flags) {
dest.writeString(this.request);
dest.writeInt(this.message);
}

public static int comparePackageInfo(String packageName) {
return packageName.hashCode() - BuildConfig.APPLICATION_ID.hashCode();
}
}
}

0 comments on commit 6ad477e

Please sign in to comment.