/
tklock.c
7470 lines (6148 loc) · 225 KB
1
2
3
4
5
/**
* @file tklock.c
* This file implements the touchscreen/keypad lock component
* of the Mode Control Entity
* <p>
6
* Copyright © 2004-2011 Nokia Corporation and/or its subsidiary(-ies).
7
* Copyright (C) 2012-2019 Jolla Ltd.
8
9
* <p>
* @author David Weinehall <david.weinehall@nokia.com>
10
11
12
13
14
15
16
* @author Tapio Rantala <ext-tapio.rantala@nokia.com>
* @author Santtu Lakkala <ext-santtu.1.lakkala@nokia.com>
* @author Jukka Turunen <ext-jukka.t.turunen@nokia.com>
* @author Irina Bezruk <ext-irina.bezruk@nokia.com>
* @author Kalle Jokiniemi <kalle.jokiniemi@jolla.com>
* @author Mika Laitio <lamikr@pilppa.org>
* @author Markus Lehtonen <markus.lehtonen@iki.fi>
17
* @author Simo Piiroinen <simo.piiroinen@jollamobile.com>
18
19
* @author Vesa Halttunen <vesa.halttunen@jollamobile.com>
* @author Andrew den Exter <andrew.den.exter@jolla.com>
20
21
22
23
24
25
26
27
28
29
30
31
32
33
*
* mce is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation.
*
* mce is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with mce. If not, see <http://www.gnu.org/licenses/>.
*/
34
#include "tklock.h"
35
36
#include "mce-common.h"
37
#include "mce-log.h"
38
#include "mce-lib.h"
39
#include "mce-io.h"
40
#include "mce-setting.h"
41
#include "mce-dbus.h"
42
#include "mce-hbtimer.h"
43
#include "evdev.h"
44
45
46
47
48
#ifdef ENABLE_WAKELOCKS
# include "libwakelock.h"
#endif
49
#include "modules/doubletap.h"
50
#include "modules/display.h"
51
52
53
54
55
56
57
58
#include "systemui/dbus-names.h"
#include "systemui/tklock-dbus-names.h"
#include <linux/input.h>
#include <unistd.h>
#include <string.h>
59
60
#include <fcntl.h>
#include <errno.h>
61
62
63
64
65
66
#include <mce/dbus-names.h>
#include <mce/mode-names.h>
#include <glib/gstdio.h>
67
68
69
70
71
72
73
74
75
76
77
typedef enum
{
/** No autorelock triggers */
AUTORELOCK_NO_TRIGGERS,
/** Autorelock on keyboard slide closed */
AUTORELOCK_KBD_SLIDE,
/** Autorelock on lens cover */
AUTORELOCK_LENS_COVER,
} autorelock_t;
78
79
80
81
/** Helper for evaluation number of items in an array */
#define numof(a) (sizeof(a)/sizeof*(a))
82
83
84
85
/* ========================================================================= *
* CONSTANTS
* ========================================================================= */
86
87
#define MODULE_NAME "tklock"
88
89
90
91
92
93
/** Max valid time_t value in milliseconds */
#define MAX_TICK (INT_MAX * (int64_t)1000)
/** Min valid time_t value in milliseconds */
#define MIN_TICK 0
94
95
96
/** Maximum number of concurrent notification ui exceptions */
#define TKLOCK_NOTIF_SLOTS 32
97
98
99
100
101
102
103
104
105
/** How long to wait for lid close after low lux [ms] */
#define TKLOCK_LIDFILTER_SET_WAIT_FOR_CLOSE_DELAY 1500
/** How long to wait for low lux after lid close [ms] */
#define TKLOCK_LIDFILTER_SET_WAIT_FOR_DARK_DELAY 1200
/** How long to wait for high lux after lid open [ms] */
#define TKLOCK_LIDFILTER_SET_WAIT_FOR_LIGHT_DELAY 1200
106
107
108
109
/* ========================================================================= *
* DATATYPES
* ========================================================================= */
110
111
112
113
114
115
116
117
typedef struct
{
/** BOOTTIME tick when notification autostops */
int64_t ns_until;
/** Amount of ms autostop extends from user input */
int64_t ns_renew;
118
119
120
/** Private D-Bus name of the slot owner */
gchar *ns_owner;
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/** Assumed unique identification string */
gchar *ns_name;
} tklock_notif_slot_t;
typedef struct
{
/** Array of notification slots */
tklock_notif_slot_t tn_slot[TKLOCK_NOTIF_SLOTS];
/** BOOTTIME linger tick from deactivated slots */
int64_t tn_linger;
/** Timer id for autostopping notification slots */
guint tn_autostop_id;
137
138
139
/** Slot owner D-Bus name monitoring list */
GSList *tn_monitor_list;
140
141
} tklock_notif_state_t;
142
143
144
145
146
147
148
149
150
151
152
/** Proximity sensor history */
typedef struct
{
/** Monotonic timestamp, ms resolution */
int64_t tick;
/** Proximity sensor state */
cover_state_t state;
} ps_history_t;
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/** Ambient light lux value mapped into enumerated states
*
* In case the lid sensor can't be trusted for some reason, data from
* ambient light sensor heuristics can be used for avoiding incorrect
* blank/unblank actions.
*
* For this purpose the raw data from ambient light sensor is tracked
* and mapped in to three states:
*
* - TKLOCK_LIDLIGHT_NA: The data from als is not applicable for filtering.
* - TKLOCK_LIDLIGHT_LO: The als indicates darkness.
* - TKLOCK_LIDLIGHT_HI: The als indicates some amount of light.
*/
typedef enum
{
/* Light level is not applicable for state evaluation */
TKLOCK_LIDLIGHT_NA,
/* Light level equals complete darkness */
TKLOCK_LIDLIGHT_LO,
/* Light level equals at least some light */
TKLOCK_LIDLIGHT_HI,
} tklock_lidlight_t;
178
179
180
/* ========================================================================= *
* PROTOTYPES
* ========================================================================= */
181
182
183
184
// datapipe values and triggers
static void tklock_datapipe_system_state_cb(gconstpointer data);
185
static void tklock_datapipe_devicelock_state_cb(gconstpointer data);
186
static void tklock_datapipe_devicelock_state_cb2(gpointer aptr);
187
static void tklock_datapipe_resume_detected_event_cb(gconstpointer data);
188
static void tklock_datapipe_devicelock_service_state_cb(gconstpointer data);
189
190
static void tklock_datapipe_lipstick_service_state_cb(gconstpointer data);
static void tklock_datapipe_osupdate_running_cb(gconstpointer data);
191
static void tklock_datapipe_shutting_down_cb(gconstpointer data);
192
static void tklock_datapipe_display_state_curr_cb(gconstpointer data);
193
194
static void tklock_datapipe_display_state_next_cb(gconstpointer data);
static void tklock_datapipe_proximity_eval_led(void);
195
196
197
198
static void tklock_datapipe_proximity_update(void);
static gboolean tklock_datapipe_proximity_uncover_cb(gpointer data);
static void tklock_datapipe_proximity_uncover_cancel(void);
static void tklock_datapipe_proximity_uncover_schedule(void);
199
static void tklock_datapipe_proximity_sensor_actual_cb(gconstpointer data);
200
static void tklock_datapipe_call_state_cb(gconstpointer data);
201
static void tklock_datapipe_music_playback_ongoing_cb(gconstpointer data);
202
203
204
static void tklock_datapipe_alarm_ui_state_cb(gconstpointer data);
static void tklock_datapipe_charger_state_cb(gconstpointer data);
static void tklock_datapipe_battery_status_cb(gconstpointer data);
205
206
207
208
209
static void tklock_datapipe_usb_cable_state_cb(gconstpointer data);
static void tklock_datapipe_jack_sense_state_cb(gconstpointer data);
static void tklock_datapipe_camera_button_state_cb(gconstpointer const data);
static void tklock_datapipe_keypress_event_cb(gconstpointer const data);
static void tklock_datapipe_uiexception_type_cb(gconstpointer data);
210
static void tklock_datapipe_audio_route_cb(gconstpointer data);
211
static void tklock_datapipe_tklock_request_cb(gconstpointer data);
212
static void tklock_datapipe_interaction_expected_cb(gconstpointer data);
213
static gpointer tklock_datapipe_submode_filter_cb(gpointer data);
214
static void tklock_datapipe_submode_cb(gconstpointer data);
215
216
217
218
219
static void tklock_datapipe_lockkey_state_cb(gconstpointer const data);
static void tklock_datapipe_heartbeat_event_cb(gconstpointer data);
static void tklock_datapipe_keyboard_slide_input_state_cb(gconstpointer const data);
static void tklock_datapipe_keyboard_slide_output_state_cb(gconstpointer const data);
static void tklock_datapipe_keyboard_available_state_cb(gconstpointer const data);
220
static void tklock_datapipe_mouse_available_state_cb(gconstpointer const data);
221
static void tklock_datapipe_light_sensor_poll_request_cb(gconstpointer const data);
222
static void tklock_datapipe_topmost_window_pid_cb(gconstpointer data);
223
static void tklock_datapipe_light_sensor_actual_cb(gconstpointer data);
224
static void tklock_datapipe_lid_sensor_is_working_cb(gconstpointer data);
225
226
227
static void tklock_datapipe_lid_sensor_actual_cb(gconstpointer data);
static void tklock_datapipe_lid_sensor_filtered_cb(gconstpointer data);
static void tklock_datapipe_lens_cover_state_cb(gconstpointer data);
228
static bool tklock_touch_activity_event_p(const struct input_event *ev);
229
static void tklock_datapipe_user_activity_event_cb(gconstpointer data);
230
static void tklock_datapipe_init_done_cb(gconstpointer data);
231
232
233
static bool tklock_datapipe_in_tklock_submode(void);
static void tklock_datapipe_set_tklock_submode(bool lock);
234
static void tklock_datapipe_set_devicelock_state(devicelock_state_t state);
235
236
static void tklock_datapipe_rethink_interaction_expected(void);
static void tklock_datapipe_update_interaction_expected(bool expected);
237
238
239
240
static void tklock_datapipe_init(void);
static void tklock_datapipe_quit(void);
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
// LID_SENSOR
static bool tklock_lidsensor_is_enabled (void);
static void tklock_lidsensor_init (void);
// LID_LIGHT
static const char *tklock_lidlight_repr (tklock_lidlight_t state);
static tklock_lidlight_t tklock_lidlight_from_lux (int lux);
// LID_FILTER
static bool tklock_lidfilter_is_enabled (void);
static void tklock_lidfilter_set_allow_close (bool allow);
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
static tklock_lidlight_t tklock_lidfilter_map_als_state (void);
static void tklock_lidfilter_set_als_state (tklock_lidlight_t state);
static gboolean tklock_lidfilter_wait_for_close_cb (gpointer aptr);
static bool tklock_lidfilter_get_wait_for_close (void);
static void tklock_lidfilter_set_wait_for_close (bool state);
static gboolean tklock_lidfilter_wait_for_dark_cb (gpointer aptr);
static bool tklock_lidfilter_get_wait_for_dark (void);
static void tklock_lidfilter_set_wait_for_dark (bool state);
static gboolean tklock_lidfilter_wait_for_light_cb (gpointer aptr);
static bool tklock_lidfilter_get_wait_for_light (void);
static void tklock_lidfilter_set_wait_for_light (bool state);
static void tklock_lidfilter_rethink_als_poll (void);
static void tklock_lidfilter_rethink_allow_close (void);
static void tklock_lidfilter_rethink_als_state (void);
static void tklock_lidfilter_rethink_lid_state (void);
// LID_POLICY
static void tklock_lidpolicy_rethink (void);
280
281
282
// keyboard slide state machine
283
284
285
static void tklock_keyboard_slide_opened(void);
static void tklock_keyboard_slide_opened_cb(gpointer aptr);
static void tklock_keyboard_slide_closed(void);
286
287
static void tklock_keyboard_slide_rethink(void);
288
289
290
// autolock state machine
static gboolean tklock_autolock_cb(gpointer aptr);
291
292
293
static void tklock_autolock_evaluate(void);
static void tklock_autolock_enable(void);
static void tklock_autolock_disable(void);
294
static void tklock_autolock_rethink(void);
295
296
static void tklock_autolock_init(void);
static void tklock_autolock_quit(void);
297
298
299
300
// proximity locking state machine
static gboolean tklock_proxlock_cb(gpointer aptr);
301
302
303
304
static void tklock_proxlock_resume(void);
static void tklock_proxlock_evaluate(void);
static void tklock_proxlock_enable(void);
static void tklock_proxlock_disable(void);
305
306
static void tklock_proxlock_rethink(void);
307
308
// autolock based on device lock changes
309
static void tklock_autolock_on_devlock_block(int duration_ms);
310
311
312
static void tklock_autolock_on_devlock_prime(void);
static void tklock_autolock_on_devlock_trigger(void);
313
314
// ui exception handling state machine
315
316
317
318
319
320
321
322
323
324
static uiexception_type_t topmost_active(uiexception_type_t mask);
static void tklock_uiexception_sync_to_datapipe(void);
static gboolean tklock_uiexception_linger_cb(gpointer aptr);
static void tklock_uiexception_begin(uiexception_type_t type, int64_t linger);
static void tklock_uiexception_end(uiexception_type_t type, int64_t linger);
static void tklock_uiexception_cancel(void);
static void tklock_uiexception_finish(void);
static bool tklock_uiexception_deny_state_restore(bool force, const char *cause);
static void tklock_uiexception_rethink(void);
325
326
327
328
329
330
331
332
333
334
335
336
// low power mode ui state machine
static void tklock_lpmui_set_state(bool enable);
static void tklock_lpmui_reset_history(void);
static void tklock_lpmui_update_history(cover_state_t state);
static bool tklock_lpmui_probe_from_pocket(void);
static bool tklock_lpmui_probe_on_table(void);
static bool tklock_lpmui_probe(void);
static void tklock_lpmui_rethink(void);
static void tklock_lpmui_pre_transition_actions(void);
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
// legacy hw event input enable/disable state machine
static void tklock_evctrl_set_state(output_state_t *output, bool enable);
static void tklock_evctrl_set_kp_state(bool enable);
static void tklock_evctrl_set_ts_state(bool enable);
static void tklock_evctrl_set_dt_state(bool enable);
static void tklock_evctrl_rethink(void);
// legacy hw double tap calibration
static void tklock_dtcalib_now(void);
static void tklock_dtcalib_from_heartbeat(void);
static gboolean tklock_dtcalib_cb(gpointer data);
static void tklock_dtcalib_start(void);
static void tklock_dtcalib_stop(void);
354
// DYNAMIC_SETTINGS
355
356
357
static void tklock_setting_sanitize_lid_open_actions(void);
static void tklock_setting_sanitize_lid_close_actions(void);
358
359
360
361
static void tklock_setting_sanitize_kbd_open_trigger(void);
static void tklock_setting_sanitize_kbd_open_actions(void);
static void tklock_setting_sanitize_kbd_close_trigger(void);
static void tklock_setting_sanitize_kbd_close_actions(void);
362
363
static void tklock_setting_cb(GConfClient *const gcc, const guint id, GConfEntry *const entry, gpointer const data);
364
365
366
static void tklock_setting_init(void);
static void tklock_setting_quit(void);
367
368
// sysfs probing
369
370
static void tklock_sysfs_probe(void);
371
372
// dbus ipc with systemui
373
374
static void tklock_ui_send_tklock_signal(void);
375
376
377
378
379
static void tklock_ui_notify_rethink_wakelock(void);
static bool tklock_ui_notify_must_be_delayed(void);
static gboolean tklock_ui_notify_end_cb(gpointer data);
static gboolean tklock_ui_notify_beg_cb(gpointer data);
static void tklock_ui_notify_schdule(void);
380
static gboolean tklock_ui_sync_cb(gpointer aptr);
381
382
static void tklock_ui_notify_cancel(void);
383
384
385
static void tklock_ui_eat_event(void);
static void tklock_ui_open(void);
static void tklock_ui_close(void);
386
387
static bool tklock_ui_is_enabled(void);
static void tklock_ui_set_enabled(bool enable);
388
389
390
static void tklock_ui_get_devicelock_cb(DBusPendingCall *pc, void *aptr);
static void tklock_ui_get_devicelock(void);
391
392
static void tklock_ui_send_lpm_signal(void);
393
394
static void tklock_ui_enable_lpm(void);
static void tklock_ui_disable_lpm(void);
395
static void tklock_ui_show_device_unlock(void);;
396
397
398
// dbus ipc
399
400
401
static void tklock_dbus_send_display_blanking_policy(DBusMessage *const req);
static gboolean tklock_dbus_display_blanking_policy_get_cb(DBusMessage *const msg);
402
403
static void tklock_dbus_send_keyboard_slide_state(DBusMessage *const req);
static gboolean tklock_dbus_keyboard_slide_state_get_req_cb(DBusMessage *const msg);
404
405
406
static void tklock_dbus_send_keyboard_available_state(DBusMessage *const req);
static gboolean tklock_dbus_keyboard_available_state_get_req_cb(DBusMessage *const msg);
407
408
409
410
static void tklock_dbus_send_mouse_available_state(DBusMessage *const req);
static gboolean tklock_dbus_mouse_available_state_get_req_cb(DBusMessage *const msg);
411
412
413
static gboolean tklock_dbus_send_tklock_mode(DBusMessage *const method_call);
static gboolean tklock_dbus_mode_get_req_cb(DBusMessage *const msg);
414
415
static tklock_request_t tklock_dbus_sanitize_requested_mode(tklock_request_t state);
416
static gboolean tklock_dbus_mode_change_req_cb(DBusMessage *const msg);
417
static gboolean tklock_dbus_interaction_expected_cb(DBusMessage *const msg);
418
419
static gboolean tklock_dbus_systemui_callback_cb(DBusMessage *const msg);
420
static gboolean tklock_dbus_devicelock_changed_cb(DBusMessage *const msg);
421
422
423
424
static gboolean tklock_dbus_notification_beg_cb(DBusMessage *const msg);
static gboolean tklock_dbus_notification_end_cb(DBusMessage *const msg);
425
426
427
static void mce_tklock_init_dbus(void);
static void mce_tklock_quit_dbus(void);
428
429
430
431
// NOTIFICATION_SLOTS
static void tklock_notif_slot_init(tklock_notif_slot_t *self);
static void tklock_notif_slot_free(tklock_notif_slot_t *self);
432
static void tklock_notif_slot_set(tklock_notif_slot_t *self, const char *owner, const char *name, int64_t until, int64_t renew);
433
434
435
436
static bool tklock_notif_slot_is_free(const tklock_notif_slot_t *self);
static bool tklock_notif_slot_has_name(const tklock_notif_slot_t *self, const char *name);
static bool tklock_notif_slot_validate(tklock_notif_slot_t *self, int64_t now);
static bool tklock_notif_slot_renew(tklock_notif_slot_t *self, int64_t now);
437
438
static bool tklock_notif_slot_has_owner(const tklock_notif_slot_t *self, const char *owner);
static gchar *tklock_notif_slot_steal_owner(tklock_notif_slot_t *self);
439
440
441
442
443
444
445
446
447
448
// NOTIFICATION_API
static void tklock_notif_init(void);
static void tklock_notif_quit(void);
static gboolean tklock_notif_autostop_cb(gpointer aptr);
static void tklock_notif_cancel_autostop(void);
static void tklock_notif_schedule_autostop(gint delay);
static void tklock_notif_update_state(void);
static void tklock_notif_extend_by_renew(void);
449
450
451
452
453
454
455
456
static void tklock_notif_vacate_slot(const char *owner, const char *name, int64_t linger);
static void tklock_notif_reserve_slot(const char *owner, const char *name, int64_t length, int64_t renew);
static void tklock_notif_vacate_slots_from(const char *owner);
static size_t tklock_notif_count_slots_from(const char *owner);
static gboolean tklock_notif_owner_dropped_cb(DBusMessage *const msg);
static void tklock_notif_add_owner_monitor(const char *owner);
static void tklock_notif_remove_owner_monitor(const char *owner);
457
458
459
static void mce_tklock_begin_notification(const char *owner, const char *name, int64_t length, int64_t renew);
static void mce_tklock_end_notification(const char *owner, const char *name, int64_t linger);
460
461
462
463
// "module" load/unload
extern gboolean mce_tklock_init(void);
extern void mce_tklock_exit(void);
464
extern void mce_tklock_unblank(display_state_t to_state);
465
466
/* ========================================================================= *
467
* DYNAMIC_SETTINGS
468
469
* ========================================================================= */
470
/** Flag: Devicelock is handled in lockscreen */
471
static gboolean tklock_devicelock_in_lockscreen = MCE_DEFAULT_TK_DEVICELOCK_IN_LOCKSCREEN;
472
static guint tklock_devicelock_in_lockscreen_setting_id = 0;
473
474
475
476
/** Flag: Convert denied tklock removal attempt to: show device unlock view */
static bool tklock_devicelock_want_to_unlock = false;
477
/** Flag: Automatically lock (after ON->DIM->OFF cycle) */
478
static gboolean tk_autolock_enabled = MCE_DEFAULT_TK_AUTOLOCK_ENABLED;
479
static guint tk_autolock_enabled_setting_id = 0;
480
481
/** Flag: Grabbing input devices is allowed */
482
static gboolean tk_input_policy_enabled = MCE_DEFAULT_TK_INPUT_POLICY_ENABLED;
483
static guint tk_input_policy_enabled_setting_id = 0;
484
485
/** Delay for automatick locking (after ON->DIM->OFF cycle) */
486
static gint tklock_autolock_delay = MCE_DEFAULT_TK_AUTOLOCK_DELAY;
487
static guint tklock_autolock_delay_setting_id = 0;
488
489
/** Flag: Proximity sensor can block touch input */
490
static gboolean proximity_blocks_touch = MCE_DEFAULT_TK_PROXIMITY_BLOCKS_TOUCH;
491
static guint proximity_blocks_touch_setting_id = 0;
492
493
/** Volume key input policy */
494
static gint volkey_policy = MCE_DEFAULT_TK_VOLKEY_POLICY;
495
static guint volkey_policy_setting_id = 0;
496
497
/** Touchscreen gesture (doubletap etc) enable mode */
498
static gint touchscreen_gesture_enable_mode = MCE_DEFAULT_DOUBLETAP_MODE;
499
static guint touchscreen_gesture_enable_mode_setting_id = 0;
500
501
/** Lid sensor open actions */
502
503
static gint tklock_lid_open_actions = MCE_DEFAULT_TK_LID_OPEN_ACTIONS;
static guint tklock_lid_open_actions_setting_id = 0;
504
505
/** Lid sensor close actions */
506
507
static gint tklock_lid_close_actions = MCE_DEFAULT_TK_LID_CLOSE_ACTIONS;
static guint tklock_lid_close_actions_setting_id = 0;
508
509
/** Flag: Is the lid sensor used for display blanking */
510
static gboolean lid_sensor_enabled = MCE_DEFAULT_TK_LID_SENSOR_ENABLED;
511
static guint lid_sensor_enabled_setting_id = 0;
512
513
/** When to react to keyboard open */
514
515
static gint tklock_kbd_open_trigger = MCE_DEFAULT_TK_KBD_OPEN_TRIGGER;
static guint tklock_kbd_open_trigger_setting_id = 0;
516
517
/** How to react to keyboard open */
518
519
static gint tklock_kbd_open_actions = MCE_DEFAULT_TK_KBD_OPEN_ACTIONS;
static guint tklock_kbd_open_actions_setting_id = 0;
520
521
/** When to react to keyboard close */
522
523
static gint tklock_kbd_close_trigger = MCE_DEFAULT_TK_KBD_CLOSE_TRIGGER;
static guint tklock_kbd_close_trigger_setting_id = 0;
524
525
/** How to react to keyboard close */
526
527
static gint tklock_kbd_close_actions = MCE_DEFAULT_TK_KBD_CLOSE_ACTIONS;
static guint tklock_kbd_close_actions_setting_id = 0;
528
529
/** Flag for: Using ALS is allowed */
530
static gboolean als_enabled = MCE_DEFAULT_DISPLAY_ALS_ENABLED;
531
static guint als_enabled_setting_id = 0;
532
533
/** Flag: Use ALS for lid close filtering */
534
static gboolean filter_lid_with_als = MCE_DEFAULT_TK_FILTER_LID_WITH_ALS;
535
static guint filter_lid_with_als_setting_id = 0;
536
537
/** Maximum amount of light ALS should report when LID is closed */
538
539
static gint filter_lid_als_limit = MCE_DEFAULT_TK_FILTER_LID_ALS_LIMIT;
static guint filter_lid_als_limit_setting_id = 0;
540
541
/** How long to keep display on after incoming call ends [ms] */
542
543
static gint exception_length_call_in = MCE_DEFAULT_TK_EXCEPT_LEN_CALL_IN;
static guint exception_length_call_in_setting_id = 0;
544
545
/** How long to keep display on after outgoing call ends [ms] */
546
547
static gint exception_length_call_out = MCE_DEFAULT_TK_EXCEPT_LEN_CALL_OUT;
static guint exception_length_call_out_setting_id = 0;
548
549
/** How long to keep display on after alarm is handled [ms] */
550
551
static gint exception_length_alarm = MCE_DEFAULT_TK_EXCEPT_LEN_ALARM;
static guint exception_length_alarm_setting_id = 0;
552
553
/** How long to keep display on when usb cable is connected [ms] */
554
555
static gint exception_length_usb_connect = MCE_DEFAULT_TK_EXCEPT_LEN_USB_CONNECT;
static guint exception_length_usb_connect_setting_id = 0;
556
557
/** How long to keep display on when usb mode dialog is shown [ms] */
558
559
static gint exception_length_usb_dialog = MCE_DEFAULT_TK_EXCEPT_LEN_USB_DIALOG;
static guint exception_length_usb_dialog_setting_id = 0;
560
561
/** How long to keep display on when charging starts [ms] */
562
563
static gint exception_length_charger = MCE_DEFAULT_TK_EXCEPT_LEN_CHARGER;
static guint exception_length_charger_setting_id = 0;
564
565
/** How long to keep display on after battery full [ms] */
566
567
static gint exception_length_battery = MCE_DEFAULT_TK_EXCEPT_LEN_BATTERY;
static guint exception_length_battery_setting_id = 0;
568
569
/** How long to keep display on when audio jack is inserted [ms] */
570
571
static gint exception_length_jack_in = MCE_DEFAULT_TK_EXCEPT_LEN_JACK_IN;
static guint exception_length_jack_in_setting_id = 0;
572
573
/** How long to keep display on when audio jack is removed [ms] */
574
575
static gint exception_length_jack_out = MCE_DEFAULT_TK_EXCEPT_LEN_JACK_OUT;
static guint exception_length_jack_out_setting_id = 0;
576
577
/** How long to keep display on when camera button is pressed [ms] */
578
579
static gint exception_length_camera = MCE_DEFAULT_TK_EXCEPT_LEN_CAMERA;
static guint exception_length_camera_setting_id = 0;
580
581
/** How long to keep display on when volume button is pressed [ms] */
582
583
static gint exception_length_volume = MCE_DEFAULT_TK_EXCEPT_LEN_VOLUME;
static guint exception_length_volume_setting_id = 0;
584
585
/** How long to extend display on when there is user activity [ms] */
586
587
static gint exception_length_activity = MCE_DEFAULT_TK_EXCEPT_LEN_ACTIVITY;
static guint exception_length_activity_setting_id = 0;
588
589
/** Flag for: Allow lockscreen animation during unblanking */
590
static gboolean lockscreen_anim_enabled = MCE_DEFAULT_TK_LOCKSCREEN_ANIM_ENABLED;
591
static guint lockscreen_anim_enabled_setting_id = 0;
592
593
594
595
596
597
598
599
600
/** Default delay for delaying proximity uncovered handling [ms] */
static gint tklock_proximity_delay_default = MCE_DEFAULT_TK_PROXIMITY_DELAY_DEFAULT;
static guint tklock_proximity_delay_default_setting_id = 0;
/** Delay for delaying proximity uncovered handling during calls [ms] */
static gint tklock_proximity_delay_incall = MCE_DEFAULT_TK_PROXIMITY_DELAY_INCALL;
static guint tklock_proximity_delay_incall_setting_id = 0;
601
602
603
604
/* ========================================================================= *
* probed control file paths
* ========================================================================= */
605
/** SysFS path to touchscreen event disable */
606
607
static output_state_t mce_touchscreen_sysfs_disable_output =
{
608
609
610
.context = "touchscreen_disable",
.truncate_file = TRUE,
.close_on_exit = TRUE,
611
};
612
613
/** SysFS path to touchscreen double-tap gesture control */
614
static const gchar *mce_touchscreen_gesture_enable_path = NULL;
615
616
617
618
/** SysFS path to touchscreen recalibration control */
static const gchar *mce_touchscreen_calibration_control_path = NULL;
619
/** SysFS path to keypad event disable */
620
621
static output_state_t mce_keypad_sysfs_disable_output =
{
622
623
624
.context = "keypad_disable",
.truncate_file = TRUE,
.close_on_exit = TRUE,
625
};
626
627
628
629
/* ========================================================================= *
* DATAPIPE VALUES AND TRIGGERS
* ========================================================================= */
630
631
632
633
634
635
636
/** Cached submode_pipe state; assume invalid */
static submode_t submode = MCE_SUBMODE_INVALID;
/** Cached PID of process owning the topmost window on UI */
static int topmost_window_pid = -1;
637
638
639
/** Cached init_done state; assume unknown */
static tristate_t init_done = TRISTATE_UNKNOWN;
640
641
642
/** Proximity state history for triggering low power mode ui */
static ps_history_t tklock_lpmui_hist[8];
643
644
645
646
647
/** Current tklock ui state
*
* Access only via tklock_ui_is_enabled() / tklock_ui_set_enabled().
*/
static bool tklock_ui_enabled_pvt = false;
648
649
/** Current tklock ui state that has been sent to lipstick */
650
static int tklock_ui_notified = -1; // does not match bool values
651
652
/** System state; is undefined at bootup, can't assume anything */
653
static system_state_t system_state = MCE_SYSTEM_STATE_UNDEF;
654
655
656
657
658
659
660
/** Display state; undefined initially, can't assume anything */
static display_state_t display_state_curr = MCE_DISPLAY_UNDEF;
/** Next Display state; undefined initially, can't assume anything */
static display_state_t display_state_next = MCE_DISPLAY_UNDEF;
661
662
663
664
/** Call state; assume no active calls */
static call_state_t call_state = CALL_STATE_NONE;
/** Actual proximity state; assume not covered */
665
static cover_state_t proximity_sensor_actual = COVER_UNDEF;
666
667
/** Effective proximity state; assume not covered */
668
static cover_state_t proximity_sensor_effective = COVER_UNDEF;
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
/** Lid cover sensor state; assume unkown
*
* When in covered state, it is assumed that it is not physically
* possible to see/interact with the display and thus it should
* stay powered off.
*
* Originally was used to track Nokia N770 slidable cover. Now
* it is used also for things like the hammerhead magnetic lid
* sensor.
*/
static cover_state_t lid_sensor_actual = COVER_UNDEF;
/** Lid cover policy state; assume unknown */
static cover_state_t lid_sensor_filtered = COVER_UNDEF;
685
/** Change notifications for system_state
686
*/
687
static void tklock_datapipe_system_state_cb(gconstpointer data)
688
{
689
690
system_state_t prev = system_state;
system_state = GPOINTER_TO_INT(data);
691
692
693
if( prev == system_state )
goto EXIT;
694
695
696
697
mce_log(LL_DEBUG, "system_state: %s -> %s",
system_state_repr(prev),
system_state_repr(system_state));
698
699
tklock_ui_set_enabled(false);
700
701
702
EXIT:
return;
703
704
}
705
/** Device lock state; assume undefined */
706
static devicelock_state_t devicelock_state = DEVICELOCK_STATE_UNDEFINED;
707
708
/** Push device lock state value into devicelock_state_pipe datapipe
709
*/
710
static void tklock_datapipe_set_devicelock_state(devicelock_state_t state)
711
{
712
switch( state ) {
713
714
715
case DEVICELOCK_STATE_UNLOCKED:
case DEVICELOCK_STATE_UNDEFINED:
case DEVICELOCK_STATE_LOCKED:
716
717
718
719
720
break;
default:
mce_log(LL_WARN, "unknown device lock state=%d; assuming locked",
state);
721
state = DEVICELOCK_STATE_LOCKED;
722
723
break;
}
724
725
726
if( devicelock_state != state ) {
datapipe_exec_full(&devicelock_state_pipe,
727
GINT_TO_POINTER(state));
728
729
730
}
}
731
/** Change notifications for devicelock_state
732
*/
733
static void tklock_datapipe_devicelock_state_cb(gconstpointer data)
734
{
735
736
devicelock_state_t prev = devicelock_state;
devicelock_state = GPOINTER_TO_INT(data);
737
738
if( devicelock_state == prev )
739
740
goto EXIT;
741
742
743
mce_log(LL_DEVEL, "devicelock_state = %s -> %s",
devicelock_state_repr(prev),
devicelock_state_repr(devicelock_state));
744
745
tklock_uiexception_rethink();
746
747
748
tklock_autolock_rethink();
749
750
751
752
753
/* When lipstick is starting up we see device lock
* going through undefined -> locked/unlocked change.
* We must not trigger autolock due to these initial
* device lock transitions */
switch( prev ) {
754
case DEVICELOCK_STATE_UNDEFINED:
755
756
757
758
759
/* Block autolock for 60 seconds when leaving
* undefined state (= lipstick startup) */
tklock_autolock_on_devlock_block(60 * 1000);
break;
760
case DEVICELOCK_STATE_LOCKED:
761
762
763
764
765
766
767
768
769
/* Unblock autolock earlier if we see transition
* away from locked state (=unlocked by user) */
tklock_autolock_on_devlock_block(0);
break;
default:
break;
}
770
771
switch( devicelock_state ) {
case DEVICELOCK_STATE_LOCKED:
772
tklock_autolock_on_devlock_trigger();
773
774
break;
case DEVICELOCK_STATE_UNLOCKED:
775
776
777
778
779
780
781
782
783
784
785
switch( display_state_next ) {
case MCE_DISPLAY_OFF:
case MCE_DISPLAY_LPM_OFF:
case MCE_DISPLAY_LPM_ON:
/* Transitions from undefined -> unlocked state occur
* during device bootup / mce restart and should not
* cause any actions.
*/
if( prev == DEVICELOCK_STATE_UNDEFINED )
break;
786
787
788
789
/* Devicelock ui keeps fingerprint scanner active in LPM state
* and unlocks device on identify, but omits unlock feedback
* and leaves the display state as-is.
*
790
791
792
793
794
795
796
797
798
* As a workaround, execute unlock feedback from mce. Then
* exit from LPM by requesting display power up and removal
* of tklock submode.
*
* While this is mostly relevant to LPM, apply the same logic
* also when in actually powered off display states to guard
* against timing glitches (getting fingerprint identification
* when already decided to exit LPM, etc) and changes in device
* lock ui side logic.
799
*/
800
801
mce_log(LL_WARN, "device got unlocked while display is off; "
"assume fingerprint authentication occurred");
802
803
datapipe_exec_full(&ngfd_event_request_pipe,
"unlock_device");
804
805
806
807
808
809
/* Delay display state / tklock processing until proximity
* sensor state is known */
common_on_proximity_schedule(MODULE_NAME,
tklock_datapipe_devicelock_state_cb2,
0);
810
811
812
break;
default:
break;
813
814
815
816
817
}
break;
default:
break;
}
818
819
820
821
822
EXIT:
return;
}
823
/** Wait for proximity sensor -callback for fingerprint unlock handling
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
*
* @param aptr unused
*/
static void tklock_datapipe_devicelock_state_cb2(gpointer aptr)
{
(void)aptr;
/* Still unlocked ? */
if( devicelock_state == DEVICELOCK_STATE_UNLOCKED ) {
if( proximity_sensor_actual != COVER_OPEN ) {
mce_log(LL_WARN, "unblank skipped due to proximity sensor");
}
else {
mce_datapipe_request_display_state(MCE_DISPLAY_ON);
mce_datapipe_request_tklock(TKLOCK_REQUEST_OFF);
}
}
}
844
/** Resumed from suspend notification */
845
static void tklock_datapipe_resume_detected_event_cb(gconstpointer data)
846
{
847
848
(void) data;
849
850
/* Re-evaluate proximity locking after resuming from
* suspend. */
851
tklock_proxlock_resume();
852
853
}
854
/** devicelock dbus name is reserved; assume unknown */
855
static service_state_t devicelock_service_state = SERVICE_STATE_UNDEF;
856
857
/** Change notifications for devicelock_service_state
858
*/
859
static void tklock_datapipe_devicelock_service_state_cb(gconstpointer data)
860
{
861
862
service_state_t prev = devicelock_service_state;
devicelock_service_state = GPOINTER_TO_INT(data);
863
864
if( devicelock_service_state == prev )
865
866
goto EXIT;
867
mce_log(LL_DEBUG, "devicelock_service_state = %s -> %s",
868
service_state_repr(prev),
869
service_state_repr(devicelock_service_state));
870
871
if( devicelock_service_state == SERVICE_STATE_RUNNING ) {
872
/* query initial device lock state on devicelock/mce startup */
873
tklock_ui_get_devicelock();
874
875
876
877
}
else {
/* if device lock service is not running, the device lock
* state is undefined */
878
tklock_datapipe_set_devicelock_state(DEVICELOCK_STATE_UNDEFINED);
879
880
881
882
883
884
}
EXIT:
return;
}
885
/** Lipstick dbus name is reserved; assume false */
886
static service_state_t lipstick_service_state = SERVICE_STATE_UNDEF;
887
888
/** Change notifications for lipstick_service_state
889
*/
890
static void tklock_datapipe_lipstick_service_state_cb(gconstpointer data)
891
{
892
893
service_state_t prev = lipstick_service_state;
lipstick_service_state = GPOINTER_TO_INT(data);
894
895
if( lipstick_service_state == prev )
896
897
goto EXIT;
898
mce_log(LL_DEBUG, "lipstick_service_state = %s -> %s",
899
service_state_repr(prev),
900
service_state_repr(lipstick_service_state));
901
902
903
904
905
bool enable_tklock = false;
/* Tklock is applicable only when lipstick is running */
if( lipstick_service_state == SERVICE_STATE_RUNNING ) {
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
if( prev == SERVICE_STATE_UNDEF ) {
/* UNDEF -> RUNNING: Implies a mce restart while lipstick
* is running. What we would like to happen is that things
* stay exactly as they were. However there is no passive
* way to recover lockscreen state from lipstick and we
* have to do something active in order to get tklock
* state in sync between mce and lipstick.
*
* If display is in powered on state, request lockscreen
* deactivation. If device happens to be locked, this is
* transformed into show-unlock-screen request.
*
* Otherwise activate lockscreen.
*/
if( display_state_next != MCE_DISPLAY_ON )
enable_tklock = true;
}
else {
/* STOPPED -> RUNNING: Implies lipstick start during
* bootup / restart later on. In this case lockscreen
* status is decided by lipstick and it defaults to having
* lockscreen active and changes are not really accepted
* until lipstick startup has finished. Making a lockscreen
* activation request merely serves as a way to ensure that
* mce and lipstick get in sync about tklock state.
*/
932
enable_tklock = true;
933
}
934
935
}
936
// force tklock ipc
937
tklock_ui_notified = -1;
938
tklock_ui_set_enabled(enable_tklock);
939
940
941
EXIT:
return;
942
943
}
944
/** Update mode is active; assume false */
945
static bool osupdate_running = false;
946
947
/** Change notifications for osupdate_running
948
*/
949
static void tklock_datapipe_osupdate_running_cb(gconstpointer data)
950
{
951
952
bool prev = osupdate_running;
osupdate_running = GPOINTER_TO_INT(data);
953
954
if( osupdate_running == prev )
955
956
goto EXIT;
957
mce_log(LL_DEBUG, "osupdate_running = %d -> %d", prev, osupdate_running);
958
959
if( osupdate_running ) {
960
/* undo tklock when update mode starts */
961
mce_datapipe_request_tklock(TKLOCK_REQUEST_OFF);
962
963
964
965
966
967
}
EXIT:
return;
}
968
969
970
971
972
973
974
975
976
977
978
979
980
/** Device is shutting down; assume false */
static bool shutting_down = false;
/** Change notifications for shutting_down
*/
static void tklock_datapipe_shutting_down_cb(gconstpointer data)
{
bool prev = shutting_down;
shutting_down = GPOINTER_TO_INT(data);
if( shutting_down == prev )
goto EXIT;
981
982
mce_log(LL_DEBUG, "shutting_down = %d -> %d",
prev, shutting_down);
983
984
985
986
987
988
989
tklock_evctrl_rethink();
EXIT:
return;
}
990
991
992
/** Autorelock trigger: assume disabled */
static autorelock_t autorelock_trigger = AUTORELOCK_NO_TRIGGERS;
993
/** Change notifications for display_state_curr
994
*/
995
static void tklock_datapipe_display_state_curr_cb(gconstpointer data)
996
{
997
998
display_state_t prev = display_state_curr;
display_state_curr = GPOINTER_TO_INT(data);
999
1000
if( display_state_curr == prev )