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
=== modified file 'src/modules/Unity/Application/dbusfocusinfo.cpp'
--- src/modules/Unity/Application/dbusfocusinfo.cpp 2016-08-25 15:27:47 +0000
+++ src/modules/Unity/Application/dbusfocusinfo.cpp 2016-08-30 12:31:05 +0000
@@ -18,6 +18,9 @@
1818
19// local19// local
20#include "cgmanager.h"20#include "cgmanager.h"
21#include "mirsurfacelistmodel.h"
22#include "mirsurfaceinterface.h"
23#include "session_interface.h"
2124
22// QPA mirserver25// QPA mirserver
23#include <logging.h>26#include <logging.h>
@@ -93,3 +96,35 @@
93 });96 });
94 return sessionWithPid;97 return sessionWithPid;
95}98}
99
100bool DBusFocusInfo::isSurfaceFocused(const QString &serializedId)
101{
102 MirSurfaceInterface *qmlSurface = findQmlSurface(serializedId);
103 bool result = qmlSurface ? qmlSurface->activeFocus() : false;
104 qCDebug(QTMIR_DBUS).nospace() << "DBusFocusInfo: isSurfaceFocused("<<serializedId<<") -> " << result;
105 return result;
106}
107
108MirSurfaceInterface *DBusFocusInfo::findQmlSurface(const QString &serializedId)
109{
110 for (Application* application : m_applications) {
111 auto session = application->session();
112
113 auto surfaceList = static_cast<MirSurfaceListModel*>(session->surfaceList());
114 for (int i = 0; i < surfaceList->count(); ++i) {
115 auto qmlSurface = static_cast<MirSurfaceInterface*>(surfaceList->get(i));
116 if (qmlSurface->persistentId() == serializedId) {
117 return qmlSurface;
118 }
119 }
120
121 surfaceList = static_cast<MirSurfaceListModel*>(session->promptSurfaceList());
122 for (int i = 0; i < surfaceList->count(); ++i) {
123 auto qmlSurface = static_cast<MirSurfaceInterface*>(surfaceList->get(i));
124 if (qmlSurface->persistentId() == serializedId) {
125 return qmlSurface;
126 }
127 }
128 }
129 return nullptr;
130}
96131
=== modified file 'src/modules/Unity/Application/dbusfocusinfo.h'
--- src/modules/Unity/Application/dbusfocusinfo.h 2016-08-25 15:10:24 +0000
+++ src/modules/Unity/Application/dbusfocusinfo.h 2016-08-30 12:31:05 +0000
@@ -22,10 +22,11 @@
22namespace qtmir {22namespace qtmir {
2323
24class CGManager;24class CGManager;
25class MirSurfaceInterface;
2526
26/*27/*
27 FIXME: This is a hack to provide OSK with needed info for avoiding input snooping.28 Enables other processes to check what is the currently focused application or surface,
28 Remove when possible29 normally for security purposes.
29 */30 */
30class DBusFocusInfo : public QObject31class DBusFocusInfo : public QObject
31{32{
@@ -39,13 +40,22 @@
3940
40 /*41 /*
41 Returns true if the application with the given PID has input focus42 Returns true if the application with the given PID has input focus
43
44 FIXME: Identifying an app through its PID is deemed racy.
45 isSurfaceFocused() is the preferred method.
42 */46 */
43 Q_SCRIPTABLE bool isPidFocused(unsigned int pid);47 Q_SCRIPTABLE bool isPidFocused(unsigned int pid);
4448
49 /*
50 Returns true if the surface with the given id has input focus
51 */
52 Q_SCRIPTABLE bool isSurfaceFocused(const QString &surfaceId);
53
45private:54private:
46 QSet<pid_t> fetchAssociatedPids(pid_t pid);55 QSet<pid_t> fetchAssociatedPids(pid_t pid);
47 SessionInterface* findSessionWithPid(const QSet<pid_t> &pidSet);56 SessionInterface* findSessionWithPid(const QSet<pid_t> &pidSet);
48 SessionInterface* findSessionWithPid(SessionInterface* session, const QSet<pid_t> &pidSet);57 SessionInterface* findSessionWithPid(SessionInterface* session, const QSet<pid_t> &pidSet);
58 MirSurfaceInterface *findQmlSurface(const QString &serializedId);
4959
50 const QList<Application*> &m_applications;60 const QList<Application*> &m_applications;
5161

Subscribers

People subscribed via source and target branches