I'm looking into duplicating the Always-On VPN (introduced in Android 4.2) functionality in my VPN android app. I could of course direct the users to the settings page and have them click the checkbox, but I'd really like to just bake this into my application. I went through the android source code for this dialog (since there is no corresponding setting exposed in the SDK) and it seems simple enough:
public void onClick(DialogInterface dialog, int which) {
final int newIndex = listView.getCheckedItemPosition();
if (mCurrentIndex == newIndex) return;
if (newIndex == 0) {
keyStore.delete(Credentials.LOCKDOWN_VPN);
} else {
final VpnProfile profile = mProfiles.get(newIndex - 1);
if (!profile.isValidLockdownProfile()) {
Toast.makeText(context, R.string.vpn_lockdown_config_error,
Toast.LENGTH_LONG).show();
return;
}
keyStore.put(Credentials.LOCKDOWN_VPN, profile.key.getBytes());
}
// kick profiles since we changed them
ConnectivityManager.from(getActivity()).updateLockdownVpn();
}
Unfortunately the keystore here is the android.security.KeyStore file instead of the usual java.security.KeyStore. As such, my question is, whats the best way to implement this block of code in my app? Is it even possible for me to change this setting in my app without root access? Is there a way for me to include the android.security.KeyStore file? Any thoughts would be very helpful!!