Search in sources :

Example 31 with DhcpResults

use of android.net.DhcpResults in project platform_frameworks_base by android.

the class IpManager method handleIPv4Success.

private void handleIPv4Success(DhcpResults dhcpResults) {
    mDhcpResults = new DhcpResults(dhcpResults);
    final LinkProperties newLp = assembleLinkProperties();
    final ProvisioningChange delta = setLinkProperties(newLp);
    if (VDBG) {
        Log.d(mTag, "onNewDhcpResults(" + Objects.toString(dhcpResults) + ")");
    }
    mCallback.onNewDhcpResults(dhcpResults);
    dispatchCallback(delta, newLp);
}
Also used : DhcpResults(android.net.DhcpResults) ProvisioningChange(android.net.LinkProperties.ProvisioningChange) LinkProperties(android.net.LinkProperties)

Example 32 with DhcpResults

use of android.net.DhcpResults in project platform_frameworks_base by android.

the class IpManager method startIPv4.

private boolean startIPv4() {
    // handle the result accordingly.
    if (mConfiguration.mStaticIpConfig != null) {
        if (setIPv4Address(mConfiguration.mStaticIpConfig.ipAddress)) {
            handleIPv4Success(new DhcpResults(mConfiguration.mStaticIpConfig));
        } else {
            return false;
        }
    } else {
        // Start DHCPv4.
        mDhcpClient = DhcpClient.makeDhcpClient(mContext, IpManager.this, mInterfaceName);
        mDhcpClient.registerForPreDhcpNotification();
        mDhcpClient.sendMessage(DhcpClient.CMD_START_DHCP);
    }
    return true;
}
Also used : DhcpResults(android.net.DhcpResults)

Example 33 with DhcpResults

use of android.net.DhcpResults in project android_frameworks_base by DirtyUnicorns.

the class IpManager method handleIPv4Success.

private void handleIPv4Success(DhcpResults dhcpResults) {
    mDhcpResults = new DhcpResults(dhcpResults);
    final LinkProperties newLp = assembleLinkProperties();
    final ProvisioningChange delta = setLinkProperties(newLp);
    if (VDBG) {
        Log.d(mTag, "onNewDhcpResults(" + Objects.toString(dhcpResults) + ")");
    }
    mCallback.onNewDhcpResults(dhcpResults);
    dispatchCallback(delta, newLp);
}
Also used : DhcpResults(android.net.DhcpResults) ProvisioningChange(android.net.LinkProperties.ProvisioningChange) LinkProperties(android.net.LinkProperties)

Example 34 with DhcpResults

use of android.net.DhcpResults in project android_frameworks_base by DirtyUnicorns.

the class DhcpPacketTest method checkIpAddress.

private void checkIpAddress(String expected, byte type, Inet4Address clientIp, Inet4Address yourIp, byte[] netmaskBytes) throws Exception {
    ByteBuffer packet = new TestDhcpPacket(type, clientIp, yourIp).setNetmaskBytes(netmaskBytes).build();
    DhcpPacket offerPacket = DhcpPacket.decodeFullPacket(packet, ENCAP_BOOTP);
    DhcpResults results = offerPacket.toDhcpResults();
    if (expected != null) {
        LinkAddress expectedAddress = new LinkAddress(expected);
        assertEquals(expectedAddress, results.ipAddress);
    } else {
        assertNull(results);
    }
}
Also used : LinkAddress(android.net.LinkAddress) DhcpResults(android.net.DhcpResults) ByteBuffer(java.nio.ByteBuffer) DhcpPacket(android.net.dhcp.DhcpPacket)

Example 35 with DhcpResults

use of android.net.DhcpResults in project android_frameworks_base by DirtyUnicorns.

the class DhcpPacketTest method assertLeaseTimeParses.

private void assertLeaseTimeParses(boolean expectValid, Integer rawLeaseTime, long leaseTimeMillis, byte[] leaseTimeBytes) throws Exception {
    TestDhcpPacket testPacket = new TestDhcpPacket(DHCP_MESSAGE_TYPE_OFFER);
    if (leaseTimeBytes != null) {
        testPacket.setLeaseTimeBytes(leaseTimeBytes);
    }
    ByteBuffer packet = testPacket.build();
    DhcpPacket offerPacket = null;
    if (!expectValid) {
        try {
            offerPacket = DhcpPacket.decodeFullPacket(packet, ENCAP_BOOTP);
            fail("Invalid packet parsed successfully: " + offerPacket);
        } catch (ParseException expected) {
        }
        return;
    }
    offerPacket = DhcpPacket.decodeFullPacket(packet, ENCAP_BOOTP);
    assertNotNull(offerPacket);
    assertEquals(rawLeaseTime, offerPacket.mLeaseTime);
    // Just check this doesn't crash.
    DhcpResults dhcpResults = offerPacket.toDhcpResults();
    assertEquals(leaseTimeMillis, offerPacket.getLeaseTimeMillis());
}
Also used : DhcpResults(android.net.DhcpResults) ByteBuffer(java.nio.ByteBuffer) DhcpPacket(android.net.dhcp.DhcpPacket)

Aggregations

DhcpResults (android.net.DhcpResults)55 DhcpPacket (android.net.dhcp.DhcpPacket)40 ByteBuffer (java.nio.ByteBuffer)36 SmallTest (android.test.suitebuilder.annotation.SmallTest)28 LinkAddress (android.net.LinkAddress)9 Inet4Address (java.net.Inet4Address)5 LinkProperties (android.net.LinkProperties)4 ProvisioningChange (android.net.LinkProperties.ProvisioningChange)4 DhcpInfo (android.net.DhcpInfo)1 NetworkInfo (android.net.NetworkInfo)1 RouteInfo (android.net.RouteInfo)1 Message (android.os.Message)1 InetAddress (java.net.InetAddress)1