on xenial help sign in
Merge pull request #166 from ubports/xenial_-_edge_-_ensureLock

Refactor handling of mainApp changes

commit7e937b90ad33e624afc391a67203be9af1880e9f authorRodney <6557070+dobey@users.noreply.github.com> dateSat 13 Jul 2019, 21:25 (7 years ago) parent22e398a7575e00
3 files changed+71−34
qml/Launcher/Launcher.qml+9 qml/Shell.qml+31−29 tests/qmltests/tst_ShellWithPin.qml+31−5
qml/Launcher/Launcher.qml+9
@@ -117,6 +117,15 @@ FocusScope {
117117 hint();
118118 }
119119
120+ // Switches the Launcher to the visible state, but only if it's not already
121+ // opened.
122+ // Prevents closing the Drawer when trying to show the Launcher.
123+ function show() {
124+ if (state === "" || state === "visibleTemporary") {
125+ switchToNextState("visible");
126+ }
127+ }
128+
120129 function hide(flags) {
121130 if ((flags & ignoreHideIfMouseOverLauncher) && Utils.Functions.itemUnderMouse(panel)) {
122131 if (state == "drawer") {
qml/Shell.qml+31−29
@@ -96,9 +96,7 @@ StyledItem {
9696 readonly property var mainApp: stage.mainApp
9797
9898 onMainAppChanged: {
99− if (mainApp) {
100− _onMainAppChanged(mainApp.appId);
101− }
99+ _onMainAppChanged((mainApp ? mainApp.appId : ""));
102100 }
103101 Connections {
104102 target: ApplicationManager
@@ -108,24 +106,40 @@ StyledItem {
108106 }
109107 }
110108 }
109+
110+ // Calls attention back to the most important thing that's been focused
111+ // (ex: phone calls go over Wizard, app focuses go over indicators, greeter
112+ // goes over everything if it is locked)
113+ // Must be called whenever app focus changes occur, even if the focus change
114+ // is "nothing is focused". In that case, call with appId = ""
111115 function _onMainAppChanged(appId) {
112− if (wizard.active && appId != "") {
113− // If this happens on first boot, we may be in the
114− // wizard while receiving a call. But a call is more
115− // important than the wizard so just bail out of it.
116− wizard.hide();
117− }
118116
119− if (appId === "dialer-app" && callManager.hasCalls && greeter.locked) {
120− // If we are in the middle of a call, make dialer lockedApp and show it.
121− // This can happen if user backs out of dialer back to greeter, then
122− // launches dialer again.
123− greeter.lockedApp = appId;
117+ if (appId !== "") {
118+ if (wizard.active) {
119+ // If this happens on first boot, we may be in the
120+ // wizard while receiving a call. A call is more
121+ // important than the wizard so just bail out of it.
122+ wizard.hide();
123+ }
124+
125+ if (appId === "dialer-app" && callManager.hasCalls && greeter.locked) {
126+ // If we are in the middle of a call, make dialer lockedApp. The
127+ // Greeter will show it when it's notified of the focus.
128+ // This can happen if user backs out of dialer back to greeter, then
129+ // launches dialer again.
130+ greeter.lockedApp = appId;
131+ }
132+
133+ panel.indicators.hide();
134+ launcher.hide(launcher.ignoreHideIfMouseOverLauncher);
135+ } else if (topLevelSurfaceList.count === 0 && !greeter.active && !wizard.active) {
136+ // Show the Launcher when there are no apps running
137+ stage.closeSpread();
138+ launcher.show();
124139 }
125− greeter.notifyAppFocusRequested(appId);
126140
127− panel.indicators.hide();
128− launcher.hide(launcher.ignoreHideIfMouseOverLauncher);
141+ // *Always* make sure the greeter knows that the focused app changed
142+ greeter.notifyAppFocusRequested(appId);
129143 }
130144
131145 // For autopilot consumption
@@ -393,18 +407,6 @@ StyledItem {
393407 }
394408 }
395409 }
396−
397− // Show the launcher in case there are no running apps
398− Connections {
399− target: topLevelSurfaceList
400− onCountChanged: {
401− if (topLevelSurfaceList.count > 0)
402− return
403−
404− stage.closeSpread()
405− launcher.switchToNextState("visible")
406− }
407− }
408410 }
409411
410412 Component {
tests/qmltests/tst_ShellWithPin.qml+31−5
@@ -140,8 +140,6 @@ Item {
140140 stage = findChild(shell, "stage");
141141 topLevelSurfaceList = findInvisibleChild(shell, "topLevelSurfaceList");
142142 verify(topLevelSurfaceList);
143−
144− startApplication("unity8-dash");
145143 }
146144
147145 function cleanup() {
@@ -288,7 +286,7 @@ Item {
288286 var greeter = findChild(shell, "greeter");
289287 var emergencyButton = findChild(greeter, "emergencyCallLabel");
290288 tap(emergencyButton)
291− tryCompare(topLevelSurfaceList, "count", 2);
289+ tryCompare(topLevelSurfaceList, "count", 1);
292290 waitUntilAppWindowIsFullyLoaded(dialerSurfaceId);
293291
294292 tryCompare(greeter, "shown", false);
@@ -416,6 +414,8 @@ Item {
416414 // - Should be back in normal dialer
417415 // (we've had a bug where we locked screen in this case)
418416
417+ startApplication("gallery-app");
418+
419419 var greeter = findChild(shell, "greeter");
420420 var panel = findChild(shell, "panel");
421421
@@ -427,8 +427,8 @@ Item {
427427 tryCompare(ApplicationManager, "focusedApplicationId", "dialer-app");
428428 callManager.foregroundCall = phoneCall;
429429
430− ApplicationManager.requestFocusApplication("unity8-dash");
431− tryCompare(ApplicationManager, "focusedApplicationId", "unity8-dash");
430+ ApplicationManager.requestFocusApplication("gallery-app");
431+ tryCompare(ApplicationManager, "focusedApplicationId", "gallery-app");
432432 var callHint = findChild(panel, "callHint");
433433 tryCompare(callHint, "visible", true);
434434 wait(10000)
@@ -528,5 +528,31 @@ Item {
528528
529529 tryCompare(launcher, "state", "drawer");
530530 }
531+
532+ /* Regression test, https://github.com/ubports/ubuntu-touch/issues/1178
533+ When all apps closed while the Greeter was shown, the Launcher would
534+ appear over the Greeter. This was caused by logic that would normally
535+ cause the Launcher to be shown over the empty Background. */
536+ function test_launcherShowCulledWhenLocked() {
537+ var launcher = findChild(shell, "launcher");
538+
539+ // Ensure the Launcher is sane
540+ touchFlick(shell, units.gu(.5), shell.height / 2, units.gu(10), shell.height / 2);
541+ tryCompare(launcher, "state", "visible");
542+ tap(shell);
543+ tryCompare(launcher, "state", "");
544+
545+ console.log("I AM LOGGING NOW");
546+ console.log(ApplicationManager.count);
547+
548+ // Start and kill an app to cause the Launcher to be triggered (in error state)
549+ startApplication("gallery-app");
550+ tryCompare(ApplicationManager, "count", 1);
551+ ApplicationManager.stopApplication("gallery-app");
552+ tryCompare(ApplicationManager, "count", 0);
553+
554+ // Make sure that the error state didn't happen
555+ tryCompare(launcher, "state", "");
556+ }
531557 }
532558}