aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Berchet <berchet@google.com>2022-05-16 09:42:03 -0700
committerVictor Berchet <berchet@google.com>2022-05-16 21:17:05 +0000
commitc6549e2b7f3126e284a79bcb4a9472be17ca4452 (patch)
treeff97c72bd4320f4ad62bd5a359968b8043c9037c
parent15693f5e93f0c0d68ebe858c1d4f3f98061c7819 (diff)
downloadchre-c6549e2b7f3126e284a79bcb4a9472be17ca4452.tar.gz
Fix disabling the scan monitoringandroid13-dev
updateNanoappScanMonitoringList might be called after a nanoapp is unloaded. In this case we should still update the list of pending subscriptions. Bug: 230656872 Test: CHQTS and added simulation test Change-Id: I1bcc25d7ff9a55f42a1732c336bd02b0b9cbd7ee
-rw-r--r--core/wifi_request_manager.cc17
-rw-r--r--test/simulation/wifi_test.cc73
2 files changed, 85 insertions, 5 deletions
diff --git a/core/wifi_request_manager.cc b/core/wifi_request_manager.cc
index 17ffadec..59396185 100644
--- a/core/wifi_request_manager.cc
+++ b/core/wifi_request_manager.cc
@@ -665,12 +665,21 @@ bool WifiRequestManager::updateNanoappScanMonitoringList(bool enable,
Nanoapp *nanoapp =
EventLoopManagerSingleton::get()->getEventLoop().findNanoappByInstanceId(
instanceId);
+ size_t nanoappIndex;
+ bool hasExistingRequest =
+ nanoappHasScanMonitorRequest(instanceId, &nanoappIndex);
+
if (nanoapp == nullptr) {
- LOGW("Failed to update scan monitoring list for non-existent nanoapp");
+ // When the scan monitoring is disabled from inside nanoappEnd() or when
+ // CHRE cleanup the subscription automatically it is possible that the
+ // current method is called after the nanoapp is unloaded. In such a case
+ // we still want to remove the nanoapp from mScanMonitorNanoapps.
+ if (!enable && hasExistingRequest) {
+ mScanMonitorNanoapps.erase(nanoappIndex);
+ } else {
+ LOGW("Failed to update scan monitoring list for non-existent nanoapp");
+ }
} else {
- size_t nanoappIndex;
- bool hasExistingRequest =
- nanoappHasScanMonitorRequest(instanceId, &nanoappIndex);
if (enable) {
if (!hasExistingRequest) {
// The scan monitor was successfully enabled for this nanoapp and
diff --git a/test/simulation/wifi_test.cc b/test/simulation/wifi_test.cc
index a8f0344c..6ce594f8 100644
--- a/test/simulation/wifi_test.cc
+++ b/test/simulation/wifi_test.cc
@@ -96,7 +96,7 @@ TEST_F(TestBase, WifiCanSubscribeAndUnsubscribeToScanMonitoring) {
EXPECT_FALSE(chrePalWifiIsScanMonitoringActive());
}
-TEST_F(TestBase, WifiSubscribeAreDisabledOnUnload) {
+TEST_F(TestBase, WifiScanMonitoringDisabledOnUnload) {
CREATE_CHRE_TEST_EVENT(MONITORING_REQUEST, 1);
struct MonitoringRequest {
@@ -156,5 +156,76 @@ TEST_F(TestBase, WifiSubscribeAreDisabledOnUnload) {
EXPECT_FALSE(chrePalWifiIsScanMonitoringActive());
}
+TEST_F(TestBase, WifiScanMonitoringDisabledOnUnloadAndCanBeReEnabled) {
+ CREATE_CHRE_TEST_EVENT(MONITORING_REQUEST, 1);
+
+ struct MonitoringRequest {
+ bool enable;
+ uint32_t cookie;
+ };
+
+ struct App : public TestNanoapp {
+ uint32_t perms = NanoappPermissions::CHRE_PERMS_WIFI;
+
+ void (*handleEvent)(uint32_t, uint16_t, const void *) =
+ [](uint32_t, uint16_t eventType, const void *eventData) {
+ static uint32_t cookie;
+
+ switch (eventType) {
+ case CHRE_EVENT_WIFI_ASYNC_RESULT: {
+ auto *event = static_cast<const chreAsyncResult *>(eventData);
+ if (event->success) {
+ TestEventQueueSingleton::get()->pushEvent(
+ CHRE_EVENT_WIFI_ASYNC_RESULT,
+ *(static_cast<const uint32_t *>(event->cookie)));
+ }
+ break;
+ }
+
+ case CHRE_EVENT_TEST_EVENT: {
+ auto event = static_cast<const TestEvent *>(eventData);
+ switch (event->type) {
+ case MONITORING_REQUEST:
+ auto request =
+ static_cast<const MonitoringRequest *>(event->data);
+ cookie = request->cookie;
+ bool success = chreWifiConfigureScanMonitorAsync(
+ request->enable, &cookie);
+ TestEventQueueSingleton::get()->pushEvent(MONITORING_REQUEST,
+ success);
+ }
+ }
+ }
+ };
+ };
+
+ auto app = loadNanoapp<App>();
+ EXPECT_FALSE(chrePalWifiIsScanMonitoringActive());
+
+ MonitoringRequest request{.enable = true, .cookie = 0x123};
+ sendEventToNanoapp(app, MONITORING_REQUEST, request);
+ bool success;
+ waitForEvent(MONITORING_REQUEST, &success);
+ EXPECT_TRUE(success);
+ uint32_t cookie;
+ waitForEvent(CHRE_EVENT_WIFI_ASYNC_RESULT, &cookie);
+ EXPECT_EQ(cookie, request.cookie);
+ EXPECT_TRUE(chrePalWifiIsScanMonitoringActive());
+
+ unloadNanoapp(app);
+ EXPECT_FALSE(chrePalWifiIsScanMonitoringActive());
+
+ app = loadNanoapp<App>();
+ EXPECT_FALSE(chrePalWifiIsScanMonitoringActive());
+
+ request = {.enable = true, .cookie = 0x456};
+ sendEventToNanoapp(app, MONITORING_REQUEST, request);
+ waitForEvent(MONITORING_REQUEST, &success);
+ EXPECT_TRUE(success);
+ waitForEvent(CHRE_EVENT_WIFI_ASYNC_RESULT, &cookie);
+ EXPECT_EQ(cookie, request.cookie);
+ EXPECT_TRUE(chrePalWifiIsScanMonitoringActive());
+}
+
} // namespace
} // namespace chre \ No newline at end of file