public static final String EXTRA_VPN_PROFILE_ID = "org.strongswan.android.VPN_PROFILE_ID";
private static final int PREPARE_VPN_SERVICE = 0;
+ 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_RECONNECT = "RECONNECT";
private static final String DIALOG_TAG = "Dialog";
private Bundle mProfileInfo;
+ private boolean mWaitingForResult;
private VpnStateService mService;
private final ServiceConnection mServiceConnection = new ServiceConnection()
{
public void onServiceConnected(ComponentName name, IBinder service)
{
mService = ((VpnStateService.LocalBinder)service).getService();
-
- if (START_PROFILE.equals(getIntent().getAction()))
- {
- startVpnProfile(getIntent());
- }
- else if (DISCONNECT.equals(getIntent().getAction()))
- {
- disconnect();
- }
+ handleIntent();
}
};
{
super.onCreate(savedInstanceState);
+ if (savedInstanceState != null)
+ {
+ mWaitingForResult = savedInstanceState.getBoolean(WAITING_FOR_RESULT, false);
+ }
this.bindService(new Intent(this, VpnStateService.class),
mServiceConnection, Service.BIND_AUTO_CREATE);
}
+ @Override
+ protected void onSaveInstanceState(Bundle outState)
+ {
+ super.onSaveInstanceState(outState);
+ outState.putBoolean(WAITING_FOR_RESULT, mWaitingForResult);
+ }
+
@Override
protected void onDestroy()
{
{
super.onNewIntent(intent);
- if (START_PROFILE.equals(intent.getAction()))
- {
- startVpnProfile(intent);
- }
- else if (DISCONNECT.equals(intent.getAction()))
+ /* store this intent in case the service is not yet connected or the activity is restarted */
+ setIntent(intent);
+
+ if (mService != null)
{
- disconnect();
+ handleIntent();
}
}
protected void prepareVpnService(Bundle profileInfo)
{
Intent intent;
+
+ if (mWaitingForResult)
+ {
+ mProfileInfo = profileInfo;
+ return;
+ }
+
try
{
intent = VpnService.prepare(this);
{
try
{
+ mWaitingForResult = true;
startActivityForResult(intent, PREPARE_VPN_SERVICE);
}
catch (ActivityNotFoundException ex)
* com.android.vpndialogs/com.android.vpndialogs.ConfirmDialog
* will not be found then */
VpnNotSupportedError.showWithMessage(this, R.string.vpn_not_supported);
+ mWaitingForResult = false;
}
}
else
switch (requestCode)
{
case PREPARE_VPN_SERVICE:
+ mWaitingForResult = false;
if (resultCode == RESULT_OK && mProfileInfo != null)
{
if (mService != null)
}
}
+ /**
+ * Handle the Intent of this Activity depending on its action
+ */
+ private void handleIntent()
+ {
+ if (START_PROFILE.equals(getIntent().getAction()))
+ {
+ startVpnProfile(getIntent());
+ }
+ else if (DISCONNECT.equals(getIntent().getAction()))
+ {
+ disconnect();
+ }
+ }
+
/**
* Dismiss dialog if shown
*/