+ // Populate the saved and current IP addresses.
+ savedIpAddressesTextView.setText(savedIpAddresses);
+ currentIpAddressesTextView.setText(DomainsActivity.currentIpAddresses);
+
+ // Set the initial display status of the IP addresses card views.
+ if (pinnedIpAddressesSwitch.isChecked()) { // IP addresses are pinned.
+ // Set the visibility of the saved IP addresses.
+ if (savedIpAddresses == null) { // There are no saved IP addresses.
+ savedIpAddressesCardView.setVisibility(View.GONE);
+ } else { // There are saved IP addresses.
+ savedIpAddressesCardView.setVisibility(View.VISIBLE);
+ }
+
+ // Set the visibility of the current IP addresses.
+ currentIpAddressesCardView.setVisibility(View.VISIBLE);
+
+ // Set the status of the radio buttons and the card view backgrounds.
+ if (savedIpAddressesCardView.getVisibility() == View.VISIBLE) { // The saved IP addresses are displayed.
+ // Check the saved IP addresses radio button.
+ savedIpAddressesRadioButton.setChecked(true);
+
+ // Uncheck the current IP addresses radio button.
+ currentIpAddressesRadioButton.setChecked(false);
+
+ // Darken the background of the current IP addresses linear layout according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ currentIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_33);
+ } else {
+ currentIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_11);
+ }
+ } else { // The saved IP addresses are hidden.
+ // Check the current IP addresses radio button.
+ currentIpAddressesRadioButton.setChecked(true);
+
+ // Uncheck the saved IP addresses radio button.
+ savedIpAddressesRadioButton.setChecked(false);
+ }
+ } else { // IP addresses are not pinned.
+ // Hide the IP addresses card views.
+ savedIpAddressesCardView.setVisibility(View.GONE);
+ currentIpAddressesCardView.setVisibility(View.GONE);
+
+ // Uncheck the radio buttons.
+ savedIpAddressesRadioButton.setChecked(false);
+ currentIpAddressesRadioButton.setChecked(false);
+ }
+
+
+ // Set the JavaScript switch listener.
+ javaScriptSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> {
+ if (isChecked) { // JavaScript is enabled.
+ // Update the JavaScript icon.
+ javaScriptImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.javascript_enabled, null));
+
+ // Enable the DOM storage `Switch`.
+ domStorageSwitch.setEnabled(true);
+
+ // Update the DOM storage icon.
+ if (domStorageSwitch.isChecked()) { // DOM storage is enabled.
+ domStorageImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.dom_storage_enabled, null));
+ } else { // DOM storage is disabled.
+ // Set the icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ domStorageImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.dom_storage_disabled_night, null));
+ } else {
+ domStorageImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.dom_storage_disabled_day, null));
+ }
+ }
+ } else { // JavaScript is disabled.
+ // Update the JavaScript icon.
+ javaScriptImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.privacy_mode, null));
+
+ // Disable the DOM storage `Switch`.
+ domStorageSwitch.setEnabled(false);
+
+ // Set the DOM storage icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ domStorageImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.dom_storage_ghosted_night, null));
+ } else {
+ domStorageImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.dom_storage_ghosted_day, null));
+ }
+ }
+ });
+
+ // Set the cookies switch listener.
+ cookiesSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> {
+ if (isChecked) { // Cookies are enabled.
+ // Update the cookies icon.
+ cookiesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.cookies_enabled, null));
+ } else { // Cookies are disabled.
+ // Update the cookies icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
+ cookiesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.cookies_disabled_day, null));
+ } else {
+ cookiesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.cookies_disabled_night, null));
+ }
+ }
+ });
+
+ // Set the DOM Storage switch listener.
+ domStorageSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> {
+ // Update the icon.
+ if (isChecked) {
+ domStorageImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.dom_storage_enabled, null));
+ } else {
+ // Set the icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ domStorageImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.dom_storage_disabled_night, null));
+ } else {
+ domStorageImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.dom_storage_disabled_day, null));
+ }
+ }
+ });
+
+ // Set the form data switch listener. It can be removed once the minimum API >= 26.
+ if (Build.VERSION.SDK_INT < 26) {
+ formDataSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> {
+ // Update the icon.
+ if (isChecked) {
+ formDataImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.form_data_enabled, null));
+ } else {
+ // Set the icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ formDataImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.form_data_disabled_night, null));
+ } else {
+ formDataImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.form_data_disabled_day, null));
+ }
+ }
+ });
+ }
+
+ // Set the EasyList switch listener.
+ easyListSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> {
+ // Update the icon.
+ if (isChecked) { // EasyList is on.
+ // Set the icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ easyListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_enabled_night, null));
+ } else {
+ easyListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_enabled_day, null));
+ }
+ } else { // EasyList is off.
+ // Set the icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ easyListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_disabled_night, null));
+ } else {
+ easyListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_disabled_day, null));
+ }
+ }
+ });
+
+ // Set the EasyPrivacy switch listener.
+ easyPrivacySwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> {
+ // Update the icon.
+ if (isChecked) { // EasyPrivacy is on.
+ // Set the icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ easyPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_enabled_night, null));
+ } else {
+ easyPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_enabled_day, null));
+ }
+ } else { // EasyPrivacy is off.
+ // Set the icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ easyPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_disabled_night, null));
+ } else {
+ easyPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_disabled_day, null));
+ }
+ }
+ });
+
+ // Set the Fanboy's Annoyance List switch listener.
+ fanboysAnnoyanceListSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> {
+ // Update the icon and Fanboy's Social Blocking List.
+ if (isChecked) { // Fanboy's Annoyance List is on.
+ // Set the icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ fanboysAnnoyanceListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_enabled_night, null));
+ } else {
+ fanboysAnnoyanceListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_enabled_day, null));
+ }
+
+ // Disable the Fanboy's Social Blocking List switch.
+ fanboysSocialBlockingListSwitch.setEnabled(false);
+
+ // Update the Fanboy's Social Blocking List icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ fanboysSocialBlockingListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_ghosted_night, null));
+ } else {
+ fanboysSocialBlockingListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_ghosted_day, null));
+ }
+ } else { // Fanboy's Annoyance List is off.
+ // Set the icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ fanboysAnnoyanceListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_disabled_night, null));
+ } else {
+ fanboysAnnoyanceListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_disabled_day, null));
+ }
+
+ // Enable the Fanboy's Social Blocking List switch.
+ fanboysSocialBlockingListSwitch.setEnabled(true);
+
+ // Update the Fanboy's Social Blocking List icon.
+ if (fanboysSocialBlockingListSwitch.isChecked()) { // Fanboy's Social Blocking List is on.
+ // Update the icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ fanboysSocialBlockingListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_enabled_night, null));
+ } else {
+ fanboysSocialBlockingListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_enabled_day, null));
+ }
+ } else { // Fanboy's Social Blocking List is off.
+ // Update the icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ fanboysSocialBlockingListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_disabled_night, null));
+ } else {
+ fanboysSocialBlockingListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_disabled_day, null));
+ }
+ }
+ }
+
+ });
+
+ // Set the Fanboy's Social Blocking List switch listener.
+ fanboysSocialBlockingListSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> {
+ // Update the icon.
+ if (isChecked) { // Fanboy's Social Blocking List is on.
+ // Set the icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ fanboysSocialBlockingListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_enabled_night, null));
+ } else {
+ fanboysSocialBlockingListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_enabled_day, null));
+ }
+ } else { // Fanboy's Social Blocking List is off.
+ // Set the icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ fanboysSocialBlockingListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_disabled_night, null));
+ } else {
+ fanboysSocialBlockingListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_disabled_day, null));
+ }
+ }
+ });
+
+ // Set the UltraList switch listener.
+ ultraListSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> {
+ // Update the icon.
+ if (isChecked) { // UltraList is on.
+ // Set the icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ ultraListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_enabled_night, null));
+ } else {
+ ultraListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_enabled_day, null));
+ }
+ } else { // UltraList is off.
+ // Set the icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ ultraListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_disabled_night, null));
+ } else {
+ ultraListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_disabled_day, null));
+ }
+ }
+ });
+
+ // Set the UltraPrivacy switch listener.
+ ultraPrivacySwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> {
+ // Update the icon.
+ if (isChecked) { // UltraPrivacy is on.
+ // Set the icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ ultraPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_enabled_night, null));
+ } else {
+ ultraPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_enabled_day, null));
+ }
+ } else { // UltraPrivacy is off.
+ // Set the icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ ultraPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_disabled_night, null));
+ } else {
+ ultraPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_disabled_day, null));
+ }
+ }
+ });
+
+ // Set the block all third-party requests switch listener.
+ blockAllThirdPartyRequestsSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> {
+ // Update the icon.
+ if (isChecked) { // Blocking all third-party requests is on.
+ // Set the icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ blockAllThirdPartyRequestsImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_all_third_party_requests_enabled_night, null));
+ } else {
+ blockAllThirdPartyRequestsImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_all_third_party_requests_enabled_day, null));
+ }
+ } else { // Blocking all third-party requests is off.
+ // Set the icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ blockAllThirdPartyRequestsImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_all_third_party_requests_disabled_night, null));
+ } else {
+ blockAllThirdPartyRequestsImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_all_third_party_requests_disabled_day, null));
+ }
+ }
+ });
+
+ // Set the user agent spinner listener.
+ userAgentSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
+ @Override
+ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
+ // Set the new user agent.
+ switch (position) {
+ case MainWebViewActivity.DOMAINS_SYSTEM_DEFAULT_USER_AGENT:
+ // Show the user agent TextView.
+ userAgentTextView.setVisibility(View.VISIBLE);
+
+ // Hide the custom user agent EditText.
+ customUserAgentEditText.setVisibility(View.GONE);
+
+ // Set the user text.
+ switch (defaultUserAgentArrayPosition) {
+ case MainWebViewActivity.UNRECOGNIZED_USER_AGENT: // The default user agent name is not on the canonical list.
+ // This is probably because it was set in an older version of Privacy Browser before the switch to persistent user agent names.
+ userAgentTextView.setText(defaultUserAgentName);
+ break;
+
+ case MainWebViewActivity.SETTINGS_WEBVIEW_DEFAULT_USER_AGENT:
+ // Display the `WebView` default user agent.
+ userAgentTextView.setText(webViewDefaultUserAgentString);
+ break;
+
+ case MainWebViewActivity.SETTINGS_CUSTOM_USER_AGENT:
+ // Display the custom user agent.
+ userAgentTextView.setText(defaultCustomUserAgentString);
+ break;
+
+ default:
+ // Get the user agent string from the user agent data array.
+ userAgentTextView.setText(userAgentDataArray[defaultUserAgentArrayPosition]);
+ }
+ break;
+
+ case MainWebViewActivity.DOMAINS_WEBVIEW_DEFAULT_USER_AGENT:
+ // Show the user agent TextView and set the text.
+ userAgentTextView.setVisibility(View.VISIBLE);
+ userAgentTextView.setText(webViewDefaultUserAgentString);
+
+ // Hide the custom user agent EditTex.
+ customUserAgentEditText.setVisibility(View.GONE);
+ break;
+
+ case MainWebViewActivity.DOMAINS_CUSTOM_USER_AGENT:
+ // Hide the user agent TextView.
+ userAgentTextView.setVisibility(View.GONE);
+
+ // Show the custom user agent EditText and set the current user agent name as the text.
+ customUserAgentEditText.setVisibility(View.VISIBLE);
+ customUserAgentEditText.setText(currentUserAgentName);
+ break;
+
+ default:
+ // Show the user agent TextView and set the text from the user agent data array, which has one less entry than the spinner, so the position must be decremented.
+ userAgentTextView.setVisibility(View.VISIBLE);
+ userAgentTextView.setText(userAgentDataArray[position - 1]);
+
+ // Hide `customUserAgentEditText`.
+ customUserAgentEditText.setVisibility(View.GONE);
+ }
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView<?> parent) {
+ // Do nothing.
+ }
+ });
+
+ // Set the font size spinner listener.
+ fontSizeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
+ @Override
+ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
+ // Update the font size display options.
+ if (position == 0) { // The system default font size has been selected.
+ // Show the default font size text view.
+ defaultFontSizeTextView.setVisibility(View.VISIBLE);
+
+ // Hide the custom font size edit text.
+ customFontSizeEditText.setVisibility(View.GONE);
+ } else { // A custom font size has been selected.
+ // Hide the default font size text view.
+ defaultFontSizeTextView.setVisibility(View.GONE);
+
+ // Show the custom font size edit text.
+ customFontSizeEditText.setVisibility(View.VISIBLE);
+ }
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView<?> parent) {
+ // Do nothing.
+ }
+ });
+
+ // Set the swipe to refresh spinner listener.
+ swipeToRefreshSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
+ @Override
+ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
+ // Update the icon and the visibility of `nightModeTextView`. Once the minimum API >= 21 a selector can be used as the tint mode instead of specifying different icons.
+ switch (position) {
+ case DomainsDatabaseHelper.SYSTEM_DEFAULT:
+ if (defaultSwipeToRefresh) { // Swipe to refresh enabled by default.
+ // Set the icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ swipeToRefreshImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.refresh_enabled_night, null));
+ } else {
+ swipeToRefreshImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.refresh_enabled_day, null));
+ }
+ } else { // Swipe to refresh disabled by default.
+ // Set the icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ swipeToRefreshImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.refresh_disabled_night, null));
+ } else {
+ swipeToRefreshImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.refresh_disabled_day, null));
+ }
+ }
+
+ // Show the swipe to refresh TextView.
+ swipeToRefreshTextView.setVisibility(View.VISIBLE);
+ break;
+
+ case DomainsDatabaseHelper.ENABLED:
+ // Set the icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ swipeToRefreshImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.refresh_enabled_night, null));
+ } else {
+ swipeToRefreshImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.refresh_enabled_day, null));
+ }
+
+ // Hide the swipe to refresh TextView.
+ swipeToRefreshTextView.setVisibility(View.GONE);
+ break;
+
+ case DomainsDatabaseHelper.DISABLED:
+ // Set the icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ swipeToRefreshImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.refresh_disabled_night, null));
+ } else {
+ swipeToRefreshImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.refresh_disabled_day, null));
+ }
+
+ // Hide the swipe to refresh TextView.
+ swipeToRefreshTextView.setVisibility(View.GONE);
+ }
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView<?> parent) {
+ // Do nothing.
+ }
+ });
+
+ // Set the WebView theme spinner listener.
+ webViewThemeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
+ @Override
+ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
+ // Update the icon and the visibility of the WebView theme text view. Once the minimum API >= 21 a selector can be used as the tint mode instead of specifying different icons.
+ switch (position) {
+ case DomainsDatabaseHelper.SYSTEM_DEFAULT: // the domain WebView theme is system default.
+ // Set the icon according to the app WebView theme.
+ switch (appWebViewThemeEntryNumber) {
+ case DomainsDatabaseHelper.SYSTEM_DEFAULT: // The default WebView theme is system default.
+ // Set the icon according to the app theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
+ // Set the light mode icon.
+ webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_light_theme_day, null));
+ } else {
+ // Set the dark theme icon.
+ webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_dark_theme_night, null));
+ }
+ break;
+
+ case DomainsDatabaseHelper.LIGHT_THEME: // The default WebView theme is light.
+ // Set the icon according to the app theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
+ webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_light_theme_day, null));
+ } else {
+ webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_light_theme_night, null));
+ }
+ break;
+
+ case DomainsDatabaseHelper.DARK_THEME: // The default WebView theme is dark.
+ // Set the icon according to the app theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
+ webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_dark_theme_day, null));
+ } else {
+ webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_dark_theme_night, null));
+ }
+ break;
+ }
+
+ // Show the WebView theme text view.
+ webViewThemeTextView.setVisibility(View.VISIBLE);
+ break;
+
+ case DomainsDatabaseHelper.LIGHT_THEME: // The domain WebView theme is light.
+ // Set the icon according to the app theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
+ webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_light_theme_day, null));
+ } else {
+ webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_light_theme_night, null));
+ }
+
+ // Hide the WebView theme text view.
+ webViewThemeTextView.setVisibility(View.GONE);
+ break;
+
+ case DomainsDatabaseHelper.DARK_THEME: // The domain WebView theme is dark.
+ // Set the icon according to the app theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
+ webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_dark_theme_day, null));
+ } else {
+ webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_dark_theme_night, null));
+ }
+
+ // Hide the WebView theme text view.
+ webViewThemeTextView.setVisibility(View.GONE);
+ break;
+ }
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView<?> parent) {
+ // Do nothing.
+ }
+ });
+
+ // Set the wide viewport spinner listener.
+ wideViewportSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
+ @Override
+ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
+ // Update the icon and the visibility of the wide viewport text view.
+ switch (position) {
+ case DomainsDatabaseHelper.SYSTEM_DEFAULT:
+ if (defaultWideViewport) { // Wide viewport is enabled by default.
+ // Set the icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_enabled_night, null));
+ } else {
+ wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_enabled_day, null));
+ }
+ } else { // Wide viewport is disabled by default.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_disabled_night, null));
+ } else {
+ wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_disabled_day, null));
+ }
+ }
+
+ // Show the wide viewport text view.
+ wideViewportTextView.setVisibility(View.VISIBLE);
+ break;
+
+ case DomainsDatabaseHelper.ENABLED:
+ // Set the icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_enabled_night, null));
+ } else {
+ wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_enabled_day, null));
+ }
+
+ // Hide the wide viewport text view.
+ wideViewportTextView.setVisibility(View.GONE);
+ break;
+
+ case DomainsDatabaseHelper.DISABLED:
+ // Set the icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_disabled_night, null));
+ } else {
+ wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_disabled_day, null));
+ }
+
+ // Hid ethe wide viewport text view.
+ wideViewportTextView.setVisibility(View.GONE);
+ break;
+ }
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView<?> parent) {
+ // Do nothing.
+ }
+ });
+
+ // Set the display webpage images spinner listener.
+ displayWebpageImagesSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
+ @Override
+ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
+ // Update the icon and the visibility of the display images text view.
+ switch (position) {
+ case DomainsDatabaseHelper.SYSTEM_DEFAULT:
+ if (defaultDisplayWebpageImages) { // Display webpage images is enabled by default.
+ // Set the icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_enabled_night, null));
+ } else {
+ displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_enabled_day, null));
+ }
+ } else { // Display webpage images is disabled by default.
+ // Set the icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_disabled_night, null));
+ } else {
+ displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_disabled_day, null));
+ }
+ }
+
+ // Show the display images text view.
+ displayImagesTextView.setVisibility(View.VISIBLE);
+ break;
+
+ case DomainsDatabaseHelper.ENABLED:
+ // Set the icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_enabled_night, null));
+ } else {
+ displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_enabled_day, null));
+ }
+
+ // Hide the display images text view.
+ displayImagesTextView.setVisibility(View.GONE);
+ break;
+
+ case DomainsDatabaseHelper.DISABLED:
+ // Set the icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_disabled_night, null));
+ } else {
+ displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_disabled_day, null));
+ }
+
+ // Hide the display images text view.
+ displayImagesTextView.setVisibility(View.GONE);
+ break;
+ }
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView<?> parent) {
+ // Do nothing.
+ }
+ });
+
+ // Set the pinned SSL certificate switch listener.
+ pinnedSslCertificateSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> {
+ // Update the icon.
+ if (isChecked) { // SSL certificate pinning is enabled.
+ // Set the icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ pinnedSslCertificateImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_enabled_night, null));
+ } else {
+ pinnedSslCertificateImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_enabled_day, null));
+ }
+
+ // Update the visibility of the saved SSL certificate.
+ if (savedSslIssuedToCNameString == null) {
+ savedSslCardView.setVisibility(View.GONE);
+ } else {
+ savedSslCardView.setVisibility(View.VISIBLE);
+ }
+
+ // Update the visibility of the current website SSL certificate.
+ if (DomainsActivity.sslIssuedToCName == null) {
+ // Hide the SSL certificate.
+ currentSslCardView.setVisibility(View.GONE);
+
+ // Show the instruction.
+ noCurrentWebsiteCertificateTextView.setVisibility(View.VISIBLE);
+ } else {
+ // Show the SSL certificate.
+ currentSslCardView.setVisibility(View.VISIBLE);
+
+ // Hide the instruction.
+ noCurrentWebsiteCertificateTextView.setVisibility(View.GONE);
+ }
+
+ // Set the status of the radio buttons.
+ if (savedSslCardView.getVisibility() == View.VISIBLE) { // The saved SSL certificate is displayed.
+ // Check the saved SSL certificate radio button.
+ savedSslCertificateRadioButton.setChecked(true);
+
+ // Uncheck the current website SSL certificate radio button.
+ currentWebsiteCertificateRadioButton.setChecked(false);
+
+ // Set the background of the saved SSL certificate linear layout to be transparent.
+ savedSslCertificateLinearLayout.setBackgroundResource(R.color.transparent);
+
+ // Darken the background of the current website SSL certificate linear layout according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_33);
+ } else {
+ currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_11);
+ }
+
+ // Scroll to the current website SSL certificate card.
+ savedSslCardView.getParent().requestChildFocus(savedSslCardView, savedSslCardView);
+ } else if (currentSslCardView.getVisibility() == View.VISIBLE) { // The saved SSL certificate is hidden but the current website SSL certificate is visible.
+ // Check the current website SSL certificate radio button.
+ currentWebsiteCertificateRadioButton.setChecked(true);
+
+ // Uncheck the saved SSL certificate radio button.
+ savedSslCertificateRadioButton.setChecked(false);
+
+ // Set the background of the current website SSL certificate linear layout to be transparent.
+ currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.transparent);
+
+ // Darken the background of the saved SSL certificate linear layout according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ savedSslCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_33);
+ } else {
+ savedSslCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_11);
+ }
+
+ // Scroll to the current website SSL certificate card.
+ currentSslCardView.getParent().requestChildFocus(currentSslCardView, currentSslCardView);
+ } else { // Neither SSL certificate is visible.
+ // Uncheck both radio buttons.
+ savedSslCertificateRadioButton.setChecked(false);
+ currentWebsiteCertificateRadioButton.setChecked(false);
+
+ // Scroll to the current website SSL certificate card.
+ noCurrentWebsiteCertificateTextView.getParent().requestChildFocus(noCurrentWebsiteCertificateTextView, noCurrentWebsiteCertificateTextView);
+ }
+ } else { // SSL certificate pinning is disabled.
+ // Set the icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ pinnedSslCertificateImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_disabled_night, null));
+ } else {
+ pinnedSslCertificateImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_disabled_day, null));
+ }
+
+ // Hide the SSl certificates and instructions.
+ savedSslCardView.setVisibility(View.GONE);
+ currentSslCardView.setVisibility(View.GONE);
+ noCurrentWebsiteCertificateTextView.setVisibility(View.GONE);
+
+ // Uncheck the radio buttons.
+ savedSslCertificateRadioButton.setChecked(false);
+ currentWebsiteCertificateRadioButton.setChecked(false);
+ }
+ });
+
+ savedSslCardView.setOnClickListener((View view) -> {
+ // Check the saved SSL certificate radio button.
+ savedSslCertificateRadioButton.setChecked(true);
+
+ // Uncheck the current website SSL certificate radio button.
+ currentWebsiteCertificateRadioButton.setChecked(false);
+
+ // Set the background of the saved SSL certificate linear layout to be transparent.
+ savedSslCertificateLinearLayout.setBackgroundResource(R.color.transparent);
+
+ // Darken the background of the current website SSL certificate linear layout according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_33);
+ } else {
+ currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_11);
+ }
+ });
+
+ savedSslCertificateRadioButton.setOnClickListener((View view) -> {
+ // Check the saved SSL certificate radio button.
+ savedSslCertificateRadioButton.setChecked(true);
+
+ // Uncheck the current website SSL certificate radio button.
+ currentWebsiteCertificateRadioButton.setChecked(false);
+
+ // Set the background of the saved SSL certificate linear layout to be transparent.
+ savedSslCertificateLinearLayout.setBackgroundResource(R.color.transparent);
+
+ // Darken the background of the current website SSL certificate linear layout according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_33);
+ } else {
+ currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_11);
+ }
+ });
+
+ currentSslCardView.setOnClickListener((View view) -> {
+ // Check the current website SSL certificate radio button.
+ currentWebsiteCertificateRadioButton.setChecked(true);
+
+ // Uncheck the saved SSL certificate radio button.
+ savedSslCertificateRadioButton.setChecked(false);
+
+ // Set the background of the current website SSL certificate linear layout to be transparent.
+ currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.transparent);
+
+ // Darken the background of the saved SSL certificate linear layout according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ savedSslCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_33);
+ } else {
+ savedSslCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_11);
+ }
+ });
+
+ currentWebsiteCertificateRadioButton.setOnClickListener((View view) -> {
+ // Check the current website SSL certificate radio button.
+ currentWebsiteCertificateRadioButton.setChecked(true);
+
+ // Uncheck the saved SSL certificate radio button.
+ savedSslCertificateRadioButton.setChecked(false);
+
+ // Set the background of the current website SSL certificate linear layout to be transparent.
+ currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.transparent);
+
+ // Darken the background of the saved SSL certificate linear layout according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ savedSslCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_33);
+ } else {
+ savedSslCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_11);
+ }
+ });
+
+ // Set the pinned IP addresses switch listener.
+ pinnedIpAddressesSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> {
+ // Update the icon.
+ if (isChecked) { // IP addresses pinning is enabled.
+ // Set the icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ pinnedIpAddressesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_enabled_night, null));
+ } else {
+ pinnedIpAddressesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_enabled_day, null));
+ }
+
+ // Update the visibility of the saved IP addresses card view.
+ if (savedIpAddresses == null) { // There are no saved IP addresses.
+ savedIpAddressesCardView.setVisibility(View.GONE);
+ } else { // There are saved IP addresses.
+ savedIpAddressesCardView.setVisibility(View.VISIBLE);
+ }
+
+ // Show the current IP addresses card view.
+ currentIpAddressesCardView.setVisibility(View.VISIBLE);
+
+ // Set the status of the radio buttons.
+ if (savedIpAddressesCardView.getVisibility() == View.VISIBLE) { // The saved IP addresses are visible.
+ // Check the saved IP addresses radio button.
+ savedIpAddressesRadioButton.setChecked(true);
+
+ // Uncheck the current IP addresses radio button.
+ currentIpAddressesRadioButton.setChecked(false);
+
+ // Set the background of the saved IP addresses linear layout to be transparent.
+ savedSslCertificateLinearLayout.setBackgroundResource(R.color.transparent);
+
+ // Darken the background of the current IP addresses linear layout according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ currentIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_33);
+ } else {
+ currentIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_11);
+ }
+ } else { // The saved IP addresses are not visible.
+ // Check the current IP addresses radio button.
+ currentIpAddressesRadioButton.setChecked(true);
+
+ // Uncheck the saved IP addresses radio button.
+ savedIpAddressesRadioButton.setChecked(false);
+
+ // Set the background of the current IP addresses linear layout to be transparent.
+ currentIpAddressesLinearLayout.setBackgroundResource(R.color.transparent);
+
+ // Darken the background of the saved IP addresses linear layout according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ savedIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_33);
+ } else {
+ savedIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_11);
+ }
+ }
+
+ // Scroll to the bottom of the card views.
+ currentIpAddressesCardView.getParent().requestChildFocus(currentIpAddressesCardView, currentIpAddressesCardView);
+ } else { // IP addresses pinning is disabled.
+ // Set the icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ pinnedIpAddressesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_disabled_night, null));
+ } else {
+ pinnedIpAddressesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_disabled_day, null));
+ }
+
+ // Hide the IP addresses card views.
+ savedIpAddressesCardView.setVisibility(View.GONE);
+ currentIpAddressesCardView.setVisibility(View.GONE);
+
+ // Uncheck the radio buttons.
+ savedIpAddressesRadioButton.setChecked(false);
+ currentIpAddressesRadioButton.setChecked(false);
+ }
+ });
+
+ savedIpAddressesCardView.setOnClickListener((View view) -> {
+ // Check the saved IP addresses radio button.
+ savedIpAddressesRadioButton.setChecked(true);
+
+ // Uncheck the current website IP addresses radio button.
+ currentIpAddressesRadioButton.setChecked(false);
+
+ // Set the background of the saved IP addresses linear layout to be transparent.
+ savedIpAddressesLinearLayout.setBackgroundResource(R.color.transparent);
+
+ // Darken the background of the current IP addresses linear layout according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ currentIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_33);
+ } else {
+ currentIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_11);
+ }
+ });
+
+ savedIpAddressesRadioButton.setOnClickListener((View view) -> {
+ // Check the saved IP addresses radio button.
+ savedIpAddressesRadioButton.setChecked(true);
+
+ // Uncheck the current website IP addresses radio button.
+ currentIpAddressesRadioButton.setChecked(false);
+
+ // Set the background of the saved IP addresses linear layout to be transparent.
+ savedIpAddressesLinearLayout.setBackgroundResource(R.color.transparent);
+
+ // Darken the background of the current IP addresses linear layout according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ currentIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_33);
+ } else {
+ currentIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_11);
+ }
+ });
+
+ currentIpAddressesCardView.setOnClickListener((View view) -> {
+ // Check the current IP addresses radio button.
+ currentIpAddressesRadioButton.setChecked(true);
+
+ // Uncheck the saved IP addresses radio button.
+ savedIpAddressesRadioButton.setChecked(false);
+
+ // Set the background of the current IP addresses linear layout to be transparent.
+ currentIpAddressesLinearLayout.setBackgroundResource(R.color.transparent);
+
+ // Darken the background of the saved IP addresses linear layout according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ savedIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_33);
+ } else {
+ savedIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_11);
+ }
+ });
+
+ currentIpAddressesRadioButton.setOnClickListener((View view) -> {
+ // Check the current IP addresses radio button.
+ currentIpAddressesRadioButton.setChecked(true);
+
+ // Uncheck the saved IP addresses radio button.
+ savedIpAddressesRadioButton.setChecked(false);
+
+ // Set the background of the current IP addresses linear layout to be transparent.
+ currentIpAddressesLinearLayout.setBackgroundResource(R.color.transparent);
+
+ // Darken the background of the saved IP addresses linear layout according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ savedIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_33);
+ } else {
+ savedIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_11);
+ }
+ });
+
+ // Set the scroll Y.
+ domainSettingsScrollView.post(() -> domainSettingsScrollView.setScrollY(scrollY));
+
+ // Return the domain settings view.
+ return domainSettingsView;
+ }
+
+ private boolean checkDomainNameAgainstCertificate(String domainName, String certificateCommonName) {
+ // Initialize `domainNamesMatch`.
+ boolean domainNamesMatch = false;
+
+ // Check various wildcard permutations if `domainName` and `certificateCommonName` are not empty.
+ // `noinspection ConstantCondition` removes Android Studio's incorrect lint warning that `domainName` can never be `null`.
+ if ((domainName != null) && (certificateCommonName != null)) {
+ // Check if the domains match.
+ if (domainName.equals(certificateCommonName)) {
+ domainNamesMatch = true;
+ }
+
+ // If `domainName` starts with a wildcard, check the base domain against all the subdomains of `certificateCommonName`.
+ if (!domainNamesMatch && domainName.startsWith("*.") && (domainName.length() > 2)) {
+ // Remove the initial `*.`.
+ String baseDomainName = domainName.substring(2);
+
+ // Setup a copy of `certificateCommonName` to test subdomains.
+ String certificateCommonNameSubdomain = certificateCommonName;
+
+ // Check all the subdomains in `certificateCommonNameSubdomain` against `baseDomainName`.
+ while (!domainNamesMatch && certificateCommonNameSubdomain.contains(".")) { // Stop checking if we know that `domainNamesMatch` is `true` or if we run out of `.`.
+ // Test the `certificateCommonNameSubdomain` against `baseDomainName`.
+ if (certificateCommonNameSubdomain.equals(baseDomainName)) {
+ domainNamesMatch = true;
+ }
+
+ // Strip out the lowest subdomain of `certificateCommonNameSubdomain`.
+ try {
+ certificateCommonNameSubdomain = certificateCommonNameSubdomain.substring(certificateCommonNameSubdomain.indexOf(".") + 1);
+ } catch (IndexOutOfBoundsException e) { // `certificateCommonNameSubdomain` ends with `.`.
+ certificateCommonNameSubdomain = "";
+ }
+ }
+ }
+
+ // If `certificateCommonName` starts with a wildcard, check the base common name against all the subdomains of `domainName`.
+ if (!domainNamesMatch && certificateCommonName.startsWith("*.") && (certificateCommonName.length() > 2)) {
+ // Remove the initial `*.`.
+ String baseCertificateCommonName = certificateCommonName.substring(2);
+
+ // Setup a copy of `domainName` to test subdomains.
+ String domainNameSubdomain = domainName;
+
+ // Check all the subdomains in `domainNameSubdomain` against `baseCertificateCommonName`.
+ while (!domainNamesMatch && domainNameSubdomain.contains(".") && (domainNameSubdomain.length() > 2)) {
+ // Test the `domainNameSubdomain` against `baseCertificateCommonName`.
+ if (domainNameSubdomain.equals(baseCertificateCommonName)) {
+ domainNamesMatch = true;
+ }
+
+ // Strip out the lowest subdomain of `domainNameSubdomain`.
+ try {
+ domainNameSubdomain = domainNameSubdomain.substring(domainNameSubdomain.indexOf(".") + 1);
+ } catch (IndexOutOfBoundsException e) { // `domainNameSubdomain` ends with `.`.
+ domainNameSubdomain = "";
+ }
+ }
+ }
+
+ // If both names start with a wildcard, check if the root of one contains the root of the other.
+ if (!domainNamesMatch && domainName.startsWith("*.") && (domainName.length() > 2) && certificateCommonName.startsWith("*.") && (certificateCommonName.length() > 2)) {
+ // Remove the wildcards.
+ String rootDomainName = domainName.substring(2);
+ String rootCertificateCommonName = certificateCommonName.substring(2);
+
+ // Check if one name ends with the contents of the other. If so, there will be overlap in the their wildcard subdomains.
+ if (rootDomainName.endsWith(rootCertificateCommonName) || rootCertificateCommonName.endsWith(rootDomainName)) {
+ domainNamesMatch = true;
+ }
+ }
+ }
+
+ return domainNamesMatch;