Search in sources :

Example 1 with DhcpInfoInternal

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

the class DhcpStateMachine method runDhcp.

private boolean runDhcp(DhcpAction dhcpAction) {
    boolean success = false;
    DhcpInfoInternal dhcpInfoInternal = new DhcpInfoInternal();
    if (dhcpAction == DhcpAction.START) {
        if (DBG)
            Log.d(TAG, "DHCP request on " + mInterfaceName);
        success = NetworkUtils.runDhcp(mInterfaceName, dhcpInfoInternal);
        mDhcpInfo = dhcpInfoInternal;
    } else if (dhcpAction == DhcpAction.RENEW) {
        if (DBG)
            Log.d(TAG, "DHCP renewal on " + mInterfaceName);
        success = NetworkUtils.runDhcpRenew(mInterfaceName, dhcpInfoInternal);
        dhcpInfoInternal.updateFromDhcpRequest(mDhcpInfo);
    }
    if (success) {
        if (DBG)
            Log.d(TAG, "DHCP succeeded on " + mInterfaceName);
        //int to long conversion
        long leaseDuration = dhcpInfoInternal.leaseDuration;
        //bad and that the device cannot renew below MIN_RENEWAL_TIME_SECS
        if (leaseDuration < MIN_RENEWAL_TIME_SECS) {
            leaseDuration = MIN_RENEWAL_TIME_SECS;
        }
        //Do it a bit earlier than half the lease duration time
        //to beat the native DHCP client and avoid extra packets
        //48% for one hour lease time = 29 minutes
        mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + //in milliseconds
        leaseDuration * 480, mDhcpRenewalIntent);
        mController.obtainMessage(CMD_POST_DHCP_ACTION, DHCP_SUCCESS, 0, dhcpInfoInternal).sendToTarget();
    } else {
        Log.e(TAG, "DHCP failed on " + mInterfaceName + ": " + NetworkUtils.getDhcpError());
        NetworkUtils.stopDhcp(mInterfaceName);
        mController.obtainMessage(CMD_POST_DHCP_ACTION, DHCP_FAILURE, 0).sendToTarget();
    }
    return success;
}
Also used : DhcpInfoInternal(android.net.DhcpInfoInternal)

Example 2 with DhcpInfoInternal

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

the class WifiConfigStore method getIpConfiguration.

/**
     * get IP configuration for a given network id
     * TODO: We cannot handle IPv6 addresses for configuration
     *       right now until NetworkUtils is fixed. When we do
     *       that, we should remove handling DhcpInfo and move
     *       to using LinkProperties
     */
static DhcpInfoInternal getIpConfiguration(int netId) {
    DhcpInfoInternal dhcpInfoInternal = new DhcpInfoInternal();
    LinkProperties linkProperties = getLinkProperties(netId);
    if (linkProperties != null) {
        Iterator<LinkAddress> iter = linkProperties.getLinkAddresses().iterator();
        if (iter.hasNext()) {
            LinkAddress linkAddress = iter.next();
            dhcpInfoInternal.ipAddress = linkAddress.getAddress().getHostAddress();
            for (RouteInfo route : linkProperties.getRoutes()) {
                dhcpInfoInternal.addRoute(route);
            }
            dhcpInfoInternal.prefixLength = linkAddress.getNetworkPrefixLength();
            Iterator<InetAddress> dnsIterator = linkProperties.getDnses().iterator();
            dhcpInfoInternal.dns1 = dnsIterator.next().getHostAddress();
            if (dnsIterator.hasNext()) {
                dhcpInfoInternal.dns2 = dnsIterator.next().getHostAddress();
            }
        }
    }
    return dhcpInfoInternal;
}
Also used : LinkAddress(android.net.LinkAddress) DhcpInfoInternal(android.net.DhcpInfoInternal) RouteInfo(android.net.RouteInfo) LinkProperties(android.net.LinkProperties) InetAddress(java.net.InetAddress)

Example 3 with DhcpInfoInternal

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

the class BluetoothTetheringDataTracker method startReverseTether.

public synchronized void startReverseTether(String iface, BluetoothDevice device) {
    mIface = iface;
    mDevice = device;
    Thread dhcpThread = new Thread(new Runnable() {

        public void run() {
            //TODO(): Add callbacks for failure and success case.
            //Currently this thread runs independently.
            DhcpInfoInternal dhcpInfoInternal = new DhcpInfoInternal();
            if (!NetworkUtils.runDhcp(mIface, dhcpInfoInternal)) {
                Log.e(TAG, "DHCP request error:" + NetworkUtils.getDhcpError());
                return;
            }
            mLinkProperties = dhcpInfoInternal.makeLinkProperties();
            mLinkProperties.setInterfaceName(mIface);
            mNetworkInfo.setIsAvailable(true);
            mNetworkInfo.setDetailedState(DetailedState.CONNECTED, null, null);
            Message msg = mCsHandler.obtainMessage(EVENT_CONFIGURATION_CHANGED, mNetworkInfo);
            msg.sendToTarget();
            msg = mCsHandler.obtainMessage(EVENT_STATE_CHANGED, mNetworkInfo);
            msg.sendToTarget();
        }
    });
    dhcpThread.start();
}
Also used : Message(android.os.Message) DhcpInfoInternal(android.net.DhcpInfoInternal)

Aggregations

DhcpInfoInternal (android.net.DhcpInfoInternal)3 LinkAddress (android.net.LinkAddress)1 LinkProperties (android.net.LinkProperties)1 RouteInfo (android.net.RouteInfo)1 Message (android.os.Message)1 InetAddress (java.net.InetAddress)1