Search in sources :

Example 6 with VpnProfile

use of android.net.vpn.VpnProfile in project android_packages_apps_Settings by LineageOS.

the class VpnSettings method deleteProfile.

// position: position in mVpnProfileList
private void deleteProfile(final int position) {
    if ((position < 0) || (position >= mVpnProfileList.size()))
        return;
    DialogInterface.OnClickListener onClickListener = new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            if (which == OK_BUTTON) {
                VpnProfile p = mVpnProfileList.remove(position);
                VpnPreference pref = mVpnPreferenceMap.remove(p.getName());
                mVpnListContainer.removePreference(pref);
                removeProfileFromStorage(p);
            }
        }
    };
    mShowingDialog = new AlertDialog.Builder(this).setTitle(android.R.string.dialog_alert_title).setIcon(android.R.drawable.ic_dialog_alert).setMessage(R.string.vpn_confirm_profile_deletion).setPositiveButton(android.R.string.ok, onClickListener).setNegativeButton(R.string.vpn_no_button, onClickListener).create();
    mShowingDialog.show();
}
Also used : AlertDialog(android.app.AlertDialog) VpnProfile(android.net.vpn.VpnProfile) DialogInterface(android.content.DialogInterface)

Example 7 with VpnProfile

use of android.net.vpn.VpnProfile in project android_packages_apps_Settings by LineageOS.

the class VpnSettings method setProfileId.

// Randomly generates an ID for the profile.
// The ID is unique and only set once when the profile is created.
private void setProfileId(VpnProfile profile) {
    String id;
    while (true) {
        id = String.valueOf(Math.abs(Double.doubleToLongBits(Math.random())));
        if (id.length() >= 8)
            break;
    }
    for (VpnProfile p : mVpnProfileList) {
        if (p.getId().equals(id)) {
            setProfileId(profile);
            return;
        }
    }
    profile.setId(id);
}
Also used : VpnProfile(android.net.vpn.VpnProfile)

Example 8 with VpnProfile

use of android.net.vpn.VpnProfile in project android_packages_apps_Settings by LineageOS.

the class VpnSettings method deserialize.

private VpnProfile deserialize(File profileObjectFile) throws IOException {
    try {
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream(profileObjectFile));
        VpnProfile p = (VpnProfile) ois.readObject();
        ois.close();
        return p;
    } catch (ClassNotFoundException e) {
        Log.d(TAG, "deserialize a profile", e);
        return null;
    }
}
Also used : VpnProfile(android.net.vpn.VpnProfile) FileInputStream(java.io.FileInputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 9 with VpnProfile

use of android.net.vpn.VpnProfile in project android_packages_apps_Settings by LineageOS.

the class VpnEditor method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    VpnProfile p = (VpnProfile) ((savedInstanceState == null) ? getIntent().getParcelableExtra(VpnSettings.KEY_VPN_PROFILE) : savedInstanceState.getParcelable(KEY_PROFILE));
    mProfileEditor = getEditor(p);
    mAddingProfile = TextUtils.isEmpty(p.getName());
    // Loads the XML preferences file
    addPreferencesFromResource(R.xml.vpn_edit);
    initViewFor(p);
    Parcel parcel = Parcel.obtain();
    p.writeToParcel(parcel, 0);
    mOriginalProfileData = parcel.marshall();
}
Also used : VpnProfile(android.net.vpn.VpnProfile) Parcel(android.os.Parcel)

Aggregations

VpnProfile (android.net.vpn.VpnProfile)9 DialogInterface (android.content.DialogInterface)2 IOException (java.io.IOException)2 AlertDialog (android.app.AlertDialog)1 VpnState (android.net.vpn.VpnState)1 Parcel (android.os.Parcel)1 Preference (android.preference.Preference)1 AdapterContextMenuInfo (android.widget.AdapterView.AdapterContextMenuInfo)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ArrayList (java.util.ArrayList)1