summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEtan Cohen <etancohen@google.com>2019-11-27 16:23:34 -0800
committerEtan Cohen <etancohen@google.com>2019-12-01 21:12:23 -0800
commit547dd792ac36cee3d618e06e4bd07311fd430146 (patch)
tree622ab060734a5fb4a1a606de1560eb15d1a1dff6
parent39012048e457542487b6b5d4049ea08ad542c7b2 (diff)
downloadwificond-547dd792ac36cee3d618e06e4bd07311fd430146.tar.gz
Convert NativeWifiClient to native parcel
As part of reverting the stable AIDL interface of wificond, need to move the NativeWifiClient to native parcel. Bug: 140062898 Test: ./system/connectivity/wificond/runtests.sh Test: manual, bring up SAP, connect client - verify information provided Change-Id: I1eaa521c16733b2571a0276fcad4f99f5d04cf5b
-rw-r--r--Android.bp4
-rw-r--r--aidl/com/android/server/wifi/wificond/NativeWifiClient.aidl4
-rw-r--r--ap_interface_impl.cpp6
-rw-r--r--client/native_wifi_client.cpp45
-rw-r--r--client/native_wifi_client.h49
-rw-r--r--tests/ap_interface_impl_unittest.cpp2
-rw-r--r--tests/native_wifi_client_unittest.cpp58
7 files changed, 160 insertions, 8 deletions
diff --git a/Android.bp b/Android.bp
index 2a31d2a..f021f4a 100644
--- a/Android.bp
+++ b/Android.bp
@@ -55,6 +55,7 @@ cc_library_static {
"client_interface_binder.cpp",
"client_interface_impl.cpp",
"logging_utils.cpp",
+ "client/native_wifi_client.cpp",
"scanning/channel_settings.cpp",
"scanning/hidden_network.cpp",
"scanning/pno_network.cpp",
@@ -124,6 +125,7 @@ cc_library_static {
srcs: [
"ipc_constants.cpp",
":libwificond_ipc_aidl",
+ "client/native_wifi_client.cpp",
"scanning/channel_settings.cpp",
"scanning/hidden_network.cpp",
"scanning/pno_network.cpp",
@@ -147,7 +149,6 @@ filegroup {
"aidl/android/net/wifi/ISendMgmtFrameEvent.aidl",
"aidl/android/net/wifi/IWificond.aidl",
"aidl/android/net/wifi/IWifiScannerImpl.aidl",
- "aidl/com/android/server/wifi/wificond/NativeWifiClient.aidl",
],
path: "aidl",
}
@@ -186,6 +187,7 @@ cc_test {
"tests/mock_netlink_manager.cpp",
"tests/mock_netlink_utils.cpp",
"tests/mock_scan_utils.cpp",
+ "tests/native_wifi_client_unittest.cpp",
"tests/netlink_manager_unittest.cpp",
"tests/netlink_utils_unittest.cpp",
"tests/nl80211_attribute_unittest.cpp",
diff --git a/aidl/com/android/server/wifi/wificond/NativeWifiClient.aidl b/aidl/com/android/server/wifi/wificond/NativeWifiClient.aidl
index e8592e3..06cc3c1 100644
--- a/aidl/com/android/server/wifi/wificond/NativeWifiClient.aidl
+++ b/aidl/com/android/server/wifi/wificond/NativeWifiClient.aidl
@@ -16,6 +16,4 @@
package com.android.server.wifi.wificond;
-parcelable NativeWifiClient {
- byte[] macAddress;
-} \ No newline at end of file
+parcelable NativeWifiClient cpp_header "wificond/client/native_wifi_client.h";
diff --git a/ap_interface_impl.cpp b/ap_interface_impl.cpp
index 18fdaf1..bd32ccb 100644
--- a/ap_interface_impl.cpp
+++ b/ap_interface_impl.cpp
@@ -94,12 +94,12 @@ void ApInterfaceImpl::OnStationEvent(
vector<uint8_t> mac_return_address = vector<uint8_t>(mac_address.begin(), mac_address.end());
const auto iterator = std::find_if(connected_clients_.begin(), connected_clients_.end(),
[&] (NativeWifiClient const& p) {
- return p.macAddress == mac_return_address;
+ return p.mac_address_ == mac_return_address;
});
if (iterator == connected_clients_.end()) {
NativeWifiClient station;
- station.macAddress = mac_return_address;
+ station.mac_address_ = mac_return_address;
connected_clients_.push_back(station);
LOG(INFO) << "Sending notifications for station event";
@@ -117,7 +117,7 @@ void ApInterfaceImpl::OnStationEvent(
vector<uint8_t> mac_return_address = vector<uint8_t>(mac_address.begin(), mac_address.end());
const auto iterator = std::find_if(connected_clients_.begin(), connected_clients_.end(),
[&] (NativeWifiClient const& p) {
- return p.macAddress == mac_return_address;
+ return p.mac_address_ == mac_return_address;
});
if (iterator != connected_clients_.end()) {
diff --git a/client/native_wifi_client.cpp b/client/native_wifi_client.cpp
new file mode 100644
index 0000000..f30ae74
--- /dev/null
+++ b/client/native_wifi_client.cpp
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "wificond/client/native_wifi_client.h"
+
+#include <android-base/logging.h>
+
+#include "wificond/parcelable_utils.h"
+
+using android::status_t;
+
+namespace com {
+namespace android {
+namespace server {
+namespace wifi {
+namespace wificond {
+
+status_t NativeWifiClient::writeToParcel(::android::Parcel* parcel) const {
+ RETURN_IF_FAILED(parcel->writeByteVector(mac_address_));
+ return ::android::OK;
+}
+
+status_t NativeWifiClient::readFromParcel(const ::android::Parcel* parcel) {
+ RETURN_IF_FAILED(parcel->readByteVector(&mac_address_));
+ return ::android::OK;
+}
+
+} // namespace wificond
+} // namespace wifi
+} // namespace server
+} // namespace android
+} // namespace com
diff --git a/client/native_wifi_client.h b/client/native_wifi_client.h
new file mode 100644
index 0000000..0bcc9d9
--- /dev/null
+++ b/client/native_wifi_client.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef WIFICOND_NATIVE_WIFI_CLIENT_H_
+#define WIFICOND_NATIVE_WIFI_CLIENT_H_
+
+#include <vector>
+
+#include <binder/Parcel.h>
+#include <binder/Parcelable.h>
+
+namespace com {
+namespace android {
+namespace server {
+namespace wifi {
+namespace wificond {
+
+class NativeWifiClient : public ::android::Parcelable {
+ public:
+ NativeWifiClient() = default;
+ bool operator==(const NativeWifiClient& rhs) const {
+ return mac_address_ == rhs.mac_address_;
+ }
+ ::android::status_t writeToParcel(::android::Parcel* parcel) const override;
+ ::android::status_t readFromParcel(const ::android::Parcel* parcel) override;
+
+ std::vector<uint8_t> mac_address_;
+};
+
+} // namespace wificond
+} // namespace wifi
+} // namespace server
+} // namespace android
+} // namespace com
+
+#endif // WIFICOND_NATIVE_WIFI_CLIENT_H_
diff --git a/tests/ap_interface_impl_unittest.cpp b/tests/ap_interface_impl_unittest.cpp
index 59d9c0f..ba6c71d 100644
--- a/tests/ap_interface_impl_unittest.cpp
+++ b/tests/ap_interface_impl_unittest.cpp
@@ -141,7 +141,7 @@ TEST_F(ApInterfaceImplTest, CanGetConnectedClientsSetsValues) {
std::vector<NativeWifiClient> associated_stations =
ap_interface_->GetConnectedClients();
NativeWifiClient station = associated_stations[0];
- EXPECT_EQ(expected_mac_address, station.macAddress);
+ EXPECT_EQ(expected_mac_address, station.mac_address_);
}
TEST_F(ApInterfaceImplTest, CallbackIsCalledOnConnectedClientsChanged) {
diff --git a/tests/native_wifi_client_unittest.cpp b/tests/native_wifi_client_unittest.cpp
new file mode 100644
index 0000000..64031cf
--- /dev/null
+++ b/tests/native_wifi_client_unittest.cpp
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2019, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <vector>
+
+#include <gtest/gtest.h>
+
+#include "wificond/client/native_wifi_client.h"
+
+using ::com::android::server::wifi::wificond::NativeWifiClient;
+using std::vector;
+
+namespace android {
+namespace wificond {
+
+namespace {
+
+const vector<uint8_t> kMacAddress = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
+const vector<uint8_t> kMacAddressOther = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x0F };
+
+} // namespace
+
+class NativeWifiClientTest : public ::testing::Test {
+};
+
+TEST_F(NativeWifiClientTest, NativeWifiClientParcelableTest) {
+ NativeWifiClient wifi_client;
+ wifi_client.mac_address_ = kMacAddress;
+
+ Parcel parcel;
+ EXPECT_EQ(::android::OK, wifi_client.writeToParcel(&parcel));
+
+ NativeWifiClient wifi_client_copy;
+ parcel.setDataPosition(0);
+ EXPECT_EQ(::android::OK, wifi_client_copy.readFromParcel(&parcel));
+
+ EXPECT_EQ(wifi_client, wifi_client_copy);
+
+ NativeWifiClient wifi_client_other;
+ wifi_client_other.mac_address_ = kMacAddressOther;
+ EXPECT_FALSE(wifi_client == wifi_client_other);
+}
+
+} // namespace wificond
+} // namespace android