| 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 (GetMessenger() && GetMessenger()->SupportsSignIn()))); | 134 (GetMessenger() && GetMessenger()->SupportsSignIn()))); |
| 135 } | 135 } |
| 136 | 136 |
| 137 void UnlockManagerImpl::SetRemoteDeviceLifeCycle( | 137 void UnlockManagerImpl::SetRemoteDeviceLifeCycle( |
| 138 RemoteDeviceLifeCycle* life_cycle) { | 138 RemoteDeviceLifeCycle* life_cycle) { |
| 139 if (GetMessenger()) | 139 if (GetMessenger()) |
| 140 GetMessenger()->RemoveObserver(this); | 140 GetMessenger()->RemoveObserver(this); |
| 141 | 141 |
| 142 life_cycle_ = life_cycle; | 142 life_cycle_ = life_cycle; |
| 143 if (life_cycle_) { | 143 if (life_cycle_) { |
| 144 proximity_monitor_ = CreateProximityMonitor(life_cycle->GetRemoteDevice()); | |
| 145 SetWakingUpState(true); | 144 SetWakingUpState(true); |
| 146 } else { | 145 } else { |
| 147 proximity_monitor_.reset(); | 146 proximity_monitor_.reset(); |
| 148 } | 147 } |
| 149 | 148 |
| 150 UpdateLockScreen(); | 149 UpdateLockScreen(); |
| 151 } | 150 } |
| 152 | 151 |
| 153 void UnlockManagerImpl::OnLifeCycleStateChanged() { | 152 void UnlockManagerImpl::OnLifeCycleStateChanged() { |
| 154 RemoteDeviceLifeCycle::State state = life_cycle_->GetState(); | 153 RemoteDeviceLifeCycle::State state = life_cycle_->GetState(); |
| 155 PA_LOG(INFO) << "[Unlock] RemoteDeviceLifeCycle state changed: " | 154 PA_LOG(INFO) << "[Unlock] RemoteDeviceLifeCycle state changed: " |
| 156 << static_cast<int>(state); | 155 << static_cast<int>(state); |
| 157 | 156 |
| 158 remote_screenlock_state_.reset(); | 157 remote_screenlock_state_.reset(); |
| 159 if (state == RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED) | 158 if (state == RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED) { |
| 159 DCHECK(life_cycle_->GetConnection()); |
| 160 DCHECK(GetMessenger()); |
| 161 proximity_monitor_ = CreateProximityMonitor(life_cycle_->GetConnection()); |
| 160 GetMessenger()->AddObserver(this); | 162 GetMessenger()->AddObserver(this); |
| 163 } |
| 161 | 164 |
| 162 if (state == RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED) | 165 if (state == RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED) |
| 163 SetWakingUpState(false); | 166 SetWakingUpState(false); |
| 164 | 167 |
| 165 UpdateLockScreen(); | 168 UpdateLockScreen(); |
| 166 } | 169 } |
| 167 | 170 |
| 168 void UnlockManagerImpl::OnUnlockEventSent(bool success) { | 171 void UnlockManagerImpl::OnUnlockEventSent(bool success) { |
| 169 if (!is_attempting_auth_) { | 172 if (!is_attempting_auth_) { |
| 170 PA_LOG(ERROR) << "[Unlock] Sent easy_unlock event, but no auth attempted."; | 173 PA_LOG(ERROR) << "[Unlock] Sent easy_unlock event, but no auth attempted."; |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 GetMessenger()->RequestUnlock(); | 316 GetMessenger()->RequestUnlock(); |
| 314 } else { | 317 } else { |
| 315 PA_LOG(INFO) << "[Unlock] Protocol v3.1 not supported, skipping " | 318 PA_LOG(INFO) << "[Unlock] Protocol v3.1 not supported, skipping " |
| 316 << "request_unlock."; | 319 << "request_unlock."; |
| 317 GetMessenger()->DispatchUnlockEvent(); | 320 GetMessenger()->DispatchUnlockEvent(); |
| 318 } | 321 } |
| 319 } | 322 } |
| 320 } | 323 } |
| 321 | 324 |
| 322 std::unique_ptr<ProximityMonitor> UnlockManagerImpl::CreateProximityMonitor( | 325 std::unique_ptr<ProximityMonitor> UnlockManagerImpl::CreateProximityMonitor( |
| 323 const cryptauth::RemoteDevice& remote_device) { | 326 cryptauth::Connection* connection) { |
| 324 return base::MakeUnique<ProximityMonitorImpl>( | 327 return base::MakeUnique<ProximityMonitorImpl>( |
| 325 remote_device, base::WrapUnique(new base::DefaultTickClock())); | 328 connection, base::WrapUnique(new base::DefaultTickClock())); |
| 326 } | 329 } |
| 327 | 330 |
| 328 void UnlockManagerImpl::SendSignInChallenge() { | 331 void UnlockManagerImpl::SendSignInChallenge() { |
| 329 if (!life_cycle_ || !GetMessenger() || !GetMessenger()->GetSecureContext()) { | 332 if (!life_cycle_ || !GetMessenger() || !GetMessenger()->GetSecureContext()) { |
| 330 PA_LOG(ERROR) << "Not ready to send sign-in challenge"; | 333 PA_LOG(ERROR) << "Not ready to send sign-in challenge"; |
| 331 return; | 334 return; |
| 332 } | 335 } |
| 333 | 336 |
| 334 cryptauth::RemoteDevice remote_device = life_cycle_->GetRemoteDevice(); | 337 cryptauth::RemoteDevice remote_device = life_cycle_->GetRemoteDevice(); |
| 335 proximity_auth_client_->GetChallengeForUserAndDevice( | 338 proximity_auth_client_->GetChallengeForUserAndDevice( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 349 life_cycle_->GetState() == RemoteDeviceLifeCycle::State::STOPPED) | 352 life_cycle_->GetState() == RemoteDeviceLifeCycle::State::STOPPED) |
| 350 return ScreenlockState::INACTIVE; | 353 return ScreenlockState::INACTIVE; |
| 351 | 354 |
| 352 if (IsUnlockAllowed()) | 355 if (IsUnlockAllowed()) |
| 353 return ScreenlockState::AUTHENTICATED; | 356 return ScreenlockState::AUTHENTICATED; |
| 354 | 357 |
| 355 if (life_cycle_->GetState() == | 358 if (life_cycle_->GetState() == |
| 356 RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED) | 359 RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED) |
| 357 return ScreenlockState::PHONE_NOT_AUTHENTICATED; | 360 return ScreenlockState::PHONE_NOT_AUTHENTICATED; |
| 358 | 361 |
| 359 if (is_waking_up_) | 362 if (is_waking_up_ || |
| 363 life_cycle_->GetState() == RemoteDeviceLifeCycle::State::AUTHENTICATING || |
| 364 life_cycle_->GetState() == |
| 365 RemoteDeviceLifeCycle::State::FINDING_CONNECTION) |
| 360 return ScreenlockState::BLUETOOTH_CONNECTING; | 366 return ScreenlockState::BLUETOOTH_CONNECTING; |
| 361 | 367 |
| 362 if (!bluetooth_adapter_ || !bluetooth_adapter_->IsPowered()) | 368 if (!bluetooth_adapter_ || !bluetooth_adapter_->IsPowered()) |
| 363 return ScreenlockState::NO_BLUETOOTH; | 369 return ScreenlockState::NO_BLUETOOTH; |
| 364 | 370 |
| 365 Messenger* messenger = GetMessenger(); | 371 Messenger* messenger = GetMessenger(); |
| 366 if (screenlock_type_ == ProximityAuthSystem::SIGN_IN && messenger && | 372 if (screenlock_type_ == ProximityAuthSystem::SIGN_IN && messenger && |
| 367 !messenger->SupportsSignIn()) | 373 !messenger->SupportsSignIn()) |
| 368 return ScreenlockState::PHONE_UNSUPPORTED; | 374 return ScreenlockState::PHONE_UNSUPPORTED; |
| 369 | 375 |
| 370 // If the RSSI is too low, then the remote device is nowhere near the local | 376 // If the RSSI is too low, then the remote device is nowhere near the local |
| 371 // device. This message should take priority over messages about screen lock | 377 // device. This message should take priority over messages about screen lock |
| 372 // states. | 378 // states. |
| 373 if (!proximity_monitor_->IsUnlockAllowed() && | 379 if (!proximity_monitor_->IsUnlockAllowed()) |
| 374 !proximity_monitor_->IsInRssiRange()) | |
| 375 return ScreenlockState::RSSI_TOO_LOW; | 380 return ScreenlockState::RSSI_TOO_LOW; |
| 376 | 381 |
| 377 if (remote_screenlock_state_) { | 382 if (remote_screenlock_state_) { |
| 378 switch (*remote_screenlock_state_) { | 383 switch (*remote_screenlock_state_) { |
| 379 case RemoteScreenlockState::DISABLED: | 384 case RemoteScreenlockState::DISABLED: |
| 380 return ScreenlockState::PHONE_NOT_LOCKABLE; | 385 return ScreenlockState::PHONE_NOT_LOCKABLE; |
| 381 | 386 |
| 382 case RemoteScreenlockState::LOCKED: | 387 case RemoteScreenlockState::LOCKED: |
| 383 if (proximity_monitor_->GetStrategy() == | |
| 384 ProximityMonitor::Strategy::CHECK_TRANSMIT_POWER && | |
| 385 !proximity_monitor_->IsUnlockAllowed()) { | |
| 386 return ScreenlockState::PHONE_LOCKED_AND_TX_POWER_TOO_HIGH; | |
| 387 } | |
| 388 return ScreenlockState::PHONE_LOCKED; | 388 return ScreenlockState::PHONE_LOCKED; |
| 389 | 389 |
| 390 case RemoteScreenlockState::UNKNOWN: | 390 case RemoteScreenlockState::UNKNOWN: |
| 391 return ScreenlockState::PHONE_UNSUPPORTED; | 391 return ScreenlockState::PHONE_UNSUPPORTED; |
| 392 | 392 |
| 393 case RemoteScreenlockState::UNLOCKED: | 393 case RemoteScreenlockState::UNLOCKED: |
| 394 // Handled by the code below. | 394 // Handled by the code below. |
| 395 break; | 395 break; |
| 396 } | 396 } |
| 397 } | 397 } |
| 398 | 398 |
| 399 if (!proximity_monitor_->IsUnlockAllowed()) { | |
| 400 ProximityMonitor::Strategy strategy = proximity_monitor_->GetStrategy(); | |
| 401 if (strategy != ProximityMonitor::Strategy::CHECK_TRANSMIT_POWER) { | |
| 402 // CHECK_RSSI should have been handled above, and no other states should | |
| 403 // prevent unlocking. | |
| 404 PA_LOG(ERROR) << "[Unlock] Invalid ProximityMonitor strategy: " | |
| 405 << static_cast<int>(strategy); | |
| 406 return ScreenlockState::NO_PHONE; | |
| 407 } | |
| 408 return ScreenlockState::TX_POWER_TOO_HIGH; | |
| 409 } | |
| 410 | |
| 411 return ScreenlockState::NO_PHONE; | 399 return ScreenlockState::NO_PHONE; |
| 412 } | 400 } |
| 413 | 401 |
| 414 void UnlockManagerImpl::UpdateLockScreen() { | 402 void UnlockManagerImpl::UpdateLockScreen() { |
| 415 UpdateProximityMonitorState(); | 403 UpdateProximityMonitorState(); |
| 416 | 404 |
| 417 ScreenlockState new_state = GetScreenlockState(); | 405 ScreenlockState new_state = GetScreenlockState(); |
| 418 if (screenlock_state_ == new_state) | 406 if (screenlock_state_ == new_state) |
| 419 return; | 407 return; |
| 420 | 408 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 | 483 |
| 496 Messenger* UnlockManagerImpl::GetMessenger() { | 484 Messenger* UnlockManagerImpl::GetMessenger() { |
| 497 // TODO(tengs): We should use a weak pointer to hold the Messenger instance | 485 // TODO(tengs): We should use a weak pointer to hold the Messenger instance |
| 498 // instead. | 486 // instead. |
| 499 if (!life_cycle_) | 487 if (!life_cycle_) |
| 500 return nullptr; | 488 return nullptr; |
| 501 return life_cycle_->GetMessenger(); | 489 return life_cycle_->GetMessenger(); |
| 502 } | 490 } |
| 503 | 491 |
| 504 } // namespace proximity_auth | 492 } // namespace proximity_auth |
| OLD | NEW |