Index: chromeos/components/tether/host_scanner.cc |
diff --git a/chromeos/components/tether/host_scanner.cc b/chromeos/components/tether/host_scanner.cc |
index e74407454e4f667e68e155838ecd6926e7b86104..66312c3acb4edbd10c6f596d39f1897cf6edd154 100644 |
--- a/chromeos/components/tether/host_scanner.cc |
+++ b/chromeos/components/tether/host_scanner.cc |
@@ -4,7 +4,10 @@ |
#include "chromeos/components/tether/host_scanner.h" |
+#include <algorithm> |
+ |
#include "base/bind.h" |
+#include "chromeos/components/tether/device_id_tether_network_guid_map.h" |
#include "chromeos/components/tether/tether_host_fetcher.h" |
#include "chromeos/network/network_state.h" |
#include "components/cryptauth/remote_device_loader.h" |
@@ -13,17 +16,35 @@ namespace chromeos { |
namespace tether { |
+namespace { |
+ |
+const char kDefaultCellCarrierName[] = "unknown-carrier"; |
+ |
+// Android signal strength is measured between 0 and 4 (inclusive), but Chrome |
+// OS signal strength is measured between 0 and 100 (inclusive). In order to |
+// convert between Android signal strength to Chrome OS signal strength, the |
+// value must be multiplied by the below value. |
+const int32_t kAndroidTetherHostToChromeOSSignalStrengthMultiplier = 25; |
+ |
+int32_t ForceBetweenZeroAndOneHundred(int32_t value) { |
+ return std::min(std::max(value, 0), 100); |
+} |
+ |
+} // namespace |
+ |
HostScanner::HostScanner( |
TetherHostFetcher* tether_host_fetcher, |
BleConnectionManager* connection_manager, |
HostScanDevicePrioritizer* host_scan_device_prioritizer, |
NetworkStateHandler* network_state_handler, |
- NotificationPresenter* notification_presenter) |
+ NotificationPresenter* notification_presenter, |
+ DeviceIdTetherNetworkGuidMap* device_id_tether_network_guid_map) |
: tether_host_fetcher_(tether_host_fetcher), |
connection_manager_(connection_manager), |
host_scan_device_prioritizer_(host_scan_device_prioritizer), |
network_state_handler_(network_state_handler), |
notification_presenter_(notification_presenter), |
+ device_id_tether_network_guid_map_(device_id_tether_network_guid_map), |
is_fetching_hosts_(false), |
weak_ptr_factory_(this) {} |
@@ -66,13 +87,38 @@ void HostScanner::OnTetherAvailabilityResponse( |
most_recent_scan_results_ = scanned_device_list_so_far; |
if (!scanned_device_list_so_far.empty()) { |
- // TODO (hansberry): Clear out old scanned hosts from NetworkStateHandler. |
- // TODO (hansberry): Add battery and cell strength properties once |
- // available. |
+ // TODO(hansberry): Clear out old scanned hosts from NetworkStateHandler. |
+ // TODO(khorimoto): Use UpdateTetherNetworkProperties if the network already |
+ // exists. |
for (auto& scanned_device_info : scanned_device_list_so_far) { |
- cryptauth::RemoteDevice remote_device = scanned_device_info.remote_device; |
- network_state_handler_->AddTetherNetworkState(remote_device.GetDeviceId(), |
- remote_device.name); |
+ const DeviceStatus& status = scanned_device_info.device_status; |
+ const cryptauth::RemoteDevice& remote_device = |
+ scanned_device_info.remote_device; |
+ |
+ const std::string carrier = |
+ (!status.has_cell_provider() || status.cell_provider().empty()) |
+ ? kDefaultCellCarrierName |
+ : status.cell_provider(); |
+ |
+ // If battery or signal strength are missing, assume they are 100. For |
+ // battery percentage, force the value to be between 0 and 100. For signal |
+ // strength, convert from Android signal strength to Chrome OS signal |
+ // strength and force the value to be between 0 and 100. |
+ const int32_t battery_percentage = |
+ status.has_battery_percentage() |
+ ? ForceBetweenZeroAndOneHundred(status.battery_percentage()) |
+ : 100; |
+ const int32_t signal_strength = |
+ status.has_connection_strength() |
+ ? ForceBetweenZeroAndOneHundred( |
+ kAndroidTetherHostToChromeOSSignalStrengthMultiplier * |
+ status.connection_strength()) |
+ : 100; |
+ |
+ network_state_handler_->AddTetherNetworkState( |
+ device_id_tether_network_guid_map_->GetTetherNetworkGuidForDeviceId( |
+ remote_device.GetDeviceId()), |
+ remote_device.name, carrier, battery_percentage, signal_strength); |
} |
if (scanned_device_list_so_far.size() == 1) { |