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

Verify package name before initializing ACRA and ErrorActivity #2649

Draft
wants to merge 2 commits into
base: hotfix/3.6.2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
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)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't build config generated on compile?

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()");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you forget to delete the quotes?

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No else needed AFAIK.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least a return to get out of there would make me feel more safe ;)

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.indexOf("com.amaze.filemanager");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this going to work on debug package?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"com.amaze.filemanager.debug".indexOf("com.amaze.filemanager") == 0

}
}
}