Refactoring

This commit is contained in:
M66B 2022-08-14 07:51:50 +02:00
parent 77b7426c8e
commit 0002857aff
5 changed files with 22 additions and 19 deletions

View File

@ -645,6 +645,10 @@ public class ApplicationEx extends Application
}
} else if (version < 1947)
editor.putBoolean("accept_unsupported", true);
else if (version < 1951) {
if (prefs.contains("open_unsafe"))
editor.putBoolean("open_safe", !prefs.getBoolean("open_unsafe", true));
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !BuildConfig.DEBUG)
editor.remove("background_service");

View File

@ -673,7 +673,7 @@ public class ConnectionHelper {
static HttpURLConnection openConnectionUnsafe(Context context, URL url, int ctimeout, int rtimeout) throws IOException {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean open_unsafe = prefs.getBoolean("open_unsafe", true);
boolean open_safe = prefs.getBoolean("open_safe", false);
int redirects = 0;
while (true) {
@ -685,7 +685,7 @@ public class ConnectionHelper {
urlConnection.setInstanceFollowRedirects(true);
if (urlConnection instanceof HttpsURLConnection) {
if (open_unsafe)
if (!open_safe)
((HttpsURLConnection) urlConnection).setHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
@ -693,7 +693,7 @@ public class ConnectionHelper {
}
});
} else {
if (!open_unsafe)
if (open_safe)
throw new IOException("https required url=" + url);
}
@ -703,7 +703,7 @@ public class ConnectionHelper {
try {
int status = urlConnection.getResponseCode();
if (open_unsafe &&
if (!open_safe &&
(status == HttpURLConnection.HTTP_MOVED_PERM ||
status == HttpURLConnection.HTTP_MOVED_TEMP ||
status == HttpURLConnection.HTTP_SEE_OTHER ||

View File

@ -79,7 +79,7 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
private SwitchCompat swSslHarden;
private SwitchCompat swSslHardenStrict;
private SwitchCompat swCertStrict;
private SwitchCompat swOpenUnsafe;
private SwitchCompat swOpenSafe;
private Button btnManage;
private TextView tvNetworkMetered;
private TextView tvNetworkRoaming;
@ -94,7 +94,7 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
"download_headers", "download_eml", "download_plain",
"require_validated", "vpn_only",
"timeout", "prefer_ip4", "bind_socket", "standalone_vpn", "tcp_keep_alive",
"ssl_harden", "ssl_harden_strict", "cert_strict", "open_unsafe"
"ssl_harden", "ssl_harden_strict", "cert_strict", "open_safe"
};
@Override
@ -126,7 +126,7 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
swSslHarden = view.findViewById(R.id.swSslHarden);
swSslHardenStrict = view.findViewById(R.id.swSslHardenStrict);
swCertStrict = view.findViewById(R.id.swCertStrict);
swOpenUnsafe = view.findViewById(R.id.swOpenUnsafe);
swOpenSafe = view.findViewById(R.id.swOpenSafe);
btnManage = view.findViewById(R.id.btnManage);
tvNetworkMetered = view.findViewById(R.id.tvNetworkMetered);
@ -309,10 +309,10 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
}
});
swOpenUnsafe.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
swOpenSafe.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("open_unsafe", checked).apply();
prefs.edit().putBoolean("open_safe", checked).apply();
}
});
@ -450,7 +450,7 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
swSslHardenStrict.setChecked(prefs.getBoolean("ssl_harden_strict", false));
swSslHardenStrict.setEnabled(swSslHarden.isChecked());
swCertStrict.setChecked(prefs.getBoolean("cert_strict", !BuildConfig.PLAY_STORE_RELEASE));
swOpenUnsafe.setChecked(prefs.getBoolean("open_unsafe", true));
swOpenSafe.setChecked(prefs.getBoolean("open_safe", false));
}
private static Intent getIntentConnectivity() {

View File

@ -484,28 +484,27 @@
app:layout_constraintTop_toBottomOf="@id/swCertStrict" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swOpenUnsafe"
android:id="@+id/swOpenSafe"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:checked="true"
android:text="@string/title_advanced_open_unsafe"
android:text="@string/title_advanced_open_safe"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvCertStrictHint"
app:switchPadding="12dp" />
<TextView
android:id="@+id/tvOpenUnsafeHint"
android:id="@+id/tvOpenSafeHint"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="48dp"
android:text="@string/title_advanced_open_unsafe_hint"
android:text="@string/title_advanced_open_safe_hint"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swOpenUnsafe" />
app:layout_constraintTop_toBottomOf="@id/swOpenSafe" />
<Button
android:id="@+id/btnManage"
@ -517,7 +516,7 @@
android:drawablePadding="6dp"
android:text="@string/title_advanced_manage_connectivity"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvOpenUnsafeHint" />
app:layout_constraintTop_toBottomOf="@id/tvOpenSafeHint" />
<TextView
android:id="@+id/tvNetworkMetered"

View File

@ -473,7 +473,7 @@
<string name="title_advanced_ssl_harden">Harden SSL connections</string>
<string name="title_advanced_ssl_harden_strict">Require TLS 1.3</string>
<string name="title_advanced_cert_strict">Strict certificate checking</string>
<string name="title_advanced_open_unsafe">Open insecure connections</string>
<string name="title_advanced_open_safe">Open secure connections only</string>
<string name="title_advanced_manage_connectivity">Manage connectivity</string>
<string name="title_advanced_caption_general">General</string>
@ -866,7 +866,7 @@
<string name="title_advanced_timeout_hint">The read/write timeout will be set to the double of the connection timeout. Higher values will result in more battery use.</string>
<string name="title_advanced_cert_strict_hint">Disabling this will relax checking of server certificates</string>
<string name="title_advanced_ssl_harden_hint">Enabling this will disable weak SSL protocols and ciphers, which can lead to connection problems</string>
<string name="title_advanced_open_unsafe_hint">Disabling this will require secure connections to download images</string>
<string name="title_advanced_open_safe_hint">Enabling this will require secure connections to download images, etc</string>
<string name="title_advanced_roaming_hint">Messages headers will always be fetched when roaming. You can use the device\'s roaming setting to disable internet while roaming.</string>
<string name="title_advanced_browse_hint">Fetch more messages when scrolling down</string>