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 // A phone eligible to unlock the device is found; but (a) the phone is
49 // locked, and (b) the local device's transmission power is too high,
50 // indicating that the phone is (probably) more than 1 foot away, and
51 // therefore is not allowed to unlock the device.
52 STATE_PHONE_LOCKED_AND_TX_POWER_TOO_HIGH
,
53 // The device can be unlocked using Easy Unlock.
59 NO_HARDLOCK
= 0, // Hard lock is not enforced. This is default.
60 USER_HARDLOCK
= 1 << 0, // Hard lock is requested by user.
61 PAIRING_CHANGED
= 1 << 1, // Hard lock because pairing data is changed.
62 NO_PAIRING
= 1 << 2, // Hard lock because there is no pairing data.
63 LOGIN_FAILED
= 1 << 3, // Transient hard lock caused by login attempt
64 // failure. Reset when screen is unlocked.
65 PAIRING_ADDED
= 1 << 4, // Similar to PAIRING_CHANGED when it happens
66 // on a new Chromebook.
69 // |user_email|: The email for the user associated with the profile to which
70 // this class is attached.
71 // |initial_hardlock_state|: The initial hardlock state.
72 // |screenlock_bridge|: The screenlock bridge used to update the screen lock
74 EasyUnlockScreenlockStateHandler(const std::string
& user_email
,
75 HardlockState initial_hardlock_state
,
76 ScreenlockBridge
* screenlock_bridge
);
77 ~EasyUnlockScreenlockStateHandler() override
;
79 // Returns true if handler is not in INACTIVE state.
80 bool IsActive() const;
82 // Whether the handler is in state that is allowed just after auth failure
83 // (i.e. the state that would cause auth failure rather than one caused by an
85 bool InStateValidOnRemoteAuthFailure() const;
87 // Changes internal state to |new_state| and updates the user's screenlock
89 void ChangeState(State new_state
);
91 // Updates the screenlock state.
92 void SetHardlockState(HardlockState new_state
);
94 // Shows the hardlock UI if the hardlock_state_ is not NO_HARDLOCK.
95 void MaybeShowHardlockUI();
97 // Marks the current screenlock state as the one for trial Easy Unlock run.
100 // Records that the user clicked on the lock icon during the trial run
101 // initiated by the Easy Unlock app.
102 void RecordClickOnLockIcon();
104 State
state() const { return state_
; }
107 // ScreenlockBridge::Observer:
108 void OnScreenDidLock(
109 ScreenlockBridge::LockHandler::ScreenType screen_type
) override
;
110 void OnScreenDidUnlock(
111 ScreenlockBridge::LockHandler::ScreenType screen_type
) override
;
112 void OnFocusedUserChanged(const std::string
& user_id
) override
;
114 // Forces refresh of the Easy Unlock screenlock UI.
115 void RefreshScreenlockState();
117 void ShowHardlockUI();
119 // Updates icon's tooltip options.
120 void UpdateTooltipOptions(
121 ScreenlockBridge::UserPodCustomIconOptions
* icon_options
);
123 // Gets the name to be used for the device. The name depends on the device
124 // type (example values: Chromebook and Chromebox).
125 base::string16
GetDeviceName();
127 // Updates the screenlock auth type if it has to be changed.
128 void UpdateScreenlockAuthType();
131 std::string user_email_
;
132 ScreenlockBridge
* screenlock_bridge_
;
134 // State of hardlock.
135 HardlockState hardlock_state_
;
136 bool hardlock_ui_shown_
;
138 // Whether this is the trial Easy Unlock run. If this is the case, a
139 // tutorial message should be shown and hard-locking be disabled. The trial
140 // run should be set if the screen was locked by the Easy Unlock setup app.
143 DISALLOW_COPY_AND_ASSIGN(EasyUnlockScreenlockStateHandler
);
146 #endif // CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SCREENLOCK_STATE_HANDLER_H_