Merge lp:~charlesk/indicator-datetime/lp-1358610-honor-other-vibrations-setting into lp:indicator-datetime/15.04

Proposed by Charles Kerr
Status: Merged
Approved by: dobey
Approved revision: 410
Merged at revision: 412
Proposed branch: lp:~charlesk/indicator-datetime/lp-1358610-honor-other-vibrations-setting
Merge into: lp:indicator-datetime/15.04
Diff against target: 212 lines (+99/-33)
3 files modified
src/com.ubuntu.touch.AccountsService.Sound.xml (+5/-0)
src/snap.cpp (+11/-3)
tests/test-snap.cpp (+83/-30)
To merge this branch: bzr merge lp:~charlesk/indicator-datetime/lp-1358610-honor-other-vibrations-setting
Reviewer Review Type Date Requested Status
dobey (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+255602@code.launchpad.net

Commit message

Honor the 'other vibrations' setting to enable/disable vibrations when alarm notifications are shown.

Description of the change

== Description of the Change

A pretty straightforward patch this time:

1. Don't vibrate if the AccountsService "Other Vibrations" bool property is false

2. In test-snap, add an AccountsService dbus mock to cover the new code.

== 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 the code build without warnings?

Yes

> Did the tests run successfully?

Yes

> 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

> What device (or emulator) has your component test plan been executed successfully on?

mako vivid r165

> What manual tests are relevant for this MP?

indicator-datetime/other-vibrations

> Did you include a link to the MR Review Checklist Template to make your reviewer's life easier?

https://wiki.ubuntu.com/Process/Merges/Checklists/indicator-datetime

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
David Barth (dbarth) wrote :

Charles, can you clarify what you need the AccountService for, and the library you use to access it? It seems that this is creating an issue further down the line with apparmor. See https://bugs.launchpad.net/ubuntu/+source/apparmor-easyprof-ubuntu/+bug/1433590 for reference.

Revision history for this message
Charles Kerr (charlesk) wrote :

David, sure, indicator-datetime is connecting to the com.ubuntu.touch.AccountsService.Sound interface in order to watch two settings that are published there:

(1) Silent Mode, so that we know whether or not to disable audio on alarms (this has been landed for some time now)

(2) Other Vibrations, so that we know whether or not to vibrate on alarms (this is new in this MP)

Revision history for this message
Charles Kerr (charlesk) wrote :
Revision history for this message
dobey (dobey) wrote :

Looks ok to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/com.ubuntu.touch.AccountsService.Sound.xml'
2--- src/com.ubuntu.touch.AccountsService.Sound.xml 2015-01-21 20:25:52 +0000
3+++ src/com.ubuntu.touch.AccountsService.Sound.xml 2015-04-09 00:42:59 +0000
4@@ -34,6 +34,11 @@
5 <annotation name="org.freedesktop.Accounts.DefaultValue" value="true"/>
6 </property>
7
8+ <!-- "Other vibrations" should cover all vibrations except for those relating to phone calls and messages -->
9+ <property name="OtherVibrate" type="b" access="readwrite">
10+ <annotation name="org.freedesktop.Accounts.DefaultValue" value="true"/>
11+ </property>
12+
13 <property name="DialpadSoundsEnabled" type="b" access="readwrite">
14 <annotation name="org.freedesktop.Accounts.DefaultValue" value="true"/>
15 </property>
16
17=== modified file 'src/snap.cpp'
18--- src/snap.cpp 2015-04-03 18:21:44 +0000
19+++ src/snap.cpp 2015-04-09 00:42:59 +0000
20@@ -104,10 +104,12 @@
21 }
22
23 // create the haptic feedback...
24- const auto haptic_mode = m_settings->alarm_haptic.get();
25 std::shared_ptr<uin::Haptic> haptic;
26- if (haptic_mode == "pulse")
27- haptic = std::make_shared<uin::Haptic>(uin::Haptic::MODE_PULSE);
28+ if (should_vibrate()) {
29+ const auto haptic_mode = m_settings->alarm_haptic.get();
30+ if (haptic_mode == "pulse")
31+ haptic = std::make_shared<uin::Haptic>(uin::Haptic::MODE_PULSE);
32+ }
33
34 // show a notification...
35 const auto minutes = std::chrono::minutes(m_settings->alarm_duration.get());
36@@ -181,6 +183,12 @@
37 && (accounts_service_sound_get_silent_mode(m_accounts_service_sound_proxy));
38 }
39
40+ bool should_vibrate() const
41+ {
42+ return (m_accounts_service_sound_proxy != nullptr)
43+ && (accounts_service_sound_get_other_vibrate(m_accounts_service_sound_proxy));
44+ }
45+
46 std::string get_alarm_uri(const Alarm& alarm,
47 const std::shared_ptr<const Settings>& settings) const
48 {
49
50=== modified file 'tests/test-snap.cpp'
51--- tests/test-snap.cpp 2015-04-05 22:27:52 +0000
52+++ tests/test-snap.cpp 2015-04-09 00:42:59 +0000
53@@ -29,6 +29,9 @@
54
55 #include <glib.h>
56
57+#include <unistd.h> // getuid()
58+#include <sys/types.h> // getuid()
59+
60 using namespace unity::indicator::datetime;
61
62 #include "glib-fixture.h"
63@@ -83,14 +86,21 @@
64
65 static constexpr char const * HINT_TIMEOUT {"x-canonical-snap-decisions-timeout"};
66
67+ static constexpr char const * AS_BUSNAME {"org.freedesktop.Accounts"};
68+ static constexpr char const * AS_INTERFACE {"com.ubuntu.touch.AccountsService.Sound"};
69+ static constexpr char const * PROP_OTHER_VIBRATIONS {"OtherVibrate"};
70+ static constexpr char const * PROP_SILENT_MODE {"SilentMode"};
71+
72 Appointment appt;
73 GDBusConnection * system_bus = nullptr;
74 GDBusConnection * session_bus = nullptr;
75 DbusTestService * service = nullptr;
76+ DbusTestDbusMock * as_mock = nullptr;
77 DbusTestDbusMock * notify_mock = nullptr;
78 DbusTestDbusMock * powerd_mock = nullptr;
79 DbusTestDbusMock * screen_mock = nullptr;
80 DbusTestDbusMock * haptic_mock = nullptr;
81+ DbusTestDbusMockObject * as_obj = nullptr;
82 DbusTestDbusMockObject * notify_obj = nullptr;
83 DbusTestDbusMockObject * powerd_obj = nullptr;
84 DbusTestDbusMockObject * screen_obj = nullptr;
85@@ -116,6 +126,38 @@
86 service = dbus_test_service_new(nullptr);
87
88 ///
89+ /// Add the AccountsService mock
90+ ///
91+
92+ as_mock = dbus_test_dbus_mock_new(AS_BUSNAME);
93+ auto as_path = g_strdup_printf("/org/freedesktop/Accounts/User%lu", (gulong)getuid());
94+ as_obj = dbus_test_dbus_mock_get_object(as_mock,
95+ as_path,
96+ AS_INTERFACE,
97+ &error);
98+ g_free(as_path);
99+ g_assert_no_error(error);
100+
101+ // PROP_SILENT_MODE
102+ dbus_test_dbus_mock_object_add_property(as_mock,
103+ as_obj,
104+ PROP_SILENT_MODE,
105+ G_VARIANT_TYPE_BOOLEAN,
106+ g_variant_new_boolean(false),
107+ &error);
108+ g_assert_no_error(error);
109+
110+ // PROP_OTHER_VIBRATIONS
111+ dbus_test_dbus_mock_object_add_property(as_mock,
112+ as_obj,
113+ PROP_OTHER_VIBRATIONS,
114+ G_VARIANT_TYPE_BOOLEAN,
115+ g_variant_new_boolean(true),
116+ &error);
117+ g_assert_no_error(error);
118+ dbus_test_service_add_task(service, DBUS_TEST_TASK(as_mock));
119+
120+ ///
121 /// Add the Notifications mock
122 ///
123
124@@ -283,6 +325,7 @@
125 g_clear_object(&screen_mock);
126 g_clear_object(&powerd_mock);
127 g_clear_object(&notify_mock);
128+ g_clear_object(&as_mock);
129 g_clear_object(&service);
130 g_object_unref(session_bus);
131 g_object_unref(system_bus);
132@@ -480,40 +523,50 @@
133 ****
134 ***/
135
136-TEST_F(SnapFixture, HapticModes)
137+TEST_F(SnapFixture,Vibrate)
138 {
139 auto settings = std::make_shared<Settings>();
140 auto ne = std::make_shared<unity::indicator::notifications::Engine>(APP_NAME);
141 auto func = [this](const Appointment&, const Alarm&){g_idle_add(quit_idle, loop);};
142 GError * error = nullptr;
143
144- // invoke a snap decision while haptic feedback is set to "pulse",
145- // confirm that VibratePattern got called
146- settings->alarm_haptic.set("pulse");
147- auto snap = new Snap (ne, settings);
148- (*snap)(appt, appt.alarms.front(), func, func);
149- wait_msec(100);
150- EXPECT_TRUE (dbus_test_dbus_mock_object_check_method_call (haptic_mock,
151- haptic_obj,
152- HAPTIC_METHOD_VIBRATE_PATTERN,
153- nullptr,
154- &error));
155- delete snap;
156-
157- // invoke a snap decision while haptic feedback is set to "none",
158- // confirm that VibratePattern =didn't= get called
159- wait_msec(100);
160- dbus_test_dbus_mock_object_clear_method_calls (haptic_mock, haptic_obj, &error);
161- settings->alarm_haptic.set("none");
162- snap = new Snap (ne, settings);
163- (*snap)(appt, appt.alarms.front(), func, func);
164- wait_msec(100);
165- EXPECT_FALSE (dbus_test_dbus_mock_object_check_method_call (haptic_mock,
166- haptic_obj,
167- HAPTIC_METHOD_VIBRATE_PATTERN,
168- nullptr,
169- &error));
170- delete snap;
171-
172- g_assert_no_error (error);
173+ struct {
174+ bool other_vibrations; // the com.ubuntu.touch.AccountsService.Sound "other vibrations" setting
175+ const char* haptic_mode; // supported values: "none", "pulse"
176+ bool expected_vibrate_called; // do we expect the phone to vibrate?
177+ } test_cases[] = {
178+ { false, "none", false },
179+ { true, "none", false },
180+ { false, "pulse", false },
181+ { true, "pulse", true }
182+ };
183+
184+ auto snap = std::make_shared<Snap>(ne, settings);
185+
186+ for(const auto& test_case : test_cases)
187+ {
188+ // clear out any previous iterations' noise
189+ dbus_test_dbus_mock_object_clear_method_calls(haptic_mock, haptic_obj, &error);
190+
191+ // set the properties to match the test case
192+ settings->alarm_haptic.set(test_case.haptic_mode);
193+ dbus_test_dbus_mock_object_update_property(as_mock,
194+ as_obj,
195+ PROP_OTHER_VIBRATIONS,
196+ g_variant_new_boolean(test_case.other_vibrations),
197+ &error);
198+ g_assert_no_error(error);
199+ wait_msec(100);
200+
201+ // run the test
202+ (*snap)(appt, appt.alarms.front(), func, func);
203+ wait_msec(100);
204+ const bool vibrate_called = dbus_test_dbus_mock_object_check_method_call(haptic_mock,
205+ haptic_obj,
206+ HAPTIC_METHOD_VIBRATE_PATTERN,
207+ nullptr,
208+ &error);
209+ g_assert_no_error(error);
210+ EXPECT_EQ(test_case.expected_vibrate_called, vibrate_called);
211+ }
212 }

Subscribers

People subscribed via source and target branches