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 .
This commit is contained in:
Tobias Brunner 2012-08-15 10:51:30 +02:00
parent c8d0c3b03d
commit 8df118f733
3 changed files with 61 additions and 1 deletions

View File

@ -23,6 +23,8 @@
<string name="reload_trusted_certs">CA-Zertifikate neu laden</string>
<string name="show_log">Log anzeigen</string>
<string name="search">Suchen</string>
<string name="vpn_not_supported_title">VPN nicht unterstützt</string>
<string name="vpn_not_supported">Ihr Gerät unterstützt keine VPN Anwendungen.\nBitte kontaktieren Sie den Hersteller.</string>
<!-- Log view -->
<string name="log_title">Log</string>

View File

@ -23,6 +23,8 @@
<string name="reload_trusted_certs">Reload CA certificates</string>
<string name="show_log">View log</string>
<string name="search">Search</string>
<string name="vpn_not_supported_title">VPN not supported</string>
<string name="vpn_not_supported">Your device does not support VPN applications.\nPlease contact the manufacturer.</string>
<!-- Log view -->
<string name="log_title">Log</string>

View File

@ -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.
*/