Merge lp:~gerboland/qtmir/url-dispatcher-respawns-so-appMan-should-not into lp:qtmir

Proposed by Gerry Boland
Status: Rejected
Rejected by: Gerry Boland
Proposed branch: lp:~gerboland/qtmir/url-dispatcher-respawns-so-appMan-should-not
Merge into: lp:qtmir
Diff against target: 73 lines (+36/-4)
2 files modified
src/modules/Unity/Application/application_manager.cpp (+13/-4)
tests/modules/ApplicationManager/application_manager_test.cpp (+23/-0)
To merge this branch: bzr merge lp:~gerboland/qtmir/url-dispatcher-respawns-so-appMan-should-not
Reviewer Review Type Date Requested Status
Mir development team Pending
Review via email: mp+238319@code.launchpad.net

Commit message

AppMan: url-dispatcher launches focusRequested apps itself, so ensure AppMan sets the app state appropriately

Let app1 be lifecycle killed, but still in the app list. app2 uses url-dispatcher to focus app1. This causes url-dispatcher to launch a new instance of app1, and then notify AppMan to request focus for app1.

However it is possible if shell acted upon the requestFocus signal, and called focusApplication(app1) - before the onProcessStarting(app1) notification from upstart was received, AppMan would respawn app1 itself. So 2 instances of app1 would be executing, and later AppMan would then reject one of them.

Description of the change

AppMan: url-dispatcher launches focusRequested apps itself, so ensure AppMan sets the app state appropriately

Let app1 be lifecycle killed, but still in the app list. app2 uses url-dispatcher to focus app1. This causes url-dispatcher to launch a new instance of app1, and then notify AppMan to request focus for app1.

However it is possible if shell acted upon the requestFocus signal, and called focusApplication(app1) - before the onProcessStarting(app1) notification from upstart was received, AppMan would respawn app1 itself. So 2 instances of app1 would be executing, and later AppMan would then reject one of them.

To post a comment you must log in.
275. By Gerry Boland

Update comments to explain new situation

276. By Gerry Boland

Merge trunk

277. By Gerry Boland

Remove unnecessary include

Unmerged revisions

277. By Gerry Boland

Remove unnecessary include

276. By Gerry Boland

Merge trunk

275. By Gerry Boland

Update comments to explain new situation

274. By Gerry Boland

AppMan: url-dispatcher launches focusRequested apps itself, so ensure AppMan sets the app state appropriately

Let app1 be lifecycle killed, but still in the app list. app2 uses url-dispatcher to focus app1. This causes url-dispatcher to launch a new instance of app1, and then notify AppMan to request focus for app1.

However it is possible if shell acted upon the requestFocus signal, and called focusApplication(app1) - before the onProcessStarting(app1) notification from upstart was received, AppMan would respawn app1 itself. So 2 instances of app1 would be executing, and later AppMan would then reject one of them.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/modules/Unity/Application/application_manager.cpp'
2--- src/modules/Unity/Application/application_manager.cpp 2014-10-30 11:55:15 +0000
3+++ src/modules/Unity/Application/application_manager.cpp 2014-12-10 12:46:03 +0000
4@@ -280,6 +280,13 @@
5 return false;
6 }
7
8+ // url-dispatcher can relaunch apps which have been OOM-killed - AppMan must accept the newly spawned
9+ // application and focus it immediately (as user expects app to still be running).
10+ if (application->state() == Application::Stopped) {
11+ qCDebug(QTMIR_APPLICATIONS) << "Stopped application appId=" << appId << "was resumed by url-dispatcher";
12+ application->setState(Application::Starting);
13+ }
14+
15 Q_EMIT focusRequested(appId);
16 return true;
17 }
18@@ -531,15 +538,17 @@
19 Q_EMIT focusRequested(appId);
20 }
21 else {
22- // url-dispatcher can relaunch apps which have been OOM-killed - AppMan must accept the newly spawned
23- // application and focus it immediately (as user expects app to still be running).
24+ // It is highly unlikely an app whose process was killed (usually by OOM) could be respawned by means other
25+ // than url-dispatcher or AppMan itself - maybe an app developer is testing lifecycle stuff?? In any case,
26+ // let's just be agreeable, accept the newly spawned process and focus it immediately.
27 if (application->state() == Application::Stopped) {
28- qCDebug(QTMIR_APPLICATIONS) << "Stopped application appId=" << appId << "is being resumed externally";
29+ qCDebug(QTMIR_APPLICATIONS) << "Stopped application appId=" << appId
30+ << "has been resumed in an unexpected way";
31 application->setState(Application::Starting);
32 Q_EMIT focusRequested(appId);
33 } else {
34 qCDebug(QTMIR_APPLICATIONS) << "ApplicationManager::onProcessStarting application already found with appId"
35- << appId;
36+ << appId << "- is probably ok";
37 }
38 }
39 }
40
41=== modified file 'tests/modules/ApplicationManager/application_manager_test.cpp'
42--- tests/modules/ApplicationManager/application_manager_test.cpp 2014-11-13 16:26:03 +0000
43+++ tests/modules/ApplicationManager/application_manager_test.cpp 2014-12-10 12:46:03 +0000
44@@ -2036,6 +2036,29 @@
45 }
46
47 /*
48+ * Test if url-dispatcher requests focus for an app which was lifecycle killed, then
49+ * AppMan assumes that url-dispatcher respawned the app (and AppMan doesn't try to respawn
50+ * the app itself)
51+ */
52+TEST_F(ApplicationManagerTests,urlDispatcherRespawnsStoppedAppsSoWeDoNotHaveTo)
53+{
54+ using namespace ::testing;
55+ quint64 procId1 = 5551;
56+ const QString appId("testAppId");
57+
58+ auto app = startApplication(procId1, appId);
59+ app->setState(Application::Stopped);
60+
61+ EXPECT_CALL(appController, startApplicationWithAppIdAndArgs(appId, _))
62+ .Times(0)
63+ .WillOnce(Return(true));
64+
65+ applicationManager.requestFocusApplication(appId);
66+
67+ EXPECT_EQ(app->state(), Application::Starting);
68+}
69+
70+/*
71 * Test that screenshotting callback works cross thread.
72 */
73 TEST_F(ApplicationManagerTests, threadedScreenshot)

Subscribers

People subscribed via source and target branches