android: Accept a profile's UUID when initiating

This commit is contained in:
Tobias Brunner 2018-06-06 16:29:02 +02:00
parent 581f4326d5
commit 93033728a9
1 changed files with 23 additions and 6 deletions

View File

@ -58,6 +58,7 @@ import org.strongswan.android.ui.VpnProfileListFragment.OnVpnProfileSelectedList
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class MainActivity extends AppCompatActivity implements OnVpnProfileSelectedListener
{
@ -341,14 +342,30 @@ public class MainActivity extends AppCompatActivity implements OnVpnProfileSelec
*/
private void startVpnProfile(Intent intent, boolean foreground)
{
long profileId = intent.getLongExtra(EXTRA_VPN_PROFILE_ID, 0);
if (profileId <= 0)
{ /* invalid invocation */
return;
}
VpnProfile profile = null;
VpnProfileDataSource dataSource = new VpnProfileDataSource(this);
dataSource.open();
VpnProfile profile = dataSource.getVpnProfile(profileId);
String profileUUID = intent.getStringExtra(EXTRA_VPN_PROFILE_ID);
if (profileUUID != null)
{
try
{
profile = dataSource.getVpnProfile(UUID.fromString(profileUUID));
}
catch (Exception e)
{ /* invalid UUID */
e.printStackTrace();
}
}
else
{
long profileId = intent.getLongExtra(EXTRA_VPN_PROFILE_ID, 0);
if (profileId > 0)
{
profile = dataSource.getVpnProfile(profileId);
}
}
dataSource.close();
if (profile != null)