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 @@ ...@@ -27,6 +27,7 @@
#include "ash/wallpaper/wallpaper_controller.h" #include "ash/wallpaper/wallpaper_controller.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "components/user_manager/user.h" #include "components/user_manager/user.h"
#include "ui/accessibility/ax_node_data.h" #include "ui/accessibility/ax_node_data.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
...@@ -459,6 +460,15 @@ views::View* LoginAuthUserView::TestApi::disabled_auth_message() const { ...@@ -459,6 +460,15 @@ views::View* LoginAuthUserView::TestApi::disabled_auth_message() const {
return view_->disabled_auth_message_; 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() = default;
LoginAuthUserView::Callbacks::Callbacks(const Callbacks& other) = default; LoginAuthUserView::Callbacks::Callbacks(const Callbacks& other) = default;
...@@ -640,6 +650,11 @@ void LoginAuthUserView::SetAuthMethods(uint32_t auth_methods, ...@@ -640,6 +650,11 @@ void LoginAuthUserView::SetAuthMethods(uint32_t auth_methods,
external_binary_auth_button_->SetVisible(has_external_binary); external_binary_auth_button_->SetVisible(has_external_binary);
external_binary_enrollment_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; int padding_view_height = kDistanceBetweenPasswordFieldAndPinKeyboardDp;
if (has_fingerprint && !has_pin) { if (has_fingerprint && !has_pin) {
padding_view_height = kDistanceBetweenPasswordFieldAndFingerprintViewDp; padding_view_height = kDistanceBetweenPasswordFieldAndFingerprintViewDp;
...@@ -853,13 +868,7 @@ void LoginAuthUserView::ButtonPressed(views::Button* sender, ...@@ -853,13 +868,7 @@ void LoginAuthUserView::ButtonPressed(views::Button* sender,
if (sender == online_sign_in_message_) { if (sender == online_sign_in_message_) {
OnOnlineSignInMessageTap(); OnOnlineSignInMessageTap();
} else if (sender == external_binary_auth_button_) { } else if (sender == external_binary_auth_button_) {
password_view_->SetReadOnly(true); AttemptAuthenticateWithExternalBinary();
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()));
} else if (sender == external_binary_enrollment_button_) { } else if (sender == external_binary_enrollment_button_) {
password_view_->SetReadOnly(true); password_view_->SetReadOnly(true);
external_binary_auth_button_->SetEnabled(false); external_binary_auth_button_->SetEnabled(false);
...@@ -870,6 +879,13 @@ void LoginAuthUserView::ButtonPressed(views::Button* sender, ...@@ -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) { void LoginAuthUserView::OnAuthSubmit(const base::string16& password) {
// Pressing enter when the password field is empty and tap-to-unlock is // Pressing enter when the password field is empty and tap-to-unlock is
// enabled should attempt unlock. // enabled should attempt unlock.
...@@ -942,4 +958,14 @@ bool LoginAuthUserView::HasAuthMethod(AuthMethods auth_method) const { ...@@ -942,4 +958,14 @@ bool LoginAuthUserView::HasAuthMethod(AuthMethods auth_method) const {
return (auth_methods_ & auth_method) != 0; 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 } // namespace ash
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/optional.h" #include "base/optional.h"
#include "base/scoped_observer.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/controls/button/button.h"
#include "ui/views/view.h" #include "ui/views/view.h"
...@@ -34,8 +36,10 @@ class LoginPinView; ...@@ -34,8 +36,10 @@ class LoginPinView;
// This class will make call mojo authentication APIs directly. The embedder can // This class will make call mojo authentication APIs directly. The embedder can
// receive some events about the results of those mojo // receive some events about the results of those mojo
// authentication attempts (ie, success/failure). // authentication attempts (ie, success/failure).
class ASH_EXPORT LoginAuthUserView : public NonAccessibleView, class ASH_EXPORT LoginAuthUserView
public views::ButtonListener { : public NonAccessibleView,
public views::ButtonListener,
public chromeos::PowerManagerClient::Observer {
public: public:
// TestApi is used for tests to get internal implementation details. // TestApi is used for tests to get internal implementation details.
class ASH_EXPORT TestApi { class ASH_EXPORT TestApi {
...@@ -48,6 +52,8 @@ class ASH_EXPORT LoginAuthUserView : public NonAccessibleView, ...@@ -48,6 +52,8 @@ class ASH_EXPORT LoginAuthUserView : public NonAccessibleView,
LoginPinView* pin_view() const; LoginPinView* pin_view() const;
views::Button* online_sign_in_message() const; views::Button* online_sign_in_message() const;
views::View* disabled_auth_message() const; views::View* disabled_auth_message() const;
views::Button* external_binary_auth_button() const;
views::Button* external_binary_enrollment_button() const;
private: private:
LoginAuthUserView* const view_; LoginAuthUserView* const view_;
...@@ -137,6 +143,10 @@ class ASH_EXPORT LoginAuthUserView : public NonAccessibleView, ...@@ -137,6 +143,10 @@ class ASH_EXPORT LoginAuthUserView : public NonAccessibleView,
// views::ButtonListener: // views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override; 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: private:
struct AnimationState; struct AnimationState;
class FingerprintView; class FingerprintView;
...@@ -161,6 +171,10 @@ class ASH_EXPORT LoginAuthUserView : public NonAccessibleView, ...@@ -161,6 +171,10 @@ class ASH_EXPORT LoginAuthUserView : public NonAccessibleView,
// bool has_tap = HasAuthMethod(AUTH_TAP). // bool has_tap = HasAuthMethod(AUTH_TAP).
bool HasAuthMethod(AuthMethods auth_method) const; 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; AuthMethods auth_methods_ = AUTH_NONE;
// True if the user's password might be a PIN. PIN is hashed differently from // 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 // password. The PIN keyboard may not always be visible even when the user
...@@ -188,6 +202,10 @@ class ASH_EXPORT LoginAuthUserView : public NonAccessibleView, ...@@ -188,6 +202,10 @@ class ASH_EXPORT LoginAuthUserView : public NonAccessibleView,
// |ApplyAnimationPostLayout|. // |ApplyAnimationPostLayout|.
std::unique_ptr<AnimationState> cached_animation_state_; std::unique_ptr<AnimationState> cached_animation_state_;
ScopedObserver<chromeos::PowerManagerClient,
chromeos::PowerManagerClient::Observer>
power_manager_client_observer_{this};
base::WeakPtrFactory<LoginAuthUserView> weak_factory_{this}; base::WeakPtrFactory<LoginAuthUserView> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(LoginAuthUserView); DISALLOW_COPY_AND_ASSIGN(LoginAuthUserView);
......
...@@ -12,13 +12,19 @@ ...@@ -12,13 +12,19 @@
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/utf_string_conversions.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 "testing/gtest/include/gtest/gtest.h"
#include "ui/events/event_utils.h" #include "ui/events/event_utils.h"
#include "ui/events/test/event_generator.h" #include "ui/events/test/event_generator.h"
#include "ui/views/controls/textfield/textfield.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/layout/box_layout.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
using testing::_;
namespace ash { namespace ash {
namespace { namespace {
...@@ -30,6 +36,9 @@ class LoginAuthUserViewUnittest : public LoginTestBase { ...@@ -30,6 +36,9 @@ class LoginAuthUserViewUnittest : public LoginTestBase {
// LoginTestBase: // LoginTestBase:
void SetUp() override { void SetUp() override {
power_manager_ = new chromeos::FakePowerManagerClient();
chromeos::DBusThreadManager::GetSetterForTesting()->SetPowerManagerClient(
base::WrapUnique(power_manager_));
LoginTestBase::SetUp(); LoginTestBase::SetUp();
user_ = CreateUser("user@domain.com"); user_ = CreateUser("user@domain.com");
...@@ -59,6 +68,8 @@ class LoginAuthUserViewUnittest : public LoginTestBase { ...@@ -59,6 +68,8 @@ class LoginAuthUserViewUnittest : public LoginTestBase {
mojom::LoginUserInfoPtr user_; mojom::LoginUserInfoPtr user_;
views::View* container_ = nullptr; // Owned by test widget view hierarchy. views::View* container_ = nullptr; // Owned by test widget view hierarchy.
LoginAuthUserView* view_ = 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: private:
DISALLOW_COPY_AND_ASSIGN(LoginAuthUserViewUnittest); DISALLOW_COPY_AND_ASSIGN(LoginAuthUserViewUnittest);
...@@ -187,4 +198,31 @@ TEST_F(LoginAuthUserViewUnittest, ...@@ -187,4 +198,31 @@ TEST_F(LoginAuthUserViewUnittest,
EXPECT_FALSE(has_password()); 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 } // 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