on xenial help sign in
Let qtmir know which apps are exempt from the lifecycle management.

This way, it can manage its own wakelocks better (and stop preventing the system from deep sleeping).

commitcb4c07bc01c4292f03e15ce1cd5cb996ddc482fa authorMichael Terry <michael.terry@canonical.com> dateTue 8 Dec 2015, 15:36 (11 years ago) parentf1fcbbbe46cb95
8 files changed+61−20
qml/Stages/PhoneStage.qml+6−4 qml/Stages/TabletStage.qml+6−4 tests/mocks/Unity/Application/ApplicationInfo.cpp+16 tests/mocks/Unity/Application/ApplicationInfo.h+4 tests/mocks/Unity/Application/ApplicationManager.cpp+2 tests/mocks/Unity/Application/ApplicationManager.h+1−1 tests/plugins/Unity/Launcher/launchermodeltest.cpp+2 tests/qmltests/tst_Shell.qml+24−11
qml/Stages/PhoneStage.qml+6−4
@@ -426,14 +426,16 @@ AbstractStage {
426426
427427 readonly property bool isDash: model.appId == "unity8-dash"
428428
429− readonly property bool canSuspend: model.isTouchApp
430− && !isExemptFromLifecycle(model.appId)
429+ Binding {
430+ target: appDelegate.application
431+ property: "exemptFromLifecycle"
432+ value: !model.isTouchApp || isExemptFromLifecycle(model.appId)
433+ }
431434
432435 Binding {
433436 target: appDelegate.application
434437 property: "requestedState"
435− value: !canSuspend
436− || (isDash && root.keepDashRunning)
438+ value: (isDash && root.keepDashRunning)
437439 || (!root.suspended && appDelegate.focus)
438440 ? ApplicationInfoInterface.RequestedRunning
439441 : ApplicationInfoInterface.RequestedSuspended
qml/Stages/TabletStage.qml+6−4
@@ -612,14 +612,16 @@ AbstractStage {
612612
613613 readonly property bool isDash: model.appId == "unity8-dash"
614614
615− readonly property bool canSuspend: model.isTouchApp
616− && !isExemptFromLifecycle(model.appId)
615+ Binding {
616+ target: spreadTile.application
617+ property: "exemptFromLifecycle"
618+ value: !model.isTouchApp || isExemptFromLifecycle(model.appId)
619+ }
617620
618621 Binding {
619622 target: spreadTile.application
620623 property: "requestedState"
621− value: !canSuspend
622− || (isDash && root.keepDashRunning)
624+ value: (isDash && root.keepDashRunning)
623625 || (!root.suspended && (model.appId == priv.mainStageAppId
624626 || model.appId == priv.sideStageAppId))
625627 ? ApplicationInfoInterface.RequestedRunning
tests/mocks/Unity/Application/ApplicationInfo.cpp+16
@@ -42,6 +42,7 @@ ApplicationInfo::ApplicationInfo(const QString &appId, QObject *parent)
4242 , m_rotatesWindowContents(false)
4343 , m_requestedState(RequestedRunning)
4444 , m_isTouchApp(true)
45+ , m_exemptFromLifecycle(false)
4546 , m_manualSurfaceCreation(false)
4647{
4748}
@@ -60,6 +61,7 @@ ApplicationInfo::ApplicationInfo(QObject *parent)
6061 , m_rotatesWindowContents(false)
6162 , m_requestedState(RequestedRunning)
6263 , m_isTouchApp(true)
64+ , m_exemptFromLifecycle(false)
6365 , m_manualSurfaceCreation(false)
6466{
6567}
@@ -263,3 +265,17 @@ void ApplicationInfo::onSessionSurfaceAdded(MirSurface* surface)
263265 }
264266 }
265267}
268+
269+bool ApplicationInfo::exemptFromLifecycle() const
270+{
271+ return m_exemptFromLifecycle;
272+}
273+
274+void ApplicationInfo::setExemptFromLifecycle(bool exemptFromLifecycle)
275+{
276+ if (m_exemptFromLifecycle != exemptFromLifecycle)
277+ {
278+ m_exemptFromLifecycle = exemptFromLifecycle;
279+ Q_EMIT exemptFromLifecycleChanged(m_exemptFromLifecycle);
280+ }
281+}
tests/mocks/Unity/Application/ApplicationInfo.h+4
@@ -92,6 +92,9 @@ public:
9292 bool isTouchApp() const override;
9393 void setIsTouchApp(bool isTouchApp); // only in mock
9494
95+ bool exemptFromLifecycle() const override;
96+ void setExemptFromLifecycle(bool) override;
97+
9598public:
9699 void setSession(Session* session);
97100 Session* session() const { return m_session; }
@@ -125,6 +128,7 @@ private:
125128 bool m_rotatesWindowContents;
126129 RequestedState m_requestedState;
127130 bool m_isTouchApp;
131+ bool m_exemptFromLifecycle;
128132
129133 bool m_manualSurfaceCreation;
130134};
tests/mocks/Unity/Application/ApplicationManager.cpp+2
@@ -107,6 +107,8 @@ QVariant ApplicationManager::data(const QModelIndex& index, int role) const {
107107 return app->focused();
108108 case RoleIsTouchApp:
109109 return app->isTouchApp();
110+ case RoleExemptFromLifecycle:
111+ return app->exemptFromLifecycle();
110112 case RoleSession:
111113 return QVariant::fromValue(app->session());
112114 case RoleFullscreen:
tests/mocks/Unity/Application/ApplicationManager.h+1−1
@@ -43,7 +43,7 @@ class ApplicationManager : public ApplicationManagerInterface {
4343 static ApplicationManager *singleton();
4444
4545 enum MoreRoles {
46− RoleSession = RoleIsTouchApp+1,
46+ RoleSession = RoleExemptFromLifecycle+1,
4747 RoleFullscreen,
4848 };
4949 enum Flag {
tests/plugins/Unity/Launcher/launchermodeltest.cpp+2
@@ -59,6 +59,8 @@ public:
5959 Qt::ScreenOrientations supportedOrientations() const override { return Qt::PortraitOrientation; }
6060 bool rotatesWindowContents() const override { return false; }
6161 bool isTouchApp() const override { return true; }
62+ bool exemptFromLifecycle() const override { return false; }
63+ void setExemptFromLifecycle(bool) override {}
6264
6365 // Methods used for mocking (not in the interface)
6466 void setFocused(bool focused) { m_focused = focused; Q_EMIT focusedChanged(focused); }
tests/qmltests/tst_Shell.qml+24−11
@@ -1857,21 +1857,28 @@ Rectangle {
18571857 loadShell(data.formFactor);
18581858 shell.usageScenario = data.usageScenario;
18591859
1860+ // Add two main stage apps, the second in order to suspend the first.
1861+ // LibreOffice has isTouchApp set to false by our mocks.
18601862 var app1 = ApplicationManager.startApplication("libreoffice");
18611863 waitUntilAppWindowIsFullyLoaded(app1);
1862− var app2 = ApplicationManager.startApplication("dialer-app");
1864+ var app2 = ApplicationManager.startApplication("gallery-app");
18631865 waitUntilAppWindowIsFullyLoaded(app2);
18641866
1865− // Make sure app1 is unfocused but still running
1866− compare(app1.session.lastSurface.activeFocus, false);
1867− compare(app1.isTouchApp, false); // sanity check our mock, which sets this for us
1868− compare(app1.requestedState, ApplicationInfoInterface.RequestedRunning);
1867+ // Sanity checking
1868+ compare(app1.stage, ApplicationInfoInterface.MainStage);
1869+ compare(app2.stage, ApplicationInfoInterface.MainStage);
1870+ verify(!app1.isTouchApp);
1871+ verify(!app1.session.lastSurface.activeFocus);
1872+
1873+ // Make sure app1 is exempt with a requested suspend
1874+ verify(app1.exemptFromLifecycle);
1875+ compare(app1.requestedState, ApplicationInfoInterface.RequestedSuspended);
18691876 }
18701877
18711878 function test_lifecyclePolicyExemption_data() {
18721879 return [
1873− {tag: "phone", formFactor: "phone", usageScenario: "phone", suspendsApps: true},
1874− {tag: "tablet", formFactor: "tablet", usageScenario: "tablet", suspendsApps: true}
1880+ {tag: "phone", formFactor: "phone", usageScenario: "phone"},
1881+ {tag: "tablet", formFactor: "tablet", usageScenario: "tablet"}
18751882 ]
18761883 }
18771884
@@ -1881,14 +1888,20 @@ Rectangle {
18811888
18821889 GSettingsController.setLifecycleExemptAppids(["webbrowser-app"]);
18831890
1891+ // Add two main stage apps, the second in order to suspend the first
18841892 var app1 = ApplicationManager.startApplication("webbrowser-app");
18851893 waitUntilAppWindowIsFullyLoaded(app1);
1886− var app2 = ApplicationManager.startApplication("dialer-app");
1894+ var app2 = ApplicationManager.startApplication("gallery-app");
18871895 waitUntilAppWindowIsFullyLoaded(app2);
18881896
1889− // Make sure app1 is unfocused but still running
1890− compare(app1.session.lastSurface.activeFocus, false);
1891− compare(app1.requestedState, ApplicationInfoInterface.RequestedRunning);
1897+ // Sanity checking
1898+ compare(app1.stage, ApplicationInfoInterface.MainStage);
1899+ compare(app2.stage, ApplicationInfoInterface.MainStage);
1900+ verify(!app1.session.lastSurface.activeFocus);
1901+
1902+ // Make sure app1 is exempt with a requested suspend
1903+ verify(app1.exemptFromLifecycle);
1904+ compare(app1.requestedState, ApplicationInfoInterface.RequestedSuspended);
18921905 }
18931906
18941907 function test_switchToStagedForcesLegacyAppClosing_data() {