Java Code Examples for de.blinkt.openvpn.core.VpnStatus#ConnectionStatus

The following examples show how to use de.blinkt.openvpn.core.VpnStatus#ConnectionStatus . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServerActivity.java    From EasyVPN-Free with GNU General Public License v3.0 5 votes vote down vote up
private void changeServerStatus(VpnStatus.ConnectionStatus status) {
    switch (status) {
        case LEVEL_CONNECTED:
            statusConnection = true;
            connectingProgress.setVisibility(View.GONE);

            if (!inBackground) {
                if (PropertiesService.getDownloaded() >= 104857600 && PropertiesService.getShowRating()
                        && BuildConfig.FLAVOR != "underground") {
                    PropertiesService.setShowRating(false);
                    showRating();
                } else {
                    chooseAction();
                }
            }

            serverConnect.setText(getString(R.string.server_btn_disconnect));
            break;
        case LEVEL_NOTCONNECTED:
            serverConnect.setText(getString(R.string.server_btn_connect));
            break;
        default:
            serverConnect.setText(getString(R.string.server_btn_disconnect));
            statusConnection = false;
            connectingProgress.setVisibility(View.VISIBLE);
    }
}
 
Example 2
Source File: ConnectingDialogFragment.java    From android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void updateState(final String state, String logmessage, final int localizedResId, VpnStatus.ConnectionStatus level) {
    ThreadUtils.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (!state.equals("NOPROCESS") && mAttached) {
                mDialog.setMessage(getString(localizedResId));
            }
        }
    });
}
 
Example 3
Source File: VPNhtApplication.java    From android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void updateState(String state, String logmessage, int localizedResId, VpnStatus.ConnectionStatus level) {
    if(!mCreated) {
        mCreated = true;
        return;
    }

    if(level.equals(VpnStatus.ConnectionStatus.LEVEL_NOTCONNECTED)) {
        PrefUtils.remove(this, Preferences.LAST_CONNECTED_HOSTNAME);
        PrefUtils.remove(this, Preferences.LAST_CONNECTED_FIREWALL);
        PrefUtils.remove(this, Preferences.LAST_CONNECTED_COUNTRY);
    }
}
 
Example 4
Source File: StatusInfo.java    From SimpleOpenVpn-Android with Apache License 2.0 4 votes vote down vote up
public VpnStatus.ConnectionStatus getLevel() {
    return level;
}
 
Example 5
Source File: StatusInfo.java    From SimpleOpenVpn-Android with Apache License 2.0 4 votes vote down vote up
public void setLevel(VpnStatus.ConnectionStatus level) {
    this.level = level;
}
 
Example 6
Source File: VPNActivity.java    From SimpleOpenVpn-Android with Apache License 2.0 4 votes vote down vote up
@Override
    public void updateState(String state, String logmessage, int localizedResId, VpnStatus.ConnectionStatus level) {
        BindUtils.bindStatus(state, logmessage, localizedResId, level);
        // 分发到事件监听
        for (VPNStatusListener vpnStatusListener : mVPNStatusListener) {
            switch (level) {
                case LEVEL_START:
                    // 开始连接
                    vpnStatusListener.onConnectStart();
                    break;
                case LEVEL_CONNECTED:
                    // 已连接
                    vpnStatusListener.onConnected();
                    break;
                case LEVEL_VPNPAUSED:
                    // 暂停
                    vpnStatusListener.onPaused();
                    break;
                case LEVEL_NONETWORK:
                    // 无网络
                    vpnStatusListener.onNoNetwork();
                    break;
                case LEVEL_CONNECTING_SERVER_REPLIED:
                    // 服务器答应
//                    vpnStatusListener.onServerReplied();
                    break;
                case LEVEL_CONNECTING_NO_SERVER_REPLY_YET:
                    // 服务器不答应
//                    vpnStatusListener.onServerNoReplied();
                    break;
                case LEVEL_NOTCONNECTED:
                    // 连接关闭
                    vpnStatusListener.onConnectClose();
                    break;
                case LEVEL_AUTH_FAILED:
                    // 认证失败
                    vpnStatusListener.onAuthFailed();
                    break;
                case LEVEL_WAITING_FOR_USER_INPUT:
                    // 等待用户输入
                    Log.d(TAG, "updateState: " + LEVEL_WAITING_FOR_USER_INPUT);
                    break;
                case UNKNOWN_LEVEL:
                    // 未知错误
                    vpnStatusListener.onUnknown();
                    break;
            }
        }
    }
 
Example 7
Source File: VPNFragment.java    From android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void updateState(final String state, String logmessage, int localizedResId, final VpnStatus.ConnectionStatus level) {
    Timber.d("State: %s", state);
    if(mCurrentVPNState.equals(level))
        return;

    mCurrentVPNState = level;

    if(level.equals(VpnStatus.ConnectionStatus.LEVEL_CONNECTED) || level.equals(VpnStatus.ConnectionStatus.LEVEL_NOTCONNECTED)) {
        new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
            @Override
            public void run() {
                updateIPData();
            }
        }, 500);
        ConnectingDialogFragment.dismiss(getChildFragmentManager());
        DisconnectingDialogFragment.dismiss(getChildFragmentManager());
    }

    ThreadUtils.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if(level.equals(VpnStatus.ConnectionStatus.LEVEL_CONNECTED)) {
                mConnectButton.setVisibility(View.GONE);
                mConnectedCard.setVisibility(View.VISIBLE);
                mConnectCard.setVisibility(View.GONE);
                mDisconnectButton.setVisibility(View.VISIBLE);
            } else if(level.equals(VpnStatus.ConnectionStatus.LEVEL_NOTCONNECTED)) {
                mConnectedCard.setVisibility(View.GONE);
                mDisconnectButton.setVisibility(View.GONE);
                mConnectButton.setVisibility(View.VISIBLE);
                mConnectCard.setVisibility(View.VISIBLE);

                if(VpnStatus.getlogbuffer().length > 10) {
                    for(int i = VpnStatus.getlogbuffer().length - 10; i < VpnStatus.getlogbuffer().length; i++) {
                        VpnStatus.LogItem log = VpnStatus.getlogbuffer()[i];
                        String logString = log.getString(mActivity);
                        if (logString.contains("Cannot open TUN")) {
                            Timber.d("NEEDS REBOOT");
                            RebootDialogFragment.show(getChildFragmentManager());
                            break;
                        }
                    }
                }
            } else {
                ConnectingDialogFragment.show(getChildFragmentManager());
            }
        }
    });
}
 
Example 8
Source File: MainActivity.java    From android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void updateState(String state, String logmessage, int localizedResId, VpnStatus.ConnectionStatus level) {
    mConnected = level.equals(VpnStatus.ConnectionStatus.LEVEL_CONNECTED);
    supportInvalidateOptionsMenu();
}