diff options
author | Christopher Wiley <wiley@google.com> | 2016-06-24 11:14:37 -0700 |
---|---|---|
committer | Christopher Wiley <wiley@google.com> | 2016-06-27 08:50:27 -0700 |
commit | ddf9ccd8144d8d381d1f5b5a625d17113229febf (patch) | |
tree | b455b37fffb4f316669c7343c6dc19298bd242d0 /libwifi_system | |
parent | 0d24d99ba447062e5fe9c094830ffeb2a3314b2f (diff) | |
download | android_frameworks_opt_net_wifi-ddf9ccd8144d8d381d1f5b5a625d17113229febf.tar.gz android_frameworks_opt_net_wifi-ddf9ccd8144d8d381d1f5b5a625d17113229febf.tar.bz2 android_frameworks_opt_net_wifi-ddf9ccd8144d8d381d1f5b5a625d17113229febf.zip |
Allow libwifi-system to be mocked
Bug: 29634806
Test: Compiles, unittests pass on bullhead
Change-Id: Ic3baf86961be077231d40ae1732b127d668e9589
Diffstat (limited to 'libwifi_system')
-rw-r--r-- | libwifi_system/Android.mk | 4 | ||||
-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 |
5 files changed, 38 insertions, 24 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 |