Search in sources :

Example 11 with LinkProperties

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

the class LinkPropertiesTest method testEqualsNull.

@SmallTest
public void testEqualsNull() {
    LinkProperties source = new LinkProperties();
    LinkProperties target = new LinkProperties();
    assertFalse(source == target);
    assertLinkPropertiesEqual(source, target);
}
Also used : LinkProperties(android.net.LinkProperties) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 12 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 13 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 14 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 15 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)

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