2 * Copyright (C) 2013-2016 Canonical Ltd.
3 * Copyright (C) 2021 UBports Foundation
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 3.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19import AccountsService 0.1
23import Lomiri.Components 1.3
24import Lomiri.Launcher 0.1
25import Lomiri.Session 0.1
33 created: loader.status == Loader.Ready
35 property real dragHandleLeftMargin: 0
37 property url background
38 property bool hasCustomBackground
39 property real backgroundSourceSize
41 // How far to offset the top greeter layer during a launcher left-drag
42 property real launcherOffset
44 // How far down to position the greeter's interface to avoid the Panel
45 property real panelHeight
47 readonly property bool active: required || hasLockedApp
48 readonly property bool fullyShown: loader.item ? loader.item.fullyShown : false
50 property bool allowFingerprint: true
52 // True when the greeter is waiting for PAM or other setup process
53 readonly property alias waiting: d.waiting
55 property string lockedApp: ""
56 readonly property bool hasLockedApp: lockedApp !== ""
58 property bool forcedUnlock
59 readonly property bool locked: LightDMService.greeter.active && !LightDMService.greeter.authenticated && !forcedUnlock
61 property bool tabletMode
62 property url viewSource // only used for testing
64 property int failedLoginsDelayAttempts: 7 // number of failed logins
65 property real failedLoginsDelayMinutes: 5 // minutes of forced waiting
66 property int failedFingerprintLoginsDisableAttempts: 5 // number of failed fingerprint logins
67 property int failedFingerprintReaderRetryDelay: 250 // time to wait before retrying a failed fingerprint read [ms]
69 readonly property bool animating: loader.item ? loader.item.animating : false
71 property rect inputMethodRect
73 property bool hasKeyboard: false
76 signal sessionStarted()
77 signal emergencyCall()
79 function forceShow() {
81 d.isLockscreen = true;
86 loader.item.forceShow();
88 // Normally loader.onLoaded will select a user, but if we're
89 // already shown, do it manually.
90 d.selectUser(d.currentIndex);
93 // Even though we may already be shown, we want to call show() for its
94 // possible side effects, like hiding indicators and such.
96 // We re-check forcedUnlock here, because selectUser above might
97 // process events during authentication, and a request to unlock could
98 // have come in in the meantime.
104 function notifyAppFocusRequested(appId) {
110 if (appId === lockedApp) {
111 hide(); // show locked app
114 d.startUnlock(false /* toTheRight */);
117 d.startUnlock(false /* toTheRight */);
121 // Notify that the user has explicitly requested an app
122 function notifyUserRequestedApp() {
127 // A hint that we're about to focus an app. This way we can look
128 // a little more responsive, rather than waiting for the above
129 // notifyAppFocusRequested call. We also need this in case we have a locked
130 // app, in order to show lockscreen instead of new app.
131 d.startUnlock(false /* toTheRight */);
134 // This is a just a glorified notifyUserRequestedApp(), but it does one
135 // other thing: it hides any cover pages to the RIGHT, because the user
136 // just came from a launcher drag starting on the left.
137 // It also returns a boolean value, indicating whether there was a visual
138 // change or not (the shell only wants to hide the launcher if there was
140 function notifyShowingDashFromDrag() {
145 return d.startUnlock(true /* toTheRight */);
148 function sessionToStart() {
149 for (var i = 0; i < LightDMService.sessions.count; i++) {
150 var session = LightDMService.sessions.data(i,
151 LightDMService.sessionRoles.KeyRole);
152 if (loader.item.sessionToStart === session) {
157 return LightDMService.greeter.defaultSession;
163 readonly property bool multiUser: LightDMService.users.count > 1
164 readonly property int selectUserIndex: d.getUserIndex(LightDMService.greeter.selectUser)
165 property int currentIndex: Math.max(selectUserIndex, 0)
166 readonly property bool waiting: LightDMService.prompts.count == 0 && !root.forcedUnlock
167 property bool isLockscreen // true when we are locking an active session, rather than first user login
168 readonly property bool secureFingerprint: isLockscreen &&
169 AccountsService.failedFingerprintLogins <
170 root.failedFingerprintLoginsDisableAttempts
171 readonly property bool alphanumeric: AccountsService.passwordDisplayHint === AccountsService.Keyboard
173 // We want 'launcherOffset' to animate down to zero. But not to animate
174 // while being dragged. So ideally we change this only when the user
175 // lets go and launcherOffset drops to zero. But we need to wait for
176 // the behavior to be enabled first. So we cache the last known good
177 // launcherOffset value to cover us during that brief gap between
178 // release and the behavior turning on.
179 property real lastKnownPositiveOffset // set in a launcherOffsetChanged below
180 property real launcherOffsetProxy: (shown && !launcherOffsetProxyBehavior.enabled) ? lastKnownPositiveOffset : 0
181 Behavior on launcherOffsetProxy {
182 id: launcherOffsetProxyBehavior
183 enabled: launcherOffset === 0
184 LomiriNumberAnimation {}
187 function getUserIndex(username) {
191 // Find index for requested user, if it exists
192 for (var i = 0; i < LightDMService.users.count; i++) {
193 if (username === LightDMService.users.data(i, LightDMService.userRoles.NameRole)) {
201 function selectUser(index) {
202 if (index < 0 || index >= LightDMService.users.count)
204 currentIndex = index;
205 var user = LightDMService.users.data(index, LightDMService.userRoles.NameRole);
206 AccountsService.user = user;
207 LauncherModel.setUser(user);
208 LightDMService.greeter.authenticate(user); // always resets auth state
211 function hideView() {
213 loader.item.enabled = false; // drop OSK and prevent interaction
219 if (LightDMService.greeter.startSessionSync(root.sessionToStart())) {
222 } else if (loader.item) {
223 loader.item.notifyAuthenticationFailed();
227 function startUnlock(toTheRight) {
229 return loader.item.tryToUnlock(toTheRight);
235 function checkForcedUnlock(hideNow) {
236 if (forcedUnlock && shown) {
239 ShellNotifier.greeter.hide(true); // skip hide animation
244 function showFingerprintMessage(msg) {
245 d.selectUser(d.currentIndex);
246 LightDMService.prompts.prepend(msg, LightDMService.prompts.Error);
248 loader.item.showErrorMessage(msg);
249 loader.item.notifyAuthenticationFailed();
254 onLauncherOffsetChanged: {
255 if (launcherOffset > 0) {
256 d.lastKnownPositiveOffset = launcherOffset;
260 onForcedUnlockChanged: d.checkForcedUnlock(false /* hideNow */)
261 Component.onCompleted: d.checkForcedUnlock(true /* hideNow */)
265 AccountsService.failedLogins = 0;
266 AccountsService.failedFingerprintLogins = 0;
268 // Stop delay timer if they logged in with fingerprint
269 forcedDelayTimer.stop();
270 forcedDelayTimer.delayMinutes = 0;
282 schema.id: "com.lomiri.Shell.Greeter"
288 // We use a short interval and check against the system wall clock
289 // because we have to consider the case that the system is suspended
290 // for a few minutes. When we wake up, we want to quickly be correct.
293 property var delayTarget
294 property int delayMinutes
296 function forceDelay() {
297 // Store the beginning time for a lockout in GSettings, so that
298 // we still lock the user out if they reboot. And we store
299 // starting time rather than end-time or how-long because:
300 // - If storing end-time and on boot we have a problem with NTP,
301 // we might get locked out for a lot longer than we thought.
302 // - If storing how-long, and user turns their phone off for an
303 // hour rather than wait, they wouldn't expect to still be locked
305 // - A malicious actor could manipulate either of the above
306 // settings to keep the user out longer. But by storing
307 // start-time, we never make the user wait longer than the full
309 greeterSettings.lockedOutTime = new Date().getTime();
310 checkForForcedDelay();
314 var diff = delayTarget - new Date();
316 delayMinutes = Math.ceil(diff / 60000);
323 function checkForForcedDelay() {
324 if (greeterSettings.lockedOutTime === 0) {
328 var now = new Date();
329 delayTarget = new Date(greeterSettings.lockedOutTime + failedLoginsDelayMinutes * 60000);
331 // If tooEarly is true, something went very wrong. Bug or NTP
332 // misconfiguration maybe?
333 var tooEarly = now.getTime() < greeterSettings.lockedOutTime;
334 var tooLate = now >= delayTarget;
336 // Compare stored time to system time. If a malicious actor is
337 // able to manipulate time to avoid our lockout, they already have
338 // enough access to cause damage. So we choose to trust this check.
339 if (tooEarly || tooLate) {
347 Component.onCompleted: checkForForcedDelay()
351 // Nothing should leak to items behind the greeter
352 MouseArea { anchors.fill: parent; hoverEnabled: true }
360 active: root.required
361 source: root.viewSource.toString() ? root.viewSource :
362 (d.multiUser || root.tabletMode) ? "WideView.qml" : "NarrowView.qml"
366 item.forceActiveFocus();
367 d.selectUser(d.currentIndex);
368 LightDMService.infographic.readyForDataChange();
378 LightDMService.greeter.respond(response);
383 onTease: root.tease()
384 onEmergencyCall: root.emergencyCall()
386 if (!loader.item.required) {
387 ShellNotifier.greeter.hide(false);
394 property: "panelHeight"
395 value: root.panelHeight
400 property: "launcherOffset"
401 value: d.launcherOffsetProxy
406 property: "dragHandleLeftMargin"
407 value: root.dragHandleLeftMargin
412 property: "delayMinutes"
413 value: forcedDelayTimer.delayMinutes
418 property: "background"
419 value: root.background
424 property: "backgroundSourceSize"
425 value: root.backgroundSourceSize
430 property: "hasCustomBackground"
431 value: root.hasCustomBackground
448 property: "alphanumeric"
449 value: d.alphanumeric
454 property: "currentIndex"
455 value: d.currentIndex
460 property: "userModel"
461 value: LightDMService.users
466 property: "infographicModel"
467 value: LightDMService.infographic
472 property: "inputMethodRect"
473 value: root.inputMethodRect
478 property: "hasKeyboard"
479 value: root.hasKeyboard
484 target: LightDMService.greeter
486 onShowGreeter: root.forceShow()
487 onHideGreeter: root.forcedUnlock = true
494 loader.item.notifyAuthenticationFailed();
497 AccountsService.failedLogins++;
499 // Check if we should initiate a forced login delay
500 if (failedLoginsDelayAttempts > 0
501 && AccountsService.failedLogins > 0
502 && AccountsService.failedLogins % failedLoginsDelayAttempts == 0) {
503 forcedDelayTimer.forceDelay();
506 d.selectUser(d.currentIndex);
516 onRequestAuthenticationUser: d.selectUser(d.getUserIndex(user))
520 target: ShellNotifier.greeter
523 root.hideNow(); // skip hide animation
531 target: ShellNotifier.greeter
537 target: DBusLomiriSessionService
538 onLockRequested: root.forceShow()
540 root.forcedUnlock = true;
541 ShellNotifier.greeter.hide(true);
546 target: LightDMService.greeter
552 target: LightDMService.infographic
554 value: AccountsService.statsWelcomeScreen ? LightDMService.users.data(d.currentIndex, LightDMService.userRoles.NameRole) : ""
559 onLanguageChanged: LightDMService.infographic.readyForDataChange()
566 onTriggered: biometryd.startOperation()
567 interval: failedFingerprintReaderRetryDelay
572 objectName: "biometryd"
574 property var operation: null
575 readonly property bool idEnabled: root.active &&
576 root.allowFingerprint &&
577 Powerd.status === Powerd.On &&
578 Biometryd.available &&
579 AccountsService.enableFingerprintIdentification
581 function startOperation() {
583 var identifier = Biometryd.defaultDevice.identifier;
584 operation = identifier.identifyUser();
585 operation.start(biometryd);
589 function cancelOperation() {
596 function restartOperation() {
598 if (failedFingerprintReaderRetryDelay > 0) {
599 fpRetryTimer.running = true;
605 function failOperation(reason) {
606 console.log("Failed to identify user by fingerprint:", reason);
608 var msg = d.secureFingerprint ? i18n.tr("Try again") :
609 d.alphanumeric ? i18n.tr("Enter passphrase to unlock") :
610 i18n.tr("Enter passcode to unlock");
611 d.showFingerprintMessage(msg);
614 Component.onCompleted: startOperation()
615 Component.onDestruction: cancelOperation()
616 onIdEnabledChanged: restartOperation()
619 if (!d.secureFingerprint) {
620 failOperation("fingerprint reader is locked");
623 if (result !== LightDMService.users.data(d.currentIndex, LightDMService.userRoles.UidRole)) {
624 AccountsService.failedFingerprintLogins++;
625 failOperation("not the selected user");
628 console.log("Identified user by fingerprint:", result);
630 loader.item.showFakePassword();
633 root.forcedUnlock = true;
636 if (!d.secureFingerprint) {
637 failOperation("fingerprint reader is locked");
638 } else if (reason !== "ERROR_CANCELED") {
639 AccountsService.failedFingerprintLogins++;
640 failOperation(reason);