Search in sources :

Example 21 with InterfaceConfiguration

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

the class IpManager method setIPv4Address.

private boolean setIPv4Address(LinkAddress address) {
    final InterfaceConfiguration ifcg = new InterfaceConfiguration();
    ifcg.setLinkAddress(address);
    try {
        mNwService.setInterfaceConfig(mInterfaceName, ifcg);
        if (VDBG)
            Log.d(mTag, "IPv4 configuration succeeded");
    } catch (IllegalStateException | RemoteException e) {
        logError("IPv4 configuration failed: %s", e);
        return false;
    }
    return true;
}
Also used : RemoteException(android.os.RemoteException) InterfaceConfiguration(android.net.InterfaceConfiguration)

Example 22 with InterfaceConfiguration

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

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 23 with InterfaceConfiguration

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

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 24 with InterfaceConfiguration

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

the class TetherInterfaceStateMachine method configureIfaceIp.

// configured when we start tethering and unconfig'd on error or conclusion
private boolean configureIfaceIp(boolean enabled) {
    if (VDBG)
        Log.d(TAG, "configureIfaceIp(" + enabled + ")");
    String ipAsString = null;
    int prefixLen = 0;
    if (mInterfaceType == ConnectivityManager.TETHERING_USB) {
        ipAsString = USB_NEAR_IFACE_ADDR;
        prefixLen = USB_PREFIX_LENGTH;
    } else if (mInterfaceType == ConnectivityManager.TETHERING_WIFI) {
        ipAsString = WIFI_HOST_IFACE_ADDR;
        prefixLen = WIFI_HOST_IFACE_PREFIX_LENGTH;
    } else {
        // Nothing to do, BT does this elsewhere.
        return true;
    }
    InterfaceConfiguration ifcg = null;
    try {
        ifcg = mNMService.getInterfaceConfig(mIfaceName);
        if (ifcg != null) {
            InetAddress addr = NetworkUtils.numericToInetAddress(ipAsString);
            ifcg.setLinkAddress(new LinkAddress(addr, prefixLen));
            if (enabled) {
                ifcg.setInterfaceUp();
            } else {
                ifcg.setInterfaceDown();
            }
            ifcg.clearFlag("running");
            mNMService.setInterfaceConfig(mIfaceName, ifcg);
        }
    } catch (Exception e) {
        Log.e(TAG, "Error configuring interface " + mIfaceName, e);
        return false;
    }
    return true;
}
Also used : LinkAddress(android.net.LinkAddress) InterfaceConfiguration(android.net.InterfaceConfiguration) InetAddress(java.net.InetAddress)

Example 25 with InterfaceConfiguration

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

the class NetworkManagementService method setInterfaceDown.

@Override
public void setInterfaceDown(String iface) {
    mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
    final InterfaceConfiguration ifcg = getInterfaceConfig(iface);
    ifcg.setInterfaceDown();
    setInterfaceConfig(iface, ifcg);
}
Also used : InterfaceConfiguration(android.net.InterfaceConfiguration)

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