Skip to content

Commit

Permalink
cros: Notify user activity when receive fingerprint attempts
Browse files Browse the repository at this point in the history
Currently fingerprint attempts are not treated as user activities.
So when the screen is off, user touch the sensor with an enrolled finger
will silently unlock the screen, with the screen remains off.
And after hitting a key, the screen turns on and already unlocked which
makes user think the screen is never locked.

This CL reports fingerprint attempts as user activity so when user touch
the sensor, the screen will be turned on.


Bug: b:115779078
Change-Id: I10acd8cc3eccb7d594465573fecf9f3099a65f8d
Reviewed-on: https://chromium-review.googlesource.com/1236556
Commit-Queue: Xiaoyin Hu <xiaoyinh@chromium.org>
Reviewed-by: Ken Rockot <rockot@chromium.org>
Reviewed-by: Michael Giuffrida <michaelpg@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Dan Erat <derat@chromium.org>
Reviewed-by: James Cook <jamescook@chromium.org>
Reviewed-by: Steven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593603}
  • Loading branch information
Sarah Hu authored and Commit Bot committed Sep 24, 2018
1 parent 73ff03f commit 8ce89c3
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 7 deletions.
1 change: 1 addition & 0 deletions ash/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"*": [ "accessibility", "app" ],
"ash_pref_connector": [ "pref_connector" ],
"catalog": [ "directory" ],
"device": [ "device:fingerprint"],
"local_state": [ "pref_client" ],
"multidevice_setup": [ "multidevice_setup" ],
"quick_launch_app": [ "mash:launchable" ],
Expand Down
5 changes: 3 additions & 2 deletions ash/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1262,8 +1262,9 @@ void Shell::Init(

peripheral_battery_notifier_ = std::make_unique<PeripheralBatteryNotifier>();
power_event_observer_.reset(new PowerEventObserver());
user_activity_notifier_.reset(
new ui::UserActivityPowerManagerNotifier(user_activity_detector_.get()));
user_activity_notifier_ =
std::make_unique<ui::UserActivityPowerManagerNotifier>(
user_activity_detector_.get(), connector_);
video_activity_notifier_.reset(
new VideoActivityNotifier(video_detector_.get()));
bluetooth_notification_controller_.reset(new BluetoothNotificationController);
Expand Down
2 changes: 1 addition & 1 deletion extensions/shell/browser/shell_desktop_controller_aura.cc
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ void ShellDesktopControllerAura::InitWindowManager() {
user_activity_detector_ = std::make_unique<ui::UserActivityDetector>();
user_activity_notifier_ =
std::make_unique<ui::UserActivityPowerManagerNotifier>(
user_activity_detector_.get());
user_activity_detector_.get(), nullptr /*connector*/);
#endif
}

Expand Down
2 changes: 2 additions & 0 deletions ui/chromeos/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ component("chromeos") {
"//components/device_event_log",
"//components/onc",
"//mojo/public/cpp/bindings",
"//services/device/public/mojom",
"//services/service_manager/public/cpp",
"//services/ws/public/cpp",
"//services/ws/public/mojom",
"//skia",
Expand Down
2 changes: 2 additions & 0 deletions ui/chromeos/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ include_rules = [
"+grit/ui_chromeos_resources.h",
"+grit/ui_chromeos_strings.h",
"+mojo/public/cpp/bindings",
"+services/device/public",
"+services/service_manager/public",
"+services/ws/public/cpp",
"+services/ws/public/mojom",
"+third_party/cros_system_api",
Expand Down
34 changes: 32 additions & 2 deletions ui/chromeos/user_activity_power_manager_notifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/power_manager_client.h"
#include "services/device/public/mojom/constants.mojom.h"
#include "services/service_manager/public/cpp/connector.h"
#include "ui/base/user_activity/user_activity_detector.h"
#include "ui/events/devices/input_device_manager.h"
#include "ui/events/devices/stylus_state.h"
Expand Down Expand Up @@ -44,10 +46,21 @@ power_manager::UserActivityType GetUserActivityTypeForEvent(
} // namespace

UserActivityPowerManagerNotifier::UserActivityPowerManagerNotifier(
UserActivityDetector* detector)
: detector_(detector) {
UserActivityDetector* detector,
service_manager::Connector* connector)
: detector_(detector), fingerprint_observer_binding_(this) {
detector_->AddObserver(this);
ui::InputDeviceManager::GetInstance()->AddObserver(this);

// Connector can be null in tests.
if (connector) {
// Treat fingerprint attempts as user activies to turn on the screen.
// I.e., when user tried to use fingerprint to unlock.
connector->BindInterface(device::mojom::kServiceName, &fingerprint_ptr_);
device::mojom::FingerprintObserverPtr observer;
fingerprint_observer_binding_.Bind(mojo::MakeRequest(&observer));
fingerprint_ptr_->AddFingerprintObserver(std::move(observer));
}
}

UserActivityPowerManagerNotifier::~UserActivityPowerManagerNotifier() {
Expand All @@ -65,6 +78,23 @@ void UserActivityPowerManagerNotifier::OnUserActivity(const Event* event) {
MaybeNotifyUserActivity(GetUserActivityTypeForEvent(event));
}

void UserActivityPowerManagerNotifier::OnAuthScanDone(
uint32_t scan_result,
const base::flat_map<std::string, std::vector<std::string>>& matches) {
MaybeNotifyUserActivity(power_manager::USER_ACTIVITY_OTHER);
}

void UserActivityPowerManagerNotifier::OnSessionFailed() {}

void UserActivityPowerManagerNotifier::OnRestarted() {}

void UserActivityPowerManagerNotifier::OnEnrollScanDone(
uint32_t scan_result,
bool enroll_session_complete,
int percent_complete) {
MaybeNotifyUserActivity(power_manager::USER_ACTIVITY_OTHER);
}

void UserActivityPowerManagerNotifier::MaybeNotifyUserActivity(
power_manager::UserActivityType user_activity_type) {
base::TimeTicks now = base::TimeTicks::Now();
Expand Down
27 changes: 25 additions & 2 deletions ui/chromeos/user_activity_power_manager_notifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,31 @@
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/time/time.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "services/device/public/mojom/fingerprint.mojom.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
#include "ui/base/user_activity/user_activity_observer.h"
#include "ui/chromeos/ui_chromeos_export.h"
#include "ui/events/devices/input_device_event_observer.h"

namespace service_manager {
class Connector;
}

namespace ui {

class UserActivityDetector;

// Notifies the power manager via D-Bus when the user is active.
class UI_CHROMEOS_EXPORT UserActivityPowerManagerNotifier
: public InputDeviceEventObserver,
public UserActivityObserver {
public UserActivityObserver,
public device::mojom::FingerprintObserver {
public:
// Registers and unregisters itself as an observer of |detector| on
// construction and destruction.
explicit UserActivityPowerManagerNotifier(UserActivityDetector* detector);
UserActivityPowerManagerNotifier(UserActivityDetector* detector,
service_manager::Connector* connector);
~UserActivityPowerManagerNotifier() override;

// InputDeviceEventObserver implementation.
Expand All @@ -33,6 +41,17 @@ class UI_CHROMEOS_EXPORT UserActivityPowerManagerNotifier
// UserActivityObserver implementation.
void OnUserActivity(const Event* event) override;

// fingerprint::mojom::FingerprintObserver:
void OnAuthScanDone(
uint32_t scan_result,
const base::flat_map<std::string, std::vector<std::string>>& matches)
override;
void OnSessionFailed() override;
void OnRestarted() override;
void OnEnrollScanDone(uint32_t scan_result,
bool enroll_session_complete,
int percent_complete) override;

private:
// Notifies power manager that the user is active and activity type. No-op if
// it is within 5 seconds from |last_notify_time_|.
Expand All @@ -41,6 +60,10 @@ class UI_CHROMEOS_EXPORT UserActivityPowerManagerNotifier

UserActivityDetector* detector_; // not owned

device::mojom::FingerprintPtr fingerprint_ptr_;
mojo::Binding<device::mojom::FingerprintObserver>
fingerprint_observer_binding_;

// Last time that the power manager was notified.
base::TimeTicks last_notify_time_;

Expand Down

0 comments on commit 8ce89c3

Please sign in to comment.