| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chromeos/components/tether/device_status_util.h" |
| 6 |
| 7 namespace chromeos { |
| 8 |
| 9 namespace tether { |
| 10 |
| 11 namespace { |
| 12 |
| 13 const char kDefaultCellCarrierName[] = "unknown-carrier"; |
| 14 |
| 15 // Android signal strength is measured between 0 and 4 (inclusive), but Chrome |
| 16 // OS signal strength is measured between 0 and 100 (inclusive). In order to |
| 17 // convert between Android signal strength to Chrome OS signal strength, the |
| 18 // value must be multiplied by the below value. |
| 19 const int32_t kAndroidTetherHostToChromeOSSignalStrengthMultiplier = 25; |
| 20 |
| 21 int32_t ForceBetweenZeroAndOneHundred(int32_t value) { |
| 22 return std::min(std::max(value, 0), 100); |
| 23 } |
| 24 |
| 25 } // namespace |
| 26 |
| 27 void NormalizeDeviceStatus(const DeviceStatus& status, |
| 28 std::string* carrier_out, |
| 29 int32_t* battery_percentage_out, |
| 30 int32_t* signal_strength_out) { |
| 31 // Use a sentinel value if carrier information is not available. This value is |
| 32 // special-cased and replaced with a localized string in the settings UI. |
| 33 if (carrier_out) { |
| 34 *carrier_out = |
| 35 (!status.has_cell_provider() || status.cell_provider().empty()) |
| 36 ? kDefaultCellCarrierName |
| 37 : status.cell_provider(); |
| 38 } |
| 39 |
| 40 // If battery or signal strength are missing, assume they are 100. For |
| 41 // battery percentage, force the value to be between 0 and 100. For signal |
| 42 // strength, convert from Android signal strength to Chrome OS signal |
| 43 // strength and force the value to be between 0 and 100. |
| 44 if (battery_percentage_out) { |
| 45 *battery_percentage_out = |
| 46 status.has_battery_percentage() |
| 47 ? ForceBetweenZeroAndOneHundred(status.battery_percentage()) |
| 48 : 100; |
| 49 } |
| 50 if (signal_strength_out) { |
| 51 *signal_strength_out = |
| 52 status.has_connection_strength() |
| 53 ? ForceBetweenZeroAndOneHundred( |
| 54 kAndroidTetherHostToChromeOSSignalStrengthMultiplier * |
| 55 status.connection_strength()) |
| 56 : 100; |
| 57 } |
| 58 } |
| 59 |
| 60 } // namespace tether |
| 61 |
| 62 } // namespace chromeos |
| OLD | NEW |