/
display.c
11169 lines (9137 loc) · 341 KB
/
display.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
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
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @file display.c
* Display module -- this implements display handling for MCE
* <p>
* Copyright © 2007-2011 Nokia Corporation and/or its subsidiary(-ies).
* <p>
* @author David Weinehall <david.weinehall@nokia.com>
* @author Simo Piiroinen <simo.piiroinen@jollamobile.com>
*
* 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/>.
*/
#include "display.h"
#include "../mce-log.h"
#include "../mce-io.h"
#include "../mce-lib.h"
#include "../mce-dbus.h"
#include "../mce-fbdev.h"
#include "../mce-conf.h"
#include "../mce-setting.h"
#include "../mce-dbus.h"
#include "../mce-sensorfw.h"
#include "../tklock.h"
#ifdef ENABLE_HYBRIS
# include "../mce-hybris.h"
#endif
#include "../mce-worker.h"
#include "../filewatcher.h"
#ifdef ENABLE_WAKELOCKS
# include "../libwakelock.h"
#endif
#include "powersavemode.h"
#include <sys/ptrace.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <glob.h>
#include <pthread.h>
#include <mce/dbus-names.h>
#include <mce/mode-names.h>
#include <glib/gstdio.h>
#include <gmodule.h>
#if 0 // DEBUG: make all logging from this module "critical"
# undef mce_log
# define mce_log(LEV, FMT, ARGS...) \
mce_log_file(LL_CRIT, __FILE__, __FUNCTION__, FMT , ## ARGS)
#endif
/* ========================================================================= *
* CONSTANTS
* ========================================================================= */
/** Module name */
#define MODULE_NAME "display"
/** UI side graphics fading percentage
*
* Controls maximum opacity of the black box rendered on top at the ui
* when backlight dimming alone is not enough to make dimmed display
* state visible to the user.
*/
#define MCE_FADER_MAXIMUM_OPACITY_PERCENT 50
/** Backlight fade animation duration after brightness setting changes */
#define MCE_FADER_DURATION_SETTINGS_CHANGED 600
/** Minimum duration for direct backlight fade animation */
#define MCE_FADER_DURATION_HW_MIN 0
/** Maximum duration for direct backlight fade animation */
#define MCE_FADER_DURATION_HW_MAX 5000
/** Minimum duration for compositor based ui dimming animation */
#define MCE_FADER_DURATION_UI_MIN 100
/** Maximum duration for compositor based ui dimming animation */
#define MCE_FADER_DURATION_UI_MAX 5000
/** How long to delay entering late suspend after powering down display */
#define MCE_DISPLAY_STM_SUSPEND_DELAY_NS (5LL * 1000LL * 1000LL * 1000LL)
/** Placeholder value for unknown compositor pid */
#define COMPOSITOR_STM_INVALID_PID (-1)
/** Panic led delay for freshly started compositor process
*
* During bootup it is more or less expected that compositor is
* unable to answer immediately. So we allow freshly started
* compositor process longer delay and bring it down gradually
* to target level.
*/
#define COMPOSITOR_STM_INITIAL_PANIC_DELAY 15000
/** Panic led delay for already established compositor process
*
* With each successfull ipc communication with the compositor,
* the expected ipc delay is lowered until the minimum is reached.
*/
#define COMPOSITOR_STM_MINIMUM_PANIC_DELAY 3000
/** How long to wait for reply to setUpdatesEnabled() calls
*
* There is no way to robustly deal with situations where compositor
* replies get delayed. If the compositor side recovers from whatever
* is delaying the dbus methdod call processing, it will see the already
* send enable/disable rendering call. Any attempts to retry / change
* direction once a request has been send can only lead to mce and
* compositor processes getting out of sync regarding updates enabled
* status.
*
* So the best option is to wait until we get a reply or compositor
* process gets restarted.
*/
# define COMPOSITOR_STM_DBUS_CALL_TIMEOUT DBUS_TIMEOUT_INFINITE
/** How long to delay retrying after failed setUpdatesEnabled() calls
*
* Few seconds delay makes sure mce does not go amok with retries if
* there should still be some hiccup with compositor dbus service.
*/
#define COMPOSITOR_STM_DBUS_RETRY_DELAY 5000
/* ========================================================================= *
* TYPEDEFS
* ========================================================================= */
/** Display type */
typedef enum {
/** Display type unset */
DISPLAY_TYPE_UNSET = -1,
/** No display available; XXX should never happen */
DISPLAY_TYPE_NONE = 0,
/** Generic display interface without CABC */
DISPLAY_TYPE_GENERIC = 1,
/** EID l4f00311 with CABC */
DISPLAY_TYPE_L4F00311 = 2,
/** Sony acx565akm with CABC */
DISPLAY_TYPE_ACX565AKM = 3,
/** Taal display */
DISPLAY_TYPE_TAAL = 4,
/** Himalaya display */
DISPLAY_TYPE_HIMALAYA = 5,
/** Generic display name */
DISPLAY_TYPE_DISPLAY0 = 6,
/** Generic name for ACPI-controlled displays */
DISPLAY_TYPE_ACPI_VIDEO0 = 7
} display_type_t;
/**
* CABC mapping; D-Bus API modes vs SysFS mode
*/
typedef struct {
/** CABC mode D-Bus name */
const gchar *const dbus;
/** CABC mode SysFS name */
const gchar *const sysfs;
/** CABC mode available */
gboolean available;
} cabc_mode_mapping_t;
/** Enumeration of possible setUpdatesEnabled() synchronization states */
typedef enum
{
/** setUpdatesEnabled() call failed */
RENDERER_ERROR = -2,
/** setUpdatesEnabled() not attempted yet */
RENDERER_UNKNOWN = -1,
/** setUpdatesEnabled(false) successfully made */
RENDERER_DISABLED = 0,
/** setUpdatesEnabled(true) successfully made */
RENDERER_ENABLED = 1,
} renderer_state_t;
/** Enumeration for compositor related debug led patterns */
typedef enum
{
/** Getting reply to setUpdatesEnabled(true) is taking too long */
COMPOSITOR_LED_ENABLE_PANIC,
/** Getting reply to setUpdatesEnabled(false) is taking too long */
COMPOSITOR_LED_DISABLE_PANIC,
/** Killing unresponsive compositor process */
COMPOSITOR_LED_KILLER_ACTIVE,
/** Number of compositor related debug led patterns */
COMPOSITOR_LED_NUMOF,
} compositor_led_t;
/** Enumeration of states mce <-> compositor ipc can be in */
typedef enum
{
/** Waiting for D-Bus service availability */
COMPOSITOR_STATE_INITIAL,
/** About to be destroyed */
COMPOSITOR_STATE_FINAL,
/** Compositor D-Bus service is not running */
COMPOSITOR_STATE_STOPPED,
/** Compositor D-Bus service is running */
COMPOSITOR_STATE_STARTED,
/** Pending setUpdatesEnabled() D-Bus method call */
COMPOSITOR_STATE_REQUESTING,
/** Successfully finished setUpdatesEnabled() D-Bus method call */
COMPOSITOR_STATE_GRANTED,
/** Received error reply to setUpdatesEnabled() D-Bus method call */
COMPOSITOR_STATE_FAILED,
/** Number of compositor ipc related states */
COMPOSITOR_STATE_NUMOF
} compositor_state_t;
/** State information for frame buffer resume waiting */
typedef struct
{
/** frame buffer suspended flag */
bool suspended;
/** worker thread id */
pthread_t thread;
/** worker thread done flag */
bool finished;
/** path to fb wakeup event file */
const char *wake_path;
/** wakeup file descriptor */
int wake_fd;
/** path to fb sleep event file */
const char *sleep_path;
/** sleep file descriptor */
int sleep_fd;
/** write end of wakeup mainloop pipe */
int pipe_fd;
/** pipe reader io watch id */
guint pipe_id;
} waitfb_t;
/** Possible values for bootstate */
typedef enum {
BOOTSTATE_UNKNOWN,
BOOTSTATE_USER,
BOOTSTATE_ACT_DEAD,
} bootstate_t;
/** Content and where to write it */
typedef struct governor_setting_t
{
/** Path (or rather glob pattern) to file where to write */
char *path;
/** Data to write */
char *data;
} governor_setting_t;
/** Display state machine states */
typedef enum
{
STM_UNSET,
STM_RENDERER_INIT_START,
STM_RENDERER_WAIT_START,
STM_ENTER_POWER_ON,
STM_STAY_POWER_ON,
STM_LEAVE_POWER_ON,
STM_RENDERER_INIT_STOP,
STM_RENDERER_WAIT_STOP,
STM_WAIT_FADE_TO_BLACK,
STM_WAIT_FADE_TO_TARGET,
STM_INIT_SUSPEND,
STM_WAIT_SUSPEND,
STM_ENTER_POWER_OFF,
STM_STAY_POWER_OFF,
STM_LEAVE_POWER_OFF,
STM_INIT_RESUME,
STM_WAIT_RESUME,
STM_ENTER_LOGICAL_OFF,
STM_STAY_LOGICAL_OFF,
STM_LEAVE_LOGICAL_OFF,
} stm_state_t;
/** Delays for display blank/unblank related debug led patterns [ms] */
enum
{
/** How long to wait for framebuffer sleep/wake event from kernel */
LED_DELAY_FB_SUSPEND_RESUME = 1000,
/** How long to wait dbus method call reply from lipstick */
LED_DELAY_UI_DISABLE_ENABLE_MINIMUM = 3000,
/** How long to initially wait dbus method call reply from lipstick */
LED_DELAY_UI_DISABLE_ENABLE_MAXIMUM = 15000,
};
/** Backlight fade types */
typedef enum
{
/** No brightness fading */
FADER_IDLE,
/** Normal brightness fading */
FADER_DEFAULT,
/** Fading to MCE_DISPLAY_DIM */
FADER_DIMMING,
/** Fading due to ALS adjustment */
FADER_ALS,
/** Fading to DISPLAY_OFF */
FADER_BLANK,
/** Fading from DISPLAY_OFF */
FADER_UNBLANK,
FADER_NUMOF
} fader_type_t;
/* ------------------------------------------------------------------------- *
* BLANKING_PAUSE_CLIENT
* ------------------------------------------------------------------------- */
typedef struct bpclient_t bpclient_t;
struct bpclient_t
{
char *bpc_name;
pid_t bpc_pid;
int64_t bpc_tmo;
};
/* ========================================================================= *
* PROTOTYPES
* ========================================================================= */
/* ------------------------------------------------------------------------- *
* MISC_UTILS
* ------------------------------------------------------------------------- */
static inline bool mdy_str_eq_p(const char *s1, const char *s2);
static const char *blanking_pause_mode_repr(blanking_pause_mode_t mode);
static const char *fader_type_name(fader_type_t type);
static int xlat(int src_lo, int src_hi, int dst_lo, int dst_hi, int val);
/* ------------------------------------------------------------------------- *
* SHUTDOWN
* ------------------------------------------------------------------------- */
static bool mdy_shutdown_in_progress(void);
/* ------------------------------------------------------------------------- *
* DATAPIPE_TRACKING
* ------------------------------------------------------------------------- */
static void mdy_datapipe_packagekit_locked_cb(gconstpointer data);;
static void mdy_datapipe_system_state_cb(gconstpointer data);
static void mdy_datapipe_submode_cb(gconstpointer data);
static void mdy_datapipe_interaction_expected_cb(gconstpointer data);
static void mdy_datapipe_lid_sensor_filtered_cb(gconstpointer data);
static gpointer mdy_datapipe_display_state_filter_cb(gpointer data);
static void mdy_datapipe_display_state_curr_cb(gconstpointer data);
static void mdy_datapipe_display_state_next_cb(gconstpointer data);
static void mdy_datapipe_keyboard_slide_input_state_cb(gconstpointer const data);
static void mdy_datapipe_display_brightness_cb(gconstpointer data);
static void mdy_datapipe_lpm_brightness_cb(gconstpointer data);
static void mdy_datapipe_display_state_req_cb(gconstpointer data);
static void mdy_datapipe_audio_route_cb(gconstpointer data);
static void mdy_datapipe_charger_state_cb(gconstpointer data);
static void mdy_datapipe_uiexception_type_cb(gconstpointer data);
static void mdy_datapipe_alarm_ui_state_cb(gconstpointer data);
static void mdy_datapipe_proximity_sensor_actual_cb(gconstpointer data);
static void mdy_datapipe_power_saving_mode_active_cb(gconstpointer data);
static void mdy_datapipe_call_state_trigger_cb(gconstpointer data);
static void mdy_datapipe_device_inactive_cb(gconstpointer data);
static void mdy_datapipe_orientation_sensor_actual_cb(gconstpointer data);
static void mdy_datapipe_shutting_down_cb(gconstpointer aptr);
static void mdy_datapipe_init(void);
static void mdy_datapipe_quit(void);
/* ------------------------------------------------------------------------- *
* FBDEV_FD
* ------------------------------------------------------------------------- */
static void mdy_fbdev_rethink(void);
/* ------------------------------------------------------------------------- *
* HIGH_BRIGHTNESS_MODE
* ------------------------------------------------------------------------- */
static void mdy_hbm_set_level(int number);
static gboolean mdy_hbm_timeout_cb(gpointer data);
static void mdy_hbm_cancel_timeout(void);
static void mdy_hbm_schedule_timeout(void);
static void mdy_hbm_rethink(void);
/* ------------------------------------------------------------------------- *
* BACKLIGHT_BRIGHTNESS
* ------------------------------------------------------------------------- */
#ifdef ENABLE_HYBRIS
static void mdy_brightness_set_level_hybris(int number);
#endif
static void mdy_brightness_set_level_default(int number);
static void mdy_brightness_set_level(int number);
static void mdy_brightness_fade_continue_with_als(fader_type_t fader_type);
static void mdy_brightness_force_level(int number);
static void mdy_brightness_set_priority_boost(bool enable);
static gboolean mdy_brightness_fade_timer_cb(gpointer data);
static void mdy_brightness_cleanup_fade_timer(void);
static void mdy_brightness_stop_fade_timer(void);
static void mdy_brightness_start_fade_timer(fader_type_t type, gint step_time);
static bool mdy_brightness_fade_is_active(void);
static bool mdy_brightness_is_fade_allowed(fader_type_t type);
static void mdy_brightness_set_fade_target_ex(fader_type_t type, gint new_brightness, gint transition_time);
static void mdy_brightness_set_fade_target_default(gint new_brightness);
static void mdy_brightness_set_fade_target_dimming(gint new_brightness);
static void mdy_brightness_set_fade_target_als(gint new_brightness);
static void mdy_brightness_set_fade_target_blank(void);
static void mdy_brightness_set_fade_target_unblank(gint new_brightness);
static int mdy_brightness_get_dim_static(void);
static int mdy_brightness_get_dim_dynamic(void);
static int mdy_brightness_get_dim_threshold_lo(void);
static int mdy_brightness_get_dim_threshold_hi(void);
static void mdy_brightness_set_on_level(gint hbm_and_level);
static void mdy_brightness_set_dim_level(void);
static void mdy_brightness_set_lpm_level(gint level);
static void mdy_brightness_init(void);
/* ------------------------------------------------------------------------- *
* UI_SIDE_DIMMING
* ------------------------------------------------------------------------- */
static void mdy_ui_dimming_set_level(int level);
static void mdy_ui_dimming_rethink(void);
/* ------------------------------------------------------------------------- *
* CONTENT_ADAPTIVE_BACKLIGHT_CONTROL
* ------------------------------------------------------------------------- */
static void mdy_cabc_mode_set(const gchar *const mode);
/* ------------------------------------------------------------------------- *
* BOOTUP_LED_PATTERN
* ------------------------------------------------------------------------- */
static void mdy_poweron_led_rethink(void);
static gboolean mdy_poweron_led_rethink_cb(gpointer aptr);
static void mdy_poweron_led_rethink_cancel(void);
static void mdy_poweron_led_rethink_schedule(void);
/* ------------------------------------------------------------------------- *
* BLANKING_PAUSE_CLIENT
* ------------------------------------------------------------------------- */
void bpclient_update_pid_cb (const peerinfo_t *peerinfo, gpointer userdata);
void bpclient_update_timeout(bpclient_t *self);
bpclient_t *bpclient_create (const char *name);
void bpclient_delete (bpclient_t *self);
void bpclient_delete_cb (void *self);
/* ------------------------------------------------------------------------- *
* AUTOMATIC_BLANKING
* ------------------------------------------------------------------------- */
/** Maximum dim timeout applicable in ACTDEAD mode [s] */
#define ACTDEAD_MAX_DIM_TIMEOUT 15
/** Maximum blank timeout applicable in ACTDEAD mode [s] */
#define ACTDEAD_MAX_OFF_TIMEOUT 15
static bool mdy_blanking_from_lockscreen(void);
static void mdy_blanking_update_device_inactive_delay(void);
static gboolean mdy_blanking_can_blank_from_low_power_mode(void);
// display timer: ON -> DIM
static gint mdy_blanking_get_default_dimming_delay(void);
static gint mdy_blanking_get_dimming_delay(void);
static gboolean mdy_blanking_dim_cb(gpointer data);
static void mdy_blanking_cancel_dim(void);
static void mdy_blanking_schedule_dim(void);
static gboolean mdy_blanking_inhibit_broadcast_cb(gpointer aptr);
static void mdy_blanking_inhibit_cancel_broadcast(void);
static void mdy_blanking_inhibit_schedule_broadcast(void);
// display timer: DIM -> OFF
static gboolean mdy_blanking_off_cb(gpointer data);
static void mdy_blanking_cancel_off(void);
static void mdy_blanking_schedule_off(void);
// display timer: LPM_ON -> LPM_OFF (when proximity covered)
static gboolean mdy_blanking_lpm_off_cb(gpointer data);
static void mdy_blanking_cancel_lpm_off(void);
static void mdy_blanking_schedule_lpm_off(void);
// blanking pause period: inhibit automatic ON -> DIM transitions
static void mdy_blanking_pause_evaluate_allowed(void);
static gboolean mdy_blanking_pause_period_cb(gpointer data);
static void mdy_blanking_stop_pause_period(void);
static void mdy_blanking_start_pause_period(int duration);
static void mdy_blanking_init_pause_client_tracking(void);
static void mdy_blanking_quit_pause_client_tracking(void);
static bool mdy_blanking_is_paused(void);
static bool mdy_blanking_pause_can_dim(void);
static bool mdy_blanking_pause_is_allowed(void);
static void mdy_blanking_add_pause_client(const char *name);
static void mdy_blanking_remove_pause_client(const char *name);
static void mdy_blanking_remove_pause_clients(void);
static void mdy_blanking_evaluate_pause_timeout(void);
// adaptive dimming period: dimming timeouts get longer on ON->DIM->ON transitions
static bool mdy_adaptive_dimming_is_enabled(void);
static gint mdy_blanking_get_adaptive_dimming_delay(void);
static void mdy_blanking_set_adaptive_dimming_delay(int timeout);
static void mdy_blanking_reset_adaptive_dimming_delay(void);
static void mdy_blanking_trigger_adaptive_dimming(void);
static gboolean mdy_blanking_adaptive_dimming_unprime_cb(gpointer data);
static void mdy_blanking_unprime_adaptive_dimming(void);
static void mdy_blanking_prime_adaptive_dimming(void);
// display timer: all of em
static bool mdy_blanking_inhibit_off_p(void);
static bool mdy_blanking_inhibit_dim_p(void);
static void mdy_blanking_rethink_timers(bool force);
static void mdy_blanking_rethink_proximity(void);
static void mdy_blanking_cancel_timers(void);
// after boot blank prevent
static void mdy_blanking_rethink_afterboot_delay(void);
static gint mdy_blanking_get_afterboot_delay(void);
/* ------------------------------------------------------------------------- *
* DISPLAY_TYPE_PROBING
* ------------------------------------------------------------------------- */
static int mdy_display_type_glob_err_cb(const char *path, int err);
static gboolean mdy_display_type_probe_brightness(const gchar *dirpath, char **setpath, char **maxpath);
static gboolean mdy_display_type_get_from_config(display_type_t *display_type);
static gboolean mdy_display_type_get_from_sysfs_probe(display_type_t *display_type);
static gboolean mdy_display_type_get_from_hybris(display_type_t *display_type);
static display_type_t mdy_display_type_get(void);
/* ------------------------------------------------------------------------- *
* FBDEV_SLEEP_AND_WAKEUP
* ------------------------------------------------------------------------- */
#ifdef ENABLE_WAKELOCKS
static gboolean mdy_waitfb_event_cb(GIOChannel *chn, GIOCondition cnd, gpointer aptr);
static void *mdy_waitfb_thread_entry(void *aptr);
static gboolean mdy_waitfb_thread_start(waitfb_t *self);
static void mdy_waitfb_thread_stop(waitfb_t *self);
#endif
/* ------------------------------------------------------------------------- *
* TOPMOST_WINDOW_TRACKING
* ------------------------------------------------------------------------- */
static void mdy_topmost_window_set_pid (int pid);
static gboolean mdy_topmost_window_pid_changed_cb (DBusMessage *const sig);
static void mdy_topmost_window_pid_reply_cb (DBusPendingCall *pc, void *aptr);
static void mdy_topmost_window_forget_pid_query (void);
static void mdy_topmost_window_send_pid_query (void);
/* ------------------------------------------------------------------------- *
* compositor_led_t
* ------------------------------------------------------------------------- */
static void compositor_led_set_active (compositor_led_t led, bool active);
static bool compositor_led_is_active (compositor_led_t led);
/* ------------------------------------------------------------------------- *
* compositor_state_t
* ------------------------------------------------------------------------- */
static const char *compositor_state_repr (compositor_state_t state);
/* ------------------------------------------------------------------------- *
* renderer_state_t
* ------------------------------------------------------------------------- */
static const char *renderer_state_repr (renderer_state_t state);
/* ------------------------------------------------------------------------- *
* compositor_stm_t
* ------------------------------------------------------------------------- */
typedef struct compositor_stm_t compositor_stm_t;
static void compositor_stm_ctor (compositor_stm_t *self);
static void compositor_stm_dtor (compositor_stm_t *self);
compositor_stm_t *compositor_stm_create (void);
void compositor_stm_delete (compositor_stm_t *self);
void compositor_stm_delete_cb (void *self);
static void compositor_stm_set_service_pid (compositor_stm_t *self, pid_t pid);
static void compositor_stm_set_service_owner (compositor_stm_t *self, const char *owner);
static const char *compositor_stm_get_service_owner (const compositor_stm_t *self);
static void compositor_stm_send_pid_query (compositor_stm_t *self);
static void compositor_stm_forget_pid_query (compositor_stm_t *self);
static void compositor_stm_pid_query_cb (DBusPendingCall *pc, void *aptr);
static void compositor_stm_send_ctrl_request (compositor_stm_t *self);
static void compositor_stm_forget_ctrl_request(compositor_stm_t *self);
static void compositor_stm_ctrl_request_cb (DBusPendingCall *pc, void *aptr);
static void compositor_stm_schedule_panic (compositor_stm_t *self);
static void compositor_stm_cancel_panic (compositor_stm_t *self);
static gboolean compositor_stm_panic_timer_cb (void *aptr);
static void compositor_stm_schedule_retry (compositor_stm_t *self);
static void compositor_stm_cancel_retry (compositor_stm_t *self);
static gboolean compositor_stm_retry_timer_cb (void *aptr);
static void compositor_stm_schedule_killer (compositor_stm_t *self);
static void compositor_stm_cancel_killer (compositor_stm_t *self);
static gboolean compositor_stm_core_timer_cb (void *aptr);
static gboolean compositor_stm_kill_timer_cb (void *aptr);
static gboolean compositor_stm_bury_timer_cb (void *aptr);
static compositor_state_t compositor_stm_get_state (const compositor_stm_t *self);
static void compositor_stm_set_state (compositor_stm_t *self, compositor_state_t state);
static void compositor_stm_enter_state (compositor_stm_t *self);
static void compositor_stm_leave_state (compositor_stm_t *self);
static void compositor_stm_eval_state (compositor_stm_t *self);
static void compositor_stm_set_target (compositor_stm_t *self, renderer_state_t state);
static void compositor_stm_set_requested (compositor_stm_t *self, renderer_state_t state);
static void compositor_stm_set_granted (compositor_stm_t *self, renderer_state_t state);
static bool compositor_stm_is_pending (const compositor_stm_t *self);
static bool compositor_stm_is_enabled (const compositor_stm_t *self);
static bool compositor_stm_is_disabled (const compositor_stm_t *self);
static void compositor_stm_set_enabled (compositor_stm_t *self, bool enable);
/* ------------------------------------------------------------------------- *
* COMPOSITOR_IPC
* ------------------------------------------------------------------------- */
static void mdy_compositor_init(void);
static void mdy_compositor_quit(void);
static void mdy_compositor_set_name_owner(const char *curr);
static void mdy_compositor_disable(void);
static void mdy_compositor_enable(void);
static bool mdy_compositor_is_available(void);
static bool mdy_compositor_is_pending(void);
static bool mdy_compositor_is_disabled(void);
static bool mdy_compositor_is_enabled(void);
/* ------------------------------------------------------------------------- *
* CALLSTATE_CHANGES
* ------------------------------------------------------------------------- */
enum
{
/** Default duration for blocking suspend after call_state changes */
CALLSTATE_CHANGE_BLOCK_SUSPEND_DEFAULT_MS = 15 * 1000,
/** Duration for blocking suspend after call_state changes to active */
CALLSTATE_CHANGE_BLOCK_SUSPEND_ACTIVE_MS = 60 * 1000,
};
static gboolean mdy_callstate_end_changed_cb(gpointer aptr);
static bool mdy_callstate_changed_recently(void);
static void mdy_callstate_clear_changed(void);
static void mdy_callstate_set_changed(void);
/* ------------------------------------------------------------------------- *
* AUTOSUSPEND_POLICY
* ------------------------------------------------------------------------- */
#ifdef ENABLE_WAKELOCKS
static int mdy_autosuspend_get_allowed_level(void);
static void mdy_autosuspend_setting_cb(GConfClient *const client, const guint id, GConfEntry *const entry, gpointer const data);
#endif
/* ------------------------------------------------------------------------- *
* ORIENTATION_ACTIVITY
* ------------------------------------------------------------------------- */
static void mdy_orientation_changed_cb(int state);
static void mdy_orientation_generate_activity(void);
static bool mdy_orientation_sensor_wanted(void);
static void mdy_orientation_sensor_rethink(void);
/* ------------------------------------------------------------------------- *
* DISPLAY_STATE
* ------------------------------------------------------------------------- */
static void mdy_display_state_changed(void);
static void mdy_display_state_enter(display_state_t prev_state, display_state_t next_state);
static void mdy_display_state_leave(display_state_t prev_state, display_state_t next_state);
/* ------------------------------------------------------------------------- *
* FRAMEBUFFER_SUSPEND_RESUME
* ------------------------------------------------------------------------- */
/** Framebuffer suspend/resume failure led patterns */
typedef enum
{
FBDEV_LED_OFF,
FBDEV_LED_SUSPENDING,
FBDEV_LED_RESUMING,
} mdy_fbsusp_led_state_t;
static void mdy_fbsusp_led_set(mdy_fbsusp_led_state_t req);
static gboolean mdy_fbsusp_led_timer_cb(gpointer aptr);
static void mdy_fbsusp_led_cancel_timer(void);
static void mdy_fbsusp_led_start_timer(mdy_fbsusp_led_state_t req);
/* ------------------------------------------------------------------------- *
* DISPLAY_STATE_MACHINE
* ------------------------------------------------------------------------- */
// human readable state names
static const char *mdy_stm_state_name(stm_state_t state);
// react to systemui availability changes
static void mdy_datapipe_compositor_service_state_cb(gconstpointer aptr);
static void mdy_datapipe_lipstick_service_state_cb(gconstpointer aptr);
// whether there is unhandled compositor availability change
static void mdy_stm_set_compositor_availability_changed(bool changed);
// whether to power on/off the frame buffer
static bool mdy_stm_display_state_needs_power(display_state_t state);
// asynchronous ioctl framebuffer power control
static void mdy_stm_fbdev_power_done_cb(void *aptr, void *reply);
static void *mdy_stm_fbdev_power_exec_cb(void *aptr);
static void mdy_stm_fbdev_set_power(bool poweron);
// asynchronous sysfs write to allow/deny suspending
static void mdy_stm_autosuspend_done_cb(void *aptr, void *reply);
static void *mdy_stm_autosuspend_exec_cb(void *aptr);
static void mdy_stm_autosuspend_set_state(bool allow);
// early/late suspend and resume
static bool mdy_stm_is_early_suspend_allowed(void);
static bool mdy_stm_is_late_suspend_allowed(void);
static void mdy_stm_start_fb_suspend(void);
static bool mdy_stm_is_fb_suspend_finished(void);
static void mdy_stm_start_fb_resume(void);
static bool mdy_stm_is_fb_resume_finished(void);
static void mdy_stm_release_wakelock(void);
static void mdy_stm_acquire_wakelock(void);
// display state changing
static void mdy_stm_push_target_change(display_state_t next_state);
static bool mdy_stm_pull_target_change(void);
static void mdy_stm_finish_target_change(void);
// actual state machine
static void mdy_stm_trans(stm_state_t state);
static void mdy_stm_step(void);
static void mdy_stm_exec(void);
// delayed state machine execution
static gboolean mdy_stm_rethink_cb(gpointer aptr);
static void mdy_stm_cancel_rethink(void);
static void mdy_stm_schedule_rethink(void);
static void mdy_stm_force_rethink(void);
/* ------------------------------------------------------------------------- *
* DISPLAY_STATE_STATISTICS
* ------------------------------------------------------------------------- */
static void mdy_statistics_update(void);
/* ------------------------------------------------------------------------- *
* CPU_SCALING_GOVERNOR
* ------------------------------------------------------------------------- */
static governor_setting_t *mdy_governor_get_settings(const char *tag);
static void mdy_governor_free_settings(governor_setting_t *settings);
static bool mdy_governor_write_data(const char *path, const char *data);
static void mdy_governor_apply_setting(const governor_setting_t *setting);
static void mdy_governor_set_state(int state);
static void mdy_governor_rethink(void);
static void mdy_governor_setting_cb(GConfClient *const client, const guint id, GConfEntry *const entry, gpointer const data);
/* ------------------------------------------------------------------------- *
* DBUS_HANDLERS
* ------------------------------------------------------------------------- */
static gboolean mdy_dbus_send_blanking_pause_status(DBusMessage *const method_call);
static gboolean mdy_dbus_send_blanking_pause_allowed_status(DBusMessage *const method_call);
static gboolean mdy_dbus_handle_blanking_pause_get_req(DBusMessage *const msg);
static gboolean mdy_dbus_handle_blanking_pause_allowed_get_req(DBusMessage *const msg);
static gboolean mdy_dbus_send_blanking_inhibit_status(DBusMessage *const method_call);
static gboolean mdy_dbus_handle_blanking_inhibit_get_req(DBusMessage *const msg);
static void mdy_dbus_invalidate_display_status(void);
static gboolean mdy_dbus_send_display_status(DBusMessage *const method_call);
static const char *mdy_dbus_get_reason_to_block_display_on(void);
static void mdy_dbus_handle_display_state_req(display_state_t state);
static gboolean mdy_dbus_handle_display_on_req(DBusMessage *const msg);
static gboolean mdy_dbus_handle_display_dim_req(DBusMessage *const msg);
static gboolean mdy_dbus_handle_display_off_req(DBusMessage *const msg);
static gboolean mdy_dbus_handle_display_lpm_req(DBusMessage *const msg);
#ifdef ENABLE_DEVEL_LOGGING
static gboolean mdy_dbus_handle_display_lpm_on_req(DBusMessage *const msg);
static gboolean mdy_dbus_handle_display_lpm_off_req(DBusMessage *const msg);
#endif
static gboolean mdy_dbus_handle_display_status_get_req(DBusMessage *const msg);
static gboolean mdy_dbus_send_cabc_mode(DBusMessage *const method_call);
static gboolean mdy_dbus_handle_cabc_mode_owner_lost_sig(DBusMessage *const msg);
static gboolean mdy_dbus_handle_cabc_mode_get_req(DBusMessage *const msg);
static gboolean mdy_dbus_handle_cabc_mode_set_req(DBusMessage *const msg);
static gboolean mdy_dbus_handle_blanking_pause_start_req(DBusMessage *const msg);
static gboolean mdy_dbus_handle_blanking_pause_cancel_req(DBusMessage *const msg);
static gboolean mdy_dbus_handle_display_stats_get_req(DBusMessage *const req);
static gboolean mdy_dbus_handle_desktop_started_sig(DBusMessage *const msg);
static void mdy_dbus_init(void);
static void mdy_dbus_quit(void);
/* ------------------------------------------------------------------------- *
* FLAG_FILE_TRACKING
* ------------------------------------------------------------------------- */
static gboolean mdy_flagfiles_desktop_ready_cb(gpointer user_data);
static void mdy_flagfiles_bootstate_cb(const char *path, const char *file, gpointer data);
static void mdy_flagfiles_init_done_cb(const char *path, const char *file, gpointer data);
static void mdy_flagfiles_osupdate_running_cb(const char *path, const char *file, gpointer data);
static void mdy_flagfiles_start_tracking(void);
static void mdy_flagfiles_stop_tracking(void);
/* ------------------------------------------------------------------------- *
* DYNAMIC_SETTINGS
* ------------------------------------------------------------------------- */
static void mdy_setting_cb(GConfClient *const gcc, const guint id, GConfEntry *const entry, gpointer const data);
static void mdy_setting_init(void);
static void mdy_setting_quit(void);
static void mdy_setting_sanitize_brightness_levels(void);
static void mdy_setting_sanitize_dim_timeouts(bool force_update);
/* ------------------------------------------------------------------------- *
* MODULE_LOAD_UNLOAD
* ------------------------------------------------------------------------- */
G_MODULE_EXPORT const gchar *g_module_check_init(GModule *module);
G_MODULE_EXPORT void g_module_unload(GModule *module);
/* ========================================================================= *
* VARIABLES
* ========================================================================= */
/** Display blank prevention timer */
static const gint mdy_blank_prevent_timeout = BLANK_PREVENT_TIMEOUT * 1000;
static const gint mdy_blank_prevent_slack = BLANK_PREVENT_SLACK * 1000;
/* ------------------------------------------------------------------------- *
* MODULE_LOAD_UNLOAD
* ------------------------------------------------------------------------- */
/** Functionality provided by this module */
static const gchar *const provides[] = { MODULE_NAME, NULL };
/** Module information */
G_MODULE_EXPORT module_info_struct module_info = {
/** Name of the module */
.name = MODULE_NAME,
/** Module provides */
.provides = provides,
/** Module priority */
.priority = 250
};
/* ------------------------------------------------------------------------- *
* SHUTDOWN
* ------------------------------------------------------------------------- */
/** Have we seen shutdown_ind signal or equivalent from dsme */
static bool mdy_shutdown_started_flag = false;
/** Start of shutdown timestamp */
static int64_t mdy_shutdown_started_tick = 0;
/** Are we already unloading the module? */
static gboolean mdy_unloading_module = FALSE;
/** Timer for waiting simulated desktop ready state */
static guint mdy_desktop_ready_id = 0;
/** Device is shutting down predicate
*/
static bool mdy_shutdown_in_progress(void)
{
return mdy_shutdown_started_flag;
}
/* ------------------------------------------------------------------------- *
* BLANKING_PAUSE_CLIENT
* ------------------------------------------------------------------------- */
/** Callback for handling blanking pause client state change notifications
*
* @param peerinfo peerinfo_t object holding currently known peer details
* @param userdata bpclient_t object as void pointer
*/
void
bpclient_update_pid_cb(const peerinfo_t *peerinfo, gpointer userdata)
{
bpclient_t *self = userdata;
peerstate_t state = peerinfo_get_state(peerinfo);
pid_t pid = peerinfo_get_owner_pid(peerinfo);
mce_log(LL_DEBUG, "client %s @%s pid=%d", self->bpc_name,
peerstate_repr(state), (int)pid);
switch( state ) {
case PEERSTATE_STALE:
case PEERSTATE_STOPPED:
case PEERSTATE_DELETED:
mdy_blanking_remove_pause_client(self->bpc_name), self = 0;
goto EXIT;
default:
break;
}
if( self->bpc_pid != pid ) {
self->bpc_pid = pid;
mdy_blanking_evaluate_pause_timeout();
}
EXIT:
return;
}
/** Renew timeout for blanking pause client
*
* @param self bpclient_t object