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.
5 #ifndef CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SCREENLOCK_STATE_HANDLER_H_
6 #define CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SCREENLOCK_STATE_HANDLER_H_
10 #include "base/strings/string16.h"
11 #include "chrome/browser/signin/screenlock_bridge.h"
15 // Profile specific class responsible for updating screenlock UI for the user
16 // associated with the profile when their Easy Unlock state changes.
17 class EasyUnlockScreenlockStateHandler
: public ScreenlockBridge::Observer
{
19 // Available Easy Unlock states.
21 // Easy Unlock is not enabled, or the screen is not locked.
23 // Bluetooth is not on.
25 // Easy Unlock is in process of turning on Bluetooth.
26 STATE_BLUETOOTH_CONNECTING
,
27 // No phones eligible to unlock the device can be found.
29 // A phone eligible to unlock the device is found, but cannot be
31 STATE_PHONE_NOT_AUTHENTICATED
,
32 // A phone eligible to unlock the device is found, but it's locked.
34 // A phone eligible to unlock the device is found, but does not have lock
36 STATE_PHONE_UNLOCKABLE
,
37 // An Easy Unlock enabled phone is found, but it is not allowed to unlock
38 // the device because it does not support reporting it's lock screen state.
39 STATE_PHONE_UNSUPPORTED
,
40 // A phone eligible to unlock the device is found, but its received signal
41 // strength is too low, i.e. the phone is roughly more than 30 feet away,
42 // and therefore is not allowed to unlock the device.
44 // A phone eligible to unlock the device is found, but the local device's
45 // transmission power is too high, indicating that the phone is (probably)
46 // more than 1 foot away, and therefore is not allowed to unlock the device.
47 STATE_TX_POWER_TOO_HIGH
,
48 // The device can be unlocked using Easy Unlock.
54 NO_HARDLOCK
= 0, // Hard lock is not enforced. This is default.
55 USER_HARDLOCK
= 1 << 0, // Hard lock is requested by user.
56 PAIRING_CHANGED
= 1 << 1, // Hard lock because pairing data is changed.
57 NO_PAIRING
= 1 << 2, // Hard lock because there is no pairing data.
58 LOGIN_FAILED
= 1 << 3, // Transient hard lock caused by login attempt
59 // failure. Reset when screen is unlocked.
60 PAIRING_ADDED
= 1 << 4, // Similar to PAIRING_CHANGED when it happens
61 // on a new Chromebook.
64 // |user_email|: The email for the user associated with the profile to which
65 // this class is attached.
66 // |initial_hardlock_state|: The initial hardlock state.
67 // |screenlock_bridge|: The screenlock bridge used to update the screen lock
69 EasyUnlockScreenlockStateHandler(const std::string
& user_email
,
70 HardlockState initial_hardlock_state
,
71 ScreenlockBridge
* screenlock_bridge
);
72 ~EasyUnlockScreenlockStateHandler() override
;
74 // Returns true if handler is not in INACTIVE state.
75 bool IsActive() const;
77 // Whether the handler is in state that is allowed just after auth failure
78 // (i.e. the state that would cause auth failure rather than one caused by an
80 bool InStateValidOnRemoteAuthFailure() const;
82 // Changes internal state to |new_state| and updates the user's screenlock
84 void ChangeState(State new_state
);
86 // Updates the screenlock state.
87 void SetHardlockState(HardlockState new_state
);
89 // Shows the hardlock UI if the hardlock_state_ is not NO_HARDLOCK.
90 void MaybeShowHardlockUI();
92 // Marks the current screenlock state as the one for trial Easy Unlock run.
95 State
state() const { return state_
; }
98 // ScreenlockBridge::Observer:
99 void OnScreenDidLock() override
;
100 void OnScreenDidUnlock() override
;
101 void OnFocusedUserChanged(const std::string
& user_id
) override
;
103 // Forces refresh of the Easy Unlock screenlock UI.
104 void RefreshScreenlockState();
106 void ShowHardlockUI();
108 // Updates icon's tooltip options.
109 // |trial_run|: Whether the trial Easy Unlock run is in progress.
110 void UpdateTooltipOptions(
112 ScreenlockBridge::UserPodCustomIconOptions
* icon_options
);
114 // Gets the name to be used for the device. The name depends on the device
115 // type (example values: Chromebook and Chromebox).
116 base::string16
GetDeviceName();
118 // Updates the screenlock auth type if it has to be changed.
119 void UpdateScreenlockAuthType();
122 std::string user_email_
;
123 ScreenlockBridge
* screenlock_bridge_
;
125 // State of hardlock.
126 HardlockState hardlock_state_
;
127 bool hardlock_ui_shown_
;
129 // Whether this is the trial Easy Unlock run. If this is the case, a
130 // tutorial message should be shown and hard-locking be disabled. The trial
131 // run should be set if the screen was locked by the Easy Unlock setup app.
134 DISALLOW_COPY_AND_ASSIGN(EasyUnlockScreenlockStateHandler
);
137 #endif // CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SCREENLOCK_STATE_HANDLER_H_