Search in sources :

Example 46 with LinkProperties

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

the class LinkPropertiesTest method testEqualsDuplicated.

@SmallTest
public void testEqualsDuplicated() {
    try {
        LinkProperties source = new LinkProperties();
        // set 3 link addresses, eg, [A, A, B]
        source.addLinkAddress(new LinkAddress(NetworkUtils.numericToInetAddress(ADDRV4), 32));
        source.addLinkAddress(new LinkAddress(NetworkUtils.numericToInetAddress(ADDRV4), 32));
        source.addLinkAddress(new LinkAddress(NetworkUtils.numericToInetAddress(ADDRV6), 128));
        LinkProperties target = new LinkProperties();
        // set 3 link addresses, eg, [A, B, B]
        target.addLinkAddress(new LinkAddress(NetworkUtils.numericToInetAddress(ADDRV4), 32));
        target.addLinkAddress(new LinkAddress(NetworkUtils.numericToInetAddress(ADDRV6), 128));
        target.addLinkAddress(new LinkAddress(NetworkUtils.numericToInetAddress(ADDRV6), 128));
        assertLinkPropertiesEqual(source, target);
    } catch (Exception e) {
        fail();
    }
}
Also used : LinkProperties(android.net.LinkProperties) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 47 with LinkProperties

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

the class LinkPropertiesTest method testStackedInterfaces.

@SmallTest
public void testStackedInterfaces() {
    LinkProperties rmnet0 = new LinkProperties();
    rmnet0.setInterfaceName("rmnet0");
    LinkProperties clat4 = new LinkProperties();
    clat4.setInterfaceName("clat4");
    assertEquals(0, rmnet0.getStackedLinks().size());
    rmnet0.addStackedLink(clat4);
    assertEquals(1, rmnet0.getStackedLinks().size());
    rmnet0.addStackedLink(clat4);
    assertEquals(1, rmnet0.getStackedLinks().size());
    assertEquals(0, clat4.getStackedLinks().size());
    // Modify an item in the returned collection to see what happens.
    for (LinkProperties link : rmnet0.getStackedLinks()) {
        if (link.getInterfaceName().equals("clat4")) {
            link.setInterfaceName("newname");
        }
    }
    for (LinkProperties link : rmnet0.getStackedLinks()) {
        assertFalse("newname".equals(link.getInterfaceName()));
    }
}
Also used : LinkProperties(android.net.LinkProperties) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 48 with LinkProperties

use of android.net.LinkProperties in project XobotOS by xamarin.

the class DefaultPhoneNotifier method doNotifyDataConnection.

private void doNotifyDataConnection(Phone sender, String reason, String apnType, Phone.DataState state) {
    // TODO
    // use apnType as the key to which connection we're talking about.
    // pass apnType back up to fetch particular for this one.
    TelephonyManager telephony = TelephonyManager.getDefault();
    LinkProperties linkProperties = null;
    LinkCapabilities linkCapabilities = null;
    boolean roaming = false;
    if (state == Phone.DataState.CONNECTED) {
        linkProperties = sender.getLinkProperties(apnType);
        linkCapabilities = sender.getLinkCapabilities(apnType);
    }
    ServiceState ss = sender.getServiceState();
    if (ss != null)
        roaming = ss.getRoaming();
    try {
        mRegistry.notifyDataConnection(convertDataState(state), sender.isDataConnectivityPossible(apnType), reason, sender.getActiveApnHost(apnType), apnType, linkProperties, linkCapabilities, ((telephony != null) ? telephony.getNetworkType() : TelephonyManager.NETWORK_TYPE_UNKNOWN), roaming);
    } catch (RemoteException ex) {
    // system process is dead
    }
}
Also used : ServiceState(android.telephony.ServiceState) TelephonyManager(android.telephony.TelephonyManager) RemoteException(android.os.RemoteException) LinkProperties(android.net.LinkProperties) LinkCapabilities(android.net.LinkCapabilities)

Example 49 with LinkProperties

use of android.net.LinkProperties in project XobotOS by xamarin.

the class DataCallState method setLinkProperties.

public SetupResult setLinkProperties(LinkProperties linkProperties, boolean okToUseSystemPropertyDns) {
    SetupResult result;
    // a failure we'll clear again at the bottom of this code.
    if (linkProperties == null)
        linkProperties = new LinkProperties();
    else
        linkProperties.clear();
    if (status == FailCause.NONE.getErrorCode()) {
        String propertyPrefix = "net." + ifname + ".";
        try {
            // set interface name
            linkProperties.setInterfaceName(ifname);
            // set link addresses
            if (addresses != null && addresses.length > 0) {
                for (String addr : addresses) {
                    LinkAddress la;
                    int addrPrefixLen;
                    String[] ap = addr.split("/");
                    if (ap.length == 2) {
                        addr = ap[0];
                        addrPrefixLen = Integer.parseInt(ap[1]);
                    } else {
                        addrPrefixLen = 0;
                    }
                    InetAddress ia;
                    try {
                        ia = NetworkUtils.numericToInetAddress(addr);
                    } catch (IllegalArgumentException e) {
                        throw new UnknownHostException("Non-numeric ip addr=" + addr);
                    }
                    if (!ia.isAnyLocalAddress()) {
                        if (addrPrefixLen == 0) {
                            // Assume point to point
                            addrPrefixLen = (ia instanceof Inet4Address) ? 32 : 128;
                        }
                        if (DBG)
                            Log.d(LOG_TAG, "addr/pl=" + addr + "/" + addrPrefixLen);
                        la = new LinkAddress(ia, addrPrefixLen);
                        linkProperties.addLinkAddress(la);
                    }
                }
            } else {
                throw new UnknownHostException("no address for ifname=" + ifname);
            }
            // set dns servers
            if (dnses != null && dnses.length > 0) {
                for (String addr : dnses) {
                    InetAddress ia;
                    try {
                        ia = NetworkUtils.numericToInetAddress(addr);
                    } catch (IllegalArgumentException e) {
                        throw new UnknownHostException("Non-numeric dns addr=" + addr);
                    }
                    if (!ia.isAnyLocalAddress()) {
                        linkProperties.addDns(ia);
                    }
                }
            } else if (okToUseSystemPropertyDns) {
                String[] dnsServers = new String[2];
                dnsServers[0] = SystemProperties.get(propertyPrefix + "dns1");
                dnsServers[1] = SystemProperties.get(propertyPrefix + "dns2");
                for (String dnsAddr : dnsServers) {
                    InetAddress ia;
                    try {
                        ia = NetworkUtils.numericToInetAddress(dnsAddr);
                    } catch (IllegalArgumentException e) {
                        throw new UnknownHostException("Non-numeric dns addr=" + dnsAddr);
                    }
                    if (!ia.isAnyLocalAddress()) {
                        linkProperties.addDns(ia);
                    }
                }
            } else {
                throw new UnknownHostException("Empty dns response and no system default dns");
            }
            // set gateways
            if ((gateways == null) || (gateways.length == 0)) {
                String sysGateways = SystemProperties.get(propertyPrefix + "gw");
                if (sysGateways != null) {
                    gateways = sysGateways.split(" ");
                } else {
                    gateways = new String[0];
                }
            }
            for (String addr : gateways) {
                InetAddress ia;
                try {
                    ia = NetworkUtils.numericToInetAddress(addr);
                } catch (IllegalArgumentException e) {
                    throw new UnknownHostException("Non-numeric gateway addr=" + addr);
                }
                if (!ia.isAnyLocalAddress()) {
                    linkProperties.addRoute(new RouteInfo(ia));
                }
            }
            result = SetupResult.SUCCESS;
        } catch (UnknownHostException e) {
            Log.d(LOG_TAG, "setLinkProperties: UnknownHostException " + e);
            e.printStackTrace();
            result = SetupResult.ERR_UnacceptableParameter;
        }
    } else {
        if (version < 4) {
            result = SetupResult.ERR_GetLastErrorFromRil;
        } else {
            result = SetupResult.ERR_RilError;
        }
    }
    // An error occurred so clear properties
    if (result != SetupResult.SUCCESS) {
        if (DBG) {
            Log.d(LOG_TAG, "setLinkProperties: error clearing LinkProperties " + "status=" + status + " result=" + result);
        }
        linkProperties.clear();
    }
    return result;
}
Also used : LinkAddress(android.net.LinkAddress) Inet4Address(java.net.Inet4Address) UnknownHostException(java.net.UnknownHostException) RouteInfo(android.net.RouteInfo) LinkProperties(android.net.LinkProperties) InetAddress(java.net.InetAddress)

Example 50 with LinkProperties

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

the class NetworkManagementService method initDataInterface.

private void initDataInterface() {
    if (!TextUtils.isEmpty(mDataInterfaceName)) {
        return;
    }
    ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
    LinkProperties linkProperties = cm.getLinkProperties(ConnectivityManager.TYPE_MOBILE);
    if (linkProperties != null) {
        mDataInterfaceName = linkProperties.getInterfaceName();
    }
}
Also used : ConnectivityManager(android.net.ConnectivityManager) 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