Commit a252bab6 authored by tengs's avatar tengs Committed by Commit bot

[EasyUnlock] Observe proximity changes and clean up TX power strategy.

With BLE, we only check the RSSI, so we can now remove all references to the TX
power proximity strategy.

Review-Url: https://codereview.chromium.org/2898513002
Cr-Commit-Position: refs/heads/master@{#473768}
parent 2187893b
......@@ -11698,12 +11698,9 @@ Please check your email at <ph name="ACCOUNT_EMAIL">$2<ex>jane.doe@gmail.com</ex
To keep your <ph name="DEVICE_TYPE">$1<ex>Chromebook</ex></ph> safe, Smart Lock for Chromebook requires a screen lock on your phone.
</message>
<message name="IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_RSSI_TOO_LOW" desc="Tooltip for an icon on a user's lock screen pod shown by Easy Unlock when a phone eligible to unlock the Chromebook is detected, but it's not in the Chromebook's proximity (> 30 feet away).">
Can’t find your phone. Make sure it’s within arm’s reach.
</message>
<message name="IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_TX_POWER_TOO_HIGH" desc="Tooltip for an icon on a user's lock screen pod shown by Easy Unlock when a phone eligible to unlock the Chromebook is detected, but it's not in the Chromebook's proximity (> 1 foot away).">
Bring your phone closer to your <ph name="DEVICE_TYPE">$1<ex>Chromebook</ex></ph> to enter.
</message>
<message name="IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_PHONE_LOCKED_AND_TX_POWER_TOO_HIGH" desc="Tooltip for an icon on a user's lock screen pod shown by Easy Unlock when a phone eligible to unlock the Chromebook is detected, but it's both (a) locked and (b) not in the Chromebook's proximity (> 1 foot away).">
<message name="IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_PHONE_LOCKED_AND_RSSI_TOO_LOW" desc="Tooltip for an icon on a user's lock screen pod shown by Easy Unlock when a phone eligible to unlock the Chromebook is detected, but it's both (a) locked and (b) not in the Chromebook's proximity (> 1 foot away).">
Unlock your phone and bring it closer to your <ph name="DEVICE_TYPE">$1<ex>Chromebook</ex></ph> to enter.
</message>
<message name="IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_INITIAL_AUTHENTICATED" desc="Tooltip text shown on lock screen when a phone eligible to unlock the Chromebook via Easy Unlock is detected and authenticated for the first time.">
......
......@@ -100,11 +100,11 @@ ScreenlockState ToScreenlockState(easy_unlock_private::State state) {
case easy_unlock_private::STATE_PHONE_UNSUPPORTED:
return ScreenlockState::PHONE_UNSUPPORTED;
case easy_unlock_private::STATE_RSSI_TOO_LOW:
return ScreenlockState::RSSI_TOO_LOW;
case easy_unlock_private::STATE_TX_POWER_TOO_HIGH:
return ScreenlockState::TX_POWER_TOO_HIGH;
// Note: TX Power is deprecated, so we merge it with the RSSI state.
return ScreenlockState::RSSI_TOO_LOW;
case easy_unlock_private::STATE_PHONE_LOCKED_AND_TX_POWER_TOO_HIGH:
return ScreenlockState::PHONE_LOCKED_AND_TX_POWER_TOO_HIGH;
return ScreenlockState::PHONE_LOCKED_AND_RSSI_TOO_LOW;
case easy_unlock_private::STATE_AUTHENTICATED:
return ScreenlockState::AUTHENTICATED;
default:
......
......@@ -49,7 +49,7 @@ enum EasyUnlockAuthEvent {
// though.
PASSWORD_ENTRY_WITH_AUTHENTICATED_PHONE = 14,
// Password is used because phone is not right next to the Chromebook.
PASSWORD_ENTRY_TX_POWER_TOO_HIGH = 15,
PASSWORD_ENTRY_TX_POWER_TOO_HIGH = 15, // DEPRECATED
// Password is used because Easy sign-in failed.
PASSWORD_ENTRY_LOGIN_FAILED = 16,
// Password is used because pairing data is changed for a "new" Chromebook
......@@ -60,7 +60,7 @@ enum EasyUnlockAuthEvent {
PASSWORD_ENTRY_NO_SCREENLOCK_STATE_HANDLER = 18,
// Password is used because the phone is (a) locked, and (b) not right next to
// the Chromebook.
PASSWORD_ENTRY_PHONE_LOCKED_AND_TX_POWER_TOO_HIGH = 19,
PASSWORD_ENTRY_PHONE_LOCKED_AND_RSSI_TOO_LOW = 19,
EASY_UNLOCK_AUTH_EVENT_COUNT // Must be the last entry.
};
......
......@@ -31,10 +31,9 @@ proximity_auth::ScreenlockBridge::UserPodCustomIcon GetIconForState(
case ScreenlockState::PHONE_LOCKED:
case ScreenlockState::PHONE_NOT_LOCKABLE:
case ScreenlockState::PHONE_UNSUPPORTED:
case ScreenlockState::RSSI_TOO_LOW:
return proximity_auth::ScreenlockBridge::USER_POD_CUSTOM_ICON_LOCKED;
case ScreenlockState::TX_POWER_TOO_HIGH:
case ScreenlockState::PHONE_LOCKED_AND_TX_POWER_TOO_HIGH:
case ScreenlockState::RSSI_TOO_LOW:
case ScreenlockState::PHONE_LOCKED_AND_RSSI_TOO_LOW:
// TODO(isherman): This icon is currently identical to the regular locked
// icon. Once the reduced proximity range flag is removed, consider
// deleting the redundant icon.
......@@ -75,11 +74,8 @@ size_t GetTooltipResourceId(ScreenlockState state) {
return IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_UNSUPPORTED_ANDROID_VERSION;
case ScreenlockState::RSSI_TOO_LOW:
return IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_RSSI_TOO_LOW;
case ScreenlockState::TX_POWER_TOO_HIGH:
return IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_TX_POWER_TOO_HIGH;
case ScreenlockState::PHONE_LOCKED_AND_TX_POWER_TOO_HIGH:
return
IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_PHONE_LOCKED_AND_TX_POWER_TOO_HIGH;
case ScreenlockState::PHONE_LOCKED_AND_RSSI_TOO_LOW:
return IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_PHONE_LOCKED_AND_RSSI_TOO_LOW;
case ScreenlockState::AUTHENTICATED:
return IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_HARDLOCK_INSTRUCTIONS;
}
......@@ -93,14 +89,14 @@ bool TooltipContainsDeviceType(ScreenlockState state) {
state == ScreenlockState::PHONE_NOT_LOCKABLE ||
state == ScreenlockState::NO_BLUETOOTH ||
state == ScreenlockState::PHONE_UNSUPPORTED ||
state == ScreenlockState::TX_POWER_TOO_HIGH ||
state == ScreenlockState::PHONE_LOCKED_AND_TX_POWER_TOO_HIGH);
state == ScreenlockState::RSSI_TOO_LOW ||
state == ScreenlockState::PHONE_LOCKED_AND_RSSI_TOO_LOW);
}
// Returns true iff the |state| corresponds to a locked remote device.
bool IsLockedState(ScreenlockState state) {
return (state == ScreenlockState::PHONE_LOCKED ||
state == ScreenlockState::PHONE_LOCKED_AND_TX_POWER_TOO_HIGH);
state == ScreenlockState::PHONE_LOCKED_AND_RSSI_TOO_LOW);
}
} // namespace
......
......@@ -698,7 +698,7 @@ TEST_F(EasyUnlockScreenlockStateHandlerTest, NoOverrideOnlineSignin) {
states.push_back(ScreenlockState::PHONE_NOT_LOCKABLE);
states.push_back(ScreenlockState::PHONE_UNSUPPORTED);
states.push_back(ScreenlockState::RSSI_TOO_LOW);
states.push_back(ScreenlockState::TX_POWER_TOO_HIGH);
states.push_back(ScreenlockState::PHONE_LOCKED_AND_RSSI_TOO_LOW);
states.push_back(ScreenlockState::AUTHENTICATED);
for (size_t i = 0; i < states.size(); ++i) {
......
......@@ -791,10 +791,8 @@ EasyUnlockAuthEvent EasyUnlockService::GetPasswordAuthEvent() const {
return PASSWORD_ENTRY_PHONE_UNSUPPORTED;
case ScreenlockState::RSSI_TOO_LOW:
return PASSWORD_ENTRY_RSSI_TOO_LOW;
case ScreenlockState::TX_POWER_TOO_HIGH:
return PASSWORD_ENTRY_TX_POWER_TOO_HIGH;
case ScreenlockState::PHONE_LOCKED_AND_TX_POWER_TOO_HIGH:
return PASSWORD_ENTRY_PHONE_LOCKED_AND_TX_POWER_TOO_HIGH;
case ScreenlockState::PHONE_LOCKED_AND_RSSI_TOO_LOW:
return PASSWORD_ENTRY_PHONE_LOCKED_AND_RSSI_TOO_LOW;
case ScreenlockState::AUTHENTICATED:
return PASSWORD_ENTRY_WITH_AUTHENTICATED_PHONE;
}
......
......@@ -27,7 +27,8 @@ const int kPollingTimeoutMs = 250;
// The RSSI threshold below which we consider the remote device to not be in
// proximity.
const int kRssiThreshold = -45;
// Tentative value, tested between a cave and Nexus 6 device.
const int kRssiThreshold = -50;
// The weight of the most recent RSSI sample.
const double kRssiSampleWeight = 0.3;
......
......@@ -38,7 +38,7 @@ const char kRemoteDevicePublicKey[] = "Remote Public Key";
const char kRemoteDeviceName[] = "LGE Nexus 5";
const char kBluetoothAddress[] = "AA:BB:CC:DD:EE:FF";
const char kPersistentSymmetricKey[] = "PSK";
const int kRssiThreshold = -45;
const int kRssiThreshold = -50;
class MockProximityMonitorObserver : public ProximityMonitorObserver {
public:
......
......@@ -34,16 +34,11 @@ enum class ScreenlockState {
// signal strength is too low, i.e. the phone is roughly more than 30 feet
// away, and therefore is not allowed to unlock the device.
RSSI_TOO_LOW,
// A phone eligible to unlock the local device is found, but the local
// device's transmission power is too high, indicating that the phone is
// (probably) more than 1 foot away, and therefore is not allowed to unlock
// the device.
TX_POWER_TOO_HIGH,
// A phone eligible to unlock the local device is found; but (a) the phone is
// locked, and (b) the local device's transmission power is too high,
// indicating that the phone is (probably) more than 1 foot away, and
// therefore is not allowed to unlock the device.
PHONE_LOCKED_AND_TX_POWER_TOO_HIGH,
PHONE_LOCKED_AND_RSSI_TOO_LOW,
// The local device can be unlocked using proximity-based authentication.
AUTHENTICATED,
};
......
......@@ -151,7 +151,7 @@ void UnlockManagerImpl::SetRemoteDeviceLifeCycle(
void UnlockManagerImpl::OnLifeCycleStateChanged() {
RemoteDeviceLifeCycle::State state = life_cycle_->GetState();
PA_LOG(INFO) << "[Unlock] RemoteDeviceLifeCycle state changed: "
PA_LOG(INFO) << "RemoteDeviceLifeCycle state changed: "
<< static_cast<int>(state);
remote_screenlock_state_.reset();
......@@ -170,7 +170,7 @@ void UnlockManagerImpl::OnLifeCycleStateChanged() {
void UnlockManagerImpl::OnUnlockEventSent(bool success) {
if (!is_attempting_auth_) {
PA_LOG(ERROR) << "[Unlock] Sent easy_unlock event, but no auth attempted.";
PA_LOG(ERROR) << "Sent easy_unlock event, but no auth attempted.";
return;
}
......@@ -179,7 +179,7 @@ void UnlockManagerImpl::OnUnlockEventSent(bool success) {
void UnlockManagerImpl::OnRemoteStatusUpdate(
const RemoteStatusUpdate& status_update) {
PA_LOG(INFO) << "[Unlock] Status Update: ("
PA_LOG(INFO) << "Status Update: ("
<< "user_present=" << status_update.user_presence << ", "
<< "secure_screen_lock="
<< status_update.secure_screen_lock_state << ", "
......@@ -196,13 +196,13 @@ void UnlockManagerImpl::OnRemoteStatusUpdate(
void UnlockManagerImpl::OnDecryptResponse(const std::string& decrypted_bytes) {
if (!is_attempting_auth_) {
PA_LOG(ERROR) << "[Unlock] Decrypt response received but not attempting "
PA_LOG(ERROR) << "Decrypt response received but not attempting "
<< "auth.";
return;
}
if (decrypted_bytes.empty()) {
PA_LOG(WARNING) << "[Unlock] Failed to decrypt sign-in challenge.";
PA_LOG(WARNING) << "Failed to decrypt sign-in challenge.";
AcceptAuthAttempt(false);
} else {
sign_in_secret_.reset(new std::string(decrypted_bytes));
......@@ -212,12 +212,12 @@ void UnlockManagerImpl::OnDecryptResponse(const std::string& decrypted_bytes) {
void UnlockManagerImpl::OnUnlockResponse(bool success) {
if (!is_attempting_auth_) {
PA_LOG(ERROR) << "[Unlock] Unlock response received but not attempting "
PA_LOG(ERROR) << "Unlock response received but not attempting "
<< "auth.";
return;
}
PA_LOG(INFO) << "[Unlock] Unlock response from remote device: "
PA_LOG(INFO) << "Unlock response from remote device: "
<< (success ? "success" : "failure");
if (success)
GetMessenger()->DispatchUnlockEvent();
......@@ -229,6 +229,11 @@ void UnlockManagerImpl::OnDisconnected() {
GetMessenger()->RemoveObserver(this);
}
void UnlockManagerImpl::OnProximityStateChanged() {
PA_LOG(INFO) << "Proximity state changed.";
UpdateLockScreen();
}
void UnlockManagerImpl::OnScreenDidLock(
ScreenlockBridge::LockHandler::ScreenType screen_type) {
OnScreenLockedOrUnlocked(true);
......@@ -281,7 +286,7 @@ void UnlockManagerImpl::SuspendDone(const base::TimeDelta& sleep_duration) {
void UnlockManagerImpl::OnAuthAttempted(
ScreenlockBridge::LockHandler::AuthType auth_type) {
if (is_attempting_auth_) {
PA_LOG(INFO) << "[Unlock] Already attempting auth.";
PA_LOG(INFO) << "Already attempting auth.";
return;
}
......@@ -291,7 +296,7 @@ void UnlockManagerImpl::OnAuthAttempted(
is_attempting_auth_ = true;
if (!life_cycle_) {
PA_LOG(ERROR) << "[Unlock] No life_cycle active when auth is attempted";
PA_LOG(ERROR) << "No life_cycle active when auth is attempted";
AcceptAuthAttempt(false);
UpdateLockScreen();
return;
......@@ -315,8 +320,7 @@ void UnlockManagerImpl::OnAuthAttempted(
if (GetMessenger()->SupportsSignIn()) {
GetMessenger()->RequestUnlock();
} else {
PA_LOG(INFO) << "[Unlock] Protocol v3.1 not supported, skipping "
<< "request_unlock.";
PA_LOG(INFO) << "Protocol v3.1 not supported, skipping request_unlock.";
GetMessenger()->DispatchUnlockEvent();
}
}
......@@ -376,8 +380,14 @@ ScreenlockState UnlockManagerImpl::GetScreenlockState() {
// If the RSSI is too low, then the remote device is nowhere near the local
// device. This message should take priority over messages about screen lock
// states.
if (!proximity_monitor_->IsUnlockAllowed())
return ScreenlockState::RSSI_TOO_LOW;
if (!proximity_monitor_->IsUnlockAllowed()) {
if (remote_screenlock_state_ &&
*remote_screenlock_state_ == RemoteScreenlockState::UNLOCKED) {
return ScreenlockState::RSSI_TOO_LOW;
} else {
return ScreenlockState::PHONE_LOCKED_AND_RSSI_TOO_LOW;
}
}
if (remote_screenlock_state_) {
switch (*remote_screenlock_state_) {
......@@ -406,6 +416,9 @@ void UnlockManagerImpl::UpdateLockScreen() {
if (screenlock_state_ == new_state)
return;
PA_LOG(INFO) << "Updating screenlock state from "
<< static_cast<int>(screenlock_state_) << " to "
<< static_cast<int>(new_state);
proximity_auth_client_->UpdateScreenlockState(new_state);
screenlock_state_ = new_state;
}
......@@ -417,6 +430,7 @@ void UnlockManagerImpl::UpdateProximityMonitorState() {
if (is_locked_ && life_cycle_ &&
life_cycle_->GetState() ==
RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED) {
proximity_monitor_->AddObserver(this);
proximity_monitor_->Start();
} else {
proximity_monitor_->Stop();
......
......@@ -11,6 +11,7 @@
#include "build/build_config.h"
#include "components/proximity_auth/messenger_observer.h"
#include "components/proximity_auth/proximity_auth_system.h"
#include "components/proximity_auth/proximity_monitor_observer.h"
#include "components/proximity_auth/remote_device_life_cycle.h"
#include "components/proximity_auth/remote_status_update.h"
#include "components/proximity_auth/screenlock_bridge.h"
......@@ -32,6 +33,7 @@ class ProximityMonitor;
// the authentication status of the registered remote devices.
class UnlockManagerImpl : public UnlockManager,
public MessengerObserver,
public ProximityMonitorObserver,
public ScreenlockBridge::Observer,
#if defined(OS_CHROMEOS)
chromeos::PowerManagerClient::Observer,
......@@ -73,6 +75,9 @@ class UnlockManagerImpl : public UnlockManager,
void OnUnlockResponse(bool success) override;
void OnDisconnected() override;
// ProximityMonitorObserver:
void OnProximityStateChanged() override;
// ScreenlockBridge::Observer
void OnScreenDidLock(
ScreenlockBridge::LockHandler::ScreenType screen_type) override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment