Search in sources :

Example 1 with LinkProperties

use of android.net.LinkProperties in project android_frameworks_base by ParanoidAndroid.

the class ConnectivityService method startLegacyVpn.

/**
     * Start legacy VPN, controlling native daemons as needed. Creates a
     * secondary thread to perform connection work, returning quickly.
     */
@Override
public void startLegacyVpn(VpnProfile profile) {
    throwIfLockdownEnabled();
    final LinkProperties egress = getActiveLinkProperties();
    if (egress == null) {
        throw new IllegalStateException("Missing active network connection");
    }
    mVpn.startLegacyVpn(profile, mKeyStore, egress);
}
Also used : LinkProperties(android.net.LinkProperties)

Example 2 with LinkProperties

use of android.net.LinkProperties in project android_frameworks_base by ParanoidAndroid.

the class ConnectivityService method handleDisconnect.

/**
     * Handle a {@code DISCONNECTED} event. If this pertains to the non-active
     * network, we ignore it. If it is for the active network, we send out a
     * broadcast. But first, we check whether it might be possible to connect
     * to a different network.
     * @param info the {@code NetworkInfo} for the network
     */
private void handleDisconnect(NetworkInfo info) {
    int prevNetType = info.getType();
    mNetTrackers[prevNetType].setTeardownRequested(false);
    // Remove idletimer previously setup in {@code handleConnect}
    removeDataActivityTracking(prevNetType);
    /*
         * If the disconnected network is not the active one, then don't report
         * this as a loss of connectivity. What probably happened is that we're
         * getting the disconnect for a network that we explicitly disabled
         * in accordance with network preference policies.
         */
    if (!mNetConfigs[prevNetType].isDefault()) {
        List<Integer> pids = mNetRequestersPids[prevNetType];
        for (Integer pid : pids) {
            // will remove them because the net's no longer connected
            // need to do this now as only now do we know the pids and
            // can properly null things that are no longer referenced.
            reassessPidDns(pid.intValue(), false);
        }
    }
    Intent intent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
    intent.putExtra(ConnectivityManager.EXTRA_NETWORK_INFO, new NetworkInfo(info));
    intent.putExtra(ConnectivityManager.EXTRA_NETWORK_TYPE, info.getType());
    if (info.isFailover()) {
        intent.putExtra(ConnectivityManager.EXTRA_IS_FAILOVER, true);
        info.setFailover(false);
    }
    if (info.getReason() != null) {
        intent.putExtra(ConnectivityManager.EXTRA_REASON, info.getReason());
    }
    if (info.getExtraInfo() != null) {
        intent.putExtra(ConnectivityManager.EXTRA_EXTRA_INFO, info.getExtraInfo());
    }
    if (mNetConfigs[prevNetType].isDefault()) {
        tryFailover(prevNetType);
        if (mActiveDefaultNetwork != -1) {
            NetworkInfo switchTo = mNetTrackers[mActiveDefaultNetwork].getNetworkInfo();
            intent.putExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO, switchTo);
        } else {
            // we're not connected anymore
            mDefaultInetConditionPublished = 0;
            intent.putExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, true);
        }
    }
    intent.putExtra(ConnectivityManager.EXTRA_INET_CONDITION, mDefaultInetConditionPublished);
    // Reset interface if no other connections are using the same interface
    boolean doReset = true;
    LinkProperties linkProperties = mNetTrackers[prevNetType].getLinkProperties();
    if (linkProperties != null) {
        String oldIface = linkProperties.getInterfaceName();
        if (TextUtils.isEmpty(oldIface) == false) {
            for (NetworkStateTracker networkStateTracker : mNetTrackers) {
                if (networkStateTracker == null)
                    continue;
                NetworkInfo networkInfo = networkStateTracker.getNetworkInfo();
                if (networkInfo.isConnected() && networkInfo.getType() != prevNetType) {
                    LinkProperties l = networkStateTracker.getLinkProperties();
                    if (l == null)
                        continue;
                    if (oldIface.equals(l.getInterfaceName())) {
                        doReset = false;
                        break;
                    }
                }
            }
        }
    }
    // do this before we broadcast the change
    handleConnectivityChange(prevNetType, doReset);
    final Intent immediateIntent = new Intent(intent);
    immediateIntent.setAction(CONNECTIVITY_ACTION_IMMEDIATE);
    sendStickyBroadcast(immediateIntent);
    sendStickyBroadcastDelayed(intent, getConnectivityChangeDelay());
    /*
         * If the failover network is already connected, then immediately send
         * out a followup broadcast indicating successful failover
         */
    if (mActiveDefaultNetwork != -1) {
        sendConnectedBroadcastDelayed(mNetTrackers[mActiveDefaultNetwork].getNetworkInfo(), getConnectivityChangeDelay());
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NetworkInfo(android.net.NetworkInfo) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) NetworkStateTracker(android.net.NetworkStateTracker) LinkProperties(android.net.LinkProperties)

Example 3 with LinkProperties

use of android.net.LinkProperties in project android_frameworks_base by ParanoidAndroid.

the class LockdownVpnTracker method handleStateChangedLocked.

/**
     * Watch for state changes to both active egress network, kicking off a VPN
     * connection when ready, or setting firewall rules once VPN is connected.
     */
private void handleStateChangedLocked() {
    Slog.d(TAG, "handleStateChanged()");
    final NetworkInfo egressInfo = mConnService.getActiveNetworkInfoUnfiltered();
    final LinkProperties egressProp = mConnService.getActiveLinkProperties();
    final NetworkInfo vpnInfo = mVpn.getNetworkInfo();
    final VpnConfig vpnConfig = mVpn.getLegacyVpnConfig();
    // Restart VPN when egress network disconnected or changed
    final boolean egressDisconnected = egressInfo == null || State.DISCONNECTED.equals(egressInfo.getState());
    final boolean egressChanged = egressProp == null || !TextUtils.equals(mAcceptedEgressIface, egressProp.getInterfaceName());
    if (egressDisconnected || egressChanged) {
        clearSourceRulesLocked();
        mAcceptedEgressIface = null;
        mVpn.stopLegacyVpn();
    }
    if (egressDisconnected) {
        hideNotification();
        return;
    }
    final int egressType = egressInfo.getType();
    if (vpnInfo.getDetailedState() == DetailedState.FAILED) {
        EventLogTags.writeLockdownVpnError(egressType);
    }
    if (mErrorCount > MAX_ERROR_COUNT) {
        showNotification(R.string.vpn_lockdown_error, R.drawable.vpn_disconnected);
    } else if (egressInfo.isConnected() && !vpnInfo.isConnectedOrConnecting()) {
        if (mProfile.isValidLockdownProfile()) {
            Slog.d(TAG, "Active network connected; starting VPN");
            EventLogTags.writeLockdownVpnConnecting(egressType);
            showNotification(R.string.vpn_lockdown_connecting, R.drawable.vpn_disconnected);
            mAcceptedEgressIface = egressProp.getInterfaceName();
            mVpn.startLegacyVpn(mProfile, KeyStore.getInstance(), egressProp);
        } else {
            Slog.e(TAG, "Invalid VPN profile; requires IP-based server and DNS");
            showNotification(R.string.vpn_lockdown_error, R.drawable.vpn_disconnected);
        }
    } else if (vpnInfo.isConnected() && vpnConfig != null) {
        final String iface = vpnConfig.interfaze;
        final String sourceAddr = vpnConfig.addresses;
        if (TextUtils.equals(iface, mAcceptedIface) && TextUtils.equals(sourceAddr, mAcceptedSourceAddr)) {
            return;
        }
        Slog.d(TAG, "VPN connected using iface=" + iface + ", sourceAddr=" + sourceAddr);
        EventLogTags.writeLockdownVpnConnected(egressType);
        showNotification(R.string.vpn_lockdown_connected, R.drawable.vpn_connected);
        try {
            clearSourceRulesLocked();
            mNetService.setFirewallInterfaceRule(iface, true);
            mNetService.setFirewallEgressSourceRule(sourceAddr, true);
            mErrorCount = 0;
            mAcceptedIface = iface;
            mAcceptedSourceAddr = sourceAddr;
        } catch (RemoteException e) {
            throw new RuntimeException("Problem setting firewall rules", e);
        }
        mConnService.sendConnectedBroadcast(augmentNetworkInfo(egressInfo));
    }
}
Also used : VpnConfig(com.android.internal.net.VpnConfig) NetworkInfo(android.net.NetworkInfo) RemoteException(android.os.RemoteException) LinkProperties(android.net.LinkProperties)

Example 4 with LinkProperties

use of android.net.LinkProperties in project android_frameworks_base by ParanoidAndroid.

the class NetworkStatsServiceTest method expectNetworkState.

private void expectNetworkState(NetworkState... state) throws Exception {
    expect(mConnManager.getAllNetworkState()).andReturn(state).atLeastOnce();
    final LinkProperties linkProp = state.length > 0 ? state[0].linkProperties : null;
    expect(mConnManager.getActiveLinkProperties()).andReturn(linkProp).atLeastOnce();
}
Also used : LinkProperties(android.net.LinkProperties)

Example 5 with LinkProperties

use of android.net.LinkProperties in project android_frameworks_base by ParanoidAndroid.

the class NetworkStatsServiceTest method buildMobile3gState.

private static NetworkState buildMobile3gState(String subscriberId) {
    final NetworkInfo info = new NetworkInfo(TYPE_MOBILE, TelephonyManager.NETWORK_TYPE_UMTS, null, null);
    info.setDetailedState(DetailedState.CONNECTED, null, null);
    final LinkProperties prop = new LinkProperties();
    prop.setInterfaceName(TEST_IFACE);
    return new NetworkState(info, prop, null, subscriberId, null);
}
Also used : NetworkInfo(android.net.NetworkInfo) NetworkState(android.net.NetworkState) LinkProperties(android.net.LinkProperties)

Aggregations

LinkProperties (android.net.LinkProperties)330 LinkAddress (android.net.LinkAddress)78 RouteInfo (android.net.RouteInfo)73 SmallTest (android.test.suitebuilder.annotation.SmallTest)68 InetAddress (java.net.InetAddress)56 Network (android.net.Network)43 NetworkInfo (android.net.NetworkInfo)40 NetworkAgentInfo (com.android.server.connectivity.NetworkAgentInfo)40 RemoteException (android.os.RemoteException)37 NetworkState (android.net.NetworkState)36 NetworkCapabilities (android.net.NetworkCapabilities)25 NetworkRequest (android.net.NetworkRequest)22 ArrayList (java.util.ArrayList)22 ProvisioningChange (android.net.LinkProperties.ProvisioningChange)20 Test (org.junit.Test)19 ConnectivityManager (android.net.ConnectivityManager)17 IpPrefix (android.net.IpPrefix)15 Inet6Address (java.net.Inet6Address)15 UnknownHostException (java.net.UnknownHostException)13 ApfFilter (android.net.apf.ApfFilter)12