Merge lp:~alfonsosanchezbeato/powerd/ofono-fixes into lp:powerd
- ofono-fixes
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Ricardo Salveti |
Approved revision: | 117 |
Merged at revision: | 121 |
Proposed branch: | lp:~alfonsosanchezbeato/powerd/ofono-fixes |
Merge into: | lp:powerd |
Diff against target: |
586 lines (+370/-94) 4 files modified
src/display.c (+1/-1) src/powerd-internal.h (+20/-2) src/powerd-object.c (+60/-6) src/powerd.cpp (+289/-85) |
To merge this branch: | bzr merge lp:~alfonsosanchezbeato/powerd/ofono-fixes |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ricardo Salveti (community) | Approve | ||
Review via email: mp+212119@code.launchpad.net |
Commit message
* Add support for multiple ofono modems (LP#1295085)
* Handle simultaneous voice calls (LP#1191033)
* Listen to ofono USSD signals
Description of the change
* Add support for multiple ofono modems (LP#1295085)
* Handle simultaneous voice calls (LP#1191033)
* Listen to ofono USSD signals
Tony Espy (awe) wrote : | # |
Ricardo Salveti (rsalveti) wrote : | # |
254 + /* Activate proximity sensor if no previously existing call */
255 + if (g_calls == NULL)
256 + if (powerd_
257 + powerd_
If you check the previous logic to enable/disable the proximity sensor, you'll see that it was only enabled when the call was in the active state, and not when the call was added in the ofono level. As a side effect, the proximity sensor is now enabled even before the call is active (the user accepts the call), which is a regression.
Please do a similar check, as we only want the proximity sensor to be enable when we have at least one active call in place.
- 115. By Alfonso Sanchez-Beato
-
Do not activate proximity sensor when calls are in "incoming" state
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote : | # |
New commit takes state of the call into consideration for activating the proximity sensor. However, I have changed the logic a bit: previously, the sensor was activated when calls moved to either "alerting" or "active" states. Now I do it when the call reaches "dialing" or "active" state.
The rationale is as follows. Taking into account that the usual sequence of states of the calls is (not all transitions are considered):
Outgoing: dialing -> alerting -> active -> disconnected
Incoming: incoming -> active -> disconnected
then I think that it makes sense to activate the sensor when the state of an outgoing call is "dialing" instead of waiting for it to be "alerting", as most people once they press the call button they move their phone near to their ear immediately (while we are still dialing) so they can hear the other party ringing (move to alerting).
So the change makes sure the proximity sensor is off only when the state is "incoming": the user is supposed to be looking at the screen at that moment to decide whether to accept the call or not. We can discuss this further if you thing there is some problem with this.
Ricardo Salveti (rsalveti) wrote : | # |
> New commit takes state of the call into consideration for activating the
> proximity sensor. However, I have changed the logic a bit: previously, the
> sensor was activated when calls moved to either "alerting" or "active" states.
> Now I do it when the call reaches "dialing" or "active" state.
>
> The rationale is as follows. Taking into account that the usual sequence of
> states of the calls is (not all transitions are considered):
>
> Outgoing: dialing -> alerting -> active -> disconnected
>
> Incoming: incoming -> active -> disconnected
>
> then I think that it makes sense to activate the sensor when the state of an
> outgoing call is "dialing" instead of waiting for it to be "alerting", as most
> people once they press the call button they move their phone near to their ear
> immediately (while we are still dialing) so they can hear the other party
> ringing (move to alerting).
>
> So the change makes sure the proximity sensor is off only when the state is
> "incoming": the user is supposed to be looking at the screen at that moment to
> decide whether to accept the call or not. We can discuss this further if you
> thing there is some problem with this.
Makes sense, and it now behaves similarly as done in android.
Just a minor comment:
235 +ofono_
236 + GAsyncResult *res,
237 + gpointer user_data)
238 +{
239 + GDBusProxy *client = G_DBUS_
Indentation here is different from the rest of the file, please change it to be similar to the rest.
Building and testing.
Ricardo Salveti (rsalveti) wrote : | # |
Tested and worked fine, can approve once the minor changes I asked in the previous comment are in place.
We already have a powerd landing slot in progress, once that lands, we can queue this MR.
- 116. By Alfonso Sanchez-Beato
-
Correct powerd.cpp indentations
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote : | # |
Indentations fixed. Just too used to ofono coding style...
How could I collapse the three commits of this MR, as can be done with "git rebase -i"?
Ricardo Salveti (rsalveti) wrote : | # |
> Indentations fixed. Just too used to ofono coding style...
Thanks!
> How could I collapse the three commits of this MR, as can be done with "git
> rebase -i"?
Don't worry about that, they will not show by default when checking the logs from the main branch. I wouldn't worry about rebase with bzr, as that's kind of a pita to do. Git is indeed *way* easier when rebasing commits.
Ricardo Salveti (rsalveti) : | # |
Ricardo Salveti (rsalveti) wrote : | # |
Actually, would you mind merging trunk back before I can land this MR?
- 117. By Alfonso Sanchez-Beato
-
Merge from main branch
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote : | # |
Trunk merged back.
Preview Diff
1 | === modified file 'src/display.c' | |||
2 | --- src/display.c 2014-01-14 03:14:22 +0000 | |||
3 | +++ src/display.c 2014-03-28 08:00:57 +0000 | |||
4 | @@ -153,7 +153,7 @@ | |||
5 | 153 | current_state = state; | 153 | current_state = state; |
6 | 154 | } | 154 | } |
7 | 155 | 155 | ||
9 | 156 | gboolean display_set_power_mode(int display, char *power_mode) | 156 | gboolean display_set_power_mode(int display, const char *power_mode) |
10 | 157 | { | 157 | { |
11 | 158 | GError *error = NULL; | 158 | GError *error = NULL; |
12 | 159 | GDBusProxy *unity_proxy = NULL; | 159 | GDBusProxy *unity_proxy = NULL; |
13 | 160 | 160 | ||
14 | === modified file 'src/powerd-internal.h' | |||
15 | --- src/powerd-internal.h 2014-01-14 03:14:22 +0000 | |||
16 | +++ src/powerd-internal.h 2014-03-28 08:00:57 +0000 | |||
17 | @@ -51,6 +51,12 @@ | |||
18 | 51 | uint ref_count; | 51 | uint ref_count; |
19 | 52 | }; | 52 | }; |
20 | 53 | 53 | ||
21 | 54 | /* Used to track call state */ | ||
22 | 55 | struct call_data { | ||
23 | 56 | char *obj_name; | ||
24 | 57 | GDBusProxy *ofono_proxy; | ||
25 | 58 | }; | ||
26 | 59 | |||
27 | 54 | void powerd_shutdown(void); | 60 | void powerd_shutdown(void); |
28 | 55 | void powerd_exit(int exit_code); | 61 | void powerd_exit(int exit_code); |
29 | 56 | void powerd_hal_signal_activity(void); | 62 | void powerd_hal_signal_activity(void); |
30 | @@ -80,7 +86,7 @@ | |||
31 | 80 | /* Display functions */ | 86 | /* Display functions */ |
32 | 81 | void powerd_brightness_set_value(gint value); | 87 | void powerd_brightness_set_value(gint value); |
33 | 82 | gboolean powerd_display_enabled(void); | 88 | gboolean powerd_display_enabled(void); |
35 | 83 | gboolean display_set_power_mode(int display, char *powerd_mode); | 89 | gboolean display_set_power_mode(int display, const char *powerd_mode); |
36 | 84 | void powerd_set_display_state(struct powerd_display_request *req); | 90 | void powerd_set_display_state(struct powerd_display_request *req); |
37 | 85 | int powerd_display_init(void); | 91 | int powerd_display_init(void); |
38 | 86 | void powerd_proximity_event(gboolean near); | 92 | void powerd_proximity_event(gboolean near); |
39 | @@ -153,16 +159,28 @@ | |||
40 | 153 | gpointer user_data); | 159 | gpointer user_data); |
41 | 154 | void powerd_name_vanished_cb(GDBusConnection *connection, const gchar *name, | 160 | void powerd_name_vanished_cb(GDBusConnection *connection, const gchar *name, |
42 | 155 | gpointer user_data); | 161 | gpointer user_data); |
43 | 162 | void ofono_get_modems_cb(GObject *source_object, GAsyncResult *res, | ||
44 | 163 | gpointer user_data); | ||
45 | 164 | void ofono_voicecall_get_props_cb(GObject *source_object, GAsyncResult *res, | ||
46 | 165 | gpointer user_data); | ||
47 | 156 | 166 | ||
48 | 157 | /* dbus signal handlers */ | 167 | /* dbus signal handlers */ |
49 | 168 | void on_ofono_manager_signal(GDBusProxy *proxy, gchar *sender_name, | ||
50 | 169 | gchar *signal_name, GVariant *parameters, gpointer user_data); | ||
51 | 170 | void on_ofono_voicecall_signal(GDBusProxy *proxy, gchar *sender_name, | ||
52 | 171 | gchar *signal_name, GVariant *parameters, gpointer user_data); | ||
53 | 158 | void on_ofono_voicecallmanager_signal(GDBusProxy *proxy, gchar *sender_name, | 172 | void on_ofono_voicecallmanager_signal(GDBusProxy *proxy, gchar *sender_name, |
54 | 159 | gchar *signal_name, GVariant *parameters, gpointer user_data); | 173 | gchar *signal_name, GVariant *parameters, gpointer user_data); |
55 | 160 | void on_ofono_messagemanager_signal(GDBusProxy *proxy, gchar *sender_name, | 174 | void on_ofono_messagemanager_signal(GDBusProxy *proxy, gchar *sender_name, |
56 | 161 | gchar *signal_name, GVariant *parameters, gpointer user_data); | 175 | gchar *signal_name, GVariant *parameters, gpointer user_data); |
58 | 162 | void on_ofono_voicecall_signal(GDBusProxy *proxy, gchar *sender_name, | 176 | void on_ofono_ussd_signal(GDBusProxy *proxy, gchar *sender_name, |
59 | 163 | gchar *signal_name, GVariant *parameters, gpointer user_data); | 177 | gchar *signal_name, GVariant *parameters, gpointer user_data); |
60 | 164 | 178 | ||
61 | 165 | /* dbus proxy async setup */ | 179 | /* dbus proxy async setup */ |
62 | 180 | void ofono_manager_proxy_connect_cb(GObject *source_object, GAsyncResult *res, | ||
63 | 181 | gpointer user_data); | ||
64 | 182 | void ofono_voicecall_proxy_connect_cb(GObject *source_object, GAsyncResult *res, | ||
65 | 183 | gpointer user_data); | ||
66 | 166 | void ofono_proxy_connect_cb(GObject *source_object, GAsyncResult *res, | 184 | void ofono_proxy_connect_cb(GObject *source_object, GAsyncResult *res, |
67 | 167 | gpointer user_data); | 185 | gpointer user_data); |
68 | 168 | 186 | ||
69 | 169 | 187 | ||
70 | === modified file 'src/powerd-object.c' | |||
71 | --- src/powerd-object.c 2013-09-12 14:23:02 +0000 | |||
72 | +++ src/powerd-object.c 2014-03-28 08:00:57 +0000 | |||
73 | @@ -259,6 +259,60 @@ | |||
74 | 259 | } | 259 | } |
75 | 260 | 260 | ||
76 | 261 | void | 261 | void |
77 | 262 | ofono_manager_proxy_connect_cb(GObject *source_object, | ||
78 | 263 | GAsyncResult *res, | ||
79 | 264 | gpointer user_data) | ||
80 | 265 | { | ||
81 | 266 | GError *error = NULL; | ||
82 | 267 | GDBusProxy *ofono_proxy; | ||
83 | 268 | |||
84 | 269 | ofono_proxy = g_dbus_proxy_new_finish(res, &error); | ||
85 | 270 | if (error) { | ||
86 | 271 | powerd_warn("%s failed: %s", __func__, error->message); | ||
87 | 272 | g_error_free(error); | ||
88 | 273 | return; | ||
89 | 274 | } | ||
90 | 275 | |||
91 | 276 | /* Register for insertion and removal of modems */ | ||
92 | 277 | g_signal_connect(ofono_proxy, "g-signal", | ||
93 | 278 | G_CALLBACK(on_ofono_manager_signal), NULL); | ||
94 | 279 | |||
95 | 280 | /* Get current modems */ | ||
96 | 281 | g_dbus_proxy_call(ofono_proxy, "GetModems", NULL, | ||
97 | 282 | G_DBUS_CALL_FLAGS_NONE, -1, NULL, | ||
98 | 283 | ofono_get_modems_cb, NULL); | ||
99 | 284 | } | ||
100 | 285 | |||
101 | 286 | void | ||
102 | 287 | ofono_voicecall_proxy_connect_cb(GObject *source_object, | ||
103 | 288 | GAsyncResult *res, | ||
104 | 289 | gpointer user_data) | ||
105 | 290 | { | ||
106 | 291 | GError *error = NULL; | ||
107 | 292 | GDBusProxy *ofono_proxy; | ||
108 | 293 | struct call_data *call; | ||
109 | 294 | |||
110 | 295 | ofono_proxy = g_dbus_proxy_new_finish(res, &error); | ||
111 | 296 | if (error) { | ||
112 | 297 | powerd_warn("%s failed: %s", __func__, error->message); | ||
113 | 298 | g_error_free(error); | ||
114 | 299 | return; | ||
115 | 300 | } | ||
116 | 301 | |||
117 | 302 | call = user_data; | ||
118 | 303 | call->ofono_proxy = ofono_proxy; | ||
119 | 304 | |||
120 | 305 | /* Register for voicecall signals */ | ||
121 | 306 | g_signal_connect(ofono_proxy, "g-signal", | ||
122 | 307 | G_CALLBACK(on_ofono_voicecall_signal), NULL); | ||
123 | 308 | |||
124 | 309 | /* Get current voice call state */ | ||
125 | 310 | g_dbus_proxy_call(ofono_proxy, "GetProperties", NULL, | ||
126 | 311 | G_DBUS_CALL_FLAGS_NONE, -1, NULL, | ||
127 | 312 | ofono_voicecall_get_props_cb, NULL); | ||
128 | 313 | } | ||
129 | 314 | |||
130 | 315 | void | ||
131 | 262 | ofono_proxy_connect_cb(GObject *source_object, | 316 | ofono_proxy_connect_cb(GObject *source_object, |
132 | 263 | GAsyncResult *res, | 317 | GAsyncResult *res, |
133 | 264 | gpointer user_data) | 318 | gpointer user_data) |
134 | @@ -275,18 +329,18 @@ | |||
135 | 275 | else { | 329 | else { |
136 | 276 | interface_name = g_dbus_proxy_get_interface_name(ofono_proxy); | 330 | interface_name = g_dbus_proxy_get_interface_name(ofono_proxy); |
137 | 277 | powerd_debug("ofono_proxy_connect_cb: proxy is %s", interface_name); | 331 | powerd_debug("ofono_proxy_connect_cb: proxy is %s", interface_name); |
143 | 278 | if (!strcmp(interface_name,"org.ofono.VoiceCall")) { | 332 | if (!strcmp(interface_name, "org.ofono.VoiceCallManager")) { |
139 | 279 | g_signal_connect(ofono_proxy, "g-signal", | ||
140 | 280 | G_CALLBACK (on_ofono_voicecall_signal), NULL); | ||
141 | 281 | } | ||
142 | 282 | else if (!strcmp(interface_name,"org.ofono.VoiceCallManager")) { | ||
144 | 283 | g_signal_connect(ofono_proxy, "g-signal", | 333 | g_signal_connect(ofono_proxy, "g-signal", |
145 | 284 | G_CALLBACK (on_ofono_voicecallmanager_signal), NULL); | 334 | G_CALLBACK (on_ofono_voicecallmanager_signal), NULL); |
146 | 285 | } | 335 | } |
148 | 286 | else if (!strcmp(interface_name,"org.ofono.MessageManager")) { | 336 | else if (!strcmp(interface_name, "org.ofono.MessageManager")) { |
149 | 287 | g_signal_connect(ofono_proxy, "g-signal", | 337 | g_signal_connect(ofono_proxy, "g-signal", |
150 | 288 | G_CALLBACK (on_ofono_messagemanager_signal), NULL); | 338 | G_CALLBACK (on_ofono_messagemanager_signal), NULL); |
151 | 289 | } | 339 | } |
152 | 340 | else if (!strcmp(interface_name, "org.ofono.SupplementaryServices")) { | ||
153 | 341 | g_signal_connect(ofono_proxy, "g-signal", | ||
154 | 342 | G_CALLBACK (on_ofono_ussd_signal), NULL); | ||
155 | 343 | } | ||
156 | 290 | else { | 344 | else { |
157 | 291 | powerd_warn("unknown interface name for this proxy, ignoring"); | 345 | powerd_warn("unknown interface name for this proxy, ignoring"); |
158 | 292 | } | 346 | } |
159 | 293 | 347 | ||
160 | === modified file 'src/powerd.cpp' | |||
161 | --- src/powerd.cpp 2014-03-27 21:00:43 +0000 | |||
162 | +++ src/powerd.cpp 2014-03-28 08:00:57 +0000 | |||
163 | @@ -125,6 +125,31 @@ | |||
164 | 125 | POWERD_DISPLAY_FLAG_BRIGHT /* flags */ | 125 | POWERD_DISPLAY_FLAG_BRIGHT /* flags */ |
165 | 126 | }; | 126 | }; |
166 | 127 | 127 | ||
167 | 128 | /* List with detected modems */ | ||
168 | 129 | static GSList *g_modems = NULL; | ||
169 | 130 | |||
170 | 131 | static void free_call_data(void *data) | ||
171 | 132 | { | ||
172 | 133 | struct call_data *call = (struct call_data *) data; | ||
173 | 134 | g_free(call->obj_name); | ||
174 | 135 | if (call->ofono_proxy) | ||
175 | 136 | g_object_unref(call->ofono_proxy); | ||
176 | 137 | } | ||
177 | 138 | |||
178 | 139 | static gint call_data_cmp(gconstpointer a, gconstpointer b) | ||
179 | 140 | { | ||
180 | 141 | const struct call_data *call = (const struct call_data *) a; | ||
181 | 142 | const char *call_name = (const char *) b; | ||
182 | 143 | |||
183 | 144 | return strcmp(call->obj_name, call_name); | ||
184 | 145 | } | ||
185 | 146 | |||
186 | 147 | /* List with existing calls */ | ||
187 | 148 | static GSList *g_calls = NULL; | ||
188 | 149 | |||
189 | 150 | /* Flag set when proximity sensor is on */ | ||
190 | 151 | static gboolean g_proximity_on = FALSE; | ||
191 | 152 | |||
192 | 128 | gboolean activity_monitor(gpointer data); | 153 | gboolean activity_monitor(gpointer data); |
193 | 129 | void update_screen_state(int state); | 154 | void update_screen_state(int state); |
194 | 130 | 155 | ||
195 | @@ -294,6 +319,184 @@ | |||
196 | 294 | powerd_reset_activity_timer(1); | 319 | powerd_reset_activity_timer(1); |
197 | 295 | } | 320 | } |
198 | 296 | 321 | ||
199 | 322 | static void watch_modem(const char *modem) | ||
200 | 323 | { | ||
201 | 324 | /* for incoming SMS signals */ | ||
202 | 325 | g_dbus_proxy_new_for_bus(G_BUS_TYPE_SYSTEM, | ||
203 | 326 | G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, | ||
204 | 327 | NULL, | ||
205 | 328 | "org.ofono", | ||
206 | 329 | modem, | ||
207 | 330 | "org.ofono.MessageManager", | ||
208 | 331 | NULL, | ||
209 | 332 | (GAsyncReadyCallback)ofono_proxy_connect_cb, | ||
210 | 333 | NULL); | ||
211 | 334 | |||
212 | 335 | /* for incoming calls Added/Removed signals */ | ||
213 | 336 | g_dbus_proxy_new_for_bus(G_BUS_TYPE_SYSTEM, | ||
214 | 337 | G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, | ||
215 | 338 | NULL, | ||
216 | 339 | "org.ofono", | ||
217 | 340 | modem, | ||
218 | 341 | "org.ofono.VoiceCallManager", | ||
219 | 342 | NULL, | ||
220 | 343 | (GAsyncReadyCallback)ofono_proxy_connect_cb, | ||
221 | 344 | NULL); | ||
222 | 345 | |||
223 | 346 | /* for USSD notifications/network requests */ | ||
224 | 347 | g_dbus_proxy_new_for_bus(G_BUS_TYPE_SYSTEM, | ||
225 | 348 | G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, | ||
226 | 349 | NULL, | ||
227 | 350 | "org.ofono", | ||
228 | 351 | modem, | ||
229 | 352 | "org.ofono.SupplementaryServices", | ||
230 | 353 | NULL, | ||
231 | 354 | (GAsyncReadyCallback)ofono_proxy_connect_cb, | ||
232 | 355 | NULL); | ||
233 | 356 | } | ||
234 | 357 | |||
235 | 358 | void | ||
236 | 359 | ofono_get_modems_cb(GObject *source_object, | ||
237 | 360 | GAsyncResult *res, | ||
238 | 361 | gpointer user_data) | ||
239 | 362 | { | ||
240 | 363 | GDBusProxy *client = G_DBUS_PROXY(source_object); | ||
241 | 364 | GVariant *result; | ||
242 | 365 | GVariant *item; | ||
243 | 366 | GError *error = NULL; | ||
244 | 367 | GVariantIter *iter; | ||
245 | 368 | |||
246 | 369 | result = g_dbus_proxy_call_finish(client, res, &error); | ||
247 | 370 | if (result == NULL) { | ||
248 | 371 | powerd_warn("%s: call error", __func__); | ||
249 | 372 | return; | ||
250 | 373 | } | ||
251 | 374 | |||
252 | 375 | g_variant_get(result, "(a(oa{sv}))", &iter); | ||
253 | 376 | while ((item = g_variant_iter_next_value(iter))) { | ||
254 | 377 | const char *obj_path; | ||
255 | 378 | |||
256 | 379 | g_variant_get_child(item, 0, "&o", &obj_path); | ||
257 | 380 | |||
258 | 381 | if (g_slist_find_custom(g_modems, obj_path, (GCompareFunc) strcmp) | ||
259 | 382 | == NULL) { | ||
260 | 383 | powerd_debug("active ofono modem %s", obj_path); | ||
261 | 384 | g_modems = g_slist_prepend(g_modems, g_strdup(obj_path)); | ||
262 | 385 | watch_modem(obj_path); | ||
263 | 386 | } | ||
264 | 387 | |||
265 | 388 | g_variant_unref(item); | ||
266 | 389 | } | ||
267 | 390 | |||
268 | 391 | g_variant_unref(result); | ||
269 | 392 | } | ||
270 | 393 | |||
271 | 394 | static void notify_proximity_sensor(const char *call_state) | ||
272 | 395 | { | ||
273 | 396 | /* | ||
274 | 397 | * This function enables the proximity sensor in case the new state of the | ||
275 | 398 | * call is: | ||
276 | 399 | * | ||
277 | 400 | * Active - meaning, the call is in progress --> Proximity On | ||
278 | 401 | * Dialing - a signal made on outbound calls only which means that | ||
279 | 402 | * we have started to talk to the network, but the call has not | ||
280 | 403 | * been picked up. --> Proximity On (this signal is not | ||
281 | 404 | * sent on inbound calls) | ||
282 | 405 | * Note that the proximity sensor is not activated for "incoming" state | ||
283 | 406 | * For more details on states see voicecall-api.txt in the ofono source | ||
284 | 407 | */ | ||
285 | 408 | |||
286 | 409 | if (g_proximity_on) | ||
287 | 410 | return; | ||
288 | 411 | |||
289 | 412 | if (strcmp("active", call_state) == 0 | ||
290 | 413 | || strcmp("dialing", call_state) == 0) { | ||
291 | 414 | if (powerd_add_display_request(&prox_sensor_req, "prox-sensor")) | ||
292 | 415 | powerd_warn("Request to use proximity sensor failed"); | ||
293 | 416 | g_proximity_on = TRUE; | ||
294 | 417 | } | ||
295 | 418 | } | ||
296 | 419 | |||
297 | 420 | static void deactivate_proximity_sensor(void) | ||
298 | 421 | { | ||
299 | 422 | if (!g_proximity_on) | ||
300 | 423 | return; | ||
301 | 424 | |||
302 | 425 | powerd_remove_display_request(prox_sensor_req.cookie); | ||
303 | 426 | g_proximity_on = FALSE; | ||
304 | 427 | } | ||
305 | 428 | |||
306 | 429 | void | ||
307 | 430 | ofono_voicecall_get_props_cb(GObject *source_object, GAsyncResult *res, | ||
308 | 431 | gpointer user_data) | ||
309 | 432 | { | ||
310 | 433 | GDBusProxy *client = G_DBUS_PROXY(source_object); | ||
311 | 434 | GVariant *result; | ||
312 | 435 | GVariant *item; | ||
313 | 436 | GError *error = NULL; | ||
314 | 437 | GVariantIter *iter = NULL; | ||
315 | 438 | |||
316 | 439 | result = g_dbus_proxy_call_finish(client, res, &error); | ||
317 | 440 | if (result == NULL) { | ||
318 | 441 | powerd_warn("%s: call error", __func__); | ||
319 | 442 | return; | ||
320 | 443 | } | ||
321 | 444 | |||
322 | 445 | g_variant_get(result, "(a{sv})", &iter); | ||
323 | 446 | |||
324 | 447 | while ((item = g_variant_iter_next_value(iter))) { | ||
325 | 448 | GVariant *value = NULL; | ||
326 | 449 | const char *prop_name = NULL; | ||
327 | 450 | const char *call_state = NULL; | ||
328 | 451 | |||
329 | 452 | g_variant_get(item, "{&sv}", &prop_name, &value); | ||
330 | 453 | |||
331 | 454 | if (strcmp("State", prop_name) == 0) { | ||
332 | 455 | g_variant_get(value, "&s", &call_state); | ||
333 | 456 | notify_proximity_sensor(call_state); | ||
334 | 457 | powerd_info("GetProperties. Call State = %s", call_state); | ||
335 | 458 | } | ||
336 | 459 | |||
337 | 460 | g_variant_unref(value); | ||
338 | 461 | g_variant_unref(item); | ||
339 | 462 | } | ||
340 | 463 | |||
341 | 464 | g_variant_unref(result); | ||
342 | 465 | } | ||
343 | 466 | |||
344 | 467 | void on_ofono_manager_signal(GDBusProxy *proxy, gchar *sender_name, | ||
345 | 468 | gchar *signal_name, GVariant *parameters, gpointer user_data) | ||
346 | 469 | { | ||
347 | 470 | const gchar *object_path; | ||
348 | 471 | GVariant *tmp; | ||
349 | 472 | char *modem; | ||
350 | 473 | GSList *node; | ||
351 | 474 | |||
352 | 475 | tmp = g_variant_get_child_value(parameters, 0); | ||
353 | 476 | |||
354 | 477 | object_path = g_variant_get_string(tmp, NULL); | ||
355 | 478 | node = g_slist_find_custom(g_modems, object_path, (GCompareFunc) strcmp); | ||
356 | 479 | |||
357 | 480 | if (strcmp("ModemAdded", signal_name) == 0) { | ||
358 | 481 | /* Add if not already in list */ | ||
359 | 482 | if (node == NULL) { | ||
360 | 483 | powerd_debug("watching ofono modem %s", object_path); | ||
361 | 484 | modem = g_strdup(object_path); | ||
362 | 485 | g_modems = g_slist_prepend(g_modems, modem); | ||
363 | 486 | watch_modem(modem); | ||
364 | 487 | } | ||
365 | 488 | } else if(strcmp("ModemRemoved", signal_name) == 0) { | ||
366 | 489 | /* Remove if found in list */ | ||
367 | 490 | if (node != NULL) { | ||
368 | 491 | powerd_debug("stop watch on ofono modem %s", object_path); | ||
369 | 492 | g_free(g_modems->data); | ||
370 | 493 | g_modems = g_slist_delete_link(g_modems, node); | ||
371 | 494 | } | ||
372 | 495 | } | ||
373 | 496 | |||
374 | 497 | g_variant_unref(tmp); | ||
375 | 498 | } | ||
376 | 499 | |||
377 | 297 | void | 500 | void |
378 | 298 | on_ofono_voicecallmanager_signal (GDBusProxy *proxy, | 501 | on_ofono_voicecallmanager_signal (GDBusProxy *proxy, |
379 | 299 | gchar *sender_name, | 502 | gchar *sender_name, |
380 | @@ -301,12 +504,76 @@ | |||
381 | 301 | GVariant *parameters, | 504 | GVariant *parameters, |
382 | 302 | gpointer user_data) | 505 | gpointer user_data) |
383 | 303 | { | 506 | { |
386 | 304 | powerd_debug("we get signal from %s: %s", sender_name, signal_name); | 507 | GVariant *tmp; |
387 | 305 | /* from org.ofono.VoiceCallManager - a call was added */ | 508 | |
388 | 306 | if (!strcmp(signal_name, "CallAdded")) { | 509 | if (!strcmp(signal_name, "CallAdded")) { |
390 | 307 | powerd_debug("Waking up the device - Incoming Call"); | 510 | struct call_data *call; |
391 | 511 | |||
392 | 308 | powerd_display_clear_override(POWERD_OVERRIDE_REASON_POWER_BUTTON); | 512 | powerd_display_clear_override(POWERD_OVERRIDE_REASON_POWER_BUTTON); |
393 | 309 | powerd_reset_activity_timer(1); | 513 | powerd_reset_activity_timer(1); |
394 | 514 | |||
395 | 515 | call = (struct call_data *) calloc(1, sizeof(*call)); | ||
396 | 516 | tmp = g_variant_get_child_value(parameters, 0); | ||
397 | 517 | call->obj_name = g_variant_dup_string(tmp, NULL); | ||
398 | 518 | g_calls = g_slist_prepend(g_calls, call); | ||
399 | 519 | |||
400 | 520 | powerd_info("%s incoming call", call->obj_name); | ||
401 | 521 | |||
402 | 522 | /* Connect to voicecall interface */ | ||
403 | 523 | g_dbus_proxy_new_for_bus(G_BUS_TYPE_SYSTEM, | ||
404 | 524 | G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, | ||
405 | 525 | NULL, | ||
406 | 526 | "org.ofono", | ||
407 | 527 | call->obj_name, | ||
408 | 528 | "org.ofono.VoiceCall", | ||
409 | 529 | NULL, | ||
410 | 530 | (GAsyncReadyCallback) ofono_voicecall_proxy_connect_cb, | ||
411 | 531 | call); | ||
412 | 532 | |||
413 | 533 | g_variant_unref(tmp); | ||
414 | 534 | |||
415 | 535 | } else if (!strcmp(signal_name, "CallRemoved")) { | ||
416 | 536 | const gchar *object_path; | ||
417 | 537 | GSList *node; | ||
418 | 538 | |||
419 | 539 | tmp = g_variant_get_child_value(parameters, 0); | ||
420 | 540 | object_path = g_variant_get_string(tmp, NULL); | ||
421 | 541 | node = g_slist_find_custom(g_calls, object_path, call_data_cmp); | ||
422 | 542 | if (node != NULL) { | ||
423 | 543 | free_call_data(node->data); | ||
424 | 544 | g_calls = g_slist_delete_link(g_calls, node); | ||
425 | 545 | powerd_info("%s call removed", object_path); | ||
426 | 546 | } | ||
427 | 547 | |||
428 | 548 | if (g_calls == NULL) | ||
429 | 549 | deactivate_proximity_sensor(); | ||
430 | 550 | |||
431 | 551 | g_variant_unref(tmp); | ||
432 | 552 | } | ||
433 | 553 | } | ||
434 | 554 | |||
435 | 555 | void | ||
436 | 556 | on_ofono_voicecall_signal (GDBusProxy *proxy, | ||
437 | 557 | gchar *sender_name, | ||
438 | 558 | gchar *signal_name, | ||
439 | 559 | GVariant *parameters, | ||
440 | 560 | gpointer user_data) | ||
441 | 561 | { | ||
442 | 562 | GVariant *value = NULL; | ||
443 | 563 | const char *prop_name = NULL; | ||
444 | 564 | const char *call_state = NULL; | ||
445 | 565 | |||
446 | 566 | if (!strcmp(signal_name, "PropertyChanged")) { | ||
447 | 567 | g_variant_get(parameters, "(&sv)", &prop_name, &value); | ||
448 | 568 | |||
449 | 569 | if (!strcmp(prop_name, "State")) { | ||
450 | 570 | g_variant_get(value, "&s", &call_state); | ||
451 | 571 | |||
452 | 572 | powerd_info("Call State = %s", call_state); | ||
453 | 573 | notify_proximity_sensor(call_state); | ||
454 | 574 | } | ||
455 | 575 | |||
456 | 576 | g_variant_unref(value); | ||
457 | 310 | } | 577 | } |
458 | 311 | } | 578 | } |
459 | 312 | 579 | ||
460 | @@ -327,63 +594,19 @@ | |||
461 | 327 | } | 594 | } |
462 | 328 | } | 595 | } |
463 | 329 | 596 | ||
466 | 330 | void | 597 | void on_ofono_ussd_signal(GDBusProxy *proxy, |
465 | 331 | on_ofono_voicecall_signal (GDBusProxy *proxy, | ||
467 | 332 | gchar *sender_name, | 598 | gchar *sender_name, |
468 | 333 | gchar *signal_name, | 599 | gchar *signal_name, |
469 | 334 | GVariant *parameters, | 600 | GVariant *parameters, |
470 | 335 | gpointer user_data) | 601 | gpointer user_data) |
471 | 336 | { | 602 | { |
472 | 337 | GVariant *value = NULL; | ||
473 | 338 | const char *prop_name; | ||
474 | 339 | const char *prop_value; | ||
475 | 340 | static gboolean alerted = FALSE; | ||
476 | 341 | |||
477 | 342 | powerd_debug("we get signal from %s: %s", sender_name, signal_name); | 603 | powerd_debug("we get signal from %s: %s", sender_name, signal_name); |
522 | 343 | 604 | /* from org.ofono.MessageManager */ | |
523 | 344 | /* This function enables and disables the proximity sensor based | 605 | if ((!strcmp(signal_name, "NotificationReceived")) || |
524 | 345 | * on the state of the call. | 606 | (!strcmp(signal_name, "RequestReceived"))) { |
525 | 346 | * | 607 | powerd_debug("Waking up the device - Incoming USSD"); |
526 | 347 | * Active - meaning, the call is in progress --> Proximity On | 608 | powerd_display_clear_override(POWERD_OVERRIDE_REASON_POWER_BUTTON); |
527 | 348 | * Alerting - a signal made on outbound calls only which means that | 609 | powerd_reset_activity_timer(1); |
484 | 349 | * the phone is ringing on the other side, but has not | ||
485 | 350 | * been picked up. --> Proximity On (this signal is not | ||
486 | 351 | * sent on inbound calls) | ||
487 | 352 | * Disconnected - the call is over. --> Proximity Off. | ||
488 | 353 | * | ||
489 | 354 | * For more details on states see voicecall-api.txt in the ofono source | ||
490 | 355 | */ | ||
491 | 356 | |||
492 | 357 | /* Note: As of June 13, 2013, the phone cannot successfully | ||
493 | 358 | * accept a call while another call is in progress. When this is fixed | ||
494 | 359 | * the code below will need to be rewritten to handle multiple | ||
495 | 360 | * active/disconnected signals. LP: #1191033 (mfisch) */ | ||
496 | 361 | |||
497 | 362 | if (!strcmp(signal_name, "PropertyChanged")) { | ||
498 | 363 | g_variant_get(parameters, "(&sv)", &prop_name, &value); | ||
499 | 364 | if (!strcmp(prop_name,"State")) { | ||
500 | 365 | g_variant_get(value, "&s", &prop_value); | ||
501 | 366 | powerd_debug("Call State = %s", prop_value); | ||
502 | 367 | if (!strcmp(prop_value,"active")) { | ||
503 | 368 | if (!alerted) { | ||
504 | 369 | //call is active, enable sensor | ||
505 | 370 | if (powerd_add_display_request(&prox_sensor_req, "prox-sensor")) | ||
506 | 371 | powerd_warn("Request to use proximity sensor failed"); | ||
507 | 372 | } | ||
508 | 373 | } | ||
509 | 374 | if (!strcmp(prop_value,"alerting")) { | ||
510 | 375 | alerted = TRUE; | ||
511 | 376 | //call is altering, enable sensor | ||
512 | 377 | if (powerd_add_display_request(&prox_sensor_req, "prox-sensor")) | ||
513 | 378 | powerd_warn("Request to use proximity sensor failed"); | ||
514 | 379 | } | ||
515 | 380 | else if (!strcmp(prop_value,"disconnected")) { | ||
516 | 381 | alerted = FALSE; | ||
517 | 382 | //call is disconnected, disable sensor | ||
518 | 383 | powerd_remove_display_request(prox_sensor_req.cookie); | ||
519 | 384 | } | ||
520 | 385 | g_variant_unref(value); | ||
521 | 386 | } | ||
528 | 387 | } | 610 | } |
529 | 388 | } | 611 | } |
530 | 389 | 612 | ||
531 | @@ -445,37 +668,15 @@ | |||
532 | 445 | powerd_name_acquired_cb, powerd_name_lost_cb, NULL, NULL); | 668 | powerd_name_acquired_cb, powerd_name_lost_cb, NULL, NULL); |
533 | 446 | powerd_debug("owner id: %u", name_id); | 669 | powerd_debug("owner id: %u", name_id); |
534 | 447 | 670 | ||
566 | 448 | /* for incoming SMS signals */ | 671 | /* Listen to modem creation */ |
567 | 449 | g_dbus_proxy_new_for_bus(G_BUS_TYPE_SYSTEM, | 672 | g_dbus_proxy_new_for_bus(G_BUS_TYPE_SYSTEM, |
568 | 450 | G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, | 673 | G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, |
569 | 451 | NULL, | 674 | NULL, |
570 | 452 | "org.ofono", | 675 | "org.ofono", |
571 | 453 | "/ril_0", | 676 | "/", |
572 | 454 | "org.ofono.MessageManager", | 677 | "org.ofono.Manager", |
573 | 455 | NULL, | 678 | NULL, |
574 | 456 | (GAsyncReadyCallback)ofono_proxy_connect_cb, | 679 | (GAsyncReadyCallback) ofono_manager_proxy_connect_cb, |
544 | 457 | NULL); | ||
545 | 458 | |||
546 | 459 | /* for incoming calls Added/Removed signals */ | ||
547 | 460 | g_dbus_proxy_new_for_bus(G_BUS_TYPE_SYSTEM, | ||
548 | 461 | G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, | ||
549 | 462 | NULL, | ||
550 | 463 | "org.ofono", | ||
551 | 464 | "/ril_0", | ||
552 | 465 | "org.ofono.VoiceCallManager", | ||
553 | 466 | NULL, | ||
554 | 467 | (GAsyncReadyCallback)ofono_proxy_connect_cb, | ||
555 | 468 | NULL); | ||
556 | 469 | |||
557 | 470 | /* for answering a call/hanging up signals */ | ||
558 | 471 | g_dbus_proxy_new_for_bus(G_BUS_TYPE_SYSTEM, | ||
559 | 472 | G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, | ||
560 | 473 | NULL, | ||
561 | 474 | "org.ofono", | ||
562 | 475 | "/ril_0/voicecall01", | ||
563 | 476 | "org.ofono.VoiceCall", | ||
564 | 477 | NULL, | ||
565 | 478 | (GAsyncReadyCallback)ofono_proxy_connect_cb, | ||
575 | 479 | NULL); | 680 | NULL); |
576 | 480 | 681 | ||
577 | 481 | /* Init this first, data is used by other inits */ | 682 | /* Init this first, data is used by other inits */ |
578 | @@ -547,5 +748,8 @@ | |||
579 | 547 | power_request_deinit(); | 748 | power_request_deinit(); |
580 | 548 | powerd_client_deinit(); | 749 | powerd_client_deinit(); |
581 | 549 | powerd_stats_deinit(); | 750 | powerd_stats_deinit(); |
582 | 751 | g_slist_free_full(g_modems, g_free); | ||
583 | 752 | g_slist_free_full(g_calls, free_call_data); | ||
584 | 753 | |||
585 | 550 | return g_exit_code; | 754 | return g_exit_code; |
586 | 551 | } | 755 | } |
The overall changes look good to me.
That said, I've discussed with rsalveti and he said he'd claim the review, so I'll leave it to him to approve.