/
ke-recv.c
3427 lines (3062 loc) · 116 KB
/
ke-recv.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 ke-recv.c
This file is part of ke-recv.
Copyright (C) 2004-2009 Nokia Corporation. All rights reserved.
Copyright (C) 2012 Pali Rohár <pali.rohar@gmail.com>
Author: Kimmo Hämäläinen <kimmo.hamalainen@nokia.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include <libhal.h>
#include "ke-recv.h"
#include "exec-func.h"
#include "gui.h"
#include "events.h"
#include "camera.h"
#include <hildon-mime.h>
#include <libgen.h>
#define FDO_SERVICE "org.freedesktop.Notifications"
#define FDO_OBJECT_PATH "/org/freedesktop/Notifications"
#define FDO_INTERFACE "org.freedesktop.Notifications"
#define USB_DOMAIN "hildon-status-bar-usb"
#define DESKTOP_IF "com.nokia.HildonDesktop"
#define FREMANTLE_MODE 1
extern GConfClient* gconfclient;
/*
const char* camera_out_udi = NULL;
const char* camera_turned_udi = NULL;
*/
const char* slide_keyboard_udi = NULL;
const char* usb_cable_udi = NULL;
static char *usb_device_name = NULL;
static char *default_usb_device_name = NULL;
/* memory card information structs */
static mmc_info_t int_mmc, ext_mmc;
static gboolean int_mmc_enabled = FALSE;
static gboolean mmc_initialised = FALSE;
/* list of USB mass storages */
static storage_info_t *storage_list = NULL;
static usb_state_t usb_state = S_INVALID_USB_STATE;
static guint usb_pending_timer_id = 0;
static guint usb_mounting_timer_id = 0;
static dbus_uint32_t usb_dialog = -1;
static int usb_unmount_timeout = 0;
extern gboolean device_locked;
gboolean desktop_started = FALSE;
static gboolean delayed_auto_install_check = FALSE;
static gboolean mmc_keys_set = FALSE;
/* "the connection" is the connection where "the message" (i.e.
the current message or signal that we're handling) came */
static DBusConnection* the_connection = NULL;
static DBusConnection* sys_conn = NULL;
DBusConnection* ses_conn = NULL;
static DBusMessage* the_message = NULL;
osso_context_t *osso;
static LibHalContext *hal_ctx;
static GMainLoop *mainloop;
void send_error(const char* s);
static void add_volume(volume_list_t *l, const char *udi);
static void add_prop_watch(const char *udi);
static int get_storage(const char *udi, char **storage_parent,
char **storage_udi);
static char *get_dev_name(const char *storage_udi);
static void handle_usb_event(usb_event_t e);
static int mount_volume(volume_list_t *vol);
static int unmount_volume(volume_list_t *vol);
static volume_list_t *add_usb_volume(volume_list_t *l, const char *udi);
static gboolean usb_unmount_recheck(gpointer data);
static int unmount_usb_volumes(void);
static int launch_fm(void);
static gboolean e_plugged_helper(void);
static void possibly_start_am(void);
static gboolean init_usb_cable_status(gpointer data);
static int mount_usb_volumes(void);
static storage_info_t *storage_from_list(const char *udi);
static mmc_info_t *mmc_from_dev_name(const char *dev);
static void get_usb_cable_udi();
static void set_usb_mode_key(const char *mode)
{
GError* err = NULL;
assert(gconfclient != NULL);
if (!gconf_client_set_string(gconfclient,
"/system/osso/af/usb-mode",
mode, &err) && err != NULL) {
ULOG_ERR_F("gconf_client_set_string failed: %s",
err->message);
g_error_free(err);
}
}
static void update_usb_device_name_key()
{
const char *s;
GError* err = NULL;
assert(gconfclient != NULL);
if (usb_device_name != NULL) {
s = usb_device_name;
} else if (default_usb_device_name != NULL) {
s = default_usb_device_name;
} else {
ULOG_DEBUG_F("no USB name available!");
return;
}
if (!gconf_client_set_string(gconfclient,
"/system/osso/af/usb-device-name",
s, &err) && err != NULL) {
ULOG_ERR_F("gconf_client_set_string failed: %s",
err->message);
g_error_free(err);
}
}
static void setup_usb_unmount_pending()
{
if (usb_pending_timer_id) {
ULOG_WARN_F("timer was already set");
} else {
usb_pending_timer_id =
g_timeout_add(MMC_USE_RECHECK_TIMEOUT,
usb_unmount_recheck, NULL);
/* try ten times */
usb_unmount_timeout = 10;
}
}
static void dismantle_usb_unmount_pending()
{
if (usb_pending_timer_id) {
if (!g_source_remove(usb_pending_timer_id)) {
ULOG_WARN_F("timer did not exist");
}
if (usb_dialog != -1) {
close_closeable_dialog(usb_dialog);
}
usb_pending_timer_id = 0;
usb_unmount_timeout = 0;
}
}
static gboolean usb_mount_check(gpointer data)
{
ULOG_DEBUG_F("entered");
#if 0
/* launch FM with what ever we have mounted */
if (desktop_started && !launch_fm()) {
/* no USB volumes mounted */
display_system_note(dgettext(USB_DOMAIN,
"stab_me_usb_no_file_system_available"));
}
#endif
usb_mounting_timer_id = 0;
return FALSE;
}
/* this code is necessary for the case where there are no volumes
* on the memory card */
static gboolean mmc_mount_check(gpointer data)
{
mmc_info_t *mmc = data;
volume_list_t *l;
int found = 0;
ULOG_DEBUG_F("entered, %s", mmc->name);
for (l = &mmc->volumes; l != NULL; l = l->next) {
if (l->udi != NULL) {
found = 1;
break;
}
}
if (!found) {
/* no volumes found, treat as unformatted */
set_mmc_corrupted_flag(TRUE, mmc);
ULOG_DEBUG_F("set %s", mmc->corrupted_key);
update_mmc_label(mmc, mmc->udi); /* clear old label */
if (desktop_started) {
display_dialog(MSG_MEMORY_CARD_IS_CORRUPTED);
}
} else {
ULOG_DEBUG_F("volumes found, doing nothing");
}
mmc->mount_timer_id = 0;
return FALSE;
}
static gboolean set_desktop_started(gpointer data)
{
ULOG_DEBUG_F("entered");
desktop_started = TRUE;
if (!mmc_initialised) {
/* initialise GConf keys and possibly mount or USB-share */
if (int_mmc_enabled) {
handle_event(E_INIT_CARD, &int_mmc, NULL);
}
handle_event(E_INIT_CARD, &ext_mmc, NULL);
mmc_initialised = TRUE;
}
#if 0
if (delayed_auto_install_check) {
possibly_start_am();
delayed_auto_install_check = FALSE;
}
#endif
return FALSE;
}
static void dismantle_usb_mount_timeout()
{
if (usb_mounting_timer_id) {
if (!g_source_remove(usb_mounting_timer_id)) {
ULOG_WARN_F("timer did not exist");
}
usb_mounting_timer_id = 0;
ULOG_DEBUG_F("dismantled USB mounting timeout");
}
}
static void setup_usb_mount_timeout(int seconds)
{
if (usb_mounting_timer_id) {
ULOG_DEBUG_F("resetting the timer");
g_source_remove(usb_mounting_timer_id);
}
usb_mounting_timer_id = g_timeout_add(seconds * 1000,
usb_mount_check, NULL);
}
static void dismantle_mmc_mount_timeout(mmc_info_t *mmc)
{
ULOG_DEBUG_F("entered, %s", mmc->name);
if (mmc->mount_timer_id) {
g_source_remove(mmc->mount_timer_id);
mmc->mount_timer_id = 0;
ULOG_DEBUG_F("dismantled mount timeout for %s", mmc->name);
}
}
static void setup_mmc_mount_timeout(mmc_info_t *mmc, int seconds)
{
ULOG_DEBUG_F("entered, %s", mmc->name);
if (mmc->mount_timer_id) {
ULOG_DEBUG_F("resetting timer for %s", mmc->name);
g_source_remove(mmc->mount_timer_id);
}
mmc->mount_timer_id = g_timeout_add(seconds * 1000,
mmc_mount_check, mmc);
}
static gboolean usb_unmount_recheck(gpointer data)
{
assert(usb_pending_timer_id != 0);
if (!unmount_usb_volumes()) {
/* re-check later */
ULOG_DEBUG_F("Some USB volumes are still in use");
if (--usb_unmount_timeout == 0) {
char msg[100];
ULOG_DEBUG_F("time out, giving up");
dismantle_usb_unmount_pending();
snprintf(msg, 100,
dgettext(USB_DOMAIN,
"stab_me_usb_cannot_eject"),
usb_device_name);
open_closeable_dialog(OSSO_GN_NOTICE, msg,
dgettext(USB_DOMAIN,
"stab_me_usb_cannot_eject_ok"));
return FALSE;
} else {
return TRUE;
}
} else {
ULOG_DEBUG_F("All USB volumes unmounted (S_EJECTED)");
dismantle_usb_unmount_pending();
set_usb_mode_key("idle"); /* hide the USB plugin */
usb_state = S_EJECTED;
return FALSE;
}
}
static mmc_info_t *mmc_from_dev_name(const char *dev)
{
if (dev == NULL) return NULL;
if (ext_mmc.whole_device != NULL
&& strncmp(ext_mmc.whole_device, dev,
strlen(ext_mmc.whole_device)) == 0) {
return &ext_mmc;
} else if (int_mmc.whole_device != NULL
&& strncmp(int_mmc.whole_device, dev,
strlen(int_mmc.whole_device)) == 0) {
return &int_mmc;
}
return NULL;
}
static DBusHandlerResult rename_handler(DBusConnection *c,
DBusMessage *m, void *data)
{
mmc_info_t *mmc;
volume_list_t *l;
DBusMessageIter iter;
char* dev = NULL, *label = NULL, *udi = NULL;
ULOG_DEBUG_F("entered");
the_connection = c;
the_message = m;
if (!dbus_message_iter_init(m, &iter)) {
ULOG_ERR_F("no device name argument");
send_error("no_argument");
goto rename_exit;
}
dbus_message_iter_get_basic(&iter, &dev);
if (dev == NULL) {
ULOG_ERR_F("message did not have device name");
send_error("no_device_name");
goto rename_exit;
}
if (!dbus_message_iter_next(&iter)) {
ULOG_ERR_F("message did not have second argument");
send_error("no_second_argument");
goto rename_exit;
}
dbus_message_iter_get_basic(&iter, &label);
if (label == NULL) {
ULOG_ERR_F("message did not have label");
send_error("no_label");
goto rename_exit;
}
mmc = mmc_from_dev_name(dev);
if (mmc == NULL) {
ULOG_ERR_F("bad device name '%s'", dev);
send_error("bad_device_name");
goto rename_exit;
}
for (l = &mmc->volumes; l != NULL; l = l->next) {
if (l->dev_name != NULL && strcmp(l->dev_name, dev) == 0) {
udi = l->udi;
break;
}
}
if (!l || !udi) {
ULOG_ERR_F("bad device name '%s'", dev);
send_error("bad_device_name");
goto rename_exit;
}
send_reply();
if (label[0] == '\0') {
/* empty label */
l->desired_label[0] = '\0';
} else {
strncpy(l->desired_label, label, 32);
l->desired_label[31] = '\0';
}
ULOG_DEBUG_F("got label: '%s'", l->desired_label);
/* validity of the label is checked later */
handle_event(E_RENAME, mmc, udi);
rename_exit:
/* invalidate */
the_connection = NULL;
the_message = NULL;
return DBUS_HANDLER_RESULT_HANDLED;
}
static DBusHandlerResult format_handler(DBusConnection *c,
DBusMessage *m, void *data)
{
mmc_info_t *mmc;
volume_list_t *l;
DBusMessageIter iter;
char* dev = NULL, *label = NULL, *udi = NULL;
ULOG_DEBUG_F("entered");
the_connection = c;
the_message = m;
if (!dbus_message_iter_init(m, &iter)) {
ULOG_ERR_F("no device name argument");
send_error("no_argument");
goto away;
}
dbus_message_iter_get_basic(&iter, &dev);
if (dev == NULL) {
ULOG_ERR_F("message did not have device name");
send_error("no_device_name");
goto away;
}
if (!dbus_message_iter_next(&iter)) {
ULOG_ERR_F("message did not have second argument");
send_error("no_second_argument");
goto away;
}
dbus_message_iter_get_basic(&iter, &label);
if (label == NULL) {
ULOG_ERR_F("message did not have label");
send_error("no_label");
goto away;
}
mmc = mmc_from_dev_name(dev);
if (mmc == NULL) {
ULOG_ERR_F("bad device name '%s'", dev);
send_error("bad_device_name");
goto away;
}
for (l = &mmc->volumes; l != NULL; l = l->next) {
if (l->dev_name != NULL && strcmp(l->dev_name, dev) == 0) {
udi = l->udi;
break;
}
}
if (!l || !udi) {
ULOG_ERR_F("bad device name '%s'", dev);
send_error("bad_device_name");
goto away;
}
send_reply();
if (label[0] == '\0') {
/* empty label */
l->desired_label[0] = '\0';
} else {
strncpy(l->desired_label, label, 32);
l->desired_label[31] = '\0';
}
ULOG_DEBUG_F("got label: '%s'", l->desired_label);
/* validity of the label is checked later */
handle_event(E_FORMAT, mmc, udi);
away:
/* invalidate */
the_connection = NULL;
the_message = NULL;
return DBUS_HANDLER_RESULT_HANDLED;
}
static DBusHandlerResult enable_mmc_swap_handler(DBusConnection *c,
DBusMessage *m,
void *data)
{
mmc_info_t *mmc = data;
ULOG_DEBUG_F("entered");
the_connection = c;
the_message = m;
handle_event(E_ENABLE_SWAP, mmc, NULL);
/* invalidate */
the_connection = NULL;
the_message = NULL;
return DBUS_HANDLER_RESULT_HANDLED;
}
static DBusHandlerResult disable_mmc_swap_handler(DBusConnection *c,
DBusMessage *m,
void *data)
{
mmc_info_t *mmc = data;
DBusMessageIter iter;
ULOG_DEBUG_F("entered");
the_connection = c;
the_message = m;
if (!dbus_message_iter_init(m, &iter)) {
ULOG_ERR_F("message does not have argument");
send_error("required argument missing");
} else {
dbus_bool_t b = FALSE;
if (dbus_message_iter_get_arg_type(&iter) !=
DBUS_TYPE_BOOLEAN) {
ULOG_ERR_F("argument is not boolean");
send_error("argument is not boolean");
} else {
dbus_message_iter_get_basic(&iter, &b);
mmc->swap_off_with_close_apps = b;
handle_event(E_DISABLE_SWAP, mmc, NULL);
}
}
/* invalidate */
the_connection = NULL;
the_message = NULL;
return DBUS_HANDLER_RESULT_HANDLED;
}
static DBusHandlerResult card_check_handler(DBusConnection *c,
DBusMessage *m,
void *data)
{
DBusMessageIter iter;
char *s = NULL;
mmc_info_t *mmc;
ULOG_DEBUG_F("entered");
the_connection = c;
the_message = m;
if (!dbus_message_iter_init(m, &iter)) {
ULOG_ERR_F("no device name argument");
send_error("no_argument");
goto away;
}
dbus_message_iter_get_basic(&iter, &s);
mmc = mmc_from_dev_name(s);
if (mmc == NULL) {
ULOG_ERR_F("bad device name '%s'", s);
send_error("bad_argument");
} else {
send_reply();
handle_event(E_CHECK, mmc, NULL);
}
away:
/* invalidate */
the_connection = NULL;
the_message = NULL;
return DBUS_HANDLER_RESULT_HANDLED;
}
#if 0
static DBusHandlerResult card_repair_handler(DBusConnection *c,
DBusMessage *m,
void *data)
{
DBusMessageIter iter;
char *s = NULL;
mmc_info_t *mmc;
ULOG_DEBUG_F("entered");
the_connection = c;
the_message = m;
if (!dbus_message_iter_init(m, &iter)) {
ULOG_ERR_F("no device name argument");
send_error("no_argument");
goto away;
}
dbus_message_iter_get_basic(&iter, &s);
mmc = mmc_from_dev_name(s);
if (mmc == NULL) {
ULOG_ERR_F("bad device name '%s'", s);
send_error("bad_argument");
} else {
send_reply();
handle_event(E_REPAIR, mmc, NULL);
}
away:
/* invalidate */
the_connection = NULL;
the_message = NULL;
return DBUS_HANDLER_RESULT_HANDLED;
}
#endif
/* This function is for testing only. Allows emulating the USB cable
* attaching and detaching. */
static DBusHandlerResult test_toggle_usb_cable(DBusConnection *c,
DBusMessage *m,
void *data)
{
gboolean value = (gboolean)data;
ULOG_DEBUG_F("entered");
the_connection = c;
the_message = m;
if (value) {
handle_usb_event(E_ENTER_HOST_MODE);
} else {
handle_usb_event(E_CABLE_DETACHED);
}
/* invalidate */
the_connection = NULL;
the_message = NULL;
return DBUS_HANDLER_RESULT_HANDLED;
}
static DBusHandlerResult eject_handler(DBusConnection *c,
DBusMessage *m,
void *data)
{
ULOG_DEBUG_F("entered");
the_connection = c;
the_message = m;
handle_usb_event(E_EJECT);
/* invalidate */
the_connection = NULL;
the_message = NULL;
return DBUS_HANDLER_RESULT_HANDLED;
}
static DBusHandlerResult cancel_eject_handler(DBusConnection *c,
DBusMessage *m,
void *data)
{
ULOG_DEBUG_F("entered");
the_connection = c;
the_message = m;
handle_usb_event(E_EJECT_CANCELLED);
/* invalidate */
the_connection = NULL;
the_message = NULL;
return DBUS_HANDLER_RESULT_HANDLED;
}
static DBusHandlerResult enable_pcsuite_handler(DBusConnection *c,
DBusMessage *m,
void *data)
{
ULOG_DEBUG_F("entered");
the_connection = c;
the_message = m;
handle_usb_event(E_ENTER_PCSUITE_MODE);
send_reply();
/* invalidate */
the_connection = NULL;
the_message = NULL;
return DBUS_HANDLER_RESULT_HANDLED;
}
static DBusHandlerResult enable_charging_handler(DBusConnection *c,
DBusMessage *m,
void *data)
{
ULOG_DEBUG_F("entered");
the_connection = c;
the_message = m;
handle_usb_event(E_ENTER_CHARGING_MODE);
send_reply();
/* invalidate */
the_connection = NULL;
the_message = NULL;
return DBUS_HANDLER_RESULT_HANDLED;
}
static DBusHandlerResult enable_mass_storage_handler(DBusConnection *c,
DBusMessage *m,
void *data)
{
ULOG_DEBUG_F("entered");
the_connection = c;
the_message = m;
handle_usb_event(E_ENTER_MASS_STORAGE_MODE);
send_reply();
/* invalidate */
the_connection = NULL;
the_message = NULL;
return DBUS_HANDLER_RESULT_HANDLED;
}
#if 0
int check_install_file(const mmc_info_t *mmc)
{
char buf[100];
int started = 0;
if (mmc->mount_point == NULL || mmc->mount_point[0] == '\0') {
return 0;
}
snprintf(buf, 100, "%s/%s", mmc->mount_point, ".auto.install");
if (g_file_test(buf, G_FILE_TEST_EXISTS)) {
ULOG_DEBUG_F(".auto.install file found");
if (hildon_mime_open_file(ses_conn, buf) != 1) {
ULOG_ERR_F("hildon_mime_open_file failed");
} else {
started = 1;
}
}
return started;
}
#endif
static void possibly_start_am(void)
{
/*
if (!check_install_file(&ext_mmc) && int_mmc_enabled) {
check_install_file(&int_mmc);
}
*/
}
/* Handler for checking for the .auto.install file on demand */
static DBusHandlerResult check_auto_install(DBusConnection *c,
DBusMessage *m,
void *data)
{
ULOG_DEBUG_F("entered");
the_connection = c;
the_message = m;
if (!desktop_started || !mmc_initialised) {
ULOG_DEBUG_F("desktop is not yet running or memory "
"cards are not ready");
delayed_auto_install_check = TRUE;
} else {
possibly_start_am();
}
send_reply();
the_connection = NULL;
the_message = NULL;
return DBUS_HANDLER_RESULT_HANDLED;
}
#if 0
static void prepare_for_shutdown()
{
if (usb_state == S_PERIPHERAL) {
unshare_usb_shared_card(&ext_mmc);
if (int_mmc_enabled) {
unshare_usb_shared_card(&int_mmc);
}
}
/* some cards could be still mounted if they were in use
* at the time the cable was connected */
possibly_turn_swap_off_simple(&ext_mmc);
unmount_volumes(&ext_mmc.volumes);
if (int_mmc_enabled) {
possibly_turn_swap_off_simple(&int_mmc);
unmount_volumes(&int_mmc.volumes);
}
unmount_usb_volumes();
}
#endif
static DBusHandlerResult
sig_handler(DBusConnection *c, DBusMessage *m, void *data)
{
gboolean handled = FALSE;
/*
ULOG_DEBUG_L("i|m|p: %s|%s|%s",
dbus_message_get_interface(m),
dbus_message_get_member(m),
dbus_message_get_path(m));
*/
the_connection = c;
the_message = m;
if (dbus_message_is_signal(m, DBUS_PATH_LOCAL, "Disconnected")) {
ULOG_INFO_L("D-Bus system bus disconnected, "
"unmounting and exiting");
g_main_loop_quit(mainloop);
handled = TRUE;
} else if (dbus_message_is_signal(m, MCE_SIGNAL_IF,
MCE_DEVICELOCK_SIG)) {
DBusMessageIter iter;
char* s = NULL;
dbus_message_iter_init(m, &iter);
dbus_message_iter_get_basic(&iter, &s);
if (s == NULL) {
ULOG_ERR_F("device lock signal did "
"not have string argument");
} else {
if (strncmp(s, MCE_LOCKED_STR,
strlen(MCE_LOCKED_STR)) == 0) {
ULOG_DEBUG_F("device locked signal");
device_locked = TRUE;
} else {
ULOG_DEBUG_F("device unlocked signal");
device_locked = FALSE;
#if 0 /* TODO: if dialog is still open, we don't need to do anything;
otherwise, we should use the user's decision (saved) */
usb_state_t state = get_usb_state();
if (state == S_PERIPHERAL) {
/* possibly USB-share cards */
handle_usb_event(E_ENTER_PERIPHERAL_MODE);
}
#endif
}
}
handled = TRUE;
} else if (dbus_message_is_signal(m, MCE_SIGNAL_IF,
MCE_SHUTDOWN_SIG)) {
ULOG_INFO_L("Shutdown signal from MCE, unmounting and exiting");
g_main_loop_quit(mainloop);
handled = TRUE;
} else if (!desktop_started &&
dbus_message_is_signal(m, DESKTOP_IF, "ready")) {
ULOG_DEBUG_F("hildon-desktop registered to system bus");
g_timeout_add(1000, set_desktop_started, NULL);
handled = TRUE;
}
/* invalidate */
the_connection = NULL;
the_message = NULL;
if (handled) {
return DBUS_HANDLER_RESULT_HANDLED;
} else {
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
}
static void notification_closed(unsigned int id)
{
if (ext_mmc.dialog_id == id) {
ext_mmc.dialog_id = -1;
} else if (ext_mmc.swap_dialog_id == id) {
ext_mmc.swap_dialog_id = -1;
} else if (int_mmc_enabled && int_mmc.dialog_id == id) {
int_mmc.dialog_id = -1;
} else if (int_mmc_enabled && int_mmc.swap_dialog_id == id) {
int_mmc.swap_dialog_id = -1;
} else if (usb_dialog == id) {
usb_dialog = -1;
} else {
ULOG_DEBUG_F("unknown dialog id: %u", id);
}
}
static void action_invoked(unsigned int id, const char *act)
{
if (ext_mmc.dialog_id == id) {
ULOG_DEBUG_F("%s dialog action: '%s'", ext_mmc.name, act);
} else if (ext_mmc.swap_dialog_id == id) {
ULOG_DEBUG_F("%s swap dialog action: '%s'",
ext_mmc.name, act);
ext_mmc.swap_dialog_response = strdup(act);
} else if (int_mmc_enabled && int_mmc.dialog_id == id) {
ULOG_DEBUG_F("%s dialog action: '%s'", int_mmc.name, act);
} else if (int_mmc_enabled && int_mmc.swap_dialog_id == id) {
ULOG_DEBUG_F("%s swap dialog action: '%s'",
int_mmc.name, act);
int_mmc.swap_dialog_response = strdup(act);
} else if (usb_dialog == id) {
ULOG_DEBUG_F("USB dialog action: '%s'", act);
handle_usb_event(E_EJECT_CANCELLED);
} else {
ULOG_DEBUG_F("unknown dialog id: %u", id);
}
}
static DBusHandlerResult
session_sig_handler(DBusConnection *c, DBusMessage *m, void *data)
{
gboolean handled = FALSE;
DBusMessageIter iter;
unsigned int i = 0;
char *s = NULL;
/*
ULOG_DEBUG_F("i|m|p: %s|%s|%s",
dbus_message_get_interface(m),
dbus_message_get_member(m),
dbus_message_get_path(m));
*/
the_connection = c;
the_message = m;
if (dbus_message_is_signal(m, FDO_INTERFACE,
"NotificationClosed")) {
if (dbus_message_iter_init(m, &iter)) {
dbus_message_iter_get_basic(&iter, &i);
ULOG_DEBUG_F("NotificationClosed for %u", i);
notification_closed(i);
}
handled = TRUE;
} else if (dbus_message_is_signal(m, FDO_INTERFACE,
"ActionInvoked")) {
if (dbus_message_iter_init(m, &iter)) {
dbus_message_iter_get_basic(&iter, &i);
if (dbus_message_iter_next(&iter)) {
dbus_message_iter_get_basic(&iter, &s);
ULOG_DEBUG_F("ActionInvoked for %u:"
" '%s'", i, s);
action_invoked(i, s);
}
}
handled = TRUE;
} else if (dbus_message_is_signal(m, DBUS_PATH_LOCAL,
"Disconnected")) {
ULOG_INFO_L("D-Bus session bus disconnected, exiting");
g_main_loop_quit(mainloop);
handled = TRUE;
}
/* invalidate */
the_connection = NULL;
the_message = NULL;
if (handled) {
return DBUS_HANDLER_RESULT_HANDLED;
} else {
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
}
/* This signal makes TN to close applications */
gboolean send_exit_signal(void)
{
DBusMessage* m = NULL;
dbus_bool_t ret = FALSE;
ULOG_DEBUG_F("entering");
assert(ses_conn != NULL);
m = dbus_message_new_signal(AK_BROADCAST_OP, AK_BROADCAST_IF,
AK_BROADCAST_EXIT);
if (m == NULL) {
ULOG_ERR_F("dbus_message_new_signal failed");
return FALSE;
}
ret = dbus_connection_send(ses_conn, m, NULL);
if (!ret) {
ULOG_ERR_F("dbus_connection_send failed");
dbus_message_unref(m);
return FALSE;
}
dbus_message_unref(m);
dbus_connection_flush(ses_conn); /* needed because the sleep hack */
return TRUE;
}
void send_error(const char* n)
{
DBusMessage* e = NULL;
assert(the_connection != NULL && the_message != NULL && n != NULL);
e = dbus_message_new_error(the_message,
"com.nokia.ke_recv.error", n);
if (e == NULL) {
ULOG_ERR_F("couldn't create error");
return;
}
if (!dbus_connection_send(the_connection, e, NULL)) {
ULOG_ERR_F("sending failed");
}
dbus_message_unref(e);
}
void send_reply(void)
{
DBusMessage* e = NULL;
assert(the_connection != NULL && the_message != NULL);
e = dbus_message_new_method_return(the_message);
if (e == NULL) {
ULOG_ERR_F("couldn't create reply");
return;
}
if (!dbus_connection_send(the_connection, e, NULL)) {
ULOG_ERR_F("sending failed");
}
dbus_message_unref(e);
}
void send_systembus_signal(const char *op, const char *iface,
const char *name)
{
DBusMessage* m;
assert(sys_conn != NULL);
m = dbus_message_new_signal(op, iface, name);
if (m == NULL) {
ULOG_ERR_F("couldn't create signal %s", name);
return;
}
if (!dbus_connection_send(sys_conn, m, NULL)) {
ULOG_ERR_F("sending signal %s failed", name);
}
dbus_message_unref(m);
}
gboolean get_device_lock(void)
{
DBusMessageIter iter;
DBusMessage* m = NULL, *r = NULL;
DBusError err;
dbus_bool_t ret = FALSE;
void* s = NULL;