managed_sim_lock_notifier.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright 2022 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_SYSTEM_NETWORK_MANAGED_SIM_LOCK_NOTIFIER_H_
  5. #define ASH_SYSTEM_NETWORK_MANAGED_SIM_LOCK_NOTIFIER_H_
  6. #include "ash/ash_export.h"
  7. #include "ash/public/cpp/session/session_observer.h"
  8. #include "base/gtest_prod_util.h"
  9. #include "base/memory/weak_ptr.h"
  10. #include "chromeos/services/network_config/public/cpp/cros_network_config_observer.h"
  11. #include "mojo/public/cpp/bindings/remote.h"
  12. #include "ui/message_center/public/cpp/notification.h"
  13. namespace ash {
  14. // Notifies the user to unlock the currently active PIN locked SIM if the
  15. // restrict cellular SIM lock Global Network Configuration is set to true.
  16. class ASH_EXPORT ManagedSimLockNotifier
  17. : public SessionObserver,
  18. public chromeos::network_config::CrosNetworkConfigObserver,
  19. public message_center::NotificationObserver {
  20. public:
  21. ManagedSimLockNotifier();
  22. ManagedSimLockNotifier(const ManagedSimLockNotifier&) = delete;
  23. ManagedSimLockNotifier& operator=(const ManagedSimLockNotifier&) = delete;
  24. ~ManagedSimLockNotifier() override;
  25. private:
  26. friend class ManagedSimLockNotifierTest;
  27. // SessionObserver:
  28. void OnSessionStateChanged(session_manager::SessionState state) override;
  29. // message_center::NotificationObserver:
  30. void Close(bool by_user) override;
  31. void Click(const absl::optional<int>& button_index,
  32. const absl::optional<std::u16string>& reply) override;
  33. // CrosNetworkConfigObserver:
  34. void OnDeviceStateListChanged() override;
  35. void OnPoliciesApplied(const std::string& userhash) override;
  36. void OnGetDeviceStateList(
  37. std::vector<chromeos::network_config::mojom::DeviceStatePropertiesPtr>
  38. devices);
  39. void OnCellularNetworksList(
  40. std::vector<chromeos::network_config::mojom::NetworkStatePropertiesPtr>
  41. networks);
  42. void OnGetGlobalPolicy(
  43. chromeos::network_config::mojom::GlobalPolicyPtr global_policy);
  44. void RemoveNotification();
  45. void CheckGlobalNetworkConfiguration();
  46. void MaybeShowNotification();
  47. void ShowNotification();
  48. static const char kManagedSimLockNotificationId[];
  49. std::string primary_iccid_ = std::string();
  50. mojo::Remote<chromeos::network_config::mojom::CrosNetworkConfig>
  51. remote_cros_network_config_;
  52. mojo::Receiver<chromeos::network_config::mojom::CrosNetworkConfigObserver>
  53. cros_network_config_observer_receiver_{this};
  54. base::WeakPtrFactory<ManagedSimLockNotifier> weak_ptr_factory_{this};
  55. };
  56. } // namespace ash
  57. #endif // ASH_SYSTEM_NETWORK_MANAGED_SIM_LOCK_NOTIFIER_H_