| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/proximity_auth/unlock_manager_impl.h" | 5 #include "components/proximity_auth/unlock_manager_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 SetWakingUpState(true); | 144 SetWakingUpState(true); |
| 145 } else { | 145 } else { |
| 146 proximity_monitor_.reset(); | 146 proximity_monitor_.reset(); |
| 147 } | 147 } |
| 148 | 148 |
| 149 UpdateLockScreen(); | 149 UpdateLockScreen(); |
| 150 } | 150 } |
| 151 | 151 |
| 152 void UnlockManagerImpl::OnLifeCycleStateChanged() { | 152 void UnlockManagerImpl::OnLifeCycleStateChanged() { |
| 153 RemoteDeviceLifeCycle::State state = life_cycle_->GetState(); | 153 RemoteDeviceLifeCycle::State state = life_cycle_->GetState(); |
| 154 PA_LOG(INFO) << "[Unlock] RemoteDeviceLifeCycle state changed: " | 154 PA_LOG(INFO) << "RemoteDeviceLifeCycle state changed: " |
| 155 << static_cast<int>(state); | 155 << static_cast<int>(state); |
| 156 | 156 |
| 157 remote_screenlock_state_.reset(); | 157 remote_screenlock_state_.reset(); |
| 158 if (state == RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED) { | 158 if (state == RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED) { |
| 159 DCHECK(life_cycle_->GetConnection()); | 159 DCHECK(life_cycle_->GetConnection()); |
| 160 DCHECK(GetMessenger()); | 160 DCHECK(GetMessenger()); |
| 161 proximity_monitor_ = CreateProximityMonitor(life_cycle_->GetConnection()); | 161 proximity_monitor_ = CreateProximityMonitor(life_cycle_->GetConnection()); |
| 162 GetMessenger()->AddObserver(this); | 162 GetMessenger()->AddObserver(this); |
| 163 } | 163 } |
| 164 | 164 |
| 165 if (state == RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED) | 165 if (state == RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED) |
| 166 SetWakingUpState(false); | 166 SetWakingUpState(false); |
| 167 | 167 |
| 168 UpdateLockScreen(); | 168 UpdateLockScreen(); |
| 169 } | 169 } |
| 170 | 170 |
| 171 void UnlockManagerImpl::OnUnlockEventSent(bool success) { | 171 void UnlockManagerImpl::OnUnlockEventSent(bool success) { |
| 172 if (!is_attempting_auth_) { | 172 if (!is_attempting_auth_) { |
| 173 PA_LOG(ERROR) << "[Unlock] Sent easy_unlock event, but no auth attempted."; | 173 PA_LOG(ERROR) << "Sent easy_unlock event, but no auth attempted."; |
| 174 return; | 174 return; |
| 175 } | 175 } |
| 176 | 176 |
| 177 AcceptAuthAttempt(success); | 177 AcceptAuthAttempt(success); |
| 178 } | 178 } |
| 179 | 179 |
| 180 void UnlockManagerImpl::OnRemoteStatusUpdate( | 180 void UnlockManagerImpl::OnRemoteStatusUpdate( |
| 181 const RemoteStatusUpdate& status_update) { | 181 const RemoteStatusUpdate& status_update) { |
| 182 PA_LOG(INFO) << "[Unlock] Status Update: (" | 182 PA_LOG(INFO) << "Status Update: (" |
| 183 << "user_present=" << status_update.user_presence << ", " | 183 << "user_present=" << status_update.user_presence << ", " |
| 184 << "secure_screen_lock=" | 184 << "secure_screen_lock=" |
| 185 << status_update.secure_screen_lock_state << ", " | 185 << status_update.secure_screen_lock_state << ", " |
| 186 << "trust_agent=" << status_update.trust_agent_state << ")"; | 186 << "trust_agent=" << status_update.trust_agent_state << ")"; |
| 187 metrics::RecordRemoteSecuritySettingsState( | 187 metrics::RecordRemoteSecuritySettingsState( |
| 188 GetRemoteSecuritySettingsState(status_update)); | 188 GetRemoteSecuritySettingsState(status_update)); |
| 189 | 189 |
| 190 remote_screenlock_state_.reset(new RemoteScreenlockState( | 190 remote_screenlock_state_.reset(new RemoteScreenlockState( |
| 191 GetScreenlockStateFromRemoteUpdate(status_update))); | 191 GetScreenlockStateFromRemoteUpdate(status_update))); |
| 192 | 192 |
| 193 // This also calls |UpdateLockScreen()| | 193 // This also calls |UpdateLockScreen()| |
| 194 SetWakingUpState(false); | 194 SetWakingUpState(false); |
| 195 } | 195 } |
| 196 | 196 |
| 197 void UnlockManagerImpl::OnDecryptResponse(const std::string& decrypted_bytes) { | 197 void UnlockManagerImpl::OnDecryptResponse(const std::string& decrypted_bytes) { |
| 198 if (!is_attempting_auth_) { | 198 if (!is_attempting_auth_) { |
| 199 PA_LOG(ERROR) << "[Unlock] Decrypt response received but not attempting " | 199 PA_LOG(ERROR) << "Decrypt response received but not attempting " |
| 200 << "auth."; | 200 << "auth."; |
| 201 return; | 201 return; |
| 202 } | 202 } |
| 203 | 203 |
| 204 if (decrypted_bytes.empty()) { | 204 if (decrypted_bytes.empty()) { |
| 205 PA_LOG(WARNING) << "[Unlock] Failed to decrypt sign-in challenge."; | 205 PA_LOG(WARNING) << "Failed to decrypt sign-in challenge."; |
| 206 AcceptAuthAttempt(false); | 206 AcceptAuthAttempt(false); |
| 207 } else { | 207 } else { |
| 208 sign_in_secret_.reset(new std::string(decrypted_bytes)); | 208 sign_in_secret_.reset(new std::string(decrypted_bytes)); |
| 209 GetMessenger()->DispatchUnlockEvent(); | 209 GetMessenger()->DispatchUnlockEvent(); |
| 210 } | 210 } |
| 211 } | 211 } |
| 212 | 212 |
| 213 void UnlockManagerImpl::OnUnlockResponse(bool success) { | 213 void UnlockManagerImpl::OnUnlockResponse(bool success) { |
| 214 if (!is_attempting_auth_) { | 214 if (!is_attempting_auth_) { |
| 215 PA_LOG(ERROR) << "[Unlock] Unlock response received but not attempting " | 215 PA_LOG(ERROR) << "Unlock response received but not attempting " |
| 216 << "auth."; | 216 << "auth."; |
| 217 return; | 217 return; |
| 218 } | 218 } |
| 219 | 219 |
| 220 PA_LOG(INFO) << "[Unlock] Unlock response from remote device: " | 220 PA_LOG(INFO) << "Unlock response from remote device: " |
| 221 << (success ? "success" : "failure"); | 221 << (success ? "success" : "failure"); |
| 222 if (success) | 222 if (success) |
| 223 GetMessenger()->DispatchUnlockEvent(); | 223 GetMessenger()->DispatchUnlockEvent(); |
| 224 else | 224 else |
| 225 AcceptAuthAttempt(false); | 225 AcceptAuthAttempt(false); |
| 226 } | 226 } |
| 227 | 227 |
| 228 void UnlockManagerImpl::OnDisconnected() { | 228 void UnlockManagerImpl::OnDisconnected() { |
| 229 GetMessenger()->RemoveObserver(this); | 229 GetMessenger()->RemoveObserver(this); |
| 230 } | 230 } |
| 231 | 231 |
| 232 void UnlockManagerImpl::OnProximityStateChanged() { |
| 233 PA_LOG(INFO) << "Proximity state changed."; |
| 234 UpdateLockScreen(); |
| 235 } |
| 236 |
| 232 void UnlockManagerImpl::OnScreenDidLock( | 237 void UnlockManagerImpl::OnScreenDidLock( |
| 233 ScreenlockBridge::LockHandler::ScreenType screen_type) { | 238 ScreenlockBridge::LockHandler::ScreenType screen_type) { |
| 234 OnScreenLockedOrUnlocked(true); | 239 OnScreenLockedOrUnlocked(true); |
| 235 } | 240 } |
| 236 | 241 |
| 237 void UnlockManagerImpl::OnScreenDidUnlock( | 242 void UnlockManagerImpl::OnScreenDidUnlock( |
| 238 ScreenlockBridge::LockHandler::ScreenType screen_type) { | 243 ScreenlockBridge::LockHandler::ScreenType screen_type) { |
| 239 OnScreenLockedOrUnlocked(false); | 244 OnScreenLockedOrUnlocked(false); |
| 240 } | 245 } |
| 241 | 246 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 | 279 |
| 275 #if defined(OS_CHROMEOS) | 280 #if defined(OS_CHROMEOS) |
| 276 void UnlockManagerImpl::SuspendDone(const base::TimeDelta& sleep_duration) { | 281 void UnlockManagerImpl::SuspendDone(const base::TimeDelta& sleep_duration) { |
| 277 SetWakingUpState(true); | 282 SetWakingUpState(true); |
| 278 } | 283 } |
| 279 #endif // defined(OS_CHROMEOS) | 284 #endif // defined(OS_CHROMEOS) |
| 280 | 285 |
| 281 void UnlockManagerImpl::OnAuthAttempted( | 286 void UnlockManagerImpl::OnAuthAttempted( |
| 282 ScreenlockBridge::LockHandler::AuthType auth_type) { | 287 ScreenlockBridge::LockHandler::AuthType auth_type) { |
| 283 if (is_attempting_auth_) { | 288 if (is_attempting_auth_) { |
| 284 PA_LOG(INFO) << "[Unlock] Already attempting auth."; | 289 PA_LOG(INFO) << "Already attempting auth."; |
| 285 return; | 290 return; |
| 286 } | 291 } |
| 287 | 292 |
| 288 if (auth_type != ScreenlockBridge::LockHandler::USER_CLICK) | 293 if (auth_type != ScreenlockBridge::LockHandler::USER_CLICK) |
| 289 return; | 294 return; |
| 290 | 295 |
| 291 is_attempting_auth_ = true; | 296 is_attempting_auth_ = true; |
| 292 | 297 |
| 293 if (!life_cycle_) { | 298 if (!life_cycle_) { |
| 294 PA_LOG(ERROR) << "[Unlock] No life_cycle active when auth is attempted"; | 299 PA_LOG(ERROR) << "No life_cycle active when auth is attempted"; |
| 295 AcceptAuthAttempt(false); | 300 AcceptAuthAttempt(false); |
| 296 UpdateLockScreen(); | 301 UpdateLockScreen(); |
| 297 return; | 302 return; |
| 298 } | 303 } |
| 299 | 304 |
| 300 if (!IsUnlockAllowed()) { | 305 if (!IsUnlockAllowed()) { |
| 301 AcceptAuthAttempt(false); | 306 AcceptAuthAttempt(false); |
| 302 UpdateLockScreen(); | 307 UpdateLockScreen(); |
| 303 return; | 308 return; |
| 304 } | 309 } |
| 305 | 310 |
| 306 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 311 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 307 FROM_HERE, | 312 FROM_HERE, |
| 308 base::Bind(&UnlockManagerImpl::AcceptAuthAttempt, | 313 base::Bind(&UnlockManagerImpl::AcceptAuthAttempt, |
| 309 reject_auth_attempt_weak_ptr_factory_.GetWeakPtr(), false), | 314 reject_auth_attempt_weak_ptr_factory_.GetWeakPtr(), false), |
| 310 base::TimeDelta::FromSeconds(kAuthAttemptTimeoutSecs)); | 315 base::TimeDelta::FromSeconds(kAuthAttemptTimeoutSecs)); |
| 311 | 316 |
| 312 if (screenlock_type_ == ProximityAuthSystem::SIGN_IN) { | 317 if (screenlock_type_ == ProximityAuthSystem::SIGN_IN) { |
| 313 SendSignInChallenge(); | 318 SendSignInChallenge(); |
| 314 } else { | 319 } else { |
| 315 if (GetMessenger()->SupportsSignIn()) { | 320 if (GetMessenger()->SupportsSignIn()) { |
| 316 GetMessenger()->RequestUnlock(); | 321 GetMessenger()->RequestUnlock(); |
| 317 } else { | 322 } else { |
| 318 PA_LOG(INFO) << "[Unlock] Protocol v3.1 not supported, skipping " | 323 PA_LOG(INFO) << "Protocol v3.1 not supported, skipping request_unlock."; |
| 319 << "request_unlock."; | |
| 320 GetMessenger()->DispatchUnlockEvent(); | 324 GetMessenger()->DispatchUnlockEvent(); |
| 321 } | 325 } |
| 322 } | 326 } |
| 323 } | 327 } |
| 324 | 328 |
| 325 std::unique_ptr<ProximityMonitor> UnlockManagerImpl::CreateProximityMonitor( | 329 std::unique_ptr<ProximityMonitor> UnlockManagerImpl::CreateProximityMonitor( |
| 326 cryptauth::Connection* connection) { | 330 cryptauth::Connection* connection) { |
| 327 return base::MakeUnique<ProximityMonitorImpl>( | 331 return base::MakeUnique<ProximityMonitorImpl>( |
| 328 connection, base::WrapUnique(new base::DefaultTickClock())); | 332 connection, base::WrapUnique(new base::DefaultTickClock())); |
| 329 } | 333 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 return ScreenlockState::NO_BLUETOOTH; | 373 return ScreenlockState::NO_BLUETOOTH; |
| 370 | 374 |
| 371 Messenger* messenger = GetMessenger(); | 375 Messenger* messenger = GetMessenger(); |
| 372 if (screenlock_type_ == ProximityAuthSystem::SIGN_IN && messenger && | 376 if (screenlock_type_ == ProximityAuthSystem::SIGN_IN && messenger && |
| 373 !messenger->SupportsSignIn()) | 377 !messenger->SupportsSignIn()) |
| 374 return ScreenlockState::PHONE_UNSUPPORTED; | 378 return ScreenlockState::PHONE_UNSUPPORTED; |
| 375 | 379 |
| 376 // If the RSSI is too low, then the remote device is nowhere near the local | 380 // If the RSSI is too low, then the remote device is nowhere near the local |
| 377 // device. This message should take priority over messages about screen lock | 381 // device. This message should take priority over messages about screen lock |
| 378 // states. | 382 // states. |
| 379 if (!proximity_monitor_->IsUnlockAllowed()) | 383 if (!proximity_monitor_->IsUnlockAllowed()) { |
| 380 return ScreenlockState::RSSI_TOO_LOW; | 384 if (remote_screenlock_state_ && |
| 385 *remote_screenlock_state_ == RemoteScreenlockState::UNLOCKED) { |
| 386 return ScreenlockState::RSSI_TOO_LOW; |
| 387 } else { |
| 388 return ScreenlockState::PHONE_LOCKED_AND_RSSI_TOO_LOW; |
| 389 } |
| 390 } |
| 381 | 391 |
| 382 if (remote_screenlock_state_) { | 392 if (remote_screenlock_state_) { |
| 383 switch (*remote_screenlock_state_) { | 393 switch (*remote_screenlock_state_) { |
| 384 case RemoteScreenlockState::DISABLED: | 394 case RemoteScreenlockState::DISABLED: |
| 385 return ScreenlockState::PHONE_NOT_LOCKABLE; | 395 return ScreenlockState::PHONE_NOT_LOCKABLE; |
| 386 | 396 |
| 387 case RemoteScreenlockState::LOCKED: | 397 case RemoteScreenlockState::LOCKED: |
| 388 return ScreenlockState::PHONE_LOCKED; | 398 return ScreenlockState::PHONE_LOCKED; |
| 389 | 399 |
| 390 case RemoteScreenlockState::UNKNOWN: | 400 case RemoteScreenlockState::UNKNOWN: |
| 391 return ScreenlockState::PHONE_UNSUPPORTED; | 401 return ScreenlockState::PHONE_UNSUPPORTED; |
| 392 | 402 |
| 393 case RemoteScreenlockState::UNLOCKED: | 403 case RemoteScreenlockState::UNLOCKED: |
| 394 // Handled by the code below. | 404 // Handled by the code below. |
| 395 break; | 405 break; |
| 396 } | 406 } |
| 397 } | 407 } |
| 398 | 408 |
| 399 return ScreenlockState::NO_PHONE; | 409 return ScreenlockState::NO_PHONE; |
| 400 } | 410 } |
| 401 | 411 |
| 402 void UnlockManagerImpl::UpdateLockScreen() { | 412 void UnlockManagerImpl::UpdateLockScreen() { |
| 403 UpdateProximityMonitorState(); | 413 UpdateProximityMonitorState(); |
| 404 | 414 |
| 405 ScreenlockState new_state = GetScreenlockState(); | 415 ScreenlockState new_state = GetScreenlockState(); |
| 406 if (screenlock_state_ == new_state) | 416 if (screenlock_state_ == new_state) |
| 407 return; | 417 return; |
| 408 | 418 |
| 419 PA_LOG(INFO) << "Updating screenlock state from " |
| 420 << static_cast<int>(screenlock_state_) << " to " |
| 421 << static_cast<int>(new_state); |
| 409 proximity_auth_client_->UpdateScreenlockState(new_state); | 422 proximity_auth_client_->UpdateScreenlockState(new_state); |
| 410 screenlock_state_ = new_state; | 423 screenlock_state_ = new_state; |
| 411 } | 424 } |
| 412 | 425 |
| 413 void UnlockManagerImpl::UpdateProximityMonitorState() { | 426 void UnlockManagerImpl::UpdateProximityMonitorState() { |
| 414 if (!proximity_monitor_) | 427 if (!proximity_monitor_) |
| 415 return; | 428 return; |
| 416 | 429 |
| 417 if (is_locked_ && life_cycle_ && | 430 if (is_locked_ && life_cycle_ && |
| 418 life_cycle_->GetState() == | 431 life_cycle_->GetState() == |
| 419 RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED) { | 432 RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED) { |
| 433 proximity_monitor_->AddObserver(this); |
| 420 proximity_monitor_->Start(); | 434 proximity_monitor_->Start(); |
| 421 } else { | 435 } else { |
| 422 proximity_monitor_->Stop(); | 436 proximity_monitor_->Stop(); |
| 423 } | 437 } |
| 424 } | 438 } |
| 425 | 439 |
| 426 void UnlockManagerImpl::SetWakingUpState(bool is_waking_up) { | 440 void UnlockManagerImpl::SetWakingUpState(bool is_waking_up) { |
| 427 is_waking_up_ = is_waking_up; | 441 is_waking_up_ = is_waking_up; |
| 428 | 442 |
| 429 // Clear the waking up state after a timeout. | 443 // Clear the waking up state after a timeout. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 | 497 |
| 484 Messenger* UnlockManagerImpl::GetMessenger() { | 498 Messenger* UnlockManagerImpl::GetMessenger() { |
| 485 // TODO(tengs): We should use a weak pointer to hold the Messenger instance | 499 // TODO(tengs): We should use a weak pointer to hold the Messenger instance |
| 486 // instead. | 500 // instead. |
| 487 if (!life_cycle_) | 501 if (!life_cycle_) |
| 488 return nullptr; | 502 return nullptr; |
| 489 return life_cycle_->GetMessenger(); | 503 return life_cycle_->GetMessenger(); |
| 490 } | 504 } |
| 491 | 505 |
| 492 } // namespace proximity_auth | 506 } // namespace proximity_auth |
| OLD | NEW |