Commit 69512b1e authored by anina koehler's avatar anina koehler Committed by Commit Bot

Trigger user activity on session launch, lock and unlock

The login API is used to trigger a session launch, lock or unlock from
an extension. Since for example a badge tap on a connected badge reader
does not count as user activity, we can launch, lock or unlock a
session while the device still thinks it is idle.

Bug: 1138999
Change-Id: I2d738083461e9991d1ea3ed3e5861c1e2c077718
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2506031
Commit-Queue: Anina Koehler <aninak@google.com>
Reviewed-by: default avatarAlexander Hendrich <hendrich@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827215}
parent 1bd82009
......@@ -25,6 +25,7 @@
#include "components/user_manager/user.h"
#include "components/user_manager/user_manager.h"
#include "components/user_manager/user_type.h"
#include "ui/base/user_activity/user_activity_detector.h"
namespace extensions {
......@@ -74,6 +75,8 @@ LoginLaunchManagedGuestSessionFunction::
ExtensionFunction::ResponseAction
LoginLaunchManagedGuestSessionFunction::Run() {
ui::UserActivityDetector::Get()->HandleExternalUserActivity();
std::unique_ptr<api::login::LaunchManagedGuestSession::Params> parameters =
api::login::LaunchManagedGuestSession::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(parameters);
......@@ -150,6 +153,8 @@ LoginLockManagedGuestSessionFunction::~LoginLockManagedGuestSessionFunction() =
default;
ExtensionFunction::ResponseAction LoginLockManagedGuestSessionFunction::Run() {
ui::UserActivityDetector::Get()->HandleExternalUserActivity();
const user_manager::UserManager* user_manager =
user_manager::UserManager::Get();
const user_manager::User* active_user = user_manager->GetActiveUser();
......@@ -175,6 +180,8 @@ LoginUnlockManagedGuestSessionFunction::
ExtensionFunction::ResponseAction
LoginUnlockManagedGuestSessionFunction::Run() {
ui::UserActivityDetector::Get()->HandleExternalUserActivity();
std::unique_ptr<api::login::UnlockManagedGuestSession::Params> parameters =
api::login::UnlockManagedGuestSession::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(parameters);
......
......@@ -12,6 +12,7 @@
#include "base/memory/scoped_refptr.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/extensions/login_screen/login/login_api_lock_handler.h"
#include "chrome/browser/chromeos/login/existing_user_controller.h"
......@@ -37,6 +38,7 @@
#include "extensions/common/extension_builder.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/user_activity/user_activity_detector.h"
using testing::_;
using testing::Invoke;
......@@ -209,6 +211,9 @@ MATCHER_P(MatchUserContextSecret, expected, "") {
// Test that calling |login.launchManagedGuestSession()| calls the corresponding
// method from the |ExistingUserController|.
TEST_F(LoginApiUnittest, LaunchManagedGuestSession) {
base::TimeTicks now_ = base::TimeTicks::Now();
ui::UserActivityDetector::Get()->set_now_for_test(now_);
std::unique_ptr<ScopedTestingProfile> profile = AddPublicAccountUser(kEmail);
EXPECT_CALL(*mock_existing_user_controller_,
Login(GetPublicUserContext(kEmail),
......@@ -216,6 +221,10 @@ TEST_F(LoginApiUnittest, LaunchManagedGuestSession) {
.Times(1);
RunFunction(new LoginLaunchManagedGuestSessionFunction(), "[]");
// Test that calling |login.launchManagedGuestSession()| triggered a user
// activity in the |UserActivityDetector|.
EXPECT_EQ(now_, ui::UserActivityDetector::Get()->last_activity_time());
}
// Test that calling |login.launchManagedGuestSession()| with a password sets
......@@ -309,6 +318,9 @@ TEST_F(LoginApiUnittest, FetchDataForNextLoginAttemptClearsPref) {
}
TEST_F(LoginApiUnittest, LockManagedGuestSession) {
base::TimeTicks now_ = base::TimeTicks::Now();
ui::UserActivityDetector::Get()->set_now_for_test(now_);
std::unique_ptr<ScopedTestingProfile> profile = AddPublicAccountUser(kEmail);
fake_chrome_user_manager_->SwitchActiveUser(AccountId::FromUserEmail(kEmail));
fake_chrome_user_manager_->set_current_user_can_lock(true);
......@@ -320,6 +332,10 @@ TEST_F(LoginApiUnittest, LockManagedGuestSession) {
.WillOnce(Return());
RunFunction(new LoginLockManagedGuestSessionFunction(), "[]");
// Test that calling |login.lockManagedGuestSession()| triggered a user
// activity in the |UserActivityDetector|.
EXPECT_EQ(now_, ui::UserActivityDetector::Get()->last_activity_time());
}
TEST_F(LoginApiUnittest, LockManagedGuestSessionNoActiveUser) {
......@@ -361,6 +377,9 @@ TEST_F(LoginApiUnittest, LockManagedGuestSessionSessionNotActive) {
}
TEST_F(LoginApiUnittest, UnlockManagedGuestSession) {
base::TimeTicks now_ = base::TimeTicks::Now();
ui::UserActivityDetector::Get()->set_now_for_test(now_);
SetExtensionWithId(kExtensionId);
std::unique_ptr<ScopedTestingProfile> scoped_profile =
AddPublicAccountUser(kEmail);
......@@ -381,6 +400,10 @@ TEST_F(LoginApiUnittest, UnlockManagedGuestSession) {
});
RunFunction(new LoginUnlockManagedGuestSessionFunction(), "[\"password\"]");
// Test that calling |login.unlockManagedGuestSession()| triggered a user
// activity in the |UserActivityDetector|.
EXPECT_EQ(now_, ui::UserActivityDetector::Get()->last_activity_time());
}
TEST_F(LoginApiUnittest, UnlockManagedGuestSessionNoActiveUser) {
......
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