Search in sources :

Example 6 with Command

use of com.android.server.NativeDaemonConnector.Command in project platform_frameworks_base by android.

the class NetworkManagementService method setDnsForwarders.

@Override
public void setDnsForwarders(Network network, String[] dns) {
    mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
    int netId = (network != null) ? network.netId : ConnectivityManager.NETID_UNSET;
    final Command cmd = new Command("tether", "dns", "set", netId);
    for (String s : dns) {
        cmd.appendArg(NetworkUtils.numericToInetAddress(s).getHostAddress());
    }
    try {
        mConnector.execute(cmd);
    } catch (NativeDaemonConnectorException e) {
        throw e.rethrowAsParcelableException();
    }
}
Also used : Command(com.android.server.NativeDaemonConnector.Command)

Example 7 with Command

use of com.android.server.NativeDaemonConnector.Command in project platform_frameworks_base by android.

the class NetworkManagementService method modifyRoute.

private void modifyRoute(String action, String netId, RouteInfo route) {
    mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
    final Command cmd = new Command("network", "route", action, netId);
    // create triplet: interface dest-ip-addr/prefixlength gateway-ip-addr
    cmd.appendArg(route.getInterface());
    cmd.appendArg(route.getDestination().toString());
    switch(route.getType()) {
        case RouteInfo.RTN_UNICAST:
            if (route.hasGateway()) {
                cmd.appendArg(route.getGateway().getHostAddress());
            }
            break;
        case RouteInfo.RTN_UNREACHABLE:
            cmd.appendArg("unreachable");
            break;
        case RouteInfo.RTN_THROW:
            cmd.appendArg("throw");
            break;
    }
    try {
        mConnector.execute(cmd);
    } catch (NativeDaemonConnectorException e) {
        throw e.rethrowAsParcelableException();
    }
}
Also used : Command(com.android.server.NativeDaemonConnector.Command)

Example 8 with Command

use of com.android.server.NativeDaemonConnector.Command in project android_frameworks_base by DirtyUnicorns.

the class NetworkManagementService method startTethering.

@Override
public void startTethering(String[] dhcpRange) {
    mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
    // cmd is "tether start first_start first_stop second_start second_stop ..."
    // an odd number of addrs will fail
    final Command cmd = new Command("tether", "start");
    for (String d : dhcpRange) {
        cmd.appendArg(d);
    }
    try {
        mConnector.execute(cmd);
    } catch (NativeDaemonConnectorException e) {
        throw e.rethrowAsParcelableException();
    }
}
Also used : Command(com.android.server.NativeDaemonConnector.Command)

Example 9 with Command

use of com.android.server.NativeDaemonConnector.Command in project android_frameworks_base by DirtyUnicorns.

the class NetworkManagementService method setInterfaceConfig.

@Override
public void setInterfaceConfig(String iface, InterfaceConfiguration cfg) {
    mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
    LinkAddress linkAddr = cfg.getLinkAddress();
    if (linkAddr == null || linkAddr.getAddress() == null) {
        throw new IllegalStateException("Null LinkAddress given");
    }
    final Command cmd = new Command("interface", "setcfg", iface, linkAddr.getAddress().getHostAddress(), linkAddr.getPrefixLength());
    for (String flag : cfg.getFlags()) {
        cmd.appendArg(flag);
    }
    try {
        mConnector.execute(cmd);
    } catch (NativeDaemonConnectorException e) {
        throw e.rethrowAsParcelableException();
    }
}
Also used : LinkAddress(android.net.LinkAddress) Command(com.android.server.NativeDaemonConnector.Command)

Example 10 with Command

use of com.android.server.NativeDaemonConnector.Command in project android_frameworks_base by DirtyUnicorns.

the class NetworkManagementService method addLegacyRouteForNetId.

@Override
public void addLegacyRouteForNetId(int netId, RouteInfo routeInfo, int uid) {
    mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
    final Command cmd = new Command("network", "route", "legacy", uid, "add", netId);
    // create triplet: interface dest-ip-addr/prefixlength gateway-ip-addr
    final LinkAddress la = routeInfo.getDestinationLinkAddress();
    cmd.appendArg(routeInfo.getInterface());
    cmd.appendArg(la.getAddress().getHostAddress() + "/" + la.getPrefixLength());
    if (routeInfo.hasGateway()) {
        cmd.appendArg(routeInfo.getGateway().getHostAddress());
    }
    try {
        mConnector.execute(cmd);
    } catch (NativeDaemonConnectorException e) {
        throw e.rethrowAsParcelableException();
    }
}
Also used : LinkAddress(android.net.LinkAddress) Command(com.android.server.NativeDaemonConnector.Command)

Aggregations

Command (com.android.server.NativeDaemonConnector.Command)58 LinkAddress (android.net.LinkAddress)12 InetAddress (java.net.InetAddress)11 InterfaceAddress (java.net.InterfaceAddress)6 NetworkInterface (java.net.NetworkInterface)6 Inet4Address (java.net.Inet4Address)1