From ca6f7bc18e496192a1969273d8f239d69f605156 Mon Sep 17 00:00:00 2001 From: "jy910.yun" Date: Wed, 26 Jun 2013 11:08:10 +0900 Subject: [PATCH] refactoring src diretory structure forder structure changed like systemd. default directory of codes is 'src'. other directory was made by functions under 'src'. directory details : src/core - common, core, edbus-handler, device-change, launch, main, predefine, sig-handler, noti src/cpu - cpu-handler src/led - led src/mmc - mmc src/power - power, lowbat src/proc - lowmem, process monitor, process manager src/ta - ta src/time - time src/usb - usb Signed-off-by: giyeol.ok Change-Id: If5b117b7f4d21bac446f7018241fba788252fae0 --- CMakeLists.txt | 52 +- debian/compat | 1 - debian/control | 30 - debian/rules | 128 ---- debian/system-server-bin.install.in | 3 - debian/system-server-bin.postinst.in | 47 -- display/core.c | 9 +- display/key-filter.c | 11 +- display/poll.h | 2 +- display/setting.c | 2 +- display/x-lcd-on.c | 17 +- include/ss_data.h | 113 ---- movi_format.sh => scripts/movi_format.sh | 0 .../battery/lowbat-handler.c | 157 ++++- src/battery/lowbat-handler.h | 25 + ss_bs.c => src/bs/bs.c | 5 +- ss_bs.h => src/bs/bs.h | 0 ss_common.c => src/core/common.c | 2 +- ss_common.h => src/core/common.h | 2 + ss_core.c => src/core/core.c | 10 +- ss_core.h => src/core/core.h | 2 +- src/core/data.h | 28 + .../core/device-change-handler.c | 90 ++- ss_device_handler.h => src/core/device-handler.h | 2 +- edbus-handler.c => src/core/edbus-handler.c | 6 +- edbus-handler.h => src/core/edbus-handler.h | 0 ss_launch.c => src/core/launch.c | 6 +- ss_launch.h => src/core/launch.h | 0 ss_log.c => src/core/log.c | 0 ss_log.h => src/core/log.h | 0 ss_main.c => src/core/main.c | 41 +- ss_noti.c => src/core/noti.c | 2 +- ss_noti.h => src/core/noti.h | 0 src/core/predefine.c | 193 ++++++ ss_predefine.h => src/core/predefine.h | 3 +- ss_queue.c => src/core/queue.c | 8 +- ss_queue.h => src/core/queue.h | 2 +- ss_sig_handler.c => src/core/sig-handler.c | 37 +- ss_sig_handler.h => src/core/sig-handler.h | 0 ss_sysnoti.c => src/core/sysnoti.c | 8 +- ss_sysnoti.h => src/core/sysnoti.h | 0 ss_cpu_handler.c => src/cpu/cpu-handler.c | 27 +- ss_cpu_handler.h => src/cpu/cpu-handler.h | 0 src/led/led.c | 10 +- src/led/led.h | 2 +- ss_mmc_handler.c => src/mmc/mmc-handler.c | 17 +- ss_predefine.c => src/power/power-handler.c | 721 +++++---------------- src/power/power-handler.h | 29 + ss_lowmem_handler.c => src/proc/lowmem-handler.c | 148 ++++- src/proc/lowmem-handler.h | 25 + ss_pmon_handler.c => src/proc/pmon-handler.c | 9 +- ss_pmon_handler.h => src/proc/pmon-handler.h | 2 +- ss_procmgr.c => src/proc/proc-handler.c | 43 +- ss_procmgr.h => src/proc/proc-handler.h | 0 ss_ta_handler.c => src/ta/ta-handler.c | 4 +- ss_timemgr.c => src/time/time-handler.c | 9 +- ss_timemgr.h => src/time/time-handler.h | 0 ss_usb_handler.c => src/usb/usb-handler.c | 6 +- ss_vibrator.c => src/vibrator/vibrator.c | 16 +- ss_vibrator.h => src/vibrator/vibrator.h | 1 + sys_pci_noti/sys_pci_noti.c | 4 +- mmc-smack-label => utils/mmc-smack-label | 0 62 files changed, 1033 insertions(+), 1084 deletions(-) delete mode 100644 debian/compat delete mode 100644 debian/control delete mode 100755 debian/rules delete mode 100644 debian/system-server-bin.install.in delete mode 100644 debian/system-server-bin.postinst.in delete mode 100644 include/ss_data.h rename movi_format.sh => scripts/movi_format.sh (100%) rename ss_lowbat_handler.c => src/battery/lowbat-handler.c (70%) mode change 100755 => 100644 create mode 100644 src/battery/lowbat-handler.h rename ss_bs.c => src/bs/bs.c (99%) rename ss_bs.h => src/bs/bs.h (100%) rename ss_common.c => src/core/common.c (99%) rename ss_common.h => src/core/common.h (81%) rename ss_core.c => src/core/core.c (96%) rename ss_core.h => src/core/core.h (96%) create mode 100644 src/core/data.h rename ss_device_change_handler.c => src/core/device-change-handler.c (89%) mode change 100755 => 100644 rename ss_device_handler.h => src/core/device-handler.h (97%) rename edbus-handler.c => src/core/edbus-handler.c (97%) rename edbus-handler.h => src/core/edbus-handler.h (100%) rename ss_launch.c => src/core/launch.c (98%) rename ss_launch.h => src/core/launch.h (100%) rename ss_log.c => src/core/log.c (100%) rename ss_log.h => src/core/log.h (100%) rename ss_main.c => src/core/main.c (78%) rename ss_noti.c => src/core/noti.c (98%) rename ss_noti.h => src/core/noti.h (100%) create mode 100644 src/core/predefine.c rename ss_predefine.h => src/core/predefine.h (91%) rename ss_queue.c => src/core/queue.c (98%) rename ss_queue.h => src/core/queue.h (98%) rename ss_sig_handler.c => src/core/sig-handler.c (64%) rename ss_sig_handler.h => src/core/sig-handler.h (100%) rename ss_sysnoti.c => src/core/sysnoti.c (98%) mode change 100755 => 100644 rename ss_sysnoti.h => src/core/sysnoti.h (100%) rename ss_cpu_handler.c => src/cpu/cpu-handler.c (97%) rename ss_cpu_handler.h => src/cpu/cpu-handler.h (100%) rename ss_mmc_handler.c => src/mmc/mmc-handler.c (98%) rename ss_predefine.c => src/power/power-handler.c (52%) create mode 100644 src/power/power-handler.h rename ss_lowmem_handler.c => src/proc/lowmem-handler.c (70%) create mode 100644 src/proc/lowmem-handler.h rename ss_pmon_handler.c => src/proc/pmon-handler.c (98%) rename ss_pmon_handler.h => src/proc/pmon-handler.h (96%) rename ss_procmgr.c => src/proc/proc-handler.c (91%) mode change 100755 => 100644 rename ss_procmgr.h => src/proc/proc-handler.h (100%) rename ss_ta_handler.c => src/ta/ta-handler.c (96%) rename ss_timemgr.c => src/time/time-handler.c (97%) rename ss_timemgr.h => src/time/time-handler.h (100%) rename ss_usb_handler.c => src/usb/usb-handler.c (95%) rename ss_vibrator.c => src/vibrator/vibrator.c (96%) rename ss_vibrator.h => src/vibrator/vibrator.h (96%) rename mmc-smack-label => utils/mmc-smack-label (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index d2259bf..f320d61 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,29 +11,31 @@ SET(DEVICED_NAME deviced) SET(VERSION 0.1.0) SET(SRCS - ss_main.c - ss_sysnoti.c - ss_launch.c - ss_queue.c - ss_core.c - ss_sig_handler.c - ss_log.c - ss_device_change_handler.c - ss_predefine.c - ss_noti.c - ss_lowbat_handler.c - ss_lowmem_handler.c - ss_pmon_handler.c - ss_mmc_handler.c - ss_usb_handler.c - ss_ta_handler.c - ss_bs.c - ss_procmgr.c - ss_timemgr.c - ss_cpu_handler.c - ss_common.c - ss_vibrator.c - edbus-handler.c) + src/battery/lowbat-handler.c + src/bs/bs.c + src/core/main.c + src/core/sysnoti.c + src/core/launch.c + src/core/queue.c + src/core/core.c + src/core/sig-handler.c + src/core/log.c + src/core/device-change-handler.c + src/core/predefine.c + src/core/noti.c + src/core/common.c + src/core/edbus-handler.c + src/cpu/cpu-handler.c + src/mmc/mmc-handler.c + src/power/power-handler.c + src/proc/lowmem-handler.c + src/proc/pmon-handler.c + src/proc/proc-handler.c + src/ta/ta-handler.c + src/time/time-handler.c + src/usb/usb-handler.c + src/vibrator/vibrator.c +) SET(SRCS ${SRCS} display/util.c @@ -76,7 +78,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/disp # libdeviced INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src/deviced) -SET(MOVINAND_FORMAT movi_format.sh) +SET(MOVINAND_FORMAT scripts/movi_format.sh) INCLUDE(FindPkgConfig) pkg_check_modules(pkgs REQUIRED @@ -147,7 +149,7 @@ INSTALL(FILES ${UDEV_RULES} DESTINATION ${UDEV_RULES_PATH}) INSTALL(PROGRAMS ${CMAKE_BINARY_DIR}/device-daemon DESTINATION bin) INSTALL(FILES system-server.conf DESTINATION /etc/dbus-1/system.d) INSTALL(FILES ${CMAKE_SOURCE_DIR}/packaging/system-server.rule DESTINATION /opt/etc/smack/accesses.d) -INSTALL(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/mmc-smack-label DESTINATION bin) +INSTALL(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/utils/mmc-smack-label DESTINATION bin) INSTALL(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/utils/set_pmon DESTINATION bin) INSTALL(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/utils/regpmon DESTINATION bin) INSTALL(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/utils/pmon DESTINATION bin) diff --git a/debian/compat b/debian/compat deleted file mode 100644 index 7ed6ff8..0000000 --- a/debian/compat +++ /dev/null @@ -1 +0,0 @@ -5 diff --git a/debian/control b/debian/control deleted file mode 100644 index 566063b..0000000 --- a/debian/control +++ /dev/null @@ -1,30 +0,0 @@ -Source: system-server -Section: tools -Priority: extra -Maintainer: Jonghoon Han Jinkun Jang DongGi Jang TAESOO JUN -Uploaders: Jinkun Jang Wonil Choi -Build-Depends: debhelper (>= 5), - libecore-dev, - libheynoti-dev, - libslp-setting-dev, - libslp-sysman-dev, - libslp-tapi-dev, - libslp-pm-dev, - libdevman-dev, - libdevman-plugin-dev, - libedbus-dev, - dlog-dev, - syspopup-caller-dev, - libattr1-dev -Standards-Version: 3.7.2 - -Package: system-server-bin -Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends} -Description: System server - -Package: system-server-bin-dbg -Section: debug -Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, system-server-bin (= ${Source-Version}) -Description: System server degug package (unstripped) diff --git a/debian/rules b/debian/rules deleted file mode 100755 index bff6ad4..0000000 --- a/debian/rules +++ /dev/null @@ -1,128 +0,0 @@ -#!/usr/bin/make -f - -# Uncomment this to turn on verbose mode. -#export DH_VERBOSE=1 - -CFLAGS ?= -Wall -g -LDFLAGS ?= -PREFIX ?= /usr -DATADIR ?= /opt - -ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) - CFLAGS += -O0 -else - CFLAGS += -O2 -endif - -LDFLAGS += -Wl,--rpath=$(PREFIX)/lib -Wl,--as-needed - -configure: configure-stamp -configure-stamp: - dh_testdir - # Add here commands to configure the package. - CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" cmake . -DCMAKE_INSTALL_PREFIX=$(PREFIX) - - touch configure-stamp - - -build: build-stamp - -build-stamp: configure-stamp - dh_testdir - - # Add here commands to compile the package. - $(MAKE) - - for f in `find $(CURDIR)/debian/ -name "*.in"`; do \ - cat $$f > $${f%.in}; \ - sed -i -e "s#@PREFIX@#$(PREFIX)#g" $${f%.in}; \ - sed -i -e "s#@DATADIR@#$(DATADIR)#g" $${f%.in}; \ - done - - touch $@ - -clean: - dh_testdir - dh_testroot - rm -f build-stamp configure-stamp - - # Add here commands to clean up after the build process. - -$(MAKE) clean - - rm -rf CMakeCache.txt - rm -rf CMakeFiles - rm -rf cmake_install.cmake - rm -rf Makefile - rm -rf install_manifest.txt - rm -rf *.so - rm -rf ./restarter/CMakeCache.txt - rm -rf ./restarter/CMakeFiles - rm -rf ./restarter/cmake_install.cmake - rm -rf ./restarter/Makefile - rm -rf ./restarter/install_manifest.txt - rm -rf ./sys_event/CMakeCache.txt - rm -rf ./sys_event/CMakeFiles - rm -rf ./sys_event/cmake_install.cmake - rm -rf ./sys_event/Makefile - rm -rf ./sys_event/install_manifest.txt - rm -rf ./udev-rules/*.rules - - for f in `find $(CURDIR)/debian/ -name "*.in"`; do \ - rm -f $${f%.in}; \ - done - - - dh_clean - -install: build - dh_testdir - dh_testroot - dh_clean -k - dh_installdirs - - # Add here commands to install the package into debian/tmp. - $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install - - mkdir -p $(CURDIR)/debian/tmp/etc/rc.d/rc3.d/ - ln -s ../init.d/system_server.sh $(CURDIR)/debian/tmp/etc/rc.d/rc3.d/S35system-server - mkdir -p $(CURDIR)/debian/tmp/etc/rc.d/rc5.d/ - ln -s ../init.d/system_server.sh $(CURDIR)/debian/tmp/etc/rc.d/rc5.d/S00system-server - -# Build architecture-independent files here. -binary-indep: build install -# We have nothing to do by default. - -# Build architecture-dependent files here. -binary-arch: build install - dh_testdir - dh_testroot - dh_installchangelogs - dh_installdocs - dh_installexamples - dh_install --sourcedir=debian/tmp -# dh_installmenu -# dh_installdebconf -# dh_installlogrotate -# dh_installemacsen -# dh_installpam -# dh_installmime -# dh_python -# dh_installinit -# dh_installcron -# dh_installinfo - dh_installman - dh_link -# dh_strip - dh_strip --dbg-package=system-server-bin-dbg - dh_compress - dh_fixperms -# dh_perl - dh_makeshlibs - dh_installdeb - dh_shlibdeps - dh_gencontrol - dh_md5sums - dh_builddeb - -binary: binary-indep binary-arch -.PHONY: build clean binary-indep binary-arch binary install configure diff --git a/debian/system-server-bin.install.in b/debian/system-server-bin.install.in deleted file mode 100644 index 3c1f907..0000000 --- a/debian/system-server-bin.install.in +++ /dev/null @@ -1,3 +0,0 @@ -@PREFIX@/bin/* -@PREFIX@/share/system-server/* -/etc/* diff --git a/debian/system-server-bin.postinst.in b/debian/system-server-bin.postinst.in deleted file mode 100644 index f449796..0000000 --- a/debian/system-server-bin.postinst.in +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/sh - -vconftool set -t int memory/sysman/usbhost_status -1 -i -vconftool set -t int memory/sysman/mmc -1 -i -vconftool set -t int memory/sysman/earjack_key 0 -i - -vconftool set -t int memory/sysman/added_usb_storage 0 -i -vconftool set -t int memory/sysman/removed_usb_storage 0 -i -vconftool set -t int memory/sysman/charger_status -1 -i -vconftool set -t int memory/sysman/charge_now -1 -i -vconftool set -t int memory/sysman/battery_status_low -1 -i -vconftool set -t int memory/sysman/battery_capacity -1 -i -vconftool set -t int memory/sysman/usb_status -1 -i -vconftool set -t int memory/sysman/earjack -1 -i -vconftool set -t int memory/sysman/low_memory 1 -i -vconftool set -t int memory/sysman/sliding_keyboard -1 -i -vconftool set -t int memory/sysman/mmc_mount -1 -i -vconftool set -t int memory/sysman/mmc_unmount -1 -i -vconftool set -t int memory/sysman/mmc_format -1 -i - -vconftool set -t string memory/private/sysman/added_storage_uevent "" -i -vconftool set -t string memory/private/sysman/removed_storage_uevent "" -i - - -heynotitool set power_off_start - -heynotitool set mmcblk_add -heynotitool set mmcblk_remove - -heynotitool set device_usb_chgdet -heynotitool set device_ta_chgdet -heynotitool set device_earjack_chgdet -heynotitool set device_earkey_chgdet -heynotitool set device_tvout_chgdet -heynotitool set device_hdmi_chgdet -heynotitool set device_charge_chgdet -heynotitool set device_keyboard_chgdet -heynotitool set device_keyboard_add -heynotitool set device_keyboard_remove -heynotitool set device_mouse_add -heynotitool set device_mouse_remove - -mkdir -p /etc/udev/rules.d -if ! [ -L /etc/udev/rules.d/91-system-server.rules ]; then - ln -s @PREFIX@/share/system-server/udev-rules/91-system-server.rules /etc/udev/rules.d/91-system-server.rules -fi - diff --git a/display/core.c b/display/core.c index 0cbed71..3c4f2c4 100644 --- a/display/core.c +++ b/display/core.c @@ -42,8 +42,8 @@ #include "core.h" #include "battery.h" #include "device-node.h" -#include "ss_queue.h" -#include "include/ss_data.h" +#include "core/queue.h" +#include "core/data.h" #define USB_CON_PIDFILE "/var/run/.system_server.pid" #define PM_STATE_LOG_FILE "/var/log/pm_state.log" @@ -122,6 +122,9 @@ static int trans_table[S_END][EVENT_END] = { #define LOCK_SCREEN_WATING_MAX_COUNT 14 /* 50 * 14 : 700 ms at worst */ #define MASK32 0xffffffff +#define ACTIVE_ACT "active" +#define INACTIVE_ACT "inactive" + static int received_sleep_cmd = 0; typedef struct _pm_lock_node { @@ -139,7 +142,7 @@ void set_process_active(bool flag, pid_t pid) sprintf(str, "%d", (int)pid); ss_action_entry_call_internal( - (flag ? PREDEF_ACTIVE : PREDEF_INACTIVE), 1, str); + (flag ? ACTIVE_ACT : INACTIVE_ACT), 1, str); } static int refresh_app_cond() diff --git a/display/key-filter.c b/display/key-filter.c index e5a830d..bbdf44f 100644 --- a/display/key-filter.c +++ b/display/key-filter.c @@ -26,8 +26,8 @@ #include "core.h" #include "poll.h" -#include "ss_queue.h" -#include "include/ss_data.h" +#include "core/queue.h" +#include "core/data.h" #include #ifndef KEY_SCREENLOCK @@ -35,7 +35,8 @@ #endif #define PREDEF_LEAVESLEEP "leavesleep" - +#define POWEROFF_ACT "poweroff" +#define PWROFF_POPUP_ACT "pwroff-popup" #define USEC_PER_SEC 1000000 #define LONG_PRESS_INTERVAL 1 /* 1 second */ #define COMBINATION_INTERVAL 0.3 /* 0.3 second */ @@ -76,9 +77,9 @@ static void longkey_pressed() (*g_pm_callback) (INPUT_POLL_EVENT, NULL); if (vconf_get_int(VCONFKEY_TESTMODE_POWER_OFF_POPUP, &val) == 0 && val == 1) - opt = PREDEF_POWEROFF; + opt = POWEROFF_ACT; else - opt = PREDEF_PWROFF_POPUP; + opt = PWROFF_POPUP_ACT; ss_action_entry_call_internal(opt, 0); } diff --git a/display/poll.h b/display/poll.h index 915c28b..7e74eb6 100644 --- a/display/poll.h +++ b/display/poll.h @@ -30,7 +30,7 @@ #define __PM_POLL_H__ #include -#include "edbus-handler.h" +#include "core/edbus-handler.h" /** * @addtogroup POWER_MANAGER * @{ diff --git a/display/setting.c b/display/setting.c index 9e5a20d..24e39d4 100644 --- a/display/setting.c +++ b/display/setting.c @@ -18,7 +18,7 @@ #include #include -#include "util.h" +#include #include "setting.h" #include "conf.h" diff --git a/display/x-lcd-on.c b/display/x-lcd-on.c index 4ef2dcd..34bfdc6 100644 --- a/display/x-lcd-on.c +++ b/display/x-lcd-on.c @@ -29,14 +29,19 @@ static int pm_x_set_lcd_backlight(struct _PMSys *p, int on) { pid_t pid; - char cmd_line[4]; + char cmd_line[8]; int ret; LOGINFO("Backlight on=%d", on); - if (on == STATUS_ON) + + switch (on) { + case STATUS_ON: snprintf(cmd_line, sizeof(cmd_line), "%s", CMD_ON); - else + break; + case STATUS_OFF: snprintf(cmd_line, sizeof(cmd_line), "%s", CMD_OFF); + break; + } signal(SIGCHLD, SIG_DFL); pid = vfork(); @@ -47,10 +52,10 @@ static int pm_x_set_lcd_backlight(struct _PMSys *p, int on) } if (pid == 0) { - LOGERR("[1] Child proccess for LCD %s was created (%s)", - ((on == STATUS_ON) ? "ON" : "OFF"), cmd_line); + LOGERR("[1] Child proccess for LCD %d was created (%s)", + on, cmd_line); execl("/usr/bin/xset", "/usr/bin/xset", "dpms", "force", - cmd_line, NULL); + cmd_line, NULL); _exit(0); } else if (pid != (ret = waitpid(pid, NULL, 0))) { LOGERR diff --git a/include/ss_data.h b/include/ss_data.h deleted file mode 100644 index 18a56cd..0000000 --- a/include/ss_data.h +++ /dev/null @@ -1,113 +0,0 @@ -/* - * 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. - */ - -#ifndef __SS_DATA_H__ -#define __SS_DATA_H__ - -#include -#include - -enum { - WIN_CREATE = 0, - WIN_SHOW, - WIN_DELETE, - WIN_MAX -}; - -#define FM_RADIO_APP "FM_radio" -#define MULTIMEDIA_APP "music" -#define BLUETOOTH_APP "bluetooth" -#define VOICERECORDER_APP "voicerecorder" - -#define MMC_DEV "/dev/mmcblk" - -#define VCONFKEY_INTERNAL_ADDED_USB_STORAGE "memory/private/sysman/added_storage_uevent" -#define VCONFKEY_INTERNAL_REMOVED_USB_STORAGE "memory/private/sysman/removed_storage_uevent" - -#define PREDEF_CALL "call" -#define PREDEF_LOWMEM "lowmem" -#define PREDEF_LOWBAT "lowbat" -#define PREDEF_USBCON "usbcon" -#define PREDEF_POWEROFF "poweroff" -#define PREDEF_REBOOT "reboot" -#define PREDEF_PWROFF_POPUP "pwroff-popup" -#define PREDEF_BACKGRD "backgrd" -#define PREDEF_FOREGRD "foregrd" -#define PREDEF_ACTIVE "active" -#define PREDEF_USB_STORAGE_ADD "usbstorage-add" -#define PREDEF_USB_STORAGE_REMOVE "usbstorage-remove" -#define PREDEF_INACTIVE "inactive" -#define PREDEF_HAPTIC "haptic" - -#define OOMADJ_SET "oomadj_set" -#define LOW_MEM_ACT "low_mem_act" -#define OOM_MEM_ACT "oom_mem_act" - -#define WARNING_LOW_BAT_ACT "warning_low_bat_act" -#define CRITICAL_LOW_BAT_ACT "critical_low_bat_act" -#define POWER_OFF_BAT_ACT "power_off_bat_act" -#define CHARGE_BAT_ACT "charge_bat_act" -#define CHARGE_CHECK_ACT "charge_check_act" -#define CHARGE_ERROR_ACT "charge_error_act" - -#define PREDEF_EARJACKCON "earjack_predef_internal" - -#define PREDEF_SET_DATETIME "set_datetime" -#define PREDEF_SET_TIMEZONE "set_timezone" - -#define PREDEF_MOUNT_MMC "mountmmc" -#define PREDEF_UNMOUNT_MMC "unmountmmc" -#define PREDEF_FORMAT_MMC "formatmmc" -#define PREDEF_CHECK_SMACK_MMC "checksmackmmc" -#define PREDEF_CHECK_MMC "checkmmc" -#define PREDEF_CHECK_MMC_PROC "checkmmcproc" - -#define PREDEF_LED "led" - -#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_FLIGHT_MODE "flightmode" - -#define PREDEF_DEVICE_CHANGED "device_changed" -#define PREDEF_INTERNAL_POWEROFF "internal_poweroff" - -#define PROCESS_GROUP_SET "process_group_set" - -#define OOMADJ_SU (-17) -#define OOMADJ_INIT (-16) -#define OOMADJ_FOREGRD_LOCKED (-15) -#define OOMADJ_FOREGRD_UNLOCKED (-10) -#define OOMADJ_BACKGRD_LOCKED (-5) -#define OOMADJ_BACKGRD_UNLOCKED (1) - -#define OOMADJ_APP_LIMIT (-16) - -#define MOVINAND_MOUNT_POINT "/opt/media" -#define MMC_MOUNT_POINT "/opt/storage/sdcard" - -struct ui_contention_info { - -}; - -struct ss_main_data { - int sysnoti_fd; - int noti_fd; -}; - -#endif /* __SS_DATA_H__ */ diff --git a/movi_format.sh b/scripts/movi_format.sh similarity index 100% rename from movi_format.sh rename to scripts/movi_format.sh diff --git a/ss_lowbat_handler.c b/src/battery/lowbat-handler.c old mode 100755 new mode 100644 similarity index 70% rename from ss_lowbat_handler.c rename to src/battery/lowbat-handler.c index 934320a..30e8262 --- a/ss_lowbat_handler.c +++ b/src/battery/lowbat-handler.c @@ -20,36 +20,49 @@ #include #include #include +#include -#include "ss_log.h" -#include "ss_launch.h" -#include "ss_noti.h" -#include "ss_queue.h" +#include "core/log.h" +#include "core/launch.h" +#include "core/noti.h" +#include "core/queue.h" +#include "core/data.h" #include "device-node.h" -#include "include/ss_data.h" #include "display/setting.h" +#define PREDEF_LOWBAT "lowbat" + #define BAT_MON_INTERVAL 30 -#define BAT_MON_INTERVAL_MIN 2 +#define BAT_MON_INTERVAL_MIN 2 #define BATTERY_CHARGING 65535 -#define BATTERY_UNKNOWN -1 -#define BATTERY_FULL 100 -#define BATTERY_NORMAL 100 -#define BATTERY_WARNING_LOW 15 -#define BATTERY_CRITICAL_LOW 5 -#define BATTERY_POWER_OFF 1 -#define BATTERY_REAL_POWER_OFF 0 +#define BATTERY_UNKNOWN -1 +#define BATTERY_FULL 100 +#define BATTERY_NORMAL 100 +#define BATTERY_WARNING_LOW 15 +#define BATTERY_CRITICAL_LOW 5 +#define BATTERY_POWER_OFF 1 +#define BATTERY_REAL_POWER_OFF 0 #define MAX_BATTERY_ERROR 10 #define RESET_RETRY_COUNT 3 -#define LOWBAT_EXEC_PATH PREFIX"/bin/lowbatt-popup" +#define BATTERY_LEVEL_CHECK_FULL 95 +#define BATTERY_LEVEL_CHECK_HIGH 15 +#define BATTERY_LEVEL_CHECK_LOW 5 +#define BATTERY_LEVEL_CHECK_CRITICAL 1 + +#define LOWBAT_OPT_WARNING 1 +#define LOWBAT_OPT_POWEROFF 2 +#define LOWBAT_OPT_CHARGEERR 3 +#define LOWBAT_OPT_CHECK 4 -#define BATTERY_LEVEL_CHECK_FULL 95 -#define BATTERY_LEVEL_CHECK_HIGH 15 -#define BATTERY_LEVEL_CHECK_LOW 5 -#define BATTERY_LEVEL_CHECK_CRITICAL 1 +#define WARNING_LOW_BAT_ACT "warning_low_bat_act" +#define CRITICAL_LOW_BAT_ACT "critical_low_bat_act" +#define POWER_OFF_BAT_ACT "power_off_bat_act" +#define CHARGE_BAT_ACT "charge_bat_act" +#define CHARGE_CHECK_ACT "charge_check_act" +#define CHARGE_ERROR_ACT "charge_error_act" #define _SYS_LOW_POWER "LOW_POWER" @@ -65,9 +78,12 @@ static int cur_bat_capacity = -1; static int bat_err_count = 0; -static int battery_warning_low_act(void *ad); -static int battery_critical_low_act(void *ad); -static int battery_power_off_act(void *ad); +static Ecore_Timer *lowbat_popup_id = NULL; +static int lowbat_popup_option = 0; + +int battery_warning_low_act(void *ad); +int battery_critical_low_act(void *ad); +int battery_power_off_act(void *ad); static struct lowbat_process_entry lpe[] = { {BATTERY_NORMAL, BATTERY_WARNING_LOW, battery_warning_low_act}, @@ -94,7 +110,7 @@ static void print_lowbat_state(unsigned int bat_percent) #endif } -static int battery_warning_low_act(void *data) +int battery_warning_low_act(void *data) { char lowbat_noti_name[NAME_MAX]; @@ -105,18 +121,25 @@ static int battery_warning_low_act(void *data) return 0; } -static int battery_critical_low_act(void *data) +int battery_critical_low_act(void *data) { ss_action_entry_call_internal(PREDEF_LOWBAT, 1, CRITICAL_LOW_BAT_ACT); return 0; } -static int battery_power_off_act(void *data) +int battery_power_off_act(void *data) { ss_action_entry_call_internal(PREDEF_LOWBAT, 1, POWER_OFF_BAT_ACT); return 0; } +int battery_charge_err_act(void *data) +{ + ss_action_entry_call_internal(PREDEF_LOWBAT, 1, CHARGE_ERROR_ACT); + return 0; +} + + static int battery_charge_act(void *data) { return 0; @@ -359,6 +382,92 @@ static int check_battery() return ret; } +int lowbat_popup(void *data) +{ + int ret = -1, state = 0; + ret = vconf_get_int(VCONFKEY_STARTER_SEQUENCE, &state); + if (state == 1 || ret != 0) { + bundle *b = NULL; + b = bundle_create(); + if (lowbat_popup_option == LOWBAT_OPT_WARNING || lowbat_popup_option == LOWBAT_OPT_CHECK) { + bundle_add(b, "_SYSPOPUP_CONTENT_", "warning"); + } else if(lowbat_popup_option == LOWBAT_OPT_POWEROFF) { + bundle_add(b, "_SYSPOPUP_CONTENT_", "poweroff"); + } else if(lowbat_popup_option == LOWBAT_OPT_CHARGEERR) { + bundle_add(b, "_SYSPOPUP_CONTENT_", "chargeerr"); + } else { + bundle_add(b, "_SYSPOPUP_CONTENT_", "check"); + } + + ret = syspopup_launch("lowbat-syspopup", b); + if (ret < 0) { + PRT_TRACE_EM("popup lauch failed\n"); + bundle_free(b); + return 1; + } + lowbat_popup_id = NULL; + lowbat_popup_option = 0; + bundle_free(b); + } else { + PRT_TRACE_EM("boot-animation running yet"); + return 1; + } + + return 0; +} + +int lowbat_def_predefine_action(int argc, char **argv) +{ + int ret, state=0; + char argstr[128]; + char* option = NULL; + + if (argc < 1) + return -1; + + if (lowbat_popup_id != NULL) { + ecore_timer_del(lowbat_popup_id); + lowbat_popup_id = NULL; + } + + bundle *b = NULL; + b = bundle_create(); + if (!strcmp(argv[0],CRITICAL_LOW_BAT_ACT)) { + bundle_add(b, "_SYSPOPUP_CONTENT_", "warning"); + lowbat_popup_option = LOWBAT_OPT_CHECK; + } else if(!strcmp(argv[0],WARNING_LOW_BAT_ACT)) { + bundle_add(b, "_SYSPOPUP_CONTENT_", "warning"); + lowbat_popup_option = LOWBAT_OPT_WARNING; + } else if(!strcmp(argv[0],POWER_OFF_BAT_ACT)) { + bundle_add(b, "_SYSPOPUP_CONTENT_", "poweroff"); + lowbat_popup_option = LOWBAT_OPT_POWEROFF; + } else if(!strcmp(argv[0],CHARGE_ERROR_ACT)) { + bundle_add(b, "_SYSPOPUP_CONTENT_", "chargeerr"); + lowbat_popup_option = LOWBAT_OPT_CHARGEERR; + } + + ret = vconf_get_int(VCONFKEY_STARTER_SEQUENCE, &state); + if (state == 1 || ret != 0) { + if (predefine_control_launch("lowbat-syspopup", b, lowbat_popup_option) < 0) { + PRT_TRACE_ERR("popup lauch failed\n"); + bundle_free(b); + lowbat_popup_option = 0; + return -1; + } + } else { + PRT_TRACE_EM("boot-animation running yet"); + lowbat_popup_id = ecore_timer_add(1, lowbat_popup, NULL); + } + bundle_free(b); + return 0; +} + +void ss_predefine_lowbat_init(void) +{ + ss_action_entry_add_internal(PREDEF_LOWBAT, lowbat_def_predefine_action, + NULL, NULL); +} + int ss_lowbat_init(struct ss_main_data *ad) { int i; diff --git a/src/battery/lowbat-handler.h b/src/battery/lowbat-handler.h new file mode 100644 index 0000000..b7b36c6 --- /dev/null +++ b/src/battery/lowbat-handler.h @@ -0,0 +1,25 @@ +/* + * system-server + * + * 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. + * +*/ + + +#ifndef __LOWBAT_HANDLER_H__ +#define __LOWBAT_HANDLER_H__ + +void ss_predefine_lowbat_init(void); +#endif /* __LOWBAT_HANDLER_H__ */ diff --git a/ss_bs.c b/src/bs/bs.c similarity index 99% rename from ss_bs.c rename to src/bs/bs.c index 4d4f3b5..5b2c7ad 100644 --- a/ss_bs.c +++ b/src/bs/bs.c @@ -28,9 +28,8 @@ #include #include #include - -#include "ss_log.h" -#include "ss_launch.h" +#include "core/log.h" +#include "core/launch.h" #define CRASH_PID_MAX 7 #define CRASH_MODE_MAX 2 diff --git a/ss_bs.h b/src/bs/bs.h similarity index 100% rename from ss_bs.h rename to src/bs/bs.h diff --git a/ss_common.c b/src/core/common.c similarity index 99% rename from ss_common.c rename to src/core/common.c index 0ce536d..e9754a2 100644 --- a/ss_common.c +++ b/src/core/common.c @@ -12,7 +12,7 @@ #include #include #include -#include "ss_log.h" +#include "log.h" #define PERMANENT_DIR "/tmp/permanent" #define VIP_DIR "/tmp/vip" diff --git a/ss_common.h b/src/core/common.h similarity index 81% rename from ss_common.h rename to src/core/common.h index 51cebcb..f04bcea 100644 --- a/ss_common.h +++ b/src/core/common.h @@ -1,6 +1,8 @@ #ifndef _SS_COMMON_H #define _SS_COMMON_H +#define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0])) + FILE * open_proc_oom_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); diff --git a/ss_core.c b/src/core/core.c similarity index 96% rename from ss_core.c rename to src/core/core.c index 06cfc1c..14633c0 100644 --- a/ss_core.c +++ b/src/core/core.c @@ -15,11 +15,11 @@ */ -#include "include/ss_data.h" -#include "ss_queue.h" -#include "ss_log.h" -#include "ss_predefine.h" -#include "ss_core.h" +#include "data.h" +#include "queue.h" +#include "log.h" +#include "predefine.h" +#include "core.h" enum ss_core_cmd_type { SS_CORE_ACT_RUN, diff --git a/ss_core.h b/src/core/core.h similarity index 96% rename from ss_core.h rename to src/core/core.h index d35e345..bf86bb5 100644 --- a/ss_core.h +++ b/src/core/core.h @@ -18,7 +18,7 @@ #ifndef __SS_CORE_H__ #define __SS_CORE_H__ -#include "include/ss_data.h" +#include "data.h" int ss_core_action_run(); int ss_core_action_clear(int pid); diff --git a/src/core/data.h b/src/core/data.h new file mode 100644 index 0000000..ffdbb3d --- /dev/null +++ b/src/core/data.h @@ -0,0 +1,28 @@ +/* + * 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. + */ + +#ifndef __SS_DATA_H__ +#define __SS_DATA_H__ + +#include +#include + +struct ss_main_data { + int sysnoti_fd; + int noti_fd; +}; + +#endif /* __SS_DATA_H__ */ diff --git a/ss_device_change_handler.c b/src/core/device-change-handler.c old mode 100755 new mode 100644 similarity index 89% rename from ss_device_change_handler.c rename to src/core/device-change-handler.c index ea83d75..67c089c --- a/ss_device_change_handler.c +++ b/src/core/device-change-handler.c @@ -27,18 +27,26 @@ #include #include #include -#include #include "dd-deviced.h" -#include "ss_queue.h" -#include "ss_log.h" -#include "ss_device_handler.h" +#include +#include "queue.h" +#include "log.h" +#include "device-handler.h" #include "device-node.h" -#include "ss_noti.h" -#include "include/ss_data.h" -#include "sys_pci_noti/sys_pci_noti.h" -#include "ss_predefine.h" +#include "noti.h" +#include "data.h" +#include "predefine.h" #include "poll.h" +#include "sys_pci_noti/sys_pci_noti.h" + +#define PREDEF_USBCON "usbcon" +#define PREDEF_EARJACKCON "earjack_predef_internal" +#define PREDEF_DEVICE_CHANGED "device_changed" + +#define TVOUT_X_BIN "/usr/bin/xberc" +#define TVOUT_FLAG 0x00000001 +#define MOVINAND_MOUNT_POINT "/opt/media" #define BUFF_MAX 255 #define SYS_CLASS_INPUT "/sys/class/input" #define USBCON_EXEC_PATH PREFIX"/bin/usb-server" @@ -92,6 +100,8 @@ enum snd_jack_types { #define ABNORMAL_POPUP_COUNTER 5 +static int ss_flags = 0; + static int input_device_number; static struct udev_monitor *mon = NULL; @@ -99,7 +109,8 @@ static struct udev *udev = NULL; static Ecore_Fd_Handler *ufdh = NULL; static int uevent_control_cb(void *data, Ecore_Fd_Handler *fd_handler); - +extern int battery_power_off_act(void *data); +extern int battery_charge_err_act(void *data); static int check_lowbat_charge_device(int bInserted) { static int bChargeDeviceInserted = 0; @@ -352,7 +363,7 @@ static void charge_cb(struct ss_main_data *ad) PRT_TRACE_ERR("fail to get battery node value"); if (charge_now == 0 && capacity == 0) { PRT_TRACE_ERR("target will be shut down"); - ss_action_entry_call_internal(PREDEF_LOWBAT, 1, POWER_OFF_BAT_ACT); + battery_power_off_act(NULL); return; } @@ -364,9 +375,9 @@ static void charge_cb(struct ss_main_data *ad) return; if (device_get_property(DEVICE_TYPE_POWER, PROP_POWER_CAPACITY, &val) == 0 && val <= 0) - ss_action_entry_call_internal(PREDEF_LOWBAT, 1, POWER_OFF_BAT_ACT); + battery_power_off_act(NULL); else - ss_action_entry_call_internal(PREDEF_LOWBAT, 1, CHARGE_ERROR_ACT); + battery_charge_err_act(NULL); return; } } else { @@ -584,6 +595,51 @@ int changed_device_def_predefine_action(int argc, char **argv) return 0; } +int usbcon_def_predefine_action(int argc, char **argv) +{ + int pid; + int val = -1; + int ret = -1; + int bat_state = VCONFKEY_SYSMAN_BAT_NORMAL; + + if (device_get_property(DEVICE_TYPE_EXTCON, PROP_EXTCON_USB_ONLINE, &val) == 0) { + if (val == 0) { + vconf_set_int(VCONFKEY_SYSMAN_USB_STATUS, + VCONFKEY_SYSMAN_USB_DISCONNECTED); + pm_unlock_internal(getpid(), LCD_OFF, STAY_CUR_STATE); + return 0; + } + + if ( vconf_get_int(VCONFKEY_SYSMAN_USB_STATUS, &val) == 0 && val == VCONFKEY_SYSMAN_USB_AVAILABLE) + return 0; + + vconf_set_int(VCONFKEY_SYSMAN_USB_STATUS, + VCONFKEY_SYSMAN_USB_AVAILABLE); + pm_lock_internal(getpid(), LCD_OFF, STAY_CUR_STATE, 0); + pid = ss_launch_if_noexist(USBCON_EXEC_PATH, NULL); + if (pid < 0) { + PRT_TRACE_ERR("usb predefine action failed\n"); + return -1; + } + return pid; + } + PRT_TRACE_ERR("failed to get usb status\n"); + return -1; +} + +int earjackcon_def_predefine_action(int argc, char **argv) +{ + int val; + + PRT_TRACE_EM("earjack_normal predefine action\n"); + if (device_get_property(DEVICE_TYPE_EXTCON, PROP_EXTCON_EARJACK_ONLINE, &val) == 0) { + return vconf_set_int(VCONFKEY_SYSMAN_EARJACK, val); + } + + return -1; +} + + static void pci_keyboard_add_cb(struct ss_main_data *ad) { char params[BUFF_MAX]; @@ -603,6 +659,13 @@ static void pci_keyboard_remove_cb(struct ss_main_data *ad) snprintf(params, sizeof(params), "%d", CB_NOTI_PCI_REMOVED); ss_launch_if_noexist("/usr/bin/sys_pci_noti", params); } + +void ss_predefine_device_change_init(void) +{ + ss_action_entry_add_internal(PREDEF_USBCON, usbcon_def_predefine_action, NULL, NULL); + ss_action_entry_add_internal(PREDEF_EARJACKCON, earjackcon_def_predefine_action, NULL, NULL); +} + int ss_device_change_init(struct ss_main_data *ad) { ss_action_entry_add_internal(PREDEF_DEVICE_CHANGED, changed_device_def_predefine_action, NULL, NULL); @@ -633,6 +696,9 @@ int ss_device_change_init(struct ss_main_data *ad) if (vconf_notify_key_changed(VCONFKEY_SYSMAN_USB_HOST_STATUS, usb_host_chgdet_cb, NULL) < 0) { PRT_TRACE_ERR("vconf key notify failed(VCONFKEY_SYSMAN_USB_HOST_STATUS)"); } + + /* check and set earjack init status */ + earjackcon_def_predefine_action(0, NULL); /* dbus noti change cb */ #ifdef ENABLE_EDBUS_USE e_dbus_init(); diff --git a/ss_device_handler.h b/src/core/device-handler.h similarity index 97% rename from ss_device_handler.h rename to src/core/device-handler.h index d31f46b..6f7ac53 100644 --- a/ss_device_handler.h +++ b/src/core/device-handler.h @@ -18,7 +18,7 @@ #ifndef __SS_DEVICE_HANDLER_H__ #define __SS_DEVICE_HANDLER_H__ -#include "include/ss_data.h" +#include "data.h" /* MMC functions */ int ss_mmc_init(); diff --git a/edbus-handler.c b/src/core/edbus-handler.c similarity index 97% rename from edbus-handler.c rename to src/core/edbus-handler.c index 4454a3e..7d2b9d4 100644 --- a/edbus-handler.c +++ b/src/core/edbus-handler.c @@ -18,9 +18,9 @@ */ -#include "ss_log.h" -#include "include/ss_data.h" -#include "edbus-handler.h" +#include "core/log.h" +#include "core/data.h" +#include "core/edbus-handler.h" #define EDBUS_INIT_RETRY_COUNT 5 diff --git a/edbus-handler.h b/src/core/edbus-handler.h similarity index 100% rename from edbus-handler.h rename to src/core/edbus-handler.h diff --git a/ss_launch.c b/src/core/launch.c similarity index 98% rename from ss_launch.c rename to src/core/launch.c index ae72fb6..03ac862 100644 --- a/ss_launch.c +++ b/src/core/launch.c @@ -25,9 +25,9 @@ #include #include "vconf-keys.h" -#include "ss_log.h" -#include "ss_launch.h" -#include "ss_common.h" +#include "log.h" +#include "launch.h" +#include "common.h" #define MAX_ARGS 255 diff --git a/ss_launch.h b/src/core/launch.h similarity index 100% rename from ss_launch.h rename to src/core/launch.h diff --git a/ss_log.c b/src/core/log.c similarity index 100% rename from ss_log.c rename to src/core/log.c diff --git a/ss_log.h b/src/core/log.h similarity index 100% rename from ss_log.h rename to src/core/log.h diff --git a/ss_main.c b/src/core/main.c similarity index 78% rename from ss_main.c rename to src/core/main.c index d33ba01..2044407 100644 --- a/ss_main.c +++ b/src/core/main.c @@ -20,21 +20,25 @@ #include #include -#include "ss_log.h" -#include "ss_core.h" -#include "ss_sig_handler.h" -#include "ss_device_handler.h" -#include "ss_pmon_handler.h" -#include "ss_sysnoti.h" -#include "ss_noti.h" -#include "ss_queue.h" -#include "ss_predefine.h" -#include "ss_bs.h" -#include "ss_procmgr.h" -#include "ss_timemgr.h" -#include "ss_cpu_handler.h" -#include "include/ss_data.h" +#include "log.h" +#include "core.h" +#include "sig-handler.h" +#include "device-handler.h" +#include "noti.h" +#include "queue.h" +#include "predefine.h" #include "edbus-handler.h" +#include "bs/bs.h" +#include "cpu/cpu-handler.h" +#include "data.h" +#include "led/led.h" +#include "proc/lowmem-handler.h" +#include "battery/lowbat-handler.h" +#include "proc/pmon-handler.h" +#include "proc/proc-handler.h" +#include "time/time-handler.h" +#include "vibrator/vibrator.h" +#include "sysnoti.h" static void fini(struct ss_main_data *ad) { @@ -66,26 +70,31 @@ static void system_server_init(struct ss_main_data *ad) ss_core_init(ad); ss_signal_init(); ss_predefine_internal_init(); + ss_predefine_lowmem_init(); + ss_predefine_lowbat_init(); + ss_predefine_device_change_init(); + ss_predefine_power_init(); ss_process_manager_init(); ss_time_manager_init(); ss_cpu_handler_init(); ss_lowmem_init(ad); ss_lowbat_init(ad); + ss_power_init(ad); ss_usb_init(); ss_ta_init(); ss_pmon_init(ad); ss_device_change_init(ad); + led_init(); ss_mmc_init(); ss_bs_init(); + vibrator_init(); } #define SS_PIDFILE_PATH "/var/run/.system_server.pid" static void sig_quit(int signo) { PRT_TRACE_ERR("received SIGTERM signal %d", signo); - if (is_power_off() == 1) - reboot(RB_POWER_OFF); } static int system_main(int argc, char **argv) { diff --git a/ss_noti.c b/src/core/noti.c similarity index 98% rename from ss_noti.c rename to src/core/noti.c index c9ed285..9de6a7c 100644 --- a/ss_noti.c +++ b/src/core/noti.c @@ -16,7 +16,7 @@ #include -#include "ss_log.h" +#include "log.h" static int noti_fd; diff --git a/ss_noti.h b/src/core/noti.h similarity index 100% rename from ss_noti.h rename to src/core/noti.h diff --git a/src/core/predefine.c b/src/core/predefine.c new file mode 100644 index 0000000..3c04230 --- /dev/null +++ b/src/core/predefine.c @@ -0,0 +1,193 @@ +/* + * 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 +#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 "poll.h" +#include "setting.h" +#include "led/led.h" + +#define PREDEFINE_SO_DIR PREFIX"/lib/ss_predefine/" + +#define LOWBAT_EXEC_PATH PREFIX"/bin/lowbatt-popup" + +#define HDMI_NOTI_EXEC_PATH PREFIX"/bin/hdmi_connection_noti" +#define LOWBAT_POPUP_NAME "lowbat-syspopup" +#define POWEROFF_POPUP_NAME "poweroff-syspopup" +#define HDMI_POPUP_NAME "hdmi-syspopup" +#define LOWMEM_POPUP_NAME "lowmem-syspopup" + +static int __predefine_get_pid(const char *execpath) +{ + DIR *dp; + struct dirent *dentry; + int pid = -1, fd; + char buf[PATH_MAX]; + char buf2[PATH_MAX]; + + dp = opendir("/proc"); + if (!dp) { + PRT_TRACE_ERR("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; + if (read(fd, buf2, PATH_MAX) < 0) { + close(fd); + continue; + } + close(fd); + + if (!strcmp(buf2, execpath)) { + closedir(dp); + return pid; + } + } + + errno = ESRCH; + closedir(dp); + return -1; +} + +int predefine_control_launch(char *name, bundle *b, int option) +{ + int pid; + static int launched_poweroff = 0; + //lowbat-popup + if (strncmp(name, LOWBAT_POPUP_NAME, strlen(LOWBAT_POPUP_NAME)) == 0) { + if (launched_poweroff == 1) { + PRT_TRACE_ERR("will be foreced power off"); + internal_poweroff_def_predefine_action(0,NULL); + return 0; + } + + if (option == 2) + launched_poweroff = 1; + + pid = __predefine_get_pid(LOWBAT_EXEC_PATH); + if (pid > 0) { + PRT_TRACE_ERR("pre launched %s destroy", LOWBAT_EXEC_PATH); + kill(pid, SIGTERM); + } + if (syspopup_launch(name, b) < 0) + return -1; + } + //poweroff-popup + if (strncmp(name, POWEROFF_POPUP_NAME, strlen(POWEROFF_POPUP_NAME)) == 0) { + if (syspopup_launch(name, b) < 0) + return -1; + } + //hdmi-popup + if (strncmp(name, HDMI_POPUP_NAME, strlen(HDMI_POPUP_NAME)) == 0) { + if (syspopup_launch(name, b) < 0) + return -1; + } + //hdmi-noti + if (strncmp(name, HDMI_NOTI_EXEC_PATH, strlen(HDMI_NOTI_EXEC_PATH)) == 0) { + if (ss_launch_if_noexist(name, "1") < 0) + return -1; + } + //user mem lowmem-popup + if (strncmp(name, LOWMEM_POPUP_NAME, strlen(LOWMEM_POPUP_NAME)) == 0) { + if (syspopup_launch(name, b) < 0) + return -1; + } + return 0; +} + +void predefine_pm_change_state(unsigned int s_bits) +{ + pm_change_internal(getpid(), s_bits); +} + +static void ss_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) { + ERR("fail open %s", PREDEFINE_SO_DIR); + return; + } + + msg = malloc(sizeof(struct sysnoti)); + if (msg == NULL) { + ERR("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]); + ss_action_entry_add(msg); + } + free(msg); + + closedir(dp); +} + +void ss_predefine_internal_init(void) +{ + + /* telephony initialize */ + int ret = 0; + + ss_action_entry_load_from_sodir(); + +} diff --git a/ss_predefine.h b/src/core/predefine.h similarity index 91% rename from ss_predefine.h rename to src/core/predefine.h index 1548ec7..d4243b1 100644 --- a/ss_predefine.h +++ b/src/core/predefine.h @@ -21,7 +21,6 @@ int call_predefine_action(int argc, char **argv); void ss_predefine_internal_init(void); -int is_power_off(void); void predefine_pm_change_state(unsigned int s_bits); -int predefine_control_launch(char *popup_name, bundle *b); +int predefine_control_launch(char *popup_name, bundle *b, int option); #endif /* __SS_PREDEFINE_H__ */ diff --git a/ss_queue.c b/src/core/queue.c similarity index 98% rename from ss_queue.c rename to src/core/queue.c index 1706525..3200bc6 100644 --- a/ss_queue.c +++ b/src/core/queue.c @@ -16,10 +16,10 @@ #include -#include "include/ss_data.h" -#include "ss_core.h" -#include "ss_queue.h" -#include "ss_log.h" +#include "data.h" +#include "core.h" +#include "queue.h" +#include "log.h" #define SS_PREDEFINE_ACT_FUNC_STR "ss_predefine_action" #define SS_IS_ACCESSIBLE_FUNC_STR "ss_is_accessible" diff --git a/ss_queue.h b/src/core/queue.h similarity index 98% rename from ss_queue.h rename to src/core/queue.h index 6b9d899..23e01f0 100644 --- a/ss_queue.h +++ b/src/core/queue.h @@ -18,7 +18,7 @@ #ifndef __SS_QUEUE_H__ #define __SS_QUEUE_H__ -#include "ss_sysnoti.h" +#include "sysnoti.h" struct ss_action_entry { int owner_pid; diff --git a/ss_sig_handler.c b/src/core/sig-handler.c similarity index 64% rename from ss_sig_handler.c rename to src/core/sig-handler.c index 1ceda17..9d77787 100644 --- a/ss_sig_handler.c +++ b/src/core/sig-handler.c @@ -19,7 +19,7 @@ #include #include #include -#include "ss_core.h" +#include "core.h" #include "edbus-handler.h" #include "poll.h" @@ -35,8 +35,6 @@ write(1, buf, strlen(buf));\ } while (0); -#define SIGNAL_NAME_POWEROFF_POPUP "poweroffpopup" - static struct sigaction sig_child_old_act; static struct sigaction sig_pipe_old_act; @@ -61,37 +59,6 @@ static void sig_pipe_handler(int signo, siginfo_t *info, void *data) } -static void poweroff_popup_edbus_signal_handler(void *data, DBusMessage *msg) -{ - DBusError err; - char *str; - int val = 0; - - if (dbus_message_is_signal(msg, INTERFACE_NAME, SIGNAL_NAME_POWEROFF_POPUP) == 0) { - PRT_TRACE_ERR("there is no power off popup signal"); - return; - } - - dbus_error_init(&err); - - if (dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID) == 0) { - PRT_TRACE_ERR("there is no message"); - return; - } - - if (strncmp(str, PREDEF_PWROFF_POPUP, strlen(PREDEF_PWROFF_POPUP)) == 0) - val = VCONFKEY_SYSMAN_POWER_OFF_POPUP; - else if (strncmp(str, PREDEF_POWEROFF, strlen(PREDEF_POWEROFF)) == 0) - val = VCONFKEY_SYSMAN_POWER_OFF_DIRECT; - else if (strncmp(str, PREDEF_POWEROFF, strlen(PREDEF_REBOOT)) == 0) - val = VCONFKEY_SYSMAN_POWER_OFF_RESTART; - if (val == 0) { - PRT_TRACE_ERR("not supported message : %s", str); - return; - } - vconf_set_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, val); -} - void ss_signal_init(void) { struct sigaction sig_act; @@ -107,8 +74,6 @@ void ss_signal_init(void) sig_act.sa_flags = SA_SIGINFO; sigemptyset(&sig_act.sa_mask); sigaction(SIGPIPE, &sig_act, &sig_pipe_old_act); - register_edbus_signal_handler(SIGNAL_NAME_POWEROFF_POPUP, - (void *)poweroff_popup_edbus_signal_handler); register_edbus_signal_handler(SIGNAL_NAME_LCD_CONTROL, (void *)lcd_control_edbus_signal_handler); diff --git a/ss_sig_handler.h b/src/core/sig-handler.h similarity index 100% rename from ss_sig_handler.h rename to src/core/sig-handler.h diff --git a/ss_sysnoti.c b/src/core/sysnoti.c old mode 100755 new mode 100644 similarity index 98% rename from ss_sysnoti.c rename to src/core/sysnoti.c index 5dd045a..1dad33a --- a/ss_sysnoti.c +++ b/src/core/sysnoti.c @@ -20,10 +20,10 @@ #include #include #include -#include "include/ss_data.h" -#include "ss_log.h" -#include "ss_queue.h" -#include "ss_common.h" +#include "data.h" +#include "log.h" +#include "queue.h" +#include "common.h" #define SYSNOTI_SOCKET_PATH "/tmp/sn" #define RETRY_READ_COUNT 5 diff --git a/ss_sysnoti.h b/src/core/sysnoti.h similarity index 100% rename from ss_sysnoti.h rename to src/core/sysnoti.h diff --git a/ss_cpu_handler.c b/src/cpu/cpu-handler.c similarity index 97% rename from ss_cpu_handler.c rename to src/cpu/cpu-handler.c index e9a808e..545ba14 100644 --- a/ss_cpu_handler.c +++ b/src/cpu/cpu-handler.c @@ -18,10 +18,15 @@ #include #include "device-node.h" -#include "ss_log.h" -#include "include/ss_data.h" +#include "core/log.h" +#include "core/data.h" #include "vconf.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 DEFAULT_MAX_CPU_FREQ 1200000 #define DEFAULT_MIN_CPU_FREQ 100000 #define POWER_SAVING_CPUFREQ 800000 @@ -220,7 +225,7 @@ static int power_saving_cpu_cb(keynode_t *key_nodes, void *data) int ss_cpu_handler_init(void) { __set_freq_limit(); - + ss_action_entry_add_internal(PREDEF_SET_MAX_FREQUENCY, set_max_frequency_action, NULL, NULL); ss_action_entry_add_internal(PREDEF_SET_MIN_FREQUENCY, set_min_frequency_action, NULL, NULL); ss_action_entry_add_internal(PREDEF_RELEASE_MAX_FREQUENCY, release_max_frequency_action, NULL, NULL); @@ -348,10 +353,6 @@ static int __add_entry_to_max_cpu_freq_list(int pid, int freq) PRT_TRACE_ERR("Remove duplicated entry failed"); } - if (freq < cur_max_cpu_freq) { - cur_max_cpu_freq = freq; - } - entry = malloc(sizeof(struct cpu_freq_entry)); if (!entry) { PRT_TRACE_ERR("Malloc failed"); @@ -366,7 +367,9 @@ static int __add_entry_to_max_cpu_freq_list(int pid, int freq) PRT_TRACE_ERR("eina_list_prepend failed"); return -1; } - + if (freq < cur_max_cpu_freq) { + cur_max_cpu_freq = freq; + } return 0; } @@ -380,10 +383,6 @@ static int __add_entry_to_min_cpu_freq_list(int pid, int freq) PRT_TRACE_ERR("Remove duplicated entry failed"); } - if (freq > cur_min_cpu_freq) { - cur_min_cpu_freq = freq; - } - entry = malloc(sizeof(struct cpu_freq_entry)); if (!entry) { PRT_TRACE_ERR("Malloc failed"); @@ -398,7 +397,9 @@ static int __add_entry_to_min_cpu_freq_list(int pid, int freq) PRT_TRACE_ERR("eina_list_prepend failed"); return -1; } - + if (freq > cur_min_cpu_freq) { + cur_min_cpu_freq = freq; + } return 0; } diff --git a/ss_cpu_handler.h b/src/cpu/cpu-handler.h similarity index 100% rename from ss_cpu_handler.h rename to src/cpu/cpu-handler.h diff --git a/src/led/led.c b/src/led/led.c index 8b114b6..c9a7528 100644 --- a/src/led/led.c +++ b/src/led/led.c @@ -22,7 +22,9 @@ #include #include "deviced/dd-led.h" -#include "ss_log.h" +#include "core/log.h" + +#define PREDEF_LED "led" enum { SET_BRT = 0, @@ -68,3 +70,9 @@ int led_def_predefine_action(int argc, char **argv) return -1; } + +int led_init(void) +{ + ss_action_entry_add_internal(PREDEF_LED, led_def_predefine_action, NULL, NULL); + return 0; +} diff --git a/src/led/led.h b/src/led/led.h index 4cd49b5..ae7c86d 100644 --- a/src/led/led.h +++ b/src/led/led.h @@ -20,5 +20,5 @@ #define __LED_H__ int led_def_predefine_action(int argc, char **argv); - +int led_init(void); #endif diff --git a/ss_mmc_handler.c b/src/mmc/mmc-handler.c similarity index 98% rename from ss_mmc_handler.c rename to src/mmc/mmc-handler.c index 8ab361d..94aa4a2 100644 --- a/ss_mmc_handler.c +++ b/src/mmc/mmc-handler.c @@ -25,12 +25,19 @@ #include #include #include -#include "ss_log.h" -#include "ss_device_handler.h" -#include "ss_predefine.h" +#include "core/log.h" +#include "core/device-handler.h" +#include "core/common.h" #define VCONFKEY_INTERNAL_PRIVATE_MMC_ID "db/private/sysman/mmc_device_id" +#define PREDEF_MOUNT_MMC "mountmmc" +#define PREDEF_UNMOUNT_MMC "unmountmmc" +#define PREDEF_FORMAT_MMC "formatmmc" +#define PREDEF_CHECK_SMACK_MMC "checksmackmmc" +#define PREDEF_CHECK_MMC "checkmmc" +#define PREDEF_CHECK_MMC_PROC "checkmmcproc" + #define MMC_MOUNT_POINT "/opt/storage/sdcard" #define MMC_DEV "/dev/mmcblk" @@ -60,8 +67,6 @@ #define MMC_32GB_SIZE 61315072 -#define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0])) - typedef enum { FS_TYPE_NONE = 0, FS_TYPE_FAT = 1, @@ -796,4 +801,4 @@ int ss_mmc_init(void) if (__check_mmc_fs() != 0) PRT_TRACE_ERR("fail to check mmc"); return 0; -} \ No newline at end of file +} diff --git a/ss_predefine.c b/src/power/power-handler.c similarity index 52% rename from ss_predefine.c rename to src/power/power-handler.c index 23b234a..a50a31b 100644 --- a/ss_predefine.c +++ b/src/power/power-handler.c @@ -21,172 +21,105 @@ #include #include #include +#include +#include +#include +#include #include #include #include #include +#include #include #include #include #include #include #include "dd-deviced.h" -#include "ss_log.h" -#include "ss_launch.h" -#include "ss_queue.h" -#include "ss_device_handler.h" +#include "core/log.h" +#include "core/launch.h" +#include "core/queue.h" +#include "core/device-handler.h" #include "device-node.h" -#include "ss_predefine.h" -#include "ss_procmgr.h" -#include "ss_vibrator.h" -#include "include/ss_data.h" -#include "ss_common.h" +#include "core/predefine.h" +#include "core/data.h" +#include "core/common.h" +#include "proc/proc-handler.h" #include "poll.h" #include "setting.h" -#include "led/led.h" - -#define PREDEFINE_SO_DIR PREFIX"/lib/ss_predefine/" - -#define CALL_EXEC_PATH PREFIX"/bin/call" -#define LOWMEM_EXEC_PATH PREFIX"/bin/lowmem-popup" -#define LOWBAT_EXEC_PATH PREFIX"/bin/lowbatt-popup" -#define USBCON_EXEC_PATH PREFIX"/bin/usb-server" -#define TVOUT_EXEC_PATH PREFIX"/bin/tvout-selector" -#define PWROFF_EXEC_PATH PREFIX"/bin/poweroff-popup" -#define MEMPS_EXEC_PATH PREFIX"/bin/memps" -#define HDMI_NOTI_EXEC_PATH PREFIX"/bin/hdmi_connection_noti" -#define LOWBAT_POPUP_NAME "lowbat-syspopup" -#define POWEROFF_POPUP_NAME "poweroff-syspopup" -#define HDMI_POPUP_NAME "hdmi-syspopup" -#define LOWMEM_POPUP_NAME "lowmem-syspopup" - -/* wait for 5 sec as victim process be dead */ -#define WAITING_INTERVAL 5 - -#define TVOUT_X_BIN "/usr/bin/xberc" -#define TVOUT_FLAG 0x00000001 -#define MEMPS_LOG_FILE "/var/log/memps" -#define MAX_RETRY 2 - -#define POWEROFF_DURATION 2 -#define POWEROFF_ANIMATION_PATH "/usr/bin/boot-animation" -#define POWEROFF_NOTI_NAME "power_off_start" -#define WM_READY_PATH "/tmp/.wm_ready" +#define SIGNAL_NAME_POWEROFF_POPUP "poweroffpopup" -#define LOWBAT_OPT_WARNING 1 -#define LOWBAT_OPT_POWEROFF 2 -#define LOWBAT_OPT_CHARGEERR 3 -#define LOWBAT_OPT_CHECK 4 +#define PREDEF_ENTERSLEEP "entersleep" +#define PREDEF_LEAVESLEEP "leavesleep" +#define PREDEF_POWEROFF "poweroff" +#define PREDEF_REBOOT "reboot" +#define PREDEF_PWROFF_POPUP "pwroff-popup" +#define PREDEF_INTERNAL_POWEROFF "internal_poweroff" +#define PREDEF_FLIGHT_MODE "flightmode" -static Ecore_Timer *lowbat_popup_id = NULL; -static int lowbat_popup_option = 0; +#define POWEROFF_NOTI_NAME "power_off_start" +#define POWEROFF_DURATION 2 +#define POWEROFF_ANIMATION_PATH "/usr/bin/boot-animation" +#define MAX_RETRY 2 static struct timeval tv_start_poweroff; -static void powerdown_ap(TapiHandle *handle, const char *noti_id, void *data, void *user_data); -static void poweroff_control_cb(keynode_t *in_key, struct ss_main_data *ad); -int internal_poweroff_def_predefine_action(int argc, char **argv); - -static int ss_flags = 0; static Ecore_Timer *poweroff_timer_id = NULL; static TapiHandle *tapi_handle = NULL; static int power_off = 0; -static int __predefine_get_pid(const char *execpath) -{ - DIR *dp; - struct dirent *dentry; - int pid = -1, fd; - char buf[PATH_MAX]; - char buf2[PATH_MAX]; - - dp = opendir("/proc"); - if (!dp) { - PRT_TRACE_ERR("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; - if (read(fd, buf2, PATH_MAX) < 0) { - close(fd); - continue; - } - close(fd); +static void poweroff_popup_edbus_signal_handler(void *data, DBusMessage *msg) +{ + DBusError err; + char *str; + int val = 0; - if (!strcmp(buf2, execpath)) { - closedir(dp); - return pid; - } + if (dbus_message_is_signal(msg, INTERFACE_NAME, SIGNAL_NAME_POWEROFF_POPUP) == 0) { + PRT_TRACE_ERR("there is no power off popup signal"); + return; } - errno = ESRCH; - closedir(dp); - return -1; -} - -int is_power_off(void) -{ - return power_off; -} + dbus_error_init(&err); -static void make_memps_log(char *file, pid_t pid, char *victim_name) -{ - time_t now; - struct tm *cur_tm; - char params[4096]; - char new_log[NAME_MAX]; - static pid_t old_pid = 0; - int ret=-1; - - if (old_pid == pid) + if (dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID) == 0) { + PRT_TRACE_ERR("there is no message"); return; - old_pid = pid; + } - now = time(NULL); - cur_tm = (struct tm *)malloc(sizeof(struct tm)); - if (cur_tm == NULL) { - PRT_TRACE_ERR("Fail to memory allocation"); + if (strncmp(str, PREDEF_PWROFF_POPUP, strlen(PREDEF_PWROFF_POPUP)) == 0) + val = VCONFKEY_SYSMAN_POWER_OFF_POPUP; + else if (strncmp(str, PREDEF_POWEROFF, strlen(PREDEF_POWEROFF)) == 0) + val = VCONFKEY_SYSMAN_POWER_OFF_DIRECT; + else if (strncmp(str, PREDEF_POWEROFF, strlen(PREDEF_REBOOT)) == 0) + val = VCONFKEY_SYSMAN_POWER_OFF_RESTART; + if (val == 0) { + PRT_TRACE_ERR("not supported message : %s", str); return; } + vconf_set_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, val); +} - if (localtime_r(&now, cur_tm) == NULL) { - PRT_TRACE_ERR("Fail to get localtime"); - free(cur_tm); +static void poweroff_control_cb(keynode_t *in_key, struct ss_main_data *ad) +{ + int val; + if (vconf_get_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, &val) != 0) return; + switch (val) { + case VCONFKEY_SYSMAN_POWER_OFF_DIRECT: + ss_action_entry_call_internal(PREDEF_POWEROFF, 0); + break; + case VCONFKEY_SYSMAN_POWER_OFF_POPUP: + ss_action_entry_call_internal(PREDEF_PWROFF_POPUP, 0); + break; + case VCONFKEY_SYSMAN_POWER_OFF_RESTART: + ss_action_entry_call_internal(PREDEF_REBOOT, 0); + break; } - PRT_TRACE("%s_%s_%d_%.4d%.2d%.2d_%.2d%.2d%.2d.log", file, victim_name, - pid, (1900 + cur_tm->tm_year), 1 + cur_tm->tm_mon, - cur_tm->tm_mday, cur_tm->tm_hour, cur_tm->tm_min, - cur_tm->tm_sec); - snprintf(new_log, sizeof(new_log), - "%s_%s_%d_%.4d%.2d%.2d_%.2d%.2d%.2d.log", file, victim_name, - pid, (1900 + cur_tm->tm_year), 1 + cur_tm->tm_mon, - cur_tm->tm_mday, cur_tm->tm_hour, cur_tm->tm_min, - cur_tm->tm_sec); - - snprintf(params, sizeof(params), "-f %s", new_log); - ret = ss_launch_evenif_exist(MEMPS_EXEC_PATH, params); - /* will be removed, just for debugging */ - if(ret > 0) { - FILE *fp; - fp = open_proc_oom_adj_file(ret, "w"); - if (fp != NULL) { - fprintf(fp, "%d", (-17)); - fclose(fp); - } - } - free(cur_tm); + if (update_pm_setting) + update_pm_setting(SETTING_POWEROFF, val); } static void remount_ro() @@ -220,244 +153,69 @@ static void remount_ro() } } -static int lowmem_get_victim_pid() -{ - pid_t pid; - int fd; - - if (device_get_property(DEVICE_TYPE_MEMORY, PROP_MEMORY_VICTIM_TASK, &pid) < 0) { - PRT_TRACE_ERR("Get victim task failed"); - return -1; - } - - return pid; -} - -int lowmem_def_predefine_action(int argc, char **argv) -{ - int pid, ret, oom_adj; - char appname[PATH_MAX]; - - if (argc < 1) - return -1; - - if (!strcmp(argv[0], OOM_MEM_ACT)) { - pid = lowmem_get_victim_pid(); - if (pid > 0 && pid != get_exec_pid(LOWMEM_EXEC_PATH) && pid != get_exec_pid(MEMPS_EXEC_PATH)) { - if ((get_cmdline_name(pid, appname, PATH_MAX)) == - 0) { - PRT_TRACE_EM - ("we will kill, lowmem lv2 = %d (%s)\n", - pid, appname); - - make_memps_log(MEMPS_LOG_FILE, pid, appname); - - if(get_app_oomadj(pid, &oom_adj) < 0) { - PRT_TRACE_ERR("Failed to get oom_adj"); - return -1; - } - PRT_TRACE("%d will be killed with %d oom_adj value", pid, oom_adj); - - kill(pid, SIGTERM); - - if (oom_adj != OOMADJ_FOREGRD_LOCKED && oom_adj != OOMADJ_FOREGRD_UNLOCKED) { - return 0; - } - - bundle *b = NULL; - - b = bundle_create(); - bundle_add(b, "_APP_NAME_", appname); - ret = syspopup_launch("lowmem-syspopup", b); - bundle_free(b); - if (ret < 0) { - PRT_TRACE_EM("popup lauch failed\n"); - return -1; - } - - if (set_app_oomadj(ret, OOMADJ_SU) < 0) { - PRT_TRACE_ERR("Failed to set oom_adj"); - } - } - } - } - return 0; -} - -int usbcon_def_predefine_action(int argc, char **argv) +static void enter_flight_mode_cb(TapiHandle *handle, int result, void *data, void *user_data) { - int pid; - int val = -1; - int ret = -1; - int bat_state = VCONFKEY_SYSMAN_BAT_NORMAL; - - if (device_get_property(DEVICE_TYPE_EXTCON, PROP_EXTCON_USB_ONLINE, &val) == 0) { - if (val == 0) { - vconf_set_int(VCONFKEY_SYSMAN_USB_STATUS, - VCONFKEY_SYSMAN_USB_DISCONNECTED); - pm_unlock_internal(getpid(), LCD_OFF, STAY_CUR_STATE); - return 0; - } - - if ( vconf_get_int(VCONFKEY_SYSMAN_USB_STATUS, &val) == 0 && val == VCONFKEY_SYSMAN_USB_AVAILABLE) - return 0; - - vconf_set_int(VCONFKEY_SYSMAN_USB_STATUS, - VCONFKEY_SYSMAN_USB_AVAILABLE); - pm_lock_internal(getpid(), LCD_OFF, STAY_CUR_STATE, 0); - pid = ss_launch_if_noexist(USBCON_EXEC_PATH, NULL); - if (pid < 0) { - PRT_TRACE_ERR("usb predefine action failed\n"); - return -1; + int bCurFlightMode = 0; + if (result != TAPI_POWER_FLIGHT_MODE_ENTER) { + PRT_TRACE_ERR("flight mode enter failed %d",result); + } else { + PRT_TRACE("enter flight mode result : %d",result); + if (vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE,&bCurFlightMode) == 0) { + PRT_TRACE("Flight Mode is %d", bCurFlightMode); + } else { + PRT_TRACE_ERR("failed to get vconf key"); } - return pid; } - PRT_TRACE_ERR("failed to get usb status\n"); - return -1; } -int earjackcon_def_predefine_action(int argc, char **argv) -{ - int val; - - PRT_TRACE_EM("earjack_normal predefine action\n"); - if (device_get_property(DEVICE_TYPE_EXTCON, PROP_EXTCON_EARJACK_ONLINE, &val) == 0) { - return vconf_set_int(VCONFKEY_SYSMAN_EARJACK, val); - } - - return -1; -} - -int lowbat_popup(void *data) +static void leave_flight_mode_cb(TapiHandle *handle, int result, void *data, void *user_data) { - int ret = -1, state = 0; - ret = vconf_get_int(VCONFKEY_STARTER_SEQUENCE, &state); - if (state == 1 || ret != 0) { - bundle *b = NULL; - b = bundle_create(); - if (lowbat_popup_option == LOWBAT_OPT_WARNING || lowbat_popup_option == LOWBAT_OPT_CHECK) { - bundle_add(b, "_SYSPOPUP_CONTENT_", "warning"); - } else if(lowbat_popup_option == LOWBAT_OPT_POWEROFF) { - bundle_add(b, "_SYSPOPUP_CONTENT_", "poweroff"); - } else if(lowbat_popup_option == LOWBAT_OPT_CHARGEERR) { - bundle_add(b, "_SYSPOPUP_CONTENT_", "chargeerr"); + int bCurFlightMode = 0; + if (result != TAPI_POWER_FLIGHT_MODE_LEAVE) { + PRT_TRACE_ERR("flight mode leave failed %d",result); + } else { + PRT_TRACE("leave flight mode result : %d",result); + if (vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE,&bCurFlightMode) == 0) { + PRT_TRACE("Flight Mode is %d", bCurFlightMode); } else { - bundle_add(b, "_SYSPOPUP_CONTENT_", "check"); - } - - ret = syspopup_launch("lowbat-syspopup", b); - if (ret < 0) { - PRT_TRACE_EM("popup lauch failed\n"); - bundle_free(b); - return 1; + PRT_TRACE_ERR("failed to get vconf key"); } - lowbat_popup_id = NULL; - lowbat_popup_option = 0; - bundle_free(b); - } else { - PRT_TRACE_EM("boot-animation running yet"); - return 1; } - - return 0; } - -int predefine_control_launch(char *name, bundle *b) +int flight_mode_def_predefine_action(int argc, char **argv) { - int pid; - static int launched_poweroff = 0; - //lowbat-popup - if (strncmp(name, LOWBAT_POPUP_NAME, strlen(LOWBAT_POPUP_NAME)) == 0) { - if (launched_poweroff == 1) { - PRT_TRACE_ERR("will be foreced power off"); - internal_poweroff_def_predefine_action(0,NULL); - return 0; - } - - if (lowbat_popup_option == LOWBAT_OPT_POWEROFF) - launched_poweroff = 1; - - pid = __predefine_get_pid(LOWBAT_EXEC_PATH); - if (pid > 0) { - PRT_TRACE_ERR("pre launched %s destroy", LOWBAT_EXEC_PATH); - kill(pid, SIGTERM); - } - if (syspopup_launch(name, b) < 0) - return -1; - } - //poweroff-popup - if (strncmp(name, POWEROFF_POPUP_NAME, strlen(POWEROFF_POPUP_NAME)) == 0) { - if (syspopup_launch(name, b) < 0) - return -1; - } - //hdmi-popup - if (strncmp(name, HDMI_POPUP_NAME, strlen(HDMI_POPUP_NAME)) == 0) { - if (syspopup_launch(name, b) < 0) - return -1; - } - //hdmi-noti - if (strncmp(name, HDMI_NOTI_EXEC_PATH, strlen(HDMI_NOTI_EXEC_PATH)) == 0) { - if (ss_launch_if_noexist(name, "1") < 0) - return -1; + int bCurFlightMode; + int err = TAPI_API_SUCCESS; + if (argc != 1 || argv[0] == NULL) { + PRT_TRACE_ERR("FlightMode Set predefine action failed"); + return -1; } - //user mem lowmem-popup - if (strncmp(name, LOWMEM_POPUP_NAME, strlen(LOWMEM_POPUP_NAME)) == 0) { - if (syspopup_launch(name, b) < 0) - return -1; + bCurFlightMode = atoi(argv[0]); + if (bCurFlightMode == 1) { + err = tel_set_flight_mode(tapi_handle, TAPI_POWER_FLIGHT_MODE_LEAVE, leave_flight_mode_cb, NULL); + } else if (bCurFlightMode == 0) { + err = tel_set_flight_mode(tapi_handle, TAPI_POWER_FLIGHT_MODE_ENTER, enter_flight_mode_cb, NULL); } + if (err != TAPI_API_SUCCESS) + PRT_TRACE_ERR("FlightMode tel api action failed %d",err); return 0; -} -void predefine_pm_change_state(unsigned int s_bits) -{ - pm_change_internal(getpid(), s_bits); } -int lowbat_def_predefine_action(int argc, char **argv) +static void __tel_init_cb(keynode_t *key_nodes,void *data) { - int ret, state=0; - char argstr[128]; - char* option = NULL; - - if (argc < 1) - return -1; - - if (lowbat_popup_id != NULL) { - ecore_timer_del(lowbat_popup_id); - lowbat_popup_id = NULL; - } - - bundle *b = NULL; - b = bundle_create(); - if (!strcmp(argv[0],CRITICAL_LOW_BAT_ACT)) { - bundle_add(b, "_SYSPOPUP_CONTENT_", "warning"); - lowbat_popup_option = LOWBAT_OPT_CHECK; - } else if(!strcmp(argv[0],WARNING_LOW_BAT_ACT)) { - bundle_add(b, "_SYSPOPUP_CONTENT_", "warning"); - lowbat_popup_option = LOWBAT_OPT_WARNING; - } else if(!strcmp(argv[0],POWER_OFF_BAT_ACT)) { - bundle_add(b, "_SYSPOPUP_CONTENT_", "poweroff"); - lowbat_popup_option = LOWBAT_OPT_POWEROFF; - } else if(!strcmp(argv[0],CHARGE_ERROR_ACT)) { - bundle_add(b, "_SYSPOPUP_CONTENT_", "chargeerr"); - lowbat_popup_option = LOWBAT_OPT_CHARGEERR; - } - - ret = vconf_get_int(VCONFKEY_STARTER_SEQUENCE, &state); - if (state == 1 || ret != 0) { - if (predefine_control_launch("lowbat-syspopup", b) < 0) { - PRT_TRACE_ERR("popup lauch failed\n"); - bundle_free(b); - lowbat_popup_option = 0; - return -1; + int bTelReady = 0; + bTelReady = vconf_keynode_get_bool(key_nodes); + if (bTelReady == 1) { + vconf_ignore_key_changed(VCONFKEY_TELEPHONY_READY, (void*)__tel_init_cb); + tapi_handle = tel_init(NULL); + if (tapi_handle == NULL) { + PRT_TRACE_ERR("tapi init error"); } } else { - PRT_TRACE_EM("boot-animation running yet"); - lowbat_popup_id = ecore_timer_add(1, lowbat_popup, NULL); + PRT_TRACE_ERR("tapi is not ready yet"); } - bundle_free(b); - return 0; } Eina_Bool powerdown_ap_by_force(void *data) @@ -536,23 +294,6 @@ static void powerdown_res_cb(TapiHandle *handle, int result, void *data, void *u PRT_TRACE("poweroff command request : %d",result); } -int poweroff_def_predefine_action(int argc, char **argv) -{ - int retry_count = 0; - - heynoti_publish(POWEROFF_NOTI_NAME); - - while (retry_count < MAX_RETRY) { - if (ss_action_entry_call_internal(PREDEF_INTERNAL_POWEROFF, 0) < 0) { - PRT_TRACE_ERR("failed to request poweroff to system_server \n"); - retry_count++; - continue; - } - vconf_ignore_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, (void*)poweroff_control_cb); - return 0; - } - return -1; -} int internal_poweroff_def_predefine_action(int argc, char **argv) { @@ -585,65 +326,6 @@ int internal_poweroff_def_predefine_action(int argc, char **argv) return 0; } -static void enter_flight_mode_cb(TapiHandle *handle, int result, void *data, void *user_data) -{ - int bCurFlightMode = 0; - if (result != TAPI_POWER_FLIGHT_MODE_ENTER) { - PRT_TRACE_ERR("flight mode enter failed %d",result); - } else { - PRT_TRACE("enter flight mode result : %d",result); - if (vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE,&bCurFlightMode) == 0) { - PRT_TRACE("Flight Mode is %d", bCurFlightMode); - } else { - PRT_TRACE_ERR("failed to get vconf key"); - } - } -} - -static void leave_flight_mode_cb(TapiHandle *handle, int result, void *data, void *user_data) -{ - int bCurFlightMode = 0; - if (result != TAPI_POWER_FLIGHT_MODE_LEAVE) { - PRT_TRACE_ERR("flight mode leave failed %d",result); - } else { - PRT_TRACE("leave flight mode result : %d",result); - if (vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE,&bCurFlightMode) == 0) { - PRT_TRACE("Flight Mode is %d", bCurFlightMode); - } else { - PRT_TRACE_ERR("failed to get vconf key"); - } - } -} - -int entersleep_def_predefine_action(int argc, char **argv) -{ - int ret; - - pm_change_internal(getpid(), LCD_NORMAL); - sync(); - - ret = tel_set_flight_mode(tapi_handle, TAPI_POWER_FLIGHT_MODE_ENTER, enter_flight_mode_cb, NULL); - PRT_TRACE_ERR("request for changing into flight mode : %d\n", ret); - - system("/etc/rc.d/rc.entersleep"); - pm_change_internal(getpid(), POWER_OFF); - - return 0; -} - -int leavesleep_def_predefine_action(int argc, char **argv) -{ - int ret; - - pm_change_internal(getpid(), LCD_NORMAL); - sync(); - - ret = tel_set_flight_mode(tapi_handle, TAPI_POWER_FLIGHT_MODE_LEAVE, leave_flight_mode_cb, NULL); - PRT_TRACE_ERR("request for changing into flight mode : %d\n", ret); - - return 0; -} - static void restart_ap(TapiHandle *handle, const char *noti_id, void *data, void *user_data); Eina_Bool restart_ap_ecore(void *data) @@ -728,36 +410,38 @@ static void restart_ap_by_force(void *data) reboot(RB_AUTOBOOT); } -int restart_def_predefine_action(int argc, char **argv) +int entersleep_def_predefine_action(int argc, char **argv) { int ret; - heynoti_publish(POWEROFF_NOTI_NAME); pm_change_internal(getpid(), LCD_NORMAL); - system("/etc/rc.d/rc.shutdown &"); sync(); - gettimeofday(&tv_start_poweroff, NULL); + ret = tel_set_flight_mode(tapi_handle, TAPI_POWER_FLIGHT_MODE_ENTER, enter_flight_mode_cb, NULL); + PRT_TRACE_ERR("request for changing into flight mode : %d\n", ret); - ret = - tel_register_noti_event(tapi_handle, TAPI_NOTI_MODEM_POWER, restart_ap, NULL); - if (ret != TAPI_API_SUCCESS) { - PRT_TRACE_ERR - ("tel_register_event is not subscribed. error %d\n", ret); - restart_ap_by_force((void *)-1); - return 0; - } + system("/etc/rc.d/rc.entersleep"); + pm_change_internal(getpid(), POWER_OFF); + return 0; +} - ret = tel_process_power_command(tapi_handle, TAPI_PHONE_POWER_OFF, powerdown_res_cb, NULL); - if (ret != TAPI_API_SUCCESS) { - PRT_TRACE_ERR("tel_process_power_command() error %d\n", ret); - restart_ap_by_force((void *)-1); +int poweroff_def_predefine_action(int argc, char **argv) +{ + int retry_count = 0; + + heynoti_publish(POWEROFF_NOTI_NAME); + + while (retry_count < MAX_RETRY) { + if (ss_action_entry_call_internal(PREDEF_INTERNAL_POWEROFF, 0) < 0) { + PRT_TRACE_ERR("failed to request poweroff to system_server \n"); + retry_count++; + continue; + } + vconf_ignore_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, (void*)poweroff_control_cb); return 0; } - - poweroff_timer_id = ecore_timer_add(15, restart_ap_ecore, NULL); - return 0; + return -1; } int launching_predefine_action(int argc, char **argv) @@ -768,111 +452,60 @@ int launching_predefine_action(int argc, char **argv) return -1; /* current just launching poweroff-popup */ - if (predefine_control_launch("poweroff-syspopup", NULL) < 0) { + if (predefine_control_launch("poweroff-syspopup", NULL, 0) < 0) { PRT_TRACE_ERR("poweroff-syspopup launch failed"); return -1; } return 0; } -int flight_mode_def_predefine_action(int argc, char **argv) +int leavesleep_def_predefine_action(int argc, char **argv) { - int bCurFlightMode; - int err = TAPI_API_SUCCESS; - if (argc != 1 || argv[0] == NULL) { - PRT_TRACE_ERR("FlightMode Set predefine action failed"); - return -1; - } - bCurFlightMode = atoi(argv[0]); - if (bCurFlightMode == 1) { - err = tel_set_flight_mode(tapi_handle, TAPI_POWER_FLIGHT_MODE_LEAVE, leave_flight_mode_cb, NULL); - } else if (bCurFlightMode == 0) { - err = tel_set_flight_mode(tapi_handle, TAPI_POWER_FLIGHT_MODE_ENTER, enter_flight_mode_cb, NULL); - } - if (err != TAPI_API_SUCCESS) - PRT_TRACE_ERR("FlightMode tel api action failed %d",err); - return 0; + int ret; + + pm_change_internal(getpid(), LCD_NORMAL); + sync(); + ret = tel_set_flight_mode(tapi_handle, TAPI_POWER_FLIGHT_MODE_LEAVE, leave_flight_mode_cb, NULL); + PRT_TRACE_ERR("request for changing into flight mode : %d\n", ret); + + return 0; } -static void ss_action_entry_load_from_sodir() +int restart_def_predefine_action(int argc, char **argv) { - DIR *dp; - struct dirent *dentry; - struct sysnoti *msg; - char *ext; - char tmp[128]; - - dp = opendir(PREDEFINE_SO_DIR); - if (!dp) { - ERR("fail open %s", PREDEFINE_SO_DIR); - return; - } - - msg = malloc(sizeof(struct sysnoti)); - if (msg == NULL) { - ERR("Malloc failed"); - closedir(dp); - return; - } + int ret; - msg->pid = getpid(); + heynoti_publish(POWEROFF_NOTI_NAME); + pm_change_internal(getpid(), LCD_NORMAL); + system("/etc/rc.d/rc.shutdown &"); + sync(); - while ((dentry = readdir(dp)) != NULL) { - if ((ext = strstr(dentry->d_name, ".so")) == NULL) - continue; + gettimeofday(&tv_start_poweroff, NULL); - snprintf(tmp, sizeof(tmp), "%s/%s", PREDEFINE_SO_DIR, - dentry->d_name); - msg->path = tmp; - *ext = 0; - msg->type = &(dentry->d_name[3]); - ss_action_entry_add(msg); + ret = + tel_register_noti_event(tapi_handle, TAPI_NOTI_MODEM_POWER, restart_ap, NULL); + if (ret != TAPI_API_SUCCESS) { + PRT_TRACE_ERR + ("tel_register_event is not subscribed. error %d\n", ret); + restart_ap_by_force((void *)-1); + return 0; } - free(msg); - closedir(dp); -} -static void __tel_init_cb(keynode_t *key_nodes,void *data) -{ - int bTelReady = 0; - bTelReady = vconf_keynode_get_bool(key_nodes); - if (bTelReady == 1) { - vconf_ignore_key_changed(VCONFKEY_TELEPHONY_READY, (void*)__tel_init_cb); - tapi_handle = tel_init(NULL); - if (tapi_handle == NULL) { - PRT_TRACE_ERR("tapi init error"); - } - } else { - PRT_TRACE_ERR("tapi is not ready yet"); - } -} -static void poweroff_control_cb(keynode_t *in_key, struct ss_main_data *ad) -{ - int val; - if (vconf_get_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, &val) != 0) - return; - switch (val) { - case VCONFKEY_SYSMAN_POWER_OFF_DIRECT: - ss_action_entry_call_internal(PREDEF_POWEROFF, 0); - break; - case VCONFKEY_SYSMAN_POWER_OFF_POPUP: - ss_action_entry_call_internal(PREDEF_PWROFF_POPUP, 0); - break; - case VCONFKEY_SYSMAN_POWER_OFF_RESTART: - ss_action_entry_call_internal(PREDEF_REBOOT, 0); - break; + + ret = tel_process_power_command(tapi_handle, TAPI_PHONE_POWER_OFF, powerdown_res_cb, NULL); + if (ret != TAPI_API_SUCCESS) { + PRT_TRACE_ERR("tel_process_power_command() error %d\n", ret); + restart_ap_by_force((void *)-1); + return 0; } - if (update_pm_setting) - update_pm_setting(SETTING_POWEROFF, val); + poweroff_timer_id = ecore_timer_add(15, restart_ap_ecore, NULL); + return 0; } -void ss_predefine_internal_init(void) +void ss_predefine_power_init(void) { - - /* telephony initialize */ - int ret = 0; int bTelReady = 0; if (vconf_get_bool(VCONFKEY_TELEPHONY_READY,&bTelReady) == 0) { if (bTelReady == 1) { @@ -886,40 +519,36 @@ void ss_predefine_internal_init(void) } else { PRT_TRACE_ERR("failed to get tapi vconf key"); } -#ifdef NOUSE - ss_action_entry_add_internal(PREDEF_CALL, call_predefine_action, NULL, - NULL); -#endif - ss_action_entry_add_internal(PREDEF_LOWMEM, lowmem_def_predefine_action, - NULL, NULL); - ss_action_entry_add_internal(PREDEF_LOWBAT, lowbat_def_predefine_action, - NULL, NULL); - ss_action_entry_add_internal(PREDEF_USBCON, usbcon_def_predefine_action, - NULL, NULL); - ss_action_entry_add_internal(PREDEF_EARJACKCON, - earjackcon_def_predefine_action, NULL, + + ss_action_entry_add_internal(PREDEF_ENTERSLEEP, + entersleep_def_predefine_action, NULL, NULL); ss_action_entry_add_internal(PREDEF_POWEROFF, poweroff_def_predefine_action, NULL, NULL); ss_action_entry_add_internal(PREDEF_PWROFF_POPUP, launching_predefine_action, NULL, NULL); + ss_action_entry_add_internal(PREDEF_LEAVESLEEP, + leavesleep_def_predefine_action, NULL, + NULL); ss_action_entry_add_internal(PREDEF_REBOOT, restart_def_predefine_action, NULL, NULL); - ss_action_entry_add_internal(PREDEF_FLIGHT_MODE, - flight_mode_def_predefine_action, NULL, NULL); + ss_action_entry_add_internal(PREDEF_INTERNAL_POWEROFF, internal_poweroff_def_predefine_action, NULL, NULL); - ss_action_entry_add_internal(PREDEF_HAPTIC, haptic_def_predefine_action, - NULL, NULL); - ss_action_entry_add_internal(PREDEF_LED, - led_def_predefine_action, NULL, NULL); + ss_action_entry_add_internal(PREDEF_FLIGHT_MODE, + flight_mode_def_predefine_action, NULL, NULL); if (vconf_notify_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, (void *)poweroff_control_cb, NULL) < 0) { PRT_TRACE_ERR("Vconf notify key chaneged failed: KEY(%s)", VCONFKEY_SYSMAN_POWER_OFF_STATUS); } - ss_action_entry_load_from_sodir(); - /* check and set earjack init status */ - earjackcon_def_predefine_action(0, NULL); } +int ss_power_init(struct ss_main_data *ad) +{ + + register_edbus_signal_handler(SIGNAL_NAME_POWEROFF_POPUP, + (void *)poweroff_popup_edbus_signal_handler); + return 0; +} + diff --git a/src/power/power-handler.h b/src/power/power-handler.h new file mode 100644 index 0000000..4aadf99 --- /dev/null +++ b/src/power/power-handler.h @@ -0,0 +1,29 @@ +/* + * system-server + * + * 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. + * +*/ + + +#ifndef __POWER_HANDLER_H__ +#define __POWER_HANDLER_H__ + +#include "core/data.h" + +void ss_predefine_power_init(void); +int ss_power_init(struct ss_main_data *ad); + +#endif /* __POWER_HANDLER_H__ */ diff --git a/ss_lowmem_handler.c b/src/proc/lowmem-handler.c similarity index 70% rename from ss_lowmem_handler.c rename to src/proc/lowmem-handler.c index 5fd4ddd..74788fd 100644 --- a/ss_lowmem_handler.c +++ b/src/proc/lowmem-handler.c @@ -21,16 +21,26 @@ #include #include #include +#include #include #include +#include #include "device-node.h" -#include "ss_log.h" -#include "ss_noti.h" -#include "ss_queue.h" -#include "include/ss_data.h" - +#include "core/log.h" +#include "core/noti.h" +#include "core/queue.h" +#include "core/predefine.h" +#include "core/data.h" + +#define PREDEF_LOWMEM "lowmem" +#define OOM_MEM_ACT "oom_mem_act" #define DELETE_SM "sh -c "PREFIX"/bin/delete.sm" +#define LOWMEM_EXEC_PATH PREFIX"/bin/lowmem-popup" +#define MEMPS_LOG_FILE "/var/log/memps" +#define MEMPS_EXEC_PATH PREFIX"/bin/memps" +/* wait for 5 sec as victim process be dead */ +#define WAITING_INTERVAL 5 #define MEMNOTIFY_NORMAL 0x0000 #define MEMNOTIFY_LOW 0xfaac @@ -205,7 +215,6 @@ static int memory_low_act(void *data) PRT_TRACE("[LOW MEM STATE] memory low state"); make_LMM_log("/var/log/memps", 1, "LOWMEM_WARNING"); remove_shm(); - heynoti_get_snoti_name(_SYS_RES_CLEANUP, lowmem_noti_name, NAME_MAX); ss_noti_send(lowmem_noti_name); vconf_set_int(VCONFKEY_SYSMAN_LOW_MEMORY, @@ -271,10 +280,12 @@ static int lowmem_process(unsigned int mem_state, void *ad) static unsigned int lowmem_read(int fd) { unsigned int mem_state; - read(fd, &mem_state, sizeof(mem_state)); + if (read(fd, &mem_state, sizeof(mem_state)) < 0) { + PRT_TRACE_ERR("error lowmem state"); + return -1; + } return mem_state; } - static int lowmem_cb(void *data, Ecore_Fd_Handler * fd_handler) { int fd; @@ -284,13 +295,13 @@ static int lowmem_cb(void *data, Ecore_Fd_Handler * fd_handler) if (!ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ)) { PRT_TRACE_ERR ("ecore_main_fd_handler_active_get error , return\n"); - return 1; + return -1; } fd = ecore_main_fd_handler_fd_get(fd_handler); if (fd < 0) { PRT_TRACE_ERR("ecore_main_fd_handler_fd_get error , return"); - return 1; + return -1; } mem_state = lowmem_read(fd); print_lowmem_state(mem_state); @@ -315,6 +326,123 @@ static int set_threshold() return 0; } +static void make_memps_log(char *file, pid_t pid, char *victim_name) +{ + time_t now; + struct tm *cur_tm; + char params[4096]; + char new_log[NAME_MAX]; + static pid_t old_pid = 0; + int ret=-1; + + if (old_pid == pid) + return; + old_pid = pid; + + now = time(NULL); + cur_tm = (struct tm *)malloc(sizeof(struct tm)); + if (cur_tm == NULL) { + PRT_TRACE_ERR("Fail to memory allocation"); + return; + } + + if (localtime_r(&now, cur_tm) == NULL) { + PRT_TRACE_ERR("Fail to get localtime"); + free(cur_tm); + return; + } + + PRT_TRACE("%s_%s_%d_%.4d%.2d%.2d_%.2d%.2d%.2d.log", file, victim_name, + pid, (1900 + cur_tm->tm_year), 1 + cur_tm->tm_mon, + cur_tm->tm_mday, cur_tm->tm_hour, cur_tm->tm_min, + cur_tm->tm_sec); + snprintf(new_log, sizeof(new_log), + "%s_%s_%d_%.4d%.2d%.2d_%.2d%.2d%.2d.log", file, victim_name, + pid, (1900 + cur_tm->tm_year), 1 + cur_tm->tm_mon, + cur_tm->tm_mday, cur_tm->tm_hour, cur_tm->tm_min, + cur_tm->tm_sec); + + snprintf(params, sizeof(params), "-f %s", new_log); + ret = ss_launch_evenif_exist(MEMPS_EXEC_PATH, params); + /* will be removed, just for debugging */ + if(ret > 0) { + FILE *fp; + fp = open_proc_oom_adj_file(ret, "w"); + if (fp != NULL) { + fprintf(fp, "%d", (-17)); + fclose(fp); + } + } + free(cur_tm); +} + +static int lowmem_get_victim_pid() +{ + pid_t pid; + int fd; + + if (device_get_property(DEVICE_TYPE_MEMORY, PROP_MEMORY_VICTIM_TASK, &pid) < 0) { + PRT_TRACE_ERR("Get victim task failed"); + return -1; + } + + return pid; +} + +int lowmem_def_predefine_action(int argc, char **argv) +{ + int pid, ret, oom_adj; + char appname[PATH_MAX]; + + if (argc < 1) + return -1; + + if (!strcmp(argv[0], OOM_MEM_ACT)) { + pid = lowmem_get_victim_pid(); + if (pid > 0 && pid != get_exec_pid(LOWMEM_EXEC_PATH) && pid != get_exec_pid(MEMPS_EXEC_PATH)) { + if ((get_cmdline_name(pid, appname, PATH_MAX)) == + 0) { + PRT_TRACE_EM + ("we will kill, lowmem lv2 = %d (%s)\n", + pid, appname); + make_memps_log(MEMPS_LOG_FILE, pid, appname); + + if(get_app_oomadj(pid, &oom_adj) < 0) { + PRT_TRACE_ERR("Failed to get oom_adj"); + return -1; + } + PRT_TRACE("%d will be killed with %d oom_adj value", pid, oom_adj); + + kill(pid, SIGTERM); + + if (check_oomadj(oom_adj) == 0) + return 0; + + bundle *b = NULL; + + b = bundle_create(); + bundle_add(b, "_APP_NAME_", appname); + ret = syspopup_launch("lowmem-syspopup", b); + bundle_free(b); + if (ret < 0) { + PRT_TRACE_EM("popup lauch failed\n"); + return -1; + } + + if (set_su_oomadj(ret) < 0) { + PRT_TRACE_ERR("Failed to set oom_adj"); + } + } + } + } + return 0; +} +int ss_predefine_lowmem_init(void) +{ + ss_action_entry_add_internal(PREDEF_LOWMEM, lowmem_def_predefine_action, + NULL, NULL); +} + int ss_lowmem_init(struct ss_main_data *ad) { char lowmem_dev_node[PATH_MAX]; diff --git a/src/proc/lowmem-handler.h b/src/proc/lowmem-handler.h new file mode 100644 index 0000000..4ec0625 --- /dev/null +++ b/src/proc/lowmem-handler.h @@ -0,0 +1,25 @@ +/* + * system-server + * + * 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. + * +*/ + + +#ifndef __LOWMEM_HANDLER_H__ +#define __LOWMEM_HANDLER_H__ + +void ss_predefine_lowmem_init(void); +#endif /* __LOWMEM_HANDLER_H__ */ diff --git a/ss_pmon_handler.c b/src/proc/pmon-handler.c similarity index 98% rename from ss_pmon_handler.c rename to src/proc/pmon-handler.c index 01e031f..9d5ccdf 100644 --- a/ss_pmon_handler.c +++ b/src/proc/pmon-handler.c @@ -22,10 +22,10 @@ #include #include "device-node.h" -#include "ss_log.h" -#include "ss_launch.h" -#include "include/ss_data.h" -#include "ss_common.h" +#include "core/log.h" +#include "core/launch.h" +#include "core/data.h" +#include "core/common.h" #define PMON_PERMANENT_DIR "/tmp/permanent" @@ -233,7 +233,6 @@ static int __pmon_start(struct ss_main_data *ad) { int pmon_fd = -1; char pmon_dev_node[PATH_MAX]; - if (device_get_property(DEVICE_TYPE_PROCESS, PROP_PROCESS_NODE, pmon_dev_node) < 0) { PRT_TRACE_ERR("ss_pmon_init get dev node path failed"); return -1; diff --git a/ss_pmon_handler.h b/src/proc/pmon-handler.h similarity index 96% rename from ss_pmon_handler.h rename to src/proc/pmon-handler.h index 70c7fe4..012ac3a 100644 --- a/ss_pmon_handler.h +++ b/src/proc/pmon-handler.h @@ -18,7 +18,7 @@ #ifndef __SS_PMON_HANDLER_H__ #define __SS_PMON_HANDLER_H__ -#include "include/ss_data.h" +#include "core/data.h" int ss_pmon_init(struct ss_main_data *ad); diff --git a/ss_procmgr.c b/src/proc/proc-handler.c old mode 100755 new mode 100644 similarity index 91% rename from ss_procmgr.c rename to src/proc/proc-handler.c index 01748ef..634e0b8 --- a/ss_procmgr.c +++ b/src/proc/proc-handler.c @@ -22,14 +22,31 @@ #include #include -#include "include/ss_data.h" -#include "ss_queue.h" -#include "ss_log.h" +#include "core/data.h" +#include "core/queue.h" +#include "core/log.h" +#include "core/common.h" + +#define OOMADJ_SU (-17) +#define OOMADJ_INIT (-16) +#define OOMADJ_FOREGRD_LOCKED (-15) +#define OOMADJ_FOREGRD_UNLOCKED (-10) +#define OOMADJ_BACKGRD_LOCKED (-5) +#define OOMADJ_BACKGRD_UNLOCKED (1) + +#define OOMADJ_APP_LIMIT (-16) #define LIMITED_BACKGRD_NUM 15 #define MAX_BACKGRD_OOMADJ (OOMADJ_BACKGRD_UNLOCKED + LIMITED_BACKGRD_NUM) #define PROCESS_VIP "process_vip" #define PROCESS_PERMANENT "process_permanent" +#define OOMADJ_SET "oomadj_set" + +#define PREDEF_BACKGRD "backgrd" +#define PREDEF_FOREGRD "foregrd" +#define PREDEF_ACTIVE "active" +#define PREDEF_INACTIVE "inactive" +#define PROCESS_GROUP_SET "process_group_set" int get_app_oomadj(int pid, int *oomadj) { @@ -91,6 +108,18 @@ int set_app_oomadj(pid_t pid, int new_oomadj) return 0; } +int set_su_oomadj(pid_t pid) +{ + return set_app_oomadj(pid, OOMADJ_SU); +} + +int check_oomadj(int oom_adj) +{ + if (oom_adj != OOMADJ_FOREGRD_LOCKED && oom_adj != OOMADJ_FOREGRD_UNLOCKED) + return 0; + return -1; +} + int set_oomadj_action(int argc, char **argv) { int pid = -1; @@ -317,9 +346,9 @@ int set_foregrd_action(int argc, char **argv) default: if(oomadj > OOMADJ_BACKGRD_UNLOCKED) { ret = set_app_oomadj((pid_t) pid, OOMADJ_FOREGRD_UNLOCKED); - } else { + } else { PRT_TRACE_EM("Unknown oomadj value (%d) !", oomadj); - ret = -1; + ret = -1; } break; @@ -361,9 +390,9 @@ int set_backgrd_action(int argc, char **argv) default: if(oomadj > OOMADJ_BACKGRD_UNLOCKED) { ret = 0; - } else { + } else { PRT_TRACE_EM("Unknown oomadj value (%d) !", oomadj); - ret = -1; + ret = -1; } break; } diff --git a/ss_procmgr.h b/src/proc/proc-handler.h similarity index 100% rename from ss_procmgr.h rename to src/proc/proc-handler.h diff --git a/ss_ta_handler.c b/src/ta/ta-handler.c similarity index 96% rename from ss_ta_handler.c rename to src/ta/ta-handler.c index 72ec823..eafb2c0 100644 --- a/ss_ta_handler.c +++ b/src/ta/ta-handler.c @@ -18,8 +18,8 @@ #include #include "device-node.h" -#include "ss_log.h" -#include "include/ss_data.h" +#include "core/log.h" +#include "core/data.h" #include "poll.h" #define RETRY 3 diff --git a/ss_timemgr.c b/src/time/time-handler.c similarity index 97% rename from ss_timemgr.c rename to src/time/time-handler.c index 31446a1..cc36365 100644 --- a/ss_timemgr.c +++ b/src/time/time-handler.c @@ -23,9 +23,9 @@ #include #include -#include "include/ss_data.h" -#include "ss_queue.h" -#include "ss_log.h" +#include "core/data.h" +#include "core/queue.h" +#include "core/log.h" #include "poll.h" #include @@ -34,6 +34,9 @@ #include #include +#define PREDEF_SET_DATETIME "set_datetime" +#define PREDEF_SET_TIMEZONE "set_timezone" + #ifndef TFD_TIMER_CANCELON_SET #define TFD_TIMER_CANCELON_SET (1<<1) #endif diff --git a/ss_timemgr.h b/src/time/time-handler.h similarity index 100% rename from ss_timemgr.h rename to src/time/time-handler.h diff --git a/ss_usb_handler.c b/src/usb/usb-handler.c similarity index 95% rename from ss_usb_handler.c rename to src/usb/usb-handler.c index 3961643..14ce2d0 100644 --- a/ss_usb_handler.c +++ b/src/usb/usb-handler.c @@ -17,10 +17,10 @@ #include -#include "ss_log.h" +#include "core/log.h" #include "device-node.h" -#include "ss_launch.h" -#include "include/ss_data.h" +#include "core/launch.h" +#include "core/data.h" #include "poll.h" #define USBCON_EXEC_PATH PREFIX"/bin/usb-server" diff --git a/ss_vibrator.c b/src/vibrator/vibrator.c similarity index 96% rename from ss_vibrator.c rename to src/vibrator/vibrator.c index 9d5c7c8..2f5dbe2 100644 --- a/ss_vibrator.c +++ b/src/vibrator/vibrator.c @@ -18,14 +18,16 @@ #include #include -#include "ss_log.h" -#include "ss_predefine.h" -#include "include/ss_data.h" +#include "core/log.h" +#include "core/predefine.h" +#include "core/data.h" #ifndef MERGE_BTW_APPLICATIONS #define MERGE_BTW_APPLICATIONS #endif +#define PREDEF_HAPTIC "haptic" + enum { OPEN = 0, CLOSE, @@ -309,4 +311,10 @@ int haptic_def_predefine_action(int argc, char **argv) } return -1; -} \ No newline at end of file +} + +int vibrator_init(void) +{ + ss_action_entry_add_internal(PREDEF_HAPTIC, haptic_def_predefine_action, + NULL, NULL); +} diff --git a/ss_vibrator.h b/src/vibrator/vibrator.h similarity index 96% rename from ss_vibrator.h rename to src/vibrator/vibrator.h index 43c98c5..4694a33 100644 --- a/ss_vibrator.h +++ b/src/vibrator/vibrator.h @@ -19,5 +19,6 @@ #define __SS_VIBRATOR_H__ int haptic_def_predefine_action(int argc, char **argv); +int vibrator_init(void); #endif /* __SS_VIBRATOR_H__ */ diff --git a/sys_pci_noti/sys_pci_noti.c b/sys_pci_noti/sys_pci_noti.c index 919b82d..56ff61a 100755 --- a/sys_pci_noti/sys_pci_noti.c +++ b/sys_pci_noti/sys_pci_noti.c @@ -21,7 +21,7 @@ #include #include #include -#include "ss_log.h" +#include "core/log.h" #include "sys_pci_noti.h" static void show_tickernoti(char *msg) @@ -80,4 +80,4 @@ int main(int argc, char *argv[]) } return 0; -} \ No newline at end of file +} diff --git a/mmc-smack-label b/utils/mmc-smack-label similarity index 100% rename from mmc-smack-label rename to utils/mmc-smack-label -- 2.7.4