Use updated mock-able libwifi-system interface
While here, replace copy/pasted code with shared functionality.
Bug: 29634806
Change-Id: If1a7b7e8baebdbccb8208bac194d95b4d2649814
diff --git a/sl4n/facades/wifi/wifi_facade.cpp b/sl4n/facades/wifi/wifi_facade.cpp
index e3f8575..f45cf9e 100644
--- a/sl4n/facades/wifi/wifi_facade.cpp
+++ b/sl4n/facades/wifi/wifi_facade.cpp
@@ -30,7 +30,8 @@
#include <utils/command_receiver.h>
#include <utils/common_utils.h>
#include <hardware_legacy/wifi_hal.h>
-#include <wifi_system/hal.h>
+#include <wifi_system/hal_tool.h>
+#include <wifi_system/interface_tool.h>
#include "wifi_facade.h"
@@ -50,20 +51,21 @@
}
bool WifiFacade::WifiStartHal() {
+ android::wifi_system::InterfaceTool if_tool;
if (wifi_hal_handle == NULL) {
- if (!android::wifi_system::init_wifi_hal_function_table(&hal_fn)) {
+ android::wifi_system::HalTool hal_tool;
+ if (!hal_tool.InitFunctionTable(&hal_fn)) {
return false;
}
- int ret = BringInterfaceUpDown(kWlanInterface, 1);
- if (ret != 0) {
+ if (!if_tool.SetWifiUpState(true)) {
return false;
}
res = hal_fn.wifi_initialize(&wifi_hal_handle);
return res == WIFI_SUCCESS;
} else {
- return BringInterfaceUpDown(kWlanInterface, 1) == 0;
+ return if_tool.SetWifiUpState(true);
}
}
@@ -146,51 +148,6 @@
}
}
-// TODO: copy of set_iface_flags from Wi-Fi JNI. Consolidate into a support
-// library.
-int WifiFacade::BringInterfaceUpDown(const char *ifname, int dev_up) {
- struct ifreq ifr;
- int ret;
- int sock = socket(PF_INET, SOCK_DGRAM, 0);
- if (sock < 0) {
- LOG(ERROR) << "Bad socket: " << sock;
- return -errno;
- }
-
- memset(&ifr, 0, sizeof(ifr));
- strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
-
- if (ioctl(sock, SIOCGIFFLAGS, &ifr) != 0) {
- ret = errno ? -errno : -999;
- LOG(ERROR) << "Could not read interface " << ifname << " flags: " << errno;
- close(sock);
- return ret;
- }
-
- if (dev_up) {
- if (ifr.ifr_flags & IFF_UP) {
- close(sock);
- return 0;
- }
- ifr.ifr_flags |= IFF_UP;
- } else {
- if (!(ifr.ifr_flags & IFF_UP)) {
- close(sock);
- return 0;
- }
- ifr.ifr_flags &= ~IFF_UP;
- }
-
- if (ioctl(sock, SIOCSIFFLAGS, &ifr) != 0) {
- LOG(ERROR) << "Could not set interface " << ifname << " flags: " << errno;
- ret = errno ? -errno : -999;
- close(sock);
- return ret;
- }
- close(sock);
- return 0;
-}
-
//////////////////
// wrappers
/////////////////
diff --git a/sl4n/facades/wifi/wifi_facade.h b/sl4n/facades/wifi/wifi_facade.h
index d78ab66..c028c5b 100644
--- a/sl4n/facades/wifi/wifi_facade.h
+++ b/sl4n/facades/wifi/wifi_facade.h
@@ -46,5 +46,4 @@
bool SharedValidator();
bool WifiStartHal();
bool WifiGetInterfaces();
- int BringInterfaceUpDown(const char *ifname, int dev_up);
};