• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/connectivity/wificond


Commit MetaInfo

Révision9f0fd68f7877ac8dc234eea35ab2e6e960a2b947 (tree)
l'heure2017-03-17 10:03:31
AuteurNingyuan Wang <nywang@goog...>
CommiterNingyuan Wang

Message de Log

Add wificond API to expose number of associated stations

Bug: 31230864
Test: compile, unit tests, manual test
Change-Id: I28cc755a79c0fb3905a6684ea1281428a5bc2afc

Change Summary

Modification

--- a/aidl/android/net/wifi/IApInterface.aidl
+++ b/aidl/android/net/wifi/IApInterface.aidl
@@ -50,4 +50,8 @@ interface IApInterface {
5050 @utf8InCpp
5151 String getInterfaceName();
5252
53+ // @return Returns the number of associated devices to this hotspot.
54+ // Returns -1 on failure.
55+ int getNumberOfAssociatedStations();
56+
5357 }
--- a/ap_interface_binder.cpp
+++ b/ap_interface_binder.cpp
@@ -96,5 +96,17 @@ binder::Status ApInterfaceBinder::getInterfaceName(std::string* out_name) {
9696 return binder::Status::ok();
9797 }
9898
99+binder::Status ApInterfaceBinder::getNumberOfAssociatedStations(
100+ int* out_num_of_stations) {
101+ if (!impl_) {
102+ LOG(WARNING) << "Cannot get number of associated stations "
103+ << "from dead ApInterface";
104+ *out_num_of_stations = -1;
105+ return binder::Status::ok();
106+ }
107+ *out_num_of_stations = impl_->GetNumberOfAssociatedStations();
108+ return binder::Status::ok();
109+}
110+
99111 } // namespace wificond
100112 } // namespace android
--- a/ap_interface_binder.h
+++ b/ap_interface_binder.h
@@ -45,6 +45,8 @@ class ApInterfaceBinder : public android::net::wifi::BnApInterface {
4545 const std::vector<uint8_t>& passphrase,
4646 bool* out_success) override;
4747 binder::Status getInterfaceName(std::string* out_name) override;
48+ binder::Status getNumberOfAssociatedStations(
49+ int* out_num_of_stations) override;
4850
4951 private:
5052 ApInterfaceImpl* impl_;
--- a/ap_interface_impl.cpp
+++ b/ap_interface_impl.cpp
@@ -47,7 +47,8 @@ ApInterfaceImpl::ApInterfaceImpl(const string& interface_name,
4747 netlink_utils_(netlink_utils),
4848 if_tool_(if_tool),
4949 hostapd_manager_(hostapd_manager),
50- binder_(new ApInterfaceBinder(this)) {
50+ binder_(new ApInterfaceBinder(this)),
51+ number_of_associated_stations_(0) {
5152 // This log keeps compiler happy.
5253 LOG(DEBUG) << "Created ap interface " << interface_name_
5354 << " with index " << interface_index_;
@@ -120,12 +121,23 @@ void ApInterfaceImpl::OnStationEvent(StationEvent event,
120121 LOG(INFO) << "New station "
121122 << LoggingUtils::GetMacString(mac_address)
122123 << " associated with hotspot";
124+ number_of_associated_stations_++;
123125 } else if (event == DEL_STATION) {
124126 LOG(INFO) << "Station "
125127 << LoggingUtils::GetMacString(mac_address)
126128 << " disassociated from hotspot";
129+ if (number_of_associated_stations_ <= 0) {
130+ LOG(ERROR) << "Received DEL_STATION event when station counter is: "
131+ << number_of_associated_stations_;
132+ } else {
133+ number_of_associated_stations_--;
134+ }
127135 }
128136 }
129137
138+int ApInterfaceImpl::GetNumberOfAssociatedStations() const {
139+ return number_of_associated_stations_;
140+}
141+
130142 } // namespace wificond
131143 } // namespace android
--- a/ap_interface_impl.h
+++ b/ap_interface_impl.h
@@ -59,6 +59,7 @@ class ApInterfaceImpl {
5959 wifi_system::HostapdManager::EncryptionType encryption_type,
6060 const std::vector<uint8_t>& passphrase);
6161 std::string GetInterfaceName() { return interface_name_; }
62+ int GetNumberOfAssociatedStations() const;
6263
6364 private:
6465 const std::string interface_name_;
@@ -68,6 +69,9 @@ class ApInterfaceImpl {
6869 wifi_system::HostapdManager* const hostapd_manager_;
6970 const android::sp<ApInterfaceBinder> binder_;
7071
72+ // Number of associated stations.
73+ int number_of_associated_stations_;
74+
7175 void OnStationEvent(StationEvent event,
7276 const std::vector<uint8_t>& mac_address);
7377
--- a/tests/ap_interface_impl_unittest.cpp
+++ b/tests/ap_interface_impl_unittest.cpp
@@ -30,9 +30,12 @@
3030 using android::wifi_system::HostapdManager;
3131 using android::wifi_system::MockHostapdManager;
3232 using android::wifi_system::MockInterfaceTool;
33+using std::placeholders::_1;
34+using std::placeholders::_2;
3335 using std::unique_ptr;
3436 using std::vector;
3537 using testing::NiceMock;
38+using testing::Invoke;
3639 using testing::Return;
3740 using testing::Sequence;
3841 using testing::StrEq;
@@ -44,6 +47,14 @@ namespace {
4447
4548 const char kTestInterfaceName[] = "testwifi0";
4649 const uint32_t kTestInterfaceIndex = 42;
50+const uint8_t kFakeMacAddress[] = {0x45, 0x54, 0xad, 0x67, 0x98, 0xf6};
51+
52+void CaptureStationEventHandler(
53+ OnStationEventHandler* out_handler,
54+ uint32_t interface_index,
55+ OnStationEventHandler handler) {
56+ *out_handler = handler;
57+}
4758
4859 class ApInterfaceImplTest : public ::testing::Test {
4960 protected:
@@ -59,9 +70,6 @@ class ApInterfaceImplTest : public ::testing::Test {
5970 unique_ptr<ApInterfaceImpl> ap_interface_;
6071
6172 void SetUp() override {
62- EXPECT_CALL(*netlink_utils_,
63- SubscribeStationEvent(kTestInterfaceIndex, _));
64-
6573 ap_interface_.reset(new ApInterfaceImpl(
6674 kTestInterfaceName,
6775 kTestInterfaceIndex,
@@ -115,5 +123,29 @@ TEST_F(ApInterfaceImplTest, ShouldRejectInvalidConfig) {
115123 vector<uint8_t>()));
116124 }
117125
126+TEST_F(ApInterfaceImplTest, CanGetNumberOfAssociatedStations) {
127+ OnStationEventHandler handler;
128+ EXPECT_CALL(*netlink_utils_,
129+ SubscribeStationEvent(kTestInterfaceIndex, _)).
130+ WillOnce(Invoke(bind(CaptureStationEventHandler, &handler, _1, _2)));
131+
132+ ap_interface_.reset(new ApInterfaceImpl(
133+ kTestInterfaceName,
134+ kTestInterfaceIndex,
135+ netlink_utils_.get(),
136+ if_tool_.get(),
137+ hostapd_manager_.get()));
138+
139+ vector<uint8_t> fake_mac_address(kFakeMacAddress,
140+ kFakeMacAddress + sizeof(kFakeMacAddress));
141+ EXPECT_EQ(0, ap_interface_->GetNumberOfAssociatedStations());
142+ handler(NEW_STATION, fake_mac_address);
143+ EXPECT_EQ(1, ap_interface_->GetNumberOfAssociatedStations());
144+ handler(NEW_STATION, fake_mac_address);
145+ EXPECT_EQ(2, ap_interface_->GetNumberOfAssociatedStations());
146+ handler(DEL_STATION, fake_mac_address);
147+ EXPECT_EQ(1, ap_interface_->GetNumberOfAssociatedStations());
148+}
149+
118150 } // namespace wificond
119151 } // namespace android