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