From aaf38263d90ac3ba61edfc54bc439c087b0c1b4d Mon Sep 17 00:00:00 2001 From: "jk7744.park" Date: Sun, 1 Feb 2015 13:51:52 +0900 Subject: [PATCH 1/1] tizen 2.3 release --- CMakeLists.txt | 173 +-- AUTHORS => CREDITS | 8 + NOTICE | 4 + packaging/README.api | 71 +- packaging/crash-daemon.service | 11 - packaging/deviced.efl | 10 + packaging/deviced.manifest | 101 +- packaging/deviced.rule | 11 - packaging/deviced.service | 2 +- packaging/deviced.spec | 143 +-- packaging/liblogd-db.manifest | 11 - packaging/liblogd.manifest | 11 - src/apps/apps.c | 5 + src/apps/apps.h | 6 +- src/apps/cool-down.c | 83 ++ src/apps/lowbat.c | 74 +- src/apps/lowmem.c | 2 +- src/auto-test/CMakeLists.txt | 12 +- src/auto-test/activation/CMakeLists.txt | 2 + src/auto-test/activation/dbus/CMakeLists.txt | 7 + .../org.tizen.system.deviced-auto-test.service | 5 + src/auto-test/activation/systemd/CMakeLists.txt | 11 + .../activation/systemd/deviced-auto-test.service | 10 + src/auto-test/archive.c | 216 ++++ src/auto-test/board-info.c | 56 +- src/auto-test/boot.c | 19 +- src/auto-test/cool-down.c | 138 +++ src/auto-test/cpu-info.c | 10 +- src/auto-test/cradle.c | 35 +- src/auto-test/earjack.c | 31 +- src/auto-test/hdmi.c | 61 +- src/auto-test/keyboard.c | 19 +- src/auto-test/power-supply.c | 121 ++- src/auto-test/result.c | 45 + src/auto-test/storage.c | 21 +- src/auto-test/test.h | 3 +- src/auto-test/time.c | 11 +- src/auto-test/tvout.c | 19 +- src/auto-test/udev.c | 22 +- src/auto-test/usb.c | 19 +- src/battery/battery.c | 170 --- src/battery/config.h | 11 + src/battery/lowbat-handler.c | 322 +++--- src/board/board-info.c | 153 ++- src/control/control.c | 16 +- src/cool-down/cool-down-micro.c | 436 ++++++++ src/cool-down/cool-down.c | 417 ++++++++ src/core/buxton-helper.c | 257 +++++ src/core/buxton-helper.h | 75 ++ src/core/common.c | 11 + src/core/common.h | 35 + src/core/core.c | 180 ---- src/core/device-change-handler.c | 480 +++++---- src/core/device-handler.h | 3 +- src/core/device-notifier.c | 60 ++ src/core/device-notifier.h | 4 +- src/core/device-plugin.c | 66 -- src/core/devices.c | 13 +- src/core/devices.h | 53 +- src/core/edbus-handler.c | 98 +- src/core/execute.c | 8 + src/core/list.h | 31 + src/core/{device-plugin.h => log.c} | 27 +- src/core/log.h | 1 - src/core/main.c | 64 +- src/core/noti.c | 86 -- src/core/power-supply.c | 312 +++--- src/core/power-supply.h | 10 +- src/core/predefine.c | 273 ----- src/core/queue.c | 283 ----- src/core/queue.h | 67 -- src/core/sig-handler.c | 1 - src/core/sysnoti.c | 342 ------ src/cpu/cpu-handler.c | 83 +- src/devicectl/CMakeLists.txt | 1 + src/devicectl/devicectl.c | 49 +- src/devicectl/usb.c | 284 +++++ src/devicectl/usb.h | 26 + src/deviced/dd-deviced.h | 17 +- src/deviced/dd-haptic.h | 2 +- src/deviced/dd-led.h | 4 +- src/deviced/dd-mmc.h | 18 +- src/deviced/haptic-module.h | 7 + src/display/alpm.c | 179 +++- src/display/auto-brightness.c | 227 ++-- src/display/core.c | 528 +++++++--- src/display/core.h | 2 + src/display/device-interface.c | 150 ++- src/display/device-interface.h | 15 +- src/display/display-actor.c | 102 ++ src/display/display-actor.h | 52 + src/display/display-dbus.c | 210 +++- ...isplay-exynos.conf => display-emul-mobile.conf} | 7 +- ...isplay-emul.conf => display-emul-wearable.conf} | 0 .../{display-msm.conf => display-mobile.conf} | 5 +- src/display/display-ops.c | 2 +- src/display/display-ops.h | 2 +- src/display/display-wearable.conf | 64 ++ src/display/enhance.c | 16 +- src/display/hbm.c | 62 ++ src/display/hbm.h | 47 + src/display/key-filter-micro.c | 31 +- src/display/key-filter.c | 220 ++-- src/display/poll.c | 13 +- src/display/poll.h | 3 + src/display/setting.c | 29 +- src/display/setting.h | 2 - src/display/smartstay.c | 2 +- src/display/weaks.h | 7 +- src/earjack/earjack.c | 141 +++ src/fsck-msdos/CMakeLists.txt | 45 + src/fsck-msdos/LICENSE | 0 src/fsck-msdos/boot.c | 298 ++++++ src/fsck-msdos/check.c | 222 ++++ src/fsck-msdos/dir.c | 1100 ++++++++++++++++++++ src/fsck-msdos/dosfs.h | 144 +++ src/fsck-msdos/ext.h | 150 +++ src/fsck-msdos/fat.c | 735 +++++++++++++ src/fsck-msdos/fsutil.h | 7 + src/fsck-msdos/main.c | 154 +++ src/gpio/buzzer.c | 97 ++ src/gpio/gpio.c | 124 +++ src/gpio/gpio.h | 63 ++ src/gpio/hall.c | 97 ++ src/gpio/sim.c | 97 ++ src/hall/hall-handler.c | 71 +- src/hall/hall-handler.h | 2 - src/haptic/HW_touch_30ms_sharp.ivt | Bin 38 -> 0 bytes src/haptic/README.standard | 13 + src/haptic/external.c | 1 + src/haptic/haptic-micro.conf | 15 + src/haptic/haptic-mobile.conf | 24 + src/haptic/haptic.c | 232 ++++- src/haptic/haptic.h | 6 + src/haptic/standard.c | 339 ++++-- src/hdmi-cec/cec.c | 414 ++++++++ src/hdmi-cec/cec.h | 28 + src/hdmi-cec/libcec.c | 738 +++++++++++++ src/hdmi-cec/libcec.h | 176 ++++ src/icd/icd-integrity.c | 134 +++ src/icd/icd-integrity.h | 25 + src/icd/icd.c | 49 + src/icd/sha2.c | 406 ++++++++ src/icd/sha2.h | 50 + src/led/conf.c | 223 ++++ src/led/{xml.h => conf.h} | 14 +- src/led/led.conf | 100 ++ src/led/rgb.c | 151 ++- src/led/xml.c | 253 ----- src/libdeviced/CMakeLists.txt | 4 +- src/libdeviced/dbus.c | 357 +++++++ src/libdeviced/deviced-noti.c | 44 +- src/libdeviced/deviced-util.c | 9 +- src/libdeviced/display.c | 9 +- src/libdeviced/led.c | 4 + src/libdeviced/mmc.c | 12 +- src/logd/CMakeLists.txt | 10 + src/logd/src/CMakeLists.txt | 29 + src/logd/src/battery/CMakeLists.txt | 35 + src/logd/src/battery/calibration.c | 222 ++++ src/logd/src/battery/power-monitor.cpp | 87 ++ src/logd/src/liblogd-db/CMakeLists.txt | 44 + src/logd/src/liblogd-db/db.c | 47 + src/logd/src/liblogd-db/db.h | 54 + src/logd/src/liblogd-db/devices.c | 391 +++++++ src/logd/src/liblogd-db/devices.h | 24 + src/logd/src/liblogd-db/events.c | 278 +++++ src/logd/src/liblogd-db/events.h | 27 + src/logd/src/liblogd-db/liblogd-db.pc.in | 8 + src/logd/src/liblogd-db/logd-db.h | 271 +++++ src/logd/src/liblogd-db/padvisor.c | 242 +++++ src/logd/src/liblogd-db/padvisor.h | 115 ++ src/logd/src/liblogd-db/proc-stat.c | 212 ++++ src/logd/src/liblogd-db/proc-stat.h | 30 + src/logd/src/liblogd-db/tests/CMakeLists.txt | 11 + src/logd/src/liblogd-db/tests/foreach-test.c | 115 ++ src/logd/src/liblogd-db/tests/padvisor-test.c | 46 + src/logd/src/liblogd/CMakeLists.txt | 39 + src/logd/src/liblogd/liblogd.pc.in | 8 + src/logd/src/liblogd/logd.c | 90 ++ src/logd/src/liblogd/logd.h | 119 +++ src/logd/src/liblogd/tests/CMakeLists.txt | 8 + src/logd/src/liblogd/tests/store-event-test.c | 21 + src/logd/src/shared/CMakeLists.txt | 21 + src/logd/src/shared/logd-taskstats.h | 82 ++ src/logd/src/shared/macro.h | 38 + src/logd/src/shared/netlink.c | 132 +++ src/logd/src/shared/netlink.h | 42 + src/logd/src/shared/proc-events.c | 60 ++ src/logd/src/shared/proc-events.h | 21 + src/logd/src/shared/socket-helper.c | 102 ++ src/logd/src/shared/socket-helper.h | 18 + src/logd/src/shared/task-stats.c | 124 +++ src/logd/src/shared/task-stats.h | 18 + src/logd_grabber/battery.c | 355 +++++++ src/logd_grabber/battery.h | 19 + src/logd_grabber/config.c | 204 ++++ src/logd_grabber/config.h | 30 + src/logd_grabber/data/logd-grabber-micro.conf.in | 12 + src/logd_grabber/data/logd-grabber.conf.in | 12 + src/logd_grabber/data/logd.sql | 39 + src/logd_grabber/display.c | 165 +++ src/logd_grabber/display.h | 13 + src/logd_grabber/event.c | 210 ++++ src/logd_grabber/event.h | 24 + src/logd_grabber/journal-reader.c | 106 ++ src/logd_grabber/journal-reader.h | 11 + src/logd_grabber/logd-grabber.c | 534 ++++++++++ src/logd_grabber/logd-grabber.h | 7 + src/logd_grabber/mmc.c | 60 ++ src/logd_grabber/mmc.h | 7 + src/logd_grabber/nlproc-stat.c | 839 +++++++++++++++ src/logd_grabber/nlproc-stat.h | 19 + src/logd_grabber/timer.c | 84 ++ src/logd_grabber/timer.h | 17 + src/mmc/exfat.c | 147 +++ src/mmc/ext4.c | 19 +- src/mmc/mmc-handler.c | 176 +++- src/mmc/mmc-handler.h | 4 +- src/mmc/vfat.c | 12 +- src/newfs-msdos/CMakeLists.txt | 33 + src/newfs-msdos/LICENSE | 0 src/newfs-msdos/newfs-msdos.c | 1075 +++++++++++++++++++ src/ode/noti.c | 192 ++++ src/{core/emulator.h => ode/noti.h} | 29 +- src/ode/ode.c | 529 ++++++++++ src/{core/core.h => ode/ode.h} | 12 +- src/pass/pass-core.c | 861 +++++++++++++++ src/pass/pass-core.h | 39 + src/pass/pass-gov-radiation.c | 210 ++++ src/pass/pass-gov-step.c | 139 +++ src/{core/sysnoti.h => pass/pass-gov.h} | 20 +- src/{core/data.h => pass/pass-hotplug.h} | 17 +- src/pass/pass-micro.conf | 245 +++++ src/pass/pass-plugin.c | 536 ++++++++++ src/pass/pass-plugin.h | 47 + src/pass/pass-table.h | 881 ++++++++++++++++ src/pass/pass-target.h | 31 + src/{core/noti.h => pass/pass-util.h} | 16 +- src/pass/pass.c | 228 ++++ src/pass/pass.conf | 4 + src/pass/pass.h | 239 +++++ src/pmqos/pmqos.c | 53 +- src/power/power-handler.c | 443 ++++---- src/power/power-handler.h | 18 +- src/power/systemd-power.c | 96 +- src/powersaver/powersaver-micro.c | 162 +++ src/powersaver/powersaver.c | 135 +-- src/powersaver/powersaver.h | 29 + src/proc/pmon-handler.c | 15 +- src/proc/proc-handler.c | 97 +- src/proc/proc-handler.h | 2 +- src/shared/dbus.c | 109 +- src/shared/dbus.h | 18 + src/sleep/sleep.c | 117 +++ src/sleep/sleep.h | 25 + src/{core/lowstorage.c => storage/storage.c} | 179 ++-- src/storage/storage.conf | 7 + src/ta/ta-handler.c | 1 - src/telephony/telephony.c | 74 +- src/testmode/testmode.c | 33 + src/ticker/ticker.h | 1 - src/tima/noti.c | 181 ++++ src/{core/predefine.h => tima/noti.h} | 18 +- src/tima/tima-lkm.c | 222 ++++ src/tima/tima-lkm.h | 25 + src/tima/tima-pkm.c | 388 +++++++ src/tima/tima-pkm.h | 25 + src/tima/tima.c | 52 + src/time/time-handler.c | 4 - src/touch/touch.c | 4 +- src/touch/touchkey.c | 80 ++ src/touch/touchscreen.c | 85 ++ src/usb/configurations/conf-supported.xml | 11 - src/usb/configurations/usb-configurations.xml | 328 ------ src/usb/usb-client-config.c | 267 +++++ src/usb/usb-client-configuration-micro.conf | 95 ++ src/usb/usb-client-configuration.conf | 81 ++ src/usb/usb-client-control.c | 18 +- src/usb/usb-client-dbus.c | 127 +++ src/usb/usb-client-event-sdk.c | 65 ++ src/usb/usb-client-mode-micro.c | 77 ++ src/usb/usb-client-mode.c | 74 ++ src/usb/usb-client-operation.conf | 41 + src/usb/usb-client-set.c | 219 +--- src/usb/usb-client-xml.c | 919 ---------------- src/usb/usb-client.c | 121 ++- src/usb/usb-client.h | 59 +- src/usb/usb-handler.c | 107 -- src/usb/usb-host-naming.c | 4 +- src/usb/usb-host-storage-exfat.c | 90 ++ src/usb/usb-host-storage-vfat.c | 4 +- src/usb/usb-host.c | 12 +- test/_export_env.sh | 8 - test/_export_target_env.sh | 7 - test/build.sh | 16 - test/clean.sh | 11 - test/config | 3 - test/execute.sh | 15 - test/push.sh | 11 - test/testcase/Makefile | 28 - test/testcase/tslist | 10 - test/testcase/utc_system_deviced_battery.c | 101 -- test/testcase/utc_system_deviced_control.c | 141 --- test/testcase/utc_system_deviced_deviced.c | 714 ------------- test/testcase/utc_system_deviced_deviced_managed.c | 422 -------- test/testcase/utc_system_deviced_display.c | 649 ------------ test/testcase/utc_system_deviced_haptic.c | 984 ----------------- test/testcase/utc_system_deviced_led.c | 248 ----- test/testcase/utc_system_deviced_mmc.c | 105 -- test/testcase/utc_system_deviced_storage.c | 131 --- test/tet_scen | 7 - test/tetbuild.cfg | 5 - test/tetclean.cfg | 5 - test/tetexec.cfg | 5 - 315 files changed, 27276 insertions(+), 9345 deletions(-) rename AUTHORS => CREDITS (51%) create mode 100755 NOTICE delete mode 100644 packaging/crash-daemon.service create mode 100644 packaging/deviced.efl delete mode 100644 packaging/deviced.rule delete mode 100644 packaging/liblogd-db.manifest delete mode 100644 packaging/liblogd.manifest create mode 100644 src/apps/cool-down.c create mode 100644 src/auto-test/activation/CMakeLists.txt create mode 100644 src/auto-test/activation/dbus/CMakeLists.txt create mode 100644 src/auto-test/activation/dbus/org.tizen.system.deviced-auto-test.service create mode 100644 src/auto-test/activation/systemd/CMakeLists.txt create mode 100644 src/auto-test/activation/systemd/deviced-auto-test.service create mode 100644 src/auto-test/archive.c create mode 100644 src/auto-test/cool-down.c create mode 100644 src/auto-test/result.c delete mode 100644 src/battery/battery.c create mode 100644 src/cool-down/cool-down-micro.c create mode 100644 src/cool-down/cool-down.c create mode 100644 src/core/buxton-helper.c create mode 100644 src/core/buxton-helper.h delete mode 100644 src/core/core.c delete mode 100644 src/core/device-plugin.c rename src/core/{device-plugin.h => log.c} (60%) delete mode 100644 src/core/noti.c delete mode 100755 src/core/predefine.c delete mode 100644 src/core/queue.c delete mode 100644 src/core/queue.h delete mode 100755 src/core/sysnoti.c create mode 100644 src/devicectl/usb.c create mode 100644 src/devicectl/usb.h create mode 100644 src/display/display-actor.c create mode 100644 src/display/display-actor.h rename src/display/{display-exynos.conf => display-emul-mobile.conf} (89%) rename src/display/{display-emul.conf => display-emul-wearable.conf} (100%) rename src/display/{display-msm.conf => display-mobile.conf} (92%) create mode 100644 src/display/display-wearable.conf create mode 100644 src/display/hbm.h create mode 100644 src/earjack/earjack.c create mode 100644 src/fsck-msdos/CMakeLists.txt create mode 100644 src/fsck-msdos/LICENSE create mode 100644 src/fsck-msdos/boot.c create mode 100644 src/fsck-msdos/check.c create mode 100644 src/fsck-msdos/dir.c create mode 100644 src/fsck-msdos/dosfs.h create mode 100644 src/fsck-msdos/ext.h create mode 100644 src/fsck-msdos/fat.c create mode 100644 src/fsck-msdos/fsutil.h create mode 100644 src/fsck-msdos/main.c create mode 100644 src/gpio/buzzer.c create mode 100644 src/gpio/gpio.c create mode 100644 src/gpio/gpio.h create mode 100644 src/gpio/hall.c create mode 100644 src/gpio/sim.c delete mode 100755 src/haptic/HW_touch_30ms_sharp.ivt create mode 100644 src/haptic/README.standard create mode 100644 src/haptic/haptic-micro.conf create mode 100644 src/haptic/haptic-mobile.conf create mode 100644 src/hdmi-cec/cec.c create mode 100644 src/hdmi-cec/cec.h create mode 100644 src/hdmi-cec/libcec.c create mode 100644 src/hdmi-cec/libcec.h create mode 100644 src/icd/icd-integrity.c create mode 100644 src/icd/icd-integrity.h create mode 100644 src/icd/icd.c create mode 100644 src/icd/sha2.c create mode 100644 src/icd/sha2.h create mode 100644 src/led/conf.c rename src/led/{xml.h => conf.h} (80%) create mode 100644 src/led/led.conf delete mode 100644 src/led/xml.c create mode 100644 src/libdeviced/dbus.c create mode 100644 src/logd/CMakeLists.txt create mode 100644 src/logd/src/CMakeLists.txt create mode 100644 src/logd/src/battery/CMakeLists.txt create mode 100644 src/logd/src/battery/calibration.c create mode 100644 src/logd/src/battery/power-monitor.cpp create mode 100644 src/logd/src/liblogd-db/CMakeLists.txt create mode 100644 src/logd/src/liblogd-db/db.c create mode 100644 src/logd/src/liblogd-db/db.h create mode 100644 src/logd/src/liblogd-db/devices.c create mode 100644 src/logd/src/liblogd-db/devices.h create mode 100644 src/logd/src/liblogd-db/events.c create mode 100644 src/logd/src/liblogd-db/events.h create mode 100644 src/logd/src/liblogd-db/liblogd-db.pc.in create mode 100644 src/logd/src/liblogd-db/logd-db.h create mode 100644 src/logd/src/liblogd-db/padvisor.c create mode 100644 src/logd/src/liblogd-db/padvisor.h create mode 100644 src/logd/src/liblogd-db/proc-stat.c create mode 100644 src/logd/src/liblogd-db/proc-stat.h create mode 100644 src/logd/src/liblogd-db/tests/CMakeLists.txt create mode 100644 src/logd/src/liblogd-db/tests/foreach-test.c create mode 100644 src/logd/src/liblogd-db/tests/padvisor-test.c create mode 100644 src/logd/src/liblogd/CMakeLists.txt create mode 100644 src/logd/src/liblogd/liblogd.pc.in create mode 100644 src/logd/src/liblogd/logd.c create mode 100644 src/logd/src/liblogd/logd.h create mode 100644 src/logd/src/liblogd/tests/CMakeLists.txt create mode 100644 src/logd/src/liblogd/tests/store-event-test.c create mode 100644 src/logd/src/shared/CMakeLists.txt create mode 100644 src/logd/src/shared/logd-taskstats.h create mode 100644 src/logd/src/shared/macro.h create mode 100644 src/logd/src/shared/netlink.c create mode 100644 src/logd/src/shared/netlink.h create mode 100644 src/logd/src/shared/proc-events.c create mode 100644 src/logd/src/shared/proc-events.h create mode 100644 src/logd/src/shared/socket-helper.c create mode 100644 src/logd/src/shared/socket-helper.h create mode 100644 src/logd/src/shared/task-stats.c create mode 100644 src/logd/src/shared/task-stats.h create mode 100644 src/logd_grabber/battery.c create mode 100644 src/logd_grabber/battery.h create mode 100644 src/logd_grabber/config.c create mode 100644 src/logd_grabber/config.h create mode 100644 src/logd_grabber/data/logd-grabber-micro.conf.in create mode 100644 src/logd_grabber/data/logd-grabber.conf.in create mode 100644 src/logd_grabber/data/logd.sql create mode 100644 src/logd_grabber/display.c create mode 100644 src/logd_grabber/display.h create mode 100644 src/logd_grabber/event.c create mode 100644 src/logd_grabber/event.h create mode 100644 src/logd_grabber/journal-reader.c create mode 100644 src/logd_grabber/journal-reader.h create mode 100644 src/logd_grabber/logd-grabber.c create mode 100644 src/logd_grabber/logd-grabber.h create mode 100644 src/logd_grabber/mmc.c create mode 100644 src/logd_grabber/mmc.h create mode 100644 src/logd_grabber/nlproc-stat.c create mode 100644 src/logd_grabber/nlproc-stat.h create mode 100644 src/logd_grabber/timer.c create mode 100644 src/logd_grabber/timer.h create mode 100644 src/mmc/exfat.c create mode 100644 src/newfs-msdos/CMakeLists.txt create mode 100644 src/newfs-msdos/LICENSE create mode 100644 src/newfs-msdos/newfs-msdos.c create mode 100644 src/ode/noti.c rename src/{core/emulator.h => ode/noti.h} (64%) create mode 100755 src/ode/ode.c rename src/{core/core.h => ode/ode.h} (81%) create mode 100644 src/pass/pass-core.c create mode 100644 src/pass/pass-core.h create mode 100644 src/pass/pass-gov-radiation.c create mode 100644 src/pass/pass-gov-step.c rename src/{core/sysnoti.h => pass/pass-gov.h} (71%) rename src/{core/data.h => pass/pass-hotplug.h} (77%) create mode 100644 src/pass/pass-micro.conf create mode 100644 src/pass/pass-plugin.c create mode 100644 src/pass/pass-plugin.h create mode 100644 src/pass/pass-table.h create mode 100644 src/pass/pass-target.h rename src/{core/noti.h => pass/pass-util.h} (76%) create mode 100644 src/pass/pass.c create mode 100644 src/pass/pass.conf create mode 100644 src/pass/pass.h create mode 100644 src/powersaver/powersaver-micro.c create mode 100644 src/powersaver/powersaver.h create mode 100644 src/sleep/sleep.c create mode 100644 src/sleep/sleep.h rename src/{core/lowstorage.c => storage/storage.c} (72%) create mode 100644 src/storage/storage.conf create mode 100644 src/tima/noti.c rename src/{core/predefine.h => tima/noti.h} (63%) create mode 100644 src/tima/tima-lkm.c create mode 100644 src/tima/tima-lkm.h create mode 100644 src/tima/tima-pkm.c create mode 100644 src/tima/tima-pkm.h create mode 100644 src/tima/tima.c create mode 100644 src/touch/touchkey.c create mode 100644 src/touch/touchscreen.c delete mode 100644 src/usb/configurations/conf-supported.xml delete mode 100644 src/usb/configurations/usb-configurations.xml create mode 100755 src/usb/usb-client-config.c create mode 100644 src/usb/usb-client-configuration-micro.conf create mode 100644 src/usb/usb-client-configuration.conf create mode 100755 src/usb/usb-client-event-sdk.c create mode 100755 src/usb/usb-client-mode-micro.c create mode 100755 src/usb/usb-client-mode.c create mode 100644 src/usb/usb-client-operation.conf delete mode 100755 src/usb/usb-client-xml.c delete mode 100755 src/usb/usb-handler.c create mode 100644 src/usb/usb-host-storage-exfat.c delete mode 100755 test/_export_env.sh delete mode 100755 test/_export_target_env.sh delete mode 100755 test/build.sh delete mode 100755 test/clean.sh delete mode 100644 test/config delete mode 100755 test/execute.sh delete mode 100755 test/push.sh delete mode 100644 test/testcase/Makefile delete mode 100644 test/testcase/tslist delete mode 100644 test/testcase/utc_system_deviced_battery.c delete mode 100644 test/testcase/utc_system_deviced_control.c delete mode 100644 test/testcase/utc_system_deviced_deviced.c delete mode 100644 test/testcase/utc_system_deviced_deviced_managed.c delete mode 100644 test/testcase/utc_system_deviced_display.c delete mode 100644 test/testcase/utc_system_deviced_haptic.c delete mode 100644 test/testcase/utc_system_deviced_led.c delete mode 100644 test/testcase/utc_system_deviced_mmc.c delete mode 100644 test/testcase/utc_system_deviced_storage.c delete mode 100644 test/tet_scen delete mode 100644 test/tetbuild.cfg delete mode 100644 test/tetclean.cfg delete mode 100644 test/tetexec.cfg diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ce4663..0589042 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,37 +76,57 @@ SET(EXEC_PREFIX "${PREFIX}/bin") SET(LIBDIR "${PREFIX}/lib") SET(INCLUDEDIR "${PREFIX}/include/${PROJECT_NAME}") SET(DATADIR "${PREFIX}/share/${PROJECT_NAME}") +SET(CONFDIR "/etc/${PROJECT_NAME}") SET(VERSION 0.1.0) SET(SRCS src/battery/config.c src/battery/lowbat-handler.c - src/battery/battery.c + src/core/buxton-helper.c src/core/device-notifier.c src/core/main.c - src/core/sysnoti.c src/core/launch.c - src/core/queue.c - src/core/core.c src/core/devices.c src/core/sig-handler.c + src/core/log.c src/core/device-change-handler.c - src/core/predefine.c src/core/common.c src/core/config-parser.c src/core/execute.c src/core/edbus-handler.c src/core/power-supply.c - src/core/lowstorage.c + src/earjack/earjack.c src/proc/cpu-info.c src/board/board-info.c src/proc/proc-handler.c + src/storage/storage.c src/ta/ta-handler.c src/time/time-handler.c src/ticker/ticker.c src/testmode/testmode.c ) +IF(USE_MICRO_DD) +SET(SRCS ${SRCS} + src/cool-down/cool-down-micro.c +) +ELSE() +SET(SRCS ${SRCS} + src/cool-down/cool-down.c +) +ENDIF() + +SET(SRCS ${SRCS} + src/hdmi-cec/libcec.c + src/hdmi-cec/cec.c +) +SET(SRCS ${SRCS} + src/gpio/gpio.c + src/gpio/buzzer.c + src/gpio/hall.c + src/gpio/sim.c +) + IF(USE_SYSTEMD_SHUTDOWN) SET(SRCS ${SRCS} src/power/systemd-power.c @@ -117,44 +137,34 @@ SET(SRCS ${SRCS} ) ENDIF() -IF(NOT USE_MICRO_DD) - IF(USE_EMULATOR) - ADD_DEFINITIONS("-DMOBILE_EMULATOR") - SET(SRCS ${SRCS} - src/core/noti.c - ) - ENDIF(USE_EMULATOR) -ENDIF(NOT USE_MICRO_DD) +#device sleep +SET(SRCS ${SRCS} + src/sleep/sleep.c +) SET(SRCS ${SRCS} src/apps/apps.c + src/apps/cool-down.c src/apps/lowbat.c src/apps/poweroff.c + src/apps/lowmem.c src/pmqos/pmqos.c src/pmqos/pmqos-plugin.c + src/telephony/telephony.c ) IF(NOT USE_MICRO_DD) SET(SRCS ${SRCS} src/battery/battery-time.c src/extcon/extcon.c - src/cpu/cpu-handler.c src/hall/hall-handler.c - src/proc/pmon-handler.c src/apps/launch.c - src/apps/lowmem.c src/apps/mmc.c src/apps/usb.c src/apps/usbotg.c src/apps/system.c ) -IF(NOT USE_SYSTEMD_SHUTDOWN) -SET(SRCS ${SRCS} - src/telephony/telephony.c -) -ENDIF() - SET(SRCS ${SRCS} src/mmc/mmc-handler.c src/mmc/uevent.c @@ -172,8 +182,14 @@ SET(SRCS ${SRCS} ENDIF(USE_EMULATOR) SET(SRCS ${SRCS} + src/mmc/exfat.c src/mmc/vfat.c ) + +SET(SRCS ${SRCS} + src/ode/ode.c + src/ode/noti.c +) ENDIF(NOT USE_MICRO_DD) # display(pm) @@ -186,6 +202,8 @@ SET(SRCS ${SRCS} src/display/poll.c src/display/setting.c src/display/display-ops.c + src/display/display-actor.c + src/display/auto-brightness.c ) IF(USE_MICRO_DD) @@ -198,7 +216,6 @@ SET(SRCS ${SRCS} src/display/brightness.c src/display/key-filter.c src/display/enhance.c - src/display/auto-brightness.c src/display/smartstay.c ) ENDIF(USE_MICRO_DD) @@ -208,18 +225,30 @@ SET(SRCS ${SRCS} src/led/torch.c src/led/pattern.c src/led/noti.c - src/led/xml.c ) +SET(SRCS ${SRCS} + src/pass/pass.c + src/pass/pass-core.c + src/pass/pass-gov-step.c + src/pass/pass-gov-radiation.c + src/pass/pass-plugin.c +) + +SET(SRCS ${SRCS} + src/touch/touchscreen.c) + IF(NOT USE_MICRO_DD) SET(SRCS ${SRCS} src/touch/touch.c + src/touch/touchkey.c src/touch/touch-controller.c src/touch/touch-plugin.c) SET(SRCS ${SRCS} src/led/rgb.c + src/led/conf.c ) ENDIF(NOT USE_MICRO_DD) @@ -229,19 +258,25 @@ SET(SRCS ${SRCS} SET(SRCS ${SRCS} src/haptic/haptic.c - src/haptic/standard.c src/haptic/external.c + src/haptic/standard.c src/haptic/emulator.c) # usb client SET(SRCS ${SRCS} src/usb/usb-common.c src/usb/usb-client.c - src/usb/usb-client-xml.c + src/usb/usb-client-event-sdk.c + src/usb/usb-client-config.c src/usb/usb-client-set.c src/usb/usb-client-control.c src/usb/usb-client-dbus.c ) +IF(USE_MICRO_DD) +SET(SRCS ${SRCS} src/usb/usb-client-mode-micro.c) +ELSE(USE_MICRO_DD) +SET(SRCS ${SRCS} src/usb/usb-client-mode.c) +ENDIF(USE_MICRO_DD) # usb host IF(NOT USE_MICRO_DD) @@ -251,6 +286,7 @@ SET(SRCS ${SRCS} src/usb/usb-host-dbus.c src/usb/usb-host-storage.c src/usb/usb-host-storage-vfat.c + src/usb/usb-host-storage-exfat.c src/usb/usb-host-hid.c src/usb/usb-host-camera.c src/usb/usb-host-printer.c @@ -259,51 +295,34 @@ SET(SRCS ${SRCS} ENDIF(NOT USE_MICRO_DD) # powersaver mode -IF(USE_MICRO_DD) SET(SRCS ${SRCS} src/powersaver/powersaver.c ) +IF(USE_MICRO_DD) +SET(SRCS ${SRCS} + src/powersaver/powersaver-micro.c +) ENDIF(USE_MICRO_DD) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src/deviced) -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/logd/src/shared) SET(PKG_MODULES + libbuxton ecore - ecore-file - ecore-x edbus eina vconf dlog device-node - libxml-2.0 capi-base-common -) - -IF(NOT USE_MICRO_DD) -SET(PKG_MODULES ${PKG_MODULES} - tapi - modem + journal + storage sensor + tapi ) -ENDIF() - -IF(USE_TRUSTZONE_QUALCOMM) -SET(PKG_MODULES ${PKG_MODULES} - tee-qsee -) -ENDIF() -IF(NOT USE_MICRO_DD) - IF(USE_EMULATOR) - SET(PKG_MODULES ${PKG_MODULES} - heynoti - ) - ENDIF(USE_EMULATOR) -ENDIF(NOT USE_MICRO_DD) INCLUDE(FindPkgConfig) pkg_check_modules(pkgs REQUIRED ${PKG_MODULES}) @@ -336,7 +355,7 @@ ENDIF() ADD_DEFINITIONS("-DDEBUG") ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} "-ldl" "-lm" "-ludev" "-ledbus" shared) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} "-ldl" "-lm" "-ludev" "-ledbus" "-lstorage" shared) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin) INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/deviced/ DESTINATION include/${PROJECT_NAME} @@ -347,40 +366,48 @@ INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/deviced/ DESTINATION include/$ CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION lib/pkgconfig) -IF(USE_ARM AND NOT USE_MICRO_DD) - INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/src/haptic/HW_touch_30ms_sharp.ivt DESTINATION ${DATADIR}) - INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/led/led.xml DESTINATION ${DATADIR}) -ENDIF(USE_ARM AND NOT USE_MICRO_DD) +IF(NOT USE_MICRO_DD) + INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/led/led.conf DESTINATION /etc/deviced) +ENDIF(NOT USE_MICRO_DD) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/scripts/dump_pm.sh DESTINATION /opt/etc/dump.d/module.d) -IF(USE_TRUSTZONE_QUALCOMM) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/display/display-msm.conf DESTINATION /etc/deviced RENAME display.conf) +IF(USE_EMULATOR AND USE_MICRO_DD) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/display/display-emul-wearable.conf DESTINATION /etc/deviced RENAME display.conf) ELSEIF(USE_EMULATOR) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/display/display-emul.conf DESTINATION /etc/deviced RENAME display.conf) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/display/display-emul-mobile.conf DESTINATION /etc/deviced RENAME display.conf) +ELSEIF(USE_MICRO_DD) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/display/display-wearable.conf DESTINATION /etc/deviced RENAME display.conf) ELSE() -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/display/display-exynos.conf DESTINATION /etc/deviced RENAME display.conf) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/display/display-mobile.conf DESTINATION /etc/deviced RENAME display.conf) ENDIF() INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/mmc/mmc.conf DESTINATION /etc/deviced RENAME mmc.conf) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/pmqos/pmqos.conf DESTINATION /etc/deviced RENAME pmqos.conf) -IF(USE_MICRO_DD) - IF(USE_EMULATOR) - INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/battery/battery-micro-emul.conf DESTINATION /etc/deviced RENAME battery.conf) - ELSE(USR_EMULATOR) - INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/battery/battery-micro.conf DESTINATION /etc/deviced RENAME battery.conf) - ENDIF(USE_EMULATOR) -ELSE(USE_MICRO_DD) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/battery/battery.conf DESTINATION /etc/deviced RENAME battery.conf) + +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/storage/storage.conf DESTINATION /etc/deviced RENAME storage.conf) + +IF(USE_MICRO_DD) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/pass/pass-micro.conf DESTINATION /etc/deviced RENAME pass.conf) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/haptic/haptic-micro.conf DESTINATION /etc/deviced RENAME haptic.conf) +ELSE() +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/pass/pass.conf DESTINATION /etc/deviced RENAME pass.conf) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/haptic/haptic-mobile.conf DESTINATION /etc/deviced RENAME haptic.conf) ENDIF(USE_MICRO_DD) INSTALL(PROGRAMS ${CMAKE_BINARY_DIR}/scripts/deviced-pre.sh DESTINATION bin) -INSTALL(FILES ${CMAKE_SOURCE_DIR}/packaging/${PROJECT_NAME}.rule DESTINATION /etc/smack/accesses2.d) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/usb/configurations/conf-supported.xml DESTINATION ${DATADIR}/usb-configurations) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/usb/configurations/usb-configurations.xml DESTINATION ${DATADIR}/usb-configurations) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/packaging/${PROJECT_NAME}.efl DESTINATION /etc/smack/accesses.d) +IF(USE_MICRO_DD) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/usb/usb-client-configuration-micro.conf DESTINATION ${CONFDIR} RENAME usb-client-configuration.conf) +ELSE(USE_MICRO_DD) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/usb/usb-client-configuration.conf DESTINATION ${CONFDIR}) +ENDIF(USE_MICRO_DD) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/usb/usb-client-operation.conf DESTINATION ${CONFDIR}) IF(NOT USE_MICRO_DD) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/scripts/movi_format.sh DESTINATION bin) INSTALL(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/scripts/mmc-smack-label DESTINATION bin) + INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/fsck-msdos/LICENSE DESTINATION share/license RENAME fsck_msdosfs) ENDIF(NOT USE_MICRO_DD) # USB (data-router) @@ -394,6 +421,10 @@ ENDIF() ADD_SUBDIRECTORY(src) ADD_SUBDIRECTORY(src/libdeviced) +IF(NOT USE_MICRO_DD) + ADD_SUBDIRECTORY(src/fsck-msdos) + ADD_SUBDIRECTORY(src/newfs-msdos) +ENDIF(NOT USE_MICRO_DD) ADD_SUBDIRECTORY(src/devicectl) ADD_SUBDIRECTORY(src/auto-test) diff --git a/AUTHORS b/CREDITS similarity index 51% rename from AUTHORS rename to CREDITS index 63a6fc5..07a78ec 100644 --- a/AUTHORS +++ b/CREDITS @@ -1,3 +1,10 @@ +Thanks to the follow people for contributing to deviced by reporting +bugs, providing fixes, providing information, providing resources or +porting to new systems: + +The names are sorted alphabetically by last name. +Names taken from sources and from version control system. + ChanWoo Choi Byung-Soo Kim Taeyoung Kim @@ -6,3 +13,4 @@ Kyungmin Park SeungHun Pi Juho Son Jiyoung Yun + diff --git a/NOTICE b/NOTICE new file mode 100755 index 0000000..dc3f273 --- /dev/null +++ b/NOTICE @@ -0,0 +1,4 @@ +Copyright (c) The Android Open Source Project +Copyright (c) Samsung Electronics Co., Ltd. All rights reserved. +Except as noted, this software is licensed under Apache License, Version 2. +Please, see the LICENSE.Apache-2.0 file for Apache License terms and conditions. diff --git a/packaging/README.api b/packaging/README.api index 1f8c8ad..6174ae7 100644 --- a/packaging/README.api +++ b/packaging/README.api @@ -5,6 +5,9 @@ DBus method_call smack authority * : all user can access the methods. +Battery + org.tizen.system.deviced.Battery.GetPercent * + org.tizen.system.deviced.Battery.GetPercentRaw * Display org.tizen.system.deviced.display.start root only org.tizen.system.deviced.display.stop root only @@ -23,10 +26,10 @@ Display org.tizen.system.deviced.display.setautobrightnessmin * org.tizen.system.deviced.display.setlcdtimeout * org.tizen.system.deviced.display.LockScreenBgOn * - org.tizen.system.deviced.display.GetDisplayCount * - org.tizen.system.deviced.display.GetMaxBrightness * - org.tizen.system.deviced.display.GetBrightness * - org.tizen.system.deviced.display.SetBrightness * + org.tizen.system.deviced.display.GetDisplayCount deviced::display + org.tizen.system.deviced.display.GetMaxBrightness deviced::display + org.tizen.system.deviced.display.GetBrightness deviced::display + org.tizen.system.deviced.display.SetBrightness deviced::display org.tizen.system.deviced.display.HoldBrightness deviced::display org.tizen.system.deviced.display.ReleaseBrightness * org.tizen.system.deviced.display.GetAclStatus * @@ -39,45 +42,46 @@ Display org.tizen.system.deviced.display.SetFrameRate * org.tizen.system.deviced.display.GetColorBlind * org.tizen.system.deviced.display.SetColorBlind * +Hall + org.tizen.system.deviced.hall.getstatus * Hapic - org.tizen.system.deviced.haptic.GetCount * - org.tizen.system.deviced.haptic.OpenDevice * - org.tizen.system.deviced.haptic.CloseDevice * - org.tizen.system.deviced.haptic.StopDevice * - org.tizen.system.deviced.haptic.VibrateMonotone * + org.tizen.system.deviced.haptic.GetCount deviced::haptic + org.tizen.system.deviced.haptic.OpenDevice deviced::haptic + org.tizen.system.deviced.haptic.CloseDevice deviced::haptic + org.tizen.system.deviced.haptic.StopDevice deviced::haptic + org.tizen.system.deviced.haptic.VibrateMonotone deviced::haptic org.tizen.system.deviced.haptic.VibrateBuffer * org.tizen.system.deviced.haptic.GetState * org.tizen.system.deviced.haptic.GetDuration * org.tizen.system.deviced.haptic.CreateEffect * org.tizen.system.deviced.haptic.SaveBinary * +Led + org.tizen.system.deviced.Led.playcustom deviced::led + org.tizen.system.deviced.Led.stopcustom deviced::led + org.tizen.system.deviced.Led.GetBrightness deviced::led + org.tizen.system.deviced.Led.GetMaxBrightness deviced::led + org.tizen.system.deviced.Led.SetBrightness deviced::led + org.tizen.system.deviced.Led.SetIrCommand deviced::led + org.tizen.system.deviced.Led.SetMode * + org.tizen.system.deviced.Led.PrintMode * +Lowmem +Mmc + org.tizen.system.deviced.Mmc.RequestMount * + org.tizen.system.deviced.Mmc.RequestUnmount * + org.tizen.system.deviced.Mmc.RequestFormat * +Ode Pass org.tizen.system.deviced.pass.start root only org.tizen.system.deviced.pass.stop root only org.tizen.system.deviced.pass.bypass root only -Hall - org.tizen.system.deviced.hall.getstatus * Power org.tizen.system.deviced.power.setresetkeydisable deviced::power org.tizen.system.deviced.power.entersleep root only org.tizen.system.deviced.power.leavesleep root only - org.tizen.system.deviced.power.reboot root only + org.tizen.system.deviced.power.reboot deviced::power org.tizen.system.deviced.power.reboot-recovery root only - org.tizen.system.deviced.power.pwroff-popup * + org.tizen.system.deviced.power.pwroff-popup deviced::power org.tizen.system.deviced.power.flightmode root only -Storage - org.tizen.system.deviced.storage.getstorage * -Ode -Lowmem -Led - org.tizen.system.deviced.Led.playcustom * - org.tizen.system.deviced.Led.stopcustom * - org.tizen.system.deviced.Led.GetBrightness * - org.tizen.system.deviced.Led.GetMaxBrightness * - org.tizen.system.deviced.Led.SetBrightness * - org.tizen.system.deviced.Led.SetIrCommand * - org.tizen.system.deviced.Led.SetMode * - org.tizen.system.deviced.Led.PrintMode * - Process org.tizen.system.deviced.Process.foregrd root only org.tizen.system.deviced.Process.backgrd root only @@ -85,7 +89,8 @@ Process org.tizen.system.deviced.Process.inactive * org.tizen.system.deviced.Process.oomadj_set root only org.tizen.system.deviced.Process.process_group_set root only - +Storage + org.tizen.system.deviced.storage.getstorage * SysNoti org.tizen.system.deviced.SysNoti.set_max_frequency root only org.tizen.system.deviced.SysNoti.set_min_frequency root only @@ -101,8 +106,8 @@ SysNoti org.tizen.system.deviced.SysNoti.udev root only org.tizen.system.deviced.SysNoti.factorymode root only org.tizen.system.deviced.SysNoti.control root only -Mmc - org.tizen.system.deviced.Mmc.RequestMount * - org.tizen.system.deviced.Mmc.RequestUnmount * - org.tizen.system.deviced.Mmc.RequestFormat * - +Usbhost + org.tizen.system.deviced.Usbhost.StorageInfoAll deviced::usbhost + org.tizen.system.deviced.Usbhost.StorageMount deviced::usbhost + org.tizen.system.deviced.Usbhost.StorageUnmount deviced::usbhost + org.tizen.system.deviced.Usbhost.StorageFormat deviced::usbhost diff --git a/packaging/crash-daemon.service b/packaging/crash-daemon.service deleted file mode 100644 index 27e39bb..0000000 --- a/packaging/crash-daemon.service +++ /dev/null @@ -1,11 +0,0 @@ -[Unit] -Description=Start the crash daemon service -After=dbus.socket - -[Service] -ExecStart=/usr/bin/crash-daemon -Restart=always -RestartSec=0 - -[Install] -WantedBy=multi-user.target diff --git a/packaging/deviced.efl b/packaging/deviced.efl new file mode 100644 index 0000000..0720b83 --- /dev/null +++ b/packaging/deviced.efl @@ -0,0 +1,10 @@ +deviced sys-assert::core rwxat- ------ +deviced system::media rwxat- ------ +deviced system::media::root rwxat- ------ +deviced system::vconf rwxat- ------ +deviced system::vconf_setting rw---- ------ +deviced com.samsung.setting::private r----- ------ +deviced system::vconf_system rw---- ------ +deviced testmode::vconf r----- ------ +deviced starter::vconf r----- ------ +pulseaudio deviced rw---- ------ diff --git a/packaging/deviced.manifest b/packaging/deviced.manifest index 97710e4..d708947 100644 --- a/packaging/deviced.manifest +++ b/packaging/deviced.manifest @@ -3,13 +3,24 @@ + + + + + + + + @@ -23,6 +34,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -30,11 +106,30 @@ + + + + + + + + + + + + + + + + + + + + + + - - - diff --git a/packaging/deviced.rule b/packaging/deviced.rule deleted file mode 100644 index bce8fd6..0000000 --- a/packaging/deviced.rule +++ /dev/null @@ -1,11 +0,0 @@ -# subject rule -deviced sys-assert::core rwxat -deviced system::media rwxat -deviced system::vconf rwxat -deviced system::vconf_setting rw -deviced com.samsung.setting::private r -deviced system::vconf_system rw -deviced testmode::vconf r -deviced starter::vconf r -# object rule -pulseaudio deviced rw diff --git a/packaging/deviced.service b/packaging/deviced.service index 9f0661a..ba9cad9 100644 --- a/packaging/deviced.service +++ b/packaging/deviced.service @@ -1,6 +1,6 @@ [Unit] Description=System device daemon -After=deviced-pre.service pulseaudio.service sound-init.service +After=deviced-pre.service immvibed.service Requires=deviced-pre.service [Service] diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 0739bbc..71f816c 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -13,30 +13,35 @@ Source5: devicectl-start@.service Source6: devicectl-stop@.service Source1001: deviced.manifest Source1002: libdeviced.manifest -Source1003: liblogd-db.manifest -Source1004: liblogd.manifest BuildRequires: cmake BuildRequires: libattr-devel BuildRequires: gettext-devel BuildRequires: pkgconfig(ecore) BuildRequires: pkgconfig(vconf) -%ifnarch %{arm} -BuildRequires: pkgconfig(heynoti) -%endif BuildRequires: pkgconfig(dlog) -BuildRequires: pkgconfig(usbutils) BuildRequires: pkgconfig(device-node) BuildRequires: pkgconfig(edbus) -BuildRequires: pkgconfig(libxml-2.0) BuildRequires: pkgconfig(capi-base-common) BuildRequires: systemd-devel BuildRequires: pkgconfig(systemd) BuildRequires: pkgconfig(sqlite3) +BuildRequires: pkgconfig(libbuxton) +BuildRequires: pkgconfig(storage) +BuildRequires: pkgconfig(dbus-glib-1) +BuildRequires: pkgconfig(journal) +BuildRequires: pkgconfig(libarchive) +BuildRequires: pkgconfig(sensor) +BuildRequires: pkgconfig(tapi) + Requires(preun): /usr/bin/systemctl Requires(post): sys-assert Requires(post): /usr/bin/systemctl Requires(post): /usr/bin/vconftool +Requires(post): pulseaudio +Requires(post): buxton +Requires(post): pkgconfig(journal) +Requires(post): pkgconfig(libarchive) Requires(postun): /usr/bin/systemctl %description @@ -65,56 +70,15 @@ Requires: libdeviced = %{version}-%{release} %description -n libdeviced-devel Deviced library for device control (devel) -%package -n logd -Summary: logd utils -Group: Framework/system - -%description -n logd -Utils for for logd - -%package -n liblogd -Summary: Activity logging API(Development) -Group: Development/Libraries - -%description -n liblogd -logd library. - -%package -n liblogd-devel -Summary: Activity logging (Development) -Summary: SLP power manager client (devel) -Group: Development/Libraries - -%description -n liblogd-devel -logd API library. - -%package -n liblogd-db -Summary: API to get activity data (Development) -Group: Development/Libraries - -%description -n liblogd-db -logd-db library. - -%package -n liblogd-db-devel -Summary: API to get activity data (Development) -Group: Development/Libraries - -%description -n liblogd-db-devel -logd-db API library. - %prep %setup -q +%if "%{?tizen_profile_name}" == "wearable" export CFLAGS+=" -DMICRO_DD" - -%if 0%{?sec_build_binary_debug_enable} -export CFLAGS+=" -DTIZEN_DEBUG_ENABLE" %endif -%if 0%{?tizen_build_binary_release_type_eng} +export CFLAGS+=" -DTIZEN_DEBUG_ENABLE" export CFLAGS+=" -DTIZEN_ENGINEER_MODE" %define ENGINEER_MODE 1 -%else -%define ENGINEER_MODE 0 -%endif %ifarch %{arm} %define ARCH arm @@ -126,8 +90,6 @@ cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DARCH=%{ARCH} %build cp %{SOURCE1001} . cp %{SOURCE1002} . -cp %{SOURCE1003} . -cp %{SOURCE1004} . make @@ -158,6 +120,36 @@ cp LICENSE.Apache-2.0 %{buildroot}/usr/share/license/%{name} cp LICENSE.Apache-2.0 %{buildroot}/usr/share/license/libdeviced %post +%if "%{?tizen_profile_name}" == "wearable" +%else +#memory type vconf key init +vconftool set -t int memory/sysman/mmc 0 -i -s system::vconf_system +vconftool set -t int memory/sysman/earjack_key 0 -i -s system::vconf_system +vconftool set -t int memory/sysman/cradle_status 0 -i -s system::vconf_system +vconftool set -t int memory/sysman/added_usb_storage 0 -i -s system::vconf_system +vconftool set -t int memory/sysman/removed_usb_storage 0 -i -s system::vconf_system +vconftool set -t int memory/sysman/earjack -1 -i -s system::vconf_system +vconftool set -t int memory/sysman/sliding_keyboard -1 -i -s system::vconf_system +vconftool set -t int memory/sysman/mmc_mount -1 -i -s system::vconf_system +vconftool set -t int memory/sysman/mmc_unmount -1 -i -s system::vconf_system +vconftool set -t int memory/sysman/mmc_format -1 -i -s system::vconf_system +vconftool set -t int memory/sysman/mmc_format_progress 0 -i -s system::vconf_system +vconftool set -t int memory/sysman/hdmi 0 -i -s system::vconf_system +vconftool set -t int memory/sysman/mmc_err_status 0 -i -s system::vconf_system +vconftool set -t int memory/private/sysman/enhance_pid 0 -i -s system::vconf_system +vconftool set -t int memory/private/sysman/siop_disable 0 -i -s system::vconf_system +vconftool set -t string memory/private/sysman/added_storage_uevent "" -i -s system::vconf_system +vconftool set -t string memory/private/sysman/removed_storage_uevent "" -u 5000 -i -s system::vconf_system +vconftool set -t string memory/private/sysman/siop_level_uevent "" -i -s system::vconf_system +#db type vconf key init +vconftool set -t int db/sysman/mmc_dev_changed 0 -i -s system::vconf_system +vconftool set -t int db/private/sysman/enhance_mode 0 -i -s system::vconf_system +vconftool set -t int db/private/sysman/enhance_scenario 0 -i -s system::vconf_system +vconftool set -t int db/private/sysman/enhance_tone 0 -i -s system::vconf_system +vconftool set -t int db/private/sysman/enhance_outdoor 0 -i -s system::vconf_system +vconftool set -t string db/private/sysman/mmc_device_id "" -i -s system::vconf_system +%endif + #memory type vconf key init vconftool set -t int memory/sysman/usbhost_status -1 -i -s system::vconf_system vconftool set -t int memory/sysman/charger_status 0 -i -s system::vconf_system @@ -170,8 +162,10 @@ vconftool set -t int memory/sysman/stime_changed 0 -i -s system::vconf_system vconftool set -t int memory/sysman/power_off 0 -u 5000 -i -f -s system::vconf_system vconftool set -t int memory/deviced/boot_power_on 0 -u 5000 -i -f -s system::vconf_system vconftool set -t int memory/sysman/battery_level_status -1 -i -s system::vconf_system +vconftool set -t int memory/sysman/low_memory 1 -i -s system::vconf_system #db type vconf key init +vconftool set -t int db/private/sysman/cool_down_mode 0 -i -s system::vconf_system vconftool set -t bool db/private/deviced/lcd_brightness_init 0 -i -s system::vconf_system vconftool set -t int memory/pm/state 0 -i -g 5000 -s system::vconf_system @@ -197,6 +191,19 @@ if [ $1 == 1 ]; then systemctl restart zbooting-done.service fi +if [ $1 == 2 ]; then # upgrade begins, it's rpm -Uvh + #buxton could be started by socket activation + systemctl start buxton.service +fi + +%pre +#without updating services "daemon-reload" following systemctl stop is wait a +# lot of time +systemctl daemon-reload +if [ $1 == 2 ]; then # it's upgrade, for rpm -Uvh + systemctl stop buxton.service +fi + %preun if [ $1 == 0 ]; then systemctl stop deviced.service @@ -211,6 +218,8 @@ systemctl daemon-reload %{_bindir}/deviced %{_bindir}/devicectl %{_bindir}/deviced-auto-test +%{_datadir}/dbus-1/services/org.tizen.system.deviced-auto-test.service +%{_libdir}/systemd/system/deviced-auto-test.service %{_libdir}/systemd/system/deviced.service %{_libdir}/systemd/system/multi-user.target.wants/deviced.service %{_sysconfdir}/systemd/default-extra-dependencies/ignore-units.d/deviced.service @@ -225,8 +234,20 @@ systemctl daemon-reload %{_libdir}/systemd/system/devicectl-start@.service %{_libdir}/systemd/system/shutdown.target.wants/devicectl-stop@display.service %{_datadir}/license/%{name} -%{_datadir}/deviced/usb-configurations/* -%{_sysconfdir}/smack/accesses2.d/deviced.rule +%{_sysconfdir}/smack/accesses.d/deviced.efl +/etc/deviced/pass.conf +/etc/deviced/usb-client-configuration.conf +/etc/deviced/usb-client-operation.conf +%if "%{?tizen_profile_name}" == "wearable" +%else +/etc/deviced/led.conf +%{_bindir}/movi_format.sh +%{_bindir}/mmc-smack-label +%{_bindir}/fsck_msdosfs +%{_bindir}/newfs_msdos +%{_datadir}/license/fsck_msdosfs +%{_datadir}/license/newfs_msdos +%endif %manifest deviced.manifest %attr(110,root,root) /opt/etc/dump.d/module.d/dump_pm.sh @@ -234,6 +255,8 @@ systemctl daemon-reload %{_sysconfdir}/deviced/mmc.conf %{_sysconfdir}/deviced/battery.conf %{_sysconfdir}/deviced/pmqos.conf +%{_sysconfdir}/deviced/storage.conf +%{_sysconfdir}/deviced/haptic.conf %attr(750,root,root)%{_bindir}/start_dr.sh %if %ENGINEER_MODE @@ -252,15 +275,3 @@ systemctl daemon-reload %{_includedir}/deviced/*.h %{_libdir}/libdeviced.so %{_libdir}/pkgconfig/deviced.pc - -%files -n logd - -%files -n liblogd -%manifest liblogd.manifest - -%files -n liblogd-devel - -%files -n liblogd-db -%manifest liblogd-db.manifest - -%files -n liblogd-db-devel diff --git a/packaging/liblogd-db.manifest b/packaging/liblogd-db.manifest deleted file mode 100644 index 0a38a69..0000000 --- a/packaging/liblogd-db.manifest +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - diff --git a/packaging/liblogd.manifest b/packaging/liblogd.manifest deleted file mode 100644 index 194afaf..0000000 --- a/packaging/liblogd.manifest +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - diff --git a/src/apps/apps.c b/src/apps/apps.c index 1560d1e..a4d1530 100755 --- a/src/apps/apps.c +++ b/src/apps/apps.c @@ -43,6 +43,11 @@ static void apps_init(void *data) static int initialized =0; if (!initialized) { + DD_LIST_FOREACH(apps_head, elem, dev) { + _D("[%s] initialize", dev->name); + if (dev->init) + dev->init(); + } initialized = 1; return; } diff --git a/src/apps/apps.h b/src/apps/apps.h index 8dd93d9..eb01510 100755 --- a/src/apps/apps.h +++ b/src/apps/apps.h @@ -22,7 +22,11 @@ #include "core/edbus-handler.h" #include "core/common.h" -#include "core/data.h" + +enum apps_enable_type{ + APPS_DISABLE = 0, + APPS_ENABLE = 1, +}; #define APPS_OPS_REGISTER(dev) \ static void __CONSTRUCTOR__ module_init(void) \ diff --git a/src/apps/cool-down.c b/src/apps/cool-down.c new file mode 100644 index 0000000..b5c0f28 --- /dev/null +++ b/src/apps/cool-down.c @@ -0,0 +1,83 @@ +/* + * deviced + * + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "core/log.h" +#include "core/common.h" +#include "apps.h" +#include "core/edbus-handler.h" +#include "core/launch.h" + +#define COOL_DOWN_POPUP_BUS_NAME POPUP_BUS_NAME +#define COOL_DOWN_POPUP_METHOD_LAUNCH "CooldownPopupLaunch" + +#define COOL_DOWN_POWER_OFF "cooldown_poweroff" +#define COOL_DOWN_POWER_WARNING "cooldown_warning" +#define COOL_DOWN_POWER_ON "cooldown_poweron" + +#define SIGNAL_COOL_DOWN_SHUT_DOWN "ShutDown" +#define SIGNAL_COOL_DOWN_SHUT_DOWN_LEN 8 +#define SIGNAL_COOL_DOWN_LIMIT_ACTION "LimitAction" +#define SIGNAL_COOL_DOWN_LIMIT_ACTION_LEN 11 +#define SIGNAL_COOL_DOWN_RELEASE "Release" +#define SIGNAL_COOL_DOWN_RELEASE_LEN 7 + +struct popup_data { + char *name; + char *key; +}; + +static int cool_down_launch(void *data) +{ + char *param[2]; + struct popup_data * key_data = (struct popup_data *)data; + int ret; + + if (!key_data || !key_data->key) + goto out; + + _I("%s", key_data->key); + + if (strncmp(key_data->key, SIGNAL_COOL_DOWN_SHUT_DOWN, + SIGNAL_COOL_DOWN_SHUT_DOWN_LEN) == 0) + param[1] = COOL_DOWN_POWER_OFF; + else if (strncmp(key_data->key, SIGNAL_COOL_DOWN_LIMIT_ACTION, + SIGNAL_COOL_DOWN_LIMIT_ACTION_LEN) == 0) + param[1] = COOL_DOWN_POWER_WARNING; + else if (strncmp(key_data->key, SIGNAL_COOL_DOWN_RELEASE, + SIGNAL_COOL_DOWN_RELEASE_LEN) == 0) + param[1] = COOL_DOWN_POWER_ON; + else + goto out; + + param[0] = POPUP_KEY_CONTENT; + + return dbus_method_async(COOL_DOWN_POPUP_BUS_NAME, + POPUP_PATH_SYSTEM, POPUP_INTERFACE_SYSTEM, + COOL_DOWN_POPUP_METHOD_LAUNCH, "ss", param); +out: + return 0; +} + + +static const struct apps_ops cooldown_ops = { + .name = "cooldown-syspopup", + .launch = cool_down_launch, +}; + +APPS_OPS_REGISTER(&cooldown_ops) diff --git a/src/apps/lowbat.c b/src/apps/lowbat.c index b90a7ff..abe3278 100644 --- a/src/apps/lowbat.c +++ b/src/apps/lowbat.c @@ -26,6 +26,13 @@ #define LOWBAT_CRITICAL "critical" #define LOWBAT_POWEROFF "poweroff" +#define DBUS_POPUP_PATH_LOWBAT POPUP_OBJECT_PATH"/Battery" +#define DBUS_POPUP_INTERFACE_LOWBAT POPUP_INTERFACE_NAME".Battery" + +#define METHOD_LOWBAT_POPUP "BatteryLow" +#define METHOD_LOWBAT_POPUP_DISABLE "LowBatteryDisable" +#define METHOD_LOWBAT_POPUP_ENABLE "LowBatteryEnable" + struct popup_data { char *name; char *key; @@ -33,6 +40,7 @@ struct popup_data { }; static int lowbat_pid = 0; +static int lowbat_popup = APPS_ENABLE; static void lowbat_cb(void *data, DBusMessage *msg, DBusError *unused) { @@ -57,16 +65,30 @@ static void lowbat_cb(void *data, DBusMessage *msg, DBusError *unused) static int lowbat_launch(void *data) { char *param[2]; + char *dest, *path, *iface, *method; struct popup_data * key_data = (struct popup_data *)data; int ret; + if (lowbat_popup == APPS_DISABLE) { + _D("skip lowbat popup control"); + return 0; + } + param[0] = key_data->key; param[1] = key_data->value; - - ret = dbus_method_async_with_reply(POPUP_BUS_NAME, - POPUP_PATH_LOWBAT, - POPUP_INTERFACE_LOWBAT, - POPUP_METHOD_LAUNCH, + if (strncmp(key_data->value, "lowbattery_warning", 18) == 0 || + strncmp(key_data->value, "lowbattery_critical", 19) == 0) { + dest = POPUP_BUS_NAME; + path = DBUS_POPUP_PATH_LOWBAT; + iface = DBUS_POPUP_INTERFACE_LOWBAT; + method = METHOD_LOWBAT_POPUP; + } else { + dest = POPUP_BUS_NAME; + path = POPUP_PATH_LOWBAT; + iface = POPUP_INTERFACE_LOWBAT; + method = POPUP_METHOD_LAUNCH; + } + ret = dbus_method_async_with_reply(dest, path, iface, method, "ss", param, lowbat_cb, -1, NULL); if (strncmp(key_data->value, LOWBAT_WARNING, strlen(LOWBAT_WARNING)) && @@ -102,10 +124,48 @@ static int lowbat_terminate(void *data) return 0; } +static DBusMessage *dbus_disable_popup(E_DBus_Object *obj, DBusMessage *msg) +{ + DBusMessageIter iter; + DBusMessage *reply; + + lowbat_popup = APPS_DISABLE; + reply = dbus_message_new_method_return(msg); + dbus_message_iter_init_append(reply, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &lowbat_popup); + return reply; +} + +static DBusMessage *dbus_enable_popup(E_DBus_Object *obj, DBusMessage *msg) +{ + DBusMessageIter iter; + DBusMessage *reply; + + lowbat_popup = APPS_ENABLE; + reply = dbus_message_new_method_return(msg); + dbus_message_iter_init_append(reply, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &lowbat_popup); + return reply; +} + +static const struct edbus_method edbus_methods[] = { + { METHOD_LOWBAT_POPUP_DISABLE, NULL, "i", dbus_disable_popup }, + { METHOD_LOWBAT_POPUP_ENABLE, NULL, "i", dbus_enable_popup }, +}; + +static void lowbat_init(void) +{ + int ret; + + ret = register_edbus_method(DEVICED_PATH_APPS, edbus_methods, ARRAY_SIZE(edbus_methods)); + if (ret < 0) + _E("fail to init edbus method(%d)", ret); +} static const struct apps_ops lowbat_ops = { - .name = "lowbat-syspopup", - .launch = lowbat_launch, + .name = "lowbat-syspopup", + .init = lowbat_init, + .launch = lowbat_launch, .terminate = lowbat_terminate, }; diff --git a/src/apps/lowmem.c b/src/apps/lowmem.c index 50755f0..96c16b7 100644 --- a/src/apps/lowmem.c +++ b/src/apps/lowmem.c @@ -36,7 +36,7 @@ static int lowmem_launch(void *data) param[0] = params->key; param[1] = params->value; - return dbus_method_sync(POPUP_BUS_NAME, + return dbus_method_async(POPUP_BUS_NAME, POPUP_PATH_LOWMEM, POPUP_INTERFACE_LOWMEM, POPUP_METHOD_LAUNCH, "ss", param); diff --git a/src/auto-test/CMakeLists.txt b/src/auto-test/CMakeLists.txt index 303482d..01f072f 100755 --- a/src/auto-test/CMakeLists.txt +++ b/src/auto-test/CMakeLists.txt @@ -15,10 +15,13 @@ SET(SRCS test.c main.c udev.c + archive.c boot.c cpu-info.c board-info.c time.c + result.c + cool-down.c ) # extcon test @@ -26,19 +29,20 @@ SET(SRCS ${SRCS} power-supply.c storage.c usb.c + hdmi.c ) IF(NOT USE_MICRO_DD) SET(SRCS ${SRCS} cradle.c earjack.c - hdmi.c keyboard.c + tvout.c ) ENDIF(NOT USE_MICRO_DD) INCLUDE(FindPkgConfig) -pkg_check_modules(pkgs REQUIRED edbus) +pkg_check_modules(pkgs REQUIRED edbus libarchive) FOREACH(flag ${pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") @@ -61,6 +65,8 @@ ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") ADD_DEFINITIONS("-DENABLE_TEST_DLOG") ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} shared) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} "-larchive" shared) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin) + +ADD_SUBDIRECTORY(activation) diff --git a/src/auto-test/activation/CMakeLists.txt b/src/auto-test/activation/CMakeLists.txt new file mode 100644 index 0000000..af86355 --- /dev/null +++ b/src/auto-test/activation/CMakeLists.txt @@ -0,0 +1,2 @@ +ADD_SUBDIRECTORY(systemd) +ADD_SUBDIRECTORY(dbus) diff --git a/src/auto-test/activation/dbus/CMakeLists.txt b/src/auto-test/activation/dbus/CMakeLists.txt new file mode 100644 index 0000000..f970318 --- /dev/null +++ b/src/auto-test/activation/dbus/CMakeLists.txt @@ -0,0 +1,7 @@ +SET(SYSTEM_DBUS_SERVICE_DIR "${PREFIX}/share/dbus-1/services") + +INSTALL(FILES + ${CMAKE_CURRENT_BINARY_DIR}/org.tizen.system.deviced-auto-test.service + DESTINATION + ${SYSTEM_DBUS_SERVICE_DIR} +) diff --git a/src/auto-test/activation/dbus/org.tizen.system.deviced-auto-test.service b/src/auto-test/activation/dbus/org.tizen.system.deviced-auto-test.service new file mode 100644 index 0000000..63efeb5 --- /dev/null +++ b/src/auto-test/activation/dbus/org.tizen.system.deviced-auto-test.service @@ -0,0 +1,5 @@ +[D-BUS Service] +Name=org.tizen.system.DevicedAutoTest +Exec=/bin/false +SystemdService=deviced-auto-test.service +User=root diff --git a/src/auto-test/activation/systemd/CMakeLists.txt b/src/auto-test/activation/systemd/CMakeLists.txt new file mode 100644 index 0000000..cd39303 --- /dev/null +++ b/src/auto-test/activation/systemd/CMakeLists.txt @@ -0,0 +1,11 @@ +SET(SD_SYS_UNIT_DIR "${LIBDIR}/systemd/system") + +SET(SD_SYS_UNITS + deviced-auto-test.service +) + +INSTALL(FILES + ${CMAKE_CURRENT_BINARY_DIR}/${SD_SYS_UNITS} + DESTINATION + ${SD_SYS_UNIT_DIR} +) diff --git a/src/auto-test/activation/systemd/deviced-auto-test.service b/src/auto-test/activation/systemd/deviced-auto-test.service new file mode 100644 index 0000000..7e8d820 --- /dev/null +++ b/src/auto-test/activation/systemd/deviced-auto-test.service @@ -0,0 +1,10 @@ +[Unit] +Description=Start the auto test service +Requires=dbus.socket +After=dbus.socket + +[Service] +Type=dbus +BusName=org.tizen.system.DevicedAutoTest +ExecStart=/usr/bin/deviced-auto-test +KillSignal=SIGUSR1 diff --git a/src/auto-test/archive.c b/src/auto-test/archive.c new file mode 100644 index 0000000..01e834c --- /dev/null +++ b/src/auto-test/archive.c @@ -0,0 +1,216 @@ +/* + * test + * + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "test.h" + +#define DEFAULT_READ_BLOCK_SIZE 10240 + +struct archive_data { + ssize_t len; + char *buff; +}; + +static mode_t default_mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; + +static int file_is_dir(const char *file) +{ + struct stat st; + + if (stat(file, &st) < 0) + return 0; + if (S_ISDIR(st.st_mode)) + return 1; + return 0; +} + +static struct archive_data* get_data_from_archive(char *path, char *item) +{ + struct archive *arch; + struct archive_entry *entry; + struct archive_data *data = NULL; + int fd; + int ret; + + if (!path || !item) + return NULL; + + _R("%s comp path %s, file name %s", __func__, path, item); + + fd = open(path, O_RDONLY); + if (fd < 0) { + _E("open fail"); + return NULL; + } + arch = archive_read_new(); + if (arch == NULL) { + _E("Couldn't create archive reader."); + goto out; + } + if (archive_read_support_compression_all(arch) != ARCHIVE_OK) { + _E("%s(%d)", archive_error_string( arch ), archive_errno( arch )); + goto out; + } + if (archive_read_support_format_all(arch) != ARCHIVE_OK) { + _E("%s(%d)", archive_error_string( arch ), archive_errno( arch )); + goto out; + } + if (archive_read_open_fd(arch, fd, DEFAULT_READ_BLOCK_SIZE) != ARCHIVE_OK) { + _E("%s(%d)", archive_error_string( arch ), archive_errno( arch )); + goto out; + } + + while ((ret = archive_read_next_header(arch, &entry)) == ARCHIVE_OK) { + if (!S_ISREG(archive_entry_mode(entry))) + continue; + if (strncmp(archive_entry_pathname(entry), item, strlen(item))) + continue; + data = (struct archive_data *)malloc(sizeof(struct archive_data)); + if (!data) { + _E("malloc fail"); + goto finish; + } + data->len = archive_entry_size(entry); + data->buff = (char *)malloc(sizeof(char)*data->len); + if (!data->buff) { + _E("malloc fail"); + goto finish; + } + _R("%s file %s size %d", __func__, archive_entry_pathname(entry), data->len); + ret = archive_read_data(arch, data->buff, data->len); + if (ret < 0) + _E("read fail"); + break; + } +finish: + /* Close the archives. */ + if (archive_read_finish(arch) != ARCHIVE_OK) + _E("Error closing input archive"); +out: + close(fd); + return data; +} + +static void test_save_data_to_file(char *name, struct archive_data *data) +{ + char path[PATH_MAX]; + char ss[PATH_MAX]; + struct stat st; + int fd; + int ret; + int i; + + if (!name || !data) { + _E("input fail"); + return; + } + snprintf(path, sizeof(path), "/tmp/%s", name); + if (file_is_dir(path)) + return; + for (i = 0; path[i] != '\0'; ss[i] = path[i], i++) + { + if (i == sizeof(ss) - 1) { + _E("fail"); + return; + } + if (((path[i] == '/') || (path[i] == '\\')) && (i > 0)) { + ss[i] = '\0'; + if (stat(ss, &st) < 0) { + ret = mkdir(ss, default_mode); + if (ret < 0) { + _E("Make Directory is failed"); + return; + } + } else if (!S_ISDIR(st.st_mode)) { + _E("fail to check dir %s", ss); + return; + } + } + } + ss[i] = '\0'; + fd = open(ss, O_CREAT | O_TRUNC | O_WRONLY, 0644); + if (fd < 0) { + _E("open fail(%s)", strerror(errno)); + return; + } + ret = write(fd, data->buff, data->len); + if (ret < 0) + _E("write fail"); + close(fd); + _R("%s %s", __func__, path); +} + +static int archive_unit(int argc, char **argv) +{ + struct archive_data *data = NULL; + struct timespec start; + struct timespec end; + long delta; + + if (argc != 4) { + _E("arg fail"); + goto out; + } + clock_gettime(CLOCK_REALTIME, &start); + data = get_data_from_archive(argv[2], argv[3]); + clock_gettime(CLOCK_REALTIME, &end); + delta = (long)((end.tv_sec*1000 + end.tv_nsec/1000000) - + (start.tv_sec*1000 + start.tv_nsec/1000000)); + + _R("%s operation time %ldms", __func__, delta); + if (!data) + goto out; + if (!data->buff) { + free(data); + goto out; + } + test_save_data_to_file(argv[3], data); + free(data->buff); + free(data); +out: + return 0; +} + +static void unit(char *unit, char *status) +{ +} + +static void archive_init(void *data) +{ +} + +static void archive_exit(void *data) +{ +} + +static const struct test_ops archive_test_ops = { + .priority = TEST_PRIORITY_NORMAL, + .name = "archive", + .init = archive_init, + .exit = archive_exit, + .unit = archive_unit, +}; + +TEST_OPS_REGISTER(&archive_test_ops) diff --git a/src/auto-test/board-info.c b/src/auto-test/board-info.c index ca4cc6d..8d45a28 100644 --- a/src/auto-test/board-info.c +++ b/src/auto-test/board-info.c @@ -18,10 +18,11 @@ #include "test.h" +#define METHOD_GET_NUM "GetNum" #define METHOD_GET_SERIAL "GetSerial" #define METHOD_GET_REVISION "GetHWRev" -void get_serial(void) +void board_serial(void) { DBusError err; DBusMessage *msg; @@ -46,9 +47,14 @@ void get_serial(void) dbus_error_free(&err); _D("%s %d", data, val); + if (val < 0) + _R("[NG] ---- %s : V(if your target is eng, NG is Normal)", + __func__); + else + _R("[OK] ---- %s : V(%s)", __func__, data); } -static void get_revision(void) +static void board_revision(void) { DBusError err; DBusMessage *msg; @@ -76,13 +82,50 @@ static void get_revision(void) } else { _D("Rinato"); } + if (val < 0) + _R("[NG] ---- %s", __func__); + else + _R("[OK] ---- %s : V(%d)", __func__, val); +} + +void board_numer(void) +{ + DBusError err; + DBusMessage *msg; + int ret, val; + char *data; + + msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME, DEVICED_PATH_BOARD, + DEVICED_INTERFACE_BOARD, METHOD_GET_NUM, NULL, NULL); + if (!msg) { + _E("fail send message"); + return; + } + + dbus_error_init(&err); + + ret = dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &data, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID); + if (!ret) { + _E("no message : [%s:%s]", err.name, err.message); + return; + } + dbus_message_unref(msg); + dbus_error_free(&err); + + _D("%s %d", data, val); + if (val < 0) + _R("[NG] ---- %s : V(if your target is eng, NG is Normal)", + __func__); + else + _R("[OK] ---- %s : V(%s)", __func__, data); } static void board_init(void *data) { _I("start test"); - get_revision(); - get_serial(); + board_revision(); + board_serial(); + board_numer(); } static void board_exit(void *data) @@ -92,8 +135,9 @@ static void board_exit(void *data) static int board_unit(int argc, char **argv) { - get_revision(); - get_serial(); + board_revision(); + board_serial(); + board_numer(); return 0; } diff --git a/src/auto-test/boot.c b/src/auto-test/boot.c index 5374e57..7fd0c48 100644 --- a/src/auto-test/boot.c +++ b/src/auto-test/boot.c @@ -109,16 +109,21 @@ static int broadcast_edbus_signal(const char *path, const char *interface, return -EPERM; } - e_dbus_message_send(edbus_conn, msg, NULL, -1, NULL); - + r = dbus_connection_send(conn, msg, NULL); dbus_message_unref(msg); + + if (r != TRUE) { + _E("dbus_connection_send error (%s:%s-%s)", path, interface, name); + return -ECOMM; + } return 0; } -static void poweroff_send_broadcast(char *status) +static void poweroff_popup(char *status) { char *arr[2]; char str_status[32]; + int val; snprintf(str_status, sizeof(str_status), "%s", status); arr[0] = str_status; @@ -126,8 +131,12 @@ static void poweroff_send_broadcast(char *status) _D("broadcast poweroff %s %s", arr[0], arr[1]); edbus_init(); - broadcast_edbus_signal(DEVICED_OBJECT_PATH, DEVICED_INTERFACE_NAME, + val = broadcast_edbus_signal(DEVICED_OBJECT_PATH, DEVICED_INTERFACE_NAME, "poweroffpopup", "si", arr); + if (val < 0) + _R("[NG] ---- %s", __func__); + else + _R("[OK] ---- %s : V(%s)", __func__, status); edbus_exit(); } @@ -140,7 +149,7 @@ static void unit(char *unit, char *status) strcmp(status, boot_control_types[index].status) != 0) continue; if (strcmp(unit, "poweroffpopup") == 0) - poweroff_send_broadcast(boot_control_types[index].status); + poweroff_popup(boot_control_types[index].status); } } diff --git a/src/auto-test/cool-down.c b/src/auto-test/cool-down.c new file mode 100644 index 0000000..eaa56d2 --- /dev/null +++ b/src/auto-test/cool-down.c @@ -0,0 +1,138 @@ +/* + * test + * + * Copyright (c) 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "test.h" + +#define METHOD_COOL_DOWN_STATUS "GetCoolDownStatus" +#define METHOD_COOL_DOWN_CHANGED "CoolDownChanged" +static int get_status(void) +{ + DBusError err; + DBusMessage *msg; + int ret; + char *str; + + msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME, + DEVICED_PATH_SYSNOTI, + DEVICED_INTERFACE_SYSNOTI, + METHOD_COOL_DOWN_STATUS, NULL, NULL); + if (!msg) { + _E("fail : %s %s %s %s", + DEVICED_BUS_NAME, DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI, + METHOD_COOL_DOWN_STATUS); + return -EBADMSG; + } + + dbus_error_init(&err); + + ret = dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &str, + DBUS_TYPE_INVALID); + if (!ret) + _E("no message : [%s:%s]", err.name, err.message); + + _I("%s", str); + if (ret < 0) + _R("[NG] ---- %s", __func__); + else + _R("[OK] ---- %s : V(%s)", __func__, str); + dbus_message_unref(msg); + dbus_error_free(&err); + return ret; +} + +static int cool_down(char *name, char *status) +{ + DBusError err; + DBusMessage *msg; + int ret, val; + char *param[4]; + + param[0] = METHOD_SET_DEVICE; + param[1] = "2"; + param[2] = name; + param[3] = status; + + msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME, + DEVICED_PATH_SYSNOTI, + DEVICED_INTERFACE_SYSNOTI, + METHOD_COOL_DOWN_CHANGED, "siss", param); + if (!msg) { + _E("fail : %s %s %s %s", + DEVICED_BUS_NAME, DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI, + METHOD_SET_DEVICE); + return -EBADMSG; + } + + dbus_error_init(&err); + + ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID); + if (ret == 0) { + _E("no message : [%s:%s]", err.name, err.message); + dbus_error_free(&err); + val = -EBADMSG; + } + _I("%s %s", name, status); + if (val < 0) + _R("[NG] ---- %s", __func__); + else + _R("[OK] ---- %s : V(%s %s)", + __func__, name, status); + dbus_message_unref(msg); + dbus_error_free(&err); + return val; +} + +static void unit(char *unit, char *status) +{ + int index; + + cool_down(unit, status); + get_status(); +} + +static void cool_down_init(void *data) +{ +} + +static void cool_down_exit(void *data) +{ +} + +static int cool_down_unit(int argc, char **argv) +{ + int status; + + if (argv[1] == NULL) + return -EINVAL; + if (argc != 4) + return -EAGAIN; + + unit(argv[2], argv[3]); +out: + return 0; +} + +static const struct test_ops cool_down_test_ops = { + .priority = TEST_PRIORITY_NORMAL, + .name = "cool-down", + .init = cool_down_init, + .exit = cool_down_exit, + .unit = cool_down_unit, +}; + +TEST_OPS_REGISTER(&cool_down_test_ops) diff --git a/src/auto-test/cpu-info.c b/src/auto-test/cpu-info.c index 9a5e156..8bac46e 100644 --- a/src/auto-test/cpu-info.c +++ b/src/auto-test/cpu-info.c @@ -20,7 +20,7 @@ #define METHOD_GET_REVISION "GetRevision" -static void get_revision(void) +static void cpuinfo_revision(void) { DBusError err; DBusMessage *msg; @@ -48,12 +48,16 @@ static void get_revision(void) } else { _D("Rinato"); } + if (val < 0) + _R("[NG] ---- %s", __func__); + else + _R("[OK] ---- %s : V(%d)", __func__, val); } static void cpuinfo_init(void *data) { _I("start test"); - get_revision(); + cpuinfo_revision(); } static void cpuinfo_exit(void *data) @@ -63,7 +67,7 @@ static void cpuinfo_exit(void *data) static int cpuinfo_unit(int argc, char **argv) { - get_revision(); + cpuinfo_revision(); return 0; } diff --git a/src/auto-test/cradle.c b/src/auto-test/cradle.c index 3abe136..eba5039 100644 --- a/src/auto-test/cradle.c +++ b/src/auto-test/cradle.c @@ -32,7 +32,7 @@ static int test_cradle(void) { DBusError err; DBusMessage *msg; - int ret, level; + int ret, val; msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME, DEVICED_PATH_SYSNOTI, @@ -47,24 +47,28 @@ static int test_cradle(void) dbus_error_init(&err); - ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &level, + ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID); if (!ret) { _E("no message : [%s:%s]", err.name, err.message); - level = -1; + val = -1; } - _I("%d", level); + _I("%d", val); + if (val < 0) + _R("[NG] ---- %s", __func__); + else + _R("[OK] ---- %s : V(%d)", __func__, val); dbus_message_unref(msg); dbus_error_free(&err); sleep(TEST_WAIT_TIME_INTERVAL); - return level; + return val; } -static int test(int index) +static int cradle(int index) { DBusError err; DBusMessage *msg; - int ret, ret_val; + int ret, val; char *param[4]; param[0] = METHOD_SET_DEVICE; @@ -85,17 +89,22 @@ static int test(int index) dbus_error_init(&err); - ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &ret_val, DBUS_TYPE_INVALID); + ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID); if (ret == 0) { _E("no message : [%s:%s]", err.name, err.message); dbus_error_free(&err); - ret_val = -EBADMSG; + val = -EBADMSG; } _I("%s %s", device_change_types[index].name, device_change_types[index].status); + if (val < 0) + _R("[NG] ---- %s", __func__); + else + _R("[OK] ---- %s : V(%s %s)", + __func__, device_change_types[index].name, device_change_types[index].status); dbus_message_unref(msg); dbus_error_free(&err); sleep(TEST_WAIT_TIME_INTERVAL); - return ret_val; + return val; } static void unit(char *unit, char *status) @@ -106,7 +115,7 @@ static void unit(char *unit, char *status) if (strcmp(unit, device_change_types[index].name) != 0 || strcmp(status, device_change_types[index].status) != 0) continue; - test(index); + cradle(index); test_cradle(); } } @@ -117,7 +126,7 @@ static void cradle_init(void *data) _I("start test"); for (index = 0; index < ARRAY_SIZE(device_change_types); index++) - test(index); + cradle(index); } static void cradle_exit(void *data) @@ -134,7 +143,7 @@ static int cradle_unit(int argc, char **argv) if (argc != 4) return -EAGAIN; - unit(argv[2], argv[3]); + unit(argv[1], argv[2]); out: return 0; } diff --git a/src/auto-test/earjack.c b/src/auto-test/earjack.c index 8643bdc..b883aae 100644 --- a/src/auto-test/earjack.c +++ b/src/auto-test/earjack.c @@ -21,17 +21,17 @@ static const struct device_change_type { char *name; char *status; } device_change_types [] = { - {"jack", "1"}, - {"jack", "0"}, - {"key", "1"}, - {"key", "0"}, + {"earjack", "1"}, + {"earjack", "0"}, + {"earkey", "1"}, + {"earkey", "0"}, }; -static int test(int index) +static int earjack(int index) { DBusError err; DBusMessage *msg; - int ret, ret_val; + int ret, val; char *param[4]; param[0] = METHOD_SET_DEVICE; @@ -52,17 +52,22 @@ static int test(int index) dbus_error_init(&err); - ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &ret_val, DBUS_TYPE_INVALID); + ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID); if (ret == 0) { _E("no message : [%s:%s]", err.name, err.message); dbus_error_free(&err); - ret_val = -EBADMSG; + val = -EBADMSG; } _I("%s %s", device_change_types[index].name, device_change_types[index].status); + if (val < 0) + _R("[NG] ---- %s", __func__); + else + _R("[OK] ---- %s : V(%s %s)", + __func__, device_change_types[index].name, device_change_types[index].status); dbus_message_unref(msg); dbus_error_free(&err); sleep(TEST_WAIT_TIME_INTERVAL); - return ret_val; + return val; } static void unit(char *unit, char *status) @@ -73,7 +78,7 @@ static void unit(char *unit, char *status) if (strcmp(unit, device_change_types[index].name) != 0 || strcmp(status, device_change_types[index].status) != 0) continue; - test(index); + earjack(index); } } @@ -83,7 +88,7 @@ static void earjack_init(void *data) _I("start test"); for (index = 0; index < ARRAY_SIZE(device_change_types); index++) - test(index); + earjack(index); } static void earjack_exit(void *data) @@ -97,10 +102,10 @@ static int earjack_unit(int argc, char **argv) if (argv[1] == NULL) return -EINVAL; - if (argc != 3) + if (argc != 4) return -EAGAIN; - unit(argv[1], argv[2]); + unit(argv[2], argv[3]); out: return 0; } diff --git a/src/auto-test/hdmi.c b/src/auto-test/hdmi.c index c1edf83..0fa383b 100644 --- a/src/auto-test/hdmi.c +++ b/src/auto-test/hdmi.c @@ -33,7 +33,7 @@ static int test_hdmi(void) { DBusError err; DBusMessage *msg; - int ret, level; + int ret, val; msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME, DEVICED_PATH_SYSNOTI, @@ -48,24 +48,28 @@ static int test_hdmi(void) dbus_error_init(&err); - ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &level, + ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID); if (!ret) { _E("no message : [%s:%s]", err.name, err.message); - level = -1; + val = -1; } - _I("%d", level); + _I("%d", val); + if (val < 0) + _R("[NG] ---- %s", __func__); + else + _R("[OK] ---- %s : V(%d)", __func__, val); dbus_message_unref(msg); dbus_error_free(&err); sleep(TEST_WAIT_TIME_INTERVAL); - return level; + return val; } static int test_hdcp(void) { DBusError err; DBusMessage *msg; - int ret, level; + int ret, val; msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME, DEVICED_PATH_SYSNOTI, @@ -80,24 +84,28 @@ static int test_hdcp(void) dbus_error_init(&err); - ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &level, + ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID); if (!ret) { _E("no message : [%s:%s]", err.name, err.message); - level = -1; + val = -1; } - _I("%d", level); + _I("%d", val); + if (val < 0) + _R("[NG] ---- %s", __func__); + else + _R("[OK] ---- %s : V(%d)", __func__, val); dbus_message_unref(msg); dbus_error_free(&err); sleep(TEST_WAIT_TIME_INTERVAL); - return level; + return val; } static int test_hdmi_audio(void) { DBusError err; DBusMessage *msg; - int ret, level; + int ret, val; msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME, DEVICED_PATH_SYSNOTI, @@ -112,24 +120,28 @@ static int test_hdmi_audio(void) dbus_error_init(&err); - ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &level, + ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID); if (!ret) { _E("no message : [%s:%s]", err.name, err.message); - level = -1; + val = -1; } - _I("%d", level); + _I("%d", val); + if (val < 0) + _R("[NG] ---- %s", __func__); + else + _R("[OK] ---- %s : V(%d)", __func__, val); dbus_message_unref(msg); dbus_error_free(&err); sleep(TEST_WAIT_TIME_INTERVAL); - return level; + return val; } -static int test(int index) +static int hdmi(int index) { DBusError err; DBusMessage *msg; - int ret, ret_val; + int ret, val; char *param[4]; param[0] = METHOD_SET_DEVICE; @@ -150,17 +162,22 @@ static int test(int index) dbus_error_init(&err); - ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &ret_val, DBUS_TYPE_INVALID); + ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID); if (ret == 0) { _E("no message : [%s:%s]", err.name, err.message); dbus_error_free(&err); - ret_val = -EBADMSG; + val = -EBADMSG; } _I("%s %s", device_change_types[index].name, device_change_types[index].status); + if (val < 0) + _R("[NG] ---- %s", __func__); + else + _R("[OK] ---- %s : V(%s %s)", + __func__, device_change_types[index].name, device_change_types[index].status); dbus_message_unref(msg); dbus_error_free(&err); sleep(TEST_WAIT_TIME_INTERVAL); - return ret_val; + return val; } static void unit(char *unit, char *status) @@ -171,7 +188,7 @@ static void unit(char *unit, char *status) if (strcmp(unit, device_change_types[index].name) != 0 || strcmp(status, device_change_types[index].status) != 0) continue; - test(index); + hdmi(index); } } @@ -181,7 +198,7 @@ static void hdmi_init(void *data) _I("start test"); for (index = 0; index < ARRAY_SIZE(device_change_types); index++) { - test(index); + hdmi(index); test_hdmi(); test_hdcp(); test_hdmi_audio(); diff --git a/src/auto-test/keyboard.c b/src/auto-test/keyboard.c index e9cec63..950ac62 100644 --- a/src/auto-test/keyboard.c +++ b/src/auto-test/keyboard.c @@ -25,11 +25,11 @@ static const struct device_change_type { {"keyboard", "0"}, }; -static int test(int index) +static int keyboard(int index) { DBusError err; DBusMessage *msg; - int ret, ret_val; + int ret, val; char *param[4]; param[0] = METHOD_SET_DEVICE; @@ -50,17 +50,22 @@ static int test(int index) dbus_error_init(&err); - ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &ret_val, DBUS_TYPE_INVALID); + ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID); if (ret == 0) { _E("no message : [%s:%s]", err.name, err.message); dbus_error_free(&err); - ret_val = -EBADMSG; + val = -EBADMSG; } _I("%s %s", device_change_types[index].name, device_change_types[index].status); + if (val < 0) + _R("[NG] ---- %s", __func__); + else + _R("[OK] ---- %s : V(%s %s)", + __func__, device_change_types[index].name, device_change_types[index].status); dbus_message_unref(msg); dbus_error_free(&err); sleep(TEST_WAIT_TIME_INTERVAL); - return ret_val; + return val; } static void unit(char *unit, char *status) @@ -71,7 +76,7 @@ static void unit(char *unit, char *status) if (strcmp(unit, device_change_types[index].name) != 0 || strcmp(status, device_change_types[index].status) != 0) continue; - test(index); + keyboard(index); } } @@ -81,7 +86,7 @@ static void keyboard_init(void *data) _I("start test"); for (index = 0; index < ARRAY_SIZE(device_change_types); index++) - test(index); + keyboard(index); } static void keyboard_exit(void *data) diff --git a/src/auto-test/power-supply.c b/src/auto-test/power-supply.c index d63a577..bbda3d4 100644 --- a/src/auto-test/power-supply.c +++ b/src/auto-test/power-supply.c @@ -21,10 +21,18 @@ #define S_ENTER 1 #define S_LEAVE 0 +enum apps_enable_type{ + APPS_DISABLE = 0, + APPS_ENABLE = 1, +}; + #define SIGNAL_CHARGE_NOW "ChargeNow" #define SIGNAL_CHARGER_STATUS "ChargerStatus" #define SIGNAL_TEMP_GOOD "TempGood" +#define METHOD_LOWBAT_POPUP_DISABLE "LowBatteryDisable" +#define METHOD_LOWBAT_POPUP_ENABLE "LowBatteryEnable" + static E_DBus_Signal_Handler *edbus_charge_now_handler; static E_DBus_Signal_Handler *edbus_charger_status_handler; static E_DBus_Signal_Handler *edbus_temp_good_handler; @@ -88,8 +96,12 @@ static struct power_supply_type { {"ta", S_ENTER, "100","Charging", "Good", "2", "1", "CHARGE"}, //charging {"ta", S_LEAVE, "100","Discharging", "Good", "1", "1", "DISCHARGE"},//discharging - {"capacity", S_ENTER, "100","Discharging", "Good", "1", "1", "CAPACITY"},//charging - {"capacity", S_LEAVE, "100","Charging", "Good", "2", "1", "CAPACITY"},//discharging + + {"full", S_ENTER, "100","Full", "Good", "2", "1", "CHARGE"}, //full + {"full", S_LEAVE, "100","Discharging", "Good", "1", "1", "DISCHARGE"},//discharging + + {"capa", S_ENTER, "100","Discharging", "Good", "1", "1", "CAPACITY"},//discharging + {"capa", S_LEAVE, "100","Charging", "Good", "2", "1", "CAPACITY"},//charging }; static void unregister_edbus_signal_handler(void) @@ -248,7 +260,7 @@ edbus_handler_out: e_dbus_shutdown(); return ret; } -static void test_signal(void) +static void power_supply_signal(void) { _I("test"); register_charge_now_handler(); @@ -257,11 +269,11 @@ static void test_signal(void) ecore_main_loop_begin(); } -static int test(int index) +static int power_supply(int index) { DBusError err; DBusMessage *msg; - int ret, ret_val; + int ret, val; char *param[7]; param[0] = POWER_SUBSYSTEM; @@ -285,16 +297,16 @@ static int test(int index) dbus_error_init(&err); - ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &ret_val, DBUS_TYPE_INVALID); + ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID); if (ret == 0) { _E("no message : [%s:%s]", err.name, err.message); dbus_error_free(&err); - ret_val = -EBADMSG; + val = -EBADMSG; } if (power_supply_types[index].name != NULL) _I("++++++++++[START] %s ++++++++++", power_supply_types[index].name); - _I("CAPACITY(%s , %s) P(%s) STATUS(%s) HEALTH(%s)", + _I("C(%s , %s) P(%s) STATUS(%s) HEALTH(%s)", power_supply_types[index].capacity, power_supply_types[index].online, power_supply_types[index].present, @@ -302,11 +314,20 @@ static int test(int index) power_supply_types[index].health); if (power_supply_types[index].name != NULL) _I("++++++++++[END] %s ++++++++++", power_supply_types[index].name); - + if (val < 0) + _R("[NG] ---- %s", __func__); + else + _R("[OK] ---- %s : C(%s , %s) P(%s) S(%s) H(%s)", + __func__, + power_supply_types[index].capacity, + power_supply_types[index].online, + power_supply_types[index].present, + power_supply_types[index].charge_status, + power_supply_types[index].health); dbus_message_unref(msg); dbus_error_free(&err); sleep(TEST_WAIT_TIME_INTERVAL); - return ret_val; + return val; } static void scenario(char *scenario) @@ -316,7 +337,7 @@ static void scenario(char *scenario) for (index = 0; index < ARRAY_SIZE(power_supply_types); index++) { if (strcmp(scenario, power_supply_types[index].scenario) != 0) continue; - test(index); + power_supply(index); } } @@ -332,7 +353,7 @@ static void unit(char *unit, int status) power_supply_types[index].status != status) continue; found = 1; - test(index); + power_supply(index); } if (found) @@ -347,13 +368,73 @@ static void unit(char *unit, int status) return; for (index = 0; index < ARRAY_SIZE(power_supply_types); index++) { - if (strcmp("capacity", power_supply_types[index].scenario) != 0 || + if (strcmp("capa", power_supply_types[index].scenario) != 0 || power_supply_types[index].status != status) continue; power_supply_types[index].capacity = unit; _D("%s", power_supply_types[index].capacity); - test(index); + power_supply(index); + } +} + +static void full(char *unit, char *capacity, int status) +{ + int index; + for (index = 0; index < ARRAY_SIZE(power_supply_types); index++) { + if (strcmp(unit, power_supply_types[index].scenario) != 0 || + power_supply_types[index].status != status) + continue; + power_supply_types[index].capacity = capacity; + _D("%s", power_supply_types[index].capacity); + power_supply(index); + } +} + +static void lowbat_popup(char *status) +{ + DBusError err; + DBusMessage *msg; + int ret, val; + char *method; + + if (!status) + return; + val = atoi(status); + if (val != APPS_ENABLE && val != APPS_DISABLE) + return; + + if (val == APPS_ENABLE) + method = METHOD_LOWBAT_POPUP_ENABLE; + else + method = METHOD_LOWBAT_POPUP_DISABLE; + msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME, + DEVICED_PATH_APPS, + DEVICED_INTERFACE_APPS, + method, NULL, NULL); + + if (!msg) { + _E("fail : %s %s %s %s", + DEVICED_BUS_NAME, DEVICED_PATH_APPS, DEVICED_INTERFACE_APPS, method); + return; } + + dbus_error_init(&err); + + ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID); + if (ret == 0) { + _E("no message : [%s:%s]", err.name, err.message); + dbus_error_free(&err); + val = -EBADMSG; + } + + if (val < 0) + _R("[NG] ---- %s : V(%s %d)", __func__, method, val); + else + _R("[OK] ---- %s : V(%s %d)", __func__, method, val); + dbus_message_unref(msg); + dbus_error_free(&err); + sleep(TEST_WAIT_TIME_INTERVAL); + return; } static void power_supply_init(void *data) @@ -362,7 +443,7 @@ static void power_supply_init(void *data) _I("start test"); for (index = 0; index < ARRAY_SIZE(power_supply_types); index++) - test(index); + power_supply(index); } static void power_supply_exit(void *data) @@ -374,16 +455,22 @@ static int power_supply_unit(int argc, char **argv) { if (argv[1] == NULL) return -EINVAL; - else if (argc != 4) + else if (argc < 4) return -EAGAIN; if (strcmp("wait", argv[2]) == 0) - test_signal(); + power_supply_signal(); + else if (strcmp("popup", argv[2]) == 0) + lowbat_popup(argv[3]); else if (strcmp("scenario", argv[2]) == 0) scenario(argv[3]); else if (strcmp("enter", argv[3]) == 0) unit(argv[2], S_ENTER); else if (strcmp("leave", argv[3]) == 0) unit(argv[2], S_LEAVE); + else if (strcmp("enter", argv[4]) == 0) + full(argv[2], argv[3], S_ENTER); + else if (strcmp("leave", argv[4]) == 0) + full(argv[2], argv[3], S_LEAVE); return 0; } diff --git a/src/auto-test/result.c b/src/auto-test/result.c new file mode 100644 index 0000000..00c1c3b --- /dev/null +++ b/src/auto-test/result.c @@ -0,0 +1,45 @@ +/* + * test + * + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "core/list.h" +#include "core/common.h" + +#ifdef ENABLE_TEST_DLOG +#define ENABLE_DLOG +#endif + +#define LOG_TAG "ATR" //AUTO_TESTE_RESULT +#include "shared/log-macro.h" + +#define BUF_MAX 256 + +void _R (const char *format, ...) +{ + va_list args; + char buf[BUF_MAX]; + + va_start(args, format); + vsnprintf(buf, BUF_MAX, format, args); + va_end(args); + + _D("%s", buf); +} \ No newline at end of file diff --git a/src/auto-test/storage.c b/src/auto-test/storage.c index dad9a7c..c1a361f 100644 --- a/src/auto-test/storage.c +++ b/src/auto-test/storage.c @@ -50,7 +50,7 @@ static int request_mem_trim(void) return ret; } -static int test_storage(void) +static int storage(void) { DBusError err; DBusMessage *msg; @@ -76,6 +76,11 @@ static int test_storage(void) _E("no message : [%s:%s]", err.name, err.message); } _I("total : %4.4lf avail %4.4lf", dTotal, dAvail); + if (ret < 0) + _R("[NG] ---- %s", __func__); + else + _R("[OK] ---- %s : T(%4.4lf) A(%4.4lf)", + __func__, dTotal, dAvail); dbus_message_unref(msg); dbus_error_free(&err); sleep(TEST_WAIT_TIME_INTERVAL); @@ -85,7 +90,7 @@ static int test_storage(void) static void storage_init(void *data) { _I("start test"); - test_storage(); + storage(); } static void storage_exit(void *data) @@ -95,14 +100,14 @@ static void storage_exit(void *data) static int storage_unit(int argc, char **argv) { - int status; - if (argv[1] == NULL) return -EINVAL; - test_storage(); - request_mem_trim(); - ecore_main_loop_begin(); -out: + if (strcmp(argv[2], "value") == 0) + storage(); + else if (strcmp(argv[2], "signal") == 0) { + request_mem_trim(); + ecore_main_loop_begin(); + } return 0; } diff --git a/src/auto-test/test.h b/src/auto-test/test.h index 2f68f3c..46ff24a 100644 --- a/src/auto-test/test.h +++ b/src/auto-test/test.h @@ -20,6 +20,7 @@ #ifndef __TEST_H__ #define __TEST_H__ #include +#include #include #include @@ -103,5 +104,5 @@ DBusMessage *deviced_dbus_method_sync_with_reply(const char *dest, const char *p void add_test(const struct test_ops *c); void remove_test(const struct test_ops *c); const struct test_ops *find_test(const char *name); - +void _R (const char *format, ...); #endif diff --git a/src/auto-test/time.c b/src/auto-test/time.c index 71edb14..69ab94a 100644 --- a/src/auto-test/time.c +++ b/src/auto-test/time.c @@ -34,18 +34,21 @@ static void time_changed(void *data, DBusMessage *msg) { DBusError err; int val; - int r; + int ret; _I("edbus signal Received"); - r = dbus_message_is_signal(msg, DEVICED_INTERFACE_TIME, TIME_CHANGE_SIGNAL); - if (!r) { + ret = dbus_message_is_signal(msg, DEVICED_INTERFACE_TIME, TIME_CHANGE_SIGNAL); + if (!ret) { _E("dbus_message_is_signal error"); return; } _I("%s - %s", DEVICED_INTERFACE_TIME, TIME_CHANGE_SIGNAL); - + if (ret < 0) + _R("[NG] ---- %s", __func__); + else + _R("[OK] ---- %s", __func__); unregister_edbus_signal_handler(); ecore_shutdown(); } diff --git a/src/auto-test/tvout.c b/src/auto-test/tvout.c index 3b75459..25bc9d9 100644 --- a/src/auto-test/tvout.c +++ b/src/auto-test/tvout.c @@ -25,11 +25,11 @@ static const struct device_change_type { {"tvout", "0"}, }; -static int test(int index) +static int tvout(int index) { DBusError err; DBusMessage *msg; - int ret, ret_val; + int ret, val; char *param[4]; param[0] = METHOD_SET_DEVICE; @@ -50,17 +50,22 @@ static int test(int index) dbus_error_init(&err); - ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &ret_val, DBUS_TYPE_INVALID); + ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID); if (ret == 0) { _E("no message : [%s:%s]", err.name, err.message); dbus_error_free(&err); - ret_val = -EBADMSG; + val = -EBADMSG; } _I("%s %s", device_change_types[index].name, device_change_types[index].status); + if (val < 0) + _R("[NG] ---- %s", __func__); + else + _R("[OK] ---- %s : V(%s %s)", + __func__, device_change_types[index].name, device_change_types[index].status); dbus_message_unref(msg); dbus_error_free(&err); sleep(TEST_WAIT_TIME_INTERVAL); - return ret_val; + return val; } static void unit(char *unit, char *status) @@ -71,7 +76,7 @@ static void unit(char *unit, char *status) if (strcmp(unit, device_change_types[index].name) != 0 || strcmp(status, device_change_types[index].status) != 0) continue; - test(index); + tvout(index); } } @@ -81,7 +86,7 @@ static void tvout_init(void *data) _I("start test"); for (index = 0; index < ARRAY_SIZE(device_change_types); index++) - test(index); + tvout(index); } static void tvout_exit(void *data) diff --git a/src/auto-test/udev.c b/src/auto-test/udev.c index c9818e3..d0cc910 100644 --- a/src/auto-test/udev.c +++ b/src/auto-test/udev.c @@ -25,11 +25,11 @@ static const struct device_change_type { {"udev", "stop"}, }; -static int test(int index) +static int udev(int index) { DBusError err; DBusMessage *msg; - int ret, ret_val; + int ret, val; char *param[3]; param[0] = UDEV; @@ -48,16 +48,22 @@ static int test(int index) dbus_error_init(&err); - ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &ret_val, DBUS_TYPE_INVALID); + ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID); if (!ret) { _E("no message : [%s:%s]", err.name, err.message); - ret_val = -EBADMSG; + val = -EBADMSG; } - _I("START"); + _I("%s", device_change_types[index].status); + if (val < 0) + _R("[NG] ---- %s : %s", + __func__, device_change_types[index].status); + else + _R("[OK] ---- %s : %s", + __func__, device_change_types[index].status); dbus_message_unref(msg); dbus_error_free(&err); sleep(TEST_WAIT_TIME_INTERVAL); - return ret_val; + return val; } static void unit(char *unit, char *status) @@ -68,7 +74,7 @@ static void unit(char *unit, char *status) if (strcmp(unit, device_change_types[index].name) != 0 || strcmp(status, device_change_types[index].status) != 0) continue; - test(index); + udev(index); } } @@ -78,7 +84,7 @@ static void udev_init(void *data) _I("start test"); for (index = 0; index < ARRAY_SIZE(device_change_types); index++) - test(index); + udev(index); } static void udev_exit(void *data) diff --git a/src/auto-test/usb.c b/src/auto-test/usb.c index 2a8a901..93f7330 100644 --- a/src/auto-test/usb.c +++ b/src/auto-test/usb.c @@ -25,11 +25,11 @@ static const struct device_change_type { {"usb", "0"}, }; -static int test(int index) +static int usb(int index) { DBusError err; DBusMessage *msg; - int ret, ret_val; + int ret, val; char *param[4]; param[0] = METHOD_SET_DEVICE; @@ -50,17 +50,22 @@ static int test(int index) dbus_error_init(&err); - ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &ret_val, DBUS_TYPE_INVALID); + ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID); if (ret == 0) { _E("no message : [%s:%s]", err.name, err.message); dbus_error_free(&err); - ret_val = -EBADMSG; + val = -EBADMSG; } _I("%s %s", device_change_types[index].name, device_change_types[index].status); + if (val < 0) + _R("[NG] ---- %s", __func__); + else + _R("[OK] ---- %s : V(%s %s)", + __func__, device_change_types[index].name, device_change_types[index].status); dbus_message_unref(msg); dbus_error_free(&err); sleep(TEST_WAIT_TIME_INTERVAL); - return ret_val; + return val; } static void unit(char *unit, char *status) @@ -71,7 +76,7 @@ static void unit(char *unit, char *status) if (strcmp(unit, device_change_types[index].name) != 0 || strcmp(status, device_change_types[index].status) != 0) continue; - test(index); + usb(index); } } @@ -81,7 +86,7 @@ static void usb_init(void *data) _I("start test"); for (index = 0; index < ARRAY_SIZE(device_change_types); index++) - test(index); + usb(index); } static void usb_exit(void *data) diff --git a/src/battery/battery.c b/src/battery/battery.c deleted file mode 100644 index a48ddfa..0000000 --- a/src/battery/battery.c +++ /dev/null @@ -1,170 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define USE_LOGD 1 - -#include -#include -#include -#include "core/log.h" -#include "core/devices.h" -#include "core/udev.h" -#include "device-node.h" -#include "core/device-handler.h" -#include "core/device-notifier.h" -#include "core/edbus-handler.h" - -/* - * get_capacity - get battery capacity value - * using device_get_property - */ -static int get_capacity(void) -{ - int val, ret; - - ret = device_get_property(DEVICE_TYPE_POWER, PROP_POWER_CAPACITY, &val); - if (ret < 0) { - _E("fail to get battery capacity value"); - val = ret; - } - return val; -} - -static int update_battery(void *data) -{ - static int capacity = -1; - static int charge_now = -1; - - if (battery.capacity != capacity) { - _D("capacity is changed %d -> %d", capacity, battery.capacity); - capacity = battery.capacity; - } - - if (battery.charge_now != charge_now) { - _D("chaging status is changed %d -> %d", charge_now, battery.charge_now); - charge_now = battery.charge_now; - } - return 0; -} - -static DBusMessage *edbus_get_percent(E_DBus_Object *obj, DBusMessage *msg) -{ - DBusMessageIter iter; - DBusMessage *reply; - int ret; - - ret = battery.capacity; - - reply = dbus_message_new_method_return(msg); - dbus_message_iter_init_append(reply, &iter); - dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); - return reply; -} - -static DBusMessage *edbus_get_percent_raw(E_DBus_Object *obj, DBusMessage *msg) -{ - DBusMessageIter iter; - DBusMessage *reply; - int ret, val; - - ret = device_get_property(DEVICE_TYPE_POWER, PROP_POWER_CAPACITY_RAW, &val); - if (ret < 0) - goto exit; - - if (val > 10000) - val = 10000; - - ret = val; - -exit: - reply = dbus_message_new_method_return(msg); - dbus_message_iter_init_append(reply, &iter); - dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); - return reply; -} - -static DBusMessage *edbus_is_full(E_DBus_Object *obj, DBusMessage *msg) -{ - DBusMessageIter iter; - DBusMessage *reply; - int ret; - - ret = battery.charge_full; - - reply = dbus_message_new_method_return(msg); - dbus_message_iter_init_append(reply, &iter); - dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); - return reply; -} - -static DBusMessage *edbus_get_health(E_DBus_Object *obj, DBusMessage *msg) -{ - DBusMessageIter iter; - DBusMessage *reply; - int ret; - - ret = battery.health; - - reply = dbus_message_new_method_return(msg); - dbus_message_iter_init_append(reply, &iter); - dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); - return reply; -} - -static const struct edbus_method edbus_methods[] = { - { "GetPercent", NULL, "i", edbus_get_percent }, - { "GetPercentRaw", NULL, "i", edbus_get_percent_raw }, - { "IsFull", NULL, "i", edbus_is_full }, - { "GetHealth", NULL, "i", edbus_get_health }, - /* Add methods here */ -}; - -/* battery ops init funcion */ -static void battery_init(void *data) -{ - int ret; - - /* init dbus interface */ - ret = register_edbus_method(DEVICED_PATH_BATTERY, - edbus_methods, ARRAY_SIZE(edbus_methods)); - if (ret < 0) - _E("fail to init edbus method(%d)", ret); - - /* get initial battery capacity */ - battery.capacity = get_capacity(); - battery.charge_now = POWER_SUPPLY_STATUS_UNKNOWN; - - /* register notifier */ - register_notifier(DEVICE_NOTIFIER_POWER_SUPPLY, update_battery); -} - -/* battery ops exit funcion */ -static void battery_exit(void *data) -{ - /* unregister notifier */ - unregister_notifier(DEVICE_NOTIFIER_POWER_SUPPLY, update_battery); -} - -static const struct device_ops battery_device_ops = { - .priority = DEVICE_PRIORITY_NORMAL, - .name = "battery", - .init = battery_init, - .exit = battery_exit, -}; - -DEVICE_OPS_REGISTER(&battery_device_ops) diff --git a/src/battery/config.h b/src/battery/config.h index 5f68716..6acd38f 100644 --- a/src/battery/config.h +++ b/src/battery/config.h @@ -20,5 +20,16 @@ #ifndef __BATTERY_CONFIG_H__ #define __BATTERY_CONFIG_H__ +#define BATTERY_FULL 100 +#define BATTERY_NORMAL BATTERY_FULL +#define BATTERY_WARNING 15 +#define BATTERY_CRITICAL 5 +#ifdef MICRO_DD +#define BATTERY_POWEROFF 3 +#else +#define BATTERY_POWEROFF 1 +#endif +#define BATTERY_REALOFF 0 + void battery_config_load(struct battery_config_info *info); #endif /* __BATTERY_CONFIG_H__ */ diff --git a/src/battery/lowbat-handler.c b/src/battery/lowbat-handler.c index 3d82613..cea6266 100644 --- a/src/battery/lowbat-handler.c +++ b/src/battery/lowbat-handler.c @@ -27,9 +27,6 @@ #include "config.h" #include "core/log.h" #include "core/launch.h" -#include "core/noti.h" -#include "core/queue.h" -#include "core/data.h" #include "core/devices.h" #include "core/device-handler.h" #include "core/device-notifier.h" @@ -40,9 +37,7 @@ #include "display/poll.h" #include "core/edbus-handler.h" #include "core/power-supply.h" - -#define PREDEF_LOWBAT "lowbat" -#define PREDEF_LOWBAT_CHANGE_FREQ "lowbat_change_freq" +#include "power/power-handler.h" #define CHARGE_POWERSAVE_FREQ_ACT "charge_powersave_freq_act" #define CHARGE_RELEASE_FREQ_ACT "charge_release_freq_act" @@ -50,7 +45,6 @@ #define BATTERY_CHARGING 65535 #define BATTERY_UNKNOWN -1 -#define BATTERY_FULL 100 #define WARNING_LOW_BAT_ACT "warning_low_bat_act" #define CRITICAL_LOW_BAT_ACT "critical_low_bat_act" @@ -86,7 +80,13 @@ static int cur_bat_capacity = -1; static int lowbat_popup_option = 0; static int lowbat_freq = -1; -static struct battery_config_info battery_info; +static struct battery_config_info battery_info = { + .normal = BATTERY_NORMAL, + .warning = BATTERY_WARNING, + .critical = BATTERY_CRITICAL, + .poweroff = BATTERY_POWEROFF, + .realoff = BATTERY_REALOFF, +}; static dd_list *lpe = NULL; static int scenario_count = 0; @@ -102,7 +102,7 @@ static int lowbat_initialized(void *data) return status; } -int lowbat_scenario(int old, int now, void *data) +static int lowbat_scenario(int old, int now, void *data) { dd_list *n; struct lowbat_process_entry *scenario; @@ -120,7 +120,7 @@ int lowbat_scenario(int old, int now, void *data) return found; } -int lowbat_add_scenario(int old, int now, int (*func)(void *data)) +static int lowbat_add_scenario(int old, int now, int (*func)(void *data)) { struct lowbat_process_entry *scenario; @@ -155,21 +155,143 @@ static void print_lowbat_state(unsigned int bat_percent) #endif } -int battery_check_act(void *data) +static int power_execute(void) +{ + static const struct device_ops *ops = NULL; + + FIND_DEVICE_INT(ops, POWER_OPS_NAME); + + return ops->execute(INTERNAL_PWROFF); +} + +static int booting_done(void *data) +{ + static int done = 0; + + if (data == NULL) + goto out; + done = (int)data; + if (!done) + goto out; + _I("booting done"); +out: + return done; +} + +static int lowbat_popup(char *option) +{ + static int launched_poweroff = 0; + static const struct device_ops *apps = NULL; + struct popup_data *params; + int ret, state=0; + int r_disturb, s_disturb, r_block, s_block; + char *value; + pid_t pid; + + if (!option) + return -1; + + if (strcmp(option, POWER_OFF_BAT_ACT)) + launched_poweroff = 0; + + if (!strcmp(option, CRITICAL_LOW_BAT_ACT)) { +#ifdef MICRO_DD + value = "lowbattery_critical"; +#else + value = "critical"; +#endif + lowbat_popup_option = LOWBAT_OPT_CHECK; + } else if (!strcmp(option, WARNING_LOW_BAT_ACT)) { + if (is_factory_mode() == 1) + return 0; +#ifdef MICRO_DD + value = "lowbattery_warning"; +#else + value = "warning"; +#endif + lowbat_popup_option = LOWBAT_OPT_WARNING; + } else if (!strcmp(option, POWER_OFF_BAT_ACT)) { + value = "poweroff"; + lowbat_popup_option = LOWBAT_OPT_POWEROFF; + } else if (!strcmp(option, CHARGE_ERROR_ACT)) { + value = "chargeerr"; + lowbat_popup_option = LOWBAT_OPT_CHARGEERR; + } else if (!strcmp(option, CHARGE_ERROR_LOW_ACT)) { + value = "chargeerrlow"; + lowbat_popup_option = LOWBAT_OPT_CHARGEERR; + } else if (!strcmp(option, CHARGE_ERROR_HIGH_ACT)) { + value = "chargeerrhigh"; + lowbat_popup_option = LOWBAT_OPT_CHARGEERR; + } else if (!strcmp(option, CHARGE_ERROR_OVP_ACT)) { + value = "chargeerrovp"; + lowbat_popup_option = LOWBAT_OPT_CHARGEERR; + } else if (!strcmp(option, CHARGE_CHECK_ACT)) { + launched_poweroff = 0; + return 0; + } else + return -1; + _D("%s", value); + ret = vconf_get_int(VCONFKEY_STARTER_SEQUENCE, &state); + if (state == 1 || ret != 0 || booting_done(NULL)) { + + if (launched_poweroff == 1) { + _I("will be foreced power off"); + power_execute(); + return 0; + } + + if (lowbat_popup_option == LOWBAT_OPT_POWEROFF) + launched_poweroff = 1; + + pid = get_exec_pid(LOWBAT_EXEC_PATH); + if (pid > 0) { + _I("pre launched %s destroy", LOWBAT_EXEC_PATH); + kill(pid, SIGTERM); + } + + FIND_DEVICE_INT(apps, "apps"); + + params = malloc(sizeof(struct popup_data)); + if (params == NULL) { + _E("Malloc failed"); + return -1; + } + r_disturb = vconf_get_int("memory/shealth/sleep/do_not_disturb", &s_disturb); + r_block = vconf_get_bool("db/setting/blockmode_wearable", &s_block); + if ((r_disturb != 0 && r_block != 0) || + (s_disturb == 0 && s_block == 0) || + lowbat_popup_option == LOWBAT_OPT_CHARGEERR) + pm_change_internal(getpid(), LCD_NORMAL); + else + _I("block LCD"); + params->name = LOWBAT_POPUP_NAME; + params->key = POPUP_KEY_CONTENT; + params->value = strdup(value); + apps->init((void *)params); + free(params->value); + free(params); + } else { + _D("boot-animation running yet"); + } + + return 0; +} + +static int battery_check_act(void *data) { - notify_action(PREDEF_LOWBAT, 1, CHARGE_CHECK_ACT); + lowbat_popup(CHARGE_CHECK_ACT); return 0; } -int battery_warning_low_act(void *data) +static int battery_warning_low_act(void *data) { - notify_action(PREDEF_LOWBAT, 1, WARNING_LOW_BAT_ACT); + lowbat_popup(WARNING_LOW_BAT_ACT); return 0; } -int battery_critical_low_act(void *data) +static int battery_critical_low_act(void *data) { - notify_action(PREDEF_LOWBAT, 1, CRITICAL_LOW_BAT_ACT); + lowbat_popup(CRITICAL_LOW_BAT_ACT); return 0; } @@ -181,25 +303,25 @@ int battery_power_off_act(void *data) int battery_charge_err_act(void *data) { - notify_action(PREDEF_LOWBAT, 1, CHARGE_ERROR_ACT); + lowbat_popup(CHARGE_ERROR_ACT); return 0; } int battery_charge_err_low_act(void *data) { - notify_action(PREDEF_LOWBAT, 1, CHARGE_ERROR_LOW_ACT); + lowbat_popup(CHARGE_ERROR_LOW_ACT); return 0; } int battery_charge_err_high_act(void *data) { - notify_action(PREDEF_LOWBAT, 1, CHARGE_ERROR_HIGH_ACT); + lowbat_popup(CHARGE_ERROR_HIGH_ACT); return 0; } int battery_charge_err_ovp_act(void *data) { - notify_action(PREDEF_LOWBAT, 1, CHARGE_ERROR_OVP_ACT); + lowbat_popup(CHARGE_ERROR_OVP_ACT); return 0; } @@ -222,10 +344,9 @@ static int battery_charge_act(void *data) static void lowbat_scenario_init(void) { lowbat_add_scenario(battery_info.normal, battery_info.warning, battery_warning_low_act); - lowbat_add_scenario(battery_info.warning, battery_info.critical, battery_warning_low_act); - lowbat_add_scenario(battery_info.critical, battery_info.poweroff, battery_critical_low_act); + lowbat_add_scenario(battery_info.warning, battery_info.critical, battery_critical_low_act); lowbat_add_scenario(battery_info.poweroff, battery_info.realoff, battery_power_off_act); - lowbat_add_scenario(battery_info.normal, battery_info.critical, battery_warning_low_act); + lowbat_add_scenario(battery_info.normal, battery_info.critical, battery_critical_low_act); lowbat_add_scenario(battery_info.warning, battery_info.poweroff, battery_critical_low_act); lowbat_add_scenario(battery_info.critical, battery_info.realoff, battery_power_off_act); lowbat_add_scenario(battery_info.normal, battery_info.poweroff, battery_critical_low_act); @@ -276,14 +397,16 @@ static int lowbat_process(int bat_percent, void *ad) int status = -1; bool low_bat = false; bool full_bat = false; +#ifdef MICRO_DD int extreme = 0; +#endif int result = 0; + int lock = -1; new_bat_capacity = bat_percent; if (new_bat_capacity < 0) return -EINVAL; change_lowbat_level(new_bat_capacity); - pm_lock_internal(INTERNAL_LOCK_BATTERY, LCD_OFF, STAY_CUR_STATE, 0); if (new_bat_capacity != cur_bat_capacity) { _D("[BAT_MON] cur = %d new = %d", cur_bat_capacity, new_bat_capacity); @@ -338,6 +461,7 @@ static int lowbat_process(int bat_percent, void *ad) if (status != -1) { + lock = pm_lock_internal(INTERNAL_LOCK_BATTERY, LCD_OFF, STAY_CUR_STATE, 0); ret = vconf_set_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, status); power_supply_broadcast(CHARGE_LEVEL_SIGNAL, status); if (update_pm_setting) @@ -348,12 +472,12 @@ static int lowbat_process(int bat_percent, void *ad) result = -EIO; goto exit; } - +#ifdef MICRO_DD if (vconf_get_int(VCONFKEY_PM_KEY_IGNORE, &extreme) == 0 && extreme == TRUE && (status > VCONFKEY_SYSMAN_BAT_POWER_OFF && status <= VCONFKEY_SYSMAN_BAT_FULL)) if (vconf_set_int(VCONFKEY_PM_KEY_IGNORE, FALSE) == 0) _I("release key ignore"); - +#endif if (new_bat_capacity <= battery_info.warning) low_bat = true; @@ -366,15 +490,17 @@ static int lowbat_process(int bat_percent, void *ad) cur_bat_state = battery_info.normal; result = lowbat_scenario(cur_bat_state, new_bat_state, NULL); if (result) - _I("cur_bat_state %d, new_bat_state %d", cur_bat_state, new_bat_state); + _I("cur %d, new %d(capacity %d)", + cur_bat_state, new_bat_state, bat_percent); cur_bat_state = new_bat_state; exit: - pm_unlock_internal(INTERNAL_LOCK_BATTERY, LCD_OFF, PM_SLEEP_MARGIN); + if (lock == 0) + pm_unlock_internal(INTERNAL_LOCK_BATTERY, LCD_OFF, PM_SLEEP_MARGIN); return result; } -static int lowbat_read() +static int lowbat_read(void) { int bat_percent, r; @@ -385,6 +511,19 @@ static int lowbat_read() return bat_percent; } +static int change_freq(char *option) +{ + int val = 0; + + if (!option) + return -1; + + if (!strcmp(option, CHARGE_POWERSAVE_FREQ_ACT)) + val = 1; + device_notify(DEVICE_NOTIFIER_PMQOS_LOWBAT, (void*)val); + return 0; +} + static void change_lowbat_cpu_freq(int bat_percent) { static int init_cpu_freq = 0; @@ -394,16 +533,16 @@ static void change_lowbat_cpu_freq(int bat_percent) if (bat_percent > battery_info.poweroff && init_cpu_freq == 0) { init_cpu_freq = 1; - notify_action(PREDEF_LOWBAT_CHANGE_FREQ, 1, CHARGE_RELEASE_FREQ_ACT); + change_freq(CHARGE_RELEASE_FREQ_ACT); return; } if (bat_percent <= battery_info.poweroff && power_save == 0) { power_save = 1; - notify_action(PREDEF_LOWBAT_CHANGE_FREQ, 1, CHARGE_POWERSAVE_FREQ_ACT); + change_freq(CHARGE_POWERSAVE_FREQ_ACT); } else if (power_save == 1) { power_save = 0; - notify_action(PREDEF_LOWBAT_CHANGE_FREQ, 1, CHARGE_RELEASE_FREQ_ACT); + change_freq(CHARGE_RELEASE_FREQ_ACT); } } @@ -456,107 +595,6 @@ static int check_battery() return ret; } -static int booting_done(void *data) -{ - static int done = 0; - - if (data == NULL) - goto out; - done = (int)data; - if (!done) - goto out; - _I("booting done"); -out: - return done; -} - -int lowbat_action(int argc, char **argv) -{ - int ret, state=0; - char argstr[128]; - char* option = NULL; - char *value; - static int launched_poweroff = 0; - pid_t pid; - struct popup_data *params; - static const struct device_ops *apps = NULL; - - if (argc < 1) - return -1; - - if (strcmp(argv[0], POWER_OFF_BAT_ACT)) - launched_poweroff = 0; - - if (!strcmp(argv[0], CRITICAL_LOW_BAT_ACT)) { - value = "extreme"; - lowbat_popup_option = LOWBAT_OPT_CHECK; - } else if (!strcmp(argv[0], WARNING_LOW_BAT_ACT)) { - if (is_factory_mode() == 1) - return 0; - value = "warning"; - lowbat_popup_option = LOWBAT_OPT_WARNING; - } else if (!strcmp(argv[0], POWER_OFF_BAT_ACT)) { - value = "poweroff"; - lowbat_popup_option = LOWBAT_OPT_POWEROFF; - } else if (!strcmp(argv[0], CHARGE_ERROR_ACT)) { - value = "chargeerr"; - lowbat_popup_option = LOWBAT_OPT_CHARGEERR; - } else if (!strcmp(argv[0], CHARGE_ERROR_LOW_ACT)) { - value = "chargeerrlow"; - lowbat_popup_option = LOWBAT_OPT_CHARGEERR; - } else if (!strcmp(argv[0], CHARGE_ERROR_HIGH_ACT)) { - value = "chargeerrhigh"; - lowbat_popup_option = LOWBAT_OPT_CHARGEERR; - } else if (!strcmp(argv[0], CHARGE_ERROR_OVP_ACT)) { - value = "chargeerrovp"; - lowbat_popup_option = LOWBAT_OPT_CHARGEERR; - } else if (!strcmp(argv[0], CHARGE_CHECK_ACT)) { - launched_poweroff = 0; - return 0; - } else - return -1; - _D("%s", value); - ret = vconf_get_int(VCONFKEY_STARTER_SEQUENCE, &state); - if (state == 1 || ret != 0 || booting_done(NULL)) { - - if (launched_poweroff == 1) { - _I("will be foreced power off"); - do_poweroff(0, NULL); - return 0; - } - - if (lowbat_popup_option == LOWBAT_OPT_POWEROFF) - launched_poweroff = 1; - - pid = predefine_get_pid(LOWBAT_EXEC_PATH); - if (pid > 0) { - _I("pre launched %s destroy", LOWBAT_EXEC_PATH); - kill(pid, SIGTERM); - } - if (apps == NULL) { - apps = find_device("apps"); - if (apps == NULL) - return 0; - } - params = malloc(sizeof(struct popup_data)); - if (params == NULL) { - _E("Malloc failed"); - return -1; - } - pm_change_internal(getpid(), LCD_NORMAL); - params->name = LOWBAT_POPUP_NAME; - params->key = POPUP_KEY_CONTENT; - params->value = strdup(value); - apps->init((void *)params); - free(params->value); - free(params); - } else { - _D("boot-animation running yet"); - } - - return 0; -} - static int check_power_save_mode(void) { int ret = 0; @@ -574,19 +612,6 @@ static int check_power_save_mode(void) return ret; } -int change_freq_action(int argc, char **argv) -{ - int val = 0; - - if (argc < 1) - return -1; - - if (!strcmp(argv[0], CHARGE_POWERSAVE_FREQ_ACT)) - val = 1; - device_notify(DEVICE_NOTIFIER_PMQOS_LOWBAT, (void*)val); - return 0; -} - static int lowbat_monitor_init(void *data) { int status = 1; @@ -597,8 +622,7 @@ static int lowbat_monitor_init(void *data) _I("%d %d %d %d %d", battery_info.normal, battery_info.warning, battery_info.critical, battery_info.poweroff, battery_info.realoff); lowbat_scenario_init(); - register_action(PREDEF_LOWBAT, lowbat_action, NULL, NULL); - register_action(PREDEF_LOWBAT_CHANGE_FREQ, change_freq_action, NULL, NULL); + check_lowbat_percent(&battery.capacity); lowbat_process(battery.capacity, NULL); return 0; } @@ -621,7 +645,7 @@ static const struct device_ops lowbat_device_ops = { .priority = DEVICE_PRIORITY_NORMAL, .name = "lowbat", .init = lowbat_init, - .exit = lowbat_exit, + .exit = lowbat_exit, }; DEVICE_OPS_REGISTER(&lowbat_device_ops) diff --git a/src/board/board-info.c b/src/board/board-info.c index 32b53f6..282aaf0 100644 --- a/src/board/board-info.c +++ b/src/board/board-info.c @@ -27,18 +27,28 @@ #define FILE_BUFF_MAX 1024 #define NOT_INITIALIZED (-1) +#define METHOD_GET_NUM "GetNum" #define METHOD_GET_SERIAL "GetSerial" #define SERIAL_PATH_NAME "/csa/imei/serialno.dat" #define METHOD_GET_REVISION "GetHWRev" #define PATH_NAME "/proc/cpuinfo" #define REVISION_NAME "Revision" +#define SERIAL_NAME "Serial" +#define SERIAL_TOK_DELIMITER "," #define TOK_DELIMITER ":" #define END_DELIMITER " \n" #define CONVERT_TYPE 10 #define REVISION_SIZE 4 +struct serial_info { + char serial[FILE_BUFF_MAX]; + char num[FILE_BUFF_MAX]; +}; + +static struct serial_info info; + static int read_from_file(const char *path, char *buf, size_t size) { int fd; @@ -111,6 +121,36 @@ static int get_revision(char *rev) return 0; } +static int get_cpuinfo_serial(void) +{ + char buf[FILE_BUFF_MAX]; + char *tag; + char *start, *ptr; + + if (read_from_file(PATH_NAME, buf, FILE_BUFF_MAX) < 0) { + _E("fail to read %s\n", PATH_NAME); + return -1; + } + + tag = strstr(buf, SERIAL_NAME); + if (tag == NULL) { + _E("cannot find Hardware in %s\n", PATH_NAME); + return -1; + } + + start = strstr(tag, TOK_DELIMITER); + if (start == NULL) { + _E("cannot find Hardware in %s\n", PATH_NAME); + return -1; + } + + start ++; + ptr = strtok(start, END_DELIMITER); + strncpy(info.serial, ptr, strlen(ptr)); + _D("%s", info.serial); + return 0; +} + static DBusMessage *dbus_revision_handler(E_DBus_Object *obj, DBusMessage *msg) { DBusMessageIter iter; @@ -133,22 +173,78 @@ out: return reply; } -static int get_serial(unsigned char *buf) +static int get_serial(void) { + static int ret = -EIO; int fd; int r; - int ret = 0; + char *tag; + char *serial; + char buf[FILE_BUFF_MAX]; + + if (ret == 0) + return ret; fd = open(SERIAL_PATH_NAME, O_RDONLY, 0); if (fd < 0) return -ENOENT; r = read(fd, buf, FILE_BUFF_MAX); - if ((r >= 0) && (r < FILE_BUFF_MAX)) - buf[r] = '\0'; - else - ret = -EIO; + if (r < 0 || r >= FILE_BUFF_MAX) + goto out; + buf[r] = '\0'; + tag = buf; + serial = strstr(buf, SERIAL_TOK_DELIMITER); + if (serial) { + serial = strtok(tag, SERIAL_TOK_DELIMITER); + if (!serial) + goto out; + r = strlen(serial); + strncpy(info.serial, serial, r); + } else { + strncpy(info.serial, buf, r); + } + _D("%s %d", info.serial, r); + ret = 0; +out: + close(fd); + return ret; +} + +static int get_num(void) +{ + static int ret = -EIO; + int fd; + int r; + char *tag; + char *num; + char buf[FILE_BUFF_MAX]; + + if (ret == 0) + return ret; + + fd = open(SERIAL_PATH_NAME, O_RDONLY, 0); + if (fd < 0) + return -ENOENT; + r = read(fd, buf, FILE_BUFF_MAX); + if (r < 0 || r >= FILE_BUFF_MAX) + goto out; + buf[r] = '\0'; + num = strstr(buf, SERIAL_TOK_DELIMITER); + if (!num) + goto out; + tag = buf; + strtok(tag, SERIAL_TOK_DELIMITER); + strtok(NULL, SERIAL_TOK_DELIMITER); + num = strtok(NULL, END_DELIMITER); + if (!num) + goto out; + r = strlen(num); + strncpy(info.num, num, r); + _D("%s %d", info.num, r); + ret = 0; +out: close(fd); return ret; } @@ -158,20 +254,46 @@ static DBusMessage *dbus_serial_handler(E_DBus_Object *obj, DBusMessage *msg) DBusMessageIter iter, arr; DBusMessage *reply; static int len = 0; + static int ret = NOT_INITIALIZED; + char buf[FILE_BUFF_MAX]; + char *param = buf; + + ret = get_serial(); + if (ret < 0) + ret = get_cpuinfo_serial(); + if (ret == 0) { + len = strlen(info.serial); + strncpy(buf, info.serial, len); + _D("%s %d", buf, len); + goto out; + } + _E("fail to get serial"); +out: + reply = dbus_message_new_method_return(msg); + dbus_message_iter_init_append(reply, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, ¶m); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); + return reply; +} + +static DBusMessage *dbus_num_handler(E_DBus_Object *obj, DBusMessage *msg) +{ + DBusMessageIter iter, arr; + DBusMessage *reply; + static int len = 0; static char buf[FILE_BUFF_MAX]; static char *param = buf; static int ret = NOT_INITIALIZED; - if (ret == 0) - goto out; - ret = get_serial(buf); + ret = get_num(); if (ret == 0) { - len = strlen(buf); + len = strlen(info.num); + strncpy(buf, info.num, len); + _D("%s %d", buf, len); goto out; } - _E("fail to get serial"); + _E("fail to get num"); out: - _D("serial : %s %d", buf, len); reply = dbus_message_new_method_return(msg); dbus_message_iter_init_append(reply, &iter); dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, ¶m); @@ -182,6 +304,7 @@ out: static const struct edbus_method edbus_methods[] = { { METHOD_GET_SERIAL, NULL, "si", dbus_serial_handler }, { METHOD_GET_REVISION, NULL, "i", dbus_revision_handler }, + { METHOD_GET_NUM, NULL, "si", dbus_num_handler }, }; static void board_init(void *data) @@ -191,6 +314,12 @@ static void board_init(void *data) ret = register_edbus_method(DEVICED_PATH_BOARD, edbus_methods, ARRAY_SIZE(edbus_methods)); if (ret < 0) _E("fail to init edbus method(%d)", ret); + ret = get_serial(); + if (ret < 0) + _E("fail to get serial info(%d)", ret); + ret = get_num(); + if (ret < 0) + _E("fail to get num info(%d)", ret); } static const struct device_ops board_device_ops = { diff --git a/src/control/control.c b/src/control/control.c index dcb21a9..de90abb 100644 --- a/src/control/control.c +++ b/src/control/control.c @@ -48,7 +48,7 @@ static int control_handler(int argc, char **argv) int device; bool enable; int ret; - const struct device_ops *dev_ops; + const struct device_ops *dev_ops = NULL; _I("argc : %d", argc); for (i = 0; i < argc; ++i) @@ -71,11 +71,7 @@ static int control_handler(int argc, char **argv) if (i >= ARRAY_SIZE(devices)) return -EINVAL; - - dev_ops = find_device(devices[i].name); - if (!dev_ops) - return -ENODEV; - + FIND_DEVICE_INT(dev_ops, devices[i].name); if (enable) ret = device_start(dev_ops); else @@ -91,7 +87,7 @@ static int get_control_handler(int argc, char **argv) int device; bool enable; int ret; - const struct device_ops *dev_ops; + const struct device_ops *dev_ops = NULL; _I("argc : %d", argc); for (i = 0; i < argc; ++i) @@ -114,9 +110,7 @@ static int get_control_handler(int argc, char **argv) if (i >= ARRAY_SIZE(devices)) return -EINVAL; - dev_ops = find_device(devices[i].name); - if (!dev_ops) - return -ENODEV; + FIND_DEVICE_INT(dev_ops, devices[i].name); return device_get_status(dev_ops); } @@ -225,8 +219,6 @@ static void control_init(void *data) ret = register_edbus_method(DEVICED_PATH_SYSNOTI, edbus_methods, ARRAY_SIZE(edbus_methods)); if (ret < 0) _E("fail to init edbus method(%d)", ret); - - register_action(CONTROL_HANDLER_NAME, control_handler, NULL, NULL); } static const struct device_ops control_device_ops = { diff --git a/src/cool-down/cool-down-micro.c b/src/cool-down/cool-down-micro.c new file mode 100644 index 0000000..e15ac05 --- /dev/null +++ b/src/cool-down/cool-down-micro.c @@ -0,0 +1,436 @@ +/* + * deviced + * + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "core/log.h" +#include "core/common.h" +#include "core/devices.h" +#include "core/device-notifier.h" +#include "core/edbus-handler.h" +#include "core/config-parser.h" +#include "core/udev.h" +#include "hall/hall-handler.h" +#include "display/poll.h" + +#define COOL_DOWN_DBUS_INTERFACE "org.tizen.trm.siop" +#define COOL_DOWN_DBUS_PATH "/Org/Tizen/Trm/Siop" +#define COOL_DOWN_DBUS_SIGNAL "ChangedCooldownMode" + +#define COOL_DOWN_POPUP_NAME "cooldown-syspopup" + +#define SIGNAL_COOL_DOWN_SHUT_DOWN "ShutDown" +#define SIGNAL_COOL_DOWN_LIMIT_ACTION "LimitAction" +#define SIGNAL_COOL_DOWN_WARNING_ACTION "WarningAction" +#define SIGNAL_COOL_DOWN_RELEASE "Release" +#define SIGNAL_COOL_DOWN_RESPONSE "CoolDownResponse" + +#define METHOD_COOL_DOWN_STATUS "GetCoolDownStatus" +#define METHOD_COOL_DOWN_CHANGED "CoolDownChanged" + +#define SIGNAL_STRING_MAX_LEN 30 + +#define COOL_DOWN_LIMIT_ACTION_WAIT 60 +#define COOL_DOWN_SHUTDOWN_POPUP_WAIT 60 +#define COOL_DOWN_SHUTDOWN_FORCE_WAIT 30 +#define SYSTEMD_STOP_POWER_OFF 4 + +#define VCONFKEY_SYSMAN_COOL_DOWN_MODE "db/private/sysman/cool_down_mode" + +enum cool_down_status_type { + COOL_DOWN_NONE_INIT, + COOL_DOWN_RELEASE, + COOL_DOWN_WARNING_ACTION, + COOL_DOWN_LIMIT_ACTION, + COOL_DOWN_SHUT_DOWN, +}; + +struct popup_data { + char *name; + char *key; +}; + +static int cool_down_level = 0; +static const char *cool_down_status = NULL; +static const struct device_ops *hall_ic = NULL; +static int cool_down_lock = 0; + +static int hall_ic_status(void) +{ + int ret; + + ret = device_get_status(hall_ic); + if (ret < 0) + return HALL_IC_OPENED; + return ret; +} + +static int telephony_execute(void *data) +{ + static const struct device_ops *ops = NULL; + int mode = *(int *)data; + int old = 0; + + vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &old); + if ((old == 0 && mode == 1) || + (old == 1 && mode == 0)) + return 0; + + FIND_DEVICE_INT(ops, "telephony"); + + return ops->execute(data); +} + +static void flight_mode_off(void) +{ + int mode = 1; + + telephony_execute(&mode); +} + +static void flight_mode_on(void) +{ + int mode = 0; + + telephony_execute(&mode); +} + +static int cool_down_popup(char *type) +{ + struct popup_data *params; + static const struct device_ops *apps = NULL; + int val; + + val = hall_ic_status(); + if (val == HALL_IC_CLOSED) { + _I("cover is closed"); + return 0; + } + + FIND_DEVICE_INT(apps, "apps"); + + params = malloc(sizeof(struct popup_data)); + if (params == NULL) { + _E("Malloc failed"); + return -1; + } + cool_down_lock = 1; + pm_change_internal(getpid(), LCD_NORMAL); + pm_lock_internal(INTERNAL_LOCK_COOL_DOWN, LCD_OFF, STAY_CUR_STATE, 0); + params->name = COOL_DOWN_POPUP_NAME; + params->key = type; + apps->init((void *)params); + free(params); + return 0; +} + +static void broadcast_cool_down_status(int status) +{ + int ret; + char buf[SIGNAL_STRING_MAX_LEN]; + char *param[1]; + static int old = COOL_DOWN_NONE_INIT; + + if (old == status) + return; + + old = status; + if (cool_down_lock) { + cool_down_lock = 0; + pm_unlock_internal(INTERNAL_LOCK_COOL_DOWN, LCD_OFF, STAY_CUR_STATE); + } + + switch(status) + { + case COOL_DOWN_RELEASE: + cool_down_status = SIGNAL_COOL_DOWN_RELEASE; + break; + case COOL_DOWN_WARNING_ACTION: + cool_down_status = SIGNAL_COOL_DOWN_WARNING_ACTION; + break; + case COOL_DOWN_LIMIT_ACTION: + cool_down_status = SIGNAL_COOL_DOWN_LIMIT_ACTION; + break; + case COOL_DOWN_SHUT_DOWN: + return; + default: + _E("abnormal value %d", status); + return; + } + + snprintf(buf, SIGNAL_STRING_MAX_LEN, "%s", cool_down_status); + param[0] = buf; + + broadcast_edbus_signal(DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI, + METHOD_COOL_DOWN_CHANGED, "s", param); + device_notify(DEVICE_NOTIFIER_COOL_DOWN, (void *)status); + _I("%s", cool_down_status); +} + +static int cool_down_booting_done(void *data) +{ + static int done = 0; + int mode; + int ret; + + if (data == NULL) + goto out; + + done = (int)data; + + switch (cool_down_level) + { + case COOL_DOWN_RELEASE: + broadcast_cool_down_status(COOL_DOWN_RELEASE); + break; + case COOL_DOWN_WARNING_ACTION: + broadcast_cool_down_status(COOL_DOWN_WARNING_ACTION); + break; + case COOL_DOWN_LIMIT_ACTION: + flight_mode_on(); + broadcast_cool_down_status(COOL_DOWN_LIMIT_ACTION); + break; + case COOL_DOWN_SHUT_DOWN: + cool_down_popup(SIGNAL_COOL_DOWN_SHUT_DOWN); + break; + default: + _E("abnormal value %d", cool_down_level); + break; + } +out: + return done; +} + +static int cool_down_execute(void *data) +{ + int booting_done; + static int old = COOL_DOWN_NONE_INIT; + + cool_down_level = *(int *)data; + if (old == cool_down_level) + return 0; + _I("status %d", cool_down_level); + booting_done = cool_down_booting_done(NULL); + if (!booting_done) + return 0; + vconf_set_int(VCONFKEY_SYSMAN_COOL_DOWN_MODE, cool_down_level); + old = cool_down_level; + + switch (cool_down_level) + { + case COOL_DOWN_RELEASE: + flight_mode_off(); + broadcast_cool_down_status(COOL_DOWN_RELEASE); + break; + case COOL_DOWN_WARNING_ACTION: + broadcast_cool_down_status(COOL_DOWN_WARNING_ACTION); + break; + case COOL_DOWN_LIMIT_ACTION: + cool_down_popup(SIGNAL_COOL_DOWN_LIMIT_ACTION); + break; + case COOL_DOWN_SHUT_DOWN: + cool_down_popup(SIGNAL_COOL_DOWN_SHUT_DOWN); + break; + } + return 0; +} + +static int changed_device(int level) +{ + int *state = NULL; + int status = level; + + state = &status; + cool_down_execute((void *)state); +out: + return 0; +} + +static void cool_down_popup_response_signal_handler(void *data, DBusMessage *msg) +{ + flight_mode_on(); + broadcast_cool_down_status(COOL_DOWN_LIMIT_ACTION); +} + +static int get_action_id(char *action) +{ + int val; + + if (MATCH(action, SIGNAL_COOL_DOWN_RELEASE)) + val = COOL_DOWN_RELEASE; + else if (MATCH(action, SIGNAL_COOL_DOWN_WARNING_ACTION)) + val = COOL_DOWN_WARNING_ACTION; + else if (MATCH(action, SIGNAL_COOL_DOWN_LIMIT_ACTION)) + val = COOL_DOWN_LIMIT_ACTION; + else if (MATCH(action, SIGNAL_COOL_DOWN_SHUT_DOWN)) + val = COOL_DOWN_SHUT_DOWN; + else + val = -EINVAL; + + return val; +} + +static void cool_down_edbus_signal_handler(void *data, DBusMessage *msg) +{ + DBusError err; + int val; + char *action; + + if (dbus_message_is_signal(msg, COOL_DOWN_DBUS_INTERFACE, COOL_DOWN_DBUS_SIGNAL) == 0) { + _E("there is no cool down signal"); + return; + } + + dbus_error_init(&err); + + if (dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &action, DBUS_TYPE_INVALID) == 0) { + _E("there is no message"); + return; + } + + val = get_action_id(action); + + if (val < 0) + _E("Invalid argument! %s", action); + else + changed_device(val); +} + +static DBusMessage *dbus_get_status(E_DBus_Object *obj, DBusMessage *msg) +{ + DBusMessageIter iter; + DBusMessage *reply; + char buf[SIGNAL_STRING_MAX_LEN]; + char *param = buf; + + switch(cool_down_level) + { + case COOL_DOWN_SHUT_DOWN: + cool_down_status = SIGNAL_COOL_DOWN_SHUT_DOWN; + break; + case COOL_DOWN_LIMIT_ACTION: + cool_down_status = SIGNAL_COOL_DOWN_LIMIT_ACTION; + break; + default: + cool_down_status = SIGNAL_COOL_DOWN_RELEASE; + break; + } + + snprintf(buf, SIGNAL_STRING_MAX_LEN, "%s", cool_down_status); + reply = dbus_message_new_method_return(msg); + dbus_message_iter_init_append(reply, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, ¶m); + return reply; +} + +static DBusMessage *dbus_device_handler(E_DBus_Object *obj, DBusMessage *msg) +{ + DBusError err; + DBusMessageIter iter; + DBusMessage *reply; + pid_t pid; + int ret = 0; + int val; + int argc; + char *type_str; + char *argv[2]; + + dbus_error_init(&err); + + if (!dbus_message_get_args(msg, &err, + DBUS_TYPE_STRING, &type_str, + DBUS_TYPE_INT32, &argc, + DBUS_TYPE_STRING, &argv[0], + DBUS_TYPE_STRING, &argv[1], DBUS_TYPE_INVALID)) { + _E("there is no message"); + ret = -EINVAL; + goto out; + } + + if (argc < 0 || !argv[0] || !argv[1]){ + _E("message is invalid!"); + ret = -EINVAL; + goto out; + } + + pid = get_edbus_sender_pid(msg); + if (kill(pid, 0) == -1) { + _E("%d process does not exist, dbus ignored!", pid); + ret = -ESRCH; + goto out; + } + + val = get_action_id(argv[1]); + + if (val < 0) { + _E("Invalid argument! %s", argv[1]); + ret = val; + } else { + changed_device(val); + } + +out: + reply = dbus_message_new_method_return(msg); + dbus_message_iter_init_append(reply, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); + + return reply; +} + +static const struct edbus_method edbus_methods[] = { + { METHOD_COOL_DOWN_STATUS, NULL, "s", dbus_get_status }, + { METHOD_COOL_DOWN_CHANGED, "siss", "i", dbus_device_handler }, +}; + +static void cool_down_init(void *data) +{ + int ret; + + ret = register_edbus_method(DEVICED_PATH_SYSNOTI, edbus_methods, ARRAY_SIZE(edbus_methods)); + if (ret < 0) + _E("fail to init edbus method(%d)", ret); + register_edbus_signal_handler(COOL_DOWN_DBUS_PATH, COOL_DOWN_DBUS_INTERFACE, + COOL_DOWN_DBUS_SIGNAL, + cool_down_edbus_signal_handler); + register_edbus_signal_handler(DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI, + SIGNAL_COOL_DOWN_RESPONSE, + cool_down_popup_response_signal_handler); + register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, cool_down_booting_done); + hall_ic = find_device(HALL_IC_NAME); +} + +static const struct device_ops cool_down_device_ops = { + .priority = DEVICE_PRIORITY_NORMAL, + .name = "cool-down", + .init = cool_down_init, + .execute = cool_down_execute, +}; + +DEVICE_OPS_REGISTER(&cool_down_device_ops) diff --git a/src/cool-down/cool-down.c b/src/cool-down/cool-down.c new file mode 100644 index 0000000..c8b10c8 --- /dev/null +++ b/src/cool-down/cool-down.c @@ -0,0 +1,417 @@ +/* + * deviced + * + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "core/log.h" +#include "core/common.h" +#include "core/devices.h" +#include "core/device-notifier.h" +#include "core/edbus-handler.h" +#include "core/udev.h" +#include "hall/hall-handler.h" + +#define COOL_DOWN_DBUS_INTERFACE "org.tizen.trm.siop" +#define COOL_DOWN_DBUS_PATH "/Org/Tizen/Trm/Siop" +#define COOL_DOWN_DBUS_SIGNAL "ChangedCooldownMode" + +#define COOL_DOWN_POPUP_NAME "cooldown-syspopup" + +#define SIGNAL_COOL_DOWN_SHUT_DOWN "ShutDown" +#define SIGNAL_COOL_DOWN_NOTIFICATION "Notification" +#define SIGNAL_COOL_DOWN_LIMIT_ACTION "LimitAction" +#define SIGNAL_COOL_DOWN_RELEASE "Release" + +#define METHOD_COOL_DOWN_STATUS "GetCoolDownStatus" +#define METHOD_COOL_DOWN_CHANGED "CoolDownChanged" + +#define SIGNAL_STRING_MAX_LEN 30 + +#define COOL_DOWN_LIMIT_ACTION_WAIT 60 +#define COOL_DOWN_SHUTDOWN_POPUP_WAIT 60 +#define COOL_DOWN_SHUTDOWN_FORCE_WAIT 30 +#define SYSTEMD_STOP_POWER_OFF 4 + +#define VCONFKEY_SYSMAN_COOL_DOWN_MODE "db/private/sysman/cool_down_mode" + +enum cool_down_status_type { + COOL_DOWN_RELEASE = 0, + COOL_DOWN_NOTIFICATION = 1, + COOL_DOWN_SHUT_DOWN = 2, +}; + +enum cool_down_timer_type { + COOL_DOWN_LIMIT_ACTION_TIMER = 1, + COOL_DOWN_POPUP_TIMER = 2, + COOL_DOWN_SHUT_DOWN_TIMER = 3, +}; + +enum cool_down_timer_status { + COOL_DOWN_TIMER_DELETED_ALREADY = 0, + COOL_DOWN_TIMER_DELETED_NOW = 1, +}; + +struct popup_data { + char *name; + char *key; +}; + +static int cool_down_level = 0; +static const char *cool_down_status = NULL; +static Ecore_Timer *app_limit_timer = NULL; +static Ecore_Timer *shut_down_timer = NULL; +static const struct device_ops *hall_ic = NULL; + +static void cool_down_timer_start(int type); +static int cool_down_timer_stop(int type); + +static int hall_ic_status(void) +{ + int ret; + + ret = device_get_status(hall_ic); + if (ret < 0) + return HALL_IC_OPENED; + return ret; +} + +static int cool_down_popup(char *type) +{ + struct popup_data *params; + static const struct device_ops *apps = NULL; + int val; + + val = hall_ic_status(); + if (val == HALL_IC_CLOSED) { + _I("cover is closed"); + return 0; + } + + FIND_DEVICE_INT(apps, "apps"); + + params = malloc(sizeof(struct popup_data)); + if (params == NULL) { + _E("Malloc failed"); + return -1; + } + params->name = COOL_DOWN_POPUP_NAME; + params->key = type; + apps->init((void *)params); + free(params); + return 0; +} + +static Eina_Bool broadcast_cool_down_limit_action(void *data) +{ + char buf[SIGNAL_STRING_MAX_LEN]; + char *param[1]; + + cool_down_timer_stop(COOL_DOWN_LIMIT_ACTION_TIMER); + + cool_down_status = SIGNAL_COOL_DOWN_LIMIT_ACTION; + snprintf(buf, SIGNAL_STRING_MAX_LEN, "%s", cool_down_status); + param[0] = buf; + + broadcast_edbus_signal(DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI, + METHOD_COOL_DOWN_CHANGED, "s", param); + _I("%s", SIGNAL_COOL_DOWN_LIMIT_ACTION); + return EINA_FALSE; +} + +static Eina_Bool cool_down_shutdown_popup(void *data) +{ + cool_down_popup(SIGNAL_COOL_DOWN_SHUT_DOWN); + cool_down_timer_start(COOL_DOWN_SHUT_DOWN_TIMER); + return EINA_FALSE; +} + +static Eina_Bool cool_down_shutdown_force(void *data) +{ + cool_down_timer_stop(COOL_DOWN_SHUT_DOWN_TIMER); + vconf_set_int(VCONFKEY_SYSMAN_COOL_DOWN_MODE, COOL_DOWN_SHUT_DOWN); + vconf_set_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, SYSTEMD_STOP_POWER_OFF); + return EINA_FALSE; +} + +static int cool_down_timer_stop(int type) +{ + if (type == COOL_DOWN_NOTIFICATION) { + if (!app_limit_timer) + return COOL_DOWN_TIMER_DELETED_ALREADY; + ecore_timer_del(app_limit_timer); + app_limit_timer = NULL; + } else if (type == COOL_DOWN_POPUP_TIMER || + type == COOL_DOWN_SHUT_DOWN_TIMER) { + if (!shut_down_timer) + return COOL_DOWN_TIMER_DELETED_ALREADY; + ecore_timer_del(shut_down_timer); + shut_down_timer = NULL; + } + _D("stop %d", type); + return COOL_DOWN_TIMER_DELETED_NOW; +} + +static void cool_down_timer_start(int type) +{ + cool_down_timer_stop(type); + if (type == COOL_DOWN_LIMIT_ACTION_TIMER) { + app_limit_timer = ecore_timer_add(COOL_DOWN_LIMIT_ACTION_WAIT, + broadcast_cool_down_limit_action, NULL); + if (!app_limit_timer) + _E("fail to add timer"); + } else if (type == COOL_DOWN_POPUP_TIMER) { + shut_down_timer = ecore_timer_add(COOL_DOWN_SHUTDOWN_POPUP_WAIT, + cool_down_shutdown_popup, NULL); + if (!shut_down_timer) + _E("fail to add timer"); + } else if (type == COOL_DOWN_SHUT_DOWN_TIMER) { + shut_down_timer = ecore_timer_add(COOL_DOWN_SHUTDOWN_FORCE_WAIT, + cool_down_shutdown_force, NULL); + if (!shut_down_timer) + _E("fail to add timer"); + } + _D("start %d", type); +} + +static void broadcast_cool_down_status(int status) +{ + int ret; + char buf[SIGNAL_STRING_MAX_LEN]; + char *param[1]; + + switch(status) + { + case COOL_DOWN_RELEASE: + cool_down_status = SIGNAL_COOL_DOWN_RELEASE; + cool_down_timer_stop(COOL_DOWN_SHUT_DOWN_TIMER); + cool_down_timer_stop(COOL_DOWN_POPUP_TIMER); + cool_down_timer_stop(COOL_DOWN_LIMIT_ACTION_TIMER); + break; + case COOL_DOWN_NOTIFICATION: + cool_down_status = SIGNAL_COOL_DOWN_NOTIFICATION; + cool_down_timer_stop(COOL_DOWN_SHUT_DOWN_TIMER); + cool_down_timer_stop(COOL_DOWN_POPUP_TIMER); + cool_down_timer_start(COOL_DOWN_LIMIT_ACTION_TIMER); + break; + case COOL_DOWN_SHUT_DOWN: + ret = cool_down_timer_stop(COOL_DOWN_LIMIT_ACTION_TIMER); + if (ret == COOL_DOWN_TIMER_DELETED_NOW) + broadcast_cool_down_limit_action(NULL); + cool_down_status = SIGNAL_COOL_DOWN_SHUT_DOWN; + cool_down_timer_start(COOL_DOWN_POPUP_TIMER); + break; + default: + _E("abnormal value %d", status); + return; + } + + snprintf(buf, SIGNAL_STRING_MAX_LEN, "%s", cool_down_status); + param[0] = buf; + + broadcast_edbus_signal(DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI, + METHOD_COOL_DOWN_CHANGED, "s", param); + device_notify(DEVICE_NOTIFIER_COOL_DOWN, (void *)status); + _I("%s", cool_down_status); +} + +static int cool_down_booting_done(void *data) +{ + static int done = 0; + int mode; + int ret; + + if (data == NULL) + goto out; + + done = (int)data; + if (cool_down_level) { + if (cool_down_level == COOL_DOWN_SHUT_DOWN) { + broadcast_cool_down_status(COOL_DOWN_NOTIFICATION); + broadcast_cool_down_limit_action(NULL); + cool_down_timer_start(COOL_DOWN_POPUP_TIMER); + goto out; + } + broadcast_cool_down_status(cool_down_level); + goto out; + } + ret = vconf_get_int(VCONFKEY_SYSMAN_COOL_DOWN_MODE, &mode); + vconf_set_int(VCONFKEY_SYSMAN_COOL_DOWN_MODE, cool_down_level); + if (ret == 0 && mode == COOL_DOWN_SHUT_DOWN) + cool_down_popup(SIGNAL_COOL_DOWN_RELEASE); +out: + return done; +} + +static int cool_down_execute(void *data) +{ + int booting_done; + static int old = COOL_DOWN_RELEASE; + + cool_down_level = *(int *)data; + if (old == cool_down_level) + return 0; + _I("status %d", cool_down_level); + + booting_done = cool_down_booting_done(NULL); + if (!booting_done) + return 0; + + if (old == COOL_DOWN_RELEASE && + cool_down_level == COOL_DOWN_SHUT_DOWN) { + old = cool_down_level; + broadcast_cool_down_status(COOL_DOWN_NOTIFICATION); + broadcast_cool_down_limit_action(NULL); + cool_down_timer_start(COOL_DOWN_POPUP_TIMER); + return 0; + } + old = cool_down_level; + broadcast_cool_down_status(cool_down_level); + return 0; +} + +static int changed_device(int level) +{ + int *state = NULL; + int status = level; + + state = &status; + cool_down_execute((void *)state); +out: + return 0; +} + +static void cool_down_edbus_signal_handler(void *data, DBusMessage *msg) +{ + DBusError err; + int val = 0; + + if (dbus_message_is_signal(msg, COOL_DOWN_DBUS_INTERFACE, COOL_DOWN_DBUS_SIGNAL) == 0) { + _E("there is no cool down signal"); + return; + } + + dbus_error_init(&err); + + if (dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID) == 0) { + _E("there is no message"); + return; + } + changed_device(val); +} + +static DBusMessage *dbus_get_status(E_DBus_Object *obj, DBusMessage *msg) +{ + DBusMessageIter iter; + DBusMessage *reply; + char buf[SIGNAL_STRING_MAX_LEN]; + char *param = buf; + + snprintf(buf, SIGNAL_STRING_MAX_LEN, "%s", cool_down_status); + reply = dbus_message_new_method_return(msg); + dbus_message_iter_init_append(reply, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, ¶m); + return reply; +} + +static DBusMessage *dbus_device_handler(E_DBus_Object *obj, DBusMessage *msg) +{ + DBusError err; + DBusMessageIter iter; + DBusMessage *reply; + pid_t pid; + int ret; + int val; + int argc; + char *type_str; + char *argv[2]; + + dbus_error_init(&err); + + if (!dbus_message_get_args(msg, &err, + DBUS_TYPE_STRING, &type_str, + DBUS_TYPE_INT32, &argc, + DBUS_TYPE_STRING, &argv[0], + DBUS_TYPE_STRING, &argv[1], DBUS_TYPE_INVALID)) { + _E("there is no message"); + ret = -EINVAL; + goto out; + } + + if (argc < 0 || !argv[0] || !argv[1]){ + _E("message is invalid!"); + ret = -EINVAL; + goto out; + } + + pid = get_edbus_sender_pid(msg); + if (kill(pid, 0) == -1) { + _E("%d process does not exist, dbus ignored!", pid); + ret = -ESRCH; + goto out; + } + + val = atoi(argv[1]); + changed_device(val); + +out: + reply = dbus_message_new_method_return(msg); + dbus_message_iter_init_append(reply, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); + + return reply; +} + +static const struct edbus_method edbus_methods[] = { + { METHOD_COOL_DOWN_STATUS, NULL, "s", dbus_get_status }, + { METHOD_COOL_DOWN_CHANGED, "siss", "i", dbus_device_handler }, +}; + +static void cool_down_init(void *data) +{ + int ret; + + ret = register_edbus_method(DEVICED_PATH_SYSNOTI, edbus_methods, ARRAY_SIZE(edbus_methods)); + if (ret < 0) + _E("fail to init edbus method(%d)", ret); + register_edbus_signal_handler(COOL_DOWN_DBUS_PATH, COOL_DOWN_DBUS_INTERFACE, + COOL_DOWN_DBUS_SIGNAL, + cool_down_edbus_signal_handler); + register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, cool_down_booting_done); + hall_ic = find_device(HALL_IC_NAME); +} + +static const struct device_ops cool_down_device_ops = { + .priority = DEVICE_PRIORITY_NORMAL, + .name = "cool-down", + .init = cool_down_init, + .execute = cool_down_execute, +}; + +DEVICE_OPS_REGISTER(&cool_down_device_ops) diff --git a/src/core/buxton-helper.c b/src/core/buxton-helper.c new file mode 100644 index 0000000..2d14a3c --- /dev/null +++ b/src/core/buxton-helper.c @@ -0,0 +1,257 @@ +/* + * deviced + * + * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +/* + * @file buxton-helper.c + * + * @desc Helper function for simplification of using and + * for looking like vconf interface + * + * + * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + */ + +#include +#include +#include +#include + +#include "buxton-helper.h" +#include "log.h" +#include "common.h" + +#define BUXTON_ATTEMPT_NUMBER 5 + +static BuxtonClient client; + +struct callback_context { + struct buxton_variant *b_variant; + int error_code; +}; + +void general_get_callback(BuxtonResponse response, void *data) +{ + BuxtonKey key; + struct buxton_variant *b_variant; + struct callback_context *context; + void *p; + uint32_t ret; + BuxtonDataType key_type; + + ret_msg_if(data == NULL, + "Invalid pointer argument!"); + context = (struct callback_context *)data; + ret_msg_if(context->b_variant == NULL, + "Invalid b_variant argument!"); + + b_variant = context->b_variant; + context->error_code = -1; + + ret = buxton_response_status(response); + ret_msg_if(ret, "Invalid buxton response"); + + p = buxton_response_value(response); + + ret_msg_if(p == NULL, "Bad buxton response: %s", strerror(errno)); + + key = buxton_response_key(response); + if (!key) { + free(p); + return; + } + + key_type = buxton_key_get_type(key); + if(key_type != b_variant->type) { + _E("Not proper type"); + goto out; + } + + switch (key_type) { + case STRING: + b_variant->string_value = (char *)p; + break; + case INT32: + b_variant->int32_value = *(int32_t *)p; + break; + case UINT32: + b_variant->uint32_value = *(uint32_t *)p; + break; + case INT64: + b_variant->int64_value = *(int64_t *)p; + break; + case UINT64: + b_variant->uint64_value = *(uint64_t *)p; + break; + case FLOAT: + b_variant->float_value = *(float *)p; + break; + case DOUBLE: + b_variant->double_value = *(double *)p; + break; + case BOOLEAN: + b_variant->bool_value = *(bool *)p; + break; + default: + break; + } + + context->error_code = 0; +out: + /* we need to free only in case of data types which was copied by + * _value_, string's pointer will be used by client */ + if (key_type != STRING) + free(p); + free(key); +} + +static int init_buxton_client(void) +{ + int ret; + + if(client != NULL) + return 0; + + ret = buxton_open(&client); + ret_value_msg_if(ret <= 0, -1, "couldn't connect to buxton server"); + + return 0; +} + +void finilize_buxton_client(void) +{ + /* buxton_close is robust to null pointer */ + buxton_close(client); +} + +int buxton_get_var(char *layer_name, char *group_name, + char *key_name, struct buxton_variant *value) +{ + BuxtonKey key; + int ret; + int attempts = 0; + + struct callback_context context = { + .b_variant = value, + .error_code = 0, + }; + + ret_value_msg_if(value == NULL, -1, + "Please provide valid pointer!"); + +get_init: + ret = init_buxton_client(); + ++attempts; + ret_value_if(ret, ret); + + key = buxton_key_create(group_name, key_name, + layer_name, value->type); + + ret = buxton_get_value(client, key, general_get_callback, &context, + true); + buxton_key_free(key); + /* don't return buxton error code, need to return internal error + * code */ + if (errno == EPIPE && attempts < BUXTON_ATTEMPT_NUMBER) { + buxton_close(client); + client = NULL; + goto get_init; + } + return ret || context.error_code ? -1 : 0; +} + +void general_set_callback(BuxtonResponse response, void *data) +{ + BuxtonKey key; + char *name; + int *ret; + int resp_ret; + + ret_msg_if(data == NULL, "Please provide *data for return value!"); + ret = data; + resp_ret = buxton_response_status(response); + + if (resp_ret != 0) { + _E("Failed to set value\n"); + *ret = resp_ret; + return; + } + + key = buxton_response_key(response); + name = buxton_key_get_name(key); + _I("Set value for key %s\n", name); + buxton_key_free(key); + free(name); + *ret = 0; +} + +/* for avoid ptr unligtment */ +static void *get_variant_align(struct buxton_variant *b_variant) +{ + switch (b_variant->type) { + case CONF_STRING: + return b_variant->string_value; + case CONF_INT32: + return &b_variant->int32_value; + case CONF_UINT32: + return &b_variant->uint32_value; + case CONF_INT64: + return &b_variant->int64_value; + case CONF_UINT64: + return &b_variant->uint64_value; + case CONF_FLOAT: + return &b_variant->float_value; + case CONF_DOUBLE: + return &b_variant->double_value; + case CONF_BOOLEAN: + return &b_variant->bool_value; + } + return NULL; +} + +int buxton_set_var(char *layer_name, char *group_name, + char *key_name, struct buxton_variant *value) +{ + int ret_data = -1; + BuxtonKey key; + int ret; + int attempts = 0; + ret_value_msg_if(value == NULL, -1, "Please provide valid pointer"); + +set_init: + ret = init_buxton_client(); + ++attempts; + ret_value_if(ret, ret); + + key = buxton_key_create(group_name, key_name, + layer_name, value->type); + + ret = buxton_set_value(client, key, get_variant_align(value), + general_set_callback, &ret_data, true); + buxton_key_free(key); + + if (errno == EPIPE && attempts < BUXTON_ATTEMPT_NUMBER) { + buxton_close(client); + client = NULL; + goto set_init; + } + + return ret || ret_data ? -1 : 0; +} + diff --git a/src/core/buxton-helper.h b/src/core/buxton-helper.h new file mode 100644 index 0000000..c3885ca --- /dev/null +++ b/src/core/buxton-helper.h @@ -0,0 +1,75 @@ +/* + * deviced + * + * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +/* + * @file buxton-helper.h + * + * @desc Helper function for simplification of using and + * for looking like vconf interface + * + * + * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + */ + +#ifndef __DEVICED_BUXTON_HELPER_H +#define __DEVICED_BUXTON_HELPER_H + +#include + +#define BUXTON_DEVICED_LAYER "base" +#define BUXTON_DEVICED_SYSTEM_GROUP "deviced_system" +#define BUXTON_DEVICED_APPS_GROUP "deviced_apps" + +/* This enum duplicates BuxtonDataType */ +typedef enum conf_data_type { + CONF_TYPE_MIN, + CONF_STRING, /** #include #include +#include #include #include #include @@ -335,3 +336,13 @@ int mount_check(const char* path) endmntent(fp); return ret; } + +void print_time(const char *prefix) +{ + struct timeval tv; + struct tm *tm; + gettimeofday(&tv, NULL); + tm = localtime(&(tv.tv_sec)); + _D("%s --> %d:%02d:%02d %d", + prefix, tm->tm_hour, tm->tm_min, tm->tm_sec, tv.tv_usec); +} diff --git a/src/core/common.h b/src/core/common.h index b25e101..7b00828 100644 --- a/src/core/common.h +++ b/src/core/common.h @@ -20,6 +20,7 @@ #ifndef __CORE_COMMON_H__ #define __CORE_COMMON_H__ +#include #include #include #include @@ -93,6 +94,39 @@ #define USEC_TO_MSEC(x) ((double)x/1000) #endif +#ifndef safe_free +#define safe_free(x) safe_free_memory((void**)&(x)) +#endif + +static inline void safe_free_memory(void** mem) +{ + if (mem && *mem) { + free(*mem); + *mem = NULL; + } +} + +#define ret_value_if(expr, val) do { \ + if (expr) { \ + _E("(%s)", #expr); \ + return (val); \ + } \ +} while (0) + +#define ret_value_msg_if(expr, val, fmt, arg...) do { \ + if (expr) { \ + _E(fmt, ##arg); \ + return val; \ + } \ +} while (0) + +#define ret_msg_if(expr, fmt, arg...) do { \ + if (expr) { \ + _E(fmt, ##arg); \ + return; \ + } \ +} while (0) + FILE * open_proc_oom_score_adj_file(int pid, const char *mode); int get_exec_pid(const char *execpath); int get_cmdline_name(pid_t pid, char *cmdline, size_t cmdline_size); @@ -103,6 +137,7 @@ int sys_get_int(char *fname, int *val); int sys_set_int(char *fname, int val); int terminate_process(char* partition, bool force); int mount_check(const char* path); +void print_time(const char *prefix); #endif /* __CORE_COMMON_H__ */ diff --git a/src/core/core.c b/src/core/core.c deleted file mode 100644 index 1ee910d..0000000 --- a/src/core/core.c +++ /dev/null @@ -1,180 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include "data.h" -#include "queue.h" -#include "log.h" -#include "predefine.h" -#include "core.h" -#include "devices.h" -#include "common.h" - -enum core_cmd_type { - CORE_ACT_RUN, - CORE_ACT_CLEAR -}; - -struct _internal_msg { - int type; - int pid; -}; - -static int core_pipe[2]; -Ecore_Fd_Handler *g_pipe_efd = NULL; - -static int __pipe_start(struct main_data *ad); -static int __pipe_stop(int fd); - -static int _core_action_run(void *user_data, - struct run_queue_entry *rq_entry) -{ - struct action_entry *act_entry = rq_entry->action_entry; - int ret; - char tmp[128]; - - rq_entry->state = STATE_RUNNING; - ret = act_entry->predefine_action(rq_entry->argc, rq_entry->argv); - if (ret <= 0) { - if (ret < 0) - _E("predefine action failed"); - goto fast_done; - } else { - snprintf(tmp, sizeof(tmp), "/proc/%d/status", ret); - if (access(tmp, R_OK) == 0) - rq_entry->forked_pid = ret; - else - goto fast_done; - } - return 0; - - fast_done: - rq_entry->forked_pid = -1; - rq_entry->state = STATE_DONE; - core_action_clear(-1); - return 0; -} - -static Eina_Bool core_pipe_cb(void *userdata, Ecore_Fd_Handler * fd_handler) -{ - struct main_data *ad = (struct main_data *)userdata; - struct _internal_msg p_msg; - int retry_count = 0; - int r = -1; - if (!ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ)) { - _E("ecore_main_fd_handler_active_get error , return"); - return EINA_TRUE; - } - - while (retry_count < 5) { - r = read(core_pipe[0], &p_msg, sizeof(struct _internal_msg)); - if (r < 0) { - if (errno == EINTR) { - _D("Re-read for error(EINTR)"); - retry_count++; - continue; - } else { - __pipe_stop(core_pipe[0]); - __pipe_stop(core_pipe[1]); - _D("restart pipe fd"); - __pipe_start(ad); - } - } else { - break; - } - } - - switch (p_msg.type) { - case CORE_ACT_RUN: - run_queue_run(STATE_INIT, _core_action_run, ad); - break; - case CORE_ACT_CLEAR: - run_queue_del_bypid(p_msg.pid); - break; - } - return EINA_TRUE; -} - -int core_action_run() -{ - struct _internal_msg p_msg; - - p_msg.type = CORE_ACT_RUN; - p_msg.pid = 0; - write(core_pipe[1], &p_msg, sizeof(struct _internal_msg)); - - return 0; -} - -int core_action_clear(int pid) -{ - struct _internal_msg p_msg; - - p_msg.type = CORE_ACT_CLEAR; - p_msg.pid = pid; - write(core_pipe[1], &p_msg, sizeof(struct _internal_msg)); - - return 0; -} - -static int __pipe_start(struct main_data *ad) -{ - if (pipe(core_pipe) < 0) { - _E("pipe cannot create"); - exit(EXIT_FAILURE); - } - - g_pipe_efd = ecore_main_fd_handler_add(core_pipe[0], ECORE_FD_READ, - core_pipe_cb, ad, NULL, NULL); - if (!g_pipe_efd) { - _E("error ecore_main_fd_handler_add"); - return -1; - } - return 0; -} - -static int __pipe_stop(int fd) -{ - if (g_pipe_efd) { - ecore_main_fd_handler_del(g_pipe_efd); - g_pipe_efd = NULL; - } - if (fd >=0) - close(fd); - - return 0; -} - -static void core_init(void *data) -{ - struct main_data *ad = (struct main_data*)data; - - __pipe_stop(core_pipe[0]); - __pipe_stop(core_pipe[1]); - - if (__pipe_start(ad) == -1) - _E("fail pipe control fd init"); -} - -static const struct device_ops core_device_ops = { - .priority = DEVICE_PRIORITY_NORMAL, - .name = "core", - .init = core_init, -}; - -DEVICE_OPS_REGISTER(&core_device_ops) diff --git a/src/core/device-change-handler.c b/src/core/device-change-handler.c index bd3c8ba..aa9b53f 100644 --- a/src/core/device-change-handler.c +++ b/src/core/device-change-handler.c @@ -29,30 +29,25 @@ #include #include #include "dd-deviced.h" -#include "queue.h" #include "log.h" #include "device-notifier.h" #include "device-handler.h" #include "device-node.h" -#include "noti.h" -#include "data.h" -#include "predefine.h" #include "display/poll.h" #include "devices.h" #include "hall/hall-handler.h" #include "udev.h" #include "common.h" -#include "common.h" #include "list.h" +#include "ode/ode.h" #include "proc/proc-handler.h" #include "edbus-handler.h" -#include "emulator.h" #include "devices.h" #include "power-supply.h" #include "display/setting.h" #include "display/core.h" +#include "usb/usb-client.h" -#define PREDEF_EARJACKCON "earjack_predef_internal" #define PREDEF_DEVICE_CHANGED "device_changed" #define PREDEF_POWER_CHANGED POWER_SUBSYSTEM #define PREDEF_UDEV_CONTROL UDEV @@ -64,11 +59,8 @@ #define BUFF_MAX 255 #define SYS_CLASS_INPUT "/sys/class/input" -#ifdef MICRO_DD -#define USB_STATE_PATH "/sys/devices/platform/jack/usb_online" -#else -#define USB_STATE_PATH "/sys/devices/virtual/switch/usb_cable/state" -#endif +#define USB_STATE_PLATFORM_PATH "/sys/devices/platform/jack/usb_online" +#define USB_STATE_SWITCH_PATH "/sys/devices/virtual/switch/usb_cable/state" #define HDMI_NOT_SUPPORTED (-1) #ifdef ENABLE_EDBUS_USE @@ -165,6 +157,9 @@ enum snd_jack_types { #define SIGNAL_HDCP_STATE "ChangedHDCP" #define SIGNAL_HDMI_AUDIO_STATE "ChangedHDMIAudio" +#define METHOD_FACTORY_MODE "factorymode" +#define VCONFKEY_SYSMAN_FACTORY_MODE "memory/sysman/factory_mode" + #define HDCP_HDMI_VALUE(HDCP, HDMI) ((HDCP << 1) | HDMI) #define METHOD_GET_CRADLE "GetCradle" @@ -181,6 +176,11 @@ struct popup_data { char *value; }; +struct siop_data { + int siop; + int rear; +}; + static int ss_flags = 0; static int input_device_number; @@ -199,7 +199,8 @@ static int ufd_udev = -1; static dd_list *opt_uevent_list = NULL; static dd_list *opt_kernel_uevent_list = NULL; static int hdmi_status = 0; -static const struct device_ops *lowbat_ops; + +static int factory_mode = 0; enum udev_subsystem_type { UDEV_HALL_IC, @@ -333,8 +334,18 @@ int get_usb_state_direct(void) FILE *fp; char str[2]; int state; + char *path; - fp = fopen(USB_STATE_PATH, "r"); + if (access(USB_STATE_PLATFORM_PATH, F_OK) == 0) + path = USB_STATE_PLATFORM_PATH; + else if (access(USB_STATE_SWITCH_PATH, F_OK) == 0) + path = USB_STATE_SWITCH_PATH; + else { + _E("Cannot get direct path"); + return -ENOENT; + } + + fp = fopen(path, "r"); if (!fp) { _E("Cannot open jack node"); return -ENOMEM; @@ -371,6 +382,7 @@ static void usb_chgdet_cb(void *data) battery_noti(DEVICE_NOTI_BATT_CHARGE, DEVICE_NOTI_ON); _D("usb device notification"); } + usb_state_changed(val); } else { _E("fail to get usb_online status"); } @@ -381,12 +393,7 @@ static void show_ticker_notification(char *text, int queue) struct ticker_data t_data; static const struct device_ops *ticker = NULL; - if (!ticker) { - ticker = find_device("ticker"); - if (!ticker) - return; - } - + FIND_DEVICE_VOID(ticker, "ticker"); t_data.name = text; t_data.type = queue; if (ticker->init) @@ -398,11 +405,8 @@ static void launch_cradle(int val) struct popup_data *params; static const struct device_ops *apps = NULL; - if (apps == NULL) { - apps = find_device("apps"); - if (apps == NULL) - return; - } + FIND_DEVICE_VOID(apps, "apps"); + params = malloc(sizeof(struct popup_data)); if (params == NULL) { _E("Malloc failed"); @@ -528,62 +532,6 @@ void sync_cradle_status(void) cradle_chgdet_cb(NULL); } -static void ta_chgdet_cb(struct main_data *ad) -{ - int val = -1; - int ret = -1; - int bat_state = VCONFKEY_SYSMAN_BAT_NORMAL; - char params[BUFF_MAX]; - - if (device_get_property(DEVICE_TYPE_EXTCON, PROP_EXTCON_TA_ONLINE, &val) == 0) { - _I("jack - ta changed %d",val); - check_lowbat_charge_device(val); - vconf_set_int(VCONFKEY_SYSMAN_CHARGER_STATUS, val); - if (val == 0) { - ret = device_get_property(DEVICE_TYPE_POWER, PROP_POWER_INSUSPEND_CHARGING_SUPPORT, &val); - if (ret != 0) - val = 0; - if (val == 0) - pm_unlock_internal(INTERNAL_LOCK_TA, LCD_OFF, STAY_CUR_STATE); - device_notify(DEVICE_NOTIFIER_BATTERY_CHARGING, (void*)FALSE); - } else { - ret = device_get_property(DEVICE_TYPE_POWER, PROP_POWER_INSUSPEND_CHARGING_SUPPORT, &val); - if (ret != 0) - val = 0; - if (val == 0) - pm_lock_internal(INTERNAL_LOCK_TA, LCD_OFF, STAY_CUR_STATE, 0); - battery_noti(DEVICE_NOTI_BATT_CHARGE, DEVICE_NOTI_ON); - _D("ta device notification"); - device_notify(DEVICE_NOTIFIER_BATTERY_CHARGING, (void*)TRUE); - } - sync_cradle_status(); - } - else - _E("failed to get ta status"); -} - -static void earjack_chgdet_cb(void *data) -{ - int val; - int ret = 0; - - if (data) - val = *(int *)data; - else { - ret = device_get_property(DEVICE_TYPE_EXTCON, PROP_EXTCON_EARJACK_ONLINE, &val); - if (ret != 0) { - _E("failed to get status"); - return; - } - } - _I("jack - earjack changed %d", val); - if (CONNECTED(val)) { - extcon_set_count(EXTCON_EARJACK); - predefine_pm_change_state(LCD_NORMAL); - } - vconf_set_int(VCONFKEY_SYSMAN_EARJACK, val); -} - static void earkey_chgdet_cb(void *data) { int val; @@ -646,6 +594,15 @@ static int hdcp_hdmi_cb(void *data) return old; } +static int hdmi_cec_execute(void *data) +{ + static const struct device_ops *ops = NULL; + + FIND_DEVICE_INT(ops, "hdmi-cec"); + + return ops->execute(data); +} + static void hdmi_chgdet_cb(void *data) { int val; @@ -682,6 +639,7 @@ static void hdmi_chgdet_cb(void *data) show_ticker_notification(HDMI_DISCONNECTED, 0); pm_unlock_internal(INTERNAL_LOCK_HDMI, LCD_DIM, PM_SLEEP_MARGIN); } + hdmi_cec_execute((void *)val); } static void hdcp_send_broadcast(int status) @@ -785,9 +743,6 @@ static void cb_xxxxx_signaled(void *data, DBusMessage * msg) { char *args; DBusError err; - struct main_data *ad; - - ad = data; dbus_error_init(&err); if (dbus_message_get_args @@ -871,6 +826,111 @@ static void check_present_status(const char *env_value) battery.present = atoi(env_value); } +static int earjack_execute(void *data) +{ + static const struct device_ops *ops = NULL; + + FIND_DEVICE_INT(ops, "earjack"); + + return ops->execute(data); +} + +static int hall_ic_execute(void) +{ + static const struct device_ops *ops = NULL; + + FIND_DEVICE_INT(ops, HALL_IC_NAME); + + return ops->execute(NULL); +} + +static int siop_execute(const char *siop, const char *rear) +{ + static const struct device_ops *ops = NULL; + struct siop_data params; + + FIND_DEVICE_INT(ops, PROC_OPS_NAME); + + if (!siop) + params.siop = 0; + else + params.siop = atoi(siop); + if (!rear) + params.rear = 0; + else + params.rear = atoi(rear); + return ops->execute((void *)¶ms); +} + +static int changed_device(const char *name, const char *value) +{ + int val = 0; + int *state = NULL; + int i; + + if (!name) + goto out; + + if (value) { + val = atoi(value); + state = &val; + } + + if (strncmp(name, USB_NAME, USB_NAME_LEN) == 0) + usb_chgdet_cb((void *)state); + else if (strncmp(name, EARJACK_NAME, EARJACK_NAME_LEN) == 0) + earjack_execute((void *)state); + else if (strncmp(name, EARKEY_NAME, EARKEY_NAME_LEN) == 0) + earkey_chgdet_cb((void *)state); + else if (strncmp(name, TVOUT_NAME, TVOUT_NAME_LEN) == 0) + tvout_chgdet_cb((void *)state); + else if (strncmp(name, HDMI_NAME, HDMI_NAME_LEN) == 0) + hdmi_chgdet_cb((void *)state); + else if (strncmp(name, HDCP_NAME, HDCP_NAME_LEN) == 0) { + hdcp_chgdet_cb((void *)state); + hdcp_hdmi_cb((void *)state); + } + else if (strncmp(name, HDMI_AUDIO_NAME, HDMI_AUDIO_LEN) == 0) + hdmi_audio_chgdet_cb((void *)state); + else if (strncmp(name, CRADLE_NAME, CRADLE_NAME_LEN) == 0) + cradle_chgdet_cb((void *)state); + else if (strncmp(name, KEYBOARD_NAME, KEYBOARD_NAME_LEN) == 0) + keyboard_chgdet_cb((void *)state); + else if (strncmp(name, POWER_SUBSYSTEM, POWER_SUPPLY_NAME_LEN) == 0) + power_supply((void *)state); +out: + return 0; +} + +static int booting_done(void *data) +{ + static int done = 0; + int ret; + int val; + + if (data == NULL) + return done; + done = (int)data; + if (done == 0) + return done; + + _I("booting done"); + + power_supply_timer_stop(); + power_supply_init(NULL); + + /* set initial state for devices */ + input_device_number = 0; + cradle_chgdet_cb(NULL); + keyboard_chgdet_cb(NULL); + hdmi_chgdet_cb(NULL); + + ret = vconf_get_int(VCONFKEY_SYSMAN_CRADLE_STATUS, &val); + if (ret == 0 && val != 0) + launch_cradle(val); + return done; +} + static Eina_Bool uevent_kernel_control_cb(void *data, Ecore_Fd_Handler *fd_handler) { struct udev_device *dev = NULL; @@ -908,7 +968,7 @@ static Eina_Bool uevent_kernel_control_cb(void *data, Ecore_Fd_Handler *fd_handl switch (udev_subsystems[i].type) { case UDEV_HALL_IC: if (!strncmp(devpath, HALL_IC_PATH, strlen(HALL_IC_PATH))) { - notify_action(PREDEF_HALL_IC, 1, HALL_IC_NAME); + hall_ic_execute(); goto out; } break; @@ -936,20 +996,20 @@ static Eina_Bool uevent_kernel_control_cb(void *data, Ecore_Fd_Handler *fd_handl case UDEV_SWITCH: env_name = udev_device_get_property_value(dev, "SWITCH_NAME"); env_value = udev_device_get_property_value(dev, "SWITCH_STATE"); - notify_action(PREDEF_DEVICE_CHANGED, 2, env_name, env_value); + changed_device(env_name, env_value); break; case UDEV_PLATFORM: if (!fnmatch(THERMISTOR_PATH, devpath, 0)) { siop_level = udev_device_get_property_value(dev, "TEMPERATURE"); rear_level = udev_device_get_property_value(dev, "REAR_TEMPERATURE"); - notify_action(SIOP_CHANGED, 2, siop_level, rear_level); + siop_execute(siop_level, rear_level); goto out; } env_value = udev_device_get_property_value(dev, ENV_FILTER); if (!env_value) break; - notify_action(PREDEF_DEVICE_CHANGED, 1, env_value); + changed_device(env_value, NULL); break; case UDEV_POWER: udev_list_entry_foreach(list_entry, udev_device_get_properties_list_entry(dev)) { @@ -978,11 +1038,13 @@ static Eina_Bool uevent_kernel_control_cb(void *data, Ecore_Fd_Handler *fd_handl check_present_status(env_value); env_value = udev_device_get_property_value(dev, CAPACITY); check_capacity_status(env_value); - battery_noti(DEVICE_NOTI_BATT_CHARGE, DEVICE_NOTI_ON); + ret = booting_done(NULL); + if (ret) + battery_noti(DEVICE_NOTI_BATT_CHARGE, DEVICE_NOTI_ON); if (env_value) - notify_action(PREDEF_DEVICE_CHANGED, 2, subsystem, env_value); + changed_device(subsystem, env_value); else - notify_action(PREDEF_DEVICE_CHANGED, 1, subsystem); + changed_device(subsystem, NULL); break; } @@ -1239,7 +1301,6 @@ void unregister_uevent_control(const struct uevent_handler *uh) continue; DD_LIST_REMOVE(opt_uevent_list, handler); - free(handler); break; } } @@ -1323,107 +1384,6 @@ int uevent_udev_get_path(const char *subsystem, dd_list **list) return 0; } -static int changed_device(int argc, char **argv) -{ - int val = 0; - int *state = NULL; - int i; - - for (i = 0 ; i < argc ; i++) { - if (argv[i] == NULL) { - _E("param is failed"); - return -EINVAL; - } - } - - if (argc == 2) { - if (argv[1] == NULL) - val = 0; - else - val = atoi(argv[1]); - state = &val; - } - - if (strncmp(argv[0], USB_NAME, USB_NAME_LEN) == 0) - usb_chgdet_cb((void *)state); - else if (strncmp(argv[0], EARJACK_NAME, EARJACK_NAME_LEN) == 0) - earjack_chgdet_cb((void *)state); - else if (strncmp(argv[0], EARKEY_NAME, EARKEY_NAME_LEN) == 0) - earkey_chgdet_cb((void *)state); - else if (strncmp(argv[0], TVOUT_NAME, TVOUT_NAME_LEN) == 0) - tvout_chgdet_cb((void *)state); - else if (strncmp(argv[0], HDMI_NAME, HDMI_NAME_LEN) == 0) - hdmi_chgdet_cb((void *)state); - else if (strncmp(argv[0], HDCP_NAME, HDCP_NAME_LEN) == 0) { - hdcp_chgdet_cb((void *)state); - hdcp_hdmi_cb((void *)state); - } - else if (strncmp(argv[0], HDMI_AUDIO_NAME, HDMI_AUDIO_LEN) == 0) - hdmi_audio_chgdet_cb((void *)state); - else if (strncmp(argv[0], CRADLE_NAME, CRADLE_NAME_LEN) == 0) - cradle_chgdet_cb((void *)state); - else if (strncmp(argv[0], KEYBOARD_NAME, KEYBOARD_NAME_LEN) == 0) - keyboard_chgdet_cb((void *)state); - else if (strncmp(argv[0], POWER_SUBSYSTEM, POWER_SUPPLY_NAME_LEN) == 0) - power_supply((void *)state); - - return 0; -} - -static int changed_dev_earjack(int argc, char **argv) -{ - int val; - - /* TODO - * if we can recognize which type of jack is changed, - * should move following code for TVOUT to a new action function */ - /* - if(device_get_property(DEVTYPE_JACK,JACK_PROP_TVOUT_ONLINE,&val) == 0) - { - if (val == 1 && - vconf_get_int(VCONFKEY_SETAPPL_TVOUT_TVSYSTEM_INT, &val) == 0) { - _E("Start TV out %s\n", (val==0)?"NTSC":(val==1)?"PAL":"Unsupported"); - switch (val) { - case 0: // NTSC - launch_after_kill_if_exist(TVOUT_X_BIN, "-connect 2"); - break; - case 1: // PAL - launch_after_kill_if_exist(TVOUT_X_BIN, "-connect 3"); - break; - default: - _E("Unsupported TV system type:%d \n", val); - return -1; - } - // UI clone on - launch_evenif_exist(TVOUT_X_BIN, "-clone 1"); - ss_flags |= TVOUT_FLAG; - return vconf_set_int(VCONFKEY_SYSMAN_EARJACK, VCONFKEY_SYSMAN_EARJACK_TVOUT); - } - else { - if(val == 1) { - _E("TV type is not set. Please set the TV type first.\n"); - return -1; - } - if (ss_flags & TVOUT_FLAG) { - _E("TV out Jack is disconnected.\n"); - // UI clone off - launch_after_kill_if_exist(TVOUT_X_BIN, "-clone 0"); - ss_flags &= ~TVOUT_FLAG; - return vconf_set_int(VCONFKEY_SYSMAN_EARJACK, VCONFKEY_SYSMAN_EARJACK_REMOVED); - } - // Current event is not TV out event. Fall through - } - } - */ - if (device_get_property(DEVICE_TYPE_EXTCON, PROP_EXTCON_EARJACK_ONLINE, &val) == 0) { - if (CONNECTED(val)) - extcon_set_count(EXTCON_EARJACK); - return vconf_set_int(VCONFKEY_SYSMAN_EARJACK, val); - } - - return -1; -} - static DBusMessage *dbus_cradle_handler(E_DBus_Object *obj, DBusMessage *msg) { DBusMessageIter iter; @@ -1520,7 +1480,7 @@ static DBusMessage *dbus_device_handler(E_DBus_Object *obj, DBusMessage *msg) goto out; } - changed_device(argc, (char **)&argv); + changed_device(argv[0], argv[1]); out: reply = dbus_message_new_method_return(msg); @@ -1583,7 +1543,7 @@ static DBusMessage *dbus_battery_handler(E_DBus_Object *obj, DBusMessage *msg) battery.present, battery.temp); battery_noti(DEVICE_NOTI_BATT_CHARGE, DEVICE_NOTI_ON); - notify_action(PREDEF_DEVICE_CHANGED, 2, POWER_SUBSYSTEM, argv[0]); + changed_device(POWER_SUBSYSTEM, argv[0]); out: reply = dbus_message_new_method_return(msg); dbus_message_iter_init_append(reply, &iter); @@ -1643,58 +1603,89 @@ out: return reply; } -static const struct edbus_method edbus_methods[] = { - { PREDEF_DEVICE_CHANGED,"siss", "i", dbus_device_handler }, - { PREDEF_POWER_CHANGED, "sisssss", "i", dbus_battery_handler }, - { PREDEF_UDEV_CONTROL, "sis", "i", dbus_udev_handler }, - { METHOD_GET_HDCP, NULL, "i", dbus_hdcp_handler }, - { METHOD_GET_HDMI_AUDIO,NULL, "i", dbus_hdmi_audio_handler }, - { METHOD_GET_HDMI, NULL, "i", dbus_hdcp_hdmi_handler }, - { METHOD_GET_CRADLE, NULL, "i", dbus_cradle_handler }, -}; +int is_factory_mode(void) +{ + return factory_mode; +} -static int booting_done(void *data) +void internal_pm_change_state(unsigned int s_bits) { - static int done = 0; - int ret; - int val; + if (is_factory_mode() == 1) + _D("skip LCD control for factory mode"); + else + pm_change_internal(getpid(), s_bits); +} - if (data == NULL) - return done; - done = (int)data; - if (done == 0) - return done; +static int set_factory_mode(int status) +{ + int ret = -1; - _I("booting done"); + if (status == 1 || status == 0) { + factory_mode = status; + /* For USB-server to refer the value */ + ret = vconf_set_int(VCONFKEY_SYSMAN_FACTORY_MODE, status); + if(ret != 0) { + _E("FAIL: vconf_set_int()"); + } + } + return factory_mode; +} - register_action(PREDEF_EARJACKCON, changed_dev_earjack, NULL, NULL); - register_action(PREDEF_DEVICE_CHANGED, changed_device, NULL, NULL); +static DBusMessage *dbus_factory_mode(E_DBus_Object *obj, DBusMessage *msg) +{ + DBusError err; + DBusMessageIter iter; + DBusMessage *reply; + pid_t pid; + int ret; + int argc; + char *type_str; + char *argv; - power_supply_timer_stop(); - power_supply_init(NULL); + dbus_error_init(&err); - if (uevent_kernel_control_start() != 0) { - _E("fail uevent control init"); - return 0; + if (!dbus_message_get_args(msg, &err, + DBUS_TYPE_STRING, &type_str, + DBUS_TYPE_INT32, &argc, + DBUS_TYPE_STRING, &argv, DBUS_TYPE_INVALID)) { + _E("there is no message"); + ret = -EINVAL; + goto out; } - if (uevent_udev_control_start() != 0) { - _E("fail uevent control init"); - return 0; + if (argc < 0) { + _E("message is invalid!"); + ret = -EINVAL; + goto out; } - /* set initial state for devices */ - input_device_number = 0; - cradle_chgdet_cb(NULL); - keyboard_chgdet_cb(NULL); - hdmi_chgdet_cb(NULL); + pid = get_edbus_sender_pid(msg); + if (kill(pid, 0) == -1) { + _E("%d process does not exist, dbus ignored!", pid); + ret = -ESRCH; + goto out; + } - ret = vconf_get_int(VCONFKEY_SYSMAN_CRADLE_STATUS, &val); - if (ret == 0 && val != 0) - launch_cradle(val); - return done; + ret = set_factory_mode(atoi(argv)); +out: + reply = dbus_message_new_method_return(msg); + dbus_message_iter_init_append(reply, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); + + return reply; } +static const struct edbus_method edbus_methods[] = { + { PREDEF_DEVICE_CHANGED, "siss", "i", dbus_device_handler }, + { PREDEF_POWER_CHANGED, "sisssss", "i", dbus_battery_handler }, + { PREDEF_UDEV_CONTROL, "sis","i", dbus_udev_handler }, + { METHOD_GET_HDCP, NULL, "i", dbus_hdcp_handler }, + { METHOD_GET_HDMI_AUDIO, NULL, "i", dbus_hdmi_audio_handler }, + { METHOD_GET_HDMI, NULL, "i", dbus_hdcp_hdmi_handler }, + { METHOD_GET_CRADLE, NULL, "i", dbus_cradle_handler }, + { METHOD_FACTORY_MODE, "sis","i", dbus_factory_mode }, +}; + static int device_change_poweroff(void *data) { uevent_kernel_control_stop(); @@ -1716,20 +1707,6 @@ static void device_change_init(void *data) if (ret < 0) _E("fail to init edbus method(%d)", ret); - /* for simple noti change cb */ - emulator_add_callback("device_usb_chgdet", (void *)usb_chgdet_cb, NULL); - emulator_add_callback("device_ta_chgdet", (void *)ta_chgdet_cb, data); - emulator_add_callback("device_earjack_chgdet", (void *)earjack_chgdet_cb, data); - emulator_add_callback("device_earkey_chgdet", (void *)earkey_chgdet_cb, data); - emulator_add_callback("device_tvout_chgdet", (void *)tvout_chgdet_cb, data); - emulator_add_callback("device_hdmi_chgdet", (void *)hdmi_chgdet_cb, data); - emulator_add_callback("device_cradle_chgdet", (void *)cradle_chgdet_cb, data); - emulator_add_callback("device_keyboard_chgdet", (void *)keyboard_chgdet_cb, data); - - emulator_add_callback("unmount_ums", (void *)ums_unmount_cb, NULL); - - /* check and set earjack init status */ - changed_dev_earjack(0, NULL); /* dbus noti change cb */ #ifdef ENABLE_EDBUS_USE e_dbus_init(); @@ -1741,6 +1718,15 @@ static void device_change_init(void *data) "system.uevent.xxxxx", "Change", cb_xxxxx_signaled, data); #endif /* ENABLE_EDBUS_USE */ + if (uevent_kernel_control_start() != 0) { + _E("fail uevent control init"); + return; + } + + if (uevent_udev_control_start() != 0) { + _E("fail uevent control init"); + return; + } } static void device_change_exit(void *data) diff --git a/src/core/device-handler.h b/src/core/device-handler.h index 071b882..49f0b55 100644 --- a/src/core/device-handler.h +++ b/src/core/device-handler.h @@ -20,7 +20,7 @@ #ifndef __DEVICE_HANDLER_H__ #define __DEVICE_HANDLER_H__ -#include "data.h" +#include "common.h" enum extcon_type { EXTCON_TA = 0, @@ -102,4 +102,5 @@ int get_usb_state_direct(void); void sync_cradle_status(void); +void internal_pm_change_state(unsigned int s_bits); #endif /* __DEVICE_HANDLER_H__ */ diff --git a/src/core/device-notifier.c b/src/core/device-notifier.c index a02584a..41c1ac9 100644 --- a/src/core/device-notifier.c +++ b/src/core/device-notifier.c @@ -22,6 +22,10 @@ #include "device-notifier.h" #include "list.h" #include "common.h" +#include + +#define LATE_INIT_WAIT_TIME 12 +#define DEFAULT_LATE_INIT_VALUE ((Ecore_Timer *)0x0DEF0DEF) struct device_notifier { enum device_notifier_type status; @@ -29,6 +33,7 @@ struct device_notifier { }; static dd_list *device_notifier_list; +static Ecore_Timer *late_init_timer = DEFAULT_LATE_INIT_VALUE; #define FIND_NOTIFIER(a, b, d, e, f) \ DD_LIST_FOREACH(a, b, d) \ @@ -101,6 +106,60 @@ void device_notify(enum device_notifier_type status, void *data) } } +static void late_init_stop(void) +{ + if (late_init_timer == NULL || + late_init_timer == DEFAULT_LATE_INIT_VALUE) + return; + ecore_timer_del(late_init_timer); + late_init_timer = NULL; +} + +static int booting_done(void *data) +{ + static int done = 0; + + if (data == NULL) + goto out; + + journal_system_booting_done(); + done = (int)data; + if (late_init_timer == NULL) + return done; + late_init_stop(); +out: + return done; +} + +static Eina_Bool late_init_timer_cb(void *data) +{ + int done; + + late_init_stop(); + done = booting_done(NULL); + if (done) + return EINA_FALSE; + _I("late booting done"); + device_notify(DEVICE_NOTIFIER_BOOTING_DONE, (void *)TRUE); + return EINA_FALSE; +} + +static void device_notifier_init(void *data) +{ + int ret; + + ret = check_systemd_active(); + if (ret == TRUE) { + _I("restart booting done"); + return; + } + register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + late_init_timer = ecore_timer_add(LATE_INIT_WAIT_TIME, + late_init_timer_cb, NULL); + if (!late_init_timer) + late_init_timer = DEFAULT_LATE_INIT_VALUE; +} + static void device_notifier_exit(void *data) { dd_list *n; @@ -114,6 +173,7 @@ static void device_notifier_exit(void *data) static const struct device_ops notifier_device_ops = { .priority = DEVICE_PRIORITY_NORMAL, .name = "notifier", + .init = device_notifier_init, .exit = device_notifier_exit, }; diff --git a/src/core/device-notifier.h b/src/core/device-notifier.h index 490a98d..e55ee14 100644 --- a/src/core/device-notifier.h +++ b/src/core/device-notifier.h @@ -45,7 +45,9 @@ enum device_notifier_type { DEVICE_NOTIFIER_POWEROFF, DEVICE_NOTIFIER_POWEROFF_HAPTIC, DEVICE_NOTIFIER_PMQOS, - DEVICE_NOTIFIER_POWERSAVER, + DEVICE_NOTIFIER_PMQOS_ULTRAPOWERSAVING, + DEVICE_NOTIFIER_PMQOS_HALL, + DEVICE_NOTIFIER_COOL_DOWN, DEVICE_NOTIFIER_MAX, }; diff --git a/src/core/device-plugin.c b/src/core/device-plugin.c deleted file mode 100644 index 3048892..0000000 --- a/src/core/device-plugin.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include - -#include "log.h" -#include "device-plugin.h" - -static void *dlopen_handle; - -int _ss_devman_plugin_init() -{ - char *error; - - dlopen_handle = dlopen(DEVMAN_PLUGIN_PATH, RTLD_NOW); - if (!dlopen_handle) { - _E("dlopen() failed"); - return -1; - } - - const OEM_sys_devman_plugin_interface *(*get_devman_plugin_interface) (); - get_devman_plugin_interface = dlsym(dlopen_handle, "OEM_sys_get_devman_plugin_interface"); - if ((error = dlerror()) != NULL) { - _E("dlsym() failed: %s", error); - dlclose(dlopen_handle); - return -1; - } - - plugin_intf = get_devman_plugin_interface(); - if (!plugin_intf) { - _E("get_devman_plugin_interface() failed"); - dlclose(dlopen_handle); - return -1; - } - - return 0; -} - - -int _ss_devman_plugin_fini() -{ - if (dlopen_handle) { - dlclose(dlopen_handle); - } - - return 0; -} - - diff --git a/src/core/devices.c b/src/core/devices.c index da2292f..de766f3 100644 --- a/src/core/devices.c +++ b/src/core/devices.c @@ -24,6 +24,10 @@ #include "common.h" #include "devices.h" +static const struct device_ops default_ops = { + .name = "default-ops", +}; + static dd_list *dev_head; void add_device(const struct device_ops *dev) @@ -48,7 +52,14 @@ const struct device_ops *find_device(const char *name) if (!strcmp(dev->name, name)) return dev; } - return NULL; + + dev = &default_ops; + return dev; +} + +int check_default(const struct device_ops *dev) +{ + return (dev == &default_ops); } void devices_init(void *data) diff --git a/src/core/devices.h b/src/core/devices.h index b4537ad..38bef89 100644 --- a/src/core/devices.h +++ b/src/core/devices.h @@ -28,14 +28,28 @@ enum device_priority { DEVICE_PRIORITY_HIGH, }; +enum device_flags { + NORMAL_MODE = 0x00000001, + AMBIENT_MODE = 0x00000002, + CORE_LOGIC_MODE = 0x00010000, + TOUCH_SCREEN_OFF_MODE = 0x00020000, + LCD_PANEL_OFF_MODE = 0x00040000, + LCD_PHASED_TRANSIT_MODE = 0x00080000, + LCD_ON_BY_GESTURE = 0x00100000, + LCD_ON_BY_POWER_KEY = 0x00200000, + LCD_ON_BY_EVENT = 0x00400000, + LCD_ON_BY_TOUCH = 0x00800000, +}; + struct device_ops { enum device_priority priority; char *name; void (*init) (void *data); void (*exit) (void *data); - int (*start) (void); - int (*stop) (void); + int (*start) (enum device_flags flags); + int (*stop) (enum device_flags flags); int (*status) (void); + int (*execute) (void *data); }; enum device_ops_status { @@ -51,7 +65,7 @@ void devices_exit(void *data); static inline int device_start(const struct device_ops *dev) { if (dev && dev->start) - return dev->start(); + return dev->start(NORMAL_MODE); return -EINVAL; } @@ -59,7 +73,25 @@ static inline int device_start(const struct device_ops *dev) static inline int device_stop(const struct device_ops *dev) { if (dev && dev->stop) - return dev->stop(); + return dev->stop(NORMAL_MODE); + + return -EINVAL; +} + +static inline int device_exit(const struct device_ops *dev, void *data) +{ + if (dev && dev->exit) { + dev->exit(data); + return 0; + } + + return -EINVAL; +} + +static inline int device_execute(const struct device_ops *dev, void *data) +{ + if (dev && dev->execute) + return dev->execute(data); return -EINVAL; } @@ -84,6 +116,19 @@ static void __DESTRUCTOR__ module_exit(void) \ void add_device(const struct device_ops *dev); void remove_device(const struct device_ops *dev); + const struct device_ops *find_device(const char *name); +int check_default(const struct device_ops *dev); + +#define NOT_SUPPORT_OPS(dev) \ + ((check_default(dev))? 1 : 0) + +#define FIND_DEVICE_INT(dev, name) do { \ + if (!dev) dev = find_device(name); if(check_default(dev)) return -ENODEV; \ +} while(0) + +#define FIND_DEVICE_VOID(dev, name) do { \ + if (!dev) dev = find_device(name); if(check_default(dev)) return; \ +} while(0) #endif diff --git a/src/core/edbus-handler.c b/src/core/edbus-handler.c index f03a051..eb9200f 100644 --- a/src/core/edbus-handler.c +++ b/src/core/edbus-handler.c @@ -19,7 +19,6 @@ #include #include "core/log.h" -#include "core/data.h" #include "core/edbus-handler.h" #include "core/common.h" #include "core/device-notifier.h" @@ -60,14 +59,19 @@ static struct edbus_object { { DEVICED_PATH_CPU , DEVICED_INTERFACE_CPU , NULL, NULL }, { DEVICED_PATH_PMQOS , DEVICED_INTERFACE_PMQOS , NULL, NULL }, { DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI, NULL, NULL }, + { DEVICED_PATH_USB , DEVICED_INTERFACE_USB , NULL, NULL }, { DEVICED_PATH_USBHOST, DEVICED_INTERFACE_USBHOST, NULL, NULL }, { DEVICED_PATH_EXTCON , DEVICED_INTERFACE_EXTCON , NULL, NULL }, { DEVICED_PATH_BATTERY, DEVICED_INTERFACE_BATTERY, NULL, NULL }, { DEVICED_PATH_BOARD, DEVICED_INTERFACE_BOARD, NULL, NULL }, { DEVICED_PATH_TESTMODE, DEVICED_INTERFACE_TESTMODE, NULL, NULL}, + { DEVICED_PATH_APPS, DEVICED_INTERFACE_APPS, NULL, NULL}, + { DEVICED_PATH_GPIO, DEVICED_INTERFACE_GPIO, NULL, NULL}, + { DEVICED_PATH_HDMICEC, DEVICED_INTERFACE_HDMICEC, NULL, NULL}, /* Add new object & interface here*/ }; +static dd_list *edbus_owner_list; static dd_list *edbus_handler_list; static dd_list *edbus_watch_list; static int edbus_init_val; @@ -254,9 +258,15 @@ int broadcast_edbus_signal(const char *path, const char *interface, return -EPERM; } - e_dbus_message_send(edbus_conn, msg, NULL, -1, NULL); - + r = dbus_connection_send(conn, msg, NULL); dbus_message_unref(msg); + + if (r != TRUE) { + _E("dbus_connection_send error(%s:%s-%s)", + path, interface, name); + return -ECOMM; + } + return 0; } @@ -502,6 +512,86 @@ static void request_name_cb(void *data, DBusMessage *msg, DBusError *error) _I("Request Name reply : %d", val); } +static void check_owner_name(void) +{ + DBusError err; + DBusMessage *msg; + DBusMessageIter iter; + char *pa[1]; + char exe_name[PATH_MAX]; + char *entry; + dd_list *n; + int pid; + + DD_LIST_FOREACH(edbus_owner_list, n, entry) { + pa[0] = entry; + msg = dbus_method_sync_with_reply(E_DBUS_FDO_BUS, + E_DBUS_FDO_PATH, + E_DBUS_FDO_INTERFACE, + "GetConnectionUnixProcessID", "s", pa); + + if (!msg) { + _E("invalid DBusMessage!"); + return; + } + + dbus_error_init(&err); + dbus_message_iter_init(msg, &iter); + + dbus_message_iter_get_basic(&iter, &pid); + if (get_cmdline_name(pid, exe_name, PATH_MAX) != 0) + goto out; + _I("%s(%d)", exe_name, pid); + +out: + dbus_message_unref(msg); + dbus_error_free(&err); + } +} + +static void check_owner_list(void) +{ + DBusError err; + DBusMessage *msg; + DBusMessageIter array, iter, item, iter_val; + char *pa[1]; + char *name; + char *entry; + + pa[0] = DEVICED_BUS_NAME; + msg = dbus_method_sync_with_reply(E_DBUS_FDO_BUS, + E_DBUS_FDO_PATH, + E_DBUS_FDO_INTERFACE, + "ListQueuedOwners", "s", pa); + + if (!msg) { + _E("invalid DBusMessage!"); + return; + } + + dbus_error_init(&err); + dbus_message_iter_init(msg, &array); + + if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY) + goto out; + dbus_message_iter_recurse(&array, &item); + while (dbus_message_iter_get_arg_type(&item) == DBUS_TYPE_STRING) { + dbus_message_iter_get_basic(&item, &name); + entry = strndup(name, strlen(name)); + DD_LIST_APPEND(edbus_owner_list, entry); + if (!edbus_owner_list) { + _E("append failed"); + free(entry); + goto out; + } + dbus_message_iter_next(&item); + } + +out: + dbus_message_unref(msg); + dbus_error_free(&err); +} + void edbus_init(void *data) { DBusError error; @@ -568,6 +658,8 @@ void edbus_init(void *data) } _D("add new obj for %s", edbus_objects[i].interface); } + check_owner_list(); + check_owner_name(); return; out3: diff --git a/src/core/execute.c b/src/core/execute.c index 1c664da..303f6b7 100755 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -64,10 +64,18 @@ int run_child(int argc, const char *argv[]) pid_t pid; struct sigaction act, oldact; int r; + FILE *fp; if (!argv) return -EINVAL; + fp = fopen(argv[0], "r"); + if (fp == NULL) { + _E("fail %s (%s)", argv[0], strerror(errno)); + return -errno; + } + fclose(fp); + /* Use default signal handler */ act.sa_handler = SIG_DFL; act.sa_sigaction = NULL; diff --git a/src/core/list.h b/src/core/list.h index b688dec..d3fa641 100644 --- a/src/core/list.h +++ b/src/core/list.h @@ -59,6 +59,37 @@ typedef Eina_List dd_list; #else #include typedef GList dd_list; + +/* + cover crash from corrupted double linked list under the glib 2.36.4 + if glib version upper than 2.36.3, exchange it to g_list_remove +*/ +static inline GList* g_list_check_remove(GList* list, gpointer data) +{ + GList *temp; + temp = list; + if (!temp) + goto out; + while (temp != NULL) { + if (temp->data != data) + temp = temp->next; + else { + if (temp->prev != NULL && temp->prev->next == temp) + temp->prev->next = temp->next; + if (temp->next != NULL && temp->next->prev == temp) + temp->next->prev = temp->prev; + if (temp == list) + list = list->next; + temp->prev = NULL; + temp->next = NULL; + g_list_free(list); + break; + } + } +out: + return list; +} + #define DD_LIST_PREPEND(a, b) \ a = g_list_prepend(a, (gpointer)b) #define DD_LIST_APPEND(a, b) \ diff --git a/src/core/device-plugin.h b/src/core/log.c similarity index 60% rename from src/core/device-plugin.h rename to src/core/log.c index 3c6df87..04aa3da 100644 --- a/src/core/device-plugin.h +++ b/src/core/log.c @@ -16,17 +16,24 @@ * limitations under the License. */ +#include +#include "log.h" -#ifndef __SS_DEVICE_PLUGIN_H__ -#define __SS_DEVICE_PLUGIN_H__ +#ifdef DEBUG +void __cyg_profile_func_enter(void *, void *) + __attribute__ ((no_instrument_function)); +void __cyg_profile_func_exit(void *, void *) + __attribute__ ((no_instrument_function)); -#include "devman-plugin-intf.h" +int g_trace_depth = -2; -#define DEVMAN_PLUGIN_PATH "/usr/lib/libslp_devman_plugin.so" +void __cyg_profile_func_enter(void *func, void *caller) +{ + g_trace_depth++; +} -int _ss_devman_plugin_init(void); -int _ss_devman_plugin_fini(void); - -const OEM_sys_devman_plugin_interface *plugin_intf; - -#endif /* __SS_DEVICE_PLUGIN_H__ */ +void __cyg_profile_func_exit(void *func, void *caller) +{ + g_trace_depth--; +} +#endif diff --git a/src/core/log.h b/src/core/log.h index 758151e..9684f38 100644 --- a/src/core/log.h +++ b/src/core/log.h @@ -30,5 +30,4 @@ #define LOG_TAG "DEVICED" #include "shared/log-macro.h" - #endif diff --git a/src/core/main.c b/src/core/main.c index 977eb06..ab3e80c 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -23,7 +23,7 @@ #include "display/core.h" #include "log.h" -#include "data.h" +#include "common.h" #include "edbus-handler.h" #include "devices.h" #include "shared/dbus.h" @@ -31,11 +31,6 @@ #define PIDFILE_PATH "/var/run/.deviced.pid" -static void init_ad(struct main_data *ad) -{ - memset(ad, 0x0, sizeof(struct main_data)); -} - static void writepid(char *pidpath) { FILE *fp; @@ -59,63 +54,24 @@ static void sig_usr1(int signo) ecore_main_loop_quit(); } -static void check_systemd_active(void) +static int deviced_main(int argc, char **argv) { - DBusError err; - DBusMessage *msg; - DBusMessageIter iter, sub; - const char *state; - char *pa[2]; - - pa[0] = "org.freedesktop.systemd1.Unit"; - pa[1] = "ActiveState"; - - _I("%s %s", pa[0], pa[1]); - - msg = dbus_method_sync_with_reply("org.freedesktop.systemd1", - "/org/freedesktop/systemd1/unit/default_2etarget", - "org.freedesktop.DBus.Properties", - "Get", "ss", pa); - if (!msg) - return; - - dbus_error_init(&err); - - if (!dbus_message_iter_init(msg, &iter) || - dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT) - goto out; + int ret; - dbus_message_iter_recurse(&iter, &sub); - - if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_STRING) - goto out; - - dbus_message_iter_get_basic(&sub, &state); - - if (strncmp(state, "active", 6) == 0) { + edbus_init(NULL); + devices_init(NULL); + ret = check_systemd_active(); + if (ret == TRUE) { _I("notify relaunch"); device_notify(DEVICE_NOTIFIER_BOOTING_DONE, (void *)TRUE); } -out: - dbus_message_unref(msg); - dbus_error_free(&err); -} - -static int system_main(int argc, char **argv) -{ - struct main_data ad; - - init_ad(&ad); - edbus_init(&ad); - devices_init(&ad); - check_systemd_active(); signal(SIGTERM, sig_quit); signal(SIGUSR1, sig_usr1); ecore_main_loop_begin(); - devices_exit(&ad); - edbus_exit(&ad); + devices_exit(NULL); + edbus_exit(NULL); ecore_shutdown(); return 0; } @@ -124,5 +80,5 @@ int main(int argc, char **argv) { writepid(PIDFILE_PATH); ecore_init(); - return system_main(argc, argv); + return deviced_main(argc, argv); } diff --git a/src/core/noti.c b/src/core/noti.c deleted file mode 100644 index 8eda5d6..0000000 --- a/src/core/noti.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include "log.h" -#include "data.h" -#include "devices.h" -#include "common.h" - -static int noti_fd; - -int noti_getfd() -{ - return noti_fd; -} - -int noti_send(char *filename) -{ - return heynoti_publish(filename); -} - -int noti_add(const char *noti, void (*cb) (void *), void *data) -{ - if (noti_fd < 0) - return -1; - - return heynoti_subscribe(noti_fd, noti, cb, data); -} - -static void noti_init(void *data) -{ - struct main_data *ad = (struct main_data*)data; - - if ((ad->noti_fd = heynoti_init()) < 0) { - _E("Hey Notification Initialize failed"); - return; - } - if (heynoti_attach_handler(ad->noti_fd) != 0) { - _E("fail to attach hey noti handler"); - return; - } - - noti_fd = heynoti_init(); - if (noti_fd < 0) { - _E("heynoti_init error"); - return; - } - - if (heynoti_attach_handler(noti_fd) < 0) { - _E("heynoti_attach_handler error"); - return; - } -} - -static void noti_exit(void *data) -{ - struct main_data *ad = (struct main_data*)data; - - heynoti_close(ad->noti_fd); - heynoti_close(noti_fd); -} - -static const struct device_ops noti_device_ops = { - .priority = DEVICE_PRIORITY_NORMAL, - .name = "noti", - .init = noti_init, - .exit = noti_exit, -}; - -DEVICE_OPS_REGISTER(¬i_device_ops) diff --git a/src/core/power-supply.c b/src/core/power-supply.c index e058023..2c24723 100644 --- a/src/core/power-supply.c +++ b/src/core/power-supply.c @@ -22,24 +22,22 @@ #include #include #include - +#include #include "devices.h" -#include "predefine.h" #include "device-handler.h" #include "device-notifier.h" #include "udev.h" #include "log.h" -#include "emulator.h" #include "display/poll.h" #include "display/setting.h" #include "proc/proc-handler.h" #include "config-parser.h" #include "power-supply.h" +#include "sleep/sleep.h" #define BUFF_MAX 255 #define POPUP_KEY_CONTENT "_SYSPOPUP_CONTENT_" -#define PREDEF_BATTERY_CF_OPENED "battery_cf_opened" #define SIGNAL_CHARGEERR_RESPONSE "ChargeErrResponse" #define SIGNAL_TEMP_GOOD "TempGood" @@ -59,12 +57,19 @@ #define BATT_CHARGE_NOTI "0" #define BATT_FULL_NOTI "2" #endif + +enum power_supply_init_type { + POWER_SUPPLY_NOT_READY = 0, + POWER_SUPPLY_INITIALIZED = 1, +}; + struct popup_data { char *name; char *key; char *value; }; +static int alert_popup = 0; static Ecore_Timer *power_timer = NULL; static Ecore_Timer *abnormal_timer = NULL; extern int battery_power_off_act(void *data); @@ -74,7 +79,7 @@ static void pm_check_and_change(int bInserted) static int old = -1; if (old != bInserted) { old = bInserted; - predefine_pm_change_state(LCD_NORMAL); + internal_pm_change_state(LCD_NORMAL); } } @@ -100,15 +105,10 @@ int check_lowbat_charge_device(int bInserted) if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &bat_state) == 0) { if(bat_state < VCONFKEY_SYSMAN_BAT_NORMAL || bat_state == VCONFKEY_SYSMAN_BAT_REAL_POWER_OFF) { - if (apps == NULL) { - apps = find_device("apps"); - if (apps == NULL) - return 0; - } + FIND_DEVICE_INT(apps, "apps"); + if(bat_state == VCONFKEY_SYSMAN_BAT_REAL_POWER_OFF) value = "poweroff"; - else if (bat_state == VCONFKEY_SYSMAN_BAT_POWER_OFF) - value = "extreme"; else value = "warning"; params = malloc(sizeof(struct popup_data)); @@ -134,21 +134,12 @@ int check_lowbat_charge_device(int bInserted) return -1; } -static int changed_battery_cf(int argc, char **argv) +static int changed_battery_cf(enum present_type status) { - int present_status; struct popup_data *params; static const struct device_ops *apps = NULL; - if (argc != 1) - return -EINVAL; - present_status = atoi(argv[0]); - - if (apps == NULL) { - apps = find_device("apps"); - if (apps == NULL) - return 0; - } + FIND_DEVICE_INT(apps, "apps"); params = malloc(sizeof(struct popup_data)); if (params == NULL) { _E("Malloc failed"); @@ -159,7 +150,7 @@ static int changed_battery_cf(int argc, char **argv) params->value = "battdisconnect"; if (apps->init == NULL || apps->exit == NULL) goto out; - if (present_status == PRESENT_ABNORMAL) + if (status == PRESENT_ABNORMAL) apps->init((void *)params); else apps->exit((void *)params); @@ -197,11 +188,7 @@ static int clean_health_popup(void) struct popup_data *params; static const struct device_ops *apps = NULL; - if (apps == NULL) { - apps = find_device("apps"); - if (apps == NULL) - return 0; - } + FIND_DEVICE_INT(apps, "apps"); params = malloc(sizeof(struct popup_data)); if (params == NULL) { _E("Malloc failed"); @@ -275,18 +262,35 @@ static void full_noti_cb(void *data, DBusMessage *msg, DBusError *err) _D("Inserted battery full noti : %d", noti_id); } -static int send_full_noti(enum charge_full_type state) +static int check_noti(void) { - int ret = 0; #ifdef MICRO_DD - char params[BUFF_MAX]; - snprintf(params, sizeof(params), "%s %d", BATT_FULL_NOTI, state); - launch_evenif_exist(DEVICE_NOTIFIER, params); + int r_disturb, s_disturb, r_block, s_block; + r_disturb = vconf_get_int("memory/shealth/sleep/do_not_disturb", &s_disturb); + r_block = vconf_get_bool("db/setting/blockmode_wearable", &s_block); + if ((r_disturb != 0 && r_block != 0) || + (s_disturb == 0 && s_block == 0)) { + return 1; + } + return 0; #else + return 1; +#endif +} + +static int send_full_noti(enum charge_full_type state) +{ + int ret = 0; + int noti; int retry; char str_id[32]; char *arr[1]; + noti = check_noti(); + + if (!noti) + return noti; + switch (state) { case CHARGING_FULL: for (retry = RETRY_MAX; retry > 0 ;retry--) { @@ -322,16 +326,12 @@ static int send_full_noti(enum charge_full_type state) _E("Failed to call dbus method (err: %d)", ret); break; } -#endif return ret; } int send_charge_noti(void) { int ret = 0; -#ifdef MICRO_DD - launch_evenif_exist(DEVICE_NOTIFIER, BATT_CHARGE_NOTI); -#else int retry; for (retry = RETRY_MAX; retry > 0 ;retry--) { @@ -346,7 +346,6 @@ int send_charge_noti(void) } } _E("Failed to call dbus method (err: %d)", ret); -#endif return ret; } @@ -358,6 +357,8 @@ void battery_noti(enum battery_noti_type type, enum battery_noti_status status) if (type == DEVICE_NOTI_BATT_FULL && status == DEVICE_NOTI_ON && full == CHARGING_NOT_FULL) { + if (charge == CHARGER_DISCHARGING) + send_charge_noti(); ret = send_full_noti(CHARGING_FULL); if (ret == 0) full = CHARGING_FULL; @@ -383,7 +384,10 @@ static void noti_batt_full(void) { char params[BUFF_MAX]; static int bat_full_noti = 0; + int r_disturb, s_disturb, r_block, s_block; + r_disturb = vconf_get_int("memory/shealth/sleep/do_not_disturb", &s_disturb); + r_block = vconf_get_bool("db/setting/blockmode_wearable", &s_block); if (!battery.charge_full && bat_full_noti == 1) { battery_noti(DEVICE_NOTI_BATT_FULL, DEVICE_NOTI_OFF); bat_full_noti = 0; @@ -394,7 +398,11 @@ static void noti_batt_full(void) battery_noti(DEVICE_NOTI_BATT_FULL, DEVICE_NOTI_ON); bat_full_noti = 1; /* turn on LCD, if battery is full charged */ - pm_change_internal(getpid(), LCD_NORMAL); + if ((r_disturb != 0 && r_block != 0) || + (s_disturb == 0 && s_block == 0)) + pm_change_internal(getpid(), LCD_NORMAL); + else + _I("block LCD"); /* on the full charge state */ device_notify(DEVICE_NOTIFIER_FULLBAT, (void*)true); } @@ -423,7 +431,7 @@ static void check_power_supply(int state) else pm_lock_internal(INTERNAL_LOCK_TA, LCD_OFF, STAY_CUR_STATE, 0); out: - _I("ta device %d", state); + _I("ta device %d(capacity %d)", state, battery.capacity); sync_cradle_status(); } @@ -431,7 +439,7 @@ out: static void update_present(enum battery_noti_status status) { static int old = DEVICE_NOTI_OFF; - char params[BUFF_MAX]; + enum present_type present; if (old == status) return; @@ -439,10 +447,10 @@ static void update_present(enum battery_noti_status status) old = status; pm_change_internal(getpid(), LCD_NORMAL); if (status == DEVICE_NOTI_ON) - snprintf(params, sizeof(params), "%d", PRESENT_ABNORMAL); + present = PRESENT_ABNORMAL; else - snprintf(params, sizeof(params), "%d", PRESENT_NORMAL); - notify_action(PREDEF_BATTERY_CF_OPENED, 1, params); + present = PRESENT_NORMAL; + changed_battery_cf(present); } static void update_health(enum battery_noti_status status) @@ -453,6 +461,12 @@ static void update_health(enum battery_noti_status status) return; _I("charge %d health %d", battery.charge_now, battery.health); old = status; + + if (alert_popup && status == DEVICE_NOTI_ON) { + _I("silent health popup"); + return; + } + pm_change_internal(getpid(), LCD_NORMAL); if (status == DEVICE_NOTI_ON) { _I("popup - Battery health status is not good"); @@ -545,65 +559,6 @@ static void check_online(void) } } -static void charge_cb(struct main_data *ad) -{ - int val = -1; - int ret; - static int present_status = PRESENT_NORMAL; - - lowbat_monitor(NULL); - - if (device_get_property(DEVICE_TYPE_POWER, PROP_POWER_CHARGE_NOW, &battery.charge_now) != 0 || - device_get_property(DEVICE_TYPE_POWER, PROP_POWER_CAPACITY, &battery.capacity) != 0) - _E("fail to get battery node value"); - - if (battery.charge_now > 0) - battery.charge_now = CHARGER_CHARGING; - else - battery.charge_now = CHARGER_DISCHARGING; - - if (battery.charge_now != CHARGER_CHARGING && battery.capacity == 0) { - _I("target will be shut down"); - battery_power_off_act(NULL); - return; - } - - ret = device_get_property(DEVICE_TYPE_POWER, PROP_POWER_PRESENT, &val); - if (ret != 0) { - battery.present = PRESENT_NORMAL; - _E("fail to get battery present value"); - goto check_health; - } -check_health: - ret = device_get_property(DEVICE_TYPE_POWER, PROP_POWER_HEALTH, &val); - if (ret != 0) { - battery.health = HEALTH_GOOD; - battery.ovp = OVP_NORMAL; - _E("failed to get battery health status"); - goto check_full; - } - if (val != BATTERY_GOOD) - _I("Battery health status is not good (%d)", val); - if (val == BATTERY_OVERHEAT) { - battery.health = HEALTH_BAD; - battery.charge_now = CHARGER_ABNORMAL; - battery.temp = TEMP_HIGH; - } else if (val == BATTERY_COLD) { - battery.health = HEALTH_BAD; - battery.charge_now = CHARGER_ABNORMAL; - battery.temp = TEMP_LOW; - } else { - battery.health = HEALTH_GOOD; - } -check_full: - ret = device_get_property(DEVICE_TYPE_POWER, PROP_POWER_CHARGE_FULL, &val); - if (ret == 0) - battery.charge_full = val; - noti_batt_full(); - check_battery_status(); - device_notify(DEVICE_NOTIFIER_BATTERY_CHARGING, (void*)battery.charge_now); -} - static int load_uevent(struct parse_result *result, void *user_data) { struct battery_status *info = user_data; @@ -634,29 +589,75 @@ static int load_uevent(struct parse_result *result, void *user_data) static void power_load_uevent(void) { int ret; + static int initialized = POWER_SUPPLY_NOT_READY; + + if (initialized == POWER_SUPPLY_INITIALIZED) + return; ret = config_parse(POWER_SUPPLY_UEVENT, load_uevent, &battery); if (ret < 0) _E("Failed to load %s, %d Use default value!", POWER_SUPPLY_UEVENT, ret); + else + initialized = POWER_SUPPLY_INITIALIZED; +} + +static int sleep_execute(void *data) +{ + static const struct device_ops *ops = NULL; + + FIND_DEVICE_INT(ops, DEVICE_SLEEP_OPS); + return ops->execute(data); } void power_supply(void *data) { int ret; + int status = POWER_SUPPLY_STATUS_DISCHARGING; + static struct battery_status old; - static int old_charge; + if (old.charge_now != battery.charge_now || battery.charge_now == CHARGER_ABNORMAL) { + vconf_set_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, battery.charge_now); + power_supply_broadcast(CHARGE_NOW_SIGNAL, battery.charge_now); + } - if (old_charge != battery.charge_now || battery.charge_now == CHARGER_ABNORMAL) { - old_charge = battery.charge_now; - vconf_set_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, old_charge); - power_supply_broadcast(CHARGE_NOW_SIGNAL, old_charge); + if (old.capacity != battery.capacity) + journal_system_battery_level(battery.capacity); + if (old.online != battery.online || + old.charge_now != battery.charge_now || + old.charge_full != battery.charge_full) { + switch (battery.charge_now) + { + case CHARGER_ABNORMAL: + status = POWER_SUPPLY_STATUS_NOT_CHARGING; + break; + case CHARGER_DISCHARGING: + if (battery.charge_full == CHARGING_FULL) + status = POWER_SUPPLY_STATUS_FULL; + else + status = POWER_SUPPLY_STATUS_DISCHARGING; + break; + case CHARGER_CHARGING: + status = POWER_SUPPLY_STATUS_CHARGING; + break; + } + journal_system_power_supply_status(battery.online, status); } lowbat_monitor(data); check_online(); - noti_batt_full(); + if (old.charge_full != battery.charge_full) { + noti_batt_full(); + } + + old.capacity = battery.capacity; + old.online = battery.online; + old.charge_now = battery.charge_now; + old.charge_full = battery.charge_full; + check_battery_status(); device_notify(DEVICE_NOTIFIER_POWER_SUPPLY, NULL); device_notify(DEVICE_NOTIFIER_BATTERY_CHARGING, (void*)battery.charge_now); + if (battery.online > POWER_SUPPLY_TYPE_BATTERY) + sleep_execute(NULL); } void power_supply_status_init(void) @@ -786,15 +787,96 @@ static DBusMessage *dbus_get_charge_level(E_DBus_Object *obj, DBusMessage *msg) return reply; } +static DBusMessage *dbus_get_percent(E_DBus_Object *obj, DBusMessage *msg) +{ + DBusMessageIter iter; + DBusMessage *reply; + int ret; + + ret = battery.capacity; + + reply = dbus_message_new_method_return(msg); + dbus_message_iter_init_append(reply, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); + return reply; +} + +static DBusMessage *dbus_get_percent_raw(E_DBus_Object *obj, DBusMessage *msg) +{ + DBusMessageIter iter; + DBusMessage *reply; + int ret, val; + + ret = device_get_property(DEVICE_TYPE_POWER, PROP_POWER_CAPACITY_RAW, &val); + if (ret < 0) + goto out; + + if (val > 10000) + val = 10000; + + ret = val; + +out: + reply = dbus_message_new_method_return(msg); + dbus_message_iter_init_append(reply, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); + return reply; +} + +static DBusMessage *dbus_is_full(E_DBus_Object *obj, DBusMessage *msg) +{ + DBusMessageIter iter; + DBusMessage *reply; + int ret; + + ret = battery.charge_full; + + reply = dbus_message_new_method_return(msg); + dbus_message_iter_init_append(reply, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); + return reply; +} + +static DBusMessage *dbus_get_health(E_DBus_Object *obj, DBusMessage *msg) +{ + DBusMessageIter iter; + DBusMessage *reply; + int ret; + + ret = battery.health; + + reply = dbus_message_new_method_return(msg); + dbus_message_iter_init_append(reply, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); + return reply; +} + static const struct edbus_method edbus_methods[] = { - { CHARGER_STATUS_SIGNAL, NULL, "i", dbus_get_charger_status }, - { CHARGE_NOW_SIGNAL, NULL, "i", dbus_get_charge_now }, - { CHARGE_LEVEL_SIGNAL, NULL, "i", dbus_get_charge_level }, + { CHARGER_STATUS_SIGNAL, NULL, "i", dbus_get_charger_status }, + { CHARGE_NOW_SIGNAL, NULL, "i", dbus_get_charge_now }, + { CHARGE_LEVEL_SIGNAL, NULL, "i", dbus_get_charge_level }, + { CHARGE_CAPACITY_SIGNAL, NULL, "i", dbus_get_percent }, + { CHARGE_CAPACITY_LAW_SIGNAL, NULL, "i", dbus_get_percent_raw }, + { CHARGE_FULL_SIGNAL, NULL, "i", dbus_is_full }, + { CHARGE_HEALTH_SIGNAL, NULL, "i", dbus_get_health }, }; +static int alert_popup_cb(keynode_t *key_nodes, void *data) +{ + alert_popup = vconf_keynode_get_bool(key_nodes); + _D("changed alert popup %d", alert_popup); + return alert_popup; +} + int power_supply_init(void *data) { int ret; + + ret = vconf_get_bool(VCONFKEY_TESTMODE_TEMP_ALERT_POPUP, &alert_popup); + if (ret < 0) + _E("fail to get alert popup status"); + vconf_notify_key_changed(VCONFKEY_TESTMODE_TEMP_ALERT_POPUP, (void *)alert_popup_cb, NULL); + ret = register_edbus_method(DEVICED_PATH_BATTERY, edbus_methods, ARRAY_SIZE(edbus_methods)); if (ret < 0) _E("fail to init edbus method(%d)", ret); @@ -804,11 +886,7 @@ int power_supply_init(void *data) if (ret < 0) _E("fail to init edbus signal(%d)", ret); - register_action(PREDEF_BATTERY_CF_OPENED, changed_battery_cf, - NULL, NULL); - /* for simple noti change cb */ - emulator_add_callback("device_charge_chgdet", (void *)charge_cb, data); power_supply_status_init(); power_supply(NULL); return ret; diff --git a/src/core/power-supply.h b/src/core/power-supply.h index 3dd2f94..49d3ea1 100644 --- a/src/core/power-supply.h +++ b/src/core/power-supply.h @@ -20,9 +20,13 @@ #ifndef __POWER_SUPPLY_H__ #define __POWER_SUPPLY_H__ -#define CHARGER_STATUS_SIGNAL "ChargerStatus" -#define CHARGE_NOW_SIGNAL "ChargeNow" -#define CHARGE_LEVEL_SIGNAL "BatteryStatusLow" +#define CHARGER_STATUS_SIGNAL "ChargerStatus" +#define CHARGE_NOW_SIGNAL "ChargeNow" +#define CHARGE_LEVEL_SIGNAL "BatteryStatusLow" +#define CHARGE_CAPACITY_SIGNAL "GetPercent" +#define CHARGE_CAPACITY_LAW_SIGNAL "GetPercentRaw" +#define CHARGE_HEALTH_SIGNAL "GetHealth" +#define CHARGE_FULL_SIGNAL "IsFull" int check_abnormal_popup(void); int check_lowbat_charge_device(int bInserted); diff --git a/src/core/predefine.c b/src/core/predefine.c deleted file mode 100755 index 3b6c515..0000000 --- a/src/core/predefine.c +++ /dev/null @@ -1,273 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include "dd-deviced.h" -#include "log.h" -#include "launch.h" -#include "queue.h" -#include "device-handler.h" -#include "device-node.h" -#include "predefine.h" -#include "proc/proc-handler.h" -#include "data.h" -#include "common.h" -#include "display/poll.h" -#include "display/setting.h" -#include "devices.h" -#include "battery/battery.h" -#include "edbus-handler.h" - -#define VCONFKEY_SYSMAN_FACTORY_MODE "memory/sysman/factory_mode" - -#define PREDEFINE_SO_DIR PREFIX"/lib/ss_predefine/" -#define PREDEF_CALL "call" -#define PREDEF_FACTORY_MODE "factorymode" - -#define CALL_EXEC_PATH PREFIX"/bin/call" - -#define LOWBAT_EXEC_PATH PREFIX"/bin/lowbatt-popup" - -#define HDMI_NOTI_EXEC_PATH PREFIX"/bin/hdmi_connection_noti" - - -static int bFactoryMode = 0; - -int predefine_get_pid(const char *execpath) -{ - DIR *dp; - struct dirent *dentry; - int pid = -1, fd; - int ret; - char buf[PATH_MAX]; - char buf2[PATH_MAX]; - - dp = opendir("/proc"); - if (!dp) { - _E("FAIL: open /proc"); - return -1; - } - - while ((dentry = readdir(dp)) != NULL) { - if (!isdigit(dentry->d_name[0])) - continue; - - pid = atoi(dentry->d_name); - - snprintf(buf, PATH_MAX, "/proc/%d/cmdline", pid); - fd = open(buf, O_RDONLY); - if (fd < 0) - continue; - ret = read(fd, buf2, PATH_MAX); - close(fd); - - if (ret < 0 || ret >=PATH_MAX) - continue; - - buf2[ret] = '\0'; - - if (!strcmp(buf2, execpath)) { - closedir(dp); - return pid; - } - } - - errno = ESRCH; - closedir(dp); - return -1; -} - -#ifdef NOUSE -int call_predefine_action(int argc, char **argv) -{ - char argstr[128]; - int pid; - - if (argc < 2) - return -1; - - snprintf(argstr, sizeof(argstr), "-t MT -n %s -i %s", argv[0], argv[1]); - pid = launch_if_noexist(CALL_EXEC_PATH, argstr); - if (pid < 0) { - _E("call predefine action failed"); - return -1; - } - return pid; -} -#endif - -void predefine_pm_change_state(unsigned int s_bits) -{ - if (is_factory_mode() == 1) - _D("skip LCD control for factory mode"); - else - pm_change_internal(getpid(), s_bits); -} - -int is_factory_mode(void) -{ - return bFactoryMode; -} -int set_factory_mode(int bOn) -{ - int ret = -1; - if ( bOn==1 || bOn==0 ) { - bFactoryMode = bOn; - /* For USB-server to refer the value */ - ret = vconf_set_int(VCONFKEY_SYSMAN_FACTORY_MODE, bOn); - if(ret != 0) { - _E("FAIL: vconf_set_int()"); - } - } - return bFactoryMode; -} - -int factory_mode_action(int argc, char **argv) -{ - int bOn; - if (argc != 1 || argv[0] == NULL) { - _E("Factory Mode Set predefine action failed"); - return -1; - } - bOn = atoi(argv[0]); - bOn = set_factory_mode(bOn); - return 0; - -} - -static void action_entry_load_from_sodir() -{ - DIR *dp; - struct dirent *dentry; - struct sysnoti *msg; - char *ext; - char tmp[128]; - - dp = opendir(PREDEFINE_SO_DIR); - if (!dp) { - _E("fail open %s", PREDEFINE_SO_DIR); - return; - } - - msg = malloc(sizeof(struct sysnoti)); - if (msg == NULL) { - _E("Malloc failed"); - closedir(dp); - return; - } - - msg->pid = getpid(); - - while ((dentry = readdir(dp)) != NULL) { - if ((ext = strstr(dentry->d_name, ".so")) == NULL) - continue; - - snprintf(tmp, sizeof(tmp), "%s/%s", PREDEFINE_SO_DIR, - dentry->d_name); - msg->path = tmp; - *ext = 0; - msg->type = &(dentry->d_name[3]); - register_msg(msg); - } - free(msg); - - closedir(dp); -} - -static DBusMessage *dbus_factory_mode(E_DBus_Object *obj, DBusMessage *msg) -{ - DBusError err; - DBusMessageIter iter; - DBusMessage *reply; - pid_t pid; - int ret; - int argc; - char *type_str; - char *argv; - - dbus_error_init(&err); - - if (!dbus_message_get_args(msg, &err, - DBUS_TYPE_STRING, &type_str, - DBUS_TYPE_INT32, &argc, - DBUS_TYPE_STRING, &argv, DBUS_TYPE_INVALID)) { - _E("there is no message"); - ret = -EINVAL; - goto out; - } - - if (argc < 0) { - _E("message is invalid!"); - ret = -EINVAL; - goto out; - } - - pid = get_edbus_sender_pid(msg); - if (kill(pid, 0) == -1) { - _E("%d process does not exist, dbus ignored!", pid); - ret = -ESRCH; - goto out; - } - - ret = set_factory_mode(atoi(argv)); -out: - reply = dbus_message_new_method_return(msg); - dbus_message_iter_init_append(reply, &iter); - dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); - - return reply; -} - -static const struct edbus_method edbus_methods[] = { - { PREDEF_FACTORY_MODE, "sis", "i", dbus_factory_mode }, -}; - -static void predefine_init(void *data) -{ - /* telephony initialize */ - int ret; - - ret = register_edbus_method(DEVICED_PATH_SYSNOTI, edbus_methods, ARRAY_SIZE(edbus_methods)); - if (ret < 0) - _E("fail to init edbus method(%d)", ret); -#ifdef NOUSE - register_action(PREDEF_CALL, call_predefine_action, NULL, NULL); -#endif - register_action(PREDEF_FACTORY_MODE, factory_mode_action, NULL, NULL); - - action_entry_load_from_sodir(); -} - -static const struct device_ops predefine_device_ops = { - .priority = DEVICE_PRIORITY_NORMAL, - .name = "predefine", - .init = predefine_init, -}; - -DEVICE_OPS_REGISTER(&predefine_device_ops) diff --git a/src/core/queue.c b/src/core/queue.c deleted file mode 100644 index d0da9b2..0000000 --- a/src/core/queue.c +++ /dev/null @@ -1,283 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include "data.h" -#include "core.h" -#include "queue.h" -#include "log.h" -#include "list.h" - -#define PREDEFINE_ACT_FUNC_STR "predefine_action" -#define IS_ACCESSIBLE_FUNC_STR "is_accessible" -#define UI_VIEWABLE_FUNC_STR "ui_viewable" - -static dd_list *predef_act_list; -static dd_list *run_queue; - -static struct action_entry *find_action_entry(char *type) -{ - dd_list *tmp; - struct action_entry *data; - - DD_LIST_FOREACH(predef_act_list, tmp, data) { - if (!strcmp(data->type, type)) - return data; - } - - return NULL; -} - -int register_action(char *type, - int (*predefine_action) (), - int (*ui_viewable) (), - int (*is_accessible) (int)) -{ - struct action_entry *data; - - data = malloc(sizeof(struct action_entry)); - - if (data == NULL) { - _E("Malloc failed"); - return -1; - } - - data->type = NULL; - if (find_action_entry(type) != NULL) - goto err; - - data->handle = NULL; - data->predefine_action = predefine_action; - if (data->predefine_action == NULL) - goto err; - - data->is_accessible = is_accessible; - data->ui_viewable = ui_viewable; - data->owner_pid = getpid(); - data->type = strdup(type); - data->path = strdup(""); - - DD_LIST_PREPEND(predef_act_list, data); - - _D("add predefine action entry suceessfully - %s", - data->type); - return 0; - err: - if (data->type != NULL) - _E("adding predefine action entry failed - %s", - data->type); - free(data); - return -1; -} - -int register_msg(struct sysnoti *msg) -{ - struct action_entry *data; - - data = malloc(sizeof(struct action_entry)); - - if (data == NULL) { - _E("Malloc failed"); - return -1; - } - - if (find_action_entry(msg->type) != NULL) - goto err; - - data->handle = dlopen(msg->path, RTLD_LAZY); - if (!data->handle) { - _E("cannot find such library"); - goto err; - } - - data->predefine_action = dlsym(data->handle, PREDEFINE_ACT_FUNC_STR); - if (data->predefine_action == NULL) { - _E("cannot find predefine_action symbol : %s", - PREDEFINE_ACT_FUNC_STR); - goto err; - } - - data->is_accessible = dlsym(data->handle, IS_ACCESSIBLE_FUNC_STR); - data->ui_viewable = dlsym(data->handle, UI_VIEWABLE_FUNC_STR); - data->owner_pid = msg->pid; - data->type = strdup(msg->type); - data->path = strdup(msg->path); - - DD_LIST_PREPEND(predef_act_list, data); - - _D("add predefine action entry suceessfully - %s", - data->type); - return 0; - err: - _E("adding predefine action entry failed - %s", msg->type); - free(data); - return -1; -} - -int notify_action(char *type, int argc, ...) -{ - dd_list *tmp; - struct action_entry *data; - va_list argptr; - int i; - int ret; - char *args = NULL; - char *argv[SYSMAN_MAXARG]; - - if (argc > SYSMAN_MAXARG || type == NULL) - return -1; - - DD_LIST_FOREACH(predef_act_list, tmp, data) { - if (strcmp(data->type, type)) - continue; - va_start(argptr, argc); - for (i = 0; i < argc; i++) { - args = va_arg(argptr, char *); - if (args != NULL) - argv[i] = strdup(args); - else - argv[i] = NULL; - } - va_end(argptr); - ret=run_queue_add(data, argc, argv); - ret=core_action_run(); - return 0; - } - - return 0; -} - -int notify_msg(struct sysnoti *msg, int sockfd) -{ - dd_list *tmp; - struct action_entry *data; - int ret; - - DD_LIST_FOREACH(predef_act_list, tmp, data) { - if (strcmp(data->type, msg->type)) - continue; - if (data->is_accessible != NULL - && data->is_accessible(sockfd) == 0) { - _E("%d cannot call that predefine module", msg->pid); - return -1; - } - ret=run_queue_add(data, msg->argc, msg->argv); - ret=core_action_run(); - return 0; - } - - _E("cannot found action"); - return -1; -} - -int run_queue_add(struct action_entry *act_entry, int argc, char **argv) -{ - struct run_queue_entry *rq_entry; - int i; - - rq_entry = malloc(sizeof(struct run_queue_entry)); - - if (rq_entry == NULL) { - _E("Malloc failed"); - return -1; - } - - rq_entry->state = STATE_INIT; - rq_entry->action_entry = act_entry; - rq_entry->forked_pid = 0; - if ( argc < 0 ) { - rq_entry->argc = 0; - } else { - rq_entry->argc = argc; - for (i = 0; i < argc; i++) - rq_entry->argv[i] = argv[i]; - } - - DD_LIST_PREPEND(run_queue, rq_entry); - - return 0; -} - -int run_queue_run(enum run_state state, - int (*run_func) (void *, struct run_queue_entry *), - void *user_data) -{ - dd_list *tmp; - struct run_queue_entry *rq_entry; - - DD_LIST_FOREACH(run_queue, tmp, rq_entry) { - if (rq_entry->state == state) - run_func(user_data, rq_entry); - } - - return 0; -} - -struct run_queue_entry *run_queue_find_bypid(int pid) -{ - dd_list *tmp; - struct run_queue_entry *rq_entry; - - DD_LIST_FOREACH(run_queue, tmp, rq_entry) { - if (rq_entry->forked_pid == pid) - return rq_entry; - } - - return NULL; -} - -int run_queue_del(struct run_queue_entry *entry) -{ - dd_list *tmp; - struct run_queue_entry *rq_entry; - int i; - - DD_LIST_FOREACH(run_queue, tmp, rq_entry) { - if (rq_entry == entry) { - DD_LIST_REMOVE(run_queue, rq_entry); - for (i = 0; i < rq_entry->argc; i++) { - if (rq_entry->argv[i]) - free(rq_entry->argv[i]); - } - free(rq_entry); - } - } - - return 0; -} - -int run_queue_del_bypid(int pid) -{ - dd_list *tmp; - struct run_queue_entry *rq_entry; - int i; - - DD_LIST_FOREACH(run_queue, tmp, rq_entry) { - if (rq_entry->forked_pid == pid) { - DD_LIST_REMOVE(run_queue, rq_entry); - for (i = 0; i < rq_entry->argc; i++) { - if (rq_entry->argv[i]) - free(rq_entry->argv[i]); - } - free(rq_entry); - } - } - - return 0; -} diff --git a/src/core/queue.h b/src/core/queue.h deleted file mode 100644 index dee1e7e..0000000 --- a/src/core/queue.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#ifndef __QUEUE_H__ -#define __QUEUE_H__ - -#include "sysnoti.h" - -struct action_entry { - int owner_pid; - void *handle; - char *type; - char *path; - int (*predefine_action) (); - int (*ui_viewable) (); - int (*is_accessible) (int caller_sockfd); -}; - -enum run_state { - STATE_INIT, - STATE_RUNNING, - STATE_DONE -}; - -struct run_queue_entry { - enum run_state state; - struct action_entry *action_entry; - int forked_pid; - int argc; - char *argv[SYSMAN_MAXARG]; -}; - -int register_action(char *type, - int (*predefine_action) (), - int (*ui_viewable) (), - int (*is_accessible) (int)); -int notify_action(char *type, int argc, ...); - -int register_msg(struct sysnoti *msg); -int notify_msg(struct sysnoti *msg, int sockfd); - -int run_queue_run(enum run_state state, - int (*run_func) (void *, struct run_queue_entry *), - void *user_data); - -struct run_queue_entry *run_queue_find_bypid(int pid); -int run_queue_add(struct action_entry *act_entry, int argc, char **argv); -int run_queue_del(struct run_queue_entry *entry); -int run_queue_del_bypid(int pid); - -#endif /* __QUEUE_H__ */ diff --git a/src/core/sig-handler.c b/src/core/sig-handler.c index 89deee8..13e9544 100644 --- a/src/core/sig-handler.c +++ b/src/core/sig-handler.c @@ -21,7 +21,6 @@ #include #include #include -#include "core.h" #include "log.h" #include "edbus-handler.h" #include "display/poll.h" diff --git a/src/core/sysnoti.c b/src/core/sysnoti.c deleted file mode 100755 index 7fe6b2f..0000000 --- a/src/core/sysnoti.c +++ /dev/null @@ -1,342 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include -#include -#include -#include "data.h" -#include "log.h" -#include "queue.h" -#include "common.h" -#include "devices.h" - -#define SYSNOTI_SOCKET_PATH "/tmp/sn" -#define RETRY_READ_COUNT 5 -enum sysnoti_cmd { - REGISTER_MSG, - NOTIFY_MSG -}; - -static Ecore_Fd_Handler *sysnoti_efd = NULL; -static int sysnoti_fd; -static int __sysnoti_start(void); -static int __sysnoti_stop(int fd); - -static void print_sysnoti_msg(const char *title, struct sysnoti *msg) -{ - int i; - char exe_name[PATH_MAX]; - - if (get_cmdline_name(msg->pid, exe_name, PATH_MAX) < 0) - snprintf(exe_name, sizeof(exe_name), "Unknown (maybe dead)"); - - _SD("pid : %d name: %s cmd : %d type : %s path : %s", - msg->pid, exe_name, msg->cmd, msg->type, msg->path); -} - -static inline int recv_int(int fd) -{ - int val, r = -1; - int retry_count = 0; - while (retry_count < RETRY_READ_COUNT) { - r = read(fd, &val, sizeof(int)); - if (r < 0) { - if(errno == EINTR) { - _D("Re-read for error(EINTR)"); - retry_count++; - continue; - } - else { - _E("Read fail for int"); - return -1; - } - } else { - return val; - } - } - return -1; -} - -static inline char *recv_str(int fd) -{ - int len, r = -1; - int retry_count = 0; - char *str; - - while (retry_count < RETRY_READ_COUNT) { - r = read(fd, &len, sizeof(int)); - if (r < 0) { - if(errno == EINTR) { - _D("Re-read for error(EINTR)"); - retry_count++; - continue; - } - else { - _E("Read fail for str length"); - return NULL; - } - } else - break; - } - if (retry_count == RETRY_READ_COUNT) { - _E("Read retry failed"); - return NULL; - } - if (len <= 0) - return NULL; - - if (len >= INT_MAX) { - _E("size is over INT_MAX"); - return NULL; - } - - str = (char *)malloc(len + 1); - if (str == NULL) { - _E("Not enough memory"); - return NULL; - } - retry_count = 0; - while (retry_count < RETRY_READ_COUNT) { - r = read(fd, str, len); - if(r < 0) { - if(errno == EINTR) { - _D("Re-read for error(EINTR)"); - retry_count++; - continue; - } else { - _E("Read fail for str"); - free(str); - str = NULL; - return NULL; - } - } else - break; - } - if (retry_count == RETRY_READ_COUNT) { - _E("Read retry failed"); - free(str); - str = NULL; - return NULL; - } - - str[len] = 0; - return str; -} - -static int read_message(int fd, struct sysnoti *msg) -{ - int i; - - if ((msg->pid = recv_int(fd)) == -1) - return -1; - if ((msg->cmd = recv_int(fd)) == -1) - return -1; - if ((msg->type = recv_str(fd)) == NULL) - return -1; - msg->path = recv_str(fd); - msg->argc = recv_int(fd); - - if (msg->argc < 0) - return -1; - for (i = 0; i < msg->argc; i++) - msg->argv[i] = recv_str(fd); - - return 0; -} - -static inline void internal_free(char *str) -{ - if (str) - free(str); -} - -static inline void free_message(struct sysnoti *msg) -{ - internal_free(msg->type); - internal_free(msg->path); - free(msg); -} - -static Eina_Bool sysnoti_cb(void *data, Ecore_Fd_Handler * fd_handler) -{ - struct sysnoti *msg; - int ret = -1; - struct sockaddr_un client_address; - int client_sockfd; - int client_len; - - if (!ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ)) { - _E("ecore_main_fd_handler_active_get error , return"); - goto out; - } - - msg = malloc(sizeof(struct sysnoti)); - if (msg == NULL) { - _E("Not enough memory"); - goto out; - } - - client_len = sizeof(client_address); - client_sockfd = accept(sysnoti_fd, (struct sockaddr *)&client_address, (socklen_t *)&client_len); - - if (client_sockfd == -1) { - _E("socket accept error"); - free(msg); - goto out; - } - if (read_message(client_sockfd, msg) < 0) { - _E("recv error msg"); - print_sysnoti_msg(__FUNCTION__, msg); - free_message(msg); - write(client_sockfd, &ret, sizeof(int)); - close(client_sockfd); - __sysnoti_stop(sysnoti_fd); - __sysnoti_start(); - goto out; - } - - print_sysnoti_msg(__FUNCTION__, msg); - if (msg->argc > SYSMAN_MAXARG) { - _E("error argument"); - free_message(msg); - write(client_sockfd, &ret, sizeof(int)); - close(client_sockfd); - goto out; - } - - switch (msg->cmd) { -#ifdef NOUSE - case REGISTER_MSG: - ret = register_msg(msg); - _E("%d", ret); - break; -#endif - case NOTIFY_MSG: - ret = notify_msg(msg, client_sockfd); - break; - default: - ret = -1; - } - - - write(client_sockfd, &ret, sizeof(int)); - close(client_sockfd); - - free_message(msg); -out: - return EINA_TRUE; -} - -static int sysnoti_server_init(void) -{ - int fd; - struct sockaddr_un serveraddr; - - if (access(SYSNOTI_SOCKET_PATH, F_OK) == 0) - unlink(SYSNOTI_SOCKET_PATH); - - fd = socket(AF_UNIX, SOCK_STREAM, 0); - if (fd < 0) { - _E("socket create failed"); - return -1; - } - if((fsetxattr(fd, "security.SMACK64IPOUT", "@", 2, 0)) < 0 ) { - _E("Socket SMACK labeling failed"); - if(errno != EOPNOTSUPP) { - close(fd); - return -1; - } - } - - if((fsetxattr(fd, "security.SMACK64IPIN", "*", 2, 0)) < 0 ) { - _E("Socket SMACK labeling failed"); - if(errno != EOPNOTSUPP) { - close(fd); - return -1; - } - } - - bzero(&serveraddr, sizeof(struct sockaddr_un)); - serveraddr.sun_family = AF_UNIX; - strncpy(serveraddr.sun_path, SYSNOTI_SOCKET_PATH, - sizeof(serveraddr.sun_path)); - - if (bind(fd, (struct sockaddr *)&serveraddr, sizeof(struct sockaddr)) < 0) { - _E("socket bind failed"); - close(fd); - return -1; - } - - if (chmod(SYSNOTI_SOCKET_PATH, (S_IRWXU | S_IRWXG | S_IRWXO)) < 0) /* 0777 */ - _E("failed to change the socket permission"); - - if (listen(fd, 5) < 0) { - _E("failed to listen"); - close(fd); - return -1; - } - - return fd; -} - -static int __sysnoti_start(void) -{ - sysnoti_fd = sysnoti_server_init(); - if ( sysnoti_fd < 0 ) - return -1; - sysnoti_efd = ecore_main_fd_handler_add(sysnoti_fd, ECORE_FD_READ, sysnoti_cb, NULL, NULL, - NULL); - if (!sysnoti_efd) { - _E("error ecore_main_fd_handler_add"); - close(sysnoti_fd); - return -1; - } - return 0; -} - -static int __sysnoti_stop(int fd) -{ - if (sysnoti_efd) { - ecore_main_fd_handler_del(sysnoti_efd); - sysnoti_efd = NULL; - } - if (fd >=0) { - close(fd); - fd = -1; - } - return 0; -} - -static void sysnoti_init(void *data) -{ - struct main_data *ad = (struct main_data*)data; - - if (__sysnoti_start() == -1) - _E("fail sys socket fd init"); -} - -static const struct device_ops sysnoti_device_ops = { - .priority = DEVICE_PRIORITY_NORMAL, - .name = "sysnoti", - .init = sysnoti_init, -}; - -DEVICE_OPS_REGISTER(&sysnoti_device_ops) diff --git a/src/cpu/cpu-handler.c b/src/cpu/cpu-handler.c index bc17054..297a1c0 100644 --- a/src/cpu/cpu-handler.c +++ b/src/cpu/cpu-handler.c @@ -23,18 +23,19 @@ #include "core/list.h" #include "core/log.h" -#include "core/data.h" #include "core/devices.h" #include "core/edbus-handler.h" #include "core/common.h" #include "core/device-notifier.h" #include "proc/proc-handler.h" -#define PREDEF_SET_MAX_FREQUENCY "set_max_frequency" -#define PREDEF_SET_MIN_FREQUENCY "set_min_frequency" -#define PREDEF_RELEASE_MAX_FREQUENCY "release_max_frequency" -#define PREDEF_RELEASE_MIN_FREQUENCY "release_min_frequency" -#define PREDEF_CPU_COUNT "set_cpu_count" +#define SET_MAX_FREQ "set_max_frequency" +#define SET_MIN_FREQ "set_min_frequency" +#define SET_FREQ_LEN 17 + +#define RELEASE_MAX_FREQ "release_max_frequency" +#define RELEASE_MIN_FREQ "release_min_frequency" +#define RELEASE_FREQ_LEN 21 #define POWER_SAVING_CPU_FREQ_RATE (0.7) @@ -343,13 +344,12 @@ static void set_emergency_limit(void) _E("failed to get vconf key"); return; } - if (val != SETTING_PSMODE_EMERGENCY) - return; - - val = EMERGENCY_LOCK; - device_notify(DEVICE_NOTIFIER_PMQOS_EMERGENCY, (void*)val); - + if (val == SETTING_PSMODE_EMERGENCY) { + val = EMERGENCY_LOCK; + device_notify(DEVICE_NOTIFIER_PMQOS_EMERGENCY, (void*)val); + } } + static int emergency_cpu_cb(keynode_t *key_nodes, void *data) { int val; @@ -485,44 +485,6 @@ static int add_entry_to_cpu_number_list(int pid, int number) return 0; } -int set_cpu_number_action(int argc, char **argv) -{ - int r; - - if(cur_siop_level() != 0) - return -EINVAL; - - if (argc == 1) {// release cpu number - r = remove_entry_from_cpu_number_list(atoi(argv[0])); - if (r < 0) { - _E("Remove entry failed"); - return r; - } - - if (cur_cpu_number == INT_MAX) - cur_cpu_number = cpu_number_limit; - - r = write_cpu_number(cur_cpu_number); - if (r < 0) { - _E("Write cpu number failed"); - return r; - } - } else if (argc ==2) {//set cpu number - r = add_entry_to_cpu_number_list(atoi(argv[0]), atoi(argv[1])); - if (r < 0) { - _E("Add entry failed"); - return r; - } - - r = write_cpu_number(cur_cpu_number); - if (r < 0) { - _E("Write entry failed"); - return r; - } - } - return 0; -} - static int booting_done(void *data) { set_freq_limit(); @@ -566,13 +528,13 @@ static DBusMessage *dbus_cpu_handler(E_DBus_Object *obj, DBusMessage *msg) goto out; } - if (strncmp(type_str, PREDEF_SET_MAX_FREQUENCY, strlen(PREDEF_SET_MAX_FREQUENCY)) == 0) + if (!strncmp(type_str, SET_MAX_FREQ, SET_FREQ_LEN)) ret = set_max_frequency_action(argc, (char **)&argv); - else if (strncmp(type_str, PREDEF_SET_MIN_FREQUENCY, strlen(PREDEF_SET_MIN_FREQUENCY)) == 0) + else if (!strncmp(type_str, SET_MIN_FREQ, SET_FREQ_LEN)) ret = set_min_frequency_action(argc, (char **)&argv); - else if (strncmp(type_str, PREDEF_RELEASE_MAX_FREQUENCY, strlen(PREDEF_RELEASE_MAX_FREQUENCY)) == 0) + else if (!strncmp(type_str, RELEASE_MAX_FREQ, RELEASE_FREQ_LEN)) ret = release_max_frequency_action(argc, (char **)&argv); - else if (strncmp(type_str, PREDEF_RELEASE_MIN_FREQUENCY, strlen(PREDEF_RELEASE_MIN_FREQUENCY)) == 0) + else if (!strncmp(type_str, RELEASE_MIN_FREQ, RELEASE_FREQ_LEN)) ret = release_min_frequency_action(argc, (char **)&argv); out: reply = dbus_message_new_method_return(msg); @@ -583,10 +545,10 @@ out: } static const struct edbus_method edbus_methods[] = { - { PREDEF_SET_MAX_FREQUENCY, "siss", "i", dbus_cpu_handler }, - { PREDEF_SET_MIN_FREQUENCY, "siss", "i", dbus_cpu_handler }, - { PREDEF_RELEASE_MAX_FREQUENCY, "siss", "i", dbus_cpu_handler }, - { PREDEF_RELEASE_MIN_FREQUENCY, "siss", "i", dbus_cpu_handler }, + { SET_MAX_FREQ, "siss", "i", dbus_cpu_handler }, + { SET_MIN_FREQ, "siss", "i", dbus_cpu_handler }, + { RELEASE_MAX_FREQ, "siss", "i", dbus_cpu_handler }, + { RELEASE_MIN_FREQ, "siss", "i", dbus_cpu_handler }, }; static void cpu_init(void *data) @@ -598,11 +560,6 @@ static void cpu_init(void *data) if (ret < 0) _E("fail to init edbus method(%d)", ret); set_cpu_number_limit(); - register_action(PREDEF_SET_MAX_FREQUENCY, set_max_frequency_action, NULL, NULL); - register_action(PREDEF_SET_MIN_FREQUENCY, set_min_frequency_action, NULL, NULL); - register_action(PREDEF_RELEASE_MAX_FREQUENCY, release_max_frequency_action, NULL, NULL); - register_action(PREDEF_RELEASE_MIN_FREQUENCY, release_min_frequency_action, NULL, NULL); - register_action(PREDEF_CPU_COUNT, set_cpu_number_action, NULL, NULL); vconf_notify_key_changed(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, (void *)power_saving_cpu_cb, NULL); vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE, (void *)emergency_cpu_cb, NULL); diff --git a/src/devicectl/CMakeLists.txt b/src/devicectl/CMakeLists.txt index 5d12dc4..b5e2e3c 100755 --- a/src/devicectl/CMakeLists.txt +++ b/src/devicectl/CMakeLists.txt @@ -7,6 +7,7 @@ ENDIF() SET(SRCS devicectl.c + usb.c ) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src) diff --git a/src/devicectl/devicectl.c b/src/devicectl/devicectl.c index d9dcfef..18f195f 100644 --- a/src/devicectl/devicectl.c +++ b/src/devicectl/devicectl.c @@ -23,6 +23,7 @@ #include #include #include +#include "usb.h" /* * devicectl [device] [action] @@ -35,6 +36,7 @@ enum device_type { DEVICE_DISPLAY, DEVICE_LED, DEVICE_PASS, + DEVICE_USB, DEVICE_MAX, DEVICE_ALL, }; @@ -50,6 +52,7 @@ static const struct device { { DEVICE_DISPLAY, "display", DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY }, { DEVICE_LED, "led", DEVICED_PATH_LED, DEVICED_INTERFACE_LED }, { DEVICE_PASS, "pass", DEVICED_PATH_PASS, DEVICED_INTERFACE_PASS }, + { DEVICE_USB, "usb", DEVICED_PATH_USB, DEVICED_INTERFACE_USB }, }; static int start_device(char **args) @@ -144,28 +147,64 @@ static int save_log(char **args) return 0; } +static int set_usb_mode(char **args) +{ + return load_usb_mode(args[3]); +} + +static int unset_usb_mode(char **args) +{ + return unload_usb_mode(args[3]); +} + static const struct action { const enum device_type id; const char *action; const int argc; int (* const func)(char **args); + const char *option; } actions[] = { - { DEVICE_ALL, "start", 3, start_device }, - { DEVICE_ALL, "stop", 3, stop_device }, - { DEVICE_DISPLAY, "dumpmode", 4, dump_mode }, - { DEVICE_LED, "dumpmode", 4, dump_mode }, - { DEVICE_DISPLAY, "savelog", 3, save_log }, + { DEVICE_ALL, "start", 3, start_device, "" }, + { DEVICE_ALL, "stop", 3, stop_device, "" }, + { DEVICE_DISPLAY, "dumpmode", 4, dump_mode, "[on|off]" }, + { DEVICE_LED, "dumpmode", 4, dump_mode, "[on|off]" }, + { DEVICE_DISPLAY, "savelog", 3, save_log, "" }, + { DEVICE_USB, "set", 4, set_usb_mode, "[sdb|ssh]" }, + { DEVICE_USB, "unset", 4, unset_usb_mode, "[sdb|ssh]" }, }; static inline void usage() { printf("[usage] devicectl \n"); + printf("Please use option --help to check options\n"); +} + +static void help() +{ + int i; + + printf("[usage] devicectl