android: Prompt the user to edit the profile if no certificate is selected

This commit is contained in:
Tobias Brunner
2025-09-30 16:51:08 +02:00
parent 1a16b2c0cb
commit 11f043c3de
8 changed files with 54 additions and 0 deletions
@@ -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.
@@ -234,6 +234,8 @@
<string name="cancel_retry">Wiederholen abbrechen</string>
<string name="power_whitelist_title">Akku-Optimierung deaktivieren</string>
<string name="power_whitelist_text">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.</string>
<string name="certificate_required_title">Benutzer-Zertifikat benötigt</string>
<string name="certificate_required_text">Bitte bearbeiten Sie das VPN Profil, um eines auszuwählen.</string>
<!-- Quick Settings tile -->
<string name="tile_default">VPN umschalten</string>
@@ -236,6 +236,8 @@
<string name="cancel_retry">Cancel retry</string>
<string name="power_whitelist_title">Disable battery optimizations</string>
<string name="power_whitelist_text">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.</string>
<string name="certificate_required_title">User certificate required</string>
<string name="certificate_required_text">Please edit the VPN profile to select one.</string>
<!-- Quick Settings tile -->
<string name="tile_default">Toggle VPN</string>
@@ -230,6 +230,8 @@
<string name="cancel_retry">Cancel retry</string>
<string name="power_whitelist_title">Disable battery optimizations</string>
<string name="power_whitelist_text">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.</string>
<string name="certificate_required_title">User certificate required</string>
<string name="certificate_required_text">Please edit the VPN profile to select one.</string>
<!-- Quick Settings tile -->
<string name="tile_default">Toggle VPN</string>
@@ -231,6 +231,8 @@
<string name="cancel_retry">Cancel retry</string>
<string name="power_whitelist_title">Disable battery optimizations</string>
<string name="power_whitelist_text">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.</string>
<string name="certificate_required_title">User certificate required</string>
<string name="certificate_required_text">Please edit the VPN profile to select one.</string>
<!-- Quick Settings tile -->
<string name="tile_default">Toggle VPN</string>
@@ -230,6 +230,8 @@
<string name="cancel_retry">取消重试</string>
<string name="power_whitelist_title">禁用电池优化</string>
<string name="power_whitelist_text">请确认下一个对话框,将应用程序添加到设备的电源白名单中,这样它就可以忽略电池优化,并准确地安排NAT保持有效和重新键入,以便在建立VPN时始终保持可访问性。</string>
<string name="certificate_required_title">User certificate required</string>
<string name="certificate_required_text">Please edit the VPN profile to select one.</string>
<!-- Quick Settings tile -->
<string name="tile_default">切换VPN</string>
@@ -230,6 +230,8 @@
<string name="cancel_retry">Cancel retry</string>
<string name="power_whitelist_title">Disable battery optimizations</string>
<string name="power_whitelist_text">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.</string>
<string name="certificate_required_title">User certificate required</string>
<string name="certificate_required_text">Please edit the VPN profile to select one.</string>
<!-- Quick Settings tile -->
<string name="tile_default">Toggle VPN</string>
@@ -234,6 +234,8 @@
<string name="cancel_retry">Cancel retry</string>
<string name="power_whitelist_title">Disable battery optimizations</string>
<string name="power_whitelist_text">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.</string>
<string name="certificate_required_title">User certificate required</string>
<string name="certificate_required_text">Please edit the VPN profile to select one.</string>
<!-- Quick Settings tile -->
<string name="tile_default">Toggle VPN</string>