shill: Make Manager.UninitializedTechnologies and others mutually exclusive.
If there is at least one device of a particular technology that is
enabled or enabling then it shouldn't be contained in
Manager.UninitializedTechnologies.
BUG=chromium:265002
TEST=1. Build and run unit tests.
2. On a device that contains a built in modem:
- stop modemmanager/cromo
- Run pseudomodem. Make sure that cellular is enabled.
- Check via DBus that Manager.UninitializedTechnologies does not
contain "cellular".
Change-Id: I85e6b06782967255d68a6c73d660fd5e00092d9e
Reviewed-on: https://gerrit.chromium.org/gerrit/63684
Reviewed-by: Ben Chan <benchan@chromium.org>
Commit-Queue: Arman Uguray <armansito@chromium.org>
Tested-by: Arman Uguray <armansito@chromium.org>
diff --git a/device_info.cc b/device_info.cc
index e7240c5..6b2fc15 100644
--- a/device_info.cc
+++ b/device_info.cc
@@ -136,13 +136,20 @@
vector<string> DeviceInfo::GetUninitializedTechnologies() const {
set<string> unique_technologies;
+ set<Technology::Identifier> initialized_technologies;
for (map<int, Info>::const_iterator it = infos_.begin(); it != infos_.end();
++it) {
- if (it->second.device)
- continue;
-
Technology::Identifier technology = it->second.technology;
- if (Technology::IsPrimaryConnectivityTechnology(technology))
+ if (it->second.device) {
+ // If there is more than one device for a technology and at least
+ // one of them has been initialized, make sure that it doesn't get
+ // listed as uninitialized.
+ initialized_technologies.insert(technology);
+ unique_technologies.erase(Technology::NameFromIdentifier(technology));
+ continue;
+ }
+ if (Technology::IsPrimaryConnectivityTechnology(technology) &&
+ !ContainsKey(initialized_technologies, technology))
unique_technologies.insert(Technology::NameFromIdentifier(technology));
}
return vector<string>(unique_technologies.begin(), unique_technologies.end());
diff --git a/device_info_unittest.cc b/device_info_unittest.cc
index 7e9bcfa..384eb5e 100644
--- a/device_info_unittest.cc
+++ b/device_info_unittest.cc
@@ -335,8 +335,12 @@
device_info_.infos_[3].technology = Technology::kCellular;
technologies = device_info_.GetUninitializedTechnologies();
- expected_technologies.insert(Technology::NameFromIdentifier(
- Technology::kCellular));
+ EXPECT_THAT(set<string>(technologies.begin(), technologies.end()),
+ ContainerEq(expected_technologies));
+
+ device_info_.infos_[3].device = device;
+ device_info_.infos_[1].device = NULL;
+ technologies = device_info_.GetUninitializedTechnologies();
EXPECT_THAT(set<string>(technologies.begin(), technologies.end()),
ContainerEq(expected_technologies));
}