use of com.android.server.NativeDaemonConnector.Command in project android_frameworks_base by crdroidandroid.
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();
}
}
use of com.android.server.NativeDaemonConnector.Command in project android_frameworks_base by crdroidandroid.
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();
}
}
use of com.android.server.NativeDaemonConnector.Command in project android_frameworks_base by crdroidandroid.
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();
}
}
Aggregations