From: Tobias Brunner Date: Tue, 30 Sep 2025 12:19:12 +0000 (+0200) Subject: android: Prompt the user to edit the profile if no certificate is selected X-Git-Tag: android-2.6.0^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=11f043c3dee948d8f4b72e0f97494cca3438ae90;p=thirdparty%2Fstrongswan.git android: Prompt the user to edit the profile if no certificate is selected --- diff --git a/src/frontends/android/app/src/main/java/org/strongswan/android/ui/VpnProfileControlActivity.java b/src/frontends/android/app/src/main/java/org/strongswan/android/ui/VpnProfileControlActivity.java index a7b39b6ac2..9ff07175e3 100644 --- a/src/frontends/android/app/src/main/java/org/strongswan/android/ui/VpnProfileControlActivity.java +++ b/src/frontends/android/app/src/main/java/org/strongswan/android/ui/VpnProfileControlActivity.java @@ -70,6 +70,7 @@ public class VpnProfileControlActivity extends AppCompatActivity private static final String WAITING_FOR_RESULT = "WAITING_FOR_RESULT"; private static final String PROFILE_NAME = "PROFILE_NAME"; private static final String PROFILE_REQUIRES_PASSWORD = "REQUIRES_PASSWORD"; + private static final String PROFILE_CERTIFICATE_MISSING = "CERTIFICATE_MISSING"; private static final String PROFILE_RECONNECT = "RECONNECT"; private static final String PROFILE_DISCONNECT = "DISCONNECT"; private static final String DIALOG_TAG = "Dialog"; @@ -332,6 +333,8 @@ public class VpnProfileControlActivity extends AppCompatActivity profileInfo.putString(VpnProfileDataSource.KEY_USERNAME, profile.getUsername()); profileInfo.putString(VpnProfileDataSource.KEY_PASSWORD, profile.getPassword()); profileInfo.putBoolean(PROFILE_REQUIRES_PASSWORD, profile.getVpnType().has(VpnTypeFeature.USER_PASS)); + profileInfo.putBoolean(PROFILE_CERTIFICATE_MISSING, profile.getVpnType().has(VpnTypeFeature.CERTIFICATE) && + profile.getUserCertificateAlias() == null); profileInfo.putString(PROFILE_NAME, profile.getName()); removeFragmentByTag(DIALOG_TAG); @@ -355,6 +358,13 @@ public class VpnProfileControlActivity extends AppCompatActivity */ private void startVpnProfile(Bundle profileInfo) { + if (profileInfo.getBoolean(PROFILE_CERTIFICATE_MISSING)) + { + CertificateRequiredDialog dialog = new CertificateRequiredDialog(); + dialog.setArguments(profileInfo); + dialog.show(getSupportFragmentManager(), DIALOG_TAG); + return; + } if (profileInfo.getBoolean(PROFILE_REQUIRES_PASSWORD) && profileInfo.getString(VpnProfileDataSource.KEY_PASSWORD) == null) { @@ -621,6 +631,36 @@ public class VpnProfileControlActivity extends AppCompatActivity } } + /** + * Class that displays a dialog warning about a missing certificate. + */ + public static class CertificateRequiredDialog extends AppCompatDialogFragment + { + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) + { + final Bundle profileInfo = getArguments(); + + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()) + .setTitle(R.string.certificate_required_title) + .setMessage(R.string.certificate_required_text) + .setNegativeButton(android.R.string.cancel, (dialog, which) -> getActivity().finish()) + .setPositiveButton(R.string.edit_profile, (dialog, which) -> { + Intent editIntent = new Intent(getActivity(), VpnProfileDetailActivity.class); + editIntent.putExtra(VpnProfileDataSource.KEY_UUID, profileInfo.getString(VpnProfileDataSource.KEY_UUID)); + startActivity(editIntent); + getActivity().finish(); + }); + return builder.create(); + } + + @Override + public void onCancel(DialogInterface dialog) + { + getActivity().finish(); + } + } + /** * Class that displays a warning before asking the user to add the app to the * device's power whitelist. diff --git a/src/frontends/android/app/src/main/res/values-de/strings.xml b/src/frontends/android/app/src/main/res/values-de/strings.xml index 3691a598c8..c282004afd 100644 --- a/src/frontends/android/app/src/main/res/values-de/strings.xml +++ b/src/frontends/android/app/src/main/res/values-de/strings.xml @@ -234,6 +234,8 @@ Wiederholen abbrechen Akku-Optimierung deaktivieren Bitte den nächsten Dialog bestätigen, um die App auf die weisse Liste für Akku-Optimierung zu setzen, so dass sie NAT keepalives und Rekeyings zeitlich korrekt planen kann, um konstant erreichbar zu bleiben während die VPN-Verbindung besteht. + Benutzer-Zertifikat benötigt + Bitte bearbeiten Sie das VPN Profil, um eines auszuwählen. VPN umschalten diff --git a/src/frontends/android/app/src/main/res/values-pl/strings.xml b/src/frontends/android/app/src/main/res/values-pl/strings.xml index 4a3b92201b..82d9655369 100644 --- a/src/frontends/android/app/src/main/res/values-pl/strings.xml +++ b/src/frontends/android/app/src/main/res/values-pl/strings.xml @@ -236,6 +236,8 @@ Cancel retry Disable battery optimizations Please confirm the next dialog to add the app to the device\'s power whitelist so it can ignore battery optimizations and schedule NAT keep-alives and rekeyings accurately in order to constantly keep reachable while the VPN is established. + User certificate required + Please edit the VPN profile to select one. Toggle VPN diff --git a/src/frontends/android/app/src/main/res/values-ru/strings.xml b/src/frontends/android/app/src/main/res/values-ru/strings.xml index bb7173e920..ac09e3e4cb 100644 --- a/src/frontends/android/app/src/main/res/values-ru/strings.xml +++ b/src/frontends/android/app/src/main/res/values-ru/strings.xml @@ -230,6 +230,8 @@ Cancel retry Disable battery optimizations Please confirm the next dialog to add the app to the device\'s power whitelist so it can ignore battery optimizations and schedule NAT keep-alives and rekeyings accurately in order to constantly keep reachable while the VPN is established. + User certificate required + Please edit the VPN profile to select one. Toggle VPN diff --git a/src/frontends/android/app/src/main/res/values-uk/strings.xml b/src/frontends/android/app/src/main/res/values-uk/strings.xml index c92f170b24..a819bc83e2 100644 --- a/src/frontends/android/app/src/main/res/values-uk/strings.xml +++ b/src/frontends/android/app/src/main/res/values-uk/strings.xml @@ -231,6 +231,8 @@ Cancel retry Disable battery optimizations Please confirm the next dialog to add the app to the device\'s power whitelist so it can ignore battery optimizations and schedule NAT keep-alives and rekeyings accurately in order to constantly keep reachable while the VPN is established. + User certificate required + Please edit the VPN profile to select one. Toggle VPN diff --git a/src/frontends/android/app/src/main/res/values-zh-rCN/strings.xml b/src/frontends/android/app/src/main/res/values-zh-rCN/strings.xml index d2b21f2271..a7ad193c78 100644 --- a/src/frontends/android/app/src/main/res/values-zh-rCN/strings.xml +++ b/src/frontends/android/app/src/main/res/values-zh-rCN/strings.xml @@ -230,6 +230,8 @@ 取消重试 禁用电池优化 请确认下一个对话框,将应用程序添加到设备的电源白名单中,这样它就可以忽略电池优化,并准确地安排NAT保持有效和重新键入,以便在建立VPN时始终保持可访问性。 + User certificate required + Please edit the VPN profile to select one. 切换VPN diff --git a/src/frontends/android/app/src/main/res/values-zh-rTW/strings.xml b/src/frontends/android/app/src/main/res/values-zh-rTW/strings.xml index 6c74fc7867..5331675844 100644 --- a/src/frontends/android/app/src/main/res/values-zh-rTW/strings.xml +++ b/src/frontends/android/app/src/main/res/values-zh-rTW/strings.xml @@ -230,6 +230,8 @@ Cancel retry Disable battery optimizations Please confirm the next dialog to add the app to the device\'s power whitelist so it can ignore battery optimizations and schedule NAT keep-alives and rekeyings accurately in order to constantly keep reachable while the VPN is established. + User certificate required + Please edit the VPN profile to select one. Toggle VPN diff --git a/src/frontends/android/app/src/main/res/values/strings.xml b/src/frontends/android/app/src/main/res/values/strings.xml index 667375864d..417463606c 100644 --- a/src/frontends/android/app/src/main/res/values/strings.xml +++ b/src/frontends/android/app/src/main/res/values/strings.xml @@ -234,6 +234,8 @@ Cancel retry Disable battery optimizations Please confirm the next dialog to add the app to the device\'s power whitelist so it can ignore battery optimizations and schedule NAT keep-alives and rekeyings accurately in order to constantly keep reachable while the VPN is established. + User certificate required + Please edit the VPN profile to select one. Toggle VPN