Search in sources :

Example 41 with Command

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

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 42 with Command

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

the class NsdService method registerService.

private boolean registerService(int regId, NsdServiceInfo service) {
    if (DBG)
        Slog.d(TAG, "registerService: " + regId + " " + service);
    try {
        Command cmd = new Command("mdnssd", "register", regId, service.getServiceName(), service.getServiceType(), service.getPort(), Base64.encodeToString(service.getTxtRecord(), Base64.DEFAULT).replace("\n", ""));
        mNativeConnector.execute(cmd);
    } catch (NativeDaemonConnectorException e) {
        Slog.e(TAG, "Failed to execute registerService " + e);
        return false;
    }
    return true;
}
Also used : Command(com.android.server.NativeDaemonConnector.Command)

Example 43 with Command

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

the class NetworkManagementService method modifyNat.

private void modifyNat(String action, String internalInterface, String externalInterface) throws SocketException {
    final Command cmd = new Command("nat", action, internalInterface, externalInterface);
    final NetworkInterface internalNetworkInterface = NetworkInterface.getByName(internalInterface);
    if (internalNetworkInterface == null) {
        cmd.appendArg("0");
    } else {
        // Don't touch link-local routes, as link-local addresses aren't routable,
        // kernel creates link-local routes on all interfaces automatically
        List<InterfaceAddress> interfaceAddresses = excludeLinkLocal(internalNetworkInterface.getInterfaceAddresses());
        cmd.appendArg(interfaceAddresses.size());
        for (InterfaceAddress ia : interfaceAddresses) {
            InetAddress addr = NetworkUtils.getNetworkPart(ia.getAddress(), ia.getNetworkPrefixLength());
            cmd.appendArg(addr.getHostAddress() + "/" + ia.getNetworkPrefixLength());
        }
    }
    try {
        mConnector.execute(cmd);
    } catch (NativeDaemonConnectorException e) {
        throw e.rethrowAsParcelableException();
    }
}
Also used : Command(com.android.server.NativeDaemonConnector.Command) InterfaceAddress(java.net.InterfaceAddress) NetworkInterface(java.net.NetworkInterface) InetAddress(java.net.InetAddress)

Example 44 with Command

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

the class NetworkManagementService method setDnsServersForNetwork.

@Override
public void setDnsServersForNetwork(int netId, String[] servers, String domains) {
    mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
    Command cmd;
    if (servers.length > 0) {
        cmd = new Command("resolver", "setnetdns", netId, (domains == null ? "" : domains));
        for (String s : servers) {
            InetAddress a = NetworkUtils.numericToInetAddress(s);
            if (a.isAnyLocalAddress() == false) {
                cmd.appendArg(a.getHostAddress());
            }
        }
    } else {
        cmd = new Command("resolver", "clearnetdns", netId);
    }
    try {
        mConnector.execute(cmd);
    } catch (NativeDaemonConnectorException e) {
        throw e.rethrowAsParcelableException();
    }
}
Also used : Command(com.android.server.NativeDaemonConnector.Command) InetAddress(java.net.InetAddress)

Example 45 with Command

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

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)

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