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.h" | 5 #include "components/proximity_auth/unlock_manager.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/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 return metrics::RemoteSecuritySettingsState::UNKNOWN; | 73 return metrics::RemoteSecuritySettingsState::UNKNOWN; |
74 } | 74 } |
75 | 75 |
76 } // namespace | 76 } // namespace |
77 | 77 |
78 UnlockManager::UnlockManager(ScreenlockType screenlock_type, | 78 UnlockManager::UnlockManager(ScreenlockType screenlock_type, |
79 scoped_ptr<ProximityMonitor> proximity_monitor, | 79 scoped_ptr<ProximityMonitor> proximity_monitor, |
80 ProximityAuthClient* proximity_auth_client) | 80 ProximityAuthClient* proximity_auth_client) |
81 : screenlock_type_(screenlock_type), | 81 : screenlock_type_(screenlock_type), |
82 life_cycle_(nullptr), | 82 life_cycle_(nullptr), |
83 messenger_(nullptr), | |
84 proximity_monitor_(proximity_monitor.Pass()), | 83 proximity_monitor_(proximity_monitor.Pass()), |
85 proximity_auth_client_(proximity_auth_client), | 84 proximity_auth_client_(proximity_auth_client), |
86 is_locked_(false), | 85 is_locked_(false), |
87 is_attempting_auth_(false), | 86 is_attempting_auth_(false), |
88 is_waking_up_(false), | 87 is_waking_up_(false), |
89 screenlock_state_(ScreenlockState::INACTIVE), | 88 screenlock_state_(ScreenlockState::INACTIVE), |
90 clear_waking_up_state_weak_ptr_factory_(this), | 89 clear_waking_up_state_weak_ptr_factory_(this), |
91 reject_auth_attempt_weak_ptr_factory_(this), | 90 reject_auth_attempt_weak_ptr_factory_(this), |
92 weak_ptr_factory_(this) { | 91 weak_ptr_factory_(this) { |
93 // TODO(isherman): Register for auth attempt notifications, equivalent to the | 92 // TODO(isherman): Register for auth attempt notifications, equivalent to the |
(...skipping 12 matching lines...) Expand all Loading... |
106 SetWakingUpState(true); | 105 SetWakingUpState(true); |
107 | 106 |
108 if (device::BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) { | 107 if (device::BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) { |
109 device::BluetoothAdapterFactory::GetAdapter( | 108 device::BluetoothAdapterFactory::GetAdapter( |
110 base::Bind(&UnlockManager::OnBluetoothAdapterInitialized, | 109 base::Bind(&UnlockManager::OnBluetoothAdapterInitialized, |
111 weak_ptr_factory_.GetWeakPtr())); | 110 weak_ptr_factory_.GetWeakPtr())); |
112 } | 111 } |
113 } | 112 } |
114 | 113 |
115 UnlockManager::~UnlockManager() { | 114 UnlockManager::~UnlockManager() { |
116 if (messenger_) | 115 if (GetMessenger()) |
117 messenger_->RemoveObserver(this); | 116 GetMessenger()->RemoveObserver(this); |
118 | 117 |
119 ScreenlockBridge::Get()->RemoveObserver(this); | 118 ScreenlockBridge::Get()->RemoveObserver(this); |
120 | 119 |
121 #if defined(OS_CHROMEOS) | 120 #if defined(OS_CHROMEOS) |
122 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); | 121 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); |
123 #endif // defined(OS_CHROMEOS) | 122 #endif // defined(OS_CHROMEOS) |
124 | 123 |
125 if (bluetooth_adapter_) | 124 if (bluetooth_adapter_) |
126 bluetooth_adapter_->RemoveObserver(this); | 125 bluetooth_adapter_->RemoveObserver(this); |
127 } | 126 } |
128 | 127 |
129 bool UnlockManager::IsUnlockAllowed() { | 128 bool UnlockManager::IsUnlockAllowed() { |
130 return (remote_screenlock_state_ && | 129 return (remote_screenlock_state_ && |
131 *remote_screenlock_state_ == RemoteScreenlockState::UNLOCKED && | 130 *remote_screenlock_state_ == RemoteScreenlockState::UNLOCKED && |
132 life_cycle_ && | 131 life_cycle_ && |
133 life_cycle_->GetState() == | 132 life_cycle_->GetState() == |
134 RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED && | 133 RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED && |
135 proximity_monitor_->IsUnlockAllowed() && | 134 proximity_monitor_->IsUnlockAllowed() && |
136 (screenlock_type_ != ScreenlockType::SIGN_IN || | 135 (screenlock_type_ != ScreenlockType::SIGN_IN || |
137 (messenger_ && messenger_->SupportsSignIn()))); | 136 (GetMessenger() && GetMessenger()->SupportsSignIn()))); |
138 } | 137 } |
139 | 138 |
140 void UnlockManager::SetRemoteDeviceLifeCycle( | 139 void UnlockManager::SetRemoteDeviceLifeCycle( |
141 RemoteDeviceLifeCycle* life_cycle) { | 140 RemoteDeviceLifeCycle* life_cycle) { |
142 if (messenger_) { | 141 if (GetMessenger()) |
143 messenger_->RemoveObserver(this); | 142 GetMessenger()->RemoveObserver(this); |
144 messenger_ = nullptr; | |
145 } | |
146 | 143 |
147 life_cycle_ = life_cycle; | 144 life_cycle_ = life_cycle; |
148 if (life_cycle_) | 145 if (life_cycle_) |
149 SetWakingUpState(true); | 146 SetWakingUpState(true); |
150 | 147 |
151 UpdateLockScreen(); | 148 UpdateLockScreen(); |
152 } | 149 } |
153 | 150 |
154 void UnlockManager::OnLifeCycleStateChanged() { | 151 void UnlockManager::OnLifeCycleStateChanged() { |
155 RemoteDeviceLifeCycle::State state = life_cycle_->GetState(); | 152 RemoteDeviceLifeCycle::State state = life_cycle_->GetState(); |
156 PA_LOG(INFO) << "[Unlock] RemoteDeviceLifeCycle state changed: " | 153 PA_LOG(INFO) << "[Unlock] RemoteDeviceLifeCycle state changed: " |
157 << static_cast<int>(state); | 154 << static_cast<int>(state); |
158 | 155 |
159 remote_screenlock_state_.reset(); | 156 remote_screenlock_state_.reset(); |
160 if (state == RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED) { | 157 if (state == RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED) |
161 messenger_ = life_cycle_->GetMessenger(); | 158 GetMessenger()->AddObserver(this); |
162 messenger_->AddObserver(this); | |
163 } | |
164 | 159 |
165 if (state == RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED) | 160 if (state == RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED) |
166 SetWakingUpState(false); | 161 SetWakingUpState(false); |
167 | 162 |
168 UpdateLockScreen(); | 163 UpdateLockScreen(); |
169 } | 164 } |
170 | 165 |
171 void UnlockManager::OnUnlockEventSent(bool success) { | 166 void UnlockManager::OnUnlockEventSent(bool success) { |
172 if (!is_attempting_auth_) { | 167 if (!is_attempting_auth_) { |
173 PA_LOG(ERROR) << "[Unlock] Sent easy_unlock event, but no auth attempted."; | 168 PA_LOG(ERROR) << "[Unlock] Sent easy_unlock event, but no auth attempted."; |
(...skipping 28 matching lines...) Expand all Loading... |
202 PA_LOG(ERROR) << "[Unlock] Decrypt response received but not attempting " | 197 PA_LOG(ERROR) << "[Unlock] Decrypt response received but not attempting " |
203 << "auth."; | 198 << "auth."; |
204 return; | 199 return; |
205 } | 200 } |
206 | 201 |
207 if (!decrypted_bytes) { | 202 if (!decrypted_bytes) { |
208 PA_LOG(INFO) << "[Unlock] Failed to decrypt sign-in challenge."; | 203 PA_LOG(INFO) << "[Unlock] Failed to decrypt sign-in challenge."; |
209 AcceptAuthAttempt(false); | 204 AcceptAuthAttempt(false); |
210 } else { | 205 } else { |
211 sign_in_secret_ = decrypted_bytes.Pass(); | 206 sign_in_secret_ = decrypted_bytes.Pass(); |
212 messenger_->DispatchUnlockEvent(); | 207 GetMessenger()->DispatchUnlockEvent(); |
213 } | 208 } |
214 } | 209 } |
215 | 210 |
216 void UnlockManager::OnUnlockResponse(bool success) { | 211 void UnlockManager::OnUnlockResponse(bool success) { |
217 if (!is_attempting_auth_) { | 212 if (!is_attempting_auth_) { |
218 PA_LOG(ERROR) << "[Unlock] Unlock response received but not attempting " | 213 PA_LOG(ERROR) << "[Unlock] Unlock response received but not attempting " |
219 << "auth."; | 214 << "auth."; |
220 return; | 215 return; |
221 } | 216 } |
222 | 217 |
223 PA_LOG(INFO) << "[Unlock] Unlock response from remote device: " | 218 PA_LOG(INFO) << "[Unlock] Unlock response from remote device: " |
224 << (success ? "success" : "failure"); | 219 << (success ? "success" : "failure"); |
225 if (success) | 220 if (success) |
226 messenger_->DispatchUnlockEvent(); | 221 GetMessenger()->DispatchUnlockEvent(); |
227 else | 222 else |
228 AcceptAuthAttempt(false); | 223 AcceptAuthAttempt(false); |
229 } | 224 } |
230 | 225 |
231 void UnlockManager::OnDisconnected() { | 226 void UnlockManager::OnDisconnected() { |
232 messenger_->RemoveObserver(this); | 227 GetMessenger()->RemoveObserver(this); |
233 messenger_ = nullptr; | |
234 } | 228 } |
235 | 229 |
236 void UnlockManager::OnScreenDidLock( | 230 void UnlockManager::OnScreenDidLock( |
237 ScreenlockBridge::LockHandler::ScreenType screen_type) { | 231 ScreenlockBridge::LockHandler::ScreenType screen_type) { |
238 OnScreenLockedOrUnlocked(true); | 232 OnScreenLockedOrUnlocked(true); |
239 } | 233 } |
240 | 234 |
241 void UnlockManager::OnScreenDidUnlock( | 235 void UnlockManager::OnScreenDidUnlock( |
242 ScreenlockBridge::LockHandler::ScreenType screen_type) { | 236 ScreenlockBridge::LockHandler::ScreenType screen_type) { |
243 OnScreenLockedOrUnlocked(false); | 237 OnScreenLockedOrUnlocked(false); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 | 303 |
310 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 304 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
311 FROM_HERE, | 305 FROM_HERE, |
312 base::Bind(&UnlockManager::AcceptAuthAttempt, | 306 base::Bind(&UnlockManager::AcceptAuthAttempt, |
313 reject_auth_attempt_weak_ptr_factory_.GetWeakPtr(), false), | 307 reject_auth_attempt_weak_ptr_factory_.GetWeakPtr(), false), |
314 base::TimeDelta::FromSeconds(kAuthAttemptTimeoutSecs)); | 308 base::TimeDelta::FromSeconds(kAuthAttemptTimeoutSecs)); |
315 | 309 |
316 if (screenlock_type_ == ScreenlockType::SIGN_IN) { | 310 if (screenlock_type_ == ScreenlockType::SIGN_IN) { |
317 SendSignInChallenge(); | 311 SendSignInChallenge(); |
318 } else { | 312 } else { |
319 if (messenger_->SupportsSignIn()) { | 313 if (GetMessenger()->SupportsSignIn()) { |
320 messenger_->RequestUnlock(); | 314 GetMessenger()->RequestUnlock(); |
321 } else { | 315 } else { |
322 PA_LOG(INFO) << "[Unlock] Protocol v3.1 not supported, skipping " | 316 PA_LOG(INFO) << "[Unlock] Protocol v3.1 not supported, skipping " |
323 << "request_unlock."; | 317 << "request_unlock."; |
324 messenger_->DispatchUnlockEvent(); | 318 GetMessenger()->DispatchUnlockEvent(); |
325 } | 319 } |
326 } | 320 } |
327 } | 321 } |
328 | 322 |
329 void UnlockManager::SendSignInChallenge() { | 323 void UnlockManager::SendSignInChallenge() { |
330 // TODO(isherman): Implement. | 324 // TODO(isherman): Implement. |
331 NOTIMPLEMENTED(); | 325 NOTIMPLEMENTED(); |
332 } | 326 } |
333 | 327 |
334 ScreenlockState UnlockManager::GetScreenlockState() { | 328 ScreenlockState UnlockManager::GetScreenlockState() { |
335 if (!life_cycle_ || | 329 if (!life_cycle_ || |
336 life_cycle_->GetState() == RemoteDeviceLifeCycle::State::STOPPED) | 330 life_cycle_->GetState() == RemoteDeviceLifeCycle::State::STOPPED) |
337 return ScreenlockState::INACTIVE; | 331 return ScreenlockState::INACTIVE; |
338 | 332 |
339 if (IsUnlockAllowed()) | 333 if (IsUnlockAllowed()) |
340 return ScreenlockState::AUTHENTICATED; | 334 return ScreenlockState::AUTHENTICATED; |
341 | 335 |
342 if (life_cycle_->GetState() == | 336 if (life_cycle_->GetState() == |
343 RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED) | 337 RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED) |
344 return ScreenlockState::PHONE_NOT_AUTHENTICATED; | 338 return ScreenlockState::PHONE_NOT_AUTHENTICATED; |
345 | 339 |
346 if (is_waking_up_) | 340 if (is_waking_up_) |
347 return ScreenlockState::BLUETOOTH_CONNECTING; | 341 return ScreenlockState::BLUETOOTH_CONNECTING; |
348 | 342 |
349 if (!bluetooth_adapter_ || !bluetooth_adapter_->IsPowered()) | 343 if (!bluetooth_adapter_ || !bluetooth_adapter_->IsPowered()) |
350 return ScreenlockState::NO_BLUETOOTH; | 344 return ScreenlockState::NO_BLUETOOTH; |
351 | 345 |
352 if (screenlock_type_ == ScreenlockType::SIGN_IN && messenger_ && | 346 Messenger* messenger = GetMessenger(); |
353 !messenger_->SupportsSignIn()) | 347 if (screenlock_type_ == ScreenlockType::SIGN_IN && messenger && |
| 348 !messenger->SupportsSignIn()) |
354 return ScreenlockState::PHONE_UNSUPPORTED; | 349 return ScreenlockState::PHONE_UNSUPPORTED; |
355 | 350 |
356 // If the RSSI is too low, then the remote device is nowhere near the local | 351 // If the RSSI is too low, then the remote device is nowhere near the local |
357 // device. This message should take priority over messages about screen lock | 352 // device. This message should take priority over messages about screen lock |
358 // states. | 353 // states. |
359 if (!proximity_monitor_->IsUnlockAllowed() && | 354 if (!proximity_monitor_->IsUnlockAllowed() && |
360 !proximity_monitor_->IsInRssiRange()) | 355 !proximity_monitor_->IsInRssiRange()) |
361 return ScreenlockState::RSSI_TOO_LOW; | 356 return ScreenlockState::RSSI_TOO_LOW; |
362 | 357 |
363 if (remote_screenlock_state_) { | 358 if (remote_screenlock_state_) { |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 return RemoteScreenlockState::LOCKED; | 456 return RemoteScreenlockState::LOCKED; |
462 | 457 |
463 case SECURE_SCREEN_LOCK_STATE_UNKNOWN: | 458 case SECURE_SCREEN_LOCK_STATE_UNKNOWN: |
464 return RemoteScreenlockState::UNKNOWN; | 459 return RemoteScreenlockState::UNKNOWN; |
465 } | 460 } |
466 | 461 |
467 NOTREACHED(); | 462 NOTREACHED(); |
468 return RemoteScreenlockState::UNKNOWN; | 463 return RemoteScreenlockState::UNKNOWN; |
469 } | 464 } |
470 | 465 |
| 466 Messenger* UnlockManager::GetMessenger() { |
| 467 // TODO(tengs): We should use a weak pointer to hold the Messenger instance |
| 468 // instead. |
| 469 if (!life_cycle_) |
| 470 return nullptr; |
| 471 return life_cycle_->GetMessenger(); |
| 472 } |
| 473 |
471 } // namespace proximity_auth | 474 } // namespace proximity_auth |
OLD | NEW |