Delete all NetworkUtils DHCP-related code.

Bug: 26991160
Change-Id: I2c74e0161f43f65c1b6a85dc9f294b64c8f1ae6e
This commit is contained in:
Erik Kline
2016-02-18 20:06:02 +09:00
parent 6ba9b90805
commit af0170a562
2 changed files with 0 additions and 272 deletions

View File

@@ -56,90 +56,6 @@ public class NetworkUtils {
*/
public native static int resetConnections(String interfaceName, int mask);
/**
* Start the DHCP client daemon, in order to have it request addresses
* for the named interface. This returns {@code true} if the DHCPv4 daemon
* starts, {@code false} otherwise. This call blocks until such time as a
* result is available or the default discovery timeout has been reached.
* Callers should check {@link #getDhcpResults} to determine whether DHCP
* succeeded or failed, and if it succeeded, to fetch the {@link DhcpResults}.
* @param interfaceName the name of the interface to configure
* @return {@code true} for success, {@code false} for failure
*/
public native static boolean startDhcp(String interfaceName);
/**
* Initiate renewal on the DHCP client daemon for the named interface. This
* returns {@code true} if the DHCPv4 daemon has been notified, {@code false}
* otherwise. This call blocks until such time as a result is available or
* the default renew timeout has been reached. Callers should check
* {@link #getDhcpResults} to determine whether DHCP succeeded or failed,
* and if it succeeded, to fetch the {@link DhcpResults}.
* @param interfaceName the name of the interface to configure
* @return {@code true} for success, {@code false} for failure
*/
public native static boolean startDhcpRenew(String interfaceName);
/**
* Start the DHCP client daemon, in order to have it request addresses
* for the named interface, and then configure the interface with those
* addresses. This call blocks until it obtains a result (either success
* or failure) from the daemon.
* @param interfaceName the name of the interface to configure
* @param dhcpResults if the request succeeds, this object is filled in with
* the IP address information.
* @return {@code true} for success, {@code false} for failure
*/
public static boolean runDhcp(String interfaceName, DhcpResults dhcpResults) {
return startDhcp(interfaceName) && getDhcpResults(interfaceName, dhcpResults);
}
/**
* Initiate renewal on the DHCP client daemon. This call blocks until it obtains
* a result (either success or failure) from the daemon.
* @param interfaceName the name of the interface to configure
* @param dhcpResults if the request succeeds, this object is filled in with
* the IP address information.
* @return {@code true} for success, {@code false} for failure
*/
public static boolean runDhcpRenew(String interfaceName, DhcpResults dhcpResults) {
return startDhcpRenew(interfaceName) && getDhcpResults(interfaceName, dhcpResults);
}
/**
* Fetch results from the DHCP client daemon. This call returns {@code true} if
* if there are results available to be read, {@code false} otherwise.
* @param interfaceName the name of the interface to configure
* @param dhcpResults if the request succeeds, this object is filled in with
* the IP address information.
* @return {@code true} for success, {@code false} for failure
*/
public native static boolean getDhcpResults(String interfaceName, DhcpResults dhcpResults);
/**
* Shut down the DHCP client daemon.
* @param interfaceName the name of the interface for which the daemon
* should be stopped
* @return {@code true} for success, {@code false} for failure
*/
public native static boolean stopDhcp(String interfaceName);
/**
* Release the current DHCP lease.
* @param interfaceName the name of the interface for which the lease should
* be released
* @return {@code true} for success, {@code false} for failure
*/
public native static boolean releaseDhcpLease(String interfaceName);
/**
* Return the last DHCP-related error message that was recorded.
* <p/>NOTE: This string is not localized, but currently it is only
* used in logging.
* @return the most recent error message, if any
*/
public native static String getDhcpError();
/**
* Attaches a socket filter that accepts DHCP packets to the given socket.
*/

View File

@@ -39,23 +39,6 @@ extern "C" {
int ifc_enable(const char *ifname);
int ifc_disable(const char *ifname);
int ifc_reset_connections(const char *ifname, int reset_mask);
int dhcp_start(const char * const ifname);
int dhcp_start_renew(const char * const ifname);
int dhcp_get_results(const char * const ifname,
const char *ipaddr,
const char *gateway,
uint32_t *prefixLength,
const char *dns[],
const char *server,
uint32_t *lease,
const char *vendorInfo,
const char *domains,
const char *mtu);
int dhcp_stop(const char *ifname);
int dhcp_release_lease(const char *ifname);
char *dhcp_get_errmsg();
}
#define NETUTILS_PKG_NAME "android/net/NetworkUtils"
@@ -64,22 +47,6 @@ namespace android {
static const uint16_t kDhcpClientPort = 68;
/*
* The following remembers the jfieldID's of the fields
* of the DhcpInfo Java object, so that we don't have
* to look them up every time.
*/
static struct fieldIds {
jmethodID clear;
jmethodID setIpAddress;
jmethodID setGateway;
jmethodID addDns;
jmethodID setDomains;
jmethodID setServerAddress;
jmethodID setLeaseDuration;
jmethodID setVendorInfo;
} dhcpResultsFieldIds;
static jint android_net_utils_resetConnections(JNIEnv* env, jobject clazz,
jstring ifname, jint mask)
{
@@ -95,137 +62,6 @@ static jint android_net_utils_resetConnections(JNIEnv* env, jobject clazz,
return (jint)result;
}
static jboolean android_net_utils_getDhcpResults(JNIEnv* env, jobject clazz, jstring ifname,
jobject dhcpResults)
{
int result;
char ipaddr[PROPERTY_VALUE_MAX];
uint32_t prefixLength;
char gateway[PROPERTY_VALUE_MAX];
char dns1[PROPERTY_VALUE_MAX];
char dns2[PROPERTY_VALUE_MAX];
char dns3[PROPERTY_VALUE_MAX];
char dns4[PROPERTY_VALUE_MAX];
const char *dns[5] = {dns1, dns2, dns3, dns4, NULL};
char server[PROPERTY_VALUE_MAX];
uint32_t lease;
char vendorInfo[PROPERTY_VALUE_MAX];
char domains[PROPERTY_VALUE_MAX];
char mtu[PROPERTY_VALUE_MAX];
const char *nameStr = env->GetStringUTFChars(ifname, NULL);
if (nameStr == NULL) return (jboolean)false;
result = ::dhcp_get_results(nameStr, ipaddr, gateway, &prefixLength,
dns, server, &lease, vendorInfo, domains, mtu);
if (result != 0) {
ALOGD("dhcp_get_results failed : %s (%s)", nameStr, ::dhcp_get_errmsg());
}
env->ReleaseStringUTFChars(ifname, nameStr);
if (result == 0) {
env->CallVoidMethod(dhcpResults, dhcpResultsFieldIds.clear);
// set the linkAddress
// dhcpResults->addLinkAddress(inetAddress, prefixLength)
result = env->CallBooleanMethod(dhcpResults, dhcpResultsFieldIds.setIpAddress,
env->NewStringUTF(ipaddr), prefixLength);
}
if (result == 0) {
// set the gateway
result = env->CallBooleanMethod(dhcpResults,
dhcpResultsFieldIds.setGateway, env->NewStringUTF(gateway));
}
if (result == 0) {
// dhcpResults->addDns(new InetAddress(dns1))
result = env->CallBooleanMethod(dhcpResults,
dhcpResultsFieldIds.addDns, env->NewStringUTF(dns1));
}
if (result == 0) {
env->CallVoidMethod(dhcpResults, dhcpResultsFieldIds.setDomains,
env->NewStringUTF(domains));
result = env->CallBooleanMethod(dhcpResults,
dhcpResultsFieldIds.addDns, env->NewStringUTF(dns2));
if (result == 0) {
result = env->CallBooleanMethod(dhcpResults,
dhcpResultsFieldIds.addDns, env->NewStringUTF(dns3));
if (result == 0) {
result = env->CallBooleanMethod(dhcpResults,
dhcpResultsFieldIds.addDns, env->NewStringUTF(dns4));
}
}
}
if (result == 0) {
// dhcpResults->setServerAddress(new InetAddress(server))
result = env->CallBooleanMethod(dhcpResults, dhcpResultsFieldIds.setServerAddress,
env->NewStringUTF(server));
}
if (result == 0) {
// dhcpResults->setLeaseDuration(lease)
env->CallVoidMethod(dhcpResults,
dhcpResultsFieldIds.setLeaseDuration, lease);
// dhcpResults->setVendorInfo(vendorInfo)
env->CallVoidMethod(dhcpResults, dhcpResultsFieldIds.setVendorInfo,
env->NewStringUTF(vendorInfo));
}
return (jboolean)(result == 0);
}
static jboolean android_net_utils_startDhcp(JNIEnv* env, jobject clazz, jstring ifname)
{
const char *nameStr = env->GetStringUTFChars(ifname, NULL);
if (nameStr == NULL) return (jboolean)false;
if (::dhcp_start(nameStr) != 0) {
ALOGD("dhcp_start failed : %s", nameStr);
return (jboolean)false;
}
return (jboolean)true;
}
static jboolean android_net_utils_startDhcpRenew(JNIEnv* env, jobject clazz, jstring ifname)
{
const char *nameStr = env->GetStringUTFChars(ifname, NULL);
if (nameStr == NULL) return (jboolean)false;
if (::dhcp_start_renew(nameStr) != 0) {
ALOGD("dhcp_start_renew failed : %s", nameStr);
return (jboolean)false;
}
return (jboolean)true;
}
static jboolean android_net_utils_stopDhcp(JNIEnv* env, jobject clazz, jstring ifname)
{
int result;
const char *nameStr = env->GetStringUTFChars(ifname, NULL);
result = ::dhcp_stop(nameStr);
env->ReleaseStringUTFChars(ifname, nameStr);
return (jboolean)(result == 0);
}
static jboolean android_net_utils_releaseDhcpLease(JNIEnv* env, jobject clazz, jstring ifname)
{
int result;
const char *nameStr = env->GetStringUTFChars(ifname, NULL);
result = ::dhcp_release_lease(nameStr);
env->ReleaseStringUTFChars(ifname, nameStr);
return (jboolean)(result == 0);
}
static jstring android_net_utils_getDhcpError(JNIEnv* env, jobject clazz)
{
return env->NewStringUTF(::dhcp_get_errmsg());
}
static void android_net_utils_attachDhcpFilter(JNIEnv *env, jobject clazz, jobject javaFd)
{
int fd = jniGetFDFromFileDescriptor(env, javaFd);
@@ -305,12 +141,6 @@ static jboolean android_net_utils_queryUserAccess(JNIEnv *env, jobject thiz, jin
static const JNINativeMethod gNetworkUtilMethods[] = {
/* name, signature, funcPtr */
{ "resetConnections", "(Ljava/lang/String;I)I", (void *)android_net_utils_resetConnections },
{ "startDhcp", "(Ljava/lang/String;)Z", (void *)android_net_utils_startDhcp },
{ "startDhcpRenew", "(Ljava/lang/String;)Z", (void *)android_net_utils_startDhcpRenew },
{ "getDhcpResults", "(Ljava/lang/String;Landroid/net/DhcpResults;)Z", (void *)android_net_utils_getDhcpResults },
{ "stopDhcp", "(Ljava/lang/String;)Z", (void *)android_net_utils_stopDhcp },
{ "releaseDhcpLease", "(Ljava/lang/String;)Z", (void *)android_net_utils_releaseDhcpLease },
{ "getDhcpError", "()Ljava/lang/String;", (void*) android_net_utils_getDhcpError },
{ "bindProcessToNetwork", "(I)Z", (void*) android_net_utils_bindProcessToNetwork },
{ "getBoundNetworkForProcess", "()I", (void*) android_net_utils_getBoundNetworkForProcess },
{ "bindProcessToNetworkForHostResolution", "(I)Z", (void*) android_net_utils_bindProcessToNetworkForHostResolution },
@@ -322,24 +152,6 @@ static const JNINativeMethod gNetworkUtilMethods[] = {
int register_android_net_NetworkUtils(JNIEnv* env)
{
jclass dhcpResultsClass = FindClassOrDie(env, "android/net/DhcpResults");
dhcpResultsFieldIds.clear = GetMethodIDOrDie(env, dhcpResultsClass, "clear", "()V");
dhcpResultsFieldIds.setIpAddress =GetMethodIDOrDie(env, dhcpResultsClass, "setIpAddress",
"(Ljava/lang/String;I)Z");
dhcpResultsFieldIds.setGateway = GetMethodIDOrDie(env, dhcpResultsClass, "setGateway",
"(Ljava/lang/String;)Z");
dhcpResultsFieldIds.addDns = GetMethodIDOrDie(env, dhcpResultsClass, "addDns",
"(Ljava/lang/String;)Z");
dhcpResultsFieldIds.setDomains = GetMethodIDOrDie(env, dhcpResultsClass, "setDomains",
"(Ljava/lang/String;)V");
dhcpResultsFieldIds.setServerAddress = GetMethodIDOrDie(env, dhcpResultsClass,
"setServerAddress", "(Ljava/lang/String;)Z");
dhcpResultsFieldIds.setLeaseDuration = GetMethodIDOrDie(env, dhcpResultsClass,
"setLeaseDuration", "(I)V");
dhcpResultsFieldIds.setVendorInfo = GetMethodIDOrDie(env, dhcpResultsClass, "setVendorInfo",
"(Ljava/lang/String;)V");
return RegisterMethodsOrDie(env, NETUTILS_PKG_NAME, gNetworkUtilMethods,
NELEM(gNetworkUtilMethods));
}