Skip to content

fix(android): fix crashes and faulty preview on Chrome 86+ #125

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

timbru31
Copy link
Contributor

@timbru31 timbru31 commented Sep 15, 2020

This is achieved by always using a new WebView instance and by destorying the old one

fix(android): correct file name for temp folder
fix(android): remove unused config file
fix(android): register only one printer adapter
fix(android): do not crash if error code is null (which is valid)
refactor(android): use Cordova's log helper
style: reformat codebase

This fixes #124

}

@Override
public void onWriteFailed(CharSequence error) {
super.onWriteFailed(error);

Log.d(TAG, "onWriteFailed: Failed!!! " + error.toString() );
LOG.e(LOG_TAG, "onWriteFailed: Failed: " + error);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here lies the reason of the crash. The error might be null according to the JavaDocs: https://developer.android.com/reference/android/print/PrintDocumentAdapter.WriteResultCallback#onWriteFailed(java.lang.CharSequence)

mWrappedInstance.onFinish();
webView.destroy();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This ensures to destroy the webView instance after the user either printed or cancelled the share PDF intent.

@timbru31 timbru31 force-pushed the fix/android-crashes-chrome-86+ branch from acc5f50 to 3b78a66 Compare September 15, 2020 12:55
LOG.e(LOG_TAG, "getAsBase64 Error in I/O: ", ex);
cordovaCallback.error(IO_EXCEPTION);
} finally {
this.webView.destroy();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This ensures that in both the success and error case of the base64 request the webView is successfully destroyed again.

@timbru31 timbru31 force-pushed the fix/android-crashes-chrome-86+ branch from 3b78a66 to d927e2d Compare September 15, 2020 12:57
//.setMinMargins(PrintAttributes.Margins.NO_MARGINS).build();


PrintDocumentAdapter printAdapter = null;
Copy link
Contributor Author

@timbru31 timbru31 Sep 15, 2020

Choose a reason for hiding this comment

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

Before, a printerAdapater was always initialized, even when the target was share which uses the printerManager. Therefore, this code block was moved to the if block.

This is achieved by always using a new WebView instance and by destorying the old one

fix(android): correct file name for temp folder
fix(android): remove unused config file
fix(android): register only one printer adapter
fix(android): do not crash if error code is null (which is valid)
refactor(android): use Cordova's log helper
style: reformat codebase
@timbru31 timbru31 force-pushed the fix/android-crashes-chrome-86+ branch from d927e2d to 04c7491 Compare September 25, 2020 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crashes with Chrome 86+ on Android
1 participant