Mir

Merge lp:~robertcarr/mir/1233944-addendum into lp:mir

Proposed by Robert Carr
Status: Merged
Approved by: kevin gunn
Approved revision: no longer in the source branch.
Merged at revision: 1105
Proposed branch: lp:~robertcarr/mir/1233944-addendum
Merge into: lp:mir
Diff against target: 65 lines (+24/-1)
2 files modified
3rd_party/android-input/android/frameworks/base/services/input/EventHub.cpp (+23/-1)
3rd_party/android-input/android/frameworks/base/services/input/EventHub.h (+1/-0)
To merge this branch: bzr merge lp:~robertcarr/mir/1233944-addendum
Reviewer Review Type Date Requested Status
Daniel d'Andrada (community) Disapprove
PS Jenkins bot (community) continuous-integration Approve
kevin gunn (community) Approve
Kevin DuBois (community) Abstain
Robert Ancell Approve
Robert Carr (community) Abstain
Review via email: mp+188900@code.launchpad.net

This proposal supersedes a proposal from 2013-10-02.

Commit message

Fix for LP#1233944

Fixes the Mir-side of bug https://bugs.launchpad.net/mir/+bug/1233944

Event files are first created with root:root permissions and only later
udev rules are applied to it, changing its permissions to root:android-input
and therefore making it readable by unity8-mir

in short: Retry opening a file when its permissions change as it might be
readable now.

Description of the change

Reproposing from my addendum branch as we want to land this quickly and dandrader is EOD. Thanks dandrader :D

==
Fixes bug 1233944.

But further work might be required (likely outside mir) due to the following error message when android-input loads the autopilot-finger device file:

"""
[InputReader] Touch device 'autopilot-finger' did not report support for X or Y axis! The device will be inoperable.
"""

To post a comment you must log in.
Revision history for this message
Robert Carr (robertcarr) wrote : Posted in a previous version of this proposal

+1

review: Approve
Revision history for this message
Robert Carr (robertcarr) wrote : Posted in a previous version of this proposal

I'm worried this may lead to opening devices multiple times. Digging deeper.

review: Needs Information
Revision history for this message
Robert Carr (robertcarr) wrote : Posted in a previous version of this proposal

I think this can lead to open devices multiple times (ending with multiple instances in the mDevices member). I think the behavior is a little unclear here...so I've proposed a small fix:

https://code.launchpad.net/~robertcarr/mir/1233944-addendum/+merge/188896

review: Needs Fixing
Revision history for this message
Robert Carr (robertcarr) :
review: Abstain
Revision history for this message
Robert Ancell (robert-ancell) wrote :

Not tested locally but the code makes sense to me as a workaround.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Kevin DuBois (kdub) wrote :

code looks okay to me too, but i'm unfamiliar with this part of the code.

review: Abstain
Revision history for this message
kevin gunn (kgunn72) wrote :

this was ok and unity8 ran fine according to racarr

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)
Revision history for this message
Daniel d'Andrada (dandrader) wrote :

I'm too late to the party but still:

hasDeviceByPathLocked() pretty much duplicates code (i.e. code bloat) as you could perfectly use the existing getDeviceByPathLocked(), like this:

s/hasDeviceByPathLocked(path)/getDeviceByPathLocked(path) != nullptr/

or even simply:

s/hasDeviceByPathLocked(path)/getDeviceByPathLocked(path)/

Secondly, we are checking for it twice. There's already a check for a pre-existing device in on diff line 31. Not checking for it in the "if(event->mask & IN_CREATE) {...}" case was already the case and it's not a problem as files do not get created twice (you gotta destroy it before recreating it).

In short: duplicated code + extra, superfluous, runtime check.

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

> In short: duplicated code + extra, superfluous, runtime check.

This is not the end of the world, naturally. :)
But really think this addendum is redundant.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '3rd_party/android-input/android/frameworks/base/services/input/EventHub.cpp'
2--- 3rd_party/android-input/android/frameworks/base/services/input/EventHub.cpp 2013-05-28 17:52:18 +0000
3+++ 3rd_party/android-input/android/frameworks/base/services/input/EventHub.cpp 2013-10-02 19:00:39 +0000
4@@ -223,7 +223,7 @@
5 LOG_ALWAYS_FATAL_IF(mEpollFd < 0, "Could not create epoll instance. errno=%d", errno);
6
7 mINotifyFd = inotify_init();
8- int result = inotify_add_watch(mINotifyFd, DEVICE_PATH, IN_DELETE | IN_CREATE);
9+ int result = inotify_add_watch(mINotifyFd, DEVICE_PATH, IN_DELETE | IN_CREATE | IN_ATTRIB);
10 LOG_ALWAYS_FATAL_IF(result < 0, "Could not register INotify for %s. errno=%d",
11 DEVICE_PATH, errno);
12
13@@ -955,6 +955,11 @@
14 char buffer[80];
15
16 ALOGV("Opening device: %s", devicePath);
17+ if (hasDeviceByPathLocked(String8(devicePath)))
18+ {
19+ ALOGV("Not opening device (%s), as it is already opened", devicePath);
20+ return -1;
21+ }
22
23 int fd = open(devicePath, O_RDWR | O_CLOEXEC);
24 if(fd < 0) {
25@@ -1416,6 +1421,14 @@
26 strcpy(filename, event->name);
27 if(event->mask & IN_CREATE) {
28 openDeviceLocked(devname);
29+ } else if (event->mask & IN_ATTRIB) {
30+ Device* device = getDeviceByPathLocked(devname);
31+ if (!device) {
32+ ALOGI("Retry opening device file %s", devname);
33+ // file permissions might have changed, making the device readable now
34+ // let's retry opening it
35+ openDeviceLocked(devname);
36+ }
37 } else {
38 ALOGI("Removing device '%s' due to inotify event\n", devname);
39 closeDeviceByPathLocked(devname);
40@@ -1523,4 +1536,13 @@
41 }
42 }
43
44+bool EventHub::hasDeviceByPathLocked(String8 const& path)
45+{
46+ for (size_t i = 0; i < mDevices.size(); i++) {
47+ auto const& device = mDevices.valueAt(i);
48+ if (device->path == path) return true;
49+ }
50+ return false;
51+}
52+
53 }; // namespace android
54
55=== modified file '3rd_party/android-input/android/frameworks/base/services/input/EventHub.h'
56--- 3rd_party/android-input/android/frameworks/base/services/input/EventHub.h 2013-05-28 17:47:03 +0000
57+++ 3rd_party/android-input/android/frameworks/base/services/input/EventHub.h 2013-10-02 19:00:39 +0000
58@@ -395,6 +395,7 @@
59
60 int32_t mNextDeviceId;
61
62+ bool hasDeviceByPathLocked(String8 const& path);
63 KeyedVector<int32_t, Device*> mDevices;
64
65 Device *mOpeningDevices;

Subscribers

People subscribed via source and target branches