Search in sources :

Example 56 with LinkProperties

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

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 57 with LinkProperties

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

the class NetworkStatsServiceTest method buildWifiState.

private static NetworkState buildWifiState() {
    final NetworkInfo info = new NetworkInfo(TYPE_WIFI, 0, null, null);
    info.setDetailedState(DetailedState.CONNECTED, null, null);
    final LinkProperties prop = new LinkProperties();
    prop.setInterfaceName(TEST_IFACE);
    return new NetworkState(info, prop, null, null, null, TEST_SSID);
}
Also used : NetworkInfo(android.net.NetworkInfo) NetworkState(android.net.NetworkState) LinkProperties(android.net.LinkProperties)

Example 58 with LinkProperties

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

the class ConnectivityService method requestRouteToHostAddress.

/**
     * Ensure that a network route exists to deliver traffic to the specified
     * host via the specified network interface.
     * @param networkType the type of the network over which traffic to the
     * specified host is to be routed
     * @param hostAddress the IP address of the host to which the route is
     * desired
     * @return {@code true} on success, {@code false} on failure
     */
@Override
public boolean requestRouteToHostAddress(int networkType, byte[] hostAddress) {
    enforceChangePermission();
    if (mProtectedNetworks.contains(networkType)) {
        enforceConnectivityInternalPermission();
    }
    InetAddress addr;
    try {
        addr = InetAddress.getByAddress(hostAddress);
    } catch (UnknownHostException e) {
        if (DBG)
            log("requestRouteToHostAddress got " + e.toString());
        return false;
    }
    if (!ConnectivityManager.isNetworkTypeValid(networkType)) {
        if (DBG)
            log("requestRouteToHostAddress on invalid network: " + networkType);
        return false;
    }
    NetworkAgentInfo nai = mLegacyTypeTracker.getNetworkForType(networkType);
    if (nai == null) {
        if (mLegacyTypeTracker.isTypeSupported(networkType) == false) {
            if (DBG)
                log("requestRouteToHostAddress on unsupported network: " + networkType);
        } else {
            if (DBG)
                log("requestRouteToHostAddress on down network: " + networkType);
        }
        return false;
    }
    DetailedState netState;
    synchronized (nai) {
        netState = nai.networkInfo.getDetailedState();
    }
    if (netState != DetailedState.CONNECTED && netState != DetailedState.CAPTIVE_PORTAL_CHECK) {
        if (VDBG) {
            log("requestRouteToHostAddress on down network " + "(" + networkType + ") - dropped" + " netState=" + netState);
        }
        return false;
    }
    final int uid = Binder.getCallingUid();
    final long token = Binder.clearCallingIdentity();
    try {
        LinkProperties lp;
        int netId;
        synchronized (nai) {
            lp = nai.linkProperties;
            netId = nai.network.netId;
        }
        boolean ok = addLegacyRouteToHost(lp, addr, netId, uid);
        if (DBG)
            log("requestRouteToHostAddress ok=" + ok);
        return ok;
    } finally {
        Binder.restoreCallingIdentity(token);
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) NetworkAgentInfo(com.android.server.connectivity.NetworkAgentInfo) DetailedState(android.net.NetworkInfo.DetailedState) InetAddress(java.net.InetAddress) LinkProperties(android.net.LinkProperties)

Example 59 with LinkProperties

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

the class ConnectivityService method logDefaultNetworkEvent.

private void logDefaultNetworkEvent(NetworkAgentInfo newNai, NetworkAgentInfo prevNai) {
    int newNetid = NETID_UNSET;
    int prevNetid = NETID_UNSET;
    int[] transports = new int[0];
    boolean hadIPv4 = false;
    boolean hadIPv6 = false;
    if (newNai != null) {
        newNetid = newNai.network.netId;
        transports = newNai.networkCapabilities.getTransportTypes();
    }
    if (prevNai != null) {
        prevNetid = prevNai.network.netId;
        final LinkProperties lp = prevNai.linkProperties;
        hadIPv4 = lp.hasIPv4Address() && lp.hasIPv4DefaultRoute();
        hadIPv6 = lp.hasGlobalIPv6Address() && lp.hasIPv6DefaultRoute();
    }
    mMetricsLog.log(new DefaultNetworkEvent(newNetid, transports, prevNetid, hadIPv4, hadIPv6));
}
Also used : DefaultNetworkEvent(android.net.metrics.DefaultNetworkEvent) LinkProperties(android.net.LinkProperties)

Example 60 with LinkProperties

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

the class ConnectivityService method callCallbackForRequest.

private void callCallbackForRequest(NetworkRequestInfo nri, NetworkAgentInfo networkAgent, int notificationType, int arg1) {
    // Default request has no msgr
    if (nri.messenger == null)
        return;
    Bundle bundle = new Bundle();
    bundle.putParcelable(NetworkRequest.class.getSimpleName(), new NetworkRequest(nri.request));
    Message msg = Message.obtain();
    if (notificationType != ConnectivityManager.CALLBACK_UNAVAIL && notificationType != ConnectivityManager.CALLBACK_RELEASED) {
        bundle.putParcelable(Network.class.getSimpleName(), networkAgent.network);
    }
    switch(notificationType) {
        case ConnectivityManager.CALLBACK_LOSING:
            {
                msg.arg1 = arg1;
                break;
            }
        case ConnectivityManager.CALLBACK_CAP_CHANGED:
            {
                bundle.putParcelable(NetworkCapabilities.class.getSimpleName(), new NetworkCapabilities(networkAgent.networkCapabilities));
                break;
            }
        case ConnectivityManager.CALLBACK_IP_CHANGED:
            {
                bundle.putParcelable(LinkProperties.class.getSimpleName(), new LinkProperties(networkAgent.linkProperties));
                break;
            }
    }
    msg.what = notificationType;
    msg.setData(bundle);
    try {
        if (VDBG) {
            log("sending notification " + notifyTypeToName(notificationType) + " for " + nri.request);
        }
        nri.messenger.send(msg);
    } catch (RemoteException e) {
        // may occur naturally in the race of binder death.
        loge("RemoteException caught trying to send a callback msg for " + nri.request);
    }
}
Also used : Message(android.os.Message) WakeupMessage(com.android.internal.util.WakeupMessage) Bundle(android.os.Bundle) Network(android.net.Network) NetworkRequest(android.net.NetworkRequest) RemoteException(android.os.RemoteException) NetworkCapabilities(android.net.NetworkCapabilities) LinkProperties(android.net.LinkProperties)

Aggregations

LinkProperties (android.net.LinkProperties)283 RouteInfo (android.net.RouteInfo)72 LinkAddress (android.net.LinkAddress)70 SmallTest (android.test.suitebuilder.annotation.SmallTest)66 InetAddress (java.net.InetAddress)52 NetworkAgentInfo (com.android.server.connectivity.NetworkAgentInfo)40 NetworkInfo (android.net.NetworkInfo)38 NetworkState (android.net.NetworkState)36 RemoteException (android.os.RemoteException)36 NetworkCapabilities (android.net.NetworkCapabilities)23 Network (android.net.Network)21 ProvisioningChange (android.net.LinkProperties.ProvisioningChange)20 ArrayList (java.util.ArrayList)17 IpPrefix (android.net.IpPrefix)15 Inet6Address (java.net.Inet6Address)15 NetworkRequest (android.net.NetworkRequest)14 ApfFilter (android.net.apf.ApfFilter)12 LargeTest (android.test.suitebuilder.annotation.LargeTest)12 UnknownHostException (java.net.UnknownHostException)12 NetworkMisc (android.net.NetworkMisc)10