euicc.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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_SERVICES_CELLULAR_SETUP_EUICC_H_
  5. #define ASH_SERVICES_CELLULAR_SETUP_EUICC_H_
  6. #include "ash/services/cellular_setup/public/mojom/esim_manager.mojom.h"
  7. #include "base/gtest_prod_util.h"
  8. #include "chromeos/ash/components/dbus/hermes/hermes_euicc_client.h"
  9. #include "chromeos/ash/components/dbus/hermes/hermes_profile_client.h"
  10. #include "chromeos/ash/components/network/cellular_inhibitor.h"
  11. #include "mojo/public/cpp/bindings/receiver_set.h"
  12. namespace dbus {
  13. class ObjectPath;
  14. }
  15. namespace ash {
  16. class CellularESimProfile;
  17. namespace cellular_setup {
  18. class ESimProfile;
  19. class ESimManager;
  20. // Implementation of mojom::Euicc. This class represents an EUICC hardware
  21. // available on the device. Euicc holds multiple ESimProfile instances.
  22. class Euicc : public mojom::Euicc {
  23. public:
  24. Euicc(const dbus::ObjectPath& path, ESimManager* esim_manager);
  25. Euicc(const Euicc&) = delete;
  26. Euicc& operator=(const Euicc&) = delete;
  27. ~Euicc() override;
  28. // mojom::Euicc:
  29. void GetProperties(GetPropertiesCallback callback) override;
  30. void GetProfileList(GetProfileListCallback callback) override;
  31. void InstallProfileFromActivationCode(
  32. const std::string& activation_code,
  33. const std::string& confirmation_code,
  34. bool is_install_via_qr_code,
  35. InstallProfileFromActivationCodeCallback callback) override;
  36. void RequestPendingProfiles(RequestPendingProfilesCallback callback) override;
  37. void GetEidQRCode(GetEidQRCodeCallback callback) override;
  38. // Updates list of eSIM profiles for this euicc from with the given
  39. // |esim_profile_states|.
  40. void UpdateProfileList(
  41. const std::vector<CellularESimProfile>& esim_profile_states);
  42. // Updates properties for this Euicc from D-Bus.
  43. void UpdateProperties();
  44. // Returns a new pending remote attached to this instance.
  45. mojo::PendingRemote<mojom::Euicc> CreateRemote();
  46. // Returns ESimProfile instance under this Euicc with given path.
  47. ESimProfile* GetProfileFromPath(const dbus::ObjectPath& path);
  48. const dbus::ObjectPath& path() { return path_; }
  49. const mojom::EuiccPropertiesPtr& properties() { return properties_; }
  50. private:
  51. FRIEND_TEST_ALL_PREFIXES(EuiccTest, RequestPendingProfiles);
  52. // These values are persisted to logs. Entries should not be renumbered and
  53. // numeric values should never be reused.
  54. enum class RequestPendingProfilesResult {
  55. kSuccess = 0,
  56. kInhibitFailed = 1,
  57. kHermesRequestFailed = 2,
  58. kMaxValue = kHermesRequestFailed
  59. };
  60. static void RecordRequestPendingProfilesResult(
  61. RequestPendingProfilesResult result);
  62. void OnESimInstallProfileResult(
  63. InstallProfileFromActivationCodeCallback callback,
  64. HermesResponseStatus hermes_status,
  65. absl::optional<dbus::ObjectPath> profile_path,
  66. absl::optional<std::string> service_path);
  67. void PerformRequestPendingProfiles(
  68. RequestPendingProfilesCallback callback,
  69. std::unique_ptr<CellularInhibitor::InhibitLock> inhibit_lock);
  70. void OnRequestPendingProfilesResult(
  71. RequestPendingProfilesCallback callback,
  72. std::unique_ptr<CellularInhibitor::InhibitLock> inhibit_lock,
  73. HermesResponseStatus status);
  74. mojom::ProfileInstallResult GetPendingProfileInfoFromActivationCode(
  75. const std::string& activation_code,
  76. ESimProfile** profile_info);
  77. // Updates an ESimProfile in |esim_profiles_| with values from given
  78. // |esim_profile_state| or creates new one if it doesn't exist. Returns
  79. // pointer to ESimProfile object if one was created.
  80. ESimProfile* UpdateOrCreateESimProfile(
  81. const CellularESimProfile& esim_profile_state);
  82. // Removes any ESimProfile object in |esim_profiles_| that doesn't exists in
  83. // given |esim_profile_states|. Returns true if any profiles were removed.
  84. bool RemoveUntrackedProfiles(
  85. const std::vector<CellularESimProfile>& esim_profile_states);
  86. // Reference to ESimManager that owns this Euicc.
  87. ESimManager* esim_manager_;
  88. mojo::ReceiverSet<mojom::Euicc> receiver_set_;
  89. mojom::EuiccPropertiesPtr properties_;
  90. dbus::ObjectPath path_;
  91. std::vector<std::unique_ptr<ESimProfile>> esim_profiles_;
  92. // Maps profile dbus paths to InstallProfileFromActivation method callbacks
  93. // that are pending creation of a new ESimProfile object.
  94. std::map<dbus::ObjectPath, InstallProfileFromActivationCodeCallback>
  95. install_calls_pending_create_;
  96. base::WeakPtrFactory<Euicc> weak_ptr_factory_{this};
  97. };
  98. } // namespace cellular_setup
  99. } // namespace ash
  100. #endif // ASH_SERVICES_CELLULAR_SETUP_EUICC_H_