+
+ // Only populate the Orbot text view if it is installed.
+ if (!orbot.isEmpty()) {
+ String orbotLabel = getString(R.string.orbot) + " ";
+ SpannableStringBuilder orbotStringBuilder = new SpannableStringBuilder(orbotLabel + orbot);
+ orbotStringBuilder.setSpan(blueColorSpan, orbotLabel.length(), orbotStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ orbotTextView.setText(orbotStringBuilder);
+ } else { // Orbot is not installed.
+ orbotTextView.setVisibility(View.GONE);
+ }
+
+ // Only populate the OpenKeychain text view if it is installed.
+ if (!openKeychain.isEmpty()) {
+ String openKeychainLabel = getString(R.string.openkeychain) + " ";
+ SpannableStringBuilder openKeychainStringBuilder = new SpannableStringBuilder(openKeychainLabel + openKeychain);
+ openKeychainStringBuilder.setSpan(blueColorSpan, openKeychainLabel.length(), openKeychainStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ openKeychainTextView.setText(openKeychainStringBuilder);
+ } else { //OpenKeychain is not installed.
+ openKeychainTextView.setVisibility(View.GONE);
+ }
+
+ // Display the package signature.
+ try {
+ // Get the first package signature. Suppress the lint warning about the need to be careful in implementing comparison of certificates for security purposes.
+ @SuppressLint("PackageManagerGetSignatures") Signature packageSignature = getContext().getPackageManager().getPackageInfo(getContext().getPackageName(), PackageManager.GET_SIGNATURES).signatures[0];
+
+ // Convert the signature to a `byte[]` `InputStream`.
+ InputStream certificateByteArrayInputStream = new ByteArrayInputStream(packageSignature.toByteArray());
+
+ // Display the certificate information on the screen.
+ try {
+ // Instantiate a `CertificateFactory`.
+ CertificateFactory certificateFactory = CertificateFactory.getInstance("X509");
+
+ // Generate an `X509Certificate`.
+ X509Certificate x509Certificate = (X509Certificate) certificateFactory.generateCertificate(certificateByteArrayInputStream);
+
+ // Store the individual sections of the certificate that we are interested in.
+ Principal issuerDNPrincipal = x509Certificate.getIssuerDN();
+ Principal subjectDNPrincipal = x509Certificate.getSubjectDN();
+ Date startDate = x509Certificate.getNotBefore();
+ Date endDate = x509Certificate.getNotAfter();
+ int certificateVersion = x509Certificate.getVersion();
+ BigInteger serialNumberBigInteger = x509Certificate.getSerialNumber();
+ String signatureAlgorithmNameString = x509Certificate.getSigAlgName();
+
+ // Create a `SpannableStringBuilder` for each `TextView` that needs multiple colors of text.
+ SpannableStringBuilder issuerDNStringBuilder = new SpannableStringBuilder(issuerDNLabel + issuerDNPrincipal.toString());
+ SpannableStringBuilder subjectDNStringBuilder = new SpannableStringBuilder(subjectDNLabel + subjectDNPrincipal.toString());
+ SpannableStringBuilder startDateStringBuilder = new SpannableStringBuilder(startDateLabel + DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.LONG).format(startDate));
+ SpannableStringBuilder endDataStringBuilder = new SpannableStringBuilder(endDateLabel + DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.LONG).format(endDate));
+ SpannableStringBuilder certificateVersionStringBuilder = new SpannableStringBuilder(certificateVersionLabel + certificateVersion);
+ SpannableStringBuilder serialNumberStringBuilder = new SpannableStringBuilder(serialNumberLabel + serialNumberBigInteger);
+ SpannableStringBuilder signatureAlgorithmStringBuilder = new SpannableStringBuilder(signatureAlgorithmLabel + signatureAlgorithmNameString);
+
+ // Setup the spans to display the device information in blue. `SPAN_INCLUSIVE_INCLUSIVE` allows the span to grow in either direction.
+ issuerDNStringBuilder.setSpan(blueColorSpan, issuerDNLabel.length(), issuerDNStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ subjectDNStringBuilder.setSpan(blueColorSpan, subjectDNLabel.length(), subjectDNStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ startDateStringBuilder.setSpan(blueColorSpan, startDateLabel.length(), startDateStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ endDataStringBuilder.setSpan(blueColorSpan, endDateLabel.length(), endDataStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ certificateVersionStringBuilder.setSpan(blueColorSpan, certificateVersionLabel.length(), certificateVersionStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ serialNumberStringBuilder.setSpan(blueColorSpan, serialNumberLabel.length(), serialNumberStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ signatureAlgorithmStringBuilder.setSpan(blueColorSpan, signatureAlgorithmLabel.length(), signatureAlgorithmStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+
+ // Display the strings in the text boxes.
+ certificateIssuerDNTextView.setText(issuerDNStringBuilder);
+ certificateSubjectDNTextView.setText(subjectDNStringBuilder);
+ certificateStartDateTextView.setText(startDateStringBuilder);
+ certificateEndDateTextView.setText(endDataStringBuilder);
+ certificateVersionTextView.setText(certificateVersionStringBuilder);
+ certificateSerialNumberTextView.setText(serialNumberStringBuilder);
+ certificateSignatureAlgorithmTextView.setText(signatureAlgorithmStringBuilder);
+ } catch (CertificateException e) {
+ // Do nothing if there is a certificate error.
+ }
+ } catch (PackageManager.NameNotFoundException e) {
+ // Do nothing if `PackageManager` says Privacy Browser isn't installed.
+ }
+ } else { // load a `WebView` for all the other tabs. Tab numbers start at 0.
+ // 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.
+ tabLayout = layoutInflater.inflate(R.layout.bare_webview, container, false);
+
+ // Get a handle for `tabWebView`.