From: Tobias Brunner Date: Wed, 7 Nov 2012 15:06:30 +0000 (+0100) Subject: android: Start a specific VPN profile based on special Intents X-Git-Tag: 5.0.2dr4~176 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=127d83bb2128d2b10d7a5e394f8620c94a2a8107;p=thirdparty%2Fstrongswan.git android: Start a specific VPN profile based on special Intents --- diff --git a/src/frontends/android/AndroidManifest.xml b/src/frontends/android/AndroidManifest.xml index 971b3073c0..c191a9e52b 100644 --- a/src/frontends/android/AndroidManifest.xml +++ b/src/frontends/android/AndroidManifest.xml @@ -35,9 +35,12 @@ android:launchMode="singleTop" > - + + + + diff --git a/src/frontends/android/res/values-de/strings.xml b/src/frontends/android/res/values-de/strings.xml index bb4cf5d3ae..5c922ad517 100644 --- a/src/frontends/android/res/values-de/strings.xml +++ b/src/frontends/android/res/values-de/strings.xml @@ -27,6 +27,7 @@ Ihr Gerät unterstützt keine VPN Anwendungen.\nBitte kontaktieren Sie den Hersteller. VPN Verbindungen sind nicht möglich im abgeriegelten Modus. Laden… + Profil nicht gefunden Log diff --git a/src/frontends/android/res/values-pl/strings.xml b/src/frontends/android/res/values-pl/strings.xml index 58d158b8ed..80fab6350e 100644 --- a/src/frontends/android/res/values-pl/strings.xml +++ b/src/frontends/android/res/values-pl/strings.xml @@ -29,6 +29,7 @@ Urządzenie nie obsługuje aplikacji VPN.\nProszę skontaktować się z producentem. Polączenia nie sa możliwe w trybie zamkniętym Wczytywanie… + Nie znaleziono profilu Log diff --git a/src/frontends/android/res/values/strings.xml b/src/frontends/android/res/values/strings.xml index 4b332348da..84fdf382ea 100644 --- a/src/frontends/android/res/values/strings.xml +++ b/src/frontends/android/res/values/strings.xml @@ -27,6 +27,7 @@ Your device does not support VPN applications.\nPlease contact the manufacturer. VPN connections are not supported in lockdown mode. Loading… + Profile not found 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 4ccf7d3145..8a5d4fedb0 100644 --- a/src/frontends/android/src/org/strongswan/android/ui/MainActivity.java +++ b/src/frontends/android/src/org/strongswan/android/ui/MainActivity.java @@ -42,10 +42,13 @@ import android.view.MenuItem; import android.view.View; import android.view.Window; import android.widget.EditText; +import android.widget.Toast; public class MainActivity extends Activity implements OnVpnProfileSelectedListener { public static final String CONTACT_EMAIL = "android@strongswan.org"; + public static final String START_PROFILE = "org.strongswan.android.action.START_PROFILE"; + public static final String EXTRA_VPN_PROFILE_ID = "org.strongswan.android.VPN_PROFILE_ID"; private static final int PREPARE_VPN_SERVICE = 0; private Bundle mProfileInfo; @@ -62,6 +65,25 @@ public class MainActivity extends Activity implements OnVpnProfileSelectedListen /* load CA certificates in a background task */ new CertificateLoadTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, false); + + if (START_PROFILE.equals(getIntent().getAction())) + { + startVpnProfile(getIntent()); + } + } + + /** + * Due to launchMode=singleTop this is called if the Activity already exists + */ + @Override + protected void onNewIntent(Intent intent) + { + super.onNewIntent(intent); + + if (START_PROFILE.equals(intent.getAction())) + { + startVpnProfile(intent); + } } @Override @@ -167,6 +189,33 @@ public class MainActivity extends Activity implements OnVpnProfileSelectedListen } } + /** + * Start the VPN profile referred to by the given intent. Displays an error + * if the profile doesn't exist. + * @param intent Intent that caused us to start this + */ + private void startVpnProfile(Intent intent) + { + long profileId = intent.getLongExtra(EXTRA_VPN_PROFILE_ID, 0); + if (profileId <= 0) + { /* invalid invocation */ + return; + } + VpnProfileDataSource dataSource = new VpnProfileDataSource(this); + dataSource.open(); + VpnProfile profile = dataSource.getVpnProfile(profileId); + dataSource.close(); + + if (profile != null) + { + onVpnProfileSelected(profile); + } + else + { + Toast.makeText(this, R.string.profile_not_found, Toast.LENGTH_LONG).show(); + } + } + /** * Class that loads or reloads the cached CA certificates. */