CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
-PROJECT(aul C CXX)
-SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
+
+PROJECT(aul)
+
SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(BINDIR "${CMAKE_INSTALL_PREFIX}/bin")
+SET(LIBDIR ${LIB_INSTALL_DIR})
+SET(INCLUDEDIR "\${prefix}/include")
SET(EXEC_PREFIX "\${prefix}")
-SET(VERSION ${FULLVER})
ADD_DEFINITIONS("-DSHARE_PREFIX=\"${SHARE_INSTALL_PREFIX}/aul\"")
-# Set required packages
-INCLUDE(FindPkgConfig)
-SET(AUL-1_LIB_PKG_CHECK_MODULES
- bundle
- capi-system-info
- dlog
- gio-2.0
- glib-2.0
- iniparser
- libsmack
- libtzplatform-config
- libxml-2.0
- pkgmgr-info
- sqlite3
- storage
- ttrace
- uuid
- vconf
- xdgmime
- )
-pkg_check_modules(libpkgs REQUIRED ${AUL-1_LIB_PKG_CHECK_MODULES})
-
-FOREACH(flag ${libpkgs_CFLAGS})
- SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
-ENDFOREACH(flag)
-
-pkg_check_modules(APP_LAUNCHER_DEPS glib-2.0 pkgmgr-info bundle)
-FOREACH(APP_LAUNCHER_FLAGS ${APP_LAUNCHER_DEPS_CFLAGS})
- SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${APP_LAUNCHER_FLAGS}")
-ENDFOREACH(APP_LAUNCHER_FLAGS)
-
-# Compiler flags
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/legacy)
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/feature)
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/aul)
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/aul/api)
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/aul/app_manager)
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/aul/common)
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/aul/socket)
-
-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} -Werror")
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+## Compile flags
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-zdefs -fvisibility=hidden -g -Wall -Werror -fpic")
SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
SET(CMAKE_C_FLAGS_RELEASE "-O2")
-SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -fvisibility=hidden -std=c++14")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_C_FLAGS} -std=c++14")
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
SET(CMAKE_CXX_FLAGS_RELEASE "-O2")
-SET(CMAKE_SKIP_BUILD_RPATH true)
-# Linker flags
SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
-# aul
-AUX_SOURCE_DIRECTORY(src SOURCES)
-AUX_SOURCE_DIRECTORY(aul AUL_SOURCES)
-AUX_SOURCE_DIRECTORY(aul/api AUL_API_SOURCES)
-AUX_SOURCE_DIRECTORY(aul/app_manager AUL_APP_MANAGER_SOURCES)
-AUX_SOURCE_DIRECTORY(aul/common AUL_COMMON_SOURCES)
-AUX_SOURCE_DIRECTORY(aul/socket AUL_SOCKET_SOURCES)
-add_library(aul SHARED
- ${SOURCES}
- ${AUL_SOURCES}
- ${AUL_API_SOURCES}
- ${AUL_APP_MANAGER_SOURCES}
- ${AUL_COMMON_SOURCES}
- ${AUL_SOCKET_SOURCES})
-TARGET_LINK_LIBRARIES(aul ${libpkgs_LDFLAGS})
-SET_TARGET_PROPERTIES(aul PROPERTIES SOVERSION ${MAJORVER})
-SET_TARGET_PROPERTIES(aul PROPERTIES VERSION ${FULLVER})
-INSTALL(TARGETS aul DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries)
+SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
+
+## Target
+SET(TARGET_AUL "aul")
+
+ENABLE_TESTING()
+SET(TARGET_AUL_UNIT_TEST "aul-unit-test")
+
+INCLUDE(FindPkgConfig)
+INCLUDE(ApplyPkgConfig)
+
+PKG_CHECK_MODULES(BUNDLE_DEPS REQUIRED bundle)
+PKG_CHECK_MODULES(CAPI_SYSTEM_INFO_DEPS REQUIRED capi-system-info)
+PKG_CHECK_MODULES(DLOG_DEPS REQUIRED dlog)
+PKG_CHECK_MODULES(GIO_DEPS REQUIRED gio-2.0)
+PKG_CHECK_MODULES(GLIB_DEPS REQUIRED glib-2.0)
+PKG_CHECK_MODULES(GMOCK_DEPS REQUIRED gmock)
+PKG_CHECK_MODULES(INIPARSER_DEPS REQUIRED iniparser)
+PKG_CHECK_MODULES(LIBSMACK_DEPS REQUIRED libsmack)
+PKG_CHECK_MODULES(LIBTZPLATFORM_CONFIG_DEPS REQUIRED libtzplatform-config)
+PKG_CHECK_MODULES(LIBXML_DEPS REQUIRED libxml-2.0)
+PKG_CHECK_MODULES(PKGMGR_INFO_DEPS REQUIRED pkgmgr-info)
+PKG_CHECK_MODULES(PKGMGR_INSTALLER_DEPS REQUIRED pkgmgr-installer)
+PKG_CHECK_MODULES(SQLITE3_DEPS REQUIRED sqlite3)
+PKG_CHECK_MODULES(STORAGE_DEPS REQUIRED storage)
+PKG_CHECK_MODULES(TTRACE_DEPS REQUIRED ttrace)
+PKG_CHECK_MODULES(UUID_DEPS REQUIRED uuid)
+PKG_CHECK_MODULES(VCONF_DEPS REQUIRED vconf)
+PKG_CHECK_MODULES(XDGMIME_DEPS REQUIRED xdgmime)
+
+
+## Target sources
+AUX_SOURCE_DIRECTORY(src SRCS)
+AUX_SOURCE_DIRECTORY(aul AUL_SRCS)
+AUX_SOURCE_DIRECTORY(aul/api AUL_API_SRCS)
+AUX_SOURCE_DIRECTORY(aul/app_manager AUL_APP_MANAGER_SRCS)
+AUX_SOURCE_DIRECTORY(aul/common AUL_COMMON_SRCS)
+AUX_SOURCE_DIRECTORY(aul/socket AUL_SOCKET_SRCS)
+
+ADD_LIBRARY(${TARGET_AUL} SHARED
+ ${SRCS}
+ ${AUL_SRCS}
+ ${AUL_API_SRCS}
+ ${AUL_APP_MANAGER_SRCS}
+ ${AUL_COMMON_SRCS}
+ ${AUL_SOCKET_SRCS}
+)
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_AUL} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/include
+ ${CMAKE_CURRENT_SOURCE_DIR}/include/internal
+ ${CMAKE_CURRENT_SOURCE_DIR}/aul/
+ ${CMAKE_CURRENT_SOURCE_DIR}/aul/api
+ ${CMAKE_CURRENT_SOURCE_DIR}/aul/app_manager
+ ${CMAKE_CURRENT_SOURCE_DIR}/aul/common
+ ${CMAKE_CURRENT_SOURCE_DIR}/aul/socket
+)
+
+SET_TARGET_PROPERTIES(${TARGET_AUL} PROPERTIES SOVERSION ${MAJORVER})
+SET_TARGET_PROPERTIES(${TARGET_AUL} PROPERTIES VERSION ${FULLVER})
+
+APPLY_PKG_CONFIG(${TARGET_AUL} PUBLIC
+ BUNDLE_DEPS
+ CAPI_SYSTEM_INFO_DEPS
+ DLOG_DEPS
+ GIO_DEPS
+ GLIB_DEPS
+ INIPARSER_DEPS
+ LIBSMACK_DEPS
+ LIBTZPLATFORM_CONFIG_DEPS
+ LIBXML_DEPS
+ PKGMGR_INFO_DEPS
+ SQLITE3_DEPS
+ STORAGE_DEPS
+ TTRACE_DEPS
+ UUID_DEPS
+ VCONF_DEPS
+ XDGMIME_DEPS
+)
+
+INSTALL(TARGETS ${TARGET_AUL} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries)
# pkgconfig file
CONFIGURE_FILE(aul.pc.in aul.pc @ONLY)
CONFIGURE_FILE(feature/preexec_list.txt.in feature/preexec_list.txt @ONLY)
-SET(HEADERS_LIB_AUL
- aul.h
- aul_sock.h
- aul_proc.h
- aul_rsc_mgr.h
- aul_svc.h
- aul_cmd.h
- aul_app_com.h
- aul_screen_connector.h
- aul_window.h
- aul_widget.h
- aul_job_scheduler.h
- aul_rpc_port.h
- aul_complication.h
- aul_debug_info.h
- aul_watchdog.h
- aul_svc_internal.h
- aul_key.h
- aul_comp_status.h
- aul_app_group.h
- aul_comp_info.h
- aul_comp_context.h
- aul_comp_info_internal.h
- aul_watch_control.h
- aul_comp_types.h
- aul_launcher_service.h
- aul_running_context.h
- )
-
-# Install headers, other files
-FOREACH(hfile ${HEADERS_LIB_AUL})
- INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/${hfile} DESTINATION include/aul)
-ENDFOREACH(hfile)
-
-SET(HEADERS_LIB_AUL_API
- aul_app_context.h
- aul_app_manager.h
- aul_app_event.h
- )
-FOREACH(hfile ${HEADERS_LIB_AUL_API})
- INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/aul/api/${hfile} DESTINATION include/aul/api)
-ENDFOREACH(hfile)
-
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/aul.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/feature/preexec_list.txt DESTINATION ${SHARE_INSTALL_PREFIX}/aul )
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/miregex DESTINATION ${SHARE_INSTALL_PREFIX}/aul )
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/aul.conf DESTINATION /etc/dbus-1/system.d)
+INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/include/ DESTINATION include/aul/
+ FILES_MATCHING
+ PATTERN "*.h"
+)
+INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/aul/api/ DESTINATION include/aul/api/
+ FILES_MATCHING
+ PATTERN "*.h"
+)
-# tool
+## Sub directories
ADD_SUBDIRECTORY(tool)
ADD_SUBDIRECTORY(parser)
+ADD_SUBDIRECTORY(test)
--- /dev/null
+# Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+#
+# This function applies external (out of source tree) dependencies
+# to given target. Arguments are:
+# TARGET - valid cmake target
+# PRIVACY - dependency can be inherited by dependent targets or not:
+# PUBLIC - this should be used by default, cause compile/link flags passing
+# PRIVATE - do not passes any settings to dependent targets,
+# may be usefull for static libraries from the inside of the project
+# Argument ARGV2 and following are supposed to be names of checked pkg config
+# packages. This function will use variables created by check_pkg_modules().
+# - ${DEP_NAME}_LIBRARIES
+# - ${DEP_NAME}_INCLUDE_DIRS
+# - ${DEP_NAME}_CFLAGS
+#
+FUNCTION(APPLY_PKG_CONFIG TARGET PRIVACY)
+ MATH(EXPR DEST_INDEX "${ARGC}-1")
+ FOREACH(I RANGE 2 ${DEST_INDEX})
+ IF(NOT ${ARGV${I}}_FOUND)
+ MESSAGE(FATAL_ERROR "Not found dependency - ${ARGV${I}}_FOUND")
+ ENDIF(NOT ${ARGV${I}}_FOUND)
+ TARGET_LINK_LIBRARIES(${TARGET} ${PRIVACY} "${${ARGV${I}}_LIBRARIES}")
+ TARGET_INCLUDE_DIRECTORIES(${TARGET} ${PRIVACY} SYSTEM "${${ARGV${I}}_INCLUDE_DIRS}")
+ STRING(REPLACE ";" " " CFLAGS_STR "${${ARGV${I}}_CFLAGS}")
+ SET(CFLAGS_LIST ${CFLAGS_STR})
+ SEPARATE_ARGUMENTS(CFLAGS_LIST)
+ FOREACH(OPTION ${CFLAGS_LIST})
+ TARGET_COMPILE_OPTIONS(${TARGET} ${PRIVACY} ${OPTION})
+ ENDFOREACH(OPTION)
+ SET_TARGET_PROPERTIES(${TARGET} PROPERTIES SKIP_BUILD_RPATH true)
+ ENDFOREACH(I RANGE 2 ${DEST_INDEX})
+ENDFUNCTION(APPLY_PKG_CONFIG TARGET PRIVACY)
+++ /dev/null
-/*
- * Copyright (c) 2000 - 2017 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.
- */
-
-#pragma once
-
-#define AUL_DBUS_PATH "/aul/dbus_handler"
-#define AUL_DBUS_SIGNAL_INTERFACE "org.tizen.aul.signal"
-#define AUL_DBUS_APPDEAD_SIGNAL "app_dead"
-#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 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"
-
-#define SYSTEM_PATH_CORE "/org/tizen/system"
-#define SYSTEM_INTERFACE_CORE "org.tizen.system.Booting"
-#define SYSTEM_SIGNAL_BOOTING_DONE "BootingDone"
-
-#define SYSTEM_PATH_THERMAL "/Org/Tizen/System/Thermal"
-#define SYSTEM_INTERFACE_THERMAL "org.tizen.system.thermal"
-#define SYSTEM_SIGNAL_COOLDOWN_MODE_CHANGED "CoolDownModeChanged"
-
-#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"
-
-#define RESOURCED_BUS_NAME "org.tizen.resourced"
-#define RESOURCED_PROC_PATH "/Org/Tizen/ResourceD/Process"
-#define RESOURCED_PROC_INTERFACE "org.tizen.resourced.process"
-#define RESOURCED_PROC_STATUS_SIGNAL "ProcStatus"
-#define RESOURCED_PROC_PRELAUNCH_SIGNAL "ProcPrelaunch"
-#define RESOURCED_PROC_WATCHDOG_SIGNAL "ProcWatchdog"
-#define RESOURCED_PROC_METHOD "ProcExclude"
-#define RESOURCED_PROC_TYPE_EXCLUDE "exclude"
-#define RESOURCED_PROC_TYPE_INCLUDE "include"
-#define RESOURCED_PROC_TYPE_WAKEUP "wakeup"
-
-#define RESOURCED_FREEZER_PATH "/Org/Tizen/Resourced/Freezer"
-#define RESOURCED_FREEZER_INTERFACE "org.tizen.resourced.freezer"
-#define RESOURCED_FREEZER_SIGNAL "FreezerState"
-
-#define ROTATION_BUS_NAME "org.tizen.system.coord"
-#define ROTATION_OBJECT_PATH "/Org/Tizen/System/Coord/Rotation"
-#define ROTATION_INTERFACE_NAME "org.tizen.system.coord.rotation"
-#define ROTATION_METHOD_NAME "Degree"
-
-#define APPFW_SUSPEND_HINT_PATH "/Org/Tizen/Appfw/SuspendHint"
-#define APPFW_SUSPEND_HINT_INTERFACE "org.tizen.appfw.SuspendHint"
-#define APPFW_SUSPEND_HINT_SIGNAL "SuspendHint"
+++ /dev/null
-/*
- * Copyright (c) 2000 - 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 API
-#define API __attribute__ ((visibility("default")))
-#endif
+++ /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.
- */
-
-#pragma once
-
-#include <sqlite3.h>
-#include <stdbool.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
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-int _svc_db_add_app(const char *op, const char *mime_type, const char *uri, const char *pkg_name, uid_t uid);
-int _svc_db_delete_with_pkgname(const char *pkg_name, uid_t uid);
-char* _svc_db_get_app(const char *op, const char *mime_type, const char *uri, uid_t uid);
-int _svc_db_is_defapp(const char *pkg_name, uid_t uid);
-int _svc_db_adjust_list_with_submode(int mainapp_mode, char *win_id, GSList **pkg_list, uid_t uid);
-int _svc_db_get_list_with_all_defapps(GSList **pkg_list, uid_t uid);
-int _svc_db_delete_all(uid_t uid);
-
-char *_svc_db_query_builder_in(const char *field, char *args);
-char *_svc_db_query_builder_or(char *q1, char *q2);
-char *_svc_db_query_builder_add(char *old_query, char *op, char *uri, char *mime, bool collate);
-char *_svc_db_query_builder_build(char *old_query);
-int _svc_db_exec_query(const char *query, GSList **pkg_list, uid_t uid);
-
-int _svc_db_add_alias_appid(const char *alias_appid, const char *appid,
- uid_t uid);
-int _svc_db_delete_alias_appid(const char *alias_appid, uid_t uid);
-int _svc_db_get_appid_from_alias_info(const char *alias_appid,
- char **appid, uid_t uid);
-int _svc_db_foreach_alias_info(void (*callback)(const char *alias_appid, const
- char *appid, void *data),
- uid_t uid, void *user_data);
-int _svc_db_enable_alias_info(const char *appid, uid_t uid);
-int _svc_db_disable_alias_info(const char *appid, uid_t uid);
-int _svc_db_foreach_alias_info_by_appid(int (*callback)(
- const char *alias_appid, const char *appid, void *data),
- const char *appid, uid_t uid, void *user_data);
-int _svc_db_foreach_allowed_info(int (*callback)(const char *appid,
- const char *allowed_appid, void *data),
- uid_t uid, void *user_data);
-int _svc_db_foreach_allowed_info_by_appid(int (*callback)(const char *appid,
- const char *allowed_appid, void *data),
- const char *appid, uid_t uid, void *user_data);
-
-#ifdef __cplusplus
-}
-#endif
-
-
+++ /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.
- */
-
-#pragma once
-
-/** 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__"
-
-
+++ /dev/null
-/*
- * Copyright (c) 2000 - 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.
- */
-
-#pragma once
-
-#include <unistd.h>
-#include <dlog.h>
-#include <tzplatform_config.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
-
-#undef LOG_TAG
-#define LOG_TAG "AUL"
-
-#define _E(fmt, arg...) LOGE(fmt, ##arg)
-#define _D(fmt, arg...) LOGD(fmt, ##arg)
-#define _W(fmt, arg...) LOGW(fmt, ##arg)
-#define _I(fmt, arg...) LOGI(fmt, ##arg)
-
-#define AUL_UTIL_PID -2
-#define MAX_LOCAL_BUFSZ 128
-#define MAX_PACKAGE_STR_SIZE 512
-#define MAX_PID_STR_BUFSZ 20
-#define MAX_UID_STR_BUFSZ 20
-#define REGULAR_UID_MIN 5000
-#define MAX_RUNNING_INSTANCE 10000
-
-typedef enum {
- TIZEN_PROFILE_UNKNOWN = 0,
- TIZEN_PROFILE_MOBILE = 0x1,
- TIZEN_PROFILE_WEARABLE = 0x2,
- TIZEN_PROFILE_TV = 0x4,
- TIZEN_PROFILE_IVI = 0x8,
- TIZEN_PROFILE_COMMON = 0x10,
-} tizen_profile_t;
-
-tizen_profile_t _get_tizen_profile(void);
-
-#define TIZEN_FEATURE_SOCKET_TIMEOUT (_get_tizen_profile() & TIZEN_PROFILE_TV)
-#define TIZEN_FEATURE_SHARE_PANEL (_get_tizen_profile() & TIZEN_PROFILE_MOBILE)
-
-#ifdef __cplusplus
-}
-#endif
+++ /dev/null
-/*
- * Copyright (c) 2019 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_WORKER_H__
-#define __AUL_WORKER_H__
-
-#include <stdbool.h>
-
-typedef void *aul_worker_h;
-
-typedef bool (*aul_worker_io_job_cb)(int fd, void *user_data);
-
-aul_worker_h aul_worker_create(const char *name);
-
-void aul_worker_destroy(aul_worker_h handle);
-
-int aul_worker_add_io_job(aul_worker_h handle, const char *job_name,
- int fd, aul_worker_io_job_cb callback, void *user_data);
-
-int aul_worker_add_anr_timer(aul_worker_h handle, int cmd);
-
-int aul_worker_remove_anr_timer(aul_worker_h handle);
-
-#endif /* __AUL_WORKER_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2000 - 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.
- */
-
-#pragma once
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int app_key_event(bundle *kb);
-
-#ifdef __cplusplus
-}
-#endif
+++ /dev/null
-/*
- * Copyright (c) 2000 - 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.
- */
-
-#pragma once
-
-#include <glib.h>
-
-int aul_initialize();
-int aul_is_initialized();
-int aul_app_register_pid(const char *appid, int pid);
-
-int app_send_cmd(int pid, int cmd, bundle *kb);
-int app_send_cmd_for_uid(int pid, uid_t uid, int cmd, bundle *kb);
-int app_send_cmd_with_noreply(int pid, int cmd, bundle *kb);
-int app_send_cmd_to_launchpad(const char *pad_type, uid_t uid, int cmd, bundle *kb);
-int app_request_to_launchpad(int cmd, const char *pkgname, bundle *kb);
-int app_request_to_launchpad_for_uid(int cmd, const char *pkgname, bundle *kb, uid_t uid);
-
-int app_result(int cmd, bundle *kb, int launched_pid);
-int aul_send_result(bundle *kb, int is_cancel);
-int aul_launch_app_with_result(const char *pkgname, bundle *kb,
- void (*cbfunc) (bundle *, int, void *),
- void *data);
-int aul_launch_app_with_result_for_uid(const char *pkgname, bundle *kb,
- void (*cbfunc) (bundle *, int, void *),
- void *data, uid_t uid);
-int app_subapp_terminate_request(void);
-
-int app_com_recv(bundle *b);
-int aul_launch_app_with_result_async(const char *appid, bundle *b,
- void (*callback)(bundle *, int, void *), void *data);
-int aul_launch_app_with_result_async_for_uid(const char *appid, bundle *b,
- void (*callback)(bundle *, int, void *), void *data, uid_t uid);
-int aul_resume_local(void);
-int aul_launch_fini(void);
-int aul_send_launch_request_for_uid(const char *appid, bundle *b, uid_t uid,
- void (*reply_cb)(bundle *b, int, void *),
- void (*error_cb)(int, void *), void *user_data);
-int aul_send_launch_request_sync_for_uid(const char *appid, bundle *b,
- uid_t uid, bundle **res_b);
-int app_request_local(int cmd, bundle *kb);
-int aul_subapp_terminate_request(const char *instance_id, int pid);
-int aul_send_resume_request_for_uid(const char *appid, bundle *b, uid_t uid,
- void (*error_cb)(int, void *), void *user_data);
+++ /dev/null
-/*
- * Copyright (c) 2000 - 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.
- */
-
-#pragma once
-
-#include <pkgmgr-info.h>
-#include <string.h>
-#include <stdio.h>
-
-#include "aul_util.h"
-
-#define MAX_PATH_LEN 1024
-
-#define AUL_APP_INFO_FLD_PKG_NAME "package"
-#define AUL_APP_INFO_FLD_APP_PATH "exec"
-#define AUL_APP_INFO_FLD_APP_TYPE "x_slp_packagetype"
-#define AUL_APP_INFO_FLD_WIDTH "x_slp_baselayoutwidth"
-#define AUL_APP_INFO_FLD_HEIGHT "x_slp_baselayoutheight"
-#define AUL_APP_INFO_FLD_VERTICAL "x_slp_ishorizontalscale"
-#define AUL_APP_INFO_FLD_MULTIPLE "x_slp_multiple"
-#define AUL_APP_INFO_FLD_TASK_MANAGE "x_slp_taskmanage"
-#define AUL_APP_INFO_FLD_MIMETYPE "mimetype"
-#define AUL_APP_INFO_FLD_SERVICE "x_slp_service"
-
-#define AUL_RETRIEVE_PKG_NAME "package = '?'"
-#define AUL_RETRIEVE_APP_PATH "exec = '?'"
-#define AUL_RETRIEVE_MIMETYPE "mimetype like '?'"
-#define AUL_RETRIEVE_SERVICE "x_slp_service like '?'"
-
-typedef struct {
- char *appid; /* appid */
- char *app_path; /* exec */
- char *original_app_path; /* exec */
- char *pkg_type; /* x_slp_packagetype */
- char *hwacc; /* hwacceleration */
- char *pkg_id;
-} app_info_from_db;
-
-static inline char *_get_appid(app_info_from_db *menu_info)
-{
- return menu_info ? menu_info->appid : NULL;
-}
-
-static inline char *_get_pkgid(app_info_from_db *menu_info)
-{
- return menu_info ? menu_info->pkg_id : NULL;
-}
-
-static inline char *_get_app_path(app_info_from_db *menu_info)
-{
- int i = 0;
- int path_len = -1;
-
- if (!menu_info || menu_info->app_path == NULL)
- return NULL;
-
- while (menu_info->app_path[i] != 0) {
- if (menu_info->app_path[i] == ' '
- || menu_info->app_path[i] == '\t') {
- path_len = i;
- break;
- }
- i++;
- }
-
- if (path_len == 0) {
- free(menu_info->app_path);
- menu_info->app_path = NULL;
- } else if (path_len > 0) {
- char *tmp_app_path = malloc(sizeof(char) * (path_len + 1));
- if (tmp_app_path == NULL)
- return NULL;
- snprintf(tmp_app_path, path_len + 1, "%s", menu_info->app_path);
- free(menu_info->app_path);
- menu_info->app_path = tmp_app_path;
- }
-
- return menu_info->app_path;
-}
-
-static inline char *_get_original_app_path(app_info_from_db *menu_info)
-{
- return menu_info ? menu_info->original_app_path : NULL;
-}
-
-static inline void _free_app_info_from_db(app_info_from_db *menu_info)
-{
- if (menu_info != NULL) {
- if (menu_info->appid != NULL)
- free(menu_info->appid);
- if (menu_info->app_path != NULL)
- free(menu_info->app_path);
- if (menu_info->original_app_path != NULL)
- free(menu_info->original_app_path);
- if (menu_info->pkg_type != NULL)
- free(menu_info->pkg_type);
- if (menu_info->hwacc != NULL)
- free(menu_info->hwacc);
- if (menu_info->pkg_id != NULL)
- free(menu_info->pkg_id);
- free(menu_info);
- }
-}
-
-static inline app_info_from_db *_get_app_info_from_db_by_pkgname(
- const char *appid)
-{
- 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;
-
- if (appid == NULL) {
- _free_app_info_from_db(menu_info);
- return NULL;
- }
-
-
- if (getuid() != GLOBAL_USER)
- ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, getuid(), &handle);
- else
- ret = pkgmgrinfo_appinfo_get_appinfo(appid, &handle);
-
- if (ret != PMINFO_R_OK) {
- _free_app_info_from_db(menu_info);
- return NULL;
- }
-
- menu_info->appid = 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 = 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 = pkgmgrinfo_appinfo_destroy_appinfo(handle);
- if (ret != PMINFO_R_OK)
- _E("pkgmgrinfo_appinfo_destroy_appinfo failed");
-
- if (!_get_app_path(menu_info)) {
- _free_app_info_from_db(menu_info);
- return NULL;
- }
-
- return menu_info;
-}
-
-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 *apppath;
- char *pkgid;
- int ret = PMINFO_R_OK;
-
- if (!menu_info)
- return ret;
-
- ret = pkgmgrinfo_appinfo_get_exec(appinfo, &apppath);
- if (ret == PMINFO_R_OK && apppath) {
- menu_info->app_path = strdup(apppath);
- if (menu_info->app_path == NULL) {
- _E("Out of memory");
- return PMINFO_R_ERROR;
- }
- }
-
- ret = pkgmgrinfo_appinfo_get_pkgid(appinfo, &pkgid);
- if (ret == PMINFO_R_OK && pkgid) {
- menu_info->pkg_id = strdup(pkgid);
- if (menu_info->pkg_id == NULL) {
- _E("Out of memory");
- return PMINFO_R_ERROR;
- }
- }
-
- return ret;
-}
-
-static inline app_info_from_db *_get_app_info_from_db_by_appid_user(
- const char *appid, uid_t uid)
-{
- app_info_from_db *menu_info;
- pkgmgrinfo_appinfo_filter_h filter;
- int ret = PMINFO_R_OK;
-
- if (uid == 0) {
- _E("request from root, treat as global user");
- uid = GLOBAL_USER;
- }
-
- if (appid == NULL)
- return NULL;
-
- menu_info = calloc(1, sizeof(app_info_from_db));
- if (menu_info == NULL)
- return NULL;
-
- ret = pkgmgrinfo_appinfo_filter_create(&filter);
- if (ret != PMINFO_R_OK) {
- _free_app_info_from_db(menu_info);
- return NULL;
- }
-
- ret = pkgmgrinfo_appinfo_filter_add_string(filter,
- PMINFO_APPINFO_PROP_APP_ID, appid);
- if (ret != PMINFO_R_OK) {
- pkgmgrinfo_appinfo_filter_destroy(filter);
- _free_app_info_from_db(menu_info);
- return NULL;
- }
-
- if (uid != GLOBAL_USER)
- ret = pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(filter,
- __appinfo_func, (void *)menu_info, uid);
- else
- ret = pkgmgrinfo_appinfo_filter_foreach_appinfo(filter,
- __appinfo_func, (void *)menu_info);
-
- if ((ret != PMINFO_R_OK) || (menu_info->app_path == NULL)) {
- pkgmgrinfo_appinfo_filter_destroy(filter);
- _free_app_info_from_db(menu_info);
- return NULL;
- }
-
- pkgmgrinfo_appinfo_filter_destroy(filter);
-
- menu_info->appid = strdup(appid);
- menu_info->original_app_path = strdup(menu_info->app_path);
-
- return menu_info;
-
-}
-
-static inline app_info_from_db *_get_app_info_from_db_by_appid(
- const char *appid)
-{
- return _get_app_info_from_db_by_appid_user(appid, GLOBAL_USER);
-}
-
-
+++ /dev/null
-/*
- * Copyright (c) 2000 - 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.
- */
-
-#pragma once
-
-#include <regex.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct _regex_tbl {
- char *mimetype;
- char *regex;
- char *desc;
- regex_t regex_preg;
- struct _regex_tbl *next;
-} regex_tbl;
-
-regex_tbl *miregex_get_regex_table();
-
-#ifdef __cplusplus
-}
-#endif
BuildRequires: pkgconfig(libxml-2.0)
BuildRequires: pkgconfig(uuid)
BuildRequires: pkgconfig(libsmack)
+BuildRequires: pkgconfig(gmock)
Recommends: amd
Recommends: amd-mod-component-manager
-CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
-
ADD_SUBDIRECTORY(metadata)
ADD_SUBDIRECTORY(component)
-CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
-PROJECT(component-plugin-parser C)
-
-SET(COMPONENT_PLUGIN_PARSER "component-based-application")
+SET(TARGET_COMPONENT_PLUGIN_PARSER "component-based-application")
SET(SHARED_DIR "${CMAKE_INSTALL_PREFIX}/share")
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/inc)
-
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SRCS)
-
-INCLUDE(FindPkgConfig)
-pkg_check_modules(COMPONENT_PLUGIN_PARSER REQUIRED
- glib-2.0
- libxml-2.0
- dlog
- libtzplatform-config
- pkgmgr-installer
- pkgmgr-info
- sqlite3
- )
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -Wall -Werror -Winline")
-FOREACH(flag ${COMPONENT_PLUGIN_PARSER_CFLAGS})
- SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
-ENDFOREACH(flag)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src
+ COMPONENT_PLUGIN_PARSER_SRCS)
-SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -fPIC -Wall -Werror -Winline")
+ADD_LIBRARY(${TARGET_COMPONENT_PLUGIN_PARSER} SHARED ${COMPONENT_PLUGIN_PARSER_SRCS})
+TARGET_LINK_LIBRARIES(${TARGET_COMPONENT_PLUGIN_PARSER} PUBLIC dl)
-ADD_LIBRARY(${COMPONENT_PLUGIN_PARSER} SHARED ${SRCS})
+TARGET_INCLUDE_DIRECTORIES(${TARGET_COMPONENT_PLUGIN_PARSER}
+ PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/inc)
-SET_TARGET_PROPERTIES(${COMPONENT_PLUGIN_PARSER} PROPERTIES COMPILE_FLAGS "${EXTRA_CFLAGS}")
-TARGET_LINK_LIBRARIES(${COMPONENT_PLUGIN_PARSER} ${COMPONENT_PLUGIN_PARSER_LDFLAGS} "-ldl")
+APPLY_PKG_CONFIG(${TARGET_COMPONENT_PLUGIN_PARSER} PUBLIC
+ DLOG_DEPS
+ GLIB_DEPS
+ LIBTZPLATFORM_CONFIG_DEPS
+ LIBXML_DEPS
+ PKGMGR_INFO_DEPS
+ PKGMGR_INSTALLER_DEPS
+ SQLITE3_DEPS
+)
-INSTALL(TARGETS ${COMPONENT_PLUGIN_PARSER}
- DESTINATION ${SYSCONF_INSTALL_DIR}/package-manager/parserlib)
+INSTALL(TARGETS ${TARGET_COMPONENT_PLUGIN_PARSER}
+ DESTINATION ${SYSCONF_INSTALL_DIR}/package-manager/parserlib)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/component.info
- DESTINATION ${SHARED_DIR}/parser-plugins)
+ DESTINATION ${SHARED_DIR}/parser-plugins)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/script/14_component-add.post
- DESTINATION ${SYSCONF_INSTALL_DIR}/gumd/useradd.d)
+ DESTINATION ${SYSCONF_INSTALL_DIR}/gumd/useradd.d)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/script/501.component_upgrade.sh
- DESTINATION ${SHARE_INSTALL_PREFIX}/upgrade/scripts)
+ DESTINATION ${SHARE_INSTALL_PREFIX}/upgrade/scripts)
-CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
-PROJECT(aul-parser C)
+SET(TARGET_AUL_PARSER "aul-parser")
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/inc)
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src AUL_PARSER_SRCS)
-pkg_check_modules(PKGS REQUIRED
- glib-2.0
- libxml-2.0
- dlog
- libtzplatform-config
- pkgmgr-installer
- sqlite3
- )
+ADD_LIBRARY(${TARGET_AUL_PARSER} SHARED ${AUL_PARSER_SRCS})
-FOREACH(FLAGS ${PKGS_CFLAGS})
- SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAGS}")
-ENDFOREACH(FLAGS)
+TARGET_INCLUDE_DIRECTORIES(${TARGET_AUL_PARSER}
+ PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/inc)
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden -fPIC")
+APPLY_PKG_CONFIG(${TARGET_AUL_PARSER} PUBLIC
+ DLOG_DEPS
+ GLIB_DEPS
+ LIBTZPLATFORM_CONFIG_DEPS
+ LIBXML_DEPS
+ PKGMGR_INSTALLER_DEPS
+ SQLITE3_DEPS
+)
-ADD_LIBRARY(aul-parser SHARED ${SRCS})
-TARGET_LINK_LIBRARIES(aul-parser ${PKGS_LDFLAGS})
-
-INSTALL(TARGETS aul-parser DESTINATION ${SYSCONF_INSTALL_DIR}/package-manager/parserlib/metadata)
+INSTALL(TARGETS ${TARGET_AUL_PARSER}
+ DESTINATION ${SYSCONF_INSTALL_DIR}/package-manager/parserlib/metadata)
--- /dev/null
+/*
+ * Copyright (c) 2000 - 2017 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.
+ */
+
+#pragma once
+
+#define AUL_DBUS_PATH "/aul/dbus_handler"
+#define AUL_DBUS_SIGNAL_INTERFACE "org.tizen.aul.signal"
+#define AUL_DBUS_APPDEAD_SIGNAL "app_dead"
+#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 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"
+
+#define SYSTEM_PATH_CORE "/org/tizen/system"
+#define SYSTEM_INTERFACE_CORE "org.tizen.system.Booting"
+#define SYSTEM_SIGNAL_BOOTING_DONE "BootingDone"
+
+#define SYSTEM_PATH_THERMAL "/Org/Tizen/System/Thermal"
+#define SYSTEM_INTERFACE_THERMAL "org.tizen.system.thermal"
+#define SYSTEM_SIGNAL_COOLDOWN_MODE_CHANGED "CoolDownModeChanged"
+
+#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"
+
+#define RESOURCED_BUS_NAME "org.tizen.resourced"
+#define RESOURCED_PROC_PATH "/Org/Tizen/ResourceD/Process"
+#define RESOURCED_PROC_INTERFACE "org.tizen.resourced.process"
+#define RESOURCED_PROC_STATUS_SIGNAL "ProcStatus"
+#define RESOURCED_PROC_PRELAUNCH_SIGNAL "ProcPrelaunch"
+#define RESOURCED_PROC_WATCHDOG_SIGNAL "ProcWatchdog"
+#define RESOURCED_PROC_METHOD "ProcExclude"
+#define RESOURCED_PROC_TYPE_EXCLUDE "exclude"
+#define RESOURCED_PROC_TYPE_INCLUDE "include"
+#define RESOURCED_PROC_TYPE_WAKEUP "wakeup"
+
+#define RESOURCED_FREEZER_PATH "/Org/Tizen/Resourced/Freezer"
+#define RESOURCED_FREEZER_INTERFACE "org.tizen.resourced.freezer"
+#define RESOURCED_FREEZER_SIGNAL "FreezerState"
+
+#define ROTATION_BUS_NAME "org.tizen.system.coord"
+#define ROTATION_OBJECT_PATH "/Org/Tizen/System/Coord/Rotation"
+#define ROTATION_INTERFACE_NAME "org.tizen.system.coord.rotation"
+#define ROTATION_METHOD_NAME "Degree"
+
+#define APPFW_SUSPEND_HINT_PATH "/Org/Tizen/Appfw/SuspendHint"
+#define APPFW_SUSPEND_HINT_INTERFACE "org.tizen.appfw.SuspendHint"
+#define APPFW_SUSPEND_HINT_SIGNAL "SuspendHint"
--- /dev/null
+/*
+ * Copyright (c) 2000 - 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 API
+#define API __attribute__ ((visibility("default")))
+#endif
--- /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.
+ */
+
+#pragma once
+
+#include <sqlite3.h>
+#include <stdbool.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
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+int _svc_db_add_app(const char *op, const char *mime_type, const char *uri, const char *pkg_name, uid_t uid);
+int _svc_db_delete_with_pkgname(const char *pkg_name, uid_t uid);
+char* _svc_db_get_app(const char *op, const char *mime_type, const char *uri, uid_t uid);
+int _svc_db_is_defapp(const char *pkg_name, uid_t uid);
+int _svc_db_adjust_list_with_submode(int mainapp_mode, char *win_id, GSList **pkg_list, uid_t uid);
+int _svc_db_get_list_with_all_defapps(GSList **pkg_list, uid_t uid);
+int _svc_db_delete_all(uid_t uid);
+
+char *_svc_db_query_builder_in(const char *field, char *args);
+char *_svc_db_query_builder_or(char *q1, char *q2);
+char *_svc_db_query_builder_add(char *old_query, char *op, char *uri, char *mime, bool collate);
+char *_svc_db_query_builder_build(char *old_query);
+int _svc_db_exec_query(const char *query, GSList **pkg_list, uid_t uid);
+
+int _svc_db_add_alias_appid(const char *alias_appid, const char *appid,
+ uid_t uid);
+int _svc_db_delete_alias_appid(const char *alias_appid, uid_t uid);
+int _svc_db_get_appid_from_alias_info(const char *alias_appid,
+ char **appid, uid_t uid);
+int _svc_db_foreach_alias_info(void (*callback)(const char *alias_appid, const
+ char *appid, void *data),
+ uid_t uid, void *user_data);
+int _svc_db_enable_alias_info(const char *appid, uid_t uid);
+int _svc_db_disable_alias_info(const char *appid, uid_t uid);
+int _svc_db_foreach_alias_info_by_appid(int (*callback)(
+ const char *alias_appid, const char *appid, void *data),
+ const char *appid, uid_t uid, void *user_data);
+int _svc_db_foreach_allowed_info(int (*callback)(const char *appid,
+ const char *allowed_appid, void *data),
+ uid_t uid, void *user_data);
+int _svc_db_foreach_allowed_info_by_appid(int (*callback)(const char *appid,
+ const char *allowed_appid, void *data),
+ const char *appid, uid_t uid, void *user_data);
+
+#ifdef __cplusplus
+}
+#endif
+
+
--- /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.
+ */
+
+#pragma once
+
+/** 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__"
+
+
--- /dev/null
+/*
+ * Copyright (c) 2000 - 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.
+ */
+
+#pragma once
+
+#include <unistd.h>
+#include <dlog.h>
+#include <tzplatform_config.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
+
+#undef LOG_TAG
+#define LOG_TAG "AUL"
+
+#define _E(fmt, arg...) LOGE(fmt, ##arg)
+#define _D(fmt, arg...) LOGD(fmt, ##arg)
+#define _W(fmt, arg...) LOGW(fmt, ##arg)
+#define _I(fmt, arg...) LOGI(fmt, ##arg)
+
+#define AUL_UTIL_PID -2
+#define MAX_LOCAL_BUFSZ 128
+#define MAX_PACKAGE_STR_SIZE 512
+#define MAX_PID_STR_BUFSZ 20
+#define MAX_UID_STR_BUFSZ 20
+#define REGULAR_UID_MIN 5000
+#define MAX_RUNNING_INSTANCE 10000
+
+typedef enum {
+ TIZEN_PROFILE_UNKNOWN = 0,
+ TIZEN_PROFILE_MOBILE = 0x1,
+ TIZEN_PROFILE_WEARABLE = 0x2,
+ TIZEN_PROFILE_TV = 0x4,
+ TIZEN_PROFILE_IVI = 0x8,
+ TIZEN_PROFILE_COMMON = 0x10,
+} tizen_profile_t;
+
+tizen_profile_t _get_tizen_profile(void);
+
+#define TIZEN_FEATURE_SOCKET_TIMEOUT (_get_tizen_profile() & TIZEN_PROFILE_TV)
+#define TIZEN_FEATURE_SHARE_PANEL (_get_tizen_profile() & TIZEN_PROFILE_MOBILE)
+
+#ifdef __cplusplus
+}
+#endif
--- /dev/null
+/*
+ * Copyright (c) 2019 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_WORKER_H__
+#define __AUL_WORKER_H__
+
+#include <stdbool.h>
+
+typedef void *aul_worker_h;
+
+typedef bool (*aul_worker_io_job_cb)(int fd, void *user_data);
+
+aul_worker_h aul_worker_create(const char *name);
+
+void aul_worker_destroy(aul_worker_h handle);
+
+int aul_worker_add_io_job(aul_worker_h handle, const char *job_name,
+ int fd, aul_worker_io_job_cb callback, void *user_data);
+
+int aul_worker_add_anr_timer(aul_worker_h handle, int cmd);
+
+int aul_worker_remove_anr_timer(aul_worker_h handle);
+
+#endif /* __AUL_WORKER_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2000 - 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.
+ */
+
+#pragma once
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int app_key_event(bundle *kb);
+
+#ifdef __cplusplus
+}
+#endif
--- /dev/null
+/*
+ * Copyright (c) 2000 - 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.
+ */
+
+#pragma once
+
+#include <glib.h>
+
+int aul_initialize();
+int aul_is_initialized();
+int aul_app_register_pid(const char *appid, int pid);
+
+int app_send_cmd(int pid, int cmd, bundle *kb);
+int app_send_cmd_for_uid(int pid, uid_t uid, int cmd, bundle *kb);
+int app_send_cmd_with_noreply(int pid, int cmd, bundle *kb);
+int app_send_cmd_to_launchpad(const char *pad_type, uid_t uid, int cmd, bundle *kb);
+int app_request_to_launchpad(int cmd, const char *pkgname, bundle *kb);
+int app_request_to_launchpad_for_uid(int cmd, const char *pkgname, bundle *kb, uid_t uid);
+
+int app_result(int cmd, bundle *kb, int launched_pid);
+int aul_send_result(bundle *kb, int is_cancel);
+int aul_launch_app_with_result(const char *pkgname, bundle *kb,
+ void (*cbfunc) (bundle *, int, void *),
+ void *data);
+int aul_launch_app_with_result_for_uid(const char *pkgname, bundle *kb,
+ void (*cbfunc) (bundle *, int, void *),
+ void *data, uid_t uid);
+int app_subapp_terminate_request(void);
+
+int app_com_recv(bundle *b);
+int aul_launch_app_with_result_async(const char *appid, bundle *b,
+ void (*callback)(bundle *, int, void *), void *data);
+int aul_launch_app_with_result_async_for_uid(const char *appid, bundle *b,
+ void (*callback)(bundle *, int, void *), void *data, uid_t uid);
+int aul_resume_local(void);
+int aul_launch_fini(void);
+int aul_send_launch_request_for_uid(const char *appid, bundle *b, uid_t uid,
+ void (*reply_cb)(bundle *b, int, void *),
+ void (*error_cb)(int, void *), void *user_data);
+int aul_send_launch_request_sync_for_uid(const char *appid, bundle *b,
+ uid_t uid, bundle **res_b);
+int app_request_local(int cmd, bundle *kb);
+int aul_subapp_terminate_request(const char *instance_id, int pid);
+int aul_send_resume_request_for_uid(const char *appid, bundle *b, uid_t uid,
+ void (*error_cb)(int, void *), void *user_data);
--- /dev/null
+/*
+ * Copyright (c) 2000 - 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.
+ */
+
+#pragma once
+
+#include <pkgmgr-info.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "aul_util.h"
+
+#define MAX_PATH_LEN 1024
+
+#define AUL_APP_INFO_FLD_PKG_NAME "package"
+#define AUL_APP_INFO_FLD_APP_PATH "exec"
+#define AUL_APP_INFO_FLD_APP_TYPE "x_slp_packagetype"
+#define AUL_APP_INFO_FLD_WIDTH "x_slp_baselayoutwidth"
+#define AUL_APP_INFO_FLD_HEIGHT "x_slp_baselayoutheight"
+#define AUL_APP_INFO_FLD_VERTICAL "x_slp_ishorizontalscale"
+#define AUL_APP_INFO_FLD_MULTIPLE "x_slp_multiple"
+#define AUL_APP_INFO_FLD_TASK_MANAGE "x_slp_taskmanage"
+#define AUL_APP_INFO_FLD_MIMETYPE "mimetype"
+#define AUL_APP_INFO_FLD_SERVICE "x_slp_service"
+
+#define AUL_RETRIEVE_PKG_NAME "package = '?'"
+#define AUL_RETRIEVE_APP_PATH "exec = '?'"
+#define AUL_RETRIEVE_MIMETYPE "mimetype like '?'"
+#define AUL_RETRIEVE_SERVICE "x_slp_service like '?'"
+
+typedef struct {
+ char *appid; /* appid */
+ char *app_path; /* exec */
+ char *original_app_path; /* exec */
+ char *pkg_type; /* x_slp_packagetype */
+ char *hwacc; /* hwacceleration */
+ char *pkg_id;
+} app_info_from_db;
+
+static inline char *_get_appid(app_info_from_db *menu_info)
+{
+ return menu_info ? menu_info->appid : NULL;
+}
+
+static inline char *_get_pkgid(app_info_from_db *menu_info)
+{
+ return menu_info ? menu_info->pkg_id : NULL;
+}
+
+static inline char *_get_app_path(app_info_from_db *menu_info)
+{
+ int i = 0;
+ int path_len = -1;
+
+ if (!menu_info || menu_info->app_path == NULL)
+ return NULL;
+
+ while (menu_info->app_path[i] != 0) {
+ if (menu_info->app_path[i] == ' '
+ || menu_info->app_path[i] == '\t') {
+ path_len = i;
+ break;
+ }
+ i++;
+ }
+
+ if (path_len == 0) {
+ free(menu_info->app_path);
+ menu_info->app_path = NULL;
+ } else if (path_len > 0) {
+ char *tmp_app_path = malloc(sizeof(char) * (path_len + 1));
+ if (tmp_app_path == NULL)
+ return NULL;
+ snprintf(tmp_app_path, path_len + 1, "%s", menu_info->app_path);
+ free(menu_info->app_path);
+ menu_info->app_path = tmp_app_path;
+ }
+
+ return menu_info->app_path;
+}
+
+static inline char *_get_original_app_path(app_info_from_db *menu_info)
+{
+ return menu_info ? menu_info->original_app_path : NULL;
+}
+
+static inline void _free_app_info_from_db(app_info_from_db *menu_info)
+{
+ if (menu_info != NULL) {
+ if (menu_info->appid != NULL)
+ free(menu_info->appid);
+ if (menu_info->app_path != NULL)
+ free(menu_info->app_path);
+ if (menu_info->original_app_path != NULL)
+ free(menu_info->original_app_path);
+ if (menu_info->pkg_type != NULL)
+ free(menu_info->pkg_type);
+ if (menu_info->hwacc != NULL)
+ free(menu_info->hwacc);
+ if (menu_info->pkg_id != NULL)
+ free(menu_info->pkg_id);
+ free(menu_info);
+ }
+}
+
+static inline app_info_from_db *_get_app_info_from_db_by_pkgname(
+ const char *appid)
+{
+ 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;
+
+ if (appid == NULL) {
+ _free_app_info_from_db(menu_info);
+ return NULL;
+ }
+
+
+ if (getuid() != GLOBAL_USER)
+ ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, getuid(), &handle);
+ else
+ ret = pkgmgrinfo_appinfo_get_appinfo(appid, &handle);
+
+ if (ret != PMINFO_R_OK) {
+ _free_app_info_from_db(menu_info);
+ return NULL;
+ }
+
+ menu_info->appid = 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 = 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 = pkgmgrinfo_appinfo_destroy_appinfo(handle);
+ if (ret != PMINFO_R_OK)
+ _E("pkgmgrinfo_appinfo_destroy_appinfo failed");
+
+ if (!_get_app_path(menu_info)) {
+ _free_app_info_from_db(menu_info);
+ return NULL;
+ }
+
+ return menu_info;
+}
+
+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 *apppath;
+ char *pkgid;
+ int ret = PMINFO_R_OK;
+
+ if (!menu_info)
+ return ret;
+
+ ret = pkgmgrinfo_appinfo_get_exec(appinfo, &apppath);
+ if (ret == PMINFO_R_OK && apppath) {
+ menu_info->app_path = strdup(apppath);
+ if (menu_info->app_path == NULL) {
+ _E("Out of memory");
+ return PMINFO_R_ERROR;
+ }
+ }
+
+ ret = pkgmgrinfo_appinfo_get_pkgid(appinfo, &pkgid);
+ if (ret == PMINFO_R_OK && pkgid) {
+ menu_info->pkg_id = strdup(pkgid);
+ if (menu_info->pkg_id == NULL) {
+ _E("Out of memory");
+ return PMINFO_R_ERROR;
+ }
+ }
+
+ return ret;
+}
+
+static inline app_info_from_db *_get_app_info_from_db_by_appid_user(
+ const char *appid, uid_t uid)
+{
+ app_info_from_db *menu_info;
+ pkgmgrinfo_appinfo_filter_h filter;
+ int ret = PMINFO_R_OK;
+
+ if (uid == 0) {
+ _E("request from root, treat as global user");
+ uid = GLOBAL_USER;
+ }
+
+ if (appid == NULL)
+ return NULL;
+
+ menu_info = calloc(1, sizeof(app_info_from_db));
+ if (menu_info == NULL)
+ return NULL;
+
+ ret = pkgmgrinfo_appinfo_filter_create(&filter);
+ if (ret != PMINFO_R_OK) {
+ _free_app_info_from_db(menu_info);
+ return NULL;
+ }
+
+ ret = pkgmgrinfo_appinfo_filter_add_string(filter,
+ PMINFO_APPINFO_PROP_APP_ID, appid);
+ if (ret != PMINFO_R_OK) {
+ pkgmgrinfo_appinfo_filter_destroy(filter);
+ _free_app_info_from_db(menu_info);
+ return NULL;
+ }
+
+ if (uid != GLOBAL_USER)
+ ret = pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(filter,
+ __appinfo_func, (void *)menu_info, uid);
+ else
+ ret = pkgmgrinfo_appinfo_filter_foreach_appinfo(filter,
+ __appinfo_func, (void *)menu_info);
+
+ if ((ret != PMINFO_R_OK) || (menu_info->app_path == NULL)) {
+ pkgmgrinfo_appinfo_filter_destroy(filter);
+ _free_app_info_from_db(menu_info);
+ return NULL;
+ }
+
+ pkgmgrinfo_appinfo_filter_destroy(filter);
+
+ menu_info->appid = strdup(appid);
+ menu_info->original_app_path = strdup(menu_info->app_path);
+
+ return menu_info;
+
+}
+
+static inline app_info_from_db *_get_app_info_from_db_by_appid(
+ const char *appid)
+{
+ return _get_app_info_from_db_by_appid_user(appid, GLOBAL_USER);
+}
+
+
--- /dev/null
+/*
+ * Copyright (c) 2000 - 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.
+ */
+
+#pragma once
+
+#include <regex.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct _regex_tbl {
+ char *mimetype;
+ char *regex;
+ char *desc;
+ regex_t regex_preg;
+ struct _regex_tbl *next;
+} regex_tbl;
+
+regex_tbl *miregex_get_regex_table();
+
+#ifdef __cplusplus
+}
+#endif
--- /dev/null
+ADD_SUBDIRECTORY(unit_tests)
--- /dev/null
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/ UNIT_TESTS_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/mock/ UNIT_TESTS_SRCS)
+ADD_EXECUTABLE(${TARGET_AUL_UNIT_TEST} ${UNIT_TESTS_SRCS})
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_AUL_UNIT_TEST} PUBLIC
+ "${CMAKE_CURRENT_SOURCE_DIR}/../"
+ "${CMAKE_CURRENT_SOURCE_DIR}/../../include"
+ "${CMAKE_CURRENT_SOURCE_DIR}/../../src"
+)
+
+APPLY_PKG_CONFIG(${TARGET_AUL_UNIT_TEST} PUBLIC
+ GLIB_DEPS
+ GMOCK_DEPS
+ BUNDLE_DEPS
+)
+
+TARGET_LINK_LIBRARIES(${TARGET_AUL_UNIT_TEST} PUBLIC ${TARGET_AUL})
+SET_TARGET_PROPERTIES(${TARGET_AUL_UNIT_TEST} PROPERTIES COMPILE_FLAGS "-fPIE")
+SET_TARGET_PROPERTIES(${TARGET_AUL_UNIT_TEST} PROPERTIES LINK_FLAGS "-pie")
+
+ADD_TEST(
+ NAME ${TARGET_AUL_UNIT_TEST}
+ COMMAND ${TARGET_AUL_UNIT_TEST}
+)
--- /dev/null
+// Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
+
+int main(int argc, char** argv) {
+ try {
+ testing::InitGoogleTest(&argc, argv);
+ } catch(...) {
+ std::cout << "Exception occurred" << std::endl;
+ }
+
+ int ret;
+ try {
+ ret = RUN_ALL_TESTS();
+ } catch (const ::testing::internal::GoogleTestFailureException& e) {
+ ret = -1;
+ std::cout << "GoogleTestFailureException was thrown:" << e.what()
+ << std::endl;
+ }
+
+ return ret;
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef UNIT_TESTS_MOCK_MOCK_HOOK_H_
+#define UNIT_TESTS_MOCK_MOCK_HOOK_H_
+
+#define MOCK_HOOK_P0(MOCK_CLASS, f) \
+ TestFixture::GetMock<MOCK_CLASS>().f()
+#define MOCK_HOOK_P1(MOCK_CLASS, f, p1) \
+ TestFixture::GetMock<MOCK_CLASS>().f(p1)
+#define MOCK_HOOK_P2(MOCK_CLASS, f, p1, p2) \
+ TestFixture::GetMock<MOCK_CLASS>().f(p1, p2)
+#define MOCK_HOOK_P3(MOCK_CLASS, f, p1, p2, p3) \
+ TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3)
+#define MOCK_HOOK_P4(MOCK_CLASS, f, p1, p2, p3, p4) \
+ TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3, p4)
+#define MOCK_HOOK_P5(MOCK_CLASS, f, p1, p2, p3, p4, p5) \
+ TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3, p4, p5)
+#define MOCK_HOOK_P6(MOCK_CLASS, f, p1, p2, p3, p4, p5, p6) \
+ TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3, p4, p5, p6)
+#define MOCK_HOOK_P7(MOCK_CLASS, f, p1, p2, p3, p4, p5, p6, p7) \
+ TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3, p4, p5, p6, p7)
+#define MOCK_HOOK_P8(MOCK_CLASS, f, p1, p2, p3, p4, p5, p6, p7, p8) \
+ TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3, p4, p5, p6, p7, p8)
+#define MOCK_HOOK_P10(MOCK_CLASS, f, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10) \
+ TestFixture::GetMock<MOCK_CLASS>().f( \
+ p1, p2, p3, p4, p5, p6, p7, p8, p9, p10)
+
+#endif // UNIT_TESTS_MOCK_MOCK_HOOK_H_
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef UNIT_TESTS_MOCK_MODULE_MOCK_H_
+#define UNIT_TESTS_MOCK_MODULE_MOCK_H_
+
+class ModuleMock {
+ public:
+ virtual ~ModuleMock() {}
+};
+
+#endif // UNIT_TESTS_MOCK_MODULE_MOCK_H_
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "unit_tests/mock/test_fixture.h"
+
+#include <memory>
+
+std::unique_ptr<ModuleMock> TestFixture::mock_;
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef UNIT_TESTS_MOCK_TEST_FIXTURE_H_
+#define UNIT_TESTS_MOCK_TEST_FIXTURE_H_
+
+#include <gtest/gtest.h>
+
+#include <memory>
+#include <stdexcept>
+#include <string>
+#include <utility>
+
+#include "unit_tests/mock/module_mock.h"
+
+class TestFixture : public ::testing::Test {
+ public:
+ explicit TestFixture(std::unique_ptr<ModuleMock>&& mock) {
+ mock_ = std::move(mock);
+ }
+ virtual ~TestFixture() {
+ mock_.reset();
+ }
+
+ virtual void SetUp() {}
+ virtual void TearDown() {}
+
+ template <typename T>
+ static T& GetMock() {
+ auto ptr = dynamic_cast<T*>(mock_.get());
+ if (!ptr)
+ throw std::invalid_argument("The test does not provide mock of \"" +
+ std::string(typeid(T).name()) + "\"");
+ return *ptr;
+ }
+
+ static std::unique_ptr<ModuleMock> mock_;
+};
+
+#endif // UNIT_TESTS_MOCK_TEST_FIXTURE_H_
-IF(_TIZEN_FEATURE_PRELINK)
-SET(CMAKE_C_FLAGS_app_launcher "${CMAKE_C_FLAGS}")
-ELSE(_TIZEN_FEATURE_PRELINK)
-SET(CMAKE_C_FLAGS_app_launcher "${CMAKE_C_FLAGS} -fPIE")
-ENDIF(_TIZEN_FEATURE_PRELINK)
-
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE")
-
-add_executable(aul_test
- aul_test.c)
-target_link_libraries(aul_test aul ${pkgs_LDFLAGS} "-pie")
-INSTALL(TARGETS aul_test DESTINATION bin)
-
-add_executable(launch_app
- launch_app.c)
-target_link_libraries(launch_app aul ${pkgs_LDFLAGS} "-pie")
-INSTALL(TARGETS launch_app DESTINATION bin)
-
-# test
-add_executable(open_app
- open_app.c)
-target_link_libraries(open_app aul ${pkgs_LDFLAGS} "-pie")
-INSTALL(TARGETS open_app DESTINATION bin)
-
-add_executable(appid2pid
- appid2pid.c)
-target_link_libraries(appid2pid aul ${pkgs_LDFLAGS} "-pie")
-INSTALL(TARGETS appid2pid DESTINATION bin)
-
-add_executable(launch_debug
- launch_debug.c)
-target_link_libraries(launch_debug aul ${pkgs_LDFLAGS} "-pie")
-INSTALL(TARGETS launch_debug DESTINATION bin)
-
-add_executable(app_launcher
- app_launcher.c)
-
-IF(_TIZEN_FEATURE_PRELINK)
-message(STATUS "[__PRELINK__] Enable")
-target_link_libraries(app_launcher aul ${pkgs_LDFLAGS})
-ELSE(_TIZEN_FEATURE_PRELINK)
-message(STATUS "[__PRELINK__] Disable")
-target_link_libraries(app_launcher aul ${pkgs_LDFLAGS} "-pie")
-ENDIF(_TIZEN_FEATURE_PRELINK)
-SET_TARGET_PROPERTIES(app_launcher PROPERTIES COMPILE_FLAGS ${CMAKE_C_FLAGS_app_launcher})
-
-INSTALL(TARGETS app_launcher DESTINATION bin)
-
-add_executable(appgroup_info
- app_group_info.c)
-target_link_libraries(appgroup_info aul ${pkgs_LDFLAGS} "-pie")
-INSTALL(TARGETS appgroup_info DESTINATION bin)
-
-add_executable(app_com_tool
- app_com_tool.c)
-target_link_libraries(app_com_tool aul ${pkgs_LDFLAGS} "-pie")
-INSTALL(TARGETS app_com_tool DESTINATION bin)
-
-add_executable(compmgr_tool
- compmgr_tool.c)
-target_link_libraries(compmgr_tool aul ${pkgs_LDFLAGS} "-pie")
-INSTALL(TARGETS compmgr_tool DESTINATION bin)
-
+ADD_SUBDIRECTORY(app_com_tool)
+ADD_SUBDIRECTORY(app_launcher)
+ADD_SUBDIRECTORY(appgroup_info)
+ADD_SUBDIRECTORY(appid2pid)
+ADD_SUBDIRECTORY(aul_test)
+ADD_SUBDIRECTORY(compmgr_tool)
+ADD_SUBDIRECTORY(launch_app)
+ADD_SUBDIRECTORY(launch_debug)
+ADD_SUBDIRECTORY(open_app)
ADD_SUBDIRECTORY(recovery)
+++ /dev/null
-#include <glib.h>
-#include <stdio.h>
-#include <aul.h>
-#include <aul_app_com.h>
-
-static GMainLoop *mainloop = NULL;
-static int gargc;
-static char **gargv;
-static aul_app_com_connection_h conn = NULL;
-
-static void __bundle_itr(const char *key, const int type, const bundle_keyval_t *kv, void *data)
-{
- printf("key: %s ", key);
- printf("type: %d", type);
- printf("\n");
-}
-
-static int __handler(const char *endpoint, aul_app_com_result_e result, bundle *envelope, void *user_data)
-{
- printf("endpoint: %s (%d) received\n", endpoint, result);
- printf("---begin---\n");
- bundle_foreach(envelope, __bundle_itr, NULL);
- printf("---end---\n\n");
-
- return 0;
-}
-
-static void __create(const char *endpoint, const char *privilege)
-{
- aul_app_com_permission_h permission = NULL;
- int ret;
-
- if (privilege) {
- permission = aul_app_com_permission_create();
- aul_app_com_permission_set_privilege(permission, privilege);
- aul_app_com_permission_set_propagation(permission, AUL_APP_COM_PRIVILEGED);
- }
-
- ret = aul_app_com_create(endpoint, permission, __handler, NULL, &conn);
- printf("app_com_create ret: %d\n", ret);
-
- if (permission)
- aul_app_com_permission_destroy(permission);
-}
-
-static void __join(const char *endpoint, const char *filter)
-{
- int ret = aul_app_com_join(endpoint, filter, __handler, NULL, &conn);
- printf("ret: %d\n", ret);
-}
-
-static void __send(const char *endpoint)
-{
- int idx = 2;
- int ret;
-
- bundle *b = bundle_create();
- for (idx = 2; idx < gargc; idx += 2)
- bundle_add_str(b, gargv[idx], gargv[idx + 1]);
-
- ret = aul_app_com_send(endpoint, b);
- bundle_free(b);
- printf("ret: %d\n", ret);
-
- g_main_loop_quit(mainloop);
-}
-
-static gboolean run_func(void *data)
-{
- if (gargc < 2 || (gargc > 1 && gargv[1] && (g_strcmp0(gargv[1], "help") == 0 && gargc == 2))) {
- printf("%s help create|join|send", gargv[0]);
- g_main_loop_quit(mainloop);
- return FALSE;
- }
-
- if (g_strcmp0(gargv[1], "create") == 0) {
- if (gargc == 3)
- __create(gargv[2], NULL);
- else if (gargc == 4)
- __create(gargv[2], gargv[3]);
- }
-
- if (g_strcmp0(gargv[1], "join") == 0) {
- if (gargc == 3)
- __join(gargv[2], NULL);
- else if (gargc == 4)
- __join(gargv[2], gargv[3]);
- }
-
- if (g_strcmp0(gargv[1], "send") == 0) {
- if (gargc > 4)
- __send(gargv[2]);
- }
-
- return FALSE;
-}
-
-int main(int argc, char **argv)
-{
- aul_launch_init(NULL, NULL);
-
- gargc = argc;
- gargv = argv;
-
- g_idle_add(run_func, NULL);
-
- mainloop = g_main_loop_new(NULL, FALSE);
- g_main_loop_run(mainloop);
- g_main_loop_unref(mainloop);
-
- if (conn)
- aul_app_com_leave(conn);
-
- return 0;
-}
--- /dev/null
+SET(TARGET_APP_COM_TOOL "app_com_tool")
+
+ADD_EXECUTABLE(${TARGET_APP_COM_TOOL} ${CMAKE_CURRENT_SOURCE_DIR}/app_com_tool.c)
+SET_TARGET_PROPERTIES(${TARGET_APP_COM_TOOL} PROPERTIES COMPILE_FLAGS ${CFLAGS} "-fPIE")
+SET_TARGET_PROPERTIES(${TARGET_APP_COM_TOOL} PROPERTIES LINK_FLAGS "-pie")
+TARGET_LINK_LIBRARIES(${TARGET_APP_COM_TOOL} PRIVATE ${TARGET_AUL})
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_APP_COM_TOOL} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../src)
+TARGET_INCLUDE_DIRECTORIES(${TARGET_APP_COM_TOOL} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../include)
+
+INSTALL(TARGETS ${TARGET_APP_COM_TOOL} DESTINATION bin)
--- /dev/null
+#include <glib.h>
+#include <stdio.h>
+#include <aul.h>
+#include <aul_app_com.h>
+
+static GMainLoop *mainloop = NULL;
+static int gargc;
+static char **gargv;
+static aul_app_com_connection_h conn = NULL;
+
+static void __bundle_itr(const char *key, const int type, const bundle_keyval_t *kv, void *data)
+{
+ printf("key: %s ", key);
+ printf("type: %d", type);
+ printf("\n");
+}
+
+static int __handler(const char *endpoint, aul_app_com_result_e result, bundle *envelope, void *user_data)
+{
+ printf("endpoint: %s (%d) received\n", endpoint, result);
+ printf("---begin---\n");
+ bundle_foreach(envelope, __bundle_itr, NULL);
+ printf("---end---\n\n");
+
+ return 0;
+}
+
+static void __create(const char *endpoint, const char *privilege)
+{
+ aul_app_com_permission_h permission = NULL;
+ int ret;
+
+ if (privilege) {
+ permission = aul_app_com_permission_create();
+ aul_app_com_permission_set_privilege(permission, privilege);
+ aul_app_com_permission_set_propagation(permission, AUL_APP_COM_PRIVILEGED);
+ }
+
+ ret = aul_app_com_create(endpoint, permission, __handler, NULL, &conn);
+ printf("app_com_create ret: %d\n", ret);
+
+ if (permission)
+ aul_app_com_permission_destroy(permission);
+}
+
+static void __join(const char *endpoint, const char *filter)
+{
+ int ret = aul_app_com_join(endpoint, filter, __handler, NULL, &conn);
+ printf("ret: %d\n", ret);
+}
+
+static void __send(const char *endpoint)
+{
+ int idx = 2;
+ int ret;
+
+ bundle *b = bundle_create();
+ for (idx = 2; idx < gargc; idx += 2)
+ bundle_add_str(b, gargv[idx], gargv[idx + 1]);
+
+ ret = aul_app_com_send(endpoint, b);
+ bundle_free(b);
+ printf("ret: %d\n", ret);
+
+ g_main_loop_quit(mainloop);
+}
+
+static gboolean run_func(void *data)
+{
+ if (gargc < 2 || (gargc > 1 && gargv[1] && (g_strcmp0(gargv[1], "help") == 0 && gargc == 2))) {
+ printf("%s help create|join|send", gargv[0]);
+ g_main_loop_quit(mainloop);
+ return FALSE;
+ }
+
+ if (g_strcmp0(gargv[1], "create") == 0) {
+ if (gargc == 3)
+ __create(gargv[2], NULL);
+ else if (gargc == 4)
+ __create(gargv[2], gargv[3]);
+ }
+
+ if (g_strcmp0(gargv[1], "join") == 0) {
+ if (gargc == 3)
+ __join(gargv[2], NULL);
+ else if (gargc == 4)
+ __join(gargv[2], gargv[3]);
+ }
+
+ if (g_strcmp0(gargv[1], "send") == 0) {
+ if (gargc > 4)
+ __send(gargv[2]);
+ }
+
+ return FALSE;
+}
+
+int main(int argc, char **argv)
+{
+ aul_launch_init(NULL, NULL);
+
+ gargc = argc;
+ gargv = argv;
+
+ g_idle_add(run_func, NULL);
+
+ mainloop = g_main_loop_new(NULL, FALSE);
+ g_main_loop_run(mainloop);
+ g_main_loop_unref(mainloop);
+
+ if (conn)
+ aul_app_com_leave(conn);
+
+ return 0;
+}
+++ /dev/null
-/*
- * Copyright (c) 2015 - 2019 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 <stdlib.h>
-
-#include "aul.h"
-#include "aul_app_group.h"
-
-static void __foreach_idle_group_info(aul_app_group_info_h info,
- void *user_data)
-{
- int *idle_count = (int *)user_data;
- const char *id = NULL;
- pid_t pid = -1;
- const char *appid = NULL;
-
- (*idle_count)++;
- aul_app_group_info_get_id(info, &id);
- aul_app_group_info_get_pid(info, &pid);
- aul_app_group_info_get_appid(info, &appid);
-
- printf("---------------------------\n");
- printf(" - id : %s\n", id);
- printf(" - pid : %d\n", pid);
- printf(" - appid : %s\n", appid);
- printf("\n");
-}
-
-static void __print_idle_info(void)
-{
- int idle_count = 0;
-
- aul_app_group_foreach_idle_info(__foreach_idle_group_info,
- (void *)&idle_count);
- printf("< Idle count : %d >\n", idle_count);
-}
-
-static void __print_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;
- };
-}
-
-static void __foreach_group_info(aul_app_group_info_h info, void *user_data)
-{
- int *member_count = (int *)user_data;
- const char *id = NULL;
- pid_t pid = -1;
- const char *appid = NULL;
- const char *pkgid = NULL;
- int wid = 0;
- bool fg = false;
- int status = -1;
-
- (*member_count)++;
- aul_app_group_info_get_id(info, &id);
- aul_app_group_info_get_pid(info, &pid);
- aul_app_group_info_get_appid(info, &appid);
- aul_app_group_info_get_pkgid(info, &pkgid);
- aul_app_group_info_get_window(info, &wid);
- aul_app_group_info_get_fg_flag(info, &fg);
- aul_app_group_info_get_status(info, &status);
-
- printf("--- member : %d\n", *member_count);
- printf(" - id : %s\n", id);
- printf(" - pid : %d\n", pid);
- printf(" - app id : %s\n", appid);
- printf(" - pkg id : %s\n", pkgid);
- printf(" - win id : %d\n", wid);
- printf(" - fg group : %s\n", fg ? "true" : "false");
- __print_status(status);
- printf("\n");
-}
-
-static void __foreach_leader_ids(const char *leader_id, void *user_data)
-{
- int *group_count = (int *)user_data;
- int member_count = 0;
-
- (*group_count)++;
- printf("----------------------------------\n");
- printf("< Group : %d >\n", *group_count);
-
- aul_app_group_foreach_group_info(leader_id, __foreach_group_info,
- (void *)&member_count);
- printf("Member count: %d\n", member_count);
- printf("\n");
-}
-
-static void __print_info(void)
-{
- int group_count = 0;
- int ret;
-
- ret = aul_app_group_foreach_leader_ids(__foreach_leader_ids,
- (void *)&group_count);
- if (ret < 0) {
- printf("No app group\n");
- return;
- }
-
- printf("==================================\n");
- printf("\n");
- printf("App Group count: %d\n", group_count);
-}
-
-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;
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 - 2017 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 <stdlib.h>
-#include <string.h>
-#include <stdbool.h>
-#include <sys/types.h>
-#include <sys/inotify.h>
-#include <linux/limits.h>
-#include <glib.h>
-#include <gio/gio.h>
-#include <pkgmgr-info.h>
-#include <bundle_internal.h>
-#include <sys/prctl.h>
-
-#include "aul.h"
-#include "aul_svc.h"
-#include "launch.h"
-
-#define LAUNCHPAD_PROCESS_POOL_SOCK ".launchpad-process-pool-sock"
-#define AMD_SOCK ".amd-sock"
-#define PATH_AUL_DAEMONS "/run/aul/daemons"
-#define PATH_AMD_SOCK PATH_AUL_DAEMONS "/" AMD_SOCK
-#define APP_TYPE_UI "uiapp"
-#define APP_TYPE_SERVICE "svcapp"
-#define INOTIFY_BUF (1024 * ((sizeof(struct inotify_event)) + 16))
-
-#ifndef PR_TASK_PERF_USER_TRACE
-#define PR_TASK_PERF_USER_TRACE 666
-#endif
-
-struct launch_arg {
- char *appid;
- bundle *b;
- pid_t pid;
- uid_t uid;
- bool debug;
- bool web_debug;
- bool sync;
-};
-
-enum command_e {
- CMD_LIST,
- CMD_STATUS,
- CMD_START,
- CMD_KILL,
- CMD_TERMINATE,
- CMD_IS_RUNNING,
- CMD_FAST_START,
- CMD_DIRECT_START,
- CMD_MAX,
-};
-
-enum option_e {
- OPT_DEBUG,
- OPT_WEB_DEBUG,
- OPT_USER,
- OPT_MAX,
-};
-
-struct command {
- const char *name;
- int (*init)(struct launch_arg *arg);
- int (*run)(struct launch_arg *arg);
- void (*finish)(struct launch_arg *arg);
-};
-
-static int result;
-static GMainLoop *loop;
-static gchar *help;
-static gpointer cmd_opt[CMD_MAX];
-static GOptionEntry cmd_entries[] = {
- {
- .long_name = "list",
- .short_name = 'l',
- .flags = 0,
- .arg = G_OPTION_ARG_NONE,
- .arg_data = &cmd_opt[CMD_LIST],
- .description = "Show installed application list",
- .arg_description = NULL
- },
- {
- .long_name = "status",
- .short_name = 'S',
- .flags = 0,
- .arg = G_OPTION_ARG_NONE,
- .arg_data = &cmd_opt[CMD_STATUS],
- .description = "Show the running application information",
- .arg_description = NULL
- },
- {
- .long_name = "start",
- .short_name = 's',
- .flags = 0,
- .arg = G_OPTION_ARG_STRING,
- .arg_data = &cmd_opt[CMD_START],
- .description = "Execute the application",
- .arg_description = "APPLICATION ID"
- },
- {
- .long_name = "kill",
- .short_name = 'k',
- .flags = 0,
- .arg = G_OPTION_ARG_STRING,
- .arg_data = &cmd_opt[CMD_KILL],
- .description = "Kill the running application",
- .arg_description = "APPLICATION ID"
- },
- {
- .long_name = "terminate",
- .short_name = 't',
- .flags = 0,
- .arg = G_OPTION_ARG_STRING,
- .arg_data = &cmd_opt[CMD_TERMINATE],
- .description = "Terminte the running application",
- .arg_description = "APPLICATION ID"
- },
- {
- .long_name = "is-running",
- .short_name = 'r',
- .flags = 0,
- .arg = G_OPTION_ARG_STRING,
- .arg_data = &cmd_opt[CMD_IS_RUNNING],
- .description = "Check whether the application is running or Not",
- .arg_description = "APPLICATION ID"
- },
- {
- .long_name = "fast-start",
- .short_name = 'f',
- .flags = 0,
- .arg = G_OPTION_ARG_STRING,
- .arg_data = &cmd_opt[CMD_FAST_START],
- .description = "[Deprecated] Execute the application quickly",
- .arg_description = "APPLICATION ID"
- },
- {
- .long_name = "direct-start",
- .short_name = 'e',
- .flags = 0,
- .arg = G_OPTION_ARG_STRING,
- .arg_data = &cmd_opt[CMD_DIRECT_START],
- .description = "Execute the application without the loader",
- .arg_description = "APPLICATION ID"
- },
- {
- NULL
- }
-};
-static gpointer opt[OPT_MAX];
-static GOptionEntry opt_entries[] = {
- {
- .long_name = "debug",
- .short_name = 'd',
- .flags = 0,
- .arg = G_OPTION_ARG_NONE,
- .arg_data = &opt[OPT_DEBUG],
- .description = "Activate debug mode",
- .arg_description = NULL
- },
- {
- .long_name = "web-debug",
- .short_name = 'w',
- .flags = 0,
- .arg = G_OPTION_ARG_NONE,
- .arg_data = &opt[OPT_WEB_DEBUG],
- .description = "Activate web debug mode, Use only for webapps",
- .arg_description = NULL
- },
- {
- .long_name = "user",
- .short_name = 'u',
- .flags = 0,
- .arg = G_OPTION_ARG_INT,
- .arg_data = &opt[OPT_USER],
- .description = "Specify the user ID",
- .arg_description = "USER ID"
- },
- {
- NULL
- }
-};
-
-static void __print_hwc_messages(const char *format, ...)
-{
- char buf[1024];
- va_list ap;
-
- va_start(ap, format);
- vsnprintf(buf, sizeof(buf), format, ap);
- va_end(ap);
-
- prctl(PR_TASK_PERF_USER_TRACE, buf, strlen(buf));
-}
-
-static GOptionGroup *__get_opt_group(void)
-{
- GOptionGroup *group;
-
- group = g_option_group_new("option", "Additional Options:",
- "Additional options", NULL, NULL);
- if (!group)
- return NULL;
-
- g_option_group_add_entries(group, opt_entries);
-
- return group;
-}
-
-static int __is_app_installed(const char *appid, uid_t uid)
-{
- pkgmgrinfo_appinfo_filter_h filter;
- int is_installed = 0;
- int ret;
-
- ret = pkgmgrinfo_appinfo_filter_create(&filter);
- if (ret != PMINFO_R_OK) {
- printf("Failed to create filter\n");
- return -1;
- }
-
- ret = pkgmgrinfo_appinfo_filter_add_string(filter,
- PMINFO_APPINFO_PROP_APP_ID, appid);
- if (ret != PMINFO_R_OK) {
- printf("Failed to add filter string\n");
- pkgmgrinfo_appinfo_filter_destroy(filter);
- return -1;
- }
-
- ret = pkgmgrinfo_appinfo_usr_filter_count(filter,
- &is_installed, uid);
- if (ret != PMINFO_R_OK) {
- printf("Failed to get filter count\n");
- pkgmgrinfo_appinfo_filter_destroy(filter);
- return -1;
- }
-
- pkgmgrinfo_appinfo_filter_destroy(filter);
-
- return is_installed;
-}
-
-static int __cmd_common_init(struct launch_arg *arg)
-{
- if (!__is_app_installed(arg->appid, arg->uid)) {
- printf("The app with ID: %s is not available for the user %d\n",
- arg->appid, arg->uid);
- return -1;
- }
-
- return 0;
-}
-
-static void __cmd_common_finish(struct launch_arg *arg)
-{
- g_main_loop_quit(loop);
-}
-
-static int __installed_list_cb(const pkgmgrinfo_appinfo_h handle, void *data)
-{
- char *label;
- char *appid;
-
- if (pkgmgrinfo_appinfo_get_label(handle, &label))
- label = "";
-
- if (pkgmgrinfo_appinfo_get_appid(handle, &appid)) {
- printf("Failed to get appid\n");
- return -1;
- }
-
- printf("\t'%s'\t '%s'\n", label, appid);
-
- return 0;
-}
-
-static int __cmd_list_run(struct launch_arg *arg)
-{
- int ret;
-
- printf("\tApplication List for user %u\n", arg->uid);
- printf("\tUser's Application \n");
- printf("\t Name \t AppID \n");
- printf("\t=================================================\n");
-
- ret = pkgmgrinfo_appinfo_get_usr_installed_list(__installed_list_cb,
- arg->uid, NULL);
-
- printf("\t=================================================\n");
-
- return ret;
-}
-
-static int __running_app_info_cb(const aul_app_info *info, void *data)
-{
- printf("\t %s (%d)\n", info->appid, info->pid);
- return 0;
-}
-
-static int __cmd_status_run(struct launch_arg *arg)
-{
- int ret;
-
- printf("\t appId (PID)\n");
- ret = aul_app_get_running_app_info_for_uid(__running_app_info_cb,
- NULL, arg->uid);
- if (ret < 0) {
- printf("Failed to show the list of running applications\n");
- return -1;
- }
-
- return 0;
-}
-
-static int __app_dead_signal_cb(int pid, void *data)
-{
- struct launch_arg *arg = (struct launch_arg *)data;
-
- if (arg->pid == pid)
- g_main_loop_quit(loop);
-
- return 0;
-}
-
-static void __reply_cb(bundle *b, int request_code,
- aul_svc_result_val result, void *data)
-{
- const char *port;
- const char *pid;
-
- port = bundle_get_val(b, "port");
- pid = bundle_get_val(b, AUL_K_CALLEE_PID);
- if (port && pid) {
- printf("... successfully launched pid = %s with debug 1 port: %s\n",
- pid, port);
- } else {
- printf("... launch failed\n");
- }
-
- g_main_loop_quit(loop);
-}
-
-static int __cmd_start_run(struct launch_arg *arg)
-{
- if (arg->web_debug) {
- aul_svc_set_operation(arg->b, AUL_SVC_OPERATION_DEFAULT);
- aul_svc_set_appid(arg->b, arg->appid);
- arg->pid = aul_svc_run_service_for_uid(arg->b, 0, __reply_cb,
- NULL, arg->uid);
- } else {
- arg->pid = aul_launch_app_for_uid(arg->appid, arg->b, arg->uid);
- if (arg->pid > 0) {
- printf("... successfully launched pid = %d with debug %d\n",
- arg->pid, arg->debug);
- }
- }
-
- if (arg->pid <= 0) {
- if (arg->pid == AUL_R_ENOAPP) {
- printf("The app with ID: %s is not available for the user %d\n",
- arg->appid, arg->uid);
- } else {
- printf("... launch failed\n");
- }
- return -1;
- }
-
- return 0;
-}
-
-static gboolean __retry_handler(gpointer data)
-{
- struct launch_arg *arg = (struct launch_arg *)data;
- int r;
-
- r = aul_app_get_status_bypid_for_uid(arg->pid, arg->uid);
- if (r == -1 || r == STATUS_DYING) {
- g_main_loop_quit(loop);
- return G_SOURCE_REMOVE;
- } else if (r < 0) {
- return G_SOURCE_CONTINUE;
- }
-
- r = aul_listen_app_dead_signal(__app_dead_signal_cb, arg);
- if (r < 0)
- return G_SOURCE_CONTINUE;
-
- return G_SOURCE_REMOVE;
-}
-
-static void __cmd_start_finish(struct launch_arg *arg)
-{
- int r;
-
- if (arg->pid > 0 && arg->sync) {
- r = aul_listen_app_dead_signal(__app_dead_signal_cb, arg);
- if (r < 0)
- g_timeout_add(500, __retry_handler, arg);
-
- return;
- }
-
- if (arg->pid > 0 && arg->web_debug)
- return;
-
- g_main_loop_quit(loop);
-}
-
-static int __kill_running_app_cb(const aul_app_info *info, void *data)
-{
- if (!strcmp(info->appid, data)) {
- aul_kill_pid(info->pid);
- printf("\t Kill appId: %s (%d)\n", info->appid, info->pid);
- }
-
- return 0;
-}
-
-static int __cmd_kill_run(struct launch_arg *arg)
-{
- int ret;
-
- if (!aul_app_is_running_for_uid(arg->appid, arg->uid)) {
- printf("result: App isn't running\n");
- return 1;
- }
-
- ret = aul_app_get_running_app_info_for_uid(__kill_running_app_cb,
- arg->appid, arg->uid);
- if (ret < 0)
- return -1;
-
- return 0;
-}
-
-static int __terminate_running_app_cb(const aul_app_info *info, void *data)
-{
- if (!strcmp(info->appid, data)) {
- aul_terminate_pid(info->pid);
- printf("\t Terminate appId: %s (%d)\n", info->appid, info->pid);
- }
-
- return 0;
-}
-
-static int __cmd_terminate_run(struct launch_arg *arg)
-{
- int ret;
-
- if (!aul_app_is_running_for_uid(arg->appid, arg->uid)) {
- printf("result: App isn't running\n");
- return 1;
- }
-
- ret = aul_app_get_running_app_info_for_uid(__terminate_running_app_cb,
- arg->appid, arg->uid);
- if (ret < 0)
- return -1;
-
- return 0;
-}
-
-static int __cmd_is_running_run(struct launch_arg *arg)
-{
- if (!aul_app_is_running_for_uid(arg->appid, arg->uid)) {
- printf("result: not running\n");
- return 1;
- }
-
- printf("result: running\n");
-
- return 0;
-}
-
-static int __get_gles(void)
-{
- FILE *fp;
- char buf[LINE_MAX];
- char *tmp;
- int gles = 1;
-
- fp = fopen("/proc/cmdline", "r");
- if (fp == NULL)
- return gles;
-
- if (fgets(buf, sizeof(buf), fp) != NULL) {
- tmp = strstr(buf, "gles");
- if (tmp != NULL)
- sscanf(tmp, "gles=%d", &gles);
- }
-
- fclose(fp);
-
- return gles;
-}
-
-static int __set_appinfo_for_launchpad(bundle *kb, const char *appid, uid_t uid)
-{
- pkgmgrinfo_appinfo_h handle;
- int ret;
- char *pkgid = NULL;
- char *exec = NULL;
- char *apptype = NULL;
- char *pkgtype = NULL;
- char *component_type = NULL;
- char *root_path = NULL;
- char *api_version = NULL;
- pkgmgrinfo_app_hwacceleration hwacc = PMINFO_HWACCELERATION_OFF;
- const char *hwacc_str = "NOT_USE";
- bool process_pool = false;
-
- if (kb == NULL)
- return -1;
-
- ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, uid, &handle);
- if (ret != PMINFO_R_OK)
- return -1;
-
- ret = pkgmgrinfo_appinfo_get_exec(handle, &exec);
- if (ret != PMINFO_R_OK)
- goto end;
-
- ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
- if (ret != PMINFO_R_OK)
- goto end;
-
- ret = pkgmgrinfo_appinfo_get_apptype(handle, &apptype);
- if (ret != PMINFO_R_OK)
- goto end;
-
- ret = pkgmgrinfo_appinfo_get_pkgtype(handle, &pkgtype);
- if (ret != PMINFO_R_OK)
- goto end;
-
- ret = pkgmgrinfo_appinfo_get_component_type(handle, &component_type);
- if (ret != PMINFO_R_OK)
- goto end;
-
- if (!component_type || (strcmp(component_type, APP_TYPE_SERVICE) != 0 &&
- strcmp(component_type, APP_TYPE_UI) != 0)) {
- ret = -1;
- goto end;
- }
-
- ret = pkgmgrinfo_appinfo_get_hwacceleration(handle, &hwacc);
- if (ret != PMINFO_R_OK)
- goto end;
-
- ret = pkgmgrinfo_appinfo_is_process_pool(handle, &process_pool);
- if (ret != PMINFO_R_OK)
- goto end;
-
- if (__get_gles() && hwacc == PMINFO_HWACCELERATION_ON)
- hwacc_str = "USE";
- else if (hwacc == PMINFO_HWACCELERATION_OFF)
- hwacc_str = "NOT_USE";
- else
- hwacc_str = "SYS";
-
- ret = pkgmgrinfo_appinfo_get_root_path(handle, &root_path);
- if (ret != PMINFO_R_OK)
- goto end;
-
- ret = pkgmgrinfo_appinfo_get_api_version(handle, &api_version);
- if (ret != PMINFO_R_OK)
- goto end;
-
- bundle_add(kb, AUL_K_APPID, appid);
- bundle_add(kb, AUL_K_HWACC, hwacc_str);
- bundle_add(kb, AUL_K_EXEC, exec);
- bundle_add(kb, AUL_K_APP_TYPE, apptype);
- bundle_add(kb, AUL_K_PKGID, pkgid);
- bundle_add(kb, AUL_K_INTERNAL_POOL, process_pool ? "true" : "false");
- bundle_add(kb, AUL_K_COMP_TYPE, component_type);
- bundle_add(kb, AUL_K_PACKAGETYPE, pkgtype);
- bundle_add(kb, AUL_K_ROOT_PATH, root_path);
- bundle_add(kb, AUL_K_API_VERSION, api_version);
- bundle_add(kb, AUL_K_FAST_LAUNCH, "true");
-
- aul_svc_set_loader_id(kb, PAD_LOADER_ID_DIRECT);
-
-end:
- pkgmgrinfo_appinfo_destroy_appinfo(handle);
-
- return ret;
-}
-
-static int __cmd_fast_start_run(struct launch_arg *arg)
-{
- if (!access(PATH_AMD_SOCK, F_OK))
- return __cmd_start_run(arg);
-
- if (__set_appinfo_for_launchpad(arg->b, arg->appid, arg->uid) < 0) {
- printf("Failed to set appinfo\n");
- return -1;
- }
-
- arg->pid = app_send_cmd_to_launchpad(LAUNCHPAD_PROCESS_POOL_SOCK,
- arg->uid, 0, arg->b);
- if (arg->pid <= 0) {
- printf("... launch failed\n");
- return -1;
- }
-
- printf("... successfully launched pid = %d with debug %d\n",
- arg->pid, arg->debug);
-
- return 0;
-}
-
-static void __cmd_fast_start_finish(struct launch_arg *arg)
-{
- __cmd_start_finish(arg);
-}
-
-static int __cmd_direct_start_run(struct launch_arg *arg)
-{
- aul_svc_set_loader_id(arg->b, PAD_LOADER_ID_DIRECT);
-
- return __cmd_start_run(arg);
-}
-
-static void __cmd_direct_start_finish(struct launch_arg *arg)
-{
- __cmd_start_finish(arg);
-}
-
-static bundle *__create_bundle(int argc, char **argv)
-{
- bundle *b;
- int i;
-
- b = bundle_create();
- if (!b)
- return NULL;
-
- for (i = 1; i + 1 < argc; i += 2)
- bundle_add(b, argv[i], argv[i + 1]);
-
- return b;
-}
-
-static void __destroy_launch_arg(struct launch_arg *launch_arg)
-{
- if (launch_arg == NULL)
- return;
-
- if (launch_arg->b)
- bundle_free(launch_arg->b);
- free(launch_arg);
-}
-
-static struct launch_arg *__create_launch_arg(int argc, char **argv)
-{
- struct launch_arg *launch_arg;
- const char *val;
-
- launch_arg = (struct launch_arg *)calloc(1, sizeof(struct launch_arg));
- if (!launch_arg)
- return NULL;
-
- if (cmd_opt[CMD_START])
- launch_arg->appid = cmd_opt[CMD_START];
- else if (cmd_opt[CMD_KILL])
- launch_arg->appid = cmd_opt[CMD_KILL];
- else if (cmd_opt[CMD_TERMINATE])
- launch_arg->appid = cmd_opt[CMD_TERMINATE];
- else if (cmd_opt[CMD_IS_RUNNING])
- launch_arg->appid = cmd_opt[CMD_IS_RUNNING];
- else if (cmd_opt[CMD_FAST_START])
- launch_arg->appid = cmd_opt[CMD_FAST_START];
- else if (cmd_opt[CMD_DIRECT_START])
- launch_arg->appid = cmd_opt[CMD_DIRECT_START];
-
- if (opt[OPT_USER])
- launch_arg->uid = GPOINTER_TO_INT(opt[OPT_USER]);
- else
- launch_arg->uid = getuid();
-
- launch_arg->debug = GPOINTER_TO_INT(opt[OPT_DEBUG]);
- launch_arg->web_debug = GPOINTER_TO_INT(opt[OPT_WEB_DEBUG]);
- launch_arg->b = __create_bundle(argc, argv);
- if (launch_arg->b) {
- val = bundle_get_val(launch_arg->b, "__LAUNCH_APP_MODE__");
- if (val && !strcmp(val, "SYNC"))
- launch_arg->sync = true;
-
- if (launch_arg->debug || launch_arg->web_debug)
- bundle_add(launch_arg->b, AUL_K_DEBUG, "1");
- }
-
- return launch_arg;
-}
-
-static struct command cmd_table[] = {
- [CMD_LIST] = {
- .name = "list",
- .init = NULL,
- .run = __cmd_list_run,
- .finish = __cmd_common_finish
- },
- [CMD_STATUS] = {
- .name = "status",
- .init = NULL,
- .run = __cmd_status_run,
- .finish = __cmd_common_finish
- },
- [CMD_START] = {
- .name = "start",
- .init = NULL,
- .run = __cmd_start_run,
- .finish = __cmd_start_finish
- },
- [CMD_KILL] = {
- .name = "kill",
- .init = __cmd_common_init,
- .run = __cmd_kill_run,
- .finish = __cmd_common_finish
- },
- [CMD_TERMINATE] = {
- .name = "terminate",
- .init = __cmd_common_init,
- .run = __cmd_terminate_run,
- .finish = __cmd_common_finish
- },
- [CMD_IS_RUNNING] = {
- .name = "is-running",
- .init = __cmd_common_init,
- .run = __cmd_is_running_run,
- .finish = __cmd_common_finish
- },
- [CMD_FAST_START] = {
- .name = "fast-start",
- .init = __cmd_common_init,
- .run = __cmd_fast_start_run,
- .finish = __cmd_fast_start_finish
- },
- [CMD_DIRECT_START] = {
- .name = "direct-start",
- .init = __cmd_common_init,
- .run = __cmd_direct_start_run,
- .finish = __cmd_direct_start_finish
- },
-};
-
-static struct command *__find_cmd(void)
-{
- int i;
-
- for (i = 0; i < G_N_ELEMENTS(cmd_table); ++i) {
- if (cmd_opt[i])
- return &cmd_table[i];
- }
-
- return NULL;
-}
-
-static gboolean __run_cmd(gpointer data)
-{
- struct launch_arg *launch_arg = (struct launch_arg *)data;
- struct command *cmd;
-
- cmd = __find_cmd();
- if (cmd == NULL) {
- printf("%s", help);
- g_main_loop_quit(loop);
- return G_SOURCE_REMOVE;
- }
-
- if (cmd->init) {
- result = cmd->init(launch_arg);
- if (result != 0) {
- g_main_loop_quit(loop);
- return G_SOURCE_REMOVE;
- }
- }
-
- if (cmd->run) {
- result = cmd->run(launch_arg);
- if (result != 0) {
- g_main_loop_quit(loop);
- return G_SOURCE_REMOVE;
- }
- }
-
- if (cmd->finish)
- cmd->finish(launch_arg);
-
- return G_SOURCE_REMOVE;
-}
-
-int main(int argc, char *argv[])
-{
- GOptionContext *context;
- GOptionGroup *opt_group;
- GError *error = NULL;
- struct launch_arg *launch_arg;
-
- __print_hwc_messages("%d|main start", getpid());
-
- context = g_option_context_new(NULL);
- g_option_context_add_main_entries(context, cmd_entries, NULL);
-
- opt_group = __get_opt_group();
- if (!opt_group) {
- printf("Failed to get opt group\n");
- g_option_context_free(context);
- return -1;
- }
- g_option_context_add_group(context, opt_group);
-
- if (!g_option_context_parse(context, &argc, &argv, &error)) {
- printf("%s: %s\n", argv[0], error->message);
- g_option_context_free(context);
- g_clear_error(&error);
- return -1;
- }
-
- help = g_option_context_get_help(context, TRUE, NULL);
- g_option_context_free(context);
-
- launch_arg = __create_launch_arg(argc, argv);
- if (!launch_arg) {
- printf("%s", help);
- free(help);
- return -1;
- }
-
- g_idle_add(__run_cmd, launch_arg);
- loop = g_main_loop_new(NULL, FALSE);
- if (!loop) {
- printf("Failed to create glib main loop\n");
- exit(EXIT_FAILURE);
- }
- g_main_loop_run(loop);
- g_main_loop_unref(loop);
- __destroy_launch_arg(launch_arg);
- free(help);
-
- return result;
-}
--- /dev/null
+SET(TARGET_APP_LAUNCHER "app_launcher")
+
+ADD_EXECUTABLE(${TARGET_APP_LAUNCHER}
+ ${CMAKE_CURRENT_SOURCE_DIR}/app_launcher.c)
+
+IF(_TIZEN_FEATURE_PRELINK)
+MESSAGE(STATUS "[__PRELINK__] Enable")
+ELSE(_TIZEN_FEATURE_PRELINK)
+MESSAGE(STATUS "[__PRELINK__] Disable")
+SET_TARGET_PROPERTIES(${TARGET_APP_LAUNCHER} PROPERTIES COMPILE_FLAGS ${CFLAGS} "-fPIE")
+SET_TARGET_PROPERTIES(${TARGET_APP_LAUNCHER} PROPERTIES LINK_FLAGS "-pie")
+ENDIF(_TIZEN_FEATURE_PRELINK)
+
+TARGET_LINK_LIBRARIES(${TARGET_APP_LAUNCHER} PRIVATE ${TARGET_AUL})
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_APP_LAUNCHER} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../src)
+TARGET_INCLUDE_DIRECTORIES(${TARGET_APP_LAUNCHER} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../include)
+
+INSTALL(TARGETS ${TARGET_APP_LAUNCHER} DESTINATION bin)
--- /dev/null
+/*
+ * Copyright (c) 2014 - 2017 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 <stdlib.h>
+#include <string.h>
+#include <stdbool.h>
+#include <sys/types.h>
+#include <sys/inotify.h>
+#include <linux/limits.h>
+#include <glib.h>
+#include <gio/gio.h>
+#include <pkgmgr-info.h>
+#include <bundle_internal.h>
+#include <sys/prctl.h>
+
+#include "aul.h"
+#include "aul_svc.h"
+#include "launch.h"
+
+#define LAUNCHPAD_PROCESS_POOL_SOCK ".launchpad-process-pool-sock"
+#define AMD_SOCK ".amd-sock"
+#define PATH_AUL_DAEMONS "/run/aul/daemons"
+#define PATH_AMD_SOCK PATH_AUL_DAEMONS "/" AMD_SOCK
+#define APP_TYPE_UI "uiapp"
+#define APP_TYPE_SERVICE "svcapp"
+#define INOTIFY_BUF (1024 * ((sizeof(struct inotify_event)) + 16))
+
+#ifndef PR_TASK_PERF_USER_TRACE
+#define PR_TASK_PERF_USER_TRACE 666
+#endif
+
+struct launch_arg {
+ char *appid;
+ bundle *b;
+ pid_t pid;
+ uid_t uid;
+ bool debug;
+ bool web_debug;
+ bool sync;
+};
+
+enum command_e {
+ CMD_LIST,
+ CMD_STATUS,
+ CMD_START,
+ CMD_KILL,
+ CMD_TERMINATE,
+ CMD_IS_RUNNING,
+ CMD_FAST_START,
+ CMD_DIRECT_START,
+ CMD_MAX,
+};
+
+enum option_e {
+ OPT_DEBUG,
+ OPT_WEB_DEBUG,
+ OPT_USER,
+ OPT_MAX,
+};
+
+struct command {
+ const char *name;
+ int (*init)(struct launch_arg *arg);
+ int (*run)(struct launch_arg *arg);
+ void (*finish)(struct launch_arg *arg);
+};
+
+static int result;
+static GMainLoop *loop;
+static gchar *help;
+static gpointer cmd_opt[CMD_MAX];
+static GOptionEntry cmd_entries[] = {
+ {
+ .long_name = "list",
+ .short_name = 'l',
+ .flags = 0,
+ .arg = G_OPTION_ARG_NONE,
+ .arg_data = &cmd_opt[CMD_LIST],
+ .description = "Show installed application list",
+ .arg_description = NULL
+ },
+ {
+ .long_name = "status",
+ .short_name = 'S',
+ .flags = 0,
+ .arg = G_OPTION_ARG_NONE,
+ .arg_data = &cmd_opt[CMD_STATUS],
+ .description = "Show the running application information",
+ .arg_description = NULL
+ },
+ {
+ .long_name = "start",
+ .short_name = 's',
+ .flags = 0,
+ .arg = G_OPTION_ARG_STRING,
+ .arg_data = &cmd_opt[CMD_START],
+ .description = "Execute the application",
+ .arg_description = "APPLICATION ID"
+ },
+ {
+ .long_name = "kill",
+ .short_name = 'k',
+ .flags = 0,
+ .arg = G_OPTION_ARG_STRING,
+ .arg_data = &cmd_opt[CMD_KILL],
+ .description = "Kill the running application",
+ .arg_description = "APPLICATION ID"
+ },
+ {
+ .long_name = "terminate",
+ .short_name = 't',
+ .flags = 0,
+ .arg = G_OPTION_ARG_STRING,
+ .arg_data = &cmd_opt[CMD_TERMINATE],
+ .description = "Terminte the running application",
+ .arg_description = "APPLICATION ID"
+ },
+ {
+ .long_name = "is-running",
+ .short_name = 'r',
+ .flags = 0,
+ .arg = G_OPTION_ARG_STRING,
+ .arg_data = &cmd_opt[CMD_IS_RUNNING],
+ .description = "Check whether the application is running or Not",
+ .arg_description = "APPLICATION ID"
+ },
+ {
+ .long_name = "fast-start",
+ .short_name = 'f',
+ .flags = 0,
+ .arg = G_OPTION_ARG_STRING,
+ .arg_data = &cmd_opt[CMD_FAST_START],
+ .description = "[Deprecated] Execute the application quickly",
+ .arg_description = "APPLICATION ID"
+ },
+ {
+ .long_name = "direct-start",
+ .short_name = 'e',
+ .flags = 0,
+ .arg = G_OPTION_ARG_STRING,
+ .arg_data = &cmd_opt[CMD_DIRECT_START],
+ .description = "Execute the application without the loader",
+ .arg_description = "APPLICATION ID"
+ },
+ {
+ NULL
+ }
+};
+static gpointer opt[OPT_MAX];
+static GOptionEntry opt_entries[] = {
+ {
+ .long_name = "debug",
+ .short_name = 'd',
+ .flags = 0,
+ .arg = G_OPTION_ARG_NONE,
+ .arg_data = &opt[OPT_DEBUG],
+ .description = "Activate debug mode",
+ .arg_description = NULL
+ },
+ {
+ .long_name = "web-debug",
+ .short_name = 'w',
+ .flags = 0,
+ .arg = G_OPTION_ARG_NONE,
+ .arg_data = &opt[OPT_WEB_DEBUG],
+ .description = "Activate web debug mode, Use only for webapps",
+ .arg_description = NULL
+ },
+ {
+ .long_name = "user",
+ .short_name = 'u',
+ .flags = 0,
+ .arg = G_OPTION_ARG_INT,
+ .arg_data = &opt[OPT_USER],
+ .description = "Specify the user ID",
+ .arg_description = "USER ID"
+ },
+ {
+ NULL
+ }
+};
+
+static void __print_hwc_messages(const char *format, ...)
+{
+ char buf[1024];
+ va_list ap;
+
+ va_start(ap, format);
+ vsnprintf(buf, sizeof(buf), format, ap);
+ va_end(ap);
+
+ prctl(PR_TASK_PERF_USER_TRACE, buf, strlen(buf));
+}
+
+static GOptionGroup *__get_opt_group(void)
+{
+ GOptionGroup *group;
+
+ group = g_option_group_new("option", "Additional Options:",
+ "Additional options", NULL, NULL);
+ if (!group)
+ return NULL;
+
+ g_option_group_add_entries(group, opt_entries);
+
+ return group;
+}
+
+static int __is_app_installed(const char *appid, uid_t uid)
+{
+ pkgmgrinfo_appinfo_filter_h filter;
+ int is_installed = 0;
+ int ret;
+
+ ret = pkgmgrinfo_appinfo_filter_create(&filter);
+ if (ret != PMINFO_R_OK) {
+ printf("Failed to create filter\n");
+ return -1;
+ }
+
+ ret = pkgmgrinfo_appinfo_filter_add_string(filter,
+ PMINFO_APPINFO_PROP_APP_ID, appid);
+ if (ret != PMINFO_R_OK) {
+ printf("Failed to add filter string\n");
+ pkgmgrinfo_appinfo_filter_destroy(filter);
+ return -1;
+ }
+
+ ret = pkgmgrinfo_appinfo_usr_filter_count(filter,
+ &is_installed, uid);
+ if (ret != PMINFO_R_OK) {
+ printf("Failed to get filter count\n");
+ pkgmgrinfo_appinfo_filter_destroy(filter);
+ return -1;
+ }
+
+ pkgmgrinfo_appinfo_filter_destroy(filter);
+
+ return is_installed;
+}
+
+static int __cmd_common_init(struct launch_arg *arg)
+{
+ if (!__is_app_installed(arg->appid, arg->uid)) {
+ printf("The app with ID: %s is not available for the user %d\n",
+ arg->appid, arg->uid);
+ return -1;
+ }
+
+ return 0;
+}
+
+static void __cmd_common_finish(struct launch_arg *arg)
+{
+ g_main_loop_quit(loop);
+}
+
+static int __installed_list_cb(const pkgmgrinfo_appinfo_h handle, void *data)
+{
+ char *label;
+ char *appid;
+
+ if (pkgmgrinfo_appinfo_get_label(handle, &label))
+ label = "";
+
+ if (pkgmgrinfo_appinfo_get_appid(handle, &appid)) {
+ printf("Failed to get appid\n");
+ return -1;
+ }
+
+ printf("\t'%s'\t '%s'\n", label, appid);
+
+ return 0;
+}
+
+static int __cmd_list_run(struct launch_arg *arg)
+{
+ int ret;
+
+ printf("\tApplication List for user %u\n", arg->uid);
+ printf("\tUser's Application \n");
+ printf("\t Name \t AppID \n");
+ printf("\t=================================================\n");
+
+ ret = pkgmgrinfo_appinfo_get_usr_installed_list(__installed_list_cb,
+ arg->uid, NULL);
+
+ printf("\t=================================================\n");
+
+ return ret;
+}
+
+static int __running_app_info_cb(const aul_app_info *info, void *data)
+{
+ printf("\t %s (%d)\n", info->appid, info->pid);
+ return 0;
+}
+
+static int __cmd_status_run(struct launch_arg *arg)
+{
+ int ret;
+
+ printf("\t appId (PID)\n");
+ ret = aul_app_get_running_app_info_for_uid(__running_app_info_cb,
+ NULL, arg->uid);
+ if (ret < 0) {
+ printf("Failed to show the list of running applications\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+static int __app_dead_signal_cb(int pid, void *data)
+{
+ struct launch_arg *arg = (struct launch_arg *)data;
+
+ if (arg->pid == pid)
+ g_main_loop_quit(loop);
+
+ return 0;
+}
+
+static void __reply_cb(bundle *b, int request_code,
+ aul_svc_result_val result, void *data)
+{
+ const char *port;
+ const char *pid;
+
+ port = bundle_get_val(b, "port");
+ pid = bundle_get_val(b, AUL_K_CALLEE_PID);
+ if (port && pid) {
+ printf("... successfully launched pid = %s with debug 1 port: %s\n",
+ pid, port);
+ } else {
+ printf("... launch failed\n");
+ }
+
+ g_main_loop_quit(loop);
+}
+
+static int __cmd_start_run(struct launch_arg *arg)
+{
+ if (arg->web_debug) {
+ aul_svc_set_operation(arg->b, AUL_SVC_OPERATION_DEFAULT);
+ aul_svc_set_appid(arg->b, arg->appid);
+ arg->pid = aul_svc_run_service_for_uid(arg->b, 0, __reply_cb,
+ NULL, arg->uid);
+ } else {
+ arg->pid = aul_launch_app_for_uid(arg->appid, arg->b, arg->uid);
+ if (arg->pid > 0) {
+ printf("... successfully launched pid = %d with debug %d\n",
+ arg->pid, arg->debug);
+ }
+ }
+
+ if (arg->pid <= 0) {
+ if (arg->pid == AUL_R_ENOAPP) {
+ printf("The app with ID: %s is not available for the user %d\n",
+ arg->appid, arg->uid);
+ } else {
+ printf("... launch failed\n");
+ }
+ return -1;
+ }
+
+ return 0;
+}
+
+static gboolean __retry_handler(gpointer data)
+{
+ struct launch_arg *arg = (struct launch_arg *)data;
+ int r;
+
+ r = aul_app_get_status_bypid_for_uid(arg->pid, arg->uid);
+ if (r == -1 || r == STATUS_DYING) {
+ g_main_loop_quit(loop);
+ return G_SOURCE_REMOVE;
+ } else if (r < 0) {
+ return G_SOURCE_CONTINUE;
+ }
+
+ r = aul_listen_app_dead_signal(__app_dead_signal_cb, arg);
+ if (r < 0)
+ return G_SOURCE_CONTINUE;
+
+ return G_SOURCE_REMOVE;
+}
+
+static void __cmd_start_finish(struct launch_arg *arg)
+{
+ int r;
+
+ if (arg->pid > 0 && arg->sync) {
+ r = aul_listen_app_dead_signal(__app_dead_signal_cb, arg);
+ if (r < 0)
+ g_timeout_add(500, __retry_handler, arg);
+
+ return;
+ }
+
+ if (arg->pid > 0 && arg->web_debug)
+ return;
+
+ g_main_loop_quit(loop);
+}
+
+static int __kill_running_app_cb(const aul_app_info *info, void *data)
+{
+ if (!strcmp(info->appid, data)) {
+ aul_kill_pid(info->pid);
+ printf("\t Kill appId: %s (%d)\n", info->appid, info->pid);
+ }
+
+ return 0;
+}
+
+static int __cmd_kill_run(struct launch_arg *arg)
+{
+ int ret;
+
+ if (!aul_app_is_running_for_uid(arg->appid, arg->uid)) {
+ printf("result: App isn't running\n");
+ return 1;
+ }
+
+ ret = aul_app_get_running_app_info_for_uid(__kill_running_app_cb,
+ arg->appid, arg->uid);
+ if (ret < 0)
+ return -1;
+
+ return 0;
+}
+
+static int __terminate_running_app_cb(const aul_app_info *info, void *data)
+{
+ if (!strcmp(info->appid, data)) {
+ aul_terminate_pid(info->pid);
+ printf("\t Terminate appId: %s (%d)\n", info->appid, info->pid);
+ }
+
+ return 0;
+}
+
+static int __cmd_terminate_run(struct launch_arg *arg)
+{
+ int ret;
+
+ if (!aul_app_is_running_for_uid(arg->appid, arg->uid)) {
+ printf("result: App isn't running\n");
+ return 1;
+ }
+
+ ret = aul_app_get_running_app_info_for_uid(__terminate_running_app_cb,
+ arg->appid, arg->uid);
+ if (ret < 0)
+ return -1;
+
+ return 0;
+}
+
+static int __cmd_is_running_run(struct launch_arg *arg)
+{
+ if (!aul_app_is_running_for_uid(arg->appid, arg->uid)) {
+ printf("result: not running\n");
+ return 1;
+ }
+
+ printf("result: running\n");
+
+ return 0;
+}
+
+static int __get_gles(void)
+{
+ FILE *fp;
+ char buf[LINE_MAX];
+ char *tmp;
+ int gles = 1;
+
+ fp = fopen("/proc/cmdline", "r");
+ if (fp == NULL)
+ return gles;
+
+ if (fgets(buf, sizeof(buf), fp) != NULL) {
+ tmp = strstr(buf, "gles");
+ if (tmp != NULL)
+ sscanf(tmp, "gles=%d", &gles);
+ }
+
+ fclose(fp);
+
+ return gles;
+}
+
+static int __set_appinfo_for_launchpad(bundle *kb, const char *appid, uid_t uid)
+{
+ pkgmgrinfo_appinfo_h handle;
+ int ret;
+ char *pkgid = NULL;
+ char *exec = NULL;
+ char *apptype = NULL;
+ char *pkgtype = NULL;
+ char *component_type = NULL;
+ char *root_path = NULL;
+ char *api_version = NULL;
+ pkgmgrinfo_app_hwacceleration hwacc = PMINFO_HWACCELERATION_OFF;
+ const char *hwacc_str = "NOT_USE";
+ bool process_pool = false;
+
+ if (kb == NULL)
+ return -1;
+
+ ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, uid, &handle);
+ if (ret != PMINFO_R_OK)
+ return -1;
+
+ ret = pkgmgrinfo_appinfo_get_exec(handle, &exec);
+ if (ret != PMINFO_R_OK)
+ goto end;
+
+ ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
+ if (ret != PMINFO_R_OK)
+ goto end;
+
+ ret = pkgmgrinfo_appinfo_get_apptype(handle, &apptype);
+ if (ret != PMINFO_R_OK)
+ goto end;
+
+ ret = pkgmgrinfo_appinfo_get_pkgtype(handle, &pkgtype);
+ if (ret != PMINFO_R_OK)
+ goto end;
+
+ ret = pkgmgrinfo_appinfo_get_component_type(handle, &component_type);
+ if (ret != PMINFO_R_OK)
+ goto end;
+
+ if (!component_type || (strcmp(component_type, APP_TYPE_SERVICE) != 0 &&
+ strcmp(component_type, APP_TYPE_UI) != 0)) {
+ ret = -1;
+ goto end;
+ }
+
+ ret = pkgmgrinfo_appinfo_get_hwacceleration(handle, &hwacc);
+ if (ret != PMINFO_R_OK)
+ goto end;
+
+ ret = pkgmgrinfo_appinfo_is_process_pool(handle, &process_pool);
+ if (ret != PMINFO_R_OK)
+ goto end;
+
+ if (__get_gles() && hwacc == PMINFO_HWACCELERATION_ON)
+ hwacc_str = "USE";
+ else if (hwacc == PMINFO_HWACCELERATION_OFF)
+ hwacc_str = "NOT_USE";
+ else
+ hwacc_str = "SYS";
+
+ ret = pkgmgrinfo_appinfo_get_root_path(handle, &root_path);
+ if (ret != PMINFO_R_OK)
+ goto end;
+
+ ret = pkgmgrinfo_appinfo_get_api_version(handle, &api_version);
+ if (ret != PMINFO_R_OK)
+ goto end;
+
+ bundle_add(kb, AUL_K_APPID, appid);
+ bundle_add(kb, AUL_K_HWACC, hwacc_str);
+ bundle_add(kb, AUL_K_EXEC, exec);
+ bundle_add(kb, AUL_K_APP_TYPE, apptype);
+ bundle_add(kb, AUL_K_PKGID, pkgid);
+ bundle_add(kb, AUL_K_INTERNAL_POOL, process_pool ? "true" : "false");
+ bundle_add(kb, AUL_K_COMP_TYPE, component_type);
+ bundle_add(kb, AUL_K_PACKAGETYPE, pkgtype);
+ bundle_add(kb, AUL_K_ROOT_PATH, root_path);
+ bundle_add(kb, AUL_K_API_VERSION, api_version);
+ bundle_add(kb, AUL_K_FAST_LAUNCH, "true");
+
+ aul_svc_set_loader_id(kb, PAD_LOADER_ID_DIRECT);
+
+end:
+ pkgmgrinfo_appinfo_destroy_appinfo(handle);
+
+ return ret;
+}
+
+static int __cmd_fast_start_run(struct launch_arg *arg)
+{
+ if (!access(PATH_AMD_SOCK, F_OK))
+ return __cmd_start_run(arg);
+
+ if (__set_appinfo_for_launchpad(arg->b, arg->appid, arg->uid) < 0) {
+ printf("Failed to set appinfo\n");
+ return -1;
+ }
+
+ arg->pid = app_send_cmd_to_launchpad(LAUNCHPAD_PROCESS_POOL_SOCK,
+ arg->uid, 0, arg->b);
+ if (arg->pid <= 0) {
+ printf("... launch failed\n");
+ return -1;
+ }
+
+ printf("... successfully launched pid = %d with debug %d\n",
+ arg->pid, arg->debug);
+
+ return 0;
+}
+
+static void __cmd_fast_start_finish(struct launch_arg *arg)
+{
+ __cmd_start_finish(arg);
+}
+
+static int __cmd_direct_start_run(struct launch_arg *arg)
+{
+ aul_svc_set_loader_id(arg->b, PAD_LOADER_ID_DIRECT);
+
+ return __cmd_start_run(arg);
+}
+
+static void __cmd_direct_start_finish(struct launch_arg *arg)
+{
+ __cmd_start_finish(arg);
+}
+
+static bundle *__create_bundle(int argc, char **argv)
+{
+ bundle *b;
+ int i;
+
+ b = bundle_create();
+ if (!b)
+ return NULL;
+
+ for (i = 1; i + 1 < argc; i += 2)
+ bundle_add(b, argv[i], argv[i + 1]);
+
+ return b;
+}
+
+static void __destroy_launch_arg(struct launch_arg *launch_arg)
+{
+ if (launch_arg == NULL)
+ return;
+
+ if (launch_arg->b)
+ bundle_free(launch_arg->b);
+ free(launch_arg);
+}
+
+static struct launch_arg *__create_launch_arg(int argc, char **argv)
+{
+ struct launch_arg *launch_arg;
+ const char *val;
+
+ launch_arg = (struct launch_arg *)calloc(1, sizeof(struct launch_arg));
+ if (!launch_arg)
+ return NULL;
+
+ if (cmd_opt[CMD_START])
+ launch_arg->appid = cmd_opt[CMD_START];
+ else if (cmd_opt[CMD_KILL])
+ launch_arg->appid = cmd_opt[CMD_KILL];
+ else if (cmd_opt[CMD_TERMINATE])
+ launch_arg->appid = cmd_opt[CMD_TERMINATE];
+ else if (cmd_opt[CMD_IS_RUNNING])
+ launch_arg->appid = cmd_opt[CMD_IS_RUNNING];
+ else if (cmd_opt[CMD_FAST_START])
+ launch_arg->appid = cmd_opt[CMD_FAST_START];
+ else if (cmd_opt[CMD_DIRECT_START])
+ launch_arg->appid = cmd_opt[CMD_DIRECT_START];
+
+ if (opt[OPT_USER])
+ launch_arg->uid = GPOINTER_TO_INT(opt[OPT_USER]);
+ else
+ launch_arg->uid = getuid();
+
+ launch_arg->debug = GPOINTER_TO_INT(opt[OPT_DEBUG]);
+ launch_arg->web_debug = GPOINTER_TO_INT(opt[OPT_WEB_DEBUG]);
+ launch_arg->b = __create_bundle(argc, argv);
+ if (launch_arg->b) {
+ val = bundle_get_val(launch_arg->b, "__LAUNCH_APP_MODE__");
+ if (val && !strcmp(val, "SYNC"))
+ launch_arg->sync = true;
+
+ if (launch_arg->debug || launch_arg->web_debug)
+ bundle_add(launch_arg->b, AUL_K_DEBUG, "1");
+ }
+
+ return launch_arg;
+}
+
+static struct command cmd_table[] = {
+ [CMD_LIST] = {
+ .name = "list",
+ .init = NULL,
+ .run = __cmd_list_run,
+ .finish = __cmd_common_finish
+ },
+ [CMD_STATUS] = {
+ .name = "status",
+ .init = NULL,
+ .run = __cmd_status_run,
+ .finish = __cmd_common_finish
+ },
+ [CMD_START] = {
+ .name = "start",
+ .init = NULL,
+ .run = __cmd_start_run,
+ .finish = __cmd_start_finish
+ },
+ [CMD_KILL] = {
+ .name = "kill",
+ .init = __cmd_common_init,
+ .run = __cmd_kill_run,
+ .finish = __cmd_common_finish
+ },
+ [CMD_TERMINATE] = {
+ .name = "terminate",
+ .init = __cmd_common_init,
+ .run = __cmd_terminate_run,
+ .finish = __cmd_common_finish
+ },
+ [CMD_IS_RUNNING] = {
+ .name = "is-running",
+ .init = __cmd_common_init,
+ .run = __cmd_is_running_run,
+ .finish = __cmd_common_finish
+ },
+ [CMD_FAST_START] = {
+ .name = "fast-start",
+ .init = __cmd_common_init,
+ .run = __cmd_fast_start_run,
+ .finish = __cmd_fast_start_finish
+ },
+ [CMD_DIRECT_START] = {
+ .name = "direct-start",
+ .init = __cmd_common_init,
+ .run = __cmd_direct_start_run,
+ .finish = __cmd_direct_start_finish
+ },
+};
+
+static struct command *__find_cmd(void)
+{
+ int i;
+
+ for (i = 0; i < G_N_ELEMENTS(cmd_table); ++i) {
+ if (cmd_opt[i])
+ return &cmd_table[i];
+ }
+
+ return NULL;
+}
+
+static gboolean __run_cmd(gpointer data)
+{
+ struct launch_arg *launch_arg = (struct launch_arg *)data;
+ struct command *cmd;
+
+ cmd = __find_cmd();
+ if (cmd == NULL) {
+ printf("%s", help);
+ g_main_loop_quit(loop);
+ return G_SOURCE_REMOVE;
+ }
+
+ if (cmd->init) {
+ result = cmd->init(launch_arg);
+ if (result != 0) {
+ g_main_loop_quit(loop);
+ return G_SOURCE_REMOVE;
+ }
+ }
+
+ if (cmd->run) {
+ result = cmd->run(launch_arg);
+ if (result != 0) {
+ g_main_loop_quit(loop);
+ return G_SOURCE_REMOVE;
+ }
+ }
+
+ if (cmd->finish)
+ cmd->finish(launch_arg);
+
+ return G_SOURCE_REMOVE;
+}
+
+int main(int argc, char *argv[])
+{
+ GOptionContext *context;
+ GOptionGroup *opt_group;
+ GError *error = NULL;
+ struct launch_arg *launch_arg;
+
+ __print_hwc_messages("%d|main start", getpid());
+
+ context = g_option_context_new(NULL);
+ g_option_context_add_main_entries(context, cmd_entries, NULL);
+
+ opt_group = __get_opt_group();
+ if (!opt_group) {
+ printf("Failed to get opt group\n");
+ g_option_context_free(context);
+ return -1;
+ }
+ g_option_context_add_group(context, opt_group);
+
+ if (!g_option_context_parse(context, &argc, &argv, &error)) {
+ printf("%s: %s\n", argv[0], error->message);
+ g_option_context_free(context);
+ g_clear_error(&error);
+ return -1;
+ }
+
+ help = g_option_context_get_help(context, TRUE, NULL);
+ g_option_context_free(context);
+
+ launch_arg = __create_launch_arg(argc, argv);
+ if (!launch_arg) {
+ printf("%s", help);
+ free(help);
+ return -1;
+ }
+
+ g_idle_add(__run_cmd, launch_arg);
+ loop = g_main_loop_new(NULL, FALSE);
+ if (!loop) {
+ printf("Failed to create glib main loop\n");
+ exit(EXIT_FAILURE);
+ }
+ g_main_loop_run(loop);
+ g_main_loop_unref(loop);
+ __destroy_launch_arg(launch_arg);
+ free(help);
+
+ return result;
+}
--- /dev/null
+SET(TARGET_APP_GROUP_INFO "appgroup_info")
+
+ADD_EXECUTABLE(${TARGET_APP_GROUP_INFO} ${CMAKE_CURRENT_SOURCE_DIR}/app_group_info.c)
+SET_TARGET_PROPERTIES(${TARGET_APP_GROUP_INFO} PROPERTIES COMPILE_FLAGS ${CFLAGS} "-fPIE")
+SET_TARGET_PROPERTIES(${TARGET_APP_GROUP_INFO} PROPERTIES LINK_FLAGS "-pie")
+TARGET_LINK_LIBRARIES(${TARGET_APP_GROUP_INFO} PRIVATE ${TARGET_AUL})
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_APP_GROUP_INFO} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../src)
+TARGET_INCLUDE_DIRECTORIES(${TARGET_APP_GROUP_INFO} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../include)
+
+INSTALL(TARGETS ${TARGET_APP_GROUP_INFO} DESTINATION bin)
--- /dev/null
+/*
+ * Copyright (c) 2015 - 2019 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 <stdlib.h>
+
+#include "aul.h"
+#include "aul_app_group.h"
+
+static void __foreach_idle_group_info(aul_app_group_info_h info,
+ void *user_data)
+{
+ int *idle_count = (int *)user_data;
+ const char *id = NULL;
+ pid_t pid = -1;
+ const char *appid = NULL;
+
+ (*idle_count)++;
+ aul_app_group_info_get_id(info, &id);
+ aul_app_group_info_get_pid(info, &pid);
+ aul_app_group_info_get_appid(info, &appid);
+
+ printf("---------------------------\n");
+ printf(" - id : %s\n", id);
+ printf(" - pid : %d\n", pid);
+ printf(" - appid : %s\n", appid);
+ printf("\n");
+}
+
+static void __print_idle_info(void)
+{
+ int idle_count = 0;
+
+ aul_app_group_foreach_idle_info(__foreach_idle_group_info,
+ (void *)&idle_count);
+ printf("< Idle count : %d >\n", idle_count);
+}
+
+static void __print_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;
+ };
+}
+
+static void __foreach_group_info(aul_app_group_info_h info, void *user_data)
+{
+ int *member_count = (int *)user_data;
+ const char *id = NULL;
+ pid_t pid = -1;
+ const char *appid = NULL;
+ const char *pkgid = NULL;
+ int wid = 0;
+ bool fg = false;
+ int status = -1;
+
+ (*member_count)++;
+ aul_app_group_info_get_id(info, &id);
+ aul_app_group_info_get_pid(info, &pid);
+ aul_app_group_info_get_appid(info, &appid);
+ aul_app_group_info_get_pkgid(info, &pkgid);
+ aul_app_group_info_get_window(info, &wid);
+ aul_app_group_info_get_fg_flag(info, &fg);
+ aul_app_group_info_get_status(info, &status);
+
+ printf("--- member : %d\n", *member_count);
+ printf(" - id : %s\n", id);
+ printf(" - pid : %d\n", pid);
+ printf(" - app id : %s\n", appid);
+ printf(" - pkg id : %s\n", pkgid);
+ printf(" - win id : %d\n", wid);
+ printf(" - fg group : %s\n", fg ? "true" : "false");
+ __print_status(status);
+ printf("\n");
+}
+
+static void __foreach_leader_ids(const char *leader_id, void *user_data)
+{
+ int *group_count = (int *)user_data;
+ int member_count = 0;
+
+ (*group_count)++;
+ printf("----------------------------------\n");
+ printf("< Group : %d >\n", *group_count);
+
+ aul_app_group_foreach_group_info(leader_id, __foreach_group_info,
+ (void *)&member_count);
+ printf("Member count: %d\n", member_count);
+ printf("\n");
+}
+
+static void __print_info(void)
+{
+ int group_count = 0;
+ int ret;
+
+ ret = aul_app_group_foreach_leader_ids(__foreach_leader_ids,
+ (void *)&group_count);
+ if (ret < 0) {
+ printf("No app group\n");
+ return;
+ }
+
+ printf("==================================\n");
+ printf("\n");
+ printf("App Group count: %d\n", group_count);
+}
+
+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;
+}
+++ /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.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "aul.h"
-
-struct app_info {
- char *appid;
- int pid;
-};
-
-static int __all_running_app_info(const aul_app_info *info, void *data)
-{
- struct app_info *appinfo = (struct app_info *)data;
-
- if (appinfo == NULL || appinfo->appid == NULL)
- return -1;
-
- if (info == NULL || info->appid == NULL)
- return -1;
-
- if (strcmp(info->appid, appinfo->appid) == 0)
- appinfo->pid = info->pid;
-
- return 0;
-}
-
-int main(int argc, char **argv)
-{
- struct app_info info;
-
- if (argc < 2) {
- printf("[usage] %s <appid>\n", argv[0]);
- exit(EXIT_FAILURE);
- }
-
- info.appid = argv[1];
- info.pid = -1;
-
- aul_app_get_all_running_app_info(__all_running_app_info, &info);
-
- printf("%d\n", info.pid);
-
- return 0;
-}
--- /dev/null
+SET(TARGET_APPID2PID "appid2pid")
+
+ADD_EXECUTABLE(${TARGET_APPID2PID} ${CMAKE_CURRENT_SOURCE_DIR}/appid2pid.c)
+SET_TARGET_PROPERTIES(${TARGET_APPID2PID} PROPERTIES COMPILE_FLAGS ${CFLAGS} "-fPIE")
+SET_TARGET_PROPERTIES(${TARGET_APPID2PID} PROPERTIES LINK_FLAGS "-pie")
+TARGET_LINK_LIBRARIES(${TARGET_APPID2PID} PRIVATE ${TARGET_AUL})
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_APPID2PID} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../src)
+TARGET_INCLUDE_DIRECTORIES(${TARGET_APPID2PID} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../include)
+
+INSTALL(TARGETS ${TARGET_APPID2PID} DESTINATION bin)
--- /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.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "aul.h"
+
+struct app_info {
+ char *appid;
+ int pid;
+};
+
+static int __all_running_app_info(const aul_app_info *info, void *data)
+{
+ struct app_info *appinfo = (struct app_info *)data;
+
+ if (appinfo == NULL || appinfo->appid == NULL)
+ return -1;
+
+ if (info == NULL || info->appid == NULL)
+ return -1;
+
+ if (strcmp(info->appid, appinfo->appid) == 0)
+ appinfo->pid = info->pid;
+
+ return 0;
+}
+
+int main(int argc, char **argv)
+{
+ struct app_info info;
+
+ if (argc < 2) {
+ printf("[usage] %s <appid>\n", argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ info.appid = argv[1];
+ info.pid = -1;
+
+ aul_app_get_all_running_app_info(__all_running_app_info, &info);
+
+ printf("%d\n", info.pid);
+
+ return 0;
+}
+++ /dev/null
-/*
- * Copyright (c) 2000 - 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.
- */
-
-#include <poll.h>
-#include <stdio.h>
-#include <sys/time.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <glib.h>
-
-#include <bundle_internal.h>
-
-#include "menu_db_util.h"
-#include "aul.h"
-
-#define MAX_LOCAL_BUFSZ 128
-#define QUERY_LEN 10240
-
-static char **gargv;
-static int gargc;
-static char *cmd;
-static int apn_pid;
-static GMainLoop *mainloop = NULL;
-static status_listen_h listen_handle;
-
-typedef struct _test_func_t {
- char *name;
- int (*func) ();
- char *desc;
- char *usage;
-} test_func_t;
-
-static bundle *create_internal_bundle(int start)
-{
- bundle *kb;
- int i;
-
- kb = bundle_create();
- for (i = start; i < gargc - 1; i++) {
- if ((i + 1) > gargc - 1)
- bundle_add(kb, gargv[i], " ");
- else
- bundle_add(kb, gargv[i], gargv[i + 1]);
- }
-
- return kb;
-}
-
-int launch_test()
-{
- static int num = 0;
- int ret = 0;
- bundle *kb = NULL;
-
- kb = create_internal_bundle(3);
- if (kb == NULL)
- return -1;
-
- printf("[aul_launch_app %d test] %s \n", num++, gargv[2]);
-
- ret = aul_launch_app(gargv[2], kb);
-
- if (kb) {
- bundle_free(kb);
- kb = NULL;
- }
- return ret;
-}
-
-int launch_test_for_uid()
-{
- static int num = 0;
- int ret = 0;
- bundle *kb = NULL;
-
- kb = create_internal_bundle(3);
- if (kb == NULL)
- return -1;
-
- printf("[aul_launch_app %d test] %s \n", num++, gargv[2]);
-
- ret = aul_launch_app_for_uid(gargv[2], kb, atoi(gargv[3]));
-
- if (kb) {
- bundle_free(kb);
- kb = NULL;
- }
- return ret;
-}
-
-int dbus_launch_test()
-{
- bundle *kb = NULL;
- int ret = 0;
-
- kb = create_internal_bundle(3);
-
- if (kb == NULL)
- return -1;
-
- ret = aul_launch_app(gargv[2], kb);
-
- if (kb) {
- bundle_free(kb);
- kb = NULL;
- }
-
- return ret;
-}
-
-int open_test()
-{
- static int num = 0;
-
- printf("[aul_open_app %d test] %s \n", num++, gargv[2]);
- return aul_open_app(gargv[2]);
-}
-
-int resume_test()
-{
- static int num = 0;
-
- printf("[aul_open_app %d test] %s \n", num++, gargv[2]);
- return aul_resume_app(gargv[2]);
-}
-
-int resume_pid_test()
-{
- static int num = 0;
- printf("[aul_resume_pid %d test] %d \n", num++, apn_pid);
- return aul_resume_pid(apn_pid);
-}
-
-int term_pid_test()
-{
- static int num = 0;
- printf("[aul_term_pid %d test] %d \n", num++, apn_pid);
- return aul_terminate_pid(apn_pid);
-}
-
-int term_req_pid_test()
-{
- static int num = 0;
- printf("[aul_subapp_terminate_request_pid %d test] %d \n", num++, apn_pid);
- return aul_subapp_terminate_request_pid(apn_pid);
-}
-
-int term_pid_without_restart_test(void)
-{
- static int num = 0;
- printf("[aul_term_pid_without_restart %d test] %d \n", num++, apn_pid);
- return aul_terminate_pid_without_restart(apn_pid);
-}
-
-int term_bgapp_pid_test(void)
-{
- static int num = 0;
- printf("[aul_term_pid_without_restart %d test] %d \n", num++, apn_pid);
- return aul_terminate_bgapp_pid(apn_pid);
-}
-
-int pause_test(void)
-{
- 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(void)
-{
- 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", ""},
- {"n", resume_test, "open_test", ""},
- {"n", resume_test, "open_test", ""},
- {"p", resume_pid_test, "resume_pid_test", ""},
- {"p", resume_pid_test, "resume_pid_test", ""},
- {"p", term_pid_test, "term_pid_test", ""},
- {"n", resume_test, "open_test", ""},
- {"n", launch_test, "launch_test", ""}
-};
-
-int all_test()
-{
- static int pos = 0;
- int ret;
-
- if (pos > sizeof(scn_func) / sizeof(test_func_t) - 1) {
- printf("all internal test done\n");
- return 0;
- }
-
- if (strncmp(scn_func[pos].name, "n", 1) == 0) {
- printf("[test %d] %s , pkgname = %s\n", pos, scn_func[pos].desc,
- gargv[2]);
- apn_pid = scn_func[pos].func();
- printf("... return pid = %d\n", apn_pid);
- } else {
- printf("[test %d] %s , pid = %d\n", pos, scn_func[pos].desc,
- apn_pid);
- ret = scn_func[pos].func();
- printf("... return res = %d\n", ret);
- }
- pos++;
-
- return 0;
-}
-
-int is_run_test()
-{
- if (aul_app_is_running(gargv[2]))
- printf("... %s is running\n", gargv[2]);
- else
- printf("... %s is not running\n", gargv[2]);
-
- return 0;
-}
-
-int iterfunc(const aul_app_info *info, void *data)
-{
- printf("\t==========================\n");
- printf("\t appid: %s\n", info->appid);
- printf("\t app_path: %s\n", info->app_path);
- printf("\t running pid: %d\n", info->pid);
- printf("\t==========================\n");
-
- return 0;
-}
-
-int get_allpkg_test()
-{
- static int num = 0;
- printf("[aul_app_get_ruuning_app_info %d test] \n", num++);
- return aul_app_get_running_app_info(iterfunc, NULL);
-}
-
-int iterfunc_status(const aul_app_info *info, void *data)
-{
- printf("\t==========================\n");
- printf("\t pid: %d\n", info->pid);
- printf("\t appid: %s\n", info->appid);
- printf("\t app_path: %s\n", info->app_path);
- printf("\t pkgid: %s\n", info->pkgid);
- printf("\t status: %d\n", info->status);
- printf("\t is_sub_app : %d\n", info->is_sub_app);
- printf("\t==========================\n");
-
- return 0;
-}
-
-int get_all_app_test()
-{
- static int num = 0;
- printf("[aul_app_get_all_running_app_info %d test] \n", num++);
- return aul_app_get_all_running_app_info(iterfunc_status, NULL);
-}
-int get_app_bypid_test()
-{
- int pid = 0;
- static int num = 0;
- char buf[MAX_LOCAL_BUFSZ];
-
- printf("[aul_app_get_appid_bypid %d test] \n", num++);
- pid = atoi(gargv[2]);
-
- if (aul_app_get_appid_bypid(pid, buf, sizeof(buf)) < 0)
- printf("no such pkg by %d\n", pid);
- else
- printf("pkgname = %s, pid = %d\n", buf, pid);
-
- return 0;
-}
-
-int get_pkg_bypid_test()
-{
- int pid = 0;
- static int num = 0;
- char buf[MAX_LOCAL_BUFSZ];
-
- printf("[aul_app_get_pkgid_bypid %d test] \n", num++);
- pid = atoi(gargv[2]);
-
- if (aul_app_get_pkgid_bypid(pid, buf, sizeof(buf)) < 0)
- printf("no such pkg by %d\n", pid);
- else
- printf("pkgname = %s, pid = %d\n", buf, pid);
-
- return 0;
-}
-
-int open_file_test()
-{
- static int num = 0;
- printf("[aul_open_file %d test] %s \n", num++, gargv[2]);
- return aul_open_file(gargv[2]);
-}
-
-int open_content_test()
-{
- static int num = 0;
- printf("[aul_open_content %d test] %s \n", num++, gargv[2]);
- return aul_open_content(gargv[2]);
-}
-
-int get_defapp_test()
-{
- static int num = 0;
- int ret;
- char buf[MAX_LOCAL_BUFSZ];
- printf("[aul_get_defapp_from_mime %d test] %s \n", num++, gargv[2]);
- ret = aul_get_defapp_from_mime(gargv[2], buf, sizeof(buf));
- if (ret >= 0)
- printf("==> defapp name = %s\n", buf);
- return ret;
-}
-
-int set_defapp_test()
-{
- static int num = 0;
- int ret;
- printf("[aul_set_defapp_with_mime %d test] %s %s\n", num++, gargv[2],
- gargv[3]);
- ret = aul_set_defapp_with_mime(gargv[2], gargv[3]);
- return ret;
-}
-
-int get_mime_file_test()
-{
- static int num = 0;
- int ret;
- char buf[MAX_LOCAL_BUFSZ];
- printf("[aul_get_mime_from_file %d test] %s \n", num++, gargv[2]);
- ret = aul_get_mime_from_file(gargv[2], buf, sizeof(buf));
- if (ret >= 0)
- printf("==> mime type = %s\n", buf);
- return ret;
-}
-
-int get_mime_content_test()
-{
- static int num = 0;
- int ret;
- char buf[MAX_LOCAL_BUFSZ];
- printf("[aul_get_mime_from_content %d test] %s \n", num++, gargv[2]);
- ret = aul_get_mime_from_content(gargv[2], buf, sizeof(buf));
- if (ret >= 0)
- printf("==> mime type = %s\n", buf);
- return ret;
-}
-
-int aul_get_mime_icon_test()
-{
- int ret;
- char buf[MAX_LOCAL_BUFSZ];
- ret = aul_get_mime_icon(gargv[2], buf, sizeof(buf));
- if (ret >= 0)
- printf("==> mimetype %s : iconname = %s\n", gargv[2], buf);
- return ret;
-}
-
-int aul_get_mime_description_test()
-{
- int ret;
- char buf[MAX_LOCAL_BUFSZ];
- ret = aul_get_mime_description(gargv[2], buf, sizeof(buf));
- if (ret >= 0)
- printf("==> mimetype %s : description = %s\n", gargv[2], buf);
- return ret;
-}
-
-int aul_get_mime_extension_test()
-{
- int ret;
- char buf[MAX_LOCAL_BUFSZ];
- ret = aul_get_mime_extension(gargv[2], buf, sizeof(buf));
- if (ret >= 0)
- printf("==> mimetype %s : extension = %s\n", gargv[2], buf);
- return ret;
-}
-
-static void print_menu_db_info(const app_info_from_db *info)
-{
- if (info == NULL) {
- printf("pkg %s no found\n", gargv[2]);
- return;
- }
-
- printf("\t==========================\n");
- printf("\t appid: %s\n", info->appid);
- printf("\t app_path: %s\n", info->app_path);
- printf("\t is_minst: %d\n", 0);
- printf("\t==========================\n");
-}
-
-static int get_pkg_func()
-{
- app_info_from_db *info;
-
- info = _get_app_info_from_db_by_pkgname(gargv[2]);
- print_menu_db_info(info);
- if (info)
- _free_app_info_from_db(info);
-
- return 0;
-}
-
-static char *status_text[] = {
- "STATUS_LAUNCHING",
- "STATUS_CREATED",
- "STATUS_FOCUS",
- "STATUS_VISIBLE",
- "STATUS_BG",
- "STATUS_DYING",
- "STATUS_HOME",
- "STATUS_NORESTART",
- "STATUS_SERVICE",
-};
-
-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_pid()
-{
- static int num = 0;
-
- printf("[aul_app_get_pid %d test] %s \n", num++, gargv[2]);
- return aul_app_get_pid(gargv[2]);;
-}
-
-static int update_running_list()
-{
- aul_running_list_update(gargv[2], gargv[3], gargv[4]);
-
- return 0;
-}
-
-static int launch_async_test()
-{
- static int num = 0;
- int ret = 0;
- bundle *kb = NULL;
-
- kb = create_internal_bundle(3);
- if (kb == NULL)
- return -1;
-
- printf("[aul_launch_app_async %d test] %s \n", num++, gargv[2]);
-
- ret = aul_launch_app_async(gargv[2], kb);
-
- if (kb) {
- bundle_free(kb);
- kb = NULL;
- }
- return ret;
-}
-
-static int launch_async_test_for_uid()
-{
- static int num = 0;
- int ret = 0;
- bundle *kb = NULL;
-
- kb = create_internal_bundle(3);
- if (kb == NULL)
- return -1;
-
- printf("[aul_launch_app_async_for_uid %d test] %s \n", num++, gargv[2]);
-
- ret = aul_launch_app_async_for_uid(gargv[2], kb, atoi(gargv[3]));
-
- if (kb) {
- bundle_free(kb);
- kb = NULL;
- }
- return ret;
-}
-
-static int open_test_for_uid()
-{
- static int num = 0;
-
- printf("[aul_open_app_for_uid %d test] %s \n", num++, gargv[2]);
- return aul_open_app_for_uid(gargv[2], atoi(gargv[3]));
-}
-
-static int resume_test_for_uid()
-{
- static int num = 0;
-
- printf("[aul_resume_app_for_uid %d test] %s \n", num++, gargv[2]);
- return aul_resume_app_for_uid(gargv[2], atoi(gargv[3]));
-}
-
-static int resume_pid_test_for_uid()
-{
- static int num = 0;
-
- printf("[aul_resume_pid_for_uid %d test] %d \n", num++, apn_pid);
- return aul_resume_pid_for_uid(apn_pid, atoi(gargv[3]));
-}
-
-static int term_pid_test_for_uid()
-{
- static int num = 0;
-
- printf("[aul_terminate_pid_for_uid %d test] %d \n", num++, apn_pid);
- return aul_terminate_pid_for_uid(apn_pid, atoi(gargv[3]));
-}
-
-static int term_pid_async_test_for_uid()
-{
- static int num = 0;
-
- printf("[aul_terminate_pid_async_for_uid %d test] %d \n", num++, apn_pid);
- return aul_terminate_pid_async_for_uid(apn_pid, atoi(gargv[3]));
-}
-
-static int get_allpkg_test_for_uid()
-{
- static int num = 0;
-
- printf("[aul_app_get_running_app_info_for_uid %d test] \n", num++);
- return aul_app_get_running_app_info_for_uid(iterfunc, NULL, atoi(gargv[3]));
-}
-
-static int get_all_app_test_for_uid()
-{
- static int num = 0;
-
- printf("[aul_app_get_all_running_app_info_for_uid %d test] \n", num++);
- return aul_app_get_all_running_app_info_for_uid(iterfunc_status, NULL, atoi(gargv[2]));
-}
-
-static int get_status_pid_for_uid()
-{
- int ret;
-
- ret = aul_app_get_status_bypid_for_uid(apn_pid, atoi(gargv[3]));
-
- printf("pid: %d uid: %d status: %d", apn_pid, atoi(gargv[3]), ret);
- if (ret >= STATUS_LAUNCHING && ret <= STATUS_NORESTART)
- printf("(%s)", status_text[ret]);
- printf("\n");
-
- return 0;
-}
-
-static int get_pid_for_uid()
-{
- static int num = 0;
-
- printf("[aul_app_get_pid_for_uid %d test] %s \n", num++, gargv[2]);
- return aul_app_get_pid_for_uid(gargv[2], atoi(gargv[3]));
-}
-
-static int pause_test_for_uid()
-{
- static int num = 0;
-
- printf("[aul_pause_app_for_uid %d test] %s \n", num++, gargv[2]);
- return aul_pause_app_for_uid(gargv[2], atoi(gargv[3]));
-}
-
-static int pause_pid_test_for_uid()
-{
- static int num = 0;
-
- printf("[aul_pause_pid_for_uid %d test] %d \n", num++, apn_pid);
- return aul_pause_pid_for_uid(apn_pid, atoi(gargv[3]));
-}
-
-static int term_pid_sync_test()
-{
- static int num = 0;
-
- printf("[aul_terminate_pid_sync %d test] %d \n", num++, apn_pid);
- return aul_terminate_pid_sync(apn_pid);
-}
-
-static int term_pid_sync_test_for_uid()
-{
- static int num = 0;
-
- printf("[aul_terminate_pid_sync_for_uid %d test] %d \n", num++, apn_pid);
- return aul_terminate_pid_sync_for_uid(apn_pid, atoi(gargv[3]));
-}
-
-static int get_status_test(void)
-{
- static int num;
- int ret;
-
- printf("[aul_app_get_status %d test] %s \n", num++, gargv[2]);
-
- ret = aul_app_get_status(gargv[2]);
- printf("appid: %s, status: %d", gargv[2], ret);
- if (ret >= STATUS_LAUNCHING && ret <= STATUS_NORESTART)
- printf("(%s)", status_text[ret]);
- printf("\n");
-
- return 0;
-}
-
-static int get_status_test_for_uid(void)
-{
- static int num;
- int ret;
-
- printf("[aul_app_get_status %d test] %s \n", num++, gargv[2]);
-
- ret = aul_app_get_status_for_uid(gargv[2], atoi(gargv[3]));
- printf("appid: %s, uid: %d, status: %d", gargv[2], atoi(gargv[3]), ret);
- if (ret >= STATUS_LAUNCHING && ret <= STATUS_NORESTART)
- printf("(%s)", status_text[ret]);
- printf("\n");
-
- return 0;
-}
-
-static int get_last_caller_pid_test(void)
-{
- static int num;
-
- printf("[aul_app_get_last_caller_pid %d test] %d \n", num++, apn_pid);
- return aul_app_get_last_caller_pid(apn_pid);
-}
-
-static int get_last_caller_pid_test_for_uid(void)
-{
- static int num;
-
- printf("[aul_app_get_last_caller_pid_for_uid %d test] %d \n", num++, apn_pid);
- return aul_app_get_last_caller_pid_for_uid(apn_pid, atoi(gargv[3]));
-}
-
-static int resume_pid_async_test(void)
-{
- static int num;
-
- printf("aul_resume_pid_async %d test] %d \n", num++, apn_pid);
- return aul_resume_pid_async(apn_pid);
-}
-
-static int resume_pid_async_test_for_uid(void)
-{
- static int num;
-
- printf("aul_resume_pid_async_for_uid %d test] %d \n", num++, apn_pid);
- return aul_resume_pid_async_for_uid(apn_pid, atoi(gargv[3]));
-}
-
-static int app_status_handler(aul_app_info *info, int ctx_status, void *data)
-{
- printf("aul_listen_app_status: %s status: %d\n", info->appid, ctx_status);
- return 0;
-}
-
-static int listen_app_status(void)
-{
- static int num;
-
- printf("aul_listen_app_status %d test] %s \n", num++, gargv[2]);
- return aul_listen_app_status(gargv[2], app_status_handler, NULL, &listen_handle);
-}
-
-static int listen_app_status_for_uid_test(void)
-{
- static int num;
-
- printf("aul_listen_app_status %d test] %s \n", num++, gargv[2]);
- return aul_listen_app_status_for_uid(gargv[2], app_status_handler, NULL, &listen_handle, apn_pid);
-}
-
-static int test_regex()
-{
- char *token;
- char mime[MAX_LOCAL_BUFSZ];
- char *saveptr;
-
- printf("=======================\n");
-
- token = strtok_r(gargv[2], " \t\n,.()", &saveptr);
- if (aul_get_mime_from_content(token, mime, sizeof(mime)) == AUL_R_OK)
- printf("found %s %s\n", mime, token);
-
- while (token) {
- token = strtok_r(NULL, " \t\n,()", &saveptr);
- if (aul_get_mime_from_content(token, mime, sizeof(mime)) ==
- AUL_R_OK)
- printf("found %s %s\n", mime, token);
- }
-
- return 0;
-}
-
-int reload_appinfo(void)
-{
- return aul_reload_appinfo();
-}
-
-static test_func_t test_func[] = {
- {"launch", launch_test, "aul_launch_app test",
- "[usage] launch <pkgname> <key1> <val1> <key2> <val2> ..."},
- {"launch_for_uid", launch_test_for_uid,
- "launch with uid test", "[usage] launch_for_uid <appid> <uid>"},
- {"open", open_test, "aul_open_app test",
- "[usage] open <pkgname>" },
- {"resume", resume_test, "aul_resume_app test",
- "[usage] resume <pkgname>" },
- {"resume_pid", resume_pid_test, "aul_resume_pid test",
- "[usage] resume_pid <pid>" },
- {"term_pid", term_pid_test, "aul_terminate_pid test",
- "[usage] term_pid <pid>" },
- {"term_req_pid", term_req_pid_test, "aul_subapp_terminate_request_pid test",
- "[usage] term_req_pid <pid>" },
- {"term_pid_without_restart", term_pid_without_restart_test, "aul_terminate_pid_without_restart test",
- "[usage] term_pid_without_restart <pid>" },
- {"term_bgapp", term_bgapp_pid_test, "aul_terminate_bgapp_pid test",
- "[usage] term_bgapp <pid>" },
- {"dbuslaunch", dbus_launch_test, "launch by dbus auto activation",
- "[usage] term_pid <pid>" },
- {"all", all_test, "test based on predefine scenario",
- "[usage] all <pkgname>"},
- {"is_run", is_run_test, "aul_is_running test",
- "[usage] is_run <pkgname>"},
- {"getallpkg", get_allpkg_test, "aul_app_get_running_app_info test",
- "[usage] getallpkg all"},
- {"getallappstatus", get_all_app_test, "aul_app_get_all_running_app_info test",
- "[usage] getallappstatus "},
- {"get_app_bypid", get_app_bypid_test, "aul_app_get_appid_bypid test",
- "[usage] get_app_bypid <pid>"},
- {"get_pkg_bypid", get_pkg_bypid_test, "aul_app_get_pkgid_bypid test",
- "[usage] get_pkg_bypid <pid>"},
- {"open_file", open_file_test, "aul_open_file test",
- "[usage] open_file <filename>"},
- {"open_content", open_content_test, "aul_open_content test",
- "[usage] open_content <content>"},
- {"get_defapp_mime", get_defapp_test, "aul_get_defapp_from_mime test",
- "[usage] get_defapp_mime <mime_type>"},
- {"set_defapp_mime", set_defapp_test, "aul_set_defapp_with_mime test",
- "[usage] set_defapp_mime <mime_type> <defapp to be set>"},
- {"get_mime_file", get_mime_file_test, "aul_get_mime_from_file test",
- "[usage] get_mime_file <filename>"},
- {"get_mime_content", get_mime_content_test, "aul_get_mime_from_content",
- "[usage] get_mime_content <content>"},
- {"get_mime_icon", aul_get_mime_icon_test, "aul_get_mime_icon test",
- "[usage] get_mime_icon <mimetype>"},
- {"get_mime_desc", aul_get_mime_description_test, "aul_get_mime_description test",
- "[usage] get_mime_desc <mimetype>"},
- {"get_mime_ext", aul_get_mime_extension_test, "aul_get_mime_extension test",
- "[usage] get_mime_ext <mimetype>"},
- {"test_regex", test_regex, "regular expression parser test",
- "[usage] test_regex <full text>"},
- {"getpkg", get_pkg_func, "get package",
- "[usage] getpkg <pkgname>"},
- {"pause", pause_test, "aul_pause_app test",
- "[usage] pause <pkgname>" },
- {"pause_pid", pause_pid_test, "aul_pause_pid test",
- "[usage] pause_pid <pid>" },
- {"update_list", update_running_list, "update running list",
- "[usage] update_list <appid> <app_path> <pid>"},
- {"reload", reload_appinfo, "reload appinfo table",
- "[usage] reload"},
- {"get_status_pid", get_status_pid, "aul_app_get_status_bypid test",
- "[usage] get_status_pid <pid>"},
- {"get_pid", get_pid, "aul_app_get_pid test",
- "[usage] get_pid <appid>"},
- {"launch_async", launch_async_test, "aul_launch_app_async test",
- "[usage] launch_async <appid> <key1> <val1> <key2> <val2> ..."},
- {"launch_async_for_uid", launch_async_test_for_uid, "aul_launch_app_async_for_uid test",
- "[usage] launch_async_for_uid <appid> <uid> <key1> <val1> <key2> <val2> ..."},
- {"open_for_uid", open_test_for_uid, "aul_open_app_for_uid test",
- "[usage] open_for_uid <appid> <uid>"},
- {"resume_for_uid", resume_test_for_uid, "aul_resume_app_for_uid test",
- "[usage] resume_for_uid <appid> <uid>"},
- {"resume_pid_for_uid", resume_pid_test_for_uid, "aul_resume_pid_for_uid test",
- "[usage] resume_pid_for_uid <pid> <uid>"},
- {"term_pid_for_uid", term_pid_test_for_uid, "aul_terminate_pid_for_uid test",
- "[usage] term_pid_for_uid <pid> <uid>"},
- {"term_pid_async_for_uid", term_pid_async_test_for_uid, "aul_terminate_pid_async_for_uid test",
- "[usage] term_pid_async_for_uid <pid> <uid>"},
- {"getallpkg_for_uid", get_allpkg_test_for_uid, "aul_app_get_running_app_info_for_uid test",
- "[usage] getallpkg_for_uid all <uid>"},
- {"getallappstatus_for_uid", get_all_app_test_for_uid, "aul_app_get_all_running_app_info_for_uid test",
- "[usage] getallappstatus_for_uid <uid>"},
- {"get_status_pid_for_uid", get_status_pid_for_uid, "aul_app_get_status_bypid_for_uid test",
- "[usage] get_status_pid_for_uid <pid> <uid>"},
- {"get_pid_for_uid", get_pid_for_uid, "aul_app_get_pid_for_uid test",
- "[usage] get_pid_for_uid <appid> <uid>"},
- {"pause_for_uid", pause_test_for_uid, "aul_pause_app_for_uid test",
- "[usage] pasue_for_uid <appid> <uid>"},
- {"pause_pid_for_uid", pause_pid_test_for_uid, "aul_pause_pid_for_uid test",
- "[usage] pause_pid_for_uid <pid> <uid>"},
- {"term_pid_sync", term_pid_sync_test, "aul_terminate_pid_sync test",
- "[usage] term_pid_sync <pid>"},
- {"term_pid_sync_for_uid", term_pid_sync_test_for_uid, "aul_terminate_pid_sync_for_uid test",
- "[usage] term_pid_sync_for_uid <pid> <uid>"},
- {"get_status", get_status_test, "aul_app_get_status test",
- "[usage] get_status <appid>"},
- {"get_status_for_uid", get_status_test_for_uid, "aul_app_get_status_for_uid test",
- "[usage] get_status_for_uid <appid> <uid>"},
- {"get_last_caller_pid", get_last_caller_pid_test, "aul_app_get_last_caller_pid test",
- "[usage] get_last_caller_pid <pid>"},
- {"get_last_caller_pid_for_uid", get_last_caller_pid_test_for_uid, "aul_app_get_last_caller_pid_for_uid test",
- "[usage] get_last_caller_pid_for_uid <pid> <uid"},
- {"resume_pid_async", resume_pid_async_test, "aul_resume_pid_async",
- "[usage] resume_pid_async <pid>"},
- {"resume_pid_async_for_uid", resume_pid_async_test_for_uid, "aul_resume_pid_async_for_uid",
- "[usage] resume_pid_async_for_uid <pid> <uid>"},
- {"listen_app_status", listen_app_status, "aul_listen_app_status",
- "[usage] listen_app_status <appid>"},
- {"listen_app_status_for_uid", listen_app_status_for_uid_test, "aul_listen_app_status_for_uid",
- "[usage] listen_app_status_for_uid <appid> <uid>"},
-};
-
-int callfunc(char *testname)
-{
- test_func_t *tmp;
- int res;
- int i;
-
- for (i = 0; i < sizeof(test_func) / sizeof(test_func_t); i++) {
- tmp = &test_func[i];
- if (strcmp(testname, tmp->name) == 0) {
- res = tmp->func();
- if (strcmp(testname, "all")) {
- if (res < 0)
- printf("... test failed\n");
- else
- printf("... test successs ret = %d\n",
- res);
- }
- }
- }
- return 0;
-}
-
-int dead_tracker(int pid, void *data)
-{
- printf("[DEAD] pid = %d dead\n", pid);
- return 0;
-}
-
-void print_usage(char *progname)
-{
- test_func_t *tmp;
- int i;
-
- printf("[usage] %s <cmd> ...\n", progname);
- printf(" - available cmd list\n");
-
- for (i = 0; i < sizeof(test_func) / sizeof(test_func_t); i++) {
- tmp = &test_func[i];
- printf("\t%s : %s\n", tmp->name, tmp->desc);
- printf("\t\t%s\n", tmp->usage);
- }
-
- printf("[note] getpkg/setpkg/delpkg/init_defapp_mime/reload "
- "cmd is internal purpose\n");
-}
-
-static gboolean run_func(void *data)
-{
- callfunc(cmd);
-
- if (strcmp(cmd, "launch_res") == 0 || strcmp(cmd, "all") == 0
- || strcmp(cmd, "dbuslaunch") == 0
- || strcmp(cmd, "listen_app_status") == 0
- || strcmp(cmd, "open_svc_res") == 0 ||
- strcmp(cmd, "listen_app_status") == 0)
- return 0;
- else
- g_main_loop_quit(mainloop);
-
- return 0;
-}
-
-int main(int argc, char **argv)
-{
- if (argc < 2) {
- print_usage(argv[0]);
- exit(0);
- }
-
- cmd = argv[1];
- gargc = argc;
- gargv = argv;
- if (argv[2])
- 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); */
-
- g_idle_add(run_func, NULL);
-
- mainloop = g_main_loop_new(NULL, FALSE);
- if (!mainloop) {
- printf("failed to create glib main loop\n");
- exit(EXIT_FAILURE);
- }
- g_main_loop_run(mainloop);
- g_main_loop_unref(mainloop);
-
- if (listen_handle)
- aul_ignore_app_status(listen_handle);
-
- return 0;
-}
-
-/* vi: set ts=8 sts=8 sw=8: */
-
--- /dev/null
+SET(TARGET_AUL_TEST "aul_test")
+
+ADD_EXECUTABLE(${TARGET_AUL_TEST} ${CMAKE_CURRENT_SOURCE_DIR}/aul_test.c)
+SET_TARGET_PROPERTIES(${TARGET_AUL_TEST} PROPERTIES COMPILE_FLAGS ${CFLAGS} "-fPIE")
+SET_TARGET_PROPERTIES(${TARGET_AUL_TEST} PROPERTIES LINK_FLAGS "-pie")
+TARGET_LINK_LIBRARIES(${TARGET_AUL_TEST} PRIVATE ${TARGET_AUL})
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_AUL_TEST} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../src)
+TARGET_INCLUDE_DIRECTORIES(${TARGET_AUL_TEST} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../include)
+
+INSTALL(TARGETS ${TARGET_AUL_TEST} DESTINATION bin)
--- /dev/null
+/*
+ * Copyright (c) 2000 - 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.
+ */
+
+#include <poll.h>
+#include <stdio.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <glib.h>
+
+#include <bundle_internal.h>
+
+#include "menu_db_util.h"
+#include "aul.h"
+
+#define MAX_LOCAL_BUFSZ 128
+#define QUERY_LEN 10240
+
+static char **gargv;
+static int gargc;
+static char *cmd;
+static int apn_pid;
+static GMainLoop *mainloop = NULL;
+static status_listen_h listen_handle;
+
+typedef struct _test_func_t {
+ char *name;
+ int (*func) ();
+ char *desc;
+ char *usage;
+} test_func_t;
+
+static bundle *create_internal_bundle(int start)
+{
+ bundle *kb;
+ int i;
+
+ kb = bundle_create();
+ for (i = start; i < gargc - 1; i++) {
+ if ((i + 1) > gargc - 1)
+ bundle_add(kb, gargv[i], " ");
+ else
+ bundle_add(kb, gargv[i], gargv[i + 1]);
+ }
+
+ return kb;
+}
+
+int launch_test()
+{
+ static int num = 0;
+ int ret = 0;
+ bundle *kb = NULL;
+
+ kb = create_internal_bundle(3);
+ if (kb == NULL)
+ return -1;
+
+ printf("[aul_launch_app %d test] %s \n", num++, gargv[2]);
+
+ ret = aul_launch_app(gargv[2], kb);
+
+ if (kb) {
+ bundle_free(kb);
+ kb = NULL;
+ }
+ return ret;
+}
+
+int launch_test_for_uid()
+{
+ static int num = 0;
+ int ret = 0;
+ bundle *kb = NULL;
+
+ kb = create_internal_bundle(3);
+ if (kb == NULL)
+ return -1;
+
+ printf("[aul_launch_app %d test] %s \n", num++, gargv[2]);
+
+ ret = aul_launch_app_for_uid(gargv[2], kb, atoi(gargv[3]));
+
+ if (kb) {
+ bundle_free(kb);
+ kb = NULL;
+ }
+ return ret;
+}
+
+int dbus_launch_test()
+{
+ bundle *kb = NULL;
+ int ret = 0;
+
+ kb = create_internal_bundle(3);
+
+ if (kb == NULL)
+ return -1;
+
+ ret = aul_launch_app(gargv[2], kb);
+
+ if (kb) {
+ bundle_free(kb);
+ kb = NULL;
+ }
+
+ return ret;
+}
+
+int open_test()
+{
+ static int num = 0;
+
+ printf("[aul_open_app %d test] %s \n", num++, gargv[2]);
+ return aul_open_app(gargv[2]);
+}
+
+int resume_test()
+{
+ static int num = 0;
+
+ printf("[aul_open_app %d test] %s \n", num++, gargv[2]);
+ return aul_resume_app(gargv[2]);
+}
+
+int resume_pid_test()
+{
+ static int num = 0;
+ printf("[aul_resume_pid %d test] %d \n", num++, apn_pid);
+ return aul_resume_pid(apn_pid);
+}
+
+int term_pid_test()
+{
+ static int num = 0;
+ printf("[aul_term_pid %d test] %d \n", num++, apn_pid);
+ return aul_terminate_pid(apn_pid);
+}
+
+int term_req_pid_test()
+{
+ static int num = 0;
+ printf("[aul_subapp_terminate_request_pid %d test] %d \n", num++, apn_pid);
+ return aul_subapp_terminate_request_pid(apn_pid);
+}
+
+int term_pid_without_restart_test(void)
+{
+ static int num = 0;
+ printf("[aul_term_pid_without_restart %d test] %d \n", num++, apn_pid);
+ return aul_terminate_pid_without_restart(apn_pid);
+}
+
+int term_bgapp_pid_test(void)
+{
+ static int num = 0;
+ printf("[aul_term_pid_without_restart %d test] %d \n", num++, apn_pid);
+ return aul_terminate_bgapp_pid(apn_pid);
+}
+
+int pause_test(void)
+{
+ 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(void)
+{
+ 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", ""},
+ {"n", resume_test, "open_test", ""},
+ {"n", resume_test, "open_test", ""},
+ {"p", resume_pid_test, "resume_pid_test", ""},
+ {"p", resume_pid_test, "resume_pid_test", ""},
+ {"p", term_pid_test, "term_pid_test", ""},
+ {"n", resume_test, "open_test", ""},
+ {"n", launch_test, "launch_test", ""}
+};
+
+int all_test()
+{
+ static int pos = 0;
+ int ret;
+
+ if (pos > sizeof(scn_func) / sizeof(test_func_t) - 1) {
+ printf("all internal test done\n");
+ return 0;
+ }
+
+ if (strncmp(scn_func[pos].name, "n", 1) == 0) {
+ printf("[test %d] %s , pkgname = %s\n", pos, scn_func[pos].desc,
+ gargv[2]);
+ apn_pid = scn_func[pos].func();
+ printf("... return pid = %d\n", apn_pid);
+ } else {
+ printf("[test %d] %s , pid = %d\n", pos, scn_func[pos].desc,
+ apn_pid);
+ ret = scn_func[pos].func();
+ printf("... return res = %d\n", ret);
+ }
+ pos++;
+
+ return 0;
+}
+
+int is_run_test()
+{
+ if (aul_app_is_running(gargv[2]))
+ printf("... %s is running\n", gargv[2]);
+ else
+ printf("... %s is not running\n", gargv[2]);
+
+ return 0;
+}
+
+int iterfunc(const aul_app_info *info, void *data)
+{
+ printf("\t==========================\n");
+ printf("\t appid: %s\n", info->appid);
+ printf("\t app_path: %s\n", info->app_path);
+ printf("\t running pid: %d\n", info->pid);
+ printf("\t==========================\n");
+
+ return 0;
+}
+
+int get_allpkg_test()
+{
+ static int num = 0;
+ printf("[aul_app_get_ruuning_app_info %d test] \n", num++);
+ return aul_app_get_running_app_info(iterfunc, NULL);
+}
+
+int iterfunc_status(const aul_app_info *info, void *data)
+{
+ printf("\t==========================\n");
+ printf("\t pid: %d\n", info->pid);
+ printf("\t appid: %s\n", info->appid);
+ printf("\t app_path: %s\n", info->app_path);
+ printf("\t pkgid: %s\n", info->pkgid);
+ printf("\t status: %d\n", info->status);
+ printf("\t is_sub_app : %d\n", info->is_sub_app);
+ printf("\t==========================\n");
+
+ return 0;
+}
+
+int get_all_app_test()
+{
+ static int num = 0;
+ printf("[aul_app_get_all_running_app_info %d test] \n", num++);
+ return aul_app_get_all_running_app_info(iterfunc_status, NULL);
+}
+int get_app_bypid_test()
+{
+ int pid = 0;
+ static int num = 0;
+ char buf[MAX_LOCAL_BUFSZ];
+
+ printf("[aul_app_get_appid_bypid %d test] \n", num++);
+ pid = atoi(gargv[2]);
+
+ if (aul_app_get_appid_bypid(pid, buf, sizeof(buf)) < 0)
+ printf("no such pkg by %d\n", pid);
+ else
+ printf("pkgname = %s, pid = %d\n", buf, pid);
+
+ return 0;
+}
+
+int get_pkg_bypid_test()
+{
+ int pid = 0;
+ static int num = 0;
+ char buf[MAX_LOCAL_BUFSZ];
+
+ printf("[aul_app_get_pkgid_bypid %d test] \n", num++);
+ pid = atoi(gargv[2]);
+
+ if (aul_app_get_pkgid_bypid(pid, buf, sizeof(buf)) < 0)
+ printf("no such pkg by %d\n", pid);
+ else
+ printf("pkgname = %s, pid = %d\n", buf, pid);
+
+ return 0;
+}
+
+int open_file_test()
+{
+ static int num = 0;
+ printf("[aul_open_file %d test] %s \n", num++, gargv[2]);
+ return aul_open_file(gargv[2]);
+}
+
+int open_content_test()
+{
+ static int num = 0;
+ printf("[aul_open_content %d test] %s \n", num++, gargv[2]);
+ return aul_open_content(gargv[2]);
+}
+
+int get_defapp_test()
+{
+ static int num = 0;
+ int ret;
+ char buf[MAX_LOCAL_BUFSZ];
+ printf("[aul_get_defapp_from_mime %d test] %s \n", num++, gargv[2]);
+ ret = aul_get_defapp_from_mime(gargv[2], buf, sizeof(buf));
+ if (ret >= 0)
+ printf("==> defapp name = %s\n", buf);
+ return ret;
+}
+
+int set_defapp_test()
+{
+ static int num = 0;
+ int ret;
+ printf("[aul_set_defapp_with_mime %d test] %s %s\n", num++, gargv[2],
+ gargv[3]);
+ ret = aul_set_defapp_with_mime(gargv[2], gargv[3]);
+ return ret;
+}
+
+int get_mime_file_test()
+{
+ static int num = 0;
+ int ret;
+ char buf[MAX_LOCAL_BUFSZ];
+ printf("[aul_get_mime_from_file %d test] %s \n", num++, gargv[2]);
+ ret = aul_get_mime_from_file(gargv[2], buf, sizeof(buf));
+ if (ret >= 0)
+ printf("==> mime type = %s\n", buf);
+ return ret;
+}
+
+int get_mime_content_test()
+{
+ static int num = 0;
+ int ret;
+ char buf[MAX_LOCAL_BUFSZ];
+ printf("[aul_get_mime_from_content %d test] %s \n", num++, gargv[2]);
+ ret = aul_get_mime_from_content(gargv[2], buf, sizeof(buf));
+ if (ret >= 0)
+ printf("==> mime type = %s\n", buf);
+ return ret;
+}
+
+int aul_get_mime_icon_test()
+{
+ int ret;
+ char buf[MAX_LOCAL_BUFSZ];
+ ret = aul_get_mime_icon(gargv[2], buf, sizeof(buf));
+ if (ret >= 0)
+ printf("==> mimetype %s : iconname = %s\n", gargv[2], buf);
+ return ret;
+}
+
+int aul_get_mime_description_test()
+{
+ int ret;
+ char buf[MAX_LOCAL_BUFSZ];
+ ret = aul_get_mime_description(gargv[2], buf, sizeof(buf));
+ if (ret >= 0)
+ printf("==> mimetype %s : description = %s\n", gargv[2], buf);
+ return ret;
+}
+
+int aul_get_mime_extension_test()
+{
+ int ret;
+ char buf[MAX_LOCAL_BUFSZ];
+ ret = aul_get_mime_extension(gargv[2], buf, sizeof(buf));
+ if (ret >= 0)
+ printf("==> mimetype %s : extension = %s\n", gargv[2], buf);
+ return ret;
+}
+
+static void print_menu_db_info(const app_info_from_db *info)
+{
+ if (info == NULL) {
+ printf("pkg %s no found\n", gargv[2]);
+ return;
+ }
+
+ printf("\t==========================\n");
+ printf("\t appid: %s\n", info->appid);
+ printf("\t app_path: %s\n", info->app_path);
+ printf("\t is_minst: %d\n", 0);
+ printf("\t==========================\n");
+}
+
+static int get_pkg_func()
+{
+ app_info_from_db *info;
+
+ info = _get_app_info_from_db_by_pkgname(gargv[2]);
+ print_menu_db_info(info);
+ if (info)
+ _free_app_info_from_db(info);
+
+ return 0;
+}
+
+static char *status_text[] = {
+ "STATUS_LAUNCHING",
+ "STATUS_CREATED",
+ "STATUS_FOCUS",
+ "STATUS_VISIBLE",
+ "STATUS_BG",
+ "STATUS_DYING",
+ "STATUS_HOME",
+ "STATUS_NORESTART",
+ "STATUS_SERVICE",
+};
+
+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_pid()
+{
+ static int num = 0;
+
+ printf("[aul_app_get_pid %d test] %s \n", num++, gargv[2]);
+ return aul_app_get_pid(gargv[2]);;
+}
+
+static int update_running_list()
+{
+ aul_running_list_update(gargv[2], gargv[3], gargv[4]);
+
+ return 0;
+}
+
+static int launch_async_test()
+{
+ static int num = 0;
+ int ret = 0;
+ bundle *kb = NULL;
+
+ kb = create_internal_bundle(3);
+ if (kb == NULL)
+ return -1;
+
+ printf("[aul_launch_app_async %d test] %s \n", num++, gargv[2]);
+
+ ret = aul_launch_app_async(gargv[2], kb);
+
+ if (kb) {
+ bundle_free(kb);
+ kb = NULL;
+ }
+ return ret;
+}
+
+static int launch_async_test_for_uid()
+{
+ static int num = 0;
+ int ret = 0;
+ bundle *kb = NULL;
+
+ kb = create_internal_bundle(3);
+ if (kb == NULL)
+ return -1;
+
+ printf("[aul_launch_app_async_for_uid %d test] %s \n", num++, gargv[2]);
+
+ ret = aul_launch_app_async_for_uid(gargv[2], kb, atoi(gargv[3]));
+
+ if (kb) {
+ bundle_free(kb);
+ kb = NULL;
+ }
+ return ret;
+}
+
+static int open_test_for_uid()
+{
+ static int num = 0;
+
+ printf("[aul_open_app_for_uid %d test] %s \n", num++, gargv[2]);
+ return aul_open_app_for_uid(gargv[2], atoi(gargv[3]));
+}
+
+static int resume_test_for_uid()
+{
+ static int num = 0;
+
+ printf("[aul_resume_app_for_uid %d test] %s \n", num++, gargv[2]);
+ return aul_resume_app_for_uid(gargv[2], atoi(gargv[3]));
+}
+
+static int resume_pid_test_for_uid()
+{
+ static int num = 0;
+
+ printf("[aul_resume_pid_for_uid %d test] %d \n", num++, apn_pid);
+ return aul_resume_pid_for_uid(apn_pid, atoi(gargv[3]));
+}
+
+static int term_pid_test_for_uid()
+{
+ static int num = 0;
+
+ printf("[aul_terminate_pid_for_uid %d test] %d \n", num++, apn_pid);
+ return aul_terminate_pid_for_uid(apn_pid, atoi(gargv[3]));
+}
+
+static int term_pid_async_test_for_uid()
+{
+ static int num = 0;
+
+ printf("[aul_terminate_pid_async_for_uid %d test] %d \n", num++, apn_pid);
+ return aul_terminate_pid_async_for_uid(apn_pid, atoi(gargv[3]));
+}
+
+static int get_allpkg_test_for_uid()
+{
+ static int num = 0;
+
+ printf("[aul_app_get_running_app_info_for_uid %d test] \n", num++);
+ return aul_app_get_running_app_info_for_uid(iterfunc, NULL, atoi(gargv[3]));
+}
+
+static int get_all_app_test_for_uid()
+{
+ static int num = 0;
+
+ printf("[aul_app_get_all_running_app_info_for_uid %d test] \n", num++);
+ return aul_app_get_all_running_app_info_for_uid(iterfunc_status, NULL, atoi(gargv[2]));
+}
+
+static int get_status_pid_for_uid()
+{
+ int ret;
+
+ ret = aul_app_get_status_bypid_for_uid(apn_pid, atoi(gargv[3]));
+
+ printf("pid: %d uid: %d status: %d", apn_pid, atoi(gargv[3]), ret);
+ if (ret >= STATUS_LAUNCHING && ret <= STATUS_NORESTART)
+ printf("(%s)", status_text[ret]);
+ printf("\n");
+
+ return 0;
+}
+
+static int get_pid_for_uid()
+{
+ static int num = 0;
+
+ printf("[aul_app_get_pid_for_uid %d test] %s \n", num++, gargv[2]);
+ return aul_app_get_pid_for_uid(gargv[2], atoi(gargv[3]));
+}
+
+static int pause_test_for_uid()
+{
+ static int num = 0;
+
+ printf("[aul_pause_app_for_uid %d test] %s \n", num++, gargv[2]);
+ return aul_pause_app_for_uid(gargv[2], atoi(gargv[3]));
+}
+
+static int pause_pid_test_for_uid()
+{
+ static int num = 0;
+
+ printf("[aul_pause_pid_for_uid %d test] %d \n", num++, apn_pid);
+ return aul_pause_pid_for_uid(apn_pid, atoi(gargv[3]));
+}
+
+static int term_pid_sync_test()
+{
+ static int num = 0;
+
+ printf("[aul_terminate_pid_sync %d test] %d \n", num++, apn_pid);
+ return aul_terminate_pid_sync(apn_pid);
+}
+
+static int term_pid_sync_test_for_uid()
+{
+ static int num = 0;
+
+ printf("[aul_terminate_pid_sync_for_uid %d test] %d \n", num++, apn_pid);
+ return aul_terminate_pid_sync_for_uid(apn_pid, atoi(gargv[3]));
+}
+
+static int get_status_test(void)
+{
+ static int num;
+ int ret;
+
+ printf("[aul_app_get_status %d test] %s \n", num++, gargv[2]);
+
+ ret = aul_app_get_status(gargv[2]);
+ printf("appid: %s, status: %d", gargv[2], ret);
+ if (ret >= STATUS_LAUNCHING && ret <= STATUS_NORESTART)
+ printf("(%s)", status_text[ret]);
+ printf("\n");
+
+ return 0;
+}
+
+static int get_status_test_for_uid(void)
+{
+ static int num;
+ int ret;
+
+ printf("[aul_app_get_status %d test] %s \n", num++, gargv[2]);
+
+ ret = aul_app_get_status_for_uid(gargv[2], atoi(gargv[3]));
+ printf("appid: %s, uid: %d, status: %d", gargv[2], atoi(gargv[3]), ret);
+ if (ret >= STATUS_LAUNCHING && ret <= STATUS_NORESTART)
+ printf("(%s)", status_text[ret]);
+ printf("\n");
+
+ return 0;
+}
+
+static int get_last_caller_pid_test(void)
+{
+ static int num;
+
+ printf("[aul_app_get_last_caller_pid %d test] %d \n", num++, apn_pid);
+ return aul_app_get_last_caller_pid(apn_pid);
+}
+
+static int get_last_caller_pid_test_for_uid(void)
+{
+ static int num;
+
+ printf("[aul_app_get_last_caller_pid_for_uid %d test] %d \n", num++, apn_pid);
+ return aul_app_get_last_caller_pid_for_uid(apn_pid, atoi(gargv[3]));
+}
+
+static int resume_pid_async_test(void)
+{
+ static int num;
+
+ printf("aul_resume_pid_async %d test] %d \n", num++, apn_pid);
+ return aul_resume_pid_async(apn_pid);
+}
+
+static int resume_pid_async_test_for_uid(void)
+{
+ static int num;
+
+ printf("aul_resume_pid_async_for_uid %d test] %d \n", num++, apn_pid);
+ return aul_resume_pid_async_for_uid(apn_pid, atoi(gargv[3]));
+}
+
+static int app_status_handler(aul_app_info *info, int ctx_status, void *data)
+{
+ printf("aul_listen_app_status: %s status: %d\n", info->appid, ctx_status);
+ return 0;
+}
+
+static int listen_app_status(void)
+{
+ static int num;
+
+ printf("aul_listen_app_status %d test] %s \n", num++, gargv[2]);
+ return aul_listen_app_status(gargv[2], app_status_handler, NULL, &listen_handle);
+}
+
+static int listen_app_status_for_uid_test(void)
+{
+ static int num;
+
+ printf("aul_listen_app_status %d test] %s \n", num++, gargv[2]);
+ return aul_listen_app_status_for_uid(gargv[2], app_status_handler, NULL, &listen_handle, apn_pid);
+}
+
+static int test_regex()
+{
+ char *token;
+ char mime[MAX_LOCAL_BUFSZ];
+ char *saveptr;
+
+ printf("=======================\n");
+
+ token = strtok_r(gargv[2], " \t\n,.()", &saveptr);
+ if (aul_get_mime_from_content(token, mime, sizeof(mime)) == AUL_R_OK)
+ printf("found %s %s\n", mime, token);
+
+ while (token) {
+ token = strtok_r(NULL, " \t\n,()", &saveptr);
+ if (aul_get_mime_from_content(token, mime, sizeof(mime)) ==
+ AUL_R_OK)
+ printf("found %s %s\n", mime, token);
+ }
+
+ return 0;
+}
+
+int reload_appinfo(void)
+{
+ return aul_reload_appinfo();
+}
+
+static test_func_t test_func[] = {
+ {"launch", launch_test, "aul_launch_app test",
+ "[usage] launch <pkgname> <key1> <val1> <key2> <val2> ..."},
+ {"launch_for_uid", launch_test_for_uid,
+ "launch with uid test", "[usage] launch_for_uid <appid> <uid>"},
+ {"open", open_test, "aul_open_app test",
+ "[usage] open <pkgname>" },
+ {"resume", resume_test, "aul_resume_app test",
+ "[usage] resume <pkgname>" },
+ {"resume_pid", resume_pid_test, "aul_resume_pid test",
+ "[usage] resume_pid <pid>" },
+ {"term_pid", term_pid_test, "aul_terminate_pid test",
+ "[usage] term_pid <pid>" },
+ {"term_req_pid", term_req_pid_test, "aul_subapp_terminate_request_pid test",
+ "[usage] term_req_pid <pid>" },
+ {"term_pid_without_restart", term_pid_without_restart_test, "aul_terminate_pid_without_restart test",
+ "[usage] term_pid_without_restart <pid>" },
+ {"term_bgapp", term_bgapp_pid_test, "aul_terminate_bgapp_pid test",
+ "[usage] term_bgapp <pid>" },
+ {"dbuslaunch", dbus_launch_test, "launch by dbus auto activation",
+ "[usage] term_pid <pid>" },
+ {"all", all_test, "test based on predefine scenario",
+ "[usage] all <pkgname>"},
+ {"is_run", is_run_test, "aul_is_running test",
+ "[usage] is_run <pkgname>"},
+ {"getallpkg", get_allpkg_test, "aul_app_get_running_app_info test",
+ "[usage] getallpkg all"},
+ {"getallappstatus", get_all_app_test, "aul_app_get_all_running_app_info test",
+ "[usage] getallappstatus "},
+ {"get_app_bypid", get_app_bypid_test, "aul_app_get_appid_bypid test",
+ "[usage] get_app_bypid <pid>"},
+ {"get_pkg_bypid", get_pkg_bypid_test, "aul_app_get_pkgid_bypid test",
+ "[usage] get_pkg_bypid <pid>"},
+ {"open_file", open_file_test, "aul_open_file test",
+ "[usage] open_file <filename>"},
+ {"open_content", open_content_test, "aul_open_content test",
+ "[usage] open_content <content>"},
+ {"get_defapp_mime", get_defapp_test, "aul_get_defapp_from_mime test",
+ "[usage] get_defapp_mime <mime_type>"},
+ {"set_defapp_mime", set_defapp_test, "aul_set_defapp_with_mime test",
+ "[usage] set_defapp_mime <mime_type> <defapp to be set>"},
+ {"get_mime_file", get_mime_file_test, "aul_get_mime_from_file test",
+ "[usage] get_mime_file <filename>"},
+ {"get_mime_content", get_mime_content_test, "aul_get_mime_from_content",
+ "[usage] get_mime_content <content>"},
+ {"get_mime_icon", aul_get_mime_icon_test, "aul_get_mime_icon test",
+ "[usage] get_mime_icon <mimetype>"},
+ {"get_mime_desc", aul_get_mime_description_test, "aul_get_mime_description test",
+ "[usage] get_mime_desc <mimetype>"},
+ {"get_mime_ext", aul_get_mime_extension_test, "aul_get_mime_extension test",
+ "[usage] get_mime_ext <mimetype>"},
+ {"test_regex", test_regex, "regular expression parser test",
+ "[usage] test_regex <full text>"},
+ {"getpkg", get_pkg_func, "get package",
+ "[usage] getpkg <pkgname>"},
+ {"pause", pause_test, "aul_pause_app test",
+ "[usage] pause <pkgname>" },
+ {"pause_pid", pause_pid_test, "aul_pause_pid test",
+ "[usage] pause_pid <pid>" },
+ {"update_list", update_running_list, "update running list",
+ "[usage] update_list <appid> <app_path> <pid>"},
+ {"reload", reload_appinfo, "reload appinfo table",
+ "[usage] reload"},
+ {"get_status_pid", get_status_pid, "aul_app_get_status_bypid test",
+ "[usage] get_status_pid <pid>"},
+ {"get_pid", get_pid, "aul_app_get_pid test",
+ "[usage] get_pid <appid>"},
+ {"launch_async", launch_async_test, "aul_launch_app_async test",
+ "[usage] launch_async <appid> <key1> <val1> <key2> <val2> ..."},
+ {"launch_async_for_uid", launch_async_test_for_uid, "aul_launch_app_async_for_uid test",
+ "[usage] launch_async_for_uid <appid> <uid> <key1> <val1> <key2> <val2> ..."},
+ {"open_for_uid", open_test_for_uid, "aul_open_app_for_uid test",
+ "[usage] open_for_uid <appid> <uid>"},
+ {"resume_for_uid", resume_test_for_uid, "aul_resume_app_for_uid test",
+ "[usage] resume_for_uid <appid> <uid>"},
+ {"resume_pid_for_uid", resume_pid_test_for_uid, "aul_resume_pid_for_uid test",
+ "[usage] resume_pid_for_uid <pid> <uid>"},
+ {"term_pid_for_uid", term_pid_test_for_uid, "aul_terminate_pid_for_uid test",
+ "[usage] term_pid_for_uid <pid> <uid>"},
+ {"term_pid_async_for_uid", term_pid_async_test_for_uid, "aul_terminate_pid_async_for_uid test",
+ "[usage] term_pid_async_for_uid <pid> <uid>"},
+ {"getallpkg_for_uid", get_allpkg_test_for_uid, "aul_app_get_running_app_info_for_uid test",
+ "[usage] getallpkg_for_uid all <uid>"},
+ {"getallappstatus_for_uid", get_all_app_test_for_uid, "aul_app_get_all_running_app_info_for_uid test",
+ "[usage] getallappstatus_for_uid <uid>"},
+ {"get_status_pid_for_uid", get_status_pid_for_uid, "aul_app_get_status_bypid_for_uid test",
+ "[usage] get_status_pid_for_uid <pid> <uid>"},
+ {"get_pid_for_uid", get_pid_for_uid, "aul_app_get_pid_for_uid test",
+ "[usage] get_pid_for_uid <appid> <uid>"},
+ {"pause_for_uid", pause_test_for_uid, "aul_pause_app_for_uid test",
+ "[usage] pasue_for_uid <appid> <uid>"},
+ {"pause_pid_for_uid", pause_pid_test_for_uid, "aul_pause_pid_for_uid test",
+ "[usage] pause_pid_for_uid <pid> <uid>"},
+ {"term_pid_sync", term_pid_sync_test, "aul_terminate_pid_sync test",
+ "[usage] term_pid_sync <pid>"},
+ {"term_pid_sync_for_uid", term_pid_sync_test_for_uid, "aul_terminate_pid_sync_for_uid test",
+ "[usage] term_pid_sync_for_uid <pid> <uid>"},
+ {"get_status", get_status_test, "aul_app_get_status test",
+ "[usage] get_status <appid>"},
+ {"get_status_for_uid", get_status_test_for_uid, "aul_app_get_status_for_uid test",
+ "[usage] get_status_for_uid <appid> <uid>"},
+ {"get_last_caller_pid", get_last_caller_pid_test, "aul_app_get_last_caller_pid test",
+ "[usage] get_last_caller_pid <pid>"},
+ {"get_last_caller_pid_for_uid", get_last_caller_pid_test_for_uid, "aul_app_get_last_caller_pid_for_uid test",
+ "[usage] get_last_caller_pid_for_uid <pid> <uid"},
+ {"resume_pid_async", resume_pid_async_test, "aul_resume_pid_async",
+ "[usage] resume_pid_async <pid>"},
+ {"resume_pid_async_for_uid", resume_pid_async_test_for_uid, "aul_resume_pid_async_for_uid",
+ "[usage] resume_pid_async_for_uid <pid> <uid>"},
+ {"listen_app_status", listen_app_status, "aul_listen_app_status",
+ "[usage] listen_app_status <appid>"},
+ {"listen_app_status_for_uid", listen_app_status_for_uid_test, "aul_listen_app_status_for_uid",
+ "[usage] listen_app_status_for_uid <appid> <uid>"},
+};
+
+int callfunc(char *testname)
+{
+ test_func_t *tmp;
+ int res;
+ int i;
+
+ for (i = 0; i < sizeof(test_func) / sizeof(test_func_t); i++) {
+ tmp = &test_func[i];
+ if (strcmp(testname, tmp->name) == 0) {
+ res = tmp->func();
+ if (strcmp(testname, "all")) {
+ if (res < 0)
+ printf("... test failed\n");
+ else
+ printf("... test successs ret = %d\n",
+ res);
+ }
+ }
+ }
+ return 0;
+}
+
+int dead_tracker(int pid, void *data)
+{
+ printf("[DEAD] pid = %d dead\n", pid);
+ return 0;
+}
+
+void print_usage(char *progname)
+{
+ test_func_t *tmp;
+ int i;
+
+ printf("[usage] %s <cmd> ...\n", progname);
+ printf(" - available cmd list\n");
+
+ for (i = 0; i < sizeof(test_func) / sizeof(test_func_t); i++) {
+ tmp = &test_func[i];
+ printf("\t%s : %s\n", tmp->name, tmp->desc);
+ printf("\t\t%s\n", tmp->usage);
+ }
+
+ printf("[note] getpkg/setpkg/delpkg/init_defapp_mime/reload "
+ "cmd is internal purpose\n");
+}
+
+static gboolean run_func(void *data)
+{
+ callfunc(cmd);
+
+ if (strcmp(cmd, "launch_res") == 0 || strcmp(cmd, "all") == 0
+ || strcmp(cmd, "dbuslaunch") == 0
+ || strcmp(cmd, "listen_app_status") == 0
+ || strcmp(cmd, "open_svc_res") == 0 ||
+ strcmp(cmd, "listen_app_status") == 0)
+ return 0;
+ else
+ g_main_loop_quit(mainloop);
+
+ return 0;
+}
+
+int main(int argc, char **argv)
+{
+ if (argc < 2) {
+ print_usage(argv[0]);
+ exit(0);
+ }
+
+ cmd = argv[1];
+ gargc = argc;
+ gargv = argv;
+ if (argv[2])
+ 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); */
+
+ g_idle_add(run_func, NULL);
+
+ mainloop = g_main_loop_new(NULL, FALSE);
+ if (!mainloop) {
+ printf("failed to create glib main loop\n");
+ exit(EXIT_FAILURE);
+ }
+ g_main_loop_run(mainloop);
+ g_main_loop_unref(mainloop);
+
+ if (listen_handle)
+ aul_ignore_app_status(listen_handle);
+
+ return 0;
+}
+
+/* vi: set ts=8 sts=8 sw=8: */
+
+++ /dev/null
-/*
- * Copyright (c) 2019 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 <stdlib.h>
-#include <string.h>
-#include <stdbool.h>
-#include <sys/types.h>
-#include <linux/limits.h>
-#include <glib.h>
-#include <gio/gio.h>
-#include <bundle_internal.h>
-#include <pkgmgr-info.h>
-
-#include "aul.h"
-#include "aul_comp_info.h"
-#include "aul_comp_context.h"
-
-enum command_e {
- CMD_LIST,
- CMD_RUNNING_LIST,
- CMD_GET,
- CMD_IS_RUNNING,
- CMD_RESUME,
- CMD_PAUSE,
- CMD_TERMINATE_BG_COMP,
- CMD_TERMINATE,
- CMD_MAX,
-};
-
-enum option_e {
- OPT_USER,
- OPT_INSTANCE,
- OPT_MAX,
-};
-
-struct command {
- const char *name;
- int (*init)(void *data);
- int (*run)(void *data);
- void (*finish)(void *data);
-};
-
-struct cmd_arg {
- char *comp_id;
- char *instance_id;
- uid_t uid;
-};
-
-static GMainLoop *loop;
-static gchar *help;
-static gpointer cmd_opt[CMD_MAX];
-static GOptionEntry cmd_entries[] = {
- {
- .long_name = "list",
- .short_name = 'l',
- .flags = 0,
- .arg = G_OPTION_ARG_NONE,
- .arg_data = &cmd_opt[CMD_LIST],
- .description = "Show installed component list",
- .arg_description = NULL
- },
- {
- .long_name = "running-list",
- .short_name = 'r',
- .flags = 0,
- .arg = G_OPTION_ARG_NONE,
- .arg_data = &cmd_opt[CMD_RUNNING_LIST],
- .description = "Show the running components information",
- .arg_description = NULL
- },
- {
- .long_name = "get",
- .short_name = 'g',
- .flags = 0,
- .arg = G_OPTION_ARG_STRING,
- .arg_data = &cmd_opt[CMD_GET],
- .description = "Show the running component information",
- .arg_description = "The component ID"
- },
- {
- .long_name = "is-running",
- .short_name = 'n',
- .flags = 0,
- .arg = G_OPTION_ARG_STRING,
- .arg_data = &cmd_opt[CMD_IS_RUNNING],
- .description = "Check whether the component is running or not",
- .arg_description = "The component ID"
- },
- {
- .long_name = "resume",
- .short_name = 'o',
- .flags = 0,
- .arg = G_OPTION_ARG_STRING,
- .arg_data = &cmd_opt[CMD_RESUME],
- .description = "Resume the running component",
- .arg_description = "The component ID"
- },
- {
- .long_name = "pause",
- .short_name = 'p',
- .flags = 0,
- .arg = G_OPTION_ARG_STRING,
- .arg_data = &cmd_opt[CMD_PAUSE],
- .description = "Pause the running component",
- .arg_description = "The component ID"
- },
- {
- .long_name = "terminate-bg-comp",
- .short_name = 'b',
- .flags = 0,
- .arg = G_OPTION_ARG_STRING,
- .arg_data = &cmd_opt[CMD_TERMINATE_BG_COMP],
- .description = "Terminate the background component",
- .arg_description = "The component ID"
- },
- {
- .long_name = "terminate",
- .short_name = 't',
- .flags = 0,
- .arg = G_OPTION_ARG_STRING,
- .arg_data = &cmd_opt[CMD_TERMINATE],
- .description = "Terminate the running component",
- .arg_description = "The component ID"
- },
- {
- NULL
- }
-};
-static gpointer opt[OPT_MAX];
-static GOptionEntry opt_entries[] = {
- {
- .long_name = "user",
- .short_name = 'u',
- .flags = 0,
- .arg = G_OPTION_ARG_INT,
- .arg_data = &opt[OPT_USER],
- .description = "Specify the user ID",
- .arg_description = "USER ID"
- },
- {
- .long_name = "instance",
- .short_name = 'i',
- .flags = 0,
- .arg = G_OPTION_ARG_INT,
- .arg_data = &opt[OPT_INSTANCE],
- .description = "Specify the instance ID",
- .arg_description = "The instance ID"
-
- },
- {
- NULL
- }
-};
-
-static GOptionGroup *__get_opt_group(void)
-{
- GOptionGroup *group;
-
- group = g_option_group_new("option", "Additional Options:",
- "Additional options", NULL, NULL);
- if (!group)
- return NULL;
-
- g_option_group_add_entries(group, opt_entries);
-
- return group;
-}
-
-static int __cmd_common_init(void *data)
-{
- struct cmd_arg *cmd_arg = (struct cmd_arg *)data;
- aul_comp_info_h handle = NULL;
- int ret;
-
- ret = aul_comp_info_usr_create(cmd_arg->comp_id, cmd_arg->uid,
- &handle);
- if (ret != AUL_R_OK) {
- printf("Failed to create component(%s) info\n",
- cmd_arg->comp_id);
- return -1;
- }
-
- aul_comp_info_destroy(handle);
-
- return 0;
-}
-
-static void __cmd_common_finish(void *data)
-{
- g_main_loop_quit(loop);
-}
-
-static bool __comp_info_cb(aul_comp_info_h handle, void *user_data)
-{
- int *member_count = (int *)user_data;
- const char *comp_id = NULL;
- const char *type = NULL;
- const char *launch_mode = NULL;
- bool main_comp = false;
- bool icon_display = false;
- bool taskmanage = false;
- const char *icon = NULL;
- const char *label = NULL;
- const char *boolean_string[] = {
- "false",
- "true",
- };
-
- aul_comp_info_get_comp_id(handle, &comp_id);
- aul_comp_info_get_type(handle, &type);
- aul_comp_info_get_launch_mode(handle, &launch_mode);
- aul_comp_info_is_main_comp(handle, &main_comp);
- aul_comp_info_is_icon_display(handle, &icon_display);
- aul_comp_info_is_taskmanage(handle, &taskmanage);
- aul_comp_info_get_icon(handle, &icon);
- aul_comp_info_get_label(handle, &label);
-
- (*member_count)++;
- printf("----------------------------------\n");
- printf("--- Member : %d\n", *member_count);
- printf(" - ID : %s\n", comp_id);
- printf(" - Type : %s\n", type);
- printf(" - Launch Mode : %s\n", launch_mode);
- printf(" - Main Comp : %s\n", boolean_string[main_comp]);
- printf(" - TaskManage : %s\n", boolean_string[taskmanage]);
- printf(" - Icon Display : %s\n", boolean_string[icon_display]);
- printf(" - Icon : %s\n", icon ? icon : "");
- printf(" - Label : %s\n", label ? label : "");
- printf("\n");
-
- return true;
-}
-
-static int __installed_list_cb(const pkgmgrinfo_appinfo_h handle, void *data)
-{
- uid_t uid = GPOINTER_TO_UINT(data);
- char *comp_type = NULL;
- char *appid = NULL;
- int member_count = 0;
- int ret;
-
- pkgmgrinfo_appinfo_get_component_type(handle, &comp_type);
- if (comp_type && strcmp(comp_type, "componentbasedapp") != 0)
- return 0;
-
- pkgmgrinfo_appinfo_get_appid(handle, &appid);
- if (!appid)
- return -1;
-
- printf("----------------------------------\n");
- printf("< Application : %s >\n", appid);
- ret = aul_comp_info_usr_foreach_comp_info_from_app(appid, uid,
- __comp_info_cb, (void *)&member_count);
- if (ret < 0) {
- fprintf(stderr, "Failed to retrieve component info. %s:%u\n",
- appid, uid);
- return -1;
- }
- printf("Member count : %d\n", member_count);
- printf("\n");
-
- return 0;
-}
-
-static int __cmd_list_run(void *data)
-{
- uid_t uid;
- int ret;
-
- if (opt[OPT_USER])
- uid = GPOINTER_TO_UINT(opt[OPT_USER]);
- else
- uid = getuid();
-
- ret = pkgmgrinfo_appinfo_get_usr_installed_list(__installed_list_cb,
- uid, GUINT_TO_POINTER(uid));
- if (ret == PMINFO_R_OK) {
- printf("==================================\n");
- printf("\n");
- }
-
- return ret;
-}
-
-static const char *__get_status_string(int status)
-{
- switch (status) {
- case COMP_STATUS_INITIALIZED:
- return "COMP_STATUS_INITIALIZED";
- case COMP_STATUS_CREATED:
- return "COMP_STATUS_CREATED";
- case COMP_STATUS_STARTED:
- return "COMP_STATUS_STARTED";
- case COMP_STATUS_RESUMED:
- return "COMP_STATUS_RESUMED";
- case COMP_STATUS_PAUSED:
- return "COMP_STATUS_PAUSED";
- case COMP_STATUS_DESTROYED:
- return "COMP_STATUS_DESTROYED";
- default:
- return "Unknown Status";
- }
-}
-
-static bool __comp_context_cb(aul_comp_context_h handle, void *user_data)
-{
- int *member_count = (int *)user_data;
- const char *app_id = NULL;
- const char *instance_id = NULL;
- const char *comp_id = NULL;
- const char *type = NULL;
- pid_t pid = -1;
- int status = -1;
- bool is_sub_comp = false;
-
- aul_comp_context_get_app_id(handle, &app_id);
- aul_comp_context_get_instance_id(handle, &instance_id);
- aul_comp_context_get_comp_id(handle, &comp_id);
- aul_comp_context_get_type(handle, &type);
- aul_comp_context_get_pid(handle, &pid);
- aul_comp_context_get_status(handle, &status);
- aul_comp_context_is_sub_comp(handle, &is_sub_comp);
-
- (*member_count)++;
- printf("----------------------------------\n");
- printf("< Member : %d >\n", *member_count);
- printf("--- ID : %s\n", comp_id);
- printf(" - Instance ID : %s\n", instance_id);
- printf(" - Application ID : %s\n", app_id);
- printf(" - Type : %s\n", type);
- printf(" - Process ID : %d\n", pid);
- printf(" - Status : %s\n", __get_status_string(status));
- printf(" - Sub Component : %s\n", is_sub_comp ? "true" : "false");
-
- return true;
-}
-
-static int __cmd_running_list_run(void *data)
-{
- int member_count = 0;
- int ret;
-
- ret = aul_comp_context_foreach_comp_context(__comp_context_cb,
- (void *)&member_count);
- if (ret == AUL_R_OK) {
- printf("==================================\n");
- printf("\n");
- printf("Component count : %d\n", member_count);
- }
-
- return ret;
-}
-
-static int __cmd_get_run(void *data)
-{
- struct cmd_arg *cmd_arg = (struct cmd_arg *)data;
- aul_comp_context_h handle = NULL;
- int member_count = 0;
- int ret;
-
- ret = aul_comp_context_usr_create(cmd_arg->comp_id, cmd_arg->uid,
- &handle);
- if (ret != AUL_R_OK) {
- printf("Failed to find running component(%s) context\n",
- cmd_arg->comp_id);
- return -1;
- }
-
- __comp_context_cb(handle, (void *)&member_count);
- aul_comp_context_destroy(handle);
- printf("[GET] result: %d\n", ret);
-
- return 0;
-}
-
-static int __cmd_is_running_run(void *data)
-{
- struct cmd_arg *cmd_arg = (struct cmd_arg *)data;
- aul_comp_context_h handle = NULL;
- bool is_running = false;
- int ret;
-
- ret = aul_comp_context_usr_create(cmd_arg->comp_id, cmd_arg->uid,
- &handle);
- if (ret != AUL_R_OK) {
- printf("Failed to find running component(%s) context\n",
- cmd_arg->comp_id);
- return -1;
- }
-
- ret = aul_comp_context_is_running(handle, &is_running);
- if (ret != AUL_R_OK) {
- printf("Failed to check running\n");
- aul_comp_context_destroy(handle);
- return -1;
- }
-
- aul_comp_context_destroy(handle);
- printf("[IS_RUNNING] %s is %s\n",
- cmd_arg->comp_id,
- is_running ? "running" : "not running");
-
- return 0;
-}
-
-static int __cmd_resume_run(void *data)
-{
- struct cmd_arg *cmd_arg = (struct cmd_arg *)data;
- aul_comp_context_h handle = NULL;
- int ret;
-
- ret = aul_comp_context_usr_create(cmd_arg->comp_id, cmd_arg->uid,
- &handle);
- if (ret != AUL_R_OK) {
- printf("Failed to find running component(%s) context\n",
- cmd_arg->comp_id);
- return -1;
- }
-
- ret = aul_comp_context_resume(handle);
- if (ret != AUL_R_OK) {
- printf("Failed to send the resume request\n");
- aul_comp_context_destroy(handle);
- return -1;
- }
-
- aul_comp_context_destroy(handle);
- printf("[RESUME] result: %d\n", ret);
-
- return 0;
-}
-
-static int __cmd_pause_run(void *data)
-{
- struct cmd_arg *cmd_arg = (struct cmd_arg *)data;
- aul_comp_context_h handle = NULL;
- int ret;
-
- ret = aul_comp_context_usr_create(cmd_arg->comp_id, cmd_arg->uid,
- &handle);
- if (ret != AUL_R_OK) {
- printf("Failed to find running component(%s) context\n",
- cmd_arg->comp_id);
- return -1;
- }
-
- ret = aul_comp_context_pause(handle);
- if (ret != AUL_R_OK) {
- printf("Failed to send the pause request\n");
- aul_comp_context_destroy(handle);
- return -1;
- }
-
- aul_comp_context_destroy(handle);
- printf("[PAUSE] result: %d\n", ret);
-
- return 0;
-}
-
-static int __cmd_terminate_bg_comp_run(void *data)
-{
- struct cmd_arg *cmd_arg = (struct cmd_arg *)data;
- aul_comp_context_h handle = NULL;
- int ret;
-
- ret = aul_comp_context_usr_create(cmd_arg->comp_id, cmd_arg->uid,
- &handle);
- if (ret != AUL_R_OK) {
- printf("Failed to find running component(%s) context\n",
- cmd_arg->comp_id);
- return -1;
- }
-
- ret = aul_comp_context_terminate_bg_comp(handle);
- if (ret != AUL_R_OK) {
- printf("Failed to send the terminate bg comp request\n");
- aul_comp_context_destroy(handle);
- return -1;
- }
-
- aul_comp_context_destroy(handle);
- printf("[TERMINATE_BG_COMP] result: %d\n", ret);
-
- return 0;
-}
-
-static int __cmd_terminate_run(void *data)
-{
- struct cmd_arg *cmd_arg = (struct cmd_arg *)data;
- aul_comp_context_h handle = NULL;
- int ret;
-
- ret = aul_comp_context_usr_create(cmd_arg->comp_id, cmd_arg->uid,
- &handle);
- if (ret != AUL_R_OK) {
- printf("Failed to find running component(%s) context\n",
- cmd_arg->comp_id);
- return -1;
- }
-
- ret = aul_comp_context_terminate(handle);
- if (ret != AUL_R_OK) {
- printf("Failed to send the terminate request\n");
- aul_comp_context_destroy(handle);
- return -1;
- }
-
- aul_comp_context_destroy(handle);
- printf("[TERMINATE] result: %d\n", ret);
-
- return 0;
-}
-
-static struct command cmd_table[] = {
- [CMD_LIST] = {
- .name = "list",
- .init = NULL,
- .run = __cmd_list_run,
- .finish = __cmd_common_finish
- },
- [CMD_RUNNING_LIST] = {
- .name = "running-list",
- .init = NULL,
- .run = __cmd_running_list_run,
- .finish = __cmd_common_finish
- },
- [CMD_GET] = {
- .name = "get",
- .init = __cmd_common_init,
- .run = __cmd_get_run,
- .finish = __cmd_common_finish
- },
- [CMD_IS_RUNNING] = {
- .name = "is-running",
- .init = __cmd_common_init,
- .run = __cmd_is_running_run,
- .finish = __cmd_common_finish
- },
- [CMD_RESUME] = {
- .name = "resume",
- .init = __cmd_common_init,
- .run = __cmd_resume_run,
- .finish = __cmd_common_finish
- },
- [CMD_PAUSE] = {
- .name = "pause",
- .init = __cmd_common_init,
- .run = __cmd_pause_run,
- .finish = __cmd_common_finish
- },
- [CMD_TERMINATE_BG_COMP] = {
- .name = "terminate-bg-comp",
- .init = __cmd_common_init,
- .run = __cmd_terminate_bg_comp_run,
- .finish = __cmd_common_finish
- },
- [CMD_TERMINATE] = {
- .name = "terminate",
- .init = __cmd_common_init,
- .run = __cmd_terminate_run,
- .finish = __cmd_common_finish
- },
-};
-
-static struct command *__find_cmd(void)
-{
- int i;
-
- for (i = 0; i < G_N_ELEMENTS(cmd_table); ++i) {
- if (cmd_opt[i])
- return &cmd_table[i];
- }
-
- return NULL;
-}
-
-static gboolean __run_cmd(gpointer data)
-{
- struct command *cmd;
- int result;
-
- cmd = __find_cmd();
- if (cmd == NULL) {
- printf("%s", help);
- g_main_loop_quit(loop);
- return G_SOURCE_REMOVE;
- }
-
- if (cmd->init) {
- result = cmd->init(data);
- if (result != 0) {
- g_main_loop_quit(loop);
- return G_SOURCE_REMOVE;
- }
- }
-
- if (cmd->run) {
- result = cmd->run(data);
- if (result != 0) {
- g_main_loop_quit(loop);
- return G_SOURCE_REMOVE;
- }
- }
-
- if (cmd->finish)
- cmd->finish(data);
-
- return G_SOURCE_REMOVE;
-}
-
-static struct cmd_arg *__create_cmd_arg(int argc, char **argv)
-{
- struct cmd_arg *cmd_arg;
- int i;
-
- cmd_arg = calloc(1, sizeof(struct cmd_arg));
- if (!cmd_arg)
- return NULL;
-
- for (i = CMD_GET; i <= CMD_TERMINATE; i++) {
- if (cmd_opt[i]) {
- cmd_arg->comp_id = cmd_opt[i];
- break;
- }
- }
-
- if (opt[OPT_USER])
- cmd_arg->uid = GPOINTER_TO_INT(opt[OPT_USER]);
- else
- cmd_arg->uid = getuid();
-
- if (opt[OPT_INSTANCE])
- cmd_arg->instance_id = opt[OPT_INSTANCE];
-
- return cmd_arg;
-}
-
-int main(int argc, char *argv[])
-{
- GOptionContext *context;
- GOptionGroup *opt_group;
- GError *error = NULL;
- struct cmd_arg *cmd_arg;
-
- context = g_option_context_new(NULL);
- g_option_context_add_main_entries(context, cmd_entries, NULL);
-
- opt_group = __get_opt_group();
- if (!opt_group) {
- printf("Failed to get opt group\n");
- g_option_context_free(context);
- return -1;
- }
- g_option_context_add_group(context, opt_group);
-
- if (!g_option_context_parse(context, &argc, &argv, &error)) {
- printf("%s: %s\n", argv[0], error->message);
- g_option_context_free(context);
- g_clear_error(&error);
- return -1;
- }
-
- help = g_option_context_get_help(context, TRUE, NULL);
- g_option_context_free(context);
-
- cmd_arg = __create_cmd_arg(argc, argv);
- if (!cmd_arg) {
- printf("%s", help);
- free(help);
- return -1;
- }
-
- g_idle_add(__run_cmd, cmd_arg);
- loop = g_main_loop_new(NULL, FALSE);
- if (!loop) {
- printf("Failed to create glib main loop\n");
- exit(EXIT_FAILURE);
- }
- g_main_loop_run(loop);
- g_main_loop_unref(loop);
- free(cmd_arg);
- free(help);
-
- return 0;
-}
--- /dev/null
+SET(TARGET_COMPMGR_TOOL "compmgr_tool")
+
+ADD_EXECUTABLE(${TARGET_COMPMGR_TOOL} ${CMAKE_CURRENT_SOURCE_DIR}/compmgr_tool.c)
+SET_TARGET_PROPERTIES(${TARGET_COMPMGR_TOOL} PROPERTIES COMPILE_FLAGS ${CFLAGS} "-fPIE")
+SET_TARGET_PROPERTIES(${TARGET_COMPMGR_TOOL} PROPERTIES LINK_FLAGS "-pie")
+TARGET_LINK_LIBRARIES(${TARGET_COMPMGR_TOOL} PRIVATE ${TARGET_AUL})
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_COMPMGR_TOOL} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../src)
+TARGET_INCLUDE_DIRECTORIES(${TARGET_COMPMGR_TOOL} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../include)
+
+INSTALL(TARGETS ${TARGET_COMPMGR_TOOL} DESTINATION bin)
--- /dev/null
+/*
+ * Copyright (c) 2019 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 <stdlib.h>
+#include <string.h>
+#include <stdbool.h>
+#include <sys/types.h>
+#include <linux/limits.h>
+#include <glib.h>
+#include <gio/gio.h>
+#include <bundle_internal.h>
+#include <pkgmgr-info.h>
+
+#include "aul.h"
+#include "aul_comp_info.h"
+#include "aul_comp_context.h"
+
+enum command_e {
+ CMD_LIST,
+ CMD_RUNNING_LIST,
+ CMD_GET,
+ CMD_IS_RUNNING,
+ CMD_RESUME,
+ CMD_PAUSE,
+ CMD_TERMINATE_BG_COMP,
+ CMD_TERMINATE,
+ CMD_MAX,
+};
+
+enum option_e {
+ OPT_USER,
+ OPT_INSTANCE,
+ OPT_MAX,
+};
+
+struct command {
+ const char *name;
+ int (*init)(void *data);
+ int (*run)(void *data);
+ void (*finish)(void *data);
+};
+
+struct cmd_arg {
+ char *comp_id;
+ char *instance_id;
+ uid_t uid;
+};
+
+static GMainLoop *loop;
+static gchar *help;
+static gpointer cmd_opt[CMD_MAX];
+static GOptionEntry cmd_entries[] = {
+ {
+ .long_name = "list",
+ .short_name = 'l',
+ .flags = 0,
+ .arg = G_OPTION_ARG_NONE,
+ .arg_data = &cmd_opt[CMD_LIST],
+ .description = "Show installed component list",
+ .arg_description = NULL
+ },
+ {
+ .long_name = "running-list",
+ .short_name = 'r',
+ .flags = 0,
+ .arg = G_OPTION_ARG_NONE,
+ .arg_data = &cmd_opt[CMD_RUNNING_LIST],
+ .description = "Show the running components information",
+ .arg_description = NULL
+ },
+ {
+ .long_name = "get",
+ .short_name = 'g',
+ .flags = 0,
+ .arg = G_OPTION_ARG_STRING,
+ .arg_data = &cmd_opt[CMD_GET],
+ .description = "Show the running component information",
+ .arg_description = "The component ID"
+ },
+ {
+ .long_name = "is-running",
+ .short_name = 'n',
+ .flags = 0,
+ .arg = G_OPTION_ARG_STRING,
+ .arg_data = &cmd_opt[CMD_IS_RUNNING],
+ .description = "Check whether the component is running or not",
+ .arg_description = "The component ID"
+ },
+ {
+ .long_name = "resume",
+ .short_name = 'o',
+ .flags = 0,
+ .arg = G_OPTION_ARG_STRING,
+ .arg_data = &cmd_opt[CMD_RESUME],
+ .description = "Resume the running component",
+ .arg_description = "The component ID"
+ },
+ {
+ .long_name = "pause",
+ .short_name = 'p',
+ .flags = 0,
+ .arg = G_OPTION_ARG_STRING,
+ .arg_data = &cmd_opt[CMD_PAUSE],
+ .description = "Pause the running component",
+ .arg_description = "The component ID"
+ },
+ {
+ .long_name = "terminate-bg-comp",
+ .short_name = 'b',
+ .flags = 0,
+ .arg = G_OPTION_ARG_STRING,
+ .arg_data = &cmd_opt[CMD_TERMINATE_BG_COMP],
+ .description = "Terminate the background component",
+ .arg_description = "The component ID"
+ },
+ {
+ .long_name = "terminate",
+ .short_name = 't',
+ .flags = 0,
+ .arg = G_OPTION_ARG_STRING,
+ .arg_data = &cmd_opt[CMD_TERMINATE],
+ .description = "Terminate the running component",
+ .arg_description = "The component ID"
+ },
+ {
+ NULL
+ }
+};
+static gpointer opt[OPT_MAX];
+static GOptionEntry opt_entries[] = {
+ {
+ .long_name = "user",
+ .short_name = 'u',
+ .flags = 0,
+ .arg = G_OPTION_ARG_INT,
+ .arg_data = &opt[OPT_USER],
+ .description = "Specify the user ID",
+ .arg_description = "USER ID"
+ },
+ {
+ .long_name = "instance",
+ .short_name = 'i',
+ .flags = 0,
+ .arg = G_OPTION_ARG_INT,
+ .arg_data = &opt[OPT_INSTANCE],
+ .description = "Specify the instance ID",
+ .arg_description = "The instance ID"
+
+ },
+ {
+ NULL
+ }
+};
+
+static GOptionGroup *__get_opt_group(void)
+{
+ GOptionGroup *group;
+
+ group = g_option_group_new("option", "Additional Options:",
+ "Additional options", NULL, NULL);
+ if (!group)
+ return NULL;
+
+ g_option_group_add_entries(group, opt_entries);
+
+ return group;
+}
+
+static int __cmd_common_init(void *data)
+{
+ struct cmd_arg *cmd_arg = (struct cmd_arg *)data;
+ aul_comp_info_h handle = NULL;
+ int ret;
+
+ ret = aul_comp_info_usr_create(cmd_arg->comp_id, cmd_arg->uid,
+ &handle);
+ if (ret != AUL_R_OK) {
+ printf("Failed to create component(%s) info\n",
+ cmd_arg->comp_id);
+ return -1;
+ }
+
+ aul_comp_info_destroy(handle);
+
+ return 0;
+}
+
+static void __cmd_common_finish(void *data)
+{
+ g_main_loop_quit(loop);
+}
+
+static bool __comp_info_cb(aul_comp_info_h handle, void *user_data)
+{
+ int *member_count = (int *)user_data;
+ const char *comp_id = NULL;
+ const char *type = NULL;
+ const char *launch_mode = NULL;
+ bool main_comp = false;
+ bool icon_display = false;
+ bool taskmanage = false;
+ const char *icon = NULL;
+ const char *label = NULL;
+ const char *boolean_string[] = {
+ "false",
+ "true",
+ };
+
+ aul_comp_info_get_comp_id(handle, &comp_id);
+ aul_comp_info_get_type(handle, &type);
+ aul_comp_info_get_launch_mode(handle, &launch_mode);
+ aul_comp_info_is_main_comp(handle, &main_comp);
+ aul_comp_info_is_icon_display(handle, &icon_display);
+ aul_comp_info_is_taskmanage(handle, &taskmanage);
+ aul_comp_info_get_icon(handle, &icon);
+ aul_comp_info_get_label(handle, &label);
+
+ (*member_count)++;
+ printf("----------------------------------\n");
+ printf("--- Member : %d\n", *member_count);
+ printf(" - ID : %s\n", comp_id);
+ printf(" - Type : %s\n", type);
+ printf(" - Launch Mode : %s\n", launch_mode);
+ printf(" - Main Comp : %s\n", boolean_string[main_comp]);
+ printf(" - TaskManage : %s\n", boolean_string[taskmanage]);
+ printf(" - Icon Display : %s\n", boolean_string[icon_display]);
+ printf(" - Icon : %s\n", icon ? icon : "");
+ printf(" - Label : %s\n", label ? label : "");
+ printf("\n");
+
+ return true;
+}
+
+static int __installed_list_cb(const pkgmgrinfo_appinfo_h handle, void *data)
+{
+ uid_t uid = GPOINTER_TO_UINT(data);
+ char *comp_type = NULL;
+ char *appid = NULL;
+ int member_count = 0;
+ int ret;
+
+ pkgmgrinfo_appinfo_get_component_type(handle, &comp_type);
+ if (comp_type && strcmp(comp_type, "componentbasedapp") != 0)
+ return 0;
+
+ pkgmgrinfo_appinfo_get_appid(handle, &appid);
+ if (!appid)
+ return -1;
+
+ printf("----------------------------------\n");
+ printf("< Application : %s >\n", appid);
+ ret = aul_comp_info_usr_foreach_comp_info_from_app(appid, uid,
+ __comp_info_cb, (void *)&member_count);
+ if (ret < 0) {
+ fprintf(stderr, "Failed to retrieve component info. %s:%u\n",
+ appid, uid);
+ return -1;
+ }
+ printf("Member count : %d\n", member_count);
+ printf("\n");
+
+ return 0;
+}
+
+static int __cmd_list_run(void *data)
+{
+ uid_t uid;
+ int ret;
+
+ if (opt[OPT_USER])
+ uid = GPOINTER_TO_UINT(opt[OPT_USER]);
+ else
+ uid = getuid();
+
+ ret = pkgmgrinfo_appinfo_get_usr_installed_list(__installed_list_cb,
+ uid, GUINT_TO_POINTER(uid));
+ if (ret == PMINFO_R_OK) {
+ printf("==================================\n");
+ printf("\n");
+ }
+
+ return ret;
+}
+
+static const char *__get_status_string(int status)
+{
+ switch (status) {
+ case COMP_STATUS_INITIALIZED:
+ return "COMP_STATUS_INITIALIZED";
+ case COMP_STATUS_CREATED:
+ return "COMP_STATUS_CREATED";
+ case COMP_STATUS_STARTED:
+ return "COMP_STATUS_STARTED";
+ case COMP_STATUS_RESUMED:
+ return "COMP_STATUS_RESUMED";
+ case COMP_STATUS_PAUSED:
+ return "COMP_STATUS_PAUSED";
+ case COMP_STATUS_DESTROYED:
+ return "COMP_STATUS_DESTROYED";
+ default:
+ return "Unknown Status";
+ }
+}
+
+static bool __comp_context_cb(aul_comp_context_h handle, void *user_data)
+{
+ int *member_count = (int *)user_data;
+ const char *app_id = NULL;
+ const char *instance_id = NULL;
+ const char *comp_id = NULL;
+ const char *type = NULL;
+ pid_t pid = -1;
+ int status = -1;
+ bool is_sub_comp = false;
+
+ aul_comp_context_get_app_id(handle, &app_id);
+ aul_comp_context_get_instance_id(handle, &instance_id);
+ aul_comp_context_get_comp_id(handle, &comp_id);
+ aul_comp_context_get_type(handle, &type);
+ aul_comp_context_get_pid(handle, &pid);
+ aul_comp_context_get_status(handle, &status);
+ aul_comp_context_is_sub_comp(handle, &is_sub_comp);
+
+ (*member_count)++;
+ printf("----------------------------------\n");
+ printf("< Member : %d >\n", *member_count);
+ printf("--- ID : %s\n", comp_id);
+ printf(" - Instance ID : %s\n", instance_id);
+ printf(" - Application ID : %s\n", app_id);
+ printf(" - Type : %s\n", type);
+ printf(" - Process ID : %d\n", pid);
+ printf(" - Status : %s\n", __get_status_string(status));
+ printf(" - Sub Component : %s\n", is_sub_comp ? "true" : "false");
+
+ return true;
+}
+
+static int __cmd_running_list_run(void *data)
+{
+ int member_count = 0;
+ int ret;
+
+ ret = aul_comp_context_foreach_comp_context(__comp_context_cb,
+ (void *)&member_count);
+ if (ret == AUL_R_OK) {
+ printf("==================================\n");
+ printf("\n");
+ printf("Component count : %d\n", member_count);
+ }
+
+ return ret;
+}
+
+static int __cmd_get_run(void *data)
+{
+ struct cmd_arg *cmd_arg = (struct cmd_arg *)data;
+ aul_comp_context_h handle = NULL;
+ int member_count = 0;
+ int ret;
+
+ ret = aul_comp_context_usr_create(cmd_arg->comp_id, cmd_arg->uid,
+ &handle);
+ if (ret != AUL_R_OK) {
+ printf("Failed to find running component(%s) context\n",
+ cmd_arg->comp_id);
+ return -1;
+ }
+
+ __comp_context_cb(handle, (void *)&member_count);
+ aul_comp_context_destroy(handle);
+ printf("[GET] result: %d\n", ret);
+
+ return 0;
+}
+
+static int __cmd_is_running_run(void *data)
+{
+ struct cmd_arg *cmd_arg = (struct cmd_arg *)data;
+ aul_comp_context_h handle = NULL;
+ bool is_running = false;
+ int ret;
+
+ ret = aul_comp_context_usr_create(cmd_arg->comp_id, cmd_arg->uid,
+ &handle);
+ if (ret != AUL_R_OK) {
+ printf("Failed to find running component(%s) context\n",
+ cmd_arg->comp_id);
+ return -1;
+ }
+
+ ret = aul_comp_context_is_running(handle, &is_running);
+ if (ret != AUL_R_OK) {
+ printf("Failed to check running\n");
+ aul_comp_context_destroy(handle);
+ return -1;
+ }
+
+ aul_comp_context_destroy(handle);
+ printf("[IS_RUNNING] %s is %s\n",
+ cmd_arg->comp_id,
+ is_running ? "running" : "not running");
+
+ return 0;
+}
+
+static int __cmd_resume_run(void *data)
+{
+ struct cmd_arg *cmd_arg = (struct cmd_arg *)data;
+ aul_comp_context_h handle = NULL;
+ int ret;
+
+ ret = aul_comp_context_usr_create(cmd_arg->comp_id, cmd_arg->uid,
+ &handle);
+ if (ret != AUL_R_OK) {
+ printf("Failed to find running component(%s) context\n",
+ cmd_arg->comp_id);
+ return -1;
+ }
+
+ ret = aul_comp_context_resume(handle);
+ if (ret != AUL_R_OK) {
+ printf("Failed to send the resume request\n");
+ aul_comp_context_destroy(handle);
+ return -1;
+ }
+
+ aul_comp_context_destroy(handle);
+ printf("[RESUME] result: %d\n", ret);
+
+ return 0;
+}
+
+static int __cmd_pause_run(void *data)
+{
+ struct cmd_arg *cmd_arg = (struct cmd_arg *)data;
+ aul_comp_context_h handle = NULL;
+ int ret;
+
+ ret = aul_comp_context_usr_create(cmd_arg->comp_id, cmd_arg->uid,
+ &handle);
+ if (ret != AUL_R_OK) {
+ printf("Failed to find running component(%s) context\n",
+ cmd_arg->comp_id);
+ return -1;
+ }
+
+ ret = aul_comp_context_pause(handle);
+ if (ret != AUL_R_OK) {
+ printf("Failed to send the pause request\n");
+ aul_comp_context_destroy(handle);
+ return -1;
+ }
+
+ aul_comp_context_destroy(handle);
+ printf("[PAUSE] result: %d\n", ret);
+
+ return 0;
+}
+
+static int __cmd_terminate_bg_comp_run(void *data)
+{
+ struct cmd_arg *cmd_arg = (struct cmd_arg *)data;
+ aul_comp_context_h handle = NULL;
+ int ret;
+
+ ret = aul_comp_context_usr_create(cmd_arg->comp_id, cmd_arg->uid,
+ &handle);
+ if (ret != AUL_R_OK) {
+ printf("Failed to find running component(%s) context\n",
+ cmd_arg->comp_id);
+ return -1;
+ }
+
+ ret = aul_comp_context_terminate_bg_comp(handle);
+ if (ret != AUL_R_OK) {
+ printf("Failed to send the terminate bg comp request\n");
+ aul_comp_context_destroy(handle);
+ return -1;
+ }
+
+ aul_comp_context_destroy(handle);
+ printf("[TERMINATE_BG_COMP] result: %d\n", ret);
+
+ return 0;
+}
+
+static int __cmd_terminate_run(void *data)
+{
+ struct cmd_arg *cmd_arg = (struct cmd_arg *)data;
+ aul_comp_context_h handle = NULL;
+ int ret;
+
+ ret = aul_comp_context_usr_create(cmd_arg->comp_id, cmd_arg->uid,
+ &handle);
+ if (ret != AUL_R_OK) {
+ printf("Failed to find running component(%s) context\n",
+ cmd_arg->comp_id);
+ return -1;
+ }
+
+ ret = aul_comp_context_terminate(handle);
+ if (ret != AUL_R_OK) {
+ printf("Failed to send the terminate request\n");
+ aul_comp_context_destroy(handle);
+ return -1;
+ }
+
+ aul_comp_context_destroy(handle);
+ printf("[TERMINATE] result: %d\n", ret);
+
+ return 0;
+}
+
+static struct command cmd_table[] = {
+ [CMD_LIST] = {
+ .name = "list",
+ .init = NULL,
+ .run = __cmd_list_run,
+ .finish = __cmd_common_finish
+ },
+ [CMD_RUNNING_LIST] = {
+ .name = "running-list",
+ .init = NULL,
+ .run = __cmd_running_list_run,
+ .finish = __cmd_common_finish
+ },
+ [CMD_GET] = {
+ .name = "get",
+ .init = __cmd_common_init,
+ .run = __cmd_get_run,
+ .finish = __cmd_common_finish
+ },
+ [CMD_IS_RUNNING] = {
+ .name = "is-running",
+ .init = __cmd_common_init,
+ .run = __cmd_is_running_run,
+ .finish = __cmd_common_finish
+ },
+ [CMD_RESUME] = {
+ .name = "resume",
+ .init = __cmd_common_init,
+ .run = __cmd_resume_run,
+ .finish = __cmd_common_finish
+ },
+ [CMD_PAUSE] = {
+ .name = "pause",
+ .init = __cmd_common_init,
+ .run = __cmd_pause_run,
+ .finish = __cmd_common_finish
+ },
+ [CMD_TERMINATE_BG_COMP] = {
+ .name = "terminate-bg-comp",
+ .init = __cmd_common_init,
+ .run = __cmd_terminate_bg_comp_run,
+ .finish = __cmd_common_finish
+ },
+ [CMD_TERMINATE] = {
+ .name = "terminate",
+ .init = __cmd_common_init,
+ .run = __cmd_terminate_run,
+ .finish = __cmd_common_finish
+ },
+};
+
+static struct command *__find_cmd(void)
+{
+ int i;
+
+ for (i = 0; i < G_N_ELEMENTS(cmd_table); ++i) {
+ if (cmd_opt[i])
+ return &cmd_table[i];
+ }
+
+ return NULL;
+}
+
+static gboolean __run_cmd(gpointer data)
+{
+ struct command *cmd;
+ int result;
+
+ cmd = __find_cmd();
+ if (cmd == NULL) {
+ printf("%s", help);
+ g_main_loop_quit(loop);
+ return G_SOURCE_REMOVE;
+ }
+
+ if (cmd->init) {
+ result = cmd->init(data);
+ if (result != 0) {
+ g_main_loop_quit(loop);
+ return G_SOURCE_REMOVE;
+ }
+ }
+
+ if (cmd->run) {
+ result = cmd->run(data);
+ if (result != 0) {
+ g_main_loop_quit(loop);
+ return G_SOURCE_REMOVE;
+ }
+ }
+
+ if (cmd->finish)
+ cmd->finish(data);
+
+ return G_SOURCE_REMOVE;
+}
+
+static struct cmd_arg *__create_cmd_arg(int argc, char **argv)
+{
+ struct cmd_arg *cmd_arg;
+ int i;
+
+ cmd_arg = calloc(1, sizeof(struct cmd_arg));
+ if (!cmd_arg)
+ return NULL;
+
+ for (i = CMD_GET; i <= CMD_TERMINATE; i++) {
+ if (cmd_opt[i]) {
+ cmd_arg->comp_id = cmd_opt[i];
+ break;
+ }
+ }
+
+ if (opt[OPT_USER])
+ cmd_arg->uid = GPOINTER_TO_INT(opt[OPT_USER]);
+ else
+ cmd_arg->uid = getuid();
+
+ if (opt[OPT_INSTANCE])
+ cmd_arg->instance_id = opt[OPT_INSTANCE];
+
+ return cmd_arg;
+}
+
+int main(int argc, char *argv[])
+{
+ GOptionContext *context;
+ GOptionGroup *opt_group;
+ GError *error = NULL;
+ struct cmd_arg *cmd_arg;
+
+ context = g_option_context_new(NULL);
+ g_option_context_add_main_entries(context, cmd_entries, NULL);
+
+ opt_group = __get_opt_group();
+ if (!opt_group) {
+ printf("Failed to get opt group\n");
+ g_option_context_free(context);
+ return -1;
+ }
+ g_option_context_add_group(context, opt_group);
+
+ if (!g_option_context_parse(context, &argc, &argv, &error)) {
+ printf("%s: %s\n", argv[0], error->message);
+ g_option_context_free(context);
+ g_clear_error(&error);
+ return -1;
+ }
+
+ help = g_option_context_get_help(context, TRUE, NULL);
+ g_option_context_free(context);
+
+ cmd_arg = __create_cmd_arg(argc, argv);
+ if (!cmd_arg) {
+ printf("%s", help);
+ free(help);
+ return -1;
+ }
+
+ g_idle_add(__run_cmd, cmd_arg);
+ loop = g_main_loop_new(NULL, FALSE);
+ if (!loop) {
+ printf("Failed to create glib main loop\n");
+ exit(EXIT_FAILURE);
+ }
+ g_main_loop_run(loop);
+ g_main_loop_unref(loop);
+ free(cmd_arg);
+ free(help);
+
+ return 0;
+}
+++ /dev/null
-/*
- * Copyright (c) 2000 - 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.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <string.h>
-#include <glib.h>
-#include <bundle_internal.h>
-#include "aul.h"
-
-static char **gargv;
-static int gargc;
-bundle *kb;
-static GMainLoop *mainloop;
-static int result;
-
-static bundle *create_internal_bundle(int start)
-{
- int i;
- int j;
- char arg[1024];
- char *val_array[128];
-
- kb = bundle_create();
- if (kb == NULL)
- return NULL;
-
- for (i = start; i + 1 < gargc; i += 2) {
- if ((i + 1) > gargc - 1) {
- bundle_add(kb, gargv[i], " ");
- } else {
- j = 1;
- snprintf(arg, sizeof(arg), "%s", gargv[i + 1]);
- val_array[0] = strtok(arg, ",");
- while (1) {
- val_array[j] = strtok(NULL, ",");
- if (val_array[j] == NULL)
- break;
- j++;
- }
-
- if (j == 1) {
- bundle_add(kb, gargv[i], gargv[i + 1]);
- } else if (j > 1) {
- bundle_add_str_array(kb, gargv[i],
- (const char**)val_array, j);
- }
- }
- }
-
- return kb;
-}
-
-static int launch(void)
-{
- kb = create_internal_bundle(2);
- if (kb == NULL) {
- printf("bundle creation fail\n");
- return -1;
- }
-
- if (bundle_get_val(kb, AUL_K_SDK))
- return aul_launch_app_async(gargv[1], kb);
-
- return aul_launch_app(gargv[1], kb);
-}
-
-static void print_usage(char *progname)
-{
- printf("[usage] %s <pkgname> <key1> <val1> <key2> <val2> ...\n",
- progname);
-}
-
-static int __launch_app_dead_handler(int pid, void *data)
-{
- int listen_pid = (intptr_t)data;
-
- if (listen_pid == pid)
- g_main_loop_quit(mainloop);
-
- return 0;
-}
-
-static gboolean run_func(gpointer data)
-{
- int pid;
- const char *str;
-
- pid = launch();
- if (pid > 0) {
- printf("... successfully launched\n");
- str = bundle_get_val(kb, "__LAUNCH_APP_MODE__");
- if (str && strcmp(str, "SYNC") == 0) {
- aul_listen_app_dead_signal(__launch_app_dead_handler,
- (void *)(intptr_t)pid);
- bundle_free(kb);
- kb = NULL;
- return FALSE;
- }
- } else {
- printf("... launch failed\n");
- result = pid;
- }
-
- if (kb) {
- bundle_free(kb);
- kb = NULL;
- }
-
- g_main_loop_quit(mainloop);
-
- return FALSE;
-}
-
-int main(int argc, char **argv)
-{
- if (argc < 2) {
- print_usage(argv[0]);
- exit(EXIT_FAILURE);
- }
-
- gargc = argc;
- gargv = argv;
-
- aul_launch_init(NULL, NULL);
-
- g_idle_add(run_func, NULL);
-
- mainloop = g_main_loop_new(NULL, FALSE);
- if (!mainloop) {
- printf("failed to create glib main loop\n");
- exit(EXIT_FAILURE);
- }
- g_main_loop_run(mainloop);
-
- return result;
-}
--- /dev/null
+SET(TARGET_LAUNCH_APP "launch_app")
+
+ADD_EXECUTABLE(${TARGET_LAUNCH_APP} ${CMAKE_CURRENT_SOURCE_DIR}/launch_app.c)
+SET_TARGET_PROPERTIES(${TARGET_LAUNCH_APP} PROPERTIES COMPILE_FLAGS ${CFLAGS} "-fPIE")
+SET_TARGET_PROPERTIES(${TARGET_LAUNCH_APP} PROPERTIES LINK_FLAGS "-pie")
+TARGET_LINK_LIBRARIES(${TARGET_LAUNCH_APP} PRIVATE ${TARGET_AUL})
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_LAUNCH_APP} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../src)
+TARGET_INCLUDE_DIRECTORIES(${TARGET_LAUNCH_APP} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../include)
+
+INSTALL(TARGETS ${TARGET_LAUNCH_APP} DESTINATION bin)
--- /dev/null
+/*
+ * Copyright (c) 2000 - 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.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <string.h>
+#include <glib.h>
+#include <bundle_internal.h>
+#include "aul.h"
+
+static char **gargv;
+static int gargc;
+bundle *kb;
+static GMainLoop *mainloop;
+static int result;
+
+static bundle *create_internal_bundle(int start)
+{
+ int i;
+ int j;
+ char arg[1024];
+ char *val_array[128];
+
+ kb = bundle_create();
+ if (kb == NULL)
+ return NULL;
+
+ for (i = start; i + 1 < gargc; i += 2) {
+ if ((i + 1) > gargc - 1) {
+ bundle_add(kb, gargv[i], " ");
+ } else {
+ j = 1;
+ snprintf(arg, sizeof(arg), "%s", gargv[i + 1]);
+ val_array[0] = strtok(arg, ",");
+ while (1) {
+ val_array[j] = strtok(NULL, ",");
+ if (val_array[j] == NULL)
+ break;
+ j++;
+ }
+
+ if (j == 1) {
+ bundle_add(kb, gargv[i], gargv[i + 1]);
+ } else if (j > 1) {
+ bundle_add_str_array(kb, gargv[i],
+ (const char**)val_array, j);
+ }
+ }
+ }
+
+ return kb;
+}
+
+static int launch(void)
+{
+ kb = create_internal_bundle(2);
+ if (kb == NULL) {
+ printf("bundle creation fail\n");
+ return -1;
+ }
+
+ if (bundle_get_val(kb, AUL_K_SDK))
+ return aul_launch_app_async(gargv[1], kb);
+
+ return aul_launch_app(gargv[1], kb);
+}
+
+static void print_usage(char *progname)
+{
+ printf("[usage] %s <pkgname> <key1> <val1> <key2> <val2> ...\n",
+ progname);
+}
+
+static int __launch_app_dead_handler(int pid, void *data)
+{
+ int listen_pid = (intptr_t)data;
+
+ if (listen_pid == pid)
+ g_main_loop_quit(mainloop);
+
+ return 0;
+}
+
+static gboolean run_func(gpointer data)
+{
+ int pid;
+ const char *str;
+
+ pid = launch();
+ if (pid > 0) {
+ printf("... successfully launched\n");
+ str = bundle_get_val(kb, "__LAUNCH_APP_MODE__");
+ if (str && strcmp(str, "SYNC") == 0) {
+ aul_listen_app_dead_signal(__launch_app_dead_handler,
+ (void *)(intptr_t)pid);
+ bundle_free(kb);
+ kb = NULL;
+ return FALSE;
+ }
+ } else {
+ printf("... launch failed\n");
+ result = pid;
+ }
+
+ if (kb) {
+ bundle_free(kb);
+ kb = NULL;
+ }
+
+ g_main_loop_quit(mainloop);
+
+ return FALSE;
+}
+
+int main(int argc, char **argv)
+{
+ if (argc < 2) {
+ print_usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ gargc = argc;
+ gargv = argv;
+
+ aul_launch_init(NULL, NULL);
+
+ g_idle_add(run_func, NULL);
+
+ mainloop = g_main_loop_new(NULL, FALSE);
+ if (!mainloop) {
+ printf("failed to create glib main loop\n");
+ exit(EXIT_FAILURE);
+ }
+ g_main_loop_run(mainloop);
+
+ return result;
+}
+++ /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.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <stdbool.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <string.h>
-
-#include <glib.h>
-#include <bundle.h>
-#include <bundle_internal.h>
-#include <pkgmgr-info.h>
-
-#include "aul.h"
-#include "aul_svc.h"
-#include "launch.h"
-
-#define LAUNCHPAD_PROCESS_POOL_SOCK ".launchpad-process-pool-sock"
-#define DLP_K_ATTACH_ARG "__DLP_ATTACH_ARG__"
-#define SDK_ATTACH "ATTACH"
-
-static GMainLoop *__mainloop;
-static bool __sync_mode;
-
-static bundle *create_internal_bundle(int argc, char **argv)
-{
- bundle *b;
- int i;
- int j;
- int cnt;
- char *arg[1024] = {0, };
-
- b = bundle_create();
- if (b == NULL)
- return NULL;
-
- for (i = 2; i < argc - 1; i++) {
- if ((i + 1) > (argc - 1)) {
- bundle_add(b, argv[1], " ");
- } else if (argv[i] && strcmp(argv[i], AUL_K_SDK) == 0) {
- bundle_add(b, AUL_K_SDK, argv[i + 1]);
- } else if (argv[i] && strcmp(argv[i], DLP_K_ATTACH_ARG) == 0) {
- arg[0] = strtok(argv[i + 1], ",");
-
- cnt = 1;
- while ((arg[cnt] = strtok(NULL, ",")) != NULL)
- cnt++;
-
- bundle_add(b, SDK_ATTACH, DLP_K_ATTACH_ARG);
- bundle_add_str_array(b, DLP_K_ATTACH_ARG, NULL, cnt);
-
- for (j = 0; j < cnt; j++) {
- bundle_set_str_array_element(b,
- DLP_K_ATTACH_ARG, j, arg[j]);
- }
- } else if (argv[i] && !strcmp(argv[i], "__LAUNCH_APP_MODE__")) {
- if (argv[i + 1] && !strcmp(argv[i + 1], "SYNC"))
- __sync_mode = true;
- }
- }
-
- return b;
-}
-
-static void print_usage(char *progname)
-{
- printf("[usage] %s [appid] %s <debugger name> %s --attach,:[port],[pid]\n",
- progname, AUL_K_SDK, DLP_K_ATTACH_ARG);
- printf("ex) $ %s [appid] %s %s %s --attach,:10003,1234\n",
- progname, AUL_K_SDK, SDK_ATTACH, DLP_K_ATTACH_ARG);
-}
-
-static int __get_gles(void)
-{
- FILE *fp;
- char buf[PATH_MAX];
- char *tmp;
- int gles = 1;
-
- fp = fopen("/proc/cmdline", "r");
- if (fp == NULL)
- return gles;
-
- if (fgets(buf, sizeof(buf), fp) != NULL) {
- tmp = strstr(buf, "gles");
- if (tmp != NULL)
- sscanf(tmp, "gles=%d", &gles);
- }
-
- fclose(fp);
-
- return gles;
-}
-
-static void __set_pkg_api_version(bundle *kb, const char *pkgid)
-{
- int ret;
- char *api_version;
- pkgmgrinfo_pkginfo_h handle;
-
- ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
- if (ret != PMINFO_R_OK)
- return;
-
- ret = pkgmgrinfo_pkginfo_get_api_version(handle, &api_version);
- if (ret != PMINFO_R_OK) {
- pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
- return;
- }
-
- printf("pkg api_version: %s\n", api_version);
- bundle_add(kb, AUL_K_API_VERSION, api_version);
- pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
-}
-
-static int __set_appinfo_for_debug_launchpad(bundle *kb, const char *appid)
-{
- pkgmgrinfo_appinfo_h handle;
- int ret;
- char *pkgid;
- char *exec;
- char *apptype;
- char *pkgtype;
- char *component_type;
- pkgmgrinfo_app_hwacceleration hwacc = PMINFO_HWACCELERATION_OFF;
- const char *hwacc_str = "NOT_USE";
- bool process_pool = false;
- char buf[12];
-
- if (kb == NULL)
- return -1;
-
- ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, getuid(), &handle);
- if (ret != PMINFO_R_OK)
- return -1;
-
- ret = pkgmgrinfo_appinfo_get_exec(handle, &exec);
- if (ret != PMINFO_R_OK)
- goto end;
-
- ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
- if (ret != PMINFO_R_OK)
- goto end;
-
- ret = pkgmgrinfo_appinfo_get_apptype(handle, &apptype);
- if (ret != PMINFO_R_OK)
- goto end;
-
- ret = pkgmgrinfo_appinfo_get_pkgtype(handle, &pkgtype);
- if (ret != PMINFO_R_OK)
- goto end;
-
- ret = pkgmgrinfo_appinfo_get_component_type(handle, &component_type);
- if (ret != PMINFO_R_OK)
- goto end;
-
- ret = pkgmgrinfo_appinfo_get_hwacceleration(handle, &hwacc);
- if (ret != PMINFO_R_OK)
- goto end;
-
- ret = pkgmgrinfo_appinfo_is_process_pool(handle, &process_pool);
- if (ret != PMINFO_R_OK)
- goto end;
-
- if (__get_gles()) {
- if (hwacc == PMINFO_HWACCELERATION_OFF)
- hwacc_str = "NOT_USE";
- else if (hwacc == PMINFO_HWACCELERATION_ON)
- hwacc_str = "USE";
- else
- hwacc_str = "SYS";
- }
-
- bundle_add(kb, AUL_K_APPID, appid);
- bundle_add(kb, AUL_K_HWACC, hwacc_str);
- bundle_add(kb, AUL_K_EXEC, exec);
- bundle_add(kb, AUL_K_APP_TYPE, apptype);
- bundle_add(kb, AUL_K_PKGID, pkgid);
- bundle_add(kb, AUL_K_INTERNAL_POOL, process_pool ? "true" : "false");
- bundle_add(kb, AUL_K_COMP_TYPE, component_type);
- bundle_add(kb, AUL_K_PACKAGETYPE, pkgtype);
-
- __set_pkg_api_version(kb, pkgid);
- aul_svc_set_loader_id(kb, PAD_LOADER_ID_DIRECT);
-
- snprintf(buf, sizeof(buf), "%d", getpid());
- bundle_add(kb, AUL_K_CALLER_PID, buf);
-
-end:
- pkgmgrinfo_appinfo_destroy_appinfo(handle);
-
- return 0;
-}
-
-static void __run_mainloop(void)
-{
- __mainloop = g_main_loop_new(NULL, FALSE);
- if (!__mainloop) {
- printf("Failed to create glib main loop\n");
- exit(EXIT_FAILURE);
- }
-
- g_main_loop_run(__mainloop);
-}
-
-static void __quit_mainloop(void)
-{
- if (__mainloop) {
- g_main_loop_quit(__mainloop);
- g_main_loop_unref(__mainloop);
- __mainloop = NULL;
- }
-}
-
-static int __app_dead_handler(int pid, void *data)
-{
- int launched_pid = GPOINTER_TO_INT(data);
-
- if (launched_pid == pid)
- __quit_mainloop();
-
- return 0;
-}
-
-static gboolean __run_cb(gpointer data)
-{
- bundle *b = (bundle *)data;
- int ret;
-
- if (!b)
- return G_SOURCE_REMOVE;
-
- ret = app_send_cmd_to_launchpad(LAUNCHPAD_PROCESS_POOL_SOCK,
- getuid(), 0, b);
- if (ret < 0)
- printf("Failed to send launch request\n");
-
- if (__sync_mode) {
- aul_listen_app_dead_signal(__app_dead_handler,
- GINT_TO_POINTER(ret));
- return G_SOURCE_REMOVE;
- }
-
- __quit_mainloop();
-
- return G_SOURCE_REMOVE;
-}
-
-int main(int argc, char **argv)
-{
- bundle *b;
-
- if (argc < 2) {
- print_usage(argv[0]);
- return -1;
- }
-
- b = create_internal_bundle(argc, argv);
- if (b == NULL) {
- printf("out of memory\n");
- return -1;
- }
-
- if (bundle_get_type(b, AUL_K_SDK) == BUNDLE_TYPE_NONE) {
- print_usage(argv[0]);
- bundle_free(b);
- return -1;
- }
-
- __set_appinfo_for_debug_launchpad(b, argv[1]);
- g_idle_add(__run_cb, b);
- __run_mainloop();
- bundle_free(b);
-
- return 0;
-}
--- /dev/null
+SET(TARGET_LAUNCH_DEBUG "launch_debug")
+
+ADD_EXECUTABLE(${TARGET_LAUNCH_DEBUG} ${CMAKE_CURRENT_SOURCE_DIR}/launch_debug.c)
+SET_TARGET_PROPERTIES(${TARGET_LAUNCH_DEBUG} PROPERTIES COMPILE_FLAGS ${CFLAGS} "-fPIE")
+SET_TARGET_PROPERTIES(${TARGET_LAUNCH_DEBUG} PROPERTIES LINK_FLAGS "-pie")
+TARGET_LINK_LIBRARIES(${TARGET_LAUNCH_DEBUG} PRIVATE ${TARGET_AUL})
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_LAUNCH_DEBUG} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../src)
+TARGET_INCLUDE_DIRECTORIES(${TARGET_LAUNCH_DEBUG} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../include)
+
+INSTALL(TARGETS ${TARGET_LAUNCH_DEBUG} DESTINATION bin)
--- /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.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <string.h>
+
+#include <glib.h>
+#include <bundle.h>
+#include <bundle_internal.h>
+#include <pkgmgr-info.h>
+
+#include "aul.h"
+#include "aul_svc.h"
+#include "launch.h"
+
+#define LAUNCHPAD_PROCESS_POOL_SOCK ".launchpad-process-pool-sock"
+#define DLP_K_ATTACH_ARG "__DLP_ATTACH_ARG__"
+#define SDK_ATTACH "ATTACH"
+
+static GMainLoop *__mainloop;
+static bool __sync_mode;
+
+static bundle *create_internal_bundle(int argc, char **argv)
+{
+ bundle *b;
+ int i;
+ int j;
+ int cnt;
+ char *arg[1024] = {0, };
+
+ b = bundle_create();
+ if (b == NULL)
+ return NULL;
+
+ for (i = 2; i < argc - 1; i++) {
+ if ((i + 1) > (argc - 1)) {
+ bundle_add(b, argv[1], " ");
+ } else if (argv[i] && strcmp(argv[i], AUL_K_SDK) == 0) {
+ bundle_add(b, AUL_K_SDK, argv[i + 1]);
+ } else if (argv[i] && strcmp(argv[i], DLP_K_ATTACH_ARG) == 0) {
+ arg[0] = strtok(argv[i + 1], ",");
+
+ cnt = 1;
+ while ((arg[cnt] = strtok(NULL, ",")) != NULL)
+ cnt++;
+
+ bundle_add(b, SDK_ATTACH, DLP_K_ATTACH_ARG);
+ bundle_add_str_array(b, DLP_K_ATTACH_ARG, NULL, cnt);
+
+ for (j = 0; j < cnt; j++) {
+ bundle_set_str_array_element(b,
+ DLP_K_ATTACH_ARG, j, arg[j]);
+ }
+ } else if (argv[i] && !strcmp(argv[i], "__LAUNCH_APP_MODE__")) {
+ if (argv[i + 1] && !strcmp(argv[i + 1], "SYNC"))
+ __sync_mode = true;
+ }
+ }
+
+ return b;
+}
+
+static void print_usage(char *progname)
+{
+ printf("[usage] %s [appid] %s <debugger name> %s --attach,:[port],[pid]\n",
+ progname, AUL_K_SDK, DLP_K_ATTACH_ARG);
+ printf("ex) $ %s [appid] %s %s %s --attach,:10003,1234\n",
+ progname, AUL_K_SDK, SDK_ATTACH, DLP_K_ATTACH_ARG);
+}
+
+static int __get_gles(void)
+{
+ FILE *fp;
+ char buf[PATH_MAX];
+ char *tmp;
+ int gles = 1;
+
+ fp = fopen("/proc/cmdline", "r");
+ if (fp == NULL)
+ return gles;
+
+ if (fgets(buf, sizeof(buf), fp) != NULL) {
+ tmp = strstr(buf, "gles");
+ if (tmp != NULL)
+ sscanf(tmp, "gles=%d", &gles);
+ }
+
+ fclose(fp);
+
+ return gles;
+}
+
+static void __set_pkg_api_version(bundle *kb, const char *pkgid)
+{
+ int ret;
+ char *api_version;
+ pkgmgrinfo_pkginfo_h handle;
+
+ ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
+ if (ret != PMINFO_R_OK)
+ return;
+
+ ret = pkgmgrinfo_pkginfo_get_api_version(handle, &api_version);
+ if (ret != PMINFO_R_OK) {
+ pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+ return;
+ }
+
+ printf("pkg api_version: %s\n", api_version);
+ bundle_add(kb, AUL_K_API_VERSION, api_version);
+ pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+}
+
+static int __set_appinfo_for_debug_launchpad(bundle *kb, const char *appid)
+{
+ pkgmgrinfo_appinfo_h handle;
+ int ret;
+ char *pkgid;
+ char *exec;
+ char *apptype;
+ char *pkgtype;
+ char *component_type;
+ pkgmgrinfo_app_hwacceleration hwacc = PMINFO_HWACCELERATION_OFF;
+ const char *hwacc_str = "NOT_USE";
+ bool process_pool = false;
+ char buf[12];
+
+ if (kb == NULL)
+ return -1;
+
+ ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, getuid(), &handle);
+ if (ret != PMINFO_R_OK)
+ return -1;
+
+ ret = pkgmgrinfo_appinfo_get_exec(handle, &exec);
+ if (ret != PMINFO_R_OK)
+ goto end;
+
+ ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
+ if (ret != PMINFO_R_OK)
+ goto end;
+
+ ret = pkgmgrinfo_appinfo_get_apptype(handle, &apptype);
+ if (ret != PMINFO_R_OK)
+ goto end;
+
+ ret = pkgmgrinfo_appinfo_get_pkgtype(handle, &pkgtype);
+ if (ret != PMINFO_R_OK)
+ goto end;
+
+ ret = pkgmgrinfo_appinfo_get_component_type(handle, &component_type);
+ if (ret != PMINFO_R_OK)
+ goto end;
+
+ ret = pkgmgrinfo_appinfo_get_hwacceleration(handle, &hwacc);
+ if (ret != PMINFO_R_OK)
+ goto end;
+
+ ret = pkgmgrinfo_appinfo_is_process_pool(handle, &process_pool);
+ if (ret != PMINFO_R_OK)
+ goto end;
+
+ if (__get_gles()) {
+ if (hwacc == PMINFO_HWACCELERATION_OFF)
+ hwacc_str = "NOT_USE";
+ else if (hwacc == PMINFO_HWACCELERATION_ON)
+ hwacc_str = "USE";
+ else
+ hwacc_str = "SYS";
+ }
+
+ bundle_add(kb, AUL_K_APPID, appid);
+ bundle_add(kb, AUL_K_HWACC, hwacc_str);
+ bundle_add(kb, AUL_K_EXEC, exec);
+ bundle_add(kb, AUL_K_APP_TYPE, apptype);
+ bundle_add(kb, AUL_K_PKGID, pkgid);
+ bundle_add(kb, AUL_K_INTERNAL_POOL, process_pool ? "true" : "false");
+ bundle_add(kb, AUL_K_COMP_TYPE, component_type);
+ bundle_add(kb, AUL_K_PACKAGETYPE, pkgtype);
+
+ __set_pkg_api_version(kb, pkgid);
+ aul_svc_set_loader_id(kb, PAD_LOADER_ID_DIRECT);
+
+ snprintf(buf, sizeof(buf), "%d", getpid());
+ bundle_add(kb, AUL_K_CALLER_PID, buf);
+
+end:
+ pkgmgrinfo_appinfo_destroy_appinfo(handle);
+
+ return 0;
+}
+
+static void __run_mainloop(void)
+{
+ __mainloop = g_main_loop_new(NULL, FALSE);
+ if (!__mainloop) {
+ printf("Failed to create glib main loop\n");
+ exit(EXIT_FAILURE);
+ }
+
+ g_main_loop_run(__mainloop);
+}
+
+static void __quit_mainloop(void)
+{
+ if (__mainloop) {
+ g_main_loop_quit(__mainloop);
+ g_main_loop_unref(__mainloop);
+ __mainloop = NULL;
+ }
+}
+
+static int __app_dead_handler(int pid, void *data)
+{
+ int launched_pid = GPOINTER_TO_INT(data);
+
+ if (launched_pid == pid)
+ __quit_mainloop();
+
+ return 0;
+}
+
+static gboolean __run_cb(gpointer data)
+{
+ bundle *b = (bundle *)data;
+ int ret;
+
+ if (!b)
+ return G_SOURCE_REMOVE;
+
+ ret = app_send_cmd_to_launchpad(LAUNCHPAD_PROCESS_POOL_SOCK,
+ getuid(), 0, b);
+ if (ret < 0)
+ printf("Failed to send launch request\n");
+
+ if (__sync_mode) {
+ aul_listen_app_dead_signal(__app_dead_handler,
+ GINT_TO_POINTER(ret));
+ return G_SOURCE_REMOVE;
+ }
+
+ __quit_mainloop();
+
+ return G_SOURCE_REMOVE;
+}
+
+int main(int argc, char **argv)
+{
+ bundle *b;
+
+ if (argc < 2) {
+ print_usage(argv[0]);
+ return -1;
+ }
+
+ b = create_internal_bundle(argc, argv);
+ if (b == NULL) {
+ printf("out of memory\n");
+ return -1;
+ }
+
+ if (bundle_get_type(b, AUL_K_SDK) == BUNDLE_TYPE_NONE) {
+ print_usage(argv[0]);
+ bundle_free(b);
+ return -1;
+ }
+
+ __set_appinfo_for_debug_launchpad(b, argv[1]);
+ g_idle_add(__run_cb, b);
+ __run_mainloop();
+ bundle_free(b);
+
+ return 0;
+}
+++ /dev/null
-/*
- * Copyright (c) 2000 - 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.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <string.h>
-#include <glib.h>
-
-#include <bundle_internal.h>
-
-#include "aul.h"
-
-#define ROOT_UID 0
-#define TMP_FILE "/tmp/.testpkg"
-
-static char **gargv;
-static int gargc;
-bundle *kb = NULL;
-static int debugFlag = 0;
-
-static GMainLoop *mainloop = NULL;
-
-static bundle *create_internal_bundle()
-{
- bundle *kb;
-
- kb = bundle_create();
- bundle_add(kb, AUL_K_DEBUG, "1");
- return kb;
-}
-
-int launch(int debug_option)
-{
- int pid;
-
- if (!debug_option)
- pid = aul_open_app(gargv[1]);
- else {
- kb = create_internal_bundle();
- if (kb == NULL) {
- printf("bundle creation fail\n");
- return -1;
- }
- pid = aul_launch_app(gargv[1], kb);
- }
- return pid;
-}
-
-void print_usage(char *progname)
-{
- printf("[usage] %s <appid> [-d]\n",
- progname);
-}
-
-static int __launch_app_dead_handler(int pid, void *data)
-{
- int listen_pid = (intptr_t)data;
-
- if (listen_pid == pid)
- g_main_loop_quit(mainloop);
-
- return 0;
-}
-
-static gboolean run_func(void *data)
-{
- int pid;
- const char *str;
-
- if ((pid = launch(debugFlag)) > 0)
- printf("... successfully launched\n");
- else
- printf("... launch failed\n");
-
- if (kb) {
- str = bundle_get_val(kb, "__LAUNCH_APP_MODE__");
-
- if (str && strcmp(str, "SYNC") == 0)
- aul_listen_app_dead_signal(__launch_app_dead_handler, (void *)(intptr_t)pid);
- else
- g_main_loop_quit(mainloop);
-
- bundle_free(kb);
- kb = NULL;
- } else {
- g_main_loop_quit(mainloop);
- }
-
-
- return TRUE;
-}
-
-
-int main(int argc, char **argv)
-{
- if ((argc < 2) || (argc > 3)) {
- print_usage(argv[0]);
- exit(EXIT_FAILURE);
- }
-
- gargc = argc;
- gargv = argv;
-
- if (argc == 3) {
- if ((strcmp(argv[2], "-d") != 0) && (strcmp(argv[1], "-d") != 0)) {
- printf("additionnal argument should be -d to enable debugging\n");
- print_usage(argv[0]);
- exit(EXIT_FAILURE);
- }
- debugFlag = 1;
- }
- aul_launch_init(NULL, NULL);
-
- g_idle_add(run_func, NULL);
-
- mainloop = g_main_loop_new(NULL, FALSE);
- if (!mainloop) {
- printf("failed to create glib main loop\n");
- exit(EXIT_FAILURE);
- }
- g_main_loop_run(mainloop);
-
- return 0;
-}
-
--- /dev/null
+SET(TARGET_OPEN_APP "open_app")
+
+ADD_EXECUTABLE(${TARGET_OPEN_APP} ${CMAKE_CURRENT_SOURCE_DIR}/open_app.c)
+SET_TARGET_PROPERTIES(${TARGET_OPEN_APP} PROPERTIES COMPILE_FLAGS ${CFLAGS} "-fPIE")
+SET_TARGET_PROPERTIES(${TARGET_OPEN_APP} PROPERTIES LINK_FLAGS "-pie")
+TARGET_LINK_LIBRARIES(${TARGET_OPEN_APP} PRIVATE ${TARGET_AUL})
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_OPEN_APP} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../src)
+TARGET_INCLUDE_DIRECTORIES(${TARGET_OPEN_APP} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../include)
+
+INSTALL(TARGETS ${TARGET_OPEN_APP} DESTINATION bin)
--- /dev/null
+/*
+ * Copyright (c) 2000 - 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.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <string.h>
+#include <glib.h>
+
+#include <bundle_internal.h>
+
+#include "aul.h"
+
+#define ROOT_UID 0
+#define TMP_FILE "/tmp/.testpkg"
+
+static char **gargv;
+static int gargc;
+bundle *kb = NULL;
+static int debugFlag = 0;
+
+static GMainLoop *mainloop = NULL;
+
+static bundle *create_internal_bundle()
+{
+ bundle *kb;
+
+ kb = bundle_create();
+ bundle_add(kb, AUL_K_DEBUG, "1");
+ return kb;
+}
+
+int launch(int debug_option)
+{
+ int pid;
+
+ if (!debug_option)
+ pid = aul_open_app(gargv[1]);
+ else {
+ kb = create_internal_bundle();
+ if (kb == NULL) {
+ printf("bundle creation fail\n");
+ return -1;
+ }
+ pid = aul_launch_app(gargv[1], kb);
+ }
+ return pid;
+}
+
+void print_usage(char *progname)
+{
+ printf("[usage] %s <appid> [-d]\n",
+ progname);
+}
+
+static int __launch_app_dead_handler(int pid, void *data)
+{
+ int listen_pid = (intptr_t)data;
+
+ if (listen_pid == pid)
+ g_main_loop_quit(mainloop);
+
+ return 0;
+}
+
+static gboolean run_func(void *data)
+{
+ int pid;
+ const char *str;
+
+ if ((pid = launch(debugFlag)) > 0)
+ printf("... successfully launched\n");
+ else
+ printf("... launch failed\n");
+
+ if (kb) {
+ str = bundle_get_val(kb, "__LAUNCH_APP_MODE__");
+
+ if (str && strcmp(str, "SYNC") == 0)
+ aul_listen_app_dead_signal(__launch_app_dead_handler, (void *)(intptr_t)pid);
+ else
+ g_main_loop_quit(mainloop);
+
+ bundle_free(kb);
+ kb = NULL;
+ } else {
+ g_main_loop_quit(mainloop);
+ }
+
+
+ return TRUE;
+}
+
+
+int main(int argc, char **argv)
+{
+ if ((argc < 2) || (argc > 3)) {
+ print_usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ gargc = argc;
+ gargv = argv;
+
+ if (argc == 3) {
+ if ((strcmp(argv[2], "-d") != 0) && (strcmp(argv[1], "-d") != 0)) {
+ printf("additionnal argument should be -d to enable debugging\n");
+ print_usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+ debugFlag = 1;
+ }
+ aul_launch_init(NULL, NULL);
+
+ g_idle_add(run_func, NULL);
+
+ mainloop = g_main_loop_new(NULL, FALSE);
+ if (!mainloop) {
+ printf("failed to create glib main loop\n");
+ exit(EXIT_FAILURE);
+ }
+ g_main_loop_run(mainloop);
+
+ return 0;
+}
+
-CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
-PROJECT(aul-db-recovery C)
-
-SET(PREFIX "${CMAKE_INSTALL_PREFIX}")
-SET(EXEC_PREFIX "\${prefix}")
-SET(PROJECT_NAME "${PROJECT_NAME}")
-SET(LIBDIR ${LIB_INSTALL_DIR})
-SET(INCLUDEDIR "\${prefix}/include")
-SET(VERSION ${FULLVER})
-
-INCLUDE(FindPkgConfig)
-SET(requires "dlog sqlite3 libsmack libtzplatform-config")
-pkg_check_modules(aul-db-recovery REQUIRED ${requires})
-
-FOREACH(flag ${aul-db-recovery_CFLAGS})
- SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
-ENDFOREACH(flag)
-SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall -Werror -Winline")
-
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../src)
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../include)
-
-ADD_EXECUTABLE(appsvc-db-recovery
- ${CMAKE_CURRENT_SOURCE_DIR}/appsvc_db_recovery.c
- ${CMAKE_CURRENT_SOURCE_DIR}/../../src/aul_db.c)
-TARGET_LINK_LIBRARIES(appsvc-db-recovery ${aul-db-recovery_LDFLAGS} "-pie")
-INSTALL(TARGETS appsvc-db-recovery DESTINATION bin)
-
-ADD_EXECUTABLE(component-db-recovery
- ${CMAKE_CURRENT_SOURCE_DIR}/component_db_recovery.c
- ${CMAKE_CURRENT_SOURCE_DIR}/../../src/aul_db.c)
-TARGET_LINK_LIBRARIES(component-db-recovery ${aul-db-recovery_LDFLAGS} "-pie")
-INSTALL(TARGETS component-db-recovery DESTINATION bin)
+########################
+## appsvc-db-recovery ##
+########################
+SET(TARGET_APPSVC_DB_RECOVERY "appsvc-db-recovery")
+ADD_EXECUTABLE(${TARGET_APPSVC_DB_RECOVERY}
+ ${CMAKE_CURRENT_SOURCE_DIR}/appsvc_db_recovery.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../src/aul_db.c)
+SET_TARGET_PROPERTIES(${TARGET_APPSVC_DB_RECOVERY} PROPERTIES COMPILE_FLAGS ${CFLAGS} "-fPIE")
+SET_TARGET_PROPERTIES(${TARGET_APPSVC_DB_RECOVERY} PROPERTIES LINK_FLAGS "-pie")
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_APPSVC_DB_RECOVERY} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../src)
+
+APPLY_PKG_CONFIG(${TARGET_APPSVC_DB_RECOVERY} PUBLIC
+ DLOG_DEPS
+ SQLITE3_DEPS
+ LIBSMACK_DEPS
+ LIBTZPLATFORM_CONFIG_DEPS)
+
+INSTALL(TARGETS ${TARGET_APPSVC_DB_RECOVERY} DESTINATION bin)
+
+###########################
+## component-db-recovery ##
+###########################
+SET(TARGET_COMPONENT_DB_RECOVERY "component-db-recovery")
+
+ADD_EXECUTABLE(${TARGET_COMPONENT_DB_RECOVERY}
+ ${CMAKE_CURRENT_SOURCE_DIR}/component_db_recovery.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../src/aul_db.c)
+SET_TARGET_PROPERTIES(${TARGET_COMPONENT_DB_RECOVERY} PROPERTIES COMPILE_FLAGS ${CFLAGS} "-fPIE")
+SET_TARGET_PROPERTIES(${TARGET_COMPONENT_DB_RECOVERY} PROPERTIES LINK_FLAGS "-pie")
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_COMPONENT_DB_RECOVERY} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../src)
+
+APPLY_PKG_CONFIG(${TARGET_COMPONENT_DB_RECOVERY} PUBLIC
+ DLOG_DEPS
+ SQLITE3_DEPS
+ LIBSMACK_DEPS
+ LIBTZPLATFORM_CONFIG_DEPS)
+
+INSTALL(TARGETS ${TARGET_COMPONENT_DB_RECOVERY} DESTINATION bin)