esim_manager.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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_ESIM_MANAGER_H_
  5. #define ASH_SERVICES_CELLULAR_SETUP_ESIM_MANAGER_H_
  6. #include "ash/services/cellular_setup/public/mojom/esim_manager.mojom.h"
  7. #include "base/memory/weak_ptr.h"
  8. #include "chromeos/ash/components/dbus/hermes/hermes_euicc_client.h"
  9. #include "chromeos/ash/components/dbus/hermes/hermes_manager_client.h"
  10. #include "chromeos/ash/components/dbus/hermes/hermes_profile_client.h"
  11. #include "chromeos/ash/components/network/cellular_esim_profile_handler.h"
  12. #include "mojo/public/cpp/bindings/pending_remote.h"
  13. #include "mojo/public/cpp/bindings/receiver_set.h"
  14. #include "mojo/public/cpp/bindings/remote_set.h"
  15. namespace dbus {
  16. class ObjectPath;
  17. }
  18. namespace ash {
  19. class CellularConnectionHandler;
  20. class CellularESimInstaller;
  21. class CellularESimUninstallHandler;
  22. class CellularInhibitor;
  23. class NetworkConnectionHandler;
  24. class NetworkStateHandler;
  25. namespace cellular_setup {
  26. class Euicc;
  27. class ESimProfile;
  28. // Implementation of mojom::ESimManager. This class uses the Hermes
  29. // DBus clients to communicate with the Hermes daemon and provide
  30. // eSIM management methods. ESimManager mojo interface is provided
  31. // in WebUI for cellular settings and eSIM setup.
  32. class ESimManager : public mojom::ESimManager,
  33. CellularESimProfileHandler::Observer,
  34. HermesManagerClient::Observer,
  35. HermesEuiccClient::Observer {
  36. public:
  37. static std::string GetRootSmdsAddress();
  38. ESimManager();
  39. ESimManager(CellularConnectionHandler* cellular_connection_handler,
  40. CellularESimInstaller* cellular_esim_installer,
  41. CellularESimProfileHandler* cellular_esim_profile_handler,
  42. CellularESimUninstallHandler* cellular_esim_uninstall_handler,
  43. CellularInhibitor* cellular_inhibitor,
  44. NetworkConnectionHandler* network_connection_handler,
  45. NetworkStateHandler* network_state_handler);
  46. ESimManager(const ESimManager&) = delete;
  47. ESimManager& operator=(const ESimManager&) = delete;
  48. ~ESimManager() override;
  49. // mojom::ESimManager
  50. void AddObserver(
  51. mojo::PendingRemote<mojom::ESimManagerObserver> observer) override;
  52. void GetAvailableEuiccs(GetAvailableEuiccsCallback callback) override;
  53. // HermesManagerClient::Observer:
  54. void OnAvailableEuiccListChanged() override;
  55. // HermesEuiccClient::Observer:
  56. void OnEuiccPropertyChanged(const dbus::ObjectPath& euicc_path,
  57. const std::string& property_name) override;
  58. // CellularESimProfileHandler::Observer:
  59. void OnESimProfileListUpdated() override;
  60. // Binds receiver to this instance.
  61. void BindReceiver(mojo::PendingReceiver<mojom::ESimManager> receiver);
  62. // Notifies observers of changes to ESimProfiles.
  63. void NotifyESimProfileChanged(ESimProfile* esim_profile);
  64. // Notifies observers of changes to ESimProfile Lists.
  65. void NotifyESimProfileListChanged(Euicc* euicc);
  66. CellularESimInstaller* cellular_esim_installer() {
  67. return cellular_esim_installer_;
  68. }
  69. CellularESimProfileHandler* cellular_esim_profile_handler() {
  70. return cellular_esim_profile_handler_;
  71. }
  72. CellularConnectionHandler* cellular_connection_handler() {
  73. return cellular_connection_handler_;
  74. }
  75. CellularESimUninstallHandler* cellular_esim_uninstall_handler() {
  76. return cellular_esim_uninstall_handler_;
  77. }
  78. CellularInhibitor* cellular_inhibitor() { return cellular_inhibitor_; }
  79. NetworkConnectionHandler* network_connection_handler() {
  80. return network_connection_handler_;
  81. }
  82. NetworkStateHandler* network_state_handler() {
  83. return network_state_handler_;
  84. }
  85. private:
  86. void UpdateAvailableEuiccs();
  87. // Removes Euicc objects in |available_euiiccs_| that are not in
  88. // |new_euicc_paths|. Returns true if any euicc objects were removed.
  89. bool RemoveUntrackedEuiccs(const std::set<dbus::ObjectPath> new_euicc_paths);
  90. Euicc* GetEuiccFromPath(const dbus::ObjectPath& path);
  91. // Creates a new Euicc object in |available_euiccs_| if it doesn't already
  92. // exist. Returns true if a new object was created.
  93. bool CreateEuiccIfNew(const dbus::ObjectPath& euicc_path);
  94. CellularConnectionHandler* cellular_connection_handler_;
  95. CellularESimInstaller* cellular_esim_installer_;
  96. CellularESimProfileHandler* cellular_esim_profile_handler_;
  97. CellularESimUninstallHandler* cellular_esim_uninstall_handler_;
  98. CellularInhibitor* cellular_inhibitor_;
  99. NetworkConnectionHandler* network_connection_handler_;
  100. NetworkStateHandler* network_state_handler_;
  101. std::vector<std::unique_ptr<Euicc>> available_euiccs_;
  102. mojo::RemoteSet<mojom::ESimManagerObserver> observers_;
  103. mojo::ReceiverSet<mojom::ESimManager> receivers_;
  104. base::WeakPtrFactory<ESimManager> weak_ptr_factory_{this};
  105. };
  106. } // namespace cellular_setup
  107. } // namespace ash
  108. // TODO(https://crbug.com/1164001): remove after the migration is finished.
  109. namespace chromeos::cellular_setup {
  110. using ::ash::cellular_setup::ESimManager;
  111. }
  112. #endif // ASH_SERVICES_CELLULAR_SETUP_ESIM_MANAGER_H_