c35b90b64b6231543d6aabc52afc116e6830054a
[PrivacyBrowser.git] / app / src / main / java / com / stoutner / privacybrowser / fragments / AboutTabFragment.java
1 /*
2  * Copyright © 2016-2020 Soren Stoutner <soren@stoutner.com>.
3  *
4  * This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
5  *
6  * Privacy Browser is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Privacy Browser is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Privacy Browser.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 package com.stoutner.privacybrowser.fragments;
21
22 import android.annotation.SuppressLint;
23 import android.content.Context;
24 import android.content.pm.PackageInfo;
25 import android.content.pm.PackageManager;
26 import android.content.pm.Signature;
27 import android.content.res.Configuration;
28 import android.os.Build;
29 import android.os.Bundle;
30 import android.text.SpannableStringBuilder;
31 import android.text.Spanned;
32 import android.text.style.ForegroundColorSpan;
33 import android.view.LayoutInflater;
34 import android.view.View;
35 import android.view.ViewGroup;
36 import android.webkit.WebView;
37 import android.widget.TextView;
38
39 import androidx.annotation.NonNull;
40 import androidx.fragment.app.Fragment;
41 import androidx.webkit.WebViewCompat;
42
43 import com.stoutner.privacybrowser.BuildConfig;
44 import com.stoutner.privacybrowser.R;
45
46 import java.io.ByteArrayInputStream;
47 import java.io.InputStream;
48 import java.math.BigInteger;
49 import java.security.Principal;
50 import java.security.cert.CertificateException;
51 import java.security.cert.CertificateFactory;
52 import java.security.cert.X509Certificate;
53 import java.text.DateFormat;
54 import java.util.Date;
55
56 public class AboutTabFragment extends Fragment {
57     // Define the class variables.
58     private int tabNumber;
59     private String[] blocklistVersions;
60     private View tabLayout;
61
62     public static AboutTabFragment createTab(int tabNumber, String[] blocklistVersions) {
63         // Create a bundle.
64         Bundle argumentsBundle = new Bundle();
65
66         // Store the tab number in the bundle.
67         argumentsBundle.putInt("tab_number", tabNumber);
68         argumentsBundle.putStringArray("blocklist_versions", blocklistVersions);
69
70         // Create a new instance of the tab fragment.
71         AboutTabFragment aboutTabFragment = new AboutTabFragment();
72
73         // Add the arguments bundle to the fragment.
74         aboutTabFragment.setArguments(argumentsBundle);
75
76         // Return the new fragment.
77         return aboutTabFragment;
78     }
79
80     @Override
81     public void onCreate(Bundle savedInstanceState) {
82         // Run the default commands.
83         super.onCreate(savedInstanceState);
84
85         // Get a handle for the arguments.
86         Bundle arguments = getArguments();
87
88         // Remove the incorrect lint warning below that arguments might be null.
89         assert arguments != null;
90
91         // Store the arguments in class variables.
92         tabNumber = getArguments().getInt("tab_number");
93         blocklistVersions = getArguments().getStringArray("blocklist_versions");
94     }
95
96     @Override
97     public View onCreateView(@NonNull LayoutInflater layoutInflater, ViewGroup container, Bundle savedInstanceState) {
98         // Get a handle for the context and assert that it isn't null.
99         Context context = getContext();
100         assert context != null;
101
102         // Get the current theme status.
103         int currentThemeStatus = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
104
105         // Load the tabs.  Tab numbers start at 0.
106         if (tabNumber == 0) {  // Load the about tab.
107             // Setting false at the end of inflater.inflate does not attach the inflated layout as a child of container.  The fragment will take care of attaching the root automatically.
108             tabLayout = layoutInflater.inflate(R.layout.about_tab_version, container, false);
109
110             // Get handles for the text views.
111             TextView versionTextView = tabLayout.findViewById(R.id.version);
112             TextView brandTextView = tabLayout.findViewById(R.id.brand);
113             TextView manufacturerTextView = tabLayout.findViewById(R.id.manufacturer);
114             TextView modelTextView = tabLayout.findViewById(R.id.model);
115             TextView deviceTextView = tabLayout.findViewById(R.id.device);
116             TextView bootloaderTextView = tabLayout.findViewById(R.id.bootloader);
117             TextView radioTextView = tabLayout.findViewById(R.id.radio);
118             TextView androidTextView = tabLayout.findViewById(R.id.android);
119             TextView securityPatchTextView = tabLayout.findViewById(R.id.security_patch);
120             TextView buildTextView = tabLayout.findViewById(R.id.build);
121             TextView webViewProviderTextView = tabLayout.findViewById(R.id.webview_provider);
122             TextView webViewVersionTextView = tabLayout.findViewById(R.id.webview_version);
123             TextView orbotTextView = tabLayout.findViewById(R.id.orbot);
124             TextView i2pTextView = tabLayout.findViewById(R.id.i2p);
125             TextView openKeychainTextView = tabLayout.findViewById(R.id.open_keychain);
126             TextView easyListTextView = tabLayout.findViewById(R.id.easylist);
127             TextView easyPrivacyTextView = tabLayout.findViewById(R.id.easyprivacy);
128             TextView fanboyAnnoyanceTextView = tabLayout.findViewById(R.id.fanboy_annoyance);
129             TextView fanboySocialTextView = tabLayout.findViewById(R.id.fanboy_social);
130             TextView ultraListTextView = tabLayout.findViewById(R.id.ultralist);
131             TextView ultraPrivacyTextView = tabLayout.findViewById(R.id.ultraprivacy);
132             TextView certificateIssuerDNTextView = tabLayout.findViewById(R.id.certificate_issuer_dn);
133             TextView certificateSubjectDNTextView = tabLayout.findViewById(R.id.certificate_subject_dn);
134             TextView certificateStartDateTextView = tabLayout.findViewById(R.id.certificate_start_date);
135             TextView certificateEndDateTextView = tabLayout.findViewById(R.id.certificate_end_date);
136             TextView certificateVersionTextView = tabLayout.findViewById(R.id.certificate_version);
137             TextView certificateSerialNumberTextView = tabLayout.findViewById(R.id.certificate_serial_number);
138             TextView certificateSignatureAlgorithmTextView = tabLayout.findViewById(R.id.certificate_signature_algorithm);
139
140             // Setup the labels.
141             String version = getString(R.string.version) + " " + BuildConfig.VERSION_NAME + " (" + getString(R.string.version_code) + " " + BuildConfig.VERSION_CODE + ")";
142             String brandLabel = getString(R.string.brand) + "  ";
143             String manufacturerLabel = getString(R.string.manufacturer) + "  ";
144             String modelLabel = getString(R.string.model) + "  ";
145             String deviceLabel = getString(R.string.device) + "  ";
146             String bootloaderLabel = getString(R.string.bootloader) + "  ";
147             String androidLabel = getString(R.string.android) + "  ";
148             String buildLabel = getString(R.string.build) + "  ";
149             String webViewVersionLabel = getString(R.string.webview_version) + "  ";
150             String easyListLabel = getString(R.string.easylist_label) + "  ";
151             String easyPrivacyLabel = getString(R.string.easyprivacy_label) + "  ";
152             String fanboyAnnoyanceLabel = getString(R.string.fanboy_annoyance_label) + "  ";
153             String fanboySocialLabel = getString(R.string.fanboy_social_label) + "  ";
154             String ultraListLabel = getString(R.string.ultralist_label) + "  ";
155             String ultraPrivacyLabel = getString(R.string.ultraprivacy_label) + "  ";
156             String issuerDNLabel = getString(R.string.issuer_dn) + "  ";
157             String subjectDNLabel = getString(R.string.subject_dn) + "  ";
158             String startDateLabel = getString(R.string.start_date) + "  ";
159             String endDateLabel = getString(R.string.end_date) + "  ";
160             String certificateVersionLabel = getString(R.string.certificate_version) + "  ";
161             String serialNumberLabel = getString(R.string.serial_number) + "  ";
162             String signatureAlgorithmLabel = getString(R.string.signature_algorithm) + "  ";
163
164             // The WebView layout is only used to get the default user agent from `bare_webview`.  It is not used to render content on the screen.
165             // Once the minimum API >= 26 this can be accomplished with the WebView package info.
166             View webViewLayout = layoutInflater.inflate(R.layout.bare_webview, container, false);
167             WebView tabLayoutWebView = webViewLayout.findViewById(R.id.bare_webview);
168             String userAgentString =  tabLayoutWebView.getSettings().getUserAgentString();
169
170             // Get the device's information and store it in strings.
171             String brand = Build.BRAND;
172             String manufacturer = Build.MANUFACTURER;
173             String model = Build.MODEL;
174             String device = Build.DEVICE;
175             String bootloader = Build.BOOTLOADER;
176             String radio = Build.getRadioVersion();
177             String android = Build.VERSION.RELEASE + " (" + getString(R.string.api) + " " + Build.VERSION.SDK_INT + ")";
178             String build = Build.DISPLAY;
179             // Select the substring that begins after `Chrome/` and goes until the next ` `.
180             String webView = userAgentString.substring(userAgentString.indexOf("Chrome/") + 7, userAgentString.indexOf(" ", userAgentString.indexOf("Chrome/")));
181
182             // Get the Orbot version name if Orbot is installed.
183             String orbot;
184             try {
185                 // Store the version name.
186                 orbot = context.getPackageManager().getPackageInfo("org.torproject.android", 0).versionName;
187             } catch (PackageManager.NameNotFoundException exception) {  // Orbot is not installed.
188                 orbot = "";
189             }
190
191             // Get the I2P version name if I2P is installed.
192             String i2p;
193             try {
194                 // Store the version name.
195                 i2p = context.getPackageManager().getPackageInfo("net.i2p.android.router", 0).versionName;
196             } catch (PackageManager.NameNotFoundException exception) {  // I2P is not installed.
197                 i2p = "";
198             }
199
200             // Get the OpenKeychain version name if it is installed.
201             String openKeychain;
202             try {
203                 // Store the version name.
204                 openKeychain = context.getPackageManager().getPackageInfo("org.sufficientlysecure.keychain", 0).versionName;
205             } catch (PackageManager.NameNotFoundException exception) {  // OpenKeychain is not installed.
206                 openKeychain = "";
207             }
208
209             // Create a `SpannableStringBuilder` for the hardware and software `TextViews` that needs multiple colors of text.
210             SpannableStringBuilder brandStringBuilder = new SpannableStringBuilder(brandLabel + brand);
211             SpannableStringBuilder manufacturerStringBuilder = new SpannableStringBuilder(manufacturerLabel + manufacturer);
212             SpannableStringBuilder modelStringBuilder = new SpannableStringBuilder(modelLabel + model);
213             SpannableStringBuilder deviceStringBuilder = new SpannableStringBuilder(deviceLabel + device);
214             SpannableStringBuilder bootloaderStringBuilder = new SpannableStringBuilder(bootloaderLabel + bootloader);
215             SpannableStringBuilder androidStringBuilder = new SpannableStringBuilder(androidLabel + android);
216             SpannableStringBuilder buildStringBuilder = new SpannableStringBuilder(buildLabel + build);
217             SpannableStringBuilder webViewVersionStringBuilder = new SpannableStringBuilder(webViewVersionLabel + webView);
218             SpannableStringBuilder easyListStringBuilder = new SpannableStringBuilder(easyListLabel + blocklistVersions[0]);
219             SpannableStringBuilder easyPrivacyStringBuilder = new SpannableStringBuilder(easyPrivacyLabel + blocklistVersions[1]);
220             SpannableStringBuilder fanboyAnnoyanceStringBuilder = new SpannableStringBuilder(fanboyAnnoyanceLabel + blocklistVersions[2]);
221             SpannableStringBuilder fanboySocialStringBuilder = new SpannableStringBuilder(fanboySocialLabel + blocklistVersions[3]);
222             SpannableStringBuilder ultraListStringBuilder = new SpannableStringBuilder(ultraListLabel + blocklistVersions[4]);
223             SpannableStringBuilder ultraPrivacyStringBuilder = new SpannableStringBuilder(ultraPrivacyLabel + blocklistVersions[5]);
224
225             // Define the blue color span variable.
226             ForegroundColorSpan blueColorSpan;
227
228             // Set the blue color span according to the theme.  The deprecated `getResources()` must be used until the minimum API >= 23.
229             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
230                 blueColorSpan = new ForegroundColorSpan(getResources().getColor(R.color.violet_500));
231             } else {
232                 blueColorSpan = new ForegroundColorSpan(getResources().getColor(R.color.blue_700));
233             }
234
235             // Setup the spans to display the device information in blue.  `SPAN_INCLUSIVE_INCLUSIVE` allows the span to grow in either direction.
236             brandStringBuilder.setSpan(blueColorSpan, brandLabel.length(), brandStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
237             manufacturerStringBuilder.setSpan(blueColorSpan, manufacturerLabel.length(), manufacturerStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
238             modelStringBuilder.setSpan(blueColorSpan, modelLabel.length(), modelStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
239             deviceStringBuilder.setSpan(blueColorSpan, deviceLabel.length(), deviceStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
240             bootloaderStringBuilder.setSpan(blueColorSpan, bootloaderLabel.length(), bootloaderStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
241             androidStringBuilder.setSpan(blueColorSpan, androidLabel.length(), androidStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
242             buildStringBuilder.setSpan(blueColorSpan, buildLabel.length(), buildStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
243             webViewVersionStringBuilder.setSpan(blueColorSpan, webViewVersionLabel.length(), webViewVersionStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
244             easyListStringBuilder.setSpan(blueColorSpan, easyListLabel.length(), easyListStringBuilder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
245             easyPrivacyStringBuilder.setSpan(blueColorSpan, easyPrivacyLabel.length(), easyPrivacyStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
246             fanboyAnnoyanceStringBuilder.setSpan(blueColorSpan, fanboyAnnoyanceLabel.length(), fanboyAnnoyanceStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
247             fanboySocialStringBuilder.setSpan(blueColorSpan, fanboySocialLabel.length(), fanboySocialStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
248             ultraListStringBuilder.setSpan(blueColorSpan, ultraListLabel.length(), ultraListStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
249             ultraPrivacyStringBuilder.setSpan(blueColorSpan, ultraPrivacyLabel.length(), ultraPrivacyStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
250
251             // Display the strings in the text boxes.
252             versionTextView.setText(version);
253             brandTextView.setText(brandStringBuilder);
254             manufacturerTextView.setText(manufacturerStringBuilder);
255             modelTextView.setText(modelStringBuilder);
256             deviceTextView.setText(deviceStringBuilder);
257             bootloaderTextView.setText(bootloaderStringBuilder);
258             androidTextView.setText(androidStringBuilder);
259             buildTextView.setText(buildStringBuilder);
260             webViewVersionTextView.setText(webViewVersionStringBuilder);
261             easyListTextView.setText(easyListStringBuilder);
262             easyPrivacyTextView.setText(easyPrivacyStringBuilder);
263             fanboyAnnoyanceTextView.setText(fanboyAnnoyanceStringBuilder);
264             fanboySocialTextView.setText(fanboySocialStringBuilder);
265             ultraListTextView.setText(ultraListStringBuilder);
266             ultraPrivacyTextView.setText(ultraPrivacyStringBuilder);
267
268             // Only populate the radio text view if there is a radio in the device.
269             if (!radio.isEmpty()) {
270                 String radioLabel = getString(R.string.radio) + "  ";
271                 SpannableStringBuilder radioStringBuilder = new SpannableStringBuilder(radioLabel + radio);
272                 radioStringBuilder.setSpan(blueColorSpan, radioLabel.length(), radioStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
273                 radioTextView.setText(radioStringBuilder);
274             } else {  // This device does not have a radio.
275                 radioTextView.setVisibility(View.GONE);
276             }
277
278             // Build.VERSION.SECURITY_PATCH is only available for SDK_INT >= 23.
279             if (Build.VERSION.SDK_INT >= 23) {
280                 String securityPatchLabel = getString(R.string.security_patch) + "  ";
281                 String securityPatch = Build.VERSION.SECURITY_PATCH;
282                 SpannableStringBuilder securityPatchStringBuilder = new SpannableStringBuilder(securityPatchLabel + securityPatch);
283                 securityPatchStringBuilder.setSpan(blueColorSpan, securityPatchLabel.length(), securityPatchStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
284                 securityPatchTextView.setText(securityPatchStringBuilder);
285             } else {  // The API < 23.
286                 // Hide the security patch text view.
287                 securityPatchTextView.setVisibility(View.GONE);
288             }
289
290             // Only populate the WebView provider if the SDK >= 21.
291             if (Build.VERSION.SDK_INT >= 21) {
292                 // Create the WebView provider label.
293                 String webViewProviderLabel = getString(R.string.webview_provider) + "  ";
294
295                 // Get the current WebView package info.
296                 PackageInfo webViewPackageInfo = WebViewCompat.getCurrentWebViewPackage(context);
297
298                 // Remove the warning below that the package info might be null.
299                 assert webViewPackageInfo != null;
300
301                 // Get the WebView provider name.
302                 String webViewPackageName = webViewPackageInfo.packageName;
303
304                 // Create the spannable string builder.
305                 SpannableStringBuilder webViewProviderStringBuilder = new SpannableStringBuilder(webViewProviderLabel + webViewPackageName);
306
307                 // Apply the coloration.
308                 webViewProviderStringBuilder.setSpan(blueColorSpan, webViewProviderLabel.length(), webViewProviderStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
309
310                 // Display the WebView provider.
311                 webViewProviderTextView.setText(webViewProviderStringBuilder);
312             } else {  // The API < 21.
313                 // Hide the WebView provider text view.
314                 webViewProviderTextView.setVisibility(View.GONE);
315             }
316
317             // Only populate the Orbot text view if it is installed.
318             if (!orbot.isEmpty()) {
319                 String orbotLabel = getString(R.string.orbot) + "  ";
320                 SpannableStringBuilder orbotStringBuilder = new SpannableStringBuilder(orbotLabel + orbot);
321                 orbotStringBuilder.setSpan(blueColorSpan, orbotLabel.length(), orbotStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
322                 orbotTextView.setText(orbotStringBuilder);
323             } else {  // Orbot is not installed.
324                 orbotTextView.setVisibility(View.GONE);
325             }
326
327             // Only populate the I2P text view if it is installed.
328             if (!i2p.isEmpty()) {
329                 String i2pLabel = getString(R.string.i2p)  + "  ";
330                 SpannableStringBuilder i2pStringBuilder = new SpannableStringBuilder(i2pLabel + i2p);
331                 i2pStringBuilder.setSpan(blueColorSpan, i2pLabel.length(), i2pStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
332                 i2pTextView.setText(i2pStringBuilder);
333             } else {  // I2P is not installed.
334                 i2pTextView.setVisibility(View.GONE);
335             }
336
337             // Only populate the OpenKeychain text view if it is installed.
338             if (!openKeychain.isEmpty()) {
339                 String openKeychainLabel = getString(R.string.openkeychain) + "  ";
340                 SpannableStringBuilder openKeychainStringBuilder = new SpannableStringBuilder(openKeychainLabel + openKeychain);
341                 openKeychainStringBuilder.setSpan(blueColorSpan, openKeychainLabel.length(), openKeychainStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
342                 openKeychainTextView.setText(openKeychainStringBuilder);
343             } else {  //OpenKeychain is not installed.
344                 openKeychainTextView.setVisibility(View.GONE);
345             }
346
347             // Display the package signature.
348             try {
349                 // Get the first package signature.  Suppress the lint warning about the need to be careful in implementing comparison of certificates for security purposes.
350                 @SuppressLint("PackageManagerGetSignatures") Signature packageSignature = getContext().getPackageManager().getPackageInfo(getContext().getPackageName(),
351                         PackageManager.GET_SIGNATURES).signatures[0];
352
353                 // Convert the signature to a byte array input stream.
354                 InputStream certificateByteArrayInputStream = new ByteArrayInputStream(packageSignature.toByteArray());
355
356                 // Display the certificate information on the screen.
357                 try {
358                     // Instantiate a `CertificateFactory`.
359                     CertificateFactory certificateFactory = CertificateFactory.getInstance("X509");
360
361                     // Generate an `X509Certificate`.
362                     X509Certificate x509Certificate = (X509Certificate) certificateFactory.generateCertificate(certificateByteArrayInputStream);
363
364                     // Store the individual sections of the certificate that we are interested in.
365                     Principal issuerDNPrincipal = x509Certificate.getIssuerDN();
366                     Principal subjectDNPrincipal = x509Certificate.getSubjectDN();
367                     Date startDate = x509Certificate.getNotBefore();
368                     Date endDate = x509Certificate.getNotAfter();
369                     int certificateVersion = x509Certificate.getVersion();
370                     BigInteger serialNumberBigInteger = x509Certificate.getSerialNumber();
371                     String signatureAlgorithmNameString = x509Certificate.getSigAlgName();
372
373                     // Create a `SpannableStringBuilder` for each `TextView` that needs multiple colors of text.
374                     SpannableStringBuilder issuerDNStringBuilder = new SpannableStringBuilder(issuerDNLabel + issuerDNPrincipal.toString());
375                     SpannableStringBuilder subjectDNStringBuilder = new SpannableStringBuilder(subjectDNLabel + subjectDNPrincipal.toString());
376                     SpannableStringBuilder startDateStringBuilder = new SpannableStringBuilder(startDateLabel + DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.LONG).format(startDate));
377                     SpannableStringBuilder endDataStringBuilder = new SpannableStringBuilder(endDateLabel + DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.LONG).format(endDate));
378                     SpannableStringBuilder certificateVersionStringBuilder = new SpannableStringBuilder(certificateVersionLabel + certificateVersion);
379                     SpannableStringBuilder serialNumberStringBuilder = new SpannableStringBuilder(serialNumberLabel + serialNumberBigInteger);
380                     SpannableStringBuilder signatureAlgorithmStringBuilder = new SpannableStringBuilder(signatureAlgorithmLabel + signatureAlgorithmNameString);
381
382                     // Setup the spans to display the device information in blue.  `SPAN_INCLUSIVE_INCLUSIVE` allows the span to grow in either direction.
383                     issuerDNStringBuilder.setSpan(blueColorSpan, issuerDNLabel.length(), issuerDNStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
384                     subjectDNStringBuilder.setSpan(blueColorSpan, subjectDNLabel.length(), subjectDNStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
385                     startDateStringBuilder.setSpan(blueColorSpan, startDateLabel.length(), startDateStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
386                     endDataStringBuilder.setSpan(blueColorSpan, endDateLabel.length(), endDataStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
387                     certificateVersionStringBuilder.setSpan(blueColorSpan, certificateVersionLabel.length(), certificateVersionStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
388                     serialNumberStringBuilder.setSpan(blueColorSpan, serialNumberLabel.length(), serialNumberStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
389                     signatureAlgorithmStringBuilder.setSpan(blueColorSpan, signatureAlgorithmLabel.length(), signatureAlgorithmStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
390
391                     // Display the strings in the text boxes.
392                     certificateIssuerDNTextView.setText(issuerDNStringBuilder);
393                     certificateSubjectDNTextView.setText(subjectDNStringBuilder);
394                     certificateStartDateTextView.setText(startDateStringBuilder);
395                     certificateEndDateTextView.setText(endDataStringBuilder);
396                     certificateVersionTextView.setText(certificateVersionStringBuilder);
397                     certificateSerialNumberTextView.setText(serialNumberStringBuilder);
398                     certificateSignatureAlgorithmTextView.setText(signatureAlgorithmStringBuilder);
399                 } catch (CertificateException e) {
400                     // Do nothing if there is a certificate error.
401                 }
402             } catch (PackageManager.NameNotFoundException e) {
403                 // Do nothing if `PackageManager` says Privacy Browser isn't installed.
404             }
405         } else { // load a WebView for all the other tabs.  Tab numbers start at 0.
406             // Setting false at the end of inflater.inflate does not attach the inflated layout as a child of container.  The fragment will take care of attaching the root automatically.
407             tabLayout = layoutInflater.inflate(R.layout.bare_webview, container, false);
408
409             // Get a handle for `tabWebView`.
410             WebView tabWebView = (WebView) tabLayout;
411
412             // Load the tabs according to the theme.
413             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {  // The dark theme is applied.
414                 // Set the background color.  The deprecated `.getColor()` must be used until the minimum API >= 23.
415                 tabWebView.setBackgroundColor(getResources().getColor(R.color.gray_850));
416
417                 switch (tabNumber) {
418                     case 1:
419                         tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/about_permissions_dark.html");
420                         break;
421
422                     case 2:
423                         tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/about_privacy_policy_dark.html");
424                         break;
425
426                     case 3:
427                         tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/about_changelog_dark.html");
428                         break;
429
430                     case 4:
431                         tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/about_licenses_dark.html");
432                         break;
433
434                     case 5:
435                         tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/about_contributors_dark.html");
436                         break;
437
438                     case 6:
439                         tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/about_links_dark.html");
440                         break;
441                 }
442             } else {  // The light theme is applied.
443                 switch (tabNumber) {
444                     case 1:
445                         tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/about_permissions_light.html");
446                         break;
447
448                     case 2:
449                         tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/about_privacy_policy_light.html");
450                         break;
451
452                     case 3:
453                         tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/about_changelog_light.html");
454                         break;
455
456                     case 4:
457                         tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/about_licenses_light.html");
458                         break;
459
460                     case 5:
461                         tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/about_contributors_light.html");
462                         break;
463
464                     case 6:
465                         tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/about_links_light.html");
466                         break;
467                 }
468             }
469         }
470
471         // Scroll the tab if the saved instance state is not null.
472         if (savedInstanceState != null) {
473             tabLayout.post(() -> {
474                 tabLayout.setScrollX(savedInstanceState.getInt("scroll_x"));
475                 tabLayout.setScrollY(savedInstanceState.getInt("scroll_y"));
476             });
477         }
478
479         // Return the formatted `tabLayout`.
480         return tabLayout;
481     }
482
483     @Override
484     public void onSaveInstanceState(@NonNull Bundle savedInstanceState) {
485         // Run the default commands.
486         super.onSaveInstanceState(savedInstanceState);
487
488         // Save the scroll positions if the tab layout is not null, which can happen if a tab is not currently selected.
489         if (tabLayout != null) {
490             savedInstanceState.putInt("scroll_x", tabLayout.getScrollX());
491             savedInstanceState.putInt("scroll_y", tabLayout.getScrollY());
492         }
493     }
494 }