Merge "Fix NAN validate interface existence" into rvc-dev am: 8fce7985c0 am: 9f1854e292

Change-Id: Ifaf2424b7f0ab61ca5f363f202c813153f1200a2
This commit is contained in:
Nate Jiang
2020-05-21 20:35:54 +00:00
committed by Automerger Merge Worker
5 changed files with 10 additions and 2 deletions

View File

@@ -41,6 +41,7 @@ class MockWifiIfaceUtil : public WifiIfaceUtil {
void(const std::string&, IfaceEventHandlers));
MOCK_METHOD1(unregisterIfaceEventHandlers, void(const std::string&));
MOCK_METHOD2(setUpState, bool(const std::string&, bool));
MOCK_METHOD1(ifNameToIndex, unsigned(const std::string&));
};
} // namespace iface_util
} // namespace implementation

View File

@@ -787,6 +787,8 @@ TEST_F(WifiChipV2_AwareIfaceCombinationTest, CreateNanWithDedicatedNanIface) {
property_set("wifi.aware.interface", "aware0");
findModeAndConfigureForIfaceType(IfaceType::STA);
ASSERT_EQ(createIface(IfaceType::STA), "wlan0");
EXPECT_CALL(*iface_util_, ifNameToIndex("aware0"))
.WillOnce(testing::Return(4));
EXPECT_CALL(*iface_util_, setUpState("aware0", true))
.WillOnce(testing::Return(true));
ASSERT_EQ(createIface(IfaceType::NAN), "aware0");

View File

@@ -19,7 +19,6 @@
#include <android-base/logging.h>
#include <android-base/unique_fd.h>
#include <cutils/properties.h>
#include <net/if.h>
#include <sys/stat.h>
#include <sys/sysmacros.h>
@@ -886,7 +885,7 @@ std::pair<WifiStatus, sp<IWifiNanIface>> WifiChip::createNanIfaceInternal() {
}
bool is_dedicated_iface = true;
std::string ifname = getNanIfaceName();
if (ifname.empty() || if_nametoindex(ifname.c_str())) {
if (ifname.empty() || !iface_util_.lock()->ifNameToIndex(ifname)) {
// Use the first shared STA iface (wlan0) if a dedicated aware iface is
// not defined.
ifname = getFirstActiveWlanIfaceName();

View File

@@ -14,6 +14,7 @@
* limitations under the License.
*/
#include <net/if.h>
#include <cstddef>
#include <iostream>
#include <limits>
@@ -122,6 +123,10 @@ bool WifiIfaceUtil::setUpState(const std::string& iface_name, bool request_up) {
}
return true;
}
unsigned WifiIfaceUtil::ifNameToIndex(const std::string& iface_name) {
return if_nametoindex(iface_name.c_str());
}
} // namespace iface_util
} // namespace implementation
} // namespace V1_4

View File

@@ -57,6 +57,7 @@ class WifiIfaceUtil {
IfaceEventHandlers handlers);
virtual void unregisterIfaceEventHandlers(const std::string& iface_name);
virtual bool setUpState(const std::string& iface_name, bool request_up);
virtual unsigned ifNameToIndex(const std::string& iface_name);
private:
std::array<uint8_t, 6> createRandomMacAddress();