diff options
author | cyBerta <cyberta@riseup.net> | 2023-10-29 15:58:52 +0100 |
---|---|---|
committer | cyBerta <cyberta@riseup.net> | 2023-10-29 15:58:52 +0100 |
commit | 50defeaff2a8468ee44db7e09752e334e4d1ba2c (patch) | |
tree | cca77a33f5b3266b9b0462136057ae47f6b146d4 /main/src/ui/java/de/blinkt/openvpn/fragments | |
parent | 45f67a08b481f2f727556a36e28d17a3f68d435a (diff) | |
parent | 87aac67b611f616aebfb722679b40e3f49576f01 (diff) |
Merge branch 'schwabe_master' into ssh_new_master
Diffstat (limited to 'main/src/ui/java/de/blinkt/openvpn/fragments')
10 files changed, 86 insertions, 18 deletions
diff --git a/main/src/ui/java/de/blinkt/openvpn/fragments/AboutFragment.java b/main/src/ui/java/de/blinkt/openvpn/fragments/AboutFragment.java index 240fbe06..de6c83d8 100644 --- a/main/src/ui/java/de/blinkt/openvpn/fragments/AboutFragment.java +++ b/main/src/ui/java/de/blinkt/openvpn/fragments/AboutFragment.java @@ -31,6 +31,7 @@ import androidx.fragment.app.Fragment; import com.android.vending.billing.IInAppBillingService; +import de.blinkt.openvpn.BuildConfig; import de.blinkt.openvpn.core.NativeUtils; import org.json.JSONException; import org.json.JSONObject; @@ -83,9 +84,18 @@ public class AboutFragment extends Fragment implements View.OnClickListener { TextView verO2 = v.findViewById(R.id.version_ovpn2); TextView verO3 = v.findViewById(R.id.version_ovpn3); + TextView osslVer = v.findViewById(R.id.openssl_version); verO2.setText(String.format(Locale.US, "OpenVPN version: %s", NativeUtils.getOpenVPN2GitVersion())); - verO3.setText(String.format(Locale.US, "OpenVPN3 core version: %s", NativeUtils.getOpenVPN3GitVersion())); + if (BuildConfig.openvpn3) + verO3.setText(String.format(Locale.US, "OpenVPN3 core version: %s", NativeUtils.getOpenVPN3GitVersion())); + else + verO3.setText("(OpenVPN 2.x only build. No OpenVPN 3.x core in this app)"); + + + osslVer.setText(String.format(Locale.US, "OpenSSL version: %s", NativeUtils.getOpenSSLVersion())); + + /* recreating view without onCreate/onDestroy cycle */ TextView translation = (TextView) v.findViewById(R.id.translation); diff --git a/main/src/ui/java/de/blinkt/openvpn/fragments/FileSelectionFragment.java b/main/src/ui/java/de/blinkt/openvpn/fragments/FileSelectionFragment.java index 121cf324..59607fd2 100644 --- a/main/src/ui/java/de/blinkt/openvpn/fragments/FileSelectionFragment.java +++ b/main/src/ui/java/de/blinkt/openvpn/fragments/FileSelectionFragment.java @@ -186,11 +186,11 @@ public class FileSelectionFragment extends ListFragment { if (!currentPath.equals(ROOT)) { item.add(ROOT); - addItem(ROOT, R.drawable.ic_root_folder_am); + addItem(ROOT, R.drawable.ic_baseline_folder_24); path.add(ROOT); item.add("../"); - addItem("../", R.drawable.ic_root_folder_am); + addItem("../", R.drawable.ic_baseline_folder_24); path.add(f.getParent()); parentPath = f.getParent(); @@ -248,11 +248,11 @@ public class FileSelectionFragment extends ListFragment { ITEM_KEY, ITEM_IMAGE}, new int[]{R.id.fdrowtext, R.id.fdrowimage}); for (String dir : dirsMap.tailMap("").values()) { - addItem(dir, R.drawable.ic_root_folder_am); + addItem(dir, R.drawable.ic_baseline_folder_24); } for (String file : filesMap.tailMap("").values()) { - addItem(file, R.drawable.ic_doc_generic_am); + addItem(file, R.drawable.ic_baseline_file_present_24); } fileList.notifyDataSetChanged(); diff --git a/main/src/ui/java/de/blinkt/openvpn/fragments/GeneralSettings.kt b/main/src/ui/java/de/blinkt/openvpn/fragments/GeneralSettings.kt index 7db8cba6..6ba7c6fd 100644 --- a/main/src/ui/java/de/blinkt/openvpn/fragments/GeneralSettings.kt +++ b/main/src/ui/java/de/blinkt/openvpn/fragments/GeneralSettings.kt @@ -73,8 +73,10 @@ class GeneralSettings : PreferenceFragmentCompat(), Preference.OnPreferenceClick findPreference<Preference>("restartvpnonboot") as CheckBoxPreference if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - val vpn:VpnService = VpnService() - startOnBoot.isChecked = vpn.isAlwaysOn + val vpn = VpnService() + if (vpn.isAlwaysOn) + /* This is not reliable when the VPN is not active */ + startOnBoot.isChecked } startOnBoot.onPreferenceChangeListener = @@ -176,6 +178,10 @@ class GeneralSettings : PreferenceFragmentCompat(), Preference.OnPreferenceClick File("/system/lib/modules/tun.ko").length() > 10 override fun onPreferenceClick(preference: Preference): Boolean { + if (!mExtapp.checkAllowingModifyingRemoteControl(requireContext())) + { + return false; + } if (preference.key == "clearapi") { val builder = AlertDialog.Builder( requireContext() diff --git a/main/src/ui/java/de/blinkt/openvpn/fragments/KeyChainSettingsFragment.kt b/main/src/ui/java/de/blinkt/openvpn/fragments/KeyChainSettingsFragment.kt index 2444fb25..8430d788 100644 --- a/main/src/ui/java/de/blinkt/openvpn/fragments/KeyChainSettingsFragment.kt +++ b/main/src/ui/java/de/blinkt/openvpn/fragments/KeyChainSettingsFragment.kt @@ -128,6 +128,7 @@ internal abstract class KeyChainSettingsFragment : Settings_Fragment(), View.OnC } if (cert != null) { certstr += X509Utils.getCertificateValidityString(cert, resources) + certstr += ", " certstr += X509Utils.getCertificateFriendlyName(cert) } diff --git a/main/src/ui/java/de/blinkt/openvpn/fragments/LogFragment.java b/main/src/ui/java/de/blinkt/openvpn/fragments/LogFragment.java index 611e10e9..c5c48b0e 100644 --- a/main/src/ui/java/de/blinkt/openvpn/fragments/LogFragment.java +++ b/main/src/ui/java/de/blinkt/openvpn/fragments/LogFragment.java @@ -538,6 +538,7 @@ public class LogFragment extends ListFragment implements StateListener, SeekBar. (dialog1, which) -> { Intent intent = new Intent(getActivity(), LaunchVPN.class); intent.putExtra(LaunchVPN.EXTRA_KEY, profile.getUUIDString()); + intent.putExtra(LaunchVPN.EXTRA_START_REASON, "restart from logwindow"); intent.setAction(Intent.ACTION_MAIN); startActivity(intent); }); diff --git a/main/src/ui/java/de/blinkt/openvpn/fragments/OpenVpnPreferencesFragment.java b/main/src/ui/java/de/blinkt/openvpn/fragments/OpenVpnPreferencesFragment.java index a3c19955..802e0b49 100644 --- a/main/src/ui/java/de/blinkt/openvpn/fragments/OpenVpnPreferencesFragment.java +++ b/main/src/ui/java/de/blinkt/openvpn/fragments/OpenVpnPreferencesFragment.java @@ -46,7 +46,6 @@ public abstract class OpenVpnPreferencesFragment extends PreferenceFragmentCompa String profileUUID = savedInstanceState.getString(VpnProfile.EXTRA_PROFILEUUID); mProfile = ProfileManager.get(getActivity(), profileUUID); loadSettings(); - } } diff --git a/main/src/ui/java/de/blinkt/openvpn/fragments/SendDumpFragment.java b/main/src/ui/java/de/blinkt/openvpn/fragments/SendDumpFragment.java index 5bc0bbb1..ae90f3d5 100644 --- a/main/src/ui/java/de/blinkt/openvpn/fragments/SendDumpFragment.java +++ b/main/src/ui/java/de/blinkt/openvpn/fragments/SendDumpFragment.java @@ -36,7 +36,12 @@ public class SendDumpFragment extends Fragment { if (c.getCacheDir() == null) return null; - for (File f : c.getCacheDir().listFiles()) { + File[] filesList = c.getCacheDir().listFiles(); + + if (filesList == null) + return null; + + for (File f : filesList) { if (!f.getName().endsWith(".dmp")) continue; @@ -104,6 +109,7 @@ public class SendDumpFragment extends Fragment { Pair<File, Long> ldump = getLastestDump(getActivity()); if (ldump == null) { VpnStatus.logError("No Minidump found!"); + return; } uris.add(Uri.parse("content://de.blinkt.openvpn.FileProvider/" + ldump.first.getName())); diff --git a/main/src/ui/java/de/blinkt/openvpn/fragments/Settings_IP.kt b/main/src/ui/java/de/blinkt/openvpn/fragments/Settings_IP.kt index 27e6854f..ef69f3f4 100644 --- a/main/src/ui/java/de/blinkt/openvpn/fragments/Settings_IP.kt +++ b/main/src/ui/java/de/blinkt/openvpn/fragments/Settings_IP.kt @@ -5,6 +5,7 @@ package de.blinkt.openvpn.fragments import android.os.Bundle +import android.view.View import androidx.preference.* import de.blinkt.openvpn.R import de.blinkt.openvpn.fragments.OpenVpnPreferencesFragment @@ -33,6 +34,22 @@ class Settings_IP : OpenVpnPreferencesFragment(), Preference.OnPreferenceChangeL // Load the preferences from an XML resource addPreferencesFromResource(R.xml.vpn_ipsettings) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + /* Bind the preferences early to avoid loadingSetting which is called + * from the superclass to access an uninitialised earlyinit property + */ + super.onViewCreated(view, savedInstanceState) + } + + override fun onBindPreferences() { + super.onBindPreferences() + bindPreferences() + loadSettings() + } + + private fun bindPreferences() { mIPv4 = findPreference("ipv4_address")!! mIPv6 = findPreference("ipv6_address")!! mUsePull = findPreference("usePull")!! @@ -45,7 +62,6 @@ class Settings_IP : OpenVpnPreferencesFragment(), Preference.OnPreferenceChangeL mNobind = findPreference("nobind")!! mUsePull.onPreferenceChangeListener = this mOverrideDNS.onPreferenceChangeListener = this - loadSettings() } diff --git a/main/src/ui/java/de/blinkt/openvpn/fragments/Utils.kt b/main/src/ui/java/de/blinkt/openvpn/fragments/Utils.kt index 4fdd50ba..55056424 100644 --- a/main/src/ui/java/de/blinkt/openvpn/fragments/Utils.kt +++ b/main/src/ui/java/de/blinkt/openvpn/fragments/Utils.kt @@ -90,6 +90,7 @@ object Utils { i.type = "text/plain" supportedMimeTypes.add("text/plain") } + else -> null } val mtm = MimeTypeMap.getSingleton() for (ext in extensions) { @@ -305,12 +306,12 @@ object Utils { if ("insecure".equals(vp.mTlSCertProfile)) warnings.add("low security (TLS security profile 'insecure' selected)"); - var cipher= vp.mCipher?.toUpperCase(Locale.ROOT) - if (cipher.isNullOrEmpty()) + var cipher= vp.mCipher.uppercase(Locale.ROOT) + if (cipher.isEmpty()) cipher = "BF-CBC"; for (weakCipher in weakCiphers) { - if ((vp.mDataCiphers != null && vp.mDataCiphers.toUpperCase(Locale.ROOT) + if ((vp.mDataCiphers != null && vp.mDataCiphers.uppercase(Locale.ROOT) .contains(weakCipher)) || (vp.mCompatMode in 1..20399 && (cipher == weakCipher)) ) diff --git a/main/src/ui/java/de/blinkt/openvpn/fragments/VPNProfileList.java b/main/src/ui/java/de/blinkt/openvpn/fragments/VPNProfileList.java index c7ee5df1..fa9438cb 100644 --- a/main/src/ui/java/de/blinkt/openvpn/fragments/VPNProfileList.java +++ b/main/src/ui/java/de/blinkt/openvpn/fragments/VPNProfileList.java @@ -5,12 +5,14 @@ package de.blinkt.openvpn.fragments; +import android.Manifest; import android.annotation.TargetApi; import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.content.pm.PackageManager; import android.content.pm.ShortcutInfo; import android.content.pm.ShortcutManager; import android.graphics.drawable.Drawable; @@ -20,6 +22,9 @@ import android.os.Build; import android.os.Bundle; import android.os.PersistableBundle; +import androidx.activity.result.ActivityResultCallback; +import androidx.activity.result.ActivityResultLauncher; +import androidx.activity.result.contract.ActivityResultContracts; import androidx.annotation.NonNull; import androidx.annotation.RequiresApi; import androidx.fragment.app.ListFragment; @@ -85,6 +90,8 @@ public class VPNProfileList extends ListFragment implements OnClickListener, Vpn private ArrayAdapter<VpnProfile> mArrayadapter; private Intent mLastIntent; private VpnProfile defaultVPN; + private View mPermissionView; + private ActivityResultLauncher<String> mPermReceiver; @Override public void updateState(String state, String logmessage, final int localizedResId, ConnectionStatus level, Intent intent) { @@ -130,6 +137,13 @@ public class VPNProfileList extends ListFragment implements OnClickListener, Vpn super.onCreate(savedInstanceState); setHasOptionsMenu(true); setListAdapter(); + + registerPermissionReceiver(); + } + + private void registerPermissionReceiver() { + mPermReceiver = registerForActivityResult(new ActivityResultContracts.RequestPermission(), + result -> checkForNotificationPermission(requireView())); } @RequiresApi(api = Build.VERSION_CODES.N_MR1) @@ -225,9 +239,10 @@ public class VPNProfileList extends ListFragment implements OnClickListener, Vpn @RequiresApi(Build.VERSION_CODES.N_MR1) ShortcutInfo createShortcut(VpnProfile profile) { Intent shortcutIntent = new Intent(Intent.ACTION_MAIN); - shortcutIntent.setClass(getActivity(), LaunchVPN.class); + shortcutIntent.setClass(requireContext(), LaunchVPN.class); shortcutIntent.putExtra(LaunchVPN.EXTRA_KEY, profile.getUUID().toString()); shortcutIntent.setAction(Intent.ACTION_MAIN); + shortcutIntent.putExtra(LaunchVPN.EXTRA_START_REASON, "shortcut"); shortcutIntent.putExtra("EXTRA_HIDELOG", true); PersistableBundle versionExtras = new PersistableBundle(); @@ -278,10 +293,24 @@ public class VPNProfileList extends ListFragment implements OnClickListener, Vpn if (fab_import != null) fab_import.setOnClickListener(this); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) + checkForNotificationPermission(v); + + return v; } + private void checkForNotificationPermission(View v) { + mPermissionView = v.findViewById(R.id.notification_permission); + boolean permissionGranted = (requireActivity().checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED); + mPermissionView.setVisibility(permissionGranted ? View.GONE : View.VISIBLE); + + mPermissionView.setOnClickListener((view) -> { + mPermReceiver.launch(Manifest.permission.POST_NOTIFICATIONS); + }); + } + private void setListAdapter() { if (mArrayadapter == null) { mArrayadapter = new VPNArrayAdapter(getActivity(), R.layout.vpn_list_item, R.id.vpn_item_title); @@ -485,11 +514,9 @@ public class VPNProfileList extends ListFragment implements OnClickListener, Vpn onAddOrDuplicateProfile(profile); } - if (resultCode != Activity.RESULT_OK) return; - if (requestCode == START_VPN_CONFIG) { String configuredVPN = data.getStringExtra(VpnProfile.EXTRA_PROFILEUUID); @@ -536,6 +563,7 @@ public class VPNProfileList extends ListFragment implements OnClickListener, Vpn Intent intent = new Intent(getActivity(), LaunchVPN.class); intent.putExtra(LaunchVPN.EXTRA_KEY, profile.getUUID().toString()); + intent.putExtra(LaunchVPN.EXTRA_START_REASON, "main profile list"); intent.setAction(Intent.ACTION_MAIN); startActivity(intent); } @@ -640,9 +668,9 @@ public class VPNProfileList extends ListFragment implements OnClickListener, Vpn public Drawable getDrawable(String source) { Drawable d = null; if ("ic_menu_add".equals(source)) - d = requireActivity().getResources().getDrawable(R.drawable.ic_menu_add_grey); + d = requireActivity().getResources().getDrawable(R.drawable.ic_menu_add_grey, requireActivity().getTheme()); else if ("ic_menu_archive".equals(source)) - d = requireActivity().getResources().getDrawable(R.drawable.ic_menu_import_grey); + d = requireActivity().getResources().getDrawable(R.drawable.ic_menu_import_grey, requireActivity().getTheme()); if (d != null) { |