Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Unified Diff: chromeos/components/tether/host_scanner.cc

Issue 2819383002: [CrOS Tether] Update NetworkState to include tether properties and integrate into NetworkStateHandl… (Closed)
Patch Set: Update TODOs. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..6a253cd03b8a3a4241044fb8cdb23ea92f43d4ea 100644
--- a/chromeos/components/tether/host_scanner.cc
+++ b/chromeos/components/tether/host_scanner.cc
@@ -5,6 +5,7 @@
#include "chromeos/components/tether/host_scanner.h"
#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 +14,39 @@ namespace chromeos {
namespace tether {
+namespace {
+
+// TODO(khorimoto): Localize this name.
+const char kDefaultCellCarrierName[] = "Unknown Carrier";
stevenjb 2017/04/19 17:34:17 We shouldn't be doing localization in this code. J
Kyle Horimoto 2017/04/19 19:23:28 Done.
+
+// 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) {
+ if (value < 0)
+ return 0;
+ if (value > 100)
+ return 100;
+ return value;
+}
stevenjb 2017/04/19 17:34:17 std::min(std::max(valuue, 0), 100);
Kyle Horimoto 2017/04/19 19:23:28 Done.
+}
+
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 +89,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()
+ ? 100
+ : ForceBetweenZeroAndOneHundred(status.battery_percentage());
stevenjb 2017/04/19 17:34:17 invert
Kyle Horimoto 2017/04/19 19:23:28 Done.
+ const int32_t signal_strength =
+ status.has_connection_strength()
+ ? 100
+ : ForceBetweenZeroAndOneHundred(
+ kAndroidTetherHostToChromeOSSignalStrengthMultiplier *
+ status.connection_strength());
stevenjb 2017/04/19 17:34:17 invert
Kyle Horimoto 2017/04/19 19:23:28 Done.
+
+ 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) {

Powered by Google App Engine
This is Rietveld 408576698