summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Wiley <wiley@google.com>2016-06-24 11:14:37 -0700
committerChristopher Wiley <wiley@google.com>2016-06-27 08:50:27 -0700
commitddf9ccd8144d8d381d1f5b5a625d17113229febf (patch)
treeb455b37fffb4f316669c7343c6dc19298bd242d0
parent0d24d99ba447062e5fe9c094830ffeb2a3314b2f (diff)
Allow libwifi-system to be mocked
Bug: 29634806 Test: Compiles, unittests pass on bullhead Change-Id: Ic3baf86961be077231d40ae1732b127d668e9589
-rw-r--r--libwifi_system/Android.mk4
-rw-r--r--libwifi_system/hal_tool.cpp (renamed from libwifi_system/hal.cpp)6
-rw-r--r--libwifi_system/include/wifi_system/hal_tool.h (renamed from libwifi_system/include/wifi_system/hal.h)17
-rw-r--r--libwifi_system/include/wifi_system/interface_tool.h (renamed from libwifi_system/include/wifi_system/interface_utils.h)27
-rw-r--r--libwifi_system/interface_tool.cpp (renamed from libwifi_system/interface_utils.cpp)8
-rw-r--r--service/jni/com_android_server_wifi_WifiNative.cpp24
6 files changed, 54 insertions, 32 deletions
diff --git a/libwifi_system/Android.mk b/libwifi_system/Android.mk
index 488efdd66..43efda960 100644
--- a/libwifi_system/Android.mk
+++ b/libwifi_system/Android.mk
@@ -47,8 +47,8 @@ LOCAL_SHARED_LIBRARIES += libwpa_client
endif
LOCAL_SRC_FILES := \
- interface_utils.cpp \
- hal.cpp \
+ interface_tool.cpp \
+ hal_tool.cpp \
wifi.cpp
include $(BUILD_SHARED_LIBRARY)
diff --git a/libwifi_system/hal.cpp b/libwifi_system/hal_tool.cpp
index 9f0c21441..4c7401d49 100644
--- a/libwifi_system/hal.cpp
+++ b/libwifi_system/hal_tool.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include "wifi_system/hal.h"
+#include "wifi_system/hal_tool.h"
#include <log/log.h>
@@ -562,7 +562,7 @@ bool init_wifi_stub_hal_func_table(wifi_hal_fn* hal_fn) {
} // namespace
-bool init_wifi_hal_function_table(wifi_hal_fn* hal_fn) {
+bool HalTool::InitFunctionTable(wifi_hal_fn* hal_fn) {
if (!init_wifi_stub_hal_func_table(hal_fn)) {
ALOGE("Can not initialize the basic function pointer table");
return false;
@@ -576,7 +576,7 @@ bool init_wifi_hal_function_table(wifi_hal_fn* hal_fn) {
return true;
}
-bool wifi_hal_can_get_valid_channels(wifi_hal_fn* hal_fn) {
+bool HalTool::CanGetValidChannels(wifi_hal_fn* hal_fn) {
return hal_fn &&
(hal_fn->wifi_get_valid_channels != wifi_get_valid_channels_stub);
}
diff --git a/libwifi_system/include/wifi_system/hal.h b/libwifi_system/include/wifi_system/hal_tool.h
index 2f2d30d81..b25893e15 100644
--- a/libwifi_system/include/wifi_system/hal.h
+++ b/libwifi_system/include/wifi_system/hal_tool.h
@@ -14,19 +14,26 @@
* limitations under the License.
*/
-#ifndef ANDROID_WIFI_SYSTEM_HAL_H
-#define ANDROID_WIFI_SYSTEM_HAL_H
+#ifndef ANDROID_WIFI_SYSTEM_HAL_TOOL_H
+#define ANDROID_WIFI_SYSTEM_HAL_TOOL_H
#include <hardware_legacy/wifi_hal.h>
namespace android {
namespace wifi_system {
-bool init_wifi_hal_function_table(wifi_hal_fn* hal_fn);
+// Utilities for interacting with the HAL.
+class HalTool {
+ public:
+ HalTool() = default;
+ virtual ~HalTool() = default;
-bool wifi_hal_can_get_valid_channels(wifi_hal_fn* hal_fn);
+ virtual bool InitFunctionTable(wifi_hal_fn* hal_fn);
+
+ virtual bool CanGetValidChannels(wifi_hal_fn* hal_fn);
+}; // class HalTool
} // namespace wifi_system
} // namespace android
-#endif // ANDROID_WIFI_SYSTEM_HAL_H
+#endif // ANDROID_WIFI_SYSTEM_HAL_TOOL_H
diff --git a/libwifi_system/include/wifi_system/interface_utils.h b/libwifi_system/include/wifi_system/interface_tool.h
index b3b23bb61..2e58379a1 100644
--- a/libwifi_system/include/wifi_system/interface_utils.h
+++ b/libwifi_system/include/wifi_system/interface_tool.h
@@ -14,22 +14,29 @@
* limitations under the License.
*/
-#ifndef ANDROID_WIFI_SYSTEM_INTERFACE_UTILS_H
-#define ANDROID_WIFI_SYSTEM_INTERFACE_UTILS_H
+#ifndef ANDROID_WIFI_SYSTEM_INTERFACE_TOOL_H
+#define ANDROID_WIFI_SYSTEM_INTERFACE_TOOL_H
namespace android {
namespace wifi_system {
-// Set the interface named by |if_name| up or down.
-// Returns true on success, false otherwise.
-bool set_iface_up(const char* if_name, bool request_up);
+class InterfaceTool {
+ public:
+ InterfaceTool() = default;
+ virtual ~InterfaceTool() = default;
-// A helpful alias for set_iface_up() that assumes there is a single system
-// WiFi interface. Prefer this form if you're hardcoding "wlan0" to help us
-// identify all the places we are hardcoding the name of the wifi interface.
-bool set_wifi_iface_up(bool request_up);
+ // Set the interface named by |if_name| up or down.
+ // Returns true on success, false otherwise.
+ virtual bool SetUpState(const char* if_name, bool request_up);
+
+ // A helpful alias for SetUpState() that assumes there is a single system
+ // WiFi interface. Prefer this form if you're hardcoding "wlan0" to help us
+ // identify all the places we are hardcoding the name of the wifi interface.
+ virtual bool SetWifiUpState(bool request_up);
+
+}; // class InterfaceTool
} // namespace wifi_system
} // namespace android
-#endif // ANDROID_WIFI_SYSTEM_INTERFACE_UTILS_H
+#endif // ANDROID_WIFI_SYSTEM_INTERFACE_TOOL_H
diff --git a/libwifi_system/interface_utils.cpp b/libwifi_system/interface_tool.cpp
index 8b935e17c..ed0b9f756 100644
--- a/libwifi_system/interface_utils.cpp
+++ b/libwifi_system/interface_tool.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include "wifi_system/interface_utils.h"
+#include "wifi_system/interface_tool.h"
#include <netinet/in.h>
#include <sys/socket.h>
@@ -33,7 +33,7 @@ const char kWlan0InterfaceName[] = "wlan0";
} // namespace
-bool set_iface_up(const char* if_name, bool request_up) {
+bool InterfaceTool::SetUpState(const char* if_name, bool request_up) {
base::unique_fd sock(socket(PF_INET, SOCK_DGRAM, 0));
if (sock.get() < 0) {
ALOGE("Bad socket: %d, errno: %d\n", sock.get(), errno);
@@ -72,8 +72,8 @@ bool set_iface_up(const char* if_name, bool request_up) {
return true;
}
-bool set_wifi_iface_up(bool request_up) {
- return set_iface_up(kWlan0InterfaceName, request_up);
+bool InterfaceTool::SetWifiUpState(bool request_up) {
+ return SetUpState(kWlan0InterfaceName, request_up);
}
} // namespace wifi_system
diff --git a/service/jni/com_android_server_wifi_WifiNative.cpp b/service/jni/com_android_server_wifi_WifiNative.cpp
index c5a268c45..146750313 100644
--- a/service/jni/com_android_server_wifi_WifiNative.cpp
+++ b/service/jni/com_android_server_wifi_WifiNative.cpp
@@ -38,8 +38,8 @@
#include <nativehelper/jni.h>
#include <utils/String16.h>
#include <utils/misc.h>
-#include <wifi_system/hal.h>
-#include <wifi_system/interface_utils.h>
+#include <wifi_system/hal_tool.h>
+#include <wifi_system/interface_tool.h>
#include <wifi_system/wifi.h>
#include "jni_helper.h"
@@ -48,6 +48,9 @@
#define EVENT_BUF_SIZE 2048
#define WAKE_REASON_TYPE_MAX 10
+using android::wifi_system::HalTool;
+using android::wifi_system::InterfaceTool;
+
namespace android {
extern "C"
@@ -243,21 +246,24 @@ static JNIObject<jobject> createScanResult(JNIHelper &helper, wifi_scan_result *
}
static jboolean android_net_wifi_set_interface_up(JNIEnv* env, jclass cls, jboolean up) {
- return wifi_system::set_wifi_iface_up((bool)up);
+ InterfaceTool if_tool;
+ return if_tool.SetWifiUpState((bool)up);
}
static jboolean android_net_wifi_startHal(JNIEnv* env, jclass cls) {
+ InterfaceTool if_tool;
JNIHelper helper(env);
wifi_handle halHandle = getWifiHandle(helper, cls);
if (halHandle != NULL) {
- return wifi_system::set_wifi_iface_up(true);
+ return if_tool.SetWifiUpState(true);
}
- if (!wifi_system::init_wifi_hal_function_table(&hal_fn)) {
+ HalTool hal_tool;
+ if (!hal_tool.InitFunctionTable(&hal_fn)) {
return false;
}
- if(!wifi_system::set_wifi_iface_up(true)) {
+ if(!if_tool.SetWifiUpState(true)) {
ALOGE("Failed to set WiFi interface up");
return false;
}
@@ -303,7 +309,8 @@ static void android_net_wifi_waitForHalEvents(JNIEnv* env, jclass cls) {
JNIHelper helper(env);
wifi_handle halHandle = getWifiHandle(helper, cls);
hal_fn.wifi_event_loop(halHandle);
- wifi_system::set_wifi_iface_up(false);
+ InterfaceTool if_tool;
+ if_tool.SetWifiUpState(false);
}
static int android_net_wifi_getInterfaces(JNIEnv *env, jclass cls) {
@@ -1332,7 +1339,8 @@ static jboolean android_net_wifi_setScanningMacOui(JNIEnv *env, jclass cls,
}
static jboolean android_net_wifi_is_get_channels_for_band_supported(JNIEnv *env, jclass cls){
- return wifi_system::wifi_hal_can_get_valid_channels(&hal_fn);
+ HalTool hal_tool;
+ return hal_tool.CanGetValidChannels(&hal_fn);
}
static jintArray android_net_wifi_getValidChannels(JNIEnv *env, jclass cls,