X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fhelpers%2FCheckPinnedMismatchHelper.java;h=5f1ab22f65c38a0901cc013a9dead62d34f3d13e;hp=25d84144b836306294ce5c8e3404d601ce4d66f9;hb=d4f39c36beb5e6c3568a1e075274ad66defd8e8e;hpb=f825cc15f0383acce10bb16443e027edb869a11e 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 25d84144..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,6 +121,17 @@ 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());