X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fhelpers%2FCheckPinnedMismatchHelper.java;h=5f1ab22f65c38a0901cc013a9dead62d34f3d13e;hb=aa121d6d6df14a0425ac3b5603765dbae7e8d156;hp=48bf73bdfdbb2f7415501ebf09a1a5fc416360d4;hpb=ff636c77836983a078f33e60616204518dab61d1;p=PrivacyBrowserAndroid.git diff --git a/app/src/main/java/com/stoutner/privacybrowser/helpers/CheckPinnedMismatchHelper.java b/app/src/main/java/com/stoutner/privacybrowser/helpers/CheckPinnedMismatchHelper.java index 48bf73bd..5f1ab22f 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/helpers/CheckPinnedMismatchHelper.java +++ b/app/src/main/java/com/stoutner/privacybrowser/helpers/CheckPinnedMismatchHelper.java @@ -1,5 +1,5 @@ /* - * Copyright © 2018-2019 Soren Stoutner . + * Copyright © 2018-2019,2021 Soren Stoutner . * * This file is part of Privacy Browser . * @@ -19,6 +19,7 @@ package com.stoutner.privacybrowser.helpers; +import android.app.Activity; import android.net.http.SslCertificate; import androidx.fragment.app.DialogFragment; @@ -31,7 +32,7 @@ import java.util.ArrayList; import java.util.Date; public class CheckPinnedMismatchHelper { - public static void checkPinnedMismatch(FragmentManager fragmentManager, NestedScrollWebView nestedScrollWebView) { + public static void checkPinnedMismatch(Activity activity, FragmentManager fragmentManager, NestedScrollWebView nestedScrollWebView) { // Initialize the current SSL certificate variables. String currentWebsiteIssuedToCName = ""; String currentWebsiteIssuedToOName = ""; @@ -120,8 +121,19 @@ public class CheckPinnedMismatchHelper { !currentWebsiteIssuedByUName.equals(pinnedSslIssuedByUName) || !currentWebsiteSslStartDateString.equals(pinnedSslStartDateString) || !currentWebsiteSslEndDateString.equals(pinnedSslEndDateString)))) { + // Prevent the dialog from displaying if the app window is not visible. + // The check pinned mismatch helper continues to function even when the app 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. + activity.wait(1000); + } catch (InterruptedException e) { + // Do nothing. + } + } + // Get a handle for the pinned mismatch alert dialog. - DialogFragment pinnedMismatchDialogFragment = PinnedMismatchDialog.displayDialog(nestedScrollWebView.getWebViewFragmentId(), nestedScrollWebView.getFavoriteOrDefaultIcon()); + DialogFragment pinnedMismatchDialogFragment = PinnedMismatchDialog.displayDialog(nestedScrollWebView.getWebViewFragmentId()); // Show the pinned mismatch alert dialog. pinnedMismatchDialogFragment.show(fragmentManager, "Pinned Mismatch");