Commit da08b742 authored by Quan Nguyen's avatar Quan Nguyen Committed by Commit Bot

cros: Attempt externalBinaryUnlock on lid-open while locked.

Bug: 890912
Change-Id: I4e58b038a6ff288d47e9c37c6b733e6586d48773
Reviewed-on: https://chromium-review.googlesource.com/c/1300097
Commit-Queue: Quan Nguyen <qnnguyen@chromium.org>
Reviewed-by: default avatarJacob Dufault <jdufault@chromium.org>
Cr-Commit-Position: refs/heads/master@{#603610}
parent a7a9dbd2
......@@ -27,6 +27,7 @@
#include "ash/wallpaper/wallpaper_controller.h"
#include "base/bind.h"
#include "base/strings/utf_string_conversions.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "components/user_manager/user.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/l10n/l10n_util.h"
......@@ -459,6 +460,15 @@ views::View* LoginAuthUserView::TestApi::disabled_auth_message() const {
return view_->disabled_auth_message_;
}
views::Button* LoginAuthUserView::TestApi::external_binary_auth_button() const {
return view_->external_binary_auth_button_;
}
views::Button* LoginAuthUserView::TestApi::external_binary_enrollment_button()
const {
return view_->external_binary_enrollment_button_;
}
LoginAuthUserView::Callbacks::Callbacks() = default;
LoginAuthUserView::Callbacks::Callbacks(const Callbacks& other) = default;
......@@ -640,6 +650,11 @@ void LoginAuthUserView::SetAuthMethods(uint32_t auth_methods,
external_binary_auth_button_->SetVisible(has_external_binary);
external_binary_enrollment_button_->SetVisible(has_external_binary);
if (has_external_binary) {
power_manager_client_observer_.Add(
chromeos::DBusThreadManager::Get()->GetPowerManagerClient());
}
int padding_view_height = kDistanceBetweenPasswordFieldAndPinKeyboardDp;
if (has_fingerprint && !has_pin) {
padding_view_height = kDistanceBetweenPasswordFieldAndFingerprintViewDp;
......@@ -853,13 +868,7 @@ void LoginAuthUserView::ButtonPressed(views::Button* sender,
if (sender == online_sign_in_message_) {
OnOnlineSignInMessageTap();
} else if (sender == external_binary_auth_button_) {
password_view_->SetReadOnly(true);
external_binary_auth_button_->SetEnabled(false);
external_binary_enrollment_button_->SetEnabled(false);
Shell::Get()->login_screen_controller()->AuthenticateUserWithExternalBinary(
current_user()->basic_user_info->account_id,
base::BindOnce(&LoginAuthUserView::OnAuthComplete,
weak_factory_.GetWeakPtr()));
AttemptAuthenticateWithExternalBinary();
} else if (sender == external_binary_enrollment_button_) {
password_view_->SetReadOnly(true);
external_binary_auth_button_->SetEnabled(false);
......@@ -870,6 +879,13 @@ void LoginAuthUserView::ButtonPressed(views::Button* sender,
}
}
void LoginAuthUserView::LidEventReceived(
chromeos::PowerManagerClient::LidState state,
const base::TimeTicks& timestamp) {
if (state == chromeos::PowerManagerClient::LidState::OPEN)
AttemptAuthenticateWithExternalBinary();
}
void LoginAuthUserView::OnAuthSubmit(const base::string16& password) {
// Pressing enter when the password field is empty and tap-to-unlock is
// enabled should attempt unlock.
......@@ -942,4 +958,14 @@ bool LoginAuthUserView::HasAuthMethod(AuthMethods auth_method) const {
return (auth_methods_ & auth_method) != 0;
}
void LoginAuthUserView::AttemptAuthenticateWithExternalBinary() {
password_view_->SetReadOnly(true);
external_binary_auth_button_->SetEnabled(false);
external_binary_enrollment_button_->SetEnabled(false);
Shell::Get()->login_screen_controller()->AuthenticateUserWithExternalBinary(
current_user()->basic_user_info->account_id,
base::BindOnce(&LoginAuthUserView::OnAuthComplete,
weak_factory_.GetWeakPtr()));
}
} // namespace ash
......@@ -16,6 +16,8 @@
#include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "base/scoped_observer.h"
#include "base/time/time.h"
#include "chromeos/dbus/power_manager_client.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/view.h"
......@@ -34,8 +36,10 @@ class LoginPinView;
// This class will make call mojo authentication APIs directly. The embedder can
// receive some events about the results of those mojo
// authentication attempts (ie, success/failure).
class ASH_EXPORT LoginAuthUserView : public NonAccessibleView,
public views::ButtonListener {
class ASH_EXPORT LoginAuthUserView
: public NonAccessibleView,
public views::ButtonListener,
public chromeos::PowerManagerClient::Observer {
public:
// TestApi is used for tests to get internal implementation details.
class ASH_EXPORT TestApi {
......@@ -48,6 +52,8 @@ class ASH_EXPORT LoginAuthUserView : public NonAccessibleView,
LoginPinView* pin_view() const;
views::Button* online_sign_in_message() const;
views::View* disabled_auth_message() const;
views::Button* external_binary_auth_button() const;
views::Button* external_binary_enrollment_button() const;
private:
LoginAuthUserView* const view_;
......@@ -137,6 +143,10 @@ class ASH_EXPORT LoginAuthUserView : public NonAccessibleView,
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// chromeos::PowerManagerClient::Observer:
void LidEventReceived(chromeos::PowerManagerClient::LidState state,
const base::TimeTicks& timestamp) override;
private:
struct AnimationState;
class FingerprintView;
......@@ -161,6 +171,10 @@ class ASH_EXPORT LoginAuthUserView : public NonAccessibleView,
// bool has_tap = HasAuthMethod(AUTH_TAP).
bool HasAuthMethod(AuthMethods auth_method) const;
// TODO(crbug/899812): remove this and pass a handler in via the Callbacks
// struct instead.
void AttemptAuthenticateWithExternalBinary();
AuthMethods auth_methods_ = AUTH_NONE;
// True if the user's password might be a PIN. PIN is hashed differently from
// password. The PIN keyboard may not always be visible even when the user
......@@ -188,6 +202,10 @@ class ASH_EXPORT LoginAuthUserView : public NonAccessibleView,
// |ApplyAnimationPostLayout|.
std::unique_ptr<AnimationState> cached_animation_state_;
ScopedObserver<chromeos::PowerManagerClient,
chromeos::PowerManagerClient::Observer>
power_manager_client_observer_{this};
base::WeakPtrFactory<LoginAuthUserView> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(LoginAuthUserView);
......
......@@ -12,13 +12,19 @@
#include "base/bind_helpers.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/fake_power_manager_client.h"
#include "chromeos/dbus/power_manager_client.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/events/event_utils.h"
#include "ui/events/test/event_generator.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/controls/textfield/textfield_test_api.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/widget/widget.h"
using testing::_;
namespace ash {
namespace {
......@@ -30,6 +36,9 @@ class LoginAuthUserViewUnittest : public LoginTestBase {
// LoginTestBase:
void SetUp() override {
power_manager_ = new chromeos::FakePowerManagerClient();
chromeos::DBusThreadManager::GetSetterForTesting()->SetPowerManagerClient(
base::WrapUnique(power_manager_));
LoginTestBase::SetUp();
user_ = CreateUser("user@domain.com");
......@@ -59,6 +68,8 @@ class LoginAuthUserViewUnittest : public LoginTestBase {
mojom::LoginUserInfoPtr user_;
views::View* container_ = nullptr; // Owned by test widget view hierarchy.
LoginAuthUserView* view_ = nullptr; // Owned by test widget view hierarchy.
chromeos::FakePowerManagerClient* power_manager_ =
nullptr; // Owned by DBusThreadmanager
private:
DISALLOW_COPY_AND_ASSIGN(LoginAuthUserViewUnittest);
......@@ -187,4 +198,31 @@ TEST_F(LoginAuthUserViewUnittest,
EXPECT_FALSE(has_password());
}
TEST_F(LoginAuthUserViewUnittest, AttemptsUnlockOnLidOpen) {
LoginAuthUserView::TestApi test_auth_user_view(view_);
std::unique_ptr<MockLoginScreenClient> client = BindMockLoginScreenClient();
SetAuthMethods(LoginAuthUserView::AUTH_EXTERNAL_BINARY);
client->set_authenticate_user_callback_result(false);
EXPECT_CALL(*client, AuthenticateUserWithExternalBinary_(
test_auth_user_view.user_view()
->current_user()
->basic_user_info->account_id,
_));
power_manager_->SetLidState(chromeos::PowerManagerClient::LidState::OPEN,
base::TimeTicks::Now());
base::RunLoop().RunUntilIdle();
LoginPasswordView::TestApi password_test(test_auth_user_view.password_view());
EXPECT_FALSE(password_test.textfield()->read_only());
EXPECT_TRUE(test_auth_user_view.external_binary_auth_button()->state() ==
views::Button::STATE_NORMAL);
EXPECT_TRUE(
test_auth_user_view.external_binary_enrollment_button()->state() ==
views::Button::STATE_NORMAL);
}
} // namespace ash
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