proximity_auth_system.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // Copyright 2014 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_PROXIMITY_AUTH_PROXIMITY_AUTH_SYSTEM_H_
  5. #define ASH_COMPONENTS_PROXIMITY_AUTH_PROXIMITY_AUTH_SYSTEM_H_
  6. #include <memory>
  7. #include <vector>
  8. #include "ash/components/multidevice/remote_device_ref.h"
  9. #include "ash/components/proximity_auth/screenlock_bridge.h"
  10. #include "components/account_id/account_id.h"
  11. namespace ash {
  12. namespace secure_channel {
  13. class SecureChannelClient;
  14. }
  15. } // namespace ash
  16. namespace proximity_auth {
  17. class ProximityAuthClient;
  18. class RemoteDeviceLifeCycle;
  19. class UnlockManager;
  20. // This is the main entry point to start Proximity Auth, the underlying system
  21. // for the Smart Lock feature. Given a list of remote devices (i.e. a
  22. // phone) for each registered user, the system will handle the connection,
  23. // authentication, and messenging protocol when the screen is locked and the
  24. // registered user is focused.
  25. class ProximityAuthSystem : public ScreenlockBridge::Observer {
  26. public:
  27. enum ScreenlockType { SESSION_LOCK, SIGN_IN };
  28. ProximityAuthSystem(
  29. ScreenlockType screenlock_type,
  30. ProximityAuthClient* proximity_auth_client,
  31. ash::secure_channel::SecureChannelClient* secure_channel_client);
  32. ProximityAuthSystem(const ProximityAuthSystem&) = delete;
  33. ProximityAuthSystem& operator=(const ProximityAuthSystem&) = delete;
  34. ~ProximityAuthSystem() override;
  35. // Starts the system to connect and authenticate when a registered user is
  36. // focused on the lock/sign-in screen.
  37. void Start();
  38. // Stops the system.
  39. void Stop();
  40. // Registers a list of |remote_devices| for |account_id| that can be used for
  41. // sign-in/unlock. |local_device| represents this device (i.e. this Chrome OS
  42. // device) for this particular user profile context. If devices were
  43. // previously registered for the user, then they will be replaced.
  44. void SetRemoteDevicesForUser(
  45. const AccountId& account_id,
  46. const ash::multidevice::RemoteDeviceRefList& remote_devices,
  47. absl::optional<ash::multidevice::RemoteDeviceRef> local_device);
  48. // Returns the RemoteDevices registered for |account_id|. Returns an empty
  49. // list
  50. // if no devices are registered for |account_id|.
  51. ash::multidevice::RemoteDeviceRefList GetRemoteDevicesForUser(
  52. const AccountId& account_id) const;
  53. // Called when the user clicks the user pod and attempts to unlock/sign-in.
  54. void OnAuthAttempted();
  55. // Called when the system suspends.
  56. void OnSuspend();
  57. // Called when the system wakes up from a suspended state.
  58. void OnSuspendDone();
  59. // Called when the screen turns off.
  60. void OnScreenOff();
  61. // Called when the system resumes after the screen turns back on.
  62. void OnScreenOffDone();
  63. // Called in order to disable attempts to get RemoteStatus from host devices.
  64. void CancelConnectionAttempt();
  65. // The last value emitted to the SmartLock.GetRemoteStatus.Unlock(.Failure)
  66. // metrics. Helps to understand whether/why not Smart Lock was an available
  67. // choice for unlock. Returns the empty string if |unlock_manager_| is
  68. // nullptr.
  69. std::string GetLastRemoteStatusUnlockForLogging();
  70. protected:
  71. // Constructor which allows passing in a custom |unlock_manager_|.
  72. // Exposed for testing.
  73. ProximityAuthSystem(
  74. ash::secure_channel::SecureChannelClient* secure_channel_client,
  75. std::unique_ptr<UnlockManager> unlock_manager);
  76. // Creates the RemoteDeviceLifeCycle for |remote_device| and |local_device|.
  77. // |remote_device| is the host intended to be connected to, and |local_device|
  78. // represents this device (i.e. this Chrome OS device) for this particular
  79. // user profile context.
  80. // Exposed for testing.
  81. virtual std::unique_ptr<RemoteDeviceLifeCycle> CreateRemoteDeviceLifeCycle(
  82. ash::multidevice::RemoteDeviceRef remote_device,
  83. absl::optional<ash::multidevice::RemoteDeviceRef> local_device);
  84. // ScreenlockBridge::Observer:
  85. void OnScreenDidLock(
  86. ScreenlockBridge::LockHandler::ScreenType screen_type) override;
  87. void OnScreenDidUnlock(
  88. ScreenlockBridge::LockHandler::ScreenType screen_type) override;
  89. void OnFocusedUserChanged(const AccountId& account_id) override;
  90. private:
  91. // Called when there is a change in |suspended_| or |screen_off_|.
  92. void OnSuspendOrScreenOffChange();
  93. // Lists of remote devices, keyed by user account id.
  94. std::map<AccountId, ash::multidevice::RemoteDeviceRefList>
  95. remote_devices_map_;
  96. // A mapping from each profile's account ID to the profile-specific
  97. // representation of this device (i.e. this Chrome OS device) for that
  98. // particular user profile.
  99. std::map<AccountId, ash::multidevice::RemoteDeviceRef> local_device_map_;
  100. // Entry point to the SecureChannel API.
  101. ash::secure_channel::SecureChannelClient* secure_channel_client_;
  102. // Responsible for the life cycle of connecting and authenticating to
  103. // the RemoteDevice of the currently focused user.
  104. std::unique_ptr<RemoteDeviceLifeCycle> remote_device_life_cycle_;
  105. // Handles the interaction with the lock screen UI.
  106. std::unique_ptr<UnlockManager> unlock_manager_;
  107. // True if the system is suspended.
  108. bool suspended_ = false;
  109. // True if the screen is off.
  110. bool screen_off_ = false;
  111. // True if the system is started_.
  112. bool started_ = false;
  113. };
  114. } // namespace proximity_auth
  115. #endif // ASH_COMPONENTS_PROXIMITY_AUTH_PROXIMITY_AUTH_SYSTEM_H_