Add DhcpStateMachine for interation with dhcpcd
- Supports wakeup and renewal on dhcp - Supports multiple controllers to use the state machine simultaneously - Optionally, a controller can request a notification prior to DHCP request/renewal being sent Change-Id: I3a9d7e6a02ff26be3a86ddca6964683ad3c28f93
This commit is contained in:
@@ -79,6 +79,16 @@ public class NetworkUtils {
|
||||
*/
|
||||
public native static boolean runDhcp(String interfaceName, DhcpInfoInternal ipInfo);
|
||||
|
||||
/**
|
||||
* 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 ipInfo 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 runDhcpRenew(String interfaceName, DhcpInfoInternal ipInfo);
|
||||
|
||||
/**
|
||||
* Shut down the DHCP client daemon.
|
||||
* @param interfaceName the name of the interface for which the daemon
|
||||
|
||||
@@ -40,6 +40,16 @@ int dhcp_do_request(const char *ifname,
|
||||
const char *dns2,
|
||||
const char *server,
|
||||
uint32_t *lease);
|
||||
|
||||
int dhcp_do_request_renew(const char *ifname,
|
||||
const char *ipaddr,
|
||||
const char *gateway,
|
||||
uint32_t *prefixLength,
|
||||
const char *dns1,
|
||||
const char *dns2,
|
||||
const char *server,
|
||||
uint32_t *lease);
|
||||
|
||||
int dhcp_stop(const char *ifname);
|
||||
int dhcp_release_lease(const char *ifname);
|
||||
char *dhcp_get_errmsg();
|
||||
@@ -146,7 +156,8 @@ static jint android_net_utils_resetConnections(JNIEnv* env, jobject clazz, jstri
|
||||
return (jint)result;
|
||||
}
|
||||
|
||||
static jboolean android_net_utils_runDhcp(JNIEnv* env, jobject clazz, jstring ifname, jobject info)
|
||||
static jboolean android_net_utils_runDhcpCommon(JNIEnv* env, jobject clazz, jstring ifname,
|
||||
jobject info, bool renew)
|
||||
{
|
||||
int result;
|
||||
char ipaddr[PROPERTY_VALUE_MAX];
|
||||
@@ -160,8 +171,14 @@ static jboolean android_net_utils_runDhcp(JNIEnv* env, jobject clazz, jstring if
|
||||
const char *nameStr = env->GetStringUTFChars(ifname, NULL);
|
||||
if (nameStr == NULL) return (jboolean)false;
|
||||
|
||||
if (renew) {
|
||||
result = ::dhcp_do_request_renew(nameStr, ipaddr, gateway, &prefixLength,
|
||||
dns1, dns2, server, &lease);
|
||||
} else {
|
||||
result = ::dhcp_do_request(nameStr, ipaddr, gateway, &prefixLength,
|
||||
dns1, dns2, server, &lease);
|
||||
}
|
||||
|
||||
env->ReleaseStringUTFChars(ifname, nameStr);
|
||||
if (result == 0 && dhcpInfoInternalFieldIds.dhcpInfoInternalClass != NULL) {
|
||||
env->SetObjectField(info, dhcpInfoInternalFieldIds.ipaddress, env->NewStringUTF(ipaddr));
|
||||
@@ -176,6 +193,17 @@ static jboolean android_net_utils_runDhcp(JNIEnv* env, jobject clazz, jstring if
|
||||
return (jboolean)(result == 0);
|
||||
}
|
||||
|
||||
static jboolean android_net_utils_runDhcp(JNIEnv* env, jobject clazz, jstring ifname, jobject info)
|
||||
{
|
||||
return android_net_utils_runDhcpCommon(env, clazz, ifname, info, false);
|
||||
}
|
||||
|
||||
static jboolean android_net_utils_runDhcpRenew(JNIEnv* env, jobject clazz, jstring ifname, jobject info)
|
||||
{
|
||||
return android_net_utils_runDhcpCommon(env, clazz, ifname, info, true);
|
||||
}
|
||||
|
||||
|
||||
static jboolean android_net_utils_stopDhcp(JNIEnv* env, jobject clazz, jstring ifname)
|
||||
{
|
||||
int result;
|
||||
@@ -219,6 +247,7 @@ static JNINativeMethod gNetworkUtilMethods[] = {
|
||||
{ "removeDefaultRoute", "(Ljava/lang/String;)I", (void *)android_net_utils_removeDefaultRoute },
|
||||
{ "resetConnections", "(Ljava/lang/String;)I", (void *)android_net_utils_resetConnections },
|
||||
{ "runDhcp", "(Ljava/lang/String;Landroid/net/DhcpInfoInternal;)Z", (void *)android_net_utils_runDhcp },
|
||||
{ "runDhcpRenew", "(Ljava/lang/String;Landroid/net/DhcpInfoInternal;)Z", (void *)android_net_utils_runDhcpRenew },
|
||||
{ "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 },
|
||||
|
||||
Reference in New Issue
Block a user