Fallback to default PNO channels if no frequency

PNO scan is sometimes started with an empty channel list. This happens either because there is only suggested network (from mobile carrier) but no saved network or the frequency from saved network is too old or there is an issue with frequency history restore.

In the above case, current design is to scan all supported frequencies again and again which results in high power consumption. This defeats the purpose of "preferred network offload"  which is supposed to scan only a few channels.

The fix to mitigate this issue:
Fall back to default scan channel list if the PNO channel list from framework is empty.

Bug: 196246332
Bug: 195029545
Test: delete all saved network, add one saved network, turn off screen.
      wificond starts with the default PNO channels.
Test: scanner unit test
Change-Id: I153a04cfe9c82a2c9b21f87c10dd46706135cf3f
Merged-In: I153a04cfe9c82a2c9b21f87c10dd46706135cf3f
diff --git a/scanning/scanner_impl.cpp b/scanning/scanner_impl.cpp
index 48ca30f..9a0372b 100644
--- a/scanning/scanner_impl.cpp
+++ b/scanning/scanner_impl.cpp
@@ -243,10 +243,9 @@
     }
   }
 
-  // Also scan the default frequencies if there is frequency data passed down but more than 30% of
+  // Also scan the default frequencies if more than kPercentNetworksWithFreq of
   // networks don't have frequency data.
-  if (unique_frequencies.size() > 0 && num_networks_no_freqs * 100 / match_ssids->size()
-      > kPercentNetworksWithFreq) {
+  if (num_networks_no_freqs * 100 > kPercentNetworksWithFreq * match_ssids->size()) {
     // Filter out frequencies not supported by chip.
     const auto band_2g = client_interface_->GetBandInfo().band_2g;
     for (const auto frequency : kPnoScanDefaultFreqs2G) {
diff --git a/tests/scanner_unittest.cpp b/tests/scanner_unittest.cpp
index dde640e..869a21b 100644
--- a/tests/scanner_unittest.cpp
+++ b/tests/scanner_unittest.cpp
@@ -51,6 +51,8 @@
 
 constexpr uint32_t kFakeInterfaceIndex = 12;
 constexpr uint32_t kFakeScanIntervalMs = 10000;
+vector<uint32_t> kDefaultFrequencies = {2412, 2417, 2422, 2427, 2432, 2437, 2447, 2452, 2457,
+                                        2462, 5180, 5200, 5220, 5240, 5745, 5765, 5785, 5805};
 
 // This is a helper function to mock the behavior of ScanUtils::Scan()
 // when we expect a error code.
@@ -509,10 +511,9 @@
   pno_settings.pno_networks_.push_back(network);
   pno_settings.pno_networks_.push_back(network2);
 
-  std::set<int32_t> default_frequencies = {2412, 2417, 2422, 2427, 2432, 2437, 2447, 2452, 2457,
-                                           2462, 5180, 5200, 5220, 5240, 5745, 5765, 5785, 5805};
-  default_frequencies.insert(5640); // add frequency from saved network
-  vector<uint32_t> expected_frequencies(default_frequencies.begin(), default_frequencies.end());
+  std::set<uint32_t> frequencies(kDefaultFrequencies.begin(), kDefaultFrequencies.end());
+  frequencies.insert(5640); // add frequency from saved network
+  vector<uint32_t> expected_frequencies(frequencies.begin(), frequencies.end());
 
   // Mock BandInfo to make sure the default_frequencies don't get filtered out as invalid.
   BandInfo band_info;
@@ -529,8 +530,8 @@
   EXPECT_TRUE(success);
 }
 
-// Verify that when there is no frequency data all pno networks, an empty list is passed into
-// StartScheduledScan in order to scan all frequencies.
+// Verify that when there is no frequency data in pno networks, default frequencies is passed into
+// StartScheduledScan frequencies.
 TEST_F(ScannerTest, TestStartPnoScanEmptyList) {
   bool success = false;
   ScanCapabilities scan_capabilities_test_frequencies(
@@ -553,7 +554,7 @@
   pno_settings.pno_networks_.push_back(network2);
   EXPECT_CALL(
       scan_utils_,
-      StartScheduledScan(_, _, _, _, _, _, _, _, Eq(vector<uint32_t>{}), _)).
+      StartScheduledScan(_, _, _, _, _, _, _, _, Eq(kDefaultFrequencies), _)).
           WillOnce(Return(true));
   EXPECT_TRUE(scanner_impl.startPnoScan(pno_settings, &success).isOk());
   EXPECT_TRUE(success);