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: 3 // number of failed fingerprint logins
68 readonly property bool animating: loader.item ? loader.item.animating : false
70 property rect inputMethodRect
72 property bool hasKeyboard: false
75 signal sessionStarted()
76 signal emergencyCall()
78 function forceShow() {
80 d.isLockscreen = true;
85 loader.item.forceShow();
87 // Normally loader.onLoaded will select a user, but if we're
88 // already shown, do it manually.
89 d.selectUser(d.currentIndex);
92 // Even though we may already be shown, we want to call show() for its
93 // possible side effects, like hiding indicators and such.
95 // We re-check forcedUnlock here, because selectUser above might
96 // process events during authentication, and a request to unlock could
97 // have come in in the meantime.
103 function notifyAppFocusRequested(appId) {
109 if (appId === lockedApp) {
110 hide(); // show locked app
113 d.startUnlock(false /* toTheRight */);
116 d.startUnlock(false /* toTheRight */);
120 // Notify that the user has explicitly requested an app
121 function notifyUserRequestedApp() {
126 // A hint that we're about to focus an app. This way we can look
127 // a little more responsive, rather than waiting for the above
128 // notifyAppFocusRequested call. We also need this in case we have a locked
129 // app, in order to show lockscreen instead of new app.
130 d.startUnlock(false /* toTheRight */);
133 // This is a just a glorified notifyUserRequestedApp(), but it does one
134 // other thing: it hides any cover pages to the RIGHT, because the user
135 // just came from a launcher drag starting on the left.
136 // It also returns a boolean value, indicating whether there was a visual
137 // change or not (the shell only wants to hide the launcher if there was
139 function notifyShowingDashFromDrag() {
144 return d.startUnlock(true /* toTheRight */);
147 function sessionToStart() {
148 for (var i = 0; i < LightDMService.sessions.count; i++) {
149 var session = LightDMService.sessions.data(i,
150 LightDMService.sessionRoles.KeyRole);
151 if (loader.item.sessionToStart === session) {
156 return LightDMService.greeter.defaultSession;
162 readonly property bool multiUser: LightDMService.users.count > 1
163 readonly property int selectUserIndex: d.getUserIndex(LightDMService.greeter.selectUser)
164 property int currentIndex: Math.max(selectUserIndex, 0)
165 readonly property bool waiting: LightDMService.prompts.count == 0 && !root.forcedUnlock
166 property bool isLockscreen // true when we are locking an active session, rather than first user login
167 readonly property bool secureFingerprint: isLockscreen &&
168 AccountsService.failedFingerprintLogins <
169 root.failedFingerprintLoginsDisableAttempts
170 readonly property bool alphanumeric: AccountsService.passwordDisplayHint === AccountsService.Keyboard
172 // We want 'launcherOffset' to animate down to zero. But not to animate
173 // while being dragged. So ideally we change this only when the user
174 // lets go and launcherOffset drops to zero. But we need to wait for
175 // the behavior to be enabled first. So we cache the last known good
176 // launcherOffset value to cover us during that brief gap between
177 // release and the behavior turning on.
178 property real lastKnownPositiveOffset // set in a launcherOffsetChanged below
179 property real launcherOffsetProxy: (shown && !launcherOffsetProxyBehavior.enabled) ? lastKnownPositiveOffset : 0
180 Behavior on launcherOffsetProxy {
181 id: launcherOffsetProxyBehavior
182 enabled: launcherOffset === 0
183 LomiriNumberAnimation {}
186 function getUserIndex(username) {
190 // Find index for requested user, if it exists
191 for (var i = 0; i < LightDMService.users.count; i++) {
192 if (username === LightDMService.users.data(i, LightDMService.userRoles.NameRole)) {
200 function selectUser(index) {
201 if (index < 0 || index >= LightDMService.users.count)
203 currentIndex = index;
204 var user = LightDMService.users.data(index, LightDMService.userRoles.NameRole);
205 AccountsService.user = user;
206 LauncherModel.setUser(user);
207 LightDMService.greeter.authenticate(user); // always resets auth state
210 function hideView() {
212 loader.item.enabled = false; // drop OSK and prevent interaction
218 if (LightDMService.greeter.startSessionSync(root.sessionToStart())) {
221 } else if (loader.item) {
222 loader.item.notifyAuthenticationFailed();
226 function startUnlock(toTheRight) {
228 return loader.item.tryToUnlock(toTheRight);
234 function checkForcedUnlock(hideNow) {
235 if (forcedUnlock && shown) {
238 ShellNotifier.greeter.hide(true); // skip hide animation
243 function showFingerprintMessage(msg) {
244 d.selectUser(d.currentIndex);
245 LightDMService.prompts.prepend(msg, LightDMService.prompts.Error);
247 loader.item.showErrorMessage(msg);
248 loader.item.notifyAuthenticationFailed();
253 onLauncherOffsetChanged: {
254 if (launcherOffset > 0) {
255 d.lastKnownPositiveOffset = launcherOffset;
259 onForcedUnlockChanged: d.checkForcedUnlock(false /* hideNow */)
260 Component.onCompleted: d.checkForcedUnlock(true /* hideNow */)
264 AccountsService.failedLogins = 0;
265 AccountsService.failedFingerprintLogins = 0;
267 // Stop delay timer if they logged in with fingerprint
268 forcedDelayTimer.stop();
269 forcedDelayTimer.delayMinutes = 0;
281 schema.id: "com.lomiri.Shell.Greeter"
287 // We use a short interval and check against the system wall clock
288 // because we have to consider the case that the system is suspended
289 // for a few minutes. When we wake up, we want to quickly be correct.
292 property var delayTarget
293 property int delayMinutes
295 function forceDelay() {
296 // Store the beginning time for a lockout in GSettings, so that
297 // we still lock the user out if they reboot. And we store
298 // starting time rather than end-time or how-long because:
299 // - If storing end-time and on boot we have a problem with NTP,
300 // we might get locked out for a lot longer than we thought.
301 // - If storing how-long, and user turns their phone off for an
302 // hour rather than wait, they wouldn't expect to still be locked
304 // - A malicious actor could manipulate either of the above
305 // settings to keep the user out longer. But by storing
306 // start-time, we never make the user wait longer than the full
308 greeterSettings.lockedOutTime = new Date().getTime();
309 checkForForcedDelay();
313 var diff = delayTarget - new Date();
315 delayMinutes = Math.ceil(diff / 60000);
322 function checkForForcedDelay() {
323 if (greeterSettings.lockedOutTime === 0) {
327 var now = new Date();
328 delayTarget = new Date(greeterSettings.lockedOutTime + failedLoginsDelayMinutes * 60000);
330 // If tooEarly is true, something went very wrong. Bug or NTP
331 // misconfiguration maybe?
332 var tooEarly = now.getTime() < greeterSettings.lockedOutTime;
333 var tooLate = now >= delayTarget;
335 // Compare stored time to system time. If a malicious actor is
336 // able to manipulate time to avoid our lockout, they already have
337 // enough access to cause damage. So we choose to trust this check.
338 if (tooEarly || tooLate) {
346 Component.onCompleted: checkForForcedDelay()
350 // Nothing should leak to items behind the greeter
351 MouseArea { anchors.fill: parent; hoverEnabled: true }
359 active: root.required
360 source: root.viewSource.toString() ? root.viewSource :
361 (d.multiUser || root.tabletMode) ? "WideView.qml" : "NarrowView.qml"
365 item.forceActiveFocus();
366 d.selectUser(d.currentIndex);
367 LightDMService.infographic.readyForDataChange();
377 LightDMService.greeter.respond(response);
382 onTease: root.tease()
383 onEmergencyCall: root.emergencyCall()
385 if (!loader.item.required) {
386 ShellNotifier.greeter.hide(false);
393 property: "panelHeight"
394 value: root.panelHeight
399 property: "launcherOffset"
400 value: d.launcherOffsetProxy
405 property: "dragHandleLeftMargin"
406 value: root.dragHandleLeftMargin
411 property: "delayMinutes"
412 value: forcedDelayTimer.delayMinutes
417 property: "background"
418 value: root.background
423 property: "backgroundSourceSize"
424 value: root.backgroundSourceSize
429 property: "hasCustomBackground"
430 value: root.hasCustomBackground
447 property: "alphanumeric"
448 value: d.alphanumeric
453 property: "currentIndex"
454 value: d.currentIndex
459 property: "userModel"
460 value: LightDMService.users
465 property: "infographicModel"
466 value: LightDMService.infographic
471 property: "inputMethodRect"
472 value: root.inputMethodRect
477 property: "hasKeyboard"
478 value: root.hasKeyboard
483 target: LightDMService.greeter
485 onShowGreeter: root.forceShow()
486 onHideGreeter: root.forcedUnlock = true
493 loader.item.notifyAuthenticationFailed();
496 AccountsService.failedLogins++;
498 // Check if we should initiate a forced login delay
499 if (failedLoginsDelayAttempts > 0
500 && AccountsService.failedLogins > 0
501 && AccountsService.failedLogins % failedLoginsDelayAttempts == 0) {
502 forcedDelayTimer.forceDelay();
505 d.selectUser(d.currentIndex);
515 onRequestAuthenticationUser: d.selectUser(d.getUserIndex(user))
519 target: ShellNotifier.greeter
522 root.hideNow(); // skip hide animation
530 target: ShellNotifier.greeter
536 target: DBusLomiriSessionService
537 onLockRequested: root.forceShow()
539 root.forcedUnlock = true;
540 ShellNotifier.greeter.hide(true);
545 target: LightDMService.greeter
551 target: LightDMService.infographic
553 value: AccountsService.statsWelcomeScreen ? LightDMService.users.data(d.currentIndex, LightDMService.userRoles.NameRole) : ""
558 onLanguageChanged: LightDMService.infographic.readyForDataChange()
563 objectName: "biometryd"
565 property var operation: null
566 readonly property bool idEnabled: root.active &&
567 root.allowFingerprint &&
568 Powerd.status === Powerd.On &&
569 Biometryd.available &&
570 AccountsService.enableFingerprintIdentification
572 function cancelOperation() {
579 function restartOperation() {
583 var identifier = Biometryd.defaultDevice.identifier;
584 operation = identifier.identifyUser();
585 operation.start(biometryd);
589 function failOperation(reason) {
590 console.log("Failed to identify user by fingerprint:", reason);
592 if (!d.secureFingerprint) {
593 d.startUnlock(false /* toTheRight */); // use normal login instead
595 var msg = d.secureFingerprint ? i18n.tr("Try again") :
596 d.alphanumeric ? i18n.tr("Enter passphrase to unlock") :
597 i18n.tr("Enter passcode to unlock");
598 d.showFingerprintMessage(msg);
601 Component.onCompleted: restartOperation()
602 Component.onDestruction: cancelOperation()
603 onIdEnabledChanged: restartOperation()
606 if (!d.secureFingerprint) {
607 failOperation("fingerprint reader is locked");
610 if (result !== LightDMService.users.data(d.currentIndex, LightDMService.userRoles.UidRole)) {
611 AccountsService.failedFingerprintLogins++;
612 failOperation("not the selected user");
615 console.log("Identified user by fingerprint:", result);
617 loader.item.showFakePassword();
620 root.forcedUnlock = true;
623 if (!d.secureFingerprint) {
624 failOperation("fingerprint reader is locked");
626 AccountsService.failedFingerprintLogins++;
627 failOperation(reason);