diff options
Diffstat (limited to 'main')
| -rwxr-xr-x | main/src/main/res/values/strings.xml | 1 | ||||
| -rw-r--r-- | main/src/ui/java/de/blinkt/openvpn/fragments/GeneralSettings.java | 156 | 
2 files changed, 85 insertions, 72 deletions
| diff --git a/main/src/main/res/values/strings.xml b/main/src/main/res/values/strings.xml index 59a443d5..ca7cd0bf 100755 --- a/main/src/main/res/values/strings.xml +++ b/main/src/main/res/values/strings.xml @@ -496,5 +496,6 @@      <string name="as_servername">AS servername</string>      <string name="request_autologin">Request autologin profile</string>      <string name="import_from_as">Import Profile from Access Server</string> +    <string name="no_default_vpn_set">Default VPN not set. Please set the Default VPN before enabling this option.</string>  </resources> diff --git a/main/src/ui/java/de/blinkt/openvpn/fragments/GeneralSettings.java b/main/src/ui/java/de/blinkt/openvpn/fragments/GeneralSettings.java index 1d8b5f77..35179f87 100644 --- a/main/src/ui/java/de/blinkt/openvpn/fragments/GeneralSettings.java +++ b/main/src/ui/java/de/blinkt/openvpn/fragments/GeneralSettings.java @@ -18,6 +18,7 @@ import android.content.pm.PackageManager;  import android.content.pm.PackageManager.NameNotFoundException;  import android.os.Build;  import android.os.Bundle; +import android.widget.Toast;  import androidx.preference.CheckBoxPreference; @@ -91,96 +92,107 @@ public class GeneralSettings extends PreferenceFragmentCompat implements Prefere              ovpn3.setChecked(false);          } +        ((CheckBoxPreference)findPreference("restartvpnonboot")).setOnPreferenceChangeListener((pref, newValue) -> { +            if (newValue.equals(true)) { +                VpnProfile vpn = ProfileManager.getAlwaysOnVPN(requireActivity()); +                if (vpn == null) { +                    Toast.makeText(requireContext(), R.string.no_default_vpn_set, Toast.LENGTH_LONG).show(); +                    return false; +                } -        setClearApiSummary(); -    } +            } +            return true; +        }); +            setClearApiSummary(); +        } -    @Override -    public void onResume() { -        super.onResume(); +        @Override +        public void onResume () { +            super.onResume(); -        VpnProfile vpn = ProfileManager.getAlwaysOnVPN(getActivity()); -        StringBuffer sb = new StringBuffer(getString(R.string.defaultvpnsummary)); -        sb.append('\n'); -        if (vpn == null) -            sb.append(getString(R.string.novpn_selected)); -        else -            sb.append(getString(R.string.vpnselected, vpn.getName())); -        mAlwaysOnVPN.setSummary(sb.toString()); -    } +            VpnProfile vpn = ProfileManager.getAlwaysOnVPN(getActivity()); +            StringBuffer sb = new StringBuffer(getString(R.string.defaultvpnsummary)); +            sb.append('\n'); +            if (vpn == null) +                sb.append(getString(R.string.novpn_selected)); +            else +                sb.append(getString(R.string.vpnselected, vpn.getName())); +            mAlwaysOnVPN.setSummary(sb.toString()); -    @Override -    public boolean onPreferenceChange(Preference preference, Object newValue) { -        if (preference == mAlwaysOnVPN) { -            VpnProfile vpn = ProfileManager.get(getActivity(), (String) newValue); -            mAlwaysOnVPN.setSummary(vpn.getName());          } -        return true; -    } -    private void setClearApiSummary() { -        Preference clearapi = findPreference("clearapi"); - -        if (mExtapp.getExtAppList().isEmpty()) { -            clearapi.setEnabled(false); -            clearapi.setSummary(R.string.no_external_app_allowed); -        } else { -            clearapi.setEnabled(true); -            clearapi.setSummary(getString(R.string.allowed_apps, getExtAppList(", "))); +        @Override +        public boolean onPreferenceChange (Preference preference, Object newValue){ +            if (preference == mAlwaysOnVPN) { +                VpnProfile vpn = ProfileManager.get(getActivity(), (String) newValue); +                mAlwaysOnVPN.setSummary(vpn.getName()); +            } +            return true;          } -    } - -    private String getExtAppList(String delim) { -        ApplicationInfo app; -        PackageManager pm = getActivity().getPackageManager(); - -        StringBuilder applist = new StringBuilder(); -        for (String packagename : mExtapp.getExtAppList()) { -            try { -                app = pm.getApplicationInfo(packagename, 0); -                if (applist.length() != 0) -                    applist.append(delim); -                applist.append(app.loadLabel(pm)); - -            } catch (NameNotFoundException e) { -                // App not found. Remove it from the list -                mExtapp.removeApp(packagename); + +        private void setClearApiSummary () { +            Preference clearapi = findPreference("clearapi"); + +            if (mExtapp.getExtAppList().isEmpty()) { +                clearapi.setEnabled(false); +                clearapi.setSummary(R.string.no_external_app_allowed); +            } else { +                clearapi.setEnabled(true); +                clearapi.setSummary(getString(R.string.allowed_apps, getExtAppList(", ")));              }          } -        return applist.toString(); -    } +        private String getExtAppList (String delim){ +            ApplicationInfo app; +            PackageManager pm = getActivity().getPackageManager(); + +            StringBuilder applist = new StringBuilder(); +            for (String packagename : mExtapp.getExtAppList()) { +                try { +                    app = pm.getApplicationInfo(packagename, 0); +                    if (applist.length() != 0) +                        applist.append(delim); +                    applist.append(app.loadLabel(pm)); + +                } catch (NameNotFoundException e) { +                    // App not found. Remove it from the list +                    mExtapp.removeApp(packagename); +                } +            } -    private boolean isTunModuleAvailable() { -        // Check if the tun module exists on the file system -        return new File("/system/lib/modules/tun.ko").length() > 10; -    } +            return applist.toString(); +        } -    @Override -    public boolean onPreferenceClick(Preference preference) { -        if (preference.getKey().equals("clearapi")) { -            Builder builder = new AlertDialog.Builder(getActivity()); -            builder.setPositiveButton(R.string.clear, this); -            builder.setNegativeButton(android.R.string.cancel, null); -            builder.setMessage(getString(R.string.clearappsdialog, getExtAppList("\n"))); -            builder.show(); -        } else if (preference.getKey().equals("osslspeed")) { -            startActivity(new Intent(getActivity(), OpenSSLSpeed.class)); +        private boolean isTunModuleAvailable () { +            // Check if the tun module exists on the file system +            return new File("/system/lib/modules/tun.ko").length() > 10;          } -        return true; -    } +        @Override +        public boolean onPreferenceClick (Preference preference){ +            if (preference.getKey().equals("clearapi")) { +                Builder builder = new AlertDialog.Builder(getActivity()); +                builder.setPositiveButton(R.string.clear, this); +                builder.setNegativeButton(android.R.string.cancel, null); +                builder.setMessage(getString(R.string.clearappsdialog, getExtAppList("\n"))); +                builder.show(); +            } else if (preference.getKey().equals("osslspeed")) { +                startActivity(new Intent(getActivity(), OpenSSLSpeed.class)); +            } -    @Override -    public void onClick(DialogInterface dialog, int which) { -        if (which == Dialog.BUTTON_POSITIVE) { -            mExtapp.clearAllApiApps(); -            setClearApiSummary(); +            return true; +        } + +        @Override +        public void onClick (DialogInterface dialog,int which){ +            if (which == Dialog.BUTTON_POSITIVE) { +                mExtapp.clearAllApiApps(); +                setClearApiSummary(); +            }          } -    } -}
\ No newline at end of file +    }
\ No newline at end of file | 
