Merge lp:~tiagosh/telephony-service/fix-1398427 into lp:telephony-service

Proposed by Tiago Salem Herrmann
Status: Merged
Approved by: Gustavo Pichorim Boiko
Approved revision: 996
Merged at revision: 994
Proposed branch: lp:~tiagosh/telephony-service/fix-1398427
Merge into: lp:telephony-service
Diff against target: 299 lines (+106/-8)
10 files modified
approver/Approver.xml (+7/-0)
approver/approver.cpp (+53/-2)
approver/approver.h (+4/-0)
approver/approverdbus.cpp (+6/-1)
approver/approverdbus.h (+5/-1)
approver/main.cpp (+4/-4)
libtelephonyservice/callmanager.cpp (+11/-0)
libtelephonyservice/callmanager.h (+1/-0)
libtelephonyservice/telepathyhelper.cpp (+13/-0)
libtelephonyservice/telepathyhelper.h (+2/-0)
To merge this branch: bzr merge lp:~tiagosh/telephony-service/fix-1398427
Reviewer Review Type Date Requested Status
Michael Zanetti (community) Approve
Gustavo Pichorim Boiko (community) Approve
PS Jenkins bot continuous-integration Needs Fixing
Michał Sawicz Approve
Review via email: mp+246224@code.launchpad.net

Commit message

Expose HandleMediaKey(bool doubleClick) to DBus.

Description of the change

Expose HandleMediaKey(bool doubleClick) to DBus.
This is going to be called by unity8.

--Checklist--
Are there any related MPs required for this MP to build/function as expected? Please list.
No

Is your branch in sync with latest trunk (e.g. bzr pull lp:trunk -> no changes)
Yes

Did you perform an exploratory manual test run of your code change and any related functionality on device or emulator?
Yes

Did you successfully run all tests found in your component's Test Plan (https://wiki.ubuntu.com/Process/Merges/TestPlan/telephony-service) on device or emulator?
Yes

If you changed the UI, was the change specified/approved by design?
N/A

If you changed UI labels, did you update the pot file?
N/A

If you changed the packaging (debian), did you add a core-dev as a reviewer to this MP?
N/A

To post a comment you must log in.
Revision history for this message
Michał Sawicz (saviq) wrote :

Hey, do you think it'd make sense for you to return true/false depending on whether you accepted (consumed/reacted to) the event? We could fall back to other consumers then.

review: Needs Information
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
992. By Tiago Salem Herrmann

Return a bool value in HandleMediaKey to indicate if the event will be handled by the approver.

Revision history for this message
Tiago Salem Herrmann (tiagosh) wrote :

> Hey, do you think it'd make sense for you to return true/false depending on
> whether you accepted (consumed/reacted to) the event? We could fall back to
> other consumers then.

Yes, good idea. Just changed the code to match your suggestion.

993. By Tiago Salem Herrmann

export handleMediaKey(bool) to qml plugin

994. By Tiago Salem Herrmann

cache hasCalls value

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Michał Sawicz (saviq) :
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
995. By Tiago Salem Herrmann

change return name

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
996. By Tiago Salem Herrmann

- change approver bus name to fix dbus activation
- use a global timer and always return right away on HandleMediaKey()

Revision history for this message
Michał Sawicz (saviq) wrote :

Great, thanks!

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

Did you perform an exploratory manual test run of the code change and any related functionality on device or emulator?
Yes

Did CI run pass? If not, please explain why.
No, but that's because the tests are being run twice, and in the second run it failed.

Have you checked that submitter has accurately filled out the submitter checklist and has taken no shortcut?
Yes

Code looks good and works as expected!

review: Approve
Revision history for this message
Michael Zanetti (mzanetti) wrote :

Hmm... this seems to crash unity8 when I call:

callManager.handleMediaKey(false)

997. By Tiago Salem Herrmann

use mApproverInterface instead of mHandlerInterface

Revision history for this message
Michael Zanetti (mzanetti) wrote :

Tried the current build from silo 19 (should be rev 997) but it still crashes with this backtrace:

http://paste.ubuntu.com/9755185/

review: Needs Fixing
998. By Tiago Salem Herrmann

initialize variable

Revision history for this message
Michael Zanetti (mzanetti) wrote :

this works for me now

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'approver/Approver.xml'
2--- approver/Approver.xml 2014-01-20 12:57:43 +0000
3+++ approver/Approver.xml 2015-01-15 14:17:50 +0000
4@@ -27,5 +27,12 @@
5 this method has no effect.
6 ]]></dox:d>
7 </method>
8+ <method name="HandleMediaKey">
9+ <dox:d><![CDATA[
10+ Handle events generated by media key buttons usually present on headsets.
11+ ]]></dox:d>
12+ <arg name="doubleClick" type="b" direction="in"/>
13+ <arg name="accepted" type="b" direction="out"/>
14+ </method>
15 </interface>
16 </node>
17
18=== modified file 'approver/approver.cpp'
19--- approver/approver.cpp 2015-01-08 01:05:51 +0000
20+++ approver/approver.cpp 2015-01-15 14:17:50 +0000
21@@ -32,6 +32,7 @@
22 #include "callmanager.h"
23 #include "callentry.h"
24 #include "tonegenerator.h"
25+#include "telepathyhelper.h"
26
27 #include <QContactAvatar>
28 #include <QContactDisplayLabel>
29@@ -54,18 +55,20 @@
30
31 Approver::Approver()
32 : Tp::AbstractClientApprover(channelFilters()),
33- mPendingSnapDecision(NULL)
34+ mPendingSnapDecision(NULL),
35+ mSettleTimer(new QTimer(this))
36 {
37 mDefaultTitle = C::gettext("Unknown caller");
38 mDefaultIcon = QUrl(telephonyServiceDir() + "assets/avatar-default@18.png").toEncoded();
39
40- ApproverDBus *dbus = new ApproverDBus();
41+ ApproverDBus *dbus = new ApproverDBus(this);
42 connect(dbus,
43 SIGNAL(acceptCallRequested()),
44 SLOT(onAcceptCallRequested()));
45 connect(dbus,
46 SIGNAL(rejectCallRequested()),
47 SLOT(onRejectCallRequested()));
48+
49 dbus->connectToBus();
50
51 if (GreeterContacts::isGreeterMode()) {
52@@ -79,6 +82,17 @@
53 mRejectActions["rejectMessage1"] = C::gettext("I'm busy at the moment. I'll call later.");
54 mRejectActions["rejectMessage2"] = C::gettext("I'm running late, on my way now.");
55 mRejectActions["rejectMessage3"] = C::gettext("Please call me back later.");
56+
57+ mSettleTimer->setInterval(500);
58+ mSettleTimer->setSingleShot(true);
59+ connect(mSettleTimer, SIGNAL(timeout()), this, SLOT(onSettleTimerTimeout()));
60+ mSettleTimer->start();
61+}
62+
63+void Approver::onSettleTimerTimeout()
64+{
65+ mSettleTimer->deleteLater();
66+ mSettleTimer = NULL;
67 }
68
69 Approver::~Approver()
70@@ -663,3 +677,40 @@
71 }
72 }
73
74+bool Approver::handleMediaKey(bool doubleClick)
75+{
76+ Q_UNUSED(doubleClick)
77+
78+ // hasCalls gets the value from handler, so even if CallManager isn't ready right now, we know
79+ // if the event will be handled later
80+ bool accepted = mPendingSnapDecision || CallManager::instance()->hasCalls();
81+
82+ // FIXME: Telepathy-qt does not let us know if existing channels are being recovered,
83+ // so if this is the first run, call this method again when mSettleTimer is done
84+ if (mSettleTimer) {
85+ QObject::connect(mSettleTimer, &QTimer::timeout, [=]() {
86+ handleMediaKey(doubleClick);
87+ });
88+ return accepted;
89+ }
90+
91+ // postpone this to avoid blocking dbus method callers
92+ QMetaObject::invokeMethod(this, "processHandleMediaKey", Qt::QueuedConnection, Q_ARG(bool, doubleClick));
93+ return accepted;
94+}
95+
96+void Approver::processHandleMediaKey(bool doubleClick)
97+{
98+ Q_UNUSED(doubleClick)
99+
100+ if (mPendingSnapDecision) {
101+ onAcceptCallRequested();
102+ } else if (CallManager::instance()->hasCalls()) {
103+ // if there is no incoming call, we have to hangup the current active call
104+ CallEntry *call = CallManager::instance()->foregroundCall();
105+ if (call) {
106+ call->endCall();
107+ }
108+ }
109+}
110+
111
112=== modified file 'approver/approver.h'
113--- approver/approver.h 2014-10-09 19:32:20 +0000
114+++ approver/approver.h 2015-01-15 14:17:50 +0000
115@@ -56,6 +56,7 @@
116 bool showSnapDecision(const Tp::ChannelDispatchOperationPtr dispatchOperation,
117 const Tp::ChannelPtr channel,
118 const QContact &contact = QContact());
119+ bool handleMediaKey(bool doubleClick);
120
121 protected:
122 Tp::ChannelDispatchOperationPtr dispatchOperationForIncomingCall();
123@@ -71,6 +72,8 @@
124 void onAcceptCallRequested();
125 void onRejectCallRequested();
126 void updateNotification(const QtContacts::QContact &contact);
127+ void onSettleTimerTimeout();
128+ void processHandleMediaKey(bool doubleClick);
129
130 private:
131 QList<Tp::ChannelDispatchOperationPtr> mDispatchOps;
132@@ -81,6 +84,7 @@
133 QString mCachedBody;
134 QFeedbackHapticsEffect mVibrateEffect;
135 QTimer mVibrateTimer;
136+ QTimer *mSettleTimer;
137 QMap<QString,QString> mRejectActions;
138 };
139
140
141=== modified file 'approver/approverdbus.cpp'
142--- approver/approverdbus.cpp 2014-01-20 12:57:43 +0000
143+++ approver/approverdbus.cpp 2015-01-15 14:17:50 +0000
144@@ -29,7 +29,7 @@
145 static const char* DBUS_SERVICE = "com.canonical.Approver";
146 static const char* DBUS_OBJECT_PATH = "/com/canonical/Approver";
147
148-ApproverDBus::ApproverDBus(QObject* parent) : QObject(parent)
149+ApproverDBus::ApproverDBus(Approver *approver, QObject* parent) : QObject(parent), mApprover(approver)
150 {
151 }
152
153@@ -64,3 +64,8 @@
154 {
155 Q_EMIT rejectCallRequested();
156 }
157+
158+bool ApproverDBus::HandleMediaKey(bool doubleClick)
159+{
160+ return mApprover->handleMediaKey(doubleClick);
161+}
162
163=== modified file 'approver/approverdbus.h'
164--- approver/approverdbus.h 2014-01-20 12:57:43 +0000
165+++ approver/approverdbus.h 2015-01-15 14:17:50 +0000
166@@ -26,6 +26,7 @@
167 #include <QtCore/QObject>
168 #include <QtDBus/QDBusContext>
169 #include "chatmanager.h"
170+#include "approver.h"
171
172 /**
173 * DBus interface for the phone approver
174@@ -35,7 +36,7 @@
175 Q_OBJECT
176
177 public:
178- ApproverDBus(QObject* parent=0);
179+ ApproverDBus(Approver *approver, QObject* parent=0);
180 ~ApproverDBus();
181
182 bool connectToBus();
183@@ -44,11 +45,14 @@
184 Q_NOREPLY void HangUpAndAcceptCall();
185 Q_NOREPLY void AcceptCall();
186 Q_NOREPLY void RejectCall();
187+ bool HandleMediaKey(bool doubleClick);
188
189 Q_SIGNALS:
190 void hangUpAndAcceptCallRequested();
191 void acceptCallRequested();
192 void rejectCallRequested();
193+private:
194+ Approver *mApprover;
195 };
196
197 #endif // APPROVERDBUS_H
198
199=== modified file 'approver/main.cpp'
200--- approver/main.cpp 2015-01-08 01:05:51 +0000
201+++ approver/main.cpp 2015-01-15 14:17:50 +0000
202@@ -58,11 +58,11 @@
203 qputenv("UBUNTU_PLATFORM_API_BACKEND", "touch_mirclient");
204 #endif
205
206- // register the approver
207- Approver *approver = new Approver();
208- QObject::connect(TelepathyHelper::instance(), &TelepathyHelper::setupReady, [approver]() {
209+ QObject::connect(TelepathyHelper::instance(), &TelepathyHelper::setupReady, []() {
210+ // register the approver
211+ TelepathyHelper::instance()->registerChannelObserver("TelephonyServiceObserver");
212+ Approver *approver = new Approver();
213 TelepathyHelper::instance()->registerClient(approver, "TelephonyServiceApprover");
214- TelepathyHelper::instance()->registerChannelObserver("TelephonyServiceObserver");
215 });
216
217 return app.exec();
218
219=== modified file 'libtelephonyservice/callmanager.cpp'
220--- libtelephonyservice/callmanager.cpp 2014-09-11 18:12:50 +0000
221+++ libtelephonyservice/callmanager.cpp 2015-01-15 14:17:50 +0000
222@@ -380,3 +380,14 @@
223 /* calling without channel, DTMF tone is played only locally */
224 phoneAppHandler->call("SendDTMF", "" , key);
225 }
226+
227+bool CallManager::handleMediaKey(bool doubleClick)
228+{
229+ QDBusInterface *approverInterface = TelepathyHelper::instance()->approverInterface();
230+ QDBusReply<bool> reply = approverInterface->call("HandleMediaKey", doubleClick);
231+ if (reply.isValid()) {
232+ return reply.value();
233+ }
234+ return false;
235+}
236+
237
238=== modified file 'libtelephonyservice/callmanager.h'
239--- libtelephonyservice/callmanager.h 2014-08-22 19:01:46 +0000
240+++ libtelephonyservice/callmanager.h 2015-01-15 14:17:50 +0000
241@@ -61,6 +61,7 @@
242 Q_INVOKABLE void mergeCalls(CallEntry *firstCall, CallEntry *secondCall);
243 Q_INVOKABLE void splitCall(CallEntry *callEntry);
244 Q_INVOKABLE void playTone(const QString &key);
245+ Q_INVOKABLE bool handleMediaKey(bool doubleClick);
246
247 CallEntry *foregroundCall() const;
248 CallEntry *backgroundCall() const;
249
250=== modified file 'libtelephonyservice/telepathyhelper.cpp'
251--- libtelephonyservice/telepathyhelper.cpp 2014-12-17 12:54:52 +0000
252+++ libtelephonyservice/telepathyhelper.cpp 2015-01-15 14:17:50 +0000
253@@ -43,6 +43,7 @@
254 mFirstTime(true),
255 mConnected(false),
256 mHandlerInterface(0),
257+ mApproverInterface(0),
258 mDefaultSimSettings(new QGSettings("com.ubuntu.phone")),
259 mFlightModeInterface("org.freedesktop.URfkill",
260 "/org/freedesktop/URfkill",
261@@ -172,6 +173,18 @@
262 return mHandlerInterface;
263 }
264
265+QDBusInterface *TelepathyHelper::approverInterface() const
266+{
267+ if (!mApproverInterface) {
268+ mApproverInterface = new QDBusInterface("org.freedesktop.Telepathy.Client.TelephonyServiceApprover",
269+ "/com/canonical/Approver",
270+ "com.canonical.TelephonyServiceApprover",
271+ QDBusConnection::sessionBus(),
272+ const_cast<TelepathyHelper*>(this));
273+ }
274+ return mApproverInterface;
275+}
276+
277 bool TelepathyHelper::connected() const
278 {
279 if (QCoreApplication::applicationName() != "telephony-service-handler" &&
280
281=== modified file 'libtelephonyservice/telepathyhelper.h'
282--- libtelephonyservice/telepathyhelper.h 2014-12-17 12:54:52 +0000
283+++ libtelephonyservice/telepathyhelper.h 2015-01-15 14:17:50 +0000
284@@ -67,6 +67,7 @@
285 QQmlListProperty<AccountEntry> qmlActiveAccounts();
286 ChannelObserver *channelObserver() const;
287 QDBusInterface *handlerInterface() const;
288+ QDBusInterface *approverInterface() const;
289 AccountEntry *defaultMessagingAccount() const;
290 AccountEntry *defaultCallAccount() const;
291
292@@ -136,6 +137,7 @@
293 bool mFirstTime;
294 bool mConnected;
295 mutable QDBusInterface *mHandlerInterface;
296+ mutable QDBusInterface *mApproverInterface;
297 QGSettings *mDefaultSimSettings;
298 QDBusInterface mFlightModeInterface;
299 };

Subscribers

People subscribed via source and target branches