ENDIF()
MESSAGE("Build type: ${CMAKE_BUILD_TYPE}")
-
# Set required packages
INCLUDE(FindPkgConfig)
-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")
+SET(pkgs_requires "dlog ecore x11 libprivilege-control rua glib-2.0 ecore-x ecore-evas iniparser ecore-input evas vconf pkgmgr-info libresourced security-server ttrace appfw-env cert-svc")
+SET(libpkgs_requires "dlog bundle dbus-glib-1 ecore-x xdgmime libsmack ecore pkgmgr-info iniparser ttrace vasum vconf capi-system-info")
IF(_APPFW_FEATURE_APP_CHECKER)
SET(pkgs_requires "${pkgs_requires} app-checker app-checker-server")
# Compiler flags
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/legacy)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/feature)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/delegator)
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wl,-zdefs" )
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fpic")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall -Werror -Wno-unused-function")
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fdata-sections -ffunction-sections -Wl,--gc-sections")
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -D_FILE_OFFSET_BITS=64")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
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_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_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)
+IF(_APPFW_FEATURE_COOLDOWN_MODE_SUPPORT)
+ ADD_DEFINITIONS("-D_APPFW_FEATURE_COOLDOWN_MODE_SUPPORT")
+ENDIF(_APPFW_FEATURE_COOLDOWN_MODE_SUPPORT)
+IF(_APPFW_FEATURE_AMD_MODULE_LOG)
+ ADD_DEFINITIONS("-D_APPFW_FEATURE_AMD_MODULE_LOG")
+ENDIF(_APPFW_FEATURE_AMD_MODULE_LOG)
+IF(_APPFW_FEATURE_EXPANSION_PKG_INSTALL)
+ ADD_DEFINITIONS("-D_APPFW_FEATURE_EXPANSION_PKG_INSTALL")
+ENDIF(_APPFW_FEATURE_EXPANSION_PKG_INSTALL)
+IF(_APPFW_FEATURE_BACKGROUND_MANAGEMENT)
+ ADD_DEFINITIONS("-D_APPFW_FEATURE_BACKGROUND_MANAGEMENT")
+ENDIF(_APPFW_FEATURE_BACKGROUND_MANAGEMENT)
+IF(_APPFW_FEATURE_AMD_KEY)
+ ADD_DEFINITIONS("-D_APPFW_FEATURE_AMD_KEY")
+ENDIF(_APPFW_FEATURE_AMD_KEY)
+IF(_APPFW_FEATURE_MMC_SUPPORT)
+ ADD_DEFINITIONS("-D_APPFW_FEATURE_MMC_SUPPORT")
+ENDIF(_APPFW_FEATURE_MMC_SUPPORT)
+IF(_APPFW_FEATURE_SEND_HOME_LAUNCH_SIGNAL)
+ ADD_DEFINITIONS("-D_APPFW_FEATURE_SEND_HOME_LAUNCH_SIGNAL")
+ENDIF(_APPFW_FEATURE_SEND_HOME_LAUNCH_SIGNAL)
+IF(_APPFW_FEATURE_FAKE_EFFECT)
+ ADD_DEFINITIONS("-D_APPFW_FEATURE_FAKE_EFFECT")
+ENDIF(_APPFW_FEATURE_FAKE_EFFECT)
+IF(_APPFW_FEATURE_EFFECTIVE_APPID)
+ ADD_DEFINITIONS("-D_APPFW_FEATURE_EFFECTIVE_APPID")
+ENDIF(_APPFW_FEATURE_EFFECTIVE_APPID)
+IF(_APPFW_FEATURE_PRIVATE_SERVICE)
+ ADD_DEFINITIONS("-D_APPFW_FEATURE_PRIVATE_SERVICE")
+ENDIF(_APPFW_FEATURE_PRIVATE_SERVICE)
+IF(_APPFW_FEATURE_TERMINATE_UNMANAGEABLE_APP)
+ ADD_DEFINITIONS("-D_APPFW_FEATURE_TERMINATE_UNMANAGEABLE_APP")
+ENDIF(_APPFW_FEATURE_TERMINATE_UNMANAGEABLE_APP)
# Linker flags
SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
### Build ###
+add_subdirectory(delegator)
# aul_mods : modules (static library)
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
src/launch_glib.c
src/launch_with_result.c
src/service.c
+ src/service_db.c
src/mime.c
src/miregex.c
src/app_signal.c
src/status.c
src/runtime_info.c
src/aul_path.c
+ src/app_group.c
+ src/zone.c
+ src/aul_rsc_mgr.c
)
target_link_libraries(aul aul_mods ${libpkgs_LDFLAGS})
+TARGET_LINK_LIBRARIES(aul aul-delegator-client)
+TARGET_LINK_LIBRARIES(aul "-ldl -lsqlite3")
SET_TARGET_PROPERTIES(aul PROPERTIES SOVERSION ${VERSION_MAJOR})
SET_TARGET_PROPERTIES(aul PROPERTIES VERSION ${VERSION})
-# launchpad(old avatar) daemon
-SET(AVATAR_NAME "launchpad_preloading_preinitializing_daemon")
-add_executable(${AVATAR_NAME}
- launchpad_src/launchpad.c
- )
-
-MESSAGE(" "${pkgs_LDFLAGS})
-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.
-
add_executable(amd
am_daemon/amd_main.c
am_daemon/amd_key.c
am_daemon/amd_request.c
am_daemon/amd_appinfo.c
- am_daemon/amd_cgutil.c
am_daemon/amd_launch.c
am_daemon/amd_status.c
+ am_daemon/amd_app_group.c
)
-target_link_libraries(amd aul_mods rua glib-2.0 bundle ail aul utilX ${pkgs_LDFLAGS} "-pie")
-
-SET(REL_AGENT daemon-manager-release-agent)
-ADD_EXECUTABLE(${REL_AGENT} agent/${REL_AGENT}.c)
-TARGET_LINK_LIBRARIES(${REL_AGENT} ${PKGS_LDFLAGS} "-pie" aul aul_mods)
-SET_TARGET_PROPERTIES(${REL_AGENT} PROPERTIES COMPILE_FLAGS "${EXTRA_CFLAGS} -fPIE")
-
-INSTALL(TARGETS ${REL_AGENT} DESTINATION bin)
-
-SET(LAUNCH_AGENT daemon-manager-launch-agent)
-ADD_EXECUTABLE(${LAUNCH_AGENT} agent/${LAUNCH_AGENT}.c)
-TARGET_LINK_LIBRARIES(${LAUNCH_AGENT} ${PKGS_LDFLAGS} "-pie")
-SET_TARGET_PROPERTIES(${LAUNCH_AGENT} PROPERTIES COMPILE_FLAGS "${EXTRA_CFLAGS} -fPIE")
-
-INSTALL(TARGETS ${LAUNCH_AGENT} DESTINATION bin)
-
-
+IF(_APPFW_FEATURE_AMD_KEY)
+ TARGET_LINK_LIBRARIES(amd utilX)
+ENDIF(_APPFW_FEATURE_AMD_KEY)
+target_link_libraries(amd aul_mods rua glib-2.0 bundle pkgmgr-info aul ${pkgs_LDFLAGS} "-pie")
+TARGET_LINK_LIBRARIES(amd "-ldl")
+
+# appgroup info tool
+ADD_EXECUTABLE(appgroup_info tool/app_group_info.c)
+SET_TARGET_PROPERTIES(appgroup_info PROPERTIES COMPILE_FLAGS "${EXTRA_CFLAGS} -fPIE")
+TARGET_LINK_LIBRARIES(appgroup_info aul_mods aul ${pkgs_LDFLAGS} "-pie")
+INSTALL(TARGETS appgroup_info DESTINATION bin)
# pkgconfig file
CONFIGURE_FILE(aul.pc.in aul.pc @ONLY)
### Install ###
INSTALL(TARGETS aul DESTINATION lib COMPONENT RuntimeLibraries)
-INSTALL(TARGETS ${AVATAR_NAME} 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_svc.h DESTINATION include/aul)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/aul_zone.h DESTINATION include/aul)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/aul_rsc_mgr.h DESTINATION include/aul)
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}/feature/preexec_list.txt DESTINATION /usr/share/aul )
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/miregex DESTINATION /usr/share/aul )
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}/include/app_launchpad_types.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)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/appsvc_db.sql DESTINATION /opt/share )
+
+IF(_APPFW_FEATURE_AMD_MODULE_LOG)
+ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/amd_log_dump.sh DESTINATION /opt/etc/dump.d/module.d)
+ENDIF(_APPFW_FEATURE_AMD_MODULE_LOG)
# test
add_subdirectory(test)
-
+++ /dev/null
-
-STRING(REPLACE ";" " " EXTRA_CFLAGS "${PKGS_CFLAGS}")
-
-SET(REL_AGENT daemon-manager-release-agent)
-ADD_EXECUTABLE(${REL_AGENT} ${REL_AGENT}.c)
-TARGET_LINK_LIBRARIES(${REL_AGENT} ${PKGS_LDFLAGS})
-SET_TARGET_PROPERTIES(${REL_AGENT} PROPERTIES COMPILE_FLAGS "${EXTRA_CFLAGS}")
-
-INSTALL(TARGETS ${REL_AGENT} DESTINATION bin)
-
-SET(LAUNCH_AGENT daemon-manager-launch-agent)
-ADD_EXECUTABLE(${LAUNCH_AGENT} ${LAUNCH_AGENT}.c)
-TARGET_LINK_LIBRARIES(${LAUNCH_AGENT} ${PKGS_LDFLAGS})
-SET_TARGET_PROPERTIES(${LAUNCH_AGENT} PROPERTIES COMPILE_FLAGS "${EXTRA_CFLAGS}")
-
-INSTALL(TARGETS ${LAUNCH_AGENT} DESTINATION bin)
+++ /dev/null
-#include <glib.h>
-#include <gio/gio.h>
-#include <stdio.h>
-#include <stdarg.h>
-
-#define DAEMON_MANAGER_NAME "org.tizen.DaemonManager"
-#define DAEMON_MANAGER_PATH "/org/tizen/DaemonManager"
-#define DAEMON_MANAGER_INTERFACE "org.tizen.DaemonManager"
-
-#define METHOD_RELEASED "Start"
-
-#define BUS_TYPE G_BUS_TYPE_SYSTEM
-
-#define LOG_PATH "/tmp/dmlaunch.err"
-
-static void elog(const char *fmt, ...)
-{
- FILE *fp;
- va_list ap;
-
- fp = fopen(LOG_PATH, "w+");
- if (!fp)
- return;
-
- va_start(ap, fmt);
- vfprintf(fp, fmt, ap);
- va_end(ap);
-
- fclose(fp);
-}
-
-int main(int argc, char *argv[])
-{
- GError *err;
- GDBusProxy *proxy = NULL;
- GDBusConnection *conn = NULL;
- GVariant *res = NULL;
-
- if (argc < 2) {
- elog("usage) %s path\n", argv[0]);
- return 1;
- }
-
- g_type_init();
-
- /* TODO: use private bus? */
- err = NULL;
- conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
- if (!conn) {
- elog("Connection failed: %s\n", err ? err->message : "");
- goto err;
- }
-
- err = NULL;
- proxy = g_dbus_proxy_new_sync(conn,
- G_DBUS_PROXY_FLAGS_NONE,
- NULL,
- DAEMON_MANAGER_NAME,
- DAEMON_MANAGER_PATH,
- DAEMON_MANAGER_INTERFACE,
- NULL,
- &err);
- if (!proxy) {
- elog("Proxy new: %s\n", err ? err->message : "");
- goto err;
- }
-
- err = NULL;
- res = g_dbus_proxy_call_sync(proxy,
- METHOD_RELEASED,
- g_variant_new("(s)", argv[1]),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &err);
- if (!res) {
- elog("Call error: %s\n", err ? err->message : "");
- goto err;
- }
-
-err:
- if (res)
- g_variant_unref(res);
-
- if (proxy)
- g_object_unref(proxy);
-
- if (conn)
- g_object_unref(conn);
-
- if (err) {
- g_clear_error(&err);
- return 1;
- }
-
- return 0;
-}
-
+++ /dev/null
-#include <stdio.h>
-#include <string.h>
-#include <stdarg.h>
-#include "app_sock.h"
-#include "aul_util.h"
-
-#define LOG_PATH "/tmp/dmlaunch.err"
-
-static void elog(const char *fmt, ...)
-{
- FILE *fp;
- va_list ap;
-
- fp = fopen(LOG_PATH, "w+");
- if (!fp)
- return;
-
- va_start(ap, fmt);
- vfprintf(fp, fmt, ap);
- va_end(ap);
-
- fclose(fp);
-}
-
-
-int main(int argc, char *argv[])
-{
- int ret = 0;
-
- elog("release agent : [%d:%s]\n", argc, argv[1]);
-
- if (argc < 2) {
- elog("usage) %s path\n", argv[0]);
- return 1;
- }
-
- ret = __app_send_raw(AUL_UTIL_PID, APP_RELEASED, (unsigned char*)argv[1], strlen(argv[1]));
-
- elog("release agent : %d\n", ret);
-
- return 0;
-}
-
+++ /dev/null
-/*
- * aul
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <stdlib.h>
-#include <glib.h>
-#include <aul.h>
-#include "aul_util.h"
-#include "simple_util.h"
-
-GSList *app_status_info_list = NULL;
-
-int _add_app_status_info_list(char *appid, int pid)
-{
- 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(pid == info_t->pid) {
- return 0;
- }
- }
-
- info_t = malloc(sizeof(app_status_info_t));
- strncpy(info_t->appid, appid, MAX_PACKAGE_STR_SIZE-1);
- info_t->status = STATUS_LAUNCHING;
- info_t->pid = pid;
- app_status_info_list = g_slist_append(app_status_info_list, info_t);
-
- for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
- {
- info_t = (app_status_info_t *)iter->data;
-
- _D("%s, %d, %d", info_t->appid, info_t->pid, info_t->status);
- }
-
- return 0;
-}
-
-int _update_app_status_info_list(int pid, int status)
-{
- 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(pid == info_t->pid) {
- info_t->status = status;
- break;
- }
- }
-
- for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
- {
- info_t = (app_status_info_t *)iter->data;
-
- _D("%s, %d, %d", info_t->appid, info_t->pid, info_t->status);
- }
-
- return 0;
-}
-
-int _remove_app_status_info_list(int pid)
-{
- 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(pid == info_t->pid) {
- app_status_info_list = g_slist_remove(app_status_info_list, info_t);
- free(info_t);
- break;
- }
- }
-
- for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
- {
- info_t = (app_status_info_t *)iter->data;
-
- _D("%s, %d, %d", info_t->appid, info_t->pid, info_t->status);
- }
-
- return 0;
-}
-
--- /dev/null
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <glib.h>
+#include <aul.h>
+#include <aul_svc.h>
+#include <Ecore_X.h>
+#include <bundle_internal.h>
+
+#include "app_sock.h"
+#include "simple_util.h"
+#include "amd_app_group.h"
+#include "amd_launch.h"
+#include "amd_request.h"
+#include "amd_status.h"
+#include "app_signal.h"
+#include "amd_appinfo.h"
+
+#define APP_SVC_K_LAUNCH_MODE "__APP_SVC_LAUNCH_MODE__"
+
+static GHashTable *app_group_hash = NULL;
+static int dead_pid = -1;
+static int focused_leader_pid = -1;
+static GList *recycle_bin = NULL;
+
+extern struct appinfomgr *_laf;
+extern char *home_appid;
+
+typedef struct _app_group_context_t {
+ int pid;
+ int wid;
+ int status;
+ int fg;
+ int group_sig;
+ int can_be_leader;
+ int reroute;
+ int caller_pid;
+ int can_shift;
+ int recycle;
+ app_group_launch_mode launch_mode;
+} app_group_context_t;
+
+static void __attach_window(int parent_wid, int child_wid)
+{
+ ecore_x_icccm_transient_for_set(child_wid, parent_wid);
+}
+
+static void __detach_window(int child_wid)
+{
+ ecore_x_icccm_transient_for_unset(child_wid);
+}
+
+static gint __comp_pid(gconstpointer a, gconstpointer b)
+{
+ app_group_context_t *ac1 = (app_group_context_t*) a;
+
+ return ac1->pid - (int)b;
+}
+
+static void __list_destroy_cb(gpointer data)
+{
+ free(data);
+}
+
+static gboolean __hash_table_cb(gpointer key, gpointer value,
+ gpointer user_data)
+{
+ int pid = (int) user_data;
+ GList *list = (GList*) value;
+ GList *itr = g_list_first(list);
+
+ while (itr != NULL) {
+ app_group_context_t *ac = (app_group_context_t*) itr->data;
+
+ if (ac->pid == pid) {
+ free(ac);
+ list = g_list_remove_link(list, itr);
+ if (g_list_length(list) == 0) {
+ g_list_free_full(list, __list_destroy_cb);
+ return TRUE;
+ } else
+ return FALSE;
+ }
+ itr = g_list_next(itr);
+ }
+
+ return FALSE;
+}
+
+static GList* __find_removable_apps(int from)
+{
+ int cnt;
+ int *pids = NULL;
+ GList *list = NULL;
+ gboolean found = FALSE;
+
+ app_group_get_leader_pids(&cnt, &pids);
+
+ int i, j;
+
+ for (i = 0; i < cnt; i++) {
+ int *gpids = NULL;
+ int gcnt;
+
+ app_group_get_group_pids(pids[i], &gcnt, &gpids);
+ for (j = 0; j < gcnt; j++) {
+ if (gpids[j] == from) {
+ found = TRUE;
+ continue;
+ }
+
+ if (found) {
+ list = g_list_append(list, (gpointer) gpids[j]);
+ }
+ }
+
+ if (gpids != NULL)
+ free(gpids);
+
+ if (found)
+ break;
+ }
+
+ if (pids != NULL)
+ free(pids);
+
+ return list;
+}
+
+static void __prepare_to_suspend_services(int pid)
+{
+ int dummy;
+ SECURE_LOGD("[__SUSPEND__] pid: %d", pid);
+ __app_send_raw_with_noreply(pid, APP_SUSPEND, (unsigned char *)&dummy, sizeof(int));
+}
+
+static void __prepare_to_wake_services(int pid)
+{
+ int dummy;
+ SECURE_LOGD("[__SUSPEND__] pid: %d", pid);
+ __app_send_raw_with_noreply(pid, APP_WAKE, (unsigned char *)&dummy, sizeof(int));
+}
+
+static void __set_fg_flag(int cpid, int flag, gboolean force)
+{
+ int lpid = app_group_get_leader_pid(cpid);
+ GHashTableIter iter;
+ gpointer key, value;
+
+ g_hash_table_iter_init(&iter, app_group_hash);
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
+ GList *list = (GList*) value;
+ GList *i = g_list_first(list);
+ app_group_context_t *ac = (app_group_context_t*) i->data;
+
+ if (ac->pid == lpid) {
+
+ while (i != NULL) {
+ ac = (app_group_context_t*) i->data;
+
+ if (ac->fg != flag || force == TRUE) {
+ const char *appid = NULL;
+ const char *pkgid = NULL;
+ const struct appinfo *ai = NULL;
+
+ appid = _status_app_get_appid_bypid(ac->pid);
+ ai = appinfo_find(_laf, appid);
+ pkgid = appinfo_get_value(ai, AIT_PKGID);
+
+ if (flag) {
+ _D("send_signal FG %s", appid);
+
+ aul_send_app_status_change_signal(ac->pid, appid,
+ pkgid,
+ STATUS_FOREGROUND,
+ APP_TYPE_UI);
+ _status_find_service_apps(ac->pid, STATUS_VISIBLE, __prepare_to_wake_services);
+ } else {
+ _D("send_signal BG %s", appid);
+ aul_send_app_status_change_signal(ac->pid, appid,
+ pkgid,
+ STATUS_BACKGROUND,
+ APP_TYPE_UI);
+ _status_find_service_apps(ac->pid, STATUS_BG, __prepare_to_suspend_services);
+ }
+ ac->fg = flag;
+ }
+ i = g_list_next(i);
+ }
+ break;
+ }
+ }
+}
+
+static gboolean __is_visible(int cpid)
+{
+ int lpid = app_group_get_leader_pid(cpid);
+ GHashTableIter iter;
+ gpointer key, value;
+
+ g_hash_table_iter_init(&iter, app_group_hash);
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
+ GList *list = (GList*) value;
+ GList *i = g_list_first(list);
+ app_group_context_t *ac = (app_group_context_t*) i->data;
+
+ if (ac->pid == lpid) {
+ while (i != NULL) {
+ ac = (app_group_context_t*) i->data;
+
+ if (ac->status == STATUS_VISIBLE)
+ return TRUE;
+
+ i = g_list_next(i);
+ }
+ break;
+ }
+ }
+
+ return FALSE;
+}
+
+static gboolean __can_attach_window(bundle *b, const char *appid, app_group_launch_mode *launch_mode)
+{
+ char *str = NULL;
+ const char *mode = NULL;
+ const struct appinfo *ai = NULL;
+
+ ai = appinfo_find(_laf, appid);
+ mode = appinfo_get_value(ai, AIT_LAUNCH_MODE);
+
+ if (mode == NULL)
+ *launch_mode = APP_GROUP_LAUNCH_MODE_SINGLE;
+ else if (strcmp(mode, "caller") == 0)
+ *launch_mode = APP_GROUP_LAUNCH_MODE_CALLER;
+ else if (strcmp(mode, "single") == 0)
+ *launch_mode = APP_GROUP_LAUNCH_MODE_SINGLE;
+ else if (strcmp(mode, "group") == 0)
+ *launch_mode = APP_GROUP_LAUNCH_MODE_GROUP;
+ else if (strcmp(mode, "singleton") == 0)
+ *launch_mode = APP_GROUP_LAUNCH_MODE_SINGLETON;
+
+ switch (*launch_mode) {
+ case APP_GROUP_LAUNCH_MODE_CALLER:
+ case APP_GROUP_LAUNCH_MODE_SINGLETON:
+ _D("launch mode from db is caller or singleton");
+
+ bundle_get_str(b, APP_SVC_K_LAUNCH_MODE, &str);
+ if (str != NULL && strncmp(str, "group", 5) == 0) {
+ return TRUE;
+ }
+ break;
+
+ case APP_GROUP_LAUNCH_MODE_GROUP:
+ return TRUE;
+
+ case APP_GROUP_LAUNCH_MODE_SINGLE:
+ return FALSE;
+ }
+
+ return FALSE;
+}
+
+static gboolean __can_be_leader(bundle *b)
+{
+ char *str = NULL;
+
+ bundle_get_str(b, AUL_SVC_K_CAN_BE_LEADER, &str);
+
+ if (str != NULL && strcmp(str, "true") == 0)
+ return TRUE;
+
+ return FALSE;
+}
+
+static int __get_previous_pid(int pid)
+{
+ GHashTableIter iter;
+ gpointer key, value;
+
+ g_hash_table_iter_init(&iter, app_group_hash);
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
+ GList *list = (GList*) value;
+ GList *i = g_list_first(list);
+
+ int previous_pid = -1;
+ while (i != NULL) {
+ app_group_context_t *ac = (app_group_context_t*) i->data;
+
+ if (ac->pid == pid) {
+ return previous_pid;
+ }
+ previous_pid = ac->pid;
+ i = g_list_next(i);
+ }
+ }
+
+ return -1;
+}
+
+static int __get_caller_pid(bundle *kb)
+{
+ const char *pid_str;
+ int pid;
+
+ pid_str = bundle_get_val(kb, AUL_K_ORG_CALLER_PID);
+ if(pid_str)
+ goto end;
+
+ pid_str = bundle_get_val(kb, AUL_K_CALLER_PID);
+ if (pid_str == NULL)
+ return -1;
+
+end:
+ pid = atoi(pid_str);
+ if (pid <= 1)
+ return -1;
+
+ return pid;
+}
+
+static app_group_context_t* __detach_context_from_recycle_bin(int pid)
+{
+ GList *iter = recycle_bin;
+
+ while (iter) {
+ app_group_context_t *ac = (app_group_context_t*) iter->data;
+
+ if (ac->pid == pid) {
+ recycle_bin = g_list_remove_link(recycle_bin, iter);
+ return ac;
+ }
+
+ iter = g_list_next(iter);
+ }
+
+ return NULL;
+
+}
+
+static void __group_add(int leader_pid, int pid, int wid, app_group_launch_mode mode,
+ int caller_pid, int can_shift, int recycle)
+{
+ app_group_context_t *ac = NULL;
+
+ if ((ac = __detach_context_from_recycle_bin(pid)) == NULL) {
+ ac = malloc(sizeof(app_group_context_t));
+
+ if (ac == NULL) {
+ _E("out of memory");
+ return;
+ }
+ ac->pid = pid;
+ ac->wid = wid;
+ ac->fg = 0;
+ ac->can_be_leader = 0;
+ ac->reroute = 0;
+ ac->launch_mode = mode;
+ ac->caller_pid = caller_pid;
+ ac->can_shift = can_shift;
+ ac->recycle = recycle;
+ }
+
+ if (leader_pid == pid || ac->recycle)
+ ac->group_sig = 1;
+ else
+ ac->group_sig = 0;
+
+ dead_pid = -1;
+
+ GList *list = (GList*) g_hash_table_lookup(app_group_hash,
+ GINT_TO_POINTER(leader_pid));
+ if (list != NULL) {
+ if (g_list_find_custom(list, (gconstpointer)pid, __comp_pid) != NULL) {
+ _E("pid exist");
+ free(ac);
+ return;
+ }
+ }
+
+ list = g_list_append(list, ac);
+ g_hash_table_insert(app_group_hash, GINT_TO_POINTER(leader_pid), list);
+
+ if (ac->wid != 0)
+ app_group_set_window(pid, ac->wid);
+}
+
+static void __group_remove(int pid)
+{
+ int ppid = __get_previous_pid(pid);
+ g_hash_table_foreach_remove(app_group_hash, __hash_table_cb,
+ GINT_TO_POINTER(pid));
+
+ if (ppid != -1) {
+ app_group_set_status(ppid, -1, FALSE);
+ }
+}
+
+static app_group_context_t* __get_context(int pid)
+{
+ GHashTableIter iter;
+ gpointer key, value;
+
+ g_hash_table_iter_init(&iter, app_group_hash);
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
+ GList *list = (GList*) value;
+ GList *i = g_list_first(list);
+
+ while (i != NULL) {
+ app_group_context_t *ac = (app_group_context_t*) i->data;
+
+ if (ac->pid == pid) {
+ return ac;
+ }
+ i = g_list_next(i);
+ }
+ }
+
+ return NULL;
+}
+
+static int __can_recycle(int pid)
+{
+ app_group_context_t *context = __get_context(pid);
+
+ if (context)
+ return context->recycle;
+
+ return 0;
+}
+
+static int __can_reroute(int pid)
+{
+ app_group_context_t *context = __get_context(pid);
+
+ if (context)
+ return context->reroute;
+
+ return 0;
+}
+
+static app_group_context_t* __context_dup(const app_group_context_t *context)
+{
+ app_group_context_t* dup;
+
+ if (!context) {
+ _E("context is NULL.");
+ return NULL;
+ }
+
+ dup = malloc(sizeof(app_group_context_t));
+ if (!dup) {
+ _E("out of memory");
+ return NULL;
+ }
+
+ memcpy(dup, context, sizeof(app_group_context_t));
+ return dup;
+}
+
+static void __do_recycle(app_group_context_t *context)
+{
+ if (context->fg) {
+ const char *appid = NULL;
+ const char *pkgid = NULL;
+ const struct appinfo *ai = NULL;
+
+ appid = _status_app_get_appid_bypid(context->pid);
+ ai = appinfo_find(_laf, appid);
+ pkgid = appinfo_get_value(ai, AIT_PKGID);
+
+ _D("send_signal BG %s", appid);
+ aul_send_app_status_change_signal(context->pid, appid, pkgid,
+ STATUS_BACKGROUND,
+ APP_TYPE_UI);
+ _status_find_service_apps(context->pid, STATUS_BG, __prepare_to_suspend_services);
+ context->fg = 0;
+ }
+ recycle_bin = g_list_append(recycle_bin, context);
+ _revoke_temporary_permission(context->pid);
+}
+
+void app_group_init()
+{
+ app_group_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL,
+ NULL);
+}
+
+void app_group_remove(int pid)
+{
+ __group_remove(pid);
+ app_group_context_t *context = __detach_context_from_recycle_bin(pid);
+
+ if (context)
+ free(context);
+}
+
+void app_group_remove_from_recycle_bin(int pid)
+{
+ app_group_context_t *context = __detach_context_from_recycle_bin(pid);
+
+ if (context)
+ free(context);
+}
+
+int app_group_get_window(int pid)
+{
+ app_group_context_t *context = __get_context(pid);
+
+ if (context)
+ return context->wid;
+
+ return -1;
+}
+
+int app_group_set_window(int pid, int wid)
+{
+ GHashTableIter iter;
+ gpointer key, value;
+
+ g_hash_table_iter_init(&iter, app_group_hash);
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
+ GList *list = (GList*) value;
+ GList *i = g_list_first(list);
+
+ int previous_wid = 0;
+ while (i != NULL) {
+ app_group_context_t *ac = (app_group_context_t*) i->data;
+
+ if (ac->pid == pid) {
+ ac->wid = wid;
+ if (previous_wid != 0)
+ __attach_window(previous_wid, wid);
+
+ if (ac->can_shift && ac->caller_pid > 0) {
+ int caller_wid = app_group_get_window(ac->caller_pid);
+
+ if (caller_wid != 0)
+ __attach_window(caller_wid, wid);
+ }
+
+ i = g_list_next(i);
+ if (i) {
+ ac = (app_group_context_t*) i->data;
+ if (ac->wid != 0)
+ __attach_window(wid, ac->wid);
+ }
+
+ return 0;
+ }
+ previous_wid = ac->wid;
+ i = g_list_next(i);
+ }
+ }
+
+ return -1;
+}
+
+void app_group_clear_top(int pid)
+{
+ GList *list = __find_removable_apps(pid);
+
+ if (list != NULL) {
+ GList *itr = g_list_last(list);
+
+ while (itr != NULL) {
+ int p = (int)(itr->data);
+
+ __detach_window(p);
+ _term_sub_app(p);
+ app_group_remove(p);
+ itr = g_list_previous(itr);
+ }
+ g_list_free(list);
+ }
+}
+
+gboolean app_group_is_group_app(bundle* kb)
+{
+ if (kb == NULL)
+ return FALSE;
+
+ char *str = NULL;
+ const char *mode = NULL;
+ char *appid = NULL;
+ const struct appinfo *ai = NULL;
+
+ bundle_get_str(kb, AUL_K_PKG_NAME, &appid);
+
+ if (appid == NULL)
+ return FALSE;
+
+ ai = appinfo_find(_laf, appid);
+ mode = appinfo_get_value(ai, AIT_LAUNCH_MODE);
+
+ if (mode != NULL && (strncmp(mode, "caller", 6) == 0 ||
+ strncmp(mode, "singleton", 9) == 0)) {
+ bundle_get_str(kb, APP_SVC_K_LAUNCH_MODE, &str);
+
+ if (str != NULL && strncmp(str, "group", 5) == 0) {
+ return TRUE;
+ }
+ } else if (mode != NULL && strncmp(mode, "group", 5) == 0) {
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+void app_group_get_leader_pids(int *cnt, int **pids)
+{
+ GHashTableIter iter;
+ gpointer key, value;
+
+ int size = g_hash_table_size(app_group_hash);
+ int *leader_pids;
+
+ if (size > 0) {
+ leader_pids = (int*) malloc(sizeof(int) * size);
+ if (leader_pids == NULL) {
+ _E("out of memory");
+ *cnt = 0;
+ *pids = NULL;
+ return;
+ }
+
+ g_hash_table_iter_init(&iter, app_group_hash);
+ int i = 0;
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
+ leader_pids[i] = (int) key;
+ i++;
+ }
+
+ *cnt = size;
+ *pids = leader_pids;
+ } else {
+ *cnt = 0;
+ *pids = NULL;
+ }
+}
+
+gboolean app_group_is_leader_pid(int pid)
+{
+ int cnt;
+ int *pids = NULL;
+ int i;
+
+ app_group_get_leader_pids(&cnt, &pids);
+
+ for (i=0; i<cnt; i++) {
+ if (pid == pids[i]) {
+ free(pids);
+ return TRUE;
+ }
+ }
+
+ if (pids != NULL)
+ free(pids);
+
+ return FALSE;
+}
+
+void app_group_get_group_pids(int leader_pid, int *cnt, int **pids)
+{
+ GHashTableIter iter;
+ gpointer key, value;
+
+ g_hash_table_iter_init(&iter, app_group_hash);
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
+ if ((int) key == leader_pid) {
+ GList *list = (GList*) value;
+ GList *i = g_list_first(list);
+ int size = g_list_length(list);
+
+ if (size > 0) {
+ int *pid_array = (int*) malloc(sizeof(int) * size);
+ int j = 0;
+
+ if (pid_array == NULL) {
+ _E("out of memory");
+ *cnt = 0;
+ *pids = NULL;
+ return;
+ }
+
+ while (i != NULL) {
+ app_group_context_t *ac = (app_group_context_t*) i->data;
+
+ pid_array[j] = ac->pid;
+ i = g_list_next(i);
+ j++;
+ }
+
+ *cnt = size;
+ *pids = pid_array;
+ } else {
+ *cnt = 0;
+ *pids = NULL;
+ }
+ return;
+ }
+ }
+
+ *cnt = 0;
+ *pids = NULL;
+}
+
+gboolean app_group_is_sub_app(int pid)
+{
+ GHashTableIter iter;
+ gpointer key, value;
+
+ g_hash_table_iter_init(&iter, app_group_hash);
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
+ GList *list = (GList*) value;
+ GList *found = NULL;
+
+ if (list != NULL) {
+ if ((found = g_list_find_custom(list, (gconstpointer)pid, __comp_pid)) != NULL) {
+ if (g_list_first(list) == found)
+ return FALSE;
+ return TRUE;
+ }
+ }
+ }
+
+ return FALSE;
+}
+
+void app_group_reroute(int pid)
+{
+ GHashTableIter iter;
+ gpointer key, value;
+
+ g_hash_table_iter_init(&iter, app_group_hash);
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
+ GList *list = (GList*) value;
+ GList *found = NULL;
+ GList *before = NULL;
+ GList *after = NULL;
+
+ if (list != NULL) {
+ if ((found = g_list_find_custom(list, (gconstpointer)pid, __comp_pid)) != NULL) {
+ before = g_list_previous(found);
+ after = g_list_next(found);
+
+ if (before == NULL || after == NULL)
+ return;
+
+ _D("reroute");
+ app_group_context_t *ac1 = (app_group_context_t*) before->data;
+ app_group_context_t *ac2 = (app_group_context_t*) after->data;
+
+ __detach_window(ac2->wid);
+ __attach_window(ac1->wid, ac2->wid);
+ break;
+ }
+ }
+ }
+}
+
+int app_group_get_leader_pid(int pid)
+{
+ GHashTableIter iter;
+ gpointer key, value;
+ int lpid = -1;
+ int again = 0;
+
+repeat:
+ g_hash_table_iter_init(&iter, app_group_hash);
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
+ GList *list = (GList*) value;
+
+ if (list != NULL) {
+ if (g_list_find_custom(list, (gconstpointer)pid, __comp_pid) != NULL) {
+ lpid = (int)key;
+ break;
+ }
+ }
+ }
+
+ if (lpid == -1 && dead_pid == pid)
+ lpid = focused_leader_pid;
+
+ if (lpid == -1 && again == 0) {
+ pid = getpgid(pid);
+ again = 1;
+ goto repeat;
+ }
+
+ return lpid;
+}
+
+void app_group_set_dead_pid(int pid)
+{
+ focused_leader_pid = app_group_get_leader_pid(pid);
+ dead_pid = pid;
+
+ if (dead_pid == focused_leader_pid) {
+ focused_leader_pid = -1;
+ dead_pid = -1;
+ }
+}
+
+int app_group_get_status(int pid)
+{
+ GHashTableIter iter;
+ gpointer key, value;
+
+ g_hash_table_iter_init(&iter, app_group_hash);
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
+ GList *list = (GList*) value;
+ GList *i = g_list_first(list);
+
+ while (i != NULL) {
+ app_group_context_t *ac = (app_group_context_t*) i->data;
+
+ if (ac->pid == pid)
+ return ac->status;
+
+ i = g_list_next(i);
+ }
+ }
+ return -1;
+}
+
+int app_group_set_status(int pid, int status, gboolean force)
+{
+ GHashTableIter iter;
+ gpointer key, value;
+
+ g_hash_table_iter_init(&iter, app_group_hash);
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
+ GList *list = (GList*) value;
+ GList *i = g_list_first(list);
+
+ while (i != NULL) {
+ app_group_context_t *ac = (app_group_context_t*) i->data;
+
+ if (ac->pid == pid) {
+ if (status > 0)
+ ac->status = status;
+ GList *last = g_list_last(list);
+ app_group_context_t *last_ac = (app_group_context_t*) last->data;
+
+ if (last_ac->wid != 0 || status == STATUS_VISIBLE || force == TRUE) {
+ if (__is_visible(pid)) {
+ __set_fg_flag(pid, 1, force);
+ if (!ac->group_sig && (int)key != pid) {
+ char *appid = NULL;
+ const char *pkgid = NULL;
+ const struct appinfo *ai = NULL;
+
+ appid = _status_app_get_appid_bypid(pid);
+ ai = appinfo_find(_laf, appid);
+ pkgid = appinfo_get_value(ai, AIT_PKGID);
+
+ _D("send group signal %d", pid);
+ aul_send_app_group_signal((int)key, pid, pkgid);
+ ac->group_sig = 1;
+ }
+ } else
+ __set_fg_flag(pid, 0, force);
+ }
+ return 0;
+ }
+ i = g_list_next(i);
+ }
+ }
+ return -1;
+}
+
+int app_group_get_fg_flag(int pid)
+{
+ GHashTableIter iter;
+ gpointer key, value;
+
+ g_hash_table_iter_init(&iter, app_group_hash);
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
+ GList *list = (GList*) value;
+ GList *i = g_list_first(list);
+
+ while (i != NULL) {
+ app_group_context_t *ac = (app_group_context_t*) i->data;
+
+ if (ac->pid == pid) {
+ return ac->fg;
+ }
+ i = g_list_next(i);
+ }
+ }
+
+ return 0;
+}
+
+int app_group_set_hint(int pid, bundle *kb)
+{
+ char *str_leader = NULL;
+ char *str_reroute = NULL;
+
+ if (kb == NULL)
+ return -1;
+
+ bundle_get_str(kb, AUL_SVC_K_CAN_BE_LEADER, &str_leader);
+ bundle_get_str(kb, AUL_SVC_K_REROUTE, &str_reroute);
+
+ GHashTableIter iter;
+ gpointer key, value;
+
+ g_hash_table_iter_init(&iter, app_group_hash);
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
+ GList *list = (GList*) value;
+ GList *i = g_list_first(list);
+
+ while (i != NULL) {
+ app_group_context_t *ac = (app_group_context_t*) i->data;
+
+ if (ac->pid == pid) {
+ if (str_leader != NULL && strcmp(str_leader, "true") == 0)
+ ac->can_be_leader = 1;
+ if (str_reroute != NULL && strcmp(str_reroute, "true") == 0)
+ ac->reroute = 1;
+ return 0;
+ }
+ i = g_list_next(i);
+ }
+ }
+
+ return -1;
+}
+
+int app_group_find_second_leader(int lpid)
+{
+ GList *list = (GList*) g_hash_table_lookup(app_group_hash,
+ GINT_TO_POINTER(lpid));
+ if (list != NULL) {
+ list = g_list_next(list);
+
+ if (list != NULL) {
+ app_group_context_t *ac = (app_group_context_t*) list->data;
+ if (ac->can_be_leader) {
+ _W("found the second leader, lpid: %d, pid: %d", lpid, ac->pid);
+ return ac->pid;
+ }
+ }
+ }
+
+ return -1;
+}
+
+void app_group_remove_leader_pid(int lpid)
+{
+ GList *list = (GList*)g_hash_table_lookup(app_group_hash,
+ GINT_TO_POINTER(lpid));
+
+ if (list != NULL) {
+ GList *next = g_list_next(list);
+
+ if (next != NULL) {
+ app_group_context_t *ac = (app_group_context_t*) list->data;
+ free(ac);
+ list = g_list_remove_link(list, list);
+
+ ac = (app_group_context_t*) next->data;
+ g_hash_table_insert(app_group_hash, GINT_TO_POINTER(ac->pid), next);
+ g_hash_table_remove(app_group_hash, GINT_TO_POINTER(lpid));
+ }
+ }
+}
+
+int app_group_can_start_app(const char *appid, bundle *b, gboolean *can_attach,
+ int *lpid, app_group_launch_mode *mode)
+{
+ const char *val = NULL;
+ int caller_pid;
+ int caller_wid;
+
+ *can_attach = FALSE;
+ if (__can_attach_window(b, appid, mode)) {
+ *can_attach = TRUE;
+
+ val = bundle_get_val(b, AUL_K_ORG_CALLER_PID);
+ if (val == NULL) {
+ val = bundle_get_val(b, AUL_K_CALLER_PID);
+ }
+
+ if (val == NULL) {
+ _E("no caller pid");
+ return -1;
+ }
+
+ caller_pid = atoi(val);
+#ifdef _APPFW_FEATURE_SEND_HOME_LAUNCH_SIGNAL
+ if (home_appid != NULL) {
+ char *caller_appid = _status_app_get_appid_bypid(caller_pid);
+
+ if (caller_appid != NULL && strcmp(caller_appid, home_appid) == 0) {
+ _E("can't be attached to home app");
+ return -1;
+ }
+ }
+#endif
+
+ *lpid = app_group_get_leader_pid(caller_pid);
+ if (*lpid != -1) {
+ caller_wid = app_group_get_window(caller_pid);
+
+ if (caller_wid == 0) {
+ _E("caller window wasn't ready");
+ if (__can_be_leader(b))
+ *can_attach = FALSE;
+ else
+ *can_attach = TRUE;
+ }
+
+ } else {
+ _E("no lpid");
+ if (__can_be_leader(b))
+ *can_attach = FALSE;
+ else
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+void app_group_start_app(int pid, bundle *b, int lpid, gboolean can_attach,
+ app_group_launch_mode mode)
+{
+ _E("app_group_start_app");
+
+ int caller_pid = __get_caller_pid(b);
+ int can_shift = 0;
+ int recycle = 0;
+ const char *str;
+
+ str = bundle_get_val(b, AUL_SVC_K_SHIFT_WINDOW);
+ if (str != NULL && strcmp(str, "true") == 0)
+ can_shift = 1;
+
+ str = bundle_get_val(b, AUL_SVC_K_RECYCLE);
+ if (str != NULL && strcmp(str, "true") == 0)
+ recycle = 1;
+
+ if (can_attach)
+ __group_add(lpid, pid, 0, mode, caller_pid, 0, recycle);
+ else
+ __group_add(pid, pid, 0, mode, caller_pid, can_shift, 0);
+ app_group_set_hint(pid, b);
+}
+
+int app_group_find_singleton(const char *appid, int *found_pid, int *found_lpid)
+{
+ GHashTableIter iter;
+ gpointer key = NULL;
+ gpointer value = NULL;
+ char *target = NULL;
+
+ g_hash_table_iter_init(&iter, app_group_hash);
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
+ GList *list = (GList*) value;
+
+ while (list != NULL) {
+ app_group_context_t *ac = (app_group_context_t*) list->data;
+
+ if (ac->launch_mode == APP_GROUP_LAUNCH_MODE_SINGLETON) {
+ target = _status_app_get_appid_bypid(ac->pid);
+
+ if (appid != NULL && target != NULL && strcmp(appid, target) == 0) {
+ *found_pid = ac->pid;
+ *found_lpid = (int)key;
+ return 0;
+ }
+ }
+ list = g_list_next(list);
+ }
+ }
+
+ return -1;
+}
+
+int app_group_can_reroute(int pid)
+{
+ GHashTableIter iter;
+ gpointer key, value;
+
+ g_hash_table_iter_init(&iter, app_group_hash);
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
+ GList *list = (GList*) value;
+ GList *i = g_list_first(list);
+
+ while (i != NULL) {
+ app_group_context_t *ac = (app_group_context_t*) i->data;
+
+ if (ac->pid == pid) {
+ return ac->reroute;
+ }
+ i = g_list_next(i);
+ }
+ }
+
+ return 0;
+}
+
+void app_group_lower(int pid, int *exit)
+{
+ if (app_group_is_sub_app(pid)) {
+ if (__can_recycle(pid) && __can_reroute(pid)) {
+ app_group_context_t *ac = __get_context(pid);
+ if (ac) {
+ if (ac->wid != 0)
+ __detach_window(ac->wid);
+ app_group_reroute(pid);
+ ac = __context_dup(ac);
+ __group_remove(pid);
+
+ if (ac)
+ __do_recycle(ac);
+
+ }
+ *exit = 0;
+ } else
+ *exit = 1;
+ return;
+ }
+
+ GHashTableIter iter;
+ gpointer key, value;
+
+ *exit = 0;
+ g_hash_table_iter_init(&iter, app_group_hash);
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
+ GList *list = (GList*) value;
+ GList *i = g_list_first(list);
+
+ while (i != NULL) {
+ app_group_context_t *ac = (app_group_context_t*) i->data;
+
+ if (ac->pid == pid) {
+ if (ac->can_shift) {
+ __detach_window(ac->wid);
+ ac->can_shift = 0;
+ ecore_x_window_lower(ac->wid);
+ }
+ return;
+ }
+ i = g_list_next(i);
+ }
+ }
+}
+
+void app_group_restart_app(int pid, bundle *b)
+{
+ if (b == NULL)
+ return;
+
+ GHashTableIter iter;
+ gpointer key, value;
+
+ g_hash_table_iter_init(&iter, app_group_hash);
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
+ GList *list = (GList*) value;
+ GList *i = g_list_first(list);
+
+ while (i != NULL) {
+ app_group_context_t *ac = (app_group_context_t*) i->data;
+
+ if (ac->pid == pid) {
+ const char *pid_str;
+ ac->caller_pid = __get_caller_pid(b);
+
+ if (ac->can_shift) {
+ if (ac->wid != 0)
+ __detach_window(ac->wid);
+ ac->can_shift = 0;
+ }
+
+ pid_str = bundle_get_val(b, AUL_SVC_K_SHIFT_WINDOW);
+ if (pid_str != NULL && strcmp(pid_str, "true") == 0) {
+ ac->can_shift = 1;
+ if (ac->wid != 0) {
+ if (ac->caller_pid > 0) {
+ int cwid = app_group_get_window(ac->caller_pid);
+
+ if (cwid != 0)
+ __attach_window(cwid, ac->wid);
+ else
+ _E("invalid caller wid");
+
+ } else
+ _E("invalid caller pid");
+
+
+ }
+ }
+ return;
+ }
+ i = g_list_next(i);
+ }
+ }
+}
+
+int app_group_find_pid_from_recycle_bin(const char *appid)
+{
+ GList *iter = recycle_bin;
+
+ while (iter) {
+ app_group_context_t *ac = (app_group_context_t*) iter->data;
+ const char *appid_from_bin = _status_app_get_appid_bypid(ac->pid);
+
+ if (appid && appid_from_bin && strcmp(appid, appid_from_bin) == 0) {
+ return ac->pid;
+ }
+
+ iter = g_list_next(iter);
+ }
+
+ return -1;
+}
+
+void app_group_get_idle_pids(int *cnt, int **pids)
+{
+ GList *iter = recycle_bin;
+ int idle_cnt = g_list_length(iter);
+
+ if (idle_cnt <= 0) {
+ *cnt = 0;
+ *pids = NULL;
+ return;
+ }
+
+ int *idle_pids = NULL;
+
+ idle_pids = malloc(sizeof(int) * idle_cnt);
+ if (idle_pids == NULL) {
+ _E("Out-of-memory");
+ *cnt = 0;
+ *pids = NULL;
+ return;
+ }
+
+ int i = 0;
+ while (iter) {
+ app_group_context_t *ac = (app_group_context_t*) iter->data;
+ idle_pids[i] = ac->pid;
+ iter = g_list_next(iter);
+ i++;
+ }
+
+ *cnt = idle_cnt;
+ *pids = idle_pids;
+}
+
+int app_group_get_next_caller_pid(int pid)
+{
+ GHashTableIter iter;
+ gpointer key, value;
+
+ g_hash_table_iter_init(&iter, app_group_hash);
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
+ GList *list = (GList*) value;
+ GList *i = g_list_first(list);
+
+ while (i != NULL) {
+ app_group_context_t *ac = (app_group_context_t*) i->data;
+
+ if (ac->pid == pid) {
+ i = g_list_next(i);
+ if (i == NULL)
+ return -1;
+
+ ac = (app_group_context_t*) i->data;
+ return ac->caller_pid;
+ }
+ i = g_list_next(i);
+ }
+ }
+
+ return -1;
+}
+
+
--- /dev/null
+#ifndef __AUL_AMD_APP_GROUP_H_
+#define __AUL_AMD_APP_GROUP_H_
+
+#include <glib.h>
+#include <bundle.h>
+
+typedef enum {
+ APP_GROUP_LAUNCH_MODE_SINGLE = 0,
+ APP_GROUP_LAUNCH_MODE_GROUP,
+ APP_GROUP_LAUNCH_MODE_CALLER,
+ APP_GROUP_LAUNCH_MODE_SINGLETON,
+} app_group_launch_mode;
+
+void app_group_init();
+void app_group_remove(int pid);
+int app_group_get_window(int pid);
+int app_group_set_window(int pid, int wid);
+void app_group_get_leader_pids(int *cnt, int **pids);
+void app_group_get_group_pids(int leader_pid, int *cnt, int **pids);
+gboolean app_group_is_leader_pid(int pid);
+gboolean app_group_is_group_app(bundle* kb);
+gboolean app_group_is_sub_app(int pid);
+void app_group_reroute(int pid);
+int app_group_get_caller_pid();
+void app_group_clear_top(int pid);
+int app_group_get_leader_pid(int pid);
+void app_group_set_dead_pid(int pid);
+int app_group_get_status(int pid);
+int app_group_set_status(int pid, int status, gboolean force);
+int app_group_get_fg_flag(int pid);
+int app_group_set_hint(int pid, bundle *kb);
+int app_group_find_second_leader(int lpid);
+void app_group_remove_leader_pid(int lpid);
+int app_group_can_start_app(const char *appid, bundle *b, gboolean *can_attach, int *lpid, app_group_launch_mode *mode);
+void app_group_start_app(int pid, bundle *b, int lpid, gboolean can_attach, app_group_launch_mode mode);
+int app_group_find_singleton(const char *appid, int *found_pid, int *found_lpid);
+int app_group_can_reroute(int pid);
+void app_group_lower(int pid, int *exit);
+void app_group_restart_app(int pid, bundle *b);
+int app_group_find_pid_from_recycle_bin(const char *appid);
+void app_group_get_idle_pids(int *cnt, int **pids);
+void app_group_remove_from_recycle_bin(int pid);
+int app_group_get_next_caller_pid(int pid);
+#endif
+
+#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "amd_config.h"
#include "simple_util.h"
#include "amd_appinfo.h"
+#include "amd_launch.h"
+#include "amd_request.h"
+#ifdef _APPFW_FEATURE_EXPANSION_PKG_INSTALL
+#include <pkgmgr-info.h>
+#include <pkgmgrinfo_type.h>
+#endif
#define SERVICE_GROUP "Service"
enum _appinfo_idx {
_AI_FILE = 0, /* service filename */
_AI_NAME,
- _AI_COMP,
_AI_EXEC,
_AI_TYPE,
_AI_ONBOOT,
_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
+#ifdef _APPFW_FEATURE_COOLDOWN_MODE_SUPPORT
+ _AI_COOLDOWN,
+#endif
+#ifdef _APPFW_FEATURE_EXPANSION_PKG_INSTALL
+ _AI_TEP,
+ _AI_STORAGE_TYPE,
+#endif
+ _AI_ALLOWED_BG,
+ _AI_API_VER,
+ _AI_LAUNCH_MODE,
+#ifdef _APPFW_FEATURE_EFFECTIVE_APPID
+ _AI_EFFECTIVE_APPID,
+#endif
+#ifdef _APPFW_FEATURE_PRIVATE_SERVICE
+ _AI_VISIBILITY,
+#endif
_AI_MAX,
};
#define _AI_START _AI_NAME /* start index */
static struct appinfo_t _appinfos[] = {
[_AI_NAME] = { "Name", AIT_NAME, },
- [_AI_COMP] = { "Component", AIT_COMP, },
[_AI_EXEC] = { "Exec", AIT_EXEC, },
[_AI_TYPE] = { "PkgType", AIT_TYPE, },
[_AI_ONBOOT] = { "StartOnBoot", AIT_ONBOOT, },
[_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
+#ifdef _APPFW_FEATURE_COOLDOWN_MODE_SUPPORT
+ [_AI_COOLDOWN] = { "CoolDown", AIT_COOLDOWN, },
+#endif
+#ifdef _APPFW_FEATURE_EXPANSION_PKG_INSTALL
+ [_AI_TEP] = {"Tep", AIT_TEP},
+ [_AI_STORAGE_TYPE] = {"StorageType", AIT_STORAGE_TYPE},
+#endif
+ [_AI_ALLOWED_BG] = {"AllowedBackground", AIT_ALLOWED_BG },
+ [_AI_API_VER] = {"ApiVersion", AIT_API_VER },
+ [_AI_LAUNCH_MODE] = {"launch_mode", AIT_LAUNCH_MODE },
+#ifdef _APPFW_FEATURE_EFFECTIVE_APPID
+ [_AI_EFFECTIVE_APPID] = {"effective-appid", AIT_EFFECTIVE_APPID },
+#endif
+#ifdef _APPFW_FEATURE_PRIVATE_SERVICE
+ [_AI_VISIBILITY] = {"visibility", AIT_VISIBILITY },
+#endif
+
};
struct appinfo {
free(cf);
}
-static int __app_info_insert_handler (const pkgmgrinfo_appinfo_h handle, void *data)
+static int __set_allowed_bg(const char *category_name, void *user_data)
+{
+ /* assume any of background category declared means that background running is allowed */
+ bool *allowed_bg = (bool *)user_data;
+
+ if (category_name && strcmp(category_name, "enable") == 0) {
+ return 0;
+ }
+
+ if (category_name && strcmp(category_name, "disable") == 0) {
+ *allowed_bg = false;
+ return -1;
+ }
+
+ _D("background category:%s", category_name);
+ *allowed_bg = true;
+ return -1;
+}
+
+static int __app_info_insert_handler(const pkgmgrinfo_appinfo_h handle, void *data)
{
struct appinfo *c;
struct appinfomgr *cf = (struct appinfomgr *)data;
#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;
- pkgmgrinfo_app_component component;
pkgmgrinfo_permission_type permission;
bool indicator_display;
int ret = -1;
#endif
int support_mode = 0;
- _D("__app_info_insert_handler");
+#ifdef _APPFW_FEATURE_EXPANSION_PKG_INSTALL
+ char *tep_name = NULL;
+ pkgmgrinfo_installed_storage installed_storage;
+#endif
+ bool allowed_bg = false;
+#ifdef _APPFW_FEATURE_EFFECTIVE_APPID
+ char *effective_appid = NULL;
+#endif
+ char *api_ver = NULL;
+ char *mode = NULL;
if (!handle) {
_E("null app handle");
return -1;
}
- c->val[_AI_NAME] = strdup(appid); //TODO :
-
- 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 :
+ c->val[_AI_NAME] = strdup(appid);
- r = pkgmgrinfo_appinfo_is_multiple(handle, &multiple);
- if(multiple == true)
- c->val[_AI_MULTI] = strdup("true");
- else c->val[_AI_MULTI] = strdup("false");
+ r = pkgmgrinfo_appinfo_is_multiple(handle, &multiple);
+ if(multiple == true)
+ c->val[_AI_MULTI] = strdup("true");
+ else c->val[_AI_MULTI] = strdup("false");
- r = pkgmgrinfo_appinfo_is_taskmanage(handle, &taskmanage);
- if (taskmanage == false) {
- c->val[_AI_TASKMANAGE] = strdup("false");
- } else {
- c->val[_AI_TASKMANAGE] = strdup("true");
- }
+ r = pkgmgrinfo_appinfo_is_taskmanage(handle, &taskmanage);
+ if (taskmanage == false) {
+ c->val[_AI_TASKMANAGE] = strdup("false");
+ } else {
+ c->val[_AI_TASKMANAGE] = strdup("true");
+ }
- r = pkgmgrinfo_appinfo_is_preload(handle, &preload);
- if (preload == false) {
- c->val[_AI_PRELOAD] = strdup("false");
- } else {
- c->val[_AI_PRELOAD] = strdup("true");
- }
+ r = pkgmgrinfo_appinfo_is_preload(handle, &preload);
+ if (preload == false) {
+ c->val[_AI_PRELOAD] = strdup("false");
+ } else {
+ c->val[_AI_PRELOAD] = strdup("true");
+ }
- if(gles == 0) {
- c->val[_AI_HWACC] = strdup("NOT_USE");
+ if(gles == 0) {
+ c->val[_AI_HWACC] = strdup("NOT_USE");
+ } else {
+ r = pkgmgrinfo_appinfo_get_hwacceleration(handle, &hwacc);
+ if (r < 0){
+ _E("ERROR IN FETCHING HWACCELERATION INFO\n");
+ c->val[_AI_HWACC] = NULL;
} else {
-
- r = pkgmgrinfo_appinfo_get_hwacceleration(handle, &hwacc);
if (hwacc == PMINFO_HWACCELERATION_ON) {
c->val[_AI_HWACC] = strdup("USE");
- } else if (hwacc == PMINFO_HWACCELERATION_DEFAULT) {
- c->val[_AI_HWACC] = strdup("SYS");
- } else {
+ } else if (hwacc == PMINFO_HWACCELERATION_OFF) {
c->val[_AI_HWACC] = strdup("NOT_USE");
+ } else {
+ c->val[_AI_HWACC] = strdup("SYS");
}
}
+ }
- r = pkgmgrinfo_appinfo_is_indicator_display_allowed(handle, &indicator_display);
- if (r <0 ){
- _E("ERROR IN FETCHING INDICATOR DISP INFO\n");
+ r = pkgmgrinfo_appinfo_is_indicator_display_allowed(handle, &indicator_display);
+ if (r <0 ){
+ _E("ERROR IN FETCHING INDICATOR DISP INFO\n");
+ c->val[_AI_INDICATORDISP] = strdup("true");
+ }else{
+ if (indicator_display == true){
c->val[_AI_INDICATORDISP] = strdup("true");
}else{
- if (indicator_display == true){
- c->val[_AI_INDICATORDISP] = strdup("true");
- }else{
- c->val[_AI_INDICATORDISP] = strdup("false");
- }
+ c->val[_AI_INDICATORDISP] = strdup("false");
}
+ }
- r = pkgmgrinfo_appinfo_get_effectimage(handle, &portraitimg, &landscapeimg);
- if (r < 0){
- _E("ERROR IN FETCHING EFFECT IMAGES\n");
+ r = pkgmgrinfo_appinfo_get_effectimage(handle, &portraitimg, &landscapeimg);
+ if (r < 0){
+ _E("ERROR IN FETCHING EFFECT IMAGES\n");
+ c->val[_AI_EFFECTIMAGEPORT] = NULL;
+ c->val[_AI_EFFECTIMAGELAND] = NULL;
+ }else{
+ if (portraitimg)
+ c->val[_AI_EFFECTIMAGEPORT] = strdup(portraitimg);
+ else
c->val[_AI_EFFECTIMAGEPORT] = NULL;
+ if (landscapeimg)
+ c->val[_AI_EFFECTIMAGELAND] = strdup(landscapeimg);
+ else
c->val[_AI_EFFECTIMAGELAND] = NULL;
- }else{
- if (portraitimg)
- c->val[_AI_EFFECTIMAGEPORT] = strdup(portraitimg);
- else
- c->val[_AI_EFFECTIMAGEPORT] = NULL;
- if (landscapeimg)
- c->val[_AI_EFFECTIMAGELAND] = strdup(landscapeimg);
- 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);
+ 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");
- }
+ 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);
+ r = pkgmgrinfo_appinfo_get_component_type(handle, &component_type);
+ c->val[_AI_COMPTYPE] = strdup(component_type);
- r = pkgmgrinfo_appinfo_is_onboot(handle, &onboot);
- if(onboot == true)
- c->val[_AI_ONBOOT] = strdup("true");
- else c->val[_AI_ONBOOT] = strdup("false");
+ r = pkgmgrinfo_appinfo_is_onboot(handle, &onboot);
+ if(onboot == true)
+ c->val[_AI_ONBOOT] = strdup("true");
+ else c->val[_AI_ONBOOT] = strdup("false");
- r = pkgmgrinfo_appinfo_is_autorestart(handle, &restart);
- if(restart == true)
- c->val[_AI_RESTART] = strdup("true");
- else c->val[_AI_RESTART] = strdup("false");
+ r = pkgmgrinfo_appinfo_is_autorestart(handle, &restart);
+ if(restart == true)
+ c->val[_AI_RESTART] = strdup("true");
+ 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_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);
+ 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");
+ // Toggle order
+ c->val[_AI_TOGGLE_ORDER] = strdup("0");
#endif
- } else {
- c->val[_AI_COMP] = strdup("svc");
-
- r = pkgmgrinfo_appinfo_is_onboot(handle, &onboot);
- if(onboot == true)
- c->val[_AI_ONBOOT] = strdup("true");
- else c->val[_AI_ONBOOT] = strdup("false");
-
- r = pkgmgrinfo_appinfo_is_autorestart(handle, &restart);
- if(restart == true)
- c->val[_AI_RESTART] = strdup("true");
- else c->val[_AI_RESTART] = strdup("false");
- }
r = pkgmgrinfo_appinfo_get_exec(handle, &exec);
c->val[_AI_EXEC] = strdup(exec);
c->val[_AI_UPS] = strdup("false");
}
#endif
+#ifdef _APPFW_FEATURE_COOLDOWN_MODE_SUPPORT
+ if(support_mode & PMINFO_SUPPORT_MODE_COOL_DOWN) {
+ c->val[_AI_COOLDOWN] = strdup("true");
+ } else {
+ c->val[_AI_COOLDOWN] = strdup("false");
+ }
+#endif
r = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
c->val[_AI_PKGID] = strdup(pkgid);
c->val[_AI_STATUS] = strdup("installed");
- SECURE_LOGD("appinfo file:%s, comp:%s, type:%s", c->val[_AI_FILE], c->val[_AI_COMP], c->val[_AI_TYPE]);
+#ifdef _APPFW_FEATURE_EXPANSION_PKG_INSTALL
+
+ ret = pkgmgrinfo_appinfo_get_tep_name(handle, &tep_name);
+ if(ret == PMINFO_R_OK) {
+ c->val[_AI_TEP] = strdup(tep_name);
+ }
+
+ ret = pkgmgrinfo_appinfo_get_installed_storage_location(handle, &installed_storage);
+ if(ret == PMINFO_R_OK) {
+ if(installed_storage == PMINFO_INTERNAL_STORAGE)
+ {
+ c->val[_AI_STORAGE_TYPE] = strdup("internal");
+ }
+ else if(installed_storage == PMINFO_EXTERNAL_STORAGE)
+ {
+ c->val[_AI_STORAGE_TYPE] = strdup("external");
+ }
+ }
+#endif
+
+#ifdef _APPFW_FEATURE_EFFECTIVE_APPID
+ ret = pkgmgrinfo_appinfo_get_effective_appid(handle, &effective_appid);
+ if (ret == PMINFO_R_OK) {
+ if (effective_appid && strlen(effective_appid) > 0)
+ c->val[_AI_EFFECTIVE_APPID] = strdup(effective_appid);
+ }
+#endif
+
+ ret = pkgmgrinfo_appinfo_get_api_version(handle, &api_ver);
+ if (ret != PMINFO_R_OK) {
+ _E("Failed to get api version");
+ _free_appinfo(c);
+ return -1;
+ }
+
+ if (api_ver)
+ c->val[_AI_API_VER] = strdup(api_ver);
+ else
+ c->val[_AI_API_VER] = strdup("NONE");
+
+ ret = pkgmgrinfo_appinfo_get_launch_mode(handle, &mode);
+ if (ret == PMINFO_R_OK && mode)
+ c->val[_AI_LAUNCH_MODE] = strdup(mode);
+ else
+ c->val[_AI_LAUNCH_MODE] = strdup("single");
+
+ /* TODO each background category may have different background management policies,
+ * so should have real background category value than allowed_background. */
+ pkgmgrinfo_appinfo_foreach_background_category(handle, __set_allowed_bg, &allowed_bg);
+ if (ret != PMINFO_R_OK) {
+ _E("Failed to check allowed background");
+ }
+
+ if (allowed_bg) {
+ SECURE_LOGD("[__SUSPEND__] allowed background, appid: %s", appid);
+ c->val[_AI_ALLOWED_BG] = strdup("ALLOWED_BG");
+ } else {
+ c->val[_AI_ALLOWED_BG] = strdup("NONE");
+ }
+#ifdef _APPFW_FEATURE_PRIVATE_SERVICE
+ c->val[_AI_VISIBILITY] = NULL;
+#endif
+ SECURE_LOGD("appinfo file:%s, type:%s", c->val[_AI_FILE], c->val[_AI_TYPE]);
g_hash_table_insert(cf->tbl, c->val[_AI_FILE], c);
return 0;
}
-static int __app_info_delete_handler (const pkgmgrinfo_appinfo_h handle, void *data)
+static int __app_info_delete_handler(const pkgmgrinfo_appinfo_h handle, void *data)
{
struct appinfomgr *cf = (struct appinfomgr *)data;
- char *appid;
+ char *appid = NULL;
pkgmgrinfo_appinfo_get_appid(handle, &appid);
- g_hash_table_remove(cf->tbl, appid);
+ if (appid)
+ g_hash_table_remove(cf->tbl, appid);
return 0;
}
static int _read_pkg_info(struct appinfomgr *cf)
{
- int ret = pkgmgrinfo_appinfo_get_install_list(__app_info_insert_handler, cf);
+ int ret;
+ ret = pkgmgrinfo_appinfo_get_install_list(__app_info_insert_handler, cf);
assert(ret == PMINFO_R_OK);
return ret;
return cf;
}
-static gboolean __amd_pkgmgrinfo_start_handler (gpointer key, gpointer value, gpointer user_data)
+static void __amd_pkgmgrinfo_start_handler (gpointer key, gpointer value, gpointer user_data)
{
struct appinfo *c = value;
char *pkgid = (char *)user_data;
c->val[_AI_STATUS] = strdup("blocking");
SECURE_LOGD("pkgmgr working for this application(%s)", c->val[_AI_NAME]);
}
- return TRUE;
}
-static gboolean __amd_pkgmgrinfo_fail_handler (gpointer key, gpointer value, gpointer user_data)
+static void __amd_pkgmgrinfo_fail_handler (gpointer key, gpointer value, gpointer user_data)
{
struct appinfo *c = value;
char *pkgid = (char *)user_data;
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)
if (r == 1 && componet && strncmp(componet, "svcapp", 6) == 0)
{
- _D("start service - %s", appid);
- _start_srv(c, NULL);
+ SECURE_LOGW("start service - %s", appid);
+ _start_srv(c);
}
return 0;
if (c != NULL && strncmp(c->val[_AI_STATUS], "restart", 7) == 0) {
__app_info_insert_handler(handle, user_data);
- __release_srv(appid);
+ _release_srv(appid);
} else {
__app_info_insert_handler(handle, user_data);
c = g_hash_table_lookup(cf->tbl, appid);
if (r == 1 && componet && strncmp(componet, "svcapp", 6) == 0)
{
- _D("start service - %s", appid);
- _start_srv(c, NULL);
+ SECURE_LOGW("start service - %s", appid);
+ _start_srv(c);
}
}
p = g_hash_table_lookup(pkg_tbl, pkgid);
if(p) {
op = p->op;
- SECURE_LOGD("op(%s), value(%s)", op, val);
+ SECURE_LOGW("op(%s), value(%s)", op, val);
if (strncmp(val, "ok", 2) == 0) {
if (op && strncmp(op, "install", 7)== 0) {
ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
static int __unmounted_list_cb(const pkgmgrinfo_appinfo_h handle, void *user_data)
{
- char *appid;
+ char *appid = NULL;
struct appinfomgr *cf = (struct appinfomgr *)user_data;
- struct appinfo *c;
+ struct appinfo *c = NULL;
pkgmgrinfo_appinfo_get_appid(handle, &appid);
- c = g_hash_table_lookup(cf->tbl, appid);
- if (c == NULL)
- return -1;
-
- SECURE_LOGD("%s : %s", c->val[_AI_FILE], c->val[_AI_STATUS]);
- free(c->val[_AI_STATUS]);
- c->val[_AI_STATUS] = strdup("unmounted");
- SECURE_LOGD("unmounted(%s)", appid);
+ if (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("unmounted");
+ SECURE_LOGD("unmounted(%s)", appid);
+ } else {
+ _E("pkgmgrinfo_appinfo_get_appid() failed");
+ }
return 0;
}
static int __mounted_list_cb(const pkgmgrinfo_appinfo_h handle, void *user_data)
{
- char *appid;
+ char *appid = NULL;
struct appinfomgr *cf = (struct appinfomgr *)user_data;
- struct appinfo *c;
+ struct appinfo *c = NULL;
pkgmgrinfo_appinfo_get_appid(handle, &appid);
- c = g_hash_table_lookup(cf->tbl, appid);
- if (c == NULL)
- return -1;
-
- SECURE_LOGD("%s : %s", c->val[_AI_FILE], c->val[_AI_STATUS]);
- if(strncmp(c->val[_AI_STATUS], "unmounted", 9) ==0 ) {
- free(c->val[_AI_STATUS]);
- c->val[_AI_STATUS] = strdup("installed");
+ if (appid) {
+ c = g_hash_table_lookup(cf->tbl, appid);
+ SECURE_LOGD("%s : %s", c->val[_AI_FILE], c->val[_AI_STATUS]);
+ if(strncmp(c->val[_AI_STATUS], "unmounted", 9) ==0 ) {
+ free(c->val[_AI_STATUS]);
+ c->val[_AI_STATUS] = strdup("installed");
+ }
+ SECURE_LOGD("mounted(%s)", appid);
+ } else {
+ _E("pkgmgrinfo_appinfo_get_appid() failed");
}
- SECURE_LOGD("mounted(%s)", appid);
return 0;
}
+#ifdef _APPFW_FEATURE_MMC_SUPPORT
static void __amd_mmc_vconf_cb(keynode_t *key, void *data)
{
int status;
- struct appinfomgr *cf = (struct appinfomgr *)data;
int ret = 0;
status = vconf_keynode_get_int(key);
}
}
}
+#endif
int appinfo_init(struct appinfomgr **cf)
{
struct appinfomgr *_cf;
int r;
+ char *cmdline;
FILE *fp = NULL;
char buf[4096] = {0,};
char *tmp = NULL;
_E("appinfo init failed: %s", strerror(errno));
return -1;
}
- r = fgets(buf, sizeof(buf), fp);
- tmp = strstr(buf, "gles");
- if(tmp != NULL) {
- sscanf(tmp,"gles=%d", &gles);
+ cmdline = fgets(buf, sizeof(buf), fp);
+ if (cmdline != NULL) {
+ tmp = strstr(buf, "gles");
+ if(tmp != NULL) {
+ sscanf(tmp,"gles=%d", &gles);
+ }
}
fclose(fp);
return -1;
}
+#ifdef _APPFW_FEATURE_MMC_SUPPORT
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");
+#endif
int event_type = PMINFO_CLIENT_STATUS_UPGRADE | PMINFO_CLIENT_STATUS_UNINSTALL | PMINFO_CLIENT_STATUS_INSTALL;
pkgmgrinfo_client *pc = NULL;
*cf = NULL;
}
-const struct appinfo *appinfo_insert(struct appinfomgr *cf, const char *pkg_name)
+const struct appinfomgr *appinfo_insert(struct appinfomgr *cf, const char *pkg_name)
{
pkgmgrinfo_pkginfo_h handle;
if (pkgmgrinfo_pkginfo_get_pkginfo(pkg_name, &handle) == PMINFO_R_OK){
const char *appinfo_set_value(struct appinfo *c, enum appinfo_type type, const char* val)
{
enum _appinfo_idx i;
+ if (!c) {
+ SECURE_LOGE("appinfo is NULL, type: %d, val: %s", type, val);
+ return NULL;
+ }
for (i = _AI_START; i < sizeof(_appinfos)/sizeof(_appinfos[0]); i++) {
if (type == _appinfos[i].type) {
SECURE_LOGD("%s : %s : %s", c->val[_AI_FILE], c->val[i], val);
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
+#ifdef _APPFW_FEATURE_COOLDOWN_MODE_SUPPORT
+ AIT_COOLDOWN,
+#endif
+#ifdef _APPFW_FEATURE_EXPANSION_PKG_INSTALL
+ AIT_TEP,
+ AIT_STORAGE_TYPE,
+#endif
+ AIT_ALLOWED_BG,
+ AIT_API_VER,
+ AIT_LAUNCH_MODE,
+#ifdef _APPFW_FEATURE_EFFECTIVE_APPID
+ AIT_EFFECTIVE_APPID,
+#endif
+#ifdef _APPFW_FEATURE_PRIVATE_SERVICE
+ AIT_VISIBILITY,
+#endif
AIT_MAX
};
+#define APP_TYPE_SERVICE "svcapp"
+#define APP_TYPE_UI "uiapp"
+#define APP_TYPE_WIDGET "widgetapp"
+#define APP_TYPE_WATCH "watchapp"
+
int appinfo_init(struct appinfomgr **cf);
void appinfo_fini(struct appinfomgr **cf);
-const struct appinfo *appinfo_insert(struct appinfomgr *cf, const char *filename);
+const struct appinfomgr *appinfo_insert(struct appinfomgr *cf, const char *filename);
void appinfo_delete(struct appinfomgr *cf, const char *filename);
const struct appinfo *appinfo_find(struct appinfomgr *cf, const char *filename);
+++ /dev/null
-#include <stdio.h>
-#include <stdlib.h>
-#include <assert.h>
-#include <string.h>
-#include <sys/mount.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <errno.h>
-#include <limits.h>
-#include <dirent.h>
-#include <mntent.h>
-
-
-#include "amd_config.h"
-#include "simple_util.h"
-#include "amd_cgutil.h"
-
-#define CFILE_RELEASE_AGENT "release_agent"
-#define CFILE_NOTIFY_ON_RELEASE "notify_on_release"
-#define CFILE_TASKS "tasks"
-
-#define DEFAULT_MODE 0755
-
-struct ctrl {
- enum ctrl_type ctrl;
- char *root; /* cginfo's mount_point + subsystem name */
-};
-
-struct cginfo {
- int refcnt;
- char *mount_point;
- struct ctrl ctrls[CTRL_MAX];
-};
-
-enum {
- _MNT_ROOT,
- _MNT_MGR,
- _MNT_CPU,
- _MNT_MEM,
- /* add type after adding mount information to mntinfos[] */
-};
-
-struct mntinfo {
- char *source;
- char *ftype; /* filesystem type */
- unsigned long flags;
- char *option;
-};
-
-static struct mntinfo mntinfos[] = {
- [_MNT_ROOT] = {
- "cgroup_root",
- "tmpfs",
- MS_NODEV | MS_NOSUID | MS_NOEXEC,
- NULL,
- },
- [_MNT_MGR] = {
- "daemon_mgr",
- "cgroup",
- MS_NODEV | MS_NOSUID | MS_NOEXEC,
- "none,name=daemon_mgr",
- },
- [_MNT_CPU] = {
- "cpuset",
- "cgroup",
- MS_NODEV | MS_NOSUID | MS_NOEXEC,
- "cpuset",
- },
- [_MNT_MEM] = {
- "memory",
- "cgroup",
- MS_NODEV | MS_NOSUID | MS_NOEXEC,
- "memory",
- },
- /* TODO: add more */
-};
-
-struct ctrlinfo {
- int mnt_type;
- char *name;
-};
-
-static struct ctrlinfo ctrlinfos[] = {
- [CTRL_MGR] = { _MNT_MGR, "mgr", },
-#if defined(USE_CGROUP_CPU)
- [CTRL_CPU] = { _MNT_CPU, "cpuset", },
-#endif
-#if defined(USE_CGROUP_MEM)
- [CTRL_MEM] = { _MNT_MEM, "memory", },
-#endif
-};
-
-static inline int _mount(const char *mount_point, struct mntinfo *mti)
-{
- assert(mti);
- return mount(mti->source, mount_point, mti->ftype, mti->flags,
- mti->option);
-}
-
-static inline int _umount(const char *mount_point)
-{
- return umount2(mount_point, MNT_DETACH);
-}
-
-static int _write_single(struct ctrl *ctr,
- const char *group, const char *file, const char *str)
-{
- FILE *fp;
- char path[FILENAME_MAX];
- int r;
-
- assert(ctr);
- assert(file);
-
- if (!str)
- str = "";
-
- snprintf(path, sizeof(path), "%s/%s%s%s", ctr->root,
- group ? : "", group ? "/" : "", file);
- fp = fopen(path, "w");
- if (!fp) {
- _E("open: %s: %s", path, strerror(errno));
- return -1;
- }
-
- r = fputs(str, fp);
- if (r == EOF) {
- _E("write: %s,%s: %s", path, str, strerror(errno));
- r = -1;
- } else {
- r = 0;
- }
-
- fclose(fp);
-
- return r;
-}
-
-/*
-static void _trunc_newline(char *buf, int sz)
-{
- char *s;
-
- assert(buf);
- assert(sz > 0);
-
- s = buf;
- while (*s) {
- if (*s == '\r' || *s == '\n') {
- *s = '\0';
- break;
- }
- s++;
- }
-}
-
-static int _read_single(struct ctrl *ctr, const char *file, char *buf, int sz)
-{
- FILE *fp;
- char path[FILENAME_MAX];
- char _buf[LINE_MAX];
- char *r;
-
- assert(ctr);
- assert(file);
- assert(buf);
- assert(sz > 0);
-
- snprintf(path, sizeof(path), "%s/%s", ctr->root, file);
- fp = fopen(path, "r");
- if (!fp) {
- _E("open: %s: %s", path, strerror(errno));
- return -1;
- }
-
- r = fgets(_buf, sizeof(_buf), fp);
- if (r == NULL) {
- _E("read: %s: %s", path, strerror(errno));
- } else {
- _trunc_newline(_buf, sizeof(_buf));
- snprintf(buf, sz, "%s", _buf);
- }
-
- fclose(fp);
-
- return r == NULL ? -1 : 0;
-}
-*/
-
-static int _destroy(struct cginfo *cg)
-{
- int i;
- int r;
-
- for (i = 0; i < sizeof(cg->ctrls)/sizeof(cg->ctrls[0]); i++) {
- struct ctrl *ctr = &cg->ctrls[i];
-
- if (ctr->root) {
- r = _umount(ctr->root);
- if (r == -1) {
- _E("unmount: %s: %s",
- ctr->root, strerror(errno));
- return -1;
- }
- free(ctr->root);
- ctr->root = NULL;
- }
- }
-
- if (cg->mount_point) {
- r = _umount(cg->mount_point);
- if (r == -1) {
- _E("unmount: %s: %s",
- cg->mount_point, strerror(errno));
- return -1;
- }
- free(cg->mount_point);
- }
-
- free(cg);
-
- return 0;
-}
-
-void cgutil_destroy(struct cginfo **cg)
-{
- int r;
-
- if (!cg || !*cg)
- return;
-
- (*cg)->refcnt--;
-
- if ((*cg)->refcnt > 0)
- return;
-
- r = _destroy(*cg);
- if (r == -1)
- return;
-
- *cg = NULL;
-}
-
-static int check_cgroup_mount(const char *mount_point)
-{
- struct mntent* mnt;
- const char* table = "/etc/mtab";
- FILE* fp;
- int r = -1;
- fp = setmntent(table, "r");
-
- if (!fp)
- return r;
-
- while (mnt=getmntent(fp)) {
- if (strcmp(mount_point, mnt->mnt_dir) == 0) {
- r = 0;
- break;
- }
- }
- endmntent(fp);
- return r;
-}
-
-static int _mount_root(struct cginfo *cg, const char *mount_point)
-{
- int r = 0;
-
- if (check_cgroup_mount(mount_point) < 0)
- r = _mount(mount_point, &mntinfos[_MNT_ROOT]);
- if (r == -1) {
- if (errno != EBUSY) {
- _E("mount: %s: %s", mount_point, strerror(errno));
- return -1;
- }
- _D("'%s' already mounted", mount_point);
- }
-
- cg->mount_point = strdup(mount_point);
-
- return 0;
-}
-
-static int _init_ctrl(struct ctrl *ctr, struct cginfo *cg, enum ctrl_type ctrl)
-{
- int r;
- int mt;
- char path[FILENAME_MAX];
-
- assert(ctr);
- assert(ctrl >= 0);
- assert(ctrl < sizeof(ctrlinfos)/sizeof(ctrlinfos[0]));
-
- mt = ctrlinfos[ctrl].mnt_type;
- snprintf(path, sizeof(path), "%s/%s",
- cg->mount_point, ctrlinfos[ctrl].name);
-
- /* TODO: read /proc/cgroup and check the current type is enabled */
-
- r = mkdir(path, DEFAULT_MODE);
- if (r == -1) {
- if (errno != EEXIST) {
- _E("mkdir: %s: %s", path, strerror(errno));
- return -1;
- }
- _D("'%s' exist", path);
- }
-
- r = _mount(path, &mntinfos[mt]);
- if (r == -1) {
- if (errno != EBUSY) {
- _E("mount: %s: %s", path, strerror(errno));
- rmdir(path);
- return -1;
- }
- _D("'%s' already mounted", path);
- }
-
- ctr->ctrl = ctrl;
- ctr->root = strdup(path);
-
- return 0;
-}
-
-static int _set_release_agent(struct ctrl *ctr, const char *agent_path)
-{
- int r;
-
- r = access(agent_path, X_OK);
- if (r == -1) {
- _E("'%s' is not executable: %s",
- agent_path, strerror(errno));
- return -1;
- }
-
- r = _write_single(ctr, NULL, CFILE_RELEASE_AGENT, agent_path);
- if (r == -1)
- return -1;
-
- r = _write_single(ctr, NULL, CFILE_NOTIFY_ON_RELEASE, "1");
- if (r == -1)
- return -1;
-
- return 0;
-}
-
-struct cginfo *cgutil_ref(struct cginfo *cg)
-{
- if (cg)
- cg->refcnt++;
-
- return cg;
-}
-
-static int _create(struct cginfo *cg,
- const char *mount_point, const char *agent_path)
-{
- int i;
- int r;
-
- r = _mount_root(cg, mount_point);
- if (r == -1)
- return -1;
-
- for (i = 0; i < sizeof(cg->ctrls)/sizeof(cg->ctrls[0]); i++) {
- r = _init_ctrl(&cg->ctrls[i], cg, i);
- if (r == -1)
- return -1;
- }
-
- r = _set_release_agent(&cg->ctrls[CTRL_MGR], agent_path);
- if (r == -1)
- return -1;
-
- return 0;
-}
-
-int cgutil_create(const char *mount_point, const char *agent_path,
- struct cginfo **cg)
-{
- struct cginfo *_cg;
- int r;
-
- if (!mount_point || !*mount_point ||
- !agent_path || !*agent_path || !cg) {
- errno = EINVAL;
- _E("cgutil create: %s", strerror(errno));
- return -1;
- }
-
- _cg = calloc(1, sizeof(*_cg));
- if (!_cg) {
- _E("cgutil alloc: %s", strerror(errno));
- return -1;
- }
-
- r = _create(_cg, mount_point, agent_path);
- if (r == -1) {
- _destroy(_cg);
- return -1;
- }
-
- *cg = cgutil_ref(_cg);
-
- return 0;
-}
-
-int cgutil_create_group(struct cginfo *cg,
- enum ctrl_type ctrl, const char *group)
-{
- int r;
- struct ctrl *ctr;
- char path[FILENAME_MAX];
-
- assert(ctrl >= 0 && ctrl < CTRL_MAX);
-
- if (!cg || !group || !*group) {
- errno = EINVAL;
- _E("cgutil create group: %s", strerror(errno));
- return -1;
- }
-
- ctr = &cg->ctrls[ctrl];
- assert(ctr);
-
- snprintf(path, sizeof(path), "%s/%s", ctr->root, FILENAME(group));
-
- r = mkdir(path, DEFAULT_MODE);
- if (r == -1) {
- _E("cgutil create group: mkdir: %s", strerror(errno));
- return -1;
- }
-
- return 0;
-}
-
-int cgutil_remove_group(struct cginfo *cg,
- enum ctrl_type ctrl, const char *group)
-{
- int r;
- struct ctrl *ctr;
- char path[FILENAME_MAX];
-
- assert(ctrl >= 0 && ctrl < CTRL_MAX);
-
- if (!cg || !group || !*group) {
- errno = EINVAL;
- _E("cgutil remove group: %s", strerror(errno));
- return -1;
- }
-
- ctr = &cg->ctrls[ctrl];
- assert(ctr);
-
- snprintf(path, sizeof(path), "%s/%s", ctr->root, FILENAME(group));
-
- r = rmdir(path);
- if (r == -1) {
- _E("cgutil remove group: rmdir: %s", strerror(errno));
- return -1;
- }
-
- return 0;
-}
-
-int cgutil_exist_group(struct cginfo *cg,
- enum ctrl_type ctrl, const char *group)
-{
- int r;
- struct ctrl *ctr;
- char path[FILENAME_MAX];
- struct stat st;
-
- assert(ctrl >= 0 && ctrl < CTRL_MAX);
-
- if (!cg || !group || !*group) {
- errno = EINVAL;
- _E("cgutil exist group: %s", strerror(errno));
- return -1;
- }
-
- ctr = &cg->ctrls[ctrl];
- assert(ctr);
-
- snprintf(path, sizeof(path), "%s/%s", ctr->root, FILENAME(group));
-
- r = stat(path, &st);
- if (r == -1) {
- if (errno == ENOENT)
- return 0;
-
- _E("cgutil exist group: %s", strerror(errno));
- return -1;
- }
-
- /* stat() returns no error, then group exists */
- return 1;
-}
-
-int cgutil_group_add_pid(struct cginfo *cg,
- enum ctrl_type ctrl, const char *group, pid_t pid)
-{
- int r;
- struct ctrl *ctr;
- char buf[32]; /* 32 is enough for ineger number */
-
- assert(ctrl >= 0 && ctrl < CTRL_MAX);
-
- /* PID 1 is init's PID */
- if (!cg || !group || !*group || pid <= 1) {
- errno = EINVAL;
- _E("cgutil add pid: %s", strerror(errno));
- return -1;
- }
-
- ctr = &cg->ctrls[ctrl];
- assert(ctr);
-
- snprintf(buf, sizeof(buf), "%d", pid);
-
- r = _write_single(ctr, FILENAME(group), CFILE_TASKS, buf);
- if (r == -1)
- return -1;
-
- return 0;
-}
-
-static int _foreach_pid(struct ctrl *ctr, const char *group,
- cgutil_iter_pid_callback cb, void *user_data)
-{
- int r;
- FILE *fp;
- char path[FILENAME_MAX];
-
- assert(ctr);
- assert(cb);
-
- snprintf(path, sizeof(path), "%s/%s/%s",
- ctr->root, FILENAME(group), CFILE_TASKS);
- fp = fopen(path, "r");
- if (!fp) {
- _E("open: %s: %s", path, strerror(errno));
- return -1;
- }
-
- while (!feof(fp)) {
- unsigned long l;
-
- r = fscanf(fp, "%lu", &l);
- if (r != 1)
- break;
-
- r = cb(user_data, group, l);
- if (r == -1)
- break;
- }
-
- fclose(fp);
-
- return 0;
-}
-
-int cgutil_group_foreach_pid(struct cginfo *cg,
- enum ctrl_type ctrl, const char *group,
- cgutil_iter_pid_callback cb, void *user_data)
-{
- struct ctrl *ctr;
-
- assert(ctrl >= 0 && ctrl < CTRL_MAX);
-
- if (!cg || !group || !*group || !cb) {
- errno = EINVAL;
- _E("cgutil foreach pid: %s", strerror(errno));
- return -1;
- }
-
- ctr = &cg->ctrls[ctrl];
- assert(ctr);
-
- return _foreach_pid(ctr, group, cb, user_data);
-}
-
-static int _foreach_group(struct ctrl *ctr,
- cgutil_iter_group_callback cb, void *user_data)
-{
- int r;
- DIR *d;
- struct dirent *de;
-
- assert(ctr);
- assert(cb);
-
- d = opendir(ctr->root);
- if (!d) {
- _E("open: %s: %s", ctr->root, strerror(errno));
- return -1;
- }
-
- for (de = readdir(d); de; de = readdir(d)) {
- if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
- continue;
-
- r = cb(user_data, de->d_name);
- if (r == -1)
- break;
- }
-
- closedir(d);
-
- return 0;
-}
-
-int cgutil_foreach_group(struct cginfo *cg, enum ctrl_type ctrl,
- cgutil_iter_group_callback cb, void *user_data)
-{
- struct ctrl *ctr;
-
- assert(ctrl >= 0 && ctrl < CTRL_MAX);
-
- if (!cg || !cb) {
- errno = EINVAL;
- _E("cgutil foreach group: %s", strerror(errno));
- return -1;
- }
-
- ctr = &cg->ctrls[ctrl];
- assert(ctr);
-
- return _foreach_group(ctr, cb, user_data);
-}
+++ /dev/null
-
-#ifndef __AUL_AMD_CGROUP_UTIL_H__
-#define __AUL_AMD_CGROUP_UTIL_H__
-
-enum ctrl_type {
- CTRL_MGR, /* for manager */
-#if defined(USE_CGROUP_CPU) /* not implemented */
- CTRL_CPU, /* cpuset */
-#endif
-#if defined(USE_CGROUP_MEM) /* not implemented */
- CTRL_MEM, /* memory */
-#endif
- /* TODO: add more */
- CTRL_MAX,
-};
-
-struct cginfo;
-
-int cgutil_create(const char *mount_point, const char *agent_path,
- struct cginfo **cg);
-void cgutil_destroy(struct cginfo **cg);
-
-struct cginfo *cgutil_ref(struct cginfo *cg);
-#define cgutil_unref(cg) cgutil_destroy(cg)
-
-
-int cgutil_create_group(struct cginfo *cg,
- enum ctrl_type ctrl, const char *group);
-int cgutil_remove_group(struct cginfo *cg,
- enum ctrl_type ctrl, const char *group);
-int cgutil_exist_group(struct cginfo *cg,
- enum ctrl_type ctrl, const char *group);
-
-typedef int (*cgutil_iter_group_callback)(void *user_data, const char *group);
-int cgutil_foreach_group(struct cginfo *cg, enum ctrl_type ctrl,
- cgutil_iter_group_callback cb, void *user_data);
-
-
-int cgutil_group_add_pid(struct cginfo *cg,
- enum ctrl_type ctrl, const char *group, pid_t pid);
-
-typedef int (*cgutil_iter_pid_callback)(void *user_data, const char *group,
- pid_t pid);
-int cgutil_group_foreach_pid(struct cginfo *cg,
- enum ctrl_type ctrl, const char *group,
- cgutil_iter_pid_callback cb, void *user_data);
-
-#endif /* __AUL_AMD_CGROUP_UTIL_H__ */
*
*/
+#define _GNU_SOURCE
#include <Ecore_X.h>
#include <Ecore_Input.h>
+#ifdef _APPFW_FEATURE_AMD_KEY
#include <utilX.h>
+#endif
#include <Ecore.h>
#include <Evas.h>
#include <aul.h>
#include <glib.h>
+#include <bundle_internal.h>
#include "amd_config.h"
#include "amd_key.h"
Ecore_Event_Handler *key_up;
Ecore_Event_Handler *key_down;
} key_info = {
- .win = NULL,
+ .win = 0,
.key_up = NULL,
.key_down = NULL,
};
GSList *key_pid_list = NULL;
+#ifdef _APPFW_FEATURE_AMD_KEY
static Eina_Bool __key_release_cb(void *data, int type, void *event);
static Eina_Bool __key_press_cb(void *data, int type, void *event);
return ECORE_CALLBACK_RENEW;
}
+ if (strcmp(ev->keyname, X_KEY_BACK) == 0) {
+ _D("skip back key case");
+ return ECORE_CALLBACK_RENEW;
+ }
+
entry = key_pid_list;
if (entry && entry->data) {
pid_data = (int *) entry->data;
return ECORE_CALLBACK_RENEW;
}
+ if (strcmp(ev->keyname, X_KEY_BACK) == 0) {
+ _D("skip back key case");
+ return ECORE_CALLBACK_RENEW;
+ }
+
entry = key_pid_list;
if (entry && entry->data) {
pid_data = (int *) entry->data;
return ECORE_CALLBACK_RENEW;
}
+#endif
int _register_key_event(int pid)
{
+#ifdef _APPFW_FEATURE_AMD_KEY
int *pid_data;
GSList *entry;
_D("pid : %d",*pid_data);
}
}
-
+#endif
return 0;
}
int _unregister_key_event(int pid)
{
+#ifdef _APPFW_FEATURE_AMD_KEY
GSList *entry;
int *pid_data;
_D("pid : %d",*pid_data);
}
}
-
+#endif
return 0;
}
int _key_init()
{
+#ifdef _APPFW_FEATURE_AMD_KEY
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");
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);
- utilx_grab_key(ecore_x_display_get(), key_info.win, KEY_NEXTSONG, SHARED_GRAB);
- utilx_grab_key(ecore_x_display_get(), key_info.win, KEY_PREVIOUSSONG, SHARED_GRAB);
- utilx_grab_key(ecore_x_display_get(), key_info.win, KEY_REWIND, SHARED_GRAB);
- utilx_grab_key(ecore_x_display_get(), key_info.win, KEY_FASTFORWARD, SHARED_GRAB);
- utilx_grab_key(ecore_x_display_get(), key_info.win, KEY_PLAYPAUSE, SHARED_GRAB);
+ utilx_grab_key(ecore_x_display_get(), key_info.win, X_KEY_PLAYCD, SHARED_GRAB);
+ utilx_grab_key(ecore_x_display_get(), key_info.win, X_KEY_STOPCD, SHARED_GRAB);
+ utilx_grab_key(ecore_x_display_get(), key_info.win, X_KEY_PAUSECD, SHARED_GRAB);
+ utilx_grab_key(ecore_x_display_get(), key_info.win, X_KEY_NEXTSONG, SHARED_GRAB);
+ utilx_grab_key(ecore_x_display_get(), key_info.win, X_KEY_PREVIOUSSONG, SHARED_GRAB);
+ utilx_grab_key(ecore_x_display_get(), key_info.win, X_KEY_REWIND, SHARED_GRAB);
+ utilx_grab_key(ecore_x_display_get(), key_info.win, X_KEY_FASTFORWARD, SHARED_GRAB);
+ utilx_grab_key(ecore_x_display_get(), key_info.win, X_KEY_PLAYPAUSE, SHARED_GRAB);
key_info.key_up = ecore_event_handler_add(ECORE_EVENT_KEY_UP, __key_release_cb, NULL);
if (!key_info.key_up) {
if (!key_info.key_down) {
_D("Failed to register a key down event handler");
}
+#endif
+ return 0;
+}
+
+int _key_grab(const char* key, int grab_mode)
+{
+#ifdef _APPFW_FEATURE_AMD_KEY
+ int ret;
+
+ if (!key_info.win) {
+ _D("There is no created hidden window");
+ }
+
+ _D("_key_grab, win : %x", key_info.win);
+
+ ret = utilx_grab_key(ecore_x_display_get(), key_info.win, key, grab_mode);
+ if(ret < 0) {
+ _W("fail(%d) to grab key(%s-%d)", ret, key, grab_mode);
+ }
+ return ret;
+#else
return 0;
+#endif
}
+int _key_ungrab(const char* key)
+{
+#ifdef _APPFW_FEATURE_AMD_KEY
+ int ret;
+
+ if (!key_info.win) {
+ _D("There is no created hidden window");
+ }
+
+ _D("_key_ungrab, win : %x", key_info.win);
+
+ ret = utilx_ungrab_key(ecore_x_display_get(), key_info.win, key);
+ if(ret < 0) {
+ _W("fail(%d) to ungrab key(%s)", ret, key);
+ }
+
+ return ret;
+#else
+ return 0;
+#endif
+}
#include <Ecore_X.h>
+#define X_KEY_PLAYCD "XF86AudioPlay"
+#define X_KEY_STOPCD "XF86AudioStop"
+#define X_KEY_PAUSECD "XF86AudioPause"
+#define X_KEY_NEXTSONG "XF86AudioNext"
+#define X_KEY_PREVIOUSSONG "XF86AudioPrev"
+#define X_KEY_REWIND "XF86AudioRewind"
+#define X_KEY_FASTFORWARD "XF86AudioForward"
+#define X_KEY_PLAYPAUSE "XF86AudioPlayPause"
+#define X_KEY_BACK "XF86Stop"
+
int _key_init(void);
int _register_key_event(int pid);
int _unregister_key_event(int pid);
Ecore_X_Window _input_window_get(void);
+int _key_grab(const char* key, int grab_mode);
+int _key_ungrab(const char* key);
#endif
*
*/
+#define _GNU_SOURCE
#include <signal.h>
#include <Ecore_X.h>
#include <Ecore_Input.h>
+#ifdef _APPFW_FEATURE_AMD_KEY
#include <utilX.h>
+#endif
#include <Ecore.h>
#include <Evas.h>
#include <Ecore_Evas.h>
-
+#include <security-server.h>
+#include <aul_svc.h>
#include <bundle.h>
+#include <bundle_internal.h>
#include <aul.h>
+#include <aul_svc.h>
+#include <aul_svc_priv_key.h>
#include <glib.h>
#ifdef _APPFW_FEATURE_APP_CHECKER
#include <app-checker-server.h>
#include <vconf.h>
#include <proc_stat.h>
#include <poll.h>
+#include <ttrace.h>
+#include <sys/smack.h>
+#include <security-server-perm.h>
+
+#ifdef _APPFW_FEATURE_PRIVATE_SERVICE
+#include <cert-service.h>
+#endif
#include "amd_config.h"
#include "amd_launch.h"
#include "amd_key.h"
#include "app_sock.h"
#include "simple_util.h"
-#include "amd_cgutil.h"
#include "launch.h"
#include "app_signal.h"
+#include "amd_app_group.h"
+#include "amd_request.h"
-#define DAC_ACTIVATE
+#define PREEXEC_ACTIVATE
+#include "preexec.h"
+#define DAC_ACTIVATE
#include "access_control.h"
+#ifdef _APPFW_FEATURE_EXPANSION_PKG_INSTALL
+#include "appfw_env.h"
+#endif
#define TERM_WAIT_SEC 3
#define INIT_PID 1
#define SDK_DYNAMIC_ANALYSIS "DYNAMIC_ANALYSIS"
#define PATH_DA_SO "/home/developer/sdk_tools/da/da_probe.so"
+#ifdef _APPFW_FEATURE_FAKE_EFFECT
#define PHONE_ORIENTATION_MODE "memory/private/sensor/10001"
-#define AMD_EFFECT_IMAGE_ENABLE "db/setting/effect_image"
#define PHONE_ROTATE_LOCK "db/setting/auto_rotate_screen"
+#endif
#define SYS_MIN_CPU_LOCK_FILE "/sys/devices/system/cpu/cpufreq/slp/min_cpu_lock"
#define MIN_CPU_LCK_CNT 0
#define HIDE_INDICATOR 0
#define SHOW_INDICATOR 1
+#define PROC_STATUS_LAUNCH 0
+#define PROC_STATUS_FG 3
+#define PROC_STATUS_BG 4
#ifdef _APPFW_FEATURE_CPU_BOOST
#define APP_BOOSTING_PERIOD 1500 //msec
#endif
+#ifdef _APPFW_FEATURE_PRIVATE_SERVICE
+#define OSP_K_LAUNCH_TYPE "__OSP_LAUNCH_TYPE__"
+#define OSP_V_LAUNCH_TYPE_DATACONTROL "datacontrol"
+#endif
+
static char *amd_cmdline;
struct appinfomgr *_laf;
-struct cginfo *_lcg;
DBusConnection *conn;
+#ifdef _APPFW_FEATURE_AMD_KEY
guint grab_timer_id;
+#endif
+
+static GList *_fgmgr_list;
+struct fgmgr {
+ guint tid;
+ int pid;
+};
#if 0
/*Unused data structure. Will be removed*/
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, 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 int __send_proc_prelaunch_signal(const char *appid, const char *pkgid, int attribute);
+int invoke_dbus_method_sync(const char *dest, const char *path,
+ const char *interface, const char *method,
+ const char *sig, char *param[]);
static void _set_sdk_env(const char* appid, char* str) {
char buf[MAX_LOCAL_BUFSZ];
setenv("HWACC", hwacc, 1);
}
+static void __set_oom(void)
+{
+ char buf[MAX_OOM_ADJ_BUFSZ] = {0,};
+ FILE *fp = NULL;
+
+ /* we should reset oomadj value as default because child
+ inherits from parent oom_adj*/
+ snprintf(buf, MAX_OOM_ADJ_BUFSZ, "/proc/%d/oom_score_adj", getpid());
+ fp = fopen(buf, "w");
+ if (fp == NULL)
+ return;
+ fprintf(fp, "%d", 100);
+ fclose(fp);
+}
+
static void _prepare_exec(const char *appid, bundle *kb)
{
const struct appinfo *ai;
signal(SIGTERM, SIG_DFL);
signal(SIGCHLD, SIG_DFL);
+ __set_oom();
+
ai = appinfo_find(_laf, appid);
app_path = appinfo_get_value(ai, AIT_EXEC);
pkg_type = appinfo_get_value(ai, AIT_TYPE);
hwacc = appinfo_get_value(ai, AIT_HWACC);
+ __preexec_run(pkg_type, appid, app_path);
+
/* SET PRIVILEGES*/
- _D("appid : %s / pkg_type : %s / app_path : %s ", appid, pkg_type, app_path);
+ SECURE_LOGD("appid : %s / pkg_type : %s / app_path : %s ", appid, pkg_type, app_path);
if (pkg_type && 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;
_set_env(appid, kb, hwacc);
}
-static int _add_cgroup(struct cginfo *cg, const char *group, int pid)
-{
- int r;
-
- r = cgutil_exist_group(cg, CTRL_MGR, group);
- if (r == -1) {
- _E("exist check error: %s", strerror(errno));
- return -1;
- }
-
- if (r == 0) { /* not exist */
- r = cgutil_create_group(cg, CTRL_MGR, group);
- if (r == -1) {
- _E("create group error");
- return -1;
- }
- }
-
- r = cgutil_group_add_pid(cg, CTRL_MGR, group, pid);
- if (r == -1) {
- _E("add pid to group error");
- cgutil_remove_group(cg, CTRL_MGR, group);
- return -1;
- }
-
- return 0;
-}
-
static char **__create_argc_argv(bundle * kb, int *margc)
{
char **argv;
*margc = argc;
return argv;
}
-static void _do_exec(struct cginfo *cg, const char *cmd, const char *group, bundle *kb)
+static void _do_exec(const char *cmd, const char *group, bundle *kb)
{
gchar **argv;
gint argc;
char **b_argv;
int b_argc;
gboolean b;
- int r;
-
- r = _add_cgroup(cg, group, getpid());
- if (r == -1)
- return;
b = g_shell_parse_argv(cmd, &argc, &argv, NULL);
dbus_connection_flush(conn);
dbus_message_unref(message);
- _D("send launch signal done\n");
+ _W("send launch signal done: %d", launch_pid);
return 0;
}
return -1;
}
+#ifdef _APPFW_FEATURE_COOLDOWN_MODE_SUPPORT
if(_status_get_cooldown_status() == COOLDOWN_LIMIT) {
_E("[Info]cooldown status : LimitAction");
return -1;
}
+#endif // _APPFW_FEATURE_COOLDOWN_MODE_SUPPORT
message = dbus_message_new_signal(RESOURCED_PROC_OBJECT,
RESOURCED_PROC_INTERFACE,
dbus_connection_flush(conn);
dbus_message_unref(message);
- _D("send launch signal done\n");
+ _W("send a watchdog signal done: %d", pid);
+
+ return 0;
+}
+
+static int __send_proc_prelaunch_signal(const char *appid, const char *pkgid, int attribute)
+{
+ DBusMessage *message;
+
+ if (conn == NULL)
+ return -1;
+
+ message = dbus_message_new_signal(RESOURCED_PROC_OBJECT,
+ RESOURCED_PROC_INTERFACE,
+ RESOURCED_PROC_PRELAUNCH_SIGNAL);
+
+ if (dbus_message_append_args(message,
+ DBUS_TYPE_STRING, &appid,
+ DBUS_TYPE_STRING, &pkgid,
+ DBUS_TYPE_INT32, &attribute,
+ 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);
+
+ SECURE_LOGW("send a prelaunch signal done: appid(%s) pkgid(%s) attribute(%x)", appid, pkgid, attribute);
return 0;
}
int wait_count;
int cmdline_changed = 0;
int cmdline_exist = 0;
- int r;
if (ret <= 1)
return -1;
cmdline = __proc_get_cmdline_bypid(ret);
if (cmdline == NULL) {
_E("error founded when being launched with %d", ret);
-
+ if (cmdline_exist || cmdline_changed) {
+ _E("The app process might be terminated while we are wating %d", ret);
+ break;
+ }
} else if (strcmp(cmdline, amd_cmdline)) {
free(cmdline);
cmdline_changed = 1;
} while (wait_count <= 20); /* max 50*20ms will be sleep*/
if ((!cmdline_exist) && (!cmdline_changed)) {
+ _E("cmdline_exist 0 & cmdline_changed 0");
return -1;
}
return ret;
}
-int service_start(struct cginfo *cg, const char *group, const char *cmd, bundle *kb)
+int start_process(const char *group, const char *cmd, bundle *kb)
{
int r;
pid_t p;
- if (!cg || !group || !*group || !cmd || !*cmd) {
- errno = EINVAL;
- _E("service start: %s", strerror(errno));
- return -1;
- }
-
p = fork();
switch (p) {
case 0: /* child process */
- _D("start service");
+ _D("start application");
+ _signal_unblock_sigchld();
#ifdef _APPFW_FEATURE_PRIORITY_CHANGE
r = setpriority(PRIO_PROCESS, 0, 0);
if (r == -1)
getpid(), errno, strerror(errno));
}
#endif
- _do_exec(cg, cmd, group, kb);
+ _do_exec(cmd, group, kb);
/* exec error */
exit(0);
break;
case -1:
- _E("service start: fork: %s", strerror(errno));
+ _E("application start: fork: %s", strerror(errno));
r = -1;
break;
default: /* parent process */
- _D("child process: %d", p);
+ _W("child process: %d", p);
r = __check_cmdline(p);
if(r > 0)
__send_app_launch_signal(r);
+ else
+ _E("cmdline change failed.");
break;
}
return r;
}
-int _start_srv(const struct appinfo *ai, bundle *kb)
+static int __check_ver(const char *required, const char *actual)
+{
+ int ret = 0;
+ if (required && actual) {
+ ret = strverscmp(required, actual); // should 0 or less
+ if (ret < 1)
+ return 1;
+ }
+
+ return 0;
+}
+
+static int __get_prelaunch_attribute(const struct appinfo *ai)
+{
+ int attribute_val = 0;
+ const char *attribute_str = NULL;
+
+ attribute_str = appinfo_get_value(ai, AIT_ALLOWED_BG);
+ if (attribute_str && strncmp(attribute_str, "ALLOWED_BG", sizeof("ALLOWED_BG")) == 0) {
+ attribute_val |= RESOURCED_ALLOWED_BG_ATTRIBUTE;
+ }
+
+#ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
+ attribute_val |= RESOURCED_BACKGROUND_MANAGEMENT_ATTRIBUTE;
+#endif
+
+ attribute_str = appinfo_get_value(ai, AIT_API_VER);
+ if (attribute_str && __check_ver("2.4", attribute_str)) {
+ attribute_val |= RESOURCED_API_VER_2_4_ATTRIBUTE;
+ }
+
+ return attribute_val;
+}
+
+int _start_srv(const struct appinfo *ai)
{
int r;
+ bundle *b = NULL;
const char *group;
const char *cmd;
const char *pkgid;
+ const char *appid = NULL;
+ int prelaunch_attribute = 0;
group = appinfo_get_filename(ai);
return -1;
}
- r = service_start(_lcg, group, cmd, kb);
+ appid = appinfo_get_value(ai, AIT_NAME);
+ pkgid = appinfo_get_value(ai, AIT_PKGID);
+
+ prelaunch_attribute = __get_prelaunch_attribute(ai);
+ if ((prelaunch_attribute & RESOURCED_ALLOWED_BG_ATTRIBUTE) ||
+ !(prelaunch_attribute & RESOURCED_API_VER_2_4_ATTRIBUTE)) {
+ SECURE_LOGD("[__SUSPEND__] allowed background, appid :%s, app_type: %s, api version: %s",
+ appid, APP_TYPE_SERVICE, appinfo_get_value(ai, AIT_API_VER));
+ if (b == NULL) {
+ b = bundle_create();
+ }
+
+ bundle_add(b, AUL_K_ALLOWED_BG, "ALLOWED_BG");
+ }
+
+ __send_proc_prelaunch_signal(appid, pkgid, prelaunch_attribute);
+
+ r = start_process(group, cmd, b);
+ if (b) {
+ bundle_free(b);
+ b = NULL;
+ }
+
if (r == -1) {
_E("start service: '%s': failed", group);
+
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);
+ aul_send_app_launch_request_signal(r, group, pkgid, APP_TYPE_SERVICE);
+ _status_add_app_info_list(group, cmd, NULL, r, -1, 0);
return 0;
}
if (!kt)
return;
- cgutil_unref(&kt->cg);
free(kt->group);
free(kt);
}
if (pid <= INIT_PID) /* block sending to all process or init */
return;
- r = cgutil_exist_group(cg, CTRL_MGR, group);
- if (r == -1) {
- _E("send SIGKILL: exist: %s", strerror(errno));
- return;
- }
- if (r == 0) {
- _D("send SIGKILL: '%s' not exist", group);
- return;
- }
-
/* TODO: check pid exist in group */
r = kill(pid, 0);
if (r == -1) {
- _D("send SIGKILL: pid %d not exist", pid);
+ _E("send SIGKILL: pid %d not exist", pid);
return;
}
return;
}
- kt->cg = cgutil_ref(cg);
kt->tid = g_timeout_add_seconds(TERM_WAIT_SEC, _ktimer_cb, kt);
_kill_list = g_list_append(_kill_list, kt);
return 0;
}
-int service_stop(struct cginfo *cg, const char *group)
-{
- if (!cg || !group || !*group) {
- errno = EINVAL;
- return -1;
- }
-
- _D("service_stop, group %s", group);
-
- return cgutil_group_foreach_pid(cg, CTRL_MGR, FILENAME(group),
- _kill_pid_cb, cg);
-}
-
void service_release(const char *group)
{
GList *l;
}
__real_send(clifd, ret);
}
- _D("resume done\n");
+ _W("resume done\n");
if (ret > 0)
__set_reply_handler(ret, pid, clifd, APP_RESUME_BY_PID);
return ret;
}
+int _pause_app(int pid, int clifd)
+{
+ int dummy;
+ int ret;
+ if ((ret =
+ __app_send_raw_with_delay_reply(pid, APP_PAUSE_BY_PID, (unsigned char *)&dummy,
+ sizeof(int))) < 0) {
+ if (ret == -EAGAIN)
+ _E("pause packet timeout error");
+ else {
+ _E("iconify failed - %d pause fail\n", pid);
+ _E("we will term the app - %d\n", pid);
+ _send_to_sigkill(pid);
+ ret = -1;
+ }
+ }
+
+ _D("pause done\n");
+ close(clifd);
+
+ return ret;
+}
+
int _fake_launch_app(int cmd, int pid, bundle * kb, int clifd)
{
int datalen;
int ret;
- bundle_raw *kb_data;
+ bundle_raw *kb_data = NULL;
+
+ if (!kb){
+ __real_send(clifd, -EINVAL);
+ return -EINVAL;
+ }
- bundle_encode(kb, &kb_data, &datalen);
+ ret = bundle_encode(kb, &kb_data, &datalen);
+ if (ret != BUNDLE_ERROR_NONE) {
+ __real_send(clifd, -EINVAL);
+ return -EINVAL;
+ }
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);
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");
close(fd);
if(res < 0) {
- if ( cmd == APP_TERM_BY_PID ) {
+ if (cmd == APP_TERM_BY_PID || cmd == APP_TERM_BGAPP_BY_PID) {
__real_send(clifd, -1);
- } else if ( cmd == APP_START_ASYNC ) {
+ } else if (cmd == APP_START_ASYNC || cmd == APP_PAUSE_BY_PID) {
close(clifd);
} else {
__real_send(clifd, res);
}
} else {
- if ( cmd == APP_TERM_BY_PID ) {
+ if (cmd == APP_TERM_BY_PID || cmd == APP_TERM_BGAPP_BY_PID) {
__real_send(clifd, 0);
- } else if ( cmd == APP_START_ASYNC ) {
+ } else if (cmd == APP_START_ASYNC || cmd == APP_PAUSE_BY_PID) {
close(clifd);
} else {
__real_send(clifd, pid);
}
}
- _D("listen fd(%d) , send fd(%d), pid(%d), cmd(%d)", fd, clifd, pid, cmd);
+ _W("listen fd(%d) , send fd(%d), pid(%d), cmd(%d)", fd, clifd, pid, cmd);
g_source_remove(r_info->timer_id);
g_source_remove_poll(r_info->src, r_info->gpollfd);
{
struct reply_info *r_info = (struct reply_info *) data;
int fd = r_info->gpollfd->fd;
+ char *appid = NULL;
+ const struct appinfo *ai;
+ int task_manage = 0;
_E("application is not responding : pid(%d) cmd(%d)", r_info->pid, r_info->cmd);
#ifdef _APPFW_FEATURE_MULTI_INSTANCE
case APP_START_MULTI_INSTANCE:
#endif
- __send_watchdog_signal(r_info->pid, SIGKILL);
+ appid = _status_app_get_appid_bypid(r_info->pid);
+ if(appid == NULL)
+ break;
+ ai = appinfo_find(_laf, appid);
+ if(ai == NULL) {
+ _E("ai is NULL");
+ break;
+ }
+ task_manage = appinfo_get_boolean(ai, AIT_TASKMANAGE);
+ if(task_manage) {
+ __send_watchdog_signal(r_info->pid, SIGKILL);
+ }
break;
case APP_TERM_BY_PID:
+ case APP_TERM_BGAPP_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;
+ } else {
+ __real_send(r_info->clifd, 0);
}
- __real_send(r_info->clifd, 0);
break;
}
g_source_unref(src);
return;
}
-
gpollfd->events = POLLIN;
gpollfd->fd = fd;
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,
_D("listen fd : %d, send fd : %d", fd, clifd);
}
+void _term_sub_app(int pid)
+{
+ int dummy;
+ int ret;
+ char *appid = NULL;
+ const char *pkgid = NULL;
+ const char *type = NULL;
+ const struct appinfo *ai = NULL;
+
+ appid = _status_app_get_appid_bypid(pid);
+ ai = appinfo_find(_laf, appid);
+ pkgid = appinfo_get_value(ai, AIT_PKGID);
+ type = appinfo_get_value(ai, AIT_COMPTYPE);
+
+ aul_send_app_terminate_request_signal(pid, appid, pkgid, type);
+ if ( (ret = __app_send_raw_with_noreply(pid, APP_TERM_BY_PID_ASYNC,
+ (unsigned char *)&dummy, sizeof(int))) < 0) {
+ _E("terminate packet send error - use SIGKILL");
+ if (_send_to_sigkill(pid) < 0) {
+ _E("fail to killing - %d\n", pid);
+ return;
+ }
+ }
+}
+
int _term_app(int pid, int clifd)
{
int dummy;
int ret;
+ if (app_group_is_leader_pid(pid)) {
+ int cnt;
+ int *pids = NULL;
+ int i;
+
+ app_group_get_group_pids(pid, &cnt, &pids);
+ if (cnt > 0) {
+ for (i = cnt-1 ; i>=0; i--) {
+ if (i != 0)
+ _term_sub_app(pids[i]);
+ app_group_remove(pids[i]);
+
+ }
+ }
+ if (pids)
+ free(pids);
+ }
+
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");
return 0;
}
+int _term_req_app(int pid, int clifd)
+{
+ int dummy;
+ int ret;
+
+ if ( (ret = __app_send_raw_with_delay_reply
+ (pid, APP_TERM_REQ_BY_PID, (unsigned char *)&dummy, sizeof(int))) < 0) {
+ _D("terminate req send error");
+ __real_send(clifd, ret);
+ }
+
+ if (ret > 0)
+ __set_reply_handler(ret, pid, clifd, APP_TERM_REQ_BY_PID);
+
+ return 0;
+}
+
+int _term_bgapp(int pid, int clifd)
+{
+ int dummy;
+ int fd;
+
+ if (app_group_is_leader_pid(pid)) {
+ int cnt;
+ int *pids = NULL;
+ int i;
+ int status = -1;
+
+ app_group_get_group_pids(pid, &cnt, &pids);
+ if (cnt > 0) {
+ status = _status_get_app_info_status(pids[cnt-1]);
+ if(status == STATUS_BG) {
+ for (i = cnt-1 ; i>=0; i--) {
+ if (i != 0)
+ _term_sub_app(pids[i]);
+ app_group_remove(pids[i]);
+ }
+ }
+ }
+ if (pids)
+ free(pids);
+ }
+
+ if ( (fd = __app_send_raw_with_delay_reply
+ (pid, APP_TERM_BGAPP_BY_PID, (unsigned char *)&dummy, sizeof(int))) < 0) {
+ _D("terminate packet send error - use SIGKILL");
+ if (_send_to_sigkill(pid) < 0) {
+ _E("fail to killing - %d\n", pid);
+ __real_send(clifd, -1);
+ return -1;
+ }
+ __real_send(clifd, 0);
+ }
+ _D("term_bgapp done\n");
+ if (fd > 0)
+ __set_reply_handler(fd, pid, clifd, APP_TERM_BGAPP_BY_PID);
+
+ return 0;
+}
+
#include <dirent.h>
#include <sqlite3.h>
static int __launchpad_update_task_managed_field(const char* app_id, int task_managed)
if (S_ISDIR(file_status.st_mode)) {
int ret;
DIR *dir = NULL;
- struct dirent entry, *result;
+ struct dirent entry, *result = NULL;
dir = opendir(PRE_LAUNCHING_LIST_DIR);
static int __nofork_processing(int cmd, int pid, bundle * kb, int clifd)
{
int ret = -1;
- int r;
+#ifdef _APPFW_FEATURE_CPU_BOOST
const char *operation;
operation = bundle_get_val(kb, "__APP_SVC_OP_TYPE__");
-#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 ||
_D("%s-%s : %d", SYSTEM_INTERFACE_NAME, SYSTEM_METHOD_NAME, ret);
}
#endif
- _D("__nofork_processing, cmd: %d, pid: %d", cmd, pid);
+ _W("__nofork_processing, cmd: %d, pid: %d", cmd, pid);
switch (cmd) {
case APP_OPEN:
case APP_RESUME:
_E("fake_launch failed. error code = %d", ret);
_D("fake launch done");
break;
+
+ default:
+ break;
}
return ret;
Ecore_Timer *timer;
};
-static int __amd_change_min_cpulock_count(int value)
-{
- int fd = -1;
- char buf[16]={0,};
- fd = open(SYS_MIN_CPU_LOCK_FILE, O_WRONLY);
- if (fd == -1)
- return -1;
- snprintf(buf, sizeof(buf), "%d", value);
- if (write(fd, buf, strlen(buf)) < 0) {
- _E("[AMD]: Unable to change min_cpu_lock value!, err: %s\n",strerror(errno));
- close(fd);
- return -1;
- }
- close(fd);
- _D("[AMD]: Succesfully changed min cpu value to %d\n", value);
- return 0;
-}
-
-static Eina_Bool __amd_restore_min_cpulock_count_cb(void *data)
-{
- struct context *ctxt = data;
- if (ctxt->timer)
- ctxt->timer = NULL;
- __amd_change_min_cpulock_count(MIN_CPU_LCK_CNT);
- return ECORE_CALLBACK_CANCEL;
-}
-
+#ifdef _APPFW_FEATURE_FAKE_EFFECT
static void __amd_effect_image_file_set(char *image_file)
{
Ecore_X_Window root_win;
+
+ if(!_window_is_initialized())
+ return;
+
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);
+ 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, int effect_type, int theme)
{
+ traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "AUL:AMD:EFFECT_START");
Ecore_X_Window root_win;
int ret;
+
+ if (!_window_is_initialized()) {
+ traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
+ return;
+ }
+
root_win = ecore_x_window_root_first_get();
_D("root win : %x",root_win);
int screen_orientation[5]={0,0,270,180,90};
if (screenmode > 4 || screenmode < 0)
screenmode=0;
- if (strncmp(indicator, "true", 4) == 0){
+ if (strncmp(indicator, "true", 4) == 0) {
_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,
screen_orientation[screenmode],
SHOW_INDICATOR, theme, 0);
- }else{
+ } else {
_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_flush();
_D("ecore_x_client_message32_send : %d",ret);
+ traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
}
-
-
+#endif
static int append_variant(DBusMessageIter *iter, const char *sig, char *param[])
{
return ret;
}
+#ifdef _APPFW_FEATURE_AMD_KEY
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);
+ if(_key_ungrab(KEY_BACK) < 0) {
+ _W("back key ungrab error");
+ } else {
+ _D("back key ungrab");
+ }
return FALSE;
}
+#endif
-static bool __check_ug_client_process_pool(const char *app_path)
+static gboolean __fg_timeout_handler(gpointer data)
{
- char sympath[MAX_PACKAGE_APP_PATH_SIZE] = {0,};
- int ret;
- bool func_ret = true;
+ struct fgmgr *fg = data;
- 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 (!fg)
+ return FALSE;
- 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;
- }
+ _status_update_app_info_list(fg->pid, STATUS_BG, TRUE);
- if(strncmp(sympath, "/usr/bin/ug-client", strlen("/usr/bin/ug-client")) != 0) {
- func_ret = false;
- }
+ _fgmgr_list = g_list_remove(_fgmgr_list, fg);
+ free(fg);
-func_out :
- _D("ug process pool check result : %d", func_ret);
- return func_ret;
+ return FALSE;
}
-#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)
+static void __add_fgmgr_list(int pid)
{
- 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;
+ struct fgmgr *fg;
- /* 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");
+ fg = calloc(1, sizeof(struct fgmgr));
+ if (!fg)
return;
- }
- SECURE_LOGD("callee appid : %s / caller_appid : %s", callee_appid, caller_appid);
+ fg->pid = pid;
+ fg->tid = g_timeout_add(5000, __fg_timeout_handler, fg);
- /* 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");
+ _fgmgr_list = g_list_append(_fgmgr_list, fg);
+}
+
+static void __del_fgmgr_list(int pid)
+{
+ GList *iter = NULL;
+ struct fgmgr *fg;
+
+ if (pid < 0)
return;
+
+ for (iter = _fgmgr_list; iter != NULL; iter = g_list_next(iter)) {
+ fg = (struct fgmgr *)iter->data;
+ if (fg->pid == pid) {
+ g_source_remove(fg->tid);
+ _fgmgr_list = g_list_remove(_fgmgr_list, fg);
+ free(fg);
+ return;
+ }
}
+}
- /* check aul_forwad_app case */
- if((caller_appid) && (strcmp(caller_appid, "org.tizen.app-selector") == 0)) {
- _D("forward app case");
- return;
+#ifdef _APPFW_FEATURE_EXPANSION_PKG_INSTALL
+static int __tep_mount(char *mnt_path[])
+{
+ DBusMessage *msg;
+ int func_ret = 0;
+ int rv = 0;
+ struct stat link_buf = {0,};
+
+ rv = lstat(mnt_path[0], &link_buf);
+ if (rv == 0) {
+ rv = unlink(mnt_path[0]);
+ if (rv)
+ _E("Unable tp remove link file %s", mnt_path[0]);
}
- /* 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;
+ msg = dbus_message_new_method_call(TEP_BUS_NAME, TEP_OBJECT_PATH,
+ TEP_INTERFACE_NAME, TEP_MOUNT_METHOD);
+ if (!msg) {
+ _E("dbus_message_new_method_call(%s:%s-%s)", TEP_OBJECT_PATH,
+ TEP_INTERFACE_NAME, TEP_MOUNT_METHOD);
+ return -1;
}
- if(caller_win_id == 0) {
- _D("caller id is 0");
- return;
+
+ if (!dbus_message_append_args(msg,
+ DBUS_TYPE_STRING, &mnt_path[0],
+ DBUS_TYPE_STRING, &mnt_path[1],
+ DBUS_TYPE_INVALID)) {
+ _E("Ran out of memory while constructing args\n");
+ func_ret = -1;
+ goto func_out;
}
- 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;
+ if (dbus_connection_send(conn, msg, NULL) == FALSE) {
+ _E("dbus_connection_send error");
+ func_ret = -1;
+ goto func_out;
}
+func_out :
+ dbus_message_unref(msg);
+ return func_ret;
+}
- do {
- const char *operation = NULL;
- operation = bundle_get_val(kb, "__APP_SVC_OP_TYPE__");
- if(operation == NULL) {
- _D("operation is null");
- break;
+static void __send_mount_request(const struct appinfo *ai, const char *tep_name,
+ bundle *kb)
+{
+ SECURE_LOGD("tep name is: %s", tep_name);
+ char *mnt_path[2] = {NULL, };
+ const char *installed_storage = NULL;
+ char tep_path[PATH_MAX] = {0, };
+
+ const char *pkgid = appinfo_get_value(ai, AIT_PKGID);
+ installed_storage = appinfo_get_value(ai, AIT_STORAGE_TYPE);
+ if (installed_storage != NULL) {
+ SECURE_LOGD("storage: %s", installed_storage);
+ if (strncmp(installed_storage, "internal", 8) == 0) {
+ snprintf(tep_path, PATH_MAX, "%s%s/res/%s", appfw_env_get_apps_path(), pkgid,
+ tep_name);
+ mnt_path[1] = strdup(tep_path);
+ snprintf(tep_path, PATH_MAX, "%s%s/res/tep", appfw_env_get_apps_path(), pkgid);
+ mnt_path[0] = strdup(tep_path);
+ } else if (strncmp(installed_storage, "external", 8) == 0) {
+ snprintf(tep_path, PATH_MAX, "%step/%s", appfw_env_get_external_storage_path(),
+ tep_name);
+ mnt_path[1] = strdup(tep_path);
+ snprintf(tep_path, PATH_MAX, "%step/tep-access",
+ appfw_env_get_external_storage_path()); /* TODO : keeping tep/tep-access for now for external storage */
+ mnt_path[0] = strdup(tep_path);
}
- 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;
+ if (mnt_path[0] && mnt_path[1]) {
+ bundle_add(kb, AUL_TEP_PATH, mnt_path[0]);
+ int ret = -1;
+ ret = aul_is_tep_mount_dbus_done(mnt_path[0]);
+ if (ret != 1) {
+ ret = __tep_mount(mnt_path);
+ if (ret < 0)
+ _E("dbus error %d", ret);
}
}
- } while (0);
+ if (mnt_path[0])
+ free(mnt_path[0]);
+ if (mnt_path[1])
+ free(mnt_path[1]);
+ }
+}
+#endif
- if(is_open_via_multi) {
- if(layout == 1)
- layout = 0;
- else
- layout = 1;
+static int __check_app_control_privilege(const char *operation, int caller_pid, const struct appinfo *caller)
+{
+ int ret;
+ const char *api_ver;
- _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;
- }
- }
+ if (caller == NULL) // daemon
+ return 0;
- char tmp_layout[128];
- char tmp_startup[128];
+ if (operation == NULL || caller_pid < 1)
+ return 0;
- snprintf(tmp_layout, 128, "%d", layout);
- snprintf(tmp_startup, 128, "%d", startup_type);
+ if (strcmp(operation, AUL_SVC_OPERATION_DOWNLOAD) == 0) {
+ api_ver = appinfo_get_value(caller, AIT_API_VER);
- 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");
- }
+ if (!api_ver) {
+ _E("failed to get api version");
+ return -1;
+ }
- SECURE_LOGD("window startup type(%d) and layout id(%d) is added", startup_type, layout);
+ if (api_ver && strverscmp("2.4", api_ver) < 1) { // ver 2.4 or later
+ ret = security_server_check_privilege_by_pid(caller_pid, "privilege::tizen::download", "rw");
+ if (ret != SECURITY_SERVER_API_SUCCESS) {
+ _E("caller %d violates http://tizen.org/privilege/download privilege (%d)", caller_pid, ret);
+ return -EILLEGALACCESS;
+ }
+ }
+ } else if (strcmp(operation, AUL_SVC_OPERATION_CALL) == 0) {
+ // Check the privilege for call operation
+ ret = security_server_check_privilege_by_pid(caller_pid, "privilege::tizen::call", "rw");
+ if (ret != SECURITY_SERVER_API_SUCCESS) {
+ _E("caller %d violates http://tizen.org/privilege/call privilege (%d)", caller_pid, ret);
+ return -EILLEGALACCESS;
+ }
+ }
- return;
+ return 0;
}
-#endif
+
int __check_mode(const struct appinfo *ai)
{
#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(tts_support && strncmp(tts_support, "false", 5) == 0)
+ _W("tts : %d %s", tts_mode, tts_support);
+ if(strncmp(tts_support, "false", 5) == 0) {
+ _W("Cannot launch this app in TTS mode");
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(ups_support && strncmp(ups_support, "false", 5) == 0)
- return -1;
+ if (ups_mode == SETTING_PSMODE_EMERGENCY) {
+ const char *ups_support = appinfo_get_value(ai, AIT_UPS);
+ _W("ups : %d %s", ups_mode, ups_support);
}
+#endif //_APPFW_FEATURE_ULTRA_POWER_SAVING_MODE
+
+ return 0;
+}
+
+static void __prepare_to_suspend_services(int pid)
+{
+ int dummy;
+ SECURE_LOGD("[__SUSPEND__] pid: %d", pid);
+ __app_send_raw_with_noreply(pid, APP_SUSPEND, (unsigned char *)&dummy, sizeof(int));
+}
+
+static void __prepare_to_wake_services(int pid)
+{
+ int dummy;
+ SECURE_LOGD("[__SUSPEND__] pid: %d", pid);
+ __app_send_raw_with_noreply(pid, APP_WAKE, (unsigned char *)&dummy, sizeof(int));
+}
+
+static gboolean __check_service_only(gpointer user_data)
+{
+ int pid = GPOINTER_TO_INT(user_data);
+ SECURE_LOGD("[__SUSPEND__] pid :%d", pid);
+
+ _status_check_service_only(pid, __prepare_to_suspend_services);
+
+ return FALSE;
+}
+
+#ifdef _APPFW_FEATURE_PRIVATE_SERVICE
+static int __get_visibility_from_cert_svc(const char *pkgid, int *visibility)
+{
+ int ret = 0;
+ const char *cert_value = NULL;
+ pkgmgrinfo_certinfo_h certinfo = NULL;
+
+ ret = pkgmgrinfo_pkginfo_create_certinfo(&certinfo);
+ if (ret != 0) {
+ _E("pkgmgrinfo_pkginfo_create_certinfo() failed.");
+ return -1;
+ }
+
+ ret = pkgmgrinfo_pkginfo_load_certinfo(pkgid, certinfo);
+ if (ret != 0) {
+ _E("pkgmgrinfo_pkginfo_load_certinfo() failed.");
+ ret = -1;
+ goto end;
+ }
+
+ ret = pkgmgrinfo_pkginfo_get_cert_value(certinfo, PMINFO_DISTRIBUTOR_ROOT_CERT,
+ &cert_value);
+ if (ret != 0 || cert_value == NULL) {
+ _E("pkgmgrinfo_pkginfo_get_cert_value() failed.");
+ ret = -1;
+ goto end;
+ }
+
+ ret = cert_svc_get_visibility_by_root_certificate(cert_value,
+ strlen(cert_value), visibility);
+ if (ret != 0) {
+ _E("cert_svc_get_visibility_by_root_cert() failed. err = [%d]", ret);
+ ret = -1;
+ goto end;
+ }
+ _D("visibility = [%d]", *visibility);
+
+end:
+ pkgmgrinfo_pkginfo_destroy_certinfo(certinfo);
+ return ret;
+}
#endif
+static int __can_share(const char *path, const char *pkgid)
+{
+ struct stat path_stat;
+
+ if (access(path, F_OK) != 0)
+ return -1;
+
+ if (stat(path, &path_stat) != 0)
+ return -1;
+
+ if (!S_ISREG(path_stat.st_mode))
+ return -1;
+
+ char buf[1024];
+
+ snprintf(buf, sizeof(buf) - 1, "/opt/usr/apps/%s/data/", pkgid);
+ if (strncmp(path, buf, strlen(buf)) != 0)
+ return -1;
+
+ return 0;
+}
+
+static int __get_current_security_attribute(int pid, char *buf, int size)
+{
+ int fd;
+ int ret;
+ char path[1024] = { 0, };
+
+ snprintf(path, sizeof(path) - 1, "/proc/%d/attr/current", pid);
+ fd = open(path, O_RDONLY);
+ if (fd < 0)
+ return -1;
+
+ ret = read(fd, buf, size - 1);
+ if (ret <= 0) {
+ close(fd);
+ return -1;
+ } else
+ buf[ret] = 0;
+
+ close(fd);
+
+ return 0;
+}
+
+static int __get_exec_label_by_pid(int pid, char** exec_label)
+{
+ const char *appid = NULL;
+ const char *exec = NULL;
+ const char *type = NULL;
+ const struct appinfo *ai = NULL;
+ char attr[1024] = { 0, };
+
+ if (__get_current_security_attribute(pid, attr, sizeof(attr)) == 0) {
+ *exec_label = strdup(attr);
+ return 0;
+ }
+
+ appid = _status_app_get_appid_bypid(pid);
+ if (appid) {
+ ai = appinfo_find(_laf, appid);
+ exec = appinfo_get_value(ai, AIT_EXEC);
+ type = appinfo_get_value(ai, AIT_TYPE);
+
+ if (exec && type) {
+ if (strcmp("wgt", type) == 0) {
+ if (smack_lgetlabel(exec, exec_label, SMACK_LABEL_EXEC) == 0)
+ return 0;
+ } else {
+ if (smack_getlabel(exec, exec_label, SMACK_LABEL_EXEC) == 0)
+ return 0;
+ }
+ }
+ }
+
+ return -1;
+}
+
+static int __get_exec_label_by_appid(const char *appid, char** exec_label)
+{
+ const char *exec = NULL;
+ const char *type = NULL;
+ const struct appinfo *ai = NULL;
+
+ if (appid) {
+ ai = appinfo_find(_laf, appid);
+ exec = appinfo_get_value(ai, AIT_EXEC);
+ type = appinfo_get_value(ai, AIT_TYPE);
+
+ if (exec && type) {
+ if (strcmp("wgt", type) == 0) {
+ if (smack_lgetlabel(exec, exec_label, SMACK_LABEL_EXEC) == 0)
+ return 0;
+ } else {
+ if (smack_getlabel(exec, exec_label, SMACK_LABEL_EXEC) == 0)
+ return 0;
+ }
+ }
+ }
+
+ return -1;
+}
+
+static int __get_owner_pid(int caller_pid, bundle *kb)
+{
+ char *org_caller = NULL;
+
+ if (bundle_get_str(kb, AUL_K_ORG_CALLER_PID, &org_caller) == BUNDLE_ERROR_NONE) {
+ int org_caller_pid = atoi(org_caller);
+ char *c_exec_label = NULL;
+
+ if (__get_exec_label_by_pid(caller_pid, &c_exec_label) == 0) {
+
+ if (c_exec_label &&
+ (strcmp(APP_SELECTOR, c_exec_label) == 0 ||
+ strcmp(SHARE_PANEL, c_exec_label) == 0))
+ caller_pid = org_caller_pid;
+ }
+
+ if (c_exec_label)
+ free(c_exec_label);
+ }
+
+ return caller_pid;
+}
+
+static int __get_exec_label(char **caller_exec_label, char **callee_exec_label,
+ int caller_pid, const char *appid)
+{
+ char *label_caller = NULL;
+ char *label = NULL;
+
+ if (__get_exec_label_by_pid(caller_pid, &label_caller) != 0) {
+ return -1;
+ }
+
+ if (__get_exec_label_by_appid(appid, &label) != 0) {
+ free(label_caller);
+ return -1;
+ }
+
+ *caller_exec_label = label_caller;
+ *callee_exec_label = label;
return 0;
}
-int _start_app(char* appid, bundle* kb, int cmd, int caller_pid, uid_t caller_uid, int fd)
+static int __grant_temporary_permission(int caller_pid, const char *appid, bundle *kb,
+ char **out_caller_exec_label, char **out_callee_exec_label,
+ char ***out_paths)
+{
+ int type = bundle_get_type(kb, AUL_SVC_DATA_PATH);
+ char *path = NULL;
+ const char **path_array = NULL;
+ int len;
+ char *caller_exec_label = NULL;
+ char *callee_exec_label = NULL;
+ int i;
+ char **paths = NULL;
+ int ret = -1;
+ int owner_pid = -1;
+ const char *tmp_appid = NULL;
+ const char *pkgid = NULL;
+ const struct appinfo *ai = NULL;
+
+ switch (type) {
+ case BUNDLE_TYPE_STR:
+ bundle_get_str(kb, AUL_SVC_DATA_PATH, &path);
+
+ if (!path) {
+ _E("path was null");
+ goto check_uri;
+ }
+
+ owner_pid = __get_owner_pid(caller_pid, kb);
+ owner_pid = getpgid(owner_pid); /* for webapp */
+ tmp_appid = _status_app_get_appid_bypid(owner_pid);
+
+ ai = appinfo_find(_laf, tmp_appid);
+ pkgid = appinfo_get_value(ai, AIT_PKGID);
+
+ if (__can_share(path, pkgid) != 0) {
+ _E("__can_share() returned an error");
+ goto check_uri;
+ }
+
+ if (__get_exec_label(&caller_exec_label, &callee_exec_label, owner_pid,
+ appid) != 0) {
+ _E("__get_exec_label() returned an error");
+ goto finally;
+ }
+
+ paths = (char**)malloc(sizeof(char*) * 3);
+ if (!paths) {
+ _E("Out of memory");
+ goto finally;
+ }
+
+ paths[0] = strdup(path);
+ paths[1] = NULL;
+ paths[2] = NULL;
+ ret = 0;
+ break;
+
+ case BUNDLE_TYPE_STR_ARRAY:
+ path_array = bundle_get_str_array(kb, AUL_SVC_DATA_PATH, &len);
+ if (!path_array || len <= 0) {
+ _E("path_array was null");
+ goto check_uri;
+ }
+
+ owner_pid = __get_owner_pid(caller_pid, kb);
+ owner_pid = getpgid(owner_pid); /* for webapp */
+ tmp_appid = _status_app_get_appid_bypid(owner_pid);
+ ai = appinfo_find(_laf, tmp_appid);
+ pkgid = appinfo_get_value(ai, AIT_PKGID);
+
+ if (__get_exec_label(&caller_exec_label, &callee_exec_label, owner_pid,
+ appid) != 0) {
+ _E("__get_exec_label() returned an error");
+ goto finally;
+ }
+
+ paths = (char**)malloc(sizeof(char*) * (len + 2));
+ if (!paths) {
+ _E("Out of memory");
+ goto finally;
+ }
+
+ int cnt = 0;
+ for (i = 0; i < len; i++) {
+ if (__can_share(path_array[i], pkgid) == 0) {
+ paths[cnt++] = strdup(path_array[i]);
+ }
+ }
+ if (cnt > 0){
+ paths[cnt] = NULL;
+ paths[cnt + 1] = NULL;
+ ret = 0;
+ } else {
+ free(paths);
+ paths = NULL;
+ }
+ break;
+ }
+
+check_uri:
+ if (bundle_get_str(kb, AUL_SVC_K_URI, &path) == BUNDLE_ERROR_NONE) {
+ if (!path) {
+ _E("path was null");
+ goto finally;
+ }
+
+ if (strncmp(path, "file://", 7) == 0)
+ path = &path[7];
+ else {
+ _E("file wasn't started with file://");
+ goto finally;
+ }
+
+ if (owner_pid == -1) {
+ owner_pid = __get_owner_pid(caller_pid, kb);
+ owner_pid = getpgid(owner_pid); /* for webapp */
+ }
+
+ tmp_appid = _status_app_get_appid_bypid(owner_pid);
+ ai = appinfo_find(_laf, tmp_appid);
+ pkgid = appinfo_get_value(ai, AIT_PKGID);
+
+ if (__can_share(path, pkgid) != 0) {
+ _E("__can_share() returned an error");
+ goto finally;
+ }
+
+ if (!caller_exec_label && !callee_exec_label)
+ if (__get_exec_label(&caller_exec_label, &callee_exec_label, owner_pid,
+ appid) != 0) {
+ _E("__get_exec_label() returned an error");
+ goto finally;
+ }
+
+ if (!paths) {
+ paths = (char**)malloc(sizeof(char*) * 2);
+ if (!paths) {
+ _E("Out of memory");
+ goto finally;
+ }
+
+ paths[0] = strdup(path);
+ paths[1] = NULL;
+ } else {
+ i = 0;
+ while (1) {
+ if (paths[i] == NULL) {
+ paths[i] = strdup(path);
+ break;
+ }
+ i++;
+ }
+ }
+ ret = 0;
+ }
+finally:
+ if (ret == 0 && caller_exec_label && paths) {
+ _D("grant permission %s : %s : %s", paths[0], caller_exec_label,
+ callee_exec_label);
+ int r = security_server_perm_apply_sharing(NULL, (const char**)paths, caller_exec_label, callee_exec_label);
+ if (r != SECURITY_SERVER_API_SUCCESS) {
+ _E("security_server_perm_apply_sharing() returned an error %d",r);
+ ret = -1;
+ } else {
+ *out_caller_exec_label = caller_exec_label;
+ *out_callee_exec_label = callee_exec_label;
+ *out_paths = paths;
+
+ caller_exec_label = NULL;
+ callee_exec_label = NULL;
+ paths = NULL;
+ }
+ }
+
+ if (caller_exec_label)
+ free(caller_exec_label);
+ if (callee_exec_label)
+ free(callee_exec_label);
+ if (paths) {
+ i = 0;
+ while (1) {
+ if (paths[i] == NULL) {
+ free(paths);
+ break;
+ }
+ free(paths[i]);
+ i++;
+ }
+ }
+ return ret;
+}
+
+static void __add_shared_info(int pid, const char *caller_exec_label, const char *callee_exec_label, char **paths)
+{
+ _status_set_exec_label(pid, callee_exec_label);
+ _status_add_shared_info(pid, caller_exec_label, paths);
+}
+
+#ifdef _APPFW_FEATURE_TERMINATE_UNMANAGEABLE_APP
+#ifdef _APPFW_FEATURE_SEND_HOME_LAUNCH_SIGNAL
+static void __check_home_app(int pid)
+{
+ const char *home_app = _get_home_appid();
+ const char *appid = NULL;
+
+ if (home_app == NULL)
+ return;
+
+ appid = _status_app_get_appid_bypid(pid);
+
+ if (appid && strcmp(appid, home_app) == 0) {
+ int cnt = 0;
+ int *pids = NULL;
+ int i;
+ const char *taskmanage = NULL;
+ const struct appinfo *ai = NULL;
+ const char* bg = NULL;
+
+ app_group_get_leader_pids(&cnt, &pids);
+ if (pids) {
+ for (i = 0; i < cnt; ++i) {
+ appid = _status_app_get_appid_bypid(pids[i]);
+ if (appid == NULL || strcmp(appid, home_app) == 0)
+ continue;
+
+ ai = appinfo_find(_laf, appid);
+ taskmanage = appinfo_get_value(ai, AIT_TASKMANAGE);
+ bg = appinfo_get_value(ai, AIT_ALLOWED_BG);
+
+ if (taskmanage && strcmp("false", taskmanage) == 0
+ && bg && strcmp("NONE", bg) == 0) {
+ int st = _status_get_app_info_status(pids[i]);
+ if (st != STATUS_DYING) {
+ _W("terminate %d %s %d", pids[i], appid, st);
+ aul_update_freezer_status(pids[i], "wakeup");
+ _term_sub_app(pids[i]);
+ }
+ }
+ }
+
+ free(pids);
+ }
+ }
+}
+#endif
+#endif
+
+int _revoke_temporary_permission(int pid)
+{
+ GList *list = _status_get_shared_info_list(pid);
+ const char *callee_label = _status_get_exec_label(pid);
+
+ if (!list || !callee_label) {
+ _E("list or callee_label was null");
+ return -1;
+ }
+
+ while (list) {
+ shared_info_t *sit = (shared_info_t*)list->data;
+
+ _D("revoke permission %s : %s", sit->owner_exec_label, callee_label);
+ int r = security_server_perm_drop_sharing(NULL, (const char**)sit->paths,
+ sit->owner_exec_label, callee_label);
+
+ if (r != SECURITY_SERVER_API_SUCCESS)
+ _E("revoke error %d",r);
+
+ list = g_list_next(list);
+ }
+ return _status_clear_shared_info_list(pid);
+}
+
+int _start_app(const char* appid, bundle* kb, int cmd, int caller_pid, uid_t caller_uid, int fd)
{
const struct appinfo *ai;
const struct appinfo *caller_ai;
const char *preload;
const char *pkg_status;
const char *operation;
- const char *fake_effect;
- char caller_appid[256];
+ char caller_appid[256] = {0,};
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 pad_pid = NO_LAUNCHPAD_PID;
int status = -1;
int r = -1;
char trm_buf[MAX_PACKAGE_STR_SIZE];
+ gboolean is_group_app = FALSE;
+#ifdef _APPFW_FEATURE_AMD_MODULE_LOG
+ char log_status[AUL_PR_NAME] = {0,};
+#endif
+#ifdef _APPFW_FEATURE_FAKE_EFFECT
+ const char *fake_effect;
int effect_mode = 0;
#ifdef _APPFW_FEATURE_WMS_CONNECTION_CHECK
int wmanager_connected = 0;
#endif
- char *caller_component_type = NULL;
+#endif /* _APPFW_FEATURE_FAKE_EFFECT */
+
+#ifdef _APPFW_FEATURE_AMD_KEY
+ const char *caller_component_type = NULL;
+#endif
+ int prelaunch_attribute = 0;
+
+ bool bg_allowed = false;
+ int lpid;
+ gboolean can_attach;
+ app_group_launch_mode launch_mode;
+ char *caller_exec_label = NULL;
+ char *callee_exec_label = NULL;
+ char **paths = NULL;
+ int grant_permission = 0;
+
+ traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "AUL:AMD:START_APP");
if (appid == NULL || kb == NULL
|| caller_pid < 0 || fd < 0) {
_D("invalid parameter");
if (fd >= 0)
__real_send(fd, -1);
+ traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
return -1;
}
ret = aul_app_get_appid_bypid(caller_pid, caller_appid, sizeof(caller_appid));
if(ret == 0) {
bundle_add(kb, AUL_K_CALLER_APPID, caller_appid);
+ caller = caller_appid;
+ } else {
+ _E("no caller appid info, ret: %d", ret);
}
} else {
bundle_add(kb, AUL_K_CALLER_APPID, caller);
}
- 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
+ if (caller)
+ SECURE_LOGW("caller appid : %s", caller);
+
+ _W("caller pid : %d", caller_pid);
+
ai = appinfo_find(_laf, appid);
if(ai == NULL) {
- _D("no appinfo");
- __real_send(fd, -1);
+ _E("no appinfo");
+ __real_send(fd, -ENOAPP);
+ traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
return -1;
} else {
pkg_status = appinfo_get_value(ai, AIT_STATUS);
if(pkg_status && (strncmp(pkg_status, "blocking", 8) == 0 || strncmp(pkg_status, "restart", 7) == 0) ) {
_D("blocking");
__real_send(fd, -EREJECTED);
+ traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
return -EREJECTED;
} else if(pkg_status && strncmp(pkg_status, "unmounted", 9) == 0 ) {
_D("unmounted");
__real_send(fd, -1);
+ traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
return -1;
}
}
pkgid = appinfo_get_value(ai, AIT_PKGID);
component_type = appinfo_get_value(ai, AIT_COMPTYPE);
+ if (pkg_type == NULL)
+ pkg_type = "unknown";
+
+#ifdef _APPFW_FEATURE_EXPANSION_PKG_INSTALL
+ const char *tep_name = NULL;
+
+ tep_name = appinfo_get_value(ai, AIT_TEP);
+ if (tep_name != NULL) {
+ __send_mount_request(ai, tep_name, kb);
+ }
+#endif
operation = bundle_get_val(kb, "__APP_SVC_OP_TYPE__");
- caller_ai = appinfo_find(_laf, curr_caller);
+ caller_ai = appinfo_find(_laf, caller);
+#ifdef _APPFW_FEATURE_AMD_KEY
+ caller_component_type = appinfo_get_value(caller_ai, AIT_COMPTYPE);
+#endif
if(permission && strncmp(permission, "signature", 9) == 0 ) {
if(caller_uid != 0 && (cmd == APP_START
{
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);
+ ret = pkgmgrinfo_pkginfo_compare_app_cert_info(caller, appid, &compare_result);
+ if (ret != PMINFO_R_OK) {
+ pid = -1;
+ _E("compare app cert info failed : %d", ret);
+ if(cmd == APP_START_ASYNC)
+ close(fd);
+ else
+ __real_send(fd, pid);
+ traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
+ return pid;
+ }
if(compare_result != PMINFO_CERT_COMPARE_MATCH) {
pid = -EILLEGALACCESS;
if(cmd == APP_START_ASYNC)
close(fd);
else
__real_send(fd, pid);
+ traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
return pid;
}
}
}
}
+ if(operation && caller_ai) {
+ ret = __check_app_control_privilege(operation, caller_pid, caller_ai);
+ if (ret < 0) {
+ if (cmd == APP_START_ASYNC)
+ close(fd);
+ else
+ __real_send(fd, ret);
+ traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
+ return ret;
+ }
+ }
+
if(__check_mode(ai) < 0) {
pid = -EREJECTED;
if(cmd == APP_START_ASYNC)
close(fd);
else
__real_send(fd, pid);
+ traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
return pid;
}
- pkgmgrinfo_client_request_enable_external_pkg(pkgid);
+ pkgmgrinfo_client_request_enable_external_pkg((char *)pkgid);
- if (component_type && (strncmp(component_type, "uiapp", strlen("uiapp")) == 0
- || strncmp(component_type, "watchapp", strlen("watchapp")) == 0
- || strncmp(component_type, "widgetapp", strlen("widgetapp")) == 0)) {
+ if (component_type && (strncmp(component_type, APP_TYPE_UI, strlen(APP_TYPE_UI)) == 0
+ || strncmp(component_type, APP_TYPE_WATCH, strlen(APP_TYPE_WATCH)) == 0
+ || strncmp(component_type, APP_TYPE_WIDGET, strlen(APP_TYPE_WIDGET)) == 0 )) {
+ gboolean new_process = FALSE;
-#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) {
+ if(old_caller && caller) {
+ if(strncmp(old_caller, caller, MAX_PACKAGE_STR_SIZE) == 0) {
pid = _status_app_is_running_v2(appid);
}
}
}
+ if (strncmp(component_type, APP_TYPE_UI, strlen(APP_TYPE_UI)) == 0) {
+ if (app_group_is_group_app(kb)) {
+ pid = -1;
+ is_group_app = TRUE;
+ }
+
+ int st = -1;
+
+ if (pid > 0)
+ st = _status_get_app_info_status(pid);
+
+ if (pid == -1 || st == STATUS_DYING) {
+ int found_pid = -1;
+ int found_lpid = -1;
+
+ if (app_group_find_singleton(appid, &found_pid, &found_lpid) == 0) {
+ pid = found_pid;
+ new_process = FALSE;
+ } else {
+ new_process = TRUE;
+ }
+
+ if (app_group_can_start_app(appid, kb, &can_attach, &lpid, &launch_mode) != 0 ) {
+ _E("can't make group info");
+ pid = -EILLEGALACCESS;
+ if (cmd == APP_START_ASYNC)
+ close(fd);
+ else
+ __real_send(fd, pid);
+ traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
+ return pid;
+ }
+
+ if (can_attach && lpid == found_lpid) {
+ _E("can't launch singleton app in the same group");
+ pid = -EILLEGALACCESS;
+ if (cmd == APP_START_ASYNC)
+ close(fd);
+ else
+ __real_send(fd, pid);
+ traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
+ return pid;
+ }
+
+ if (found_pid != -1) {
+ _W("app_group_clear_top, pid: %d", found_pid);
+ app_group_clear_top(found_pid);
+ }
+ }
+
+ if (pid == -1 && can_attach)
+ pid = app_group_find_pid_from_recycle_bin(appid);
+ }
+
#ifdef _APPFW_FEATURE_APP_CONTROL_LITE
char app_path_link[512] = {0,};
const char *caller_app_path = NULL;
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);
+ traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
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) {
+ if(caller) {
+#ifdef _APPFW_FEATURE_AMD_KEY
+ if (caller_component_type && strncmp(caller_component_type, APP_TYPE_UI, strlen(APP_TYPE_UI)) == 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);
}
+ if(_key_grab(KEY_BACK, EXCLUSIVE_GRAB) < 0) {
+ _W("back key grab error");
+ } else {
+ _D("back key grab");
+ }
}
+#endif
}
+ if (__grant_temporary_permission(caller_pid, appid, kb,
+ &caller_exec_label, &callee_exec_label, &paths) == 0)
+ grant_permission = 1;
status = _status_get_app_info_status(pid);
if (pid > 0 && status != STATUS_DYING) {
if (caller_pid == pid) {
SECURE_LOGD("caller process & callee process is same.[%s:%d]", appid, pid);
pid = -ELOCALLAUNCH_ID;
} else {
- if(pkg_type && strncmp(pkg_type, "wgt", 3) == 0) {
+ if(strncmp(pkg_type, "wgt", 3) == 0) {
__pre_launching_processing(appid);
}
- proc_group_change_status(PROC_CGROUP_SET_RESUME_REQUEST, pid, appid);
+
+#ifdef _APPFW_FEATURE_AMD_MODULE_LOG
+ strncpy(log_status, "RESUMING", strlen("RESUMING"));
+#endif
+
+ proc_group_change_status(PROC_CGROUP_SET_RESUME_REQUEST, pid, (char *)appid);
+
if ((ret = __nofork_processing(cmd, pid, kb, fd)) < 0) {
pid = ret;
} else {
if (r == -1)
_D("send SIGKILL: %s", strerror(errno));
}
+
+#ifdef _APPFW_FEATURE_AMD_MODULE_LOG
+ strncpy(log_status, "LAUNCHING", strlen("LAUNCHING"));
+#endif
+
+ // 2.4 bg categorized ui app || watch || widget -> bg allowed (2.3 ui app -> not allowed)
+ prelaunch_attribute = __get_prelaunch_attribute(ai);
+ if ((strncmp(component_type, APP_TYPE_UI, sizeof(APP_TYPE_UI)) == 0
+ && (prelaunch_attribute & RESOURCED_ALLOWED_BG_ATTRIBUTE))
+ || (strncmp(component_type, APP_TYPE_WATCH, sizeof(APP_TYPE_WATCH)) == 0)
+ || (strncmp(component_type, APP_TYPE_WIDGET, sizeof(APP_TYPE_WIDGET)) == 0)) {
+ _D("[__SUSPEND__] allowed background, appid: %s", appid);
+ bundle_add(kb, AUL_K_ALLOWED_BG, "ALLOWED_BG");
+ }
+
+ __send_proc_prelaunch_signal(appid, pkgid, prelaunch_attribute);
+
+#ifdef _APPFW_FEATURE_FAKE_EFFECT
fake_effect = bundle_get_val(kb, "__FAKE_EFFECT__");
+#endif
#ifdef _APPFW_FEATURE_CPU_BOOST
if (cmd == APP_OPEN || operation != NULL ||
_D("%s-%s : %d", SYSTEM_INTERFACE_NAME, SYSTEM_METHOD_NAME, ret);
}
#endif
+
+#ifdef _APPFW_FEATURE_FAKE_EFFECT
/*
* effect_mode = 0
* default mode : fake effect off, 1.6 MHZ off
* 1.6 MHZ mode : faek effect off, 1.6MHZ on
*
*/
- vconf_get_int(AMD_EFFECT_IMAGE_ENABLE, &effect_mode);
+ vconf_get_int(VCONFKEY_AMD_EFFECT_IMAGE_ENABLE, &effect_mode);
#ifdef _APPFW_FEATURE_WMS_CONNECTION_CHECK
vconf_get_bool(VCONFKEY_WMS_WMANAGER_CONNECTED, &wmanager_connected);
#endif
#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;
+ const char *effectimg_type = NULL;
#endif
const char *indicator = NULL;
int screen_mode = 0;
- bool rotate_allowed = false;
+ int rotate_allowed = 0;
int file_type = 1;
int theme = 0;
}
}
}
+#endif /* _APPFW_FEATURE_FAKE_EFFECT */
#ifdef _APPFW_FEATURE_DEBUG_LAUNCHPAD
if (bundle_get_type(kb, AUL_K_SDK) != BUNDLE_TYPE_NONE) {
pad_pid = DEBUG_LAUNCHPAD_PID;
- } else if (pkg_type && strncmp(pkg_type, "wgt", 3) == 0) {
+ } else if (strncmp(pkg_type, "wgt", 3) == 0) {
pad_pid = WEB_LAUNCHPAD_PID;
}
#else
- if (pkg_type && strncmp(pkg_type, "wgt", 3) == 0) {
+ if (strncmp(pkg_type, "wgt", 3) == 0) {
pad_pid = WEB_LAUNCHPAD_PID;
}
#endif
-#ifdef _APPFW_FEATURE_NATIVE_LAUNCHPAD
- else if (pkg_type && 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);
SECURE_LOGD("appid: %s", appid);
- if (process_pool && strncmp(process_pool, "true", strlen("true")) == 0)
+ pad_pid = PROCESS_POOL_LAUNCHPAD_PID;
+ 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)
{
- #ifndef _APPFW_FEATURE_PROCESS_POOL_COMMON
- if (hwacc && 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;
- }
+ _W("Sending to legacy launchpad because process-pool launchpad is not initialized.");
+ pad_pid = NO_LAUNCHPAD_PID;
}
}
#endif //_APPFW_FEATURE_PROCESS_POOL
-
+ _W("pad pid(%d)", pad_pid);
__set_appinfo_for_launchpad(ai, kb);
- pid = app_send_cmd(pad_pid, cmd, kb);
+ if (pad_pid == NO_LAUNCHPAD_PID)
+ {
+ pid = start_process(appid, app_path, kb);
+ }
+ else
+ {
+ pid = app_send_cmd(pad_pid, cmd, kb);
+ if (pid == AUL_R_ENOLAUNCHPAD && pad_pid == PROCESS_POOL_LAUNCHPAD_PID) {
+ _W("Launch with legacy way");
+ pad_pid = NO_LAUNCHPAD_PID;
+ pid = start_process(appid, app_path, kb);
+ }
+ }
if(pid == AUL_R_ECOMM) {
pid = -ENOLAUNCHPAD;
}
- //_add_cgroup(_lcg, appid, pid);
- proc_cgroup_launch(PROC_CGROUP_SET_LAUNCH_REQUEST, pid, appid, pkgid);
+ aul_send_app_launch_request_signal(pid, appid, pkgid, component_type);
snprintf(trm_buf, MAX_PACKAGE_STR_SIZE, "appinfo_launch:%s[PID]%d", appid, pid);
__trm_app_info_send_socket(trm_buf);
}
if(pid < 0) {
+#ifdef _APPFW_FEATURE_AMD_KEY
if(_input_window_get() != 0)
ecore_x_pointer_ungrab();
_D("pid(%d) ecore_x_pointer_ungrab", pid);
+ if(_key_ungrab(KEY_BACK) < 0) {
+ _W("back key ungrab error");
+ } else {
+ _D("back key ungrab");
+ }
+#endif
} else {
- grab_timer_id = g_timeout_add(1000, __grab_timeout_handler, pid);
+ if (new_process) {
+ _D("add app group info");
+ app_group_start_app(pid, kb, lpid, can_attach, launch_mode);
+
+ if (component_type && strncmp(component_type, APP_TYPE_UI, strlen(APP_TYPE_UI)) == 0)
+ __add_fgmgr_list(pid);
+ } else if (cmd == APP_START
+ || cmd == APP_START_RES
+ || cmd == APP_START_ASYNC
+#ifdef _APPFW_FEATURE_MULTI_INSTANCE
+ || cmd == APP_START_MULTI_INSTANCE
+#endif
+ ) {
+ app_group_restart_app(pid, kb);
+ }
+
+#ifdef _APPFW_FEATURE_AMD_KEY
+ grab_timer_id = g_timeout_add(1000, __grab_timeout_handler, (void *)pid);
+#endif
}
}
- else if (component_type && strncmp(component_type, "svcapp", 6) == 0) {
+ else if (component_type && strncmp(component_type, APP_TYPE_SERVICE, sizeof(APP_TYPE_SERVICE)) == 0) {
+#ifdef _APPFW_FEATURE_PRIVATE_SERVICE
+ const char *caller_appid = _status_app_get_appid_bypid(caller_pid);
+
+ if (caller_appid) {
+ const struct appinfo *ai = NULL;
+ const char *caller_pkgid = NULL;
+ const char *pkgid = NULL;
+
+ ai = appinfo_find(_laf, appid);
+ pkgid = appinfo_get_value(ai, AIT_PKGID);
+ ai = appinfo_find(_laf, caller_appid);
+ caller_pkgid = appinfo_get_value(ai, AIT_PKGID);
+
+ if (caller_pkgid && pkgid && strcmp(caller_pkgid, pkgid) != 0) {
+ const char *launch_type = bundle_get_val(kb, OSP_K_LAUNCH_TYPE);
+
+ if (launch_type == NULL || strcmp(launch_type, OSP_V_LAUNCH_TYPE_DATACONTROL) != 0) {
+ const char *v = appinfo_get_value(ai, AIT_VISIBILITY);
+ char num[256] = { 0, };
+
+ if (v == NULL) {
+ int vi_num = 0;
+
+ if (__get_visibility_from_cert_svc(caller_pkgid, &vi_num) == 0) {
+ snprintf(num, 255, "%d", vi_num);
+ appinfo_set_value((struct appinfo*)ai, AIT_VISIBILITY, num);
+ v = num;
+ } else
+ _E("Failed to get visibility");
+ }
+
+ if (v) {
+ int visibility = atoi(v);
+ if (!(visibility & CERT_SVC_VISIBILITY_PLATFORM)) {
+ _E("Couldn't launch service app in other packages");
+ __real_send(fd, -EREJECTED);
+ traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
+ return -EREJECTED;
+ }
+ }
+ }
+ }
+ }
+#endif
pid = _status_app_is_running_v2(appid);
+
+ prelaunch_attribute = __get_prelaunch_attribute(ai);
+
+ // 2.4 bg-categorized svc app || 2.3 svc app -> bg allowed
+ if ((prelaunch_attribute & RESOURCED_ALLOWED_BG_ATTRIBUTE)
+ || !(prelaunch_attribute & RESOURCED_API_VER_2_4_ATTRIBUTE)) {
+ _D("[__SUSPEND__] allowed backgroudn, appid: %s", appid);
+ bundle_add(kb, AUL_K_ALLOWED_BG, "ALLOWED_BG");
+ bg_allowed = true;
+ }
+
+ if (__grant_temporary_permission(caller_pid, appid, kb,
+ &caller_exec_label, &callee_exec_label, &paths) == 0)
+ grant_permission = 1;
+
if (pid > 0) {
+#ifdef _APPFW_FEATURE_AMD_MODULE_LOG
+ strncpy(log_status, "RESUMING", strlen("RESUMING"));
+#endif
+ aul_send_app_resume_request_signal(pid, appid, pkgid, APP_TYPE_SERVICE);
+
+ if (!bg_allowed)
+ __prepare_to_wake_services(pid);
+
if ((ret = __nofork_processing(cmd, pid, kb, fd)) < 0) {
pid = ret;
+ } else {
+ delay_reply = 1;
}
} else if (cmd != APP_RESUME) {
+#ifdef _APPFW_FEATURE_AMD_MODULE_LOG
+ strncpy(log_status, "LAUNCHING", strlen("LAUNCHING"));
+#endif
+
+ __send_proc_prelaunch_signal(appid, pkgid, prelaunch_attribute);
+
#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);
+ SECURE_LOGD("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);
+ pid = start_process(appid, app_path, kb);
}
#else
- pid = service_start(_lcg, appid, app_path, kb);
- proc_cgroup_launch(PROC_CGROUP_SET_SERVICE_REQUEST, pid, appid, pkgid);
+ pid = start_process(appid, app_path, kb);
#endif
+ aul_send_app_launch_request_signal(pid, appid, pkgid, component_type);
+ }
+
+ if (bg_allowed) {
+ g_idle_add(__check_service_only, (gpointer)pid);
}
+
} else {
_E("unkown application");
}
__real_send(fd, pid);
}
+#ifdef _APPFW_FEATURE_AMD_MODULE_LOG
+ _status_log_save(log_status, appid);
+#endif
+
if(pid > 0) {
-#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
+ _status_add_app_info_list(appid, app_path, caller, pid, pad_pid, is_group_app);
+ _status_update_app_info_caller_pid(pid, caller_pid);
+ if (grant_permission) {
+ __add_shared_info(pid, caller_exec_label, callee_exec_label, paths);
+ if (caller_exec_label) {
+ free(caller_exec_label);
+ caller_exec_label = NULL;
+ }
+ if (callee_exec_label) {
+ free(callee_exec_label);
+ callee_exec_label = NULL;
+ }
+ }
+
+#ifdef _APPFW_FEATURE_AMD_MODULE_LOG
+ snprintf(log_status, AUL_PR_NAME, "SUCCESS: %d", pid);
+ _status_log_save(log_status, appid);
#endif
- _status_add_app_info_list(appid, app_path, curr_caller, pid, pad_pid);
#ifdef _APPFW_FEATURE_APP_CHECKER
- const char *pkgtype = NULL;
+ pkg_type = appinfo_get_value(ai, AIT_TYPE);
+ if (!pkg_type)
+ return -1;
- pkgtype = appinfo_get_value(ai, AIT_TYPE);
- if (pkgtype == NULL) {
- _E("pkgtype is NULL");
+ ret = ac_server_check_launch_privilege(appid, pkg_type, pid);
+ if (ret != AC_R_ERROR) {
+ traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
+ return pid;
+ } else {
+ traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
return -1;
}
-
- ret = ac_server_check_launch_privilege(appid, pkgtype, pid);
- return ret != AC_R_ERROR ? pid : -1;
#endif
}
+#ifdef _APPFW_FEATURE_AMD_MODULE_LOG
+ else {
+ _status_log_save("FAILURE", appid);
+ }
+#endif
+ traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
return pid;
}
int __e17_status_handler(int pid, int status, void *data)
{
- if( status == 0 || status == 3) {
+ if (status == PROC_STATUS_FG) {
+ __del_fgmgr_list(pid);
+
+#ifdef _APPFW_FEATURE_AMD_KEY
_D("pid(%d) status(%d)", pid, status);
if(_input_window_get() != 0)
ecore_x_pointer_ungrab();
+ if(_key_ungrab(KEY_BACK) < 0) {
+ _W("back key ungrab error");
+ } else {
+ _D("back key ungrab");
+ }
g_source_remove(grab_timer_id);
+#endif
+ _status_update_app_info_list(pid, STATUS_VISIBLE, FALSE);
+#ifdef _APPFW_FEATURE_TERMINATE_UNMANAGEABLE_APP
+#ifdef _APPFW_FEATURE_SEND_HOME_LAUNCH_SIGNAL
+ __check_home_app(pid);
+#endif
+#endif
+ } else if (status == PROC_STATUS_BG) {
+ _status_update_app_info_list(pid, STATUS_BG, FALSE);
+ } else if (status == PROC_STATUS_LAUNCH) {
+ _D("pid(%d) status(%d)", pid, status);
+ traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "AUL:AMD:EFFECT_DONE");
+ traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
}
return 0;
amd_cmdline = __proc_get_cmdline_bypid(getpid());
_laf = amd->af;
- _lcg = amd->cg;
conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
if (!conn) {
_D("ret : %d", ret);
+ __preexec_init(0, NULL);
+
return 0;
}
}
void __set_appinfo_for_launchpad(const struct appinfo *ai, bundle *kb) {
+ int ret;
+
_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));
+ ret = bundle_del(kb, AUL_K_HWACC);
+ if (ret != BUNDLE_ERROR_NONE)
+ _D("bundle_del error: %d", ret);
+ ret = bundle_add(kb, AUL_K_HWACC, appinfo_get_value(ai, AIT_HWACC));
+ if (ret != BUNDLE_ERROR_NONE)
+ _E("failed to set AUL_K_HWACC: ret(%d)", ret);
+
+
+ bundle_del(kb, AUL_K_TASKMANAGE);
+ if (ret != BUNDLE_ERROR_NONE)
+ _D("bundle_del error: %d", ret);
bundle_add(kb, AUL_K_TASKMANAGE, appinfo_get_value(ai, AIT_TASKMANAGE));
+ if (ret != BUNDLE_ERROR_NONE)
+ _E("failed to set AUL_K_TASKMANAGE: ret(%d)", ret);
+
+ bundle_del(kb, AUL_K_EXEC);
+ if (ret != BUNDLE_ERROR_NONE)
+ _D("bundle_del error: %d", ret);
bundle_add(kb, AUL_K_EXEC, appinfo_get_value(ai, AIT_EXEC));
+ if (ret != BUNDLE_ERROR_NONE)
+ _E("failed to set AUL_K_EXEC: ret(%d)", ret);
+
+ bundle_del(kb, AUL_K_PACKAGETYPE);
+ if (ret != BUNDLE_ERROR_NONE)
+ _D("bundle_del error: %d", ret);
bundle_add(kb, AUL_K_PACKAGETYPE, appinfo_get_value(ai, AIT_TYPE));
+ if (ret != BUNDLE_ERROR_NONE)
+ _E("failed to set AUL_K_PACKAGETYPE: ret(%d)", ret);
+
+ bundle_del(kb, AUL_K_INTERNAL_POOL);
+ if (ret != BUNDLE_ERROR_NONE)
+ _D("bundle_del error: %d", ret);
+ bundle_add(kb, AUL_K_INTERNAL_POOL, appinfo_get_value(ai, AIT_POOL));
+ if (ret != BUNDLE_ERROR_NONE)
+ _E("failed to set AUL_K_INTERNAL_POOL: ret(%d)", ret);
+
+ bundle_del(kb, AUL_K_PKGID);
+ if (ret != BUNDLE_ERROR_NONE)
+ _D("bundle_del error: %d", ret);
+ bundle_add(kb, AUL_K_PKGID, appinfo_get_value(ai, AIT_PKGID));
+ if (ret != BUNDLE_ERROR_NONE)
+ _E("failed to set AUL_K_PKGID: ret(%d)", ret);
}
#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 <glib.h>
#include <bundle.h>
#include "aul_util.h"
int _send_to_sigkill(int pid);
int _resume_app(int pid, int clifd);
+int _pause_app(int pid, int clifd);
+void _term_sub_app(int pid);
int _term_app(int pid, int clifd);
+int _term_bgapp(int pid, int clifd);
+int _term_req_app(int pid, int clifd);
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);
+int _start_app(const 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 _start_srv(const struct appinfo *ai);
+int _revoke_temporary_permission(int pid);
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);
-
+int _window_is_initialized(void);
+int _amd_proc_remove_proc_info(pid_t pid);
+void _amd_suspend_add_timer(pid_t pid);
+void _amd_suspend_remove_timer(pid_t pid);
#endif /* __AUL_AMD_LAUNCH_H_ */
*
*/
+#define _GNU_SOURCE
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <Ecore_X.h>
#include <Ecore_Input.h>
-#include <utilX.h>
#include <Ecore.h>
#include <Evas.h>
#include <aul.h>
#include "aul_util.h"
#include "app_sock.h"
#include "amd_appinfo.h"
-#include "amd_cgutil.h"
#include "amd_key.h"
#include "amd_status.h"
#include "amd_launch.h"
#include "amd_request.h"
-
-#ifndef MOUNT_PATH
-# define MOUNT_PATH "/sys/fs/cgroup"
+#include "amd_app_group.h"
+#ifdef _APPFW_FEATURE_EXPANSION_PKG_INSTALL
+#include "appfw_env.h"
+#include "app_signal.h"
#endif
-#ifndef AGENT_PATH
-# define AGENT_PATH "/usr/bin/daemon-manager-release-agent"
-#endif
#ifdef _APPFW_FEATURE_BG_PROCESS_LIMIT
typedef struct _r_app_info_t{
#endif
gboolean platform_ready = false;
-
-#define WINDOW_READY "/tmp/.wm_ready"
+#ifdef _APPFW_FEATURE_ULTRA_POWER_SAVING_MODE
+int ups_mode = 0;
+#endif
typedef struct _window_watch {
int watch_fd;
} _window_watch_t;
static _window_watch_t *win_info_t = NULL;
+#ifdef _APPFW_FEATURE_EXPANSION_PKG_INSTALL
+extern DBusConnection *conn;
+extern struct appinfomgr *_laf;
+#endif
+
+static int window_initialized = 0;
+
#ifdef _APPFW_FEATURE_BG_PROCESS_LIMIT
static void __vconf_cb(keynode_t *key, void *data);
#endif
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)
{
for ( i=0, iter = r_app_info_list; i<n ; i++) {
info_t = (r_app_info_t *)iter->data;
- //__send_to_sigkill(info_t->pid);
- proc_group_change_status(PROC_CGROUP_SET_TERMINATE_REQUEST, info_t->pid, NULL);
+ aul_send_app_terminate_request_signal(info_t->pid, NULL, NULL, 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);
END:
pkgmgrinfo_appinfo_destroy_appinfo(handle);
-
- free(item);
return false;
}
}
#endif
+#ifdef _APPFW_FEATURE_EXPANSION_PKG_INSTALL
+static int __tep_unmount_dbus(char *mnt_path)
+{
+ DBusMessage *msg;
+ msg = dbus_message_new_method_call(TEP_BUS_NAME, TEP_OBJECT_PATH,
+ TEP_INTERFACE_NAME, TEP_UNMOUNT_METHOD);
+ if (!msg) {
+ _E("dbus_message_new_method_call(%s:%s-%s)", TEP_OBJECT_PATH,
+ TEP_INTERFACE_NAME, TEP_UNMOUNT_METHOD);
+ return -1;
+ }
+
+ if (!dbus_message_append_args(msg,
+ DBUS_TYPE_STRING, &mnt_path,
+ DBUS_TYPE_INVALID)) {
+ _E("Ran out of memory while constructing args\n");
+ dbus_message_unref(msg);
+ return -1;
+ }
+
+ if (dbus_connection_send(conn, msg, NULL) == FALSE) {
+ _E("dbus send error");
+ dbus_message_unref(msg);
+ return -1;
+ }
+ dbus_message_unref(msg);
+ return 0;
+}
+
+static void __send_unmount_request(int pid)
+{
+ const char *tep_name = NULL;
+ const struct appinfo *ai = NULL;
+ char *appid = NULL;
+ appid = _status_app_get_appid_bypid(pid);
+ if (!appid) {
+ _E("_status_app_get_appid_bypid : appid not found");
+ return;
+ }
+ ai = appinfo_find(_laf, appid);
+ tep_name = appinfo_get_value(ai, AIT_TEP);
+ if (tep_name != NULL) {
+ char tep_message[PATH_MAX] = {0, };
+ const char *installed_storage = NULL;
+ char *mnt_path = NULL;
+ struct stat link_buf;
+
+ installed_storage = appinfo_get_value(ai, AIT_STORAGE_TYPE);
+ if (installed_storage != NULL) {
+ if (strncmp(installed_storage, "internal", 8) == 0) {
+ snprintf(tep_message, sizeof(tep_message), "%s%s/res/tep", appfw_env_get_apps_path(), appid);
+ mnt_path = strdup(tep_message);
+ } else if (strncmp(installed_storage, "external", 8) == 0) {
+ snprintf(tep_message, sizeof(tep_message), "%step/tep-access", appfw_env_get_external_storage_path());
+ mnt_path = strdup(tep_message);
+ }
+ if (mnt_path) {
+ int ret = __tep_unmount_dbus(mnt_path);
+ if (ret < 0) {
+ _E("dbus call failed for unmount");
+ }
+ ret = lstat(mnt_path, &link_buf);
+ if (ret == 0) {
+ ret = unlink(mnt_path);
+ if (ret == 0)
+ _D("Symbolic link removed");
+ else
+ _E("Failed to remove the link");
+ }
+ free(mnt_path);
+ }
+ }
+ }
+}
+#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);
+ _W("__app_dead_handler, pid: %d", pid);
if(pid <= 0)
return 0;
+#ifdef _APPFW_FEATURE_EXPANSION_PKG_INSTALL
+ __send_unmount_request(pid);
+#endif
+
+ if (app_group_is_leader_pid(pid)) {
+ _W("app_group_leader_app, pid: %d", pid);
+ if (app_group_find_second_leader(pid) == -1) {
+ app_group_clear_top(pid);
+ app_group_set_dead_pid(pid);
+ app_group_remove(pid);
+ } else
+ app_group_remove_leader_pid(pid);
+ } else if (app_group_is_sub_app(pid)) {
+ _W("app_group_sub_app, pid: %d", pid);
+ int caller_pid = app_group_get_next_caller_pid(pid);
+
+ if (app_group_can_reroute(pid) || (caller_pid > 0 && caller_pid != pid)) {
+ _W("app_group reroute");
+ app_group_reroute(pid);
+ } else {
+ _W("app_group clear top");
+ app_group_clear_top(pid);
+ }
+ app_group_set_dead_pid(pid);
+ app_group_remove(pid);
+ }
+
+ app_group_remove_from_recycle_bin(pid);
+
_unregister_key_event(pid);
#ifdef _APPFW_FEATURE_BG_PROCESS_LIMIT
__remove_item_running_list(pid);
#endif
+ _revoke_temporary_permission(pid);
_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);
+ aul_send_app_terminated_signal(pid);
snprintf(buf, MAX_LOCAL_BUFSZ, "%s/%d", AUL_SOCK_PREFIX, pid);
unlink(buf);
+#ifdef _APPFW_FEATURE_AMD_MODULE_LOG
+ snprintf(buf, MAX_LOCAL_BUFSZ, "%d", pid);
+ _status_log_save("TERMINATED", buf);
+#endif
+
return 0;
}
if (r == 1 && componet && strncmp(componet, "svcapp", 6) == 0)
{
const char *appid = appinfo_get_value(ai, AIT_NAME);
+#ifdef _APPFW_FEATURE_ULTRA_POWER_SAVING_MODE
+ r = appinfo_get_boolean(ai, AIT_PRELOAD);
+ if (ups_mode == SETTING_PSMODE_EMERGENCY && r == 0) {
+ _W("In UPS mode, skip to launch the servce apps");
+ return;
+ }
+#endif
if (appid && _status_app_is_running(appid) < 0)
{
- _I("start service (on-boot) - %s", appid);
- _start_srv(ai, NULL);
+ _W("start service (on-boot) - %s", appid);
+ _start_srv(ai);
}
else
{
static void _start_services(struct amdmgr *amd)
{
+#ifdef _APPFW_FEATURE_ULTRA_POWER_SAVING_MODE
+ if(vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &ups_mode) < 0)
+ _E("vconf_get_int() failed");
+#endif
+
appinfo_foreach(amd->af, __start_cb, amd);
}
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);
+ guint timer_id = g_timeout_add(60000, __platform_ready_handler, NULL);
+ SECURE_LOGW("[Info] timer_id: %u", timer_id);
return 0;
}
-static gboolean _check_window_ready(void)
-{
- if (access(WINDOW_READY, R_OK) == 0)
- return true;
- else
- return false;
-}
-
static void __window_init(void)
{
- _D("_window_init");
+ _W("_window_init");
ecore_x_init(NULL);
_set_atom_effect();
-#ifndef __i386__
_key_init();
-#endif
+ window_initialized = 1;
+}
+
+int _window_is_initialized()
+{
+ return window_initialized;
}
static Eina_Bool _window_cb(void *data, Ecore_Fd_Handler * fd_handler)
{
int fd;
- char buf[FILENAME_MAX];
+ char buf[FILENAME_MAX] = {0};
ssize_t len = 0;
struct inotify_event* event;
return ECORE_CALLBACK_CANCEL;
}
len = read(fd, buf, FILENAME_MAX);
+ if (len < 0)
+ _E("read failed, error [%s]", strerror(errno));;
event = (struct inotify_event*) &buf[0];
- _D("filename : %s", event->name);
+ if(event)
+ _D("filename : %s", event->name);
- if (access(WINDOW_READY, R_OK) == 0) {
+ if (_status_check_window_ready()) {
__window_init();
if (win_info_t) {
ecore_main_fd_handler_del(win_info_t->win_watch_ewd);
static void _register_window_init(void)
{
- _D("_register_window_init");
+ _W("_register_window_init");
win_info_t = malloc(sizeof(_window_watch_t));
if (!win_info_t) {
static void _window_init(void)
{
- if (_check_window_ready())
+ if (_status_check_window_ready())
__window_init();
else
_register_window_init();
struct amdmgr amd;
int ret = 0;
+ /* sigprocmask() is used to fetch and/or change the signal mask of the calling thread.
+ * As a result, please make sure that there are not any other threads except for calling thread.
+ * */
+ int fd = _signal_block_sigchld();
+ assert(fd != -1);
+
ecore_init();
evas_init();
ecore_event_init();
- _D("ecore init done\n");
+ _W("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);
+ ret = _request_init(&amd, fd);
assert(ret == 0);
_launch_init(&amd);
_status_init(&amd);
_window_init();
+ app_group_init();
- _D("AMD init done\n");
+ _W("AMD init done\n");
#ifdef _APPFW_FEATURE_BG_PROCESS_LIMIT
if (vconf_notify_key_changed(VCONFKEY_SETAPPL_DEVOPTION_BGPROCESS, __vconf_cb, NULL) != 0) {
int res = setpriority(PRIO_PROCESS, 0, -12);
if (res == -1)
{
- SECURE_LOGE("Setting process (%d) priority to -12 failed, errno: %d (%s)",
+ _E("Setting process (%d) priority to -12 failed, errno: %d (%s)",
getpid(), errno, strerror(errno));
}
#endif
gboolean __amd_ready(gpointer user_data)
{
- _D("AMD ready\n");
+ _W("AMD ready\n");
int handle = creat("/tmp/amd_ready", S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
if (handle != -1)
int main(int argc, char *argv[])
{
- _D("AMD main()\n");
+ _W("AMD main()\n");
#ifdef _APPFW_FEATURE_APP_CHECKER
if (ac_server_initialize() != AC_R_OK){
* limitations under the License.
*
*/
+
+#define _GNU_SOURCE
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <aul.h>
#include <glib.h>
#include <bundle.h>
+#include <bundle_internal.h>
#include <rua.h>
+#include <rua_stat.h>
#include <proc_stat.h>
#include <security-server.h>
#include <vconf.h>
+#include <ttrace.h>
+#include <Ecore.h>
+#include <sys/signalfd.h>
+#include <signal.h>
+#include <wait.h>
+#include <pkgmgr-info.h>
#include "amd_config.h"
#include "simple_util.h"
#include "amd_key.h"
#include "amd_launch.h"
#include "amd_appinfo.h"
-#include "amd_cgutil.h"
#include "amd_status.h"
-
-#include <pkgmgr-info.h>
+#include "amd_app_group.h"
#define INHOUSE_UID 5000
#endif
struct appinfomgr *_raf;
-struct cginfo *_rcg;
static DBusConnection *bus = NULL;
+static sigset_t oldmask;
+#ifdef _APPFW_FEATURE_SEND_HOME_LAUNCH_SIGNAL
char *home_appid = NULL;
+#endif
+struct restart_info {
+ char *appid;
+ int count;
+ Ecore_Timer *timer;
+};
+
+GHashTable *restart_tbl;
static int __send_result_to_client(int fd, int res);
static gboolean __request_handler(gpointer data);
+// TODO: Replace with pkgmgr-info header
+int pkgmgrinfo_updateinfo_check_update(const char* pkgid);
+
+static int __send_result_data(int fd, int cmd, unsigned char *kb_data, int datalen)
+{
+ int len;
+ int ret;
+ int res = 0;
+ app_pkt_t *pkt = NULL;
+
+ if (datalen > AUL_SOCK_MAXBUFF - 8) {
+ _E("datalen > AUL_SOCK_MAXBUFF\n");
+ return -EINVAL;
+ }
+
+ pkt = (app_pkt_t *) malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
+ if (NULL == pkt) {
+ _E("Malloc Failed!");
+ return -ENOMEM;
+ }
+ memset(pkt, 0, AUL_SOCK_MAXBUFF);
+
+ pkt->cmd = cmd;
+ pkt->len = datalen;
+ memcpy(pkt->data, kb_data, datalen);
+
+ if ((len = send(fd, pkt, datalen + 8, MSG_NOSIGNAL)) != datalen + 8) {
+ _E("sendto() failed - %d %d (errno %d)", len, datalen + 8, errno);
+ if(len > 0) {
+ while (len != datalen + 8) {
+ ret = send(fd, &pkt->data[len-8], datalen + 8 - len, MSG_NOSIGNAL);
+ if (ret < 0) {
+ _E("second sendto() failed - %d %d (errno %d)", ret, datalen + 8, errno);
+ close(fd);
+ if (pkt) {
+ free(pkt);
+ pkt = NULL;
+ }
+ return -ECOMM;
+ }
+ len += ret;
+ _D("sendto() len - %d %d", len, datalen + 8);
+ }
+ } else {
+ close(fd);
+ if (pkt) {
+ free(pkt);
+ pkt = NULL;
+ }
+ return -ECOMM;
+ }
+ }
+ if (pkt) {
+ free(pkt);
+ pkt = NULL;
+ }
+
+ close(fd);
+ return res;
+}
+
static int __send_result_to_client(int fd, int res)
{
- _D("__send_result_to_client, res: %d", fd, res);
+ if (fd < 0)
+ return -1;
+
+ _W("__send_result_to_client, pid: %d", res);
if (send(fd, &res, sizeof(int), MSG_NOSIGNAL) < 0) {
if (errno == EPIPE) {
static void __real_send(int clifd, int ret)
{
- if(clifd <= 0) {
+ if(clifd < 0)
return;
- }
+
if (send(clifd, &ret, sizeof(int), MSG_NOSIGNAL) < 0) {
if (errno == EPIPE) {
_E("send failed due to EPIPE.\n");
bundle_add(kb, AUL_K_CALLEE_PID, tmp_pid);
}
- _D("__forward_cmd: %d %d", cr_pid, pgid);
+ _W("__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)
int pid;
int ret = -1;
int dummy;
+ char *appid = NULL;
+ const char *pkgid = NULL;
+ const char *type = NULL;
+ const struct appinfo *ai = NULL;
if (pkg_name == NULL)
return -1;
return -1;
}
+ /* check whether app process is dead or not */
+ char buf[1024];
+ snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
+ if (access(buf, F_OK) != 0) {
+ _E("pid(%d) is dead. cmd(%d) is canceled", pid, cmd);
+ __real_send(clifd, -ECOMM);
+ return -ECOMM;
+ }
+
if (_status_get_app_info_status(pid) == -1) {
char buf[512];
if (_status_get_pkgname_bypid(pid, buf, 512) == -1) {
_E("request for unknown pid. It might not be a pid of app: %d", pid);
+ __real_send(clifd, -1);
return -1;
}
}
+ appid = _status_app_get_appid_bypid(pid);
+ ai = appinfo_find(_raf, appid);
+ pkgid = appinfo_get_value(ai, AIT_PKGID);
+ type = appinfo_get_value(ai, AIT_COMPTYPE);
+
if (cmd == APP_RESUME_BY_PID)
- proc_group_change_status(PROC_CGROUP_SET_RESUME_REQUEST, pid, NULL);
+ aul_send_app_resume_request_signal(pid, appid, pkgid, type);
else
- proc_group_change_status(PROC_CGROUP_SET_TERMINATE_REQUEST, pid, NULL);
+ aul_send_app_terminate_request_signal(pid, appid, pkgid, type);
- _D("__app_process_by_pid, cmd: %d, pid: %d, ", cmd, pid);
+ SECURE_LOGD("__app_process_by_pid, pid: %d, ", pid);
switch (cmd) {
case APP_RESUME_BY_PID:
ret = _resume_app(pid, clifd);
case APP_TERM_BY_PID_WITHOUT_RESTART:
ret = _term_app(pid, clifd);
break;
+ case APP_TERM_BGAPP_BY_PID:
+ ret = _term_bgapp(pid, clifd);
+ break;
case APP_KILL_BY_PID:
if ((ret = _send_to_sigkill(pid)) < 0)
_E("fail to killing - %d\n", pid);
__real_send(clifd, ret);
break;
case APP_TERM_REQ_BY_PID:
- if ((ret = __app_send_raw(pid, cmd, (unsigned char *)&dummy, sizeof(int))) < 0) {
- _D("terminate req packet send error");
- }
- __real_send(clifd, ret);
+ ret = _term_req_app(pid, clifd);
break;
case APP_TERM_BY_PID_ASYNC:
if ((ret = __app_send_raw_with_noreply(pid, cmd, (unsigned char *)&dummy, sizeof(int))) < 0) {
}
__real_send(clifd, ret);
break;
+ case APP_PAUSE_BY_PID:
+ ret = _pause_app(pid, clifd);
+ break;
+ default:
+ break;
}
return ret;
}
+#ifdef _APPFW_FEATURE_EFFECTIVE_APPID
+static void __set_effective_appid(bundle *kb)
+{
+ const struct appinfo *ai;
+ const struct appinfo *effective_ai;
+ char *appid;
+ const char *effective_appid;
+
+ appid = (char *)bundle_get_val(kb, AUL_K_PKG_NAME);
+ if (appid) {
+ ai = appinfo_find(_raf, appid);
+ if (ai == NULL)
+ return;
+
+ effective_appid = appinfo_get_value(ai, AIT_EFFECTIVE_APPID);
+ if (effective_appid) {
+ const char *pkgid;
+ const char *effective_pkgid;
+ effective_ai = appinfo_find(_raf, effective_appid);
+ if (effective_ai == NULL)
+ return;
+
+ pkgid = appinfo_get_value(ai, AIT_PKGID);
+ effective_pkgid = appinfo_get_value(effective_ai, AIT_PKGID);
+ if (pkgid && effective_pkgid && strcmp(pkgid, effective_pkgid) == 0) {
+ _D("use effective appid instead of the real appid");
+ bundle_del(kb, AUL_K_PKG_NAME);
+ bundle_add(kb, AUL_K_PKG_NAME, effective_appid);
+ }
+ }
+ }
+}
+#endif
+
static gboolean __add_history_handler(gpointer user_data)
{
struct rua_rec rec;
bundle *kb = NULL;
char *appid = NULL;
char *app_path = NULL;
+ char *stat_caller = NULL;
+ char *stat_tag = NULL;
struct appinfo *ai;
+
app_pkt_t *pkt = (app_pkt_t *)user_data;
if (!pkt)
return FALSE;
-
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;
- }
+ if (!app_group_is_group_app(kb)) {
+
+#ifdef _APPFW_FEATURE_EFFECTIVE_APPID
+ __set_effective_appid(kb);
#endif
- ai = (struct appinfo *)appinfo_find(_raf, appid);
- app_path = (char *)appinfo_get_value(ai, AIT_EXEC);
+ appid = (char *)bundle_get_val(kb, AUL_K_PKG_NAME);
+
+ ai = (struct appinfo *)appinfo_find(_raf, appid);
+ app_path = (char *)appinfo_get_value(ai, AIT_EXEC);
+
+ memset((void *)&rec, 0, sizeof(rec));
- memset((void *)&rec, 0, sizeof(rec));
+ rec.pkg_name = appid;
+ rec.app_path = app_path;
- rec.pkg_name = appid;
- rec.app_path = app_path;
+ if(pkt->len > 0) {
+ rec.arg = (char *)pkt->data;
+ }
+
+ SECURE_LOGD("add rua history %s %s", rec.pkg_name, rec.app_path);
- if(pkt->len > 0) {
- rec.arg = (char *)pkt->data;
+ ret = rua_add_history(&rec);
+ if (ret == -1)
+ _D("rua add history error");
}
- SECURE_LOGD("add rua history %s %s", rec.pkg_name, rec.app_path);
+ stat_caller = (char *)bundle_get_val(kb, AUL_SVC_K_RUA_STAT_CALLER);
+ stat_tag = (char *)bundle_get_val(kb, AUL_SVC_K_RUA_STAT_TAG);
- ret = rua_add_history(&rec);
- if (ret == -1)
- _D("rua add history error");
+ if (stat_caller != NULL && stat_tag != NULL) {
+ SECURE_LOGD("rua_stat_caller: %s, rua_stat_tag: %s", stat_caller, stat_tag);
+ rua_stat_update(stat_caller, stat_tag);
+ }
if (kb != NULL)
bundle_free(kb);
free(pkt);
-#ifdef _APPFW_FEATURE_CONTACT_PHONE_AS_ONE_APP
- if (need_free)
- free(appid);
-#endif
-
return FALSE;
}
return -1; /* stop the iteration */
}
-static int __releasable(const char *filename)
+int _release_srv(const char *appid)
{
- int sz;
int r;
+ const struct appinfo *ai;
- if (!filename || !*filename) {
- _E("release service: name is empty");
- return -1;
- }
-
- r = cgutil_exist_group(_rcg, CTRL_MGR, filename);
- if (r == -1) {
- SECURE_LOGE("release service: exist: %s", strerror(errno));
- return -1;
- }
- if (r == 0) {
- SECURE_LOGE("release service: '%s' already not exist", filename);
+ ai = (struct appinfo *)appinfo_find(_raf, appid);
+ if (!ai) {
+ _E("appid not found");
+ SECURE_LOGE("release service: '%s' not found", appid);
return -1;
}
- sz = 0;
- r = cgutil_group_foreach_pid(_rcg, CTRL_MGR, filename,
- __get_pid_cb, &sz);
- if (r == -1) {
- SECURE_LOGE("release service: '%s' read pid error", filename);
- return -1;
- }
- if (sz > 0) {
- SECURE_LOGE("release service: '%s' group has process", filename);
- return -1;
+ r = appinfo_get_boolean(ai, AIT_RESTART);
+ if (r == 1) {
+ _W("Auto restart");
+ SECURE_LOGD("Auto restart set: '%s'", appid);
+ return _start_srv(ai);
}
return 0;
}
-int __release_srv(const char *filename)
+static Eina_Bool __restart_timeout_handler(void *data)
{
- int r;
- const struct appinfo *ai;
+ struct restart_info *ri = (struct restart_info *)data;
- r = __releasable(filename);
- if (r == -1)
- return -1;
+ _D("ri (%x)", ri);
+ SECURE_LOGD("appid (%s)", ri->appid);
- ai = (struct appinfo *)appinfo_find(_raf, filename);
- if (!ai) {
- SECURE_LOGE("release service: '%s' not found", filename);
- return -1;
- }
+ g_hash_table_remove(restart_tbl, ri->appid);
+ free(ri->appid);
+ free(ri);
- r = appinfo_get_boolean(ai, AIT_RESTART);
- if (r == 1) {
- SECURE_LOGD("Auto restart set: '%s'", filename);
- return _start_srv(ai, NULL);
- }
+ return ECORE_CALLBACK_CANCEL;
+}
- service_release(filename);
+static bool __check_restart(const char *appid)
+{
+ struct restart_info *ri = NULL;
+ //struct appinfo *ai = NULL;
- r = cgutil_remove_group(_rcg, CTRL_MGR, filename);
- if (r == -1) {
- SECURE_LOGE("'%s' group remove error: %s", filename, strerror(errno));
- return -1;
- }
+ ri = g_hash_table_lookup(restart_tbl, appid);
- return 0;
+ if(!ri) {
+ ri = calloc(1, sizeof(*ri));
+ if (!ri) {
+ _E("create restart info: %s", strerror(errno));
+ return true;
+ }
+ memset(ri, 0, sizeof(struct restart_info));
+ ri->appid = strdup(appid);
+ ri->count = 1;
+ g_hash_table_insert(restart_tbl, ri->appid, ri);
+
+ _D("ri (%x)", ri);
+ SECURE_LOGD("appid (%s)", appid);
+
+ ri->timer = ecore_timer_add(10, __restart_timeout_handler, ri);
+ } else {
+ ri->count++;
+ _D("count (%d)", ri->count);
+ if(ri->count > 5) {
+ /*ai = appinfo_find(_raf, appid);
+ if(ai) {
+ appinfo_set_value(ai, AIT_STATUS, "norestart");
+ }*/
+ ecore_timer_del(ri->timer);
+ return false;
+ }
+ }
+ return true;
}
+#ifdef _APPFW_FEATURE_SEND_HOME_LAUNCH_SIGNAL
static inline int __send_home_launch_signal(int pid)
{
DBusMessage *message;
dbus_connection_flush(bus);
dbus_message_unref(message);
- _D("send dead signal done\n");
+ _W("send a home launch signal");
return 0;
}
+#endif
static inline int __send_app_termination_signal(int dead_pid)
{
dbus_connection_flush(bus);
dbus_message_unref(message);
- _D("send dead signal done\n");
+ _W("send dead signal done");
+
+ return 0;
+}
+
+int _send_set_process_group_signal_signal(int owner_pid, int child_pid)
+{
+ DBusMessage *message;
+
+ if (bus == NULL)
+ return -1;
+
+ message = dbus_message_new_signal(RESOURCED_PROC_OBJECT,
+ RESOURCED_PROC_INTERFACE,
+ RESOURCED_PROC_GROUP_SIGNAL);
+
+ if (dbus_message_append_args(message,
+ DBUS_TYPE_INT32, &owner_pid,
+ DBUS_TYPE_INT32, &child_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);
+
+ _W("send set_process_group signal done");
return 0;
}
switch (order) {
case 0:
target = multi_appid;
- appinfo_set_value(ai, AIT_TOGGLE_ORDER, "1");
+ appinfo_set_value((struct appinfo *)ai,
+ AIT_TOGGLE_ORDER, "1");
break;
case 1:
target = appid;
- appinfo_set_value(ai, AIT_TOGGLE_ORDER, "0");
+ appinfo_set_value((struct appinfo *)ai,
+ AIT_TOGGLE_ORDER, "0");
break;
default:
} else {
// Main app is running
if (_status_app_is_running(appid) != -1) {
- _D("Send a request to the running main appid: %s", appid);
+ SECURE_LOGD("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);
+ SECURE_LOGD("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);
+ SECURE_LOGD("Both apps are not running, launch a main app - %s", appid);
target = appid;
}
}
}
#endif
+static void __dispatch_app_group_get_window(int clifd, const app_pkt_t *pkt)
+{
+ bundle *b;
+ char *buf;
+ int pid;
+ int wid;
+
+ b = bundle_decode(pkt->data, pkt->len);
+ bundle_get_str(b, AUL_K_PID, &buf);
+ pid = atoi(buf);
+ bundle_free(b);
+ wid = app_group_get_window(pid);
+ __real_send(clifd, wid);
+}
+
+static void __dispatch_app_group_set_window(int clifd, const app_pkt_t *pkt, int pid)
+{
+ bundle *b;
+ char *buf;
+ int wid;
+ int ret;
+
+ b = bundle_decode(pkt->data, pkt->len);
+ bundle_get_str(b, AUL_K_WID, &buf);
+ wid = atoi(buf);
+ bundle_free(b);
+ ret = app_group_set_window(pid, wid);
+ __real_send(clifd, ret);
+}
+
+static void __dispatch_app_group_get_fg_flag(int clifd, const app_pkt_t *pkt)
+{
+ bundle *b;
+ char *buf;
+ int pid;
+ int fg;
+
+ b = bundle_decode(pkt->data, pkt->len);
+ bundle_get_str(b, AUL_K_PID, &buf);
+ pid = atoi(buf);
+ bundle_free(b);
+ fg = app_group_get_fg_flag(pid);
+ __real_send(clifd, fg);
+}
+
+static void __dispatch_app_group_clear_top(int clifd, int pid)
+{
+ app_group_clear_top(pid);
+ __real_send(clifd, 0);
+}
+
+static void __dispatch_app_group_get_leader_pid(int clifd,
+ const app_pkt_t *pkt)
+{
+ bundle *b;
+ char *buf;
+ int pid;
+ int lpid;
+
+ b = bundle_decode(pkt->data, pkt->len);
+ bundle_get_str(b, AUL_K_PID, &buf);
+ pid = atoi(buf);
+ bundle_free(b);
+ lpid = app_group_get_leader_pid(pid);
+ __real_send(clifd, lpid);
+}
+
+static void __dispatch_app_group_get_leader_pids(int clifd,
+ const app_pkt_t *pkt)
+{
+ int cnt;
+ int *pids;
+ unsigned char empty[1] = { 0 };
+
+ app_group_get_leader_pids(&cnt, &pids);
+
+ if (pids == NULL || cnt == 0) {
+ __send_result_data(clifd, APP_GROUP_GET_LEADER_PIDS, empty, 0);
+ } else {
+ __send_result_data(clifd, APP_GROUP_GET_LEADER_PIDS,
+ (unsigned char *)pids, cnt * sizeof(int));
+ }
+ if (pids != NULL)
+ free(pids);
+}
+
+static void __dispatch_app_group_get_idle_pids(int clifd,
+ const app_pkt_t *pkt)
+{
+ int cnt;
+ int *pids;
+ unsigned char empty[1] = { 0 };
+
+ app_group_get_idle_pids(&cnt, &pids);
+
+ if (pids == NULL || cnt == 0) {
+ __send_result_data(clifd, APP_GROUP_GET_IDLE_PIDS, empty, 0);
+ } else {
+ __send_result_data(clifd, APP_GROUP_GET_IDLE_PIDS,
+ (unsigned char *)pids, cnt * sizeof(int));
+ }
+ if (pids != NULL)
+ free(pids);
+}
+
+static void __dispatch_app_group_get_group_pids(int clifd, const app_pkt_t *pkt)
+{
+ bundle *b;
+ char *buf;
+ int leader_pid;
+ int cnt;
+ int *pids;
+ unsigned char empty[1] = { 0 };
+
+ b = bundle_decode(pkt->data, pkt->len);
+ bundle_get_str(b, AUL_K_LEADER_PID, &buf);
+ leader_pid = atoi(buf);
+ bundle_free(b);
+
+ app_group_get_group_pids(leader_pid, &cnt, &pids);
+ if (pids == NULL || cnt == 0) {
+ __send_result_data(clifd, APP_GROUP_GET_GROUP_PIDS, empty, 0);
+ } else {
+ __send_result_data(clifd, APP_GROUP_GET_GROUP_PIDS,
+ (unsigned char *)pids, cnt * sizeof(int));
+ }
+ if (pids != NULL)
+ free(pids);
+}
+
+static void __dispatch_app_group_lower(int clifd, int pid)
+{
+ int ret = 0;
+
+ app_group_lower(pid, &ret);
+ __real_send(clifd, ret);
+}
+
+static void __check_host_pid(bundle *kb, struct ucred *cr)
+{
+ if (cr->pid == 0) {
+ SECURE_LOGD("check host pid");
+
+ char *spid = NULL;
+
+ bundle_get_str(kb, AUL_K_HOST_PID, &spid);
+ if (spid != NULL) {
+ cr->pid = atoi(spid);
+ SECURE_LOGD("caller pid was changed by host pid %s", spid);
+ }
+ }
+}
+
static gboolean __request_handler(gpointer data)
{
GPollFD *gpollfd = (GPollFD *) data;
int *status;
int ret = -1;
int free_pkt = 1;
- char *appid;
+ char *appid = NULL;
char *term_pid = NULL;
int pid;
bundle *kb = NULL;
const struct appinfo *ai;
- const char *pkg_status;
- item_pkt_t *item;
+ int owner_pid;
+ int child_pid;
+ traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "AUL:AMD:REQ_HANDLER");
if ((pkt = __app_recv_raw(fd, &clifd, &cr)) == NULL) {
_E("recv error");
+ traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
return FALSE;
}
+ kb = bundle_decode(pkt->data, pkt->len);
+#ifdef _APPFW_FEATURE_EFFECTIVE_APPID
+ __set_effective_appid(kb);
+#endif
_D("__request_handler: %d", pkt->cmd);
+
switch (pkt->cmd) {
case APP_OPEN:
case APP_RESUME:
case APP_START_RES:
case APP_START_ASYNC:
ret = security_server_check_privilege_by_sockfd(clifd, "aul::launch", "x");
- if(ret == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
+ if (cr.pid != 0 && 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);
+ __check_host_pid(kb, &cr);
appid = (char *)bundle_get_val(kb, AUL_K_PKG_NAME);
#ifdef _APPFW_FEATURE_MULTI_INSTANCE
ai = appinfo_find(_raf, appid);
if (ai == NULL) {
_E("no appinfo");
- __real_send(clifd, -1);
- ret = -1;
+ __real_send(clifd, -ENOAPP);
} 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);
-
+ SECURE_LOGD("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);
+ SECURE_LOGD("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);
+ SECURE_LOGD("No multi-instance app information, launch a main appid: - %s", appid);
ret = _start_app(appid, kb, pkt->cmd, cr.pid, cr.uid, clifd);
}
}
else
{
- _D("launch a single-instance appid: %s", appid);
+ SECURE_LOGD("launch a single-instance appid: %s", appid);
ret = _start_app(appid, kb, pkt->cmd, cr.pid, cr.uid, clifd);
}
}
ret = _start_app(appid, kb, pkt->cmd, cr.pid, cr.uid, clifd);
#endif
- 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 (ret > 0 && bundle_get_type(kb, AUL_K_PRELAUCHING) == BUNDLE_TYPE_NONE) {
+#ifdef _APPFW_FEATURE_BG_PROCESS_LIMIT
+ if (!app_group_is_group_app(kb)) {
+ item_pkt_t *item = g_malloc0(sizeof(item_pkt_t));
+ item->pid = ret;
+ strncpy(item->appid, appid, 511);
+ __add_item_running_list(item);
+ g_free(item);
+ }
+#endif
+#ifdef _APPFW_FEATURE_SEND_HOME_LAUNCH_SIGNAL
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);
+ g_timeout_add(1500, __add_history_handler, pkt);
+ free_pkt = 0;
}
if (kb != NULL)
#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) {
+ if (cr.pid != 0 && 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);
+ SECURE_LOGD("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 (ret > 0) {
+#ifdef _APPFW_FEATURE_BG_PROCESS_LIMIT
+ if (!app_group_is_group_app(kb)) {
+ item_pkt_t *item = g_malloc0(sizeof(item_pkt_t));
+ item->pid = ret;
+ strncpy(item->appid, appid, 511);
+ __add_item_running_list(item);
+ g_free(item);
+ }
+#endif
+#ifdef _APPFW_FEATURE_SEND_HOME_LAUNCH_SIGNAL
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);
+ g_timeout_add(1500, __add_history_handler, pkt);
+ free_pkt = 0;
}
if (kb != NULL)
#endif
case APP_RESULT:
case APP_CANCEL:
- kb = bundle_decode(pkt->data, pkt->len);
ret = __foward_cmd(pkt->cmd, kb, cr.pid);
- //__real_send(clifd, ret);
close(clifd);
break;
+ case APP_PAUSE:
+ appid = (char *)bundle_get_val(kb, AUL_K_PKG_NAME);
+ ret = _status_app_is_running_v2_cached(appid);
+ if (ret > 0) {
+ _pause_app(ret, clifd);
+ } else {
+ _E("%s is not running", appid);
+ close(clifd);
+ }
+ break;
case APP_RESUME_BY_PID:
+ case APP_PAUSE_BY_PID:
case APP_TERM_REQ_BY_PID:
- kb = bundle_decode(pkt->data, pkt->len);
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) {
+ if (cr.pid != 0 && 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");
+ if (ai) {
+ appinfo_set_value((struct appinfo *)ai, AIT_STATUS, "norestart");
ret = __app_process_by_pid(pkt->cmd, term_pid, &cr, clifd);
} else {
ret = -1;
- __real_send(clifd, ret);
+ __send_result_to_client(clifd, ret);
}
}
break;
case APP_TERM_BY_PID:
case APP_KILL_BY_PID:
ret = security_server_check_privilege_by_sockfd(clifd, "aul::terminate", "x");
- if(ret == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
+ if (cr.pid != 0 && ret == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
+ _E("terminate request has been denied by smack");
+ ret = -EILLEGALACCESS;
+ __real_send(clifd, ret);
+ } else {
+ appid = (char *)bundle_get_val(kb, AUL_K_PKG_NAME);
+ ret = __app_process_by_pid(pkt->cmd, appid, &cr, clifd);
+ }
+ break;
+ case APP_TERM_BGAPP_BY_PID:
+ ret = security_server_check_privilege_by_sockfd(clifd, "aul::terminatebgapp", "x");
+ if (cr.pid != 0 && 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);
appid = (char *)bundle_get_val(kb, AUL_K_PKG_NAME);
ret = __app_process_by_pid(pkt->cmd, appid, &cr, clifd);
}
case APP_IS_RUNNING:
appid = malloc(MAX_PACKAGE_STR_SIZE);
if (appid == NULL) {
- _E("out of memory");
- ret = -1;
- __send_result_to_client(clifd, ret);
+ _E("Failed to allocate memory");
+ __send_result_to_client(clifd, -1);
break;
}
-
strncpy(appid, (const char*)pkt->data, MAX_PACKAGE_STR_SIZE-1);
- ret = _status_app_is_running_v2(appid);
+ ret = _status_app_is_running_v2_cached(appid);
SECURE_LOGD("APP_IS_RUNNING : %s : %d",appid, ret);
+ if (ret > 0 && _status_get_app_info_status(ret) == STATUS_DYING) {
+ SECURE_LOGD("APP_IS_RUNNING: %d is dying", ret);
+ ret = -1;
+ }
__send_result_to_client(clifd, ret);
free(appid);
break;
break;
case APP_STATUS_UPDATE:
status = (int *)pkt->data;
+ _W("app status : %d", *status);
if(*status == STATUS_NORESTART) {
appid = _status_app_get_appid_bypid(cr.pid);
ai = appinfo_find(_raf, appid);
- if (ai)
- appinfo_set_value(ai, AIT_STATUS, "norestart");
+ appinfo_set_value((struct appinfo *)ai, AIT_STATUS, "norestart");
} else {
- ret = _status_update_app_info_list(cr.pid, *status);
+ ret = _status_update_app_info_list(cr.pid, *status, FALSE);
}
- //__send_result_to_client(clifd, ret);
close(clifd);
break;
- case APP_RELEASED:
- appid = malloc(MAX_PACKAGE_STR_SIZE);
- if (appid == NULL) {
- _E("out of memory");
- ret = -1;
- __send_result_to_client(clifd, ret);
- break;
- }
-
- 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);
- SECURE_LOGD("appid(%s) pkg_status(%s)", appid, pkg_status);
- if(ai && pkg_status && strncmp(pkg_status, "blocking", 8) == 0) {
- appinfo_set_value(ai, AIT_STATUS, "restart");
- } else if (ai && pkg_status && strncmp(pkg_status, "norestart", 9) == 0) {
- appinfo_set_value(ai, AIT_STATUS, "installed");
- } else {
- ret = __release_srv(appid);
- }
+ case APP_GET_STATUS:
+ memcpy(&pid, pkt->data, sizeof(int));
+ ret = _status_get_app_info_status(pid);
__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:
- /*kb = bundle_decode(pkt->data, pkt->len);
- appid = (char *)bundle_get_val(kb, AUL_K_APPID);
+ /*appid = (char *)bundle_get_val(kb, AUL_K_APPID);
app_path = (char *)bundle_get_val(kb, AUL_K_EXEC);
tmp_pid = (char *)bundle_get_val(kb, AUL_K_PID);
pid = atoi(tmp_pid);
__send_result_to_client(clifd, ret);
break;
+ case APP_GROUP_GET_WINDOW:
+ __dispatch_app_group_get_window(clifd, pkt);
+ break;
+
+ case APP_GROUP_SET_WINDOW:
+ __dispatch_app_group_set_window(clifd, pkt, cr.pid);
+ break;
+
+ case APP_GROUP_GET_FG:
+ __dispatch_app_group_get_fg_flag(clifd, pkt);
+ break;
+
+ case APP_GROUP_GET_LEADER_PIDS:
+ __dispatch_app_group_get_leader_pids(clifd, pkt);
+ break;
+
+ case APP_GROUP_GET_GROUP_PIDS:
+ __dispatch_app_group_get_group_pids(clifd, pkt);
+ break;
+
+ case APP_GROUP_CLEAR_TOP:
+ __dispatch_app_group_clear_top(clifd, cr.pid);
+ break;
+
+ case APP_GROUP_GET_LEADER_PID:
+ __dispatch_app_group_get_leader_pid(clifd, pkt);
+ break;
+
+ case APP_GROUP_LOWER:
+ __dispatch_app_group_lower(clifd, cr.pid);
+ break;
+
+ case APP_GROUP_GET_IDLE_PIDS:
+ __dispatch_app_group_get_idle_pids(clifd, pkt);
+ break;
+
case APP_GET_CMDLINE:
memcpy(&pid, pkt->data, sizeof(int));
ret = _status_get_cmdline(clifd, pid);
_D("APP_GET_CMDLINE : %d : %d", pid, ret);
break;
+ case APP_GET_PID:
+ appid = (char *)malloc(MAX_PACKAGE_STR_SIZE);
+ if (appid == NULL) {
+ _E("failed to allocate appid");
+ __send_result_to_client(clifd, -1);
+ break;
+ }
+ strncpy(appid, (const char *)pkt->data, MAX_PACKAGE_STR_SIZE - 1);
+ ret = _status_app_is_running_v2_cached(appid);
+ SECURE_LOGD("APP_GET_PID: %s : %d", appid, ret);
+ __send_result_to_client(clifd, ret);
+ free(appid);
+ break;
+
+ case APP_GET_PID_CACHE:
+ appid = (char *)malloc(MAX_PACKAGE_STR_SIZE);
+ if (appid == NULL) {
+ _E("failed to allocate appid");
+ __send_result_to_client(clifd, -1);
+ break;
+ }
+ strncpy(appid, (const char *)pkt->data, MAX_PACKAGE_STR_SIZE - 1);
+ ret = _status_app_is_running_from_cache(appid);
+ SECURE_LOGD("APP_GET_PID_CACHE: %s : %d", appid, ret);
+ __send_result_to_client(clifd, ret);
+ free(appid);
+ break;
+
+ case APP_GET_LAST_CALLER_PID:
+ memcpy(&pid, pkt->data, sizeof(int));
+ ret = _status_get_app_info_last_caller_pid(pid);
+ SECURE_LOGD("APP_GET_LAST_CALLER_PID: %d : %d", pid, ret);
+ __send_result_to_client(clifd, ret);
+ break;
+ case APP_SET_PROCESS_GROUP:
+ owner_pid = atoi(bundle_get_val(kb, AUL_K_OWNER_PID));
+ child_pid = atoi(bundle_get_val(kb, AUL_K_CHILD_PID));
+ ret = _send_set_process_group_signal_signal(owner_pid, child_pid);
+ if (kb != NULL)
+ bundle_free(kb), kb = NULL;
+ __send_result_to_client(clifd, ret);
+ break;
+ case APP_GET_GROUP_INFO:
+ _status_send_group_info(clifd);
+ break;
default:
_E("no support packet");
close(clifd);
if (kb != NULL)
bundle_free(kb), kb = NULL;
+ traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
return TRUE;
}
.finalize = NULL
};
+#ifdef _APPFW_FEATURE_SEND_HOME_LAUNCH_SIGNAL
static void __home_appid_vconf_cb(keynode_t *key, void *data)
{
char *tmpstr;
}
home_appid = strdup(tmpstr);
}
+#endif
-int _request_init(struct amdmgr *amd)
+static int __signal_get_sigchld_fd(sigset_t mask)
+{
+ int sfd;
+
+ sfd = signalfd(-1, &mask, SFD_NONBLOCK | SFD_CLOEXEC);
+
+ if (sfd == -1) {
+ _E("failed to create signalfd for SIGCHLD");
+ return -1;
+ }
+
+ return sfd;
+}
+
+static void __release_app(int pid)
+{
+ const char *pkg_status;
+ const char *appid = NULL;
+ const struct appinfo *ai = NULL;
+
+ appid = _status_app_get_appid_bypid(pid);
+ ai = appinfo_find(_raf, appid);
+ pkg_status = appinfo_get_value(ai, AIT_STATUS);
+ SECURE_LOGI("appid: %s", appid);
+ if (ai && pkg_status && strncmp(pkg_status, "blocking", 8) == 0) {
+ appinfo_set_value((struct appinfo *)ai, AIT_STATUS, "restart");
+ } else if (ai && pkg_status && strncmp(pkg_status, "norestart", 9) == 0) {
+ appinfo_set_value((struct appinfo *)ai, AIT_STATUS, "installed");
+ } else {
+ if (appid != NULL && __check_restart(appid)) {
+ _release_srv(appid);
+ }
+ }
+
+ __send_app_termination_signal(pid);
+}
+
+static gboolean __sigchld_handler(gpointer data)
+{
+ int fd = (int)data;
+ struct signalfd_siginfo si;
+
+ while (1) {
+ int nr = read(fd, &si, sizeof(struct signalfd_siginfo));
+
+ if (nr != sizeof(struct signalfd_siginfo))
+ break;
+ while (1) {
+ int status;
+ pid_t pid = waitpid(-1, &status, WNOHANG);
+
+ if (pid <= 0)
+ break;
+ _D("Sig child %d", pid);
+ __release_app(pid);
+ }
+
+ }
+
+ return TRUE;
+}
+
+int _signal_block_sigchld(void)
+{
+ sigset_t mask;
+
+ sigemptyset(&mask);
+ sigaddset(&mask, SIGCHLD);
+
+ if (sigprocmask(SIG_BLOCK, &mask, &oldmask) == -1) {
+ _E("failed to sigprocmask");
+ return -1;
+ }
+
+ return __signal_get_sigchld_fd(mask);
+}
+
+int _signal_unblock_sigchld(void)
+{
+ if(sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0) {
+ _E("SIG_SETMASK error");
+ return -1;
+ }
+
+ _D("SIGCHLD unblocked");
+ return 0;
+}
+
+int _request_init(struct amdmgr *amd, int fd_sig)
{
int fd;
int r;
GPollFD *gpollfd;
+ GPollFD *gpollfd_sig;
GSource *src;
+ GSource *src_sig;
DBusError error;
fd = __create_server_sock(AUL_UTIL_PID);
+ if (fd < 0) {
+ _E("fail to create server sock");
+ return -1;
+ }
src = g_source_new(&funcs, sizeof(GSource));
gpollfd = (GPollFD *) g_malloc(sizeof(GPollFD));
if (gpollfd == NULL) {
- _E("out of memory");
g_source_unref(src);
close(fd);
return -1;
g_source_set_priority(src, G_PRIORITY_DEFAULT);
r = g_source_attach(src, NULL);
- if (r == 0)
- {
+ if (r == 0) {
+ _E("fail to attach the source : %d", r);
+ return -1;
+ }
+
+ src_sig = g_source_new(&funcs, sizeof(GSource));
+
+ gpollfd_sig = (GPollFD *) g_malloc(sizeof(GPollFD));
+ if (gpollfd_sig == NULL) {
+ g_source_unref(src_sig);
+ close(fd_sig);
+ return -1;
+ }
+
+ gpollfd_sig->events = G_IO_IN;
+ gpollfd_sig->fd = fd_sig;
+
+ g_source_add_poll(src_sig, gpollfd_sig);
+ g_source_set_callback(src_sig, (GSourceFunc) __sigchld_handler,
+ (gpointer) fd_sig, NULL);
+ g_source_set_priority(src_sig, G_PRIORITY_DEFAULT);
+ r = g_source_attach(src_sig, NULL);
+ if (r == 0) {
_E("fail to attach the source : %d", r);
return -1;
}
_raf = amd->af;
- _rcg = amd->cg;
r = rua_init();
r = rua_clear_history();
dbus_error_init(&error);
bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
+
+#ifdef _APPFW_FEATURE_SEND_HOME_LAUNCH_SIGNAL
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");
}
+#endif
+ restart_tbl = g_hash_table_new(g_str_hash, g_str_equal);
return 0;
}
+#ifdef _APPFW_FEATURE_SEND_HOME_LAUNCH_SIGNAL
+const char* _get_home_appid(void)
+{
+ return home_appid;
+}
+#endif
#ifndef __AUL_AMD_REQUEST_H_
#define __AUL_AMD_REQUEST_H_
-int _request_init(struct amdmgr *amd);
-
-
+int _request_init(struct amdmgr *amd, int fd_sig);
+int _release_srv(const char *appid);
+int _send_set_process_group_signal_signal(int owner_pid, int child_pid);
+int _signal_block_sigchld(void);
+int _signal_unblock_sigchld(void);
+#ifdef _APPFW_FEATURE_SEND_HOME_LAUNCH_SIGNAL
+const char* _get_home_appid(void);
+#endif
#endif
*
*/
+#define _GNU_SOURCE
#include <stdlib.h>
#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
#include <glib.h>
#include <aul.h>
#include <string.h>
#include <Ecore.h>
#include <proc_stat.h>
#include <pkgmgr-info.h>
-#ifdef _APPFW_FEATURE_VISIBILITY_CHECK_BY_LCD_STATUS
-#include <Ecore_X.h>
+#ifdef _APPFW_FEATURE_ULTRA_POWER_SAVING_MODE
#include <vconf/vconf.h>
#endif
+#include <bundle_internal.h>
+#include "launch.h"
#include "amd_config.h"
#include "amd_status.h"
#include "amd_appinfo.h"
+#include "amd_launch.h"
#include "aul_util.h"
#include "simple_util.h"
#include "app_sock.h"
#include "menu_db_util.h"
+#include "amd_app_group.h"
+
+#define WINDOW_READY "/tmp/.wm_ready"
+
+#ifdef _APPFW_FEATURE_COOLDOWN_MODE_SUPPORT
+int cooldown_status = 0;
+#endif // _APPFW_FEATURE_COOLDOWN_MODE_SUPPORT
GSList *app_status_info_list = NULL;
+GHashTable *pkg_status_info_table = NULL;
+GHashTable *app_running_cache = NULL;
struct appinfomgr *_saf = NULL;
-GHashTable *cooldown_tbl;
+#ifdef _APPFW_FEATURE_AMD_MODULE_LOG
+#define AMD_LOG_BUFFER_SIZE 10000
+#define AMD_LOG_BUFFER_STRING_SIZE 128
+#define AMD_LOG_FILE "/var/log/amd.log"
-GHashTable *cooldown_black_tbl;
+static int log_index = 0;
+static int log_fd = 0;
+#endif
-char *cooldown_list[] = {
-};
+static int __send_result_to_client(int clifd, int res)
+{
+ if (clifd < 0)
+ return -1;
-char *cooldown_black_list[] = {
-};
+ if (send(clifd, &res, sizeof(int), MSG_NOSIGNAL) < 0) {
+ if (errno == EPIPE)
+ _E("send failed due to EPIPE.\n");
+ _E("send fail to client");
+ }
-int cooldown_status = 0;
+ close(clifd);
-#define WHITE_LIST_COUNT 0
-#define BLACK_LIST_COUNT 0
+ return 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
+static app_status_info_t* __get_app_status_info(int pid)
+{
+ 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 (info_t && info_t->pid == pid) {
+ return info_t;
+ }
+ }
+
+ return NULL;
+}
+
+static void __add_running_cache(const char *appid, int pid)
+{
+ if (!appid || pid < 1)
+ return;
+
+ if (!app_running_cache)
+ app_running_cache = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
+
+ GSList *pid_list = NULL;
+
+ pid_list = (GSList *)g_hash_table_lookup(app_running_cache, appid);
+ if (pid_list == NULL) {
+ pid_list = g_slist_append(pid_list, GINT_TO_POINTER(pid));
+ g_hash_table_insert(app_running_cache, g_strdup(appid), pid_list);
+ } else {
+ if (!g_slist_find(pid_list, GINT_TO_POINTER(pid)))
+ pid_list = g_slist_append(pid_list, GINT_TO_POINTER(pid));
+ }
+}
+
+static void __remove_running_cache(const char *appid, int pid)
+{
+ if (!appid || pid < 1)
+ return;
+
+ if (!app_running_cache)
+ return;
+
+ GSList *pid_list = NULL;
+ GSList *remain_list = NULL;
+
+ pid_list = (GSList *)g_hash_table_lookup(app_running_cache, appid);
+ if (pid_list == NULL)
+ return;
+
+ remain_list = g_slist_remove(pid_list, GINT_TO_POINTER(pid));
+ if (remain_list && remain_list != pid_list) {
+ g_hash_table_replace(app_running_cache, g_strdup(appid), remain_list);
+ }
+
+ if (!remain_list) {
+ g_hash_table_remove(app_running_cache, appid);
+ }
+}
+
+static void __add_pkg_info(const char *pkgid, app_status_info_t *appinfo)
+{
+ pkg_status_info_t *pkginfo = NULL;
+
+ if (pkgid == NULL || appinfo == NULL) {
+ _E("empty arguments: %s", pkgid == NULL ? (appinfo == NULL ? "appinfo, pkgid" : "pkgid") : "appinfo");
+ return;
+ }
+
+ if (pkg_status_info_table == NULL)
+ pkg_status_info_table = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
+
+ pkginfo = g_hash_table_lookup(pkg_status_info_table, pkgid);
+ if (pkginfo == NULL) {
+ pkginfo = (pkg_status_info_t *)malloc(sizeof(pkg_status_info_t));
+ if (pkginfo == NULL) {
+ _E("failed to allocate memory");
+ return;
+ }
+ memset(pkginfo, 0, sizeof(pkg_status_info_t));
+ pkginfo->pkgid = strdup(pkgid);
+ if (pkginfo->pkgid == NULL) {
+ free(pkginfo);
+ _E("failed to allocate memory");
+ return;
+ }
+ g_hash_table_insert(pkg_status_info_table, pkginfo->pkgid, pkginfo);
+ }
+
+ pkginfo->status = appinfo->status;
+ appinfo->pkginfo = pkginfo;
+
+ if (appinfo->status == STATUS_SERVICE) {
+ pkginfo->svc_list = g_slist_append(pkginfo->svc_list, appinfo);
+ }
+ else {
+ pkginfo->ui_list = g_slist_append(pkginfo->ui_list, appinfo);
+ }
+}
+
+static int __get_ui_app_status_pkg_info(pkg_status_info_t *pkginfo)
+{
+ app_status_info_t *appinfo = NULL;
+ GSList *iter = NULL;
+ int status = STATUS_BG;
+
+ if (pkginfo == NULL)
+ return -1;
+
+ iter = pkginfo->ui_list;
+ while (iter) {
+ appinfo = (app_status_info_t *)iter->data;
+ if (appinfo->status != STATUS_BG) {
+ status = appinfo->status;
+ }
+
+ iter = g_slist_next(iter);
+ }
+
+ return status;
+}
+
+static int __update_pkg_info(const char *pkgid, app_status_info_t *appinfo)
+{
+ pkg_status_info_t *pkginfo = NULL;
+ int ret = 0;
+
+ if (pkgid == NULL || appinfo == NULL)
+ return -1;
+
+ if (pkg_status_info_table == NULL) {
+ return -1;
+ }
+
+ pkginfo = (pkg_status_info_t *)g_hash_table_lookup(pkg_status_info_table, pkgid);
+ if (pkginfo == NULL) {
+ _E("pkgid(%s) is not on list");
+ return -1;
+ }
+
+ if (pkginfo->ui_list) {
+ ret = __get_ui_app_status_pkg_info(pkginfo);
+ if (ret > -1)
+ pkginfo->status = ret;
+ }
+ else
+ pkginfo->status = STATUS_SERVICE;
+
+ return 0;
+}
+
+
+static void __remove_pkg_info(const char *pkgid, app_status_info_t *appinfo)
+{
+ pkg_status_info_t *pkginfo = NULL;
+ const struct appinfo *ai = NULL;
+ const char *component_type = NULL;
+
+ if (pkgid == NULL || appinfo == NULL) {
+ _E("empty arguments: %s", pkgid == NULL ? (appinfo == NULL ? "appinfo, pkgid" : "pkgid") : "appinfo");
+ return;
+ }
+
+ ai = appinfo_find(_saf, appinfo->appid);
+ component_type = appinfo_get_value(ai, AIT_COMPTYPE);
+
+ pkginfo = (pkg_status_info_t *)g_hash_table_lookup(pkg_status_info_table, pkgid);
+ if (pkginfo == NULL) {
+ _E("pkgid(%s) is not on list");
+ return;
+ }
+
+ if (component_type && strcmp(component_type, APP_TYPE_SERVICE) == 0) {
+ if (pkginfo->svc_list) {
+ pkginfo->svc_list = g_slist_remove(pkginfo->svc_list, appinfo);
+ _D("STATUS_SERVICE : appid(%s)", appinfo->appid);
+ }
+ } else {
+ if (pkginfo->ui_list) {
+ pkginfo->ui_list = g_slist_remove(pkginfo->ui_list, appinfo);
+ _D("~STATUS_SERVICE : appid(%s)", appinfo->appid);
+ }
+ }
+
+ if (!pkginfo->svc_list && !pkginfo->ui_list) {
+ g_hash_table_remove(pkg_status_info_table, pkgid);
+ if (pkginfo->pkgid) {
+ free(pkginfo->pkgid);
+ pkginfo->pkgid = NULL;
+ }
+ free(pkginfo);
+ }
+}
+
+static void __remove_all_shared_info(app_status_info_t *info_t)
+{
+ if (info_t && info_t->shared_info_list) {
+ GList *list = info_t->shared_info_list;
+
+ while (list) {
+ shared_info_t *sit = (shared_info_t*)list->data;
+
+ if (sit) {
+ if (sit->owner_exec_label)
+ free(sit->owner_exec_label);
+ if (sit->paths) {
+ int i = 0;
+ while (1) {
+ if (sit->paths[i] == NULL) {
+ free(sit->paths);
+ break;
+ }
+
+ free(sit->paths[i]);
+ i++;
+ }
+ }
+ free(sit);
+ }
+ list = g_list_next(list);
+ }
+
+ g_list_free(info_t->shared_info_list);
+ info_t->shared_info_list = NULL;
+ }
+}
+
+static void __destroy_app_status_info(app_status_info_t *info_t)
+{
+ if (info_t == NULL)
+ return;
+
+ if (info_t->appid) {
+ free(info_t->appid);
+ info_t->appid = NULL;
+ }
+
+ if (info_t->app_path) {
+ free(info_t->app_path);
+ info_t->app_path = NULL;
+ }
+
+ if (info_t->caller) {
+ free(info_t->caller);
+ info_t->caller = NULL;
+ }
-int _status_add_app_info_list(char *appid, char *app_path, const char *caller, int pid, int pad_pid)
+ if (info_t->pkgid) {
+ free(info_t->pkgid);
+ info_t->pkgid = NULL;
+ }
+
+ if (info_t->exec_label) {
+ free(info_t->exec_label);
+ info_t->exec_label = NULL;
+ }
+
+ __remove_all_shared_info(info_t);
+ free(info_t);
+}
+
+int _status_add_app_info_list(const char *appid, const char *app_path,
+ const char *caller, int pid, int pad_pid, int is_subapp)
{
GSList *iter = NULL;
app_status_info_t *info_t = NULL;
+ const struct appinfo *ai;
+ const char *component_type = NULL;
+ const char *pkgid = NULL;
- for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
- {
+ if (!appid || !app_path)
+ return -1;
+
+ for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter)) {
info_t = (app_status_info_t *)iter->data;
- if(pid == info_t->pid) {
- return 0;
+ if (pid == info_t->pid) {
+ if (!strcmp(appid, info_t->appid)) {
+ return 0;
+ } else {
+ __remove_running_cache(info_t->appid, info_t->pid);
+ app_status_info_list = g_slist_remove(app_status_info_list, info_t);
+
+ __remove_pkg_info(info_t->pkgid, info_t);
+
+ __destroy_app_status_info(info_t);
+ break;
+ }
}
}
+ ai = appinfo_find(_saf, appid);
+
info_t = malloc(sizeof(app_status_info_t));
if (info_t == NULL) {
_E("out of memory");
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->appid = strdup(appid);
+ if (info_t->appid == NULL)
+ goto error;
+
+ info_t->app_path = strdup(app_path);
+ if (info_t->app_path == NULL)
+ goto error;
+
+ if (caller) {
+ info_t->caller = strdup(caller);
+ if (info_t->caller == NULL)
+ goto error;
+ }
+
+ component_type = appinfo_get_value(ai, AIT_COMPTYPE);
+ if (component_type && strcmp(component_type, APP_TYPE_SERVICE) == 0) {
+ info_t->status = STATUS_SERVICE;
+ } else {
+ info_t->status = STATUS_LAUNCHING;
+ }
+
+ pkgid = appinfo_get_value(ai, AIT_PKGID);
+ if (pkgid == NULL)
+ goto error;
+
info_t->pid = pid;
info_t->pad_pid = pad_pid;
+ info_t->is_subapp = is_subapp;
+ info_t->shared_info_list = NULL;
+ info_t->exec_label = NULL;
+
+ info_t->pkgid = strdup(pkgid);
+ if (info_t->pkgid == NULL)
+ goto error;
+
app_status_info_list = g_slist_append(app_status_info_list, info_t);
- for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
- {
- info_t = (app_status_info_t *)iter->data;
+ __add_pkg_info(pkgid, info_t);
- //SECURE_LOGD("%s, %d, %d", info_t->appid, info_t->pid, info_t->status);
- }
+ __add_running_cache(info_t->appid, pid);
+
+ _D("pid(%d) appid(%s) pkgid(%s) comp(%s)", pid, appid, pkgid, component_type);
return 0;
+
+error:
+ __destroy_app_status_info(info_t);
+
+ return -1;
}
static Eina_Bool __app_terminate_timer_cb(void *data)
ret = kill(pid, SIGKILL);
if (ret == -1)
- _D("send SIGKILL: %s", strerror(errno));
+ _W("send SIGKILL: %s", strerror(errno));
return ECORE_CALLBACK_CANCEL;
}
-int _status_update_app_info_list(int pid, int status)
+int _status_update_app_info_list(int pid, int status, gboolean force)
{
GSList *iter = NULL;
app_status_info_t *info_t = NULL;
+ _D("pid(%d) status(%d)", pid, status);
for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
{
info_t = (app_status_info_t *)iter->data;
info_t->status = status;
if(status == STATUS_DYING) {
if(info_t->pad_pid != DEBUG_LAUNCHPAD_PID)
- ecore_timer_add(2, __app_terminate_timer_cb, info_t->pid);
+ ecore_timer_add(5, __app_terminate_timer_cb, (void *)info_t->pid);
}
+ __update_pkg_info(info_t->pkgid, info_t);
+
+ _D("pid(%d) appid(%s) pkgid(%s) status(%d)", pid, info_t->appid, info_t->pkgid, info_t->status);
break;
}
}
- for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
- {
- info_t = (app_status_info_t *)iter->data;
-
- //SECURE_LOGD("%s, %d, %d", info_t->appid, info_t->pid, info_t->status);
- }
+ app_group_set_status(pid, status, force);
return 0;
}
{
info_t = (app_status_info_t *)iter->data;
if(pid == info_t->pid) {
+ __remove_running_cache(info_t->appid, info_t->pid);
app_status_info_list = g_slist_remove(app_status_info_list, info_t);
- free(info_t);
- break;
- }
- }
- for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
- {
- info_t = (app_status_info_t *)iter->data;
+ __remove_pkg_info(info_t->pkgid, info_t);
- //SECURE_LOGD("%s, %d, %d", info_t->appid, info_t->pid, info_t->status);
+ __destroy_app_status_info(info_t);
+ break;
+ }
}
return 0;
}
}
+ return app_group_get_status(pid);
+}
+
+static gint __find_app_bypid(gconstpointer app_data, gconstpointer pid_data)
+{
+ int pid = GPOINTER_TO_INT(pid_data);
+ app_status_info_t *appinfo = (app_status_info_t *)app_data;
+
+ if (appinfo && pid && appinfo->pid == pid)
+ return 0;
+
+ return -1;
+}
+
+void _status_find_service_apps(int pid, enum app_status status, void (*send_event_to_svc_core) (int))
+{
+ GSList *app_list = NULL;
+ GSList *svc_list = NULL;
+ app_status_info_t *info_t = NULL;
+ app_status_info_t *svc_info_t = NULL;
+
+ app_list = g_slist_find_custom(app_status_info_list, GINT_TO_POINTER(pid), __find_app_bypid);
+
+ if (!app_list) {
+ _E("unable to find app by pid:%d", pid);
+ return;
+ }
+
+ info_t = (app_status_info_t *)app_list->data;
+ if (info_t && info_t->pkginfo && info_t->pkginfo->status == status)
+ svc_list = info_t->pkginfo->svc_list;
+
+ while (svc_list) {
+ svc_info_t = (app_status_info_t *)svc_list->data;
+ if (svc_info_t)
+ send_event_to_svc_core(svc_info_t->pid);
+
+ svc_list = g_slist_next(svc_list);
+ }
+}
+
+void _status_check_service_only(int pid, void (*send_event_to_svc_core) (int))
+{
+ GSList *app_list = NULL;
+ GSList *ui_list = NULL;
+ app_status_info_t *info_t = NULL;
+ app_status_info_t *ui_info_t = NULL;
+ int ui_cnt = 0;
+
+ app_list = g_slist_find_custom(app_status_info_list, GINT_TO_POINTER(pid), __find_app_bypid);
+
+ if (!app_list) {
+ _E("unable to find app by pid:%d", pid);
+ return;
+ }
+
+ info_t = (app_status_info_t *)app_list->data;
+ ui_list = info_t->pkginfo->ui_list;
+ while (ui_list) {
+ ui_info_t = (app_status_info_t *)ui_list->data;
+ if (ui_info_t && _status_app_is_running_v2(ui_info_t->appid) > 0) {
+ ui_cnt++;
+ }
+ ui_list = g_slist_next(ui_list);
+ }
+
+ if (ui_cnt == 0)
+ send_event_to_svc_core(pid);
+}
+
+int _status_update_app_info_caller_pid(int pid, int caller_pid)
+{
+ 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 (info_t && info_t->pid == pid) {
+ info_t->last_caller_pid = caller_pid;
+ return 0;
+ }
+ }
+ return -1;
+}
+
+int _status_set_exec_label(int pid, const char *exec_label)
+{
+ app_status_info_t *info_t = __get_app_status_info(pid);
+
+ if (info_t) {
+ if (info_t->exec_label)
+ free(info_t->exec_label);
+ info_t->exec_label = strdup(exec_label);
+ return 0;
+ }
+
+ return -1;
+}
+
+const char* _status_get_exec_label(int pid)
+{
+ app_status_info_t *info_t = __get_app_status_info(pid);
+
+ if (info_t)
+ return info_t->exec_label;
+
+ return NULL;
+}
+
+int _status_add_shared_info(int pid, const char *exec_label, char **paths)
+{
+ shared_info_t *sit = (shared_info_t*)malloc(sizeof(shared_info_t));
+
+ if (!sit)
+ return -1;
+
+ sit->owner_exec_label = strdup(exec_label);
+ sit->paths = paths;
+
+ app_status_info_t* info_t = __get_app_status_info(pid);
+
+ if (info_t) {
+ info_t->shared_info_list = g_list_append(info_t->shared_info_list, sit);
+ return 0;
+ }
+
+ if (sit->owner_exec_label)
+ free(sit->owner_exec_label);
+ free(sit);
+ return -1;
+}
+
+int _status_clear_shared_info_list(int pid)
+{
+ app_status_info_t* info_t = __get_app_status_info(pid);
+
+ if (info_t) {
+ __remove_all_shared_info(info_t);
+ return 0;
+ }
+
return -1;
}
+GList* _status_get_shared_info_list(int pid)
+{
+ app_status_info_t *info_t = __get_app_status_info(pid);
+
+ if (info_t)
+ return info_t->shared_info_list;
+
+ return NULL;
+}
-int _status_app_is_running(char *appid)
+int _status_get_app_info_last_caller_pid(int pid)
+{
+ 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 (info_t && info_t->pid == pid) {
+ return info_t->last_caller_pid;
+ }
+ }
+ return -1;
+}
+
+int _status_app_is_running(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) == 0 ) {
+ if( strncmp(appid, info_t->appid, MAX_PACKAGE_STR_SIZE) == 0 && !info_t->is_subapp) {
return info_t->pid;
}
}
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) {
+ if( strncmp(appid, info_t->appid, MAX_PACKAGE_STR_SIZE-1) == 0 && !info_t->is_subapp) {
return info_t->caller;
}
}
return NULL;
}
+
int _status_send_running_appinfo(int fd)
{
GSList *iter = NULL;
app_status_info_t *info_t = NULL;
app_pkt_t *pkt = NULL;
- int len;
char tmp_pid[MAX_PID_STR_BUFSZ];
- pkt = (app_pkt_t *) malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
- if(!pkt) {
+ pkt = (app_pkt_t *)malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
+ if (!pkt) {
_E("malloc fail");
- return 0;
+ __send_result_to_client(fd, -1);
+ return -1;
}
memset(pkt, 0, AUL_SOCK_MAXBUFF);
for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
{
info_t = (app_status_info_t *)iter->data;
+ if (app_group_is_sub_app(info_t->pid))
+ continue;
+
snprintf(tmp_pid, MAX_PID_STR_BUFSZ, "%d", info_t->pid);
strncat((char *)pkt->data, tmp_pid, MAX_PID_STR_BUFSZ);
strncat((char *)pkt->data, ":", 1);
pkt->cmd = APP_RUNNING_INFO_RESULT;
pkt->len = strlen((char *)pkt->data) + 1;
- if ((len = send(fd, pkt, pkt->len + 8, 0)) != pkt->len + 8) {
+ if ((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)
+ if (pkt)
free(pkt);
close(fd);
return 0;
}
-int _status_app_is_running_v2(char *appid)
+int _status_app_is_running_v2(const char *appid)
{
char *apppath = NULL;
int ret = 0;
int i = 0;
- const char *ae;
+ const char *ae = NULL;
const struct appinfo *ai;
if(appid == NULL)
return -1;
apppath = strdup(ae);
- if (apppath == NULL) {
- _E("out of memory");
+ if (apppath == NULL)
return -1;
- }
/*truncate apppath if it includes default bundles */
while (apppath[i] != 0) {
return ret;
}
+int _status_app_is_running_from_cache(const char *appid)
+{
+ const char *path = NULL;
+ GSList *pid_list = NULL;
+ const struct appinfo *ai;
+
+ if (app_running_cache)
+ pid_list = (GSList *)g_hash_table_lookup(app_running_cache, appid);
+
+ if (pid_list) {
+ ai = appinfo_find(_saf, appid);
+ if (ai == NULL)
+ return -1;
+
+ path = appinfo_get_value(ai, AIT_EXEC);
+ if (path == NULL)
+ return -1;
+
+ while (pid_list) {
+ if (__proc_check_app(path, GPOINTER_TO_INT(pid_list->data))) {
+ _D("is_running hit cache, return immediately");
+ return GPOINTER_TO_INT(pid_list->data);
+ } else {
+ _E("is_running garbage, pid: %d", GPOINTER_TO_INT(pid_list->data));
+ __remove_running_cache(appid, GPOINTER_TO_INT(pid_list->data));
+ }
+ pid_list = pid_list->next;
+ }
+ }
+
+ return 0;
+}
+
+int _status_app_is_running_v2_cached(const char *appid)
+{
+ int ret = 0;
+
+ ret = _status_app_is_running_from_cache(appid);
+ if (ret > 0)
+ return ret;
+
+ ret = _status_app_is_running_v2(appid);
+ if (ret > 0) {
+ _E("is running missing app detected: %s (%d)", appid, ret);
+ __add_running_cache((char *)appid, ret);
+ }
+
+ return ret;
+}
+
static int __get_pkginfo(const char *dname, const char *cmdline, void *priv)
{
app_info_from_db *menu_info;
int _status_send_running_appinfo_v2(int fd)
{
app_pkt_t *pkt = NULL;
- int len;
pkt = (app_pkt_t *) malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
- if(!pkt) {
+ if (!pkt) {
_E("malloc fail");
- close(fd);
- return 0;
+ __send_result_to_client(fd, -1);
+ return -1;
}
memset(pkt, 0, AUL_SOCK_MAXBUFF);
pkt->cmd = APP_RUNNING_INFO_RESULT;
pkt->len = strlen((char *)pkt->data) + 1;
- if ((len = send(fd, pkt, pkt->len + 8, 0)) != pkt->len + 8) {
+ if ((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)
+ if (pkt)
free(pkt);
close(fd);
int _status_get_appid_bypid(int fd, int pid)
{
app_pkt_t *pkt = NULL;
- int len;
int pgid;
pkt = (app_pkt_t *) malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
out:
pkt->len = strlen((char *)pkt->data) + 1;
- if ((len = send(fd, pkt, pkt->len + 8, 0)) != pkt->len + 8) {
+ if ((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");
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);
out:
pkt->len = strlen((char *)pkt->data) + 1;
- if ((len = send(fd, pkt, pkt->len + 8, 0)) != pkt->len + 8) {
+ if ((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");
{
app_pkt_t *pkt = NULL;
int len;
- int pgid;
char *cmdline;
pkt = (app_pkt_t *) malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
- if(!pkt) {
+ if (!pkt) {
_E("malloc fail");
close(fd);
return 0;
goto out;
_E("cmdline : %s", cmdline);
- snprintf((char *)pkt->data, MAX_PACKAGE_STR_SIZE, cmdline);
+ strncpy((char *)pkt->data, cmdline, MAX_PACKAGE_STR_SIZE);
_E("pkt->data : %s", pkt->data);
pkt->cmd = APP_GET_INFO_OK;
}
-static void __app_info_iter_limit_cb(void *user_data, const char *appid, const struct appinfo *ai)
+int _status_send_group_info(int fd)
{
- if(!g_hash_table_lookup(cooldown_tbl, appid)) {
- appinfo_set_value(ai, AIT_STATUS, "blocking");
+ GSList *iter = NULL;
+ GSList *iter2 = NULL;
+ app_status_info_t *info_t = NULL;
+ app_status_info_t *info_t2 = NULL;
+ app_pkt_t *pkt = NULL;
+ char buf[2048];
+
+ pkt = (app_pkt_t *) malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
+ if (!pkt) {
+ _E("malloc fail");
+ __send_result_to_client(fd, -1);
+ return -1;
}
-}
-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");
+ memset(pkt, 0, AUL_SOCK_MAXBUFF);
+
+ snprintf(buf, sizeof(buf), "=======================STATUS_LAUNCHING======================\n");
+ strncat((char *)pkt->data, buf, 2048);
+ for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
+ {
+ info_t = (app_status_info_t *)iter->data;
+ if(info_t->status == STATUS_LAUNCHING) {
+ snprintf(buf, sizeof(buf), "%s(%d)=>", info_t->appid, info_t->pid);
+ strncat((char *)pkt->data, buf, 2048);
+ snprintf(buf, sizeof(buf), "||\n");
+ strncat((char *)pkt->data, buf, 2048);
+ }
}
-}
-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;
+ snprintf(buf, sizeof(buf), "\n");
+ strncat((char *)pkt->data, buf, 2048);
- 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 && component && strncmp(component, "svcapp", 6) == 0)
- {
- if (_status_app_is_running(appid) < 0)
+ snprintf(buf, sizeof(buf), "=======================STATUS_FG=============================\n");
+ strncat((char *)pkt->data, buf, 2048);
+ for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
+ {
+ info_t = (app_status_info_t *)iter->data;
+
+ _D("%s(%d)=>", info_t->appid, info_t->pid);
+ if(info_t->status != STATUS_VISIBLE) {
+ continue;
+ }
+
+ snprintf(buf, sizeof(buf), "%s(%d)=>", info_t->appid, info_t->pid);
+ strncat((char *)pkt->data, buf, 2048);
+ snprintf(buf, sizeof(buf), "||\n");
+ strncat((char *)pkt->data, buf, 2048);
+
+ }
+
+ snprintf(buf, sizeof(buf), "\n");
+ strncat((char *)pkt->data, buf, 2048);
+
+ snprintf(buf, sizeof(buf), "=======================STATUS_BG=============================\n");
+ strncat((char *)pkt->data, buf, 2048);
+
+ for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
+ {
+ info_t = (app_status_info_t *)iter->data;
+
+ if(info_t->status != STATUS_BG)
+ continue;
+ snprintf(buf, sizeof(buf), "%s(%d)=>", info_t->appid, info_t->pid);
+ strncat((char *)pkt->data, buf, 2048);
+ snprintf(buf, sizeof(buf), "||\n");
+ strncat((char *)pkt->data, buf, 2048);
+
+ }
+
+ snprintf(buf, sizeof(buf), "\n");
+ strncat((char *)pkt->data, buf, 2048);
+
+ snprintf(buf, sizeof(buf), "=======================STATUS_SERVICE(FG)====================\n");
+ strncat((char *)pkt->data, buf, 2048);
+ for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
+ {
+ info_t = (app_status_info_t *)iter->data;
+ if(info_t->status == STATUS_SERVICE && info_t->pkginfo->status == STATUS_VISIBLE) {
+ snprintf(buf, sizeof(buf), "[pkgid(%s)]", info_t->pkginfo->pkgid);
+ strncat((char *)pkt->data, buf, 2048);
+ for (iter2 = info_t->pkginfo->svc_list; iter2 != NULL; iter2 = g_slist_next(iter2))
{
- _I("start service (cooldown release) - %s", appid);
- _start_srv(ai, NULL);
+ info_t2 = (app_status_info_t *)iter2->data;
+ snprintf(buf, sizeof(buf), "%s(%d)=>", info_t2->appid, info_t2->pid);
+ strncat((char *)pkt->data, buf, 2048);
}
- else
+ snprintf(buf, sizeof(buf), "||\n");
+ strncat((char *)pkt->data, buf, 2048);
+ }
+ }
+ snprintf(buf, sizeof(buf), "\n");
+ strncat((char *)pkt->data, buf, 2048);
+
+ snprintf(buf, sizeof(buf), "=======================STATUS_SERVICE(BG)====================\n");
+ strncat((char *)pkt->data, buf, 2048);
+ for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
+ {
+ info_t = (app_status_info_t *)iter->data;
+ if(info_t->status == STATUS_SERVICE && info_t->pkginfo->status == STATUS_BG) {
+ snprintf(buf, sizeof(buf), "[pkgid(%s)]", info_t->pkginfo->pkgid);
+ strncat((char *)pkt->data, buf, 2048);
+ for (iter2 = info_t->pkginfo->svc_list; iter2 != NULL; iter2 = g_slist_next(iter2))
{
- _E("service: %s is already running", appid);
+ info_t2 = (app_status_info_t *)iter2->data;
+ snprintf(buf, sizeof(buf), "%s(%d)=>", info_t2->appid, info_t2->pid);
+ strncat((char *)pkt->data, buf, 2048);
}
+ snprintf(buf, sizeof(buf), "||\n");
+ strncat((char *)pkt->data, buf, 2048);
}
- appinfo_set_value(ai, AIT_STATUS, "installed");
}
+ snprintf(buf, sizeof(buf), "\n");
+ strncat((char *)pkt->data, buf, 2048);
+
+ snprintf(buf, sizeof(buf), "=======================STATUS_SERVICE========================\n");
+ strncat((char *)pkt->data, buf, 2048);
+ for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
+ {
+ info_t = (app_status_info_t *)iter->data;
+ if(info_t->status == STATUS_SERVICE && info_t->pkginfo->status == STATUS_SERVICE) {
+ snprintf(buf, sizeof(buf), "[pkgid(%s)]", info_t->pkginfo->pkgid);
+ _D("[pkgid(%s)]", info_t->pkginfo->pkgid);
+ strncat((char *)pkt->data, buf, 2048);
+ for (iter2 = info_t->pkginfo->svc_list; iter2 != NULL; iter2 = g_slist_next(iter2))
+ {
+ info_t2 = (app_status_info_t *)iter2->data;
+ snprintf(buf, sizeof(buf), "%s(%d)=>", info_t2->appid, info_t2->pid);
+ strncat((char *)pkt->data, buf, 2048);
+ }
+ snprintf(buf, sizeof(buf), "||\n");
+ strncat((char *)pkt->data, buf, 2048);
+ }
+ }
+
+ snprintf(buf, sizeof(buf), "************************************************************\n");
+ strncat((char *)pkt->data, buf, 2048);
+
+ pkt->cmd = APP_GET_GROUP_INFO;
+ pkt->len = strlen((char *)pkt->data) + 1;
+
+ if ((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;
}
+#ifdef _APPFW_FEATURE_COOLDOWN_MODE_SUPPORT
+static void __app_info_iter_limit_cb(void *user_data, const char *appid, const struct appinfo *ai)
+{
+ if(appinfo_get_boolean(ai, AIT_TASKMANAGE) && !appinfo_get_boolean(ai, AIT_COOLDOWN) ) {
+ appinfo_set_value((struct appinfo *)ai, AIT_STATUS, "blocking");
+ }
+}
+static void __app_info_iter_release_cb(void *user_data, const char *appid, const struct appinfo *ai)
+{
+ if(appinfo_get_boolean(ai, AIT_TASKMANAGE) && !appinfo_get_boolean(ai, AIT_COOLDOWN) ) {
+ appinfo_set_value((struct appinfo *)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;
+ const struct appinfo *ai;
int dummy;
- _I("__cooldown_cb, status: %s", status);
+ _D("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) );
+ ai = appinfo_find(_saf, info_t->appid);
+ if(appinfo_get_boolean(ai, AIT_TASKMANAGE) && !appinfo_get_boolean(ai, AIT_COOLDOWN)) {
+ appinfo_set_value((struct appinfo *)ai, AIT_STATUS, "blocking");
+ const char *type = appinfo_get_value(ai, AIT_COMPTYPE);
+ aul_send_app_terminate_request_signal(info_t->pid, info_t->appid, info_t->pkgid, type);
+ __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){
+ } else if (strncmp(status, "Release", 7) == 0 && cooldown_status != COOLDOWN_RELEASE){
appinfo_foreach(_saf, __app_info_iter_release_cb, NULL);
cooldown_status = COOLDOWN_RELEASE;
}
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;
- }
+#endif // _APPFW_FEATURE_COOLDOWN_MODE_SUPPORT
- if (gesture == WAKE_UP_GESTURE_CLOCK) {
- SECURE_LOGD("Skip when wake-up gesture is a Clock.");
- return 0;
- }
+#ifdef _APPFW_FEATURE_ULTRA_POWER_SAVING_MODE
+static void __app_info_iter_ups_release_cb(void *user_data, const char *appid, const struct appinfo *ai)
+{
+ const char *component = NULL;
+ int onboot = 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;
+ component = appinfo_get_value(ai, AIT_COMPTYPE);
+ onboot = appinfo_get_boolean(ai, AIT_ONBOOT);
+ if (onboot == 1 && strncmp(component, "svcapp", 6) == 0) {
+ if (_status_app_is_running(appid) < 0) {
+ _W("start service (ups release) - %s", appid);
+ _start_srv(ai);
+ } else {
+ _E("service: %s is already running", appid);
+ }
}
- 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);
+static void __ups_cb(keynode_t *key, void *data)
+{
+ const char *name = NULL;
+ int ups_mode = 0;
+
+ name = vconf_keynode_get_name(key);
+ if (name == NULL) {
+ _E("vconf key value for UPS mode is invalid");
+ return;
+ } else if (strcmp(name, VCONFKEY_SETAPPL_PSMODE) == 0) {
+ ups_mode = vconf_keynode_get_int(key);
+ if (ups_mode == SETTING_PSMODE_NORMAL) {
+ _W("UPS mode is disabled");
+ appinfo_foreach(_saf, __app_info_iter_ups_release_cb, NULL);
}
-
- // 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;
- }
+ else if (ups_mode == SETTING_PSMODE_EMERGENCY) {
+ _W("UPS mode is enabled");
+ }
+ else {
+ _W("Current Power Saving mode: %d", ups_mode);
}
-
- 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
+#endif //_APPFW_FEATURE_ULTRA_POWER_SAVING_MODE
-static int __app_info_handler (const pkgmgrinfo_appinfo_h handle, void *data)
+#ifdef _APPFW_FEATURE_AMD_MODULE_LOG
+static int _status_log_init(void)
{
- char *tmp_appid;
- char *appid;
+ int offset = 0;
- pkgmgrinfo_appinfo_get_appid(handle, &tmp_appid);
+ log_fd = open(AMD_LOG_FILE, O_CREAT | O_WRONLY, 0644);
- appid = strdup(tmp_appid);
+ if(log_fd < 0)
+ return -1;
- g_hash_table_insert(cooldown_tbl, appid, appid);
+ offset = lseek(log_fd, 0, SEEK_END);
+ if (offset != 0) {
+ log_index = (int)(offset / AMD_LOG_BUFFER_STRING_SIZE);
- SECURE_LOGD("white_list : %s", appid);
+ if (log_index >= AMD_LOG_BUFFER_SIZE) {
+ log_index = 0;
+ lseek(log_fd, 0, SEEK_SET);
+ }
+ }
return 0;
}
-static int __blacklist_app_info_handler (const pkgmgrinfo_appinfo_h handle, void *data)
+int _status_log_save(const char *tag, const char *message)
{
- char *tmp_appid;
- char *appid;
+ int ret = 0;
+ int offset = 0;
+ time_t now;
+ char time_buf[32] = {0,};
+ char buffer[AMD_LOG_BUFFER_STRING_SIZE] = {0,};
- pkgmgrinfo_appinfo_get_appid(handle, &tmp_appid);
+ if(log_fd < 0)
+ return -1;
- appid = strdup(tmp_appid);
+ time(&now);
+ ctime_r(&now, time_buf);
+ if (log_index != 0) {
+ offset = lseek(log_fd, 0, SEEK_CUR);
+ } else {
+ offset = lseek(log_fd, 0, SEEK_SET);
+ }
- g_hash_table_insert(cooldown_black_tbl, appid, appid);
+ if (offset == -1)
+ _E("error in lseek: %s", strerror(errno));
- SECURE_LOGD("white_list : %s", appid);
+ snprintf(buffer, AMD_LOG_BUFFER_STRING_SIZE, "[%-6d] %-15s %-50s %s", log_index, tag, message, time_buf);
+
+ ret = write(log_fd, buffer, strlen(buffer));
+ if (ret < 0) {
+ _E("Cannot write the amd log: %d", ret);
+ return -1;
+ }
+
+ if (++log_index >= AMD_LOG_BUFFER_SIZE) {
+ log_index = 0;
+ }
return 0;
}
+#endif
int _status_init(struct amdmgr* amd)
{
- int i;
- pkgmgrinfo_appinfo_h handle = NULL;
-
_saf = amd->af;
+#ifdef _APPFW_FEATURE_COOLDOWN_MODE_SUPPORT
aul_listen_cooldown_signal(__cooldown_cb, NULL);
+#endif // _APPFW_FEATURE_COOLDOWN_MODE_SUPPORT
- 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_ULTRA_POWER_SAVING_MODE
+ if (vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE, __ups_cb, NULL) != 0) {
+ _E("Unable to register callback for VCONFKEY_SETAPPL_PSMODE");
}
+#endif
-#ifdef _APPFW_FEATURE_VISIBILITY_CHECK_BY_LCD_STATUS
- // Register callback for LCD On/Off
- aul_listen_lcd_status_signal(__lcd_status_cb, NULL);
+#ifdef _APPFW_FEATURE_AMD_MODULE_LOG
+ _status_log_init();
#endif
+
return 0;
}
+gboolean _status_check_window_ready(void)
+{
+ if (access(WINDOW_READY, R_OK) == 0)
+ return true;
+ else
+ return false;
+}
*
*/
+#ifndef __AUL_AMD_STATUS_H_
+#define __AUL_AMD_STATUS_H_
+#include <glib.h>
-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_add_app_info_list(const char *appid, const char *app_path,
+ const char *caller, int pid, int pad_pid, int is_subapp);
+int _status_update_app_info_list(int pid, int status, gboolean force);
+int _status_update_app_info_caller_pid(int pid, int caller_pid);
+int _status_get_app_info_last_caller_pid(int pid);
int _status_remove_app_info_list(int pid);
int _status_get_app_info_status(int pid);
-int _status_app_is_running(char *appid);
+int _status_app_is_running(const char *appid);
+void _status_find_service_apps(int pid, enum app_status, void (*send_event_to_svc_core) (int));
+void _status_check_service_only(int pid, void (*send_event_to_svc_core) (int));
+char* _status_app_get_appid_bypid(int pid);
+
int _status_send_running_appinfo(int fd);
-int _status_app_is_running_v2(char *appid);
+int _status_app_is_running_v2(const char *appid);
+int _status_app_is_running_v2_cached(const char *appid);
+int _status_app_is_running_from_cache(const char *appid);
int _status_send_running_appinfo_v2(int fd);
int _status_get_pkgname_bypid(int pid, char *pkgname, int len);
int _status_get_appid_bypid(int fd, int pid);
int _status_get_pkgid_bypid(int fd, int pid);
+int _status_get_cmdline(int fd, int pid);
+int _status_send_group_info(int fd);
char* _status_get_caller_by_appid(const char *appid);
int _status_get_cooldown_status(void);
+int _status_set_exec_label(int pid, const char *exec_label);
+const char* _status_get_exec_label(int pid);
+int _status_set_caller_exec_label(int pid, const char *exec_label);
+int _status_add_shared_info(int pid, const char *exec_label, char **paths);
+int _status_clear_shared_info_list(int pid);
+GList* _status_get_shared_info_list(int pid);
+gboolean _status_check_window_ready(void);
+#ifdef _APPFW_FEATURE_AMD_MODULE_LOG
+int _status_log_save(const char *tag, const char *message);
+int _status_log_write(void);
+#endif
//TODO : remove
COOLDOWN_LIMIT,
};
+typedef struct _shared_info_t {
+ char *owner_exec_label;
+ char **paths;
+} shared_info_t;
+
+#endif
+
<smack request="aul::launch" type="x"/>
<smack request="aul::terminate" type="x"/>
<smack request="security-server::api-privilege-by-pid" type="w"/>
+ <smack request="security-server::api-permissions" type="w"/>
+ <smack request="device::app_logging" type="w"/>
+ <smack request="device::sys_logging" type="w"/>
+ <smack request="tizen::vconf::platform::rw" type="rw"/>
+ <smack request="dbus" type="rwxa"/>
+ <smack request="xorg" type="rwx"/>
</request>
<provide>
<label name="aul::db"/>
<label name="aul::launch"/>
<label name="aul::terminate"/>
+ <label name="aul::jump"/>
+ <label name="aul::appgroup_info"/>
</provide>
+ <permit>
+ <smack permit="dbus" type="rwxa"/>
+ <smack permit="xorg" type="rwx"/>
+ </permit>
</define>
<assign>
<filesystem path="/usr/lib/libaul.so.0" label="_"/>
<filesystem path="/usr/lib/libaul.so.0.1.0" label="_"/>
+ <filesystem path="/usr/share/appsvc" label="_"/>
+ <filesystem path="/usr/share/appsvc/alias.ini" label="_"/>
+ <filesystem path="/usr/share/dbus-1/system-services/org.tizen.aul.delegator.service" label="_"/>
</assign>
<request>
<domain name="aul"/>
Name: libaul
Description: new application utility library
Version: @VERSION@
-Requires: sqlite3 bundle ail glib-2.0 xdgmime
+Requires: sqlite3 bundle pkgmgr-info glib-2.0 xdgmime
Libs: -L${libdir} -laul
Cflags: -I${includedir}
--- /dev/null
+#!/bin/sh
+
+AMD_DUMP=$1/amd
+
+mkdir -p $AMD_DUMP
+
+mv -f /var/log/amd.log $AMD_DUMP
--- /dev/null
+PRAGMA journal_mode = PERSIST;
+
+CREATE TABLE IF NOT EXISTS appsvc (
+ operation TEXT,
+ mime_type TEXT DEFAULT 'NULL',
+ uri TEXT DEFAULT 'NULL',
+ pkg_name TEXT,
+ PRIMARY KEY (operation,mime_type,uri)
+);
+
+
--- /dev/null
+
+cmake_minimum_required(VERSION 2.6)
+#set(CMAKE_SKIP_BUILD_RPATH true)
+set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
+
+### Get required CFLAGS, LDFLAGS from pkg-config
+include(FindPkgConfig)
+pkg_check_modules(delegator_pkgs REQUIRED dbus-1 glib-2.0 dbus-glib-1 gio-2.0 gio-unix-2.0 dlog vasum security-server)
+
+foreach(flag ${delegator_pkgs_CFLAGS})
+ set(delegator_pkgs_CFLAGS_str "${delegator_pkgs_CFLAGS_str} ${flag}")
+endforeach()
+
+### Set current binary dir to be included (for generated *.h files)
+include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
+
+#GDBUS specific code
+add_custom_command(OUTPUT delegator_client_gdbus_generated.c delegator_client_gdbus_generated.h
+ COMMAND gdbus-codegen --generate-c-code delegator_client_gdbus_generated
+ --interface-prefix delegator ${CMAKE_CURRENT_SOURCE_DIR}/delegator.xml
+ )
+
+### Build modules
+add_executable(aul-delegator-server
+ delegator_client_gdbus_generated.c
+ delegator_server.c
+ )
+set_target_properties(aul-delegator-server PROPERTIES COMPILE_FLAGS "${delegator_pkgs_CFLAGS_str} -fPIE")
+target_link_libraries(aul-delegator-server bundle aul ${delegator_pkgs_LDFLAGS} "-pie")
+add_dependencies(aul-delegator-server delegator_client_gdbus_generated.h)
+add_dependencies(aul-delegator-server delegator_client_gdbus_generated.c)
+
+add_library(aul-delegator-client STATIC
+ delegator_client_gdbus_generated.c
+ delegator_client.c
+ )
+set_target_properties(aul-delegator-client PROPERTIES COMPILE_FLAGS "${delegator_pkgs_CFLAGS_str} ${CFLAGS} -fPIC")
+target_link_libraries(aul-delegator-client bundle ${delegator_pkgs_LDFLAGS})
+add_dependencies(aul-delegator-client delegator_client_gdbus_generated.h)
+add_dependencies(aul-delegator-client delegator_client_gdbus_generated.c)
+
+### Create pc file
+configure_file(org.tizen.aul.delegator.service.in org.tizen.aul.delegator.service @ONLY)
+
+## Install
+INSTALL(TARGETS aul-delegator-client DESTINATION lib COMPONENT RuntimeLibraries)
+INSTALL(TARGETS aul-delegator-server DESTINATION bin)
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.tizen.aul.delegator.service DESTINATION ${PREFIX}/share/dbus-1/system-services/)
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/aul-delegator-server.service DESTINATION ${PREFIX}/lib/systemd/system/)
+
+
+
--- /dev/null
+[Unit]
+Description=Delegator
+
+[Service]
+BusName=org.tizen.aul.delegator
+ExecStart=/usr/bin/aul-delegator-server
+
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+
+<node name="/org/tizen/aul/delegator">
+ <interface name="org.tizen.aul.delegator">
+ <method name="Launch">
+ <arg type="s" name="container" direction="in" />
+ <arg type="s" name="bundle" direction="in" />
+ <arg type="i" name="ret" direction="out" />
+ </method>
+ </interface>
+</node>
--- /dev/null
+#define _GNU_SOURCE
+#include <string.h>
+#include <bundle.h>
+#include <bundle_internal.h>
+#include <pkgmgr-info.h>
+#include "aul.h"
+#include "aul_svc.h"
+#include "delegator_config.h"
+#include "delegator_client_gdbus_generated.h"
+#include "delegator_client.h"
+#include "aul_svc_priv_key.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "DELEGATOR_CLIENT"
+
+int delegator_client_launch(const char *zone, bundle* kb)
+{
+ GError *error = NULL;
+ int ret = 0;
+ GDBusConnection *conn;
+ OrgTizenAulDelegator *proxy;
+
+ if (zone == NULL)
+ return AUL_SVC_RET_EINVAL;
+
+ conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+ if (error) {
+ SECURE_LOGE("gdbus connection error (%s)", error->message);
+ g_error_free(error);
+ }
+ if (conn == NULL) {
+ SECURE_LOGE(
+ "gdbus connection is not set, even gdbus error isn't raised");
+ return AUL_SVC_RET_ERROR;
+ }
+
+ proxy = org_tizen_aul_delegator_proxy_new_sync(conn,
+ G_DBUS_PROXY_FLAGS_NONE, DELEGATOR_INTERFACE,
+ DELEGATOR_NODE,
+ NULL, &error);
+ if (proxy == NULL) {
+ SECURE_LOGE("Unable to create proxy[err=%s]\n", error->message);
+ g_error_free(error);
+ g_object_unref(conn);
+ return AUL_SVC_RET_ERROR;
+ }
+
+ bundle_raw* br = NULL;
+ int len;
+
+ if (kb != NULL) {
+ bundle_encode(kb, &br, &len);
+ }
+ org_tizen_aul_delegator_call_launch_sync(proxy, zone,
+ (const gchar *) br, &ret,
+ NULL, &error);
+
+ if (br != NULL)
+ free(br);
+ g_dbus_connection_flush_sync(conn, NULL, NULL);
+ g_object_unref(conn);
+
+ return ret;
+}
+
+int delegator_client_can_jump(char **zone, bundle *kb)
+{
+ if (kb != NULL) {
+ char *val = NULL;
+
+ bundle_get_str(kb, AUL_SVC_K_OPERATION, &val);
+ if (val != NULL && strcmp(AUL_SVC_OPERATION_JUMP, val) == 0) {
+ char *op = NULL;
+ char *domain = NULL;
+
+ bundle_del(kb, AUL_SVC_K_OPERATION);
+ bundle_get_str(kb, AUL_SVC_K_JUMP_ORIGIN_OPERATION, &op);
+ bundle_get_str(kb, AUL_SVC_K_JUMP_ZONE_NAME, &domain);
+
+ if (domain != NULL) {
+ if (op != NULL) {
+ bundle_add_str(kb, AUL_SVC_K_OPERATION, op);
+ }
+
+ *zone = strdup(domain);
+ bundle_del(kb, AUL_SVC_K_JUMP_ZONE_NAME);
+ bundle_del(kb, AUL_SVC_K_JUMP_ORIGIN_OPERATION);
+ return AUL_SVC_RET_OK;
+ }
+ }
+ }
+
+ return AUL_SVC_RET_EREJECTED;
+}
+
+
+
--- /dev/null
+#ifndef __DELEGATOR_CLIENT_H__
+#define __DELEGATOR_CLIENT_H__
+
+#include <bundle.h>
+
+int delegator_client_launch(const char *zone, bundle *kb);
+int delegator_client_can_jump(char **zone, bundle *kb);
+
+#endif /* __DELEGATOR_CLIENT_H__ */
+
--- /dev/null
+#ifndef __DELEGATOR_CONFIG_H__
+#define __DELEGATOR_CONFIG_H__
+
+#define USE_DLOG 1 /* Use dlog! */
+
+#include <dlog.h>
+#include <dbus/dbus-glib.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#define DELEGATOR_INTERFACE "org.tizen.aul.delegator"
+#define DELEGATOR_NODE "/org/tizen/aul/delegator"
+
+#endif
+
--- /dev/null
+#define _GNU_SOURCE
+#include <bundle.h>
+#include <string.h>
+#include <security-server.h>
+#include "aul.h"
+#include "aul_svc.h"
+#include "aul_zone.h"
+#include "delegator_config.h"
+#include "delegator_client_gdbus_generated.h"
+#include "vasum.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "DELEGATOR_SERVER"
+
+GMainLoop *gMainLoop;
+GDBusConnection *context_connection = NULL;
+static int result = -1;
+
+static int __get_caller_pid(const char *name)
+{
+ guint pid = -1;
+ GVariant *ret;
+ GError *error = NULL;
+
+ ret = g_dbus_connection_call_sync (context_connection,
+ "org.freedesktop.DBus",
+ "/org/freedesktop/DBus",
+ "org.freedesktop.DBus",
+ "GetConnectionUnixProcessID",
+ g_variant_new ("(s)", name),
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+ g_variant_get (ret, "(u)", &pid);
+ g_variant_unref (ret);
+
+ return pid;
+}
+
+static gboolean on_handle_launch(OrgTizenAulDelegator *object,
+ GDBusMethodInvocation *invocation, const gchar *arg_container,
+ const gchar *arg_bundle)
+{
+ SECURE_LOGD("delegator server on_handle_launch(%s)", arg_container);
+
+ vsm_context_h ctx;
+ vsm_zone_h dom;
+
+ int pid;
+ int ret;
+ const char *name = g_dbus_method_invocation_get_sender(invocation);
+
+ pid = __get_caller_pid(name);
+
+ ret = security_server_check_privilege_by_pid(pid, "aul::jump", "x");
+ if (ret == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
+ SECURE_LOGE("delegator launch request has been denied by smack");
+ org_tizen_aul_delegator_complete_launch(object, invocation,
+ AUL_SVC_RET_EREJECTED);
+ return TRUE;
+ }
+
+ ctx = vsm_create_context();
+
+ if (ctx) {
+ dom = vsm_lookup_zone_by_name(ctx, arg_container);
+ if (dom) {
+ char *focus = NULL;
+ bundle *b = bundle_decode((const bundle_raw *)arg_bundle, strlen(arg_bundle));
+ bundle_get_str(b, AUL_SVC_K_FOCUS_ZONE, &focus);
+ if (focus == NULL || strcmp(focus, "true") == 0)
+ vsm_set_foreground(dom);
+ SECURE_LOGD("delegator server domain was changed");
+
+ char *old_zone = NULL;
+
+ aul_set_zone(arg_container, &old_zone);
+ result = aul_svc_run_service(b, 0, NULL, NULL);
+ bundle_free(b);
+ if (old_zone)
+ free(old_zone);
+ SECURE_LOGD("delegator launch result = %d", result);
+ org_tizen_aul_delegator_complete_launch(object, invocation, result);
+ vsm_cleanup_context(ctx);
+ return TRUE;
+
+ }
+ org_tizen_aul_delegator_complete_launch(object, invocation,
+ AUL_SVC_RET_EINVAL);
+ vsm_cleanup_context(ctx);
+ }
+
+ return TRUE;
+}
+
+static void on_name_acquired(GDBusConnection *connection, const gchar *name,
+ gpointer user_data)
+{
+ SECURE_LOGD("delegator server on_name_acquired ++");
+
+ OrgTizenAulDelegator *skeleton;
+
+ skeleton = org_tizen_aul_delegator_skeleton_new();
+ g_signal_connect(skeleton, "handle-launch", G_CALLBACK(on_handle_launch),
+ NULL);
+ g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(skeleton),
+ connection,
+ DELEGATOR_NODE, NULL);
+ context_connection = connection;
+ SECURE_LOGD("delegator server on_name_acquired -- ");
+}
+
+int main(int argc, char *argv[])
+{
+ gMainLoop = g_main_loop_new(NULL, FALSE);
+ if (!gMainLoop) {
+ SECURE_LOGE("delegator server g_main_loop_new failed\n");
+ return -1;
+ }
+
+ guint id = g_bus_own_name(G_BUS_TYPE_SYSTEM, DELEGATOR_INTERFACE,
+ G_BUS_NAME_OWNER_FLAGS_NONE, NULL, on_name_acquired, NULL, NULL,
+ NULL);
+
+ SECURE_LOGD("delegator server Main loop is created.");
+ g_main_loop_run(gMainLoop);
+ g_bus_unown_name(id);
+ g_main_loop_unref(gMainLoop);
+
+ return 0;
+}
+
--- /dev/null
+[D-BUS Service]
+Name=org.tizen.aul.delegator
+Exec=/bin/false
+SystemdService=aul-delegator-server.service
+User=root
+
return;
}
- handle = dlopen(sopath, RTLD_NOW);
+ handle = dlopen(sopath, RTLD_GLOBAL | RTLD_LAZY);
if (handle == NULL) {
free(type_t);
continue;
GSList *iter = NULL;
preexec_list_t *type_t;
- if (!preexec_initialized)
+ if (!preexec_initialized || !pkg_type)
return;
for (iter = preexec_list; iter != NULL; iter = g_slist_next(iter)) {
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _APP_LAUNCHPAD_TYPES_H_
+#define _APP_LAUNCHPAD_TYPES_H_
+
+enum launchpad_type_e {
+ NO_LAUNCHPAD_PID = -1,
+ AUL_UTIL_PID = -2,
+ WEB_LAUNCHPAD_PID = -3,
+#ifdef _APPFW_FEATURE_DEBUG_LAUNCHPAD
+ DEBUG_LAUNCHPAD_PID = -4,
+#endif
+#ifdef _APPFW_FEATURE_PROCESS_POOL
+ PROCESS_POOL_LAUNCHPAD_PID = -5,
+#endif
+};
+
+#endif
+
#define AUL_DBUS_APPLAUNCH_SIGNAL "app_launch"
#define AUL_DBUS_HOMELAUNCH_SIGNAL "home_launch"
+#define AUL_APP_STATUS_DBUS_PATH "/Org/Tizen/Aul/AppStatus"
+#define AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE "org.tizen.aul.AppStatus"
+#define STATUS_FOREGROUND "fg"
+#define STATUS_BACKGROUND "bg"
+
+#define AUL_APP_STATUS_DBUS_LAUNCH_REQUEST "AppLaunch"
+#define AUL_APP_STATUS_DBUS_RESUME_REQUEST "AppResume"
+#define AUL_APP_STATUS_DBUS_TERMINATE_REQUEST "AppTerminate"
+#define AUL_APP_STATUS_DBUS_STATUS_CHANGE "AppStatusChange"
+#define AUL_APP_STATUS_DBUS_GROUP "AppGroup"
+#define AUL_APP_STATUS_DBUS_TERMINATED "AppTerminated"
+
#ifdef _APPFW_FEATURE_CPU_BOOST
#define SYSTEM_BUS_NAME "org.tizen.system.deviced"
#define SYSTEM_OBJECT_PATH "/Org/Tizen/System/DeviceD/PmQos"
#define RESOURCED_PROC_INTERFACE "org.tizen.resourced.process"
#define RESOURCED_PROC_METHOD "ProcExclude"
+#define APPFW_SUSPEND_HINT_PATH "/Org/Tizen/Appfw/SuspendHint"
+#define APPFW_SUSPEND_HINT_INTERFACE "org.tizen.appfw.SuspendHint"
+#define APPFW_SUSPEND_HINT_SIGNAL "SuspendHint"
+
+#define RESOURCED_FREEZER_PATH "/Org/Tizen/Resourced/Freezer"
+#define RESOURCED_FREEZER_INTERFACE "org.tizen.resourced.freezer"
+#define RESOURCED_FREEZER_SIGNAL "FreezerState"
+
+#define RESOURCED_ALLOWED_BG_ATTRIBUTE 0x100
+#define RESOURCED_BACKGROUND_MANAGEMENT_ATTRIBUTE 0x200
+#define RESOURCED_API_VER_2_4_ATTRIBUTE 0x400
+
+#define RESOURCED_PROC_PRELAUNCH_SIGNAL "ProcPrelaunch"
#define RESOURCED_PROC_WATCHDOG_SIGNAL "ProcWatchdog"
+#define RESOURCED_PROC_GROUP_SIGNAL "ProcGroup"
#define PROC_TYPE_EXCLUDE "exclude"
#define PROC_TYPE_INCLUDE "include"
#define PROC_TYPE_WAKEUP "wakeup"
-#ifdef _APPFW_FEATURE_VISIBILITY_CHECK_BY_LCD_STATUS
-#define DEVICED_PATH_DISPLAY "/Org/Tizen/System/DeviceD/Display"
-#define DEVICED_INTERFACE_DISPLAY "org.tizen.system.deviced.display"
-
-#define DEVICED_SIGNAL_LCD_ON "LCDOn"
-#define DEVICED_SIGNAL_LCD_OFF "LCDOff"
+#ifdef _APPFW_FEATURE_EXPANSION_PKG_INSTALL
+#define TEP_BUS_NAME "org.tizen.system.deviced"
+#define TEP_OBJECT_PATH "/Org/Tizen/System/DeviceD/Tzip"
+#define TEP_INTERFACE_NAME "org.tizen.system.deviced.Tzip"
+#define TEP_MOUNT_METHOD "Mount"
+#define TEP_UNMOUNT_METHOD "Unmount"
+#define TEP_IS_MOUNTED_METHOD "IsMounted"
#endif
+
#endif
#ifndef __APP_PKT_H_
#define __APP_PKT_H_
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
#include <unistd.h>
-#define __USE_GNU
#include <sys/socket.h>
#include <linux/un.h>
+#include "aul_zone.h"
+
+#include "app_launchpad_types.h"
enum app_cmd {
APP_START,
APP_KEY_RESERVE,
APP_KEY_RELEASE,
APP_STATUS_UPDATE,
- APP_RELEASED,
APP_RUNNING_LIST_UPDATE,
APP_TERM_REQ_BY_PID,
APP_START_ASYNC,
#ifdef _APPFW_FEATURE_MULTI_INSTANCE
APP_START_MULTI_INSTANCE,
#endif
-#ifdef _APPFW_FEATURE_VISIBILITY_CHECK_BY_LCD_STATUS
- APP_PAUSE_LCD_OFF,
- APP_RESUME_LCD_ON,
-#endif
+ APP_GROUP_GET_WINDOW,
+ APP_GROUP_GET_LEADER_PIDS,
+ APP_GROUP_GET_GROUP_PIDS,
+ APP_GROUP_CLEAR_TOP,
+ APP_GROUP_GET_LEADER_PID,
+ APP_GROUP_GET_FG,
+ APP_GROUP_SET_WINDOW,
+ APP_GROUP_LOWER,
+ APP_GROUP_GET_IDLE_PIDS,
APP_GET_CMDLINE,
+ APP_TERM_BGAPP_BY_PID,
+ APP_PAUSE,
+ APP_PAUSE_BY_PID,
+ APP_GET_PID,
+ APP_GET_PID_CACHE,
+ APP_GET_STATUS,
+ APP_SET_PROCESS_GROUP,
+ APP_GET_GROUP_INFO,
+ APP_SUSPEND,
+ APP_WAKE,
+ APP_GET_LAST_CALLER_PID,
};
-#define AUL_SOCK_PREFIX "/tmp/alaunch"
-#define AUL_SOCK_MAXBUFF 65535
-#define LAUNCHPAD_PID -1
-#define WEB_LAUNCHPAD_PID -3
-#ifdef _APPFW_FEATURE_DEBUG_LAUNCHPAD
-#define DEBUG_LAUNCHPAD_PID -4
-#endif
-#ifdef _APPFW_FEATURE_PROCESS_POOL
-#define PROCESS_POOL_LAUNCHPAD_PID -5
-#endif
-#ifdef _APPFW_FEATURE_NATIVE_LAUNCHPAD
-#define NATIVE_LAUNCHPAD_PID -6
-#endif
+#define AUL_SOCK_PREFIX _get_sock_prefix()
+#define AUL_SOCK_MAXBUFF 131071
#define ELOCALLAUNCH_ID 128
#define EILLEGALACCESS 127
#define ETERMINATING 126
#define EUGLOCAL_LAUNCH 124
#endif
#define EREJECTED 123
+#define ENOAPP 122
+
typedef struct _app_pkt_t {
app_pkt_t *__app_recv_raw(int fd, int *clifd, struct ucred *cr);
app_pkt_t *__app_send_cmd_with_result(int pid, int cmd, unsigned char *kb_data, int datalen);
-
#endif
STATUS_BG,
STATUS_DYING,
STATUS_HOME,
- STATUS_NORESTART
+ STATUS_NORESTART,
+ STATUS_SERVICE
};
/** @} */
AUL_START,
AUL_RESUME,
AUL_TERMINATE,
-#ifdef _APPFW_FEATURE_VISIBILITY_CHECK_BY_LCD_STATUS
- AUL_PAUSE_LCD_OFF,
- AUL_RESUME_LCD_ON,
-#endif
+ AUL_TERMINATE_BGAPP,
+ AUL_PAUSE,
+ AUL_SUSPEND,
+ AUL_WAKE,
}aul_type;
/** AUL internal private key */
/** AUL internal private key */
#define AUL_K_PID "__AUL_PID__"
/** AUL internal private key */
+#define AUL_K_WID "__AUL_WID__"
+/** AUL internal private key */
+#define AUL_K_LEADER_PID "__AUL_LEADER_PID__"
+
+/** AUL internal private key */
#define AUL_K_PRELAUCHING "__AUL_PRELAUCHING__"
-#ifdef _APPFW_FEATURE_CONTACT_PHONE_AS_ONE_APP
-/** AUL internal private key - To distinguish between Contacts and Phone */
-#define AUL_K_INTERNAL_APPID "__AUL_INTERNAL_APPID__"
-#endif
+/** AUL internal private key */
+#define AUL_K_OWNER_PID "__AUL_OWNER_PID__"
+/** AUL internal private key */
+#define AUL_K_CHILD_PID "__AUL_CHILD_PID__"
#ifdef _APPFW_FEATURE_PROCESS_POOL
-#define AUL_K_LAUNCHPAD_TYPE "__AUL_LAUNCHPAD_TYPE__"
+#define AUL_K_INTERNAL_POOL "__AUL_INTERNAL_POOL__"
#endif
#ifdef _APPFW_FEATURE_DATA_CONTROL
#define AUL_K_DATA_CONTROL_TYPE "__AUL_DATA_CONTROL_TYPE__"
#endif
+/** AUL internal private key */
+#define AUL_K_HOST_PID "__AUL_HOST_PID__"
+
+/** Internal operation for launching application which is other zone */
+#define AUL_SVC_OPERATION_JUMP "http://tizen.org/appcontrol/operation/jump"
+#define AUL_SVC_K_JUMP_ZONE_NAME "__K_JUMP_DOMAIN_NAME__"
+#define AUL_SVC_K_JUMP_ORIGIN_OPERATION "__K_JUMP_ORIGIN_OPERATION__"
+#define AUL_SVC_K_FOCUS_ZONE "__K_FOCUS_ZONE__"
+#define AUL_SVC_K_RUA_STAT_CALLER "__K_RUA_STAT_CALLER__"
+#define AUL_SVC_K_RUA_STAT_TAG "__K_RUA_STAT_TAG__"
+
+
+#define AUL_K_ALLOWED_BG "__AUL_INTERNAL_ALLOWED_BG__"
+
+#ifdef _APPFW_FEATURE_EXPANSION_PKG_INSTALL
+#define AUL_TEP_PATH "_AUL_TEP_PATH_"
+int aul_check_tep_mount(const char *tep_path);
+int aul_is_tep_mount_dbus_done(const char *tep_string);
+#endif
+
+
+/** AUL internal private key */
+#define AUL_K_PKGID "__AUL_PKGID_"
+
+
/**
* @brief This is callback function for aul_launch_init
* @param[in] type event's type received from system
* If you have not the permission, this API return AUL_R_ERROR. \n
*/
int aul_terminate_pid(int pid);
+int aul_terminate_bgapp_pid(int pid);
int aul_terminate_pid_without_restart(int pid);
int aul_terminate_pid_async(int pid);
const char *aul_get_app_data_path(void);
const char *aul_get_app_cache_path(void);
const char *aul_get_app_resource_path(void);
+const char *aul_get_app_tep_resource_path(void);
const char *aul_get_app_shared_data_path(void);
const char *aul_get_app_shared_resource_path(void);
const char *aul_get_app_shared_trusted_path(void);
int aul_is_subapp(void);
int aul_add_caller_cb(int pid, void (*caller_cb) (int, void *), void *data);
int aul_remove_caller_cb(int pid);
+int aul_invoke_caller_cb(int pid);
#ifdef _APPFW_FEATURE_PROCESS_POOL
void aul_set_preinit_window(void *evas_object);
void aul_set_preinit_appid(const char *appid);
+void aul_set_preinit_pkgid(const char *pkgid);
+const char* aul_get_preinit_pkgid(void);
+
int aul_launch_app_async(const char *appid, bundle *kb);
#ifdef _APPFW_FEATURE_MULTI_INSTANCE
int aul_update_freezer_status(int pid, const char* type);
+int aul_send_app_launch_request_signal(int pid, const char* appid, const char* pkgid, const char* type);
+int aul_send_app_resume_request_signal(int pid, const char* appid, const char* pkgid, const char *type);
+int aul_send_app_terminate_request_signal(int pid, const char* appid, const char* pkgid, const char *type);
+int aul_send_app_status_change_signal(int pid, const char* appid, const char* pkgid, const char* status, const char *type);
+int aul_send_app_terminated_signal(int pid);
+int aul_send_app_group_signal(int owner_pid, int child_pid, const char *child_pkgid);
+
int aul_status_update(int status);
+/**
+ * @par Description:
+ * This API gets status of specified application process id.
+ * @par Purpose:
+ * This API's purpose is to get the application's status.
+ *
+ * @param[in] pid pid of application
+ * @return 0 or greater if success, nagative value if fail
+ * @retval STATUS_LAUNCHING
+ * @retval STATUS_CREATED
+ * @retval STATUS_FOCUS
+ * @retval STATUS_VISIBLE
+ * @retval STATUS_BG
+ * @retval STATUS_DYING
+ * @retval STATUS_HOME
+ * @retval STATUS_NORESTART
+ * @see
+ * aul_status_update
+ * @pre
+ * None
+ * @post
+ * None
+ * @code
+ * #include <aul.h>
+ *
+ * int iterfunc(const aul_app_info *info, void *data)
+ * {
+ * int status;
+ * status = aul_app_get_status_bypid(info->pid);
+ * if (status == STATUS_FOCUS) {
+ * printf("%s has focus", info->app_id);
+ * (int *)data = info->pid;
+ * return -1;
+ * }
+ * return 0;
+ * }
+ *
+ * int find_focus_app_pid()
+ * {
+ * int pid = 0;
+ * aul_app_get_running_app_info(iterfunc, &pid);
+ * return pid;
+ * }
+ * @endcode
+ * @remark
+ * None
+ */
+int aul_app_get_status_bypid(int pid);
+
+/**
+ * @par Description
+ * This API sets callback function that on application status changed.
+ * @par Purpose:
+ * This API's purpose is to listen the application's status changed within
+ * the caller process. In general, a library that required to release resource on
+ * application's status may use this API.
+ *
+ * @param[in] func callback function
+ * @param[in] data user data
+ * @return 0 if success, negative value if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_ERROR - general error
+ * @see
+ * aul_remove_status_local_cb
+ * @pre
+ * None
+ * @post
+ * None
+ * @code
+ * #include <aul.h>
+ *
+ * int status_changed(int status, void *data)
+ * {
+ * if (status == STATUS_FOCUS)
+ * printf("%d has focus\n", getpid());
+ *
+ * if (status == STATUS_VISIBLE)
+ * printf("%d resume\n", getpid());
+ *
+ * if (status == STATUS_BG0
+ * printf("%d pause\n", getpid());
+ * }
+ *
+ * void listen_app_status()
+ * {
+ * aul_add_status_local_cb(status_changed, NULL);
+ * }
+ * @endcode
+ * @remark
+ * None
+ *
+ */
+int aul_add_status_local_cb(int (*func) (int, void *), void *data);
+
+/**
+ * @par Description
+ * This API unsets callback function that on application status changed.
+ * @par Purpose:
+ * This API's purpose is to remove callback that added by
+ * aul_add_status_local_cb.
+ *
+ * @param[in] func callback function
+ * @param[in] data user data
+ * @return 0 if success, negative value if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_ERROR - general error
+ *
+ * @pre
+ * None
+ * @post
+ * None
+ * @see
+ * aul_add_status_local_cb
+ * @code
+ * #include <aul.h>
+ *
+ * int status_changed(int status, void *data)
+ * {
+ * if (status == STATUS_FOCUS)
+ * printf("%d has focus\n", getpid());
+ *
+ * if (status == STATUS_VISIBLE)
+ * printf("%d resume\n", getpid());
+ *
+ * if (status == STATUS_BG0
+ * printf("%d pause\n", getpid());
+ * }
+ *
+ * void listen_app_status()
+ * {
+ * aul_add_status_local_cb(status_changed, NULL);
+ * }
+ *
+ * void ignore_app_status()
+ * {
+ * aul_remove_status_local_cb(status_changed, NULL);
+ * }
+ *
+ * @endcode
+ * @remark
+ * None
+ *
+ */
+int aul_remove_status_local_cb(int (*func) (int, void *), void *data);
+
+int aul_invoke_status_local_cb(int status);
+
+int aul_running_list_update(char *appid, char *app_path, char *pid);
+
int aul_get_app_allocated_memory(void);
long long aul_get_app_running_time(void);
char *aul_get_cmdline_bypid(int pid);
+int aul_app_group_get_window(int pid);
+int aul_app_group_set_window(int wid);
+void aul_app_group_get_leader_pids(int *cnt, int **pids);
+void aul_app_group_get_group_pids(int leader_pid, int *cnt, int **pids);
+int aul_app_group_get_leader_pid(int pid);
+int aul_app_group_clear_top(void);
+int aul_app_group_is_top(void);
+int aul_app_group_get_fg_flag(int pid);
+void aul_app_group_lower(int *exit);
+void aul_app_group_get_idle_pids(int *cnt, int **pids);
+
+char *aul_get_group_info(void);
+
+int aul_pause_app(const char *appid);
+int aul_pause_pid(int pid);
+int aul_app_get_pid(const char *appid);
+int aul_app_get_pid_cache(const char *appid);
+
+int aul_app_get_last_caller_pid(int pid);
+
+int aul_set_process_group(int parent_pid, int child_pid);
/** @} */
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __AUL_RESOURCE_MANAGER_H__
+#define __AUL_RESOURCE_MANAGER_H__
+
+#include <tizen.h>
+#include <bundle.h>
+#include <glib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Enumeration for Resource Types
+ * @since_tizen 2.4
+ */
+typedef enum {
+ AUL_RESOURCE_TYPE_IMAGE = 0, /**<Image*/
+ AUL_RESOURCE_TYPE_LAYOUT, /**<Edje*/
+ AUL_RESOURCE_TYPE_SOUND, /**<Sound*/
+ AUL_RESOURCE_TYPE_BIN, /**<Bin*/
+ AUL_RESOURCE_TYPE_MIN = AUL_RESOURCE_TYPE_IMAGE,
+ AUL_RESOURCE_TYPE_MAX = AUL_RESOURCE_TYPE_BIN,
+/*add values between AUL_RESOURCE_TYPE_MIN and AUL_RESOURCE_TYPE_MAX*/
+} aul_resource_e;
+
+/**
+ * @brief Enumeration for Aul Resource Manager Error.
+ * @since_tizen 2.4
+ */
+typedef enum {
+ AUL_RESOURCE_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
+ AUL_RESOURCE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
+ AUL_RESOURCE_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
+ AUL_RESOURCE_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */
+} aul_resource_error_e;
+
+/**
+ * @brief Creates resource manager and get from db.
+ *
+ * @since_tizen 2.4
+ * @remarks If resource manager is already exist,
+ * It will just return APP_RESOURCE_ERROR_NONE
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_RESOURCE_ERROR_NONE Successful
+ * @retval #AUL_RESOURCE_ERROR_IO_ERROR IO Internal I/O Error
+ * @retval #AUL_RESOURCE_ERROR_OUT_OF_MEMORY Out of memeory
+ * @see aul_resource_manager_release()
+ */
+int aul_resource_manager_init(void);
+
+/**
+ * @brief Creates resource manager and make valid filelist from given attributes.
+ *
+ * @since_tizen 2.4
+ * @remarks If resource manager is already exist,
+ * It will just return APP_RESOURCE_ERROR_NONE
+ * This function should called from resource slice tool only.
+ * @param[in] rsc_folder_path path of resource.
+ * @param[in] b bundle which contain attributes about target device.
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_RESOURCE_ERROR_NONE Successful
+ * @retval #AUL_RESOURCE_ERROR_IO_ERROR IO Internal I/O Error
+ * @retval #AUL_RESOURCE_ERROR_OUT_OF_MEMORY Out of memeory
+ * @see aul_resource_manager_release()
+ */
+int aul_resource_manager_init_slice(const char *rsc_folder_path, bundle *b);
+
+/**
+ * @brief Convert resource ID to path name
+ *
+ * @since_tizen 2.4
+ * @remarks If resource manager is not created yet,
+ * aul_resource_manager_init() will be invoked automatically.
+ * Caller should free the returned pointer.
+ * @param[in] type Resource type @see aul_resource_e
+ * @param[in] id Resource ID
+ * @param[out] path The name of requested resource on success, otherwise NULL
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_RESOURCE_ERROR_NONE Successful
+ * @retval #AUL_RESOURCE_ERROR_INVALID_PARAMETER Invalid Parameter
+ * @retval #AUL_RESOURCE_ERROR_IO_ERROR Internal I/O Error
+ * @see aul_resource_manager_init()
+ */
+int aul_resource_manager_get(aul_resource_e type, const char *id, char **path);
+
+/**
+ * @brief Destroys resource manager.
+ *
+ * @since_tizen 2.4
+ * @remarks Please make sure that the instance of resource manager should be released when the application is closing only.
+ * It is highly recommended way to improve run-time performance.
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_RESOURCE_ERROR_NONE Successful
+ * @see aul_resource_manager_init()
+ */
+int aul_resource_manager_release(void);
+
+/**
+ * @brief Get valid file path list.
+ *
+ * @since_tizen 2.4
+ * @remarks Please make sure that the instance of resource manager should be released when the application is closing only.
+ * It is highly recommended way to improve run-time performance.
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_RESOURCE_ERROR_NONE Successful
+ * @see aul_resource_manager_init()
+ */
+int aul_resource_manager_get_path_list(GHashTable **list);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __AUL_RESOURCE_MANAGER_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __AUL_SVC_H__
+#define __AUL_SVC_H__
+
+#include <bundle.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/** AUL_SVC OPERATION TYPE*/
+#define AUL_SVC_OPERATION_DEFAULT "http://tizen.org/appcontrol/operation/default"
+/** AUL_SVC OPERATION TYPE*/
+#define AUL_SVC_OPERATION_EDIT "http://tizen.org/appcontrol/operation/edit"
+/** AUL_SVC OPERATION TYPE*/
+#define AUL_SVC_OPERATION_VIEW "http://tizen.org/appcontrol/operation/view"
+/** AUL_SVC OPERATION TYPE*/
+#define AUL_SVC_OPERATION_PICK "http://tizen.org/appcontrol/operation/pick"
+/** AUL_SVC OPERATION TYPE*/
+#define AUL_SVC_OPERATION_CREATE_CONTENT "http://tizen.org/appcontrol/operation/create_content"
+/** AUL_SVC OPERATION TYPE*/
+#define AUL_SVC_OPERATION_CALL "http://tizen.org/appcontrol/operation/call"
+/** AUL_SVC OPERATION TYPE*/
+#define AUL_SVC_OPERATION_SEND "http://tizen.org/appcontrol/operation/send"
+/** AUL_SVC OPERATION TYPE*/
+#define AUL_SVC_OPERATION_SEND_TEXT "http://tizen.org/appcontrol/operation/send_text"
+/** AUL_SVC OPERATION TYPE*/
+#define AUL_SVC_OPERATION_DIAL "http://tizen.org/appcontrol/operation/dial"
+/** AUL_SVC OPERATION TYPE*/
+#define AUL_SVC_OPERATION_SEARCH "http://tizen.org/appcontrol/operation/search"
+/** AUL_SVC OPERATION TYPE*/
+#define AUL_SVC_OPERATION_DOWNLOAD "http://tizen.org/appcontrol/operation/download"
+/** AUL_SVC OPERATION TYPE*/
+#define AUL_SVC_OPERATION_SHARE "http://tizen.org/appcontrol/operation/share"
+/** AUL_SVC OPERATION TYPE*/
+#define AUL_SVC_OPERATION_MULTI_SHARE "http://tizen.org/appcontrol/operation/multi_share"
+/** AUL_SVC OPERATION TYPE*/
+#define AUL_SVC_OPERATION_SHARE_TEXT "http://tizen.org/appcontrol/operation/share_text"
+/** AUL_SVC_OPERATION_TYPE*/
+#define AUL_SVC_OPERATION_COMPOSE "http://tizen.org/appcontrol/operation/compose"
+/** AUL_SVC OPERATION TYPE*/
+#define AUL_SVC_OPERATION_LOCATION "http://tizen.org/appcontrol/operation/configure/location"
+/** AUL_SVC OPERATION TYPE*/
+#define AUL_SVC_OPERATION_FONT_TYPE "http://tizen.org/appcontrol/operation/configure/font/type"
+/** AUL_SVC OPERATION TYPE*/
+#define AUL_SVC_OPERATION_FONT_SIZE "http://tizen.org/appcontrol/operation/configure/font/size"
+#define AUL_SVC_OPERATION_LAUNCH_ON_EVENT "http://tizen.org/appcontrol/operation/launch_on_event"
+
+
+
+/** AUL_SVC DATA SUBJECT*/
+#define AUL_SVC_DATA_SUBJECT "http://tizen.org/appcontrol/data/subject"
+/** AUL_SVC DATA TYPE*/
+#define AUL_SVC_DATA_TO "http://tizen.org/appcontrol/data/to"
+/** AUL_SVC DATA TYPE*/
+#define AUL_SVC_DATA_CC "http://tizen.org/appcontrol/data/cc"
+/** AUL_SVC DATA TYPE*/
+#define AUL_SVC_DATA_BCC "http://tizen.org/appcontrol/data/bcc"
+/** AUL_SVC DATA TYPE*/
+#define AUL_SVC_DATA_TEXT "http://tizen.org/appcontrol/data/text"
+/** AUL_SVC DATA TYPE*/
+#define AUL_SVC_DATA_TITLE "http://tizen.org/appcontrol/data/title"
+/** AUL_SVC DATA TYPE*/
+#define AUL_SVC_DATA_SELECTED "http://tizen.org/appcontrol/data/selected"
+/** AUL_SVC DATA TYPE*/
+#define AUL_SVC_DATA_KEYWORD "http://tizen.org/appcontrol/data/keyword"
+/** AUL_SVC DATA TYPE*/
+#define AUL_SVC_DATA_PATH "http://tizen.org/appcontrol/data/path"
+/** AUL_SVC DATA TYPE*/
+#define AUL_SVC_DATA_SELECTION_MODE "http://tizen.org/appcontrol/data/selection_mode"
+/** AUL_SVC DATA TYPE*/
+#define AUL_SVC_DATA_RETURN_RESULT "http://tizen.org/appcontrol/data/return_result"
+
+
+/** AUL SVC internal private key */
+#define AUL_SVC_K_URI_R_INFO "__AUL_SVC_URI_R_INFO__"
+
+#define AUL_SVC_K_SELECTOR_EXTRA_LIST "http://tizen.org/appcontrol/data/selector_extra_list"
+
+#ifdef _APPFW_FEATURE_MULTI_INSTANCE
+#define AUL_SVC_K_MULTI_INSTANCE "multi_instance"
+#endif
+
+#define APP_SELECTOR "org.tizen.app-selector"
+#define SHARE_PANEL "org.tizen.share-panel"
+
+/** Internal operation for launching application which is other zone */
+#define AUL_SVC_OPERATION_JUMP "http://tizen.org/appcontrol/operation/jump"
+#define AUL_SVC_K_JUMP_ZONE_NAME "__K_JUMP_DOMAIN_NAME__"
+#define AUL_SVC_K_JUMP_ORIGIN_OPERATION "__K_JUMP_ORIGIN_OPERATION__"
+#define AUL_SVC_K_FOCUS_ZONE "__K_FOCUS_ZONE__"
+#define AUL_SVC_K_LAUNCH_RESULT_APP_STARTED "__K_LAUNCH_RESULT_APP_STARTED__"
+#define AUL_SVC_K_CAN_BE_LEADER "__K_CAN_BE_LEADER__"
+#define AUL_SVC_K_REROUTE "__K_REROUTE__"
+#define AUL_SVC_K_SHIFT_WINDOW "__K_SHIFT_WINDOW"
+#define AUL_SVC_K_RECYCLE "__K_RECYCLE"
+
+
+/**
+ * @brief Return values in appsvc.
+ */
+typedef enum _aul_svc_return_val {
+ AUL_SVC_RET_EREJECTED = -7, /**< application launch rejected */
+ AUL_SVC_RET_ETERMINATING = -6, /**< application terminating */
+ AUL_SVC_RET_EILLACC = -5, /**< Illegal Access */
+ AUL_SVC_RET_ELAUNCH = -4, /**< Failure on launching the app */
+ AUL_SVC_RET_ENOMATCH = -3, /**< No matching result Error */
+ AUL_SVC_RET_EINVAL = -2, /**< Invalid argument */
+ AUL_SVC_RET_ERROR = -1, /**< General error */
+ AUL_SVC_RET_OK = 0 /**< General success */
+} aul_svc_return_val;
+
+
+/**
+ * @brief result values in appsvc.
+ */
+typedef enum _aul_svc_result_val
+{
+ AUL_SVC_RES_CANCEL = -2, /**< Cancel by system */
+ AUL_SVC_RES_NOT_OK = -1, /**< Fail by user */
+ AUL_SVC_RES_OK = 0 /**< Success by user */
+} aul_svc_result_val;
+
+
+/**
+ * @brief aul_svc_res_fn is appsvc result function
+ * @param[out] b result bundle
+ * @param[out] request_code request code
+ * @param[out] result result value
+ * @param[out] data user-supplied data
+*/
+typedef void (*aul_svc_res_fn)(bundle *b, int request_code, aul_svc_result_val result, void *data);
+
+
+/**
+ * @brief iterator function running with aul_svc_get_list
+ * @param[out] appid appid retreived by aul_svc_get_list
+ * @param[out] data user-supplied data
+*/
+typedef int (*aul_svc_info_iter_fn)(const char *appid, void *data);
+
+typedef int (*aul_svc_host_res_fn)(void *data);
+
+/**
+ * @par Description:
+ * This function sets an operation to launch application based on appsvc.
+ *
+ * @param[in] b bundle object
+ * @param[in] operation operation
+ *
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_SVC_RET_OK - success
+ * @retval AUL_SVC_RET_ERROR - general error
+ * @retval AUL_SVC_RET_EINVAL - invalid argument(content)
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks An application must call this function before using aul_svc_run_service API.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ bundle *b = NULL;
+
+ b = bundle_create();
+
+ aul_svc_set_operation(b, AUL_SVC_OPERATION_VIEW);
+}
+ * @endcode
+ *
+ */
+int aul_svc_set_operation(bundle *b, const char *operation);
+
+/**
+ * @par Description:
+ * This function sets an uri to launch application based on appsvc.
+ *
+ * @param[in] b bundle object
+ * @param[in] uri uri
+ *
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_SVC_RET_OK - success
+ * @retval AUL_SVC_RET_ERROR - general error
+ * @retval AUL_SVC_RET_EINVAL - invalid argument(content)
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ bundle *b = NULL;
+
+ b = bundle_create();
+
+ aul_svc_set_operation(b, AUL_SVC_OPERATION_VIEW);
+ aul_svc_set_uri(b,"http://www.samsung.com");
+}
+ * @endcode
+ *
+ */
+int aul_svc_set_uri(bundle *b, const char *uri);
+
+/**
+ * @par Description:
+ * This function sets a mime-type to launch application based on appsvc.
+ *
+ * @param[in] b bundle object
+ * @param[in] mime mime-type
+ *
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_SVC_RET_OK - success
+ * @retval AUL_SVC_RET_ERROR - general error
+ * @retval AUL_SVC_RET_EINVAL - invalid argument(content)
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ bundle *b = NULL;
+
+ b = bundle_create();
+
+ aul_svc_set_operation(b, AUL_SVC_OPERATION_PICK);
+ aul_svc_set_mime(b,"image/jpg");
+}
+ * @endcode
+ *
+ */
+int aul_svc_set_mime(bundle *b, const char *mime);
+
+/**
+ * @par Description:
+ * This function sets an extra data to launch application based on appsvc.
+ *
+ * @param[in] b bundle object
+ * @param[in] key key of extra data
+ * @param[in] val data
+ *
+ * @return 0 if success, negative value(<0) if fail
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ bundle *b = NULL;
+
+ b = bundle_create();
+
+ aul_svc_set_operation(b, AUL_SVC_OPERATION_SEND);
+ aul_svc_set_uri(b,"mailto:xxx1@xxx");
+ aul_svc_add_data(b,AUL_SVC_DATA_CC,"xxx2@xxx");
+}
+ * @endcode
+ *
+ */
+int aul_svc_add_data(bundle *b, const char *key, const char *val);
+
+/**
+ * @par Description:
+ * This function sets an extra array data to launch application based on appsvc.
+ *
+ * @param[in] b bundle object
+ * @param[in] key key of extra data
+ * @param[in] val_array data
+ * @param[in] len Length of array
+ *
+ * @return 0 if success, negative value(<0) if fail
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ bundle *b = NULL;
+ char *images[] = {"/opt/media/a.jpg", "/opt/media/b.jpg", "/opt/media/c.jpg"};
+
+ b = bundle_create();
+
+ aul_svc_add_data_array(b, AUL_SVC_DATA_SELECTED, images, 3);
+}
+ * @endcode
+ *
+ */
+int aul_svc_add_data_array(bundle *b, const char *key, const char **val_array, int len);
+
+
+/**
+ * @par Description:
+ * This function sets a package name to launch application based on appsvc.
+ *
+ * @param[in] b bundle object
+ * @param[in] pkg_name package name for explict launch
+ *
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_SVC_RET_OK - success
+ * @retval AUL_SVC_RET_ERROR - general error
+ * @retval AUL_SVC_RET_EINVAL - invalid argument(content)
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ bundle *b = NULL;
+
+ b = bundle_create();
+
+ aul_svc_set_operation(b, AUL_SVC_OPERATION_PICK);
+ aul_svc_set_mime(b,"image/jpg");
+ aul_svc_set_pkgname(b, "org.tizen.mygallery");
+}
+ * @endcode
+ *
+ */
+/* Deprecated API */
+int aul_svc_set_pkgname(bundle *b, const char *pkg_name); // __attribute__((deprecated));
+
+
+/**
+ * @par Description:
+ * This function sets a appid to launch application based on appsvc.
+ *
+ * @param[in] b bundle object
+ * @param[in] appid application id for explict launch
+ *
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_SVC_RET_OK - success
+ * @retval AUL_SVC_RET_ERROR - general error
+ * @retval AUL_SVC_RET_EINVAL - invalid argument(content)
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ bundle *b = NULL;
+
+ b = bundle_create();
+
+ aul_svc_set_operation(b, AUL_SVC_OPERATION_PICK);
+ aul_svc_set_mime(b,"image/jpg");
+ aul_svc_set_appid(b, "org.tizen.mygallery");
+}
+ * @endcode
+ *
+ */
+int aul_svc_set_appid(bundle *b, const char *appid);
+
+
+/**
+ * @par Description:
+ * This function sets a appid to launch application based on appsvc.
+ *
+ * @param[in] b bundle object
+ * @param[in] application category
+ *
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_SVC_RET_OK - success
+ * @retval AUL_SVC_RET_ERROR - general error
+ * @retval AUL_SVC_RET_EINVAL - invalid argument(content)
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ bundle *b = NULL;
+
+ b = bundle_create();
+
+ aul_svc_set_operation(b, AUL_SVC_OPERATION_VIEW);
+ aul_svc_set_category(b, "http://tizen.org/category/app/browser");
+}
+ * @endcode
+ *
+ */
+int aul_svc_set_category(bundle *b, const char *category);
+
+/**
+ * @par Description:
+ * This API launch application based on appsvc.
+ *
+ * @param[in] b bundle to be passed to callee
+ * @param[in] request_code request code
+ * @param[in] cbfunc result callback function
+ * @param[in] data user-supplied data passed to callback function
+ *
+ * @return callee's pid if success, negative value(<0) if fail
+ * @retval callee's pid - success
+ * @retval AUL_SVC_RET_ERROR - general error
+ * @retval AUL_SVC_RET_EINVAL - invalid argument(content)
+ * @retval AUL_SVC_RET_ENOMATCH - no matching result Error
+ * @retval AUL_SVC_RET_ELAUNCH - failure on launching the app
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ bundle *b = NULL;
+ static int num = 0;
+
+ b = bundle_create();
+
+ aul_svc_set_operation(b, AUL_SVC_OPERATION_PICK);
+ aul_svc_set_mime(b,"image/jpg");
+
+ return aul_svc_run_service(b, 0, cb_func, (void*)NULL);
+}
+ * @endcode
+ *
+ */
+int aul_svc_run_service(bundle *b, int request_code, aul_svc_res_fn cbfunc, void *data);
+
+/**
+ * @par Description:
+ * This API use to get application list that is matched with given bundle.
+ *
+ * @param[in] b bundle to resolve application
+ * @param[in] iter_fn iterator function
+ * @param[in] data user-supplied data for iter_fn
+ *
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_SVC_RET_OK - success
+ * @retval AUL_SVC_RET_EINVAL - invalid argument(content)
+ * @retval AUL_SVC_RET_ENOMATCH - no matching result Error
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+static int iter_fn(const char* appid, void *data)
+{
+ printf("\t==========================\n");
+ printf("\t appid: %s\n", appid);
+ printf("\t==========================\n");
+ return 0;
+}
+
+...
+{
+ bundle *b = NULL;
+ static int num = 0;
+
+ b = bundle_create();
+
+ aul_svc_set_operation(b, AUL_SVC_OPERATION_PICK);
+ aul_svc_set_mime(b,"image/jpg");
+
+ return aul_svc_get_list(b, iter_fn, (void*)NULL);
+}
+ * @endcode
+ *
+ */
+int aul_svc_get_list(bundle *b, aul_svc_info_iter_fn iter_fn, void *data);
+
+/**
+ * @par Description:
+ * This API use to get default applications
+ *
+ * @param[in] iter_fn iterator function
+ * @param[in] data user-supplied data for iter_fn
+ *
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_SVC_RET_OK - success
+ * @retval AUL_SVC_RET_EINVAL - invalid argument(content)
+ * @retval AUL_SVC_RET_ENOMATCH - no matching result Error
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+static int iter_fn(const char* appid, void *data)
+{
+ printf("\t==========================\n");
+ printf("\t appid : %s\n", appid);
+ printf("\t==========================\n");
+ return 0;
+}
+
+...
+{
+ return aul_svc_get_all_defapps(iter_fn, (void*)NULL);
+}
+ * @endcode
+ *
+ */
+int aul_svc_get_all_defapps(aul_svc_info_iter_fn iter_fn, void *data);
+
+/**
+ * @par Description:
+ * This function gets a operation from bundle.
+ *
+ * @param[in] b bundle object
+ *
+ * @return Pointer for operation string if success, NULL if fail
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ char *val;
+ val = aul_svc_get_operation(b);
+}
+ * @endcode
+ *
+ */
+const char *aul_svc_get_operation(bundle *b);
+
+/**
+ * @par Description:
+ * This function gets a uri from bundle.
+ *
+ * @param[in] b bundle object
+ *
+ * @return Pointer for uri string if success, NULL if fail
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ char *val;
+ val = aul_svc_get_uri(b);
+}
+ * @endcode
+ *
+ */
+const char *aul_svc_get_uri(bundle *b);
+
+/**
+ * @par Description:
+ * This function gets a mime-type from bundle.
+ *
+ * @param[in] b bundle object
+ *
+ * @return Pointer for mime-type string if success, NULL if fail
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ char *val;
+ val = aul_svc_get_mime(b);
+}
+ * @endcode
+ *
+ */
+const char *aul_svc_get_mime(bundle *b);
+
+/**
+ * @par Description:
+ * This function gets a package name from bundle.
+ *
+ * @param[in] b bundle object
+ *
+ * @return Pointer for package name string if success, NULL if fail
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ char *val;
+ val = aul_svc_get_pkgname(b);
+}
+ * @endcode
+ *
+ */
+/* Deprecated API */
+const char *aul_svc_get_pkgname(bundle *b); // __attribute__((deprecated));
+
+/**
+ * @par Description:
+ * This function gets a application id from bundle.
+ *
+ * @param[in] b bundle object
+ *
+ * @return Pointer for application id string if success, NULL if fail
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ char *val;
+ val = aul_svc_get_appid(b);
+}
+ * @endcode
+ *
+ */
+const char *aul_svc_get_appid(bundle *b);
+
+/**
+ * @par Description:
+ * This function gets a application category from bundle.
+ *
+ * @param[in] b bundle object
+ *
+ * @return Pointer for application category string if success, NULL if fail
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ char *val;
+ val = aul_svc_get_category(b);
+}
+ * @endcode
+ *
+ */
+const char *aul_svc_get_category(bundle *b);
+
+/**
+ * @par Description:
+ * This function gets value from key.
+ *
+ * @param[in] b bundle object
+ * @param[in] key key
+ *
+ * @return Pointer for value string if success, NULL if fail
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ char *val;
+ val = aul_svc_get_data(b, AUL_SVC_DATA_CC);
+}
+ * @endcode
+ *
+ */
+const char *aul_svc_get_data(bundle *b, const char *key);
+
+/**
+ * @par Description:
+ * This function gets value from key.
+ *
+ * @param[in] b bundle object
+ * @param[in] key key
+ * @param[out] len length of array
+ *
+ * @return Pointer for value string array if success, NULL if fail
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ char **val_array;
+ int len;
+ char *val;
+
+ if(aul_svc_data_is_array(b, AUL_SVC_DATA_SELECTED))
+ val_array = aul_svc_get_data_array(b, AUL_SVC_DATA_SELECTED, &len);
+ else
+ val = aul_svc_get_data(b, AUL_SVC_DATA_SELECTED);
+}
+ * @endcode
+ *
+ */
+const char **aul_svc_get_data_array(bundle *b, const char *key, int *len);
+
+/**
+ * @par Description:
+ * This API create appsvc result bundle based on bundle received in reset event.
+ *
+ * @param[in] inb bundle received in reset event
+ * @param[in] outb bundle to use for returning result
+ *
+ * @retval AUL_SVC_RET_OK - success
+ * @retval AUL_SVC_RET_ERROR - general error
+ * @retval AUL_SVC_RET_EINVAL - invalid argument(content)
+ *
+ * @pre None.
+ * @post None.
+ * @see aul_svc_send_result.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ struct appdata *ad = data;
+ bundle* res_bundle;
+
+ aul_svc_create_result_bundle(ad->b,&res_bundle);
+ bundle_add(res_bundle, "result", "1");
+ aul_svc_send_result(res_bundle, 0);
+}
+ * @endcode
+ *
+ */
+int aul_svc_create_result_bundle(bundle *inb, bundle **outb);
+
+/**
+ * @par Description:
+ * This API send appsvc result to caller with bundle.
+ *
+ * @param[in] b Result data in bundle format
+ * @param[in] result result value
+ *
+ * @retval AUL_SVC_RET_OK - success
+ * @retval AUL_SVC_RET_ERROR - general error
+ * @retval AUL_SVC_RET_EINVAL - invalid argument(content)
+ *
+ * @pre aul_svc_create_result_bundle.
+ * @post None.
+ * @see aul_svc_send_result.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ struct appdata *ad = data;
+ bundle* res_bundle;
+
+ aul_svc_create_result_bundle(ad->b,&res_bundle);
+ bundle_add(res_bundle, "result", "1");
+ aul_svc_send_result(res_bundle, 0);
+}
+ * @endcode
+ *
+ */
+int aul_svc_send_result(bundle *b, aul_svc_result_val result);
+
+/**
+ * @par Description:
+ * This API set the default application(package name) associated with op, uri and mime-type.
+ *
+ * @param[in] op operation
+ * @param[in] mime_type mime-type
+ * @param[in] scheme scheme of uri
+ * @param[in] defapp default application
+ *
+ * @retval AUL_SVC_RET_OK - success
+ * @retval AUL_SVC_RET_ERROR - general error
+ * @retval AUL_SVC_RET_EINVAL - invalid argument(content)
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ aul_svc_set_defapp(AUL_SVC_OPERATION_VIEW, NULL,"http", "org.tizen.mybrowser");
+}
+ * @endcode
+ *
+ */
+int aul_svc_set_defapp(const char *op, const char *mime_type, const char *uri,
+ const char *defapp);
+
+/**
+ * @par Description:
+ * This API unset the default application(package name) associated with op, uri and mime-type.
+ *
+ * @param[in] defapp default application
+ *
+ * @retval AUL_SVC_RET_OK - success
+ * @retval AUL_SVC_RET_ERROR - general error
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ aul_svc_unset_defapp("org.tizen.test");
+}
+ * @endcode
+ *
+ */
+int aul_svc_unset_defapp(const char *defapp);
+
+/**
+ * @par Description:
+ * This API unset all of default applications associated with op, uri and mime-type.
+ *
+ *
+ * @retval AUL_SVC_RET_OK - success
+ * @retval AUL_SVC_RET_ERROR - general error
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ aul_svc_unset_all_defapps();
+}
+ * @endcode
+ *
+ */
+int aul_svc_unset_all_defapps();
+
+/**
+ * @par Description:
+ * This API ask a application is default application or not.
+ *
+ * @param[in] appid application appid
+ * @return true / false
+ * @retval 1 app_name is default application in appsvc.
+ * @retval 0 app_name is NOT default application in appsvc.
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+ ...
+
+ * int is_defapp_browser_app()
+ * {
+ * return aul_svc_is_defapp("org.tizen.browser");
+ * }
+ *
+ * @endcode
+ * @remark
+ * None
+*
+*/
+int aul_svc_is_defapp(const char *appid);
+
+
+/**
+ * @par Description:
+ * This API ask a extra data is array or not.
+ *
+ * @param[in] b bundle object
+ * @param[in] key key of extra data
+ * @return true / false
+ * @retval 1 a extra data is array.
+ * @retval 0 a extra data is not array.
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+ ...
+
+ * int aul_svc_data_is_array(bundle *b, char *key)
+ * {
+ * return aul_svc_data_is_array(b, key);
+ * }
+ *
+ * @endcode
+ * @remark
+ * None
+*
+*/
+int aul_svc_data_is_array(bundle *b, const char *key);
+
+int aul_svc_subapp_terminate_request_pid(int pid);
+
+/**
+ * @par Description:
+ * This function sets an uri to launch application based on appsvc.
+ *
+ * @param[in] b bundle object
+ * @param[in] char *mode
+ *
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_SVC_RET_OK - success
+ * @retval AUL_SVC_RET_ERROR - general error
+ * @retval AUL_SVC_RET_EINVAL - invalid argument(content)
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ aul_svc_set_launch_mode(app_control->data, mode);
+}
+ * @endcode
+ *
+ */
+int aul_svc_set_launch_mode(bundle *b, const char *mode);
+
+/**
+ * @par Description:
+ * This function sets an uri to launch application based on appsvc.
+ *
+ * @param[in] b bundle object
+ *
+ * @return Pointer for launch mode string if success, NULL if fail
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ aul_svc_get_launch_mode(app_control->data);
+}
+ * @endcode
+ *
+ */
+const char *aul_svc_get_launch_mode(bundle *b);
+
+int aul_svc_allow_transient_app(bundle *b, int wid);
+
+int aul_svc_request_transient_app(bundle *b, int callee_wid,
+ aul_svc_host_res_fn cbfunc, void *data);
+
+int aul_svc_subscribe_launch_result(bundle *b, const char *event);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* __AUL_SVC_H__ */
+
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef __AUL_SVC_DB_H__
+#define __AUL_SVC_DB_H__
+
+#include <sqlite3.h>
+#include <time.h>
+#include <sys/types.h>
+#include <glib.h>
+
+#define MAX_FILTER_STR_SIZE 1024
+#define MAX_PACKAGE_STR_SIZE 512
+#define MAX_URI_STR_SIZE 256
+#define MAX_MIME_STR_SIZE 256
+#define MAX_SCHEME_STR_SIZE 256
+#define MAX_HOST_STR_SIZE 256
+#define MAX_OP_STR_SIZE 128
+
+#define _SVC_DB_PATH "/opt/dbspace/.appsvc.db"
+#define _SVC_APP_INFO_DB_PATH "/opt/dbspace/.pkgmgr_parser.db"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+int _svc_db_check_perm();
+int _svc_db_add_app(const char *op, const char *mime_type, const char *uri, const char *pkg_name);
+int _svc_db_delete_with_pkgname(const char *pkg_name);
+char* _svc_db_get_app(const char *op, const char *mime_type, const char *uri);
+int _svc_db_is_defapp(const char *pkg_name);
+int _svc_db_adjust_list_with_submode(int mainapp_mode, char *win_id, GSList **pkg_list);
+int _svc_db_get_list_with_condition(char *op, char *uri, char *mime, GSList **pkg_list);
+int _svc_db_get_list_with_collation(char *op, char *uri, char *mime, GSList **pkg_list);
+int _svc_db_get_list_with_all_defapps(GSList **pkg_list);
+int _svc_db_delete_all();
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __AUL_SVC_DB_H__ */
+
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef __PRIV_KEY_H__
+#define __PRIV_KEY_H__
+
+/** AUL SVC internal private key */
+#define AUL_SVC_K_OPERATION "__APP_SVC_OP_TYPE__"
+/** AUL SVC internal private key */
+#define AUL_SVC_K_URI "__APP_SVC_URI__"
+/** AUL SVC internal private key */
+#define AUL_SVC_K_MIME "__APP_SVC_MIME_TYPE__"
+/** AUL SVC internal private key */
+#define AUL_SVC_K_DATA "__APP_SVC_DATA__"
+/** AUL SVC internal private key */
+#define AUL_SVC_K_PKG_NAME "__APP_SVC_PKG_NAME__"
+/** AUL SVC internal private key */
+#define AUL_SVC_K_CATEGORY "__APP_SVC_CATEGORY__"
+/** AUL SVC internal private key */
+#define AUL_SVC_K_RES_VAL "__APP_SVC_K_RES_VAL__"
+/** AUL SVC internal private key */
+#define AUL_SVC_K_WIN_ID "__APP_SVC_K_WIN_ID__"
+/** AUL SVC internal private key */
+#define AUL_SVC_K_LAUNCH_MODE "__APP_SVC_LAUNCH_MODE__"
+
+#endif /* __PRIV_KEY_H__ */
+
#ifndef __AUL_UTIL_H_
#define __AUL_UTIL_H_
-#define AUL_UTIL_PID -2
+#include <glib.h>
+#include "app_launchpad_types.h"
+
+#define SYSTEM_UID 200
+#define APP_UID 5000
#define MAX_PACKAGE_STR_SIZE 512
#define MAX_PACKAGE_APP_PATH_SIZE 512
#define MAX_RUNNING_APP_INFO 512
-typedef struct _app_status_info_t{
- char appid[MAX_PACKAGE_STR_SIZE];
- char app_path[MAX_PACKAGE_APP_PATH_SIZE];
- char caller[MAX_PACKAGE_STR_SIZE];
+typedef struct _app_status_info_t app_status_info_t;
+typedef struct _pkg_status_info_t pkg_status_info_t;
+
+struct _app_status_info_t {
+ char *appid;
+ char *app_path;
+ char *caller;
+ char *pkgid;
+ char *exec_label;
int status;
int pid;
int pad_pid;
-} app_status_info_t;
+ int last_caller_pid;
+ int is_subapp;
+ pkg_status_info_t *pkginfo;
+ GList *shared_info_list;
+};
+
+struct _pkg_status_info_t {
+ char *pkgid;
+ int status;
+ GSList *ui_list;
+ GSList *svc_list;
+};
struct amdmgr {
struct appinfomgr *af; /* appinfo manager */
- struct cginfo *cg; /* cgroup infomation */
};
-int _add_app_status_info_list(char *appid, int pid);
-int _update_app_status_info_list(int pid, int status);
-int _remove_app_status_info_list(int pid);
-
#endif
-
-
--- /dev/null
+/*
+ * aul
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+#ifndef __AUL_ZONE_H_
+#define __AUL_ZONE_H_
+
+extern char *_socket_prefix;
+extern char *_root_path;
+extern char *_cur_zone;
+extern int _pid_offset;
+const char* _get_sock_prefix();
+const char* _get_root_path();
+
+int aul_set_zone(const char *zone, char **old_zone);
+
+#endif
+
+
+
#include <glib.h>
int aul_initialize();
+void aul_finalize();
int aul_register_init_callback(
int (*aul_handler)(aul_type type, bundle *, void *), void *data);
int aul_is_initialized();
int _app_start_res_prepare(bundle *kb);
int app_result(int cmd, bundle *kb, int launched_pid);
int aul_send_result(bundle *kb, int is_cancel);
+int app_subapp_terminate_request();
int aul_launch_app_with_result(const char *pkgname, bundle *kb,
void (*cbfunc) (bundle *, int, void *),
void *data);
+int __call_aul_handler(aul_type type, bundle *kb);
+
gboolean __aul_glib_handler(gpointer data);
#ifndef __MENU_DB_UTIL_H_
#define __MENU_DB_UTIL_H_
-#include <ail.h>
+#include <pkgmgr-info.h>
#include <string.h>
#include <stdio.h>
#include "simple_util.h"
#define AUL_RETRIEVE_SERVICE "x_slp_service like '?'"
typedef struct {
- char *pkg_name; /* package */
+ char *pkg_name; /* appid */
char *app_path; /* exec */
char *original_app_path; /* exec */
char *pkg_type; /* x_slp_packagetype */
}
static inline app_info_from_db *_get_app_info_from_db_by_pkgname(
- const char *pkgname)
+ const char *appid)
{
- app_info_from_db *menu_info;
- ail_appinfo_h handle;
- ail_error_e ret;
- char *str = NULL;
+ app_info_from_db *menu_info = NULL;
+ pkgmgrinfo_appinfo_h handle = NULL;
+ int ret = PMINFO_R_OK;
+ char *exec = NULL;
+ char *apptype = NULL;
menu_info = calloc(1, sizeof(app_info_from_db));
if (menu_info == NULL) {
return NULL;
}
- ret = ail_get_appinfo(pkgname, &handle);
- if (ret != AIL_ERROR_OK) {
+ if(appid == NULL) {
_free_app_info_from_db(menu_info);
return NULL;
}
- ret = ail_appinfo_get_str(handle, AIL_PROP_PACKAGE_STR, &str);
- if (str) {
- menu_info->pkg_name = strdup(str);
- str = NULL;
+ ret = pkgmgrinfo_appinfo_get_appinfo(appid, &handle);
+ if (ret != PMINFO_R_OK) {
+ _free_app_info_from_db(menu_info);
+ return NULL;
}
- ret = ail_appinfo_get_str(handle, AIL_PROP_EXEC_STR, &str);
- if (str) {
- menu_info->app_path = strdup(str);
- str = NULL;
+ menu_info->pkg_name = strdup(appid);
+
+ ret = pkgmgrinfo_appinfo_get_exec(handle, &exec);
+ if(ret != PMINFO_R_OK) {
+ _E("fail to get exec from appinfo handle");
+ }
+ if (exec) {
+ menu_info->app_path = strdup(exec);
}
if (menu_info->app_path != NULL)
menu_info->original_app_path = strdup(menu_info->app_path);
- ret = ail_appinfo_get_str(handle, AIL_PROP_X_SLP_PACKAGETYPE_STR, &str);
- if (str) {
- menu_info->pkg_type = strdup(str);
- str = NULL;
+ ret = pkgmgrinfo_appinfo_get_apptype(handle, &apptype);
+ if(ret != PMINFO_R_OK) {
+ _E("fail to get apptype from appinfo handle");
+ }
+ if (apptype) {
+ menu_info->pkg_type = strdup(apptype);
}
- ret = ail_destroy_appinfo(handle);
- if (ret != AIL_ERROR_OK) {
- _E("ail_destroy_appinfo failed");
+ ret = pkgmgrinfo_appinfo_destroy_appinfo(handle);
+ if (ret != PMINFO_R_OK) {
+ _E("pkgmgrinfo_appinfo_destroy_appinfo failed");
}
if (!_get_app_path(menu_info)) {
return menu_info;
}
-static inline ail_cb_ret_e __appinfo_func(const ail_appinfo_h appinfo, void *user_data)
+static inline int __appinfo_func(const pkgmgrinfo_appinfo_h appinfo, void *user_data)
{
app_info_from_db *menu_info = (app_info_from_db *)user_data;
- char *package;
- char *pkgid;
- ail_cb_ret_e ret = AIL_CB_RET_CONTINUE;
+ char *appid = NULL;
+ char *pkgid = NULL;
+ int ret = PMINFO_R_OK; // continue the loop
if (!menu_info)
return ret;
- ail_appinfo_get_str(appinfo, AIL_PROP_PACKAGE_STR, &package);
- if (package) {
- menu_info->pkg_name = strdup(package);
- ret = AIL_CB_RET_CANCEL;
+ ret = pkgmgrinfo_appinfo_get_appid(appinfo, &appid);
+ if (ret == PMINFO_R_OK && appid) {
+ menu_info->pkg_name = strdup(appid);
+ //ret = PMINFO_R_ERROR; // stop the loop
}
- ail_appinfo_get_str(appinfo, AIL_PROP_X_SLP_PKGID_STR, &pkgid);
- if (pkgid) {
+ ret = pkgmgrinfo_appinfo_get_pkgid(appinfo, &pkgid);
+ if (ret == PMINFO_R_OK && pkgid) {
menu_info->pkg_id = strdup(pkgid);
}
const char *apppath)
{
app_info_from_db *menu_info = NULL;
- ail_filter_h filter;
- ail_error_e ret;
- int count;
+ pkgmgrinfo_appinfo_filter_h filter = NULL;
+ int ret = PMINFO_R_OK;
if (apppath == NULL)
return NULL;
if (menu_info == NULL)
return NULL;
- ret = ail_filter_new(&filter);
- if (ret != AIL_ERROR_OK) {
+ ret = pkgmgrinfo_appinfo_filter_create(&filter);
+ if (ret != PMINFO_R_OK) {
_free_app_info_from_db(menu_info);
return NULL;
}
- ret = ail_filter_add_str(filter, AIL_PROP_X_SLP_EXE_PATH, apppath);
- if (ret != AIL_ERROR_OK) {
- ail_filter_destroy(filter);
+ ret = pkgmgrinfo_appinfo_filter_add_string(filter, PMINFO_APPINFO_PROP_APP_EXEC, apppath);
+ if (ret != PMINFO_R_OK) {
+ pkgmgrinfo_appinfo_filter_destroy(filter);
_free_app_info_from_db(menu_info);
return NULL;
}
- ret = ail_filter_count_appinfo(filter, &count);
- if (ret != AIL_ERROR_OK) {
- ail_filter_destroy(filter);
+ ret = pkgmgrinfo_appinfo_filter_foreach_appinfo(filter, __appinfo_func, (void *)menu_info);
+ if (menu_info->pkg_name == NULL) {
+ _I("path : %s, ret : %d", apppath, ret);
+ pkgmgrinfo_appinfo_filter_destroy(filter);
_free_app_info_from_db(menu_info);
return NULL;
}
- if (count < 1) {
- ail_filter_destroy(filter);
- _free_app_info_from_db(menu_info);
- return NULL;
- }
-
- ail_filter_list_appinfo_foreach(filter, __appinfo_func, (void *)menu_info);
- ail_filter_destroy(filter);
+ pkgmgrinfo_appinfo_filter_destroy(filter);
menu_info->app_path = strdup(apppath);
menu_info->original_app_path = strdup(apppath);
#ifdef PERF_ACTIVATE
#include <sys/time.h>
+#include <bundle_internal.h>
static struct timeval __g_base_time = {
.tv_sec = 0,
.tv_usec = 0
#endif
-#define MAX_LOCAL_BUFSZ 128
+#define MAX_LOCAL_BUFSZ 512
#define MAX_PID_STR_BUFSZ 20
+#define MAX_STATUS_STR_BUFSZ 32
+#define MAX_OOM_ADJ_BUFSZ 32
#define _E(fmt, arg...) LOGE(fmt, ##arg)
#define _D(fmt, arg...) LOGD(fmt, ##arg)
} \
} while (0)
+int __proc_check_app(const char *path, int pid);
int __proc_iter_cmdline(int (*iterfunc)
(const char *dname, const char *cmdline, void *priv),
void *priv);
* simple AUL daemon - launchpad
*/
+#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <dlfcn.h>
#include <sys/prctl.h>
#include <malloc.h>
#include <sys/resource.h>
+#include <ttrace.h>
+#include <bundle_internal.h>
#include "app_sock.h"
#include "aul.h"
#include <sqlite3.h>
#define _static_ static inline
-#define POLLFD_MAX 1
+#define POLLFD_MAX 2
#define SQLITE_FLUSH_MAX (1048576) /* (1024*1024) */
#define AUL_POLL_CNT 15
#define AUL_PR_NAME 16
_static_ int __resume_app(int pid);
_static_ int __real_send(int clifd, int ret);
_static_ void __send_result_to_caller(int clifd, int ret);
-_static_ void __launchpad_main_loop(int main_fd);
+_static_ void __launchpad_main_loop(int main_fd, int sigchld_fd);
_static_ int __launchpad_pre_init(int argc, char **argv);
_static_ int __launchpad_post_init();
-extern ail_error_e ail_db_close(void);
}
}
-_static_ void __launchpad_main_loop(int main_fd)
+_static_ void __launchpad_main_loop(int main_fd, int sigchld_fd)
{
bundle *kb = NULL;
app_pkt_t *pkt = NULL;
char sock_path[UNIX_PATH_MAX] = {0,};
+ traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "AUL:PAD:MAINLOOP");
pkt = __app_recv_raw(main_fd, &clifd, &cr);
if (!pkt) {
_D("packet is NULL");
close(clifd);
close(main_fd);
- __signal_unset_sigchld();
+ close(sigchld_fd);
+ __signal_unblock_sigchld();
__signal_fini();
snprintf(sock_path, UNIX_PATH_MAX, "%s/%d", AUL_SOCK_PREFIX, getpid());
menu_info, kb) < 0) {
SECURE_LOGE("preparing work fail to launch - "
"can not launch %s\n", pkg_name);
+ traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
exit(-1);
}
__real_launch(app_path, kb);
+ traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
exit(-1);
}
SECURE_LOGD("==> real launch pid : %d %s\n", pid, app_path);
__send_result_to_caller(clifd, pid);
if (pid > 0) {
- if (is_real_launch) {
- /*TODO: retry*/
- __signal_block_sigchld();
+ if (is_real_launch)
__send_app_launch_signal(pid);
- __signal_unblock_sigchld();
- }
}
if (menu_info != NULL)
initialized = 1;
}
+ traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
+
}
_static_ int __launchpad_pre_init(int argc, char **argv)
return 0;
}
- if (__signal_set_sigchld() < 0)
- return -1;
-
initialized++;
return 0;
int main(int argc, char **argv)
{
int main_fd;
+ int sigchld_fd;
struct pollfd pfds[POLLFD_MAX];
- int i;
/* init without concerning X & EFL*/
main_fd = __launchpad_pre_init(argc, argv);
pfds[0].events = POLLIN;
pfds[0].revents = 0;
+ sigchld_fd = __signal_get_sigchld_fd();
+ if (sigchld_fd == -1) {
+ _E("failed to get sigchld fd");
+ exit(-1);
+ }
+ pfds[1].fd = sigchld_fd;
+ pfds[1].events = POLLIN;
+ pfds[1].revents = 0;
+
#ifdef _APPFW_FEATURE_PRIORITY_CHANGE
int res = setpriority(PRIO_PROCESS, 0, -12);
if (res == -1)
exit(-1);
}
- for (i = 0; i < POLLFD_MAX; i++) {
- if ((pfds[i].revents & POLLIN) != 0) {
- __launchpad_main_loop(pfds[i].fd);
- }
+ if ((pfds[1].revents & POLLIN) != 0) {
+ struct signalfd_siginfo siginfo;
+ ssize_t s;
+
+ do {
+ s = read(pfds[1].fd, &siginfo, sizeof(struct signalfd_siginfo));
+ if (s == 0)
+ break;
+
+ if (s != sizeof(struct signalfd_siginfo)) {
+ _E("error reading sigchld info");
+ break;
+ }
+ __launchpad_process_sigchld(&siginfo);
+ } while (s > 0);
+ }
+
+ if ((pfds[0].revents & POLLIN) != 0) {
+ __launchpad_main_loop(pfds[0].fd, sigchld_fd);
}
}
}
#include <pthread.h>
+#include <sys/signalfd.h>
+#include <signal.h>
#include "app_signal.h"
-static struct sigaction old_sigchild;
-static DBusConnection *bus = NULL;
sigset_t oldmask;
static inline void __socket_garbage_collector()
static inline int __send_app_dead_signal(int dead_pid)
{
+ DBusConnection *bus;
DBusMessage *message;
+ DBusError error;
- if (bus == NULL)
+ dbus_error_init(&error);
+ dbus_threads_init_default();
+ bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
+ if (!bus) {
+ _E("Failed to connect to the D-BUS daemon: %s", error.message);
+ dbus_error_free(&error);
return -1;
+ }
message = dbus_message_new_signal(AUL_DBUS_PATH,
AUL_DBUS_SIGNAL_INTERFACE,
}
dbus_connection_flush(bus);
+ dbus_connection_close(bus);
dbus_message_unref(message);
_D("send dead signal done\n");
static inline int __send_app_launch_signal(int launch_pid)
{
+ DBusConnection *bus;
DBusMessage *message;
+ DBusError error;
- if (bus == NULL)
+ dbus_error_init(&error);
+ dbus_threads_init_default();
+ bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
+ if (!bus) {
+ _E("Failed to connect to the D-BUS daemon: %s", error.message);
+ dbus_error_free(&error);
return -1;
+ }
message = dbus_message_new_signal(AUL_DBUS_PATH,
AUL_DBUS_SIGNAL_INTERFACE,
}
dbus_connection_flush(bus);
+ dbus_connection_close(bus);
dbus_message_unref(message);
_D("send launch signal done\n");
return 0;
}
-static void __launchpad_sig_child(int signo, siginfo_t *info, void *data)
+static void __launchpad_process_sigchld(struct signalfd_siginfo *info)
{
int status;
pid_t child_pid;
pid_t child_pgid;
- child_pgid = getpgid(info->si_pid);
- _I("dead_pid = %d pgid = %d", info->si_pid, child_pgid);
+ child_pgid = getpgid(info->ssi_pid);
+ _I("dead_pid = %d pgid = %d", info->ssi_pid, child_pgid);
while ((child_pid = waitpid(-1, &status, WNOHANG)) > 0) {
if (child_pid == child_pgid)
return 0;
}
-static inline int __signal_set_sigchld(void)
-{
- struct sigaction act;
- DBusError error;
-
- dbus_error_init(&error);
- dbus_threads_init_default();
- bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
- if (!bus) {
- _E("Failed to connect to the D-BUS daemon: %s", error.message);
- dbus_error_free(&error);
- return -1;
- }
- /* TODO: if process stop mechanism is included,
- should be modified (SA_NOCLDSTOP)*/
- act.sa_handler = NULL;
- act.sa_sigaction = __launchpad_sig_child;
- sigemptyset(&act.sa_mask);
- act.sa_flags = SA_NOCLDSTOP | SA_SIGINFO;
-
- if (sigaction(SIGCHLD, &act, &old_sigchild) < 0)
- return -1;
-
- return 0;
-}
-
-static inline int __signal_unset_sigchld(void)
+static inline int __signal_get_sigchld_fd(void)
{
- struct sigaction dummy;
-
- if (bus == NULL)
- return 0;
+ sigset_t mask;
+ int sfd;
- dbus_connection_close(bus);
- if (sigaction(SIGCHLD, &old_sigchild, &dummy) < 0)
- return -1;
+ sigemptyset(&mask);
+ sigaddset(&mask, SIGCHLD);
- return 0;
-}
+ if (sigprocmask(SIG_BLOCK, &mask, &oldmask) == -1)
+ _E("failed to sigprocmask");
-static inline int __signal_block_sigchld(void)
-{
- sigset_t newmask;
-
- sigemptyset(&newmask);
- sigaddset(&newmask, SIGCHLD);
-
- if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0) {
- _E("SIG_BLOCK error");
+ sfd = signalfd(-1, &mask, SFD_NONBLOCK | SFD_CLOEXEC);
+ if (sfd == -1) {
+ _E("failed to create signalfd for SIGCHLD");
return -1;
}
- _D("SIGCHLD blocked");
-
- return 0;
+ return sfd;
}
static inline int __signal_unblock_sigchld(void)
*
*/
-
+#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
[Unit]
Description=Start the Access Control server
-After=dbus.service vconf-setup.service
+Requires=xorg.service tizen-generate-env.service
+After=dbus.service vconf-setup.service xorg.service tizen-generate-env.service
[Service]
EnvironmentFile=/run/tizen-mobile-env
Name: aul
Summary: App utility library
Version: 0.2.3.0
-Release: 6
+Release: 7
Group: System/Libraries
License: Apache-2.0
Source0: %{name}-%{version}.tar.gz
Source101: ac.service
-Source102: launchpad-preload.service
Requires(post): /sbin/ldconfig
Requires(post): /usr/bin/systemctl
BuildRequires: pkgconfig(ecore)
BuildRequires: pkgconfig(bundle)
BuildRequires: pkgconfig(dlog)
-BuildRequires: pkgconfig(ail)
BuildRequires: xdgmime-devel, pkgconfig(xdgmime)
BuildRequires: pkgconfig(libprivilege-control)
-BuildRequires: pkgconfig(app-checker)
-BuildRequires: pkgconfig(app-checker-server)
BuildRequires: pkgconfig(rua)
BuildRequires: pkgconfig(ecore-x)
+BuildRequires: pkgconfig(ecore-evas)
BuildRequires: pkgconfig(ecore-input)
BuildRequires: pkgconfig(utilX)
BuildRequires: pkgconfig(vconf)
BuildRequires: pkgconfig(pkgmgr-info)
BuildRequires: pkgconfig(libsmack)
-#BuildRequires: pkgconfig(system-resource)
BuildRequires: pkgconfig(libresourced)
BuildRequires: pkgconfig(security-server)
+BuildRequires: pkgconfig(iniparser)
+BuildRequires: pkgconfig(ttrace)
+BuildRequires: pkgconfig(vasum)
+BuildRequires: pkgconfig(appfw-env)
+BuildRequires: pkgconfig(capi-system-info)
+BuildRequires: pkgconfig(cert-svc)
-%define feature_appfw_integrated_contact_phone 1
-%define feature_appfw_multi_instance 1
-%define feature_appfw_process_pool 1
%define keepstatic 1
-%if "%{?tizen_profile_name}" == "wearable"
-%define appfw_feature_process_pool_common 1
+
+%define appfw_feature_process_pool 1
+%define appfw_feature_multi_instance 1
%define appfw_feature_hw_rendering 0
-%elseif "%{?tizen_profile_name}" == "mobile"
-%define appfw_feature_process_pool_common 0
-%define appfw_feature_hw_rendering 1
-%endif
%define appfw_feature_priority_change 1
%define appfw_feature_default_fake_image 0
%define appfw_feature_data_control 1
%define appfw_feature_debug_launchpad 1
%define appfw_feature_app_control_lite 0
-%define appfw_feature_native_launchpad 0
+%define appfw_feature_terminate_unmanageable_app 0
%if "%{?tizen_profile_name}" == "wearable"
%define appfw_feature_bg_process_limit 0
%define appfw_feature_app_checker 0
-%define appfw_feature_tts_mode 1
-%elseif "%{?tizen_profile_name}" == "mobile"
-%define appfw_feature_bg_process_limit 1
+%define appfw_feature_tts_mode 0
+%define appfw_feature_cpu_boost 1
+%define appfw_feature_amd_key 1
+%define appfw_feature_mmc_support 1
+%define appfw_feature_send_home_launch_signal 1
+%define appfw_feature_fake_effect 1
+%define appfw_feature_effective_appid 0
+%define appfw_feature_private_service 1
+%define appfw_feature_background_management 1
+%else
+%if "%{?tizen_profile_name}" == "mobile"
+BuildRequires: pkgconfig(app-checker)
+BuildRequires: pkgconfig(app-checker-server)
+
+%define appfw_feature_bg_process_limit 0
%define appfw_feature_app_checker 1
%define appfw_feature_tts_mode 0
+%define appfw_feature_cpu_boost 1
+%define appfw_feature_amd_key 1
+%define appfw_feature_mmc_support 1
+%define appfw_feature_send_home_launch_signal 1
+%define appfw_feature_fake_effect 1
+%define appfw_feature_effective_appid 1
+%define appfw_feature_private_service 1
+%define appfw_feature_background_management 1
+%else
+%if "%{?tizen_profile_name}" == "tv"
+%define appfw_feature_bg_process_limit 0
+%define appfw_feature_app_checker 0
+%define appfw_feature_tts_mode 0
+%define appfw_feature_cpu_boost 0
+%define appfw_feature_amd_key 0
+%define appfw_feature_mmc_support 0
+%define appfw_feature_send_home_launch_signal 0
+%define appfw_feature_fake_effect 0
+%define appfw_feature_effective_appid 0
+%define appfw_feature_private_service 0
+%define appfw_feature_background_management 0
+%endif
+%endif
%endif
%define appfw_feature_ultra_power_saving_mode 0
+%define appfw_feature_cooldown_mode_support 0
%if "%{?tizen_profile_name}" == "wearable"
%define appfw_feature_visibility_check_by_lcd_status 1
-%elseif "%{?tizen_profile_name}" == "mobile"
+%else
+%if "%{?tizen_profile_name}" == "mobile"
%define appfw_feature_visibility_check_by_lcd_status 0
+%else
+%if "%{?tizen_profile_name}" == "tv"
+%define appfw_feature_visibility_check_by_lcd_status 0
+%endif
%endif
+%endif
+%define appfw_feature_amd_module_log 1
+%define appfw_feature_expansion_pkg_install 1
%description
Application utility library
export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE"
export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE"
%endif
-%if 0%{?feature_appfw_process_pool}
+%if 0%{?appfw_feature_process_pool}
_APPFW_FEATURE_PROCESS_POOL=ON
- %if 0%{?appfw_feature_process_pool_common}
- _APPFW_FEATURE_PROCESS_POOL_COMMON=ON
- %else
- %if 0%{?appfw_feature_hw_rendering}
- _APPFW_FEATURE_PROCESS_POOL_HW_RENDERING=ON
- %endif
- %endif
-%endif
-%if 0%{?feature_appfw_multi_instance}
-_APPFW_FEATURE_MULTI_INSTANCE=ON
%endif
-%if 0%{?feature_appfw_integrated_contact_phone}
-_APPFW_FEATURE_CONTACT_PHONE_AS_ONE_APP=ON
+%if 0%{?appfw_feature_multi_instance}
+_APPFW_FEATURE_MULTI_INSTANCE=ON
%endif
%if 0%{?appfw_feature_priority_change}
_APPFW_FEATURE_PRIORITY_CHANGE=ON
%if 0%{?appfw_feature_app_control_lite}
_APPFW_FEATURE_APP_CONTROL_LITE=ON
%endif
-%if 0%{?appfw_feature_native_launchpad}
-_APPFW_FEATURE_NATIVE_LAUNCHPAD=ON
-%endif
%if 0%{?appfw_feature_bg_process_limit}
_APPFW_FEATURE_BG_PROCESS_LIMIT=ON
%endif
%if 0%{?appfw_feature_ultra_power_saving_mode}
_APPFW_FEATURE_ULTRA_POWER_SAVING_MODE=ON
%endif
-%if 0%{?appfw_feature_visibility_check_by_lcd_status}
-_APPFW_FEATURE_VISIBILITY_CHECK_BY_LCD_STATUS=ON
+%if 0%{?appfw_feature_cooldown_mode_support}
+_APPFW_FEATURE_COOLDOWN_MODE_SUPPORT=ON
+%endif
+%if 0%{?appfw_feature_amd_module_log}
+_APPFW_FEATURE_AMD_MODULE_LOG=ON
+%endif
+%if 0%{?appfw_feature_expansion_pkg_install}
+_APPFW_FEATURE_EXPANSION_PKG_INSTALL=ON
+%endif
+%if 0%{?appfw_feature_cpu_boost}
+_APPFW_FEATURE_CPU_BOOST=ON
+%endif
+%if 0%{?appfw_feature_background_management}
+_APPFW_FEATURE_BACKGROUND_MANAGEMENT=ON
+%endif
+%if 0%{?appfw_feature_amd_key}
+_APPFW_FEATURE_AMD_KEY=ON
+%endif
+%if 0%{?appfw_feature_mmc_support}
+_APPFW_FEATURE_MMC_SUPPORT=ON
+%endif
+%if 0%{?appfw_feature_send_home_launch_signal}
+_APPFW_FEATURE_SEND_HOME_LAUNCH_SIGNAL=ON
+%endif
+%if 0%{?appfw_feature_fake_effect}
+_APPFW_FEATURE_FAKE_EFFECT=ON
+%endif
+%if 0%{?appfw_feature_effective_appid}
+_APPFW_FEATURE_EFFECTIVE_APPID=ON
+%endif
+%if 0%{?appfw_feature_private_service}
+_APPFW_FEATURE_PRIVATE_SERVICE=ON
+%endif
+%if 0%{?appfw_feature_terminate_unmanageable_app}
+_APPFW_FEATURE_TERMINATE_UNMANAGEABLE_APP=ON
%endif
cmake -DCMAKE_INSTALL_PREFIX=%{_prefix} \
-D_APPFW_FEATURE_PROCESS_POOL:BOOL=${_APPFW_FEATURE_PROCESS_POOL} \
- -D_APPFW_FEATURE_PROCESS_POOL_COMMON:BOOL=${_APPFW_FEATURE_PROCESS_POOL_COMMON} \
- -D_APPFW_FEATURE_PROCESS_POOL_HW_RENDERING:BOOL=${_APPFW_FEATURE_PROCESS_POOL_HW_RENDERING} \
-D_APPFW_FEATURE_MULTI_INSTANCE:BOOL=${_APPFW_FEATURE_MULTI_INSTANCE} \
- -D_APPFW_FEATURE_MULTI_WINDOW:BOOL=${_APPFW_FEATURE_MULTI_WINDOW} \
-D_APPFW_FEATURE_CHANGEABLE_COLOR:BOOL=${_APPFW_FEATURE_CHANGEABLE_COLOR} \
-D_APPFW_FEATURE_CPU_BOOST:BOOL=${_APPFW_FEATURE_CPU_BOOST} \
- -D_APPFW_FEATURE_CONTACT_PHONE_AS_ONE_APP:BOOL=${_APPFW_FEATURE_CONTACT_PHONE_AS_ONE_APP} \
-D_APPFW_FEATURE_PRIORITY_CHANGE:BOOL=${_APPFW_FEATURE_PRIORITY_CHANGE} \
-D_APPFW_FEATURE_DEFAULT_FAKE_IMAGE:BOOL=${_APPFW_FEATURE_DEFAULT_FAKE_IMAGE} \
-D_APPFW_FEATURE_DATA_CONTROL:BOOL=${_APPFW_FEATURE_DATA_CONTROL} \
-D_APPFW_FEATURE_DEBUG_LAUNCHPAD:BOOL=${_APPFW_FEATURE_DEBUG_LAUNCHPAD} \
-D_APPFW_FEATURE_APP_CONTROL_LITE:BOOL=${_APPFW_FEATURE_APP_CONTROL_LITE} \
- -D_APPFW_FEATURE_NATIVE_LAUNCHPAD:BOOL=${_APPFW_FEATURE_NATIVE_LAUNCHPAD} \
-D_APPFW_FEATURE_WMS_CONNECTION_CHECK:BOOL=${_APPFW_FEATURE_WMS_CONNECTION_CHECK} \
-D_APPFW_FEATURE_BG_PROCESS_LIMIT:BOOL=${_APPFW_FEATURE_BG_PROCESS_LIMIT} \
-D_APPFW_FEATURE_APP_CHECKER:BOOL=${_APPFW_FEATURE_APP_CHECKER} \
-D_APPFW_FEATURE_TTS_MODE:BOOL=${_APPFW_FEATURE_TTS_MODE} \
-D_APPFW_FEATURE_ULTRA_POWER_SAVING_MODE:BOOL=${_APPFW_FEATURE_ULTRA_POWER_SAVING_MODE} \
+ -D_APPFW_FEATURE_COOLDOWN_MODE_SUPPORT:BOOL=${_APPFW_FEATURE_COOLDOWN_MODE_SUPPORT} \
-D_APPFW_FEATURE_VISIBILITY_CHECK_BY_LCD_STATUS:BOOL=${_APPFW_FEATURE_VISIBILITY_CHECK_BY_LCD_STATUS} \
+ -D_APPFW_FEATURE_AMD_MODULE_LOG:BOOL=${_APPFW_FEATURE_AMD_MODULE_LOG} \
+ -D_APPFW_FEATURE_EXPANSION_PKG_INSTALL:BOOL=${_APPFW_FEATURE_EXPANSION_PKG_INSTALL} \
+ -D_APPFW_FEATURE_BACKGROUND_MANAGEMENT:BOOL=${_APPFW_FEATURE_BACKGROUND_MANAGEMENT} \
+ -D_APPFW_FEATURE_AMD_KEY:BOOL=${_APPFW_FEATURE_AMD_KEY} \
+ -D_APPFW_FEATURE_MMC_SUPPORT:BOOL=${_APPFW_FEATURE_MMC_SUPPORT} \
+ -D_APPFW_FEATURE_SEND_HOME_LAUNCH_SIGNAL:BOOL=${_APPFW_FEATURE_SEND_HOME_LAUNCH_SIGNAL} \
+ -D_APPFW_FEATURE_FAKE_EFFECT:BOOL=${_APPFW_FEATURE_FAKE_EFFECT} \
+ -D_APPFW_FEATURE_EFFECTIVE_APPID:BOOL=${_APPFW_FEATURE_EFFECTIVE_APPID} \
+ -D_APPFW_FEATURE_PRIVATE_SERVICE:BOOL=${_APPFW_FEATURE_PRIVATE_SERVICE} \
+ -D_APPFW_FEATURE_TERMINATE_UNMANAGEABLE_APP:BOOL=${_APPFW_FEATURE_TERMINATE_UNMANAGEABLE_APP} \
.
make %{?jobs:-j%jobs}
mkdir -p %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants
install -m0644 %SOURCE101 %{buildroot}%{_libdir}/systemd/system/ac.service
ln -s ../ac.service %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants/ac.service
-install -m0644 %SOURCE102 %{buildroot}%{_libdir}/systemd/system/launchpad-preload.service
-ln -s ../launchpad-preload.service %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants/launchpad-preload.service
mkdir -p %{buildroot}/usr/share/license
cp LICENSE %{buildroot}/usr/share/license/%{name}
+mkdir -p %{buildroot}/usr/share/appsvc
+cp -R %{_builddir}/%{name}-%{version}/res/arm/usr/share/appsvc/* %{buildroot}/usr/share/appsvc
+
%post
-vconftool set -t int db/setting/effect_image 1 -f -s system::vconf_inhouse
+/sbin/ldconfig
+mkdir -p /opt/dbspace
+sqlite3 /opt/dbspace/.appsvc.db < /opt/share/appsvc_db.sql
+rm -rf /opt/share/appsvc_db.sql
+
+chown 0:5000 /opt/dbspace/.appsvc.db
+chown 0:5000 /opt/dbspace/.appsvc.db-journal
+chmod 664 /opt/dbspace/.appsvc.db
+chmod 664 /opt/dbspace/.appsvc.db-journal
+chsmack -a 'app-svc::db' /opt/dbspace/.appsvc.db
+chsmack -a 'app-svc::db' /opt/dbspace/.appsvc.db-journal
+
+%postun -p /sbin/ldconfig
%files
%manifest aul.manifest
+/opt/share/appsvc_db.sql
%attr(0644,root,root) %{_libdir}/libaul.so.0
%attr(0644,root,root) %{_libdir}/libaul.so.0.1.0
%if 0%{?appfw_feature_default_fake_image}
%{_bindir}/aul_test
%{_bindir}/launch_app
%{_bindir}/open_app
+%{_bindir}/appgroup_info
+/usr/share/appsvc/*
/usr/share/aul/miregex/*
-/usr/share/aul/preload_list.txt
/usr/share/aul/preexec_list.txt
%if 0%{?appfw_feature_default_fake_image}
/usr/share/splash_images/*
%endif
-%{_bindir}/launchpad_preloading_preinitializing_daemon
+%if 0%{?appfw_feature_amd_module_log}
+%attr(0755,root,root) /opt/etc/dump.d/module.d/amd_log_dump.sh
+%endif
%{_bindir}/amd
-%{_bindir}/daemon-manager-release-agent
-%{_bindir}/daemon-manager-launch-agent
%{_libdir}/systemd/system/ac.service
%{_libdir}/systemd/system/multi-user.target.wants/ac.service
-%{_libdir}/systemd/system/launchpad-preload.service
-%{_libdir}/systemd/system/multi-user.target.wants/launchpad-preload.service
/usr/share/license/%{name}
+%{_datadir}/dbus-1/system-services/org.tizen.aul.delegator.service
+%{_libdir}/systemd/system/aul-delegator-server.service
+%{_bindir}/aul-delegator-server
+
%files devel
%{_includedir}/aul/*.h
%{_includedir}/aul/launch/*.h
[Unit]
Description=Start the Access Control server
-After=dbus.service vconf-setup.service ac.service
+Requires=xorg.service tizen-generate-env.service
+After=dbus.service vconf-setup.service ac.service xorg.service tizen-generate-env.service
[Service]
EnvironmentFile=/run/tizen-mobile-env
--- /dev/null
+# Alias
+[Alias]
+tizen.imageviewer=image-viewer-efl
+tizen.internet=org.tizen.browser
+tizen.phone=org.tizen.phone
+tizen.filemanager=org.tizen.myfile
+tizen.contacts=org.tizen.contacts
+tizen.call=org.tizen.call
+tizen.smsmessages=msg-composer-efl
+tizen.mmsmessages=msg-composer-efl
+tizen.messages=msg-composer-efl
+tizen.email=org.tizen.email
+tizen.calendar=org.tizen.calendar
+tizen.camera=org.tizen.camera-app
--- /dev/null
+#define _GNU_SOURCE
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <bundle_internal.h>
+#include "aul.h"
+#include "aul_api.h"
+#include "aul_util.h"
+#include "app_sock.h"
+#include "launch.h"
+#include "simple_util.h"
+
+SLPAPI int aul_app_group_get_window(int pid)
+{
+ int ret;
+ bundle *b;
+ char buf[128];
+
+ b = bundle_create();
+ snprintf(buf, 128, "%d", pid);
+ bundle_add_str(b, AUL_K_PID, buf);
+ ret = app_send_cmd(AUL_UTIL_PID, APP_GROUP_GET_WINDOW, b);
+ bundle_free(b);
+
+ return ret;
+}
+
+SLPAPI int aul_app_group_set_window(int wid)
+{
+ int ret;
+ bundle *b;
+ char buf[128];
+
+ b = bundle_create();
+ snprintf(buf, 128, "%d", wid);
+ bundle_add_str(b, AUL_K_WID, buf);
+ ret = app_send_cmd(AUL_UTIL_PID, APP_GROUP_SET_WINDOW, b);
+ bundle_free(b);
+
+ return ret;
+}
+
+SLPAPI void aul_app_group_get_leader_pids(int *cnt, int **pids)
+{
+ app_pkt_t *ret = NULL;
+ *cnt = 0;
+ *pids = NULL;
+
+ ret = __app_send_cmd_with_result(AUL_UTIL_PID, APP_GROUP_GET_LEADER_PIDS,
+ NULL, 0);
+ if (ret != NULL) {
+ *cnt = ret->len / sizeof(int);
+ if (ret->len > 0 && ret->len <= AUL_SOCK_MAXBUFF - 8) {
+ *pids = malloc(ret->len);
+ if (*pids == NULL) {
+ _E("out of memory");
+ free(ret);
+ return;
+ }
+
+ memcpy(*pids, ret->data, ret->len);
+ }
+ free(ret);
+ }
+
+}
+
+SLPAPI void aul_app_group_get_group_pids(int leader_pid, int *cnt, int **pids)
+{
+ app_pkt_t *ret = NULL;
+ bundle *b;
+ bundle_raw *br;
+ int datalen;
+ char buf[128];
+ *cnt = 0;
+ *pids = NULL;
+
+ b = bundle_create();
+ snprintf(buf, 128, "%d", leader_pid);
+ bundle_add_str(b, AUL_K_LEADER_PID, buf);
+
+ bundle_encode(b, &br, &datalen);
+ ret = __app_send_cmd_with_result(AUL_UTIL_PID, APP_GROUP_GET_GROUP_PIDS, br,
+ datalen);
+
+ if (ret != NULL) {
+ *cnt = ret->len / sizeof(int);
+ if (ret->len > 0 && ret->len <= AUL_SOCK_MAXBUFF - 8) {
+ *pids = malloc(ret->len);
+ if (*pids == NULL) {
+ _E("out of memory");
+ free(br);
+ bundle_free(b);
+ free(ret);
+ return;
+ }
+
+ memcpy(*pids, ret->data, ret->len);
+ }
+ free(ret);
+ }
+
+ free(br);
+ bundle_free(b);
+}
+
+SLPAPI int aul_app_group_get_leader_pid(int pid)
+{
+ int ret;
+ bundle *b;
+ char buf[128];
+
+ b = bundle_create();
+ snprintf(buf, 128, "%d", pid);
+ bundle_add_str(b, AUL_K_PID, buf);
+ ret = app_send_cmd(AUL_UTIL_PID, APP_GROUP_GET_LEADER_PID, b);
+ bundle_free(b);
+
+ return ret;
+}
+
+SLPAPI int aul_app_group_clear_top(void)
+{
+ unsigned char dummy[1] = { 0 };
+ return __app_send_raw(AUL_UTIL_PID, APP_GROUP_CLEAR_TOP, dummy, 0);
+}
+
+SLPAPI int aul_app_group_is_top(void)
+{
+ int lpid = aul_app_group_get_leader_pid(getpid());
+
+ if (lpid > 0) {
+ int cnt;
+ int *pids = NULL;
+ aul_app_group_get_group_pids(lpid, &cnt, &pids);
+ if (cnt > 0) {
+ if (pids[cnt-1] == getpid()) {
+ free(pids);
+ return 1;
+ }
+
+ free(pids);
+ return 0;
+ }
+ }
+
+ return 1;
+}
+
+SLPAPI int aul_app_group_get_fg_flag(int pid)
+{
+ int ret;
+ bundle *b;
+ char buf[128];
+
+ b = bundle_create();
+ snprintf(buf, 128, "%d", pid);
+ bundle_add_str(b, AUL_K_PID, buf);
+ ret = app_send_cmd(AUL_UTIL_PID, APP_GROUP_GET_FG, b);
+ bundle_free(b);
+
+ return ret;
+}
+
+SLPAPI void aul_app_group_lower(int *exit)
+{
+ int ret;
+ unsigned char dummy[1] = { 0 };
+ ret = __app_send_raw(AUL_UTIL_PID, APP_GROUP_LOWER, dummy, 0);
+ *exit = ret;
+}
+
+SLPAPI void aul_app_group_get_idle_pids(int *cnt, int **pids)
+{
+ app_pkt_t *ret = NULL;
+ *cnt = 0;
+ *pids = NULL;
+
+ ret = __app_send_cmd_with_result(AUL_UTIL_PID, APP_GROUP_GET_IDLE_PIDS,
+ NULL, 0);
+ if (ret != NULL) {
+ *cnt = ret->len / sizeof(int);
+ if (ret->len > 0 && ret->len <= AUL_SOCK_MAXBUFF - 8) {
+ *pids = malloc(ret->len);
+ if (*pids == NULL) {
+ _E("out of memory");
+ free(ret);
+ return;
+ }
+
+ memcpy(*pids, ret->data, ret->len);
+ }
+ free(ret);
+ }
+}
+
*
*/
-
+#define _GNU_SOURCE
#include <stdio.h>
+#include <dbus/dbus-glib-lowlevel.h>
#include "app_signal.h"
#include "aul_api.h"
static int (*_cooldown_handler) (const char *cooldown_status, void *data);
static void *_cooldown_data;
-#ifdef _APPFW_FEATURE_VISIBILITY_CHECK_BY_LCD_STATUS
-static int (*_lcd_status_handler) (const char *lcd_status, void *data);
-static void *_lcd_status_data;
-#endif
-
static DBusConnection *bus;
static int app_dbus_signal_handler_initialized = 0;
+DBusError err;
+DBusConnection* conn = NULL;
+
static DBusHandlerResult
__app_dbus_signal_filter(DBusConnection *conn, DBusMessage *message,
void *user_data)
if (_cooldown_handler)
_cooldown_handler(cooldown_status, _cooldown_data);
}
-#ifdef _APPFW_FEATURE_VISIBILITY_CHECK_BY_LCD_STATUS
- else if (dbus_message_is_signal(
- message, interface, DEVICED_SIGNAL_LCD_ON)) {
- if (_lcd_status_handler)
- _lcd_status_handler(DEVICED_SIGNAL_LCD_ON, _lcd_status_data);
- } else if (dbus_message_is_signal(
- message, interface, DEVICED_SIGNAL_LCD_OFF)) {
- if (_lcd_status_handler)
- _lcd_status_handler(DEVICED_SIGNAL_LCD_OFF, _lcd_status_data);
- }
-#endif
return DBUS_HANDLER_RESULT_HANDLED;
}
-int __app_dbus_signal_handler_init(void)
-{
- int ret = 0;
-
- if (app_dbus_signal_handler_initialized)
- return 0;
-
- ret = __app_dbus_signal_handler_init_with_param(AUL_DBUS_PATH, AUL_DBUS_SIGNAL_INTERFACE);
-
- app_dbus_signal_handler_initialized = 1;
-
- return ret;
-}
-
-int __app_dbus_signal_handler_init_with_param(const char* path, const char* interface)
+static int __app_dbus_signal_handler_init_with_param(const char* path, const char* interface)
{
DBusError error;
char rule[MAX_LOCAL_BUFSZ];
return -1;
}
- if (dbus_connection_add_filter(bus,
+ if (dbus_connection_add_filter(bus,
__app_dbus_signal_filter, NULL, NULL) == FALSE) {
_E("add filter fail");
return -1;
return 0;
}
-int __app_dbus_signal_handler_fini(void)
+static int __app_dbus_signal_handler_init(void)
{
int ret = 0;
- if (!app_dbus_signal_handler_initialized)
+ if (app_dbus_signal_handler_initialized)
return 0;
- ret = __app_dbus_signal_handler_fini_with_param(AUL_DBUS_PATH, AUL_DBUS_SIGNAL_INTERFACE);
+ ret = __app_dbus_signal_handler_init_with_param(AUL_DBUS_PATH, AUL_DBUS_SIGNAL_INTERFACE);
- app_dbus_signal_handler_initialized = 0;
+ app_dbus_signal_handler_initialized = 1;
return ret;
}
-int __app_dbus_signal_handler_fini_with_param(const char* path, const char* interface)
+static int __app_dbus_signal_handler_fini_with_param(const char* path, const char* interface)
{
DBusError error;
char rule[MAX_LOCAL_BUFSZ];
return 0;
}
+static int __app_dbus_signal_handler_fini(void)
+{
+ int ret = 0;
+
+ if (!app_dbus_signal_handler_initialized)
+ return 0;
+
+ ret = __app_dbus_signal_handler_fini_with_param(AUL_DBUS_PATH, AUL_DBUS_SIGNAL_INTERFACE);
+
+ app_dbus_signal_handler_initialized = 0;
+
+ return ret;
+}
+
SLPAPI int aul_listen_app_dead_signal(int (*func) (int, void *), void *data)
{
if (func) {
return AUL_R_OK;
}
-#ifdef _APPFW_FEATURE_VISIBILITY_CHECK_BY_LCD_STATUS
-SLPAPI int aul_listen_lcd_status_signal(int (*func) (const char *, void *), void *data)
-{
- if (func) {
- if (__app_dbus_signal_handler_init_with_param(DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY) < 0) {
- _E("error app signal init");
- return AUL_R_ERROR;
- }
- }
- _lcd_status_handler = func;
- _lcd_status_data = data;
-
- return AUL_R_OK;
-}
-#endif
-
SLPAPI int aul_update_freezer_status(int pid, const char* type)
{
DBusError err;
dbus_error_init(&err);
+ _W("send_update_freezer_status, pid: %d, type: %s", pid, type);
+
conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
if (!conn) {
_E("Fail to dbus_bus_get : %s", err.message);
ret = -1;
}
- _D("Send a freezer signal pid: %d, type: %s", pid, type);
-
if (!dbus_connection_send(conn, msg, &serial)) {
_E("Failed to send a D-Bus Message.");
ret = -1;
}
+int __app_status_dbus_init(void)
+{
+ int ret = 0;
+
+ if (conn)
+ return 0;
+
+ dbus_error_init(&err);
+ conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
+
+ return ret;
+}
+
+SLPAPI int aul_send_app_launch_request_signal(int pid, const char* appid, const char* pkgid, const char* type)
+{
+ DBusMessage* msg = NULL;
+ dbus_uint32_t serial = 0;
+
+ int ret = -1;
+
+ __app_status_dbus_init();
+
+ _W("send_app_launch_signal, pid: %d, appid: %s", pid, appid);
+
+ msg = dbus_message_new_signal(AUL_APP_STATUS_DBUS_PATH,
+ AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE,
+ AUL_APP_STATUS_DBUS_LAUNCH_REQUEST);
+ if (!msg) {
+ _E("Could not create DBus Message.");
+ ret = -1;
+ goto end;
+ }
+
+ if (!dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_STRING, &appid,
+ DBUS_TYPE_STRING, &pkgid,
+ DBUS_TYPE_STRING, &type,
+ DBUS_TYPE_INVALID)) {
+ _E("Failed to append a D-Bus Message.");
+ ret = -1;
+ }
+
+ if (!dbus_connection_send(conn, msg, &serial)) {
+ _E("Failed to send a D-Bus Message.");
+ ret = -1;
+ }
+
+ dbus_connection_flush(conn);
+
+end:
+ if (msg) {
+ dbus_message_unref(msg);
+ }
+ return ret;
+}
+
+SLPAPI int aul_send_app_resume_request_signal(int pid, const char* appid, const char* pkgid, const char* type)
+{
+ DBusMessage* msg = NULL;
+ dbus_uint32_t serial = 0;
+ const char *empty_string = "";
+
+ int ret = -1;
+
+ __app_status_dbus_init();
+
+ _W("send_app_resume_signal, pid: %d, appid: %s", pid, appid);
+
+ msg = dbus_message_new_signal(AUL_APP_STATUS_DBUS_PATH,
+ AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE,
+ AUL_APP_STATUS_DBUS_RESUME_REQUEST);
+ if (!msg) {
+ _E("Could not create DBus Message.");
+ ret = -1;
+ goto end;
+ }
+
+ if(appid) {
+ if (!dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_STRING, &appid,
+ DBUS_TYPE_STRING, &pkgid,
+ DBUS_TYPE_STRING, &type,
+ DBUS_TYPE_INVALID)) {
+ _E("Failed to append a D-Bus Message.");
+ ret = -1;
+ }
+ } else {
+ if (!dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_STRING, &empty_string,
+ DBUS_TYPE_STRING, &empty_string,
+ DBUS_TYPE_STRING, &empty_string,
+ DBUS_TYPE_INVALID)) {
+ _E("Failed to append a D-Bus Message.");
+ ret = -1;
+ }
+ }
+
+ if (!dbus_connection_send(conn, msg, &serial)) {
+ _E("Failed to send a D-Bus Message.");
+ ret = -1;
+ }
+
+ dbus_connection_flush(conn);
+
+end:
+ if (msg) {
+ dbus_message_unref(msg);
+ }
+
+ return ret;
+}
+
+SLPAPI int aul_send_app_terminate_request_signal(int pid, const char* appid, const char* pkgid, const char *type)
+{
+ DBusMessage* msg = NULL;
+ dbus_uint32_t serial = 0;
+ const char *empty_string = "";
+
+ int ret = -1;
+
+ __app_status_dbus_init();
+
+ msg = dbus_message_new_signal(AUL_APP_STATUS_DBUS_PATH,
+ AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE,
+ AUL_APP_STATUS_DBUS_TERMINATE_REQUEST);
+ if (!msg) {
+ _E("Could not create DBus Message.");
+ ret = -1;
+ goto end;
+ }
+
+ if(appid) {
+ if (!dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_STRING, &appid,
+ DBUS_TYPE_STRING, &pkgid,
+ DBUS_TYPE_STRING, &type,
+ DBUS_TYPE_INVALID)) {
+ _E("Failed to append a D-Bus Message.");
+ ret = -1;
+ }
+ } else {
+ if (!dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_STRING, &empty_string,
+ DBUS_TYPE_STRING, &empty_string,
+ DBUS_TYPE_STRING, &empty_string,
+ DBUS_TYPE_INVALID)) {
+ _E("Failed to append a D-Bus Message.");
+ ret = -1;
+ }
+ }
+
+ if (!dbus_connection_send(conn, msg, &serial)) {
+ _E("Failed to send a D-Bus Message.");
+ ret = -1;
+ }
+
+ dbus_connection_flush(conn);
+
+end:
+ if (msg) {
+ dbus_message_unref(msg);
+ }
+
+ return ret;
+
+}
+
+SLPAPI int aul_send_app_status_change_signal(int pid, const char* appid, const char* pkgid, const char* status, const char *type)
+{
+ DBusMessage* msg = NULL;
+ dbus_uint32_t serial = 0;
+ const char *empty_string = "";
+
+ int ret = -1;
+
+ _W("send_app_status_change_signal, pid: %d, appid: %s, status: %s", pid, appid, status);
+
+ __app_status_dbus_init();
+
+ msg = dbus_message_new_signal(AUL_APP_STATUS_DBUS_PATH,
+ AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE,
+ AUL_APP_STATUS_DBUS_STATUS_CHANGE);
+ if (!msg) {
+ _E("Could not create DBus Message.");
+ ret = -1;
+ goto end;
+ }
+
+ if(appid) {
+ if (!dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_STRING, &appid,
+ DBUS_TYPE_STRING, &pkgid,
+ DBUS_TYPE_STRING, &status,
+ DBUS_TYPE_STRING, &type,
+ DBUS_TYPE_INVALID)) {
+ _E("Failed to append a D-Bus Message.");
+ ret = -1;
+ }
+ } else {
+ if (!dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_STRING, &empty_string,
+ DBUS_TYPE_STRING, &empty_string,
+ DBUS_TYPE_STRING, &status,
+ DBUS_TYPE_STRING, &type,
+ DBUS_TYPE_INVALID)) {
+ _E("Failed to append a D-Bus Message.");
+ ret = -1;
+ }
+ }
+
+ if (!dbus_connection_send(conn, msg, &serial)) {
+ _E("Failed to send a D-Bus Message.");
+ ret = -1;
+ }
+
+ dbus_connection_flush(conn);
+
+end:
+ if (msg) {
+ dbus_message_unref(msg);
+ }
+
+ return ret;
+}
+
+SLPAPI int aul_send_app_terminated_signal(int pid)
+{
+ DBusMessage* msg = NULL;
+ dbus_uint32_t serial = 0;
+
+ int ret = -1;
+
+ __app_status_dbus_init();
+
+ msg = dbus_message_new_signal(AUL_APP_STATUS_DBUS_PATH,
+ AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE,
+ AUL_APP_STATUS_DBUS_TERMINATED);
+ if (!msg) {
+ _E("Could not create DBus Message.");
+ ret = -1;
+ goto end;
+ }
+
+ if (!dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_INVALID)) {
+ _E("Failed to append a D-Bus Message.");
+ ret = -1;
+ }
+
+ if (!dbus_connection_send(conn, msg, &serial)) {
+ _E("Failed to send a D-Bus Message.");
+ ret = -1;
+ }
+
+ dbus_connection_flush(conn);
+
+end:
+ if (msg) {
+ dbus_message_unref(msg);
+ }
+ return ret;
+}
+
+SLPAPI int aul_send_app_group_signal(int owner_pid, int child_pid, const char *child_pkgid)
+{
+ DBusMessage* msg = NULL;
+ dbus_uint32_t serial = 0;
+ const char *empty_string = "";
+
+ int ret = -1;
+
+ _W("send_app_group_signal, owner: %d, child: %d", owner_pid, child_pid);
+
+ __app_status_dbus_init();
+
+ msg = dbus_message_new_signal(AUL_APP_STATUS_DBUS_PATH,
+ AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE,
+ AUL_APP_STATUS_DBUS_GROUP);
+ if (!msg) {
+ _E("Could not create DBus Message.");
+ ret = -1;
+ goto end;
+ }
+
+ if (child_pkgid) {
+ if (!dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &owner_pid,
+ DBUS_TYPE_INT32, &child_pid,
+ DBUS_TYPE_STRING, &child_pkgid,
+ DBUS_TYPE_INVALID)) {
+ _E("Failed to append a D-Bus Message.");
+ ret = -1;
+ }
+ } else {
+ if (!dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &owner_pid,
+ DBUS_TYPE_INT32, &child_pid,
+ DBUS_TYPE_STRING, &empty_string,
+ DBUS_TYPE_INVALID)) {
+ _E("Failed to append a D-Bus Message.");
+ ret = -1;
+ }
+ }
+
+ if (!dbus_connection_send(conn, msg, &serial)) {
+ _E("Failed to send a D-Bus Message.");
+ ret = -1;
+ }
+
+ dbus_connection_flush(conn);
+
+end:
+ if (msg) {
+ dbus_message_unref(msg);
+ }
+
+ return ret;
+}
*
*/
-
+#define _GNU_SOURCE
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
static int __connect_client_sock(int sockfd, const struct sockaddr *saptr, socklen_t salen,
int nsec);
+char *_socket_prefix = NULL;
+char *_root_path = NULL;
+char *_cur_zone = NULL;
+int _pid_offset = 0;
+
+const char* _get_sock_prefix()
+{
+ if (_socket_prefix == NULL)
+ return "/tmp/alaunch";
+
+ return _socket_prefix;
+}
+
+const char* _get_root_path()
+{
+ if (_root_path == NULL)
+ return "/";
+
+ return _root_path;
+}
static inline void __set_sock_option(int fd, int cli)
{
(void) mkdir(AUL_SOCK_PREFIX, S_IRWXU | S_IRWXG | S_IRWXO | S_ISVTX);
umask(orig_mask);
- fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
+ fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
/* support above version 2.6.27*/
if (fd < 0) {
if (errno == EINVAL) {
}
/* support app launched by shell script */
- if (pid != LAUNCHPAD_PID) {
+ if (pid > 0 || pid == WEB_LAUNCHPAD_PID) {
int pgid;
pgid = getpgid(pid);
if (pgid > 1) {
if ((*clifd = accept(fd, (struct sockaddr *)&aul_addr,
(socklen_t *) &sun_size)) == -1) {
- if (errno != EINTR)
+ if (errno != EINTR && errno != EAGAIN && errno != EWOULDBLOCK)
_E("accept error: %d", errno);
return NULL;
}
(socklen_t *) &cl) < 0) {
_E("peer information error");
close(*clifd);
+ *clifd = -1;
return NULL;
}
pkt = (app_pkt_t *) malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
if(pkt == NULL) {
close(*clifd);
+ *clifd = -1;
return NULL;
}
memset(pkt, 0, AUL_SOCK_MAXBUFF);
_E("recv error %d %d", len, pkt->len);
free(pkt);
close(*clifd);
+ *clifd = -1;
return NULL;
}
_E("package length error (%d)", pkt->len);
free(pkt);
close(*clifd);
+ *clifd = -1;
return NULL;
}
while (len < (pkt->len + pkt_header_size)) {
ret = recv(*clifd, &pkt->data[len - pkt_header_size],
(pkt->len + pkt_header_size) - len, 0);
- if (ret <= 0) { /* ret may be 0 when the peer has performed an orderly shutdown */
+ if (ret < 0) {
_E("recv error: %d %d %d", errno, len, pkt->len);
free(pkt);
close(*clifd);
+ *clifd = -1;
return NULL;
}
len += ret;
*
*/
+#define _GNU_SOURCE
#include <unistd.h>
#include <linux/limits.h>
#include <assert.h>
#include <pkgmgr-info.h>
+#include <pkgmgrinfo_zone.h>
#include "aul_api.h"
#include "aul_util.h"
#include "simple_util.h"
#include "aul.h"
+#include "aul_zone.h"
#define _MAX_PACKAGE_ID_LEN 256
#define _MAX_BASE_PATH_LEN 512
static const char _EXTERNAL_APP_SPECIFIC_PATH[] = "/opt/storage/sdcard/apps/";
static const char _APP_SPECIFIC_PATH[] = "/opt/usr/apps/";
+static const char _PRELOADED_APP_SPECIFIC_PATH[] = "/usr/apps/";
static const char _DATA_DIR[] = "data/";
static const char _CACHE_DIR[] = "cache/";
static const char _RESOURCE_DIR[] = "res/";
+static const char _TEP_RESOURCE_DIR[] = "res/tep/";
static const char _SHARED_DATA_DIR[] = "shared/data/";
static const char _SHARED_TRUSTED_DIR[] = "shared/trusted/";
static const char _SHARED_RESOURCE_DIR[] = "shared/res/";
+static char external_root_path[_MAX_BASE_PATH_LEN] = {0,};
+static char root_path[_MAX_BASE_PATH_LEN] = {0,};
+static char data_path[_MAX_BASE_PATH_LEN] = {0,};
+static char cache_path[_MAX_BASE_PATH_LEN] = {0,};
+static char resource_path[_MAX_BASE_PATH_LEN] = {0,};
+static char tep_resource_path[_MAX_BASE_PATH_LEN] = {0,};
+static char shared_data_path[_MAX_BASE_PATH_LEN] = {0,};
+static char shared_resource_path[_MAX_BASE_PATH_LEN] = {0,};
+static char shared_trusted_path[_MAX_BASE_PATH_LEN] = {0,};
+static char external_data_path[_MAX_BASE_PATH_LEN] = {0,};
+static char external_cache_path[_MAX_BASE_PATH_LEN] = {0,};
+static char external_shared_data_path[_MAX_BASE_PATH_LEN] = {0,};
+static char pkgid[_MAX_PACKAGE_ID_LEN] = {0,};
+
static int __get_pkgid_by_appid(char *pkgid, int pkgid_len, const char *appid)
{
pkgmgrinfo_appinfo_h handle = NULL;
// get pkginfo handle
int err = pkgmgrinfo_appinfo_get_appinfo(appid, &handle);
- if (err != PMINFO_R_OK)
- {
+ if (err != PMINFO_R_OK) {
_E("Failed to get app info. (err:%d)", err);
return AUL_R_ENOAPP;
}
// get and set pkgid
err = pkgmgrinfo_appinfo_get_pkgid(handle, &tmp_pkgid);
- if (err != PMINFO_R_OK)
- {
+ if (err != PMINFO_R_OK) {
_E("Failed to get pkgid. (err:%d)", err);
pkgmgrinfo_appinfo_destroy_appinfo(handle);
return AUL_R_ENOAPP;
}
-
- strncat(pkgid, tmp_pkgid, pkgid_len);
+ strncpy(pkgid, tmp_pkgid, pkgid_len);
pkgmgrinfo_appinfo_destroy_appinfo(handle);
return AUL_R_OK;
static int __get_pkgid(char* pkgid, int pkgid_len)
{
char appid[_MAX_PACKAGE_ID_LEN] = {0,};
+ const char *preinit_pkgid = NULL;
+
+ preinit_pkgid = aul_get_preinit_pkgid();
+ if (preinit_pkgid != NULL) {
+ strncpy(pkgid, preinit_pkgid, pkgid_len);
+ return AUL_R_OK;
+ }
// get appid
int err = aul_app_get_appid_bypid(getpid(), appid, _MAX_PACKAGE_ID_LEN - 1);
- if (err != AUL_R_OK)
- {
+ if (err != AUL_R_OK) {
_E("Failed to get appid. (err:%d)", err);
return err;
}
return __get_pkgid_by_appid(pkgid, pkgid_len, appid);
}
-static int __get_root_path(char *root_path, int root_path_len, bool external)
+static const char* __get_app_specific_path(const char *pkgid)
{
- static char pkgid[_MAX_PACKAGE_ID_LEN] = {0,};
- const char *specific_path = external ? _EXTERNAL_APP_SPECIFIC_PATH : _APP_SPECIFIC_PATH;
+ pkgmgrinfo_pkginfo_h handle;
+ int ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
+ if (ret != PMINFO_R_OK)
+ return NULL;
+
+ bool preload;
+ ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
+ if (ret != PMINFO_R_OK) {
+ pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+ return NULL;
+ }
- if (pkgid[0] == '\0')
- {
- int err = __get_pkgid(pkgid, _MAX_PACKAGE_ID_LEN - 1);
- if (err != AUL_R_OK)
- {
- return err;
- }
+ pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+
+ if (preload) {
+ return _PRELOADED_APP_SPECIFIC_PATH;
}
- {
- int specific_path_len = strlen(specific_path);
- int pkgid_len = strlen(pkgid);
- int total_len = specific_path_len + pkgid_len + 1;
- if (total_len > root_path_len)
- {
- _E("Assert: path length %d is too long", total_len);
- assert(false);
+ return _APP_SPECIFIC_PATH;
+}
+
+static int __get_root_path(char *root_path, int root_path_len, bool external,
+ bool can_write)
+{
+ char pkgid[_MAX_PACKAGE_ID_LEN] = {0,};
+ const char *specific_path = NULL;
+
+ int err = __get_pkgid(pkgid, _MAX_PACKAGE_ID_LEN - 1);
+ if (err != AUL_R_OK) {
+ return err;
+ }
+
+ if (can_write)
+ specific_path = external ? _EXTERNAL_APP_SPECIFIC_PATH : _APP_SPECIFIC_PATH;
+ else {
+ specific_path = external ? _EXTERNAL_APP_SPECIFIC_PATH : __get_app_specific_path(pkgid);
+ if (specific_path == NULL) {
+ _E("out of memory");
+ return AUL_R_ERROR;
}
+ }
- strncat(root_path, specific_path, specific_path_len);
- strncat(root_path + specific_path_len, pkgid, pkgid_len);
- root_path[specific_path_len + pkgid_len] = '/';
+ int specific_path_len = strlen(specific_path);
+ int pkgid_len = strlen(pkgid);
+ int total_len = specific_path_len + pkgid_len + 1;
+
+ if (total_len > root_path_len) {
+ _E("Assert: path length %d is too long", total_len);
+ assert(false);
}
+ strncat(root_path, specific_path, specific_path_len);
+ strncat(root_path + specific_path_len, pkgid, pkgid_len);
+ root_path[specific_path_len + pkgid_len] = '/';
+ root_path[specific_path_len + pkgid_len + 1] = '\0';
+
return AUL_R_OK;
}
-static int __get_path(char *path, int path_len, const char *dir_name, bool external)
+static char* __get_base_path(bool can_write)
{
+ static char base_path[_MAX_BASE_PATH_LEN] = {0,};
+
+ base_path[0] = '\0';
+ if (__get_root_path(base_path, _MAX_BASE_PATH_LEN - 1, false,
+ can_write) != AUL_R_OK)
+ return NULL;
+
+ return base_path;
+}
+
+static int __get_path(char *path, int path_len, const char *dir_name,
+ bool external, bool can_write)
+{
+ char* root_path = NULL;
+ pkgmgrinfo_pkginfo_h pkginfo = NULL;
+ int is_res = 0;
+
if (dir_name == NULL)
{
_E("Assert: dir name is NULL!");
assert(false);
}
+ else if (strncmp(dir_name, _RESOURCE_DIR, strlen(_RESOURCE_DIR)) == 0 ||
+ strncmp(dir_name, _SHARED_RESOURCE_DIR, strlen(_SHARED_RESOURCE_DIR)) == 0)
{
- const char *root_path = external ? aul_get_app_external_root_path() : aul_get_app_root_path();
- if (root_path == NULL)
+ char pkgid[_MAX_PACKAGE_ID_LEN] = {0,};
+ if (__get_pkgid(pkgid, _MAX_PACKAGE_ID_LEN - 1) != AUL_R_OK)
+ {
+ _E("Assert: failed to get the package id!");
+ assert(false);
+ }
+
+ if (pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &pkginfo) != PMINFO_R_OK)
{
+ _E("Failed to get the package info from pkgid!");
return AUL_R_ERROR;
}
- else
+
+ if (pkgmgrinfo_pkginfo_get_root_path(pkginfo, &root_path) != PMINFO_R_OK)
+ {
+ _E("Failed to get the root path from pkginfo!");
+ pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
+ return AUL_R_ERROR;
+ }
+
+ is_res = 1;
+ }
+ else
+ {
+ root_path = (char *) (external ? aul_get_app_external_root_path() :
+ __get_base_path(can_write));
+ if (root_path == NULL)
{
- int dir_name_len = strlen(dir_name);
- int root_path_len = strlen(root_path);
- int total_len = root_path_len + dir_name_len;
-
- if (total_len > path_len)
- {
- _E("Assert: path length %d is too long", total_len);
- assert(false);
- }
-
- strncpy(path, root_path, root_path_len);
- strncpy(path + root_path_len, dir_name, dir_name_len);
+ _E("root_path is NULL!");
+ return AUL_R_ERROR;
}
}
+ int dir_name_len = strlen(dir_name);
+ int root_path_len = strlen(root_path);
+ int total_len = root_path_len + dir_name_len;
+
+ if (total_len > path_len)
+ {
+ _E("Assert: path length %d is too long", total_len);
+ assert(false);
+ }
+
+ strncpy(path, root_path, root_path_len);
+ if (is_res)
+ {
+ strncat(path, "/", 1);
+ ++root_path_len;
+ }
+ strncpy(path + root_path_len, dir_name, dir_name_len);
+
+ if (pkginfo != NULL)
+ {
+ pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
+ }
+
return AUL_R_OK;
}
-static int __get_path_by_appid(char **path, const char *appid, const char *dir_name, bool external)
+static int __get_path_by_appid(char **path, const char *appid,
+ const char *dir_name, bool external)
{
- if (dir_name == NULL)
- {
+ if (dir_name == NULL) {
_E("Assert: dir name is NULL!");
assert(false);
}
- if (path == NULL || appid == NULL)
- {
+ if (path == NULL || appid == NULL) {
return AUL_R_EINVAL;
}
- {
- char pkgid[_MAX_PACKAGE_ID_LEN] = {0,};
- int err = __get_pkgid_by_appid(pkgid, _MAX_PACKAGE_ID_LEN - 1, appid);
- if (err != AUL_R_OK)
- {
- return err;
+ pkgmgrinfo_pkginfo_h pkginfo = NULL;
+ char *specific_path = NULL;
+ int total_len = 0;
+
+ char pkgid[_MAX_PACKAGE_ID_LEN] = {0,};
+ int err = __get_pkgid_by_appid(pkgid, _MAX_PACKAGE_ID_LEN - 1, appid);
+ if (err != AUL_R_OK) {
+ return err;
+ }
+
+ if (strncmp(dir_name, _RESOURCE_DIR, strlen(_RESOURCE_DIR)) == 0 ||
+ strncmp(dir_name, _SHARED_RESOURCE_DIR, strlen(_SHARED_RESOURCE_DIR)) == 0) {
+ if (pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &pkginfo) != PMINFO_R_OK) {
+ _E("Failed to get the package info from pkgid!");
+ return AUL_R_ERROR;
}
- {
- const char *specific_path = external ? _EXTERNAL_APP_SPECIFIC_PATH : _APP_SPECIFIC_PATH;
- int specific_path_len = strlen(specific_path);
- int pkgid_len = strlen(pkgid);
- int dir_name_len = strlen(dir_name);
- int total_len = specific_path_len + pkgid_len + 1 + dir_name_len;
-
- if (total_len > _MAX_BASE_PATH_LEN - 1)
- {
- _E("Assert: path length %d is too long", total_len);
- assert(false);
- }
-
- *path = (char *)calloc(total_len + 1, sizeof(char));
- if (*path == NULL)
- {
- return AUL_R_ERROR;
- }
-
- snprintf(*path, total_len + 1, "%s%s/%s", specific_path, pkgid, dir_name);
+
+ if (pkgmgrinfo_pkginfo_get_root_path(pkginfo, &specific_path) != PMINFO_R_OK) {
+ _E("Failed to get the root path from pkginfo!");
+ pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
+ return AUL_R_ERROR;
}
+
+ total_len = strlen(specific_path) + strlen(dir_name) + 1;
+
+ } else {
+ specific_path = (char *) (external ? _EXTERNAL_APP_SPECIFIC_PATH : _APP_SPECIFIC_PATH);
+ total_len = strlen(specific_path) + strlen(pkgid) + 1 + strlen(dir_name);
+ }
+
+ if (total_len > _MAX_BASE_PATH_LEN - 1) {
+ _E("Assert: path length %d is too long", total_len);
+ assert(false);
+ }
+
+ *path = (char *)calloc(total_len + 1, sizeof(char));
+ if (*path == NULL) {
+ pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
+ return AUL_R_ERROR;
+ }
+
+ if (pkginfo != NULL) {
+ snprintf(*path, total_len + 1, "%s/%s", specific_path, dir_name);
+ pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
+ } else {
+ snprintf(*path, total_len + 1, "%s%s/%s", specific_path, pkgid, dir_name);
}
return AUL_R_OK;
}
+void _clear_path_cache(void)
+{
+ external_root_path[0] = '\0';
+ root_path[0] = '\0';
+ data_path[0] = '\0';
+ cache_path[0] = '\0';
+ resource_path[0] = '\0';
+ shared_data_path[0] = '\0';
+ shared_resource_path[0] = '\0';
+ shared_trusted_path[0] = '\0';
+ external_data_path[0] = '\0';
+ external_cache_path[0] = '\0';
+ external_shared_data_path[0] = '\0';
+ pkgid[0] = '\0';
+}
+
SLPAPI const char *aul_get_app_external_root_path(void)
{
- static char external_root_path[_MAX_BASE_PATH_LEN] = {0,};
- if (external_root_path[0] == '\0')
- {
- if (__get_root_path(external_root_path, _MAX_BASE_PATH_LEN - 1, true) != AUL_R_OK)
- {
+ if (external_root_path[0] == '\0') {
+ char oldZone[64] = { 0, };
+
+ pkgmgrinfo_pkginfo_set_zone(_cur_zone, oldZone, 64);
+ int ret = __get_root_path(external_root_path, _MAX_BASE_PATH_LEN - 1, true,
+ false);
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
+ if (ret != AUL_R_OK)
return NULL;
- }
}
+
return external_root_path;
}
SLPAPI const char *aul_get_app_root_path(void)
{
- static char root_path[_MAX_BASE_PATH_LEN] = {0,};
- if (root_path[0] == '\0')
- {
- if (__get_root_path(root_path, _MAX_BASE_PATH_LEN - 1, false) != AUL_R_OK)
- {
+ if (root_path[0] == '\0') {
+ char oldZone[64] = { 0, };
+
+ pkgmgrinfo_pkginfo_set_zone(_cur_zone, oldZone, 64);
+ int ret = __get_root_path(root_path, _MAX_BASE_PATH_LEN - 1, false, false);
+
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
+
+ if ( ret != AUL_R_OK)
return NULL;
- }
}
return root_path;
}
SLPAPI const char *aul_get_app_data_path(void)
{
- static char data_path[_MAX_BASE_PATH_LEN] = {0,};
- if (data_path[0] == '\0')
- {
- if (__get_path(data_path, _MAX_BASE_PATH_LEN - 1, _DATA_DIR, false) != AUL_R_OK)
- {
+ if (data_path[0] == '\0') {
+ char oldZone[64] = { 0, };
+
+ pkgmgrinfo_pkginfo_set_zone(_cur_zone, oldZone, 64);
+ int ret = __get_path(data_path, _MAX_BASE_PATH_LEN - 1, _DATA_DIR, false, true);
+
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
+
+ if ( ret != AUL_R_OK)
return NULL;
- }
}
return data_path;
}
SLPAPI const char *aul_get_app_cache_path(void)
{
- static char cache_path[_MAX_BASE_PATH_LEN] = {0,};
- if (cache_path[0] == '\0')
- {
- if (__get_path(cache_path, _MAX_BASE_PATH_LEN - 1, _CACHE_DIR, false) != AUL_R_OK)
- {
+ if (cache_path[0] == '\0') {
+ char oldZone[64] = { 0, };
+
+ pkgmgrinfo_pkginfo_set_zone(_cur_zone, oldZone, 64);
+ int ret = __get_path(cache_path, _MAX_BASE_PATH_LEN - 1, _CACHE_DIR, false,
+ true);
+
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
+
+ if ( ret != AUL_R_OK)
return NULL;
- }
}
return cache_path;
}
SLPAPI const char *aul_get_app_resource_path(void)
{
- static char resource_path[_MAX_BASE_PATH_LEN] = {0,};
- if (resource_path[0] == '\0')
- {
- if (__get_path(resource_path, _MAX_BASE_PATH_LEN - 1, _RESOURCE_DIR, false) != AUL_R_OK)
- {
+ if (resource_path[0] == '\0') {
+ char oldZone[64] = { 0, };
+
+ pkgmgrinfo_pkginfo_set_zone(_cur_zone, oldZone, 64);
+ int ret = __get_path(resource_path, _MAX_BASE_PATH_LEN - 1, _RESOURCE_DIR,
+ false,
+ false);
+
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
+
+ if ( ret != AUL_R_OK)
return NULL;
- }
}
return resource_path;
}
+SLPAPI const char *aul_get_app_tep_resource_path(void)
+{
+ if (tep_resource_path[0] == '\0') {
+ char oldZone[64] = { 0, };
+
+ pkgmgrinfo_pkginfo_set_zone(_cur_zone, oldZone, 64);
+ int ret = __get_path(tep_resource_path, _MAX_BASE_PATH_LEN - 1, _TEP_RESOURCE_DIR,
+ false,
+ false);
+
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
+
+ if ( ret != AUL_R_OK)
+ return NULL;
+ }
+ return tep_resource_path;
+}
+
SLPAPI const char *aul_get_app_shared_data_path(void)
{
- static char shared_data_path[_MAX_BASE_PATH_LEN] = {0,};
- if (shared_data_path[0] == '\0')
- {
- if (__get_path(shared_data_path, _MAX_BASE_PATH_LEN - 1, _SHARED_DATA_DIR, false) != AUL_R_OK)
- {
+ if (shared_data_path[0] == '\0') {
+ char oldZone[64] = { 0, };
+
+ pkgmgrinfo_pkginfo_set_zone(_cur_zone, oldZone, 64);
+ int ret = __get_path(shared_data_path, _MAX_BASE_PATH_LEN - 1, _SHARED_DATA_DIR,
+ false, true);
+
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
+
+ if ( ret != AUL_R_OK)
return NULL;
- }
+
}
return shared_data_path;
}
SLPAPI const char *aul_get_app_shared_resource_path(void)
{
- static char shared_resource_path[_MAX_BASE_PATH_LEN] = {0,};
- if (shared_resource_path[0] == '\0')
- {
- if (__get_path(shared_resource_path, _MAX_BASE_PATH_LEN - 1, _SHARED_RESOURCE_DIR, false) != AUL_R_OK)
- {
+ if (shared_resource_path[0] == '\0') {
+ char oldZone[64] = { 0, };
+
+ pkgmgrinfo_pkginfo_set_zone(_cur_zone, oldZone, 64);
+ int ret = __get_path(shared_resource_path, _MAX_BASE_PATH_LEN - 1,
+ _SHARED_RESOURCE_DIR, false, false);
+
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
+
+ if ( ret != AUL_R_OK)
return NULL;
- }
}
return shared_resource_path;
}
SLPAPI const char *aul_get_app_shared_trusted_path(void)
{
- static char shared_trusted_path[_MAX_BASE_PATH_LEN] = {0,};
- if (shared_trusted_path[0] == '\0')
- {
- if (__get_path(shared_trusted_path, _MAX_BASE_PATH_LEN - 1, _SHARED_TRUSTED_DIR, false) != AUL_R_OK)
- {
+ if (shared_trusted_path[0] == '\0') {
+ char oldZone[64] = { 0, };
+
+ pkgmgrinfo_pkginfo_set_zone(_cur_zone, oldZone, 64);
+ int ret = __get_path(shared_trusted_path, _MAX_BASE_PATH_LEN - 1,
+ _SHARED_TRUSTED_DIR, false, true);
+
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
+
+ if ( ret != AUL_R_OK)
return NULL;
- }
+
}
return shared_trusted_path;
}
SLPAPI const char *aul_get_app_external_data_path(void)
{
- static char external_data_path[_MAX_BASE_PATH_LEN] = {0,};
- if (external_data_path[0] == '\0')
- {
- if (__get_path(external_data_path, _MAX_BASE_PATH_LEN - 1, _DATA_DIR, true) != AUL_R_OK)
- {
+ if (external_data_path[0] == '\0') {
+ char oldZone[64] = { 0, };
+
+ pkgmgrinfo_pkginfo_set_zone(_cur_zone, oldZone, 64);
+ int ret = __get_path(external_data_path, _MAX_BASE_PATH_LEN - 1, _DATA_DIR,
+ true,
+ true);
+
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
+
+ if ( ret != AUL_R_OK)
return NULL;
- }
+
}
return external_data_path;
}
SLPAPI const char *aul_get_app_external_cache_path(void)
{
- static char external_cache_path[_MAX_BASE_PATH_LEN] = {0,};
- if (external_cache_path[0] == '\0')
- {
- if (__get_path(external_cache_path, _MAX_BASE_PATH_LEN - 1, _CACHE_DIR, true) != AUL_R_OK)
- {
+ if (external_cache_path[0] == '\0') {
+ char oldZone[64] = { 0, };
+
+ pkgmgrinfo_pkginfo_set_zone(_cur_zone, oldZone, 64);
+ int ret = __get_path(external_cache_path, _MAX_BASE_PATH_LEN - 1, _CACHE_DIR,
+ true,
+ true);
+
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
+
+ if ( ret != AUL_R_OK)
return NULL;
- }
+
}
return external_cache_path;
}
SLPAPI const char *aul_get_app_external_shared_data_path(void)
{
- static char external_shared_data_path[_MAX_BASE_PATH_LEN] = {0,};
- if (external_shared_data_path[0] == '\0')
- {
- if (__get_path(external_shared_data_path, _MAX_PACKAGE_ID_LEN - 1, _SHARED_DATA_DIR, true) != AUL_R_OK)
- {
+ if (external_shared_data_path[0] == '\0') {
+ char oldZone[64] = { 0, };
+
+ pkgmgrinfo_pkginfo_set_zone(_cur_zone, oldZone, 64);
+ int ret = __get_path(external_shared_data_path, _MAX_PACKAGE_ID_LEN - 1,
+ _SHARED_DATA_DIR, true, true);
+
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
+
+ if ( ret != AUL_R_OK)
return NULL;
- }
+
}
return external_shared_data_path;
}
SLPAPI const char *aul_get_app_specific_path(void)
{
- return _APP_SPECIFIC_PATH;
+ const char *specific_path = NULL;
+ char oldZone[64] = { 0, };
+
+ if (pkgid[0] == '\0') {
+ pkgmgrinfo_pkginfo_set_zone(_cur_zone, oldZone, 64);
+ int err = __get_pkgid(pkgid, _MAX_PACKAGE_ID_LEN - 1);
+
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
+
+ if (err != AUL_R_OK) {
+ return NULL;
+ }
+ }
+
+ pkgmgrinfo_pkginfo_set_zone(_cur_zone, oldZone, 64);
+ specific_path = __get_app_specific_path(pkgid);
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
+
+ return specific_path;
}
SLPAPI const char *aul_get_app_external_specific_path(void)
SLPAPI int aul_get_app_shared_data_path_by_appid(const char *appid, char **path)
{
- return __get_path_by_appid(path, appid, _SHARED_DATA_DIR, false);
+ char oldZone[64] = { 0, };
+
+ pkgmgrinfo_pkginfo_set_zone(_cur_zone, oldZone, 64);
+ int ret = __get_path_by_appid(path, appid, _SHARED_DATA_DIR, false);
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
+
+ return ret;
}
-SLPAPI int aul_get_app_shared_resource_path_by_appid(const char *appid, char **path)
+SLPAPI int aul_get_app_shared_resource_path_by_appid(const char *appid,
+ char **path)
{
- return __get_path_by_appid(path, appid, _SHARED_RESOURCE_DIR, false);
+ char oldZone[64] = { 0, };
+
+ pkgmgrinfo_pkginfo_set_zone(_cur_zone, oldZone, 64);
+ int ret = __get_path_by_appid(path, appid, _SHARED_RESOURCE_DIR, false);
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
+
+ return ret;
}
-SLPAPI int aul_get_app_shared_trusted_path_by_appid(const char *appid, char **path)
+SLPAPI int aul_get_app_shared_trusted_path_by_appid(const char *appid,
+ char **path)
{
- return __get_path_by_appid(path, appid, _SHARED_TRUSTED_DIR, false);
+ char oldZone[64] = { 0, };
+
+ pkgmgrinfo_pkginfo_set_zone(_cur_zone, oldZone, 64);
+ int ret = __get_path_by_appid(path, appid, _SHARED_TRUSTED_DIR, false);
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
+
+ return ret;
}
-SLPAPI int aul_get_app_external_shared_data_path_by_appid(const char *appid, char **path)
+SLPAPI int aul_get_app_external_shared_data_path_by_appid(const char *appid,
+ char **path)
{
- return __get_path_by_appid(path, appid, _SHARED_DATA_DIR, true);
+ char oldZone[64] = { 0, };
+
+ pkgmgrinfo_pkginfo_set_zone(_cur_zone, oldZone, 64);
+ int ret = __get_path_by_appid(path, appid, _SHARED_DATA_DIR, true);
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
+
+ return ret;
}
SLPAPI char *aul_get_cmdline_bypid(int pid)
{
return __proc_get_cmdline_bypid(pid);
}
+
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#define _GNU_SOURCE
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <glib/gstdio.h>
+#include <bundle_internal.h>
+#include <assert.h>
+#include <dlog.h>
+#include <vconf.h>
+#include <system_info.h>
+#include <pkgmgr-info.h>
+#include <pkgmgrinfo_resource.h>
+
+#include "aul.h"
+#include "aul_api.h"
+#include "aul_rsc_mgr.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "AUL_RESOURCE_MANAGER"
+
+#define WEIGHT_SCREEN_DPI 10000
+#define WEIGHT_SCREEN_DPI_RANGE 10000
+#define WEIGHT_SCREEN_BPP 1000
+#define WEIGHT_SCREEN_WIDTH_RANGE 100
+#define WEIGHT_SCREEN_LARGE 10
+#define WEIGHT_PLATFORM_VERSION 1000000
+#define WEIGHT_LANGUAGE 100000
+
+#define THRESHOLD_TO_CLEAN 50 /* app_resource_manager_trim_cache */
+
+#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))
+#define MAX_PATH 1024
+
+typedef struct {
+ resource_data_t *data;
+ GHashTable *cache;
+} resource_manager_t;
+
+typedef struct {
+ char *output;
+ int hit_cnt;
+ bool remove;
+} resource_cache_context_t;
+
+typedef struct {
+ const char *bundle_attr_key;
+ unsigned int bundle_attr_value;
+} resource_node_attr_t;
+
+typedef struct {
+ char *folder;
+ char *type;
+} resource_node_list_t;
+
+enum {
+ NODE_ATTR_MIN = 0,
+ NODE_ATTR_SCREEN_DPI,
+ NODE_ATTR_SCREEN_DPI_RANGE,
+ NODE_ATTR_SCREEN_WIDTH_RANGE,
+ NODE_ATTR_SCREEN_LARGE,
+ NODE_ATTR_SCREEN_BPP,
+ NODE_ATTR_PLATFORM_VER,
+ NODE_ATTR_LANGUAGE,
+ NODE_ATTR_MAX
+};
+
+static resource_manager_t *resource_handle = NULL;
+
+static resource_node_attr_t map[] = {
+ { RSC_NODE_ATTR_SCREEN_DPI, NODE_ATTR_SCREEN_DPI },
+ { RSC_NODE_ATTR_SCREEN_DPI_RANGE, NODE_ATTR_SCREEN_DPI_RANGE },
+ { RSC_NODE_ATTR_SCREEN_WIDTH_RANGE, NODE_ATTR_SCREEN_WIDTH_RANGE },
+ { RSC_NODE_ATTR_SCREEN_LARGE, NODE_ATTR_SCREEN_LARGE },
+ { RSC_NODE_ATTR_SCREEN_BPP, NODE_ATTR_SCREEN_BPP },
+ { RSC_NODE_ATTR_PLATFORM_VER, NODE_ATTR_PLATFORM_VER },
+ { RSC_NODE_ATTR_LANGUAGE, NODE_ATTR_LANGUAGE },
+};
+
+static GHashTable *attr_key = NULL;
+static const char *res_path = NULL;
+static char *cur_language = NULL;
+static bool is_slice = FALSE;
+
+static GHashTable *valid_path_list = NULL;
+static GHashTable *supported_lang_list = NULL;
+static GHashTable *id_list = NULL;
+static GList *all_node_list = NULL;
+static bundle *given_attr_list = NULL;
+
+static gint __resource_manager_comp(gconstpointer a, gconstpointer b)
+{
+ resource_group_t *rsc_group = (resource_group_t *) a;
+
+ return strcmp(rsc_group->type, b);
+}
+
+static gint __compare_path(gconstpointer a, gconstpointer b)
+{
+ char tmp_path[MAX_PATH] = {0, };
+ resource_node_list_t *tmp_node_info= (resource_node_list_t *)a;
+
+ snprintf(tmp_path, MAX_PATH - 1, "%s%s", res_path, tmp_node_info->folder);
+ return strncmp(tmp_path, (char *)b, strlen(tmp_path));
+}
+
+
+static int __get_dpi(void)
+{
+ int dpi = 0;
+ char *tmp = NULL;
+ if (is_slice) {
+ bundle_get_str(given_attr_list, RSC_NODE_ATTR_SCREEN_DPI, &tmp);
+ if (tmp == NULL) {
+ LOGE("Failed to retrieve DPI");
+ dpi = 0;
+ } else
+ dpi = atoi(tmp);
+ } else
+ system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
+
+ return dpi;
+}
+
+static int __get_screen_width(void)
+{
+ int screen_width = 0;
+ char *tmp = NULL;
+
+ if (is_slice) {
+ bundle_get_str(given_attr_list, RSC_NODE_ATTR_SCREEN_WIDTH_RANGE, &tmp);
+ if (tmp == NULL) {
+ LOGE("Failed to retrieve screen width");
+ screen_width = 0;
+ } else
+ screen_width = atoi(tmp);
+ } else
+ system_info_get_platform_int("http://tizen.org/feature/screen.width", &screen_width);
+
+ return screen_width;
+}
+
+static bool __get_screen_large(void)
+{
+ bool screen_large = true;
+ char *tmp = NULL;
+
+ if (is_slice) {
+ bundle_get_str(given_attr_list, RSC_NODE_ATTR_SCREEN_LARGE, &tmp);
+ if (tmp == NULL) {
+ LOGE("Failed to retrieve screen large");
+ screen_large = false;
+ } else
+ screen_large = atoi(tmp);
+ } else {
+ if (system_info_get_platform_bool("http://tizen.org/feature/screen.size.large", &screen_large) != SYSTEM_INFO_ERROR_NONE) {
+ LOGE("Failed to get info of screen.size.large");
+ screen_large = false;
+ }
+ }
+
+ return screen_large;
+}
+
+static int __get_screen_bpp(void)
+{
+ int screen_bpp = 0;
+ char *tmp = NULL;
+
+ if (is_slice) {
+ bundle_get_str(given_attr_list, RSC_NODE_ATTR_SCREEN_BPP, &tmp);
+ if (tmp == NULL) {
+ LOGE("Failed to retrieve screen bpp");
+ screen_bpp = 0;
+ } else
+ screen_bpp = atoi(tmp);
+ } else
+ system_info_get_platform_int("http://tizen.org/feature/screen.bpp", &screen_bpp);
+
+ return screen_bpp;
+}
+
+static char *__get_platform_version(void)
+{
+ char *version = NULL;
+ if (is_slice)
+ bundle_get_str(given_attr_list, RSC_NODE_ATTR_PLATFORM_VER, &version);
+ else
+ system_info_get_platform_string("http://tizen.org/feature/platform.version", &version);
+
+ return version;
+}
+
+static void __bundle_iterator_get_valid_nodes(const char *key, const int type,
+ const bundle_keyval_t *kv, void *data)
+{
+ unsigned int node_attr;
+ bool *invalid = (bool *) data;
+ bool ret_bool = true;
+ int min, max;
+ char from[5] = { 0, };
+ char to[3] = { 0, };
+ bool t_val;
+ char *val;
+ size_t size;
+ static int screen_dpi = -1;
+ static int screen_width = -1;
+ static int screen_size_large = -1;
+ static char *version = NULL;
+ static int screen_bpp = -1;
+
+ if (*invalid)
+ return;
+
+ bundle_keyval_get_basic_val((bundle_keyval_t *) kv, (void**) &val, &size);
+
+ node_attr = (guint) g_hash_table_lookup(attr_key, key);
+ if (node_attr <= NODE_ATTR_MIN || node_attr >= NODE_ATTR_MAX) {
+ LOGE("INVALID_PARAMETER(0x%08x), node_attr(%d)",
+ AUL_RESOURCE_ERROR_INVALID_PARAMETER, node_attr);
+ *invalid = true;
+ return;
+ }
+
+ switch (node_attr) {
+ case NODE_ATTR_SCREEN_DPI:
+ if (screen_dpi == -1)
+ screen_dpi =__get_dpi();
+ if (screen_dpi != atoi(val))
+ *invalid = true;
+ break;
+
+ case NODE_ATTR_SCREEN_DPI_RANGE:
+ sscanf(val, "%s %d %s %d", from, &min, to, &max);
+ if (screen_dpi == -1)
+ screen_dpi =__get_dpi();
+ if (!(min <= screen_dpi && screen_dpi <= max))
+ *invalid = true;
+ break;
+
+ case NODE_ATTR_SCREEN_WIDTH_RANGE:
+ sscanf(val, "%s %d %s %d", from, &min, to, &max);
+ if (screen_width == -1)
+ screen_width = __get_screen_width();
+ if (!(min <= screen_width && screen_width <= max))
+ *invalid = true;
+ break;
+
+ case NODE_ATTR_SCREEN_LARGE:
+ if (!(strcmp(val, "true")))
+ t_val = true;
+ else
+ t_val = false;
+ if (screen_size_large == -1) {
+ ret_bool = __get_screen_large();
+ if (ret_bool)
+ screen_size_large = 1;
+ else
+ screen_size_large = 0;
+ }
+ if (((bool)screen_size_large) != t_val)
+ *invalid = true;
+ break;
+
+ case NODE_ATTR_SCREEN_BPP:
+ if (screen_bpp == -1)
+ screen_bpp = __get_screen_bpp();
+ if (screen_bpp != atoi(val))
+ *invalid = true;
+ break;
+
+ case NODE_ATTR_PLATFORM_VER:
+ if (version == NULL)
+ version = __get_platform_version();
+ if (strcmp(version, val))
+ *invalid = true;
+ break;
+
+ case NODE_ATTR_LANGUAGE:
+ if (cur_language == NULL)
+ cur_language = vconf_get_str(VCONFKEY_LANGSET);
+
+ if (strncmp(cur_language, val, strlen(val)))
+ *invalid = true;
+ break;
+ }
+}
+
+static void __bundle_iterator_get_best_node(const char *key, const char *val,
+ void *data)
+{
+ unsigned int node_attr;
+ unsigned int *weight = (unsigned int *) data;
+
+ node_attr = (guint) g_hash_table_lookup(attr_key, key);
+ if (node_attr <= NODE_ATTR_MIN || node_attr >= NODE_ATTR_MAX) {
+ LOGE("INVALID_PARAMETER(0x%08x), node_attr(%d)",
+ AUL_RESOURCE_ERROR_INVALID_PARAMETER, node_attr);
+ return;
+ }
+
+ switch (node_attr) {
+ case NODE_ATTR_SCREEN_DPI:
+ *weight += WEIGHT_SCREEN_DPI;
+ break;
+
+ case NODE_ATTR_SCREEN_DPI_RANGE:
+ *weight += WEIGHT_SCREEN_DPI_RANGE;
+ break;
+
+ case NODE_ATTR_SCREEN_WIDTH_RANGE:
+ *weight += WEIGHT_SCREEN_WIDTH_RANGE;
+ break;
+
+ case NODE_ATTR_SCREEN_LARGE:
+ *weight += WEIGHT_SCREEN_LARGE;
+ break;
+
+ case NODE_ATTR_SCREEN_BPP:
+ *weight += WEIGHT_SCREEN_BPP;
+ break;
+
+ case NODE_ATTR_PLATFORM_VER:
+ *weight += WEIGHT_PLATFORM_VERSION;
+ break;
+
+ case NODE_ATTR_LANGUAGE:
+ *weight += WEIGHT_LANGUAGE;
+ break;
+ }
+}
+
+static const char *__get_cache(aul_resource_e type,
+ const char *id)
+{
+ unsigned int total_len = 0;
+ char *key = NULL;
+ char *rsc_type;
+ resource_cache_context_t *resource_cache = NULL;
+
+ if (is_slice == TRUE)
+ return NULL;
+
+ if (id == NULL) {
+ LOGE("INVALID_PARAMETER(0x%08x), id",
+ AUL_RESOURCE_ERROR_INVALID_PARAMETER);
+ return NULL;
+ }
+
+ if (type < AUL_RESOURCE_TYPE_MIN || type > AUL_RESOURCE_TYPE_MAX) {
+ LOGE("INVALID_PARAMETER(0x%08x), type(%d)",
+ AUL_RESOURCE_ERROR_INVALID_PARAMETER, type);
+ return NULL;
+ } else {
+ switch (type) {
+ case AUL_RESOURCE_TYPE_IMAGE:
+ rsc_type = RSC_GROUP_TYPE_IMAGE;
+ break;
+
+ case AUL_RESOURCE_TYPE_LAYOUT:
+ rsc_type = RSC_GROUP_TYPE_LAYOUT;
+ break;
+
+ case AUL_RESOURCE_TYPE_SOUND:
+ rsc_type = RSC_GROUP_TYPE_SOUND;
+ break;
+
+ case AUL_RESOURCE_TYPE_BIN:
+ rsc_type = RSC_GROUP_TYPE_BIN;
+ break;
+ }
+ }
+
+ if (resource_handle->cache == NULL) {
+ LOGE("INVALID_PARAMETER(0x%08x), hashtable",
+ AUL_RESOURCE_ERROR_INVALID_PARAMETER);
+ return NULL;
+ } else {
+ total_len = strlen(rsc_type) + strlen(id) + 2;
+
+ key = (char *) calloc(1, total_len);
+ if (key == NULL) {
+ LOGE("failed to create a resource_cache(0x%08x)",
+ AUL_RESOURCE_ERROR_OUT_OF_MEMORY);
+ free(resource_cache);
+ return NULL;
+ }
+
+ snprintf(key, total_len, "%s:%s", rsc_type, id);
+ LOGD("key : %s", key);
+
+ resource_cache = g_hash_table_lookup(resource_handle->cache, key);
+ free(key);
+ if (resource_cache == NULL) {
+ LOGE("IO_ERROR(0x%08x), find list resource_cache",
+ AUL_RESOURCE_ERROR_IO_ERROR);
+ return NULL;
+ }
+
+ resource_cache->hit_cnt++;
+ }
+
+ return resource_cache->output;
+}
+
+static gint __cache_hit_compare(gconstpointer a, gconstpointer b)
+{
+ const resource_cache_context_t *lhs = (const resource_cache_context_t *) a;
+ const resource_cache_context_t *rhs = (const resource_cache_context_t *) b;
+
+ return lhs->hit_cnt - rhs->hit_cnt;
+}
+
+static gboolean __cache_remove(gpointer key, gpointer value, gpointer user_data)
+{
+ resource_cache_context_t *c = (resource_cache_context_t *) (value);
+
+ if (c->remove) {
+ free(key);
+ free(c->output);
+ free(c);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static void __trim_cache(void)
+{
+ GList *values = g_hash_table_get_values(resource_handle->cache);
+ values = g_list_sort(values, __cache_hit_compare);
+
+ int i = 0;
+ GList *iter_list = values;
+ while (iter_list != NULL) {
+ if (i >= (THRESHOLD_TO_CLEAN / 2))
+ break;
+
+ resource_cache_context_t *c =
+ (resource_cache_context_t *) (iter_list->data);
+ c->remove = true;
+ iter_list = g_list_next(iter_list);
+ i++;
+ }
+
+ g_list_free(values);
+ g_hash_table_foreach_remove(resource_handle->cache, __cache_remove, NULL);
+
+}
+
+static void __put_cache(aul_resource_e type, const char *id,
+ const char *val)
+{
+ unsigned int total_len = 0;
+ char *key;
+ char *rsc_type;
+ resource_cache_context_t *resource_cache;
+
+ if (is_slice == TRUE)
+ return;
+
+ /* To remove chache from the low frequency of use. */
+ if (val == NULL) {
+ LOGE("INVALID_PARAMETER(0x%08x), fname",
+ AUL_RESOURCE_ERROR_INVALID_PARAMETER);
+ return;
+ }
+
+ if (id == NULL) {
+ LOGE("INVALID_PARAMETER(0x%08x), id",
+ AUL_RESOURCE_ERROR_INVALID_PARAMETER);
+ return;
+ }
+
+ if (type < AUL_RESOURCE_TYPE_MIN || type > AUL_RESOURCE_TYPE_MAX) {
+ LOGE("INVALID_PARAMETER(0x%08x), type(%d)",
+ AUL_RESOURCE_ERROR_INVALID_PARAMETER, type);
+ return;
+ } else {
+ switch (type) {
+ case AUL_RESOURCE_TYPE_IMAGE:
+ rsc_type = RSC_GROUP_TYPE_IMAGE;
+ break;
+
+ case AUL_RESOURCE_TYPE_LAYOUT:
+ rsc_type = RSC_GROUP_TYPE_LAYOUT;
+ break;
+
+ case AUL_RESOURCE_TYPE_SOUND:
+ rsc_type = RSC_GROUP_TYPE_SOUND;
+ break;
+
+ case AUL_RESOURCE_TYPE_BIN:
+ rsc_type = RSC_GROUP_TYPE_BIN;
+ break;
+ }
+ }
+
+ if (g_hash_table_size(resource_handle->cache) > THRESHOLD_TO_CLEAN)
+ __trim_cache();
+
+ resource_cache = (resource_cache_context_t *) calloc(1,
+ sizeof(resource_cache_context_t));
+ if (resource_cache == NULL) {
+ LOGE("failed to create a resource_group(0x%08x)",
+ AUL_RESOURCE_ERROR_OUT_OF_MEMORY);
+ return;
+ }
+
+ total_len = strlen(rsc_type) + strlen(id) + 2;
+
+ key = (char *) calloc(1, total_len);
+ if (key == NULL) {
+ LOGE("failed to create a resource_cache(0x%08x)",
+ AUL_RESOURCE_ERROR_OUT_OF_MEMORY);
+ free(resource_cache);
+ return;
+ }
+
+ snprintf(key, total_len, "%s:%s", rsc_type, id);
+ LOGD("key : %s", key);
+
+ resource_cache->output = strdup(val);
+ resource_cache->hit_cnt = 0;
+ resource_cache->remove = false;
+
+ g_hash_table_insert(resource_handle->cache, key, resource_cache);
+}
+
+static resource_group_t *__find_group(resource_data_t *data,
+ int type)
+{
+ resource_group_t *rsc_group = NULL;
+ char *rsc_type;
+
+ if (data == NULL) {
+ LOGE("INVALID_PARAMETER(0x%08x), resource_data_t",
+ AUL_RESOURCE_ERROR_INVALID_PARAMETER);
+ return NULL;
+ }
+
+ if (type < AUL_RESOURCE_TYPE_MIN || type > AUL_RESOURCE_TYPE_MAX) {
+ LOGE("INVALID_PARAMETER(0x%08x), type(%d)",
+ AUL_RESOURCE_ERROR_INVALID_PARAMETER, type);
+ return NULL;
+ } else {
+ switch (type) {
+ case AUL_RESOURCE_TYPE_IMAGE:
+ rsc_type = RSC_GROUP_TYPE_IMAGE;
+ break;
+
+ case AUL_RESOURCE_TYPE_LAYOUT:
+ rsc_type = RSC_GROUP_TYPE_LAYOUT;
+ break;
+
+ case AUL_RESOURCE_TYPE_SOUND:
+ rsc_type = RSC_GROUP_TYPE_SOUND;
+ break;
+
+ case AUL_RESOURCE_TYPE_BIN:
+ rsc_type = RSC_GROUP_TYPE_BIN;
+ break;
+ }
+ }
+
+ GList* found = g_list_find_custom(data->group_list, rsc_type,
+ __resource_manager_comp);
+ if (found == NULL) {
+ LOGE("IO_ERROR(0x%08x), find list resource_group %s",
+ AUL_RESOURCE_ERROR_IO_ERROR, rsc_type);
+ return NULL;
+ }
+
+ rsc_group = (resource_group_t *) (found->data);
+
+ return rsc_group;
+}
+
+static GList *__get_valid_nodes(resource_group_t *group,
+ const char *id)
+{
+ GList *list = NULL;
+ GList *valid_list = NULL;
+ resource_node_t *valid_node = NULL;
+ resource_node_t *rsc_node = NULL;
+
+ if (group->node_list == NULL) {
+ LOGE("INVALID_PARAMETER(0x%08x), resource_group",
+ AUL_RESOURCE_ERROR_INVALID_PARAMETER);
+ return NULL;
+ }
+
+ list = g_list_first(group->node_list);
+
+ char path_buf[MAX_PATH] = { 0, };
+ while (list) {
+ bool invalid = false;
+ rsc_node = (resource_node_t *) list->data;
+
+ snprintf(path_buf, MAX_PATH - 1, "%s%s/%s", res_path,
+ rsc_node->folder, id);
+ if (access(path_buf, R_OK) == 0) {
+ bundle_foreach(rsc_node->attr, __bundle_iterator_get_valid_nodes,
+ &invalid);
+
+ if (!invalid) {
+ valid_node = (resource_node_t *) list->data;
+ valid_list = g_list_append(valid_list, valid_node);
+ }
+ }
+
+ list = g_list_next(list);
+ }
+
+ return valid_list;
+}
+
+static resource_node_t *__get_best_node(GList *nodes)
+{
+ unsigned int weight_tmp = 0;
+ resource_node_t *best_node = NULL;
+ GList *list = NULL;
+
+ if (nodes == NULL) {
+ LOGE("INVALID_PARAMETER(0x%08x), resource_node lists",
+ AUL_RESOURCE_ERROR_INVALID_PARAMETER);
+ return NULL;
+ }
+
+ list = g_list_first(nodes);
+
+ while (list != NULL) {
+ unsigned int weight = 0;
+ resource_node_t *res_node = (resource_node_t *) (list->data);
+
+ bundle_iterate(res_node->attr, __bundle_iterator_get_best_node, &weight);
+ if (weight > weight_tmp) {
+ best_node = res_node;
+ weight_tmp = weight;
+ }
+ list = g_list_next(list);
+ }
+
+ return best_node;
+}
+
+static int __open(resource_manager_t **handle)
+{
+ int retval = AUL_RESOURCE_ERROR_NONE;
+ resource_manager_t *rsc_manager = NULL;
+ char buf[MAX_PATH] = { 0, };
+
+ rsc_manager = (resource_manager_t *) calloc(1, sizeof(resource_manager_t));
+ if (!rsc_manager) {
+ LOGE("failed to create a resource_manager(0x%08x)",
+ AUL_RESOURCE_ERROR_OUT_OF_MEMORY);
+ return AUL_RESOURCE_ERROR_OUT_OF_MEMORY;
+ }
+
+ snprintf(buf, MAX_PATH - 1, "%sres.xml", res_path);
+ retval = pkgmgrinfo_resource_open(buf, &(rsc_manager->data));
+ if (retval != PMINFO_R_OK) {
+ LOGE("IO_ERROR(0x%08x), failed to get db for resource manager",
+ AUL_RESOURCE_ERROR_IO_ERROR);
+ free(rsc_manager);
+ return AUL_RESOURCE_ERROR_IO_ERROR;
+ }
+
+ rsc_manager->cache = g_hash_table_new(g_str_hash, g_str_equal);
+ *handle = rsc_manager;
+
+ return AUL_RESOURCE_ERROR_NONE;
+}
+
+static void __invalidate_cache()
+{
+ if (resource_handle != NULL) {
+ if (resource_handle->cache != NULL) {
+ GHashTableIter iter;
+ gpointer key, value;
+
+ g_hash_table_iter_init(&iter, resource_handle->cache);
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
+ free(key);
+ resource_cache_context_t *c = (resource_cache_context_t *) value;
+ free(c->output);
+ free(value);
+ }
+ g_hash_table_remove_all(resource_handle->cache);
+ if (cur_language) {
+ free(cur_language);
+ cur_language = NULL;
+ }
+ }
+ }
+}
+
+static int __close(resource_manager_t *handle)
+{
+ if (handle == NULL) {
+ LOGE("INVALID_PARAMETER(0x%08x), resource_manager",
+ AUL_RESOURCE_ERROR_INVALID_PARAMETER);
+ return AUL_RESOURCE_ERROR_INVALID_PARAMETER;
+ }
+
+ __invalidate_cache();
+ if (handle->cache != NULL) {
+ g_hash_table_destroy(handle->cache);
+ }
+
+ if (handle->data != NULL) {
+ pkgmgrinfo_resource_close(handle->data);
+ }
+
+ free(handle);
+
+ return AUL_RESOURCE_ERROR_NONE;
+}
+
+static void __vconf_cb(keynode_t *key, void *data)
+{
+ __invalidate_cache();
+}
+
+static const char *_get_app_resource_path(const char *rsc_folder_path)
+{
+ if (is_slice == FALSE)
+ return aul_get_app_resource_path();
+
+ if (rsc_folder_path == NULL)
+ return NULL;
+
+ return rsc_folder_path;
+}
+
+static void path_callback(char *path)
+{
+ char orig_path[MAX_PATH] = {0, };
+ char *path_ptr = NULL;
+ int path_len = 0;
+ GList *tmp_list = g_list_find_custom(all_node_list, path, __compare_path);
+
+ resource_node_list_t *tmp_node_info = NULL;
+ if (tmp_list == NULL)
+ g_hash_table_add(valid_path_list, strdup(path));
+ else {
+ tmp_node_info = (resource_node_list_t *)tmp_list->data;
+ path_len = strlen(path);
+ if (path_len >= MAX_PATH) {
+ LOGE("path[%s] is too long", path);
+ return;
+ }
+ strncpy(orig_path, path, path_len);
+ path_ptr = &orig_path[strlen(res_path) + strlen(tmp_node_info->folder)];
+ g_hash_table_insert(id_list, strdup(path_ptr), strdup(tmp_node_info->type));
+ }
+}
+
+static void __scan_dir(const char *path, void (*func)(char *))
+{
+ struct dirent **items;
+ int nitems, i;
+ struct stat fstat;
+ char abs_path[MAX_PATH] = {0, };
+ char cwd[MAX_PATH] = {0, };
+ char *tmp = NULL;
+
+ if (chdir(path) < 0) {
+ LOGE("failed to chdir[%s]", path);
+ return;
+ }
+
+ tmp = getcwd(cwd, MAX_PATH - 1);
+ if (tmp == NULL) {
+ LOGE("failed to get cwd");
+ return;
+ }
+ nitems = scandir("./", &items, NULL, alphasort);
+
+ for (i = 0; i < nitems; i++) {
+ if (items[i]->d_name[0] == '.')
+ continue;
+
+ snprintf(abs_path, MAX_PATH - 1, "%s/%s", cwd, items[i]->d_name);
+
+ if (g_lstat(abs_path, &fstat) != 0) {
+ LOGE("failed to retrieve info[%s]", abs_path);
+ return;
+ }
+ if ((fstat.st_mode & S_IFDIR) == S_IFDIR)
+ __scan_dir(abs_path, path_callback);
+ else
+ func(abs_path);
+ }
+
+}
+
+static aul_resource_e __get_resource_type(char *type)
+{
+ if (type == NULL)
+ return -1;
+
+ if (strcmp(type, RSC_GROUP_TYPE_IMAGE) == 0)
+ return AUL_RESOURCE_TYPE_IMAGE;
+ else if(strcmp(type, RSC_GROUP_TYPE_LAYOUT) == 0)
+ return AUL_RESOURCE_TYPE_LAYOUT;
+ else if(strcmp(type, RSC_GROUP_TYPE_SOUND) == 0)
+ return AUL_RESOURCE_TYPE_SOUND;
+ else if(strcmp(type, RSC_GROUP_TYPE_BIN) == 0)
+ return AUL_RESOURCE_TYPE_BIN;
+ else
+ return -1;
+}
+
+static int __set_valid_filelist(bundle *b)
+{
+ if (b == NULL || supported_lang_list == NULL) {
+ LOGE("INVALID_PARAMETER(0x%08x), bundle",
+ AUL_RESOURCE_ERROR_INVALID_PARAMETER);
+ return AUL_RESOURCE_ERROR_INVALID_PARAMETER;
+ }
+
+ int retval = AUL_RESOURCE_ERROR_NONE;
+ char *path = NULL;
+ GHashTableIter id_list_iter;
+ GHashTableIter lang_list_iter;
+ gpointer id_key, lang_key, id_type;
+ aul_resource_e rsc_type = AUL_RESOURCE_TYPE_MIN;
+
+ given_attr_list = b;
+ g_hash_table_iter_init(&id_list_iter, id_list);
+
+ while (g_hash_table_iter_next(&id_list_iter, &id_key, &id_type)) {
+ rsc_type = __get_resource_type((char *)id_type);
+ if (rsc_type == -1) {
+ LOGE("failed to get resource type[%s]", (char *)id_type);
+ return AUL_RESOURCE_ERROR_IO_ERROR;
+ }
+
+ g_hash_table_iter_init(&lang_list_iter, supported_lang_list);
+ while (g_hash_table_iter_next(&lang_list_iter, &lang_key, NULL)) {
+ cur_language = strdup(lang_key);
+ if (cur_language == NULL) {
+ LOGE("failed to strdup");
+ return AUL_RESOURCE_ERROR_OUT_OF_MEMORY;
+ }
+
+ retval = aul_resource_manager_get(rsc_type, id_key, &path);
+ if (retval == AUL_RESOURCE_ERROR_NONE)
+ g_hash_table_add(valid_path_list, path);
+ else
+ LOGE("failed to get value with given type[%d], key[%s]", rsc_type, id_key);
+
+ if (cur_language) {
+ free(cur_language);
+ cur_language = NULL;
+ }
+ }
+ }
+ return AUL_RESOURCE_ERROR_NONE;
+}
+
+static int __make_list(void)
+{
+ resource_group_t *tmp_group = NULL;
+ resource_node_t *tmp_node = NULL;
+ resource_node_list_t *tmp_node_struct = NULL;
+ char *group_type = NULL;
+ char folder[MAX_PATH] = {0 ,};
+ char *node_lang = NULL;
+ GList *group_list = NULL;
+ GList *node_list = NULL;
+ bundle *b = NULL;
+
+
+ /* make node folder list */
+ group_list = resource_handle->data->group_list;
+ if (group_list == NULL)
+ return AUL_RESOURCE_ERROR_IO_ERROR;
+
+ while (group_list != NULL) {
+ tmp_group = (resource_group_t *)group_list->data;
+ if (tmp_group == NULL)
+ return AUL_RESOURCE_ERROR_IO_ERROR;
+
+ group_type = tmp_group->type;
+ node_list = tmp_group->node_list;
+ memset(folder, '\0', MAX_PATH);
+ snprintf(folder, MAX_PATH - 1, "%s/",tmp_group->folder);
+
+ /*make struct and put it into all node list*/
+ tmp_node_struct = (resource_node_list_t *)calloc(1, sizeof(resource_node_list_t));
+ if (tmp_node_struct == NULL) {
+ LOGE("calloc failed");
+ return AUL_RESOURCE_ERROR_OUT_OF_MEMORY;
+ }
+
+ tmp_node_struct->folder = strdup(folder);
+ tmp_node_struct->type = strdup(group_type);
+ all_node_list = g_list_append(all_node_list, tmp_node_struct);
+
+ while (node_list != NULL) {
+ tmp_node = (resource_node_t *)node_list->data;
+ if (tmp_node == NULL)
+ return AUL_RESOURCE_ERROR_IO_ERROR;
+
+ /*retrieve language value from each node*/
+ b = tmp_node->attr;
+ if (b == NULL)
+ return AUL_RESOURCE_ERROR_IO_ERROR;
+ bundle_get_str(b, RSC_NODE_ATTR_LANGUAGE, &node_lang);
+ if (node_lang != NULL)
+ g_hash_table_add(supported_lang_list, strdup(node_lang));
+
+ memset(folder, '\0', MAX_PATH);
+ snprintf(folder, MAX_PATH - 1, "%s/",tmp_node->folder);
+
+ /*make struct and put it into all node list*/
+ tmp_node_struct = (resource_node_list_t *)calloc(1, sizeof(resource_node_list_t));
+ if (tmp_node_struct == NULL) {
+ LOGE("calloc failed");
+ return AUL_RESOURCE_ERROR_OUT_OF_MEMORY;
+ }
+
+ tmp_node_struct->folder = strdup(folder);
+ tmp_node_struct->type = strdup(group_type);
+ all_node_list = g_list_prepend(all_node_list, tmp_node_struct);
+
+ node_list = g_list_next(node_list);
+ }
+ group_list = g_list_next(group_list);
+ }
+
+ __scan_dir(res_path, path_callback);
+
+ /* add language which is not existed to find default resources */
+ g_hash_table_add(supported_lang_list, strdup("NoLang"));
+ return AUL_RESOURCE_ERROR_NONE;
+}
+
+static void __free_str(gpointer data)
+{
+ if (data == NULL)
+ return;
+
+ char *char_data = (char *)data;
+ free(char_data);
+ data = NULL;
+}
+
+static int __init(const char *rsc_folder_path, bundle *b)
+{
+ if (rsc_folder_path != NULL && b != NULL)
+ is_slice = TRUE;
+ else
+ is_slice = FALSE;
+
+ if (resource_handle != NULL)
+ return AUL_RESOURCE_ERROR_NONE;
+
+ int retval = AUL_RESOURCE_ERROR_NONE;
+
+ res_path = _get_app_resource_path(rsc_folder_path);
+ if (res_path == NULL) {
+ LOGE("IO_ERROR(0x%08x), failed to get resource path",
+ AUL_RESOURCE_ERROR_IO_ERROR);
+ return AUL_RESOURCE_ERROR_IO_ERROR;
+ }
+
+ retval = __open(&resource_handle);
+ if (retval != AUL_RESOURCE_ERROR_NONE) {
+ LOGE("IO_ERROR(0x%08x), failed to get resource_handle(%d)",
+ AUL_RESOURCE_ERROR_IO_ERROR, retval);
+ return AUL_RESOURCE_ERROR_IO_ERROR;
+ }
+
+ if (attr_key == NULL) {
+ attr_key = g_hash_table_new(g_str_hash, g_str_equal);
+
+ if (attr_key == NULL)
+ return AUL_RESOURCE_ERROR_OUT_OF_MEMORY;
+
+ unsigned int i;
+ for (i = 0; i < ARRAY_SIZE(map); i++) {
+ g_hash_table_insert(attr_key, (char *) map[i].bundle_attr_key,
+ (gpointer) (map[i].bundle_attr_value));
+ }
+ }
+
+ if (is_slice == FALSE) {
+ int r = vconf_notify_key_changed(VCONFKEY_LANGSET, __vconf_cb, NULL);
+
+ if (r < 0) {
+ LOGE("IO_ERROR(0x%08x), failed to register vconf(%d)",
+ AUL_RESOURCE_ERROR_IO_ERROR, r);
+ return AUL_RESOURCE_ERROR_IO_ERROR;
+ }
+ } else {
+ /* make ID list */
+ if (id_list == NULL)
+ id_list = g_hash_table_new_full(g_str_hash, g_str_equal, __free_str, __free_str);
+
+ if (supported_lang_list == NULL)
+ supported_lang_list = g_hash_table_new_full(g_str_hash, g_str_equal, __free_str, NULL);
+
+ if (valid_path_list == NULL)
+ valid_path_list = g_hash_table_new_full(g_str_hash, g_str_equal, __free_str, NULL);
+
+ retval = __make_list();
+ if (retval < 0) {
+ LOGE("Failed to initialize filelist");
+ return AUL_RESOURCE_ERROR_IO_ERROR;
+ }
+
+ retval = __set_valid_filelist(b);
+ if (retval < 0) {
+ LOGE("Failed to get valid filelist");
+ return AUL_RESOURCE_ERROR_IO_ERROR;
+ }
+
+ }
+
+ return AUL_RESOURCE_ERROR_NONE;
+}
+
+SLPAPI int aul_resource_manager_init(void)
+{
+ return __init(NULL, NULL);
+}
+
+SLPAPI int aul_resource_manager_init_slice(const char *rsc_folder_path, bundle *b)
+{
+ if (rsc_folder_path == NULL || b == NULL)
+ return AUL_RESOURCE_ERROR_INVALID_PARAMETER;
+
+ return __init(rsc_folder_path, b);
+}
+
+
+SLPAPI int aul_resource_manager_get_path_list(GHashTable **list)
+{
+ if (is_slice == FALSE)
+ return AUL_RESOURCE_ERROR_IO_ERROR;
+
+ if (valid_path_list != NULL)
+ *list = valid_path_list;
+ else
+ return AUL_RESOURCE_ERROR_IO_ERROR;
+
+ return AUL_RESOURCE_ERROR_NONE;
+}
+
+SLPAPI int aul_resource_manager_get(aul_resource_e type, const char *id, char **path)
+{
+ int retval = AUL_RESOURCE_ERROR_NONE;
+ char *put_fname = NULL;
+ const char *cached_path = NULL;
+ GList *list = NULL;
+ resource_group_t *resource_group = NULL;
+ resource_node_t *resource_node = NULL;
+
+ *path = NULL;
+
+ if (id == NULL) {
+ LOGE("INVALID_PARAMETER(0x%08x), resource_data_t",
+ AUL_RESOURCE_ERROR_INVALID_PARAMETER);
+ return AUL_RESOURCE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (type < AUL_RESOURCE_TYPE_MIN || type > AUL_RESOURCE_TYPE_MAX) {
+ LOGE("INVALID_PARAMETER(0x%08x), type(%d)",
+ AUL_RESOURCE_ERROR_INVALID_PARAMETER, type);
+ return AUL_RESOURCE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (is_slice == FALSE) {
+ if (resource_handle == NULL) {
+ retval = aul_resource_manager_init();
+ if (retval != AUL_RESOURCE_ERROR_NONE)
+ return retval;
+ }
+
+ /* To get fname from cache */
+ cached_path = __get_cache(type, id);
+ if (cached_path != NULL) {
+ *path = strdup(cached_path);
+ return AUL_RESOURCE_ERROR_NONE;
+ }
+ }
+
+ if (resource_handle == NULL)
+ return AUL_RESOURCE_ERROR_IO_ERROR;
+
+ resource_group = __find_group(resource_handle->data, type);
+ if (resource_group == NULL) {
+ LOGE("IO_ERROR(0x%08x), failed to get resource_group",
+ AUL_RESOURCE_ERROR_IO_ERROR);
+ retval = AUL_RESOURCE_ERROR_IO_ERROR;
+ goto Exception;
+ }
+
+ list = __get_valid_nodes(resource_group, id);
+ if (list == NULL) {
+ retval = AUL_RESOURCE_ERROR_IO_ERROR;
+ goto Exception;
+ }
+
+ resource_node = __get_best_node(list);
+ if (resource_node == NULL) {
+ retval = AUL_RESOURCE_ERROR_IO_ERROR;
+ goto Exception;
+ } else {
+ unsigned int total_len = strlen(res_path)
+ + strlen(resource_node->folder) + strlen(id) + 3;
+ put_fname = (char *) calloc(1, total_len);
+ if (!put_fname) {
+ if (list != NULL)
+ g_list_free(list);
+ return AUL_RESOURCE_ERROR_OUT_OF_MEMORY;
+ }
+ snprintf(put_fname, total_len, "%s%s/%s", res_path,
+ resource_node->folder, id);
+ *path = strdup(put_fname);
+ }
+
+ __put_cache(type, id, put_fname);
+
+
+Exception:
+ if (list != NULL)
+ g_list_free(list);
+
+ if (put_fname == NULL && resource_group != NULL) {
+ char path_buf[MAX_PATH] = { 0, };
+ char group_path_buf[MAX_PATH] = { 0, };
+
+ snprintf(path_buf, MAX_PATH - 1, "%s%s/%s", res_path,
+ resource_group->folder, id);
+ snprintf(group_path_buf, MAX_PATH - 1, "%s/%s", resource_group->folder, id);
+
+ list = g_list_first(resource_group->node_list);
+ while (list) {
+ resource_node = (resource_node_t *) list->data;
+ if (strncmp(group_path_buf, resource_node->folder, strlen(resource_node->folder)) == 0) {
+ *path = NULL;
+ return AUL_RESOURCE_ERROR_IO_ERROR;
+ }
+ list = g_list_next(list);
+ }
+
+ if (access(path_buf, R_OK) == 0) {
+ __put_cache(type, id, path_buf);
+ *path = strdup(path_buf);
+ retval = AUL_RESOURCE_ERROR_NONE;
+ }
+ }
+
+ if (put_fname != NULL)
+ free(put_fname);
+
+ return retval;
+}
+
+static void __free_node_folder_list(gpointer data)
+{
+ resource_node_list_t *node_data = (resource_node_list_t *)data;
+ if (node_data == NULL)
+ return;
+
+ if (node_data->folder != NULL) {
+ free(node_data->folder);
+ node_data->folder = NULL;
+ }
+
+ if (node_data->type != NULL) {
+ free(node_data->type);
+ node_data->type = NULL;
+ }
+
+ free(node_data);
+}
+
+SLPAPI int aul_resource_manager_release(void)
+{
+ if (resource_handle != NULL) {
+ __close(resource_handle);
+ resource_handle = NULL;
+ }
+
+ if (attr_key != NULL) {
+ g_hash_table_destroy(attr_key);
+ attr_key = NULL;
+ }
+
+ if (cur_language) {
+ free(cur_language);
+ cur_language = NULL;
+ }
+
+ if (is_slice == FALSE)
+ vconf_ignore_key_changed(VCONFKEY_LANGSET, __vconf_cb);
+ else {
+ if (valid_path_list != NULL) {
+ g_hash_table_destroy(valid_path_list);
+ valid_path_list = NULL;
+ }
+
+ if (supported_lang_list != NULL) {
+ g_hash_table_destroy(supported_lang_list);
+ supported_lang_list = NULL;
+ }
+
+ if (id_list != NULL) {
+ g_hash_table_destroy(id_list);
+ id_list = NULL;
+ }
+
+ if (all_node_list != NULL) {
+ g_list_free_full(all_node_list, __free_node_folder_list);
+ all_node_list = NULL;
+ }
+ }
+ return AUL_RESOURCE_ERROR_NONE;
+}
*
*/
-
+#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
-#include <utilX.h>
#include <glib.h>
#include <poll.h>
#include <bundle.h>
SLPAPI int aul_key_init(int (*aul_handler) (bundle *, void *), void *data)
{
+#ifdef _APPFW_FEATURE_AMD_KEY
int fd;
GPollFD *gpollfd;
GSource *src;
gpollfd = (GPollFD *) g_malloc(sizeof(GPollFD));
if (gpollfd == NULL) {
- _E("out of memory");
g_source_unref(src);
- close(fd);
return AUL_R_ERROR;
}
return AUL_R_ERROR;
g_source_unref(src);
-
+#endif
return AUL_R_OK;
}
SLPAPI int aul_key_reserve()
{
+#ifdef _APPFW_FEATURE_AMD_KE
bundle *kb;
int ret;
bundle_free(kb);
return ret;
+#else
+ return AUL_R_OK;
+#endif
}
SLPAPI int aul_key_release()
{
+#ifdef _APPFW_FEATURE_AMD_KE
bundle *kb;
int ret;
bundle_free(kb);
return ret;
+#else
+ return AUL_R_OK;
+#endif
}
-
-
-
*
*/
-
+#define _GNU_SOURCE
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/time.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <glib.h>
#ifdef _APPFW_FEATURE_APP_CONTROL_LITE
#include <pkgmgr-info.h>
+#include <pkgmgrinfo_zone.h>
#endif
+#include <ttrace.h>
+#include <bundle_internal.h>
#include "aul.h"
#include "aul_api.h"
#include "launch.h"
#include "key.h"
#include "aul_util.h"
+#include "aul_zone.h"
+#ifdef _APPFW_FEATURE_EXPANSION_PKG_INSTALL
+#include <dbus/dbus.h>
+#include "app_signal.h"
+#define TEP_ISMOUNT_MAX_RETRY_CNT 20
+#endif
static int aul_initialized = 0;
static int aul_fd;
static void *_aul_data;
-
-static int __call_aul_handler(aul_type type, bundle *kb);
static int app_resume();
static int app_terminate();
static void __clear_internal_key(bundle *kb);
extern int aul_launch_fini();
+#ifdef _APPFW_FEATURE_EXPANSION_PKG_INSTALL
+SLPAPI int aul_is_tep_mount_dbus_done(const char *tep_string)
+{
+ DBusMessage *msg;
+ DBusMessage *reply;
+ DBusError err;
+ int ret = -1;
+ int r = -1;
+
+ DBusConnection *conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
+ if (!conn) {
+ _E("dbus_bus_get error");
+ return -EBADMSG;
+ }
+
+ msg = dbus_message_new_method_call(TEP_BUS_NAME, TEP_OBJECT_PATH, TEP_INTERFACE_NAME, TEP_IS_MOUNTED_METHOD);
+ if(!msg) {
+ _E("dbus_message_new_method_call(%s:%s-%s)", TEP_OBJECT_PATH, TEP_INTERFACE_NAME, TEP_IS_MOUNTED_METHOD);
+ return ret;
+ }
+
+ if (!dbus_message_append_args(msg,
+ DBUS_TYPE_STRING, &tep_string,
+ DBUS_TYPE_INVALID)) {
+ _E("Ran out of memory while constructing args\n");
+ dbus_message_unref(msg);
+ return ret;
+ }
+
+ dbus_error_init(&err);
+ reply = dbus_connection_send_with_reply_and_block(conn, msg, 500, &err);
+ if (!reply) {
+ _E("dbus_connection_send error(%s:%s)", err.name, err.message);
+ goto func_out;
+ }
+
+ r = dbus_message_get_args(reply, &err, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
+ if (!r) {
+ _E("no message : [%s:%s]", err.name, err.message);
+ goto func_out;
+ }
+
+func_out :
+ dbus_message_unref(msg);
+ dbus_error_free(&err);
+ return ret;
+}
+
+SLPAPI int aul_check_tep_mount(const char *tep_path)
+{
+ if(tep_path) {
+ int rv = -1;
+ int cnt = 0;
+ while(cnt < TEP_ISMOUNT_MAX_RETRY_CNT) {
+ rv = aul_is_tep_mount_dbus_done(tep_path);
+ if(rv == 1)
+ break;
+ usleep(50 * 1000);
+ cnt++;
+ }
+ /* incase after trying 1 sec, not getting mounted then quit */
+ if( rv != 1) {
+ _E("Not able to mount within 1 sec");
+ return -1;
+ }
+ }
+ return 0;
+}
+#endif
+
int aul_is_initialized()
{
return aul_initialized;
}
-static int __call_aul_handler(aul_type type, bundle *kb)
+int __call_aul_handler(aul_type type, bundle *kb)
{
if (_aul_handler)
_aul_handler(type, kb, _aul_data);
return 0;
}
-#ifdef _APPFW_FEATURE_VISIBILITY_CHECK_BY_LCD_STATUS
-static int app_resume_lcd_on()
+static int bgapp_terminate()
{
- __call_aul_handler(AUL_RESUME_LCD_ON, NULL);
+ __call_aul_handler(AUL_TERMINATE_BGAPP, NULL);
return 0;
}
-static int app_pause_lcd_off()
+static int app_pause()
{
- __call_aul_handler(AUL_PAUSE_LCD_OFF, NULL);
+ __call_aul_handler(AUL_PAUSE, NULL);
+ return 0;
+}
+
+static int app_prepare_to_suspend()
+{
+ _D("[__SUSPEND__]");
+ __call_aul_handler(AUL_SUSPEND, NULL);
+ return 0;
+}
+
+static int app_prepare_to_wake()
+{
+ _D("[__WAKE__]");
+ __call_aul_handler(AUL_WAKE, NULL);
return 0;
}
-#endif
/**
* @brief encode kb and send it to 'pid'
SLPAPI int app_send_cmd(int pid, int cmd, bundle *kb)
{
int datalen;
- bundle_raw *kb_data;
- int res;
+ bundle_raw *kb_data = NULL;
+ int res = AUL_R_OK;
- bundle_encode(kb, &kb_data, &datalen);
+ res = bundle_encode(kb, &kb_data, &datalen);
+ if (res != BUNDLE_ERROR_NONE) {
+ return AUL_R_EINVAL;
+ }
if ((res = __app_send_raw(pid, cmd, kb_data, datalen)) < 0) {
switch (res) {
case -EINVAL:
case -EREJECTED:
res = AUL_R_EREJECTED;
break;
+ case -ENOAPP:
+ res = AUL_R_ENOAPP;
+ break;
default:
res = AUL_R_ERROR;
}
SLPAPI int app_send_cmd_with_noreply(int pid, int cmd, bundle *kb)
{
int datalen;
- bundle_raw *kb_data;
- int res;
+ bundle_raw *kb_data = NULL;
+ int res = AUL_R_OK;
- bundle_encode(kb, &kb_data, &datalen);
+ res = bundle_encode(kb, &kb_data, &datalen);
+ if (res != BUNDLE_ERROR_NONE) {
+ return AUL_R_EINVAL;
+ }
if ((res = __app_send_raw_with_noreply(pid, cmd, kb_data, datalen)) < 0) {
switch (res) {
case -EINVAL:
return 0;
}
+static int __app_pause_local()
+{
+ if (!aul_is_initialized())
+ return AUL_R_ENOINIT;
+
+ app_pause();
+
+ return 0;
+}
+
/**
* @brief start caller with kb
* @return callee's pid
int must_free = 0;
int ret = 0;
+#ifdef _APPFW_FEATURE_APP_CONTROL_LITE
+ char oldZone[64] = { 0, };
+ pkgmgrinfo_pkginfo_set_zone(_cur_zone, oldZone, 64);
+#endif
+
+ traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "AUL:REQ_TO_PAD");
SECURE_LOGD("launch request : %s", pkgname);
if (kb == NULL) {
kb = bundle_create();
+ if (kb == NULL)
+ return AUL_R_ERROR;
must_free = 1;
- } else
+ } else {
__clear_internal_key(kb);
+ }
- bundle_add(kb, AUL_K_PKG_NAME, pkgname);
+ ret = bundle_add(kb, AUL_K_PKG_NAME, pkgname);
+ if (ret != BUNDLE_ERROR_NONE) {
+ if (must_free)
+ bundle_free(kb);
+ return AUL_R_ERROR;
+ }
__set_stime(kb);
- if(cmd == APP_START_ASYNC)
+
+ switch (cmd) {
+ case APP_START_ASYNC:
+ case APP_PAUSE:
+ case APP_PAUSE_BY_PID:
ret = app_send_cmd_with_noreply(AUL_UTIL_PID, cmd, kb);
- else
+ break;
+ default:
ret = app_send_cmd(AUL_UTIL_PID, cmd, kb);
+ break;
+ }
_D("launch request result : %d", ret);
if (ret == AUL_R_LOCAL
#endif
) {
_E("app_request_to_launchpad : Same Process Send Local");
- bundle *b;
+ bundle *b = NULL;
#ifdef _APPFW_FEATURE_APP_CONTROL_LITE
if(ret == AUL_R_UG_LOCAL) {
case APP_RESUME_BY_PID:
ret = __app_resume_local();
break;
+ case APP_PAUSE:
+ case APP_PAUSE_BY_PID:
+ ret = __app_pause_local();
+ break;
default:
_E("no support packet");
}
if (must_free)
bundle_free(kb);
+#ifdef _APPFW_FEATURE_APP_CONTROL_LITE
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
+#endif
+
+ traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
+
return ret;
}
return -1;
}
- if (pkt->cmd != APP_RESULT && pkt->cmd != APP_CANCEL && cr.uid != 0) {
+ if (pkt->cmd != APP_RESULT && pkt->cmd != APP_CANCEL && pkt->cmd != APP_SUSPEND && pkt->cmd != APP_WAKE
+ &&cr.uid != 0 && cr.uid != SYSTEM_UID) {
_E("security error");
__send_result_to_launchpad(clifd, -1);
free(pkt);
}
if (pkt->cmd != APP_RESULT && pkt->cmd != APP_CANCEL && pkt->cmd != APP_KEY_EVENT && pkt->cmd != APP_TERM_BY_PID_ASYNC
-#ifdef _APPFW_FEATURE_VISIBILITY_CHECK_BY_LCD_STATUS
- && pkt->cmd != APP_PAUSE_LCD_OFF && pkt->cmd != APP_RESUME_LCD_ON
-#endif
- ) {
+ && pkt->cmd != APP_SUSPEND && pkt->cmd != APP_WAKE ) {
ret = __send_result_to_launchpad(clifd, 0);
if (ret < 0) {
free(pkt);
app_resume();
break;
+ case APP_SUSPEND:
+ app_prepare_to_suspend();
+ break;
+ case APP_WAKE:
+ app_prepare_to_wake();
+ break;
case APP_TERM_BY_PID: /* run in callee */
case APP_TERM_BY_PID_ASYNC:
app_terminate();
break;
+ case APP_TERM_BGAPP_BY_PID:
+ bgapp_terminate();
+ break;
+
case APP_TERM_REQ_BY_PID: /* run in callee */
app_subapp_terminate_request();
break;
bundle_free(kbundle);
break;
-#ifdef _APPFW_FEATURE_VISIBILITY_CHECK_BY_LCD_STATUS
- case APP_PAUSE_LCD_OFF:
- app_pause_lcd_off();
+ case APP_PAUSE_BY_PID:
+ app_pause();
break;
- case APP_RESUME_LCD_ON:
- app_resume_lcd_on();
- break;
-#endif
default:
_E("no support packet");
}
int aul_initialize()
{
if (aul_initialized) {
- //_E("aul already initialized");
+ _E("aul already initialized");
return AUL_R_ECANCELED;
}
-
- aul_fd = __create_server_sock(getpid());
+ aul_fd = __create_server_sock(getpid() + _pid_offset);
if (aul_fd < 0) {
_E("aul_init create sock failed");
return AUL_R_ECOMM;
if (aul_initialized) {
close(aul_fd);
+ aul_initialized = 0;
}
return;
return ret;
}
+SLPAPI int aul_terminate_bgapp_pid(int pid)
+{
+ char pkgname[MAX_PID_STR_BUFSZ];
+ int ret;
+
+ if (pid <= 0)
+ return AUL_R_EINVAL;
+
+ snprintf(pkgname, MAX_PID_STR_BUFSZ, "%d", pid);
+ ret = app_request_to_launchpad(APP_TERM_BGAPP_BY_PID, pkgname, NULL);
+ return ret;
+}
+
SLPAPI int aul_terminate_pid_without_restart(int pid)
{
char pkgname[MAX_PID_STR_BUFSZ];
}
#endif
+SLPAPI int aul_pause_app(const char *appid)
+{
+ int ret;
+
+ if (appid == NULL)
+ return AUL_R_EINVAL;
+
+ ret = app_request_to_launchpad(APP_PAUSE, appid, NULL);
+ return ret;
+}
+
+SLPAPI int aul_pause_pid(int pid)
+{
+ char app_pid[MAX_PID_STR_BUFSZ];
+ int ret;
+
+ if (pid <= 0)
+ return AUL_R_EINVAL;
+
+ snprintf(app_pid, MAX_PID_STR_BUFSZ, "%d", pid);
+ ret = app_request_to_launchpad(APP_PAUSE_BY_PID, app_pid, NULL);
+ return ret;
+}
+
/* vi: set ts=8 sts=8 sw=8: */
*
*/
-
+#define _GNU_SOURCE
#include <glib.h>
#include <poll.h>
#include <bundle.h>
#include "launch.h"
#include "simple_util.h"
#include <Ecore.h>
+#include <bundle_internal.h>
static GSource *src;
gpollfd = (GPollFD *) g_malloc(sizeof(GPollFD));
if (gpollfd == NULL) {
- _E("out of memory");
g_source_unref(src);
- close(fd);
return AUL_R_ERROR;
}
if (b == NULL) {
_E("bundle for APP_START is NULL");
}
- if (g_idle_add(__app_start_internal, b) > 0)
+ if (g_idle_add_full(G_PRIORITY_DEFAULT, __app_start_internal, b, NULL) > 0)
return AUL_R_OK;
- else
+ else {
+ _E("g_idle_add_full() failed.");
return AUL_R_ERROR;
+ }
}
SLPAPI int aul_launch_argv_handler_for_efl(int argc, char **argv)
_E("bundle for APP_START is NULL");
}
- idler = ecore_idler_add(__app_start_internal, b);
+ idler = ecore_idler_add((Ecore_Task_Cb)__app_start_internal, b);
if (idler)
return AUL_R_OK;
else
*
*/
-
+#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
+#include <vasum.h>
+#include <bundle_internal.h>
#include "aul.h"
+#include "aul_svc.h"
#include "aul_api.h"
#include "app_sock.h"
#include "simple_util.h"
#include "launch.h"
#include "aul_util.h"
+#include "aul_zone.h"
/*#define ACTIVATE_PREEMPT_FEATURE*/
static app_resultcb_info_t *rescb_head2 = NULL;
#endif
-
static int is_subapp = 0;
subapp_fn subapp_cb = NULL;
void *subapp_data = NULL;
int launched_pid)
{
app_resultcb_info_t *info;
- int pgid;
char *fwdpid_str;
if (((info = __find_resultcb(launched_pid)) == NULL)
|| (launched_pid < 0)) {
- _E("reject by pid - wait pid = %d, recvd pid = %d\n", getpid(),
- launched_pid);
-
- /* second chance - support app launched by shell script*/
- pgid = getpgid(launched_pid);
- if (pgid <= 1)
- return -1;
- if ((info = __find_resultcb(pgid)) == NULL) {
- _E("second chance : also reject pgid - %d\n", pgid);
- return -1;
- }
+ _E("reject by pid - wait pid = %d, recvd pid = %d\n", getpid(), launched_pid);
+ return -1;
}
if (info->cb_func == NULL || kb == NULL)
__remove_resultcb(info);
__add_resultcb2(newinfo.launched_pid, newinfo.cb_func, newinfo.priv_data);
- _D("change callback __AUL_FWD_UG_ID__ - %d\n", newinfo.launched_pid);
+ _D("change callback, fwd pid: %d", newinfo.launched_pid);
goto end;
}
__remove_resultcb(info);
__add_resultcb(newinfo.launched_pid, newinfo.cb_func, newinfo.priv_data);
- _D("change callback - %s\n",AUL_K_FWD_CALLEE_PID);
+ _D("change callback, fwd pid: %d", newinfo.launched_pid);
goto end;
}
int ret;
#ifdef _APPFW_FEATURE_APP_CONTROL_LITE
int id = -1;
- char id_str[256] = {0, };
#endif
+ char id_str[256] = {0, };
if (!aul_is_initialized()) {
if (aul_launch_init(NULL, NULL) < 0)
pthread_mutex_lock(&result_lock);
#ifdef _APPFW_FEATURE_APP_CONTROL_LITE
id = rand();
- sprintf(id_str, "%d", id);
+ snprintf(id_str, sizeof(id_str), "%d", id);
bundle_add(kb, "__AUL_UG_ID__", id_str);
#endif
+ if (_pid_offset > 0) {
+ snprintf(id_str, sizeof(id_str), "%d", getpid() + _pid_offset);
+ bundle_add(kb, AUL_K_HOST_PID, id_str);
+ }
+
ret = app_request_to_launchpad(APP_START_RES, pkgname, kb);
if (ret > 0)
__add_resultcb(ret, cbfunc, data);
bundle_del(kb, AUL_K_ORG_CALLER_PID);
bundle_add(kb, AUL_K_ORG_CALLER_PID, caller);
+ bundle_del(kb, AUL_SVC_K_CAN_BE_LEADER);
+ bundle_del(kb, AUL_SVC_K_REROUTE);
+ bundle_del(kb, AUL_SVC_K_RECYCLE);
+
#ifdef _APPFW_FEATURE_APP_CONTROL_LITE
caller_pid = atoi(caller);
#endif
{
if(is_subapp) {
subapp_cb(subapp_data);
-
- return 0;
+ } else {
+ __call_aul_handler(AUL_TERMINATE, NULL);
}
- return -1;
+ return 0;
}
SLPAPI int aul_set_subapp(subapp_fn cb, void *data)
return 0;
}
+static gboolean __invoke_caller_cb(gpointer data)
+{
+ int launched_pid = 0;
+ app_resultcb_info_t *info;
+
+ if (data == NULL)
+ return G_SOURCE_REMOVE;
+
+ launched_pid = GPOINTER_TO_INT(data);
+
+ info = __find_resultcb(launched_pid);
+
+ if (info && info->caller_cb)
+ info->caller_cb(info->launched_pid, info->caller_data);
+
+ return G_SOURCE_REMOVE;
+}
+
+SLPAPI int aul_invoke_caller_cb(int pid)
+{
+ if (g_idle_add_full(G_PRIORITY_DEFAULT, __invoke_caller_cb, GINT_TO_POINTER(pid), NULL) > 0)
+ return -1;
+
+ return 0;
+}
+
#ifdef _APPFW_FEATURE_APP_CONTROL_LITE
SLPAPI int aul_call_ug_result_callback(bundle *kb, int is_cancel, int id)
{
}
#endif
+
*
*/
+#define _GNU_SOURCE
#include "aul.h"
#include "aul_api.h"
#include "miregex.h"
SLPAPI int aul_get_mime_from_file(const char *filename, char *mimetype, int len)
{
const char *mime;
- struct stat statbuf;
+ struct stat statbuf;
+ char err_buf[128] = {0,};
+
if (filename == NULL)
return AUL_R_EINVAL;
if (access(filename, F_OK) != 0) {
- _E("access fail(%s)", strerror(errno));
+ if (!strerror_r(errno, err_buf, sizeof(err_buf)))
+ _E("access fail(%s)", err_buf);
+ else
+ _E("access fail(%d)", errno);
return AUL_R_EINVAL;
}
- if (stat(filename, &statbuf) != 0){
- _E("Unable to get stat, error is %s", strerror(errno));
+ if (stat(filename, &statbuf) != 0) {
+ if (!strerror_r(errno, err_buf, sizeof(err_buf)))
+ _E("Unable to get stat, error is %s", err_buf);
+ else
+ _E("Unable to get stat, error is %d", errno);
return AUL_R_ERROR;
}
if(S_ISDIR(statbuf.st_mode))
*
*/
-
+#define _GNU_SOURCE
#include "miregex.h"
#include "simple_util.h"
#include <sys/types.h>
regex_tbl *miregex_get_regex_table()
{
DIR *dp;
- struct dirent *dentry;
+ struct dirent dentry;
+ struct dirent *result = NULL;
char buf[MAX_LOCAL_BUFSZ];
miregex_file_info *info;
if (dp == NULL)
return NULL;
- while ((dentry = readdir(dp)) != NULL) {
- if (dentry->d_name[0] == '.')
+ while (readdir_r(dp, &dentry, &result) == 0 && result != NULL) {
+ if (dentry.d_name[0] == '.')
continue;
snprintf(buf, sizeof(buf), "%s/%s", MIREGEX_DIR,
- dentry->d_name);
+ dentry.d_name);
info = __get_miregex_file_info(buf);
if (info == NULL)
continue;
- if (__add_miregex(dentry->d_name,
+ if (__add_miregex(dentry.d_name,
info->regex, info->desc) < 0) {
/* TODO : invalid regular expression - will be removed*/
}
*
*/
-
+#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <pkgmgr-info.h>
+#include <pkgmgrinfo_zone.h>
#include "aul.h"
#include "aul_api.h"
#include "menu_db_util.h"
#include "simple_util.h"
#include "app_sock.h"
#include "aul_util.h"
+#include "aul_zone.h"
#define METADATA_LEGACY_LIFECYCLE "http://developer.samsung.com/tizen/metadata/legacylifecycle"
-static char *__appid = NULL;
+static const char *__appid = NULL;
+static const char *__pkgid = NULL;
static int __aul_support_legacy_lifecycle = -1;
static int __get_pkgname_bypid(int pid, char *pkgname, int len);
+SLPAPI int aul_app_get_pid(const char *appid)
+{
+ int ret = 0;
+
+ if (appid == NULL)
+ return 0;
+
+ ret = __app_send_raw(AUL_UTIL_PID, APP_GET_PID, (unsigned char *)appid, strlen(appid));
+
+ return ret;
+}
+
+SLPAPI int aul_app_get_pid_cache(const char *appid)
+{
+ int ret = 0;
+
+ if (appid == NULL)
+ return 0;
+
+ ret = __app_send_raw(AUL_UTIL_PID, APP_GET_PID_CACHE, (unsigned char *)appid, strlen(appid));
+
+ return ret;
+}
+
+SLPAPI int aul_app_get_last_caller_pid(int pid)
+{
+ int ret = 0;
+
+ if (pid < 0)
+ return 0;
+
+ ret = __app_send_raw(AUL_UTIL_PID, APP_GET_LAST_CALLER_PID, (unsigned char *)&pid, sizeof(pid));
+
+ return ret;
+}
+
SLPAPI int aul_app_is_running(const char *appid)
{
int ret = 0;
SLPAPI void aul_set_preinit_appid(const char *appid)
{
- __appid = appid;
+ __appid = (char *)appid;
}
-static char* __aul_get_preinit_appid(void)
+static const char* __aul_get_preinit_appid(void)
{
return __appid;
}
+SLPAPI void aul_set_preinit_pkgid(const char *pkgid)
+{
+ __pkgid = (char *)pkgid;
+}
+
+SLPAPI const char* aul_get_preinit_pkgid(void)
+{
+ return __pkgid;
+}
+
static int __get_pkgname_bypid(int pid, char *pkgname, int len)
{
char *cmdline;
free(cmdline);
_free_app_info_from_db(menu_info);
-
return 0;
}
app_pkt_t *pkt = NULL;
int pgid;
- if (pid == getpid()) {
- char *preinit_appid = __aul_get_preinit_appid();
-
- if (preinit_appid != NULL)
- {
-#ifdef _APPFW_FEATURE_CONTACT_PHONE_AS_ONE_APP
- if(strncmp(preinit_appid, "org.tizen.phone", MAX_PACKAGE_STR_SIZE) == 0) {
- snprintf(appid, len > MAX_PACKAGE_STR_SIZE ? MAX_PACKAGE_STR_SIZE : len, "%s", "org.tizen.contacts");
- } else {
-#endif
+ char oldZone[64] = { 0, };
+ pkgmgrinfo_pkginfo_set_zone(_cur_zone, oldZone, 64);
+
+ if (_cur_zone == NULL) {
+ if (pid == getpid()) {
+ const char *preinit_appid = __aul_get_preinit_appid();
+
+ if (preinit_appid != NULL)
+ {
snprintf(appid, len > MAX_PACKAGE_STR_SIZE ? MAX_PACKAGE_STR_SIZE : len, "%s", preinit_appid);
-#ifdef _APPFW_FEATURE_CONTACT_PHONE_AS_ONE_APP
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
+ return AUL_R_OK;
}
-#endif
- return AUL_R_OK;
}
- }
- if (pid == getpid() || getuid()==0 || geteuid()==0) {
- if (__get_pkgname_bypid(pid, appid, len) == 0) {
- SECURE_LOGD("appid for %d is %s", pid, appid);
- return AUL_R_OK;
- }
- /* support app launched by shell script*/
-
- pgid = getpgid(pid);
- if (pgid <= 1)
- return AUL_R_ERROR;
+ if (pid == getpid() || getuid()==0 || geteuid()==0) {
+ if (__get_pkgname_bypid(pid, appid, len) == 0) {
+ SECURE_LOGD("appid for %d is %s", pid, appid);
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
+ return AUL_R_OK;
+ }
+ /* support app launched by shell script*/
+ if (pid <= 0)
+ return AUL_R_ERROR;
+
+ pgid = getpgid(pid);
+ if (pgid <= 1) {
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
+ return AUL_R_ERROR;
+ }
- _D("second change pgid = %d, pid = %d", pgid, pid);
- if (__get_pkgname_bypid(pgid, appid, len) == 0)
- return AUL_R_OK;
+ _D("second change pgid = %d, pid = %d", pgid, pid);
+ if (__get_pkgname_bypid(pgid, appid, len) == 0) {
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
+ return AUL_R_OK;
+ }
- return AUL_R_ERROR;
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
+ return AUL_R_ERROR;
+ }
}
- if (appid == NULL)
+ if (appid == NULL) {
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
return AUL_R_EINVAL;
+ }
pkt = __app_send_cmd_with_result(AUL_UTIL_PID, APP_GET_APPID_BYPID, (unsigned char *)&pid, sizeof(pid));
- if(pkt == NULL)
+ if(pkt == NULL) {
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
return AUL_R_ERROR;
+ }
if(pkt->cmd == APP_GET_INFO_ERROR) {
free(pkt);
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
return AUL_R_ERROR;
}
snprintf(appid, len, "%s", pkt->data);
free(pkt);
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
return AUL_R_OK;
}
char *cmdline;
app_info_from_db *menu_info;
+ if (pid == getpid()) {
+ const char *preinit_pkgid = aul_get_preinit_pkgid();
+ if (preinit_pkgid != NULL) {
+ snprintf(pkgid, len, "%s", preinit_pkgid);
+ return AUL_R_OK;
+ }
+ }
+
cmdline = __proc_get_cmdline_bypid(pid);
if (cmdline == NULL)
return -1;
{
app_pkt_t *pkt = NULL;
int pgid;
+ char oldZone[64] = { 0, };
+ pkgmgrinfo_pkginfo_set_zone(_cur_zone, oldZone, 64);
if(pid == getpid() || getuid()==0 || geteuid()==0) {
if (__get_pkgid_bypid(pid, pkgid, len) == 0) {
- SECURE_LOGD("appid for %d is %s", pid, pkgid);
+ SECURE_LOGD("pkgid for %d is %s", pid, pkgid);
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
return AUL_R_OK;
}
/* support app launched by shell script*/
pgid = getpgid(pid);
- if (pgid <= 1)
+ if (pgid <= 1) {
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
return AUL_R_ERROR;
+ }
_D("second change pgid = %d, pid = %d", pgid, pid);
- if (__get_pkgid_bypid(pgid, pkgid, len) == 0)
+ if (__get_pkgid_bypid(pgid, pkgid, len) == 0) {
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
return AUL_R_OK;
+ }
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
return AUL_R_ERROR;
}
- if (pkgid == NULL)
+ if (pkgid == NULL) {
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
return AUL_R_EINVAL;
+ }
- pkt = __app_send_cmd_with_result(AUL_UTIL_PID, APP_GET_APPID_BYPID, (unsigned char *)&pid, sizeof(pid));
+ pkt = __app_send_cmd_with_result(AUL_UTIL_PID, APP_GET_PKGID_BYPID, (unsigned char *)&pid, sizeof(pid));
- if(pkt == NULL)
+ if(pkt == NULL) {
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
return AUL_R_ERROR;
+ }
if(pkt->cmd == APP_GET_INFO_ERROR) {
free(pkt);
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
return AUL_R_ERROR;
}
-
snprintf(pkgid, len, "%s", pkt->data);
free(pkt);
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
+
return AUL_R_OK;
}
-
SLPAPI int aul_app_get_cmdline_bypid(int pid, char *cmdline, int len)
{
app_pkt_t *pkt = NULL;
SLPAPI int aul_get_support_legacy_lifecycle(void)
{
- if (__aul_support_legacy_lifecycle != -1)
+ char oldZone[64] = { 0, };
+
+ pkgmgrinfo_pkginfo_set_zone(_cur_zone, oldZone, 64);
+ if (__aul_support_legacy_lifecycle != -1) {
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
return __aul_support_legacy_lifecycle;
+ }
int ret = 0;
pkgmgrinfo_appinfo_h handle = NULL;
char *metadata_value = NULL;
+ if (!__appid) {
+ char appid[128] = {0,};
+
+ ret = aul_app_get_appid_bypid(getpid(), appid, sizeof(appid));
+ if (ret != AUL_R_OK) {
+ _E("Failed to get appid");
+ return 0;
+ }
+
+ __appid = strdup(appid);
+ }
+
ret = pkgmgrinfo_appinfo_get_appinfo(__appid, &handle);
- if (ret != PMINFO_R_OK)
+ if (ret != PMINFO_R_OK) {
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
return 0;
+ }
ret = pkgmgrinfo_appinfo_get_metadata_value(handle, METADATA_LEGACY_LIFECYCLE, &metadata_value);
if (ret != PMINFO_R_OK) {
}
pkgmgrinfo_appinfo_destroy_appinfo(handle);
-
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
return __aul_support_legacy_lifecycle;
}
+SLPAPI char *aul_get_group_info(void)
+{
+ app_pkt_t *pkt = NULL;
+ char *result = NULL;
+ int len = 0;
+
+ pkt = __app_send_cmd_with_result(AUL_UTIL_PID, APP_GET_GROUP_INFO, NULL, 0);
+ if (pkt) {
+ len = strlen((const char *)pkt->data);
+ result = (char *)malloc(sizeof(char) * (len +1));
+ if (result == NULL) {
+ _E("Failed to allocate memory");
+ free(pkt);
+ return NULL;
+ }
+ strncpy(result, (const char *)pkt->data, len);
+ result[len] = 0;
+ free(pkt);
+ }
+
+ return result;
+}
*
*/
+#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/sysinfo.h>
+#include <limits.h>
#include "aul.h"
#include "aul_api.h"
#include "simple_util.h"
+#include "aul_zone.h"
#define _MAX_STATUS_BUF_SIZE 64
#define _MAX_STAT_BUF_SIZE 1024
long long __get_process_running_time(pid_t pid)
{
- char proc_path[sizeof("/proc//stat") + sizeof(int) * 3] = { 0, };
+ char proc_path[_MAX_STAT_BUF_SIZE] = { 0, };
char *line = NULL;
ssize_t res = -1;
int i = 0;
if (pid == -1) //self
{
_D("self");
- strcpy(proc_path, "/proc/self/stat");
+ snprintf(proc_path, sizeof(proc_path), "%sproc/self/stat", _get_root_path());
}
else if (pid > 0)
{
SECURE_LOGD("pid: %d", pid);
- sprintf(proc_path, "/proc/%u/task", pid);
+ snprintf(proc_path, sizeof(proc_path), "%sproc/%u/task", _get_root_path(), pid);
_E("Not supported");
return -1;
}
{
if (strncmp(field, key, strlen(key)) == 0)
{
+ if (value > (INT_MAX / 1024)) {
+ value = INT_MAX / 1024;
+ }
+
SECURE_LOGD("PROC %s VALUE: %d\n", field, value * 1024);
fclose(fp);
SLPAPI int aul_get_app_allocated_memory(void)
{
- return __get_info_from_proc(PROC_PROCESS_STATUS_INFO, PROC_KEY_PROCESS_MEMORY);
+ char buf[_MAX_STAT_BUF_SIZE] = {0, };
+
+ snprintf(buf, _MAX_STAT_BUF_SIZE - 1, "%s%s", _get_root_path(),
+ PROC_PROCESS_STATUS_INFO);
+ return __get_info_from_proc(buf, PROC_KEY_PROCESS_MEMORY);
}
SLPAPI long long aul_get_app_running_time(void)
/*
- * aul
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
*
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
+ * distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
*/
+#define _GNU_SOURCE
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
-
#include <stdio.h>
#include <string.h>
#include <bundle.h>
-
+#include <bundle_internal.h>
+#include <glib.h>
+#include <string.h>
+#include <pthread.h>
+#include <dlfcn.h>
+#include <Ecore_X.h>
+#include <Ecore.h>
+#include <iniparser.h>
+#include <pkgmgr-info.h>
+#include <pkgmgrinfo_zone.h>
#include "aul.h"
#include "aul_api.h"
+#include "aul_svc.h"
+#include "aul_svc_db.h"
+#include "simple_util.h"
+#include "aul_svc_priv_key.h"
+#include "aul_zone.h"
+#include "delegator_client.h"
+#include "launch.h"
+
+/* callback handling */
+typedef struct _aul_svc_cb_info_t {
+ aul_svc_res_fn cb_func;
+ int request_code;
+ void *data;
+} aul_svc_cb_info_t;
+
+typedef struct _aul_svc_resolve_info_t {
+ char *pkgname;
+ char *op;
+ char *uri;
+ char *scheme;
+ char *host;
+ char *uri_r_info;
+ char *origin_mime;
+ char *mime;
+ char *m_type;
+ char *s_type;
+ char *category;
+ char *win_id;
+ int mime_set;
+} aul_svc_resolve_info_t;
+
+typedef struct _aul_svc_transient_cb_info_t {
+ aul_svc_host_res_fn cb_func;
+ Ecore_X_Window win_id;
+ void *data;
+} aul_svc_transient_cb_info_t;
+
+pthread_mutex_t iniparser_lock = PTHREAD_MUTEX_INITIALIZER;
+GSList *tmp_list;
+
+static aul_svc_cb_info_t *__create_rescb(int request_code,
+ aul_svc_res_fn cbfunc,
+ void *data);
+static void __remove_rescb(aul_svc_cb_info_t *info);
+static int __set_bundle(bundle *b, const char *key, const char *value);
+static void __aul_cb(bundle *b, int is_cancel, void *data);
+static int __run_svc_with_pkgname(char *pkgname, bundle *b, int request_code,
+ aul_svc_res_fn cbfunc, void *data);
+static int __get_resolve_info(bundle *b, aul_svc_resolve_info_t *info);
+static int __free_resolve_info_data(aul_svc_resolve_info_t *info);
+
+static void __set_transient_for(Ecore_X_Window callee, Ecore_X_Window caller,
+ void *data);
+
+static char *white_list[] = {
+ APP_SELECTOR,
+ SHARE_PANEL,
+ NULL
+};
+
+static bool __is_special_app(const char *appid)
+{
+ const char *id;
+ int i = 0;
+
+ if (appid == NULL)
+ return false;
+
+ while ((id = white_list[i]) != NULL) {
+ if (strcmp(id, appid) == 0)
+ return true;
+ i++;
+ }
+ return false;
+}
+
+static Eina_Bool __transient_cb(void *data, int type, void *event)
+{
+ Ecore_X_Event_Window_Hide *ev;
+ aul_svc_transient_cb_info_t* cb_info;
+
+ if ((!event) || (!data)) {
+ _E("input param of transient cb is null");
+ return ECORE_CALLBACK_CANCEL;
+ }
+
+ ev = event;
+ cb_info = (aul_svc_transient_cb_info_t*) data;
+
+ if (ev->win == cb_info->win_id) {
+ if (cb_info->cb_func)
+ cb_info->cb_func(cb_info->data);
+ ecore_main_loop_quit();
+ }
+
+ return ECORE_CALLBACK_RENEW;
+}
+
+static int __aul_subapp_cb(void *data)
+{
+ aul_svc_transient_cb_info_t* cb_info;
+
+ cb_info = (aul_svc_transient_cb_info_t*) data;
+
+ cb_info->cb_func(cb_info->data);
+ ecore_main_loop_quit();
+
+ return 0;
+}
+
+static aul_svc_cb_info_t *__create_rescb(int request_code,
+ aul_svc_res_fn cbfunc,
+ void *data)
+{
+ aul_svc_cb_info_t* info;
+
+ info = (aul_svc_cb_info_t*)calloc(1, sizeof(aul_svc_cb_info_t));
+ if (info == NULL)
+ return NULL;
+
+ info->request_code = request_code;
+ info->cb_func = cbfunc;
+ info->data = data;
+
+ return info;
+}
+
+static void __remove_rescb(aul_svc_cb_info_t *info)
+{
+ if (info) free(info);
+}
+
+static int __set_bundle(bundle *b, const char *key, const char *value)
+{
+ const char *val = NULL;
+
+ val = bundle_get_val(b, key);
+ if (val) {
+ if ( bundle_del(b, key) != 0 ) {
+ return AUL_SVC_RET_ERROR;
+ }
+ }
+
+ if (!value)
+ return AUL_SVC_RET_EINVAL;
+
+ if ( bundle_add(b, key, value) != 0 ) {
+ return AUL_SVC_RET_ERROR;
+ }
+
+ _D("__set_bundle");
+
+ return AUL_SVC_RET_OK;
+}
+
+static int __set_bundle_array(bundle *b, const char *key, const char **value,
+ int len)
+{
+
+ int type;
+ type = aul_svc_data_is_array(b, key);
+
+ if (type == 1) {
+ if ( bundle_del(b, key) != 0 ) {
+ return AUL_SVC_RET_ERROR;
+ }
+ }
+
+ if (!value)
+ return AUL_SVC_RET_EINVAL;
+
+ if ( bundle_add_str_array(b, key, value, len) != 0 ) {
+ return AUL_SVC_RET_ERROR;
+ }
+
+ _D("__set_bundle_array");
+
+ return AUL_SVC_RET_OK;
+}
+
+static void __aul_cb(bundle *b, int is_cancel, void *data)
+{
+ const char *val = NULL;
+ aul_svc_cb_info_t* cb_info;
+ int res;
+
+ if (is_cancel)
+ res = AUL_SVC_RES_CANCEL;
+ else {
+ /* get result_code from bundle */
+ val = bundle_get_val(b, AUL_SVC_K_RES_VAL);
+ res = (val == NULL) ? AUL_SVC_RES_NOT_OK : atoi(val);
+ }
+
+ /* remove result_code from bundle */
+ bundle_del(b, AUL_SVC_K_RES_VAL);
+
+ /* find corresponding callback */
+ cb_info = (aul_svc_cb_info_t*)data;
+
+ cb_info->cb_func(b, cb_info->request_code, (aul_svc_result_val)res,
+ cb_info->data);
+ __remove_rescb(cb_info);
+
+
+ return;
+}
+
+static int __run_svc_with_pkgname(char *pkgname, bundle *b, int request_code,
+ aul_svc_res_fn cbfunc, void *data)
+{
+ aul_svc_cb_info_t *cb_info = NULL;
+ int ret = -1;
+
+ if ( bundle_get_type(b, AUL_SVC_K_SELECTOR_EXTRA_LIST) != BUNDLE_TYPE_NONE ) {
+ if ( !aul_svc_get_pkgname(b) ) {
+ pkgname = APP_SELECTOR;
+ }
+ }
+
+ if ( bundle_get_val(b, AUL_K_FORCE_LAUNCH_APP_SELECTOR) ) {
+ pkgname = APP_SELECTOR;
+ }
+
+ if ( __is_special_app(pkgname)) {
+ bundle_del(b, AUL_SVC_K_CAN_BE_LEADER);
+ bundle_add_str(b, AUL_SVC_K_CAN_BE_LEADER, "true");
+ bundle_del(b, AUL_SVC_K_REROUTE);
+ bundle_add_str(b, AUL_SVC_K_REROUTE, "true");
+ bundle_del(b, AUL_SVC_K_RECYCLE);
+ bundle_add_str(b, AUL_SVC_K_RECYCLE, "true");
+
+ }
+
+ if (cbfunc) {
+ SECURE_LOGD("pkg_name : %s - with result", pkgname);
+
+ cb_info = __create_rescb(request_code, cbfunc, data);
+ ret = aul_launch_app_with_result(pkgname, b, __aul_cb, cb_info);
+ } else {
+ SECURE_LOGD("pkg_name : %s - no result", pkgname);
+
+#ifdef _APPFW_FEATURE_MULTI_INSTANCE
+ const char* data = bundle_get_val(b, AUL_SVC_K_MULTI_INSTANCE);
+ if (data) {
+ SECURE_LOGD("multi_instance value = %s", data);
+ }
+
+ if (data && strncmp(data, "TRUE", strlen("TRUE")) == 0) {
+ ret = aul_launch_app_for_multi_instance(pkgname, b);
+ } else {
+ ret = aul_launch_app(pkgname, b);
+ }
+#else
+ ret = aul_launch_app(pkgname, b);
+#endif
+ }
+
+ if (ret < 0) {
+ switch (ret) {
+ case AUL_R_EILLACC:
+ ret = AUL_SVC_RET_EILLACC;
+ break;
+ case AUL_R_EINVAL:
+ ret = AUL_SVC_RET_EINVAL;
+ break;
+ case AUL_R_ETERMINATING:
+ ret = AUL_SVC_RET_ETERMINATING;
+ break;
+ case AUL_R_EREJECTED:
+ ret = AUL_SVC_RET_EREJECTED;
+ break;
+ case AUL_R_ENOAPP:
+ ret = AUL_SVC_RET_ENOMATCH;
+ break;
+ default:
+ ret = AUL_SVC_RET_ELAUNCH;
+ }
+ }
+
+ return ret;
+}
+
+static int __get_resolve_info(bundle *b, aul_svc_resolve_info_t *info)
+{
+ char *tmp = NULL;
+ char *strtok_buf = NULL;
+ int ret = -1;
+
+ info->op = (char *)aul_svc_get_operation(b);
+ info->uri = (char *)aul_svc_get_uri(b);
+
+ if ((info->uri) && (strcmp(info->uri, "") == 0)) {
+ _E("Uri is empty");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ info->origin_mime = info->mime = (char *)aul_svc_get_mime(b);
+ info->pkgname = (char *)aul_svc_get_pkgname(b);
+ info->category = (char *)aul_svc_get_category(b);
+ info->win_id = (char *)bundle_get_val(b, AUL_SVC_K_WIN_ID);
+
+ _D("getting resolve info for: operation - %s / uri - %s / mime - %s\n",
+ info->op, info->uri, info->mime);
+
+ if (info->uri) {
+ if (strncmp(info->uri, "/", 1) == 0) {
+ if (!info->mime) {
+ info->origin_mime = info->mime = malloc(MAX_MIME_STR_SIZE);
+ if (info->mime == NULL) {
+ _E("out of memory");
+ return AUL_SVC_RET_ERROR;
+ }
+
+ ret = aul_get_mime_from_file(info->uri, info->mime, MAX_MIME_STR_SIZE);
+ info->mime_set = 1;
+ }
+ info->uri = NULL;
+ } else if (strncmp(info->uri, "file:///", 8) == 0) {
+ if (!info->mime) {
+ info->origin_mime = info->mime = malloc(MAX_MIME_STR_SIZE);
+ if (info->mime == NULL) {
+ _E("out of memory");
+ return AUL_SVC_RET_ERROR;
+ }
+
+ ret = aul_get_mime_from_file(&info->uri[7], info->mime, MAX_MIME_STR_SIZE);
+ info->mime_set = 1;
+ }
+ } else if (strncmp(info->uri, "file:/", 6) == 0) {
+ if (!info->mime) {
+ info->origin_mime = info->mime = malloc(MAX_MIME_STR_SIZE);
+ if (info->mime == NULL) {
+ _E("out of memory");
+ return AUL_SVC_RET_ERROR;
+ }
+
+ ret = aul_get_mime_from_file(&info->uri[5], info->mime, MAX_MIME_STR_SIZE);
+ info->mime_set = 1;
+ }
+ }
+
+ if (info->mime_set == 1 && ret < 0) {
+ _E("aul_get_mime_from_file : %d", ret);
+ free(info->mime);
+ info->origin_mime = info->mime = NULL;
+ info->mime_set = 0;
+ }
+ }
+
+ if (info->uri) {
+ GRegex *regex;
+ GMatchInfo *match_info;
+ GError *error = NULL;
+
+ regex = g_regex_new ("^(([^:/?#]+):)?(//([^/?#]*))?", 0, 0, &error);
+ if (g_regex_match (regex, info->uri, 0, &match_info) == FALSE) {
+ g_regex_unref (regex);
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ info->scheme = g_match_info_fetch (match_info, 2);
+ info->host = g_match_info_fetch (match_info, 4);
+
+ if (info->scheme && info->host) {
+ info->uri_r_info = malloc(MAX_SCHEME_STR_SIZE + MAX_HOST_STR_SIZE + 2);
+ if (info->uri_r_info == NULL) {
+ _E("out of memory");
+ g_match_info_free(match_info);
+ g_regex_unref(regex);
+ return AUL_SVC_RET_ERROR;
+ }
+
+ snprintf(info->uri_r_info, MAX_SCHEME_STR_SIZE + MAX_HOST_STR_SIZE + 1,
+ "%s://%s", info->scheme, info->host);
+ }
+
+ g_match_info_free (match_info);
+ g_regex_unref (regex);
+
+ } else {
+ info->scheme = strdup("NULL");
+ }
+
+ if (!info->mime)
+ info->mime = strdup("NULL");
+ else {
+ info->m_type = malloc(MAX_LOCAL_BUFSZ);
+ if (info->m_type == NULL) {
+ _E("ouf of memory");
+ return AUL_SVC_RET_ERROR;
+ }
+
+ info->s_type = malloc(MAX_LOCAL_BUFSZ);
+ if (info->s_type == NULL) {
+ _E("out of memory");
+ free(info->m_type);
+ return AUL_SVC_RET_ERROR;
+ }
+
+ tmp = strdup(info->mime);
+ strtok_buf = strtok(tmp, "/");
+ if (strtok_buf)
+ strncpy(info->m_type, strtok_buf, MAX_LOCAL_BUFSZ - 1);
+ strtok_buf = strtok(NULL, "/");
+ if (strtok_buf)
+ strncpy(info->s_type, strtok_buf, MAX_LOCAL_BUFSZ - 1);
+ free(tmp);
+
+ if (strncmp(info->m_type, "*", 1) == 0) {
+ strncpy(info->m_type, "%", MAX_LOCAL_BUFSZ - 1);
+ }
+ if (strncmp(info->s_type, "*", 1) == 0) {
+ strncpy(info->s_type, "%", MAX_LOCAL_BUFSZ - 1);
+ }
+
+ info->mime = malloc(MAX_MIME_STR_SIZE);
+ if (info->mime == NULL) {
+ _E("out of memory");
+ free(info->s_type);
+ free(info->m_type);
+ return AUL_SVC_RET_ERROR;
+ }
+
+ snprintf(info->mime, MAX_MIME_STR_SIZE - 1, "%s/%s", info->m_type,
+ info->s_type);
+ }
+
+ return 0;
+}
+
+static int __free_resolve_info_data(aul_svc_resolve_info_t *info)
+{
+ if (info->mime)
+ free(info->mime);
+ if (info->scheme)
+ free(info->scheme);
+ if (info->host)
+ free(info->host);
+ if (info->m_type)
+ free(info->m_type);
+ if (info->s_type)
+ free(info->s_type);
+ if (info->uri_r_info)
+ free(info->uri_r_info);
+ if (info->mime_set)
+ free(info->origin_mime);
+
+ return 0;
+}
+
+static void __set_transient_for(Ecore_X_Window callee, Ecore_X_Window caller,
+ void *data)
+{
+ void (*ecore_x_icccm_transient_for_set) (Ecore_X_Window, Ecore_X_Window);
+ void (*ecore_x_window_client_manage) (Ecore_X_Window);
+ int* ecore_x_event_window_destroy;
+
+ void *handle = dlopen("libecore_x.so.1", RTLD_LAZY | RTLD_LOCAL);
+ if (!handle) {
+ _E("dlopen error %s", dlerror());
+ return;
+ }
+
+ ecore_x_icccm_transient_for_set = dlsym(handle,
+ "ecore_x_icccm_transient_for_set");
+ if (ecore_x_icccm_transient_for_set == NULL) {
+ _E("dlsym error");
+ dlclose(handle);
+ return;
+ }
+
+ ecore_x_icccm_transient_for_set(callee, caller);
+
+ ecore_x_window_client_manage = dlsym(handle, "ecore_x_window_client_manage");
+ if (ecore_x_window_client_manage == NULL) {
+ _E("dlsym error");
+ dlclose(handle);
+ return;
+ }
+
+ ecore_x_window_client_manage(caller);
+
+ ecore_x_event_window_destroy = dlsym(handle, "ECORE_X_EVENT_WINDOW_DESTROY");
+ if (ecore_x_event_window_destroy == NULL) {
+ _E("dlsym error");
+ dlclose(handle);
+ return;
+ }
+
+ ecore_event_handler_add(*ecore_x_event_window_destroy, __transient_cb, data);;
+
+ dlclose(handle);
+}
+
+static char* __get_alias_appid(char *appid)
+{
+ char *alias_id = NULL;
+ char *val = NULL;
+ char key_string[MAX_PACKAGE_STR_SIZE + 5];
+ dictionary *dic;
+
+ dic = iniparser_load("/usr/share/appsvc/alias.ini");
+
+ if (dic == NULL)
+ return NULL;
+
+ snprintf(key_string, sizeof(key_string), "Alias:%s", appid);
+ pthread_mutex_lock(&iniparser_lock);
+ val = iniparser_getstr(dic, key_string);
+ pthread_mutex_unlock(&iniparser_lock);
+
+ SECURE_LOGD("alias_id : %s", val);
+
+ if (val != NULL) {
+ alias_id = malloc(MAX_PACKAGE_STR_SIZE);
+ if (alias_id == NULL) {
+ _E("out of memory");
+ iniparser_freedict(dic);
+ return NULL;
+ }
+
+ strncpy(alias_id, val, MAX_PACKAGE_STR_SIZE - 1);
+ }
+
+ iniparser_freedict(dic);
+
+ return alias_id;
+}
+
+static int __get_list_with_condition_mime_extened(char *op, char *uri,
+ char *mime, char *m_type, char *s_type, GSList **pkg_list)
+{
+ char *tmp;
+
+ tmp = malloc(MAX_MIME_STR_SIZE);
+ if (tmp == NULL) {
+ _E("out of memory");
+ return -1;
+ }
+
+ _svc_db_get_list_with_condition(op, uri, mime, pkg_list);
+ if ((strncmp(mime, "NULL", 4) != 0) && (strncmp(s_type, "%", 1) != 0)) {
+ snprintf(tmp, MAX_MIME_STR_SIZE - 1, "%s/*", m_type);
+ _svc_db_get_list_with_condition(op, uri, tmp, pkg_list);
+ }
+ if ((strncmp(mime, "NULL", 4) != 0) && (strncmp(m_type, "%", 1) != 0)) {
+ snprintf(tmp, MAX_MIME_STR_SIZE - 1, "*/*");
+ _svc_db_get_list_with_condition(op, uri, tmp, pkg_list);
+ }
+
+ free(tmp);
+
+ return 0;
+}
+
+static int __get_list_with_condition_mime_extened_with_collation(char *op,
+ char *uri, char *mime, char *m_type, char *s_type, GSList **pkg_list)
+{
+ char *tmp;
+
+ tmp = malloc(MAX_MIME_STR_SIZE);
+ if (tmp == NULL) {
+ _E("out of memory");
+ return -1;
+ }
+
+ _svc_db_get_list_with_collation(op, uri, mime, pkg_list);
+ if ((strncmp(mime, "NULL", 4) != 0) && (strncmp(s_type, "%", 1) != 0)) {
+ snprintf(tmp, MAX_MIME_STR_SIZE - 1, "%s/*", m_type);
+ _svc_db_get_list_with_collation(op, uri, tmp, pkg_list);
+ }
+ if ((strncmp(mime, "NULL", 4) != 0) && (strncmp(m_type, "%", 1) != 0)) {
+ snprintf(tmp, MAX_MIME_STR_SIZE - 1, "*/*");
+ _svc_db_get_list_with_collation(op, uri, tmp, pkg_list);
+ }
+
+ free(tmp);
+
+ return 0;
+}
+
+
+static int __app_list_cb(pkgmgrinfo_appinfo_h handle, void *user_data)
+{
+ char *appid = NULL;
+ GSList **app_list = (GSList **)user_data;
+ char *str = NULL;
+ GSList *iter = NULL;
+
+ pkgmgrinfo_appinfo_get_appid(handle, &str);
+ _D("Matching application is %s", str);
+
+ for (iter = tmp_list; iter != NULL; iter = g_slist_next(iter)) {
+ if (strncmp(str, (char *)iter->data, MAX_PACKAGE_STR_SIZE - 1) == 0) {
+ appid = strdup(str);
+ *app_list = g_slist_append(*app_list, (void *)appid);
+ _D("%s is added", appid);
+ }
+ }
+
+ return 0;
+}
+
+static int __get_list_with_category(char *category, GSList **pkg_list)
+{
+ int ret;
+ pkgmgrinfo_appinfo_filter_h handle;
+ GSList *app_list = NULL;
+ GSList *iter = NULL;
+ char *list_item = NULL;
+
+ ret = pkgmgrinfo_appinfo_filter_create(&handle);
+ ret = pkgmgrinfo_appinfo_filter_add_string(handle,
+ PMINFO_APPINFO_PROP_APP_CATEGORY, category);
+
+ tmp_list = *pkg_list;
+ ret = pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, __app_list_cb,
+ &app_list);
+ if (ret != PMINFO_R_OK) {
+ pkgmgrinfo_appinfo_filter_destroy(handle);
+ return -1;
+ }
+ pkgmgrinfo_appinfo_filter_destroy(handle);
+
+ for (iter = *pkg_list; iter != NULL; iter = g_slist_next(iter)) {
+ list_item = (char *)iter->data;
+ g_free(list_item);
+ }
+ g_slist_free(*pkg_list);
+
+ *pkg_list = app_list;
+
+ return 0;
+}
+
+static int __appid_compare(gconstpointer data1, gconstpointer data2)
+{
+ char *a = (char *)data1;
+ char *b = (char *)data2;
+ return strcmp(a, b);
+}
+
+static int __check_mainapp_mode(char *operation)
+{
+ return 0;
+}
+
+static int __get_list_with_submode(char *operation, char *win_id,
+ GSList **pkg_list)
+{
+ int ret = 0;
+ int mainapp_mode = 0;
+
+ mainapp_mode = __check_mainapp_mode(operation);
+
+ SECURE_LOGD("mainapp_mode : %d", mainapp_mode);
+
+ ret = _svc_db_adjust_list_with_submode(mainapp_mode, win_id, pkg_list);
+
+ if (ret < 0) {
+ _E("error on get_list_with_submode :%d", ret);
+ return -1;
+ }
+
+ return 0;
+}
+
+SLPAPI int aul_svc_set_operation(bundle *b, const char *operation)
+{
+ if (b == NULL) {
+ _E("bundle for aul_svc_set_operation is NULL");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ return __set_bundle(b, AUL_SVC_K_OPERATION, operation);
+}
+
+SLPAPI int aul_svc_set_uri(bundle *b, const char *uri)
+{
+ if (b == NULL) {
+ _E("bundle for aul_svc_set_uri is NULL");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ return __set_bundle(b, AUL_SVC_K_URI, uri);
+}
+
+SLPAPI int aul_svc_set_mime(bundle *b, const char *mime)
+{
+ if (b == NULL) {
+ _E("bundle for aul_svc_set_mime is NULL");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ return __set_bundle(b, AUL_SVC_K_MIME, mime);
+}
+
+SLPAPI int aul_svc_add_data(bundle *b, const char *key, const char *val)
+{
+ if (b == NULL || key == NULL) {
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ /* check key for data */
+ /******************/
+
+ return __set_bundle(b, key, val);
+}
+
+SLPAPI int aul_svc_add_data_array(bundle *b, const char *key,
+ const char **val_array, int len)
+{
+ if (b == NULL || key == NULL) {
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ /* check key for data */
+ /******************/
+
+ return __set_bundle_array(b, key, val_array, len);
+}
+
+
+SLPAPI int aul_svc_set_pkgname(bundle *b, const char *pkg_name)
+{
+ if (b == NULL) {
+ _E("bundle for aul_svc_set_pkgname is NULL");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ return __set_bundle(b, AUL_SVC_K_PKG_NAME, pkg_name);
+}
+
+
+SLPAPI int aul_svc_set_appid(bundle *b, const char *appid)
+{
+ char *alias_id = NULL;
+ int ret;
+
+ if (b == NULL || appid == NULL) {
+ _E("bundle for aul_svc_set_appid is NULL");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ alias_id = __get_alias_appid((char *)appid);
+ if (alias_id == NULL) {
+ ret = __set_bundle(b, AUL_SVC_K_PKG_NAME, appid);
+ } else {
+ ret = __set_bundle(b, AUL_SVC_K_PKG_NAME, alias_id);
+ free(alias_id);
+ }
+
+ return ret;
+}
+
+SLPAPI int aul_svc_set_category(bundle *b, const char *category)
+{
+ if (b == NULL) {
+ _E("bundle for aul_svc_set_category is NULL");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ return __set_bundle(b, AUL_SVC_K_CATEGORY, category);
+}
+
+SLPAPI int aul_svc_set_launch_mode(bundle *b, const char *mode)
+{
+ if (b == NULL) {
+ _E("bundle for aul_svc_set_launch_mode is NULL");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ return __set_bundle(b, AUL_SVC_K_LAUNCH_MODE, mode);
+}
+
+SLPAPI int aul_svc_run_service(bundle *b, int request_code,
+ aul_svc_res_fn cbfunc,
+ void *data)
+{
+ aul_svc_resolve_info_t info;
+ char *pkgname;
+ char *operation;
+ int pkg_count = 0;
+ int ret = -1;
+ char oldZone[64] = { 0, };
+
+ GSList *pkg_list = NULL;
+ GSList *iter = NULL;
+ char *list_item;
+
+ if (b == NULL) {
+ _E("bundle for aul_svc_set_appid is NULL");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ pkgmgrinfo_pkginfo_set_zone(_cur_zone, oldZone, 64);
+ pkgname = (char *)aul_svc_get_pkgname(b);
+ operation = (char *)aul_svc_get_operation(b);
+
+ char *zone = NULL;
+
+ if (delegator_client_can_jump(&zone, b) == AUL_SVC_RET_OK) {
+ ret = delegator_client_launch(zone, b);
+ if (zone != NULL)
+ free(zone);
+ return ret;
+ }
+
+ /* explict*/
+ if (pkgname) {
+ if (operation == NULL)
+ aul_svc_set_operation(b, AUL_SVC_OPERATION_DEFAULT);
+ ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data);
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
+ return ret;
+ }
+
+ /* share panel */
+ if (operation && (strcmp(operation, AUL_SVC_OPERATION_SHARE) == 0
+ || strcmp(operation, AUL_SVC_OPERATION_MULTI_SHARE) == 0
+ || strcmp(operation, AUL_SVC_OPERATION_SHARE_TEXT) == 0)) {
+ ret = __run_svc_with_pkgname(SHARE_PANEL, b, request_code, cbfunc, data);
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
+ return ret;
+ }
+
+ memset(&info, 0, sizeof(aul_svc_resolve_info_t));
+ ret = __get_resolve_info(b, &info);
+ if (ret < 0) {
+ __free_resolve_info_data(&info);
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
+ return ret;
+ }
+
+ SECURE_LOGD("op - %s / mime - %s / scheme - %s\n", info.op, info.origin_mime,
+ info.scheme);
+
+ ret = _svc_db_check_perm();
+ if (ret < 0) {
+ _E("permission error : %d", ret);
+ ret = AUL_SVC_RET_EILLACC;
+ goto end;
+ }
+
+ /*uri*/
+ pkgname = _svc_db_get_app(info.op, info.origin_mime, info.uri);
+ if (pkgname == NULL) {
+ __get_list_with_condition_mime_extened_with_collation(info.op, info.uri,
+ info.mime, info.m_type, info.s_type, &pkg_list);
+ pkg_count = g_slist_length(pkg_list);
+ if (pkg_count > 0) {
+
+ if (info.uri_r_info) {
+ __get_list_with_condition_mime_extened(info.op, info.uri_r_info,
+ info.mime, info.m_type, info.s_type, &pkg_list);
+ }
+
+ __get_list_with_condition_mime_extened(info.op, info.scheme,
+ info.mime, info.m_type, info.s_type, &pkg_list);
+
+ __get_list_with_condition_mime_extened(info.op, "*",
+ info.mime, info.m_type, info.s_type, &pkg_list);
+
+ if (info.scheme && (strcmp(info.scheme, "file") == 0)
+ && info.mime && (strcmp(info.mime, "NULL") != 0)) {
+ __get_list_with_condition_mime_extened(info.op, "NULL",
+ info.mime, info.m_type, info.s_type, &pkg_list);
+ }
+
+ if (info.category) {
+ __get_list_with_category(info.category, &pkg_list);
+ }
+
+ __get_list_with_submode(info.op, info.win_id, &pkg_list);
+
+ pkg_count = g_slist_length(pkg_list);
+ _D("pkg_count : %d", pkg_count);
+
+ if (pkg_count == 1) {
+ pkgname = (char *)pkg_list->data;
+ if (pkgname != NULL) {
+ ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data);
+ goto end;
+ }
+ } else {
+ bundle_add(b, AUL_SVC_K_URI_R_INFO, info.uri);
+ ret = __run_svc_with_pkgname(APP_SELECTOR, b, request_code, cbfunc, data);
+ goto end;
+ }
+ for (iter = pkg_list; iter != NULL; iter = g_slist_next(iter)) {
+ list_item = (char *)iter->data;
+ g_free(list_item);
+ }
+ g_slist_free(pkg_list);
+ pkg_list = NULL;
+ }
+ } else {
+ ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data);
+ free(pkgname);
+ goto end;
+ }
+
+ /*scheme & host*/
+ if (info.uri_r_info) {
+ pkgname = _svc_db_get_app(info.op, info.origin_mime, info.uri_r_info);
+
+ if (pkgname == NULL) {
+ __get_list_with_condition_mime_extened(info.op, info.uri_r_info,
+ info.mime, info.m_type, info.s_type, &pkg_list);
+ pkg_count = g_slist_length(pkg_list);
+ if (pkg_count > 0) {
+ __get_list_with_condition_mime_extened(info.op, info.scheme,
+ info.mime, info.m_type, info.s_type, &pkg_list);
+
+ __get_list_with_condition_mime_extened(info.op, "*",
+ info.mime, info.m_type, info.s_type, &pkg_list);
+
+ if (info.scheme && (strcmp(info.scheme, "file") == 0)
+ && info.mime && (strcmp(info.mime, "NULL") != 0)) {
+ __get_list_with_condition_mime_extened(info.op, "NULL",
+ info.mime, info.m_type, info.s_type, &pkg_list);
+ }
+
+ if (info.category) {
+ __get_list_with_category(info.category, &pkg_list);
+ }
+
+ __get_list_with_submode(info.op, info.win_id, &pkg_list);
+
+ pkg_count = g_slist_length(pkg_list);
+ _D("pkg_count : %d", pkg_count);
+
+ if (pkg_count == 1) {
+ pkgname = (char *)pkg_list->data;
+ if (pkgname != NULL) {
+ ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data);
+ goto end;
+ }
+ } else {
+ bundle_add(b, AUL_SVC_K_URI_R_INFO, info.uri_r_info);
+ ret = __run_svc_with_pkgname(APP_SELECTOR, b, request_code, cbfunc, data);
+ goto end;
+ }
+ }
+ for (iter = pkg_list; iter != NULL; iter = g_slist_next(iter)) {
+ list_item = (char *)iter->data;
+ g_free(list_item);
+ }
+ g_slist_free(pkg_list);
+ pkg_list = NULL;
+ } else {
+ ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data);
+ free(pkgname);
+ goto end;
+ }
+ }
+
+ /*scheme*/
+ pkgname = _svc_db_get_app(info.op, info.origin_mime, info.scheme);
+
+ if (pkgname == NULL) {
+ __get_list_with_condition_mime_extened(info.op, info.scheme,
+ info.mime, info.m_type, info.s_type, &pkg_list);
+
+ __get_list_with_condition_mime_extened(info.op, "*",
+ info.mime, info.m_type, info.s_type, &pkg_list);
+
+ if (info.scheme && (strcmp(info.scheme, "file") == 0)
+ && info.mime && (strcmp(info.mime, "NULL") != 0)) {
+ __get_list_with_condition_mime_extened(info.op, "NULL",
+ info.mime, info.m_type, info.s_type, &pkg_list);
+ }
+
+ if (info.category) {
+ __get_list_with_category(info.category, &pkg_list);
+ }
+
+ __get_list_with_submode(info.op, info.win_id, &pkg_list);
+
+ pkg_count = g_slist_length(pkg_list);
+ _D("pkg_count : %d", pkg_count);
+
+ if (pkg_count == 1) {
+ pkgname = (char *)pkg_list->data;
+ if (pkgname != NULL) {
+ ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data);
+ }
+ } else if (pkg_count < 1) {
+ __free_resolve_info_data(&info);
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
+ return AUL_SVC_RET_ENOMATCH;
+ } else {
+ bundle_add(b, AUL_SVC_K_URI_R_INFO, info.scheme);
+ ret = __run_svc_with_pkgname(APP_SELECTOR, b, request_code, cbfunc, data);
+ }
+
+ for (iter = pkg_list; iter != NULL; iter = g_slist_next(iter)) {
+ list_item = (char *)iter->data;
+ g_free(list_item);
+ }
+ g_slist_free(pkg_list);
+ } else {
+ ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data);
+ free(pkgname);
+ }
+
+end:
+ __free_resolve_info_data(&info);
+
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
+ return ret;
+}
+
+SLPAPI int aul_svc_get_list(bundle *b, aul_svc_info_iter_fn iter_fn, void *data)
+{
+ aul_svc_resolve_info_t info;
+ char *pkgname = NULL;
+ int pkg_count;
+ int ret = -1;
+ char oldZone[64] = { 0, };
+
+ GSList *pkg_list = NULL;
+ GSList *iter = NULL;
+
+ if (b == NULL) {
+ _E("bundle for aul_svc_run_service is NULL");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ if (iter_fn == NULL) {
+ _E("iter_fn for aul_svc_run_service is NULL");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ pkgmgrinfo_pkginfo_set_zone(_cur_zone, oldZone, 64);
+
+ /* parse bundle */
+ memset(&info, 0, sizeof(aul_svc_resolve_info_t));
+ ret = __get_resolve_info(b, &info);
+ if (ret < 0) {
+ __free_resolve_info_data(&info);
+ return ret;
+ }
+
+ _D("operation - %s / shceme - %s / mime - %s\n", info.op, info.scheme,
+ info.mime);
+
+ __get_list_with_condition_mime_extened_with_collation(info.op, info.uri,
+ info.mime, info.m_type, info.s_type, &pkg_list);
+
+ if (info.uri_r_info) {
+ __get_list_with_condition_mime_extened(info.op, info.uri_r_info,
+ info.mime, info.m_type, info.s_type, &pkg_list);
+ }
+
+ __get_list_with_condition_mime_extened(info.op, info.scheme,
+ info.mime, info.m_type, info.s_type, &pkg_list);
+
+ __get_list_with_condition_mime_extened(info.op, "*",
+ info.mime, info.m_type, info.s_type, &pkg_list);
+
+ if (info.scheme && (strcmp(info.scheme, "file") == 0)
+ && info.mime && (strcmp(info.mime, "NULL") != 0)) {
+ __get_list_with_condition_mime_extened(info.op, "NULL",
+ info.mime, info.m_type, info.s_type, &pkg_list);
+ }
+
+ if (info.category) {
+ __get_list_with_category(info.category, &pkg_list);
+ }
+
+ __get_list_with_submode(info.op, info.win_id, &pkg_list);
+
+ pkg_count = g_slist_length(pkg_list);
+ if (pkg_count == 0) {
+ _E("Cannot find associated application");
+
+ __free_resolve_info_data(&info);
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
+ return AUL_SVC_RET_ENOMATCH;
+ }
+
+ for (iter = pkg_list; iter != NULL; iter = g_slist_next(iter)) {
+ pkgname = iter->data;
+ SECURE_LOGD("PKGNAME : %s\n", pkgname);
+ if ( iter_fn(pkgname, data) != 0)
+ break;
+ g_free(pkgname);
+ }
+
+ g_slist_free(pkg_list);
+ __free_resolve_info_data(&info);
+
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
+ return AUL_SVC_RET_OK;
+}
+
+SLPAPI int aul_svc_get_all_defapps(aul_svc_info_iter_fn iter_fn, void *data)
+{
+ char *pkgname = NULL;
+ int ret = -1;
+ char oldZone[64] = { 0, };
+
+ GSList *pkg_list = NULL;
+ GSList *iter = NULL;
+
+ pkgmgrinfo_pkginfo_set_zone(_cur_zone, oldZone, 64);
+
+ ret = _svc_db_check_perm();
+ if (ret < 0) {
+ _E("permission error : %d", ret);
+ return AUL_SVC_RET_EILLACC;
+ }
+
+ ret = _svc_db_get_list_with_all_defapps(&pkg_list);
+ if (ret < 0)
+ return ret;
+
+ for (iter = pkg_list; iter != NULL; iter = g_slist_next(iter)) {
+ pkgname = iter->data;
+ if ( iter_fn(pkgname, data) != 0)
+ break;
+ g_free(pkgname);
+ }
+
+ g_slist_free(pkg_list);
+
+ pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
+ return AUL_SVC_RET_OK;
+}
+
+SLPAPI const char *aul_svc_get_operation(bundle *b)
+{
+ return bundle_get_val(b, AUL_SVC_K_OPERATION);
+}
+
+SLPAPI const char *aul_svc_get_uri(bundle *b)
+{
+ return bundle_get_val(b, AUL_SVC_K_URI);
+}
+
+SLPAPI const char *aul_svc_get_mime(bundle *b)
+{
+ return bundle_get_val(b, AUL_SVC_K_MIME);
+}
+
+SLPAPI const char *aul_svc_get_data(bundle *b, const char *key)
+{
+ return bundle_get_val(b, key);
+}
+
+SLPAPI const char **aul_svc_get_data_array(bundle *b, const char *key, int *len)
+{
+ return bundle_get_str_array(b, key, len);
+}
+
+SLPAPI const char *aul_svc_get_pkgname(bundle *b)
+{
+ return bundle_get_val(b, AUL_SVC_K_PKG_NAME);
+}
+
+SLPAPI const char *aul_svc_get_appid(bundle *b)
+{
+ return bundle_get_val(b, AUL_SVC_K_PKG_NAME);
+}
+
+SLPAPI const char *aul_svc_get_category(bundle *b)
+{
+ return bundle_get_val(b, AUL_SVC_K_CATEGORY);
+}
+
+SLPAPI const char *aul_svc_get_launch_mode(bundle *b)
+{
+ return bundle_get_val(b, AUL_SVC_K_LAUNCH_MODE);
+}
+
+SLPAPI int aul_svc_create_result_bundle(bundle *inb, bundle **outb)
+{
+ int ret = -1;
+
+ if (inb == NULL || outb == NULL) {
+ _E("bundle is NULL");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ ret = aul_create_result_bundle(inb, outb);
+
+ /* add additional bundle */
+ /* bundle_add(outb, " ", " "); */
+
+ if (ret == AUL_R_OK)
+ ret = AUL_SVC_RET_OK;
+ else if (ret == AUL_R_EINVAL)
+ ret = AUL_SVC_RET_EINVAL;
+ else
+ ret = AUL_SVC_RET_ERROR;
+
+ return ret;
+}
+
+SLPAPI int aul_svc_send_result(bundle *b, aul_svc_result_val result)
+{
+ int ret;
+ char tmp[MAX_LOCAL_BUFSZ];
+
+ if (b == NULL) {
+ _E("aul_svc_send_result is NULL");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ if (result != AUL_SVC_RES_OK && result != AUL_SVC_RES_NOT_OK) {
+ _E("invalid result %d", (int)result);
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ /* add result_code to bundle */
+ snprintf(tmp, MAX_LOCAL_BUFSZ, "%d", (int)result);
+ ret = __set_bundle(b, AUL_SVC_K_RES_VAL, tmp);
+ if (ret < 0)
+ return AUL_SVC_RET_ERROR;
+
+ ret = aul_send_service_result(b);
+
+ /* remove result_code from bundle */
+ bundle_del(b, AUL_SVC_K_RES_VAL);
+
+ return ret;
+}
+
+SLPAPI int aul_svc_set_defapp(const char *op, const char *mime_type,
+ const char *uri,
+ const char *defapp)
+{
+ int ret;
+
+ if (op == NULL || defapp == NULL)
+ return AUL_SVC_RET_EINVAL;
+
+ ret = _svc_db_check_perm();
+ if (ret < 0) {
+ _E("permission error : %d", ret);
+ return AUL_SVC_RET_EILLACC;
+ }
+
+ ret = _svc_db_add_app(op, mime_type, uri, defapp);
+
+ if (ret < 0)
+ return AUL_SVC_RET_ERROR;
+
+ return AUL_SVC_RET_OK;
+}
+
+SLPAPI int aul_svc_unset_defapp(const char *defapp)
+{
+ int ret;
+
+ if (defapp == NULL)
+ return AUL_SVC_RET_EINVAL;
+
+ ret = _svc_db_check_perm();
+ if (ret < 0) {
+ _E("permission error : %d", ret);
+ return AUL_SVC_RET_EILLACC;
+ }
+
+ ret = _svc_db_delete_with_pkgname(defapp);
+
+ if (ret < 0)
+ return AUL_SVC_RET_ERROR;
+
+ return AUL_SVC_RET_OK;
+}
+
+SLPAPI int aul_svc_unset_all_defapps()
+{
+ int ret;
+
+ ret = _svc_db_check_perm();
+ if (ret < 0) {
+ _E("permission error : %d", ret);
+ return AUL_SVC_RET_EILLACC;
+ }
+
+ ret = _svc_db_delete_all();
+
+ if (ret < 0)
+ return AUL_SVC_RET_ERROR;
+
+ return AUL_SVC_RET_OK;
+}
+
+SLPAPI int aul_svc_is_defapp(const char *pkg_name)
+{
+ int ret;
+
+ ret = _svc_db_check_perm();
+ if (ret < 0) {
+ _E("permission error : %d", ret);
+ return AUL_SVC_RET_EILLACC;
+ }
+
+ return _svc_db_is_defapp(pkg_name);
+}
+
+SLPAPI int aul_svc_data_is_array(bundle *b, const char *key)
+{
+ int type;
+ type = bundle_get_type(b, key);
+
+ if (type <= 0)
+ return 0;
+
+ if (type & BUNDLE_TYPE_ARRAY)
+ return 1;
+ return 0;
+}
+
+SLPAPI int aul_svc_allow_transient_app(bundle *b, int wid)
+{
+ char win_id[MAX_LOCAL_BUFSZ];
+
+ snprintf(win_id, MAX_LOCAL_BUFSZ, "%d", wid);
+
+ if (b == NULL) {
+ _E("bundle for aul_svc_allow_transient_app is NULL");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ return __set_bundle(b, AUL_SVC_K_WIN_ID, win_id);
+}
+
+SLPAPI int aul_svc_request_transient_app(bundle *b, int callee_wid,
+ aul_svc_host_res_fn cbfunc, void *data)
+{
+ const char *caller = NULL;
+ Ecore_X_Window caller_wid;
+ aul_svc_transient_cb_info_t* info;
+
+ caller = bundle_get_val(b, AUL_SVC_K_WIN_ID);
+ if (caller == NULL)
+ return AUL_SVC_RET_ERROR;
+
+ caller_wid = atoi(caller);
+
+ if (callee_wid == caller_wid) {
+ _E("callee window id is same as calleer window id. request will be ignored");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ info = (aul_svc_transient_cb_info_t*)calloc(1,
+ sizeof(aul_svc_transient_cb_info_t));
+ if (info == NULL)
+ return AUL_SVC_RET_ERROR;
+
+ info->win_id = caller_wid;
+ info->cb_func = cbfunc;
+ info->data = data;
+
+ __set_transient_for(callee_wid, caller_wid, info);
+
+ aul_set_subapp(__aul_subapp_cb, info);
+
+ return 0;
+}
+
+SLPAPI int aul_svc_subapp_terminate_request_pid(int pid)
+{
+ int cpid = getpid();
+ int lcnt;
+ int *lpids = NULL;
+ int i;
+
+ aul_app_group_get_leader_pids(&lcnt, &lpids);
+ for (i = 0; i < lcnt; i++) {
+ if (lpids[i] == cpid) {
+ int cnt;
+ int *pids = NULL;
+
+ aul_app_group_get_group_pids(cpid, &cnt, &pids);
+
+ if (cnt == 0) {
+ free(lpids);
+ if (pids)
+ free(pids);
+
+ return aul_subapp_terminate_request_pid(pid);
+ }
+
+ if (pids != NULL)
+ free(pids);
+ break;
+ }
+ }
+
+ if (lpids != NULL)
+ free(lpids);
+
+ return aul_app_group_clear_top();
+}
SLPAPI int aul_send_service_result(bundle *b)
{
return aul_send_result(b, 0);
}
+
+SLPAPI int aul_svc_subscribe_launch_result(bundle *b, const char *result)
+{
+ if (b == NULL) {
+ _E("bundle for aul_svc_subscribe_launch_result is NULL");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ return __set_bundle(b, result, "1");
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <glib.h>
+#include <unistd.h>
+#include <ttrace.h>
+#include <ctype.h>
+
+#include "aul_svc_db.h"
+#include "simple_util.h"
+
+#define SVC_DB_PATH __get_db_path()
+#define APP_INFO_DB_PATH __get_app_info_db_path()
+
+#define QUERY_MAX_LEN 8192
+#define URI_MAX_LEN 4096
+#define BUF_MAX_LEN 1024
+
+#define SVC_COLLATION "appsvc_collation"
+
+static sqlite3 *svc_db = NULL;
+static sqlite3 *app_info_db = NULL;
+
+char *_svc_db_path = NULL;
+char *_svc_app_info_db_path = NULL;
+
+static const char* __get_db_path()
+{
+ if (_svc_db_path == NULL)
+ return _SVC_DB_PATH;
+
+ return _svc_db_path;
+}
+
+static const char* __get_app_info_db_path()
+{
+ if (_svc_app_info_db_path == NULL)
+ return _SVC_APP_INFO_DB_PATH;
+
+ return _svc_app_info_db_path;
+}
+
+/**
+ * db initialize
+ */
+static int __init(void)
+{
+ int rc;
+
+ if (svc_db) {
+ _D("Already initialized\n");
+ return 0;
+ }
+
+ rc = sqlite3_open(SVC_DB_PATH, &svc_db);
+ if (rc) {
+ _E("Can't open database: %d, %s, extended: %d", rc, sqlite3_errmsg(svc_db),
+ sqlite3_extended_errcode(svc_db));
+ goto err;
+ }
+
+ // Enable persist journal mode
+ rc = sqlite3_exec(svc_db, "PRAGMA journal_mode = PERSIST", NULL, NULL, NULL);
+ if (SQLITE_OK != rc) {
+ _E("Fail to change journal mode\n");
+ goto err;
+ }
+
+ return 0;
+err:
+ sqlite3_close(svc_db);
+ svc_db = NULL;
+ return -1;
+}
+
+static int __collate_appsvc(void *ucol, int str1_len, const void *str1,
+ int str2_len, const void *str2)
+{
+ char *saveptr1 = NULL;
+ char *saveptr2 = NULL;
+ char *dup_str1;
+ char *dup_str2;
+ char *token;
+ char *in_op;
+ char *in_uri;
+ char *in_mime;
+ char *op;
+ char *uri;
+ char *mime;
+
+ if (str1 == NULL || str2 == NULL)
+ return -1;
+
+ dup_str1 = strdup(str1);
+ dup_str2 = strdup(str2);
+
+ in_op = strtok_r(dup_str2, "|", &saveptr1);
+ in_uri = strtok_r(NULL, "|", &saveptr1);
+ in_mime = strtok_r(NULL, "|", &saveptr1);
+
+ if (!(in_op && in_uri && in_mime)) {
+ _D("op(%s) uri(%s) mime(%s)", in_op, in_uri, in_mime);
+ free(dup_str1);
+ free(dup_str2);
+ return -1;
+ }
+
+ token = strtok_r(dup_str1, ";", &saveptr1);
+
+ if (token == NULL) {
+ free(dup_str1);
+ free(dup_str2);
+ return -1;
+ }
+
+ do {
+ //_D("token : %s", token);
+ op = strtok_r(token, "|", &saveptr2);
+ uri = strtok_r(NULL, "|", &saveptr2);
+ mime = strtok_r(NULL, "|", &saveptr2);
+
+ if (!(op && uri && mime)) {
+ _D("op(%s) uri(%s) mime(%s)", op, uri, mime);
+ continue;
+ }
+
+ if ( (strcmp(op, in_op) == 0) && (strcmp(mime, in_mime) == 0) ) {
+ SECURE_LOGD("%s %s %s %s %s %s", op, in_op, mime, in_mime, uri, in_uri);
+ if (g_pattern_match_simple(uri, in_uri)) {
+ SECURE_LOGD("in_uri : %s | uri : %s", in_uri, uri);
+ free(dup_str1);
+ free(dup_str2);
+ return 0;
+ }
+ }
+ } while ( (token = strtok_r(NULL, ";", &saveptr1)) );
+
+ free(dup_str1);
+ free(dup_str2);
+
+ return -1;
+}
+
+static int __init_app_info_db(void)
+{
+ int rc;
+
+ if (app_info_db) {
+ _D("Already initialized\n");
+ return 0;
+ }
+
+ rc = sqlite3_open(APP_INFO_DB_PATH, &app_info_db);
+ if (rc) {
+ _E("Can't open database: %d, %s, extended: %d", rc, sqlite3_errmsg(app_info_db),
+ sqlite3_extended_errcode(app_info_db));
+ goto err;
+ }
+
+ // Enable persist journal mode
+ rc = sqlite3_exec(app_info_db, "PRAGMA journal_mode = PERSIST", NULL, NULL,
+ NULL);
+ if (SQLITE_OK != rc) {
+ _D("Fail to change journal mode\n");
+ goto err;
+ }
+
+ sqlite3_create_collation(app_info_db, SVC_COLLATION, SQLITE_UTF8, NULL,
+ __collate_appsvc);
+
+ return 0;
+err:
+ sqlite3_close(app_info_db);
+ app_info_db = NULL;
+ return -1;
+}
+
+
+static int __fini(void)
+{
+ if (svc_db) {
+ sqlite3_close(svc_db);
+ svc_db = NULL;
+ }
+ return 0;
+}
+
+int _svc_db_check_perm()
+{
+ int ret = 0;
+ ret = access(SVC_DB_PATH, R_OK | W_OK);
+
+ return ret;
+}
+
+int _svc_db_add_app(const char *op, const char *mime_type, const char *uri,
+ const char *pkg_name)
+{
+ char m[BUF_MAX_LEN];
+ char u[URI_MAX_LEN];
+ const char insert_query[] =
+ "insert into appsvc( operation, mime_type, uri, pkg_name) values(?,?,?,?)";
+ sqlite3_stmt* p_statement;
+ int result;
+
+ if (__init() < 0)
+ return -1;
+
+ if (op == NULL )
+ return -1;
+
+ if (mime_type == NULL)
+ strncpy(m, "NULL", BUF_MAX_LEN - 1);
+ else
+ strncpy(m, mime_type, BUF_MAX_LEN - 1);
+
+ if (uri == NULL)
+ strncpy(u, "NULL", URI_MAX_LEN - 1);
+ else
+ strncpy(u, uri, URI_MAX_LEN - 1);
+
+
+ result = sqlite3_prepare_v2(svc_db, insert_query, strlen(insert_query),
+ &p_statement, NULL);
+ if (result != SQLITE_OK) {
+ _E("Sqlite3 error [%d] : <%s> preparing <%s> querry\n", result,
+ sqlite3_errmsg(svc_db), insert_query);
+ return -1;
+ }
+
+ sqlite3_bind_text(p_statement, 1, op, -1, SQLITE_TRANSIENT);
+ sqlite3_bind_text(p_statement, 2, m, -1, SQLITE_TRANSIENT);
+ sqlite3_bind_text(p_statement, 3, u, -1, SQLITE_TRANSIENT);
+ sqlite3_bind_text(p_statement, 4, pkg_name, -1, SQLITE_TRANSIENT);
+
+
+ result = sqlite3_step(p_statement);
+ if (result != SQLITE_DONE) {
+ _E("Sqlite3 error [%d] : <%s> executing statement\n", result,
+ sqlite3_errmsg(svc_db));
+ }
+
+ result = sqlite3_finalize(p_statement);
+ if (result != SQLITE_OK) {
+ _E("Sqlite3 error [%d] : <%s> finalizing statement\n", result,
+ sqlite3_errmsg(svc_db));
+ }
+
+ __fini();
+ return 0;
+}
+
+int _svc_db_delete_with_pkgname(const char *pkg_name)
+{
+ const char delete_query[] = "delete from appsvc where pkg_name = ?;";
+ sqlite3_stmt* p_statement;
+ int result;
+
+ if (pkg_name == NULL) {
+ _E("Invalid argument: data to delete is NULL\n");
+ return -1;
+ }
+
+ if (__init() < 0)
+ return -1;
+
+ result = sqlite3_prepare_v2(svc_db, delete_query, strlen(delete_query),
+ &p_statement, NULL);
+ if (result != SQLITE_OK) {
+ _E("Sqlite3 error [%d] : <%s> preparing <%s> querry\n", result,
+ sqlite3_errmsg(svc_db), delete_query);
+ return -1;
+ }
+
+ sqlite3_bind_text(p_statement, 1, pkg_name, -1, SQLITE_TRANSIENT);
+
+ result = sqlite3_step(p_statement);
+ if (result != SQLITE_DONE) {
+ _E("Sqlite3 error [%d] : <%s> executing statement\n", result,
+ sqlite3_errmsg(svc_db));
+ }
+
+ result = sqlite3_finalize(p_statement);
+ if (result != SQLITE_OK) {
+ _E("Sqlite3 error [%d] : <%s> finalizing statement\n", result,
+ sqlite3_errmsg(svc_db));
+ }
+
+ __fini();
+
+ return 0;
+}
+
+int _svc_db_delete_all()
+{
+ char query[QUERY_MAX_LEN];
+ char* error_message = NULL;
+
+ if (__init() < 0)
+ return -1;
+
+ snprintf(query, QUERY_MAX_LEN, "delete from appsvc;");
+
+ if (SQLITE_OK != sqlite3_exec(svc_db, query, NULL, NULL, &error_message)) {
+ _E("Don't execute query = %s, error message = %s\n", query, error_message);
+ return -1;
+ }
+
+ __fini();
+
+ return 0;
+}
+
+int _svc_db_is_defapp(const char *pkg_name)
+{
+ char query[QUERY_MAX_LEN];
+ sqlite3_stmt *stmt;
+ int cnt = 0;
+ int ret = -1;
+
+ if (pkg_name == NULL) {
+ _E("Invalid argument: data to delete is NULL\n");
+ return 0;
+ }
+
+ if (__init() < 0)
+ return 0;
+
+ snprintf(query, QUERY_MAX_LEN,
+ "select count(*) from appsvc where pkg_name = '%s';", pkg_name);
+
+ ret = sqlite3_prepare(svc_db, query, sizeof(query), &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ _E("prepare error, ret = %d, extended = %d\n", ret,
+ sqlite3_extended_errcode(svc_db));
+ return -1;
+ }
+
+ ret = sqlite3_step(stmt);
+ if (ret == SQLITE_ROW) {
+ cnt = sqlite3_column_int(stmt, 0);
+ }
+ sqlite3_finalize(stmt);
+
+ __fini();
+
+ if (cnt < 1) return 0;
+
+ return 1;
+}
+
+char* _svc_db_get_app(const char *op, const char *mime_type, const char *uri)
+{
+ char m[BUF_MAX_LEN];
+ char u[URI_MAX_LEN];
+ char query[QUERY_MAX_LEN];
+ sqlite3_stmt* stmt;
+ int ret;
+ char* pkgname;
+ char* ret_val = NULL;
+
+ if (op == NULL )
+ return NULL;
+
+ if (mime_type == NULL)
+ strncpy(m, "NULL", BUF_MAX_LEN - 1);
+ else
+ strncpy(m, mime_type, BUF_MAX_LEN - 1);
+
+ if (uri == NULL)
+ strncpy(u, "NULL", URI_MAX_LEN - 1);
+ else
+ strncpy(u, uri, URI_MAX_LEN - 1);
+
+ if (__init() < 0)
+ return NULL;
+
+
+ snprintf(query, QUERY_MAX_LEN,
+ "select pkg_name from appsvc where operation='%s' and mime_type='%s' and uri='%s'",
+ \
+ op, m, u);
+
+ SECURE_LOGD("query : %s\n", query);
+
+ ret = sqlite3_prepare(svc_db, query, strlen(query), &stmt, NULL);
+ if ( ret != SQLITE_OK) {
+ _E("prepare error, ret = %d, extended = %d\n", ret,
+ sqlite3_extended_errcode(svc_db));
+ goto db_fini;
+ }
+
+ ret = sqlite3_step(stmt);
+ if (ret != SQLITE_ROW) {
+ _D("no result");
+ goto stmt_finialize;
+ }
+
+ pkgname = (char*) sqlite3_column_text(stmt, 0);
+ if (pkgname) {
+ ret_val = malloc(BUF_MAX_LEN);
+ if (ret_val == NULL) {
+ _E("out of memory");
+ goto stmt_finialize;
+ }
+
+ strncpy(ret_val, (const char *)sqlite3_column_text(stmt, 0), BUF_MAX_LEN - 1);
+ }
+
+ SECURE_LOGD("pkgname : %s\n", pkgname);
+
+stmt_finialize :
+ ret = sqlite3_finalize(stmt);
+ if ( ret != SQLITE_OK) {
+ _D("finalize error(%d)", ret);
+ }
+
+db_fini :
+ __fini();
+
+ return ret_val;
+}
+
+static int __appid_compare(gconstpointer data1, gconstpointer data2)
+{
+ char *a = (char *)data1;
+ char *b = (char *)data2;
+ return strcmp(a, b);
+}
+
+int _svc_db_adjust_list_with_submode(int mainapp_mode, char *win_id, GSList **pkg_list)
+{
+ sqlite3_stmt* stmt;
+ int ret;
+ char query[QUERY_MAX_LEN];
+ char *subappid = NULL;
+ char *submode_mainid = NULL;
+ char *excluded_appid = NULL;
+ GSList *subapp = NULL;
+ GSList *mainapp = NULL;
+
+ if (__init_app_info_db() < 0)
+ return 0;
+
+ snprintf(query, QUERY_MAX_LEN, "select ac.app_id, ai.app_submode_mainid from package_app_app_control as ac, package_app_info ai where ac.app_id = ai.app_id and ai.app_submode_mainid!=''");
+ ret = sqlite3_prepare(app_info_db, query, sizeof(query), &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ _E("prepare error, ret = %d, extended = %d\n", ret,
+ sqlite3_extended_errcode(app_info_db));
+ return -1;
+ }
+
+ while (sqlite3_step(stmt) == SQLITE_ROW) {
+ subappid = (char *)sqlite3_column_text(stmt, 0);
+ submode_mainid = (char *)sqlite3_column_text(stmt, 1);
+ subapp = g_slist_find_custom(*pkg_list, subappid, __appid_compare);
+
+ if (subapp == NULL)
+ continue;
+
+ // find if the main app is in the pkg_list
+ mainapp = g_slist_find_custom(*pkg_list, submode_mainid, __appid_compare);
+ if (mainapp == NULL)
+ continue;
+
+ if (win_id && !mainapp_mode)
+ //subapp mode - remove mainapp from list
+ excluded_appid = (char *)mainapp->data;
+ else
+ //mainapp mode - remove subapp from list
+ excluded_appid = (char *)subapp->data;
+
+ if (excluded_appid) {
+ _E("remove %s from app list with submode", excluded_appid);
+ *pkg_list = g_slist_remove(*pkg_list, excluded_appid);
+ free(excluded_appid);
+ excluded_appid = NULL;
+ }
+ }
+
+ ret = sqlite3_finalize(stmt);
+ return 0;
+}
+
+int _svc_db_get_list_with_condition(char *op, char *uri, char *mime,
+ GSList **pkg_list)
+{
+ char query[QUERY_MAX_LEN];
+ sqlite3_stmt* stmt;
+ int ret;
+ GSList *iter = NULL;
+ char *str = NULL;
+ char *pkgname = NULL;
+ int found;
+
+ if (__init_app_info_db() < 0)
+ return 0;
+
+ snprintf(query, QUERY_MAX_LEN,
+ "select ac.app_id from package_app_app_control as ac, package_app_info ai where ac.app_id = ai.app_id and ac.app_control like '%%%s|%s|%s%%' and ai.app_disable='false' and ai.component_type='uiapp'",
+ op, uri, mime);
+ SECURE_LOGD("query : %s\n", query);
+
+ ret = sqlite3_prepare(app_info_db, query, strlen(query), &stmt, NULL);
+ if ( ret != SQLITE_OK) {
+ _E("prepare error, ret = %d, extended = %d\n", ret,
+ sqlite3_extended_errcode(app_info_db));
+ return -1;
+ }
+
+ while (sqlite3_step(stmt) == SQLITE_ROW) {
+ str = (char *)sqlite3_column_text(stmt, 0);
+ found = 0;
+ for (iter = *pkg_list; iter != NULL; iter = g_slist_next(iter)) {
+ pkgname = (char *)iter->data;
+ if (strncmp(str, pkgname, MAX_PACKAGE_STR_SIZE - 1) == 0) {
+ found = 1;
+ break;
+ }
+ }
+ if (found == 0) {
+ pkgname = strdup(str);
+ *pkg_list = g_slist_append(*pkg_list, (void *)pkgname);
+ _D("%s is added", pkgname);
+ }
+ }
+
+ ret = sqlite3_finalize(stmt);
+
+ return 0;
+}
+
+int _svc_db_get_list_with_collation(char *op, char *uri, char *mime,
+ GSList **pkg_list)
+{
+ char query[QUERY_MAX_LEN];
+ sqlite3_stmt* stmt;
+ int ret;
+ GSList *iter = NULL;
+ char *str = NULL;
+ char *pkgname = NULL;
+ int found;
+
+ traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "AUL:SVC_COLLATION");
+
+ if (__init_app_info_db() < 0) {
+ traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
+ return 0;
+ }
+
+ snprintf(query, QUERY_MAX_LEN,
+ "select ac.app_id from package_app_app_control as ac, package_app_info ai where ac.app_id = ai.app_id and ac.app_control='%s|%s|%s' collate appsvc_collation and ai.app_disable='false' and ai.component_type='uiapp'",
+ op, uri, mime);
+ SECURE_LOGD("query : %s\n", query);
+
+ ret = sqlite3_prepare(app_info_db, query, strlen(query), &stmt, NULL);
+ if ( ret != SQLITE_OK) {
+ _E("prepare error, ret = %d, extended = %d\n", ret,
+ sqlite3_extended_errcode(app_info_db));
+ traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
+ return -1;
+ }
+
+ while (sqlite3_step(stmt) == SQLITE_ROW) {
+ str = (char *)sqlite3_column_text(stmt, 0);
+ found = 0;
+ for (iter = *pkg_list; iter != NULL; iter = g_slist_next(iter)) {
+ pkgname = (char *)iter->data;
+ if (strncmp(str, pkgname, MAX_PACKAGE_STR_SIZE - 1) == 0) {
+ found = 1;
+ break;
+ }
+ }
+ if (found == 0) {
+ pkgname = strdup(str);
+ *pkg_list = g_slist_append(*pkg_list, (void *)pkgname);
+ _D("%s is added", pkgname);
+ }
+ }
+
+ ret = sqlite3_finalize(stmt);
+
+ traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
+ return 0;
+}
+
+int _svc_db_get_list_with_all_defapps(GSList **pkg_list)
+{
+ char query[QUERY_MAX_LEN];
+ sqlite3_stmt* stmt;
+ int ret;
+ GSList *iter = NULL;
+ char *str = NULL;
+ char *pkgname = NULL;
+ int found;
+
+ if (__init() < 0)
+ return 0;
+
+ snprintf(query, QUERY_MAX_LEN, "select pkg_name from appsvc");
+
+ ret = sqlite3_prepare(svc_db, query, sizeof(query), &stmt, NULL);
+ if ( ret != SQLITE_OK) {
+ _E("prepare error, ret = %d, extended = %d\n", ret,
+ sqlite3_extended_errcode(svc_db));
+ return -1;
+ }
+
+ while (sqlite3_step(stmt) == SQLITE_ROW) {
+ str = (char *)sqlite3_column_text(stmt, 0);
+ found = 0;
+ for (iter = *pkg_list; iter != NULL; iter = g_slist_next(iter)) {
+ pkgname = (char *)iter->data;
+ if (strncmp(str, pkgname, MAX_PACKAGE_STR_SIZE - 1) == 0) {
+ found = 1;
+ break;
+ }
+ }
+ if (found == 0) {
+ pkgname = strdup(str);
+ *pkg_list = g_slist_append(*pkg_list, (void *)pkgname);
+ _D("[%s] is def app", pkgname);
+ }
+ }
+
+ ret = sqlite3_finalize(stmt);
+
+ return 0;
+}
+
*
*/
-
+#define _GNU_SOURCE
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <linux/un.h>
+#include <glib.h>
#include "simple_util.h"
+#include "aul_zone.h"
#define BINSH_NAME "/bin/sh"
#define BINSH_SIZE 7
return pid;
}
+int __proc_check_app(const char *path, int pid)
+{
+ char buf[MAX_LOCAL_BUFSZ] = {0};
+ char *cmdline;
+ int ret = 0;
+
+ if (!path || pid < 1)
+ return 0;
+
+ snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
+ ret = __read_proc(buf, buf, sizeof(buf));
+ if (ret <= 0)
+ return 0;
+
+ /* support app launched by shell script */
+ cmdline = buf;
+ if (strncmp(buf, BINSH_NAME, BINSH_SIZE) == 0) {
+ cmdline = &buf[BINSH_SIZE + 1];
+ } else if (strncmp(buf, BASH_NAME, BASH_SIZE) == 0) {
+ if (strncmp(&buf[BASH_SIZE + OPROFILE_SIZE + 2], OPTION_VALGRIND_NAME, OPTION_VALGRIND_SIZE) == 0) {
+ cmdline = &buf[BASH_SIZE + OPROFILE_SIZE + OPTION_VALGRIND_SIZE + 3];
+ }
+ }
+
+ if (strncmp(cmdline, path, MAX_LOCAL_BUFSZ - 1) == 0)
+ return pid;
+
+ return 0;
+}
+
+extern gboolean app_group_is_sub_app(int pid);
+
int __proc_iter_cmdline(
int (*iterfunc)(const char *dname, const char *cmdline, void *priv),
void *priv)
{
- DIR *dp;
- struct dirent *dentry;
- int pid;
- int ret;
- char buf[MAX_LOCAL_BUFSZ];
+ DIR *dp = NULL;
+ struct dirent *dentry = NULL;
+ int pid = 0;
+ int ret = 0;
+ char buf[MAX_LOCAL_BUFSZ] = {0,};
- dp = opendir("/proc");
+ snprintf(buf, sizeof(buf), "%sproc", _get_root_path());
+ dp = opendir(buf);
if (dp == NULL) {
return -1;
}
if (!isdigit(dentry->d_name[0]))
continue;
- snprintf(buf, sizeof(buf), "/proc/%s/cmdline", dentry->d_name);
+ snprintf(buf, sizeof(buf), "%sproc/%s/cmdline", _get_root_path(), dentry->d_name);
ret = __read_proc(buf, buf, sizeof(buf));
if (ret <= 0)
continue;
/* support app launched by shell script*/
- if (strncmp(buf, BINSH_NAME, BINSH_SIZE) == 0)
- pid =
- iterfunc(dentry->d_name, &buf[BINSH_SIZE + 1],
- priv);
- else
+ if (strncmp(buf, BINSH_NAME, BINSH_SIZE) == 0) {
+ pid = iterfunc(dentry->d_name, &buf[BINSH_SIZE + 1], priv);
+ }
+ else if (strncmp(buf, VALGRIND_NAME, VALGRIND_SIZE) == 0) {
+ char* ptr = buf + VALGRIND_SIZE + 1;
+
+ // buf comes with double null-terminated string
+ while (1) {
+ while (*ptr) {
+ ptr++;
+ }
+ ptr++;
+
+ if (*ptr == '\0') { // double null
+ break;
+ }
+
+ // ignore trailing "--"
+ if (strncmp(ptr, "-", 1) != 0) {
+ break;
+ }
+ };
+
+ _D("cmdline is [%s]", ptr);
+ pid = iterfunc(dentry->d_name, ptr, priv);
+ }
+ else {
pid = iterfunc(dentry->d_name, buf, priv);
+ }
if (pid > 0) {
+ if (app_group_is_sub_app(pid))
+ continue;
+
closedir(dp);
return pid;
}
char buf[MAX_CMD_BUFSZ];
int ret;
- snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
+ snprintf(buf, sizeof(buf), "%sproc/%d/cmdline", _get_root_path(), pid);
ret = __read_proc(buf, buf, sizeof(buf));
if (ret <= 0)
return NULL;
}
ptr++;
- if (*ptr == NULL)
+ if (*ptr == '\0')
break;
// ignore trailing "--"
if (pid <= 1)
return -1;
- snprintf(buf, sizeof(buf), "/proc/%d/stat", pid);
+ snprintf(buf, sizeof(buf), "%sproc/%d/stat", _get_root_path(), pid);
ret = __read_proc(buf, buf, sizeof(buf));
if (ret < 0)
return -1;
struct dirent *dentry;
int _pgid;
int ret = -1;
+ char buf[MAX_LOCAL_BUFSZ] = { 0, };
- dp = opendir("/proc");
+ snprintf(buf, sizeof(buf), "%sproc", _get_root_path());
+ dp = opendir(buf);
if (dp == NULL) {
return -1;
}
int socket_fd = 0;
int ret = 0;
struct sockaddr_un addr;
+ char buf[MAX_LOCAL_BUFSZ] = { 0, };
_D("__trm_app_info_send_socket");
- if (access(trm_socket_for_app_info, F_OK) != 0) {
+ snprintf(buf, sizeof(buf), "%s%s", _get_root_path(), trm_socket_for_app_info);
+
+ if (access(buf, F_OK) != 0) {
_E("access");
goto trm_end;
}
}
memset(&addr, 0, sizeof(addr));
- snprintf(addr.sun_path, UNIX_PATH_MAX, "%s", trm_socket_for_app_info);
+ snprintf(addr.sun_path, UNIX_PATH_MAX, "%s", buf);
addr.sun_family = AF_LOCAL;
- ret = connect(socket_fd, (struct sockaddr *) &addr ,sizeof(sa_family_t) + strlen(trm_socket_for_app_info) );
+ ret = connect(socket_fd, (struct sockaddr *) &addr ,sizeof(sa_family_t) + strlen(buf) );
if (ret != 0) {
close(socket_fd);
goto trm_end;
*
*/
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
#include <aul.h>
#include <bundle.h>
+#include <bundle_internal.h>
#include "aul_util.h"
#include "app_sock.h"
#include "aul_api.h"
#include "launch.h"
+#include "simple_util.h"
+
+typedef struct _app_status_cb_info_t {
+ int (*handler) (int status, void *data);
+ void *data;
+ struct _app_status_cb_info_t *next;
+} app_status_cb_info_t;
+
+app_status_cb_info_t *app_status_cb = NULL;
SLPAPI int aul_status_update(int status)
{
ret = __app_send_raw_with_noreply(AUL_UTIL_PID, APP_STATUS_UPDATE, (unsigned char *)&status, sizeof(status));
+ if (!ret)
+ aul_invoke_status_local_cb(status);
+
return ret;
}
+SLPAPI int aul_app_get_status_bypid(int pid)
+{
+ int ret;
+
+ ret = __app_send_raw(AUL_UTIL_PID, APP_GET_STATUS, (unsigned char *)&pid, sizeof(pid));
+
+ return ret;
+}
+
+SLPAPI int aul_add_status_local_cb(int (*func)(int status, void *data), void *data)
+{
+ app_status_cb_info_t *cb = app_status_cb;
+
+ if (func == NULL)
+ return -1;
+
+ // check known callback
+ while (cb) {
+ if (cb && cb->handler == func && cb->data == data) {
+ // already in list
+ return 0;
+ }
+ cb = cb->next;
+ }
+
+ cb = (app_status_cb_info_t *)malloc(sizeof(app_status_cb_info_t));
+ if (cb == NULL)
+ return -1;
+
+ cb->handler = func;
+ cb->data = data;
+
+ cb->next = app_status_cb;
+ app_status_cb = cb;
+
+ return 0;
+}
+
+SLPAPI int aul_remove_status_local_cb(int (*func)(int status, void *data), void *data)
+{
+ app_status_cb_info_t *cb = app_status_cb;
+ app_status_cb_info_t *tmp = NULL;
+
+ if (app_status_cb
+ && app_status_cb->handler == func
+ && app_status_cb->data == data) {
+ cb = app_status_cb->next;
+ free(app_status_cb);
+ app_status_cb = cb;
+ return 0;
+ }
+
+ while (cb) {
+ if (cb->next
+ && cb->next->handler == func
+ && cb->next->data == data) {
+ tmp = cb->next->next;
+ free(cb->next);
+ cb->next = tmp;
+ return 0;
+ }
+
+ cb = cb->next;
+ }
+
+ return -1;
+}
+
+SLPAPI int aul_invoke_status_local_cb(int status)
+{
+ app_status_cb_info_t *cb = app_status_cb;
+
+ while (cb) {
+ if (cb->handler) {
+ if (cb->handler(status, cb->data) < 0)
+ aul_remove_status_local_cb(cb->handler, cb->data);
+ }
+
+ cb = cb->next;
+ }
+
+ return 0;
+}
+
SLPAPI int aul_running_list_update(char *appid, char *app_path, char *pid)
{
int ret;
return ret;
}
+SLPAPI int aul_set_process_group(int owner_pid, int child_pid)
+{
+ int ret = -1;
+ bundle *kb = NULL;
+ char pid_buf[MAX_PID_STR_BUFSZ] = {0,};
+
+ kb = bundle_create();
+
+ snprintf(pid_buf, MAX_PID_STR_BUFSZ, "%d", owner_pid);
+ bundle_add(kb, AUL_K_OWNER_PID, pid_buf);
+ snprintf(pid_buf, MAX_PID_STR_BUFSZ, "%d", child_pid);
+ bundle_add(kb, AUL_K_CHILD_PID, pid_buf);
+
+ ret = app_send_cmd(AUL_UTIL_PID, APP_SET_PROCESS_GROUP, kb);
+
+ if (kb != NULL)
+ bundle_free(kb);
+
+ return ret;
+}
--- /dev/null
+/*
+ * aul
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#define _GNU_SOURCE
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdlib.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <bundle.h>
+#include <vasum.h>
+
+#include "aul.h"
+#include "launch.h"
+#include "aul_api.h"
+#include "aul_svc_db.h"
+
+#define MAX_BUF 1024
+#define PID_MAX_DEFAULT 0x8000
+#define __ZONE_PREFIX "/var/lib/lxc/%s/rootfs"
+
+extern char *_socket_prefix;
+extern char *_root_path;
+extern char *_cur_zone;
+extern int _pid_offset;
+extern char *_svc_db_path;
+extern char *_svc_app_info_db_path;
+
+extern void _clear_path_cache(void);
+
+SLPAPI int aul_set_zone(const char *zone, char **old_zone)
+{
+ if (vsm_is_virtualized())
+ return AUL_R_ERROR;
+
+ if (aul_is_initialized()) {
+ aul_finalize();
+ }
+
+ *old_zone = _cur_zone;
+ _clear_path_cache();
+ if (zone == NULL) {
+ if (_socket_prefix != NULL)
+ free(_socket_prefix);
+ _socket_prefix = NULL;
+
+ if (_root_path)
+ free(_root_path);
+ _root_path = NULL;
+
+ if (_svc_db_path != NULL)
+ free(_svc_db_path);
+ _svc_db_path = NULL;
+
+ if (_svc_app_info_db_path != NULL)
+ free(_svc_app_info_db_path);
+ _svc_app_info_db_path = NULL;
+
+ _pid_offset = 0;
+ _cur_zone = NULL;
+ return 0;
+ }
+
+ _cur_zone = strdup(zone);
+ char path[MAX_BUF] = { '\0', };
+
+ snprintf(path, MAX_BUF - 1, __ZONE_PREFIX"%s",
+ zone, "/tmp/alaunch");
+ if (_socket_prefix != NULL)
+ free(_socket_prefix);
+ _socket_prefix = strdup(path);
+ _pid_offset = PID_MAX_DEFAULT;
+
+ snprintf(path, MAX_BUF - 1, __ZONE_PREFIX"/", zone);
+ if (_root_path != NULL)
+ free(_root_path);
+ _root_path = strdup(path);
+
+ snprintf(path, MAX_BUF - 1, __ZONE_PREFIX"/%s", zone, _SVC_DB_PATH);
+ if (_svc_db_path != NULL)
+ free(_svc_db_path);
+ _svc_db_path = strdup(path);
+
+ snprintf(path, MAX_BUF - 1, __ZONE_PREFIX"%s", zone, _SVC_APP_INFO_DB_PATH);
+ if (_svc_app_info_db_path != NULL)
+ free(_svc_app_info_db_path);
+ _svc_app_info_db_path = strdup(path);
+
+ return 0;
+}
+
*
*/
+#define _GNU_SOURCE
#include <poll.h>
#include <stdio.h>
#include <unistd.h>
/* ecore-glib integration */
#include <Ecore.h>
+#include <bundle_internal.h>
extern int aul_listen_app_dead_signal(int (*func) (int, void *), void *data);
case AUL_TERMINATE:
exit(0);
break;
+ default:
+ break;
}
return 0;
}
*
*/
+#define _GNU_SOURCE
#include <glib.h>
#include "aul_dbus.h"
#include <sys/time.h>
*
*/
-
+#define _GNU_SOURCE
#include <poll.h>
#include <stdio.h>
#include <sys/time.h>
#include <unistd.h>
#include <Ecore.h>
+#include <bundle_internal.h>
#include "menu_db_util.h"
#include "aul.h"
+#include "aul_svc.h"
#define PERF_ACTIVATE
#include "perf.h"
-#define MAX_LOCAL_BUFSZ 128
#define QUERY_LEN 10240
static char **gargv;
return ret;
}
-static void prt_recvd_bundle(const char *key, const char *value, void *d)
-{
- printf("recvd - key: %s, value: %s\n", key, value);
-}
-
-static void cb_func(bundle *kb, int is_cancel, void *data)
-{
- int num;
- num = (int)data;
-
- if (is_cancel) {
- printf("==== %d : canceled(preemptted) my request ===\n", num);
- } else {
- printf("==== %d : result packet ===\n", num);
- bundle_iterate(kb, prt_recvd_bundle, NULL);
- }
-
- if ((strcmp(cmd, "launch_res") == 0)
- || (strcmp(cmd, "open_svc_res") == 0))
- ecore_main_loop_quit();
-}
-
int open_test()
{
static int num = 0;
return aul_subapp_terminate_request_pid(apn_pid);
}
+int pause_test()
+{
+ static int num = 0;
+
+ printf("[aul_pause_app %d test] %s \n", num++, gargv[2]);
+ return aul_pause_app(gargv[2]);
+}
+
+int pause_pid_test()
+{
+ static int num = 0;
+
+ printf("[aul_pause_pid %d test] %d \n", num++, apn_pid);
+ return aul_pause_pid(apn_pid);
+}
+
static test_func_t scn_func[] = {
{"n", launch_test, "launch_test", ""},
{"n", launch_test, "launch_test", ""},
return 0;
}
+int get_pid_test()
+{
+ printf("[aul_app_get_pid %s test] \n", gargv[2]);
+ return aul_app_get_pid(gargv[2]);
+}
+
+int get_pid_cache_test()
+{
+ printf("[aul_app_get_pid_cache %s test] \n", gargv[2]);
+ return aul_app_get_pid_cache(gargv[2]);
+}
+
int iterfunc(const aul_app_info *info, void *data)
{
printf("\t==========================\n");
return 0;
}
+static char *status_text[] = {
+ "STATUS_LAUNCHING",
+ "STATUS_CREATED",
+ "STATUS_FOCUS",
+ "STATUS_VISIBLE",
+ "STATUS_BG",
+ "STATUS_DYING",
+ "STATUS_HOME",
+ "STATUS_NORESTART",
+};
+
+static int get_status_pid()
+{
+ int ret;
+ ret = aul_app_get_status_bypid(apn_pid);
+
+ printf("pid: %d status: %d ", apn_pid, ret);
+ if (ret >= STATUS_LAUNCHING && ret <= STATUS_NORESTART)
+ printf("(%s)", status_text[ret]);
+
+ printf("\n");
+
+ return 0;
+}
+
+static int get_last_caller_pid()
+{
+ int ret;
+ int pid;
+
+ pid = atoi(gargv[2]);
+ ret = aul_app_get_last_caller_pid(pid);
+ printf("pid: %d, last caller pid: %d\n", pid, ret);
+ return ret;
+}
+
static int update_running_list()
{
aul_running_list_update(gargv[2], gargv[3], gargv[4]);
return 0;
}
+static int set_group_test()
+{
+ int owner_pid;
+ int child_pid;
+
+ owner_pid = atoi(gargv[2]);
+ child_pid = atoi(gargv[3]);
+ aul_set_process_group(owner_pid, child_pid);
+
+ return 0;
+}
+
+static int get_group_test()
+{
+ char *str;
+
+ str = aul_get_group_info();
+ printf("%s\n", str);
+ free(str);
+
+ return 0;
+}
+
+/** AUL SVC internal private key */
+#define AUL_SVC_K_OPERATION "__APP_SVC_OP_TYPE__"
+/** AUL SVC internal private key */
+#define AUL_SVC_K_URI "__APP_SVC_URI__"
+/** AUL SVC internal private key */
+#define AUL_SVC_K_MIME "__APP_SVC_MIME_TYPE__"
+/** AUL SVC internal private key */
+#define AUL_SVC_K_CATEGORY "__APP_SVC_CATEGORY__"
+/** AUL SVC internal private key */
+
+static int iter_svc_fn(const char *appid, void *data)
+{
+ printf("matched : %s\n", appid);
+ return 0;
+}
+
+static int get_svc_list()
+{
+ int i = 2;
+ int ret = 0;
+ bundle *b = NULL;
+ if (gargc < 3 || (gargc - 2) % 2 == 1) {
+ printf("[usage] get_svc_list --operation <operation> --mime <mime> --uri <uri>\n");
+ return -1;
+ }
+
+ b = bundle_create();
+ if (!b) {
+ printf("out of memory\n");
+ return -1;
+ }
+
+ for (i = 2; i < gargc; i+=2) {
+ if (strcmp(gargv[i], "--operation") == 0) {
+ bundle_add(b, AUL_SVC_K_OPERATION, gargv[i + 1]);
+ }
+ else if (strcmp(gargv[i], "--mime") == 0) {
+ bundle_add(b, AUL_SVC_K_MIME, gargv[i + 1]);
+ }
+ else if (strcmp(gargv[i], "--uri") == 0) {
+ bundle_add(b, AUL_SVC_K_URI, gargv[i + 1]);
+ }
+ else if (strcmp(gargv[i], "--category") == 0) {
+ bundle_add(b, AUL_SVC_K_CATEGORY, gargv[i + 1]);
+ }
+ }
+
+ printf("start aul_svc_get_list\n");
+ ret = aul_svc_get_list(b, iter_svc_fn, NULL);
+ printf("end aul_svc_get_list\n");
+ bundle_free(b);
+
+ return ret;
+}
/*
static int set_pkg_func()
"[usage] getpkg <pkgname>"},
{"update_list", update_running_list, "update running list",
"[usage] update_list <appid> <app_path> <pid>"},
+
+ {"pause",pause_test,"aul_pause_app test",
+ "[usage] pause <pkgname>" },
+ {"pause_pid",pause_pid_test,"aul_pause_pid test",
+ "[usage] pause_pid <pid>" },
+
+ {"get_pid", get_pid_test, "aul_get_pid test",
+ "[usage] get_pid <pkgname>"},
+ {"get_pid_cache", get_pid_cache_test, "aul_get_pid_cache test",
+ "[usage] get_pid_cache <pkgname>"},
+
+ {"get_status_pid", get_status_pid, "aul_app_get_status_bypid test",
+ "[usage] get_status_pid <pid>"},
+ {"set_group", set_group_test, "set_group_test",
+ "[usage] set_group <pid> <pid>"},
+ {"get_group", get_group_test, "get_group_test",
+ "[usage] get_group"},
+ {"get_svc_list", get_svc_list, "aul_svc_get_list test",
+ "[usage] get_svc_list --operation <operation> --mime <mime> --uri <uri>"},
+ {"get_last_caller_pid", get_last_caller_pid, "aul_app_get_last_caller_pid test",
+ "[usage] get_last_caller_pid <pid>"},
+
/*
{"setpkg", set_pkg_func, "set package",
"[usage] setpkg <pkgname> <apppath>"},
gargv = argv;
apn_pid = atoi(argv[2]);
- aul_launch_init(NULL, NULL);
-
/*aul_listen_app_dead_signal(dead_tracker,NULL); */
/*aul_listen_app_dead_signal(NULL,NULL); */
*
*/
+#define _GNU_SOURCE
#include <stdio.h>
#include <glib.h>
#include "aul_dbus.h"
#include "aul.h"
#include <sys/time.h>
#include <stdlib.h>
+#include <bundle_internal.h>
#define MAX_LOCAL_BUFSZ 128
dbus_message_append_args(reply, DBUS_TYPE_STRING,
&str, DBUS_TYPE_INVALID);
- dbus_connection_send(bus, reply, NULL);
+ if (dbus_connection_send(bus, reply, NULL) == FALSE)
+ _E("Failed to reply");
+
dbus_message_unref(reply);
return 0;
case AUL_TERMINATE:
exit(0);
break;
+ default:
+ break;
}
return 0;
}
loop = g_main_loop_new(NULL, FALSE);
- aul_launch_init(aul_handler, NULL);
- aul_launch_argv_handler(argc, argv);
+ if (aul_launch_init(aul_handler, NULL) != AUL_R_OK)
+ return -1;
+
+ if (aul_launch_argv_handler(argc, argv) < 0)
+ return -1;
g_main_loop_run(loop);
*
*/
+#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <Ecore.h>
+#include <bundle_internal.h>
#include "aul.h"
#define ROOT_UID 0
int launch()
{
- FILE *fp;
- int ret = -1;
int pid = -1;
kb = create_internal_bundle(2);
static Eina_Bool run_func(void *data)
{
int pid = -1;
- char *str = NULL;
+ const char *str = NULL;
if ((pid = launch()) > 0) {
printf("... successfully launched\n");
- str = bundle_get_val(kb, "__LAUNCH_APP_MODE__");
+ str = bundle_get_val(kb, "__LAUNCH_APP_MODE__");
- if( str && strcmp(str, "SYNC") == 0 ) {
- aul_listen_app_dead_signal(__launch_app_dead_handler, pid);
+ if(str && strcmp(str, "SYNC") == 0 ) {
+ aul_listen_app_dead_signal(__launch_app_dead_handler, (void *)pid);
} else {
ecore_main_loop_quit();
}
gargc = argc;
gargv = argv;
- aul_launch_init(NULL, NULL);
-
ecore_idler_add(run_func, NULL);
ecore_main_loop_begin();
*
*/
+#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <Ecore.h>
+#include <bundle_internal.h>
#include "aul.h"
#define ROOT_UID 0
static Eina_Bool run_func(void *data)
{
int pid = -1;
- char *str = NULL;
+ const char *str = NULL;
if ((pid = launch()) > 0) {
printf("... successfully launched\n");
} else {
str = bundle_get_val(kb, "__LAUNCH_APP_MODE__");
if( str && strcmp(str, "SYNC") == 0 ) {
- aul_listen_app_dead_signal(__launch_app_dead_handler, pid);
+ aul_listen_app_dead_signal(__launch_app_dead_handler, (void *)pid);
} else {
ecore_main_loop_quit();
}
gargc = argc;
gargv = argv;
- aul_launch_init(NULL, NULL);
-
ecore_idler_add(run_func, NULL);
ecore_main_loop_begin();
--- /dev/null
+#include <stdio.h>
+#include <stdlib.h>
+#include "aul.h"
+
+static void print_app_status(int status);
+
+static void print_idle_info(void)
+{
+ int cnt = 0;
+ int *pids = NULL;
+ int i;
+ char appid_buf[1024] = {0,};
+ int ret;
+
+ aul_app_group_get_idle_pids(&cnt, &pids);
+ printf("< Idle : %d >\n", cnt);
+ if (pids) {
+ for (i = 0; i < cnt; ++i) {
+ printf("---------------------------\n");
+ printf(" pid : %d\n", pids[i]);
+ ret = aul_app_get_appid_bypid(pids[i], appid_buf, sizeof(appid_buf) - 1);
+
+ if (ret != AUL_R_OK) {
+ appid_buf[0] = '\0';
+ }
+ printf(" appid : %s\n", appid_buf);
+ }
+
+ free(pids);
+ }
+}
+
+static int print_info(void)
+{
+ int *leader_pids = NULL;
+ int *member_pids = NULL;
+ int group_cnt = 0;
+ int member_cnt = 0;
+ int win_id = 0;
+ int group_num = 0;
+ int member_num = 0;
+ int app_status = -1;
+ int ret = 0;
+ char appid_buf[1024] = {0,};
+ char pkgid_buf[1024] = {0,};
+ int fg;
+
+ aul_app_group_get_leader_pids(&group_cnt, &leader_pids);
+ printf("App group count : %d\n", group_cnt);
+ printf("\n");
+
+ if(group_cnt == 0){
+ printf("No app groups\n");
+ goto FINISH;
+ }
+
+ for(group_num = 0; group_num < group_cnt; group_num++){
+ aul_app_group_get_group_pids(leader_pids[group_num], &member_cnt, &member_pids);
+
+ printf("< Group : %d >\n", group_num + 1);
+ printf("member cnt : %d\n", member_cnt);
+ printf("\n");
+
+ for(member_num = 0; member_num < member_cnt; member_num++){
+ ret = aul_app_get_appid_bypid(member_pids[member_num], appid_buf, sizeof(appid_buf) - 1);
+
+ if(ret != AUL_R_OK){
+ appid_buf[0] = '\0';
+ }
+
+ ret = aul_app_get_pkgid_bypid(member_pids[member_num], pkgid_buf, sizeof(pkgid_buf) - 1);
+ if(ret != AUL_R_OK){
+ pkgid_buf[0] = '\0';
+ }
+
+ win_id = aul_app_group_get_window(member_pids[member_num]);
+ fg = aul_app_group_get_fg_flag(member_pids[member_num]);
+
+ printf("--- member : %d\n", member_num + 1);
+ printf(" - app id : %s\n", appid_buf);
+ printf(" - pkg id : %s\n", pkgid_buf);
+ printf(" - pid : %d\n", member_pids[member_num]);
+ printf(" - win id : %d\n", win_id);
+ if (fg)
+ printf(" - fg group : TRUE\n");
+ else
+ printf(" - fg group : FALSE\n");
+
+ app_status = aul_app_get_status_bypid(member_pids[member_num]);
+ print_app_status(app_status);
+ printf("\n");
+ }
+ printf("==================================\n");
+ printf("\n");
+ }
+
+FINISH:
+
+ if(leader_pids != NULL)
+ free(leader_pids);
+
+ if(leader_pids != NULL)
+ free(member_pids);
+
+ return 0;
+}
+
+static void print_app_status(int status)
+{
+ switch (status) {
+ case STATUS_LAUNCHING:
+ printf(" - status : STATUS_LAUNCHING \n");
+ break;
+ case STATUS_CREATED:
+ printf(" - status : STATUS_CREATED \n");
+ break;
+ case STATUS_FOCUS:
+ printf(" - status : STATUS_FOCUS \n");
+ break;
+ case STATUS_VISIBLE:
+ printf(" - status : STATUS_VISIBLE \n");
+ break;
+ case STATUS_BG:
+ printf(" - status : STATUS_BG \n");
+ break;
+ case STATUS_DYING:
+ printf(" - status : STATUS_DYING \n");
+ break;
+ case STATUS_HOME:
+ printf(" - status : STATUS_HOME \n");
+ break;
+ case STATUS_NORESTART:
+ printf(" - status : STATUS_NORESTART \n");
+ break;
+ default:
+ printf(" - status error or unknown status\n");
+ break;
+ };
+}
+
+int main(int argc, char** argv)
+{
+ printf("\n");
+ printf("### App Group Informantion ###\n");
+ printf("\n");
+
+ print_info();
+ print_idle_info();
+
+ printf("### end ###\n");
+
+ return 0;
+}