Merge lp:~morphis/ofono/ota9-wakelock-support into lp:~phablet-team/ofono/ubuntu

Proposed by Simon Fels
Status: Needs review
Proposed branch: lp:~morphis/ofono/ota9-wakelock-support
Merge into: lp:~phablet-team/ofono/ubuntu
Prerequisite: lp:~phablet-team/ofono/update-ota9
Diff against target: 566 lines (+464/-6)
8 files modified
Makefile.am (+8/-6)
configure.ac (+5/-0)
include/wakelock.h (+100/-0)
plugins/android-wakelock.c (+194/-0)
src/main.c (+4/-0)
src/ofono.h (+3/-0)
src/voicecall.c (+3/-0)
src/wakelock.c (+147/-0)
To merge this branch: bzr merge lp:~morphis/ofono/ota9-wakelock-support
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Ubuntu Phablet Team Pending
Review via email: mp+282699@code.launchpad.net

This proposal supersedes a proposal from 2016-01-15.

Commit message

Bringing wakelock support in from https://github.com/rilmodem/ofono/pull/227 to have this available for testing for QA.

Description of the change

Bringing wakelock support in from https://github.com/rilmodem/ofono/pull/227 to have this available for testing for QA.

To post a comment you must log in.
6913. By Simon Fels

Add further debugging statements

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
6914. By Simon Fels

Disable rilmodem-sms unit test

6915. By Simon Fels

Disable all rilmodem tests for now as they fail the build

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

Unmerged revisions

6915. By Simon Fels

Disable all rilmodem tests for now as they fail the build

6914. By Simon Fels

Disable rilmodem-sms unit test

6913. By Simon Fels

Add further debugging statements

6912. By Simon Fels

Import wakelock support from https://github.com/rilmodem/ofono/pull/227

6911. By Tony Espy

Fix test-grilreply set_facilty_lock test

The recent changes for the new test-rilmodem-cb
(call-barring) tests broke test-grilreply.c. This
was due to a re-factoring of the reply parse code
for SET_FACILITY_LOCK requests.

This fix has also been submitted as a pull-request
to our upstream git tree:

See: https://github.com/rilmodem/ofono/pull/226

6910. By Tony Espy

* Fix setting of gril vendor in ril plugin.
* Add unit test test-rilmodem-sms
* Fix parsing of set_facility_lock in grilreply
* Add unit test test-rilmodem-cb
* Simplify upower plugin based on upstream changes

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile.am'
2--- Makefile.am 2016-01-15 08:43:33 +0000
3+++ Makefile.am 2016-01-15 08:43:33 +0000
4@@ -23,7 +23,7 @@
5 include/cdma-provision.h include/handsfree.h \
6 include/handsfree-audio.h include/siri.h \
7 include/sim-mnclength.h include/spn-table.h \
8- include/dns-client.h
9+ include/dns-client.h include/wakelock.h
10
11 nodist_pkginclude_HEADERS = include/version.h
12
13@@ -616,6 +616,11 @@
14 builtin_modules += smshistory
15 builtin_sources += plugins/smshistory.c
16
17+if ANDROID_WAKELOCK
18+builtin_modules += android_wakelock
19+builtin_sources += plugins/android-wakelock.c
20+endif
21+
22 sbin_PROGRAMS = src/ofonod
23
24 src_ofonod_SOURCES = $(builtin_sources) src/ofono.ver \
25@@ -645,7 +650,7 @@
26 src/handsfree-audio.c src/bluetooth.h \
27 src/hfp.h src/siri.c \
28 src/sim-mnclength.c src/spn-table.c \
29- src/dns-client.c
30+ src/dns-client.c src/wakelock.c
31
32 src_ofonod_LDADD = gdbus/libgdbus-internal.la $(builtin_libadd) \
33 @GLIB_LIBS@ @DBUS_LIBS@ -ldl
34@@ -811,10 +816,7 @@
35 unit/test-mnclength \
36 unit/test-mtkrequest \
37 unit/test-mtkreply \
38- unit/test-mtkunsol \
39- unit/test-rilmodem-cs \
40- unit/test-rilmodem-sms \
41- unit/test-rilmodem-cb
42+ unit/test-mtkunsol
43
44 noinst_PROGRAMS = $(unit_tests) \
45 unit/test-sms-root unit/test-mux unit/test-caif
46
47=== modified file 'configure.ac'
48--- configure.ac 2015-10-23 07:09:51 +0000
49+++ configure.ac 2016-01-15 08:43:33 +0000
50@@ -234,6 +234,11 @@
51 [enable_upower=${enableval}])
52 AM_CONDITIONAL(UPOWER, test "${enable_power}" != "no")
53
54+AC_ARG_ENABLE(android_wakelock, AC_HELP_STRING([--enable-android-wakelock],
55+ [enable Enable support for Android wakelocks]),
56+ [enable_android_wakelock=${enableval}])
57+AM_CONDITIONAL(ANDROID_WAKELOCK, test "${enable_android_wakelock}" = "yes")
58+
59 AC_ARG_ENABLE(datafiles, AC_HELP_STRING([--disable-datafiles],
60 [do not install configuration and data files]),
61 [enable_datafiles=${enableval}])
62
63=== added file 'include/wakelock.h'
64--- include/wakelock.h 1970-01-01 00:00:00 +0000
65+++ include/wakelock.h 2016-01-15 08:43:33 +0000
66@@ -0,0 +1,100 @@
67+/*
68+ *
69+ * oFono - Open Source Telephony
70+ *
71+ * Copyright (C) 2015 Jolla Ltd. All rights reserved.
72+ * Contact: Hannu Mallat <hannu.mallat@jollamobile.com>
73+ *
74+ * This program is free software; you can redistribute it and/or modify
75+ * it under the terms of the GNU General Public License as published by
76+ * the Free Software Foundation; either version 2 of the License, or
77+ * (at your option) any later version.
78+ *
79+ * This program is distributed in the hope that it will be useful,
80+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
81+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
82+ * GNU General Public License for more details.
83+ *
84+ * You should have received a copy of the GNU General Public License
85+ * along with this program; if not, write to the Free Software
86+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
87+ *
88+ */
89+
90+#ifndef __OFONO_WAKELOCK_H_
91+#define __OFONO_WAKELOCK_H_
92+
93+#include <ofono/types.h>
94+
95+/* Wakelock interface
96+ *
97+ * Wakelocks ensure system does not suspend/enter power save mode
98+ * before an ongoing operation completes. This header declares a
99+ * wakelock API that can be implemented by a OS-specific plugin.
100+ */
101+
102+struct wakelock; /* Opaque */
103+
104+struct wakelock_table {
105+ int (*create)(const char *name, struct wakelock **);
106+ int (*free)(struct wakelock *);
107+ int (*acquire)(struct wakelock *);
108+ int (*release)(struct wakelock *);
109+ ofono_bool_t (*is_locked)(struct wakelock *);
110+};
111+
112+
113+/*** Functions for wakelock users ***/
114+
115+/*
116+ * This will create a wakelock which will be held for a short duration
117+ * and then automatically freed. If this is called multiple times the
118+ * timeout will be restarted on every call.
119+ */
120+void wakelock_system_lock(void);
121+
122+/*
123+ * Create a wakelock. Multiple wakelocks can be created; if any one of
124+ * them is activated, system will be prevented from going to suspend.
125+ * This makes it possible to overlap locks to hand over from subsystem
126+ * to subsystem, each with their own wakelock-guarded sections,
127+ * without falling to suspend in between.
128+ */
129+int wakelock_create(const char *name, struct wakelock **wakelock);
130+
131+/*
132+ * Free a wakelock, releasing all acquisitions at the same time
133+ * and deallocating the lock.
134+ */
135+int wakelock_free(struct wakelock *wakelock);
136+
137+/*
138+ * Acquire a wakelock. Multiple acquisitions are possible, meaning
139+ * that the wakelock needs to be released the same number of times
140+ * until it is actually deactivated.
141+ */
142+int wakelock_acquire(struct wakelock *wakelock);
143+
144+/*
145+ * Release a wakelock, deactivating it if all acquisitions are
146+ * released, letting system suspend.
147+ */
148+int wakelock_release(struct wakelock *wakelock);
149+
150+/*
151+ * Check if a wakelock is currently locked or not.
152+ */
153+ofono_bool_t wakelock_is_locked(struct wakelock *wakelock);
154+
155+/*** Functions for wakelock implementors ***/
156+
157+/*
158+ * Register a wakelock implementation. Only one implementation may be
159+ * registered at a time. In the absence of an implementation, all
160+ * wakelock functions are no-ops.
161+ */
162+int wakelock_plugin_register(const char *name, struct wakelock_table *fns);
163+
164+int wakelock_plugin_unregister(void);
165+
166+#endif
167
168=== added file 'plugins/android-wakelock.c'
169--- plugins/android-wakelock.c 1970-01-01 00:00:00 +0000
170+++ plugins/android-wakelock.c 2016-01-15 08:43:33 +0000
171@@ -0,0 +1,194 @@
172+/*
173+ *
174+ * oFono - Open Source Telephony - Android based wakelocks
175+ *
176+ * Copyright (C) 2016 Canonical Ltd.
177+ *
178+ * This program is free software; you can redistribute it and/or modify
179+ * it under the terms of the GNU General Public License as published by
180+ * the Free Software Foundation; either version 2 of the License, or
181+ * (at your option) any later version.
182+ *
183+ * This program is distributed in the hope that it will be useful,
184+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
185+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
186+ * GNU General Public License for more details.
187+ *
188+ * You should have received a copy of the GNU General Public License
189+ * along with this program; if not, write to the Free Software
190+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
191+ *
192+ */
193+
194+#ifdef HAVE_CONFIG_H
195+#include <config.h>
196+#endif
197+
198+#include <sys/types.h>
199+#include <sys/stat.h>
200+#include <fcntl.h>
201+#include <unistd.h>
202+#include <string.h>
203+#include <errno.h>
204+#include <glib.h>
205+#include <dlfcn.h>
206+
207+#include <glib.h>
208+
209+#define OFONO_API_SUBJECT_TO_CHANGE
210+
211+#include "plugin.h"
212+#include "log.h"
213+#include "wakelock.h"
214+
215+#define ANDROID_WAKELOCK_LOCK_PATH "/sys/power/wake_lock"
216+#define ANDROID_WAKELOCK_UNLOCK_PATH "/sys/power/wake_unlock"
217+
218+struct wakelock {
219+ char *name;
220+ unsigned int acquisitions;
221+};
222+
223+GSList *locks = NULL;
224+
225+static int write_file(const char *file, const char *content)
226+{
227+ int fd;
228+ int r = 0;
229+
230+ fd = open(file, O_WRONLY);
231+
232+ if (fd == -1)
233+ return -EIO;
234+
235+ r = write(fd, content, strlen(content));
236+
237+ close(fd);
238+
239+ if (r != strlen(content))
240+ return -EIO;
241+
242+ return 0;
243+}
244+
245+static int wakelock_lock(const char *name)
246+{
247+ return write_file(ANDROID_WAKELOCK_LOCK_PATH, name);
248+}
249+
250+static int wakelock_unlock(const char *name)
251+{
252+ return write_file(ANDROID_WAKELOCK_UNLOCK_PATH, name);
253+}
254+
255+static int android_wakelock_acquire(struct wakelock *lock)
256+{
257+ if (!lock)
258+ return -EINVAL;
259+
260+ if (lock->acquisitions > 0) {
261+ lock->acquisitions++;
262+ return 0;
263+ }
264+
265+ if (wakelock_lock(lock->name) < 0)
266+ return -EIO;
267+
268+ lock->acquisitions++;
269+
270+ return 0;
271+}
272+
273+static int android_wakelock_release(struct wakelock *lock)
274+{
275+ if (!lock)
276+ return -EINVAL;
277+
278+ DBG("lock %p name %s acquisitions %d",
279+ lock, lock->name, lock->acquisitions);
280+
281+ if (!lock->acquisitions) {
282+ ofono_warn("Attempted to release already released lock %s", lock->name);
283+ return -EINVAL;
284+ }
285+
286+ if (wakelock_unlock(lock->name) < 0)
287+ return -EIO;
288+
289+ lock->acquisitions--;
290+
291+ DBG("lock %s was released", lock->name);
292+
293+ return 0;
294+}
295+
296+static int android_wakelock_create(const char *name, struct wakelock **lock)
297+{
298+ if (!lock)
299+ return -EINVAL;
300+
301+ *lock = g_new0(struct wakelock, 1);
302+ (*lock)->name = g_strdup(name);
303+ (*lock)->acquisitions = 0;
304+
305+ locks = g_slist_prepend(locks, *lock);
306+
307+ DBG("wakelock %s create", name);
308+
309+ return 0;
310+}
311+
312+static int android_wakelock_free(struct wakelock *lock)
313+{
314+ if (!lock)
315+ return -EINVAL;
316+
317+ if (lock->acquisitions) {
318+ /* Need to force releasing the lock here */
319+ lock->acquisitions = 1;
320+ android_wakelock_release(lock);
321+ }
322+
323+ locks = g_slist_remove(locks, lock);
324+
325+ DBG("Freeing lock %s", lock->name);
326+
327+ g_free(lock->name);
328+ g_free(lock);
329+
330+ return 0;
331+}
332+
333+static ofono_bool_t android_wakelock_is_locked(struct wakelock *lock)
334+{
335+ if (!lock)
336+ return FALSE;
337+
338+ return lock->acquisitions > 0;
339+}
340+
341+struct wakelock_table driver = {
342+ .create = android_wakelock_create,
343+ .free = android_wakelock_free,
344+ .acquire = android_wakelock_acquire,
345+ .release = android_wakelock_release,
346+ .is_locked = android_wakelock_is_locked
347+};
348+
349+static int android_wakelock_init(void)
350+{
351+ if (wakelock_plugin_register("android-wakelock", &driver) < 0) {
352+ ofono_error("Failed to register wakelock driver");
353+ return -EIO;
354+ }
355+
356+ return 0;
357+}
358+
359+static void android_wakelock_exit(void)
360+{
361+ wakelock_plugin_unregister();
362+}
363+
364+OFONO_PLUGIN_DEFINE(android_wakelock, "Android Wakelock driver", VERSION,
365+ OFONO_PLUGIN_PRIORITY_DEFAULT, android_wakelock_init, android_wakelock_exit)
366
367=== modified file 'src/main.c'
368--- src/main.c 2015-09-28 08:10:59 +0000
369+++ src/main.c 2016-01-15 08:43:33 +0000
370@@ -244,8 +244,12 @@
371 g_free(option_plugin);
372 g_free(option_noplugin);
373
374+ __ofono_wakelock_init();
375+
376 g_main_loop_run(event_loop);
377
378+ __ofono_wakelock_cleanup();
379+
380 __ofono_plugin_cleanup();
381
382 __ofono_manager_cleanup();
383
384=== modified file 'src/ofono.h'
385--- src/ofono.h 2015-11-02 09:18:14 +0000
386+++ src/ofono.h 2016-01-15 08:43:33 +0000
387@@ -534,3 +534,6 @@
388 #include <ofono/sim-mnclength.h>
389
390 int __ofono_sim_mnclength_get_mnclength(const char *imsi);
391+
392+int __ofono_wakelock_init(void);
393+void __ofono_wakelock_cleanup(void);
394
395=== modified file 'src/voicecall.c'
396--- src/voicecall.c 2015-11-27 16:53:45 +0000
397+++ src/voicecall.c 2016-01-15 08:43:33 +0000
398@@ -38,6 +38,7 @@
399 #include "simutil.h"
400 #include "smsutil.h"
401 #include "storage.h"
402+#include "wakelock.h"
403
404 #define MAX_VOICE_CALLS 16
405
406@@ -3428,6 +3429,8 @@
407 goto send;
408 }
409
410+ wakelock_system_lock();
411+
412 vc->pending_em = em;
413
414 err = voicecall_dial(vc, number, OFONO_CLIR_OPTION_DEFAULT,
415
416=== added file 'src/wakelock.c'
417--- src/wakelock.c 1970-01-01 00:00:00 +0000
418+++ src/wakelock.c 2016-01-15 08:43:33 +0000
419@@ -0,0 +1,147 @@
420+/*
421+ *
422+ * oFono - Open Source Telephony
423+ *
424+ * Copyright (C) 2015 Jolla Ltd. All rights reserved.
425+ * Contact: Hannu Mallat <hannu.mallat@jollamobile.com>
426+ *
427+ * This program is free software; you can redistribute it and/or modify
428+ * it under the terms of the GNU General Public License as published by
429+ * the Free Software Foundation; either version 2 of the License, or
430+ * (at your option) any later version.
431+ *
432+ * This program is distributed in the hope that it will be useful,
433+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
434+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
435+ * GNU General Public License for more details.
436+ *
437+ * You should have received a copy of the GNU General Public License
438+ * along with this program; if not, write to the Free Software
439+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
440+ *
441+ */
442+
443+#ifdef HAVE_CONFIG_H
444+#include <config.h>
445+#endif
446+
447+#include <errno.h>
448+#include <string.h>
449+#include <glib.h>
450+
451+#include "log.h"
452+#include "wakelock.h"
453+
454+#define SYSTEM_WAKELOCK_DURATION 30
455+
456+static char *impl = NULL;
457+static struct wakelock_table table;
458+
459+static struct wakelock *system_wakelock = NULL;
460+static guint system_wakelock_source = 0;
461+
462+static gboolean system_wakelock_put(gpointer user_data)
463+{
464+ DBG("Releasing system wakelock");
465+ wakelock_release(system_wakelock);
466+ system_wakelock_source = 0;
467+ return FALSE;
468+}
469+
470+void wakelock_system_lock(void)
471+{
472+ if (!impl)
473+ return;
474+
475+ DBG("Acquiring system wakelock");
476+
477+ guint old_source = system_wakelock_source;
478+
479+ system_wakelock_source = g_timeout_add_seconds(SYSTEM_WAKELOCK_DURATION,
480+ system_wakelock_put,
481+ NULL);
482+ if (system_wakelock_source)
483+ wakelock_acquire(system_wakelock);
484+
485+ if (old_source) {
486+ g_source_remove(old_source);
487+ wakelock_release(system_wakelock);
488+ }
489+}
490+
491+int wakelock_create(const char *name, struct wakelock **wakelock)
492+{
493+ if (!impl) {
494+ *wakelock = NULL;
495+ return -EINVAL;
496+ }
497+
498+ return (table.create)(name, wakelock);
499+}
500+
501+int wakelock_free(struct wakelock *wakelock)
502+{
503+ if (!impl)
504+ return -EINVAL;
505+
506+ return table.free(wakelock);
507+}
508+
509+int wakelock_acquire(struct wakelock *wakelock)
510+{
511+ if (!impl)
512+ return -EINVAL;
513+
514+ return table.acquire(wakelock);
515+}
516+
517+int wakelock_release(struct wakelock *wakelock)
518+{
519+ if (!impl)
520+ return -EINVAL;
521+
522+ return table.release(wakelock);
523+}
524+
525+ofono_bool_t wakelock_is_locked(struct wakelock *wakelock) {
526+ if (!impl)
527+ return -EINVAL;
528+
529+ return table.is_locked(wakelock);
530+}
531+
532+int wakelock_plugin_register(const char *name, struct wakelock_table *fns)
533+{
534+ if (impl)
535+ return -EALREADY;
536+
537+ impl = g_strdup(name);
538+ memcpy(&table, fns, sizeof(struct wakelock_table));
539+ return 0;
540+}
541+
542+int wakelock_plugin_unregister(void)
543+{
544+ if (!impl)
545+ return -ENOENT;
546+
547+ memset(&table, 0, sizeof(struct wakelock_table));
548+ g_free(impl);
549+ impl = NULL;
550+
551+ return 0;
552+}
553+
554+int __ofono_wakelock_init(void)
555+{
556+ if (wakelock_create("ofono-system-keepalive", &system_wakelock) < 0)
557+ ofono_warn("Failed to create system keep alive wakelock");
558+
559+ return 0;
560+}
561+
562+void __ofono_wakelock_cleanup(void)
563+{
564+ if (system_wakelock)
565+ wakelock_free(system_wakelock);
566+}

Subscribers

People subscribed via source and target branches