diff --git a/app/src/main/java/com/emanuelef/remote_capture/activities/prefs/SettingsActivity.java b/app/src/main/java/com/emanuelef/remote_capture/activities/prefs/SettingsActivity.java index af82d697..0fede0e0 100644 --- a/app/src/main/java/com/emanuelef/remote_capture/activities/prefs/SettingsActivity.java +++ b/app/src/main/java/com/emanuelef/remote_capture/activities/prefs/SettingsActivity.java @@ -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); diff --git a/app/src/main/java/com/emanuelef/remote_capture/fragments/prefs/Socks5Settings.java b/app/src/main/java/com/emanuelef/remote_capture/fragments/prefs/Socks5Settings.java new file mode 100644 index 00000000..0223f6b1 --- /dev/null +++ b/app/src/main/java/com/emanuelef/remote_capture/fragments/prefs/Socks5Settings.java @@ -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 . + * + * 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); + } +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0f7af2f5..d02de296 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -120,7 +120,9 @@ Dark Theme SOCKS5 - Redirect all the TCP connections to the specified SOCKS5 proxy + SOCKS5 redirection + Configure the redirection to a SOCKS5 proxy + Redirect all the TCP connections to a SOCKS5 proxy SOCKS5 proxy: %1$s:%2$d Proxy IP address Proxy port diff --git a/app/src/main/res/xml/root_preferences.xml b/app/src/main/res/xml/root_preferences.xml index 6a40393e..46d11a20 100644 --- a/app/src/main/res/xml/root_preferences.xml +++ b/app/src/main/res/xml/root_preferences.xml @@ -100,26 +100,12 @@ app:summary="@string/full_payload_summary" app:defaultValue="false" /> - - - - - + app:fragment="com.emanuelef.remote_capture.fragments.prefs.Socks5Settings" /> @@ -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" /> + + + + + + +