X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fasynctasks%2FGetHostIpAddresses.java;h=c3e30c619b9adeeb1446dea380b61b8ca1cff244;hb=HEAD;hp=811eb7d322192a445a55c1ca5d3b08f98972bd45;hpb=86e63c8ed007311ab392d4beb7dd7ba64b9c3c70;p=PrivacyBrowserAndroid.git diff --git a/app/src/main/java/com/stoutner/privacybrowser/asynctasks/GetHostIpAddresses.java b/app/src/main/java/com/stoutner/privacybrowser/asynctasks/GetHostIpAddresses.java deleted file mode 100644 index 811eb7d3..00000000 --- a/app/src/main/java/com/stoutner/privacybrowser/asynctasks/GetHostIpAddresses.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright © 2019 Soren Stoutner . - * - * This file is part of Privacy Browser . - * - * Privacy Browser is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Privacy Browser is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Privacy Browser. If not, see . - */ - -package com.stoutner.privacybrowser.asynctasks; - -import android.app.Activity; -import android.os.AsyncTask; - -import androidx.fragment.app.FragmentManager; - -import com.stoutner.privacybrowser.helpers.CheckPinnedMismatchHelper; -import com.stoutner.privacybrowser.views.NestedScrollWebView; - -import java.lang.ref.WeakReference; -import java.net.InetAddress; -import java.net.UnknownHostException; - -// This must run asynchronously because it involves a network request. `String` declares the parameters. `Void` does not declare progress units. `String` contains the results. -public class GetHostIpAddresses extends AsyncTask { - // The weak references are used to determine if the activity have disappeared while the AsyncTask is running. - private final WeakReference activityWeakReference; - private final WeakReference fragmentManagerWeakReference; - private final WeakReference nestedScrollWebViewWeakReference; - - public GetHostIpAddresses(Activity activity, FragmentManager fragmentManager, NestedScrollWebView nestedScrollWebView) { - // Populate the weak references. - activityWeakReference = new WeakReference<>(activity); - fragmentManagerWeakReference = new WeakReference<>(fragmentManager); - nestedScrollWebViewWeakReference = new WeakReference<>(nestedScrollWebView); - } - - @Override - protected String doInBackground(String... domainName) { - // Get a handles for the weak references. - Activity activity = activityWeakReference.get(); - FragmentManager fragmentManager = fragmentManagerWeakReference.get(); - NestedScrollWebView nestedScrollWebView = nestedScrollWebViewWeakReference.get(); - - // Abort if the activity or its components are gone. - if ((activity == null) || activity.isFinishing() || fragmentManager == null || nestedScrollWebView == null) { - // Return an empty spannable string builder. - return ""; - } - - // Initialize an IP address string builder. - StringBuilder ipAddresses = new StringBuilder(); - - // Get an array with the IP addresses for the host. - try { - // Get an array with all the IP addresses for the domain. - InetAddress[] inetAddressesArray = InetAddress.getAllByName(domainName[0]); - - // Add each IP address to the string builder. - for (InetAddress inetAddress : inetAddressesArray) { - // Add a line break to the string builder if this is not the first IP address. - if (ipAddresses.length() > 0) { - ipAddresses.append("\n"); - } - - // Add the IP address to the string builder. - ipAddresses.append(inetAddress.getHostAddress()); - } - } catch (UnknownHostException exception) { - // Do nothing. - } - - // Return the string. - return ipAddresses.toString(); - } - - // `onPostExecute()` operates on the UI thread. - @Override - protected void onPostExecute(String ipAddresses) { - // Get a handle for the activity and the nested scroll WebView. - Activity activity = activityWeakReference.get(); - FragmentManager fragmentManager = fragmentManagerWeakReference.get(); - NestedScrollWebView nestedScrollWebView = nestedScrollWebViewWeakReference.get(); - - // Abort if the activity or its components are gone. - if ((activity == null) || activity.isFinishing() || fragmentManager == null || nestedScrollWebView == null) { - return; - } - - // Store the IP addresses. - nestedScrollWebView.setCurrentIpAddresses(ipAddresses); - - // Checked for pinned mismatches if there is pinned information and it is not ignored. - if ((nestedScrollWebView.hasPinnedSslCertificate() || nestedScrollWebView.hasPinnedIpAddresses()) && !nestedScrollWebView.ignorePinnedDomainInformation()) { - CheckPinnedMismatchHelper.checkPinnedMismatch(fragmentManager, nestedScrollWebView); - } - } -} \ No newline at end of file