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 5 #ifndef CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SCREENLOCK_STATE_HANDLER_H_ 6 #define CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SCREENLOCK_STATE_HANDLER_H_ 7 8 #include <string> 9 10 #include "base/strings/string16.h" 11 #include "base/timer/timer.h" 12 #include "chrome/browser/signin/screenlock_bridge.h" 13 14 class PrefService; 15 16 // Profile specific class responsible for updating screenlock UI for the user 17 // associated with the profile when their Easy Unlock state changes. 18 class EasyUnlockScreenlockStateHandler : public ScreenlockBridge::Observer { 19 public: 20 // Available Easy Unlock states. 21 enum State { 22 // Easy Unlock is not enabled, or the screen is not locked. 23 STATE_INACTIVE, 24 // Bluetooth is not on. 25 STATE_NO_BLUETOOTH, 26 // Easy Unlock is in process of turning on Bluetooth. 27 STATE_BLUETOOTH_CONNECTING, 28 // No phones eligible to unlock the device can be found. 29 STATE_NO_PHONE, 30 // A phone eligible to unlock the device is found, but cannot be 31 // authenticated. 32 STATE_PHONE_NOT_AUTHENTICATED, 33 // A phone eligible to unlock the device is found, but it's locked. 34 STATE_PHONE_LOCKED, 35 // A phone eligible to unlock the device is found, but does not have lock 36 // screen enabled. 37 STATE_PHONE_UNLOCKABLE, 38 // A phone eligible to unlock the device is found, but it's not close enough 39 // to be allowed to unlock the device. 40 STATE_PHONE_NOT_NEARBY, 41 // An Easy Unlock enabled phone is found, but it is not allowed to unlock 42 // the device because it does not support reporting it's lock screen state. 43 STATE_PHONE_UNSUPPORTED, 44 // The device can be unlocked using Easy Unlock. 45 STATE_AUTHENTICATED 46 }; 47 48 // Hard lock states. 49 enum HardlockState { 50 NO_HARDLOCK = 0, // Hard lock is not enforced. This is default. 51 USER_HARDLOCK = 1 << 0, // Hard lock is requested by user. 52 PAIRING_CHANGED = 1 << 1, // Hard lock because pairing data is changed. 53 NO_PAIRING = 1 << 2, // Hard lock because there is no pairing data. 54 LOGIN_FAILED = 1 << 3, // Transient hard lock caused by login attempt 55 // failure. Reset when screen is unlocked. 56 PAIRING_ADDED = 1 << 4, // Similar to PAIRING_CHANGED when it happens 57 // on a new Chromebook. 58 }; 59 60 // |user_email|: The email for the user associated with the profile to which 61 // this class is attached. 62 // |initial_hardlock_state|: The initial hardlock state. 63 // |screenlock_bridge|: The screenlock bridge used to update the screen lock 64 // state. 65 EasyUnlockScreenlockStateHandler(const std::string& user_email, 66 HardlockState initial_hardlock_state, 67 ScreenlockBridge* screenlock_bridge); 68 virtual ~EasyUnlockScreenlockStateHandler(); 69 70 // Returns true if handler is not in INACTIVE state. 71 bool IsActive() const; 72 73 // Changes internal state to |new_state| and updates the user's screenlock 74 // accordingly. 75 void ChangeState(State new_state); 76 77 // Updates the screenlock state. 78 void SetHardlockState(HardlockState new_state); 79 80 // Shows the hardlock UI if the hardlock_state_ is not NO_HARDLOCK. 81 void MaybeShowHardlockUI(); 82 83 // Marks the current screenlock state as the one for trial Easy Unlock run. 84 void SetTrialRun(); 85 86 State state() const { return state_; } 87 88 private: 89 // ScreenlockBridge::Observer: 90 virtual void OnScreenDidLock() OVERRIDE; 91 virtual void OnScreenDidUnlock() OVERRIDE; 92 virtual void OnFocusedUserChanged(const std::string& user_id) OVERRIDE; 93 94 // Forces refresh of the Easy Unlock screenlock UI. 95 void RefreshScreenlockState(); 96 97 void ShowHardlockUI(); 98 99 // Updates icon's tooltip options. 100 // |trial_run|: Whether the trial Easy Unlock run is in progress. 101 void UpdateTooltipOptions( 102 bool trial_run, 103 ScreenlockBridge::UserPodCustomIconOptions* icon_options); 104 105 // Gets the name to be used for the device. The name depends on the device 106 // type (example values: Chromebook and Chromebox). 107 base::string16 GetDeviceName(); 108 109 // Updates the screenlock auth type if it has to be changed. 110 void UpdateScreenlockAuthType(); 111 112 State state_; 113 std::string user_email_; 114 ScreenlockBridge* screenlock_bridge_; 115 116 // State of hardlock. 117 HardlockState hardlock_state_; 118 bool hardlock_ui_shown_; 119 120 // Whether this is the trial Easy Unlock run. If this is the case, a 121 // tutorial message should be shown and hard-locking be disabled. The trial 122 // run should be set if the screen was locked by the Easy Unlock setup app. 123 bool is_trial_run_; 124 125 DISALLOW_COPY_AND_ASSIGN(EasyUnlockScreenlockStateHandler); 126 }; 127 128 #endif // CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SCREENLOCK_STATE_HANDLER_H_ 129