/
display.c
8465 lines (6973 loc) · 258 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.h"
#include "../mce-log.h"
#include "../mce-io.h"
#include "../mce-lib.h"
#include "../mce-fbdev.h"
#include "../mce-conf.h"
#include "../mce-gconf.h"
#include "../mce-dbus.h"
#include "../mce-sensorfw.h"
#ifdef ENABLE_HYBRIS
# include "../mce-hybris.h"
#endif
#include "../filewatcher.h"
#ifdef ENABLE_WAKELOCKS
# include "../libwakelock.h"
#endif
#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"
/** Define demo mode DBUS method */
#define MCE_DBUS_DEMO_MODE_REQ "display_set_demo_mode"
/** UI side graphics fading percentage
*
* Controls 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_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
/* ========================================================================= *
* 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;
/** Inhibit type */
typedef enum {
/** Inhibit value invalid */
INHIBIT_INVALID = -1,
/** No inhibit */
INHIBIT_OFF = 0,
/** Default value */
DEFAULT_BLANKING_INHIBIT_MODE = INHIBIT_OFF,
/** Inhibit blanking; always keep on if charger connected */
INHIBIT_STAY_ON_WITH_CHARGER = 1,
/** Inhibit blanking; always keep on or dimmed if charger connected */
INHIBIT_STAY_DIM_WITH_CHARGER = 2,
/** Inhibit blanking; always keep on */
INHIBIT_STAY_ON = 3,
/** Inhibit blanking; always keep on or dimmed */
INHIBIT_STAY_DIM = 4,
} inhibit_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;
/** UpdatesEnabled state for UI */
typedef enum
{
RENDERER_ERROR = -2,
RENDERER_UNKNOWN = -1,
RENDERER_DISABLED = 0,
RENDERER_ENABLED = 1,
} renderer_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 = 1500,
};
/* ========================================================================= *
* PROTOTYPES
* ========================================================================= */
/* ------------------------------------------------------------------------- *
* MISC_UTILS
* ------------------------------------------------------------------------- */
static inline bool mdy_str_eq_p(const char *s1, const char *s2);
static int64_t mdy_get_boot_tick(void);
/* ------------------------------------------------------------------------- *
* SHUTDOWN
* ------------------------------------------------------------------------- */
static bool mdy_shutdown_in_progress(void);
static void mdy_shutdown_set_state(bool in_progress);
/* ------------------------------------------------------------------------- *
* 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 gpointer mdy_datapipe_display_state_filter_cb(gpointer data);
static void mdy_datapipe_display_state_cb(gconstpointer data);
static void mdy_datapipe_display_state_next_cb(gconstpointer 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_exception_state_cb(gconstpointer data);
static void mdy_datapipe_alarm_ui_state_cb(gconstpointer data);
static void mdy_datapipe_proximity_sensor_cb(gconstpointer data);
static void mdy_datapipe_power_saving_mode_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_state_cb(gconstpointer data);
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
* ------------------------------------------------------------------------- */
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;
static const char *
fader_type_name(fader_type_t type)
{
static const char * const lut[FADER_NUMOF] =
{
[FADER_IDLE] = "IDLE",
[FADER_DEFAULT] = "DEFAULT",
[FADER_DIMMING] = "DIMMING",
[FADER_ALS] = "ALS",
[FADER_BLANK] = "BLANK",
[FADER_UNBLANK] = "UNBLANK",
};
return (type < FADER_NUMOF) ? lut[type] : "INVALID";
}
#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_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 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 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);
/* ------------------------------------------------------------------------- *
* UI_SIDE_DIMMING
* ------------------------------------------------------------------------- */
static void mdy_ui_dimming_set_needed(bool is_needed);
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);
/* ------------------------------------------------------------------------- *
* AUTOMATIC_BLANKING
* ------------------------------------------------------------------------- */
static guint mdy_blanking_find_dim_timeout_index(gint dim_timeout);
static gboolean mdy_blanking_can_blank_from_low_power_mode(void);
// display timer: ON -> DIM
static gboolean mdy_blanking_dim_cb(gpointer data);
static void mdy_blanking_cancel_dim(void);
static void mdy_blanking_schedule_dim(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 gboolean mdy_blanking_pause_period_cb(gpointer data);
static void mdy_blanking_stop_pause_period(void);
static void mdy_blanking_start_pause_period(void);
static bool mdy_blanking_is_paused(void);
static void mdy_blanking_add_pause_client(const gchar *name);
static gboolean mdy_blanking_remove_pause_client(const gchar *name);
static void mdy_blanking_remove_pause_clients(void);
static gboolean mdy_blanking_pause_client_lost_cb(DBusMessage *const msg);
// adaptive dimming period: dimming timeouts get longer on ON->DIM->ON transitions
static gboolean mdy_blanking_adaptive_dimming_cb(gpointer data);
static void mdy_blanking_start_adaptive_dimming(void);
static void mdy_blanking_stop_adaptive_dimming(void);
// display timer: all of em
static void mdy_blanking_rethink_timers(bool force);
static void mdy_blanking_rethink_proximity(void);
static void mdy_blanking_cancel_timers(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
/* ------------------------------------------------------------------------- *
* COMPOSITOR_IPC
* ------------------------------------------------------------------------- */
static void mdy_compositor_set_killer_led(bool enable);
static void mdy_compositor_set_panic_led(renderer_state_t req);
static gboolean mdy_compositor_panic_led_cb(gpointer aptr);
static void mdy_compositor_cancel_panic_led(void);
static void mdy_compositor_schedule_panic_led(renderer_state_t req);
static gboolean mdy_compositor_kill_verify_cb(gpointer aptr);
static gboolean mdy_compositor_kill_kill_cb(gpointer aptr);
static gboolean mdy_compositor_kill_core_cb(gpointer aptr);
static void mdy_compositor_schedule_killer(void);
static void mdy_compositor_cancel_killer(void);
static void mdy_compositor_name_owner_pid_cb(const char *name, int pid);
static bool mdy_compositor_is_available(void);
static void mdy_compositor_name_owner_set(const char *curr);
static void mdy_compositor_state_req_cb(DBusPendingCall *pending, void *user_data);
static void mdy_compositor_cancel_state_req(void);
static gboolean mdy_compositor_start_state_req(renderer_state_t state);
/* ------------------------------------------------------------------------- *
* CALLSTATE_CHANGES
* ------------------------------------------------------------------------- */
enum
{
/** Default duration for blocking suspend after call_state changes */
CALLSTATE_CHANGE_BLOCK_SUSPEND_DEFAULT_MS = 5 * 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_gconf_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 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_available_cb(gconstpointer aptr);
static void mdy_datapipe_lipstick_available_cb(gconstpointer aptr);
// whether to power on/off the frame buffer
static bool mdy_stm_display_state_needs_power(display_state_t state);
// 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 bool mdy_stm_is_target_changing(void);
static void mdy_stm_finish_target_change(void);
// setUpdatesEnabled() from state machine
static bool mdy_stm_is_renderer_pending(void);
static bool mdy_stm_is_renderer_disabled(void);
static bool mdy_stm_is_renderer_enabled(void);
static void mdy_stm_disable_renderer(void);
static void mdy_stm_enable_renderer(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);
/* ------------------------------------------------------------------------- *
* 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_conf_cb(GConfClient *const client, const guint id, GConfEntry *const entry, gpointer const data);
/* ------------------------------------------------------------------------- *
* DBUS_HANDLERS
* ------------------------------------------------------------------------- */
static gboolean mdy_dbus_send_display_status(DBusMessage *const method_call);
static const char *mdy_dbus_get_reason_to_block_display_on(void);
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);
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_set_demo_mode_req(DBusMessage *const msg);
static gboolean mdy_dbus_handle_desktop_started_sig(DBusMessage *const msg);
static void mdy_dbus_handle_shutdown_started(void);
static gboolean mdy_dbus_handle_shutdown_started_sig(DBusMessage *const msg);
static gboolean mdy_dbus_handle_thermal_shutdown_started_sig(DBusMessage *const msg);
static gboolean mdy_dbus_handle_battery_empty_shutdown_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_update_mode_cb(const char *path, const char *file, gpointer data);
static void mdy_flagfiles_start_tracking(void);
static void mdy_flagfiles_stop_tracking(void);
/* ------------------------------------------------------------------------- *
* GCONF_SETTINGS
* ------------------------------------------------------------------------- */
static void mdy_gconf_cb(GConfClient *const gcc, const guint id, GConfEntry *const entry, gpointer const data);
static void mdy_gconf_init(void);
static void mdy_gconf_quit(void);
static void mdy_gconf_sanitize_brightness_settings(void);
/* ------------------------------------------------------------------------- *
* MODULE_LOAD_UNLOAD
* ------------------------------------------------------------------------- */
G_MODULE_EXPORT const gchar *g_module_check_init(GModule *module);
G_MODULE_EXPORT void g_module_unload(GModule *module);
/* ========================================================================= *
* VARIABLES
* ========================================================================= */
/* ------------------------------------------------------------------------- *
* 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;
}
/** Update device is shutting down state
*/
static void mdy_shutdown_set_state(bool in_progress)
{
if( mdy_shutdown_started_flag == in_progress )
goto EXIT;
if( (mdy_shutdown_started_flag = in_progress) ) {
mce_log(LL_DEVEL, "Shutdown started");
mdy_shutdown_started_tick = mdy_get_boot_tick();
}
else {
mce_log(LL_DEVEL, "Shutdown canceled");
}
/* Framebuffer must be kept open during shutdown */
mdy_fbdev_rethink();
EXIT:
return;
}
/* ------------------------------------------------------------------------- *
* AUTOMATIC_BLANKING
* ------------------------------------------------------------------------- */
/** ID for adaptive display dimming timer source */
static guint mdy_blanking_adaptive_dimming_cb_id = 0;
/** Index for the array of adaptive dimming timeout multipliers */
static guint mdy_adaptive_dimming_index = 0;
/** Display blank timeout setting when low power mode is supported */
static gint mdy_disp_lpm_off_timeout = DEFAULT_LPM_BLANK_TIMEOUT;
/** Display low power mode timeout setting */
static gint mdy_disp_lpm_on_timeout = DEFAULT_BLANK_TIMEOUT;
/** Display blank prevention timer */
static gint mdy_blank_prevent_timeout = BLANK_PREVENT_TIMEOUT;
/** Bootup dim additional timeout */
static gint mdy_additional_bootup_dim_timeout = 0;
/** File used to enable low power mode */
static gchar *mdy_low_power_mode_file = NULL;
/** Is display low power mode supported
*
* Since we now support proximity based fake lpm that does not
* require special support from display hw / drivers, the logic
* for mdy_low_power_mode_supported can be switched to: enabled
* by default and disabled only in special cases.
*/
static gboolean mdy_low_power_mode_supported = TRUE;
/** Maximum number of monitored services that calls blanking pause */
#define BLANKING_PAUSE_MAX_MONITORED 5
/**
* Index for the array of possible display dim timeouts
*/
static guint mdy_dim_timeout_index = 0;
/* ------------------------------------------------------------------------- *
* HIGH_BRIGHTNESS_MODE
* ------------------------------------------------------------------------- */
/** File used to set high brightness mode */
static output_state_t mdy_high_brightness_mode_output =
{
.context = "high_brightness_mode",
.truncate_file = TRUE,
.close_on_exit = FALSE,
};
/** Is display high brightness mode supported */
static gboolean mdy_high_brightness_mode_supported = FALSE;
/* ------------------------------------------------------------------------- *
* CONTENT_ADAPTIVE_BACKLIGHT_CONTROL
* ------------------------------------------------------------------------- */
/** Is content adaptive brightness control supported */
static gboolean mdy_cabc_is_supported = FALSE;
/** File used to get the available CABC modes */
static gchar *mdy_cabc_available_modes_file = NULL;
/**
* CABC mode (power save mode active) -- uses the SysFS mode names;
* NULL to disable
*/
static const gchar *mdy_psm_cabc_mode = NULL;
/** CABC mode -- uses the SysFS mode names */
static const gchar *mdy_cabc_mode = DEFAULT_CABC_MODE;
/** File used to set the CABC mode */
static gchar *mdy_cabc_mode_file = NULL;
/** List of monitored CABC mode requesters */
static GSList *mdy_cabc_mode_monitor_list = NULL;
/* ------------------------------------------------------------------------- *
* FLAG_FILE_TRACKING
* ------------------------------------------------------------------------- */
/** Are we going to USER or ACT_DEAD */
static bootstate_t mdy_bootstate = BOOTSTATE_UNKNOWN;
/** Content change watcher for the bootstate flag file */
static filewatcher_t *mdy_bootstate_watcher = 0;
/** Is the init-done flag file present in the file system */
static gboolean mdy_init_done = FALSE;
/** Content change watcher for the init-done flag file */
static filewatcher_t *mdy_init_done_watcher = 0;
/** Is the update-mode flag file present in the file system */
static gboolean mdy_update_mode = FALSE;
/** Content change watcher for the update-mode flag file */
static filewatcher_t *mdy_update_mode_watcher = 0;
/* ------------------------------------------------------------------------- *
* GCONF_SETTINGS
* ------------------------------------------------------------------------- */
/** Display blanking timeout setting */
static gint mdy_disp_blank_timeout = DEFAULT_BLANK_TIMEOUT;
/** GConf callback ID for mdy_disp_blank_timeout */
static guint mdy_disp_blank_timeout_gconf_cb_id = 0;
/** Number of brightness steps */
static gint mdy_brightness_step_count = DEFAULT_DISP_BRIGHTNESS_STEP_COUNT;
/** Size of one brightness step */
static gint mdy_brightness_step_size = DEFAULT_DISP_BRIGHTNESS_STEP_SIZE;
/** display brightness setting; [1, mdy_brightness_step_count] */
static gint mdy_brightness_setting = DEFAULT_DISP_BRIGHTNESS;
/** timestamp of the latest brightness setting change */
static int64_t mdy_brightness_setting_change_time = 0;
/** GConf callback ID for mdy_brightness_step_count */
static guint mdy_brightness_step_count_gconf_id = 0;
/** GConf callback ID for mdy_brightness_step_size */
static guint mdy_brightness_step_size_gconf_id = 0;
/** GConf callback ID for mdy_brightness_setting */
static guint mdy_brightness_setting_gconf_id = 0;
/** GConf callback ID for auto-brightness setting */
static guint mdy_automatic_brightness_setting_gconf_id = 0;
/** PSM display brightness setting; [1, 5]
* or -1 when power save mode is not active
*
* (not in gconf, but kept close to mdy_brightness_setting)
*/
static gint mdy_psm_disp_brightness = -1;
/** Never blank display setting */
static gint mdy_disp_never_blank = 0;
/** GConf callback ID for display never blank setting */
static guint mdy_disp_never_blank_gconf_cb_id = 0;
/** Use adaptive timeouts for dimming */
static gboolean mdy_adaptive_dimming_enabled = DEFAULT_ADAPTIVE_DIMMING_ENABLED;
/** GConf callback ID for display blanking timeout setting */
static guint mdy_adaptive_dimming_enabled_gconf_cb_id = 0;
/** Array of possible display dim timeouts */
static GSList *mdy_possible_dim_timeouts = NULL;
/** Threshold to use for adaptive timeouts for dimming in milliseconds */
static gint mdy_adaptive_dimming_threshold = DEFAULT_ADAPTIVE_DIMMING_THRESHOLD;
/** GConf callback ID for the threshold for adaptive display dimming */
static guint mdy_adaptive_dimming_threshold_gconf_cb_id = 0;
/** Display dimming timeout setting */
static gint mdy_disp_dim_timeout = DEFAULT_DIM_TIMEOUT;
/** GConf callback ID for display dimming timeout setting */
static guint mdy_disp_dim_timeout_gconf_cb_id = 0;
/** Use low power mode setting */
static gboolean mdy_use_low_power_mode = FALSE;
/** GConf callback ID for low power mode setting */
static guint mdy_use_low_power_mode_gconf_cb_id = 0;
/** Display blanking inhibit mode */
static inhibit_t mdy_blanking_inhibit_mode = DEFAULT_BLANKING_INHIBIT_MODE;
/** GConf callback ID for display blanking inhibit mode setting */
static guint mdy_blanking_inhibit_mode_gconf_cb_id = 0;
/* ========================================================================= *
* MISC_UTILS
* ========================================================================= */
/** Null tolerant string equality predicate
*/
static inline bool mdy_str_eq_p(const char *s1, const char *s2)
{
// Note: mdy_str_eq_p(NULL, NULL) -> false on purpose
return (s1 && s2) ? !strcmp(s1, s2) : false;
}
/** Get CLOCK_BOOTTIME time stamp in milliseconds
*/
static int64_t mdy_get_boot_tick(void)
{
int64_t res = 0;
struct timespec ts;
if( clock_gettime(CLOCK_BOOTTIME, &ts) == 0 ) {
res = ts.tv_sec;
res *= 1000;
res += ts.tv_nsec / 1000000;
}
return res;
}
/* ========================================================================= *
* DATAPIPE_TRACKING
* ========================================================================= */
/** PackageKit Locked property is set to true during sw updates */
static bool packagekit_locked = false;
/**
* Handle packagekit_locked_pipe notifications
*
* @param data The locked state stored in a pointer
*/
static void mdy_datapipe_packagekit_locked_cb(gconstpointer data)
{
bool prev = packagekit_locked;
packagekit_locked = GPOINTER_TO_INT(data);
if( packagekit_locked == prev )
goto EXIT;
/* Log by default as it might help analyzing upgrade problems */
mce_log(LL_WARN, "packagekit_locked = %d", packagekit_locked);
/* re-evaluate suspend policy */
mdy_stm_schedule_rethink();
EXIT:
return;
}
/* Cached system state */
static system_state_t system_state = MCE_STATE_UNDEF;
/**
* Handle system_state_pipe notifications
*
* @param data The system state stored in a pointer
*/