]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/commitdiff
Fix a crash caused by dialogs attempting to display while the app is paused. https...
authorSoren Stoutner <soren@stoutner.com>
Tue, 9 Mar 2021 22:23:38 +0000 (15:23 -0700)
committerSoren Stoutner <soren@stoutner.com>
Tue, 9 Mar 2021 22:23:38 +0000 (15:23 -0700)
app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java

index cd7a164c44abac393c434c5720084393bdd4a4ef..bef36d6a3de96444a723cf23bb4503c04be2c226 100644 (file)
@@ -5428,6 +5428,17 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
             // Get the file name from the content disposition.
             String fileNameString = PrepareSaveDialog.getFileNameFromHeaders(this, contentDisposition, mimetype, downloadUrl);
 
+            // Prevent the dialog from displaying if the app window is not visible.
+            // The download listener continues to function even when the WebView is paused.  Attempting to display a dialog in that state leads to a crash.
+            while (!activity.getWindow().isActive()) {
+                try {
+                    // The window is not active.  Wait 1 second.
+                    wait(1000);
+                } catch (InterruptedException e) {
+                    // Do nothing.
+                }
+            }
+
             // Instantiate the save dialog.
             DialogFragment saveDialogFragment = SaveWebpageDialog.saveWebpage(StoragePermissionDialog.SAVE_URL, downloadUrl, formattedFileSizeString, fileNameString, userAgent,
                     nestedScrollWebView.getAcceptFirstPartyCookies());
@@ -6429,6 +6440,17 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
                     // Store the SSL error handler.
                     nestedScrollWebView.setSslErrorHandler(handler);
 
+                    // Prevent the dialog from displaying if the app window is not visible.
+                    // The SSL error handler continues to function even when the WebView is paused.  Attempting to display a dialog in that state leads to a crash.
+                    while (!activity.getWindow().isActive()) {
+                        try {
+                            // The window is not active.  Wait 1 second.
+                            wait(1000);
+                        } catch (InterruptedException e) {
+                            // Do nothing.
+                        }
+                    }
+
                     // Instantiate an SSL certificate error alert dialog.
                     DialogFragment sslCertificateErrorDialogFragment = SslCertificateErrorDialog.displayDialog(error, nestedScrollWebView.getWebViewFragmentId());