Search in sources :

Example 6 with InterfaceConfiguration

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

the class Nat464Xlat method interfaceAdded.

@Override
public void interfaceAdded(String iface) {
    if (iface.equals(CLAT_INTERFACE_NAME)) {
        Slog.i(TAG, "interface " + CLAT_INTERFACE_NAME + " added, mIsRunning = " + mIsRunning + " -> true");
        mIsRunning = true;
        // it's running on.
        try {
            InterfaceConfiguration config = mNMService.getInterfaceConfig(iface);
            mLP.clear();
            mLP.setInterfaceName(iface);
            RouteInfo ipv4Default = new RouteInfo(new LinkAddress(Inet4Address.ANY, 0), null, iface);
            mLP.addRoute(ipv4Default);
            mLP.addLinkAddress(config.getLinkAddress());
            mTracker.addStackedLink(mLP);
            Slog.i(TAG, "Adding stacked link. tracker LP: " + mTracker.getLinkProperties());
        } catch (RemoteException e) {
            Slog.e(TAG, "Error getting link properties: " + e);
        }
        // Inform ConnectivityService that things have changed.
        Message msg = mHandler.obtainMessage(NetworkStateTracker.EVENT_CONFIGURATION_CHANGED, mTracker.getNetworkInfo());
        Slog.i(TAG, "sending message to ConnectivityService: " + msg);
        msg.sendToTarget();
    }
}
Also used : LinkAddress(android.net.LinkAddress) Message(android.os.Message) RouteInfo(android.net.RouteInfo) RemoteException(android.os.RemoteException) InterfaceConfiguration(android.net.InterfaceConfiguration)

Example 7 with InterfaceConfiguration

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

the class WifiStateMachine method stopTethering.

private void stopTethering() {
    checkAndSetConnectivityInstance();
    /* Clear the interface config to allow dhcp correctly configure new
           ip settings */
    InterfaceConfiguration ifcg = null;
    try {
        ifcg = mNwService.getInterfaceConfig(mTetherInterfaceName);
        if (ifcg != null) {
            ifcg.setLinkAddress(new LinkAddress(NetworkUtils.numericToInetAddress("0.0.0.0"), 0));
            mNwService.setInterfaceConfig(mTetherInterfaceName, ifcg);
        }
    } catch (Exception e) {
        loge("Error resetting interface " + mTetherInterfaceName + ", :" + e);
    }
    if (mCm.untether(mTetherInterfaceName) != ConnectivityManager.TETHER_ERROR_NO_ERROR) {
        loge("Untether initiate failed!");
    }
}
Also used : LinkAddress(android.net.LinkAddress) InterfaceConfiguration(android.net.InterfaceConfiguration) RemoteException(android.os.RemoteException)

Example 8 with InterfaceConfiguration

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

the class NetworkManagementService method getInterfaceConfig.

@Override
public InterfaceConfiguration getInterfaceConfig(String iface) {
    mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
    final NativeDaemonEvent event;
    try {
        event = mConnector.execute("interface", "getcfg", iface);
    } catch (NativeDaemonConnectorException e) {
        throw e.rethrowAsParcelableException();
    }
    event.checkCode(InterfaceGetCfgResult);
    // Rsp: 213 xx:xx:xx:xx:xx:xx yyy.yyy.yyy.yyy zzz flag1 flag2 flag3
    final StringTokenizer st = new StringTokenizer(event.getMessage());
    InterfaceConfiguration cfg;
    try {
        cfg = new InterfaceConfiguration();
        cfg.setHardwareAddress(st.nextToken(" "));
        InetAddress addr = null;
        int prefixLength = 0;
        try {
            addr = NetworkUtils.numericToInetAddress(st.nextToken());
        } catch (IllegalArgumentException iae) {
            Slog.e(TAG, "Failed to parse ipaddr", iae);
        }
        try {
            prefixLength = Integer.parseInt(st.nextToken());
        } catch (NumberFormatException nfe) {
            Slog.e(TAG, "Failed to parse prefixLength", nfe);
        }
        cfg.setLinkAddress(new LinkAddress(addr, prefixLength));
        while (st.hasMoreTokens()) {
            cfg.setFlag(st.nextToken());
        }
    } catch (NoSuchElementException nsee) {
        throw new IllegalStateException("Invalid response from daemon: " + event);
    }
    return cfg;
}
Also used : LinkAddress(android.net.LinkAddress) StringTokenizer(java.util.StringTokenizer) InterfaceConfiguration(android.net.InterfaceConfiguration) InetAddress(java.net.InetAddress) NoSuchElementException(java.util.NoSuchElementException)

Example 9 with InterfaceConfiguration

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

the class IpManager method clearIPv4Address.

private void clearIPv4Address() {
    try {
        final InterfaceConfiguration ifcg = new InterfaceConfiguration();
        ifcg.setLinkAddress(new LinkAddress("0.0.0.0/0"));
        mNwService.setInterfaceConfig(mInterfaceName, ifcg);
    } catch (IllegalStateException | RemoteException e) {
        Log.e(mTag, "ALERT: Failed to clear IPv4 address on interface " + mInterfaceName, e);
    }
}
Also used : LinkAddress(android.net.LinkAddress) RemoteException(android.os.RemoteException) InterfaceConfiguration(android.net.InterfaceConfiguration)

Example 10 with InterfaceConfiguration

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

the class WifiStateMachine method stopTethering.

private void stopTethering() {
    checkAndSetConnectivityInstance();
    /* Clear the interface config to allow dhcp correctly configure new
           ip settings */
    InterfaceConfiguration ifcg = null;
    try {
        ifcg = mNwService.getInterfaceConfig(mInterfaceName);
        if (ifcg != null) {
            ifcg.addr = new LinkAddress(NetworkUtils.numericToInetAddress("0.0.0.0"), 0);
            mNwService.setInterfaceConfig(mInterfaceName, ifcg);
        }
    } catch (Exception e) {
        loge("Error resetting interface " + mInterfaceName + ", :" + e);
    }
    if (mCm.untether(mInterfaceName) != ConnectivityManager.TETHER_ERROR_NO_ERROR) {
        loge("Untether initiate failed!");
    }
}
Also used : LinkAddress(android.net.LinkAddress) InterfaceConfiguration(android.net.InterfaceConfiguration) RemoteException(android.os.RemoteException)

Aggregations

InterfaceConfiguration (android.net.InterfaceConfiguration)44 LinkAddress (android.net.LinkAddress)22 RemoteException (android.os.RemoteException)20 InetAddress (java.net.InetAddress)13 NoSuchElementException (java.util.NoSuchElementException)6 StringTokenizer (java.util.StringTokenizer)6 NotFoundException (android.content.res.Resources.NotFoundException)1 ConnectivityManager (android.net.ConnectivityManager)1 RouteInfo (android.net.RouteInfo)1 IBinder (android.os.IBinder)1 INetworkManagementService (android.os.INetworkManagementService)1 Message (android.os.Message)1