Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(756)

Side by Side Diff: components/proximity_auth/unlock_manager.cc

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

Powered by Google App Engine
This is Rietveld 408576698