blob: 448cd2ad3d10fb1680121980fea3e5b222f65062 [file] [log] [blame]
tengsa72d9762014-08-29 22:56:281// 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
James Hawkins813085e2018-03-30 18:56:415#ifndef CHROMEOS_COMPONENTS_PROXIMITY_AUTH_PROXIMITY_AUTH_SYSTEM_H_
6#define CHROMEOS_COMPONENTS_PROXIMITY_AUTH_PROXIMITY_AUTH_SYSTEM_H_
tengsa72d9762014-08-29 22:56:287
dcheng2f012692016-04-21 00:19:348#include <memory>
tengs2ae24cbb2015-07-22 17:43:199#include <vector>
10
tengsa72d9762014-08-29 22:56:2811#include "base/macros.h"
Kyle Horimotoffeff6a72018-12-01 02:42:0612#include "chromeos/components/multidevice/remote_device_ref.h"
James Hawkins813085e2018-03-30 18:56:4113#include "chromeos/components/proximity_auth/screenlock_bridge.h"
Alexander Alekseev3f09a8f2018-05-03 02:52:1014#include "components/account_id/account_id.h"
tengsa72d9762014-08-29 22:56:2815
Ryan Hansberry56292a02018-06-22 23:39:1916namespace chromeos {
17namespace secure_channel {
18class SecureChannelClient;
19} // namespace secure_channel
20} // namespace chromeos
21
tengsa72d9762014-08-29 22:56:2822namespace proximity_auth {
23
tengsae50e972015-10-02 04:00:4024class ProximityAuthClient;
Ryan Hansberry2104fb82019-07-24 03:06:3725class RemoteDeviceLifeCycle;
tengsae50e972015-10-02 04:00:4026class UnlockManager;
tengs163fa442015-10-01 02:22:1727
tengsae50e972015-10-02 04:00:4028// This is the main entry point to start Proximity Auth, the underlying system
tengsf65903f2015-12-08 08:57:5429// for the Smart Lock feature. Given a list of remote devices (i.e. a
30// phone) for each registered user, the system will handle the connection,
31// authentication, and messenging protocol when the screen is locked and the
32// registered user is focused.
Ryan Hansberry2104fb82019-07-24 03:06:3733class ProximityAuthSystem : public ScreenlockBridge::Observer {
tengsae50e972015-10-02 04:00:4034 public:
tengsa85897c22015-10-29 01:12:0035 enum ScreenlockType { SESSION_LOCK, SIGN_IN };
36
Ryan Hansberry56292a02018-06-22 23:39:1937 ProximityAuthSystem(
38 ScreenlockType screenlock_type,
39 ProximityAuthClient* proximity_auth_client,
40 chromeos::secure_channel::SecureChannelClient* secure_channel_client);
tengsae50e972015-10-02 04:00:4041 ~ProximityAuthSystem() override;
42
tengsf65903f2015-12-08 08:57:5443 // Starts the system to connect and authenticate when a registered user is
44 // focused on the lock/sign-in screen.
tengsae50e972015-10-02 04:00:4045 void Start();
46
tengsf65903f2015-12-08 08:57:5447 // Stops the system.
48 void Stop();
49
alemate546380c2015-12-09 23:54:4650 // Registers a list of |remote_devices| for |account_id| that can be used for
Ryan Hansberry56292a02018-06-22 23:39:1951 // sign-in/unlock. |local_device| represents this device (i.e. this Chrome OS
52 // device) for this particular user profile context. If devices were
53 // previously registered for the user, then they will be replaced.
khorimotode98b9e2016-12-07 22:28:5554 void SetRemoteDevicesForUser(
55 const AccountId& account_id,
Kyle Horimotoffeff6a72018-12-01 02:42:0656 const chromeos::multidevice::RemoteDeviceRefList& remote_devices,
Anton Bikineeva55469fa2021-05-15 18:01:4557 absl::optional<chromeos::multidevice::RemoteDeviceRef> local_device);
tengsf65903f2015-12-08 08:57:5458
alemate546380c2015-12-09 23:54:4659 // Returns the RemoteDevices registered for |account_id|. Returns an empty
60 // list
61 // if no devices are registered for |account_id|.
Kyle Horimotoffeff6a72018-12-01 02:42:0662 chromeos::multidevice::RemoteDeviceRefList GetRemoteDevicesForUser(
khorimotode98b9e2016-12-07 22:28:5563 const AccountId& account_id) const;
tengsf65903f2015-12-08 08:57:5464
tengsae50e972015-10-02 04:00:4065 // Called when the user clicks the user pod and attempts to unlock/sign-in.
James Hawkinse4928152019-11-25 18:21:2666 void OnAuthAttempted();
tengsae50e972015-10-02 04:00:4067
68 // Called when the system suspends.
69 void OnSuspend();
70
71 // Called when the system wakes up from a suspended state.
72 void OnSuspendDone();
tengsa72d9762014-08-29 22:56:2873
Regan Hsu53001b72018-11-27 18:14:4874 // Called in order to disable attempts to get RemoteStatus from host devices.
75 void CancelConnectionAttempt();
76
Curt Clemens6b6173f2021-08-12 20:56:2377 // The last value emitted to the SmartLock.GetRemoteStatus.Unlock(.Failure)
78 // metrics. Helps to understand whether/why not Smart Lock was an available
79 // choice for unlock. Returns the empty string if |unlock_manager_| is
80 // nullptr.
81 std::string GetLastRemoteStatusUnlockForLogging();
82
tengs9fc34de22017-04-04 23:49:1383 protected:
84 // Constructor which allows passing in a custom |unlock_manager_|.
85 // Exposed for testing.
Ryan Hansberry56292a02018-06-22 23:39:1986 ProximityAuthSystem(
Ryan Hansberry56292a02018-06-22 23:39:1987 chromeos::secure_channel::SecureChannelClient* secure_channel_client,
James Hawkinsb5469b5be2018-11-10 02:15:0188 std::unique_ptr<UnlockManager> unlock_manager);
tengs9fc34de22017-04-04 23:49:1389
Ryan Hansberry56292a02018-06-22 23:39:1990 // Creates the RemoteDeviceLifeCycle for |remote_device| and |local_device|.
91 // |remote_device| is the host intended to be connected to, and |local_device|
92 // represents this device (i.e. this Chrome OS device) for this particular
93 // user profile context.
tengs9fc34de22017-04-04 23:49:1394 // Exposed for testing.
95 virtual std::unique_ptr<RemoteDeviceLifeCycle> CreateRemoteDeviceLifeCycle(
Kyle Horimotoffeff6a72018-12-01 02:42:0696 chromeos::multidevice::RemoteDeviceRef remote_device,
Anton Bikineeva55469fa2021-05-15 18:01:4597 absl::optional<chromeos::multidevice::RemoteDeviceRef> local_device);
tengs9fc34de22017-04-04 23:49:1398
tengsae50e972015-10-02 04:00:4099 // ScreenlockBridge::Observer:
100 void OnScreenDidLock(
101 ScreenlockBridge::LockHandler::ScreenType screen_type) override;
102 void OnScreenDidUnlock(
103 ScreenlockBridge::LockHandler::ScreenType screen_type) override;
alemate546380c2015-12-09 23:54:46104 void OnFocusedUserChanged(const AccountId& account_id) override;
tengsae50e972015-10-02 04:00:40105
tengs9fc34de22017-04-04 23:49:13106 private:
alemate546380c2015-12-09 23:54:46107 // Lists of remote devices, keyed by user account id.
Kyle Horimotoffeff6a72018-12-01 02:42:06108 std::map<AccountId, chromeos::multidevice::RemoteDeviceRefList>
109 remote_devices_map_;
tengsae50e972015-10-02 04:00:40110
Ryan Hansberry56292a02018-06-22 23:39:19111 // A mapping from each profile's account ID to the profile-specific
112 // representation of this device (i.e. this Chrome OS device) for that
113 // particular user profile.
Kyle Horimotoffeff6a72018-12-01 02:42:06114 std::map<AccountId, chromeos::multidevice::RemoteDeviceRef> local_device_map_;
Ryan Hansberry56292a02018-06-22 23:39:19115
Ryan Hansberry56292a02018-06-22 23:39:19116 // Entry point to the SecureChannel API.
117 chromeos::secure_channel::SecureChannelClient* secure_channel_client_;
118
tengsae50e972015-10-02 04:00:40119 // Responsible for the life cycle of connecting and authenticating to
tengsf65903f2015-12-08 08:57:54120 // the RemoteDevice of the currently focused user.
dcheng2f012692016-04-21 00:19:34121 std::unique_ptr<RemoteDeviceLifeCycle> remote_device_life_cycle_;
tengsae50e972015-10-02 04:00:40122
sacomoto474f53b2017-07-18 22:37:02123 // Handles the interaction with the lock screen UI.
124 std::unique_ptr<UnlockManager> unlock_manager_;
125
tengsae50e972015-10-02 04:00:40126 // True if the system is suspended.
127 bool suspended_;
128
tengsf65903f2015-12-08 08:57:54129 // True if the system is started_.
130 bool started_;
131
tengsa72d9762014-08-29 22:56:28132 DISALLOW_COPY_AND_ASSIGN(ProximityAuthSystem);
133};
134
135} // namespace proximity_auth
136
James Hawkins813085e2018-03-30 18:56:41137#endif // CHROMEOS_COMPONENTS_PROXIMITY_AUTH_PROXIMITY_AUTH_SYSTEM_H_