Search in sources :

Example 1 with VpnState

use of android.net.vpn.VpnState 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);
    }
}
Also used : VpnProfile(android.net.vpn.VpnProfile) VpnState(android.net.vpn.VpnState) AdapterContextMenuInfo(android.widget.AdapterView.AdapterContextMenuInfo)

Example 2 with VpnState

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

the class VpnSettings method changeState.

private void changeState(VpnProfile p, VpnState state) {
    VpnState oldState = p.getState();
    if (oldState == state)
        return;
    p.setState(state);
    mVpnPreferenceMap.get(p.getName()).setSummary(getProfileSummaryString(p));
    switch(state) {
        case CONNECTED:
            mConnectingActor = null;
            mActiveProfile = p;
            disableProfilePreferencesIfOneActive();
            break;
        case CONNECTING:
            mConnectingActor = getActor(p);
        // pass through
        case DISCONNECTING:
            mActiveProfile = p;
            disableProfilePreferencesIfOneActive();
            break;
        case CANCELLED:
            changeState(p, VpnState.IDLE);
            break;
        case IDLE:
            assert (mActiveProfile == p);
            if (mConnectingErrorCode == NO_ERROR) {
                onIdle();
            } else {
                showDialog(mConnectingErrorCode);
                mConnectingErrorCode = NO_ERROR;
            }
            break;
    }
}
Also used : VpnState(android.net.vpn.VpnState)

Aggregations

VpnState (android.net.vpn.VpnState)2 VpnProfile (android.net.vpn.VpnProfile)1 AdapterContextMenuInfo (android.widget.AdapterView.AdapterContextMenuInfo)1