OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h" | 5 #include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/chromeos/chromeos_utils.h" | 10 #include "chrome/browser/chromeos/chromeos_utils.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 93 |
94 // Returns true iff the |state| corresponds to a locked remote device. | 94 // Returns true iff the |state| corresponds to a locked remote device. |
95 bool IsLockedState(ScreenlockState state) { | 95 bool IsLockedState(ScreenlockState state) { |
96 return (state == ScreenlockState::PHONE_LOCKED || | 96 return (state == ScreenlockState::PHONE_LOCKED || |
97 state == ScreenlockState::PHONE_LOCKED_AND_TX_POWER_TOO_HIGH); | 97 state == ScreenlockState::PHONE_LOCKED_AND_TX_POWER_TOO_HIGH); |
98 } | 98 } |
99 | 99 |
100 } // namespace | 100 } // namespace |
101 | 101 |
102 EasyUnlockScreenlockStateHandler::EasyUnlockScreenlockStateHandler( | 102 EasyUnlockScreenlockStateHandler::EasyUnlockScreenlockStateHandler( |
103 const std::string& user_email, | 103 const user_manager::UserID& user_id, |
104 HardlockState initial_hardlock_state, | 104 HardlockState initial_hardlock_state, |
105 proximity_auth::ScreenlockBridge* screenlock_bridge) | 105 proximity_auth::ScreenlockBridge* screenlock_bridge) |
106 : state_(ScreenlockState::INACTIVE), | 106 : state_(ScreenlockState::INACTIVE), |
107 user_email_(user_email), | 107 user_id_(user_id), |
108 screenlock_bridge_(screenlock_bridge), | 108 screenlock_bridge_(screenlock_bridge), |
109 hardlock_state_(initial_hardlock_state), | 109 hardlock_state_(initial_hardlock_state), |
110 hardlock_ui_shown_(false), | 110 hardlock_ui_shown_(false), |
111 is_trial_run_(false), | 111 is_trial_run_(false), |
112 did_see_locked_phone_(false) { | 112 did_see_locked_phone_(false) { |
113 DCHECK(screenlock_bridge_); | 113 DCHECK(screenlock_bridge_); |
114 screenlock_bridge_->AddObserver(this); | 114 screenlock_bridge_->AddObserver(this); |
115 } | 115 } |
116 | 116 |
117 EasyUnlockScreenlockStateHandler::~EasyUnlockScreenlockStateHandler() { | 117 EasyUnlockScreenlockStateHandler::~EasyUnlockScreenlockStateHandler() { |
(...skipping 19 matching lines...) Expand all Loading... |
137 return; | 137 return; |
138 | 138 |
139 state_ = new_state; | 139 state_ = new_state; |
140 | 140 |
141 // If lock screen is not active or it forces offline password, just cache the | 141 // If lock screen is not active or it forces offline password, just cache the |
142 // current state. The screenlock state will get refreshed in |ScreenDidLock|. | 142 // current state. The screenlock state will get refreshed in |ScreenDidLock|. |
143 if (!screenlock_bridge_->IsLocked()) | 143 if (!screenlock_bridge_->IsLocked()) |
144 return; | 144 return; |
145 | 145 |
146 // Do nothing when auth type is online. | 146 // Do nothing when auth type is online. |
147 if (screenlock_bridge_->lock_handler()->GetAuthType(user_email_) == | 147 if (screenlock_bridge_->lock_handler()->GetAuthType(user_id_) == |
148 proximity_auth::ScreenlockBridge::LockHandler::ONLINE_SIGN_IN) { | 148 proximity_auth::ScreenlockBridge::LockHandler::ONLINE_SIGN_IN) { |
149 return; | 149 return; |
150 } | 150 } |
151 | 151 |
152 if (IsLockedState(state_)) | 152 if (IsLockedState(state_)) |
153 did_see_locked_phone_ = true; | 153 did_see_locked_phone_ = true; |
154 | 154 |
155 // No hardlock UI for trial run. | 155 // No hardlock UI for trial run. |
156 if (!is_trial_run_ && hardlock_state_ != NO_HARDLOCK) { | 156 if (!is_trial_run_ && hardlock_state_ != NO_HARDLOCK) { |
157 ShowHardlockUI(); | 157 ShowHardlockUI(); |
158 return; | 158 return; |
159 } | 159 } |
160 | 160 |
161 UpdateScreenlockAuthType(); | 161 UpdateScreenlockAuthType(); |
162 | 162 |
163 proximity_auth::ScreenlockBridge::UserPodCustomIcon icon = | 163 proximity_auth::ScreenlockBridge::UserPodCustomIcon icon = |
164 GetIconForState(state_); | 164 GetIconForState(state_); |
165 | 165 |
166 if (icon == proximity_auth::ScreenlockBridge::USER_POD_CUSTOM_ICON_NONE) { | 166 if (icon == proximity_auth::ScreenlockBridge::USER_POD_CUSTOM_ICON_NONE) { |
167 screenlock_bridge_->lock_handler()->HideUserPodCustomIcon(user_email_); | 167 screenlock_bridge_->lock_handler()->HideUserPodCustomIcon(user_id_); |
168 return; | 168 return; |
169 } | 169 } |
170 | 170 |
171 proximity_auth::ScreenlockBridge::UserPodCustomIconOptions icon_options; | 171 proximity_auth::ScreenlockBridge::UserPodCustomIconOptions icon_options; |
172 icon_options.SetIcon(icon); | 172 icon_options.SetIcon(icon); |
173 | 173 |
174 // Don't hardlock on trial run. | 174 // Don't hardlock on trial run. |
175 if (is_trial_run_) | 175 if (is_trial_run_) |
176 icon_options.SetTrialRun(); | 176 icon_options.SetTrialRun(); |
177 else if (HardlockOnClick(state_)) | 177 else if (HardlockOnClick(state_)) |
178 icon_options.SetHardlockOnClick(); | 178 icon_options.SetHardlockOnClick(); |
179 | 179 |
180 UpdateTooltipOptions(&icon_options); | 180 UpdateTooltipOptions(&icon_options); |
181 | 181 |
182 // For states without tooltips, we still need to set an accessibility label. | 182 // For states without tooltips, we still need to set an accessibility label. |
183 if (state_ == ScreenlockState::BLUETOOTH_CONNECTING) { | 183 if (state_ == ScreenlockState::BLUETOOTH_CONNECTING) { |
184 icon_options.SetAriaLabel( | 184 icon_options.SetAriaLabel( |
185 l10n_util::GetStringUTF16(IDS_SMART_LOCK_SPINNER_ACCESSIBILITY_LABEL)); | 185 l10n_util::GetStringUTF16(IDS_SMART_LOCK_SPINNER_ACCESSIBILITY_LABEL)); |
186 } | 186 } |
187 | 187 |
188 screenlock_bridge_->lock_handler()->ShowUserPodCustomIcon(user_email_, | 188 screenlock_bridge_->lock_handler()->ShowUserPodCustomIcon(user_id_, |
189 icon_options); | 189 icon_options); |
190 } | 190 } |
191 | 191 |
192 void EasyUnlockScreenlockStateHandler::SetHardlockState( | 192 void EasyUnlockScreenlockStateHandler::SetHardlockState( |
193 HardlockState new_state) { | 193 HardlockState new_state) { |
194 if (hardlock_state_ == new_state) | 194 if (hardlock_state_ == new_state) |
195 return; | 195 return; |
196 | 196 |
197 if (new_state == LOGIN_FAILED && hardlock_state_ != NO_HARDLOCK) | 197 if (new_state == LOGIN_FAILED && hardlock_state_ != NO_HARDLOCK) |
198 return; | 198 return; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 is_trial_run_ = false; | 241 is_trial_run_ = false; |
242 | 242 |
243 // Upon a successful unlock event, record whether the user's phone was locked | 243 // Upon a successful unlock event, record whether the user's phone was locked |
244 // at any point while the lock screen was up. | 244 // at any point while the lock screen was up. |
245 if (state_ == ScreenlockState::AUTHENTICATED) | 245 if (state_ == ScreenlockState::AUTHENTICATED) |
246 RecordEasyUnlockDidUserManuallyUnlockPhone(did_see_locked_phone_); | 246 RecordEasyUnlockDidUserManuallyUnlockPhone(did_see_locked_phone_); |
247 did_see_locked_phone_ = false; | 247 did_see_locked_phone_ = false; |
248 } | 248 } |
249 | 249 |
250 void EasyUnlockScreenlockStateHandler::OnFocusedUserChanged( | 250 void EasyUnlockScreenlockStateHandler::OnFocusedUserChanged( |
251 const std::string& user_id) { | 251 const user_manager::UserID& user_id) { |
252 } | 252 } |
253 | 253 |
254 void EasyUnlockScreenlockStateHandler::RefreshScreenlockState() { | 254 void EasyUnlockScreenlockStateHandler::RefreshScreenlockState() { |
255 ScreenlockState last_state = state_; | 255 ScreenlockState last_state = state_; |
256 // This should force updating screenlock state. | 256 // This should force updating screenlock state. |
257 state_ = ScreenlockState::INACTIVE; | 257 state_ = ScreenlockState::INACTIVE; |
258 ChangeState(last_state); | 258 ChangeState(last_state); |
259 } | 259 } |
260 | 260 |
261 void EasyUnlockScreenlockStateHandler::ShowHardlockUI() { | 261 void EasyUnlockScreenlockStateHandler::ShowHardlockUI() { |
262 DCHECK(hardlock_state_ != NO_HARDLOCK); | 262 DCHECK(hardlock_state_ != NO_HARDLOCK); |
263 | 263 |
264 if (!screenlock_bridge_->IsLocked()) | 264 if (!screenlock_bridge_->IsLocked()) |
265 return; | 265 return; |
266 | 266 |
267 // Do not override online signin. | 267 // Do not override online signin. |
268 const proximity_auth::ScreenlockBridge::LockHandler::AuthType | 268 const proximity_auth::ScreenlockBridge::LockHandler::AuthType |
269 existing_auth_type = | 269 existing_auth_type = |
270 screenlock_bridge_->lock_handler()->GetAuthType(user_email_); | 270 screenlock_bridge_->lock_handler()->GetAuthType(user_id_); |
271 if (existing_auth_type == | 271 if (existing_auth_type == |
272 proximity_auth::ScreenlockBridge::LockHandler::ONLINE_SIGN_IN) | 272 proximity_auth::ScreenlockBridge::LockHandler::ONLINE_SIGN_IN) |
273 return; | 273 return; |
274 | 274 |
275 if (existing_auth_type != | 275 if (existing_auth_type != |
276 proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD) { | 276 proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD) { |
277 screenlock_bridge_->lock_handler()->SetAuthType( | 277 screenlock_bridge_->lock_handler()->SetAuthType( |
278 user_email_, | 278 user_id_, |
279 proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 279 proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
280 base::string16()); | 280 base::string16()); |
281 } | 281 } |
282 | 282 |
283 if (hardlock_state_ == NO_PAIRING) { | 283 if (hardlock_state_ == NO_PAIRING) { |
284 screenlock_bridge_->lock_handler()->HideUserPodCustomIcon(user_email_); | 284 screenlock_bridge_->lock_handler()->HideUserPodCustomIcon(user_id_); |
285 hardlock_ui_shown_ = false; | 285 hardlock_ui_shown_ = false; |
286 return; | 286 return; |
287 } | 287 } |
288 | 288 |
289 if (hardlock_ui_shown_) | 289 if (hardlock_ui_shown_) |
290 return; | 290 return; |
291 | 291 |
292 proximity_auth::ScreenlockBridge::UserPodCustomIconOptions icon_options; | 292 proximity_auth::ScreenlockBridge::UserPodCustomIconOptions icon_options; |
293 if (hardlock_state_ == LOGIN_FAILED) { | 293 if (hardlock_state_ == LOGIN_FAILED) { |
294 icon_options.SetIcon( | 294 icon_options.SetIcon( |
(...skipping 20 matching lines...) Expand all Loading... |
315 IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_HARDLOCK_PAIRING_ADDED, device_name, | 315 IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_HARDLOCK_PAIRING_ADDED, device_name, |
316 device_name); | 316 device_name); |
317 } else if (hardlock_state_ == LOGIN_FAILED) { | 317 } else if (hardlock_state_ == LOGIN_FAILED) { |
318 tooltip = l10n_util::GetStringUTF16( | 318 tooltip = l10n_util::GetStringUTF16( |
319 IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_LOGIN_FAILURE); | 319 IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_LOGIN_FAILURE); |
320 } else { | 320 } else { |
321 LOG(ERROR) << "Unknown hardlock state " << hardlock_state_; | 321 LOG(ERROR) << "Unknown hardlock state " << hardlock_state_; |
322 } | 322 } |
323 icon_options.SetTooltip(tooltip, true /* autoshow */); | 323 icon_options.SetTooltip(tooltip, true /* autoshow */); |
324 | 324 |
325 screenlock_bridge_->lock_handler()->ShowUserPodCustomIcon(user_email_, | 325 screenlock_bridge_->lock_handler()->ShowUserPodCustomIcon(user_id_, |
326 icon_options); | 326 icon_options); |
327 hardlock_ui_shown_ = true; | 327 hardlock_ui_shown_ = true; |
328 } | 328 } |
329 | 329 |
330 void EasyUnlockScreenlockStateHandler::UpdateTooltipOptions( | 330 void EasyUnlockScreenlockStateHandler::UpdateTooltipOptions( |
331 proximity_auth::ScreenlockBridge::UserPodCustomIconOptions* icon_options) { | 331 proximity_auth::ScreenlockBridge::UserPodCustomIconOptions* icon_options) { |
332 size_t resource_id = 0; | 332 size_t resource_id = 0; |
333 base::string16 device_name; | 333 base::string16 device_name; |
334 if (is_trial_run_ && state_ == ScreenlockState::AUTHENTICATED) { | 334 if (is_trial_run_ && state_ == ScreenlockState::AUTHENTICATED) { |
335 resource_id = IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_INITIAL_AUTHENTICATED; | 335 resource_id = IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_INITIAL_AUTHENTICATED; |
(...skipping 30 matching lines...) Expand all Loading... |
366 #endif | 366 #endif |
367 } | 367 } |
368 | 368 |
369 void EasyUnlockScreenlockStateHandler::UpdateScreenlockAuthType() { | 369 void EasyUnlockScreenlockStateHandler::UpdateScreenlockAuthType() { |
370 if (!is_trial_run_ && hardlock_state_ != NO_HARDLOCK) | 370 if (!is_trial_run_ && hardlock_state_ != NO_HARDLOCK) |
371 return; | 371 return; |
372 | 372 |
373 // Do not override online signin. | 373 // Do not override online signin. |
374 const proximity_auth::ScreenlockBridge::LockHandler::AuthType | 374 const proximity_auth::ScreenlockBridge::LockHandler::AuthType |
375 existing_auth_type = | 375 existing_auth_type = |
376 screenlock_bridge_->lock_handler()->GetAuthType(user_email_); | 376 screenlock_bridge_->lock_handler()->GetAuthType(user_id_); |
377 DCHECK_NE(proximity_auth::ScreenlockBridge::LockHandler::ONLINE_SIGN_IN, | 377 DCHECK_NE(proximity_auth::ScreenlockBridge::LockHandler::ONLINE_SIGN_IN, |
378 existing_auth_type); | 378 existing_auth_type); |
379 | 379 |
380 if (state_ == ScreenlockState::AUTHENTICATED) { | 380 if (state_ == ScreenlockState::AUTHENTICATED) { |
381 if (existing_auth_type != | 381 if (existing_auth_type != |
382 proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK) { | 382 proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK) { |
383 screenlock_bridge_->lock_handler()->SetAuthType( | 383 screenlock_bridge_->lock_handler()->SetAuthType( |
384 user_email_, | 384 user_id_, |
385 proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, | 385 proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, |
386 l10n_util::GetStringUTF16( | 386 l10n_util::GetStringUTF16( |
387 IDS_EASY_UNLOCK_SCREENLOCK_USER_POD_AUTH_VALUE)); | 387 IDS_EASY_UNLOCK_SCREENLOCK_USER_POD_AUTH_VALUE)); |
388 } | 388 } |
389 } else if (existing_auth_type != | 389 } else if (existing_auth_type != |
390 proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD) { | 390 proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD) { |
391 screenlock_bridge_->lock_handler()->SetAuthType( | 391 screenlock_bridge_->lock_handler()->SetAuthType( |
392 user_email_, | 392 user_id_, |
393 proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 393 proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
394 base::string16()); | 394 base::string16()); |
395 } | 395 } |
396 } | 396 } |
OLD | NEW |