import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.Dialog;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.Dialog;
import com.stoutner.privacybrowser.activities.MainWebViewActivity;
import com.stoutner.privacybrowser.R;
import com.stoutner.privacybrowser.activities.MainWebViewActivity;
import com.stoutner.privacybrowser.R;
// `@SuppressLing("InflateParams")` removes the warning about using `null` as the parent view group when inflating the `AlertDialog`.
@SuppressLint("InflateParams")
public class ViewSslCertificateDialog extends DialogFragment {
// `@SuppressLing("InflateParams")` removes the warning about using `null` as the parent view group when inflating the `AlertDialog`.
@SuppressLint("InflateParams")
public class ViewSslCertificateDialog extends DialogFragment {
- // Get the activity's layout inflater.
- LayoutInflater layoutInflater = getActivity().getLayoutInflater();
+ // Remove the incorrect lint warning below that the activity might be null.
+ assert getActivity() != null;
- // Create a drawable version of the favorite icon.
- Drawable favoriteIconDrawable = new BitmapDrawable(getResources(), MainWebViewActivity.favoriteIconBitmap);
+ // Get the activity's layout inflater.
+ LayoutInflater layoutInflater = getActivity().getLayoutInflater();
TextView issuedToCNameTextView = alertDialog.findViewById(R.id.issued_to_cname);
TextView issuedToONameTextView = alertDialog.findViewById(R.id.issued_to_oname);
TextView issuedToUNameTextView = alertDialog.findViewById(R.id.issued_to_uname);
TextView issuedToCNameTextView = alertDialog.findViewById(R.id.issued_to_cname);
TextView issuedToONameTextView = alertDialog.findViewById(R.id.issued_to_oname);
TextView issuedToUNameTextView = alertDialog.findViewById(R.id.issued_to_uname);
String cNameLabel = getString(R.string.common_name) + " ";
String oNameLabel = getString(R.string.organization) + " ";
String uNameLabel = getString(R.string.organizational_unit) + " ";
String startDateLabel = getString(R.string.start_date) + " ";
String endDateLabel = getString(R.string.end_date) + " ";
String cNameLabel = getString(R.string.common_name) + " ";
String oNameLabel = getString(R.string.organization) + " ";
String uNameLabel = getString(R.string.organizational_unit) + " ";
String startDateLabel = getString(R.string.start_date) + " ";
String endDateLabel = getString(R.string.end_date) + " ";
String domainString = uri.getHost();
// Get the SSL certificate.
SslCertificate sslCertificate = MainWebViewActivity.sslCertificate;
// Get the strings from the SSL certificate.
String domainString = uri.getHost();
// Get the SSL certificate.
SslCertificate sslCertificate = MainWebViewActivity.sslCertificate;
// Get the strings from the SSL certificate.
- String issuedToCNameString = sslCertificate.getIssuedTo().getCName();
- String issuedToONameString = sslCertificate.getIssuedTo().getOName();
- String issuedToUNameString = sslCertificate.getIssuedTo().getUName();
- String issuedByCNameString = sslCertificate.getIssuedBy().getCName();
- String issuedByONameString = sslCertificate.getIssuedBy().getOName();
- String issuedByUNameString = sslCertificate.getIssuedBy().getUName();
+ String issuedToCName = sslCertificate.getIssuedTo().getCName();
+ String issuedToOName = sslCertificate.getIssuedTo().getOName();
+ String issuedToUName = sslCertificate.getIssuedTo().getUName();
+ String issuedByCName = sslCertificate.getIssuedBy().getCName();
+ String issuedByOName = sslCertificate.getIssuedBy().getOName();
+ String issuedByUName = sslCertificate.getIssuedBy().getUName();
Date startDate = sslCertificate.getValidNotBeforeDate();
Date endDate = sslCertificate.getValidNotAfterDate();
Date startDate = sslCertificate.getValidNotBeforeDate();
Date endDate = sslCertificate.getValidNotAfterDate();
- SpannableStringBuilder issuedToCNameStringBuilder = new SpannableStringBuilder(cNameLabel + issuedToCNameString);
- SpannableStringBuilder issuedToONameStringBuilder = new SpannableStringBuilder(oNameLabel + issuedToONameString);
- SpannableStringBuilder issuedToUNameStringBuilder = new SpannableStringBuilder(uNameLabel + issuedToUNameString);
- SpannableStringBuilder issuedByCNameStringBuilder = new SpannableStringBuilder(cNameLabel + issuedByCNameString);
- SpannableStringBuilder issuedByONameStringBuilder = new SpannableStringBuilder(oNameLabel + issuedByONameString);
- SpannableStringBuilder issuedByUNameStringBuilder = new SpannableStringBuilder(uNameLabel + issuedByUNameString);
+ SpannableStringBuilder ipAddressesStringBuilder = new SpannableStringBuilder(ipAddressesLabel + MainWebViewActivity.currentHostIpAddresses);
+ SpannableStringBuilder issuedToCNameStringBuilder = new SpannableStringBuilder(cNameLabel + issuedToCName);
+ SpannableStringBuilder issuedToONameStringBuilder = new SpannableStringBuilder(oNameLabel + issuedToOName);
+ SpannableStringBuilder issuedToUNameStringBuilder = new SpannableStringBuilder(uNameLabel + issuedToUName);
+ SpannableStringBuilder issuedByCNameStringBuilder = new SpannableStringBuilder(cNameLabel + issuedByCName);
+ SpannableStringBuilder issuedByONameStringBuilder = new SpannableStringBuilder(oNameLabel + issuedByOName);
+ SpannableStringBuilder issuedByUNameStringBuilder = new SpannableStringBuilder(uNameLabel + issuedByUName);
SpannableStringBuilder startDateStringBuilder = new SpannableStringBuilder(startDateLabel + DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.LONG).format(startDate));
SpannableStringBuilder endDateStringBuilder = new SpannableStringBuilder(endDateLabel + DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.LONG).format(endDate));
SpannableStringBuilder startDateStringBuilder = new SpannableStringBuilder(startDateLabel + DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.LONG).format(startDate));
SpannableStringBuilder endDateStringBuilder = new SpannableStringBuilder(endDateLabel + DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.LONG).format(endDate));
if (MainWebViewActivity.darkTheme) {
//noinspection deprecation
blueColorSpan = new ForegroundColorSpan(getResources().getColor(R.color.blue_400));
if (MainWebViewActivity.darkTheme) {
//noinspection deprecation
blueColorSpan = new ForegroundColorSpan(getResources().getColor(R.color.blue_400));
- // Formet the `domainString` and `issuedToCName` colors.
- if (domainString.equals(issuedToCNameString)) { // `domainString` and `issuedToCNameString` match.
+ // Remove the incorrect lint error that `.equals` might produce a NullPointerException.
+ assert domainString != null;
+
+ // Formet the domain string and issued to CName colors.
+ if (domainString.equals(issuedToCName)) { // `domainString` and `issuedToCName` match.
// Set the strings to be blue.
domainStringBuilder.setSpan(blueColorSpan, domainLabel.length(), domainStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
issuedToCNameStringBuilder.setSpan(blueColorSpan, cNameLabel.length(), issuedToCNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
// Set the strings to be blue.
domainStringBuilder.setSpan(blueColorSpan, domainLabel.length(), domainStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
issuedToCNameStringBuilder.setSpan(blueColorSpan, cNameLabel.length(), issuedToCNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
issuedToCNameStringBuilder.setSpan(redColorSpan, cNameLabel.length(), issuedToCNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
}
issuedToCNameStringBuilder.setSpan(redColorSpan, cNameLabel.length(), issuedToCNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
}
- // Setup the issued to and issued by spans to display the certificate information in blue. `SPAN_INCLUSIVE_INCLUSIVE` allows the span to grow in either direction.
+ // Set the IP addresses, issued to, and issued by spans to display the certificate information in blue. `SPAN_INCLUSIVE_INCLUSIVE` allows the span to grow in either direction.
+ ipAddressesStringBuilder.setSpan(blueColorSpan, ipAddressesLabel.length(), ipAddressesStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
issuedToONameStringBuilder.setSpan(blueColorSpan, oNameLabel.length(), issuedToONameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
issuedToUNameStringBuilder.setSpan(blueColorSpan, uNameLabel.length(), issuedToUNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
issuedByCNameStringBuilder.setSpan(blueColorSpan, cNameLabel.length(), issuedByCNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
issuedByONameStringBuilder.setSpan(blueColorSpan, oNameLabel.length(), issuedByONameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
issuedByUNameStringBuilder.setSpan(blueColorSpan, uNameLabel.length(), issuedByUNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
issuedToONameStringBuilder.setSpan(blueColorSpan, oNameLabel.length(), issuedToONameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
issuedToUNameStringBuilder.setSpan(blueColorSpan, uNameLabel.length(), issuedToUNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
issuedByCNameStringBuilder.setSpan(blueColorSpan, cNameLabel.length(), issuedByCNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
issuedByONameStringBuilder.setSpan(blueColorSpan, oNameLabel.length(), issuedByONameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
issuedByUNameStringBuilder.setSpan(blueColorSpan, uNameLabel.length(), issuedByUNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
Date currentDate = Calendar.getInstance().getTime();
// Format the start date color. `SPAN_INCLUSIVE_INCLUSIVE` allows the span to grow in either direction.
Date currentDate = Calendar.getInstance().getTime();
// Format the start date color. `SPAN_INCLUSIVE_INCLUSIVE` allows the span to grow in either direction.
issuedToCNameTextView.setText(issuedToCNameStringBuilder);
issuedToONameTextView.setText(issuedToONameStringBuilder);
issuedToUNameTextView.setText(issuedToUNameStringBuilder);
issuedToCNameTextView.setText(issuedToCNameStringBuilder);
issuedToONameTextView.setText(issuedToONameStringBuilder);
issuedToUNameTextView.setText(issuedToUNameStringBuilder);