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/signin/easy_unlock_metrics.h" | 10 #include "chrome/browser/signin/easy_unlock_metrics.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 | 96 |
97 // Returns true iff the |state| corresponds to a locked remote device. | 97 // Returns true iff the |state| corresponds to a locked remote device. |
98 bool IsLockedState(ScreenlockState state) { | 98 bool IsLockedState(ScreenlockState state) { |
99 return (state == ScreenlockState::PHONE_LOCKED || | 99 return (state == ScreenlockState::PHONE_LOCKED || |
100 state == ScreenlockState::PHONE_LOCKED_AND_TX_POWER_TOO_HIGH); | 100 state == ScreenlockState::PHONE_LOCKED_AND_TX_POWER_TOO_HIGH); |
101 } | 101 } |
102 | 102 |
103 } // namespace | 103 } // namespace |
104 | 104 |
105 EasyUnlockScreenlockStateHandler::EasyUnlockScreenlockStateHandler( | 105 EasyUnlockScreenlockStateHandler::EasyUnlockScreenlockStateHandler( |
106 const std::string& user_email, | 106 const AccountId& account_id, |
107 HardlockState initial_hardlock_state, | 107 HardlockState initial_hardlock_state, |
108 proximity_auth::ScreenlockBridge* screenlock_bridge) | 108 proximity_auth::ScreenlockBridge* screenlock_bridge) |
109 : state_(ScreenlockState::INACTIVE), | 109 : state_(ScreenlockState::INACTIVE), |
110 user_email_(user_email), | 110 account_id_(account_id), |
111 screenlock_bridge_(screenlock_bridge), | 111 screenlock_bridge_(screenlock_bridge), |
112 hardlock_state_(initial_hardlock_state), | 112 hardlock_state_(initial_hardlock_state) { |
113 hardlock_ui_shown_(false), | |
114 is_trial_run_(false), | |
115 did_see_locked_phone_(false) { | |
116 DCHECK(screenlock_bridge_); | 113 DCHECK(screenlock_bridge_); |
117 screenlock_bridge_->AddObserver(this); | 114 screenlock_bridge_->AddObserver(this); |
118 } | 115 } |
119 | 116 |
120 EasyUnlockScreenlockStateHandler::~EasyUnlockScreenlockStateHandler() { | 117 EasyUnlockScreenlockStateHandler::~EasyUnlockScreenlockStateHandler() { |
121 screenlock_bridge_->RemoveObserver(this); | 118 screenlock_bridge_->RemoveObserver(this); |
122 // Make sure the screenlock state set by this gets cleared. | 119 // Make sure the screenlock state set by this gets cleared. |
123 ChangeState(ScreenlockState::INACTIVE); | 120 ChangeState(ScreenlockState::INACTIVE); |
124 } | 121 } |
125 | 122 |
(...skipping 14 matching lines...) Expand all Loading... |
140 return; | 137 return; |
141 | 138 |
142 state_ = new_state; | 139 state_ = new_state; |
143 | 140 |
144 // 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 |
145 // current state. The screenlock state will get refreshed in |ScreenDidLock|. | 142 // current state. The screenlock state will get refreshed in |ScreenDidLock|. |
146 if (!screenlock_bridge_->IsLocked()) | 143 if (!screenlock_bridge_->IsLocked()) |
147 return; | 144 return; |
148 | 145 |
149 // Do nothing when auth type is online. | 146 // Do nothing when auth type is online. |
150 if (screenlock_bridge_->lock_handler()->GetAuthType(user_email_) == | 147 if (screenlock_bridge_->lock_handler()->GetAuthType(account_id_) == |
151 proximity_auth::ScreenlockBridge::LockHandler::ONLINE_SIGN_IN) { | 148 proximity_auth::ScreenlockBridge::LockHandler::ONLINE_SIGN_IN) { |
152 return; | 149 return; |
153 } | 150 } |
154 | 151 |
155 if (IsLockedState(state_)) | 152 if (IsLockedState(state_)) |
156 did_see_locked_phone_ = true; | 153 did_see_locked_phone_ = true; |
157 | 154 |
158 // No hardlock UI for trial run. | 155 // No hardlock UI for trial run. |
159 if (!is_trial_run_ && hardlock_state_ != NO_HARDLOCK) { | 156 if (!is_trial_run_ && hardlock_state_ != NO_HARDLOCK) { |
160 ShowHardlockUI(); | 157 ShowHardlockUI(); |
161 return; | 158 return; |
162 } | 159 } |
163 | 160 |
164 UpdateScreenlockAuthType(); | 161 UpdateScreenlockAuthType(); |
165 | 162 |
166 proximity_auth::ScreenlockBridge::UserPodCustomIcon icon = | 163 proximity_auth::ScreenlockBridge::UserPodCustomIcon icon = |
167 GetIconForState(state_); | 164 GetIconForState(state_); |
168 | 165 |
169 if (icon == proximity_auth::ScreenlockBridge::USER_POD_CUSTOM_ICON_NONE) { | 166 if (icon == proximity_auth::ScreenlockBridge::USER_POD_CUSTOM_ICON_NONE) { |
170 screenlock_bridge_->lock_handler()->HideUserPodCustomIcon(user_email_); | 167 screenlock_bridge_->lock_handler()->HideUserPodCustomIcon(account_id_); |
171 return; | 168 return; |
172 } | 169 } |
173 | 170 |
174 proximity_auth::ScreenlockBridge::UserPodCustomIconOptions icon_options; | 171 proximity_auth::ScreenlockBridge::UserPodCustomIconOptions icon_options; |
175 icon_options.SetIcon(icon); | 172 icon_options.SetIcon(icon); |
176 | 173 |
177 // Don't hardlock on trial run. | 174 // Don't hardlock on trial run. |
178 if (is_trial_run_) | 175 if (is_trial_run_) |
179 icon_options.SetTrialRun(); | 176 icon_options.SetTrialRun(); |
180 else if (HardlockOnClick(state_)) | 177 else if (HardlockOnClick(state_)) |
181 icon_options.SetHardlockOnClick(); | 178 icon_options.SetHardlockOnClick(); |
182 | 179 |
183 UpdateTooltipOptions(&icon_options); | 180 UpdateTooltipOptions(&icon_options); |
184 | 181 |
185 // 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. |
186 if (state_ == ScreenlockState::BLUETOOTH_CONNECTING) { | 183 if (state_ == ScreenlockState::BLUETOOTH_CONNECTING) { |
187 icon_options.SetAriaLabel( | 184 icon_options.SetAriaLabel( |
188 l10n_util::GetStringUTF16(IDS_SMART_LOCK_SPINNER_ACCESSIBILITY_LABEL)); | 185 l10n_util::GetStringUTF16(IDS_SMART_LOCK_SPINNER_ACCESSIBILITY_LABEL)); |
189 } | 186 } |
190 | 187 |
191 screenlock_bridge_->lock_handler()->ShowUserPodCustomIcon(user_email_, | 188 screenlock_bridge_->lock_handler()->ShowUserPodCustomIcon(account_id_, |
192 icon_options); | 189 icon_options); |
193 } | 190 } |
194 | 191 |
195 void EasyUnlockScreenlockStateHandler::SetHardlockState( | 192 void EasyUnlockScreenlockStateHandler::SetHardlockState( |
196 HardlockState new_state) { | 193 HardlockState new_state) { |
197 if (hardlock_state_ == new_state) | 194 if (hardlock_state_ == new_state) |
198 return; | 195 return; |
199 | 196 |
200 if (new_state == LOGIN_FAILED && hardlock_state_ != NO_HARDLOCK) | 197 if (new_state == LOGIN_FAILED && hardlock_state_ != NO_HARDLOCK) |
201 return; | 198 return; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 is_trial_run_ = false; | 241 is_trial_run_ = false; |
245 | 242 |
246 // 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 |
247 // at any point while the lock screen was up. | 244 // at any point while the lock screen was up. |
248 if (state_ == ScreenlockState::AUTHENTICATED) | 245 if (state_ == ScreenlockState::AUTHENTICATED) |
249 RecordEasyUnlockDidUserManuallyUnlockPhone(did_see_locked_phone_); | 246 RecordEasyUnlockDidUserManuallyUnlockPhone(did_see_locked_phone_); |
250 did_see_locked_phone_ = false; | 247 did_see_locked_phone_ = false; |
251 } | 248 } |
252 | 249 |
253 void EasyUnlockScreenlockStateHandler::OnFocusedUserChanged( | 250 void EasyUnlockScreenlockStateHandler::OnFocusedUserChanged( |
254 const std::string& user_id) { | 251 const AccountId& account_id) {} |
255 } | |
256 | 252 |
257 void EasyUnlockScreenlockStateHandler::RefreshScreenlockState() { | 253 void EasyUnlockScreenlockStateHandler::RefreshScreenlockState() { |
258 ScreenlockState last_state = state_; | 254 ScreenlockState last_state = state_; |
259 // This should force updating screenlock state. | 255 // This should force updating screenlock state. |
260 state_ = ScreenlockState::INACTIVE; | 256 state_ = ScreenlockState::INACTIVE; |
261 ChangeState(last_state); | 257 ChangeState(last_state); |
262 } | 258 } |
263 | 259 |
264 void EasyUnlockScreenlockStateHandler::ShowHardlockUI() { | 260 void EasyUnlockScreenlockStateHandler::ShowHardlockUI() { |
265 DCHECK(hardlock_state_ != NO_HARDLOCK); | 261 DCHECK(hardlock_state_ != NO_HARDLOCK); |
266 | 262 |
267 if (!screenlock_bridge_->IsLocked()) | 263 if (!screenlock_bridge_->IsLocked()) |
268 return; | 264 return; |
269 | 265 |
270 // Do not override online signin. | 266 // Do not override online signin. |
271 const proximity_auth::ScreenlockBridge::LockHandler::AuthType | 267 const proximity_auth::ScreenlockBridge::LockHandler::AuthType |
272 existing_auth_type = | 268 existing_auth_type = |
273 screenlock_bridge_->lock_handler()->GetAuthType(user_email_); | 269 screenlock_bridge_->lock_handler()->GetAuthType(account_id_); |
274 if (existing_auth_type == | 270 if (existing_auth_type == |
275 proximity_auth::ScreenlockBridge::LockHandler::ONLINE_SIGN_IN) | 271 proximity_auth::ScreenlockBridge::LockHandler::ONLINE_SIGN_IN) |
276 return; | 272 return; |
277 | 273 |
278 if (existing_auth_type != | 274 if (existing_auth_type != |
279 proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD) { | 275 proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD) { |
280 screenlock_bridge_->lock_handler()->SetAuthType( | 276 screenlock_bridge_->lock_handler()->SetAuthType( |
281 user_email_, | 277 account_id_, |
282 proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 278 proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
283 base::string16()); | 279 base::string16()); |
284 } | 280 } |
285 | 281 |
286 if (hardlock_state_ == NO_PAIRING) { | 282 if (hardlock_state_ == NO_PAIRING) { |
287 screenlock_bridge_->lock_handler()->HideUserPodCustomIcon(user_email_); | 283 screenlock_bridge_->lock_handler()->HideUserPodCustomIcon(account_id_); |
288 hardlock_ui_shown_ = false; | 284 hardlock_ui_shown_ = false; |
289 return; | 285 return; |
290 } | 286 } |
291 | 287 |
292 if (hardlock_ui_shown_) | 288 if (hardlock_ui_shown_) |
293 return; | 289 return; |
294 | 290 |
295 proximity_auth::ScreenlockBridge::UserPodCustomIconOptions icon_options; | 291 proximity_auth::ScreenlockBridge::UserPodCustomIconOptions icon_options; |
296 if (hardlock_state_ == LOGIN_FAILED) { | 292 if (hardlock_state_ == LOGIN_FAILED) { |
297 icon_options.SetIcon( | 293 icon_options.SetIcon( |
(...skipping 20 matching lines...) Expand all Loading... |
318 IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_HARDLOCK_PAIRING_ADDED, device_name, | 314 IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_HARDLOCK_PAIRING_ADDED, device_name, |
319 device_name); | 315 device_name); |
320 } else if (hardlock_state_ == LOGIN_FAILED) { | 316 } else if (hardlock_state_ == LOGIN_FAILED) { |
321 tooltip = l10n_util::GetStringUTF16( | 317 tooltip = l10n_util::GetStringUTF16( |
322 IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_LOGIN_FAILURE); | 318 IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_LOGIN_FAILURE); |
323 } else { | 319 } else { |
324 LOG(ERROR) << "Unknown hardlock state " << hardlock_state_; | 320 LOG(ERROR) << "Unknown hardlock state " << hardlock_state_; |
325 } | 321 } |
326 icon_options.SetTooltip(tooltip, true /* autoshow */); | 322 icon_options.SetTooltip(tooltip, true /* autoshow */); |
327 | 323 |
328 screenlock_bridge_->lock_handler()->ShowUserPodCustomIcon(user_email_, | 324 screenlock_bridge_->lock_handler()->ShowUserPodCustomIcon(account_id_, |
329 icon_options); | 325 icon_options); |
330 hardlock_ui_shown_ = true; | 326 hardlock_ui_shown_ = true; |
331 } | 327 } |
332 | 328 |
333 void EasyUnlockScreenlockStateHandler::UpdateTooltipOptions( | 329 void EasyUnlockScreenlockStateHandler::UpdateTooltipOptions( |
334 proximity_auth::ScreenlockBridge::UserPodCustomIconOptions* icon_options) { | 330 proximity_auth::ScreenlockBridge::UserPodCustomIconOptions* icon_options) { |
335 size_t resource_id = 0; | 331 size_t resource_id = 0; |
336 base::string16 device_name; | 332 base::string16 device_name; |
337 if (is_trial_run_ && state_ == ScreenlockState::AUTHENTICATED) { | 333 if (is_trial_run_ && state_ == ScreenlockState::AUTHENTICATED) { |
338 resource_id = IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_INITIAL_AUTHENTICATED; | 334 resource_id = IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_INITIAL_AUTHENTICATED; |
(...skipping 30 matching lines...) Expand all Loading... |
369 #endif | 365 #endif |
370 } | 366 } |
371 | 367 |
372 void EasyUnlockScreenlockStateHandler::UpdateScreenlockAuthType() { | 368 void EasyUnlockScreenlockStateHandler::UpdateScreenlockAuthType() { |
373 if (!is_trial_run_ && hardlock_state_ != NO_HARDLOCK) | 369 if (!is_trial_run_ && hardlock_state_ != NO_HARDLOCK) |
374 return; | 370 return; |
375 | 371 |
376 // Do not override online signin. | 372 // Do not override online signin. |
377 const proximity_auth::ScreenlockBridge::LockHandler::AuthType | 373 const proximity_auth::ScreenlockBridge::LockHandler::AuthType |
378 existing_auth_type = | 374 existing_auth_type = |
379 screenlock_bridge_->lock_handler()->GetAuthType(user_email_); | 375 screenlock_bridge_->lock_handler()->GetAuthType(account_id_); |
380 DCHECK_NE(proximity_auth::ScreenlockBridge::LockHandler::ONLINE_SIGN_IN, | 376 DCHECK_NE(proximity_auth::ScreenlockBridge::LockHandler::ONLINE_SIGN_IN, |
381 existing_auth_type); | 377 existing_auth_type); |
382 | 378 |
383 if (state_ == ScreenlockState::AUTHENTICATED) { | 379 if (state_ == ScreenlockState::AUTHENTICATED) { |
384 if (existing_auth_type != | 380 if (existing_auth_type != |
385 proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK) { | 381 proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK) { |
386 screenlock_bridge_->lock_handler()->SetAuthType( | 382 screenlock_bridge_->lock_handler()->SetAuthType( |
387 user_email_, | 383 account_id_, |
388 proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, | 384 proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, |
389 l10n_util::GetStringUTF16( | 385 l10n_util::GetStringUTF16( |
390 IDS_EASY_UNLOCK_SCREENLOCK_USER_POD_AUTH_VALUE)); | 386 IDS_EASY_UNLOCK_SCREENLOCK_USER_POD_AUTH_VALUE)); |
391 } | 387 } |
392 } else if (existing_auth_type != | 388 } else if (existing_auth_type != |
393 proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD) { | 389 proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD) { |
394 screenlock_bridge_->lock_handler()->SetAuthType( | 390 screenlock_bridge_->lock_handler()->SetAuthType( |
395 user_email_, | 391 account_id_, |
396 proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 392 proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
397 base::string16()); | 393 base::string16()); |
398 } | 394 } |
399 } | 395 } |
OLD | NEW |