Merge lp:~dandrader/qtmir/focusInfoSurfaceId into lp:qtmir

Proposed by Daniel d'Andrada
Status: Merged
Approved by: Michael Terry
Approved revision: no longer in the source branch.
Merged at revision: 555
Proposed branch: lp:~dandrader/qtmir/focusInfoSurfaceId
Merge into: lp:qtmir
Prerequisite: lp:~unity-team/qtmir/persistent_surface_id
Diff against target: 89 lines (+47/-2)
2 files modified
src/modules/Unity/Application/dbusfocusinfo.cpp (+35/-0)
src/modules/Unity/Application/dbusfocusinfo.h (+12/-2)
To merge this branch: bzr merge lp:~dandrader/qtmir/focusInfoSurfaceId
Reviewer Review Type Date Requested Status
Michael Terry (community) Approve
Unity8 CI Bot (community) continuous-integration Needs Fixing
Gerry Boland (community) Needs Fixing
Review via email: mp+303737@code.launchpad.net

Commit message

DBusFocusInfo: added isSurfaceFocused(serializedId)

Description of the change

* Are there any related MPs required for this MP to build/function as expected? Please list.
https://code.launchpad.net/~unity-team/unity-api/persistent_surface_id/+merge/303552
https://code.launchpad.net/~unity-team/unity8/persistent_surface_id/+merge/303600

For testing you also need:
https://code.launchpad.net/~dandrader/qtubuntu/content-hub-clipboard/+merge/301272
https://code.launchpad.net/~ken-vandine/content-hub/pasteboard/+merge/296352

* Did you perform an exploratory manual test run of your code change and any related functionality?
Yes

* If you changed the packaging (debian), did you subscribe the ubuntu-unity team to this MP?
N/A

To post a comment you must log in.
Revision history for this message
Unity8 CI Bot (unity8-ci-bot) wrote :

FAILED: Continuous integration, rev:550
https://unity8-jenkins.ubuntu.com/job/lp-qtmir-ci/344/
Executed test runs:
    FAILURE: https://unity8-jenkins.ubuntu.com/job/build/2646/console
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-0-fetch/2674
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/2548
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial+overlay/2548
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-1-sourcepkg/release=yakkety/2548
    FAILURE: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=vivid+overlay/2542/console
    FAILURE: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/2542/console
    FAILURE: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=yakkety/2542/console
    FAILURE: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=vivid+overlay/2542/console
    FAILURE: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/2542/console
    FAILURE: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=yakkety/2542/console
    FAILURE: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=vivid+overlay/2542/console
    FAILURE: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/2542/console
    FAILURE: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=yakkety/2542/console

Click here to trigger a rebuild:
https://unity8-jenkins.ubuntu.com/job/lp-qtmir-ci/344/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Gerry Boland (gerboland) wrote :

+ Enables other processes to check who's the curretly focused application or surface,
typo "currently" and s/who's/what is/

review: Needs Fixing
Revision history for this message
Daniel d'Andrada (dandrader) wrote :

On 24/08/2016 06:48, Gerry Boland wrote:
> Review: Needs Fixing
>
> + Enables other processes to check who's the curretly focused application or surface,
> typo "currently" and s/who's/what is/
>
>
Fixed.

Revision history for this message
Unity8 CI Bot (unity8-ci-bot) wrote :

FAILED: Continuous integration, rev:551
https://unity8-jenkins.ubuntu.com/job/lp-qtmir-ci/345/
Executed test runs:
    FAILURE: https://unity8-jenkins.ubuntu.com/job/build/2652/console
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-0-fetch/2680
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/2553
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial+overlay/2553
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-1-sourcepkg/release=yakkety/2553
    FAILURE: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=vivid+overlay/2547/console
    FAILURE: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/2547/console
    FAILURE: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=yakkety/2547/console
    FAILURE: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=vivid+overlay/2547/console
    FAILURE: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/2547/console
    FAILURE: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=yakkety/2547/console
    FAILURE: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=vivid+overlay/2547/console
    FAILURE: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/2547/console
    FAILURE: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=yakkety/2547/console

Click here to trigger a rebuild:
https://unity8-jenkins.ubuntu.com/job/lp-qtmir-ci/345/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Gerry Boland (gerboland) wrote :

Code looks ok, how can I test?

Revision history for this message
Daniel d'Andrada (dandrader) wrote :

> Code looks ok, how can I test?

- Apply this patch http://pastebin.ubuntu.com/23085097/ so that you can conveniently see the persistent surface ids in unity8.log

- Launch an app and copy its surface id by looking into its log entry which should look like this:

qtmir.surfaces: MirSurface[0x204a090,"webbrowser-app"]::MirSurface("1a711701-97a1-417d-b867-586cbb2d8477")

- Call isSurfaceFocused over dbus and check the result when the launched app is focused and when it's not.

$ gdbus call --session --dest com.canonical.Unity.FocusInfo --object-path /com/canonical/Unity/FocusInfo --method com.canonical.Unity.FocusInfo.isSurfaceFocused "1a711701-97a1-417d-b867-586cbb2d8477"

Revision history for this message
Tyler Hicks (tyhicks) wrote :

Thank you for implementing this! From a security standpoint, it is much better than the PID based API.

550. By Daniel d'Andrada

DBusFocusInfo.isPidFocused: search sessions recursively (LP: #1612166)

Approved by: Gerry Boland, Unity8 CI Bot

551. By MichaƂ Sawicz

Revert r538 that's causing a unity8 crash when launching emergency dialer over greeter (LP: #1616842)

Approved by: Unity8 CI Bot

552. By CI Train Bot Account

Releasing 0.4.8+16.10.20160826.1-0ubuntu1

Revision history for this message
Michael Terry (mterry) wrote :

Gerry liked the code. Code seems fine to me too. I tested this with silo 37 and it worked fine (was able to confirm dbus call worked with command line gdbus).

review: Approve
553. By Daniel d'Andrada

Merge lp:~unity-team/qtmir/persistent_surface_id

554. By Daniel d'Andrada

DBusFocusInfo: added isSurfaceFocused(serializedId)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/modules/Unity/Application/dbusfocusinfo.cpp'
2--- src/modules/Unity/Application/dbusfocusinfo.cpp 2016-08-25 15:27:47 +0000
3+++ src/modules/Unity/Application/dbusfocusinfo.cpp 2016-08-30 12:31:05 +0000
4@@ -18,6 +18,9 @@
5
6 // local
7 #include "cgmanager.h"
8+#include "mirsurfacelistmodel.h"
9+#include "mirsurfaceinterface.h"
10+#include "session_interface.h"
11
12 // QPA mirserver
13 #include <logging.h>
14@@ -93,3 +96,35 @@
15 });
16 return sessionWithPid;
17 }
18+
19+bool DBusFocusInfo::isSurfaceFocused(const QString &serializedId)
20+{
21+ MirSurfaceInterface *qmlSurface = findQmlSurface(serializedId);
22+ bool result = qmlSurface ? qmlSurface->activeFocus() : false;
23+ qCDebug(QTMIR_DBUS).nospace() << "DBusFocusInfo: isSurfaceFocused("<<serializedId<<") -> " << result;
24+ return result;
25+}
26+
27+MirSurfaceInterface *DBusFocusInfo::findQmlSurface(const QString &serializedId)
28+{
29+ for (Application* application : m_applications) {
30+ auto session = application->session();
31+
32+ auto surfaceList = static_cast<MirSurfaceListModel*>(session->surfaceList());
33+ for (int i = 0; i < surfaceList->count(); ++i) {
34+ auto qmlSurface = static_cast<MirSurfaceInterface*>(surfaceList->get(i));
35+ if (qmlSurface->persistentId() == serializedId) {
36+ return qmlSurface;
37+ }
38+ }
39+
40+ surfaceList = static_cast<MirSurfaceListModel*>(session->promptSurfaceList());
41+ for (int i = 0; i < surfaceList->count(); ++i) {
42+ auto qmlSurface = static_cast<MirSurfaceInterface*>(surfaceList->get(i));
43+ if (qmlSurface->persistentId() == serializedId) {
44+ return qmlSurface;
45+ }
46+ }
47+ }
48+ return nullptr;
49+}
50
51=== modified file 'src/modules/Unity/Application/dbusfocusinfo.h'
52--- src/modules/Unity/Application/dbusfocusinfo.h 2016-08-25 15:10:24 +0000
53+++ src/modules/Unity/Application/dbusfocusinfo.h 2016-08-30 12:31:05 +0000
54@@ -22,10 +22,11 @@
55 namespace qtmir {
56
57 class CGManager;
58+class MirSurfaceInterface;
59
60 /*
61- FIXME: This is a hack to provide OSK with needed info for avoiding input snooping.
62- Remove when possible
63+ Enables other processes to check what is the currently focused application or surface,
64+ normally for security purposes.
65 */
66 class DBusFocusInfo : public QObject
67 {
68@@ -39,13 +40,22 @@
69
70 /*
71 Returns true if the application with the given PID has input focus
72+
73+ FIXME: Identifying an app through its PID is deemed racy.
74+ isSurfaceFocused() is the preferred method.
75 */
76 Q_SCRIPTABLE bool isPidFocused(unsigned int pid);
77
78+ /*
79+ Returns true if the surface with the given id has input focus
80+ */
81+ Q_SCRIPTABLE bool isSurfaceFocused(const QString &surfaceId);
82+
83 private:
84 QSet<pid_t> fetchAssociatedPids(pid_t pid);
85 SessionInterface* findSessionWithPid(const QSet<pid_t> &pidSet);
86 SessionInterface* findSessionWithPid(SessionInterface* session, const QSet<pid_t> &pidSet);
87+ MirSurfaceInterface *findQmlSurface(const QString &serializedId);
88
89 const QList<Application*> &m_applications;
90

Subscribers

People subscribed via source and target branches