phone_status_model.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // Copyright 2020 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. #ifndef ASH_COMPONENTS_PHONEHUB_PHONE_STATUS_MODEL_H_
  5. #define ASH_COMPONENTS_PHONEHUB_PHONE_STATUS_MODEL_H_
  6. #include <stdint.h>
  7. #include <ostream>
  8. #include <string>
  9. #include "third_party/abseil-cpp/absl/types/optional.h"
  10. namespace ash {
  11. namespace phonehub {
  12. // Contains properties representing a phone's status, including mobile
  13. // connection state and battery/power state.
  14. class PhoneStatusModel {
  15. public:
  16. enum class MobileStatus {
  17. // The phone does not have a physical SIM inserted or an eSIM profile set
  18. // up.
  19. kNoSim = 0,
  20. // The phone has a SIM, but it is not connected to a mobile network.
  21. kSimButNoReception = 1,
  22. // The phone has a SIM and is connected to a mobile network using that SIM.
  23. kSimWithReception = 2
  24. };
  25. // Number of "bars" in the connection strength; only applies when the device
  26. // has reception.
  27. enum class SignalStrength {
  28. kZeroBars = 0,
  29. kOneBar = 1,
  30. kTwoBars = 2,
  31. kThreeBars = 3,
  32. kFourBars = 4
  33. };
  34. struct MobileConnectionMetadata {
  35. bool operator==(const MobileConnectionMetadata& other) const;
  36. bool operator!=(const MobileConnectionMetadata& other) const;
  37. SignalStrength signal_strength;
  38. // Name of the service provider (e.g., "Google Fi").
  39. std::u16string mobile_provider;
  40. };
  41. enum class ChargingState {
  42. // Not charging (i.e., on battery power).
  43. kNotCharging = 0,
  44. // Charging via AC adapter.
  45. kChargingAc = 1,
  46. // Charging via a USB connection.
  47. kChargingUsb = 2
  48. };
  49. // Android devices can enable "battery saver" mode, which causes the battery
  50. // charge to last longer by reducing/eliminating functionality with
  51. // significant power impact.
  52. enum class BatterySaverState { kOff = 0, kOn = 1 };
  53. // Note: If |mobile_status| is not kSimWithReception,
  54. // |mobile_connection_metadata| should be null.
  55. PhoneStatusModel(MobileStatus mobile_status,
  56. const absl::optional<MobileConnectionMetadata>&
  57. mobile_connection_metadata,
  58. ChargingState charging_state,
  59. BatterySaverState battery_saver_state,
  60. uint32_t battery_percentage);
  61. PhoneStatusModel(const PhoneStatusModel& other);
  62. ~PhoneStatusModel();
  63. bool operator==(const PhoneStatusModel& other) const;
  64. bool operator!=(const PhoneStatusModel& other) const;
  65. MobileStatus mobile_status() const { return mobile_status_; }
  66. // Note: Null when mobile_status() is not kSimWithReception.
  67. const absl::optional<MobileConnectionMetadata>& mobile_connection_metadata()
  68. const {
  69. return mobile_connection_metadata_;
  70. }
  71. ChargingState charging_state() const { return charging_state_; }
  72. BatterySaverState battery_saver_state() const { return battery_saver_state_; }
  73. uint32_t battery_percentage() const { return battery_percentage_; }
  74. private:
  75. MobileStatus mobile_status_;
  76. absl::optional<MobileConnectionMetadata> mobile_connection_metadata_;
  77. ChargingState charging_state_;
  78. BatterySaverState battery_saver_state_;
  79. uint32_t battery_percentage_;
  80. };
  81. std::ostream& operator<<(std::ostream& stream,
  82. PhoneStatusModel::MobileStatus mobile_status);
  83. std::ostream& operator<<(std::ostream& stream,
  84. PhoneStatusModel::SignalStrength signal_strength);
  85. std::ostream& operator<<(
  86. std::ostream& stream,
  87. PhoneStatusModel::MobileConnectionMetadata mobile_connection_metadata);
  88. std::ostream& operator<<(std::ostream& stream,
  89. PhoneStatusModel::ChargingState charging_state);
  90. std::ostream& operator<<(
  91. std::ostream& stream,
  92. PhoneStatusModel::BatterySaverState battery_saver_state);
  93. } // namespace phonehub
  94. } // namespace ash
  95. // TODO(https://crbug.com/1164001): remove after the migration is finished.
  96. namespace chromeos {
  97. namespace phonehub {
  98. using ::ash::phonehub::PhoneStatusModel;
  99. }
  100. } // namespace chromeos
  101. #endif // ASH_COMPONENTS_PHONEHUB_PHONE_STATUS_MODEL_H_