use of android.net.vpn.VpnProfile in project android_packages_apps_Settings by LineageOS.
the class VpnSettings method replaceProfile.
// index: index to mVpnProfileList
private void replaceProfile(int index, VpnProfile p) throws IOException {
Map<String, VpnPreference> map = mVpnPreferenceMap;
VpnProfile oldProfile = mVpnProfileList.set(index, p);
VpnPreference pref = map.remove(oldProfile.getName());
if (pref.mProfile != oldProfile) {
throw new RuntimeException("inconsistent state!");
}
p.setId(oldProfile.getId());
processSecrets(p);
// directories.
if (Util.copyFiles(getProfileDir(oldProfile), getProfileDir(p))) {
removeProfileFromStorage(oldProfile);
}
saveProfileToStorage(p);
pref.setProfile(p);
map.put(p.getName(), pref);
}
use of android.net.vpn.VpnProfile in project android_packages_apps_Settings by LineageOS.
the class VpnSettings method onActivityResult.
@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
if ((resultCode == RESULT_CANCELED) || (data == null)) {
Log.d(TAG, "no result returned by editor");
return;
}
if (requestCode == REQUEST_SELECT_VPN_TYPE) {
String typeName = data.getStringExtra(KEY_VPN_TYPE);
startVpnEditor(createVpnProfile(typeName));
} else if (requestCode == REQUEST_ADD_OR_EDIT_PROFILE) {
VpnProfile p = data.getParcelableExtra(KEY_VPN_PROFILE);
if (p == null) {
Log.e(TAG, "null object returned by editor");
return;
}
int index = getProfileIndexFromId(p.getId());
if (checkDuplicateName(p, index)) {
final VpnProfile profile = p;
Util.showErrorMessage(this, String.format(getString(R.string.vpn_error_duplicate_name), p.getName()), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int w) {
startVpnEditor(profile);
}
});
return;
}
if (needKeyStoreToSave(p)) {
Runnable action = new Runnable() {
public void run() {
onActivityResult(requestCode, resultCode, data);
}
};
if (!unlockKeyStore(p, action))
return;
}
try {
if (index < 0) {
addProfile(p);
Util.showShortToastMessage(this, String.format(getString(R.string.vpn_profile_added), p.getName()));
} else {
replaceProfile(index, p);
Util.showShortToastMessage(this, String.format(getString(R.string.vpn_profile_replaced), p.getName()));
}
} catch (IOException e) {
final VpnProfile profile = p;
Util.showErrorMessage(this, e + ": " + e.getMessage(), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int w) {
startVpnEditor(profile);
}
});
}
} else {
throw new RuntimeException("unknown request code: " + requestCode);
}
}
use of android.net.vpn.VpnProfile in project android_packages_apps_Settings by LineageOS.
the class VpnSettings method retrieveVpnListFromStorage.
private void retrieveVpnListFromStorage() {
mVpnPreferenceMap = new LinkedHashMap<String, VpnPreference>();
mVpnProfileList = Collections.synchronizedList(new ArrayList<VpnProfile>());
mVpnListContainer.removeAll();
File root = new File(PROFILES_ROOT);
String[] dirs = root.list();
if (dirs == null)
return;
for (String dir : dirs) {
File f = new File(new File(root, dir), PROFILE_OBJ_FILE);
if (!f.exists())
continue;
try {
VpnProfile p = deserialize(f);
if (p == null)
continue;
if (!checkIdConsistency(dir, p))
continue;
mVpnProfileList.add(p);
} catch (IOException e) {
Log.e(TAG, "retrieveVpnListFromStorage()", e);
}
}
Collections.sort(mVpnProfileList, new Comparator<VpnProfile>() {
public int compare(VpnProfile p1, VpnProfile p2) {
return p1.getName().compareTo(p2.getName());
}
public boolean equals(VpnProfile p) {
// not used
return false;
}
});
for (VpnProfile p : mVpnProfileList) {
Preference pref = addPreferenceFor(p, false);
}
disableProfilePreferencesIfOneActive();
}
use of android.net.vpn.VpnProfile in project android_packages_apps_Settings by LineageOS.
the class VpnSettings method onCreateContextMenu.
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
VpnProfile p = getProfile(getProfilePositionFrom((AdapterContextMenuInfo) menuInfo));
if (p != null) {
VpnState state = p.getState();
menu.setHeaderTitle(p.getName());
boolean isIdle = (state == VpnState.IDLE);
boolean isNotConnect = (isIdle || (state == VpnState.DISCONNECTING) || (state == VpnState.CANCELLED));
menu.add(0, CONTEXT_MENU_CONNECT_ID, 0, R.string.vpn_menu_connect).setEnabled(isIdle && (mActiveProfile == null));
menu.add(0, CONTEXT_MENU_DISCONNECT_ID, 0, R.string.vpn_menu_disconnect).setEnabled(state == VpnState.CONNECTED);
menu.add(0, CONTEXT_MENU_EDIT_ID, 0, R.string.vpn_menu_edit).setEnabled(isNotConnect);
menu.add(0, CONTEXT_MENU_DELETE_ID, 0, R.string.vpn_menu_delete).setEnabled(isNotConnect);
}
}
use of android.net.vpn.VpnProfile in project android_packages_apps_Settings by LineageOS.
the class VpnSettings method onContextItemSelected.
@Override
public boolean onContextItemSelected(MenuItem item) {
int position = getProfilePositionFrom((AdapterContextMenuInfo) item.getMenuInfo());
VpnProfile p = getProfile(position);
switch(item.getItemId()) {
case CONTEXT_MENU_CONNECT_ID:
case CONTEXT_MENU_DISCONNECT_ID:
connectOrDisconnect(p);
return true;
case CONTEXT_MENU_EDIT_ID:
startVpnEditor(p);
return true;
case CONTEXT_MENU_DELETE_ID:
deleteProfile(position);
return true;
}
return super.onContextItemSelected(item);
}
Aggregations