From cac4c534c166bd8c9778f250b0c326dc52f9f9f8 Mon Sep 17 00:00:00 2001 From: "jk7744.park" Date: Sun, 1 Feb 2015 13:34:01 +0900 Subject: [PATCH] tizen 2.3 release --- CMakeLists.txt | 132 ++- TC/unit/pkgname.h | 2 +- agent/daemon-manager-launch-agent.c | 6 - am_daemon/amd_appinfo.c | 216 +++- am_daemon/amd_appinfo.h | 20 + am_daemon/amd_key.c | 18 +- am_daemon/amd_key.h | 3 + am_daemon/amd_launch.c | 1030 ++++++++++++++--- am_daemon/amd_launch.h | 18 +- am_daemon/amd_main.c | 285 ++++- am_daemon/amd_request.c | 342 +++++- am_daemon/amd_request.h | 2 +- am_daemon/amd_status.c | 339 +++++- am_daemon/amd_status.h | 14 +- aul-mobile.manifest | 27 - aul-wearable.manifest => aul.manifest | 1 - data/aul_mime.sh | 28 - data/aul_service.sh | 28 - data/aul_service_test.sh | 15 - data/config_splash.sh | 26 + data/create_default_service.sh | 96 -- data/mida_db.sql | 47 - data/service/README | 1 - effect_img/type0_portrait.jpg | Bin 0 -> 18180 bytes effect_img/type1_portrait.jpg | Bin 0 -> 17546 bytes effect_img/type2_portrait.jpg | Bin 0 -> 17276 bytes effect_img/type3_portrait.jpg | Bin 0 -> 16749 bytes effect_img/type4_portrait.jpg | Bin 0 -> 17608 bytes include/SLP_AUL_PG.h | 117 +- include/app_signal.h | 45 +- include/app_sock.h | 29 +- include/aul.h | 479 ++------ include/aul_service.h | 84 -- include/aul_util.h | 1 + include/menu_db_util.h | 18 + include/mida.h | 51 - include/simple_util.h | 2 + launchpad_src/launchpad.c | 41 +- launchpad_src/sigchild.h | 15 +- legacy/preload.h | 108 +- packaging/ac-mobile.service | 16 - packaging/{ac-wearable.service => ac.service} | 4 +- packaging/aul.spec | 181 ++- packaging/launchpad-preload-mobile.service | 13 - ...-wearable.service => launchpad-preload.service} | 0 .../process-pool-launchpad-preload-mobile.service | 10 - ...process-pool-launchpad-preload-wearable.service | 10 - process_pool/launchpad.c | 1211 -------------------- process_pool/preload_list_for_process_pool.txt | 0 process_pool/process_pool.c | 282 ----- process_pool/process_pool.h | 37 - src/app_signal.c | 162 ++- src/app_sock.c | 46 +- src/aul_path.c | 371 ++++++ src/launch.c | 192 +++- src/launch_with_result.c | 162 ++- src/mida.c | 516 --------- src/mime.c | 249 +--- src/pkginfo.c | 159 ++- src/runtime_info.c | 178 +++ src/service.c | 187 --- test/aul_dbus.h | 4 +- test/aul_test.c | 152 +-- test/com.samsung.camera.service | 4 +- 64 files changed, 3742 insertions(+), 4090 deletions(-) delete mode 100644 aul-mobile.manifest rename aul-wearable.manifest => aul.manifest (91%) delete mode 100755 data/aul_mime.sh delete mode 100755 data/aul_service.sh delete mode 100755 data/aul_service_test.sh delete mode 100755 data/create_default_service.sh delete mode 100644 data/mida_db.sql delete mode 100644 data/service/README create mode 100755 effect_img/type0_portrait.jpg create mode 100755 effect_img/type1_portrait.jpg create mode 100755 effect_img/type2_portrait.jpg create mode 100755 effect_img/type3_portrait.jpg create mode 100755 effect_img/type4_portrait.jpg mode change 100755 => 100644 include/SLP_AUL_PG.h delete mode 100755 include/aul_service.h delete mode 100755 include/mida.h delete mode 100644 packaging/ac-mobile.service rename packaging/{ac-wearable.service => ac.service} (84%) delete mode 100644 packaging/launchpad-preload-mobile.service rename packaging/{launchpad-preload-wearable.service => launchpad-preload.service} (100%) delete mode 100644 packaging/process-pool-launchpad-preload-mobile.service delete mode 100644 packaging/process-pool-launchpad-preload-wearable.service delete mode 100755 process_pool/launchpad.c delete mode 100644 process_pool/preload_list_for_process_pool.txt delete mode 100644 process_pool/process_pool.c delete mode 100644 process_pool/process_pool.h create mode 100755 src/aul_path.c delete mode 100755 src/mida.c create mode 100755 src/runtime_info.c diff --git a/CMakeLists.txt b/CMakeLists.txt index e5fb947..e83452e 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,12 +22,17 @@ MESSAGE("Build type: ${CMAKE_BUILD_TYPE}") # Set required packages INCLUDE(FindPkgConfig) -IF(DEVICE_PROFILE STREQUAL "wearable") -pkg_check_modules(pkgs REQUIRED dlog ecore x11 libprivilege-control rua glib-2.0 ecore-x ecore-input evas vconf pkgmgr-info system-resource security-server deviced elementary libsystemd-daemon privacy-manager-client) -ELSE() -pkg_check_modules(pkgs REQUIRED dlog ecore x11 libprivilege-control rua glib-2.0 ecore-x ecore-input evas vconf pkgmgr-info security-server elementary libsystemd-daemon privacy-manager-client) -ENDIF() -pkg_check_modules(libpkgs REQUIRED dlog bundle dbus-glib-1 ail xdgmime libsmack ecore ecore-x) +SET(pkgs_requires "dlog ecore x11 libprivilege-control rua glib-2.0 ecore-x ecore-input evas vconf pkgmgr-info libresourced security-server") +SET(libpkgs_requires "dlog bundle dbus-glib-1 ail xdgmime libsmack ecore pkgmgr-info") + +IF(_APPFW_FEATURE_APP_CHECKER) + SET(pkgs_requires "${pkgs_requires} app-checker app-checker-server") + SET(libpkgs_requires "${libpkgs_requires} app-checker") + ADD_DEFINITIONS("-D_APPFW_FEATURE_APP_CHECKER") +ENDIF(_APPFW_FEATURE_APP_CHECKER) + +pkg_check_modules(pkgs REQUIRED ${pkgs_requires}) +pkg_check_modules(libpkgs REQUIRED ${libpkgs_requires}) PKG_CHECK_MODULES(PKGS REQUIRED glib-2.0 gio-2.0 dlog bundle) FIND_LIBRARY(LIB_DL dl) @@ -44,7 +49,6 @@ ENDFOREACH(flag) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/legacy) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/feature) -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/launchpad_src) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wl,-zdefs" ) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden") SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fpic") @@ -57,7 +61,7 @@ SET(CMAKE_C_FLAGS_RELEASE "-O2") SET(CMAKE_SKIP_BUILD_RPATH true) -# Get uname value to set 'TARGET' definition +# Get uname value to set 'TARGET' definition # TODO: Is this needed? FIND_PROGRAM(UNAME NAMES uname) EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH") @@ -65,16 +69,63 @@ IF("${ARCH}" STREQUAL "arm") ADD_DEFINITIONS("-DTARGET") MESSAGE("add -DTARGET") ENDIF("${ARCH}" STREQUAL "arm") -IF(DEVICE_PROFILE STREQUAL "wearable") - ADD_DEFINITIONS("-DWEARABLE_PROFILE") -ELSEIF(DEVICE_PROFILE STREQUAL "mobile") - ADD_DEFINITIONS("-DMOBILE_PROFILE") -ENDIF() ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") ADD_DEFINITIONS("-DSHARE_PREFIX=\"/usr/share/aul\"") -ADD_DEFINITIONS("-DPROCESS_POOL_ENABLE") -ADD_DEFINITIONS("-DREMOVE_DB_ACCESS") +IF(_APPFW_FEATURE_PROCESS_POOL) + ADD_DEFINITIONS("-D_APPFW_FEATURE_PROCESS_POOL") +ENDIF(_APPFW_FEATURE_PROCESS_POOL) +IF(_APPFW_FEATURE_PROCESS_POOL_COMMON) + ADD_DEFINITIONS("-D_APPFW_FEATURE_PROCESS_POOL_COMMON") +ENDIF(_APPFW_FEATURE_PROCESS_POOL_COMMON) +IF(_APPFW_FEATURE_PROCESS_POOL_HW_RENDERING) + ADD_DEFINITIONS("-D_APPFW_FEATURE_PROCESS_POOL_HW_RENDERING") +ENDIF(_APPFW_FEATURE_PROCESS_POOL_HW_RENDERING) +IF(_APPFW_FEATURE_MULTI_INSTANCE) + ADD_DEFINITIONS("-D_APPFW_FEATURE_MULTI_INSTANCE") +ENDIF(_APPFW_FEATURE_MULTI_INSTANCE) +IF(_APPFW_FEATURE_MULTI_WINDOW) + ADD_DEFINITIONS("-D_APPFW_FEATURE_MULTI_WINDOW") +ENDIF(_APPFW_FEATURE_MULTI_WINDOW) +IF(_APPFW_FEATURE_CHANGEABLE_COLOR) + ADD_DEFINITIONS("-D_APPFW_FEATURE_CHANGEABLE_COLOR") +ENDIF(_APPFW_FEATURE_CHANGEABLE_COLOR) +IF(_APPFW_FEATURE_CPU_BOOST) + ADD_DEFINITIONS("-D_APPFW_FEATURE_CPU_BOOST") +ENDIF(_APPFW_FEATURE_CPU_BOOST) +IF(_APPFW_FEATURE_CONTACT_PHONE_AS_ONE_APP) + ADD_DEFINITIONS("-D_APPFW_FEATURE_CONTACT_PHONE_AS_ONE_APP") +ENDIF(_APPFW_FEATURE_CONTACT_PHONE_AS_ONE_APP) +IF(_APPFW_FEATURE_PRIORITY_CHANGE) + ADD_DEFINITIONS("-D_APPFW_FEATURE_PRIORITY_CHANGE") +ENDIF(_APPFW_FEATURE_PRIORITY_CHANGE) +IF(_APPFW_FEATURE_DATA_CONTROL) + ADD_DEFINITIONS("-D_APPFW_FEATURE_DATA_CONTROL") +ENDIF(_APPFW_FEATURE_DATA_CONTROL) +IF(_APPFW_FEATURE_DEBUG_LAUNCHPAD) + ADD_DEFINITIONS("-D_APPFW_FEATURE_DEBUG_LAUNCHPAD") +ENDIF(_APPFW_FEATURE_DEBUG_LAUNCHPAD) +IF(_APPFW_FEATURE_APP_CONTROL_LITE) + ADD_DEFINITIONS("-D_APPFW_FEATURE_APP_CONTROL_LITE") +ENDIF(_APPFW_FEATURE_APP_CONTROL_LITE) +IF(_APPFW_FEATURE_NATIVE_LAUNCHPAD) + ADD_DEFINITIONS("-D_APPFW_FEATURE_NATIVE_LAUNCHPAD") +ENDIF(_APPFW_FEATURE_NATIVE_LAUNCHPAD) +IF(_APPFW_FEATURE_WMS_CONNECTION_CHECK) + ADD_DEFINITIONS("-D_APPFW_FEATURE_WMS_CONNECTION_CHECK") +ENDIF(_APPFW_FEATURE_WMS_CONNECTION_CHECK) +IF(_APPFW_FEATURE_BG_PROCESS_LIMIT) + ADD_DEFINITIONS("-D_APPFW_FEATURE_BG_PROCESS_LIMIT") +ENDIF(_APPFW_FEATURE_BG_PROCESS_LIMIT) +IF(_APPFW_FEATURE_TTS_MODE) + ADD_DEFINITIONS("-D_APPFW_FEATURE_TTS_MODE") +ENDIF(_APPFW_FEATURE_TTS_MODE) +IF(_APPFW_FEATURE_ULTRA_POWER_SAVING_MODE) + ADD_DEFINITIONS("-D_APPFW_FEATURE_ULTRA_POWER_SAVING_MODE") +ENDIF(_APPFW_FEATURE_ULTRA_POWER_SAVING_MODE) +IF(_APPFW_FEATURE_VISIBILITY_CHECK_BY_LCD_STATUS) + ADD_DEFINITIONS("-D_APPFW_FEATURE_VISIBILITY_CHECK_BY_LCD_STATUS") +ENDIF(_APPFW_FEATURE_VISIBILITY_CHECK_BY_LCD_STATUS) # Linker flags SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") @@ -88,6 +139,11 @@ add_library(aul_mods STATIC src/simple_util.c ) +# launchpad_common (static library) +ADD_LIBRARY(launchpad_common STATIC + launchpad_src/util_x.c + ) + # aul add_library(aul SHARED src/pkginfo.c @@ -96,11 +152,12 @@ add_library(aul SHARED src/launch_with_result.c src/service.c src/mime.c - src/mida.c src/miregex.c src/app_signal.c src/key.c src/status.c + src/runtime_info.c + src/aul_path.c ) target_link_libraries(aul aul_mods ${libpkgs_LDFLAGS}) SET_TARGET_PROPERTIES(aul PROPERTIES SOVERSION ${VERSION_MAJOR}) @@ -110,27 +167,14 @@ SET_TARGET_PROPERTIES(aul PROPERTIES VERSION ${VERSION}) SET(AVATAR_NAME "launchpad_preloading_preinitializing_daemon") add_executable(${AVATAR_NAME} launchpad_src/launchpad.c - launchpad_src/util_x.c ) MESSAGE(" "${pkgs_LDFLAGS}) -target_link_libraries(${AVATAR_NAME} aul_mods aul ${pkgs_LDFLAGS} ${LIB_DL}) +target_link_libraries(${AVATAR_NAME} aul_mods launchpad_common aul ${pkgs_LDFLAGS} ${LIB_DL} "-pie") set_target_properties(${AVATAR_NAME} PROPERTIES SKIP_BUILD_RPATH true ) # remove rpath option that is automatically generated by cmake. -# Process pool launchpad -SET(PROCESS_POOL "process_pool_launchpad_preloading_preinitializing_daemon") -ADD_EXECUTABLE(${PROCESS_POOL} - process_pool/launchpad.c - process_pool/process_pool.c - launchpad_src/util_x.c - ) -TARGET_LINK_LIBRARIES(${PROCESS_POOL} aul_mods aul ${pkgs_LDFLAGS} ${LIB_DL}) -SET_TARGET_PROPERTIES(${PROCESS_POOL} - PROPERTIES SKIP_BUILD_RPATH true - ) # remove rpath option that is automatically generated by cmake. - add_executable(amd am_daemon/amd_main.c am_daemon/amd_key.c @@ -165,24 +209,32 @@ CONFIGURE_FILE(aul.pc.in aul.pc @ONLY) ### Install ### INSTALL(TARGETS aul DESTINATION lib COMPONENT RuntimeLibraries) INSTALL(TARGETS ${AVATAR_NAME} DESTINATION bin) -INSTALL(TARGETS ${PROCESS_POOL} DESTINATION bin) INSTALL(TARGETS amd DESTINATION bin) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/aul.h DESTINATION include/aul) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/aul_service.h DESTINATION include/aul) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/SLP_AUL_PG.h DESTINATION include/aul) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/aul_service.sh DESTINATION bin) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/aul_service_test.sh DESTINATION bin) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/aul_mime.sh DESTINATION bin) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/config_splash.sh DESTINATION bin) +IF (_APPFW_FEATURE_DEFAULT_FAKE_IMAGE) + ADD_DEFINITIONS("-D_APPFW_FEATURE_DEFAULT_FAKE_IMAGE") + INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/config_splash.sh DESTINATION bin) +ENDIF(_APPFW_FEATURE_DEFAULT_FAKE_IMAGE) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/aul.pc DESTINATION lib/pkgconfig) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/legacy/preload_list.txt DESTINATION /usr/share/aul ) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/process_pool/preload_list_for_process_pool.txt DESTINATION /usr/share/aul ) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/feature/preexec_list.txt DESTINATION /usr/share/aul ) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/mida_db.sql DESTINATION /usr/share/aul ) INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/miregex DESTINATION /usr/share/aul ) -INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/service DESTINATION /usr/share/aul ) + +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/app_sock.h DESTINATION include/aul/launch) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/simple_util.h DESTINATION include/aul/launch) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/menu_db_util.h DESTINATION include/aul/launch) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/app_signal.h DESTINATION include/aul/launch) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/aul_util.h DESTINATION include/aul/launch) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/access_control.h DESTINATION include/aul/launch) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/perf.h DESTINATION include/aul/launch) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/feature/preexec.h DESTINATION include/aul/launchpad) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/legacy/preload.h DESTINATION include/aul/launchpad) +INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/launchpad_src/ DESTINATION include/aul/launchpad FILES_MATCHING PATTERN "*.h") +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libaul_mods.a DESTINATION lib) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/liblaunchpad_common.a DESTINATION lib) # test add_subdirectory(test) + diff --git a/TC/unit/pkgname.h b/TC/unit/pkgname.h index bd86d85..b5fcc27 100755 --- a/TC/unit/pkgname.h +++ b/TC/unit/pkgname.h @@ -20,7 +20,7 @@ */ #define MAX_LOCAL_BUFSZ 128 -#define EXIST_PKGNAME "org.tizen.calculator" +#define EXIST_PKGNAME "com.samsung.calculator" #define NO_EXIST_PKGNAME "empty.fault.application" #define EXIST_FILENAME "/usr/share/aul/preload_list.txt" diff --git a/agent/daemon-manager-launch-agent.c b/agent/daemon-manager-launch-agent.c index 2978766..bc27fa9 100644 --- a/agent/daemon-manager-launch-agent.c +++ b/agent/daemon-manager-launch-agent.c @@ -3,15 +3,9 @@ #include #include -#ifdef WEARABLE_PROFILE #define DAEMON_MANAGER_NAME "com.samsung.DaemonManager" #define DAEMON_MANAGER_PATH "/com/samsung/DaemonManager" #define DAEMON_MANAGER_INTERFACE "com.samsung.DaemonManager" -#else -#define DAEMON_MANAGER_NAME "org.tizen.DaemonManager" -#define DAEMON_MANAGER_PATH "/org/tizen/DaemonManager" -#define DAEMON_MANAGER_INTERFACE "org.tizen.DaemonManager" -#endif #define METHOD_RELEASED "Start" diff --git a/am_daemon/amd_appinfo.c b/am_daemon/amd_appinfo.c index 9212227..842fbb6 100755 --- a/am_daemon/amd_appinfo.c +++ b/am_daemon/amd_appinfo.c @@ -36,9 +36,28 @@ enum _appinfo_idx { _AI_INDICATORDISP, _AI_EFFECTIMAGEPORT, _AI_EFFECTIMAGELAND, +#ifdef _APPFW_FEATURE_CHANGEABLE_COLOR + _AI_EFFECTTYPE, +#endif _AI_STATUS, +#ifdef _APPFW_FEATURE_PROCESS_POOL _AI_POOL, +#endif _AI_COMPTYPE, +#ifdef _APPFW_FEATURE_MULTI_INSTANCE + _AI_MULTI_INSTANCE, + _AI_MULTI_INSTANCE_MAINID, + _AI_TOGGLE_ORDER, +#endif +#ifdef _APPFW_FEATURE_MULTI_WINDOW + _AI_MULTI_WINDOW, +#endif +#ifdef _APPFW_FEATURE_TTS_MODE + _AI_TTS, +#endif +#ifdef _APPFW_FEATURE_ULTRA_POWER_SAVING_MODE + _AI_UPS, +#endif _AI_MAX, }; #define _AI_START _AI_NAME /* start index */ @@ -64,9 +83,28 @@ static struct appinfo_t _appinfos[] = { [_AI_INDICATORDISP] = { "indicatordisplay", AIT_INDICATOR_DISP, }, [_AI_EFFECTIMAGEPORT] = { "portaitimg", AIT_EFFECTIMAGEPORT, }, [_AI_EFFECTIMAGELAND] = { "landscapeimg", AIT_EFFECTIMAGELAND, }, +#ifdef _APPFW_FEATURE_CHANGEABLE_COLOR + [_AI_EFFECTTYPE] = { "EffectType", AIT_EFFECTTYPE, }, +#endif [_AI_STATUS] = { "status", AIT_STATUS, }, +#ifdef _APPFW_FEATURE_PROCESS_POOL [_AI_POOL] = { "ProcessPool", AIT_POOL, }, +#endif [_AI_COMPTYPE] = { "ComponentType", AIT_COMPTYPE, }, +#ifdef _APPFW_FEATURE_MULTI_INSTANCE + [_AI_MULTI_INSTANCE] = { "multi-instance", AIT_MULTI_INSTANCE, }, + [_AI_MULTI_INSTANCE_MAINID] = { "multi-instance-mainid", AIT_MULTI_INSTANCE_MAINID, }, + [_AI_TOGGLE_ORDER] = { "toggleOrder", AIT_TOGGLE_ORDER, }, +#endif +#ifdef _APPFW_FEATURE_MULTI_WINDOW + [_AI_MULTI_WINDOW] = { "multi-window", AIT_MULTI_WINDOW, }, +#endif +#ifdef _APPFW_FEATURE_TTS_MODE + [_AI_TTS] = { "TTS", AIT_TTS, }, +#endif +#ifdef _APPFW_FEATURE_ULTRA_POWER_SAVING_MODE + [_AI_UPS] = { "UPS", AIT_UPS, }, +#endif }; struct appinfo { @@ -75,7 +113,7 @@ struct appinfo { struct pkginfo { char *pkgid; - char *op; + char *op; }; int gles = 1; @@ -90,8 +128,10 @@ static void _free_appinfo(gpointer data) if (!c) return; - for (i = 0; i < sizeof(c->val)/sizeof(c->val[0]); i++) - free(c->val[i]); + for (i = 0; i < sizeof(c->val)/sizeof(c->val[0]); i++) { + if(c->val[i] != NULL) + free(c->val[i]); + } free(c); } @@ -113,11 +153,21 @@ static int __app_info_insert_handler (const pkgmgrinfo_appinfo_h handle, void *d char *exec; char *portraitimg; char *landscapeimg; +#ifdef _APPFW_FEATURE_CHANGEABLE_COLOR + char *effectimg_type; +#endif char *type; char *appid; char *pkgid; char *component_type; + char *multi_mainid; bool multiple; +#ifdef _APPFW_FEATURE_MULTI_INSTANCE + bool multi_instance; +#endif +#ifdef _APPFW_FEATURE_MULTI_WINDOW + bool multi_window; +#endif bool onboot; bool restart; pkgmgrinfo_app_hwacceleration hwacc; @@ -127,7 +177,12 @@ static int __app_info_insert_handler (const pkgmgrinfo_appinfo_h handle, void *d int ret = -1; bool taskmanage; bool preload; +#ifdef _APPFW_FEATURE_PROCESS_POOL bool process_pool = 0; +#endif + int support_mode = 0; + + _D("__app_info_insert_handler"); if (!handle) { _E("null app handle"); @@ -159,7 +214,12 @@ static int __app_info_insert_handler (const pkgmgrinfo_appinfo_h handle, void *d c->val[_AI_NAME] = strdup(appid); //TODO : - pkgmgrinfo_appinfo_get_component(handle, &component); + ret = pkgmgrinfo_appinfo_get_component(handle, &component); + if (ret < 0) { + _E("fail to get component"); + _free_appinfo(c); + return -1; + } if(component == PMINFO_UI_APP) { c->val[_AI_COMP] = strdup("ui"); //TODO : @@ -223,13 +283,19 @@ static int __app_info_insert_handler (const pkgmgrinfo_appinfo_h handle, void *d else c->val[_AI_EFFECTIMAGELAND] = NULL; } +#ifdef _APPFW_FEATURE_CHANGEABLE_COLOR + r = pkgmgrinfo_appinfo_get_effectimage_type(handle, &effectimg_type); + c->val[_AI_EFFECTTYPE] = strdup(effectimg_type); +#endif + +#ifdef _APPFW_FEATURE_PROCESS_POOL r = pkgmgrinfo_appinfo_is_process_pool(handle, &process_pool); if (process_pool == false) { c->val[_AI_POOL] = strdup("false"); } else { c->val[_AI_POOL] = strdup("true"); } - +#endif r = pkgmgrinfo_appinfo_get_component_type(handle, &component_type); c->val[_AI_COMPTYPE] = strdup(component_type); @@ -241,7 +307,28 @@ static int __app_info_insert_handler (const pkgmgrinfo_appinfo_h handle, void *d r = pkgmgrinfo_appinfo_is_autorestart(handle, &restart); if(restart == true) c->val[_AI_RESTART] = strdup("true"); - else c->val[_AI_RESTART] = strdup("false"); + else c->val[_AI_RESTART] = strdup("false"); + +#ifdef _APPFW_FEATURE_MULTI_INSTANCE + r = pkgmgrinfo_appinfo_is_multi_instance(handle, &multi_instance); + if(multi_instance == true) + c->val[_AI_MULTI_INSTANCE] = strdup("true"); + else + c->val[_AI_MULTI_INSTANCE] = strdup("false"); + + r = pkgmgrinfo_appinfo_get_multi_instance_mainid(handle, &multi_mainid); + c->val[_AI_MULTI_INSTANCE_MAINID] = strdup(multi_mainid); + + // Toggle order + c->val[_AI_TOGGLE_ORDER] = strdup("0"); +#endif +#ifdef _APPFW_FEATURE_MULTI_WINDOW + r = pkgmgrinfo_appinfo_is_multi_window(handle, &multi_window); + if((r == PMINFO_R_OK) && (multi_window == true)) + c->val[_AI_MULTI_WINDOW] = strdup("true"); + else + c->val[_AI_MULTI_WINDOW] = strdup("false"); +#endif } else { c->val[_AI_COMP] = strdup("svc"); @@ -277,12 +364,28 @@ static int __app_info_insert_handler (const pkgmgrinfo_appinfo_h handle, void *d c->val[_AI_PERM] = strdup("normal"); } + pkgmgrinfo_appinfo_get_support_mode(handle, &support_mode); +#ifdef _APPFW_FEATURE_TTS_MODE + if(support_mode & PMINFO_MODE_PROP_SCREEN_READER) { + c->val[_AI_TTS] = strdup("true"); + } else { + c->val[_AI_TTS] = strdup("false"); + } +#endif +#ifdef _APPFW_FEATURE_ULTRA_POWER_SAVING_MODE + if(support_mode & PMINFO_MODE_PROP_ULTRA_POWER_SAVING) { + c->val[_AI_UPS] = strdup("true"); + } else { + c->val[_AI_UPS] = strdup("false"); + } +#endif + r = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid); c->val[_AI_PKGID] = strdup(pkgid); c->val[_AI_STATUS] = strdup("installed"); - SECURE_LOGD("%s : %s : %s", c->val[_AI_FILE], c->val[_AI_COMP], c->val[_AI_TYPE]); + SECURE_LOGD("appinfo file:%s, comp:%s, type:%s", c->val[_AI_FILE], c->val[_AI_COMP], c->val[_AI_TYPE]); g_hash_table_insert(cf->tbl, c->val[_AI_FILE], c); @@ -303,11 +406,11 @@ static int __app_info_delete_handler (const pkgmgrinfo_appinfo_h handle, void *d static int _read_pkg_info(struct appinfomgr *cf) { - int r; + int ret = pkgmgrinfo_appinfo_get_install_list(__app_info_insert_handler, cf); - r = pkgmgrinfo_appinfo_get_install_list(__app_info_insert_handler, cf); + assert(ret == PMINFO_R_OK); - return r; + return ret; } static struct appinfomgr *_init() @@ -328,20 +431,30 @@ static struct appinfomgr *_init() return cf; } -static int __amd_pkgmgrinfo_update_start_handler(pkgmgrinfo_appinfo_h handle, void *user_data) +static gboolean __amd_pkgmgrinfo_start_handler (gpointer key, gpointer value, gpointer user_data) { - char *appid = NULL; - struct appinfomgr *cf = (struct appinfomgr *)user_data; - struct appinfo *c; + struct appinfo *c = value; + char *pkgid = (char *)user_data; - pkgmgrinfo_appinfo_get_appid(handle, &appid); - c = g_hash_table_lookup(cf->tbl, appid); - SECURE_LOGD("%s : %s", c->val[_AI_FILE], c->val[_AI_STATUS]); - free(c->val[_AI_STATUS]); - c->val[_AI_STATUS] = strdup("upgrading"); - SECURE_LOGD("upgrading... (%s)", appid); + if (c != NULL && strcmp(c->val[_AI_PKGID], pkgid) == 0) { + free(c->val[_AI_STATUS]); + c->val[_AI_STATUS] = strdup("blocking"); + SECURE_LOGD("pkgmgr working for this application(%s)", c->val[_AI_NAME]); + } + return TRUE; +} - return 0; +static gboolean __amd_pkgmgrinfo_fail_handler (gpointer key, gpointer value, gpointer user_data) +{ + struct appinfo *c = value; + char *pkgid = (char *)user_data; + + if (c != NULL && strcmp(c->val[_AI_PKGID], pkgid) == 0) { + free(c->val[_AI_STATUS]); + c->val[_AI_STATUS] = strdup("installed"); + SECURE_LOGD("pkgmgr fail(%s)", c->val[_AI_NAME]); + } + return TRUE; } static int __amd_pkgmgrinfo_install_end_handler(pkgmgrinfo_appinfo_h handle, void *user_data) @@ -379,7 +492,8 @@ static int __amd_pkgmgrinfo_update_end_handler(pkgmgrinfo_appinfo_h handle, void pkgmgrinfo_appinfo_get_appid(handle, &appid); c = g_hash_table_lookup(cf->tbl, appid); - if (strncmp(c->val[_AI_STATUS], "restart", 7) == 0) { + + if (c != NULL && strncmp(c->val[_AI_STATUS], "restart", 7) == 0) { __app_info_insert_handler(handle, user_data); __release_srv(appid); } else { @@ -403,7 +517,7 @@ static gboolean __amd_pkgmgrinfo_uninstall_end_handler (gpointer key, gpointer v { struct appinfo *c = value; char *pkgid = (char *)user_data; - + if (strcmp(c->val[_AI_PKGID], pkgid) == 0) { SECURE_LOGD("appid(%s), pkgid(%s)", c->val[_AI_NAME], pkgid); return TRUE; @@ -430,29 +544,12 @@ static int __amd_pkgmgrinfo_status_cb(int req_id, const char *pkg_type, p->op = strdup(val); g_hash_table_insert(pkg_tbl, p->pkgid, p); if (strncmp(val, "install", 7) == 0) { - + } - else if (strncmp(val, "update", 6) == 0) { - ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle); - if (ret != PMINFO_R_OK) - return -1; - ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_UI_APP, __amd_pkgmgrinfo_update_start_handler, user_data); - if (ret != PMINFO_R_OK) { - pkgmgrinfo_pkginfo_destroy_pkginfo(handle); - return -1; - } - pkgmgrinfo_pkginfo_destroy_pkginfo(handle); - } - else if (strncmp(val, "uninstall", 9) == 0) { - ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle); - if (ret != PMINFO_R_OK) - return -1; - ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_UI_APP, __amd_pkgmgrinfo_update_start_handler, user_data); - if (ret != PMINFO_R_OK) { - pkgmgrinfo_pkginfo_destroy_pkginfo(handle); - return -1; - } - pkgmgrinfo_pkginfo_destroy_pkginfo(handle); + else if ((strncmp(val, "update", 6) == 0) || (strncmp(val, "uninstall", 9) == 0)) { + g_hash_table_foreach(cf->tbl, __amd_pkgmgrinfo_start_handler, (gpointer)pkgid); + _D("__amd_pkgmgrinfo_start_handler"); + ret = 0; } } else if (strncmp(key,"end", 3) == 0) { @@ -490,7 +587,11 @@ static int __amd_pkgmgrinfo_status_cb(int req_id, const char *pkg_type, } } else if (strncmp(val, "fail", 4) == 0) { - + if ((op && strncmp(op, "update", 6) == 0) || (op && strncmp(op, "uninstall", 9) == 0) ) { + g_hash_table_foreach(cf->tbl, __amd_pkgmgrinfo_fail_handler, (gpointer)pkgid); + _D("__amd_pkgmgrinfo_fail_handler"); + ret = 0; + } } g_hash_table_remove(pkg_tbl, p->pkgid); free(p->pkgid); @@ -539,7 +640,7 @@ static void __amd_mmc_vconf_cb(keynode_t *key, void *data) { int status; struct appinfomgr *cf = (struct appinfomgr *)data; - int ret; + int ret = 0; status = vconf_keynode_get_int(key); if( status < 0 ) { @@ -547,9 +648,15 @@ static void __amd_mmc_vconf_cb(keynode_t *key, void *data) } if(status == VCONFKEY_SYSMAN_MMC_REMOVED || status == VCONFKEY_SYSMAN_MMC_INSERTED_NOT_MOUNTED) { - pkgmgrinfo_appinfo_get_unmounted_list(__unmounted_list_cb, data); + ret = pkgmgrinfo_appinfo_get_unmounted_list(__unmounted_list_cb, data); + if (ret != PMINFO_R_OK){ + _E("pkgmgrinfo_appinfo_get_unmounted_list failed: %d", ret); + } } else if(status == VCONFKEY_SYSMAN_MMC_MOUNTED){ - pkgmgrinfo_appinfo_get_mounted_list(__mounted_list_cb, data); + ret = pkgmgrinfo_appinfo_get_mounted_list(__mounted_list_cb, data); + if (ret != PMINFO_R_OK){ + _E("pkgmgrinfo_appinfo_get_mounted_list failed: %d", ret); + } } } @@ -580,8 +687,10 @@ int appinfo_init(struct appinfomgr **cf) fclose(fp); _cf = _init(); - if (!_cf) + if (!_cf) { + assert(_cf); return -1; + } r = _read_pkg_info(_cf); if (r != PMINFO_R_OK) { @@ -589,6 +698,10 @@ int appinfo_init(struct appinfomgr **cf) return -1; } + r = vconf_notify_key_changed(VCONFKEY_SYSMAN_MMC_STATUS, __amd_mmc_vconf_cb, _cf); + if (r < 0) + _E("Unable to register vconf notification callback for VCONFKEY_SYSMAN_MMC_STATUS\n"); + int event_type = PMINFO_CLIENT_STATUS_UPGRADE | PMINFO_CLIENT_STATUS_UNINSTALL | PMINFO_CLIENT_STATUS_INSTALL; pkgmgrinfo_client *pc = NULL; pc = pkgmgrinfo_client_new(PMINFO_LISTENING); @@ -634,7 +747,6 @@ const struct appinfo *appinfo_find(struct appinfomgr *cf, const char *filename) { if (!cf || !filename || !*filename) { errno = EINVAL; - _E("appinfo find: %s", strerror(errno)); return NULL; } @@ -647,7 +759,7 @@ const char *appinfo_get_value(const struct appinfo *c, enum appinfo_type type) if (!c) { errno = EINVAL; - _E("appinfo get value: %s", strerror(errno)); + _E("appinfo get value: %s, %d", strerror(errno), type); return NULL; } diff --git a/am_daemon/amd_appinfo.h b/am_daemon/amd_appinfo.h index 19d6ece..77bf6e6 100755 --- a/am_daemon/amd_appinfo.h +++ b/am_daemon/amd_appinfo.h @@ -20,9 +20,29 @@ enum appinfo_type { AIT_INDICATOR_DISP, AIT_EFFECTIMAGEPORT, AIT_EFFECTIMAGELAND, +#ifdef _APPFW_FEATURE_CHANGEABLE_COLOR + AIT_EFFECTTYPE, +#endif AIT_STATUS, +#ifdef _APPFW_FEATURE_PROCESS_POOL AIT_POOL, +#endif AIT_COMPTYPE, +#ifdef _APPFW_FEATURE_MULTI_INSTANCE + AIT_MULTI_INSTANCE, + AIT_MULTI_INSTANCE_MAINID, + AIT_TOGGLE_ORDER, +#endif +#ifdef _APPFW_FEATURE_MULTI_WINDOW + AIT_MULTI_WINDOW, +#endif +#ifdef _APPFW_FEATURE_TTS_MODE + AIT_TTS, +#endif +#ifdef _APPFW_FEATURE_ULTRA_POWER_SAVING_MODE + AIT_UPS, +#endif + AIT_MAX }; int appinfo_init(struct appinfomgr **cf); diff --git a/am_daemon/amd_key.c b/am_daemon/amd_key.c index 65fdee4..a64fe45 100755 --- a/am_daemon/amd_key.c +++ b/am_daemon/amd_key.c @@ -28,12 +28,13 @@ #include #include "amd_config.h" +#include "amd_key.h" #include "simple_util.h" #include "app_sock.h" #include "launch.h" static struct { - Evas_Object *win; + Ecore_X_Window win; Ecore_Event_Handler *key_up; Ecore_Event_Handler *key_down; } key_info = { @@ -70,7 +71,7 @@ static Eina_Bool __key_release_cb(void *data, int type, void *event) bundle_add(kb, AUL_K_MULTI_KEY, ev->keyname); bundle_add(kb, AUL_K_MULTI_KEY_EVENT, AUL_V_KEY_RELEASED); - ret = app_send_cmd(*pid_data, APP_KEY_EVENT, kb); + ret = app_send_cmd_with_noreply(*pid_data, APP_KEY_EVENT, kb); if (ret < 0) _E("app_send_cmd failed with error %d\n", ret); @@ -104,7 +105,7 @@ static Eina_Bool __key_press_cb(void *data, int type, void *event) bundle_add(kb, AUL_K_MULTI_KEY, ev->keyname); bundle_add(kb, AUL_K_MULTI_KEY_EVENT, AUL_V_KEY_PRESSED); - ret = app_send_cmd(*pid_data, APP_KEY_EVENT, kb); + ret = app_send_cmd_with_noreply(*pid_data, APP_KEY_EVENT, kb); if (ret < 0) _E("app_send_cmd failed with error %d\n", ret); @@ -164,17 +165,26 @@ int _unregister_key_event(int pid) return 0; } +Ecore_X_Window _input_window_get() +{ + return key_info.win; +} + int _key_init() { - key_info.win = ecore_x_window_input_new(0, 0, 0, 1, 1); + key_info.win = ecore_x_window_input_new(ecore_x_window_root_first_get(), 0, 0, 1, 1); if (!key_info.win) { _D("Failed to create hidden window"); } + _D("_key_init, win : %x", key_info.win); + ecore_x_icccm_title_set(key_info.win, "acdaemon,key,receiver"); ecore_x_netwm_name_set(key_info.win, "acdaemon,key,receiver"); ecore_x_netwm_pid_set(key_info.win, getpid()); + ecore_x_window_show(key_info.win); + utilx_grab_key(ecore_x_display_get(), key_info.win, KEY_PLAYCD, SHARED_GRAB); utilx_grab_key(ecore_x_display_get(), key_info.win, KEY_STOPCD, SHARED_GRAB); utilx_grab_key(ecore_x_display_get(), key_info.win, KEY_PAUSECD, SHARED_GRAB); diff --git a/am_daemon/amd_key.h b/am_daemon/amd_key.h index bcf8d2e..bee999e 100755 --- a/am_daemon/amd_key.h +++ b/am_daemon/amd_key.h @@ -22,9 +22,12 @@ #ifndef __AUL_AMD_KEY_H_ #define __AUL_AMD_KEY_H_ +#include + int _key_init(void); int _register_key_event(int pid); int _unregister_key_event(int pid); +Ecore_X_Window _input_window_get(void); #endif diff --git a/am_daemon/amd_launch.c b/am_daemon/amd_launch.c index 2e3802d..5489773 100755 --- a/am_daemon/amd_launch.c +++ b/am_daemon/amd_launch.c @@ -30,6 +30,9 @@ #include #include #include +#ifdef _APPFW_FEATURE_APP_CHECKER +#include +#endif #include #include #include @@ -38,18 +41,17 @@ #include #include #include +#include #include #include -#ifdef WEARABLE_PROFILE #include -#endif #include -#include #include "amd_config.h" #include "amd_launch.h" #include "amd_appinfo.h" #include "amd_status.h" +#include "amd_key.h" #include "app_sock.h" #include "simple_util.h" #include "amd_cgutil.h" @@ -60,9 +62,6 @@ #include "access_control.h" -#ifdef WEARABLE_PROFILE -#include "dd-display.h" -#endif #define TERM_WAIT_SEC 3 #define INIT_PID 1 @@ -85,10 +84,18 @@ #define HIDE_INDICATOR 0 #define SHOW_INDICATOR 1 +#ifdef _APPFW_FEATURE_CPU_BOOST +#define APP_BOOSTING_PERIOD 1500 //msec +#endif + +static char *amd_cmdline; + struct appinfomgr *_laf; struct cginfo *_lcg; DBusConnection *conn; +guint grab_timer_id; + #if 0 /*Unused data structure. Will be removed*/ @@ -113,9 +120,11 @@ struct ktimer { static const char *atom_name = "_E_COMP_FAKE_LAUNCH_IMAGE"; // Atomic ID string static Ecore_X_Atom ATOM_IMAGE_EFFECT; //Atomic ID static void __amd_effect_image_file_set(char *image_file); -static void __amd_send_message_to_e17(int screenmode, const char * indicator); +static void __amd_send_message_to_e17(int screenmode, const char * indicator, int effect_type, int theme); static int __amd_change_min_cpulock_count(int value); static Eina_Bool __amd_restore_min_cpulock_count_cb(void *data); +static void __set_reply_handler(int fd, int pid, int clifd, int cmd); +static void __real_send(int clifd, int ret); static void _set_sdk_env(const char* appid, char* str) { char buf[MAX_LOCAL_BUFSZ]; @@ -198,7 +207,7 @@ static void _prepare_exec(const char *appid, bundle *kb) /* SET PRIVILEGES*/ _D("appid : %s / pkg_type : %s / app_path : %s ", appid, pkg_type, app_path); - if ((ret = __set_access(appid, pkg_type, app_path)) < 0) { + if (strncmp(pkg_type, "wgt", 3) !=0 && (ret = __set_access(appid, pkg_type, app_path)) < 0) { _D("fail to set privileges - check your package's credential : %d\n", ret); return; } @@ -222,9 +231,6 @@ static void _prepare_exec(const char *appid, bundle *kb) /* SET ENVIROMENT*/ _set_env(appid, kb, hwacc); - - /* TODO: do security job */ - /* TODO: setuid */ } static int _add_cgroup(struct cginfo *cg, const char *group, int pid) @@ -296,6 +302,121 @@ static void _do_exec(struct cginfo *cg, const char *cmd, const char *group, bund g_strfreev(argv); } +static inline int __send_app_launch_signal(int launch_pid) +{ + DBusMessage *message; + + if (conn == NULL) + return -1; + + message = dbus_message_new_signal(AUL_DBUS_PATH, + AUL_DBUS_SIGNAL_INTERFACE, + AUL_DBUS_APPLAUNCH_SIGNAL); + + if (dbus_message_append_args(message, + DBUS_TYPE_UINT32, &launch_pid, + DBUS_TYPE_INVALID) == FALSE) { + _E("Failed to load data error"); + return -1; + } + + if (dbus_connection_send(conn, message, NULL) == FALSE) { + _E("dbus send error"); + return -1; + } + + dbus_connection_flush(conn); + dbus_message_unref(message); + + _D("send launch signal done\n"); + + return 0; +} + +static int __send_watchdog_signal(int pid, int signal_num) +{ + DBusMessage *message; + + if (conn == NULL) + return -1; + + if (!_get_platform_ready()) { + _E("[Info]_get_platform_ready return false"); + return -1; + } + + if(_status_get_cooldown_status() == COOLDOWN_LIMIT) { + _E("[Info]cooldown status : LimitAction"); + return -1; + } + + message = dbus_message_new_signal(RESOURCED_PROC_OBJECT, + RESOURCED_PROC_INTERFACE, + RESOURCED_PROC_WATCHDOG_SIGNAL); + + if (dbus_message_append_args(message, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INT32, &signal_num, + DBUS_TYPE_INVALID) == FALSE) { + _E("Failed to load data error"); + return -1; + } + + if (dbus_connection_send(conn, message, NULL) == FALSE) { + _E("dbus send error"); + return -1; + } + + dbus_connection_flush(conn); + dbus_message_unref(message); + + _D("send launch signal done\n"); + + return 0; +} + +static int __check_cmdline(int ret) +{ + char *cmdline; + int wait_count; + int cmdline_changed = 0; + int cmdline_exist = 0; + int r; + + if (ret <= 1) + return -1; + + /* check normally was launched?*/ + wait_count = 1; + do { + cmdline = __proc_get_cmdline_bypid(ret); + if (cmdline == NULL) { + _E("error founded when being launched with %d", ret); + + } else if (strcmp(cmdline, amd_cmdline)) { + free(cmdline); + cmdline_changed = 1; + break; + } else { + cmdline_exist = 1; + free(cmdline); + } + + _D("-- now wait to change cmdline --"); + usleep(50 * 1000); /* 50ms sleep*/ + wait_count++; + } while (wait_count <= 20); /* max 50*20ms will be sleep*/ + + if ((!cmdline_exist) && (!cmdline_changed)) { + return -1; + } + + if (!cmdline_changed) + _E("process launched, but cmdline not changed"); + + return ret; +} + int service_start(struct cginfo *cg, const char *group, const char *cmd, bundle *kb) { int r; @@ -311,6 +432,14 @@ int service_start(struct cginfo *cg, const char *group, const char *cmd, bundle switch (p) { case 0: /* child process */ _D("start service"); +#ifdef _APPFW_FEATURE_PRIORITY_CHANGE + r = setpriority(PRIO_PROCESS, 0, 0); + if (r == -1) + { + SECURE_LOGE("Setting process (%d) priority to 0 failed, errno: %d (%s)", + getpid(), errno, strerror(errno)); + } +#endif _do_exec(cg, cmd, group, kb); /* exec error */ @@ -322,7 +451,9 @@ int service_start(struct cginfo *cg, const char *group, const char *cmd, bundle break; default: /* parent process */ _D("child process: %d", p); - r = p; + r = __check_cmdline(p); + if(r > 0) + __send_app_launch_signal(r); break; } @@ -334,6 +465,7 @@ int _start_srv(const struct appinfo *ai, bundle *kb) int r; const char *group; const char *cmd; + const char *pkgid; group = appinfo_get_filename(ai); @@ -349,6 +481,10 @@ int _start_srv(const struct appinfo *ai, bundle *kb) return -1; } + pkgid = appinfo_get_value(ai, AIT_PKGID); + proc_cgroup_launch(PROC_CGROUP_SET_SERVICE_REQUEST, r, group, pkgid); + _status_add_app_info_list(group, cmd, NULL, r, -1); + return 0; } @@ -461,6 +597,8 @@ int service_stop(struct cginfo *cg, const char *group) return -1; } + _D("service_stop, group %s", group); + return cgutil_group_foreach_pid(cg, CTRL_MGR, FILENAME(group), _kill_pid_cb, cg); } @@ -483,6 +621,8 @@ void service_release(const char *group) if (k->group && !strcmp(k->group, group)) d = l; + else + d = NULL; } _del_list(d); @@ -501,7 +641,7 @@ int _send_to_sigkill(int pid) return 0; } -int _resume_app(int pid) +int _resume_app(int pid, int clifd) { int dummy; int ret; @@ -516,21 +656,32 @@ int _resume_app(int pid) _send_to_sigkill(pid); ret = -1; } + __real_send(clifd, ret); } _D("resume done\n"); + + if (ret > 0) + __set_reply_handler(ret, pid, clifd, APP_RESUME_BY_PID); + return ret; } -int _fake_launch_app(int cmd, int pid, bundle * kb) +int _fake_launch_app(int cmd, int pid, bundle * kb, int clifd) { int datalen; int ret; bundle_raw *kb_data; bundle_encode(kb, &kb_data, &datalen); - if ((ret = __app_send_raw_with_delay_reply(pid, cmd, kb_data, datalen)) < 0) + if ((ret = __app_send_raw_with_delay_reply(pid, cmd, kb_data, datalen)) < 0) { _E("error request fake launch - error code = %d", ret); + __real_send(clifd, ret); + } free(kb_data); + + if (ret > 0) + __set_reply_handler(ret, pid, clifd, cmd); + return ret; } @@ -650,13 +801,25 @@ static gboolean __recv_timeout_handler(gpointer data) close(fd); - if( r_info->cmd == APP_TERM_BY_PID ) { + switch (r_info->cmd) { + case APP_OPEN: + case APP_RESUME: + case APP_START: + case APP_START_RES: + case APP_START_ASYNC: +#ifdef _APPFW_FEATURE_MULTI_INSTANCE + case APP_START_MULTI_INSTANCE: +#endif + __send_watchdog_signal(r_info->pid, SIGKILL); + break; + case APP_TERM_BY_PID: if (_send_to_sigkill(r_info->pid) < 0) { _E("fail to killing - %d\n", r_info->pid); __real_send(r_info->clifd, -1); return -1; } __real_send(r_info->clifd, 0); + break; } g_source_remove_poll(r_info->src, r_info->gpollfd); @@ -667,15 +830,41 @@ static gboolean __recv_timeout_handler(gpointer data) return FALSE; } -_term_app(int pid, int clifd) +static void __set_reply_handler(int fd, int pid, int clifd, int cmd) { - int dummy; - int ret; - int r; GPollFD *gpollfd; GSource *src; struct reply_info *r_info; + src = g_source_new(&funcs, sizeof(GSource)); + + gpollfd = (GPollFD *) g_malloc(sizeof(GPollFD)); + gpollfd->events = POLLIN; + gpollfd->fd = fd; + + r_info = malloc(sizeof(*r_info)); + r_info->clifd = clifd; + r_info->pid = pid; + r_info->src = src; + r_info->gpollfd = gpollfd; + r_info->cmd = cmd; + + + r_info->timer_id = g_timeout_add(5000, __recv_timeout_handler, (gpointer) r_info); + g_source_add_poll(src, gpollfd); + g_source_set_callback(src, (GSourceFunc) __reply_handler, + (gpointer) r_info, NULL); + g_source_set_priority(src, G_PRIORITY_DEFAULT); + g_source_attach(src, NULL); + + _D("listen fd : %d, send fd : %d", fd, clifd); +} + +int _term_app(int pid, int clifd) +{ + int dummy; + int ret; + if ( (ret = __app_send_raw_with_delay_reply (pid, APP_TERM_BY_PID, (unsigned char *)&dummy, sizeof(int))) < 0) { _D("terminate packet send error - use SIGKILL"); @@ -687,60 +876,128 @@ _term_app(int pid, int clifd) __real_send(clifd, 0); } _D("term done\n"); - if(ret > 0) { - src = g_source_new(&funcs, sizeof(GSource)); + if (ret > 0) + __set_reply_handler(ret, pid, clifd, APP_TERM_BY_PID); + + return 0; +} - gpollfd = (GPollFD *) g_malloc(sizeof(GPollFD)); - gpollfd->events = POLLIN; - gpollfd->fd = ret; +#include +#include +static int __launchpad_update_task_managed_field(const char* app_id, int task_managed) +{ + sqlite3 *db = NULL; + char *sqlite3_error_msg = NULL; - r_info = malloc(sizeof(*r_info)); - r_info->clifd = clifd; - r_info->pid = pid; - r_info->src = src; - r_info->gpollfd = gpollfd; - r_info->cmd = APP_TERM_BY_PID; + if (sqlite3_open("/opt/dbspace/.pkgmgr_parser.db", &db) != SQLITE_OK) { + _E("sqlite3_open() failed! -> %s\n", sqlite3_errmsg(db)); + return -1; + } - _D("listen fd : %d, send fd : %d", ret, clifd); + if (sqlite3_exec(db, "PRAGMA journal_mode = PERSIST", NULL, NULL, &sqlite3_error_msg) != SQLITE_OK) { + _E("sqlite3_exec(\"PRAGMA journal_mode = PERSIST\") failed! -> %s", sqlite3_error_msg); + sqlite3_free(sqlite3_error_msg); + sqlite3_close(db); + return -1; + } - r_info->timer_id = g_timeout_add(5000, __recv_timeout_handler, (gpointer) r_info); - g_source_add_poll(src, gpollfd); - g_source_set_callback(src, (GSourceFunc) __reply_handler, - (gpointer) r_info, NULL); - g_source_set_priority(src, G_PRIORITY_DEFAULT); - r = g_source_attach(src, NULL); + if (sqlite3_exec(db, "BEGIN EXCLUSIVE", NULL, NULL, &sqlite3_error_msg) != SQLITE_OK) { + _E("sqlite3_exec(\"BEGIN EXCLUSIVE\") failed! -> %s", sqlite3_error_msg); + sqlite3_free(sqlite3_error_msg); + sqlite3_close(db); + return -1; } - return 0; + + char query[1024] = {0, }; + snprintf(query, 1024,"update package_app_info set app_taskmanage='%s' where app_id='%s'", + task_managed ? "true" : "false", app_id); + + if (sqlite3_exec(db, query, NULL, NULL, &sqlite3_error_msg) != SQLITE_OK) { + _E("sqlite3_exec(\"%s\") failed! -> %s", query, sqlite3_error_msg); + sqlite3_free(sqlite3_error_msg); + return -1; + } + + if (sqlite3_exec(db, "COMMIT", NULL, NULL, NULL) != SQLITE_OK) { + _E("sqlite3_exec(\"COMMIT\") failed!"); + if (sqlite3_exec(db, "ROLLBACK", NULL, NULL, NULL) != SQLITE_OK) { + _E("sqlite3_exec(\"ROLLBACK\") failed!"); + } + sqlite3_close(db); + return -1; + } + + sqlite3_close(db); + +return 0; +} + +static void __pre_launching_processing(const char* app_id) +{ + const char* const PRE_LAUNCHING_LIST_DIR = "/opt/usr/etc/wrt_launchpad_daemon/pre_launching_list"; + + struct stat file_status; + if (stat(PRE_LAUNCHING_LIST_DIR, &file_status) == 0) { + if (S_ISDIR(file_status.st_mode)) { + int ret; + DIR *dir = NULL; + struct dirent entry, *result; + + dir = opendir(PRE_LAUNCHING_LIST_DIR); + + if (dir) { + for (ret = readdir_r(dir, &entry, &result); + result != NULL && ret == 0; + ret = readdir_r(dir, &entry, &result)) { + if (strncmp(entry.d_name, ".", 2) == 0 || + strncmp(entry.d_name, "..", 3) == 0) { + continue; + } + + if (strcmp(entry.d_name, app_id) == 0) + { + __launchpad_update_task_managed_field(app_id, 1); + } + } + + closedir(dir); + } + else { + _E("opendir(\"%s\") failed!", PRE_LAUNCHING_LIST_DIR); + } + } + } } static int __nofork_processing(int cmd, int pid, bundle * kb, int clifd) { int ret = -1; int r; - GPollFD *gpollfd; - GSource *src; - struct reply_info *r_info; const char *operation; operation = bundle_get_val(kb, "__APP_SVC_OP_TYPE__"); - if ( cmd == APP_OPEN || - (operation != NULL && strncmp(operation, "http://tizen.org/appcontrol/operation/main", 512) == 0)){ +#ifdef _APPFW_FEATURE_CPU_BOOST + //TODO: CPU boosting for relaunching will be removed. + //Home screen requests CPU boosting on launching or relaunching during 200 msec. + if (cmd == APP_OPEN || + (operation != NULL && strncmp(operation, "http://tizen.org/appcontrol/operation/main", 512) == 0)) { char *arr[2]; char val[32]; - snprintf(val, sizeof(val), "%d", 800); + snprintf(val, sizeof(val), "%d", APP_BOOSTING_PERIOD); arr[0] = val; arr[1] = NULL; ret = invoke_dbus_method_sync(SYSTEM_BUS_NAME, SYSTEM_OBJECT_PATH, - SYSTEM_INTERFACE_NAME, SYSTEM_METHOD_NAME, "i", arr); + SYSTEM_INTERFACE_NAME, SYSTEM_METHOD_NAME, "i", arr); _D("%s-%s : %d", SYSTEM_INTERFACE_NAME, SYSTEM_METHOD_NAME, ret); } - +#endif + _D("__nofork_processing, cmd: %d, pid: %d", cmd, pid); switch (cmd) { case APP_OPEN: case APP_RESUME: _D("resume app's pid : %d\n", pid); - if ((ret = _resume_app(pid)) < 0) + if ((ret = _resume_app(pid, clifd)) < 0) _E("__resume_app failed. error code = %d", ret); _D("resume app done"); break; @@ -748,37 +1005,16 @@ static int __nofork_processing(int cmd, int pid, bundle * kb, int clifd) case APP_START: case APP_START_RES: case APP_START_ASYNC: +#ifdef _APPFW_FEATURE_MULTI_INSTANCE + case APP_START_MULTI_INSTANCE: +#endif _D("fake launch pid : %d\n", pid); - if ((ret = _fake_launch_app(cmd, pid, kb)) < 0) + if ((ret = _fake_launch_app(cmd, pid, kb, clifd)) < 0) _E("fake_launch failed. error code = %d", ret); _D("fake launch done"); break; } - if(ret > 0) { - src = g_source_new(&funcs, sizeof(GSource)); - - gpollfd = (GPollFD *) g_malloc(sizeof(GPollFD)); - gpollfd->events = POLLIN; - gpollfd->fd = ret; - - r_info = malloc(sizeof(*r_info)); - r_info->clifd = clifd; - r_info->pid = pid; - r_info->src = src; - r_info->gpollfd = gpollfd; - r_info->cmd = cmd; - - _D("listen fd : %d, send fd : %d", ret, clifd); - - r_info->timer_id = g_timeout_add(5200, __recv_timeout_handler, (gpointer) r_info); - g_source_add_poll(src, gpollfd); - g_source_set_callback(src, (GSourceFunc) __reply_handler, - (gpointer) r_info, NULL); - g_source_set_priority(src, G_PRIORITY_DEFAULT); - r = g_source_attach(src, NULL); - } - return ret; } @@ -835,33 +1071,36 @@ static void __amd_effect_image_file_set(char *image_file) { Ecore_X_Window root_win; root_win = ecore_x_window_root_first_get(); + SECURE_LOGD("path : %s", image_file); ecore_x_window_prop_string_set(root_win, ATOM_IMAGE_EFFECT,image_file); } -static void __amd_send_message_to_e17(int screenmode, const char * indicator) +static void __amd_send_message_to_e17(int screenmode, const char * indicator, int effect_type, int theme) { Ecore_X_Window root_win; int ret; root_win = ecore_x_window_root_first_get(); _D("root win : %x",root_win); - int screen_orientation[5]={0,270,0,180,90}; + int screen_orientation[5]={0,0,270,180,90}; if (screenmode > 4 || screenmode < 0) screenmode=0; if (strncmp(indicator, "true", 4) == 0){ - _D("[LAUNCHING EFFECT]: screen mode is %d, indicator show\n", screen_orientation[screenmode] ); + _D("[LAUNCHING EFFECT]: screen mode(%d), effect type(%d), theme(%d), indicator show", + screen_orientation[screenmode], effect_type, theme); ret = ecore_x_client_message32_send (root_win, ATOM_IMAGE_EFFECT, - ECORE_X_EVENT_MASK_WINDOW_PROPERTY, 1, + ECORE_X_EVENT_MASK_WINDOW_PROPERTY, effect_type, screen_orientation[screenmode], - SHOW_INDICATOR, 0, 0); + SHOW_INDICATOR, theme, 0); }else{ - _D("[LAUNCHING EFFECT]: screen mode is %d, indicator hide\n", screen_orientation[screenmode] ); + _D("[LAUNCHING EFFECT]: screen mode(%d), effect type(%d), theme(%d), indicator show", + screen_orientation[screenmode], effect_type, theme); ret = ecore_x_client_message32_send (root_win, ATOM_IMAGE_EFFECT, - ECORE_X_EVENT_MASK_WINDOW_PROPERTY, 1, + ECORE_X_EVENT_MASK_WINDOW_PROPERTY, effect_type, screen_orientation[screenmode], - HIDE_INDICATOR, 0, 0); + HIDE_INDICATOR, theme, 0); } ecore_x_flush(); _D("ecore_x_client_message32_send : %d",ret); @@ -920,12 +1159,14 @@ int invoke_dbus_method_sync(const char *dest, const char *path, return -EBADMSG; } - dbus_message_iter_init_append(msg, &iter); - r = append_variant(&iter, sig, param); - if (r < 0) { - _E("append_variant error(%d)", r); - dbus_message_unref(msg); - return -EBADMSG; + if( param ) { + dbus_message_iter_init_append(msg, &iter); + r = append_variant(&iter, sig, param); + if (r < 0) { + _E("append_variant error(%d)", r); + dbus_message_unref(msg); + return -EBADMSG; + } } dbus_error_init(&err); @@ -949,9 +1190,225 @@ int invoke_dbus_method_sync(const char *dest, const char *path, return ret; } +static gboolean __grab_timeout_handler(gpointer data) +{ + int pid = (int) data; + + if(_input_window_get() != 0) + ecore_x_pointer_ungrab(); + _D("pid(%d) ecore_x_pointer_ungrab", pid); + + return FALSE; +} + +static bool __check_ug_client_process_pool(const char *app_path) +{ + char sympath[MAX_PACKAGE_APP_PATH_SIZE] = {0,}; + int ret; + bool func_ret = true; + + if(!app_path) { + _E("invalid input param"); + func_ret = false; + goto func_out; + } + + if(strncmp(app_path, "/usr/ug/bin/", strlen("/usr/ug/bin")) != 0) { + func_ret = false; + goto func_out; + } + + if(readlink(app_path, sympath, MAX_PACKAGE_APP_PATH_SIZE-1) == -1) { + _E("read app path link error(%d)", errno); + func_ret = false; + goto func_out; + } + + if(strncmp(sympath, "/usr/bin/ug-client", strlen("/usr/bin/ug-client")) != 0) { + func_ret = false; + } + +func_out : + _D("ug process pool check result : %d", func_ret); + return func_ret; +} + +#ifdef _APPFW_FEATURE_MULTI_WINDOW +static void __add_multi_window_info(bundle* kb, const struct appinfo *ai, const char* callee_appid, const char* caller_appid) +{ + const struct appinfo *caller_ai; + const struct appinfo *callee_ai; + unsigned int layout = -1; // 0 : top of split window / 1 : bottom of split window + const char *caller = NULL; + Ecore_X_Window caller_win_id = 0; + const char *bundle_layout = NULL; + int is_open_via_multi = 0; + int startup_type = 2; //2 means callee will be displayed as split view + const char *caller_ai_multi_window = NULL; + const char *callee_ai_multi_window = NULL; + int ret = 0; + int multiwindow_enabled = 0; + + /* check multi window is enabled or not */ + ret = vconf_get_bool(VCONFKEY_QUICKSETTING_MULTIWINDOW_ENABLED, &multiwindow_enabled); + if((ret != VCONF_OK) || (multiwindow_enabled == 0)) { + _D("multiwindow is disabled"); + return; + } + + SECURE_LOGD("callee appid : %s / caller_appid : %s", callee_appid, caller_appid); + + /* check whether caller & callee ui app support multi window or not */ + caller_ai = appinfo_find(_laf, caller_appid); + if(caller_ai == NULL) { + _D("no caller appinfo"); + return; + } + caller_ai_multi_window = appinfo_get_value(caller_ai, AIT_MULTI_WINDOW); + if((caller_ai_multi_window == NULL) || (strcmp(caller_ai_multi_window, "true") != 0)) { + _D("caller app does not support multi window"); + return; + } + callee_ai = appinfo_find(_laf, callee_appid); + if(callee_ai == NULL) { + _D("no callee appinfo"); + return; + } + callee_ai_multi_window = appinfo_get_value(callee_ai, AIT_MULTI_WINDOW); + if((callee_ai_multi_window == NULL) || (strcmp(callee_ai_multi_window, "true") != 0)) { + _D("callee app does not support multi window"); + return; + } + + /* check aul_forwad_app case */ + if((caller_appid) && (strcmp(caller_appid, "org.tizen.app-selector") == 0)) { + _D("forward app case"); + return; + } + + /* get multi window layout value */ + caller = bundle_get_val(kb, "__APP_SVC_K_WIN_ID__"); + if(caller) { + caller_win_id = atoi(caller); + } else { + _D("caller win id is null"); + return; + } + if(caller_win_id == 0) { + _D("caller id is 0"); + return; + } + + if( ecore_x_window_prop_card32_get(caller_win_id, + ECORE_X_ATOM_E_WINDOW_DESKTOP_LAYOUT, &layout, 1 ) != -1 ) + { + if(layout == 0 || layout == 1) { + _D("layout : %d", layout); + } else { + _W("x_window__prop_get layout value error : %d", layout); + return; + } + } else { + layout = -1; + } + + do { + const char *operation = NULL; + operation = bundle_get_val(kb, "__APP_SVC_OP_TYPE__"); + if(operation == NULL) { + _D("operation is null"); + break; + } + + if(strcmp(operation,"http://tizen.org/appcontrol/operation/view") == 0) { + int open_via_multi = 0; + ret = vconf_get_bool(VCONFKEY_SETAPPL_OPEN_VIA_MULTI, &open_via_multi); + _D("open_via_multi : %d", open_via_multi); + if((ret == VCONF_OK) && (open_via_multi == 1)) { + is_open_via_multi = 1; + /* callee window should not be transient for caller window under "open in multi window" mode */ + if(caller) { + if(bundle_del(kb, "__APP_SVC_K_WIN_ID__") == -1) { + _D("failed to remove window id of bundle (errno : %d)", errno); + } + } + break; + } + } + } while (0); + + if(is_open_via_multi) { + if(layout == 1) + layout = 0; + else + layout = 1; + + _D("open via multi scenario. reverted layout id is %d", layout); + } else { + /* multi window support app need be launched with full view + when app is launched from multi window support app with full view. */ + if(layout == -1) { + startup_type = 0; + } + } + + char tmp_layout[128]; + char tmp_startup[128]; + + snprintf(tmp_layout, 128, "%d", layout); + snprintf(tmp_startup, 128, "%d", startup_type); + + if(bundle_add(kb, "window_layout_id", tmp_layout) != 0) { + _W("winow layout id bundle add error"); + } + if(bundle_add(kb, "window_startup_type", tmp_startup) != 0) { + _W("winow startup type bundle add error"); + } + + SECURE_LOGD("window startup type(%d) and layout id(%d) is added", startup_type, layout); + + return; +} +#endif + +int __check_mode(const struct appinfo *ai) +{ +#ifdef _APPFW_FEATURE_TTS_MODE + int tts_mode = 0; + const char *tts_support = NULL; +#endif +#ifdef _APPFW_FEATURE_ULTRA_POWER_SAVING_MODE + int ups_mode = 0; + const char *ups_support = NULL; +#endif + +#ifdef _APPFW_FEATURE_TTS_MODE + vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &tts_mode); + if(tts_mode) { + tts_support = appinfo_get_value(ai, AIT_TTS); + _D("tts : %d %s", tts_mode, tts_support); + if(strncmp(tts_support, "false", 5) == 0) + return -1; + } +#endif + +#ifdef _APPFW_FEATURE_ULTRA_POWER_SAVING_MODE + vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &ups_mode); + if(ups_mode == SETTING_PSMODE_WEARABLE) { + ups_support = appinfo_get_value(ai, AIT_UPS); + _D("ups : %d %s", ups_mode, ups_support); + if(strncmp(ups_support, "false", 5) == 0) + return -1; + } +#endif + + return 0; +} + int _start_app(char* appid, bundle* kb, int cmd, int caller_pid, uid_t caller_uid, int fd) { const struct appinfo *ai; + const struct appinfo *caller_ai; int ret = -1; const char *multiple = NULL; const char *app_path = NULL; @@ -959,27 +1416,36 @@ int _start_app(char* appid, bundle* kb, int cmd, int caller_pid, uid_t caller_ui const char *component_type = NULL; int pid = -1; char tmp_pid[MAX_PID_STR_BUFSZ]; - const char *hwacc; const char *permission; const char *pkgid; - const char *taskmanage; const char *preload; const char *pkg_status; const char *operation; + const char *fake_effect; char caller_appid[256]; char* caller = NULL; + char* curr_caller = NULL; + char* old_caller = NULL; pkgmgrinfo_cert_compare_result_type_e compare_result; int delay_reply = 0; int pad_pid = LAUNCHPAD_PID; int status = -1; int r = -1; char trm_buf[MAX_PACKAGE_STR_SIZE]; - bool consented = true; int effect_mode = 0; -#ifdef WEARABLE_PROFILE +#ifdef _APPFW_FEATURE_WMS_CONNECTION_CHECK int wmanager_connected = 0; #endif + char *caller_component_type = NULL; + + if (appid == NULL || kb == NULL + || caller_pid < 0 || caller_uid < 0 || fd < 0) { + _D("invalid parameter"); + if (fd >= 0) + __real_send(fd, -1); + return -1; + } snprintf(tmp_pid, MAX_PID_STR_BUFSZ, "%d", caller_pid); bundle_add(kb, AUL_K_CALLER_PID, tmp_pid); @@ -996,20 +1462,29 @@ int _start_app(char* appid, bundle* kb, int cmd, int caller_pid, uid_t caller_ui } else { bundle_add(kb, AUL_K_CALLER_APPID, caller); } - SECURE_LOGD("caller : %s", bundle_get_val(kb,AUL_K_CALLER_APPID)); - + curr_caller = bundle_get_val(kb,AUL_K_CALLER_APPID); + SECURE_LOGD("caller : %s", curr_caller); + +#ifdef _APPFW_FEATURE_CONTACT_PHONE_AS_ONE_APP + // Add the appid into bundle to distinguish between Contacts and Phone. + if (strncmp(appid, "org.tizen.contacts", strlen("org.tizen.contacts")) == 0 + || strncmp(appid, "org.tizen.phone", strlen("org.tizen.phone")) == 0) + { + bundle_add(kb, AUL_K_INTERNAL_APPID, appid); + SECURE_LOGD("Add the appid[%s] into bundle to distinguish between Contacts and Phone.", appid); + } +#endif ai = appinfo_find(_laf, appid); - if(ai == NULL) { _D("no appinfo"); __real_send(fd, -1); return -1; } else { pkg_status = appinfo_get_value(ai, AIT_STATUS); - if(pkg_status && strncmp(pkg_status, "upgrading", 9) == 0 ) { - _D("upgrading"); - __real_send(fd, -1); - return -1; + if(pkg_status && (strncmp(pkg_status, "blocking", 8) == 0 || strncmp(pkg_status, "restart", 7) == 0) ) { + _D("blocking"); + __real_send(fd, -EREJECTED); + return -EREJECTED; } else if(pkg_status && strncmp(pkg_status, "unmounted", 9) == 0 ) { _D("unmounted"); __real_send(fd, -1); @@ -1017,53 +1492,105 @@ int _start_app(char* appid, bundle* kb, int cmd, int caller_pid, uid_t caller_ui } } - pkgid = appinfo_get_value(ai, AIT_PKGID); - - if(bundle_get_val(kb, AUL_K_PRIVACY_APPID)){ - bundle_del(kb, AUL_K_PRIVACY_APPID); - } else { - privacy_manager_client_check_user_consented(pkgid, &consented); - - _D("consented : %d", consented); - - if(consented == false && bundle_get_val(kb, AUL_K_SDK) == NULL) { - _D("appid : %s", appid); - bundle_add(kb, AUL_K_PRIVACY_APPID, appid); - appid = PRIVACY_POPUP; - bundle_del(kb, AUL_K_PKG_NAME); - bundle_add(kb, AUL_K_PKG_NAME, appid); - ai = appinfo_find(_laf, appid); - } - } - app_path = appinfo_get_value(ai, AIT_EXEC); pkg_type = appinfo_get_value(ai, AIT_TYPE); permission = appinfo_get_value(ai, AIT_PERM); pkgid = appinfo_get_value(ai, AIT_PKGID); component_type = appinfo_get_value(ai, AIT_COMPTYPE); + operation = bundle_get_val(kb, "__APP_SVC_OP_TYPE__"); + caller_ai = appinfo_find(_laf, curr_caller); + if(permission && strncmp(permission, "signature", 9) == 0 ) { - if(caller_uid != 0 && (cmd == APP_START || cmd == APP_START_RES || cmd == APP_START_ASYNC)){ - const struct appinfo *caller_ai; - caller_ai = appinfo_find(_laf, caller_appid); + if(caller_uid != 0 && (cmd == APP_START + || cmd == APP_START_RES + || cmd == APP_START_ASYNC +#ifdef _APPFW_FEATURE_MULTI_INSTANCE + || cmd == APP_START_MULTI_INSTANCE +#endif + )) + { preload = appinfo_get_value(caller_ai, AIT_PRELOAD); if( preload && strncmp(preload, "true", 4) != 0 ) { pkgmgrinfo_pkginfo_compare_app_cert_info(caller_appid, appid, &compare_result); if(compare_result != PMINFO_CERT_COMPARE_MATCH) { pid = -EILLEGALACCESS; - __real_send(fd, pid); + if(cmd == APP_START_ASYNC) + close(fd); + else + __real_send(fd, pid); return pid; } } } } + if(__check_mode(ai) < 0) { + pid = -EREJECTED; + if(cmd == APP_START_ASYNC) + close(fd); + else + __real_send(fd, pid); + return pid; + } + pkgmgrinfo_client_request_enable_external_pkg(pkgid); if (component_type && strncmp(component_type, "uiapp", 5) == 0) { + +#ifdef _APPFW_FEATURE_MULTI_WINDOW + if((cmd != APP_RESUME) && (cmd != APP_OPEN)) { + __add_multi_window_info(kb, ai, (const char*) appid, (const char*)bundle_get_val(kb,AUL_K_CALLER_APPID)); + } +#endif multiple = appinfo_get_value(ai, AIT_MULTI); if (!multiple || strncmp(multiple, "false", 5) == 0) { pid = _status_app_is_running_v2(appid); + } else if (operation != NULL && strncmp(operation, "http://tizen.org/appcontrol/operation/view", 512) == 0){ + old_caller = _status_get_caller_by_appid(appid); + if(old_caller && curr_caller) { + if(strncmp(old_caller, curr_caller, MAX_PACKAGE_STR_SIZE) == 0) { + pid = _status_app_is_running_v2(appid); + } + } + } + +#ifdef _APPFW_FEATURE_APP_CONTROL_LITE + char app_path_link[512] = {0,}; + const char *caller_app_path = NULL; + char caller_app_path_link[512] = {0,}; + + caller_app_path = appinfo_get_value(caller_ai, AIT_EXEC); + + SECURE_LOGD("callee path(%s) caller path(%s)", app_path, caller_app_path); + + readlink(app_path, app_path_link, 512); + readlink(caller_app_path, caller_app_path_link, 512); + + SECURE_LOGD("callee link(%s) caller link(%s)", app_path_link, caller_app_path_link); + + if(strncmp(app_path_link, "/usr/bin/ug-client", 512) == 0) { + if (strcmp(caller, "org.tizen.app-selector") == 0){ + pid = atoi(bundle_get_val(kb,AUL_K_ORG_CALLER_PID)); + bundle_add(kb, "__AUL_UG_EXEC__", app_path); + SECURE_LOGD("app_path : %s , ug id(%s)", app_path, bundle_get_val(kb, "__AUL_UG_ID__")); + } else if(strncmp(caller_app_path_link, "/usr/bin/ug-client", 512) == 0) { + __real_send(fd, -EUGLOCAL_LAUNCH); + return -1; + } + } +#endif + + if(curr_caller) { + caller_component_type = appinfo_get_value(caller_ai, AIT_COMPTYPE); + if (caller_component_type && strncmp(caller_component_type, "uiapp", 5) == 0) { + Ecore_X_Window in_win; + in_win = _input_window_get(); + if(in_win) { + ret = ecore_x_pointer_grab(in_win); + _D("win(%x) ecore_x_pointer_grab(%d)", in_win, ret); + } + } } status = _status_get_app_info_status(pid); @@ -1072,9 +1599,10 @@ int _start_app(char* appid, bundle* kb, int cmd, int caller_pid, uid_t caller_ui SECURE_LOGD("caller process & callee process is same.[%s:%d]", appid, pid); pid = -ELOCALLAUNCH_ID; } else { -#ifdef WEARABLE_PROFILE + if(strncmp(pkg_type, "wgt", 3) == 0) { + __pre_launching_processing(appid); + } proc_group_change_status(PROC_CGROUP_SET_RESUME_REQUEST, pid, appid); -#endif if ((ret = __nofork_processing(cmd, pid, kb, fd)) < 0) { pid = ret; } else { @@ -1087,25 +1615,22 @@ int _start_app(char* appid, bundle* kb, int cmd, int caller_pid, uid_t caller_ui if (r == -1) _D("send SIGKILL: %s", strerror(errno)); } - hwacc = appinfo_get_value(ai, AIT_HWACC); - bundle_add(kb, AUL_K_HWACC, hwacc); - taskmanage = appinfo_get_value(ai, AIT_TASKMANAGE); - bundle_add(kb, AUL_K_TASKMANAGE, taskmanage); - operation = bundle_get_val(kb, "__APP_SVC_OP_TYPE__"); - - if ( cmd == APP_OPEN || - (operation != NULL && strncmp(operation, "http://tizen.org/appcontrol/operation/main", 512) == 0) || - (caller != NULL && strcmp(caller, "com.samsung.wnotification2") == 0) ){ + fake_effect = bundle_get_val(kb, "__FAKE_EFFECT__"); + +#ifdef _APPFW_FEATURE_CPU_BOOST + if (cmd == APP_OPEN || operation != NULL || + (caller != NULL && strcmp(caller, "org.tizen.wnotification2") == 0) || + (caller != NULL && strcmp(caller, "org.tizen.wnotiboard-popup") == 0)) { char *arr[2]; char val[32]; - snprintf(val, sizeof(val), "%d", 1200); + snprintf(val, sizeof(val), "%d", APP_BOOSTING_PERIOD); arr[0] = val; arr[1] = NULL; ret = invoke_dbus_method_sync(SYSTEM_BUS_NAME, SYSTEM_OBJECT_PATH, - SYSTEM_INTERFACE_NAME, SYSTEM_METHOD_NAME, "i", arr); + SYSTEM_INTERFACE_NAME, SYSTEM_METHOD_NAME, "i", arr); _D("%s-%s : %d", SYSTEM_INTERFACE_NAME, SYSTEM_METHOD_NAME, ret); } - +#endif /* * effect_mode = 0 * default mode : fake effect off, 1.6 MHZ off @@ -1118,63 +1643,189 @@ int _start_app(char* appid, bundle* kb, int cmd, int caller_pid, uid_t caller_ui * */ vconf_get_int(AMD_EFFECT_IMAGE_ENABLE, &effect_mode); -#ifdef WEARABLE_PROFILE +#ifdef _APPFW_FEATURE_WMS_CONNECTION_CHECK vconf_get_bool(VCONFKEY_WMS_WMANAGER_CONNECTED, &wmanager_connected); +#endif //_D("*******[effect_mode] Mode : %d\n ", effect_mode ); - if ( ( cmd == APP_OPEN || (operation != NULL && strncmp(operation, "http://tizen.org/appcontrol/operation/main", 512) == 0) ) - && (effect_mode == 1 || effect_mode == 2) && wmanager_connected == true){ -#else - if ( ( cmd == APP_OPEN || (operation != NULL && strncmp(operation, "http://tizen.org/appcontrol/operation/main", 512) == 0) ) - && (effect_mode == 1 || effect_mode == 2)){ + if ( ( cmd == APP_OPEN || + ( (operation != NULL && strncmp(operation, "http://tizen.org/appcontrol/operation/main", 512) == 0) + && !(fake_effect != NULL && strncmp(fake_effect, "OFF", 3) == 0) ) + ) && (effect_mode == 1 || effect_mode == 2) +#ifdef _APPFW_FEATURE_WMS_CONNECTION_CHECK + && wmanager_connected == true #endif + ){ char image_filename[256] = {0,}; + char xml_filename[256] = {0,}; const char *portraitimg = NULL; + const char *landscapeimg = NULL; +#ifdef _APPFW_FEATURE_CHANGEABLE_COLOR + char *effectimg_type = NULL; +#endif const char *indicator = NULL; + int screen_mode = 0; bool rotate_allowed = false; + int file_type = 1; + int theme = 0; + //vconf_get_int(PHONE_ORIENTATION_MODE, &screen_mode); + screen_mode = invoke_dbus_method_sync(ROTATION_BUS_NAME, ROTATION_OBJECT_PATH, + ROTATION_INTERFACE_NAME, ROTATION_METHOD_NAME, "i", NULL); + _D("%s-%s : %d", ROTATION_INTERFACE_NAME, ROTATION_METHOD_NAME, screen_mode); vconf_get_bool(PHONE_ROTATE_LOCK, &rotate_allowed); /*TODO: use vconf_notify_key_changed()*/ portraitimg = appinfo_get_value(ai, AIT_EFFECTIMAGEPORT); + landscapeimg = appinfo_get_value(ai, AIT_EFFECTIMAGELAND); +#ifdef _APPFW_FEATURE_CHANGEABLE_COLOR + effectimg_type = appinfo_get_value(ai, AIT_EFFECTTYPE); +#endif indicator = appinfo_get_value(ai, AIT_INDICATOR_DISP); /*Currently we assume apps supporting launching effect supports portrait mode*/ - if (portraitimg){ - snprintf(image_filename, 255, "%s", portraitimg); - if (access(image_filename, R_OK) == 0){ - __amd_effect_image_file_set("/usr/share/splash_images/type0_portrait.bmp"); - __amd_send_message_to_e17(0, indicator); + if (indicator && portraitimg) { + if (rotate_allowed == false) { + screen_mode = 1; + } + if ((screen_mode == 2 || screen_mode == 4) && (rotate_allowed == true)) { + /*if there is no landscape image, that means app supports only portrait mode.*/ + if (landscapeimg) { + snprintf(image_filename, 255, "%s", landscapeimg); + } + } else { + snprintf(image_filename, 255, "%s", portraitimg); + } + if (access(image_filename, R_OK) == 0) { +#ifdef _APPFW_FEATURE_CHANGEABLE_COLOR + if(strncmp(effectimg_type, "edj-dark", strlen(effectimg_type)) == 0) { + file_type = 0; + theme = 0; + } else if (strncmp(effectimg_type, "edj-light", strlen(effectimg_type)) == 0) { + file_type = 0; + theme = 1; + } else if (strncmp(effectimg_type, "edj-default", strlen(effectimg_type)) == 0) { + file_type = 0; + theme = 2; + } else { + file_type = 1; + theme = 0; + } + + do { + if (file_type == 1) + break; + r = snprintf(xml_filename, 255, "/usr/apps/%s/shared/res/tables/%s_ChangeableColorInfo.xml", pkgid, pkgid); + if (access(xml_filename, R_OK) == 0) { + //snprintf(image_filename, 255, "%s:%s", image_filename, xml_filename); + strcat(image_filename, ":"); + strcat(image_filename, xml_filename); + break; + } + r = snprintf(xml_filename, 255, "/opt/usr/apps/%s/shared/res/tables/%s_ChangeableColorInfo.xml", pkgid, pkgid); + if (access(xml_filename, R_OK) == 0) { + //snprintf(image_filename, 255, "%s:%s", image_filename, xml_filename); + strcat(image_filename, ":"); + strcat(image_filename, xml_filename); + break; + } + } while(0); +#endif +#ifndef _APPFW_FEATURE_DEFAULT_FAKE_IMAGE + __amd_effect_image_file_set(image_filename); +#else + if(file_type == 1) { + __amd_effect_image_file_set("/usr/share/splash_images/type0_portrait.bmp"); + } else { + __amd_effect_image_file_set(image_filename); + } +#endif + __amd_send_message_to_e17(screen_mode, indicator, file_type, theme); } } } - bundle_add(kb, AUL_K_EXEC, app_path); - bundle_add(kb, AUL_K_PACKAGETYPE, pkg_type); - if(bundle_get_type(kb, AUL_K_SDK) != BUNDLE_TYPE_NONE) { +#ifdef _APPFW_FEATURE_DEBUG_LAUNCHPAD + if (bundle_get_type(kb, AUL_K_SDK) != BUNDLE_TYPE_NONE) { pad_pid = DEBUG_LAUNCHPAD_PID; - } else if(strncmp(pkg_type, "wgt", 3) == 0) { + } else if (strncmp(pkg_type, "wgt", 3) == 0) { pad_pid = WEB_LAUNCHPAD_PID; } -#ifdef PROCESS_POOL_ENABLE +#else + if (strncmp(pkg_type, "wgt", 3) == 0) { + pad_pid = WEB_LAUNCHPAD_PID; + } +#endif +#ifdef _APPFW_FEATURE_NATIVE_LAUNCHPAD + else if (strncmp(pkg_type, "tpk", 3) == 0) { + char native_sock[UNIX_PATH_MAX] = { 0, }; + snprintf(native_sock, UNIX_PATH_MAX, "%s/%d", AUL_SOCK_PREFIX, pad_pid); + if (access(native_sock, F_OK) != 0) { + _D("Sending to native launchpad because native launchpad is not initialized."); + } else { + pad_pid = NATIVE_LAUNCHPAD_PID; + } + } +#endif +#ifdef _APPFW_FEATURE_PROCESS_POOL else { const char *process_pool = appinfo_get_value(ai, AIT_POOL); - _D("process_pool: %s\n", process_pool); + _D("process_pool: %s", process_pool); + + const char *hwacc = appinfo_get_value(ai, AIT_HWACC); + _D("h/w acceleration: %s", hwacc); + + SECURE_LOGD("appid: %s", appid); - if (strncmp(process_pool, "true", 4) == 0) + if (strncmp(process_pool, "true", strlen("true")) == 0) { + #ifndef _APPFW_FEATURE_PROCESS_POOL_COMMON + if (strncmp(hwacc, "USE", strlen("USE")) != 0) + { + _D("Sending to process-pool launchpad (type1)."); + bundle_add(kb, AUL_K_LAUNCHPAD_TYPE, "1"); //sw rendering + pad_pid = PROCESS_POOL_LAUNCHPAD_PID; + } + else + { + #ifndef _APPFW_FEATURE_PROCESS_POOL_HW_RENDERING + _D("Sending to legacy launchpad because launchpad type2 is not supported."); + #else + _D("Sending to process-pool launchpad (type2)."); + bundle_add(kb, AUL_K_LAUNCHPAD_TYPE, "2"); //hw rendering + pad_pid = PROCESS_POOL_LAUNCHPAD_PID; + #endif + } + #else //_APPFW_FEATURE_PROCESS_POOL_COMMON + _D("Sending to process-pool launchpad (combine mode)."); + bundle_add(kb, AUL_K_LAUNCHPAD_TYPE, "1"); pad_pid = PROCESS_POOL_LAUNCHPAD_PID; + #endif //_APPFW_FEATURE_PROCESS_POOL_COMMON + + char pad_sock[UNIX_PATH_MAX] = { 0, }; + snprintf(pad_sock, UNIX_PATH_MAX, "%s/%d", AUL_SOCK_PREFIX, pad_pid); + if (access(pad_sock, F_OK) != 0) + { + _D("Sending to legacy launchpad because process-pool launchpad is not initialized."); + pad_pid = LAUNCHPAD_PID; + } } } -#endif +#endif //_APPFW_FEATURE_PROCESS_POOL + __set_appinfo_for_launchpad(ai, kb); pid = app_send_cmd(pad_pid, cmd, kb); - if(pid == -3) { + if(pid == AUL_R_ECOMM) { pid = -ENOLAUNCHPAD; } //_add_cgroup(_lcg, appid, pid); -#ifdef WEARABLE_PROFILE - proc_group_change_status(PROC_CGROUP_SET_LAUNCH_REQUEST, pid, appid); + proc_cgroup_launch(PROC_CGROUP_SET_LAUNCH_REQUEST, pid, appid, pkgid); snprintf(trm_buf, MAX_PACKAGE_STR_SIZE, "appinfo_launch:%s[PID]%d", appid, pid); __trm_app_info_send_socket(trm_buf); -#endif + } + if(pid < 0) { + if(_input_window_get() != 0) + ecore_x_pointer_ungrab(); + _D("pid(%d) ecore_x_pointer_ungrab", pid); + } else { + grab_timer_id = g_timeout_add(1000, __grab_timeout_handler, pid); } } else if (component_type && strncmp(component_type, "svcapp", 6) == 0) { @@ -1184,9 +1835,22 @@ int _start_app(char* appid, bundle* kb, int cmd, int caller_pid, uid_t caller_ui pid = ret; } } else if (cmd != APP_RESUME) { +#ifdef _APPFW_FEATURE_DEBUG_LAUNCHPAD + if (bundle_get_type(kb, AUL_K_SDK) != BUNDLE_TYPE_NONE) { + _D("The svcapp(%s) is launched by debug-launchpad", appid); + __set_appinfo_for_launchpad(ai, kb); + pid = app_send_cmd(DEBUG_LAUNCHPAD_PID, cmd, kb); + if (pid == AUL_R_ECOMM) { + pid = -ENOLAUNCHPAD; + } + proc_cgroup_launch(PROC_CGROUP_SET_LAUNCH_REQUEST, pid, appid, pkgid); + } else { + pid = service_start(_lcg, appid, app_path, kb); + proc_cgroup_launch(PROC_CGROUP_SET_SERVICE_REQUEST, pid, appid, pkgid); + } +#else pid = service_start(_lcg, appid, app_path, kb); -#ifdef WEARABLE_PROFILE - proc_group_change_status(PROC_CGROUP_SET_SERVICE_REQUEST, pid, appid); + proc_cgroup_launch(PROC_CGROUP_SET_SERVICE_REQUEST, pid, appid, pkgid); #endif } } else { @@ -1201,26 +1865,56 @@ int _start_app(char* appid, bundle* kb, int cmd, int caller_pid, uid_t caller_ui } if(pid > 0) { - _status_add_app_info_list(appid, app_path, pid, pad_pid); - } +#ifdef _APPFW_FEATURE_CONTACT_PHONE_AS_ONE_APP + // Add the appid into bundle to distinguish between Contacts and Phone. + if (strncmp(appid, "org.tizen.phone", strlen("org.tizen.phone")) == 0) + _status_add_app_info_list("org.tizen.contacts", app_path, curr_caller, pid, pad_pid); + else +#endif + _status_add_app_info_list(appid, app_path, curr_caller, pid, pad_pid); -#ifdef WEARABLE_PROFILE - display_lock_state(LCD_OFF, STAY_CUR_STATE, 1000); +#ifdef _APPFW_FEATURE_APP_CHECKER + ret = ac_server_check_launch_privilege(appid, appinfo_get_value(ai, AIT_TYPE), pid); + return ret != AC_R_ERROR ? pid : -1; #endif + } return pid; } +int __e17_status_handler(int pid, int status, void *data) +{ + if( status == 0 || status == 3) { + _D("pid(%d) status(%d)", pid, status); + if(_input_window_get() != 0) + ecore_x_pointer_ungrab(); + g_source_remove(grab_timer_id); + } + + return 0; +} int _launch_init(struct amdmgr* amd) { + int ret = 0; + + _D("_launch_init"); + + amd_cmdline = __proc_get_cmdline_bypid(getpid()); + _laf = amd->af; _lcg = amd->cg; + conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); if (!conn) { _E("dbus_bus_get error"); return -EBADMSG; } + + ret = aul_listen_e17_status_signal(__e17_status_handler, NULL); + + _D("ret : %d", ret); + return 0; } @@ -1229,4 +1923,10 @@ void _set_atom_effect(void) ATOM_IMAGE_EFFECT = ecore_x_atom_get(atom_name); } - +void __set_appinfo_for_launchpad(const struct appinfo *ai, bundle *kb) { + _D("Add hwacc, taskmanage, app_path and pkg_type into bundle for sending those to launchpad."); + bundle_add(kb, AUL_K_HWACC, appinfo_get_value(ai, AIT_HWACC)); + bundle_add(kb, AUL_K_TASKMANAGE, appinfo_get_value(ai, AIT_TASKMANAGE)); + bundle_add(kb, AUL_K_EXEC, appinfo_get_value(ai, AIT_EXEC)); + bundle_add(kb, AUL_K_PACKAGETYPE, appinfo_get_value(ai, AIT_TYPE)); +} diff --git a/am_daemon/amd_launch.h b/am_daemon/amd_launch.h index 4d67357..9cde936 100755 --- a/am_daemon/amd_launch.h +++ b/am_daemon/amd_launch.h @@ -22,20 +22,32 @@ #ifndef __AUL_AMD_LAUNCH_H_ #define __AUL_AMD_LAUNCH_H_ +#ifndef _APPFW_FEATURE_PROCESS_POOL + #ifdef _APPFW_FEATURE_PROCESS_POOL_COMMON + #error _APPFW_FEATURE_PROCESS_POOL should be defined !! + #else + #ifdef _APPFW_FEATURE_PROCESS_POOL_HW_RENDERING + #error _APPFW_FEATURE_PROCESS_POOL should be defined !! + #endif + #endif +#endif + +#include #include #include "aul_util.h" #include "amd_appinfo.h" int _send_to_sigkill(int pid); -int _resume_app(int pid); +int _resume_app(int pid, int clifd); int _term_app(int pid, int clifd); -int _fake_launch_app(int cmd, int pid, bundle * kb); +int _fake_launch_app(int cmd, int pid, bundle * kb, int clifd); int _start_app(char* appid, bundle* kb, int cmd, int caller_pid, uid_t caller_uid, int fd); void service_release(const char *group); int _start_srv(const struct appinfo *ai, bundle *kb); int _launch_init(struct amdmgr* amd); void _set_atom_effect(void); - +void __set_appinfo_for_launchpad(const struct appinfo *ai, bundle *kb); +gboolean _get_platform_ready(void); #endif /* __AUL_AMD_LAUNCH_H_ */ diff --git a/am_daemon/amd_main.c b/am_daemon/amd_main.c index 6248a0d..f182bfe 100755 --- a/am_daemon/amd_main.c +++ b/am_daemon/amd_main.c @@ -31,12 +31,19 @@ #include #include #include -#include +#ifdef _APPFW_FEATURE_APP_CHECKER +#include +#endif #include +#include +#include +#include +#include #include "amd_config.h" #include "simple_util.h" #include "aul_util.h" +#include "app_sock.h" #include "amd_appinfo.h" #include "amd_cgutil.h" #include "amd_key.h" @@ -52,6 +59,17 @@ # define AGENT_PATH "/usr/bin/daemon-manager-release-agent" #endif +#ifdef _APPFW_FEATURE_BG_PROCESS_LIMIT +typedef struct _r_app_info_t{ + char pkg_name[MAX_PACKAGE_STR_SIZE]; + int pid; +} r_app_info_t; + +GSList *r_app_info_list = NULL; +#endif + +gboolean platform_ready = false; + #define WINDOW_READY "/tmp/.wm_ready" typedef struct _window_watch { @@ -61,15 +79,197 @@ typedef struct _window_watch { } _window_watch_t; static _window_watch_t *win_info_t = NULL; +#ifdef _APPFW_FEATURE_BG_PROCESS_LIMIT +static void __vconf_cb(keynode_t *key, void *data); +#endif static int __app_dead_handler(int pid, void *data); static int __init(); extern int _status_init(struct amdmgr* amd); +static int __send_to_sigkill(int pid) +{ + int pgid; + + _D("__send_to_sigkill, pid: %d", pid); + + pgid = getpgid(pid); + if (pgid <= 1) + return -1; + + if (killpg(pgid, SIGKILL) < 0) + return -1; + + return 0; +} + +#ifdef _APPFW_FEATURE_BG_PROCESS_LIMIT +static int __kill_bg_apps(int limit) +{ + int len; + int i; + int n; + r_app_info_t *info_t = NULL; + GSList *iter = NULL; + + len = g_slist_length(r_app_info_list); + + n = len - limit; + + if (n<=0) return 0; + + for ( i=0, iter = r_app_info_list; idata; + //__send_to_sigkill(info_t->pid); + proc_group_change_status(PROC_CGROUP_SET_TERMINATE_REQUEST, info_t->pid, NULL); + _term_app(info_t->pid, 0); + iter = g_slist_next(iter); + r_app_info_list = g_slist_remove(r_app_info_list, info_t); + free(info_t); + } + + return 0; +} + +static int __remove_item_running_list(int pid) +{ + r_app_info_t *info_t = NULL; + GSList *iter = NULL; + + for (iter = r_app_info_list; iter != NULL; iter = g_slist_next(iter)) + { + info_t = (r_app_info_t *)iter->data; + if(pid == info_t->pid) { + r_app_info_list = g_slist_remove(r_app_info_list, info_t); + free(info_t); + break; + } + } + return 0; +} + +gboolean __add_item_running_list(gpointer user_data) +{ + + bool taskmanage; + pkgmgrinfo_appinfo_h handle = NULL; + int ret = 0; + r_app_info_t *info_t = NULL; + GSList *iter = NULL; + int found = 0; + int limit; + + item_pkt_t *item = (item_pkt_t *)user_data; + if (item == NULL) { + return false; + } + + char* appid = item->appid; + int pid = item->pid; + + SECURE_LOGD("__add_item_running_list pid: %d", pid); + + if (vconf_get_int(VCONFKEY_SETAPPL_DEVOPTION_BGPROCESS, &limit) != 0){ + _E("Unable to get VCONFKEY_SETAPPL_DEVOPTION_BGPROCESS\n"); + } + + if (appid == NULL) { + return false; + } else if (strncmp(appid, "org.tizen.cluster-home", 24) == 0) { + if(limit>0) __kill_bg_apps(limit-1); + return false; + } + + SECURE_LOGD("__add_item_running_list appid: %s", appid); + + ret = pkgmgrinfo_appinfo_get_appinfo(appid, &handle); + if (ret != PMINFO_R_OK) { + _E("pkgmgrinfo_pkginfo_get_pkginfo with %s failed", appid); + return false; + } + + ret = pkgmgrinfo_appinfo_is_taskmanage(handle, &taskmanage); + if (ret != PMINFO_R_OK) { + _E("pkgmgrinfo_appinfo_is_taskmanage failed"); + goto END; + } + + if (taskmanage == false) + goto END; + + for (iter = r_app_info_list; iter != NULL; iter = g_slist_next(iter)) + { + info_t = (r_app_info_t *)iter->data; + if(pid == info_t->pid) { + found = 1; + r_app_info_list = g_slist_remove(r_app_info_list, info_t); + r_app_info_list = g_slist_append(r_app_info_list, info_t); + break; + } + } + + if(found == 0) { + info_t = malloc(sizeof(r_app_info_t)); + strncpy(info_t->pkg_name, appid, MAX_PACKAGE_STR_SIZE-1); + info_t->pid = pid; + r_app_info_list = g_slist_append(r_app_info_list, info_t); + } + + for (iter = r_app_info_list; iter != NULL; iter = g_slist_next(iter)) + { + info_t = (r_app_info_t *)iter->data; + } + + if(limit>0) __kill_bg_apps(limit); + + for (iter = r_app_info_list; iter != NULL; iter = g_slist_next(iter)) + { + info_t = (r_app_info_t *)iter->data; + } + +END: + pkgmgrinfo_appinfo_destroy_appinfo(handle); + + free(item); + return false; +} + +static void __vconf_cb(keynode_t *key, void *data) +{ + int limit; + const char *name; + + name = vconf_keynode_get_name(key); + if( name == NULL ) { + return; + }else if ( strcmp(name, VCONFKEY_SETAPPL_DEVOPTION_BGPROCESS) == 0){ + limit = vconf_keynode_get_int(key); + if(limit>0) __kill_bg_apps(limit); + } +} +#endif + static int __app_dead_handler(int pid, void *data) { + char trm_buf[MAX_PACKAGE_STR_SIZE]; + char buf[MAX_LOCAL_BUFSZ]; + + _I("__app_dead_handler, pid: %d", pid); + + if(pid <= 0) + return 0; + _unregister_key_event(pid); +#ifdef _APPFW_FEATURE_BG_PROCESS_LIMIT + __remove_item_running_list(pid); +#endif _status_remove_app_info_list(pid); + snprintf(trm_buf, MAX_PACKAGE_STR_SIZE, "appinfo_terminated:[PID]%d", pid); + __trm_app_info_send_socket(trm_buf); + + snprintf(buf, MAX_LOCAL_BUFSZ, "%s/%d", AUL_SOCK_PREFIX, pid); + unlink(buf); + return 0; } @@ -86,10 +286,16 @@ static void __start_cb(void *user_data, if (r == 1 && strncmp(componet, "svcapp", 6) == 0) { - const char *pkgid = appinfo_get_value(ai, AIT_PKGID); - _D("start service - %s", pkgid); - - _start_srv(ai, NULL); + const char *appid = appinfo_get_value(ai, AIT_NAME); + if (_status_app_is_running(appid) < 0) + { + _I("start service (on-boot) - %s", appid); + _start_srv(ai, NULL); + } + else + { + _E("service: %s is already running", appid); + } } } @@ -98,10 +304,29 @@ static void _start_services(struct amdmgr *amd) appinfo_foreach(amd->af, __start_cb, amd); } +gboolean _get_platform_ready() +{ + return platform_ready; +} + +static gboolean __platform_ready_handler(gpointer data) +{ + _E("[Info]__platform_ready_handler"); + platform_ready = true; + + return FALSE; +} + static int __booting_done_handler(int pid, void *data) { + guint timer_id; + + _E("[Info]__booting_done_handler, pid: %d", pid); + _start_services((struct amdmgr*)data); + timer_id = g_timeout_add(60000, __platform_ready_handler, NULL); + return 0; } @@ -115,6 +340,8 @@ static gboolean _check_window_ready(void) static void __window_init(void) { + _D("_window_init"); + ecore_x_init(NULL); _set_atom_effect(); #ifndef __i386__ @@ -160,6 +387,8 @@ static Eina_Bool _window_cb(void *data, Ecore_Fd_Handler * fd_handler) static void _register_window_init(void) { + _D("_register_window_init"); + win_info_t = malloc(sizeof(_window_watch_t)); if (!win_info_t) { _E("Unable to allocate memory. don't init widow\n"); @@ -182,30 +411,54 @@ static void _window_init(void) static int __init() { struct amdmgr amd; + int ret = 0; ecore_init(); evas_init(); ecore_event_init(); - appinfo_init(&amd.af); - cgutil_create(MOUNT_PATH, AGENT_PATH, &amd.cg); - _requset_init(&amd); + _D("ecore init done\n"); + + ret = appinfo_init(&amd.af); + assert(ret == 0); + + ret = cgutil_create(MOUNT_PATH, AGENT_PATH, &amd.cg); + assert(ret == 0); + + ret = _request_init(&amd); + assert(ret == 0); + _launch_init(&amd); _status_init(&amd); _window_init(); - aul_listen_app_dead_signal(__app_dead_handler, NULL); + _D("AMD init done\n"); +#ifdef _APPFW_FEATURE_BG_PROCESS_LIMIT + if (vconf_notify_key_changed(VCONFKEY_SETAPPL_DEVOPTION_BGPROCESS, __vconf_cb, NULL) != 0) { + _E("Unable to register callback for VCONFKEY_SETAPPL_DEVOPTION_BGPROCESS\n"); + } +#endif + + aul_listen_app_dead_signal(__app_dead_handler, NULL); aul_listen_booting_done_signal(__booting_done_handler, &amd); +#ifdef _APPFW_FEATURE_PRIORITY_CHANGE + int res = setpriority(PRIO_PROCESS, 0, -12); + if (res == -1) + { + SECURE_LOGE("Setting process (%d) priority to -12 failed, errno: %d (%s)", + getpid(), errno, strerror(errno)); + } +#endif return 0; } gboolean __amd_ready(gpointer user_data) { - int handle; + _D("AMD ready\n"); - handle = creat("/tmp/amd_ready", S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); + int handle = creat("/tmp/amd_ready", S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); if (handle != -1) close(handle); @@ -214,7 +467,17 @@ gboolean __amd_ready(gpointer user_data) int main(int argc, char *argv[]) { + _D("AMD main()\n"); + +#ifdef _APPFW_FEATURE_APP_CHECKER + if (ac_server_initialize() != AC_R_OK){ + _E("ac_server_initialize failed!\n"); + assert(0); + return -1; + } +#endif if (__init() != 0){ + assert(0); _E("AMD Initialization failed!\n"); return -1; } diff --git a/am_daemon/amd_request.c b/am_daemon/amd_request.c index 9b8927e..04f270a 100755 --- a/am_daemon/amd_request.c +++ b/am_daemon/amd_request.c @@ -31,14 +31,14 @@ #include #include #include -#ifdef WEARABLE_PROFILE #include -#endif #include +#include #include "amd_config.h" #include "simple_util.h" #include "app_sock.h" +#include "app_signal.h" #include "aul_util.h" #include "amd_request.h" #include "amd_key.h" @@ -47,20 +47,32 @@ #include "amd_cgutil.h" #include "amd_status.h" +#include #define INHOUSE_UID 5000 +#ifdef _APPFW_FEATURE_MULTI_INSTANCE +#define METADATA_MULTI_INSTANCE "http://developer.samsung.com/tizen/metadata/multiinstance" +#endif + struct appinfomgr *_raf; struct cginfo *_rcg; +static DBusConnection *bus = NULL; +char *home_appid = NULL; + static int __send_result_to_client(int fd, int res); static gboolean __request_handler(gpointer data); static int __send_result_to_client(int fd, int res) { + _D("__send_result_to_client, res: %d", fd, res); + if (send(fd, &res, sizeof(int), MSG_NOSIGNAL) < 0) { - if (errno == EPIPE) + if (errno == EPIPE) { _E("send failed due to EPIPE.\n"); + } + _E("send fail to client"); } close(fd); @@ -69,6 +81,9 @@ static int __send_result_to_client(int fd, int res) static void __real_send(int clifd, int ret) { + if(clifd <= 0) { + return; + } if (send(clifd, &ret, sizeof(int), MSG_NOSIGNAL) < 0) { if (errno == EPIPE) { _E("send failed due to EPIPE.\n"); @@ -110,15 +125,19 @@ static int __foward_cmd(int cmd, bundle *kb, int cr_pid) int res; if ((pid = __get_caller_pid(kb)) < 0) - return AUL_R_ERROR; + { + return AUL_R_ERROR; + } pgid = getpgid(cr_pid); if(pgid > 0) { snprintf(tmp_pid, MAX_PID_STR_BUFSZ, "%d", pgid); - bundle_del(kb,AUL_K_CALLEE_PID); + bundle_del(kb, AUL_K_CALLEE_PID); bundle_add(kb, AUL_K_CALLEE_PID, tmp_pid); } + _D("__forward_cmd: %d %d", cr_pid, pgid); + bundle_encode(kb, &kb_data, &datalen); if ((res = __app_send_raw_with_noreply(pid, cmd, kb_data, datalen)) < 0) res = AUL_R_ERROR; @@ -148,19 +167,18 @@ static int __app_process_by_pid(int cmd, _E("invalid pid"); return -1; } -#ifdef WEARABLE_PROFILE if (cmd == APP_RESUME_BY_PID) proc_group_change_status(PROC_CGROUP_SET_RESUME_REQUEST, pid, NULL); else proc_group_change_status(PROC_CGROUP_SET_TERMINATE_REQUEST, pid, NULL); -#endif + _D("__app_process_by_pid, cmd: %d, pid: %d, ", cmd, pid); switch (cmd) { case APP_RESUME_BY_PID: - ret = _resume_app(pid); - __real_send(clifd, ret); + ret = _resume_app(pid, clifd); break; case APP_TERM_BY_PID: + case APP_TERM_BY_PID_WITHOUT_RESTART: ret = _term_app(pid, clifd); break; case APP_KILL_BY_PID: @@ -169,10 +187,17 @@ static int __app_process_by_pid(int cmd, __real_send(clifd, ret); break; case APP_TERM_REQ_BY_PID: - if ((ret = __app_send_raw(pid, APP_TERM_REQ_BY_PID, (unsigned char *)&dummy, sizeof(int))) < 0) { + if ((ret = __app_send_raw(pid, cmd, (unsigned char *)&dummy, sizeof(int))) < 0) { + _D("terminate req packet send error"); + } + __real_send(clifd, ret); + break; + case APP_TERM_BY_PID_ASYNC: + if ((ret = __app_send_raw_with_noreply(pid, cmd, (unsigned char *)&dummy, sizeof(int))) < 0) { _D("terminate req packet send error"); } __real_send(clifd, ret); + break; } return ret; @@ -194,6 +219,15 @@ static gboolean __add_history_handler(gpointer user_data) kb = bundle_decode(pkt->data, pkt->len); appid = (char *)bundle_get_val(kb, AUL_K_PKG_NAME); +#ifdef _APPFW_FEATURE_CONTACT_PHONE_AS_ONE_APP + // When the Phone is executed, the Contacts is shown on task manager. + int need_free = 0; + if (strncmp(appid, "org.tizen.phone", strlen("org.tizen.phone")) == 0) + { + appid = strndup("org.tizen.contacts", strlen("org.tizen.contacts")); + need_free = 1; + } +#endif ai = (struct appinfo *)appinfo_find(_raf, appid); app_path = (char *)appinfo_get_value(ai, AIT_EXEC); @@ -216,6 +250,11 @@ static gboolean __add_history_handler(gpointer user_data) bundle_free(kb); free(pkt); +#ifdef _APPFW_FEATURE_CONTACT_PHONE_AS_ONE_APP + if (need_free) + free(appid); +#endif + return FALSE; } @@ -296,6 +335,136 @@ int __release_srv(const char *filename) return 0; } +static inline int __send_home_launch_signal(int pid) +{ + DBusMessage *message; + + if (bus == NULL) + return -1; + + message = dbus_message_new_signal(AUL_DBUS_PATH, + AUL_DBUS_SIGNAL_INTERFACE, + AUL_DBUS_HOMELAUNCH_SIGNAL); + + if (dbus_message_append_args(message, + DBUS_TYPE_UINT32, &pid, + DBUS_TYPE_INVALID) == FALSE) { + _E("Failed to load data error"); + return -1; + } + + if (dbus_connection_send(bus, message, NULL) == FALSE) { + _E("dbus send error"); + return -1; + } + + dbus_connection_flush(bus); + dbus_message_unref(message); + + _D("send dead signal done\n"); + + return 0; +} + +static inline int __send_app_termination_signal(int dead_pid) +{ + DBusMessage *message; + + if (bus == NULL) + return -1; + + message = dbus_message_new_signal(AUL_DBUS_PATH, + AUL_DBUS_SIGNAL_INTERFACE, + AUL_DBUS_APPDEAD_SIGNAL); + + if (dbus_message_append_args(message, + DBUS_TYPE_UINT32, &dead_pid, + DBUS_TYPE_INVALID) == FALSE) { + _E("Failed to load data error"); + return -1; + } + + if (dbus_connection_send(bus, message, NULL) == FALSE) { + _E("dbus send error"); + return -1; + } + + dbus_connection_flush(bus); + dbus_message_unref(message); + + _D("send dead signal done\n"); + + return 0; +} + +#ifdef _APPFW_FEATURE_MULTI_INSTANCE +static char* __get_metadata_value(const char *appid, const char *metadata_key) +{ + int ret = 0; + pkgmgrinfo_appinfo_h handle; + char *metadata_value = NULL; + char *multi_appid = NULL; + + ret = pkgmgrinfo_appinfo_get_appinfo(appid, &handle); + if (ret != PMINFO_R_OK) + return NULL; + + ret = pkgmgrinfo_appinfo_get_metadata_value(handle, metadata_key, &metadata_value); + if (ret != PMINFO_R_OK) { + pkgmgrinfo_appinfo_destroy_appinfo(handle); + return NULL; + } + + multi_appid = strdup(metadata_value); + + pkgmgrinfo_appinfo_destroy_appinfo(handle); + + return multi_appid; +} + +static const char* __check_target_appid(const struct appinfo* ai, const char *appid, const char *multi_appid) +{ + const char* target = NULL; + + // Both apps are running + if (_status_app_is_running(appid) != -1 && _status_app_is_running(multi_appid) != -1) { + const char* toggle = appinfo_get_value(ai, AIT_TOGGLE_ORDER); + int order = atoi(toggle); + + _D("launch a multi-instance app with toggle mode: %d", order); + switch (order) { + case 0: + target = multi_appid; + appinfo_set_value(ai, AIT_TOGGLE_ORDER, "1"); + break; + + case 1: + target = appid; + appinfo_set_value(ai, AIT_TOGGLE_ORDER, "0"); + break; + + default: + break; + } + } else { + // Main app is running + if (_status_app_is_running(appid) != -1) { + _D("Send a request to the running main appid: %s", appid); + target = appid; + // Sub app is running + } else if (_status_app_is_running(multi_appid) != -1) { + _D("Send a request to the running sub appid: %s", multi_appid); + target = multi_appid; + } else { + _D("Both apps are not running, launch a main app - %s", appid); + target = appid; + } + } + + return target; +} +#endif + static gboolean __request_handler(gpointer data) { GPollFD *gpollfd = (GPollFD *) data; @@ -307,18 +476,19 @@ static gboolean __request_handler(gpointer data) int ret = -1; int free_pkt = 1; char *appid; - /*char *app_path; - char *tmp_pid;*/ + char *term_pid = NULL; int pid; bundle *kb = NULL; const struct appinfo *ai; const char *pkg_status; + item_pkt_t *item; if ((pkt = __app_recv_raw(fd, &clifd, &cr)) == NULL) { _E("recv error"); return FALSE; } + _D("__request_handler: %d", pkt->cmd); switch (pkt->cmd) { case APP_OPEN: case APP_RESUME: @@ -333,10 +503,55 @@ static gboolean __request_handler(gpointer data) } else { kb = bundle_decode(pkt->data, pkt->len); appid = (char *)bundle_get_val(kb, AUL_K_PKG_NAME); + +#ifdef _APPFW_FEATURE_MULTI_INSTANCE + // Check the multi-instance app + ai = appinfo_find(_raf, appid); + if (ai == NULL) { + _E("no appinfo"); + __real_send(clifd, -1); + ret = -1; + } else { + const char* multi = appinfo_get_value(ai, AIT_MULTI_INSTANCE); + if( multi && strncmp(multi, "true", strlen("true")) == 0 ) { + + char* multi_appid =__get_metadata_value(appid, METADATA_MULTI_INSTANCE); + if (multi_appid != NULL) + { + _D("Multi-instance main: %s, sub: %s", appid, multi_appid); + + const char* target_appid = __check_target_appid(ai, appid, multi_appid); + + _D("launch a target appid: - %s", target_appid); + ret = _start_app(target_appid, kb, pkt->cmd, cr.pid, cr.uid, clifd); + } else { + _D("No multi-instance app information, launch a main appid: - %s", appid); + ret = _start_app(appid, kb, pkt->cmd, cr.pid, cr.uid, clifd); + } + + free(multi_appid); + } + else + { + _D("launch a single-instance appid: %s", appid); + ret = _start_app(appid, kb, pkt->cmd, cr.pid, cr.uid, clifd); + } + } +#else ret = _start_app(appid, kb, pkt->cmd, cr.pid, cr.uid, clifd); +#endif - if(ret > 0) { + if(ret > 0 && bundle_get_type(kb, AUL_K_PRELAUCHING) == BUNDLE_TYPE_NONE) { + item = calloc(1, sizeof(item_pkt_t)); + item->pid = ret; + strncpy(item->appid, appid, 511); free_pkt = 0; + + if (home_appid && strncmp(appid, home_appid, strlen(appid)) == 0) + __send_home_launch_signal(ret); +#ifdef _APPFW_FEATURE_BG_PROCESS_LIMIT + __add_item_running_list(item); +#endif g_timeout_add(1000, __add_history_handler, pkt); } @@ -344,6 +559,40 @@ static gboolean __request_handler(gpointer data) bundle_free(kb), kb = NULL; } break; +#ifdef _APPFW_FEATURE_MULTI_INSTANCE + case APP_START_MULTI_INSTANCE: + ret = security_server_check_privilege_by_sockfd(clifd, "aul::launch", "x"); + if(ret == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) { + _E("launch request has been denied by smack"); + ret = -EILLEGALACCESS; + __real_send(clifd, ret); + } else { + kb = bundle_decode(pkt->data, pkt->len); + appid = (char *)bundle_get_val(kb, AUL_K_PKG_NAME); + + _D("launch a multi-instance appid: %s", appid); + ret = _start_app(appid, kb, pkt->cmd, cr.pid, cr.uid, clifd); + } + + if(ret > 0) { + item = calloc(1, sizeof(item_pkt_t)); + item->pid = ret; + strncpy(item->appid, appid, 511); + free_pkt = 0; + + if (home_appid && strncmp(appid, home_appid, strlen(appid)) == 0) + __send_home_launch_signal(ret); +#ifdef _APPFW_FEATURE_BG_PROCESS_LIMIT + __add_item_running_list(item); +#endif + g_timeout_add(1000, __add_history_handler, pkt); + } + + if (kb != NULL) + bundle_free(kb), kb = NULL; + + break; +#endif case APP_RESULT: case APP_CANCEL: kb = bundle_decode(pkt->data, pkt->len); @@ -357,6 +606,26 @@ static gboolean __request_handler(gpointer data) appid = (char *)bundle_get_val(kb, AUL_K_PKG_NAME); ret = __app_process_by_pid(pkt->cmd, appid, &cr, clifd); break; + case APP_TERM_BY_PID_WITHOUT_RESTART: + case APP_TERM_BY_PID_ASYNC: + ret = security_server_check_privilege_by_sockfd(clifd, "aul::terminate", "x"); + if(ret == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) { + _E("terminate request has been denied by smack"); + ret = -EILLEGALACCESS; + __real_send(clifd, ret); + } else { + kb = bundle_decode(pkt->data, pkt->len); + term_pid = (char *)bundle_get_val(kb, AUL_K_PKG_NAME); + appid = _status_app_get_appid_bypid(atoi(term_pid)); + ai = appinfo_find(_raf, appid); + if(ai) { + appinfo_set_value(ai, AIT_STATUS, "norestart"); + ret = __app_process_by_pid(pkt->cmd, term_pid, &cr, clifd); + } else { + ret = -1; + } + } + break; case APP_TERM_BY_PID: case APP_KILL_BY_PID: ret = security_server_check_privilege_by_sockfd(clifd, "aul::terminate", "x"); @@ -373,6 +642,9 @@ static gboolean __request_handler(gpointer data) case APP_RUNNING_INFO: _status_send_running_appinfo_v2(clifd); break; + case APP_RUNNING_INFO_MEMORY: + _status_send_running_appinfo(clifd); + break; case APP_IS_RUNNING: appid = malloc(MAX_PACKAGE_STR_SIZE); strncpy(appid, (const char*)pkt->data, MAX_PACKAGE_STR_SIZE-1); @@ -382,10 +654,15 @@ static gboolean __request_handler(gpointer data) free(appid); break; case APP_GET_APPID_BYPID: - memcpy(&pid, pkt->data, pkt->len); + memcpy(&pid, pkt->data, sizeof(int)); ret = _status_get_appid_bypid(clifd, pid); _D("APP_GET_APPID_BYPID : %d : %d", pid, ret); break; + case APP_GET_PKGID_BYPID: + memcpy(&pid, pkt->data, sizeof(int)); + ret = _status_get_pkgid_bypid(clifd, pid); + _D("APP_GET_PKGID_BYPID : %d : %d", pid, ret); + break; case APP_KEY_RESERVE: ret = _register_key_event(cr.pid); __send_result_to_client(clifd, ret); @@ -408,11 +685,11 @@ static gboolean __request_handler(gpointer data) break; case APP_RELEASED: appid = malloc(MAX_PACKAGE_STR_SIZE); - strncpy(appid, (const char*)pkt->data, MAX_PACKAGE_STR_SIZE-1); + strncpy(appid, (const char*)&pkt->data[1], MAX_PACKAGE_STR_SIZE-1); ai = appinfo_find(_raf, appid); pkg_status = appinfo_get_value(ai, AIT_STATUS); - _D("pkg_status : %s", pkg_status); - if(pkg_status && strncmp(pkg_status, "upgrading", 9) == 0) { + SECURE_LOGD("appid(%s) pkg_status(%s)", appid, pkg_status); + if(pkg_status && strncmp(pkg_status, "blocking", 8) == 0) { appinfo_set_value(ai, AIT_STATUS, "restart"); } else if (pkg_status && strncmp(pkg_status, "norestart", 9) == 0) { appinfo_set_value(ai, AIT_STATUS, "installed"); @@ -420,6 +697,10 @@ static gboolean __request_handler(gpointer data) ret = __release_srv(appid); } __send_result_to_client(clifd, ret); + ret = _status_app_is_running(appid); + SECURE_LOGI("appid(%s) dead pid(%d)", appid, ret); + if(ret > 0) + __send_app_termination_signal(ret); free(appid); break; case APP_RUNNING_LIST_UPDATE: @@ -481,12 +762,28 @@ static GSourceFuncs funcs = { .finalize = NULL }; -int _requset_init(struct amdmgr *amd) +static void __home_appid_vconf_cb(keynode_t *key, void *data) +{ + char *tmpstr; + + tmpstr = vconf_keynode_get_str(key); + if (tmpstr == NULL) { + return; + } + + if (home_appid) { + free(home_appid); + } + home_appid = strdup(tmpstr); +} + +int _request_init(struct amdmgr *amd) { int fd; int r; GPollFD *gpollfd; GSource *src; + DBusError error; fd = __create_server_sock(AUL_UTIL_PID); src = g_source_new(&funcs, sizeof(GSource)); @@ -503,7 +800,7 @@ int _requset_init(struct amdmgr *amd) r = g_source_attach(src, NULL); if (r == 0) { - /* TODO: error handle*/ + _E("fail to attach the source : %d", r); return -1; } @@ -515,6 +812,13 @@ int _requset_init(struct amdmgr *amd) _D("rua_clear_history : %d", r); + dbus_error_init(&error); + bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error); + home_appid = vconf_get_str(VCONFKEY_SETAPPL_SELECTED_PACKAGE_NAME); + if (vconf_notify_key_changed(VCONFKEY_SETAPPL_SELECTED_PACKAGE_NAME, __home_appid_vconf_cb, NULL) != 0) { + _E("Unable to register callback for VCONFKEY_SETAPPL_SELECTED_PACKAGE_NAME\n"); + } + return 0; } diff --git a/am_daemon/amd_request.h b/am_daemon/amd_request.h index 3353c7e..ca409b1 100755 --- a/am_daemon/amd_request.h +++ b/am_daemon/amd_request.h @@ -23,7 +23,7 @@ #ifndef __AUL_AMD_REQUEST_H_ #define __AUL_AMD_REQUEST_H_ -int _requset_init(struct amdmgr *amd); +int _request_init(struct amdmgr *amd); diff --git a/am_daemon/amd_status.c b/am_daemon/amd_status.c index 3143962..904c3ba 100755 --- a/am_daemon/amd_status.c +++ b/am_daemon/amd_status.c @@ -25,6 +25,12 @@ #include #include #include +#include +#include +#ifdef _APPFW_FEATURE_VISIBILITY_CHECK_BY_LCD_STATUS +#include +#include +#endif #include "amd_config.h" #include "amd_status.h" @@ -35,10 +41,31 @@ #include "menu_db_util.h" GSList *app_status_info_list = NULL; - struct appinfomgr *_saf = NULL; -int _status_add_app_info_list(char *appid, char *app_path, int pid, int pad_pid) +GHashTable *cooldown_tbl; + +GHashTable *cooldown_black_tbl; + +char *cooldown_list[] = { +}; + +char *cooldown_black_list[] = { +}; + +int cooldown_status = 0; + +#define WHITE_LIST_COUNT 0 +#define BLACK_LIST_COUNT 0 + +#ifdef _APPFW_FEATURE_VISIBILITY_CHECK_BY_LCD_STATUS +#define LCD_ON "LCDOn" +#define LCD_OFF "LCDOff" +#define PROC_SIZE 256 +#define WAKE_UP_GESTURE_CLOCK 1 +#endif + +int _status_add_app_info_list(char *appid, char *app_path, const char *caller, int pid, int pad_pid) { GSList *iter = NULL; app_status_info_t *info_t = NULL; @@ -52,8 +79,12 @@ int _status_add_app_info_list(char *appid, char *app_path, int pid, int pad_pid) } info_t = malloc(sizeof(app_status_info_t)); + memset(info_t, 0, sizeof(app_status_info_t)); + strncpy(info_t->appid, appid, MAX_PACKAGE_STR_SIZE-1); strncpy(info_t->app_path, app_path, MAX_PACKAGE_APP_PATH_SIZE-1); + if(caller) + strncpy(info_t->caller, caller, MAX_PACKAGE_STR_SIZE-1); info_t->status = STATUS_LAUNCHING; info_t->pid = pid; info_t->pad_pid = pad_pid; @@ -183,6 +214,22 @@ char* _status_app_get_appid_bypid(int pid) return NULL; } +char* _status_get_caller_by_appid(const char *appid) +{ + GSList *iter = NULL; + app_status_info_t *info_t = NULL; + + for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter)) + { + info_t = (app_status_info_t *)iter->data; + if( strncmp(appid, info_t->appid, MAX_PACKAGE_STR_SIZE-1) == 0) { + return info_t->caller; + } + } + + return NULL; +} + int _status_send_running_appinfo(int fd) { GSList *iter = NULL; @@ -355,11 +402,11 @@ int _status_get_appid_bypid(int fd, int pid) memset(pkt, 0, AUL_SOCK_MAXBUFF); - pkt->cmd = APP_GET_APPID_BYPID_ERROR; + pkt->cmd = APP_GET_INFO_ERROR; if (__get_pkgname_bypid(pid, (char *)pkt->data, MAX_PACKAGE_STR_SIZE) == 0) { SECURE_LOGD("appid for %d is %s", pid, pkt->data); - pkt->cmd = APP_GET_APPID_BYPID_OK; + pkt->cmd = APP_GET_INFO_OK; goto out; } /* support app launched by shell script*/ @@ -370,7 +417,77 @@ int _status_get_appid_bypid(int fd, int pid) _D("second change pgid = %d, pid = %d", pgid, pid); if (__get_pkgname_bypid(pgid, (char *)pkt->data, MAX_PACKAGE_STR_SIZE) == 0) - pkt->cmd = APP_GET_APPID_BYPID_OK; + pkt->cmd = APP_GET_INFO_OK; + + out: + pkt->len = strlen((char *)pkt->data) + 1; + + if ((len = send(fd, pkt, pkt->len + 8, 0)) != pkt->len + 8) { + if (errno == EPIPE) + _E("send failed due to EPIPE.\n"); + _E("send fail to client"); + } + + if(pkt) + free(pkt); + + close(fd); + + return 0; +} + +static int __get_pkgid_bypid(int pid, char *pkgid, int len) +{ + char *cmdline; + app_info_from_db *menu_info; + + cmdline = __proc_get_cmdline_bypid(pid); + if (cmdline == NULL) + return -1; + + if ((menu_info = _get_app_info_from_db_by_apppath(cmdline)) == NULL) { + free(cmdline); + return -1; + } else + snprintf(pkgid, len, "%s", _get_pkgid(menu_info)); + + free(cmdline); + _free_app_info_from_db(menu_info); + + return 0; +} + +int _status_get_pkgid_bypid(int fd, int pid) +{ + app_pkt_t *pkt = NULL; + int len; + int pgid; + + pkt = (app_pkt_t *) malloc(sizeof(char) * AUL_SOCK_MAXBUFF); + if(!pkt) { + _E("malloc fail"); + close(fd); + return 0; + } + + memset(pkt, 0, AUL_SOCK_MAXBUFF); + + pkt->cmd = APP_GET_INFO_ERROR; + + if (__get_pkgid_bypid(pid, (char *)pkt->data, MAX_PACKAGE_STR_SIZE) == 0) { + SECURE_LOGD("appid for %d is %s", pid, pkt->data); + pkt->cmd = APP_GET_INFO_OK; + goto out; + } + /* support app launched by shell script*/ + _D("second chance"); + pgid = getpgid(pid); + if (pgid <= 1) + goto out; + + _D("second change pgid = %d, pid = %d", pgid, pid); + if (__get_pkgid_bypid(pgid, (char *)pkt->data, MAX_PACKAGE_STR_SIZE) == 0) + pkt->cmd = APP_GET_INFO_OK; out: pkt->len = strlen((char *)pkt->data) + 1; @@ -389,11 +506,223 @@ int _status_get_appid_bypid(int fd, int pid) return 0; } +static void __app_info_iter_limit_cb(void *user_data, const char *appid, const struct appinfo *ai) +{ + if(!g_hash_table_lookup(cooldown_tbl, appid)) { + appinfo_set_value(ai, AIT_STATUS, "blocking"); + } +} + +static void __app_info_iter_waring_cb(void *user_data, const char *appid, const struct appinfo *ai) +{ + if(g_hash_table_lookup(cooldown_black_tbl, appid)) { + appinfo_set_value(ai, AIT_STATUS, "blocking"); + } +} + +static void __app_info_iter_release_cb(void *user_data, const char *appid, const struct appinfo *ai) +{ + const char *component = NULL; + int onboot = 0; + int restart = 0; + + if(!g_hash_table_lookup(cooldown_tbl, appid)) { + component = appinfo_get_value(ai, AIT_COMPTYPE); + onboot = appinfo_get_boolean(ai, AIT_ONBOOT); + restart = appinfo_get_boolean(ai, AIT_RESTART); + if (onboot == 1 && restart == 1 && strncmp(component, "svcapp", 6) == 0) + { + if (_status_app_is_running(appid) < 0) + { + _I("start service (cooldown release) - %s", appid); + _start_srv(ai, NULL); + } + else + { + _E("service: %s is already running", appid); + } + } + appinfo_set_value(ai, AIT_STATUS, "installed"); + } +} + + + +static int __cooldown_cb(const char* status, void *data) +{ + GSList *iter = NULL; + app_status_info_t *info_t = NULL; + int ret; + int dummy; + + _I("__cooldown_cb, status: %s", status); + + if(strncmp(status, "LimitAction", 11) == 0) { + appinfo_foreach(_saf, __app_info_iter_limit_cb, NULL); + for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter)) + { + info_t = (app_status_info_t *)iter->data; + if(!g_hash_table_lookup(cooldown_tbl, info_t->appid)) { + proc_group_change_status(PROC_CGROUP_SET_TERMINATE_REQUEST, info_t->pid, NULL); + ret = __app_send_raw_with_noreply(info_t->pid, APP_TERM_BY_PID_ASYNC, (unsigned char *)&dummy, sizeof(int) ); + } + } + cooldown_status = COOLDOWN_LIMIT; + } else if(strncmp(status, "WarningAction", 13) == 0) { + appinfo_foreach(_saf, __app_info_iter_waring_cb, NULL); + for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter)) + { + info_t = (app_status_info_t *)iter->data; + if(g_hash_table_lookup(cooldown_black_tbl, info_t->appid)) { + proc_group_change_status(PROC_CGROUP_SET_TERMINATE_REQUEST, info_t->pid, NULL); + ret = __app_send_raw_with_noreply(info_t->pid, APP_TERM_BY_PID_ASYNC, (unsigned char *)&dummy, sizeof(int) ); + } + } + cooldown_status = COOLDOWN_WARNING; + } else if (strncmp(status, "Release", 7) == 0){ + appinfo_foreach(_saf, __app_info_iter_release_cb, NULL); + cooldown_status = COOLDOWN_RELEASE; + } + + return 0; +} + +int _status_get_cooldown_status(void) +{ + return cooldown_status; +} + +#ifdef _APPFW_FEATURE_VISIBILITY_CHECK_BY_LCD_STATUS +static int __lcd_status_cb(const char *lcd_status, void *data) +{ + int gesture = -1; + Ecore_X_Window win; + int pid = 0; + bundle *kb = NULL; + char proc_file[PROC_SIZE] = {0, }; + static int paused_pid = 0; + + // Check the wake-up gesture is a clock or not. + // 0: Off, 1: Clock, 2: Last viewed screen + if (vconf_get_int(VCONFKEY_WMS_WAKEUP_BY_GESTURE_SETTING, &gesture) < 0) { + _E("Failed to get VCONFKEY_WMS_WAKEUP_BY_GESTURE_SETTING"); + return 0; + } + + if (gesture == WAKE_UP_GESTURE_CLOCK) { + SECURE_LOGD("Skip when wake-up gesture is a Clock."); + return 0; + } + + // Get the topmost app + win = ecore_x_window_focus_get(); + if (ecore_x_netwm_pid_get(win, &pid) != 1) { + _E("Can't get pid for focus x window (%x)", win); + return 0; + } + SECURE_LOGD("The topmost app's pid is %d.", pid); + + // Pause or Resume the app when the lcd becomes On/Off + if (lcd_status && (strncmp(lcd_status, LCD_OFF, strlen(LCD_OFF)) == 0)) { + SECURE_LOGD("LCD status becomes Off. Pause the topmose app, %d", pid); + paused_pid = pid; + kb = bundle_create(); + app_send_cmd_with_noreply(pid, APP_PAUSE_LCD_OFF, kb); + } + else if (lcd_status && (strncmp(lcd_status, LCD_ON, strlen(LCD_ON)) == 0)) { + if (paused_pid != pid) { + SECURE_LOGE("The topmost app(%d) is different with the paused app(%d).", pid, paused_pid); + } + + // Check whether the paused app is running or Not + snprintf(proc_file, PROC_SIZE, "/proc/%d/cmdline", paused_pid); + if (access(proc_file, F_OK) != 0) { + SECURE_LOGE("paused app(%d) seems to be killed.", paused_pid); + if (paused_pid != pid) { + paused_pid = pid; + } else { + return 0; + } + } + + SECURE_LOGD("LCD status becomes On. Resume the paused app, %d", paused_pid); + kb = bundle_create(); + app_send_cmd_with_noreply(paused_pid, APP_RESUME_LCD_ON, kb); + } + else { + _E("Invalid input param for lcd_status."); + } + + bundle_free(kb); + return 0; +} +#endif + +static int __app_info_handler (const pkgmgrinfo_appinfo_h handle, void *data) +{ + char *tmp_appid; + char *appid; + + pkgmgrinfo_appinfo_get_appid(handle, &tmp_appid); + + appid = strdup(tmp_appid); + + g_hash_table_insert(cooldown_tbl, appid, appid); + + SECURE_LOGD("white_list : %s", appid); + + return 0; +} + +static int __blacklist_app_info_handler (const pkgmgrinfo_appinfo_h handle, void *data) +{ + char *tmp_appid; + char *appid; + + pkgmgrinfo_appinfo_get_appid(handle, &tmp_appid); + + appid = strdup(tmp_appid); + + g_hash_table_insert(cooldown_black_tbl, appid, appid); + + SECURE_LOGD("white_list : %s", appid); + + return 0; +} int _status_init(struct amdmgr* amd) { + int i; + pkgmgrinfo_appinfo_h handle = NULL; + _saf = amd->af; + aul_listen_cooldown_signal(__cooldown_cb, NULL); + + cooldown_tbl = g_hash_table_new(g_str_hash, g_str_equal); + for(i = 0; i < WHITE_LIST_COUNT; i++) { + SECURE_LOGD("pkgid %s", cooldown_list[i]); + if (pkgmgrinfo_pkginfo_get_pkginfo(cooldown_list[i], &handle) == PMINFO_R_OK){ + pkgmgrinfo_appinfo_get_list(handle, PMINFO_SVC_APP, __app_info_handler, NULL); + pkgmgrinfo_appinfo_get_list(handle, PMINFO_UI_APP, __app_info_handler, NULL); + pkgmgrinfo_pkginfo_destroy_pkginfo(handle); + } + } + + cooldown_black_tbl = g_hash_table_new(g_str_hash, g_str_equal); + for(i = 0; i < BLACK_LIST_COUNT; i++) { + SECURE_LOGD("pkgid %s", cooldown_black_list[i]); + if (pkgmgrinfo_pkginfo_get_pkginfo(cooldown_black_list[i], &handle) == PMINFO_R_OK){ + pkgmgrinfo_appinfo_get_list(handle, PMINFO_SVC_APP, __blacklist_app_info_handler, NULL); + pkgmgrinfo_appinfo_get_list(handle, PMINFO_UI_APP, __blacklist_app_info_handler, NULL); + pkgmgrinfo_pkginfo_destroy_pkginfo(handle); + } + } + +#ifdef _APPFW_FEATURE_VISIBILITY_CHECK_BY_LCD_STATUS + // Register callback for LCD On/Off + aul_listen_lcd_status_signal(__lcd_status_cb, NULL); +#endif return 0; } diff --git a/am_daemon/amd_status.h b/am_daemon/amd_status.h index 157d749..d8fa74f 100755 --- a/am_daemon/amd_status.h +++ b/am_daemon/amd_status.h @@ -21,7 +21,7 @@ -int _status_add_app_info_list(char *appid, char *app_path, int pid, int pad_pid); +int _status_add_app_info_list(char *appid, char *app_path,const char *caller, int pid, int pad_pid); int _status_update_app_info_list(int pid, int status); int _status_remove_app_info_list(int pid); int _status_get_app_info_status(int pid); @@ -30,7 +30,9 @@ int _status_send_running_appinfo(int fd); int _status_app_is_running_v2(char *appid); int _status_send_running_appinfo_v2(int fd); int _status_get_appid_bypid(int fd, int pid); - +int _status_get_pkgid_bypid(int fd, int pid); +char* _status_get_caller_by_appid(const char *appid); +int _status_get_cooldown_status(void); @@ -41,7 +43,13 @@ typedef struct _item_pkt_t { char appid[512]; } item_pkt_t; +#ifdef _APPFW_FEATURE_BG_PROCESS_LIMIT gboolean __add_item_running_list(gpointer user_data); +#endif - +enum cooldown_status_val { + COOLDOWN_RELEASE, + COOLDOWN_WARNING, + COOLDOWN_LIMIT, +}; diff --git a/aul-mobile.manifest b/aul-mobile.manifest deleted file mode 100644 index 08d812c..0000000 --- a/aul-mobile.manifest +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/aul-wearable.manifest b/aul.manifest similarity index 91% rename from aul-wearable.manifest rename to aul.manifest index 0bf756f..979caa3 100644 --- a/aul-wearable.manifest +++ b/aul.manifest @@ -5,7 +5,6 @@ -