Move SOCKS5 prefs to separate screen

This commit is contained in:
emanuele-f 2023-03-16 11:38:08 +01:00
parent 2b87ca5e0d
commit 3761d3311a
5 changed files with 105 additions and 48 deletions

View File

@ -126,18 +126,16 @@ public class SettingsActivity extends BaseActivity implements PreferenceFragment
}
public static class SettingsFragment extends PreferenceFragmentCompat {
private SwitchPreference mSocks5Enabled;
private SwitchPreference mTlsDecryption;
private SwitchPreference mBlockQuic;
private SwitchPreference mFullPayloadEnabled;
private SwitchPreference mRootCaptureEnabled;
private SwitchPreference mAutoBlockPrivateDNS;
private EditTextPreference mSocks5ProxyIp;
private EditTextPreference mSocks5ProxyPort;
private EditTextPreference mMitmproxyOpts;
private DropDownPreference mIpMode;
private DropDownPreference mCapInterface;
private Preference mVpnExceptions;
private Preference mSocks5Settings;
private Preference mDnsSettings;
private Preference mPortMapping;
private Preference mMitmWizard;
@ -164,7 +162,7 @@ public class SettingsActivity extends BaseActivity implements PreferenceFragment
setupSecurityPrefs();
setupOtherPrefs();
socks5ProxyHideShow(mTlsDecryption.isChecked(), mSocks5Enabled.isChecked(), rootCaptureEnabled());
socks5ProxyHideShow(mTlsDecryption.isChecked(), rootCaptureEnabled());
mBlockQuic.setVisible(!rootCaptureEnabled());
rootCaptureHideShow(rootCaptureEnabled());
@ -308,7 +306,7 @@ public class SettingsActivity extends BaseActivity implements PreferenceFragment
mMitmWizard.setVisible((boolean) newValue);
mMitmproxyOpts.setVisible((boolean) newValue);
socks5ProxyHideShow((boolean) newValue, mSocks5Enabled.isChecked(), rootCaptureEnabled());
socks5ProxyHideShow((boolean) newValue, rootCaptureEnabled());
return true;
});
@ -339,27 +337,11 @@ public class SettingsActivity extends BaseActivity implements PreferenceFragment
return true;
});
mSocks5Enabled = requirePreference(Prefs.PREF_SOCKS5_ENABLED_KEY);
mSocks5Enabled.setOnPreferenceChangeListener((preference, newValue) -> {
socks5ProxyHideShow(mTlsDecryption.isChecked(), (boolean)newValue, rootCaptureEnabled());
return true;
});
/* TLS Proxy IP validation */
mSocks5ProxyIp = requirePreference(Prefs.PREF_SOCKS5_PROXY_IP_KEY);
mSocks5ProxyIp.setOnPreferenceChangeListener((preference, newValue) -> Utils.validateIpAddress(newValue.toString()));
/* TLS Proxy port validation */
mSocks5ProxyPort = requirePreference(Prefs.PREF_SOCKS5_PROXY_PORT_KEY);
mSocks5ProxyPort.setOnBindEditTextListener(editText -> editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED));
mSocks5ProxyPort.setOnPreferenceChangeListener((preference, newValue) -> Utils.validatePort(newValue.toString()));
mSocks5Settings = requirePreference("socks5_settings");
}
private void socks5ProxyHideShow(boolean tlsDecryption, boolean socks5Enabled, boolean rootEnabled) {
boolean available = !tlsDecryption && !rootEnabled;
mSocks5Enabled.setVisible(available);
mSocks5ProxyIp.setVisible(socks5Enabled && available);
mSocks5ProxyPort.setVisible(socks5Enabled && available);
private void socks5ProxyHideShow(boolean tlsDecryption, boolean rootEnabled) {
mSocks5Settings.setVisible(!tlsDecryption && !rootEnabled);
}
private void setupOtherPrefs() {
@ -415,14 +397,12 @@ public class SettingsActivity extends BaseActivity implements PreferenceFragment
private void rootCaptureHideShow(boolean enabled) {
if(enabled) {
mAutoBlockPrivateDNS.setVisible(false);
mSocks5Enabled.setVisible(false);
mSocks5ProxyIp.setVisible(false);
mSocks5ProxyPort.setVisible(false);
mBlockQuic.setVisible(false);
mSocks5Settings.setVisible(false);
} else {
mAutoBlockPrivateDNS.setVisible(true);
mBlockQuic.setVisible(true);
socks5ProxyHideShow(mTlsDecryption.isChecked(), mSocks5Enabled.isChecked(), false);
socks5ProxyHideShow(mTlsDecryption.isChecked(), false);
}
mIpMode.setVisible(!enabled);

View File

@ -0,0 +1,64 @@
/*
* This file is part of PCAPdroid.
*
* PCAPdroid is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PCAPdroid is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PCAPdroid. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2023 - Emanuele Faranda
*/
package com.emanuelef.remote_capture.fragments.prefs;
import android.os.Bundle;
import android.text.InputType;
import androidx.annotation.Nullable;
import androidx.preference.EditTextPreference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.SwitchPreference;
import com.emanuelef.remote_capture.R;
import com.emanuelef.remote_capture.Utils;
import com.emanuelef.remote_capture.model.Prefs;
import java.util.Objects;
public class Socks5Settings extends PreferenceFragmentCompat {
private EditTextPreference mSocks5ProxyIp;
private EditTextPreference mSocks5ProxyPort;
@Override
public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable String rootKey) {
setPreferencesFromResource(R.xml.socks5_preferences, rootKey);
/* SOCKS5 Proxy IP validation */
mSocks5ProxyIp = Objects.requireNonNull(findPreference(Prefs.PREF_SOCKS5_PROXY_IP_KEY));
mSocks5ProxyIp.setOnPreferenceChangeListener((preference, newValue) -> Utils.validateIpAddress(newValue.toString()));
/* SOCKS5 Proxy port validation */
mSocks5ProxyPort = Objects.requireNonNull(findPreference(Prefs.PREF_SOCKS5_PROXY_PORT_KEY));
mSocks5ProxyPort.setOnBindEditTextListener(editText -> editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED));
mSocks5ProxyPort.setOnPreferenceChangeListener((preference, newValue) -> Utils.validatePort(newValue.toString()));
SwitchPreference mSocks5Enabled = Objects.requireNonNull(findPreference(Prefs.PREF_SOCKS5_ENABLED_KEY));
mSocks5Enabled.setOnPreferenceChangeListener((preference, newValue) -> {
toggleVisisiblity((boolean) newValue);
return true;
});
toggleVisisiblity(mSocks5Enabled.isChecked());
}
private void toggleVisisiblity(boolean socks5_enabled) {
mSocks5ProxyIp.setVisible(socks5_enabled);
mSocks5ProxyPort.setVisible(socks5_enabled);
}
}

View File

@ -120,7 +120,9 @@
<string name="theme_dark">Dark</string>
<string name="app_theme">Theme</string>
<string name="socks5_proxy">SOCKS5</string>
<string name="enable_socks5_proxy_summary">Redirect all the TCP connections to the specified SOCKS5 proxy</string>
<string name="socks5_redirection">SOCKS5 redirection</string>
<string name="socks5_summary">Configure the redirection to a SOCKS5 proxy</string>
<string name="enable_socks5_proxy_summary">Redirect all the TCP connections to a SOCKS5 proxy</string>
<string name="socks5_info">SOCKS5 proxy: %1$s:%2$d</string>
<string name="proxy_ip_address">Proxy IP address</string>
<string name="proxy_port">Proxy port</string>

View File

@ -100,26 +100,12 @@
app:summary="@string/full_payload_summary"
app:defaultValue="false" />
<SwitchPreference
app:key="socks5_enabled"
<Preference
android:key="socks5_settings"
app:title="@string/socks5_proxy"
app:summary="@string/socks5_summary"
app:iconSpaceReserved="false"
app:summary="@string/enable_socks5_proxy_summary"
app:defaultValue="false" />
<EditTextPreference
app:key="socks5_proxy_ip_address"
app:title="@string/proxy_ip_address"
app:defaultValue="0.0.0.0"
app:iconSpaceReserved="false"
app:useSimpleSummaryProvider="true" />
<EditTextPreference
app:key="socks5_proxy_port"
app:title="@string/proxy_port"
app:iconSpaceReserved="false"
app:defaultValue="8050"
app:useSimpleSummaryProvider="true" />
app:fragment="com.emanuelef.remote_capture.fragments.prefs.Socks5Settings" />
</PreferenceCategory>
<PreferenceCategory app:title="@string/capture_prefs" app:iconSpaceReserved="false" >
@ -148,7 +134,7 @@
app:title="@string/dns_servers"
app:summary="@string/dns_servers_summary"
app:iconSpaceReserved="false"
app:fragment="com.emanuelef.remote_capture.fragments.DnsSettings" />
app:fragment="com.emanuelef.remote_capture.fragments.prefs.DnsSettings" />
<SwitchPreference
app:key="start_at_boot"

View File

@ -0,0 +1,25 @@
<PreferenceScreen
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<SwitchPreference
app:key="socks5_enabled"
app:title="@string/socks5_redirection"
app:iconSpaceReserved="false"
app:summary="@string/enable_socks5_proxy_summary"
app:defaultValue="false" />
<EditTextPreference
app:key="socks5_proxy_ip_address"
app:title="@string/proxy_ip_address"
app:defaultValue="0.0.0.0"
app:iconSpaceReserved="false"
app:useSimpleSummaryProvider="true" />
<EditTextPreference
app:key="socks5_proxy_port"
app:title="@string/proxy_port"
app:iconSpaceReserved="false"
app:defaultValue="8050"
app:useSimpleSummaryProvider="true" />
</PreferenceScreen>