From: Tobias Brunner Date: Wed, 15 Aug 2012 08:51:30 +0000 (+0200) Subject: Show an error message if VPN is not supported X-Git-Tag: 5.0.1~193 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8df118f73368aa1c8776e7ec3578ebd5bd995a26;p=thirdparty%2Fstrongswan.git Show an error message if VPN is not supported Some devices have Android 4 installed but the system images still seem to lack the components that are required for VPN support. One such component is the dialog used to grant permission to create . --- diff --git a/src/frontends/android/res/values-de/strings.xml b/src/frontends/android/res/values-de/strings.xml index 13a34b2910..9f3f637a84 100644 --- a/src/frontends/android/res/values-de/strings.xml +++ b/src/frontends/android/res/values-de/strings.xml @@ -23,6 +23,8 @@ CA-Zertifikate neu laden Log anzeigen Suchen + VPN nicht unterstützt + Ihr Gerät unterstützt keine VPN Anwendungen.\nBitte kontaktieren Sie den Hersteller. Log diff --git a/src/frontends/android/res/values/strings.xml b/src/frontends/android/res/values/strings.xml index 07dd8c269e..bc7fa4a1db 100644 --- a/src/frontends/android/res/values/strings.xml +++ b/src/frontends/android/res/values/strings.xml @@ -23,6 +23,8 @@ Reload CA certificates View log Search + VPN not supported + Your device does not support VPN applications.\nPlease contact the manufacturer. Log diff --git a/src/frontends/android/src/org/strongswan/android/ui/MainActivity.java b/src/frontends/android/src/org/strongswan/android/ui/MainActivity.java index 80f1a27b3d..bc5030ea5c 100644 --- a/src/frontends/android/src/org/strongswan/android/ui/MainActivity.java +++ b/src/frontends/android/src/org/strongswan/android/ui/MainActivity.java @@ -30,6 +30,7 @@ import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.app.Dialog; import android.app.DialogFragment; +import android.content.ActivityNotFoundException; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; @@ -46,8 +47,11 @@ import android.widget.EditText; public class MainActivity extends Activity implements OnVpnProfileSelectedListener { public static final String CONTACT_EMAIL = "android@strongswan.org"; + private static final String SHOW_ERROR_DIALOG = "errordialog"; private static final int PREPARE_VPN_SERVICE = 0; + private VpnProfile activeProfile; + private AlertDialog mErrorDialog; @Override public void onCreate(Bundle savedInstanceState) @@ -59,10 +63,32 @@ public class MainActivity extends Activity implements OnVpnProfileSelectedListen ActionBar bar = getActionBar(); bar.setDisplayShowTitleEnabled(false); + if (savedInstanceState != null && savedInstanceState.getBoolean(SHOW_ERROR_DIALOG)) + { + showVpnNotSupportedError(); + } + /* load CA certificates in a background task */ new CertificateLoadTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, false); } + @Override + protected void onSaveInstanceState(Bundle outState) + { + super.onSaveInstanceState(outState); + outState.putBoolean(SHOW_ERROR_DIALOG, mErrorDialog != null); + } + + @Override + protected void onDestroy() + { + super.onDestroy(); + if (mErrorDialog != null) + { /* avoid any errors about leaked windows */ + mErrorDialog.dismiss(); + } + } + @Override public boolean onCreateOptionsMenu(Menu menu) { @@ -96,7 +122,18 @@ public class MainActivity extends Activity implements OnVpnProfileSelectedListen Intent intent = VpnService.prepare(this); if (intent != null) { - startActivityForResult(intent, PREPARE_VPN_SERVICE); + try + { + startActivityForResult(intent, PREPARE_VPN_SERVICE); + } + catch (ActivityNotFoundException ex) + { + /* it seems some devices, even though they come with Android 4, + * don't have the VPN components built into the system image. + * com.android.vpndialogs/com.android.vpndialogs.ConfirmDialog + * will not be found then */ + showVpnNotSupportedError(); + } } else { @@ -138,6 +175,25 @@ public class MainActivity extends Activity implements OnVpnProfileSelectedListen } } + /** + * Show an error dialog if case the device lacks VPN support. + */ + private void showVpnNotSupportedError() + { + mErrorDialog = new AlertDialog.Builder(this) + .setTitle(R.string.vpn_not_supported_title) + .setMessage(getString(R.string.vpn_not_supported)) + .setCancelable(false) + .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) + { + mErrorDialog = null; + dialog.dismiss(); + } + }).show(); + } + /** * Class that loads or reloads the cached CA certificates. */