The following directories are moved to the src directory.
- aul
- server
- parser
- tool
The include directory is moved to the src/aul directory.
The source codes will have the following directory structure:
aul-1/src
|---aul
|---parser
|---server
+---tool
Change-Id: I0f29482336759eea00cbbdef0b8d15bc11eccbc4
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
ADD_DEFINITIONS("-DLIBDIR=\"${LIBDIR}\"")
## Compile flags
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-zdefs -fvisibility=hidden -g -Wall -Werror -fpic ")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-zdefs")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fpic")
SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
SET(CMAKE_C_FLAGS_RELEASE "-O2")
SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
-SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
+SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
+ "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
## Target
SET(TARGET_AUL "aul")
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_control AUL_APP_CONTROL_SRCS)
-AUX_SOURCE_DIRECTORY(aul/app_group AUL_APP_GROUP_SRCS)
-AUX_SOURCE_DIRECTORY(aul/app_info AUL_APP_INFO_SRCS)
-AUX_SOURCE_DIRECTORY(aul/app_manager AUL_APP_MANAGER_SRCS)
-AUX_SOURCE_DIRECTORY(aul/common AUL_COMMON_SRCS)
-AUX_SOURCE_DIRECTORY(aul/component AUL_COMPONENT_SRCS)
-AUX_SOURCE_DIRECTORY(aul/socket AUL_SOCKET_SRCS)
-
-ADD_LIBRARY(${TARGET_AUL} SHARED
- ${SRCS}
- ${AUL_SRCS}
- ${AUL_API_SRCS}
- ${AUL_APP_CONTROL_SRCS}
- ${AUL_APP_GROUP_SRCS}
- ${AUL_APP_MANAGER_SRCS}
- ${AUL_APP_INFO_SRCS}
- ${AUL_COMMON_SRCS}
- ${AUL_COMPONENT_SRCS}
- ${AUL_SOCKET_SRCS}
- ${AUL_BOOT_SEQUENCE_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_control
- ${CMAKE_CURRENT_SOURCE_DIR}/aul/app_manager
- ${CMAKE_CURRENT_SOURCE_DIR}/aul/common
- ${CMAKE_CURRENT_SOURCE_DIR}/aul/component
- ${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
- CAPI_SYSTEM_RESOURCE_DEPS
- DLOG_DEPS
- GIO_DEPS
- GLIB_DEPS
- INIPARSER_DEPS
- LIBSMACK_DEPS
- LIBTZPLATFORM_CONFIG_DEPS
- LIBXML_DEPS
- PARCEL_DEPS
- PKGMGR_INFO_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)
-CONFIGURE_FILE(data/appsvc_db.sql.in data/appsvc_db.sql @ONLY)
-CONFIGURE_FILE(scripts/12_appsvc-add.post.in scripts/12_appsvc-add.post @ONLY)
-CONFIGURE_FILE(scripts/501.appsvc_db_upgrade.sh.in scripts/501.appsvc_db_upgrade.sh @ONLY)
-CONFIGURE_FILE(scripts/upgrade/1_appsvc_db_upgrade.sh.in scripts/upgrade/1_appsvc_db_upgrade.sh @ONLY)
-CONFIGURE_FILE(scripts/upgrade/2_appsvc_db_upgrade.sh.in scripts/upgrade/2_appsvc_db_upgrade.sh @ONLY)
+CONFIGURE_FILE(feature/preexec_list.txt.in
+ feature/preexec_list.txt @ONLY)
+CONFIGURE_FILE(data/appsvc_db.sql.in
+ data/appsvc_db.sql @ONLY)
+CONFIGURE_FILE(scripts/12_appsvc-add.post.in
+ scripts/12_appsvc-add.post @ONLY)
+CONFIGURE_FILE(scripts/501.appsvc_db_upgrade.sh.in
+ scripts/501.appsvc_db_upgrade.sh @ONLY)
+CONFIGURE_FILE(scripts/upgrade/1_appsvc_db_upgrade.sh.in
+ scripts/upgrade/1_appsvc_db_upgrade.sh @ONLY)
+CONFIGURE_FILE(scripts/upgrade/2_appsvc_db_upgrade.sh.in
+ scripts/upgrade/2_appsvc_db_upgrade.sh @ONLY)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/scripts/501.appsvc_db_upgrade.sh
DESTINATION /usr/share/upgrade/scripts)
DESTINATION /etc/aul/upgrade/scripts)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/scripts/upgrade/2_appsvc_db_upgrade.sh
DESTINATION /etc/aul/upgrade/scripts)
-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"
-)
+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 )
## Sub directories
-ADD_SUBDIRECTORY(parser)
-ADD_SUBDIRECTORY(server)
+ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(test)
-ADD_SUBDIRECTORY(tool)
+++ /dev/null
-<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
- "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
-<busconfig>
- <policy context="default">
- <deny own="org.tizen.aul.AppStatus"/>
- <deny send_type="method_call" send_destination="org.tizen.aul.AppStatus"/>
- <deny send_type="signal" send_interface="org.tizen.aul.AppStatus"/>
- </policy>
- <policy user="app_fw">
- <allow own="org.tizen.aul.AppStatus"/>
- <allow send_type="signal" send_interface="org.tizen.aul.AppStatus"/>
- </policy>
- <policy user="root">
- <allow own="org.tizen.aul.AppStatus"/>
- </policy>
-</busconfig>
+++ /dev/null
-# Package Information for pkg-config
-
-prefix=@PREFIX@
-exec_prefix=@EXEC_PREFIX@
-libdir=@LIB_INSTALL_DIR@
-includedir=@INCLUDE_INSTALL_DIR@
-
-Name: libaul
-Description: new application utility library
-Version: @VERSION@
-Requires: bundle glib-2.0 xdgmime vconf dlog
-Libs: -L${libdir} -laul
-Cflags: -I${includedir} -I${includedir}/aul -I${includedir}/aul/api
+++ /dev/null
-/*
- * Copyright (c) 2020 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 <aul.h>
-#include <sys/types.h>
-#include <tizen.h>
-#include <unistd.h>
-
-#include <memory>
-
-#include "aul/api/aul_app_context.h"
-#include "aul/app_manager/app_manager.hh"
-#include "aul/common/api.hh"
-#include "aul/common/log_private.hh"
-
-using namespace aul;
-
-extern "C" API int aul_app_context_create(const char *app_id,
- aul_app_context_h* app_context) {
- if (!app_id || !app_context) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- char caller_id[256] = { 0, };
- int ret = aul_app_get_appid_bypid(getpid(), caller_id, sizeof(caller_id));
- if (ret == AUL_R_OK) {
- if (!strcmp(caller_id, app_id)) {
- _W("Same Application(%s)", app_id);
- return aul_app_context_create_with_pid(getpid(), app_context);
- }
- }
-
- AppManager app_manager;
- auto handle = app_manager.GetAppContext(app_id);
- if (get_last_result() != AUL_R_OK) {
- _E("Failed to get app context");
- return get_last_result();
- }
-
- *app_context = handle.release();
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_app_context_create_with_inst_id(
- const char* app_id,
- const char* inst_id,
- aul_app_context_h* app_context) {
- if (!app_id || !inst_id || !app_context) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- AppManager app_manager;
- auto handle = app_manager.GetAppContext(app_id, inst_id);
- if (get_last_result() != AUL_R_OK) {
- _E("Failed to get app context");
- return get_last_result();
- }
-
- *app_context = handle.release();
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_app_context_create_with_pid(int pid,
- aul_app_context_h* app_context) {
- if (pid < 2 || !app_context) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- AppManager app_manager;
- auto handle = app_manager.GetAppContext(pid);
- if (get_last_result() != AUL_R_OK) {
- _E("Failed to get app context");
- return get_last_result();
- }
-
- *app_context = handle.release();
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_app_context_destroy(aul_app_context_h app_context) {
- if (!app_context) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* handle = static_cast<AppContext*>(app_context);
- delete handle;
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_app_context_clone(aul_app_context_h app_context,
- aul_app_context_h* clone) {
- if (!app_context || !clone) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* handle = static_cast<AppContext*>(app_context);
- AppContext::Builder builder;
- builder.SetAppId(handle->GetAppId());
- builder.SetPkgId(handle->GetPkgId());
- builder.SetInstId(handle->GetInstId());
- builder.SetExec(handle->GetExec());
- builder.SetPid(handle->GetPid());
- builder.SetStatus(handle->GetStatus());
- builder.SetIsSubApp(handle->IsSubApp());
-
- *clone = std::make_unique<AppContext>(builder.Build()).release();
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_app_context_get_app_id(aul_app_context_h app_context,
- char** app_id) {
- if (!app_context || !app_id) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* handle = static_cast<AppContext*>(app_context);
- *app_id = strdup(handle->GetAppId().c_str());
- if (*app_id == nullptr) {
- _E("Failed to duplicate application ID");
- return AUL_R_ENOMEM;
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_app_context_get_pkg_id(aul_app_context_h app_context,
- char** pkg_id) {
- if (!app_context || !pkg_id) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* handle = static_cast<AppContext*>(app_context);
- *pkg_id = strdup(handle->GetPkgId().c_str());
- if (*pkg_id == nullptr) {
- _E("Failed to duplicate package ID");
- return AUL_R_ENOMEM;
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_app_context_get_inst_id(aul_app_context_h app_context,
- char** inst_id) {
- if (!app_context || !inst_id) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* handle = static_cast<AppContext*>(app_context);
- *inst_id = strdup(handle->GetInstId().c_str());
- if (*inst_id == nullptr) {
- _E("Failed to duplicate instance ID");
- return AUL_R_ENOMEM;
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_app_context_get_app_path(aul_app_context_h app_context,
- char** app_path) {
- if (!app_context || !app_path) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* handle = static_cast<AppContext*>(app_context);
- *app_path = strdup(handle->GetExec().c_str());
- if (*app_path == nullptr) {
- _E("Failed to duplicate app path");
- return AUL_R_ENOMEM;
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_app_context_get_pid(aul_app_context_h app_context,
- int* pid) {
- if (!app_context || !pid) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* handle = static_cast<AppContext*>(app_context);
- *pid = handle->GetPid();
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_app_context_get_status(aul_app_context_h app_context,
- int* status) {
- if (!app_context || !status) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* handle = static_cast<AppContext*>(app_context);
- *status = handle->GetStatus();
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_app_context_is_sub_app(aul_app_context_h app_context,
- bool* is_sub_app) {
- if (!app_context || !is_sub_app) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* handle = static_cast<AppContext*>(app_context);
- *is_sub_app = handle->IsSubApp();
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_app_context_is_running(aul_app_context_h app_context,
- bool* is_running) {
- if (!app_context || !is_running) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* handle = static_cast<AppContext*>(app_context);
- int ret = aul_app_is_running(handle->GetAppId().c_str());
- if (ret == 1) {
- *is_running = true;
- } else {
- char app_id[256] = { 0, };
- int ret = aul_app_get_appid_bypid(handle->GetPid(), app_id, sizeof(app_id));
- if (ret == AUL_R_OK)
- *is_running = true;
- else
- *is_running = false;
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_app_context_is_equal(aul_app_context_h lhs,
- aul_app_context_h rhs,
- bool* equal) {
- if (!lhs || !rhs || !equal) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* lh = static_cast<AppContext*>(lhs);
- auto* rh = static_cast<AppContext*>(rhs);
- if (lh->GetAppId() == rh->GetAppId() && lh->GetPid() == rh->GetPid())
- *equal = true;
- else
- *equal = false;
-
- return AUL_R_OK;
-}
+++ /dev/null
-/*
- * Copyright (c) 2020 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_API_AUL_APP_CONTEXT_H_
-#define AUL_API_AUL_APP_CONTEXT_H_
-
-#include <aul.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef void *aul_app_context_h;
-
-int aul_app_context_create(const char *app_id, aul_app_context_h *app_context);
-
-int aul_app_context_create_with_inst_id(const char *app_id, const char *inst_id,
- aul_app_context_h *app_context);
-
-int aul_app_context_create_with_pid(int pid, aul_app_context_h *app_context);
-
-int aul_app_context_destroy(aul_app_context_h app_context);
-
-int aul_app_context_clone(aul_app_context_h app_context,
- aul_app_context_h *clone);
-
-int aul_app_context_get_app_id(aul_app_context_h app_context, char **app_id);
-
-int aul_app_context_get_pkg_id(aul_app_context_h app_context, char **pkg_id);
-
-int aul_app_context_get_inst_id(aul_app_context_h app_context, char **inst_id);
-
-int aul_app_context_get_app_path(aul_app_context_h app_context,
- char **app_path);
-
-int aul_app_context_get_pid(aul_app_context_h app_context, int *pid);
-
-int aul_app_context_get_status(aul_app_context_h app_context, int *status);
-
-int aul_app_context_is_sub_app(aul_app_context_h app_context, bool *is_sub_app);
-
-int aul_app_context_is_running(aul_app_context_h app_context, bool *is_running);
-
-int aul_app_context_is_equal(aul_app_context_h lhs, aul_app_context_h rhs,
- bool *equal);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // AUL_API_AUL_APP_CONTEXT_HH_
+++ /dev/null
-/*
- * Copyright (c) 2020 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 "aul/api/aul_app_event.h"
-
-#include <glib.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include <string>
-#include <utility>
-
-#include "aul/app_manager/app_event.hh"
-#include "aul/common/api.hh"
-#include "aul/common/exception.hh"
-#include "aul/common/log_private.hh"
-
-namespace {
-using namespace aul;
-
-class AppEventStub : public AppEvent,
- public AppEvent::IEvent {
- public:
- AppEventStub(std::string app_id,
- aul_app_event_launched_cb launched_cb,
- aul_app_event_terminated_cb terminated_cb,
- void* user_data)
- : AppEvent(std::move(app_id), this),
- launched_cb_(launched_cb),
- terminated_cb_(terminated_cb),
- user_data_(user_data) {
- }
-
- AppEventStub(aul_app_event_launched_cb launched_cb,
- aul_app_event_terminated_cb terminated_cb,
- void* user_data)
- : AppEvent(this),
- launched_cb_(launched_cb),
- terminated_cb_(terminated_cb),
- user_data_(user_data) {
- }
-
- void OnAppLaunched(const AppContext* context) override {
- if (disposing_)
- return;
-
- AppContext* ctx = const_cast<AppContext*>(context);
- launched_cb_(static_cast<aul_app_context_h>(ctx), user_data_);
- }
-
- void OnAppTerminated(const AppContext* context) override {
- if (disposing_)
- return;
-
- AppContext* ctx = const_cast<AppContext*>(context);
- terminated_cb_(static_cast<aul_app_context_h>(ctx), user_data_);
- }
-
- void Dispose() {
- if (disposing_)
- return;
-
- disposing_ = true;
- g_idle_add_full(G_PRIORITY_HIGH,
- [](gpointer user_data) {
- auto* event = static_cast<AppEventStub*>(user_data);
- delete event;
- return G_SOURCE_REMOVE;
- }, this, nullptr);
- }
-
- private:
- bool disposing_ = false;
- aul_app_event_launched_cb launched_cb_;
- aul_app_event_terminated_cb terminated_cb_;
- void* user_data_;
-};
-
-} // namespace
-
-extern "C" API int aul_app_event_create_with_appid(const char* app_id,
- aul_app_event_launched_cb launched_cb,
- aul_app_event_terminated_cb terminated_cb,
- void* user_data,
- aul_app_event_h* app_event) {
- if (!app_id || !launched_cb || !terminated_cb || !app_event) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- AppEventStub* handle = nullptr;
- try {
- handle = new AppEventStub(app_id, launched_cb, terminated_cb, user_data);
- handle->Listen();
- } catch (Exception& e) {
- return e.GetErrorCode();
- }
-
- *app_event = static_cast<aul_app_event_h>(handle);
- return AUL_R_OK;
-}
-
-extern "C" API int aul_app_event_create(aul_app_event_launched_cb launched_cb,
- aul_app_event_terminated_cb terminated_cb,
- void* user_data,
- aul_app_event_h* app_event) {
- if (!launched_cb || !terminated_cb || !app_event) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- AppEventStub* handle = nullptr;
- try {
- handle = new AppEventStub(launched_cb, terminated_cb, user_data);
- handle->Listen();
- } catch (Exception& e) {
- return e.GetErrorCode();
- }
-
- *app_event = static_cast<aul_app_event_h>(handle);
- return AUL_R_OK;
-}
-
-extern "C" API int aul_app_event_destroy(aul_app_event_h app_event) {
- if (!app_event) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* handle = static_cast<AppEventStub*>(app_event);
- if (getpid() == gettid())
- delete handle;
- else
- handle->Dispose();
-
- return AUL_R_OK;
-}
+++ /dev/null
-/*
- * Copyright (c) 2020 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_API_AUL_APP_EVENT_H_
-#define AUL_API_AUL_APP_EVENT_H_
-
-#include <aul.h>
-#include <aul_app_context.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef void *aul_app_event_h;
-
-typedef void (*aul_app_event_launched_cb)(aul_app_context_h app_context,
- void *user_data);
-
-typedef void (*aul_app_event_terminated_cb)(aul_app_context_h app_context,
- void *user_data);
-
-int aul_app_event_create_with_appid(const char *app_id,
- aul_app_event_launched_cb launched_cb,
- aul_app_event_terminated_cb terminated_cb,
- void *user_data,
- aul_app_event_h *app_event);
-
-int aul_app_event_create(aul_app_event_launched_cb launched_cb,
- aul_app_event_terminated_cb terminated_cb,
- void *user_data,
- aul_app_event_h *app_event);
-
-int aul_app_event_destroy(aul_app_event_h app_event);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // AUL_API_AUL_APP_EVENT_HH_
+++ /dev/null
-/*
- * Copyright (c) 2021 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 <bundle_cpp.h>
-
-#include <memory>
-#include <stdexcept>
-#include <string>
-
-#include "aul/api/aul_app_lifecycle.h"
-#include "aul/common/api.hh"
-#include "aul/common/exception.hh"
-#include "aul/socket/client.hh"
-#include "include/aul.h"
-#include "include/aul_app_com.h"
-#include "include/aul_cmd.h"
-#include "include/aul_error.h"
-#include "include/aul_sock.h"
-
-namespace {
-
-class EventListener {
- public:
- EventListener() {
- }
-
- ~EventListener() {
- Deregister();
- }
-
- int Register(aul_app_lifecycle_state_changed_cb cb, void* user_data) {
- cb_ = cb;
- user_data_ = user_data;
-
- if (conn_ != nullptr) {
- _W("Callback was already registered.");
- return AUL_R_OK;
- }
-
- int ret = aul_app_com_create_async("app_lifecycle_state_change", nullptr,
- AppComMessageCb, this, &conn_);
- if (ret != AUL_R_OK) {
- _E("aul_app_com_create_async() is failed. error(%d)", ret);
- return ret;
- }
-
- return AUL_R_OK;
- }
-
- int Deregister() {
- if (conn_ == nullptr)
- return AUL_R_OK;
-
- aul_app_com_leave(conn_);
- conn_ = nullptr;
- return AUL_R_OK;
- }
-
- private:
- static int AppComMessageCb(const char* endpoint, aul_app_com_result_e res,
- bundle* envelope, void* user_data) {
- tizen_base::Bundle b(envelope, false, false);
- std::string app_id = b.GetString(AUL_K_APPID);
- pid_t pid = std::stoi(b.GetString(AUL_K_PID));
- int state = std::stoi(b.GetString(AUL_K_STATE));
- std::string has_focus = b.GetString(AUL_K_HAS_FOCUS);
-
- auto* handle = static_cast<EventListener*>(user_data);
- if (handle->cb_) {
- handle->cb_(app_id.c_str(), pid,
- static_cast<aul_app_lifecycle_state_e>(state),
- has_focus == "true" ? true : false,
- handle->user_data_);
- }
-
- return 0;
- }
-
- private:
- aul_app_com_connection_h conn_ = nullptr;
- aul_app_lifecycle_state_changed_cb cb_ = nullptr;
- void* user_data_ = nullptr;
-};
-
-EventListener listener;
-
-} // namespace
-
-extern "C" API int aul_app_lifecycle_register_state_changed_cb(
- aul_app_lifecycle_state_changed_cb callback, void *user_data) {
- if (callback == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- return listener.Register(callback, user_data);
-}
-
-extern "C" API int aul_app_lifecycle_deregister_state_changed_cb(void) {
- return listener.Deregister();
-}
-
-extern "C" API int aul_app_lifecycle_update_state(
- aul_app_lifecycle_state_e state) {
- tizen_base::Bundle b;
- b.Add(AUL_K_STATE, std::to_string(static_cast<int>(state)));
- aul::Packet packet(APP_LIFECYCLE_UPDATE_STATE,
- AUL_SOCK_NOREPLY | AUL_SOCK_BUNDLE, b);
- try {
- aul::Client client(aul::PATH_AMD_SOCK);
- int ret = client.Send(packet);
- if (ret < 0)
- return aul_error_convert(ret);
- } catch (aul::Exception& e) {
- return aul_error_convert(e.GetErrorCode());
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_app_lifecycle_get_state(const char* app_id,
- aul_app_lifecycle_state_e* state) {
- if (app_id == nullptr || state == nullptr) {
- _E("Invalid prameter");
- return AUL_R_EINVAL;
- }
-
- tizen_base::Bundle b;
- b.Add(AUL_K_APPID, app_id);
- aul::Packet* recv_pkt = nullptr;
- aul::Packet packet(APP_LIFECYCLE_GET_STATE, AUL_SOCK_BUNDLE, b);
- try {
- aul::Client client(aul::PATH_AMD_SOCK);
- int ret = client.Send(packet);
- if (ret < 0)
- return aul_error_convert(ret);
-
- ret = client.Recv(&recv_pkt);
- if (ret < 0)
- return aul_error_convert(ret);
-
- std::unique_ptr<aul::Packet> pkt_auto(recv_pkt);
- if (recv_pkt->GetCmd() != APP_GET_INFO_OK) {
- _E("Failed to get app lifecycle state");
- return AUL_R_ERROR;
- }
-
- tizen_base::Bundle res_b = recv_pkt->DataToBundle();
- std::string val = res_b.GetString(AUL_K_STATE);
- if (!val.empty())
- *state = static_cast<aul_app_lifecycle_state_e>(std::stoi(val));
- } catch (std::invalid_argument& e) {
- _E("Out of memory");
- return AUL_R_ENOMEM;
- } catch (aul::Exception& e) {
- _E("Exception(%s) occurs", e.what());
- return aul_error_convert(e.GetErrorCode());
- }
-
- return AUL_R_OK;
-}
+++ /dev/null
-/*
- * Copyright (c) 2021 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_API_AUL_APP_LIFECYCLE_H_
-#define AUL_API_AUL_APP_LIFECYCLE_H_
-
-#include <stdbool.h>
-#include <aul.h>
-#include <tizen.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @brief Enumeration for application lifecycle state.
- * @since_tizen 6.5
- */
-typedef enum {
- AUL_APP_LIFECYCLE_STATE_INITIALIZED, /**< The application is initialized. */
- AUL_APP_LIFECYCLE_STATE_CREATED, /**< The application is created. */
- AUL_APP_LIFECYCLE_STATE_RESUMED, /**< The application is resumed. */
- AUL_APP_LIFECYCLE_STATE_PAUSED, /**< The application is paused. */
- AUL_APP_LIFECYCLE_STATE_DESTROYED, /**< The application is terminated. */
-} aul_app_lifecycle_state_e;
-
-/**
- * @brief Called when the state of the application is changed.
- * @since_tizen 6.5
- * @param[in] app_id The application ID
- * @param[in] pid The process ID
- * @param[in] state The state of the application lifecycle
- * @param[in] has_focus If it's true, the application has focus
- * @param[in] user_data The user data passed from the registration function
- * @see aul_app_lifecycle_register_state_changed_cb()
- * @see aul_app_lifecycle_deregister_state_changed_cb()
- */
-typedef void (*aul_app_lifecycle_state_changed_cb)(const char *app_id, pid_t pid, aul_app_lifecycle_state_e state, bool has_focus, void *user_data);
-
-/**
- * @breif Registers a callback function to be invoked when the state of the application is changed.
- * @details To deregister the callback function, you have to call aul_app_lifecycle_deregister_state_changed_cb().
- * @since_tizen 6.5
- * @param[in] callback The callback function
- * @param[in] user_data The user data to be passed to the callback function
- * @return @c 0 on success,
- * otherwise a negative error value
- * @see aul_app_lifecycle_state_changed_cb()
- * @see aul_app_lifecycle_deregister_state_changed_cb()
- */
-int aul_app_lifecycle_register_state_changed_cb(aul_app_lifecycle_state_changed_cb callback, void *user_data);
-
-/**
- * @brief Deregister the callback function.
- * @since_tizen 6.5
- * @return @c 0 on success,
- * otherwise a negative error value
- * @see aul_app_lifecycle_register_state_changed_cb()
- */
-int aul_app_lifecycle_deregister_state_changed_cb(void);
-
-/**
- * @brief Updates the state of the application lifecycle.
- * @since_tizen 6.5
- * @param[in] state The state of the application lifecycle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @see #aul_app_lifecycle_state_e
- */
-int aul_app_lifecycle_update_state(aul_app_lifecycle_state_e state);
-
-/**
- * @brief Gets the state of the application lifecycle of the given application ID.
- * @since_tizen 6.5
- * @param[in] app_id The application ID
- * @param[out] state The state of the application lifecycle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @see #aul_app_lifecycle_state_e
- */
-int aul_app_lifecycle_get_state(const char *app_id, aul_app_lifecycle_state_e *state);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // AUL_API_AUL_APP_LIFECYCLE_HH_
+++ /dev/null
-/*
- * Copyright (c) 2020 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 <tizen.h>
-
-#include "aul/api/aul_app_manager.h"
-#include "aul/app_manager/app_manager.hh"
-#include "aul/common/api.hh"
-#include "aul/common/log_private.hh"
-
-using namespace aul;
-
-extern "C" API int aul_app_manager_foreach_app_context(
- aul_app_manager_app_context_cb callback,
- void* user_data) {
- if (!callback) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- AppManager app_manager;
- for (auto& i : app_manager.GetAppContexts()) {
- if (!callback(static_cast<AppContext*>(i.get()), user_data))
- break;
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_app_manager_foreach_all_app_context(
- aul_app_manager_app_context_cb callback,
- void* user_data) {
- if (!callback) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- AppManager app_manager;
- for (auto& i : app_manager.GetAllAppContexts()) {
- if (!callback(static_cast<AppContext*>(i.get()), user_data))
- break;
- }
-
- return AUL_R_OK;
-}
+++ /dev/null
-/*
- * Copyright (c) 2020 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_API_AUL_APP_MANAGER_H_
-#define AUL_API_AUL_APP_MANAGER_H_
-
-#include <stdbool.h>
-
-#include <aul.h>
-#include <aul_app_context.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef bool (*aul_app_manager_app_context_cb)(aul_app_context_h app_context,
- void *user_data);
-
-int aul_app_manager_foreach_app_context(aul_app_manager_app_context_cb callback,
- void *user_data);
-
-int aul_app_manager_foreach_all_app_context(
- aul_app_manager_app_context_cb callback,
- void *user_data);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // AUL_API_AUL_APP_MANAGER_HH_
+++ /dev/null
-/*
- * Copyright (c) 2020 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 <tizen.h>
-
-#include "aul/api/aul_component_port.h"
-#include "aul/common/api.hh"
-#include "aul/common/log_private.hh"
-#include "aul/component/component_port.hh"
-
-using namespace aul;
-
-extern "C" API int aul_component_port_exist(const char* port_name,
- bool* exist) {
- if (port_name == nullptr || exist == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- ComponentPort port(port_name);
- bool res = port.Exist();
- int ret = get_last_result();
- if (ret != AUL_R_OK)
- return ret;
-
- *exist = res;
- return AUL_R_OK;
-}
-
-extern "C" API int aul_component_port_create(const char* port_name, int* fd) {
- if (port_name == nullptr || fd == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- ComponentPort port(port_name);
- int ret = port.Create();
- if (ret < 0) {
- _E("Failed to create a port. port_name(%s), error(%d)",
- port_name, ret);
- return ret;
- }
-
- *fd = ret;
- _D("Port(%s) is created. fd(%d)", port_name, *fd);
- return AUL_R_OK;
-}
-
-extern "C" API int aul_component_port_destroy(const char* port_name) {
- if (port_name == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- ComponentPort port(port_name);
- int ret = port.Destroy();
- if (ret != AUL_R_OK) {
- _E("Failed to destroy a port. port_name(%s), error(%d)",
- port_name, ret);
- return ret;
- }
-
- _D("Port(%s) is destroyed", port_name);
- return AUL_R_OK;
-}
+++ /dev/null
-/*
- * Copyright (c) 2020 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_API_AUL_COMPONENT_PORT_H_
-#define AUL_API_AUL_COMPONENT_PORT_H_
-
-#include <stdbool.h>
-
-#include <aul.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int aul_component_port_exist(const char *port_name, bool *exist);
-
-int aul_component_port_create(const char *port_name, int *fd);
-
-int aul_component_port_destroy(const char *port_name);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // AUL_API_AUL_COMPONENT_PORT_HH_
+++ /dev/null
-/*
- * Copyright (c) 2021 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 <errno.h>
-#include <glib.h>
-
-#include "aul/app_control/resolve_info.hh"
-#include "aul/common/exception.hh"
-#include "aul/common/log_private.hh"
-#include "aul/common/util.hh"
-#include "include/aul.h"
-#include "src/aul_svc_priv_key.h"
-
-namespace aul {
-
-ResolveInfo::Builder& ResolveInfo::Builder::SetPkgName(std::string pkg_name) {
- pkg_name_ = std::move(pkg_name);
- return *this;
-}
-
-ResolveInfo::Builder& ResolveInfo::Builder::SetOperation(
- std::string operation) {
- operation_ = std::move(operation);
- return *this;
-}
-
-ResolveInfo::Builder& ResolveInfo::Builder::SetUri(std::string uri) {
- uri_ = std::move(uri);
- return *this;
-}
-
-ResolveInfo::Builder& ResolveInfo::Builder::SetScheme(std::string scheme) {
- scheme_ = std::move(scheme);
- return *this;
-}
-
-ResolveInfo::Builder& ResolveInfo::Builder::SetHost(std::string host) {
- host_ = std::move(host);
- return *this;
-}
-
-ResolveInfo::Builder& ResolveInfo::Builder::SetUriRInfo(
- std::string uri_r_info) {
- uri_r_info_ = std::move(uri_r_info);
- return *this;
-}
-
-ResolveInfo::Builder& ResolveInfo::Builder::SetOriginMime(
- std::string origin_mime) {
- origin_mime_ = std::move(origin_mime);
- return *this;
-}
-
-ResolveInfo::Builder& ResolveInfo::Builder::SetMime(std::string mime) {
- mime_ = std::move(mime);
- return *this;
-}
-
-ResolveInfo::Builder& ResolveInfo::Builder::SetMType(std::string m_type) {
- m_type_ = std::move(m_type);
- return *this;
-}
-
-ResolveInfo::Builder& ResolveInfo::Builder::SetSType(std::string s_type) {
- s_type_ = std::move(s_type);
- return *this;
-}
-
-ResolveInfo::Builder& ResolveInfo::Builder::SetCategory(std::string category) {
- category_ = std::move(category);
- return *this;
-}
-
-ResolveInfo::Builder& ResolveInfo::Builder::SetWinId(std::string win_id) {
- win_id_ = std::move(win_id);
- return *this;
-}
-
-ResolveInfo* ResolveInfo::Builder::Build() {
- return new (std::nothrow) ResolveInfo(std::move(pkg_name_),
- std::move(operation_), std::move(uri_), std::move(scheme_),
- std::move(host_), std::move(uri_r_info_), std::move(origin_mime_),
- std::move(mime_), std::move(m_type_), std::move(s_type_),
- std::move(category_), std::move(win_id_));
-}
-
-void ResolveInfo::Manager::GetMime(std::string& uri, std::string& mime) {
- if (uri.empty())
- return;
-
- bool need_check = false;
- int index;
- if (uri.compare(0, 1, "/") == 0) {
- if (mime.empty()) {
- need_check = true;
- index = 0;
- }
- } else if (uri.compare(0, 8, "file:///") == 0) {
- if (mime.empty()) {
- need_check = true;
- index = 7;
- }
- } else if (uri.compare(0, 6, "file:/") == 0) {
- if (mime.empty()) {
- need_check = true;
- index = 5;
- }
- }
-
- if (need_check) {
- char mime_buf[256] = { 0, };
- int ret;
- if (index > 0) {
- ret = aul_get_mime_from_file(&(uri.c_str()[index]), mime_buf,
- sizeof(mime_buf));
- } else {
- ret = aul_get_mime_from_file(uri.c_str(), mime_buf, sizeof(mime_buf));
- uri = "";
- }
-
- if (ret != AUL_R_OK) {
- _E("aul_get_mime_from_file() is failed. error(%d)", ret);
- } else {
- mime = mime_buf;
- }
- }
-}
-
-int ResolveInfo::Manager::GetSchemeAndHost(const std::string& uri,
- std::string& scheme, std::string& host, std::string& uri_r_info) {
- if (uri.empty()) {
- scheme = "NULL";
- return 0;
- }
-
- GError* error = nullptr;
- GRegex* regex = g_regex_new("^(([^:/?#]+):)?(//([^/?#]*))?",
- static_cast<GRegexCompileFlags>(0),
- static_cast<GRegexMatchFlags>(0),
- &error);
- if (regex == nullptr) {
- _E("g_regex_new() is failed");
- g_clear_error(&error);
- return -ENOMEM;
- }
- std::unique_ptr<GRegex, decltype(g_regex_unref)*> regex_ptr(
- regex, g_regex_unref);
-
- GMatchInfo* match_info = nullptr;
- gboolean ret = g_regex_match(regex, uri.c_str(),
- static_cast<GRegexMatchFlags>(0), &match_info);
- if (!ret)
- return -EINVAL;
-
- std::unique_ptr<GMatchInfo, decltype(g_match_info_free)*>
- match_info_ptr(match_info, g_match_info_free);
-
- gchar* scheme_ptr = g_match_info_fetch(match_info, 2);
- auto scheme_p = std::unique_ptr<gchar, decltype(g_free)*>(scheme_ptr, g_free);
- if (scheme_ptr)
- scheme = scheme_ptr;
-
- gchar* host_ptr = g_match_info_fetch(match_info, 4);
- auto host_p = std::unique_ptr<gchar, decltype(g_free)*>(host_ptr, g_free);
- if (host_ptr)
- host = host_ptr;
-
- if (scheme_ptr && host_ptr)
- uri_r_info = scheme + "://" + host;
-
- return 0;
-}
-
-ResolveInfo* ResolveInfo::Manager::Create(const tizen_base::Bundle& b) {
- ResolveInfo::Builder builder;
- builder.SetPkgName(b.GetString(AUL_SVC_K_PKG_NAME));
- builder.SetOperation(b.GetString(AUL_SVC_K_OPERATION));
- builder.SetCategory(b.GetString(AUL_SVC_K_CATEGORY));
- builder.SetWinId(b.GetString(AUL_SVC_K_WIN_ID));
-
- std::string uri = b.GetString(AUL_SVC_K_URI);
- std::string mime = b.GetString(AUL_SVC_K_MIME);
- SECURE_LOGD("operation(%s), uri(%s), mime(%s)",
- b.GetString(AUL_SVC_K_OPERATION).c_str(), uri.c_str(), mime.c_str());
-
- GetMime(uri, mime);
- builder.SetOriginMime(mime);
-
- std::string scheme;
- std::string host;
- std::string uri_r_info;
- int ret = GetSchemeAndHost(uri, scheme, host, uri_r_info);
- if (ret != 0)
- THROW(ret);
-
- builder.SetUriRInfo(uri_r_info);
- builder.SetScheme(scheme);
- builder.SetHost(host);
- builder.SetUri(uri);
-
- if (mime.empty()) {
- mime = "NULL";
- } else {
- auto vec = Util::Split(mime, "/");
- if (vec.size() > 1) {
- std::string m_type = vec[0];
- if (strncmp(m_type.c_str(), "*", 1) == 0)
- m_type = "%";
-
- std::string s_type = vec[1];
- if (strncmp(s_type.c_str(), "*", 1) == 0)
- s_type = "%";
-
- mime = m_type + "/" + s_type;
-
- builder.SetMType(m_type);
- builder.SetSType(s_type);
- }
- }
- builder.SetMime(mime);
-
- return builder.Build();
-}
-
-ResolveInfo::ResolveInfo(std::string pkg_name, std::string operation,
- std::string uri, std::string scheme,
- std::string host, std::string uri_r_info,
- std::string origin_mime, std::string mime,
- std::string m_type, std::string s_type,
- std::string category, std::string win_id)
- : pkg_name_(std::move(pkg_name)),
- operation_(std::move(operation)),
- uri_(std::move(uri)),
- scheme_(std::move(scheme)),
- host_(std::move(host)),
- uri_r_info_(std::move(uri_r_info)),
- origin_mime_(std::move(origin_mime)),
- mime_(std::move(mime)),
- m_type_(std::move(m_type)),
- s_type_(std::move(s_type)),
- category_(std::move(category)),
- win_id_(std::move(win_id)) {
-}
-
-ResolveInfo::~ResolveInfo() = default;
-
-void ResolveInfo::SetUriRInfo(std::string uri_r_info) {
- uri_r_info_ = std::move(uri_r_info);
-}
-
-const std::string& ResolveInfo::GetPkgName() const {
- return pkg_name_;
-}
-
-const std::string& ResolveInfo::GetOperation() const {
- return operation_;
-}
-
-const std::string& ResolveInfo::GetUri() const {
- return uri_;
-}
-
-const std::string& ResolveInfo::GetScheme() const {
- return scheme_;
-}
-
-const std::string& ResolveInfo::GetHost() const {
- return host_;
-}
-
-const std::string& ResolveInfo::GetUriRInfo() const {
- return uri_r_info_;
-}
-
-const std::string& ResolveInfo::GetOriginMime() const {
- return origin_mime_;
-}
-
-const std::string& ResolveInfo::GetMime() const {
- return mime_;
-}
-
-const std::string& ResolveInfo::GetMType() const {
- return m_type_;
-}
-
-const std::string& ResolveInfo::GetSType() const {
- return s_type_;
-}
-
-const std::string& ResolveInfo::GetCategory() const {
- return category_;
-}
-
-const std::string& ResolveInfo::GetWinId() const {
- return win_id_;
-}
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2021 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_APP_CONTROL_RESOLVE_INFO_HH_
-#define AUL_APP_CONTROL_RESOLVE_INFO_HH_
-
-#include <bundle_cpp.h>
-
-#include <string>
-
-#include "aul/common/exception.hh"
-
-namespace aul {
-
-class ResolveInfo {
- public:
- class Builder {
- public:
- Builder& SetPkgName(std::string pkg_name);
- Builder& SetOperation(std::string operation);
- Builder& SetUri(std::string uri);
- Builder& SetScheme(std::string scheme);
- Builder& SetHost(std::string host);
- Builder& SetUriRInfo(std::string uri_r_info);
- Builder& SetOriginMime(std::string origin_mime);
- Builder& SetMime(std::string mime);
- Builder& SetMType(std::string m_type);
- Builder& SetSType(std::string s_type);
- Builder& SetCategory(std::string category);
- Builder& SetWinId(std::string win_id);
- ResolveInfo* Build();
-
- private:
- std::string pkg_name_;
- std::string operation_;
- std::string uri_;
- std::string scheme_;
- std::string host_;
- std::string uri_r_info_;
- std::string origin_mime_;
- std::string mime_;
- std::string m_type_;
- std::string s_type_;
- std::string category_;
- std::string win_id_;
- };
-
- class Manager {
- public:
- static ResolveInfo* Create(const tizen_base::Bundle& b);
- private:
- static int GetSchemeAndHost(const std::string& uri,
- std::string& scheme, std::string& host, std::string& uri_r_info);
- static void GetMime(std::string& uri, std::string& mime);
- };
-
- ResolveInfo() = default;
- ResolveInfo(std::string pkg_name, std::string operation,
- std::string uri, std::string scheme,
- std::string host, std::string uri_r_info,
- std::string origin_mime, std::string mime,
- std::string m_type, std::string s_type,
- std::string category, std::string win_id);
- virtual ~ResolveInfo();
-
- void SetUriRInfo(std::string uri_r_info);
-
- const std::string& GetPkgName() const;
- const std::string& GetOperation() const;
- const std::string& GetUri() const;
- const std::string& GetScheme() const;
- const std::string& GetHost() const;
- const std::string& GetUriRInfo() const;
- const std::string& GetOriginMime() const;
- const std::string& GetMime() const;
- const std::string& GetMType() const;
- const std::string& GetSType() const;
- const std::string& GetCategory() const;
- const std::string& GetWinId() const;
-
- private:
- std::string pkg_name_;
- std::string operation_;
- std::string uri_;
- std::string scheme_;
- std::string host_;
- std::string uri_r_info_;
- std::string origin_mime_;
- std::string mime_;
- std::string m_type_;
- std::string s_type_;
- std::string category_;
- std::string win_id_;
-};
-
-} // namespace aul
-
-#endif // AUL_APP_CONTROL_RESOLVE_INFO_HH_
+++ /dev/null
-/*
- * Copyright (c) 2022 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 "aul/app_group/app_group_info.hh"
-
-#include "include/aul.h"
-#include "aul/common/exception.hh"
-
-namespace aul {
-
-AppGroupInfo::Builder& AppGroupInfo::Builder::SetId(
- const tizen_base::Bundle& b) {
- id_ = std::move(b.GetString(AUL_K_INSTANCE_ID));
- return *this;
-}
-
-AppGroupInfo::Builder& AppGroupInfo::Builder::SetPid(
- const tizen_base::Bundle& b) {
- auto pid_str = b.GetString(AUL_K_PID);
- if (pid_str.empty())
- return *this;
-
- pid_ = std::stoi(pid_str);
- return *this;
-}
-
-AppGroupInfo::Builder& AppGroupInfo::Builder::SetAppId(
- const tizen_base::Bundle& b) {
- appid_ = std::move(b.GetString(AUL_K_APPID));
- return *this;
-}
-
-AppGroupInfo::Builder& AppGroupInfo::Builder::SetPkgId(
- const tizen_base::Bundle& b) {
- pkgid_ = std::move(b.GetString(AUL_K_PKGID));
- return *this;
-}
-
-AppGroupInfo::Builder& AppGroupInfo::Builder::SetWid(
- const tizen_base::Bundle& b) {
- auto wid_str = b.GetString(AUL_K_WID);
- if (wid_str.empty())
- return *this;
-
- wid_ = std::stoi(wid_str);
- return *this;
-}
-
-AppGroupInfo::Builder& AppGroupInfo::Builder::SetFg(
- const tizen_base::Bundle& b) {
- auto fg_str = b.GetString(AUL_K_FG_FLAG);
- if (fg_str.empty())
- return *this;
-
- fg_ = std::stoi(fg_str) ? true : false;
- return *this;
-}
-
-AppGroupInfo::Builder& AppGroupInfo::Builder::SetStatus(
- const tizen_base::Bundle& b) {
- auto status_str = b.GetString(AUL_K_STATUS);
- if (status_str.empty())
- return *this;
-
- status_ = std::stoi(status_str);
- return *this;
-}
-
-AppGroupInfo::Builder::operator AppGroupInfo*() {
- Validate();
- return new (std::nothrow) AppGroupInfo(std::move(id_), pid_,
- std::move(appid_), std::move(pkgid_), wid_, fg_, status_);
-}
-
-void AppGroupInfo::Builder::Validate() {
- if (id_.empty() ||
- pid_ < 1 ||
- appid_.empty() ||
- pkgid_.empty() ||
- wid_ < 0 ||
- status_ < 0) {
- _E("id(%s), pid(%d), appid(%s), pkgid(%s), wid(%d), status(%d)",
- id_.c_str(), pid_, appid_.c_str(), pkgid_.c_str(), wid_, status_);
- THROW(AUL_R_ERROR);
- }
-}
-
-AppGroupInfo::AppGroupInfo(std::string id, pid_t pid, std::string appid,
- std::string pkgid, int wid, bool fg, int status)
- : id_(std::move(id)),
- pid_(pid),
- appid_(std::move(appid)),
- pkgid_(std::move(pkgid)),
- wid_(wid),
- fg_(fg),
- status_(status) {
-}
-
-const std::string& AppGroupInfo::GetId() const {
- return id_;
-}
-
-pid_t AppGroupInfo::GetPid() const {
- return pid_;
-}
-
-const std::string& AppGroupInfo::GetAppId() const {
- return appid_;
-}
-
-const std::string& AppGroupInfo::GetPkgId() const {
- return pkgid_;
-}
-
-int AppGroupInfo::GetWid() const {
- return wid_;
-}
-
-bool AppGroupInfo::IsFg() const {
- return fg_;
-}
-
-int AppGroupInfo::GetStatus() const {
- return status_;
-}
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2022 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_APP_GROUP_APP_GROUP_INFO_HH
-#define AUL_APP_GROUP_APP_GROUP_INFO_HH
-
-#include <sys/types.h>
-#include <unistd.h>
-
-#include <bundle_cpp.h>
-
-#include <string>
-
-namespace aul {
-
-class AppGroupInfo {
- public:
- class Builder {
- public:
- Builder& SetId(const tizen_base::Bundle& b);
- Builder& SetPid(const tizen_base::Bundle& b);
- Builder& SetAppId(const tizen_base::Bundle& b);
- Builder& SetPkgId(const tizen_base::Bundle& b);
- Builder& SetWid(const tizen_base::Bundle& b);
- Builder& SetFg(const tizen_base::Bundle& b);
- Builder& SetStatus(const tizen_base::Bundle& b);
- operator AppGroupInfo*();
-
- private:
- void Validate();
-
- private:
- std::string id_;
- pid_t pid_ = -1;
- std::string appid_;
- std::string pkgid_;
- int wid_ = -1;
- bool fg_ = false;
- int status_ = -1;
- };
-
- AppGroupInfo(std::string id, pid_t pid, std::string appid,
- std::string pkgid, int wid, bool fg, int status);
-
- const std::string& GetId() const;
- pid_t GetPid() const;
- const std::string& GetAppId() const;
- const std::string& GetPkgId() const;
- int GetWid() const;
- bool IsFg() const;
- int GetStatus() const;
-
- private:
- std::string id_;
- pid_t pid_ = -1;
- std::string appid_;
- std::string pkgid_;
- int wid_ = -1;
- bool fg_ = false;
- int status_ = -1;
-};
-
-} // namespace aul
-
-#endif // AUL_APP_GROUP_APP_GROUP_INFO_HH
+++ /dev/null
-/*
- * Copyright (c) 2021 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 <pkgmgr-info.h>
-
-#include <string>
-
-#include "aul/app_info/app_info.hh"
-#include "aul/common/exception.hh"
-#include "aul/socket/client.hh"
-#include "include/aul.h"
-#include "include/aul_cmd.h"
-#include "include/aul_error.h"
-#include "include/aul_sock.h"
-
-namespace aul {
-
-AppInfo::Builder& AppInfo::Builder::SetAppId(std::string app_id) {
- app_id_ = std::move(app_id);
- return *this;
-}
-
-AppInfo::Builder& AppInfo::Builder::SetPkgId(std::string pkg_id) {
- pkg_id_ = std::move(pkg_id);
- return *this;
-}
-
-AppInfo::Builder& AppInfo::Builder::SetRootPath(std::string root_path) {
- root_path_ = std::move(root_path);
- return *this;
-}
-
-AppInfo::Builder& AppInfo::Builder::SetLightUserSwitchMode(std::string mode) {
- light_user_switch_mode_ = std::move(mode);
- return *this;
-}
-
-AppInfo::Builder::operator AppInfo*() {
- return new (std::nothrow) AppInfo(std::move(app_id_), std::move(pkg_id_),
- std::move(root_path_), std::move(light_user_switch_mode_));
-}
-
-AppInfo* AppInfo::Get(const std::string& app_id, uid_t uid) {
- pkgmgrinfo_appinfo_h handle;
- int ret = pkgmgrinfo_appinfo_get_usr_appinfo(app_id.c_str(), uid, &handle);
- if (ret != PMINFO_R_OK) {
- _E("Failed to get appinfo. app_id(%s), uid(%u), error(%d)",
- app_id.c_str(), uid, ret);
- return nullptr;
- }
-
- std::unique_ptr<std::remove_pointer<pkgmgrinfo_appinfo_h>::type,
- decltype(pkgmgrinfo_appinfo_destroy_appinfo)*> ptr(handle,
- pkgmgrinfo_appinfo_destroy_appinfo);
-
- char* pkg_id;
- ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkg_id);
- if (ret != PMINFO_R_OK) {
- _E("Failed to get pkgid. error(%d)", ret);
- return nullptr;
- }
-
- char* root_path;
- ret = pkgmgrinfo_appinfo_get_root_path(handle, &root_path);
- if (ret != PMINFO_R_OK) {
- _E("Failed to get root path. error(%d)", ret);
- return nullptr;
- }
-
- char* mode;
- ret = pkgmgrinfo_appinfo_get_light_user_switch_mode(handle, &mode);
- if (ret != PMINFO_R_OK) {
- _E("Failed to get light user switch mode. error(%d)", ret);
- return nullptr;
- }
-
- return Builder().SetAppId(app_id).SetPkgId(pkg_id)
- .SetRootPath(root_path).SetLightUserSwitchMode(mode);
-}
-
-AppInfo* AppInfo::Get(int pid) {
- char app_id[256] = { 0, };
- int ret = aul_app_get_appid_bypid(pid, app_id, sizeof(app_id));
- if (ret != AUL_R_OK)
- return nullptr;
-
- if (pid != getpid())
- return Get(app_id, getuid());
-
- char pkg_id[256] = { 0, };
- ret = aul_app_get_appid_bypid(pid, pkg_id, sizeof(pkg_id));
- if (ret != AUL_R_OK)
- return Get(app_id, getuid());
-
- const char* root_path = aul_get_preinit_root_path();
- if (root_path == nullptr)
- return Get(app_id, getuid());
-
- return Builder().SetAppId(app_id).SetPkgId(pkg_id).SetRootPath(root_path);
-}
-
-AppInfo::AppInfo(std::string app_id, std::string pkg_id,
- std::string root_path, std::string light_user_switch_mode)
- : app_id_(std::move(app_id)),
- pkg_id_(std::move(pkg_id)),
- root_path_(std::move(root_path)),
- light_user_switch_mode_(std::move(light_user_switch_mode)) {
-}
-
-const std::string& AppInfo::GetAppId() const {
- return app_id_;
-}
-
-const std::string& AppInfo::GetPkgId() const {
- return pkg_id_;
-}
-
-const std::string& AppInfo::GetRootPath() const {
- return root_path_;
-}
-
-const std::string& AppInfo::GetLightUserSwitchMode() const {
- return light_user_switch_mode_;
-}
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2021 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_APP_INFO_APP_INFO_HH
-#define AUL_APP_INFO_APP_INFO_HH
-
-#include <sys/types.h>
-#include <unistd.h>
-
-#include <string>
-
-namespace aul {
-
-class AppInfo {
- public:
- class Builder {
- public:
- Builder& SetAppId(std::string app_id);
- Builder& SetPkgId(std::string pkg_id);
- Builder& SetRootPath(std::string root_path);
- Builder& SetLightUserSwitchMode(std::string mode);
- operator AppInfo*();
-
- private:
- std::string app_id_;
- std::string pkg_id_;
- std::string root_path_;
- std::string light_user_switch_mode_;
- };
-
- static AppInfo* Get(const std::string& app_id, uid_t uid);
- static AppInfo* Get(int pid);
-
- AppInfo(std::string app_id,
- std::string pkg_id,
- std::string root_path,
- std::string light_user_switch_mode);
-
- const std::string& GetAppId() const;
- const std::string& GetPkgId() const;
- const std::string& GetRootPath() const;
- const std::string& GetLightUserSwitchMode() const;
-
- private:
- std::string app_id_;
- std::string pkg_id_;
- std::string root_path_;
- std::string light_user_switch_mode_;
-};
-
-} // namespace aul
-
-#endif // AUL_APP_INFO_APP_INFO_HH
+++ /dev/null
-/*
- * Copyright (c) 2021 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 <sys/types.h>
-#include <tzplatform_config.h>
-#include <unistd.h>
-
-#include <memory>
-
-#include "aul/app_info/app_info.hh"
-#include "aul/app_info/directory_info.hh"
-#include "aul/common/common.hh"
-#include "aul/common/log_private.hh"
-#include "include/aul.h"
-
-namespace aul {
-namespace {
-
-constexpr const char kDataDir[] = "data/";
-constexpr const char kCacheDir[] = "cache/";
-constexpr const char kResourceDir[] = "res/";
-constexpr const char kTepResourceDir[] = "tep/mount/";
-constexpr const char kSharedDataDir[] = "shared/data/";
-constexpr const char kSharedTrustedDir[] = "shared/trusted/";
-constexpr const char kSharedResourceDir[] = "shared/res/";
-constexpr const char kAppRWDir[] = "apps_rw/";
-constexpr const char kLightUserSwitchModeDefault[] = "default";
-constexpr const char kResControlAllowedDir[] = "res/mount/allowed/";
-constexpr const char kResControlGlobalDir[] = "res/mount/global/";
-
-std::string GetRWPath(const std::string& pkg_id, uid_t uid) {
- tzplatform_set_user(uid);
- std::string path = std::string(tzplatform_getenv(TZ_USER_APP)) + "/" + pkg_id;
- tzplatform_reset_user();
- return path;
-}
-
-std::string GetPath(const std::string& path,
- const std::string& dir_name) {
- return path + "/" + dir_name;
-}
-
-} // namespace
-
-DirectoryInfo::Builder& DirectoryInfo::Builder::SetRootPath(
- std::string root_path) {
- root_path_ = std::move(root_path);
- return *this;
-}
-
-DirectoryInfo::Builder& DirectoryInfo::Builder::SetDataPath(
- std::string data_path) {
- data_path_ = std::move(data_path);
- return *this;
-}
-
-DirectoryInfo::Builder& DirectoryInfo::Builder::SetCachePath(
- std::string cache_path) {
- cache_path_ = std::move(cache_path);
- return *this;
-}
-
-DirectoryInfo::Builder& DirectoryInfo::Builder::SetResourcePath(
- std::string resource_path) {
- resource_path_ = std::move(resource_path);
- return *this;
-}
-
-DirectoryInfo::Builder& DirectoryInfo::Builder::SetTepResourcePath(
- std::string tep_resource_path) {
- tep_resource_path_ = std::move(tep_resource_path);
- return *this;
-}
-
-DirectoryInfo::Builder& DirectoryInfo::Builder::SetSharedDataPath(
- std::string shared_data_path) {
- shared_data_path_ = std::move(shared_data_path);
- return *this;
-}
-
-DirectoryInfo::Builder& DirectoryInfo::Builder::SetSharedResourcePath(
- std::string shared_resource_path) {
- shared_resource_path_ = std::move(shared_resource_path);
- return *this;
-}
-
-DirectoryInfo::Builder& DirectoryInfo::Builder::SetSharedTrustedPath(
- std::string shared_trusted_path) {
- shared_trusted_path_ = std::move(shared_trusted_path);
- return *this;
-}
-
-DirectoryInfo::Builder& DirectoryInfo::Builder::SetResControlAllowedPath(
- std::string res_control_allowed_res_path) {
- res_control_allowed_res_path_ = std::move(res_control_allowed_res_path);
- return *this;
-}
-
-DirectoryInfo::Builder& DirectoryInfo::Builder::SetResControlGlobalPath(
- std::string res_control_global_res_path) {
- res_control_global_res_path_ = std::move(res_control_global_res_path);
- return *this;
-}
-
-DirectoryInfo::Builder::operator DirectoryInfo*() {
- return new (std::nothrow) DirectoryInfo(std::move(root_path_),
- std::move(data_path_), std::move(cache_path_),
- std::move(resource_path_), std::move(tep_resource_path_),
- std::move(shared_data_path_), std::move(shared_resource_path_),
- std::move(shared_trusted_path_), std::move(res_control_allowed_res_path_),
- std::move(res_control_global_res_path_));
-}
-
-DirectoryInfo* DirectoryInfo::Get(const std::string app_id,
- uid_t uid) {
- std::unique_ptr<AppInfo> info(AppInfo::Get(app_id, uid));
- if (info.get() == nullptr)
- return nullptr;
-
- std::string root_path = info->GetRootPath();
- std::string rw_path = GetRWPath(info->GetPkgId(), uid);
- return Builder().SetRootPath(info->GetRootPath())
- .SetDataPath(GetPath(rw_path, kDataDir))
- .SetCachePath(GetPath(rw_path, kCacheDir))
- .SetResourcePath(GetPath(root_path, kResourceDir))
- .SetTepResourcePath(GetPath(root_path, kTepResourceDir))
- .SetSharedDataPath(GetPath(rw_path, kSharedDataDir))
- .SetSharedResourcePath(GetPath(root_path, kSharedResourceDir))
- .SetSharedTrustedPath(GetPath(rw_path, kSharedTrustedDir))
- .SetResControlAllowedPath(GetPath(root_path, kResControlAllowedDir))
- .SetResControlGlobalPath(GetPath(root_path, kResControlGlobalDir));
-}
-
-DirectoryInfo* DirectoryInfo::Get() {
- char app_id[256] = { 0, };
- int ret = aul_app_get_appid_bypid(getpid(), app_id, sizeof(app_id));
- if (ret != AUL_R_OK)
- return nullptr;
-
- return Get(app_id, getuid());
-}
-
-DirectoryInfo::DirectoryInfo(std::string root_path,
- std::string data_path,
- std::string cache_path,
- std::string resource_path,
- std::string tep_resource_path,
- std::string shared_data_path,
- std::string shared_resource_path,
- std::string shared_trusted_path,
- std::string res_control_allowed_res_path,
- std::string res_control_global_res_path)
- : root_path_(std::move(root_path)),
- data_path_(std::move(data_path)),
- cache_path_(std::move(cache_path)),
- resource_path_(std::move(resource_path)),
- tep_resource_path_(std::move(tep_resource_path)),
- shared_data_path_(std::move(shared_data_path)),
- shared_resource_path_(std::move(shared_resource_path)),
- shared_trusted_path_(std::move(shared_trusted_path)),
- res_control_allowed_res_path_(std::move(res_control_allowed_res_path)),
- res_control_global_res_path_(std::move(res_control_global_res_path)) {
-}
-
-const std::string& DirectoryInfo::GetRootPath() const {
- return root_path_;
-}
-
-const std::string& DirectoryInfo::GetDataPath() const {
- return data_path_;
-}
-
-const std::string& DirectoryInfo::GetCachePath() const {
- return cache_path_;
-}
-
-const std::string& DirectoryInfo::GetResourcePath() const {
- return resource_path_;
-}
-
-const std::string& DirectoryInfo::GetTepResourcePath() const {
- return tep_resource_path_;
-}
-
-const std::string& DirectoryInfo::GetSharedDataPath() const {
- return shared_data_path_;
-}
-
-const std::string& DirectoryInfo::GetSharedResourcePath() const {
- return shared_resource_path_;
-}
-
-const std::string& DirectoryInfo::GetSharedTrustedPath() const {
- return shared_trusted_path_;
-}
-
-const std::string& DirectoryInfo::GetResControlAllowedResPath() const {
- return res_control_allowed_res_path_;
-}
-
-const std::string& DirectoryInfo::GetResControlGlobalResPath() const {
- return res_control_global_res_path_;
-}
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2021 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_APP_INFO_DIRECTORY_INFO_HH
-#define AUL_APP_INFO_DIRECTORY_INFO_HH
-
-#include <string>
-
-namespace aul {
-
-class DirectoryInfo {
- public:
- static DirectoryInfo* Get(const std::string app_id, uid_t uid);
- static DirectoryInfo* Get();
-
- const std::string& GetRootPath() const;
- const std::string& GetDataPath() const;
- const std::string& GetCachePath() const;
- const std::string& GetResourcePath() const;
- const std::string& GetTepResourcePath() const;
- const std::string& GetSharedDataPath() const;
- const std::string& GetSharedResourcePath() const;
- const std::string& GetSharedTrustedPath() const;
- const std::string& GetResControlAllowedResPath() const;
- const std::string& GetResControlGlobalResPath() const;
-
- private:
- class Builder {
- public:
- Builder& SetRootPath(std::string root_path);
- Builder& SetDataPath(std::string data_path);
- Builder& SetCachePath(std::string cache_path);
- Builder& SetResourcePath(std::string resource_path);
- Builder& SetTepResourcePath(std::string tep_resource_path);
- Builder& SetSharedDataPath(std::string shared_data_path);
- Builder& SetSharedResourcePath(std::string shared_resource_path);
- Builder& SetSharedTrustedPath(std::string shared_trusted_path);
- Builder& SetResControlAllowedPath(std::string res_control_allowed_res_path);
- Builder& SetResControlGlobalPath(std::string res_control_global_res_path);
-
- operator DirectoryInfo*();
-
- private:
- std::string root_path_;
- std::string rw_path_;
- std::string data_path_;
- std::string cache_path_;
- std::string resource_path_;
- std::string tep_resource_path_;
- std::string shared_data_path_;
- std::string shared_resource_path_;
- std::string shared_trusted_path_;
- std::string res_control_allowed_res_path_;
- std::string res_control_global_res_path_;
- };
-
- DirectoryInfo(std::string root_path,
- std::string data_path,
- std::string cache_path,
- std::string resource_path,
- std::string tep_resource_path,
- std::string shared_data_path,
- std::string shared_resource_path,
- std::string shared_trusted_path,
- std::string res_control_allowed_res_path,
- std::string res_control_global_res_path);
-
- private:
- std::string root_path_;
- std::string data_path_;
- std::string cache_path_;
- std::string resource_path_;
- std::string tep_resource_path_;
- std::string shared_data_path_;
- std::string shared_resource_path_;
- std::string shared_trusted_path_;
- std::string res_control_allowed_res_path_;
- std::string res_control_global_res_path_;
-};
-
-} // namespace aul
-
-#endif // AUL_APP_INFO_DIRECTORY_INFO_HH
+++ /dev/null
-/*
- * Copyright (c) 2021 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 <storage-internal.h>
-#include <sys/types.h>
-#include <tzplatform_config.h>
-#include <unistd.h>
-
-#include <memory>
-
-#include "aul/app_info/app_info.hh"
-#include "aul/app_info/external_directory_info.hh"
-#include "aul/common/common.hh"
-#include "aul/common/log_private.hh"
-#include "include/aul.h"
-
-namespace aul {
-namespace {
-
-constexpr const char kDefaultExternalStorage[] = "/opt/media/sdcard";
-constexpr const char kDataDir[] = "data/";
-constexpr const char kCacheDir[] = "cache/";
-constexpr const char kSharedDataDir[] = "shared/data/";
-
-std::string GetSdCardPath() {
- int storage_id = 0;
- char* path = nullptr;
- int ret = storage_get_primary_sdcard(&storage_id, &path);
- if (ret != STORAGE_ERROR_NONE)
- _W("Failed to get primary sdcard. error(%d)", ret);
-
- auto ptr = std::unique_ptr<char, decltype(std::free)*>(path, std::free);
- if (path)
- return std::string(path);
-
- return std::string(kDefaultExternalStorage);
-}
-
-std::string GetExternalPath(const std::string& pkg_id, uid_t uid) {
- std::string sdcard_path = GetSdCardPath();
- tzplatform_set_user(uid);
- std::string path = sdcard_path + "/apps/" +
- std::string(tzplatform_getenv(TZ_USER_NAME)) + "/apps_rw/" +
- pkg_id;
- tzplatform_reset_user();
- return path;
-}
-
-std::string GetPath(const std::string& path,
- const std::string& dir_name) {
- return path + "/" + dir_name;
-}
-
-} // namespace
-
-ExternalDirectoryInfo::Builder& ExternalDirectoryInfo::Builder::SetRootPath(
- std::string root_path) {
- root_path_ = std::move(root_path);
- return *this;
-}
-
-ExternalDirectoryInfo::Builder& ExternalDirectoryInfo::Builder::SetDataPath(
- std::string data_path) {
- data_path_ = std::move(data_path);
- return *this;
-}
-
-ExternalDirectoryInfo::Builder& ExternalDirectoryInfo::Builder::SetCachePath(
- std::string cache_path) {
- cache_path_ = std::move(cache_path);
- return *this;
-}
-
-ExternalDirectoryInfo::Builder&
-ExternalDirectoryInfo::Builder::SetSharedDataPath(
- std::string shared_data_path) {
- shared_data_path_ = std::move(shared_data_path);
- return *this;
-}
-
-ExternalDirectoryInfo::Builder::operator ExternalDirectoryInfo*() {
- return new (std::nothrow) ExternalDirectoryInfo(std::move(root_path_),
- std::move(data_path_), std::move(cache_path_),
- std::move(shared_data_path_));
-}
-
-ExternalDirectoryInfo* ExternalDirectoryInfo::Get(const std::string app_id,
- uid_t uid) {
- std::unique_ptr<AppInfo> info(AppInfo::Get(app_id, uid));
- if (info.get() == nullptr)
- return nullptr;
-
- std::string external_path = GetExternalPath(info->GetPkgId(), uid);
- return Builder().SetRootPath(std::string(external_path) + "/")
- .SetDataPath(GetPath(external_path, kDataDir))
- .SetCachePath(GetPath(external_path, kCacheDir))
- .SetSharedDataPath(GetPath(external_path, kSharedDataDir));
-}
-
-ExternalDirectoryInfo* ExternalDirectoryInfo::Get() {
- char app_id[256] = { 0, };
- int ret = aul_app_get_appid_bypid(getpid(), app_id, sizeof(app_id));
- if (ret != AUL_R_OK)
- return nullptr;
-
- return Get(app_id, getuid());
-}
-
-ExternalDirectoryInfo::ExternalDirectoryInfo(std::string root_path,
- std::string data_path,
- std::string cache_path,
- std::string shared_data_path)
- : root_path_(std::move(root_path)),
- data_path_(std::move(data_path)),
- cache_path_(std::move(cache_path)),
- shared_data_path_(std::move(shared_data_path)) {
-}
-
-const std::string& ExternalDirectoryInfo::GetRootPath() const {
- return root_path_;
-}
-
-const std::string& ExternalDirectoryInfo::GetDataPath() const {
- return data_path_;
-}
-
-const std::string& ExternalDirectoryInfo::GetCachePath() const {
- return cache_path_;
-}
-
-const std::string& ExternalDirectoryInfo::GetSharedDataPath() const {
- return shared_data_path_;
-}
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2021 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_APP_INFO_EXTERNAL_DIRECTORY_INFO_HH
-#define AUL_APP_INFO_EXTERNAL_DIRECTORY_INFO_HH
-
-#include <string>
-
-namespace aul {
-
-class ExternalDirectoryInfo {
- public:
- static ExternalDirectoryInfo* Get(const std::string app_id, uid_t uid);
- static ExternalDirectoryInfo* Get();
-
- const std::string& GetRootPath() const;
- const std::string& GetDataPath() const;
- const std::string& GetCachePath() const;
- const std::string& GetSharedDataPath() const;
-
- private:
- class Builder {
- public:
- Builder& SetRootPath(std::string root_path);
- Builder& SetDataPath(std::string data_path);
- Builder& SetCachePath(std::string cache_path);
- Builder& SetSharedDataPath(std::string shared_data_path);
-
- operator ExternalDirectoryInfo*();
-
- private:
- std::string root_path_;
- std::string data_path_;
- std::string cache_path_;
- std::string shared_data_path_;
- };
-
- ExternalDirectoryInfo(std::string root_path,
- std::string data_path,
- std::string cache_path,
- std::string shared_data_path);
-
- private:
- std::string root_path_;
- std::string data_path_;
- std::string cache_path_;
- std::string shared_data_path_;
-};
-
-} // namespace aul
-
-#endif // AUL_APP_INFO_EXTERNAL_DIRECTORY_INFO_HH
+++ /dev/null
-/*
- * Copyright (c) 2020 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 <memory>
-
-#include "aul/app_manager/app_context.hh"
-#include "include/aul.h"
-
-namespace aul {
-
-AppContext::Builder& AppContext::Builder::SetAppId(std::string app_id) {
- app_id_ = std::move(app_id);
- return *this;
-}
-
-AppContext::Builder& AppContext::Builder::SetPkgId(std::string pkg_id) {
- pkg_id_ = std::move(pkg_id);
- return *this;
-}
-
-AppContext::Builder& AppContext::Builder::SetInstId(std::string inst_id) {
- inst_id_ = std::move(inst_id);
- return *this;
-}
-
-AppContext::Builder& AppContext::Builder::SetExec(std::string exec) {
- exec_ = std::move(exec);
- return *this;
-}
-
-AppContext::Builder& AppContext::Builder::SetPid(int pid) {
- pid_ = pid;
- return *this;
-}
-
-AppContext::Builder& AppContext::Builder::SetStatus(int status) {
- status_ = status;
- return *this;
-}
-
-AppContext::Builder& AppContext::Builder::SetIsSubApp(bool is_sub_app) {
- is_sub_app_ = is_sub_app;
- return *this;
-}
-
-AppContext AppContext::Builder::Build() {
- return AppContext(std::move(app_id_), std::move(pkg_id_), std::move(inst_id_),
- std::move(exec_), pid_, status_, is_sub_app_);
-}
-
-AppContext::AppContext(tizen_base::Bundle b) {
- Set(std::move(b));
-}
-
-AppContext::AppContext(std::string app_id,
- std::string pkg_id,
- std::string inst_id,
- std::string exec,
- int pid,
- int status,
- bool is_sub_app)
- : app_id_(std::move(app_id)),
- pkg_id_(std::move(pkg_id)),
- inst_id_(std::move(inst_id)),
- exec_(std::move(exec)),
- pid_(pid),
- status_(status),
- is_sub_app_(is_sub_app) {
-}
-
-const std::string& AppContext::GetAppId() const {
- return app_id_;
-}
-
-const std::string& AppContext::GetPkgId() const {
- return pkg_id_;
-}
-
-const std::string& AppContext::GetInstId() const {
- return inst_id_;
-}
-
-const std::string& AppContext::GetExec() const {
- return exec_;
-}
-
-int AppContext::GetPid() const {
- return pid_;
-}
-
-int AppContext::GetStatus() const {
- return status_;
-}
-
-void AppContext::SetStatus(int status) {
- status_ = status;
-}
-
-bool AppContext::IsSubApp() const {
- return is_sub_app_;
-}
-
-void AppContext::Set(tizen_base::Bundle b) {
- app_id_ = std::move(b.GetString(AUL_K_APPID));
- pkg_id_ = std::move(b.GetString(AUL_K_PKGID));
- inst_id_ = std::move(b.GetString(AUL_K_INSTANCE_ID));
- exec_ = std::move(b.GetString(AUL_K_EXEC));
- pid_ = std::stoi(b.GetString(AUL_K_PID));
- status_ = std::stoi(b.GetString(AUL_K_STATUS));
- is_sub_app_ = static_cast<bool>(std::stoi(b.GetString(AUL_K_IS_SUBAPP)));
-}
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2020 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_APP_MANAGER_APP_CONTEXT_HH_
-#define AUL_APP_MANAGER_APP_CONTEXT_HH_
-
-#include <bundle_cpp.h>
-
-#include <string>
-
-namespace aul {
-
-class AppContext {
- public:
- class Builder {
- public:
- Builder& SetAppId(std::string app_id);
- Builder& SetPkgId(std::string pkg_id);
- Builder& SetInstId(std::string inst_id);
- Builder& SetExec(std::string exec);
- Builder& SetPid(int pid);
- Builder& SetStatus(int status);
- Builder& SetIsSubApp(bool is_sub_app);
- AppContext Build();
-
- private:
- std::string app_id_;
- std::string pkg_id_;
- std::string inst_id_;
- std::string exec_;
- int pid_;
- int status_;
- bool is_sub_app_;
- };
-
- explicit AppContext(tizen_base::Bundle b);
- virtual ~AppContext() = default;
-
- const std::string& GetAppId() const;
- const std::string& GetPkgId() const;
- const std::string& GetInstId() const;
- const std::string& GetExec() const;
- int GetPid() const;
- int GetStatus() const;
- bool IsSubApp() const;
-
- void SetStatus(int status);
-
- private:
- AppContext(std::string app_id,
- std::string pkg_id,
- std::string inst_id,
- std::string exec,
- int pid,
- int status,
- bool is_sub_app);
-
- void Set(tizen_base::Bundle b);
-
- private:
- std::string app_id_;
- std::string pkg_id_;
- std::string inst_id_;
- std::string exec_;
- int pid_;
- int status_;
- bool is_sub_app_;
-};
-
-} // namespace aul
-
-#endif // AUL_APP_MANAGER_APP_CONTEXT_HH_
+++ /dev/null
-/*
- * Copyright (c) 2020 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 <unistd.h>
-#include <sys/types.h>
-
-#include <bundle_cpp.h>
-
-#include <utility>
-
-#include "aul/app_manager/app_event.hh"
-#include "aul/common/common.hh"
-#include "aul/common/exception.hh"
-#include "aul/common/log_private.hh"
-
-namespace aul {
-
-AppEvent::AppEvent(std::string app_id, AppEvent::IEvent* ev)
- : app_id_(std::move(app_id)), ev_(ev) {
- endpoint_ = "app_status_event:" + app_id_;
- if (getuid() >= REGULAR_UID_MIN)
- endpoint_ += ":" + std::to_string(getuid());
-}
-
-AppEvent::AppEvent(AppEvent::IEvent* ev) : ev_(ev) {
- endpoint_ = "app_status_event";
- if (getuid() >= REGULAR_UID_MIN)
- endpoint_ += ":" + std::to_string(getuid());
-}
-
-AppEvent::~AppEvent() {
- if (handle_)
- aul_app_com_leave(handle_);
-}
-
-void AppEvent::Listen() {
- int ret = aul_app_com_create_async(endpoint_.c_str(), nullptr, OnAppStatusCb,
- this, &handle_);
- if (ret != AUL_R_OK) {
- _E("aul_app_com_create(%s) is failed. error(%d)", endpoint_.c_str(), ret);
- THROW(ret);
- }
-}
-
-int AppEvent::OnAppStatusCb(const char* endpoint, aul_app_com_result_e res,
- bundle* envelope, void* user_data) {
- tizen_base::Bundle b(envelope);
- AppContext::Builder builder;
- builder.SetAppId(b.GetString(AUL_K_APPID));
- builder.SetPkgId(b.GetString(AUL_K_PKGID));
- builder.SetInstId(b.GetString(AUL_K_INSTANCE_ID));
- builder.SetExec(b.GetString(AUL_K_EXEC));
- builder.SetPid(std::stoi(b.GetString(AUL_K_PID)));
- builder.SetStatus(std::stoi(b.GetString(AUL_K_STATUS)));
- builder.SetIsSubApp(static_cast<bool>(
- std::stoi(b.GetString(AUL_K_IS_SUBAPP))));
- AppContext app_context = builder.Build();
-
- auto* handle = static_cast<AppEvent*>(user_data);
- IEvent* ev = handle->ev_;
- int context_status = std::stoi(b.GetString("__CONTEXT_STATUS__"));
- if (context_status == STATUS_TERMINATE)
- ev->OnAppTerminated(&app_context);
- else
- ev->OnAppLaunched(&app_context);
- return 0;
-}
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2020 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_APP_MANAGER_APP_EVENT_HH_
-#define AUL_APP_MANAGER_APP_EVENT_HH_
-
-#include <string>
-
-#include "aul/app_manager/app_context.hh"
-#include "include/aul.h"
-#include "include/aul_app_com.h"
-
-namespace aul {
-
-class AppEvent {
- public:
- class IEvent {
- public:
- virtual void OnAppLaunched(const AppContext* context) = 0;
- virtual void OnAppTerminated(const AppContext* context) = 0;
- };
-
- AppEvent(std::string app_id, IEvent* ev);
- explicit AppEvent(IEvent* ev);
- virtual ~AppEvent();
-
- void Listen();
-
- private:
- static int OnAppStatusCb(const char* endpoint, aul_app_com_result_e res,
- bundle* envelope, void* user_data);
-
- private:
- std::string app_id_;
- IEvent* ev_;
- std::string endpoint_;
- aul_app_com_connection_h handle_ = nullptr;
-};
-
-} // namespace aul
-
-#endif // AUL_APP_MANAGER_APP_EVENT_HH_
+++ /dev/null
-/*
- * Copyright (c) 2020 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 <tizen.h>
-
-#include <stdexcept>
-
-#include "aul/app_manager/app_manager.hh"
-#include "aul/common/exception.hh"
-#include "aul/common/log_private.hh"
-#include "aul/socket/client.hh"
-#include "include/aul.h"
-#include "include/aul_cmd.h"
-#include "include/aul_error.h"
-#include "include/aul_sock.h"
-
-namespace aul {
-
-AppManager::AppContextList AppManager::GetAppContexts() {
- AppContextList list;
- int ret = aul_app_get_running_app_info(AppInfoCb, &list);
- if (ret != AUL_R_OK)
- _E("Failed to get running app info. error(%d)", ret);
-
- return list;
-}
-
-AppManager::AppContextList AppManager::GetAllAppContexts() {
- AppContextList list;
- int ret = aul_app_get_all_running_app_info(AppInfoCb, &list);
- if (ret != AUL_R_OK)
- _E("Failed to get all running app info. error(%d)", ret);
-
- return list;
-}
-
-std::unique_ptr<AppContext> AppManager::GetAppContext(
- const std::string& app_id) {
- tizen_base::Bundle b;
- b.Add(AUL_K_APPID, app_id);
- Packet packet(APP_CONTEXT_GET, AUL_SOCK_ASYNC | AUL_SOCK_BUNDLE, b);
- return GetAppContext(packet);
-}
-
-std::unique_ptr<AppContext> AppManager::GetAppContext(
- const std::string& app_id,
- const std::string& inst_id) {
- tizen_base::Bundle b;
- b.Add(AUL_K_APPID, app_id);
- b.Add(AUL_K_INSTANCE_ID, inst_id);
- Packet packet(APP_CONTEXT_GET_BY_INSTANCE_ID,
- AUL_SOCK_ASYNC | AUL_SOCK_BUNDLE, b);
- return GetAppContext(packet);
-}
-
-std::unique_ptr<AppContext> AppManager::GetAppContext(int pid) {
- tizen_base::Bundle b;
- b.Add(AUL_K_PID, std::to_string(pid));
- Packet packet(APP_CONTEXT_GET_BY_PID, AUL_SOCK_ASYNC | AUL_SOCK_BUNDLE, b);
- return GetAppContext(packet);
-}
-
-std::unique_ptr<AppContext> AppManager::GetAppContext(const Packet& packet) {
- Packet* recv_pkt = nullptr;
- try {
- Client client(PATH_AMD_SOCK);
- int ret = client.Send(packet);
- if (ret < 0) {
- set_last_result(aul_error_convert(ret));
- return {};
- }
-
- ret = client.Recv(&recv_pkt);
- if (ret < 0) {
- set_last_result(aul_error_convert(ret));
- return {};
- }
-
- std::unique_ptr<Packet> ptr(recv_pkt);
- if (recv_pkt->GetCmd() != APP_GET_INFO_OK) {
- _E("Failed to find app context");
- set_last_result(aul_error_convert(recv_pkt->GetCmd()));
- return {};
- }
-
- set_last_result(AUL_R_OK);
- tizen_base::Bundle b = recv_pkt->DataToBundle();
- return std::unique_ptr<AppContext>(new (std::nothrow) AppContext(b));
- } catch (std::invalid_argument& e) {
- _E("Out of memory");
- set_last_result(AUL_R_ENOMEM);
- return {};
- } catch (Exception& e) {
- _E("Failed to create client. error(%d)", e.GetErrorCode());
- set_last_result(aul_error_convert(e.GetErrorCode()));
- return {};
- }
-}
-
-int AppManager::AppInfoCb(const aul_app_info* info, void* data) {
- auto* list = static_cast<AppContextList*>(data);
- AppContext::Builder builder;
- builder.SetAppId(info->appid);
- builder.SetPkgId(info->pkgid);
- builder.SetInstId(info->instance_id);
- builder.SetExec(info->app_path);
- builder.SetPid(info->pid);
- builder.SetStatus(info->status);
- builder.SetIsSubApp(static_cast<bool>(info->is_sub_app));
- list->push_back(std::make_unique<AppContext>(builder.Build()));
- return 0;
-}
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2020 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_APP_MANAGER_APP_MANAGER_HH_
-#define AUL_APP_MANAGER_APP_MANAGER_HH_
-
-#include <memory>
-#include <string>
-#include <list>
-
-#include "aul/app_manager/app_context.hh"
-#include "aul/socket/packet.hh"
-#include "include/aul.h"
-
-namespace aul {
-
-class AppManager {
- public:
- using AppContextList = std::list<std::unique_ptr<AppContext>>;
-
- AppManager() = default;
- virtual ~AppManager() = default;
-
- AppContextList GetAppContexts();
- AppContextList GetAllAppContexts();
- std::unique_ptr<AppContext> GetAppContext(const std::string& app_id);
- std::unique_ptr<AppContext> GetAppContext(const std::string& app_id,
- const std::string& inst_id);
- std::unique_ptr<AppContext> GetAppContext(int pid);
-
- private:
- std::unique_ptr<AppContext> GetAppContext(const Packet& packet);
-
- private:
- static int AppInfoCb(const aul_app_info* info, void* data);
-};
-
-} // namespace aul
-
-#endif // AUL_APP_MANAGER_APP_MANAGER_HH_
+++ /dev/null
-/*
- * Copyright (c) 2020 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_COMMON_API_HH_
-#define AUL_COMMON_API_HH_
-
-#ifdef API
-#undef API
-#endif
-#define API __attribute__ ((visibility("default")))
-
-#endif // AUL_COMMON_API_HH_
+++ /dev/null
-/*
- * Copyright (c) 2020 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_COMMON_COMMON_HH_
-#define AUL_COMMON_COMMON_HH_
-
-#undef REGULAR_UID_MIN
-#define REGULAR_UID_MIN 5000
-
-#endif // AUL_COMMON_COMMON_HH_
+++ /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 AUL_COMMON_EXCEPTION_HH_
-#define AUL_COMMON_EXCEPTION_HH_
-
-#include <string>
-#include <exception>
-
-#include "aul/common/log_private.hh"
-
-#define THROW(error_code) throw Exception(error_code, __FUNCTION__, __LINE__)
-
-namespace aul {
-
-class Exception : public std::exception {
- public:
- explicit Exception(int error_code, std::string file = __FILE__,
- int line = __LINE__ ) {
- error_code_ = error_code;
- message_ = file.substr(file.find_last_of("/") + 1) + ":"
- + std::to_string(line) + " code:" + std::to_string(error_code_);
- }
-
- virtual ~Exception() {}
-
- virtual const char *what(void) const noexcept {
- return message_.c_str();
- }
-
- int GetErrorCode() const {
- return error_code_;
- }
-
- private:
- int error_code_;
- std::string message_;
-};
-
-} // namespace aul
-
-#endif // AUL_COMMON_EXCEPTION_HH_
+++ /dev/null
-/*
- * Copyright (c) 2021 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 AUL_COMMON_FILE_DESCRIPTOR_HH_
-#define AUL_COMMON_FILE_DESCRIPTOR_HH_
-
-#include <unistd.h>
-#include <sys/types.h>
-
-namespace aul {
-
-class FileDescriptor {
- public:
- explicit FileDescriptor(int fd = -1) : fd_(fd) {}
-
- virtual ~FileDescriptor() {
- if (fd_ > -1)
- close(fd_);
- }
-
- void Set(int fd) {
- fd_ = fd;
- }
-
- int Get() const {
- return fd_;
- }
-
- void Close() {
- if (fd_ > -1) {
- close(fd_);
- fd_ = -1;
- }
- }
-
- bool IsClosed() {
- return fd_ < 0 ? true : false;
- }
-
- private:
- int fd_;
-};
-
-} // namespace aul
-
-#endif // AUL_COMMON_FILE_DESCRIPTOR_HH_
+++ /dev/null
-/*
- * Copyright (c) 2020 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_COMMON_LOG_PRIVATE_HH_
-#define AUL_COMMON_LOG_PRIVATE_HH_
-
-#include <dlog.h>
-
-#undef LOG_TAG
-#define LOG_TAG "AUL"
-
-#undef _E
-#define _E LOGE
-
-#undef _W
-#define _W LOGW
-
-#undef _I
-#define _I LOGI
-
-#undef _D
-#define _D LOGD
-
-#endif // AUL_COMMON_LOG_PRIVATE_HH_
+++ /dev/null
-/*
- * Copyright (c) 2021 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_COMMON_UTIL_HH_
-#define AUL_COMMON_UTIL_HH_
-
-#include <algorithm>
-#include <string>
-#include <vector>
-
-namespace aul {
-
-class Util {
- public:
- static std::vector<std::string> Split(const std::string& str,
- const std::string& delimiter) {
- std::string string(str);
- std::vector<std::string> result;
- std::size_t pos;
- while ((pos = string.find(delimiter)) != std::string::npos) {
- std::string token = string.substr(0, pos);
- result.push_back(token);
- string.erase(0, pos + delimiter.length());
- }
- result.push_back(string);
- return result;
- }
-};
-
-} // namespace aul
-
-#endif // AUL_COMMON_UTIL_HH_
+++ /dev/null
-/*
- * Copyright (c) 2022 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 "aul/component/component_info.hh"
-
-#include "include/aul.h"
-
-#include "aul/common/exception.hh"
-
-namespace aul {
-
-ComponentInfo::Builder& ComponentInfo::Builder::SetAppId(
- const tizen_base::Bundle& b) {
- app_id_ = std::move(b.GetString(AUL_K_APPID));
- return *this;
-}
-
-ComponentInfo::Builder& ComponentInfo::Builder::SetComponentId(
- const tizen_base::Bundle& b) {
- component_id_ = std::move(b.GetString(AUL_K_COMPONENT_ID));
- return *this;
-}
-
-ComponentInfo::Builder& ComponentInfo::Builder::SetType(
- const tizen_base::Bundle& b) {
- type_ = std::move(b.GetString(AUL_K_COMPONENT_TYPE));
- return *this;
-}
-
-ComponentInfo::Builder& ComponentInfo::Builder::SetLaunchMode(
- const tizen_base::Bundle& b) {
- launch_mode_ = std::move(b.GetString(AUL_K_LAUNCH_MODE));
- return *this;
-}
-
-ComponentInfo::Builder& ComponentInfo::Builder::SetMainComponent(
- const tizen_base::Bundle& b) {
- if (b.GetString(AUL_K_MAIN_COMP) == "true")
- main_component_ = true;
-
- return *this;
-}
-
-ComponentInfo::Builder& ComponentInfo::Builder::SetIconDisplay(
- const tizen_base::Bundle& b) {
- if (b.GetString(AUL_K_ICON_DISPLAY) == "true")
- icon_display_ = true;
-
- return *this;
-}
-
-ComponentInfo::Builder& ComponentInfo::Builder::SetTaskmanage(
- const tizen_base::Bundle& b) {
- if (b.GetString(AUL_K_TASK_MANAGE) == "true")
- taskmanage_ = true;
-
- return *this;
-}
-
-ComponentInfo::Builder& ComponentInfo::Builder::SetLocalizedInfo(
- const tizen_base::Bundle& b) {
- auto localized_info_array = b.GetStringArray(AUL_K_LOCALIZED_INFO);
- if (localized_info_array.empty())
- return *this;
-
- auto localized_info_size_array = b.GetStringArray(AUL_K_LOCALIZED_INFO_SIZE);
- if (localized_info_size_array.empty())
- return *this;
-
- if (localized_info_array.size() != localized_info_size_array.size())
- return *this;
-
- for (unsigned int i = 0; i < localized_info_size_array.size(); ++i) {
- int len = std::stoi(localized_info_size_array[i]);
- auto* kb = bundle_decode(
- reinterpret_cast<bundle_raw*>(const_cast<char*>(
- localized_info_array[i].c_str())), len);
- if (kb == nullptr)
- return *this;
-
- try {
- tizen_base::Bundle b(kb, false, true);
- LocalizedInfo* info = LocalizedInfo::Builder()
- .SetLocale(b)
- .SetIcon(b)
- .SetLabel(b);
- if (info == nullptr)
- return *this;
-
- auto locale = info->GetLocale();
- localized_info_[std::move(locale)] = std::shared_ptr<LocalizedInfo>(info);
- } catch (const Exception& e) {
- _E("Exception occurs. error(%s)", e.what());
- }
- }
-
- return *this;
-}
-
-
-ComponentInfo::Builder::operator ComponentInfo*() {
- Validate();
- return new (std::nothrow) ComponentInfo(std::move(app_id_),
- std::move(component_id_), std::move(type_), std::move(launch_mode_),
- main_component_, icon_display_, taskmanage_, std::move(localized_info_));
-}
-
-void ComponentInfo::Builder::Validate() {
- if (app_id_.empty() ||
- component_id_.empty() ||
- type_.empty() ||
- launch_mode_.empty())
- THROW(AUL_R_ERROR);
-}
-
-ComponentInfo::ComponentInfo(std::string app_id,
- std::string component_id,
- std::string type,
- std::string launch_mode,
- bool main_component,
- bool icon_display,
- bool taskmanage,
- std::unordered_map<std::string,
- std::shared_ptr<LocalizedInfo>> localized_info)
- : app_id_(std::move(app_id)),
- component_id_(std::move(component_id)),
- type_(std::move(type)),
- launch_mode_(std::move(launch_mode)),
- main_component_(main_component),
- icon_display_(icon_display),
- taskmanage_(taskmanage),
- localized_info_(std::move(localized_info)) {
-}
-
-const std::string& ComponentInfo::GetAppId() const {
- return app_id_;
-}
-
-const std::string& ComponentInfo::GetComponentId() const {
- return component_id_;
-}
-
-const std::string& ComponentInfo::GetType() const {
- return type_;
-}
-
-const std::string& ComponentInfo::GetLaunchMode() const {
- return launch_mode_;
-}
-
-bool ComponentInfo::IsMainComponent() const {
- return main_component_;
-}
-
-bool ComponentInfo::IsIconDisplay() const {
- return icon_display_;
-}
-
-bool ComponentInfo::IsTaskmanage() const {
- return taskmanage_;
-}
-
-const LocalizedInfo* ComponentInfo::GetLocalizedInfo(
- const std::string& locale) const {
- auto found = localized_info_.find(locale);
- if (found == localized_info_.end())
- return nullptr;
-
- return (found->second).get();
-}
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2022 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_COMPONENT_COMPONENT_INFO_HH_
-#define AUL_COMPONENT_COMPONENT_INFO_HH_
-
-#include <bundle_cpp.h>
-
-#include <memory>
-#include <string>
-#include <unordered_map>
-
-#include "aul/component/localized_info.hh"
-
-namespace aul {
-
-class ComponentInfo {
- public:
- class Builder {
- public:
- Builder& SetAppId(const tizen_base::Bundle& b);
- Builder& SetComponentId(const tizen_base::Bundle& b);
- Builder& SetType(const tizen_base::Bundle& b);
- Builder& SetLaunchMode(const tizen_base::Bundle& b);
- Builder& SetMainComponent(const tizen_base::Bundle& b);
- Builder& SetIconDisplay(const tizen_base::Bundle& b);
- Builder& SetTaskmanage(const tizen_base::Bundle& b);
- Builder& SetLocalizedInfo(const tizen_base::Bundle& b);
-
- operator ComponentInfo*();
-
- private:
- void Validate();
-
- private:
- std::string app_id_;
- std::string component_id_;
- std::string type_;
- std::string launch_mode_;
- bool main_component_ = false;
- bool icon_display_ = false;
- bool taskmanage_ = false;
- std::unordered_map<std::string,
- std::shared_ptr<LocalizedInfo>> localized_info_;
- };
-
- ComponentInfo(std::string app_id,
- std::string component_id,
- std::string type,
- std::string launch_mode,
- bool main_component,
- bool icon_display,
- bool taskmanage,
- std::unordered_map<std::string,
- std::shared_ptr<LocalizedInfo>> localized_info);
-
- const std::string& GetAppId() const;
- const std::string& GetComponentId() const;
- const std::string& GetType() const;
- const std::string& GetLaunchMode() const;
- bool IsMainComponent() const;
- bool IsIconDisplay() const;
- bool IsTaskmanage() const;
- const LocalizedInfo* GetLocalizedInfo(const std::string& locale) const;
-
- private:
- std::string app_id_;
- std::string component_id_;
- std::string type_;
- std::string launch_mode_;
- bool main_component_ = false;
- bool icon_display_ = false;
- bool taskmanage_ = false;
- std::unordered_map<std::string,
- std::shared_ptr<LocalizedInfo>> localized_info_;
-};
-
-} // namespace aul
-
-#endif // AUL_COMPONENT_COMPONENT_INFO_HH_
+++ /dev/null
-/*
- * Copyright (c) 2020 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 <bundle_cpp.h>
-#include <tizen.h>
-
-#include <stdexcept>
-
-#include "aul/common/log_private.hh"
-#include "aul/common/exception.hh"
-#include "aul/component/component_port.hh"
-#include "aul/socket/client.hh"
-#include "include/aul.h"
-#include "include/aul_cmd.h"
-#include "include/aul_error.h"
-#include "include/aul_sock.h"
-
-namespace aul {
-
-ComponentPort::ComponentPort(std::string name)
- : name_(std::move(name)) {
-}
-
-bool ComponentPort::Exist() {
- int ret = SendRequest(COMP_PORT_EXIST, AUL_SOCK_NONE);
- if (ret < 0) {
- _E("Failed to send a request. error(%d)", ret);
- set_last_result(ret);
- return false;
- }
-
- return ret == 1 ? true : false;
-}
-
-int ComponentPort::Create() {
- tizen_base::Bundle b;
- b.Add(AUL_K_COMPONENT_PORT, name_);
- Packet pkt(COMP_PORT_CREATE, AUL_SOCK_ASYNC | AUL_SOCK_BUNDLE, b);
- int fds[2] = { -1, };
- try {
- Client client(PATH_AMD_SOCK);
- int ret = client.Send(pkt);
- if (ret < 0)
- return aul_error_convert(ret);
-
- ret = aul_sock_recv_reply_sock_fd(client.RemoveFd(), &fds, 1);
- if (ret != 0)
- return aul_error_convert(ret);
- } catch (Exception& e) {
- _E("Failed to create client. error(%d)", e.GetErrorCode());
- return aul_error_convert(e.GetErrorCode());
- }
-
- return fds[0];
-}
-
-int ComponentPort::Destroy() {
- int ret = SendRequest(COMP_PORT_DESTROY, AUL_SOCK_NOREPLY);
- if (ret < 0) {
- _E("Failed to send a request. error(%d)", ret);
- return ret;
- }
-
- return 0;
-}
-
-int ComponentPort::SendRequest(int cmd, int opt) {
- tizen_base::Bundle b;
- b.Add(AUL_K_COMPONENT_PORT, name_);
- Packet pkt(cmd, opt | AUL_SOCK_BUNDLE, b);
- Packet* recv_pkt = nullptr;
- try {
- Client client(PATH_AMD_SOCK);
- int ret = client.Send(pkt);
- if (ret < 0)
- return aul_error_convert(ret);
-
- if (opt & AUL_SOCK_NOREPLY)
- return ret;
-
- ret = client.Recv(&recv_pkt);
- if (ret < 0)
- return aul_error_convert(ret);
-
- std::unique_ptr<Packet> ptr(recv_pkt);
- if (recv_pkt->GetCmd() != cmd) {
- _E("Invalid protocol");
- return AUL_R_ECOMM;
- }
-
- b = recv_pkt->DataToBundle();
- auto str = b.GetString(AUL_K_RESULT);
- ret = std::stoi(str);
- if (ret < 0)
- return aul_error_convert(ret);
-
- return ret;
- } catch(std::invalid_argument& e) {
- _E("Out of memory");
- return AUL_R_ENOMEM;
- } catch (Exception& e) {
- _E("Failed to create client. error(%d)", e.GetErrorCode());
- return aul_error_convert(e.GetErrorCode());
- }
-}
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2020 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_COMPONENT_COMPONENT_PORT_HH_
-#define AUL_COMPONENT_COMPONENT_PORT_HH_
-
-#include <string>
-
-namespace aul {
-
-class ComponentPort {
- public:
- explicit ComponentPort(std::string name);
- virtual ~ComponentPort() = default;
-
- bool Exist();
- int Create();
- int Destroy();
-
- private:
- int SendRequest(int cmd, int opt);
-
- private:
- std::string name_;
-};
-
-} // namespace aul
-
-#endif // AUL_COMPONENT_COMPONENT_PORT_HH_
+++ /dev/null
-/*
- * Copyright (c) 2022 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 "aul/component/component_running_context.hh"
-
-#include "include/aul.h"
-
-#include "aul/common/exception.hh"
-
-namespace aul {
-
-ComponentRunningContext::Builder&
-ComponentRunningContext::Builder::SetComponentId(const tizen_base::Bundle& b) {
- component_id_ = std::move(b.GetString(AUL_K_COMPONENT_ID));
- return *this;
-}
-
-ComponentRunningContext::Builder&
-ComponentRunningContext::Builder::SetInstanceId(const tizen_base::Bundle& b) {
- instance_id_ = std::move(b.GetString(AUL_K_INSTANCE_ID));
- return *this;
-}
-
-ComponentRunningContext::Builder& ComponentRunningContext::Builder::SetAppId(
- const tizen_base::Bundle& b) {
- app_id_ = std::move(b.GetString(AUL_K_APPID));
- return *this;
-}
-
-ComponentRunningContext::Builder& ComponentRunningContext::Builder::SetType(
- const tizen_base::Bundle& b) {
- type_ = std::move(b.GetString(AUL_K_COMPONENT_TYPE));
- return *this;
-}
-
-ComponentRunningContext::Builder& ComponentRunningContext::Builder::SetPid(
- const tizen_base::Bundle& b) {
- auto value = b.GetString(AUL_K_PID);
- if (value.empty())
- return *this;
-
- pid_ = std::stoi(value);
- return *this;
-}
-
-ComponentRunningContext::Builder& ComponentRunningContext::Builder::SetStatus(
- const tizen_base::Bundle& b) {
- auto value = b.GetString(AUL_K_STATUS);
- if (value.empty())
- return *this;
-
- status_ = std::stoi(value);
- return *this;
-}
-
-ComponentRunningContext::Builder&
-ComponentRunningContext::Builder::SetSubComponent(const tizen_base::Bundle& b) {
- auto value = b.GetString(AUL_K_IS_SUB_COMP);
- if (value.empty())
- return *this;
-
- is_sub_component_ = std::stoi(value) ? true : false;
- return *this;
-}
-
-ComponentRunningContext::Builder::operator ComponentRunningContext*() {
- Validate();
- return new (std::nothrow) ComponentRunningContext(std::move(component_id_),
- std::move(instance_id_), std::move(app_id_), std::move(type_),
- pid_, status_, is_sub_component_);
-}
-
-void ComponentRunningContext::Builder::Validate() {
- if (component_id_.empty() ||
- instance_id_.empty() ||
- app_id_.empty() ||
- type_.empty() ||
- pid_ < 0 ||
- status_ < 0 )
- THROW(AUL_R_ERROR);
-}
-
-ComponentRunningContext::ComponentRunningContext(std::string component_id,
- std::string instance_id,
- std::string app_id,
- std::string type,
- pid_t pid,
- int status,
- bool is_sub_component)
- : component_id_(std::move(component_id)),
- instance_id_(std::move(instance_id)),
- app_id_(std::move(app_id)),
- type_(std::move(type)),
- pid_(pid),
- status_(status),
- is_sub_component_(is_sub_component) {
-}
-
-const std::string& ComponentRunningContext::GetComponentId() const {
- return component_id_;
-}
-
-const std::string& ComponentRunningContext::GetInstanceId() const {
- return instance_id_;
-}
-
-const std::string& ComponentRunningContext::GetAppId() const {
- return app_id_;
-}
-
-const std::string& ComponentRunningContext::GetType() const {
- return type_;
-}
-
-pid_t ComponentRunningContext::GetPid() const {
- return pid_;
-}
-
-int ComponentRunningContext::GetStatus() const {
- return status_;
-}
-
-bool ComponentRunningContext::IsSubComponent() const {
- return is_sub_component_;
-}
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2022 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_COMPONENT_COMPONENT_RUNNING_CONTEXT_HH_
-#define AUL_COMPONENT_COMPONENT_RUNNING_CONTEXT_HH_
-
-#include <unistd.h>
-
-#include <bundle_cpp.h>
-
-#include <string>
-
-namespace aul {
-
-class ComponentRunningContext {
- public:
- class Builder {
- public:
- Builder& SetComponentId(const tizen_base::Bundle& b);
- Builder& SetInstanceId(const tizen_base::Bundle& b);
- Builder& SetAppId(const tizen_base::Bundle& b);
- Builder& SetType(const tizen_base::Bundle& b);
- Builder& SetPid(const tizen_base::Bundle& b);
- Builder& SetStatus(const tizen_base::Bundle& b);
- Builder& SetSubComponent(const tizen_base::Bundle& b);
-
- operator ComponentRunningContext*();
-
- private:
- void Validate();
-
- private:
- std::string component_id_;
- std::string instance_id_;
- std::string app_id_;
- std::string type_;
- pid_t pid_ = -1;
- int status_ = -1;
- bool is_sub_component_ = false;
- };
-
- ComponentRunningContext(std::string component_id,
- std::string instance_id,
- std::string app_id,
- std::string type,
- pid_t pid,
- int status,
- bool is_sub_component);
-
- const std::string& GetComponentId() const;
- const std::string& GetInstanceId() const;
- const std::string& GetAppId() const;
- const std::string& GetType() const;
- pid_t GetPid() const;
- int GetStatus() const;
- bool IsSubComponent() const;
-
- private:
- std::string component_id_;
- std::string instance_id_;
- std::string app_id_;
- std::string type_;
- pid_t pid_;
- int status_;
- bool is_sub_component_;
-};
-
-} // namespace aul
-
-#endif // AUL_COMPONENT_COMPONENT_RUNNING_CONTEXT_HH_
+++ /dev/null
-/*
- * Copyright (c) 2022 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 "aul/component/localized_info.hh"
-
-#include "aul/common/exception.hh"
-#include "include/aul.h"
-
-namespace aul {
-
-LocalizedInfo::Builder& LocalizedInfo::Builder::SetLocale(
- const tizen_base::Bundle& b) {
- locale_ = std::move(b.GetString(AUL_K_LOCALE));
- return *this;
-}
-
-LocalizedInfo::Builder& LocalizedInfo::Builder::SetIcon(
- const tizen_base::Bundle& b) {
- icon_ = std::move(b.GetString(AUL_K_ICON));
- return *this;
-}
-
-LocalizedInfo::Builder& LocalizedInfo::Builder::SetLabel(
- const tizen_base::Bundle& b) {
- label_ = std::move(b.GetString(AUL_K_LABEL));
- return *this;
-}
-
-LocalizedInfo::Builder::operator LocalizedInfo*() {
- Validate();
- return new (std::nothrow) LocalizedInfo(std::move(locale_),
- std::move(icon_), std::move(label_));
-}
-
-void LocalizedInfo::Builder::Validate() {
- if (locale_.empty())
- THROW(AUL_R_ERROR);
-}
-
-LocalizedInfo::LocalizedInfo(std::string locale, std::string icon,
- std::string label)
- : locale_(std::move(locale)),
- icon_(std::move(icon)),
- label_(std::move(label)) {
-}
-
-const std::string& LocalizedInfo::GetLocale() const {
- return locale_;
-}
-
-const std::string& LocalizedInfo::GetIcon() const {
- return icon_;
-}
-
-const std::string& LocalizedInfo::GetLabel() const {
- return label_;
-}
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2022 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_COMPONENT_LOCALIZED_INFO_HH_
-#define AUL_COMPONENT_LOCALIZED_INFO_HH_
-
-#include <bundle_cpp.h>
-
-#include <string>
-
-namespace aul {
-
-class LocalizedInfo {
- public:
- class Builder {
- public:
- Builder& SetLocale(const tizen_base::Bundle& b);
- Builder& SetIcon(const tizen_base::Bundle& b);
- Builder& SetLabel(const tizen_base::Bundle& b);
-
- operator LocalizedInfo*();
-
- private:
- void Validate();
-
- private:
- std::string locale_;
- std::string icon_;
- std::string label_;
- };
-
- LocalizedInfo(std::string locale, std::string icon, std::string label);
-
- const std::string& GetLocale() const;
- const std::string& GetIcon() const;
- const std::string& GetLabel() const;
-
- private:
- std::string locale_;
- std::string icon_;
- std::string label_;
-};
-
-} // namespace aul
-
-#endif // AUL_COMPONENT_LOCALIZED_INFO_HH_
+++ /dev/null
-/*
- * Copyright (c) 2020 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 <unistd.h>
-
-#include <memory>
-#include <type_traits>
-
-#include "aul/common/exception.hh"
-#include "aul/common/log_private.hh"
-#include "aul/socket/client.hh"
-
-namespace aul {
-
-namespace {
-
-// POD type
-class Header {
- public:
- int cmd;
- int len;
- int opt;
-};
-
-} // namespace
-
-Client::Client(std::string path, int timeout_msec) : Socket(std::move(path)) {
- int retry = 2;
- do {
- int ret = Connect();
- if (ret == 0) {
- break;
- } else if (ret < -1) {
- _E("Maybe peer not launched or peer dead. path(%s), fd(%d)",
- GetPath().c_str(), GetFd());
- usleep(100 * 1000);
- --retry;
- } else if (ret < 0) {
- _E("Failed to connect to socket(%s), fd(%d)",
- GetPath().c_str(), GetFd());
- THROW(-ECOMM);
- }
- } while (retry > 0);
-
- if (retry == 0)
- THROW(-ECOMM);
-
- SetTimeout(timeout_msec);
-}
-
-int Client::Send(const Packet& packet) {
- _W("cmd(%d)", packet.GetCmd());
- tizen_base::Parcel parcel;
- parcel.WriteParcelable(packet);
- return Socket::Send(parcel.GetData(), parcel.GetDataSize());
-}
-
-int Client::Recv(Packet** packet) {
- Header header;
- static_assert(std::is_standard_layout<Header>(),
- "Header should be POD type");
- static_assert(std::is_trivial<Header>(), "Header should be POD type");
-
- int ret = Socket::Recv(&header, sizeof(Header));
- if (ret < 0)
- return ret;
-
- if (header.len < 0 || header.len > MAX_PAYLOAD_SIZE) {
- _E("Invalid size(%d)", header.len);
- return -ECOMM;
- }
-
- std::vector<unsigned char> buf(header.len);
- ret = Socket::Recv(buf.data(), header.len);
- if (ret < 0) {
- return ret;
- }
-
- *packet = new (std::nothrow) Packet(header.cmd, header.opt, std::move(buf));
- if (*packet == nullptr) {
- _E("Out of memory");
- return -ENOMEM;
- }
-
- return 0;
-}
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2020 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_SOCKET_CLIENT_HH_
-#define AUL_SOCKET_CLIENT_HH_
-
-#include "aul/socket/packet.hh"
-#include "aul/socket/socket.hh"
-
-namespace aul {
-
-class Client : public Socket {
- public:
- explicit Client(std::string path, int timeout_msec = 5000);
- int Send(const Packet& packet);
- int Recv(Packet** packet);
-};
-
-} // namespace aul
-
-#endif // AUL_SOCKET_CLIENT_HH_
+++ /dev/null
-/*
- * Copyright (c) 2022 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 "aul/socket/client_socket.hh"
-
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <sys/un.h>
-#include <unistd.h>
-
-namespace aul {
-namespace {
-
-constexpr const int MAX_RETRY_CNT = 2;
-
-} // namespace
-
-ClientSocket::ClientSocket() {
- fd_ = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
- if (fd_ < 0) {
- int error = -errno;
- _E("socket() is failed. errno(%d)", errno);
- THROW(error);
- }
-}
-
-ClientSocket::ClientSocket(int fd) : fd_(fd) {}
-
-ClientSocket::~ClientSocket() {
- Close();
-}
-
-void ClientSocket::Close() {
- if (fd_ > -1) {
- close(fd_);
- fd_ = -1;
- }
-}
-
-void ClientSocket::Connect(const std::string& endpoint) {
- int flag = fcntl(fd_, F_GETFL, 0);
- if (flag == -1) {
- int ret = -errno;
- _E("Failed to fcntl(%d, F_GETFL, 0). errno(%d)", fd_, errno);
- THROW(ret);
- }
-
- fcntl(fd_, F_SETFL, flag | O_NONBLOCK);
- struct sockaddr_un sockaddr = { 0, };
- sockaddr.sun_family = AF_UNIX;
- snprintf(sockaddr.sun_path, sizeof(sockaddr.sun_path), "%s",
- endpoint.c_str());
- struct sockaddr* sockaddr_ptr = reinterpret_cast<struct sockaddr*>(&sockaddr);
- socklen_t len = static_cast<socklen_t>(sizeof(sockaddr));
-
- int ret;
- int retry = 2;
- do {
- ret = connect(fd_, sockaddr_ptr, len);
- if (ret == 0)
- break;
-
- retry--;
- ret = -errno;
- usleep(100 * 1000);
- } while (retry > 0);
-
- fcntl(fd_, F_SETFL, flag);
- if (ret < 0) {
- _E("connect() is failed. errno(%d)", -ret);
- THROW(ret);
- }
-}
-
-int ClientSocket::Send(const void* buf, unsigned int size) {
- const unsigned char* buffer = static_cast<const unsigned char*>(buf);
- size_t len = size;
- int retry_cnt = MAX_RETRY_CNT;
- while (len) {
- ssize_t bytes = send(fd_, buffer, len, MSG_NOSIGNAL | MSG_DONTWAIT);
- if (bytes < 0) {
- if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) {
- if (retry_cnt > 0) {
- retry_cnt--;
- _E("send(): fd(%d), errno(%d). sleep and retry ...", fd_, errno);
- usleep(10 * 1000);
- continue;
- }
- }
-
- _E("send() is failed. fd(%d), errno(%d)", fd_, errno);
- return -ECOMM;
- }
-
- len -= bytes;
- buffer += bytes;
- }
-
- return 0;
-}
-
-int ClientSocket::Receive(void* buf, unsigned int size) {
- bool is_blocking;
- if (fcntl(fd_, F_GETFL, 0) & O_NONBLOCK)
- is_blocking = false;
- else
- is_blocking = true;
-
- int retry_count = 20;
- unsigned char* buffer = static_cast<unsigned char*>(buf);
- size_t len = size;
- while (len) {
- ssize_t bytes = recv(fd_, buffer, len, 0);
- if (bytes == 0) {
- _W("EOF. fd(%d)", fd_);
- return -ECOMM;
- }
-
- if (bytes < 0) {
- if (errno == EINTR || errno == EAGAIN) {
- if (is_blocking && errno == EAGAIN) {
- _E("Timed out. fd(%d)", fd_);
- return -EAGAIN;
- }
-
- if (retry_count > 0) {
- usleep(100 * 1000);
- retry_count--;
- continue;
- }
- }
-
- _E("recv() is failed. fd(%d), errno(%d)", fd_, errno);
- return -ECOMM;
- }
-
- len -= bytes;
- buffer += bytes;
- }
-
- return 0;
-}
-
-int ClientSocket::GetReceiveBufferSize() {
- int value;
- socklen_t len = sizeof(int);
- int ret = getsockopt(fd_, SOL_SOCKET, SO_RCVBUF,
- reinterpret_cast<void*>(&value), &len);
- if (ret < 0) {
- ret = -errno;
- _E("getsockopt() is failed. errno(%d)", errno);
- THROW(ret);
- }
-
- return value;
-}
-
-int ClientSocket::GetSendBufferSize() {
- int value;
- socklen_t len = sizeof(int);
- int ret = getsockopt(fd_, SOL_SOCKET, SO_SNDBUF,
- reinterpret_cast<void*>(&value), &len);
- if (ret < 0) {
- ret = -errno;
- _E("getsockopt() is failed. errno(%d)", errno);
- THROW(ret);
- }
-
- return value;
-}
-
-int ClientSocket::GetReceiveTimeout() {
- struct timeval timeout = { 0, };
- socklen_t len = static_cast<socklen_t>(sizeof(struct timeval));
- int ret = getsockopt(fd_, SOL_SOCKET, SO_RCVTIMEO,
- reinterpret_cast<void*>(&timeout), &len);
- if (ret < 0) {
- ret = -errno;
- _E("getsockopt() is failed. errno(%d)", errno);
- THROW(ret);
- }
-
- int value = timeout.tv_sec * 1000 + timeout.tv_usec / 1000;
- return value;
-}
-
-void ClientSocket::SetReceiveBufferSize(int size) {
- socklen_t len = sizeof(size);
- int ret = setsockopt(fd_, SOL_SOCKET, SO_RCVBUF, &size, len);
- if (ret < 0) {
- ret = -errno;
- _E("setsockopt() is failed. errno(%d)", errno);
- THROW(ret);
- }
-}
-
-void ClientSocket::SetSendBufferSize(int size) {
- socklen_t len = sizeof(size);
- int ret = setsockopt(fd_, SOL_SOCKET, SO_SNDBUF, &size, len);
- if (ret < 0) {
- ret = -errno;
- _E("setsockopt() is failed. errno(%d)", errno);
- THROW(ret);
- }
-}
-
-void ClientSocket::SetReceiveTimeout(int timeout) {
- if (timeout == INT_MAX)
- return;
-
- if (timeout == -1)
- timeout = 5000;
-
- if (timeout < 0) {
- _E("Invalid parameter");
- THROW(-EINVAL);
- }
-
- struct timeval tv = {
- .tv_sec = static_cast<time_t>(timeout / 1000),
- .tv_usec = static_cast<suseconds_t>((timeout % 1000) * 1000)
- };
- socklen_t len = static_cast<socklen_t>(sizeof(struct timeval));
- int ret = setsockopt(fd_, SOL_SOCKET, SO_RCVTIMEO, &tv, len);
- if (ret < 0) {
- ret = -errno;
- _E("setsockopt() is failed. errno(%d)", errno);
- THROW(ret);
- }
-}
-
-bool ClientSocket::IsClosed() {
- return fd_ < 0;
-}
-
-int ClientSocket::GetFd() const {
- return fd_;
-}
-
-int ClientSocket::RemoveFd() {
- int fd = fd_;
- fd_ = -1;
- return fd;
-}
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2022 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_SOCKET_CLIENT_SOCKET_HH_
-#define AUL_SOCKET_CLIENT_SOCKET_HH_
-
-#include <memory>
-#include <string>
-
-#include "aul/common/exception.hh"
-
-namespace aul {
-
-class ClientSocket {
- public:
- ClientSocket();
- explicit ClientSocket(int fd);
- virtual ~ClientSocket();
-
- void Close();
- void Connect(const std::string& endpoint);
- int Send(const void* buf, unsigned int size);
- int Receive(void* buf, unsigned int size);
- int GetReceiveBufferSize();
- int GetSendBufferSize();
- int GetReceiveTimeout();
- void SetReceiveBufferSize(int size);
- void SetSendBufferSize(int size);
- void SetReceiveTimeout(int timeout);
- bool IsClosed();
- int GetFd() const;
- int RemoveFd();
-
- private:
- int fd_;
-};
-
-} // namespace aul
-
-#endif // AUL_SOCKET_CLIENT_SOCKET_HH_
+++ /dev/null
-/*
- * Copyright (c) 2020 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 <memory>
-
-#include "aul/socket/packet.hh"
-
-namespace aul {
-
-Packet::Packet() : cmd_(0), opt_(0) {
-}
-
-Packet::Packet(int cmd, int opt, std::vector<unsigned char> data)
- : cmd_(cmd), opt_(opt), data_(std::move(data)) {
-}
-
-Packet::Packet(int cmd, int opt, tizen_base::Bundle data)
- : cmd_(cmd), opt_(opt) {
- auto raw = data.ToRaw();
- auto* raw_ptr = reinterpret_cast<unsigned char*>(raw.first.get());
- data_.insert(data_.end(), raw_ptr, raw_ptr + raw.second);
-}
-
-Packet::Packet(const unsigned char* buf, unsigned int size)
- : cmd_(-1), opt_(0) {
- tizen_base::Parcel parcel(buf, size);
- parcel.ReadParcelable(this);
-}
-
-int Packet::GetCmd() const {
- return cmd_;
-}
-
-int Packet::GetOpt() const {
- return opt_;
-}
-
-const std::vector<unsigned char>& Packet::GetData() {
- return data_;
-}
-
-void Packet::SetCmd(int cmd) {
- cmd_ = cmd;
-}
-
-void Packet::SetOpt(int opt) {
- opt_ = opt;
-}
-
-void Packet::SetData(std::vector<unsigned char> data) {
- data_ = std::move(data);
-}
-
-tizen_base::Bundle Packet::DataToBundle() {
- const bundle_raw* raw = reinterpret_cast<const bundle_raw*>(&data_[0]);
- bundle* b = bundle_decode(raw, data_.size());
- return tizen_base::Bundle(b, false, true);
-}
-
-void Packet::WriteToParcel(tizen_base::Parcel* parcel) const {
- parcel->WriteInt32(cmd_);
- parcel->WriteInt32(data_.size());
- parcel->WriteInt32(opt_);
- if (data_.size() > 0) {
- auto* p = reinterpret_cast<const void*>(&data_[0]);
- parcel->Write(p, data_.size());
- }
-}
-
-void Packet::ReadFromParcel(tizen_base::Parcel* parcel) {
- parcel->ReadInt32(&cmd_);
- int size = 0;
- parcel->ReadInt32(&size);
- parcel->ReadInt32(&opt_);
- if (size > 0) {
- auto* data = new (std::nothrow) unsigned char[size];
- if (data == nullptr)
- return;
-
- std::unique_ptr<unsigned char[]> ptr(data);
- parcel->Read(data, size);
- data_.insert(data_.end(), data, data + size);
- }
-}
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2020 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_SOCKET_PACKET_HH_
-#define AUL_SOCKET_PACKET_HH_
-
-#include <bundle_cpp.h>
-#include <parcel.hh>
-#include <parcelable.hh>
-
-#include <vector>
-
-namespace aul {
-
-class Packet : public tizen_base::Parcelable {
- public:
- Packet();
- Packet(int cmd, int opt, std::vector<unsigned char> data);
- Packet(int cmd, int opt, tizen_base::Bundle data);
- Packet(const unsigned char* buf, unsigned int size);
- virtual ~Packet() = default;
-
- int GetCmd() const;
- int GetOpt() const;
- const std::vector<unsigned char>& GetData();
-
- void SetCmd(int cmd);
- void SetOpt(int opt);
- void SetData(std::vector<unsigned char> data);
-
- tizen_base::Bundle DataToBundle();
-
- void WriteToParcel(tizen_base::Parcel* parcel) const override;
- void ReadFromParcel(tizen_base::Parcel* parcel) override;
-
- private:
- int cmd_;
- int opt_;
- std::vector<unsigned char> data_;
-};
-
-} // namespace aul
-
-#endif // AUL_SOCKET_PACKET_HH_
+++ /dev/null
-/*
- * Copyright (c) 2022 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 "aul/socket/server_socket.hh"
-
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <sys/un.h>
-#include <unistd.h>
-
-#include "aul/common/exception.hh"
-#include "aul/common/log_private.hh"
-
-namespace aul {
-
-ServerSocket::ServerSocket() {
- fd_ = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
- if (fd_ < 0) {
- fd_ = -errno;
- _E("socket() is failed. errno(%d)", errno);
- THROW(fd_);
- }
-}
-
-ServerSocket::ServerSocket(int fd) : fd_(fd) {}
-
-ServerSocket::~ServerSocket() {
- Close();
-}
-
-ClientSocket* ServerSocket::Accept() {
- struct sockaddr_un addr = { 0, };
- socklen_t len = static_cast<socklen_t>(sizeof(struct sockaddr_un));
- auto* addr_ptr = reinterpret_cast<struct sockaddr*>(&addr);
- int client_fd = accept(GetFd(), addr_ptr, &len);
- if (client_fd == -1) {
- _E("accept() is failed. errno(%d)", errno);
- return nullptr;
- }
-
- ClientSocket* client = new (std::nothrow) ClientSocket(client_fd);
- if (client == nullptr) {
- _E("Out of memory");
- close(client_fd);
- return nullptr;
- }
-
- return client;
-}
-
-void ServerSocket::Bind(const std::string& bindpoint) {
- struct sockaddr_un sockaddr = { 0, };
- sockaddr.sun_family = AF_UNIX;
- snprintf(sockaddr.sun_path, sizeof(sockaddr.sun_path), "%s",
- bindpoint.c_str());
- struct sockaddr* sockaddr_ptr = reinterpret_cast<struct sockaddr*>(&sockaddr);
- socklen_t len = static_cast<socklen_t>(sizeof(sockaddr));
-
- unlink(bindpoint.c_str());
- int ret = bind(GetFd(), sockaddr_ptr, len);
- if (ret < 0) {
- ret = -errno;
- _E("bind() is failed. errno(%d)", errno);
- THROW(ret);
- }
-}
-
-void ServerSocket::Close() {
- if (fd_ > -1) {
- close(fd_);
- fd_ = -1;
- }
-}
-
-void ServerSocket::Listen(int backlog) {
- int ret = listen(fd_, backlog);
- if (ret < 0) {
- ret = -errno;
- _E("listen() is failed. errno(%d)", errno);
- THROW(ret);
- }
-}
-
-int ServerSocket::GetReceiveBufferSize() {
- int value;
- socklen_t len = sizeof(int);
- int ret = getsockopt(fd_, SOL_SOCKET, SO_RCVBUF,
- reinterpret_cast<void*>(&value), &len);
- if (ret < 0) {
- ret = -errno;
- _E("getsockopt() is failed. errno(%d)", errno);
- THROW(ret);
- }
-
- return value;
-}
-
-int ServerSocket::GetSendBufferSize() {
- int value;
- socklen_t len = sizeof(int);
- int ret = getsockopt(fd_, SOL_SOCKET, SO_SNDBUF,
- reinterpret_cast<void*>(&value), &len);
- if (ret < 0) {
- ret = -errno;
- _E("getsockopt() is failed. errno(%d)", errno);
- THROW(ret);
- }
-
- return value;
-}
-
-void ServerSocket::SetReceiveBufferSize(int size) {
- socklen_t len = sizeof(size);
- int ret = setsockopt(fd_, SOL_SOCKET, SO_RCVBUF, &size, len);
- if (ret < 0) {
- ret = -errno;
- _E("setsockopt() is failed. errno(%d)", errno);
- THROW(ret);
- }
-}
-
-void ServerSocket::SetSendBufferSize(int size) {
- socklen_t len = sizeof(size);
- int ret = setsockopt(fd_, SOL_SOCKET, SO_SNDBUF, &size, len);
- if (ret < 0) {
- ret = -errno;
- _E("setsockopt() is failed. errno(%d)", errno);
- THROW(ret);
- }
-}
-
-bool ServerSocket::IsClosed() {
- return fd_ < 0;
-}
-
-int ServerSocket::GetFd() const {
- return fd_;
-}
-
-int ServerSocket::RemoveFd() {
- int fd = fd_;
- fd_ = -1;
- return fd;
-}
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2022 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_SOCKET_SERVER_SOCKET_HH_
-#define AUL_SOCKET_SERVER_SOCKET_HH_
-
-#include <memory>
-#include <string>
-
-#include "aul/common/exception.hh"
-#include "aul/socket/client_socket.hh"
-
-namespace aul {
-
-class ServerSocket {
- public:
- ServerSocket();
- explicit ServerSocket(int fd);
- virtual ~ServerSocket();
-
- ClientSocket* Accept();
- void Bind(const std::string& bindpoint);
- void Close();
- void Listen(int backlog);
- int GetReceiveBufferSize();
- int GetSendBufferSize();
- void SetReceiveBufferSize(int size);
- void SetSendBufferSize(int size);
- bool IsClosed();
- int GetFd() const;
- int RemoveFd();
-
- private:
- int fd_;
-};
-
-} // namespace aul
-
-#endif // AUL_SOCKET_SERVER_SOCKET_HH_
+++ /dev/null
-/*
- * Copyright (c) 2020 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 <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <unistd.h>
-
-#include <algorithm>
-
-#include "aul/common/log_private.hh"
-#include "aul/socket/socket.hh"
-
-namespace aul {
-
-Socket::Socket(std::string path) : path_(std::move(path)), fd_(0) {
- Create();
-}
-
-Socket::Socket(int fd)
- : fd_(fd) {
-}
-
-Socket::~Socket() {
- if (fd_ > 0)
- close(fd_);
-}
-
-int Socket::Send(const void* buf, unsigned int size) {
- const unsigned char* buffer = static_cast<const unsigned char*>(buf);
- unsigned int left = size;
- while (left) {
- ssize_t nb = send(fd_, buffer, left, MSG_NOSIGNAL);
- if (nb < 0) {
- _E("send() is failed. fd(%d), errno(%d)", fd_, errno);
- return -ECOMM;
- }
-
- left -= nb;
- buffer += nb;
- }
-
- return 0;
-}
-
-int Socket::Recv(void* buf, unsigned int size) {
- bool is_blocking = true;
- if (fcntl(fd_, F_GETFL, 0) & O_NONBLOCK)
- is_blocking = false;
-
- int retry_count = 20;
- unsigned char* buffer = static_cast<unsigned char*>(buf);
- unsigned int left = size;
- while (left) {
- ssize_t nb = recv(fd_, buffer, left, 0);
- if (nb == 0) {
- _W("Socket was disconnected. fd(%d)", fd_);
- return -ECOMM;
- } else if (nb < 0) {
- if (errno == EINTR) {
- continue;
- } else if (errno == EAGAIN) {
- if (is_blocking) {
- _E("Timed out. fd(%d)", fd_);
- return -EAGAIN;
- }
-
- if (retry_count > 0) {
- usleep(100 * 1000);
- retry_count--;
- continue;
- }
- }
-
- _E("recv() is failed. fd(%d), errno(%d)", fd_, errno);
- return -ECOMM;
- }
-
- left -= nb;
- buffer += nb;
- }
-
- return 0;
-}
-
-int Socket::Listen() {
- int ret = bind(fd_, reinterpret_cast<struct sockaddr*>(&addr_),
- sizeof(addr_));
- if (ret < 0) {
- _E("bind() is failed. fd(%d), errno(%d)", fd_, errno);
- return -1;
- }
-
- SetOption();
-
- ret = listen(fd_, 128);
- if (ret < 0) {
- _E("listen() is failed. fd(%d), errno(%d)", fd_, errno);
- return -1;
- }
-
- return 0;
-}
-
-int Socket::Connect() {
- int flags = fcntl(fd_, F_GETFL, 0);
- fcntl(fd_, F_SETFL, flags | O_NONBLOCK);
-
- int ret = connect(fd_, reinterpret_cast<struct sockaddr*>(&addr_),
- sizeof(addr_));
- fcntl(fd_, F_SETFL, flags);
- if (ret < 0) {
- if (errno != EAGAIN && errno != EINPROGRESS)
- return -2;
- } else if (ret == 0) {
- SetOption();
- return 0;
- }
-
- fd_set readfds;
- FD_ZERO(&readfds);
- FD_SET(fd_, &readfds);
- fd_set writefds = readfds;
- struct timeval timeout = { 0, 100 * 1000 };
- ret = select(fd_ + 1, &readfds, &writefds, NULL, &timeout);
- if (ret == 0) {
- errno = ETIMEDOUT;
- return -1;
- }
-
- if (FD_ISSET(fd_, &readfds) || FD_ISSET(fd_, &writefds)) {
- int error = 0;
- socklen_t len = sizeof(error);
- if (getsockopt(fd_, SOL_SOCKET, SO_ERROR, &error, &len) < 0)
- return -1;
- }
-
- return -1;
-}
-
-int Socket::GetFd() const {
- return fd_;
-}
-
-const std::string& Socket::GetPath() const {
- return path_;
-}
-
-int Socket::RemoveFd() {
- int fd = fd_;
- fd_ = -1;
- return fd;
-}
-
-void Socket::SetOption() {
- int size = MAX_AUL_BUFF_SIZE;
- int ret = setsockopt(fd_, SOL_SOCKET, SO_SNDBUF, &size, sizeof(size));
- if (ret < 0) {
- _E("setsockopt() is failed. fd(%d), errno(%d)", fd_, errno);
- return;
- }
-
- ret = setsockopt(fd_, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size));
- if (ret < 0) {
- _E("setsockopt() is failed. fd(%d), errno(%d)", fd_, errno);
- return;
- }
-}
-
-void Socket::SetTimeout(int timeout_msec) {
- if (timeout_msec == INT_MAX)
- return;
-
- if (timeout_msec == -1)
- timeout_msec = 5000;
-
- if (timeout_msec < 0) {
- _E("Invalid timeout_msec parameter");
- return;
- }
-
- struct timeval timeout = {
- .tv_sec = static_cast<time_t>(timeout_msec / 1000),
- .tv_usec = static_cast<suseconds_t>((timeout_msec % 1000) * 1000)
- };
- int ret = setsockopt(fd_, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
- if (ret < 0)
- _E("setsockopt() is failed. fd(%d), errno(%d)", fd_, errno);
-}
-
-void Socket::Create() {
- fd_ = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
- if (fd_ < 0) {
- _E("socket() is failed. errno(%d)", errno);
- return;
- }
-
- addr_.sun_family = AF_UNIX;
- snprintf(addr_.sun_path, sizeof(addr_.sun_path), "%s", path_.c_str());
-}
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2020 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_SOCKET_SOCKET_HH_
-#define AUL_SOCKET_SOCKET_HH_
-
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <sys/un.h>
-
-#include <string>
-
-namespace aul {
-
-static const char PATH_AMD_SOCK[] = "/run/aul/daemons/.amd-sock";
-static const int MAX_PAYLOAD_SIZE = 1024 * 1024 * 1;
-static const int MAX_AUL_BUFF_SIZE = 131071;
-
-class Socket {
- public:
- explicit Socket(std::string path);
- explicit Socket(int fd);
- virtual ~Socket();
-
- int Send(const void* buf, unsigned int len);
- int Recv(void* buf, unsigned int len);
- int Listen();
- int Connect();
-
- int GetFd() const;
- void SetTimeout(int timeout_msec);
- const std::string& GetPath() const;
- int RemoveFd();
-
- private:
- void SetOption();
- void Create();
-
- private:
- std::string path_;
- int fd_;
- struct sockaddr_un addr_ = { 0, };
-};
-
-} // namespace aul
-
-#endif // AUL_SOCKET_SOCKET_HH_
+++ /dev/null
-/*
- * aul
- *
- * 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 <errno.h>
-#include <bundle.h>
-#include <sys/types.h>
-#include <stdbool.h>
-
-#include "aul_key.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @brief Return values in AUL.
- */
-typedef enum _aul_return_val {
- AUL_R_ENOMEM = -16, /**< Out of memory (Since 5.5) */
- AUL_R_ENOENT = -15, /**< App directory entry error */
- AUL_R_EREJECTED = -14, /**< App disable for mode */
- AUL_R_ENOAPP = -13, /**< Failed to find app ID or pkg ID */
- AUL_R_EHIDDENFORGUEST = -11, /**< App hidden for guest mode */
- AUL_R_ENOLAUNCHPAD = -10, /**< no launchpad */
- AUL_R_ETERMINATING = -9, /**< application terminating */
- AUL_R_EILLACC = -8, /**< Illegal Access */
- AUL_R_LOCAL = -7, /**< Launch by himself */
- AUL_R_ETIMEOUT = -6, /**< Timeout */
- AUL_R_ECANCELED = -5, /**< Operation canceled */
- AUL_R_EINVAL = -4, /**< Invalid argument */
- AUL_R_ECOMM = -3, /**< Comunication Error */
- AUL_R_ENOINIT = -2, /**< AUL handler NOT initialized */
- AUL_R_ERROR = -1, /**< General error */
- AUL_R_OK = 0 /**< General success */
-} aul_return_val;
-
-enum app_status {
- STATUS_LAUNCHING,
- STATUS_CREATED,
- STATUS_FOCUS,
- STATUS_VISIBLE,
- STATUS_BG,
- STATUS_DYING,
- STATUS_HOME,
- STATUS_NORESTART,
- STATUS_SERVICE,
- STATUS_TERMINATE,
-};
-
-typedef enum _aul_type {
- AUL_START,
- AUL_RESUME,
- AUL_TERMINATE,
- AUL_TERMINATE_BGAPP,
- AUL_PAUSE,
- AUL_WAKE,
- AUL_SUSPEND,
- AUL_WIDGET_CONTENT,
- AUL_UPDATE_REQUESTED,
- AUL_TERMINATE_INST,
- AUL_TERMINATE_BG_INST,
-} aul_type;
-
-typedef enum aul_widget_lifecycle_event {
- AUL_WIDGET_LIFE_CYCLE_EVENT_APP_DEAD = 0,
- AUL_WIDGET_LIFE_CYCLE_EVENT_CREATE = 1, /**< The widget is created */
- AUL_WIDGET_LIFE_CYCLE_EVENT_DESTROY = 2, /**< The widget is destroyed */
- AUL_WIDGET_LIFE_CYCLE_EVENT_PAUSE = 3, /**< The widget is paused */
- AUL_WIDGET_LIFE_CYCLE_EVENT_RESUME = 4 /**< The widget is resumed */
-} aul_widget_lifecycle_event_e;
-
-typedef enum aul_widget_instance_event {
- AUL_WIDGET_INSTANCE_EVENT_CREATE = 0,
- AUL_WIDGET_INSTANCE_EVENT_DESTROY = 1,
- AUL_WIDGET_INSTANCE_EVENT_TERMINATE = 2,
- AUL_WIDGET_INSTANCE_EVENT_PAUSE = 3,
- AUL_WIDGET_INSTANCE_EVENT_RESUME = 4,
- AUL_WIDGET_INSTANCE_EVENT_UPDATE = 5,
- AUL_WIDGET_INSTANCE_EVENT_PERIOD_CHANGED = 6,
- AUL_WIDGET_INSTANCE_EVENT_SIZE_CHANGED = 7,
- AUL_WIDGET_INSTANCE_EVENT_EXTRA_UPDATED = 8,
- AUL_WIDGET_INSTANCE_EVENT_FAULT = 9,
- AUL_WIDGET_INSTANCE_EVENT_APP_RESTART_REQUEST = 10,
- AUL_WIDGET_INSTANCE_EVENT_CREATE_ABORTED = 11
-} aul_widget_instance_event_e;
-
-typedef enum _aul_process_status {
- AUL_PROC_STATUS_LAUNCH = 0,
- AUL_PROC_STATUS_FG = 3,
- AUL_PROC_STATUS_BG = 4,
- AUL_PROC_STATUS_FOCUS = 5,
- AUL_PROC_STATUS_HIDE = 7
-} aul_process_status_e;
-
-/**
- * @brief This is callback function for aul_launch_init
- * @param[in] type event's type received from system
- * @param[in] b In case of RESET events, bundle which is received from peer
- * @param[in] data user-supplied data
- */
-typedef int (*aul_handler_fn)(aul_type type, bundle *b, void *data);
-
-/**
- * @par Description:
- * This API install your AUL handler and setup AUL internal connection.
- * @par Purpose:
- * AUL receive START(RESET), RESUME, TERMINATE events from system.\n
- * This API use to handle the events. \n
- * @par Typical use case:
- * In general, you need not use this API.
- * If you use AppCore, you should NOT use this API.
- * AppCore will set default aul_handler.
- *
- * @param[in] handler aul main callback handler function
- * @param[in] data user-supplied data for start_handler
- * @return 0 if success, negative value(<0) if fail\n
- * @retval AUL_R_OK - success
- * @retval AUL_R_ECANCELD - aul handler was installed already by others
- * @retval AUL_R_ECOMM - error to create internal ipc
- * @retval AUL_R_ERROR - error to attach glib main loop
- *
- * @warning If you use AppCore, you should NOT use this API.\n
- * You need glib main loop.\n
- * @pre
- * you must have aul handler to use this API.
- * aul_luanch_init register aul handler.
- * @code
- * #include <aul.h>
- * #include <bundle.h>
- *
- * static int aul_handler(aul_type type, bundle *kb,void *data)
- * {
- * switch(type)
- * {
- * case AUL_START:
- * // process RESET event
- * break;
- * case AUL_RESUME:
- * // process RESUME event
- * break;
- * case AUL_TERMINATE:
- * // preocess TERMINATE event
- * break;
- * }
- * return 0;
- * }
- *
- * static GMainLoop *mainloop = NULL;
- *
- * int main(int argc, char **argv)
- * {
- * aul_launch_init(aul_handler,NULL);
- * aul_launch_argv_handler(argc, argv);
- *
- * mainloop = g_main_loop_new(NULL, FALSE);
- * g_main_loop_run(mainloop);
- * }
- *
- * @endcode
- * @remark
- * This API is only available in User Session.
-*/
-int aul_launch_init(aul_handler_fn handler, void *data);
-
-/**
- * @par Description:
- * This API create internal RESET events with given argc, argv \n
- * @par Purpose:
- * This API's purpose is to generate reset event.
- * If you want to generate local RESET events with argument vector format, use this API
- * @par Typical use case:
- * In general, you need not use this API.
- * AppCore use this API to create internal reset event.
- *
- * @param[in] argc # of args
- * @param[in] argv list of arg strings
- * @return 0 if success, negative value(<0) if fail
- * @retval AUL_R_OK - success
- * @retval AUL_R_ENOINIT - aul handler was NOT yet installed
- * @retval AUL_R_ECANCLED - error to create internal bundle with given argc,argv.
- * @retval AUL_R_ERROR - general error
- *
- * @pre
- * you must have aul handler to use this API.
- * aul_luanch_init register aul handler.
- * @see
- * aul_launch_init
- * @code
- * #include <aul.h>
- * #include <bundle.h>
- *
- * int send_local_reset_event()
- * {
- * int argc=3;
- * char* argv[4];
- * argv[0] = "local.app";
- * argv[1] = "event_type";
- * argv[2] = "my_reset";
- * argv[3] = NULL;
- * aul_launch_argv_handler(argc,argv);
- * }
- *
- * @endcode
- * @remark
- * If you use AppCore, you NEED NOT use this API.
- * This API is only available in User Session.
-*/
-int aul_launch_argv_handler(int argc, char **argv);
-
-/**
- * @par Description:
- * This API creates internal RESET events with given bundle \n
- * @par Purpose:
- * This API's purpose is to generate reset event.
- * If you want to generate local RESET events with argument vector format, first use
- * bundle_import_from_argv to create a bundle from the argument vector and then use this API
- * Eventually, this API will replace aul_launch_argv_handler().
- * @par Typical use case:
- * In general, you need not use this API.
- * AppCore use this API to create internal reset event.
- *
- * @param[in] b bundle
- * @return 0 if success, negative value(<0) if fail
- * @retval AUL_R_OK - success
- * @retval AUL_R_ENOINIT - aul handler was NOT yet installed
- * @retval AUL_R_ERROR - general error
- *
- * @pre
- * you must have aul handler to use this API.
- * aul_luanch_init register aul handler.
- * @post
- * None
- * @see
- * aul_launch_init, bundle_import_from_argv
- * @code
- * #include <aul.h>
- * #include <bundle.h>
- *
- * int send_local_reset_event()
- * {
- * bundle* b;
- * int argc=3;
- * char* argv[4];
- * argv[0] = "local.app";
- * argv[1] = "event_type";
- * argv[2] = "my_reset";
- * argv[3] = NULL;
- *
- * b = bundle_import_from_argv(argc,argv);
- * aul_launch_local(b);
- * }
- *
- * @endcode
- * @remark
- * If you use AppCore, you NEED NOT to use this API.
- * This API is only available in User Session.
-*/
-int aul_launch_local(bundle *b);
-
-/**
- * @par Description:
- * This API launches application with the given bundle.
- * If the application is not running or a multiple-instance one, this API launches with the given bundle.
- * If the application is running, this API sends a RESET event to the App.
- * While the application is running, if the application cannot receive the RESET event,
- * this API returns a general error(AUL_R_ERROR).\n
- * @par Purpose:
- * This API is for caller.
- * This API's purpose is to launch/reset application with given bundle.
- * @par Typical use case:
- * If you know the target application's pkgname and bundle types,
- * you can use this API to launch/reset the application.
- *
- * @param[in] pkgname package name to be run as callee
- * @param[in] kb bundle to be passed to callee
- * @return callee's pid if success, negative value(<0) if fail
- * @retval AUL_R_OK - success
- * @retval AUL_R_EINVAL - invaild package name
- * @retval AUL_R_ECOM - internal AUL IPC error
- * @retval AUL_R_ERROR - general error
- *
- * @see
- * aul_open_app
- * @code
- * #include <aul.h>
- * #include <bundle.h>
- *
- * int launch_inhouse_contact_app()
- * {
- * bundle *b;
- * b = bundle_create();
- * bundle_add(b,"type","SIM");
- * aul_launch_app("org.tizen.contact",b);
- * }
- *
- * @endcode
- * @remark
- * This API is only available in User Session.
- */
-int aul_launch_app(const char *appid, bundle *kb);
-
-/**
- * @par Description:
- * This API launches application with the given bundle.
- * If the application is not running or a multiple-instance one, this API launches with the given bundle.
- * If the application is running, this API sends a RESET event to the App.
- * While the application is running, if the application cannot receive the RESET event,
- * this API returns a general error(AUL_R_ERROR).\n
- * @par Purpose:
- * This API is for caller.
- * This API's purpose is to launch/reset application with given bundle.
- * @par Typical use case:
- * If you know the target application's pkgname and bundle types,
- * you can use this API to launch/reset the application.
- *
- * @param[in] pkgname package name to be run as callee
- * @param[in] kb bundle to be passed to callee
- * @param[in] uid User ID to launch
- * @return callee's pid if success, negative value(<0) if fail
- * @retval AUL_R_OK - success
- * @retval AUL_R_EINVAL - invaild package name
- * @retval AUL_R_ECOM - internal AUL IPC error
- * @retval AUL_R_ERROR - general error
- *
- * @see
- * aul_open_app
- * @remark
- * This API is also available in System Session.
- */
-int aul_launch_app_for_uid(const char *appid, bundle *kb, uid_t uid);
-
-/**
- * @par Description:
- * This API launches application, as menu screen launches the app.
- * Thus, if the application is running, this API sends a RESUME event to the app.
- * If the application is not running, this API launches the app.
- * While the application is running, if the application cannot receive the RESUME event,
- * AUL tries to raise the application's default window.
- *
- * @par Purpose:
- * This API is for caller.
- * This API's purpose is to resume/launch application
- * @par Typical use case:
- * If you only want to show application with previous state or default state, Use this API.
- *
- * @param[in] pkgname package name to be resume as callee
- * @return callee's pid if success, negative value(<0) if fail
- * @retval AUL_R_OK - success
- * @retval AUL_R_EINVAL - invaild package name
- * @retval AUL_R_ECOM - internal AUL IPC error
- * @retval AUL_R_ERROR - general error
- *
- * @see
- * aul_launch_app, aul_app_is_running, aul_resume_pid
- * @code
- * #include <aul.h>
- * #include <bundle.h>
- *
- * int open_inhouse_contact_app()
- * {
- * if(aul_app_is_running("org.tizen.contact"))
- * aul_open_app("org.tizen.contact");
- * }
- *
- * @endcode
- * @remark
- * If you don't want to launch the app,
- * you should check app's running state with aul_app_is_running.
- * This API will launch the application if the application is not running.
- * This API is only available in User Session.
-*/
-int aul_open_app(const char *appid);
-
-/**
- * @par Description:
- * This API launches application, as menu screen launches the app.
- * Thus, if the application is running, this API sends a RESUME event to the app.
- * If the application is not running, this API launches the app.
- * While the application is running, if the application cannot receive the RESUME event,
- * AUL tries to raise the application's default window.
- *
- * @par Purpose:
- * This API is for caller.
- * This API's purpose is to resume/launch application
- * @par Typical use case:
- * If you only want to show application with previous state or default state, Use this API.
- *
- * @param[in] pkgname package name to be resume as callee
- * @param[in] uid User ID
- * @return callee's pid if success, negative value(<0) if fail
- * @retval AUL_R_OK - success
- * @retval AUL_R_EINVAL - invaild package name
- * @retval AUL_R_ECOM - internal AUL IPC error
- * @retval AUL_R_ERROR - general error
- *
- * @remark
- * If you don't want to launch the app,
- * you should check app's running state with aul_app_is_running.
- * This API will launch the application if the application is not running.
- * This API is only available to System user.
- */
-int aul_open_app_for_uid(const char *appid, uid_t uid);
-
-/**
- * @par Description:
- * This API trigger to resume application
- * If the application is running, this API send a resume event to the App.
- * If the application is not running, this API launches the app.
- * Although the application is running, if the application cannot receive resume event,
- * AUL try to raise the application's default windows.
- * @par Purpose:
- * This API is for caller.
- * This API's purpose is to send resume event.
- * @par Typical use case:
- * If you only want to show application with previous state or default state, Use this API.
- *
- * @param[in] pkgname package name to be resume as callee
- * @return callee's pid if success, negative value(<0) if fail
- * @retval AUL_R_OK - success
- * @retval AUL_R_EINVAL - invaild package name
- * @retval AUL_R_ECOM - internal AUL IPC error
- * @retval AUL_R_ERROR - general error
- *
- * @see
- * aul_launch_app(), aul_app_is_running(), aul_resume_pid()
- *
- * @deprecated
- * This function will be deprecated. Use aul_open_app() instead of this function.
- *
- * @code
- * #include <aul.h>
- * #include <bundle.h>
- *
- * int resume_inhouse_contact_app()
- * {
- * if(aul_app_is_running("org.tizen.contact"))
- * aul_resume_app("org.tizen.contact");
- * }
- *
- * @endcode
- * @remark
- * If you don't want to launch the app,
- * you should check app's running state with aul_app_is_running.
- * This API will launch the application if the application is not running.
- * If you want to only resume without launching in multiple instance application model,
- * you should use aul_resume_pid.
- * This API is only available in User Session.
-*/
-int aul_resume_app(const char *appid);
-
-/**
- * @par Description:
- * This API trigger to resume application
- * If the application is running, this API send a resume event to the App.
- * If the application is not running, this API launches the app.
- * Although the application is running, if the application cannot receive resume event,
- * AUL try to raise the application's default windows.
- * @par Purpose:
- * This API is for caller.
- * This API's purpose is to send resume event.
- * @par Typical use case:
- * If you only want to show application with previous state or default state, Use this API.
- *
- * @param[in] pkgname package name to be resume as callee
- * @param[in] uid User ID
- * @return callee's pid if success, negative value(<0) if fail
- * @retval AUL_R_OK - success
- * @retval AUL_R_EINVAL - invaild package name
- * @retval AUL_R_ECOM - internal AUL IPC error
- * @retval AUL_R_ERROR - general error
- *
- * @remark
- * If you don't want to launch the app,
- * you should check app's running state with aul_app_is_running.
- * This API will launch the application if the application is not running.
- * If you want to only resume without launching in multiple instance application model,
- * you should use aul_resume_pid.
- * This API is only available to System user.
- */
-int aul_resume_app_for_uid(const char *appid, uid_t uid);
-
-/**
- * @par Description:
- * This API trigger to resume application
- * If the application is running, this API send a resume event to the App.
- * If the application is not running, this API return AUL_R_ERROR.
- * Although the application is running, if the application cannot receive resume event,
- * AUL try to raise the application's default windows.
- * @par Purpose:
- * This API is for caller.
- * This API's purpose is to send resume event.
- * @par Typical use case:
- * In multiple application model, If you want to only resume specific application, Use this API
- *
- * @param[in] pid application's pid to be resumed
- * @return 0 if success, negative value(<0) if fail
- * @retval AUL_R_OK - success
- * @retval AUL_R_EINVAL - invaild pid
- * @retval AUL_R_ECOM - internal AUL IPC error
- * @retval AUL_R_ERROR - general error (include application is not running)
- * @warning This API need to require root or inhouse permisssion \n
- * If you have not the permission, this API return AUL_R_ERROR. \n
- * @see
- * aul_launch_app
- * @code
- * #include <aul.h>
- * #include <bundle.h>
- *
- * int iterfunc(const aul_app_info *info, void *data)
- * {
- * if(strcmp(info->pkg_name,"org.tizen.contact")==0)
- * aul_resume_pid(info->pid);
- * }
- *
- * int iterate_running_apps()
- * {
- * return aul_app_get_running_app_info(iterfunc,NULL);
- * }
- *
- * @endcode
- * @remark
- * This API is only available in User Session.
-*/
-int aul_resume_pid(int pid);
-
-/**
- * @par Description:
- * This API trigger to resume application
- * If the application is running, this API send a resume event to the App.
- * If the application is not running, this API return AUL_R_ERROR.
- * Although the application is running, if the application cannot receive resume event,
- * AUL try to raise the application's default windows.
- * @par Purpose:
- * This API is for caller.
- * This API's purpose is to send resume event.
- * @par Typical use case:
- * In multiple application model, If you want to only resume specific application, Use this API
- *
- * @param[in] pid application's pid to be resumed
- * @param[in] uid User ID
- * @return 0 if success, negative value(<0) if fail
- * @retval AUL_R_OK - success
- * @retval AUL_R_EINVAL - invaild pid
- * @retval AUL_R_ECOM - internal AUL IPC error
- * @retval AUL_R_ERROR - general error (include application is not running)
- * @warning This API need to require root or inhouse permisssion \n
- * If you have not the permission, this API return AUL_R_ERROR. \n
- * @remark
- * This API is only available to System user.
-*/
-int aul_resume_pid_for_uid(int pid, uid_t uid);
-
-/**
- * @par Description:
- * This API trigger to terminate application
- *
- * If the application is running, this API send a terminate event to the App. \n
- * If the app cannot receive the event, AUL kill forcely the application.\n
- * @par Purpose:
- * This API's purpose is to kill application
- * @par Typical use case:
- * In general, Application like Task Manager use this API.
- *
- * This API need to require root or inhouse permisssion. \n
- *
- * @param[in] pid application's pid to be terminated
- * @return 0 if success, negative value(<0) if fail
- * @retval AUL_R_OK - success
- * @retval AUL_R_EINVAL - invaild pid
- * @retval AUL_R_ECOM - internal AUL IPC error
- * @retval AUL_R_ERROR - general error
- * @warning This API need to require root or inhouse permisssion. \n
- *
- * @code
- * #include <aul.h>
- * #include <bundle.h>
- *
- * int iterfunc(const aul_app_info *info, void *data)
- * {
- * if(strcmp(info->pkg_name,"org.tizen.contact")==0)
- * aul_terminate_pid(info->pid);
- * }
- *
- * int iterate_running_apps()
- * {
- * return aul_app_get_running_app_info(iterfunc,NULL);
- * }
- *
- * @endcode
- * @remark
- * If you have not the permission, this API return AUL_R_ERROR. \n
- * This API is only available in User Session.
-*/
-int aul_terminate_pid(int pid);
-
-/**
- * @par Description:
- * This API trigger to terminate application
- *
- * If the application is running, this API send a terminate event to the App. \n
- * If the app cannot receive the event, AUL kill forcely the application.\n
- * @par Purpose:
- * This API's purpose is to kill application
- * @par Typical use case:
- * In general, Application like Task Manager use this API.
- *
- * This API need to require root or inhouse permisssion. \n
- *
- * @param[in] pid application's pid to be terminated
- * @param[in] uid User ID
- * @return 0 if success, negative value(<0) if fail
- * @retval AUL_R_OK - success
- * @retval AUL_R_EINVAL - invaild pid
- * @retval AUL_R_ECOM - internal AUL IPC error
- * @retval AUL_R_ERROR - general error
- * @warning This API need to require root or inhouse permisssion. \n
- *
- * @remark
- * If you have not the permission, this API return AUL_R_ERROR. \n
- * This API is only available to System user.
- */
-int aul_terminate_pid_for_uid(int pid, uid_t uid);
-
-/**
- * @par Description:
- * This API trigger to terminate application asynchronously
- *
- * If the application is running, this API send a terminate event to the App. \n
- * If the app cannot receive the event, AUL kill forcely the application.\n
- * @par Purpose:
- * This API's purpose is to kill application
- * @par Typical use case:
- * In general, Application like Task Manager use this API.
- *
- * This API need to require root or inhouse permisssion. \n
- *
- * @param[in] pid application's pid to be terminated
- * @return 0 if success, negative value(<0) if fail
- * @retval AUL_R_OK - success
- * @retval AUL_R_EINVAL - invaild pid
- * @retval AUL_R_ECOM - internal AUL IPC error
- * @retval AUL_R_ERROR - general error
- * @warning This API need to require root or inhouse permisssion. \n
- * @remark
- * If you have not the permission, this API return AUL_R_ERROR. \n
- * This API is only available in User Session.
-*/
-int aul_terminate_pid_async(int pid);
-
-/**
- * @par Description:
- * This API trigger to terminate application asynchronously
- *
- * If the application is running, this API send a terminate event to the App. \n
- * If the app cannot receive the event, AUL kill forcely the application.\n
- * @par Purpose:
- * This API's purpose is to kill application
- * @par Typical use case:
- * In general, Application like Task Manager use this API.
- *
- * This API need to require root or inhouse permisssion. \n
- *
- * @param[in] pid application's pid to be terminated
- * @param[in] uid User ID
- * @return 0 if success, negative value(<0) if fail
- * @retval AUL_R_OK - success
- * @retval AUL_R_EINVAL - invaild pid
- * @retval AUL_R_ECOM - internal AUL IPC error
- * @retval AUL_R_ERROR - general error
- * @warning This API need to require root or inhouse permisssion. \n
- * @remark
- * If you have not the permission, this API return AUL_R_ERROR. \n
- * This API is only available to System user.
- */
-int aul_terminate_pid_async_for_uid(int pid, uid_t uid);
-
-/**
- * @par Description:
- * This API trigger to terminate application synchronously
- *
- * If the application is running, this API sends a terminate event to the application. \n
- * And then, this API waits until the application is terminated successfully. \n
- * If the app cannot receive the event, AUL kill forcely the application. \n
- * @par Purpose:
- * This API's purpose is to kill application
- * @par Typical use case:
- * In general, Application like Task Manager use this API.
- *
- * This API need to require root or platform level permisssion. \n
- *
- * @param[in] pid application's pid to be terminated
- * @return 0 if success, negative value(<0) if fail
- * @retval AUL_R_OK - success
- * @retval AUL_R_EINVAL - invaild pid
- * @retval AUL_R_ECOM - internal AUL IPC error
- * @retval AUL_R_ERROR - general error
- * @warning This API need to require root or platform level permisssion. \n
- * @remark
- * If you have not the permission, this API return AUL_R_ERROR. \n
- * This API is only available in User Session.
-*/
-int aul_terminate_pid_sync(int pid);
-
-/**
- * @par Description:
- * This API trigger to terminate application synchronously
- *
- * If the application is running, this API send a terminate event to the application. \n
- * And then, this API waits until the application is terminated successfully. \n
- * If the app cannot receive the event, AUL kill forcely the application. \n
- * @par Purpose:
- * This API's purpose is to kill application
- * @par Typical use case:
- * In general, Application like Task Manager use this API.
- *
- * This API need to require root or platform level permisssion. \n
- *
- * @param[in] pid application's pid to be terminated
- * @param[in] uid User ID
- * @return 0 if success, negative value(<0) if fail
- * @retval AUL_R_OK - success
- * @retval AUL_R_EINVAL - invaild pid
- * @retval AUL_R_ECOM - internal AUL IPC error
- * @retval AUL_R_ERROR - general error
- * @warning This API need to require root or platform level permisssion. \n
- * @remark
- * If you have not the permission, this API return AUL_R_ERROR. \n
- * This API is only available to System user.
- */
-int aul_terminate_pid_sync_for_uid(int pid, uid_t uid);
-
-/**
- *@brief Running application's information structure retrieved by AUL
- */
-typedef struct _aul_app_info {
- int pid; /**< app's pid if running*/
- char *pkg_name; /**< application id */
- char *app_path; /**< application excutable path */
- char *appid;
- char *pkgid; /**< package id */
- int status; /**< app's status */
- int is_sub_app; /**< state whether sub app of app group */
- char *instance_id;
-} aul_app_info;
-
-/**
- * @brief iterator function running with aul_app_get_running_app_info
- * @param[out] ainfo aul_app_info retreived by aul_app_get_running_app_info
- * @param[out] data user-supplied data
-*/
-typedef int (*aul_app_info_iter_fn)(const aul_app_info *ainfo, void *data);
-
-/**
- * @par Description:
- * This API ask a application is running by application package name.
- * @par Purpose:
- * To know whether some application is running or not, use this API
- * @par Typical use case:
- * For example, If you want to know browser application running,
- * you can check it by using this API.
- *
- * @param[in] pkgname application package name
- * @return true / false
- * @retval 1 app_name is running now.
- * @retval 0 app_name is NOT running now.
- *
- * @code
- * #include <aul.h>
- *
- * int is_running_browser_app()
- * {
- * return aul_app_is_running("org.tizen.browser");
- * }
- *
- * @endcode
- * @remark
- * This API is only available in User Session.
- *
- */
-int aul_app_is_running(const char *appid);
-
-/**
- * @par Description:
- * This API ask a application is running by application package name.
- * @par Purpose:
- * To know whether some application is running or not, use this API
- * @par Typical use case:
- * For example, If you want to know browser application running,
- * you can check it by using this API.
- *
- * @param[in] pkgname application package name
- * @param[in] uid User ID
- * @return true / false
- * @retval 1 app_name is running now.
- * @retval 0 app_name is NOT running now.
- *
- * @endcode
- * @remark
- * This API is only available to System User.
- */
-int aul_app_is_running_for_uid(const char *appid, uid_t uid);
-
-/**
- * @par Description:
- * This API use to get running application list.
- * This API call iter_fn with each aul_app_info of running apps when running application is found.
- * @par Purpose:
- * If you want to get running application list, use this API
- * @par Typical use case:
- * In general, this API is used by task manager appllication. (running application list viewer)
- *
- * @param[in] iter_fn iterator function
- * @param[in] user_data user-supplied data for iter_fn
- * @return 0 if success, negative value(<0) if fail
- * @retval AUL_R_OK - success
- * @retval AUL_R_ERROR - internal error
- *
- * @code
- * #include <aul.h>
- *
- * int iterfunc(const aul_app_info* info, void* data)
- * {
- * printf("\t==========================\n");
- * printf("\t pkg_name: %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 iterate_running_apps()
- * {
- * return aul_app_get_running_app_info(iterfunc,NULL);
- * }
- *
- * @endcode
- * @remark
- * This API should use if you want to know running application which has desktop files.
- * If you want to get all process list, you must iterate process information by using proc filesystem
- * Or, If you want to get all window list, you must iterate XWindows by using XWindow APIs
- * This API is only available in User Session.
- */
-int aul_app_get_running_app_info(aul_app_info_iter_fn iter_fn, void *user_data);
-
-/**
- * @par Description:
- * This API use to get running application list.
- * This API call iter_fn with each aul_app_info of running apps when running application is found.
- * @par Purpose:
- * If you want to get running application list, use this API
- * @par Typical use case:
- * In general, this API is used by task manager appllication. (running application list viewer)
- *
- * @param[in] iter_fn iterator function
- * @param[in] user_data user-supplied data for iter_fn
- * @param[in] uid User ID
- * @return 0 if success, negative value(<0) if fail
- * @retval AUL_R_OK - success
- * @retval AUL_R_ERROR - internal error
- *
- * @remark
- * This API should use if you want to know running application which has desktop files.
- * If you want to get all process list, you must iterate process information by using proc filesystem
- * Or, If you want to get all window list, you must iterate XWindows by using XWindow APIs
- * This API is only available to System user.
- */
-int aul_app_get_running_app_info_for_uid(aul_app_info_iter_fn iter_fn, void *user_data, uid_t uid);
-
-/**
- * @par Description:
- * This API use to get all running application list, including sub app.
- * This API call iter_fn with each aul_app_info of running apps when running application is found.
- * @par Purpose:
- * If you want to get all running application list, use this API
- * @par Typical use case:
- * In general, this API is used by task manager application. (running application list viewer)
- *
- * @param[in] iter_fn iterator function
- * @param[in] user_data user-supplied data for iter_fn
- * @return 0 if success, negative value(<0) if fail
- * @retval AUL_R_OK - success
- * @retval AUL_R_ERROR - internal error
- *
- * @code
- * #include <aul.h>
- *
- * 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 iterate_running_apps()
- * {
- * return aul_app_get_all_running_app_info(iterfunc_status,NULL);
- * }
- *
- * @endcode
- * @remark
- * This API should use if you want to know running application which has desktop files.
- * If you want to get all process list, you must iterate process information by using proc filesystem
- * Or, If you want to get all window list, you must iterate XWindows by using XWindow APIs
- * This API is only available in User Session.
- */
-int aul_app_get_all_running_app_info(aul_app_info_iter_fn iter_fn, void *user_data);
-
-/**
- * @par Description:
- * This API use to get all running application list, including sub app.
- * This API call iter_fn with each aul_app_info of running apps when running application is found.
- * @par Purpose:
- * If you want to get all running application list, use this API
- * @par Typical use case:
- * In general, this API is used by task manager application. (running application list viewer)
- *
- * @param[in] iter_fn iterator function
- * @param[in] user_data user-supplied data for iter_fn
- * @param[in] uid User ID
- * @return 0 if success, negative value(<0) if fail
- * @retval AUL_R_OK - success
- * @retval AUL_R_ERROR - internal error
- *
- * @remark
- * This API should use if you want to know running application which has desktop files.
- * If you want to get all process list, you must iterate process information by using proc filesystem
- * Or, If you want to get all window list, you must iterate XWindows by using XWindow APIs
- * This API is only available to System user.
- */
-int aul_app_get_all_running_app_info_for_uid(aul_app_info_iter_fn iter_fn, void *user_data, uid_t uid);
-
-/**
- * @par Description:
- * This API get application package name by pid
- * @par Purpose:
- * If you want to get package name of running application, use this API
- * @par Typical use case:
- * In general, You can use this API when you want to know caller's information.
- *
- * @param[in] pid given pid
- * @param[out] pkgname pkgname to be get
- * @param[in] len length of pkgname
- * @return 0 if success, negative value(<0) if fail
- * @retval AUL_R_OK - success
- * @retval AUL_R_ERROR - no such a package name
- * @code
- * #include <aul.h>
- * #include <bundle.h>
- *
- * static int app_reset(bundle *b, void *data)
- * {
- * int pid;
- * char appname[255];
- *
- * pid = atoi(bundle_get_val(b,AUL_K_CALLER_PID));
- * aul_app_get_pkgname_bypid(pid, appname, sizeof(appname));
- * }
- *
- * @endcode
- * @remark
- * This API is only available in User Session.
-*/
-int aul_app_get_pkgname_bypid(int pid, char *pkgname, int len);
-
-/**
- * @par Description:
- * This API get application pkgid by pid
- * @par Purpose:
- * If you want to get pkgid of running application, use this API
- * @par Typical use case:
- * In general, You can use this API when you want to know caller's information.
- *
- * @param[in] pid given pid
- * @param[out] pkgid package id
- * @param[in] len length of pkgid
- * @return 0 if success, negative value(<0) if fail
- * @retval AUL_R_OK - success
- * @retval AUL_R_ERROR - no such a appid
- *
- * @code
- * #include <aul.h>
- * #include <bundle.h>
- *
- * static int app_reset(bundle *b, void *data)
- * {
- * int pid;
- * char pkgid[255];
- *
- * pid = atoi(bundle_get_val(b, AUL_K_CALLER_PID));
- * aul_app_get_pkgid_bypid(pid, pkgid, sizeof(pkgid));
- * }
- *
- * @endcode
- * @remark
- * This API is only available in User Session.
-*/
-int aul_app_get_pkgid_bypid(int pid, char *pkgid, int len);
-
-/**
- * @par Description:
- * This API get application pkgid by pid
- * @par Purpose:
- * If you want to get pkgid of running application, use this API
- * @par Typical use case:
- * In general, You can use this API when you want to know caller's information.
- *
- * @param[in] pid given pid
- * @param[out] pkgid package id
- * @param[in] len length of pkgid
- * @param[in] uid User ID
- * @return 0 if success, negative value(<0) if fail
- * @retval AUL_R_OK - success
- * @retval AUL_R_ERROR - no such a appid
- *
- * @remark
- * This API is also available to System user.
-*/
-int aul_app_get_pkgid_bypid_for_uid(int pid, char *pkgid, int len, uid_t uid);
-
-/**
- * @par Description:
- * This API get application appid by pid
- * @par Purpose:
- * If you want to get appid of running application, use this API
- * @par Typical use case:
- * In general, You can use this API when you want to know caller's information.
- *
- * @param[in] pid given pid
- * @param[out] appid application id
- * @param[in] len length of pkgname
- * @return 0 if success, negative value(<0) if fail
- * @retval AUL_R_OK - success
- * @retval AUL_R_ERROR - no such a appid
- * @code
- * #include <aul.h>
- * #include <bundle.h>
- *
- * static int app_reset(bundle *b, void *data)
- * {
- * int pid;
- * char appid[255];
- *
- * pid = atoi(bundle_get_val(b,AUL_K_CALLER_PID));
- * aul_app_get_appid_bypid(pid, appid, sizeof(appid));
- * }
- *
- * @endcode
- * @remark
- * This API is only available in User Session.
-*/
-int aul_app_get_appid_bypid(int pid, char *appid, int len);
-
-/**
- * @par Description:
- * This API get application appid by pid
- * @par Purpose:
- * If you want to get appid of running application, use this API
- * @par Typical use case:
- * In general, You can use this API when you want to know caller's information.
- *
- * @param[in] pid given pid
- * @param[out] appid application id
- * @param[in] len length of pkgname
- * @param[in] uid User ID
- * @return 0 if success, negative value(<0) if fail
- * @retval AUL_R_OK - success
- * @retval AUL_R_ERROR - no such a appid
- * @remark
- * This API is also available to System user.
-*/
-int aul_app_get_appid_bypid_for_uid(int pid, char *appid, int len, uid_t uid);
-
-/**
- * @par Description:
- * This API launch application associated with given filename
- * @par Purpose:
- * This API is for caller.
- * This API launch application based on mime type.
- * This API find mime_type associated with file name,
- * and then find default app associated with found mime_type
- * and then launch the app with filename argument.
- * @par Typical use case:
- * You can launch application to process given filename.
- * That is, Even if you don't know the specific application's pkgname,
- * you can launch the applicaiton processing given filename .
- * For example, If you want to process image file, you can simply launch image viewer.
- * At that time, you can use this APIs like aul_open_file("myimage.jpg");
- *
- * @param[in] filename filename
- * @return callee's pid or 0 if success, negative value if fail\n
- * (when no found default app, return 0)
- * @retval AUL_R_OK - success
- * @retval AUL_R_EINVAL - invalid argument(filename)
- * @retval AUL_R_ECOM - internal AUL IPC error
- * @retval AUL_R_ERROR - general error
- *
- * @code
- * #include <aul.h>
- *
- * int view_image_file(char *filename)
- * {
- * aul_open_file(filename);
- * }
- *
- * @endcode
- * @remark
- * This API is only available in User Session.
- *
- */
-int aul_open_file(const char* filename);
-
-/**
- * @par Description:
- * This API launch application associated with given specific mimetype
- * @par Purpose:
- * This API is for caller.
- * This API launch application based on mime type like aul_open_file API.
- * But, This API don't find mime_type associated with file name.
- * This API use mimetype given by user. By using given mimetype, find default application.
- * and then launch the app with filename argument.
- * @par Typical use case:
- * Some files cannot extract exact mimetype automatically.
- * For example, To know mime type of files with DRM lock, first we should unlock DRM file.
- * In this case, You can use this API.
- * First, unlock DRM file, and extract mimetype from unlock file by using aul_get_mime_from_file,
- * and then, use this API with DRM file and extracted mime type.
- *
- * @param[in] filename filename
- * @param[in] mimetype specific mimetype
- * @return callee's pid or 0 if success, negative value if fail\n
- * (when no found default app, return 0)
- * @retval AUL_R_OK - success
- * @retval AUL_R_EINVAL - invalid argument(filename,mimetype)
- * @retval AUL_R_ECOM - internal AUL IPC error
- * @retval AUL_R_ERROR - general error
- *
- * @see
- * aul_open_file, aul_get_mime_from_file
- * @code
- * #include <aul.h>
- *
- * int view_drm_image_file(char *drm_filename)
- * {
- * char* mimetype;
- * // you must implement this function
- * mimetype = get_mimetype_from_drmfile(drm_filename);
- *
- * aul_open_file_with_mimetype(drm_filename,mimetype);
- * }
- *
- * @endcode
- * @remark
- * This API is only available in User Session.
- */
-int aul_open_file_with_mimetype(const char *filename, const char *mimetype);
-
-/**
- * @par Description:
- * This API launch application associated with content like "http://www.samsung.com"
- * @par Purpose:
- * This API is for caller.
- * This API launch application based on mime type.
- * This API find mime_type associated with content,
- * and then find default app associated with found mime_type,
- * and then launch the app with content argument.
- * @par Typical use case:
- * You can launch application to process given content.
- * That is, Even if you don't know the specific application's pkgname,
- * you can launch the applicaiton processing given content.
- * For example, If you want to process URL "http://www.samsung.com",
- * you can simply launch browser.
- * At that time, you can use this APIs like aul_open_content("http://www.samsung.com");
- *
- * @param[in] content content
- * @return callee's pid or 0 if success, negative value if fail\n
- * (when no found default app, return 0)
- * @retval AUL_R_OK - success
- * @retval AUL_R_EINVAL - invalid argument(content)
- * @retval AUL_R_ECOM - internal AUL IPC error
- * @retval AUL_R_ERROR - general error or no found mimetype
- *
- * @code
- * #include <aul.h>
- *
- * int view_url(char *url)
- * {
- * aul_open_content(url);
- * }
- *
- * @endcode
- * @remark
- * This API is only available in User Session.
- *
- */
-int aul_open_content(const char* content);
-
-/**
- * @par Description:
- * This API get the default application(appid) associated with MIME type
- * @par Purpose:
- * This API use to get default application associteted with mimetype
- * In general, Setting Application need this API.
- * @par Typical use case:
- * Setting Application show mapping of default application / mimetype
- *
- * @param[in] mimetype a mime type
- * @param[out] defapp a application appid of the app
- * @param[in] len length of defapp
- * @return 0 if success, negative value if fail
- * @retval AUL_R_OK - success
- * @retval AUL_R_EINVAL - invalid argument(mimetype)
- * @retval AUL_R_ERROR - general error or no found mimetype
- *
- * @see
- * aul_set_defapp_with_mime
- * @code
- * #include <aul.h>
- *
- * void get_text_html_defapp()
- * {
- * char appname[255];
- * aul_get_defapp_from_mime("text/html",appname,sizeof(appname));
- * }
- *
- * @endcode
- * @remark
- * This API is only available in User Session.
- *
- */
-int aul_get_defapp_from_mime(const char *mimetype, char *defapp, int len);
-
-/**
- * @par Description:
- * This API set the default application(appid) associated with MIME type
- * @par Purpose:
- * This API use to change default application associteted with mimetype
- * In general, Setting Application or Installer need this API.
- * @par Typical use case:
- * Default Application associated with mimetype can be changed by Setting Application or installer
- * So, application to process specific mimetype can be substituted.
- *
- * @param[in] mimetype a mime type
- * @param[in] defapp a application appid of the app to be set
- * @return 0 if success, negative value if fail
- * @retval AUL_R_OK - success
- * @retval AUL_R_EINVAL - invalid argument(mimetype)
- * @retval AUL_R_ERROR - general error
- *
- * @see
- * aul_get_defapp_from_mime
- * @code
- * #include <aul.h>
- *
- * void set_text_html_defapp()
- * {
- * aul_set_defapp_with_mime("text/html","org.tizen.browser");
- * }
- *
- * @endcode
- * @remark
- * This API is only available in User Session.
-*/
-int aul_set_defapp_with_mime(const char *mimetype, const char *defapp);
-
-/**
- * @par Description:
- * This API get the mimetype associated with filename
- * @par Purpose:
- * This API use to get mimetype associteted with given filename
- * In general, This API use when you want to know only mimetype given filename.
- * @par Typical use case:
- * For example, In trasfering data through bluetooth,
- * additional information like mimetype should be added.
- * In such situation, You can get mimetype by using this API.
- *
- * @param[in] filename file name
- * @param[out] mimetype a mime type
- * @param[in] len length of mimetype
- * @return 0 if success, negative value if fail
- * @retval AUL_R_OK - success
- * @retval AUL_R_EINVAL - invalid argument(filename)
- * @retval AUL_R_ERROR - general error
- *
- * @code
- * #include <aul.h>
- *
- * void get_mimetype()
- * {
- * char mimetype[255];
- * aul_get_mime_from_file("image.jpg",mimetype,sizeof(mimetype));
- * }
- *
- * @endcode
- * @remark
- * This API is only available in User Session.
- */
-int aul_get_mime_from_file(const char *filename, char *mimetype, int len);
-
-/**
- * @par Description:
- * This API get the mimetype associated with given content
- * @par Purpose:
- * This API use to get mimetype associteted with given content
- * In general, This API use when you want to know only mimetype given content
- * @par Typical use case:
- * For example, In trasfering data through bluetooth,
- * additional information like mimetype should be added.
- * In such situation, You can get mimetype by using this API.
- *
- * @param[in] content content string like "011-0000-0000"
- * @param[out] mimetype a mime type
- * @param[in] len length of mimetype
- * @return 0 if success, negative value if fail
- * @retval AUL_R_OK - success
- * @retval AUL_R_EINVAL - invalid argument(content)
- * @retval AUL_R_ERROR - general error
- *
- * @code
- * #include <aul.h>
- *
- * void get_mimetype()
- * {
- * char mimetype[255];
- * aul_get_mime_from_content("http://www.samsung.com",mimetype,sizeof(mimetype));
- * }
- *
- * @endcode
- * @remark
- * This API is only available in User Session.
-*/
-int aul_get_mime_from_content(const char *content, char *mimetype, int len);
-
-/**
- * @par Description:
- * This API get the icon's name associated with given mimetype
- * @par Purpose:
- * This API use to get icon's name associteted with given mimetype
- * @par Typical use case:
- * If you want to show mimetype's icon, use this API.
- *
- * @param[in] mimetype a mime type
- * @param[out] iconname icon's name
- * @param[in] len length of iconname
- * @return 0 if success, negative value if fail
- * @retval AUL_R_OK - success
- * @retval AUL_R_EINVAL - invalid argument(content)
- * @retval AUL_R_ERROR - general error (no such mime type)
- *
- * @code
- * #include <aul.h>
- *
- * void get_mime_icon()
- * {
- * char icon[255];
- * aul_get_mime_icon("text/html",icon,sizeof(icon));
- * }
- *
- * @endcode
- * @remark
- * This API is only available in User Session.
- */
-int aul_get_mime_icon(const char *mimetype, char *iconname, int len);
-
-/**
- * @par Description:
- * This API get the extensions associated with given mimetype
- * @par Purpose:
- * This API use to get extensions associteted with given mimetype
- * @par Typical use case:
- * In general, user is not familiar with mimetype(text/html),
- * user is familiar with extenstions(*.html, *.htm)
- * So, To show mimetype information to user, use this API
- *
- * @param[in] mimetype a mime type
- * @param[out] extlist extentions (ex> mpeg,mpg,mpe)
- * @param[in] len length of extlist
- * @return 0 if success, negative value if fail
- * @retval AUL_R_OK - success
- * @retval AUL_R_EINVAL - invalid argument(mimetype)
- * @retval AUL_R_ERROR - general error (no mimetype or no extenstion)
- *
- * @see
- * aul_get_mime_description
- * @code
- * #include <aul.h>
- *
- * void get_extension()
- * {
- * char extlist[255];
- * aul_get_mime_extension("text/html",extlist,sizeof(extlist));
- * }
- *
- * @endcode
- * @remark
- * Some mimetype don't have extension.
- * In that case, You can use aul_get_mime_description.
- * This API is only available in User Session.
-*/
-int aul_get_mime_extension(const char *mimetype, char *extlist, int len);
-
-/**
- * @par Description:
- * This API get the description associated with given mimetype
- * @par Purpose:
- * This API use to get description associteted with given mimetype
- * @par Typical use case:
- * In general, user is not familiar with mimetype(text/html),
- * user is familiar with well-knowing information like extenstions(*.html, *.htm)
- * But, some mimetype don't have extenstion.
- * At that time,to show mimetype information to user, use this API
- *
- * @param[in] mimetype a mime type
- * @param[out] desc description (ex> Call client)
- * @param[in] len length of desc
- * @return 0 if success, negative value if fail
- * @retval AUL_R_OK - success
- * @retval AUL_R_EINVAL - invalid argument(mimetype)
- * @retval AUL_R_ERROR - general error (no mimetype or no descrition)
- *
- * @see
- * aul_get_mime_extension
- * @code
- * #include <aul.h>
- *
- * void get_information_from_mime()
- * {
- * char info[255];
- * if(aul_get_mime_extension("text/html",info,sizeof(info))<0){
- * aul_get_mime_description("text/html",info,sizeof(info));
- * }
- * }
- *
- * @endcode
- * @remark
- * This API is only available in User Session.
- */
-int aul_get_mime_description(const char *mimetype, char *desc, int len);
-
-/**
- * @par Description:
- * This API create service result bundle based on bundle received in reset event.
- * @par Purpose:
- * This API use to create result bundle to send it to caller.
- * @par Typical use case:
- * This API is for callee which provide application service.\n
- * To send result to caller, You must create result bundle. \n
- * Callee(application providing the service) can send result by using this API and aul_send_service_result.
- *
- * @param[in] inb bundle received in reset event
- * @param[out] outb bundle to use for returning result
- * @return 0 if success, negative value(<0) if fail
- * @retval AUL_R_OK - success
- * @retval AUL_R_EINVAL - inb is not bundle created by aul_open_service
- * @retval AUL_R_ERROR - general error
- *
- * @pre
- * To create result bundle, You need received original bundle.
- * The original bundle can get from app_reset handler.
- * @post
- * None
- * @see
- * aul_send_service_result
- * @code
- * #include <aul.h>
- * #include <bundle.h>
- *
- * int app_reset(bundle *b, void *data)
- * {
- * ad->recved_bundle = bundle_dup(b);
- * }
- *
- * int click_ok()
- * {
- * bundle* res_bundle;
- * aul_create_result_bundle(ad->recved_bundle,&res_bundle);
- * bundle_add(res_bundle, "result", "1");
- * aul_send_service_result(res_bundle);
- * }
- * @endcode
- * @remark
- * This API is only available in User Session.
- *
- */
-int aul_create_result_bundle(bundle *inb, bundle **outb);
-
-/**
- * @par Description:
- * This API send service result to caller with bundle
- * @par Purpose:
- * This API is used to send result bundle to caller.
- * @par Typical use case:
- * This API is for callee which provide application service.\n
- * To send result to caller, You can use this API after creating result bundle. \n
- * Callee(application to provide service) can send result by using this API and aul_create_result_bundle.
- *
- * @param[in] b Result data in bundle format
- * @return 0 if success, negative value(<0) if fail
- * @retval AUL_R_OK - success
- * @retval AUL_R_EINVAL - invalid result bundle
- * @retval AUL_R_ECOMM - internal AUL IPC error
- * @retval AUL_R_ERROR - general error
- *
- * @pre
- * To send result bundle, You must create result bundle.
- * see aul_create_result_bundle
- * @post
- * None
- * @see
- * aul_create_result_bundle
- * @code
- * #include <aul.h>
- * #include <bundle.h>
- *
- * int app_reset(bundle *b, void *data)
- * {
- * ad->recved_bundle = bundle_dup(b);
- * }
- *
- * int click_ok()
- * {
- * bundle* res_bundle;
- * aul_create_result_bundle(ad->recved_bundle,&res_bundle);
- * bundle_add(res_bundle, "result", "1");
- * aul_send_service_result(res_bundle);
- * }
- * @endcode
- * @remark
- * This API is only available in User Session.
- *
- */
-int aul_send_service_result(bundle *b);
-
-/**
- * @brief Called when an application is terminated.
- * @details This function is called when an application is terminated, after you register this callback using aul_listen_app_dead_signal().
- * @param[in] pid The process ID
- * @param[in] user_data The user data passed from the registeration function
- *
- * @see aul_listen_app_dead_signal()
- */
-typedef int (*aul_app_dead_event_cb)(int pid, void *user_data);
-
-/**
- * @breif Registers a callback function to be invoked when the application is terminated.
- * @remarks If the callback function is nullptr, the registered event will be deregistered.
- * @param[in] callback The callback function
- * @param[in] user_data The user data to be passed to the callback function
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #AUL_R_OK Successful
- * @retval #AUL_R_ERROR Internal I/O error
- * @see aul_app_dead_event_cb()
- *
- * @remarks This function is only available for App Framework internally.
- *
- * @code
- * #include <aul.h>
- *
- * static int app_dead_event_cb(int pid, void *user_data)
- * {
- * dlog_print(DLOG_INFO, LOG_TAG, "application(%s) is terminated", pid);
- * return 0;
- * }
- *
- * int listen_app_dead_signal(void)
- * {
- * int ret;
- *
- * ret = aul_listen_app_dead_signal(app_dead_event_cb, NULL);
- * if (ret != AUL_R_OK) {
- * dlog_print(DLOG_ERROR, LOG_TAG, "aul_listen_app_dead_signal() is failed. error(%d)", ret);
- * return -1;
- * }
- *
- * return 0;
- * }
- */
-int aul_listen_app_dead_signal(aul_app_dead_event_cb callback, void *user_data);
-
-/**
- * @brief Called when an application is launched.
- * @details This function is called when an application is launched, after you register this callback using aul_listen_app_launch_signal().
- * @param[in] pid The process ID
- * @param[in] user_data The user data passed from the registeration function
- *
- * @see aul_listen_app_launch_signal()
- */
-typedef int (*aul_app_launch_event_cb)(int pid, void *user_data);
-
-/**
- * @brief Registers a callback function to be invoked when the application is launched.
- * @remarks If the callback function is nullptr, the registered event will be deregistered.
- * @param[in] callback The callback function
- * @param[in] user_data The user data to be passed to the callback function
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #AUL_R_OK Successful
- * @retval #AUL_R_ERROR Internal I/O error
- * @see aul_app_launch_event_cb()
- *
- * @remarks This function is only available for App Framework internally.
- *
- * @see
- * #include <aul.h>
- *
- * static int app_launch_event_cb(int pid, void *user_data)
- * {
- * dlog_print(DLOG_INFO, LOG_TAG, "application(%d) is launched", pid);
- * return 0;
- * }
- *
- * int listen_app_launch_signal(void)
- * {
- * int ret;
- *
- * ret = aul_listen_app_launch_signal(app_launch_event_cb, NULL);
- * if (ret != AUL_R_OK) {
- * dlog_print(DLOG_ERROR, LOG_TAG, "aul_listen_app_launch_signal() is failed. error(%d)", ret);
- * return -1;
- * }
- *
- * return 0;
- * }
- */
-int aul_listen_app_launch_signal(aul_app_launch_event_cb callback, void *user_data);
-
-/**
- * @brief Called when an application is launched.
- * @details This function is called when an application is launched, after you register this callback using aul_listen_app_launch_signal_v2().
- * @param[in] pid The process ID
- * @param[in] appid The application ID
- * @param[in] user_data The user data passed from the registeration function
- *
- * @see aul_listen_app_launch_signal_v2()
- */
-typedef int (*aul_app_launch_event_cb_v2)(int pid, const char *appid, void *user_data);
-
-/**
- * @brief Registers a callback function to be invoked when the application is launched.
- * @remarks If the callback function is nullptr, the registered event will be deregistered.
- * @param[in] callback The callback function
- * @param[in] user_data The user data to be passed to the callback function
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #AUL_R_OK Successful
- * @retval #AUL_R_ERROR Internal I/O error
- *
- * @see aul_app_launch_event_cb_v2()
- *
- * @remarks This function is only available for App Framework internally.
- *
- * @code
- * #include <aul.h>
- *
- * static int app_launch_event_cb(int pid, const char *appid, void *user_data)
- * {
- * dlog_print(DLOG_INFO, LOG_TAG, "application(%s:%d) is launched", appid, pid);
- * return 0;
- * }
- *
- * int listen_app_launch_signal(void)
- * {
- * int ret;
- *
- * ret = aul_listen_app_launch_signal_v2(app_launch_event_cb, NULL);
- * if (ret != AUL_R_OK) {
- * dlog_print(DLOG_ERROR, LOG_TAG, "aul_listen_app_launch_signal_v2() is failed. error(%d)", ret);
- * return -1;
- * }
- *
- * return 0;
- * }
- */
-int aul_listen_app_launch_signal_v2(aul_app_launch_event_cb_v2 callback, void *user_data);
-
-/**
- * @brief Called when an application is terminated.
- * @details This function is called when an application is terminated, after you register this callback using aul_listen_app_dead_signal_v2().
- * @param[in] pid The process ID
- * @param[in] status The exit status
- * @param[in] user_data The user data passed from the registeration function
- *
- * @see aul_listen_app_dead_signal_v2()
- */
-typedef void (*aul_app_dead_event_cb_v2)(int pid, int status, void* user_data);
-
-/**
- * @breif Registers a callback function to be invoked when the application is terminated.
- * @remarks If the callback function is nullptr, the registered event will be deregistered.
- * @param[in] callback The callback function
- * @param[in] user_data The user data to be passed to the callback function
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #AUL_R_OK Successful
- * @retval #AUL_R_ERROR Internal I/O error
- * @see aul_app_dead_event_cb_v2()
- *
- * @remarks This function is only available for App Framework internally.
- *
- * @code
- * #include <aul.h>
- *
- * static void app_dead_event_cb(int pid, int status, void *user_data)
- * {
- * dlog_print(DLOG_INFO, LOG_TAG, "application(%s) is terminated. status(%d)", pid, status);
- * }
- *
- * int listen_app_dead_signal(void)
- * {
- * int ret;
- *
- * ret = aul_listen_app_dead_signal_v2(app_dead_event_cb, NULL);
- * if (ret != AUL_R_OK) {
- * dlog_print(DLOG_ERROR, LOG_TAG, "aul_listen_app_dead_signal_v2() is failed. error(%d)", ret);
- * return -1;
- * }
- *
- * return 0;
- * }
- */
-int aul_listen_app_dead_signal_v2(aul_app_dead_event_cb_v2 callback, void *user_data);
-
-/**
- * @par Description:
- * This API gets status of specified application process id.
- * @par Purpose:
- * This API's purpose is to get the application's status.
- *
- * @param[in] pid pid of application
- * @return 0 or greater if success, nagative value if fail
- * @retval STATUS_LAUNCHING
- * @retval STATUS_VISIBLE
- * @retval STATUS_BG
- * @retval STATUS_DYING
- * @retval STATUS_NORESTART
- * @see
- * aul_status_update
- * @code
- * #include <aul.h>
- *
- * int iterfunc(const aul_app_info *info, void *data)
- * {
- * int status;
- * status = aul_app_get_status_bypid(info->pid);
- * if (status == STATUS_VISIBLE) {
- * printf("%s has focus", info->app_id);
- * (int *)data = info->pid;
- * return -1;
- * }
- * return 0;
- * }
- *
- * int find_focus_app_pid()
- * {
- * int pid = 0;
- * aul_app_get_running_app_info(iterfunc, &pid);
- * return pid;
- * }
- * @endcode
- * @remark
- * This API is only available in User Session.
- */
-int aul_app_get_status_bypid(int pid);
-
-/**
- * @par Description:
- * This API gets status of specified application process id.
- * @par Purpose:
- * This API's purpose is to get the application's status.
- *
- * @param[in] pid pid of application
- * @param[in] uid User ID
- * @return 0 or greater if success, nagative value if fail
- * @retval STATUS_LAUNCHING
- * @retval STATUS_VISIBLE
- * @retval STATUS_BG
- * @retval STATUS_DYING
- * @retval STATUS_NORESTART
- *
- * @remark
- * This API is only available to System user.
- */
-int aul_app_get_status_bypid_for_uid(int pid, uid_t uid);
-
-/**
- * @par Description:
- * This API gets the status of specified application id.
- * @par Purpose:
- * This API's purpose is to get the status of the application.
- *
- * @param[in] appid application ID
- * @return 0 or greater if success, nagative value if fail
- * @retval STATUS_LAUNCHING
- * @retval STATUS_FOCUS
- * @retval STATUS_VISIBLE
- * @retval STATUS_BG
- * @retval STATUS_DYING
- * @retval STATUS_NORESTART
- * @see
- * aul_status_update
- * @code
- * #include <aul.h>
- *
- * int func(void)
- * {
- * int status;
- *
- * status = aul_app_get_status("org.tizen.helloworld");
- * if (status == STATUS_FOCUS)
- * printf("org.tizen.helloworld has focus");
- *
- * return 0;
- * }
- *
- * @endcode
- * @remark
- * This API is only available in User Session.
- */
-int aul_app_get_status(const char *appid);
-
-/**
- * @par Description:
- * This API gets the status of specified application id.
- * @par Purpose:
- * This API's purpose is to get the status of the application
- *
- * @param[in] appid application ID
- * @param[in] uid User ID
- * @return 0 or greater if success, nagative value if fail
- * @retval STATUS_LAUNCHING
- * @retval STATUS_FOCUS
- * @retval STATUS_VISIBLE
- * @retval STATUS_BG
- * @retval STATUS_DYING
- * @retval STATUS_NORESTART
- *
- * @remark
- * This API is only available to System user.
- */
-int aul_app_get_status_for_uid(const char *appid, uid_t uid);
-
-/**
- * @brief Called when the status is changed.
- * @remarks If @c is a negative error value,
- * the registered callback function will be deregistered.
- * @param[in] status The status
- * @param[in] user_data The user data passed from the registration function
- * @return @c 0 to continue with the next iteration of the loop,
- * otherwise a negative error value to break out of the loop
- * @see aul_add_status_local_cb()
- * @see aul_remove_status_local_cb();
- */
-typedef int (*aul_status_local_cb)(int status, void *user_data);
-
-/**
- * @par Description
- * This API sets callback function that on application status changed.
- * @par Purpose:
- * This API's purpose is to listen the application's status changed within
- * the caller process. In general, a library that required to release resource on
- * application's status may use this API.
- *
- * @param[in] callback callback function
- * @param[in] data user data
- * @return 0 if success, negative value if fail
- * @retval AUL_R_OK - success
- * @retval AUL_R_ERROR - general error
- * @see
- * aul_remove_status_local_cb
- * @code
- * #include <aul.h>
- *
- * int status_changed(int status, void *data)
- * {
- * if (status == STATUS_VISIBLE)
- * printf("%d resume\n", getpid());
- *
- * if (status == STATUS_BG)
- * printf("%d pause\n", getpid());
- * }
- *
- * void listen_app_status()
- * {
- * aul_add_status_local_cb(status_changed, NULL);
- * }
- * @endcode
- * @remark
- * This API is only available in User Session.
- *
- */
-int aul_add_status_local_cb(aul_status_local_cb callback, void *data);
-
-/**
- * @par Description
- * This API unsets callback function that on application status changed.
- * @par Purpose:
- * This API's purpose is to remove callback that added by
- * aul_add_status_local_cb.
- *
- * @param[in] callback callback function
- * @param[in] data user data
- * @return 0 if success, negative value if fail
- * @retval AUL_R_OK - success
- * @retval AUL_R_ERROR - general error
- *
- * @see
- * aul_add_status_local_cb
- * @code
- * #include <aul.h>
- *
- * int status_changed(int status, void *data)
- * {
- * if (status == STATUS_VISIBLE)
- * printf("%d resume\n", getpid());
- *
- * if (status == STATUS_BG)
- * printf("%d pause\n", getpid());
- * }
- *
- * void listen_app_status()
- * {
- * aul_add_status_local_cb(status_changed, NULL);
- * }
- *
- * void ignore_app_status()
- * {
- * aul_remove_status_local_cb(status_changed, NULL);
- * }
- *
- * @endcode
- * @remark
- * This API is only available in User Session.
- *
- */
-int aul_remove_status_local_cb(aul_status_local_cb callback, void *data);
-
-/*
- * This API is only for appfw internally.
- */
-int aul_set_process_group(int parent_pid, int child_pid);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_terminate_bgapp_pid(int pid);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_terminate_pid_without_restart(int pid);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_terminate_pid_sync_without_restart(int pid);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_terminate_pid_sync_without_restart_for_uid(int pid, uid_t uid);
-
-/*
- * This API is only for Appfw internally.
- */
-const char *aul_get_app_external_root_path(void);
-
-/*
- * This API is only for Appfw internally.
- */
-const char *aul_get_app_root_path(void);
-
-/*
- * This API is only for Appfw internally.
- */
-const char *aul_get_app_data_path(void);
-
-/*
- * This API is only for Appfw internally.
- */
-const char *aul_get_app_cache_path(void);
-
-/*
- * This API is only for Appfw internally.
- */
-const char *aul_get_app_resource_path(void);
-
-/*
- * This API is only for Appfw internally.
- */
-const char *aul_get_app_tep_resource_path(void);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_get_app_shared_data_path(char **path);
-
-/*
- * This API is only for Appfw internally.
- */
-const char *aul_get_app_shared_resource_path(void);
-
-/*
- * This API is only for Appfw internally.
- */
-const char *aul_get_app_shared_trusted_path(void);
-
-/*
- * This API is only for Appfw internally.
- */
-const char *aul_get_app_external_data_path(void);
-
-/*
- * This API is only for Appfw internally.
- */
-const char *aul_get_app_external_cache_path(void);
-
-/*
- * This API is only for Appfw internally.
- */
-const char *aul_get_app_external_shared_data_path(void);
-
-/*
- * This API is only for Appfw internally.
- */
-const char *aul_get_app_specific_path(void);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_get_app_res_control_allowed_resource_path(const char *res_type, char **path);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_get_app_res_control_global_resource_path(const char *res_type, char **path);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_get_app_shared_data_path_by_appid(const char *app_id, char **path);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_get_app_shared_resource_path_by_appid(const char *app_id, char **path);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_get_app_shared_trusted_path_by_appid(const char *app_id, char **path);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_get_app_external_shared_data_path_by_appid(const char *app_id, char **path);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_get_usr_app_shared_data_path_by_appid(const char *app_id, char **path, uid_t uid);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_get_usr_app_shared_resource_path_by_appid(const char *app_id, char **path, uid_t uid);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_get_usr_app_shared_trusted_path_by_appid(const char *app_id, char **path, uid_t uid);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_get_usr_app_external_shared_data_path_by_appid(const char *app_id, char **path, uid_t uid);
-
-/*
- * This type is only for Appfw internally.
- */
-typedef int (*subapp_fn)(void *data);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_set_subapp(subapp_fn cb, void *data);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_subapp_terminate_request_pid(int pid);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_is_subapp(void);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_kill_pid(int pid);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_add_caller_cb(int pid, void (*caller_cb) (int, void *), void *data);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_remove_caller_cb(int pid, void *data);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_invoke_caller_cb(void *data);
-
-/*
- * This API is only for Appfw internally.
- */
-void aul_set_preinit_window(void *evas_object);
-
-/*
- * This API is only for Appfw internally.
- */
-void* aul_get_preinit_window(const char *win_name);
-
-/*
- * This API is only for Appfw internally.
- */
-void aul_set_preinit_background(void *evas_object);
-
-/*
- * This API is only for Appfw internally.
- */
-void* aul_get_preinit_background(void);
-
-/*
- * This API is only for Appfw internally.
- */
-void aul_set_preinit_conformant(void *evas_object);
-
-/*
- * This API is only for Appfw internally.
- */
-void* aul_get_preinit_conformant(void);
-
-/*
- * This API is only for Appfw internally.
- */
-void aul_set_preinit_appid(const char *appid);
-
-/*
- * This API is only for Appfw internally.
- */
-void aul_set_preinit_pkgid(const char *pkgid);
-
-/*
- * This API is only for Appfw internally.
- */
-void aul_set_preinit_root_path(const char *root_path);
-
-/*
- * This API is only for Appfw internally.
- */
-const char *aul_get_preinit_root_path(void);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_update_freezer_status(int pid, const char* type);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_send_app_launch_request_signal(int pid, const char* appid, const char* pkgid, const char* type);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_send_app_resume_request_signal(int pid, const char* appid, const char* pkgid, const char *type);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_send_app_terminate_request_signal(int pid, const char* appid, const char* pkgid, const char *type);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_send_app_status_change_signal(int pid, const char* appid, const char* pkgid, const char* status, const char *type);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_send_app_terminated_signal(int pid);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_send_app_group_signal(int owner_pid, int child_pid, const char *child_pkgid);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_invoke_status_local_cb(int status);
-
-/*
- * This type is only for Appfw internally.
- */
-typedef int (*data_control_provider_handler_fn) (bundle *b, int request_id, void *data);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_set_data_control_provider_cb(data_control_provider_handler_fn handler);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_unset_data_control_provider_cb(void);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_pause_app(const char *appid);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_pause_app_for_uid(const char *appid, uid_t uid);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_pause_pid(int pid);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_pause_pid_for_uid(int pid, uid_t uid);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_reload_appinfo(void);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_status_update(int status);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_app_group_get_window(int pid);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_app_group_set_window(int wid);
-
-/*
- * This API is only for Appfw internally.
- */
-void aul_app_group_get_leader_pids(int *cnt, int **pids);
-
-/*
- * This API is only for Appfw internally.
- */
-void aul_app_group_get_group_pids(int leader_pid, int *cnt, int **pids);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_app_group_get_leader_pid(int pid);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_app_group_clear_top(void);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_app_group_is_top(void);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_app_group_get_fg_flag(int pid);
-
-/*
- * This API is only for Appfw internally.
- */
-void aul_app_group_lower(int *exit);
-
-/*
- * This API is only for Appfw internally.
- */
-void aul_app_group_get_idle_pids(int *cnt, int **pids);
-
-/**
- * @par Description:
- * This API puts some app below the caller app
- * @par Purpose:
- * This API's purpose is to reorder window stack limitedly.
- *
- * @param[in] below_appid The appid to be reordered below the caller app
- * @return 0 success, negative value(<0) if fail
- *
- * @remark
- * below_appid should be main app which have been launched before.
- * This API is only available in User Session.
-*/
-int aul_app_group_activate_below(const char *below_appid);
-
-/**
- * @par Description:
- * This API puts some app above the caller app
- * @par Purpose:
- * This API's purpose is to reorder window stack limitedly.
- *
- * @param[in] above_appid The appid to be reordered above the caller app
- * @return 0 if success, negative value(<0) if fail
- *
- * @remark
- * above_appid should be main app which have been launched before.
- * This API is only available in User Session.
-*/
-int aul_app_group_activate_above(const char *above_appid);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_request_data_control_socket_pair(bundle *b, int *fd);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_request_message_port_socket_pair(int *fd);
-
-/**
- * @brief Called when the system booting is completed.
- * @param[in] unused The unused parameter
- * @param[in] user_data The use data passed from the registration function
- * @return The return value is not used.
- *
- * @see aul_listen_booting_done_signal();
- */
-typedef int (*aul_booting_done_event_cb)(int unused, void *user_data);
-
-/**
- * @brief Registers a callback function to be invoked when the system booting is completed.
- * @param[in] callback The callback function
- * @param[in] user_data The user data to be passed to the callback function
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @see aul_booting_done_event_cb()a
- * @remarks This function is only available for App Framework internally.
- */
-int aul_listen_booting_done_signal(aul_booting_done_event_cb, void *user_data);
-
-/**
- * @brief Called when the coodlown event occurs.
- * @param[in] status The cooldown status
- * @param[in] user_data The user data passed from the registration function
- * @return The return value is not used.
- *
- * @see aul_listen_cooldown_signal()
- */
-typedef int (*aul_cooldown_event_cb)(const char *status, void *user_data);
-
-/**
- * @brief Registers a callback function to be invoked when the cooldown event occurs.
- * @param[in] callback The callback function
- * @param[in] user_data The user data to be passed to the callback function
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @see aul_coodlown_event_cb()
- *
- * @remarks This function is only available for App Framework internally.
- */
-int aul_listen_cooldown_signal(int (*func) (const char *, void *), void *data);
-
-/**
- * @brief Called when the status of the app process is changed.
- * @details This function is called when the app process status is changed, after you register this callback using aul_listen_app_status_signal().
- * @param[in] pid The process ID
- * @param[in] status The status of the process
- * @param[in] user_data The user data passed from the registeration function
- *
- * @see @aul_listen_app_status_signal()
- * @see #aul_process_status_e
- */
-typedef int (*aul_app_status_changed_cb)(int pid, int status, void *user_data);
-
-/**
- * @brief Registers a callback function to be invoked when the process status is changed.
- * @remarks If the callback function is nullptr, the registered event will be deregistered.
- * @param[in] callback The callback function
- * @param[in] user_data The user data to be passed to the callback function
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #AUL_R_OK Successful
- * @retval #AUL_R_ERROR Internal I/O error
- *
- * @see @aul_app_status_changed_cb()
- * @see #aul_process_status_e
- *
- * @remarks This function is only available for App Framework internally.
- *
- * @code
- * #include <aul.h>
- *
- * static int app_status_changed_cb(int pid, int status, void *user_data)
- * {
- * cosnt char *app_status;
- *
- * switch (status) {
- * case AUL_PROC_STATUS_LAUNCH:
- * app_status = "LAUNCHING";
- * break;
- * case AUL_PROC_STATUS_FG:
- * app_status = "VISIBLE";
- * break;
- * case AUL_PROC_STATUS_BG:
- * app_status = "BACKGROUND";
- * break;
- * case AUL_PROC_STATUS_FOCUS:
- * app_status = "FOCUS";
- * break;
- * case AUL_PROC_STATUS_HIDE:
- * app_status = "HIDE";
- * break;
- * default:
- * app_status = "UNKNOWN";
- * break;
- * }
- *
- * dlog_print(DLOG_INFO, LOG_TAG, "pid: %d, status: %%s(%d)", pid, app_status, status);
- * return 0;
- * }
- *
- * int listen_app_status_signal(void)
- * {
- * int ret;
- *
- * ret = aul_listen_app_status_signal(app_status_changed_cb, NULL);
- * if (ret != AUL_R_OK) {
- * dlog_print(DLOG_ERROR, LOG_TAG, "aul_listen_app_status_signal() is failed. error(%d)", ret);
- * return -1;
- * }
- *
- * return 0;
- * }
- */
-int aul_listen_app_status_signal(aul_app_status_changed_cb callback, void *user_data);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_check_tep_mount(const char *tep_path);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_is_tep_mount_dbus_done(const char *tep_string);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_forward_app(const char *appid, bundle *kb);
-
-/**
- * @par Description:
- * This API create custom launchpad-loader
- * @par Purpose:
- * This API's purpose is to make a slot for custom loader.
- * Once it is made, added loader will make a candidate process to use.
- *
- * @param[in] loader_path The file name of the custom loader binary including full path
- * @param[in] extra A bundle to be passed to the custom loader
- * @return Loader ID if success, negative value(<0) if fail
- *
- * @remark
- * This API is only for Appfw internally.
- * This API is only available in User Session.
-*/
-int aul_add_loader(const char *loader_path, bundle *extra);
-
-/**
- * @par Description:
- * This API create custom launchpad-loader
- * @par Purpose:
- * This API's purpose is to make a slot for custom loader.
- * Once it is made, added loader will make a candidate process to use.
- *
- * @param[in] loader_path The file name of the custom loader binary including full path
- * @param[in] extra A bundle to be passed to the custom loader
- * @param[in] uid User ID
- * @return Loader ID if success, negative value(<0) if fail
- *
- * @remark
- * This API is only for Appfw internally.
- * This API is only available to System user.
-*/
-int aul_add_loader_for_uid(const char *loader_path, bundle *extra, uid_t uid);
-
-
-/**
- * @par Description:
- * This API destroy custom launchpad-loader
- * @par Purpose:
- * This API's purpose is to remove a slot for custom loader.
- * Once it is removed, the prepared process will be removed as well.
- *
- * @param[in] loader_id Loader ID
- * @return 0 if success, negative value(<0) if fail
- *
- * @remark
- * This API is only for Appfw internally.
- * This API is only available in User Session.
-*/
-int aul_remove_loader(int loader_id);
-
-/**
- * @par Description:
- * This API destroy custom launchpad-loader
- * @par Purpose:
- * This API's purpose is to remove a slot for custom loader.
- * Once it is removed, the prepared process will be removed as well.
- *
- * @param[in] loader_id Loader ID
- * @param[in] uid User ID
- * @return 0 if success, negative value(<0) if fail
- *
- * @remark
- * This API is only for Appfw internally.
- * This API is only available to System user.
-*/
-int aul_remove_loader_for_uid(int loader_id, uid_t uid);
-
-/**
- * @par Description
- * This API gets specified application process id.
- * @par Purpose:
- * The purpose of this API is to get the pid of specified application.
- *
- * @param[in] appid application name
- * @return callee's pid if success, negative value(<0) if fail
- *
- * @remark
- * This API is only available in User Session.
- */
-int aul_app_get_pid(const char *appid);
-
-/**
- * @par Description
- * This API gets specified application process id.
- * @par Purpose:
- * The purpose of this API is to get the pid of specified application.
- *
- * @param[in] appid application name
- * @param[in] uid User ID
- * @return callee's pid if success, negative value(<0) if fail
- *
- * @remark
- * This API is only available to System user.
- */
-int aul_app_get_pid_for_uid(const char *appid, uid_t uid);
-
-/**
- * @par Description:
- * This function update rua stat.
- *
- * @param[in] b Bundle object contains caller and tag information.
- * @param[in] uid Target uid
- *
- * @return 0 if success, negative value(<0) if fail
- * @see None
- * @remarks This API is only for Appfw internally.
- *
- * @par Sample code:
- * @code
-#include <aul.h>
-
-...
-{
- int r;
- bundle *b = bundle_create();
- bundle_add_str(b, AUL_SVC_K_RUA_STAT_CALLER, caller);
- bundle_add_str(b, AUL_SVC_K_RUA_STAT_TAG, tag);
-
- r = aul_update_rua_stat_for_uid(b);
-}
-
- * @endcode
- **/
-int aul_update_rua_stat_for_uid(bundle *b, uid_t uid);
-
-/**
- * @par Description:
- * This function add rua history.
- *
- * @param[in] b Bundle object Target Package name or app path.
- * @param[in] uid Target uid
- *
- * @return 0 if success, negative value(<0) if fail
- * @see None
- * @remarks This API is only for Appfw internally.
- *
- * @par Sample code:
- * @code
-#include <aul.h>
-
-...
-{
- int r;
- bundle *b = bundle_create();
- if (pkg_name)
- bundle_add_str(b, AUL_K_RUA_PKGNAME, pkg_name);
- else if (app_path)
- bundle_add_str(b, AUL_K_RUA_APPPATH, app_path);
-
- r = aul_add_rua_history_for_uid(b);
-}
-
- * @endcode
- **/
-int aul_add_rua_history_for_uid(bundle *b, uid_t uid);
-
-/**
- * @par Description:
- * This function delete rua history.
- *
- * @param[in] b Bundle object Target Package name. If NULL or has no value, delete all rua history.
- * @param[in] uid Target uid
- *
- * @return 0 if success, negative value(<0) if fail
- * @see None
- * @remarks This API is only for Appfw internally.
- *
- * @par Sample code:
- * @code
-#include <aul.h>
-
-...
-{
- int r;
- bundle *b = NULL;
- if (pkg_name) {
- b = bundle_create();
- bundle_add_str(b, AUL_K_RUA_PKGNAME, pkg_name);
- }
- r = aul_delete_rua_history_for_uid(b, getuid());
-}
-
- * @endcode
- **/
-int aul_delete_rua_history_for_uid(bundle *b, uid_t uid);
-
-
-/**
- * @par Description:
- * This function sets the default application(application id) associated with operatioin, uri and mime-type.
- *
- * @param[in] b Bundle object Target application id and operation, uri and mime-type.
- *
- * @return 0 if success, negative value(<0) if fail
- * @see None
- * @remarks This API is only for Appfw internally.
- *
- * @par Sample code:
- * @code
-#include <aul.h>
-#include <aul_svc.h>
-
-...
-{
- int r;
- bundle *b = bundle_create();
-
- const char *appid = "org.tizen.test";
- const char *operation = "test_operation";
- const char *mime_type = "test_mime";
- const char *uri = "test_uri";
-
- aul_svc_set_operation(b, operation);
- aul_svc_set_mime(b, mime_type);
- aul_svc_set_uri(b, uri);
-
- aul_svc_set_appid(b, appid)
-
- r = aul_set_default_app_by_operation(b);
-}
-
- * @endcode
- **/
-int aul_set_default_app_by_operation(bundle *b);
-
-/**
- * @par Description:
- * This API unset the default application(application id) associated with operation, uri and mime-type.
- *
- * @param[in] app_id The ID of the application
- *
- * @return 0 if success, negative value(<0) if fail
- *
- * @pre None.
- * @post None.
- * @see None.
- * @remarks None.
- *
- * @par Sample code:
- * @code
-#include <aul.h>
-
-...
-{
- aul_unset_default_app_by_operation("org.tizen.test");
-}
- * @endcode
- *
- */
-int aul_unset_default_app_by_operation(const char *app_id);
-
-/**
- * @par Description:
- * Sends the launch request asynchronously.
- *
- * @param[in] appid The application ID
- * @param[in] kb The Bundle data
- * @return a pid of the callee on success,
- * otherwise a negative error value
- * @retval AUL_R_OK - Successful
- * @retval AUL_R_EINVAL - Invalid parameter
- * @retval AUL_R_ECOM - Internal AUL IPC error
- * @retval AUL_R_ERROR - General error
- *
- * @remark
- * This API is only available in User Session.
- * This API doesn't check whether the callee application is executed successfully.
- * If the caller application is equal to the callee application, this API can return AUL_R_OK.
- */
-int aul_launch_app_async(const char *appid, bundle *kb);
-
-/**
- * @par Description:
- * Sends the launch request asynchronously.
- *
- * @param[in] appid The application ID
- * @param[in] kb The Bundle data
- * @param[in] uid User ID
- * @return a pid of the callee on success,
- * otherwise a negative error value
- * @retval AUL_R_OK - Successful
- * @retval AUL_R_EINVAL - Invalid parameter
- * @retval AUL_R_ECOM - Internal AUL IPC error
- * @retval AUL_R_ERROR - General error
- *
- * @remark
- * This API is only available to System user.
- * This API doesn't check whether the callee application is executed successfully.
- * If the caller application is equal to the callee application, this API can return AUL_R_OK.
- */
-int aul_launch_app_async_for_uid(const char *appid, bundle *kb, uid_t uid);
-
-/**
- * @par Description:
- * This API request launchpad to make candidate processes.
- *
- * @return 0 if success, negative value(<0) if fail
- *
- * @remark
- * This API is only available in User Session.
- */
-int aul_prepare_candidate_process(void);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_widget_instance_add(const char *widget_id, const char *instance_id);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_widget_instance_del(const char *widget_id, const char *instance_id);
-
-/*
- * This API is only for Appfw internally.
- */
-typedef void (*aul_widget_instance_foreach_cb)(const char *instance_id, void *data);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_widget_instance_foreach(const char *widget_id, aul_widget_instance_foreach_cb cb, void *data);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_widget_instance_update(const char *widget_id, const char *instance_id, bundle *b);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_widget_instance_count(const char *widget_id);
-
-/**
- * @par Description:
- * This API gets the last caller process id of specified application process id.
- * @par Purpose:
- * This API's purpose is to get the application's last caller process id.
- *
- * @param[in] pid pid of application
- * @return caller pid if success, nagative value if fail
- *
- * @remark
- * This API is only available in User Session.
- */
-int aul_app_get_last_caller_pid(int pid);
-
-/**
- * @par Description:
- * This API gets the last caller process id of specified application process id.
- * @par Purpose:
- * This API's purpose is to get the last caller process id of the application.
- *
- * @param[in] pid pid of application
- * @param[in] uid User ID
- * @return caller pid if success, nagative value if fail
- *
- * @remark
- * This API is only available in System users.
- */
-int aul_app_get_last_caller_pid_for_uid(int pid, uid_t uid);
-
-/**
- * @par Description:
- * This API trigger to resume application asynchronously.
- * If the application is running, this API send a resume event to the App.
- * If the application is not running, this API return AUL_R_ERROR.
- * Although the application is running, if the application cannot receive resume event,
- * AUL try to raise the application's default windows.
- * @par Purpose:
- * This API is for caller.
- * This API's purpose is to send resume event.
- * @par Typical use case:
- * In multiple application model, If you want to only resume specific application, Use this API
- *
- * @param[in] pid application's pid to be resumed
- * @return 0 if success, negative value(<0) if fail
- * @retval AUL_R_OK - success
- * @retval AUL_R_EINVAL - invaild pid
- * @retval AUL_R_ECOM - internal AUL IPC error
- * @retval AUL_R_ERROR - general error (include application is not running)
- * @warning This API need to require root or inhouse permisssion \n
- * If you have not the permission, this API return AUL_R_ERROR. \n
- * @remark
- * This API is only available to User Session.
- */
-int aul_resume_pid_async(int pid);
-
-/**
- * @par Description:
- * This API trigger to resume application asynchronously.
- * If the application is running, this API send a resume event to the App.
- * If the application is not running, this API return AUL_R_ERROR.
- * Although the application is running, if the application cannot receive resume event,
- * AUL try to raise the application's default windows.
- * @par Purpose:
- * This API is for caller.
- * This API's purpose is to send resume event.
- * @par Typical use case:
- * In multiple application model, If you want to only resume specific application, Use this API
- *
- * @param[in] pid application's pid to be resumed
- * @param[in] uid User ID
- * @return 0 if success, negative value(<0) if fail
- * @retval AUL_R_OK - success
- * @retval AUL_R_EINVAL - invaild pid
- * @retval AUL_R_ECOM - internal AUL IPC error
- * @retval AUL_R_ERROR - general error (include application is not running)
- * @warning This API need to require root or inhouse permisssion \n
- * If you have not the permission, this API return AUL_R_ERROR. \n
- * @remark
- * This API is only available to System user.
- */
-int aul_resume_pid_async_for_uid(int pid, uid_t uid);
-
-/**
- * @par Description:
- * This API set the alias appid.
- * The alias appid is only available for the aul_svc_set_appid() API.
- * If the appid is not available, this API returns an error.
- *
- * @privlevel platform
- * @privilege %http://tizen.org/privilege/systemsettings.admin
- * @param[in] alias_appid an alias application ID
- * @param[in] appid an application ID
- * @return 0 if success, negative value(<0) if fail
- *
- * @remark
- * This API is only available to User Session.
- */
-int aul_set_alias_appid(const char *alias_appid, const char *appid);
-
-/**
- * @par Description:
- * This API unset the alias appid.
- *
- * @privlevel platform
- * @privilege %http://tizen.org/privilege/systemsettings.admin
- * @param[in] alias_appid an alias application ID
- * @return 0 if success, negative value(<0) if fail
- *
- * @remark
- * This API is only available to User Session.
- */
-int aul_unset_alias_appid(const char *alias_appid);
-
-/**
- * @par Description:
- * This API activates the alias information based on the given appid.
- *
- * @privlevel platform
- * @privilege %http://tizen.org/privilege/systemsettings.admin
- * @param[in] appid an application ID
- * @return 0 if success, negative value(<0) if fail
- *
- * @remark
- * This API is only available to User Session.
- */
-int aul_enable_alias_info(const char *appid);
-
-/**
- * @par Description:
- * This API deactivates the alias information based on the given appid.
- *
- * @privlebel platform
- * @privilege %http://tizen.org/privilege/systemsettings.admin
- * @param[in] appid an application ID
- * @return 0 if success, negative value(<0) if fail
- *
- * @remark
- * This API is only available to User Session.
- */
-int aul_disable_alias_info(const char *appid);
-
-/**
- * This API is only for Appfw internally.
- */
-typedef int (*app_status_cb)(aul_app_info *info, int ctx_status, void *data);
-
-/**
- * This API is only for Appfw internally.
- */
-typedef struct status_listen_s *status_listen_h;
-
-/**
- * @par Description:
- * Registers a callback function to be invoked when the application change status.
- *
- * @param[in] appid The application ID to get status
- * @param[in] callback The callback function to register
- * @param[in] data The user data to be passed to the callback function
- * @param[out] handle The status listen handle
- * @return @c 0 on success,
- * otherwise a negative error value
- */
-int aul_listen_app_status(const char *appid, app_status_cb callback,
- void *data, status_listen_h *handle);
-int aul_listen_app_status_for_uid(const char *appid, app_status_cb callback,
- void *data, status_listen_h *handle, uid_t uid);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_widget_instance_get_content(const char *widget_id, const char *instance_id, char **content);
-
-/**
- * @par Description:
- * Gets running application instance info
- * This API calls the iter_fn with the aul_app_info when running app instance info is found.
- *
- * @param[in] iter_fn iterative function
- * @param[in] user_data User data
- * @return 0 if success, negative value(<0) if fail
- * @retval AUL_R_OK Successful
- * @retval AUL_R_ERROR General error
- * @retval AUL_R_EINVAL Invalid parameter
- */
-int aul_app_get_running_app_instance_info(aul_app_info_iter_fn iter_fn,
- void *user_data);
-int aul_app_get_running_app_instance_info_for_uid(aul_app_info_iter_fn iter_fn,
- void *user_data, uid_t uid);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_app_get_instance_id_bypid(int pid, char *instance_id, int len);
-int aul_app_get_instance_id_bypid_for_uid(int pid, char *instance_id,
- int len, uid_t uid);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_resume_app_by_instance_id(const char *appid, const char *instance_id);
-int aul_resume_app_by_instance_id_for_uid(const char *appid,
- const char *instance_id, uid_t uid);
-
-/**
- * This API is only for Appfw internally.
- */
-int aul_ignore_app_status(status_listen_h handle);
-
-/**
- * This API is only for Appfw internally.
- */
-int aul_notify_exit(void);
-int aul_notify_start(void);
-
-/**
- * This API is only for App Framework internally.
- */
-const char *aul_app_status_convert_to_string(int status);
-
-/**
- * This API is only for App Framework internally.
- */
-int aul_terminate_instance_async(const char *instance_id, int pid);
-int aul_terminate_instance_async_for_uid(const char *instance_id, int pid,
- uid_t uid);
-
-/**
- * @brief Sends the terminate request.
- * @since_tizen 5.5
- * @privlevel platform
- * @privilege %http://tizen.org/privilege/appmanager.kill
- *
- * @param[in] appid The application ID
- * @param[in] instance_id The instance ID
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_terminate_app_with_instance_id(const char *appid,
- const char *instance_id);
-
-/**
- * @brief Sends the terminate request.
- * @since_tizen 5.5
- * @privlevel platform
- * @privilege %http://tizen.org/privilege/appmanager.kill
- *
- * @param[in] appid The application ID
- * @param[in] instance_id The instance ID
- * @param[in] uid The user ID
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_terminate_app_with_instance_id_for_uid(const char *appid,
- const char *instance_id, uid_t uid);
-
-/**
- * @brief Sends the terminate request.
- * @since_tizen 5.5
- * @privlevel platform
- * @privilege %http://tizen.org/privilege/appmanager.kill
- *
- * @param[in] appid The application ID
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_terminate_app(const char *appid);
-
-/**
- * @brief Sends the terminate request.
- * @since_tizen 5.5
- * @privlevel platform
- * @privilege %http://tizen.org/privilege/appmanager.kill
- *
- * @param[in] appid The application ID
- * @param[in] uid The user ID
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_terminate_app_for_uid(const char *appid, uid_t uid);
-
-/**
- * @brief Checks whether the application is running or not.
- * @since_tizen 5.5
- *
- * @param[in] appid The application ID
- * @param[in] instance_id The instance ID
- * @param[out] running @c true if the instance is running, \n
- * otherwise @c false if not running
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_app_is_running_with_instance_id(const char *appid,
- const char *instance_id, bool *running);
-
-/**
- * @brief Sends a preparation request for an app-defined loader.
- * @since_tizen 5.5
- *
- * @param[in] loader_name The loader name
- * @return @c the loader ID on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_prepare_app_defined_loader(const char *loader_name);
-int aul_prepare_app_defined_loader_for_uid(const char *loader_name, uid_t uid);
-
-/**
- * @remarks This function is only for App Framework internally.
- */
-int aul_status_update_v2(int status);
-
-/**
- * @remarks This function is only for App Framework internally.
- */
-int aul_get_default_app(bundle *b, char **appid);
-
-/**
- * @remarks This function is only for App Framework internally.
- */
-int aul_set_auto_restart(bundle *b);
-
-/**
- * @remarks This function is only for App Framework internally.
- */
-int aul_unset_auto_restart(void);
-
-/**
- * @remarks This function is only for App Framework internally.
- */
-int aul_package_pre_event_send(uid_t uid, bundle *b);
-
-/**
- * @remarks This function is only for App Framework internally.
- */
-int aul_launch_worker_init(void);
-
-/**
- * @remarks This function is only for App Framework internally.
- */
-void aul_launch_worker_fini(void);
-
-/**
- * @brief Called when the application ID is delivered.
- * @since_tizen 8.0
- * @param[in] result The result
- * @param[in] pid The process ID
- * @param[in] appid The application ID
- * @param[in] user_data The user data passed from the regitration function
- * @remarks This function is only for App Framework internally.
- * @see aul_app_get_appid_bypid_async()
- */
-typedef void (*aul_appid_cb)(int result, pid_t pid, const char *appid, void *user_data);
-
-/**
- * @brief Gets the application ID from the process ID.
- * @since_tizen 8.0
- * @param[in] pid The process ID
- * @param[in] callback The callback function
- * @param[in] user_data The user data to be passed to the callaback function
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #AUL_R_OK Successful
- * @retval #AUL_R_EINVAL Invalid parameter
- * @retval #AUL_R_ENOMEM Out of memory
- * @retval #AUL_R_ERROR Internal I/O error
- * @remarks This function is only for App Framework internally.
- * @see aul_appid_cb()
- */
-int aul_app_get_appid_bypid_async(pid_t pid, aul_appid_cb callback, void *user_data);
-
-/**
- * @brief Called when the result is delivered.
- * @since_tizen 8.0
- * @param[in] result The result
- * @param[in] user_data The user data passed from the regitration function
- * @remarks This function is only for App Framework internally.
- */
-typedef void (*aul_result_cb)(int result, void *user_data);
-
-/**
- * @brief Sends the termination request with the process ID.
- * @since_tizen 8.0
- * @privilege %http://tizen.org/privilege/appmanager.kill
- * @privlevel platform
- * @param[in] pid The process ID
- * @param[in] callback The callback function
- * @param[in] user_data The user data to be passed to the callback function
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #AUL_R_OK Successful
- * @retval #AUL_R_EINVAL Invalid parameter
- * @retval #AUL_R_ENOMEM Out of memory
- * @retval #AUL_R_ERROR Internal I/O error
- * @remarks This function is only for App Framework internally.
- * @see aul_result_cb()
- */
-int aul_terminate_pid_async_v2(pid_t pid, aul_result_cb callback, void *user_data);
-
-/**
- * @brief Sends the termination request.
- * @since_tizen 8.0
- * @privilege %http://tizen.org/privilege/appmanager.kill
- * @privlevel platform
- * @param[in] appid The application ID
- * @param[in] callback The callback function
- * @param[in] user_data The user data to be passed to the callback function
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #AUL_R_OK Successful
- * @retval #AUL_R_EINVAL Invalid parameter
- * @retval #AUL_R_ENOMEM Out of memory
- * @retval #AUL_R_ERROR Internal I/O error
- * @remarks This function is only for App Framework internally.
- * @see aul_result_cb()
- */
-int aul_terminate_app_async(const char *appid, aul_result_cb callback, void *user_data);
-
-/**
- * @brief Sends the request to kill the process ID.
- * @since_tizen 8.0
- * @privilege %http://tizen.org/privilege/appmanager.kill
- * @privlevel platform
- * @param[in] pid The process ID
- * @param[in] callback The callback function
- * @param[in] user_data The user data to be passed to the callback function
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #AUL_R_OK Successful
- * @retval #AUL_R_EINVAL Invalid parameter
- * @retval #AUL_R_ENOMEM Out of memory
- * @retval #AUL_R_ERROR Internal I/O error
- * @remarks This function is only for App Framework internally.
- * @see aul_result_cb()
- */
-int aul_kill_pid_async(pid_t pid, aul_result_cb callback, void *user_data);
-
-/**
- * @Brief Called when the reply is delivered from the callee application.
- * @since_tizen 8.0
- * @param[in] b The bundle object
- * @param[in] is_cancel If true, the request was cancelled
- * @param[in] user_data The user data passed from the registration function
- * @remarks This function is only for App Framework internally.
- * @see aul_send_launch_request_for_uid()
- */
-typedef void (*aul_reply_cb)(bundle *b, int is_cancel, void *user_data);
-
-/**
- * @brief Sends the launch request asynchronously.
- * @since_tizen 8.0
- * @privilege %http://tizen.org/privilege/appmanager.launch
- * @privlevel public
- * @param[in] appid The application ID
- * @param[in] b The bundle object
- * @param[in] uid The target user ID
- * @param[in] reply_cb The reply callback function
- * @param[in] result_cb The result callback function
- * @param[in] user_data The user data to be passed to the callback function
- * @retrun @c 0 on success,
- * otherwise a negative error value
- * @retval #AUL_R_OK Successful
- * @retval #AUL_R_EINVAL Invalid parameter
- * @retval #AUL_R_ENOMEM Out of memory
- * @retval #AUL_R_ERROR Internal I/O error
- * @retval #AUL_R_ECOMM Communication error on send
- * @retval #AUL_R_EILLACC Permission denied
- * @remarks This function is only for App Framework internally.
- * @see aul_reply_cb()
- */
-int aul_send_launch_request_for_uid(const char *appid, bundle *b, uid_t uid,
- aul_reply_cb reply_cb, aul_result_cb result_cb, void *user_data);
-
-/**
- * @brief Sends the kill request to the running loader process.
- * @since_tizen 8.0
- * @remarks This function is only available for system and user daemons.
- * @param[in] loader_name The loader name
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #AUL_R_OK Successful
- * @retval #AUL_R_EINVAL Invalid parameter
- * @retval #AUL_R_ECOMM Communication error on send
- * @retval #AUL_R_EILLACC Permission denied
- */
-int aul_kill_loader(const char *loader_name);
-
-/**
- * @brief Sends the kill request to the running loader process.
- * @since_tizen 8.0
- * @remarks This function is only available for system and user daemons.
- * @param[in] loader_name The loader name
- * @param[in] uid The target uid
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #AUL_R_OK Successful
- * @retval #AUL_R_EINVAL Invalid parameter
- * @retval #AUL_R_ECOMM Communication error on send
- * @retval #AUL_R_EILLACC Permission denied
- */
-int aul_kill_loader_for_uid(const char *loader_name, uid_t uid);
-
-/**
- * @brief Sends the restart request to the running loader process.
- * @since_tizen 8.0
- * @details This function is to restart the loader process.
- * If the process is running, it will be terminated and executed.
- * @remarks This function is only available for system and user daemons.
- * @param[in] loader_name The loader name
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #AUL_R_OK Successful
- * @retval #AUL_R_EINVAL Invalid parameter
- * @retval #AUL_R_ECOMM Communication error on send
- * @retval #AUL_R_EILLACC Permission denied
- */
-int aul_restart_loader(const char *loader_name);
-
-/**
- * @brief Sends the restart request to the running loader process.
- * @since_tizen 8.0
- * @details This function is to restart the loader process.
- * If the process is running, it will be terminated and executed.
- * @remarks This function is only available for system and user daemons.
- * @param[in] loader_name The loader name
- * @param[in] uid The target uid
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #AUL_R_OK Successful
- * @retval #AUL_R_EINVAL Invalid parameter
- * @retval #AUL_R_ECOMM Communication error on send
- * @retval #AUL_R_EILLACC Permission denied
- */
-int aul_restart_loader_for_uid(const char *loader_name, uid_t uid);
-
-#ifdef __cplusplus
- }
-#endif
+++ /dev/null
-/*
- * Copyright (c) 2015 - 2021 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __APP_COM_H__
-#define __APP_COM_H__
-
-#include <bundle.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef enum {
- AUL_APP_COM_PUBLIC = 0x0, /* allowed for all */
- AUL_APP_COM_PRIVILEGED = 0x1, /* allowed for given privileged app */
-} aul_app_com_propagate_option_e;
-
-typedef enum {
- AUL_APP_COM_R_ERROR_OK = 0,
- AUL_APP_COM_R_ERROR_UNKNOWN_ENDPOINT = -1,
- AUL_APP_COM_R_ERROR_ENDPOINT_ALREADY_EXISTS = -2,
- AUL_APP_COM_R_ERROR_ILLEGAL_ACCESS = -3,
- AUL_APP_COM_R_ERROR_CLIENT_REMAINING = -4,
- AUL_APP_COM_R_ERROR_OUT_OF_MEMORY = -5,
- AUL_APP_COM_R_ERROR_FATAL_ERROR = -6,
-} aul_app_com_error_e;
-
-typedef enum {
- AUL_APP_COM_R_OK = 0,
- AUL_APP_COM_R_ILLEGAL_ACCESS = -1,
-} aul_app_com_result_e;
-
-typedef void *aul_app_com_permission_h;
-typedef void *aul_app_com_connection_h;
-
-typedef int (*app_com_cb)(const char *endpoint, aul_app_com_result_e result, bundle *envelope, void *user_data);
-
-/**
- * aul_app_com provides publish-subscribe style message for internal AUL use.
- * e.g) widget status propagation, sharing callee app status to caller app
- * @code
-
-static int __handler(const char *endpoint, aul_app_com_result_e result, bundle *envelope, void *user_data)
-{
- _D("endpoint: %s", endpoint);
- _D("result: %d", result);
-
- return 0;
-}
-
-// viewer-side
-aul_app_com_permission_h permission = aul_app_com_permission_create();
-aul_app_com_permission_set_propagation(permission, AUL_APP_COM_PRIVILEGED);
-aul_app_com_permission_set_privilege(permission, "http://tizen.org/privilege/widget.viewer");
-aul_app_com_connection_h connection = NULL;
-aul_app_com_create("widget.status", permission, __handler, NULL, &connection);
-
-
-// widget-side
-bundle *b = bundle_create();
-bundle_add_str(b, "WIDGET_ID", "org.example.widget");
-bundle_add_str(b, "STATUS", "RUNNING");
-aul_app_com_send("widget.status", b);
-bundle_free(b);
-
-
-// monitor-side
-static int __handler(const char *endpoint, aul_app_com_result_e result, bundle *envelope, void *user_data)
-{
- const char *widget_id = bundle_get_val(envelope, "WIDGET_ID");
- const char *status = bundle_get_val(envelope, "STATUS");
-
- _D("%s is %s", widget_id, status);
-
- return 0;
-}
-
-aul_app_com_connection_h connection = NULL;
-aul_app_com_join("widget.status", NULL, __handler, NULL, &connection);
-
- */
-
-aul_app_com_permission_h aul_app_com_permission_create();
-void aul_app_com_permission_destroy(aul_app_com_permission_h permission);
-int aul_app_com_permission_set_propagation(aul_app_com_permission_h permission, aul_app_com_propagate_option_e option);
-int aul_app_com_permission_set_privilege(aul_app_com_permission_h permission, const char *privilege);
-
-int aul_app_com_create(const char *endpoint, aul_app_com_permission_h permission, app_com_cb callback, void *user_data, aul_app_com_connection_h *connection);
-int aul_app_com_join(const char *endpoint, const char *filter, app_com_cb callback, void *user_data, aul_app_com_connection_h *connection);
-int aul_app_com_leave(aul_app_com_connection_h connection);
-int aul_app_com_send(const char *endpoint, bundle *envelope);
-
-int aul_app_com_create_async(const char *endpoint,
- aul_app_com_permission_h permission,
- app_com_cb callback,
- void *user_data,
- aul_app_com_connection_h *connection);
-
-#ifdef __cplusplus
-}
-#endif
-
-#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_APP_GROUP_H__
-#define __AUL_APP_GROUP_H__
-
-#include <stdbool.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @brief The AUL application group information handle.
- * @since_tizen 5.5
- */
-typedef struct aul_app_group_info_s *aul_app_group_info_h;
-
-typedef void (*aul_app_group_leader_id_cb)(const char *leader_id, void* user_data);
-
-typedef void (*aul_app_group_info_cb)(aul_app_group_info_h info, void *user_data);
-
-/**
- * @brief Gets the ID.
- * @since_tizen 5.5
- * @remarks You should not release @a appid by using free().
- *
- * @param[in] h The app group info handle
- * @param[out] id The ID
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_app_group_info_get_id(aul_app_group_info_h h, const char **id);
-
-/**
- * @brief Gets the process ID.
- * @since_tizen 5.5
- *
- * @param[in] h The app group info handle
- * @param[out] pid The process ID
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_app_group_info_get_pid(aul_app_group_info_h h, pid_t *pid);
-
-/**
- * @brief Gets the application ID.
- * @since_tizen 5.5
- * @remarks You should not release @a appid by using free().
- *
- * @param[in] h The app group info handle
- * @param[out] appid The application ID
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_app_group_info_get_appid(aul_app_group_info_h h, const char **appid);
-
-/**
- * @brief Gets the package ID.
- * @since_tizen 5.5
- * @remarks You should not release @a appid by using free().
- *
- * @param[in] h The app group info handle
- * @param[out] pkgid The package ID
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_app_group_info_get_pkgid(aul_app_group_info_h h, const char **pkgid);
-
-/**
- * @brief Gets the window ID.
- * @since_tizen 5.5
- *
- * @param[in] h The app group info handle
- * @param[out] wid The window ID
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_app_group_info_get_window(aul_app_group_info_h h, int *wid);
-
-/**
- * @brief Gets the flag that the group is running foreground.
- * @since_tizen 5.5
- *
- * @param[in] h The app group info handle
- * @param[out] fg_flag The flag of the foreground
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_app_group_info_get_fg_flag(aul_app_group_info_h h, bool *fg_flag);
-
-/**
- * @brief Gets the status of the instance.
- * @since_tizen 5.5
- *
- * @param[in] h The app group info handle
- * @param[out] status The status
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_app_group_info_get_status(aul_app_group_info_h h, int *status);
-
-/**
- * @brief Retrieves the leader instances.
- * @since_tizen 5.5
- *
- * @param[in] callback The callback function
- * @param[in] user_data The user data to be passed the callback function
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_app_group_foreach_leader_ids(aul_app_group_leader_id_cb callback,
- void *user_data);
-
-/**
- * @brief Retrieves the group instances.
- * @since_tizen 5.5
- *
- * @param[in] leader_id The leader ID of the app group.
- * @param[in] callback The callback function
- * @param[in] user_data The user data to be passed the callback function
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_app_group_foreach_group_info(const char *leader_id,
- aul_app_group_info_cb callback, void *user_data);
-
-/**
- * @brief Retrieves the idle instances.
- * @since_tizen 5.5
- *
- * @param[in] callback The callback function
- * @param[in] user_data The user data to be passed the callback function
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_app_group_foreach_idle_info(aul_app_group_info_cb callback,
- void *user_data);
-
-/**
- * @brief Sets the window.
- * @since_tizen 5.5
- *
- * @param[in] id The instance ID
- * @param[in] wid The window(surface) ID
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_app_group_set_window_v2(const char *id, int wid);
-
-/**
- * @brief Lowers the window.
- * @since_tizen 5.5
- *
- * @param[in] id The instance ID
- * @param[out] exit The flag if it's 'true', the instance should be terminated
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_app_group_lower_v2(const char *id, bool *exit);
-
-/**
- * @brief Adds a new app group to the app group.
- * @details A new app group will be added using the given window ID.
- * @since_tizen 6.0
- *
- * @param[in] wid The window(surface) ID
- * @return @c 0 on success,
- * otherwise a negatvie error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_app_group_add(int wid);
-
-/**
- * @brief Removes the app group using the given window ID.
- * @since_tizen 6.0
- *
- * @param[in] wid The window(surface) ID
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_app_group_remove(int wid);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __AUL_APP_GROUP_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#pragma once
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-enum app_cmd {
- APP_START = 0,
-
- APP_OPEN = 1,
- APP_RESUME = 2,
- APP_RESUME_BY_PID = 3,
- APP_TERM_BY_PID = 4,
- APP_TERM_BY_PID_WITHOUT_RESTART = 5,
- APP_RESULT = 6,
- APP_START_RES = 7,
- APP_CANCEL = 8,
- APP_KILL_BY_PID = 9,
- APP_UPDATE_RUA_STAT = 10,
-
- APP_ADD_HISTORY = 11,
- APP_REMOVE_HISTORY = 12,
- APP_RUNNING_INFO = 13,
- APP_RUNNING_INFO_RESULT = 14,
- APP_IS_RUNNING = 15,
- APP_GET_APPID_BYPID = 16,
- APP_GET_PKGID_BYPID = 17,
- APP_GET_INFO_OK = 18,
- APP_GET_INFO_ERROR = 19,
- APP_KEY_EVENT = 20, /**< Unused */
-
- APP_KEY_RESERVE = 21, /**< Unused */
- APP_KEY_RELEASE = 22, /**< Unused */
- APP_STATUS_UPDATE = 23,
- APP_RUNNING_LIST_UPDATE = 24,
- APP_TERM_REQ_BY_PID = 25,
- APP_TERM_BY_PID_ASYNC = 26,
- APP_TERM_BGAPP_BY_PID = 27,
- APP_PAUSE = 28,
- APP_PAUSE_BY_PID = 29,
- APP_GROUP_GET_WINDOW = 30,
-
- APP_GROUP_SET_WINDOW = 31,
- APP_GROUP_GET_FG = 32,
- APP_GROUP_GET_LEADER_PID = 33,
- APP_GROUP_GET_LEADER_PIDS = 34,
- APP_GROUP_GET_GROUP_PIDS = 35,
- APP_GROUP_GET_IDLE_PIDS = 36,
- APP_GROUP_LOWER = 37,
- APP_GROUP_CLEAR_TOP = 38,
- APP_GROUP_ACTIVATE_BELOW = 39,
- APP_GET_STATUS = 40,
-
- APP_ADD_LOADER = 41,
- APP_REMOVE_LOADER = 42,
- APP_GET_PID = 43,
- APP_GET_DC_SOCKET_PAIR = 44,
- APP_GET_MP_SOCKET_PAIR = 45,
- APP_COM_CREATE = 46,
- APP_COM_JOIN = 47,
- APP_COM_SEND = 48,
- APP_COM_LEAVE = 49,
- APP_COM_MESSAGE = 50,
-
- WIDGET_ADD = 51,
- WIDGET_DEL = 52,
- WIDGET_LIST = 53,
- WIDGET_UPDATE = 54,
- WIDGET_COUNT = 55,
- WIDGET_GET_CONTENT = 56,
- APP_REGISTER_PID = 57,
- APP_WAKE = 58,
- APP_SUSPEND = 59,
- AMD_RELOAD_APPINFO = 60,
-
- LAUNCHPAD_DEAD_SIGNAL = 61,
- APP_ALL_RUNNING_INFO = 62,
- APP_SET_APP_CONTROL_DEFAULT_APP = 63,
- APP_UNSET_APP_CONTROL_DEFAULT_APP = 64,
- APP_START_ASYNC = 65,
- APP_SET_PROCESS_GROUP = 66,
- APP_PREPARE_CANDIDATE_PROCESS = 67,
- APP_TERM_BY_PID_SYNC = 68,
- APP_GET_STATUS_BY_APPID = 69,
- APP_GET_LAST_CALLER_PID = 70,
-
- APP_TERM_BY_PID_SYNC_WITHOUT_RESTART = 71,
- APP_RESUME_BY_PID_ASYNC = 72,
- APP_SET_ALIAS_APPID = 73,
- APP_UNSET_ALIAS_APPID = 74,
- APP_ENABLE_ALIAS_INFO = 75,
- APP_DISABLE_ALIAS_INFO = 76,
- APP_GROUP_ACTIVATE_ABOVE = 77,
- ADD_APP_SCREEN = 78,
- REMOVE_APP_SCREEN = 79,
- APP_UPDATE_REQUESTED = 80,
-
- ADD_SCREEN_VIEWER = 81,
- REMOVE_SCREEN_VIEWER = 82,
- LAUNCHPAD_LAUNCH_SIGNAL = 83,
- APP_RUNNING_INSTANCE_INFO = 84,
- APP_GET_INSTANCE_ID_BYPID = 85,
- APP_SET_CACHE = 86,
- APP_GET_APPID_FROM_CACHE = 87,
- APP_INVALIDATE_CACHE = 88,
- APP_STARTUP_SIGNAL = 89,
- APP_WINDOW_ATTACH = 90,
-
- APP_WINDOW_DETACH = 91,
- APP_START_RES_ASYNC = 92,
- APP_NOTIFY_EXIT = 93,
- APP_GET_APPID_BY_SURFACE_ID = 94,
- APP_GET_INSTANCE_ID_BY_SURFACE_ID = 95,
- UPDATE_SCREEN_VIEWER_STATUS = 96,
- WIDGET_RUNNING_INFO = 97,
- JOB_STATUS_UPDATE = 98,
- WIDGET_CHANGE_STATUS = 99,
- RPC_PORT_PREPARE_STUB = 100,
-
- RPC_PORT_CREATE_SOCKET_PAIR = 101,
- RPC_PORT_NOTIFY_RPC_FINISHED = 102,
- COMPLICATION_UPDATE_REQUEST = 103,
- APP_NOTIFY_START = 104,
- WATCHDOG_ENABLE = 105,
- WATCHDOG_DISABLE = 106,
- WATCHDOG_PING = 107,
- WATCHDOG_KICK = 108,
- APP_SEND_LAUNCH_REQUEST = 109,
- APP_SEND_LAUNCH_REQUEST_SYNC = 110,
-
- COMP_NOTIFY_START = 111,
- COMP_NOTIFY_EXIT = 112,
- COMP_STATUS_UPDATE = 113,
- APP_TERM_INSTANCE_ASYNC = 114,
- APP_GROUP_SET_WINDOW_V2 = 115,
- APP_GROUP_LOWER_V2 = 116,
- APP_GROUP_GET_LEADER_IDS = 117,
- APP_GROUP_GET_GROUP_INFO = 118,
- APP_GROUP_GET_IDLE_INFO = 119,
- COMP_CONTEXT_FOREACH = 120,
-
- COMP_CONTEXT_GET = 121,
- COMP_CONTEXT_IS_RUNNING = 122,
- COMP_CONTEXT_RESUME = 123,
- COMP_CONTEXT_PAUSE = 124,
- COMP_CONTEXT_TERMINATE_BG_COMP = 125,
- COMP_CONTEXT_TERMINATE = 126,
- APP_RESUME_INSTANCE = 127,
- APP_PAUSE_INSTANCE = 128,
- APP_TERM_BG_INSTANCE = 129,
- LAUNCHPAD_CHILD_PROCESS = 130, /* unused */
-
- COMP_INFO_GET = 131,
- COMP_INFO_FOREACH = 132,
- APP_TERMINATE = 133,
- APP_IS_RUNNING_V2 = 134,
- ANR_NOTIFY = 135,
- APP_GET_RUNNING_CONTEXT = 136,
- LAUNCHER_SERVICE_NOTIFY_ANIMATION_STARTED = 137,
- LAUNCHER_SERVICE_NOTIFY_ANIMATION_FINISHED = 138,
- APP_SEND_RESUME_REQUEST = 139,
- APP_PREPARE_APP_DEFINED_LOADER = 140,
-
- WIDGET_DISABLE = 141,
- TRIGGER_APP_SCREEN_FOCUSED_FORCE = 142,
- WIDGET_EVENT = 143,
- SET_PRIVATE_SHARING = 144,
- UNSET_PRIVATE_SHARING = 145,
- APP_CONTEXT_GET = 146,
- APP_CONTEXT_GET_BY_INSTANCE_ID = 147,
- APP_CONTEXT_GET_BY_PID = 148,
- APP_GROUP_ADD = 149,
- APP_GROUP_REMOVE = 150,
-
- APP_GET_APPID_LIST = 151,
- COMP_PORT_EXIST = 152,
- COMP_PORT_CREATE = 153,
- COMP_PORT_DESTROY = 154,
- APP_LIFECYCLE_UPDATE_STATE = 155,
-
- APP_STATUS_UPDATE_V2 = 156,
- APP_GET_APP_CONTROL_DEFAULT_APPS = 157,
- APP_GET_APPID_BY_ALIAS_APPID = 158,
- APP_GET_APP_CONTROL_DEFAULT_APP = 159,
- APP_LIFECYCLE_GET_STATE = 160,
-
- PROC_REGISTER = 161,
- PROC_DEREGISTER = 162,
- PROC_GET_NAME = 163,
- PROC_GET_EXTRA = 164,
- RPC_PORT_CREATE = 165,
-
- RPC_PORT_DESTROY = 166,
- RPC_PORT_EXIST = 167,
- APP_WINDOW_ATTACH_BELOW = 168,
- PROC_GROUP_ADD = 169,
- PROC_GROUP_REMOVE = 170,
-
- APP_CONNECT = 171,
- APP_SET_AUTO_RESTART = 172,
- BOOT_SEQUENCE_START_APP = 173,
- BOOT_SEQUENCE_GET_APPINFO_LIST = 174,
- BOOT_SEQUENCE_RELOAD = 175,
-
- PKG_PRE_EVENT_SEND = 176,
- PROC_GROUP_FOREACH = 177,
- PROC_GROUP_GET = 178,
-
- APP_CMD_MAX
-};
-
-const char *aul_cmd_convert_to_string(int cmd);
-
-#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.
- */
-
-#pragma once
-
-#include <unistd.h>
-#include <stdbool.h>
-
-#include <aul.h>
-#include <aul_comp_types.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @brief The component context handle.
- * @since_tizen 5.5
- */
-typedef struct aul_comp_context_s *aul_comp_context_h;
-
-/**
- * @brief Called to get the component context for each component.
- * @since_tizen 5.5
- * @remarks You MUST NOT release @a handle using aul_comp_context_destroy().
- *
- * @param[in] handle The component context handle
- * @param[in] user_data The user data passed from the foreach function
- * @return @c true to continue with the next iteration of the loop, \n
- * otherwise @ false to break out of the loop
- * @see aul_comp_context_foreach_comp_context()
- */
-typedef bool (*aul_comp_context_cb)(aul_comp_context_h handle, void *user_data);
-
-/**
- * @brief Retrieves all running components context.
- * @since_tizen 5.5
- * @privlevel public
- * @privilege %http://tizen.org/privilege/packagemanager.info
- *
- * @param[in] callback The callback function to invoke
- * @param[in] user_data The user data to be passed to the callback function
- * @return @c 0 on success,
- * otherwise a negative error value
- * @see aul_comp_context_cb()
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_comp_context_foreach_comp_context(aul_comp_context_cb callback,
- void *user_data);
-
-/**
- * @brief Gets the application ID of the component.
- * @since_tizen 5.5
- * @remarks You MUST NOT release @a app_id using free().
- *
- * @param[in] handle The component context handle
- * @param[out] app_id The application ID of the component
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_comp_context_get_app_id(aul_comp_context_h handle, const char **app_id);
-
-/**
- * @brief Gets the instance ID of the component.
- * @since_tizen 5.5
- * @remarks You MUST NOT release @a app_id using free().
- *
- * @param[in] handle The component context handle
- * @param[out] instance_id The instance ID of the component
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_comp_context_get_instance_id(aul_comp_context_h handle,
- const char **instance_id);
-
-/**
- * @brief Gets the ID of the component.
- * @since_tizen 5.5
- * @remarks You MUST NOT release @a comp_id using free().
- *
- * @param[in] handle The component context handle
- * @param[out] comp_id The ID of the component
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_comp_context_get_comp_id(aul_comp_context_h handle,
- const char **comp_id);
-
-/**
- * @brief Gets the type of the component.
- * @since_tizen 5.5
- * @remarks You MUST NOT release @a type using free().
- *
- * @param[in] handle The component context handle
- * @param[out] type The type of the component
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_comp_context_get_type(aul_comp_context_h handle, const char **type);
-
-/**
- * @brief Gets the process ID of the component.
- * @since_tizen 5.5
- *
- * @param[in] handle The component context handle
- * @param[out] pid The process ID of the component
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_comp_context_get_pid(aul_comp_context_h handle, pid_t *pid);
-
-/**
- * @brief Gets the status of the component.
- * @since_tizen 5.5
- *
- * @param[in] handle The component context handle
- * @param[out] status The status of the component
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @see comp_status_e
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_comp_context_get_status(aul_comp_context_h handle, int *status);
-
-/**
- * @brief Checks whether the component is sub component of the app group or not.
- * @since_tizen 5.5
- *
- * @param[in] handle The component context handle
- * @param[out] is_sub_comp @c true if the component is sub component, \n
- * otherwise @c false
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_comp_context_is_sub_comp(aul_comp_context_h handle, bool *is_sub_comp);
-
-/**
- * @brief Creates the component context handle.
- * @since_tizen 5.5
- * @privlevel public
- * @privilege %http://tizen.org/privilege/packagemanager.info
- * @remarks You MUST release @c clone using aul_comp_context_destroy().
- *
- * @param[in] comp_id The component ID
- * @param[out] handle The component context handle
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- * @see aul_comp_context_destroy()
- */
-int aul_comp_context_create(const char *comp_id, aul_comp_context_h *handle);
-
-/**
- * @brief Creates the component context handle.
- * @since_tizen 5.5
- * @privlevel public
- * @privilege %http://tizen.org/privilege/packagemanager.info
- * @remarks You MUST release @c clone using aul_comp_context_destroy().
- *
- * @param[in] comp_id The component ID
- * @parma[in] uid The user ID
- * @param[out] handle The component context handle
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- * @see aul_comp_context_destroy()
- */
-int aul_comp_context_usr_create(const char *comp_id, uid_t uid,
- aul_comp_context_h *handle);
-
-/**
- * @brief Destroys the component context handle.
- * @since_tizen 5.5
- *
- * @param[in] handle The component context handle
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_comp_context_destroy(aul_comp_context_h handle);
-
-/**
- * @brief Clones the component context handle.
- * @since_tizen 5.5
- * @remarks You MUST release @c clone using aul_comp_context_destroy().
- *
- * @param[in] handle The component context handle
- * @param[out] clone A newly created component context handle, if sucessfully cloned
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- * @see aul_comp_context_destroy()
- */
-int aul_comp_context_clone(aul_comp_context_h handle,
- aul_comp_context_h *clone);
-
-/**
- * @brief Checks whether the component is running or not.
- * @since_tizen 5.5
- *
- * @param[in] handle The component context handle
- * @param[out] running @c true if the component is running, \n
- * otherwise @c false if not running
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_comp_context_is_running(aul_comp_context_h handle, bool *running);
-
-/**
- * @brief Sends the request for resuming the component.
- * @since_tizen 5.5
- * @privlevel public
- * @privilege %http://tizen.org/privilege/appmanager.launch
- *
- * @param[in] handle The component context handle
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_comp_context_resume(aul_comp_context_h handle);
-
-/**
- * @brief Sends the request for pausing the component.
- * @since_tizen 5.5
- * @privlevel public
- * @privilege %http://tizen.org/privilege/appmanager.launch
- *
- * @param[in] handle The component context handle
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_comp_context_pause(aul_comp_context_h handle);
-
-/**
- * @brief Sends the request for terminating the background component.
- * @since_tizen 5.5
- * @privlevel public
- * @privilege %http://tizen.org/privilege/appmanager.kill.bgapp
- *
- * @param[in] handle The component context handle
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_comp_context_terminate_bg_comp(aul_comp_context_h handle);
-
-/**
- * @brief Sends the request for terminating the running component.
- * @since_tizen 5.5
- * @privlevel platform
- * @privilege %http://tizen.org/privilege/appmanager.kill
- *
- * @param[in] handle The component context handle
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_comp_context_terminate(aul_comp_context_h handle);
-
-#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.
- */
-
-#pragma once
-
-#include <unistd.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @brief The component information handle.
- * @since_tizen 5.5
- */
-typedef void *aul_comp_info_h;
-
-/**
- * @brief Called to get the component information once for each installed component.
- * @since_tizen 5.5
- *
- * @param[in] handle The component information handle
- * @param[in] user_data The user data passed from the foreach function
- * @return @c true to continue with the next iteration of the loop, \n
- * otherwise @ false to break out of the loop
- * @see aul_comp_info_foreach_comp_info()
- * @see aul_comp_info_usr_foreach_comp_info()
- */
-typedef bool (*aul_comp_info_cb)(aul_comp_info_h handle, void *user_data);
-
-/**
- * @brief Creates the component information handle.
- * @since_tizen 5.5
- * @privlevel public
- * @privilege %http://tizen.org/privilege/packagemanager.info
- * @remarks You MUST release @a handle using aul_comp_info_destroy().
- *
- * @param[in] comp_id The component ID
- * @param[out] handle The component information handle
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_comp_info_create(const char *comp_id, aul_comp_info_h *handle);
-
-/**
- * @brief Creates the component information handle.
- * @since_tizen 5.5
- * @privlevel public
- * @privilege %http://tizen.org/privilege/packagemanager.info
- * @remarks You MUST release @a handle using aul_comp_info_destroy().
- *
- * @param[in] comp_id The component ID
- * @param[in] uid The user ID
- * @param[out] handle The component information handle
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_comp_info_usr_create(const char *comp_id, uid_t uid,
- aul_comp_info_h *handle);
-
-/**
- * @brief Destroys the component information handle.
- * @since_tizen 5.5
- *
- * @param[in] handle The component information handle
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_comp_info_destroy(aul_comp_info_h handle);
-
-/**
- * @brief Clones the component information handle.
- * @since_tizen 5.5
- * @remarks You MUST release @a clone using aul_comp_info_destroy().
- *
- * @param[in] handle The component information handle
- * @param[out] clone A newly created component information handle, if successfully cloned
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_comp_info_clone(aul_comp_info_h handle, aul_comp_info_h *clone);
-
-/**
- * @brief Gets the application ID of the component.
- * @since_tizen 5.5
- * @remarks You MUST NOT release @a app_id using free().
- *
- * @param[in] handle The component information handle
- * @param[out] app_id The application ID of the component
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_comp_info_get_app_id(aul_comp_info_h handle, const char **app_id);
-
-/**
- * @brief Gets the ID of the component.
- * @since_tizen 5.5
- * @remarks You MUST NOT release @a comp_id using free().
- *
- * @param[in] handle The component information handle
- * @param[out] comp_id The ID of the component
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_comp_info_get_comp_id(aul_comp_info_h handle, const char **comp_id);
-
-/**
- * @brief Gets the type of the component.
- * @since_tizen 5.5
- * @remarks You MUST NOT release @a type using free().
- *
- * @param[in] handle The component information handle
- * @param[out] type The type of the component
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_comp_info_get_type(aul_comp_info_h handle, const char **type);
-
-/**
- * @brief Gets the launch mode of the component.
- * @since_tizen 5.5
- * @remarks You MUST NOT release @a launch_mode using free().
- *
- * @param[in] handle The component information handle
- * @param[out] launch_mode The launch mode of the component
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_comp_info_get_launch_mode(aul_comp_info_h handle,
- const char **launch_mode);
-
-/**
- * @brief Checks whether the component is the main component or not.
- * @since_tizen 5.5
- *
- * @param[in] handle The component information handle
- * @param[out] main_comp @c true if the component is the main component, \n
- * otherwise @c false
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_comp_info_is_main_comp(aul_comp_info_h handle, bool *main_comp);
-
-/**
- * @brief Checks whether the icon of the component should be displayed or not.
- * @since_tizen 5.5
- *
- * @param[in] handle The component information handle
- * @param[out] icon_display @c true if the icon should be displayed, \n
- * otherwise @c false
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_comp_info_is_icon_display(aul_comp_info_h handle, bool *icon_display);
-
-/**
- * @brief Checks whether the component should be managed by task-manager or not.
- * @since_tizen 5.5
- *
- * @param[in] handle The component information handle
- * @param[out] taskmanage @c true if the component should be managed by task-manager, \n
- * otherwise @c false
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_comp_info_is_taskmanage(aul_comp_info_h handle, bool *taskmanage);
-
-/**
- * @brief Gets the icon path of the component.
- * @since_tizen 5.5
- * @remarks You MUST NOT release @a icon using free().
- *
- * @param[in] handle The component information handle
- * @param[out] icon The icon path of the component
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_comp_info_get_icon(aul_comp_info_h handle, const char **icon);
-
-/**
- * @brief Gets the label of the component.
- * @since_tizen 5.5
- * @remarks You MUST NOT release @a label using free().
- *
- * @param[in] handle The component information handle
- * @param[out] label The label of the component
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_comp_info_get_label(aul_comp_info_h handle, const char **label);
-
-/**
- * @brief Gets the localed label of the component.
- * @since_tizen 5.5
- * @remarks You MUST release @a label using free().
- *
- * @param[in] comp_id The component ID
- * @param[in] locale The locale information
- * @param[out] label The localed label of the component
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_comp_info_get_localed_label(aul_comp_info_h handle, const char *locale,
- const char **label);
-
-/**
- * @brief Retrieves all installed components information of the specified application.
- * @since_tizen 5.5
- * @privlevel public
- * @privilege %http://tizen.org/privilege/packagemanager.info
- *
- * @param[in] app_id The application ID
- * @param[in] callback The callback function to invoke
- * @param[in] user_data The user data to be passed to the callback function
- * @return @c 0 on success,
- * otherwise a negative error value
- * @see aul_comp_info_cb()
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_comp_info_foreach_comp_info_from_app(const char *app_id,
- aul_comp_info_cb callback, void *user_data);
-
-/**
- * @brief Retrieves all installed components information of the specified application.
- * @since_tizen 5.5
- * @privlevel public
- * @privilege %http://tizen.org/privilege/packagemanager.info
- *
- * @param[in] app_id The application ID
- * @param[in] uid The user ID
- * @param[in] callback The callback function to invoke
- * @param[in] user_data The user data to be passed to the callback function
- * @return @c 0 on success,
- * otherwise a negative error value
- * @see aul_comp_info_cb()
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_comp_info_usr_foreach_comp_info_from_app(const char *app_id, uid_t uid,
- aul_comp_info_cb callback, void *user_data);
-
-/**
- * @brief Retrieves all installed components information.
- * @since_tizen 5.5
- * @privlevel public
- * @privilege %http://tizen.org/privilege/packagemanager.info
- *
- * @param[in] callback The callback function to invoke
- * @param[in] user_data The user data to be passed to the callback function
- * @return @c 0 on success,
- * otherwise a negative error value
- * @see aul_comp_info_cb()
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_comp_info_foreach_comp_info(aul_comp_info_cb callback, void *user_data);
-
-/**
- * @brief Retrieves all installed components information.
- * @since_tizen 5.5
- * @privlevel public
- * @privilege %http://tizen.org/privilege/packagemanager.info
- *
- * @param[in] uid The user ID
- * @param[in] callback The callback function to invoke
- * @param[in] user_data The user data to be passed to the callback function
- * @return @c 0 on success,
- * otherwise a negative error value
- * @see aul_comp_info_cb()
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_comp_info_usr_foreach_comp_info(uid_t uid, aul_comp_info_cb callback,
- void *user_data);
-
-#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.
- */
-
-#pragma once
-
-#include <aul.h>
-#include <aul_comp_types.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @brief Updates a status of a component.
- * @since_tizen 5.5
- *
- * @param[in] instance_id The instance ID
- * @param[in] status The status
- *
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_comp_status_update(const char *instance_id, int status);
-
-/**
- * @brief Notifies that a component is starting.
- * @since_tizen 5.5
- *
- * @param[in] instance_id The instance ID
- *
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_comp_notify_start(const char *instance_id);
-
-/**
- * @brief Notifies that a component is exiting.
- * @since_tizen 5.5
- *
- * @param[in] instance_id The instance ID
- *
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_comp_notify_exit(const char *instance_id);
-
-/**
- * @brief Sends the resume request.
- * @since_tizen 5.5
- * @privlevel public
- * @privilege %http://tizen.org/privilege/appmanager.launch
- *
- * @param[in] instance_id The instance ID
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_comp_resume(const char *instance_id);
-
-/**
- * @brief Sends the terminate request.
- * @since_tizen 5.5
- * @privlevel platform
- * @privilege %http://tizen.org/privilege/appmanager.kill
- *
- * @param[in] instance_id The instance ID
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_comp_terminate(const char *instance_id);
-
-/**
- * @brief Checks whether the instance of the component is running or not.
- * @since_tizen 5.5
- *
- * @param[in] instance_id The instance ID
- * @param[out] running @c true if the instance is running, \n
- * otherwise @c false if not running
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_comp_is_running(const char *instance_id, bool *running);
-
-#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.
- */
-
-#pragma once
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @brief Enumeration for component status.
- * @since_tizen 5.5
- */
-typedef enum {
- COMP_STATUS_INITIALIZED, /**< Initialized status */
- COMP_STATUS_CREATED, /**< Created status */
- COMP_STATUS_STARTED, /**< Started status */
- COMP_STATUS_RESUMED, /**< Resumed status */
- COMP_STATUS_PAUSED, /**< Paused status */
- COMP_STATUS_DESTROYED, /**< Destroyed status */
-} comp_status_e;
-
-#ifdef __cplusplus
-}
-#endif
+++ /dev/null
-/*
- * Copyright (c) 2018 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_COMPLICATION_H__
-#define __AUL_COMPLICATION_H__
-
-#include <sys/types.h>
-#include <aul.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int aul_complication_update_request(const char *appid,
- const char *provider_appid, uid_t uid);
-
-int aul_complication_launch_with_extra_data(const char *appid,
- const char *provider_appid, uid_t uid,
- const char *key, const char *value);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __AUL_COMPLICATION_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2018 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_DEBUG_INFO_H__
-#define __AUL_DEBUG_INFO_H__
-
-#include <bundle.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @brief Initializes debug information.
- *
- * @return @c 0 on success,
- * otherwise a negative error value
- */
-int aul_debug_info_init(void);
-
-/**
- * @brief Finalizes debug information.
- *
- * @return @c 0 on success,
- * otherwise a negative error value
- */
-int aul_debug_info_fini(void);
-
-/**
- * @breif Sets the debug information into the bundle object.
- *
- * @param[in] src The bundle object
- * @param[in] dst The bundle object
- *
- * @return @c 0 on success,
- * otherwise a negative error value
- */
-int aul_debug_info_set(bundle *src, bundle *dst);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __AUL_DEBUG_INFO_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2016 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_ERROR_H__
-#define __AUL_ERROR_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_error_convert(int res);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __AUL_ERROR_H__ */
+++ /dev/null
-/*
- * Copyright (c) 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
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define AUL_K_JOB_ID "__AUL_JOB_ID__"
-#define AUL_K_JOB_STATUS "__AUL_JOB_STATUS__"
-#define AUL_K_JOB_REAL_ID "__AUL_JOB_REAL_ID__"
-
-#define AUL_K_JOB_PERIODIC "__AUL_JOB_PERIODIC__"
-#define AUL_K_JOB_PERSISTENT "__AUL_JOB_PERSISTENT__"
-#define AUL_K_JOB_IS_ONCE "__AUL_JOB_IS_ONCE__"
-
-#define AUL_K_JOB_REQ_TIMEOUT "__AUL_JOB_REQ_TIMEOUT__"
-#define AUL_K_JOB_REQ_BATTERY_NOT_LOW "__AUL_JOB_REQ_BATTERY_NOT_LOW__"
-#define AUL_K_JOB_REQ_CHARGING "__AUL_JOB_REQ_CHARGING__"
-#define AUL_K_JOB_REQ_WIFI_CONNECTION "__AUL_JOB_REQ_WIFI_CONNECTION__"
-
-#define AUL_K_JOB_TRIG_BATTERY_LEVEL_EMPTY \
- "__AUL_JOB_TRIG_BATTERY_LEVEL_EMPTY__"
-#define AUL_K_JOB_TRIG_BATTERY_LEVEL_CRITICAL \
- "__AUL_JOB_TRIG_BATTERY_LEVEL_CRITICAL__"
-#define AUL_K_JOB_TRIG_BATTERY_LEVEL_LOW \
- "__AUL_JOB_TRIG_BATTERY_LEVEL_LOW__"
-#define AUL_K_JOB_TRIG_BATTERY_LEVEL_HIGH \
- "__AUL_JOB_TRIG_BATTERY_LEVEL_HIGH__"
-#define AUL_K_JOB_TRIG_CHARGER_STATE_CONNECTED \
- "__AUL_JOB_TRIG_CHARGER_STATE_CONNECTED__"
-#define AUL_K_JOB_TRIG_CHARGER_STATE_DISCONNECTED \
- "__AUL_JOB_TRIG_CHARGER_STATE_DISCONNECTED__"
-#define AUL_K_JOB_TRIG_DISPLAY_STATE_ON \
- "__AUL_JOB_TRIG_DISPLAY_STATE_ON__"
-#define AUL_K_JOB_TRIG_DISPLAY_STATE_OFF \
- "__AUL_JOB_TRIG_DISPLAY_STATE_OFF__"
-#define AUL_K_JOB_TRIG_DISPLAY_STATE_DIM \
- "__AUL_JOB_TRIG_DISPLAY_STATE_DIM__"
-#define AUL_K_JOB_TRIG_EARJACK_STATE_CONNECTED \
- "__AUL_JOB_TRIG_EARJACK_STATE_CONNECTED__"
-#define AUL_K_JOB_TRIG_EARJACK_STATE_DISCONNECTED \
- "__AUL_JOB_TRIG_EARJACK_STATE_DISCONNECTED__"
-#define AUL_K_JOB_TRIG_GPS_STATE_DISABLED \
- "__AUL_JOB_TRIG_GPS_STATE_DISABLED__"
-#define AUL_K_JOB_TRIG_GPS_STATE_SEARCHING \
- "__AUL_JOB_TRIG_GPS_STATE_SEARCHING__"
-#define AUL_K_JOB_TRIG_GPS_STATE_CONNECTED \
- "__AUL_JOB_TRIG_GPS_STATE_CONNECTED__"
-#define AUL_K_JOB_TRIG_POWERSAVE_MODE_ENABLED \
- "__AUL_JOB_TRIG_POWERSAVE_MODE_ENABLED__"
-#define AUL_K_JOB_TRIG_POWERSAVE_MODE_DISABLED \
- "__AUL_JOB_TRIG_POWERSAVE_MODE_DISABLED__"
-#define AUL_K_JOB_TRIG_USB_STATE_CONNECTED \
- "__AUL_JOB_TRIG_USB_STATE_CONNECTED__"
-#define AUL_K_JOB_TRIG_USB_STATE_DISCONNECTED \
- "__AUL_JOB_TRIG_USB_STATE_DISCONNECTED__"
-#define AUL_K_JOB_TRIG_WIFI_STATE_DISABLED \
- "__AUL_JOB_TRIG_WIFI_STATE_DISABLED__"
-#define AUL_K_JOB_TRIG_WIFI_STATE_DISCONNECTED \
- "__AUL_JOB_TRIG_WIFI_STATE_DISCONNECTED__"
-#define AUL_K_JOB_TRIG_WIFI_STATE_CONNECTED \
- "__AUL_JOB_TRIG_WIFI_STATE_CONNECTED__"
-
-typedef enum {
- JOB_STATUS_START,
- JOB_STATUS_STOPPED,
- JOB_STATUS_FINISHED,
-} aul_job_status_e;
-
-int aul_job_scheduler_update_job_status(const char *job_id,
- aul_job_status_e job_status);
-
-#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.
- */
-
-#pragma once
-
-/**
- * @brief Definition for AUL: The process ID of the caller.
- * @since_tizen 2.2
- */
-#define AUL_K_CALLER_PID "__AUL_CALLER_PID__"
-
-/**
- * @brief Definition for AUL: The process ID of the callee.
- * @since_tizen 2.2
- */
-#define AUL_K_CALLEE_PID "__AUL_CALLEE_PID__"
-
-/**
- * @brief Definition for AUL: The user ID of the caller.
- * @since_tizen 3.0
- */
-#define AUL_K_CALLER_UID "__AUL_CALLER_UID__"
-
-/**
- * @brief Definition for AUL: The user ID of the callee.
- * @since_tizen 3.0
- */
-#define AUL_K_CALLEE_UID "__AUL_CALLEE_UID__"
-
-/**
- * @brief Definition for AUL: The user ID of the taget user.
- * @since_tizen 3.0
- */
-#define AUL_K_TARGET_UID "__AUL_TARGET_UID__"
-
-/**
- * @brief Definition for AUL: The application ID of the caller.
- * @since_tizen 2.2
- */
-#define AUL_K_CALLER_APPID "__AUL_CALLER_APPID__"
-
-/**
- * @brief Definitnon for AUL: The application ID of the callee.
- * @since_tizen 2.2
- */
-#define AUL_K_CALLEE_APPID "__AUL_CALLEE_APPID__"
-
-/**
- * @deprecated Deprecated since 3.0
- * @brief Definition for AUL: The first argument.
- * @since_tizen 2.2
- */
-#define AUL_K_ARGV0 "__AUL_ARGV0__"
-
-/**
- * @brief Definition for AUL: The start time.
- * @since_tizen 2.2
- */
-#define AUL_K_STARTTIME "__AUL_STARTTIME__"
-
-/**
- * @brief Definition for AUL: The MIME-Type data.
- * @since_tizen 2.2
- */
-#define AUL_K_MIME_TYPE "__AUL_MIME_TYPE__"
-
-/**
- * @brief Definition for AUL: The unaliased MIME-Type data.
- * @since_tizen 2.2
- */
-#define AUL_K_UNALIASED_MIME_TYPE "__AUL_UNALIASED_MIME_TYPE__"
-
-/**
- * @brief Definition for AUL: The content of the MIME-Type data.
- * @since_tizen 2.2
- */
-#define AUL_K_MIME_CONTENT "__AUL_MIME_CONTENT__"
-
-/**
- * @brief Definition for AUL: The service name.
- * @since_tizen 2.2
- */
-#define AUL_K_SERVICE_NAME "__AUL_SERVICE_NAME__"
-
-/**
- * @brief Definition for AUL: The flag if it's 'true', the app-selector is launched forcedly.
- * @since_tizen 2.2
- */
-#define AUL_K_FORCE_LAUNCH_APP_SELECTOR "__AUL_FORCE_LAUNCH_APP_SELECTOR__"
-
-/**
- * @brief Definition for AUL: The flag if it's set, the request is for debugging web-applications.
- * @since_tizen 3.0
- */
-#define AUL_K_DEBUG "__AUL_DEBUG__"
-
-/**
- * @brief Definition for AUL: The SDK data.
- * @since_tizen 2.3
- */
-#define AUL_K_SDK "__AUL_SDK__"
-
-/**
- * @deprecated Deprecated since 3.0
- * @brief Definition for AUL: The multiple key.
- * @since_tizen 2.3
- */
-#define AUL_K_MULTI_KEY "__AUL_MULTI_KEY__"
-
-/**
- * @deprecated Deprecated since 3.0
- * @brief Definition for AUL: The multiple key event.
- * @since_tizen 2.3
- */
-#define AUL_K_MULTI_KEY_EVENT "__AUL_MULTI_KEY_EVENT__"
-
-/**
- * @brief Definition for AUL: The privacy application ID.
- * @since_tizen 2.3
- */
-#define AUL_K_PRIVACY_APPID "__AUL_PRIVACY_APPID__"
-
-/**
- * @deprecased Deprecated since tizen 3.0
- * @brief Definition for AUL: The key pressed event.
- * @since_tizen 2.3
- */
-#define AUL_V_KEY_PRESSED "__AUL_KEY_PRESSED__"
-
-/**
- * @deprecased Deprecated since tizen 3.0
- * @brief Definition for AUL: The key released event.
- * @since_tizen 2.3
- */
-#define AUL_V_KEY_RELEASED "__AUL_KEY_RELEASED__"
-
-/**
- * @brief Definition for RUA: The caller information.
- * @since_tizen 3.0
- */
-#define AUL_SVC_K_RUA_STAT_CALLER "__K_RUA_STAT_CALLER__"
-
-/**
- * @brief Definition for RUA: The tag information.
- * @since_tizen 3.0
- */
-#define AUL_SVC_K_RUA_STAT_TAG "__K_RUA_STAT_TAG__"
-
-/**
- * @brief Definition for RUA: The application ID.
- * @since_tizen 3.0
- */
-#define AUL_K_RUA_PKGNAME "__K_RUA_PKGNAME"
-
-/**
- * @brief Definition for RUA: The application path.
- * @since_tizen 3.0
- */
-#define AUL_K_RUA_APPPATH "__K_RUA_APPPATH"
-
-/**
- * @brief Definition for RUA: The arguments.
- * @since_tizen 3.0
- */
-#define AUL_K_RUA_ARG "__K_RUA_ARG"
-
-/**
- * @brief Definition for RUA: The launched time.
- * @since_tizen 3.0
- */
-#define AUL_K_RUA_TIME "__K_RUA_TIME"
-
-/**
- * @brief Definition for RUA: The instance ID.
- * @since_tizen 3.0
- */
-#define AUL_K_RUA_INSTANCE_ID "__K_RUA_INSTANCE_ID"
-
-/**
- * @brief Definition for RUA: The instance name.
- * @since_tizen 3.0
- */
-#define AUL_K_RUA_INSTANCE_NAME "__K_RUA_INSTANCE_NAME"
-
-/**
- * @brief Definition for RUA: The icon path.
- * @since_tizen 3.0
- */
-#define AUL_K_RUA_ICON "__K_RUA_ICON"
-
-/**
- * @brief Definition for RUA: The URI data.
- * @since_tizen 3.0
- */
-#define AUL_K_RUA_URI "__K_RUA_URI"
-
-/**
- * @brief Definition for AUL: The application ID.
- * @since_tizen 2.2
- */
-#define AUL_K_PKG_NAME "__AUL_PKG_NAME__"
-
-/**
- * @brief Definition for AUL: The flag if it's 'true', the caller process waits to get the result from the callee application.
- * @since_tizen 2.2
- */
-#define AUL_K_WAIT_RESULT "__AUL_WAIT_RESULT__"
-
-/**
- * @brief Definition for AUL: The flag if it's 'true', the request is for sending the result.
- * @since_tizen 2.2
- */
-#define AUL_K_SEND_RESULT "__AUL_SEND_RESULT__"
-
-/**
- * @brief Definition for AUL: The taskmanage value.
- * @since_tizen 2.2
- */
-#define AUL_K_TASK_MANAGE "__AUL_TASK_MANAGE__"
-
-/**
- * @brief Definition for AUL: The application type.
- * @since_tizen 2.2
- */
-#define AUL_K_APP_TYPE "__AUL_APP_TYPE__"
-
-/**
- * @brief Definition for AUL: The process ID of the original caller.
- * @since_tizen 2.2
- */
-#define AUL_K_ORG_CALLER_PID "__AUL_ORG_CALLER_PID__"
-
-/**
- * @brief Definition for AUL: The process ID of the forwarded callee.
- * @since_tizen 2.2
- */
-#define AUL_K_FWD_CALLEE_PID "__AUL_FWD_CALLEE_PID__"
-
-/**
- * @brief Definition for AUL: The flag if it's 'true', the request is not cancelled.
- * @since_tizen 2.2
- */
-#define AUL_K_NO_CANCEL "__AUL_NO_CANCEL__"
-
-/**
- * @brief Definition for AUL: The executable file path.
- * @since_tizen 2.2
- */
-#define AUL_K_EXEC "__AUL_EXEC__"
-
-/**
- * @brief Definition for AUL: The flag if it's 'true', the application can be launched by multiple processes.
- * @since_tizen 2.2
- */
-#define AUL_K_MULTIPLE "__AUL_MULTIPLE__"
-
-/**
- * @brief Definition for AUL: The type of the package.
- * @since_tizen 2.2
- */
-#define AUL_K_PACKAGETYPE "__AUL_PACKAGETYPE__"
-
-/**
- * @brief Definition for AUL: The flag if it's 'true', the application uses hardware-acceleration.
- * @since_tizen 2.2
- */
-#define AUL_K_HWACC "__AUL_HWACC__"
-
-/**
- * @brief Definition for AUL: The application ID.
- * @since_tizen 2.2
- */
-#define AUL_K_APPID "__AUL_APPID__"
-
-/**
- * @brief Definition for AUL: The process ID.
- * @since_tizen 2.2
- */
-#define AUL_K_PID "__AUL_PID__"
-
-/**
- * @brief Definition for AUL: The window ID.
- * @since_tizen 2.4
- */
-#define AUL_K_WID "__AUL_WID__"
-
-/**
- * @breif Definition for AUL: The process ID of the leader process.
- * @since_tizen 2.4
- */
-#define AUL_K_LEADER_PID "__AUL_LEADER_PID__"
-
-/**
- * @brief Definition for Data-Control: The type of data-control.
- * @since_tizen 2.2
- */
-#define AUL_K_DATA_CONTROL_TYPE "__AUL_DATA_CONTROL_TYPE__"
-
-/**
- * @brief Definition for AUL: The package ID.
- * @since_tizen 2.2
- */
-#define AUL_K_PKGID "__AUL_PKGID_"
-
-/**
- * @deprecated Deprecated since 3.0
- * @brief Definition for AUL: The flag if it's 'true', the application can be launched by internal process-pool.
- * @since_tizen 2.2
- */
-#define AUL_K_INTERNAL_POOL "__AUL_INTERNAL_POOL__"
-
-/**
- * @brief Definition for AUL: The TEP resource path.
- * @since_tizen 2.4
- */
-#define AUL_K_TEP_PATH "__AUL_TEP_PATH__"
-
-/**
- * @brief Definition for AUL: The component type.
- * @since_tizen 2.2
- */
-#define AUL_K_COMP_TYPE "__AUL_COMP_TYPE__"
-
-/**
- * @brief Definition for AUL: The loader ID.
- * @since_tizen 3.0
- */
-#define AUL_K_LOADER_ID "__AUL_LOADER_ID__"
-
-/**
- * @brief Definition for AUL: The executable file path of the loader.
- * @since_tizen 3.0
- */
-#define AUL_K_LOADER_PATH "__AUL_LOADER_PATH__"
-
-/**
- * @brief Definition for AUL: The extra data of the loader.
- * @since_tizen 3.0
- */
-#define AUL_K_LOADER_EXTRA "__AUL_LOADER_EXTRA__"
-
-/**
- * @brief Definition for AUL: The loader name.
- * @since_tizen 3.0
- */
-#define AUL_K_LOADER_NAME "__AUL_LOADER_NAME__"
-
-/**
- * @brief Definition for AUL: The wayland display.
- * @since_tizen 3.0
- */
-#define AUL_K_WAYLAND_DISPLAY "__AUL_WAYLAND_DISPLAY__"
-
-/**
- * @brief Definition for AUL: The wayland working directory path.
- * @since_tizen 3.0
- */
-#define AUL_K_WAYLAND_WORKING_DIR "__AUL_WAYLAND_WORKING_DIR__"
-
-/**
- * @brief Definition for AUL: The sender process ID of app-com.
- * @since_tizen 3.0
- */
-#define AUL_K_COM_SENDER_PID "__AUL_COM_SENDER_PID__"
-
-/**
- * @brief Definition for AUL: The endpoint of app-com.
- * @since_tizen 3.0
- */
-#define AUL_K_COM_ENDPOINT "__AUL_COM_ENDPOINT__"
-
-/**
- * @brief Definition for AUL: The privilege of app-com.
- * @since_tizen 3.0
- */
-#define AUL_K_COM_PRIVILEGE "__AUL_COM_PRIVILEGE__"
-
-/**
- * @brief Definition for AUL: The propagate information of app-com.
- * @since_tizen 3.0
- */
-#define AUL_K_COM_PROPAGATE "__AUL_COM_PROPAGATE__"
-
-/**
- * @brief Definition for AUL: The filter of app-com.
- * @since_tizen 3.0
- */
-#define AUL_K_COM_FILTER "__AUL_COM_FILTER__"
-
-/**
- * @brief Definition for AUL: The result of app-com.
- * @since_tizen 3.0
- */
-#define AUL_K_COM_RESULT "__AUL_COM_RESULT__"
-
-/**
- * @brief Definition for AUL: The root path.
- * @since_tizen 3.0
- */
-#define AUL_K_ROOT_PATH "__AUL_ROOT_PATH__"
-
-/**
- * @brief Definition for AUL: The sequence number.
- * @since_tizen 3.0
- */
-#define AUL_K_SEQ_NUM "__AUL_SEQ_NUM__"
-
-/**
- * @brief Definition for AUL: The API version.
- * @since_tizen 3.0
- */
-#define AUL_K_API_VERSION "__AUL_API_VERSION__"
-
-/**
- * @brief Definition for AUL: The flag if it's 'true', the application can be running in the background.
- * @since_tizen 2.4
- */
-#define AUL_K_ALLOWED_BG "__AUL_ALLOWED_BG__"
-
-/**
- * @brief Definition for AUL: The owner process ID of app-group.
- * @since_tizen 2.4
- */
-#define AUL_K_OWNER_PID "__AUL_OWNER_PID__"
-
-/**
- * @brief Definition for AUL: The child process ID of app-group.
- * @since_tizen 2.4
- */
-#define AUL_K_CHILD_PID "__AUL_CHILD_PID__"
-
-/**
- * @brief Definition for Widget: The widget viewer.
- * @since_tizen 3.0
- */
-#define AUL_K_WIDGET_VIEWER "__AUL_WIDGET_VIEWER__"
-
-/**
- * @brief Definition for Widget: The widget ID.
- * @since_tizen 3.0
- */
-#define AUL_K_WIDGET_ID "__AUL_WIDGET_ID__"
-
-/**
- * @brief Definition for Widget: The instance ID of the widget.
- * @since_tizen 3.0
- */
-#define AUL_K_WIDGET_INSTANCE_ID "__AUL_WIDGET_INSTANCE_ID__"
-
-/**
- * @brief Definition for Widget: The status of the widget.
- * @since_tizen 3.0
- */
-#define AUL_K_WIDGET_STATUS "__AUL_WIDGET_STATUS__"
-
-/**
- * @brief Definition for Widget: The error code of the widget.
- * @since_tizen 3.0
- */
-#define AUL_K_WIDGET_ERROR_CODE "__AUL_WIDGET_ERROR_CODE__"
-
-/**
- * @brief Definition for Widget: The widget content infomation.
- * @since_tizen 3.0
- */
-#define AUL_K_WIDGET_CONTENT_INFO "__AUL_WIDGET_CONTENT_INFO__"
-
-/**
- * @brief Definition for AUL: The target process ID.
- * @since_tizen 3.0
- */
-#define AUL_K_TARGET_PID "__AUL_TARGET_PID__"
-
-/**
- * @brief Definition for AUL: The alias application ID.
- * @since_tizen 3.0
- */
-#define AUL_K_ALIAS_APPID "__AUL_ALIAS_APPID__"
-
-/**
- * @brief Definition for AUL: The original application ID.
- * @since_tizen 3.0
- */
-#define AUL_K_ORG_APPID "__AUL_ORG_APPID__"
-
-/**
- * @brief Definition for AUL: The status value.
- * @since_tizen 3.0
- */
-#define AUL_K_STATUS "__AUL_STATUS__"
-
-/**
- * @brief Definition for AUL: The flag if it's 'true', the application is launched by sub-application of app-group.
- * @since_tizen 2.4
- */
-#define AUL_K_IS_SUBAPP "__AUL_IS_SUBAPP__"
-
-/**
- * @brief Definition for AUL: The instance ID.
- * @since_tizen 4.0
- */
-#define AUL_K_INSTANCE_ID "__AUL_INSTANCE_ID__"
-
-/**
- * @brief Definition for AUL: The user ID of the original caller.
- * @since_tizen 3.0
- */
-#define AUL_K_ORG_CALLER_UID "__AUL_ORG_CALLER_UID__"
-
-/**
- * @brief Definition for AUL: The checksum data to store app-control information.
- * @details This definition is to improve the launch performance.
- * @since_tizen 3.0
- */
-#define AUL_K_CHECKSUM "__AUL_CHECKSUM__"
-
-/**
- * @brief Definition for Screen-Connector: The flag if it's 'true', the request type is private.
- * @since_tizen 3.0
- */
-#define AUL_K_PRIVATE "__AUL_PRIVATE__"
-
-/**
- * @brief Definition for Screen-Connector: The screen type.
- * @since_tizen 3.0
- */
-#define AUL_K_SCREEN_TYPE "__AUL_SCREEN_TYPE__"
-
-/**
- * @brief Definition for Screen-Connector: The reference count of the viewer.
- * @since_tizen 3.0
- */
-#define AUL_K_VIEWER_REF "__AUL_VIEWER_REF__"
-
-/**
- * @brief Definition for AUL: The application ID of the parent for transient-for.
- * @since_tizen 3.0
- */
-#define AUL_K_PARENT_APPID "__AUL_PARENT_APPID__"
-
-/**
- * @brief Definition for AUL: The application ID of the child for transient-for.
- * @since_tizen 3.0
- */
-#define AUL_K_CHILD_APPID "__AUL_CHILD_APPID__"
-
-/**
- * @deprecated Deprecated since 4.0
- * @brief Definition for AUL: The flag if it's 'true', the request is for fast launch.
- * @since_tizen 3.0
- */
-#define AUL_K_FAST_LAUNCH "__AUL_FAST_LAUNCH__"
-
-/**
- * @brief Definition for Widget: The flag if it's 'true', the widget is faulted.
- * @since_tizen 3.0
- */
-#define AUL_K_IS_FAULT "__AUL_IS_FAULT__"
-
-/**
- * @brief Definition for AUL: The profile.
- * @since_tizen 3.0
- */
-#define AUL_K_PROFILE "__AUL_PROFILE__"
-
-/**
- * @brief Definition for AUL: The flag if it's 'true', the application is installed for global user.
- * @since_tizen 3.0
- */
-#define AUL_K_IS_GLOBAL "__AUL_IS_GLOBAL__"
-
-/**
- * @brief Definition for AUL: The flag if it's 'true', the request is to create a new instance.
- * @since_tizen 3.0
- */
-#define AUL_K_NEW_INSTANCE "__AUL_NEW_INSTANCE__"
-
-/**
- * @brief Definition for AUL: The flag if it's 'true', the application is installed.
- * @since_tizen 3.0
- */
-#define AUL_K_IS_INSTALLED "__AUL_IS_INSTALLED__"
-
-/**
- * @brief Definition for AUL: The request type.
- * @details This key is only for Application Manager.
- * @since_tizen 4.0
- */
-#define AUL_K_REQUEST_TYPE "__AUL_REQUEST_TYPE__"
-
-/**
- * @brief Definition for AUL: The application ID of the original caller.
- * @since_tizen 3.0
- */
-#define AUL_K_ORG_CALLER_APPID "__AUL_ORG_CALLER_APPID__"
-
-/**
- * @brief Definition for AUL: The package ID of the original caller.
- * @since_tizen 3.0
- */
-#define AUL_K_ORG_CALLER_PKGID "__AUL_ORG_CALLER_PKGID__"
-
-/**
- * @brief Definition for AUL: The installed storage.
- * @since_tizen 2.4
- */
-#define AUL_K_INSTALLED_STORAGE "__AUL_INSTALLED_STORAGE__"
-
-/**
- * @brief Definition for AUL: The component ID.
- * @since_tizen 5.5
- */
-#define AUL_K_COMPONENT_ID "__AUL_COMPONENT_ID__"
-
-/**
- * @brief Definition for AUL: The instance ID of the caller.
- * @since_tizen 5.5
- */
-#define AUL_K_CALLER_INSTANCE_ID "__AUL_CALLER_INSTANCE_ID__"
-
-/**
- * @brief Definition for AUL: The instance ID of the original caller.
- * @since_tizen 5.5
- */
-#define AUL_K_ORG_CALLER_INSTANCE_ID "__AUL_ORG_CALLER_INSTANCE_ID__"
-
-/**
- * @brief Definition for AUL: The IDs of the app group leader.
- * @since_tizen 5.5
- */
-#define AUL_K_LEADER_IDS "__AUL_LEADER_IDS__"
-
-/**
- * @brief Definition for AUL: The ID of the app group leader.
- * @since_tizen 5.5
- */
-#define AUL_K_LEADER_ID "__AUL_LEADER_ID__"
-
-/**
- * @brief Definition for AUL: The flag of the foreground.
- * @since_tizen 5.5
- */
-#define AUL_K_FG_FLAG "__AUL_FG_FLAG__"
-
-/**
- * @brief Definition for AUL: The type of the component.
- * @since_tizen 5.5
- */
-#define AUL_K_COMPONENT_TYPE "__AUL_COMPONENT_TYPE__"
-
-/**
- * @breif Definition for AUL: The flag if it's 'true', the component is sub component of the group.
- * @since_tizen 5.5
- */
-#define AUL_K_IS_SUB_COMP "__AUL_IS_SUB_COMP__"
-
-/**
- * @brief Definition for AUL: The flag if it's 'true', the component is the main component of the application.
- * @since_tizen 5.5
- */
-#define AUL_K_MAIN_COMP "__AUL_MAIN_COMP__"
-
-/**
- * @brief Definition for AUL: The flag if it's 'true', the icon of the component should be display.
- * @since_tizen 5.5
- */
-#define AUL_K_ICON_DISPLAY "__AUL_ICON_DISPLAY__"
-
-/**
- * @brief Definition for AUL: The localized information.
- * @since_tizen 5.5
- */
-#define AUL_K_LOCALIZED_INFO "__AUL_LOCALIZED_INFO__"
-
-/**
- * @brief Definition for AUL: The size of the localized information.
- * @since_tizen 5.5
- */
-#define AUL_K_LOCALIZED_INFO_SIZE "__AUL_LOCALIZED_INFO_SIZE__"
-
-/**
- * @brief Definition for AUL: The locale.
- * @since_tizen 5.5
- */
-#define AUL_K_LOCALE "__AUL_LOCALE__"
-
-/**
- * @brief Definition for AUL: The icon path.
- * @since_tizen 5.5
- */
-#define AUL_K_ICON "__AUL_ICON__"
-
-/**
- * @brief Definition for AUL: The label.
- * @since_tizen 5.5
- */
-#define AUL_K_LABEL "__AUL_LABEL__"
-
-/**
- * @brief Definition for AUL: The launch mode.
- * @since_tizen 5.5
- */
-#define AUL_K_LAUNCH_MODE "__AUL_LAUNCH_MODE__"
-
-/**
- * @brief Definition for AUL: The interval.
- * @since_tizen 5.5
- */
-#define AUL_K_INTERVAL "__AUL_INTERVAL__"
-
-/**
- * @brief Definition for AUL: The command.
- * @since_tizen 5.5
- */
-#define AUL_K_COMMAND "__AUL_COMMAND__"
-
-/**
- * @brief Definition for AUL: The name for the launcher service.
- * @since_tizen 5.5
- */
-#define AUL_K_LAUNCHER_SERVICE "__K_LAUNCHER_SERVICE__"
-
-/**
- * @brief Definition for AUL: The unqiue ID of the launcher service.
- * @since_tizen 5.5
- */
-#define AUL_K_LAUNCHER_SERVICE_SERIAL "__K_LAUNCHER_SERVICE_SERIAL__"
-
-/**
- * @brief Definition for AUL: The event of the launcher service.
- * @since_tizen 5.5
- */
-#define AUL_K_LAUNCHER_SERVICE_EVENT "__K_LAUNCHER_SERVICE_EVENT__"
-
-/**
- * @brief Definition for AUL: The name of the app-defined loader.
- * @since_tizen 5.5
- */
-#define AUL_K_APP_DEFINED_LOADER "__K_APP_DEFINED_LOADER__"
-
-/**
- * @brief Definition for AUL: The widget disable.
- * @since_tizen 5.5
- */
-#define AUL_K_WIDGET_DISABLE "__AUL_WIDGET_DISABLE__"
-
-/**
- * @brief Definition for AUL: The flag of the multiple instance shortcut.
- * @details If it's true, the request is for the multiple instance shortcut.
- * @since_tizen 5.5
- */
-#define AUL_K_MULTI_INSTANCE_SHORTCUT "__AUL_MULTI_INSTANCE_SHORTCUT__"
-
-/**
- * @brief Definition for AUL: The event name.
- * @since_tizen 5.5
- */
-#define AUL_K_EVENT_NAME "__AUL_EVENT_NAME__"
-
-/**
- * @brief Definition for AUL: The event data.
- * @since_tizen 5.5
- */
-#define AUL_K_EVENT_DATA "__AUL_EVENT_DATA__"
-
-/**
- * @brief Definition for AUL: The value for supporting positioning of the app group.
- * @details If the key exists, the callee app group will be inserted into
- * the app group before the given position.
- * @since_tizen 6.0
- */
-#define AUL_K_INSERT_BEFORE_WINDOW "__K_INSERT_BEFORE_WINDOW"
-
-/**
- * @brief Definition for AUL: The list of application ID.
- * @since_tizen 6.0
- */
-#define AUL_K_APPID_LIST "__AUL_K_APPID_LIST__"
-
-/**
- * @brief Definition for AUL: The name of the component port.
- * @since_tizen 6.5
- */
-#define AUL_K_COMPONENT_PORT "__AUL_COMPONENT_PORT__"
-
-/**
- * @brief Definition for AUL: The result.
- * @since_tizen 6.5
- */
-#define AUL_K_RESULT "__AUL_RESULT__"
-
-/**
- * @brief Definition for AUL: The flag if it's 'true', the application has focus.
- * @since_tizen 6.5
- */
-#define AUL_K_HAS_FOCUS "__AUL_HAS_FOCUS__"
-
-/**
- * @brief Definition for AUL: The state of the application lifecycle.
- * @since_tizen 6.5
- */
-#define AUL_K_STATE "__AUL_STATE__"
-
-/**
- * @brief Definition for AUL: The list of paths in a global resource packages.
- * @since_tizen 6.5
- */
-#define AUL_K_MOUNT_GLOBAL_RES_DIR "__AUL_MOUNT_GLOBAL_RES_DIR__"
-
-/**
- * @brief Definition for AUL: The list of paths in a allowed resource packages.
- * @since_tizen 6.5
- */
-#define AUL_K_MOUNT_ALLOWED_RES_DIR "__AUL_MOUNT_ALLOWED_RES_DIR__"
-
-/**
- * @brief Definition for AUL: The name of the process.
- * @since_tizen 6.5
- */
-#define AUL_K_PROC_NAME "__AUL_PROC_NAME__"
-
-/**
- * @brief Definition for AUL: The extra data of the process.
- * @since_tizen 6.5
- */
-#define AUL_K_PROC_EXTRA "__AUL_PROC_EXTRA__"
-
-/**
- * @brief Definition for AUL: The flag of the auto restart.
- * @since_tizen 7.0
- */
-#define AUL_K_AUTO_RESTART "__AUL_AUTO_RESTART__"
-
-/**
- * @brief Definition for AUL: The bundle data for auto restart.
- * @since_tizen 7.0
- */
-#define AUL_K_RESTART_EXTRA "__AUL_RESTART_EXTRA__"
-
-/**
- * @brief Definition for AUL: The priority of boot sequence app.
- * @since_tizen 7.0
- */
-#define AUL_K_BOOT_SEQUENCE_PRIORITY "__AUL_BOOT_SEQUENCE_PRIORITY__"
-
-/**
- * @brief Definition for AUL: The flag of boot sequence app's reqdy wait.
- * @since_tizen 7.0
- */
-#define AUL_K_BOOT_SEQUENCE_READY_WAIT "__AUL_BOOT_SEQUENCE_READY_WAIT__"
-
-/**
- * @brief Definition for AUL: The sub status of app.
- * @since_tizen 7.0
- */
-#define AUL_K_SUB_STATUS "__AUL_SUB_STATUS__"
-
-/**
- * @brief Definition for AUL: The appid list of boot sequence app's after dependency.
- * @since_tizen 7.0
- */
-#define AUL_K_BOOT_SEQUENCE_AFTER "__AUL_BOOT_SEQUENCE_AFTER__"
-
-/**
- * @brief Definition for AUL: The appid list of boot sequence app's before dependency.
- * @since_tizen 7.0
- */
-#define AUL_K_BOOT_SEQUENCE_BEFORE "__AUL_BOOT_SEQUENCE_BEFORE__"
-
-/**
- * @brief Definition for AUL: The appid list of boot sequence app's requires dependency.
- * @since_tizen 7.0
- */
-#define AUL_K_BOOT_SEQUENCE_REQUIRES "__AUL_BOOT_SEQUENCE_REQUIRES__"
-
-/**
- * @brief Definition for AUL: The appid list of boot sequence app's conflicts dependency.
- * @since_tizen 7.0
- */
-#define AUL_K_BOOT_SEQUENCE_CONFLICTS "__AUL_BOOT_SEQUENCE_CONFLICTS__"
-
-/**
- * @brief Definition for AUL: The args bundle data.
- * @since_tizen 7.0
- */
-#define AUL_K_ARGS "__AUL_ARGS__"
-
-/**
- * @brief Definition for AUL: The timeout.
- * @since_tizen 7.0
- */
-#define AUL_K_TIMEOUT "__AUL_TIMEOUT__"
-
-/**
- * @brief Definition for AUL: The begin timestamp of boot sequence app start.
- * @since_tizen 7.0
- */
-#define AUL_K_BEGIN_TIMESTAMP "__AUL_BEGIN_TIMESTAMP__"
-
-/**
- * @brief Definition for AUL: The end timestamp of boot sequence app start.
- * @since_tizen 7.0
- */
-#define AUL_K_END_TIMESTAMP "__AUL_END_TIMESTAMP__"
-
-/**
- * @brief Definition for AUL: The socket ready timestamp of boot sequence app.
- * @since_tizen 7.0
- */
-#define AUL_K_SOCKET_READY_TIMESTAMP "__AUL_SOCKET_READY_TIMESTAMP__"
-
-/**
- * @brief Definition for AUL: The terminated timestamp of boot sequence app.
- * @since_tizen 7.0
- */
-#define AUL_K_TERMINATED_TIMESTAMP "__AUL_TERMINATED_TIMESTAMP__"
-
-/**
- * @brief Definition for AUL: The status message of boot sequence app.
- * @since_tizen 7.0
- */
-#define AUL_K_STATUS_MSG "__AUL_STATUS_MSG__"
-
-/**
- * @brief Definition for AUL: The vconf data of boot sequence app.
- * @since_tizen 7.0
- */
-#define AUL_K_VCONF_DATA "__AUL_VCONF_DATA__"
-
-/**
- * @brief Definition for AUL: The value of indicating a enabled light user for app.
- * @since_tizen 7.0
- */
-#define AUL_K_ENABLED_LIGHT_USER "__AUL_ENABLED_LIGHT_USER__"
-
-/**
- * @brief Definition for AUL: The complication mode.
- * @since_tizen 5.0
- */
-#define AUL_K_COMPLICATION_MODE "__AUL_COMPLICATION_MODE__"
-
-/**
- * @brief Definition for AUL: The package event name.
- * @since_tizen 7.0
- */
-#define AUL_K_PKG_EVENT_NAME "__AUL_K_PKG_EVENT_NAME__"
-
-/**
- * @brief Definition for AUL: The package event
- * @since_tizen 7.0
- */
-#define AUL_K_PKG_EVENT_RESULT "__AUL_K_PKG_EVENT_RESULT__"
-
-/**
- * @brief Definition for AUL: The socket timeout milli seconds.
- * @since_tizen 8.0
- */
-#define AUL_K_SOCKET_TIMEOUT "__AUL_SOCKET_TIMEOUT__"
-
-/**
- * @brief Definition for AUL: The list of mounted resource packages
- * @since_tizen 8.0
- */
-#define AUL_K_MOUNT_RES_PKGIDS "__AUL_MOUNT_RES_PKGIDS__"
-
-/**
- * @brief Definition for AUL: X position of the window.
- * @since_tizen 8.0
- */
-#define AUL_K_HINT_SCREEN_POS_X "__K_HINT_SCREEN_POS_X"
-
-/**
- * @brief Definition for AUL: Y position of the window.
- * @since_tizen 8.0
- */
-#define AUL_K_HINT_SCREEN_POS_Y "__K_HINT_SCREEN_POS_Y"
-
-/**
- * @brief Definition for AUL: Width of the window.
- * @since_tizen 8.0
- */
-#define AUL_K_HINT_SCREEN_WIDTH "__K_HINT_SCREEN_WIDTH"
-
-/**
- * @brief Definition for AUL: Height of the window.
- * @since_tizen 8.0
- */
-#define AUL_K_HINT_SCREEN_HEIGHT "__K_HINT_SCREEN_HEIGHT"
-
-/**
- * @brief Definition for AUL: The application ID for multiple instances.
- * @since_tizen 8.0
- */
-#define AUL_K_MULTIPLE_INSTANCE_APPID "__AUL_MULTIPLE_INSTANCE_APPID__"
-
-/**
- * @brief Definition for AUL: The request ID.
- * @since_tizen 8.0
- */
-#define AUL_K_REQUEST_ID "__AUL_REQUEST_ID__"
-
-/**
- * @brief Definition for AUL: The list of paths in a library resource packages.
- * @since_tizen 9.0
- */
-#define AUL_K_MOUNT_LIB_DIR "__AUL_MOUNT_LIB_DIR__"
-
-/**
- * @brief Definition for AUL: The list of mounted gadget package IDs.
- * @since_tizen 7.0
- */
-#define AUL_K_MOUNT_GADGET_PKGIDS "__AUL_MOUNT_GADGET_PKGIDS__"
-
-/**
- * @brief Definition for AUL: The list of paths of gadget packages.
- * @since_tizen 7.0
- */
-#define AUL_K_MOUNT_GADGET_PATHS "__AUL_MOUNT_GADGET_PATHS__"
+++ /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_LAUNCHER_SERVICE_H__
-#define __AUL_LAUNCHER_SERVICE_H__
-
-#include <stdint.h>
-#include <aul.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @brief The AUL launcher service handle.
- * @since_tizen 5.5
- */
-typedef struct aul_launcher_service_s *aul_launcher_service_h;
-
-/**
- * @brief Called when an application is launched.
- * @since_tizen 5.5
- *
- * @param[in] appid The application ID
- * @param[in] instance_id The instance ID
- * @param[in] pid The process ID
- * @param[in] serial The unique ID
- * @param[in] user_data The user data passed from the callback registration function
- *
- * @see aul_launcher_service_create()
- */
-typedef void (*aul_launcher_service_cb)(const char *appid,
- const char *instance_id,
- const int pid,
- const uint32_t serial,
- void *user_data);
-
-/**
- * @brief Creates the launcher service handle.
- * @details To invoke the callback function, aul_launcher_service_listen() has to be called.
- * @since_tizen 5.5
- *
- * @param[in] name The name of the launcher service
- * @param[in] callback The callback function to be called when the application is launched
- * @param[in] user_data The user data to be passed to the callback function
- * @param[out] handle The launcher service handle
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @see aul_launcher_service_cb()
- * @see aul_launcher_service_listen()
- * @see aul_launcher_service_destroy()
- *
- * @remarks This function is only available for App Framework internally.
- */
-int aul_launcher_service_create(const char *name,
- aul_launcher_service_cb callback,
- void *user_data, aul_launcher_service_h *handle);
-
-/**
- * @brief Listens to the launcher service signal.
- * @details The callback function is invoked when the signal is received.
- * @since_tizen 5.5
- *
- * @param[in] handle The launcher service handle
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @see aul_launcher_service_create()
- *
- * @remarks This function is only available for App Framework internally.
- */
-int aul_launcher_service_listen(aul_launcher_service_h handle);
-
-/**
- * @brief Unsubscribes the registered launcher service.
- * @since_tizen 5.5
- *
- * @param[in] handle The launcher service handle
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @see aul_launcher_service_create()
- *
- * @remarks This function is only available for App Framework internally.
- */
-int aul_launcher_service_destroy(aul_launcher_service_h handle);
-
-/**
- * @brief Notifies that the animation is started.
- * @since_tizen 5.5
- *
- * @return 0 on success,
- * otherwise a negative error value
- *
- * @see aul_launcher_service_notify_animation_finished()
- *
- * @remarks This function is only available for App Framework internally.
- */
-int aul_launcher_service_notify_animation_started(void);
-
-/**
- * @brief Notifies that the animation is finished.
- * @since_tizen 5.5
- *
- * @return 0 on success,
- * otherwise a negative error value
- *
- * @see aul_launcher_service_notify_animation_started()
- *
- * @remarks This function is only available for App Framework internally.
- */
-int aul_launcher_service_notify_animation_finished(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __AUL_LAUNCHER_SERVICE_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2000 - 2021 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_PROC_H__
-#define __AUL_RPOC_H__
-
-#include <sys/types.h>
-#include <unistd.h>
-
-#include <aul.h>
-#include <bundle.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @brief Gets the user ID of the process from the proc filesystem.
- * @since_tizen 6.5
- * @param[in] pid The process ID
- * @param[out] uid The user ID
- * @return @c 0 on success,
- * otherwise a negative error value
- * @remarks This function is only for App Framework internally.
- */
-int aul_proc_get_uid(pid_t pid, uid_t *uid);
-
-/**
- * @brief Gets the SMACK label of the process from the proc filesystem.
- * @since_tizen 6.5
- * @param[in] pid The process ID
- * @param[in] buf The buffer
- * @param[in] buf_size The size of the buffer
- * @return @c 0 on success,
- * otherwise a negative error value
- * @remarks This function is only for App Framework internally.
- */
-int aul_proc_get_attr(pid_t pid, char *buf, size_t buf_size);
-
-/**
- * @brief Gets the cmdline of the process from the proc filesystem.
- * @since_tizen 6.5
- * @param[in] pid The process ID
- * @param[in] buf The buffer
- * @param[in] buf_size The size of the buffer
- * @return @c 0 on success,
- * otherwise a negative error value
- * @remarks This function is only for App Framework internally.
- */
-int aul_proc_get_cmdline(pid_t pid, char *buf, size_t buf_size);
-
-/**
- * @brief Registers the process information,
- * @details This function registers the process information to the application manager daemon.
- * After calling this function, the other process can get the process information
- * using aul_proc_get_name() or aul_proc_get_extra().
- * @since_tizen 6.5
- * @param[in] name The process name
- * @param[in] extra The extra data
- * @return @c 0 on success,
- * otherwise a negative error value
- * @remarks This function is only for App Framework internally.
- */
-int aul_proc_register(const char *name, bundle *extra);
-
-/**
- * @brief Deregister the process information.
- * @since_tizen 6.5
- * @return @c 0 on success,
- * otherwise a negative error value
- * @remarks This function is only for App Framework internally.
- */
-int aul_proc_deregister(void);
-
-/**
- * @brief Gets the process name.
- * @since_tizen 6.5
- * @remarks The @a name MUST be released using free().
- * @param[in] pid The process ID
- * @param[out] name The process name
- * @return @c 0 on success,
- * otherwise a negative error value
- * @remarks This function is only for App Framework internally.
- */
-int aul_proc_get_name(pid_t pid, char **name);
-
-/**
- * @brief Gets the extra data of the process.
- * @since_tizen 6.5
- * @reamrks The @a extra MUST be released using bundle_free().
- * @param[in] pid The process ID
- * @param[out] extra The extra data
- * @return @c 0 on success,
- * otherwise a negative error value
- * @remarks This function is only for App Framework internally.
- */
-int aul_proc_get_extra(pid_t pid, bundle **extra);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __AUL_PROC_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2021 - 2023 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_PROC_GROUP_H__
-#define __AUL_PROC_GROUP_H__
-
-#include <sys/types.h>
-#include <unistd.h>
-
-#include <aul.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @brief The process group information handle.
- * @since_tizen 8.0
- */
-typedef void *aul_proc_group_info_h;
-
-/**
- * @brief Called when the process group info is delivered.
- * @remarks This function is only for App Framework internally.
- * @details You must not release @a h using aul_proc_group_info_destroy().
- * It's managed by platform.
- * @since_tizen 8.0
- * @param[in] h The process group info handle
- * @param[in] user_data The user data passed from the registration function
- * @see aul_proc_group_foreach()
- */
-typedef void (*aul_proc_group_cb)(aul_proc_group_info_h h, void *user_data);
-
-/**
- * @brief Gets the leader process ID from the process group info handle.
- * @remarks This function is only for App Framework internally.
- * @since_tizen 8.0
- * @param[in] h The process group info handle
- * @param[out] leader_pid The leader pid of the process group
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #AUL_R_OK Successful
- * @retval #AUL_R_EINVAL Invalid parameter
- * @see aul_proc_group_foreach()
- */
-int aul_proc_group_info_get_leader_pid(aul_proc_group_info_h h, pid_t *leader_pid);
-
-/**
- * @brief Gets the sub process IDs from the process group info handle.
- * @remarks This function is only for App Framework internally.
- * @details You must not release the @c sub_pids using free().
- * It's managed by platform.
- * The sub_pids is only valid in the callback function.
- * @since_tizen 8.0
- * @param[in] h The process group info handle
- * @param[out] sub_pids The sub pids of the process group
- * @param[out] length The length of the sub pids
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #AUL_R_OK Successful
- * @retval #AUL_R_EINVAL Invalid parameter
- * @see aul_proc_group_foreach()
- */
-int aul_proc_group_info_get_sub_pids(aul_proc_group_info_h h, const pid_t **sub_pids, size_t *length);
-
-/**
- * @brief Releases the process group info handle.
- * @remarks This function is only for App Framework internally.
- * @since_tizen 8.0
- * @param[in] h The process group info handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #AUL_R_OK Sucessful
- * @retval #AUL_R_EINVAL Invalid parameter
- * @see aul_proc_group_get()
- */
-int aul_proc_group_info_destroy(aul_proc_group_info_h h);
-
-/**
- * @brief Adds the process to the process group.
- * @remarks This function is only for App Framework internally.
- * @remarks If the pid is not equal to the process ID of the caller,
- * the caller MUST have a permission that is signed by platform certificate.
- * If the caller doesn't have the permission, the function returns AUL_R_EILLACC.
- * @since_tizen 6.5
- * @param[in] pid The process ID
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #AUL_R_OK Successful
- * @retval #AUL_R_EINVAL Invalid parameter
- * @retval #AUL_R_ECOMM Communication error on send
- * @retval #AUL_R_EILLACC Permission denied
- */
-int aul_proc_group_add(pid_t pid);
-
-/**
- * @brief Removes the process from the process group.
- * @remarks This function is only for App Framework internally.
- * @remarks If the pid is not equal to the process ID of the caller,
- * the caller MUST have a permission that is signed by platform certificate.
- * If the caller doesn't have the permission, the function returns AUL_R_EILLACC.
- * @since_tizen 6.5
- * @param[in] pid The process ID
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #AUL_R_OK Successful
- * @retval #AUL_R_EINVAL Invalid parameter
- * @retval #AUL_R_ECOMM Communication error on send
- * @retval #AUL_R_EILLACC Permission denied
- */
-int aul_proc_group_remove(pid_t pid);
-
-/**
- * @brief Retrieves the process group information.
- * @remarks This function is only for App Framework internally.
- * @remarks This definition is only available for platform level signed applications.
- * @param[in] callback The callback function
- * @param[in] user_data The user data to be passed the callback function
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #AUL_R_OK Successful
- * @retval #AUL_R_EINVAL Invalid parameter
- * @retval #AUL_R_ECOMM Communication error
- * @retval #AUL_R_EILLACC Permission denied
- * @see aul_proc_group_cb()
- */
-int aul_proc_group_foreach(aul_proc_group_cb callback, void *user_data);
-
-/**
- * @brief Gets the specific process group info.
- * @remarks This function is only for App Framework internally.
- * @remarks This definition is only available for platform level signed applications.
- * @details You must release the @c h using aul_proc_group_info_destroy().
- * @since_tizen 8.0
- * @param[in] pid The process ID
- * @param[out] h The process group info handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #AUL_R_OK Successful
- * @retval #AUL_R_EINVAL Invalid parameter
- * @retval #AUL_R_ENOENT No such group info
- * @retval #AUL_R_ENOMEM Out of memory
- * @see aul_proc_group_info_destroy()
- */
-int aul_proc_group_get(pid_t pid, aul_proc_group_info_h *h);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __AUL_PROC_GROUP_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2018 - 2021 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_RPC_PORT_H__
-#define __AUL_RPC_PORT_H__
-
-#include <sys/types.h>
-#include <unistd.h>
-
-#include <aul.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifndef AUL_K_RPC_PORT
-#define AUL_K_RPC_PORT "__K_RPC_PORT"
-#endif
-
-typedef void *aul_rpc_port_watch_h;
-
-typedef void (*aul_rpc_port_appeared_cb)(const char *app_id,
- const char *port_name, int pid, void *user_data);
-
-typedef void (*aul_rpc_port_vanished_cb)(const char *app_id,
- const char *port_name, int pid, void *user_data);
-
-int aul_rpc_port_prepare_stub(const char *app_id, const char *port_name);
-
-int aul_rpc_port_usr_prepare_stub(const char *app_id, const char *port_name,
- uid_t uid);
-
-int aul_rpc_port_create_socket_pair(const char *app_id, const char *port_name,
- int (*fds)[2]);
-
-int aul_rpc_port_notify_rpc_finished(void);
-
-int aul_rpc_port_set_private_sharing(const char *app_id, const char *paths[],
- unsigned int size);
-
-int aul_rpc_port_unset_private_sharing(const char *app_id);
-
-int aul_rpc_port_create(const char *port_name, int *fd);
-
-int aul_rpc_port_usr_create(const char *port_name, uid_t uid, int *fd);
-
-int aul_rpc_port_destroy(const char *port_name);
-
-int aul_rpc_port_usr_destroy(const char *port_name, uid_t uid);
-
-int aul_rpc_port_add_watch(const char *app_id, const char *port_name,
- aul_rpc_port_appeared_cb appeared_cb,
- aul_rpc_port_vanished_cb vanished_cb,
- void *user_data,
- aul_rpc_port_watch_h *handle);
-
-int aul_rpc_port_usr_add_watch(const char *app_id, const char *port_name,
- aul_rpc_port_appeared_cb appeared_cb,
- aul_rpc_port_vanished_cb vanished_cb,
- void *user_data, uid_t uid,
- aul_rpc_port_watch_h *handle);
-
-
-int aul_rpc_port_remove_watch(aul_rpc_port_watch_h handle);
-
-int aul_rpc_port_exist(const char *appid, const char *port_name, bool *exist);
-
-int aul_rpc_port_usr_exist(const char *appid, const char *port_name, uid_t uid,
- bool *exist);
-
-int aul_rpc_port_get_path(const char *appid, const char *port_name,
- char **path);
-
-int aul_rpc_port_usr_get_path(const char *appid, const char *port_name,
- uid_t uid, char **path);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __AUL_RPC_PORT_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <tizen.h>
-#include <bundle.h>
-#include <glib.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @brief Enumeration for Resource Types
- * @since_tizen 2.4
- */
-typedef enum {
- AUL_RESOURCE_TYPE_IMAGE = 0, /**<Image*/
- AUL_RESOURCE_TYPE_LAYOUT, /**<Edje*/
- AUL_RESOURCE_TYPE_SOUND, /**<Sound*/
- AUL_RESOURCE_TYPE_BIN, /**<Bin*/
- AUL_RESOURCE_TYPE_MIN = AUL_RESOURCE_TYPE_IMAGE,
- AUL_RESOURCE_TYPE_MAX = AUL_RESOURCE_TYPE_BIN,
-/*add values between AUL_RESOURCE_TYPE_MIN and AUL_RESOURCE_TYPE_MAX*/
-} aul_resource_e;
-
-/**
- * @brief Enumeration for Aul Resource Manager Error.
- * @since_tizen 2.4
- */
-typedef enum {
- AUL_RESOURCE_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
- AUL_RESOURCE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
- AUL_RESOURCE_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
- AUL_RESOURCE_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */
-} aul_resource_error_e;
-
-/**
- * @brief Creates resource manager and get from db.
- *
- * @since_tizen 2.4
- * @remarks If resource manager is already exist,
- * It will just return APP_RESOURCE_ERROR_NONE
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #AUL_RESOURCE_ERROR_NONE Successful
- * @retval #AUL_RESOURCE_ERROR_IO_ERROR IO Internal I/O Error
- * @retval #AUL_RESOURCE_ERROR_OUT_OF_MEMORY Out of memeory
- * @see aul_resource_manager_release()
- */
-int aul_resource_manager_init(void);
-
-/**
- * @brief Creates resource manager and make valid filelist from given attributes.
- *
- * @since_tizen 2.4
- * @remarks If resource manager is already exist,
- * It will just return APP_RESOURCE_ERROR_NONE
- * This function should called from resource slice tool only.
- * @param[in] rsc_folder_path path of resource.
- * @param[in] b bundle which contain attributes about target device.
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #AUL_RESOURCE_ERROR_NONE Successful
- * @retval #AUL_RESOURCE_ERROR_IO_ERROR IO Internal I/O Error
- * @retval #AUL_RESOURCE_ERROR_OUT_OF_MEMORY Out of memeory
- * @see aul_resource_manager_release()
- */
-int aul_resource_manager_init_slice(const char *rsc_folder_path, bundle *b);
-
-/**
- * @brief Convert resource ID to path name
- *
- * @since_tizen 2.4
- * @remarks If resource manager is not created yet,
- * aul_resource_manager_init() will be invoked automatically.
- * Caller should free the returned pointer.
- * @param[in] type Resource type @see aul_resource_e
- * @param[in] id Resource ID
- * @param[out] path The name of requested resource on success, otherwise NULL
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #AUL_RESOURCE_ERROR_NONE Successful
- * @retval #AUL_RESOURCE_ERROR_INVALID_PARAMETER Invalid Parameter
- * @retval #AUL_RESOURCE_ERROR_IO_ERROR Internal I/O Error
- * @see aul_resource_manager_init()
- */
-int aul_resource_manager_get(aul_resource_e type, const char *id, char **path);
-
-/**
- * @brief Destroys resource manager.
- *
- * @since_tizen 2.4
- * @remarks Please make sure that the instance of resource manager should be released when the application is closing only.
- * It is highly recommended way to improve run-time performance.
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #AUL_RESOURCE_ERROR_NONE Successful
- * @see aul_resource_manager_init()
- */
-int aul_resource_manager_release(void);
-
-/**
- * @brief Get valid file path list.
- *
- * @since_tizen 2.4
- * @remarks Please make sure that the instance of resource manager should be released when the application is closing only.
- * It is highly recommended way to improve run-time performance.
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #AUL_RESOURCE_ERROR_NONE Successful
- * @see aul_resource_manager_init()
- */
-int aul_resource_manager_get_path_list(GHashTable **list);
-
-/**
- * @}
- */
-
-#ifdef __cplusplus
-}
-#endif
-
-
+++ /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_RUNNING_CONTEXT_H__
-#define __AUL_RUNNING_CONTEXT_H__
-
-#include <stdint.h>
-#include <aul.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @brief The AUL running context handle.
- * @since_tizen 5.5
- */
-typedef struct aul_running_context_s *aul_running_context_h;
-
-/**
- * @brief Creates the running context handle.
- * @since_tizen 5.5
- *
- * @param[in] app_id The application ID
- * @param[in] inst_id The instance ID
- * @param[in] comp_id The component ID
- * @param[out] handle The running context handle of the given IDs
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only available for platform level signed applications.
- */
-int aul_running_context_create(const char *app_id,
- const char *inst_id,
- const char *comp_id,
- aul_running_context_h *handle);
-
-/**
- * @brief Destroyes the running context handle.
- * @since_tizen 5.5
- *
- * @param[in] handle The running context handle
- * @return @c 0 on success,
- * otherwise a negative error value
- */
-int aul_running_context_destroy(aul_running_context_h handle);
-
-/**
- * @brief Gets the application ID.
- * @since_tizen 5.5
- * @remarks The @a app_id MUST NOT be released using free().
- * It's released when the runnning context handle is released.
- *
- * @param[in] handle The running context handle
- * @param[out] app_id The application ID
- * @return @c 0 on success,
- * otherwise a negative error value
- */
-int aul_running_context_get_app_id(aul_running_context_h handle,
- const char **app_id);
-
-/**
- * @brief Gets the instance ID.
- * @since_tizen 5.5
- * @remarks The @a inst_id MUST NOT be release using free().
- * It's released when the running context handle is released.
- *
- * @param[in] handle The running context handle
- * @param[out] inst_id The instance ID
- * @return @c 0 on success,
- * otherwise a negative error value
- */
-int aul_running_context_get_inst_id(aul_running_context_h handle,
- const char **inst_id);
-
-/**
- * @brief Gets the process ID.
- * @since_tizen 5.5
- *
- * @param[in] handle The running context handle
- * @param[out] pid The process ID
- * @return @c 0 on success,
- * otherwise a negative error value
- */
-int aul_running_context_get_pid(aul_running_context_h handle,
- int *pid);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __AUL_RUNNING_CONTEXT_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2016 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_SCREEN_CONNECTOR_H__
-#define __AUL_SCREEN_CONNECTOR_H__
-
-#include <stdbool.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef enum {
- AUL_SCREEN_TYPE_WIDGET = 0x01,
- AUL_SCREEN_TYPE_WATCH = 0x02,
- AUL_SCREEN_TYPE_UI = 0x04,
- AUL_SCREEN_TYPE_COMPONENT_BASED = 0x08,
- AUL_SCREEN_TYPE_ALL = AUL_SCREEN_TYPE_WIDGET | AUL_SCREEN_TYPE_WATCH |
- AUL_SCREEN_TYPE_UI | AUL_SCREEN_TYPE_COMPONENT_BASED,
-} aul_screen_type_e;
-
-typedef enum {
- AUL_SCREEN_CONNECTOR_EVENT_TYPE_ADD,
- AUL_SCREEN_CONNECTOR_EVENT_TYPE_REMOVE,
- AUL_SCREEN_CONNECTOR_EVENT_TYPE_UPDATE,
- AUL_SCREEN_CONNECTOR_EVENT_TYPE_FOCUS,
-} aul_screen_connector_event_type_e;
-
-typedef enum {
- AUL_SCREEN_STATUS_RESUME,
- AUL_SCREEN_STATUS_PRE_RESUME,
- AUL_SCREEN_STATUS_PAUSE,
-} aul_screen_status_e;
-
-typedef void (*aul_screen_viewer_cb)(const char *appid,
- const char *instance_id, const int pid,
- const unsigned int surface_id,
- aul_screen_connector_event_type_e event_type, void *data);
-
-typedef struct aul_screen_viewer_s *aul_screen_viewer_h;
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_screen_connector_add_app_screen(const char *instance_id,
- unsigned int surf);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_screen_connector_remove_app_screen(const char *instance_id);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_screen_connector_send_update_request(const char *appid,
- const char *instance_id);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_screen_connector_add_screen_viewer(aul_screen_viewer_cb callback,
- aul_screen_type_e type, bool priv,
- void *data, aul_screen_viewer_h *handle);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_screen_connector_remove_screen_viewer(aul_screen_viewer_h handle);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_screen_connector_get_appid_by_surface_id(unsigned int surface_id,
- char **appid);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_screen_connector_get_instance_id_by_surface_id(unsigned int surface_id,
- char **instance_id);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_screen_connector_update_screen_viewer_status(aul_screen_status_e status,
- unsigned int provider_surf);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_screen_connector_trigger_focused_force(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __AUL_SCREEN_CONNECTOR_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
-
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE
-#endif
-
-#include <unistd.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <stdbool.h>
-#include <bundle.h>
-
-#include <aul_cmd.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define AUL_SOCK_MAXBUFF 131071
-#define ELOCALLAUNCH_ID 128
-#define EILLEGALACCESS 127
-#define ETERMINATING 126
-#define ENOLAUNCHPAD 125
-#define EREJECTED 123
-
-#define AUL_PKT_HEADER_SIZE (sizeof(int) + sizeof(int) + sizeof(int))
-
-typedef struct _app_pkt_t {
- int cmd;
- int len;
- int opt;
- unsigned char data[1];
-} app_pkt_t;
-
-typedef enum {
- AUL_SOCK_NONE = 0x0, /* default */
- AUL_SOCK_NOREPLY = 0x1, /* return immediately after packet sent without reply */
- AUL_SOCK_ASYNC = 0x2, /* leave fd in open and return fd of client socket */
- AUL_SOCK_QUEUE = 0x4, /* add request to pending list in case of receiver is busy */
- AUL_SOCK_BUNDLE = 0x8, /* has bundle */
-} aul_sock_opt_e;
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_sock_create_server(int pid, uid_t uid);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_sock_send_raw(int pid, uid_t uid, int cmd, unsigned char *kb_data, int datalen, int opt);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_sock_send_bundle(int pid, uid_t uid, int cmd, bundle *kb, int opt);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_sock_send_raw_with_fd(int fd, int cmd, unsigned char *kb_data, int datalen, int opt);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_sock_send_bundle_with_fd(int fd, int cmd, bundle *kb, int opt);
-
-/*
- * This API is only for Appfw internally.
- */
-app_pkt_t *aul_sock_recv_pkt(int fd, int *clifd, struct ucred *cr);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_sock_create_launchpad_client(const char *pad_type, uid_t uid);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_sock_recv_reply_sock_fd(int fd, int (*ret_fd)[2], int num_of_ret_fd);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_sock_recv_reply_pkt(int fd, app_pkt_t **pkt);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_sock_set_sock_option(int fd, int cli);
-
-/*
- * This API is only for Appfw internally.
- */
-struct timeval aul_sock_get_rcv_timeval(void);
-
-/*
- * This API in only for Appfw internally.
- */
-int aul_sock_recv_pkt_with_cb(int fd,
- void (*callback)(app_pkt_t *pkt, void *data),
- void *user_data);
-
-/*
- * This API in only for Appfw internally.
- */
-int aul_sock_recv_result_with_fd(int fd);
-
-/*
- * This API in only for Appfw internally.
- */
-int aul_sock_destroy_server(int fd);
-
-/**
- * This API is only for Appfw internally.
- */
-int aul_sock_send_result(int fd, int res);
-
-/**
- * This API is only for Appfw internally.
- */
-int aul_sock_send_result_v2(int fd, int res, bool do_close);
-
-/**
- * This API is only for Appfw internally.
- */
-int aul_sock_recv_reply_pkt_v2(int fd, app_pkt_t **pkt, bool do_close);
-
-/**
- * This API is only for Appfw internally.
- */
-int aul_sock_create_launchpad_client_without_timeout(const char *pad_type, uid_t uid);
-
-/**
- * This API is only for Appfw internally.
- */
-int aul_sock_send_raw_data(int fd, unsigned char *raw_data, size_t length, bool do_close);
-
-#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
-
-#include <bundle.h>
-#include <sys/types.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifndef AUL_DEPRECATED_API
-#define AUL_DEPRECATED_API __attribute__((__visibility__("default"), deprecated))
-#endif
-
-/** AUL_SVC OPERATION TYPE*/
-#define AUL_SVC_OPERATION_DEFAULT "http://tizen.org/appcontrol/operation/default"
-/** AUL_SVC OPERATION TYPE*/
-#define AUL_SVC_OPERATION_EDIT "http://tizen.org/appcontrol/operation/edit"
-/** AUL_SVC OPERATION TYPE*/
-#define AUL_SVC_OPERATION_VIEW "http://tizen.org/appcontrol/operation/view"
-/** AUL_SVC OPERATION TYPE*/
-#define AUL_SVC_OPERATION_PICK "http://tizen.org/appcontrol/operation/pick"
-/** AUL_SVC OPERATION TYPE*/
-#define AUL_SVC_OPERATION_CREATE_CONTENT "http://tizen.org/appcontrol/operation/create_content"
-/** AUL_SVC OPERATION TYPE*/
-#define AUL_SVC_OPERATION_CALL "http://tizen.org/appcontrol/operation/call"
-/** AUL_SVC OPERATION TYPE*/
-#define AUL_SVC_OPERATION_SEND "http://tizen.org/appcontrol/operation/send"
-/** AUL_SVC OPERATION TYPE*/
-#define AUL_SVC_OPERATION_SEND_TEXT "http://tizen.org/appcontrol/operation/send_text"
-/** AUL_SVC OPERATION TYPE*/
-#define AUL_SVC_OPERATION_DIAL "http://tizen.org/appcontrol/operation/dial"
-/** AUL_SVC OPERATION TYPE*/
-#define AUL_SVC_OPERATION_SEARCH "http://tizen.org/appcontrol/operation/search"
-/** AUL_SVC OPERATION TYPE*/
-#define AUL_SVC_OPERATION_DOWNLOAD "http://tizen.org/appcontrol/operation/download"
-/** AUL_SVC OPERATION TYPE*/
-#define AUL_SVC_OPERATION_SHARE "http://tizen.org/appcontrol/operation/share"
-/** AUL_SVC OPERATION TYPE*/
-#define AUL_SVC_OPERATION_MULTI_SHARE "http://tizen.org/appcontrol/operation/multi_share"
-/** AUL_SVC OPERATION TYPE*/
-#define AUL_SVC_OPERATION_SHARE_TEXT "http://tizen.org/appcontrol/operation/share_text"
-/** AUL_SVC_OPERATION_TYPE*/
-#define AUL_SVC_OPERATION_COMPOSE "http://tizen.org/appcontrol/operation/compose"
-/** AUL_SVC OPERATION TYPE*/
-#define AUL_SVC_OPERATION_LOCATION "http://tizen.org/appcontrol/operation/configure/location"
-/** AUL_SVC OPERATION TYPE*/
-#define AUL_SVC_OPERATION_FONT_TYPE "http://tizen.org/appcontrol/operation/configure/font/type"
-/** AUL_SVC OPERATION TYPE*/
-#define AUL_SVC_OPERATION_FONT_SIZE "http://tizen.org/appcontrol/operation/configure/font/size"
-#define AUL_SVC_OPERATION_LAUNCH_ON_EVENT "http://tizen.org/appcontrol/operation/launch_on_event"
-
-
-
-/** AUL_SVC DATA SUBJECT*/
-#define AUL_SVC_DATA_SUBJECT "http://tizen.org/appcontrol/data/subject"
-/** AUL_SVC DATA TYPE*/
-#define AUL_SVC_DATA_TO "http://tizen.org/appcontrol/data/to"
-/** AUL_SVC DATA TYPE*/
-#define AUL_SVC_DATA_CC "http://tizen.org/appcontrol/data/cc"
-/** AUL_SVC DATA TYPE*/
-#define AUL_SVC_DATA_BCC "http://tizen.org/appcontrol/data/bcc"
-/** AUL_SVC DATA TYPE*/
-#define AUL_SVC_DATA_TEXT "http://tizen.org/appcontrol/data/text"
-/** AUL_SVC DATA TYPE*/
-#define AUL_SVC_DATA_TITLE "http://tizen.org/appcontrol/data/title"
-/** AUL_SVC DATA TYPE*/
-#define AUL_SVC_DATA_SELECTED "http://tizen.org/appcontrol/data/selected"
-/** AUL_SVC DATA TYPE*/
-#define AUL_SVC_DATA_KEYWORD "http://tizen.org/appcontrol/data/keyword"
-/** AUL_SVC DATA TYPE*/
-#define AUL_SVC_DATA_PATH "http://tizen.org/appcontrol/data/path"
-/** AUL_SVC DATA TYPE*/
-#define AUL_SVC_DATA_SELECTION_MODE "http://tizen.org/appcontrol/data/selection_mode"
-/** AUL_SVC DATA TYPE*/
-#define AUL_SVC_DATA_RETURN_RESULT "http://tizen.org/appcontrol/data/return_result"
-
-/** AUL SVC internal private key */
-#define AUL_SVC_K_URI_R_INFO "__AUL_SVC_URI_R_INFO__"
-
-#define AUL_SVC_K_SELECTOR_EXTRA_LIST "http://tizen.org/appcontrol/data/selector_extra_list"
-
-/** AUL SVC internal private key */
-#define AUL_SVC_OPERATION_LAUNCH_WIDGET "http://tizen.org/appcontrol/operation/launch_widget"
-
-#ifdef _APPFW_FEATURE_MULTI_INSTANCE
-#define AUL_SVC_K_MULTI_INSTANCE "multi_instance"
-#endif
-
-#define APP_SELECTOR "org.tizen.app-selector"
-#define SHARE_PANEL "org.tizen.share-panel"
-
-/** Internal operation for launching application which is other zone */
-#define AUL_SVC_OPERATION_JUMP "http://tizen.org/appcontrol/operation/jump"
-#define AUL_SVC_K_JUMP_ZONE_NAME "__K_JUMP_DOMAIN_NAME__"
-#define AUL_SVC_K_JUMP_ORIGIN_OPERATION "__K_JUMP_ORIGIN_OPERATION__"
-#define AUL_SVC_K_FOCUS_ZONE "__K_FOCUS_ZONE__"
-#define AUL_SVC_K_LAUNCH_RESULT_APP_STARTED "__K_LAUNCH_RESULT_APP_STARTED__"
-#define AUL_SVC_K_CAN_BE_LEADER "__K_CAN_BE_LEADER__"
-#define AUL_SVC_K_REROUTE "__K_REROUTE__"
-#define AUL_SVC_K_SHIFT_WINDOW "__K_SHIFT_WINDOW"
-#define AUL_SVC_K_RECYCLE "__K_RECYCLE"
-#define AUL_SVC_K_RELOCATE_BELOW "__K_RELOCATE_BELOW"
-#define AUL_SVC_K_BG_LAUNCH "__K_BG_LAUNCH"
-#define AUL_SVC_K_SPLASH_SCREEN "__K_SPLASH_SCREEN"
-#define AUL_SVC_K_ALIAS_INFO "__K_ALIAS_INFO"
-
-#define PAD_LOADER_ID_DIRECT 1
-
-/**
- * @brief Return values in appsvc.
- */
-typedef enum _aul_svc_return_val {
- AUL_SVC_RET_ETIMEOUT = -10, /**< Timeout */
- AUL_SVC_RET_ENOMEM = -9, /**< Out of memory */
- AUL_SVC_RET_ECANCELED = -8, /**< Operation is canceled */
- AUL_SVC_RET_EREJECTED = -7, /**< application launch rejected */
- AUL_SVC_RET_ETERMINATING = -6, /**< application terminating */
- AUL_SVC_RET_EILLACC = -5, /**< Illegal Access */
- AUL_SVC_RET_ELAUNCH = -4, /**< Failure on launching the app */
- AUL_SVC_RET_ENOMATCH = -3, /**< No matching result Error */
- AUL_SVC_RET_EINVAL = -2, /**< Invalid argument */
- AUL_SVC_RET_ERROR = -1, /**< General error */
- AUL_SVC_RET_OK = 0, /**< General success */
-} aul_svc_return_val;
-
-
-/**
- * @brief result values in appsvc.
- */
-typedef enum _aul_svc_result_val {
- AUL_SVC_RES_CANCEL = -2, /**< Cancel by system */
- AUL_SVC_RES_NOT_OK = -1, /**< Fail by user */
- AUL_SVC_RES_OK = 0 /**< Success by user */
-} aul_svc_result_val;
-
-
-/**
- * @brief aul_svc_res_fn is appsvc result function
- * @param[out] b result bundle
- * @param[out] request_code request code
- * @param[out] result result value
- * @param[out] data user-supplied data
-*/
-typedef void (*aul_svc_res_fn)(bundle *b, int request_code, aul_svc_result_val result, void *data);
-
-/**
- * @brief Called when the result of the launch request is delivered.
- *
- * @param[in] request_code The request code
- * @param[in] result The result, the process ID of the callee on success otherwise a negative error value
- * @param[in] user_data The user data passed from the callback registration function
- */
-typedef void (*aul_svc_err_cb)(int request_code, int result, void *user_data);
-
-/**
- * @brief iterator function running with aul_svc_get_list
- * @param[out] appid appid retreived by aul_svc_get_list
- * @param[out] data user-supplied data
-*/
-typedef int (*aul_svc_info_iter_fn)(const char *appid, void *data);
-
-typedef int (*aul_svc_host_res_fn)(void *data);
-
-/**
- * @par Description:
- * This function sets an operation to launch application based on appsvc.
- *
- * @param[in] b bundle object
- * @param[in] operation operation
- *
- * @return 0 if success, negative value(<0) if fail
- * @retval AUL_SVC_RET_OK - success
- * @retval AUL_SVC_RET_ERROR - general error
- * @retval AUL_SVC_RET_EINVAL - invalid argument(content)
- *
- * @pre None.
- * @post None.
- * @see None.
- * @remarks An application must call this function before using aul_svc_run_service API.
- *
- * @par Sample code:
- * @code
-#include <aul_svc.h>
-
-...
-{
- bundle *b = NULL;
-
- b = bundle_create();
-
- aul_svc_set_operation(b, AUL_SVC_OPERATION_VIEW);
-}
- * @endcode
- *
- */
-int aul_svc_set_operation(bundle *b, const char *operation);
-
-/**
- * @par Description:
- * This function sets an uri to launch application based on appsvc.
- *
- * @param[in] b bundle object
- * @param[in] uri uri
- *
- * @return 0 if success, negative value(<0) if fail
- * @retval AUL_SVC_RET_OK - success
- * @retval AUL_SVC_RET_ERROR - general error
- * @retval AUL_SVC_RET_EINVAL - invalid argument(content)
- *
- * @pre None.
- * @post None.
- * @see None.
- * @remarks None.
- *
- * @par Sample code:
- * @code
-#include <aul_svc.h>
-
-...
-{
- bundle *b = NULL;
-
- b = bundle_create();
-
- aul_svc_set_operation(b, AUL_SVC_OPERATION_VIEW);
- aul_svc_set_uri(b,"http://www.samsung.com");
-}
- * @endcode
- *
- */
-int aul_svc_set_uri(bundle *b, const char *uri);
-
-/**
- * @par Description:
- * This function sets a mime-type to launch application based on appsvc.
- *
- * @param[in] b bundle object
- * @param[in] mime mime-type
- *
- * @return 0 if success, negative value(<0) if fail
- * @retval AUL_SVC_RET_OK - success
- * @retval AUL_SVC_RET_ERROR - general error
- * @retval AUL_SVC_RET_EINVAL - invalid argument(content)
- *
- * @pre None.
- * @post None.
- * @see None.
- * @remarks None.
- *
- * @par Sample code:
- * @code
-#include <aul_svc.h>
-
-...
-{
- bundle *b = NULL;
-
- b = bundle_create();
-
- aul_svc_set_operation(b, AUL_SVC_OPERATION_PICK);
- aul_svc_set_mime(b,"image/jpg");
-}
- * @endcode
- *
- */
-int aul_svc_set_mime(bundle *b, const char *mime);
-
-/**
- * @par Description:
- * This function sets an extra data to launch application based on appsvc.
- *
- * @param[in] b bundle object
- * @param[in] key key of extra data
- * @param[in] val data
- *
- * @return 0 if success, negative value(<0) if fail
- *
- * @pre None.
- * @post None.
- * @see None.
- * @remarks None.
- *
- * @par Sample code:
- * @code
-#include <aul_svc.h>
-
-...
-{
- bundle *b = NULL;
-
- b = bundle_create();
-
- aul_svc_set_operation(b, AUL_SVC_OPERATION_SEND);
- aul_svc_set_uri(b,"mailto:xxx1@xxx");
- aul_svc_add_data(b,AUL_SVC_DATA_CC,"xxx2@xxx");
-}
- * @endcode
- *
- */
-int aul_svc_add_data(bundle *b, const char *key, const char *val);
-
-/**
- * @par Description:
- * This function sets an extra array data to launch application based on appsvc.
- *
- * @param[in] b bundle object
- * @param[in] key key of extra data
- * @param[in] val_array data
- * @param[in] len Length of array
- *
- * @return 0 if success, negative value(<0) if fail
- *
- * @pre None.
- * @post None.
- * @see None.
- * @remarks None.
- *
- * @par Sample code:
- * @code
-#include <aul_svc.h>
-
-...
-{
- bundle *b = NULL;
- char *images[] = {"/opt/media/a.jpg", "/opt/media/b.jpg", "/opt/media/c.jpg"};
-
- b = bundle_create();
-
- aul_svc_add_data_array(b, AUL_SVC_DATA_SELECTED, images, 3);
-}
- * @endcode
- *
- */
-int aul_svc_add_data_array(bundle *b, const char *key, const char **val_array, int len);
-
-
-/**
- * @par Description:
- * This function sets a package name to launch application based on appsvc.
- *
- * @param[in] b bundle object
- * @param[in] pkg_name package name for explict launch
- *
- * @return 0 if success, negative value(<0) if fail
- * @retval AUL_SVC_RET_OK - success
- * @retval AUL_SVC_RET_ERROR - general error
- * @retval AUL_SVC_RET_EINVAL - invalid argument(content)
- *
- * @pre None.
- * @post None.
- * @see None.
- * @remarks None.
- *
- * @par Sample code:
- * @code
-#include <aul_svc.h>
-
-...
-{
- bundle *b = NULL;
-
- b = bundle_create();
-
- aul_svc_set_operation(b, AUL_SVC_OPERATION_PICK);
- aul_svc_set_mime(b,"image/jpg");
- aul_svc_set_pkgname(b, "org.tizen.mygallery");
-}
- * @endcode
- *
- */
-/* Deprecated API */
-int aul_svc_set_pkgname(bundle *b, const char *pkg_name); // __attribute__((deprecated));
-
-
-/**
- * @par Description:
- * This function sets a appid to launch application based on appsvc.
- *
- * @param[in] b bundle object
- * @param[in] appid application id for explict launch
- *
- * @return 0 if success, negative value(<0) if fail
- * @retval AUL_SVC_RET_OK - success
- * @retval AUL_SVC_RET_ERROR - general error
- * @retval AUL_SVC_RET_EINVAL - invalid argument(content)
- *
- * @pre None.
- * @post None.
- * @see None.
- * @remarks None.
- *
- * @par Sample code:
- * @code
-#include <aul_svc.h>
-
-...
-{
- bundle *b = NULL;
-
- b = bundle_create();
-
- aul_svc_set_operation(b, AUL_SVC_OPERATION_PICK);
- aul_svc_set_mime(b,"image/jpg");
- aul_svc_set_appid(b, "org.tizen.mygallery");
-}
- * @endcode
- *
- */
-int aul_svc_set_appid(bundle *b, const char *appid);
-
-
-/**
- * @par Description:
- * This function sets a appid to launch application based on appsvc.
- *
- * @param[in] b bundle object
- * @param[in] application category
- *
- * @return 0 if success, negative value(<0) if fail
- * @retval AUL_SVC_RET_OK - success
- * @retval AUL_SVC_RET_ERROR - general error
- * @retval AUL_SVC_RET_EINVAL - invalid argument(content)
- *
- * @pre None.
- * @post None.
- * @see None.
- * @remarks None.
- *
- * @par Sample code:
- * @code
-#include <aul_svc.h>
-
-...
-{
- bundle *b = NULL;
-
- b = bundle_create();
-
- aul_svc_set_operation(b, AUL_SVC_OPERATION_VIEW);
- aul_svc_set_category(b, "http://tizen.org/category/app/browser");
-}
- * @endcode
- *
- */
-int aul_svc_set_category(bundle *b, const char *category);
-
-/**
- * @par Description:
- * This API launch application based on appsvc.
- *
- * @param[in] b bundle to be passed to callee
- * @param[in] request_code request code
- * @param[in] cbfunc result callback function
- * @param[in] data user-supplied data passed to callback function
- *
- * @return callee's pid if success, negative value(<0) if fail
- * @retval callee's pid - success
- * @retval AUL_SVC_RET_ERROR - general error
- * @retval AUL_SVC_RET_EINVAL - invalid argument(content)
- * @retval AUL_SVC_RET_ENOMATCH - no matching result Error
- * @retval AUL_SVC_RET_ELAUNCH - failure on launching the app
- *
- * @pre None.
- * @post None.
- * @see None.
- * @remarks None.
- *
- * @par Sample code:
- * @code
-#include <aul_svc.h>
-
-...
-{
- bundle *b = NULL;
- static int num = 0;
-
- b = bundle_create();
-
- aul_svc_set_operation(b, AUL_SVC_OPERATION_PICK);
- aul_svc_set_mime(b,"image/jpg");
-
- return aul_svc_run_service(b, 0, cb_func, (void*)NULL);
-}
- * @endcode
- *
- */
-int aul_svc_run_service(bundle *b, int request_code, aul_svc_res_fn cbfunc, void *data);
-int aul_svc_run_service_for_uid(bundle *b, int request_code,
- aul_svc_res_fn cbfunc, void *data, uid_t uid);
-
-/**
- * @par Description:
- * This API use to get application list that is matched with given bundle.
- *
- * @param[in] b bundle to resolve application
- * @param[in] iter_fn iterator function
- * @param[in] data user-supplied data for iter_fn
- *
- * @return 0 if success, negative value(<0) if fail
- * @retval AUL_SVC_RET_OK - success
- * @retval AUL_SVC_RET_EINVAL - invalid argument(content)
- * @retval AUL_SVC_RET_ENOMATCH - no matching result Error
- *
- * @pre None.
- * @post None.
- * @see None.
- * @remarks None.
- *
- * @par Sample code:
- * @code
-#include <aul_svc.h>
-
-static int iter_fn(const char* appid, void *data)
-{
- printf("\t==========================\n");
- printf("\t appid: %s\n", appid);
- printf("\t==========================\n");
- return 0;
-}
-
-...
-{
- bundle *b = NULL;
- static int num = 0;
-
- b = bundle_create();
-
- aul_svc_set_operation(b, AUL_SVC_OPERATION_PICK);
- aul_svc_set_mime(b,"image/jpg");
-
- return aul_svc_get_list(b, iter_fn, (void*)NULL);
-}
- * @endcode
- *
- */
-int aul_svc_get_list(bundle *b, aul_svc_info_iter_fn iter_fn, void *data);
-int aul_svc_get_list_for_uid(bundle *b, aul_svc_info_iter_fn iter_fn,
- void *data, uid_t uid);
-
-/**
- * @par Description:
- * This API use to get default applications
- *
- * @param[in] iter_fn iterator function
- * @param[in] data user-supplied data for iter_fn
- *
- * @return 0 if success, negative value(<0) if fail
- * @retval AUL_SVC_RET_OK - success
- * @retval AUL_SVC_RET_EINVAL - invalid argument(content)
- * @retval AUL_SVC_RET_ENOMATCH - no matching result Error
- *
- * @pre None.
- * @post None.
- * @see None.
- * @remarks None.
- *
- * @par Sample code:
- * @code
-#include <aul_svc.h>
-
-static int iter_fn(const char* appid, void *data)
-{
- printf("\t==========================\n");
- printf("\t appid : %s\n", appid);
- printf("\t==========================\n");
- return 0;
-}
-
-...
-{
- return aul_svc_get_all_defapps(iter_fn, (void*)NULL);
-}
- * @endcode
- *
- */
-int aul_svc_get_all_defapps(aul_svc_info_iter_fn iter_fn, void *data);
-int aul_svc_get_all_defapps_for_uid(aul_svc_info_iter_fn iter_fn,
- void *data, uid_t uid);
-
-/**
- * @par Description:
- * This function gets a operation from bundle.
- *
- * @param[in] b bundle object
- *
- * @return Pointer for operation string if success, NULL if fail
- *
- * @pre None.
- * @post None.
- * @see None.
- * @remarks None.
- *
- * @par Sample code:
- * @code
-#include <aul_svc.h>
-
-...
-{
- char *val;
- val = aul_svc_get_operation(b);
-}
- * @endcode
- *
- */
-const char *aul_svc_get_operation(bundle *b);
-
-/**
- * @par Description:
- * This function gets a uri from bundle.
- *
- * @param[in] b bundle object
- *
- * @return Pointer for uri string if success, NULL if fail
- *
- * @pre None.
- * @post None.
- * @see None.
- * @remarks None.
- *
- * @par Sample code:
- * @code
-#include <aul_svc.h>
-
-...
-{
- char *val;
- val = aul_svc_get_uri(b);
-}
- * @endcode
- *
- */
-const char *aul_svc_get_uri(bundle *b);
-
-/**
- * @par Description:
- * This function gets a mime-type from bundle.
- *
- * @param[in] b bundle object
- *
- * @return Pointer for mime-type string if success, NULL if fail
- *
- * @pre None.
- * @post None.
- * @see None.
- * @remarks None.
- *
- * @par Sample code:
- * @code
-#include <aul_svc.h>
-
-...
-{
- char *val;
- val = aul_svc_get_mime(b);
-}
- * @endcode
- *
- */
-const char *aul_svc_get_mime(bundle *b);
-
-/**
- * @par Description:
- * This function gets a package name from bundle.
- *
- * @param[in] b bundle object
- *
- * @return Pointer for package name string if success, NULL if fail
- *
- * @pre None.
- * @post None.
- * @see None.
- * @remarks None.
- *
- * @par Sample code:
- * @code
-#include <aul_svc.h>
-
-...
-{
- char *val;
- val = aul_svc_get_pkgname(b);
-}
- * @endcode
- *
- */
-/* Deprecated API */
-const char *aul_svc_get_pkgname(bundle *b); // __attribute__((deprecated));
-
-/**
- * @par Description:
- * This function gets a application id from bundle.
- *
- * @param[in] b bundle object
- *
- * @return Pointer for application id string if success, NULL if fail
- *
- * @pre None.
- * @post None.
- * @see None.
- * @remarks None.
- *
- * @par Sample code:
- * @code
-#include <aul_svc.h>
-
-...
-{
- char *val;
- val = aul_svc_get_appid(b);
-}
- * @endcode
- *
- */
-const char *aul_svc_get_appid(bundle *b);
-
-/**
- * @par Description:
- * This function gets a application category from bundle.
- *
- * @param[in] b bundle object
- *
- * @return Pointer for application category string if success, NULL if fail
- *
- * @pre None.
- * @post None.
- * @see None.
- * @remarks None.
- *
- * @par Sample code:
- * @code
-#include <aul_svc.h>
-
-...
-{
- char *val;
- val = aul_svc_get_category(b);
-}
- * @endcode
- *
- */
-const char *aul_svc_get_category(bundle *b);
-
-/**
- * @par Description:
- * This function gets value from key.
- *
- * @param[in] b bundle object
- * @param[in] key key
- *
- * @return Pointer for value string if success, NULL if fail
- *
- * @pre None.
- * @post None.
- * @see None.
- * @remarks None.
- *
- * @par Sample code:
- * @code
-#include <aul_svc.h>
-
-...
-{
- char *val;
- val = aul_svc_get_data(b, AUL_SVC_DATA_CC);
-}
- * @endcode
- *
- */
-const char *aul_svc_get_data(bundle *b, const char *key);
-
-/**
- * @par Description:
- * This function gets value from key.
- *
- * @param[in] b bundle object
- * @param[in] key key
- * @param[out] len length of array
- *
- * @return Pointer for value string array if success, NULL if fail
- *
- * @pre None.
- * @post None.
- * @see None.
- * @remarks None.
- *
- * @par Sample code:
- * @code
-#include <aul_svc.h>
-
-...
-{
- char **val_array;
- int len;
- char *val;
-
- if(aul_svc_data_is_array(b, AUL_SVC_DATA_SELECTED))
- val_array = aul_svc_get_data_array(b, AUL_SVC_DATA_SELECTED, &len);
- else
- val = aul_svc_get_data(b, AUL_SVC_DATA_SELECTED);
-}
- * @endcode
- *
- */
-const char **aul_svc_get_data_array(bundle *b, const char *key, int *len);
-
-/**
- * @par Description:
- * This API create appsvc result bundle based on bundle received in reset event.
- *
- * @param[in] inb bundle received in reset event
- * @param[in] outb bundle to use for returning result
- *
- * @retval AUL_SVC_RET_OK - success
- * @retval AUL_SVC_RET_ERROR - general error
- * @retval AUL_SVC_RET_EINVAL - invalid argument(content)
- *
- * @pre None.
- * @post None.
- * @see aul_svc_send_result.
- * @remarks None.
- *
- * @par Sample code:
- * @code
-#include <aul_svc.h>
-
-...
-{
- struct appdata *ad = data;
- bundle* res_bundle;
-
- aul_svc_create_result_bundle(ad->b,&res_bundle);
- bundle_add(res_bundle, "result", "1");
- aul_svc_send_result(res_bundle, 0);
-}
- * @endcode
- *
- */
-int aul_svc_create_result_bundle(bundle *inb, bundle **outb);
-
-/**
- * @par Description:
- * This API send appsvc result to caller with bundle.
- *
- * @param[in] b Result data in bundle format
- * @param[in] result result value
- *
- * @retval AUL_SVC_RET_OK - success
- * @retval AUL_SVC_RET_ERROR - general error
- * @retval AUL_SVC_RET_EINVAL - invalid argument(content)
- *
- * @pre aul_svc_create_result_bundle.
- * @post None.
- * @see aul_svc_send_result.
- * @remarks None.
- *
- * @par Sample code:
- * @code
-#include <aul_svc.h>
-
-...
-{
- struct appdata *ad = data;
- bundle* res_bundle;
-
- aul_svc_create_result_bundle(ad->b,&res_bundle);
- bundle_add(res_bundle, "result", "1");
- aul_svc_send_result(res_bundle, 0);
-}
- * @endcode
- *
- */
-int aul_svc_send_result(bundle *b, aul_svc_result_val result);
-
-/**
- * @par Description:
- * This API ask a extra data is array or not.
- *
- * @param[in] b bundle object
- * @param[in] key key of extra data
- * @return true / false
- * @retval 1 a extra data is array.
- * @retval 0 a extra data is not array.
- *
- * @pre None.
- * @post None.
- * @see None.
- * @remarks None.
- *
- * @par Sample code:
- * @code
-#include <aul_svc.h>
-
- ...
-
- * int aul_svc_data_is_array(bundle *b, char *key)
- * {
- * return aul_svc_data_is_array(b, key);
- * }
- *
- * @endcode
- * @remark
- * None
-*
-*/
-int aul_svc_data_is_array(bundle *b, const char *key);
-
-int aul_svc_subapp_terminate_request_pid(int pid);
-
-/**
- * @par Description:
- * This function sets an uri to launch application based on appsvc.
- *
- * @param[in] b bundle object
- * @param[in] char *mode
- *
- * @return 0 if success, negative value(<0) if fail
- * @retval AUL_SVC_RET_OK - success
- * @retval AUL_SVC_RET_ERROR - general error
- * @retval AUL_SVC_RET_EINVAL - invalid argument(content)
- *
- * @pre None.
- * @post None.
- * @see None.
- * @remarks None.
- *
- * @par Sample code:
- * @code
-#include <aul_svc.h>
-
-...
-{
- aul_svc_set_launch_mode(app_control->data, mode);
-}
- * @endcode
- *
- */
-int aul_svc_set_launch_mode(bundle *b, const char *mode);
-
-/**
- * @par Description:
- * This function sets an uri to launch application based on appsvc.
- *
- * @param[in] b bundle object
- *
- * @return Pointer for launch mode string if success, NULL if fail
- *
- * @pre None.
- * @post None.
- * @see None.
- * @remarks None.
- *
- * @par Sample code:
- * @code
-#include <aul_svc.h>
-
-...
-{
- aul_svc_get_launch_mode(app_control->data);
-}
- * @endcode
- *
- */
-const char *aul_svc_get_launch_mode(bundle *b);
-
-int aul_svc_allow_transient_app(bundle *b, int wid);
-
-int aul_svc_request_transient_app(bundle *b, int callee_wid,
- aul_svc_host_res_fn cbfunc, void *data);
-
-int aul_svc_subscribe_launch_result(bundle *b, const char *event);
-
-/**
- * @par Description:
- * This function sets loader ID into bundle.
- *
- * @param[in] b Bundle object
- * @param[in] loader_id Loader ID from aul_add_loader() or PAD_LOADER_ID_DIRECT to launch apps without loader
- *
- * @return 0 if success, negative value(<0) if fail
- * @see aul_add_loader, aul_remove_loader
- * @remarks This API is only for Appfw internally.
- */
-int aul_svc_set_loader_id(bundle *b, int loader_id);
-
-/**
- * @par Description:
- * This function sets loader name into bundle. Launchpad will assign a static slot to launch an app.
- *
- * @param[in] b Bundle object
- * @param[in] loader_name Loader name to assign
- *
- * @return 0 if success, negative value(<0) if fail
- * @remarks This API is only for Appfw internally.
- */
-int aul_svc_set_loader_name(bundle *b, const char *loader_name);
-
-/**
- * @par Description:
- * This API sets the background launch mode.
- * If the background launch mode is enabled, a window of the callee process doesn't appear on the screen.
- *
- * @param[in] b Bundle object
- * @param[in] enabled boolean (true / false)
- *
- * @return 0 if success, negative value(<0) if fail
- * @remarks This API is only for Appfw internally.
- */
-int aul_svc_set_background_launch(bundle *b, int enabled);
-
-/**
- * @par Description:
- * This API gets an application ID by an alias application ID.
- *
- * @param[in] alias_appid An alias application ID
- * @param[out] appid An application ID
- *
- * @return 0 if success, negative value(<0) if fail
- */
-int aul_svc_get_appid_by_alias_appid(const char *alias_appid, char **appid);
-int aul_svc_get_appid_by_alias_appid_for_uid(const char *alias_appid,
- char **appid, uid_t uid);
-
-/**
- * @par Description:
- * Gets the instance ID.
- *
- * @param[in] b Bundle object
- *
- * @return Pointer for application id string if success, NULL if fail
- */
-const char *aul_svc_get_instance_id(bundle *b);
-
-/**
- * @par Description:
- * Sets the instance ID.
- *
- * @param[in] b Bundle object
- * @param[in] instance ID Instance ID
- *
- * @return 0 if success, negative value(<0) if fail
- */
-int aul_svc_set_instance_id(bundle *b, const char *instance_id);
-
-/**
- * @par Description:
- * Sends the launch request asynchronous.
- *
- * @param[in] b Bundle object
- * @param[in] request_code Request Code
- * @param[in] cbfunc Callback function
- * @param[in] data User data
- *
- * @return a pid of the callee on success,
- * otherwise a negative error value
- */
-int aul_svc_run_service_async(bundle *b, int request_code,
- aul_svc_res_fn cbfunc, void *data);
-int aul_svc_run_service_async_for_uid(bundle *b, int request_code,
- aul_svc_res_fn cbfunc, void *data, uid_t uid);
-
-
-/**
- * @brief Sends the launch request asynchronous.
- *
- * @param[in] b The bundle object
- * @param[in] request_code The request code
- * @param[in] cbfunc The reply callback function
- * @param[in] err_cb The result callback function
- * @param[in] user_data The user data to be passed to the callback function
- *
- * @return a pid of the callee on success,
- * otherwise a negative error value
- */
-int aul_svc_send_launch_request(bundle *b, int request_code,
- aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb,
- void *user_data);
-
-/**
- * @brief Sends the launch request asynchronous.
- *
- * @param[in] b The bundle object
- * @param[in] request_code The request code
- * @param[in] cbfunc The reply callback function
- * @param[in] err_cb The result callback function
- * @param[in] user_data The user data to be passed to the callback function
- * @param[in] uid The user ID
- *
- * @return a pid of the callee on success,
- * otherwise a negative error value
- */
-int aul_svc_send_launch_request_for_uid(bundle *b, int request_code,
- aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb,
- void *user_data, uid_t uid);
-
-/**
- * @brief Sends the launch request synchronous.
- *
- * @param[in] b The bundle object
- * @param[in] request_code The request code
- * @param[out] res_b The bundle object
- * @param[out] res The result
- * @param[in] uid The user ID
- *
- * @return a pid of the callee on success,
- * otherwise a negative error value
- */
-int aul_svc_send_launch_request_sync_for_uid(bundle *b, int request_code,
- bundle **res_b, aul_svc_result_val *res, uid_t uid);
-
-/**
- * @brief Sets the ID of the caller instance.
- * @since_tizen 5.5
- *
- * @param[in] b The bundle object
- * @param[in] instance_id The ID of the caller instance
- *
- * @return @c 0 on success,
- * otherwise a negative error value
- */
-int aul_svc_set_caller_instance_id(bundle *b, const char *instance_id);
-
-/**
- * @brief Sets the ID of the component.
- * @since_tizen 5.5
- *
- * @param[in] b The bundle object
- * @param[in] comp_id The ID of the component
- *
- * @return @c 0 on success,
- * otherwise a negative error value
- */
-int aul_svc_set_comp_id(bundle *b, const char *comp_id);
-
-/**
- * @brief Gets the ID of the component.
- * @since_tizen 5.5
- *
- * @param[in] b The bundle object
- *
- * @return @c a component ID on success,
- * otherwise a nullptr
- */
-const char *aul_svc_get_comp_id(bundle *b);
-
-/**
- * This API is only for App Framework internally.
- */
-int aul_svc_subapp_terminate_request(bundle *b, int pid);
-
-/**
- * @brief Sends the resumption request asynchronoulsy.
- * @since_tizen 5.5
- *
- * @param[in] b The bundle object
- * @param[in] request code The request code
- * @param[in] err_cb The result callback function
- * @param[in] user_data The user data to be passed to the callback function
- *
- * @return @c 0 on success,
- * otherwise a negative error value
- */
-int aul_svc_send_resume_request(bundle *b, int request_code,
- aul_svc_err_cb err_cb, void *user_data);
-int aul_svc_send_resume_request_for_uid(bundle *b, int request_code,
- aul_svc_err_cb err_cb, void *user_data, uid_t uid);
-
-/**
- * @par Description:
- * This function sets window position into bundle.
- *
- * @param[in] b Bundle object
- * @param[in] x x position of window
- * @param[in] y y position of window
- * @param[in] w width of window
- * @param[in] h height of window
- *
- * @return 0 if success, negative value(<0) if fail
- * @see aul_svc_get_window_position
- * @remarks This API is only for Appfw internally.
- */
-int aul_svc_set_window_position(bundle *b, int x, int y, int w, int h);
-
-/**
- * @par Description:
- * This function gets window position into bundle.
- *
- * @param[in] b Bundle object
- * @param[out] x x position of window
- * @param[out] y y position of window
- * @param[out] w width of window
- * @param[out] h height of window
- *
- * @return 0 if success, negative value(<0) if fail
- * @see aul_svc_set_window_position
- * @remarks This API is only for Appfw internally.
- */
-int aul_svc_get_window_position(bundle* b, int *x, int *y, int *w, int *h);
-
-/**
- * @deprecated Deprecated since 6.5.
- */
-int aul_svc_set_defapp(const char *op, const char *mime_type,
- const char *uri, const char *defapp) AUL_DEPRECATED_API;
-int aul_svc_set_defapp_for_uid(const char *op, const char *mime_type,
- const char *uri, const char *defapp, uid_t uid) AUL_DEPRECATED_API;
-
-/**
- * @deprecated Deprecated since 6.5.
- */
-int aul_svc_unset_defapp(const char *defapp) AUL_DEPRECATED_API;
-int aul_svc_unset_defapp_for_uid(const char *defapp, uid_t uid) AUL_DEPRECATED_API;
-
-/**
- * @deprecated Deprecated since 6.5.
- */
-int aul_svc_unset_all_defapps(void) AUL_DEPRECATED_API;
-int aul_svc_unset_all_defapps_for_uid(uid_t uid) AUL_DEPRECATED_API;
-
-/**
- * @deprecated Deprecated since 6.5
- */
-int aul_svc_is_defapp(const char *appid) AUL_DEPRECATED_API;
-int aul_svc_is_defapp_for_uid(const char *pkg_name, uid_t uid) AUL_DEPRECATED_API;
-
-/**
- * @deprecated Deprecated since 6.5.
- */
-int aul_svc_set_alias_appid(const char *alias_appid, const char *appid) AUL_DEPRECATED_API;
-int aul_svc_set_alias_appid_for_uid(const char *alias_appid, const char *appid,
- uid_t uid) AUL_DEPRECATED_API;
-
-/**
- * @deprecated Deprecated since 6.5.
- */
-int aul_svc_unset_alias_appid(const char *alias_appid) AUL_DEPRECATED_API;
-int aul_svc_unset_alias_appid_for_uid(const char *alias_appid, uid_t uid) AUL_DEPRECATED_API;
-
-/**
- * @deprecated Deprecated since 6.5.
- */
-int aul_svc_foreach_alias_info(
- void (*callback)(const char *, const char *, void *),
- void *user_data) AUL_DEPRECATED_API;
-int aul_svc_foreach_alias_info_for_uid(
- void (*callback)(const char *, const char *, void *),
- uid_t uid, void *user_data) AUL_DEPRECATED_API;
-
-/**
- * @deprecated Deprecated since 6.5.
- */
-int aul_svc_enable_alias_info(const char *appid) AUL_DEPRECATED_API;
-int aul_svc_enable_alias_info_for_uid(const char *appid, uid_t uid) AUL_DEPRECATED_API;
-
-/**
- * @deprecated Deprecated since 6.5.
- */
-int aul_svc_disable_alias_info(const char *appid) AUL_DEPRECATED_API;
-int aul_svc_disable_alias_info_for_uid(const char *appid, uid_t uid) AUL_DEPRECATED_API;
-
-/**
- * @deprecated Deprecated since 6.5.
- */
-int aul_svc_foreach_alias_info_by_appid(
- int (*callback)(const char *, const char *, void *),
- const char *appid, void *user_data) AUL_DEPRECATED_API;
-int aul_svc_foreach_alias_info_by_appid_for_uid(
- int (*callback)(const char *, const char *, void *),
- const char *appid, uid_t uid, void *user_data) AUL_DEPRECATED_API;
-
-/**
- * @deprecated Deprecated since 6.5.
- */
-int aul_svc_foreach_allowed_info(
- int (*callback)(const char *, const char *, void *),
- void *user_data) AUL_DEPRECATED_API;
-int aul_svc_foreach_allowed_info_for_uid(
- int (*callback)(const char *, const char *, void *),
- uid_t uid, void *user_data) AUL_DEPRECATED_API;
-
-/**
- * @deprecated Deprecated since 6.5
- */
-int aul_svc_foreach_allowed_info_by_appid(
- int (*callback)(const char *, const char *, void *),
- const char *appid, void *user_data) AUL_DEPRECATED_API;
-int aul_svc_foreach_allowed_info_by_appid_for_uid(
- int (*callback)(const char *, const char *, void *),
- const char *appid, uid_t uid, void *user_data) AUL_DEPRECATED_API;
-
-#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.
- */
-
-#pragma once
-
-#include <bundle.h>
-#include <sys/types.h>
-
-#include "aul_svc.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @brief The AUL Service information handle.
- * @since_tizen 5.5
- * @remarks This API is only for App Framework internally.
- */
-typedef void *aul_svc_info_h;
-
-/**
- * @brief Creates the AUL Service information handle.
- * @since_tizen 5.5
- *
- * @param[in] b The bundle object
- * @param[out] h The AUL Service information handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #AUL_SVC_RET_OK Successful
- * @retval #AUL_SVC_RET_EINVAL Invalid parameter
- * @retval #AUL_SVC_RET_ERROR Out of memory
- */
-int aul_svc_info_create(bundle *b, aul_svc_info_h *h);
-
-/**
- * @brief Gets the operation to be performed.
- * @since_tizen 5.5
- *
- * @param[in] h The AUL Service information handle
- * @param[out] operation The operation to be performed
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #AUL_SVC_RET_OK Successful
- * @retval #AUL_SVC_RET_EINVAL Invalid parameter
- * @retval #AUL_SVC_RET_ERROR Out of memory
- */
-int aul_svc_info_get_operation(aul_svc_info_h h, char **operation);
-
-/**
- * @brief Gets the URI of the data.
- * @since_tizen 5.5
- *
- * @param[in] h The AUL Service information handle
- * @param[out] uri The URI of the data
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #AUL_SVC_RET_OK Successful
- * @retval #AUL_SVC_RET_EINVAL Invalid parameter
- * @retval #AUL_SVC_RET_ERROR Out of memory
- */
-int aul_svc_info_get_uri(aul_svc_info_h h, char **uri);
-
-/**
- * @brief Gets the scheme of the URI.
- * @since_tizen 5.5
- *
- * @param[in] h The AUL Service information handle
- * @param[out] uri_scheme The scheme of the URI
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #AUL_SVC_RET_OK Successful
- * @retval #AUL_SVC_RET_EINVAL Invalid parameter
- * @retval #AUL_SVC_RET_ERROR Out of memory
- */
-int aul_svc_info_get_uri_scheme(aul_svc_info_h h, char **uri_scheme);
-
-/**
- * @brief Gets the host of the URI.
- * @since_tizen 5.5
- *
- * @param[in] h The AUL Service information handle
- * @param[out] uri_host The host of the URI
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #AUL_SVC_RET_OK Successful
- * @retval #AUL_SVC_RET_EINVAL Invalid parameter
- * @retval #AUL_SVC_RET_ERROR Out of memory
- */
-int aul_svc_info_get_uri_host(aul_svc_info_h h, char **uri_host);
-
-/**
- * @brief Gets the explicit MIME type of the data.
- * @since_tizen 5.5
- *
- * @param[in] h The AUL Service information handle
- * @param[out] mime The explicit MIME type of the data
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #AUL_SVC_RET_OK Successful
- * @retval #AUL_SVC_RET_EINVAL Invalid parameter
- * @retval #AUL_SVC_RET_ERROR Out of memory
- */
-int aul_svc_info_get_mime(aul_svc_info_h h, char **mime);
-
-/**
- * @brief Gets the type of the MIME type.
- * @since_tizen 5.5
- *
- * @param[in] h The AUL Service information handle
- * @param[out] mime_type The type of the MIME type
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #AUL_SVC_RET_OK Successful
- * @retval #AUL_SVC_RET_EINVAL Invalid parameter
- * @retval #AUL_SVC_RET_ERROR Out of memory
- */
-int aul_svc_info_get_mime_type(aul_svc_info_h h, char **mime_type);
-
-/**
- * @brief Gets the subtype of the MIME type.
- * @since_tizen 5.5
- *
- * @param[in] h The AUL Service information handle
- * @param[out] mime_subtype The subtype of the MIME type
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #AUL_SVC_RET_OK Successful
- * @retval #AUL_SVC_RET_EINVAL Invalid parameter
- * @retval #AUL_SVC_RET_ERROR Out of memory
- */
-int aul_svc_info_get_mime_subtype(aul_svc_info_h h, char **mime_subtype);
-
-/**
- * @brief Destroys the AUL Service information handle.
- * @since_tizen 5.5
- *
- * @param[in] h The AUL Service information handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #AUL_SVC_RET_OK Successful
- * @retval #AUL_SVC_RET_EINVAL Invalid parameter
- */
-int aul_svc_info_destroy(aul_svc_info_h h);
-
-/**
- * @brief Resolves the app control.
- * @since_tizen 6.0
- * @remarks The @appid_array should be released using aul_svc_free_appid_array().
- *
- * @param[in] b The bundle object
- * @param[in] uid The user ID
- * @param[out] appid_array The array pointer of the appid
- * @param[out] len The array length
- * @return @c 0 on success,
- * otherwise a negative error value
- * @remarks This API is only for App Framework internally.
- * @see aul_svc_free_appid_array()
- */
-int aul_svc_resolve(bundle *b, uid_t uid, char ***appid_array,
- unsigned int *len);
-
-/**
- * @brief Gets an array of application ID.
- * @since_tizen 6.0
- * @remarks The @appid_array should be released using aul_svc_free_appid_array().
- *
- * @param[in] b The bundle object
- * @param[in] uid The user ID
- * @param[out] appid_array The array pointer of the appid
- * @param[out] len The array length
- * @return @c 0 on success,
- * otherwise a negative error value
- * @remarks This API is only for App Framework internally.
- * @see aul_svc_free_appid_array()
- */
-int aul_svc_get_appid_array(bundle *b, uid_t uid, char ***appid_array,
- unsigned int *len);
-
-/**
- * @brief Release an array of application ID.
- * @since_tizen 6.0
- *
- * @param[in] appid_array The array pointer of the appid
- * @param[in] len The array length
- * @remarks This API is only for App Framework internally.
- */
-void aul_svc_free_appid_array(char **appid_array, unsigned int len);
-
-#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_WATCH_CONTROL_H__
-#define __AUL_WATCH_CONTROL_H__
-
-#include <bundle.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @brief The watch control handle.
- * @since_tizen 5.5
- */
-typedef void *aul_watch_control_h;
-
-/**
- * @brief Called when another application sends a launch request to the application.
- * @details Before calling app_control_cb() function, this callback function is called.
- * @since_tizen 5.5
- *
- * @param[in] b The bundle object
- * @param[in] user_data The user data passed from the callback registration function
- * @see aul_watch_control_add_handler()
- *
- * @remarks This is only for App Framework internally.
- */
-typedef void (*aul_watch_control_cb)(bundle *b, void *user_data);
-
-/**
- * @brief Adds the watch control handle.
- * @since_tizen 5.5
- *
- * @param[in] callback The callback function
- * @param[in] user_data The user data to be passed to the callback function
- * @param[out] handle The watch control handle
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @see aul_watch_control_remove_handler()
- * @see aul_watch_control_cb()
- *
- * @remarks This is only for App Framework internally.
- */
-int aul_watch_control_add_handler(aul_watch_control_cb callback,
- void *user_data, aul_watch_control_h *handle);
-
-/**
- * @brief Removes registered watch control handle.
- * @since_tizen 5.5
- *
- * @param[in] handle The watch control handle
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @see aul_watch_control_add_handler()
- *
- * @remarks This is only for App Framework internally.
- */
-int aul_watch_control_remove_handler(aul_watch_control_h handle);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __AUL_WATCH_CONTROL_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2018 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_WATCHDOG_H__
-#define __AUL_WATCHDOG_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @brief Enables watchdog timer.
- *
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_watchdog_enable(void);
-
-/**
- * @brief Disables watchdog timer.
- *
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_watchdog_disable(void);
-
-/**
- * @brief Kicks whatchdog timer.
- *
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_watchdog_kick(void);
-
-/**
- * @brief Starts watchdog timer.
- *
- * @param[in] interval The interval of the timer
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-void aul_watchdog_start(unsigned int interval);
-
-/**
- * @brief Stops watchdog timer.
- *
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-void aul_watchdog_stop(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __AUL_WATCHDOG_H__ */
+++ /dev/null
-/*
- * Copyright (c) 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
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @par Description:
- * Widget information handle.
- */
-typedef struct aul_widget_info_s *aul_widget_info_h;
-
-/**
- * @par Description:
- * Called to get the widget information
- * @param[in] info The handle of the widget information
- * @param[in] user_data The user data passed from the foreach function
- *
- * @pre aul_widget_info_foreach() will invoke this callback.
- * @see aul_widget_info_foreach()
- */
-typedef void (*aul_widget_info_cb)(aul_widget_info_h info, void *user_data);
-
-/**
- * @par Description:
- * Retrieves all widget information of running widget applications.
- * @privlevel platform
- * @privilege %http://tizen.org/privilege/internal/default/platform
- * @param[in] callback The callback function to invoke
- * @param[in] user_data The user data to be passed to the callback function
- * @return @c 0 on success,
- * otherwise a negative error value
- * @post This function invokes aul_widget_info_cb() for each widget information.
- * @see aul_widget_info_cb()
- */
-int aul_widget_info_foreach(aul_widget_info_cb callback, void *user_data);
-int aul_widget_info_foreach_for_uid(aul_widget_info_cb callback,
- void *user_data, uid_t uid);
-
-/**
- * @par Description:
- * Gets the process ID with the given handle.
- * @param[in] info The handle of the widget information
- * @param[out] pid The process ID
- * @return @c 0 on success,
- * otherwise a negative error value
- */
-int aul_widget_info_get_pid(aul_widget_info_h info, pid_t *pid);
-
-/**
- * @par Description:
- * Gets the surface ID with the given handle.
- * @param[in] info The handle of the widget information
- * @param[out] surf The surface ID
- * @return @c 0 on success,
- * otherwise a negative error value
- */
-int aul_widget_info_get_surface_id(aul_widget_info_h info, unsigned int *surf);
-
-/**
- * @par Description:
- * Gets the widget ID with the given handle.
- * @param[in] info The handle of the widget information
- * @param[out] widget_id The widget ID
- * @return @c 0 on success,
- * otherwise a negative error value
- * @remarks The @a widget_id must be released using free().
- */
-int aul_widget_info_get_widget_id(aul_widget_info_h info, char **widget_id);
-
-/**
- * @par Description:
- * Gets the widget instance ID with the given handle.
- * @param[in] info The handle of the widget information
- * @param[out] instance_id The widget instance ID
- * @return @c 0 on success,
- * otherwise a negative error value
- * @remarks The @a instance_id must be released using free().
- */
-int aul_widget_info_get_instance_id(aul_widget_info_h info, char **instance_id);
-
-/**
- * @par Description:
- * Gets the application ID with the given handle.
- * @param[in] info The handle of the widget information
- * @param[out] app_id The application ID
- * @return @c 0 on success,
- * otherwise a negative error value
- * @remarks The @a app_id must be released using free().
- */
-int aul_widget_info_get_app_id(aul_widget_info_h info, char **app_id);
-
-/**
- * @par Description:
- * Gets the package ID with the given handle.
- * @param[in] info The handle of the widget information
- * @param[out] package_id The package ID
- * @return @c 0 on success,
- * otherwise a negative error value
- * @remarks The @a app_id must be released using free().
- */
-int aul_widget_info_get_package_id(aul_widget_info_h info, char **package_id);
-
-/**
- * @par Description:
- * Gets the path with the given handle.
- * @param[in] info The handle of the widget information
- * @param[out] app_path The path of the widget application
- * @return @c 0 on success,
- * otherwise a negative error value
- * @remarks The @a app_id must be released using free().
- */
-int aul_widget_info_get_app_path(aul_widget_info_h info, char **app_path);
-
-/**
- * @par Description:
- * Change app status.
- * @param[in] widget_id The widget app id
- * @param[in] status The widget app status
- * @return @c 0 on success,
- * otherwise a negative error value
- */
-int aul_widget_instance_change_status(const char *widget_id, const char *status);
-
-/**
- * @par Description:
- * Writes file log.
- * @param[in] tag The log tag
- * @param[in] format The log foramt
- * @return @c 0 on success,
- * otherwise a negative error value
- */
-int aul_widget_write_log(const char *tag, const char *format, ...);
-
-int aul_widget_service_set_disable(const char *widget_id, bool is_disable);
-
-/**
- * @brief Called when the widget event is delivered.
- * @since_tizen 5.5
- *
- * @param[in] event_name The event name
- * @param[in] event_data The event data
- * @param[in] user_data The user data passed from the registration function
- *
- * @see aul_widget_set_event_cb()
- */
-typedef void (*aul_widget_event_cb)(const char *event_name, bundle *event_data,
- void *user_data);
-
-/**
- * @brief Definition for AUL widget event: Saves image.
- * @since_tizen 5.5
- */
-#define AUL_WIDGET_EVENT_SAVE_IMAGE "save.image"
-
-/**
- * @brief Registers the event callback function.
- * @since_tizen 5.5
- *
- * @param[in] callback The callback function
- * @param[in] user_data The user data to be passed to the callback function
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @see aul_widget_event_cb()
- * @see aul_widget_unset_event_cb()
- */
-int aul_widget_set_event_cb(aul_widget_event_cb callback, void *user_data);
-
-/**
- * @brief Unregisters the event callback function.
- * @since_tizen 5.5
- *
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @see aul_widget_set_event_cb()
- */
-int aul_widget_unset_event_cb(void);
-
-/**
- * @brief Sends the widget event.
- * @since_tizen 5.5
- * @privlevel platform
- * @privilege %http://tizen.org/privilege/internal/default/platform
- *
- * @param[in] event_name The event name
- * @param[in] event_data The event data
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @see aul_widget_set_event_cb()
- */
-int aul_widget_send_event(const char *event_name, bundle *event_data);
-
-
-int aul_widget_send_status_to_service(const char *class_id,
- const char *instance_id, const char *sender_pkgid, int status);
-
-int aul_widget_send_status_to_viewer(const char *class_id,
- const char *instance_id, const char *viewer_endpoint,
- int status, int err, bundle *extra);
-
-#ifdef __cplusplus
-}
-#endif
+++ /dev/null
-/*
- * Copyright (c) 2017 - 2021 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 <stdbool.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef void *aul_window_info_h;
-typedef void *aul_window_stack_h;
-
-/**
- * @par Description:
- * This API creates the window stack handle.
- * @par Purpose:
- * To get information of windows, the stack handle is needed.
- *
- * @param[out] handle Handle for the window stack
- * @return 0 if success, negative value(<0) if fail
- *
- * @see
- * aul_window_stack_del
- * @remark
- * It should be freed by aul_window_stack_del function.
-*/
-int aul_window_stack_get(aul_window_stack_h *handle);
-
-/**
- * @par Description:
- * This API destroy the window stack handle.
- *
- * @param[in] handle Handle for the window stack
- * @return 0 if success, negative value(<0) if fail
- *
- * @see
- * aul_window_stack_get
-*/
-int aul_window_stack_del(aul_window_stack_h handle);
-
-/**
- * @par Description:
- * This API invokes iterator function for each window.
- *
- * @param[in] handle Handle for the window stack
- * @param[in] iter_cb The iteration callback
- * @param[in] data The data which will be sent to the iterator
- * @return 0 if success, negative value(<0) if fail
- *
-*/
-int aul_window_stack_foreach(aul_window_stack_h handle,
- void (*iter_cb)(aul_window_info_h info, void *data), void *data);
-
-/**
- * @par Description:
- * This API gets the global resource ID from the window handle.
- *
- * @param[in] info Handle for the window
- * @param[out] rid Global resource ID
- *
- * @return 0 if success, negative value(<0) if fail
- *
-*/
-int aul_window_stack_info_get_resource_id(aul_window_info_h info, unsigned int *rid);
-
-/**
- * @par Description:
- * This API gets the process ID from the window handle.
- *
- * @param[in] info Handle for the window
- * @param[out] pid Process ID
- *
- * @return 0 if success, negative value(<0) if fail
- *
-*/
-int aul_window_info_get_pid(aul_window_info_h info, int *pid);
-
-/**
- * @par Description:
- * This API gets the process ID for its parent window from the window handle.
- *
- * @param[in] info Handle for the window
- * @param[out] pid Process ID
- *
- * @return 0 if success, negative value(<0) if fail
- *
- * @remark
- * pid will be -1 when the parent window is not exist
- *
-*/
-int aul_window_info_get_parent_pid(aul_window_info_h info, int *ppid);
-
-/**
- * @par Description:
- * This API gets the process ID for its ancestor window from the window handle.
- *
- * @param[in] info Handle for the window
- * @param[out] pid Process ID
- *
- * @return 0 if success, negative value(<0) if fail
- *
- * @remark
- * pid will be -1 when the ancestor window is not exist
- *
-*/
-int aul_window_info_get_ancestor_pid(aul_window_info_h info, int *apid);
-
-/**
- * @par Description:
- * This API gets the window visibility from the window handle.
- *
- * @param[in] info Handle for the window
- * @param[out] visibility visibility
- * 0 Fully visible state
- * 1 Partially visible state
- * 2 Invisible state by other window
- * -1 Invisible state
- *
- * @return 0 if success, negative value(<0) if fail
- *
-*/
-int aul_window_info_get_visibility(aul_window_info_h info, int *visibility);
-
-/**
- * @par Description:
- * This API gets the flag value of supporting alpha blending.
- *
- * @param[in] info Handle for the window
- * @param[out] alpha The flag value of supporting alpha blending
- *
- * @return 0 if success, negative value(<0) if fail
- *
-*/
-int aul_window_info_has_alpha(aul_window_info_h info, bool *alpha);
-
-/**
- * @par Description:
- * This API gets the flag value of the focused state.
- *
- * @param[in] info Handle for the window
- * @param[out] focused The flag value of the focused state
- *
- * @return 0 if success, negative value(<0) if fail
- *
-*/
-int aul_window_info_is_focused(aul_window_info_h info, bool *focused);
-
-typedef enum _aul_window_notification_level_e {
- AUL_WINDOW_NOTIFICATION_LEVEL_NONE = 0,
- AUL_WINDOW_NOTIFICATION_LEVEL_DEFAULT = 10,
- AUL_WINDOW_NOTIFICATION_LEVEL_MEDIUM = 20,
- AUL_WINDOW_NOTIFICATION_LEVEL_HIGH = 30,
- AUL_WINDOW_NOTIFICATION_LEVEL_TOP = 40,
- AUL_WINDOW_NOTIFICATION_LEVEL_PRIVILEGE = 99,
-} aul_window_notification_level_e;
-
-/**
- * @par Description:
- * This API gets the window notification level from the window handle.
- *
- * @param[in] info Handle for the window
- * @param[out] level Notification level
- * @return 0 if success, negative value(<0) if fail
- *
-*/
-int aul_window_info_get_notification_level(aul_window_info_h info,
- aul_window_notification_level_e *level);
-
-/**
- * @par Description:
- * This API gets the location and the size from window handle.
- *
- * @param[in] info Handle for the window
- * @param[out] x Position x
- * @param[out] y Position y
- * @param[out] w Width
- * @param[out] h Height
- *
- * @return 0 if success, negative value(<0) if fail
- *
-*/
-int aul_window_info_get_geometry(aul_window_info_h info, int *x, int *y, int *w, int *h);
-
-
-/**
- * @par Description:
- * This API gets pid for the focused window.
- *
- * @param[out] pid focused pid
- *
- * @return 0 if success, negative value(<0) if fail
- *
-*/
-int aul_window_get_focused_pid(pid_t *pid);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_window_attach(const char *parent_appid, const char *child_appid);
-
-/*
- * This API is only for Appfw internally.
- */
-int aul_window_detach(const char *child_appid);
-
-/**
- * @par Description:
- * This API gets the flag value of the opaque state.
- *
- * @param[in] info Handle for the window
- * @param[out] opaque The flag value of the opaque state.
- *
- * @return 0 on success, otherwise a negative error value.
- */
-int aul_window_info_get_opaque(aul_window_info_h info, bool *opaque);
-
-/**
- * @brief Attach the window below the window of the parent application.
- * @since_tizen 6.5
- * @remarks This function is only available for platform level signed applications.
- *
- * @param[in] parent_appid The application ID of the parent
- * @param[in] child_appid The application ID of the child
- * @return @c 0 on success,
- * otherwise a negative error value
- * @remarks This function is only for App Framework internally.
- */
-int aul_window_attach_below(const char *parent_appid, const char *child_appid);
-
-/**
- * @brief Called when the window of the application is appeared.
- * @since_tizen 6.5
- * @details When the window is appeared, the event_name is "Appeared".
- *
- * @param[in] event_name The event name
- * @param[in] appid The application ID
- * @param[in] wid The window ID
- * @param[in] pid The process ID
- * @param[in] user_data The user data passed from the registration function
- * @see aul_window_register_event_cb()
- * @see aul_window_deregister_event_cb()
- */
-typedef void (*aul_window_event_cb)(const char *event_name, const char *appid, int wid, int pid, void *user_data);
-
-/**
- * @brief Registers the window event callback function.
- * @since_tizen 6.5
- *
- * @param[in] callback The callback function
- * @param[in] user_data The user data to be passed to the callback function
- * @return @c 0 on success,
- * otherwise a negative error value
- */
-int aul_window_register_event_cb(aul_window_event_cb callback, void *user_data);
-
-/**
- * @brief Deregisters the window event callback function.
- * @since_tizen 6.5
- */
-void aul_window_deregister_event_cb(void);
-
-#ifdef __cplusplus
-}
-#endif
%__make %{?_smp_mflags}
sqlite3 .appsvc.db < ./data/appsvc_db.sql
-sqlite3 .component.db < ./parser/component/data/component_db.sql
+sqlite3 .component.db < ./src/parser/component/data/component_db.sql
%check
-export LD_LIBRARY_PATH="../../"
+export LD_LIBRARY_PATH="../../src/aul"
ctest -V
%if 0%{?gcov:1}
+++ /dev/null
-ADD_SUBDIRECTORY(boot-sequencer)
-ADD_SUBDIRECTORY(component)
-ADD_SUBDIRECTORY(exec-checker)
-ADD_SUBDIRECTORY(metadata)
+++ /dev/null
-SET(TARGET_BOOT_SEQUENCER_PARSER_PLUGIN "boot-sequencer")
-
-SET(SHARED_DIR "${CMAKE_INSTALL_PREFIX}/share")
-
-SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall -Werror -Winline")
-
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}
- BOOT_SEQUENCER_PARSER_PLUGIN_SRCS)
-
-ADD_LIBRARY(${TARGET_BOOT_SEQUENCER_PARSER_PLUGIN} SHARED
- ${BOOT_SEQUENCER_PARSER_PLUGIN_SRCS})
-
-TARGET_INCLUDE_DIRECTORIES(${TARGET_BOOT_SEQUENCER_PARSER_PLUGIN}
- PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
-
-TARGET_LINK_LIBRARIES(${TARGET_BOOT_SEQUENCER_PARSER_PLUGIN} PUBLIC "-ldl")
-
-APPLY_PKG_CONFIG(${TARGET_BOOT_SEQUENCER_PARSER_PLUGIN} PUBLIC
- BUNDLE_DEPS
- DLOG_DEPS
- GLIB_DEPS
- LIBTZPLATFORM_CONFIG_DEPS
- LIBXML_DEPS
- PKGMGR_INFO_DEPS
- PKGMGR_INSTALLER_DEPS
-)
-
-INSTALL(TARGETS ${TARGET_BOOT_SEQUENCER_PARSER_PLUGIN}
- DESTINATION ${SYSCONF_INSTALL_DIR}/package-manager/parserlib)
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/boot-sequencer.info
- DESTINATION ${SHARED_DIR}/parser-plugins)
+++ /dev/null
-/*
- * Copyright (c) 2022 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 "app_info.hh"
-
-namespace boot_sequencer {
-
-AppInfo::AppInfo(std::string appid) : appid_(std::move(appid)) {}
-
-const std::string& AppInfo::GetAppId() const {
- return appid_;
-}
-
-const std::string& AppInfo::GetAfter() const {
- return after_;
-}
-
-const std::string& AppInfo::GetBefore() const {
- return before_;
-}
-
-const std::string& AppInfo::GetRequires() const {
- return requires_;
-}
-
-const std::string& AppInfo::GetConflicts() const {
- return conflicts_;
-}
-
-const std::string& AppInfo::GetArgs() const {
- return args_;
-}
-
-const std::string& AppInfo::GetVconf() const {
- return vconf_;
-}
-
-const std::string& AppInfo::GetPathExists() const {
- return path_exists_;
-}
-
-const std::string& AppInfo::GetBackgroundLaunch() const {
- return background_launch_;
-}
-
-const std::string& AppInfo::GetWaitUntilReady() const {
- return wait_until_ready_;
-}
-
-const std::string& AppInfo::GetTimeout() const {
- return timeout_;
-}
-
-void AppInfo::SetAfter(std::string after) {
- if (after_.empty())
- after_ = std::move(after);
- else
- after_ += "|" + std::move(after);
-}
-
-void AppInfo::SetBefore(std::string before) {
- if (before_.empty())
- before_ = std::move(before);
- else
- before_ += "|" + std::move(before);
-}
-
-void AppInfo::SetRequires(std::string requires_dep) {
- if (requires_.empty())
- requires_ = std::move(requires_dep);
- else
- requires_ += "|" + std::move(requires_dep);
-}
-
-void AppInfo::SetConflicts(std::string conflicts) {
- if (conflicts_.empty())
- conflicts_ = std::move(conflicts);
- else
- conflicts_ += "|" + std::move(conflicts);
-}
-
-void AppInfo::SetArgs(std::string args) {
- args_ = std::move(args);
-}
-
-void AppInfo::SetVconf(std::string vconf) {
- if (vconf_.empty())
- vconf_ = std::move(vconf);
- else
- vconf_ += "|" + std::move(vconf);
-}
-
-void AppInfo::SetPathExists(std::string path_exists) {
- if (path_exists_.empty())
- path_exists_ = std::move(path_exists);
- else
- path_exists_ += "|" + std::move(path_exists);
-}
-
-void AppInfo::SetBackgroundLaunch(std::string background_launch) {
- background_launch_ = std::move(background_launch);
-}
-
-void AppInfo::SetWaitUntilReady(std::string wait_until_ready) {
- wait_until_ready_ = std::move(wait_until_ready);
-}
-
-void AppInfo::SetTimeout(std::string timeout) {
- timeout_ = std::move(timeout);
-}
-
-} // namespace boot_sequencer
+++ /dev/null
-/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef APP_INFO_HH_
-#define APP_INFO_HH_
-
-#include <string>
-
-namespace boot_sequencer {
-
-class AppInfo {
- public:
- explicit AppInfo(std::string appid);
- virtual ~AppInfo() = default;
-
- const std::string& GetAppId() const;
- const std::string& GetAfter() const;
- const std::string& GetBefore() const;
- const std::string& GetRequires() const;
- const std::string& GetConflicts() const;
- const std::string& GetArgs() const;
- const std::string& GetVconf() const;
- const std::string& GetPathExists() const;
- const std::string& GetBackgroundLaunch() const;
- const std::string& GetWaitUntilReady() const;
- const std::string& GetTimeout() const;
-
- void SetAfter(std::string after);
- void SetBefore(std::string before);
- void SetRequires(std::string requires_dep);
- void SetConflicts(std::string conflicts);
- void SetArgs(std::string args);
- void SetVconf(std::string vconf);
- void SetPathExists(std::string path_exists);
- void SetBackgroundLaunch(std::string background_launch);
- void SetWaitUntilReady(std::string wait_until_ready);
- void SetTimeout(std::string timeout);
-
- private:
- std::string appid_;
- std::string after_;
- std::string before_;
- std::string requires_;
- std::string conflicts_;
- std::string args_;
- std::string vconf_;
- std::string path_exists_;
- std::string background_launch_;
- std::string wait_until_ready_;
- std::string timeout_;
-};
-
-} // namespace boot_sequencer
-
-#endif // APP_INFO_HH_
+++ /dev/null
-/*
- * Copyright (c) 2022 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 <tzplatform_config.h>
-
-#include <memory>
-
-#include "appsvc_db.hh"
-#include "log_private.hh"
-
-namespace boot_sequencer {
-namespace {
-
-constexpr const uid_t ROOT_UID = 0;
-
-const uid_t GLOBAL_USER = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
-
-constexpr const char QUERY_SELECT[] =
- "SELECT appid, after, before, requires, conflicts, vconf, path_exists, "
- "args, background_launch, wait_until_ready, timeout "
- "FROM boot_sequence WHERE package = ?;";
-constexpr const char QUERY_INSERT_OR_REPLACE[] =
- "INSERT OR REPLACE INTO boot_sequence(package, appid, after, before, "
- "requires, conflicts, vconf, path_exists, args, background_launch, "
- "wait_until_ready, timeout) "
- "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
-constexpr const char QUERY_DELETE[] =
- "DELETE FROM boot_sequence WHERE package = ?;";
-
-} // namespace
-
-AppSvcDB::AppSvcDB(uid_t uid) : Database(GetDBPath(uid)) {
-}
-
-AppSvcDB::~AppSvcDB() = default;
-
-std::vector<std::shared_ptr<AppInfo>> AppSvcDB::Select(
- const std::string& package) {
- std::vector<std::string> bind_text { package };
- auto cursor = Query(QUERY_SELECT, bind_text);
- if (cursor == nullptr)
- return {};
-
- cursor->Execute();
- int idx;
- std::vector<std::shared_ptr<AppInfo>> app_infos;
- while (!cursor->IsDone()) {
- idx = 0;
- auto appid = cursor->GetColumn(idx++);
- auto app_info = std::make_shared<AppInfo>(std::move(appid));
- app_info->SetAfter(cursor->GetColumn(idx++));
- app_info->SetBefore(cursor->GetColumn(idx++));
- app_info->SetRequires(cursor->GetColumn(idx++));
- app_info->SetConflicts(cursor->GetColumn(idx++));
- app_info->SetVconf(cursor->GetColumn(idx++));
- app_info->SetPathExists(cursor->GetColumn(idx++));
- app_info->SetArgs(cursor->GetColumn(idx++));
- app_info->SetBackgroundLaunch(cursor->GetColumn(idx++));
- app_info->SetWaitUntilReady(cursor->GetColumn(idx++));
- app_info->SetTimeout(cursor->GetColumn(idx++));
- app_infos.push_back(std::move(app_info));
- cursor->Next();
- }
-
- return app_infos;
-}
-
-void AppSvcDB::Insert(const std::string& package,
- const std::shared_ptr<AppInfo>& app_info) {
- std::vector<std::string> bind_text {
- package,
- app_info->GetAppId(),
- app_info->GetAfter(),
- app_info->GetBefore(),
- app_info->GetRequires(),
- app_info->GetConflicts(),
- app_info->GetVconf(),
- app_info->GetPathExists(),
- app_info->GetArgs(),
- app_info->GetBackgroundLaunch(),
- app_info->GetWaitUntilReady(),
- app_info->GetTimeout()
- };
- auto cursor = Query(QUERY_INSERT_OR_REPLACE, bind_text);
- if (cursor == nullptr)
- THROW(-1);
-
- if (!cursor->Execute())
- THROW(-1);
-}
-
-void AppSvcDB::Delete(const std::string& package) {
- std::vector<std::string> bind_text { package };
- auto cursor = Query(QUERY_DELETE, bind_text);
- if (cursor == nullptr)
- THROW(-1);
-
- if (!cursor->Execute())
- THROW(-1);
-}
-
-std::string AppSvcDB::GetDBPath(uid_t uid) {
- std::string db_path;
- if (uid == ROOT_UID || uid == GLOBAL_USER) {
- db_path = std::string(tzplatform_getenv(TZ_SYS_DB)) + "/.appsvc.db";
- } else {
- db_path = std::string(tzplatform_getenv(TZ_SYS_DB)) + "/user/" +
- std::to_string(uid) + "/.appsvc.db";
- }
- return db_path;
-}
-
-} // namespace boot_sequencer
+++ /dev/null
-/*
- * Copyright (c) 2022 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 APPSVC_DB_HH_
-#define APPSVC_DB_HH_
-
-#include <unistd.h>
-
-#include <memory>
-#include <string>
-#include <vector>
-
-#include "app_info.hh"
-#include "database.hh"
-
-namespace boot_sequencer {
-
-class AppSvcDB : public Database {
- public:
- explicit AppSvcDB(uid_t uid);
- virtual ~AppSvcDB();
-
- std::vector<std::shared_ptr<AppInfo>> Select(const std::string& package);
- void Insert(const std::string& package,
- const std::shared_ptr<AppInfo>& app_info);
- void Delete(const std::string& package);
-
- private:
- static std::string GetDBPath(uid_t uid);
-};
-
-} // namespace boot_sequencer
-
-#endif // APPSVC_DB_HH_
+++ /dev/null
-/*
- * Copyright (c) 2022 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 "cert_checker.hh"
-
-#include <dlfcn.h>
-#include <pkgmgr-info.h>
-
-#include <memory>
-
-#include "log_private.hh"
-
-namespace boot_sequencer {
-namespace {
-
-constexpr const char LIBCERT_SVC_VCORE[] = "libcert-svc-vcore.so.2";
-
-typedef struct {
- void* privatePtr;
-} CertSvcInstance;
-
-typedef struct {
- size_t privateHandler;
- CertSvcInstance privateInstance;
-} CertSvcCertificate;
-
-typedef enum {
- CERTSVC_FORM_DER,
- CERTSVC_FORM_DER_BASE64,
-} CertSvcCertificateFrom;
-
-typedef enum {
- CERTSVC_VISIBILITY_DEVELOPER = 1,
- CERTSVC_VISIBILITY_PUBLIC = 1 << 6,
- CERTSVC_VISIBILITY_PARTNER = 1 << 7,
- CERTSVC_VISIBILITY_PLATFORM = 1 << 10
-} CertSvcVisibility;
-
-class CertSvc {
- public:
- static CertSvc& GetInst() {
- static CertSvc inst;
- if (inst.disposed_)
- inst.Init();
-
- return inst;
- }
-
- void Dispose() {
- if (disposed_)
- return;
-
- certsvc_certificate_free_ = nullptr;
- certsvc_certificate_get_visibility_ = nullptr;
- certsvc_certificate_new_from_memory_ = nullptr;
- certsvc_instance_free_ = nullptr;
- certsvc_instance_new_ = nullptr;
-
- if (handle_ != nullptr) {
- dlclose(handle_);
- handle_ = nullptr;
- }
-
- disposed_ = true;
- }
-
- int GetVisibility(const std::string& cert_value) {
- if (disposed_ || cert_value.empty())
- return CERTSVC_VISIBILITY_PUBLIC;
-
- CertSvcInstance instance;
- int ret = certsvc_instance_new_(&instance);
- if (ret != 1) {
- _E("certsvc_instance_new() is failed. error(%d)", ret);
- return CERTSVC_VISIBILITY_PUBLIC;
- }
-
- CertSvcCertificate certificate;
- ret = certsvc_certificate_new_from_memory_(instance,
- reinterpret_cast<const unsigned char*>(cert_value.c_str()),
- cert_value.length(), CERTSVC_FORM_DER_BASE64, &certificate);
- if (ret != 1) {
- _E("certsvc_certificate_new_from_memory() is failed. error(%d)", ret);
- certsvc_instance_free_(instance);
- return CERTSVC_VISIBILITY_PUBLIC;
- }
-
- CertSvcVisibility visibility = CERTSVC_VISIBILITY_PUBLIC;
- ret = certsvc_certificate_get_visibility_(certificate, &visibility);
- if (ret != 1)
- _E("certsvc_certificate_get_visibility() is failed. error(%d)", ret);
-
- certsvc_certificate_free_(certificate);
- certsvc_instance_free_(instance);
- return static_cast<int>(visibility);
- }
-
- private:
- using CertSvcInstanceNew = int (*)(CertSvcInstance*);
- using CertSvcInstanceFree = int (*)(CertSvcInstance);
- using CertSvcCertificateNewFromMemory =
- int (*)(CertSvcInstance, const unsigned char*, size_t,
- CertSvcCertificateFrom, CertSvcCertificate*);
- using CertSvcCertificateGetVisibility =
- int (*)(CertSvcCertificate, CertSvcVisibility*);
- using CertSvcCertificateFree = int (*)(CertSvcCertificate);
-
- CertSvc() = default;
-
- ~CertSvc() {
- Dispose();
- }
-
- void Init() {
- std::string path = std::string(LIBDIR) + "/" +
- std::string(LIBCERT_SVC_VCORE);
- void* handle = dlopen(path.c_str(), RTLD_LAZY | RTLD_LOCAL);
- if (handle == nullptr) {
- _E("dlopen() is failed. error(%s)", dlerror());
- return;
- }
- auto dlcloser = [](void* p) { dlclose(p); };
- std::unique_ptr<void, decltype(dlcloser)> handle_auto(handle, dlcloser);
-
- certsvc_instance_new_ = reinterpret_cast<CertSvcInstanceNew>(
- dlsym(handle, "certsvc_instance_new"));
- if (certsvc_instance_new_ == nullptr) {
- _E("dlsym() is failed. 'certsvc_isntance_new'");
- return;
- }
-
- certsvc_instance_free_ = reinterpret_cast<CertSvcInstanceFree>(
- dlsym(handle, "certsvc_instance_free"));
- if (certsvc_instance_free_ == nullptr) {
- _E("dlsym() is failed. 'certsvc_instance_free'");
- return;
- }
-
- certsvc_certificate_new_from_memory_ =
- reinterpret_cast<CertSvcCertificateNewFromMemory>(
- dlsym(handle, "certsvc_certificate_new_from_memory"));
- if (certsvc_certificate_new_from_memory_ == nullptr) {
- _E("dlsym() is failed. 'certsvc_certificate_new_from_memory'");
- return;
- }
-
- certsvc_certificate_get_visibility_ =
- reinterpret_cast<CertSvcCertificateGetVisibility>(
- dlsym(handle, "certsvc_certificate_get_visibility"));
- if (certsvc_certificate_get_visibility_ == nullptr) {
- _E("dlsym() is failed. 'certsvc_certificate_get_visibility'");
- return;
- }
-
- certsvc_certificate_free_ = reinterpret_cast<CertSvcCertificateFree>(
- dlsym(handle, "certsvc_certificate_free"));
- if (certsvc_certificate_free_ == nullptr) {
- _E("dlsym() is failed. 'certsvc_certificate_free'");
- return;
- }
-
- handle_ = handle_auto.release();
- disposed_ = false;
- }
-
- private:
- bool disposed_ = true;
- void* handle_ = nullptr;
- CertSvcInstanceNew certsvc_instance_new_ = nullptr;
- CertSvcInstanceFree certsvc_instance_free_ = nullptr;
- CertSvcCertificateNewFromMemory certsvc_certificate_new_from_memory_ = nullptr;
- CertSvcCertificateGetVisibility certsvc_certificate_get_visibility_ = nullptr;
- CertSvcCertificateFree certsvc_certificate_free_ = nullptr;
-};
-
-bool IsPreload(const std::string& pkgid, uid_t uid) {
- pkgmgrinfo_pkginfo_h handle;
- int ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid.c_str(), uid, &handle);
- if (ret != PMINFO_R_OK) {
- _E("pkgmgrinfo_pkginfo_get_usr_pkginfo() is failed. error(%d)", ret);
- return false;
- }
-
- bool preload = false;
- ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
- if (ret != PMINFO_R_OK)
- _E("pkgmgrinfo_pkginfo_is_preload() is failed. error(%d)", ret);
-
- pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
- return preload;
-}
-
-std::string GetCertValueFromPkgInfo(const std::string& pkgid, uid_t uid) {
- pkgmgrinfo_certinfo_h certinfo;
- int ret = pkgmgrinfo_pkginfo_create_certinfo(&certinfo);
- if (ret != PMINFO_R_OK) {
- _E("pkgmgrinfo_pkginfo_create_certinfo() is failed. error(%d)", ret);
- return {};
- }
- auto certinfo_auto = std::unique_ptr<
- std::remove_pointer<pkgmgrinfo_certinfo_h>::type,
- decltype(pkgmgrinfo_pkginfo_destroy_certinfo)*>(
- certinfo, pkgmgrinfo_pkginfo_destroy_certinfo);
-
- ret = pkgmgrinfo_pkginfo_load_certinfo(pkgid.c_str(), certinfo, uid);
- if (ret != PMINFO_R_OK) {
- _E("pkgmgrinfo_pkginfo_load_certinfo() is failed. error(%d)", ret);
- return {};
- }
-
- const char* cert_value;
- ret = pkgmgrinfo_pkginfo_get_cert_value(certinfo,
- PMINFO_DISTRIBUTOR_ROOT_CERT, &cert_value);
- if (ret != PMINFO_R_OK || cert_value == nullptr) {
- _E("pkgmgrinfo_pkginfo_get_cert_value() is failed. error(%d)", ret);
- return {};
- }
-
- return std::string(cert_value);
-}
-
-} // namespace
-
-
-bool CertChecker::IsPrivilegedPackage(const std::string& pkgid, uid_t uid) {
- if (IsPreload(pkgid, uid)) {
- _W("%s is preload package", pkgid.c_str());
- return true;
- }
-
- int visibility = CertSvc::GetInst().GetVisibility(
- GetCertValueFromPkgInfo(pkgid, uid));
- _D("Visibility: %d", visibility);
- if (visibility & CERTSVC_VISIBILITY_PLATFORM ||
- visibility & CERTSVC_VISIBILITY_PARTNER)
- return true;
-
- return false;
-}
-
-} // namespace boot_sequencer
+++ /dev/null
-/*
- * Copyright (c) 2022 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 CERT_CHECKER_HH_
-#define CERT_CHECKER_HH_
-
-#include <sys/types.h>
-
-#include <string>
-
-namespace boot_sequencer {
-
-class CertChecker {
- public:
- static bool IsPrivilegedPackage(const std::string& pkgid, uid_t uid);
-};
-
-} // namespace boot_sequencer
-
-#endif // CERT_CHECKER_HH_
+++ /dev/null
-type="tag";name="ui-application";path="/etc/package-manager/parserlib/libboot-sequencer.so"
-type="tag";name="service-application";path="/etc/package-manager/parserlib/libboot-sequencer.so"
+++ /dev/null
-/*
- * Copyright (c) 2022 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 <unistd.h>
-
-#include <memory>
-
-#include "database.hh"
-#include "exception.hh"
-#include "log_private.hh"
-
-namespace boot_sequencer {
-
-static const int BUSY_WAITING_USEC = 50000;
-static const int BUSY_WAITING_MAX = 40;
-
-Database::Cursor::~Cursor() {
- if (stmt_ != nullptr)
- sqlite3_finalize(stmt_);
-}
-
-Database::Cursor::Cursor(sqlite3* db, const std::string& query,
- const std::vector<std::string>& bind_text) {
- sqlite3_stmt* stmt;
- int ret = sqlite3_prepare_v2(db, query.c_str(), query.length(), &stmt,
- nullptr);
- auto stmt_auto = std::unique_ptr<sqlite3_stmt, decltype(sqlite3_finalize)*>(
- stmt, sqlite3_finalize);
- if (ret != SQLITE_OK) {
- _E("sqlite3_prepare_v2() is failed. error(%s:%d)", sqlite3_errmsg(db), ret);
- THROW(-ret);
- }
-
- int index = 1;
- for (auto const& text : bind_text) {
- ret = sqlite3_bind_text(stmt, index++, text.c_str(), -1, SQLITE_TRANSIENT);
- if (ret != SQLITE_OK) {
- _E("sqlite3_bind_text() is failed. index(%d), error(%s:%d)",
- index - 1, sqlite3_errmsg(db), ret);
- THROW(-ret);
- }
- }
-
- stmt_ = stmt_auto.release();
-}
-
-void Database::Cursor::Next() {
- int ret = sqlite3_step(stmt_);
- if (ret == SQLITE_ROW)
- return;
-
- if (ret == SQLITE_DONE)
- _D("SQLITE_DONE");
- else if (ret == SQLITE_BUSY)
- _E("SQLITE_BUSY");
- else if (ret == SQLITE_ERROR)
- _E("SQLITE_ERROR");
- else if (ret == SQLITE_MISUSE)
- _E("SQLITE_MISUSE");
-
- done_ = true;
-}
-
-bool Database::Cursor::IsDone() const {
- return done_;
-}
-
-bool Database::Cursor::Execute() {
- int ret = sqlite3_step(stmt_);
- if (ret != SQLITE_DONE) {
- _E("sqlite3_step() is failed. error(%d)", ret);
- if (ret != SQLITE_ROW)
- done_ = true;
-
- return false;
- }
-
- done_ = true;
- return true;
-}
-
-std::string Database::Cursor::GetColumn(int index) {
- auto* text = reinterpret_cast<const char*>(sqlite3_column_text(stmt_, index));
- if (text)
- return std::string(text);
-
- return {};
-}
-
-Database::Database(std::string path) : path_(std::move(path)) {}
-
-Database::~Database() {
- Close();
-}
-
-void Database::BeginTransaction() {
- int ret = sqlite3_exec(db_, "BEGIN TRANSACTION", nullptr, nullptr, nullptr);
- if (ret != SQLITE_OK) {
- _E("sqlite3_exec() is failed. error(%s:%d)", sqlite3_errmsg(db_), ret);
- THROW(-ret);
- }
-}
-
-void Database::EndTransaction() {
- int ret = sqlite3_exec(db_, "END TRANSACTION", nullptr, nullptr, nullptr);
- if (ret != SQLITE_OK) {
- _E("sqlite3_exec() is failed. error(%s:%d)", sqlite3_errmsg(db_), ret);
- THROW(-ret);
- }
-}
-
-void Database::Rollback() {
- int ret = sqlite3_exec(db_, "ROLLBACK", nullptr, nullptr, nullptr);
- if (ret != SQLITE_OK) {
- _E("sqlite3_exec() is failed. error(%s:%d", sqlite3_errmsg(db_), ret);
- THROW(-ret);
- }
-}
-
-void Database::Open() {
- sqlite3* db;
- int ret = sqlite3_open_v2(path_.c_str(), &db, SQLITE_OPEN_READWRITE, nullptr);
- if (ret != SQLITE_OK) {
- _E("sqlite3_open_v2() is failed. error(%d)", ret);
- sqlite3_close_v2(db);
- THROW(-ret);
- }
-
- ret = sqlite3_busy_handler(db, BusyHandler,
- static_cast<void*>(const_cast<char*>(path_.c_str())));
- if (ret != SQLITE_OK) {
- _E("sqlite3_busy_handler() is failed. error(%s:%d)",
- sqlite3_errmsg(db), ret);
- sqlite3_close_v2(db);
- THROW(-ret);
- }
-
- ret = sqlite3_exec(db, "PRAGMA foreign_keys=ON", nullptr, nullptr, nullptr);
- if (ret != SQLITE_OK) {
- _E("sqlite3_exec() is failed. error(%s:%d)", sqlite3_errmsg(db), ret);
- sqlite3_close_v2(db);
- THROW(-ret);
- }
-
- db_ = db;
-}
-
-void Database::Close() {
- if (db_) {
- sqlite3_close_v2(db_);
- db_ = nullptr;
- }
-}
-
-std::shared_ptr<Database::Cursor> Database::Query(const std::string& query,
- const std::vector<std::string>& bind_text) {
- try {
- auto cursor = std::shared_ptr<Database::Cursor>(
- new Database::Cursor(db_, query, bind_text));
- return cursor;
- } catch (const Exception& e) {
- return nullptr;
- }
-}
-
-int Database::BusyHandler(void* data, int count) {
- if (count < BUSY_WAITING_MAX) {
- usleep(BUSY_WAITING_USEC);
- return 1;
- }
-
- auto* path = static_cast<char*>(data);
- _E("Database(%s) is busy", path);
- return 0;
-}
-
-} // namespace boot_sequencer
+++ /dev/null
-/*
- * Copyright (c) 2022 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 DATABASE_HH_
-#define DATABASE_HH_
-
-#include <sqlite3.h>
-
-#include <memory>
-#include <string>
-#include <vector>
-
-#include "exception.hh"
-
-namespace boot_sequencer {
-
-class Database {
- public:
- class Cursor {
- public:
- ~Cursor();
- Cursor(const Cursor&) = delete;
- Cursor& operator=(const Cursor&) = delete;
-
- void Next();
- bool IsDone() const;
- bool Execute();
- std::string GetColumn(int index);
-
- private:
- friend class Database;
- Cursor(sqlite3* db, const std::string& query,
- const std::vector<std::string>& bind_text);
-
- private:
- sqlite3_stmt* stmt_ = nullptr;
- bool done_ = false;
- };
-
- explicit Database(std::string path);
- virtual ~Database();
-
- void Open();
- void Close();
- void BeginTransaction();
- void EndTransaction();
- void Rollback();
- std::shared_ptr<Cursor> Query(const std::string& query,
- const std::vector<std::string>& bind_text);
-
- private:
- static int BusyHandler(void* data, int count);
-
- private:
- std::string path_;
- sqlite3* db_ = nullptr;
-};
-
-} // namespace boot_sequencer
-
-#endif // DATABASE_HH_
+++ /dev/null
-/*
- * Copyright (c) 2022 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 EVENT_TYPE_HH_
-#define EVENT_TYPE_HH_
-
-namespace boot_sequencer {
-
-enum class EventType {
- Install,
- Uninstall,
- Upgrade,
- Undo,
-};
-
-} // namespace boot_sequencer
-
-#endif // EVENT_TYPE_HH_
+++ /dev/null
-/*
- * Copyright (c) 2022 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 "exception.hh"
-
-#include <libgen.h>
-
-namespace boot_sequencer {
-
-Exception::Exception(int error_code, std::string file, int line)
- : error_code_(error_code) {
- message_ = std::string(basename(const_cast<char*>(file.c_str()))) + ":" +
- std::to_string(line) + " code:" + std::to_string(error_code_);
-}
-
-const char* Exception::what() const noexcept {
- return message_.c_str();
-}
-
-int Exception::GetErrorCode() const {
- return error_code_;
-}
-
-} // namespace boot_sequencer
+++ /dev/null
-/*
- * Copyright (c) 2022 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 EXCEPTION_HH_
-#define EXCEPTION_HH_
-
-#include <exception>
-#include <string>
-
-#define THROW(error_code) throw Exception(error_code, __FILE__, __LINE__)
-
-namespace boot_sequencer {
-
-class Exception : public std::exception {
- public:
- explicit Exception(int error_code, std::string file, int line);
- virtual ~Exception() = default;
-
- virtual const char* what() const noexcept;
- int GetErrorCode() const;
-
- private:
- int error_code_;
- std::string message_;
-};
-
-} // namespace boot_sequencer
-
-#endif // EXCEPTION_HH_
+++ /dev/null
-/*
- * Copyright (c) 2022 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 LOG_PRIVATE_HH_
-#define LOG_PRIVATE_HH_
-
-#include <dlog.h>
-
-#undef LOG_TAG
-#define LOG_TAG "BOOT_SEQUENCER_PLUGIN_PARSER"
-
-#undef _E
-#define _E LOGE
-
-#undef _W
-#define _W LOGW
-
-#undef _I
-#define _I LOGI
-
-#undef _D
-#define _D LOGD
-
-#endif // LOG_PRIVATE_HH_
+++ /dev/null
-/*
- * Copyright (c) 2022 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 "package_event_args.hh"
-
-namespace boot_sequencer {
-
-PackageEventArgs::PackageEventArgs(std::string package, EventType event_type)
- : package_(std::move(package)),
- event_type_(event_type) {
-}
-
-const std::string& PackageEventArgs::GetPackage() const {
- return package_;
-}
-
-EventType PackageEventArgs::GetEventType() const {
- return event_type_;
-}
-
-void PackageEventArgs::Push(std::shared_ptr<AppInfo> app_info) {
- app_infos_.push_back(std::move(app_info));
-}
-
-const std::vector<std::shared_ptr<AppInfo>>&
-PackageEventArgs::GetAppInfos() const {
- return app_infos_;
-}
-
-void PackageEventArgs::Reset(std::vector<std::shared_ptr<AppInfo>> app_infos) {
- app_infos_ = std::move(app_infos);
-}
-
-} // namespace boot_sequencer
+++ /dev/null
-/*
- * Copyright (c) 2022 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 PACKAGE_EVENT_ARGS_HH_
-#define PACKAGE_EVENT_ARGS_HH_
-
-#include <memory>
-#include <string>
-#include <vector>
-
-#include "app_info.hh"
-#include "event_type.hh"
-
-namespace boot_sequencer {
-
-class PackageEventArgs {
- public:
- PackageEventArgs(std::string package, EventType event_type);
-
- const std::string& GetPackage() const;
- EventType GetEventType() const;
-
- void Push(std::shared_ptr<AppInfo> app_info);
- const std::vector<std::shared_ptr<AppInfo>>& GetAppInfos() const;
- void Reset(std::vector<std::shared_ptr<AppInfo>> app_infos);
-
- private:
- std::string package_;
- EventType event_type_;
- std::vector<std::shared_ptr<AppInfo>> app_infos_;
-};
-
-} // namespace boot_sequencer
-
-#endif // PACKAGE_EVENT_ARGS_HH_
+++ /dev/null
-/*
- * Copyright (c) 2022 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 "parser_plugin.hh"
-
-#include <pkgmgr-info.h>
-#include <pkgmgr_installer_info.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <bundle_cpp.h>
-
-#include <memory>
-
-#include "cert_checker.hh"
-#include "log_private.hh"
-
-namespace boot_sequencer {
-namespace {
-
-constexpr const char REQUIRED_API_VERSION[] = "7";
-
-std::string GetName(xmlNode* node) {
- if (node == nullptr)
- return {};
-
- return std::string(reinterpret_cast<const char*>(node->name));
-}
-
-std::string GetAttribute(xmlNode* node, const char* key) {
- xmlChar* val = xmlGetProp(node, reinterpret_cast<const xmlChar*>(key));
- if (val != nullptr) {
- std::string attr(reinterpret_cast<char*>(val));
- xmlFree(val);
- return attr;
- }
-
- return {};
-}
-
-uid_t GetTargetUid() {
- uid_t target_uid;
- pkgmgr_installer_info_get_target_uid(&target_uid);
- return target_uid;
-}
-
-bool IsSupported(const std::string& appid, uid_t uid) {
- pkgmgrinfo_appinfo_h handle;
- int ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid.c_str(), uid, &handle);
- if (ret != PMINFO_R_OK)
- return false;
-
- auto handle_auto = std::unique_ptr<
- std::remove_pointer<pkgmgrinfo_appinfo_h>::type,
- decltype(pkgmgrinfo_appinfo_destroy_appinfo)*>(
- handle, pkgmgrinfo_appinfo_destroy_appinfo);
-
- char* apptype;
- ret = pkgmgrinfo_appinfo_get_apptype(handle, &apptype);
- if (ret != PMINFO_R_OK)
- return false;
-
- char* api_version;
- ret = pkgmgrinfo_appinfo_get_api_version(handle, &api_version);
- if (ret != PMINFO_R_OK)
- return false;
-
- if (strverscmp(REQUIRED_API_VERSION, api_version) <= 0)
- return true;
-
- return false;
-}
-
-} // namespace
-
-ParserPlugin& ParserPlugin::GetInst() {
- static ParserPlugin inst;
- return inst;
-}
-
-void ParserPlugin::Init(xmlDocPtr doc, std::string package,
- EventType event_type) {
- doc_ = doc;
- args_ = std::unique_ptr<PackageEventArgs>(
- new PackageEventArgs(package, event_type));
- backup_args_ = std::unique_ptr<PackageEventArgs>(
- new PackageEventArgs(std::move(package), event_type));
-}
-
-int ParserPlugin::Process() {
- int ret = Prepare();
- if (ret != 0)
- return ret;
-
- ret = StepBackup();
- if (ret != 0) {
- Post();
- return ret;
- }
-
- if (args_->GetEventType() == EventType::Install)
- ret = StepInstall();
- else if (args_->GetEventType() == EventType::Uninstall)
- ret = StepUninstall();
- else if (args_->GetEventType() == EventType::Upgrade)
- ret = StepUpgrade();
-
- if (ret != 0)
- Rollback();
-
- Post();
- return ret;
-}
-
-int ParserPlugin::Undo() {
- _E("Undo");
- int ret = Prepare();
- if (ret != 0)
- return ret;
-
- ret = StepUninstall();
- if (ret != 0)
- return ret;
-
- ret = StepRestore();
- Post();
- return ret;
-}
-
-ParserPlugin::ParserPlugin() : db_(new AppSvcDB(GetTargetUid())) {}
-
-int ParserPlugin::Prepare() {
- try {
- db_->Open();
- db_->BeginTransaction();
- } catch (const Exception& e) {
- _E("Exception(%s) occurs", e.what());
- return e.GetErrorCode();
- }
-
- return 0;
-}
-
-int ParserPlugin::StepBackup() {
- try {
- auto app_infos = db_->Select(backup_args_->GetPackage());
- backup_args_->Reset(std::move(app_infos));
- } catch (const Exception& e) {
- _E("Exception(%s) occurs", e.what());
- return e.GetErrorCode();
- }
-
- return 0;
-}
-
-int ParserPlugin::StepInstall() {
- if (!CertChecker::IsPrivilegedPackage(args_->GetPackage(), GetTargetUid())) {
- _W("%s is not a platform package", args_->GetPackage().c_str());
- return 0;
- }
-
- int ret = Parse();
- if (ret != 0)
- return ret;
-
- for (auto& app_info : args_->GetAppInfos()) {
- try {
- db_->Insert(args_->GetPackage(), app_info);
- } catch (const Exception& e) {
- _E("Exception(%s) occurs", e.what());
- return e.GetErrorCode();
- }
- }
-
- return 0;
-}
-
-int ParserPlugin::StepUninstall() {
- try {
- db_->Delete(args_->GetPackage());
- } catch (const Exception& e) {
- _E("Exception(%s) occurs", e.what());
- return e.GetErrorCode();
- }
-
- return 0;
-}
-
-int ParserPlugin::StepUpgrade() {
- int ret = StepUninstall();
- if (ret != 0)
- return ret;
-
- return StepInstall();
-}
-
-int ParserPlugin::StepRestore() {
- _E("Restore");
- for (auto& app_info : backup_args_->GetAppInfos()) {
- try {
- db_->Insert(backup_args_->GetPackage(), app_info);
- } catch (const Exception& e) {
- _E("Exception(%s) occurs", e.what());
- return e.GetErrorCode();
- }
- }
-
- return 0;
-}
-
-void ParserPlugin::Post() {
- try {
- db_->EndTransaction();
- db_->Close();
- } catch (const Exception& e) {
- _E("Exception(%s) occurs", e.what());
- }
-}
-
-void ParserPlugin::Rollback() {
- try {
- db_->Rollback();
- } catch (const Exception& e) {
- _E("Exception(%s) occurs", e.what());
- }
-}
-
-int ParserPlugin::Parse() {
- xmlNode* root = xmlDocGetRootElement(doc_);
- if (root == nullptr) {
- _E("xmlDocGetRootElement() is failed");
- return -1;
- }
-
- for (xmlNode* node = root->children; node; node = node->next) {
- std::string appid = GetAttribute(node, "appid");
- if (appid.empty())
- continue;
-
- std::string comp_type = GetName(node);
- if (comp_type == "widget-application" || comp_type == "watch-application")
- continue;
-
- if (!IsSupported(appid, GetTargetUid())) continue;
-
- AppInfo* app_info = nullptr;
- for (xmlNode* child_node = node->children; child_node;
- child_node = child_node->next) {
- std::string name = GetName(child_node);
- if (name != "boot-sequence")
- continue;
-
- app_info = new (std::nothrow) AppInfo(appid);
- if (app_info == nullptr) {
- _E("Out of memory");
- return -1;
- }
-
- ParseBootSequence(child_node, app_info);
- break;
- }
-
- if (app_info == nullptr) continue;
- args_->Push(std::shared_ptr<AppInfo>(app_info));
- }
-
- return 0;
-}
-
-void ParserPlugin::ParseBootSequence(xmlNode* node, AppInfo* app_info) {
- for (xmlNode* child_node = node->children; child_node;
- child_node = child_node->next) {
- std::string name = GetName(child_node);
- if (name == "dependency") {
- auto after = GetAttribute(child_node, "after");
- if (!after.empty())
- app_info->SetAfter(std::move(after));
-
- auto before = GetAttribute(child_node, "before");
- if (!before.empty())
- app_info->SetBefore(std::move(before));
-
- auto requires_dep = GetAttribute(child_node, "requires");
- if (!requires_dep.empty())
- app_info->SetRequires(std::move(requires_dep));
-
- auto conflicts = GetAttribute(child_node, "conflicts");
- if (!conflicts.empty())
- app_info->SetConflicts(std::move(conflicts));
-
- auto vconf_key = GetAttribute(child_node, "vconf-key");
- if (!vconf_key.empty()) {
- auto vconf_value = GetAttribute(child_node, "vconf-value");
- if (vconf_value.empty()) {
- _E("vconf-value MUST be set");
- continue;
- }
-
- // 'String', 'Int32', 'Boolean', 'Double'
- auto vconf_type = GetAttribute(child_node, "vconf-type");
- tizen_base::Bundle vconf {
- { "__VCONF_KEY__", vconf_key },
- { "__VCONF_VALUE__", vconf_value },
- { "__VCONF_TYPE__", vconf_type.empty() ? "String" : vconf_type }
- };
-
- app_info->SetVconf(reinterpret_cast<char*>(vconf.ToRaw().first.get()));
- }
-
- auto path_exists = GetAttribute(child_node, "path-exists");
- if (!path_exists.empty())
- app_info->SetPathExists(std::move(path_exists));
- } else if (name == "option") {
- auto args = GetAttribute(child_node, "args");
- if (!args.empty())
- app_info->SetArgs(std::move(args));
-
- auto background_launch = GetAttribute(child_node, "background-launch");
- if (!background_launch.empty())
- app_info->SetBackgroundLaunch(std::move(background_launch));
-
- auto wait_until_ready = GetAttribute(child_node, "wait-until-ready");
- if (!wait_until_ready.empty())
- app_info->SetWaitUntilReady(std::move(wait_until_ready));
-
- auto timeout = GetAttribute(child_node, "timeout");
- if (!timeout.empty())
- app_info->SetTimeout(std::move(timeout));
- }
- }
-
- if (app_info->GetBackgroundLaunch() != "true" &&
- app_info->GetBackgroundLaunch() != "false")
- app_info->SetBackgroundLaunch("true");
-
- if (app_info->GetWaitUntilReady() != "true" &&
- app_info->GetWaitUntilReady() != "false")
- app_info->SetWaitUntilReady("true");
-
- // Default timeout: 5 seconds
- if (app_info->GetTimeout().empty())
- app_info->SetTimeout("5000");
-}
-
-} // namespace boot_sequencer
+++ /dev/null
-/*
- * Copyright (c) 2022 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 PARSER_PLUGIN_HH_
-#define PARSER_PLUGIN_HH_
-
-#include <libxml/tree.h>
-
-#include <memory>
-#include <string>
-
-#include "appsvc_db.hh"
-#include "package_event_args.hh"
-
-namespace boot_sequencer {
-
-class ParserPlugin {
- public:
- static ParserPlugin& GetInst();
- void Init(xmlDocPtr doc, std::string package, EventType event_type);
-
- int Process();
- int Undo();
-
- private:
- ParserPlugin();
- ~ParserPlugin() = default;
-
- int Prepare();
- int StepBackup();
- int StepInstall();
- int StepUninstall();
- int StepUpgrade();
- int StepRestore();
- void Post();
- void Rollback();
-
- int Parse();
- void ParseBootSequence(xmlNode* node, AppInfo* app_info);
-
- private:
- std::unique_ptr<AppSvcDB> db_;
- xmlDocPtr doc_ = nullptr;
- std::unique_ptr<PackageEventArgs> args_;
- std::unique_ptr<PackageEventArgs> backup_args_;
-};
-
-} // namespace boot_sequencer
-
-#endif // PARSER_PLUGIN_HH_
+++ /dev/null
-/*
- * Copyright (c) 2022 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 <glib.h>
-#include <libxml/tree.h>
-
-#include "parser_plugin.hh"
-
-#undef EXPORT
-#define EXPORT __attribute__ ((visibility("default")))
-
-using namespace boot_sequencer;
-
-extern "C" EXPORT int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr doc,
- const char* package) {
- auto& plugin = ParserPlugin::GetInst();
- plugin.Init(doc, package, EventType::Install);
- return plugin.Process();
-}
-
-extern "C" EXPORT int PKGMGR_PARSER_PLUGIN_UPGRADE(xmlDocPtr doc,
- const char* package) {
- auto& plugin = ParserPlugin::GetInst();
- plugin.Init(doc, package, EventType::Upgrade);
- return plugin.Process();
-}
-
-extern "C" EXPORT int PKGMGR_PARSER_PLUGIN_UNINSTALL(xmlDocPtr doc,
- const char* package) {
- auto& plugin = ParserPlugin::GetInst();
- plugin.Init(doc, package, EventType::Uninstall);
- return plugin.Process();
-}
-
-extern "C" EXPORT int PKGMGR_PARSER_PLUGIN_RECOVERINSTALL(xmlDocPtr doc,
- const char* package) {
- auto& plugin = ParserPlugin::GetInst();
- plugin.Init(doc, package, EventType::Uninstall);
- return plugin.Process();
-}
-
-extern "C" EXPORT int PKGMGR_PARSER_PLUGIN_RECOVERUPGRADE(xmlDocPtr doc,
- const char* package) {
- auto& plugin = ParserPlugin::GetInst();
- plugin.Init(doc, package, EventType::Upgrade);
- return plugin.Process();
-}
-
-extern "C" EXPORT int PKGMGR_PARSER_PLUGIN_RECOVERUNINSTALL(xmlDocPtr doc,
- const char* package) {
- auto& plugin = ParserPlugin::GetInst();
- plugin.Init(doc, package, EventType::Uninstall);
- return plugin.Process();
-}
-
-extern "C" EXPORT int PKGMGR_PARSER_PLUGIN_UNDO(xmlDocPtr doc,
- const char* package) {
- auto& plugin = ParserPlugin::GetInst();
- plugin.Init(doc, package, EventType::Undo);
- return plugin.Undo();
-}
+++ /dev/null
-SET(TARGET_COMPONENT_PLUGIN_PARSER "component-based-application")
-
-SET(SHARED_DIR "${CMAKE_INSTALL_PREFIX}/share")
-
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -Wall -Werror -Winline")
-
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src
- COMPONENT_PLUGIN_PARSER_SRCS)
-
-ADD_LIBRARY(${TARGET_COMPONENT_PLUGIN_PARSER} SHARED ${COMPONENT_PLUGIN_PARSER_SRCS})
-TARGET_LINK_LIBRARIES(${TARGET_COMPONENT_PLUGIN_PARSER} PUBLIC dl)
-
-TARGET_INCLUDE_DIRECTORIES(${TARGET_COMPONENT_PLUGIN_PARSER}
- PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/inc)
-
-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
-)
-
-CONFIGURE_FILE(data/component_db.sql.in data/component_db.sql @ONLY)
-CONFIGURE_FILE(script/14_component-add.post.in
- script/14_component-add.post @ONLY)
-CONFIGURE_FILE(script/501.component_upgrade.sh.in
- script/501.component_upgrade.sh @ONLY)
-CONFIGURE_FILE(script/upgrade/1_component_db_upgrade.sh.in
- script/upgrade/1_component_db_upgrade.sh @ONLY)
-
-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)
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/script/14_component-add.post
- DESTINATION ${SYSCONF_INSTALL_DIR}/gumd/useradd.d)
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/script/501.component_upgrade.sh
- DESTINATION ${SHARE_INSTALL_PREFIX}/upgrade/scripts)
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/script/upgrade/1_component_db_upgrade.sh
- DESTINATION /etc/aul/component/upgrade/scripts)
+++ /dev/null
-type="tag";name="component-based-application";path="/etc/package-manager/parserlib/libcomponent-based-application.so";vitalness="true"
+++ /dev/null
-PRAGMA journal_mode = PERSIST;
-PRAGMA user_version = @COMPONENT_DB_VERSION@;
-
-CREATE TABLE IF NOT EXISTS component_info (
- package TEXT NOT NULL,
- app_id TEXT NOT NULL,
- component_id TEXT NOT NULL,
- component_type TEXT NOT NULL,
- component_launch_mode TEXT NOT NULL,
- component_main TEXT NOT NULL,
- component_icon_display NOT NULL,
- component_taskmanage NOT NULL,
- PRIMARY KEY (component_id)
-);
-
-CREATE TABLE IF NOT EXISTS component_localized_info (
- component_id TEXT NOT NULL,
- component_locale TEXT NOT NULL DEFAULT 'No Locale',
- component_label TEXT,
- component_icon TEXT,
- PRIMARY KEY (component_id, component_locale)
- FOREIGN KEY (component_id)
- REFERENCES component_info(component_id) ON DELETE CASCADE
-);
+++ /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 __COMPONENT_PLUGIN_PARSER_H__
-#define __COMPONENT_PLUGIN_PARSER_H__
-
-#include <libxml/tree.h>
-
-int component_plugin_parser_install(xmlDocPtr doc, const char *package);
-
-int component_plugin_parser_uninstall(xmlDocPtr doc, const char *package);
-
-int component_plugin_parser_upgrade(xmlDocPtr doc, const char *package);
-
-#endif /* __COMPONENT_PLUGIN_PARSER_H__ */
+++ /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 __COMPONENT_PLUGIN_PARSER_DB_H__
-#define __COMPONENT_PLUGIN_PARSER_DB_H__
-
-#include <sys/types.h>
-
-#include "component_plugin_parser_type.h"
-
-int component_plugin_parser_db_init(void);
-
-int component_plugin_parser_db_fini(void);
-
-int component_plugin_parser_db_begin_transaction(void);
-
-int component_plugin_parser_db_end_transaction(void);
-
-int component_plugin_parser_db_rollback(void);
-
-int component_plugin_parser_db_insert(component_t *component);
-
-int component_plugin_parser_db_delete(const char *package);
-
-uid_t component_plugin_parser_db_get_target_uid(void);
-
-#endif /* __COMPONENT_PLUGIN_PARSER_DB_H__ */
+++ /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 __COMPONENT_PLUGIN_PARSER_HANDLER_H__
-#define __COMPONENT_PLUGIN_PARSER_HANDLER_H__
-
-#include <libxml/tree.h>
-
-int component_plugin_parser_handler_install(const char *package, xmlDocPtr doc);
-
-int component_plugin_parser_handler_uninstall(const char *package);
-
-int component_plugin_parser_handler_init(void);
-
-int component_plugin_parser_handler_fini(void);
-
-#endif /* __COMPONENT_PLUGIN_PARSER_HANDLER_H__ */
+++ /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 __COMPONENT_PLUGIN_PARSER_PRIVATE_H__
-#define __COMPONENT_PLUGIN_PARSER_PRIVATE_H__
-
-#include <dlog.h>
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-
-#define LOG_TAG "COMPONENT_PLUGIN_PARSER"
-
-#ifdef EXPORT
-#undef EXPORT
-#endif
-
-#define EXPORT __attribute__ ((visibility("default")))
-
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
-
-#define ROOT_UID 0
-
-#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
-
-#define FEATURE_SCREEN_DPI "http://tizen.org/feature/screen.dpi"
-
-#define DEFAULT_LOCALE "No Locale"
-
-#define LDPI "ldpi"
-#define MDPI "mdpi"
-#define HDPI "hdpi"
-#define XHDPI "xhdpi"
-#define XXHDPI "xxhdpi"
-
-#define LDPI_MIN 0
-#define LDPI_MAX 240
-#define MDPI_MIN 241
-#define MDPI_MAX 300
-#define HDPI_MIN 301
-#define HDPI_MAX 380
-#define XHDPI_MIN 381
-#define XHDPI_MAX 480
-#define XXHDPI_MIN 481
-#define XXHDPI_MAX 600
-
-#endif /* __COMPONENT_PLUGIN_PARSER_PRIVATE_H__ */
+++ /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 __COMPONENT_PLUGIN_PARSER_TYPE_H__
-#define __COMPONENT_PLUGIN_PARSER_TYPE_H__
-
-#include <glib.h>
-
-typedef struct {
- char *label;
- char *lang;
-} label_t;
-
-typedef struct {
- char *icon;
- char *lang;
- char *dpi;
-} icon_t;
-
-typedef struct {
- char *package;
- char *app_id;
- char *id;
- char *type;
- char *launch_mode;
- char *main;
- char *icon_display;
- char *taskmanage;
- GList *icon;
- GList *label;
-} component_t;
-
-#endif /* __COMPONENT_PLUGIN_PARSER_TYPE_H__ */
+++ /dev/null
-#!/bin/sh
-
-#------------------------------------------#
-# Add Component DB #
-#------------------------------------------#
-
-# Macro
-PATH=/bin:/usr/bin:/sbin:/usr/sbin
-
-# Create DB Path
-mkdir -p -Z User::Home -m 755 /opt/dbspace/user
-export `tzplatform-get --user $2 TZ_USER_NAME`
-mkdir -p -Z User::Home -m 770 /opt/dbspace/user/$2
-chown $TZ_USER_NAME:system_share /opt/dbspace/user/$2
-
-# Create DB
-sqlite3 /opt/dbspace/user/$2/.component.db << EOF
-PRAGMA journal_mode = PERSIST;
-PAAGMA user_version = @COMPONENT_DB_VERSION@;
-
-CREATE TABLE IF NOT EXISTS component_info (
- package TEXT NOT NULL,
- app_id TEXT NOT NULL,
- component_id TEXT NOT NULL,
- component_type TEXT NOT NULL,
- component_launch_mode TEXT NOT NULL,
- component_main TEXT NOT NULL,
- component_icon_display NOT NULL,
- component_taskmanage NOT NULL,
- PRIMARY KEY (component_id)
-);
-
-CREATE TABLE IF NOT EXISTS component_localized_info (
- component_id TEXT NOT NULL,
- component_locale TEXT NOT NULL DEFAULT 'No Locale',
- component_label TEXT,
- component_icon TEXT,
- PRIMARY KEY (component_id, component_locale)
- FOREIGN KEY (component_id)
- REFERENCES component_info(component_id) ON DELETE CASCADE
-);
-
-EOF
-
-# Adjust Permission
-chmod 664 /opt/dbspace/user/$2/.component.db
-chmod 664 /opt/dbspace/user/$2/.component.db-journal
-
-chown $TZ_USER_NAME:system_share /opt/dbspace/user/$2/.component.db
-chown $TZ_USER_NAME:system_share /opt/dbspace/user/$2/.component.db-journal
-
-chsmack -a User::Home /opt/dbspace/user/$2/.component.db
-chsmack -a User::Home /opt/dbspace/user/$2/.component.db-journal
-
+++ /dev/null
-#!/bin/sh
-PATH="/usr/bin:/bin:/usr/sbin:/sbin"
-
-DB_VERSION="@COMPONENT_DB_VERSION@"
-
-FILE_DB=".component.db"
-PATH_SYS_DB="/opt/dbspace/${FILE_DB}"
-PATH_USER_DB_DIR="/opt/dbspace/user"
-PATH_UPGRADE_SCRIPT_DIR="/etc/aul/component/upgrade/scripts"
-NAME_UPGRADE_SCRIPT="component_db_upgrade.sh"
-CURRENT_DB_VERSION=0
-
-CompareDBVersion() {
- PATH_DB=$1
- CURRENT_DB_VERSION=`sqlite3 ${PATH_DB} 'PRAGMA user_version;'`
-
- echo "## Compare DB version"
- echo " - Path: ${PATH_DB}"
- echo " - Current DB version: ${CURRENT_DB_VERSION}"
-
- if [ "${DB_VERSION}" -eq "${CURRENT_DB_VERSION}" ]; then
- echo " - DB version[${DB_VERSION}] is equal to current DB version[${CURRENT_DB_VERSION}]"
- return 0
- elif [ "${DB_VERSION}" -gt "${CURRENT_DB_VERSION}" ]; then
- echo " - DB version[${DB_VERSION}] is greater than current DB version[${CURRENT_DB_VERSION}]"
- return 1
- else
- echo " - DB version[${DB_VERSION}] is less than current DB version[${CURRENT_DB_VERSION}]"
- return 0
- fi
- echo "## Compare DB version [Done]"
-}
-
-UpgradeDB() {
- PATH_DB=$1
- VERSION=$2
- echo "## UpgradeDB Path[${PATH_DB}] Version[${VERSION}]"
- i=${VERSION}
- while [ ${i} -le ${DB_VERSION} ]; do
- FILE_SCRIPT="${i}_${NAME_UPGRADE_SCRIPT}"
- PATH_SCRIPT="${PATH_UPGRADE_SCRIPT_DIR}/${FILE_SCRIPT}"
- if [ -e "${PATH_SCRIPT}" ]; then
- echo " - Script: ${PATH_SCRIPT}"
- ${PATH_SCRIPT} ${PATH_DB}
- fi
-
- i=`expr ${i} + 1`
- done
- echo "## UpgradeDB Path[${PATH_DB}] Version[${VERSION}] [Done]"
-}
-
-CheckAndUpgradeDB() {
- echo "### Check and upgrade DB"
-
- CompareDBVersion ${PATH_SYS_DB}
- RESULT=$?
- if [ "${RESULT}" -eq 1 ]; then
- VERSION=`expr ${CURRENT_DB_VERSION} + 1`
- UpgradeDB ${PATH_SYS_DB} ${VERSION}
- fi
-
- for DIR in ${PATH_USER_DB_DIR}/*; do
- echo " - Directory: ${DIR}"
- if [ -d "${DIR}" ]; then
- PATH_DB="${DIR}/${FILE_DB}"
- CompareDBVersion ${PATH_DB}
- RESULT=$?
- if [ "${RESULT}" -eq 1 ]; then
- VERSION=`expr ${CURRENT_DB_VERSION} + 1`
- UpgradeDB ${PATH_DB} ${VERSION}
- fi
- fi
- done
- echo "### Check and upgrade DB [Done]"
-}
-
-echo "#### Upgrade component db ####"
-CheckAndUpgradeDB
-echo "#### Upgrade component db [Done] ####"
+++ /dev/null
-#!/bin/sh
-
-#------------------------------------------#
-# component db upgrade ver.1 (4.0 -> 5.5) #
-#------------------------------------------#
-
-# Macro
-PATH=/bin:/usr/bin:/sbin:/usr/sbin
-
-PATH_DB="$1"
-PATH_NEW_DB="${PATH_DB}.new"
-PATH_BACKUP_DB="${PATH_DB}.bak"
-
-Init() {
- echo "### Initialize"
- cp ${PATH_DB} ${PATH_BACKUP_DB}
- cp ${PATH_DB}-journal ${PATH_BACKUP_DB}-journal
-
- if [ -e "${PATH_NEW_DB}" ]; then
- rm ${PATH_NEW_DB}
- fi
-
- if [ -e "${PATH_NEW_DB}-journal" ]; then
- rm ${PATH_NEW_DB}-journal
- fi
-}
-
-# Create new DB
-CreateNewDB() {
-sqlite3 ${PATH_NEW_DB} << EOF
-PRAGMA journal_mode = PERSIST;
-PRAGMA user_version = @COMPONENT_DB_VERSION@;
-
-CREATE TABLE IF NOT EXISTS component_info (
- package TEXT NOT NULL,
- app_id TEXT NOT NULL,
- component_id TEXT NOT NULL,
- component_type TEXT NOT NULL,
- component_launch_mode TEXT NOT NULL,
- component_main TEXT NOT NULL,
- component_icon_display NOT NULL,
- component_taskmanage NOT NULL,
- PRIMARY KEY (component_id)
-);
-
-CREATE TABLE IF NOT EXISTS component_localized_info (
- component_id TEXT NOT NULL,
- component_locale TEXT NOT NULL DEFAULT 'No Locale',
- component_label TEXT,
- component_icon TEXT,
- PRIMARY KEY (component_id, component_locale)
- FOREIGN KEY (component_id)
- REFERENCES component_info(component_id) ON DELETE CASCADE
-);
-
-EOF
-}
-
-# Insert old data into new DB
-InsertComponentInfo() {
- echo " - Insert component_info"
- TABLE=`sqlite3 ${PATH_DB} 'SELECT package, app_id, component_id, component_type, component_launch_mode, component_main, component_icon_display, component_taskmanage FROM component_info;'`
- for ROW in ${TABLE}; do
- IFS='|' read -ra VALUE <<< "${ROW}";
- QUERY="INSERT INTO component_info(package, app_id, component_id, component_type, component_launch_mode, component_main, component_icon_display, component_taskmanage) VALUES('${VALUE[0]}', '${VALUE[1]}', '${VALUE[2]}', '${VALUE[3]}', '${VALUE[4]}', '${VALUE[5]}', '${VALUE[6]}', '${VALUE[7]}');"
- echo " + Query: ${QUERY}"
- sqlite3 ${PATH_NEW_DB} "${QUERY}"
- done
-}
-
-InsertComponentLocalizedInfo() {
- echo " - Insert component_localized_info"
- TABLE=`sqlite3 ${PATH_DB} 'SELECT component_id, component_locale, component_label, component_icon FROM component_localized_info;'`
- for ROW in ${TABLE}; do
- IFS='|' read -ra VALUE <<< "${ROW}";
- QUERY="INSERT INTO component_localized_info(component_id, component_locale, component_label, component_icon) VALUES('${VALUE[0]}', '${VALUE[1]}', '${VALUE[2]}', '${VALUE[3]}');"
- echo " + Query: ${QUERY}"
- sqlite3 ${PATH_NEW_DB} "${QUERY}"
- done
-}
-
-Upgrade() {
- echo "### Upgrade"
- CreateNewDB
-
- InsertComponentInfo
- InsertComponentLocalizedInfo
-
- cp ${PATH_NEW_DB} ${PATH_DB}
- cp ${PATH_NEW_DB}-journal ${PATH_DB}-journal
-
- chown :system_share ${PATH_DB}
- chown :system_share ${PATH_DB}-journal
- chsmack -a User::Home ${PATH_DB}
- chsmack -a User::Home ${PATH_DB}-journal
- chmod 664 ${PATH_DB}
- chmod 664 ${PATH_DB}-journal
-}
-
-Fini() {
- echo "### Finish"
- rm ${PATH_NEW_DB}
- rm ${PATH_NEW_DB}-journal
-
- rm ${PATH_BACKUP_DB}
- rm ${PATH_BACKUP_DB}-journal
-}
-
-echo "#### 1. Upgrade component db ####"
-Init
-Upgrade
-Fini
-echo "#### 1. Upgrade component db [Done] ####"
+++ /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 "component_plugin_parser.h"
-#include "component_plugin_parser_handler.h"
-#include "component_plugin_parser_private.h"
-
-int component_plugin_parser_install(xmlDocPtr doc, const char *package)
-{
- int ret;
-
- ret = component_plugin_parser_handler_init();
- if (ret < 0) {
- LOGE("Failed to initialize parser handler");
- return -1;
- }
-
- ret = component_plugin_parser_handler_install(package, doc);
- if (ret < 0) {
- LOGE("Failed to intall components. package(%s)", package);
- component_plugin_parser_handler_fini();
- return -1;
- }
-
- component_plugin_parser_handler_fini();
-
- return 0;
-}
-
-int component_plugin_parser_uninstall(xmlDocPtr doc, const char *package)
-{
- int ret;
-
- ret = component_plugin_parser_handler_init();
- if (ret < 0) {
- LOGE("Failed to initializer parser handler");
- return -1;
- }
-
- ret = component_plugin_parser_handler_uninstall(package);
- if (ret < 0) {
- LOGE("Failed to uninstall components. package(%s)", package);
- component_plugin_parser_handler_fini();
- return 0;
- }
-
- component_plugin_parser_handler_fini();
-
- return 0;
-}
-
-int component_plugin_parser_upgrade(xmlDocPtr doc, const char *package)
-{
- int ret;
-
- ret = component_plugin_parser_handler_init();
- if (ret < 0) {
- LOGE("Failed to initialize parser handler");
- return -1;
- }
-
- ret = component_plugin_parser_handler_uninstall(package);
- if (ret < 0)
- LOGW("Failed to uninstall components. package(%s)", package);
-
- ret = component_plugin_parser_handler_install(package, doc);
- if (ret < 0) {
- LOGE("Failed to install components. package(%s)", package);
- component_plugin_parser_handler_fini();
- return -1;
- }
-
- component_plugin_parser_handler_fini();
-
- return 0;
-}
+++ /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 <unistd.h>
-#include <dlfcn.h>
-#include <sys/types.h>
-#include <libgen.h>
-#include <linux/limits.h>
-#include <sqlite3.h>
-#include <tzplatform_config.h>
-#include <pkgmgr_installer_info.h>
-#include <dlog.h>
-
-#include "component_plugin_parser_db.h"
-#include "component_plugin_parser_private.h"
-
-#define LIBCAPI_SYSTEM_INFO LIBDIR"/libcapi-system-info.so.0"
-
-#define BUSY_WAITING_USEC 50000
-#define BUSY_WAITING_MAX 40
-
-#define BIND_TEXT(db, stmt, i, text) do { \
- if (sqlite3_bind_text(stmt, i, text, -1, SQLITE_STATIC) != SQLITE_OK) {\
- LOGE("sqlite3_bind_text() is failed. error(%s)", \
- sqlite3_errmsg(db)); \
- sqlite3_finalize(stmt); \
- return -1; \
- } \
-} while (0)
-
-struct cb_data_s {
- const char *lang;
- int dpi;
-};
-
-static sqlite3 *__db;
-static int (*__system_info_get_platform_int)(const char *, int *);
-
-static int __load_system_info(void)
-{
- void *handle;
-
- if (__system_info_get_platform_int)
- return 0;
-
- __system_info_get_platform_int = dlsym(RTLD_DEFAULT,
- "system_info_get_platform_int");
- if (__system_info_get_platform_int)
- return 0;
-
- handle = dlopen(LIBCAPI_SYSTEM_INFO, RTLD_LAZY | RTLD_LOCAL);
- if (!handle) {
- LOGE("Failed to open %s", LIBCAPI_SYSTEM_INFO);
- return -1;
- }
-
- __system_info_get_platform_int = dlsym(handle,
- "system_info_get_platform_int");
- if (!__system_info_get_platform_int) {
- LOGE("Failed to find system_info_get_platform_int");
- return -1;
- }
-
- return 0;
-}
-
-uid_t component_plugin_parser_db_get_target_uid(void)
-{
- static uid_t target_uid = (uid_t)-1;
- int ret;
-
- if (target_uid != (uid_t)-1)
- return target_uid;
-
- ret = pkgmgr_installer_info_get_target_uid(&target_uid);
- if (ret < 0)
- LOGE("Failed to get target uid. error(%d)", ret);
-
- return target_uid;
-}
-
-static bool __is_global_user(uid_t uid)
-{
- if (uid == ROOT_UID || uid == GLOBAL_USER)
- return true;
-
- return false;
-}
-
-static const char *__get_db_path(uid_t uid)
-{
- static char db_path[PATH_MAX];
- const char *path;
-
- path = tzplatform_getenv(TZ_SYS_DB);
- if (!path) {
- LOGE("Failed to get TZ_SYS_DB path");
- return NULL;
- }
-
- if (__is_global_user(uid)) {
- snprintf(db_path, sizeof(db_path), "%s/.component.db", path);
- } else {
- snprintf(db_path, sizeof(db_path), "%s/user/%u/.component.db",
- path, uid);
- }
-
- return db_path;
-}
-
-static int __db_busy_handler(void *data, int count)
-{
- const char *path = (const char *)data;
-
- if (count < BUSY_WAITING_MAX) {
- usleep(BUSY_WAITING_USEC);
- return 1;
- }
-
- LOGE("Database(%s) is busy", path);
-
- return 0;
-}
-
-static sqlite3 *__open_db(const char *path)
-{
- sqlite3 *db = NULL;
- int ret;
-
- ret = sqlite3_open_v2(path, &db, SQLITE_OPEN_READWRITE, NULL);
- if (ret != SQLITE_OK) {
- LOGE("sqlite3_open_v2() is failed. error(%d)", ret);
- sqlite3_close_v2(db);
- return NULL;
- }
-
- ret = sqlite3_busy_handler(db, __db_busy_handler, (void *)path);
- if (ret != SQLITE_OK) {
- LOGE("Failed to register busy handler. error(%s)",
- sqlite3_errmsg(db));
- sqlite3_close_v2(db);
- return NULL;
- }
-
- ret = sqlite3_exec(db, "PRAGMA foreign_keys=ON", NULL, NULL, NULL);
- if (ret != SQLITE_OK) {
- LOGE("Failed to enable foreign key support. error(%s)",
- sqlite3_errmsg(db));
- sqlite3_close_v2(db);
- return NULL;
- }
-
- return db;
-}
-
-void __close_db(sqlite3 *db)
-{
- if (!db)
- return;
-
- sqlite3_close_v2(db);
-}
-
-static bool __integrity_check(sqlite3 *db)
-{
- static const char query[] = "PRAGMA integrity_check";
- sqlite3_stmt *stmt = NULL;
- const char *res;
- int ret;
-
- ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
- if (ret != SQLITE_OK) {
- LOGE("sqlite3_prepare_v2() is failed. error(%s)",
- sqlite3_errmsg(db));
- return false;
- }
-
- ret = sqlite3_step(stmt);
- if (ret != SQLITE_ROW) {
- LOGE("sqlite3_step() is failed. error(%s)", sqlite3_errmsg(db));
- sqlite3_finalize(stmt);
- return false;
- }
-
- res = (const char *)sqlite3_column_text(stmt, 0);
- if (!res) {
- LOGE("Failed to check integrity db. error(%s)",
- sqlite3_errmsg(db));
- sqlite3_finalize(stmt);
- return false;
- }
-
- if (strcmp(res, "ok") != 0) {
- sqlite3_finalize(stmt);
- return false;
- }
-
- sqlite3_finalize(stmt);
-
- return true;
-}
-
-static gint __compare_lang(gconstpointer a, gconstpointer b,
- gpointer user_data)
-{
- const char *lang_a = (const char *)a;
- const char *lang_b = (const char *)b;
-
- if (lang_a == NULL || lang_b == NULL)
- return 0;
-
- return strcmp(lang_a, lang_b);
-}
-
-static gint __compare_label_with_lang(gconstpointer a, gconstpointer b)
-{
- label_t *label = (label_t *)a;
- const char *lang = (const char *)b;
-
- return strcasecmp(label->lang, lang);
-}
-
-static int __check_screen_dpi(const char *dpi_str, int dpi_int)
-{
- if (dpi_str == NULL)
- return -1;
-
- if (strcasecmp(dpi_str, LDPI) == 0) {
- if (dpi_int >= LDPI_MIN && dpi_int <= LDPI_MAX)
- return 0;
- } else if (strcasecmp(dpi_str, MDPI) == 0) {
- if (dpi_int >= MDPI_MIN && dpi_int <= MDPI_MAX)
- return 0;
- } else if (strcasecmp(dpi_str, HDPI) == 0) {
- if (dpi_int >= HDPI_MIN && dpi_int <= HDPI_MAX)
- return 0;
- } else if (strcasecmp(dpi_str, XHDPI) == 0) {
- if (dpi_int >= XHDPI_MIN && dpi_int <= XHDPI_MAX)
- return 0;
- } else if (strcasecmp(dpi_str, XXHDPI) == 0) {
- if (dpi_int >= XXHDPI_MIN && dpi_int <= XXHDPI_MAX)
- return 0;
- }
-
- return -1;
-}
-
-static int __get_screen_dpi_strings(int dpi, const char *(*dpi_str)[2])
-{
- if (!dpi_str)
- return -1;
-
- if (dpi >= LDPI_MIN && dpi <= LDPI_MAX) {
- (*dpi_str)[0] = "LDPI";
- (*dpi_str)[1] = "ldpi";
- } else if (dpi >= MDPI_MIN && dpi <= MDPI_MAX) {
- (*dpi_str)[0] = "MDPI";
- (*dpi_str)[1] = "mdpi";
- } else if (dpi >= HDPI_MIN && dpi <= HDPI_MAX) {
- (*dpi_str)[0] = "HDPI";
- (*dpi_str)[1] = "hdpi";
- } else if (dpi >= XHDPI_MIN && dpi <= XHDPI_MAX) {
- (*dpi_str)[0] = "XHDPI";
- (*dpi_str)[1] = "xhdpi";
- } else if (dpi >= XXHDPI_MIN && dpi <= XXHDPI_MAX) {
- (*dpi_str)[0] = "XXHDPI";
- (*dpi_str)[1] = "xxhdpi";
- } else {
- LOGE("Unidentified dpi[%d]", dpi);
- return -1;
- }
-
- return 0;
-}
-
-static int __check_icon_resolution(int dpi, const char *icon, char **new_icon)
-{
- const char *dpi_str[2] = { NULL, };
- char path[PATH_MAX];
- char buf[PATH_MAX];
- const char *file;
- const char *dir;
- int ret;
-
- if (!icon || !new_icon)
- return -1;
-
- ret = __get_screen_dpi_strings(dpi, &dpi_str);
- if (ret != 0)
- return -1;
-
- snprintf(buf, sizeof(buf), "%s", icon);
- file = basename(buf);
- if (!file)
- return -1;
-
- dir = dirname(buf);
- if (!dir)
- return -1;
-
- snprintf(path, sizeof(path), "%s/%s%s", dir, dpi_str[0], file);
- if (access(path, F_OK) == 0) {
- *new_icon = strdup(path);
- return 0;
- }
-
- snprintf(path, sizeof(path), "%s/%s%s", dir, dpi_str[1], file);
- if (access(path, F_OK) == 0) {
- *new_icon = strdup(path);
- return 0;
- }
-
- return -1;
-}
-
-static gint __compare_icon_with_lang_dpi(gconstpointer a, gconstpointer b)
-{
- icon_t *icon = (icon_t *)a;
- struct cb_data_s *cb_data = (struct cb_data_s *)b;
-
- if (strcasecmp(icon->lang, cb_data->lang) == 0 &&
- __check_screen_dpi(icon->dpi, cb_data->dpi) == 0)
- return 0;
-
- return -1;
-}
-
-static gint __compare_icon_with_lang(gconstpointer a, gconstpointer b)
-{
- icon_t *icon = (icon_t *)a;
- struct cb_data_s *cb_data = (struct cb_data_s *)b;
- char *new_icon = NULL;
-
- if (strcasecmp(icon->lang, cb_data->lang) == 0) {
- if (strcmp(icon->lang, DEFAULT_LOCALE) == 0) {
- __check_icon_resolution(cb_data->dpi,
- icon->icon, &new_icon);
- if (new_icon) {
- free(icon->icon);
- icon->icon = new_icon;
- }
- }
-
- return 0;
- }
-
- return -1;
-}
-
-static gint __compare_icon_with_dpi(gconstpointer a, gconstpointer b)
-{
- icon_t *icon = (icon_t *)a;
- struct cb_data_s *cb_data = (struct cb_data_s *)b;
-
- if (icon->lang && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
- return -1;
-
- if (icon->dpi == NULL)
- return -1;
-
- if (__check_screen_dpi(icon->dpi, cb_data->dpi) == 0)
- return 0;
-
- return -1;
-}
-
-static gint __compare_icon_with_default_lang(gconstpointer a, gconstpointer b)
-{
- icon_t *icon = (icon_t *)a;
- struct cb_data_s *cb_data = (struct cb_data_s *)b;
- char *new_icon = NULL;
-
- if (icon->lang && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
- return -1;
-
- if (icon->dpi != NULL)
- return -1;
-
- __check_icon_resolution(cb_data->dpi, icon->icon, &new_icon);
- if (new_icon) {
- free(icon->icon);
- icon->icon = new_icon;
- }
-
- return 0;
-}
-
-static void __foreach_label_lang(gpointer data, gpointer user_data)
-{
- label_t *label = (label_t *)data;
- GList **locales = (GList **)user_data;
-
- if (!label)
- return;
-
- if (!label->lang)
- return;
-
- *locales = g_list_insert_sorted_with_data(*locales,
- (gpointer)label->lang, __compare_lang, NULL);
-}
-
-static void __foreach_icon_lang(gpointer data, gpointer user_data)
-{
- icon_t *icon = (icon_t *)data;
- GList **locales = (GList **)user_data;
-
- if (!icon)
- return;
-
- if (!icon->lang)
- return;
-
- *locales = g_list_insert_sorted_with_data(*locales,
- (gpointer)icon->lang, __compare_lang, NULL);
-}
-
-static GList *__create_locale_list(GList *labels, GList *icons)
-{
- const char *prev_locale = NULL;
- const char *locale;
- GList *locales = NULL;
- GList *iter;
-
- g_list_foreach(labels, __foreach_label_lang, &locales);
- g_list_foreach(icons, __foreach_icon_lang, &locales);
-
- iter = locales;
- while (iter) {
- locale = (const char *)iter->data;
- iter = g_list_next(iter);
- if (prev_locale) {
- if (!strcmp(prev_locale, locale))
- locales = g_list_remove(locales, locale);
- else
- prev_locale = locale;
- } else {
- prev_locale = locale;
-
- }
- }
-
- return locales;
-}
-
-static const char *__find_label(GList *labels, const char *locale)
-{
- label_t *label;
- GList *found;
-
- found = g_list_find_custom(labels, locale, __compare_label_with_lang);
- if (!found)
- return NULL;
-
- label = (label_t *)found->data;
- if (!label)
- return NULL;
-
- return label->label;
-}
-
-static const char *__find_icon(GList *icons, const char *locale)
-{
- struct cb_data_s cb_data = { locale, -1};
- icon_t *icon;
- GList *found;
- int ret;
-
- ret = __load_system_info();
- if (ret < 0)
- return NULL;
-
- ret = __system_info_get_platform_int(FEATURE_SCREEN_DPI, &cb_data.dpi);
- if (ret != 0)
- return NULL;
-
- /* Step 1 */
- found = g_list_find_custom(icons, &cb_data,
- (GCompareFunc)__compare_icon_with_lang_dpi);
- if (found) {
- icon = (icon_t *)found->data;
- return icon->icon;
- }
-
- /* Step 2 */
- found = g_list_find_custom(icons, &cb_data,
- (GCompareFunc)__compare_icon_with_lang);
- if (found) {
- icon = (icon_t *)found->data;
- return icon->icon;
- }
-
- /* Step 3 */
- found = g_list_find_custom(icons, &cb_data,
- (GCompareFunc)__compare_icon_with_dpi);
- if (found) {
- icon = (icon_t *)found->data;
- return icon->icon;
- }
-
- /* Step 4 */
- found = g_list_find_custom(icons, &cb_data,
- (GCompareFunc)__compare_icon_with_default_lang);
- if (found) {
- icon = (icon_t *)found->data;
- return icon->icon;
- }
-
- return NULL;
-}
-
-static int __insert_component_localized_info(component_t *component,
- GList *locales)
-{
- static const char query[] =
- "INSERT INTO component_localized_info "
- "(component_id, component_locale, component_label, "
- "component_icon) VALUES (?, ?, ?, ?)";
- sqlite3_stmt *stmt = NULL;
- const char *locale;
- const char *label;
- const char *icon;
- GList *iter;
- int idx;
- int ret;
-
- ret = sqlite3_prepare_v2(__db, query, strlen(query), &stmt, NULL);
- if (ret != SQLITE_OK) {
- LOGE("sqlite3_prepare_v2() is failed. error(%s)",
- sqlite3_errmsg(__db));
- return -1;
- }
-
- iter = locales;
- while (iter) {
- locale = (const char *)iter->data;
- iter = g_list_next(iter);
-
- label = __find_label(component->label, locale);
- icon = __find_icon(component->icon, locale);
- if (!label && !icon)
- continue;
-
- idx = 1;
- BIND_TEXT(__db, stmt, idx++, component->id);
- BIND_TEXT(__db, stmt, idx++, locale);
- BIND_TEXT(__db, stmt, idx++, label);
- BIND_TEXT(__db, stmt, idx++, icon);
-
- ret = sqlite3_step(stmt);
- if (ret != SQLITE_DONE) {
- LOGE("sqlite3_step() is failed. error(%s)",
- sqlite3_errmsg(__db));
- sqlite3_finalize(stmt);
- return -1;
- }
-
- sqlite3_reset(stmt);
- }
-
- sqlite3_finalize(stmt);
-
- return 0;
-}
-
-int component_plugin_parser_db_insert(component_t *component)
-{
- static const char query[] =
- "INSERT INTO component_info "
- "(package, app_id, component_id, component_type, "
- "component_launch_mode, component_main, "
- "component_icon_display, component_taskmanage) "
- "VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
- sqlite3_stmt *stmt = NULL;
- GList *locales = NULL;
- int idx;
- int ret;
-
- if (!component) {
- LOGE("Invalid parameter");
- return -1;
- }
-
- if (!__db) {
- LOGE("Database is not prepared");
- return -1;
- }
-
- ret = sqlite3_prepare_v2(__db, query, strlen(query), &stmt, NULL);
- if (ret != SQLITE_OK) {
- LOGE("sqlite3_prepare_v2() is failed. error(%s)",
- sqlite3_errmsg(__db));
- return -1;
- }
-
- idx = 1;
- BIND_TEXT(__db, stmt, idx++, component->package);
- BIND_TEXT(__db, stmt, idx++, component->app_id);
- BIND_TEXT(__db, stmt, idx++, component->id);
- BIND_TEXT(__db, stmt, idx++, component->type);
- BIND_TEXT(__db, stmt, idx++, component->launch_mode);
- BIND_TEXT(__db, stmt, idx++, component->main);
- BIND_TEXT(__db, stmt, idx++, component->icon_display);
- BIND_TEXT(__db, stmt, idx++, component->taskmanage);
-
- ret = sqlite3_step(stmt);
- if (ret != SQLITE_DONE) {
- LOGE("sqlite3_step() is failed. error(%s)",
- sqlite3_errmsg(__db));
- sqlite3_finalize(stmt);
- return -1;
- }
- sqlite3_finalize(stmt);
-
- locales = __create_locale_list(component->label, component->icon);
- ret = __insert_component_localized_info(component, locales);
- if (ret < 0) {
- LOGE("Failed to insert component localized info");
- g_list_free(locales);
- return -1;
- }
- g_list_free(locales);
-
- return 0;
-}
-
-int component_plugin_parser_db_delete(const char *package)
-{
- static const char query[] =
- "DELETE FROM component_info WHERE package=?";
- sqlite3_stmt *stmt = NULL;
- int ret;
-
- if (!package) {
- LOGE("Invalid parameter");
- return -1;
- }
-
- if (!__db) {
- LOGE("Database is not prepared");
- return -1;
- }
-
- ret = sqlite3_prepare_v2(__db, query, strlen(query), &stmt, NULL);
- if (ret != SQLITE_OK) {
- LOGE("sqlite3_prepare_v2() is failed. error(%s)",
- sqlite3_errmsg(__db));
- return -1;
- }
-
- BIND_TEXT(__db, stmt, 1, package);
-
- ret = sqlite3_step(stmt);
- if (ret != SQLITE_DONE) {
- LOGE("sqlite3_step() is failed. error(%s)",
- sqlite3_errmsg(__db));
- sqlite3_finalize(stmt);
- return -1;
- }
-
- sqlite3_finalize(stmt);
-
- return 0;
-}
-
-int component_plugin_parser_db_begin_transaction(void)
-{
- int ret;
-
- if (!__db) {
- LOGE("Database is not prepared");
- return -1;
- }
-
- ret = sqlite3_exec(__db, "BEGIN TRANSACTION", NULL, NULL, NULL);
- if (ret != SQLITE_OK) {
- LOGE("Transaction is failed. error(%s)", sqlite3_errmsg(__db));
- return -1;
- }
-
- return 0;
-}
-
-int component_plugin_parser_db_end_transaction(void)
-{
- int ret;
-
- if (!__db) {
- LOGE("Database is not prepared");
- return -1;
- }
-
- ret = sqlite3_exec(__db, "END TRANSACTION", NULL, NULL, NULL);
- if (ret != SQLITE_OK) {
- LOGE("Transaction is failed. error(%s)", sqlite3_errmsg(__db));
- return -1;
- }
-
- return 0;
-}
-
-int component_plugin_parser_db_rollback(void)
-{
- int ret;
-
- if (!__db) {
- LOGE("Database is not prepared");
- return -1;
- }
-
- ret = sqlite3_exec(__db, "ROLLBACK", NULL, NULL, NULL);
- if (ret != SQLITE_OK) {
- LOGE("Rollback is failed. error(%s)", sqlite3_errmsg(__db));
- return -1;
- }
-
- return 0;
-}
-
-int component_plugin_parser_db_init(void)
-{
- const char *path;
- uid_t target_uid;
- int ret;
-
- target_uid = component_plugin_parser_db_get_target_uid();
- path = __get_db_path(target_uid);
- if (!path) {
- LOGE("Failed to get db path. uid(%u)", target_uid);
- return -1;
- }
-
- ret = access(path, F_OK);
- if (ret != 0) {
- LOGE("%s does not exists", path);
- return -1;
- }
-
- __db = __open_db(path);
- if (!__db) {
- LOGE("Failed to open db(%s)", path);
- return -1;
- }
-
- if (!__integrity_check(__db)) {
- LOGE("Database(%s) is corrupted", path);
- __close_db(__db);
- __db = NULL;
- return -1;
- }
-
- return 0;
-}
-
-int component_plugin_parser_db_fini(void)
-{
- if (!__db)
- return -1;
-
- __close_db(__db);
- __db = NULL;
-
- return 0;
-}
+++ /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.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdbool.h>
-#include <string.h>
-#include <stdint.h>
-#include <sys/types.h>
-
-#include <glib.h>
-#include <pkgmgr-info.h>
-
-#include "component_plugin_parser_handler.h"
-#include "component_plugin_parser_private.h"
-#include "component_plugin_parser_type.h"
-#include "component_plugin_parser_db.h"
-
-typedef enum {
- COMPONENT_TYPE_NONE,
- COMPONENT_TYPE_FRAME,
- COMPONENT_TYPE_SERVICE,
- COMPONENT_TYPE_WIDGET,
- COMPONENT_TYPE_MAX,
-} component_type_e;
-
-typedef enum {
- COMPONENT_ATTR_NONE,
- COMPONENT_ATTR_ID,
- COMPONENT_ATTR_LAUNCH_MODE,
- COMPONENT_ATTR_MAIN,
- COMPONENT_ATTR_ICON_DISPLAY,
- COMPONENT_ATTR_TASKMANAGE,
- COMPONENT_ATTR_MAX,
-} component_attr_e;
-
-typedef enum {
- COMPONENT_ELM_NONE,
- COMPONENT_ELM_ICON,
- COMPONENT_ELM_LABEL,
- COMPONENT_ELM_MAX,
-} component_elm_e;
-
-typedef enum {
- COMPONENT_ICON_ATTR_NONE,
- COMPONENT_ICON_ATTR_TEXT,
- COMPONENT_ICON_ATTR_LANG,
- COMPONENT_ICON_ATTR_DPI,
- COMPONENT_ICON_ATTR_MAX,
-} component_icon_attr_e;
-
-typedef enum {
- COMPONENT_LABEL_ATTR_NONE,
- COMPONENT_LABEL_ATTR_TEXT,
- COMPONENT_LABEL_ATTR_LANG,
- COMPONENT_LABEL_ATTR_MAX,
-} component_label_attr_e;
-
-typedef struct {
- uint32_t tag;
- const char *name;
-} tag_map_t;
-
-static tag_map_t __component_type_map[] = {
- { COMPONENT_TYPE_FRAME, "frame-component" },
- { COMPONENT_TYPE_SERVICE, "service-component" },
- { COMPONENT_TYPE_WIDGET, "widget-component" },
-};
-
-static const char *__component_type_string[] = {
- [COMPONENT_TYPE_FRAME] = "frame",
- [COMPONENT_TYPE_SERVICE] = "service",
- [COMPONENT_TYPE_WIDGET] = "widget",
-};
-
-static const char *__component_attr_string[] = {
- [COMPONENT_ATTR_ID] = "id",
- [COMPONENT_ATTR_LAUNCH_MODE] = "launch_mode",
- [COMPONENT_ATTR_MAIN] = "main",
- [COMPONENT_ATTR_ICON_DISPLAY] = "icon-display",
- [COMPONENT_ATTR_TASKMANAGE] = "taskmanage",
-};
-
-static const char *__component_elm_string[] = {
- [COMPONENT_ELM_ICON] = "icon",
- [COMPONENT_ELM_LABEL] = "label",
-};
-
-static const char *__component_icon_attr_string[] = {
- [COMPONENT_ICON_ATTR_TEXT] = "#text",
- [COMPONENT_ICON_ATTR_LANG] = "lang",
- [COMPONENT_ICON_ATTR_DPI] = "dpi",
-};
-
-static const char *__component_label_attr_string[] = {
- [COMPONENT_LABEL_ATTR_TEXT] = "#text",
- [COMPONENT_LABEL_ATTR_LANG] = "lang",
-};
-
-typedef int (*component_plugin_parser_func)(xmlNode *node, void *data);
-
-static char __root_path[PATH_MAX];
-
-static uint32_t __get_component_type_tag(const char *name)
-{
- uint32_t i;
-
- for (i = 0; i < ARRAY_SIZE(__component_type_map); i++) {
- if (!strcmp(__component_type_map[i].name, name))
- return __component_type_map[i].tag;
- }
-
- return 0;
-}
-
-static bool __is_service_component(const char *type)
-{
- if (!strcmp(type, __component_type_string[COMPONENT_TYPE_SERVICE]))
- return true;
-
- return false;
-}
-
-static bool __is_widget_component(const char *type)
-{
- if (!strcmp(type, __component_type_string[COMPONENT_TYPE_WIDGET]))
- return true;
-
- return false;
-}
-
-static bool __is_boolean(const char *value)
-{
- if (!strcmp(value, "true") || !strcmp(value, "false"))
- return true;
-
- return false;
-}
-
-static char *__get_attribute(xmlNode *node, const char *name)
-{
- xmlChar *val;
- char *attr = NULL;
-
- val = xmlGetProp(node, (const xmlChar *)name);
- if (val) {
- attr = strdup((char *)val);
- xmlFree(val);
- }
-
- return attr;
-}
-
-static char *__get_language(xmlNode *node)
-{
- xmlChar *val;
- char *lang = NULL;
-
- val = xmlNodeGetLang(node);
- if (val) {
- lang = strdup((char *)val);
- xmlFree(val);
- }
-
- return lang;
-}
-
-static const char *__get_name(xmlNode *node)
-{
- if (!node)
- return NULL;
-
- return (const char *)node->name;
-}
-
-static void __set_root_path(const char *package)
-{
- uid_t uid = component_plugin_parser_db_get_target_uid();
- pkgmgrinfo_pkginfo_h handle = NULL;
- char *root_path = NULL;
- int ret;
-
- ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(package, uid, &handle);
- if (ret != PMINFO_R_OK) {
- LOGE("Failed to get package(%s) info", package);
- return;
- }
-
- ret = pkgmgrinfo_pkginfo_get_root_path(handle, &root_path);
- if (ret != PMINFO_R_OK)
- LOGE("Failed to get root path. package(%s)", package);
-
- if (root_path)
- snprintf(__root_path, sizeof(__root_path), "%s", root_path);
-
- pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
-}
-
-static void __destroy_label(gpointer data)
-{
- label_t *info = (label_t *)data;
-
- if (!info)
- return;
-
- if (info->label)
- free(info->label);
- if (info->lang)
- free(info->lang);
- free(info);
-}
-
-static void __destroy_icon(gpointer data)
-{
- icon_t *info = (icon_t *)data;
-
- if (!info)
- return;
-
- if (info->icon)
- free(info->icon);
- if (info->lang)
- free(info->lang);
- if (info->dpi)
- free(info->dpi);
- free(info);
-}
-
-static void __destroy_component(gpointer data)
-{
- component_t *info = (component_t *)data;
-
- if (!info)
- return;
-
- if (info->package)
- free(info->package);
- if (info->app_id)
- free(info->app_id);
- if (info->id)
- free(info->id);
- if (info->launch_mode)
- free(info->launch_mode);
- if (info->main)
- free(info->main);
- if (info->icon_display)
- free(info->icon_display);
- if (info->taskmanage)
- free(info->taskmanage);
- if (info->icon)
- g_list_free_full(info->icon, __destroy_icon);
- if (info->label)
- g_list_free_full(info->label, __destroy_label);
- free(info);
-}
-
-static component_t *__create_component(const char *package, const char *app_id,
- const char *type)
-{
- component_t *info;
-
- info = calloc(1, sizeof(component_t));
- if (!info) {
- LOGE("Out of memory");
- return NULL;
- }
-
- info->package = strdup(package);
- if (!info->package) {
- LOGE("Failed to duplicate package");
- free(info);
- return NULL;
- }
-
- info->app_id = strdup(app_id);
- if (!info->app_id) {
- LOGE("Failed to duplicate app_id");
- __destroy_component(info);
- return NULL;
- }
-
- info->type = strdup(type);
- if (!info->type) {
- LOGE("Failed to duplicate type");
- __destroy_component(info);
- return NULL;
- }
-
- return info;
-}
-
-static int __component_label_attr_text(xmlNode *node, void *data)
-{
- label_t *info = (label_t *)data;
-
- info->label = strdup((const char *)node->children->content);
- if (!info->label) {
- LOGE("Failed to duplicate label");
- return -1;
- }
-
- return 0;
-}
-
-static int __component_label_attr_lang(xmlNode *node, void *data)
-{
- label_t *info = (label_t *)data;
- char *lang;
-
- lang = __get_language(node);
- if (!lang) {
- info->lang = strdup(DEFAULT_LOCALE);
- if (!info->lang) {
- LOGE("Out of memory");
- return -1;
- }
- } else {
- info->lang = lang;
- }
-
- return 0;
-}
-
-static component_plugin_parser_func __label_attr_table[] = {
- [COMPONENT_LABEL_ATTR_TEXT] = __component_label_attr_text,
- [COMPONENT_LABEL_ATTR_LANG] = __component_label_attr_lang,
-};
-
-static int __component_icon_attr_text(xmlNode *node, void *data)
-{
- icon_t *info = (icon_t *)data;
- const char *file = (const char *)node->children->content;
- char *path;
- int size;
-
- if (file[0] == '/') {
- size = strlen(file) + 1;
- path = (char *)malloc(size);
- if (!path) {
- LOGE("Out of memory");
- return -1;
- }
-
- snprintf(path, size, "%s", file);
- } else {
- size = strlen(__root_path) + strlen("/shared/res/") +
- strlen(file) + 1;
- path = (char *)malloc(size);
- if (!path) {
- LOGE("Out of memory");
- return -1;
- }
-
- snprintf(path, size, "%s/shared/res/%s", __root_path, file);
- }
-
- info->icon = path;
-
- return 0;
-}
-
-static int __component_icon_attr_lang(xmlNode *node, void *data)
-{
- icon_t *info = (icon_t *)data;
- char *lang;
-
- lang = __get_language(node);
- if (!lang) {
- info->lang = strdup(DEFAULT_LOCALE);
- if (!info->lang) {
- LOGE("Out of memory");
- return -1;
- }
- } else {
- info->lang = lang;
- }
-
- return 0;
-}
-
-static int __component_icon_attr_dpi(xmlNode *node, void *data)
-{
- icon_t *info = (icon_t *)data;
- const char *key;
-
- key = __component_icon_attr_string[COMPONENT_ICON_ATTR_DPI];
- info->dpi = __get_attribute(node, key);
-
- return 0;
-}
-
-static component_plugin_parser_func __icon_attr_table[] = {
- [COMPONENT_ICON_ATTR_TEXT] = __component_icon_attr_text,
- [COMPONENT_ICON_ATTR_LANG] = __component_icon_attr_lang,
- [COMPONENT_ICON_ATTR_DPI] = __component_icon_attr_dpi,
-};
-
-static int __component_elm_icon(xmlNode *node, void *data)
-{
- component_t *info = (component_t *)data;
- const char *key = __component_elm_string[COMPONENT_ELM_ICON];
- icon_t *icon;
- uint32_t i;
- int ret;
-
- if (strcmp(__get_name(node), key) != 0)
- return 0;
-
- if (!node->children || !node->children->content)
- return 0;
-
- icon = calloc(1, sizeof(icon_t));
- if (!icon) {
- LOGE("Out of memory");
- return -1;
- }
-
- for (i = 0; i < ARRAY_SIZE(__icon_attr_table); i++) {
- if (!__icon_attr_table[i])
- continue;
-
- ret = __icon_attr_table[i](node, icon);
- if (ret < 0) {
- LOGE("Failed to parse icon attribute %s",
- __component_icon_attr_string[i]);
- __destroy_icon(icon);
- return -1;
- }
- }
-
- info->icon = g_list_append(info->icon, icon);
-
- return 0;
-}
-
-static int __component_elm_label(xmlNode *node, void *data)
-{
- component_t *info = (component_t *)data;
- const char *key = __component_elm_string[COMPONENT_ELM_LABEL];
- label_t *label;
- uint32_t i;
- int ret;
-
- if (strcmp(__get_name(node), key) != 0)
- return 0;
-
- if (!node->children || !node->children->content)
- return 0;
-
- label = calloc(1, sizeof(label_t));
- if (!label) {
- LOGE("Out of memory");
- return -1;
- }
-
- for (i = 0; i < ARRAY_SIZE(__label_attr_table); i++) {
- if (!__label_attr_table[i])
- continue;
-
- ret = __label_attr_table[i](node, label);
- if (ret < 0) {
- LOGE("Failed to parse label attribute %s",
- __component_label_attr_string[i]);
- __destroy_label(label);
- return -1;
- }
- }
-
- info->label = g_list_append(info->label, label);
-
- return 0;
-}
-
-static component_plugin_parser_func __elm_table[] = {
- [COMPONENT_ELM_ICON] = __component_elm_icon,
- [COMPONENT_ELM_LABEL] = __component_elm_label,
-};
-
-/**
- * @brief Parses the elements of the component.
- */
-static int __parse_component_element(xmlNode *node, component_t *component)
-{
- uint32_t i;
- int ret;
-
- for (i = 0; i < ARRAY_SIZE(__elm_table); i++) {
- if (!__elm_table[i])
- continue;
-
- ret = __elm_table[i](node, component);
- if (ret < 0) {
- LOGE("Failed to parse element %s",
- __component_elm_string[i]);
- return -1;
- }
- }
-
- return 0;
-}
-
-static int __component_attr_id(xmlNode *node, void *data)
-{
- component_t *info = (component_t *)data;
- const char *key = __component_attr_string[COMPONENT_ATTR_ID];
- char *value;
-
- value = __get_attribute(node, key);
- if (!value) {
- LOGE("Failed to get id attribute");
- return -1;
- }
-
- info->id = value;
-
- return 0;
-}
-
-static int __component_attr_launch_mode(xmlNode *node, void *data)
-{
- component_t *info = (component_t *)data;
- const char *key = __component_attr_string[COMPONENT_ATTR_LAUNCH_MODE];
- char *value;
-
- if (__is_service_component(info->type) ||
- __is_widget_component(info->type)) {
- info->launch_mode = strdup("single");
- if (!info->launch_mode) {
- LOGE("Failed to duplicate launch mode");
- return -1;
- }
-
- return 0;
- }
-
- value = __get_attribute(node, key);
- if (!value) {
- info->launch_mode = strdup("single");
- if (!info->launch_mode) {
- LOGE("Failed to duplicate launch mode");
- return -1;
- }
-
- return 0;
- }
-
- if (strcmp(value, "single") != 0 &&
- strcmp(value, "caller") != 0 &&
- strcmp(value, "group") != 0) {
- LOGE("launch_mode should be 'single' or 'caller' or group'");
- free(value);
- return -1;
- }
-
- info->launch_mode = value;
-
- return 0;
-}
-
-static int __component_attr_main(xmlNode *node, void *data)
-{
- component_t *info = (component_t *)data;
- const char *key = __component_attr_string[COMPONENT_ATTR_MAIN];
- char *value;
-
- value = __get_attribute(node, key);
- if (!value) {
- info->main = strdup("true");
- if (!info->launch_mode) {
- LOGE("Failed to duplicate main");
- return -1;
- }
-
- return 0;
- }
-
- if (!__is_boolean(value)) {
- LOGE("main should be 'true' or 'false'");
- free(value);
- return -1;
- }
-
- info->main = value;
-
- return 0;
-}
-
-static int __component_attr_icon_display(xmlNode *node, void *data)
-{
- component_t *info = (component_t *)data;
- const char *key = __component_attr_string[COMPONENT_ATTR_ICON_DISPLAY];
- char *value;
-
- if (__is_service_component(info->type)) {
- info->icon_display = strdup("false");
- if (!info->icon_display) {
- LOGE("Failed to duplicate icon display");
- return -1;
- }
-
- return 0;
- }
-
- value = __get_attribute(node, key);
- if (!value) {
- info->icon_display = strdup("true");
- if (!info->icon_display) {
- LOGE("Failed to duplicate icon display");
- return -1;
- }
-
- return 0;
- }
-
- if (!__is_boolean(value)) {
- LOGE("icon-display should be 'true' or 'false'");
- free(value);
- return -1;
- }
-
- info->icon_display = value;
-
- return 0;
-}
-
-static int __component_attr_taskmanage(xmlNode *node, void *data)
-{
- component_t *info = (component_t *)data;
- const char *key = __component_attr_string[COMPONENT_ATTR_TASKMANAGE];
- char *value;
-
- if (__is_service_component(info->type) ||
- __is_widget_component(info->type)) {
- info->taskmanage = strdup("false");
- if (!info->taskmanage) {
- LOGE("Failed to duplicate taskmanage");
- return -1;
- }
-
- return 0;
- }
-
- value = __get_attribute(node, key);
- if (!value) {
- info->taskmanage = strdup("true");
- if (!info->taskmanage) {
- LOGE("Failed to duplicate taskmanage");
- return -1;
- }
-
- return 0;
- }
-
- if (!__is_boolean(value)) {
- LOGE("taskmanage should be 'true' or 'false'");
- free(value);
- return -1;
- }
-
- info->taskmanage = value;
-
- return 0;
-}
-
-static component_plugin_parser_func __attr_table[] = {
- [COMPONENT_ATTR_ID] = __component_attr_id,
- [COMPONENT_ATTR_LAUNCH_MODE] = __component_attr_launch_mode,
- [COMPONENT_ATTR_MAIN] = __component_attr_main,
- [COMPONENT_ATTR_ICON_DISPLAY] = __component_attr_icon_display,
- [COMPONENT_ATTR_TASKMANAGE] = __component_attr_taskmanage,
-};
-
-/**
- * @brief Parses the attributes of the component.
- */
-static int __parse_component_attribute(xmlNode *node, component_t *component)
-{
- uint32_t i;
- int ret;
-
- for (i = 0; i < ARRAY_SIZE(__attr_table); i++) {
- if (!__attr_table[i])
- continue;
-
- ret = __attr_table[i](node, component);
- if (ret < 0) {
- LOGE("Failed to parse attribute %s",
- __component_attr_string[i]);
- return -1;
- }
- }
-
- return 0;
-}
-
-static int __parse_component(const char *package, const char *app_id,
- xmlNode *node, component_t **component)
-{
- component_t *info = NULL;
- xmlNode *iter;
- const char *type;
- uint32_t tag;
- int ret;
-
- tag = __get_component_type_tag(__get_name(node));
- if (tag == COMPONENT_TYPE_NONE || tag >= COMPONENT_TYPE_MAX)
- return 0;
-
- type = __component_type_string[tag];
- info = __create_component(package, app_id, type);
- if (!info)
- return -1;
-
- ret = __parse_component_attribute(node, info);
- if (ret < 0) {
- __destroy_component(info);
- return -1;
- }
-
- for (iter = node->children; iter; iter = iter->next) {
- if (!iter->name)
- continue;
-
- ret = __parse_component_element(iter, info);
- if (ret < 0) {
- __destroy_component(info);
- return -1;
- }
- }
-
- *component = info;
-
- return 0;
-}
-
-/**
- * @brief Parses component-based-application
- *
- * Structure of tizen-manifest.xml for xml elements:
- * <component-based-application>
- * \_ <icon>
- * \_ <label>
- * \_ <metadata>
- * \_ <app-control>
- * \_ <background-category>
- * \_ <data-control>
- * \_ <splash-screens>
- * \_ <splash-screen>
- * \_ <frame-component>
- * \_ <icon>
- * \_ <label>
- * \_ <service-component>
- */
-static int __parse_component_based_application(const char *package,
- xmlNode *node, GList **list)
-{
- component_t *info;
- xmlNode *iter;
- char *app_id;
- int ret;
-
- app_id = __get_attribute(node, "appid");
- if (!app_id) {
- LOGE("Failed to get appid");
- return -1;
- }
-
- for (iter = node->children; iter; iter = iter->next) {
- if (!iter->name)
- continue;
-
- info = NULL;
- ret = __parse_component(package, app_id, iter, &info);
- if (ret < 0) {
- g_list_free_full(*list, __destroy_component);
- *list = NULL;
- free(app_id);
- return -1;
- }
-
- if (info)
- *list = g_list_append(*list, info);
- }
-
- free(app_id);
-
- return 0;
-}
-
-static gint __compare_component_main(gconstpointer a, gconstpointer b)
-{
- component_t *info = (component_t *)a;
- const char *value = (const char *)b;
-
- return strcmp(info->main, value);
-}
-
-static int __fill_extra_info(GList *components)
-{
- component_t *main_info = NULL;
- component_t *info;
- GList *found;
- GList *iter;
-
- found = g_list_find_custom(components, "true",
- __compare_component_main);
- if (found)
- main_info = (component_t *)found->data;
-
- if (!main_info) {
- main_info = (component_t *)components->data;
- free(main_info->main);
- main_info->main = strdup("true");
- }
-
- iter = components;
- while (iter) {
- info = (component_t *)iter->data;
- iter = g_list_next(iter);
- if (info == main_info)
- continue;
-
- free(info->main);
- info->main = strdup("false");
- }
-
- return 0;
-}
-
-static int __insert_component_info(GList *components)
-{
- component_t *info;
- GList *iter;
- int ret;
-
- ret = component_plugin_parser_db_begin_transaction();
- if (ret < 0) {
- LOGE("Failed to initialize db");
- return -1;
- }
-
- iter = components;
- while (iter) {
- info = (component_t *)iter->data;
- iter = g_list_next(iter);
- ret = component_plugin_parser_db_insert(info);
- if (ret < 0) {
- LOGE("Failed to insert component info(%s:%s)",
- info->app_id, info->id);
- component_plugin_parser_db_rollback();
- return -1;
- }
- }
-
- return component_plugin_parser_db_end_transaction();
-}
-
-int component_plugin_parser_handler_install(const char *package, xmlDocPtr doc)
-{
- GList *list = NULL;
- GList *tmp = NULL;
- const char *name;
- xmlNode *root;
- xmlNode *node;
- int ret;
-
- if (!doc || !package) {
- LOGE("Invalid parameter");
- return -1;
- }
-
- root = xmlDocGetRootElement(doc);
- if (!root) {
- LOGE("Failed to get root element");
- return -1;
- }
-
- __set_root_path(package);
-
- for (node = root->children; node; node = node->next) {
- name = __get_name(node);
- if (!name)
- continue;
-
- if (strcmp(name, "component-based-application") != 0)
- continue;
-
- ret = __parse_component_based_application(package, node, &tmp);
- if (ret < 0) {
- LOGE("Failed to parse component-based-application");
- g_list_free_full(list, __destroy_component);
- return -1;
- }
-
- if (!tmp) {
- LOGE("Component info is empty");
- g_list_free_full(list, __destroy_component);
- return -1;
- }
-
- __fill_extra_info(tmp);
- list = g_list_concat(list, tmp);
- tmp = NULL;
- }
-
- if (!list) {
- LOGE("Component info is empty");
- return -1;
- }
-
- ret = __insert_component_info(list);
- g_list_free_full(list, __destroy_component);
-
- return ret;
-}
-
-int component_plugin_parser_handler_uninstall(const char *package)
-{
- int ret;
-
- ret = component_plugin_parser_db_begin_transaction();
- if (ret < 0) {
- LOGE("Failed to initialize db");
- return -1;
- }
-
- ret = component_plugin_parser_db_delete(package);
- if (ret < 0) {
- LOGE("Failed to delete component info(%s)", package);
- component_plugin_parser_db_rollback();
- return -1;
- }
-
- return component_plugin_parser_db_end_transaction();
-}
-
-int component_plugin_parser_handler_init(void)
-{
- return component_plugin_parser_db_init();
-}
-
-int component_plugin_parser_handler_fini(void)
-{
- return component_plugin_parser_db_fini();
-}
+++ /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 <glib.h>
-#include <libxml/tree.h>
-
-#include "component_plugin_parser.h"
-#include "component_plugin_parser_private.h"
-
-EXPORT int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr doc, const char *package)
-{
- return component_plugin_parser_install(doc, package);
-}
-
-EXPORT int PKGMGR_PARSER_PLUGIN_UNINSTALL(xmlDocPtr doc, const char *package)
-{
- return component_plugin_parser_uninstall(doc, package);
-}
-
-EXPORT int PKGMGR_PARSER_PLUGIN_UPGRADE(xmlDocPtr doc, const char *package)
-{
- return component_plugin_parser_upgrade(doc, package);
-}
-
-EXPORT int PKGMGR_PARSER_PLUGIN_RECOVERINSTALL(xmlDocPtr doc,
- const char *package)
-{
- return component_plugin_parser_uninstall(doc, package);
-}
-
-EXPORT int PKGMGR_PARSER_PLUGIN_RECOVERUNINSTALL(xmlDocPtr doc,
- const char *package)
-{
- return component_plugin_parser_uninstall(doc, package);
-}
-
-EXPORT int PKGMGR_PARSER_PLUGIN_RECOVERUPGRADE(xmlDocPtr doc,
- const char *package)
-{
- return component_plugin_parser_upgrade(doc, package);
-}
-
+++ /dev/null
-SET(TARGET_CHECK_EXEC_PLUGIN_PARSER "exec-checker")
-
-SET(SHARED_DIR "${CMAKE_INSTALL_PREFIX}/share")
-
-SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall -Werror -Winline")
-
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src
- CHECK_EXEC_PLUGIN_PARSER_SRCS)
-
-ADD_LIBRARY(${TARGET_CHECK_EXEC_PLUGIN_PARSER} SHARED ${CHECK_EXEC_PLUGIN_PARSER_SRCS})
-TARGET_LINK_LIBRARIES(${TARGET_CHECK_EXEC_PLUGIN_PARSER} PUBLIC dl)
-
-TARGET_INCLUDE_DIRECTORIES(${TARGET_CHECK_EXEC_PLUGIN_PARSER}
- PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/inc)
-
-APPLY_PKG_CONFIG(${TARGET_CHECK_EXEC_PLUGIN_PARSER} PUBLIC
- DLOG_DEPS
- GLIB_DEPS
- LIBTZPLATFORM_CONFIG_DEPS
- LIBXML_DEPS
- PKGMGR_INFO_DEPS
- PKGMGR_INSTALLER_DEPS
-)
-
-INSTALL(TARGETS ${TARGET_CHECK_EXEC_PLUGIN_PARSER}
- DESTINATION ${SYSCONF_INSTALL_DIR}/package-manager/parserlib)
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/exec-checker.info
- DESTINATION ${SHARED_DIR}/parser-plugins)
+++ /dev/null
-type="tag";name="ui-application";path="/etc/package-manager/parserlib/libexec-checker.so"
-type="tag";name="service-application";path="/etc/package-manager/parserlib/libexec-checker.so"
-type="tag";name="widget-application";path="/etc/package-manager/parserlib/libexec-checker.so"
-type="tag";name="watch-application";path="/etc/package-manager/parserlib/libexec-checker.so"
-type="tag";name="component-based-application";path="/etc/package-manager/parserlib/libexec-checker.so"
+++ /dev/null
-/*
- * Copyright (c) 2021 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 EXEC_CHECKER_HH_
-#define EXEC_CHECKER_HH_
-
-#include <string>
-
-namespace plugin {
-
-class ExecChecker {
- public:
- explicit ExecChecker(std::string path);
- ~ExecChecker() = default;
- bool IsShared();
- bool CheckMainSymbol();
- bool CheckDependencyLibs();
- bool IsSameArch(const ExecChecker& exe);
-
- private:
- std::string path_;
- int class_bit_ = 0;
- uint16_t arch_bit_ = 0;
- uint16_t type_ = 0;
-};
-
-} // namespace plugin
-
-#endif // EXEC_CHECKER_HH_
+++ /dev/null
-/*
- * Copyright (c) 2021 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 EXEC_CEHCKER_PRIVATE_HH_
-#define EXEC_CEHCKER_PRIVATE_HH_
-
-#include <dlog.h>
-#include <stdio.h>
-
-#undef API
-#define API __attribute__((visibility("default")))
-
-#define ROOT_UID 0
-
-#undef LOG_TAG
-#define LOG_TAG "EXEC_CHECKER_PLUGIN_PARSER"
-
-#define LOGE_STD(fmt, arg...) \
- fprintf(stderr, "[%s][ERROR] " fmt "\n", LOG_TAG, ##arg)
-#define LOGW_STD(fmt, arg...) \
- fprintf(stderr, "[%s][WARNING] " fmt "\n", LOG_TAG, ##arg)
-#define LOGI_STD(fmt, arg...) printf("[%s][INFO] " fmt "\n", LOG_TAG, ##arg)
-
-#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
-
-#endif // EXEC_CEHCKER_PRIVATE_HH_
+++ /dev/null
-/*
- * Copyright (c) 2021 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 EXEC_CHECKER_PLUGIN_MANAGER_HH_
-#define EXEC_CHECKER_PLUGIN_MANAGER_HH_
-
-#include <libxml/tree.h>
-#include <memory>
-#include <string>
-
-#include "exec_checker.hh"
-
-namespace plugin {
-
-class PluginManager {
- public:
- static PluginManager& GetInst();
- void Init(xmlDocPtr doc, std::string package);
- int Process();
- ~PluginManager() = default;
-
- private:
- PluginManager();
-
- private:
- std::unique_ptr<ExecChecker> self_;
- std::string package_;
- xmlDocPtr doc_ = nullptr;
-};
-
-} // namespace plugin
-
-#endif // EXEC_CHECKER_PLUGIN_MANAGER_HH_
+++ /dev/null
-/*
- * Copyright (c) 2021 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 <dlfcn.h>
-#include <elf.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <unistd.h>
-#include <uuid/uuid.h>
-
-#include <fstream>
-#include <memory>
-#include <string>
-#include <utility>
-
-#include "exec_checker.hh"
-#include "exec_checker_private.hh"
-
-namespace plugin {
-namespace {
-
-union header {
- char c[4096];
- Elf32_Ehdr ehdr32;
- Elf64_Ehdr ehdr64;
-};
-
-template <typename Shdr>
-Shdr* GetSectionFromShdr(const char* name, Shdr* shdr,
- const char* shdr_names, int e_shnum) {
- for (int i = 0; i < e_shnum; ++i) {
- if (shdr[i].sh_size) {
- if (!strcmp(&shdr_names[shdr[i].sh_name], name))
- return &shdr[i];
- }
- }
-
- return nullptr;
-}
-
-int Read(FILE* fp, void* ptr, long offset, size_t size) {
- if (offset < 0 || size == 0) {
- LOGE_STD("Invalid parameter");
- return -1;
- }
-
- if (fseek(fp, offset, SEEK_SET) < 0) {
- LOGE_STD("fseek() is failed. errno(%d)", errno);
- return -1;
- }
-
- auto nbytes = fread(ptr, 1, size, fp);
- if (nbytes <= 0) {
- LOGE_STD("fread() is failed. error(%zd)", nbytes);
- return -1;
- }
-
- return 0;
-}
-
-char* GetDataFromFile(FILE* fp, unsigned long offset, size_t size) {
- if (size == 0) {
- LOGE_STD("Invalid parameter");
- return nullptr;
- }
-
- void* ptr = malloc(size);
- if (ptr == nullptr) {
- LOGE_STD("Out of memory");
- return nullptr;
- }
-
- if (Read(fp, ptr, static_cast<long>(offset & LONG_MAX), size) < 0) {
- free(ptr);
- return nullptr;
- }
-
- return static_cast<char*>(ptr);
-}
-
-template <typename Ehdr, typename Half, typename Shdr, typename Sym>
-bool FindMainSymbolFromEhdr(FILE* fp, Ehdr* ehdr) {
- rewind(fp);
- Half shdr_tab_size = ehdr->e_shentsize * ehdr->e_shnum;
- Shdr shdr_tab[shdr_tab_size];
- if (Read(fp, &shdr_tab, static_cast<long>(ehdr->e_shoff & LONG_MAX),
- shdr_tab_size) < 0)
- return false;
-
- if (ehdr->e_shstrndx >= shdr_tab_size)
- return false;
-
- char* shdr_names = GetDataFromFile(fp, shdr_tab[ehdr->e_shstrndx].sh_offset,
- shdr_tab[ehdr->e_shstrndx].sh_size);
- if (shdr_names == nullptr)
- return false;
-
- std::unique_ptr<char, decltype(std::free)*> shdr_names_auto(
- shdr_names, std::free);
-
- auto* shdr_strtab = GetSectionFromShdr<Shdr>(
- ".dynstr", shdr_tab, shdr_names, ehdr->e_shnum);
- if (shdr_strtab == nullptr)
- return false;
-
- auto* shdr_symtab = GetSectionFromShdr<Shdr>(
- ".dynsym", shdr_tab, shdr_names, ehdr->e_shnum);
- if (shdr_symtab == nullptr)
- return false;
-
- if (shdr_symtab->sh_type == SHT_DYNSYM) {
- auto* symtab = reinterpret_cast<Sym*>(GetDataFromFile(fp,
- shdr_symtab->sh_offset, shdr_symtab->sh_size));
- if (symtab == nullptr)
- return false;
-
- std::unique_ptr<Sym, decltype(std::free)*> symtab_auto(symtab, std::free);
-
- auto* strtab = GetDataFromFile(fp, shdr_strtab->sh_offset,
- shdr_strtab->sh_size);
- if (strtab == nullptr)
- return false;
-
- std::unique_ptr<char, decltype(std::free)*> strtab_auto(strtab, std::free);
-
- int size = shdr_symtab->sh_size / sizeof(Sym);
- for (int i = 0; i < size; ++i) {
- char* name = strtab + symtab[i].st_name;
- if (name && !strcmp(name, "main"))
- return true;
- }
- }
-
- return false;
-}
-
-} // namespace
-
-ExecChecker::ExecChecker(std::string path) : path_(std::move(path)) {
- int fd = open(path_.c_str(), O_RDONLY);
- if (fd < 0) {
- LOGE_STD("Failed to open file(%s). errno(%d)", path_.c_str(), errno);
- return;
- }
-
- header h;
- ssize_t nbyte = read(fd, h.c, sizeof(h));
- close(fd);
- if (nbyte < 2) {
- LOGE_STD("Failed to read file(%s). errno(%d)", path_.c_str(), errno);
- return;
- }
-
- if (nbyte < SELFMAG || memcmp(h.c, ELFMAG, SELFMAG) != 0) {
- LOGE_STD("This binary is not elf format(%s)", path_.c_str());
- return;
- }
-
- if (nbyte >= static_cast<int>(sizeof(Elf32_Ehdr)) &&
- h.c[EI_CLASS] == ELFCLASS32) {
- class_bit_ = 32;
- arch_bit_ = h.ehdr32.e_machine;
- type_ = h.ehdr32.e_type;
- } else if (nbyte >= static_cast<int>(sizeof(Elf64_Ehdr)) &&
- h.c[EI_CLASS] == ELFCLASS64) {
- class_bit_ = 64;
- arch_bit_ = h.ehdr64.e_machine;
- type_ = h.ehdr64.e_type;
- }
- LOGI_STD("%s class: %dbit, e_machine: %hu, e_type : %hu",
- path_.c_str(), class_bit_, arch_bit_, type_);
-}
-
-bool ExecChecker::IsShared() {
- return type_ == ET_DYN;
-}
-
-bool ExecChecker::CheckMainSymbol() {
- FILE* fp = fopen(path_.c_str(), "r");
- if (fp == nullptr) {
- LOGE_STD("fopen() is failed. errno(%d)", errno);
- return false;
- }
-
- std::unique_ptr<FILE, decltype(fclose)*> fp_auto(fp, fclose);
- header h;
- size_t nbytes = fread(h.c, 1, sizeof(h), fp);
- if (nbytes < 2) {
- LOGE_STD("fread() is failed");
- return false;
- }
-
- if (class_bit_ == 64) {
- return FindMainSymbolFromEhdr<Elf64_Ehdr, Elf64_Half, Elf64_Shdr, Elf64_Sym>(
- fp, &h.ehdr64);
- }
-
- return FindMainSymbolFromEhdr<Elf32_Ehdr, Elf32_Half, Elf32_Shdr, Elf32_Sym>(
- fp, &h.ehdr32);
-}
-
-bool ExecChecker::CheckDependencyLibs() {
- std::string root_path = path_.substr(0, path_.find_last_of('/') - 4);
- char uuid[37];
- uuid_t u;
- uuid_generate(u);
- uuid_unparse(u, uuid);
-
- std::string tmp = std::string("/tmp/") +
- path_.substr(path_.find_last_of('/') + 1) + "_" + uuid;
- std::string cmd = "LD_LIBRARY_PATH=" + root_path + "/lib /usr/bin/ldd " +
- path_ + " > " + tmp;
-
- if (tmp.size() > PATH_MAX)
- tmp = tmp.substr(0, PATH_MAX);
-
- bool pass = true;
- int ret = WEXITSTATUS(system(cmd.c_str()));
- if (ret != 0) {
- LOGE_STD("Failed to execute ldd %s, (%d)", cmd.c_str(), ret);
- return false;
- }
-
- std::ifstream f(tmp);
- char buf[1000];
- while (!f.eof()) {
- f.getline(buf, sizeof(buf));
-
- std::string line = buf;
- if (line.find("not found", 0) != line.npos) {
- LOGE_STD("Not found library (%s)",
- line.substr(0, line.find_first_of(' ', 0)).c_str());
- pass = false;
- break;
- }
- }
-
- f.close();
- remove(tmp.c_str());
- return pass;
-}
-
-bool ExecChecker::IsSameArch(const ExecChecker& exe) {
- return class_bit_ == exe.class_bit_ && arch_bit_ == exe.arch_bit_;
-}
-
-} // namespace plugin
+++ /dev/null
-/*
- * Copyright (c) 2021 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 <glib.h>
-#include <libxml/tree.h>
-
-#include "exec_checker_private.hh"
-#include "plugin_manager.hh"
-
-namespace {
-
-int Run(xmlDocPtr doc, const char* package) {
- if (doc == nullptr || package == nullptr) {
- LOGE_STD("Invalid parameter doc(%p) package(%p)", doc, package);
- return -1;
- }
- auto& manager = plugin::PluginManager::GetInst();
- manager.Init(doc, package);
- return manager.Process();
-}
-
-} // namespace
-
-extern "C" API int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr doc,
- const char* package) {
- return Run(doc, package);
-}
-
-extern "C" API int PKGMGR_PARSER_PLUGIN_UPGRADE(xmlDocPtr doc,
- const char* package) {
- return Run(doc, package);
-}
-
-extern "C" API int PKGMGR_PARSER_PLUGIN_RECOVERINSTALL(xmlDocPtr doc,
- const char* package) {
- return Run(doc, package);
-}
-
-extern "C" API int PKGMGR_PARSER_PLUGIN_RECOVERUPGRADE(xmlDocPtr doc,
- const char* package) {
- return Run(doc, package);
-}
+++ /dev/null
-/*
- * Copyright (c) 2021 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 <libxml/tree.h>
-#include <pkgmgr-info.h>
-#include <pkgmgr_installer_info.h>
-#include <unistd.h>
-
-#include <memory>
-#include <string>
-#include <utility>
-
-#include "exec_checker.hh"
-#include "exec_checker_private.hh"
-#include "plugin_manager.hh"
-
-namespace plugin {
-namespace {
-
-std::string GetAttribute(xmlNode* node, const char* key) {
- std::string ret;
- xmlChar* val = xmlGetProp(node, reinterpret_cast<const xmlChar*>(key));
- if (val != nullptr) {
- ret = reinterpret_cast<char*>(val);
- xmlFree(val);
- }
-
- return ret;
-}
-
-} // namespace
-
-PluginManager::PluginManager() {
- char path[1024];
- int nbyte = readlink("/proc/self/exe", path, sizeof(path) - 1);
- if (nbyte == -1) {
- LOGE_STD("Failed to get path. errno(%d)", errno);
- return;
- }
-
- path[nbyte] = '\0';
- self_ = std::unique_ptr<ExecChecker>(new (std::nothrow) ExecChecker(path));
- if (self_ == nullptr)
- LOGE_STD("Out of memory");
-}
-
-PluginManager& PluginManager::GetInst() {
- static PluginManager inst;
- return inst;
-}
-
-void PluginManager::Init(xmlDocPtr doc, std::string package) {
- package_ = std::move(package);
- doc_ = doc;
-}
-
-int PluginManager::Process() {
- xmlNode* root = xmlDocGetRootElement(doc_);
- if (root == nullptr) {
- LOGE_STD("Failed to get root element");
- return -1;
- }
- uid_t uid;
- int ret = pkgmgr_installer_info_get_target_uid(&uid);
- if (ret != PMINFO_R_OK) {
- LOGE_STD("Failed to get target uid. (%s)", package_.c_str());
- return -1;
- }
-
- for (xmlNode* node = root->children; node; node = node->next) {
- auto* apptype = reinterpret_cast<const char*>(node->name);
- if (apptype == nullptr)
- continue;
-
- std::string appid = GetAttribute(node, "appid");
- if (appid.empty()) {
- LOGE_STD("Failed to find appid. (%s)", appid.c_str());
- return -1;
- }
-
- pkgmgrinfo_appinfo_h app_info;
- ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid.c_str(), uid, &app_info);
- if (ret < 0) {
- LOGE_STD("Failed to get appinfo. (%s)", appid.c_str());
- return -1;
- }
- auto app_info_auto =
- std::unique_ptr<std::remove_pointer_t<pkgmgrinfo_appinfo_h>,
- decltype(pkgmgrinfo_appinfo_destroy_appinfo)*>(
- app_info, pkgmgrinfo_appinfo_destroy_appinfo);
-
- char* exec = nullptr;
- ret = pkgmgrinfo_appinfo_get_exec(app_info, &exec);
- if (ret < 0) {
- LOGE_STD("Failed to get app path. (%s)", package_.c_str());
- return -1;
- }
-
- std::string app_type = GetAttribute(node, "type");
- if (app_type != "capp" && app_type != "c++app")
- continue;
-
- LOGI_STD("Check binary: %s", exec);
- ExecChecker checker(exec);
-
- if (!self_->IsSameArch(checker))
- return -1;
-
- if (!checker.IsShared())
- LOGW("%s is not shared object", exec);
-
- if (!checker.CheckMainSymbol())
- LOGW_STD("Failed to find main symbol");
-
- if (!checker.CheckDependencyLibs())
- return -1;
- }
-
- return 0;
-}
-
-} // namespace plugin
+++ /dev/null
-ADD_SUBDIRECTORY(alias-appid)
-ADD_SUBDIRECTORY(allowed-appid)
+++ /dev/null
-SET(TARGET_ALIAS_APPID_PLUGIN "alias-appid-plugin")
-
-SET(SHARED_DIR "${CMAKE_INSTALL_PREFIX}/share")
-
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
-
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} ALIAS_APPID_PLUGIN_SRCS)
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../common COMMON_SRCS)
-
-ADD_LIBRARY(${TARGET_ALIAS_APPID_PLUGIN} SHARED
- ${ALIAS_APPID_PLUGIN_SRCS}
- ${COMMON_SRCS})
-
-TARGET_INCLUDE_DIRECTORIES(${TARGET_ALIAS_APPID_PLUGIN} PUBLIC
- "${CMAKE_CURRENT_SOURCE_DIR}/../")
-
-APPLY_PKG_CONFIG(${TARGET_ALIAS_APPID_PLUGIN} PUBLIC
- DLOG_DEPS
- GLIB_DEPS
- LIBTZPLATFORM_CONFIG_DEPS
- LIBXML_DEPS
- PKGMGR_INSTALLER_DEPS
- SQLITE3_DEPS
-)
-
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/alias-appid.info
- DESTINATION ${SHARED_DIR}/parser-plugins)
-INSTALL(TARGETS ${TARGET_ALIAS_APPID_PLUGIN}
- DESTINATION ${SYSCONF_INSTALL_DIR}/package-manager/parserlib/metadata)
+++ /dev/null
-/*
- * Copyright (c) 2020 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 ALIAS_APPID_ALIAS_INFO_HH_
-#define ALIAS_APPID_ALIAS_INFO_HH_
-
-#include <string>
-
-namespace plugin {
-
-class AliasInfo {
- public:
- AliasInfo(std::string alias_appid, std::string appid)
- : alias_appid_(std::move(alias_appid)), appid_(std::move(appid)) {
- }
-
- virtual ~AliasInfo() = default;
-
- const std::string& GetAliasAppId() const {
- return alias_appid_;
- }
-
- const std::string& GetAppId() const {
- return appid_;
- }
-
- private:
- std::string alias_appid_;
- std::string appid_;
-};
-
-} // namespace plugin
-
-#endif // ALIAS_APPID_ALIAS_INFO_HH_
+++ /dev/null
-/*
- * Copyright (c) 2020 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 <tzplatform_config.h>
-
-#include <memory>
-
-#include "alias-appid/appsvc_db.hh"
-#include "common/log_private.hh"
-
-namespace plugin {
-
-static const uid_t ROOT_UID = 0;
-static const uid_t GLOBAL_USER = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
-
-AppSvcDB::AppSvcDB(uid_t uid) : Database(GetDBPath(uid)) {
-}
-
-AppSvcDB::~AppSvcDB() = default;
-
-std::vector<std::shared_ptr<AliasInfo>> AppSvcDB::Select(
- const std::string& appid) {
- static const char query[] = "SELECT alias_appid FROM alias_info "
- "WHERE appid = ?;";
- sqlite3_stmt* stmt;
- __PREPARE_V2(GetHandle(), query, strlen(query), stmt);
- auto stmt_ptr = std::unique_ptr<sqlite3_stmt, decltype(sqlite3_finalize)*>(
- stmt, sqlite3_finalize);
- __BIND_TEXT(GetHandle(), stmt, 1, appid.c_str());
-
- std::vector<std::shared_ptr<AliasInfo>> infos;
- while (sqlite3_step(stmt) == SQLITE_ROW) {
- std::string alias_appid = ColumnText(stmt, 0);
- if (!alias_appid.empty())
- infos.emplace_back(new (std::nothrow) AliasInfo(alias_appid, appid));
- }
-
- return infos;
-}
-
-void AppSvcDB::Insert(const std::string& alias_appid,
- const std::string& appid) {
- static const char query[] = "INSERT OR REPLACE INTO "
- "alias_info(alias_appid, appid) VALUES(?, ?);";
- sqlite3_stmt* stmt;
- __PREPARE_V2(GetHandle(), query, strlen(query), stmt);
- std::unique_ptr<sqlite3_stmt, decltype(sqlite3_finalize)*> stmt_ptr(
- stmt, sqlite3_finalize);
- __BIND_TEXT(GetHandle(), stmt, 1, alias_appid.c_str());
- __BIND_TEXT(GetHandle(), stmt, 2, appid.c_str());
- __STEP(GetHandle(), stmt);
-}
-
-void AppSvcDB::Delete(const std::string& alias_appid,
- const std::string& appid) {
- static const char query[] = "DELETE FROM alias_info WHERE "
- "alias_appid = ? AND appid = ?;";
- sqlite3_stmt* stmt;
- __PREPARE_V2(GetHandle(), query, strlen(query), stmt);
- std::unique_ptr<sqlite3_stmt, decltype(sqlite3_finalize)*> stmt_ptr(
- stmt, sqlite3_finalize);
- __BIND_TEXT(GetHandle(), stmt, 1, alias_appid.c_str());
- __BIND_TEXT(GetHandle(), stmt, 2, appid.c_str());
- __STEP(GetHandle(), stmt);
-}
-
-void AppSvcDB::Delete(const std::string& appid) {
- static const char query[] = "DELETE FROM alias_info WHERE appid = ?;";
- sqlite3_stmt* stmt;
- __PREPARE_V2(GetHandle(), query, strlen(query), stmt);
- std::unique_ptr<sqlite3_stmt, decltype(sqlite3_finalize)*> stmt_ptr(
- stmt, sqlite3_finalize);
- __BIND_TEXT(GetHandle(), stmt, 1, appid.c_str());
- __STEP(GetHandle(), stmt);
-}
-
-std::string AppSvcDB::GetDBPath(uid_t uid) {
- std::string db_path;
- if (uid == ROOT_UID || uid == GLOBAL_USER) {
- db_path = std::string(tzplatform_getenv(TZ_SYS_DB)) + "/.appsvc.db";
- } else {
- db_path = std::string(tzplatform_getenv(TZ_SYS_DB)) + "/user/" +
- std::to_string(uid) + "/.appsvc.db";
- }
- return db_path;
-}
-
-} // namespace plugin
+++ /dev/null
-/*
- * Copyright (c) 2020 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 ALIAS_APPID_APPSVC_DB_HH_
-#define ALIAS_APPID_APPSVC_DB_HH_
-
-#include <unistd.h>
-
-#include <memory>
-#include <string>
-#include <vector>
-
-#include "alias-appid/alias_info.hh"
-#include "common/database.hh"
-
-namespace plugin {
-
-class AppSvcDB : public Database {
- public:
- explicit AppSvcDB(uid_t uid);
- virtual ~AppSvcDB();
-
- std::vector<std::shared_ptr<AliasInfo>> Select(const std::string& appid);
- void Insert(const std::string& alias_appid, const std::string& appid);
- void Delete(const std::string& alias_appid, const std::string& appid);
- void Delete(const std::string& appid);
-
- private:
- static std::string GetDBPath(uid_t uid);
-};
-
-} // namespace plugin
-
-#endif // ALIAS_APPID_APPSVC_DB_HH_
+++ /dev/null
-type="metadata";name="http://tizen.org/metadata/aliasappid";path="/etc/package-manager/parserlib/metadata/libalias-appid-plugin.so"
+++ /dev/null
-/*
- * Copyright (c) 2020 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 <glib.h>
-
-#include "common/log_private.hh"
-#include "alias-appid/plugin_manager.hh"
-
-#undef API
-#define API __attribute__ ((visibility("default")))
-
-using namespace plugin;
-
-extern "C" API int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char* pkgid,
- const char* appid, GList* list) {
- _W("[__ALIAS_APPID__] pkgid(%s), appid(%s)", pkgid, appid);
- PluginManager::GetInst().AddAppEventArgs(pkgid, appid,
- EventType::Install, list);
- PluginManager::GetInst().Do();
- return 0;
-}
-
-extern "C" API int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char* pkgid,
- const char* appid, GList* list) {
- _W("[__ALIAS_APPID__] pkgid(%s), appid(%s)", pkgid, appid);
- PluginManager::GetInst().AddAppEventArgs(pkgid, appid,
- EventType::Uninstall, list);
- PluginManager::GetInst().Do();
- return 0;
-}
-
-extern "C" API int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char* pkgid,
- const char* appid, GList* list) {
- _W("[__ALIAS_APPID__] pkgid(%s), appid(%s)", pkgid, appid);
- PluginManager::GetInst().AddAppEventArgs(pkgid, appid,
- EventType::Upgrade, list);
- PluginManager::GetInst().Do();
- return 0;
-}
-
-extern "C" API int PKGMGR_MDPARSER_PLUGIN_RECOVERINSTALL(const char* pkgid,
- const char* appid, GList* list) {
- _W("[__ALIAS_APPID__] pkgid(%s), appid(%s)", pkgid, appid);
- PluginManager::GetInst().AddAppEventArgs(pkgid, appid,
- EventType::Uninstall, list);
- PluginManager::GetInst().Do();
- return 0;
-}
-
-extern "C" API int PKGMGR_MDPARSER_PLUGIN_RECOVERUNINSTALL(const char* pkgid,
- const char* appid, GList* list) {
- _W("[__ALIAS_APPID__] pkgid(%s), appid(%s)", pkgid, appid);
- PluginManager::GetInst().AddAppEventArgs(pkgid, appid,
- EventType::Uninstall, list);
- PluginManager::GetInst().Do();
- return 0;
-}
-
-extern "C" API int PKGMGR_MDPARSER_PLUGIN_RECOVERUPGRADE(const char* pkgid,
- const char* appid, GList* list) {
- _W("[__ALIAS_APPID__] pkgid(%s), appid(%s)", pkgid, appid);
- PluginManager::GetInst().AddAppEventArgs(pkgid, appid,
- EventType::Upgrade, list);
- PluginManager::GetInst().Do();
- return 0;
-}
-
-extern "C" API int PKGMGR_MDPARSER_PLUGIN_CLEAN(const char* pkgid,
- const char* appid, GList* list) {
- _W("[__ALIAS_APPID__] pkgid(%s), appid(%s)", pkgid, appid);
- PluginManager::GetInst().Clean();
- return 0;
-}
-
-extern "C" API int PKGMGR_MDPARSER_PLUGIN_UNDO(const char* pkgid,
- const char* appid, GList* list) {
- _W("[__ALIAS_APPID__] pkgid(%s), appid(%s)", pkgid, appid);
- PluginManager::GetInst().Undo();
- return 0;
-}
-
-extern "C" API int PKGMGR_MDPARSER_PLUGIN_REMOVED(const char* pkgid,
- const char* appid, GList* list) {
- _W("[__ALIAS_APPID__] pkgid(%s), appid(%s)", pkgid, appid);
- return 0;
-}
+++ /dev/null
-/*
- * Copyright (c) 2020 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 "alias-appid/appsvc_db.hh"
-#include "alias-appid/plugin_manager.hh"
-#include "common/exception.hh"
-#include "common/log_private.hh"
-
-namespace plugin {
-
-PluginManager::PluginManager()
- : MetadataPlugin(std::unique_ptr<Database>(
- new AppSvcDB(MetadataPlugin::GetUid()))) {
-}
-
-PluginManager::~PluginManager() = default;
-
-PluginManager& PluginManager::GetInst() {
- static PluginManager inst;
- return inst;
-}
-
-bool PluginManager::StepBackup(const std::unique_ptr<AppEventArgs>& args) {
- auto* db = dynamic_cast<AppSvcDB*>(GetDB());
- if (db == nullptr) {
- _E("MetadataPlugin is not prepared");
- return false;
- }
-
- try {
- auto info_arr = db->Select(args->GetAppId());
- if (info_arr.size() != 0)
- infos_.insert(infos_.end(), info_arr.begin(), info_arr.end());
- } catch (Exception& e) {
- _E("Exception(%d) occurs", e.GetErrorCode());
- return false;
- }
-
- return true;
-}
-
-bool PluginManager::StepInstall(const std::unique_ptr<AppEventArgs>& args) {
- auto* db = dynamic_cast<AppSvcDB*>(GetDB());
- if (db == nullptr) {
- _E("MetadataPlugin is not prepared");
- return false;
- }
-
- for (auto& metadata : args->GetMetadataList()) {
- try {
- db->Insert(metadata->GetValue(), args->GetAppId());
- } catch (Exception& e) {
- return false;
- }
- }
- return true;
-}
-
-bool PluginManager::StepUninstall(const std::unique_ptr<AppEventArgs>& args) {
- auto* db = dynamic_cast<AppSvcDB*>(GetDB());
- if (db == nullptr) {
- _E("MetadataPlugin is not prepared");
- return false;
- }
-
- if (args->GetMetadataList().empty()) {
- try {
- db->Delete(args->GetAppId());
- } catch (Exception& e) {
- _W("Failed to delete alias info. appid(%s)", args->GetAppId().c_str());
- }
- return true;
- }
-
- for (auto& metadata : args->GetMetadataList()) {
- try {
- db->Delete(metadata->GetValue(), args->GetAppId());
- } catch (Exception& e) {
- return false;
- }
- }
- return true;
-}
-
-bool PluginManager::StepUpgrade(const std::unique_ptr<AppEventArgs>& args) {
- auto* db = dynamic_cast<AppSvcDB*>(GetDB());
- if (db == nullptr) {
- _E("MetadataPlugin is not prepared");
- return false;
- }
-
- try {
- db->Delete(args->GetAppId());
- } catch (Exception& e) {
- _W("Failed to delete alias info. appid(%s)", args->GetAppId().c_str());
- }
-
- return StepInstall(args);
-}
-
-bool PluginManager::StepRestore() {
- _E("Restore");
- auto* db = dynamic_cast<AppSvcDB*>(GetDB());
- if (db == nullptr) {
- _E("MetadataPlugin is not prepared");
- return false;
- }
-
- for (auto& info : infos_) {
- try {
- db->Insert(info->GetAliasAppId(), info->GetAppId());
- } catch (Exception& e) {
- _E("Exception(%d) occurs", e.GetErrorCode());
- return false;
- }
- }
-
- return true;
-}
-
-} // namespace plugin
+++ /dev/null
-/*
- * Copyright (c) 2020 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 ALIAS_APPID_PLUGIN_MANAGER_HH_
-#define ALIAS_APPID_PLUGIN_MANAGER_HH_
-
-#include <vector>
-
-#include "alias-appid/alias_info.hh"
-#include "common/metadata_plugin.hh"
-
-namespace plugin {
-
-class PluginManager : public MetadataPlugin {
- private:
- PluginManager();
- ~PluginManager();
-
- public:
- static PluginManager& GetInst();
-
- bool StepBackup(const std::unique_ptr<AppEventArgs>& args) override;
- bool StepInstall(const std::unique_ptr<AppEventArgs>& args) override;
- bool StepUninstall(const std::unique_ptr<AppEventArgs>& args) override;
- bool StepUpgrade(const std::unique_ptr<AppEventArgs>& args) override;
- bool StepRestore() override;
-
- private:
- std::vector<std::shared_ptr<AliasInfo>> infos_;
-};
-
-} // namespace plugin
-
-#endif // ALIAS_APPID_PLUGIN_MANAGER_HH_
+++ /dev/null
-SET(TARGET_ALLOWED_APPID_PLUGIN "allowed-appid-plugin")
-
-SET(SHARED_DIR "${CMAKE_INSTALL_PREFIX}/share")
-
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
-
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} ALLOWED_APPID_PLUGIN_SRCS)
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../common COMMON_SRCS)
-
-ADD_LIBRARY(${TARGET_ALLOWED_APPID_PLUGIN} SHARED
- ${ALLOWED_APPID_PLUGIN_SRCS}
- ${COMMON_SRCS})
-
-TARGET_INCLUDE_DIRECTORIES(${TARGET_ALLOWED_APPID_PLUGIN} PUBLIC
- "${CMAKE_CURRENT_SOURCE_DIR}/../")
-
-APPLY_PKG_CONFIG(${TARGET_ALLOWED_APPID_PLUGIN} PUBLIC
- DLOG_DEPS
- GLIB_DEPS
- LIBTZPLATFORM_CONFIG_DEPS
- LIBXML_DEPS
- PKGMGR_INSTALLER_DEPS
- SQLITE3_DEPS
-)
-
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/allowed-appid.info
- DESTINATION ${SHARED_DIR}/parser-plugins)
-INSTALL(TARGETS ${TARGET_ALLOWED_APPID_PLUGIN}
- DESTINATION ${SYSCONF_INSTALL_DIR}/package-manager/parserlib/metadata)
+++ /dev/null
-/*
- * Copyright (c) 2020 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 ALLOWED_APPID_ALLOWED_INFO_HH_
-#define ALLOWED_APPID_ALLOWED_INFO_HH_
-
-#include <memory>
-#include <string>
-
-namespace plugin {
-
-class AllowedInfo {
- public:
- AllowedInfo(std::string appid, std::string allowed_appid)
- : appid_(std::move(appid)), allowed_appid_(std::move(allowed_appid)) {
- }
-
- virtual ~AllowedInfo() = default;
-
- const std::string& GetAppId() const {
- return appid_;
- }
-
- const std::string& GetAllowedAppId() const {
- return allowed_appid_;
- }
-
- private:
- std::string appid_;
- std::string allowed_appid_;
-};
-
-} // namespace plugin
-
-#endif // ALLOWED_APPID_ALLOWED_INFO_HH_
+++ /dev/null
-/*
- * Copyright (c) 2020 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 <tzplatform_config.h>
-
-#include <memory>
-
-#include "allowed-appid/appsvc_db.hh"
-#include "common/log_private.hh"
-
-namespace plugin {
-
-static const uid_t ROOT_UID = 0;
-static const uid_t GLOBAL_USER = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
-
-AppSvcDB::AppSvcDB(uid_t uid) : Database(GetDBPath(uid)) {
-}
-
-AppSvcDB::~AppSvcDB() = default;
-
-std::vector<std::shared_ptr<AllowedInfo>> AppSvcDB::Select(
- const std::string& appid) {
- static const char query[] = "SELECT allowed_appid FROM "
- "allowed_info WHERE appid = ?;";
- sqlite3_stmt* stmt;
- __PREPARE_V2(GetHandle(), query, strlen(query), stmt);
- auto stmt_ptr = std::unique_ptr<sqlite3_stmt, decltype(sqlite3_finalize)*>(
- stmt, sqlite3_finalize);
- __BIND_TEXT(GetHandle(), stmt, 1, appid.c_str());
-
- std::vector<std::shared_ptr<AllowedInfo>> allowed_infos;
- while (sqlite3_step(stmt) == SQLITE_ROW) {
- std::string allowed_appid = ColumnText(stmt, 0);
- if (!allowed_appid.empty()) {
- allowed_infos.emplace_back(
- new (std::nothrow) AllowedInfo(appid, allowed_appid));
- }
- }
-
- return allowed_infos;
-}
-
-void AppSvcDB::Insert(const std::string& appid,
- const std::string& allowed_appid) {
- static const char query[] = "INSERT OR REPLACE INTO "
- "allowed_info(appid, allowed_appid) VALUES(?, ?);";
- sqlite3_stmt* stmt;
- __PREPARE_V2(GetHandle(), query, strlen(query), stmt);
- std::unique_ptr<sqlite3_stmt, decltype(sqlite3_finalize)*> stmt_ptr(
- stmt, sqlite3_finalize);
- __BIND_TEXT(GetHandle(), stmt, 1, appid.c_str());
- __BIND_TEXT(GetHandle(), stmt, 2, allowed_appid.c_str());
- __STEP(GetHandle(), stmt);
-}
-
-void AppSvcDB::Delete(const std::string& appid) {
- static const char query[] = "DELETE FROM allowed_info WHERE appid = ?;";
- sqlite3_stmt* stmt;
- __PREPARE_V2(GetHandle(), query, strlen(query), stmt);
- std::unique_ptr<sqlite3_stmt, decltype(sqlite3_finalize)*> stmt_ptr(
- stmt, sqlite3_finalize);
- __BIND_TEXT(GetHandle(), stmt, 1, appid.c_str());
- __STEP(GetHandle(), stmt);
-}
-
-std::string AppSvcDB::GetDBPath(uid_t uid) {
- std::string db_path;
- if (uid == ROOT_UID || uid == GLOBAL_USER) {
- db_path = std::string(tzplatform_getenv(TZ_SYS_DB)) + "/.appsvc.db";
- } else {
- db_path = std::string(tzplatform_getenv(TZ_SYS_DB)) + "/user/" +
- std::to_string(uid) + "/.appsvc.db";
- }
- return db_path;
-}
-
-} // namespace plugin
+++ /dev/null
-/*
- * Copyright (c) 2020 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 ALLOWED_APPID_APPSVC_DB_HH_
-#define ALLOWED_APPID_APPSVC_DB_HH_
-
-#include <unistd.h>
-
-#include <memory>
-#include <string>
-#include <vector>
-
-#include "allowed-appid/allowed_info.hh"
-#include "common/database.hh"
-
-namespace plugin {
-
-class AppSvcDB : public Database {
- public:
- explicit AppSvcDB(uid_t uid);
- virtual ~AppSvcDB();
-
- std::vector<std::shared_ptr<AllowedInfo>> Select(const std::string& appid);
- void Insert(const std::string& appid, const std::string& allowed_appid);
- void Delete(const std::string& appid);
-
- private:
- static std::string GetDBPath(uid_t uid);
-};
-
-} // namespace plugin
-
-#endif // ALLOWED_APPID_APPSVC_DB_HH_
+++ /dev/null
-type="metadata";name="http://tizen.org/metadata/allowedappid";path="/etc/package-manager/parserlib/metadata/liballowed-appid-plugin.so"
+++ /dev/null
-/*
- * Copyright (c) 2020 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 <glib.h>
-
-#include "allowed-appid/plugin_manager.hh"
-#include "common/log_private.hh"
-
-#undef API
-#define API __attribute__ ((visibility("default")))
-
-using namespace plugin;
-
-extern "C" API int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char* pkgid,
- const char* appid, GList* list) {
- _W("[__ALLOWED_APPID__] pkgid(%s), appid(%s)", pkgid, appid);
- PluginManager::GetInst().AddAppEventArgs(pkgid, appid,
- EventType::Install, list);
- PluginManager::GetInst().Do();
- return 0;
-}
-
-extern "C" API int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char* pkgid,
- const char* appid, GList* list) {
- _W("[__ALLOWED_APPID__] pkgid(%s), appid(%s)", pkgid, appid);
- PluginManager::GetInst().AddAppEventArgs(pkgid, appid,
- EventType::Uninstall, list);
- PluginManager::GetInst().Do();
- return 0;
-}
-
-extern "C" API int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char* pkgid,
- const char* appid, GList* list) {
- _W("[__ALLOWED_APPID__] pkgid(%s), appid(%s)", pkgid, appid);
- PluginManager::GetInst().AddAppEventArgs(pkgid, appid,
- EventType::Upgrade, list);
- PluginManager::GetInst().Do();
- return 0;
-}
-
-extern "C" API int PKGMGR_MDPARSER_PLUGIN_RECOVERINSTALL(const char* pkgid,
- const char* appid, GList* list) {
- _W("[__ALLOWED_APPID__] pkgid(%s), appid(%s)", pkgid, appid);
- PluginManager::GetInst().AddAppEventArgs(pkgid, appid,
- EventType::Uninstall, list);
- PluginManager::GetInst().Do();
- return 0;
-}
-
-extern "C" API int PKGMGR_MDPARSER_PLUGIN_RECOVERUNINSTALL(const char* pkgid,
- const char* appid, GList* list) {
- _W("[__ALLOWED_APPID__] pkgid(%s), appid(%s)", pkgid, appid);
- PluginManager::GetInst().AddAppEventArgs(pkgid, appid,
- EventType::Uninstall, list);
- PluginManager::GetInst().Do();
- return 0;
-}
-
-extern "C" API int PKGMGR_MDPARSER_PLUGIN_RECOVERUPGRADE(const char* pkgid,
- const char* appid, GList* list) {
- _W("[__ALLOWED_APPID__] pkgid(%s), appid(%s)", pkgid, appid);
- PluginManager::GetInst().AddAppEventArgs(pkgid, appid,
- EventType::Upgrade, list);
- PluginManager::GetInst().Do();
- return 0;
-}
-
-extern "C" API int PKGMGR_MDPARSER_PLUGIN_CLEAN(const char* pkgid,
- const char* appid, GList* list) {
- _W("[__ALLOWED_APPID__] pkgid(%s), appid(%s)", pkgid, appid);
- PluginManager::GetInst().Clean();
- return 0;
-}
-
-extern "C" API int PKGMGR_MDPARSER_PLUGIN_UNDO(const char* pkgid,
- const char* appid, GList* list) {
- _W("[__ALLOWED_APPID__] pkgid(%s), appid(%s)", pkgid, appid);
- PluginManager::GetInst().Undo();
- return 0;
-}
-
-extern "C" API int PKGMGR_MDPARSER_PLUGIN_REMOVED(const char* pkgid,
- const char* appid, GList* list) {
- _W("[__ALLOWED_APPID__] pkgid(%s), appid(%s)", pkgid, appid);
- return 0;
-}
+++ /dev/null
-/*
- * Copyright (c) 2020 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 "allowed-appid/appsvc_db.hh"
-#include "allowed-appid/plugin_manager.hh"
-#include "common/exception.hh"
-#include "common/log_private.hh"
-
-namespace plugin {
-
-PluginManager::PluginManager()
- : MetadataPlugin(std::unique_ptr<Database>(
- new AppSvcDB(MetadataPlugin::GetUid()))) {
-}
-
-PluginManager::~PluginManager() = default;
-
-PluginManager& PluginManager::GetInst() {
- static PluginManager inst;
- return inst;
-}
-
-bool PluginManager::StepBackup(const std::unique_ptr<AppEventArgs>& args) {
- auto* db = dynamic_cast<AppSvcDB*>(GetDB());
- if (db == nullptr) {
- _E("MetadataPlugin is not prepared");
- return false;
- }
-
- try {
- auto info_arr = db->Select(args->GetAppId());
- if (info_arr.size() != 0)
- infos_.insert(infos_.end(), info_arr.begin(), info_arr.end());
- } catch (Exception& e) {
- _E("Execption(%d) occurs", e.GetErrorCode());
- return false;
- }
-
- return true;
-}
-
-std::vector<std::string> PluginManager::Split(const std::string& str,
- const std::string& delim) {
- std::string string(str);
- std::vector<std::string> result;
- std::size_t pos;
- while ((pos = string.find(delim)) != std::string::npos) {
- std::string token = string.substr(0, pos);
- result.push_back(token);
- string.erase(0, pos + delim.length());
- }
- result.push_back(string);
- return result;
-}
-
-bool PluginManager::StepInstall(const std::unique_ptr<AppEventArgs>& args) {
- auto* db = dynamic_cast<AppSvcDB*>(GetDB());
- if (db == nullptr) {
- _E("MetadataPlugin is not prepared");
- return false;
- }
-
- for (auto& metadata : args->GetMetadataList()) {
- for (auto& app_id : Split(metadata->GetValue(), "|")) {
- try {
- db->Insert(args->GetAppId(), app_id);
- } catch (Exception& e) {
- return false;
- }
- }
- }
- return true;
-}
-
-bool PluginManager::StepUninstall(const std::unique_ptr<AppEventArgs>& args) {
- auto* db = dynamic_cast<AppSvcDB*>(GetDB());
- if (db == nullptr) {
- _E("MetadataPlugin is not prepared");
- return false;
- }
-
- try {
- db->Delete(args->GetAppId());
- } catch (Exception& e) {
- _W("Failed to delete alias info. appid(%s)", args->GetAppId().c_str());
- }
- return true;
-}
-
-bool PluginManager::StepUpgrade(const std::unique_ptr<AppEventArgs>& args) {
- if (!StepUninstall(args))
- return false;
-
- return StepInstall(args);
-}
-
-bool PluginManager::StepRestore() {
- _E("Restore");
- auto* db = dynamic_cast<AppSvcDB*>(GetDB());
- if (db == nullptr) {
- _E("MetadataPlugin is not prepared");
- return false;
- }
-
- for (auto& info : infos_) {
- try {
- db->Insert(info->GetAppId(), info->GetAllowedAppId());
- } catch (Exception& e) {
- _E("Exception(%d) occurs", e.GetErrorCode());
- return false;
- }
- }
-
- return true;
-}
-
-} // namespace plugin
+++ /dev/null
-/*
- * Copyright (c) 2020 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 ALLOWED_APPID_PLUGIN_MANAGER_HH_
-#define ALLOWED_APPID_PLUGIN_MANAGER_HH_
-
-#include <vector>
-
-#include "common/metadata_plugin.hh"
-#include "allowed-appid/allowed_info.hh"
-
-namespace plugin {
-
-class PluginManager : public MetadataPlugin {
- private:
- PluginManager();
- ~PluginManager();
-
- public:
- static PluginManager& GetInst();
-
- bool StepBackup(const std::unique_ptr<AppEventArgs>& args) override;
- bool StepInstall(const std::unique_ptr<AppEventArgs>& args) override;
- bool StepUninstall(const std::unique_ptr<AppEventArgs>& args) override;
- bool StepUpgrade(const std::unique_ptr<AppEventArgs>& args) override;
- bool StepRestore() override;
-
- private:
- std::vector<std::string> Split(const std::string& str,
- const std::string& delim);
-
- private:
- std::vector<std::shared_ptr<AllowedInfo>> infos_;
-};
-
-} // namespace plugin
-
-#endif // ALLOWED_APPID_PLUGIN_MANAGER_HH_
+++ /dev/null
-/*
- * Copyright (c) 2020 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 COMMON_APP_EVENT_ARGS_HH_
-#define COMMON_APP_EVENT_ARGS_HH_
-
-#include <list>
-#include <memory>
-#include <string>
-
-#include "common/event_type.hh"
-#include "common/metadata.hh"
-
-namespace plugin {
-
-class AppEventArgs {
- public:
- AppEventArgs(std::string appid, std::string pkgid, EventType event_type)
- : appid_(std::move(appid)),
- pkgid_(std::move(pkgid)),
- event_type_(event_type) {
- }
-
- virtual ~AppEventArgs() = default;
-
- const std::string& GetAppId() {
- return appid_;
- }
-
- const std::string& GetPkgId() {
- return pkgid_;
- }
-
- EventType GetEventType() const {
- return event_type_;
- }
-
- const std::list<std::unique_ptr<Metadata>>& GetMetadataList() {
- return list_;
- }
-
- void AddMetadata(std::unique_ptr<Metadata> metadata) {
- list_.push_back(std::move(metadata));
- }
-
- private:
- std::string appid_;
- std::string pkgid_;
- EventType event_type_;
- std::list<std::unique_ptr<Metadata>> list_;
-};
-
-} // namespace plugin
-
-#endif // COMMON_APP_EVENT_ARGS_HH_
+++ /dev/null
-/*
- * Copyright (c) 2020 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 <unistd.h>
-
-#include <memory>
-
-#include "common/database.hh"
-#include "common/exception.hh"
-#include "common/log_private.hh"
-
-namespace plugin {
-
-static const int BUSY_WAITING_USEC = 50000;
-static const int BUSY_WAITING_MAX = 40;
-
-Database::Database(std::string path) : path_(std::move(path)) {
-}
-
-Database::~Database() {
- Close();
-}
-
-void Database::BeginTransaction() {
- int ret = sqlite3_exec(db_, "BEGIN TRANSACTION", nullptr, nullptr, nullptr);
- if (ret != SQLITE_OK) {
- _E("sqlite3_exec() is failed. error(%s:%d)", sqlite3_errmsg(db_), ret);
- THROW(-ret);
- }
-}
-
-void Database::EndTransaction() {
- int ret = sqlite3_exec(db_, "END TRANSACTION", nullptr, nullptr, nullptr);
- if (ret != SQLITE_OK) {
- _E("sqlite3_exec() is failed. error(%s:%d)", sqlite3_errmsg(db_), ret);
- THROW(-ret);
- }
-}
-
-void Database::Rollback() {
- int ret = sqlite3_exec(db_, "ROLLBACK", nullptr, nullptr, nullptr);
- if (ret != SQLITE_OK) {
- _E("sqlite3_exec() is failed. error(%s:%d", sqlite3_errmsg(db_), ret);
- THROW(-ret);
- }
-}
-
-void Database::Open() {
- sqlite3* db;
- int ret = sqlite3_open_v2(path_.c_str(), &db, SQLITE_OPEN_READWRITE, nullptr);
- if (ret != SQLITE_OK) {
- _E("sqlite3_open_v2() is failed. error(%d)", ret);
- THROW(-ret);
- }
-
- ret = sqlite3_busy_handler(db, BusyHandler,
- static_cast<void*>(const_cast<char*>(path_.c_str())));
- if (ret != SQLITE_OK) {
- _E("sqlite3_busy_handler() is failed. error(%s:%d)",
- sqlite3_errmsg(db), ret);
- sqlite3_close_v2(db);
- THROW(-ret);
- }
-
- ret = sqlite3_exec(db, "PRAGMA foreign_keys=ON", nullptr, nullptr, nullptr);
- if (ret != SQLITE_OK) {
- _E("sqlite3_exec() is failed. error(%s:%d)", sqlite3_errmsg(db), ret);
- sqlite3_close_v2(db);
- THROW(-ret);
- }
-
- db_ = db;
-}
-
-void Database::Close() {
- if (db_) {
- sqlite3_close_v2(db_);
- db_ = nullptr;
- }
-}
-
-sqlite3* Database::GetHandle() {
- return db_;
-}
-
-std::string Database::ColumnText(sqlite3_stmt* stmt, int index) {
- auto* text = reinterpret_cast<const char*>(sqlite3_column_text(stmt, index));
- if (text)
- return std::string(text);
-
- return {};
-}
-
-bool Database::IntegrityCheck() {
- static const char query[] = "PRAGMA integrity_check";
- sqlite3_stmt* stmt;
- int ret = sqlite3_prepare_v2(db_, query, strlen(query), &stmt, nullptr);
- if (ret != SQLITE_OK) {
- _E("sqlite3_prepare_v2() is failed. error(%s:%d)",
- sqlite3_errmsg(db_), ret);
- return false;
- }
-
- std::unique_ptr<sqlite3_stmt, decltype(sqlite3_finalize)*> stmt_ptr(
- stmt, sqlite3_finalize);
-
- ret = sqlite3_step(stmt);
- if (ret != SQLITE_ROW) {
- _E("sqlite3_step() is failed. error(%s:%d)", sqlite3_errmsg(db_), ret);
- return false;
- }
-
- auto* res = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0));
- if (res == nullptr) {
- _E("sqlite3_column_text() is failed. error(%s)", sqlite3_errmsg(db_));
- return false;
- }
-
- if (strcmp(res, "ok") != 0)
- return false;
-
- return true;
-}
-
-int Database::BusyHandler(void* data, int count) {
- if (count < BUSY_WAITING_MAX) {
- usleep(BUSY_WAITING_USEC);
- return 1;
- }
- auto* path = static_cast<char*>(data);
- _E("Database(%s) is busy", path);
- return 0;
-}
-
-} // namespace plugin
+++ /dev/null
-/*
- * Copyright (c) 2020 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 COMMON_DATABASE_HH_
-#define COMMON_DATABASE_HH_
-
-#include <sqlite3.h>
-
-#include <string>
-
-#include "common/exception.hh"
-
-#define __PREPARE_V2(db, query, length, stmt) do { \
- int ret = sqlite3_prepare_v2(db, query, length, &stmt, nullptr); \
- if (ret != SQLITE_OK) { \
- _E("sqlite3_prepare_v2() is failed. error(%s:%d)", \
- sqlite3_errmsg(db), ret); \
- THROW(-ret); \
- } \
-} while (0)
-
-
-#define __BIND_TEXT(db, stmt, i, text) do { \
- int ret = sqlite3_bind_text(stmt, i, text, -1, SQLITE_TRANSIENT); \
- if (ret != SQLITE_OK) { \
- _E("sqlite3_bind_text() is failed. index(%d), error(%s:%d)", \
- i, sqlite3_errmsg(db), ret); \
- THROW(-ret); \
- } \
-} while (0)
-
-#define __STEP(db, stmt) do { \
- int ret = sqlite3_step(stmt); \
- if (ret != SQLITE_DONE) { \
- _E("sqlite3_step() is failed. error(%s:%d)", sqlite3_errmsg(db), ret); \
- THROW(-ret); \
- } \
-} while (0)
-
-namespace plugin {
-
-class Database {
- public:
- explicit Database(std::string path);
- virtual ~Database();
-
- void Open();
- void Close();
- bool IntegrityCheck();
- void BeginTransaction();
- void EndTransaction();
- void Rollback();
- sqlite3* GetHandle();
- std::string ColumnText(sqlite3_stmt* stmt, int index);
-
- private:
- static int BusyHandler(void* data, int count);
-
- private:
- std::string path_;
- sqlite3* db_ = nullptr;
-};
-
-} // namespace plugin
-
-#endif // COMMON_DATABASE_HH_
+++ /dev/null
-/*
- * Copyright (c) 2020 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 COMMON_EVENT_TYPE_HH_
-#define COMMON_EVENT_TYPE_HH_
-
-namespace plugin {
-
-enum class EventType {
- Install,
- Uninstall,
- Upgrade,
-};
-
-} // namespace plugin
-
-#endif // COMMON_EVENT_TYPE_HH_
+++ /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 COMMON_EXCEPTION_HH_
-#define COMMON_EXCEPTION_HH_
-
-#include <libgen.h>
-
-#include <exception>
-#include <string>
-
-#include "common/log_private.hh"
-
-#define THROW(error_code) throw Exception(error_code, __FILE__, __LINE__)
-
-namespace plugin {
-
-class Exception : public std::exception {
- public:
- explicit Exception(int error_code, std::string file = __FILE__,
- int line = __LINE__ ) {
- error_code_ = error_code;
- message_ = std::string(basename(const_cast<char*>(file.c_str()))) + ":" +
- std::to_string(line) + " code:" + std::to_string(error_code_);
- _E("%s", message_.c_str());
- }
-
- virtual ~Exception() {}
-
- virtual const char* what(void) const noexcept {
- return message_.c_str();
- }
-
- int GetErrorCode() {
- return error_code_;
- }
-
- private:
- int error_code_;
- std::string message_;
-};
-
-} // namespace plugin
-
-#endif // COMMON_EXCEPTION_HH_
+++ /dev/null
-/*
- * Copyright (c) 2020 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 COMMON_LOG_PRIVATE_HH_
-#define COMMON_LOG_PRIVATE_HH_
-
-#include <dlog.h>
-
-#undef LOG_TAG
-#define LOG_TAG "METADATA_PLUGIN_PARSER"
-
-#undef _E
-#define _E LOGE
-
-#undef _W
-#define _W LOGW
-
-#undef _I
-#define _I LOGI
-
-#undef _D
-#define _D LOGD
-
-#endif // COMMON_LOG_PRIVATE_HH_
+++ /dev/null
-/*
- * Copyright (c) 2020 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 COMMON_METADATA_HH_
-#define COMMON_METADATA_HH_
-
-#include <string>
-
-namespace plugin {
-
-class Metadata {
- public:
- Metadata(std::string key, std::string value)
- : key_(std::move(key)), value_(std::move(value)) {
- }
-
- virtual ~Metadata() = default;
-
- const std::string& GetKey() {
- return key_;
- }
-
- const std::string& GetValue() {
- return value_;
- }
-
- private:
- std::string key_;
- std::string value_;
-};
-
-} // namespace plugin
-
-#endif // COMMON_METADATA_HH_
+++ /dev/null
-/*
- * Copyright (c) 2020 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 <unistd.h>
-#include <pkgmgr_installer_info.h>
-
-#include "common/database.hh"
-#include "common/exception.hh"
-#include "common/log_private.hh"
-#include "common/metadata_plugin.hh"
-#include "common/metadata_type.hh"
-
-namespace plugin {
-
-void MetadataPlugin::AddAppEventArgs(const std::string& pkgid,
- const std::string& appid, EventType event_type, GList* list) {
- auto args = new (std::nothrow) AppEventArgs(appid, pkgid, event_type);
- if (args == nullptr) {
- _E("Out of memory");
- return;
- }
-
- GList* iter = list;
- while (iter) {
- metadata_t* md = static_cast<metadata_t*>(iter->data);
- args->AddMetadata(std::unique_ptr<Metadata>(
- new (std::nothrow) Metadata(md->key, md->value)));
- iter = g_list_next(iter);
- }
-
- list_.emplace_back(args);
-}
-
-void MetadataPlugin::Do() {
- _W("Do");
- if (!Prepare())
- return;
-
- for (auto& args : list_) {
- bool ret = StepBackup(args);
- if (!ret) {
- Post();
- return;
- }
- }
-
- for (auto& args : list_) {
- bool ret = true;
- if (args->GetEventType() == EventType::Install) {
- ret = StepInstall(args);
- } else if (args->GetEventType() == EventType::Uninstall) {
- ret = StepUninstall(args);
- } else if (args->GetEventType() == EventType::Upgrade) {
- ret = StepUpgrade(args);
- }
-
- if (!ret) {
- Rollback();
- return;
- }
- }
- Post();
-}
-
-void MetadataPlugin::Clean() {
- _W("Clean");
-}
-
-Database* MetadataPlugin::GetDB() {
- return db_.get();
-}
-
-uid_t MetadataPlugin::GetUid() {
- uid_t target_uid;
- pkgmgr_installer_info_get_target_uid(&target_uid);
- return target_uid;
-}
-
-bool MetadataPlugin::Prepare() {
- try {
- db_->Open();
- if (!db_->IntegrityCheck())
- return false;
- db_->BeginTransaction();
- } catch (Exception& e) {
- return false;
- }
- return true;
-}
-
-bool MetadataPlugin::StepBackup(const std::unique_ptr<AppEventArgs>& args) {
- return true;
-}
-
-bool MetadataPlugin::StepInstall(const std::unique_ptr<AppEventArgs>& args) {
- return true;
-}
-
-bool MetadataPlugin::StepUninstall(const std::unique_ptr<AppEventArgs>& args) {
- return true;
-}
-
-bool MetadataPlugin::StepUpgrade(const std::unique_ptr<AppEventArgs>& args) {
- return true;
-}
-
-bool MetadataPlugin::StepRestore() {
- return true;
-}
-
-void MetadataPlugin::Post() {
- try {
- db_->EndTransaction();
- db_->Close();
- } catch (Exception& e) {
- _E("Exception(%d) occurs", e.GetErrorCode());
- }
-}
-
-void MetadataPlugin::Rollback() {
- try {
- db_->Rollback();
- } catch (Exception& e) {
- _E("Exception(%d) occurs", e.GetErrorCode());
- }
-}
-
-void MetadataPlugin::Undo() {
- _E("Undo");
- if (!Prepare())
- return;
-
- for (auto& args : list_) {
- if (!StepUninstall(args))
- _E("StepUninstall() is failed");
- }
-
- if (!StepRestore())
- _E("StepRestore() is failed");
-
- Post();
-}
-
-} // namespace plugin
+++ /dev/null
-/*
- * Copyright (c) 2020 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 COMMON_METADATA_PLUGIN_HH_
-#define COMMON_METADATA_PLUGIN_HH_
-
-#include <glib.h>
-#include <unistd.h>
-
-#include <list>
-#include <memory>
-#include <string>
-
-#include "common/app_event_args.hh"
-#include "common/database.hh"
-
-namespace plugin {
-
-class MetadataPlugin {
- public:
- explicit MetadataPlugin(std::unique_ptr<Database> db) : db_(std::move(db)) { }
- virtual ~MetadataPlugin() = default;
-
- void AddAppEventArgs(const std::string& pkgid, const std::string& appid,
- EventType event_type, GList* list);
- Database* GetDB();
-
- void Do();
- void Clean();
- void Undo();
-
- virtual bool Prepare();
- virtual bool StepBackup(const std::unique_ptr<AppEventArgs>& args);
- virtual bool StepInstall(const std::unique_ptr<AppEventArgs>& args);
- virtual bool StepUninstall(const std::unique_ptr<AppEventArgs>& args);
- virtual bool StepUpgrade(const std::unique_ptr<AppEventArgs>& args);
- virtual bool StepRestore();
- virtual void Post();
- virtual void Rollback();
-
- static uid_t GetUid();
-
- public:
- std::unique_ptr<Database> db_;
- std::list<std::unique_ptr<AppEventArgs>> list_;
-};
-
-} // namespace plugin
-
-#endif // COMMON_METADATA_PLUGIN_HH_
+++ /dev/null
-/*
- * Copyright (c) 2020 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 COMMON_METADATA_TYPE_HH_
-#define COMMON_METADATA_TYPE_HH_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct metadata_s {
- const char* key;
- const char* value;
-} metadata_t;
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // COMMON_METADATA_TYPE_HH_
+++ /dev/null
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} AUL_SERVER_SRCS)
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/api AUL_SERVER_API_SRCS)
-
-ADD_LIBRARY(${TARGET_AUL_SERVER} SHARED
- ${AUL_SERVER_SRCS}
- ${AUL_SERVER_API_SRCS}
-)
-
-TARGET_INCLUDE_DIRECTORIES(${TARGET_AUL_SERVER} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}
- ${CMAKE_CURRENT_SOURCE_DIR}/../
- ${CMAKE_CURRENT_SOURCE_DIR}/api
-)
-
-SET_TARGET_PROPERTIES(${TARGET_AUL_SERVER} PROPERTIES SOVERSION ${MAJORVER})
-SET_TARGET_PROPERTIES(${TARGET_AUL_SERVER} PROPERTIES VERSION ${FULLVER})
-
-APPLY_PKG_CONFIG(${TARGET_AUL_SERVER} PUBLIC
- SQLITE3_DEPS
- DLOG_DEPS
-)
-
-CONFIGURE_FILE(${TARGET_AUL_SERVER}.pc.in ${TARGET_AUL_SERVER}.pc @ONLY)
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_AUL_SERVER}.pc
- DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
-
-INSTALL(TARGETS ${TARGET_AUL_SERVER} DESTINATION ${LIB_INSTALL_DIR}
- COMPONENT RuntimeLibraries)
-
-INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/api/
- DESTINATION include/aul/server
- FILES_MATCHING
- PATTERN "*.h"
-)
+++ /dev/null
-/*
- * Copyright (c) 2022 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 "server/api/aul_boot_sequence.h"
-
-#include <memory>
-#include <string>
-#include <tuple>
-#include <utility>
-#include <vector>
-
-#include "server/boot_sequence.hh"
-#include "server/common_private.hh"
-#include "server/database.hh"
-#include "server/log_private.hh"
-
-using namespace aul;
-
-namespace {
-
-constexpr const char APPSVC_DB[] = ".appsvc.db";
-constexpr const char QUERY_SELECT_FROM_BOOT_SEQUENCE[] =
- "SELECT appid, after, before, requires, conflicts, vconf, path_exists, "
- "args, background_launch, wait_until_ready, timeout FROM boot_sequence";
-
-using SelectBootSequenceCb =
- int (*)(sqlite3*, sqlite3_stmt*,
- std::tuple<std::vector<std::shared_ptr<BootSequence>>&>);
-
-template <typename T, typename ...ARGS>
-int Step(T cb, std::tuple<ARGS...> args,
- bool readonly, const std::string& query, uid_t uid) {
- std::string path = Database::GetPath(APPSVC_DB, uid);
- Database db(path, false);
- try {
- db.Open(readonly ? SQLITE_OPEN_READONLY : SQLITE_OPEN_READWRITE);
- } catch (Exception& e) {
- return AUL_ERROR_IO_ERROR;
- }
-
- sqlite3_stmt* stmt;
- __PREPARE_V2(db.GetHandle(), query.c_str(), query.length(), stmt);
- auto stmt_ptr = std::unique_ptr<sqlite3_stmt, decltype(sqlite3_finalize)*>(
- stmt, sqlite3_finalize);
-
- int ret;
- if (readonly) {
- ret = cb(db.GetHandle(), stmt, args);
- } else {
- db.BeginTransaction();
- ret = cb(db.GetHandle(), stmt, args);
- if (ret < 0)
- db.Rollback();
- else
- db.EndTransaction();
- }
-
- return ret;
-}
-
-int GetBootSequence(uid_t uid,
- std::vector<std::shared_ptr<BootSequence>>& infos) {
- std::string query(QUERY_SELECT_FROM_BOOT_SEQUENCE);
- std::tuple<std::vector<std::shared_ptr<BootSequence>>&> param(infos);
- int ret = Step<SelectBootSequenceCb,
- std::vector<std::shared_ptr<BootSequence>>&>(
- [](sqlite3* db, sqlite3_stmt* stmt,
- std::tuple<std::vector<std::shared_ptr<BootSequence>>&> args)
- -> int {
- auto& infos = std::get<0>(args);
- int idx;
- while (sqlite3_step(stmt) == SQLITE_ROW) {
- idx = 0;
- std::string appid = Database::ColumnText(stmt, idx++);
- auto info = std::make_shared<BootSequence>(std::move(appid));
- info->SetAfter(Database::ColumnText(stmt, idx++));
- info->SetBefore(Database::ColumnText(stmt, idx++));
- info->SetRequires(Database::ColumnText(stmt, idx++));
- info->SetConflicts(Database::ColumnText(stmt, idx++));
- info->SetVconf(Database::ColumnText(stmt, idx++));
- info->SetPathExists(Database::ColumnText(stmt, idx++));
- info->SetArgs(Database::ColumnText(stmt, idx++));
- info->SetBackgroundLaunch(Database::ColumnText(stmt, idx++));
- info->SetWaitUntilReady(Database::ColumnText(stmt, idx++));
- info->SetTimeout(Database::ColumnText(stmt, idx++));
- infos.push_back(std::move(info));
- }
-
- return AUL_ERROR_NONE;
- }, param, false, query, uid);
- if (ret != AUL_ERROR_NONE)
- return AUL_ERROR_IO_ERROR;
-
- return AUL_ERROR_NONE;
-}
-
-} // namespace
-
-extern "C" API int aul_boot_sequence_foreach_usr(uid_t uid,
- aul_boot_sequence_cb callback, void* user_data) {
- if (callback == nullptr) {
- _E("Invalid parameter");
- return AUL_ERROR_INVALID_PARAMETER;
- }
-
- if (uid < REGULAR_UID_MIN)
- uid = GLOBALAPP_UID;
-
- std::vector<std::shared_ptr<BootSequence>> infos;
- int ret = GetBootSequence(uid, infos);
- if (ret == AUL_ERROR_NONE && uid != GLOBALAPP_UID)
- ret = GetBootSequence(GLOBALAPP_UID, infos);
-
- if (ret != AUL_ERROR_NONE) {
- _E("Failed to get boot sequence. error(%d)", ret);
- return ret;
- }
-
- for (auto& info : infos) {
- if (!callback(info.get(), uid, user_data))
- break;
- }
-
- return AUL_ERROR_NONE;
-}
-
-extern "C" API int aul_boot_sequence_get_appid(aul_boot_sequence_h handle,
- const char** appid) {
- if (handle == nullptr || appid == nullptr) {
- _E("Invalid parameter");
- return AUL_ERROR_INVALID_PARAMETER;
- }
-
- auto* h = static_cast<BootSequence*>(handle);
- *appid = h->GetAppId().c_str();
- return AUL_ERROR_NONE;
-}
-
-extern "C" API int aul_boot_sequence_get_after(aul_boot_sequence_h handle,
- const char** after) {
- if (handle == nullptr || after == nullptr) {
- _E("Invalid parameter");
- return AUL_ERROR_INVALID_PARAMETER;
- }
-
- auto* h = static_cast<BootSequence*>(handle);
- *after = h->GetAfter().c_str();
- return AUL_ERROR_NONE;
-}
-
-extern "C" API int aul_boot_sequence_get_before(aul_boot_sequence_h handle,
- const char** before) {
- if (handle == nullptr || before == nullptr) {
- _E("Invalid parameter");
- return AUL_ERROR_INVALID_PARAMETER;
- }
-
- auto* h = static_cast<BootSequence*>(handle);
- *before = h->GetBefore().c_str();
- return AUL_ERROR_NONE;
-}
-
-extern "C" API int aul_boot_sequence_get_requires(aul_boot_sequence_h handle,
- const char** requires_dep) {
- if (handle == nullptr || requires_dep == nullptr) {
- _E("Invalid parameter");
- return AUL_ERROR_INVALID_PARAMETER;
- }
-
- auto* h = static_cast<BootSequence*>(handle);
- *requires_dep = h->GetRequires().c_str();
- return AUL_ERROR_NONE;
-}
-
-extern "C" API int aul_boot_sequence_get_conflicts(aul_boot_sequence_h handle,
- const char** conflicts) {
- if (handle == nullptr || conflicts == nullptr) {
- _E("Invalid parameter");
- return AUL_ERROR_INVALID_PARAMETER;
- }
-
- auto* h = static_cast<BootSequence*>(handle);
- *conflicts = h->GetConflicts().c_str();
- return AUL_ERROR_NONE;
-}
-
-extern "C" API int aul_boot_sequence_get_vconf(aul_boot_sequence_h handle,
- const char** vconf) {
- if (handle == nullptr || vconf == nullptr) {
- _E("Invalid parameter");
- return AUL_ERROR_INVALID_PARAMETER;
- }
-
- auto* h = static_cast<BootSequence*>(handle);
- *vconf = h->GetVconf().c_str();
- return AUL_ERROR_NONE;
-}
-
-extern "C" API int aul_boot_sequence_get_path_exists(aul_boot_sequence_h handle,
- const char** path_exists) {
- if (handle == nullptr || path_exists == nullptr) {
- _E("Invalid parameter");
- return AUL_ERROR_INVALID_PARAMETER;
- }
-
- auto* h = static_cast<BootSequence*>(handle);
- *path_exists = h->GetPathExists().c_str();
- return AUL_ERROR_NONE;
-}
-
-extern "C" API int aul_boot_sequence_get_args(aul_boot_sequence_h handle,
- const char** args) {
- if (handle == nullptr || args == nullptr) {
- _E("Invalid parameter");
- return AUL_ERROR_INVALID_PARAMETER;
- }
-
- auto* h = static_cast<BootSequence*>(handle);
- *args = h->GetArgs().c_str();
- return AUL_ERROR_NONE;
-}
-
-extern "C" API int aul_boot_sequence_get_background_launch(
- aul_boot_sequence_h handle, const char** background_launch) {
- if (handle == nullptr || background_launch == nullptr) {
- _E("Invalid parameter");
- return AUL_ERROR_INVALID_PARAMETER;
- }
-
- auto* h = static_cast<BootSequence*>(handle);
- *background_launch = h->GetBackgroundLaunch().c_str();
- return AUL_ERROR_NONE;
-}
-
-extern "C" API int aul_boot_sequence_get_wait_until_ready(
- aul_boot_sequence_h handle, const char** wait_until_ready) {
- if (handle == nullptr || wait_until_ready == nullptr) {
- _E("Invalid parameter");
- return AUL_ERROR_INVALID_PARAMETER;
- }
-
- auto* h = static_cast<BootSequence*>(handle);
- *wait_until_ready = h->GetWaitUntilReady().c_str();
- return AUL_ERROR_NONE;
-}
-
-extern "C" API int aul_boot_sequence_get_timeout(aul_boot_sequence_h handle,
- const char** timeout) {
- if (handle == nullptr || timeout == nullptr) {
- _E("Invalid parameter");
- return AUL_ERROR_INVALID_PARAMETER;
- }
-
- auto* h = static_cast<BootSequence*>(handle);
- *timeout = h->GetTimeout().c_str();
- return AUL_ERROR_NONE;
-}
+++ /dev/null
-/*
- * Copyright (c) 2022 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_BOOT_SEQUENCE_H__
-#define __AUL_BOOT_SEQUENCE_H__
-
-#include <stdbool.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include <aul_types.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef void *aul_boot_sequence_h;
-
-typedef bool (*aul_boot_sequence_cb)(aul_boot_sequence_h, uid_t, void *);
-
-int aul_boot_sequence_foreach_usr(uid_t uid, aul_boot_sequence_cb callback, void *user_data);
-
-int aul_boot_sequence_get_appid(aul_boot_sequence_h handle, const char **appid);
-
-int aul_boot_sequence_get_after(aul_boot_sequence_h handle, const char **after);
-
-int aul_boot_sequence_get_before(aul_boot_sequence_h handle, const char **before);
-
-int aul_boot_sequence_get_requires(aul_boot_sequence_h handle, const char **requires_dep);
-
-int aul_boot_sequence_get_conflicts(aul_boot_sequence_h handle, const char **conflicts);
-
-int aul_boot_sequence_get_vconf(aul_boot_sequence_h handle, const char **vconf);
-
-int aul_boot_sequence_get_path_exists(aul_boot_sequence_h handle, const char **path_exists);
-
-int aul_boot_sequence_get_args(aul_boot_sequence_h handle, const char **args);
-
-int aul_boot_sequence_get_background_launch(aul_boot_sequence_h handle, const char **background_launch);
-
-int aul_boot_sequence_get_wait_until_ready(aul_boot_sequence_h handle, const char **wait_until_ready);
-
-int aul_boot_sequence_get_timeout(aul_boot_sequence_h handle, const char** timeout);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __AUL_BOOT_SEQUENCE_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2019 - 2021 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 <errno.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include <memory>
-#include <string>
-#include <vector>
-#include <tuple>
-
-#include "server/api/aul_comp_info_internal.h"
-#include "server/common_private.hh"
-#include "server/component_info.hh"
-#include "server/database.hh"
-#include "server/exception.hh"
-#include "server/localized_info.hh"
-#include "server/log_private.hh"
-
-using namespace aul;
-
-namespace {
-
-const char COMPONENT_DB[] = ".component.db";
-const char QUERY_COMPONENT_INFO[] = "SELECT app_id, component_id, "
- "component_type, component_launch_mode, component_main, "
- "component_icon_display, component_taskmanage FROM component_info";
-const char QUERY_LOCALIZED_INFO[] = "SELECT component_locale, "
- "component_icon, component_label FROM component_localized_info";
-
-ComponentInfo* CreateComponentInfo(sqlite3_stmt* stmt) {
- int idx = 0;
- ComponentInfo::Builder builder;
- builder.SetAppId(Database::ColumnText(stmt, idx++));
- builder.SetCompId(Database::ColumnText(stmt, idx++));
- builder.SetType(Database::ColumnText(stmt, idx++));
- builder.SetLaunchMode(Database::ColumnText(stmt, idx++));
- builder.SetMainComp(Database::ColumnText(stmt, idx++));
- builder.SetIconDisplay(Database::ColumnText(stmt, idx++));
- builder.SetTaskManage(Database::ColumnText(stmt, idx++));
- return builder.Build();
-}
-
-LocalizedInfo* CreateLocalizedInfo(sqlite3_stmt* stmt) {
- int idx = 0;
- LocalizedInfo::Builder builder;
- builder.SetLocale(Database::ColumnText(stmt, idx++));
- builder.SetIcon(Database::ColumnText(stmt, idx++));
- builder.SetLabel(Database::ColumnText(stmt, idx++));
- return builder.Build();
-}
-
-template <typename T, typename ...ARGS>
-int Step(T cb, std::tuple<ARGS...> args, const std::string& query, uid_t uid) {
- std::string path = Database::GetPath(COMPONENT_DB, uid);
- Database db(path);
- try {
- db.Open(SQLITE_OPEN_READONLY);
- } catch (Exception& e) {
- return e.GetErrorCode();
- }
-
- sqlite3_stmt* stmt;
- __PREPARE_V2(db.GetHandle(), query.c_str(), query.length(), stmt);
- auto stmt_ptr = std::unique_ptr<sqlite3_stmt, decltype(sqlite3_finalize)*>(
- stmt, sqlite3_finalize);
- return cb(db.GetHandle(), stmt, args);
-}
-
-using GetComponentInfoCb =
- int (*)(sqlite3*, sqlite3_stmt*, std::tuple<const char*, ComponentInfo**>);
-using GetComponentInfosCb =
- int (*)(sqlite3*, sqlite3_stmt*,
- std::tuple<const char*, std::vector<std::unique_ptr<ComponentInfo>>&>);
-using GetLocalizedInfosCb =
- int (*)(sqlite3*, sqlite3_stmt*,
- std::tuple<const char*, std::vector<std::unique_ptr<LocalizedInfo>>&>);
-
-int GetComponentInfo(const char* comp_id, uid_t uid,
- ComponentInfo** info) {
- std::string query = std::string(QUERY_COMPONENT_INFO) +
- " WHERE component_id=?";
- std::tuple<const char*, ComponentInfo**> param(comp_id, info);
- return Step<GetComponentInfoCb, const char*, ComponentInfo**>(
- [](sqlite3* db, sqlite3_stmt* stmt,
- std::tuple<const char*, ComponentInfo**> args) -> int {
- __BIND_TEXT(db, stmt, 1, std::get<0>(args));
- int ret = sqlite3_step(stmt);
- if (ret != SQLITE_ROW) {
- _E("sqlite3_step() is failed");
- return AUL_ERROR_NO_SUCH_APP;
- }
-
- auto** component_info = std::get<1>(args);
- *component_info = CreateComponentInfo(stmt);
- if (*component_info == nullptr)
- return AUL_ERROR_OUT_OF_MEMORY;
-
- return AUL_ERROR_NONE;
- }, param, query, uid);
-}
-
-int GetComponentInfos(const char* app_id, uid_t uid,
- std::vector<std::unique_ptr<ComponentInfo>>& infos) {
- std::string query = std::string(QUERY_COMPONENT_INFO);
- if (app_id != nullptr)
- query += " WHERE app_id=?";
-
- std::tuple<const char*, std::vector<std::unique_ptr<ComponentInfo>>&> param(
- app_id, infos);
- return Step<GetComponentInfosCb, const char*,
- std::vector<std::unique_ptr<ComponentInfo>>&>(
- [](sqlite3* db, sqlite3_stmt* stmt, std::tuple<const char*,
- std::vector<std::unique_ptr<ComponentInfo>>&> args) -> int {
- auto* id = std::get<0>(args);
- if (id != nullptr)
- __BIND_TEXT(db, stmt, 1, id);
-
- auto& v = std::get<1>(args);
- while (sqlite3_step(stmt) == SQLITE_ROW)
- v.emplace_back(CreateComponentInfo(stmt));
-
- if (v.empty())
- return AUL_ERROR_NO_SUCH_APP;
-
- return AUL_ERROR_NONE;
- }, param, query, uid);
-}
-
-int GetLocalizedInfos(const char* comp_id, uid_t uid,
- std::vector<std::unique_ptr<LocalizedInfo>>& infos) {
- std::string query = std::string(QUERY_LOCALIZED_INFO);
- if (comp_id != nullptr)
- query += " WHERE component_id=?";
-
- std::tuple<const char*, std::vector<std::unique_ptr<LocalizedInfo>>&> param(
- comp_id, infos);
- return Step<GetLocalizedInfosCb, const char*,
- std::vector<std::unique_ptr<LocalizedInfo>>&>(
- [](sqlite3* db, sqlite3_stmt* stmt, std::tuple<const char*,
- std::vector<std::unique_ptr<LocalizedInfo>>&> args) -> int {
- auto* id = std::get<0>(args);
- if (id != nullptr)
- __BIND_TEXT(db, stmt, 1, id);
-
- auto& v = std::get<1>(args);
- while (sqlite3_step(stmt) == SQLITE_ROW)
- v.emplace_back(CreateLocalizedInfo(stmt));
-
- if (v.empty())
- return AUL_ERROR_NO_SUCH_APP;
-
- return AUL_ERROR_NONE;
- }, param, query, uid);
-}
-
-} // namespace
-
-extern "C" API int aul_compinfo_create(const char* comp_id,
- aul_compinfo_h* handle) {
- return aul_compinfo_usr_create(comp_id, getuid(), handle);
-}
-
-extern "C" API int aul_compinfo_usr_create(const char* comp_id, uid_t uid,
- aul_compinfo_h* handle) {
- if (comp_id == nullptr || handle == nullptr) {
- _E("Invalid parameter");
- return AUL_ERROR_INVALID_PARAMETER;
- }
-
- ComponentInfo* info;
- int ret = ::GetComponentInfo(comp_id, uid, &info);
- if (ret != AUL_ERROR_NONE && uid != GLOBALAPP_UID)
- ret = ::GetComponentInfo(comp_id, GLOBALAPP_UID, &info);
-
- if (ret != AUL_ERROR_NONE)
- return ret;
-
- *handle = static_cast<aul_compinfo_h>(info);
- return AUL_ERROR_NONE;
-}
-
-extern "C" API int aul_compinfo_destroy(aul_compinfo_h handle) {
- if (handle == nullptr) {
- _E("Invalid parameter");
- return AUL_ERROR_INVALID_PARAMETER;
- }
-
- auto* info = static_cast<ComponentInfo*>(handle);
- delete info;
- return AUL_ERROR_NONE;
-}
-
-extern "C" API int aul_compinfo_clone(aul_compinfo_h handle,
- aul_compinfo_h* clone) {
- if (handle == nullptr || clone == nullptr) {
- _E("Invalid parameter");
- return AUL_ERROR_INVALID_PARAMETER;
- }
-
- auto* info = static_cast<ComponentInfo*>(handle);
- ComponentInfo::Builder builder;
- builder.SetAppId(info->GetAppId());
- builder.SetCompId(info->GetCompId());
- builder.SetType(info->GetType());
- builder.SetLaunchMode(info->GetLaunchMode());
- builder.SetMainComp(info->GetMainComp());
- builder.SetIconDisplay(info->GetIconDisplay());
- builder.SetTaskManage(info->GetTaskManage());
- auto* cloned_info = builder.Build();
- if (cloned_info == nullptr) {
- _E("Out of memory");
- return AUL_ERROR_OUT_OF_MEMORY;
- }
-
- *clone = static_cast<aul_compinfo_h>(cloned_info);
- return AUL_ERROR_NONE;
-}
-
-extern "C" API int aul_compinfo_get_app_id(aul_compinfo_h handle,
- const char** app_id) {
- if (handle == nullptr || app_id == nullptr) {
- _E("Invalid parameter");
- return AUL_ERROR_INVALID_PARAMETER;
- }
-
- auto* info = static_cast<ComponentInfo*>(handle);
- *app_id = info->GetAppId().c_str();
- return AUL_ERROR_NONE;
-}
-
-extern "C" API int aul_compinfo_get_comp_id(aul_compinfo_h handle,
- const char** comp_id) {
- if (handle == nullptr || comp_id == nullptr) {
- _E("Invalid parameter");
- return AUL_ERROR_INVALID_PARAMETER;
- }
-
- auto* info = static_cast<ComponentInfo*>(handle);
- *comp_id = info->GetCompId().c_str();
- return AUL_ERROR_NONE;
-}
-
-extern "C" API int aul_compinfo_get_type(aul_compinfo_h handle,
- const char** type) {
- if (handle == nullptr || type == nullptr) {
- _E("Invalid parameter");
- return AUL_ERROR_INVALID_PARAMETER;
- }
-
- auto* info = static_cast<ComponentInfo*>(handle);
- *type = info->GetType().c_str();
- return AUL_ERROR_NONE;
-}
-
-extern "C" API int aul_compinfo_get_launch_mode(aul_compinfo_h handle,
- const char** launch_mode) {
- if (handle == nullptr || launch_mode == nullptr) {
- _E("Invalid parameter");
- return AUL_ERROR_INVALID_PARAMETER;
- }
-
- auto* info = static_cast<ComponentInfo*>(handle);
- *launch_mode = info->GetLaunchMode().c_str();
- return AUL_ERROR_NONE;
-}
-
-extern "C" API int aul_compinfo_is_main_comp(aul_compinfo_h handle,
- bool* main_comp) {
- if (handle == nullptr || main_comp == nullptr) {
- _E("Invalid parameter");
- return AUL_ERROR_INVALID_PARAMETER;
- }
-
- auto* info = static_cast<ComponentInfo*>(handle);
- if (info->GetMainComp() == "true")
- *main_comp = true;
- else
- *main_comp = false;
-
- return AUL_ERROR_NONE;
-}
-
-extern "C" API int aul_compinfo_is_icon_display(aul_compinfo_h handle,
- bool* icon_display) {
- if (handle == nullptr || icon_display == nullptr) {
- _E("Invalid parameter");
- return AUL_ERROR_INVALID_PARAMETER;
- }
-
- auto* info = static_cast<ComponentInfo*>(handle);
- if (info->GetIconDisplay() == "true")
- *icon_display = true;
- else
- *icon_display = false;
-
- return AUL_ERROR_NONE;
-}
-
-extern "C" API int aul_compinfo_is_taskmanage(aul_compinfo_h handle,
- bool* taskmanage) {
- if (handle == nullptr || taskmanage == nullptr) {
- _E("Invalid parameter");
- return AUL_ERROR_INVALID_PARAMETER;
- }
-
- auto* info = static_cast<ComponentInfo*>(handle);
- if (info->GetTaskManage() == "true")
- *taskmanage = true;
- else
- *taskmanage = false;
-
- return AUL_ERROR_NONE;
-}
-
-extern "C" API int aul_compinfo_foreach_compinfo_from_app(const char* app_id,
- aul_compinfo_cb callback, void* user_data) {
- return aul_compinfo_usr_foreach_compinfo_from_app(app_id, getuid(),
- callback, user_data);
-}
-
-extern "C" API int aul_compinfo_usr_foreach_compinfo_from_app(
- const char* app_id, uid_t uid, aul_compinfo_cb callback, void* user_data) {
- if (app_id == nullptr || callback == nullptr) {
- _E("Invalid parameter");
- return AUL_ERROR_INVALID_PARAMETER;
- }
-
- std::vector<std::unique_ptr<ComponentInfo>> infos;
- int ret = ::GetComponentInfos(app_id, uid, infos);
- if (ret != AUL_ERROR_NONE && uid != GLOBALAPP_UID)
- ret = ::GetComponentInfos(app_id, GLOBALAPP_UID, infos);
-
- if (ret != AUL_ERROR_NONE) {
- _E("Failed to get component infos");
- return ret;
- }
-
- for (auto& info : infos) {
- aul_compinfo_h handle = static_cast<aul_compinfo_h>(info.get());
- if (!callback(handle, user_data))
- break;
- }
-
- return AUL_ERROR_NONE;
-}
-
-extern "C" API int aul_compinfo_foreach_compinfo(aul_compinfo_cb callback,
- void* user_data) {
- return aul_compinfo_usr_foreach_compinfo(getuid(), callback, user_data);
-}
-
-extern "C" API int aul_compinfo_usr_foreach_compinfo(uid_t uid,
- aul_compinfo_cb callback, void* user_data) {
- if (callback == nullptr) {
- _E("Invalid parameter");
- return AUL_ERROR_INVALID_PARAMETER;
- }
-
- std::vector<std::unique_ptr<ComponentInfo>> infos;
- int ret = ::GetComponentInfos(nullptr, uid, infos);
- if (ret != AUL_ERROR_NONE && uid != GLOBALAPP_UID)
- ret = ::GetComponentInfos(nullptr, GLOBALAPP_UID, infos);
-
- if (ret != AUL_ERROR_NONE) {
- _E("Failed to get component infos");
- return ret;
- }
-
- for (auto& info : infos) {
- aul_compinfo_h handle = static_cast<aul_compinfo_h>(info.get());
- if (!callback(handle, user_data))
- break;
- }
-
- return AUL_ERROR_NONE;
-}
-
-extern "C" API int aul_compinfo_localized_info_get_locale(
- aul_compinfo_localized_info_h handle, const char** locale) {
- if (handle == nullptr || locale == nullptr) {
- _E("Invalid parameter");
- return AUL_ERROR_INVALID_PARAMETER;
- }
-
- auto* info = static_cast<LocalizedInfo*>(handle);
- *locale = info->GetLocale().c_str();
- return AUL_ERROR_NONE;
-}
-
-extern "C" API int aul_compinfo_localized_info_get_icon(
- aul_compinfo_localized_info_h handle, const char** icon) {
- if (handle == nullptr || icon == nullptr) {
- _E("Invalid parameter");
- return AUL_ERROR_INVALID_PARAMETER;
- }
-
- auto* info = static_cast<LocalizedInfo*>(handle);
- *icon = info->GetIcon().c_str();
- return AUL_ERROR_NONE;
-}
-
-extern "C" API int aul_compinfo_localized_info_get_label(
- aul_compinfo_localized_info_h handle, const char** label) {
- if (handle == nullptr || label == nullptr) {
- _E("Invalid parameter");
- return AUL_ERROR_INVALID_PARAMETER;
- }
-
- auto* info = static_cast<LocalizedInfo*>(handle);
- *label = info->GetLabel().c_str();
- return AUL_ERROR_NONE;
-}
-
-extern "C" API int aul_compinfo_foreach_localized_info(const char* comp_id,
- aul_compinfo_localized_info_cb callback, void* user_data) {
- return aul_compinfo_usr_foreach_localized_info(comp_id, getuid(),
- callback, user_data);
-}
-
-extern "C" API int aul_compinfo_usr_foreach_localized_info(const char* comp_id,
- uid_t uid, aul_compinfo_localized_info_cb callback, void* user_data) {
- if (comp_id == nullptr || callback == nullptr) {
- _E("Invalid parameter");
- return AUL_ERROR_INVALID_PARAMETER;
- }
-
- std::vector<std::unique_ptr<LocalizedInfo>> infos;
- int ret = GetLocalizedInfos(comp_id, uid, infos);
- if (ret != AUL_ERROR_NONE && uid != GLOBALAPP_UID)
- ret = GetLocalizedInfos(comp_id, GLOBALAPP_UID, infos);
-
- if (ret != AUL_ERROR_NONE) {
- _E("Failed to get localized infos");
- return ret;
- }
-
- for (auto& info : infos) {
- auto handle = static_cast<aul_compinfo_localized_info_h>(info.get());
- if (!callback(handle, user_data))
- break;
- }
-
- return AUL_ERROR_NONE;
-}
+++ /dev/null
-/*
- * Copyright (c) 2019 - 2021 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_COMP_INFO_INTERNAL_H__
-#define __AUL_COMP_INFO_INTERNAL_H__
-
-#include <unistd.h>
-
-#include <aul_types.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @brief The component information handle.
- * @since_tizen 5.5
- */
-typedef void *aul_compinfo_h;
-
-/**
- * @brief The localized information handle of the component.
- * @since_tizen 5.5
- */
-typedef void *aul_compinfo_localized_info_h;
-
-/**
- * @brief Called to get the component information once for each installed component.
- * @since_tizen 5.5
- *
- * @param[in] handle The component information handle
- * @param[in] user_data The user data passed from the foreach function
- * @return @c true to continue with the next iteration of the loop, \n
- * otherwise @ false to break out of the loop
- * @see aul_compinfo_foreach_compinfo()
- * @see aul_compinfo_usr_foreach_compinfo()
- */
-typedef bool (*aul_compinfo_cb)(aul_compinfo_h handle, void *user_data);
-
-/**
- * @brief Called to get the localized information once for each installed component.
- * @since_tizen 5.5
- *
- * @param[in] handle The localized_information handle of the component
- * @param[in] user_data The user data passed from the foreach function
- * @return @c true to continue with the next iteration of the loop, \n
- * otherwise @ false to break out of the loop
- * @see aul_compinfo_foreach_localized_info()
- * @see aul_compinfo_usr_foreach_localized_info()
- */
-typedef bool (*aul_compinfo_localized_info_cb)(
- aul_compinfo_localized_info_h handle, void *user_data);
-
-/**
- * @brief Creates the component information handle.
- * @since_tizen 5.5
- * @remarks You MUST release @a handle using aul_compinfo_destroy().
- *
- * @param[in] comp_id The component ID
- * @param[out] handle The component information handle
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_compinfo_create(const char *comp_id, aul_compinfo_h *handle);
-
-/**
- * @brief Creates the component information handle.
- * @since_tizen 5.5
- * @remarks You MUST release @a handle using aul_comp_info_destroy().
- *
- * @param[in] comp_id The component ID
- * @param[in] uid The user ID
- * @param[out] handle The component information handle
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_compinfo_usr_create(const char *comp_id, uid_t uid,
- aul_compinfo_h *handle);
-
-/**
- * @brief Destroys the component information handle.
- * @since_tizen 5.5
- *
- * @param[in] handle The component information handle
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_compinfo_destroy(aul_compinfo_h handle);
-
-/**
- * @brief Clones the component information handle.
- * @since_tizen 5.5
- * @remarks You MUST release @a clone using aul_compinfo_destroy().
- *
- * @param[in] handle The component information handle
- * @param[out] clone A newly created component information handle, if successfully cloned
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_compinfo_clone(aul_compinfo_h handle, aul_compinfo_h *clone);
-
-/**
- * @brief Gets the application ID of the component.
- * @since_tizen 5.5
- * @remarks You MUST NOT release @a app_id using free().
- *
- * @param[in] handle The component information handle
- * @param[out] app_id The application ID of the component
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_compinfo_get_app_id(aul_compinfo_h handle, const char **app_id);
-
-/**
- * @brief Gets the ID of the component.
- * @since_tizen 5.5
- * @remarks You MUST NOT release @a comp_id using free().
- *
- * @param[in] handle The component information handle
- * @param[out] comp_id The ID of the component
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_compinfo_get_comp_id(aul_compinfo_h handle, const char **comp_id);
-
-/**
- * @brief Gets the type of the component.
- * @since_tizen 5.5
- * @remarks You MUST NOT release @a type using free().
- *
- * @param[in] handle The component information handle
- * @param[out] type The type of the component
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_compinfo_get_type(aul_compinfo_h handle, const char **type);
-
-/**
- * @brief Gets the launch mode of the component.
- * @since_tizen 5.5
- * @remarks You MUST NOT release @a launch_mode using free().
- *
- * @param[in] handle The component information handle
- * @param[out] launch_mode The launch mode of the component
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_compinfo_get_launch_mode(aul_compinfo_h handle,
- const char **launch_mode);
-
-/**
- * @brief Checks whether the component is the main component or not.
- * @since_tizen 5.5
- *
- * @param[in] handle The component information handle
- * @param[out] main_comp @c true if the component is the main component, \n
- * otherwise @c false
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_compinfo_is_main_comp(aul_compinfo_h handle, bool *main_comp);
-
-/**
- * @brief Checks whether the icon of the component should be displayed or not.
- * @since_tizen 5.5
- *
- * @param[in] handle The component information handle
- * @param[out] icon_display @c true if the icon should be displayed, \n
- * otherwise @c false
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_compinfo_is_icon_display(aul_compinfo_h handle, bool *icon_display);
-
-/**
- * @brief Checks whether the component should be managed by task-manager or not.
- * @since_tizen 5.5
- *
- * @param[in] handle The component information handle
- * @param[out] taskmanage @c true if the component should be managed by task-manager, \n
- * otherwise @c false
- * @return @c 0 on success,
- * otherwise a negative error value
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_compinfo_is_taskmanage(aul_compinfo_h handle, bool *taskmanage);
-
-/**
- * @brief Retrieves all installed components information of the specified application.
- * @since_tizen 5.5
- *
- * @param[in] app_id The application ID
- * @param[in] callback The callback function to invoke
- * @param[in] user_data The user data to be passed to the callback function
- * @return @c 0 on success,
- * otherwise a negative error value
- * @see aul_comp_info_cb()
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_compinfo_foreach_compinfo_from_app(const char *app_id,
- aul_compinfo_cb callback, void *user_data);
-
-/**
- * @brief Retrieves all installed components information of the specified application.
- * @since_tizen 5.5
- *
- * @param[in] app_id The application ID
- * @param[in] uid The user ID
- * @param[in] callback The callback function to invoke
- * @param[in] user_data The user data to be passed to the callback function
- * @return @c 0 on success,
- * otherwise a negative error value
- * @see aul_compinfo_cb()
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_compinfo_usr_foreach_compinfo_from_app(const char *app_id, uid_t uid,
- aul_compinfo_cb callback, void *user_data);
-
-/**
- * @brief Retrieves all installed components information.
- * @since_tizen 5.5
- *
- * @param[in] callback The callback function to invoke
- * @param[in] user_data The user data to be passed to the callback function
- * @return @c 0 on success,
- * otherwise a negative error value
- * @see aul_compinfo_cb()
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_compinfo_foreach_compinfo(aul_compinfo_cb callback, void *user_data);
-
-/**
- * @brief Retrieves all installed components information.
- * @since_tizen 5.5
- *
- * @param[in] uid The user ID
- * @param[in] callback The callback function to invoke
- * @param[in] user_data The user data to be passed to the callback function
- * @return @c 0 on success,
- * otherwise a negative error value
- * @see aul_compinfo_cb()
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_compinfo_usr_foreach_compinfo(uid_t uid, aul_compinfo_cb callback,
- void *user_data);
-
-/**
- * @brief Gets the locale of the component.
- * @since_tizen 5.5
- * @details The @a handle is passed from the aul_compinfo_localized_info_cb() function.
- * @remarks You MUST NOT release @a locale using free().
- *
- * @param[in] handle The localized information handle
- * @param[out] locale The locale
- * @return @c 0 on success,
- * otherwise a negative error value
- * @see aul_compinfo_foreach_localized_info()
- * @see aul_compinfo_localized_info_cb()
- *
- * @remarks This function is only for App Framework insternally.
- */
-int aul_compinfo_localized_info_get_locale(aul_compinfo_localized_info_h handle,
- const char **locale);
-
-/**
- * @brief Gets the icon path of the component.
- * @since_tizen 5.5
- * @details The @a handle is passed from the aul_compinfo_localized_info_cb() function.
- * @remarks You MUST NOT release @a icon using free().
- *
- * @param[in] handle The localized information handle
- * @param[out] icon The icon path
- * @return @c 0 on success,
- * otherwise a negative error value
- * @see aul_compinfo_foreach_localized_info()
- * @see aul_compinfo_localized_info_cb()
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_compinfo_localized_info_get_icon(aul_compinfo_localized_info_h handle,
- const char **icon);
-
-/**
- * @brief Gets the label of the component.
- * @since_tizen 5.5
- * @details The @a handle is passed from the aul_compinfo_localized_info_cb() function.
- * @remarks You MUST NOT release @a label using free().
- *
- * @param[in] handle The localized information handle
- * @param[out] label The label
- * @return @c 0 on success,
- * otherwise a negative error value
- * @see aul_compinfo_foreach_localized_info()
- * @see aul_compinfo_localized_info_cb()
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_compinfo_localized_info_get_label(aul_compinfo_localized_info_h handle,
- const char **label);
-
-/**
- * @brief Retrieves all localized information of the specified component.
- * @since_tizen 5.5
- *
- * @param[in] comp_id The component ID
- * @param[in] callback The callback function to invoke
- * @param[in] user_data The user data to be passed to the callback function
- * @return @c 0 on success,
- * otherwise a negative error value
- * @see aul_compinfo_localized_info_cb()
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_compinfo_foreach_localized_info(const char *comp_id,
- aul_compinfo_localized_info_cb callback, void *user_data);
-
-/**
- * @brief Retrieves all localized information of the specified component.
- * @since_tizen 5.5
- *
- * @param[in] comp_id The component ID
- * @param[in] uid The user ID
- * @param[in] callback The callback function to invoke
- * @param[in] user_data The user data to be passed to the callback function
- * @return @c 0 on success,
- * otherwise a negative error value
- * @see aul_compinfo_localized_info_cb()
- *
- * @remarks This function is only for App Framework internally.
- */
-int aul_compinfo_usr_foreach_localized_info(const char *comp_id, uid_t uid,
- aul_compinfo_localized_info_cb callback, void *user_data);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __AUL_COMP_INFO_INTERNAL_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2021 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 <sys/types.h>
-#include <tzplatform_config.h>
-#include <unistd.h>
-
-#include <map>
-#include <memory>
-#include <string>
-#include <tuple>
-#include <utility>
-#include <vector>
-
-#include "server/api/aul_service.h"
-#include "server/common_private.hh"
-#include "server/database.hh"
-#include "server/log_private.hh"
-
-using namespace aul;
-
-namespace {
-
-const char APPSVC_DB[] = ".appsvc.db";
-const char QUERY_INSERT_OR_REPLACE_INTO_APPSVC[] = "INSERT OR REPLACE INTO "
- "appsvc(operation, mime_type, uri, pkg_name) VALUES(?, ?, ?, ?)";
-const char QUERY_DELETE_FROM_APPSVC[] = "DELETE FROM appsvc";
-const char QUERY_INSERT_OR_REPLACE_INTO_ALIAS_INFO[] =
- "INSERT OR REPLACE INTO alias_info(alias_appid, appid) VALUES(?, ?)";
-const char QUERY_DELETE_FROM_ALIAS_INFO[] = "DELETE FROM alias_info";
-const char QUERY_SELECT_FROM_ALIAS_INFO[] = "SELECT alias_appid, appid "
- "FROM alias_info";
-const char QUERY_INSERT_OR_REPLACE_INTO_ALIAS_INFO_FOR_UID[] =
- "INSERT OR REPLACE INTO alias_info_for_uid(appid, uid, is_enabled) "
- "VALUES((SELECT appid FROM alias_info WHERE appid = ?), ?, ?)";
-const char QUERY_UPDATE_ALIAS_INFO_SET_ENABLE_WHERE_APPID[] =
- "UPDATE alias_info set enable = ? WHERE appid = ?";
-const char QUERY_SELECT_APPID_FROM_ALIAS_INFO[] =
- "SELECT appid FROM alias_info WHERE alias_info.alias_appid = ?";
-const char QUERY_SELECT_FROM_ALLOWED_INFO[] =
- "SELECT appid, allowed_appid FROM allowed_info";
-
-using InsertDefaultAppTupleParam = std::vector<const char*>;
-using InsertDefaultAppCb =
- int (*)(sqlite3*, sqlite3_stmt*, std::tuple<InsertDefaultAppTupleParam>);
-using DeleteDefaultAppCb =
- int (*)(sqlite3*, sqlite3_stmt*, std::tuple<const char*>);
-using InsertAliasAppIdParam = std::vector<const char*>;
-using InsertAliasAppIdCb =
- int (*)(sqlite3*, sqlite3_stmt*, std::tuple<InsertAliasAppIdParam>);
-using DeleteAliasAppIdCb =
- int (*)(sqlite3*, sqlite3_stmt*, std::tuple<const char*>);
-using SelectAliasInfoCb =
- int (*)(sqlite3*, sqlite3_stmt*,
- std::tuple<uid_t, uid_t, std::map<std::string, std::string>&>);
-using EnableOrDisableAliasInfoCb =
- int (*)(sqlite3*, sqlite3_stmt*,
- std::tuple<uid_t, uid_t, const char*, bool>);
-using SelectAllowedInfoCb =
- int (*)(sqlite3*, sqlite3_stmt*,
- std::tuple<std::vector<std::pair<std::string, std::string>>&>);
-
-template <typename T, typename ...ARGS>
-int Step(T cb, std::tuple<ARGS...> args,
- bool readonly, const std::string& query, uid_t uid) {
- std::string path = Database::GetPath(APPSVC_DB, uid);
- Database db(path, false);
- try {
- db.Open(readonly ? SQLITE_OPEN_READONLY : SQLITE_OPEN_READWRITE);
- } catch (Exception& e) {
- return AUL_ERROR_IO_ERROR;
- }
-
- sqlite3_stmt* stmt;
- __PREPARE_V2(db.GetHandle(), query.c_str(), query.length(), stmt);
- auto stmt_ptr = std::unique_ptr<sqlite3_stmt, decltype(sqlite3_finalize)*>(
- stmt, sqlite3_finalize);
-
- int ret;
- if (readonly) {
- ret = cb(db.GetHandle(), stmt, args);
- } else {
- db.BeginTransaction();
- ret = cb(db.GetHandle(), stmt, args);
- if (ret < 0)
- db.Rollback();
- else
- db.EndTransaction();
- }
-
- return ret;
-}
-
-int GetAliasInfos(uid_t uid, uid_t db_uid,
- std::map<std::string, std::string>& infos) {
- std::string query(QUERY_SELECT_FROM_ALIAS_INFO);
- if (db_uid == GLOBALAPP_UID) {
- query += " WHERE alias_info.appid NOT IN (SELECT appid FROM";
- query += " alias_info_for_uid WHERE uid = ?)";
- } else {
- query += " WHERE enable = 'true'";
- }
-
- std::tuple<uid_t, uid_t, std::map<std::string, std::string>&> param(
- uid, db_uid, infos);
- int ret = Step<SelectAliasInfoCb, uid_t, uid_t,
- std::map<std::string, std::string>&>(
- [](sqlite3* db, sqlite3_stmt* stmt,
- std::tuple<uid_t, uid_t,
- std::map<std::string, std::string>&> args) -> int {
- uid_t db_uid = std::get<1>(args);
- if (db_uid == GLOBALAPP_UID) {
- uid_t uid = std::get<0>(args);
- __BIND_INT(db, stmt, 1, uid);
- }
-
- auto& infos = std::get<2>(args);
- while (sqlite3_step(stmt) == SQLITE_ROW) {
- int idx = 0;
- std::string alias_appid = Database::ColumnText(stmt, idx++);
- std::string appid = Database::ColumnText(stmt, idx++);
- infos[alias_appid] = appid;
- }
-
- return AUL_ERROR_NONE;
- }, param, true, query, db_uid);
- if (ret != AUL_ERROR_NONE)
- return AUL_ERROR_IO_ERROR;
-
- return AUL_ERROR_NONE;
-}
-
-int EnableOrDisableAliasInfo(uid_t uid, uid_t db_uid, const char* appid,
- bool enable) {
- std::string query;
- if (db_uid == GLOBALAPP_UID)
- query = QUERY_INSERT_OR_REPLACE_INTO_ALIAS_INFO_FOR_UID;
- else
- query = QUERY_UPDATE_ALIAS_INFO_SET_ENABLE_WHERE_APPID;
-
- std::tuple<uid_t, uid_t, const char*, bool> param(uid, db_uid, appid, enable);
- int ret = Step<EnableOrDisableAliasInfoCb, uid_t, uid_t, const char*, bool>(
- [](sqlite3* db, sqlite3_stmt* stmt,
- std::tuple<uid_t, uid_t, const char*, bool> args) -> int {
- int idx = 1;
- uid_t db_uid = std::get<1>(args);
- if (db_uid == GLOBALAPP_UID) {
- __BIND_TEXT(db, stmt, idx++, std::get<2>(args));
- __BIND_INT(db, stmt, idx++, std::get<0>(args));
- __BIND_TEXT(db, stmt, idx++, std::get<3>(args) ? "true" : "false");
- } else {
- __BIND_TEXT(db, stmt, idx++, std::get<3>(args) ? "true" : "false");
- __BIND_TEXT(db, stmt, idx++, std::get<2>(args));
- }
-
- __STEP(db, stmt);
- return AUL_ERROR_NONE;
- }, param, false, query, db_uid);
- if (ret != AUL_ERROR_NONE)
- return AUL_ERROR_IO_ERROR;
-
- return AUL_ERROR_NONE;
-}
-
-int GetAllowedInfos(uid_t uid,
- std::vector<std::pair<std::string, std::string>>& infos) {
- std::string query(QUERY_SELECT_FROM_ALLOWED_INFO);
- std::tuple<std::vector<std::pair<std::string, std::string>>&> param(infos);
- int ret = Step<SelectAllowedInfoCb,
- std::vector<std::pair<std::string, std::string>>&>(
- [](sqlite3* db, sqlite3_stmt* stmt,
- std::tuple<std::vector<std::pair<std::string,
- std::string>>&> args) -> int {
- auto& infos = std::get<0>(args);
- while (sqlite3_step(stmt) == SQLITE_ROW) {
- int idx = 0;
- std::string appid = Database::ColumnText(stmt, idx++);
- std::string allowed_appid = Database::ColumnText(stmt, idx++);
- infos.emplace_back(appid, allowed_appid);
- }
- return AUL_ERROR_NONE;
- }, param, false, query, uid);
- if (ret != AUL_ERROR_NONE)
- return AUL_ERROR_IO_ERROR;
-
- return AUL_ERROR_NONE;
-}
-
-} // namespace
-
-extern "C" API int aul_service_insert_usr_default_app(const char* operation,
- const char* mime_type, const char* uri, const char* appid, uid_t uid) {
- if (operation == nullptr || appid == nullptr) {
- _E("Invalid parameter");
- return AUL_ERROR_INVALID_PARAMETER;
- }
-
- std::string query(QUERY_INSERT_OR_REPLACE_INTO_APPSVC);
- std::vector<const char*> argv { operation, mime_type, uri, appid };
- std::tuple<InsertDefaultAppTupleParam> param(argv);
- int ret = Step<InsertDefaultAppCb, InsertDefaultAppTupleParam>(
- [](sqlite3* db, sqlite3_stmt* stmt,
- std::tuple<InsertDefaultAppTupleParam> args) -> int {
- int idx = 1;
- auto argv = std::get<0>(args);
- __BIND_TEXT(db, stmt, idx++, argv[0]);
- __BIND_TEXT(db, stmt, idx++, argv[1] ? argv[1] : "NULL");
- __BIND_TEXT(db, stmt, idx++, argv[2] ? argv[2] : "NULL");
- __BIND_TEXT(db, stmt, idx++, argv[3]);
- __STEP(db, stmt);
- return AUL_ERROR_NONE;
- }, param, false, query, uid);
- if (ret != AUL_ERROR_NONE)
- return AUL_ERROR_IO_ERROR;
-
- return AUL_ERROR_NONE;
-}
-
-static int __delete_usr_default_app(const char* appid, uid_t uid) {
- std::string query(QUERY_DELETE_FROM_APPSVC);
- if (appid != nullptr)
- query += " WHERE pkg_name = ?";
-
- std::tuple<const char*> param(appid);
- int ret = Step<DeleteDefaultAppCb, const char*>(
- [](sqlite3* db, sqlite3_stmt* stmt, std::tuple<const char*> args) -> int {
- auto* appid = std::get<0>(args);
- __BIND_TEXT(db, stmt, 1, appid);
- __STEP(db, stmt);
- return AUL_ERROR_NONE;
- }, param, false, query, uid);
- if (ret != AUL_ERROR_NONE)
- return AUL_ERROR_IO_ERROR;
-
- return AUL_ERROR_NONE;
-}
-
-extern "C" API int aul_service_delete_usr_default_app(const char* appid,
- uid_t uid) {
- if (appid == nullptr) {
- _E("Invalid parameter");
- return AUL_ERROR_INVALID_PARAMETER;
- }
-
- return __delete_usr_default_app(appid, uid);
-}
-
-extern "C" API int aul_service_delete_usr_all_default_app(uid_t uid) {
- return __delete_usr_default_app(nullptr, uid);
-}
-
-extern "C" API int aul_service_insert_usr_alias_appid(const char* alias_appid,
- const char* appid, uid_t uid) {
- if (alias_appid == nullptr || appid == nullptr) {
- _E("Invalid parameter");
- return AUL_ERROR_INVALID_PARAMETER;
- }
-
- std::string query(QUERY_INSERT_OR_REPLACE_INTO_ALIAS_INFO);
- std::vector<const char*> argv { alias_appid, appid };
- std::tuple<InsertAliasAppIdParam> param(argv);
- int ret = Step<InsertAliasAppIdCb, InsertAliasAppIdParam>(
- [](sqlite3* db, sqlite3_stmt* stmt,
- std::tuple<InsertAliasAppIdParam> args) -> int {
- auto& argv = std::get<0>(args);
- int idx = 1;
- __BIND_TEXT(db, stmt, idx++, argv[0]);
- __BIND_TEXT(db, stmt, idx++, argv[1]);
- __STEP(db, stmt);
- return AUL_ERROR_NONE;
- }, param, false, query, uid);
- if (ret != AUL_ERROR_NONE)
- return AUL_ERROR_IO_ERROR;
-
- return AUL_ERROR_NONE;
-}
-
-extern "C" API int aul_service_delete_usr_alias_appid(const char* alias_appid,
- uid_t uid) {
- if (alias_appid == nullptr) {
- _E("Invalid parameter");
- return AUL_ERROR_INVALID_PARAMETER;
- }
-
- std::string query = std::string(QUERY_DELETE_FROM_ALIAS_INFO) +
- " WHERE alias_appid = ?";
- std::tuple<const char*> param(alias_appid);
- int ret = Step<DeleteAliasAppIdCb, const char*>(
- [](sqlite3* db, sqlite3_stmt* stmt, std::tuple<const char*> args) -> int {
- auto* alias_appid = std::get<0>(args);
- __BIND_TEXT(db, stmt, 1, alias_appid);
- __STEP(db, stmt);
- return AUL_ERROR_NONE;
- }, param, false, query, uid);
- if (ret != AUL_ERROR_NONE)
- return AUL_ERROR_IO_ERROR;
-
- return AUL_ERROR_NONE;
-}
-
-extern "C" API int aul_service_foreach_usr_alias_info(
- aul_service_alias_info_cb callback, uid_t uid, void* user_data) {
- if (callback == nullptr) {
- _E("Invalid parameter");
- return AUL_ERROR_INVALID_PARAMETER;
- }
-
-
- std::map<std::string, std::string> infos;
- int ret = GetAliasInfos(uid, uid, infos);
- if (ret == AUL_ERROR_NONE && uid != GLOBALAPP_UID)
- ret = GetAliasInfos(uid, GLOBALAPP_UID, infos);
-
- if (ret != AUL_ERROR_NONE) {
- _E("Failed to get alias infos. error(%d)", ret);
- return ret;
- }
-
- auto iter = infos.begin();
- while (iter != infos.end()) {
- if (!callback(iter->first.c_str(), iter->second.c_str(), user_data))
- break;
- iter++;
- }
-
- return AUL_ERROR_NONE;
-}
-
-extern "C" API int aul_service_enable_usr_alias_info(const char* appid,
- uid_t uid) {
- if (appid == nullptr) {
- _E("Invalid parameter");
- return AUL_ERROR_INVALID_PARAMETER;
- }
-
- int ret = EnableOrDisableAliasInfo(uid, uid, appid, true);
- if (ret != AUL_ERROR_NONE && uid != GLOBALAPP_UID)
- ret = EnableOrDisableAliasInfo(uid, GLOBALAPP_UID, appid, true);
-
- return ret;
-}
-
-extern "C" API int aul_service_disable_usr_alias_info(const char* appid,
- uid_t uid) {
- if (appid == nullptr) {
- _E("Invalid parameter");
- return AUL_ERROR_INVALID_PARAMETER;
- }
-
- int ret = EnableOrDisableAliasInfo(uid, uid, appid, false);
- if (ret != AUL_ERROR_NONE && uid != GLOBALAPP_UID)
- ret = EnableOrDisableAliasInfo(uid, GLOBALAPP_UID, appid, false);
-
- return ret;
-}
-
-extern "C" API int aul_service_foreach_usr_allowed_info(
- aul_service_allowed_info_cb callback, uid_t uid, void* user_data) {
- if (callback == nullptr) {
- _E("Invalid parameter");
- return AUL_ERROR_INVALID_PARAMETER;
- }
-
- std::vector<std::pair<std::string, std::string>> infos;
- int ret = GetAllowedInfos(uid, infos);
- if (ret == AUL_ERROR_NONE && uid != GLOBALAPP_UID)
- ret = GetAllowedInfos(GLOBALAPP_UID, infos);
-
- if (ret != AUL_ERROR_NONE) {
- _E("Failed to get allowed infos. error(%d)", ret);
- return ret;
- }
-
- for (auto& info : infos) {
- if (!callback(info.first.c_str(), info.second.c_str(), user_data))
- break;
- }
-
- return AUL_ERROR_NONE;
-}
+++ /dev/null
-/*
- * Copyright (c) 2021 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_SERVICE_H__
-#define __AUL_SERVICE_H__
-
-#include <stdbool.h>
-
-#include <aul_types.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef bool (*aul_service_alias_info_cb)(const char *alias_appid, const char *appid, void *user_data);
-
-typedef bool (*aul_service_allowed_info_cb)(const char *appid, const char *allowed_appid, void *user_data);
-
-int aul_service_insert_usr_default_app(const char* operation, const char* mime_type, const char* uri, const char* appid, uid_t uid);
-
-int aul_service_delete_usr_default_app(const char* appid, uid_t uid);
-
-int aul_service_delete_usr_all_default_app(uid_t uid);
-
-int aul_service_insert_usr_alias_appid(const char* alias_appid, const char* appid, uid_t uid);
-
-int aul_service_delete_usr_alias_appid(const char* alias_appid, uid_t uid);
-
-int aul_service_foreach_usr_alias_info(aul_service_alias_info_cb callback, uid_t uid, void* user_data);
-
-int aul_service_enable_usr_alias_info(const char* appid, uid_t uid);
-
-int aul_service_disable_usr_alias_info(const char* appid, uid_t uid);
-
-int aul_service_foreach_usr_allowed_info(aul_service_allowed_info_cb callback, uid_t uid, void* user_data);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __AUL_SERVICE_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2021 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_TYPES_H__
-#define __AUL_TYPES_H__
-
-#include <errno.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @brief Enumeration for errors of AUL.
- * @since_tizen 6.5
- */
-typedef enum {
- AUL_ERROR_NONE = 0, /**< Successful */
- AUL_ERROR_INVALID_PARAMETER = -EINVAL, /**< Invalid parameter */
- AUL_ERROR_IO_ERROR = -EIO, /**< I/O error */
- AUL_ERROR_NO_SUCH_APP = -ENOENT, /**< No such application */
- AUL_ERROR_NO_DATA = -ENODATA, /**< No data */
- AUL_ERROR_OUT_OF_MEMORY = -ENOMEM, /**< Out of memory */
- AUL_ERROR_PERMISSION_DENIED = -EPERM, /**< Permission denied */
-} aul_error_e;
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __AUL_TYPES_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2021 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 <sys/types.h>
-#include <tzplatform_config.h>
-#include <unistd.h>
-
-#include "server/api/aul_widget_service.h"
-#include "server/common_private.hh"
-#include "server/database.hh"
-#include "server/log_private.hh"
-
-using namespace aul;
-
-namespace {
-
-const char WIDGET_DB[] = ".widget.db";
-const char QUERY_SET_DISABLE[] = "UPDATE widget_class SET is_disable = ? "
- "WHERE classid = ?";
-
-std::string GetWidgetDBPath(uid_t uid) {
- std::string path;
- if (uid == ROOT_UID || uid == GLOBALAPP_UID) {
- path = tzplatform_mkpath(TZ_SYS_DB, WIDGET_DB);
- } else {
- tzplatform_set_user(uid);
- path = tzplatform_mkpath(TZ_USER_DB, WIDGET_DB);
- tzplatform_reset_user();
- }
-
- return path;
-}
-
-int SetDisable(sqlite3* db, const char* widget_id, bool is_disable) {
- sqlite3_stmt* stmt;
- __PREPARE_V2(db, QUERY_SET_DISABLE, strlen(QUERY_SET_DISABLE),
- stmt);
- auto stmt_ptr = std::unique_ptr<sqlite3_stmt, decltype(sqlite3_finalize)*>(
- stmt, sqlite3_finalize);
-
- int idx = 1;
- __BIND_INT(db, stmt, idx++, is_disable ? 1 : 0);
- __BIND_TEXT(db, stmt, idx++, widget_id);
- __STEP(db, stmt);
- return AUL_ERROR_NONE;
-}
-
-} // namespace
-
-extern "C" API int aul_widget_service_set_usr_disable_db(const char* widget_id,
- bool is_disable, uid_t uid) {
- if (widget_id == nullptr) {
- _E("Invalid parameter");
- return AUL_ERROR_INVALID_PARAMETER;
- }
-
- std::string path = ::GetWidgetDBPath(uid);
- aul::Database db(path);
- try {
- db.Open();
- if (!db.IntegrityCheck()) {
- _E("database is corrupted");
- return AUL_ERROR_IO_ERROR;
- }
- } catch (Exception& e) {
- return AUL_ERROR_IO_ERROR;
- }
-
- db.BeginTransaction();
- int ret = ::SetDisable(db.GetHandle(), widget_id, is_disable);
- db.EndTransaction();
- return ret;
-}
-
-extern "C" API int aul_widget_service_set_disable_db(const char *widget_id,
- bool is_disable) {
- return aul_widget_service_set_usr_disable_db(widget_id, is_disable, getuid());
-}
+++ /dev/null
-/*
- * Copyright (c) 2021 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_WIDGET_SERVICE_H__
-#define __AUL_WIDGET_SERVICE_H__
-
-#include <aul_types.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int aul_widget_service_set_usr_disable_db(const char* widget_id, bool is_disable, uid_t uid);
-
-int aul_widget_service_set_disable_db(const char *widget_id, bool is_disable);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __AUL_WIDGET_SERVICE_H__ */
+++ /dev/null
-# Package Information for pkg-config
-
-prefix=@PREFIX@
-exec_prefix=@EXEC_PREFIX@
-libdir=@LIB_INSTALL_DIR@
-includedir=@INCLUDE_INSTALL_DIR@
-
-Name: libaul-server
-Description: Application Utility Libarary (Server)
-Version: @VERSION@
-Requires:
-Libs: -L${libdir} -laul-server
-Cflags: -I${includedir} -I${includedir}/aul/server
+++ /dev/null
-/*
- * Copyright (c) 2022 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 "server/boot_sequence.hh"
-
-namespace aul {
-
-BootSequence::BootSequence(std::string appid) : appid_(std::move(appid)) {}
-
-const std::string& BootSequence::GetAppId() const {
- return appid_;
-}
-
-const std::string& BootSequence::GetAfter() const {
- return after_;
-}
-
-const std::string& BootSequence::GetBefore() const {
- return before_;
-}
-
-const std::string& BootSequence::GetRequires() const {
- return requires_;
-}
-
-const std::string& BootSequence::GetConflicts() const {
- return conflicts_;
-}
-
-const std::string& BootSequence::GetArgs() const {
- return args_;
-}
-
-const std::string& BootSequence::GetVconf() const {
- return vconf_;
-}
-
-const std::string& BootSequence::GetPathExists() const {
- return path_exists_;
-}
-
-const std::string& BootSequence::GetBackgroundLaunch() const {
- return background_launch_;
-}
-
-const std::string& BootSequence::GetWaitUntilReady() const {
- return wait_until_ready_;
-}
-
-const std::string& BootSequence::GetTimeout() const {
- return timeout_;
-}
-
-void BootSequence::SetAfter(std::string after) {
- after_ = std::move(after);
-}
-
-void BootSequence::SetBefore(std::string before) {
- before_ = std::move(before);
-}
-
-void BootSequence::SetRequires(std::string requires_dep) {
- requires_ = std::move(requires_dep);
-}
-
-void BootSequence::SetConflicts(std::string conflicts) {
- conflicts_ = std::move(conflicts);
-}
-
-void BootSequence::SetArgs(std::string args) {
- args_ = std::move(args);
-}
-
-void BootSequence::SetVconf(std::string vconf) {
- vconf_ = std::move(vconf);
-}
-
-void BootSequence::SetPathExists(std::string path_exists) {
- path_exists_ = std::move(path_exists);
-}
-
-void BootSequence::SetBackgroundLaunch(std::string background_launch) {
- background_launch_ = std::move(background_launch);
-}
-
-void BootSequence::SetWaitUntilReady(std::string wait_until_ready) {
- wait_until_ready_ = std::move(wait_until_ready);
-}
-
-void BootSequence::SetTimeout(std::string timeout) {
- timeout_ = std::move(timeout);
-}
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2022 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 SERVER_BOOT_SEQUENCE_HH_
-#define SERVER_BOOT_SEQUENCE_HH_
-
-#include <string>
-
-namespace aul {
-
-class BootSequence {
- public:
- explicit BootSequence(std::string appid);
-
- const std::string& GetAppId() const;
- const std::string& GetAfter() const;
- const std::string& GetBefore() const;
- const std::string& GetRequires() const;
- const std::string& GetConflicts() const;
- const std::string& GetArgs() const;
- const std::string& GetVconf() const;
- const std::string& GetPathExists() const;
- const std::string& GetBackgroundLaunch() const;
- const std::string& GetWaitUntilReady() const;
- const std::string& GetTimeout() const;
-
- void SetAfter(std::string after);
- void SetBefore(std::string before);
- void SetRequires(std::string requires_dep);
- void SetConflicts(std::string conflicts);
- void SetArgs(std::string args);
- void SetVconf(std::string vconf);
- void SetPathExists(std::string path_exists);
- void SetBackgroundLaunch(std::string background_launch);
- void SetWaitUntilReady(std::string wait_until_ready);
- void SetTimeout(std::string timeout);
-
- private:
- std::string appid_;
- std::string after_;
- std::string before_;
- std::string requires_;
- std::string conflicts_;
- std::string args_;
- std::string vconf_;
- std::string path_exists_;
- std::string background_launch_;
- std::string wait_until_ready_;
- std::string timeout_;
-};
-
-} // namespace aul
-
-#endif // SERVER_BOOT_SEQUENCE_HH_
+++ /dev/null
-/*
- * Copyright (c) 2021 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 SERVER_COMMON_PRIVATE_HH_
-#define SERVER_COMMON_PRIVATE_HH_
-
-#include <tzplatform_config.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#undef API
-#define API __attribute__ ((visibility("default")))
-
-#undef ROOT_UID
-#define ROOT_UID 0
-
-#undef GLOBALAPP_UID
-#define GLOBALAPP_UID tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
-
-#undef REGULAR_UID_MIN
-#define REGULAR_UID_MIN 5000
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // SERVER_COMMON_PRIVATE_HH_
+++ /dev/null
-/*
- * Copyright (c) 2021 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 "server/component_info.hh"
-
-namespace aul {
-
-ComponentInfo::Builder& ComponentInfo::Builder::SetAppId(std::string app_id) {
- app_id_ = std::move(app_id);
- return *this;
-}
-
-ComponentInfo::Builder& ComponentInfo::Builder::SetCompId(std::string comp_id) {
- comp_id_ = std::move(comp_id);
- return *this;
-}
-
-ComponentInfo::Builder& ComponentInfo::Builder::SetType(std::string type) {
- type_ = std::move(type);
- return *this;
-}
-
-ComponentInfo::Builder& ComponentInfo::Builder::SetLaunchMode(
- std::string launch_mode) {
- launch_mode_ = std::move(launch_mode);
- return *this;
-}
-
-ComponentInfo::Builder& ComponentInfo::Builder::SetMainComp(
- std::string main_comp) {
- main_comp_ = std::move(main_comp);
- return *this;
-}
-
-ComponentInfo::Builder& ComponentInfo::Builder::SetIconDisplay(
- std::string icon_display) {
- icon_display_ = std::move(icon_display);
- return *this;
-}
-
-ComponentInfo::Builder& ComponentInfo::Builder::SetTaskManage(
- std::string taskmanage) {
- taskmanage_ = std::move(taskmanage);
- return *this;
-}
-
-ComponentInfo* ComponentInfo::Builder::Build() {
- return new (std::nothrow) ComponentInfo(std::move(app_id_),
- std::move(comp_id_), std::move(type_), std::move(launch_mode_),
- std::move(main_comp_), std::move(icon_display_), std::move(taskmanage_));
-}
-
-ComponentInfo::ComponentInfo(std::string app_id,
- std::string comp_id,
- std::string type,
- std::string launch_mode,
- std::string main_comp,
- std::string icon_display,
- std::string taskmanage)
- : app_id_(std::move(app_id)),
- comp_id_(std::move(comp_id)),
- type_(std::move(type)),
- launch_mode_(std::move(launch_mode)),
- main_comp_(std::move(main_comp)),
- icon_display_(std::move(icon_display)),
- taskmanage_(std::move(taskmanage)) {
-}
-
-const std::string& ComponentInfo::GetAppId() const {
- return app_id_;
-}
-
-const std::string& ComponentInfo::GetCompId() const {
- return comp_id_;
-}
-
-const std::string& ComponentInfo::GetType() const {
- return type_;
-}
-
-const std::string& ComponentInfo::GetLaunchMode() const {
- return launch_mode_;
-}
-
-const std::string& ComponentInfo::GetMainComp() const {
- return main_comp_;
-}
-
-const std::string& ComponentInfo::GetIconDisplay() const {
- return icon_display_;
-}
-
-const std::string& ComponentInfo::GetTaskManage() const {
- return taskmanage_;
-}
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2021 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 SERVER_COMPONENT_INFO_HH_
-#define SERVER_COMPONENT_INFO_HH_
-
-#include <string>
-
-namespace aul {
-
-class ComponentInfo {
- public:
- class Builder {
- public:
- Builder& SetAppId(std::string app_id);
- Builder& SetCompId(std::string comp_id);
- Builder& SetType(std::string type);
- Builder& SetLaunchMode(std::string launch_mode);
- Builder& SetMainComp(std::string main_comp);
- Builder& SetIconDisplay(std::string icon_display);
- Builder& SetTaskManage(std::string taskmanage);
- ComponentInfo* Build();
-
- private:
- std::string app_id_;
- std::string comp_id_;
- std::string type_;
- std::string launch_mode_;
- std::string main_comp_;
- std::string icon_display_;
- std::string taskmanage_;
- };
-
- ComponentInfo(std::string app_id,
- std::string comp_id,
- std::string type,
- std::string launch_mode,
- std::string main_comp,
- std::string icon_display,
- std::string taskmanage);
-
- const std::string& GetAppId() const;
- const std::string& GetCompId() const;
- const std::string& GetType() const;
- const std::string& GetLaunchMode() const;
- const std::string& GetMainComp() const;
- const std::string& GetIconDisplay() const;
- const std::string& GetTaskManage() const;
-
- private:
- std::string app_id_;
- std::string comp_id_;
- std::string type_;
- std::string launch_mode_;
- std::string main_comp_;
- std::string icon_display_;
- std::string taskmanage_;
-};
-
-} // namespace aul
-
-#endif // SERVER_COMPONENT_INFO_HH_
+++ /dev/null
-/*
- * Copyright (c) 2021 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 <unistd.h>
-
-#include <memory>
-
-#include "server/common_private.hh"
-#include "server/database.hh"
-#include "server/exception.hh"
-#include "server/log_private.hh"
-
-namespace aul {
-namespace {
-
-const int BUSY_WAITING_USEC = 50000;
-const int BUSY_WAITING_MAX = 40;
-
-} // namespace
-
-Database::Database(std::string path, bool enable_foreign_keys)
- : path_(std::move(path)),
- enable_foreign_keys_(enable_foreign_keys) {
-}
-
-Database::~Database() {
- Close();
-}
-
-void Database::BeginTransaction() {
- int ret = sqlite3_exec(db_, "BEGIN TRANSACTION", nullptr, nullptr, nullptr);
- if (ret != SQLITE_OK)
- _E("sqlite3_exec() is failed. error(%s:%d)", sqlite3_errmsg(db_), ret);
-}
-
-void Database::EndTransaction() {
- int ret = sqlite3_exec(db_, "END TRANSACTION", nullptr, nullptr, nullptr);
- if (ret != SQLITE_OK)
- _E("sqlite3_exec() is failed. error(%s:%d)", sqlite3_errmsg(db_), ret);
-}
-
-void Database::Rollback() {
- int ret = sqlite3_exec(db_, "ROLLBACK", nullptr, nullptr, nullptr);
- if (ret != SQLITE_OK)
- _E("sqlite3_exec() is failed. error(%s:%d", sqlite3_errmsg(db_), ret);
-}
-
-void Database::Open(int flags) {
- sqlite3* db;
- int ret = sqlite3_open_v2(path_.c_str(), &db, flags, nullptr);
- if (ret != SQLITE_OK) {
- _E("sqlite3_open_v2() is failed. path(%s), error(%d)", path_.c_str(), ret);
- THROW(-ret);
- }
-
- ret = sqlite3_busy_handler(db, BusyHandler,
- static_cast<void*>(const_cast<char*>(path_.c_str())));
- if (ret != SQLITE_OK) {
- _E("sqlite3_busy_handler() is failed. error(%s:%d)",
- sqlite3_errmsg(db), ret);
- sqlite3_close_v2(db);
- THROW(-ret);
- }
-
- if (enable_foreign_keys_) {
- ret = sqlite3_exec(db, "PRAGMA foreign_keys=ON", nullptr, nullptr, nullptr);
- if (ret != SQLITE_OK) {
- _E("sqlite3_exec() is failed. error(%s:%d)", sqlite3_errmsg(db), ret);
- sqlite3_close_v2(db);
- THROW(-ret);
- }
- }
-
- db_ = db;
-}
-
-void Database::Close() {
- if (db_) {
- sqlite3_close_v2(db_);
- db_ = nullptr;
- }
-}
-
-sqlite3* Database::GetHandle() {
- return db_;
-}
-
-std::string Database::ColumnText(sqlite3_stmt* stmt, int index) {
- auto* text = reinterpret_cast<const char*>(sqlite3_column_text(stmt, index));
- if (text)
- return std::string(text);
-
- return {};
-}
-
-bool Database::IntegrityCheck() {
- static const char query[] = "PRAGMA integrity_check";
- sqlite3_stmt* stmt;
- int ret = sqlite3_prepare_v2(db_, query, strlen(query), &stmt, nullptr);
- if (ret != SQLITE_OK) {
- _E("sqlite3_prepare_v2() is failed. error(%s:%d)",
- sqlite3_errmsg(db_), ret);
- return false;
- }
-
- std::unique_ptr<sqlite3_stmt, decltype(sqlite3_finalize)*> stmt_ptr(
- stmt, sqlite3_finalize);
-
- ret = sqlite3_step(stmt);
- if (ret != SQLITE_ROW) {
- _E("sqlite3_step() is failed. error(%s:%d)", sqlite3_errmsg(db_), ret);
- return false;
- }
-
- auto* res = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0));
- if (res == nullptr) {
- _E("sqlite3_column_text() is failed. error(%s)", sqlite3_errmsg(db_));
- return false;
- }
-
- if (strcmp(res, "ok") != 0)
- return false;
-
- return true;
-}
-
-std::string Database::GetPath(const std::string& name, uid_t uid) {
- std::string path = std::string(tzplatform_getenv(TZ_SYS_DB)) + "/";
- if (uid >= REGULAR_UID_MIN)
- path += "user/" + std::to_string(uid) + "/";
-
- path += name;
- return path;
-}
-
-int Database::BusyHandler(void* data, int count) {
- if (count < BUSY_WAITING_MAX) {
- usleep(BUSY_WAITING_USEC);
- return 1;
- }
-
- auto* path = static_cast<char*>(data);
- _E("Database(%s) is busy", path);
- return 0;
-}
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2021 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 SERVER_DATABASE_HH_
-#define SERVER_DATABASE_HH_
-
-#include <sqlite3.h>
-
-#include <memory>
-#include <string>
-
-#include "exception.hh"
-
-#define __PREPARE_V2(db, query, length, stmt) do { \
- int ret = sqlite3_prepare_v2(db, query, length, &stmt, nullptr); \
- if (ret != SQLITE_OK) { \
- _E("sqlite3_prepare_v2() is failed. error(%s:%d)", \
- sqlite3_errmsg(db), ret); \
- return -1; \
- } \
-} while (0)
-
-#define __BIND_INT(db, stmt, i, val) do { \
- if (sqlite3_bind_int(stmt, i, val) != SQLITE_OK) { \
- _E("sqlite3_bind_int() is failed. index(%d), error(%s)", \
- i, sqlite3_errmsg(db)); \
- return -1; \
- } \
-} while (0)
-
-#define __BIND_TEXT(db, stmt, i, text) do { \
- int ret = sqlite3_bind_text(stmt, i, text, -1, SQLITE_TRANSIENT); \
- if (ret != SQLITE_OK) { \
- _E("sqlite3_bind_text() is failed. index(%d), error(%s:%d)", \
- i, sqlite3_errmsg(db), ret); \
- return -1; \
- } \
-} while (0)
-
-#define __STEP(db, stmt) do { \
- int ret = sqlite3_step(stmt); \
- if (ret != SQLITE_DONE) { \
- _E("sqlite3_step() is failed. error(%s:%d)", sqlite3_errmsg(db), ret); \
- return -1; \
- } \
-} while (0)
-
-#define JOURNAL_MODE_WAL "WAL"
-
-#define JOURNAL_MODE_PERSIST "PERSIST"
-
-#define JOURNAL_MODE_MEMORY "MEMORY"
-
-namespace aul {
-
-class Database {
- public:
- explicit Database(std::string path, bool enable_foreign_keys = true);
- virtual ~Database();
-
- void Open(int flags = SQLITE_OPEN_READWRITE);
- void Close();
- bool IntegrityCheck();
- void BeginTransaction();
- void EndTransaction();
- void Rollback();
- sqlite3* GetHandle();
-
- static std::string ColumnText(sqlite3_stmt* stmt, int index);
- static std::string GetPath(const std::string& name, uid_t uid);
-
- private:
- static int BusyHandler(void* data, int count);
-
- private:
- std::string path_;
- bool enable_foreign_keys_;
- sqlite3* db_ = nullptr;
-};
-
-} // namespace aul
-
-#endif // SERVER_DATABASE_HH_
+++ /dev/null
-/*
- * Copyright (c) 2021 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 "server/exception.hh"
-
-#include <libgen.h>
-
-namespace aul {
-
-Exception::Exception(int error_code, std::string file, int line)
- : error_code_(error_code) {
- message_ = std::string(basename(const_cast<char*>(file.c_str()))) + ":" +
- std::to_string(line) + " code:" + std::to_string(error_code_);
-}
-
-const char* Exception::what() const noexcept {
- return message_.c_str();
-}
-
-int Exception::GetErrorCode() {
- return error_code_;
-}
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2021 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 SERVER_EXCEPTION_HH_
-#define SERVER_EXCEPTION_HH_
-
-#include <string>
-#include <exception>
-
-#define THROW(error_code) throw Exception(error_code, __FILE__, __LINE__)
-
-namespace aul {
-
-class Exception : public std::exception {
- public:
- explicit Exception(int error_code, std::string file, int line);
- virtual ~Exception() = default;
-
- virtual const char* what() const noexcept;
- int GetErrorCode();
-
- private:
- int error_code_;
- std::string message_;
-};
-
-} // namespace aul
-
-#endif // SERVER_EXCEPTION_HH_
+++ /dev/null
-/*
- * Copyright (c) 2021 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 "server/localized_info.hh"
-
-namespace aul {
-
-LocalizedInfo::Builder& LocalizedInfo::Builder::SetLocale(std::string locale) {
- locale_ = std::move(locale);
- return *this;
-}
-
-LocalizedInfo::Builder& LocalizedInfo::Builder::SetIcon(std::string icon) {
- icon_ = std::move(icon);
- return *this;
-}
-
-LocalizedInfo::Builder& LocalizedInfo::Builder::SetLabel(std::string label) {
- label_ = std::move(label);
- return *this;
-}
-
-LocalizedInfo* LocalizedInfo::Builder::Build() {
- return new (std::nothrow) LocalizedInfo(std::move(locale_), std::move(icon_),
- std::move(label_));
-}
-
-LocalizedInfo::LocalizedInfo(std::string locale,
- std::string icon,
- std::string label)
- : locale_(std::move(locale)),
- icon_(std::move(icon)),
- label_(std::move(label)) {
-}
-
-const std::string& LocalizedInfo::GetLocale() const {
- return locale_;
-}
-
-const std::string& LocalizedInfo::GetIcon() const {
- return icon_;
-}
-
-const std::string& LocalizedInfo::GetLabel() const {
- return label_;
-}
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2021 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 SERVER_LOCALIZED_INFO_HH_
-#define SERVER_LOCALIZED_INFO_HH_
-
-#include <string>
-
-namespace aul {
-
-class LocalizedInfo {
- public:
- class Builder {
- public:
- Builder& SetLocale(std::string locale);
- Builder& SetIcon(std::string icon);
- Builder& SetLabel(std::string label);
- LocalizedInfo* Build();
-
- private:
- std::string locale_;
- std::string icon_;
- std::string label_;
- };
-
- LocalizedInfo(std::string locale, std::string icon, std::string label);
- const std::string& GetLocale() const;
- const std::string& GetIcon() const;
- const std::string& GetLabel() const;
-
- private:
- std::string locale_;
- std::string icon_;
- std::string label_;
-};
-
-} // namespace aul
-
-#endif // SERVER_LOCALIZED_INFO_HH_
+++ /dev/null
-/*
- * Copyright (c) 2021 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 SERVER_LOG_PRIVATE_HH_
-#define SERVER_LOG_PRIVATE_HH_
-
-#include <dlog.h>
-
-#undef LOG_TAG
-#define LOG_TAG "AUL"
-
-#undef _E
-#define _E LOGE
-
-#undef _W
-#define _W LOGW
-
-#undef _I
-#define _I LOGI
-
-#undef _D
-#define _D LOGD
-
-#endif // SERVER_LOG_PRIVATE_HH_
--- /dev/null
+ADD_SUBDIRECTORY(aul)
+ADD_SUBDIRECTORY(parser)
+ADD_SUBDIRECTORY(server)
+ADD_SUBDIRECTORY(tool)
+++ /dev/null
-/*
- * Copyright (c) 2015 - 2022 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul_app_com.h"
-
-#include <bundle_cpp.h>
-#include <bundle_internal.h>
-
-#include <list>
-#include <mutex>
-#include <string>
-
-#include "app_request.h"
-#include "aul_api.h"
-#include "aul_util.h"
-#include "include/aul.h"
-#include "include/aul_cmd.h"
-#include "launch.h"
-
-using namespace aul::internal;
-
-namespace {
-
-class AppComConnection {
- public:
- AppComConnection(std::string endpoint, app_com_cb cb, void* user_data)
- : endpoint_(std::move(endpoint)),
- cb_(cb),
- user_data_(user_data) {
- }
-
- ~AppComConnection() = default;
-
- const std::string& GetEndpoint() const {
- return endpoint_;
- }
-
- void Disable() {
- disabled_ = true;
- }
-
- bool IsDisabled() const {
- return disabled_;
- }
-
- void Invoke(aul_app_com_result_e result, bundle* envelope) {
- if (!disabled_ && cb_)
- cb_(endpoint_.c_str(), result, envelope, user_data_);
- }
-
- private:
- bool disabled_ = false;
- std::string endpoint_;
- app_com_cb cb_;
- void* user_data_;
-};
-
-class AppComPermission {
- public:
- AppComPermission() : option_(AUL_APP_COM_PUBLIC) {}
- ~AppComPermission() {}
-
- void SetPrivilege(std::string privilege) {
- privilege_ = std::move(privilege);
- }
-
- void SetPropagationOption(aul_app_com_propagate_option_e option) {
- option_ = option;
- }
-
- const std::string& GetPrivilege() const {
- return privilege_;
- }
-
- aul_app_com_propagate_option_e GetPropagationOption() const {
- return option_;
- }
-
- private:
- std::string privilege_;
- aul_app_com_propagate_option_e option_;
-};
-
-class Context {
- public:
- Context() {}
- ~Context() {}
-
- int Receive(bundle* b) {
- const char* val = bundle_get_val(b, AUL_K_COM_ENDPOINT);
- if (val == nullptr)
- return -1;
-
- size_t result_size = 0;
- aul_app_com_result_e* result = nullptr;
- int ret = bundle_get_byte(b, AUL_K_COM_RESULT,
- reinterpret_cast<void**>(&result), &result_size);
- if (ret != BUNDLE_ERROR_NONE)
- return -1;
-
- std::string endpoint(val);
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
- auto iter = conns_.begin();
- while (iter != conns_.end()) {
- auto& conn = *iter;
- iter++;
- if (conn->GetEndpoint() == endpoint)
- conn->Invoke(*result, b);
- }
-
- return 0;
- }
-
- AppComConnection* AddConnection(std::string endpoint, app_com_cb cb,
- void* user_data) {
- auto* conn = new (std::nothrow) AppComConnection(endpoint, cb, user_data);
- if (conn == nullptr)
- return nullptr;
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
- conns_.emplace_back(conn);
- return conn;
- }
-
- void RemoveConnection(AppComConnection* conn) {
- std::lock_guard<std::recursive_mutex> lock(mutex_);
- auto iter = conns_.begin();
- while (iter != conns_.end()) {
- if ((*iter).get() == conn) {
- iter = conns_.erase(iter);
- break;
- } else {
- iter++;
- }
- }
- }
-
- bool ExistConnection(const std::string& endpoint) {
- std::lock_guard<std::recursive_mutex> lock(mutex_);
- for (auto& conn : conns_) {
- if (conn->GetEndpoint() == endpoint && !conn->IsDisabled())
- return true;
- }
-
- return false;
- }
-
- bool ExistConnection(AppComConnection* conn) {
- std::lock_guard<std::recursive_mutex> lock(mutex_);
- if (conn->IsDisabled())
- return false;
-
- for (auto& i : conns_) {
- if (i.get() == conn)
- return true;
- }
-
- return false;
- }
-
- std::recursive_mutex& GetMutex() const {
- return mutex_;
- }
-
- private:
- std::list<std::unique_ptr<AppComConnection>> conns_;
- mutable std::recursive_mutex mutex_;
-};
-
-Context context;
-
-int AppComCreate(const char* endpoint,
- aul_app_com_permission_h permission, app_com_cb callback, void* user_data,
- bool sync, aul_app_com_connection_h* connection) {
- if (endpoint == nullptr || callback == nullptr || connection == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- if (!aul_is_initialized()) {
- if (aul_launch_init(nullptr, nullptr) < 0)
- return AUL_R_ENOINIT;
- }
-
- tizen_base::Bundle b { { AUL_K_COM_ENDPOINT, endpoint } };
- if (permission) {
- auto* handle = static_cast<AppComPermission*>(permission);
- auto option = handle->GetPropagationOption();
- if (option) {
- auto* p = reinterpret_cast<unsigned char*>(&option);
- std::vector<unsigned char> bytes;
- std::copy(p, p + sizeof(option), std::back_inserter(bytes));
- b.Add(AUL_K_COM_PROPAGATE, bytes);
- }
-
- if (!handle->GetPrivilege().empty())
- b.Add(AUL_K_COM_PRIVILEGE, handle->GetPrivilege());
- }
-
- int ret = AppRequest(APP_COM_CREATE, getuid())
- .With(std::move(b))
- .SendSimply(sync ? AUL_SOCK_NONE : AUL_SOCK_NOREPLY);
- if (ret == 0) {
- *connection = static_cast<aul_app_com_connection_h>(
- context.AddConnection(endpoint, callback, user_data));
- }
-
- return ret;
-}
-
-} // namespace
-
-int app_com_recv(bundle* b) {
- if (b == nullptr)
- return -1;
-
- return context.Receive(b);
-}
-
-extern "C" API aul_app_com_permission_h aul_app_com_permission_create() {
- auto* handle = new (std::nothrow) AppComPermission();
- return static_cast<aul_app_com_permission_h>(handle);
-}
-
-extern "C" API void aul_app_com_permission_destroy(
- aul_app_com_permission_h permission) {
- if (permission == nullptr)
- return;
-
- auto* handle = static_cast<AppComPermission*>(permission);
- delete handle;
-}
-
-extern "C" API int aul_app_com_permission_set_propagation(
- aul_app_com_permission_h permission,
- aul_app_com_propagate_option_e option) {
- if (permission == nullptr)
- return AUL_R_EINVAL;
-
- auto* handle = static_cast<AppComPermission*>(permission);
- handle->SetPropagationOption(option);
- return AUL_R_OK;
-}
-
-extern "C" API int aul_app_com_permission_set_privilege(
- aul_app_com_permission_h permission, const char* privilege) {
- if (permission == nullptr || privilege == nullptr)
- return AUL_R_EINVAL;
-
- auto* handle = static_cast<AppComPermission*>(permission);
- handle->SetPrivilege(privilege);
- return AUL_R_OK;
-}
-
-extern "C" API int aul_app_com_create(const char* endpoint,
- aul_app_com_permission_h permission, app_com_cb callback,
- void* user_data, aul_app_com_connection_h* connection) {
- return AppComCreate(endpoint, permission, callback, user_data,
- true, connection);
-}
-
-extern "C" API int aul_app_com_create_async(const char* endpoint,
- aul_app_com_permission_h permission, app_com_cb callback,
- void* user_data, aul_app_com_connection_h* connection) {
- return AppComCreate(endpoint, permission, callback, user_data,
- false, connection);
-}
-
-extern "C" API int aul_app_com_join(const char* endpoint, const char* filter,
- app_com_cb callback, void* user_data,
- aul_app_com_connection_h* connection) {
- if (endpoint == nullptr || callback == nullptr || connection == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- if (!aul_is_initialized()) {
- if (aul_launch_init(nullptr, nullptr) < 0)
- return AUL_R_ENOINIT;
- }
-
- tizen_base::Bundle b { { AUL_K_COM_ENDPOINT, endpoint } };
- if (filter)
- b.Add(AUL_K_COM_FILTER, filter);
-
- int ret = AppRequest(APP_COM_JOIN, getuid())
- .With(std::move(b))
- .SendSimply();
- if (ret == 0) {
- *connection = static_cast<aul_app_com_connection_h>(
- context.AddConnection(endpoint, callback, user_data));
- }
-
- return ret;
-}
-
-extern "C" API int aul_app_com_send(const char* endpoint, bundle* envelope) {
- if (endpoint == nullptr || envelope == nullptr)
- return AUL_R_EINVAL;
-
- std::string com_endpoint;
- tizen_base::Bundle b(envelope, false, false);
- bundle_type type = b.GetType(AUL_K_COM_ENDPOINT);
- if (type != BUNDLE_TYPE_NONE) {
- com_endpoint = b.GetString(AUL_K_COM_ENDPOINT);
- b.Delete(AUL_K_COM_ENDPOINT);
- }
-
- b.Add(AUL_K_COM_ENDPOINT, endpoint);
-
- int ret = AppRequest(APP_COM_SEND, getuid())
- .With(std::move(b))
- .SendSimply();
- if (type != BUNDLE_TYPE_NONE) {
- bundle_del(envelope, AUL_K_COM_ENDPOINT);
- bundle_add_str(envelope, AUL_K_COM_ENDPOINT, com_endpoint.c_str());
- }
-
- return ret;
-}
-
-extern "C" API int aul_app_com_leave(aul_app_com_connection_h connection) {
- if (connection == nullptr)
- return AUL_R_EINVAL;
-
- auto* conn = static_cast<AppComConnection*>(connection);
- if (!context.ExistConnection(conn)) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- std::lock_guard<std::recursive_mutex> lock(context.GetMutex());
- conn->Disable();
-
- std::string endpoint = conn->GetEndpoint();
- if (!context.ExistConnection(endpoint)) {
- tizen_base::Bundle b { { AUL_K_COM_ENDPOINT, endpoint } };
- int ret = AppRequest(APP_COM_LEAVE, getuid())
- .With(std::move(b))
- .SendSimply(AUL_SOCK_NOREPLY);
- if (ret != 0)
- _E("Failed to send leave request. error(%d)", ret);
- }
-
- g_idle_add_full(G_PRIORITY_HIGH, [](gpointer user_data) -> gboolean {
- auto* conn = static_cast<AppComConnection*>(user_data);
- std::lock_guard<std::recursive_mutex> lock(context.GetMutex());
- context.RemoveConnection(conn);
- return G_SOURCE_REMOVE;
- }, connection, nullptr);
-
- return AUL_R_OK;
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 - 2022 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul_app_group.h"
-
-#include <bundle_cpp.h>
-
-#include <memory>
-#include <string>
-#include <vector>
-
-#include "app_request.h"
-#include "aul_api.h"
-#include "aul_util.h"
-#include "include/aul.h"
-#include "include/aul_error.h"
-#include "include/aul_sock.h"
-#include "launch.h"
-
-#include "aul/app_group/app_group_info.hh"
-#include "aul/common/exception.hh"
-
-using namespace aul;
-using namespace aul::internal;
-
-struct aul_app_group_info_s {
- void* dummy;
-};
-
-namespace {
-
-constexpr const int kMaxPacketLength = AUL_SOCK_MAXBUFF - AUL_PKT_HEADER_SIZE;
-
-AppGroupInfo* CreateAppGroupInfo(const tizen_base::Bundle& b) {
- return AppGroupInfo::Builder()
- .SetId(b)
- .SetPid(b)
- .SetAppId(b)
- .SetPkgId(b)
- .SetWid(b)
- .SetFg(b)
- .SetStatus(b);
-}
-
-std::vector<std::shared_ptr<AppGroupInfo>> ReceiveAppGroupInfos(int fd) {
- std::vector<std::shared_ptr<AppGroupInfo>> infos;
- int ret = aul_sock_recv_pkt_with_cb(fd,
- [](app_pkt_t* pkt, void* user_data) {
- if (pkt->cmd == APP_GET_INFO_ERROR || !(pkt->opt & AUL_SOCK_BUNDLE))
- return;
-
- bundle* kb = bundle_decode(pkt->data, pkt->len);
- if (kb == nullptr) {
- _E("bundle_decode() is failed");
- return;
- }
-
- tizen_base::Bundle b(kb, false, true);
- try {
- auto* info = CreateAppGroupInfo(b);
- if (info == nullptr) {
- _E("Out of memory");
- return;
- }
-
- auto* info_array =
- static_cast<std::vector<std::shared_ptr<AppGroupInfo>>*>(
- user_data);
- info_array->emplace_back(info);
- } catch (const Exception& e) {
- _E("Exception occurs. error(%s)", e.what());
- }
- }, &infos);
- if (ret < 0)
- THROW(aul_error_convert(ret));
-
- return infos;
-}
-
-std::vector<std::string> ReceiveLeaderIds(int fd) {
- app_pkt_t* pkt = nullptr;
- int ret = aul_sock_recv_reply_pkt(fd, &pkt);
- if (ret < 0 || pkt == nullptr)
- THROW(AUL_R_ERROR);
-
- auto pkt_auto = std::unique_ptr<app_pkt_t, decltype(std::free)*>(
- pkt, std::free);
-
- bundle* kb = bundle_decode(pkt->data, pkt->len);
- if (kb == nullptr) {
- _E("bundle_decode() is failed. data(%s:%d)", pkt->data, pkt->len);
- THROW(AUL_R_ERROR);
- }
-
- tizen_base::Bundle b(kb, false, true);
- return b.GetStringArray(AUL_K_LEADER_IDS);
-}
-
-void ReceivePids(int fd, int* cnt, int** pids) {
- app_pkt_t* pkt = nullptr;
- int ret = aul_sock_recv_reply_pkt(fd, &pkt);
- if (ret < 0 || pkt == nullptr)
- THROW(AUL_R_ERROR);
-
- auto pkt_auto = std::unique_ptr<app_pkt_t, decltype(std::free)*>(
- pkt, std::free);
-
- int count = pkt->len / sizeof(int);
- if (count > 0 && pkt->len <= kMaxPacketLength) {
- *pids = reinterpret_cast<int*>(calloc(1, pkt->len));
- if (*pids == nullptr) {
- _E("Out of memory");
- THROW(AUL_R_ENOMEM);
- }
-
- memcpy(*pids, pkt->data, pkt->len);
- *cnt = count;
- }
-}
-
-} // namespace
-
-extern "C" API int aul_app_group_get_window(int pid) {
- if (pid < 1) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- return AppRequest(APP_GROUP_GET_WINDOW, getuid())
- .SetPid(pid)
- .SendSimply();
-}
-
-extern "C" API int aul_app_group_set_window(int wid) {
- if (wid < 1) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- tizen_base::Bundle b { { AUL_K_WID, std::to_string(wid) } };
- return AppRequest(APP_GROUP_SET_WINDOW, getuid())
- .With(std::move(b))
- .SendSimply(AUL_SOCK_NOREPLY);
-}
-
-extern "C" API void aul_app_group_get_leader_pids(int* cnt, int** pids) {
- if (cnt == nullptr || pids == nullptr) {
- _E("Invalid parameter");
- return;
- }
-
- *cnt = 0;
- *pids = nullptr;
-
- int fd = AppRequest(APP_GROUP_GET_LEADER_PIDS, getuid())
- .SendCmdOnly(AUL_SOCK_ASYNC);
- if (fd < 0)
- return;
-
- try {
- ReceivePids(fd, cnt, pids);
- } catch (const Exception& e) {
- _E("Exception occurs. error(%s)", e.what());
- }
-}
-
-extern "C" API void aul_app_group_get_group_pids(int leader_pid, int* cnt,
- int** pids) {
- if (leader_pid < 1 || cnt == nullptr || pids == nullptr) {
- _E("Invalid parameter");
- return;
- }
-
- *cnt = 0;
- *pids = nullptr;
-
- tizen_base::Bundle b { { AUL_K_LEADER_PID, std::to_string(leader_pid) } };
- int fd = AppRequest(APP_GROUP_GET_GROUP_PIDS, getuid())
- .With(std::move(b))
- .SendSimply(AUL_SOCK_ASYNC);
- if (fd < 0)
- return;
-
- try {
- ReceivePids(fd, cnt, pids);
- } catch (const Exception& e) {
- _E("Exception occurs. error(%s)", e.what());
- }
-}
-
-extern "C" API int aul_app_group_get_leader_pid(int pid) {
- if (pid < 1) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- return AppRequest(APP_GROUP_GET_LEADER_PID, getuid())
- .SetPid(pid)
- .SendSimply();
-}
-
-extern "C" API int aul_app_group_clear_top(void) {
- return AppRequest(APP_GROUP_CLEAR_TOP, getuid())
- .SendCmdOnly();
-}
-
-extern "C" API int aul_app_group_is_top(void) {
- int leader_pid = aul_app_group_get_leader_pid(getpid());
- if (leader_pid < 1)
- return 1;
-
- int cnt = 0;
- int* pids = nullptr;
- aul_app_group_get_group_pids(leader_pid, &cnt, &pids);
- auto pids_auto = std::unique_ptr<int, decltype(std::free)*>(pids, std::free);
- if (cnt > 0 && pids != nullptr) {
- if (pids[cnt - 1] == getpid())
- return 1;
-
- return 0;
- }
-
- return 1;
-}
-
-extern "C" API int aul_app_group_get_fg_flag(int pid) {
- if (pid < 1) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- return AppRequest(APP_GROUP_GET_FG, getuid())
- .SetPid(pid)
- .SendSimply();
-}
-
-extern "C" API void aul_app_group_lower(int* exit) {
- if (exit == nullptr) {
- _E("Invalid parameter");
- return;
- }
-
- int ret = AppRequest(APP_GROUP_LOWER, getuid())
- .SendCmdOnly();
- if (ret < 0)
- return;
-
- *exit = ret;
-}
-
-extern "C" API void aul_app_group_get_idle_pids(int* cnt, int** pids) {
- if (cnt == nullptr || pids == nullptr) {
- _E("Invalid parameter");
- return;
- }
-
- *cnt = 0;
- *pids = nullptr;
- int fd = AppRequest(APP_GROUP_GET_IDLE_PIDS, getuid())
- .SendCmdOnly(AUL_SOCK_ASYNC);
- if (fd < 0)
- return;
-
- try {
- ReceivePids(fd, cnt, pids);
- } catch (const Exception& e) {
- _E("Exception occurs. error(%s)", e.what());
- }
-}
-
-extern "C" API int aul_app_group_activate_below(const char* below_appid) {
- if (below_appid == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- return AppRequest(APP_GROUP_ACTIVATE_BELOW, getuid())
- .SetAppId(below_appid)
- .SendSimply();
-}
-
-extern "C" API int aul_app_group_activate_above(const char* above_appid) {
- if (above_appid == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- return AppRequest(APP_GROUP_ACTIVATE_ABOVE, getuid())
- .SetAppId(above_appid)
- .SendSimply();
-}
-
-extern "C" API int aul_app_group_set_window_v2(const char* inst_id, int wid) {
- if (inst_id == nullptr || wid < 1) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- tizen_base::Bundle b {
- { AUL_K_INSTANCE_ID, inst_id },
- { AUL_K_WID, std::to_string(wid) }
- };
-
- return AppRequest(APP_GROUP_SET_WINDOW_V2, getuid())
- .With(std::move(b))
- .SendSimply(AUL_SOCK_NOREPLY);
-}
-
-extern "C" API int aul_app_group_lower_v2(const char* inst_id, bool* exit) {
- if (inst_id == nullptr || exit == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- int ret = AppRequest(APP_GROUP_LOWER_V2, getuid())
- .SetInstId(inst_id)
- .SendSimply();
- if (ret < 0)
- return ret;
-
- *exit = (ret == 0) ? false : true;
- return AUL_R_OK;
-}
-
-extern "C" API int aul_app_group_foreach_leader_ids(
- aul_app_group_leader_id_cb callback, void* user_data) {
- if (callback == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- int fd = AppRequest(APP_GROUP_GET_LEADER_IDS, getuid())
- .SendCmdOnly(AUL_SOCK_ASYNC);
- if (fd < 0)
- return aul_error_convert(fd);
-
- try {
- for (auto const& id : ReceiveLeaderIds(fd))
- callback(id.c_str(), user_data);
- } catch (const Exception& e) {
- _E("Exception occurs. error(%s)", e.what());
- return e.GetErrorCode();
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_app_group_foreach_group_info(const char* leader_id,
- aul_app_group_info_cb callback, void* user_data) {
- if (leader_id == nullptr || callback == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- tizen_base::Bundle b { { AUL_K_LEADER_ID, leader_id } };
- int fd = AppRequest(APP_GROUP_GET_GROUP_INFO, getuid())
- .With(std::move(b))
- .SendSimply(AUL_SOCK_ASYNC);
- if (fd < 0)
- return aul_error_convert(fd);
-
- try {
- for (auto const& info : ReceiveAppGroupInfos(fd))
- callback(reinterpret_cast<aul_app_group_info_h>(info.get()), user_data);
- } catch (const Exception& e) {
- _E("Exception occurs. error(%s)", e.what());
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_app_group_foreach_idle_info(
- aul_app_group_info_cb callback, void* user_data) {
- if (callback == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- int fd = AppRequest(APP_GROUP_GET_IDLE_INFO, getuid())
- .SendCmdOnly(AUL_SOCK_ASYNC);
- if (fd < 0)
- return aul_error_convert(fd);
-
- try {
- for (auto const& info : ReceiveAppGroupInfos(fd))
- callback(reinterpret_cast<aul_app_group_info_h>(info.get()), user_data);
- } catch (const Exception& e) {
- _E("Exception occurs. error(%s)", e.what());
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_app_group_info_get_id(aul_app_group_info_h h,
- const char** id) {
- if (h == nullptr || id == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* info = reinterpret_cast<AppGroupInfo*>(h);
- *id = info->GetId().c_str();
- return AUL_R_OK;
-}
-
-extern "C" API int aul_app_group_info_get_pid(aul_app_group_info_h h,
- pid_t* pid) {
- if (h == nullptr || pid == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* info = reinterpret_cast<AppGroupInfo*>(h);
- *pid = info->GetPid();
- return AUL_R_OK;
-}
-
-extern "C" API int aul_app_group_info_get_appid(aul_app_group_info_h h,
- const char** appid) {
- if (h == nullptr || appid == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* info = reinterpret_cast<AppGroupInfo*>(h);
- *appid = info->GetAppId().c_str();
- return AUL_R_OK;
-}
-
-extern "C" API int aul_app_group_info_get_pkgid(aul_app_group_info_h h,
- const char** pkgid) {
- if (h == nullptr || pkgid == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* info = reinterpret_cast<AppGroupInfo*>(h);
- *pkgid = info->GetPkgId().c_str();
- return AUL_R_OK;
-}
-
-extern "C" API int aul_app_group_info_get_window(aul_app_group_info_h h,
- int* wid) {
- if (h == nullptr || wid == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* info = reinterpret_cast<AppGroupInfo*>(h);
- *wid = info->GetWid();
- return AUL_R_OK;
-}
-
-extern "C" API int aul_app_group_info_get_fg_flag(aul_app_group_info_h h,
- bool* fg_flag) {
- if (h == nullptr || fg_flag == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* info = reinterpret_cast<AppGroupInfo*>(h);
- *fg_flag = info->IsFg();
- return AUL_R_OK;
-}
-
-extern "C" API int aul_app_group_info_get_status(aul_app_group_info_h h,
- int* status) {
- if (h == nullptr || status == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* info = reinterpret_cast<AppGroupInfo*>(h);
- *status = info->GetStatus();
- return AUL_R_OK;
-}
-
-extern "C" API int aul_app_group_add(int wid) {
- if (wid < 1) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- tizen_base::Bundle b { { AUL_K_WID, std::to_string(wid) } };
- return AppRequest(APP_GROUP_ADD, getuid())
- .With(std::move(b))
- .SendSimply(AUL_SOCK_NOREPLY);
-}
-
-extern "C" API int aul_app_group_remove(int wid) {
- if (wid < 1) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- tizen_base::Bundle b { { AUL_K_WID, std::to_string(wid) } };
- return AppRequest(APP_GROUP_REMOVE, getuid())
- .With(std::move(b))
- .SendSimply(AUL_SOCK_NOREPLY);
-}
+++ /dev/null
-/*
- * Copyright (c) 2021 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 "app_request.h"
-
-#include <bundle_internal.h>
-#include <ctype.h>
-#include <dirent.h>
-#include <fcntl.h>
-#include <gio/gio.h>
-#include <glib.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <ttrace.h>
-
-#include <memory>
-#include <utility>
-
-#include "aul_cmd.h"
-#include "aul_error.h"
-#include "aul_sock.h"
-#include "aul_util.h"
-#include "launch.h"
-
-namespace aul {
-namespace internal {
-
-AppRequest::AppRequest(int cmd, uid_t uid) : cmd_(cmd), uid_(uid) {
- SetUid(uid);
-}
-
-AppRequest::AppRequest(int cmd) : cmd_(cmd), uid_(getuid()) {
- SetUid(uid_);
-}
-
-AppRequest& AppRequest::With(tizen_base::Bundle b) {
- bundle_ = std::move(b);
- ClearInternalKey();
- SetUid(uid_);
- return *this;
-}
-
-AppRequest& AppRequest::With(bundle* b) {
- if (b == nullptr)
- return *this;
- bundle_ = tizen_base::Bundle(b, false, false);
- ClearInternalKey();
- SetUid(uid_);
- return *this;
-}
-
-AppRequest& AppRequest::SetAppId(const std::string& app_id) {
- bundle_.Delete(AUL_K_APPID);
- bundle_.Add(AUL_K_APPID, app_id);
- return *this;
-}
-
-AppRequest& AppRequest::SetInstId(const std::string& inst_id) {
- bundle_.Delete(AUL_K_INSTANCE_ID);
- bundle_.Add(AUL_K_INSTANCE_ID, inst_id);
- return *this;
-}
-
-AppRequest& AppRequest::SetAppIdAsPid(pid_t pid) {
- char buf[MAX_PID_STR_BUFSZ];
- snprintf(buf, sizeof(buf), "%d", pid);
- bundle_.Delete(AUL_K_APPID);
- bundle_.Add(AUL_K_APPID, buf);
- return *this;
-}
-
-AppRequest& AppRequest::SetPid(pid_t pid) {
- char buf[MAX_PID_STR_BUFSZ];
- snprintf(buf, sizeof(buf), "%d", pid);
- bundle_.Delete(AUL_K_PID);
- bundle_.Add(AUL_K_PID, buf);
- return *this;
-}
-
-int AppRequest::Send(int opt) {
- traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "AUL:REQ_TO_PAD");
- std::string appid = bundle_.GetString(AUL_K_APPID);
- _W("Request cmd(%d:%s): appid(%s), target_uid(%u)",
- cmd_, aul_cmd_convert_to_string(cmd_), appid.c_str(), uid_);
-
- SetTime();
- switch (cmd_) {
- case APP_SEND_LAUNCH_REQUEST:
- case APP_SEND_LAUNCH_REQUEST_SYNC:
- case APP_SEND_RESUME_REQUEST:
- opt |= AUL_SOCK_ASYNC;
- break;
- }
-
- int ret = aul_sock_send_bundle(AUL_UTIL_PID, uid_, cmd_,
- bundle_.GetHandle(), opt);
- if (ret < 0)
- ret = aul_error_convert(ret);
- _W("Request cmd(%d:%s): result(%d)",
- cmd_, aul_cmd_convert_to_string(cmd_), ret);
- if (ret == AUL_R_LOCAL)
- ret = app_request_local(cmd_, bundle_.GetHandle());
- traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
- return ret;
-}
-
-int AppRequest::SendSimply(int opt) {
- _W("Request cmd(%d:%s): target_uid(%u)",
- cmd_, aul_cmd_convert_to_string(cmd_), uid_);
- int ret = aul_sock_send_bundle(AUL_UTIL_PID, uid_, cmd_,
- bundle_.GetHandle(), opt);
- if (ret < 0)
- ret = aul_error_convert(ret);
- _W("Request cmd(%d:%s): result(%d)",
- cmd_, aul_cmd_convert_to_string(cmd_), ret);
- return ret;
-}
-
-int AppRequest::SendCmdOnly(int opt) {
- _W("Request cmd(%d:%s): target_uid(%u)",
- cmd_, aul_cmd_convert_to_string(cmd_), uid_);
- int ret = aul_sock_send_raw(AUL_UTIL_PID, uid_, cmd_, nullptr, 0, opt);
- _W("Request cmd(%d:%s): result(%d)",
- cmd_, aul_cmd_convert_to_string(cmd_), ret);
- return ret;
-}
-
-void AppRequest::ClearInternalKey() {
- bundle_.Delete(AUL_K_CALLER_PID);
- bundle_.Delete(AUL_K_APPID);
- bundle_.Delete(AUL_K_WAIT_RESULT);
- bundle_.Delete(AUL_K_SEND_RESULT);
- bundle_.Delete(AUL_K_ARGV0);
-}
-
-void AppRequest::SetTime() {
- struct timespec start;
- clock_gettime(CLOCK_MONOTONIC, &start);
- char tmp[MAX_LOCAL_BUFSZ];
- snprintf(tmp, sizeof(tmp), "%ld/%ld", start.tv_sec, start.tv_nsec);
- bundle_.Delete(AUL_K_STARTTIME);
- bundle_.Add(AUL_K_STARTTIME, tmp);
-}
-
-void AppRequest::SetUid(uid_t uid) {
- char buf[MAX_PID_STR_BUFSZ];
- snprintf(buf, sizeof(buf), "%d", uid);
- bundle_.Delete(AUL_K_TARGET_UID);
- bundle_.Add(AUL_K_TARGET_UID, buf);
-}
-
-} // namespace internal
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef APP_REQUEST_H_
-#define APP_REQUEST_H_
-
-#include <bundle_cpp.h>
-#include <bundle.h>
-#include <string>
-
-#include "aul.h"
-#include "aul_sock.h"
-
-namespace aul {
-namespace internal {
-
-class AppRequest {
- public:
- AppRequest(int cmd, uid_t uid);
- AppRequest(int cmd);
-
- AppRequest& With(tizen_base::Bundle b);
- AppRequest& With(bundle* b);
- AppRequest& SetAppId(const std::string& app_id);
- AppRequest& SetInstId(const std::string& inst_id);
- AppRequest& SetAppIdAsPid(pid_t pid);
- AppRequest& SetPid(pid_t pid);
- int Send(int opt = AUL_SOCK_QUEUE);
- int SendSimply(int opt = AUL_SOCK_NONE);
- int SendCmdOnly(int opt = AUL_SOCK_NONE);
-
- private:
- void ClearInternalKey();
- void SetTime();
- void SetUid(uid_t uid);
-
- private:
- int cmd_;
- uid_t uid_;
- tizen_base::Bundle bundle_;
-};
-
-} // namespace internal
-} // namespace aul
-
-#endif // APP_REQUEST_H_
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2000 - 2022 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 <gio/gio.h>
-#include <glib.h>
-
-#include <memory>
-#include <mutex>
-#include <string>
-
-#include "include/aul.h"
-#include "aul_api.h"
-
-#include "log_private.hh"
-
-namespace {
-
-constexpr const char AUL_DBUS_PATH[] = "/aul/dbus_handler";
-constexpr const char AUL_DBUS_SIGNAL_INTERFACE[] = "org.tizen.aul.signal";
-constexpr const char AUL_DBUS_APPDEAD_SIGNAL[] = "app_dead";
-constexpr const char AUL_DBUS_APPLAUNCH_SIGNAL[] = "app_launch";
-
-constexpr const char AUL_APP_STATUS_DBUS_PATH[] = "/Org/Tizen/Aul/AppStatus";
-constexpr const char AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE[] =
- "org.tizen.aul.AppStatus";
-constexpr const char AUL_APP_STATUS_DBUS_LAUNCH_REQUEST[] = "AppLaunch";
-constexpr const char AUL_APP_STATUS_DBUS_RESUME_REQUEST[] = "AppResume";
-constexpr const char AUL_APP_STATUS_DBUS_TERMINATE_REQUEST[] = "AppTerminate";
-constexpr const char AUL_APP_STATUS_DBUS_STATUS_CHANGE[] = "AppStatusChange";
-constexpr const char AUL_APP_STATUS_DBUS_GROUP[] = "AppGroup";
-constexpr const char AUL_APP_STATUS_DBUS_TERMINATED[] = "AppTerminated";
-
-constexpr const char SYSTEM_PATH_CORE[] = "/org/tizen/system";
-constexpr const char SYSTEM_INTERFACE_CORE[] = "org.tizen.system.Booting";
-constexpr const char SYSTEM_SIGNAL_BOOTING_DONE[] = "BootingDone";
-
-constexpr const char SYSTEM_PATH_THERMAL[] = "/Org/Tizen/System/Thermal";
-constexpr const char SYSTEM_INTERFACE_THERMAL[] = "org.tizen.system.thermal";
-constexpr const char SYSTEM_SIGNAL_COOLDOWN_MODE_CHANGED[] =
- "CoolDownModeChanged";
-
-constexpr const char RESOURCED_BUS_NAME[] = "org.tizen.resourced";
-constexpr const char RESOURCED_PROC_PATH[] = "/Org/Tizen/ResourceD/Process";
-constexpr const char RESOURCED_PROC_INTERFACE[] = "org.tizen.resourced.process";
-constexpr const char RESOURCED_PROC_STATUS_SIGNAL[] = "ProcStatus";
-constexpr const char RESOURCED_PROC_METHOD[] = "ProcExclude";
-
-template <typename T>
-class Event {
- public:
- Event(std::string object_path, std::string interface_name,
- std::string signal_name)
- : object_path_(std::move(object_path)),
- interface_name_(std::move(interface_name)),
- signal_name_(std::move(signal_name)) {
- }
-
- virtual ~Event() {
- Unsubscribe();
- }
-
- const std::string& GetObjectPath() const { return object_path_; }
-
- const std::string& GetInterfaceName() const { return interface_name_; }
-
- const std::string& GetSignalName() const { return signal_name_; }
-
- virtual void Invoke(GVariant* parameters) {}
-
- T GetCallback() const { return cb_; }
-
- void* GetUserData() const { return user_data_; }
-
- bool Subscribe() {
- std::lock_guard<std::recursive_mutex> lock(GetMutex());
- if (source_ != 0)
- return true;
-
- GError* err = nullptr;
- conn_ = g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &err);
- if (conn_ == nullptr) {
- _E("g_bus_get_sync() is failed. error(%s)", err ? err->message : "");
- g_clear_error(&err);
- return false;
- }
-
- source_ = g_dbus_connection_signal_subscribe(
- conn_, nullptr, interface_name_.c_str(), signal_name_.c_str(),
- object_path_.c_str(), nullptr, G_DBUS_SIGNAL_FLAGS_NONE, DBusSignalCb,
- this, nullptr);
- if (source_ == 0) {
- _E("g_dbus_connection_signal_subscribe() is failed");
- g_object_unref(conn_);
- conn_ = nullptr;
- return false;
- }
-
- return true;
- }
-
- bool SetCallback(T cb, void* user_data) {
- std::lock_guard<std::recursive_mutex> lock(GetMutex());
- cb_ = cb;
- user_data_ = user_data;
-
- if (cb_ == nullptr) {
- Unsubscribe();
- return true;
- }
-
- return Subscribe();
- }
-
- private:
- void Unsubscribe() {
- std::lock_guard<std::recursive_mutex> lock(GetMutex());
- if (source_ == 0)
- return;
-
- g_dbus_connection_signal_unsubscribe(conn_, source_);
- source_ = 0;
-
- g_object_unref(conn_);
- conn_ = nullptr;
- }
-
- std::recursive_mutex& GetMutex() const {
- return mutex_;
- }
-
- static void DBusSignalCb(GDBusConnection* connection,
- const gchar* sender_name, const gchar* object_path,
- const gchar* interface_name, const gchar* signal_name,
- GVariant* parameters, gpointer user_data) {
- auto* event = static_cast<Event*>(user_data);
- std::lock_guard<std::recursive_mutex> lock(event->GetMutex());
- if (event->source_ != 0)
- event->Invoke(parameters);
- }
-
- private:
- std::string object_path_;
- std::string interface_name_;
- std::string signal_name_;
- std::remove_pointer_t<T>* cb_ = nullptr;
- void* user_data_ = nullptr;
- GDBusConnection* conn_ = nullptr;
- guint source_ = 0;
- mutable std::recursive_mutex mutex_;
-};
-
-class AppDeadEvent : public Event<aul_app_dead_event_cb> {
- public:
- AppDeadEvent() : Event<aul_app_dead_event_cb>(AUL_DBUS_PATH,
- AUL_DBUS_SIGNAL_INTERFACE, AUL_DBUS_APPDEAD_SIGNAL) {
- }
-
- void Invoke(GVariant* parameters) override {
- gint pid;
- gint dummy;
- g_variant_get(parameters, "(ii)", &pid, &dummy);
-
- auto cb = GetCallback();
- if (cb != nullptr)
- cb(static_cast<int>(pid), GetUserData());
- }
-};
-
-class AppDeadEvent2 : public Event<aul_app_dead_event_cb_v2> {
- public:
- AppDeadEvent2() : Event<aul_app_dead_event_cb_v2>(AUL_DBUS_PATH,
- AUL_DBUS_SIGNAL_INTERFACE, AUL_DBUS_APPDEAD_SIGNAL) {
- }
-
- void Invoke(GVariant* parameters) override {
- gint pid;
- gint status;
- g_variant_get(parameters, "(ii)", &pid, &status);
-
- auto cb = GetCallback();
- if (cb != nullptr)
- cb(static_cast<int>(pid), static_cast<int>(status), GetUserData());
- }
-};
-
-class AppLaunchEvent : public Event<aul_app_launch_event_cb> {
- public:
- AppLaunchEvent() : Event<aul_app_launch_event_cb>(AUL_DBUS_PATH,
- AUL_DBUS_SIGNAL_INTERFACE, AUL_DBUS_APPLAUNCH_SIGNAL) {
- }
-
- void Invoke(GVariant* parameters) override {
- guint pid;
- gchar* appid;
- g_variant_get(parameters, "(u&s)", &pid, &appid);
-
- auto cb = GetCallback();
- if (cb != nullptr)
- cb(static_cast<int>(pid), GetUserData());
- }
-};
-
-class AppLaunchEvent2 : public Event<aul_app_launch_event_cb_v2> {
- public:
- AppLaunchEvent2() : Event<aul_app_launch_event_cb_v2>(AUL_DBUS_PATH,
- AUL_DBUS_SIGNAL_INTERFACE, AUL_DBUS_APPLAUNCH_SIGNAL) {
- }
-
- void Invoke(GVariant* parameters) override {
- guint pid;
- gchar* appid;
- g_variant_get(parameters, "(u&s)", &pid, &appid);
-
- auto cb = GetCallback();
- if (cb != nullptr)
- cb(static_cast<int>(pid), appid, GetUserData());
- }
-};
-
-class BootingDoneEvent : public Event<aul_booting_done_event_cb> {
- public:
- BootingDoneEvent() : Event<aul_booting_done_event_cb>(SYSTEM_PATH_CORE,
- SYSTEM_INTERFACE_CORE, SYSTEM_SIGNAL_BOOTING_DONE) {
- }
-
- void Invoke(GVariant* parameters) override {
- auto cb = GetCallback();
- if (cb != nullptr)
- cb(0, GetUserData());
- }
-};
-
-class CooldownEvent : public Event<aul_cooldown_event_cb> {
- public:
- CooldownEvent() : Event<aul_cooldown_event_cb>(SYSTEM_PATH_THERMAL,
- SYSTEM_INTERFACE_THERMAL, SYSTEM_SIGNAL_COOLDOWN_MODE_CHANGED) {
- }
-
- void Invoke(GVariant* parameters) override {
- gchar* cooldown_status;
- g_variant_get(parameters, "(&s)", &cooldown_status);
-
- auto cb = GetCallback();
- if (cb != nullptr)
- cb(cooldown_status, GetUserData());
- }
-};
-
-class AppStatusChangedEvent : public Event<aul_app_status_changed_cb> {
- public:
- AppStatusChangedEvent()
- : Event<aul_app_status_changed_cb>(RESOURCED_PROC_PATH,
- RESOURCED_PROC_INTERFACE, RESOURCED_PROC_STATUS_SIGNAL) {
- }
-
- void Invoke(GVariant* parameters) override {
- gint pid = -1;
- gint status = -1;
- g_variant_get(parameters, "(ii)", &status, &pid);
-
- auto cb = GetCallback();
- if (cb != nullptr)
- cb(pid, status, GetUserData());
- }
-};
-
-class AppSignalContext {
- public:
- AppSignalContext() = default;
- ~AppSignalContext() {
- }
-
- bool AppDeadEventSubscribe(aul_app_dead_event_cb cb, void* user_data) {
- std::lock_guard<std::recursive_mutex> lock(mutex_);
- if (app_dead_event_ == nullptr)
- app_dead_event_ = std::make_unique<AppDeadEvent>();
-
- return app_dead_event_->SetCallback(cb, user_data);
- }
-
- bool AppDeadEvent2Subscribe(
- aul_app_dead_event_cb_v2 cb, void* user_data) {
- std::lock_guard<std::recursive_mutex> lock(mutex_);
- if (app_dead_event2_ == nullptr)
- app_dead_event2_ = std::make_unique<AppDeadEvent2>();
-
- return app_dead_event2_->SetCallback(cb, user_data);
- }
-
- bool AppLaunchEventSubscribe(aul_app_launch_event_cb cb, void* user_data) {
- std::lock_guard<std::recursive_mutex> lock(mutex_);
- if (app_launch_event_ == nullptr)
- app_launch_event_ = std::make_unique<AppLaunchEvent>();
-
- return app_launch_event_->SetCallback(cb, user_data);
- }
-
- bool AppLaunchEvent2Subscribe(aul_app_launch_event_cb_v2 cb,
- void* user_data) {
- std::lock_guard<std::recursive_mutex> lock(mutex_);
- if (app_launch_event2_ == nullptr)
- app_launch_event2_ = std::make_unique<AppLaunchEvent2>();
-
- return app_launch_event2_->SetCallback(cb, user_data);
- }
-
- bool BootingDoneEventSubscribe(aul_booting_done_event_cb cb,
- void* user_data) {
- std::lock_guard<std::recursive_mutex> lock(mutex_);
- if (app_dead_event_ == nullptr)
- app_dead_event_ = std::make_unique<AppDeadEvent>();
-
- return booting_done_event_->SetCallback(cb, user_data);
- }
-
- bool CooldownEventSubscribe(aul_cooldown_event_cb cb, void* user_data) {
- std::lock_guard<std::recursive_mutex> lock(mutex_);
- if (cooldown_event_ == nullptr)
- cooldown_event_ = std::make_unique<CooldownEvent>();
-
- return cooldown_event_->SetCallback(cb, user_data);
- }
-
- bool AppStatusChangedEventSubscribe(aul_app_status_changed_cb cb,
- void* user_data) {
- std::lock_guard<std::recursive_mutex> lock(mutex_);
- if (app_status_changed_event_ == nullptr)
- app_status_changed_event_ = std::make_unique<AppStatusChangedEvent>();
-
- return app_status_changed_event_->SetCallback(cb, user_data);
- }
-
- private:
- std::recursive_mutex mutex_;
- std::unique_ptr<AppDeadEvent> app_dead_event_;
- std::unique_ptr<AppDeadEvent2> app_dead_event2_;
- std::unique_ptr<AppLaunchEvent> app_launch_event_;
- std::unique_ptr<AppLaunchEvent2> app_launch_event2_;
- std::unique_ptr<BootingDoneEvent> booting_done_event_;
- std::unique_ptr<CooldownEvent> cooldown_event_;
- std::unique_ptr<AppStatusChangedEvent> app_status_changed_event_;
-};
-
-AppSignalContext context;
-
-bool EmitSignal(const std::string& object_path,
- const std::string& interface_name, const std::string& signal_name,
- GVariant* parameters) {
- GError* err = nullptr;
- auto* conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &err);
- if (conn == nullptr) {
- _E("g_bus_get_sync() is failed. error(%s)", err ? err->message : "");
- g_clear_error(&err);
- return false;
- }
- std::unique_ptr<GDBusConnection, decltype(g_object_unref)*> conn_auto(
- conn, g_object_unref);
-
- if (!g_dbus_connection_emit_signal(conn, nullptr, object_path.c_str(),
- interface_name.c_str(), signal_name.c_str(), parameters, &err)) {
- _E("g_dbus_connection_emit_signal() is failed. error(%s)",
- err ? err->message : "");
- g_clear_error(&err);
- return false;
- }
-
- if (!g_dbus_connection_flush_sync(conn, nullptr, &err)) {
- _E("g_dbus_connection_flush_sync() is failed. error(%s)",
- err ? err->message : "");
- g_clear_error(&err);
- return false;
- }
-
- return true;
-}
-
-bool SendMessage(const std::string& name, const std::string& path,
- const std::string& interface, const std::string& method, GVariant* body) {
- GError* err = nullptr;
- auto* conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &err);
- if (conn == nullptr) {
- _E("g_bus_get_sync() is failed. error(%s)", err ? err->message : "");
- g_clear_error(&err);
- return false;
- }
- std::unique_ptr<GDBusConnection, decltype(g_object_unref)*> conn_auto(
- conn, g_object_unref);
-
- auto* msg = g_dbus_message_new_method_call(name.c_str(), path.c_str(),
- interface.c_str(), method.c_str());
- if (msg == nullptr) {
- _E("g_dbus_message_new_method_call() is failed");
- return false;
- }
- std::unique_ptr<GDBusMessage, decltype(g_object_unref)*> msg_auto(
- msg, g_object_unref);
-
- g_dbus_message_set_body(msg, body);
- g_dbus_connection_send_message_with_reply(conn, msg,
- G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, nullptr, nullptr,
- [](GObject* source_object, GAsyncResult* res, gpointer user_data) {
- auto* conn = static_cast<GDBusConnection*>(user_data);
- int result;
- GError* err = nullptr;
- auto* reply = g_dbus_connection_send_message_with_reply_finish(conn,
- res, &err);
- if (reply == nullptr) {
- _E("No reply. error(%s)", err ? err->message : "");
- result = -1;
- } else {
- result = 0;
- }
-
- g_clear_error(&err);
- if (reply != nullptr)
- g_object_unref(reply);
- if (conn != nullptr)
- g_object_unref(conn);
-
- _I("Result: %d", result);
- }, conn);
- conn_auto.release();
- return true;
-}
-
-} // namespace
-
-extern "C" API int aul_listen_app_dead_signal(aul_app_dead_event_cb callback,
- void* user_data) {
- if (!context.AppDeadEventSubscribe(callback, user_data))
- return AUL_R_ERROR;
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_listen_app_dead_signal_v2(
- aul_app_dead_event_cb_v2 callback, void* user_data) {
- if (!context.AppDeadEvent2Subscribe(callback, user_data))
- return AUL_R_ERROR;
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_listen_app_launch_signal(
- aul_app_launch_event_cb callback, void* user_data) {
- if (!context.AppLaunchEventSubscribe(callback, user_data))
- return AUL_R_ERROR;
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_listen_app_launch_signal_v2(
- aul_app_launch_event_cb_v2 callback, void* user_data) {
- if (!context.AppLaunchEvent2Subscribe(callback, user_data))
- return AUL_R_ERROR;
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_listen_booting_done_signal(
- aul_booting_done_event_cb callback, void* user_data) {
- _W("DEPRECATION WARNING: %s() is deprecated "
- "and will be remove from next release.", __FUNCTION__);
- if (!context.BootingDoneEventSubscribe(callback, user_data))
- return AUL_R_ERROR;
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_listen_cooldown_signal(aul_cooldown_event_cb callback,
- void *user_data) {
- _W("DEPRECATION WARNING: %s() is deprecated "
- "and will be remove from next release.", __FUNCTION__);
- if (!context.CooldownEventSubscribe(callback, user_data))
- return AUL_R_ERROR;
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_listen_app_status_signal(
- aul_app_status_changed_cb callback, void *user_data) {
- if (!context.AppStatusChangedEventSubscribe(callback, user_data))
- return AUL_R_ERROR;
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_update_freezer_status(int pid, const char* type) {
- if (pid <= 1 || type == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- GVariant* body = g_variant_new("(si)", type, pid);
- if (body == nullptr) {
- _E("Out of memory");
- return AUL_R_ENOMEM;
- }
-
- if (!SendMessage(RESOURCED_BUS_NAME, RESOURCED_PROC_PATH,
- RESOURCED_PROC_INTERFACE, RESOURCED_PROC_METHOD, body)) {
- g_variant_unref(body);
- return AUL_R_ERROR;
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_send_app_launch_request_signal(int pid,
- const char* appid, const char* pkgid, const char* type) {
- if (pid <= 1 || appid == nullptr || pkgid == nullptr || type == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- GVariant* parameters = g_variant_new("(isss)", pid, appid, pkgid, type);
- if (parameters == nullptr) {
- _E("Out of memory");
- return AUL_R_ENOMEM;
- }
-
- if (!EmitSignal(AUL_APP_STATUS_DBUS_PATH,
- AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE,
- AUL_APP_STATUS_DBUS_LAUNCH_REQUEST, parameters)) {
- g_variant_unref(parameters);
- return AUL_R_ERROR;
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_send_app_resume_request_signal(int pid,
- const char* appid, const char* pkgid, const char* type) {
- if (pid <= 1) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- if (appid == nullptr)
- appid = "";
- if (pkgid == nullptr)
- pkgid = "";
- if (type == nullptr)
- type = "";
-
- GVariant* parameters = g_variant_new("(isss)", pid, appid, pkgid, type);
- if (parameters == nullptr) {
- _E("Out of memory");
- return AUL_R_ENOMEM;
- }
-
- if (!EmitSignal(AUL_APP_STATUS_DBUS_PATH,
- AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE,
- AUL_APP_STATUS_DBUS_RESUME_REQUEST, parameters)) {
- g_variant_unref(parameters);
- return AUL_R_ERROR;
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_send_app_terminate_request_signal(int pid,
- const char* appid, const char* pkgid, const char* type) {
- if (pid <= 1) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- if (appid == nullptr)
- appid = "";
- if (pkgid == nullptr)
- pkgid = "";
- if (type == nullptr)
- type = "";
-
- GVariant* parameters = g_variant_new("(isss)", pid, appid, pkgid, type);
- if (parameters == nullptr) {
- _E("Out of memory");
- return AUL_R_ENOMEM;
- }
-
- if (!EmitSignal(AUL_APP_STATUS_DBUS_PATH,
- AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE,
- AUL_APP_STATUS_DBUS_TERMINATE_REQUEST, parameters)) {
- g_variant_unref(parameters);
- return AUL_R_ERROR;
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_send_app_status_change_signal(int pid,
- const char* appid, const char* pkgid, const char* status,
- const char* type) {
- if (pid <= 1 || status == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- if (appid == nullptr)
- appid = "";
- if (pkgid == nullptr)
- pkgid = "";
- if (type == nullptr)
- type = "";
-
- GVariant* parameters = g_variant_new("(issss)",
- pid, appid, pkgid, status, type);
- if (parameters == nullptr) {
- _E("Out of memory");
- return AUL_R_ENOMEM;
- }
-
- if (!EmitSignal(AUL_APP_STATUS_DBUS_PATH,
- AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE,
- AUL_APP_STATUS_DBUS_STATUS_CHANGE, parameters)) {
- g_variant_unref(parameters);
- return AUL_R_ERROR;
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_send_app_terminated_signal(int pid) {
- if (pid <= 1) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- GVariant* parameters = g_variant_new("(i)", pid);
- if (parameters == nullptr) {
- _E("Out of memory");
- return AUL_R_ENOMEM;
- }
-
- if (!EmitSignal(AUL_APP_STATUS_DBUS_PATH,
- AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE,
- AUL_APP_STATUS_DBUS_TERMINATED, parameters)) {
- g_variant_unref(parameters);
- return AUL_R_ERROR;
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_send_app_group_signal(int owner_pid, int child_pid,
- const char* child_pkgid) {
- if (owner_pid <= 1 || child_pid <= 1) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- if (child_pkgid == nullptr)
- child_pkgid = "";
-
- GVariant* parameters = g_variant_new("(iis)",
- owner_pid, child_pid, child_pkgid);
- if (parameters == nullptr) {
- _E("Out of memory");
- return AUL_R_ENOMEM;
- }
-
- if (!EmitSignal(AUL_APP_STATUS_DBUS_PATH,
- AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE,
- AUL_APP_STATUS_DBUS_GROUP, parameters)) {
- g_variant_unref(parameters);
- return AUL_R_ERROR;
- }
-
- return AUL_R_OK;
-}
+++ /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
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/api AUL_API_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/app_control
+ AUL_APP_CONTROL_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/app_group AUL_APP_GROUP_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/app_info AUL_APP_INFO_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/app_manager AUL_APP_MANAGER_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/common AUL_COMMON_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/component AUL_COMPONENT_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/socket AUL_SOCKET_SRCS)
+
+ADD_LIBRARY(${TARGET_AUL} SHARED
+ ${SRCS}
+ ${AUL_API_SRCS}
+ ${AUL_APP_CONTROL_SRCS}
+ ${AUL_APP_GROUP_SRCS}
+ ${AUL_APP_MANAGER_SRCS}
+ ${AUL_APP_INFO_SRCS}
+ ${AUL_COMMON_SRCS}
+ ${AUL_COMPONENT_SRCS}
+ ${AUL_SOCKET_SRCS}
+ ${AUL_BOOT_SEQUENCE_SRCS}
+)
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_AUL} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/../
+ ${CMAKE_CURRENT_SOURCE_DIR}/include
+ ${CMAKE_CURRENT_SOURCE_DIR}/include/internal
+ ${CMAKE_CURRENT_SOURCE_DIR}/api
+ ${CMAKE_CURRENT_SOURCE_DIR}/app_control
+ ${CMAKE_CURRENT_SOURCE_DIR}/app_manager
+ ${CMAKE_CURRENT_SOURCE_DIR}/common
+ ${CMAKE_CURRENT_SOURCE_DIR}/component
+ ${CMAKE_CURRENT_SOURCE_DIR}/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
+ CAPI_SYSTEM_RESOURCE_DEPS
+ DLOG_DEPS
+ GIO_DEPS
+ GLIB_DEPS
+ INIPARSER_DEPS
+ LIBSMACK_DEPS
+ LIBTZPLATFORM_CONFIG_DEPS
+ LIBXML_DEPS
+ PARCEL_DEPS
+ PKGMGR_INFO_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)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/aul.pc
+ DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/aul.conf
+ DESTINATION /etc/dbus-1/system.d)
+
+INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION include/aul
+ FILES_MATCHING
+ PATTERN "*.h"
+)
+
+INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/api/ DESTINATION include/aul/api
+ FILES_MATCHING
+ PATTERN "*.h"
+)
--- /dev/null
+/*
+ * Copyright (c) 2020 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 <aul.h>
+#include <sys/types.h>
+#include <tizen.h>
+#include <unistd.h>
+
+#include <memory>
+
+#include "aul/api/aul_app_context.h"
+#include "aul/app_manager/app_manager.hh"
+#include "aul/common/api.hh"
+#include "aul/common/log_private.hh"
+
+using namespace aul;
+
+extern "C" API int aul_app_context_create(const char *app_id,
+ aul_app_context_h* app_context) {
+ if (!app_id || !app_context) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ char caller_id[256] = { 0, };
+ int ret = aul_app_get_appid_bypid(getpid(), caller_id, sizeof(caller_id));
+ if (ret == AUL_R_OK) {
+ if (!strcmp(caller_id, app_id)) {
+ _W("Same Application(%s)", app_id);
+ return aul_app_context_create_with_pid(getpid(), app_context);
+ }
+ }
+
+ AppManager app_manager;
+ auto handle = app_manager.GetAppContext(app_id);
+ if (get_last_result() != AUL_R_OK) {
+ _E("Failed to get app context");
+ return get_last_result();
+ }
+
+ *app_context = handle.release();
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_app_context_create_with_inst_id(
+ const char* app_id,
+ const char* inst_id,
+ aul_app_context_h* app_context) {
+ if (!app_id || !inst_id || !app_context) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ AppManager app_manager;
+ auto handle = app_manager.GetAppContext(app_id, inst_id);
+ if (get_last_result() != AUL_R_OK) {
+ _E("Failed to get app context");
+ return get_last_result();
+ }
+
+ *app_context = handle.release();
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_app_context_create_with_pid(int pid,
+ aul_app_context_h* app_context) {
+ if (pid < 2 || !app_context) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ AppManager app_manager;
+ auto handle = app_manager.GetAppContext(pid);
+ if (get_last_result() != AUL_R_OK) {
+ _E("Failed to get app context");
+ return get_last_result();
+ }
+
+ *app_context = handle.release();
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_app_context_destroy(aul_app_context_h app_context) {
+ if (!app_context) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* handle = static_cast<AppContext*>(app_context);
+ delete handle;
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_app_context_clone(aul_app_context_h app_context,
+ aul_app_context_h* clone) {
+ if (!app_context || !clone) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* handle = static_cast<AppContext*>(app_context);
+ AppContext::Builder builder;
+ builder.SetAppId(handle->GetAppId());
+ builder.SetPkgId(handle->GetPkgId());
+ builder.SetInstId(handle->GetInstId());
+ builder.SetExec(handle->GetExec());
+ builder.SetPid(handle->GetPid());
+ builder.SetStatus(handle->GetStatus());
+ builder.SetIsSubApp(handle->IsSubApp());
+
+ *clone = std::make_unique<AppContext>(builder.Build()).release();
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_app_context_get_app_id(aul_app_context_h app_context,
+ char** app_id) {
+ if (!app_context || !app_id) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* handle = static_cast<AppContext*>(app_context);
+ *app_id = strdup(handle->GetAppId().c_str());
+ if (*app_id == nullptr) {
+ _E("Failed to duplicate application ID");
+ return AUL_R_ENOMEM;
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_app_context_get_pkg_id(aul_app_context_h app_context,
+ char** pkg_id) {
+ if (!app_context || !pkg_id) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* handle = static_cast<AppContext*>(app_context);
+ *pkg_id = strdup(handle->GetPkgId().c_str());
+ if (*pkg_id == nullptr) {
+ _E("Failed to duplicate package ID");
+ return AUL_R_ENOMEM;
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_app_context_get_inst_id(aul_app_context_h app_context,
+ char** inst_id) {
+ if (!app_context || !inst_id) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* handle = static_cast<AppContext*>(app_context);
+ *inst_id = strdup(handle->GetInstId().c_str());
+ if (*inst_id == nullptr) {
+ _E("Failed to duplicate instance ID");
+ return AUL_R_ENOMEM;
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_app_context_get_app_path(aul_app_context_h app_context,
+ char** app_path) {
+ if (!app_context || !app_path) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* handle = static_cast<AppContext*>(app_context);
+ *app_path = strdup(handle->GetExec().c_str());
+ if (*app_path == nullptr) {
+ _E("Failed to duplicate app path");
+ return AUL_R_ENOMEM;
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_app_context_get_pid(aul_app_context_h app_context,
+ int* pid) {
+ if (!app_context || !pid) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* handle = static_cast<AppContext*>(app_context);
+ *pid = handle->GetPid();
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_app_context_get_status(aul_app_context_h app_context,
+ int* status) {
+ if (!app_context || !status) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* handle = static_cast<AppContext*>(app_context);
+ *status = handle->GetStatus();
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_app_context_is_sub_app(aul_app_context_h app_context,
+ bool* is_sub_app) {
+ if (!app_context || !is_sub_app) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* handle = static_cast<AppContext*>(app_context);
+ *is_sub_app = handle->IsSubApp();
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_app_context_is_running(aul_app_context_h app_context,
+ bool* is_running) {
+ if (!app_context || !is_running) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* handle = static_cast<AppContext*>(app_context);
+ int ret = aul_app_is_running(handle->GetAppId().c_str());
+ if (ret == 1) {
+ *is_running = true;
+ } else {
+ char app_id[256] = { 0, };
+ int ret = aul_app_get_appid_bypid(handle->GetPid(), app_id, sizeof(app_id));
+ if (ret == AUL_R_OK)
+ *is_running = true;
+ else
+ *is_running = false;
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_app_context_is_equal(aul_app_context_h lhs,
+ aul_app_context_h rhs,
+ bool* equal) {
+ if (!lhs || !rhs || !equal) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* lh = static_cast<AppContext*>(lhs);
+ auto* rh = static_cast<AppContext*>(rhs);
+ if (lh->GetAppId() == rh->GetAppId() && lh->GetPid() == rh->GetPid())
+ *equal = true;
+ else
+ *equal = false;
+
+ return AUL_R_OK;
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 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_API_AUL_APP_CONTEXT_H_
+#define AUL_API_AUL_APP_CONTEXT_H_
+
+#include <aul.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void *aul_app_context_h;
+
+int aul_app_context_create(const char *app_id, aul_app_context_h *app_context);
+
+int aul_app_context_create_with_inst_id(const char *app_id, const char *inst_id,
+ aul_app_context_h *app_context);
+
+int aul_app_context_create_with_pid(int pid, aul_app_context_h *app_context);
+
+int aul_app_context_destroy(aul_app_context_h app_context);
+
+int aul_app_context_clone(aul_app_context_h app_context,
+ aul_app_context_h *clone);
+
+int aul_app_context_get_app_id(aul_app_context_h app_context, char **app_id);
+
+int aul_app_context_get_pkg_id(aul_app_context_h app_context, char **pkg_id);
+
+int aul_app_context_get_inst_id(aul_app_context_h app_context, char **inst_id);
+
+int aul_app_context_get_app_path(aul_app_context_h app_context,
+ char **app_path);
+
+int aul_app_context_get_pid(aul_app_context_h app_context, int *pid);
+
+int aul_app_context_get_status(aul_app_context_h app_context, int *status);
+
+int aul_app_context_is_sub_app(aul_app_context_h app_context, bool *is_sub_app);
+
+int aul_app_context_is_running(aul_app_context_h app_context, bool *is_running);
+
+int aul_app_context_is_equal(aul_app_context_h lhs, aul_app_context_h rhs,
+ bool *equal);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // AUL_API_AUL_APP_CONTEXT_HH_
--- /dev/null
+/*
+ * Copyright (c) 2020 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 "aul/api/aul_app_event.h"
+
+#include <glib.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <string>
+#include <utility>
+
+#include "aul/app_manager/app_event.hh"
+#include "aul/common/api.hh"
+#include "aul/common/exception.hh"
+#include "aul/common/log_private.hh"
+
+namespace {
+using namespace aul;
+
+class AppEventStub : public AppEvent,
+ public AppEvent::IEvent {
+ public:
+ AppEventStub(std::string app_id,
+ aul_app_event_launched_cb launched_cb,
+ aul_app_event_terminated_cb terminated_cb,
+ void* user_data)
+ : AppEvent(std::move(app_id), this),
+ launched_cb_(launched_cb),
+ terminated_cb_(terminated_cb),
+ user_data_(user_data) {
+ }
+
+ AppEventStub(aul_app_event_launched_cb launched_cb,
+ aul_app_event_terminated_cb terminated_cb,
+ void* user_data)
+ : AppEvent(this),
+ launched_cb_(launched_cb),
+ terminated_cb_(terminated_cb),
+ user_data_(user_data) {
+ }
+
+ void OnAppLaunched(const AppContext* context) override {
+ if (disposing_)
+ return;
+
+ AppContext* ctx = const_cast<AppContext*>(context);
+ launched_cb_(static_cast<aul_app_context_h>(ctx), user_data_);
+ }
+
+ void OnAppTerminated(const AppContext* context) override {
+ if (disposing_)
+ return;
+
+ AppContext* ctx = const_cast<AppContext*>(context);
+ terminated_cb_(static_cast<aul_app_context_h>(ctx), user_data_);
+ }
+
+ void Dispose() {
+ if (disposing_)
+ return;
+
+ disposing_ = true;
+ g_idle_add_full(G_PRIORITY_HIGH,
+ [](gpointer user_data) {
+ auto* event = static_cast<AppEventStub*>(user_data);
+ delete event;
+ return G_SOURCE_REMOVE;
+ }, this, nullptr);
+ }
+
+ private:
+ bool disposing_ = false;
+ aul_app_event_launched_cb launched_cb_;
+ aul_app_event_terminated_cb terminated_cb_;
+ void* user_data_;
+};
+
+} // namespace
+
+extern "C" API int aul_app_event_create_with_appid(const char* app_id,
+ aul_app_event_launched_cb launched_cb,
+ aul_app_event_terminated_cb terminated_cb,
+ void* user_data,
+ aul_app_event_h* app_event) {
+ if (!app_id || !launched_cb || !terminated_cb || !app_event) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ AppEventStub* handle = nullptr;
+ try {
+ handle = new AppEventStub(app_id, launched_cb, terminated_cb, user_data);
+ handle->Listen();
+ } catch (Exception& e) {
+ return e.GetErrorCode();
+ }
+
+ *app_event = static_cast<aul_app_event_h>(handle);
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_app_event_create(aul_app_event_launched_cb launched_cb,
+ aul_app_event_terminated_cb terminated_cb,
+ void* user_data,
+ aul_app_event_h* app_event) {
+ if (!launched_cb || !terminated_cb || !app_event) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ AppEventStub* handle = nullptr;
+ try {
+ handle = new AppEventStub(launched_cb, terminated_cb, user_data);
+ handle->Listen();
+ } catch (Exception& e) {
+ return e.GetErrorCode();
+ }
+
+ *app_event = static_cast<aul_app_event_h>(handle);
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_app_event_destroy(aul_app_event_h app_event) {
+ if (!app_event) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* handle = static_cast<AppEventStub*>(app_event);
+ if (getpid() == gettid())
+ delete handle;
+ else
+ handle->Dispose();
+
+ return AUL_R_OK;
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 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_API_AUL_APP_EVENT_H_
+#define AUL_API_AUL_APP_EVENT_H_
+
+#include <aul.h>
+#include <aul_app_context.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void *aul_app_event_h;
+
+typedef void (*aul_app_event_launched_cb)(aul_app_context_h app_context,
+ void *user_data);
+
+typedef void (*aul_app_event_terminated_cb)(aul_app_context_h app_context,
+ void *user_data);
+
+int aul_app_event_create_with_appid(const char *app_id,
+ aul_app_event_launched_cb launched_cb,
+ aul_app_event_terminated_cb terminated_cb,
+ void *user_data,
+ aul_app_event_h *app_event);
+
+int aul_app_event_create(aul_app_event_launched_cb launched_cb,
+ aul_app_event_terminated_cb terminated_cb,
+ void *user_data,
+ aul_app_event_h *app_event);
+
+int aul_app_event_destroy(aul_app_event_h app_event);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // AUL_API_AUL_APP_EVENT_HH_
--- /dev/null
+/*
+ * Copyright (c) 2021 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 <bundle_cpp.h>
+
+#include <memory>
+#include <stdexcept>
+#include <string>
+
+#include "aul/api/aul_app_lifecycle.h"
+#include "aul/common/api.hh"
+#include "aul/common/exception.hh"
+#include "aul/socket/client.hh"
+#include "include/aul.h"
+#include "include/aul_app_com.h"
+#include "include/aul_cmd.h"
+#include "include/aul_error.h"
+#include "include/aul_sock.h"
+
+namespace {
+
+class EventListener {
+ public:
+ EventListener() {
+ }
+
+ ~EventListener() {
+ Deregister();
+ }
+
+ int Register(aul_app_lifecycle_state_changed_cb cb, void* user_data) {
+ cb_ = cb;
+ user_data_ = user_data;
+
+ if (conn_ != nullptr) {
+ _W("Callback was already registered.");
+ return AUL_R_OK;
+ }
+
+ int ret = aul_app_com_create_async("app_lifecycle_state_change", nullptr,
+ AppComMessageCb, this, &conn_);
+ if (ret != AUL_R_OK) {
+ _E("aul_app_com_create_async() is failed. error(%d)", ret);
+ return ret;
+ }
+
+ return AUL_R_OK;
+ }
+
+ int Deregister() {
+ if (conn_ == nullptr)
+ return AUL_R_OK;
+
+ aul_app_com_leave(conn_);
+ conn_ = nullptr;
+ return AUL_R_OK;
+ }
+
+ private:
+ static int AppComMessageCb(const char* endpoint, aul_app_com_result_e res,
+ bundle* envelope, void* user_data) {
+ tizen_base::Bundle b(envelope, false, false);
+ std::string app_id = b.GetString(AUL_K_APPID);
+ pid_t pid = std::stoi(b.GetString(AUL_K_PID));
+ int state = std::stoi(b.GetString(AUL_K_STATE));
+ std::string has_focus = b.GetString(AUL_K_HAS_FOCUS);
+
+ auto* handle = static_cast<EventListener*>(user_data);
+ if (handle->cb_) {
+ handle->cb_(app_id.c_str(), pid,
+ static_cast<aul_app_lifecycle_state_e>(state),
+ has_focus == "true" ? true : false,
+ handle->user_data_);
+ }
+
+ return 0;
+ }
+
+ private:
+ aul_app_com_connection_h conn_ = nullptr;
+ aul_app_lifecycle_state_changed_cb cb_ = nullptr;
+ void* user_data_ = nullptr;
+};
+
+EventListener listener;
+
+} // namespace
+
+extern "C" API int aul_app_lifecycle_register_state_changed_cb(
+ aul_app_lifecycle_state_changed_cb callback, void *user_data) {
+ if (callback == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ return listener.Register(callback, user_data);
+}
+
+extern "C" API int aul_app_lifecycle_deregister_state_changed_cb(void) {
+ return listener.Deregister();
+}
+
+extern "C" API int aul_app_lifecycle_update_state(
+ aul_app_lifecycle_state_e state) {
+ tizen_base::Bundle b;
+ b.Add(AUL_K_STATE, std::to_string(static_cast<int>(state)));
+ aul::Packet packet(APP_LIFECYCLE_UPDATE_STATE,
+ AUL_SOCK_NOREPLY | AUL_SOCK_BUNDLE, b);
+ try {
+ aul::Client client(aul::PATH_AMD_SOCK);
+ int ret = client.Send(packet);
+ if (ret < 0)
+ return aul_error_convert(ret);
+ } catch (aul::Exception& e) {
+ return aul_error_convert(e.GetErrorCode());
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_app_lifecycle_get_state(const char* app_id,
+ aul_app_lifecycle_state_e* state) {
+ if (app_id == nullptr || state == nullptr) {
+ _E("Invalid prameter");
+ return AUL_R_EINVAL;
+ }
+
+ tizen_base::Bundle b;
+ b.Add(AUL_K_APPID, app_id);
+ aul::Packet* recv_pkt = nullptr;
+ aul::Packet packet(APP_LIFECYCLE_GET_STATE, AUL_SOCK_BUNDLE, b);
+ try {
+ aul::Client client(aul::PATH_AMD_SOCK);
+ int ret = client.Send(packet);
+ if (ret < 0)
+ return aul_error_convert(ret);
+
+ ret = client.Recv(&recv_pkt);
+ if (ret < 0)
+ return aul_error_convert(ret);
+
+ std::unique_ptr<aul::Packet> pkt_auto(recv_pkt);
+ if (recv_pkt->GetCmd() != APP_GET_INFO_OK) {
+ _E("Failed to get app lifecycle state");
+ return AUL_R_ERROR;
+ }
+
+ tizen_base::Bundle res_b = recv_pkt->DataToBundle();
+ std::string val = res_b.GetString(AUL_K_STATE);
+ if (!val.empty())
+ *state = static_cast<aul_app_lifecycle_state_e>(std::stoi(val));
+ } catch (std::invalid_argument& e) {
+ _E("Out of memory");
+ return AUL_R_ENOMEM;
+ } catch (aul::Exception& e) {
+ _E("Exception(%s) occurs", e.what());
+ return aul_error_convert(e.GetErrorCode());
+ }
+
+ return AUL_R_OK;
+}
--- /dev/null
+/*
+ * Copyright (c) 2021 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_API_AUL_APP_LIFECYCLE_H_
+#define AUL_API_AUL_APP_LIFECYCLE_H_
+
+#include <stdbool.h>
+#include <aul.h>
+#include <tizen.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Enumeration for application lifecycle state.
+ * @since_tizen 6.5
+ */
+typedef enum {
+ AUL_APP_LIFECYCLE_STATE_INITIALIZED, /**< The application is initialized. */
+ AUL_APP_LIFECYCLE_STATE_CREATED, /**< The application is created. */
+ AUL_APP_LIFECYCLE_STATE_RESUMED, /**< The application is resumed. */
+ AUL_APP_LIFECYCLE_STATE_PAUSED, /**< The application is paused. */
+ AUL_APP_LIFECYCLE_STATE_DESTROYED, /**< The application is terminated. */
+} aul_app_lifecycle_state_e;
+
+/**
+ * @brief Called when the state of the application is changed.
+ * @since_tizen 6.5
+ * @param[in] app_id The application ID
+ * @param[in] pid The process ID
+ * @param[in] state The state of the application lifecycle
+ * @param[in] has_focus If it's true, the application has focus
+ * @param[in] user_data The user data passed from the registration function
+ * @see aul_app_lifecycle_register_state_changed_cb()
+ * @see aul_app_lifecycle_deregister_state_changed_cb()
+ */
+typedef void (*aul_app_lifecycle_state_changed_cb)(const char *app_id, pid_t pid, aul_app_lifecycle_state_e state, bool has_focus, void *user_data);
+
+/**
+ * @breif Registers a callback function to be invoked when the state of the application is changed.
+ * @details To deregister the callback function, you have to call aul_app_lifecycle_deregister_state_changed_cb().
+ * @since_tizen 6.5
+ * @param[in] callback The callback function
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @see aul_app_lifecycle_state_changed_cb()
+ * @see aul_app_lifecycle_deregister_state_changed_cb()
+ */
+int aul_app_lifecycle_register_state_changed_cb(aul_app_lifecycle_state_changed_cb callback, void *user_data);
+
+/**
+ * @brief Deregister the callback function.
+ * @since_tizen 6.5
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @see aul_app_lifecycle_register_state_changed_cb()
+ */
+int aul_app_lifecycle_deregister_state_changed_cb(void);
+
+/**
+ * @brief Updates the state of the application lifecycle.
+ * @since_tizen 6.5
+ * @param[in] state The state of the application lifecycle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @see #aul_app_lifecycle_state_e
+ */
+int aul_app_lifecycle_update_state(aul_app_lifecycle_state_e state);
+
+/**
+ * @brief Gets the state of the application lifecycle of the given application ID.
+ * @since_tizen 6.5
+ * @param[in] app_id The application ID
+ * @param[out] state The state of the application lifecycle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @see #aul_app_lifecycle_state_e
+ */
+int aul_app_lifecycle_get_state(const char *app_id, aul_app_lifecycle_state_e *state);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // AUL_API_AUL_APP_LIFECYCLE_HH_
--- /dev/null
+/*
+ * Copyright (c) 2020 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 <tizen.h>
+
+#include "aul/api/aul_app_manager.h"
+#include "aul/app_manager/app_manager.hh"
+#include "aul/common/api.hh"
+#include "aul/common/log_private.hh"
+
+using namespace aul;
+
+extern "C" API int aul_app_manager_foreach_app_context(
+ aul_app_manager_app_context_cb callback,
+ void* user_data) {
+ if (!callback) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ AppManager app_manager;
+ for (auto& i : app_manager.GetAppContexts()) {
+ if (!callback(static_cast<AppContext*>(i.get()), user_data))
+ break;
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_app_manager_foreach_all_app_context(
+ aul_app_manager_app_context_cb callback,
+ void* user_data) {
+ if (!callback) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ AppManager app_manager;
+ for (auto& i : app_manager.GetAllAppContexts()) {
+ if (!callback(static_cast<AppContext*>(i.get()), user_data))
+ break;
+ }
+
+ return AUL_R_OK;
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 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_API_AUL_APP_MANAGER_H_
+#define AUL_API_AUL_APP_MANAGER_H_
+
+#include <stdbool.h>
+
+#include <aul.h>
+#include <aul_app_context.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef bool (*aul_app_manager_app_context_cb)(aul_app_context_h app_context,
+ void *user_data);
+
+int aul_app_manager_foreach_app_context(aul_app_manager_app_context_cb callback,
+ void *user_data);
+
+int aul_app_manager_foreach_all_app_context(
+ aul_app_manager_app_context_cb callback,
+ void *user_data);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // AUL_API_AUL_APP_MANAGER_HH_
--- /dev/null
+/*
+ * Copyright (c) 2020 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 <tizen.h>
+
+#include "aul/api/aul_component_port.h"
+#include "aul/common/api.hh"
+#include "aul/common/log_private.hh"
+#include "aul/component/component_port.hh"
+
+using namespace aul;
+
+extern "C" API int aul_component_port_exist(const char* port_name,
+ bool* exist) {
+ if (port_name == nullptr || exist == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ ComponentPort port(port_name);
+ bool res = port.Exist();
+ int ret = get_last_result();
+ if (ret != AUL_R_OK)
+ return ret;
+
+ *exist = res;
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_component_port_create(const char* port_name, int* fd) {
+ if (port_name == nullptr || fd == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ ComponentPort port(port_name);
+ int ret = port.Create();
+ if (ret < 0) {
+ _E("Failed to create a port. port_name(%s), error(%d)",
+ port_name, ret);
+ return ret;
+ }
+
+ *fd = ret;
+ _D("Port(%s) is created. fd(%d)", port_name, *fd);
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_component_port_destroy(const char* port_name) {
+ if (port_name == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ ComponentPort port(port_name);
+ int ret = port.Destroy();
+ if (ret != AUL_R_OK) {
+ _E("Failed to destroy a port. port_name(%s), error(%d)",
+ port_name, ret);
+ return ret;
+ }
+
+ _D("Port(%s) is destroyed", port_name);
+ return AUL_R_OK;
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 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_API_AUL_COMPONENT_PORT_H_
+#define AUL_API_AUL_COMPONENT_PORT_H_
+
+#include <stdbool.h>
+
+#include <aul.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int aul_component_port_exist(const char *port_name, bool *exist);
+
+int aul_component_port_create(const char *port_name, int *fd);
+
+int aul_component_port_destroy(const char *port_name);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // AUL_API_AUL_COMPONENT_PORT_HH_
--- /dev/null
+/*
+ * Copyright (c) 2015 - 2022 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 "aul/include/aul_app_com.h"
+
+#include <bundle_cpp.h>
+#include <bundle_internal.h>
+
+#include <list>
+#include <mutex>
+#include <string>
+
+#include "aul/app_request.h"
+#include "aul/aul_api.h"
+#include "aul/aul_util.h"
+#include "aul/include/aul.h"
+#include "aul/include/aul_cmd.h"
+#include "aul/launch.h"
+
+using namespace aul::internal;
+
+namespace {
+
+class AppComConnection {
+ public:
+ AppComConnection(std::string endpoint, app_com_cb cb, void* user_data)
+ : endpoint_(std::move(endpoint)),
+ cb_(cb),
+ user_data_(user_data) {
+ }
+
+ ~AppComConnection() = default;
+
+ const std::string& GetEndpoint() const {
+ return endpoint_;
+ }
+
+ void Disable() {
+ disabled_ = true;
+ }
+
+ bool IsDisabled() const {
+ return disabled_;
+ }
+
+ void Invoke(aul_app_com_result_e result, bundle* envelope) {
+ if (!disabled_ && cb_)
+ cb_(endpoint_.c_str(), result, envelope, user_data_);
+ }
+
+ private:
+ bool disabled_ = false;
+ std::string endpoint_;
+ app_com_cb cb_;
+ void* user_data_;
+};
+
+class AppComPermission {
+ public:
+ AppComPermission() : option_(AUL_APP_COM_PUBLIC) {}
+ ~AppComPermission() {}
+
+ void SetPrivilege(std::string privilege) {
+ privilege_ = std::move(privilege);
+ }
+
+ void SetPropagationOption(aul_app_com_propagate_option_e option) {
+ option_ = option;
+ }
+
+ const std::string& GetPrivilege() const {
+ return privilege_;
+ }
+
+ aul_app_com_propagate_option_e GetPropagationOption() const {
+ return option_;
+ }
+
+ private:
+ std::string privilege_;
+ aul_app_com_propagate_option_e option_;
+};
+
+class Context {
+ public:
+ Context() {}
+ ~Context() {}
+
+ int Receive(bundle* b) {
+ const char* val = bundle_get_val(b, AUL_K_COM_ENDPOINT);
+ if (val == nullptr)
+ return -1;
+
+ size_t result_size = 0;
+ aul_app_com_result_e* result = nullptr;
+ int ret = bundle_get_byte(b, AUL_K_COM_RESULT,
+ reinterpret_cast<void**>(&result), &result_size);
+ if (ret != BUNDLE_ERROR_NONE)
+ return -1;
+
+ std::string endpoint(val);
+
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ auto iter = conns_.begin();
+ while (iter != conns_.end()) {
+ auto& conn = *iter;
+ iter++;
+ if (conn->GetEndpoint() == endpoint)
+ conn->Invoke(*result, b);
+ }
+
+ return 0;
+ }
+
+ AppComConnection* AddConnection(std::string endpoint, app_com_cb cb,
+ void* user_data) {
+ auto* conn = new (std::nothrow) AppComConnection(endpoint, cb, user_data);
+ if (conn == nullptr)
+ return nullptr;
+
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ conns_.emplace_back(conn);
+ return conn;
+ }
+
+ void RemoveConnection(AppComConnection* conn) {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ auto iter = conns_.begin();
+ while (iter != conns_.end()) {
+ if ((*iter).get() == conn) {
+ iter = conns_.erase(iter);
+ break;
+ } else {
+ iter++;
+ }
+ }
+ }
+
+ bool ExistConnection(const std::string& endpoint) {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ for (auto& conn : conns_) {
+ if (conn->GetEndpoint() == endpoint && !conn->IsDisabled())
+ return true;
+ }
+
+ return false;
+ }
+
+ bool ExistConnection(AppComConnection* conn) {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ if (conn->IsDisabled())
+ return false;
+
+ for (auto& i : conns_) {
+ if (i.get() == conn)
+ return true;
+ }
+
+ return false;
+ }
+
+ std::recursive_mutex& GetMutex() const {
+ return mutex_;
+ }
+
+ private:
+ std::list<std::unique_ptr<AppComConnection>> conns_;
+ mutable std::recursive_mutex mutex_;
+};
+
+Context context;
+
+int AppComCreate(const char* endpoint,
+ aul_app_com_permission_h permission, app_com_cb callback, void* user_data,
+ bool sync, aul_app_com_connection_h* connection) {
+ if (endpoint == nullptr || callback == nullptr || connection == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ if (!aul_is_initialized()) {
+ if (aul_launch_init(nullptr, nullptr) < 0)
+ return AUL_R_ENOINIT;
+ }
+
+ tizen_base::Bundle b { { AUL_K_COM_ENDPOINT, endpoint } };
+ if (permission) {
+ auto* handle = static_cast<AppComPermission*>(permission);
+ auto option = handle->GetPropagationOption();
+ if (option) {
+ auto* p = reinterpret_cast<unsigned char*>(&option);
+ std::vector<unsigned char> bytes;
+ std::copy(p, p + sizeof(option), std::back_inserter(bytes));
+ b.Add(AUL_K_COM_PROPAGATE, bytes);
+ }
+
+ if (!handle->GetPrivilege().empty())
+ b.Add(AUL_K_COM_PRIVILEGE, handle->GetPrivilege());
+ }
+
+ int ret = AppRequest(APP_COM_CREATE, getuid())
+ .With(std::move(b))
+ .SendSimply(sync ? AUL_SOCK_NONE : AUL_SOCK_NOREPLY);
+ if (ret == 0) {
+ *connection = static_cast<aul_app_com_connection_h>(
+ context.AddConnection(endpoint, callback, user_data));
+ }
+
+ return ret;
+}
+
+} // namespace
+
+int app_com_recv(bundle* b) {
+ if (b == nullptr)
+ return -1;
+
+ return context.Receive(b);
+}
+
+extern "C" API aul_app_com_permission_h aul_app_com_permission_create() {
+ auto* handle = new (std::nothrow) AppComPermission();
+ return static_cast<aul_app_com_permission_h>(handle);
+}
+
+extern "C" API void aul_app_com_permission_destroy(
+ aul_app_com_permission_h permission) {
+ if (permission == nullptr)
+ return;
+
+ auto* handle = static_cast<AppComPermission*>(permission);
+ delete handle;
+}
+
+extern "C" API int aul_app_com_permission_set_propagation(
+ aul_app_com_permission_h permission,
+ aul_app_com_propagate_option_e option) {
+ if (permission == nullptr)
+ return AUL_R_EINVAL;
+
+ auto* handle = static_cast<AppComPermission*>(permission);
+ handle->SetPropagationOption(option);
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_app_com_permission_set_privilege(
+ aul_app_com_permission_h permission, const char* privilege) {
+ if (permission == nullptr || privilege == nullptr)
+ return AUL_R_EINVAL;
+
+ auto* handle = static_cast<AppComPermission*>(permission);
+ handle->SetPrivilege(privilege);
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_app_com_create(const char* endpoint,
+ aul_app_com_permission_h permission, app_com_cb callback,
+ void* user_data, aul_app_com_connection_h* connection) {
+ return AppComCreate(endpoint, permission, callback, user_data,
+ true, connection);
+}
+
+extern "C" API int aul_app_com_create_async(const char* endpoint,
+ aul_app_com_permission_h permission, app_com_cb callback,
+ void* user_data, aul_app_com_connection_h* connection) {
+ return AppComCreate(endpoint, permission, callback, user_data,
+ false, connection);
+}
+
+extern "C" API int aul_app_com_join(const char* endpoint, const char* filter,
+ app_com_cb callback, void* user_data,
+ aul_app_com_connection_h* connection) {
+ if (endpoint == nullptr || callback == nullptr || connection == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ if (!aul_is_initialized()) {
+ if (aul_launch_init(nullptr, nullptr) < 0)
+ return AUL_R_ENOINIT;
+ }
+
+ tizen_base::Bundle b { { AUL_K_COM_ENDPOINT, endpoint } };
+ if (filter)
+ b.Add(AUL_K_COM_FILTER, filter);
+
+ int ret = AppRequest(APP_COM_JOIN, getuid())
+ .With(std::move(b))
+ .SendSimply();
+ if (ret == 0) {
+ *connection = static_cast<aul_app_com_connection_h>(
+ context.AddConnection(endpoint, callback, user_data));
+ }
+
+ return ret;
+}
+
+extern "C" API int aul_app_com_send(const char* endpoint, bundle* envelope) {
+ if (endpoint == nullptr || envelope == nullptr)
+ return AUL_R_EINVAL;
+
+ std::string com_endpoint;
+ tizen_base::Bundle b(envelope, false, false);
+ bundle_type type = b.GetType(AUL_K_COM_ENDPOINT);
+ if (type != BUNDLE_TYPE_NONE) {
+ com_endpoint = b.GetString(AUL_K_COM_ENDPOINT);
+ b.Delete(AUL_K_COM_ENDPOINT);
+ }
+
+ b.Add(AUL_K_COM_ENDPOINT, endpoint);
+
+ int ret = AppRequest(APP_COM_SEND, getuid())
+ .With(std::move(b))
+ .SendSimply();
+ if (type != BUNDLE_TYPE_NONE) {
+ bundle_del(envelope, AUL_K_COM_ENDPOINT);
+ bundle_add_str(envelope, AUL_K_COM_ENDPOINT, com_endpoint.c_str());
+ }
+
+ return ret;
+}
+
+extern "C" API int aul_app_com_leave(aul_app_com_connection_h connection) {
+ if (connection == nullptr)
+ return AUL_R_EINVAL;
+
+ auto* conn = static_cast<AppComConnection*>(connection);
+ if (!context.ExistConnection(conn)) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ std::lock_guard<std::recursive_mutex> lock(context.GetMutex());
+ conn->Disable();
+
+ std::string endpoint = conn->GetEndpoint();
+ if (!context.ExistConnection(endpoint)) {
+ tizen_base::Bundle b { { AUL_K_COM_ENDPOINT, endpoint } };
+ int ret = AppRequest(APP_COM_LEAVE, getuid())
+ .With(std::move(b))
+ .SendSimply(AUL_SOCK_NOREPLY);
+ if (ret != 0)
+ _E("Failed to send leave request. error(%d)", ret);
+ }
+
+ g_idle_add_full(G_PRIORITY_HIGH, [](gpointer user_data) -> gboolean {
+ auto* conn = static_cast<AppComConnection*>(user_data);
+ std::lock_guard<std::recursive_mutex> lock(context.GetMutex());
+ context.RemoveConnection(conn);
+ return G_SOURCE_REMOVE;
+ }, connection, nullptr);
+
+ return AUL_R_OK;
+}
--- /dev/null
+/*
+ * Copyright (c) 2021 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 "aul/app_control/resolve_info.hh"
+
+#include <errno.h>
+#include <glib.h>
+
+#include "aul/aul_svc_priv_key.h"
+#include "aul/common/exception.hh"
+#include "aul/common/log_private.hh"
+#include "aul/common/util.hh"
+#include "aul/include/aul.h"
+
+namespace aul {
+
+ResolveInfo::Builder& ResolveInfo::Builder::SetPkgName(std::string pkg_name) {
+ pkg_name_ = std::move(pkg_name);
+ return *this;
+}
+
+ResolveInfo::Builder& ResolveInfo::Builder::SetOperation(
+ std::string operation) {
+ operation_ = std::move(operation);
+ return *this;
+}
+
+ResolveInfo::Builder& ResolveInfo::Builder::SetUri(std::string uri) {
+ uri_ = std::move(uri);
+ return *this;
+}
+
+ResolveInfo::Builder& ResolveInfo::Builder::SetScheme(std::string scheme) {
+ scheme_ = std::move(scheme);
+ return *this;
+}
+
+ResolveInfo::Builder& ResolveInfo::Builder::SetHost(std::string host) {
+ host_ = std::move(host);
+ return *this;
+}
+
+ResolveInfo::Builder& ResolveInfo::Builder::SetUriRInfo(
+ std::string uri_r_info) {
+ uri_r_info_ = std::move(uri_r_info);
+ return *this;
+}
+
+ResolveInfo::Builder& ResolveInfo::Builder::SetOriginMime(
+ std::string origin_mime) {
+ origin_mime_ = std::move(origin_mime);
+ return *this;
+}
+
+ResolveInfo::Builder& ResolveInfo::Builder::SetMime(std::string mime) {
+ mime_ = std::move(mime);
+ return *this;
+}
+
+ResolveInfo::Builder& ResolveInfo::Builder::SetMType(std::string m_type) {
+ m_type_ = std::move(m_type);
+ return *this;
+}
+
+ResolveInfo::Builder& ResolveInfo::Builder::SetSType(std::string s_type) {
+ s_type_ = std::move(s_type);
+ return *this;
+}
+
+ResolveInfo::Builder& ResolveInfo::Builder::SetCategory(std::string category) {
+ category_ = std::move(category);
+ return *this;
+}
+
+ResolveInfo::Builder& ResolveInfo::Builder::SetWinId(std::string win_id) {
+ win_id_ = std::move(win_id);
+ return *this;
+}
+
+ResolveInfo* ResolveInfo::Builder::Build() {
+ return new (std::nothrow) ResolveInfo(std::move(pkg_name_),
+ std::move(operation_), std::move(uri_), std::move(scheme_),
+ std::move(host_), std::move(uri_r_info_), std::move(origin_mime_),
+ std::move(mime_), std::move(m_type_), std::move(s_type_),
+ std::move(category_), std::move(win_id_));
+}
+
+void ResolveInfo::Manager::GetMime(std::string& uri, std::string& mime) {
+ if (uri.empty())
+ return;
+
+ bool need_check = false;
+ int index;
+ if (uri.compare(0, 1, "/") == 0) {
+ if (mime.empty()) {
+ need_check = true;
+ index = 0;
+ }
+ } else if (uri.compare(0, 8, "file:///") == 0) {
+ if (mime.empty()) {
+ need_check = true;
+ index = 7;
+ }
+ } else if (uri.compare(0, 6, "file:/") == 0) {
+ if (mime.empty()) {
+ need_check = true;
+ index = 5;
+ }
+ }
+
+ if (need_check) {
+ char mime_buf[256] = { 0, };
+ int ret;
+ if (index > 0) {
+ ret = aul_get_mime_from_file(&(uri.c_str()[index]), mime_buf,
+ sizeof(mime_buf));
+ } else {
+ ret = aul_get_mime_from_file(uri.c_str(), mime_buf, sizeof(mime_buf));
+ uri = "";
+ }
+
+ if (ret != AUL_R_OK) {
+ _E("aul_get_mime_from_file() is failed. error(%d)", ret);
+ } else {
+ mime = mime_buf;
+ }
+ }
+}
+
+int ResolveInfo::Manager::GetSchemeAndHost(const std::string& uri,
+ std::string& scheme, std::string& host, std::string& uri_r_info) {
+ if (uri.empty()) {
+ scheme = "NULL";
+ return 0;
+ }
+
+ GError* error = nullptr;
+ GRegex* regex = g_regex_new("^(([^:/?#]+):)?(//([^/?#]*))?",
+ static_cast<GRegexCompileFlags>(0),
+ static_cast<GRegexMatchFlags>(0),
+ &error);
+ if (regex == nullptr) {
+ _E("g_regex_new() is failed");
+ g_clear_error(&error);
+ return -ENOMEM;
+ }
+ std::unique_ptr<GRegex, decltype(g_regex_unref)*> regex_ptr(
+ regex, g_regex_unref);
+
+ GMatchInfo* match_info = nullptr;
+ gboolean ret = g_regex_match(regex, uri.c_str(),
+ static_cast<GRegexMatchFlags>(0), &match_info);
+ if (!ret)
+ return -EINVAL;
+
+ std::unique_ptr<GMatchInfo, decltype(g_match_info_free)*>
+ match_info_ptr(match_info, g_match_info_free);
+
+ gchar* scheme_ptr = g_match_info_fetch(match_info, 2);
+ auto scheme_p = std::unique_ptr<gchar, decltype(g_free)*>(scheme_ptr, g_free);
+ if (scheme_ptr)
+ scheme = scheme_ptr;
+
+ gchar* host_ptr = g_match_info_fetch(match_info, 4);
+ auto host_p = std::unique_ptr<gchar, decltype(g_free)*>(host_ptr, g_free);
+ if (host_ptr)
+ host = host_ptr;
+
+ if (scheme_ptr && host_ptr)
+ uri_r_info = scheme + "://" + host;
+
+ return 0;
+}
+
+ResolveInfo* ResolveInfo::Manager::Create(const tizen_base::Bundle& b) {
+ ResolveInfo::Builder builder;
+ builder.SetPkgName(b.GetString(AUL_SVC_K_PKG_NAME));
+ builder.SetOperation(b.GetString(AUL_SVC_K_OPERATION));
+ builder.SetCategory(b.GetString(AUL_SVC_K_CATEGORY));
+ builder.SetWinId(b.GetString(AUL_SVC_K_WIN_ID));
+
+ std::string uri = b.GetString(AUL_SVC_K_URI);
+ std::string mime = b.GetString(AUL_SVC_K_MIME);
+ SECURE_LOGD("operation(%s), uri(%s), mime(%s)",
+ b.GetString(AUL_SVC_K_OPERATION).c_str(), uri.c_str(), mime.c_str());
+
+ GetMime(uri, mime);
+ builder.SetOriginMime(mime);
+
+ std::string scheme;
+ std::string host;
+ std::string uri_r_info;
+ int ret = GetSchemeAndHost(uri, scheme, host, uri_r_info);
+ if (ret != 0)
+ THROW(ret);
+
+ builder.SetUriRInfo(uri_r_info);
+ builder.SetScheme(scheme);
+ builder.SetHost(host);
+ builder.SetUri(uri);
+
+ if (mime.empty()) {
+ mime = "NULL";
+ } else {
+ auto vec = Util::Split(mime, "/");
+ if (vec.size() > 1) {
+ std::string m_type = vec[0];
+ if (strncmp(m_type.c_str(), "*", 1) == 0)
+ m_type = "%";
+
+ std::string s_type = vec[1];
+ if (strncmp(s_type.c_str(), "*", 1) == 0)
+ s_type = "%";
+
+ mime = m_type + "/" + s_type;
+
+ builder.SetMType(m_type);
+ builder.SetSType(s_type);
+ }
+ }
+ builder.SetMime(mime);
+
+ return builder.Build();
+}
+
+ResolveInfo::ResolveInfo(std::string pkg_name, std::string operation,
+ std::string uri, std::string scheme,
+ std::string host, std::string uri_r_info,
+ std::string origin_mime, std::string mime,
+ std::string m_type, std::string s_type,
+ std::string category, std::string win_id)
+ : pkg_name_(std::move(pkg_name)),
+ operation_(std::move(operation)),
+ uri_(std::move(uri)),
+ scheme_(std::move(scheme)),
+ host_(std::move(host)),
+ uri_r_info_(std::move(uri_r_info)),
+ origin_mime_(std::move(origin_mime)),
+ mime_(std::move(mime)),
+ m_type_(std::move(m_type)),
+ s_type_(std::move(s_type)),
+ category_(std::move(category)),
+ win_id_(std::move(win_id)) {
+}
+
+ResolveInfo::~ResolveInfo() = default;
+
+void ResolveInfo::SetUriRInfo(std::string uri_r_info) {
+ uri_r_info_ = std::move(uri_r_info);
+}
+
+const std::string& ResolveInfo::GetPkgName() const {
+ return pkg_name_;
+}
+
+const std::string& ResolveInfo::GetOperation() const {
+ return operation_;
+}
+
+const std::string& ResolveInfo::GetUri() const {
+ return uri_;
+}
+
+const std::string& ResolveInfo::GetScheme() const {
+ return scheme_;
+}
+
+const std::string& ResolveInfo::GetHost() const {
+ return host_;
+}
+
+const std::string& ResolveInfo::GetUriRInfo() const {
+ return uri_r_info_;
+}
+
+const std::string& ResolveInfo::GetOriginMime() const {
+ return origin_mime_;
+}
+
+const std::string& ResolveInfo::GetMime() const {
+ return mime_;
+}
+
+const std::string& ResolveInfo::GetMType() const {
+ return m_type_;
+}
+
+const std::string& ResolveInfo::GetSType() const {
+ return s_type_;
+}
+
+const std::string& ResolveInfo::GetCategory() const {
+ return category_;
+}
+
+const std::string& ResolveInfo::GetWinId() const {
+ return win_id_;
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2021 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_APP_CONTROL_RESOLVE_INFO_HH_
+#define AUL_APP_CONTROL_RESOLVE_INFO_HH_
+
+#include <bundle_cpp.h>
+
+#include <string>
+
+#include "aul/common/exception.hh"
+
+namespace aul {
+
+class ResolveInfo {
+ public:
+ class Builder {
+ public:
+ Builder& SetPkgName(std::string pkg_name);
+ Builder& SetOperation(std::string operation);
+ Builder& SetUri(std::string uri);
+ Builder& SetScheme(std::string scheme);
+ Builder& SetHost(std::string host);
+ Builder& SetUriRInfo(std::string uri_r_info);
+ Builder& SetOriginMime(std::string origin_mime);
+ Builder& SetMime(std::string mime);
+ Builder& SetMType(std::string m_type);
+ Builder& SetSType(std::string s_type);
+ Builder& SetCategory(std::string category);
+ Builder& SetWinId(std::string win_id);
+ ResolveInfo* Build();
+
+ private:
+ std::string pkg_name_;
+ std::string operation_;
+ std::string uri_;
+ std::string scheme_;
+ std::string host_;
+ std::string uri_r_info_;
+ std::string origin_mime_;
+ std::string mime_;
+ std::string m_type_;
+ std::string s_type_;
+ std::string category_;
+ std::string win_id_;
+ };
+
+ class Manager {
+ public:
+ static ResolveInfo* Create(const tizen_base::Bundle& b);
+ private:
+ static int GetSchemeAndHost(const std::string& uri,
+ std::string& scheme, std::string& host, std::string& uri_r_info);
+ static void GetMime(std::string& uri, std::string& mime);
+ };
+
+ ResolveInfo() = default;
+ ResolveInfo(std::string pkg_name, std::string operation,
+ std::string uri, std::string scheme,
+ std::string host, std::string uri_r_info,
+ std::string origin_mime, std::string mime,
+ std::string m_type, std::string s_type,
+ std::string category, std::string win_id);
+ virtual ~ResolveInfo();
+
+ void SetUriRInfo(std::string uri_r_info);
+
+ const std::string& GetPkgName() const;
+ const std::string& GetOperation() const;
+ const std::string& GetUri() const;
+ const std::string& GetScheme() const;
+ const std::string& GetHost() const;
+ const std::string& GetUriRInfo() const;
+ const std::string& GetOriginMime() const;
+ const std::string& GetMime() const;
+ const std::string& GetMType() const;
+ const std::string& GetSType() const;
+ const std::string& GetCategory() const;
+ const std::string& GetWinId() const;
+
+ private:
+ std::string pkg_name_;
+ std::string operation_;
+ std::string uri_;
+ std::string scheme_;
+ std::string host_;
+ std::string uri_r_info_;
+ std::string origin_mime_;
+ std::string mime_;
+ std::string m_type_;
+ std::string s_type_;
+ std::string category_;
+ std::string win_id_;
+};
+
+} // namespace aul
+
+#endif // AUL_APP_CONTROL_RESOLVE_INFO_HH_
--- /dev/null
+/*
+ * Copyright (c) 2015 - 2022 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 "aul/include/aul_app_group.h"
+
+#include <bundle_cpp.h>
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "aul/app_group/app_group_info.hh"
+#include "aul/app_request.h"
+#include "aul/aul_api.h"
+#include "aul/aul_util.h"
+#include "aul/common/exception.hh"
+#include "aul/include/aul.h"
+#include "aul/include/aul_error.h"
+#include "aul/include/aul_sock.h"
+#include "aul/launch.h"
+
+using namespace aul;
+using namespace aul::internal;
+
+struct aul_app_group_info_s {
+ void* dummy;
+};
+
+namespace {
+
+constexpr const int kMaxPacketLength = AUL_SOCK_MAXBUFF - AUL_PKT_HEADER_SIZE;
+
+AppGroupInfo* CreateAppGroupInfo(const tizen_base::Bundle& b) {
+ return AppGroupInfo::Builder()
+ .SetId(b)
+ .SetPid(b)
+ .SetAppId(b)
+ .SetPkgId(b)
+ .SetWid(b)
+ .SetFg(b)
+ .SetStatus(b);
+}
+
+std::vector<std::shared_ptr<AppGroupInfo>> ReceiveAppGroupInfos(int fd) {
+ std::vector<std::shared_ptr<AppGroupInfo>> infos;
+ int ret = aul_sock_recv_pkt_with_cb(fd,
+ [](app_pkt_t* pkt, void* user_data) {
+ if (pkt->cmd == APP_GET_INFO_ERROR || !(pkt->opt & AUL_SOCK_BUNDLE))
+ return;
+
+ bundle* kb = bundle_decode(pkt->data, pkt->len);
+ if (kb == nullptr) {
+ _E("bundle_decode() is failed");
+ return;
+ }
+
+ tizen_base::Bundle b(kb, false, true);
+ try {
+ auto* info = CreateAppGroupInfo(b);
+ if (info == nullptr) {
+ _E("Out of memory");
+ return;
+ }
+
+ auto* info_array =
+ static_cast<std::vector<std::shared_ptr<AppGroupInfo>>*>(
+ user_data);
+ info_array->emplace_back(info);
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%s)", e.what());
+ }
+ }, &infos);
+ if (ret < 0)
+ THROW(aul_error_convert(ret));
+
+ return infos;
+}
+
+std::vector<std::string> ReceiveLeaderIds(int fd) {
+ app_pkt_t* pkt = nullptr;
+ int ret = aul_sock_recv_reply_pkt(fd, &pkt);
+ if (ret < 0 || pkt == nullptr)
+ THROW(AUL_R_ERROR);
+
+ auto pkt_auto = std::unique_ptr<app_pkt_t, decltype(std::free)*>(
+ pkt, std::free);
+
+ bundle* kb = bundle_decode(pkt->data, pkt->len);
+ if (kb == nullptr) {
+ _E("bundle_decode() is failed. data(%s:%d)", pkt->data, pkt->len);
+ THROW(AUL_R_ERROR);
+ }
+
+ tizen_base::Bundle b(kb, false, true);
+ return b.GetStringArray(AUL_K_LEADER_IDS);
+}
+
+void ReceivePids(int fd, int* cnt, int** pids) {
+ app_pkt_t* pkt = nullptr;
+ int ret = aul_sock_recv_reply_pkt(fd, &pkt);
+ if (ret < 0 || pkt == nullptr)
+ THROW(AUL_R_ERROR);
+
+ auto pkt_auto = std::unique_ptr<app_pkt_t, decltype(std::free)*>(
+ pkt, std::free);
+
+ int count = pkt->len / sizeof(int);
+ if (count > 0 && pkt->len <= kMaxPacketLength) {
+ *pids = reinterpret_cast<int*>(calloc(1, pkt->len));
+ if (*pids == nullptr) {
+ _E("Out of memory");
+ THROW(AUL_R_ENOMEM);
+ }
+
+ memcpy(*pids, pkt->data, pkt->len);
+ *cnt = count;
+ }
+}
+
+} // namespace
+
+extern "C" API int aul_app_group_get_window(int pid) {
+ if (pid < 1) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ return AppRequest(APP_GROUP_GET_WINDOW, getuid())
+ .SetPid(pid)
+ .SendSimply();
+}
+
+extern "C" API int aul_app_group_set_window(int wid) {
+ if (wid < 1) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ tizen_base::Bundle b { { AUL_K_WID, std::to_string(wid) } };
+ return AppRequest(APP_GROUP_SET_WINDOW, getuid())
+ .With(std::move(b))
+ .SendSimply(AUL_SOCK_NOREPLY);
+}
+
+extern "C" API void aul_app_group_get_leader_pids(int* cnt, int** pids) {
+ if (cnt == nullptr || pids == nullptr) {
+ _E("Invalid parameter");
+ return;
+ }
+
+ *cnt = 0;
+ *pids = nullptr;
+
+ int fd = AppRequest(APP_GROUP_GET_LEADER_PIDS, getuid())
+ .SendCmdOnly(AUL_SOCK_ASYNC);
+ if (fd < 0)
+ return;
+
+ try {
+ ReceivePids(fd, cnt, pids);
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%s)", e.what());
+ }
+}
+
+extern "C" API void aul_app_group_get_group_pids(int leader_pid, int* cnt,
+ int** pids) {
+ if (leader_pid < 1 || cnt == nullptr || pids == nullptr) {
+ _E("Invalid parameter");
+ return;
+ }
+
+ *cnt = 0;
+ *pids = nullptr;
+
+ tizen_base::Bundle b { { AUL_K_LEADER_PID, std::to_string(leader_pid) } };
+ int fd = AppRequest(APP_GROUP_GET_GROUP_PIDS, getuid())
+ .With(std::move(b))
+ .SendSimply(AUL_SOCK_ASYNC);
+ if (fd < 0)
+ return;
+
+ try {
+ ReceivePids(fd, cnt, pids);
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%s)", e.what());
+ }
+}
+
+extern "C" API int aul_app_group_get_leader_pid(int pid) {
+ if (pid < 1) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ return AppRequest(APP_GROUP_GET_LEADER_PID, getuid())
+ .SetPid(pid)
+ .SendSimply();
+}
+
+extern "C" API int aul_app_group_clear_top(void) {
+ return AppRequest(APP_GROUP_CLEAR_TOP, getuid())
+ .SendCmdOnly();
+}
+
+extern "C" API int aul_app_group_is_top(void) {
+ int leader_pid = aul_app_group_get_leader_pid(getpid());
+ if (leader_pid < 1)
+ return 1;
+
+ int cnt = 0;
+ int* pids = nullptr;
+ aul_app_group_get_group_pids(leader_pid, &cnt, &pids);
+ auto pids_auto = std::unique_ptr<int, decltype(std::free)*>(pids, std::free);
+ if (cnt > 0 && pids != nullptr) {
+ if (pids[cnt - 1] == getpid())
+ return 1;
+
+ return 0;
+ }
+
+ return 1;
+}
+
+extern "C" API int aul_app_group_get_fg_flag(int pid) {
+ if (pid < 1) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ return AppRequest(APP_GROUP_GET_FG, getuid())
+ .SetPid(pid)
+ .SendSimply();
+}
+
+extern "C" API void aul_app_group_lower(int* exit) {
+ if (exit == nullptr) {
+ _E("Invalid parameter");
+ return;
+ }
+
+ int ret = AppRequest(APP_GROUP_LOWER, getuid())
+ .SendCmdOnly();
+ if (ret < 0)
+ return;
+
+ *exit = ret;
+}
+
+extern "C" API void aul_app_group_get_idle_pids(int* cnt, int** pids) {
+ if (cnt == nullptr || pids == nullptr) {
+ _E("Invalid parameter");
+ return;
+ }
+
+ *cnt = 0;
+ *pids = nullptr;
+ int fd = AppRequest(APP_GROUP_GET_IDLE_PIDS, getuid())
+ .SendCmdOnly(AUL_SOCK_ASYNC);
+ if (fd < 0)
+ return;
+
+ try {
+ ReceivePids(fd, cnt, pids);
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%s)", e.what());
+ }
+}
+
+extern "C" API int aul_app_group_activate_below(const char* below_appid) {
+ if (below_appid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ return AppRequest(APP_GROUP_ACTIVATE_BELOW, getuid())
+ .SetAppId(below_appid)
+ .SendSimply();
+}
+
+extern "C" API int aul_app_group_activate_above(const char* above_appid) {
+ if (above_appid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ return AppRequest(APP_GROUP_ACTIVATE_ABOVE, getuid())
+ .SetAppId(above_appid)
+ .SendSimply();
+}
+
+extern "C" API int aul_app_group_set_window_v2(const char* inst_id, int wid) {
+ if (inst_id == nullptr || wid < 1) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ tizen_base::Bundle b {
+ { AUL_K_INSTANCE_ID, inst_id },
+ { AUL_K_WID, std::to_string(wid) }
+ };
+
+ return AppRequest(APP_GROUP_SET_WINDOW_V2, getuid())
+ .With(std::move(b))
+ .SendSimply(AUL_SOCK_NOREPLY);
+}
+
+extern "C" API int aul_app_group_lower_v2(const char* inst_id, bool* exit) {
+ if (inst_id == nullptr || exit == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ int ret = AppRequest(APP_GROUP_LOWER_V2, getuid())
+ .SetInstId(inst_id)
+ .SendSimply();
+ if (ret < 0)
+ return ret;
+
+ *exit = (ret == 0) ? false : true;
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_app_group_foreach_leader_ids(
+ aul_app_group_leader_id_cb callback, void* user_data) {
+ if (callback == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ int fd = AppRequest(APP_GROUP_GET_LEADER_IDS, getuid())
+ .SendCmdOnly(AUL_SOCK_ASYNC);
+ if (fd < 0)
+ return aul_error_convert(fd);
+
+ try {
+ for (auto const& id : ReceiveLeaderIds(fd))
+ callback(id.c_str(), user_data);
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%s)", e.what());
+ return e.GetErrorCode();
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_app_group_foreach_group_info(const char* leader_id,
+ aul_app_group_info_cb callback, void* user_data) {
+ if (leader_id == nullptr || callback == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ tizen_base::Bundle b { { AUL_K_LEADER_ID, leader_id } };
+ int fd = AppRequest(APP_GROUP_GET_GROUP_INFO, getuid())
+ .With(std::move(b))
+ .SendSimply(AUL_SOCK_ASYNC);
+ if (fd < 0)
+ return aul_error_convert(fd);
+
+ try {
+ for (auto const& info : ReceiveAppGroupInfos(fd))
+ callback(reinterpret_cast<aul_app_group_info_h>(info.get()), user_data);
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%s)", e.what());
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_app_group_foreach_idle_info(
+ aul_app_group_info_cb callback, void* user_data) {
+ if (callback == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ int fd = AppRequest(APP_GROUP_GET_IDLE_INFO, getuid())
+ .SendCmdOnly(AUL_SOCK_ASYNC);
+ if (fd < 0)
+ return aul_error_convert(fd);
+
+ try {
+ for (auto const& info : ReceiveAppGroupInfos(fd))
+ callback(reinterpret_cast<aul_app_group_info_h>(info.get()), user_data);
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%s)", e.what());
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_app_group_info_get_id(aul_app_group_info_h h,
+ const char** id) {
+ if (h == nullptr || id == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* info = reinterpret_cast<AppGroupInfo*>(h);
+ *id = info->GetId().c_str();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_app_group_info_get_pid(aul_app_group_info_h h,
+ pid_t* pid) {
+ if (h == nullptr || pid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* info = reinterpret_cast<AppGroupInfo*>(h);
+ *pid = info->GetPid();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_app_group_info_get_appid(aul_app_group_info_h h,
+ const char** appid) {
+ if (h == nullptr || appid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* info = reinterpret_cast<AppGroupInfo*>(h);
+ *appid = info->GetAppId().c_str();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_app_group_info_get_pkgid(aul_app_group_info_h h,
+ const char** pkgid) {
+ if (h == nullptr || pkgid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* info = reinterpret_cast<AppGroupInfo*>(h);
+ *pkgid = info->GetPkgId().c_str();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_app_group_info_get_window(aul_app_group_info_h h,
+ int* wid) {
+ if (h == nullptr || wid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* info = reinterpret_cast<AppGroupInfo*>(h);
+ *wid = info->GetWid();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_app_group_info_get_fg_flag(aul_app_group_info_h h,
+ bool* fg_flag) {
+ if (h == nullptr || fg_flag == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* info = reinterpret_cast<AppGroupInfo*>(h);
+ *fg_flag = info->IsFg();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_app_group_info_get_status(aul_app_group_info_h h,
+ int* status) {
+ if (h == nullptr || status == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* info = reinterpret_cast<AppGroupInfo*>(h);
+ *status = info->GetStatus();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_app_group_add(int wid) {
+ if (wid < 1) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ tizen_base::Bundle b { { AUL_K_WID, std::to_string(wid) } };
+ return AppRequest(APP_GROUP_ADD, getuid())
+ .With(std::move(b))
+ .SendSimply(AUL_SOCK_NOREPLY);
+}
+
+extern "C" API int aul_app_group_remove(int wid) {
+ if (wid < 1) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ tizen_base::Bundle b { { AUL_K_WID, std::to_string(wid) } };
+ return AppRequest(APP_GROUP_REMOVE, getuid())
+ .With(std::move(b))
+ .SendSimply(AUL_SOCK_NOREPLY);
+}
--- /dev/null
+/*
+ * Copyright (c) 2022 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 "aul/app_group/app_group_info.hh"
+
+#include "include/aul.h"
+#include "aul/common/exception.hh"
+
+namespace aul {
+
+AppGroupInfo::Builder& AppGroupInfo::Builder::SetId(
+ const tizen_base::Bundle& b) {
+ id_ = std::move(b.GetString(AUL_K_INSTANCE_ID));
+ return *this;
+}
+
+AppGroupInfo::Builder& AppGroupInfo::Builder::SetPid(
+ const tizen_base::Bundle& b) {
+ auto pid_str = b.GetString(AUL_K_PID);
+ if (pid_str.empty())
+ return *this;
+
+ pid_ = std::stoi(pid_str);
+ return *this;
+}
+
+AppGroupInfo::Builder& AppGroupInfo::Builder::SetAppId(
+ const tizen_base::Bundle& b) {
+ appid_ = std::move(b.GetString(AUL_K_APPID));
+ return *this;
+}
+
+AppGroupInfo::Builder& AppGroupInfo::Builder::SetPkgId(
+ const tizen_base::Bundle& b) {
+ pkgid_ = std::move(b.GetString(AUL_K_PKGID));
+ return *this;
+}
+
+AppGroupInfo::Builder& AppGroupInfo::Builder::SetWid(
+ const tizen_base::Bundle& b) {
+ auto wid_str = b.GetString(AUL_K_WID);
+ if (wid_str.empty())
+ return *this;
+
+ wid_ = std::stoi(wid_str);
+ return *this;
+}
+
+AppGroupInfo::Builder& AppGroupInfo::Builder::SetFg(
+ const tizen_base::Bundle& b) {
+ auto fg_str = b.GetString(AUL_K_FG_FLAG);
+ if (fg_str.empty())
+ return *this;
+
+ fg_ = std::stoi(fg_str) ? true : false;
+ return *this;
+}
+
+AppGroupInfo::Builder& AppGroupInfo::Builder::SetStatus(
+ const tizen_base::Bundle& b) {
+ auto status_str = b.GetString(AUL_K_STATUS);
+ if (status_str.empty())
+ return *this;
+
+ status_ = std::stoi(status_str);
+ return *this;
+}
+
+AppGroupInfo::Builder::operator AppGroupInfo*() {
+ Validate();
+ return new (std::nothrow) AppGroupInfo(std::move(id_), pid_,
+ std::move(appid_), std::move(pkgid_), wid_, fg_, status_);
+}
+
+void AppGroupInfo::Builder::Validate() {
+ if (id_.empty() ||
+ pid_ < 1 ||
+ appid_.empty() ||
+ pkgid_.empty() ||
+ wid_ < 0 ||
+ status_ < 0) {
+ _E("id(%s), pid(%d), appid(%s), pkgid(%s), wid(%d), status(%d)",
+ id_.c_str(), pid_, appid_.c_str(), pkgid_.c_str(), wid_, status_);
+ THROW(AUL_R_ERROR);
+ }
+}
+
+AppGroupInfo::AppGroupInfo(std::string id, pid_t pid, std::string appid,
+ std::string pkgid, int wid, bool fg, int status)
+ : id_(std::move(id)),
+ pid_(pid),
+ appid_(std::move(appid)),
+ pkgid_(std::move(pkgid)),
+ wid_(wid),
+ fg_(fg),
+ status_(status) {
+}
+
+const std::string& AppGroupInfo::GetId() const {
+ return id_;
+}
+
+pid_t AppGroupInfo::GetPid() const {
+ return pid_;
+}
+
+const std::string& AppGroupInfo::GetAppId() const {
+ return appid_;
+}
+
+const std::string& AppGroupInfo::GetPkgId() const {
+ return pkgid_;
+}
+
+int AppGroupInfo::GetWid() const {
+ return wid_;
+}
+
+bool AppGroupInfo::IsFg() const {
+ return fg_;
+}
+
+int AppGroupInfo::GetStatus() const {
+ return status_;
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2022 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_APP_GROUP_APP_GROUP_INFO_HH
+#define AUL_APP_GROUP_APP_GROUP_INFO_HH
+
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <bundle_cpp.h>
+
+#include <string>
+
+namespace aul {
+
+class AppGroupInfo {
+ public:
+ class Builder {
+ public:
+ Builder& SetId(const tizen_base::Bundle& b);
+ Builder& SetPid(const tizen_base::Bundle& b);
+ Builder& SetAppId(const tizen_base::Bundle& b);
+ Builder& SetPkgId(const tizen_base::Bundle& b);
+ Builder& SetWid(const tizen_base::Bundle& b);
+ Builder& SetFg(const tizen_base::Bundle& b);
+ Builder& SetStatus(const tizen_base::Bundle& b);
+ operator AppGroupInfo*();
+
+ private:
+ void Validate();
+
+ private:
+ std::string id_;
+ pid_t pid_ = -1;
+ std::string appid_;
+ std::string pkgid_;
+ int wid_ = -1;
+ bool fg_ = false;
+ int status_ = -1;
+ };
+
+ AppGroupInfo(std::string id, pid_t pid, std::string appid,
+ std::string pkgid, int wid, bool fg, int status);
+
+ const std::string& GetId() const;
+ pid_t GetPid() const;
+ const std::string& GetAppId() const;
+ const std::string& GetPkgId() const;
+ int GetWid() const;
+ bool IsFg() const;
+ int GetStatus() const;
+
+ private:
+ std::string id_;
+ pid_t pid_ = -1;
+ std::string appid_;
+ std::string pkgid_;
+ int wid_ = -1;
+ bool fg_ = false;
+ int status_ = -1;
+};
+
+} // namespace aul
+
+#endif // AUL_APP_GROUP_APP_GROUP_INFO_HH
--- /dev/null
+/*
+ * Copyright (c) 2021 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 <pkgmgr-info.h>
+
+#include <string>
+
+#include "aul/app_info/app_info.hh"
+#include "aul/common/exception.hh"
+#include "aul/socket/client.hh"
+#include "include/aul.h"
+#include "include/aul_cmd.h"
+#include "include/aul_error.h"
+#include "include/aul_sock.h"
+
+namespace aul {
+
+AppInfo::Builder& AppInfo::Builder::SetAppId(std::string app_id) {
+ app_id_ = std::move(app_id);
+ return *this;
+}
+
+AppInfo::Builder& AppInfo::Builder::SetPkgId(std::string pkg_id) {
+ pkg_id_ = std::move(pkg_id);
+ return *this;
+}
+
+AppInfo::Builder& AppInfo::Builder::SetRootPath(std::string root_path) {
+ root_path_ = std::move(root_path);
+ return *this;
+}
+
+AppInfo::Builder& AppInfo::Builder::SetLightUserSwitchMode(std::string mode) {
+ light_user_switch_mode_ = std::move(mode);
+ return *this;
+}
+
+AppInfo::Builder::operator AppInfo*() {
+ return new (std::nothrow) AppInfo(std::move(app_id_), std::move(pkg_id_),
+ std::move(root_path_), std::move(light_user_switch_mode_));
+}
+
+AppInfo* AppInfo::Get(const std::string& app_id, uid_t uid) {
+ pkgmgrinfo_appinfo_h handle;
+ int ret = pkgmgrinfo_appinfo_get_usr_appinfo(app_id.c_str(), uid, &handle);
+ if (ret != PMINFO_R_OK) {
+ _E("Failed to get appinfo. app_id(%s), uid(%u), error(%d)",
+ app_id.c_str(), uid, ret);
+ return nullptr;
+ }
+
+ std::unique_ptr<std::remove_pointer<pkgmgrinfo_appinfo_h>::type,
+ decltype(pkgmgrinfo_appinfo_destroy_appinfo)*> ptr(handle,
+ pkgmgrinfo_appinfo_destroy_appinfo);
+
+ char* pkg_id;
+ ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkg_id);
+ if (ret != PMINFO_R_OK) {
+ _E("Failed to get pkgid. error(%d)", ret);
+ return nullptr;
+ }
+
+ char* root_path;
+ ret = pkgmgrinfo_appinfo_get_root_path(handle, &root_path);
+ if (ret != PMINFO_R_OK) {
+ _E("Failed to get root path. error(%d)", ret);
+ return nullptr;
+ }
+
+ char* mode;
+ ret = pkgmgrinfo_appinfo_get_light_user_switch_mode(handle, &mode);
+ if (ret != PMINFO_R_OK) {
+ _E("Failed to get light user switch mode. error(%d)", ret);
+ return nullptr;
+ }
+
+ return Builder().SetAppId(app_id).SetPkgId(pkg_id)
+ .SetRootPath(root_path).SetLightUserSwitchMode(mode);
+}
+
+AppInfo* AppInfo::Get(int pid) {
+ char app_id[256] = { 0, };
+ int ret = aul_app_get_appid_bypid(pid, app_id, sizeof(app_id));
+ if (ret != AUL_R_OK)
+ return nullptr;
+
+ if (pid != getpid())
+ return Get(app_id, getuid());
+
+ char pkg_id[256] = { 0, };
+ ret = aul_app_get_appid_bypid(pid, pkg_id, sizeof(pkg_id));
+ if (ret != AUL_R_OK)
+ return Get(app_id, getuid());
+
+ const char* root_path = aul_get_preinit_root_path();
+ if (root_path == nullptr)
+ return Get(app_id, getuid());
+
+ return Builder().SetAppId(app_id).SetPkgId(pkg_id).SetRootPath(root_path);
+}
+
+AppInfo::AppInfo(std::string app_id, std::string pkg_id,
+ std::string root_path, std::string light_user_switch_mode)
+ : app_id_(std::move(app_id)),
+ pkg_id_(std::move(pkg_id)),
+ root_path_(std::move(root_path)),
+ light_user_switch_mode_(std::move(light_user_switch_mode)) {
+}
+
+const std::string& AppInfo::GetAppId() const {
+ return app_id_;
+}
+
+const std::string& AppInfo::GetPkgId() const {
+ return pkg_id_;
+}
+
+const std::string& AppInfo::GetRootPath() const {
+ return root_path_;
+}
+
+const std::string& AppInfo::GetLightUserSwitchMode() const {
+ return light_user_switch_mode_;
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2021 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_APP_INFO_APP_INFO_HH
+#define AUL_APP_INFO_APP_INFO_HH
+
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <string>
+
+namespace aul {
+
+class AppInfo {
+ public:
+ class Builder {
+ public:
+ Builder& SetAppId(std::string app_id);
+ Builder& SetPkgId(std::string pkg_id);
+ Builder& SetRootPath(std::string root_path);
+ Builder& SetLightUserSwitchMode(std::string mode);
+ operator AppInfo*();
+
+ private:
+ std::string app_id_;
+ std::string pkg_id_;
+ std::string root_path_;
+ std::string light_user_switch_mode_;
+ };
+
+ static AppInfo* Get(const std::string& app_id, uid_t uid);
+ static AppInfo* Get(int pid);
+
+ AppInfo(std::string app_id,
+ std::string pkg_id,
+ std::string root_path,
+ std::string light_user_switch_mode);
+
+ const std::string& GetAppId() const;
+ const std::string& GetPkgId() const;
+ const std::string& GetRootPath() const;
+ const std::string& GetLightUserSwitchMode() const;
+
+ private:
+ std::string app_id_;
+ std::string pkg_id_;
+ std::string root_path_;
+ std::string light_user_switch_mode_;
+};
+
+} // namespace aul
+
+#endif // AUL_APP_INFO_APP_INFO_HH
--- /dev/null
+/*
+ * Copyright (c) 2021 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 <sys/types.h>
+#include <tzplatform_config.h>
+#include <unistd.h>
+
+#include <memory>
+
+#include "aul/app_info/app_info.hh"
+#include "aul/app_info/directory_info.hh"
+#include "aul/common/common.hh"
+#include "aul/common/log_private.hh"
+#include "include/aul.h"
+
+namespace aul {
+namespace {
+
+constexpr const char kDataDir[] = "data/";
+constexpr const char kCacheDir[] = "cache/";
+constexpr const char kResourceDir[] = "res/";
+constexpr const char kTepResourceDir[] = "tep/mount/";
+constexpr const char kSharedDataDir[] = "shared/data/";
+constexpr const char kSharedTrustedDir[] = "shared/trusted/";
+constexpr const char kSharedResourceDir[] = "shared/res/";
+constexpr const char kAppRWDir[] = "apps_rw/";
+constexpr const char kLightUserSwitchModeDefault[] = "default";
+constexpr const char kResControlAllowedDir[] = "res/mount/allowed/";
+constexpr const char kResControlGlobalDir[] = "res/mount/global/";
+
+std::string GetRWPath(const std::string& pkg_id, uid_t uid) {
+ tzplatform_set_user(uid);
+ std::string path = std::string(tzplatform_getenv(TZ_USER_APP)) + "/" + pkg_id;
+ tzplatform_reset_user();
+ return path;
+}
+
+std::string GetPath(const std::string& path,
+ const std::string& dir_name) {
+ return path + "/" + dir_name;
+}
+
+} // namespace
+
+DirectoryInfo::Builder& DirectoryInfo::Builder::SetRootPath(
+ std::string root_path) {
+ root_path_ = std::move(root_path);
+ return *this;
+}
+
+DirectoryInfo::Builder& DirectoryInfo::Builder::SetDataPath(
+ std::string data_path) {
+ data_path_ = std::move(data_path);
+ return *this;
+}
+
+DirectoryInfo::Builder& DirectoryInfo::Builder::SetCachePath(
+ std::string cache_path) {
+ cache_path_ = std::move(cache_path);
+ return *this;
+}
+
+DirectoryInfo::Builder& DirectoryInfo::Builder::SetResourcePath(
+ std::string resource_path) {
+ resource_path_ = std::move(resource_path);
+ return *this;
+}
+
+DirectoryInfo::Builder& DirectoryInfo::Builder::SetTepResourcePath(
+ std::string tep_resource_path) {
+ tep_resource_path_ = std::move(tep_resource_path);
+ return *this;
+}
+
+DirectoryInfo::Builder& DirectoryInfo::Builder::SetSharedDataPath(
+ std::string shared_data_path) {
+ shared_data_path_ = std::move(shared_data_path);
+ return *this;
+}
+
+DirectoryInfo::Builder& DirectoryInfo::Builder::SetSharedResourcePath(
+ std::string shared_resource_path) {
+ shared_resource_path_ = std::move(shared_resource_path);
+ return *this;
+}
+
+DirectoryInfo::Builder& DirectoryInfo::Builder::SetSharedTrustedPath(
+ std::string shared_trusted_path) {
+ shared_trusted_path_ = std::move(shared_trusted_path);
+ return *this;
+}
+
+DirectoryInfo::Builder& DirectoryInfo::Builder::SetResControlAllowedPath(
+ std::string res_control_allowed_res_path) {
+ res_control_allowed_res_path_ = std::move(res_control_allowed_res_path);
+ return *this;
+}
+
+DirectoryInfo::Builder& DirectoryInfo::Builder::SetResControlGlobalPath(
+ std::string res_control_global_res_path) {
+ res_control_global_res_path_ = std::move(res_control_global_res_path);
+ return *this;
+}
+
+DirectoryInfo::Builder::operator DirectoryInfo*() {
+ return new (std::nothrow) DirectoryInfo(std::move(root_path_),
+ std::move(data_path_), std::move(cache_path_),
+ std::move(resource_path_), std::move(tep_resource_path_),
+ std::move(shared_data_path_), std::move(shared_resource_path_),
+ std::move(shared_trusted_path_), std::move(res_control_allowed_res_path_),
+ std::move(res_control_global_res_path_));
+}
+
+DirectoryInfo* DirectoryInfo::Get(const std::string app_id,
+ uid_t uid) {
+ std::unique_ptr<AppInfo> info(AppInfo::Get(app_id, uid));
+ if (info.get() == nullptr)
+ return nullptr;
+
+ std::string root_path = info->GetRootPath();
+ std::string rw_path = GetRWPath(info->GetPkgId(), uid);
+ return Builder().SetRootPath(info->GetRootPath())
+ .SetDataPath(GetPath(rw_path, kDataDir))
+ .SetCachePath(GetPath(rw_path, kCacheDir))
+ .SetResourcePath(GetPath(root_path, kResourceDir))
+ .SetTepResourcePath(GetPath(root_path, kTepResourceDir))
+ .SetSharedDataPath(GetPath(rw_path, kSharedDataDir))
+ .SetSharedResourcePath(GetPath(root_path, kSharedResourceDir))
+ .SetSharedTrustedPath(GetPath(rw_path, kSharedTrustedDir))
+ .SetResControlAllowedPath(GetPath(root_path, kResControlAllowedDir))
+ .SetResControlGlobalPath(GetPath(root_path, kResControlGlobalDir));
+}
+
+DirectoryInfo* DirectoryInfo::Get() {
+ char app_id[256] = { 0, };
+ int ret = aul_app_get_appid_bypid(getpid(), app_id, sizeof(app_id));
+ if (ret != AUL_R_OK)
+ return nullptr;
+
+ return Get(app_id, getuid());
+}
+
+DirectoryInfo::DirectoryInfo(std::string root_path,
+ std::string data_path,
+ std::string cache_path,
+ std::string resource_path,
+ std::string tep_resource_path,
+ std::string shared_data_path,
+ std::string shared_resource_path,
+ std::string shared_trusted_path,
+ std::string res_control_allowed_res_path,
+ std::string res_control_global_res_path)
+ : root_path_(std::move(root_path)),
+ data_path_(std::move(data_path)),
+ cache_path_(std::move(cache_path)),
+ resource_path_(std::move(resource_path)),
+ tep_resource_path_(std::move(tep_resource_path)),
+ shared_data_path_(std::move(shared_data_path)),
+ shared_resource_path_(std::move(shared_resource_path)),
+ shared_trusted_path_(std::move(shared_trusted_path)),
+ res_control_allowed_res_path_(std::move(res_control_allowed_res_path)),
+ res_control_global_res_path_(std::move(res_control_global_res_path)) {
+}
+
+const std::string& DirectoryInfo::GetRootPath() const {
+ return root_path_;
+}
+
+const std::string& DirectoryInfo::GetDataPath() const {
+ return data_path_;
+}
+
+const std::string& DirectoryInfo::GetCachePath() const {
+ return cache_path_;
+}
+
+const std::string& DirectoryInfo::GetResourcePath() const {
+ return resource_path_;
+}
+
+const std::string& DirectoryInfo::GetTepResourcePath() const {
+ return tep_resource_path_;
+}
+
+const std::string& DirectoryInfo::GetSharedDataPath() const {
+ return shared_data_path_;
+}
+
+const std::string& DirectoryInfo::GetSharedResourcePath() const {
+ return shared_resource_path_;
+}
+
+const std::string& DirectoryInfo::GetSharedTrustedPath() const {
+ return shared_trusted_path_;
+}
+
+const std::string& DirectoryInfo::GetResControlAllowedResPath() const {
+ return res_control_allowed_res_path_;
+}
+
+const std::string& DirectoryInfo::GetResControlGlobalResPath() const {
+ return res_control_global_res_path_;
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2021 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_APP_INFO_DIRECTORY_INFO_HH
+#define AUL_APP_INFO_DIRECTORY_INFO_HH
+
+#include <string>
+
+namespace aul {
+
+class DirectoryInfo {
+ public:
+ static DirectoryInfo* Get(const std::string app_id, uid_t uid);
+ static DirectoryInfo* Get();
+
+ const std::string& GetRootPath() const;
+ const std::string& GetDataPath() const;
+ const std::string& GetCachePath() const;
+ const std::string& GetResourcePath() const;
+ const std::string& GetTepResourcePath() const;
+ const std::string& GetSharedDataPath() const;
+ const std::string& GetSharedResourcePath() const;
+ const std::string& GetSharedTrustedPath() const;
+ const std::string& GetResControlAllowedResPath() const;
+ const std::string& GetResControlGlobalResPath() const;
+
+ private:
+ class Builder {
+ public:
+ Builder& SetRootPath(std::string root_path);
+ Builder& SetDataPath(std::string data_path);
+ Builder& SetCachePath(std::string cache_path);
+ Builder& SetResourcePath(std::string resource_path);
+ Builder& SetTepResourcePath(std::string tep_resource_path);
+ Builder& SetSharedDataPath(std::string shared_data_path);
+ Builder& SetSharedResourcePath(std::string shared_resource_path);
+ Builder& SetSharedTrustedPath(std::string shared_trusted_path);
+ Builder& SetResControlAllowedPath(std::string res_control_allowed_res_path);
+ Builder& SetResControlGlobalPath(std::string res_control_global_res_path);
+
+ operator DirectoryInfo*();
+
+ private:
+ std::string root_path_;
+ std::string rw_path_;
+ std::string data_path_;
+ std::string cache_path_;
+ std::string resource_path_;
+ std::string tep_resource_path_;
+ std::string shared_data_path_;
+ std::string shared_resource_path_;
+ std::string shared_trusted_path_;
+ std::string res_control_allowed_res_path_;
+ std::string res_control_global_res_path_;
+ };
+
+ DirectoryInfo(std::string root_path,
+ std::string data_path,
+ std::string cache_path,
+ std::string resource_path,
+ std::string tep_resource_path,
+ std::string shared_data_path,
+ std::string shared_resource_path,
+ std::string shared_trusted_path,
+ std::string res_control_allowed_res_path,
+ std::string res_control_global_res_path);
+
+ private:
+ std::string root_path_;
+ std::string data_path_;
+ std::string cache_path_;
+ std::string resource_path_;
+ std::string tep_resource_path_;
+ std::string shared_data_path_;
+ std::string shared_resource_path_;
+ std::string shared_trusted_path_;
+ std::string res_control_allowed_res_path_;
+ std::string res_control_global_res_path_;
+};
+
+} // namespace aul
+
+#endif // AUL_APP_INFO_DIRECTORY_INFO_HH
--- /dev/null
+/*
+ * Copyright (c) 2021 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 <storage-internal.h>
+#include <sys/types.h>
+#include <tzplatform_config.h>
+#include <unistd.h>
+
+#include <memory>
+
+#include "aul/app_info/app_info.hh"
+#include "aul/app_info/external_directory_info.hh"
+#include "aul/common/common.hh"
+#include "aul/common/log_private.hh"
+#include "include/aul.h"
+
+namespace aul {
+namespace {
+
+constexpr const char kDefaultExternalStorage[] = "/opt/media/sdcard";
+constexpr const char kDataDir[] = "data/";
+constexpr const char kCacheDir[] = "cache/";
+constexpr const char kSharedDataDir[] = "shared/data/";
+
+std::string GetSdCardPath() {
+ int storage_id = 0;
+ char* path = nullptr;
+ int ret = storage_get_primary_sdcard(&storage_id, &path);
+ if (ret != STORAGE_ERROR_NONE)
+ _W("Failed to get primary sdcard. error(%d)", ret);
+
+ auto ptr = std::unique_ptr<char, decltype(std::free)*>(path, std::free);
+ if (path)
+ return std::string(path);
+
+ return std::string(kDefaultExternalStorage);
+}
+
+std::string GetExternalPath(const std::string& pkg_id, uid_t uid) {
+ std::string sdcard_path = GetSdCardPath();
+ tzplatform_set_user(uid);
+ std::string path = sdcard_path + "/apps/" +
+ std::string(tzplatform_getenv(TZ_USER_NAME)) + "/apps_rw/" +
+ pkg_id;
+ tzplatform_reset_user();
+ return path;
+}
+
+std::string GetPath(const std::string& path,
+ const std::string& dir_name) {
+ return path + "/" + dir_name;
+}
+
+} // namespace
+
+ExternalDirectoryInfo::Builder& ExternalDirectoryInfo::Builder::SetRootPath(
+ std::string root_path) {
+ root_path_ = std::move(root_path);
+ return *this;
+}
+
+ExternalDirectoryInfo::Builder& ExternalDirectoryInfo::Builder::SetDataPath(
+ std::string data_path) {
+ data_path_ = std::move(data_path);
+ return *this;
+}
+
+ExternalDirectoryInfo::Builder& ExternalDirectoryInfo::Builder::SetCachePath(
+ std::string cache_path) {
+ cache_path_ = std::move(cache_path);
+ return *this;
+}
+
+ExternalDirectoryInfo::Builder&
+ExternalDirectoryInfo::Builder::SetSharedDataPath(
+ std::string shared_data_path) {
+ shared_data_path_ = std::move(shared_data_path);
+ return *this;
+}
+
+ExternalDirectoryInfo::Builder::operator ExternalDirectoryInfo*() {
+ return new (std::nothrow) ExternalDirectoryInfo(std::move(root_path_),
+ std::move(data_path_), std::move(cache_path_),
+ std::move(shared_data_path_));
+}
+
+ExternalDirectoryInfo* ExternalDirectoryInfo::Get(const std::string app_id,
+ uid_t uid) {
+ std::unique_ptr<AppInfo> info(AppInfo::Get(app_id, uid));
+ if (info.get() == nullptr)
+ return nullptr;
+
+ std::string external_path = GetExternalPath(info->GetPkgId(), uid);
+ return Builder().SetRootPath(std::string(external_path) + "/")
+ .SetDataPath(GetPath(external_path, kDataDir))
+ .SetCachePath(GetPath(external_path, kCacheDir))
+ .SetSharedDataPath(GetPath(external_path, kSharedDataDir));
+}
+
+ExternalDirectoryInfo* ExternalDirectoryInfo::Get() {
+ char app_id[256] = { 0, };
+ int ret = aul_app_get_appid_bypid(getpid(), app_id, sizeof(app_id));
+ if (ret != AUL_R_OK)
+ return nullptr;
+
+ return Get(app_id, getuid());
+}
+
+ExternalDirectoryInfo::ExternalDirectoryInfo(std::string root_path,
+ std::string data_path,
+ std::string cache_path,
+ std::string shared_data_path)
+ : root_path_(std::move(root_path)),
+ data_path_(std::move(data_path)),
+ cache_path_(std::move(cache_path)),
+ shared_data_path_(std::move(shared_data_path)) {
+}
+
+const std::string& ExternalDirectoryInfo::GetRootPath() const {
+ return root_path_;
+}
+
+const std::string& ExternalDirectoryInfo::GetDataPath() const {
+ return data_path_;
+}
+
+const std::string& ExternalDirectoryInfo::GetCachePath() const {
+ return cache_path_;
+}
+
+const std::string& ExternalDirectoryInfo::GetSharedDataPath() const {
+ return shared_data_path_;
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2021 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_APP_INFO_EXTERNAL_DIRECTORY_INFO_HH
+#define AUL_APP_INFO_EXTERNAL_DIRECTORY_INFO_HH
+
+#include <string>
+
+namespace aul {
+
+class ExternalDirectoryInfo {
+ public:
+ static ExternalDirectoryInfo* Get(const std::string app_id, uid_t uid);
+ static ExternalDirectoryInfo* Get();
+
+ const std::string& GetRootPath() const;
+ const std::string& GetDataPath() const;
+ const std::string& GetCachePath() const;
+ const std::string& GetSharedDataPath() const;
+
+ private:
+ class Builder {
+ public:
+ Builder& SetRootPath(std::string root_path);
+ Builder& SetDataPath(std::string data_path);
+ Builder& SetCachePath(std::string cache_path);
+ Builder& SetSharedDataPath(std::string shared_data_path);
+
+ operator ExternalDirectoryInfo*();
+
+ private:
+ std::string root_path_;
+ std::string data_path_;
+ std::string cache_path_;
+ std::string shared_data_path_;
+ };
+
+ ExternalDirectoryInfo(std::string root_path,
+ std::string data_path,
+ std::string cache_path,
+ std::string shared_data_path);
+
+ private:
+ std::string root_path_;
+ std::string data_path_;
+ std::string cache_path_;
+ std::string shared_data_path_;
+};
+
+} // namespace aul
+
+#endif // AUL_APP_INFO_EXTERNAL_DIRECTORY_INFO_HH
--- /dev/null
+/*
+ * Copyright (c) 2020 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 <memory>
+
+#include "aul/app_manager/app_context.hh"
+#include "include/aul.h"
+
+namespace aul {
+
+AppContext::Builder& AppContext::Builder::SetAppId(std::string app_id) {
+ app_id_ = std::move(app_id);
+ return *this;
+}
+
+AppContext::Builder& AppContext::Builder::SetPkgId(std::string pkg_id) {
+ pkg_id_ = std::move(pkg_id);
+ return *this;
+}
+
+AppContext::Builder& AppContext::Builder::SetInstId(std::string inst_id) {
+ inst_id_ = std::move(inst_id);
+ return *this;
+}
+
+AppContext::Builder& AppContext::Builder::SetExec(std::string exec) {
+ exec_ = std::move(exec);
+ return *this;
+}
+
+AppContext::Builder& AppContext::Builder::SetPid(int pid) {
+ pid_ = pid;
+ return *this;
+}
+
+AppContext::Builder& AppContext::Builder::SetStatus(int status) {
+ status_ = status;
+ return *this;
+}
+
+AppContext::Builder& AppContext::Builder::SetIsSubApp(bool is_sub_app) {
+ is_sub_app_ = is_sub_app;
+ return *this;
+}
+
+AppContext AppContext::Builder::Build() {
+ return AppContext(std::move(app_id_), std::move(pkg_id_), std::move(inst_id_),
+ std::move(exec_), pid_, status_, is_sub_app_);
+}
+
+AppContext::AppContext(tizen_base::Bundle b) {
+ Set(std::move(b));
+}
+
+AppContext::AppContext(std::string app_id,
+ std::string pkg_id,
+ std::string inst_id,
+ std::string exec,
+ int pid,
+ int status,
+ bool is_sub_app)
+ : app_id_(std::move(app_id)),
+ pkg_id_(std::move(pkg_id)),
+ inst_id_(std::move(inst_id)),
+ exec_(std::move(exec)),
+ pid_(pid),
+ status_(status),
+ is_sub_app_(is_sub_app) {
+}
+
+const std::string& AppContext::GetAppId() const {
+ return app_id_;
+}
+
+const std::string& AppContext::GetPkgId() const {
+ return pkg_id_;
+}
+
+const std::string& AppContext::GetInstId() const {
+ return inst_id_;
+}
+
+const std::string& AppContext::GetExec() const {
+ return exec_;
+}
+
+int AppContext::GetPid() const {
+ return pid_;
+}
+
+int AppContext::GetStatus() const {
+ return status_;
+}
+
+void AppContext::SetStatus(int status) {
+ status_ = status;
+}
+
+bool AppContext::IsSubApp() const {
+ return is_sub_app_;
+}
+
+void AppContext::Set(tizen_base::Bundle b) {
+ app_id_ = std::move(b.GetString(AUL_K_APPID));
+ pkg_id_ = std::move(b.GetString(AUL_K_PKGID));
+ inst_id_ = std::move(b.GetString(AUL_K_INSTANCE_ID));
+ exec_ = std::move(b.GetString(AUL_K_EXEC));
+ pid_ = std::stoi(b.GetString(AUL_K_PID));
+ status_ = std::stoi(b.GetString(AUL_K_STATUS));
+ is_sub_app_ = static_cast<bool>(std::stoi(b.GetString(AUL_K_IS_SUBAPP)));
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2020 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_APP_MANAGER_APP_CONTEXT_HH_
+#define AUL_APP_MANAGER_APP_CONTEXT_HH_
+
+#include <bundle_cpp.h>
+
+#include <string>
+
+namespace aul {
+
+class AppContext {
+ public:
+ class Builder {
+ public:
+ Builder& SetAppId(std::string app_id);
+ Builder& SetPkgId(std::string pkg_id);
+ Builder& SetInstId(std::string inst_id);
+ Builder& SetExec(std::string exec);
+ Builder& SetPid(int pid);
+ Builder& SetStatus(int status);
+ Builder& SetIsSubApp(bool is_sub_app);
+ AppContext Build();
+
+ private:
+ std::string app_id_;
+ std::string pkg_id_;
+ std::string inst_id_;
+ std::string exec_;
+ int pid_;
+ int status_;
+ bool is_sub_app_;
+ };
+
+ explicit AppContext(tizen_base::Bundle b);
+ virtual ~AppContext() = default;
+
+ const std::string& GetAppId() const;
+ const std::string& GetPkgId() const;
+ const std::string& GetInstId() const;
+ const std::string& GetExec() const;
+ int GetPid() const;
+ int GetStatus() const;
+ bool IsSubApp() const;
+
+ void SetStatus(int status);
+
+ private:
+ AppContext(std::string app_id,
+ std::string pkg_id,
+ std::string inst_id,
+ std::string exec,
+ int pid,
+ int status,
+ bool is_sub_app);
+
+ void Set(tizen_base::Bundle b);
+
+ private:
+ std::string app_id_;
+ std::string pkg_id_;
+ std::string inst_id_;
+ std::string exec_;
+ int pid_;
+ int status_;
+ bool is_sub_app_;
+};
+
+} // namespace aul
+
+#endif // AUL_APP_MANAGER_APP_CONTEXT_HH_
--- /dev/null
+/*
+ * Copyright (c) 2020 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 <unistd.h>
+#include <sys/types.h>
+
+#include <bundle_cpp.h>
+
+#include <utility>
+
+#include "aul/app_manager/app_event.hh"
+#include "aul/common/common.hh"
+#include "aul/common/exception.hh"
+#include "aul/common/log_private.hh"
+
+namespace aul {
+
+AppEvent::AppEvent(std::string app_id, AppEvent::IEvent* ev)
+ : app_id_(std::move(app_id)), ev_(ev) {
+ endpoint_ = "app_status_event:" + app_id_;
+ if (getuid() >= REGULAR_UID_MIN)
+ endpoint_ += ":" + std::to_string(getuid());
+}
+
+AppEvent::AppEvent(AppEvent::IEvent* ev) : ev_(ev) {
+ endpoint_ = "app_status_event";
+ if (getuid() >= REGULAR_UID_MIN)
+ endpoint_ += ":" + std::to_string(getuid());
+}
+
+AppEvent::~AppEvent() {
+ if (handle_)
+ aul_app_com_leave(handle_);
+}
+
+void AppEvent::Listen() {
+ int ret = aul_app_com_create_async(endpoint_.c_str(), nullptr, OnAppStatusCb,
+ this, &handle_);
+ if (ret != AUL_R_OK) {
+ _E("aul_app_com_create(%s) is failed. error(%d)", endpoint_.c_str(), ret);
+ THROW(ret);
+ }
+}
+
+int AppEvent::OnAppStatusCb(const char* endpoint, aul_app_com_result_e res,
+ bundle* envelope, void* user_data) {
+ tizen_base::Bundle b(envelope);
+ AppContext::Builder builder;
+ builder.SetAppId(b.GetString(AUL_K_APPID));
+ builder.SetPkgId(b.GetString(AUL_K_PKGID));
+ builder.SetInstId(b.GetString(AUL_K_INSTANCE_ID));
+ builder.SetExec(b.GetString(AUL_K_EXEC));
+ builder.SetPid(std::stoi(b.GetString(AUL_K_PID)));
+ builder.SetStatus(std::stoi(b.GetString(AUL_K_STATUS)));
+ builder.SetIsSubApp(static_cast<bool>(
+ std::stoi(b.GetString(AUL_K_IS_SUBAPP))));
+ AppContext app_context = builder.Build();
+
+ auto* handle = static_cast<AppEvent*>(user_data);
+ IEvent* ev = handle->ev_;
+ int context_status = std::stoi(b.GetString("__CONTEXT_STATUS__"));
+ if (context_status == STATUS_TERMINATE)
+ ev->OnAppTerminated(&app_context);
+ else
+ ev->OnAppLaunched(&app_context);
+ return 0;
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2020 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_APP_MANAGER_APP_EVENT_HH_
+#define AUL_APP_MANAGER_APP_EVENT_HH_
+
+#include <string>
+
+#include "aul/app_manager/app_context.hh"
+#include "include/aul.h"
+#include "include/aul_app_com.h"
+
+namespace aul {
+
+class AppEvent {
+ public:
+ class IEvent {
+ public:
+ virtual void OnAppLaunched(const AppContext* context) = 0;
+ virtual void OnAppTerminated(const AppContext* context) = 0;
+ };
+
+ AppEvent(std::string app_id, IEvent* ev);
+ explicit AppEvent(IEvent* ev);
+ virtual ~AppEvent();
+
+ void Listen();
+
+ private:
+ static int OnAppStatusCb(const char* endpoint, aul_app_com_result_e res,
+ bundle* envelope, void* user_data);
+
+ private:
+ std::string app_id_;
+ IEvent* ev_;
+ std::string endpoint_;
+ aul_app_com_connection_h handle_ = nullptr;
+};
+
+} // namespace aul
+
+#endif // AUL_APP_MANAGER_APP_EVENT_HH_
--- /dev/null
+/*
+ * Copyright (c) 2020 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 <tizen.h>
+
+#include <stdexcept>
+
+#include "aul/app_manager/app_manager.hh"
+#include "aul/common/exception.hh"
+#include "aul/common/log_private.hh"
+#include "aul/socket/client.hh"
+#include "include/aul.h"
+#include "include/aul_cmd.h"
+#include "include/aul_error.h"
+#include "include/aul_sock.h"
+
+namespace aul {
+
+AppManager::AppContextList AppManager::GetAppContexts() {
+ AppContextList list;
+ int ret = aul_app_get_running_app_info(AppInfoCb, &list);
+ if (ret != AUL_R_OK)
+ _E("Failed to get running app info. error(%d)", ret);
+
+ return list;
+}
+
+AppManager::AppContextList AppManager::GetAllAppContexts() {
+ AppContextList list;
+ int ret = aul_app_get_all_running_app_info(AppInfoCb, &list);
+ if (ret != AUL_R_OK)
+ _E("Failed to get all running app info. error(%d)", ret);
+
+ return list;
+}
+
+std::unique_ptr<AppContext> AppManager::GetAppContext(
+ const std::string& app_id) {
+ tizen_base::Bundle b;
+ b.Add(AUL_K_APPID, app_id);
+ Packet packet(APP_CONTEXT_GET, AUL_SOCK_ASYNC | AUL_SOCK_BUNDLE, b);
+ return GetAppContext(packet);
+}
+
+std::unique_ptr<AppContext> AppManager::GetAppContext(
+ const std::string& app_id,
+ const std::string& inst_id) {
+ tizen_base::Bundle b;
+ b.Add(AUL_K_APPID, app_id);
+ b.Add(AUL_K_INSTANCE_ID, inst_id);
+ Packet packet(APP_CONTEXT_GET_BY_INSTANCE_ID,
+ AUL_SOCK_ASYNC | AUL_SOCK_BUNDLE, b);
+ return GetAppContext(packet);
+}
+
+std::unique_ptr<AppContext> AppManager::GetAppContext(int pid) {
+ tizen_base::Bundle b;
+ b.Add(AUL_K_PID, std::to_string(pid));
+ Packet packet(APP_CONTEXT_GET_BY_PID, AUL_SOCK_ASYNC | AUL_SOCK_BUNDLE, b);
+ return GetAppContext(packet);
+}
+
+std::unique_ptr<AppContext> AppManager::GetAppContext(const Packet& packet) {
+ Packet* recv_pkt = nullptr;
+ try {
+ Client client(PATH_AMD_SOCK);
+ int ret = client.Send(packet);
+ if (ret < 0) {
+ set_last_result(aul_error_convert(ret));
+ return {};
+ }
+
+ ret = client.Recv(&recv_pkt);
+ if (ret < 0) {
+ set_last_result(aul_error_convert(ret));
+ return {};
+ }
+
+ std::unique_ptr<Packet> ptr(recv_pkt);
+ if (recv_pkt->GetCmd() != APP_GET_INFO_OK) {
+ _E("Failed to find app context");
+ set_last_result(aul_error_convert(recv_pkt->GetCmd()));
+ return {};
+ }
+
+ set_last_result(AUL_R_OK);
+ tizen_base::Bundle b = recv_pkt->DataToBundle();
+ return std::unique_ptr<AppContext>(new (std::nothrow) AppContext(b));
+ } catch (std::invalid_argument& e) {
+ _E("Out of memory");
+ set_last_result(AUL_R_ENOMEM);
+ return {};
+ } catch (Exception& e) {
+ _E("Failed to create client. error(%d)", e.GetErrorCode());
+ set_last_result(aul_error_convert(e.GetErrorCode()));
+ return {};
+ }
+}
+
+int AppManager::AppInfoCb(const aul_app_info* info, void* data) {
+ auto* list = static_cast<AppContextList*>(data);
+ AppContext::Builder builder;
+ builder.SetAppId(info->appid);
+ builder.SetPkgId(info->pkgid);
+ builder.SetInstId(info->instance_id);
+ builder.SetExec(info->app_path);
+ builder.SetPid(info->pid);
+ builder.SetStatus(info->status);
+ builder.SetIsSubApp(static_cast<bool>(info->is_sub_app));
+ list->push_back(std::make_unique<AppContext>(builder.Build()));
+ return 0;
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2020 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_APP_MANAGER_APP_MANAGER_HH_
+#define AUL_APP_MANAGER_APP_MANAGER_HH_
+
+#include <memory>
+#include <string>
+#include <list>
+
+#include "aul/app_manager/app_context.hh"
+#include "aul/socket/packet.hh"
+#include "include/aul.h"
+
+namespace aul {
+
+class AppManager {
+ public:
+ using AppContextList = std::list<std::unique_ptr<AppContext>>;
+
+ AppManager() = default;
+ virtual ~AppManager() = default;
+
+ AppContextList GetAppContexts();
+ AppContextList GetAllAppContexts();
+ std::unique_ptr<AppContext> GetAppContext(const std::string& app_id);
+ std::unique_ptr<AppContext> GetAppContext(const std::string& app_id,
+ const std::string& inst_id);
+ std::unique_ptr<AppContext> GetAppContext(int pid);
+
+ private:
+ std::unique_ptr<AppContext> GetAppContext(const Packet& packet);
+
+ private:
+ static int AppInfoCb(const aul_app_info* info, void* data);
+};
+
+} // namespace aul
+
+#endif // AUL_APP_MANAGER_APP_MANAGER_HH_
--- /dev/null
+/*
+ * Copyright (c) 2021 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 "aul/app_request.h"
+
+#include <bundle_internal.h>
+#include <ctype.h>
+#include <dirent.h>
+#include <fcntl.h>
+#include <gio/gio.h>
+#include <glib.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <ttrace.h>
+
+#include <memory>
+#include <utility>
+
+#include "aul/aul_util.h"
+#include "aul/include/aul_cmd.h"
+#include "aul/include/aul_error.h"
+#include "aul/include/aul_sock.h"
+#include "aul/launch.h"
+
+namespace aul {
+namespace internal {
+
+AppRequest::AppRequest(int cmd, uid_t uid) : cmd_(cmd), uid_(uid) {
+ SetUid(uid);
+}
+
+AppRequest::AppRequest(int cmd) : cmd_(cmd), uid_(getuid()) {
+ SetUid(uid_);
+}
+
+AppRequest& AppRequest::With(tizen_base::Bundle b) {
+ bundle_ = std::move(b);
+ ClearInternalKey();
+ SetUid(uid_);
+ return *this;
+}
+
+AppRequest& AppRequest::With(bundle* b) {
+ if (b == nullptr)
+ return *this;
+ bundle_ = tizen_base::Bundle(b, false, false);
+ ClearInternalKey();
+ SetUid(uid_);
+ return *this;
+}
+
+AppRequest& AppRequest::SetAppId(const std::string& app_id) {
+ bundle_.Delete(AUL_K_APPID);
+ bundle_.Add(AUL_K_APPID, app_id);
+ return *this;
+}
+
+AppRequest& AppRequest::SetInstId(const std::string& inst_id) {
+ bundle_.Delete(AUL_K_INSTANCE_ID);
+ bundle_.Add(AUL_K_INSTANCE_ID, inst_id);
+ return *this;
+}
+
+AppRequest& AppRequest::SetAppIdAsPid(pid_t pid) {
+ char buf[MAX_PID_STR_BUFSZ];
+ snprintf(buf, sizeof(buf), "%d", pid);
+ bundle_.Delete(AUL_K_APPID);
+ bundle_.Add(AUL_K_APPID, buf);
+ return *this;
+}
+
+AppRequest& AppRequest::SetPid(pid_t pid) {
+ char buf[MAX_PID_STR_BUFSZ];
+ snprintf(buf, sizeof(buf), "%d", pid);
+ bundle_.Delete(AUL_K_PID);
+ bundle_.Add(AUL_K_PID, buf);
+ return *this;
+}
+
+int AppRequest::Send(int opt) {
+ traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "AUL:REQ_TO_PAD");
+ std::string appid = bundle_.GetString(AUL_K_APPID);
+ _W("Request cmd(%d:%s): appid(%s), target_uid(%u)",
+ cmd_, aul_cmd_convert_to_string(cmd_), appid.c_str(), uid_);
+
+ SetTime();
+ switch (cmd_) {
+ case APP_SEND_LAUNCH_REQUEST:
+ case APP_SEND_LAUNCH_REQUEST_SYNC:
+ case APP_SEND_RESUME_REQUEST:
+ opt |= AUL_SOCK_ASYNC;
+ break;
+ }
+
+ int ret = aul_sock_send_bundle(AUL_UTIL_PID, uid_, cmd_,
+ bundle_.GetHandle(), opt);
+ if (ret < 0)
+ ret = aul_error_convert(ret);
+ _W("Request cmd(%d:%s): result(%d)",
+ cmd_, aul_cmd_convert_to_string(cmd_), ret);
+ if (ret == AUL_R_LOCAL)
+ ret = app_request_local(cmd_, bundle_.GetHandle());
+ traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
+ return ret;
+}
+
+int AppRequest::SendSimply(int opt) {
+ _W("Request cmd(%d:%s): target_uid(%u)",
+ cmd_, aul_cmd_convert_to_string(cmd_), uid_);
+ int ret = aul_sock_send_bundle(AUL_UTIL_PID, uid_, cmd_,
+ bundle_.GetHandle(), opt);
+ if (ret < 0)
+ ret = aul_error_convert(ret);
+ _W("Request cmd(%d:%s): result(%d)",
+ cmd_, aul_cmd_convert_to_string(cmd_), ret);
+ return ret;
+}
+
+int AppRequest::SendCmdOnly(int opt) {
+ _W("Request cmd(%d:%s): target_uid(%u)",
+ cmd_, aul_cmd_convert_to_string(cmd_), uid_);
+ int ret = aul_sock_send_raw(AUL_UTIL_PID, uid_, cmd_, nullptr, 0, opt);
+ _W("Request cmd(%d:%s): result(%d)",
+ cmd_, aul_cmd_convert_to_string(cmd_), ret);
+ return ret;
+}
+
+void AppRequest::ClearInternalKey() {
+ bundle_.Delete(AUL_K_CALLER_PID);
+ bundle_.Delete(AUL_K_APPID);
+ bundle_.Delete(AUL_K_WAIT_RESULT);
+ bundle_.Delete(AUL_K_SEND_RESULT);
+ bundle_.Delete(AUL_K_ARGV0);
+}
+
+void AppRequest::SetTime() {
+ struct timespec start;
+ clock_gettime(CLOCK_MONOTONIC, &start);
+ char tmp[MAX_LOCAL_BUFSZ];
+ snprintf(tmp, sizeof(tmp), "%ld/%ld", start.tv_sec, start.tv_nsec);
+ bundle_.Delete(AUL_K_STARTTIME);
+ bundle_.Add(AUL_K_STARTTIME, tmp);
+}
+
+void AppRequest::SetUid(uid_t uid) {
+ char buf[MAX_PID_STR_BUFSZ];
+ snprintf(buf, sizeof(buf), "%d", uid);
+ bundle_.Delete(AUL_K_TARGET_UID);
+ bundle_.Add(AUL_K_TARGET_UID, buf);
+}
+
+} // namespace internal
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2021 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_APP_REQUEST_H_
+#define AUL_APP_REQUEST_H_
+
+#include <bundle_cpp.h>
+#include <bundle.h>
+#include <string>
+
+#include "aul/include/aul.h"
+#include "aul/include/aul_sock.h"
+
+namespace aul {
+namespace internal {
+
+class AppRequest {
+ public:
+ AppRequest(int cmd, uid_t uid);
+ explicit AppRequest(int cmd);
+
+ AppRequest& With(tizen_base::Bundle b);
+ AppRequest& With(bundle* b);
+ AppRequest& SetAppId(const std::string& app_id);
+ AppRequest& SetInstId(const std::string& inst_id);
+ AppRequest& SetAppIdAsPid(pid_t pid);
+ AppRequest& SetPid(pid_t pid);
+ int Send(int opt = AUL_SOCK_QUEUE);
+ int SendSimply(int opt = AUL_SOCK_NONE);
+ int SendCmdOnly(int opt = AUL_SOCK_NONE);
+
+ private:
+ void ClearInternalKey();
+ void SetTime();
+ void SetUid(uid_t uid);
+
+ private:
+ int cmd_;
+ uid_t uid_;
+ tizen_base::Bundle bundle_;
+};
+
+} // namespace internal
+} // namespace aul
+
+#endif // AUL_APP_REQUEST_H_
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2000 - 2022 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 <gio/gio.h>
+#include <glib.h>
+
+#include <memory>
+#include <mutex>
+#include <string>
+
+#include "aul/aul_api.h"
+#include "aul/include/aul.h"
+#include "aul/common/log_private.hh"
+
+namespace {
+
+constexpr const char AUL_DBUS_PATH[] = "/aul/dbus_handler";
+constexpr const char AUL_DBUS_SIGNAL_INTERFACE[] = "org.tizen.aul.signal";
+constexpr const char AUL_DBUS_APPDEAD_SIGNAL[] = "app_dead";
+constexpr const char AUL_DBUS_APPLAUNCH_SIGNAL[] = "app_launch";
+
+constexpr const char AUL_APP_STATUS_DBUS_PATH[] = "/Org/Tizen/Aul/AppStatus";
+constexpr const char AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE[] =
+ "org.tizen.aul.AppStatus";
+constexpr const char AUL_APP_STATUS_DBUS_LAUNCH_REQUEST[] = "AppLaunch";
+constexpr const char AUL_APP_STATUS_DBUS_RESUME_REQUEST[] = "AppResume";
+constexpr const char AUL_APP_STATUS_DBUS_TERMINATE_REQUEST[] = "AppTerminate";
+constexpr const char AUL_APP_STATUS_DBUS_STATUS_CHANGE[] = "AppStatusChange";
+constexpr const char AUL_APP_STATUS_DBUS_GROUP[] = "AppGroup";
+constexpr const char AUL_APP_STATUS_DBUS_TERMINATED[] = "AppTerminated";
+
+constexpr const char SYSTEM_PATH_CORE[] = "/org/tizen/system";
+constexpr const char SYSTEM_INTERFACE_CORE[] = "org.tizen.system.Booting";
+constexpr const char SYSTEM_SIGNAL_BOOTING_DONE[] = "BootingDone";
+
+constexpr const char SYSTEM_PATH_THERMAL[] = "/Org/Tizen/System/Thermal";
+constexpr const char SYSTEM_INTERFACE_THERMAL[] = "org.tizen.system.thermal";
+constexpr const char SYSTEM_SIGNAL_COOLDOWN_MODE_CHANGED[] =
+ "CoolDownModeChanged";
+
+constexpr const char RESOURCED_BUS_NAME[] = "org.tizen.resourced";
+constexpr const char RESOURCED_PROC_PATH[] = "/Org/Tizen/ResourceD/Process";
+constexpr const char RESOURCED_PROC_INTERFACE[] = "org.tizen.resourced.process";
+constexpr const char RESOURCED_PROC_STATUS_SIGNAL[] = "ProcStatus";
+constexpr const char RESOURCED_PROC_METHOD[] = "ProcExclude";
+
+template <typename T>
+class Event {
+ public:
+ Event(std::string object_path, std::string interface_name,
+ std::string signal_name)
+ : object_path_(std::move(object_path)),
+ interface_name_(std::move(interface_name)),
+ signal_name_(std::move(signal_name)) {
+ }
+
+ virtual ~Event() {
+ Unsubscribe();
+ }
+
+ const std::string& GetObjectPath() const { return object_path_; }
+
+ const std::string& GetInterfaceName() const { return interface_name_; }
+
+ const std::string& GetSignalName() const { return signal_name_; }
+
+ virtual void Invoke(GVariant* parameters) {}
+
+ T GetCallback() const { return cb_; }
+
+ void* GetUserData() const { return user_data_; }
+
+ bool Subscribe() {
+ std::lock_guard<std::recursive_mutex> lock(GetMutex());
+ if (source_ != 0)
+ return true;
+
+ GError* err = nullptr;
+ conn_ = g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &err);
+ if (conn_ == nullptr) {
+ _E("g_bus_get_sync() is failed. error(%s)", err ? err->message : "");
+ g_clear_error(&err);
+ return false;
+ }
+
+ source_ = g_dbus_connection_signal_subscribe(
+ conn_, nullptr, interface_name_.c_str(), signal_name_.c_str(),
+ object_path_.c_str(), nullptr, G_DBUS_SIGNAL_FLAGS_NONE, DBusSignalCb,
+ this, nullptr);
+ if (source_ == 0) {
+ _E("g_dbus_connection_signal_subscribe() is failed");
+ g_object_unref(conn_);
+ conn_ = nullptr;
+ return false;
+ }
+
+ return true;
+ }
+
+ bool SetCallback(T cb, void* user_data) {
+ std::lock_guard<std::recursive_mutex> lock(GetMutex());
+ cb_ = cb;
+ user_data_ = user_data;
+
+ if (cb_ == nullptr) {
+ Unsubscribe();
+ return true;
+ }
+
+ return Subscribe();
+ }
+
+ private:
+ void Unsubscribe() {
+ std::lock_guard<std::recursive_mutex> lock(GetMutex());
+ if (source_ == 0)
+ return;
+
+ g_dbus_connection_signal_unsubscribe(conn_, source_);
+ source_ = 0;
+
+ g_object_unref(conn_);
+ conn_ = nullptr;
+ }
+
+ std::recursive_mutex& GetMutex() const {
+ return mutex_;
+ }
+
+ static void DBusSignalCb(GDBusConnection* connection,
+ const gchar* sender_name, const gchar* object_path,
+ const gchar* interface_name, const gchar* signal_name,
+ GVariant* parameters, gpointer user_data) {
+ auto* event = static_cast<Event*>(user_data);
+ std::lock_guard<std::recursive_mutex> lock(event->GetMutex());
+ if (event->source_ != 0)
+ event->Invoke(parameters);
+ }
+
+ private:
+ std::string object_path_;
+ std::string interface_name_;
+ std::string signal_name_;
+ std::remove_pointer_t<T>* cb_ = nullptr;
+ void* user_data_ = nullptr;
+ GDBusConnection* conn_ = nullptr;
+ guint source_ = 0;
+ mutable std::recursive_mutex mutex_;
+};
+
+class AppDeadEvent : public Event<aul_app_dead_event_cb> {
+ public:
+ AppDeadEvent() : Event<aul_app_dead_event_cb>(AUL_DBUS_PATH,
+ AUL_DBUS_SIGNAL_INTERFACE, AUL_DBUS_APPDEAD_SIGNAL) {
+ }
+
+ void Invoke(GVariant* parameters) override {
+ gint pid;
+ gint dummy;
+ g_variant_get(parameters, "(ii)", &pid, &dummy);
+
+ auto cb = GetCallback();
+ if (cb != nullptr)
+ cb(static_cast<int>(pid), GetUserData());
+ }
+};
+
+class AppDeadEvent2 : public Event<aul_app_dead_event_cb_v2> {
+ public:
+ AppDeadEvent2() : Event<aul_app_dead_event_cb_v2>(AUL_DBUS_PATH,
+ AUL_DBUS_SIGNAL_INTERFACE, AUL_DBUS_APPDEAD_SIGNAL) {
+ }
+
+ void Invoke(GVariant* parameters) override {
+ gint pid;
+ gint status;
+ g_variant_get(parameters, "(ii)", &pid, &status);
+
+ auto cb = GetCallback();
+ if (cb != nullptr)
+ cb(static_cast<int>(pid), static_cast<int>(status), GetUserData());
+ }
+};
+
+class AppLaunchEvent : public Event<aul_app_launch_event_cb> {
+ public:
+ AppLaunchEvent() : Event<aul_app_launch_event_cb>(AUL_DBUS_PATH,
+ AUL_DBUS_SIGNAL_INTERFACE, AUL_DBUS_APPLAUNCH_SIGNAL) {
+ }
+
+ void Invoke(GVariant* parameters) override {
+ guint pid;
+ gchar* appid;
+ g_variant_get(parameters, "(u&s)", &pid, &appid);
+
+ auto cb = GetCallback();
+ if (cb != nullptr)
+ cb(static_cast<int>(pid), GetUserData());
+ }
+};
+
+class AppLaunchEvent2 : public Event<aul_app_launch_event_cb_v2> {
+ public:
+ AppLaunchEvent2() : Event<aul_app_launch_event_cb_v2>(AUL_DBUS_PATH,
+ AUL_DBUS_SIGNAL_INTERFACE, AUL_DBUS_APPLAUNCH_SIGNAL) {
+ }
+
+ void Invoke(GVariant* parameters) override {
+ guint pid;
+ gchar* appid;
+ g_variant_get(parameters, "(u&s)", &pid, &appid);
+
+ auto cb = GetCallback();
+ if (cb != nullptr)
+ cb(static_cast<int>(pid), appid, GetUserData());
+ }
+};
+
+class BootingDoneEvent : public Event<aul_booting_done_event_cb> {
+ public:
+ BootingDoneEvent() : Event<aul_booting_done_event_cb>(SYSTEM_PATH_CORE,
+ SYSTEM_INTERFACE_CORE, SYSTEM_SIGNAL_BOOTING_DONE) {
+ }
+
+ void Invoke(GVariant* parameters) override {
+ auto cb = GetCallback();
+ if (cb != nullptr)
+ cb(0, GetUserData());
+ }
+};
+
+class CooldownEvent : public Event<aul_cooldown_event_cb> {
+ public:
+ CooldownEvent() : Event<aul_cooldown_event_cb>(SYSTEM_PATH_THERMAL,
+ SYSTEM_INTERFACE_THERMAL, SYSTEM_SIGNAL_COOLDOWN_MODE_CHANGED) {
+ }
+
+ void Invoke(GVariant* parameters) override {
+ gchar* cooldown_status;
+ g_variant_get(parameters, "(&s)", &cooldown_status);
+
+ auto cb = GetCallback();
+ if (cb != nullptr)
+ cb(cooldown_status, GetUserData());
+ }
+};
+
+class AppStatusChangedEvent : public Event<aul_app_status_changed_cb> {
+ public:
+ AppStatusChangedEvent()
+ : Event<aul_app_status_changed_cb>(RESOURCED_PROC_PATH,
+ RESOURCED_PROC_INTERFACE, RESOURCED_PROC_STATUS_SIGNAL) {
+ }
+
+ void Invoke(GVariant* parameters) override {
+ gint pid = -1;
+ gint status = -1;
+ g_variant_get(parameters, "(ii)", &status, &pid);
+
+ auto cb = GetCallback();
+ if (cb != nullptr)
+ cb(pid, status, GetUserData());
+ }
+};
+
+class AppSignalContext {
+ public:
+ AppSignalContext() = default;
+ ~AppSignalContext() {
+ }
+
+ bool AppDeadEventSubscribe(aul_app_dead_event_cb cb, void* user_data) {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ if (app_dead_event_ == nullptr)
+ app_dead_event_ = std::make_unique<AppDeadEvent>();
+
+ return app_dead_event_->SetCallback(cb, user_data);
+ }
+
+ bool AppDeadEvent2Subscribe(
+ aul_app_dead_event_cb_v2 cb, void* user_data) {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ if (app_dead_event2_ == nullptr)
+ app_dead_event2_ = std::make_unique<AppDeadEvent2>();
+
+ return app_dead_event2_->SetCallback(cb, user_data);
+ }
+
+ bool AppLaunchEventSubscribe(aul_app_launch_event_cb cb, void* user_data) {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ if (app_launch_event_ == nullptr)
+ app_launch_event_ = std::make_unique<AppLaunchEvent>();
+
+ return app_launch_event_->SetCallback(cb, user_data);
+ }
+
+ bool AppLaunchEvent2Subscribe(aul_app_launch_event_cb_v2 cb,
+ void* user_data) {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ if (app_launch_event2_ == nullptr)
+ app_launch_event2_ = std::make_unique<AppLaunchEvent2>();
+
+ return app_launch_event2_->SetCallback(cb, user_data);
+ }
+
+ bool BootingDoneEventSubscribe(aul_booting_done_event_cb cb,
+ void* user_data) {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ if (app_dead_event_ == nullptr)
+ app_dead_event_ = std::make_unique<AppDeadEvent>();
+
+ return booting_done_event_->SetCallback(cb, user_data);
+ }
+
+ bool CooldownEventSubscribe(aul_cooldown_event_cb cb, void* user_data) {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ if (cooldown_event_ == nullptr)
+ cooldown_event_ = std::make_unique<CooldownEvent>();
+
+ return cooldown_event_->SetCallback(cb, user_data);
+ }
+
+ bool AppStatusChangedEventSubscribe(aul_app_status_changed_cb cb,
+ void* user_data) {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ if (app_status_changed_event_ == nullptr)
+ app_status_changed_event_ = std::make_unique<AppStatusChangedEvent>();
+
+ return app_status_changed_event_->SetCallback(cb, user_data);
+ }
+
+ private:
+ std::recursive_mutex mutex_;
+ std::unique_ptr<AppDeadEvent> app_dead_event_;
+ std::unique_ptr<AppDeadEvent2> app_dead_event2_;
+ std::unique_ptr<AppLaunchEvent> app_launch_event_;
+ std::unique_ptr<AppLaunchEvent2> app_launch_event2_;
+ std::unique_ptr<BootingDoneEvent> booting_done_event_;
+ std::unique_ptr<CooldownEvent> cooldown_event_;
+ std::unique_ptr<AppStatusChangedEvent> app_status_changed_event_;
+};
+
+AppSignalContext context;
+
+bool EmitSignal(const std::string& object_path,
+ const std::string& interface_name, const std::string& signal_name,
+ GVariant* parameters) {
+ GError* err = nullptr;
+ auto* conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &err);
+ if (conn == nullptr) {
+ _E("g_bus_get_sync() is failed. error(%s)", err ? err->message : "");
+ g_clear_error(&err);
+ return false;
+ }
+ std::unique_ptr<GDBusConnection, decltype(g_object_unref)*> conn_auto(
+ conn, g_object_unref);
+
+ if (!g_dbus_connection_emit_signal(conn, nullptr, object_path.c_str(),
+ interface_name.c_str(), signal_name.c_str(), parameters, &err)) {
+ _E("g_dbus_connection_emit_signal() is failed. error(%s)",
+ err ? err->message : "");
+ g_clear_error(&err);
+ return false;
+ }
+
+ if (!g_dbus_connection_flush_sync(conn, nullptr, &err)) {
+ _E("g_dbus_connection_flush_sync() is failed. error(%s)",
+ err ? err->message : "");
+ g_clear_error(&err);
+ return false;
+ }
+
+ return true;
+}
+
+bool SendMessage(const std::string& name, const std::string& path,
+ const std::string& interface, const std::string& method, GVariant* body) {
+ GError* err = nullptr;
+ auto* conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &err);
+ if (conn == nullptr) {
+ _E("g_bus_get_sync() is failed. error(%s)", err ? err->message : "");
+ g_clear_error(&err);
+ return false;
+ }
+ std::unique_ptr<GDBusConnection, decltype(g_object_unref)*> conn_auto(
+ conn, g_object_unref);
+
+ auto* msg = g_dbus_message_new_method_call(name.c_str(), path.c_str(),
+ interface.c_str(), method.c_str());
+ if (msg == nullptr) {
+ _E("g_dbus_message_new_method_call() is failed");
+ return false;
+ }
+ std::unique_ptr<GDBusMessage, decltype(g_object_unref)*> msg_auto(
+ msg, g_object_unref);
+
+ g_dbus_message_set_body(msg, body);
+ g_dbus_connection_send_message_with_reply(conn, msg,
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, nullptr, nullptr,
+ [](GObject* source_object, GAsyncResult* res, gpointer user_data) {
+ auto* conn = static_cast<GDBusConnection*>(user_data);
+ int result;
+ GError* err = nullptr;
+ auto* reply = g_dbus_connection_send_message_with_reply_finish(conn,
+ res, &err);
+ if (reply == nullptr) {
+ _E("No reply. error(%s)", err ? err->message : "");
+ result = -1;
+ } else {
+ result = 0;
+ }
+
+ g_clear_error(&err);
+ if (reply != nullptr)
+ g_object_unref(reply);
+ if (conn != nullptr)
+ g_object_unref(conn);
+
+ _I("Result: %d", result);
+ }, conn);
+ conn_auto.release();
+ return true;
+}
+
+} // namespace
+
+extern "C" API int aul_listen_app_dead_signal(aul_app_dead_event_cb callback,
+ void* user_data) {
+ if (!context.AppDeadEventSubscribe(callback, user_data))
+ return AUL_R_ERROR;
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_listen_app_dead_signal_v2(
+ aul_app_dead_event_cb_v2 callback, void* user_data) {
+ if (!context.AppDeadEvent2Subscribe(callback, user_data))
+ return AUL_R_ERROR;
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_listen_app_launch_signal(
+ aul_app_launch_event_cb callback, void* user_data) {
+ if (!context.AppLaunchEventSubscribe(callback, user_data))
+ return AUL_R_ERROR;
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_listen_app_launch_signal_v2(
+ aul_app_launch_event_cb_v2 callback, void* user_data) {
+ if (!context.AppLaunchEvent2Subscribe(callback, user_data))
+ return AUL_R_ERROR;
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_listen_booting_done_signal(
+ aul_booting_done_event_cb callback, void* user_data) {
+ _W("DEPRECATION WARNING: %s() is deprecated "
+ "and will be remove from next release.", __FUNCTION__);
+ if (!context.BootingDoneEventSubscribe(callback, user_data))
+ return AUL_R_ERROR;
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_listen_cooldown_signal(aul_cooldown_event_cb callback,
+ void *user_data) {
+ _W("DEPRECATION WARNING: %s() is deprecated "
+ "and will be remove from next release.", __FUNCTION__);
+ if (!context.CooldownEventSubscribe(callback, user_data))
+ return AUL_R_ERROR;
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_listen_app_status_signal(
+ aul_app_status_changed_cb callback, void *user_data) {
+ if (!context.AppStatusChangedEventSubscribe(callback, user_data))
+ return AUL_R_ERROR;
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_update_freezer_status(int pid, const char* type) {
+ if (pid <= 1 || type == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ GVariant* body = g_variant_new("(si)", type, pid);
+ if (body == nullptr) {
+ _E("Out of memory");
+ return AUL_R_ENOMEM;
+ }
+
+ if (!SendMessage(RESOURCED_BUS_NAME, RESOURCED_PROC_PATH,
+ RESOURCED_PROC_INTERFACE, RESOURCED_PROC_METHOD, body)) {
+ g_variant_unref(body);
+ return AUL_R_ERROR;
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_send_app_launch_request_signal(int pid,
+ const char* appid, const char* pkgid, const char* type) {
+ if (pid <= 1 || appid == nullptr || pkgid == nullptr || type == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ GVariant* parameters = g_variant_new("(isss)", pid, appid, pkgid, type);
+ if (parameters == nullptr) {
+ _E("Out of memory");
+ return AUL_R_ENOMEM;
+ }
+
+ if (!EmitSignal(AUL_APP_STATUS_DBUS_PATH,
+ AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE,
+ AUL_APP_STATUS_DBUS_LAUNCH_REQUEST, parameters)) {
+ g_variant_unref(parameters);
+ return AUL_R_ERROR;
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_send_app_resume_request_signal(int pid,
+ const char* appid, const char* pkgid, const char* type) {
+ if (pid <= 1) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ if (appid == nullptr)
+ appid = "";
+ if (pkgid == nullptr)
+ pkgid = "";
+ if (type == nullptr)
+ type = "";
+
+ GVariant* parameters = g_variant_new("(isss)", pid, appid, pkgid, type);
+ if (parameters == nullptr) {
+ _E("Out of memory");
+ return AUL_R_ENOMEM;
+ }
+
+ if (!EmitSignal(AUL_APP_STATUS_DBUS_PATH,
+ AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE,
+ AUL_APP_STATUS_DBUS_RESUME_REQUEST, parameters)) {
+ g_variant_unref(parameters);
+ return AUL_R_ERROR;
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_send_app_terminate_request_signal(int pid,
+ const char* appid, const char* pkgid, const char* type) {
+ if (pid <= 1) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ if (appid == nullptr)
+ appid = "";
+ if (pkgid == nullptr)
+ pkgid = "";
+ if (type == nullptr)
+ type = "";
+
+ GVariant* parameters = g_variant_new("(isss)", pid, appid, pkgid, type);
+ if (parameters == nullptr) {
+ _E("Out of memory");
+ return AUL_R_ENOMEM;
+ }
+
+ if (!EmitSignal(AUL_APP_STATUS_DBUS_PATH,
+ AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE,
+ AUL_APP_STATUS_DBUS_TERMINATE_REQUEST, parameters)) {
+ g_variant_unref(parameters);
+ return AUL_R_ERROR;
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_send_app_status_change_signal(int pid,
+ const char* appid, const char* pkgid, const char* status,
+ const char* type) {
+ if (pid <= 1 || status == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ if (appid == nullptr)
+ appid = "";
+ if (pkgid == nullptr)
+ pkgid = "";
+ if (type == nullptr)
+ type = "";
+
+ GVariant* parameters = g_variant_new("(issss)",
+ pid, appid, pkgid, status, type);
+ if (parameters == nullptr) {
+ _E("Out of memory");
+ return AUL_R_ENOMEM;
+ }
+
+ if (!EmitSignal(AUL_APP_STATUS_DBUS_PATH,
+ AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE,
+ AUL_APP_STATUS_DBUS_STATUS_CHANGE, parameters)) {
+ g_variant_unref(parameters);
+ return AUL_R_ERROR;
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_send_app_terminated_signal(int pid) {
+ if (pid <= 1) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ GVariant* parameters = g_variant_new("(i)", pid);
+ if (parameters == nullptr) {
+ _E("Out of memory");
+ return AUL_R_ENOMEM;
+ }
+
+ if (!EmitSignal(AUL_APP_STATUS_DBUS_PATH,
+ AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE,
+ AUL_APP_STATUS_DBUS_TERMINATED, parameters)) {
+ g_variant_unref(parameters);
+ return AUL_R_ERROR;
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_send_app_group_signal(int owner_pid, int child_pid,
+ const char* child_pkgid) {
+ if (owner_pid <= 1 || child_pid <= 1) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ if (child_pkgid == nullptr)
+ child_pkgid = "";
+
+ GVariant* parameters = g_variant_new("(iis)",
+ owner_pid, child_pid, child_pkgid);
+ if (parameters == nullptr) {
+ _E("Out of memory");
+ return AUL_R_ENOMEM;
+ }
+
+ if (!EmitSignal(AUL_APP_STATUS_DBUS_PATH,
+ AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE,
+ AUL_APP_STATUS_DBUS_GROUP, parameters)) {
+ g_variant_unref(parameters);
+ return AUL_R_ERROR;
+ }
+
+ return AUL_R_OK;
+}
--- /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
+<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
+<busconfig>
+ <policy context="default">
+ <deny own="org.tizen.aul.AppStatus"/>
+ <deny send_type="method_call" send_destination="org.tizen.aul.AppStatus"/>
+ <deny send_type="signal" send_interface="org.tizen.aul.AppStatus"/>
+ </policy>
+ <policy user="app_fw">
+ <allow own="org.tizen.aul.AppStatus"/>
+ <allow send_type="signal" send_interface="org.tizen.aul.AppStatus"/>
+ </policy>
+ <policy user="root">
+ <allow own="org.tizen.aul.AppStatus"/>
+ </policy>
+</busconfig>
--- /dev/null
+# Package Information for pkg-config
+
+prefix=@PREFIX@
+exec_prefix=@EXEC_PREFIX@
+libdir=@LIB_INSTALL_DIR@
+includedir=@INCLUDE_INSTALL_DIR@
+
+Name: libaul
+Description: new application utility library
+Version: @VERSION@
+Requires: bundle glib-2.0 xdgmime vconf dlog
+Libs: -L${libdir} -laul
+Cflags: -I${includedir} -I${includedir}/aul -I${includedir}/aul/api
--- /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) 2018 - 2020 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 "aul/include/aul_cmd.h"
+
+#include <stdio.h>
+
+#include "aul/aul_api.h"
+
+extern "C" API const char* aul_cmd_convert_to_string(int cmd) {
+ static const char* cmd_string_table[] = {
+ "APP_START",
+
+ "APP_OPEN",
+ "APP_RESUME",
+ "APP_RESUME_BY_PID",
+ "APP_TERM_BY_PID",
+ "APP_TERM_BY_PID_WITHOUT_RESTART",
+ "APP_RESULT",
+ "APP_START_RES",
+ "APP_CANCEL",
+ "APP_KILL_BY_PID",
+ "APP_UPDATE_RUA_STAT",
+
+ "APP_ADD_HISTORY",
+ "APP_REMOVE_HISTORY",
+ "APP_RUNNING_INFO",
+ "APP_RUNNING_INFO_RESULT",
+ "APP_IS_RUNNING",
+ "APP_GET_APPID_BYPID",
+ "APP_GET_PKGID_BYPID",
+ "APP_GET_INFO_OK",
+ "APP_GET_INFO_ERROR",
+ "APP_KEY_EVENT",
+
+ "APP_KEY_RESERVE",
+ "APP_KEY_RELEASE",
+ "APP_STATUS_UPDATE",
+ "APP_RUNNING_LIST_UPDATE",
+ "APP_TERM_REQ_BY_PID",
+ "APP_TERM_BY_PID_ASYNC",
+ "APP_TERM_BGAPP_BY_PID",
+ "APP_PAUSE",
+ "APP_PAUSE_BY_PID",
+ "APP_GROUP_GET_WINDOW",
+
+ "APP_GROUP_SET_WINDOW",
+ "APP_GROUP_GET_FG",
+ "APP_GROUP_GET_LEADER_PID",
+ "APP_GROUP_GET_LEADER_PIDS",
+ "APP_GROUP_GET_GROUP_PIDS",
+ "APP_GROUP_GET_IDLE_PIDS",
+ "APP_GROUP_LOWER",
+ "APP_GROUP_CLEAR_TOP",
+ "APP_GROUP_ACTIVATE_BELOW",
+ "APP_GET_STATUS",
+
+ "APP_ADD_LOADER",
+ "APP_REMOVE_LOADER",
+ "APP_GET_PID",
+ "APP_GET_DC_SOCKET_PAIR",
+ "APP_GET_MP_SOCKET_PAIR",
+ "APP_COM_CREATE",
+ "APP_COM_JOIN",
+ "APP_COM_SEND",
+ "APP_COM_LEAVE",
+ "APP_COM_MESSAGE",
+
+ "WIDGET_ADD",
+ "WIDGET_DEL",
+ "WIDGET_LIST",
+ "WIDGET_UPDATE",
+ "WIDGET_COUNT",
+ "WIDGET_GET_CONTENT",
+ "APP_REGISTER_PID",
+ "APP_WAKE",
+ "APP_SUSPEND",
+ "AMD_RELOAD_APPINFO",
+
+ "LAUNCHPAD_DEAD_SIGNAL",
+ "APP_ALL_RUNNING_INFO",
+ "APP_SET_APP_CONTROL_DEFAULT_APP",
+ "APP_UNSET_APP_CONTROL_DEFAULT_APP",
+ "APP_START_ASYNC",
+ "APP_SET_PROCESS_GROUP",
+ "APP_PREPARE_CANDIDATE_PROCESS",
+ "APP_TERM_BY_PID_SYNC",
+ "APP_GET_STATUS_BY_APPID",
+ "APP_GET_LAST_CALLER_PID",
+
+ "APP_TERM_BY_PID_SYNC_WITHOUT_RESTART",
+ "APP_RESUME_BY_PID_ASYNC",
+ "APP_SET_ALIAS_APPID",
+ "APP_UNSET_ALIAS_APPID",
+ "APP_ENABLE_ALIAS_INFO",
+ "APP_DISABLE_ALIAS_INFO",
+ "APP_GROUP_ACTIVATE_ABOVE",
+ "ADD_APP_SCREEN",
+ "REMOVE_APP_SCREEN",
+ "APP_UPDATE_REQUESTED",
+
+ "ADD_SCREEN_VIEWER",
+ "REMOVE_SCREEN_VIEWER",
+ "LAUNCHPAD_LAUNCH_SIGNAL",
+ "APP_RUNNING_INSTANCE_INFO",
+ "APP_GET_INSTANCE_ID_BYPID",
+ "APP_SET_CACHE",
+ "APP_GET_APPID_FROM_CACHE",
+ "APP_INVALIDATE_CACHE",
+ "APP_STARTUP_SIGNAL",
+ "APP_WINDOW_ATTACH",
+
+ "APP_WINDOW_DETACH",
+ "APP_START_RES_ASYNC",
+ "APP_NOTIFY_EXIT",
+ "APP_GET_APPID_BY_SURFACE_ID",
+ "APP_GET_INSTANCE_ID_BY_SURFACE_ID",
+ "UPDATE_SCREEN_VIEWER_STATUS",
+ "WIDGET_RUNNING_INFO",
+ "JOB_STATUS_UPDATE",
+ "WIDGET_CHANGE_STATUS",
+ "RPC_PORT_PREPARE_STUB",
+
+ "RPC_PORT_CREATE_SOCKET_PAIR",
+ "RPC_PORT_NOTIFY_RPC_FINISHED",
+ "COMPLICATION_UPDATE_REQUEST",
+ "APP_NOTIFY_START",
+ "WATCHDOG_ENABLE",
+ "WATCHDOG_DISABLE",
+ "WATCHDOG_PING",
+ "WATCHDOG_KICK",
+ "APP_SEND_LAUNCH_REQUEST",
+ "APP_SEND_LAUNCH_REQUEST_SYNC",
+
+ "COMP_NOTIFY_START",
+ "COMP_NOTIFY_EXIT",
+ "COMP_STATUS_UPDATE",
+ "APP_TERM_INSTANCE_ASYNC",
+ "APP_GROUP_SET_WINDOW_V2",
+ "APP_GROUP_LOWER_V2",
+ "APP_GROUP_GET_LEADER_IDS",
+ "APP_GROUP_GET_GROUP_INFO",
+ "APP_GROUP_GET_IDLE_INFO",
+ "COMP_CONTEXT_FOREACH",
+
+ "COMP_CONTEXT_GET",
+ "COMP_CONTEXT_IS_RUNNING",
+ "COMP_CONTEXT_RESUME",
+ "COMP_CONTEXT_PAUSE",
+ "COMP_CONTEXT_TERMINATE_BG_COMP",
+ "COMP_CONTEXT_TERMINATE",
+ "APP_RESUME_INSTANCE",
+ "APP_PAUSE_INSTANCE",
+ "APP_TERM_BG_INSTANCE",
+ "LAUNCHPAD_CHILD_PROCESS", /* unused */
+
+ "COMP_INFO_GET",
+ "COMP_INFO_FOREACH",
+ "APP_TERMINATE",
+ "APP_IS_RUNNING_V2",
+ "ANR_NOTIFY",
+ "APP_GET_RUNNING_CONTEXT",
+ "LAUNCHER_SERVICE_NOTIFY_ANIMATION_STARTED",
+ "LAUNCHER_SERVICE_NOTIFY_ANIMATION_FINISHED",
+ "APP_SEND_RESUME_REQUEST",
+ "APP_PREPARE_APP_DEFINED_LOADER",
+
+ "WIDGET_DISABLE",
+ "TRIGGER_APP_SCREEN_FOCUSED_FORCE",
+ "WIDGET_EVENT",
+ "SET_PRIVATE_SHARING",
+ "UNSET_PRIVATE_SHARING",
+ "APP_CONTEXT_GET",
+ "APP_CONTEXT_GET_BY_INSTANCE_ID",
+ "APP_CONTEXT_GET_BY_PID",
+ "APP_GROUP_ADD",
+ "APP_GROUP_REMOVE",
+
+ "APP_GET_APPID_LIST",
+ "COMP_PORT_EXIST",
+ "COMP_PORT_CREATE",
+ "COMP_PORT_DESTROY",
+ "APP_LIFECYCLE_UPDATE_STATE",
+
+ "APP_STATUS_UPDATE_V2",
+ "APP_GET_APP_CONTROL_DEFAULT_APPS",
+ "APP_GET_APPID_BY_ALIAS_APPID",
+ "APP_GET_APP_CONTROL_DEFAULT_APP",
+ "APP_LIFECYCLE_GET_STATE",
+
+ "PROC_REGISTER",
+ "PROC_DEREGISTER",
+ "PROC_GET_NAME",
+ "PROC_GET_EXTRA",
+ "RPC_PORT_CREATE",
+
+ "RPC_PORT_DESTROY",
+ "RPC_PORT_EXIST",
+ "APP_WINDOW_ATTACH_BELOW",
+ "PROC_GROUP_ADD",
+ "PROC_GROUP_REMOVE",
+
+ "APP_CONNECT",
+ "APP_SET_AUTO_RESTART",
+ "BOOT_SEQUENCE_START_APP",
+ "BOOT_SEQUENCE_GET_APPINFO_LIST",
+ "BOOT_SEQUENCE_RELOAD",
+
+ "PKG_PRE_EVENT_SEND",
+ "PROC_GROUP_FOREACH",
+ "PROC_GROUP_GET",
+
+ "CUSTOM_COMMAND"};
+
+ if (cmd < 0 || cmd >= APP_CMD_MAX) return cmd_string_table[APP_CMD_MAX];
+
+ return cmd_string_table[cmd];
+}
--- /dev/null
+/*
+ * Copyright (c) 2019 - 2022 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 "aul/include/aul_comp_context.h"
+
+#include <bundle_cpp.h>
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "aul/app_request.h"
+#include "aul/aul_api.h"
+#include "aul/aul_util.h"
+#include "aul/common/exception.hh"
+#include "aul/component/component_running_context.hh"
+#include "aul/include/aul.h"
+#include "aul/include/aul_error.h"
+
+using namespace aul;
+
+struct aul_comp_context_s {
+ void* dummy;
+};
+
+namespace {
+using namespace aul::internal;
+
+ComponentRunningContext* CreateComponentRunningContext(
+ const tizen_base::Bundle& b) {
+ return ComponentRunningContext::Builder()
+ .SetComponentId(b)
+ .SetInstanceId(b)
+ .SetAppId(b)
+ .SetType(b)
+ .SetPid(b)
+ .SetStatus(b)
+ .SetSubComponent(b);
+}
+
+ComponentRunningContext* GetComponentRunningContext(
+ const std::string& component_id, uid_t uid) {
+ tizen_base::Bundle b { { AUL_K_COMPONENT_ID, component_id } };
+ int fd = AppRequest(COMP_CONTEXT_GET, uid)
+ .With(std::move(b))
+ .SendSimply(AUL_SOCK_ASYNC);
+ if (fd < 0)
+ THROW(fd);
+
+ app_pkt_t* pkt;
+ int ret = aul_sock_recv_reply_pkt(fd, &pkt);
+ if (ret < 0)
+ THROW(aul_error_convert(fd));
+
+ auto pkt_auto = std::unique_ptr<app_pkt_t, decltype(std::free)*>(
+ pkt, std::free);
+
+ if (pkt->cmd != APP_GET_INFO_OK) {
+ _E("Failed to get component running context. error(%d)", pkt->cmd);
+ THROW(pkt->cmd);
+ }
+
+ bundle* kb = nullptr;
+ if (pkt->opt & AUL_SOCK_BUNDLE) {
+ kb = bundle_decode(pkt->data, pkt->len);
+ if (kb == nullptr)
+ THROW(AUL_R_ENOMEM);
+ } else {
+ _E("Wrong packet");
+ THROW(AUL_R_ERROR);
+ }
+
+ return CreateComponentRunningContext(tizen_base::Bundle(kb, false, true));
+}
+
+std::vector<std::unique_ptr<ComponentRunningContext>>
+GetComponentRunningContexts() {
+ int fd = AppRequest(COMP_CONTEXT_FOREACH, getuid())
+ .SendSimply(AUL_SOCK_ASYNC);
+ if (fd < 0)
+ THROW(fd);
+
+ std::vector<std::unique_ptr<ComponentRunningContext>> contexts;
+ int ret = aul_sock_recv_pkt_with_cb(fd,
+ [](app_pkt_t* pkt, void* user_data) {
+ if (pkt == nullptr) {
+ _E("pkt is nullptr");
+ return;
+ }
+
+ if (pkt->cmd == APP_GET_INFO_ERROR) {
+ _E("Failed to get component running context");
+ return;
+ }
+
+ bundle* kb = nullptr;
+ if (pkt->opt & AUL_SOCK_BUNDLE)
+ kb = bundle_decode(pkt->data, pkt->len);
+
+ if (kb == nullptr)
+ return;
+
+ tizen_base::Bundle b(kb, false, true);
+ auto* context_array =
+ static_cast<std::vector<std::unique_ptr<ComponentRunningContext>>*>(
+ user_data);
+
+ try {
+ context_array->emplace_back(CreateComponentRunningContext(b));
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%s)", e.what());
+ }
+ }, &contexts);
+ if (ret < 0)
+ THROW(aul_error_convert(ret));
+
+ return contexts;
+}
+
+int SendRequest(ComponentRunningContext* context, int cmd) {
+ tizen_base::Bundle b {
+ { AUL_K_COMPONENT_ID, context->GetComponentId() },
+ { AUL_K_INSTANCE_ID, context->GetInstanceId() }
+ };
+
+ int ret = AppRequest(cmd, getuid())
+ .With(std::move(b))
+ .SendSimply();
+ if (ret < 0)
+ THROW(ret);
+
+ return ret;
+}
+
+} // namespace
+
+extern "C" API int aul_comp_context_foreach_comp_context(
+ aul_comp_context_cb callback, void* user_data) {
+ if (callback == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ try {
+ for (auto const& context : GetComponentRunningContexts()) {
+ auto* handle = reinterpret_cast<aul_comp_context_h>(context.get());
+ if (!callback(handle, user_data))
+ break;
+ }
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%d)", e.GetErrorCode());
+ return e.GetErrorCode();
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_context_get_comp_id(aul_comp_context_h handle,
+ const char** comp_id) {
+ if (handle == nullptr || comp_id == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* context = reinterpret_cast<ComponentRunningContext*>(handle);
+ *comp_id = context->GetComponentId().c_str();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_context_get_instance_id(aul_comp_context_h handle,
+ const char** instance_id) {
+ if (handle == nullptr || instance_id == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* context = reinterpret_cast<ComponentRunningContext*>(handle);
+ *instance_id = context->GetInstanceId().c_str();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_context_get_app_id(aul_comp_context_h handle,
+ const char** app_id) {
+ if (handle == nullptr || app_id == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* context = reinterpret_cast<ComponentRunningContext*>(handle);
+ *app_id = context->GetAppId().c_str();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_context_get_type(aul_comp_context_h handle,
+ const char** type) {
+ if (handle == nullptr || type == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* context = reinterpret_cast<ComponentRunningContext*>(handle);
+ *type = context->GetType().c_str();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_context_get_pid(aul_comp_context_h handle,
+ pid_t* pid) {
+ if (handle == nullptr || pid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* context = reinterpret_cast<ComponentRunningContext*>(handle);
+ *pid = context->GetPid();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_context_get_status(aul_comp_context_h handle,
+ int* status) {
+ if (handle == nullptr || status == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* context = reinterpret_cast<ComponentRunningContext*>(handle);
+ *status = context->GetStatus();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_context_is_sub_comp(aul_comp_context_h handle,
+ bool* is_sub_comp) {
+ if (handle == nullptr || is_sub_comp == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* context = reinterpret_cast<ComponentRunningContext*>(handle);
+ *is_sub_comp = context->IsSubComponent();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_context_create(const char* comp_id,
+ aul_comp_context_h* handle) {
+ return aul_comp_context_usr_create(comp_id, getuid(), handle);
+}
+
+extern "C" API int aul_comp_context_usr_create(const char* comp_id,
+ uid_t uid, aul_comp_context_h* handle) {
+ if (comp_id == nullptr || handle == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ try {
+ auto* context = GetComponentRunningContext(comp_id, uid);
+ if (context == nullptr)
+ return AUL_R_ENOMEM;
+
+ *handle = reinterpret_cast<aul_comp_context_h>(context);
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%d)", e.GetErrorCode());
+ return e.GetErrorCode();
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_context_destroy(aul_comp_context_h handle) {
+ if (handle == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* context = reinterpret_cast<ComponentRunningContext*>(handle);
+ delete context;
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_context_clone(aul_comp_context_h handle,
+ aul_comp_context_h* clone) {
+ if (handle == nullptr || clone == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* context = reinterpret_cast<ComponentRunningContext*>(handle);
+ auto* cloned_context = new (std::nothrow) ComponentRunningContext(*context);
+ if (cloned_context == nullptr) {
+ _E("Out of memory");
+ return AUL_R_ENOMEM;
+ }
+
+ *clone = reinterpret_cast<aul_comp_context_h>(cloned_context);
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_context_is_running(aul_comp_context_h handle,
+ bool* running) {
+ if (handle == nullptr || running == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ try {
+ auto* context = reinterpret_cast<ComponentRunningContext*>(handle);
+ int ret = SendRequest(context, COMP_CONTEXT_IS_RUNNING);
+ *running = (ret == 0) ? false : true;
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%d)", e.GetErrorCode());
+ return e.GetErrorCode();
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" int aul_comp_context_resume(aul_comp_context_h handle) {
+ if (handle == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ try {
+ auto* context = reinterpret_cast<ComponentRunningContext*>(handle);
+ SendRequest(context, COMP_CONTEXT_RESUME);
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%d)", e.GetErrorCode());
+ return e.GetErrorCode();
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" int aul_comp_context_pause(aul_comp_context_h handle) {
+ if (handle == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ try {
+ auto* context = reinterpret_cast<ComponentRunningContext*>(handle);
+ SendRequest(context, COMP_CONTEXT_PAUSE);
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%d)", e.GetErrorCode());
+ return e.GetErrorCode();
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" int aul_comp_context_terminate_bg_comp(aul_comp_context_h handle) {
+ if (handle == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ try {
+ auto* context = reinterpret_cast<ComponentRunningContext*>(handle);
+ SendRequest(context, COMP_CONTEXT_TERMINATE_BG_COMP);
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%d)", e.GetErrorCode());
+ return e.GetErrorCode();
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" int aul_comp_context_terminate(aul_comp_context_h handle) {
+ if (handle == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ try {
+ auto* context = reinterpret_cast<ComponentRunningContext*>(handle);
+ SendRequest(context, COMP_CONTEXT_TERMINATE);
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%d)", e.GetErrorCode());
+ return e.GetErrorCode();
+ }
+
+ return AUL_R_OK;
+}
--- /dev/null
+/*
+ * Copyright (c) 2019 - 2022 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 "aul/include/aul_comp_info.h"
+
+#include <vconf.h>
+
+#include <cctype>
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "aul/app_request.h"
+#include "aul/aul_api.h"
+#include "aul/aul_util.h"
+#include "aul/common/exception.hh"
+#include "aul/component/component_info.hh"
+#include "aul/include/aul.h"
+#include "aul/include/aul_error.h"
+#include "aul/include/aul_sock.h"
+
+using namespace aul;
+
+namespace {
+using namespace aul::internal;
+
+constexpr const char kDefaultLocale[] = "No Locale";
+
+std::string GetSystemLocale() {
+ char* lang = vconf_get_str(VCONFKEY_LANGSET);
+ if (lang == nullptr) {
+ lang = strdup(kDefaultLocale);
+ if (lang == nullptr) {
+ _E("strdup() is failed");
+ THROW(AUL_R_ENOMEM);
+ }
+ }
+
+ auto lang_auto = std::unique_ptr<char, decltype(std::free)*>(lang, std::free);
+
+ return std::string({
+ lang[0],
+ lang[1],
+ '-',
+ static_cast<char>(std::tolower(static_cast<int>(lang[3]))),
+ static_cast<char>(std::tolower(static_cast<int>(lang[4])))
+ });
+}
+
+ComponentInfo* CreateComponentInfoFromAppPacket(
+ app_pkt_t* pkt) {
+ if (pkt->cmd != APP_GET_INFO_OK)
+ THROW(aul_error_convert(pkt->cmd));
+
+ bundle* kb = nullptr;
+ if (pkt->opt & AUL_SOCK_BUNDLE) {
+ kb = bundle_decode(pkt->data, pkt->len);
+ if (kb == nullptr)
+ THROW(AUL_R_ENOMEM);
+ } else {
+ THROW(AUL_R_ERROR);
+ }
+
+ tizen_base::Bundle b(kb, false, true);
+ return ComponentInfo::Builder()
+ .SetAppId(b)
+ .SetComponentId(b)
+ .SetType(b)
+ .SetLaunchMode(b)
+ .SetMainComponent(b)
+ .SetIconDisplay(b)
+ .SetTaskmanage(b)
+ .SetLocalizedInfo(b);
+}
+
+ComponentInfo* GetComponentInfo(const char* comp_id,
+ uid_t uid) {
+ tizen_base::Bundle b { { AUL_K_COMPONENT_ID, comp_id } };
+ int fd = AppRequest(COMP_INFO_GET, uid)
+ .With(std::move(b))
+ .SendSimply(AUL_SOCK_ASYNC);
+ if (fd < 0)
+ THROW(fd);
+
+ app_pkt_t* pkt = nullptr;
+ int ret = aul_sock_recv_reply_pkt(fd, &pkt);
+ if (ret < 0)
+ THROW(aul_error_convert(ret));
+
+ auto pkt_auto = std::unique_ptr<app_pkt_t, decltype(std::free)*>(
+ pkt, std::free);
+ return CreateComponentInfoFromAppPacket(pkt);
+}
+
+std::vector<std::shared_ptr<ComponentInfo>> GetComponentInfos(uid_t uid) {
+ int fd = AppRequest(COMP_INFO_FOREACH, uid)
+ .SendSimply(AUL_SOCK_ASYNC);
+ if (fd < 0)
+ THROW(fd);
+
+ std::vector<std::shared_ptr<ComponentInfo>> component_infos;
+ int ret = aul_sock_recv_pkt_with_cb(fd,
+ [](app_pkt_t* pkt, void* user_data) {
+ if (pkt == nullptr)
+ return;
+
+ try {
+ auto* infos =
+ static_cast<std::vector<std::shared_ptr<ComponentInfo>>*>(
+ user_data);
+ infos->emplace_back(CreateComponentInfoFromAppPacket(pkt));
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%s)", e.what());
+ }
+ }, &component_infos);
+ if (ret < 0)
+ THROW(aul_error_convert(ret));
+
+ return component_infos;
+}
+
+} // namespace
+
+extern "C" API int aul_comp_info_create(const char* comp_id,
+ aul_comp_info_h* handle) {
+ return aul_comp_info_usr_create(comp_id, getuid(), handle);
+}
+
+extern "C" API int aul_comp_info_usr_create(const char* comp_id, uid_t uid,
+ aul_comp_info_h* handle) {
+ if(comp_id == nullptr || handle == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ try {
+ auto* info = GetComponentInfo(comp_id, uid);
+ *handle = static_cast<aul_comp_info_h>(info);
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%s)", e.what());
+ return e.GetErrorCode();
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_info_destroy(aul_comp_info_h handle) {
+ if (handle == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* info = static_cast<ComponentInfo*>(handle);
+ delete info;
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_info_clone(aul_comp_info_h handle,
+ aul_comp_info_h* clone) {
+ if (handle == nullptr || clone == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* info = static_cast<ComponentInfo*>(handle);
+ auto* cloned_info = new (std::nothrow) ComponentInfo(*info);
+ if (cloned_info == nullptr) {
+ _E("Out of memory");
+ return AUL_R_ENOMEM;
+ }
+
+ *clone = static_cast<aul_comp_info_h>(cloned_info);
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_info_get_app_id(aul_comp_info_h handle,
+ const char** app_id) {
+ if (handle == nullptr || app_id == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* info = static_cast<ComponentInfo*>(handle);
+ *app_id = info->GetAppId().c_str();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_info_get_comp_id(aul_comp_info_h handle,
+ const char** comp_id) {
+ if (handle == nullptr || comp_id == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* info = static_cast<ComponentInfo*>(handle);
+ *comp_id = info->GetComponentId().c_str();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_info_get_type(aul_comp_info_h handle,
+ const char** type) {
+ if (handle == nullptr || type == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* info = static_cast<ComponentInfo*>(handle);
+ *type = info->GetType().c_str();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_info_get_launch_mode(aul_comp_info_h handle,
+ const char** launch_mode) {
+ if (handle == nullptr || launch_mode == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* info = static_cast<ComponentInfo*>(handle);
+ *launch_mode = info->GetLaunchMode().c_str();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_info_is_main_comp(aul_comp_info_h handle,
+ bool* main_comp) {
+ if (handle == nullptr || main_comp == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* info = static_cast<ComponentInfo*>(handle);
+ *main_comp = info->IsMainComponent();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_info_is_icon_display(aul_comp_info_h handle,
+ bool* icon_display) {
+ if (handle == nullptr || icon_display == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* info = static_cast<ComponentInfo*>(handle);
+ *icon_display = info->IsIconDisplay();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_info_is_taskmanage(aul_comp_info_h handle,
+ bool* taskmanage) {
+ if (handle == nullptr || taskmanage == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* info = static_cast<ComponentInfo*>(handle);
+ *taskmanage = info->IsTaskmanage();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_info_get_icon(aul_comp_info_h handle,
+ const char** icon) {
+ if (handle == nullptr || icon == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* info = static_cast<ComponentInfo*>(handle);
+ try {
+ auto* localized_info = info->GetLocalizedInfo(GetSystemLocale());
+ if (localized_info == nullptr) {
+ localized_info = info->GetLocalizedInfo(kDefaultLocale);
+ if (localized_info == nullptr)
+ return AUL_R_ENOENT;
+ }
+
+ *icon = localized_info->GetIcon().c_str();
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%s)", e.what());
+ return e.GetErrorCode();
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_info_get_label(aul_comp_info_h handle,
+ const char** label) {
+ if (handle == nullptr || label == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* info = static_cast<ComponentInfo*>(handle);
+ try {
+ auto* localized_info = info->GetLocalizedInfo(GetSystemLocale());
+ if (localized_info == nullptr) {
+ localized_info = info->GetLocalizedInfo(kDefaultLocale);
+ if (localized_info == nullptr)
+ return AUL_R_ENOENT;
+ }
+
+ *label = localized_info->GetLabel().c_str();
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%s)", e.what());
+ return e.GetErrorCode();
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_info_get_localed_label(aul_comp_info_h handle,
+ const char* locale, const char** label) {
+ if (handle == nullptr || locale == nullptr || label == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* info = static_cast<ComponentInfo*>(handle);
+ auto* localized_info = info->GetLocalizedInfo(locale);
+ if (localized_info == nullptr) {
+ localized_info = info->GetLocalizedInfo(kDefaultLocale);
+ if (localized_info == nullptr)
+ return AUL_R_ENOENT;
+ }
+
+ *label = localized_info->GetLabel().c_str();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_info_foreach_comp_info_from_app(const char* app_id,
+ aul_comp_info_cb callback, void* user_data) {
+ return aul_comp_info_usr_foreach_comp_info_from_app(app_id, getuid(),
+ callback, user_data);
+}
+
+extern "C" API int aul_comp_info_usr_foreach_comp_info_from_app(
+ const char* app_id, uid_t uid, aul_comp_info_cb callback, void* user_data) {
+ if (app_id == nullptr || callback == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ try {
+ for (auto const& info : GetComponentInfos(uid)) {
+ if (info->GetAppId().compare(app_id) != 0)
+ continue;
+
+ if (!callback(info.get(), user_data))
+ break;
+ }
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%s)", e.what());
+ return e.GetErrorCode();
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_info_foreach_comp_info(aul_comp_info_cb callback,
+ void* user_data) {
+ return aul_comp_info_usr_foreach_comp_info(getuid(), callback, user_data);
+}
+
+extern "C" API int aul_comp_info_usr_foreach_comp_info(uid_t uid,
+ aul_comp_info_cb callback, void* user_data) {
+ if (callback == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ try {
+ for (auto const& info : GetComponentInfos(uid)) {
+ if (!callback(info.get(), user_data))
+ break;
+ }
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%s)", e.what());
+ return e.GetErrorCode();
+ }
+
+ return AUL_R_OK;
+}
--- /dev/null
+/*
+ * Copyright (c) 2019 - 2022 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul_comp_status.h"
+
+#include <bundle_cpp.h>
+
+#include "include/aul.h"
+#include "include/aul_sock.h"
+#include "include/aul_error.h"
+#include "aul_util.h"
+#include "aul_api.h"
+
+#include "app_request.h"
+
+using namespace aul::internal;
+
+extern "C" API int aul_comp_status_update(const char* instance_id, int status) {
+ if (instance_id == nullptr ||
+ status < STATUS_LAUNCHING ||
+ status > STATUS_TERMINATE) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ tizen_base::Bundle b {
+ { AUL_K_INSTANCE_ID, instance_id },
+ { AUL_K_STATUS, std::to_string(status) },
+ };
+
+ return AppRequest(COMP_STATUS_UPDATE, getuid())
+ .With(std::move(b))
+ .SendSimply(AUL_SOCK_NOREPLY);
+}
+
+extern "C" API int aul_comp_notify_start(const char* instance_id) {
+ if (instance_id == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ return AppRequest(COMP_NOTIFY_START, getuid())
+ .SetInstId(instance_id)
+ .SendSimply(AUL_SOCK_NOREPLY);
+}
+
+extern "C" API int aul_comp_notify_exit(const char* instance_id) {
+ if (instance_id == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ return AppRequest(COMP_NOTIFY_EXIT, getuid())
+ .SetInstId(instance_id)
+ .SendSimply(AUL_SOCK_NOREPLY);
+}
+
+extern "C" API int aul_comp_resume(const char* instance_id) {
+ if (instance_id == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ return AppRequest(COMP_CONTEXT_RESUME, getuid())
+ .SetInstId(instance_id)
+ .SendSimply();
+}
+
+extern "C" API int aul_comp_terminate(const char* instance_id) {
+ if (instance_id == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ return AppRequest(COMP_CONTEXT_TERMINATE, getuid())
+ .SetInstId(instance_id)
+ .SendSimply();
+}
+
+extern "C" API int aul_comp_is_running(const char* instance_id, bool* running) {
+ if (instance_id == nullptr || running == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ int ret = AppRequest(COMP_CONTEXT_IS_RUNNING, getuid())
+ .SetInstId(instance_id)
+ .SendSimply();
+ if (ret < 0)
+ return ret;
+
+ *running = (ret == 0) ? false : true;
+ return AUL_R_OK;
+}
--- /dev/null
+/*
+ * Copyright (c) 2018 - 2022 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul_complication.h"
+
+#include <bundle_cpp.h>
+
+#include <string>
+
+#include "app_request.h"
+#include "aul_api.h"
+#include "aul_util.h"
+#include "include/aul.h"
+#include "include/aul_sock.h"
+
+using namespace aul::internal;
+
+namespace {
+
+constexpr const char kUpdateRequest[] = "__UPDATE_REQUEST__";
+constexpr const char kLaunchRequest[] = "__LAUNCH_REQUEST__";
+
+} // namespace
+
+extern "C" API int aul_complication_update_request(const char* appid,
+ const char* provider_appid, uid_t uid) {
+ if (appid == nullptr || provider_appid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ tizen_base::Bundle b {
+ { AUL_K_CALLER_APPID, appid },
+ { AUL_K_COMPLICATION_MODE, kUpdateRequest}
+ };
+
+ int ret = AppRequest(COMPLICATION_UPDATE_REQUEST, uid)
+ .With(std::move(b))
+ .SetAppId(provider_appid)
+ .Send();
+ if (ret < 0)
+ return ret;
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_complication_launch_with_extra_data(const char* appid,
+ const char* provider_appid, uid_t uid, const char* key, const char* value) {
+ if (appid == nullptr ||
+ provider_appid == nullptr ||
+ key == nullptr ||
+ value == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ tizen_base::Bundle b {
+ { AUL_K_CALLER_APPID, appid },
+ { AUL_K_COMPLICATION_MODE, kLaunchRequest },
+ { key, value }
+ };
+
+ int ret = AppRequest(COMPLICATION_UPDATE_REQUEST, uid)
+ .With(std::move(b))
+ .SetAppId(provider_appid)
+ .Send();
+ if (ret < 0)
+ return ret;
+
+ return AUL_R_OK;
+}
--- /dev/null
+/*
+ * Copyright (c) 2018 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 <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <glib.h>
+#include <bundle_internal.h>
+
+#include "aul.h"
+#include "aul_api.h"
+#include "aul_util.h"
+#include "aul_debug_info.h"
+
+#define PATH_AUL "/usr/share/aul"
+#define TAG_DEBUGGER "[DEBUGGER]"
+#define TAG_NAME "NAME"
+#define TAG_EXTRA_KEY "EXTRA_KEY"
+#define TAG_EXTRA_ENV "EXTRA_ENV"
+#define TAG_UNLINK "UNLINK"
+#define TAG_ATTACH "ATTACH"
+#define TAG_LAST_EXTRA_KEY "LAST_EXTRA_KEY"
+#define TAG_DEFAULT_OPT "DEFAULT_OPT"
+
+#define FREE_AND_NULL(x) do { \
+ if (x) { \
+ free(x); \
+ x = NULL; \
+ } \
+} while (0)
+
+struct debugger_info_s {
+ char *name;
+ char *attach;
+ GList *extra_key_list;
+ GList *extra_env_list;
+ GList *unlink_list;
+ GList *last_extra_key_list;
+ GList *default_opt_list;
+};
+
+struct debug_info_s {
+ bool initialized;
+ GList *debugger_list;
+};
+
+struct cb_data_s {
+ bundle *src;
+ bundle *dst;
+};
+
+static struct debug_info_s __info;
+
+static struct debugger_info_s *__create_debugger_info(void)
+{
+ struct debugger_info_s *info;
+
+ info = calloc(1, sizeof(struct debugger_info_s));
+ if (info == NULL) {
+ _E("out of memory");
+ return NULL;
+ }
+
+ return info;
+}
+
+static void __destroy_debugger_info(gpointer data)
+{
+ struct debugger_info_s *info = (struct debugger_info_s *)data;
+
+ if (info == NULL)
+ return;
+
+ if (info->default_opt_list)
+ g_list_free_full(info->default_opt_list, free);
+ if (info->last_extra_key_list)
+ g_list_free_full(info->last_extra_key_list, free);
+ if (info->attach)
+ free(info->attach);
+ if (info->unlink_list)
+ g_list_free_full(info->unlink_list, free);
+ if (info->extra_env_list)
+ g_list_free_full(info->extra_env_list, free);
+ if (info->extra_key_list)
+ g_list_free_full(info->extra_key_list, free);
+ if (info->name)
+ free(info->name);
+ free(info);
+}
+
+static struct debugger_info_s *__find_debugger_info(const char *name)
+{
+ struct debugger_info_s *debugger;
+ GList *iter;
+
+ iter = __info.debugger_list;
+ while (iter) {
+ debugger = (struct debugger_info_s *)iter->data;
+ if (debugger && debugger->name &&
+ !strcmp(debugger->name, name))
+ return debugger;
+
+ iter = g_list_next(iter);
+ }
+
+ return NULL;
+}
+
+static GList *__parse_file(GList *list, const char *path)
+{
+ FILE *fp;
+ char buf[LINE_MAX];
+ char *tok1 = NULL;
+ char *tok2 = NULL;
+ struct debugger_info_s *info = NULL;
+
+ fp = fopen(path, "rt");
+ if (fp == NULL)
+ return list;
+
+ while (fgets(buf, sizeof(buf), fp) != NULL) {
+ FREE_AND_NULL(tok1);
+ FREE_AND_NULL(tok2);
+ sscanf(buf, "%ms %ms", &tok1, &tok2);
+ if (tok1 && strcasecmp(TAG_DEBUGGER, tok1) == 0) {
+ if (info) {
+ _D("name: %s", info->name);
+ list = g_list_append(list, info);
+ }
+
+ info = __create_debugger_info();
+ if (info == NULL)
+ break;
+
+ continue;
+ }
+
+ if (!tok1 || !tok2)
+ continue;
+ if (tok1[0] == '\0' || tok2[0] == '\0' || tok1[0] == '#')
+ continue;
+ if (info == NULL)
+ continue;
+
+ if (strcasecmp(TAG_NAME, tok1) == 0) {
+ info->name = strdup(tok2);
+ if (info->name == NULL) {
+ _E("out of memory");
+ __destroy_debugger_info(info);
+ info = NULL;
+ break;
+ }
+ } else if (strcasecmp(TAG_EXTRA_KEY, tok1) == 0) {
+ info->extra_key_list = g_list_append(
+ info->extra_key_list, strdup(tok2));
+ } else if (strcasecmp(TAG_EXTRA_ENV, tok1) == 0) {
+ info->extra_env_list = g_list_append(
+ info->extra_env_list, strdup(tok2));
+ } else if (strcasecmp(TAG_UNLINK, tok1) == 0) {
+ info->unlink_list = g_list_append(info->unlink_list,
+ strdup(tok2));
+ } else if (strcasecmp(TAG_ATTACH, tok1) == 0) {
+ info->attach = strdup(tok2);
+ if (info->attach == NULL) {
+ _E("attach is NULL");
+ __destroy_debugger_info(info);
+ info = NULL;
+ break;
+ }
+ } else if (strcasecmp(TAG_LAST_EXTRA_KEY, tok1) == 0) {
+ info->last_extra_key_list = g_list_append(
+ info->last_extra_key_list,
+ strdup(tok2));
+ } else if (strcasecmp(TAG_DEFAULT_OPT, tok1) == 0) {
+ info->default_opt_list = g_list_append(
+ info->default_opt_list,
+ strdup(tok2));
+ }
+ }
+ fclose(fp);
+
+ if (info) {
+ _D("name: %s", info->name);
+ list = g_list_append(list, info);
+ }
+
+ if (tok1)
+ free(tok1);
+ if (tok2)
+ free(tok2);
+
+ return list;
+}
+
+static int __load_debugger_info(const char *path)
+{
+ DIR *dp;
+ struct dirent *dentry = NULL;
+ char buf[PATH_MAX];
+ char *ext;
+
+ if (path == NULL)
+ return -1;
+
+ dp = opendir(path);
+ if (dp == NULL)
+ return -1;
+
+ while ((dentry = readdir(dp)) != NULL) {
+ if (dentry->d_name[0] == '.')
+ continue;
+
+ ext = strrchr(dentry->d_name, '.');
+ if (ext && strcmp(ext, ".debugger") == 0) {
+ snprintf(buf, sizeof(buf), "%s/%s",
+ path, dentry->d_name);
+ __info.debugger_list = __parse_file(
+ __info.debugger_list, buf);
+ }
+ }
+ closedir(dp);
+
+ return 0;
+}
+
+static void __unload_debugger_info(void)
+{
+ if (__info.debugger_list == NULL)
+ return;
+
+ g_list_free_full(__info.debugger_list, __destroy_debugger_info);
+ __info.debugger_list = NULL;
+}
+
+API int aul_debug_info_init(void)
+{
+ int r;
+
+ if (__info.initialized)
+ return AUL_R_OK;
+
+ r = __load_debugger_info(PATH_AUL);
+ if (r != 0) {
+ _E("Failed to loader debugger information");
+ return AUL_R_ERROR;
+ }
+
+ __info.initialized = true;
+ return AUL_R_OK;
+}
+
+API int aul_debug_info_fini(void)
+{
+ if (!__info.initialized)
+ return AUL_R_OK;
+
+ __unload_debugger_info();
+
+ __info.initialized = false;
+ return AUL_R_OK;
+}
+
+static void __copy_data(bundle *src, bundle *dst, const char *key)
+{
+ const char **str_arr;
+ char *str = NULL;
+ int len = 0;
+
+ if (bundle_get_type(src, key) == BUNDLE_TYPE_STR_ARRAY) {
+ str_arr = bundle_get_str_array(src, key, &len);
+ if (str_arr) {
+ bundle_del(dst, key);
+ bundle_add_str_array(dst, key, str_arr, len);
+ }
+ } else {
+ bundle_get_str(src, key, &str);
+ if (str) {
+ bundle_del(dst, key);
+ bundle_add_str(dst, key, str);
+ }
+ }
+}
+
+static void __foreach_cb(gpointer data, gpointer user_data)
+{
+ struct cb_data_s *cb_data = (struct cb_data_s *)user_data;
+ const char *key = (const char *)data;
+
+ if (!key || !cb_data) {
+ _E("Critical error!");
+ return;
+ }
+
+ __copy_data(cb_data->src, cb_data->dst, key);
+ _D("[__DEBUG_INFO__] key(%s)", key);
+}
+
+static void __set_debug_info(struct debugger_info_s *debugger,
+ bundle *src, bundle *dst)
+{
+ const char *val;
+ struct cb_data_s cb_data = {
+ .src = src,
+ .dst = dst
+ };
+
+ __copy_data(src, dst, AUL_K_SDK);
+ if (debugger->extra_key_list)
+ g_list_foreach(debugger->extra_key_list, __foreach_cb, &cb_data);
+ if (debugger->extra_env_list)
+ g_list_foreach(debugger->extra_env_list, __foreach_cb, &cb_data);
+ if (debugger->unlink_list)
+ g_list_foreach(debugger->unlink_list, __foreach_cb, &cb_data);
+ if (debugger->last_extra_key_list)
+ g_list_foreach(debugger->last_extra_key_list, __foreach_cb, &cb_data);
+ if (debugger->default_opt_list)
+ g_list_foreach(debugger->default_opt_list, __foreach_cb, &cb_data);
+
+ val = bundle_get_val(src, AUL_K_ORG_CALLER_PID);
+ if (!val)
+ val = bundle_get_val(src, AUL_K_CALLER_PID);
+
+ if (val) {
+ bundle_del(dst, AUL_K_ORG_CALLER_PID);
+ bundle_add(dst, AUL_K_ORG_CALLER_PID, val);
+ }
+
+ _D("[__DEBUG_INFO__] Debugger(%s)", debugger->name);
+}
+
+API int aul_debug_info_set(bundle *src, bundle *dst)
+{
+ const char *name;
+ struct debugger_info_s *debugger;
+
+ if (!src || !dst) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ if (!__info.initialized) {
+ _E("Debug info is not initilaized");
+ return AUL_R_ERROR;
+ }
+
+ name = bundle_get_val(src, AUL_K_SDK);
+ if (!name) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ debugger = __find_debugger_info(name);
+ if (!debugger) {
+ _E("Failed to find debugger(%s)", name);
+ return AUL_R_EINVAL;
+ }
+
+ __set_debug_info(debugger, src, dst);
+
+ return AUL_R_OK;
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 "aul/include/aul_error.h"
+
+#include <errno.h>
+
+#include "aul/aul_api.h"
+#include "aul/aul_util.h"
+#include "aul/include/aul.h"
+#include "aul/include/aul_sock.h"
+
+extern "C" API int aul_error_convert(int res) {
+ int ret;
+
+ switch (res) {
+ case -ENOMEM:
+ ret = AUL_R_ENOMEM;
+ break;
+ case -EREJECTED:
+ ret = AUL_R_EREJECTED;
+ break;
+ case -ENOENT:
+ ret = AUL_R_ENOAPP;
+ break;
+ case -ETERMINATING:
+ ret = AUL_R_ETERMINATING;
+ break;
+ case -EILLEGALACCESS:
+ ret = AUL_R_EILLACC;
+ break;
+ case -ELOCALLAUNCH_ID:
+ ret = AUL_R_LOCAL;
+ break;
+ case -EAGAIN:
+ ret = AUL_R_ETIMEOUT;
+ break;
+ case -EINVAL:
+ ret = AUL_R_EINVAL;
+ break;
+ case -ECOMM:
+ ret = AUL_R_ECOMM;
+ break;
+ case -ECANCELED:
+ ret = AUL_R_ECANCELED;
+ break;
+ default:
+ ret = AUL_R_ERROR;
+ break;
+ }
+
+ return ret;
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 - 2022 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 "aul/include/aul_job_scheduler.h"
+
+#include <bundle_cpp.h>
+
+#include "aul/app_request.h"
+#include "aul/aul_api.h"
+#include "aul/aul_util.h"
+#include "aul/include/aul.h"
+#include "aul/include/aul_sock.h"
+
+extern "C" API int aul_job_scheduler_update_job_status(const char* job_id,
+ aul_job_status_e job_status) {
+ if (job_id == nullptr ||
+ job_status < JOB_STATUS_START ||
+ job_status > JOB_STATUS_FINISHED) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ tizen_base::Bundle b {
+ { AUL_K_JOB_ID, job_id },
+ { AUL_K_JOB_STATUS, std::to_string(job_status) }
+ };
+
+ return aul::internal::AppRequest(JOB_STATUS_UPDATE, getuid())
+ .With(std::move(b))
+ .SendSimply(AUL_SOCK_NOREPLY);
+}
--- /dev/null
+/*
+ * Copyright (c) 2018 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 _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
+#include <stdio.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <ctype.h>
+#include <glib.h>
+#include <bundle_internal.h>
+
+#include "aul_api.h"
+#include "aul_cmd.h"
+#include "aul_util.h"
+#include "aul.h"
+#include "aul_sock.h"
+#include "launch.h"
+#include "aul_watch_control_internal.h"
+#include "aul_worker.h"
+#include "aul_watchdog.h"
+
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
+
+#define K_SERVICE_THREAD "__K_SERVICE_THREAD"
+
+#define AUL_CTOR __attribute__ ((constructor))
+#define AUL_DTOR __attribute__ ((destructor))
+
+typedef struct client_channel_s {
+ int fd;
+ pid_t pid;
+ uid_t uid;
+} client_channel_t;
+
+struct aul_request_s {
+ int cmd;
+ int clifd;
+ bundle *b;
+ int req_id;
+};
+
+typedef struct aul_request_s *aul_request_h;
+
+typedef void (*dispatcher)(aul_request_h req);
+
+typedef struct aul_handler_s {
+ aul_handler_fn callback;
+ void *user_data;
+} aul_handler;
+
+typedef struct subapp_handler_s {
+ bool is_subapp;
+ subapp_fn callback;
+ void *user_data;
+} subapp_handler;
+
+typedef struct data_control_provider_handler_s {
+ data_control_provider_handler_fn callback;
+} data_control_provider_handler;
+
+typedef struct launch_context_s {
+ bool initialized;
+ aul_worker_h worker;
+ aul_handler aul;
+ subapp_handler subapp;
+ data_control_provider_handler dcp;
+ GList* clients;
+ GRecMutex init_mutex;
+ GRecMutex mutex;
+ GMainContext *tizen_context;
+ bool touch_argv_handler;
+} launch_context;
+
+static launch_context __context;
+
+AUL_CTOR static void __aul_constructor(void)
+{
+ g_rec_mutex_init(&__context.init_mutex);
+}
+
+AUL_DTOR static void __aul_destructor(void)
+{
+ if (g_rec_mutex_trylock(&__context.init_mutex))
+ g_rec_mutex_unlock(&__context.init_mutex);
+
+ g_rec_mutex_clear(&__context.init_mutex);
+}
+
+static void __destroy_client_channel(gpointer data)
+{
+ client_channel_t *channel = data;
+ free(channel);
+}
+
+static client_channel_t *__create_client_channel(int fd, pid_t pid, uid_t uid)
+{
+ client_channel_t *channel;
+
+ channel = calloc(1, sizeof(client_channel_t));
+ if (!channel) {
+ _E("Out of memory");
+ return NULL;
+ }
+
+ channel->fd = fd;
+ channel->pid = pid;
+ channel->uid = uid;
+
+ return channel;
+}
+
+static void __add_client_channel(client_channel_t *channel)
+{
+ g_rec_mutex_lock(&__context.mutex);
+ __context.clients = g_list_append(__context.clients, channel);
+ g_rec_mutex_unlock(&__context.mutex);
+}
+
+static void __remove_client_channel(client_channel_t *channel)
+{
+ g_rec_mutex_lock(&__context.mutex);
+ __context.clients = g_list_remove(__context.clients, channel);
+ g_rec_mutex_unlock(&__context.mutex);
+}
+
+static client_channel_t *__find_client_channel(int fd)
+{
+ client_channel_t *channel;
+ GList *iter;
+
+ g_rec_mutex_lock(&__context.mutex);
+ iter = __context.clients;
+ while (iter) {
+ channel = iter->data;
+ if (channel->fd == fd) {
+ g_rec_mutex_unlock(&__context.mutex);
+ return channel;
+ }
+
+ iter = g_list_next(iter);
+ }
+ g_rec_mutex_unlock(&__context.mutex);
+
+ return NULL;
+}
+
+static void __invoke_aul_handler(aul_type type, bundle *b)
+{
+ if (__context.aul.callback)
+ __context.aul.callback(type, b, __context.aul.user_data);
+}
+
+static void __dispatch_app_start(aul_request_h req)
+{
+ const char *str;
+
+ aul_watch_control_invoke(req->b);
+ __invoke_aul_handler(AUL_START, req->b);
+ str = bundle_get_val(req->b, AUL_K_DATA_CONTROL_TYPE);
+ if (str && !strcmp(str, "CORE")) {
+ if (__context.dcp.callback)
+ __context.dcp.callback(req->b, 0, NULL);
+ }
+}
+
+static void __dispatch_app_resume(aul_request_h req)
+{
+ __invoke_aul_handler(AUL_RESUME, NULL);
+}
+
+static void __dispatch_app_term_by_pid(aul_request_h req)
+{
+ __invoke_aul_handler(AUL_TERMINATE, NULL);
+}
+
+static void __dispatch_app_term_bgapp_by_pid(aul_request_h req)
+{
+ __invoke_aul_handler(AUL_TERMINATE_BGAPP, NULL);
+}
+
+static void __dispatch_app_term_req_by_pid(aul_request_h req)
+{
+ if (__context.subapp.is_subapp) {
+ if (__context.subapp.callback)
+ __context.subapp.callback(__context.subapp.user_data);
+ } else {
+ __invoke_aul_handler(AUL_TERMINATE, NULL);
+ }
+}
+
+static void __dispatch_app_result(aul_request_h req)
+{
+ const char *pid_str;
+ int pid = -1;
+
+ pid_str = bundle_get_val(req->b, AUL_K_CALLEE_PID);
+ if (pid_str)
+ pid = atoi(pid_str);
+
+ app_result(req->cmd, req->b, pid);
+}
+
+static void __dispatch_app_pause_by_pid(aul_request_h req)
+{
+ __invoke_aul_handler(AUL_PAUSE, req->b);
+}
+
+static void __dispatch_app_com_message(aul_request_h req)
+{
+ app_com_recv(req->b);
+}
+
+static void __dispatch_app_wake(aul_request_h req)
+{
+ __invoke_aul_handler(AUL_WAKE, req->b);
+}
+
+static void __dispatch_app_suspend(aul_request_h req)
+{
+ __invoke_aul_handler(AUL_SUSPEND, req->b);
+}
+
+static void __dispatch_widget_get_content(aul_request_h req)
+{
+ const char *widget_id;
+ const char *instance_id;
+ const char *content_info;
+ int fds[2] = { 0, };
+ int r;
+
+ r = aul_sock_recv_reply_sock_fd(req->clifd, &fds, 1);
+ if (r < 0) {
+ _E("Failed to receive fds");
+ return;
+ }
+
+ widget_id = bundle_get_val(req->b, AUL_K_WIDGET_ID);
+ if (!widget_id) {
+ _E("Failed to get widget ID");
+ aul_sock_send_raw_with_fd(fds[0], -EINVAL, 0, 0,
+ AUL_SOCK_NOREPLY);
+ return;
+ }
+
+ instance_id = bundle_get_val(req->b, AUL_K_WIDGET_INSTANCE_ID);
+ if (!instance_id) {
+ _E("Failed to get instance ID");
+ aul_sock_send_raw_with_fd(fds[0], -EINVAL, 0, 0,
+ AUL_SOCK_NOREPLY);
+ return;
+ }
+
+ __invoke_aul_handler(AUL_WIDGET_CONTENT, req->b);
+
+ content_info = bundle_get_val(req->b, AUL_K_WIDGET_CONTENT_INFO);
+ if (content_info) {
+ r = aul_sock_send_raw_with_fd(fds[0], 0,
+ (unsigned char *)content_info,
+ strlen(content_info) + 1, AUL_SOCK_NOREPLY);
+ } else {
+ r = aul_sock_send_raw_with_fd(fds[0], -ENOENT,
+ NULL, 0, AUL_SOCK_NOREPLY);
+ }
+
+ if (r < 0) {
+ _E("Failed to send content info. fd(%d), result(%d)",
+ fds[0], r);
+ }
+}
+
+static void __dispatch_app_update_requested(aul_request_h req)
+{
+ __invoke_aul_handler(AUL_UPDATE_REQUESTED, req->b);
+}
+
+static void __dispatch_app_term_inst(aul_request_h req)
+{
+ __invoke_aul_handler(AUL_TERMINATE_INST, req->b);
+}
+
+static void __dispatch_app_resume_inst(aul_request_h req)
+{
+ __invoke_aul_handler(AUL_RESUME, req->b);
+}
+
+static void __dispatch_app_pause_inst(aul_request_h req)
+{
+ __invoke_aul_handler(AUL_PAUSE, req->b);
+}
+
+static void __dispatch_app_term_bg_inst(aul_request_h req)
+{
+ __invoke_aul_handler(AUL_TERMINATE_BG_INST, req->b);
+}
+
+static void __dispatch_watchdog_enable(aul_request_h req)
+{
+ const char *interval_str;
+ unsigned int interval;
+
+ interval_str = bundle_get_val(req->b, AUL_K_INTERVAL);
+ if (!interval_str) {
+ _E("Invalid request");
+ return;
+ }
+
+ interval = strtoul(interval_str, NULL, 10);
+ aul_watchdog_start(interval);
+}
+
+static void __dispatch_watchdog_disable(aul_request_h req)
+{
+ aul_watchdog_stop();
+}
+
+static void __dispatch_app_connect(aul_request_h req)
+{
+}
+
+static dispatcher __dispatcher[] = {
+ [APP_START] = __dispatch_app_start,
+ [APP_START_RES] = __dispatch_app_start,
+ [APP_START_ASYNC] = __dispatch_app_start,
+ [APP_START_RES_ASYNC] = __dispatch_app_start,
+ [APP_OPEN] = __dispatch_app_resume,
+ [APP_RESUME] = __dispatch_app_resume,
+ [APP_RESUME_BY_PID] = __dispatch_app_resume,
+ [APP_TERM_BY_PID] = __dispatch_app_term_by_pid,
+ [APP_TERM_BY_PID_ASYNC] = __dispatch_app_term_by_pid,
+ [APP_TERM_BY_PID_SYNC] = __dispatch_app_term_by_pid,
+ [APP_TERM_BGAPP_BY_PID] = __dispatch_app_term_bgapp_by_pid,
+ [APP_TERM_REQ_BY_PID] = __dispatch_app_term_req_by_pid,
+ [APP_RESULT] = __dispatch_app_result,
+ [APP_CANCEL] = __dispatch_app_result,
+ [APP_PAUSE_BY_PID] = __dispatch_app_pause_by_pid,
+ [APP_COM_MESSAGE] = __dispatch_app_com_message,
+ [APP_WAKE] = __dispatch_app_wake,
+ [APP_SUSPEND] = __dispatch_app_suspend,
+ [WIDGET_GET_CONTENT] = __dispatch_widget_get_content,
+ [APP_UPDATE_REQUESTED] = __dispatch_app_update_requested,
+ [APP_SEND_LAUNCH_REQUEST] = __dispatch_app_start,
+ [APP_SEND_LAUNCH_REQUEST_SYNC] = __dispatch_app_start,
+ [APP_TERM_INSTANCE_ASYNC] = __dispatch_app_term_inst,
+ [APP_RESUME_INSTANCE] = __dispatch_app_resume_inst,
+ [APP_PAUSE_INSTANCE] = __dispatch_app_pause_inst,
+ [APP_TERM_BG_INSTANCE] = __dispatch_app_term_bg_inst,
+ [WATCHDOG_ENABLE] = __dispatch_watchdog_enable,
+ [WATCHDOG_DISABLE] = __dispatch_watchdog_disable,
+ [APP_CONNECT] = __dispatch_app_connect,
+};
+
+static void __destroy_request(struct aul_request_s *req)
+{
+ if (req->b)
+ bundle_free(req->b);
+ free(req);
+}
+
+static struct aul_request_s *__create_request(int cmd, int clifd, bundle *b)
+{
+ struct aul_request_s *req;
+ const char *val;
+
+ req = malloc(sizeof(struct aul_request_s));
+ if (!req) {
+ _E("Out of memory");
+ return NULL;
+ }
+
+ req->cmd = cmd;
+ req->clifd = clifd;
+ req->b = b;
+ val = bundle_get_val(b, AUL_K_REQUEST_ID);
+ req->req_id = val ? atoi(val) : -1;
+
+ return req;
+}
+
+static int __send_result(struct aul_request_s *req, int res)
+{
+ int ret;
+ int buf[2];
+
+ if (req->cmd != WIDGET_GET_CONTENT && req->clifd >= 0) {
+ g_rec_mutex_lock(&__context.mutex);
+ if (__find_client_channel(req->clifd) == NULL) {
+ _E("Failed to find client channel. fd(%d), cmd(%s:%d)",
+ req->clifd,
+ aul_cmd_convert_to_string(req->cmd),
+ req->cmd);
+ g_rec_mutex_unlock(&__context.mutex);
+ return -1;
+ }
+
+ buf[0] = req->req_id;
+ buf[1] = res;
+ ret = aul_sock_send_raw_data(req->clifd, (unsigned char *)&buf,
+ sizeof(int) + sizeof(int), false);
+ g_rec_mutex_unlock(&__context.mutex);
+ if (ret < 0) {
+ _E("Failed to send result. cmd(%s:%d), seq(%d)",
+ aul_cmd_convert_to_string(req->cmd),
+ req->cmd, req->req_id);
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
+static gboolean __dispatch_request(gpointer data)
+{
+ struct aul_request_s *req = (struct aul_request_s *)data;
+ int ret;
+
+ if (!__context.initialized) {
+ _W("Ignore request(%d)", req->cmd);
+ __destroy_request(req);
+ return G_SOURCE_REMOVE;
+ }
+
+ aul_worker_remove_anr_timer(__context.worker);
+
+ ret = __send_result(req, 0);
+ if (ret < 0) {
+ __destroy_request(req);
+ return G_SOURCE_REMOVE;
+ }
+
+ if (req->cmd >= APP_START && req->cmd < ARRAY_SIZE(__dispatcher) &&
+ __dispatcher[req->cmd]) {
+ _W("[%d] Command(%s:%d)",
+ req->req_id,
+ aul_cmd_convert_to_string(req->cmd), req->cmd);
+ __dispatcher[req->cmd](req);
+ } else {
+ _E("[%d] Command(%s:%d) is not available",
+ req->req_id,
+ aul_cmd_convert_to_string(req->cmd), req->cmd);
+ }
+
+ __destroy_request(req);
+
+ return G_SOURCE_REMOVE;
+}
+
+static guint __g_idle_add_full(GMainContext *context, gint priority,
+ GSourceFunc func, gpointer data)
+{
+ GSource *source;
+ guint tag;
+
+ source = g_idle_source_new();
+ if (!source)
+ return 0;
+
+ g_source_set_callback(source, (GSourceFunc)func, data, NULL);
+ g_source_set_priority(source, priority);
+ tag = g_source_attach(source, context);
+ g_source_unref(source);
+
+ return tag;
+}
+
+static GMainContext *__get_glib_context(int cmd, bundle *b)
+{
+ GMainContext *context;
+
+ if (b && bundle_get_type(b, K_SERVICE_THREAD) != BUNDLE_TYPE_NONE)
+ return NULL;
+
+ switch (cmd) {
+ case APP_START:
+ case APP_START_RES:
+ case APP_START_ASYNC:
+ case APP_START_RES_ASYNC:
+ case APP_OPEN:
+ case APP_RESUME:
+ case APP_RESUME_BY_PID:
+ case APP_PAUSE_BY_PID:
+ case APP_SEND_LAUNCH_REQUEST:
+ case APP_SEND_LAUNCH_REQUEST_SYNC:
+ case APP_RESUME_INSTANCE:
+ case APP_PAUSE_INSTANCE:
+ context = __context.tizen_context;
+ break;
+ default:
+ context = NULL;
+ break;
+ }
+
+ return context;
+}
+
+static void __process_app_pkt(app_pkt_t *pkt, int clifd, aul_worker_h worker)
+{
+ struct aul_request_s *req;
+ bundle *b = NULL;
+ char *timeout_str;
+ unsigned int timeout = 5000;
+ int ret;
+
+ if (pkt->opt & AUL_SOCK_BUNDLE) {
+ b = bundle_decode(pkt->data, pkt->len);
+ if (!b) {
+ _E("Failed to decode the packet");
+ return;
+ }
+
+ ret = bundle_get_str(b, AUL_K_SOCKET_TIMEOUT, &timeout_str);
+ if (ret == BUNDLE_ERROR_NONE && isdigit(timeout_str[0])) {
+ timeout = atoi(timeout_str);
+ _I("timeout: %ums", timeout);
+ }
+ }
+
+ req = __create_request(pkt->cmd, clifd, b);
+ if (!req) {
+ bundle_free(b);
+ return;
+ }
+
+ aul_worker_add_anr_timer(worker, pkt->cmd, timeout);
+ __g_idle_add_full(__get_glib_context(pkt->cmd, b), G_PRIORITY_DEFAULT,
+ __dispatch_request, req);
+}
+
+static bool __received_event_cb(int fd, int condition, void *user_data)
+{
+ aul_worker_h worker = user_data;
+ client_channel_t *channel;
+ app_pkt_t *pkt;
+ int ret;
+
+ g_rec_mutex_lock(&__context.mutex);
+ channel = __find_client_channel(fd);
+ if (!channel) {
+ _E("Failed to find client channel. fd(%d)", fd);
+ g_rec_mutex_unlock(&__context.mutex);
+ return false;
+ }
+
+ if (condition & (AUL_IO_HUP | AUL_IO_ERR | AUL_IO_NVAL)) {
+ _E("IO error occurred. condition(%d), fd(%d)", condition, fd);
+ aul_worker_remove_io_job(worker, fd);
+ __remove_client_channel(channel);
+ __destroy_client_channel(channel);
+ g_rec_mutex_unlock(&__context.mutex);
+ return true;
+ }
+
+ ret = aul_sock_recv_reply_pkt_v2(fd, &pkt, false);
+ g_rec_mutex_unlock(&__context.mutex);
+ if (ret != 0) {
+ _E("Failed to receive the packet. error(%d)", ret);
+ return true;
+ }
+
+ __process_app_pkt(pkt, fd, worker);
+ free(pkt);
+
+ return true;
+}
+
+static bool __connected_event_cb(int fd, int condition, void *user_data)
+{
+ int cond = AUL_IO_IN | AUL_IO_HUP | AUL_IO_ERR | AUL_IO_NVAL;
+ aul_worker_h worker = user_data;
+ client_channel_t *channel = NULL;
+ struct ucred cr;
+ int clifd;
+ app_pkt_t *pkt;
+ int ret;
+
+ pkt = aul_sock_recv_pkt(fd, &clifd, &cr);
+ if (!pkt) {
+ _E("Failed to receive the packet");
+ return true;
+ }
+
+ _W("pid(%d), clifd(%d), cmd(%d)", cr.pid, clifd, pkt->cmd);
+ if (pkt->cmd != WIDGET_GET_CONTENT) {
+ if (pkt->opt & AUL_SOCK_NOREPLY) {
+ close(clifd);
+ clifd = -1;
+ } else {
+ channel = __create_client_channel(clifd,
+ cr.pid, cr.uid);
+ if (!channel) {
+ free(pkt);
+ close(clifd);
+ return true;
+ }
+
+ __add_client_channel(channel);
+ }
+ }
+
+ __process_app_pkt(pkt, clifd, worker);
+
+ if (pkt->cmd == WIDGET_GET_CONTENT)
+ clifd = -1;
+
+ free(pkt);
+
+ if (clifd < 0)
+ return true;
+
+ ret = aul_worker_add_io_job(worker, "client", clifd, cond, true,
+ __received_event_cb, worker);
+ if (ret < 0) {
+ _E("Failed to add io job. error(%d)", ret);
+ __remove_client_channel(channel);
+ __destroy_client_channel(channel);
+ return true;
+ }
+
+ return true;
+}
+
+static void __finalize_context(void)
+{
+ g_rec_mutex_lock(&__context.init_mutex);
+ if (!__context.initialized) {
+ g_rec_mutex_unlock(&__context.init_mutex);
+ return;
+ }
+
+ __context.touch_argv_handler = false;
+
+ aul_launch_worker_fini();
+
+ if (__context.tizen_context) {
+ g_main_context_unref(__context.tizen_context);
+ __context.tizen_context = NULL;
+ }
+
+ if (__context.clients) {
+ g_list_free_full(__context.clients, __destroy_client_channel);
+ __context.clients = NULL;
+ }
+
+ if (g_rec_mutex_trylock(&__context.mutex))
+ g_rec_mutex_unlock(&__context.mutex);
+
+ g_rec_mutex_clear(&__context.mutex);
+
+ __context.initialized = false;
+ g_rec_mutex_unlock(&__context.init_mutex);
+}
+
+static GMainContext *__get_tizen_glib_context(void)
+{
+ GMainContext *context;
+ const char *env;
+
+ env = getenv("TIZEN_GLIB_CONTEXT");
+ if (env)
+ context = (GMainContext *)strtoul(env, NULL, 10);
+ else
+ context = NULL;
+
+ return context;
+}
+
+static int __initialize_context(void)
+{
+ GMainContext *context;
+ int ret;
+ int fd;
+
+ if (__context.initialized) {
+ _E("Already initialized");
+ context = __get_tizen_glib_context();
+ if (context)
+ __context.tizen_context = g_main_context_ref(context);
+
+ return AUL_R_OK;
+ }
+
+ fd = aul_initialize();
+ if (fd < 0) {
+ _E("Failed to initialize aul");
+ return fd;
+ }
+
+ g_rec_mutex_init(&__context.mutex);
+
+ context = __get_tizen_glib_context();
+ if (context)
+ __context.tizen_context = g_main_context_ref(context);
+ else
+ __context.tizen_context = NULL;
+
+ if (aul_launch_worker_init() != AUL_R_OK) {
+ __finalize_context();
+ return AUL_R_ERROR;
+ }
+
+ ret = aul_worker_add_io_job(__context.worker, "server", fd, AUL_IO_IN,
+ false, __connected_event_cb, __context.worker);
+ if (ret < 0) {
+ __finalize_context();
+ return ret;
+ }
+
+ __context.initialized = true;
+
+ return AUL_R_OK;
+}
+
+API int aul_launch_worker_init(void)
+{
+ if (__context.worker != NULL)
+ return AUL_R_OK;
+
+ __context.worker = aul_worker_create("aul+");
+ if (__context.worker == NULL)
+ return AUL_R_ERROR;
+
+ return AUL_R_OK;
+}
+
+API void aul_launch_worker_fini(void)
+{
+ if (__context.worker == NULL)
+ return;
+
+ aul_worker_destroy(__context.worker);
+ __context.worker = NULL;
+}
+
+API int aul_launch_init(aul_handler_fn callback, void *user_data)
+{
+ int ret;
+
+ g_rec_mutex_lock(&__context.init_mutex);
+ if (callback) {
+ __context.aul.callback = callback;
+ __context.aul.user_data = user_data;
+ }
+
+ ret = __initialize_context();
+ g_rec_mutex_unlock(&__context.init_mutex);
+
+ return ret;
+}
+
+API int aul_launch_fini(void)
+{
+ __finalize_context();
+ return AUL_R_OK;
+}
+
+static gboolean __app_start_cb(gpointer data)
+{
+ bundle *b = (bundle *)data;
+ struct aul_request_s req = {
+ .cmd = APP_START,
+ .clifd = 0,
+ .b = b
+ };
+
+ __dispatch_app_start(&req);
+
+ if (req.b)
+ bundle_free(req.b);
+
+ return G_SOURCE_REMOVE;
+}
+
+API int aul_launch_argv_handler(int argc, char **argv)
+{
+ bundle *b;
+
+ if (!aul_is_initialized()) {
+ _E("AUL is not initialized");
+ return AUL_R_ENOINIT;
+ }
+
+ if (__context.touch_argv_handler) {
+ _E("Already registered");
+ return AUL_R_OK;
+ }
+
+ b = bundle_import_from_argv(argc, argv);
+ if (!b)
+ _E("Bundle is nullptr");
+
+ if (!__g_idle_add_full(__get_glib_context(APP_START, b),
+ G_PRIORITY_HIGH, __app_start_cb, b)) {
+ _E("Failed to add idler");
+ return AUL_R_ERROR;
+ }
+
+ __context.touch_argv_handler = true;
+ return AUL_R_OK;
+}
+
+API int aul_launch_local(bundle *b)
+{
+ if (!aul_is_initialized()) {
+ _E("AUL is not initialized");
+ return AUL_R_ENOINIT;
+ }
+
+ if (!b)
+ _E("Bundle is nullptr");
+
+ if (!__g_idle_add_full(__get_glib_context(APP_START, b),
+ G_PRIORITY_DEFAULT, __app_start_cb, b)) {
+ _E("Failed to add idler");
+ return AUL_R_ERROR;
+ }
+
+ return AUL_R_OK;
+}
+
+int aul_resume_local(void)
+{
+ if (!aul_is_initialized()) {
+ _E("AUL is not initialized");
+ return AUL_R_ENOINIT;
+ }
+
+ __dispatch_app_resume(NULL);
+
+ return AUL_R_OK;
+}
+
+API int aul_set_subapp(subapp_fn callback, void *user_data)
+{
+ __context.subapp.is_subapp = true;
+ __context.subapp.callback = callback;
+ __context.subapp.user_data = user_data;
+
+ return AUL_R_OK;
+}
+
+API int aul_is_subapp(void)
+{
+ return (int)__context.subapp.is_subapp;
+}
+
+API int aul_set_data_control_provider_cb(data_control_provider_handler_fn cb)
+{
+ __context.dcp.callback = cb;
+
+ return AUL_R_OK;
+}
+
+API int aul_unset_data_control_provider_cb(void)
+{
+ __context.dcp.callback = NULL;
+
+ return AUL_R_OK;
+}
--- /dev/null
+/*
+ * Copyright (c) 2019 - 2022 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 "aul/include/aul_launcher_service.h"
+
+#include <bundle_internal.h>
+#include <glib.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "aul/app_request.h"
+#include "aul/aul_api.h"
+#include "aul/aul_util.h"
+#include "aul/include/aul_app_com.h"
+#include "aul/include/aul_error.h"
+#include "aul/include/aul_sock.h"
+
+struct aul_launcher_serivce_s {
+ void* dummy;
+};
+
+using namespace aul::internal;
+namespace {
+
+class LauncherService {
+ public:
+ LauncherService(std::string name, aul_launcher_service_cb cb,
+ void* user_data)
+ : name_(std::move(name)), cb_(cb), user_data_(user_data) {
+ }
+
+ ~LauncherService() {
+ if (conn_ != nullptr)
+ aul_app_com_leave(conn_);
+ }
+
+ int Listen() {
+ if (conn_ != nullptr)
+ return AUL_R_OK;
+
+ std::string endpoint = "launcher_service:" + name_ + ":" +
+ std::to_string(getpid());
+ int ret = aul_app_com_create(endpoint.c_str(), nullptr, AppComCb,
+ this, &conn_);
+ if (ret < 0) {
+ _E("Failed to create app com. error(%d)", ret);
+ return AUL_R_ERROR;
+ }
+
+ return AUL_R_OK;
+ }
+
+ private:
+ static int AppComCb(const char* endpoint, aul_app_com_result_e result,
+ bundle* envelope, void* user_data) {
+ const char* appid = bundle_get_val(envelope, AUL_K_APPID);
+ if (appid == nullptr) {
+ _E("Failed to get application ID");
+ return -1;
+ }
+
+ const char* instance_id = bundle_get_val(envelope, AUL_K_INSTANCE_ID);
+ if (instance_id == nullptr) {
+ _E("Failed to get instance ID");
+ return -1;
+ }
+
+ const char* pid_str = bundle_get_val(envelope, AUL_K_PID);
+ if (pid_str == nullptr) {
+ _E("Failed to get process ID");
+ return -1;
+ }
+ int pid = atoi(pid_str);
+
+ const char* serial_str = bundle_get_val(envelope,
+ AUL_K_LAUNCHER_SERVICE_SERIAL);
+ if (serial_str == nullptr) {
+ _E("Failed to get serial");
+ return -1;
+ }
+ uint32_t serial = strtoul(serial_str, NULL, 10);
+
+ auto* launcher_service = static_cast<LauncherService*>(user_data);
+ launcher_service->cb_(appid, instance_id, pid, serial,
+ launcher_service->user_data_);
+ return 0;
+ }
+
+ private:
+ std::string name_;
+ aul_launcher_service_cb cb_;
+ void* user_data_;
+ aul_app_com_connection_h conn_ = nullptr;
+};
+
+} // namespace
+
+extern "C" API int aul_launcher_service_create(const char* name,
+ aul_launcher_service_cb callback, void* user_data,
+ aul_launcher_service_h* handle) {
+ if (callback == nullptr || name == nullptr || handle == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* service = new (std::nothrow) LauncherService(name, callback, user_data);
+ if (service == nullptr) {
+ _E("Out of memory");
+ return AUL_R_ENOMEM;
+ }
+
+ *handle = reinterpret_cast<aul_launcher_service_h>(service);
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_launcher_service_listen(aul_launcher_service_h handle) {
+ if (handle == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* service = reinterpret_cast<LauncherService*>(handle);
+ return service->Listen();
+}
+
+extern "C" API int aul_launcher_service_destroy(aul_launcher_service_h handle) {
+ if (handle == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* service = reinterpret_cast<LauncherService*>(handle);
+ delete service;
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_launcher_service_notify_animation_started(void) {
+ return AppRequest(LAUNCHER_SERVICE_NOTIFY_ANIMATION_STARTED, getuid())
+ .SendCmdOnly(AUL_SOCK_NOREPLY);
+}
+
+extern "C" API int aul_launcher_service_notify_animation_finished(void) {
+ return AppRequest(LAUNCHER_SERVICE_NOTIFY_ANIMATION_FINISHED, getuid())
+ .SendCmdOnly(AUL_SOCK_NOREPLY);
+}
--- /dev/null
+/*
+ * Copyright (c) 2021 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 <memory>
+#include <mutex>
+#include <string>
+
+#include "aul/app_info/directory_info.hh"
+#include "aul/app_info/external_directory_info.hh"
+#include "aul/aul_api.h"
+#include "aul/aul_util.h"
+#include "aul/include/aul.h"
+
+#undef AUL_API
+#define AUL_API extern "C" API
+
+namespace {
+std::unique_ptr<aul::DirectoryInfo> context(nullptr);
+std::unique_ptr<aul::ExternalDirectoryInfo> ext_context(nullptr);
+std::mutex mutex;
+std::mutex ext_mutex;
+
+const aul::DirectoryInfo* GetCurrentContext() {
+ std::unique_lock<std::mutex> lock(mutex);
+ if (context.get() == nullptr)
+ context.reset(aul::DirectoryInfo::Get());
+
+ return context.get();
+}
+
+const aul::ExternalDirectoryInfo* GetCurrentExtContext() {
+ std::unique_lock<std::mutex> lock(ext_mutex);
+ if (ext_context.get() == nullptr)
+ ext_context.reset(aul::ExternalDirectoryInfo::Get());
+
+ return ext_context.get();
+}
+
+} // namespace
+
+AUL_API const char* aul_get_app_external_root_path(void) {
+ auto* context = GetCurrentExtContext();
+ if (context == nullptr)
+ return nullptr;
+
+ return context->GetRootPath().c_str();
+}
+
+AUL_API const char* aul_get_app_root_path(void) {
+ auto* context = GetCurrentContext();
+ if (context == nullptr)
+ return nullptr;
+
+ return context->GetRootPath().c_str();
+}
+
+AUL_API const char* aul_get_app_data_path(void) {
+ auto* context = GetCurrentContext();
+ if (context == nullptr)
+ return nullptr;
+
+ return context->GetDataPath().c_str();
+}
+
+AUL_API const char* aul_get_app_cache_path(void) {
+ auto* context = GetCurrentContext();
+ if (context == nullptr)
+ return nullptr;
+
+ return context->GetCachePath().c_str();
+}
+
+AUL_API const char* aul_get_app_resource_path(void) {
+ auto* context = GetCurrentContext();
+ if (context == nullptr)
+ return nullptr;
+
+ return context->GetResourcePath().c_str();
+}
+
+AUL_API const char* aul_get_app_tep_resource_path(void) {
+ auto* context = GetCurrentContext();
+ if (context == nullptr)
+ return nullptr;
+
+ return context->GetTepResourcePath().c_str();
+}
+
+AUL_API int aul_get_app_shared_data_path(char** path) {
+ auto* context = GetCurrentContext();
+ if (context == nullptr)
+ return AUL_R_ERROR;
+
+ if (access(context->GetSharedDataPath().c_str(), F_OK) != 0)
+ return AUL_R_EREJECTED;
+
+ *path = strdup(context->GetSharedDataPath().c_str());
+ return AUL_R_OK;
+}
+
+AUL_API const char* aul_get_app_shared_resource_path(void) {
+ auto* context = GetCurrentContext();
+ if (context == nullptr)
+ return nullptr;
+
+ return context->GetSharedResourcePath().c_str();
+}
+
+AUL_API const char* aul_get_app_shared_trusted_path(void) {
+ auto* context = GetCurrentContext();
+ if (context == nullptr)
+ return nullptr;
+
+ return context->GetSharedTrustedPath().c_str();
+}
+
+AUL_API const char* aul_get_app_external_data_path(void) {
+ auto* context = GetCurrentExtContext();
+ if (context == nullptr)
+ return nullptr;
+
+ return context->GetDataPath().c_str();
+}
+
+AUL_API const char* aul_get_app_external_cache_path(void) {
+ auto* context = GetCurrentExtContext();
+ if (context == nullptr)
+ return nullptr;
+
+ return context->GetCachePath().c_str();
+}
+
+AUL_API const char* aul_get_app_external_shared_data_path(void) {
+ auto* context = GetCurrentExtContext();
+ if (context == nullptr)
+ return nullptr;
+
+ return context->GetSharedDataPath().c_str();
+}
+
+AUL_API const char* aul_get_app_specific_path(void) {
+ if (GetCurrentContext() == nullptr)
+ return nullptr;
+
+ return tzplatform_getenv(TZ_USER_APP);
+}
+
+AUL_API int aul_get_app_res_control_allowed_resource_path(const char* res_type,
+ char** path) {
+ if (res_type == nullptr || path == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* context = GetCurrentContext();
+ if (context == nullptr)
+ return AUL_R_ERROR;
+
+ std::string result = context->GetResControlAllowedResPath() + res_type + "/";
+
+ if (access(result.c_str(), F_OK) != 0)
+ return AUL_R_EREJECTED;
+
+ *path = strdup(result.c_str());
+ if (*path == nullptr) {
+ LOGE("Out of memory");
+ return AUL_R_ENOMEM;
+ }
+
+ return AUL_R_OK;
+}
+
+AUL_API int aul_get_app_res_control_global_resource_path(const char* res_type,
+ char** path) {
+ if (res_type == nullptr || path == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* context = GetCurrentContext();
+ if (context == nullptr)
+ return AUL_R_ERROR;
+
+ std::string result = context->GetResControlGlobalResPath() + res_type + "/";
+
+ if (access(result.c_str(), F_OK) != 0)
+ return AUL_R_EREJECTED;
+
+ *path = strdup(result.c_str());
+ if (*path == nullptr) {
+ LOGE("Out of memory");
+ return AUL_R_ENOMEM;
+ }
+
+ return AUL_R_OK;
+}
+
+AUL_API int aul_get_app_shared_data_path_by_appid(const char* appid,
+ char** path) {
+ if (path == nullptr)
+ return AUL_R_EINVAL;
+
+ if (appid == nullptr)
+ return aul_get_app_shared_data_path(path);
+
+ std::unique_ptr<aul::DirectoryInfo> info(
+ aul::DirectoryInfo::Get(appid, getuid()));
+ if (info.get() == nullptr)
+ return AUL_R_ENOAPP;
+
+ if (access(info->GetSharedDataPath().c_str(), F_OK) != 0)
+ return AUL_R_EREJECTED;
+
+ *path = strdup(info->GetSharedDataPath().c_str());
+ return AUL_R_OK;
+}
+
+AUL_API int aul_get_app_shared_resource_path_by_appid(const char* appid,
+ char** path) {
+ if (appid == nullptr || path == nullptr)
+ return AUL_R_EINVAL;
+
+ std::unique_ptr<aul::DirectoryInfo> info(
+ aul::DirectoryInfo::Get(appid, getuid()));
+ if (info.get() == nullptr)
+ return AUL_R_ENOAPP;
+
+ *path = strdup(info->GetSharedResourcePath().c_str());
+ return AUL_R_OK;
+}
+
+AUL_API int aul_get_app_shared_trusted_path_by_appid(const char* appid,
+ char** path) {
+ if (appid == nullptr || path == nullptr)
+ return AUL_R_EINVAL;
+
+ std::unique_ptr<aul::DirectoryInfo> info(
+ aul::DirectoryInfo::Get(appid, getuid()));
+ if (info.get() == nullptr)
+ return AUL_R_ENOAPP;
+
+ *path = strdup(info->GetSharedTrustedPath().c_str());
+ return AUL_R_OK;
+}
+
+AUL_API int aul_get_app_external_shared_data_path_by_appid(const char* appid,
+ char** path) {
+ if (appid == nullptr || path == nullptr)
+ return AUL_R_EINVAL;
+
+ std::unique_ptr<aul::ExternalDirectoryInfo> info(
+ aul::ExternalDirectoryInfo::Get(appid, getuid()));
+ if (info.get() == nullptr)
+ return AUL_R_ENOAPP;
+
+ *path = strdup(info->GetSharedDataPath().c_str());
+ return AUL_R_OK;
+}
+
+AUL_API int aul_get_usr_app_shared_data_path_by_appid(const char* appid,
+ char** path, uid_t uid) {
+ if (appid == nullptr || path == nullptr)
+ return AUL_R_EINVAL;
+
+ std::unique_ptr<aul::DirectoryInfo> info(
+ aul::DirectoryInfo::Get(appid, uid));
+ if (info.get() == nullptr)
+ return AUL_R_ENOAPP;
+
+ if (access(info->GetSharedDataPath().c_str(), F_OK) != 0)
+ return AUL_R_EREJECTED;
+
+ *path = strdup(info->GetSharedDataPath().c_str());
+ return AUL_R_OK;
+}
+
+AUL_API int aul_get_usr_app_shared_resource_path_by_appid(const char* appid,
+ char** path, uid_t uid) {
+ if (appid == nullptr || path == nullptr)
+ return AUL_R_EINVAL;
+
+ std::unique_ptr<aul::DirectoryInfo> info(
+ aul::DirectoryInfo::Get(appid, uid));
+ if (info.get() == nullptr)
+ return AUL_R_ENOAPP;
+
+ *path = strdup(info->GetSharedResourcePath().c_str());
+ return AUL_R_OK;
+}
+
+AUL_API int aul_get_usr_app_shared_trusted_path_by_appid(const char* appid,
+ char** path, uid_t uid) {
+ if (appid == nullptr || path == nullptr)
+ return AUL_R_EINVAL;
+
+ std::unique_ptr<aul::DirectoryInfo> info(
+ aul::DirectoryInfo::Get(appid, uid));
+ if (info.get() == nullptr)
+ return AUL_R_ENOAPP;
+
+ *path = strdup(info->GetSharedTrustedPath().c_str());
+ return AUL_R_OK;
+}
+
+AUL_API int aul_get_usr_app_external_shared_data_path_by_appid(
+ const char* appid, char** path, uid_t uid) {
+ if (appid == nullptr || path == nullptr)
+ return AUL_R_EINVAL;
+
+ std::unique_ptr<aul::ExternalDirectoryInfo> info(
+ aul::ExternalDirectoryInfo::Get(appid, uid));
+ if (info.get() == nullptr)
+ return AUL_R_ENOAPP;
+
+ *path = strdup(info->GetSharedDataPath().c_str());
+ return AUL_R_OK;
+}
--- /dev/null
+/*
+ * Copyright (c) 2000 - 2021 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 "aul/include/aul_proc.h"
+
+#include <bundle_cpp.h>
+#include <bundle_internal.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <memory>
+#include <mutex>
+#include <string>
+
+#include "aul/app_request.h"
+#include "aul/aul_api.h"
+#include "aul/aul_util.h"
+#include "aul/common/file_descriptor.hh"
+#include "aul/include/aul_sock.h"
+
+using namespace aul;
+using namespace aul::internal;
+
+namespace {
+
+class ProcContext {
+ public:
+ ProcContext() {}
+ ~ProcContext() {}
+
+ void SetName(std::string name) {
+ std::lock_guard<std::mutex> lock(mutex_);
+ name_ = std::move(name);
+ }
+
+ const std::string& GetName() {
+ std::lock_guard<std::mutex> lock(mutex_);
+ return name_;
+ }
+
+ void SetExtra(tizen_base::Bundle extra) {
+ std::lock_guard<std::mutex> lock(mutex_);
+ extra_ = std::move(extra);
+ }
+
+ tizen_base::Bundle& GetExtra() {
+ std::lock_guard<std::mutex> lock(mutex_);
+ return extra_;
+ }
+
+ void SetFd(int fd) {
+ std::lock_guard<std::mutex> lock(mutex_);
+ fd_.Set(fd);
+ }
+
+ void Close() {
+ std::lock_guard<std::mutex> lock(mutex_);
+ fd_.Close();
+ }
+
+ bool IsClosed() {
+ std::lock_guard<std::mutex> lock(mutex_);
+ return fd_.IsClosed();
+ }
+
+ private:
+ FileDescriptor fd_;
+ std::string name_;
+ tizen_base::Bundle extra_;
+ mutable std::mutex mutex_;
+};
+
+int ReadFromPath(const std::string& path, char* buf, size_t buf_size) {
+ int fd = open(path.c_str(), O_RDONLY);
+ if (fd < 0) {
+ _E("open() is failed. path(%s), errno(%d)", path.c_str(), errno);
+ return AUL_R_ERROR;
+ }
+
+ FileDescriptor fd_closer(fd);
+ ssize_t bytes = read(fd, buf, buf_size - 1);
+ if (bytes <= 0) {
+ _E("read() is failed. errno(%d)", errno);
+ return AUL_R_ERROR;
+ }
+
+ buf[bytes] = '\0';
+ return AUL_R_OK;
+}
+
+int SendAndReceive(int cmd, pid_t pid, uid_t uid, bundle** response) {
+ int fd = AppRequest(cmd, uid)
+ .SetPid(pid)
+ .SendSimply(AUL_SOCK_ASYNC);
+ if (fd < 0 || fd >= sysconf(_SC_OPEN_MAX)) {
+ _E("Failed to send request. error(%d)", fd);
+ return fd;
+ }
+
+ FileDescriptor fd_closer(fd);
+ app_pkt_t* pkt = nullptr;
+ int ret = aul_sock_recv_reply_pkt(fd, &pkt);
+ if (ret < 0) {
+ _E("Failed to receive reply packet. error(%d)", ret);
+ return AUL_R_ECOMM;
+ }
+
+ std::unique_ptr<app_pkt_t, decltype(std::free)*> pkt_auto(pkt, std::free);
+ if (!(pkt->opt & AUL_SOCK_BUNDLE)) {
+ _E("Invalid protocol");
+ return AUL_R_ECOMM;
+ }
+
+ if (pkt->cmd != APP_GET_INFO_OK) {
+ _E("Failed to get name by pid(%d)", pid);
+ return AUL_R_ERROR;
+ }
+
+ *response = bundle_decode(pkt->data, pkt->len);
+ if (*response == nullptr) {
+ _E("bundle_decode() is failed");
+ return AUL_R_ERROR;
+ }
+
+ return AUL_R_OK;
+}
+
+ProcContext context;
+
+} // namespace
+
+extern "C" API int aul_proc_get_uid(pid_t pid, uid_t* uid) {
+ if (pid < 1 || uid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ std::string path = "/proc/" + std::to_string(pid);
+ struct stat stat_buf;
+ int ret = stat(path.c_str(), &stat_buf);
+ if (ret < 0) {
+ _E("stat() is failed. path(%s), errno(%d)", path.c_str(), errno);
+ return AUL_R_ERROR;
+ }
+
+ *uid = stat_buf.st_uid;
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_proc_get_attr(pid_t pid, char* buf, size_t buf_size) {
+ if (pid < 1 || buf == nullptr || buf_size <= 0) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ std::string path = "/proc/" + std::to_string(pid) + "/attr/current";
+ return ReadFromPath(path, buf, buf_size);
+}
+
+extern "C" API int aul_proc_get_cmdline(pid_t pid, char* buf, size_t buf_size) {
+ if (pid < 1 || buf == nullptr || buf_size <= 0) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ std::string path = "/proc/" + std::to_string(pid) + "/cmdline";
+ return ReadFromPath(path, buf, buf_size);
+}
+
+extern "C" API int aul_proc_register(const char* name, bundle* extra) {
+ if (name == nullptr || name[0] == '\0') {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ if (!context.IsClosed()) {
+ _E("Already registered. Please call aul_proc_deregister() first");
+ return AUL_R_ERROR;
+ }
+
+ tizen_base::Bundle b {{AUL_K_PROC_NAME, name}};
+ if (extra) {
+ tizen_base::Bundle extra_data(extra, false, false);
+ auto raw = extra_data.ToRaw();
+ b.Add(AUL_K_PROC_EXTRA, reinterpret_cast<const char*>(raw.first.get()));
+ }
+
+ int ret = AppRequest(PROC_REGISTER, getuid())
+ .With(b)
+ .SendSimply(AUL_SOCK_ASYNC);
+ if (ret < 0) {
+ _E("Failed to send request. name(%s), error(%d)", name, ret);
+ return ret;
+ }
+
+ int res = aul_sock_recv_result_with_fd(ret);
+ if (res != 0) {
+ _E("Failed to receive the result. fd(%d)", res);
+ close(ret);
+ return AUL_R_ERROR;
+ }
+
+ context.SetFd(ret);
+ context.SetName(name);
+ if (extra)
+ context.SetExtra(tizen_base::Bundle(extra, true, true));
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_proc_deregister(void) {
+ if (context.IsClosed()) {
+ _E("Invalid context");
+ return AUL_R_ERROR;
+ }
+
+ int ret = AppRequest(PROC_DEREGISTER, getuid())
+ .SendSimply(AUL_SOCK_NOREPLY);
+ if (ret < 0) {
+ _E("Failed to send request. error(%d)", ret);
+ return ret;
+ }
+
+ context.Close();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_proc_get_name(pid_t pid, char** name) {
+ if (pid < 1 || name == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ if (pid == getpid() && !context.IsClosed() && !context.GetName().empty()) {
+ *name = strdup(context.GetName().c_str());
+ if (*name == nullptr) {
+ _E("strdup() is failed");
+ return AUL_R_ENOMEM;
+ }
+
+ return AUL_R_OK;
+ }
+
+ bundle* response;
+ int ret = SendAndReceive(PROC_GET_NAME, pid, getuid(), &response);
+ if (ret != AUL_R_OK)
+ return ret;
+
+ tizen_base::Bundle b(response, false, true);
+ std::string val = b.GetString(AUL_K_PROC_NAME);
+ if (val.empty()) {
+ _E("Failed to get name");
+ return AUL_R_ERROR;
+ }
+
+ *name = strdup(val.c_str());
+ if (*name == nullptr) {
+ _E("strdup() is failed");
+ return AUL_R_ENOMEM;
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_proc_get_extra(pid_t pid, bundle** extra) {
+ if (pid < 1 || extra == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ if (pid == getpid() && !context.IsClosed()) {
+ auto& extra_data = context.GetExtra();
+ *extra = bundle_dup(extra_data.GetHandle());
+ if (*extra == nullptr) {
+ _E("bundle_dup() is failed");
+ return AUL_R_ENOMEM;
+ }
+
+ return AUL_R_OK;
+ }
+
+ bundle* response;
+ int ret = SendAndReceive(PROC_GET_EXTRA, pid, getuid(), &response);
+ if (ret != AUL_R_OK)
+ return ret;
+
+ tizen_base::Bundle b(response, false, true);
+ std::string raw = b.GetString(AUL_K_PROC_EXTRA);
+ if (raw.empty()) {
+ _E("Failed to get extra");
+ return AUL_R_ERROR;
+ }
+
+ tizen_base::Bundle extra_data(raw);
+ *extra = extra_data.Detach();
+ return AUL_R_OK;
+}
--- /dev/null
+/*
+ * Copyright (c) 2021 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 "aul/include/aul_proc_group.h"
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include "aul/app_request.h"
+#include "aul/aul_api.h"
+#include "aul/aul_util.h"
+#include "aul/common/file_descriptor.hh"
+#include "aul/include/aul_error.h"
+#include "aul/include/aul_sock.h"
+
+using namespace aul;
+using namespace aul::internal;
+
+namespace {
+
+class ProcGroupInfo {
+ public:
+ ProcGroupInfo(pid_t leader_pid, std::vector<pid_t> sub_pids)
+ : leader_pid_(leader_pid), sub_pids_(std::move(sub_pids)) {}
+
+ pid_t GetLeaderPid() const {
+ return leader_pid_;
+ }
+
+ const std::vector<pid_t>& GetSubPids() const {
+ return sub_pids_;
+ }
+
+ private:
+ pid_t leader_pid_;
+ std::vector<pid_t> sub_pids_;
+};
+
+int SendAndReceive(int cmd, pid_t pid, bundle** response) {
+ int fd = AppRequest(cmd, getuid())
+ .SetPid(pid)
+ .SendSimply(AUL_SOCK_ASYNC);
+ if (fd < 0 || fd >= sysconf(_SC_OPEN_MAX)) {
+ _E("Failed to send request. error(%d)", fd);
+ return fd;
+ }
+
+ FileDescriptor fd_closer(fd);
+ app_pkt_t* pkt = nullptr;
+ int ret = aul_sock_recv_reply_pkt(fd, &pkt);
+ if (ret < 0) {
+ _E("Failed to receive reply packet. error(%d)", ret);
+ return AUL_R_ECOMM;
+ }
+
+ std::unique_ptr<app_pkt_t, decltype(std::free)*> pkt_auto(pkt, std::free);
+ if (!(pkt->opt & AUL_SOCK_BUNDLE)) {
+ _E("Invalid protocol");
+ return AUL_R_ECOMM;
+ }
+
+ if (pkt->cmd != APP_GET_INFO_OK) {
+ _E("Failed to get result");
+ return AUL_R_ERROR;
+ }
+
+ *response = bundle_decode(pkt->data, pkt->len);
+ if (*response == nullptr) {
+ _E("bundle_decode() is failed");
+ return AUL_R_ERROR;
+ }
+
+ return AUL_R_OK;
+}
+
+} // namespace
+
+extern "C" API int aul_proc_group_add(pid_t pid) {
+ if (pid < 1) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ int ret = AppRequest(PROC_GROUP_ADD, getuid())
+ .SetPid(pid)
+ .SendSimply();
+ if (ret < 0) {
+ _E("Failed to send the request. error(%d)", ret);
+ return aul_error_convert(ret);
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_proc_group_remove(pid_t pid) {
+ if (pid < 1) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ int ret = AppRequest(PROC_GROUP_REMOVE, getuid())
+ .SetPid(pid)
+ .SendSimply();
+ if (ret < 0) {
+ _E("Failed to send the request. error(%d)", ret);
+ return aul_error_convert(ret);
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_proc_group_foreach(aul_proc_group_cb callback,
+ void *user_data) {
+ if (callback == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ bundle* response = nullptr;
+ int ret = SendAndReceive(PROC_GROUP_FOREACH, 0, &response);
+ if (ret != AUL_R_OK)
+ return ret;
+
+ tizen_base::Bundle b(response, false, true);
+ auto length_str = b.GetString("__K_LENGTH");
+ int length = std::stoi(length_str);
+ for (int i = 0; i < length; ++i) {
+ auto group = b.GetStringArray(std::to_string(i));
+ if (group.size() == 0) {
+ _E("Invalid size. index(%d)", i);
+ continue;
+ }
+
+ pid_t leader_pid = std::stoi(group[0]);
+ std::vector<pid_t> sub_pids;
+ for (size_t index = 1; index < group.size(); ++index)
+ sub_pids.push_back(std::stoi(group[index]));
+
+ ProcGroupInfo info(leader_pid, std::move(sub_pids));
+ callback(static_cast<aul_proc_group_info_h>(&info), user_data);
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_proc_group_info_get_leader_pid(aul_proc_group_info_h h,
+ pid_t* leader_pid) {
+ if (h == nullptr || leader_pid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* info = static_cast<ProcGroupInfo*>(h);
+ *leader_pid = info->GetLeaderPid();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_proc_group_info_get_sub_pids(aul_proc_group_info_h h,
+ const pid_t** sub_pids, size_t* length) {
+ if (h == nullptr || sub_pids == nullptr || length == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* info = static_cast<ProcGroupInfo*>(h);
+ auto& pids = info->GetSubPids();
+ *sub_pids = const_cast<pid_t*>(pids.data());
+ *length = pids.size();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_proc_group_get(pid_t pid,
+ aul_proc_group_info_h *h) {
+ if (pid < 2 || h == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ bundle* response = nullptr;
+ int ret = SendAndReceive(PROC_GROUP_GET, pid, &response);
+ if (ret != AUL_R_OK)
+ return ret;
+
+ tizen_base::Bundle b(response, false, true);
+ auto group = b.GetStringArray("__K_GROUP_INFO");
+ if (group.size() == 0) {
+ _E("There is no group info. pid(%d)", pid);
+ return AUL_R_ENOENT;
+ }
+
+ pid_t leader_pid = std::stoi(group[0]);
+ std::vector<pid_t> sub_pids;
+ for (size_t index = 1; index < group.size(); ++index)
+ sub_pids.push_back(std::stoi(group[index]));
+
+ auto* info = new (std::nothrow) ProcGroupInfo(leader_pid,
+ std::move(sub_pids));
+ if (info == nullptr) {
+ _E("Out of memory");
+ return AUL_R_ENOMEM;
+ }
+
+ *h = static_cast<aul_proc_group_info_h>(info);
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_proc_group_info_destroy(aul_proc_group_info_h h) {
+ if (h == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* handle = static_cast<ProcGroupInfo*>(h);
+ delete handle;
+ return AUL_R_OK;
+}
--- /dev/null
+/*
+ * Copyright (c) 2018 - 2021 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 "aul/include/aul_rpc_port.h"
+
+#include <bundle_cpp.h>
+#include <bundle_internal.h>
+#include <glib.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <memory>
+#include <string>
+
+#include "aul/app_request.h"
+#include "aul/aul_api.h"
+#include "aul/aul_util.h"
+#include "aul/include/aul.h"
+#include "aul/include/aul_app_com.h"
+#include "aul/include/aul_error.h"
+#include "aul/include/aul_sock.h"
+#include "aul/include/aul_svc.h"
+
+using namespace aul::internal;
+
+namespace {
+
+constexpr const char kEndpoint[] = "org.tizen.rpcport";
+constexpr const char kInterfacePrefix[] = "org.tizen.rpcport._";
+constexpr const char kPathRunAulRpcPort[] = "/run/aul/rpcport/";
+
+class WatchInfo {
+ public:
+ WatchInfo(std::string app_id, std::string port_name,
+ aul_rpc_port_appeared_cb appeared_cb,
+ aul_rpc_port_vanished_cb vanished_cb,
+ void* user_data, uid_t uid)
+ : app_id_(std::move(app_id)),
+ port_name_(std::move(port_name)),
+ appeared_cb_(appeared_cb),
+ vanished_cb_(vanished_cb),
+ user_data_(user_data),
+ uid_(uid) {
+ }
+
+ ~WatchInfo() {}
+
+ int Watch() {
+ int ret = aul_app_com_create(kEndpoint, nullptr, AppComCb, this, &conn_);
+ if (ret != AUL_R_OK)
+ _E("aul_app_com_create() is failed. error(%d)", ret);
+
+ return ret;
+ }
+
+ void Unwatch() {
+ if (conn_) {
+ aul_app_com_leave(conn_);
+ conn_ = nullptr;
+ }
+ }
+
+ private:
+ static int AppComCb(const char* endpoint, aul_app_com_result_e result,
+ bundle* envelope, void* user_data) {
+ auto* info = static_cast<WatchInfo*>(user_data);
+ tizen_base::Bundle b(envelope, false, false);
+ std::string app_id = b.GetString(AUL_K_APPID);
+ if (info->app_id_ != app_id)
+ return -1;
+
+ std::string port_name = b.GetString(AUL_K_RPC_PORT);
+ if (info->port_name_ != port_name)
+ return -1;
+
+ std::string uid_str = b.GetString(AUL_K_CALLER_UID);
+ uid_t uid =
+ static_cast<uid_t>(std::stoul(uid_str, nullptr, 10) & UINT32_MAX);
+ if (info->uid_ != uid)
+ return -1;
+
+ std::string pid_str = b.GetString(AUL_K_PID);
+ int pid = std::stoi(pid_str);
+ std::string event_name = b.GetString(AUL_K_EVENT_NAME);
+ if (event_name == "Appeared") {
+ info->appeared_cb_(app_id.c_str(), port_name.c_str(), pid,
+ info->user_data_);
+ } else {
+ info->vanished_cb_(app_id.c_str(), port_name.c_str(), pid,
+ info->user_data_);
+ }
+
+ return 0;
+ }
+
+ private:
+ std::string app_id_;
+ std::string port_name_;
+ aul_rpc_port_appeared_cb appeared_cb_;
+ aul_rpc_port_vanished_cb vanished_cb_;
+ void* user_data_;
+ uid_t uid_;
+ aul_app_com_connection_h conn_ = nullptr;
+};
+
+std::string GetInterfaceName(const std::string& app_id,
+ const std::string& port_name, uid_t uid) {
+ std::string name = kInterfacePrefix + app_id + "_" + port_name;
+ char* checksum = g_compute_checksum_for_string(G_CHECKSUM_SHA1,
+ name.c_str(), name.length());
+ std::unique_ptr<char, decltype(g_free)*> checksum_auto(checksum, g_free);
+ return std::to_string(uid) + "@" + std::string(checksum);
+}
+
+std::string GetPath(const std::string& interface_name) {
+ return std::string(kPathRunAulRpcPort) + "." + interface_name;
+}
+
+} // namespace
+
+extern "C" API int aul_rpc_port_prepare_stub(const char* app_id,
+ const char* port_name) {
+ return aul_rpc_port_usr_prepare_stub(app_id, port_name, getuid());
+}
+
+extern "C" API int aul_rpc_port_usr_prepare_stub(const char* app_id,
+ const char* port_name, uid_t uid) {
+ if (app_id == nullptr || port_name == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ tizen_base::Bundle b {{AUL_K_RPC_PORT, port_name}};
+ int ret = AppRequest(RPC_PORT_PREPARE_STUB, uid)
+ .With(b)
+ .SetAppId(app_id)
+ .SendSimply(AUL_SOCK_QUEUE);
+ if (ret < 0) {
+ _E("Failed to send request. app_id(%s), port_name(%s)", app_id, port_name);
+ return ret;
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_rpc_port_create_socket_pair(const char* app_id,
+ const char* port_name, int (*fds)[2]) {
+ if (app_id == nullptr || port_name == nullptr || fds == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ tizen_base::Bundle b {{AUL_K_RPC_PORT, port_name}};
+ int fd = AppRequest(RPC_PORT_CREATE_SOCKET_PAIR, getuid())
+ .With(b)
+ .SetAppId(app_id)
+ .SendSimply(AUL_SOCK_ASYNC);
+ if (fd <= 0 || fd >= sysconf(_SC_OPEN_MAX)) {
+ _E("Failed to send socket pair creation request. error(%d)", fd);
+ return fd;
+ }
+
+ int ret = aul_sock_recv_reply_sock_fd(fd, fds, 2);
+ if (ret != 0) {
+ _E("Failed to receive socket fds. error(%d)", ret);
+ return aul_error_convert(ret);
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_rpc_port_notify_rpc_finished(void) {
+ int ret = AppRequest(RPC_PORT_NOTIFY_RPC_FINISHED, getuid())
+ .SetPid(getpid())
+ .SendSimply(AUL_SOCK_NOREPLY);
+ if (ret != 0) {
+ _E("Failed to notify rpc finished. error(%d)", ret);
+ return ret;
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_rpc_port_set_private_sharing(const char* app_id,
+ const char* paths[], unsigned int size) {
+ if (app_id == nullptr || paths == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ tizen_base::Bundle b {{AUL_K_CALLEE_APPID, app_id}};
+ std::vector<std::string> v;
+ for (unsigned int i = 0; i < size; ++i)
+ v.push_back(paths[i]);
+ b.Add(AUL_SVC_DATA_PATH, v);
+
+ int ret = AppRequest(SET_PRIVATE_SHARING, getuid())
+ .With(b)
+ .SetPid(getpid())
+ .SendSimply(AUL_SOCK_NOREPLY);
+ if (ret != 0) {
+ _E("Failed to set private sharing. error(%d)", ret);
+ return ret;
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_rpc_port_unset_private_sharing(const char* app_id) {
+ if (app_id == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ tizen_base::Bundle b {{AUL_K_CALLEE_APPID, app_id}};
+ int ret = AppRequest(UNSET_PRIVATE_SHARING, getuid())
+ .With(b)
+ .SetPid(getpid())
+ .SendSimply(AUL_SOCK_NOREPLY);
+ if (ret != 0) {
+ _E("Failed to unset private sharing. error(%d)", ret);
+ return ret;
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_rpc_port_create(const char* port_name, int* fd) {
+ return aul_rpc_port_usr_create(port_name, getuid(), fd);
+}
+
+extern "C" API int aul_rpc_port_usr_create(const char* port_name, uid_t uid,
+ int* fd) {
+ if (port_name == nullptr || fd == nullptr) {
+ _E("Invalid paramter");
+ return AUL_R_EINVAL;
+ }
+
+ tizen_base::Bundle b {{AUL_K_RPC_PORT, port_name}};
+ int req_fd = AppRequest(RPC_PORT_CREATE, uid)
+ .With(b)
+ .SendSimply(AUL_SOCK_ASYNC);
+ if (req_fd <= 0 || req_fd >= sysconf(_SC_OPEN_MAX)) {
+ _E("Failed to send socket creation request. error(%d)", req_fd);
+ return req_fd;
+ }
+
+ int fds[2] = { -1, };
+ int ret = aul_sock_recv_reply_sock_fd(req_fd, &fds, 1);
+ if (ret != 0) {
+ _E("Failed to receive socket fds. error(%d)", ret);
+ return aul_error_convert(ret);
+ }
+
+ *fd = fds[0];
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_rpc_port_destroy(const char* port_name) {
+ return aul_rpc_port_usr_destroy(port_name, getuid());
+}
+
+extern "C" API int aul_rpc_port_usr_destroy(const char* port_name, uid_t uid) {
+ if (port_name == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ tizen_base::Bundle b {{AUL_K_RPC_PORT, port_name}};
+ int ret = AppRequest(RPC_PORT_DESTROY, uid)
+ .With(b)
+ .SendSimply(AUL_SOCK_NOREPLY);
+ if (ret != 0) {
+ _E("Failed to send socket desctruction request. error(%d)", ret);
+ return ret;
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_rpc_port_add_watch(const char* app_id,
+ const char* port_name, aul_rpc_port_appeared_cb appeared_cb,
+ aul_rpc_port_vanished_cb vanished_cb, void* user_data,
+ aul_rpc_port_watch_h* handle) {
+ return aul_rpc_port_usr_add_watch(app_id, port_name, appeared_cb, vanished_cb,
+ user_data, getuid(), handle);
+}
+
+extern "C" API int aul_rpc_port_usr_add_watch(const char* app_id,
+ const char* port_name, aul_rpc_port_appeared_cb appeared_cb,
+ aul_rpc_port_vanished_cb vanished_cb, void* user_data, uid_t uid,
+ aul_rpc_port_watch_h* handle) {
+ if (app_id == nullptr || port_name == nullptr || appeared_cb == nullptr ||
+ vanished_cb == nullptr || handle == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* info = new (std::nothrow) WatchInfo(app_id, port_name, appeared_cb,
+ vanished_cb, user_data, uid);
+ if (info == nullptr) {
+ _E("Out of memory");
+ return AUL_R_ENOMEM;
+ }
+
+ int ret = info->Watch();
+ if (ret != AUL_R_OK) {
+ delete info;
+ return ret;
+ }
+
+ *handle = static_cast<aul_rpc_port_watch_h>(info);
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_rpc_port_remove_watch(aul_rpc_port_watch_h handle) {
+ if (handle == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* info = static_cast<WatchInfo*>(handle);
+ info->Unwatch();
+ delete info;
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_rpc_port_exist(const char* app_id, const char* port_name,
+ bool* exist) {
+ return aul_rpc_port_usr_exist(app_id, port_name, getuid(), exist);
+}
+
+extern "C" API int aul_rpc_port_usr_exist(const char* app_id,
+ const char* port_name, uid_t uid, bool* exist) {
+ if (app_id == nullptr || port_name == nullptr || exist == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ char* port_path;
+ if (aul_rpc_port_usr_get_path(app_id, port_name, uid, &port_path) != AUL_R_OK)
+ return AUL_R_ENOMEM;
+
+ int ret = access(port_path, F_OK);
+ free(port_path);
+ *exist = (ret == 0) ? true : false;
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_rpc_port_get_path(const char* app_id,
+ const char* port_name, char** path) {
+ return aul_rpc_port_usr_get_path(app_id, port_name, getuid(), path);
+}
+
+extern "C" API int aul_rpc_port_usr_get_path(const char* app_id,
+ const char* port_name, uid_t uid, char** path) {
+ if (app_id == nullptr || port_name == nullptr || path == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ std::string interface_name = GetInterfaceName(app_id, port_name, uid);
+ std::string port_path = GetPath(interface_name);
+ struct sockaddr_un addr = { 0, };
+ snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", port_path.c_str());
+ *path = strdup(addr.sun_path);
+ if (*path == nullptr) {
+ _E("Out of memory");
+ return AUL_R_ENOMEM;
+ }
+
+ return AUL_R_OK;
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#define _GNU_SOURCE
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+#include <glib/gstdio.h>
+#include <bundle_internal.h>
+#include <assert.h>
+#include <dlog.h>
+#include <vconf.h>
+#include <system_info.h>
+
+#include "aul.h"
+#include "aul_api.h"
+#include "aul_rsc_mgr.h"
+#include "aul_rsc_mgr_internal.h"
+
+#define WEIGHT_SCREEN_DPI 10000
+#define WEIGHT_SCREEN_DPI_RANGE 10000
+#define WEIGHT_SCREEN_BPP 1000
+#define WEIGHT_SCREEN_WIDTH_RANGE 100
+#define WEIGHT_SCREEN_LARGE 10
+#define WEIGHT_PLATFORM_VERSION 1000000
+#define WEIGHT_LANGUAGE 100000
+
+#define THRESHOLD_TO_CLEAN 50 /* app_resource_manager_trim_cache */
+
+#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))
+#define MAX_PATH 1024
+
+typedef struct {
+ resource_data_t *data;
+ GHashTable *cache;
+} resource_manager_t;
+
+typedef struct {
+ char *output;
+ int hit_cnt;
+ bool remove;
+} resource_cache_context_t;
+
+typedef struct {
+ const char *bundle_attr_key;
+ unsigned int bundle_attr_value;
+} resource_node_attr_t;
+
+typedef struct {
+ char *folder;
+ char *type;
+} resource_node_list_t;
+
+enum {
+ NODE_ATTR_MIN = 0,
+ NODE_ATTR_SCREEN_DPI,
+ NODE_ATTR_SCREEN_DPI_RANGE,
+ NODE_ATTR_SCREEN_WIDTH_RANGE,
+ NODE_ATTR_SCREEN_LARGE,
+ NODE_ATTR_SCREEN_BPP,
+ NODE_ATTR_PLATFORM_VER,
+ NODE_ATTR_LANGUAGE,
+ NODE_ATTR_MAX
+};
+
+static resource_manager_t *resource_handle = NULL;
+
+static resource_node_attr_t map[] = {
+ { RSC_NODE_ATTR_SCREEN_DPI, NODE_ATTR_SCREEN_DPI },
+ { RSC_NODE_ATTR_SCREEN_DPI_RANGE, NODE_ATTR_SCREEN_DPI_RANGE },
+ { RSC_NODE_ATTR_SCREEN_WIDTH_RANGE, NODE_ATTR_SCREEN_WIDTH_RANGE },
+ { RSC_NODE_ATTR_SCREEN_LARGE, NODE_ATTR_SCREEN_LARGE },
+ { RSC_NODE_ATTR_SCREEN_BPP, NODE_ATTR_SCREEN_BPP },
+ { RSC_NODE_ATTR_PLATFORM_VER, NODE_ATTR_PLATFORM_VER },
+ { RSC_NODE_ATTR_LANGUAGE, NODE_ATTR_LANGUAGE },
+};
+
+static GHashTable *attr_key = NULL;
+static const char *res_path = NULL;
+static char *cur_language = NULL;
+static bool is_slice = FALSE;
+
+static GHashTable *valid_path_list = NULL;
+static GHashTable *supported_lang_list = NULL;
+static GHashTable *id_list = NULL;
+static GList *all_node_list = NULL;
+static bundle *given_attr_list = NULL;
+
+static gint __resource_manager_comp(gconstpointer a, gconstpointer b)
+{
+ resource_group_t *rsc_group = (resource_group_t *) a;
+
+ return strcmp(rsc_group->type, b);
+}
+
+static gint __compare_path(gconstpointer a, gconstpointer b)
+{
+ char tmp_path[MAX_PATH] = {0, };
+ resource_node_list_t *tmp_node_info = (resource_node_list_t *)a;
+
+ snprintf(tmp_path, MAX_PATH - 1, "%s%s", res_path, tmp_node_info->folder);
+ return strncmp(tmp_path, (char *)b, strlen(tmp_path));
+}
+
+static int __get_dpi(void)
+{
+ int dpi = 0;
+ char *tmp = NULL;
+
+ if (is_slice) {
+ bundle_get_str(given_attr_list, RSC_NODE_ATTR_SCREEN_DPI, &tmp);
+ if (tmp == NULL) {
+ LOGE("Failed to retrieve DPI");
+ dpi = 0;
+ } else {
+ dpi = atoi(tmp);
+ }
+ } else {
+ system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
+ }
+
+ return dpi;
+}
+
+static int __get_screen_width(void)
+{
+ int screen_width = 0;
+ char *tmp = NULL;
+
+ if (is_slice) {
+ bundle_get_str(given_attr_list, RSC_NODE_ATTR_SCREEN_WIDTH_RANGE, &tmp);
+ if (tmp == NULL) {
+ LOGE("Failed to retrieve screen width");
+ screen_width = 0;
+ } else
+ screen_width = atoi(tmp);
+ } else
+ system_info_get_platform_int("http://tizen.org/feature/screen.width", &screen_width);
+
+ return screen_width;
+}
+
+static bool __get_screen_large(void)
+{
+ bool screen_large = true;
+ char *tmp = NULL;
+
+ if (is_slice) {
+ bundle_get_str(given_attr_list, RSC_NODE_ATTR_SCREEN_LARGE, &tmp);
+ if (tmp == NULL) {
+ LOGE("Failed to retrieve screen large");
+ screen_large = false;
+ } else
+ screen_large = atoi(tmp);
+ } else {
+ if (system_info_get_platform_bool("http://tizen.org/feature/screen.size.large", &screen_large) != SYSTEM_INFO_ERROR_NONE) {
+ LOGE("Failed to get info of screen.size.large");
+ screen_large = false;
+ }
+ }
+
+ return screen_large;
+}
+
+static int __get_screen_bpp(void)
+{
+ int screen_bpp = 0;
+ char *tmp = NULL;
+
+ if (is_slice) {
+ bundle_get_str(given_attr_list, RSC_NODE_ATTR_SCREEN_BPP, &tmp);
+ if (tmp == NULL) {
+ LOGE("Failed to retrieve screen bpp");
+ screen_bpp = 0;
+ } else
+ screen_bpp = atoi(tmp);
+ } else
+ system_info_get_platform_int("http://tizen.org/feature/screen.bpp", &screen_bpp);
+
+ return screen_bpp;
+}
+
+static char *__get_platform_version(void)
+{
+ char *version = NULL;
+ if (is_slice)
+ bundle_get_str(given_attr_list, RSC_NODE_ATTR_PLATFORM_VER, &version);
+ else
+ system_info_get_platform_string("http://tizen.org/feature/platform.version", &version);
+
+ return version;
+}
+
+static void __bundle_iterator_get_valid_nodes(const char *key, const int type,
+ const bundle_keyval_t *kv, void *data)
+{
+ unsigned int node_attr;
+ bool *invalid = (bool *) data;
+ bool ret_bool = true;
+ int min, max;
+ char *from = NULL;
+ char *to = NULL;
+ bool t_val;
+ char *val;
+ size_t size;
+ static int screen_dpi = -1;
+ static int screen_width = -1;
+ static int screen_size_large = -1;
+ static char *version = NULL;
+ static int screen_bpp = -1;
+
+ if (*invalid)
+ return;
+
+ bundle_keyval_get_basic_val((bundle_keyval_t *) kv, (void**) &val, &size);
+
+ node_attr = (uintptr_t)g_hash_table_lookup(attr_key, key);
+ if (node_attr <= NODE_ATTR_MIN || node_attr >= NODE_ATTR_MAX) {
+ LOGE("INVALID_PARAMETER(0x%08x), node_attr(%d)",
+ AUL_RESOURCE_ERROR_INVALID_PARAMETER, node_attr);
+ *invalid = true;
+ return;
+ }
+
+ switch (node_attr) {
+ case NODE_ATTR_SCREEN_DPI:
+ if (screen_dpi == -1)
+ screen_dpi = __get_dpi();
+ if (screen_dpi != atoi(val))
+ *invalid = true;
+ break;
+ case NODE_ATTR_SCREEN_DPI_RANGE:
+ sscanf(val, "%ms %d %ms %d", &from, &min, &to, &max);
+ if (screen_dpi == -1)
+ screen_dpi = __get_dpi();
+ if (!(min <= screen_dpi && screen_dpi <= max))
+ *invalid = true;
+ if (from)
+ free(from);
+ if (to)
+ free(to);
+ break;
+ case NODE_ATTR_SCREEN_WIDTH_RANGE:
+ sscanf(val, "%ms %d %ms %d", &from, &min, &to, &max);
+ if (screen_width == -1)
+ screen_width = __get_screen_width();
+ if (!(min <= screen_width && screen_width <= max))
+ *invalid = true;
+ if (from)
+ free(from);
+ if (to)
+ free(to);
+ break;
+ case NODE_ATTR_SCREEN_LARGE:
+ if (!(strcmp(val, "true")))
+ t_val = true;
+ else
+ t_val = false;
+ if (screen_size_large == -1) {
+ ret_bool = __get_screen_large();
+ if (ret_bool)
+ screen_size_large = 1;
+ else
+ screen_size_large = 0;
+ }
+ if (((bool)screen_size_large) != t_val)
+ *invalid = true;
+ break;
+ case NODE_ATTR_SCREEN_BPP:
+ if (screen_bpp == -1)
+ screen_bpp = __get_screen_bpp();
+ if (screen_bpp != atoi(val))
+ *invalid = true;
+ break;
+ case NODE_ATTR_PLATFORM_VER:
+ if (version == NULL)
+ version = __get_platform_version();
+ if (strcmp(version, val))
+ *invalid = true;
+ break;
+ case NODE_ATTR_LANGUAGE:
+ if (cur_language == NULL) {
+ cur_language = vconf_get_str(VCONFKEY_LANGSET);
+ if (cur_language == NULL)
+ *invalid = true;
+ }
+ if (cur_language && strncmp(cur_language, val, strlen(val)))
+ *invalid = true;
+ break;
+ }
+}
+
+static void __bundle_iterator_get_best_node(const char *key, const char *val,
+ void *data)
+{
+ unsigned int node_attr;
+ unsigned int *weight = (unsigned int *)data;
+
+ node_attr = (uintptr_t)g_hash_table_lookup(attr_key, key);
+ if (node_attr <= NODE_ATTR_MIN || node_attr >= NODE_ATTR_MAX) {
+ LOGE("INVALID_PARAMETER(0x%08x), node_attr(%d)",
+ AUL_RESOURCE_ERROR_INVALID_PARAMETER, node_attr);
+ return;
+ }
+
+ switch (node_attr) {
+ case NODE_ATTR_SCREEN_DPI:
+ *weight += WEIGHT_SCREEN_DPI;
+ break;
+ case NODE_ATTR_SCREEN_DPI_RANGE:
+ *weight += WEIGHT_SCREEN_DPI_RANGE;
+ break;
+ case NODE_ATTR_SCREEN_WIDTH_RANGE:
+ *weight += WEIGHT_SCREEN_WIDTH_RANGE;
+ break;
+ case NODE_ATTR_SCREEN_LARGE:
+ *weight += WEIGHT_SCREEN_LARGE;
+ break;
+ case NODE_ATTR_SCREEN_BPP:
+ *weight += WEIGHT_SCREEN_BPP;
+ break;
+ case NODE_ATTR_PLATFORM_VER:
+ *weight += WEIGHT_PLATFORM_VERSION;
+ break;
+ case NODE_ATTR_LANGUAGE:
+ *weight += WEIGHT_LANGUAGE;
+ break;
+ }
+}
+
+static const char *__get_cache(aul_resource_e type,
+ const char *id)
+{
+ unsigned int total_len = 0;
+ char *key = NULL;
+ char *rsc_type;
+ resource_cache_context_t *resource_cache = NULL;
+
+ if (is_slice == TRUE)
+ return NULL;
+
+ if (id == NULL) {
+ LOGW("(0x%08x), id",
+ AUL_RESOURCE_ERROR_INVALID_PARAMETER);
+ return NULL;
+ }
+
+ if (type < AUL_RESOURCE_TYPE_MIN || type > AUL_RESOURCE_TYPE_MAX) {
+ LOGW("(0x%08x), type(%d)",
+ AUL_RESOURCE_ERROR_INVALID_PARAMETER, type);
+ return NULL;
+ } else {
+ switch (type) {
+ case AUL_RESOURCE_TYPE_IMAGE:
+ rsc_type = RSC_GROUP_TYPE_IMAGE;
+ break;
+ case AUL_RESOURCE_TYPE_LAYOUT:
+ rsc_type = RSC_GROUP_TYPE_LAYOUT;
+ break;
+ case AUL_RESOURCE_TYPE_SOUND:
+ rsc_type = RSC_GROUP_TYPE_SOUND;
+ break;
+ case AUL_RESOURCE_TYPE_BIN:
+ rsc_type = RSC_GROUP_TYPE_BIN;
+ break;
+ }
+ }
+
+ if (resource_handle->cache == NULL) {
+ LOGW("(0x%08x), hashtable",
+ AUL_RESOURCE_ERROR_INVALID_PARAMETER);
+ return NULL;
+ } else {
+ total_len = (unsigned int)(strlen(rsc_type) + strlen(id) + 2);
+ key = (char *)calloc(1, total_len);
+ if (key == NULL) {
+ LOGE("OOM!, failed to create a resource_cache(0x%08x)",
+ AUL_RESOURCE_ERROR_OUT_OF_MEMORY);
+ free(resource_cache);
+ return NULL;
+ }
+
+ snprintf(key, total_len, "%s:%s", rsc_type, id);
+ LOGD("key : %s", key);
+
+ resource_cache = g_hash_table_lookup(resource_handle->cache, key);
+ free(key);
+ if (resource_cache == NULL) {
+ LOGW("(0x%08x), find list resource_cache",
+ AUL_RESOURCE_ERROR_IO_ERROR);
+ return NULL;
+ }
+
+ resource_cache->hit_cnt++;
+ }
+
+ return resource_cache->output;
+}
+
+static gint __cache_hit_compare(gconstpointer a, gconstpointer b)
+{
+ const resource_cache_context_t *lhs = (const resource_cache_context_t *) a;
+ const resource_cache_context_t *rhs = (const resource_cache_context_t *) b;
+
+ return lhs->hit_cnt - rhs->hit_cnt;
+}
+
+static gboolean __cache_remove(gpointer key, gpointer value, gpointer user_data)
+{
+ resource_cache_context_t *c = (resource_cache_context_t *) (value);
+
+ if (c->remove) {
+ free(key);
+ free(c->output);
+ free(c);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static void __trim_cache(void)
+{
+ GList *values = g_hash_table_get_values(resource_handle->cache);
+ values = g_list_sort(values, __cache_hit_compare);
+
+ int i = 0;
+ GList *iter_list = values;
+ while (iter_list != NULL) {
+ if (i >= (THRESHOLD_TO_CLEAN / 2))
+ break;
+
+ resource_cache_context_t *c =
+ (resource_cache_context_t *) (iter_list->data);
+ c->remove = true;
+ iter_list = g_list_next(iter_list);
+ i++;
+ }
+
+ g_list_free(values);
+ g_hash_table_foreach_remove(resource_handle->cache, __cache_remove, NULL);
+
+}
+
+static void __put_cache(aul_resource_e type, const char *id,
+ const char *val)
+{
+ unsigned int total_len = 0;
+ char *key;
+ char *rsc_type;
+ resource_cache_context_t *resource_cache;
+
+ if (is_slice == TRUE)
+ return;
+
+ /* To remove chache from the low frequency of use. */
+ if (val == NULL) {
+ LOGE("INVALID_PARAMETER(0x%08x), fname",
+ AUL_RESOURCE_ERROR_INVALID_PARAMETER);
+ return;
+ }
+
+ if (id == NULL) {
+ LOGE("INVALID_PARAMETER(0x%08x), id",
+ AUL_RESOURCE_ERROR_INVALID_PARAMETER);
+ return;
+ }
+
+ if (type < AUL_RESOURCE_TYPE_MIN || type > AUL_RESOURCE_TYPE_MAX) {
+ LOGE("INVALID_PARAMETER(0x%08x), type(%d)",
+ AUL_RESOURCE_ERROR_INVALID_PARAMETER, type);
+ return;
+ } else {
+ switch (type) {
+ case AUL_RESOURCE_TYPE_IMAGE:
+ rsc_type = RSC_GROUP_TYPE_IMAGE;
+ break;
+ case AUL_RESOURCE_TYPE_LAYOUT:
+ rsc_type = RSC_GROUP_TYPE_LAYOUT;
+ break;
+ case AUL_RESOURCE_TYPE_SOUND:
+ rsc_type = RSC_GROUP_TYPE_SOUND;
+ break;
+ case AUL_RESOURCE_TYPE_BIN:
+ rsc_type = RSC_GROUP_TYPE_BIN;
+ break;
+ }
+ }
+
+ if (g_hash_table_size(resource_handle->cache) > THRESHOLD_TO_CLEAN)
+ __trim_cache();
+
+ resource_cache = (resource_cache_context_t *)calloc(1,
+ sizeof(resource_cache_context_t));
+ if (resource_cache == NULL) {
+ LOGE("failed to create a resource_group(0x%08x)",
+ AUL_RESOURCE_ERROR_OUT_OF_MEMORY);
+ return;
+ }
+
+ total_len = (unsigned int)(strlen(rsc_type) + strlen(id) + 2);
+ key = (char *)calloc(1, total_len);
+ if (key == NULL) {
+ LOGE("failed to create a resource_cache(0x%08x)",
+ AUL_RESOURCE_ERROR_OUT_OF_MEMORY);
+ free(resource_cache);
+ return;
+ }
+
+ snprintf(key, total_len, "%s:%s", rsc_type, id);
+ LOGD("key : %s", key);
+
+ resource_cache->output = strdup(val);
+ resource_cache->hit_cnt = 0;
+ resource_cache->remove = false;
+
+ g_hash_table_insert(resource_handle->cache, key, resource_cache);
+}
+
+static resource_group_t *__find_group(resource_data_t *data,
+ int type)
+{
+ resource_group_t *rsc_group = NULL;
+ char *rsc_type;
+
+ if (data == NULL) {
+ LOGE("INVALID_PARAMETER(0x%08x), resource_data_t",
+ AUL_RESOURCE_ERROR_INVALID_PARAMETER);
+ return NULL;
+ }
+
+ if (type < AUL_RESOURCE_TYPE_MIN || type > AUL_RESOURCE_TYPE_MAX) {
+ LOGE("INVALID_PARAMETER(0x%08x), type(%d)",
+ AUL_RESOURCE_ERROR_INVALID_PARAMETER, type);
+ return NULL;
+ } else {
+ switch (type) {
+ case AUL_RESOURCE_TYPE_IMAGE:
+ rsc_type = RSC_GROUP_TYPE_IMAGE;
+ break;
+ case AUL_RESOURCE_TYPE_LAYOUT:
+ rsc_type = RSC_GROUP_TYPE_LAYOUT;
+ break;
+ case AUL_RESOURCE_TYPE_SOUND:
+ rsc_type = RSC_GROUP_TYPE_SOUND;
+ break;
+ case AUL_RESOURCE_TYPE_BIN:
+ rsc_type = RSC_GROUP_TYPE_BIN;
+ break;
+ }
+ }
+
+ GList* found = g_list_find_custom(data->group_list, rsc_type,
+ __resource_manager_comp);
+ if (found == NULL) {
+ LOGE("IO_ERROR(0x%08x), find list resource_group %s",
+ AUL_RESOURCE_ERROR_IO_ERROR, rsc_type);
+ return NULL;
+ }
+
+ rsc_group = (resource_group_t *) (found->data);
+
+ return rsc_group;
+}
+
+static GList *__get_valid_nodes(resource_group_t *group,
+ const char *id)
+{
+ GList *list = NULL;
+ GList *valid_list = NULL;
+ resource_node_t *valid_node = NULL;
+ resource_node_t *rsc_node = NULL;
+
+ if (group->node_list == NULL) {
+ LOGE("INVALID_PARAMETER(0x%08x), resource_group",
+ AUL_RESOURCE_ERROR_INVALID_PARAMETER);
+ return NULL;
+ }
+
+ list = g_list_first(group->node_list);
+
+ char path_buf[MAX_PATH] = { 0, };
+ while (list) {
+ bool invalid = false;
+ rsc_node = (resource_node_t *) list->data;
+
+ snprintf(path_buf, MAX_PATH - 1, "%s%s/%s", res_path,
+ rsc_node->folder, id);
+ if (access(path_buf, R_OK) == 0) {
+ bundle_foreach(rsc_node->attr, __bundle_iterator_get_valid_nodes,
+ &invalid);
+
+ if (!invalid) {
+ valid_node = (resource_node_t *) list->data;
+ valid_list = g_list_append(valid_list, valid_node);
+ }
+ }
+
+ list = g_list_next(list);
+ }
+
+ return valid_list;
+}
+
+static resource_node_t *__get_best_node(GList *nodes)
+{
+ unsigned int weight_tmp = 0;
+ resource_node_t *best_node = NULL;
+ GList *list = NULL;
+
+ if (nodes == NULL) {
+ LOGE("INVALID_PARAMETER(0x%08x), resource_node lists",
+ AUL_RESOURCE_ERROR_INVALID_PARAMETER);
+ return NULL;
+ }
+
+ list = g_list_first(nodes);
+
+ while (list != NULL) {
+ unsigned int weight = 0;
+ resource_node_t *res_node = (resource_node_t *) (list->data);
+
+ bundle_iterate(res_node->attr, __bundle_iterator_get_best_node, &weight);
+ if (weight > weight_tmp) {
+ best_node = res_node;
+ weight_tmp = weight;
+ }
+ list = g_list_next(list);
+ }
+
+ return best_node;
+}
+
+static int __open(resource_manager_t **handle)
+{
+ int retval = AUL_RESOURCE_ERROR_NONE;
+ resource_manager_t *rsc_manager = NULL;
+ char buf[MAX_PATH] = { 0, };
+
+ rsc_manager = (resource_manager_t *) calloc(1, sizeof(resource_manager_t));
+ if (!rsc_manager) {
+ LOGE("failed to create a resource_manager(0x%08x)",
+ AUL_RESOURCE_ERROR_OUT_OF_MEMORY);
+ return AUL_RESOURCE_ERROR_OUT_OF_MEMORY;
+ }
+
+ snprintf(buf, MAX_PATH - 1, "%sres.xml", res_path);
+ retval = _resource_open(buf, &(rsc_manager->data));
+ if (retval) {
+ LOGE("IO_ERROR(0x%08x), failed to get db for resource manager",
+ AUL_RESOURCE_ERROR_IO_ERROR);
+ free(rsc_manager);
+ return AUL_RESOURCE_ERROR_IO_ERROR;
+ }
+
+ rsc_manager->cache = g_hash_table_new(g_str_hash, g_str_equal);
+ *handle = rsc_manager;
+
+ return AUL_RESOURCE_ERROR_NONE;
+}
+
+static void __invalidate_cache()
+{
+ if (resource_handle != NULL) {
+ if (resource_handle->cache != NULL) {
+ GHashTableIter iter;
+ gpointer key, value;
+
+ g_hash_table_iter_init(&iter, resource_handle->cache);
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
+ free(key);
+ resource_cache_context_t *c = (resource_cache_context_t *) value;
+ free(c->output);
+ free(value);
+ }
+ g_hash_table_remove_all(resource_handle->cache);
+ if (cur_language) {
+ free(cur_language);
+ cur_language = NULL;
+ }
+ }
+ }
+}
+
+static int __close(resource_manager_t *handle)
+{
+ if (handle == NULL) {
+ LOGE("INVALID_PARAMETER(0x%08x), resource_manager",
+ AUL_RESOURCE_ERROR_INVALID_PARAMETER);
+ return AUL_RESOURCE_ERROR_INVALID_PARAMETER;
+ }
+
+ __invalidate_cache();
+ if (handle->cache != NULL)
+ g_hash_table_destroy(handle->cache);
+
+ if (handle->data != NULL)
+ _resource_close(handle->data);
+
+ free(handle);
+
+ return AUL_RESOURCE_ERROR_NONE;
+}
+
+static void __vconf_cb(keynode_t *key, void *data)
+{
+ char *val;
+
+ val = vconf_keynode_get_str(key);
+ if (val && cur_language && !strcmp(val, cur_language))
+ return;
+
+ __invalidate_cache();
+}
+
+static const char *_get_app_resource_path(const char *rsc_folder_path)
+{
+ if (is_slice == FALSE)
+ return aul_get_app_resource_path();
+
+ if (rsc_folder_path == NULL)
+ return NULL;
+
+ return rsc_folder_path;
+}
+
+static void path_callback(char *path)
+{
+ char orig_path[PATH_MAX] = {0, };
+ char *path_ptr = NULL;
+ int path_len = 0;
+ GList *tmp_list = g_list_find_custom(all_node_list, path, __compare_path);
+
+ resource_node_list_t *tmp_node_info = NULL;
+ if (tmp_list == NULL)
+ g_hash_table_add(valid_path_list, strdup(path));
+ else {
+ tmp_node_info = (resource_node_list_t *)tmp_list->data;
+ path_len = strlen(path);
+ if (path_len >= PATH_MAX) {
+ LOGE("path[%s] is too long", path);
+ return;
+ }
+ strncpy(orig_path, path, sizeof(orig_path) - path_len - 1);
+ path_ptr = &orig_path[strlen(res_path) + strlen(tmp_node_info->folder)];
+ g_hash_table_insert(id_list, strdup(path_ptr), strdup(tmp_node_info->type));
+ }
+}
+
+static void __scan_dir(const char *path, void (*func)(char *))
+{
+ struct dirent **items;
+ int nitems, i;
+ struct stat fstat;
+ char abs_path[PATH_MAX] = {0, };
+ char cwd[MAX_PATH] = {0, };
+ char *tmp = NULL;
+
+ if (chdir(path) < 0) {
+ LOGE("failed to chdir[%s]", path);
+ return;
+ }
+
+ tmp = getcwd(cwd, MAX_PATH - 1);
+ if (tmp == NULL) {
+ LOGE("failed to get cwd");
+ return;
+ }
+ nitems = scandir("./", &items, NULL, alphasort);
+
+ for (i = 0; i < nitems; i++) {
+ if (items[i]->d_name[0] == '.')
+ continue;
+
+ snprintf(abs_path, sizeof(abs_path), "%s/%s", cwd, items[i]->d_name);
+
+ if (g_lstat(abs_path, &fstat) != 0) {
+ LOGE("failed to retrieve info[%s]", abs_path);
+ return;
+ }
+ if ((fstat.st_mode & S_IFDIR) == S_IFDIR)
+ __scan_dir(abs_path, path_callback);
+ else
+ func(abs_path);
+ }
+
+}
+
+static aul_resource_e __get_resource_type(char *type)
+{
+ if (type == NULL)
+ return -1;
+
+ if (strcmp(type, RSC_GROUP_TYPE_IMAGE) == 0)
+ return AUL_RESOURCE_TYPE_IMAGE;
+ else if (strcmp(type, RSC_GROUP_TYPE_LAYOUT) == 0)
+ return AUL_RESOURCE_TYPE_LAYOUT;
+ else if (strcmp(type, RSC_GROUP_TYPE_SOUND) == 0)
+ return AUL_RESOURCE_TYPE_SOUND;
+ else if (strcmp(type, RSC_GROUP_TYPE_BIN) == 0)
+ return AUL_RESOURCE_TYPE_BIN;
+ else
+ return -1;
+}
+
+static int __set_valid_filelist(bundle *b)
+{
+ if (b == NULL || supported_lang_list == NULL) {
+ LOGE("INVALID_PARAMETER(0x%08x), bundle",
+ AUL_RESOURCE_ERROR_INVALID_PARAMETER);
+ return AUL_RESOURCE_ERROR_INVALID_PARAMETER;
+ }
+
+ int retval = AUL_RESOURCE_ERROR_NONE;
+ char *path = NULL;
+ GHashTableIter id_list_iter;
+ GHashTableIter lang_list_iter;
+ gpointer id_key, lang_key, id_type;
+ aul_resource_e rsc_type = AUL_RESOURCE_TYPE_MIN;
+
+ given_attr_list = b;
+ g_hash_table_iter_init(&id_list_iter, id_list);
+
+ while (g_hash_table_iter_next(&id_list_iter, &id_key, &id_type)) {
+ rsc_type = __get_resource_type((char *)id_type);
+ if (rsc_type == -1) {
+ LOGE("failed to get resource type[%s]", (char *)id_type);
+ return AUL_RESOURCE_ERROR_IO_ERROR;
+ }
+
+ g_hash_table_iter_init(&lang_list_iter, supported_lang_list);
+ while (g_hash_table_iter_next(&lang_list_iter, &lang_key, NULL)) {
+ cur_language = strdup(lang_key);
+ if (cur_language == NULL) {
+ LOGE("failed to strdup");
+ return AUL_RESOURCE_ERROR_OUT_OF_MEMORY;
+ }
+
+ retval = aul_resource_manager_get(rsc_type, id_key, &path);
+ if (retval == AUL_RESOURCE_ERROR_NONE)
+ g_hash_table_add(valid_path_list, path);
+ else
+ LOGE("failed to get value with given type[%d], key[%s]", rsc_type, (const char *)id_key);
+
+ if (cur_language) {
+ free(cur_language);
+ cur_language = NULL;
+ }
+ }
+ }
+ return AUL_RESOURCE_ERROR_NONE;
+}
+
+static int __make_list(void)
+{
+ resource_group_t *tmp_group = NULL;
+ resource_node_t *tmp_node = NULL;
+ resource_node_list_t *tmp_node_struct = NULL;
+ char *group_type = NULL;
+ char folder[MAX_PATH] = {0 ,};
+ char *node_lang = NULL;
+ GList *group_list = NULL;
+ GList *node_list = NULL;
+ bundle *b = NULL;
+
+
+ /* make node folder list */
+ group_list = resource_handle->data->group_list;
+ if (group_list == NULL)
+ return AUL_RESOURCE_ERROR_IO_ERROR;
+
+ while (group_list != NULL) {
+ tmp_group = (resource_group_t *)group_list->data;
+ if (tmp_group == NULL)
+ return AUL_RESOURCE_ERROR_IO_ERROR;
+
+ group_type = tmp_group->type;
+ node_list = tmp_group->node_list;
+ memset(folder, '\0', MAX_PATH);
+ snprintf(folder, MAX_PATH - 1, "%s/", tmp_group->folder);
+
+ /* make struct and put it into all node list */
+ tmp_node_struct = (resource_node_list_t *)calloc(1, sizeof(resource_node_list_t));
+ if (tmp_node_struct == NULL) {
+ LOGE("calloc failed");
+ return AUL_RESOURCE_ERROR_OUT_OF_MEMORY;
+ }
+
+ tmp_node_struct->folder = strdup(folder);
+ tmp_node_struct->type = strdup(group_type);
+ all_node_list = g_list_append(all_node_list, tmp_node_struct);
+
+ while (node_list != NULL) {
+ tmp_node = (resource_node_t *)node_list->data;
+ if (tmp_node == NULL)
+ return AUL_RESOURCE_ERROR_IO_ERROR;
+
+ /* retrieve language value from each node */
+ b = tmp_node->attr;
+ if (b == NULL)
+ return AUL_RESOURCE_ERROR_IO_ERROR;
+ bundle_get_str(b, RSC_NODE_ATTR_LANGUAGE, &node_lang);
+ if (node_lang != NULL)
+ g_hash_table_add(supported_lang_list, strdup(node_lang));
+
+ memset(folder, '\0', MAX_PATH);
+ snprintf(folder, MAX_PATH - 1, "%s/", tmp_node->folder);
+
+ /* make struct and put it into all node list */
+ tmp_node_struct = (resource_node_list_t *)calloc(1, sizeof(resource_node_list_t));
+ if (tmp_node_struct == NULL) {
+ LOGE("calloc failed");
+ return AUL_RESOURCE_ERROR_OUT_OF_MEMORY;
+ }
+
+ tmp_node_struct->folder = strdup(folder);
+ tmp_node_struct->type = strdup(group_type);
+ all_node_list = g_list_prepend(all_node_list, tmp_node_struct);
+
+ node_list = g_list_next(node_list);
+ }
+ group_list = g_list_next(group_list);
+ }
+
+ __scan_dir(res_path, path_callback);
+
+ /* add language which is not existed to find default resources */
+ g_hash_table_add(supported_lang_list, strdup("NoLang"));
+ return AUL_RESOURCE_ERROR_NONE;
+}
+
+static void __free_str(gpointer data)
+{
+ if (data == NULL)
+ return;
+
+ char *char_data = (char *)data;
+ free(char_data);
+ data = NULL;
+}
+
+static int __init(const char *rsc_folder_path, bundle *b)
+{
+ if (rsc_folder_path != NULL && b != NULL)
+ is_slice = TRUE;
+ else
+ is_slice = FALSE;
+
+ if (resource_handle != NULL)
+ return AUL_RESOURCE_ERROR_NONE;
+
+ int retval = AUL_RESOURCE_ERROR_NONE;
+
+ res_path = _get_app_resource_path(rsc_folder_path);
+ if (res_path == NULL) {
+ LOGE("IO_ERROR(0x%08x), failed to get resource path",
+ AUL_RESOURCE_ERROR_IO_ERROR);
+ return AUL_RESOURCE_ERROR_IO_ERROR;
+ }
+
+ retval = __open(&resource_handle);
+ if (retval != AUL_RESOURCE_ERROR_NONE) {
+ LOGE("IO_ERROR(0x%08x), failed to get resource_handle(%d)",
+ AUL_RESOURCE_ERROR_IO_ERROR, retval);
+ return AUL_RESOURCE_ERROR_IO_ERROR;
+ }
+
+ if (attr_key == NULL) {
+ attr_key = g_hash_table_new(g_str_hash, g_str_equal);
+
+ if (attr_key == NULL)
+ return AUL_RESOURCE_ERROR_OUT_OF_MEMORY;
+
+ unsigned int i;
+ for (i = 0; i < ARRAY_SIZE(map); i++) {
+ g_hash_table_insert(attr_key, (char *)map[i].bundle_attr_key,
+ (gpointer)((uintptr_t)(map[i].bundle_attr_value)));
+ }
+ }
+
+ if (is_slice == FALSE) {
+ int r = vconf_notify_key_changed(VCONFKEY_LANGSET, __vconf_cb, NULL);
+
+ if (r < 0) {
+ LOGE("IO_ERROR(0x%08x), failed to register vconf(%d)",
+ AUL_RESOURCE_ERROR_IO_ERROR, r);
+ return AUL_RESOURCE_ERROR_IO_ERROR;
+ }
+ } else {
+ /* make ID list */
+ if (id_list == NULL)
+ id_list = g_hash_table_new_full(g_str_hash, g_str_equal, __free_str, __free_str);
+
+ if (supported_lang_list == NULL)
+ supported_lang_list = g_hash_table_new_full(g_str_hash, g_str_equal, __free_str, NULL);
+
+ if (valid_path_list == NULL)
+ valid_path_list = g_hash_table_new_full(g_str_hash, g_str_equal, __free_str, NULL);
+
+ retval = __make_list();
+ if (retval < 0) {
+ LOGE("Failed to initialize filelist");
+ return AUL_RESOURCE_ERROR_IO_ERROR;
+ }
+
+ retval = __set_valid_filelist(b);
+ if (retval < 0) {
+ LOGE("Failed to get valid filelist");
+ return AUL_RESOURCE_ERROR_IO_ERROR;
+ }
+
+ }
+
+ return AUL_RESOURCE_ERROR_NONE;
+}
+
+API int aul_resource_manager_init(void)
+{
+ return __init(NULL, NULL);
+}
+
+API int aul_resource_manager_init_slice(const char *rsc_folder_path, bundle *b)
+{
+ if (rsc_folder_path == NULL || b == NULL)
+ return AUL_RESOURCE_ERROR_INVALID_PARAMETER;
+
+ return __init(rsc_folder_path, b);
+}
+
+
+API int aul_resource_manager_get_path_list(GHashTable **list)
+{
+ if (is_slice == FALSE)
+ return AUL_RESOURCE_ERROR_IO_ERROR;
+
+ if (valid_path_list != NULL)
+ *list = valid_path_list;
+ else
+ return AUL_RESOURCE_ERROR_IO_ERROR;
+
+ return AUL_RESOURCE_ERROR_NONE;
+}
+
+static bool __verify_current_language(void)
+{
+ char *lang;
+
+ lang = vconf_get_str(VCONFKEY_LANGSET);
+ if (!lang)
+ return false;
+
+ if (cur_language && !strcmp(lang, cur_language)) {
+ free(lang);
+ return true;
+ }
+
+ free(lang);
+
+ return false;
+}
+
+API int aul_resource_manager_get(aul_resource_e type, const char *id, char **path)
+{
+ int retval = AUL_RESOURCE_ERROR_NONE;
+ char *put_fname = NULL;
+ const char *cached_path = NULL;
+ GList *list = NULL;
+ resource_group_t *resource_group = NULL;
+ resource_node_t *resource_node = NULL;
+
+ *path = NULL;
+
+ if (id == NULL) {
+ LOGE("INVALID_PARAMETER(0x%08x), resource_data_t",
+ AUL_RESOURCE_ERROR_INVALID_PARAMETER);
+ return AUL_RESOURCE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (type < AUL_RESOURCE_TYPE_MIN || type > AUL_RESOURCE_TYPE_MAX) {
+ LOGE("INVALID_PARAMETER(0x%08x), type(%d)",
+ AUL_RESOURCE_ERROR_INVALID_PARAMETER, type);
+ return AUL_RESOURCE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (is_slice == FALSE) {
+ if (resource_handle == NULL) {
+ retval = aul_resource_manager_init();
+ if (retval != AUL_RESOURCE_ERROR_NONE)
+ return retval;
+ }
+
+ if (__verify_current_language()) {
+ /* To get fname from cache */
+ cached_path = __get_cache(type, id);
+ if (cached_path != NULL) {
+ *path = strdup(cached_path);
+ return AUL_RESOURCE_ERROR_NONE;
+ }
+ } else {
+ __invalidate_cache();
+ }
+ }
+
+ if (resource_handle == NULL)
+ return AUL_RESOURCE_ERROR_IO_ERROR;
+
+ resource_group = __find_group(resource_handle->data, type);
+ if (resource_group == NULL) {
+ LOGE("IO_ERROR(0x%08x), failed to get resource_group",
+ AUL_RESOURCE_ERROR_IO_ERROR);
+ retval = AUL_RESOURCE_ERROR_IO_ERROR;
+ goto Exception;
+ }
+
+ list = __get_valid_nodes(resource_group, id);
+ if (list == NULL) {
+ retval = AUL_RESOURCE_ERROR_IO_ERROR;
+ goto Exception;
+ }
+
+ resource_node = __get_best_node(list);
+ if (resource_node == NULL) {
+ retval = AUL_RESOURCE_ERROR_IO_ERROR;
+ goto Exception;
+ } else {
+ unsigned int total_len = (unsigned int)(strlen(res_path)
+ + strlen(resource_node->folder)
+ + strlen(id) + 3);
+ put_fname = (char *) calloc(1, total_len);
+ if (!put_fname) {
+ if (list != NULL)
+ g_list_free(list);
+ return AUL_RESOURCE_ERROR_OUT_OF_MEMORY;
+ }
+ snprintf(put_fname, total_len, "%s%s/%s", res_path,
+ resource_node->folder, id);
+ *path = strdup(put_fname);
+ }
+
+ __put_cache(type, id, put_fname);
+
+
+Exception:
+ if (list != NULL)
+ g_list_free(list);
+
+ if (put_fname == NULL && resource_group != NULL) {
+ char path_buf[MAX_PATH] = { 0, };
+ char group_path_buf[MAX_PATH] = { 0, };
+
+ snprintf(path_buf, MAX_PATH - 1, "%s%s/%s", res_path,
+ resource_group->folder, id);
+ snprintf(group_path_buf, MAX_PATH - 1, "%s/%s", resource_group->folder, id);
+
+ list = g_list_first(resource_group->node_list);
+ while (list) {
+ resource_node = (resource_node_t *) list->data;
+ if (strncmp(group_path_buf, resource_node->folder, strlen(resource_node->folder)) == 0) {
+ *path = NULL;
+ return AUL_RESOURCE_ERROR_IO_ERROR;
+ }
+ list = g_list_next(list);
+ }
+
+ if (access(path_buf, R_OK) == 0) {
+ __put_cache(type, id, path_buf);
+ *path = strdup(path_buf);
+ retval = AUL_RESOURCE_ERROR_NONE;
+ }
+ }
+
+ if (put_fname != NULL)
+ free(put_fname);
+
+ return retval;
+}
+
+static void __free_node_folder_list(gpointer data)
+{
+ resource_node_list_t *node_data = (resource_node_list_t *)data;
+ if (node_data == NULL)
+ return;
+
+ if (node_data->folder != NULL) {
+ free(node_data->folder);
+ node_data->folder = NULL;
+ }
+
+ if (node_data->type != NULL) {
+ free(node_data->type);
+ node_data->type = NULL;
+ }
+
+ free(node_data);
+}
+
+API int aul_resource_manager_release(void)
+{
+ if (resource_handle != NULL) {
+ __close(resource_handle);
+ resource_handle = NULL;
+ }
+
+ if (attr_key != NULL) {
+ g_hash_table_destroy(attr_key);
+ attr_key = NULL;
+ }
+
+ if (cur_language) {
+ free(cur_language);
+ cur_language = NULL;
+ }
+
+ if (is_slice == FALSE)
+ vconf_ignore_key_changed(VCONFKEY_LANGSET, __vconf_cb);
+ else {
+ if (valid_path_list != NULL) {
+ g_hash_table_destroy(valid_path_list);
+ valid_path_list = NULL;
+ }
+
+ if (supported_lang_list != NULL) {
+ g_hash_table_destroy(supported_lang_list);
+ supported_lang_list = NULL;
+ }
+
+ if (id_list != NULL) {
+ g_hash_table_destroy(id_list);
+ id_list = NULL;
+ }
+
+ if (all_node_list != NULL) {
+ g_list_free_full(all_node_list, __free_node_folder_list);
+ all_node_list = NULL;
+ }
+ }
+ return AUL_RESOURCE_ERROR_NONE;
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 <stdlib.h>
+#include <string.h>
+
+#include <glib.h>
+#include <libxml/tree.h>
+#include <libxml/xmlschemas.h>
+
+#include <dlog.h>
+#include <bundle.h>
+
+#include "aul_rsc_mgr_internal.h"
+#include "aul_rsc_mgr_schema.h"
+
+static char *__get_attribute(xmlNode *xml_node, const char *name)
+{
+ xmlChar *val;
+ char *attr = NULL;
+
+ val = xmlGetProp(xml_node, (const xmlChar *)name);
+ if (val) {
+ attr = strdup((const char *)val);
+ xmlFree(val);
+ }
+
+ return attr;
+}
+
+static void __get_attribute_into_bundle(xmlNode *xml_node, const char *name,
+ bundle *b)
+{
+ char *attr;
+
+ attr = __get_attribute(xml_node, name);
+ if (attr) {
+ bundle_add_str(b, name, attr);
+ free(attr);
+ }
+}
+
+static int __parse_node(xmlNode *xml_node, GList **nodes)
+{
+ resource_node_t *node;
+
+ if (strcmp((char *)xml_node->name, "node"))
+ return -1;
+
+ node = calloc(1, sizeof(resource_node_t));
+ if (!node) {
+ LOGE("Out of memory");
+ return -1;
+ }
+
+ node->folder = __get_attribute(xml_node, "folder");
+ /* why we should use bundle here? */
+ node->attr = bundle_create();
+ if (node->attr == NULL) {
+ LOGE("Out of memory");
+ free(node->folder);
+ free(node);
+ return -1;
+ }
+
+ __get_attribute_into_bundle(xml_node, RSC_NODE_ATTR_SCREEN_DPI,
+ node->attr);
+ __get_attribute_into_bundle(xml_node, RSC_NODE_ATTR_SCREEN_DPI_RANGE,
+ node->attr);
+ __get_attribute_into_bundle(xml_node, RSC_NODE_ATTR_SCREEN_WIDTH_RANGE,
+ node->attr);
+ __get_attribute_into_bundle(xml_node, RSC_NODE_ATTR_SCREEN_LARGE,
+ node->attr);
+ __get_attribute_into_bundle(xml_node, RSC_NODE_ATTR_SCREEN_BPP,
+ node->attr);
+ __get_attribute_into_bundle(xml_node, RSC_NODE_ATTR_PLATFORM_VER,
+ node->attr);
+ __get_attribute_into_bundle(xml_node, RSC_NODE_ATTR_LANGUAGE,
+ node->attr);
+
+ *nodes = g_list_append(*nodes, node);
+
+ return 0;
+}
+
+static char *_get_group_type(xmlNode *xml_node)
+{
+ static const char delim[] = "-";
+ char *str;
+ char *tok;
+ char *ptr;
+
+ /* copy original string */
+ str = strdup((const char *)xml_node->name);
+ if (str == NULL) {
+ LOGE("Out of memory");
+ return NULL;
+ }
+
+ tok = strtok_r(str, delim, &ptr);
+ /* not a group element */
+ if (tok == NULL || strcmp(tok, "group")) {
+ free(str);
+ return NULL;
+ }
+
+ tok = strtok_r(NULL, delim, &ptr);
+ /* invalid element */
+ if (tok == NULL) {
+ free(str);
+ return NULL;
+ }
+
+ ptr = strdup(tok);
+ free(str);
+
+ return ptr;
+}
+
+static int __parse_group(xmlNode *xml_node, GList **groups)
+{
+ xmlNode *tmp;
+ char *type;
+ resource_group_t *group;
+
+ type = _get_group_type(xml_node);
+ if (type == NULL)
+ return -1;
+
+ group = calloc(1, sizeof(resource_group_t));
+ if (group == NULL) {
+ LOGE("Out of memory");
+ free(type);
+ return -1;
+ }
+
+ group->type = type;
+ group->folder = __get_attribute(xml_node, "folder");
+
+ for (tmp = xml_node->children; tmp; tmp = tmp->next) {
+ if (xml_node->type != XML_ELEMENT_NODE)
+ continue;
+ if (__parse_node(tmp, &group->node_list))
+ continue;
+ }
+
+ *groups = g_list_append(*groups, group);
+
+ return 0;
+}
+
+static int __parse_resource(xmlNode *xml_node, resource_data_t **data)
+{
+ xmlNode *tmp;
+
+ *data = calloc(1, sizeof(resource_data_t));
+ if (*data == NULL) {
+ LOGE("out of memory");
+ return -1;
+ }
+
+ for (tmp = xml_node->children; tmp; tmp = tmp->next) {
+ if (tmp->type != XML_ELEMENT_NODE)
+ continue;
+ __parse_group(tmp, &(*data)->group_list);
+ }
+
+ return 0;
+}
+
+static int __validate_schema(const char *path)
+{
+ xmlSchemaParserCtxt *parser_ctxt;
+ xmlSchema *schema;
+ xmlSchemaValidCtxt *valid_ctxt;
+ int ret;
+
+ parser_ctxt = xmlSchemaNewMemParserCtxt(res_schema, sizeof(res_schema));
+ if (parser_ctxt == NULL) {
+ LOGE("failed to create parser context");
+ return -1;
+ }
+
+ schema = xmlSchemaParse(parser_ctxt);
+ if (schema == NULL) {
+ LOGE("failed to create schema");
+ xmlSchemaFreeParserCtxt(parser_ctxt);
+ return -1;
+ }
+
+ valid_ctxt = xmlSchemaNewValidCtxt(schema);
+ if (valid_ctxt == NULL) {
+ LOGE("failed to create valid context");
+ xmlSchemaFree(schema);
+ xmlSchemaFreeParserCtxt(parser_ctxt);
+ return -1;
+ }
+
+ ret = xmlSchemaValidateFile(valid_ctxt, path, 0);
+ if (ret)
+ LOGE("%s: validation failed(%d)", path, ret);
+
+ xmlSchemaFreeValidCtxt(valid_ctxt);
+ xmlSchemaFree(schema);
+ xmlSchemaFreeParserCtxt(parser_ctxt);
+
+ return ret;
+}
+
+int _resource_open(const char *path, resource_data_t **data)
+{
+ int ret;
+ xmlDoc *doc;
+ xmlNode *root;
+
+ if (__validate_schema(path))
+ return -1;
+ doc = xmlReadFile(path, NULL, 0);
+ if (doc == NULL)
+ return -1;
+ root = xmlDocGetRootElement(doc);
+ if (!root) {
+ xmlFreeDoc(doc);
+ return -1;
+ }
+
+ ret = __parse_resource(root, data);
+
+ xmlFreeDoc(doc);
+
+ return ret;
+}
+
+static void __free_resource_node(gpointer data)
+{
+ resource_node_t *node = (resource_node_t *)data;
+
+ free(node->folder);
+ bundle_free(node->attr);
+ free(node);
+}
+
+static void __free_resource_group(gpointer data)
+{
+ resource_group_t *group = (resource_group_t *)data;
+
+ free(group->folder);
+ free(group->type);
+
+ g_list_free_full(group->node_list, __free_resource_node);
+
+ free(group);
+}
+
+int _resource_close(resource_data_t *data)
+{
+ /*
+ free(data->package);
+ */
+ g_list_free_full(data->group_list, __free_resource_group);
+
+ free(data);
+
+ return 0;
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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_RSC_MGR_INTERNAL_H__
+#define __AUL_RSC_MGR_INTERNAL_H__
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "AUL_RESOURCE_MANAGER"
+
+#define RSC_GROUP_TYPE_IMAGE "image"
+#define RSC_GROUP_TYPE_LAYOUT "layout"
+#define RSC_GROUP_TYPE_SOUND "sound"
+#define RSC_GROUP_TYPE_BIN "bin"
+
+#define RSC_NODE_ATTR_SCREEN_DPI "screen-dpi"
+#define RSC_NODE_ATTR_SCREEN_DPI_RANGE "screen-dpi-range"
+#define RSC_NODE_ATTR_SCREEN_WIDTH_RANGE "screen-width-range"
+#define RSC_NODE_ATTR_SCREEN_LARGE "screen-large"
+#define RSC_NODE_ATTR_SCREEN_BPP "screen-bpp"
+#define RSC_NODE_ATTR_PLATFORM_VER "platform-version"
+#define RSC_NODE_ATTR_LANGUAGE "language"
+
+typedef struct {
+ char *folder;
+ bundle *attr;
+} resource_node_t;
+
+typedef struct {
+ char *folder;
+ char *type;
+ GList *node_list;
+} resource_group_t;
+
+typedef struct {
+ char *package;
+ GList *group_list;
+} resource_data_t;
+
+int _resource_open(const char *path, resource_data_t **data);
+int _resource_close(resource_data_t *data);
+
+#endif
--- /dev/null
+#ifndef __AUL_RSC_MGR_SCHEMA_H__
+#define __AUL_RSC_MGR_SCHEMA_H__
+
+static const char res_schema[] =
+"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" elementFormDefault=\"qualified\" targetNamespace=\"http://tizen.org/ns/rm\" xmlns:packages=\"http://tizen.org/ns/rm\">"
+" <xs:import namespace=\"http://www.w3.org/XML/1998/namespace\"/>"
+" <xs:element name=\"res\">"
+" <xs:complexType>"
+" <xs:all>"
+" <xs:element name=\"group-image\" type=\"packages:GroupContainer\" maxOccurs=\"1\" minOccurs=\"0\"/>"
+" <xs:element name=\"group-layout\" type=\"packages:GroupContainer\" maxOccurs=\"1\" minOccurs=\"0\"/>"
+" <xs:element name=\"group-sound\" type=\"packages:GroupContainer\" maxOccurs=\"1\" minOccurs=\"0\"/>"
+" <xs:element name=\"group-bin\" type=\"packages:GroupContainer\" maxOccurs=\"1\" minOccurs=\"0\"/>"
+" </xs:all>"
+" </xs:complexType>"
+" </xs:element>"
+" <xs:complexType name=\"GroupContainer\">"
+" <xs:sequence>"
+" <xs:element name=\"node\" maxOccurs=\"unbounded\" minOccurs=\"0\">"
+" <xs:complexType>"
+" <xs:attribute name=\"folder\" type=\"xs:string\" use=\"required\"/>"
+" <xs:attribute name=\"screen-dpi\" type=\"xs:integer\"/>"
+" <xs:attribute name=\"screen-dpi-range\" type=\"xs:string\"/>"
+" <xs:attribute name=\"screen-width-range\" type=\"xs:string\"/>"
+" <xs:attribute name=\"screen-large\" type=\"xs:boolean\"/>"
+" <xs:attribute name=\"screen-bpp\" type=\"xs:integer\"/>"
+" <xs:attribute name=\"platform-version\" type=\"xs:string\"/>"
+" <xs:attribute name=\"language\" type=\"xs:string\"/>"
+" </xs:complexType>"
+" </xs:element>"
+" </xs:sequence>"
+" <xs:attribute name=\"folder\" type=\"xs:string\" use=\"required\"/>"
+" </xs:complexType>"
+"</xs:schema>";
+
+#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.
+ *
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <bundle_internal.h>
+#include <glib.h>
+
+#include "aul_api.h"
+#include "aul_cmd.h"
+#include "aul_error.h"
+#include "aul_running_context.h"
+#include "aul_sock.h"
+#include "aul_util.h"
+
+struct aul_running_context_s {
+ char *app_id;
+ char *comp_id;
+ char *inst_id;
+ int pid;
+};
+
+static void __destroy_running_context(gpointer data)
+{
+ struct aul_running_context_s *context = data;
+
+ free(context->inst_id);
+ free(context->comp_id);
+ free(context->app_id);
+ free(context);
+}
+
+static struct aul_running_context_s *__create_running_context(bundle *b)
+{
+ struct aul_running_context_s *context;
+ const char *val;
+
+ context = calloc(1, sizeof(struct aul_running_context_s));
+ if (!context) {
+ _E("Out of memory");
+ return NULL;
+ }
+
+ val = bundle_get_val(b, AUL_K_APPID);
+ if (val)
+ context->app_id = strdup(val);
+
+ val = bundle_get_val(b, AUL_K_COMPONENT_ID);
+ if (val)
+ context->comp_id = strdup(val);
+
+ val = bundle_get_val(b, AUL_K_INSTANCE_ID);
+ if (val)
+ context->inst_id = strdup(val);
+
+ val = bundle_get_val(b, AUL_K_PID);
+ if (val)
+ context->pid = atoi(val);
+
+ return context;
+}
+
+static bundle *__create_bundle(const char *app_id,
+ const char *comp_id,
+ const char *inst_id)
+{
+ bundle *b;
+
+ b = bundle_create();
+ if (!b) {
+ _E("Out of memory");
+ return NULL;
+ }
+
+ bundle_add(b, AUL_K_APPID, app_id);
+
+ if (comp_id)
+ bundle_add(b, AUL_K_COMPONENT_ID, comp_id);
+
+ if (inst_id)
+ bundle_add(b, AUL_K_INSTANCE_ID, inst_id);
+
+ return b;
+}
+
+API int aul_running_context_create(const char *app_id,
+ const char *comp_id,
+ const char *inst_id,
+ aul_running_context_h *handle)
+{
+ struct aul_running_context_s *context;
+ app_pkt_t *pkt = NULL;
+ bundle *b;
+ int ret;
+ int fd;
+
+ if (!app_id || !handle) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ b = __create_bundle(app_id, comp_id, inst_id);
+ if (!b)
+ return AUL_R_ENOMEM;
+
+ fd = aul_sock_send_bundle(AUL_UTIL_PID, getuid(),
+ APP_GET_RUNNING_CONTEXT,
+ b, AUL_SOCK_ASYNC);
+ bundle_free(b);
+ if (fd <= 0) {
+ _E("Failed to send the request. error(%d)", fd);
+ return aul_error_convert(fd);
+ }
+
+ ret = aul_sock_recv_reply_pkt(fd, &pkt);
+ if (ret < 0 || pkt == NULL) {
+ _E("Failed to get reply. error(%d)", ret);
+ return aul_error_convert(ret);
+ }
+
+ if (pkt->cmd != APP_GET_INFO_OK) {
+ _E("Failed to get running context. error(%d)", pkt->cmd);
+ ret = aul_error_convert(pkt->cmd);
+ free(pkt);
+ return ret;
+ }
+
+ if (!(pkt->opt & AUL_SOCK_BUNDLE)) {
+ _E("Invalid protocol");
+ free(pkt);
+ return AUL_R_ERROR;
+ }
+
+ b = bundle_decode(pkt->data, pkt->len);
+ free(pkt);
+ if (!b) {
+ _E("Failed to decode bundle data");
+ return AUL_R_ERROR;
+ }
+
+ context = __create_running_context(b);
+ bundle_free(b);
+ if (!context) {
+ _E("Failed to create running context");
+ return AUL_R_ENOMEM;
+ }
+
+ *handle = context;
+
+ return AUL_R_OK;
+}
+
+API int aul_running_context_destroy(aul_running_context_h handle)
+{
+ if (!handle) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ __destroy_running_context(handle);
+
+ return AUL_R_OK;
+}
+
+API int aul_running_context_get_app_id(aul_running_context_h handle,
+ const char **app_id)
+{
+ if (!handle || !app_id) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ *app_id = handle->app_id;
+
+ return AUL_R_OK;
+}
+
+API int aul_running_context_get_comp_id(aul_running_context_h handle,
+ const char **comp_id)
+{
+ if (!handle || !comp_id) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ *comp_id = handle->comp_id;
+
+ return AUL_R_OK;
+}
+
+API int aul_running_context_get_inst_id(aul_running_context_h handle,
+ const char **inst_id)
+{
+ if (!handle || !inst_id) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ *inst_id = handle->inst_id;
+
+ return AUL_R_OK;
+}
+
+API int aul_running_context_get_pid(aul_running_context_h handle,
+ int *pid)
+{
+ if (!handle || !pid) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ *pid = handle->pid;
+
+ return AUL_R_OK;
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 <stdbool.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <glib.h>
+#include <bundle.h>
+#include <bundle_internal.h>
+
+#include "aul_util.h"
+#include "aul_api.h"
+#include "aul.h"
+#include "aul_sock.h"
+#include "aul_app_com.h"
+#include "aul_screen_connector.h"
+
+struct aul_screen_viewer_s {
+ aul_app_com_connection_h conn;
+ aul_screen_viewer_cb callback;
+ aul_screen_type_e type;
+ bool priv;
+ unsigned int ref;
+ void *user_data;
+};
+
+static unsigned int ref;
+
+static unsigned int __get_ref(void)
+{
+ return ++ref;
+}
+
+static int __add_screen_viewer(int type, bool priv, unsigned int ref)
+{
+ int ret;
+ bundle *b;
+ char buf[MAX_PID_STR_BUFSZ];
+
+ b = bundle_create();
+ if (b == NULL) {
+ _E("out of memory");
+ return -1;
+ }
+
+ snprintf(buf, sizeof(buf), "%d", type);
+ ret = bundle_add(b, AUL_K_SCREEN_TYPE, buf);
+ if (ret != BUNDLE_ERROR_NONE) {
+ _E("Failed to add screen type(%d)", type);
+ bundle_free(b);
+ return -1;
+ }
+
+ snprintf(buf, sizeof(buf), "%u", ref);
+ ret = bundle_add(b, AUL_K_VIEWER_REF, buf);
+ if (ret != BUNDLE_ERROR_NONE) {
+ _E("Failed to add viewer reference(%u)", ref);
+ bundle_free(b);
+ return -1;
+ }
+
+ if (priv) {
+ ret = bundle_add(b, AUL_K_PRIVATE, "true");
+ if (ret != BUNDLE_ERROR_NONE) {
+ _E("Failed to add bundle data");
+ bundle_free(b);
+ return -1;
+ }
+ }
+
+ ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(),
+ ADD_SCREEN_VIEWER, b, AUL_SOCK_NOREPLY);
+ bundle_free(b);
+ if (ret < 0)
+ return -1;
+
+ return 0;
+}
+
+static int __remove_screen_viewer(int type, bool priv, unsigned int ref)
+{
+ int ret;
+ bundle *b;
+ char buf[MAX_PID_STR_BUFSZ];
+
+ b = bundle_create();
+ if (b == NULL) {
+ _E("out of memory");
+ return -1;
+ }
+
+ snprintf(buf, sizeof(buf), "%d", type);
+ ret = bundle_add(b, AUL_K_SCREEN_TYPE, buf);
+ if (ret != BUNDLE_ERROR_NONE) {
+ _E("Failed to add view mode");
+ bundle_free(b);
+ return -1;
+ }
+
+ snprintf(buf, sizeof(buf), "%u", ref);
+ ret = bundle_add(b, AUL_K_VIEWER_REF, buf);
+ if (ret != BUNDLE_ERROR_NONE) {
+ _E("Failed to add viewer reference(%u)", ref);
+ bundle_free(b);
+ return -1;
+ }
+
+ if (priv) {
+ ret = bundle_add(b, AUL_K_PRIVATE, "true");
+ if (ret != BUNDLE_ERROR_NONE) {
+ _E("Failed to add bundle data");
+ bundle_free(b);
+ return -1;
+ }
+ }
+
+ ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(),
+ REMOVE_SCREEN_VIEWER, b, AUL_SOCK_NOREPLY);
+ bundle_free(b);
+ if (ret < 0)
+ return -1;
+
+ return 0;
+}
+
+static int __app_screen_event_cb(const char *endpoint, aul_app_com_result_e res,
+ bundle *envelope, void *user_data)
+{
+ aul_screen_viewer_h handle = (aul_screen_viewer_h)user_data;
+ char *appid = NULL;
+ char *instance_id = NULL;
+ unsigned int *surf = NULL;
+ int *pid = NULL;
+ size_t size;
+ char *event = NULL;
+ aul_screen_connector_event_type_e event_type;
+
+ bundle_get_str(envelope, "__AUL_SC_EVENT__", &event);
+ if (event == NULL) {
+ _E("Failed to get screen connector event");
+ return -1;
+ } else if (strcmp(event, "add_screen") == 0) {
+ event_type = AUL_SCREEN_CONNECTOR_EVENT_TYPE_ADD;
+ } else if (strcmp(event, "remove_screen") == 0) {
+ event_type = AUL_SCREEN_CONNECTOR_EVENT_TYPE_REMOVE;
+ } else if (strcmp(event, "update_screen") == 0) {
+ event_type = AUL_SCREEN_CONNECTOR_EVENT_TYPE_UPDATE;
+ } else if (strcmp(event, "focus_screen") == 0) {
+ event_type = AUL_SCREEN_CONNECTOR_EVENT_TYPE_FOCUS;
+ } else {
+ _E("Unknown event type(%s)", event);
+ return -1;
+ }
+
+ bundle_get_str(envelope, "__AUL_SC_APPID__", &appid);
+ if (appid == NULL) {
+ _E("Failed to get appid");
+ return -1;
+ }
+
+ bundle_get_byte(envelope, "__AUL_SC_SURFACE__",
+ (void **)&surf, &size);
+ if (surf == NULL) {
+ _E("Failed to get surface");
+ return -1;
+ }
+
+ bundle_get_byte(envelope, "__AUL_SC_PID__", (void **)&pid, &size);
+ if (pid == NULL) {
+ _E("Failed to get pid");
+ return -1;
+ }
+ bundle_get_str(envelope, "__AUL_SC_INSTANCE_ID__", &instance_id);
+
+ if (handle->callback) {
+ handle->callback(appid, instance_id, *pid, *surf,
+ event_type, handle->user_data);
+ }
+ _D("appid(%s), instance_id(%s), pid(%d), surface(%d), event_type(%d)",
+ appid, instance_id, *pid, *surf, event_type);
+
+ return 0;
+}
+
+static int __screen_viewer_fini(aul_screen_viewer_h screen_viewer)
+{
+ int ret;
+
+ if (screen_viewer->conn) {
+ aul_app_com_leave(screen_viewer->conn);
+ screen_viewer->conn = NULL;
+ }
+
+ ret = __remove_screen_viewer(screen_viewer->type, screen_viewer->priv,
+ screen_viewer->ref);
+ if (ret < 0) {
+ _E("Failed to remove screen watcher");
+ return -1;
+ }
+
+ return 0;
+}
+
+static int __screen_viewer_init(aul_screen_viewer_h screen_viewer)
+{
+ int ret;
+ char endpoint[128];
+ pid_t pid = getpid();
+
+ snprintf(endpoint, sizeof(endpoint), "app_screen_event:%u:%d",
+ screen_viewer->ref, pid);
+ aul_app_com_create(endpoint, NULL, __app_screen_event_cb,
+ screen_viewer, &screen_viewer->conn);
+ if (screen_viewer->conn == NULL) {
+ _E("Failed to create app com");
+ return -1;
+ }
+
+ ret = __add_screen_viewer(screen_viewer->type, screen_viewer->priv,
+ screen_viewer->ref);
+ if (ret < 0) {
+ _E("Failed to add screen watcher");
+ return -1;
+ }
+
+ return 0;
+}
+
+API int aul_screen_connector_add_screen_viewer(aul_screen_viewer_cb callback,
+ aul_screen_type_e type, bool priv,
+ void *data, aul_screen_viewer_h *handle)
+{
+ struct aul_screen_viewer_s *screen_viewer;
+
+ if (handle == NULL || callback == NULL ||
+ !(type & AUL_SCREEN_TYPE_ALL)) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ screen_viewer = (struct aul_screen_viewer_s *)calloc(1,
+ sizeof(struct aul_screen_viewer_s));
+ if (screen_viewer == NULL) {
+ _E("Out of memory");
+ return AUL_R_EINVAL;
+ }
+
+ screen_viewer->callback = callback;
+ screen_viewer->type = type;
+ screen_viewer->priv = priv;
+ screen_viewer->ref = __get_ref();
+ screen_viewer->user_data = data;
+
+ if (__screen_viewer_init(screen_viewer) < 0) {
+ __screen_viewer_fini(screen_viewer);
+ free(screen_viewer);
+ return AUL_R_ERROR;
+ }
+ *handle = screen_viewer;
+
+ return AUL_R_OK;
+}
+
+API int aul_screen_connector_remove_screen_viewer(aul_screen_viewer_h handle)
+{
+ if (handle == NULL)
+ return AUL_R_EINVAL;
+
+ __screen_viewer_fini(handle);
+ free(handle);
+
+ return AUL_R_OK;
+}
+
+API int aul_screen_connector_add_app_screen(const char *instance_id,
+ unsigned int surf)
+{
+ int ret;
+ bundle *b;
+ char buf[MAX_PID_STR_BUFSZ];
+
+ b = bundle_create();
+ if (b == NULL) {
+ _E("out of memory");
+ return AUL_R_ERROR;
+ }
+
+ snprintf(buf, sizeof(buf), "%d", surf);
+ ret = bundle_add(b, AUL_K_WID, buf);
+ if (ret != BUNDLE_ERROR_NONE) {
+ _E("Failed to add surf");
+ bundle_free(b);
+ return AUL_R_ERROR;
+ }
+
+ if (instance_id) {
+ ret = bundle_add(b, AUL_K_INSTANCE_ID, instance_id);
+ if (ret != BUNDLE_ERROR_NONE) {
+ _E("Failed to add instance id");
+ bundle_free(b);
+ return AUL_R_ERROR;
+ }
+ }
+
+ ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(),
+ ADD_APP_SCREEN, b, AUL_SOCK_NOREPLY);
+ bundle_free(b);
+ if (ret < 0) {
+ _E("Failed to add app screen");
+ return ret;
+ }
+
+ return AUL_R_OK;
+}
+
+API int aul_screen_connector_remove_app_screen(const char *instance_id)
+{
+ int ret;
+ bundle *b;
+
+ b = bundle_create();
+ if (b == NULL) {
+ _E("out of memory");
+ return AUL_R_ERROR;
+ }
+
+ if (instance_id) {
+ ret = bundle_add(b, AUL_K_INSTANCE_ID, instance_id);
+ if (ret != BUNDLE_ERROR_NONE) {
+ _E("Failed to add instance id");
+ bundle_free(b);
+ return AUL_R_ERROR;
+ }
+ }
+
+ ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(),
+ REMOVE_APP_SCREEN, b, AUL_SOCK_NOREPLY);
+ bundle_free(b);
+ if (ret < 0) {
+ _E("Failed to remove app screen");
+ return ret;
+ }
+
+ return AUL_R_OK;
+}
+
+API int aul_screen_connector_send_update_request(const char *appid,
+ const char *instance_id)
+{
+ int ret;
+ bundle *b;
+
+ if (appid == NULL) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ b = bundle_create();
+ if (b == NULL) {
+ _E("out of memory");
+ return AUL_R_ERROR;
+ }
+
+ ret = bundle_add(b, AUL_K_APPID, appid);
+ if (ret != BUNDLE_ERROR_NONE) {
+ _E("Failed to add appid");
+ bundle_free(b);
+ return AUL_R_ERROR;
+ }
+
+ if (instance_id) {
+ ret = bundle_add(b, AUL_K_INSTANCE_ID, instance_id);
+ if (ret != BUNDLE_ERROR_NONE) {
+ _E("Failed to add instance id");
+ bundle_free(b);
+ return AUL_R_ERROR;
+ }
+ }
+
+ ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(),
+ APP_UPDATE_REQUESTED, b, AUL_SOCK_NOREPLY);
+ bundle_free(b);
+ if (ret < 0) {
+ _E("Failed to update app screen");
+ return ret;
+ }
+
+ return AUL_R_OK;
+}
+
+static bundle *__send_request_with_surface_id(int cmd, unsigned int surface_id)
+{
+ app_pkt_t *pkt = NULL;
+ bundle *b;
+ int fd;
+ int r;
+
+ b = bundle_create();
+ if (b == NULL) {
+ _E("Out of memory");
+ return NULL;
+ }
+
+ r = bundle_add_byte(b, "__AUL_SC_SURFACE__",
+ &surface_id, sizeof(unsigned int));
+ if (r != BUNDLE_ERROR_NONE) {
+ _E("Failed to add surface id(%u)", surface_id);
+ bundle_free(b);
+ return NULL;
+ }
+
+ fd = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), cmd, b,
+ AUL_SOCK_ASYNC);
+ bundle_free(b);
+ if (fd < 0) {
+ _E("Failed to send request(%d)", cmd);
+ return NULL;
+ }
+
+ aul_sock_recv_reply_pkt(fd, &pkt);
+ if (pkt == NULL) {
+ _E("Failed to receive the packet");
+ return NULL;
+ }
+
+ b = bundle_decode(pkt->data, pkt->len);
+ free(pkt);
+ if (b == NULL) {
+ _E("Failed to decode bundle data");
+ return NULL;
+ }
+
+ return b;
+}
+
+API int aul_screen_connector_get_appid_by_surface_id(unsigned int surface_id,
+ char **appid)
+{
+ const char *val;
+ bundle *b;
+
+ if (appid == NULL) {
+ _E("Invalid parameter");
+ return AUL_R_ERROR;
+ }
+
+ b = __send_request_with_surface_id(APP_GET_APPID_BY_SURFACE_ID,
+ surface_id);
+ if (b == NULL)
+ return AUL_R_ERROR;
+
+ val = bundle_get_val(b, AUL_K_APPID);
+ if (val == NULL) {
+ _E("Failed to get appid");
+ bundle_free(b);
+ return AUL_R_ERROR;
+ }
+
+ *appid = strdup(val);
+ if (*appid == NULL) {
+ _E("Out of memory");
+ bundle_free(b);
+ return AUL_R_ERROR;
+ }
+ bundle_free(b);
+
+ return AUL_R_OK;
+}
+
+API int aul_screen_connector_get_instance_id_by_surface_id(
+ unsigned int surface_id, char **instance_id)
+{
+ const char *val;
+ bundle *b;
+
+ if (instance_id == NULL) {
+ _E("Invalid parameter");
+ return AUL_R_ERROR;
+ }
+
+ b = __send_request_with_surface_id(APP_GET_INSTANCE_ID_BY_SURFACE_ID,
+ surface_id);
+ if (b == NULL)
+ return AUL_R_ERROR;
+
+ val = bundle_get_val(b, AUL_K_INSTANCE_ID);
+ if (val == NULL) {
+ _E("Failed to get instance id");
+ bundle_free(b);
+ return AUL_R_ERROR;
+ }
+
+ *instance_id = strdup(val);
+ if (*instance_id == NULL) {
+ _E("Out of memory");
+ bundle_free(b);
+ return AUL_R_ERROR;
+ }
+ bundle_free(b);
+
+ return AUL_R_OK;
+}
+
+
+API int aul_screen_connector_update_screen_viewer_status(
+ aul_screen_status_e status, unsigned int provider_surf)
+{
+ char buf[32];
+ bundle *b;
+ int ret;
+
+ if (status < AUL_SCREEN_STATUS_RESUME ||
+ status > AUL_SCREEN_STATUS_PAUSE) {
+ _E("Invalid parameter");
+ return AUL_R_ERROR;
+ }
+
+ b = bundle_create();
+ if (b == NULL) {
+ _E("Out of memory");
+ return AUL_R_ERROR;
+ }
+
+ snprintf(buf, sizeof(buf), "%u", provider_surf);
+ ret = bundle_add(b, AUL_K_WID, buf);
+ if (ret != BUNDLE_ERROR_NONE) {
+ _E("Failed to add provider surface id");
+ bundle_free(b);
+ return AUL_R_ERROR;
+ }
+
+ snprintf(buf, sizeof(buf), "%d", status);
+ ret = bundle_add(b, "__AUL_SC_VIEWER_STATUS__", buf);
+ if (ret != BUNDLE_ERROR_NONE) {
+ _E("Failed to add screen status");
+ bundle_free(b);
+ return AUL_R_ERROR;
+ }
+
+ ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(),
+ UPDATE_SCREEN_VIEWER_STATUS, b, AUL_SOCK_NOREPLY);
+ bundle_free(b);
+
+ return ret;
+}
+
+API int aul_screen_connector_trigger_focused_force(void)
+{
+ int ret;
+ char buf[MAX_PID_STR_BUFSZ];
+ bundle *b;
+
+ b = bundle_create();
+ if (b == NULL) {
+ _E("out of memory");
+ return -1;
+ }
+
+ snprintf(buf, sizeof(buf), "%d", AUL_SCREEN_TYPE_UI);
+ ret = bundle_add(b, AUL_K_SCREEN_TYPE, buf);
+ if (ret != BUNDLE_ERROR_NONE) {
+ _E("Failed to add view mode");
+ bundle_free(b);
+ return -1;
+ }
+
+ ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(),
+ TRIGGER_APP_SCREEN_FOCUSED_FORCE, b, AUL_SOCK_NOREPLY);
+ bundle_free(b);
+
+ return ret;
+}
--- /dev/null
+/*
+ * Copyright (c) 2000 - 2022 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 "aul/include/aul_sock.h"
+
+#include <bundle_cpp.h>
+#include <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <glib.h>
+#include <libgen.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <tzplatform_config.h>
+#include <unistd.h>
+#include <vconf.h>
+
+#include "aul/aul_api.h"
+#include "aul/aul_util.h"
+#include "aul/cpu_inheritance.hh"
+#include "aul/include/aul_key.h"
+#include "aul/socket/client_socket.hh"
+#include "aul/socket/packet.hh"
+#include "aul/socket/server_socket.hh"
+
+using namespace aul;
+
+namespace {
+
+constexpr const int MAX_NR_OF_DESCRIPTORS = 2;
+constexpr const int MAX_PAYLOAD_SIZE = 1024 * 1024 * 1;
+constexpr const char PATH_AUL_SOCKET_TIMEOUT[] = "/run/aul/.socket_timeout";
+constexpr const char PATH_AMD_SOCK[] = "/run/aul/daemons/.amd-sock";
+
+constexpr unsigned int SOCKET_TIMEOUT_MIN = 5000U;
+constexpr unsigned int SOCKET_TIMEOUT_MAX = 30000U;
+
+// POD type
+struct PacketHeader {
+ int cmd;
+ int len;
+ int opt;
+};
+
+class SocketTimeout {
+ public:
+ SocketTimeout() = default;
+
+ ~SocketTimeout() {
+ if (initialized_)
+ vconf_ignore_key_changed(VCONFKEY_AUL_SOCKET_TIMEOUT, VconfCb);
+ }
+
+ timeval GetTimeval() const {
+ return time_val_;
+ }
+
+ bool IsInitialized() const {
+ return initialized_;
+ }
+
+ void Init() {
+ if (access(PATH_AUL_SOCKET_TIMEOUT, F_OK) != 0) {
+ initialized_ = true;
+ return;
+ }
+
+ double timeout = 5.2f;
+ int ret = vconf_get_dbl(VCONFKEY_AUL_SOCKET_TIMEOUT, &timeout);
+ if (ret != VCONF_OK)
+ _E("vconf_get_dbl() is failed. error(%d)", ret);
+
+ ret = vconf_notify_key_changed(VCONFKEY_AUL_SOCKET_TIMEOUT, VconfCb, this);
+ if (ret != VCONF_OK)
+ _E("vconf_notify_key_changed() is failed. error(%d)", ret);
+
+ SetTimeout(timeout);
+ initialized_ = true;
+ }
+
+ private:
+ static void VconfCb(keynode_t* node, void* user_data) {
+ auto* h = static_cast<SocketTimeout*>(user_data);
+ double timeout = vconf_keynode_get_dbl(node);
+ h->SetTimeout(timeout);
+ }
+
+ void SetTimeout(double timeout) {
+ char buf[12];
+ snprintf(buf, sizeof(buf), "%.3f", timeout);
+ gchar* ptr = nullptr;
+ time_val_.tv_sec = g_ascii_strtoll(buf, &ptr, 10);
+ time_val_.tv_usec = g_ascii_strtoll(ptr + 1, &ptr, 10) * 1000;
+ }
+
+ private:
+ bool initialized_ = false;
+ timeval time_val_ = { 5, 200 * 1000 };
+};
+
+std::string GetSocketPath(pid_t pid, uid_t uid) {
+ if (pid == -2)
+ return std::string(PATH_AMD_SOCK);
+
+ char path[108];
+ if (uid < REGULAR_UID_MIN)
+ snprintf(path, sizeof(path), "/run/aul/daemons/%u/.app-sock-%d", uid, pid);
+ else
+ snprintf(path, sizeof(path), "/run/aul/apps/%u/%d/.app-sock", uid, pid);
+
+ return std::string(path);
+}
+
+int CreateSocketDirectory(pid_t pid, uid_t uid) {
+ std::string socket_path = GetSocketPath(pid, uid);
+ std::string path = dirname(const_cast<char*>(socket_path.c_str()));
+ if (mkdir(path.c_str(), 0700) != 0) {
+ if (errno == EEXIST) {
+ if (access(path.c_str(), R_OK) != 0) {
+ _E("access() is failed. path(%s), errno(%d)", path.c_str(), errno);
+ return -1;
+ }
+ } else {
+ _E("mkdir() is failed. path(%s), errno(%d)", path.c_str(), errno);
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+class SocketLink {
+ public:
+ SocketLink() = default;
+
+ void Create(const std::string& socket_path, pid_t pid, uid_t uid) {
+ if (CreateSocketDirectory(pid, uid) != 0)
+ return;
+
+ path_ = GetSocketPath(pid, uid);
+ if (link(socket_path.c_str(), path_.c_str()) != 0) {
+ _E("link() is failed. old(%s), new(%s), errno(%d)",
+ socket_path.c_str(), path_.c_str(), errno);
+ }
+
+ created_ = true;
+ }
+
+ void Delete() {
+ if (!created_)
+ return;
+
+ unlink(path_.c_str());
+ created_ = false;
+ }
+
+ private:
+ bool created_ = false;
+ std::string path_;
+};
+
+int SendAndReceive(ClientSocket* client, int cmd, unsigned char* data,
+ int datalen, int opt) {
+ _D("fd(%d), cmd(%d)", client->GetFd(), cmd);
+
+ Packet packet(cmd, opt, { data, data + datalen });
+ tizen_base::Parcel parcel;
+ parcel.WriteParcelable(packet);
+
+ int ret = client->Send(parcel.GetData(), parcel.GetDataSize());
+ if (ret != 0 || opt & AUL_SOCK_NOREPLY) {
+ if (!(opt & AUL_SOCK_ASYNC))
+ client->Close();
+
+ return ret;
+ }
+
+ if (opt & AUL_SOCK_ASYNC)
+ return client->RemoveFd();
+
+ int res;
+ ret = client->Receive(reinterpret_cast<void*>(&res), sizeof(res));
+ if (ret < 0)
+ res = ret;
+
+ return res;
+}
+
+int SendAndReceive(int fd, int cmd, unsigned char* data, int datalen,
+ int opt) {
+ ClientSocket client(fd);
+ int ret = SendAndReceive(&client, cmd, data, datalen, opt);
+ if (ret < 0) {
+ if (opt & AUL_SOCK_ASYNC)
+ client.RemoveFd();
+ }
+
+ return ret;
+}
+
+int SendAndReceive(int pid, uid_t uid, int cmd, unsigned char* data,
+ int datalen, int opt) {
+ int ret;
+ try {
+ ClientSocket client;
+ std::string endpoint = GetSocketPath(pid, uid);
+ client.Connect(endpoint);
+ aul_sock_set_sock_option(client.GetFd(), 1);
+
+ const auto& inherit = internal::CPUInheritance(pid, cmd);
+ ret = SendAndReceive(&client, cmd, data, datalen, opt);
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%d)", e.GetErrorCode());
+ return -ECOMM;
+ }
+
+ return ret;
+}
+
+int SendAndReceiveWithTimeout(int pid, uid_t uid, int cmd, unsigned char* data,
+ int datalen, int opt, int timeout) {
+ int ret;
+ try {
+ ClientSocket client;
+ client.Connect(GetSocketPath(pid, uid));
+ aul_sock_set_sock_option(client.GetFd(), 1);
+ _W("timeout: %dms", timeout);
+ client.SetReceiveTimeout(timeout);
+
+ const auto& inherit = internal::CPUInheritance(pid, cmd);
+ ret = SendAndReceive(&client, cmd, data, datalen, opt);
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%d)", e.GetErrorCode());
+ return -ECOMM;
+ }
+
+ return ret;
+}
+
+int ReceiveAppPacket(ClientSocket* client, app_pkt_t** out_pkt) {
+ PacketHeader header;
+ static_assert(std::is_standard_layout<PacketHeader>(),
+ "PacketHeader should be POD type");
+ static_assert(std::is_trivial<PacketHeader>(),
+ "Header should be POD type");
+
+ *out_pkt = nullptr;
+ int ret = client->Receive(&header, sizeof(header));
+ if (ret < 0)
+ return ret;
+
+ if (header.len < 0 || header.len > MAX_PAYLOAD_SIZE) {
+ _E("Invalid packet. length(%d)", header.len);
+ return -ECOMM;
+ }
+
+ app_pkt_t* pkt = static_cast<app_pkt_t*>(
+ calloc(1, sizeof(app_pkt_t) + header.len));
+ if (pkt == nullptr) {
+ _E("Out of memory");
+ return -ENOMEM;
+ }
+
+ pkt->cmd = header.cmd;
+ pkt->len = header.len;
+ pkt->opt = header.opt;
+
+ ret = client->Receive(pkt->data, pkt->len);
+ if (ret < 0) {
+ free(pkt);
+ return ret;
+ }
+
+ *out_pkt = pkt;
+ return 0;
+}
+
+int GetFileDescriptor(struct cmsghdr* cmsg, struct msghdr* msg, int* fds,
+ int maxdesc) {
+ if (cmsg == nullptr || msg == nullptr)
+ return 0;
+
+ if (cmsg->cmsg_type != SCM_RIGHTS)
+ return 0;
+
+ int retnr = 0;
+ if (msg->msg_controllen > 0) {
+ int payload = cmsg->cmsg_len - sizeof(*cmsg);
+ int* recvdesc = reinterpret_cast<int*>(CMSG_DATA(cmsg));
+ int nrdesc = payload / sizeof(int);
+ retnr = nrdesc < maxdesc ? nrdesc : maxdesc;
+ for (int i = 0; i < nrdesc; ++i) {
+ if (maxdesc-- > 0)
+ *fds++ = *recvdesc++;
+ else
+ close(*recvdesc++);
+ }
+ }
+
+ return retnr;
+}
+
+int ReceiveMessage(int fd, struct iovec* vec, size_t vec_max_size,
+ int* vec_size, int* fds, int* nr_fds) {
+ if (vec == nullptr || vec_max_size < 1 || vec_size == nullptr)
+ return -EINVAL;
+
+ char buf[CMSG_SPACE(sizeof(int) * MAX_NR_OF_DESCRIPTORS) + CMSG_SPACE(50)] = { 0, };
+ struct msghdr msg = { 0, };
+ msg.msg_iov = vec;
+ msg.msg_iovlen = vec_max_size;
+ msg.msg_control = buf;
+ msg.msg_controllen = sizeof(buf);
+
+ bool is_blocking;
+ if (fcntl(fd, F_GETFL, 0) & O_NONBLOCK)
+ is_blocking = false;
+ else
+ is_blocking = true;
+
+retry:
+ int ret = recvmsg(fd, &msg, 0);
+ if (ret == 0) {
+ _W("Socket was disconnected. fd(%d)", fd);
+ return -ECOMM;
+ }
+
+ if (ret < 0) {
+ if (errno == EINTR || errno == EAGAIN) {
+ if (is_blocking && errno == EAGAIN) {
+ _E("recvmsg() timed out. fd(%d)", fd);
+ return -EAGAIN;
+ }
+
+ usleep(100 * 1000);
+ goto retry;
+ }
+
+ ret = -errno;
+ _E("recvmsg() is failed. fd(%d), errno(%d)", fd, errno);
+ return ret;
+ }
+
+ *vec_size = msg.msg_iovlen;
+
+ struct cmsghdr* cmsg = CMSG_FIRSTHDR(&msg);
+ if (cmsg == nullptr) {
+ if (nr_fds != nullptr)
+ *nr_fds = 0;
+ } else {
+ for (int i = 0; cmsg != nullptr; cmsg = CMSG_NXTHDR(&msg, cmsg), ++i) {
+ if (cmsg->cmsg_type == SCM_RIGHTS) {
+ if (fds != nullptr) {
+ int fdnum = GetFileDescriptor(cmsg, &msg, fds, MAX_NR_OF_DESCRIPTORS);
+ if (nr_fds != nullptr)
+ *nr_fds = fdnum;
+ }
+ }
+ }
+ }
+
+ return 0;
+}
+
+void DeleteDirectories(const std::string& path) {
+ if (path.empty())
+ return;
+
+ DIR* dp = opendir(path.c_str());
+ if (dp == nullptr)
+ return;
+
+ struct stat statbuf;
+ struct dirent* dentry = nullptr;
+ while ((dentry = readdir(dp)) != nullptr) {
+ if (!strcmp(dentry->d_name, ".") || !strcmp(dentry->d_name, ".."))
+ continue;
+
+ std::string entry = path + dentry->d_name;
+ if (stat(entry.c_str(), &statbuf) == 0) {
+ if (S_ISDIR(statbuf.st_mode))
+ DeleteDirectories(entry);
+ else
+ unlink(entry.c_str());
+ }
+ }
+
+ rmdir(path.c_str());
+ closedir(dp);
+}
+
+unsigned int GetSocketTimeout(unsigned int timeout) {
+ return std::min(std::max(timeout, SOCKET_TIMEOUT_MIN), SOCKET_TIMEOUT_MAX);
+}
+
+SocketTimeout socket_timeout;
+SocketLink socket_link;
+
+} // namespace
+
+extern "C" API struct timeval aul_sock_get_rcv_timeout(void) {
+ return socket_timeout.GetTimeval();
+}
+
+extern "C" API int aul_sock_set_sock_option(int fd, int cli) {
+ if (fd < 0 || fd >= sysconf(_SC_OPEN_MAX)) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ int size = AUL_SOCK_MAXBUFF;
+ int ret = setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &size, sizeof(size));
+ if (ret != 0)
+ return ret;
+
+ ret = setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size));
+ if (ret != 0)
+ return ret;
+
+ if (cli) {
+ if (TIZEN_FEATURE_SOCKET_TIMEOUT && !socket_timeout.IsInitialized())
+ socket_timeout.Init();
+
+ auto timeout = socket_timeout.GetTimeval();
+ ret = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
+ if (ret != 0)
+ return ret;
+ }
+
+ return 0;
+}
+
+extern "C" API int aul_sock_create_server(int pid, uid_t uid) {
+ auto path = GetSocketPath(pid, uid);
+ int fd = -1;
+ try {
+ if (CreateSocketDirectory(pid, uid) != 0)
+ return -1;
+
+ ServerSocket socket;
+ socket.Bind(path);
+ aul_sock_set_sock_option(socket.GetFd(), 0);
+ socket.Listen(128);
+ fd = socket.RemoveFd();
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%d)", e.GetErrorCode());
+ return e.GetErrorCode();
+ }
+
+ if (pid > 0) {
+ pid_t aul_pid;
+ const char* aul_pid_str = getenv("AUL_PID");
+ if (aul_pid_str != nullptr && isdigit(aul_pid_str[0]))
+ aul_pid = atoi(aul_pid_str);
+ else
+ aul_pid = -1;
+
+ if (aul_pid > 1 && aul_pid != pid)
+ socket_link.Create(path.c_str(), aul_pid, uid);
+ }
+
+ return fd;
+}
+
+extern "C" API int aul_sock_send_raw_with_fd(int fd, int cmd,
+ unsigned char* kb_data, int datalen, int opt) {
+ if (fd < 0 || fd >= sysconf(_SC_OPEN_MAX)) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ return SendAndReceive(fd, cmd, kb_data, datalen, opt);
+}
+
+extern "C" API int aul_sock_send_bundle_with_fd(int fd, int cmd, bundle* kb,
+ int opt) {
+ if (fd < 0 || fd >= sysconf(_SC_OPEN_MAX) || kb == nullptr) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ tizen_base::Bundle b(kb, false, false);
+ auto raw = b.ToRaw();
+ return SendAndReceive(fd, cmd,
+ reinterpret_cast<unsigned char*>(raw.first.get()),
+ raw.second, opt | AUL_SOCK_BUNDLE);
+}
+
+extern "C" API int aul_sock_send_raw(int pid, uid_t uid, int cmd,
+ unsigned char* kb_data, int datalen, int opt) {
+ return SendAndReceive(pid, uid, cmd, kb_data, datalen, opt);
+}
+
+extern "C" API int aul_sock_send_bundle(int pid, uid_t uid, int cmd,
+ bundle* kb, int opt) {
+ if (kb == nullptr)
+ return -EINVAL;
+
+ tizen_base::Bundle b(kb, false, false);
+ std::string timeout_str = b.GetString(AUL_K_SOCKET_TIMEOUT);
+ if (timeout_str.empty() || !isdigit(timeout_str[0])) {
+ auto [ptr, size] = b.ToRaw();
+ return SendAndReceive(pid, uid, cmd,
+ reinterpret_cast<unsigned char*>(ptr.get()),
+ size, opt | AUL_SOCK_BUNDLE);
+ }
+
+ unsigned int timeout = static_cast<unsigned int>(std::stoi(timeout_str));
+ if (timeout < SOCKET_TIMEOUT_MIN || timeout > SOCKET_TIMEOUT_MAX) {
+ timeout = GetSocketTimeout(timeout);
+ b.Delete(AUL_K_SOCKET_TIMEOUT);
+ b.Add(AUL_K_SOCKET_TIMEOUT, std::to_string(timeout));
+ }
+
+ auto [ptr, size] = b.ToRaw();
+ return SendAndReceiveWithTimeout(
+ pid, uid, cmd, reinterpret_cast<unsigned char*>(ptr.get()), size,
+ opt | AUL_SOCK_BUNDLE, timeout);
+}
+
+extern "C" API app_pkt_t* aul_sock_recv_pkt(int fd, int* clifd,
+ struct ucred* cred) {
+ if (fd < 0 || fd >= sysconf(_SC_OPEN_MAX)) {
+ _E("Invalid parameter");
+ return nullptr;
+ }
+
+ ServerSocket server(fd);
+ auto client = std::unique_ptr<ClientSocket>(server.Accept());
+ server.RemoveFd();
+ if (client.get() == nullptr)
+ return nullptr;
+
+ socklen_t optlen = static_cast<socklen_t>(sizeof(struct ucred));
+ int ret = getsockopt(client->GetFd(), SOL_SOCKET, SO_PEERCRED,
+ cred, &optlen);
+ if (ret < 0) {
+ _E("getsockopt() is failed. errno(%d)", errno);
+ return nullptr;
+ }
+
+ aul_sock_set_sock_option(client->GetFd(), 1);
+
+ app_pkt_t* pkt = nullptr;
+ ret = ReceiveAppPacket(client.get(), &pkt);
+ if (ret < 0)
+ return nullptr;
+
+ *clifd = client->RemoveFd();
+ return pkt;
+}
+
+extern "C" API int aul_sock_recv_reply_pkt(int fd, app_pkt_t** ret_pkt) {
+ return aul_sock_recv_reply_pkt_v2(fd, ret_pkt, true);
+}
+
+extern "C" API int aul_sock_recv_reply_sock_fd(int fd, int (*ret_fd)[2],
+ int fd_size) {
+ if (fd < 0 || fd >= sysconf(_SC_OPEN_MAX)) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ int fds[2] = { -1, -1 };
+ int vec_len = 0;
+ int fds_len = 0;
+ char recv_buff[1024] = { 0, };;
+ struct iovec vec[3] = { 0, };
+ vec[0].iov_base = recv_buff;
+ vec[0].iov_len = sizeof(recv_buff);
+ int ret = ReceiveMessage(fd, vec, 1, &vec_len, fds, &fds_len);
+ if (ret < 0) {
+ _E("ReceiveMessage() is failed. error(%d)", ret);
+ if (fds_len > 0)
+ close(fds[0]);
+
+ ret = -ECOMM;
+ } else if (fds_len == fd_size && fds_len == 2) {
+ (*ret_fd)[0] = fds[0];
+ (*ret_fd)[1] = fds[1];
+ } else if (fds_len == fd_size && fds_len == 1) {
+ (*ret_fd)[0] = fds[0];
+ } else {
+ _E("Wrong number of FD received. Expected: %d, Actual: %d",
+ fd_size, fds_len);
+ ret = -ECOMM;
+ }
+
+ close(fd);
+ return ret;
+}
+
+extern "C" API int aul_sock_create_launchpad_client_without_timeout(
+ const char* pad_type, uid_t uid) {
+ int fd = -1;
+ try {
+ ClientSocket client;
+ std::string endpoint = "/run/aul/daemons/" + std::to_string(uid) + "/" +
+ std::string(pad_type);
+ client.Connect(endpoint);
+ fd = client.RemoveFd();
+ aul_sock_set_sock_option(fd, 0);
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%d)", e.GetErrorCode());
+ return e.GetErrorCode();
+ }
+
+ return fd;
+}
+
+extern "C" API int aul_sock_create_launchpad_client(const char* pad_type,
+ uid_t uid) {
+ int fd = -1;
+ try {
+ ClientSocket client;
+ std::string endpoint = "/run/aul/daemons/" + std::to_string(uid) + "/" +
+ std::string(pad_type);
+ client.Connect(endpoint);
+ fd = client.RemoveFd();
+ aul_sock_set_sock_option(fd, 1);
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%d)", e.GetErrorCode());
+ return e.GetErrorCode();
+ }
+
+ return fd;
+}
+
+extern "C" API int aul_sock_recv_pkt_with_cb(int fd,
+ void (*callback)(app_pkt_t* pkt, void* user_data),
+ void* user_data) {
+ if (fd < 0 || fd >= sysconf(_SC_OPEN_MAX)) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ if (callback == nullptr) {
+ _E("Invalid parameter");
+ close(fd);
+ return -1;
+ }
+
+ ClientSocket client(fd);
+ int count = 0;
+ int ret = client.Receive(&count, sizeof(count));
+ if (ret != 0) {
+ _E("Receive() is failed. error(%d)", ret);
+ return ret;
+ }
+
+ if (count <= 0 || count > MAX_RUNNING_INSTANCE) {
+ _E("Error occurs. count(%d)", count);
+ return -ECOMM;
+ }
+
+ app_pkt_t** pkt = reinterpret_cast<app_pkt_t**>(
+ calloc(count, sizeof(app_pkt_t*)));
+ if (pkt == nullptr) {
+ _E("Out of memory");
+ return -ENOMEM;
+ }
+
+ for (int i = 0; i < count; ++i) {
+ ret = ReceiveAppPacket(&client, &pkt[i]);
+ if (ret != 0) {
+ _E("ReceiveAppPacket() is failed. error(%d)", ret);
+ break;
+ }
+ }
+
+ for (int i = 0; i < count; ++i) {
+ if (pkt[i] != nullptr) {
+ callback(pkt[i], user_data);
+ free(pkt[i]);
+ }
+ }
+
+ free(pkt);
+ return ret;
+}
+
+extern "C" API int aul_sock_recv_result_with_fd(int fd) {
+ if (fd < 0 || fd >= sysconf(_SC_OPEN_MAX)) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ ClientSocket client(fd);
+ int res;
+ int ret = client.Receive(&res, sizeof(res));
+ client.RemoveFd();
+ if (ret < 0) {
+ _E("Receive() is failed. fd(%d), error(%d)", fd, ret);
+ res = -ECOMM;
+ }
+
+ return res;
+}
+
+extern "C" API int aul_sock_destroy_server(int fd) {
+ if (fd > -1 && fd < sysconf(_SC_OPEN_MAX))
+ close(fd);
+
+ if (getuid() < REGULAR_UID_MIN) {
+ std::string path = "/run/aul/daemons/" + std::to_string(getuid()) +
+ "/.app-sock-" + std::to_string(getpid());
+ unlink(path.c_str());
+ } else {
+ std::string path = "/run/aul/apps/" + std::to_string(getuid()) + "/" +
+ std::to_string(getpid());
+ DeleteDirectories(path);
+ }
+ socket_link.Delete();
+
+ return 0;
+}
+
+extern "C" API int aul_sock_send_result(int fd, int res) {
+ return aul_sock_send_result_v2(fd, res, true);
+}
+
+extern "C" API int aul_sock_send_result_v2(int fd, int res, bool do_close) {
+ if (fd < 0 || fd >= sysconf(_SC_OPEN_MAX)) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ int ret = send(fd, &res, sizeof(res), MSG_NOSIGNAL);
+ if (ret < 0)
+ _E("send() is failed. fd(%d), errno(%d)", fd, errno);
+
+ if (do_close)
+ close(fd);
+
+ return ret;
+}
+
+extern "C" API int aul_sock_recv_reply_pkt_v2(int fd, app_pkt_t** pkt,
+ bool do_close) {
+ if (fd < 0 || fd >= sysconf(_SC_OPEN_MAX)) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ if (pkt == nullptr) {
+ _E("Invalid parameter");
+ if (do_close)
+ close(fd);
+
+ return -EINVAL;
+ }
+
+ ClientSocket client(fd);
+ int ret = ReceiveAppPacket(&client, pkt);
+ if (!do_close)
+ client.RemoveFd();
+
+ return ret;
+}
+
+extern "C" API int aul_sock_send_raw_data(int fd, unsigned char* raw_data,
+ size_t length, bool do_close) {
+ if (fd < 0 || fd >= sysconf(_SC_OPEN_MAX)) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ int ret = send(fd, raw_data, length, MSG_NOSIGNAL);
+ if (ret < 0)
+ _E("send() is failed. fd(%d), errno(%d)", fd, errno);
+
+ if (do_close)
+ close(fd);
+
+ return ret;
+}
--- /dev/null
+/*
+ * Copyright (c) 2021 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 <bundle.h>
+#include <bundle_cpp.h>
+#include <bundle_internal.h>
+#include <dlfcn.h>
+#include <glib.h>
+#include <iniparser.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include <atomic>
+#include <memory>
+#include <mutex>
+#include <string>
+#include <unordered_map>
+#include <vector>
+
+#include "aul/app_control/resolve_info.hh"
+#include "aul/include/aul.h"
+#include "aul/include/aul_app_group.h"
+#include "aul/include/aul_error.h"
+#include "aul/include/aul_sock.h"
+#include "aul/include/aul_svc.h"
+#include "aul/include/aul_svc_internal.h"
+#include "aul/aul_api.h"
+#include "aul/aul_svc_priv_key.h"
+#include "aul/aul_util.h"
+#include "aul/launch.h"
+
+#undef MAX_MIME_STR_SIZE
+#define MAX_MIME_STR_SIZE 256
+
+#undef MAX_SCHEME_STR_SIZE
+#define MAX_SCHEME_STR_SIZE 256
+
+#undef MAX_HOST_STR_SIZE
+#define MAX_HOST_STR_SIZE 256
+
+#undef DEPRECATION_WARNING
+#define DEPRECATION_WARNING() do { \
+ dlog_print(DLOG_WARN, LOG_TAG, \
+ "DEPRECATION WARNING: %s() is deprecated and " \
+ "will be removed from next release.", __FUNCTION__); \
+} while (0)
+
+namespace {
+
+constexpr const char kPathAmdReady[] = "/run/.amd_ready";
+constexpr const char kPathLibAulServer[] = LIBDIR "/libaul-server.so.0";
+constexpr const char kAulServiceForeachUsrAliasInfo[] =
+ "aul_service_foreach_usr_alias_info";
+
+class CbInfo {
+ public:
+ CbInfo(int request_code, aul_svc_res_fn res_fn,
+ aul_svc_err_cb err_cb, void* user_data)
+ : request_code_(request_code),
+ res_fn_(res_fn),
+ err_cb_(err_cb),
+ user_data_(user_data) {
+ }
+
+ int request_code_;
+ aul_svc_res_fn res_fn_;
+ aul_svc_err_cb err_cb_;
+ void* user_data_;
+};
+
+class AliasInfo {
+ public:
+ explicit AliasInfo(std::string alias_appid)
+ : alias_appid_(std::move(alias_appid)) {
+ }
+
+ std::string alias_appid_;
+ std::string appid_;
+};
+
+class AppSvcAlias {
+ public:
+ AppSvcAlias() = default;
+
+ void Load() {
+ std::lock_guard<std::mutex> lock(mutex_);
+ if (loaded_)
+ return;
+
+ dictionary* dict = iniparser_load("/usr/share/appsvc/alias.ini");
+ if (dict == nullptr) {
+ loaded_ = true;
+ return;
+ }
+
+ std::string delimiter = "Alias:";
+ for (int i = 0; i < dict->n; ++i) {
+ if (dict->key[i] == nullptr || dict->val[i] == nullptr)
+ continue;
+
+ std::string key = dict->key[i];
+ key.erase(0, key.find(delimiter) + delimiter.length() + 1);
+ std::string value = dict->val[i];
+ map_[key] = value;
+ }
+
+ iniparser_freedict(dict);
+ loaded_ = true;
+ }
+
+ std::string GetAliasAppId(const std::string& alias_appid) {
+ auto found = map_.find(alias_appid);
+ if (found == map_.end())
+ return {};
+
+ SECURE_LOGD("alias_appid: %s, appid: %s",
+ alias_appid.c_str(), found->second.c_str());
+ return found->second;
+ }
+
+ private:
+ bool loaded_ = false;
+ std::unordered_map<std::string, std::string> map_;
+ std::mutex mutex_;
+};
+
+AppSvcAlias appsvc_alias;
+
+int SetBundle(bundle* b, const char* key, const char* value) {
+ if (bundle_get_type(b, key) != BUNDLE_TYPE_NONE) {
+ if (bundle_del(b, key) != BUNDLE_ERROR_NONE)
+ return AUL_SVC_RET_ERROR;
+ }
+
+ if (value == nullptr)
+ return AUL_SVC_RET_EINVAL;
+
+ if (bundle_add(b, key, value) != BUNDLE_ERROR_NONE)
+ return AUL_SVC_RET_ERROR;
+
+ SECURE_LOGD("key(%s), value(%s)", key, value);
+ return AUL_SVC_RET_OK;
+}
+
+int SetBundleArray(bundle* b, const char* key, const char** value,
+ int len) {
+ int is_array = aul_svc_data_is_array(b, key);
+ if (is_array) {
+ if (bundle_del(b, key) != BUNDLE_ERROR_NONE)
+ return AUL_SVC_RET_ERROR;
+ }
+
+ if (value == nullptr)
+ return AUL_SVC_RET_EINVAL;
+
+ if (bundle_add_str_array(b, key, value, len) != BUNDLE_ERROR_NONE)
+ return AUL_SVC_RET_ERROR;
+
+ SECURE_LOGD("key(%s), length(%d)", key, len);
+ return AUL_SVC_RET_OK;
+}
+
+std::string GetAliasAppId(const char* appid) {
+ appsvc_alias.Load();
+ return appsvc_alias.GetAliasAppId(appid);
+}
+
+bool IsSpecialApp(const char* appid) {
+ if (!strcmp(appid, APP_SELECTOR) || !strcmp(appid, SHARE_PANEL))
+ return true;
+
+ return false;
+}
+
+bool IsSpecialOperation(const char* operation) {
+ if (operation == nullptr)
+ return false;
+
+ int ret = strcmp(operation,
+ "http://tizen.org/appcontrol/operation/guide_privacy_setting");
+ if (ret == 0)
+ return true;
+
+ return false;
+}
+
+std::string GetAppId(bundle* request) {
+ const char* appid = aul_svc_get_pkgname(request);
+ if (appid == nullptr) {
+ if (aul_svc_get_operation(request) == nullptr) {
+ _E("Invalid request");
+ return {};
+ }
+
+ appid = "@UNKNOWN";
+ }
+
+ int ret = bundle_get_type(request, AUL_SVC_K_SELECTOR_EXTRA_LIST);
+ if (ret != BUNDLE_TYPE_NONE) {
+ if (appid == nullptr || !strcmp(appid, "@UNKNOWN"))
+ appid = APP_SELECTOR;
+ }
+
+ ret = bundle_get_type(request, AUL_K_FORCE_LAUNCH_APP_SELECTOR);
+ if (ret != BUNDLE_TYPE_NONE)
+ appid = APP_SELECTOR;
+
+ return std::string(appid);
+}
+
+void SetLaunchData(bundle* request, const std::string& appid) {
+ const char* operation = aul_svc_get_operation(request);
+ if (operation == nullptr)
+ aul_svc_set_operation(request, AUL_SVC_OPERATION_DEFAULT);
+
+ if (IsSpecialApp(appid.c_str()) || IsSpecialOperation(operation)) {
+ SetBundle(request, AUL_SVC_K_CAN_BE_LEADER, "true");
+ SetBundle(request, AUL_SVC_K_REROUTE, "true");
+ SetBundle(request, AUL_SVC_K_RECYCLE, "true");
+ }
+
+ const char* launch_mode = aul_svc_get_launch_mode(request);
+ if (launch_mode && !strcmp(launch_mode, "group")) {
+ int ret = bundle_get_type(request, AUL_K_INSTANCE_ID);
+ if (ret == BUNDLE_TYPE_NONE)
+ aul_set_instance_info(appid.c_str(), request);
+ }
+}
+
+int AulErrorConvert(int res) {
+ switch (res) {
+ case AUL_R_EILLACC:
+ return AUL_SVC_RET_EILLACC;
+ case AUL_R_EINVAL:
+ return AUL_SVC_RET_EINVAL;
+ case AUL_R_ETERMINATING:
+ return AUL_SVC_RET_ETERMINATING;
+ case AUL_R_EREJECTED:
+ return AUL_SVC_RET_EREJECTED;
+ case AUL_R_ENOAPP:
+ return AUL_SVC_RET_ENOMATCH;
+ case AUL_R_ECANCELED:
+ return AUL_SVC_RET_ECANCELED;
+ case AUL_R_ETIMEOUT:
+ return AUL_SVC_RET_ETIMEOUT;
+ default:
+ return AUL_SVC_RET_ELAUNCH;
+ }
+}
+
+void LaunchWithResultCb(bundle* b, int is_cancel, void* data) {
+ int res;
+ if (is_cancel) {
+ res = AUL_SVC_RES_CANCEL;
+ } else {
+ const char* val = bundle_get_val(b, AUL_SVC_K_RES_VAL);
+ res = (val == nullptr) ? AUL_SVC_RES_NOT_OK : atoi(val);
+ }
+
+ bundle_del(b, AUL_SVC_K_RES_VAL);
+ auto* cb_info = static_cast<CbInfo*>(data);
+ if (cb_info == nullptr) {
+ _E("Invalid parameter");
+ return;
+ }
+
+ if (cb_info->res_fn_) {
+ cb_info->res_fn_(b, cb_info->request_code_,
+ static_cast<aul_svc_result_val>(res), cb_info->user_data_);
+ cb_info->res_fn_ = nullptr;
+ }
+
+ if (cb_info->err_cb_ != nullptr)
+ return;
+
+ delete cb_info;
+}
+
+void ErrorCb(int error, void* data) {
+ if (error < 0)
+ error = AulErrorConvert(error);
+
+ auto* cb_info = static_cast<CbInfo*>(data);
+ if (cb_info == nullptr) {
+ _E("Invalid parameter");
+ return;
+ }
+
+ if (cb_info->err_cb_) {
+ cb_info->err_cb_(cb_info->request_code_, error, cb_info->user_data_);
+ cb_info->err_cb_ = nullptr;
+ }
+
+ if (cb_info->res_fn_)
+ return;
+
+ delete cb_info;
+}
+
+using SendLaunchRequestCb =
+ int (*)(const std::string&, bundle*, uid_t, CbInfo*);
+using SendLaunchRequestSyncCb =
+ int (*)(const std::string&, bundle*, uid_t, bundle**);
+
+template <typename T, typename A>
+int SendLaunchRequest(T cb, bundle* request, uid_t uid, A arg) {
+ if (request == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ std::string appid = GetAppId(request);
+ if (appid.empty()) {
+ _E("GetAppId() is failed");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ SetLaunchData(request, appid);
+ return cb(appid, request, uid, arg);
+}
+
+int SendAndReceive(int cmd, uid_t uid, bundle* request, bundle** response) {
+ int fd = aul_sock_send_bundle(AUL_UTIL_PID, uid, cmd, request,
+ AUL_SOCK_ASYNC);
+ if (fd < 0)
+ return AUL_SVC_RET_ERROR;
+
+ app_pkt_t* pkt = nullptr;
+ int ret = aul_sock_recv_reply_pkt(fd, &pkt);
+ if (ret < 0) {
+ _E("Failed to receive reply packet. error(%d)", ret);
+ return AUL_SVC_RET_ERROR;
+ }
+
+ auto ptr = std::unique_ptr<app_pkt_t, decltype(std::free)*>(pkt, std::free);
+ if (pkt->cmd != APP_GET_INFO_OK && pkt->cmd != cmd) {
+ if (pkt->cmd == APP_GET_INFO_ERROR)
+ return AUL_SVC_RET_ERROR;
+
+ return AulErrorConvert(aul_error_convert(pkt->cmd));
+ }
+
+ bundle* b = nullptr;
+ if (pkt->opt & AUL_SOCK_BUNDLE) {
+ b = bundle_decode(pkt->data, pkt->len);
+ if (b == nullptr) {
+ _E("bundle_decode() is failed");
+ return AUL_SVC_RET_ENOMEM;
+ }
+ } else {
+ _E("Invalid packet");
+ return AUL_SVC_RET_ERROR;
+ }
+
+ *response = b;
+ return AUL_SVC_RET_OK;
+}
+
+std::atomic<bool> amd_ready { false };
+bool IsAmdReady() {
+ if (amd_ready)
+ return amd_ready;
+
+ if (access(kPathAmdReady, F_OK) == 0) {
+ amd_ready.exchange(true);
+ return amd_ready;
+ }
+
+ return false;
+}
+
+using AulServiceAliasInfoCb =
+ bool (*)(const char*, const char*, void*);
+using AulServiceForeachUsrAliasInfoFunc =
+ int (*)(AulServiceAliasInfoCb, uid_t, void*);
+
+int GetAppIdByAliasAppIdFromDB(const char* alias_appid, char** app_id,
+ uid_t uid) {
+ void* handle = dlopen(kPathLibAulServer, RTLD_LAZY | RTLD_GLOBAL);
+ if (handle == nullptr) {
+ _E("dlopen() is failed. path(%s), error(%s)", kPathLibAulServer, dlerror());
+ return AUL_SVC_RET_ERROR;
+ }
+
+ auto dl_closer = [](void* ptr) {
+ dlclose(ptr);
+ };
+
+ std::unique_ptr<void, decltype(dl_closer)> handle_auto(handle, dl_closer);
+ auto* func = reinterpret_cast<AulServiceForeachUsrAliasInfoFunc>(
+ dlsym(handle, kAulServiceForeachUsrAliasInfo));
+ if (func == nullptr) {
+ _E("dlsym() is failed. error(%s)", dlerror());
+ return AUL_SVC_RET_ERROR;
+ }
+
+ AliasInfo info(alias_appid);
+ int ret = func(
+ [](const char* alias_appid, const char* appid, void* user_data) -> bool {
+ auto* info = static_cast<AliasInfo*>(user_data);
+ if (info->alias_appid_ == alias_appid) {
+ info->appid_ = appid;
+ return false;
+ }
+
+ return true;
+ }, uid, &info);
+ if (ret != 0) {
+ _E("%s() is failed. error(%d)", kAulServiceForeachUsrAliasInfo, ret);
+ return AUL_SVC_RET_ERROR;
+ }
+
+ if (info.appid_.empty())
+ return AUL_SVC_RET_ERROR;
+
+ *app_id = strdup(info.appid_.c_str());
+ if (*app_id == nullptr) {
+ _E("strdup() is failed");
+ return AUL_SVC_RET_ENOMEM;
+ }
+
+ return AUL_SVC_RET_OK;
+}
+
+} // namespace
+
+extern "C" API int aul_svc_set_operation(bundle* b, const char* operation) {
+ if (b == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ return ::SetBundle(b, AUL_SVC_K_OPERATION, operation);
+}
+
+extern "C" API int aul_svc_set_uri(bundle* b, const char* uri) {
+ if (b == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ return ::SetBundle(b, AUL_SVC_K_URI, uri);
+}
+
+extern "C" API int aul_svc_set_mime(bundle* b, const char* mime) {
+ if (b == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ return ::SetBundle(b, AUL_SVC_K_MIME, mime);
+}
+
+extern "C" API int aul_svc_add_data(bundle* b, const char* key,
+ const char* value) {
+ if (b == nullptr || key == nullptr)
+ return AUL_SVC_RET_EINVAL;
+
+ return ::SetBundle(b, key, value);
+}
+
+extern "C" API int aul_svc_add_data_array(bundle* b, const char* key,
+ const char** value, int len) {
+ if (b == nullptr || key == nullptr)
+ return AUL_SVC_RET_EINVAL;
+
+ return ::SetBundleArray(b, key, value, len);
+}
+
+extern "C" API int aul_svc_set_pkgname(bundle* b, const char* pkg_name) {
+ if (b == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ return ::SetBundle(b, AUL_SVC_K_PKG_NAME, pkg_name);
+}
+
+extern "C" API int aul_svc_set_appid(bundle* b, const char* appid) {
+ if (b == nullptr || appid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ if (TIZEN_FEATURE_APPSVC_ALIAS) {
+ std::string alias_id = ::GetAliasAppId(appid);
+ if (!alias_id.empty())
+ return ::SetBundle(b, AUL_SVC_K_PKG_NAME, alias_id.c_str());
+ }
+
+ return ::SetBundle(b, AUL_SVC_K_PKG_NAME, appid);
+}
+
+extern "C" API int aul_svc_set_category(bundle* b, const char* category) {
+ if (b == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ return ::SetBundle(b, AUL_SVC_K_CATEGORY, category);
+}
+
+extern "C" API int aul_svc_set_launch_mode(bundle* b, const char* mode) {
+ if (b == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ return ::SetBundle(b, AUL_SVC_K_LAUNCH_MODE, mode);
+}
+
+extern "C" API int aul_svc_resolve(bundle* b, uid_t uid, char*** appid_array,
+ unsigned int* len) {
+ return aul_svc_get_appid_array(b, uid, appid_array, len);
+}
+
+extern "C" API int aul_svc_run_service(bundle* b, int request_code,
+ aul_svc_res_fn cbfunc, void* data) {
+ return aul_svc_run_service_for_uid(b, request_code, cbfunc, data, getuid());
+}
+
+extern "C" API int aul_svc_run_service_for_uid(bundle* b, int request_code,
+ aul_svc_res_fn cbfunc, void* data, uid_t uid) {
+ CbInfo* cb_info = nullptr;
+ if (cbfunc) {
+ cb_info = new (std::nothrow) CbInfo(request_code, cbfunc, nullptr, data);
+ if (cb_info == nullptr)
+ LOGE("Out of memory");
+ }
+
+ std::tuple<aul_svc_res_fn, void*> param { cbfunc, data };
+ int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
+ [](const std::string& appid, bundle* request, uid_t uid,
+ CbInfo* cb_info) -> int {
+ int ret;
+ if (cb_info) {
+ ret = aul_launch_app_with_result_for_uid(appid.c_str(), request,
+ LaunchWithResultCb, cb_info, uid);
+ } else {
+ ret = aul_launch_app_for_uid(appid.c_str(), request, uid);
+ }
+
+ return ret;
+ }, b, uid, cb_info);
+ if (ret < 0) {
+ if (cb_info)
+ delete cb_info;
+
+ ret = AulErrorConvert(ret);
+ }
+
+ return ret;
+}
+
+extern "C" API int aul_svc_get_list(bundle* b, aul_svc_info_iter_fn iter_fn,
+ void* data) {
+ return aul_svc_get_list_for_uid(b, iter_fn, data, getuid());
+}
+
+extern "C" API int aul_svc_get_list_for_uid(bundle* b,
+ aul_svc_info_iter_fn iter_fn, void* data, uid_t uid) {
+ if (b == nullptr || iter_fn == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ char** appid_array = nullptr;
+ unsigned int len = 0;
+ int ret = aul_svc_get_appid_array(b, uid, &appid_array, &len);
+ if (ret != AUL_SVC_RET_OK)
+ return ret;
+
+ if (len == 0) {
+ _E("Failed to find associated application");
+ aul_svc_free_appid_array(appid_array, len);
+ return AUL_SVC_RET_ENOMATCH;
+ }
+
+ for (unsigned int i = 0; i < len; ++i) {
+ SECURE_LOGD("APPID: %s", appid_array[i]);
+ if (iter_fn(appid_array[i], data) != 0)
+ break;
+ }
+
+ aul_svc_free_appid_array(appid_array, len);
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_get_all_defapps(aul_svc_info_iter_fn iter_fn,
+ void* data) {
+ return aul_svc_get_all_defapps_for_uid(iter_fn, data, getuid());
+}
+
+extern "C" API int aul_svc_get_all_defapps_for_uid(aul_svc_info_iter_fn iter_fn,
+ void* data, uid_t uid) {
+ if (iter_fn == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ bundle* response;
+ tizen_base::Bundle request;
+ int ret = ::SendAndReceive(APP_GET_APP_CONTROL_DEFAULT_APPS, uid,
+ request.GetHandle(), &response);
+ if (ret != AUL_SVC_RET_OK)
+ return ret;
+
+ tizen_base::Bundle res(response, false, true);
+ auto appid_array = res.GetStringArray(AUL_K_APPID_LIST);
+ for (auto& appid : appid_array) {
+ if (iter_fn(appid.c_str(), data) != 0)
+ break;
+ }
+
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API const char* aul_svc_get_operation(bundle* b) {
+ return bundle_get_val(b, AUL_SVC_K_OPERATION);
+}
+
+extern "C" API const char* aul_svc_get_uri(bundle* b) {
+ return bundle_get_val(b, AUL_SVC_K_URI);
+}
+
+extern "C" API const char* aul_svc_get_mime(bundle* b) {
+ return bundle_get_val(b, AUL_SVC_K_MIME);
+}
+
+extern "C" API const char* aul_svc_get_data(bundle* b, const char* key) {
+ return bundle_get_val(b, key);
+}
+
+extern "C" API const char** aul_svc_get_data_array(bundle* b, const char* key,
+ int* len) {
+ return bundle_get_str_array(b, key, len);
+}
+
+extern "C" API const char* aul_svc_get_pkgname(bundle* b) {
+ return bundle_get_val(b, AUL_SVC_K_PKG_NAME);
+}
+
+extern "C" API const char* aul_svc_get_appid(bundle* b) {
+ return bundle_get_val(b, AUL_SVC_K_PKG_NAME);
+}
+
+extern "C" API const char* aul_svc_get_category(bundle* b) {
+ return bundle_get_val(b, AUL_SVC_K_CATEGORY);
+}
+
+extern "C" API const char* aul_svc_get_launch_mode(bundle* b) {
+ return bundle_get_val(b, AUL_SVC_K_LAUNCH_MODE);
+}
+
+extern "C" API int aul_svc_create_result_bundle(bundle* inb, bundle** outb) {
+ if (inb == nullptr || outb == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ int ret = aul_create_result_bundle(inb, outb);
+ if (ret != AUL_R_OK)
+ return AulErrorConvert(ret);
+
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_send_result(bundle* b, aul_svc_result_val result) {
+ if (b == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ int ret = ::SetBundle(b, AUL_SVC_K_RES_VAL, std::to_string(result).c_str());
+ if (ret < 0)
+ return AUL_SVC_RET_ERROR;
+
+ if (result == AUL_SVC_RES_CANCEL)
+ ret = aul_send_result(b, 1);
+ else
+ ret = aul_send_result(b, 0);
+
+ bundle_del(b, AUL_SVC_K_RES_VAL);
+ return ret;
+}
+
+extern "C" API int aul_svc_data_is_array(bundle* b, const char* key) {
+ int type = bundle_get_type(b, key);
+ if (type <= 0)
+ return 0;
+
+ if (type & BUNDLE_TYPE_ARRAY)
+ return 1;
+
+ return 0;
+}
+
+extern "C" API int aul_svc_allow_transient_app(bundle* b, int wid) {
+ if (b == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ return ::SetBundle(b, AUL_SVC_K_WIN_ID, std::to_string(wid).c_str());
+}
+
+extern "C" API int aul_svc_request_transient_app(bundle* b, int callee_wid,
+ aul_svc_host_res_fn cbfunc, void* data) {
+ return 0;
+}
+
+extern "C" API int aul_svc_subapp_terminate_request_pid(int pid) {
+ int cpid = getpid();
+ int lcnt;
+ int* lpids = nullptr;
+ aul_app_group_get_leader_pids(&lcnt, &lpids);
+ for (int i = 0; i < lcnt; ++i) {
+ if (lpids[i] == cpid) {
+ int cnt;
+ int* pids = nullptr;
+ aul_app_group_get_group_pids(cpid, &cnt, &pids);
+ if (cnt == 0) {
+ free(lpids);
+ if (pids)
+ free(pids);
+
+ return aul_subapp_terminate_request_pid(pid);
+ }
+
+ if (pids != nullptr)
+ free(pids);
+ break;
+ }
+ }
+
+ if (lpids != nullptr)
+ free(lpids);
+
+ return aul_app_group_clear_top();
+}
+
+extern "C" API int aul_send_service_result(bundle* b) {
+ return aul_send_result(b, 0);
+}
+
+extern "C" API int aul_svc_subscribe_launch_result(bundle* b,
+ const char* result) {
+ if (b == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ return ::SetBundle(b, result, "1");
+}
+
+extern "C" API int aul_svc_set_loader_id(bundle* b, int loader_id) {
+ if (b == nullptr || loader_id <= 0) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ return ::SetBundle(b, AUL_K_LOADER_ID, std::to_string(loader_id).c_str());
+}
+
+extern "C" API int aul_svc_set_loader_name(bundle* b, const char* loader_name) {
+ if (b == nullptr || loader_name == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ return ::SetBundle(b, AUL_K_LOADER_NAME, loader_name);
+}
+
+extern "C" API int aul_svc_set_background_launch(bundle* b, int enabled) {
+ if (b == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ return ::SetBundle(b, AUL_SVC_K_BG_LAUNCH, enabled ? "enable" : nullptr);
+}
+
+extern "C" API int aul_svc_get_appid_by_alias_appid(const char* alias_appid,
+ char** appid) {
+ return aul_svc_get_appid_by_alias_appid_for_uid(alias_appid, appid, getuid());
+}
+
+extern "C" API int aul_svc_get_appid_by_alias_appid_for_uid(
+ const char* alias_appid, char** appid, uid_t uid) {
+ if (alias_appid == nullptr || appid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ if (!IsAmdReady())
+ return GetAppIdByAliasAppIdFromDB(alias_appid, appid, uid);
+
+ bundle* response;
+ tizen_base::Bundle request;
+ request.Add(AUL_K_ALIAS_APPID, alias_appid);
+ int ret = ::SendAndReceive(APP_GET_APPID_BY_ALIAS_APPID, uid,
+ request.GetHandle(), &response);
+ if (ret != AUL_SVC_RET_OK)
+ return ret;
+
+ tizen_base::Bundle res(response, false, true);
+ auto val = res.GetString(AUL_K_APPID);
+ if (val.empty())
+ return AUL_SVC_RET_ERROR;
+
+ *appid = strdup(val.c_str());
+ if (*appid == nullptr) {
+ _E("Out of memory");
+ return AUL_SVC_RET_ENOMEM;
+ }
+
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API const char *aul_svc_get_instance_id(bundle* b) {
+ return bundle_get_val(b, AUL_K_INSTANCE_ID);
+}
+
+extern "C" API int aul_svc_set_instance_id(bundle* b, const char* instance_id) {
+ if (b == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ return ::SetBundle(b, AUL_K_INSTANCE_ID, instance_id);
+}
+
+extern "C" API int aul_svc_run_service_async(bundle* b, int request_code,
+ aul_svc_res_fn cbfunc, void* data) {
+ return aul_svc_run_service_async_for_uid(b, request_code, cbfunc, data,
+ getuid());
+}
+
+extern "C" API int aul_svc_run_service_async_for_uid(bundle* b,
+ int request_code, aul_svc_res_fn cbfunc, void* data, uid_t uid) {
+ CbInfo* cb_info = nullptr;
+ if (cbfunc)
+ cb_info = new (std::nothrow) CbInfo(request_code, cbfunc, nullptr, data);
+
+ int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
+ [](const std::string& appid, bundle* request, uid_t uid,
+ CbInfo* info) -> int {
+ if (info) {
+ return aul_launch_app_with_result_async_for_uid(appid.c_str(),
+ request, LaunchWithResultCb, info, uid);
+ }
+
+ return aul_launch_app_async_for_uid(appid.c_str(), request, uid);
+ }, b, uid, cb_info);
+ if (ret < 0) {
+ if (cb_info)
+ delete cb_info;
+
+ ret = AulErrorConvert(ret);
+ }
+
+ return ret;
+}
+
+extern "C" API int aul_svc_send_launch_request(bundle* b, int request_code,
+ aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb, void* user_data) {
+ return aul_svc_send_launch_request_for_uid(b, request_code,
+ cbfunc, err_cb, user_data, getuid());
+}
+
+extern "C" API int aul_svc_send_launch_request_for_uid(bundle* b,
+ int request_code, aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb,
+ void* user_data, uid_t uid) {
+ if (b == nullptr || err_cb == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ CbInfo* cb_info = new (std::nothrow) CbInfo(request_code, cbfunc, err_cb,
+ user_data);
+ if (cb_info == nullptr)
+ _E("Out of memory");
+
+ int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
+ [](const std::string& appid, bundle* request, uid_t uid,
+ CbInfo* info) -> int {
+ return aul_send_launch_request_for_uid(appid.c_str(), request, uid,
+ info->res_fn_ ? ::LaunchWithResultCb : nullptr, ::ErrorCb, info);
+ }, b, uid, cb_info);
+ if (ret < 0) {
+ delete cb_info;
+ ret = ::AulErrorConvert(ret);
+ }
+
+ return ret;
+}
+
+extern "C" API int aul_svc_send_launch_request_sync_for_uid(bundle* b,
+ int request_code, bundle** res_b, aul_svc_result_val* res, uid_t uid) {
+ if (b == nullptr || res_b == nullptr || res == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ int ret = ::SendLaunchRequest<::SendLaunchRequestSyncCb, bundle**>(
+ [](const std::string& appid, bundle* request, uid_t uid,
+ bundle** response) -> int {
+ return aul_send_launch_request_sync_for_uid(appid.c_str(), request,
+ uid, response);
+ }, b, uid, res_b);
+ if (ret > 0) {
+ auto* val = bundle_get_val(*res_b, AUL_SVC_K_RES_VAL);
+ *res = static_cast<aul_svc_result_val>(
+ (val == nullptr) ? AUL_SVC_RES_NOT_OK : atoi(val));
+ } else {
+ ret = ::AulErrorConvert(ret);
+ *res = AUL_SVC_RES_CANCEL;
+ }
+
+ return ret;
+}
+
+extern "C" API int aul_svc_info_create(bundle* b, aul_svc_info_h* h) {
+ if (b == nullptr || h == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ aul::ResolveInfo* resolve_info = nullptr;
+ try {
+ tizen_base::Bundle kb(b, false, false);
+ resolve_info = aul::ResolveInfo::Manager::Create(kb);
+ } catch (aul::Exception& e) {
+ return AUL_SVC_RET_ERROR;
+ }
+
+ *h = static_cast<aul_svc_info_h>(resolve_info);
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_info_get_operation(aul_svc_info_h h,
+ char** operation) {
+ if (h == nullptr || operation == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ auto* info = static_cast<aul::ResolveInfo*>(h);
+ auto& value = info->GetOperation();
+ *operation = strdup(value.empty() ? "NULL" : value.c_str());
+ if (*operation == nullptr) {
+ _E("Failed to duplicate operation");
+ return AUL_SVC_RET_ERROR;
+ }
+
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_info_get_uri(aul_svc_info_h h, char** uri) {
+ if (h == nullptr || uri == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ auto* info = static_cast<aul::ResolveInfo*>(h);
+ auto& value = info->GetUri();
+ *uri = strdup(value.empty() ? "NULL" : value.c_str());
+ if (*uri == nullptr) {
+ _E("Failed to duplicate URI");
+ return AUL_SVC_RET_ERROR;
+ }
+
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_info_get_uri_scheme(aul_svc_info_h h,
+ char** uri_scheme) {
+ if (h == nullptr || uri_scheme == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ auto* info = static_cast<aul::ResolveInfo*>(h);
+ auto& value = info->GetScheme();
+ *uri_scheme = strdup(value.empty() ? "NULL" : value.c_str());
+ if (*uri_scheme == nullptr) {
+ _E("Failed to duplicate URI scheme");
+ return AUL_SVC_RET_ERROR;
+ }
+
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_info_get_uri_host(aul_svc_info_h h,
+ char** uri_host) {
+ if (h == nullptr || uri_host == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ auto* info = static_cast<aul::ResolveInfo*>(h);
+ auto& value = info->GetHost();
+ *uri_host = strdup(value.empty() ? "NULL" : value.c_str());
+ if (*uri_host == nullptr) {
+ _E("Failed to duplicate URI host");
+ return AUL_SVC_RET_ERROR;
+ }
+
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_info_get_mime(aul_svc_info_h h, char** mime) {
+ if (h == nullptr || mime == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ auto* info = static_cast<aul::ResolveInfo*>(h);
+ auto& value = info->GetMime();
+ *mime = strdup(value.empty() ? "NULL" : value.c_str());
+ if (*mime == nullptr) {
+ _E("Failed to duplicate MIME-Type");
+ return AUL_SVC_RET_ERROR;
+ }
+
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_info_get_mime_type(aul_svc_info_h h,
+ char** mime_type) {
+ if (h == nullptr || mime_type == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ auto* info = static_cast<aul::ResolveInfo*>(h);
+ auto& value = info->GetMType();
+ *mime_type = strdup(value.empty() ? "NULL" : value.c_str());
+ if (*mime_type == nullptr) {
+ _E("Failed to duplicate the type of MIME-Type");
+ return AUL_SVC_RET_ERROR;
+ }
+
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_info_get_mime_subtype(aul_svc_info_h h,
+ char** mime_subtype) {
+ if (h == nullptr || mime_subtype == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ auto* info = static_cast<aul::ResolveInfo*>(h);
+ auto& value = info->GetSType();
+ *mime_subtype = strdup(value.empty() ? "NULL" : value.c_str());
+ if (*mime_subtype == nullptr) {
+ _E("Failed to duplicate the subtype of MIME-Type");
+ return AUL_SVC_RET_ERROR;
+ }
+
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_info_destroy(aul_svc_info_h h) {
+ if (h == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ auto* info = static_cast<aul::ResolveInfo*>(h);
+ delete info;
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_set_caller_instance_id(bundle* b,
+ const char* instance_id) {
+ if (b == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ return ::SetBundle(b, AUL_K_CALLER_INSTANCE_ID, instance_id);
+}
+
+extern "C" API int aul_svc_set_comp_id(bundle* b, const char* comp_id) {
+ if (b == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ return ::SetBundle(b, AUL_K_COMPONENT_ID, comp_id);
+}
+
+extern "C" API const char *aul_svc_get_comp_id(bundle* b) {
+ return bundle_get_val(b, AUL_K_COMPONENT_ID);
+}
+
+extern "C" API int aul_svc_subapp_terminate_request(bundle* b, int pid) {
+ if (b == nullptr || pid < 0) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ const char* inst_id = bundle_get_val(b, AUL_K_INSTANCE_ID);
+ if (inst_id == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ char buf[512] = { 0, };
+ const char* caller_inst_id = bundle_get_val(b, AUL_K_CALLER_INSTANCE_ID);
+ if (caller_inst_id == nullptr) {
+ int ret = aul_app_get_instance_id_bypid(getpid(), buf, sizeof(buf));
+ if (ret != AUL_R_OK) {
+ _E("aul_app_get_instance_id_bypid() is failed. error(%d)", ret);
+ return AUL_SVC_RET_ERROR;
+ }
+
+ caller_inst_id = buf;
+ }
+
+ int cnt = 0;
+ aul_app_group_foreach_group_info(caller_inst_id,
+ [](aul_app_group_info_h info, void* data) {
+ int* count = static_cast<int*>(data);
+ (*count)++;
+ }, static_cast<void*>(&cnt));
+ if (cnt == 0)
+ return aul_subapp_terminate_request(inst_id, pid);
+
+ return aul_app_group_clear_top();
+}
+
+extern "C" API int aul_svc_send_resume_request(bundle* b, int request_code,
+ aul_svc_err_cb err_cb, void *user_data) {
+ return aul_svc_send_resume_request_for_uid(b, request_code, err_cb, user_data,
+ getuid());
+}
+
+extern "C" API int aul_svc_send_resume_request_for_uid(bundle* b,
+ int request_code, aul_svc_err_cb err_cb, void* user_data, uid_t uid) {
+ if (b == nullptr || err_cb == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ auto* cb_info = new (std::nothrow) CbInfo(request_code, nullptr, err_cb,
+ user_data);
+ if (cb_info == nullptr)
+ _E("Out of memory");
+
+ int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
+ [](const std::string& appid, bundle* request, uid_t uid,
+ CbInfo* info) -> int {
+ return aul_send_resume_request_for_uid(appid.c_str(), request, uid,
+ ErrorCb, info);
+ }, b, uid, cb_info);
+ if (ret < 0) {
+ delete cb_info;
+ ret = ::AulErrorConvert(ret);
+ }
+
+ return ret;
+}
+
+extern "C" API int aul_svc_get_appid_array(bundle* b, uid_t uid,
+ char*** appid_array, unsigned int* len) {
+ if (b == nullptr || appid_array == nullptr || len == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ bundle_del(b, AUL_K_APPID);
+ bundle_add(b, AUL_K_APPID, "@UNKNOWN");
+
+ bundle* response;
+ int ret = ::SendAndReceive(APP_GET_APPID_LIST, uid, b, &response);
+ if (ret != AUL_SVC_RET_OK)
+ return ret;
+
+ tizen_base::Bundle res(response, false, true);
+ auto str = res.GetString(AUL_SVC_K_URI_R_INFO);
+ if (!str.empty())
+ ::SetBundle(b, AUL_SVC_K_URI_R_INFO, str.c_str());
+
+ auto str_arr = res.GetStringArray(AUL_K_APPID_LIST);
+ if (str_arr.empty()) {
+ _E("Failed to get appid list");
+ return AUL_SVC_RET_ERROR;
+ }
+
+ *appid_array = reinterpret_cast<char**>(
+ calloc(str_arr.size(), sizeof(char*)));
+ if (*appid_array == nullptr) {
+ _E("Out of memory");
+ return AUL_SVC_RET_ENOMEM;
+ }
+
+ *len = str_arr.size();
+
+ int i = 0;
+ for (auto& appid : str_arr)
+ (*appid_array)[i++] = strdup(appid.c_str());
+
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API void aul_svc_free_appid_array(char** appid_array,
+ unsigned int len) {
+ if (appid_array == nullptr)
+ return;
+
+ for (unsigned int i = 0; i < len; ++i)
+ free(appid_array[i]);
+
+ free(appid_array);
+}
+
+extern "C" API int aul_svc_set_window_position(bundle* b,
+ int x, int y, int w, int h) {
+ if (b == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ ::SetBundle(b, AUL_K_HINT_SCREEN_POS_X, std::to_string(x).c_str());
+ ::SetBundle(b, AUL_K_HINT_SCREEN_POS_Y, std::to_string(y).c_str());
+ ::SetBundle(b, AUL_K_HINT_SCREEN_WIDTH, std::to_string(w).c_str());
+ ::SetBundle(b, AUL_K_HINT_SCREEN_HEIGHT, std::to_string(h).c_str());
+
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_get_window_position(bundle* b,
+ int* x, int* y, int* w, int* h) {
+ if (b == nullptr ||
+ x == nullptr ||
+ y == nullptr ||
+ w == nullptr ||
+ h == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ char* x_str = nullptr;
+ char* y_str = nullptr;
+ char* w_str = nullptr;
+ char* h_str = nullptr;
+
+ bundle_get_str(b , AUL_K_HINT_SCREEN_POS_X, &x_str);
+ bundle_get_str(b , AUL_K_HINT_SCREEN_POS_Y, &y_str);
+ bundle_get_str(b , AUL_K_HINT_SCREEN_WIDTH, &w_str);
+ bundle_get_str(b , AUL_K_HINT_SCREEN_HEIGHT, &h_str);
+
+ if (x_str == nullptr ||
+ y_str == nullptr ||
+ w_str == nullptr ||
+ h_str == nullptr) {
+ _E("failed to get position");
+ return AUL_SVC_RET_ERROR;
+ }
+
+ *x = atoi(x_str);
+ *y = atoi(y_str);
+ *w = atoi(w_str);
+ *h = atoi(h_str);
+
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_set_defapp(const char* op, const char* mime_type,
+ const char* uri, const char* defapp) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_set_defapp_for_uid(const char* op,
+ const char* mime_type, const char* uri, const char* defapp, uid_t uid) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_unset_defapp(const char* defapp) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_unset_defapp_for_uid(const char* defapp, uid_t uid) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_unset_all_defapps(void) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_unset_all_defapps_for_uid(uid_t uid) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_is_defapp(const char* pkg_name) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_is_defapp_for_uid(const char* pkg_name, uid_t uid) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_set_alias_appid(const char* alias_appid,
+ const char* appid) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_set_alias_appid_for_uid(const char* alias_appid,
+ const char* appid, uid_t uid) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_unset_alias_appid(const char* alias_appid) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_unset_alias_appid_for_uid(const char* alias_appid,
+ uid_t uid) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_foreach_alias_info(
+ void (*callback)(const char *, const char *, void *),
+ void* user_data) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_foreach_alias_info_for_uid(
+ void (*callback)(const char *, const char *, void *),
+ uid_t uid, void* user_data) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_enable_alias_info(const char* appid) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_enable_alias_info_for_uid(const char* appid,
+ uid_t uid) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_disable_alias_info(const char* appid) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_disable_alias_info_for_uid(const char* appid,
+ uid_t uid) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_foreach_alias_info_by_appid(
+ int (*callback)(const char *, const char *, void *),
+ const char* appid, void* user_data) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_foreach_alias_info_by_appid_for_uid(
+ int (*callback)(const char *, const char *, void *),
+ const char* appid, uid_t uid, void* user_data) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_foreach_allowed_info(
+ int (*callback)(const char *, const char *, void *),
+ void* user_data) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_foreach_allowed_info_for_uid(
+ int (*callback)(const char *, const char *, void *),
+ uid_t uid, void* user_data) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_foreach_allowed_info_by_appid(
+ int (*callback)(const char *, const char *, void *),
+ const char* appid, void* user_data) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_foreach_allowed_info_by_appid_for_uid(
+ int (*callback)(const char *, const char *, void *),
+ const char* appid, uid_t uid, void* user_data) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
--- /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) 2016 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 <stdlib.h>
+#include <system_info.h>
+#include "aul_util.h"
+
+tizen_profile_t _get_tizen_profile(void)
+{
+ static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
+ char *profile_name = NULL;
+
+ if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
+ return profile;
+
+ system_info_get_platform_string("http://tizen.org/feature/profile",
+ &profile_name);
+ if (profile_name == NULL)
+ return profile;
+
+ switch (*profile_name) {
+ case 'm':
+ case 'M':
+ profile = TIZEN_PROFILE_MOBILE;
+ break;
+ case 'w':
+ case 'W':
+ profile = TIZEN_PROFILE_WEARABLE;
+ break;
+ case 't':
+ case 'T':
+ profile = TIZEN_PROFILE_TV;
+ break;
+ case 'i':
+ case 'I':
+ profile = TIZEN_PROFILE_IVI;
+ break;
+ default: /* common or unknown ==> ALL ARE COMMON. */
+ profile = TIZEN_PROFILE_COMMON;
+ break;
+ }
+ free(profile_name);
+
+ return profile;
+}
--- /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"
+
+#undef _E
+#define _E(fmt, arg...) LOGE(fmt, ##arg)
+
+#undef _D
+#define _D(fmt, arg...) LOGD(fmt, ##arg)
+
+#undef _W
+#define _W(fmt, arg...) LOGW(fmt, ##arg)
+
+#undef _I
+#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)
+#define TIZEN_FEATURE_APPSVC_ALIAS (!(_get_tizen_profile() & TIZEN_PROFILE_TV))
+
+#ifdef __cplusplus
+}
+#endif
--- /dev/null
+/*
+ * Copyright (c) 2019 - 2022 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 "aul/include/aul_watch_control.h"
+
+#include <algorithm>
+#include <iterator>
+#include <list>
+
+#include "aul/aul_api.h"
+#include "aul/aul_util.h"
+#include "aul/aul_watch_control_internal.h"
+#include "aul/include/aul.h"
+
+namespace {
+
+class WatchControl {
+ public:
+ WatchControl(aul_watch_control_cb cb, void* user_data)
+ : cb_(cb), user_data_(user_data) {
+ }
+
+ void Invoke(bundle* b) {
+ if (cb_)
+ cb_(b, user_data_);
+ }
+
+ private:
+ aul_watch_control_cb cb_;
+ void* user_data_;
+};
+
+std::list<WatchControl*> controls;
+
+} // namespace
+
+extern "C" API int aul_watch_control_add_handler(aul_watch_control_cb callback,
+ void* user_data, aul_watch_control_h* handle) {
+ if (callback == nullptr || handle == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* control = new (std::nothrow) WatchControl(callback, user_data);
+ if (control == nullptr) {
+ _E("Out of memory");
+ return AUL_R_ENOMEM;
+ }
+
+ controls.push_back(control);
+ *handle = static_cast<aul_watch_control_h>(control);
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_watch_control_remove_handler(
+ aul_watch_control_h handle) {
+ if (handle == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* control = static_cast<WatchControl*>(handle);
+ auto found = std::find(controls.begin(), controls.end(), control);
+ if (found == controls.end()) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ controls.erase(found);
+ delete control;
+ return AUL_R_OK;
+}
+
+void aul_watch_control_invoke(bundle* b) {
+ if (controls.empty())
+ return;
+
+ for (auto control : controls)
+ control->Invoke(b);
+}
--- /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_WATCH_CONTROL_INTERNAL_H__
+#define __AUL_WATCH_CONTROL_INTERNAL_H__
+
+#include <bundle.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void aul_watch_control_invoke(bundle *b);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __AUL_WATCH_CONTROL_INTERNAL_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2018 - 2022 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 "aul/include/aul_watchdog.h"
+
+#include <glib.h>
+
+#include "aul/app_request.h"
+#include "aul/aul_api.h"
+#include "aul/aul_util.h"
+#include "aul/common/exception.hh"
+#include "aul/include/aul.h"
+#include "aul/include/aul_error.h"
+
+using namespace aul;
+
+namespace {
+using namespace aul::internal;
+
+class WatchdogContext {
+ public:
+ WatchdogContext() = default;
+
+ ~WatchdogContext() {
+ Stop();
+
+ if (enabled_) {
+ try {
+ Disable();
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%d)", e.GetErrorCode());
+ }
+ }
+ }
+
+ void Enable() {
+ if (enabled_) {
+ _W("Already enabled");
+ return;
+ }
+
+ int ret = AppRequest(WATCHDOG_ENABLE, getuid())
+ .SendCmdOnly(AUL_SOCK_NOREPLY);
+ if (ret < 0)
+ THROW(aul_error_convert(ret));
+
+ enabled_ = true;
+ _D("Enabled");
+ }
+
+ void Disable() {
+ if (!enabled_)
+ THROW(AUL_R_ERROR);
+
+ int ret = AppRequest(WATCHDOG_DISABLE, getuid())
+ .SendCmdOnly(AUL_SOCK_NOREPLY);
+ if (ret < 0)
+ THROW(aul_error_convert(ret));
+
+ enabled_ = false;
+ _D("Disabled");
+ }
+
+ void Kick() {
+ if (!enabled_)
+ THROW(AUL_R_ERROR);
+
+ int ret = AppRequest(WATCHDOG_KICK, getuid())
+ .SendCmdOnly(AUL_SOCK_NOREPLY);
+ if (ret < 0)
+ THROW(aul_error_convert(ret));
+
+ Stop();
+ Start(interval_);
+ _D("Kicked");
+ }
+
+ void Start(unsigned int interval) {
+ _D("Interval: %u", interval);
+ if (interval == 0) {
+ _E("Invalid parameter");
+ return;
+ }
+
+ if (timer_ != 0) {
+ _E("Already started");
+ return;
+ }
+
+ enabled_ = true;
+ interval_ = interval;
+ timer_ = g_timeout_add(interval,
+ [](gpointer user_data) -> gboolean {
+ auto* handle = static_cast<WatchdogContext*>(user_data);
+ try {
+ handle->Ping();
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%d)", e.GetErrorCode());
+ }
+
+ return G_SOURCE_CONTINUE;
+ }, this);
+
+ try {
+ Ping();
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%d)", e.GetErrorCode());
+ }
+ }
+
+ void Stop() {
+ if (timer_ == 0)
+ return;
+
+ g_source_remove(timer_);
+ timer_ = 0;
+ }
+
+ bool IsEnabled() const {
+ return enabled_;
+ }
+
+ private:
+ void Ping() {
+ int ret = AppRequest(WATCHDOG_PING, getuid())
+ .SendCmdOnly(AUL_SOCK_NOREPLY);
+ if (ret < 0)
+ THROW(aul_error_convert(ret));
+
+ _D("Ping");
+ }
+
+ private:
+ bool enabled_ = false;
+ unsigned int interval_ = 0;
+ guint timer_ = 0;
+};
+
+WatchdogContext context;
+
+} // namespace
+
+extern "C" API int aul_watchdog_enable(void) {
+ try {
+ context.Enable();
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%d)", e.GetErrorCode());
+ return e.GetErrorCode();
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_watchdog_disable(void) {
+ try {
+ context.Disable();
+ } catch (const Exception& e) {
+ if (context.IsEnabled())
+ _E("Exception occurs. error(%d)", e.GetErrorCode());
+
+ return e.GetErrorCode();
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_watchdog_kick(void) {
+ try {
+ context.Kick();
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%d)", e.GetErrorCode());
+ return e.GetErrorCode();
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" void aul_watchdog_start(unsigned int interval) {
+ context.Start(interval);
+}
+
+extern "C" void aul_watchdog_stop(void) {
+ context.Stop();
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 - 2021 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 "aul/include/aul_window.h"
+
+#include <bundle_cpp.h>
+#include <gio/gio.h>
+#include <glib.h>
+#include <stdbool.h>
+#include <stdio.h>
+
+#include <memory>
+#include <mutex>
+#include <string>
+
+#include "aul/app_request.h"
+#include "aul/aul_api.h"
+#include "aul/aul_util.h"
+#include "aul/include/aul.h"
+#include "aul/include/aul_app_com.h"
+#include "aul/include/aul_cmd.h"
+#include "aul/launch.h"
+
+using namespace aul;
+using namespace aul::internal;
+
+namespace {
+
+constexpr const char kWmBusName[] = "org.enlightenment.wm";
+constexpr const char kWmObjectPath[] = "/org/enlightenment/wm";
+constexpr const char kWmInterfaceName[] = "org.enlightenment.wm.proc";
+constexpr const char kWmMethodNameInfo[] = "GetVisibleWinInfo";
+constexpr const char kWmMethodNameFocus[] = "GetFocusProc";
+constexpr const unsigned int kWmDbusTimeout = 5000;
+
+GDBusConnection* system_conn;
+
+GDBusConnection* GetConn() {
+ if (system_conn == nullptr) {
+ GError* error = nullptr;
+ system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &error);
+ if (system_conn == nullptr) {
+ _E("g_bus_get_sync() is failed. error(%s)",
+ error ? error->message : "Unknown");
+ g_clear_error(&error);
+ return nullptr;
+ }
+ }
+
+ return system_conn;
+}
+
+class WindowInfo {
+ public:
+ WindowInfo(unsigned int rid, int x, int y, int w, int h,
+ bool alpha, int visibility, bool focused, int pid, int ppid,
+ int apid, int noti_level, bool opaque)
+ : rid_(rid), x_(x), y_(y), w_(w), h_(h), alpha_(alpha),
+ visibility_(visibility), focused_(focused), pid_(pid),
+ ppid_(ppid), apid_(apid), noti_level_(noti_level), opaque_(opaque) {
+ }
+
+ unsigned int GetResourceId() const {
+ return rid_;
+ }
+
+ int GetPositionX() const {
+ return x_;
+ }
+
+ int GetPositionY() const {
+ return y_;
+ }
+
+ int GetWidth() const {
+ return w_;
+ }
+
+ int GetHeight() const {
+ return h_;
+ }
+
+ bool HasAlpha() const {
+ return alpha_;
+ }
+
+ int GetVisibility() const {
+ return visibility_;
+ }
+
+ bool IsFocused() const {
+ return focused_;
+ }
+
+ int GetPid() const {
+ return pid_;
+ }
+
+ int GetParentPid() const {
+ return ppid_;
+ }
+
+ int GetAncestorPid() const {
+ return apid_;
+ }
+
+ int GetNotificationLevel() const {
+ return noti_level_;
+ }
+
+ bool IsOpaque() const {
+ return opaque_;
+ }
+
+ private:
+ unsigned int rid_;
+ int x_;
+ int y_;
+ int w_;
+ int h_;
+ bool alpha_;
+ int visibility_;
+ bool focused_;
+ int pid_;
+ int ppid_;
+ int apid_;
+ int noti_level_;
+ bool opaque_;
+};
+
+void WindowInfoDestroyFunc(gpointer data) {
+ auto* info = static_cast<WindowInfo*>(data);
+ if (info == nullptr)
+ return;
+
+ delete info;
+}
+
+class WindowEventListener {
+ public:
+ WindowEventListener() = default;
+
+ ~WindowEventListener() {
+ Deregister();
+ }
+
+ int Register(aul_window_event_cb cb, void* user_data) {
+ std::lock_guard<std::recursive_mutex> lock(GetMutex());
+ cb_ = cb;
+ user_data_ = user_data;
+
+ if (conn_ != nullptr)
+ return AUL_R_OK;
+
+ int ret = aul_app_com_create_async("aul_window_event", nullptr,
+ AppComMessageCb, this, &conn_);
+ if (ret != AUL_R_OK) {
+ _E("aul_app_com_create_async() is failed. error(%d)", ret);
+ return ret;
+ }
+
+ return AUL_R_OK;
+ }
+
+ void Deregister() {
+ std::lock_guard<std::recursive_mutex> lock(GetMutex());
+ cb_ = nullptr;
+ user_data_ = nullptr;
+
+ if (conn_ == nullptr)
+ return;
+
+ aul_app_com_leave(conn_);
+ conn_ = nullptr;
+ }
+
+ private:
+ static int AppComMessageCb(const char* endpoint, aul_app_com_result_e res,
+ bundle* envelope, void* user_data) {
+ tizen_base::Bundle b(envelope, false, false);
+ std::string event_name = b.GetString(AUL_K_EVENT_NAME);
+ std::string appid = b.GetString(AUL_K_APPID);
+ int wid = std::stoi(b.GetString(AUL_K_WID));
+ int pid = std::stoi(b.GetString(AUL_K_PID));
+
+ auto* handle = static_cast<WindowEventListener*>(user_data);
+ std::lock_guard<std::recursive_mutex> lock(handle->GetMutex());
+ if (handle->cb_) {
+ handle->cb_(event_name.c_str(), appid.c_str(), wid, pid,
+ handle->user_data_);
+ }
+
+ return 0;
+ }
+
+ std::recursive_mutex& GetMutex() const {
+ return mutex_;
+ }
+
+ private:
+ aul_app_com_connection_h conn_ = nullptr;
+ aul_window_event_cb cb_ = nullptr;
+ void* user_data_ = nullptr;
+ mutable std::recursive_mutex mutex_;
+};
+
+WindowEventListener listener;
+
+} // namespace
+
+extern "C" API int aul_window_stack_get(aul_window_stack_h* handle) {
+ if (handle == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ GDBusConnection* conn = GetConn();
+ if (conn == nullptr)
+ return AUL_R_ERROR;
+
+ auto* msg = g_dbus_message_new_method_call(kWmBusName,
+ kWmObjectPath, kWmInterfaceName, kWmMethodNameInfo);
+ if (msg == nullptr) {
+ _E("g_dbus_message_new_method_call() is faield");
+ return AUL_R_ERROR;
+ }
+ std::unique_ptr<GDBusMessage, decltype(g_object_unref)*> msg_auto(
+ msg, g_object_unref);
+
+ GError* error = nullptr;
+ auto* reply = g_dbus_connection_send_message_with_reply_sync(conn, msg,
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE, kWmDbusTimeout, nullptr, nullptr, &error);
+ if (reply == nullptr || error != nullptr) {
+ _E("g_dbus_connection_send_message_with_reply_sync() is failed. error(%s)",
+ error ? error->message : "Unknown");
+ g_clear_error(&error);
+ return AUL_R_ERROR;
+ }
+ std::unique_ptr<GDBusMessage, decltype(g_object_unref)*> reply_auto(
+ reply, g_object_unref);
+
+ auto* body = g_dbus_message_get_body(reply);
+ if (body == nullptr) {
+ _E("g_dbus_message_get_body() is failed");
+ return AUL_R_ERROR;
+ }
+
+ unsigned int rid = 0;
+ int x = -1;
+ int y = -1;
+ int w = -1;
+ int h = -1;
+ gboolean alpha = FALSE;
+ int visibility = -1;
+ gboolean focused = FALSE;
+ int pid = -1;
+ int ppid = -1;
+ int apid = -1;
+ int noti_level = -1;
+ gboolean opaque = FALSE;
+
+ GVariantIter* iter = nullptr;
+ g_variant_get(body, "(a(uiiiibibiiiib))", &iter);
+ if (iter == nullptr)
+ return AUL_R_ERROR;
+
+ std::unique_ptr<GVariantIter, decltype(g_variant_iter_free)*> iter_auto(
+ iter, g_variant_iter_free);
+
+ GList* list = nullptr;
+ while (g_variant_iter_loop(iter, "(uiiiibibiiiib)",
+ &rid,
+ &x,
+ &y,
+ &w,
+ &h,
+ &alpha,
+ &visibility,
+ &focused,
+ &pid,
+ &ppid,
+ &apid,
+ ¬i_level,
+ &opaque)) {
+ auto* info = new (std::nothrow) WindowInfo(rid, x, y, w, h,
+ alpha ? true : false, visibility, focused ? true : false,
+ pid, ppid, apid, noti_level, opaque ? true : false);
+ if (info == nullptr) {
+ _E("Out of memory");
+ g_list_free_full(list, WindowInfoDestroyFunc);
+ return AUL_R_ENOMEM;
+ }
+
+ list = g_list_append(list, info);
+ }
+
+ *handle = static_cast<aul_window_stack_h>(list);
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_window_stack_del(aul_window_stack_h handle) {
+ if (handle == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* list = static_cast<GList*>(handle);
+ g_list_free_full(list, WindowInfoDestroyFunc);
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_window_stack_foreach(aul_window_stack_h handle,
+ void (*iter_cb)(aul_window_info_h info, void* data), void* data) {
+ if (handle == nullptr || iter_cb == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* iter = static_cast<GList*>(handle);
+ while (iter) {
+ iter_cb(static_cast<aul_window_info_h>(iter->data), data);
+ iter = g_list_next(iter);
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_window_stack_info_get_resource_id(aul_window_info_h info,
+ unsigned int* rid) {
+ if (info == nullptr || rid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* handle = static_cast<WindowInfo*>(info);
+ *rid = handle->GetResourceId();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_window_info_get_pid(aul_window_info_h info, int* pid) {
+ if (info == nullptr || pid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* handle = static_cast<WindowInfo*>(info);
+ *pid = handle->GetPid();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_window_info_get_parent_pid(aul_window_info_h info,
+ int* ppid) {
+ if (info == nullptr || ppid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* handle = static_cast<WindowInfo*>(info);
+ *ppid = handle->GetParentPid();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_window_info_get_ancestor_pid(aul_window_info_h info,
+ int* apid) {
+ if (info == nullptr || apid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* handle = static_cast<WindowInfo*>(info);
+ *apid = handle->GetAncestorPid();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_window_info_get_visibility(aul_window_info_h info,
+ int* visibility) {
+ if (info == nullptr || visibility == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* handle = static_cast<WindowInfo*>(info);
+ *visibility = handle->GetVisibility();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_window_info_has_alpha(aul_window_info_h info,
+ bool* alpha) {
+ if (info == nullptr || alpha == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* handle = static_cast<WindowInfo*>(info);
+ *alpha = handle->HasAlpha();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_window_info_is_focused(aul_window_info_h info,
+ bool* focused) {
+ if (info == nullptr || focused == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* handle = static_cast<WindowInfo*>(info);
+ *focused = handle->IsFocused();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_window_info_get_geometry(aul_window_info_h info,
+ int* x, int* y, int* w, int* h) {
+ if (info == nullptr ||
+ x == nullptr ||
+ y == nullptr ||
+ w == nullptr ||
+ h == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* handle = static_cast<WindowInfo*>(info);
+ *x = handle->GetPositionX();
+ *y = handle->GetPositionY();
+ *w = handle->GetWidth();
+ *h = handle->GetHeight();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_window_info_get_notification_level(
+ aul_window_info_h info, aul_window_notification_level_e* level) {
+ if (info == nullptr || level == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* handle = static_cast<WindowInfo*>(info);
+ *level = static_cast<aul_window_notification_level_e>(
+ handle->GetNotificationLevel());
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_window_info_get_opaque(aul_window_info_h info,
+ bool* opaque) {
+ if (info == nullptr || opaque == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* handle = static_cast<WindowInfo*>(info);
+ *opaque = handle->IsOpaque();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_window_get_focused_pid(pid_t* pid) {
+ if (pid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ GDBusConnection* conn = GetConn();
+ if (conn == nullptr)
+ return AUL_R_ERROR;
+
+ auto* msg = g_dbus_message_new_method_call(kWmBusName,
+ kWmObjectPath, kWmInterfaceName, kWmMethodNameFocus);
+ if (msg == nullptr) {
+ _E("g_dbus_message_new_method_call() is failed");
+ return AUL_R_ERROR;
+ }
+ std::unique_ptr<GDBusMessage, decltype(g_object_unref)*> msg_auto(
+ msg, g_object_unref);
+
+ GError* error = nullptr;
+ auto* reply = g_dbus_connection_send_message_with_reply_sync(conn, msg,
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE, kWmDbusTimeout, nullptr, nullptr,
+ &error);
+ if (reply == nullptr || error != nullptr) {
+ _E("g_dbus_connection_send_message_with_reply_sync() is failed. error(%s)",
+ error ? error->message : "Unknown");
+ g_clear_error(&error);
+ return AUL_R_ERROR;
+ }
+ std::unique_ptr<GDBusMessage, decltype(g_object_unref)*> reply_auto(
+ reply, g_object_unref);
+
+ auto* body = g_dbus_message_get_body(reply);
+ if (body == nullptr) {
+ _E("g_dbus_message_get_body() is failed");
+ return AUL_R_ERROR;
+ }
+
+ gint focused_pid = -1;
+ g_variant_get(body, "(i)", &focused_pid);
+ *pid = static_cast<pid_t>(focused_pid);
+ _W("Result = %d", focused_pid);
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_window_attach(const char* parent_appid,
+ const char* child_appid) {
+ if (parent_appid == nullptr || child_appid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ tizen_base::Bundle b {
+ { AUL_K_PARENT_APPID, parent_appid },
+ { AUL_K_CHILD_APPID, child_appid }
+ };
+ int ret = AppRequest(APP_WINDOW_ATTACH, getuid())
+ .With(b)
+ .SendSimply();
+ if (ret < 0) {
+ _E("Failed to send request. error(%d)", ret);
+ return ret;
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_window_detach(const char* child_appid) {
+ if (child_appid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ tizen_base::Bundle b {{ AUL_K_CHILD_APPID, child_appid }};
+ int ret = AppRequest(APP_WINDOW_DETACH, getuid())
+ .With(b)
+ .SendSimply();
+ if (ret < 0) {
+ _E("Failed to send request. error(%d)", ret);
+ return ret;
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_window_attach_below(const char* parent_appid,
+ const char* child_appid) {
+ if (parent_appid == nullptr || child_appid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ tizen_base::Bundle b {
+ { AUL_K_PARENT_APPID, parent_appid },
+ { AUL_K_CHILD_APPID, child_appid }
+ };
+ int ret = AppRequest(APP_WINDOW_ATTACH_BELOW, getuid())
+ .With(b)
+ .SendSimply();
+ if (ret < 0) {
+ _E("Failed to send request. error(%d)", ret);
+ return ret;
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_window_register_event_cb(aul_window_event_cb callback,
+ void* user_data) {
+ if (callback == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ int ret = listener.Register(callback, user_data);
+ if (ret != AUL_R_OK)
+ return ret;
+
+ return AUL_R_OK;
+}
+
+extern "C" API void aul_window_deregister_event_cb(void) {
+ listener.Deregister();
+}
--- /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 <pthread.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/syscall.h>
+#include <fcntl.h>
+#include <glib.h>
+#include <gio/gio.h>
+
+#include "aul.h"
+#include "aul_util.h"
+#include "aul_sock.h"
+#include "aul_worker.h"
+
+#define DEFAULT_INTERVAL 5000
+
+struct job_s {
+ char *name;
+ GIOChannel *channel;
+ guint tag;
+ void *callback;
+ void *user_data;
+};
+
+struct anr_timer_s {
+ guint tag;
+ gint64 start_time;
+ GQueue *cmd_queue;
+};
+
+struct aul_worker_s {
+ char *name;
+ GThread *thread;
+ GMutex mutex;
+ GCond cond;
+ GMainContext *context;
+ GMainLoop *loop;
+ GList *jobs;
+ struct anr_timer_s *anr_timer;
+};
+
+static void __destroy_anr_timer(struct anr_timer_s *timer)
+{
+ g_queue_free(timer->cmd_queue);
+ free(timer);
+}
+
+static struct anr_timer_s *__create_anr_timer(void)
+{
+ struct anr_timer_s *timer;
+
+ timer = calloc(1, sizeof(struct anr_timer_s));
+ if (!timer) {
+ _E("Out of memory");
+ return NULL;
+ }
+
+ timer->cmd_queue = g_queue_new();
+ if (!timer->cmd_queue) {
+ _E("Failed to create GQueue");
+ __destroy_anr_timer(timer);
+ return NULL;
+ }
+
+ return timer;
+}
+
+static void __destroy_job(gpointer data)
+{
+ struct job_s *job = (struct job_s *)data;
+ GSource *source;
+ GMainContext *context;
+
+ if (job->channel)
+ g_io_channel_unref(job->channel);
+
+ if (job->tag) {
+ context = g_main_context_get_thread_default();
+ source = g_main_context_find_source_by_id(context, job->tag);
+ _W("GMainContext(%p), GSource(%p)", context, source);
+ if (source && !g_source_is_destroyed(source)) {
+ _W("Destroy GSource(%p)", source);
+ g_source_destroy(source);
+ }
+ }
+
+ free(job->name);
+ free(job);
+}
+
+static struct job_s *__create_job(const char *name,
+ GIOChannel *channel,
+ void *callback,
+ void *user_data)
+{
+ struct job_s *job;
+
+ job = calloc(1, sizeof(struct job_s));
+ if (!job) {
+ _E("Failed to create job");
+ return NULL;
+ }
+
+ job->name = strdup(name);
+ if (!job->name) {
+ _E("Failed to duplicate job name");
+ __destroy_job(job);
+ return NULL;
+ }
+
+ job->channel = channel;
+ job->callback = callback;
+ job->user_data = user_data;
+
+ return job;
+}
+
+static int __set_comm(const char *name)
+{
+ int fd;
+ ssize_t bytes_written;
+ char path[PATH_MAX];
+ pid_t tid = syscall(__NR_gettid);
+
+ _I("[%s] TID(%d)", name, tid);
+ snprintf(path, sizeof(path), "/proc/%d/comm", tid);
+ fd = open(path, O_WRONLY);
+ if (fd < 0) {
+ _E("Failed to open %s. error(%d)", path, errno);
+ return -1;
+ }
+
+ bytes_written = write(fd, name, strlen(name) + 1);
+ if (bytes_written < 0) {
+ _E("Failed to write name(%s)", name);
+ close(fd);
+ return -1;
+ }
+
+ close(fd);
+
+ return 0;
+}
+
+static GIOCondition __convert_aul_io_condition(int condition)
+{
+ GIOCondition cond = 0;
+
+ if (condition & AUL_IO_IN)
+ cond |= G_IO_IN;
+ if (condition & AUL_IO_OUT)
+ cond |= G_IO_OUT;
+ if (condition & AUL_IO_PRI)
+ cond |= G_IO_PRI;
+ if (condition & AUL_IO_HUP)
+ cond |= G_IO_HUP;
+ if (condition & AUL_IO_ERR)
+ cond |= G_IO_ERR;
+ if (condition & AUL_IO_NVAL)
+ cond |= G_IO_NVAL;
+
+ return cond;
+}
+
+static int __convert_g_io_condition(GIOCondition condition)
+{
+ int cond = 0;
+
+ if (condition & G_IO_IN)
+ cond |= AUL_IO_IN;
+ if (condition & G_IO_OUT)
+ cond |= AUL_IO_OUT;
+ if (condition & G_IO_PRI)
+ cond |= AUL_IO_PRI;
+ if (condition & G_IO_HUP)
+ cond |= AUL_IO_HUP;
+ if (condition & G_IO_ERR)
+ cond |= AUL_IO_ERR;
+ if (condition & G_IO_NVAL)
+ cond |= AUL_IO_NVAL;
+
+ return cond;
+}
+
+static gboolean __io_job_handler(GIOChannel *io, GIOCondition condition,
+ gpointer data)
+{
+ int fd = g_io_channel_unix_get_fd(io);
+ struct job_s *job = (struct job_s *)data;
+ aul_worker_io_job_cb callback;
+ GSource *source;
+ int cond;
+
+ source = g_main_current_source();
+ if (!source || g_source_is_destroyed(source)) {
+ _E("[__JOB__] GSource(%p) is destroyed", source);
+ return G_SOURCE_REMOVE;
+ }
+
+ cond = __convert_g_io_condition(condition);
+ callback = (aul_worker_io_job_cb)job->callback;
+ if (callback(fd, cond, job->user_data))
+ return G_SOURCE_CONTINUE;
+
+ _I("[__JOB__] name(%s)", job->name);
+ job->tag = 0;
+
+ return G_SOURCE_REMOVE;
+}
+
+int aul_worker_add_io_job(aul_worker_h handle, const char *job_name,
+ int fd, int condition, bool do_close,
+ aul_worker_io_job_cb callback,
+ void *user_data)
+{
+ GIOCondition cond = __convert_aul_io_condition(condition);
+ struct aul_worker_s *worker = (struct aul_worker_s *)handle;
+ struct job_s *job;
+ GIOChannel *channel;
+ GSource *source;
+
+ if (!worker || !job_name || fd < 0 || !callback) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ channel = g_io_channel_unix_new(fd);
+ if (!channel) {
+ _E("Failed to create GIOChannel");
+ if (do_close)
+ close(fd);
+
+ return AUL_R_ENOMEM;
+ }
+
+ g_io_channel_set_close_on_unref(channel, do_close);
+ source = g_io_create_watch(channel, cond);
+ if (!source) {
+ _E("Failed to create GSource");
+ g_io_channel_unref(channel);
+ return AUL_R_ENOMEM;
+ }
+
+ job = __create_job(job_name, channel, callback, user_data);
+ if (!job) {
+ _E("Failed to create job(%s)", job_name);
+ g_source_unref(source);
+ g_io_channel_unref(channel);
+ return AUL_R_ENOMEM;
+ }
+
+ g_source_set_callback(source, (GSourceFunc)__io_job_handler, job, NULL);
+ g_source_set_priority(source, G_PRIORITY_DEFAULT);
+
+ g_mutex_lock(&worker->mutex);
+ worker->jobs = g_list_append(worker->jobs, job);
+ job->tag = g_source_attach(source, worker->context);
+ _W("GMainContext(%p), GSource(%p)", worker->context, source);
+ g_mutex_unlock(&worker->mutex);
+
+ g_source_unref(source);
+
+ return AUL_R_OK;
+}
+
+void aul_worker_remove_io_job(aul_worker_h handle, int fd)
+{
+ struct aul_worker_s *worker = handle;
+ struct job_s *job;
+ GList *iter;
+
+ if (worker == NULL || fd < 0) {
+ _E("Invalid parameter");
+ return;
+ }
+
+ g_mutex_lock(&worker->mutex);
+ iter = worker->jobs;
+ while (iter != NULL) {
+ job = iter->data;
+ iter = g_list_next(iter);
+ if (job->channel == NULL)
+ continue;
+
+ if (g_io_channel_unix_get_fd(job->channel) == fd) {
+ worker->jobs = g_list_remove(worker->jobs, job);
+ __destroy_job(job);
+ break;
+ }
+ }
+ g_mutex_unlock(&worker->mutex);
+}
+
+void aul_worker_destroy(aul_worker_h handle)
+{
+ struct aul_worker_s *worker = (struct aul_worker_s *)handle;
+
+ if (!worker)
+ return;
+
+ if (worker->thread) {
+ if (g_main_loop_is_running(worker->loop))
+ g_main_loop_quit(worker->loop);
+ else
+ _E("GMainLoop is not running");
+
+ g_thread_join(worker->thread);
+ }
+
+ if (worker->loop)
+ g_main_loop_unref(worker->loop);
+
+ if (worker->context)
+ g_main_context_unref(worker->context);
+
+ g_cond_clear(&worker->cond);
+ g_mutex_clear(&worker->mutex);
+
+ __destroy_anr_timer(worker->anr_timer);
+ free(worker->name);
+ free(worker);
+}
+
+static gboolean __notify_cb(gpointer data)
+{
+ struct aul_worker_s *worker = (struct aul_worker_s *)data;
+
+ _W("GMainLoop is started");
+ g_mutex_lock(&worker->mutex);
+ g_cond_signal(&worker->cond);
+ g_mutex_unlock(&worker->mutex);
+
+ return G_SOURCE_REMOVE;
+}
+
+static gpointer __worker_thread_loop(gpointer data)
+{
+ struct aul_worker_s *worker = (struct aul_worker_s *)data;
+ struct anr_timer_s *anr_timer = worker->anr_timer;
+ GSource *source;
+
+ g_mutex_lock(&worker->mutex);
+ __set_comm(worker->name);
+
+ source = g_idle_source_new();
+ if (!source) {
+ _E("Failed to create GSource");
+ g_cond_signal(&worker->cond);
+ g_mutex_unlock(&worker->mutex);
+ return NULL;
+ }
+
+ g_source_set_callback(source, (GSourceFunc)__notify_cb, worker, NULL);
+ g_source_set_priority(source, G_PRIORITY_HIGH);
+ g_source_attach(source, worker->context);
+ g_source_unref(source);
+
+ g_main_context_push_thread_default(worker->context);
+ g_mutex_unlock(&worker->mutex);
+ g_main_loop_run(worker->loop);
+
+ g_mutex_lock(&worker->mutex);
+ if (anr_timer->tag) {
+ source = g_main_context_find_source_by_id(worker->context,
+ anr_timer->tag);
+ if (source && !g_source_is_destroyed(source))
+ g_source_destroy(source);
+
+ anr_timer->tag = 0;
+ }
+
+ g_list_free_full(worker->jobs, __destroy_job);
+ g_main_context_pop_thread_default(worker->context);
+ g_mutex_unlock(&worker->mutex);
+ _W("Shut down worker");
+
+ return NULL;
+}
+
+aul_worker_h aul_worker_create(const char *name)
+{
+ struct aul_worker_s *worker;
+
+ if (!name) {
+ _E("Invalid parameter");
+ return NULL;
+ }
+
+ worker = calloc(1, sizeof(struct aul_worker_s));
+ if (!worker) {
+ _E("Out of memory");
+ return NULL;
+ }
+
+ g_mutex_init(&worker->mutex);
+ g_cond_init(&worker->cond);
+
+ worker->name = strdup(name);
+ if (!worker->name) {
+ _E("Failed to duplicate name");
+ aul_worker_destroy(worker);
+ return NULL;
+ }
+
+ worker->anr_timer = __create_anr_timer();
+ if (!worker->anr_timer) {
+ _E("Failed to create ANR timer");
+ aul_worker_destroy(worker);
+ return NULL;
+ }
+
+ worker->context = g_main_context_new();
+ if (!worker->context) {
+ _E("Failed to create GMainContext");
+ aul_worker_destroy(worker);
+ return NULL;
+ }
+ _W("GMainContext(%p)", worker->context);
+
+ worker->loop = g_main_loop_new(worker->context, FALSE);
+ if (!worker->loop) {
+ _E("Failed to create GMainLoop");
+ aul_worker_destroy(worker);
+ return NULL;
+ }
+
+ g_mutex_lock(&worker->mutex);
+
+ worker->thread = g_thread_new(name, __worker_thread_loop, worker);
+ if (!worker->thread) {
+ _E("Failed to create worker thread");
+ g_mutex_unlock(&worker->mutex);
+ aul_worker_destroy(worker);
+ return NULL;
+ }
+
+ while (!g_main_loop_is_running(worker->loop))
+ g_cond_wait(&worker->cond, &worker->mutex);
+
+ g_mutex_unlock(&worker->mutex);
+
+ return worker;
+}
+
+static gboolean __timeout_cb(gpointer data)
+{
+ struct aul_worker_s *worker = data;
+ struct anr_timer_s *anr_timer;
+ char buf[12];
+ bundle *b;
+ int cmd;
+
+ _E("Application Not Responding");
+ g_mutex_lock(&worker->mutex);
+ anr_timer = worker->anr_timer;
+ anr_timer->tag = 0;
+ anr_timer->start_time = 0;
+
+ b = bundle_create();
+ while (!g_queue_is_empty(anr_timer->cmd_queue)) {
+ cmd = GPOINTER_TO_INT(g_queue_pop_head(anr_timer->cmd_queue));
+ snprintf(buf, sizeof(buf), "%d", cmd);
+ bundle_del(b, AUL_K_COMMAND);
+ bundle_add_str(b, AUL_K_COMMAND, buf);
+ aul_sock_send_bundle(AUL_UTIL_PID, getuid(), ANR_NOTIFY, b,
+ AUL_SOCK_NOREPLY);
+ }
+ bundle_free(b);
+ g_mutex_unlock(&worker->mutex);
+
+ return G_SOURCE_REMOVE;
+}
+
+int aul_worker_add_anr_timer(aul_worker_h handle, int cmd, unsigned int timeout)
+{
+ struct aul_worker_s *worker = handle;
+ struct anr_timer_s *anr_timer;
+ unsigned int elapsed_time;
+ unsigned int interval;
+ gint64 current_time;
+ GSource *source;
+
+ if (!worker) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&worker->mutex);
+
+ anr_timer = worker->anr_timer;
+ if (anr_timer->tag) {
+ source = g_main_context_find_source_by_id(worker->context,
+ anr_timer->tag);
+ g_source_destroy(source);
+ anr_timer->tag = 0;
+ }
+
+ g_queue_push_tail(anr_timer->cmd_queue, GINT_TO_POINTER(cmd));
+
+ current_time = g_get_monotonic_time();
+ if (anr_timer->start_time == 0) {
+ interval = timeout;
+ anr_timer->start_time = current_time;
+ } else {
+ elapsed_time = (unsigned int)((current_time -
+ anr_timer->start_time) / 1000);
+ interval = timeout + (DEFAULT_INTERVAL - elapsed_time);
+ anr_timer->start_time = current_time;
+ }
+
+ source = g_timeout_source_new(interval);
+ g_source_set_callback(source, (GSourceFunc)__timeout_cb, worker, NULL);
+ anr_timer->tag = g_source_attach(source, worker->context);
+ g_source_unref(source);
+
+ return AUL_R_OK;
+}
+
+int aul_worker_remove_anr_timer(aul_worker_h handle)
+{
+ struct aul_worker_s *worker = handle;
+ struct anr_timer_s *anr_timer;
+ GSource *source;
+
+ if (!worker) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&worker->mutex);
+
+ anr_timer = worker->anr_timer;
+ if (g_queue_is_empty(anr_timer->cmd_queue)) {
+ _E("Queue is empty");
+ return AUL_R_ERROR;
+ }
+
+ g_queue_pop_head(anr_timer->cmd_queue);
+ if (!g_queue_is_empty(anr_timer->cmd_queue))
+ return AUL_R_OK;
+
+ if (anr_timer->tag) {
+ source = g_main_context_find_source_by_id(worker->context,
+ anr_timer->tag);
+ if (source && !g_source_is_destroyed(source))
+ g_source_destroy(source);
+
+ anr_timer->tag = 0;
+ anr_timer->start_time = 0;
+ }
+
+ return AUL_R_OK;
+}
--- /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 enum {
+ AUL_IO_IN = 0x01,
+ AUL_IO_OUT = 0x02,
+ AUL_IO_PRI = 0x04,
+ AUL_IO_ERR = 0x10,
+ AUL_IO_HUP = 0x20,
+ AUL_IO_NVAL = 0x40,
+} aul_io_condition_e;
+
+typedef bool (*aul_worker_io_job_cb)(int fd, int condition, 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, int condition, bool do_close,
+ aul_worker_io_job_cb callback, void *user_data);
+
+void aul_worker_remove_io_job(aul_worker_h handle, int fd);
+
+int aul_worker_add_anr_timer(aul_worker_h handle,
+ int cmd, unsigned int timeout);
+
+int aul_worker_remove_anr_timer(aul_worker_h handle);
+
+#endif /* __AUL_WORKER_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2020 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_COMMON_API_HH_
+#define AUL_COMMON_API_HH_
+
+#ifdef API
+#undef API
+#endif
+#define API __attribute__ ((visibility("default")))
+
+#endif // AUL_COMMON_API_HH_
--- /dev/null
+/*
+ * Copyright (c) 2020 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_COMMON_COMMON_HH_
+#define AUL_COMMON_COMMON_HH_
+
+#undef REGULAR_UID_MIN
+#define REGULAR_UID_MIN 5000
+
+#endif // AUL_COMMON_COMMON_HH_
--- /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 AUL_COMMON_EXCEPTION_HH_
+#define AUL_COMMON_EXCEPTION_HH_
+
+#include <string>
+#include <exception>
+
+#include "aul/common/log_private.hh"
+
+#define THROW(error_code) throw Exception(error_code, __FUNCTION__, __LINE__)
+
+namespace aul {
+
+class Exception : public std::exception {
+ public:
+ explicit Exception(int error_code, std::string file = __FILE__,
+ int line = __LINE__ ) {
+ error_code_ = error_code;
+ message_ = file.substr(file.find_last_of("/") + 1) + ":"
+ + std::to_string(line) + " code:" + std::to_string(error_code_);
+ }
+
+ virtual ~Exception() {}
+
+ virtual const char *what(void) const noexcept {
+ return message_.c_str();
+ }
+
+ int GetErrorCode() const {
+ return error_code_;
+ }
+
+ private:
+ int error_code_;
+ std::string message_;
+};
+
+} // namespace aul
+
+#endif // AUL_COMMON_EXCEPTION_HH_
--- /dev/null
+/*
+ * Copyright (c) 2021 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 AUL_COMMON_FILE_DESCRIPTOR_HH_
+#define AUL_COMMON_FILE_DESCRIPTOR_HH_
+
+#include <unistd.h>
+#include <sys/types.h>
+
+namespace aul {
+
+class FileDescriptor {
+ public:
+ explicit FileDescriptor(int fd = -1) : fd_(fd) {}
+
+ virtual ~FileDescriptor() {
+ if (fd_ > -1)
+ close(fd_);
+ }
+
+ void Set(int fd) {
+ fd_ = fd;
+ }
+
+ int Get() const {
+ return fd_;
+ }
+
+ void Close() {
+ if (fd_ > -1) {
+ close(fd_);
+ fd_ = -1;
+ }
+ }
+
+ bool IsClosed() {
+ return fd_ < 0 ? true : false;
+ }
+
+ private:
+ int fd_;
+};
+
+} // namespace aul
+
+#endif // AUL_COMMON_FILE_DESCRIPTOR_HH_
--- /dev/null
+/*
+ * Copyright (c) 2020 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_COMMON_LOG_PRIVATE_HH_
+#define AUL_COMMON_LOG_PRIVATE_HH_
+
+#include <dlog.h>
+
+#undef LOG_TAG
+#define LOG_TAG "AUL"
+
+#undef _E
+#define _E LOGE
+
+#undef _W
+#define _W LOGW
+
+#undef _I
+#define _I LOGI
+
+#undef _D
+#define _D LOGD
+
+#endif // AUL_COMMON_LOG_PRIVATE_HH_
--- /dev/null
+/*
+ * Copyright (c) 2021 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_COMMON_UTIL_HH_
+#define AUL_COMMON_UTIL_HH_
+
+#include <algorithm>
+#include <string>
+#include <vector>
+
+namespace aul {
+
+class Util {
+ public:
+ static std::vector<std::string> Split(const std::string& str,
+ const std::string& delimiter) {
+ std::string string(str);
+ std::vector<std::string> result;
+ std::size_t pos;
+ while ((pos = string.find(delimiter)) != std::string::npos) {
+ std::string token = string.substr(0, pos);
+ result.push_back(token);
+ string.erase(0, pos + delimiter.length());
+ }
+ result.push_back(string);
+ return result;
+ }
+};
+
+} // namespace aul
+
+#endif // AUL_COMMON_UTIL_HH_
--- /dev/null
+/*
+ * Copyright (c) 2022 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 "aul/component/component_info.hh"
+
+#include "include/aul.h"
+
+#include "aul/common/exception.hh"
+
+namespace aul {
+
+ComponentInfo::Builder& ComponentInfo::Builder::SetAppId(
+ const tizen_base::Bundle& b) {
+ app_id_ = std::move(b.GetString(AUL_K_APPID));
+ return *this;
+}
+
+ComponentInfo::Builder& ComponentInfo::Builder::SetComponentId(
+ const tizen_base::Bundle& b) {
+ component_id_ = std::move(b.GetString(AUL_K_COMPONENT_ID));
+ return *this;
+}
+
+ComponentInfo::Builder& ComponentInfo::Builder::SetType(
+ const tizen_base::Bundle& b) {
+ type_ = std::move(b.GetString(AUL_K_COMPONENT_TYPE));
+ return *this;
+}
+
+ComponentInfo::Builder& ComponentInfo::Builder::SetLaunchMode(
+ const tizen_base::Bundle& b) {
+ launch_mode_ = std::move(b.GetString(AUL_K_LAUNCH_MODE));
+ return *this;
+}
+
+ComponentInfo::Builder& ComponentInfo::Builder::SetMainComponent(
+ const tizen_base::Bundle& b) {
+ if (b.GetString(AUL_K_MAIN_COMP) == "true")
+ main_component_ = true;
+
+ return *this;
+}
+
+ComponentInfo::Builder& ComponentInfo::Builder::SetIconDisplay(
+ const tizen_base::Bundle& b) {
+ if (b.GetString(AUL_K_ICON_DISPLAY) == "true")
+ icon_display_ = true;
+
+ return *this;
+}
+
+ComponentInfo::Builder& ComponentInfo::Builder::SetTaskmanage(
+ const tizen_base::Bundle& b) {
+ if (b.GetString(AUL_K_TASK_MANAGE) == "true")
+ taskmanage_ = true;
+
+ return *this;
+}
+
+ComponentInfo::Builder& ComponentInfo::Builder::SetLocalizedInfo(
+ const tizen_base::Bundle& b) {
+ auto localized_info_array = b.GetStringArray(AUL_K_LOCALIZED_INFO);
+ if (localized_info_array.empty())
+ return *this;
+
+ auto localized_info_size_array = b.GetStringArray(AUL_K_LOCALIZED_INFO_SIZE);
+ if (localized_info_size_array.empty())
+ return *this;
+
+ if (localized_info_array.size() != localized_info_size_array.size())
+ return *this;
+
+ for (unsigned int i = 0; i < localized_info_size_array.size(); ++i) {
+ int len = std::stoi(localized_info_size_array[i]);
+ auto* kb = bundle_decode(
+ reinterpret_cast<bundle_raw*>(const_cast<char*>(
+ localized_info_array[i].c_str())), len);
+ if (kb == nullptr)
+ return *this;
+
+ try {
+ tizen_base::Bundle b(kb, false, true);
+ LocalizedInfo* info = LocalizedInfo::Builder()
+ .SetLocale(b)
+ .SetIcon(b)
+ .SetLabel(b);
+ if (info == nullptr)
+ return *this;
+
+ auto locale = info->GetLocale();
+ localized_info_[std::move(locale)] = std::shared_ptr<LocalizedInfo>(info);
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%s)", e.what());
+ }
+ }
+
+ return *this;
+}
+
+
+ComponentInfo::Builder::operator ComponentInfo*() {
+ Validate();
+ return new (std::nothrow) ComponentInfo(std::move(app_id_),
+ std::move(component_id_), std::move(type_), std::move(launch_mode_),
+ main_component_, icon_display_, taskmanage_, std::move(localized_info_));
+}
+
+void ComponentInfo::Builder::Validate() {
+ if (app_id_.empty() ||
+ component_id_.empty() ||
+ type_.empty() ||
+ launch_mode_.empty())
+ THROW(AUL_R_ERROR);
+}
+
+ComponentInfo::ComponentInfo(std::string app_id,
+ std::string component_id,
+ std::string type,
+ std::string launch_mode,
+ bool main_component,
+ bool icon_display,
+ bool taskmanage,
+ std::unordered_map<std::string,
+ std::shared_ptr<LocalizedInfo>> localized_info)
+ : app_id_(std::move(app_id)),
+ component_id_(std::move(component_id)),
+ type_(std::move(type)),
+ launch_mode_(std::move(launch_mode)),
+ main_component_(main_component),
+ icon_display_(icon_display),
+ taskmanage_(taskmanage),
+ localized_info_(std::move(localized_info)) {
+}
+
+const std::string& ComponentInfo::GetAppId() const {
+ return app_id_;
+}
+
+const std::string& ComponentInfo::GetComponentId() const {
+ return component_id_;
+}
+
+const std::string& ComponentInfo::GetType() const {
+ return type_;
+}
+
+const std::string& ComponentInfo::GetLaunchMode() const {
+ return launch_mode_;
+}
+
+bool ComponentInfo::IsMainComponent() const {
+ return main_component_;
+}
+
+bool ComponentInfo::IsIconDisplay() const {
+ return icon_display_;
+}
+
+bool ComponentInfo::IsTaskmanage() const {
+ return taskmanage_;
+}
+
+const LocalizedInfo* ComponentInfo::GetLocalizedInfo(
+ const std::string& locale) const {
+ auto found = localized_info_.find(locale);
+ if (found == localized_info_.end())
+ return nullptr;
+
+ return (found->second).get();
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2022 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_COMPONENT_COMPONENT_INFO_HH_
+#define AUL_COMPONENT_COMPONENT_INFO_HH_
+
+#include <bundle_cpp.h>
+
+#include <memory>
+#include <string>
+#include <unordered_map>
+
+#include "aul/component/localized_info.hh"
+
+namespace aul {
+
+class ComponentInfo {
+ public:
+ class Builder {
+ public:
+ Builder& SetAppId(const tizen_base::Bundle& b);
+ Builder& SetComponentId(const tizen_base::Bundle& b);
+ Builder& SetType(const tizen_base::Bundle& b);
+ Builder& SetLaunchMode(const tizen_base::Bundle& b);
+ Builder& SetMainComponent(const tizen_base::Bundle& b);
+ Builder& SetIconDisplay(const tizen_base::Bundle& b);
+ Builder& SetTaskmanage(const tizen_base::Bundle& b);
+ Builder& SetLocalizedInfo(const tizen_base::Bundle& b);
+
+ operator ComponentInfo*();
+
+ private:
+ void Validate();
+
+ private:
+ std::string app_id_;
+ std::string component_id_;
+ std::string type_;
+ std::string launch_mode_;
+ bool main_component_ = false;
+ bool icon_display_ = false;
+ bool taskmanage_ = false;
+ std::unordered_map<std::string,
+ std::shared_ptr<LocalizedInfo>> localized_info_;
+ };
+
+ ComponentInfo(std::string app_id,
+ std::string component_id,
+ std::string type,
+ std::string launch_mode,
+ bool main_component,
+ bool icon_display,
+ bool taskmanage,
+ std::unordered_map<std::string,
+ std::shared_ptr<LocalizedInfo>> localized_info);
+
+ const std::string& GetAppId() const;
+ const std::string& GetComponentId() const;
+ const std::string& GetType() const;
+ const std::string& GetLaunchMode() const;
+ bool IsMainComponent() const;
+ bool IsIconDisplay() const;
+ bool IsTaskmanage() const;
+ const LocalizedInfo* GetLocalizedInfo(const std::string& locale) const;
+
+ private:
+ std::string app_id_;
+ std::string component_id_;
+ std::string type_;
+ std::string launch_mode_;
+ bool main_component_ = false;
+ bool icon_display_ = false;
+ bool taskmanage_ = false;
+ std::unordered_map<std::string,
+ std::shared_ptr<LocalizedInfo>> localized_info_;
+};
+
+} // namespace aul
+
+#endif // AUL_COMPONENT_COMPONENT_INFO_HH_
--- /dev/null
+/*
+ * Copyright (c) 2020 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 <bundle_cpp.h>
+#include <tizen.h>
+
+#include <stdexcept>
+
+#include "aul/common/log_private.hh"
+#include "aul/common/exception.hh"
+#include "aul/component/component_port.hh"
+#include "aul/socket/client.hh"
+#include "include/aul.h"
+#include "include/aul_cmd.h"
+#include "include/aul_error.h"
+#include "include/aul_sock.h"
+
+namespace aul {
+
+ComponentPort::ComponentPort(std::string name)
+ : name_(std::move(name)) {
+}
+
+bool ComponentPort::Exist() {
+ int ret = SendRequest(COMP_PORT_EXIST, AUL_SOCK_NONE);
+ if (ret < 0) {
+ _E("Failed to send a request. error(%d)", ret);
+ set_last_result(ret);
+ return false;
+ }
+
+ return ret == 1 ? true : false;
+}
+
+int ComponentPort::Create() {
+ tizen_base::Bundle b;
+ b.Add(AUL_K_COMPONENT_PORT, name_);
+ Packet pkt(COMP_PORT_CREATE, AUL_SOCK_ASYNC | AUL_SOCK_BUNDLE, b);
+ int fds[2] = { -1, };
+ try {
+ Client client(PATH_AMD_SOCK);
+ int ret = client.Send(pkt);
+ if (ret < 0)
+ return aul_error_convert(ret);
+
+ ret = aul_sock_recv_reply_sock_fd(client.RemoveFd(), &fds, 1);
+ if (ret != 0)
+ return aul_error_convert(ret);
+ } catch (Exception& e) {
+ _E("Failed to create client. error(%d)", e.GetErrorCode());
+ return aul_error_convert(e.GetErrorCode());
+ }
+
+ return fds[0];
+}
+
+int ComponentPort::Destroy() {
+ int ret = SendRequest(COMP_PORT_DESTROY, AUL_SOCK_NOREPLY);
+ if (ret < 0) {
+ _E("Failed to send a request. error(%d)", ret);
+ return ret;
+ }
+
+ return 0;
+}
+
+int ComponentPort::SendRequest(int cmd, int opt) {
+ tizen_base::Bundle b;
+ b.Add(AUL_K_COMPONENT_PORT, name_);
+ Packet pkt(cmd, opt | AUL_SOCK_BUNDLE, b);
+ Packet* recv_pkt = nullptr;
+ try {
+ Client client(PATH_AMD_SOCK);
+ int ret = client.Send(pkt);
+ if (ret < 0)
+ return aul_error_convert(ret);
+
+ if (opt & AUL_SOCK_NOREPLY)
+ return ret;
+
+ ret = client.Recv(&recv_pkt);
+ if (ret < 0)
+ return aul_error_convert(ret);
+
+ std::unique_ptr<Packet> ptr(recv_pkt);
+ if (recv_pkt->GetCmd() != cmd) {
+ _E("Invalid protocol");
+ return AUL_R_ECOMM;
+ }
+
+ b = recv_pkt->DataToBundle();
+ auto str = b.GetString(AUL_K_RESULT);
+ ret = std::stoi(str);
+ if (ret < 0)
+ return aul_error_convert(ret);
+
+ return ret;
+ } catch(std::invalid_argument& e) {
+ _E("Out of memory");
+ return AUL_R_ENOMEM;
+ } catch (Exception& e) {
+ _E("Failed to create client. error(%d)", e.GetErrorCode());
+ return aul_error_convert(e.GetErrorCode());
+ }
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2020 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_COMPONENT_COMPONENT_PORT_HH_
+#define AUL_COMPONENT_COMPONENT_PORT_HH_
+
+#include <string>
+
+namespace aul {
+
+class ComponentPort {
+ public:
+ explicit ComponentPort(std::string name);
+ virtual ~ComponentPort() = default;
+
+ bool Exist();
+ int Create();
+ int Destroy();
+
+ private:
+ int SendRequest(int cmd, int opt);
+
+ private:
+ std::string name_;
+};
+
+} // namespace aul
+
+#endif // AUL_COMPONENT_COMPONENT_PORT_HH_
--- /dev/null
+/*
+ * Copyright (c) 2022 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 "aul/component/component_running_context.hh"
+
+#include "include/aul.h"
+
+#include "aul/common/exception.hh"
+
+namespace aul {
+
+ComponentRunningContext::Builder&
+ComponentRunningContext::Builder::SetComponentId(const tizen_base::Bundle& b) {
+ component_id_ = std::move(b.GetString(AUL_K_COMPONENT_ID));
+ return *this;
+}
+
+ComponentRunningContext::Builder&
+ComponentRunningContext::Builder::SetInstanceId(const tizen_base::Bundle& b) {
+ instance_id_ = std::move(b.GetString(AUL_K_INSTANCE_ID));
+ return *this;
+}
+
+ComponentRunningContext::Builder& ComponentRunningContext::Builder::SetAppId(
+ const tizen_base::Bundle& b) {
+ app_id_ = std::move(b.GetString(AUL_K_APPID));
+ return *this;
+}
+
+ComponentRunningContext::Builder& ComponentRunningContext::Builder::SetType(
+ const tizen_base::Bundle& b) {
+ type_ = std::move(b.GetString(AUL_K_COMPONENT_TYPE));
+ return *this;
+}
+
+ComponentRunningContext::Builder& ComponentRunningContext::Builder::SetPid(
+ const tizen_base::Bundle& b) {
+ auto value = b.GetString(AUL_K_PID);
+ if (value.empty())
+ return *this;
+
+ pid_ = std::stoi(value);
+ return *this;
+}
+
+ComponentRunningContext::Builder& ComponentRunningContext::Builder::SetStatus(
+ const tizen_base::Bundle& b) {
+ auto value = b.GetString(AUL_K_STATUS);
+ if (value.empty())
+ return *this;
+
+ status_ = std::stoi(value);
+ return *this;
+}
+
+ComponentRunningContext::Builder&
+ComponentRunningContext::Builder::SetSubComponent(const tizen_base::Bundle& b) {
+ auto value = b.GetString(AUL_K_IS_SUB_COMP);
+ if (value.empty())
+ return *this;
+
+ is_sub_component_ = std::stoi(value) ? true : false;
+ return *this;
+}
+
+ComponentRunningContext::Builder::operator ComponentRunningContext*() {
+ Validate();
+ return new (std::nothrow) ComponentRunningContext(std::move(component_id_),
+ std::move(instance_id_), std::move(app_id_), std::move(type_),
+ pid_, status_, is_sub_component_);
+}
+
+void ComponentRunningContext::Builder::Validate() {
+ if (component_id_.empty() ||
+ instance_id_.empty() ||
+ app_id_.empty() ||
+ type_.empty() ||
+ pid_ < 0 ||
+ status_ < 0 )
+ THROW(AUL_R_ERROR);
+}
+
+ComponentRunningContext::ComponentRunningContext(std::string component_id,
+ std::string instance_id,
+ std::string app_id,
+ std::string type,
+ pid_t pid,
+ int status,
+ bool is_sub_component)
+ : component_id_(std::move(component_id)),
+ instance_id_(std::move(instance_id)),
+ app_id_(std::move(app_id)),
+ type_(std::move(type)),
+ pid_(pid),
+ status_(status),
+ is_sub_component_(is_sub_component) {
+}
+
+const std::string& ComponentRunningContext::GetComponentId() const {
+ return component_id_;
+}
+
+const std::string& ComponentRunningContext::GetInstanceId() const {
+ return instance_id_;
+}
+
+const std::string& ComponentRunningContext::GetAppId() const {
+ return app_id_;
+}
+
+const std::string& ComponentRunningContext::GetType() const {
+ return type_;
+}
+
+pid_t ComponentRunningContext::GetPid() const {
+ return pid_;
+}
+
+int ComponentRunningContext::GetStatus() const {
+ return status_;
+}
+
+bool ComponentRunningContext::IsSubComponent() const {
+ return is_sub_component_;
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2022 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_COMPONENT_COMPONENT_RUNNING_CONTEXT_HH_
+#define AUL_COMPONENT_COMPONENT_RUNNING_CONTEXT_HH_
+
+#include <unistd.h>
+
+#include <bundle_cpp.h>
+
+#include <string>
+
+namespace aul {
+
+class ComponentRunningContext {
+ public:
+ class Builder {
+ public:
+ Builder& SetComponentId(const tizen_base::Bundle& b);
+ Builder& SetInstanceId(const tizen_base::Bundle& b);
+ Builder& SetAppId(const tizen_base::Bundle& b);
+ Builder& SetType(const tizen_base::Bundle& b);
+ Builder& SetPid(const tizen_base::Bundle& b);
+ Builder& SetStatus(const tizen_base::Bundle& b);
+ Builder& SetSubComponent(const tizen_base::Bundle& b);
+
+ operator ComponentRunningContext*();
+
+ private:
+ void Validate();
+
+ private:
+ std::string component_id_;
+ std::string instance_id_;
+ std::string app_id_;
+ std::string type_;
+ pid_t pid_ = -1;
+ int status_ = -1;
+ bool is_sub_component_ = false;
+ };
+
+ ComponentRunningContext(std::string component_id,
+ std::string instance_id,
+ std::string app_id,
+ std::string type,
+ pid_t pid,
+ int status,
+ bool is_sub_component);
+
+ const std::string& GetComponentId() const;
+ const std::string& GetInstanceId() const;
+ const std::string& GetAppId() const;
+ const std::string& GetType() const;
+ pid_t GetPid() const;
+ int GetStatus() const;
+ bool IsSubComponent() const;
+
+ private:
+ std::string component_id_;
+ std::string instance_id_;
+ std::string app_id_;
+ std::string type_;
+ pid_t pid_;
+ int status_;
+ bool is_sub_component_;
+};
+
+} // namespace aul
+
+#endif // AUL_COMPONENT_COMPONENT_RUNNING_CONTEXT_HH_
--- /dev/null
+/*
+ * Copyright (c) 2022 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 "aul/component/localized_info.hh"
+
+#include "aul/common/exception.hh"
+#include "include/aul.h"
+
+namespace aul {
+
+LocalizedInfo::Builder& LocalizedInfo::Builder::SetLocale(
+ const tizen_base::Bundle& b) {
+ locale_ = std::move(b.GetString(AUL_K_LOCALE));
+ return *this;
+}
+
+LocalizedInfo::Builder& LocalizedInfo::Builder::SetIcon(
+ const tizen_base::Bundle& b) {
+ icon_ = std::move(b.GetString(AUL_K_ICON));
+ return *this;
+}
+
+LocalizedInfo::Builder& LocalizedInfo::Builder::SetLabel(
+ const tizen_base::Bundle& b) {
+ label_ = std::move(b.GetString(AUL_K_LABEL));
+ return *this;
+}
+
+LocalizedInfo::Builder::operator LocalizedInfo*() {
+ Validate();
+ return new (std::nothrow) LocalizedInfo(std::move(locale_),
+ std::move(icon_), std::move(label_));
+}
+
+void LocalizedInfo::Builder::Validate() {
+ if (locale_.empty())
+ THROW(AUL_R_ERROR);
+}
+
+LocalizedInfo::LocalizedInfo(std::string locale, std::string icon,
+ std::string label)
+ : locale_(std::move(locale)),
+ icon_(std::move(icon)),
+ label_(std::move(label)) {
+}
+
+const std::string& LocalizedInfo::GetLocale() const {
+ return locale_;
+}
+
+const std::string& LocalizedInfo::GetIcon() const {
+ return icon_;
+}
+
+const std::string& LocalizedInfo::GetLabel() const {
+ return label_;
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2022 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_COMPONENT_LOCALIZED_INFO_HH_
+#define AUL_COMPONENT_LOCALIZED_INFO_HH_
+
+#include <bundle_cpp.h>
+
+#include <string>
+
+namespace aul {
+
+class LocalizedInfo {
+ public:
+ class Builder {
+ public:
+ Builder& SetLocale(const tizen_base::Bundle& b);
+ Builder& SetIcon(const tizen_base::Bundle& b);
+ Builder& SetLabel(const tizen_base::Bundle& b);
+
+ operator LocalizedInfo*();
+
+ private:
+ void Validate();
+
+ private:
+ std::string locale_;
+ std::string icon_;
+ std::string label_;
+ };
+
+ LocalizedInfo(std::string locale, std::string icon, std::string label);
+
+ const std::string& GetLocale() const;
+ const std::string& GetIcon() const;
+ const std::string& GetLabel() const;
+
+ private:
+ std::string locale_;
+ std::string icon_;
+ std::string label_;
+};
+
+} // namespace aul
+
+#endif // AUL_COMPONENT_LOCALIZED_INFO_HH_
--- /dev/null
+/*
+ * Copyright (c) 2023 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 "aul/cpu_inheritance.hh"
+
+#include <cpu-boosting.h>
+
+#include "aul/aul_util.h"
+#include "aul/include/aul_cmd.h"
+
+namespace aul {
+namespace internal {
+namespace {
+
+constexpr const char DEST_PROCESS[] = "amd";
+
+} // namespace
+
+CPUInheritance::CPUInheritance(pid_t pid, int cmd) {
+ if (pid == -2 && IsLaunchRequest(cmd)) {
+ int ret = resource_set_cpu_inheritance(gettid(),
+ const_cast<char*>(DEST_PROCESS), -1);
+ if (ret != 0)
+ _E("resource_set_cpu_inheritance() is failed. error(%d)", ret);
+ else
+ inherited_ = true;
+ }
+}
+
+CPUInheritance::CPUInheritance() {
+ int ret = resource_set_cpu_inheritance(gettid(),
+ const_cast<char*>(DEST_PROCESS), -1);
+ if (ret != 0)
+ _E("resource_set_cpu_inheritance() is failed. error(%d)", ret);
+ else
+ inherited_ = true;
+}
+
+CPUInheritance::~CPUInheritance() {
+ if (inherited_) {
+ int ret = resource_clear_cpu_inheritance(gettid(),
+ const_cast<char*>(DEST_PROCESS));
+ if (ret != 0)
+ _E("resource_clear_cpu_inheritance() is failed. error(%d)", ret);
+ }
+}
+
+bool CPUInheritance::IsLaunchRequest(int cmd) {
+ switch (cmd) {
+ case APP_START:
+ case APP_OPEN:
+ case APP_RESUME:
+ case APP_START_RES:
+ case APP_START_ASYNC:
+ case APP_SEND_LAUNCH_REQUEST_SYNC:
+ case RPC_PORT_PREPARE_STUB:
+ return true;
+ default:
+ return false;
+ }
+}
+
+} // namespace internal
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2023 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 CPU_INHERITANCE_HH_
+#define CPU_INHERITANCE_HH_
+
+#include <sys/types.h>
+
+namespace aul {
+namespace internal {
+
+class CPUInheritance {
+ public:
+ CPUInheritance(pid_t pid, int cmd);
+ CPUInheritance();
+ ~CPUInheritance();
+
+ private:
+ static bool IsLaunchRequest(int cmd);
+
+ private:
+ bool inherited_ = false;
+};
+
+} // namespace internal
+} // namespace aul
+
+#endif // CPU_INHERITANCE_HH_
--- /dev/null
+/*
+ * aul
+ *
+ * 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 <errno.h>
+#include <bundle.h>
+#include <sys/types.h>
+#include <stdbool.h>
+
+#include "aul_key.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Return values in AUL.
+ */
+typedef enum _aul_return_val {
+ AUL_R_ENOMEM = -16, /**< Out of memory (Since 5.5) */
+ AUL_R_ENOENT = -15, /**< App directory entry error */
+ AUL_R_EREJECTED = -14, /**< App disable for mode */
+ AUL_R_ENOAPP = -13, /**< Failed to find app ID or pkg ID */
+ AUL_R_EHIDDENFORGUEST = -11, /**< App hidden for guest mode */
+ AUL_R_ENOLAUNCHPAD = -10, /**< no launchpad */
+ AUL_R_ETERMINATING = -9, /**< application terminating */
+ AUL_R_EILLACC = -8, /**< Illegal Access */
+ AUL_R_LOCAL = -7, /**< Launch by himself */
+ AUL_R_ETIMEOUT = -6, /**< Timeout */
+ AUL_R_ECANCELED = -5, /**< Operation canceled */
+ AUL_R_EINVAL = -4, /**< Invalid argument */
+ AUL_R_ECOMM = -3, /**< Comunication Error */
+ AUL_R_ENOINIT = -2, /**< AUL handler NOT initialized */
+ AUL_R_ERROR = -1, /**< General error */
+ AUL_R_OK = 0 /**< General success */
+} aul_return_val;
+
+enum app_status {
+ STATUS_LAUNCHING,
+ STATUS_CREATED,
+ STATUS_FOCUS,
+ STATUS_VISIBLE,
+ STATUS_BG,
+ STATUS_DYING,
+ STATUS_HOME,
+ STATUS_NORESTART,
+ STATUS_SERVICE,
+ STATUS_TERMINATE,
+};
+
+typedef enum _aul_type {
+ AUL_START,
+ AUL_RESUME,
+ AUL_TERMINATE,
+ AUL_TERMINATE_BGAPP,
+ AUL_PAUSE,
+ AUL_WAKE,
+ AUL_SUSPEND,
+ AUL_WIDGET_CONTENT,
+ AUL_UPDATE_REQUESTED,
+ AUL_TERMINATE_INST,
+ AUL_TERMINATE_BG_INST,
+} aul_type;
+
+typedef enum aul_widget_lifecycle_event {
+ AUL_WIDGET_LIFE_CYCLE_EVENT_APP_DEAD = 0,
+ AUL_WIDGET_LIFE_CYCLE_EVENT_CREATE = 1, /**< The widget is created */
+ AUL_WIDGET_LIFE_CYCLE_EVENT_DESTROY = 2, /**< The widget is destroyed */
+ AUL_WIDGET_LIFE_CYCLE_EVENT_PAUSE = 3, /**< The widget is paused */
+ AUL_WIDGET_LIFE_CYCLE_EVENT_RESUME = 4 /**< The widget is resumed */
+} aul_widget_lifecycle_event_e;
+
+typedef enum aul_widget_instance_event {
+ AUL_WIDGET_INSTANCE_EVENT_CREATE = 0,
+ AUL_WIDGET_INSTANCE_EVENT_DESTROY = 1,
+ AUL_WIDGET_INSTANCE_EVENT_TERMINATE = 2,
+ AUL_WIDGET_INSTANCE_EVENT_PAUSE = 3,
+ AUL_WIDGET_INSTANCE_EVENT_RESUME = 4,
+ AUL_WIDGET_INSTANCE_EVENT_UPDATE = 5,
+ AUL_WIDGET_INSTANCE_EVENT_PERIOD_CHANGED = 6,
+ AUL_WIDGET_INSTANCE_EVENT_SIZE_CHANGED = 7,
+ AUL_WIDGET_INSTANCE_EVENT_EXTRA_UPDATED = 8,
+ AUL_WIDGET_INSTANCE_EVENT_FAULT = 9,
+ AUL_WIDGET_INSTANCE_EVENT_APP_RESTART_REQUEST = 10,
+ AUL_WIDGET_INSTANCE_EVENT_CREATE_ABORTED = 11
+} aul_widget_instance_event_e;
+
+typedef enum _aul_process_status {
+ AUL_PROC_STATUS_LAUNCH = 0,
+ AUL_PROC_STATUS_FG = 3,
+ AUL_PROC_STATUS_BG = 4,
+ AUL_PROC_STATUS_FOCUS = 5,
+ AUL_PROC_STATUS_HIDE = 7
+} aul_process_status_e;
+
+/**
+ * @brief This is callback function for aul_launch_init
+ * @param[in] type event's type received from system
+ * @param[in] b In case of RESET events, bundle which is received from peer
+ * @param[in] data user-supplied data
+ */
+typedef int (*aul_handler_fn)(aul_type type, bundle *b, void *data);
+
+/**
+ * @par Description:
+ * This API install your AUL handler and setup AUL internal connection.
+ * @par Purpose:
+ * AUL receive START(RESET), RESUME, TERMINATE events from system.\n
+ * This API use to handle the events. \n
+ * @par Typical use case:
+ * In general, you need not use this API.
+ * If you use AppCore, you should NOT use this API.
+ * AppCore will set default aul_handler.
+ *
+ * @param[in] handler aul main callback handler function
+ * @param[in] data user-supplied data for start_handler
+ * @return 0 if success, negative value(<0) if fail\n
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_ECANCELD - aul handler was installed already by others
+ * @retval AUL_R_ECOMM - error to create internal ipc
+ * @retval AUL_R_ERROR - error to attach glib main loop
+ *
+ * @warning If you use AppCore, you should NOT use this API.\n
+ * You need glib main loop.\n
+ * @pre
+ * you must have aul handler to use this API.
+ * aul_luanch_init register aul handler.
+ * @code
+ * #include <aul.h>
+ * #include <bundle.h>
+ *
+ * static int aul_handler(aul_type type, bundle *kb,void *data)
+ * {
+ * switch(type)
+ * {
+ * case AUL_START:
+ * // process RESET event
+ * break;
+ * case AUL_RESUME:
+ * // process RESUME event
+ * break;
+ * case AUL_TERMINATE:
+ * // preocess TERMINATE event
+ * break;
+ * }
+ * return 0;
+ * }
+ *
+ * static GMainLoop *mainloop = NULL;
+ *
+ * int main(int argc, char **argv)
+ * {
+ * aul_launch_init(aul_handler,NULL);
+ * aul_launch_argv_handler(argc, argv);
+ *
+ * mainloop = g_main_loop_new(NULL, FALSE);
+ * g_main_loop_run(mainloop);
+ * }
+ *
+ * @endcode
+ * @remark
+ * This API is only available in User Session.
+*/
+int aul_launch_init(aul_handler_fn handler, void *data);
+
+/**
+ * @par Description:
+ * This API create internal RESET events with given argc, argv \n
+ * @par Purpose:
+ * This API's purpose is to generate reset event.
+ * If you want to generate local RESET events with argument vector format, use this API
+ * @par Typical use case:
+ * In general, you need not use this API.
+ * AppCore use this API to create internal reset event.
+ *
+ * @param[in] argc # of args
+ * @param[in] argv list of arg strings
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_ENOINIT - aul handler was NOT yet installed
+ * @retval AUL_R_ECANCLED - error to create internal bundle with given argc,argv.
+ * @retval AUL_R_ERROR - general error
+ *
+ * @pre
+ * you must have aul handler to use this API.
+ * aul_luanch_init register aul handler.
+ * @see
+ * aul_launch_init
+ * @code
+ * #include <aul.h>
+ * #include <bundle.h>
+ *
+ * int send_local_reset_event()
+ * {
+ * int argc=3;
+ * char* argv[4];
+ * argv[0] = "local.app";
+ * argv[1] = "event_type";
+ * argv[2] = "my_reset";
+ * argv[3] = NULL;
+ * aul_launch_argv_handler(argc,argv);
+ * }
+ *
+ * @endcode
+ * @remark
+ * If you use AppCore, you NEED NOT use this API.
+ * This API is only available in User Session.
+*/
+int aul_launch_argv_handler(int argc, char **argv);
+
+/**
+ * @par Description:
+ * This API creates internal RESET events with given bundle \n
+ * @par Purpose:
+ * This API's purpose is to generate reset event.
+ * If you want to generate local RESET events with argument vector format, first use
+ * bundle_import_from_argv to create a bundle from the argument vector and then use this API
+ * Eventually, this API will replace aul_launch_argv_handler().
+ * @par Typical use case:
+ * In general, you need not use this API.
+ * AppCore use this API to create internal reset event.
+ *
+ * @param[in] b bundle
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_ENOINIT - aul handler was NOT yet installed
+ * @retval AUL_R_ERROR - general error
+ *
+ * @pre
+ * you must have aul handler to use this API.
+ * aul_luanch_init register aul handler.
+ * @post
+ * None
+ * @see
+ * aul_launch_init, bundle_import_from_argv
+ * @code
+ * #include <aul.h>
+ * #include <bundle.h>
+ *
+ * int send_local_reset_event()
+ * {
+ * bundle* b;
+ * int argc=3;
+ * char* argv[4];
+ * argv[0] = "local.app";
+ * argv[1] = "event_type";
+ * argv[2] = "my_reset";
+ * argv[3] = NULL;
+ *
+ * b = bundle_import_from_argv(argc,argv);
+ * aul_launch_local(b);
+ * }
+ *
+ * @endcode
+ * @remark
+ * If you use AppCore, you NEED NOT to use this API.
+ * This API is only available in User Session.
+*/
+int aul_launch_local(bundle *b);
+
+/**
+ * @par Description:
+ * This API launches application with the given bundle.
+ * If the application is not running or a multiple-instance one, this API launches with the given bundle.
+ * If the application is running, this API sends a RESET event to the App.
+ * While the application is running, if the application cannot receive the RESET event,
+ * this API returns a general error(AUL_R_ERROR).\n
+ * @par Purpose:
+ * This API is for caller.
+ * This API's purpose is to launch/reset application with given bundle.
+ * @par Typical use case:
+ * If you know the target application's pkgname and bundle types,
+ * you can use this API to launch/reset the application.
+ *
+ * @param[in] pkgname package name to be run as callee
+ * @param[in] kb bundle to be passed to callee
+ * @return callee's pid if success, negative value(<0) if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_EINVAL - invaild package name
+ * @retval AUL_R_ECOM - internal AUL IPC error
+ * @retval AUL_R_ERROR - general error
+ *
+ * @see
+ * aul_open_app
+ * @code
+ * #include <aul.h>
+ * #include <bundle.h>
+ *
+ * int launch_inhouse_contact_app()
+ * {
+ * bundle *b;
+ * b = bundle_create();
+ * bundle_add(b,"type","SIM");
+ * aul_launch_app("org.tizen.contact",b);
+ * }
+ *
+ * @endcode
+ * @remark
+ * This API is only available in User Session.
+ */
+int aul_launch_app(const char *appid, bundle *kb);
+
+/**
+ * @par Description:
+ * This API launches application with the given bundle.
+ * If the application is not running or a multiple-instance one, this API launches with the given bundle.
+ * If the application is running, this API sends a RESET event to the App.
+ * While the application is running, if the application cannot receive the RESET event,
+ * this API returns a general error(AUL_R_ERROR).\n
+ * @par Purpose:
+ * This API is for caller.
+ * This API's purpose is to launch/reset application with given bundle.
+ * @par Typical use case:
+ * If you know the target application's pkgname and bundle types,
+ * you can use this API to launch/reset the application.
+ *
+ * @param[in] pkgname package name to be run as callee
+ * @param[in] kb bundle to be passed to callee
+ * @param[in] uid User ID to launch
+ * @return callee's pid if success, negative value(<0) if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_EINVAL - invaild package name
+ * @retval AUL_R_ECOM - internal AUL IPC error
+ * @retval AUL_R_ERROR - general error
+ *
+ * @see
+ * aul_open_app
+ * @remark
+ * This API is also available in System Session.
+ */
+int aul_launch_app_for_uid(const char *appid, bundle *kb, uid_t uid);
+
+/**
+ * @par Description:
+ * This API launches application, as menu screen launches the app.
+ * Thus, if the application is running, this API sends a RESUME event to the app.
+ * If the application is not running, this API launches the app.
+ * While the application is running, if the application cannot receive the RESUME event,
+ * AUL tries to raise the application's default window.
+ *
+ * @par Purpose:
+ * This API is for caller.
+ * This API's purpose is to resume/launch application
+ * @par Typical use case:
+ * If you only want to show application with previous state or default state, Use this API.
+ *
+ * @param[in] pkgname package name to be resume as callee
+ * @return callee's pid if success, negative value(<0) if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_EINVAL - invaild package name
+ * @retval AUL_R_ECOM - internal AUL IPC error
+ * @retval AUL_R_ERROR - general error
+ *
+ * @see
+ * aul_launch_app, aul_app_is_running, aul_resume_pid
+ * @code
+ * #include <aul.h>
+ * #include <bundle.h>
+ *
+ * int open_inhouse_contact_app()
+ * {
+ * if(aul_app_is_running("org.tizen.contact"))
+ * aul_open_app("org.tizen.contact");
+ * }
+ *
+ * @endcode
+ * @remark
+ * If you don't want to launch the app,
+ * you should check app's running state with aul_app_is_running.
+ * This API will launch the application if the application is not running.
+ * This API is only available in User Session.
+*/
+int aul_open_app(const char *appid);
+
+/**
+ * @par Description:
+ * This API launches application, as menu screen launches the app.
+ * Thus, if the application is running, this API sends a RESUME event to the app.
+ * If the application is not running, this API launches the app.
+ * While the application is running, if the application cannot receive the RESUME event,
+ * AUL tries to raise the application's default window.
+ *
+ * @par Purpose:
+ * This API is for caller.
+ * This API's purpose is to resume/launch application
+ * @par Typical use case:
+ * If you only want to show application with previous state or default state, Use this API.
+ *
+ * @param[in] pkgname package name to be resume as callee
+ * @param[in] uid User ID
+ * @return callee's pid if success, negative value(<0) if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_EINVAL - invaild package name
+ * @retval AUL_R_ECOM - internal AUL IPC error
+ * @retval AUL_R_ERROR - general error
+ *
+ * @remark
+ * If you don't want to launch the app,
+ * you should check app's running state with aul_app_is_running.
+ * This API will launch the application if the application is not running.
+ * This API is only available to System user.
+ */
+int aul_open_app_for_uid(const char *appid, uid_t uid);
+
+/**
+ * @par Description:
+ * This API trigger to resume application
+ * If the application is running, this API send a resume event to the App.
+ * If the application is not running, this API launches the app.
+ * Although the application is running, if the application cannot receive resume event,
+ * AUL try to raise the application's default windows.
+ * @par Purpose:
+ * This API is for caller.
+ * This API's purpose is to send resume event.
+ * @par Typical use case:
+ * If you only want to show application with previous state or default state, Use this API.
+ *
+ * @param[in] pkgname package name to be resume as callee
+ * @return callee's pid if success, negative value(<0) if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_EINVAL - invaild package name
+ * @retval AUL_R_ECOM - internal AUL IPC error
+ * @retval AUL_R_ERROR - general error
+ *
+ * @see
+ * aul_launch_app(), aul_app_is_running(), aul_resume_pid()
+ *
+ * @deprecated
+ * This function will be deprecated. Use aul_open_app() instead of this function.
+ *
+ * @code
+ * #include <aul.h>
+ * #include <bundle.h>
+ *
+ * int resume_inhouse_contact_app()
+ * {
+ * if(aul_app_is_running("org.tizen.contact"))
+ * aul_resume_app("org.tizen.contact");
+ * }
+ *
+ * @endcode
+ * @remark
+ * If you don't want to launch the app,
+ * you should check app's running state with aul_app_is_running.
+ * This API will launch the application if the application is not running.
+ * If you want to only resume without launching in multiple instance application model,
+ * you should use aul_resume_pid.
+ * This API is only available in User Session.
+*/
+int aul_resume_app(const char *appid);
+
+/**
+ * @par Description:
+ * This API trigger to resume application
+ * If the application is running, this API send a resume event to the App.
+ * If the application is not running, this API launches the app.
+ * Although the application is running, if the application cannot receive resume event,
+ * AUL try to raise the application's default windows.
+ * @par Purpose:
+ * This API is for caller.
+ * This API's purpose is to send resume event.
+ * @par Typical use case:
+ * If you only want to show application with previous state or default state, Use this API.
+ *
+ * @param[in] pkgname package name to be resume as callee
+ * @param[in] uid User ID
+ * @return callee's pid if success, negative value(<0) if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_EINVAL - invaild package name
+ * @retval AUL_R_ECOM - internal AUL IPC error
+ * @retval AUL_R_ERROR - general error
+ *
+ * @remark
+ * If you don't want to launch the app,
+ * you should check app's running state with aul_app_is_running.
+ * This API will launch the application if the application is not running.
+ * If you want to only resume without launching in multiple instance application model,
+ * you should use aul_resume_pid.
+ * This API is only available to System user.
+ */
+int aul_resume_app_for_uid(const char *appid, uid_t uid);
+
+/**
+ * @par Description:
+ * This API trigger to resume application
+ * If the application is running, this API send a resume event to the App.
+ * If the application is not running, this API return AUL_R_ERROR.
+ * Although the application is running, if the application cannot receive resume event,
+ * AUL try to raise the application's default windows.
+ * @par Purpose:
+ * This API is for caller.
+ * This API's purpose is to send resume event.
+ * @par Typical use case:
+ * In multiple application model, If you want to only resume specific application, Use this API
+ *
+ * @param[in] pid application's pid to be resumed
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_EINVAL - invaild pid
+ * @retval AUL_R_ECOM - internal AUL IPC error
+ * @retval AUL_R_ERROR - general error (include application is not running)
+ * @warning This API need to require root or inhouse permisssion \n
+ * If you have not the permission, this API return AUL_R_ERROR. \n
+ * @see
+ * aul_launch_app
+ * @code
+ * #include <aul.h>
+ * #include <bundle.h>
+ *
+ * int iterfunc(const aul_app_info *info, void *data)
+ * {
+ * if(strcmp(info->pkg_name,"org.tizen.contact")==0)
+ * aul_resume_pid(info->pid);
+ * }
+ *
+ * int iterate_running_apps()
+ * {
+ * return aul_app_get_running_app_info(iterfunc,NULL);
+ * }
+ *
+ * @endcode
+ * @remark
+ * This API is only available in User Session.
+*/
+int aul_resume_pid(int pid);
+
+/**
+ * @par Description:
+ * This API trigger to resume application
+ * If the application is running, this API send a resume event to the App.
+ * If the application is not running, this API return AUL_R_ERROR.
+ * Although the application is running, if the application cannot receive resume event,
+ * AUL try to raise the application's default windows.
+ * @par Purpose:
+ * This API is for caller.
+ * This API's purpose is to send resume event.
+ * @par Typical use case:
+ * In multiple application model, If you want to only resume specific application, Use this API
+ *
+ * @param[in] pid application's pid to be resumed
+ * @param[in] uid User ID
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_EINVAL - invaild pid
+ * @retval AUL_R_ECOM - internal AUL IPC error
+ * @retval AUL_R_ERROR - general error (include application is not running)
+ * @warning This API need to require root or inhouse permisssion \n
+ * If you have not the permission, this API return AUL_R_ERROR. \n
+ * @remark
+ * This API is only available to System user.
+*/
+int aul_resume_pid_for_uid(int pid, uid_t uid);
+
+/**
+ * @par Description:
+ * This API trigger to terminate application
+ *
+ * If the application is running, this API send a terminate event to the App. \n
+ * If the app cannot receive the event, AUL kill forcely the application.\n
+ * @par Purpose:
+ * This API's purpose is to kill application
+ * @par Typical use case:
+ * In general, Application like Task Manager use this API.
+ *
+ * This API need to require root or inhouse permisssion. \n
+ *
+ * @param[in] pid application's pid to be terminated
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_EINVAL - invaild pid
+ * @retval AUL_R_ECOM - internal AUL IPC error
+ * @retval AUL_R_ERROR - general error
+ * @warning This API need to require root or inhouse permisssion. \n
+ *
+ * @code
+ * #include <aul.h>
+ * #include <bundle.h>
+ *
+ * int iterfunc(const aul_app_info *info, void *data)
+ * {
+ * if(strcmp(info->pkg_name,"org.tizen.contact")==0)
+ * aul_terminate_pid(info->pid);
+ * }
+ *
+ * int iterate_running_apps()
+ * {
+ * return aul_app_get_running_app_info(iterfunc,NULL);
+ * }
+ *
+ * @endcode
+ * @remark
+ * If you have not the permission, this API return AUL_R_ERROR. \n
+ * This API is only available in User Session.
+*/
+int aul_terminate_pid(int pid);
+
+/**
+ * @par Description:
+ * This API trigger to terminate application
+ *
+ * If the application is running, this API send a terminate event to the App. \n
+ * If the app cannot receive the event, AUL kill forcely the application.\n
+ * @par Purpose:
+ * This API's purpose is to kill application
+ * @par Typical use case:
+ * In general, Application like Task Manager use this API.
+ *
+ * This API need to require root or inhouse permisssion. \n
+ *
+ * @param[in] pid application's pid to be terminated
+ * @param[in] uid User ID
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_EINVAL - invaild pid
+ * @retval AUL_R_ECOM - internal AUL IPC error
+ * @retval AUL_R_ERROR - general error
+ * @warning This API need to require root or inhouse permisssion. \n
+ *
+ * @remark
+ * If you have not the permission, this API return AUL_R_ERROR. \n
+ * This API is only available to System user.
+ */
+int aul_terminate_pid_for_uid(int pid, uid_t uid);
+
+/**
+ * @par Description:
+ * This API trigger to terminate application asynchronously
+ *
+ * If the application is running, this API send a terminate event to the App. \n
+ * If the app cannot receive the event, AUL kill forcely the application.\n
+ * @par Purpose:
+ * This API's purpose is to kill application
+ * @par Typical use case:
+ * In general, Application like Task Manager use this API.
+ *
+ * This API need to require root or inhouse permisssion. \n
+ *
+ * @param[in] pid application's pid to be terminated
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_EINVAL - invaild pid
+ * @retval AUL_R_ECOM - internal AUL IPC error
+ * @retval AUL_R_ERROR - general error
+ * @warning This API need to require root or inhouse permisssion. \n
+ * @remark
+ * If you have not the permission, this API return AUL_R_ERROR. \n
+ * This API is only available in User Session.
+*/
+int aul_terminate_pid_async(int pid);
+
+/**
+ * @par Description:
+ * This API trigger to terminate application asynchronously
+ *
+ * If the application is running, this API send a terminate event to the App. \n
+ * If the app cannot receive the event, AUL kill forcely the application.\n
+ * @par Purpose:
+ * This API's purpose is to kill application
+ * @par Typical use case:
+ * In general, Application like Task Manager use this API.
+ *
+ * This API need to require root or inhouse permisssion. \n
+ *
+ * @param[in] pid application's pid to be terminated
+ * @param[in] uid User ID
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_EINVAL - invaild pid
+ * @retval AUL_R_ECOM - internal AUL IPC error
+ * @retval AUL_R_ERROR - general error
+ * @warning This API need to require root or inhouse permisssion. \n
+ * @remark
+ * If you have not the permission, this API return AUL_R_ERROR. \n
+ * This API is only available to System user.
+ */
+int aul_terminate_pid_async_for_uid(int pid, uid_t uid);
+
+/**
+ * @par Description:
+ * This API trigger to terminate application synchronously
+ *
+ * If the application is running, this API sends a terminate event to the application. \n
+ * And then, this API waits until the application is terminated successfully. \n
+ * If the app cannot receive the event, AUL kill forcely the application. \n
+ * @par Purpose:
+ * This API's purpose is to kill application
+ * @par Typical use case:
+ * In general, Application like Task Manager use this API.
+ *
+ * This API need to require root or platform level permisssion. \n
+ *
+ * @param[in] pid application's pid to be terminated
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_EINVAL - invaild pid
+ * @retval AUL_R_ECOM - internal AUL IPC error
+ * @retval AUL_R_ERROR - general error
+ * @warning This API need to require root or platform level permisssion. \n
+ * @remark
+ * If you have not the permission, this API return AUL_R_ERROR. \n
+ * This API is only available in User Session.
+*/
+int aul_terminate_pid_sync(int pid);
+
+/**
+ * @par Description:
+ * This API trigger to terminate application synchronously
+ *
+ * If the application is running, this API send a terminate event to the application. \n
+ * And then, this API waits until the application is terminated successfully. \n
+ * If the app cannot receive the event, AUL kill forcely the application. \n
+ * @par Purpose:
+ * This API's purpose is to kill application
+ * @par Typical use case:
+ * In general, Application like Task Manager use this API.
+ *
+ * This API need to require root or platform level permisssion. \n
+ *
+ * @param[in] pid application's pid to be terminated
+ * @param[in] uid User ID
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_EINVAL - invaild pid
+ * @retval AUL_R_ECOM - internal AUL IPC error
+ * @retval AUL_R_ERROR - general error
+ * @warning This API need to require root or platform level permisssion. \n
+ * @remark
+ * If you have not the permission, this API return AUL_R_ERROR. \n
+ * This API is only available to System user.
+ */
+int aul_terminate_pid_sync_for_uid(int pid, uid_t uid);
+
+/**
+ *@brief Running application's information structure retrieved by AUL
+ */
+typedef struct _aul_app_info {
+ int pid; /**< app's pid if running*/
+ char *pkg_name; /**< application id */
+ char *app_path; /**< application excutable path */
+ char *appid;
+ char *pkgid; /**< package id */
+ int status; /**< app's status */
+ int is_sub_app; /**< state whether sub app of app group */
+ char *instance_id;
+} aul_app_info;
+
+/**
+ * @brief iterator function running with aul_app_get_running_app_info
+ * @param[out] ainfo aul_app_info retreived by aul_app_get_running_app_info
+ * @param[out] data user-supplied data
+*/
+typedef int (*aul_app_info_iter_fn)(const aul_app_info *ainfo, void *data);
+
+/**
+ * @par Description:
+ * This API ask a application is running by application package name.
+ * @par Purpose:
+ * To know whether some application is running or not, use this API
+ * @par Typical use case:
+ * For example, If you want to know browser application running,
+ * you can check it by using this API.
+ *
+ * @param[in] pkgname application package name
+ * @return true / false
+ * @retval 1 app_name is running now.
+ * @retval 0 app_name is NOT running now.
+ *
+ * @code
+ * #include <aul.h>
+ *
+ * int is_running_browser_app()
+ * {
+ * return aul_app_is_running("org.tizen.browser");
+ * }
+ *
+ * @endcode
+ * @remark
+ * This API is only available in User Session.
+ *
+ */
+int aul_app_is_running(const char *appid);
+
+/**
+ * @par Description:
+ * This API ask a application is running by application package name.
+ * @par Purpose:
+ * To know whether some application is running or not, use this API
+ * @par Typical use case:
+ * For example, If you want to know browser application running,
+ * you can check it by using this API.
+ *
+ * @param[in] pkgname application package name
+ * @param[in] uid User ID
+ * @return true / false
+ * @retval 1 app_name is running now.
+ * @retval 0 app_name is NOT running now.
+ *
+ * @endcode
+ * @remark
+ * This API is only available to System User.
+ */
+int aul_app_is_running_for_uid(const char *appid, uid_t uid);
+
+/**
+ * @par Description:
+ * This API use to get running application list.
+ * This API call iter_fn with each aul_app_info of running apps when running application is found.
+ * @par Purpose:
+ * If you want to get running application list, use this API
+ * @par Typical use case:
+ * In general, this API is used by task manager appllication. (running application list viewer)
+ *
+ * @param[in] iter_fn iterator function
+ * @param[in] user_data user-supplied data for iter_fn
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_ERROR - internal error
+ *
+ * @code
+ * #include <aul.h>
+ *
+ * int iterfunc(const aul_app_info* info, void* data)
+ * {
+ * printf("\t==========================\n");
+ * printf("\t pkg_name: %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 iterate_running_apps()
+ * {
+ * return aul_app_get_running_app_info(iterfunc,NULL);
+ * }
+ *
+ * @endcode
+ * @remark
+ * This API should use if you want to know running application which has desktop files.
+ * If you want to get all process list, you must iterate process information by using proc filesystem
+ * Or, If you want to get all window list, you must iterate XWindows by using XWindow APIs
+ * This API is only available in User Session.
+ */
+int aul_app_get_running_app_info(aul_app_info_iter_fn iter_fn, void *user_data);
+
+/**
+ * @par Description:
+ * This API use to get running application list.
+ * This API call iter_fn with each aul_app_info of running apps when running application is found.
+ * @par Purpose:
+ * If you want to get running application list, use this API
+ * @par Typical use case:
+ * In general, this API is used by task manager appllication. (running application list viewer)
+ *
+ * @param[in] iter_fn iterator function
+ * @param[in] user_data user-supplied data for iter_fn
+ * @param[in] uid User ID
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_ERROR - internal error
+ *
+ * @remark
+ * This API should use if you want to know running application which has desktop files.
+ * If you want to get all process list, you must iterate process information by using proc filesystem
+ * Or, If you want to get all window list, you must iterate XWindows by using XWindow APIs
+ * This API is only available to System user.
+ */
+int aul_app_get_running_app_info_for_uid(aul_app_info_iter_fn iter_fn, void *user_data, uid_t uid);
+
+/**
+ * @par Description:
+ * This API use to get all running application list, including sub app.
+ * This API call iter_fn with each aul_app_info of running apps when running application is found.
+ * @par Purpose:
+ * If you want to get all running application list, use this API
+ * @par Typical use case:
+ * In general, this API is used by task manager application. (running application list viewer)
+ *
+ * @param[in] iter_fn iterator function
+ * @param[in] user_data user-supplied data for iter_fn
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_ERROR - internal error
+ *
+ * @code
+ * #include <aul.h>
+ *
+ * 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 iterate_running_apps()
+ * {
+ * return aul_app_get_all_running_app_info(iterfunc_status,NULL);
+ * }
+ *
+ * @endcode
+ * @remark
+ * This API should use if you want to know running application which has desktop files.
+ * If you want to get all process list, you must iterate process information by using proc filesystem
+ * Or, If you want to get all window list, you must iterate XWindows by using XWindow APIs
+ * This API is only available in User Session.
+ */
+int aul_app_get_all_running_app_info(aul_app_info_iter_fn iter_fn, void *user_data);
+
+/**
+ * @par Description:
+ * This API use to get all running application list, including sub app.
+ * This API call iter_fn with each aul_app_info of running apps when running application is found.
+ * @par Purpose:
+ * If you want to get all running application list, use this API
+ * @par Typical use case:
+ * In general, this API is used by task manager application. (running application list viewer)
+ *
+ * @param[in] iter_fn iterator function
+ * @param[in] user_data user-supplied data for iter_fn
+ * @param[in] uid User ID
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_ERROR - internal error
+ *
+ * @remark
+ * This API should use if you want to know running application which has desktop files.
+ * If you want to get all process list, you must iterate process information by using proc filesystem
+ * Or, If you want to get all window list, you must iterate XWindows by using XWindow APIs
+ * This API is only available to System user.
+ */
+int aul_app_get_all_running_app_info_for_uid(aul_app_info_iter_fn iter_fn, void *user_data, uid_t uid);
+
+/**
+ * @par Description:
+ * This API get application package name by pid
+ * @par Purpose:
+ * If you want to get package name of running application, use this API
+ * @par Typical use case:
+ * In general, You can use this API when you want to know caller's information.
+ *
+ * @param[in] pid given pid
+ * @param[out] pkgname pkgname to be get
+ * @param[in] len length of pkgname
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_ERROR - no such a package name
+ * @code
+ * #include <aul.h>
+ * #include <bundle.h>
+ *
+ * static int app_reset(bundle *b, void *data)
+ * {
+ * int pid;
+ * char appname[255];
+ *
+ * pid = atoi(bundle_get_val(b,AUL_K_CALLER_PID));
+ * aul_app_get_pkgname_bypid(pid, appname, sizeof(appname));
+ * }
+ *
+ * @endcode
+ * @remark
+ * This API is only available in User Session.
+*/
+int aul_app_get_pkgname_bypid(int pid, char *pkgname, int len);
+
+/**
+ * @par Description:
+ * This API get application pkgid by pid
+ * @par Purpose:
+ * If you want to get pkgid of running application, use this API
+ * @par Typical use case:
+ * In general, You can use this API when you want to know caller's information.
+ *
+ * @param[in] pid given pid
+ * @param[out] pkgid package id
+ * @param[in] len length of pkgid
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_ERROR - no such a appid
+ *
+ * @code
+ * #include <aul.h>
+ * #include <bundle.h>
+ *
+ * static int app_reset(bundle *b, void *data)
+ * {
+ * int pid;
+ * char pkgid[255];
+ *
+ * pid = atoi(bundle_get_val(b, AUL_K_CALLER_PID));
+ * aul_app_get_pkgid_bypid(pid, pkgid, sizeof(pkgid));
+ * }
+ *
+ * @endcode
+ * @remark
+ * This API is only available in User Session.
+*/
+int aul_app_get_pkgid_bypid(int pid, char *pkgid, int len);
+
+/**
+ * @par Description:
+ * This API get application pkgid by pid
+ * @par Purpose:
+ * If you want to get pkgid of running application, use this API
+ * @par Typical use case:
+ * In general, You can use this API when you want to know caller's information.
+ *
+ * @param[in] pid given pid
+ * @param[out] pkgid package id
+ * @param[in] len length of pkgid
+ * @param[in] uid User ID
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_ERROR - no such a appid
+ *
+ * @remark
+ * This API is also available to System user.
+*/
+int aul_app_get_pkgid_bypid_for_uid(int pid, char *pkgid, int len, uid_t uid);
+
+/**
+ * @par Description:
+ * This API get application appid by pid
+ * @par Purpose:
+ * If you want to get appid of running application, use this API
+ * @par Typical use case:
+ * In general, You can use this API when you want to know caller's information.
+ *
+ * @param[in] pid given pid
+ * @param[out] appid application id
+ * @param[in] len length of pkgname
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_ERROR - no such a appid
+ * @code
+ * #include <aul.h>
+ * #include <bundle.h>
+ *
+ * static int app_reset(bundle *b, void *data)
+ * {
+ * int pid;
+ * char appid[255];
+ *
+ * pid = atoi(bundle_get_val(b,AUL_K_CALLER_PID));
+ * aul_app_get_appid_bypid(pid, appid, sizeof(appid));
+ * }
+ *
+ * @endcode
+ * @remark
+ * This API is only available in User Session.
+*/
+int aul_app_get_appid_bypid(int pid, char *appid, int len);
+
+/**
+ * @par Description:
+ * This API get application appid by pid
+ * @par Purpose:
+ * If you want to get appid of running application, use this API
+ * @par Typical use case:
+ * In general, You can use this API when you want to know caller's information.
+ *
+ * @param[in] pid given pid
+ * @param[out] appid application id
+ * @param[in] len length of pkgname
+ * @param[in] uid User ID
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_ERROR - no such a appid
+ * @remark
+ * This API is also available to System user.
+*/
+int aul_app_get_appid_bypid_for_uid(int pid, char *appid, int len, uid_t uid);
+
+/**
+ * @par Description:
+ * This API launch application associated with given filename
+ * @par Purpose:
+ * This API is for caller.
+ * This API launch application based on mime type.
+ * This API find mime_type associated with file name,
+ * and then find default app associated with found mime_type
+ * and then launch the app with filename argument.
+ * @par Typical use case:
+ * You can launch application to process given filename.
+ * That is, Even if you don't know the specific application's pkgname,
+ * you can launch the applicaiton processing given filename .
+ * For example, If you want to process image file, you can simply launch image viewer.
+ * At that time, you can use this APIs like aul_open_file("myimage.jpg");
+ *
+ * @param[in] filename filename
+ * @return callee's pid or 0 if success, negative value if fail\n
+ * (when no found default app, return 0)
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_EINVAL - invalid argument(filename)
+ * @retval AUL_R_ECOM - internal AUL IPC error
+ * @retval AUL_R_ERROR - general error
+ *
+ * @code
+ * #include <aul.h>
+ *
+ * int view_image_file(char *filename)
+ * {
+ * aul_open_file(filename);
+ * }
+ *
+ * @endcode
+ * @remark
+ * This API is only available in User Session.
+ *
+ */
+int aul_open_file(const char* filename);
+
+/**
+ * @par Description:
+ * This API launch application associated with given specific mimetype
+ * @par Purpose:
+ * This API is for caller.
+ * This API launch application based on mime type like aul_open_file API.
+ * But, This API don't find mime_type associated with file name.
+ * This API use mimetype given by user. By using given mimetype, find default application.
+ * and then launch the app with filename argument.
+ * @par Typical use case:
+ * Some files cannot extract exact mimetype automatically.
+ * For example, To know mime type of files with DRM lock, first we should unlock DRM file.
+ * In this case, You can use this API.
+ * First, unlock DRM file, and extract mimetype from unlock file by using aul_get_mime_from_file,
+ * and then, use this API with DRM file and extracted mime type.
+ *
+ * @param[in] filename filename
+ * @param[in] mimetype specific mimetype
+ * @return callee's pid or 0 if success, negative value if fail\n
+ * (when no found default app, return 0)
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_EINVAL - invalid argument(filename,mimetype)
+ * @retval AUL_R_ECOM - internal AUL IPC error
+ * @retval AUL_R_ERROR - general error
+ *
+ * @see
+ * aul_open_file, aul_get_mime_from_file
+ * @code
+ * #include <aul.h>
+ *
+ * int view_drm_image_file(char *drm_filename)
+ * {
+ * char* mimetype;
+ * // you must implement this function
+ * mimetype = get_mimetype_from_drmfile(drm_filename);
+ *
+ * aul_open_file_with_mimetype(drm_filename,mimetype);
+ * }
+ *
+ * @endcode
+ * @remark
+ * This API is only available in User Session.
+ */
+int aul_open_file_with_mimetype(const char *filename, const char *mimetype);
+
+/**
+ * @par Description:
+ * This API launch application associated with content like "http://www.samsung.com"
+ * @par Purpose:
+ * This API is for caller.
+ * This API launch application based on mime type.
+ * This API find mime_type associated with content,
+ * and then find default app associated with found mime_type,
+ * and then launch the app with content argument.
+ * @par Typical use case:
+ * You can launch application to process given content.
+ * That is, Even if you don't know the specific application's pkgname,
+ * you can launch the applicaiton processing given content.
+ * For example, If you want to process URL "http://www.samsung.com",
+ * you can simply launch browser.
+ * At that time, you can use this APIs like aul_open_content("http://www.samsung.com");
+ *
+ * @param[in] content content
+ * @return callee's pid or 0 if success, negative value if fail\n
+ * (when no found default app, return 0)
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_EINVAL - invalid argument(content)
+ * @retval AUL_R_ECOM - internal AUL IPC error
+ * @retval AUL_R_ERROR - general error or no found mimetype
+ *
+ * @code
+ * #include <aul.h>
+ *
+ * int view_url(char *url)
+ * {
+ * aul_open_content(url);
+ * }
+ *
+ * @endcode
+ * @remark
+ * This API is only available in User Session.
+ *
+ */
+int aul_open_content(const char* content);
+
+/**
+ * @par Description:
+ * This API get the default application(appid) associated with MIME type
+ * @par Purpose:
+ * This API use to get default application associteted with mimetype
+ * In general, Setting Application need this API.
+ * @par Typical use case:
+ * Setting Application show mapping of default application / mimetype
+ *
+ * @param[in] mimetype a mime type
+ * @param[out] defapp a application appid of the app
+ * @param[in] len length of defapp
+ * @return 0 if success, negative value if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_EINVAL - invalid argument(mimetype)
+ * @retval AUL_R_ERROR - general error or no found mimetype
+ *
+ * @see
+ * aul_set_defapp_with_mime
+ * @code
+ * #include <aul.h>
+ *
+ * void get_text_html_defapp()
+ * {
+ * char appname[255];
+ * aul_get_defapp_from_mime("text/html",appname,sizeof(appname));
+ * }
+ *
+ * @endcode
+ * @remark
+ * This API is only available in User Session.
+ *
+ */
+int aul_get_defapp_from_mime(const char *mimetype, char *defapp, int len);
+
+/**
+ * @par Description:
+ * This API set the default application(appid) associated with MIME type
+ * @par Purpose:
+ * This API use to change default application associteted with mimetype
+ * In general, Setting Application or Installer need this API.
+ * @par Typical use case:
+ * Default Application associated with mimetype can be changed by Setting Application or installer
+ * So, application to process specific mimetype can be substituted.
+ *
+ * @param[in] mimetype a mime type
+ * @param[in] defapp a application appid of the app to be set
+ * @return 0 if success, negative value if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_EINVAL - invalid argument(mimetype)
+ * @retval AUL_R_ERROR - general error
+ *
+ * @see
+ * aul_get_defapp_from_mime
+ * @code
+ * #include <aul.h>
+ *
+ * void set_text_html_defapp()
+ * {
+ * aul_set_defapp_with_mime("text/html","org.tizen.browser");
+ * }
+ *
+ * @endcode
+ * @remark
+ * This API is only available in User Session.
+*/
+int aul_set_defapp_with_mime(const char *mimetype, const char *defapp);
+
+/**
+ * @par Description:
+ * This API get the mimetype associated with filename
+ * @par Purpose:
+ * This API use to get mimetype associteted with given filename
+ * In general, This API use when you want to know only mimetype given filename.
+ * @par Typical use case:
+ * For example, In trasfering data through bluetooth,
+ * additional information like mimetype should be added.
+ * In such situation, You can get mimetype by using this API.
+ *
+ * @param[in] filename file name
+ * @param[out] mimetype a mime type
+ * @param[in] len length of mimetype
+ * @return 0 if success, negative value if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_EINVAL - invalid argument(filename)
+ * @retval AUL_R_ERROR - general error
+ *
+ * @code
+ * #include <aul.h>
+ *
+ * void get_mimetype()
+ * {
+ * char mimetype[255];
+ * aul_get_mime_from_file("image.jpg",mimetype,sizeof(mimetype));
+ * }
+ *
+ * @endcode
+ * @remark
+ * This API is only available in User Session.
+ */
+int aul_get_mime_from_file(const char *filename, char *mimetype, int len);
+
+/**
+ * @par Description:
+ * This API get the mimetype associated with given content
+ * @par Purpose:
+ * This API use to get mimetype associteted with given content
+ * In general, This API use when you want to know only mimetype given content
+ * @par Typical use case:
+ * For example, In trasfering data through bluetooth,
+ * additional information like mimetype should be added.
+ * In such situation, You can get mimetype by using this API.
+ *
+ * @param[in] content content string like "011-0000-0000"
+ * @param[out] mimetype a mime type
+ * @param[in] len length of mimetype
+ * @return 0 if success, negative value if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_EINVAL - invalid argument(content)
+ * @retval AUL_R_ERROR - general error
+ *
+ * @code
+ * #include <aul.h>
+ *
+ * void get_mimetype()
+ * {
+ * char mimetype[255];
+ * aul_get_mime_from_content("http://www.samsung.com",mimetype,sizeof(mimetype));
+ * }
+ *
+ * @endcode
+ * @remark
+ * This API is only available in User Session.
+*/
+int aul_get_mime_from_content(const char *content, char *mimetype, int len);
+
+/**
+ * @par Description:
+ * This API get the icon's name associated with given mimetype
+ * @par Purpose:
+ * This API use to get icon's name associteted with given mimetype
+ * @par Typical use case:
+ * If you want to show mimetype's icon, use this API.
+ *
+ * @param[in] mimetype a mime type
+ * @param[out] iconname icon's name
+ * @param[in] len length of iconname
+ * @return 0 if success, negative value if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_EINVAL - invalid argument(content)
+ * @retval AUL_R_ERROR - general error (no such mime type)
+ *
+ * @code
+ * #include <aul.h>
+ *
+ * void get_mime_icon()
+ * {
+ * char icon[255];
+ * aul_get_mime_icon("text/html",icon,sizeof(icon));
+ * }
+ *
+ * @endcode
+ * @remark
+ * This API is only available in User Session.
+ */
+int aul_get_mime_icon(const char *mimetype, char *iconname, int len);
+
+/**
+ * @par Description:
+ * This API get the extensions associated with given mimetype
+ * @par Purpose:
+ * This API use to get extensions associteted with given mimetype
+ * @par Typical use case:
+ * In general, user is not familiar with mimetype(text/html),
+ * user is familiar with extenstions(*.html, *.htm)
+ * So, To show mimetype information to user, use this API
+ *
+ * @param[in] mimetype a mime type
+ * @param[out] extlist extentions (ex> mpeg,mpg,mpe)
+ * @param[in] len length of extlist
+ * @return 0 if success, negative value if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_EINVAL - invalid argument(mimetype)
+ * @retval AUL_R_ERROR - general error (no mimetype or no extenstion)
+ *
+ * @see
+ * aul_get_mime_description
+ * @code
+ * #include <aul.h>
+ *
+ * void get_extension()
+ * {
+ * char extlist[255];
+ * aul_get_mime_extension("text/html",extlist,sizeof(extlist));
+ * }
+ *
+ * @endcode
+ * @remark
+ * Some mimetype don't have extension.
+ * In that case, You can use aul_get_mime_description.
+ * This API is only available in User Session.
+*/
+int aul_get_mime_extension(const char *mimetype, char *extlist, int len);
+
+/**
+ * @par Description:
+ * This API get the description associated with given mimetype
+ * @par Purpose:
+ * This API use to get description associteted with given mimetype
+ * @par Typical use case:
+ * In general, user is not familiar with mimetype(text/html),
+ * user is familiar with well-knowing information like extenstions(*.html, *.htm)
+ * But, some mimetype don't have extenstion.
+ * At that time,to show mimetype information to user, use this API
+ *
+ * @param[in] mimetype a mime type
+ * @param[out] desc description (ex> Call client)
+ * @param[in] len length of desc
+ * @return 0 if success, negative value if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_EINVAL - invalid argument(mimetype)
+ * @retval AUL_R_ERROR - general error (no mimetype or no descrition)
+ *
+ * @see
+ * aul_get_mime_extension
+ * @code
+ * #include <aul.h>
+ *
+ * void get_information_from_mime()
+ * {
+ * char info[255];
+ * if(aul_get_mime_extension("text/html",info,sizeof(info))<0){
+ * aul_get_mime_description("text/html",info,sizeof(info));
+ * }
+ * }
+ *
+ * @endcode
+ * @remark
+ * This API is only available in User Session.
+ */
+int aul_get_mime_description(const char *mimetype, char *desc, int len);
+
+/**
+ * @par Description:
+ * This API create service result bundle based on bundle received in reset event.
+ * @par Purpose:
+ * This API use to create result bundle to send it to caller.
+ * @par Typical use case:
+ * This API is for callee which provide application service.\n
+ * To send result to caller, You must create result bundle. \n
+ * Callee(application providing the service) can send result by using this API and aul_send_service_result.
+ *
+ * @param[in] inb bundle received in reset event
+ * @param[out] outb bundle to use for returning result
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_EINVAL - inb is not bundle created by aul_open_service
+ * @retval AUL_R_ERROR - general error
+ *
+ * @pre
+ * To create result bundle, You need received original bundle.
+ * The original bundle can get from app_reset handler.
+ * @post
+ * None
+ * @see
+ * aul_send_service_result
+ * @code
+ * #include <aul.h>
+ * #include <bundle.h>
+ *
+ * int app_reset(bundle *b, void *data)
+ * {
+ * ad->recved_bundle = bundle_dup(b);
+ * }
+ *
+ * int click_ok()
+ * {
+ * bundle* res_bundle;
+ * aul_create_result_bundle(ad->recved_bundle,&res_bundle);
+ * bundle_add(res_bundle, "result", "1");
+ * aul_send_service_result(res_bundle);
+ * }
+ * @endcode
+ * @remark
+ * This API is only available in User Session.
+ *
+ */
+int aul_create_result_bundle(bundle *inb, bundle **outb);
+
+/**
+ * @par Description:
+ * This API send service result to caller with bundle
+ * @par Purpose:
+ * This API is used to send result bundle to caller.
+ * @par Typical use case:
+ * This API is for callee which provide application service.\n
+ * To send result to caller, You can use this API after creating result bundle. \n
+ * Callee(application to provide service) can send result by using this API and aul_create_result_bundle.
+ *
+ * @param[in] b Result data in bundle format
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_EINVAL - invalid result bundle
+ * @retval AUL_R_ECOMM - internal AUL IPC error
+ * @retval AUL_R_ERROR - general error
+ *
+ * @pre
+ * To send result bundle, You must create result bundle.
+ * see aul_create_result_bundle
+ * @post
+ * None
+ * @see
+ * aul_create_result_bundle
+ * @code
+ * #include <aul.h>
+ * #include <bundle.h>
+ *
+ * int app_reset(bundle *b, void *data)
+ * {
+ * ad->recved_bundle = bundle_dup(b);
+ * }
+ *
+ * int click_ok()
+ * {
+ * bundle* res_bundle;
+ * aul_create_result_bundle(ad->recved_bundle,&res_bundle);
+ * bundle_add(res_bundle, "result", "1");
+ * aul_send_service_result(res_bundle);
+ * }
+ * @endcode
+ * @remark
+ * This API is only available in User Session.
+ *
+ */
+int aul_send_service_result(bundle *b);
+
+/**
+ * @brief Called when an application is terminated.
+ * @details This function is called when an application is terminated, after you register this callback using aul_listen_app_dead_signal().
+ * @param[in] pid The process ID
+ * @param[in] user_data The user data passed from the registeration function
+ *
+ * @see aul_listen_app_dead_signal()
+ */
+typedef int (*aul_app_dead_event_cb)(int pid, void *user_data);
+
+/**
+ * @breif Registers a callback function to be invoked when the application is terminated.
+ * @remarks If the callback function is nullptr, the registered event will be deregistered.
+ * @param[in] callback The callback function
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_R_OK Successful
+ * @retval #AUL_R_ERROR Internal I/O error
+ * @see aul_app_dead_event_cb()
+ *
+ * @remarks This function is only available for App Framework internally.
+ *
+ * @code
+ * #include <aul.h>
+ *
+ * static int app_dead_event_cb(int pid, void *user_data)
+ * {
+ * dlog_print(DLOG_INFO, LOG_TAG, "application(%s) is terminated", pid);
+ * return 0;
+ * }
+ *
+ * int listen_app_dead_signal(void)
+ * {
+ * int ret;
+ *
+ * ret = aul_listen_app_dead_signal(app_dead_event_cb, NULL);
+ * if (ret != AUL_R_OK) {
+ * dlog_print(DLOG_ERROR, LOG_TAG, "aul_listen_app_dead_signal() is failed. error(%d)", ret);
+ * return -1;
+ * }
+ *
+ * return 0;
+ * }
+ */
+int aul_listen_app_dead_signal(aul_app_dead_event_cb callback, void *user_data);
+
+/**
+ * @brief Called when an application is launched.
+ * @details This function is called when an application is launched, after you register this callback using aul_listen_app_launch_signal().
+ * @param[in] pid The process ID
+ * @param[in] user_data The user data passed from the registeration function
+ *
+ * @see aul_listen_app_launch_signal()
+ */
+typedef int (*aul_app_launch_event_cb)(int pid, void *user_data);
+
+/**
+ * @brief Registers a callback function to be invoked when the application is launched.
+ * @remarks If the callback function is nullptr, the registered event will be deregistered.
+ * @param[in] callback The callback function
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_R_OK Successful
+ * @retval #AUL_R_ERROR Internal I/O error
+ * @see aul_app_launch_event_cb()
+ *
+ * @remarks This function is only available for App Framework internally.
+ *
+ * @see
+ * #include <aul.h>
+ *
+ * static int app_launch_event_cb(int pid, void *user_data)
+ * {
+ * dlog_print(DLOG_INFO, LOG_TAG, "application(%d) is launched", pid);
+ * return 0;
+ * }
+ *
+ * int listen_app_launch_signal(void)
+ * {
+ * int ret;
+ *
+ * ret = aul_listen_app_launch_signal(app_launch_event_cb, NULL);
+ * if (ret != AUL_R_OK) {
+ * dlog_print(DLOG_ERROR, LOG_TAG, "aul_listen_app_launch_signal() is failed. error(%d)", ret);
+ * return -1;
+ * }
+ *
+ * return 0;
+ * }
+ */
+int aul_listen_app_launch_signal(aul_app_launch_event_cb callback, void *user_data);
+
+/**
+ * @brief Called when an application is launched.
+ * @details This function is called when an application is launched, after you register this callback using aul_listen_app_launch_signal_v2().
+ * @param[in] pid The process ID
+ * @param[in] appid The application ID
+ * @param[in] user_data The user data passed from the registeration function
+ *
+ * @see aul_listen_app_launch_signal_v2()
+ */
+typedef int (*aul_app_launch_event_cb_v2)(int pid, const char *appid, void *user_data);
+
+/**
+ * @brief Registers a callback function to be invoked when the application is launched.
+ * @remarks If the callback function is nullptr, the registered event will be deregistered.
+ * @param[in] callback The callback function
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_R_OK Successful
+ * @retval #AUL_R_ERROR Internal I/O error
+ *
+ * @see aul_app_launch_event_cb_v2()
+ *
+ * @remarks This function is only available for App Framework internally.
+ *
+ * @code
+ * #include <aul.h>
+ *
+ * static int app_launch_event_cb(int pid, const char *appid, void *user_data)
+ * {
+ * dlog_print(DLOG_INFO, LOG_TAG, "application(%s:%d) is launched", appid, pid);
+ * return 0;
+ * }
+ *
+ * int listen_app_launch_signal(void)
+ * {
+ * int ret;
+ *
+ * ret = aul_listen_app_launch_signal_v2(app_launch_event_cb, NULL);
+ * if (ret != AUL_R_OK) {
+ * dlog_print(DLOG_ERROR, LOG_TAG, "aul_listen_app_launch_signal_v2() is failed. error(%d)", ret);
+ * return -1;
+ * }
+ *
+ * return 0;
+ * }
+ */
+int aul_listen_app_launch_signal_v2(aul_app_launch_event_cb_v2 callback, void *user_data);
+
+/**
+ * @brief Called when an application is terminated.
+ * @details This function is called when an application is terminated, after you register this callback using aul_listen_app_dead_signal_v2().
+ * @param[in] pid The process ID
+ * @param[in] status The exit status
+ * @param[in] user_data The user data passed from the registeration function
+ *
+ * @see aul_listen_app_dead_signal_v2()
+ */
+typedef void (*aul_app_dead_event_cb_v2)(int pid, int status, void* user_data);
+
+/**
+ * @breif Registers a callback function to be invoked when the application is terminated.
+ * @remarks If the callback function is nullptr, the registered event will be deregistered.
+ * @param[in] callback The callback function
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_R_OK Successful
+ * @retval #AUL_R_ERROR Internal I/O error
+ * @see aul_app_dead_event_cb_v2()
+ *
+ * @remarks This function is only available for App Framework internally.
+ *
+ * @code
+ * #include <aul.h>
+ *
+ * static void app_dead_event_cb(int pid, int status, void *user_data)
+ * {
+ * dlog_print(DLOG_INFO, LOG_TAG, "application(%s) is terminated. status(%d)", pid, status);
+ * }
+ *
+ * int listen_app_dead_signal(void)
+ * {
+ * int ret;
+ *
+ * ret = aul_listen_app_dead_signal_v2(app_dead_event_cb, NULL);
+ * if (ret != AUL_R_OK) {
+ * dlog_print(DLOG_ERROR, LOG_TAG, "aul_listen_app_dead_signal_v2() is failed. error(%d)", ret);
+ * return -1;
+ * }
+ *
+ * return 0;
+ * }
+ */
+int aul_listen_app_dead_signal_v2(aul_app_dead_event_cb_v2 callback, void *user_data);
+
+/**
+ * @par Description:
+ * This API gets status of specified application process id.
+ * @par Purpose:
+ * This API's purpose is to get the application's status.
+ *
+ * @param[in] pid pid of application
+ * @return 0 or greater if success, nagative value if fail
+ * @retval STATUS_LAUNCHING
+ * @retval STATUS_VISIBLE
+ * @retval STATUS_BG
+ * @retval STATUS_DYING
+ * @retval STATUS_NORESTART
+ * @see
+ * aul_status_update
+ * @code
+ * #include <aul.h>
+ *
+ * int iterfunc(const aul_app_info *info, void *data)
+ * {
+ * int status;
+ * status = aul_app_get_status_bypid(info->pid);
+ * if (status == STATUS_VISIBLE) {
+ * printf("%s has focus", info->app_id);
+ * (int *)data = info->pid;
+ * return -1;
+ * }
+ * return 0;
+ * }
+ *
+ * int find_focus_app_pid()
+ * {
+ * int pid = 0;
+ * aul_app_get_running_app_info(iterfunc, &pid);
+ * return pid;
+ * }
+ * @endcode
+ * @remark
+ * This API is only available in User Session.
+ */
+int aul_app_get_status_bypid(int pid);
+
+/**
+ * @par Description:
+ * This API gets status of specified application process id.
+ * @par Purpose:
+ * This API's purpose is to get the application's status.
+ *
+ * @param[in] pid pid of application
+ * @param[in] uid User ID
+ * @return 0 or greater if success, nagative value if fail
+ * @retval STATUS_LAUNCHING
+ * @retval STATUS_VISIBLE
+ * @retval STATUS_BG
+ * @retval STATUS_DYING
+ * @retval STATUS_NORESTART
+ *
+ * @remark
+ * This API is only available to System user.
+ */
+int aul_app_get_status_bypid_for_uid(int pid, uid_t uid);
+
+/**
+ * @par Description:
+ * This API gets the status of specified application id.
+ * @par Purpose:
+ * This API's purpose is to get the status of the application.
+ *
+ * @param[in] appid application ID
+ * @return 0 or greater if success, nagative value if fail
+ * @retval STATUS_LAUNCHING
+ * @retval STATUS_FOCUS
+ * @retval STATUS_VISIBLE
+ * @retval STATUS_BG
+ * @retval STATUS_DYING
+ * @retval STATUS_NORESTART
+ * @see
+ * aul_status_update
+ * @code
+ * #include <aul.h>
+ *
+ * int func(void)
+ * {
+ * int status;
+ *
+ * status = aul_app_get_status("org.tizen.helloworld");
+ * if (status == STATUS_FOCUS)
+ * printf("org.tizen.helloworld has focus");
+ *
+ * return 0;
+ * }
+ *
+ * @endcode
+ * @remark
+ * This API is only available in User Session.
+ */
+int aul_app_get_status(const char *appid);
+
+/**
+ * @par Description:
+ * This API gets the status of specified application id.
+ * @par Purpose:
+ * This API's purpose is to get the status of the application
+ *
+ * @param[in] appid application ID
+ * @param[in] uid User ID
+ * @return 0 or greater if success, nagative value if fail
+ * @retval STATUS_LAUNCHING
+ * @retval STATUS_FOCUS
+ * @retval STATUS_VISIBLE
+ * @retval STATUS_BG
+ * @retval STATUS_DYING
+ * @retval STATUS_NORESTART
+ *
+ * @remark
+ * This API is only available to System user.
+ */
+int aul_app_get_status_for_uid(const char *appid, uid_t uid);
+
+/**
+ * @brief Called when the status is changed.
+ * @remarks If @c is a negative error value,
+ * the registered callback function will be deregistered.
+ * @param[in] status The status
+ * @param[in] user_data The user data passed from the registration function
+ * @return @c 0 to continue with the next iteration of the loop,
+ * otherwise a negative error value to break out of the loop
+ * @see aul_add_status_local_cb()
+ * @see aul_remove_status_local_cb();
+ */
+typedef int (*aul_status_local_cb)(int status, void *user_data);
+
+/**
+ * @par Description
+ * This API sets callback function that on application status changed.
+ * @par Purpose:
+ * This API's purpose is to listen the application's status changed within
+ * the caller process. In general, a library that required to release resource on
+ * application's status may use this API.
+ *
+ * @param[in] callback callback function
+ * @param[in] data user data
+ * @return 0 if success, negative value if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_ERROR - general error
+ * @see
+ * aul_remove_status_local_cb
+ * @code
+ * #include <aul.h>
+ *
+ * int status_changed(int status, void *data)
+ * {
+ * if (status == STATUS_VISIBLE)
+ * printf("%d resume\n", getpid());
+ *
+ * if (status == STATUS_BG)
+ * printf("%d pause\n", getpid());
+ * }
+ *
+ * void listen_app_status()
+ * {
+ * aul_add_status_local_cb(status_changed, NULL);
+ * }
+ * @endcode
+ * @remark
+ * This API is only available in User Session.
+ *
+ */
+int aul_add_status_local_cb(aul_status_local_cb callback, void *data);
+
+/**
+ * @par Description
+ * This API unsets callback function that on application status changed.
+ * @par Purpose:
+ * This API's purpose is to remove callback that added by
+ * aul_add_status_local_cb.
+ *
+ * @param[in] callback callback function
+ * @param[in] data user data
+ * @return 0 if success, negative value if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_ERROR - general error
+ *
+ * @see
+ * aul_add_status_local_cb
+ * @code
+ * #include <aul.h>
+ *
+ * int status_changed(int status, void *data)
+ * {
+ * if (status == STATUS_VISIBLE)
+ * printf("%d resume\n", getpid());
+ *
+ * if (status == STATUS_BG)
+ * printf("%d pause\n", getpid());
+ * }
+ *
+ * void listen_app_status()
+ * {
+ * aul_add_status_local_cb(status_changed, NULL);
+ * }
+ *
+ * void ignore_app_status()
+ * {
+ * aul_remove_status_local_cb(status_changed, NULL);
+ * }
+ *
+ * @endcode
+ * @remark
+ * This API is only available in User Session.
+ *
+ */
+int aul_remove_status_local_cb(aul_status_local_cb callback, void *data);
+
+/*
+ * This API is only for appfw internally.
+ */
+int aul_set_process_group(int parent_pid, int child_pid);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_terminate_bgapp_pid(int pid);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_terminate_pid_without_restart(int pid);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_terminate_pid_sync_without_restart(int pid);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_terminate_pid_sync_without_restart_for_uid(int pid, uid_t uid);
+
+/*
+ * This API is only for Appfw internally.
+ */
+const char *aul_get_app_external_root_path(void);
+
+/*
+ * This API is only for Appfw internally.
+ */
+const char *aul_get_app_root_path(void);
+
+/*
+ * This API is only for Appfw internally.
+ */
+const char *aul_get_app_data_path(void);
+
+/*
+ * This API is only for Appfw internally.
+ */
+const char *aul_get_app_cache_path(void);
+
+/*
+ * This API is only for Appfw internally.
+ */
+const char *aul_get_app_resource_path(void);
+
+/*
+ * This API is only for Appfw internally.
+ */
+const char *aul_get_app_tep_resource_path(void);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_get_app_shared_data_path(char **path);
+
+/*
+ * This API is only for Appfw internally.
+ */
+const char *aul_get_app_shared_resource_path(void);
+
+/*
+ * This API is only for Appfw internally.
+ */
+const char *aul_get_app_shared_trusted_path(void);
+
+/*
+ * This API is only for Appfw internally.
+ */
+const char *aul_get_app_external_data_path(void);
+
+/*
+ * This API is only for Appfw internally.
+ */
+const char *aul_get_app_external_cache_path(void);
+
+/*
+ * This API is only for Appfw internally.
+ */
+const char *aul_get_app_external_shared_data_path(void);
+
+/*
+ * This API is only for Appfw internally.
+ */
+const char *aul_get_app_specific_path(void);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_get_app_res_control_allowed_resource_path(const char *res_type, char **path);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_get_app_res_control_global_resource_path(const char *res_type, char **path);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_get_app_shared_data_path_by_appid(const char *app_id, char **path);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_get_app_shared_resource_path_by_appid(const char *app_id, char **path);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_get_app_shared_trusted_path_by_appid(const char *app_id, char **path);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_get_app_external_shared_data_path_by_appid(const char *app_id, char **path);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_get_usr_app_shared_data_path_by_appid(const char *app_id, char **path, uid_t uid);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_get_usr_app_shared_resource_path_by_appid(const char *app_id, char **path, uid_t uid);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_get_usr_app_shared_trusted_path_by_appid(const char *app_id, char **path, uid_t uid);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_get_usr_app_external_shared_data_path_by_appid(const char *app_id, char **path, uid_t uid);
+
+/*
+ * This type is only for Appfw internally.
+ */
+typedef int (*subapp_fn)(void *data);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_set_subapp(subapp_fn cb, void *data);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_subapp_terminate_request_pid(int pid);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_is_subapp(void);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_kill_pid(int pid);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_add_caller_cb(int pid, void (*caller_cb) (int, void *), void *data);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_remove_caller_cb(int pid, void *data);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_invoke_caller_cb(void *data);
+
+/*
+ * This API is only for Appfw internally.
+ */
+void aul_set_preinit_window(void *evas_object);
+
+/*
+ * This API is only for Appfw internally.
+ */
+void* aul_get_preinit_window(const char *win_name);
+
+/*
+ * This API is only for Appfw internally.
+ */
+void aul_set_preinit_background(void *evas_object);
+
+/*
+ * This API is only for Appfw internally.
+ */
+void* aul_get_preinit_background(void);
+
+/*
+ * This API is only for Appfw internally.
+ */
+void aul_set_preinit_conformant(void *evas_object);
+
+/*
+ * This API is only for Appfw internally.
+ */
+void* aul_get_preinit_conformant(void);
+
+/*
+ * This API is only for Appfw internally.
+ */
+void aul_set_preinit_appid(const char *appid);
+
+/*
+ * This API is only for Appfw internally.
+ */
+void aul_set_preinit_pkgid(const char *pkgid);
+
+/*
+ * This API is only for Appfw internally.
+ */
+void aul_set_preinit_root_path(const char *root_path);
+
+/*
+ * This API is only for Appfw internally.
+ */
+const char *aul_get_preinit_root_path(void);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_update_freezer_status(int pid, const char* type);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_send_app_launch_request_signal(int pid, const char* appid, const char* pkgid, const char* type);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_send_app_resume_request_signal(int pid, const char* appid, const char* pkgid, const char *type);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_send_app_terminate_request_signal(int pid, const char* appid, const char* pkgid, const char *type);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_send_app_status_change_signal(int pid, const char* appid, const char* pkgid, const char* status, const char *type);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_send_app_terminated_signal(int pid);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_send_app_group_signal(int owner_pid, int child_pid, const char *child_pkgid);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_invoke_status_local_cb(int status);
+
+/*
+ * This type is only for Appfw internally.
+ */
+typedef int (*data_control_provider_handler_fn) (bundle *b, int request_id, void *data);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_set_data_control_provider_cb(data_control_provider_handler_fn handler);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_unset_data_control_provider_cb(void);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_pause_app(const char *appid);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_pause_app_for_uid(const char *appid, uid_t uid);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_pause_pid(int pid);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_pause_pid_for_uid(int pid, uid_t uid);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_reload_appinfo(void);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_status_update(int status);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_app_group_get_window(int pid);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_app_group_set_window(int wid);
+
+/*
+ * This API is only for Appfw internally.
+ */
+void aul_app_group_get_leader_pids(int *cnt, int **pids);
+
+/*
+ * This API is only for Appfw internally.
+ */
+void aul_app_group_get_group_pids(int leader_pid, int *cnt, int **pids);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_app_group_get_leader_pid(int pid);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_app_group_clear_top(void);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_app_group_is_top(void);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_app_group_get_fg_flag(int pid);
+
+/*
+ * This API is only for Appfw internally.
+ */
+void aul_app_group_lower(int *exit);
+
+/*
+ * This API is only for Appfw internally.
+ */
+void aul_app_group_get_idle_pids(int *cnt, int **pids);
+
+/**
+ * @par Description:
+ * This API puts some app below the caller app
+ * @par Purpose:
+ * This API's purpose is to reorder window stack limitedly.
+ *
+ * @param[in] below_appid The appid to be reordered below the caller app
+ * @return 0 success, negative value(<0) if fail
+ *
+ * @remark
+ * below_appid should be main app which have been launched before.
+ * This API is only available in User Session.
+*/
+int aul_app_group_activate_below(const char *below_appid);
+
+/**
+ * @par Description:
+ * This API puts some app above the caller app
+ * @par Purpose:
+ * This API's purpose is to reorder window stack limitedly.
+ *
+ * @param[in] above_appid The appid to be reordered above the caller app
+ * @return 0 if success, negative value(<0) if fail
+ *
+ * @remark
+ * above_appid should be main app which have been launched before.
+ * This API is only available in User Session.
+*/
+int aul_app_group_activate_above(const char *above_appid);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_request_data_control_socket_pair(bundle *b, int *fd);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_request_message_port_socket_pair(int *fd);
+
+/**
+ * @brief Called when the system booting is completed.
+ * @param[in] unused The unused parameter
+ * @param[in] user_data The use data passed from the registration function
+ * @return The return value is not used.
+ *
+ * @see aul_listen_booting_done_signal();
+ */
+typedef int (*aul_booting_done_event_cb)(int unused, void *user_data);
+
+/**
+ * @brief Registers a callback function to be invoked when the system booting is completed.
+ * @param[in] callback The callback function
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @see aul_booting_done_event_cb()a
+ * @remarks This function is only available for App Framework internally.
+ */
+int aul_listen_booting_done_signal(aul_booting_done_event_cb, void *user_data);
+
+/**
+ * @brief Called when the coodlown event occurs.
+ * @param[in] status The cooldown status
+ * @param[in] user_data The user data passed from the registration function
+ * @return The return value is not used.
+ *
+ * @see aul_listen_cooldown_signal()
+ */
+typedef int (*aul_cooldown_event_cb)(const char *status, void *user_data);
+
+/**
+ * @brief Registers a callback function to be invoked when the cooldown event occurs.
+ * @param[in] callback The callback function
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @see aul_coodlown_event_cb()
+ *
+ * @remarks This function is only available for App Framework internally.
+ */
+int aul_listen_cooldown_signal(int (*func) (const char *, void *), void *data);
+
+/**
+ * @brief Called when the status of the app process is changed.
+ * @details This function is called when the app process status is changed, after you register this callback using aul_listen_app_status_signal().
+ * @param[in] pid The process ID
+ * @param[in] status The status of the process
+ * @param[in] user_data The user data passed from the registeration function
+ *
+ * @see @aul_listen_app_status_signal()
+ * @see #aul_process_status_e
+ */
+typedef int (*aul_app_status_changed_cb)(int pid, int status, void *user_data);
+
+/**
+ * @brief Registers a callback function to be invoked when the process status is changed.
+ * @remarks If the callback function is nullptr, the registered event will be deregistered.
+ * @param[in] callback The callback function
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_R_OK Successful
+ * @retval #AUL_R_ERROR Internal I/O error
+ *
+ * @see @aul_app_status_changed_cb()
+ * @see #aul_process_status_e
+ *
+ * @remarks This function is only available for App Framework internally.
+ *
+ * @code
+ * #include <aul.h>
+ *
+ * static int app_status_changed_cb(int pid, int status, void *user_data)
+ * {
+ * cosnt char *app_status;
+ *
+ * switch (status) {
+ * case AUL_PROC_STATUS_LAUNCH:
+ * app_status = "LAUNCHING";
+ * break;
+ * case AUL_PROC_STATUS_FG:
+ * app_status = "VISIBLE";
+ * break;
+ * case AUL_PROC_STATUS_BG:
+ * app_status = "BACKGROUND";
+ * break;
+ * case AUL_PROC_STATUS_FOCUS:
+ * app_status = "FOCUS";
+ * break;
+ * case AUL_PROC_STATUS_HIDE:
+ * app_status = "HIDE";
+ * break;
+ * default:
+ * app_status = "UNKNOWN";
+ * break;
+ * }
+ *
+ * dlog_print(DLOG_INFO, LOG_TAG, "pid: %d, status: %%s(%d)", pid, app_status, status);
+ * return 0;
+ * }
+ *
+ * int listen_app_status_signal(void)
+ * {
+ * int ret;
+ *
+ * ret = aul_listen_app_status_signal(app_status_changed_cb, NULL);
+ * if (ret != AUL_R_OK) {
+ * dlog_print(DLOG_ERROR, LOG_TAG, "aul_listen_app_status_signal() is failed. error(%d)", ret);
+ * return -1;
+ * }
+ *
+ * return 0;
+ * }
+ */
+int aul_listen_app_status_signal(aul_app_status_changed_cb callback, void *user_data);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_check_tep_mount(const char *tep_path);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_is_tep_mount_dbus_done(const char *tep_string);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_forward_app(const char *appid, bundle *kb);
+
+/**
+ * @par Description:
+ * This API create custom launchpad-loader
+ * @par Purpose:
+ * This API's purpose is to make a slot for custom loader.
+ * Once it is made, added loader will make a candidate process to use.
+ *
+ * @param[in] loader_path The file name of the custom loader binary including full path
+ * @param[in] extra A bundle to be passed to the custom loader
+ * @return Loader ID if success, negative value(<0) if fail
+ *
+ * @remark
+ * This API is only for Appfw internally.
+ * This API is only available in User Session.
+*/
+int aul_add_loader(const char *loader_path, bundle *extra);
+
+/**
+ * @par Description:
+ * This API create custom launchpad-loader
+ * @par Purpose:
+ * This API's purpose is to make a slot for custom loader.
+ * Once it is made, added loader will make a candidate process to use.
+ *
+ * @param[in] loader_path The file name of the custom loader binary including full path
+ * @param[in] extra A bundle to be passed to the custom loader
+ * @param[in] uid User ID
+ * @return Loader ID if success, negative value(<0) if fail
+ *
+ * @remark
+ * This API is only for Appfw internally.
+ * This API is only available to System user.
+*/
+int aul_add_loader_for_uid(const char *loader_path, bundle *extra, uid_t uid);
+
+
+/**
+ * @par Description:
+ * This API destroy custom launchpad-loader
+ * @par Purpose:
+ * This API's purpose is to remove a slot for custom loader.
+ * Once it is removed, the prepared process will be removed as well.
+ *
+ * @param[in] loader_id Loader ID
+ * @return 0 if success, negative value(<0) if fail
+ *
+ * @remark
+ * This API is only for Appfw internally.
+ * This API is only available in User Session.
+*/
+int aul_remove_loader(int loader_id);
+
+/**
+ * @par Description:
+ * This API destroy custom launchpad-loader
+ * @par Purpose:
+ * This API's purpose is to remove a slot for custom loader.
+ * Once it is removed, the prepared process will be removed as well.
+ *
+ * @param[in] loader_id Loader ID
+ * @param[in] uid User ID
+ * @return 0 if success, negative value(<0) if fail
+ *
+ * @remark
+ * This API is only for Appfw internally.
+ * This API is only available to System user.
+*/
+int aul_remove_loader_for_uid(int loader_id, uid_t uid);
+
+/**
+ * @par Description
+ * This API gets specified application process id.
+ * @par Purpose:
+ * The purpose of this API is to get the pid of specified application.
+ *
+ * @param[in] appid application name
+ * @return callee's pid if success, negative value(<0) if fail
+ *
+ * @remark
+ * This API is only available in User Session.
+ */
+int aul_app_get_pid(const char *appid);
+
+/**
+ * @par Description
+ * This API gets specified application process id.
+ * @par Purpose:
+ * The purpose of this API is to get the pid of specified application.
+ *
+ * @param[in] appid application name
+ * @param[in] uid User ID
+ * @return callee's pid if success, negative value(<0) if fail
+ *
+ * @remark
+ * This API is only available to System user.
+ */
+int aul_app_get_pid_for_uid(const char *appid, uid_t uid);
+
+/**
+ * @par Description:
+ * This function update rua stat.
+ *
+ * @param[in] b Bundle object contains caller and tag information.
+ * @param[in] uid Target uid
+ *
+ * @return 0 if success, negative value(<0) if fail
+ * @see None
+ * @remarks This API is only for Appfw internally.
+ *
+ * @par Sample code:
+ * @code
+#include <aul.h>
+
+...
+{
+ int r;
+ bundle *b = bundle_create();
+ bundle_add_str(b, AUL_SVC_K_RUA_STAT_CALLER, caller);
+ bundle_add_str(b, AUL_SVC_K_RUA_STAT_TAG, tag);
+
+ r = aul_update_rua_stat_for_uid(b);
+}
+
+ * @endcode
+ **/
+int aul_update_rua_stat_for_uid(bundle *b, uid_t uid);
+
+/**
+ * @par Description:
+ * This function add rua history.
+ *
+ * @param[in] b Bundle object Target Package name or app path.
+ * @param[in] uid Target uid
+ *
+ * @return 0 if success, negative value(<0) if fail
+ * @see None
+ * @remarks This API is only for Appfw internally.
+ *
+ * @par Sample code:
+ * @code
+#include <aul.h>
+
+...
+{
+ int r;
+ bundle *b = bundle_create();
+ if (pkg_name)
+ bundle_add_str(b, AUL_K_RUA_PKGNAME, pkg_name);
+ else if (app_path)
+ bundle_add_str(b, AUL_K_RUA_APPPATH, app_path);
+
+ r = aul_add_rua_history_for_uid(b);
+}
+
+ * @endcode
+ **/
+int aul_add_rua_history_for_uid(bundle *b, uid_t uid);
+
+/**
+ * @par Description:
+ * This function delete rua history.
+ *
+ * @param[in] b Bundle object Target Package name. If NULL or has no value, delete all rua history.
+ * @param[in] uid Target uid
+ *
+ * @return 0 if success, negative value(<0) if fail
+ * @see None
+ * @remarks This API is only for Appfw internally.
+ *
+ * @par Sample code:
+ * @code
+#include <aul.h>
+
+...
+{
+ int r;
+ bundle *b = NULL;
+ if (pkg_name) {
+ b = bundle_create();
+ bundle_add_str(b, AUL_K_RUA_PKGNAME, pkg_name);
+ }
+ r = aul_delete_rua_history_for_uid(b, getuid());
+}
+
+ * @endcode
+ **/
+int aul_delete_rua_history_for_uid(bundle *b, uid_t uid);
+
+
+/**
+ * @par Description:
+ * This function sets the default application(application id) associated with operatioin, uri and mime-type.
+ *
+ * @param[in] b Bundle object Target application id and operation, uri and mime-type.
+ *
+ * @return 0 if success, negative value(<0) if fail
+ * @see None
+ * @remarks This API is only for Appfw internally.
+ *
+ * @par Sample code:
+ * @code
+#include <aul.h>
+#include <aul_svc.h>
+
+...
+{
+ int r;
+ bundle *b = bundle_create();
+
+ const char *appid = "org.tizen.test";
+ const char *operation = "test_operation";
+ const char *mime_type = "test_mime";
+ const char *uri = "test_uri";
+
+ aul_svc_set_operation(b, operation);
+ aul_svc_set_mime(b, mime_type);
+ aul_svc_set_uri(b, uri);
+
+ aul_svc_set_appid(b, appid)
+
+ r = aul_set_default_app_by_operation(b);
+}
+
+ * @endcode
+ **/
+int aul_set_default_app_by_operation(bundle *b);
+
+/**
+ * @par Description:
+ * This API unset the default application(application id) associated with operation, uri and mime-type.
+ *
+ * @param[in] app_id The ID of the application
+ *
+ * @return 0 if success, negative value(<0) if fail
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul.h>
+
+...
+{
+ aul_unset_default_app_by_operation("org.tizen.test");
+}
+ * @endcode
+ *
+ */
+int aul_unset_default_app_by_operation(const char *app_id);
+
+/**
+ * @par Description:
+ * Sends the launch request asynchronously.
+ *
+ * @param[in] appid The application ID
+ * @param[in] kb The Bundle data
+ * @return a pid of the callee on success,
+ * otherwise a negative error value
+ * @retval AUL_R_OK - Successful
+ * @retval AUL_R_EINVAL - Invalid parameter
+ * @retval AUL_R_ECOM - Internal AUL IPC error
+ * @retval AUL_R_ERROR - General error
+ *
+ * @remark
+ * This API is only available in User Session.
+ * This API doesn't check whether the callee application is executed successfully.
+ * If the caller application is equal to the callee application, this API can return AUL_R_OK.
+ */
+int aul_launch_app_async(const char *appid, bundle *kb);
+
+/**
+ * @par Description:
+ * Sends the launch request asynchronously.
+ *
+ * @param[in] appid The application ID
+ * @param[in] kb The Bundle data
+ * @param[in] uid User ID
+ * @return a pid of the callee on success,
+ * otherwise a negative error value
+ * @retval AUL_R_OK - Successful
+ * @retval AUL_R_EINVAL - Invalid parameter
+ * @retval AUL_R_ECOM - Internal AUL IPC error
+ * @retval AUL_R_ERROR - General error
+ *
+ * @remark
+ * This API is only available to System user.
+ * This API doesn't check whether the callee application is executed successfully.
+ * If the caller application is equal to the callee application, this API can return AUL_R_OK.
+ */
+int aul_launch_app_async_for_uid(const char *appid, bundle *kb, uid_t uid);
+
+/**
+ * @par Description:
+ * This API request launchpad to make candidate processes.
+ *
+ * @return 0 if success, negative value(<0) if fail
+ *
+ * @remark
+ * This API is only available in User Session.
+ */
+int aul_prepare_candidate_process(void);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_widget_instance_add(const char *widget_id, const char *instance_id);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_widget_instance_del(const char *widget_id, const char *instance_id);
+
+/*
+ * This API is only for Appfw internally.
+ */
+typedef void (*aul_widget_instance_foreach_cb)(const char *instance_id, void *data);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_widget_instance_foreach(const char *widget_id, aul_widget_instance_foreach_cb cb, void *data);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_widget_instance_update(const char *widget_id, const char *instance_id, bundle *b);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_widget_instance_count(const char *widget_id);
+
+/**
+ * @par Description:
+ * This API gets the last caller process id of specified application process id.
+ * @par Purpose:
+ * This API's purpose is to get the application's last caller process id.
+ *
+ * @param[in] pid pid of application
+ * @return caller pid if success, nagative value if fail
+ *
+ * @remark
+ * This API is only available in User Session.
+ */
+int aul_app_get_last_caller_pid(int pid);
+
+/**
+ * @par Description:
+ * This API gets the last caller process id of specified application process id.
+ * @par Purpose:
+ * This API's purpose is to get the last caller process id of the application.
+ *
+ * @param[in] pid pid of application
+ * @param[in] uid User ID
+ * @return caller pid if success, nagative value if fail
+ *
+ * @remark
+ * This API is only available in System users.
+ */
+int aul_app_get_last_caller_pid_for_uid(int pid, uid_t uid);
+
+/**
+ * @par Description:
+ * This API trigger to resume application asynchronously.
+ * If the application is running, this API send a resume event to the App.
+ * If the application is not running, this API return AUL_R_ERROR.
+ * Although the application is running, if the application cannot receive resume event,
+ * AUL try to raise the application's default windows.
+ * @par Purpose:
+ * This API is for caller.
+ * This API's purpose is to send resume event.
+ * @par Typical use case:
+ * In multiple application model, If you want to only resume specific application, Use this API
+ *
+ * @param[in] pid application's pid to be resumed
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_EINVAL - invaild pid
+ * @retval AUL_R_ECOM - internal AUL IPC error
+ * @retval AUL_R_ERROR - general error (include application is not running)
+ * @warning This API need to require root or inhouse permisssion \n
+ * If you have not the permission, this API return AUL_R_ERROR. \n
+ * @remark
+ * This API is only available to User Session.
+ */
+int aul_resume_pid_async(int pid);
+
+/**
+ * @par Description:
+ * This API trigger to resume application asynchronously.
+ * If the application is running, this API send a resume event to the App.
+ * If the application is not running, this API return AUL_R_ERROR.
+ * Although the application is running, if the application cannot receive resume event,
+ * AUL try to raise the application's default windows.
+ * @par Purpose:
+ * This API is for caller.
+ * This API's purpose is to send resume event.
+ * @par Typical use case:
+ * In multiple application model, If you want to only resume specific application, Use this API
+ *
+ * @param[in] pid application's pid to be resumed
+ * @param[in] uid User ID
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_EINVAL - invaild pid
+ * @retval AUL_R_ECOM - internal AUL IPC error
+ * @retval AUL_R_ERROR - general error (include application is not running)
+ * @warning This API need to require root or inhouse permisssion \n
+ * If you have not the permission, this API return AUL_R_ERROR. \n
+ * @remark
+ * This API is only available to System user.
+ */
+int aul_resume_pid_async_for_uid(int pid, uid_t uid);
+
+/**
+ * @par Description:
+ * This API set the alias appid.
+ * The alias appid is only available for the aul_svc_set_appid() API.
+ * If the appid is not available, this API returns an error.
+ *
+ * @privlevel platform
+ * @privilege %http://tizen.org/privilege/systemsettings.admin
+ * @param[in] alias_appid an alias application ID
+ * @param[in] appid an application ID
+ * @return 0 if success, negative value(<0) if fail
+ *
+ * @remark
+ * This API is only available to User Session.
+ */
+int aul_set_alias_appid(const char *alias_appid, const char *appid);
+
+/**
+ * @par Description:
+ * This API unset the alias appid.
+ *
+ * @privlevel platform
+ * @privilege %http://tizen.org/privilege/systemsettings.admin
+ * @param[in] alias_appid an alias application ID
+ * @return 0 if success, negative value(<0) if fail
+ *
+ * @remark
+ * This API is only available to User Session.
+ */
+int aul_unset_alias_appid(const char *alias_appid);
+
+/**
+ * @par Description:
+ * This API activates the alias information based on the given appid.
+ *
+ * @privlevel platform
+ * @privilege %http://tizen.org/privilege/systemsettings.admin
+ * @param[in] appid an application ID
+ * @return 0 if success, negative value(<0) if fail
+ *
+ * @remark
+ * This API is only available to User Session.
+ */
+int aul_enable_alias_info(const char *appid);
+
+/**
+ * @par Description:
+ * This API deactivates the alias information based on the given appid.
+ *
+ * @privlebel platform
+ * @privilege %http://tizen.org/privilege/systemsettings.admin
+ * @param[in] appid an application ID
+ * @return 0 if success, negative value(<0) if fail
+ *
+ * @remark
+ * This API is only available to User Session.
+ */
+int aul_disable_alias_info(const char *appid);
+
+/**
+ * This API is only for Appfw internally.
+ */
+typedef int (*app_status_cb)(aul_app_info *info, int ctx_status, void *data);
+
+/**
+ * This API is only for Appfw internally.
+ */
+typedef struct status_listen_s *status_listen_h;
+
+/**
+ * @par Description:
+ * Registers a callback function to be invoked when the application change status.
+ *
+ * @param[in] appid The application ID to get status
+ * @param[in] callback The callback function to register
+ * @param[in] data The user data to be passed to the callback function
+ * @param[out] handle The status listen handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ */
+int aul_listen_app_status(const char *appid, app_status_cb callback,
+ void *data, status_listen_h *handle);
+int aul_listen_app_status_for_uid(const char *appid, app_status_cb callback,
+ void *data, status_listen_h *handle, uid_t uid);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_widget_instance_get_content(const char *widget_id, const char *instance_id, char **content);
+
+/**
+ * @par Description:
+ * Gets running application instance info
+ * This API calls the iter_fn with the aul_app_info when running app instance info is found.
+ *
+ * @param[in] iter_fn iterative function
+ * @param[in] user_data User data
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_R_OK Successful
+ * @retval AUL_R_ERROR General error
+ * @retval AUL_R_EINVAL Invalid parameter
+ */
+int aul_app_get_running_app_instance_info(aul_app_info_iter_fn iter_fn,
+ void *user_data);
+int aul_app_get_running_app_instance_info_for_uid(aul_app_info_iter_fn iter_fn,
+ void *user_data, uid_t uid);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_app_get_instance_id_bypid(int pid, char *instance_id, int len);
+int aul_app_get_instance_id_bypid_for_uid(int pid, char *instance_id,
+ int len, uid_t uid);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_resume_app_by_instance_id(const char *appid, const char *instance_id);
+int aul_resume_app_by_instance_id_for_uid(const char *appid,
+ const char *instance_id, uid_t uid);
+
+/**
+ * This API is only for Appfw internally.
+ */
+int aul_ignore_app_status(status_listen_h handle);
+
+/**
+ * This API is only for Appfw internally.
+ */
+int aul_notify_exit(void);
+int aul_notify_start(void);
+
+/**
+ * This API is only for App Framework internally.
+ */
+const char *aul_app_status_convert_to_string(int status);
+
+/**
+ * This API is only for App Framework internally.
+ */
+int aul_terminate_instance_async(const char *instance_id, int pid);
+int aul_terminate_instance_async_for_uid(const char *instance_id, int pid,
+ uid_t uid);
+
+/**
+ * @brief Sends the terminate request.
+ * @since_tizen 5.5
+ * @privlevel platform
+ * @privilege %http://tizen.org/privilege/appmanager.kill
+ *
+ * @param[in] appid The application ID
+ * @param[in] instance_id The instance ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_terminate_app_with_instance_id(const char *appid,
+ const char *instance_id);
+
+/**
+ * @brief Sends the terminate request.
+ * @since_tizen 5.5
+ * @privlevel platform
+ * @privilege %http://tizen.org/privilege/appmanager.kill
+ *
+ * @param[in] appid The application ID
+ * @param[in] instance_id The instance ID
+ * @param[in] uid The user ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_terminate_app_with_instance_id_for_uid(const char *appid,
+ const char *instance_id, uid_t uid);
+
+/**
+ * @brief Sends the terminate request.
+ * @since_tizen 5.5
+ * @privlevel platform
+ * @privilege %http://tizen.org/privilege/appmanager.kill
+ *
+ * @param[in] appid The application ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_terminate_app(const char *appid);
+
+/**
+ * @brief Sends the terminate request.
+ * @since_tizen 5.5
+ * @privlevel platform
+ * @privilege %http://tizen.org/privilege/appmanager.kill
+ *
+ * @param[in] appid The application ID
+ * @param[in] uid The user ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_terminate_app_for_uid(const char *appid, uid_t uid);
+
+/**
+ * @brief Checks whether the application is running or not.
+ * @since_tizen 5.5
+ *
+ * @param[in] appid The application ID
+ * @param[in] instance_id The instance ID
+ * @param[out] running @c true if the instance is running, \n
+ * otherwise @c false if not running
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_app_is_running_with_instance_id(const char *appid,
+ const char *instance_id, bool *running);
+
+/**
+ * @brief Sends a preparation request for an app-defined loader.
+ * @since_tizen 5.5
+ *
+ * @param[in] loader_name The loader name
+ * @return @c the loader ID on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_prepare_app_defined_loader(const char *loader_name);
+int aul_prepare_app_defined_loader_for_uid(const char *loader_name, uid_t uid);
+
+/**
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_status_update_v2(int status);
+
+/**
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_get_default_app(bundle *b, char **appid);
+
+/**
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_set_auto_restart(bundle *b);
+
+/**
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_unset_auto_restart(void);
+
+/**
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_package_pre_event_send(uid_t uid, bundle *b);
+
+/**
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_launch_worker_init(void);
+
+/**
+ * @remarks This function is only for App Framework internally.
+ */
+void aul_launch_worker_fini(void);
+
+/**
+ * @brief Called when the application ID is delivered.
+ * @since_tizen 8.0
+ * @param[in] result The result
+ * @param[in] pid The process ID
+ * @param[in] appid The application ID
+ * @param[in] user_data The user data passed from the regitration function
+ * @remarks This function is only for App Framework internally.
+ * @see aul_app_get_appid_bypid_async()
+ */
+typedef void (*aul_appid_cb)(int result, pid_t pid, const char *appid, void *user_data);
+
+/**
+ * @brief Gets the application ID from the process ID.
+ * @since_tizen 8.0
+ * @param[in] pid The process ID
+ * @param[in] callback The callback function
+ * @param[in] user_data The user data to be passed to the callaback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_R_OK Successful
+ * @retval #AUL_R_EINVAL Invalid parameter
+ * @retval #AUL_R_ENOMEM Out of memory
+ * @retval #AUL_R_ERROR Internal I/O error
+ * @remarks This function is only for App Framework internally.
+ * @see aul_appid_cb()
+ */
+int aul_app_get_appid_bypid_async(pid_t pid, aul_appid_cb callback, void *user_data);
+
+/**
+ * @brief Called when the result is delivered.
+ * @since_tizen 8.0
+ * @param[in] result The result
+ * @param[in] user_data The user data passed from the regitration function
+ * @remarks This function is only for App Framework internally.
+ */
+typedef void (*aul_result_cb)(int result, void *user_data);
+
+/**
+ * @brief Sends the termination request with the process ID.
+ * @since_tizen 8.0
+ * @privilege %http://tizen.org/privilege/appmanager.kill
+ * @privlevel platform
+ * @param[in] pid The process ID
+ * @param[in] callback The callback function
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_R_OK Successful
+ * @retval #AUL_R_EINVAL Invalid parameter
+ * @retval #AUL_R_ENOMEM Out of memory
+ * @retval #AUL_R_ERROR Internal I/O error
+ * @remarks This function is only for App Framework internally.
+ * @see aul_result_cb()
+ */
+int aul_terminate_pid_async_v2(pid_t pid, aul_result_cb callback, void *user_data);
+
+/**
+ * @brief Sends the termination request.
+ * @since_tizen 8.0
+ * @privilege %http://tizen.org/privilege/appmanager.kill
+ * @privlevel platform
+ * @param[in] appid The application ID
+ * @param[in] callback The callback function
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_R_OK Successful
+ * @retval #AUL_R_EINVAL Invalid parameter
+ * @retval #AUL_R_ENOMEM Out of memory
+ * @retval #AUL_R_ERROR Internal I/O error
+ * @remarks This function is only for App Framework internally.
+ * @see aul_result_cb()
+ */
+int aul_terminate_app_async(const char *appid, aul_result_cb callback, void *user_data);
+
+/**
+ * @brief Sends the request to kill the process ID.
+ * @since_tizen 8.0
+ * @privilege %http://tizen.org/privilege/appmanager.kill
+ * @privlevel platform
+ * @param[in] pid The process ID
+ * @param[in] callback The callback function
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_R_OK Successful
+ * @retval #AUL_R_EINVAL Invalid parameter
+ * @retval #AUL_R_ENOMEM Out of memory
+ * @retval #AUL_R_ERROR Internal I/O error
+ * @remarks This function is only for App Framework internally.
+ * @see aul_result_cb()
+ */
+int aul_kill_pid_async(pid_t pid, aul_result_cb callback, void *user_data);
+
+/**
+ * @Brief Called when the reply is delivered from the callee application.
+ * @since_tizen 8.0
+ * @param[in] b The bundle object
+ * @param[in] is_cancel If true, the request was cancelled
+ * @param[in] user_data The user data passed from the registration function
+ * @remarks This function is only for App Framework internally.
+ * @see aul_send_launch_request_for_uid()
+ */
+typedef void (*aul_reply_cb)(bundle *b, int is_cancel, void *user_data);
+
+/**
+ * @brief Sends the launch request asynchronously.
+ * @since_tizen 8.0
+ * @privilege %http://tizen.org/privilege/appmanager.launch
+ * @privlevel public
+ * @param[in] appid The application ID
+ * @param[in] b The bundle object
+ * @param[in] uid The target user ID
+ * @param[in] reply_cb The reply callback function
+ * @param[in] result_cb The result callback function
+ * @param[in] user_data The user data to be passed to the callback function
+ * @retrun @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_R_OK Successful
+ * @retval #AUL_R_EINVAL Invalid parameter
+ * @retval #AUL_R_ENOMEM Out of memory
+ * @retval #AUL_R_ERROR Internal I/O error
+ * @retval #AUL_R_ECOMM Communication error on send
+ * @retval #AUL_R_EILLACC Permission denied
+ * @remarks This function is only for App Framework internally.
+ * @see aul_reply_cb()
+ */
+int aul_send_launch_request_for_uid(const char *appid, bundle *b, uid_t uid,
+ aul_reply_cb reply_cb, aul_result_cb result_cb, void *user_data);
+
+/**
+ * @brief Sends the kill request to the running loader process.
+ * @since_tizen 8.0
+ * @remarks This function is only available for system and user daemons.
+ * @param[in] loader_name The loader name
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_R_OK Successful
+ * @retval #AUL_R_EINVAL Invalid parameter
+ * @retval #AUL_R_ECOMM Communication error on send
+ * @retval #AUL_R_EILLACC Permission denied
+ */
+int aul_kill_loader(const char *loader_name);
+
+/**
+ * @brief Sends the kill request to the running loader process.
+ * @since_tizen 8.0
+ * @remarks This function is only available for system and user daemons.
+ * @param[in] loader_name The loader name
+ * @param[in] uid The target uid
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_R_OK Successful
+ * @retval #AUL_R_EINVAL Invalid parameter
+ * @retval #AUL_R_ECOMM Communication error on send
+ * @retval #AUL_R_EILLACC Permission denied
+ */
+int aul_kill_loader_for_uid(const char *loader_name, uid_t uid);
+
+/**
+ * @brief Sends the restart request to the running loader process.
+ * @since_tizen 8.0
+ * @details This function is to restart the loader process.
+ * If the process is running, it will be terminated and executed.
+ * @remarks This function is only available for system and user daemons.
+ * @param[in] loader_name The loader name
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_R_OK Successful
+ * @retval #AUL_R_EINVAL Invalid parameter
+ * @retval #AUL_R_ECOMM Communication error on send
+ * @retval #AUL_R_EILLACC Permission denied
+ */
+int aul_restart_loader(const char *loader_name);
+
+/**
+ * @brief Sends the restart request to the running loader process.
+ * @since_tizen 8.0
+ * @details This function is to restart the loader process.
+ * If the process is running, it will be terminated and executed.
+ * @remarks This function is only available for system and user daemons.
+ * @param[in] loader_name The loader name
+ * @param[in] uid The target uid
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_R_OK Successful
+ * @retval #AUL_R_EINVAL Invalid parameter
+ * @retval #AUL_R_ECOMM Communication error on send
+ * @retval #AUL_R_EILLACC Permission denied
+ */
+int aul_restart_loader_for_uid(const char *loader_name, uid_t uid);
+
+#ifdef __cplusplus
+ }
+#endif
--- /dev/null
+/*
+ * Copyright (c) 2015 - 2021 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __APP_COM_H__
+#define __APP_COM_H__
+
+#include <bundle.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum {
+ AUL_APP_COM_PUBLIC = 0x0, /* allowed for all */
+ AUL_APP_COM_PRIVILEGED = 0x1, /* allowed for given privileged app */
+} aul_app_com_propagate_option_e;
+
+typedef enum {
+ AUL_APP_COM_R_ERROR_OK = 0,
+ AUL_APP_COM_R_ERROR_UNKNOWN_ENDPOINT = -1,
+ AUL_APP_COM_R_ERROR_ENDPOINT_ALREADY_EXISTS = -2,
+ AUL_APP_COM_R_ERROR_ILLEGAL_ACCESS = -3,
+ AUL_APP_COM_R_ERROR_CLIENT_REMAINING = -4,
+ AUL_APP_COM_R_ERROR_OUT_OF_MEMORY = -5,
+ AUL_APP_COM_R_ERROR_FATAL_ERROR = -6,
+} aul_app_com_error_e;
+
+typedef enum {
+ AUL_APP_COM_R_OK = 0,
+ AUL_APP_COM_R_ILLEGAL_ACCESS = -1,
+} aul_app_com_result_e;
+
+typedef void *aul_app_com_permission_h;
+typedef void *aul_app_com_connection_h;
+
+typedef int (*app_com_cb)(const char *endpoint, aul_app_com_result_e result, bundle *envelope, void *user_data);
+
+/**
+ * aul_app_com provides publish-subscribe style message for internal AUL use.
+ * e.g) widget status propagation, sharing callee app status to caller app
+ * @code
+
+static int __handler(const char *endpoint, aul_app_com_result_e result, bundle *envelope, void *user_data)
+{
+ _D("endpoint: %s", endpoint);
+ _D("result: %d", result);
+
+ return 0;
+}
+
+// viewer-side
+aul_app_com_permission_h permission = aul_app_com_permission_create();
+aul_app_com_permission_set_propagation(permission, AUL_APP_COM_PRIVILEGED);
+aul_app_com_permission_set_privilege(permission, "http://tizen.org/privilege/widget.viewer");
+aul_app_com_connection_h connection = NULL;
+aul_app_com_create("widget.status", permission, __handler, NULL, &connection);
+
+
+// widget-side
+bundle *b = bundle_create();
+bundle_add_str(b, "WIDGET_ID", "org.example.widget");
+bundle_add_str(b, "STATUS", "RUNNING");
+aul_app_com_send("widget.status", b);
+bundle_free(b);
+
+
+// monitor-side
+static int __handler(const char *endpoint, aul_app_com_result_e result, bundle *envelope, void *user_data)
+{
+ const char *widget_id = bundle_get_val(envelope, "WIDGET_ID");
+ const char *status = bundle_get_val(envelope, "STATUS");
+
+ _D("%s is %s", widget_id, status);
+
+ return 0;
+}
+
+aul_app_com_connection_h connection = NULL;
+aul_app_com_join("widget.status", NULL, __handler, NULL, &connection);
+
+ */
+
+aul_app_com_permission_h aul_app_com_permission_create();
+void aul_app_com_permission_destroy(aul_app_com_permission_h permission);
+int aul_app_com_permission_set_propagation(aul_app_com_permission_h permission, aul_app_com_propagate_option_e option);
+int aul_app_com_permission_set_privilege(aul_app_com_permission_h permission, const char *privilege);
+
+int aul_app_com_create(const char *endpoint, aul_app_com_permission_h permission, app_com_cb callback, void *user_data, aul_app_com_connection_h *connection);
+int aul_app_com_join(const char *endpoint, const char *filter, app_com_cb callback, void *user_data, aul_app_com_connection_h *connection);
+int aul_app_com_leave(aul_app_com_connection_h connection);
+int aul_app_com_send(const char *endpoint, bundle *envelope);
+
+int aul_app_com_create_async(const char *endpoint,
+ aul_app_com_permission_h permission,
+ app_com_cb callback,
+ void *user_data,
+ aul_app_com_connection_h *connection);
+
+#ifdef __cplusplus
+}
+#endif
+
+#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_APP_GROUP_H__
+#define __AUL_APP_GROUP_H__
+
+#include <stdbool.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief The AUL application group information handle.
+ * @since_tizen 5.5
+ */
+typedef struct aul_app_group_info_s *aul_app_group_info_h;
+
+typedef void (*aul_app_group_leader_id_cb)(const char *leader_id, void* user_data);
+
+typedef void (*aul_app_group_info_cb)(aul_app_group_info_h info, void *user_data);
+
+/**
+ * @brief Gets the ID.
+ * @since_tizen 5.5
+ * @remarks You should not release @a appid by using free().
+ *
+ * @param[in] h The app group info handle
+ * @param[out] id The ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_app_group_info_get_id(aul_app_group_info_h h, const char **id);
+
+/**
+ * @brief Gets the process ID.
+ * @since_tizen 5.5
+ *
+ * @param[in] h The app group info handle
+ * @param[out] pid The process ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_app_group_info_get_pid(aul_app_group_info_h h, pid_t *pid);
+
+/**
+ * @brief Gets the application ID.
+ * @since_tizen 5.5
+ * @remarks You should not release @a appid by using free().
+ *
+ * @param[in] h The app group info handle
+ * @param[out] appid The application ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_app_group_info_get_appid(aul_app_group_info_h h, const char **appid);
+
+/**
+ * @brief Gets the package ID.
+ * @since_tizen 5.5
+ * @remarks You should not release @a appid by using free().
+ *
+ * @param[in] h The app group info handle
+ * @param[out] pkgid The package ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_app_group_info_get_pkgid(aul_app_group_info_h h, const char **pkgid);
+
+/**
+ * @brief Gets the window ID.
+ * @since_tizen 5.5
+ *
+ * @param[in] h The app group info handle
+ * @param[out] wid The window ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_app_group_info_get_window(aul_app_group_info_h h, int *wid);
+
+/**
+ * @brief Gets the flag that the group is running foreground.
+ * @since_tizen 5.5
+ *
+ * @param[in] h The app group info handle
+ * @param[out] fg_flag The flag of the foreground
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_app_group_info_get_fg_flag(aul_app_group_info_h h, bool *fg_flag);
+
+/**
+ * @brief Gets the status of the instance.
+ * @since_tizen 5.5
+ *
+ * @param[in] h The app group info handle
+ * @param[out] status The status
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_app_group_info_get_status(aul_app_group_info_h h, int *status);
+
+/**
+ * @brief Retrieves the leader instances.
+ * @since_tizen 5.5
+ *
+ * @param[in] callback The callback function
+ * @param[in] user_data The user data to be passed the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_app_group_foreach_leader_ids(aul_app_group_leader_id_cb callback,
+ void *user_data);
+
+/**
+ * @brief Retrieves the group instances.
+ * @since_tizen 5.5
+ *
+ * @param[in] leader_id The leader ID of the app group.
+ * @param[in] callback The callback function
+ * @param[in] user_data The user data to be passed the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_app_group_foreach_group_info(const char *leader_id,
+ aul_app_group_info_cb callback, void *user_data);
+
+/**
+ * @brief Retrieves the idle instances.
+ * @since_tizen 5.5
+ *
+ * @param[in] callback The callback function
+ * @param[in] user_data The user data to be passed the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_app_group_foreach_idle_info(aul_app_group_info_cb callback,
+ void *user_data);
+
+/**
+ * @brief Sets the window.
+ * @since_tizen 5.5
+ *
+ * @param[in] id The instance ID
+ * @param[in] wid The window(surface) ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_app_group_set_window_v2(const char *id, int wid);
+
+/**
+ * @brief Lowers the window.
+ * @since_tizen 5.5
+ *
+ * @param[in] id The instance ID
+ * @param[out] exit The flag if it's 'true', the instance should be terminated
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_app_group_lower_v2(const char *id, bool *exit);
+
+/**
+ * @brief Adds a new app group to the app group.
+ * @details A new app group will be added using the given window ID.
+ * @since_tizen 6.0
+ *
+ * @param[in] wid The window(surface) ID
+ * @return @c 0 on success,
+ * otherwise a negatvie error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_app_group_add(int wid);
+
+/**
+ * @brief Removes the app group using the given window ID.
+ * @since_tizen 6.0
+ *
+ * @param[in] wid The window(surface) ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_app_group_remove(int wid);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __AUL_APP_GROUP_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#pragma once
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+enum app_cmd {
+ APP_START = 0,
+
+ APP_OPEN = 1,
+ APP_RESUME = 2,
+ APP_RESUME_BY_PID = 3,
+ APP_TERM_BY_PID = 4,
+ APP_TERM_BY_PID_WITHOUT_RESTART = 5,
+ APP_RESULT = 6,
+ APP_START_RES = 7,
+ APP_CANCEL = 8,
+ APP_KILL_BY_PID = 9,
+ APP_UPDATE_RUA_STAT = 10,
+
+ APP_ADD_HISTORY = 11,
+ APP_REMOVE_HISTORY = 12,
+ APP_RUNNING_INFO = 13,
+ APP_RUNNING_INFO_RESULT = 14,
+ APP_IS_RUNNING = 15,
+ APP_GET_APPID_BYPID = 16,
+ APP_GET_PKGID_BYPID = 17,
+ APP_GET_INFO_OK = 18,
+ APP_GET_INFO_ERROR = 19,
+ APP_KEY_EVENT = 20, /**< Unused */
+
+ APP_KEY_RESERVE = 21, /**< Unused */
+ APP_KEY_RELEASE = 22, /**< Unused */
+ APP_STATUS_UPDATE = 23,
+ APP_RUNNING_LIST_UPDATE = 24,
+ APP_TERM_REQ_BY_PID = 25,
+ APP_TERM_BY_PID_ASYNC = 26,
+ APP_TERM_BGAPP_BY_PID = 27,
+ APP_PAUSE = 28,
+ APP_PAUSE_BY_PID = 29,
+ APP_GROUP_GET_WINDOW = 30,
+
+ APP_GROUP_SET_WINDOW = 31,
+ APP_GROUP_GET_FG = 32,
+ APP_GROUP_GET_LEADER_PID = 33,
+ APP_GROUP_GET_LEADER_PIDS = 34,
+ APP_GROUP_GET_GROUP_PIDS = 35,
+ APP_GROUP_GET_IDLE_PIDS = 36,
+ APP_GROUP_LOWER = 37,
+ APP_GROUP_CLEAR_TOP = 38,
+ APP_GROUP_ACTIVATE_BELOW = 39,
+ APP_GET_STATUS = 40,
+
+ APP_ADD_LOADER = 41,
+ APP_REMOVE_LOADER = 42,
+ APP_GET_PID = 43,
+ APP_GET_DC_SOCKET_PAIR = 44,
+ APP_GET_MP_SOCKET_PAIR = 45,
+ APP_COM_CREATE = 46,
+ APP_COM_JOIN = 47,
+ APP_COM_SEND = 48,
+ APP_COM_LEAVE = 49,
+ APP_COM_MESSAGE = 50,
+
+ WIDGET_ADD = 51,
+ WIDGET_DEL = 52,
+ WIDGET_LIST = 53,
+ WIDGET_UPDATE = 54,
+ WIDGET_COUNT = 55,
+ WIDGET_GET_CONTENT = 56,
+ APP_REGISTER_PID = 57,
+ APP_WAKE = 58,
+ APP_SUSPEND = 59,
+ AMD_RELOAD_APPINFO = 60,
+
+ LAUNCHPAD_DEAD_SIGNAL = 61,
+ APP_ALL_RUNNING_INFO = 62,
+ APP_SET_APP_CONTROL_DEFAULT_APP = 63,
+ APP_UNSET_APP_CONTROL_DEFAULT_APP = 64,
+ APP_START_ASYNC = 65,
+ APP_SET_PROCESS_GROUP = 66,
+ APP_PREPARE_CANDIDATE_PROCESS = 67,
+ APP_TERM_BY_PID_SYNC = 68,
+ APP_GET_STATUS_BY_APPID = 69,
+ APP_GET_LAST_CALLER_PID = 70,
+
+ APP_TERM_BY_PID_SYNC_WITHOUT_RESTART = 71,
+ APP_RESUME_BY_PID_ASYNC = 72,
+ APP_SET_ALIAS_APPID = 73,
+ APP_UNSET_ALIAS_APPID = 74,
+ APP_ENABLE_ALIAS_INFO = 75,
+ APP_DISABLE_ALIAS_INFO = 76,
+ APP_GROUP_ACTIVATE_ABOVE = 77,
+ ADD_APP_SCREEN = 78,
+ REMOVE_APP_SCREEN = 79,
+ APP_UPDATE_REQUESTED = 80,
+
+ ADD_SCREEN_VIEWER = 81,
+ REMOVE_SCREEN_VIEWER = 82,
+ LAUNCHPAD_LAUNCH_SIGNAL = 83,
+ APP_RUNNING_INSTANCE_INFO = 84,
+ APP_GET_INSTANCE_ID_BYPID = 85,
+ APP_SET_CACHE = 86,
+ APP_GET_APPID_FROM_CACHE = 87,
+ APP_INVALIDATE_CACHE = 88,
+ APP_STARTUP_SIGNAL = 89,
+ APP_WINDOW_ATTACH = 90,
+
+ APP_WINDOW_DETACH = 91,
+ APP_START_RES_ASYNC = 92,
+ APP_NOTIFY_EXIT = 93,
+ APP_GET_APPID_BY_SURFACE_ID = 94,
+ APP_GET_INSTANCE_ID_BY_SURFACE_ID = 95,
+ UPDATE_SCREEN_VIEWER_STATUS = 96,
+ WIDGET_RUNNING_INFO = 97,
+ JOB_STATUS_UPDATE = 98,
+ WIDGET_CHANGE_STATUS = 99,
+ RPC_PORT_PREPARE_STUB = 100,
+
+ RPC_PORT_CREATE_SOCKET_PAIR = 101,
+ RPC_PORT_NOTIFY_RPC_FINISHED = 102,
+ COMPLICATION_UPDATE_REQUEST = 103,
+ APP_NOTIFY_START = 104,
+ WATCHDOG_ENABLE = 105,
+ WATCHDOG_DISABLE = 106,
+ WATCHDOG_PING = 107,
+ WATCHDOG_KICK = 108,
+ APP_SEND_LAUNCH_REQUEST = 109,
+ APP_SEND_LAUNCH_REQUEST_SYNC = 110,
+
+ COMP_NOTIFY_START = 111,
+ COMP_NOTIFY_EXIT = 112,
+ COMP_STATUS_UPDATE = 113,
+ APP_TERM_INSTANCE_ASYNC = 114,
+ APP_GROUP_SET_WINDOW_V2 = 115,
+ APP_GROUP_LOWER_V2 = 116,
+ APP_GROUP_GET_LEADER_IDS = 117,
+ APP_GROUP_GET_GROUP_INFO = 118,
+ APP_GROUP_GET_IDLE_INFO = 119,
+ COMP_CONTEXT_FOREACH = 120,
+
+ COMP_CONTEXT_GET = 121,
+ COMP_CONTEXT_IS_RUNNING = 122,
+ COMP_CONTEXT_RESUME = 123,
+ COMP_CONTEXT_PAUSE = 124,
+ COMP_CONTEXT_TERMINATE_BG_COMP = 125,
+ COMP_CONTEXT_TERMINATE = 126,
+ APP_RESUME_INSTANCE = 127,
+ APP_PAUSE_INSTANCE = 128,
+ APP_TERM_BG_INSTANCE = 129,
+ LAUNCHPAD_CHILD_PROCESS = 130, /* unused */
+
+ COMP_INFO_GET = 131,
+ COMP_INFO_FOREACH = 132,
+ APP_TERMINATE = 133,
+ APP_IS_RUNNING_V2 = 134,
+ ANR_NOTIFY = 135,
+ APP_GET_RUNNING_CONTEXT = 136,
+ LAUNCHER_SERVICE_NOTIFY_ANIMATION_STARTED = 137,
+ LAUNCHER_SERVICE_NOTIFY_ANIMATION_FINISHED = 138,
+ APP_SEND_RESUME_REQUEST = 139,
+ APP_PREPARE_APP_DEFINED_LOADER = 140,
+
+ WIDGET_DISABLE = 141,
+ TRIGGER_APP_SCREEN_FOCUSED_FORCE = 142,
+ WIDGET_EVENT = 143,
+ SET_PRIVATE_SHARING = 144,
+ UNSET_PRIVATE_SHARING = 145,
+ APP_CONTEXT_GET = 146,
+ APP_CONTEXT_GET_BY_INSTANCE_ID = 147,
+ APP_CONTEXT_GET_BY_PID = 148,
+ APP_GROUP_ADD = 149,
+ APP_GROUP_REMOVE = 150,
+
+ APP_GET_APPID_LIST = 151,
+ COMP_PORT_EXIST = 152,
+ COMP_PORT_CREATE = 153,
+ COMP_PORT_DESTROY = 154,
+ APP_LIFECYCLE_UPDATE_STATE = 155,
+
+ APP_STATUS_UPDATE_V2 = 156,
+ APP_GET_APP_CONTROL_DEFAULT_APPS = 157,
+ APP_GET_APPID_BY_ALIAS_APPID = 158,
+ APP_GET_APP_CONTROL_DEFAULT_APP = 159,
+ APP_LIFECYCLE_GET_STATE = 160,
+
+ PROC_REGISTER = 161,
+ PROC_DEREGISTER = 162,
+ PROC_GET_NAME = 163,
+ PROC_GET_EXTRA = 164,
+ RPC_PORT_CREATE = 165,
+
+ RPC_PORT_DESTROY = 166,
+ RPC_PORT_EXIST = 167,
+ APP_WINDOW_ATTACH_BELOW = 168,
+ PROC_GROUP_ADD = 169,
+ PROC_GROUP_REMOVE = 170,
+
+ APP_CONNECT = 171,
+ APP_SET_AUTO_RESTART = 172,
+ BOOT_SEQUENCE_START_APP = 173,
+ BOOT_SEQUENCE_GET_APPINFO_LIST = 174,
+ BOOT_SEQUENCE_RELOAD = 175,
+
+ PKG_PRE_EVENT_SEND = 176,
+ PROC_GROUP_FOREACH = 177,
+ PROC_GROUP_GET = 178,
+
+ APP_CMD_MAX
+};
+
+const char *aul_cmd_convert_to_string(int cmd);
+
+#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.
+ */
+
+#pragma once
+
+#include <unistd.h>
+#include <stdbool.h>
+
+#include <aul.h>
+#include <aul_comp_types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief The component context handle.
+ * @since_tizen 5.5
+ */
+typedef struct aul_comp_context_s *aul_comp_context_h;
+
+/**
+ * @brief Called to get the component context for each component.
+ * @since_tizen 5.5
+ * @remarks You MUST NOT release @a handle using aul_comp_context_destroy().
+ *
+ * @param[in] handle The component context handle
+ * @param[in] user_data The user data passed from the foreach function
+ * @return @c true to continue with the next iteration of the loop, \n
+ * otherwise @ false to break out of the loop
+ * @see aul_comp_context_foreach_comp_context()
+ */
+typedef bool (*aul_comp_context_cb)(aul_comp_context_h handle, void *user_data);
+
+/**
+ * @brief Retrieves all running components context.
+ * @since_tizen 5.5
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/packagemanager.info
+ *
+ * @param[in] callback The callback function to invoke
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @see aul_comp_context_cb()
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_context_foreach_comp_context(aul_comp_context_cb callback,
+ void *user_data);
+
+/**
+ * @brief Gets the application ID of the component.
+ * @since_tizen 5.5
+ * @remarks You MUST NOT release @a app_id using free().
+ *
+ * @param[in] handle The component context handle
+ * @param[out] app_id The application ID of the component
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_context_get_app_id(aul_comp_context_h handle, const char **app_id);
+
+/**
+ * @brief Gets the instance ID of the component.
+ * @since_tizen 5.5
+ * @remarks You MUST NOT release @a app_id using free().
+ *
+ * @param[in] handle The component context handle
+ * @param[out] instance_id The instance ID of the component
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_context_get_instance_id(aul_comp_context_h handle,
+ const char **instance_id);
+
+/**
+ * @brief Gets the ID of the component.
+ * @since_tizen 5.5
+ * @remarks You MUST NOT release @a comp_id using free().
+ *
+ * @param[in] handle The component context handle
+ * @param[out] comp_id The ID of the component
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_context_get_comp_id(aul_comp_context_h handle,
+ const char **comp_id);
+
+/**
+ * @brief Gets the type of the component.
+ * @since_tizen 5.5
+ * @remarks You MUST NOT release @a type using free().
+ *
+ * @param[in] handle The component context handle
+ * @param[out] type The type of the component
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_context_get_type(aul_comp_context_h handle, const char **type);
+
+/**
+ * @brief Gets the process ID of the component.
+ * @since_tizen 5.5
+ *
+ * @param[in] handle The component context handle
+ * @param[out] pid The process ID of the component
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_context_get_pid(aul_comp_context_h handle, pid_t *pid);
+
+/**
+ * @brief Gets the status of the component.
+ * @since_tizen 5.5
+ *
+ * @param[in] handle The component context handle
+ * @param[out] status The status of the component
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @see comp_status_e
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_context_get_status(aul_comp_context_h handle, int *status);
+
+/**
+ * @brief Checks whether the component is sub component of the app group or not.
+ * @since_tizen 5.5
+ *
+ * @param[in] handle The component context handle
+ * @param[out] is_sub_comp @c true if the component is sub component, \n
+ * otherwise @c false
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_context_is_sub_comp(aul_comp_context_h handle, bool *is_sub_comp);
+
+/**
+ * @brief Creates the component context handle.
+ * @since_tizen 5.5
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/packagemanager.info
+ * @remarks You MUST release @c clone using aul_comp_context_destroy().
+ *
+ * @param[in] comp_id The component ID
+ * @param[out] handle The component context handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ * @see aul_comp_context_destroy()
+ */
+int aul_comp_context_create(const char *comp_id, aul_comp_context_h *handle);
+
+/**
+ * @brief Creates the component context handle.
+ * @since_tizen 5.5
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/packagemanager.info
+ * @remarks You MUST release @c clone using aul_comp_context_destroy().
+ *
+ * @param[in] comp_id The component ID
+ * @parma[in] uid The user ID
+ * @param[out] handle The component context handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ * @see aul_comp_context_destroy()
+ */
+int aul_comp_context_usr_create(const char *comp_id, uid_t uid,
+ aul_comp_context_h *handle);
+
+/**
+ * @brief Destroys the component context handle.
+ * @since_tizen 5.5
+ *
+ * @param[in] handle The component context handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_context_destroy(aul_comp_context_h handle);
+
+/**
+ * @brief Clones the component context handle.
+ * @since_tizen 5.5
+ * @remarks You MUST release @c clone using aul_comp_context_destroy().
+ *
+ * @param[in] handle The component context handle
+ * @param[out] clone A newly created component context handle, if sucessfully cloned
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ * @see aul_comp_context_destroy()
+ */
+int aul_comp_context_clone(aul_comp_context_h handle,
+ aul_comp_context_h *clone);
+
+/**
+ * @brief Checks whether the component is running or not.
+ * @since_tizen 5.5
+ *
+ * @param[in] handle The component context handle
+ * @param[out] running @c true if the component is running, \n
+ * otherwise @c false if not running
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_context_is_running(aul_comp_context_h handle, bool *running);
+
+/**
+ * @brief Sends the request for resuming the component.
+ * @since_tizen 5.5
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/appmanager.launch
+ *
+ * @param[in] handle The component context handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_context_resume(aul_comp_context_h handle);
+
+/**
+ * @brief Sends the request for pausing the component.
+ * @since_tizen 5.5
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/appmanager.launch
+ *
+ * @param[in] handle The component context handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_context_pause(aul_comp_context_h handle);
+
+/**
+ * @brief Sends the request for terminating the background component.
+ * @since_tizen 5.5
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/appmanager.kill.bgapp
+ *
+ * @param[in] handle The component context handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_context_terminate_bg_comp(aul_comp_context_h handle);
+
+/**
+ * @brief Sends the request for terminating the running component.
+ * @since_tizen 5.5
+ * @privlevel platform
+ * @privilege %http://tizen.org/privilege/appmanager.kill
+ *
+ * @param[in] handle The component context handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_context_terminate(aul_comp_context_h handle);
+
+#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.
+ */
+
+#pragma once
+
+#include <unistd.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief The component information handle.
+ * @since_tizen 5.5
+ */
+typedef void *aul_comp_info_h;
+
+/**
+ * @brief Called to get the component information once for each installed component.
+ * @since_tizen 5.5
+ *
+ * @param[in] handle The component information handle
+ * @param[in] user_data The user data passed from the foreach function
+ * @return @c true to continue with the next iteration of the loop, \n
+ * otherwise @ false to break out of the loop
+ * @see aul_comp_info_foreach_comp_info()
+ * @see aul_comp_info_usr_foreach_comp_info()
+ */
+typedef bool (*aul_comp_info_cb)(aul_comp_info_h handle, void *user_data);
+
+/**
+ * @brief Creates the component information handle.
+ * @since_tizen 5.5
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/packagemanager.info
+ * @remarks You MUST release @a handle using aul_comp_info_destroy().
+ *
+ * @param[in] comp_id The component ID
+ * @param[out] handle The component information handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_info_create(const char *comp_id, aul_comp_info_h *handle);
+
+/**
+ * @brief Creates the component information handle.
+ * @since_tizen 5.5
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/packagemanager.info
+ * @remarks You MUST release @a handle using aul_comp_info_destroy().
+ *
+ * @param[in] comp_id The component ID
+ * @param[in] uid The user ID
+ * @param[out] handle The component information handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_info_usr_create(const char *comp_id, uid_t uid,
+ aul_comp_info_h *handle);
+
+/**
+ * @brief Destroys the component information handle.
+ * @since_tizen 5.5
+ *
+ * @param[in] handle The component information handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_info_destroy(aul_comp_info_h handle);
+
+/**
+ * @brief Clones the component information handle.
+ * @since_tizen 5.5
+ * @remarks You MUST release @a clone using aul_comp_info_destroy().
+ *
+ * @param[in] handle The component information handle
+ * @param[out] clone A newly created component information handle, if successfully cloned
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_info_clone(aul_comp_info_h handle, aul_comp_info_h *clone);
+
+/**
+ * @brief Gets the application ID of the component.
+ * @since_tizen 5.5
+ * @remarks You MUST NOT release @a app_id using free().
+ *
+ * @param[in] handle The component information handle
+ * @param[out] app_id The application ID of the component
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_info_get_app_id(aul_comp_info_h handle, const char **app_id);
+
+/**
+ * @brief Gets the ID of the component.
+ * @since_tizen 5.5
+ * @remarks You MUST NOT release @a comp_id using free().
+ *
+ * @param[in] handle The component information handle
+ * @param[out] comp_id The ID of the component
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_info_get_comp_id(aul_comp_info_h handle, const char **comp_id);
+
+/**
+ * @brief Gets the type of the component.
+ * @since_tizen 5.5
+ * @remarks You MUST NOT release @a type using free().
+ *
+ * @param[in] handle The component information handle
+ * @param[out] type The type of the component
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_info_get_type(aul_comp_info_h handle, const char **type);
+
+/**
+ * @brief Gets the launch mode of the component.
+ * @since_tizen 5.5
+ * @remarks You MUST NOT release @a launch_mode using free().
+ *
+ * @param[in] handle The component information handle
+ * @param[out] launch_mode The launch mode of the component
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_info_get_launch_mode(aul_comp_info_h handle,
+ const char **launch_mode);
+
+/**
+ * @brief Checks whether the component is the main component or not.
+ * @since_tizen 5.5
+ *
+ * @param[in] handle The component information handle
+ * @param[out] main_comp @c true if the component is the main component, \n
+ * otherwise @c false
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_info_is_main_comp(aul_comp_info_h handle, bool *main_comp);
+
+/**
+ * @brief Checks whether the icon of the component should be displayed or not.
+ * @since_tizen 5.5
+ *
+ * @param[in] handle The component information handle
+ * @param[out] icon_display @c true if the icon should be displayed, \n
+ * otherwise @c false
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_info_is_icon_display(aul_comp_info_h handle, bool *icon_display);
+
+/**
+ * @brief Checks whether the component should be managed by task-manager or not.
+ * @since_tizen 5.5
+ *
+ * @param[in] handle The component information handle
+ * @param[out] taskmanage @c true if the component should be managed by task-manager, \n
+ * otherwise @c false
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_info_is_taskmanage(aul_comp_info_h handle, bool *taskmanage);
+
+/**
+ * @brief Gets the icon path of the component.
+ * @since_tizen 5.5
+ * @remarks You MUST NOT release @a icon using free().
+ *
+ * @param[in] handle The component information handle
+ * @param[out] icon The icon path of the component
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_info_get_icon(aul_comp_info_h handle, const char **icon);
+
+/**
+ * @brief Gets the label of the component.
+ * @since_tizen 5.5
+ * @remarks You MUST NOT release @a label using free().
+ *
+ * @param[in] handle The component information handle
+ * @param[out] label The label of the component
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_info_get_label(aul_comp_info_h handle, const char **label);
+
+/**
+ * @brief Gets the localed label of the component.
+ * @since_tizen 5.5
+ * @remarks You MUST release @a label using free().
+ *
+ * @param[in] comp_id The component ID
+ * @param[in] locale The locale information
+ * @param[out] label The localed label of the component
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_info_get_localed_label(aul_comp_info_h handle, const char *locale,
+ const char **label);
+
+/**
+ * @brief Retrieves all installed components information of the specified application.
+ * @since_tizen 5.5
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/packagemanager.info
+ *
+ * @param[in] app_id The application ID
+ * @param[in] callback The callback function to invoke
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @see aul_comp_info_cb()
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_info_foreach_comp_info_from_app(const char *app_id,
+ aul_comp_info_cb callback, void *user_data);
+
+/**
+ * @brief Retrieves all installed components information of the specified application.
+ * @since_tizen 5.5
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/packagemanager.info
+ *
+ * @param[in] app_id The application ID
+ * @param[in] uid The user ID
+ * @param[in] callback The callback function to invoke
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @see aul_comp_info_cb()
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_info_usr_foreach_comp_info_from_app(const char *app_id, uid_t uid,
+ aul_comp_info_cb callback, void *user_data);
+
+/**
+ * @brief Retrieves all installed components information.
+ * @since_tizen 5.5
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/packagemanager.info
+ *
+ * @param[in] callback The callback function to invoke
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @see aul_comp_info_cb()
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_info_foreach_comp_info(aul_comp_info_cb callback, void *user_data);
+
+/**
+ * @brief Retrieves all installed components information.
+ * @since_tizen 5.5
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/packagemanager.info
+ *
+ * @param[in] uid The user ID
+ * @param[in] callback The callback function to invoke
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @see aul_comp_info_cb()
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_info_usr_foreach_comp_info(uid_t uid, aul_comp_info_cb callback,
+ void *user_data);
+
+#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.
+ */
+
+#pragma once
+
+#include <aul.h>
+#include <aul_comp_types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Updates a status of a component.
+ * @since_tizen 5.5
+ *
+ * @param[in] instance_id The instance ID
+ * @param[in] status The status
+ *
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_status_update(const char *instance_id, int status);
+
+/**
+ * @brief Notifies that a component is starting.
+ * @since_tizen 5.5
+ *
+ * @param[in] instance_id The instance ID
+ *
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_notify_start(const char *instance_id);
+
+/**
+ * @brief Notifies that a component is exiting.
+ * @since_tizen 5.5
+ *
+ * @param[in] instance_id The instance ID
+ *
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_notify_exit(const char *instance_id);
+
+/**
+ * @brief Sends the resume request.
+ * @since_tizen 5.5
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/appmanager.launch
+ *
+ * @param[in] instance_id The instance ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_resume(const char *instance_id);
+
+/**
+ * @brief Sends the terminate request.
+ * @since_tizen 5.5
+ * @privlevel platform
+ * @privilege %http://tizen.org/privilege/appmanager.kill
+ *
+ * @param[in] instance_id The instance ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_terminate(const char *instance_id);
+
+/**
+ * @brief Checks whether the instance of the component is running or not.
+ * @since_tizen 5.5
+ *
+ * @param[in] instance_id The instance ID
+ * @param[out] running @c true if the instance is running, \n
+ * otherwise @c false if not running
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_is_running(const char *instance_id, bool *running);
+
+#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.
+ */
+
+#pragma once
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Enumeration for component status.
+ * @since_tizen 5.5
+ */
+typedef enum {
+ COMP_STATUS_INITIALIZED, /**< Initialized status */
+ COMP_STATUS_CREATED, /**< Created status */
+ COMP_STATUS_STARTED, /**< Started status */
+ COMP_STATUS_RESUMED, /**< Resumed status */
+ COMP_STATUS_PAUSED, /**< Paused status */
+ COMP_STATUS_DESTROYED, /**< Destroyed status */
+} comp_status_e;
+
+#ifdef __cplusplus
+}
+#endif
--- /dev/null
+/*
+ * Copyright (c) 2018 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_COMPLICATION_H__
+#define __AUL_COMPLICATION_H__
+
+#include <sys/types.h>
+#include <aul.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int aul_complication_update_request(const char *appid,
+ const char *provider_appid, uid_t uid);
+
+int aul_complication_launch_with_extra_data(const char *appid,
+ const char *provider_appid, uid_t uid,
+ const char *key, const char *value);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __AUL_COMPLICATION_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2018 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_DEBUG_INFO_H__
+#define __AUL_DEBUG_INFO_H__
+
+#include <bundle.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Initializes debug information.
+ *
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ */
+int aul_debug_info_init(void);
+
+/**
+ * @brief Finalizes debug information.
+ *
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ */
+int aul_debug_info_fini(void);
+
+/**
+ * @breif Sets the debug information into the bundle object.
+ *
+ * @param[in] src The bundle object
+ * @param[in] dst The bundle object
+ *
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ */
+int aul_debug_info_set(bundle *src, bundle *dst);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __AUL_DEBUG_INFO_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2016 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_ERROR_H__
+#define __AUL_ERROR_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_error_convert(int res);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __AUL_ERROR_H__ */
--- /dev/null
+/*
+ * Copyright (c) 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
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define AUL_K_JOB_ID "__AUL_JOB_ID__"
+#define AUL_K_JOB_STATUS "__AUL_JOB_STATUS__"
+#define AUL_K_JOB_REAL_ID "__AUL_JOB_REAL_ID__"
+
+#define AUL_K_JOB_PERIODIC "__AUL_JOB_PERIODIC__"
+#define AUL_K_JOB_PERSISTENT "__AUL_JOB_PERSISTENT__"
+#define AUL_K_JOB_IS_ONCE "__AUL_JOB_IS_ONCE__"
+
+#define AUL_K_JOB_REQ_TIMEOUT "__AUL_JOB_REQ_TIMEOUT__"
+#define AUL_K_JOB_REQ_BATTERY_NOT_LOW "__AUL_JOB_REQ_BATTERY_NOT_LOW__"
+#define AUL_K_JOB_REQ_CHARGING "__AUL_JOB_REQ_CHARGING__"
+#define AUL_K_JOB_REQ_WIFI_CONNECTION "__AUL_JOB_REQ_WIFI_CONNECTION__"
+
+#define AUL_K_JOB_TRIG_BATTERY_LEVEL_EMPTY \
+ "__AUL_JOB_TRIG_BATTERY_LEVEL_EMPTY__"
+#define AUL_K_JOB_TRIG_BATTERY_LEVEL_CRITICAL \
+ "__AUL_JOB_TRIG_BATTERY_LEVEL_CRITICAL__"
+#define AUL_K_JOB_TRIG_BATTERY_LEVEL_LOW \
+ "__AUL_JOB_TRIG_BATTERY_LEVEL_LOW__"
+#define AUL_K_JOB_TRIG_BATTERY_LEVEL_HIGH \
+ "__AUL_JOB_TRIG_BATTERY_LEVEL_HIGH__"
+#define AUL_K_JOB_TRIG_CHARGER_STATE_CONNECTED \
+ "__AUL_JOB_TRIG_CHARGER_STATE_CONNECTED__"
+#define AUL_K_JOB_TRIG_CHARGER_STATE_DISCONNECTED \
+ "__AUL_JOB_TRIG_CHARGER_STATE_DISCONNECTED__"
+#define AUL_K_JOB_TRIG_DISPLAY_STATE_ON \
+ "__AUL_JOB_TRIG_DISPLAY_STATE_ON__"
+#define AUL_K_JOB_TRIG_DISPLAY_STATE_OFF \
+ "__AUL_JOB_TRIG_DISPLAY_STATE_OFF__"
+#define AUL_K_JOB_TRIG_DISPLAY_STATE_DIM \
+ "__AUL_JOB_TRIG_DISPLAY_STATE_DIM__"
+#define AUL_K_JOB_TRIG_EARJACK_STATE_CONNECTED \
+ "__AUL_JOB_TRIG_EARJACK_STATE_CONNECTED__"
+#define AUL_K_JOB_TRIG_EARJACK_STATE_DISCONNECTED \
+ "__AUL_JOB_TRIG_EARJACK_STATE_DISCONNECTED__"
+#define AUL_K_JOB_TRIG_GPS_STATE_DISABLED \
+ "__AUL_JOB_TRIG_GPS_STATE_DISABLED__"
+#define AUL_K_JOB_TRIG_GPS_STATE_SEARCHING \
+ "__AUL_JOB_TRIG_GPS_STATE_SEARCHING__"
+#define AUL_K_JOB_TRIG_GPS_STATE_CONNECTED \
+ "__AUL_JOB_TRIG_GPS_STATE_CONNECTED__"
+#define AUL_K_JOB_TRIG_POWERSAVE_MODE_ENABLED \
+ "__AUL_JOB_TRIG_POWERSAVE_MODE_ENABLED__"
+#define AUL_K_JOB_TRIG_POWERSAVE_MODE_DISABLED \
+ "__AUL_JOB_TRIG_POWERSAVE_MODE_DISABLED__"
+#define AUL_K_JOB_TRIG_USB_STATE_CONNECTED \
+ "__AUL_JOB_TRIG_USB_STATE_CONNECTED__"
+#define AUL_K_JOB_TRIG_USB_STATE_DISCONNECTED \
+ "__AUL_JOB_TRIG_USB_STATE_DISCONNECTED__"
+#define AUL_K_JOB_TRIG_WIFI_STATE_DISABLED \
+ "__AUL_JOB_TRIG_WIFI_STATE_DISABLED__"
+#define AUL_K_JOB_TRIG_WIFI_STATE_DISCONNECTED \
+ "__AUL_JOB_TRIG_WIFI_STATE_DISCONNECTED__"
+#define AUL_K_JOB_TRIG_WIFI_STATE_CONNECTED \
+ "__AUL_JOB_TRIG_WIFI_STATE_CONNECTED__"
+
+typedef enum {
+ JOB_STATUS_START,
+ JOB_STATUS_STOPPED,
+ JOB_STATUS_FINISHED,
+} aul_job_status_e;
+
+int aul_job_scheduler_update_job_status(const char *job_id,
+ aul_job_status_e job_status);
+
+#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.
+ */
+
+#pragma once
+
+/**
+ * @brief Definition for AUL: The process ID of the caller.
+ * @since_tizen 2.2
+ */
+#define AUL_K_CALLER_PID "__AUL_CALLER_PID__"
+
+/**
+ * @brief Definition for AUL: The process ID of the callee.
+ * @since_tizen 2.2
+ */
+#define AUL_K_CALLEE_PID "__AUL_CALLEE_PID__"
+
+/**
+ * @brief Definition for AUL: The user ID of the caller.
+ * @since_tizen 3.0
+ */
+#define AUL_K_CALLER_UID "__AUL_CALLER_UID__"
+
+/**
+ * @brief Definition for AUL: The user ID of the callee.
+ * @since_tizen 3.0
+ */
+#define AUL_K_CALLEE_UID "__AUL_CALLEE_UID__"
+
+/**
+ * @brief Definition for AUL: The user ID of the taget user.
+ * @since_tizen 3.0
+ */
+#define AUL_K_TARGET_UID "__AUL_TARGET_UID__"
+
+/**
+ * @brief Definition for AUL: The application ID of the caller.
+ * @since_tizen 2.2
+ */
+#define AUL_K_CALLER_APPID "__AUL_CALLER_APPID__"
+
+/**
+ * @brief Definitnon for AUL: The application ID of the callee.
+ * @since_tizen 2.2
+ */
+#define AUL_K_CALLEE_APPID "__AUL_CALLEE_APPID__"
+
+/**
+ * @deprecated Deprecated since 3.0
+ * @brief Definition for AUL: The first argument.
+ * @since_tizen 2.2
+ */
+#define AUL_K_ARGV0 "__AUL_ARGV0__"
+
+/**
+ * @brief Definition for AUL: The start time.
+ * @since_tizen 2.2
+ */
+#define AUL_K_STARTTIME "__AUL_STARTTIME__"
+
+/**
+ * @brief Definition for AUL: The MIME-Type data.
+ * @since_tizen 2.2
+ */
+#define AUL_K_MIME_TYPE "__AUL_MIME_TYPE__"
+
+/**
+ * @brief Definition for AUL: The unaliased MIME-Type data.
+ * @since_tizen 2.2
+ */
+#define AUL_K_UNALIASED_MIME_TYPE "__AUL_UNALIASED_MIME_TYPE__"
+
+/**
+ * @brief Definition for AUL: The content of the MIME-Type data.
+ * @since_tizen 2.2
+ */
+#define AUL_K_MIME_CONTENT "__AUL_MIME_CONTENT__"
+
+/**
+ * @brief Definition for AUL: The service name.
+ * @since_tizen 2.2
+ */
+#define AUL_K_SERVICE_NAME "__AUL_SERVICE_NAME__"
+
+/**
+ * @brief Definition for AUL: The flag if it's 'true', the app-selector is launched forcedly.
+ * @since_tizen 2.2
+ */
+#define AUL_K_FORCE_LAUNCH_APP_SELECTOR "__AUL_FORCE_LAUNCH_APP_SELECTOR__"
+
+/**
+ * @brief Definition for AUL: The flag if it's set, the request is for debugging web-applications.
+ * @since_tizen 3.0
+ */
+#define AUL_K_DEBUG "__AUL_DEBUG__"
+
+/**
+ * @brief Definition for AUL: The SDK data.
+ * @since_tizen 2.3
+ */
+#define AUL_K_SDK "__AUL_SDK__"
+
+/**
+ * @deprecated Deprecated since 3.0
+ * @brief Definition for AUL: The multiple key.
+ * @since_tizen 2.3
+ */
+#define AUL_K_MULTI_KEY "__AUL_MULTI_KEY__"
+
+/**
+ * @deprecated Deprecated since 3.0
+ * @brief Definition for AUL: The multiple key event.
+ * @since_tizen 2.3
+ */
+#define AUL_K_MULTI_KEY_EVENT "__AUL_MULTI_KEY_EVENT__"
+
+/**
+ * @brief Definition for AUL: The privacy application ID.
+ * @since_tizen 2.3
+ */
+#define AUL_K_PRIVACY_APPID "__AUL_PRIVACY_APPID__"
+
+/**
+ * @deprecased Deprecated since tizen 3.0
+ * @brief Definition for AUL: The key pressed event.
+ * @since_tizen 2.3
+ */
+#define AUL_V_KEY_PRESSED "__AUL_KEY_PRESSED__"
+
+/**
+ * @deprecased Deprecated since tizen 3.0
+ * @brief Definition for AUL: The key released event.
+ * @since_tizen 2.3
+ */
+#define AUL_V_KEY_RELEASED "__AUL_KEY_RELEASED__"
+
+/**
+ * @brief Definition for RUA: The caller information.
+ * @since_tizen 3.0
+ */
+#define AUL_SVC_K_RUA_STAT_CALLER "__K_RUA_STAT_CALLER__"
+
+/**
+ * @brief Definition for RUA: The tag information.
+ * @since_tizen 3.0
+ */
+#define AUL_SVC_K_RUA_STAT_TAG "__K_RUA_STAT_TAG__"
+
+/**
+ * @brief Definition for RUA: The application ID.
+ * @since_tizen 3.0
+ */
+#define AUL_K_RUA_PKGNAME "__K_RUA_PKGNAME"
+
+/**
+ * @brief Definition for RUA: The application path.
+ * @since_tizen 3.0
+ */
+#define AUL_K_RUA_APPPATH "__K_RUA_APPPATH"
+
+/**
+ * @brief Definition for RUA: The arguments.
+ * @since_tizen 3.0
+ */
+#define AUL_K_RUA_ARG "__K_RUA_ARG"
+
+/**
+ * @brief Definition for RUA: The launched time.
+ * @since_tizen 3.0
+ */
+#define AUL_K_RUA_TIME "__K_RUA_TIME"
+
+/**
+ * @brief Definition for RUA: The instance ID.
+ * @since_tizen 3.0
+ */
+#define AUL_K_RUA_INSTANCE_ID "__K_RUA_INSTANCE_ID"
+
+/**
+ * @brief Definition for RUA: The instance name.
+ * @since_tizen 3.0
+ */
+#define AUL_K_RUA_INSTANCE_NAME "__K_RUA_INSTANCE_NAME"
+
+/**
+ * @brief Definition for RUA: The icon path.
+ * @since_tizen 3.0
+ */
+#define AUL_K_RUA_ICON "__K_RUA_ICON"
+
+/**
+ * @brief Definition for RUA: The URI data.
+ * @since_tizen 3.0
+ */
+#define AUL_K_RUA_URI "__K_RUA_URI"
+
+/**
+ * @brief Definition for AUL: The application ID.
+ * @since_tizen 2.2
+ */
+#define AUL_K_PKG_NAME "__AUL_PKG_NAME__"
+
+/**
+ * @brief Definition for AUL: The flag if it's 'true', the caller process waits to get the result from the callee application.
+ * @since_tizen 2.2
+ */
+#define AUL_K_WAIT_RESULT "__AUL_WAIT_RESULT__"
+
+/**
+ * @brief Definition for AUL: The flag if it's 'true', the request is for sending the result.
+ * @since_tizen 2.2
+ */
+#define AUL_K_SEND_RESULT "__AUL_SEND_RESULT__"
+
+/**
+ * @brief Definition for AUL: The taskmanage value.
+ * @since_tizen 2.2
+ */
+#define AUL_K_TASK_MANAGE "__AUL_TASK_MANAGE__"
+
+/**
+ * @brief Definition for AUL: The application type.
+ * @since_tizen 2.2
+ */
+#define AUL_K_APP_TYPE "__AUL_APP_TYPE__"
+
+/**
+ * @brief Definition for AUL: The process ID of the original caller.
+ * @since_tizen 2.2
+ */
+#define AUL_K_ORG_CALLER_PID "__AUL_ORG_CALLER_PID__"
+
+/**
+ * @brief Definition for AUL: The process ID of the forwarded callee.
+ * @since_tizen 2.2
+ */
+#define AUL_K_FWD_CALLEE_PID "__AUL_FWD_CALLEE_PID__"
+
+/**
+ * @brief Definition for AUL: The flag if it's 'true', the request is not cancelled.
+ * @since_tizen 2.2
+ */
+#define AUL_K_NO_CANCEL "__AUL_NO_CANCEL__"
+
+/**
+ * @brief Definition for AUL: The executable file path.
+ * @since_tizen 2.2
+ */
+#define AUL_K_EXEC "__AUL_EXEC__"
+
+/**
+ * @brief Definition for AUL: The flag if it's 'true', the application can be launched by multiple processes.
+ * @since_tizen 2.2
+ */
+#define AUL_K_MULTIPLE "__AUL_MULTIPLE__"
+
+/**
+ * @brief Definition for AUL: The type of the package.
+ * @since_tizen 2.2
+ */
+#define AUL_K_PACKAGETYPE "__AUL_PACKAGETYPE__"
+
+/**
+ * @brief Definition for AUL: The flag if it's 'true', the application uses hardware-acceleration.
+ * @since_tizen 2.2
+ */
+#define AUL_K_HWACC "__AUL_HWACC__"
+
+/**
+ * @brief Definition for AUL: The application ID.
+ * @since_tizen 2.2
+ */
+#define AUL_K_APPID "__AUL_APPID__"
+
+/**
+ * @brief Definition for AUL: The process ID.
+ * @since_tizen 2.2
+ */
+#define AUL_K_PID "__AUL_PID__"
+
+/**
+ * @brief Definition for AUL: The window ID.
+ * @since_tizen 2.4
+ */
+#define AUL_K_WID "__AUL_WID__"
+
+/**
+ * @breif Definition for AUL: The process ID of the leader process.
+ * @since_tizen 2.4
+ */
+#define AUL_K_LEADER_PID "__AUL_LEADER_PID__"
+
+/**
+ * @brief Definition for Data-Control: The type of data-control.
+ * @since_tizen 2.2
+ */
+#define AUL_K_DATA_CONTROL_TYPE "__AUL_DATA_CONTROL_TYPE__"
+
+/**
+ * @brief Definition for AUL: The package ID.
+ * @since_tizen 2.2
+ */
+#define AUL_K_PKGID "__AUL_PKGID_"
+
+/**
+ * @deprecated Deprecated since 3.0
+ * @brief Definition for AUL: The flag if it's 'true', the application can be launched by internal process-pool.
+ * @since_tizen 2.2
+ */
+#define AUL_K_INTERNAL_POOL "__AUL_INTERNAL_POOL__"
+
+/**
+ * @brief Definition for AUL: The TEP resource path.
+ * @since_tizen 2.4
+ */
+#define AUL_K_TEP_PATH "__AUL_TEP_PATH__"
+
+/**
+ * @brief Definition for AUL: The component type.
+ * @since_tizen 2.2
+ */
+#define AUL_K_COMP_TYPE "__AUL_COMP_TYPE__"
+
+/**
+ * @brief Definition for AUL: The loader ID.
+ * @since_tizen 3.0
+ */
+#define AUL_K_LOADER_ID "__AUL_LOADER_ID__"
+
+/**
+ * @brief Definition for AUL: The executable file path of the loader.
+ * @since_tizen 3.0
+ */
+#define AUL_K_LOADER_PATH "__AUL_LOADER_PATH__"
+
+/**
+ * @brief Definition for AUL: The extra data of the loader.
+ * @since_tizen 3.0
+ */
+#define AUL_K_LOADER_EXTRA "__AUL_LOADER_EXTRA__"
+
+/**
+ * @brief Definition for AUL: The loader name.
+ * @since_tizen 3.0
+ */
+#define AUL_K_LOADER_NAME "__AUL_LOADER_NAME__"
+
+/**
+ * @brief Definition for AUL: The wayland display.
+ * @since_tizen 3.0
+ */
+#define AUL_K_WAYLAND_DISPLAY "__AUL_WAYLAND_DISPLAY__"
+
+/**
+ * @brief Definition for AUL: The wayland working directory path.
+ * @since_tizen 3.0
+ */
+#define AUL_K_WAYLAND_WORKING_DIR "__AUL_WAYLAND_WORKING_DIR__"
+
+/**
+ * @brief Definition for AUL: The sender process ID of app-com.
+ * @since_tizen 3.0
+ */
+#define AUL_K_COM_SENDER_PID "__AUL_COM_SENDER_PID__"
+
+/**
+ * @brief Definition for AUL: The endpoint of app-com.
+ * @since_tizen 3.0
+ */
+#define AUL_K_COM_ENDPOINT "__AUL_COM_ENDPOINT__"
+
+/**
+ * @brief Definition for AUL: The privilege of app-com.
+ * @since_tizen 3.0
+ */
+#define AUL_K_COM_PRIVILEGE "__AUL_COM_PRIVILEGE__"
+
+/**
+ * @brief Definition for AUL: The propagate information of app-com.
+ * @since_tizen 3.0
+ */
+#define AUL_K_COM_PROPAGATE "__AUL_COM_PROPAGATE__"
+
+/**
+ * @brief Definition for AUL: The filter of app-com.
+ * @since_tizen 3.0
+ */
+#define AUL_K_COM_FILTER "__AUL_COM_FILTER__"
+
+/**
+ * @brief Definition for AUL: The result of app-com.
+ * @since_tizen 3.0
+ */
+#define AUL_K_COM_RESULT "__AUL_COM_RESULT__"
+
+/**
+ * @brief Definition for AUL: The root path.
+ * @since_tizen 3.0
+ */
+#define AUL_K_ROOT_PATH "__AUL_ROOT_PATH__"
+
+/**
+ * @brief Definition for AUL: The sequence number.
+ * @since_tizen 3.0
+ */
+#define AUL_K_SEQ_NUM "__AUL_SEQ_NUM__"
+
+/**
+ * @brief Definition for AUL: The API version.
+ * @since_tizen 3.0
+ */
+#define AUL_K_API_VERSION "__AUL_API_VERSION__"
+
+/**
+ * @brief Definition for AUL: The flag if it's 'true', the application can be running in the background.
+ * @since_tizen 2.4
+ */
+#define AUL_K_ALLOWED_BG "__AUL_ALLOWED_BG__"
+
+/**
+ * @brief Definition for AUL: The owner process ID of app-group.
+ * @since_tizen 2.4
+ */
+#define AUL_K_OWNER_PID "__AUL_OWNER_PID__"
+
+/**
+ * @brief Definition for AUL: The child process ID of app-group.
+ * @since_tizen 2.4
+ */
+#define AUL_K_CHILD_PID "__AUL_CHILD_PID__"
+
+/**
+ * @brief Definition for Widget: The widget viewer.
+ * @since_tizen 3.0
+ */
+#define AUL_K_WIDGET_VIEWER "__AUL_WIDGET_VIEWER__"
+
+/**
+ * @brief Definition for Widget: The widget ID.
+ * @since_tizen 3.0
+ */
+#define AUL_K_WIDGET_ID "__AUL_WIDGET_ID__"
+
+/**
+ * @brief Definition for Widget: The instance ID of the widget.
+ * @since_tizen 3.0
+ */
+#define AUL_K_WIDGET_INSTANCE_ID "__AUL_WIDGET_INSTANCE_ID__"
+
+/**
+ * @brief Definition for Widget: The status of the widget.
+ * @since_tizen 3.0
+ */
+#define AUL_K_WIDGET_STATUS "__AUL_WIDGET_STATUS__"
+
+/**
+ * @brief Definition for Widget: The error code of the widget.
+ * @since_tizen 3.0
+ */
+#define AUL_K_WIDGET_ERROR_CODE "__AUL_WIDGET_ERROR_CODE__"
+
+/**
+ * @brief Definition for Widget: The widget content infomation.
+ * @since_tizen 3.0
+ */
+#define AUL_K_WIDGET_CONTENT_INFO "__AUL_WIDGET_CONTENT_INFO__"
+
+/**
+ * @brief Definition for AUL: The target process ID.
+ * @since_tizen 3.0
+ */
+#define AUL_K_TARGET_PID "__AUL_TARGET_PID__"
+
+/**
+ * @brief Definition for AUL: The alias application ID.
+ * @since_tizen 3.0
+ */
+#define AUL_K_ALIAS_APPID "__AUL_ALIAS_APPID__"
+
+/**
+ * @brief Definition for AUL: The original application ID.
+ * @since_tizen 3.0
+ */
+#define AUL_K_ORG_APPID "__AUL_ORG_APPID__"
+
+/**
+ * @brief Definition for AUL: The status value.
+ * @since_tizen 3.0
+ */
+#define AUL_K_STATUS "__AUL_STATUS__"
+
+/**
+ * @brief Definition for AUL: The flag if it's 'true', the application is launched by sub-application of app-group.
+ * @since_tizen 2.4
+ */
+#define AUL_K_IS_SUBAPP "__AUL_IS_SUBAPP__"
+
+/**
+ * @brief Definition for AUL: The instance ID.
+ * @since_tizen 4.0
+ */
+#define AUL_K_INSTANCE_ID "__AUL_INSTANCE_ID__"
+
+/**
+ * @brief Definition for AUL: The user ID of the original caller.
+ * @since_tizen 3.0
+ */
+#define AUL_K_ORG_CALLER_UID "__AUL_ORG_CALLER_UID__"
+
+/**
+ * @brief Definition for AUL: The checksum data to store app-control information.
+ * @details This definition is to improve the launch performance.
+ * @since_tizen 3.0
+ */
+#define AUL_K_CHECKSUM "__AUL_CHECKSUM__"
+
+/**
+ * @brief Definition for Screen-Connector: The flag if it's 'true', the request type is private.
+ * @since_tizen 3.0
+ */
+#define AUL_K_PRIVATE "__AUL_PRIVATE__"
+
+/**
+ * @brief Definition for Screen-Connector: The screen type.
+ * @since_tizen 3.0
+ */
+#define AUL_K_SCREEN_TYPE "__AUL_SCREEN_TYPE__"
+
+/**
+ * @brief Definition for Screen-Connector: The reference count of the viewer.
+ * @since_tizen 3.0
+ */
+#define AUL_K_VIEWER_REF "__AUL_VIEWER_REF__"
+
+/**
+ * @brief Definition for AUL: The application ID of the parent for transient-for.
+ * @since_tizen 3.0
+ */
+#define AUL_K_PARENT_APPID "__AUL_PARENT_APPID__"
+
+/**
+ * @brief Definition for AUL: The application ID of the child for transient-for.
+ * @since_tizen 3.0
+ */
+#define AUL_K_CHILD_APPID "__AUL_CHILD_APPID__"
+
+/**
+ * @deprecated Deprecated since 4.0
+ * @brief Definition for AUL: The flag if it's 'true', the request is for fast launch.
+ * @since_tizen 3.0
+ */
+#define AUL_K_FAST_LAUNCH "__AUL_FAST_LAUNCH__"
+
+/**
+ * @brief Definition for Widget: The flag if it's 'true', the widget is faulted.
+ * @since_tizen 3.0
+ */
+#define AUL_K_IS_FAULT "__AUL_IS_FAULT__"
+
+/**
+ * @brief Definition for AUL: The profile.
+ * @since_tizen 3.0
+ */
+#define AUL_K_PROFILE "__AUL_PROFILE__"
+
+/**
+ * @brief Definition for AUL: The flag if it's 'true', the application is installed for global user.
+ * @since_tizen 3.0
+ */
+#define AUL_K_IS_GLOBAL "__AUL_IS_GLOBAL__"
+
+/**
+ * @brief Definition for AUL: The flag if it's 'true', the request is to create a new instance.
+ * @since_tizen 3.0
+ */
+#define AUL_K_NEW_INSTANCE "__AUL_NEW_INSTANCE__"
+
+/**
+ * @brief Definition for AUL: The flag if it's 'true', the application is installed.
+ * @since_tizen 3.0
+ */
+#define AUL_K_IS_INSTALLED "__AUL_IS_INSTALLED__"
+
+/**
+ * @brief Definition for AUL: The request type.
+ * @details This key is only for Application Manager.
+ * @since_tizen 4.0
+ */
+#define AUL_K_REQUEST_TYPE "__AUL_REQUEST_TYPE__"
+
+/**
+ * @brief Definition for AUL: The application ID of the original caller.
+ * @since_tizen 3.0
+ */
+#define AUL_K_ORG_CALLER_APPID "__AUL_ORG_CALLER_APPID__"
+
+/**
+ * @brief Definition for AUL: The package ID of the original caller.
+ * @since_tizen 3.0
+ */
+#define AUL_K_ORG_CALLER_PKGID "__AUL_ORG_CALLER_PKGID__"
+
+/**
+ * @brief Definition for AUL: The installed storage.
+ * @since_tizen 2.4
+ */
+#define AUL_K_INSTALLED_STORAGE "__AUL_INSTALLED_STORAGE__"
+
+/**
+ * @brief Definition for AUL: The component ID.
+ * @since_tizen 5.5
+ */
+#define AUL_K_COMPONENT_ID "__AUL_COMPONENT_ID__"
+
+/**
+ * @brief Definition for AUL: The instance ID of the caller.
+ * @since_tizen 5.5
+ */
+#define AUL_K_CALLER_INSTANCE_ID "__AUL_CALLER_INSTANCE_ID__"
+
+/**
+ * @brief Definition for AUL: The instance ID of the original caller.
+ * @since_tizen 5.5
+ */
+#define AUL_K_ORG_CALLER_INSTANCE_ID "__AUL_ORG_CALLER_INSTANCE_ID__"
+
+/**
+ * @brief Definition for AUL: The IDs of the app group leader.
+ * @since_tizen 5.5
+ */
+#define AUL_K_LEADER_IDS "__AUL_LEADER_IDS__"
+
+/**
+ * @brief Definition for AUL: The ID of the app group leader.
+ * @since_tizen 5.5
+ */
+#define AUL_K_LEADER_ID "__AUL_LEADER_ID__"
+
+/**
+ * @brief Definition for AUL: The flag of the foreground.
+ * @since_tizen 5.5
+ */
+#define AUL_K_FG_FLAG "__AUL_FG_FLAG__"
+
+/**
+ * @brief Definition for AUL: The type of the component.
+ * @since_tizen 5.5
+ */
+#define AUL_K_COMPONENT_TYPE "__AUL_COMPONENT_TYPE__"
+
+/**
+ * @breif Definition for AUL: The flag if it's 'true', the component is sub component of the group.
+ * @since_tizen 5.5
+ */
+#define AUL_K_IS_SUB_COMP "__AUL_IS_SUB_COMP__"
+
+/**
+ * @brief Definition for AUL: The flag if it's 'true', the component is the main component of the application.
+ * @since_tizen 5.5
+ */
+#define AUL_K_MAIN_COMP "__AUL_MAIN_COMP__"
+
+/**
+ * @brief Definition for AUL: The flag if it's 'true', the icon of the component should be display.
+ * @since_tizen 5.5
+ */
+#define AUL_K_ICON_DISPLAY "__AUL_ICON_DISPLAY__"
+
+/**
+ * @brief Definition for AUL: The localized information.
+ * @since_tizen 5.5
+ */
+#define AUL_K_LOCALIZED_INFO "__AUL_LOCALIZED_INFO__"
+
+/**
+ * @brief Definition for AUL: The size of the localized information.
+ * @since_tizen 5.5
+ */
+#define AUL_K_LOCALIZED_INFO_SIZE "__AUL_LOCALIZED_INFO_SIZE__"
+
+/**
+ * @brief Definition for AUL: The locale.
+ * @since_tizen 5.5
+ */
+#define AUL_K_LOCALE "__AUL_LOCALE__"
+
+/**
+ * @brief Definition for AUL: The icon path.
+ * @since_tizen 5.5
+ */
+#define AUL_K_ICON "__AUL_ICON__"
+
+/**
+ * @brief Definition for AUL: The label.
+ * @since_tizen 5.5
+ */
+#define AUL_K_LABEL "__AUL_LABEL__"
+
+/**
+ * @brief Definition for AUL: The launch mode.
+ * @since_tizen 5.5
+ */
+#define AUL_K_LAUNCH_MODE "__AUL_LAUNCH_MODE__"
+
+/**
+ * @brief Definition for AUL: The interval.
+ * @since_tizen 5.5
+ */
+#define AUL_K_INTERVAL "__AUL_INTERVAL__"
+
+/**
+ * @brief Definition for AUL: The command.
+ * @since_tizen 5.5
+ */
+#define AUL_K_COMMAND "__AUL_COMMAND__"
+
+/**
+ * @brief Definition for AUL: The name for the launcher service.
+ * @since_tizen 5.5
+ */
+#define AUL_K_LAUNCHER_SERVICE "__K_LAUNCHER_SERVICE__"
+
+/**
+ * @brief Definition for AUL: The unqiue ID of the launcher service.
+ * @since_tizen 5.5
+ */
+#define AUL_K_LAUNCHER_SERVICE_SERIAL "__K_LAUNCHER_SERVICE_SERIAL__"
+
+/**
+ * @brief Definition for AUL: The event of the launcher service.
+ * @since_tizen 5.5
+ */
+#define AUL_K_LAUNCHER_SERVICE_EVENT "__K_LAUNCHER_SERVICE_EVENT__"
+
+/**
+ * @brief Definition for AUL: The name of the app-defined loader.
+ * @since_tizen 5.5
+ */
+#define AUL_K_APP_DEFINED_LOADER "__K_APP_DEFINED_LOADER__"
+
+/**
+ * @brief Definition for AUL: The widget disable.
+ * @since_tizen 5.5
+ */
+#define AUL_K_WIDGET_DISABLE "__AUL_WIDGET_DISABLE__"
+
+/**
+ * @brief Definition for AUL: The flag of the multiple instance shortcut.
+ * @details If it's true, the request is for the multiple instance shortcut.
+ * @since_tizen 5.5
+ */
+#define AUL_K_MULTI_INSTANCE_SHORTCUT "__AUL_MULTI_INSTANCE_SHORTCUT__"
+
+/**
+ * @brief Definition for AUL: The event name.
+ * @since_tizen 5.5
+ */
+#define AUL_K_EVENT_NAME "__AUL_EVENT_NAME__"
+
+/**
+ * @brief Definition for AUL: The event data.
+ * @since_tizen 5.5
+ */
+#define AUL_K_EVENT_DATA "__AUL_EVENT_DATA__"
+
+/**
+ * @brief Definition for AUL: The value for supporting positioning of the app group.
+ * @details If the key exists, the callee app group will be inserted into
+ * the app group before the given position.
+ * @since_tizen 6.0
+ */
+#define AUL_K_INSERT_BEFORE_WINDOW "__K_INSERT_BEFORE_WINDOW"
+
+/**
+ * @brief Definition for AUL: The list of application ID.
+ * @since_tizen 6.0
+ */
+#define AUL_K_APPID_LIST "__AUL_K_APPID_LIST__"
+
+/**
+ * @brief Definition for AUL: The name of the component port.
+ * @since_tizen 6.5
+ */
+#define AUL_K_COMPONENT_PORT "__AUL_COMPONENT_PORT__"
+
+/**
+ * @brief Definition for AUL: The result.
+ * @since_tizen 6.5
+ */
+#define AUL_K_RESULT "__AUL_RESULT__"
+
+/**
+ * @brief Definition for AUL: The flag if it's 'true', the application has focus.
+ * @since_tizen 6.5
+ */
+#define AUL_K_HAS_FOCUS "__AUL_HAS_FOCUS__"
+
+/**
+ * @brief Definition for AUL: The state of the application lifecycle.
+ * @since_tizen 6.5
+ */
+#define AUL_K_STATE "__AUL_STATE__"
+
+/**
+ * @brief Definition for AUL: The list of paths in a global resource packages.
+ * @since_tizen 6.5
+ */
+#define AUL_K_MOUNT_GLOBAL_RES_DIR "__AUL_MOUNT_GLOBAL_RES_DIR__"
+
+/**
+ * @brief Definition for AUL: The list of paths in a allowed resource packages.
+ * @since_tizen 6.5
+ */
+#define AUL_K_MOUNT_ALLOWED_RES_DIR "__AUL_MOUNT_ALLOWED_RES_DIR__"
+
+/**
+ * @brief Definition for AUL: The name of the process.
+ * @since_tizen 6.5
+ */
+#define AUL_K_PROC_NAME "__AUL_PROC_NAME__"
+
+/**
+ * @brief Definition for AUL: The extra data of the process.
+ * @since_tizen 6.5
+ */
+#define AUL_K_PROC_EXTRA "__AUL_PROC_EXTRA__"
+
+/**
+ * @brief Definition for AUL: The flag of the auto restart.
+ * @since_tizen 7.0
+ */
+#define AUL_K_AUTO_RESTART "__AUL_AUTO_RESTART__"
+
+/**
+ * @brief Definition for AUL: The bundle data for auto restart.
+ * @since_tizen 7.0
+ */
+#define AUL_K_RESTART_EXTRA "__AUL_RESTART_EXTRA__"
+
+/**
+ * @brief Definition for AUL: The priority of boot sequence app.
+ * @since_tizen 7.0
+ */
+#define AUL_K_BOOT_SEQUENCE_PRIORITY "__AUL_BOOT_SEQUENCE_PRIORITY__"
+
+/**
+ * @brief Definition for AUL: The flag of boot sequence app's reqdy wait.
+ * @since_tizen 7.0
+ */
+#define AUL_K_BOOT_SEQUENCE_READY_WAIT "__AUL_BOOT_SEQUENCE_READY_WAIT__"
+
+/**
+ * @brief Definition for AUL: The sub status of app.
+ * @since_tizen 7.0
+ */
+#define AUL_K_SUB_STATUS "__AUL_SUB_STATUS__"
+
+/**
+ * @brief Definition for AUL: The appid list of boot sequence app's after dependency.
+ * @since_tizen 7.0
+ */
+#define AUL_K_BOOT_SEQUENCE_AFTER "__AUL_BOOT_SEQUENCE_AFTER__"
+
+/**
+ * @brief Definition for AUL: The appid list of boot sequence app's before dependency.
+ * @since_tizen 7.0
+ */
+#define AUL_K_BOOT_SEQUENCE_BEFORE "__AUL_BOOT_SEQUENCE_BEFORE__"
+
+/**
+ * @brief Definition for AUL: The appid list of boot sequence app's requires dependency.
+ * @since_tizen 7.0
+ */
+#define AUL_K_BOOT_SEQUENCE_REQUIRES "__AUL_BOOT_SEQUENCE_REQUIRES__"
+
+/**
+ * @brief Definition for AUL: The appid list of boot sequence app's conflicts dependency.
+ * @since_tizen 7.0
+ */
+#define AUL_K_BOOT_SEQUENCE_CONFLICTS "__AUL_BOOT_SEQUENCE_CONFLICTS__"
+
+/**
+ * @brief Definition for AUL: The args bundle data.
+ * @since_tizen 7.0
+ */
+#define AUL_K_ARGS "__AUL_ARGS__"
+
+/**
+ * @brief Definition for AUL: The timeout.
+ * @since_tizen 7.0
+ */
+#define AUL_K_TIMEOUT "__AUL_TIMEOUT__"
+
+/**
+ * @brief Definition for AUL: The begin timestamp of boot sequence app start.
+ * @since_tizen 7.0
+ */
+#define AUL_K_BEGIN_TIMESTAMP "__AUL_BEGIN_TIMESTAMP__"
+
+/**
+ * @brief Definition for AUL: The end timestamp of boot sequence app start.
+ * @since_tizen 7.0
+ */
+#define AUL_K_END_TIMESTAMP "__AUL_END_TIMESTAMP__"
+
+/**
+ * @brief Definition for AUL: The socket ready timestamp of boot sequence app.
+ * @since_tizen 7.0
+ */
+#define AUL_K_SOCKET_READY_TIMESTAMP "__AUL_SOCKET_READY_TIMESTAMP__"
+
+/**
+ * @brief Definition for AUL: The terminated timestamp of boot sequence app.
+ * @since_tizen 7.0
+ */
+#define AUL_K_TERMINATED_TIMESTAMP "__AUL_TERMINATED_TIMESTAMP__"
+
+/**
+ * @brief Definition for AUL: The status message of boot sequence app.
+ * @since_tizen 7.0
+ */
+#define AUL_K_STATUS_MSG "__AUL_STATUS_MSG__"
+
+/**
+ * @brief Definition for AUL: The vconf data of boot sequence app.
+ * @since_tizen 7.0
+ */
+#define AUL_K_VCONF_DATA "__AUL_VCONF_DATA__"
+
+/**
+ * @brief Definition for AUL: The value of indicating a enabled light user for app.
+ * @since_tizen 7.0
+ */
+#define AUL_K_ENABLED_LIGHT_USER "__AUL_ENABLED_LIGHT_USER__"
+
+/**
+ * @brief Definition for AUL: The complication mode.
+ * @since_tizen 5.0
+ */
+#define AUL_K_COMPLICATION_MODE "__AUL_COMPLICATION_MODE__"
+
+/**
+ * @brief Definition for AUL: The package event name.
+ * @since_tizen 7.0
+ */
+#define AUL_K_PKG_EVENT_NAME "__AUL_K_PKG_EVENT_NAME__"
+
+/**
+ * @brief Definition for AUL: The package event
+ * @since_tizen 7.0
+ */
+#define AUL_K_PKG_EVENT_RESULT "__AUL_K_PKG_EVENT_RESULT__"
+
+/**
+ * @brief Definition for AUL: The socket timeout milli seconds.
+ * @since_tizen 8.0
+ */
+#define AUL_K_SOCKET_TIMEOUT "__AUL_SOCKET_TIMEOUT__"
+
+/**
+ * @brief Definition for AUL: The list of mounted resource packages
+ * @since_tizen 8.0
+ */
+#define AUL_K_MOUNT_RES_PKGIDS "__AUL_MOUNT_RES_PKGIDS__"
+
+/**
+ * @brief Definition for AUL: X position of the window.
+ * @since_tizen 8.0
+ */
+#define AUL_K_HINT_SCREEN_POS_X "__K_HINT_SCREEN_POS_X"
+
+/**
+ * @brief Definition for AUL: Y position of the window.
+ * @since_tizen 8.0
+ */
+#define AUL_K_HINT_SCREEN_POS_Y "__K_HINT_SCREEN_POS_Y"
+
+/**
+ * @brief Definition for AUL: Width of the window.
+ * @since_tizen 8.0
+ */
+#define AUL_K_HINT_SCREEN_WIDTH "__K_HINT_SCREEN_WIDTH"
+
+/**
+ * @brief Definition for AUL: Height of the window.
+ * @since_tizen 8.0
+ */
+#define AUL_K_HINT_SCREEN_HEIGHT "__K_HINT_SCREEN_HEIGHT"
+
+/**
+ * @brief Definition for AUL: The application ID for multiple instances.
+ * @since_tizen 8.0
+ */
+#define AUL_K_MULTIPLE_INSTANCE_APPID "__AUL_MULTIPLE_INSTANCE_APPID__"
+
+/**
+ * @brief Definition for AUL: The request ID.
+ * @since_tizen 8.0
+ */
+#define AUL_K_REQUEST_ID "__AUL_REQUEST_ID__"
+
+/**
+ * @brief Definition for AUL: The list of paths in a library resource packages.
+ * @since_tizen 9.0
+ */
+#define AUL_K_MOUNT_LIB_DIR "__AUL_MOUNT_LIB_DIR__"
+
+/**
+ * @brief Definition for AUL: The list of mounted gadget package IDs.
+ * @since_tizen 7.0
+ */
+#define AUL_K_MOUNT_GADGET_PKGIDS "__AUL_MOUNT_GADGET_PKGIDS__"
+
+/**
+ * @brief Definition for AUL: The list of paths of gadget packages.
+ * @since_tizen 7.0
+ */
+#define AUL_K_MOUNT_GADGET_PATHS "__AUL_MOUNT_GADGET_PATHS__"
--- /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_LAUNCHER_SERVICE_H__
+#define __AUL_LAUNCHER_SERVICE_H__
+
+#include <stdint.h>
+#include <aul.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief The AUL launcher service handle.
+ * @since_tizen 5.5
+ */
+typedef struct aul_launcher_service_s *aul_launcher_service_h;
+
+/**
+ * @brief Called when an application is launched.
+ * @since_tizen 5.5
+ *
+ * @param[in] appid The application ID
+ * @param[in] instance_id The instance ID
+ * @param[in] pid The process ID
+ * @param[in] serial The unique ID
+ * @param[in] user_data The user data passed from the callback registration function
+ *
+ * @see aul_launcher_service_create()
+ */
+typedef void (*aul_launcher_service_cb)(const char *appid,
+ const char *instance_id,
+ const int pid,
+ const uint32_t serial,
+ void *user_data);
+
+/**
+ * @brief Creates the launcher service handle.
+ * @details To invoke the callback function, aul_launcher_service_listen() has to be called.
+ * @since_tizen 5.5
+ *
+ * @param[in] name The name of the launcher service
+ * @param[in] callback The callback function to be called when the application is launched
+ * @param[in] user_data The user data to be passed to the callback function
+ * @param[out] handle The launcher service handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @see aul_launcher_service_cb()
+ * @see aul_launcher_service_listen()
+ * @see aul_launcher_service_destroy()
+ *
+ * @remarks This function is only available for App Framework internally.
+ */
+int aul_launcher_service_create(const char *name,
+ aul_launcher_service_cb callback,
+ void *user_data, aul_launcher_service_h *handle);
+
+/**
+ * @brief Listens to the launcher service signal.
+ * @details The callback function is invoked when the signal is received.
+ * @since_tizen 5.5
+ *
+ * @param[in] handle The launcher service handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @see aul_launcher_service_create()
+ *
+ * @remarks This function is only available for App Framework internally.
+ */
+int aul_launcher_service_listen(aul_launcher_service_h handle);
+
+/**
+ * @brief Unsubscribes the registered launcher service.
+ * @since_tizen 5.5
+ *
+ * @param[in] handle The launcher service handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @see aul_launcher_service_create()
+ *
+ * @remarks This function is only available for App Framework internally.
+ */
+int aul_launcher_service_destroy(aul_launcher_service_h handle);
+
+/**
+ * @brief Notifies that the animation is started.
+ * @since_tizen 5.5
+ *
+ * @return 0 on success,
+ * otherwise a negative error value
+ *
+ * @see aul_launcher_service_notify_animation_finished()
+ *
+ * @remarks This function is only available for App Framework internally.
+ */
+int aul_launcher_service_notify_animation_started(void);
+
+/**
+ * @brief Notifies that the animation is finished.
+ * @since_tizen 5.5
+ *
+ * @return 0 on success,
+ * otherwise a negative error value
+ *
+ * @see aul_launcher_service_notify_animation_started()
+ *
+ * @remarks This function is only available for App Framework internally.
+ */
+int aul_launcher_service_notify_animation_finished(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __AUL_LAUNCHER_SERVICE_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2000 - 2021 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_PROC_H__
+#define __AUL_RPOC_H__
+
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <aul.h>
+#include <bundle.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Gets the user ID of the process from the proc filesystem.
+ * @since_tizen 6.5
+ * @param[in] pid The process ID
+ * @param[out] uid The user ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_proc_get_uid(pid_t pid, uid_t *uid);
+
+/**
+ * @brief Gets the SMACK label of the process from the proc filesystem.
+ * @since_tizen 6.5
+ * @param[in] pid The process ID
+ * @param[in] buf The buffer
+ * @param[in] buf_size The size of the buffer
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_proc_get_attr(pid_t pid, char *buf, size_t buf_size);
+
+/**
+ * @brief Gets the cmdline of the process from the proc filesystem.
+ * @since_tizen 6.5
+ * @param[in] pid The process ID
+ * @param[in] buf The buffer
+ * @param[in] buf_size The size of the buffer
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_proc_get_cmdline(pid_t pid, char *buf, size_t buf_size);
+
+/**
+ * @brief Registers the process information,
+ * @details This function registers the process information to the application manager daemon.
+ * After calling this function, the other process can get the process information
+ * using aul_proc_get_name() or aul_proc_get_extra().
+ * @since_tizen 6.5
+ * @param[in] name The process name
+ * @param[in] extra The extra data
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_proc_register(const char *name, bundle *extra);
+
+/**
+ * @brief Deregister the process information.
+ * @since_tizen 6.5
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_proc_deregister(void);
+
+/**
+ * @brief Gets the process name.
+ * @since_tizen 6.5
+ * @remarks The @a name MUST be released using free().
+ * @param[in] pid The process ID
+ * @param[out] name The process name
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_proc_get_name(pid_t pid, char **name);
+
+/**
+ * @brief Gets the extra data of the process.
+ * @since_tizen 6.5
+ * @reamrks The @a extra MUST be released using bundle_free().
+ * @param[in] pid The process ID
+ * @param[out] extra The extra data
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_proc_get_extra(pid_t pid, bundle **extra);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __AUL_PROC_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2021 - 2023 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_PROC_GROUP_H__
+#define __AUL_PROC_GROUP_H__
+
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <aul.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief The process group information handle.
+ * @since_tizen 8.0
+ */
+typedef void *aul_proc_group_info_h;
+
+/**
+ * @brief Called when the process group info is delivered.
+ * @remarks This function is only for App Framework internally.
+ * @details You must not release @a h using aul_proc_group_info_destroy().
+ * It's managed by platform.
+ * @since_tizen 8.0
+ * @param[in] h The process group info handle
+ * @param[in] user_data The user data passed from the registration function
+ * @see aul_proc_group_foreach()
+ */
+typedef void (*aul_proc_group_cb)(aul_proc_group_info_h h, void *user_data);
+
+/**
+ * @brief Gets the leader process ID from the process group info handle.
+ * @remarks This function is only for App Framework internally.
+ * @since_tizen 8.0
+ * @param[in] h The process group info handle
+ * @param[out] leader_pid The leader pid of the process group
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_R_OK Successful
+ * @retval #AUL_R_EINVAL Invalid parameter
+ * @see aul_proc_group_foreach()
+ */
+int aul_proc_group_info_get_leader_pid(aul_proc_group_info_h h, pid_t *leader_pid);
+
+/**
+ * @brief Gets the sub process IDs from the process group info handle.
+ * @remarks This function is only for App Framework internally.
+ * @details You must not release the @c sub_pids using free().
+ * It's managed by platform.
+ * The sub_pids is only valid in the callback function.
+ * @since_tizen 8.0
+ * @param[in] h The process group info handle
+ * @param[out] sub_pids The sub pids of the process group
+ * @param[out] length The length of the sub pids
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_R_OK Successful
+ * @retval #AUL_R_EINVAL Invalid parameter
+ * @see aul_proc_group_foreach()
+ */
+int aul_proc_group_info_get_sub_pids(aul_proc_group_info_h h, const pid_t **sub_pids, size_t *length);
+
+/**
+ * @brief Releases the process group info handle.
+ * @remarks This function is only for App Framework internally.
+ * @since_tizen 8.0
+ * @param[in] h The process group info handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_R_OK Sucessful
+ * @retval #AUL_R_EINVAL Invalid parameter
+ * @see aul_proc_group_get()
+ */
+int aul_proc_group_info_destroy(aul_proc_group_info_h h);
+
+/**
+ * @brief Adds the process to the process group.
+ * @remarks This function is only for App Framework internally.
+ * @remarks If the pid is not equal to the process ID of the caller,
+ * the caller MUST have a permission that is signed by platform certificate.
+ * If the caller doesn't have the permission, the function returns AUL_R_EILLACC.
+ * @since_tizen 6.5
+ * @param[in] pid The process ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_R_OK Successful
+ * @retval #AUL_R_EINVAL Invalid parameter
+ * @retval #AUL_R_ECOMM Communication error on send
+ * @retval #AUL_R_EILLACC Permission denied
+ */
+int aul_proc_group_add(pid_t pid);
+
+/**
+ * @brief Removes the process from the process group.
+ * @remarks This function is only for App Framework internally.
+ * @remarks If the pid is not equal to the process ID of the caller,
+ * the caller MUST have a permission that is signed by platform certificate.
+ * If the caller doesn't have the permission, the function returns AUL_R_EILLACC.
+ * @since_tizen 6.5
+ * @param[in] pid The process ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_R_OK Successful
+ * @retval #AUL_R_EINVAL Invalid parameter
+ * @retval #AUL_R_ECOMM Communication error on send
+ * @retval #AUL_R_EILLACC Permission denied
+ */
+int aul_proc_group_remove(pid_t pid);
+
+/**
+ * @brief Retrieves the process group information.
+ * @remarks This function is only for App Framework internally.
+ * @remarks This definition is only available for platform level signed applications.
+ * @param[in] callback The callback function
+ * @param[in] user_data The user data to be passed the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_R_OK Successful
+ * @retval #AUL_R_EINVAL Invalid parameter
+ * @retval #AUL_R_ECOMM Communication error
+ * @retval #AUL_R_EILLACC Permission denied
+ * @see aul_proc_group_cb()
+ */
+int aul_proc_group_foreach(aul_proc_group_cb callback, void *user_data);
+
+/**
+ * @brief Gets the specific process group info.
+ * @remarks This function is only for App Framework internally.
+ * @remarks This definition is only available for platform level signed applications.
+ * @details You must release the @c h using aul_proc_group_info_destroy().
+ * @since_tizen 8.0
+ * @param[in] pid The process ID
+ * @param[out] h The process group info handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_R_OK Successful
+ * @retval #AUL_R_EINVAL Invalid parameter
+ * @retval #AUL_R_ENOENT No such group info
+ * @retval #AUL_R_ENOMEM Out of memory
+ * @see aul_proc_group_info_destroy()
+ */
+int aul_proc_group_get(pid_t pid, aul_proc_group_info_h *h);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __AUL_PROC_GROUP_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2018 - 2021 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_RPC_PORT_H__
+#define __AUL_RPC_PORT_H__
+
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <aul.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef AUL_K_RPC_PORT
+#define AUL_K_RPC_PORT "__K_RPC_PORT"
+#endif
+
+typedef void *aul_rpc_port_watch_h;
+
+typedef void (*aul_rpc_port_appeared_cb)(const char *app_id,
+ const char *port_name, int pid, void *user_data);
+
+typedef void (*aul_rpc_port_vanished_cb)(const char *app_id,
+ const char *port_name, int pid, void *user_data);
+
+int aul_rpc_port_prepare_stub(const char *app_id, const char *port_name);
+
+int aul_rpc_port_usr_prepare_stub(const char *app_id, const char *port_name,
+ uid_t uid);
+
+int aul_rpc_port_create_socket_pair(const char *app_id, const char *port_name,
+ int (*fds)[2]);
+
+int aul_rpc_port_notify_rpc_finished(void);
+
+int aul_rpc_port_set_private_sharing(const char *app_id, const char *paths[],
+ unsigned int size);
+
+int aul_rpc_port_unset_private_sharing(const char *app_id);
+
+int aul_rpc_port_create(const char *port_name, int *fd);
+
+int aul_rpc_port_usr_create(const char *port_name, uid_t uid, int *fd);
+
+int aul_rpc_port_destroy(const char *port_name);
+
+int aul_rpc_port_usr_destroy(const char *port_name, uid_t uid);
+
+int aul_rpc_port_add_watch(const char *app_id, const char *port_name,
+ aul_rpc_port_appeared_cb appeared_cb,
+ aul_rpc_port_vanished_cb vanished_cb,
+ void *user_data,
+ aul_rpc_port_watch_h *handle);
+
+int aul_rpc_port_usr_add_watch(const char *app_id, const char *port_name,
+ aul_rpc_port_appeared_cb appeared_cb,
+ aul_rpc_port_vanished_cb vanished_cb,
+ void *user_data, uid_t uid,
+ aul_rpc_port_watch_h *handle);
+
+
+int aul_rpc_port_remove_watch(aul_rpc_port_watch_h handle);
+
+int aul_rpc_port_exist(const char *appid, const char *port_name, bool *exist);
+
+int aul_rpc_port_usr_exist(const char *appid, const char *port_name, uid_t uid,
+ bool *exist);
+
+int aul_rpc_port_get_path(const char *appid, const char *port_name,
+ char **path);
+
+int aul_rpc_port_usr_get_path(const char *appid, const char *port_name,
+ uid_t uid, char **path);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __AUL_RPC_PORT_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <tizen.h>
+#include <bundle.h>
+#include <glib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Enumeration for Resource Types
+ * @since_tizen 2.4
+ */
+typedef enum {
+ AUL_RESOURCE_TYPE_IMAGE = 0, /**<Image*/
+ AUL_RESOURCE_TYPE_LAYOUT, /**<Edje*/
+ AUL_RESOURCE_TYPE_SOUND, /**<Sound*/
+ AUL_RESOURCE_TYPE_BIN, /**<Bin*/
+ AUL_RESOURCE_TYPE_MIN = AUL_RESOURCE_TYPE_IMAGE,
+ AUL_RESOURCE_TYPE_MAX = AUL_RESOURCE_TYPE_BIN,
+/*add values between AUL_RESOURCE_TYPE_MIN and AUL_RESOURCE_TYPE_MAX*/
+} aul_resource_e;
+
+/**
+ * @brief Enumeration for Aul Resource Manager Error.
+ * @since_tizen 2.4
+ */
+typedef enum {
+ AUL_RESOURCE_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
+ AUL_RESOURCE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
+ AUL_RESOURCE_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
+ AUL_RESOURCE_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */
+} aul_resource_error_e;
+
+/**
+ * @brief Creates resource manager and get from db.
+ *
+ * @since_tizen 2.4
+ * @remarks If resource manager is already exist,
+ * It will just return APP_RESOURCE_ERROR_NONE
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_RESOURCE_ERROR_NONE Successful
+ * @retval #AUL_RESOURCE_ERROR_IO_ERROR IO Internal I/O Error
+ * @retval #AUL_RESOURCE_ERROR_OUT_OF_MEMORY Out of memeory
+ * @see aul_resource_manager_release()
+ */
+int aul_resource_manager_init(void);
+
+/**
+ * @brief Creates resource manager and make valid filelist from given attributes.
+ *
+ * @since_tizen 2.4
+ * @remarks If resource manager is already exist,
+ * It will just return APP_RESOURCE_ERROR_NONE
+ * This function should called from resource slice tool only.
+ * @param[in] rsc_folder_path path of resource.
+ * @param[in] b bundle which contain attributes about target device.
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_RESOURCE_ERROR_NONE Successful
+ * @retval #AUL_RESOURCE_ERROR_IO_ERROR IO Internal I/O Error
+ * @retval #AUL_RESOURCE_ERROR_OUT_OF_MEMORY Out of memeory
+ * @see aul_resource_manager_release()
+ */
+int aul_resource_manager_init_slice(const char *rsc_folder_path, bundle *b);
+
+/**
+ * @brief Convert resource ID to path name
+ *
+ * @since_tizen 2.4
+ * @remarks If resource manager is not created yet,
+ * aul_resource_manager_init() will be invoked automatically.
+ * Caller should free the returned pointer.
+ * @param[in] type Resource type @see aul_resource_e
+ * @param[in] id Resource ID
+ * @param[out] path The name of requested resource on success, otherwise NULL
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_RESOURCE_ERROR_NONE Successful
+ * @retval #AUL_RESOURCE_ERROR_INVALID_PARAMETER Invalid Parameter
+ * @retval #AUL_RESOURCE_ERROR_IO_ERROR Internal I/O Error
+ * @see aul_resource_manager_init()
+ */
+int aul_resource_manager_get(aul_resource_e type, const char *id, char **path);
+
+/**
+ * @brief Destroys resource manager.
+ *
+ * @since_tizen 2.4
+ * @remarks Please make sure that the instance of resource manager should be released when the application is closing only.
+ * It is highly recommended way to improve run-time performance.
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_RESOURCE_ERROR_NONE Successful
+ * @see aul_resource_manager_init()
+ */
+int aul_resource_manager_release(void);
+
+/**
+ * @brief Get valid file path list.
+ *
+ * @since_tizen 2.4
+ * @remarks Please make sure that the instance of resource manager should be released when the application is closing only.
+ * It is highly recommended way to improve run-time performance.
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_RESOURCE_ERROR_NONE Successful
+ * @see aul_resource_manager_init()
+ */
+int aul_resource_manager_get_path_list(GHashTable **list);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+
--- /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_RUNNING_CONTEXT_H__
+#define __AUL_RUNNING_CONTEXT_H__
+
+#include <stdint.h>
+#include <aul.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief The AUL running context handle.
+ * @since_tizen 5.5
+ */
+typedef struct aul_running_context_s *aul_running_context_h;
+
+/**
+ * @brief Creates the running context handle.
+ * @since_tizen 5.5
+ *
+ * @param[in] app_id The application ID
+ * @param[in] inst_id The instance ID
+ * @param[in] comp_id The component ID
+ * @param[out] handle The running context handle of the given IDs
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only available for platform level signed applications.
+ */
+int aul_running_context_create(const char *app_id,
+ const char *inst_id,
+ const char *comp_id,
+ aul_running_context_h *handle);
+
+/**
+ * @brief Destroyes the running context handle.
+ * @since_tizen 5.5
+ *
+ * @param[in] handle The running context handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ */
+int aul_running_context_destroy(aul_running_context_h handle);
+
+/**
+ * @brief Gets the application ID.
+ * @since_tizen 5.5
+ * @remarks The @a app_id MUST NOT be released using free().
+ * It's released when the runnning context handle is released.
+ *
+ * @param[in] handle The running context handle
+ * @param[out] app_id The application ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ */
+int aul_running_context_get_app_id(aul_running_context_h handle,
+ const char **app_id);
+
+/**
+ * @brief Gets the instance ID.
+ * @since_tizen 5.5
+ * @remarks The @a inst_id MUST NOT be release using free().
+ * It's released when the running context handle is released.
+ *
+ * @param[in] handle The running context handle
+ * @param[out] inst_id The instance ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ */
+int aul_running_context_get_inst_id(aul_running_context_h handle,
+ const char **inst_id);
+
+/**
+ * @brief Gets the process ID.
+ * @since_tizen 5.5
+ *
+ * @param[in] handle The running context handle
+ * @param[out] pid The process ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ */
+int aul_running_context_get_pid(aul_running_context_h handle,
+ int *pid);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __AUL_RUNNING_CONTEXT_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2016 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_SCREEN_CONNECTOR_H__
+#define __AUL_SCREEN_CONNECTOR_H__
+
+#include <stdbool.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum {
+ AUL_SCREEN_TYPE_WIDGET = 0x01,
+ AUL_SCREEN_TYPE_WATCH = 0x02,
+ AUL_SCREEN_TYPE_UI = 0x04,
+ AUL_SCREEN_TYPE_COMPONENT_BASED = 0x08,
+ AUL_SCREEN_TYPE_ALL = AUL_SCREEN_TYPE_WIDGET | AUL_SCREEN_TYPE_WATCH |
+ AUL_SCREEN_TYPE_UI | AUL_SCREEN_TYPE_COMPONENT_BASED,
+} aul_screen_type_e;
+
+typedef enum {
+ AUL_SCREEN_CONNECTOR_EVENT_TYPE_ADD,
+ AUL_SCREEN_CONNECTOR_EVENT_TYPE_REMOVE,
+ AUL_SCREEN_CONNECTOR_EVENT_TYPE_UPDATE,
+ AUL_SCREEN_CONNECTOR_EVENT_TYPE_FOCUS,
+} aul_screen_connector_event_type_e;
+
+typedef enum {
+ AUL_SCREEN_STATUS_RESUME,
+ AUL_SCREEN_STATUS_PRE_RESUME,
+ AUL_SCREEN_STATUS_PAUSE,
+} aul_screen_status_e;
+
+typedef void (*aul_screen_viewer_cb)(const char *appid,
+ const char *instance_id, const int pid,
+ const unsigned int surface_id,
+ aul_screen_connector_event_type_e event_type, void *data);
+
+typedef struct aul_screen_viewer_s *aul_screen_viewer_h;
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_screen_connector_add_app_screen(const char *instance_id,
+ unsigned int surf);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_screen_connector_remove_app_screen(const char *instance_id);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_screen_connector_send_update_request(const char *appid,
+ const char *instance_id);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_screen_connector_add_screen_viewer(aul_screen_viewer_cb callback,
+ aul_screen_type_e type, bool priv,
+ void *data, aul_screen_viewer_h *handle);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_screen_connector_remove_screen_viewer(aul_screen_viewer_h handle);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_screen_connector_get_appid_by_surface_id(unsigned int surface_id,
+ char **appid);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_screen_connector_get_instance_id_by_surface_id(unsigned int surface_id,
+ char **instance_id);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_screen_connector_update_screen_viewer_status(aul_screen_status_e status,
+ unsigned int provider_surf);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_screen_connector_trigger_focused_force(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __AUL_SCREEN_CONNECTOR_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
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
+#include <unistd.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <stdbool.h>
+#include <bundle.h>
+
+#include <aul_cmd.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define AUL_SOCK_MAXBUFF 131071
+#define ELOCALLAUNCH_ID 128
+#define EILLEGALACCESS 127
+#define ETERMINATING 126
+#define ENOLAUNCHPAD 125
+#define EREJECTED 123
+
+#define AUL_PKT_HEADER_SIZE (sizeof(int) + sizeof(int) + sizeof(int))
+
+typedef struct _app_pkt_t {
+ int cmd;
+ int len;
+ int opt;
+ unsigned char data[1];
+} app_pkt_t;
+
+typedef enum {
+ AUL_SOCK_NONE = 0x0, /* default */
+ AUL_SOCK_NOREPLY = 0x1, /* return immediately after packet sent without reply */
+ AUL_SOCK_ASYNC = 0x2, /* leave fd in open and return fd of client socket */
+ AUL_SOCK_QUEUE = 0x4, /* add request to pending list in case of receiver is busy */
+ AUL_SOCK_BUNDLE = 0x8, /* has bundle */
+} aul_sock_opt_e;
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_sock_create_server(int pid, uid_t uid);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_sock_send_raw(int pid, uid_t uid, int cmd, unsigned char *kb_data, int datalen, int opt);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_sock_send_bundle(int pid, uid_t uid, int cmd, bundle *kb, int opt);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_sock_send_raw_with_fd(int fd, int cmd, unsigned char *kb_data, int datalen, int opt);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_sock_send_bundle_with_fd(int fd, int cmd, bundle *kb, int opt);
+
+/*
+ * This API is only for Appfw internally.
+ */
+app_pkt_t *aul_sock_recv_pkt(int fd, int *clifd, struct ucred *cr);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_sock_create_launchpad_client(const char *pad_type, uid_t uid);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_sock_recv_reply_sock_fd(int fd, int (*ret_fd)[2], int num_of_ret_fd);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_sock_recv_reply_pkt(int fd, app_pkt_t **pkt);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_sock_set_sock_option(int fd, int cli);
+
+/*
+ * This API is only for Appfw internally.
+ */
+struct timeval aul_sock_get_rcv_timeval(void);
+
+/*
+ * This API in only for Appfw internally.
+ */
+int aul_sock_recv_pkt_with_cb(int fd,
+ void (*callback)(app_pkt_t *pkt, void *data),
+ void *user_data);
+
+/*
+ * This API in only for Appfw internally.
+ */
+int aul_sock_recv_result_with_fd(int fd);
+
+/*
+ * This API in only for Appfw internally.
+ */
+int aul_sock_destroy_server(int fd);
+
+/**
+ * This API is only for Appfw internally.
+ */
+int aul_sock_send_result(int fd, int res);
+
+/**
+ * This API is only for Appfw internally.
+ */
+int aul_sock_send_result_v2(int fd, int res, bool do_close);
+
+/**
+ * This API is only for Appfw internally.
+ */
+int aul_sock_recv_reply_pkt_v2(int fd, app_pkt_t **pkt, bool do_close);
+
+/**
+ * This API is only for Appfw internally.
+ */
+int aul_sock_create_launchpad_client_without_timeout(const char *pad_type, uid_t uid);
+
+/**
+ * This API is only for Appfw internally.
+ */
+int aul_sock_send_raw_data(int fd, unsigned char *raw_data, size_t length, bool do_close);
+
+#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
+
+#include <bundle.h>
+#include <sys/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef AUL_DEPRECATED_API
+#define AUL_DEPRECATED_API __attribute__((__visibility__("default"), deprecated))
+#endif
+
+/** AUL_SVC OPERATION TYPE*/
+#define AUL_SVC_OPERATION_DEFAULT "http://tizen.org/appcontrol/operation/default"
+/** AUL_SVC OPERATION TYPE*/
+#define AUL_SVC_OPERATION_EDIT "http://tizen.org/appcontrol/operation/edit"
+/** AUL_SVC OPERATION TYPE*/
+#define AUL_SVC_OPERATION_VIEW "http://tizen.org/appcontrol/operation/view"
+/** AUL_SVC OPERATION TYPE*/
+#define AUL_SVC_OPERATION_PICK "http://tizen.org/appcontrol/operation/pick"
+/** AUL_SVC OPERATION TYPE*/
+#define AUL_SVC_OPERATION_CREATE_CONTENT "http://tizen.org/appcontrol/operation/create_content"
+/** AUL_SVC OPERATION TYPE*/
+#define AUL_SVC_OPERATION_CALL "http://tizen.org/appcontrol/operation/call"
+/** AUL_SVC OPERATION TYPE*/
+#define AUL_SVC_OPERATION_SEND "http://tizen.org/appcontrol/operation/send"
+/** AUL_SVC OPERATION TYPE*/
+#define AUL_SVC_OPERATION_SEND_TEXT "http://tizen.org/appcontrol/operation/send_text"
+/** AUL_SVC OPERATION TYPE*/
+#define AUL_SVC_OPERATION_DIAL "http://tizen.org/appcontrol/operation/dial"
+/** AUL_SVC OPERATION TYPE*/
+#define AUL_SVC_OPERATION_SEARCH "http://tizen.org/appcontrol/operation/search"
+/** AUL_SVC OPERATION TYPE*/
+#define AUL_SVC_OPERATION_DOWNLOAD "http://tizen.org/appcontrol/operation/download"
+/** AUL_SVC OPERATION TYPE*/
+#define AUL_SVC_OPERATION_SHARE "http://tizen.org/appcontrol/operation/share"
+/** AUL_SVC OPERATION TYPE*/
+#define AUL_SVC_OPERATION_MULTI_SHARE "http://tizen.org/appcontrol/operation/multi_share"
+/** AUL_SVC OPERATION TYPE*/
+#define AUL_SVC_OPERATION_SHARE_TEXT "http://tizen.org/appcontrol/operation/share_text"
+/** AUL_SVC_OPERATION_TYPE*/
+#define AUL_SVC_OPERATION_COMPOSE "http://tizen.org/appcontrol/operation/compose"
+/** AUL_SVC OPERATION TYPE*/
+#define AUL_SVC_OPERATION_LOCATION "http://tizen.org/appcontrol/operation/configure/location"
+/** AUL_SVC OPERATION TYPE*/
+#define AUL_SVC_OPERATION_FONT_TYPE "http://tizen.org/appcontrol/operation/configure/font/type"
+/** AUL_SVC OPERATION TYPE*/
+#define AUL_SVC_OPERATION_FONT_SIZE "http://tizen.org/appcontrol/operation/configure/font/size"
+#define AUL_SVC_OPERATION_LAUNCH_ON_EVENT "http://tizen.org/appcontrol/operation/launch_on_event"
+
+
+
+/** AUL_SVC DATA SUBJECT*/
+#define AUL_SVC_DATA_SUBJECT "http://tizen.org/appcontrol/data/subject"
+/** AUL_SVC DATA TYPE*/
+#define AUL_SVC_DATA_TO "http://tizen.org/appcontrol/data/to"
+/** AUL_SVC DATA TYPE*/
+#define AUL_SVC_DATA_CC "http://tizen.org/appcontrol/data/cc"
+/** AUL_SVC DATA TYPE*/
+#define AUL_SVC_DATA_BCC "http://tizen.org/appcontrol/data/bcc"
+/** AUL_SVC DATA TYPE*/
+#define AUL_SVC_DATA_TEXT "http://tizen.org/appcontrol/data/text"
+/** AUL_SVC DATA TYPE*/
+#define AUL_SVC_DATA_TITLE "http://tizen.org/appcontrol/data/title"
+/** AUL_SVC DATA TYPE*/
+#define AUL_SVC_DATA_SELECTED "http://tizen.org/appcontrol/data/selected"
+/** AUL_SVC DATA TYPE*/
+#define AUL_SVC_DATA_KEYWORD "http://tizen.org/appcontrol/data/keyword"
+/** AUL_SVC DATA TYPE*/
+#define AUL_SVC_DATA_PATH "http://tizen.org/appcontrol/data/path"
+/** AUL_SVC DATA TYPE*/
+#define AUL_SVC_DATA_SELECTION_MODE "http://tizen.org/appcontrol/data/selection_mode"
+/** AUL_SVC DATA TYPE*/
+#define AUL_SVC_DATA_RETURN_RESULT "http://tizen.org/appcontrol/data/return_result"
+
+/** AUL SVC internal private key */
+#define AUL_SVC_K_URI_R_INFO "__AUL_SVC_URI_R_INFO__"
+
+#define AUL_SVC_K_SELECTOR_EXTRA_LIST "http://tizen.org/appcontrol/data/selector_extra_list"
+
+/** AUL SVC internal private key */
+#define AUL_SVC_OPERATION_LAUNCH_WIDGET "http://tizen.org/appcontrol/operation/launch_widget"
+
+#ifdef _APPFW_FEATURE_MULTI_INSTANCE
+#define AUL_SVC_K_MULTI_INSTANCE "multi_instance"
+#endif
+
+#define APP_SELECTOR "org.tizen.app-selector"
+#define SHARE_PANEL "org.tizen.share-panel"
+
+/** Internal operation for launching application which is other zone */
+#define AUL_SVC_OPERATION_JUMP "http://tizen.org/appcontrol/operation/jump"
+#define AUL_SVC_K_JUMP_ZONE_NAME "__K_JUMP_DOMAIN_NAME__"
+#define AUL_SVC_K_JUMP_ORIGIN_OPERATION "__K_JUMP_ORIGIN_OPERATION__"
+#define AUL_SVC_K_FOCUS_ZONE "__K_FOCUS_ZONE__"
+#define AUL_SVC_K_LAUNCH_RESULT_APP_STARTED "__K_LAUNCH_RESULT_APP_STARTED__"
+#define AUL_SVC_K_CAN_BE_LEADER "__K_CAN_BE_LEADER__"
+#define AUL_SVC_K_REROUTE "__K_REROUTE__"
+#define AUL_SVC_K_SHIFT_WINDOW "__K_SHIFT_WINDOW"
+#define AUL_SVC_K_RECYCLE "__K_RECYCLE"
+#define AUL_SVC_K_RELOCATE_BELOW "__K_RELOCATE_BELOW"
+#define AUL_SVC_K_BG_LAUNCH "__K_BG_LAUNCH"
+#define AUL_SVC_K_SPLASH_SCREEN "__K_SPLASH_SCREEN"
+#define AUL_SVC_K_ALIAS_INFO "__K_ALIAS_INFO"
+
+#define PAD_LOADER_ID_DIRECT 1
+
+/**
+ * @brief Return values in appsvc.
+ */
+typedef enum _aul_svc_return_val {
+ AUL_SVC_RET_ETIMEOUT = -10, /**< Timeout */
+ AUL_SVC_RET_ENOMEM = -9, /**< Out of memory */
+ AUL_SVC_RET_ECANCELED = -8, /**< Operation is canceled */
+ AUL_SVC_RET_EREJECTED = -7, /**< application launch rejected */
+ AUL_SVC_RET_ETERMINATING = -6, /**< application terminating */
+ AUL_SVC_RET_EILLACC = -5, /**< Illegal Access */
+ AUL_SVC_RET_ELAUNCH = -4, /**< Failure on launching the app */
+ AUL_SVC_RET_ENOMATCH = -3, /**< No matching result Error */
+ AUL_SVC_RET_EINVAL = -2, /**< Invalid argument */
+ AUL_SVC_RET_ERROR = -1, /**< General error */
+ AUL_SVC_RET_OK = 0, /**< General success */
+} aul_svc_return_val;
+
+
+/**
+ * @brief result values in appsvc.
+ */
+typedef enum _aul_svc_result_val {
+ AUL_SVC_RES_CANCEL = -2, /**< Cancel by system */
+ AUL_SVC_RES_NOT_OK = -1, /**< Fail by user */
+ AUL_SVC_RES_OK = 0 /**< Success by user */
+} aul_svc_result_val;
+
+
+/**
+ * @brief aul_svc_res_fn is appsvc result function
+ * @param[out] b result bundle
+ * @param[out] request_code request code
+ * @param[out] result result value
+ * @param[out] data user-supplied data
+*/
+typedef void (*aul_svc_res_fn)(bundle *b, int request_code, aul_svc_result_val result, void *data);
+
+/**
+ * @brief Called when the result of the launch request is delivered.
+ *
+ * @param[in] request_code The request code
+ * @param[in] result The result, the process ID of the callee on success otherwise a negative error value
+ * @param[in] user_data The user data passed from the callback registration function
+ */
+typedef void (*aul_svc_err_cb)(int request_code, int result, void *user_data);
+
+/**
+ * @brief iterator function running with aul_svc_get_list
+ * @param[out] appid appid retreived by aul_svc_get_list
+ * @param[out] data user-supplied data
+*/
+typedef int (*aul_svc_info_iter_fn)(const char *appid, void *data);
+
+typedef int (*aul_svc_host_res_fn)(void *data);
+
+/**
+ * @par Description:
+ * This function sets an operation to launch application based on appsvc.
+ *
+ * @param[in] b bundle object
+ * @param[in] operation operation
+ *
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_SVC_RET_OK - success
+ * @retval AUL_SVC_RET_ERROR - general error
+ * @retval AUL_SVC_RET_EINVAL - invalid argument(content)
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks An application must call this function before using aul_svc_run_service API.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ bundle *b = NULL;
+
+ b = bundle_create();
+
+ aul_svc_set_operation(b, AUL_SVC_OPERATION_VIEW);
+}
+ * @endcode
+ *
+ */
+int aul_svc_set_operation(bundle *b, const char *operation);
+
+/**
+ * @par Description:
+ * This function sets an uri to launch application based on appsvc.
+ *
+ * @param[in] b bundle object
+ * @param[in] uri uri
+ *
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_SVC_RET_OK - success
+ * @retval AUL_SVC_RET_ERROR - general error
+ * @retval AUL_SVC_RET_EINVAL - invalid argument(content)
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ bundle *b = NULL;
+
+ b = bundle_create();
+
+ aul_svc_set_operation(b, AUL_SVC_OPERATION_VIEW);
+ aul_svc_set_uri(b,"http://www.samsung.com");
+}
+ * @endcode
+ *
+ */
+int aul_svc_set_uri(bundle *b, const char *uri);
+
+/**
+ * @par Description:
+ * This function sets a mime-type to launch application based on appsvc.
+ *
+ * @param[in] b bundle object
+ * @param[in] mime mime-type
+ *
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_SVC_RET_OK - success
+ * @retval AUL_SVC_RET_ERROR - general error
+ * @retval AUL_SVC_RET_EINVAL - invalid argument(content)
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ bundle *b = NULL;
+
+ b = bundle_create();
+
+ aul_svc_set_operation(b, AUL_SVC_OPERATION_PICK);
+ aul_svc_set_mime(b,"image/jpg");
+}
+ * @endcode
+ *
+ */
+int aul_svc_set_mime(bundle *b, const char *mime);
+
+/**
+ * @par Description:
+ * This function sets an extra data to launch application based on appsvc.
+ *
+ * @param[in] b bundle object
+ * @param[in] key key of extra data
+ * @param[in] val data
+ *
+ * @return 0 if success, negative value(<0) if fail
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ bundle *b = NULL;
+
+ b = bundle_create();
+
+ aul_svc_set_operation(b, AUL_SVC_OPERATION_SEND);
+ aul_svc_set_uri(b,"mailto:xxx1@xxx");
+ aul_svc_add_data(b,AUL_SVC_DATA_CC,"xxx2@xxx");
+}
+ * @endcode
+ *
+ */
+int aul_svc_add_data(bundle *b, const char *key, const char *val);
+
+/**
+ * @par Description:
+ * This function sets an extra array data to launch application based on appsvc.
+ *
+ * @param[in] b bundle object
+ * @param[in] key key of extra data
+ * @param[in] val_array data
+ * @param[in] len Length of array
+ *
+ * @return 0 if success, negative value(<0) if fail
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ bundle *b = NULL;
+ char *images[] = {"/opt/media/a.jpg", "/opt/media/b.jpg", "/opt/media/c.jpg"};
+
+ b = bundle_create();
+
+ aul_svc_add_data_array(b, AUL_SVC_DATA_SELECTED, images, 3);
+}
+ * @endcode
+ *
+ */
+int aul_svc_add_data_array(bundle *b, const char *key, const char **val_array, int len);
+
+
+/**
+ * @par Description:
+ * This function sets a package name to launch application based on appsvc.
+ *
+ * @param[in] b bundle object
+ * @param[in] pkg_name package name for explict launch
+ *
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_SVC_RET_OK - success
+ * @retval AUL_SVC_RET_ERROR - general error
+ * @retval AUL_SVC_RET_EINVAL - invalid argument(content)
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ bundle *b = NULL;
+
+ b = bundle_create();
+
+ aul_svc_set_operation(b, AUL_SVC_OPERATION_PICK);
+ aul_svc_set_mime(b,"image/jpg");
+ aul_svc_set_pkgname(b, "org.tizen.mygallery");
+}
+ * @endcode
+ *
+ */
+/* Deprecated API */
+int aul_svc_set_pkgname(bundle *b, const char *pkg_name); // __attribute__((deprecated));
+
+
+/**
+ * @par Description:
+ * This function sets a appid to launch application based on appsvc.
+ *
+ * @param[in] b bundle object
+ * @param[in] appid application id for explict launch
+ *
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_SVC_RET_OK - success
+ * @retval AUL_SVC_RET_ERROR - general error
+ * @retval AUL_SVC_RET_EINVAL - invalid argument(content)
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ bundle *b = NULL;
+
+ b = bundle_create();
+
+ aul_svc_set_operation(b, AUL_SVC_OPERATION_PICK);
+ aul_svc_set_mime(b,"image/jpg");
+ aul_svc_set_appid(b, "org.tizen.mygallery");
+}
+ * @endcode
+ *
+ */
+int aul_svc_set_appid(bundle *b, const char *appid);
+
+
+/**
+ * @par Description:
+ * This function sets a appid to launch application based on appsvc.
+ *
+ * @param[in] b bundle object
+ * @param[in] application category
+ *
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_SVC_RET_OK - success
+ * @retval AUL_SVC_RET_ERROR - general error
+ * @retval AUL_SVC_RET_EINVAL - invalid argument(content)
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ bundle *b = NULL;
+
+ b = bundle_create();
+
+ aul_svc_set_operation(b, AUL_SVC_OPERATION_VIEW);
+ aul_svc_set_category(b, "http://tizen.org/category/app/browser");
+}
+ * @endcode
+ *
+ */
+int aul_svc_set_category(bundle *b, const char *category);
+
+/**
+ * @par Description:
+ * This API launch application based on appsvc.
+ *
+ * @param[in] b bundle to be passed to callee
+ * @param[in] request_code request code
+ * @param[in] cbfunc result callback function
+ * @param[in] data user-supplied data passed to callback function
+ *
+ * @return callee's pid if success, negative value(<0) if fail
+ * @retval callee's pid - success
+ * @retval AUL_SVC_RET_ERROR - general error
+ * @retval AUL_SVC_RET_EINVAL - invalid argument(content)
+ * @retval AUL_SVC_RET_ENOMATCH - no matching result Error
+ * @retval AUL_SVC_RET_ELAUNCH - failure on launching the app
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ bundle *b = NULL;
+ static int num = 0;
+
+ b = bundle_create();
+
+ aul_svc_set_operation(b, AUL_SVC_OPERATION_PICK);
+ aul_svc_set_mime(b,"image/jpg");
+
+ return aul_svc_run_service(b, 0, cb_func, (void*)NULL);
+}
+ * @endcode
+ *
+ */
+int aul_svc_run_service(bundle *b, int request_code, aul_svc_res_fn cbfunc, void *data);
+int aul_svc_run_service_for_uid(bundle *b, int request_code,
+ aul_svc_res_fn cbfunc, void *data, uid_t uid);
+
+/**
+ * @par Description:
+ * This API use to get application list that is matched with given bundle.
+ *
+ * @param[in] b bundle to resolve application
+ * @param[in] iter_fn iterator function
+ * @param[in] data user-supplied data for iter_fn
+ *
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_SVC_RET_OK - success
+ * @retval AUL_SVC_RET_EINVAL - invalid argument(content)
+ * @retval AUL_SVC_RET_ENOMATCH - no matching result Error
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+static int iter_fn(const char* appid, void *data)
+{
+ printf("\t==========================\n");
+ printf("\t appid: %s\n", appid);
+ printf("\t==========================\n");
+ return 0;
+}
+
+...
+{
+ bundle *b = NULL;
+ static int num = 0;
+
+ b = bundle_create();
+
+ aul_svc_set_operation(b, AUL_SVC_OPERATION_PICK);
+ aul_svc_set_mime(b,"image/jpg");
+
+ return aul_svc_get_list(b, iter_fn, (void*)NULL);
+}
+ * @endcode
+ *
+ */
+int aul_svc_get_list(bundle *b, aul_svc_info_iter_fn iter_fn, void *data);
+int aul_svc_get_list_for_uid(bundle *b, aul_svc_info_iter_fn iter_fn,
+ void *data, uid_t uid);
+
+/**
+ * @par Description:
+ * This API use to get default applications
+ *
+ * @param[in] iter_fn iterator function
+ * @param[in] data user-supplied data for iter_fn
+ *
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_SVC_RET_OK - success
+ * @retval AUL_SVC_RET_EINVAL - invalid argument(content)
+ * @retval AUL_SVC_RET_ENOMATCH - no matching result Error
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+static int iter_fn(const char* appid, void *data)
+{
+ printf("\t==========================\n");
+ printf("\t appid : %s\n", appid);
+ printf("\t==========================\n");
+ return 0;
+}
+
+...
+{
+ return aul_svc_get_all_defapps(iter_fn, (void*)NULL);
+}
+ * @endcode
+ *
+ */
+int aul_svc_get_all_defapps(aul_svc_info_iter_fn iter_fn, void *data);
+int aul_svc_get_all_defapps_for_uid(aul_svc_info_iter_fn iter_fn,
+ void *data, uid_t uid);
+
+/**
+ * @par Description:
+ * This function gets a operation from bundle.
+ *
+ * @param[in] b bundle object
+ *
+ * @return Pointer for operation string if success, NULL if fail
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ char *val;
+ val = aul_svc_get_operation(b);
+}
+ * @endcode
+ *
+ */
+const char *aul_svc_get_operation(bundle *b);
+
+/**
+ * @par Description:
+ * This function gets a uri from bundle.
+ *
+ * @param[in] b bundle object
+ *
+ * @return Pointer for uri string if success, NULL if fail
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ char *val;
+ val = aul_svc_get_uri(b);
+}
+ * @endcode
+ *
+ */
+const char *aul_svc_get_uri(bundle *b);
+
+/**
+ * @par Description:
+ * This function gets a mime-type from bundle.
+ *
+ * @param[in] b bundle object
+ *
+ * @return Pointer for mime-type string if success, NULL if fail
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ char *val;
+ val = aul_svc_get_mime(b);
+}
+ * @endcode
+ *
+ */
+const char *aul_svc_get_mime(bundle *b);
+
+/**
+ * @par Description:
+ * This function gets a package name from bundle.
+ *
+ * @param[in] b bundle object
+ *
+ * @return Pointer for package name string if success, NULL if fail
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ char *val;
+ val = aul_svc_get_pkgname(b);
+}
+ * @endcode
+ *
+ */
+/* Deprecated API */
+const char *aul_svc_get_pkgname(bundle *b); // __attribute__((deprecated));
+
+/**
+ * @par Description:
+ * This function gets a application id from bundle.
+ *
+ * @param[in] b bundle object
+ *
+ * @return Pointer for application id string if success, NULL if fail
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ char *val;
+ val = aul_svc_get_appid(b);
+}
+ * @endcode
+ *
+ */
+const char *aul_svc_get_appid(bundle *b);
+
+/**
+ * @par Description:
+ * This function gets a application category from bundle.
+ *
+ * @param[in] b bundle object
+ *
+ * @return Pointer for application category string if success, NULL if fail
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ char *val;
+ val = aul_svc_get_category(b);
+}
+ * @endcode
+ *
+ */
+const char *aul_svc_get_category(bundle *b);
+
+/**
+ * @par Description:
+ * This function gets value from key.
+ *
+ * @param[in] b bundle object
+ * @param[in] key key
+ *
+ * @return Pointer for value string if success, NULL if fail
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ char *val;
+ val = aul_svc_get_data(b, AUL_SVC_DATA_CC);
+}
+ * @endcode
+ *
+ */
+const char *aul_svc_get_data(bundle *b, const char *key);
+
+/**
+ * @par Description:
+ * This function gets value from key.
+ *
+ * @param[in] b bundle object
+ * @param[in] key key
+ * @param[out] len length of array
+ *
+ * @return Pointer for value string array if success, NULL if fail
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ char **val_array;
+ int len;
+ char *val;
+
+ if(aul_svc_data_is_array(b, AUL_SVC_DATA_SELECTED))
+ val_array = aul_svc_get_data_array(b, AUL_SVC_DATA_SELECTED, &len);
+ else
+ val = aul_svc_get_data(b, AUL_SVC_DATA_SELECTED);
+}
+ * @endcode
+ *
+ */
+const char **aul_svc_get_data_array(bundle *b, const char *key, int *len);
+
+/**
+ * @par Description:
+ * This API create appsvc result bundle based on bundle received in reset event.
+ *
+ * @param[in] inb bundle received in reset event
+ * @param[in] outb bundle to use for returning result
+ *
+ * @retval AUL_SVC_RET_OK - success
+ * @retval AUL_SVC_RET_ERROR - general error
+ * @retval AUL_SVC_RET_EINVAL - invalid argument(content)
+ *
+ * @pre None.
+ * @post None.
+ * @see aul_svc_send_result.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ struct appdata *ad = data;
+ bundle* res_bundle;
+
+ aul_svc_create_result_bundle(ad->b,&res_bundle);
+ bundle_add(res_bundle, "result", "1");
+ aul_svc_send_result(res_bundle, 0);
+}
+ * @endcode
+ *
+ */
+int aul_svc_create_result_bundle(bundle *inb, bundle **outb);
+
+/**
+ * @par Description:
+ * This API send appsvc result to caller with bundle.
+ *
+ * @param[in] b Result data in bundle format
+ * @param[in] result result value
+ *
+ * @retval AUL_SVC_RET_OK - success
+ * @retval AUL_SVC_RET_ERROR - general error
+ * @retval AUL_SVC_RET_EINVAL - invalid argument(content)
+ *
+ * @pre aul_svc_create_result_bundle.
+ * @post None.
+ * @see aul_svc_send_result.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ struct appdata *ad = data;
+ bundle* res_bundle;
+
+ aul_svc_create_result_bundle(ad->b,&res_bundle);
+ bundle_add(res_bundle, "result", "1");
+ aul_svc_send_result(res_bundle, 0);
+}
+ * @endcode
+ *
+ */
+int aul_svc_send_result(bundle *b, aul_svc_result_val result);
+
+/**
+ * @par Description:
+ * This API ask a extra data is array or not.
+ *
+ * @param[in] b bundle object
+ * @param[in] key key of extra data
+ * @return true / false
+ * @retval 1 a extra data is array.
+ * @retval 0 a extra data is not array.
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+ ...
+
+ * int aul_svc_data_is_array(bundle *b, char *key)
+ * {
+ * return aul_svc_data_is_array(b, key);
+ * }
+ *
+ * @endcode
+ * @remark
+ * None
+*
+*/
+int aul_svc_data_is_array(bundle *b, const char *key);
+
+int aul_svc_subapp_terminate_request_pid(int pid);
+
+/**
+ * @par Description:
+ * This function sets an uri to launch application based on appsvc.
+ *
+ * @param[in] b bundle object
+ * @param[in] char *mode
+ *
+ * @return 0 if success, negative value(<0) if fail
+ * @retval AUL_SVC_RET_OK - success
+ * @retval AUL_SVC_RET_ERROR - general error
+ * @retval AUL_SVC_RET_EINVAL - invalid argument(content)
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ aul_svc_set_launch_mode(app_control->data, mode);
+}
+ * @endcode
+ *
+ */
+int aul_svc_set_launch_mode(bundle *b, const char *mode);
+
+/**
+ * @par Description:
+ * This function sets an uri to launch application based on appsvc.
+ *
+ * @param[in] b bundle object
+ *
+ * @return Pointer for launch mode string if success, NULL if fail
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <aul_svc.h>
+
+...
+{
+ aul_svc_get_launch_mode(app_control->data);
+}
+ * @endcode
+ *
+ */
+const char *aul_svc_get_launch_mode(bundle *b);
+
+int aul_svc_allow_transient_app(bundle *b, int wid);
+
+int aul_svc_request_transient_app(bundle *b, int callee_wid,
+ aul_svc_host_res_fn cbfunc, void *data);
+
+int aul_svc_subscribe_launch_result(bundle *b, const char *event);
+
+/**
+ * @par Description:
+ * This function sets loader ID into bundle.
+ *
+ * @param[in] b Bundle object
+ * @param[in] loader_id Loader ID from aul_add_loader() or PAD_LOADER_ID_DIRECT to launch apps without loader
+ *
+ * @return 0 if success, negative value(<0) if fail
+ * @see aul_add_loader, aul_remove_loader
+ * @remarks This API is only for Appfw internally.
+ */
+int aul_svc_set_loader_id(bundle *b, int loader_id);
+
+/**
+ * @par Description:
+ * This function sets loader name into bundle. Launchpad will assign a static slot to launch an app.
+ *
+ * @param[in] b Bundle object
+ * @param[in] loader_name Loader name to assign
+ *
+ * @return 0 if success, negative value(<0) if fail
+ * @remarks This API is only for Appfw internally.
+ */
+int aul_svc_set_loader_name(bundle *b, const char *loader_name);
+
+/**
+ * @par Description:
+ * This API sets the background launch mode.
+ * If the background launch mode is enabled, a window of the callee process doesn't appear on the screen.
+ *
+ * @param[in] b Bundle object
+ * @param[in] enabled boolean (true / false)
+ *
+ * @return 0 if success, negative value(<0) if fail
+ * @remarks This API is only for Appfw internally.
+ */
+int aul_svc_set_background_launch(bundle *b, int enabled);
+
+/**
+ * @par Description:
+ * This API gets an application ID by an alias application ID.
+ *
+ * @param[in] alias_appid An alias application ID
+ * @param[out] appid An application ID
+ *
+ * @return 0 if success, negative value(<0) if fail
+ */
+int aul_svc_get_appid_by_alias_appid(const char *alias_appid, char **appid);
+int aul_svc_get_appid_by_alias_appid_for_uid(const char *alias_appid,
+ char **appid, uid_t uid);
+
+/**
+ * @par Description:
+ * Gets the instance ID.
+ *
+ * @param[in] b Bundle object
+ *
+ * @return Pointer for application id string if success, NULL if fail
+ */
+const char *aul_svc_get_instance_id(bundle *b);
+
+/**
+ * @par Description:
+ * Sets the instance ID.
+ *
+ * @param[in] b Bundle object
+ * @param[in] instance ID Instance ID
+ *
+ * @return 0 if success, negative value(<0) if fail
+ */
+int aul_svc_set_instance_id(bundle *b, const char *instance_id);
+
+/**
+ * @par Description:
+ * Sends the launch request asynchronous.
+ *
+ * @param[in] b Bundle object
+ * @param[in] request_code Request Code
+ * @param[in] cbfunc Callback function
+ * @param[in] data User data
+ *
+ * @return a pid of the callee on success,
+ * otherwise a negative error value
+ */
+int aul_svc_run_service_async(bundle *b, int request_code,
+ aul_svc_res_fn cbfunc, void *data);
+int aul_svc_run_service_async_for_uid(bundle *b, int request_code,
+ aul_svc_res_fn cbfunc, void *data, uid_t uid);
+
+
+/**
+ * @brief Sends the launch request asynchronous.
+ *
+ * @param[in] b The bundle object
+ * @param[in] request_code The request code
+ * @param[in] cbfunc The reply callback function
+ * @param[in] err_cb The result callback function
+ * @param[in] user_data The user data to be passed to the callback function
+ *
+ * @return a pid of the callee on success,
+ * otherwise a negative error value
+ */
+int aul_svc_send_launch_request(bundle *b, int request_code,
+ aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb,
+ void *user_data);
+
+/**
+ * @brief Sends the launch request asynchronous.
+ *
+ * @param[in] b The bundle object
+ * @param[in] request_code The request code
+ * @param[in] cbfunc The reply callback function
+ * @param[in] err_cb The result callback function
+ * @param[in] user_data The user data to be passed to the callback function
+ * @param[in] uid The user ID
+ *
+ * @return a pid of the callee on success,
+ * otherwise a negative error value
+ */
+int aul_svc_send_launch_request_for_uid(bundle *b, int request_code,
+ aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb,
+ void *user_data, uid_t uid);
+
+/**
+ * @brief Sends the launch request synchronous.
+ *
+ * @param[in] b The bundle object
+ * @param[in] request_code The request code
+ * @param[out] res_b The bundle object
+ * @param[out] res The result
+ * @param[in] uid The user ID
+ *
+ * @return a pid of the callee on success,
+ * otherwise a negative error value
+ */
+int aul_svc_send_launch_request_sync_for_uid(bundle *b, int request_code,
+ bundle **res_b, aul_svc_result_val *res, uid_t uid);
+
+/**
+ * @brief Sets the ID of the caller instance.
+ * @since_tizen 5.5
+ *
+ * @param[in] b The bundle object
+ * @param[in] instance_id The ID of the caller instance
+ *
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ */
+int aul_svc_set_caller_instance_id(bundle *b, const char *instance_id);
+
+/**
+ * @brief Sets the ID of the component.
+ * @since_tizen 5.5
+ *
+ * @param[in] b The bundle object
+ * @param[in] comp_id The ID of the component
+ *
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ */
+int aul_svc_set_comp_id(bundle *b, const char *comp_id);
+
+/**
+ * @brief Gets the ID of the component.
+ * @since_tizen 5.5
+ *
+ * @param[in] b The bundle object
+ *
+ * @return @c a component ID on success,
+ * otherwise a nullptr
+ */
+const char *aul_svc_get_comp_id(bundle *b);
+
+/**
+ * This API is only for App Framework internally.
+ */
+int aul_svc_subapp_terminate_request(bundle *b, int pid);
+
+/**
+ * @brief Sends the resumption request asynchronoulsy.
+ * @since_tizen 5.5
+ *
+ * @param[in] b The bundle object
+ * @param[in] request code The request code
+ * @param[in] err_cb The result callback function
+ * @param[in] user_data The user data to be passed to the callback function
+ *
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ */
+int aul_svc_send_resume_request(bundle *b, int request_code,
+ aul_svc_err_cb err_cb, void *user_data);
+int aul_svc_send_resume_request_for_uid(bundle *b, int request_code,
+ aul_svc_err_cb err_cb, void *user_data, uid_t uid);
+
+/**
+ * @par Description:
+ * This function sets window position into bundle.
+ *
+ * @param[in] b Bundle object
+ * @param[in] x x position of window
+ * @param[in] y y position of window
+ * @param[in] w width of window
+ * @param[in] h height of window
+ *
+ * @return 0 if success, negative value(<0) if fail
+ * @see aul_svc_get_window_position
+ * @remarks This API is only for Appfw internally.
+ */
+int aul_svc_set_window_position(bundle *b, int x, int y, int w, int h);
+
+/**
+ * @par Description:
+ * This function gets window position into bundle.
+ *
+ * @param[in] b Bundle object
+ * @param[out] x x position of window
+ * @param[out] y y position of window
+ * @param[out] w width of window
+ * @param[out] h height of window
+ *
+ * @return 0 if success, negative value(<0) if fail
+ * @see aul_svc_set_window_position
+ * @remarks This API is only for Appfw internally.
+ */
+int aul_svc_get_window_position(bundle* b, int *x, int *y, int *w, int *h);
+
+/**
+ * @deprecated Deprecated since 6.5.
+ */
+int aul_svc_set_defapp(const char *op, const char *mime_type,
+ const char *uri, const char *defapp) AUL_DEPRECATED_API;
+int aul_svc_set_defapp_for_uid(const char *op, const char *mime_type,
+ const char *uri, const char *defapp, uid_t uid) AUL_DEPRECATED_API;
+
+/**
+ * @deprecated Deprecated since 6.5.
+ */
+int aul_svc_unset_defapp(const char *defapp) AUL_DEPRECATED_API;
+int aul_svc_unset_defapp_for_uid(const char *defapp, uid_t uid) AUL_DEPRECATED_API;
+
+/**
+ * @deprecated Deprecated since 6.5.
+ */
+int aul_svc_unset_all_defapps(void) AUL_DEPRECATED_API;
+int aul_svc_unset_all_defapps_for_uid(uid_t uid) AUL_DEPRECATED_API;
+
+/**
+ * @deprecated Deprecated since 6.5
+ */
+int aul_svc_is_defapp(const char *appid) AUL_DEPRECATED_API;
+int aul_svc_is_defapp_for_uid(const char *pkg_name, uid_t uid) AUL_DEPRECATED_API;
+
+/**
+ * @deprecated Deprecated since 6.5.
+ */
+int aul_svc_set_alias_appid(const char *alias_appid, const char *appid) AUL_DEPRECATED_API;
+int aul_svc_set_alias_appid_for_uid(const char *alias_appid, const char *appid,
+ uid_t uid) AUL_DEPRECATED_API;
+
+/**
+ * @deprecated Deprecated since 6.5.
+ */
+int aul_svc_unset_alias_appid(const char *alias_appid) AUL_DEPRECATED_API;
+int aul_svc_unset_alias_appid_for_uid(const char *alias_appid, uid_t uid) AUL_DEPRECATED_API;
+
+/**
+ * @deprecated Deprecated since 6.5.
+ */
+int aul_svc_foreach_alias_info(
+ void (*callback)(const char *, const char *, void *),
+ void *user_data) AUL_DEPRECATED_API;
+int aul_svc_foreach_alias_info_for_uid(
+ void (*callback)(const char *, const char *, void *),
+ uid_t uid, void *user_data) AUL_DEPRECATED_API;
+
+/**
+ * @deprecated Deprecated since 6.5.
+ */
+int aul_svc_enable_alias_info(const char *appid) AUL_DEPRECATED_API;
+int aul_svc_enable_alias_info_for_uid(const char *appid, uid_t uid) AUL_DEPRECATED_API;
+
+/**
+ * @deprecated Deprecated since 6.5.
+ */
+int aul_svc_disable_alias_info(const char *appid) AUL_DEPRECATED_API;
+int aul_svc_disable_alias_info_for_uid(const char *appid, uid_t uid) AUL_DEPRECATED_API;
+
+/**
+ * @deprecated Deprecated since 6.5.
+ */
+int aul_svc_foreach_alias_info_by_appid(
+ int (*callback)(const char *, const char *, void *),
+ const char *appid, void *user_data) AUL_DEPRECATED_API;
+int aul_svc_foreach_alias_info_by_appid_for_uid(
+ int (*callback)(const char *, const char *, void *),
+ const char *appid, uid_t uid, void *user_data) AUL_DEPRECATED_API;
+
+/**
+ * @deprecated Deprecated since 6.5.
+ */
+int aul_svc_foreach_allowed_info(
+ int (*callback)(const char *, const char *, void *),
+ void *user_data) AUL_DEPRECATED_API;
+int aul_svc_foreach_allowed_info_for_uid(
+ int (*callback)(const char *, const char *, void *),
+ uid_t uid, void *user_data) AUL_DEPRECATED_API;
+
+/**
+ * @deprecated Deprecated since 6.5
+ */
+int aul_svc_foreach_allowed_info_by_appid(
+ int (*callback)(const char *, const char *, void *),
+ const char *appid, void *user_data) AUL_DEPRECATED_API;
+int aul_svc_foreach_allowed_info_by_appid_for_uid(
+ int (*callback)(const char *, const char *, void *),
+ const char *appid, uid_t uid, void *user_data) AUL_DEPRECATED_API;
+
+#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.
+ */
+
+#pragma once
+
+#include <bundle.h>
+#include <sys/types.h>
+
+#include "aul_svc.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief The AUL Service information handle.
+ * @since_tizen 5.5
+ * @remarks This API is only for App Framework internally.
+ */
+typedef void *aul_svc_info_h;
+
+/**
+ * @brief Creates the AUL Service information handle.
+ * @since_tizen 5.5
+ *
+ * @param[in] b The bundle object
+ * @param[out] h The AUL Service information handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_SVC_RET_OK Successful
+ * @retval #AUL_SVC_RET_EINVAL Invalid parameter
+ * @retval #AUL_SVC_RET_ERROR Out of memory
+ */
+int aul_svc_info_create(bundle *b, aul_svc_info_h *h);
+
+/**
+ * @brief Gets the operation to be performed.
+ * @since_tizen 5.5
+ *
+ * @param[in] h The AUL Service information handle
+ * @param[out] operation The operation to be performed
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_SVC_RET_OK Successful
+ * @retval #AUL_SVC_RET_EINVAL Invalid parameter
+ * @retval #AUL_SVC_RET_ERROR Out of memory
+ */
+int aul_svc_info_get_operation(aul_svc_info_h h, char **operation);
+
+/**
+ * @brief Gets the URI of the data.
+ * @since_tizen 5.5
+ *
+ * @param[in] h The AUL Service information handle
+ * @param[out] uri The URI of the data
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_SVC_RET_OK Successful
+ * @retval #AUL_SVC_RET_EINVAL Invalid parameter
+ * @retval #AUL_SVC_RET_ERROR Out of memory
+ */
+int aul_svc_info_get_uri(aul_svc_info_h h, char **uri);
+
+/**
+ * @brief Gets the scheme of the URI.
+ * @since_tizen 5.5
+ *
+ * @param[in] h The AUL Service information handle
+ * @param[out] uri_scheme The scheme of the URI
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_SVC_RET_OK Successful
+ * @retval #AUL_SVC_RET_EINVAL Invalid parameter
+ * @retval #AUL_SVC_RET_ERROR Out of memory
+ */
+int aul_svc_info_get_uri_scheme(aul_svc_info_h h, char **uri_scheme);
+
+/**
+ * @brief Gets the host of the URI.
+ * @since_tizen 5.5
+ *
+ * @param[in] h The AUL Service information handle
+ * @param[out] uri_host The host of the URI
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_SVC_RET_OK Successful
+ * @retval #AUL_SVC_RET_EINVAL Invalid parameter
+ * @retval #AUL_SVC_RET_ERROR Out of memory
+ */
+int aul_svc_info_get_uri_host(aul_svc_info_h h, char **uri_host);
+
+/**
+ * @brief Gets the explicit MIME type of the data.
+ * @since_tizen 5.5
+ *
+ * @param[in] h The AUL Service information handle
+ * @param[out] mime The explicit MIME type of the data
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_SVC_RET_OK Successful
+ * @retval #AUL_SVC_RET_EINVAL Invalid parameter
+ * @retval #AUL_SVC_RET_ERROR Out of memory
+ */
+int aul_svc_info_get_mime(aul_svc_info_h h, char **mime);
+
+/**
+ * @brief Gets the type of the MIME type.
+ * @since_tizen 5.5
+ *
+ * @param[in] h The AUL Service information handle
+ * @param[out] mime_type The type of the MIME type
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_SVC_RET_OK Successful
+ * @retval #AUL_SVC_RET_EINVAL Invalid parameter
+ * @retval #AUL_SVC_RET_ERROR Out of memory
+ */
+int aul_svc_info_get_mime_type(aul_svc_info_h h, char **mime_type);
+
+/**
+ * @brief Gets the subtype of the MIME type.
+ * @since_tizen 5.5
+ *
+ * @param[in] h The AUL Service information handle
+ * @param[out] mime_subtype The subtype of the MIME type
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_SVC_RET_OK Successful
+ * @retval #AUL_SVC_RET_EINVAL Invalid parameter
+ * @retval #AUL_SVC_RET_ERROR Out of memory
+ */
+int aul_svc_info_get_mime_subtype(aul_svc_info_h h, char **mime_subtype);
+
+/**
+ * @brief Destroys the AUL Service information handle.
+ * @since_tizen 5.5
+ *
+ * @param[in] h The AUL Service information handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_SVC_RET_OK Successful
+ * @retval #AUL_SVC_RET_EINVAL Invalid parameter
+ */
+int aul_svc_info_destroy(aul_svc_info_h h);
+
+/**
+ * @brief Resolves the app control.
+ * @since_tizen 6.0
+ * @remarks The @appid_array should be released using aul_svc_free_appid_array().
+ *
+ * @param[in] b The bundle object
+ * @param[in] uid The user ID
+ * @param[out] appid_array The array pointer of the appid
+ * @param[out] len The array length
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @remarks This API is only for App Framework internally.
+ * @see aul_svc_free_appid_array()
+ */
+int aul_svc_resolve(bundle *b, uid_t uid, char ***appid_array,
+ unsigned int *len);
+
+/**
+ * @brief Gets an array of application ID.
+ * @since_tizen 6.0
+ * @remarks The @appid_array should be released using aul_svc_free_appid_array().
+ *
+ * @param[in] b The bundle object
+ * @param[in] uid The user ID
+ * @param[out] appid_array The array pointer of the appid
+ * @param[out] len The array length
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @remarks This API is only for App Framework internally.
+ * @see aul_svc_free_appid_array()
+ */
+int aul_svc_get_appid_array(bundle *b, uid_t uid, char ***appid_array,
+ unsigned int *len);
+
+/**
+ * @brief Release an array of application ID.
+ * @since_tizen 6.0
+ *
+ * @param[in] appid_array The array pointer of the appid
+ * @param[in] len The array length
+ * @remarks This API is only for App Framework internally.
+ */
+void aul_svc_free_appid_array(char **appid_array, unsigned int len);
+
+#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_WATCH_CONTROL_H__
+#define __AUL_WATCH_CONTROL_H__
+
+#include <bundle.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief The watch control handle.
+ * @since_tizen 5.5
+ */
+typedef void *aul_watch_control_h;
+
+/**
+ * @brief Called when another application sends a launch request to the application.
+ * @details Before calling app_control_cb() function, this callback function is called.
+ * @since_tizen 5.5
+ *
+ * @param[in] b The bundle object
+ * @param[in] user_data The user data passed from the callback registration function
+ * @see aul_watch_control_add_handler()
+ *
+ * @remarks This is only for App Framework internally.
+ */
+typedef void (*aul_watch_control_cb)(bundle *b, void *user_data);
+
+/**
+ * @brief Adds the watch control handle.
+ * @since_tizen 5.5
+ *
+ * @param[in] callback The callback function
+ * @param[in] user_data The user data to be passed to the callback function
+ * @param[out] handle The watch control handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @see aul_watch_control_remove_handler()
+ * @see aul_watch_control_cb()
+ *
+ * @remarks This is only for App Framework internally.
+ */
+int aul_watch_control_add_handler(aul_watch_control_cb callback,
+ void *user_data, aul_watch_control_h *handle);
+
+/**
+ * @brief Removes registered watch control handle.
+ * @since_tizen 5.5
+ *
+ * @param[in] handle The watch control handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @see aul_watch_control_add_handler()
+ *
+ * @remarks This is only for App Framework internally.
+ */
+int aul_watch_control_remove_handler(aul_watch_control_h handle);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __AUL_WATCH_CONTROL_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2018 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_WATCHDOG_H__
+#define __AUL_WATCHDOG_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Enables watchdog timer.
+ *
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_watchdog_enable(void);
+
+/**
+ * @brief Disables watchdog timer.
+ *
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_watchdog_disable(void);
+
+/**
+ * @brief Kicks whatchdog timer.
+ *
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_watchdog_kick(void);
+
+/**
+ * @brief Starts watchdog timer.
+ *
+ * @param[in] interval The interval of the timer
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+void aul_watchdog_start(unsigned int interval);
+
+/**
+ * @brief Stops watchdog timer.
+ *
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+void aul_watchdog_stop(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __AUL_WATCHDOG_H__ */
--- /dev/null
+/*
+ * Copyright (c) 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
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @par Description:
+ * Widget information handle.
+ */
+typedef struct aul_widget_info_s *aul_widget_info_h;
+
+/**
+ * @par Description:
+ * Called to get the widget information
+ * @param[in] info The handle of the widget information
+ * @param[in] user_data The user data passed from the foreach function
+ *
+ * @pre aul_widget_info_foreach() will invoke this callback.
+ * @see aul_widget_info_foreach()
+ */
+typedef void (*aul_widget_info_cb)(aul_widget_info_h info, void *user_data);
+
+/**
+ * @par Description:
+ * Retrieves all widget information of running widget applications.
+ * @privlevel platform
+ * @privilege %http://tizen.org/privilege/internal/default/platform
+ * @param[in] callback The callback function to invoke
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @post This function invokes aul_widget_info_cb() for each widget information.
+ * @see aul_widget_info_cb()
+ */
+int aul_widget_info_foreach(aul_widget_info_cb callback, void *user_data);
+int aul_widget_info_foreach_for_uid(aul_widget_info_cb callback,
+ void *user_data, uid_t uid);
+
+/**
+ * @par Description:
+ * Gets the process ID with the given handle.
+ * @param[in] info The handle of the widget information
+ * @param[out] pid The process ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ */
+int aul_widget_info_get_pid(aul_widget_info_h info, pid_t *pid);
+
+/**
+ * @par Description:
+ * Gets the surface ID with the given handle.
+ * @param[in] info The handle of the widget information
+ * @param[out] surf The surface ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ */
+int aul_widget_info_get_surface_id(aul_widget_info_h info, unsigned int *surf);
+
+/**
+ * @par Description:
+ * Gets the widget ID with the given handle.
+ * @param[in] info The handle of the widget information
+ * @param[out] widget_id The widget ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @remarks The @a widget_id must be released using free().
+ */
+int aul_widget_info_get_widget_id(aul_widget_info_h info, char **widget_id);
+
+/**
+ * @par Description:
+ * Gets the widget instance ID with the given handle.
+ * @param[in] info The handle of the widget information
+ * @param[out] instance_id The widget instance ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @remarks The @a instance_id must be released using free().
+ */
+int aul_widget_info_get_instance_id(aul_widget_info_h info, char **instance_id);
+
+/**
+ * @par Description:
+ * Gets the application ID with the given handle.
+ * @param[in] info The handle of the widget information
+ * @param[out] app_id The application ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @remarks The @a app_id must be released using free().
+ */
+int aul_widget_info_get_app_id(aul_widget_info_h info, char **app_id);
+
+/**
+ * @par Description:
+ * Gets the package ID with the given handle.
+ * @param[in] info The handle of the widget information
+ * @param[out] package_id The package ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @remarks The @a app_id must be released using free().
+ */
+int aul_widget_info_get_package_id(aul_widget_info_h info, char **package_id);
+
+/**
+ * @par Description:
+ * Gets the path with the given handle.
+ * @param[in] info The handle of the widget information
+ * @param[out] app_path The path of the widget application
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @remarks The @a app_id must be released using free().
+ */
+int aul_widget_info_get_app_path(aul_widget_info_h info, char **app_path);
+
+/**
+ * @par Description:
+ * Change app status.
+ * @param[in] widget_id The widget app id
+ * @param[in] status The widget app status
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ */
+int aul_widget_instance_change_status(const char *widget_id, const char *status);
+
+/**
+ * @par Description:
+ * Writes file log.
+ * @param[in] tag The log tag
+ * @param[in] format The log foramt
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ */
+int aul_widget_write_log(const char *tag, const char *format, ...);
+
+int aul_widget_service_set_disable(const char *widget_id, bool is_disable);
+
+/**
+ * @brief Called when the widget event is delivered.
+ * @since_tizen 5.5
+ *
+ * @param[in] event_name The event name
+ * @param[in] event_data The event data
+ * @param[in] user_data The user data passed from the registration function
+ *
+ * @see aul_widget_set_event_cb()
+ */
+typedef void (*aul_widget_event_cb)(const char *event_name, bundle *event_data,
+ void *user_data);
+
+/**
+ * @brief Definition for AUL widget event: Saves image.
+ * @since_tizen 5.5
+ */
+#define AUL_WIDGET_EVENT_SAVE_IMAGE "save.image"
+
+/**
+ * @brief Registers the event callback function.
+ * @since_tizen 5.5
+ *
+ * @param[in] callback The callback function
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @see aul_widget_event_cb()
+ * @see aul_widget_unset_event_cb()
+ */
+int aul_widget_set_event_cb(aul_widget_event_cb callback, void *user_data);
+
+/**
+ * @brief Unregisters the event callback function.
+ * @since_tizen 5.5
+ *
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @see aul_widget_set_event_cb()
+ */
+int aul_widget_unset_event_cb(void);
+
+/**
+ * @brief Sends the widget event.
+ * @since_tizen 5.5
+ * @privlevel platform
+ * @privilege %http://tizen.org/privilege/internal/default/platform
+ *
+ * @param[in] event_name The event name
+ * @param[in] event_data The event data
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @see aul_widget_set_event_cb()
+ */
+int aul_widget_send_event(const char *event_name, bundle *event_data);
+
+
+int aul_widget_send_status_to_service(const char *class_id,
+ const char *instance_id, const char *sender_pkgid, int status);
+
+int aul_widget_send_status_to_viewer(const char *class_id,
+ const char *instance_id, const char *viewer_endpoint,
+ int status, int err, bundle *extra);
+
+#ifdef __cplusplus
+}
+#endif
--- /dev/null
+/*
+ * Copyright (c) 2017 - 2021 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 <stdbool.h>
+#include <sys/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void *aul_window_info_h;
+typedef void *aul_window_stack_h;
+
+/**
+ * @par Description:
+ * This API creates the window stack handle.
+ * @par Purpose:
+ * To get information of windows, the stack handle is needed.
+ *
+ * @param[out] handle Handle for the window stack
+ * @return 0 if success, negative value(<0) if fail
+ *
+ * @see
+ * aul_window_stack_del
+ * @remark
+ * It should be freed by aul_window_stack_del function.
+*/
+int aul_window_stack_get(aul_window_stack_h *handle);
+
+/**
+ * @par Description:
+ * This API destroy the window stack handle.
+ *
+ * @param[in] handle Handle for the window stack
+ * @return 0 if success, negative value(<0) if fail
+ *
+ * @see
+ * aul_window_stack_get
+*/
+int aul_window_stack_del(aul_window_stack_h handle);
+
+/**
+ * @par Description:
+ * This API invokes iterator function for each window.
+ *
+ * @param[in] handle Handle for the window stack
+ * @param[in] iter_cb The iteration callback
+ * @param[in] data The data which will be sent to the iterator
+ * @return 0 if success, negative value(<0) if fail
+ *
+*/
+int aul_window_stack_foreach(aul_window_stack_h handle,
+ void (*iter_cb)(aul_window_info_h info, void *data), void *data);
+
+/**
+ * @par Description:
+ * This API gets the global resource ID from the window handle.
+ *
+ * @param[in] info Handle for the window
+ * @param[out] rid Global resource ID
+ *
+ * @return 0 if success, negative value(<0) if fail
+ *
+*/
+int aul_window_stack_info_get_resource_id(aul_window_info_h info, unsigned int *rid);
+
+/**
+ * @par Description:
+ * This API gets the process ID from the window handle.
+ *
+ * @param[in] info Handle for the window
+ * @param[out] pid Process ID
+ *
+ * @return 0 if success, negative value(<0) if fail
+ *
+*/
+int aul_window_info_get_pid(aul_window_info_h info, int *pid);
+
+/**
+ * @par Description:
+ * This API gets the process ID for its parent window from the window handle.
+ *
+ * @param[in] info Handle for the window
+ * @param[out] pid Process ID
+ *
+ * @return 0 if success, negative value(<0) if fail
+ *
+ * @remark
+ * pid will be -1 when the parent window is not exist
+ *
+*/
+int aul_window_info_get_parent_pid(aul_window_info_h info, int *ppid);
+
+/**
+ * @par Description:
+ * This API gets the process ID for its ancestor window from the window handle.
+ *
+ * @param[in] info Handle for the window
+ * @param[out] pid Process ID
+ *
+ * @return 0 if success, negative value(<0) if fail
+ *
+ * @remark
+ * pid will be -1 when the ancestor window is not exist
+ *
+*/
+int aul_window_info_get_ancestor_pid(aul_window_info_h info, int *apid);
+
+/**
+ * @par Description:
+ * This API gets the window visibility from the window handle.
+ *
+ * @param[in] info Handle for the window
+ * @param[out] visibility visibility
+ * 0 Fully visible state
+ * 1 Partially visible state
+ * 2 Invisible state by other window
+ * -1 Invisible state
+ *
+ * @return 0 if success, negative value(<0) if fail
+ *
+*/
+int aul_window_info_get_visibility(aul_window_info_h info, int *visibility);
+
+/**
+ * @par Description:
+ * This API gets the flag value of supporting alpha blending.
+ *
+ * @param[in] info Handle for the window
+ * @param[out] alpha The flag value of supporting alpha blending
+ *
+ * @return 0 if success, negative value(<0) if fail
+ *
+*/
+int aul_window_info_has_alpha(aul_window_info_h info, bool *alpha);
+
+/**
+ * @par Description:
+ * This API gets the flag value of the focused state.
+ *
+ * @param[in] info Handle for the window
+ * @param[out] focused The flag value of the focused state
+ *
+ * @return 0 if success, negative value(<0) if fail
+ *
+*/
+int aul_window_info_is_focused(aul_window_info_h info, bool *focused);
+
+typedef enum _aul_window_notification_level_e {
+ AUL_WINDOW_NOTIFICATION_LEVEL_NONE = 0,
+ AUL_WINDOW_NOTIFICATION_LEVEL_DEFAULT = 10,
+ AUL_WINDOW_NOTIFICATION_LEVEL_MEDIUM = 20,
+ AUL_WINDOW_NOTIFICATION_LEVEL_HIGH = 30,
+ AUL_WINDOW_NOTIFICATION_LEVEL_TOP = 40,
+ AUL_WINDOW_NOTIFICATION_LEVEL_PRIVILEGE = 99,
+} aul_window_notification_level_e;
+
+/**
+ * @par Description:
+ * This API gets the window notification level from the window handle.
+ *
+ * @param[in] info Handle for the window
+ * @param[out] level Notification level
+ * @return 0 if success, negative value(<0) if fail
+ *
+*/
+int aul_window_info_get_notification_level(aul_window_info_h info,
+ aul_window_notification_level_e *level);
+
+/**
+ * @par Description:
+ * This API gets the location and the size from window handle.
+ *
+ * @param[in] info Handle for the window
+ * @param[out] x Position x
+ * @param[out] y Position y
+ * @param[out] w Width
+ * @param[out] h Height
+ *
+ * @return 0 if success, negative value(<0) if fail
+ *
+*/
+int aul_window_info_get_geometry(aul_window_info_h info, int *x, int *y, int *w, int *h);
+
+
+/**
+ * @par Description:
+ * This API gets pid for the focused window.
+ *
+ * @param[out] pid focused pid
+ *
+ * @return 0 if success, negative value(<0) if fail
+ *
+*/
+int aul_window_get_focused_pid(pid_t *pid);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_window_attach(const char *parent_appid, const char *child_appid);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_window_detach(const char *child_appid);
+
+/**
+ * @par Description:
+ * This API gets the flag value of the opaque state.
+ *
+ * @param[in] info Handle for the window
+ * @param[out] opaque The flag value of the opaque state.
+ *
+ * @return 0 on success, otherwise a negative error value.
+ */
+int aul_window_info_get_opaque(aul_window_info_h info, bool *opaque);
+
+/**
+ * @brief Attach the window below the window of the parent application.
+ * @since_tizen 6.5
+ * @remarks This function is only available for platform level signed applications.
+ *
+ * @param[in] parent_appid The application ID of the parent
+ * @param[in] child_appid The application ID of the child
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_window_attach_below(const char *parent_appid, const char *child_appid);
+
+/**
+ * @brief Called when the window of the application is appeared.
+ * @since_tizen 6.5
+ * @details When the window is appeared, the event_name is "Appeared".
+ *
+ * @param[in] event_name The event name
+ * @param[in] appid The application ID
+ * @param[in] wid The window ID
+ * @param[in] pid The process ID
+ * @param[in] user_data The user data passed from the registration function
+ * @see aul_window_register_event_cb()
+ * @see aul_window_deregister_event_cb()
+ */
+typedef void (*aul_window_event_cb)(const char *event_name, const char *appid, int wid, int pid, void *user_data);
+
+/**
+ * @brief Registers the window event callback function.
+ * @since_tizen 6.5
+ *
+ * @param[in] callback The callback function
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ */
+int aul_window_register_event_cb(aul_window_event_cb callback, void *user_data);
+
+/**
+ * @brief Deregisters the window event callback function.
+ * @since_tizen 6.5
+ */
+void aul_window_deregister_event_cb(void);
+
+#ifdef __cplusplus
+}
+#endif
--- /dev/null
+/*
+ * Copyright (c) 2000 - 2021 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 "aul/launch.h"
+
+#include <bundle_internal.h>
+#include <ctype.h>
+#include <dirent.h>
+#include <fcntl.h>
+#include <gio/gio.h>
+#include <glib-unix.h>
+#include <glib.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <ttrace.h>
+
+#include <filesystem>
+#include <memory>
+#include <string>
+#include <utility>
+
+#include "aul/app_request.h"
+#include "aul/app_signal.h"
+#include "aul/aul_api.h"
+#include "aul/aul_util.h"
+#include "aul/include/aul.h"
+#include "aul/include/aul_app_com.h"
+#include "aul/include/aul_error.h"
+#include "aul/include/aul_sock.h"
+
+using namespace aul::internal;
+
+namespace {
+
+constexpr const char kRunAulDaemonsPath[] = "/run/aul/daemons/";
+constexpr const char kLaunchpadProcessPoolSock[] =
+ ".launchpad-process-pool-sock";
+const int kPadCmdKillLoader = 19;
+const int kPadCmdRestartLoader = 20;
+constexpr const int TEP_ISMOUNT_MAX_RETRY_CNT = 20;
+
+class ResultInfo {
+ public:
+ ResultInfo(int fd, aul_result_cb callback, void* user_data)
+ : fd_(fd), callback_(callback), user_data_(user_data) {}
+
+ ResultInfo(const ResultInfo&) = delete;
+ ResultInfo& operator = (const ResultInfo&) = delete;
+
+ ~ResultInfo() {
+ if (source_ != 0)
+ g_source_remove(source_);
+
+ if (fd_ > -1)
+ close(fd_);
+ }
+
+ bool Watch() {
+ source_ = g_unix_fd_add(fd_,
+ static_cast<GIOCondition>(G_IO_IN | G_IO_HUP | G_IO_ERR),
+ FdSourceFunc, this);
+ if (source_ == 0) {
+ _E("g_unix_fd_add() is failed");
+ return false;
+ }
+
+ return true;
+ }
+
+ private:
+ void ProcessReadEvent() {
+ int res = aul_sock_recv_result_with_fd(fd_);
+ if (res < 0)
+ res = aul_error_convert(res);
+ else
+ res = AUL_R_OK;
+
+ callback_(res, user_data_);
+ }
+
+ void ProcessErrorEvent() {
+ callback_(AUL_R_ERROR, user_data_);
+ }
+
+ static gboolean FdSourceFunc(int fd, GIOCondition condition,
+ void* user_data) {
+ auto* info = static_cast<ResultInfo*>(user_data);
+ if (condition & G_IO_IN)
+ info->ProcessReadEvent();
+ else
+ info->ProcessErrorEvent();
+
+ info->source_ = 0;
+ delete info;
+ return G_SOURCE_REMOVE;
+ }
+
+ private:
+ int fd_;
+ aul_result_cb callback_;
+ void *user_data_;
+ guint source_ = 0;
+};
+
+int aul_initialized = 0;
+int aul_fd;
+void* window_object = nullptr;
+void* bg_object = nullptr;
+void* conformant_object = nullptr;
+
+int SendCmdForUidOpt(int pid, uid_t uid, int cmd, bundle* kb, int opt) {
+ int res = aul_sock_send_bundle(pid, uid, cmd, kb, opt);
+ if (res < 0)
+ res = aul_error_convert(res);
+
+ return res;
+}
+
+int SendCmdNoReplyForUidOpt(int pid, uid_t uid, int cmd, bundle* kb, int opt) {
+ int res = aul_sock_send_bundle(pid, uid, cmd, kb, opt | AUL_SOCK_NOREPLY);
+ if (res < 0)
+ res = aul_error_convert(res);
+
+ return res;
+}
+
+int CheckEnvPid() {
+ const char* env_str = getenv("AUL_PID");
+ if (env_str && isdigit(*env_str)) {
+ int env_pid = atoi(env_str);
+ if (env_pid != getpid()) {
+ _W("pid(%d) is not equal to AUL_PID(%d)",
+ getpid(), env_pid);
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+int GetPreInitFd() {
+ int fd = -1;
+
+ if (CheckEnvPid() != 0)
+ return fd;
+
+ const char* listen_fd = getenv("AUL_LISTEN_FD");
+ if (listen_fd) {
+ if (isdigit(*listen_fd))
+ fd = atoi(listen_fd);
+ setenv("AUL_LISTEN_FD", "-1", 1);
+ }
+
+ return fd;
+}
+
+} // namespace
+
+extern "C" int aul_is_initialized() {
+ return aul_initialized;
+}
+
+extern "C" API int app_send_cmd(int pid, int cmd, bundle* kb) {
+ return SendCmdForUidOpt(pid, getuid(), cmd, kb, AUL_SOCK_NONE);
+}
+
+extern "C" API int app_send_cmd_for_uid(int pid, uid_t uid, int cmd,
+ bundle* kb) {
+ return SendCmdForUidOpt(pid, uid, cmd, kb, AUL_SOCK_NONE);
+}
+
+extern "C" API int app_send_cmd_with_queue_for_uid(int pid, uid_t uid, int cmd,
+ bundle* kb) {
+ return SendCmdForUidOpt(pid, uid, cmd, kb, AUL_SOCK_QUEUE);
+}
+
+extern "C" API int app_send_cmd_with_queue_noreply_for_uid(int pid, uid_t uid,
+ int cmd, bundle* kb) {
+ return SendCmdNoReplyForUidOpt(pid, uid, cmd, kb, AUL_SOCK_QUEUE);
+}
+
+extern "C" API int app_send_cmd_with_noreply(int pid, int cmd, bundle* kb) {
+ return SendCmdForUidOpt(pid, getuid(), cmd, kb, AUL_SOCK_NOREPLY);
+}
+
+extern "C" API int app_send_cmd_to_launchpad(const char* pad_type, uid_t uid,
+ int cmd, bundle* kb) {
+ int fd = aul_sock_create_launchpad_client(pad_type, uid);
+ if (fd < 0)
+ return -1;
+
+ int res = aul_sock_send_bundle_with_fd(fd, cmd, kb, AUL_SOCK_ASYNC);
+ if (res < 0) {
+ close(fd);
+ return res;
+ }
+
+retry_recv:
+ int len = recv(fd, &res, sizeof(int), 0);
+ if (len == -1) {
+ if (errno == EAGAIN) {
+ char buf[1024];
+ _E("recv timeout: %d(%s)", errno, strerror_r(errno, buf, sizeof(buf)));
+ res = -EAGAIN;
+ } else if (errno == EINTR) {
+ char buf[1024];
+ _D("recv: %d(%s)", errno, strerror_r(errno, buf, sizeof(buf)));
+ goto retry_recv;
+ } else {
+ char buf[1024];
+ _E("recv error: %d(%s)", errno, strerror_r(errno, buf, sizeof(buf)));
+ res = -ECOMM;
+ }
+ }
+
+ close(fd);
+ return res;
+}
+
+extern "C" int app_request_local(int cmd, bundle* kb) {
+ _E("app_request_to_launchpad : Same Process Send Local");
+ switch (cmd) {
+ case APP_START:
+ case APP_START_RES:
+ case APP_START_ASYNC:
+ case WIDGET_UPDATE:
+ case APP_START_RES_ASYNC:
+ case APP_SEND_LAUNCH_REQUEST:
+ return aul_launch_local(bundle_dup(kb));
+ case APP_OPEN:
+ case APP_RESUME:
+ case APP_RESUME_BY_PID:
+ case APP_RESUME_BY_PID_ASYNC:
+ case APP_SEND_RESUME_REQUEST:
+ return aul_resume_local();
+ default:
+ _E("no support packet");
+ return AUL_R_LOCAL;
+ }
+}
+
+extern "C" int app_request_to_launchpad_for_uid(int cmd, const char* appid,
+ bundle* kb, uid_t uid) {
+ return AppRequest(cmd, uid)
+ .With(kb)
+ .SetAppId(appid)
+ .Send();
+}
+
+extern "C" int aul_initialize() {
+ if (aul_initialized)
+ return AUL_R_ECANCELED;
+
+ aul_fd = GetPreInitFd();
+ if (aul_fd > 0 && aul_fd < sysconf(_SC_OPEN_MAX)) {
+ int flag = fcntl(aul_fd, F_GETFD);
+ flag |= FD_CLOEXEC;
+ (void)fcntl(aul_fd, F_SETFD, flag);
+ } else {
+ _W("Failed to get preinit fd");
+ aul_fd = aul_sock_create_server(getpid(), getuid());
+ if (aul_fd < 0) {
+ _E("aul_init create sock failed");
+ return AUL_R_ECOMM;
+ }
+ }
+ aul_notify_start();
+
+ aul_initialized = 1;
+ return aul_fd;
+}
+
+extern "C" API void aul_finalize() {
+ aul_launch_fini();
+
+ if (aul_initialized) {
+ aul_sock_destroy_server(aul_fd);
+ aul_fd = -1;
+ }
+}
+
+extern "C" API int aul_request_data_control_socket_pair(bundle* kb, int* fd) {
+ if (fd == nullptr)
+ return AUL_R_EINVAL;
+
+ int clifd = AppRequest(APP_GET_DC_SOCKET_PAIR)
+ .With(kb)
+ .SendSimply(AUL_SOCK_ASYNC);
+ if (clifd <= 0)
+ return AUL_R_ERROR;
+
+ int ret = aul_sock_recv_result_with_fd(clifd);
+ if (ret < 0) {
+ close(clifd);
+ if (ret == -EILLEGALACCESS) {
+ _E("Illegal access in datacontrol socket pair request");
+ return AUL_R_EILLACC;
+ }
+ return ret;
+ }
+
+ int fds[2] = { 0, };
+ ret = aul_sock_recv_reply_sock_fd(clifd, &fds, 1);
+ if (ret == 0)
+ fd[0] = fds[0];
+
+ return ret;
+}
+
+extern "C" API int aul_request_message_port_socket_pair(int* fd) {
+ if (fd == nullptr)
+ return AUL_R_EINVAL;
+
+ int ret = AppRequest(APP_GET_MP_SOCKET_PAIR)
+ .SendCmdOnly(AUL_SOCK_ASYNC);
+ if (ret > 0) {
+ int fds[2] = {0, };
+ ret = aul_sock_recv_reply_sock_fd(ret, &fds, 2);
+ if (ret == 0) {
+ fd[0] = fds[0];
+ fd[1] = fds[1];
+ }
+ }
+
+ return ret;
+}
+
+extern "C" API int aul_launch_app(const char* appid, bundle* kb) {
+ return aul_launch_app_for_uid(appid, kb, getuid());
+}
+
+extern "C" API int aul_launch_app_for_uid(const char* appid, bundle* kb,
+ uid_t uid) {
+ if (appid == nullptr)
+ return AUL_R_EINVAL;
+
+ return AppRequest(APP_START, uid)
+ .With(kb)
+ .SetAppId(appid)
+ .Send();
+}
+
+extern "C" API int aul_open_app(const char* appid) {
+ return aul_open_app_for_uid(appid, getuid());
+}
+
+extern "C" API int aul_open_app_for_uid(const char* appid, uid_t uid) {
+ if (appid == nullptr)
+ return AUL_R_EINVAL;
+
+ return AppRequest(APP_OPEN, uid)
+ .SetAppId(appid)
+ .Send();
+}
+
+extern "C" API int aul_resume_app(const char* appid) {
+ return aul_resume_app_for_uid(appid, getuid());
+}
+
+extern "C" API int aul_resume_app_for_uid(const char* appid, uid_t uid) {
+ if (appid == nullptr)
+ return AUL_R_EINVAL;
+
+ return AppRequest(APP_RESUME, uid)
+ .SetAppId(appid)
+ .Send();
+}
+
+extern "C" API int aul_resume_pid(int pid) {
+ return aul_resume_pid_for_uid(pid, getuid());
+}
+
+extern "C" API int aul_resume_pid_for_uid(int pid, uid_t uid) {
+ if (pid <= 0)
+ return AUL_R_EINVAL;
+
+ return AppRequest(APP_RESUME_BY_PID, uid)
+ .SetAppIdAsPid(pid)
+ .Send();
+}
+
+extern "C" API int aul_terminate_pid(int pid) {
+ return aul_terminate_pid_for_uid(pid, getuid());
+}
+
+extern "C" API int aul_terminate_pid_for_uid(int pid, uid_t uid) {
+ if (pid <= 0)
+ return AUL_R_EINVAL;
+
+ int ret = AppRequest(APP_TERM_BY_PID, uid)
+ .SetAppIdAsPid(pid)
+ .Send();
+ if (ret == pid)
+ ret = AUL_R_OK;
+
+ return ret;
+}
+
+extern "C" API int aul_terminate_bgapp_pid(int pid) {
+ if (pid <= 0)
+ return AUL_R_EINVAL;
+
+ int ret = AppRequest(APP_TERM_BGAPP_BY_PID)
+ .SetAppIdAsPid(pid)
+ .Send();
+ if (ret == pid)
+ ret = AUL_R_OK;
+
+ return ret;
+}
+
+extern "C" API int aul_terminate_pid_without_restart(int pid) {
+ if (pid <= 0)
+ return AUL_R_EINVAL;
+
+ return AppRequest(APP_TERM_BY_PID_WITHOUT_RESTART)
+ .SetAppIdAsPid(pid)
+ .Send();
+}
+
+extern "C" API int aul_terminate_pid_sync_without_restart(int pid) {
+ return aul_terminate_pid_sync_without_restart_for_uid(pid, getuid());
+}
+
+extern "C" API int aul_terminate_pid_sync_without_restart_for_uid(int pid,
+ uid_t uid) {
+ if (pid <= 0)
+ return AUL_R_EINVAL;
+
+ return AppRequest(APP_TERM_BY_PID_SYNC_WITHOUT_RESTART, uid)
+ .SetAppIdAsPid(pid)
+ .Send();
+}
+
+extern "C" API int aul_terminate_pid_async(int pid) {
+ return aul_terminate_pid_async_for_uid(pid, getuid());
+}
+
+extern "C" API int aul_terminate_pid_async_for_uid(int pid, uid_t uid) {
+ if (pid <= 0)
+ return AUL_R_EINVAL;
+
+ return AppRequest(APP_TERM_BY_PID_ASYNC, uid)
+ .SetAppIdAsPid(pid)
+ .Send();
+}
+
+extern "C" API int aul_kill_pid(int pid) {
+ if (pid <= 0)
+ return AUL_R_EINVAL;
+
+ return AppRequest(APP_KILL_BY_PID)
+ .SetAppIdAsPid(pid)
+ .Send();
+}
+
+extern "C" API void aul_set_preinit_window(void* evas_object) {
+ window_object = evas_object;
+}
+
+extern "C" API void* aul_get_preinit_window(const char* win_name) {
+ return window_object;
+}
+
+extern "C" API void aul_set_preinit_background(void* evas_object) {
+ bg_object = evas_object;
+}
+
+extern "C" API void* aul_get_preinit_background(void) {
+ return bg_object;
+}
+
+extern "C" API void aul_set_preinit_conformant(void* evas_object) {
+ conformant_object = evas_object;
+}
+
+extern "C" API void* aul_get_preinit_conformant(void) {
+ return conformant_object;
+}
+
+extern "C" API int aul_pause_app(const char* appid) {
+ return aul_pause_app_for_uid(appid, getuid());
+}
+
+extern "C" API int aul_pause_app_for_uid(const char* appid, uid_t uid) {
+ if (appid == nullptr)
+ return AUL_R_EINVAL;
+
+ return AppRequest(APP_PAUSE, uid)
+ .SetAppId(appid)
+ .Send(AUL_SOCK_QUEUE | AUL_SOCK_NOREPLY);
+}
+
+extern "C" API int aul_pause_pid(int pid) {
+ return aul_pause_pid_for_uid(pid, getuid());
+}
+
+extern "C" API int aul_pause_pid_for_uid(int pid, uid_t uid) {
+ if (pid <= 0)
+ return AUL_R_EINVAL;
+
+ return AppRequest(APP_PAUSE_BY_PID, uid)
+ .SetAppIdAsPid(pid)
+ .Send(AUL_SOCK_QUEUE | AUL_SOCK_NOREPLY);
+}
+
+extern "C" API int aul_reload_appinfo(void) {
+ return AppRequest(AMD_RELOAD_APPINFO)
+ .SetAppIdAsPid(getpid())
+ .Send();
+}
+
+extern "C" API int aul_is_tep_mount_dbus_done(const char* tep_string) {
+ GError* err = nullptr;
+ GDBusConnection* conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &err);
+ if (conn == nullptr) {
+ _E("g_bus_get_sync() is failed. error(%s)", err ? err->message : "Unknown");
+ g_clear_error(&err);
+ return AUL_R_ERROR;
+ }
+
+ std::unique_ptr<GDBusConnection, decltype(g_object_unref)*> conn_ptr(
+ conn, g_object_unref);
+
+ GDBusMessage* msg = g_dbus_message_new_method_call(TEP_BUS_NAME,
+ TEP_OBJECT_PATH,
+ TEP_INTERFACE_NAME,
+ TEP_IS_MOUNTED_METHOD);
+ if (msg == nullptr) {
+ _E("g_dbus_message_new_method_call() is failed. error(%s)",
+ err ? err->message : "Unknown");
+ return AUL_R_ERROR;
+ }
+
+ std::unique_ptr<GDBusMessage, decltype(g_object_unref)*> msg_ptr(
+ msg, g_object_unref);
+ g_dbus_message_set_body(msg, g_variant_new("(s)", tep_string));
+
+ GDBusMessage* reply = g_dbus_connection_send_message_with_reply_sync(conn,
+ msg,
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE,
+ 500,
+ nullptr,
+ nullptr,
+ &err);
+ if (reply == nullptr || err != nullptr) {
+ _E("g_dbus_connection_send_message_with_reply_sync() is failed. error(%s)",
+ err ? err->message : "Unknown");
+ g_clear_error(&err);
+ return AUL_R_ERROR;
+ }
+
+ std::unique_ptr<GDBusMessage, decltype(g_object_unref)*> reply_ptr(
+ reply, g_object_unref);
+
+ GVariant* body = g_dbus_message_get_body(reply);
+ if (body == nullptr) {
+ _E("g_dbus_message_get_body() is failed.");
+ return AUL_R_ERROR;
+ }
+
+ int ret = AUL_R_ERROR;
+ g_variant_get(body, "(i)", &ret);
+ return ret;
+}
+
+extern "C" API int aul_check_tep_mount(const char* tep_path) {
+ if (tep_path) {
+ int ret = -1;
+ int cnt = 0;
+ while (cnt < TEP_ISMOUNT_MAX_RETRY_CNT) {
+ ret = aul_is_tep_mount_dbus_done(tep_path);
+ if (ret == 1)
+ break;
+ usleep(50 * 1000);
+ cnt++;
+ }
+ /* incase after trying 1 sec, not getting mounted then quit */
+ if (ret != 1) {
+ _E("Not able to mount within 1 sec");
+ return -1;
+ }
+ }
+ return 0;
+}
+
+extern "C" API int aul_add_loader(const char* loader_path, bundle* kb) {
+ return aul_add_loader_for_uid(loader_path, kb, getuid());
+}
+
+extern "C" API int aul_add_loader_for_uid(const char* loader_path, bundle* kb,
+ uid_t uid) {
+ if (loader_path == nullptr)
+ return AUL_R_EINVAL;
+
+ tizen_base::Bundle b = { {AUL_K_LOADER_PATH, loader_path} };
+
+ if (kb) {
+ try {
+ tizen_base::Bundle extra(kb, false, false);
+ auto raw = extra.ToRaw();
+ b.Add(AUL_K_LOADER_EXTRA, (const char*)(raw.first.get()));
+ } catch (const std::bad_alloc&) {
+ return AUL_R_EINVAL;
+ }
+ }
+
+ return AppRequest(APP_ADD_LOADER, uid)
+ .With(std::move(b))
+ .SendSimply();
+}
+
+extern "C" API int aul_remove_loader(int loader_id) {
+ return aul_remove_loader_for_uid(loader_id, getuid());
+}
+
+extern "C" API int aul_remove_loader_for_uid(int loader_id, uid_t uid) {
+ if (loader_id <= 0)
+ return AUL_R_EINVAL;
+
+ return AppRequest(APP_REMOVE_LOADER, uid)
+ .With({{AUL_K_LOADER_ID, std::to_string(loader_id)}})
+ .SendSimply();
+}
+
+extern "C" API int aul_app_register_pid(const char* appid, int pid) {
+ if (appid == nullptr || pid <= 0)
+ return AUL_R_EINVAL;
+
+ return AppRequest(APP_REGISTER_PID)
+ .SetAppId(appid)
+ .SetPid(pid)
+ .SendSimply(AUL_SOCK_NOREPLY);
+}
+
+extern "C" API int aul_launch_app_async(const char* appid, bundle* kb) {
+ return aul_launch_app_async_for_uid(appid, kb, getuid());
+}
+
+extern "C" API int aul_launch_app_async_for_uid(const char* appid, bundle* kb,
+ uid_t uid) {
+ if (appid == nullptr)
+ return AUL_R_EINVAL;
+
+ return AppRequest(APP_START_ASYNC, uid)
+ .With(kb)
+ .SetAppId(appid)
+ .Send();
+}
+
+extern "C" API int aul_prepare_candidate_process(void) {
+ return AppRequest(APP_PREPARE_CANDIDATE_PROCESS)
+ .SendCmdOnly();
+}
+
+extern "C" API int aul_terminate_pid_sync(int pid) {
+ return aul_terminate_pid_sync_for_uid(pid, getuid());
+}
+
+extern "C" API int aul_terminate_pid_sync_for_uid(int pid, uid_t uid) {
+ if (pid <= 0)
+ return AUL_R_EINVAL;
+
+ return AppRequest(APP_TERM_BY_PID_SYNC, uid)
+ .SetAppIdAsPid(pid)
+ .Send();
+}
+
+extern "C" API int aul_resume_pid_async(int pid) {
+ return aul_resume_pid_async_for_uid(pid, getuid());
+}
+
+extern "C" API int aul_resume_pid_async_for_uid(int pid, uid_t uid) {
+ if (pid <= 0)
+ return AUL_R_EINVAL;
+
+ return AppRequest(APP_RESUME_BY_PID_ASYNC, uid)
+ .SetAppIdAsPid(pid)
+ .Send();
+}
+
+extern "C" API int aul_resume_app_by_instance_id(const char* appid,
+ const char *instance_id) {
+ return aul_resume_app_by_instance_id_for_uid(appid, instance_id, getuid());
+}
+
+extern "C" API int aul_resume_app_by_instance_id_for_uid(const char* appid,
+ const char* instance_id, uid_t uid) {
+ if (appid == nullptr || instance_id == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ return AppRequest(APP_RESUME, uid)
+ .SetAppId(appid)
+ .SetInstId(instance_id)
+ .Send();
+}
+
+extern "C" API int aul_terminate_instance_async(const char* instance_id,
+ int pid) {
+ return aul_terminate_instance_async_for_uid(instance_id, pid, getuid());
+}
+
+extern "C" API int aul_terminate_instance_async_for_uid(const char* instance_id,
+ int pid, uid_t uid) {
+ if (instance_id == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ return AppRequest(APP_TERM_INSTANCE_ASYNC, uid)
+ .SetAppIdAsPid(pid)
+ .SetInstId(instance_id)
+ .Send();
+}
+
+extern "C" API int aul_terminate_app_with_instance_id(const char* appid,
+ const char* instance_id) {
+ return aul_terminate_app_with_instance_id_for_uid(appid, instance_id,
+ getuid());
+}
+
+extern "C" API int aul_terminate_app_with_instance_id_for_uid(const char* appid,
+ const char* instance_id, uid_t uid) {
+ if (appid == nullptr || instance_id == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ return AppRequest(APP_TERMINATE, uid)
+ .SetAppId(appid)
+ .SetInstId(instance_id)
+ .Send();
+}
+
+extern "C" API int aul_terminate_app(const char* appid) {
+ return aul_terminate_app_for_uid(appid, getuid());
+}
+
+extern "C" API int aul_terminate_app_for_uid(const char* appid, uid_t uid) {
+ if (appid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ return AppRequest(APP_TERMINATE, uid)
+ .SetAppId(appid)
+ .Send();
+}
+
+extern "C" API int aul_prepare_app_defined_loader(const char* loader_name) {
+ return aul_prepare_app_defined_loader_for_uid(loader_name, getuid());
+}
+
+extern "C" API int aul_prepare_app_defined_loader_for_uid(
+ const char* loader_name, uid_t uid) {
+ if (loader_name == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ int ret = AppRequest(APP_PREPARE_APP_DEFINED_LOADER, uid)
+ .With({{AUL_K_LOADER_NAME, loader_name}})
+ .SendSimply();
+ if (ret < 0) {
+ _E("Failed to prepare app-defined loader. error(%d)", ret);
+ return ret;
+ }
+
+ _I("loader id(%d)", ret);
+ return ret;
+}
+
+extern "C" API int aul_terminate_pid_async_v2(pid_t pid,
+ aul_result_cb callback, void *user_data) {
+ if (pid < 1 || callback == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ int fd = AppRequest(APP_TERM_BY_PID, getuid())
+ .SetAppIdAsPid(pid)
+ .SendSimply(AUL_SOCK_ASYNC);
+ if (fd < 0) {
+ _E("Failed to send request. error(%d)", fd);
+ return fd;
+ }
+
+ try {
+ auto* info = new ResultInfo(fd, callback, user_data);
+ info->Watch();
+ } catch (const std::exception& e) {
+ _E("Exception occurs. error: %s", e.what());
+ close(fd);
+ return AUL_R_ERROR;
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_terminate_app_async(const char* appid,
+ aul_result_cb callback, void *user_data) {
+ if (appid == nullptr || callback == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ int fd = AppRequest(APP_TERMINATE, getuid())
+ .SetAppId(appid)
+ .SendSimply(AUL_SOCK_ASYNC);
+ if (fd < 0) {
+ _E("Failed to send request. error(%d)", fd);
+ return fd;
+ }
+
+ try {
+ auto* info = new ResultInfo(fd, callback, user_data);
+ info->Watch();
+ } catch (const std::exception& e) {
+ _E("Exception occurs. error: %s", e.what());
+ close(fd);
+ return AUL_R_ERROR;
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_kill_pid_async(pid_t pid,
+ aul_result_cb callback, void *user_data) {
+ if (pid < 1 || callback == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ int fd = AppRequest(APP_KILL_BY_PID, getuid())
+ .SetAppIdAsPid(pid)
+ .SendSimply(AUL_SOCK_ASYNC);
+ if (fd < 0) {
+ _E("Failed to send request. error(%d)", fd);
+ return fd;
+ }
+
+ try {
+ auto* info = new ResultInfo(fd, callback, user_data);
+ info->Watch();
+ } catch (const std::exception& e) {
+ _E("Exception occurs. error: %s", e.what());
+ close(fd);
+ return AUL_R_ERROR;
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_kill_loader(const char* loader_name) {
+ return aul_kill_loader_for_uid(loader_name, getuid());
+}
+
+extern "C" API int aul_kill_loader_for_uid(const char* loader_name,
+ uid_t uid) {
+ if (loader_name == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ if (uid < REGULAR_UID_MIN) {
+ uid = tzplatform_getuid(TZ_SYS_DEFAULT_USER);
+ _W("Use system default user ID(%u)", uid);
+ }
+
+ std::string endpoint = kRunAulDaemonsPath + std::to_string(uid) + "/" +
+ std::string(kLaunchpadProcessPoolSock);
+ if (!std::filesystem::exists(endpoint)) {
+ _E("launchpad socket is not prepared");
+ return AUL_R_ENOENT;
+ }
+
+ int fd = aul_sock_create_launchpad_client(kLaunchpadProcessPoolSock, uid);
+ if (fd < 0) {
+ _E("Failed to create launchpad client socket. error(%d)", fd);
+ return aul_error_convert(fd);
+ }
+
+ tizen_base::Bundle b = { {AUL_K_LOADER_NAME, loader_name} };
+ int ret = aul_sock_send_bundle_with_fd(fd, kPadCmdKillLoader, b.GetHandle(),
+ AUL_SOCK_NOREPLY);
+ if (ret != AUL_R_OK)
+ return aul_error_convert(ret);
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_restart_loader(const char* loader_name) {
+ return aul_restart_loader_for_uid(loader_name, getuid());
+}
+
+extern "C" API int aul_restart_loader_for_uid(const char* loader_name,
+ uid_t uid) {
+ if (loader_name == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ if (uid < REGULAR_UID_MIN) {
+ uid = tzplatform_getuid(TZ_SYS_DEFAULT_USER);
+ _W("Use system default user ID(%u)", uid);
+ }
+
+ std::string endpoint = kRunAulDaemonsPath + std::to_string(uid) + "/" +
+ std::string(kLaunchpadProcessPoolSock);
+ if (!std::filesystem::exists(endpoint)) {
+ _E("launchpad socket is not prepared");
+ return AUL_R_ENOENT;
+ }
+
+ int fd = aul_sock_create_launchpad_client(kLaunchpadProcessPoolSock, uid);
+ if (fd < 0) {
+ _E("Failed to create launchpad client socket. error(%d)", fd);
+ return aul_error_convert(fd);
+ }
+
+ tizen_base::Bundle b = { {AUL_K_LOADER_NAME, loader_name} };
+ int ret = aul_sock_send_bundle_with_fd(fd, kPadCmdRestartLoader,
+ b.GetHandle(), AUL_SOCK_NOREPLY);
+ if (ret != AUL_R_OK)
+ return aul_error_convert(ret);
+
+ return AUL_R_OK;
+}
--- /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>
+#include <bundle.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int aul_initialize(void);
+int aul_is_initialized(void);
+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_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_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);
+void aul_set_instance_info(const char *app_id, bundle *kb);
+
+#ifdef __cplusplus
+}
+#endif
--- /dev/null
+/*
+* Copyright (c) 2000 - 2021 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 <bundle_internal.h>
+#include <gio/gio.h>
+#include <glib.h>
+#include <uuid.h>
+
+#include <atomic>
+#include <functional>
+#include <list>
+#include <mutex>
+
+#include "aul/app_request.h"
+#include "aul/aul_api.h"
+#include "aul/aul_svc_priv_key.h"
+#include "aul/aul_util.h"
+#include "aul/cpu_inheritance.hh"
+#include "aul/include/aul.h"
+#include "aul/include/aul_error.h"
+#include "aul/include/aul_sock.h"
+#include "aul/include/aul_svc.h"
+#include "aul/launch.h"
+
+using namespace aul::internal;
+
+namespace {
+
+using ErrCb = std::function<void(int, void*)>;
+using ReplyCb = std::function<void(bundle*, int, void*)>;
+
+class ReplyList;
+class ReplyInfo {
+ public:
+ ReplyInfo(int pid, std::string seq_num,
+ ReplyCb reply_cb, void* user_data)
+ : seq_num_(std::move(seq_num)), launched_pid_(pid),
+ reply_cb_(std::move(reply_cb)), user_data_(user_data) {}
+
+ void SetCallerCb(ErrCb cb,
+ void* caller_data) {
+ caller_cb_ = std::move(cb);
+ caller_data_ = caller_data;
+ }
+
+ void UnsetCallerCb() {
+ caller_cb_ = nullptr;
+ caller_data_ = nullptr;
+ }
+
+ int GetLaunchedPid() const {
+ return launched_pid_;
+ }
+
+ const ErrCb& GetCallerCb() const {
+ return caller_cb_;
+ }
+
+ void* GetCallerData() const {
+ return caller_data_;
+ }
+
+ private:
+ friend class ReplyList;
+
+ std::string seq_num_;
+ int launched_pid_;
+ ReplyCb reply_cb_;
+ void* user_data_;
+ ErrCb caller_cb_;
+ void* caller_data_ = nullptr;
+};
+
+class ReplyList {
+ public:
+ std::unique_ptr<ReplyInfo> FindByCallerData(void* caller_data) {
+ std::unique_lock<std::mutex> lock(mutex_);
+ for (auto& i : list_) {
+ if (i->caller_data_ == caller_data)
+ return std::unique_ptr<ReplyInfo>(new ReplyInfo(*i));
+ }
+
+ return {};
+ }
+
+ std::unique_ptr<ReplyInfo> Pop(const std::string& seq_num) {
+ if (seq_num.empty())
+ return nullptr;
+
+ std::unique_lock<std::mutex> lock(mutex_);
+ for (auto i = list_.begin(); i != list_.end(); ++i) {
+ if ((*i)->seq_num_ == seq_num) {
+ auto ret = std::move(*i);
+ list_.erase(i);
+ return ret;
+ }
+ }
+
+ return nullptr;
+ }
+
+ void Remove(int pid) {
+ std::unique_lock<std::mutex> lock(mutex_);
+ for (auto i = list_.begin(); i != list_.end(); ) {
+ if ((*i)->launched_pid_ == pid) {
+ i = list_.erase(i);
+ } else {
+ ++i;
+ }
+ }
+ }
+
+ void Push(std::unique_ptr<ReplyInfo> info) {
+ if (info == nullptr)
+ return;
+
+ std::unique_lock<std::mutex> lock(mutex_);
+ list_.push_back(std::move(info));
+ }
+
+ void UpdatePid(const std::string& seq_num, int launched_pid) {
+ std::unique_lock<std::mutex> lock(mutex_);
+ auto* i = Find(seq_num);
+ if (i == nullptr)
+ return;
+ i->launched_pid_ = launched_pid;
+ }
+
+ bool SetCallerCb(int pid, ErrCb cb,
+ void* caller_data) {
+ std::unique_lock<std::mutex> lock(mutex_);
+ auto* i = Find(pid);
+ if (i == nullptr)
+ return false;
+ i->SetCallerCb(std::move(cb), caller_data);
+ return true;
+ }
+
+ bool UnsetCallerCb(int pid, void* caller_data) {
+ std::unique_lock<std::mutex> lock(mutex_);
+ auto* i = Find(pid, caller_data);
+ if (i == nullptr)
+ return false;
+ i->UnsetCallerCb();
+ return true;
+ }
+
+ int InvokeReplyCb(const tizen_base::Bundle& b, bool is_cancel,
+ int launched_pid) {
+ if (launched_pid < 0) {
+ _E("Received pid(%d)", launched_pid);
+ return -1;
+ }
+
+ auto seq_num = b.GetString(AUL_K_SEQ_NUM);
+ if (seq_num.empty()) {
+ _E("Failed to get seq num");
+ return -1;
+ }
+
+ auto info = Pop(seq_num);
+ if (info == nullptr) {
+ _E("Failed to find reply info");
+ return -1;
+ }
+
+ if (info->reply_cb_ == nullptr) {
+ _E("Reply callback function is nullptr");
+ return -1;
+ }
+
+ auto fwdpid_str = b.GetString(AUL_K_FWD_CALLEE_PID);
+ if (is_cancel && !fwdpid_str.empty()) {
+ launched_pid = atoi(fwdpid_str.c_str());
+ auto new_info = std::make_unique<ReplyInfo>(launched_pid, seq_num,
+ info->reply_cb_, info->user_data_);
+ Push(std::move(new_info));
+
+ if (info->caller_cb_ != nullptr)
+ info->caller_cb_(launched_pid, info->caller_data_);
+
+ _W("Change reply info. fwd pid: %d", launched_pid);
+ return 0;
+ }
+
+ info->reply_cb_(b.GetHandle(), is_cancel ? 1 : 0, info->user_data_);
+
+ return 0;
+ }
+
+ private:
+ ReplyInfo* Find(const std::string& seq_num) {
+ for (auto& i : list_) {
+ if (i->seq_num_ == seq_num)
+ return i.get();
+ }
+
+ return nullptr;
+ }
+
+ ReplyInfo* Find(int pid) {
+ for (auto& i : list_) {
+ if (i->launched_pid_ == pid && i->caller_cb_ == nullptr)
+ return i.get();
+ }
+
+ return nullptr;
+ }
+
+ ReplyInfo* Find(int pid, void* caller_data) {
+ for (auto& i : list_) {
+ if (i->launched_pid_ == pid && i->caller_data_ == caller_data)
+ return i.get();
+ }
+
+ return nullptr;
+ }
+
+ private:
+ std::list<std::unique_ptr<ReplyInfo>> list_;
+ std::mutex mutex_;
+};
+
+ReplyList __reply_list;
+
+class ErrorInfo {
+ public:
+ ErrorInfo(std::string seq_num, tizen_base::Bundle b, int cmd,
+ ErrCb error_cb, void* user_data)
+ : seq_num_(std::move(seq_num)),
+ b_(std::move(b)), cmd_(cmd),
+ error_cb_(std::move(error_cb)),
+ user_data_(user_data) {
+ }
+
+ ErrorInfo(const ErrorInfo&) = delete;
+ ErrorInfo& operator = (const ErrorInfo&) = delete;
+
+ ~ErrorInfo() {
+ if (io_ != nullptr)
+ g_io_channel_unref(io_);
+ }
+
+ int AddWatch(int fd) {
+ GIOCondition cond = static_cast<GIOCondition> (G_IO_IN | G_IO_PRI |
+ G_IO_ERR | G_IO_HUP);
+ io_ = g_io_channel_unix_new(fd);
+ if (io_ == nullptr) {
+ _E("Failed to create gio channel");
+ return -1;
+ }
+
+ guint source = g_io_add_watch(io_, cond, ErrorHandlerCb, this);
+ if (source == 0) {
+ _E("Failed to add gio watch");
+ return -1;
+ }
+ g_io_channel_set_close_on_unref(io_, TRUE);
+
+ return 0;
+ }
+
+ static gboolean ErrorHandlerCb(GIOChannel* io, GIOCondition cond,
+ gpointer user_data) {
+ int fd = g_io_channel_unix_get_fd(io);
+ auto* info = reinterpret_cast<ErrorInfo*>(user_data);
+
+ if (info == nullptr) {
+ _E("Critical error!");
+ return G_SOURCE_REMOVE;
+ }
+
+ int res = aul_sock_recv_result_with_fd(fd);
+ if (res < 1) {
+ res = aul_error_convert(res);
+ if (res == AUL_R_LOCAL)
+ res = app_request_local(info->cmd_, info->b_.GetHandle());
+ } else {
+ __reply_list.UpdatePid(info->seq_num_, res);
+ }
+
+ _W("Sequence(%s), result(%d)", info->seq_num_.c_str(), res);
+
+ if (info->error_cb_ != nullptr) {
+ info->error_cb_(res, info->user_data_);
+ info->error_cb_ = nullptr;
+ }
+
+ if (res < 1)
+ __reply_list.Pop(info->seq_num_);
+
+ delete info;
+ return G_SOURCE_REMOVE;
+ }
+
+ private:
+ GIOChannel* io_ = nullptr;
+ std::string seq_num_;
+ tizen_base::Bundle b_;
+ int cmd_;
+ ErrCb error_cb_;
+ void* user_data_;
+ CPUInheritance inheritance_;
+};
+
+std::string __gen_seq_num() {
+ char uuid[37];
+ uuid_t u;
+ uuid_generate(u);
+ uuid_unparse(u, uuid);
+ return std::string(uuid);
+}
+
+int __get_caller_pid(const tizen_base::Bundle& b) {
+ std::string pid_str = b.GetString(AUL_K_ORG_CALLER_PID);
+ if (pid_str.empty())
+ pid_str = b.GetString(AUL_K_CALLER_PID);
+
+ if (pid_str.empty())
+ return -1;
+
+ int pid = atoi(pid_str.c_str());
+ if (pid <= 1)
+ return -1;
+
+ return pid;
+}
+
+int __launch_app_with_result(int cmd, const char* appid, bundle* kb,
+ void (*callback)(bundle*, int, void*), void* data, uid_t uid) {
+ if (!aul_is_initialized()) {
+ if (aul_launch_init(nullptr, nullptr) < 0)
+ return AUL_R_ENOINIT;
+ }
+
+ if (appid == nullptr || callback == nullptr || kb == nullptr)
+ return AUL_R_EINVAL;
+
+ std::string seq_num = __gen_seq_num();
+ bundle_del(kb, AUL_K_SEQ_NUM);
+ bundle_add(kb, AUL_K_SEQ_NUM, seq_num.c_str());
+
+ auto info = std::make_unique<ReplyInfo>(-1, seq_num, callback, data);
+ __reply_list.Push(std::move(info));
+
+ int ret = AppRequest(cmd, uid)
+ .With(kb)
+ .SetAppId(appid)
+ .Send();
+
+ if (ret > 0)
+ __reply_list.UpdatePid(seq_num, ret);
+ else
+ __reply_list.Pop(seq_num);
+
+ return ret;
+}
+
+int __set_caller_info(bundle* kb) {
+ const char* caller_pid;
+ const char* caller_uid;
+
+ caller_pid = bundle_get_val(kb, AUL_K_CALLER_PID);
+ if (caller_pid == nullptr) {
+ _E("Failed to get caller pid");
+ return AUL_R_EINVAL;
+ }
+
+ caller_uid = bundle_get_val(kb, AUL_K_CALLER_UID);
+ if (caller_uid == nullptr) {
+ _E("Failed to get caller uid");
+ return AUL_R_EINVAL;
+ }
+
+ bundle_del(kb, AUL_K_ORG_CALLER_PID);
+ bundle_add(kb, AUL_K_ORG_CALLER_PID, caller_pid);
+ bundle_del(kb, AUL_K_ORG_CALLER_UID);
+ bundle_add(kb, AUL_K_ORG_CALLER_UID, caller_uid);
+
+ return AUL_R_OK;
+}
+
+int __recv_reply_bundle(int fd, bundle** reply_b) {
+ app_pkt_t* pkt = nullptr;
+ int ret = aul_sock_recv_reply_pkt(fd, &pkt);
+ if (ret != 0) {
+ _E("Failed to receive the packet. result(%d)", ret);
+ if (ret == -EAGAIN)
+ return AUL_R_ETIMEOUT;
+
+ return AUL_R_ECOMM;
+ }
+
+ std::unique_ptr<app_pkt_t, decltype(free)*> pkt_auto(pkt, free);
+ if (!(pkt_auto->opt & AUL_SOCK_BUNDLE)) {
+ _E("Invalid protocol");
+ return AUL_R_ECOMM;
+ }
+
+ ret = pkt_auto->cmd;
+ if (ret < 0) {
+ _E("The launch request is failed. result(%d)", ret);
+ if (ret == -EAGAIN)
+ return AUL_R_ETIMEOUT;
+
+ return AUL_R_ERROR;
+ }
+
+ bundle* kb = bundle_decode(pkt_auto->data, pkt_auto->len);
+ if (kb == nullptr) {
+ _E("Out of memory");
+ return AUL_R_ERROR;
+ }
+
+ *reply_b = kb;
+ return ret;
+}
+
+int __send_request_with_callback(int cmd, const char* appid, bundle* b,
+ uid_t uid,
+ void (*reply_cb)(bundle* b, int, void*),
+ void (*error_cb)(int, void*),
+ void* user_data) {
+ if (!aul_is_initialized()) {
+ if (aul_launch_init(nullptr, nullptr) < 0) {
+ _E("Failed to initialize aul launch");
+ return AUL_R_ENOINIT;
+ }
+ }
+
+ if (appid == nullptr || b == nullptr || error_cb == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ std::string seq_num = __gen_seq_num();
+ bundle_del(b, AUL_K_SEQ_NUM);
+ bundle_add(b, AUL_K_SEQ_NUM, seq_num.c_str());
+
+ if (reply_cb != nullptr) {
+ auto r_info = std::make_unique<ReplyInfo>(-1, seq_num, reply_cb,
+ user_data);
+ __reply_list.Push(std::move(r_info));
+ }
+
+ int fd = AppRequest(cmd, uid)
+ .With(b)
+ .SetAppId(appid)
+ .Send();
+ if (fd < 0 || fd >= sysconf(_SC_OPEN_MAX)) {
+ _E("Failed to send launch request. appid(%s), result(%d)",
+ appid, fd);
+ if (reply_cb)
+ __reply_list.Pop(seq_num);
+ return AUL_R_ECOMM;
+ }
+
+ auto error_info = std::make_unique<ErrorInfo>(seq_num,
+ tizen_base::Bundle(b, true, true), cmd, error_cb, user_data);
+ if (error_info.get() == nullptr) {
+ _E("Failed to create error info");
+ if (reply_cb != nullptr)
+ __reply_list.Pop(seq_num);
+ return AUL_R_ERROR;
+ }
+
+ if (error_info->AddWatch(fd) < 0) {
+ _E("Failed to add resultcb watch");
+ if (reply_cb != nullptr)
+ __reply_list.Pop(seq_num);
+ close(fd);
+ return AUL_R_ERROR;
+ }
+
+ error_info.release();
+ return AUL_R_OK;
+}
+
+int __send_launch_request(const std::string& appid, bundle* kb, uid_t uid) {
+ std::string seq_num = __gen_seq_num();
+ tizen_base::Bundle b(kb, false, false);
+ b.Delete(AUL_K_SEQ_NUM);
+ b.Add(AUL_K_SEQ_NUM, seq_num);
+
+ int fd = AppRequest(APP_SEND_LAUNCH_REQUEST_SYNC, uid)
+ .With(b)
+ .SetAppId(appid)
+ .Send();
+ if (fd < 0 || fd >= sysconf(_SC_OPEN_MAX)) {
+ _E("Failed to send launch request. appid(%s), result(%d)",
+ appid.c_str(), fd);
+ return AUL_R_ECOMM;
+ }
+
+ return fd;
+}
+
+} // namespace
+
+extern "C" int app_result(int cmd, bundle* kb, int launched_pid) {
+ switch (cmd) {
+ case APP_RESULT:
+ __reply_list.InvokeReplyCb(tizen_base::Bundle(kb, false, false), false,
+ launched_pid);
+ break;
+ case APP_CANCEL:
+ __reply_list.InvokeReplyCb(tizen_base::Bundle(kb, false, false), true,
+ launched_pid);
+ break;
+ }
+
+ return 0;
+}
+
+extern "C" API int aul_launch_app_with_result(const char* pkgname, bundle* kb,
+ void (*cbfunc)(bundle*, int, void*), void* data) {
+ return __launch_app_with_result(APP_START_RES, pkgname, kb, cbfunc,
+ data, getuid());
+}
+
+extern "C" API int aul_launch_app_with_result_for_uid(const char* pkgname,
+ bundle* kb, void (*cbfunc)(bundle*, int, void*), void* data, uid_t uid) {
+ return __launch_app_with_result(APP_START_RES, pkgname, kb, cbfunc,
+ data, uid);
+}
+
+extern "C" void aul_set_instance_info(const char* app_id, bundle* kb) {
+ const char* component_id;
+ char buf[1024];
+ char uuid[37];
+ uuid_t u;
+
+ uuid_generate(u);
+ uuid_unparse(u, uuid);
+
+ component_id = bundle_get_val(kb, AUL_K_COMPONENT_ID);
+ if (component_id != nullptr) {
+ snprintf(buf, sizeof(buf), "%s:%s:%s",
+ uuid, app_id, component_id);
+ } else {
+ snprintf(buf, sizeof(buf), "%s:%s", uuid, app_id);
+ }
+
+ bundle_del(kb, AUL_K_INSTANCE_ID);
+ bundle_add(kb, AUL_K_INSTANCE_ID, buf);
+}
+
+extern "C" API int aul_forward_app(const char* pkgname, bundle* kb) {
+ if (pkgname == nullptr || kb == nullptr)
+ return AUL_R_EINVAL;
+
+ if (__set_caller_info(kb) < 0)
+ return AUL_R_EINVAL;
+
+ bundle_del(kb, AUL_SVC_K_CAN_BE_LEADER);
+ bundle_del(kb, AUL_SVC_K_REROUTE);
+ bundle_del(kb, AUL_SVC_K_RECYCLE);
+
+ const char* launch_mode = bundle_get_val(kb, AUL_SVC_K_LAUNCH_MODE);
+ if (launch_mode != nullptr && !strcmp(launch_mode, "group"))
+ aul_set_instance_info(pkgname, kb);
+
+ int ret;
+ tizen_base::Bundle dupb(kb, true, true);
+ if (bundle_get_val(kb, AUL_K_WAIT_RESULT) != nullptr) {
+ ret = AppRequest(APP_START_RES)
+ .With(kb)
+ .SetAppId(pkgname)
+ .Send();
+ if (ret < 0)
+ return ret;
+ } else {
+ ret = AppRequest(APP_START)
+ .With(kb)
+ .SetAppId(pkgname)
+ .Send();
+ return ret;
+ }
+
+ bundle* outb = nullptr;
+ int pid = ret;
+ ret = aul_create_result_bundle(dupb.GetHandle(), &outb);
+ if (ret < 0)
+ return ret;
+ tizen_base::Bundle outb_auto(outb, false, true);
+
+ outb_auto.Delete(AUL_K_FWD_CALLEE_PID);
+ outb_auto.Add(AUL_K_FWD_CALLEE_PID, std::to_string(pid));
+ return aul_send_result(outb_auto.GetHandle(), 1);
+}
+
+extern "C" API int aul_create_result_bundle(bundle* inb, bundle** outb) {
+ *outb = nullptr;
+
+ if (inb == nullptr) {
+ _E("return msg create fail");
+ return AUL_R_EINVAL;
+ }
+
+ tizen_base::Bundle inb_auto(inb, false, false);
+ tizen_base::Bundle outb_auto;
+
+ if (!inb_auto.GetString(AUL_K_WAIT_RESULT).empty()) {
+ outb_auto.Add(AUL_K_SEND_RESULT, "1");
+ _D("original msg is msg with result");
+ } else {
+ _D("original msg is not msg with result");
+ }
+
+ std::string uid_str = inb_auto.GetString(AUL_K_ORG_CALLER_UID);
+ if (uid_str.empty()) {
+ uid_str = inb_auto.GetString(AUL_K_CALLER_UID);
+ if (uid_str.empty()) {
+ _E("Failed to find caller uid");
+ return AUL_R_EINVAL;
+ }
+ }
+
+ outb_auto.Add(AUL_K_ORG_CALLER_UID, uid_str);
+ std::string pid_str = inb_auto.GetString(AUL_K_ORG_CALLER_PID);
+ if (!pid_str.empty()) {
+ outb_auto.Add(AUL_K_ORG_CALLER_PID, pid_str);
+ goto end;
+ }
+
+ pid_str = inb_auto.GetString(AUL_K_CALLER_PID);
+ if (pid_str.empty()) {
+ _E("original msg does not have caller pid");
+ return AUL_R_EINVAL;
+ }
+
+ outb_auto.Add(AUL_K_CALLER_PID, pid_str);
+
+end:
+ std::string num_str = inb_auto.GetString(AUL_K_SEQ_NUM);
+ if (num_str.empty()) {
+ _E("original msg does not have seq num");
+ return AUL_R_ECANCELED;
+ }
+
+ outb_auto.Add(AUL_K_SEQ_NUM, num_str);
+ *outb = outb_auto.Detach();
+ return AUL_R_OK;
+}
+
+extern "C" int aul_send_result(bundle* kb, int is_cancel) {
+ int pid;
+ int ret;
+ int callee_pid;
+ int callee_pgid;
+ char callee_appid[256];
+
+ if (kb == nullptr)
+ return AUL_R_EINVAL;
+
+ tizen_base::Bundle b(kb, false, false);
+ if ((pid = __get_caller_pid(b)) < 0)
+ return AUL_R_EINVAL;
+
+ _D("caller pid : %d", pid);
+
+ if (b.GetString(AUL_K_SEND_RESULT).empty()) {
+ _D("original msg is not msg with result");
+ return AUL_R_OK;
+ }
+
+ callee_pid = getpid();
+ callee_pgid = getpgid(callee_pid);
+ b.Add(AUL_K_CALLEE_PID, std::to_string(callee_pgid));
+
+ ret = aul_app_get_appid_bypid(callee_pid, callee_appid,
+ sizeof(callee_appid));
+ if (ret == 0)
+ b.Add(AUL_K_CALLEE_APPID, callee_appid);
+ else
+ _W("fail(%d) to get callee appid by pid", ret);
+
+ ret = app_send_cmd_with_noreply(AUL_UTIL_PID,
+ (is_cancel == 1) ? APP_CANCEL : APP_RESULT, b.GetHandle());
+ _D("app_send_cmd_with_noreply : %d", ret);
+
+ return ret;
+}
+
+extern "C" API int aul_subapp_terminate_request_pid(int pid) {
+ if (pid <= 0)
+ return AUL_R_EINVAL;
+
+ __reply_list.Remove(pid);
+ return AppRequest(APP_TERM_REQ_BY_PID)
+ .SetAppIdAsPid(pid)
+ .Send();
+}
+
+extern "C" int aul_subapp_terminate_request(const char* instance_id, int pid) {
+ if (pid <= 0)
+ return AUL_R_EINVAL;
+
+ __reply_list.Remove(pid);
+ return aul_terminate_instance_async(instance_id, pid);
+}
+
+extern "C" API int aul_add_caller_cb(int pid, void (*caller_cb)(int, void*),
+ void* data) {
+ if (pid <= 0)
+ return AUL_R_EINVAL;
+
+ if (__reply_list.SetCallerCb(pid, caller_cb, data))
+ return AUL_R_OK;
+
+ return AUL_R_ERROR;
+}
+
+extern "C" API int aul_remove_caller_cb(int pid, void* data) {
+ if (pid <= 0)
+ return AUL_R_EINVAL;
+
+ if (__reply_list.UnsetCallerCb(pid, data))
+ return AUL_R_OK;
+
+ return AUL_R_ERROR;
+}
+
+extern "C" API int aul_invoke_caller_cb(void* data) {
+ auto info = __reply_list.FindByCallerData(data);
+ if (info == nullptr)
+ return 0;
+
+ g_idle_add_full(G_PRIORITY_DEFAULT, [](gpointer data) -> gboolean {
+ auto* info = reinterpret_cast<ReplyInfo*>(data);
+
+ if (info != nullptr && info->GetCallerCb() != nullptr)
+ info->GetCallerCb()(info->GetLaunchedPid(), info->GetCallerData());
+
+ delete info;
+ return G_SOURCE_REMOVE;
+ }, info.release(), nullptr);
+
+ return 0;
+}
+
+extern "C" API int aul_launch_app_with_result_async(const char* appid,
+ bundle* b, void (*callback)(bundle*, int, void*), void* data) {
+ return __launch_app_with_result(APP_START_RES_ASYNC, appid, b, callback,
+ data, getuid());
+}
+
+extern "C" API int aul_launch_app_with_result_async_for_uid(const char* appid,
+ bundle* b, void (*callback)(bundle*, int, void*), void* data, uid_t uid) {
+ return __launch_app_with_result(APP_START_RES_ASYNC, appid, b, callback,
+ data, uid);
+}
+
+extern "C" API int aul_send_launch_request_for_uid(const char* appid,
+ bundle* b, uid_t uid, aul_reply_cb reply_cb,
+ aul_result_cb result_cb, void* user_data) {
+ return __send_request_with_callback(APP_SEND_LAUNCH_REQUEST, appid, b,
+ uid, reply_cb, result_cb, user_data);
+}
+
+extern "C" API int aul_send_launch_request_sync_for_uid(const char* appid,
+ bundle* b, uid_t uid, bundle** res_b) {
+ if (!aul_is_initialized()) {
+ if (aul_launch_init(nullptr, nullptr) < 0) {
+ _E("Failed to initialize aul launch");
+ return AUL_R_ENOINIT;
+ }
+ }
+
+ if (appid == nullptr || b == nullptr || res_b == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ int fd = __send_launch_request(appid, b, uid);
+ if (fd < 0)
+ return fd;
+
+ return __recv_reply_bundle(fd, res_b);
+}
+
+extern "C" API int aul_send_resume_request_for_uid(const char* appid,
+ bundle* b, uid_t uid, void (*error_cb)(int, void*), void* user_data) {
+ return __send_request_with_callback(APP_SEND_RESUME_REQUEST, appid, b,
+ uid, nullptr, error_cb, 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 <stdlib.h>
+
+#include "aul_util.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#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 = (char *)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 = (app_info_from_db *)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 = (app_info_from_db *)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);
+}
+
+#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.
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <string.h>
+
+#include <xdgmime.h>
+
+#include "aul.h"
+#include "aul_api.h"
+#include "miregex.h"
+#include "menu_db_util.h"
+#include "aul_util.h"
+
+static int __match_content_with_regex(const char *content, regex_t *regex_preg)
+{
+ if (regexec(regex_preg, content, 0, NULL, 0) == 0)
+ return 1;
+ else
+ return 0;
+}
+
+API int aul_get_mime_from_content(const char *content, char *mimetype,
+ int len)
+{
+ char *founded = NULL;
+ regex_tbl *miregex_tbl = NULL;
+
+ if (content == NULL)
+ return AUL_R_EINVAL;
+
+ if ((miregex_tbl = miregex_get_regex_table()) == NULL) {
+ _E("load miregex_table fail");
+ return AUL_R_ERROR;
+ }
+
+ while (miregex_tbl) {
+ if (__match_content_with_regex(content,
+ &(miregex_tbl->regex_preg))) {
+ founded = miregex_tbl->mimetype;
+ SECURE_LOGD("content %s => mimetype %s", content, founded);
+ break;
+ }
+ miregex_tbl = miregex_tbl->next;
+ }
+
+ if (founded != NULL)
+ snprintf(mimetype, len, "%s", founded);
+ else {
+ /* TODO : should to try to extract from share mime info's data*/
+ return AUL_R_ERROR;
+ }
+
+ return AUL_R_OK;
+}
+
+API int aul_get_mime_description(const char *mimetype, char *desc, int len)
+{
+ regex_tbl *miregex_tbl = NULL;
+ char *founded = NULL;
+
+ if (mimetype == NULL)
+ return AUL_R_EINVAL;
+
+ if ((miregex_tbl = miregex_get_regex_table()) == NULL) {
+ _E("load miregex_table fail");
+ return AUL_R_ERROR;
+ }
+
+ while (miregex_tbl) {
+ if (strcmp(miregex_tbl->mimetype, mimetype) == 0) {
+ founded = miregex_tbl->desc;
+ _D("mimetype %s => desc %s", mimetype, founded);
+ break;
+ }
+ miregex_tbl = miregex_tbl->next;
+ }
+
+ if (founded != NULL)
+ snprintf(desc, len, "%s", founded);
+ else {
+ /* TODO : should to try to extract from share mime info's comment */
+ return AUL_R_ERROR;
+ }
+
+ return AUL_R_OK;
+}
+
+API int aul_get_mime_extension(const char *mimetype, char *ext, int len)
+{
+ const char **extlist;
+ int totlen = 0;
+ const char *unaliased_mimetype;
+
+ if (mimetype == NULL || ext == NULL || len <= 0)
+ return AUL_R_EINVAL;
+
+ unaliased_mimetype = xdg_mime_unalias_mime_type(mimetype);
+ if (unaliased_mimetype == NULL)
+ return AUL_R_ERROR;
+
+ extlist = xdg_mime_get_file_names_from_mime_type(unaliased_mimetype);
+ if (extlist == NULL)
+ return AUL_R_ERROR;
+
+ if (extlist[0] == NULL)
+ return AUL_R_ERROR;
+
+ ext[0] = 0;
+ while (*extlist != NULL) {
+ if (*(extlist + 1) == NULL) {
+ snprintf(&ext[totlen], len - totlen, "%s", *extlist);
+ break;
+ } else {
+ snprintf(&ext[totlen], len - totlen, "%s,", *extlist);
+ if (strlen(*extlist) > len - totlen - 1)
+ break;
+ totlen += strlen(*extlist) + 1;
+ extlist++;
+ }
+ }
+
+ return AUL_R_OK;
+}
+
+API int aul_get_mime_icon(const char *mimetype, char *iconname, int len)
+{
+ const char *icon;
+ const char *unaliased_mimetype;
+
+ if (mimetype == NULL || iconname == NULL || len <= 0)
+ return AUL_R_EINVAL;
+
+ unaliased_mimetype = xdg_mime_unalias_mime_type(mimetype);
+ if (unaliased_mimetype == NULL)
+ return AUL_R_ERROR;
+
+ icon = xdg_mime_get_icon(unaliased_mimetype);
+ if (icon == NULL)
+ icon = xdg_mime_get_generic_icon(unaliased_mimetype);
+
+ if (icon != NULL) {
+ snprintf(iconname, len, "%s", icon);
+ return AUL_R_OK;
+ } else
+ return AUL_R_ERROR;
+}
+
+API int aul_get_mime_from_file(const char *filename, char *mimetype, int len)
+{
+ const char *mime;
+ if (filename == NULL)
+ return AUL_R_EINVAL;
+
+ if (access(filename, F_OK) != 0)
+ return AUL_R_EINVAL;
+
+ mime = xdg_mime_get_mime_type_for_file(filename, 0);
+ if (strcmp(mime, "application/octet-stream") == 0)
+ mime = xdg_mime_get_mime_type_from_file_name(filename);
+
+ snprintf(mimetype, len, "%s", mime);
+ return AUL_R_OK;
+}
+
+API int aul_set_defapp_with_mime(const char *mimetype, const char *defapp)
+{
+ /* removed */
+ return 0;
+}
+
+API int aul_get_defapp_from_mime(const char *mimetype, char *defapp, int len)
+{
+ /* removed */
+ return 0;
+}
+
+API int aul_open_content(const char *content)
+{
+ /* removed */
+ return 0;
+}
+
+API int aul_open_file_with_mimetype(const char *filename,
+ const char *mimetype)
+{
+ /* removed */
+ return 0;
+}
+
+API int aul_open_file(const char *filename)
+{
+ /* removed */
+ 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.
+ */
+
+#define _GNU_SOURCE
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <linux/limits.h>
+
+#include "miregex.h"
+#include "aul_util.h"
+
+#define MIREGEX_DIR SHARE_PREFIX"/miregex"
+#define ONELINE_BUF 1024
+
+typedef struct miregex_file_info_t {
+ char *regex;
+ char *desc;
+} miregex_file_info;
+
+regex_tbl *miregex_tbl = NULL;
+static time_t miregex_mtime = 0;
+
+static void __free_miregex_file_info(miregex_file_info *info);
+static miregex_file_info *__get_miregex_file_info(const char *path);
+static int __add_miregex(const char *name, const char *regex, const char *desc);
+static int __need_update_miregex_tbl();
+static void __miregex_free_regex_table();
+
+
+
+static void __free_miregex_file_info(miregex_file_info *info)
+{
+ if (info == NULL)
+ return;
+
+ if (info->regex != NULL)
+ free(info->regex);
+
+ if (info->desc != NULL)
+ free(info->desc);
+
+ free(info);
+}
+
+static miregex_file_info *__get_miregex_file_info(const char *path)
+{
+ FILE *f;
+ char oneline[ONELINE_BUF];
+ miregex_file_info *info;
+
+ f = fopen(path, "r");
+ if (f == NULL) {
+ _E("miregex file %s is cannot open", path);
+ return NULL;
+ }
+
+ info = (miregex_file_info *)malloc(sizeof(miregex_file_info));
+ if (info == NULL) {
+ fclose(f);
+ return NULL;
+ }
+
+ info->regex = NULL;
+ info->desc = NULL;
+
+ while ((info->regex == NULL) || (info->desc == NULL)) {
+ memset(oneline, 0, ONELINE_BUF);
+ if (fgets(oneline, ONELINE_BUF, f) == NULL)
+ break;
+
+ oneline[strlen(oneline) - 1] = 0;
+
+ if (info->regex == NULL)
+ info->regex = strdup(oneline);
+ else
+ info->desc = strdup(oneline);
+ }
+
+ fclose(f);
+
+ return info;
+}
+
+static int __add_miregex(const char *name, const char *regex, const char *desc)
+{
+ regex_tbl *tbl = NULL;
+ int error;
+ int ret;
+ char *msg = NULL;
+
+ if (regex == NULL)
+ return -1;
+
+ tbl = (regex_tbl *)malloc(sizeof(regex_tbl));
+ if (NULL == tbl) {
+ _E("Malloc failed!");
+ return -1;
+ }
+
+ if ((error = regcomp(&(tbl->regex_preg), regex,
+ REG_EXTENDED | REG_NOSUB)) != 0) {
+ ret = regerror(error, &(tbl->regex_preg), NULL, 0);
+ msg = (char *)malloc(sizeof(char) * ret);
+ if (NULL == msg) {
+ _E("Malloc failed!");
+ if (tbl) {
+ free(tbl);
+ tbl = NULL;
+ }
+
+ return -1;
+ }
+ regerror(error, &(tbl->regex_preg), msg, ret);
+ _E("regex compile error - %s", msg);
+ if (msg) {
+ free(msg);
+ msg = NULL;
+ }
+
+ if (tbl) {
+ free(tbl);
+ tbl = NULL;
+ }
+
+ return -1;
+ }
+
+ tbl->mimetype = strdup(name);
+ tbl->regex = strdup(regex);
+ if (desc != NULL)
+ tbl->desc = strdup(desc);
+ tbl->next = miregex_tbl;
+ miregex_tbl = tbl;
+
+ return 0;
+}
+
+static int __need_update_miregex_tbl()
+{
+ struct stat st;
+
+ if (stat(MIREGEX_DIR, &st) < 0) {
+ _E("stat error - check miregex dir - %s", MIREGEX_DIR);
+ return 1;
+ }
+
+ if (st.st_mtime != miregex_mtime) {
+ miregex_mtime = st.st_mtime;
+ return 1;
+ }
+
+ if (miregex_tbl == NULL) {
+ miregex_mtime = st.st_mtime;
+ return 1;
+ }
+
+ return 0;
+}
+
+static void __miregex_free_regex_table()
+{
+ regex_tbl *tbl;
+
+ while (miregex_tbl) {
+ if (miregex_tbl->mimetype != NULL)
+ free(miregex_tbl->mimetype);
+ if (miregex_tbl->regex != NULL)
+ free(miregex_tbl->regex);
+ if (miregex_tbl->desc != NULL)
+ free(miregex_tbl->desc);
+ regfree(&(miregex_tbl->regex_preg));
+
+ tbl = miregex_tbl;
+ miregex_tbl = miregex_tbl->next;
+ free(tbl);
+ }
+
+ miregex_tbl = NULL;
+}
+
+regex_tbl *miregex_get_regex_table()
+{
+ DIR *dp;
+ struct dirent *dentry = NULL;
+ char buf[PATH_MAX];
+ miregex_file_info *info;
+
+ if (!__need_update_miregex_tbl())
+ return miregex_tbl;
+
+ _D("*** reload miregex tbl ***");
+
+ if (miregex_tbl != NULL)
+ __miregex_free_regex_table();
+
+ dp = opendir(MIREGEX_DIR);
+ if (dp == NULL)
+ return NULL;
+
+ while ((dentry = readdir(dp)) != NULL) {
+ if (dentry->d_name[0] == '.')
+ continue;
+
+ snprintf(buf, sizeof(buf), "%s/%s", MIREGEX_DIR,
+ dentry->d_name);
+
+ info = __get_miregex_file_info(buf);
+ if (info == NULL)
+ continue;
+
+ if (__add_miregex(dentry->d_name,
+ info->regex, info->desc) < 0) {
+ /* TODO : invalid regular expression - will be removed*/
+ }
+
+ __free_miregex_file_info(info);
+ }
+
+ closedir(dp);
+
+ return miregex_tbl;
+}
--- /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
+/*
+ * Copyright (c) 2012 - 2022 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 <bundle_cpp.h>
+#include <bundle_internal.h>
+#include <glib-unix.h>
+#include <glib.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <atomic>
+#include <exception>
+#include <memory>
+#include <string>
+#include <thread>
+
+#include "aul/app_request.h"
+#include "aul/aul_api.h"
+#include "aul/aul_util.h"
+#include "aul/include/aul.h"
+#include "aul/include/aul_error.h"
+#include "aul/include/aul_sock.h"
+#include "aul/menu_db_util.h"
+#include "aul/pkginfo_internal.h"
+
+using namespace aul::internal;
+
+namespace {
+
+constexpr const char* kAppInfoKeys[] = {
+ AUL_K_PID,
+ AUL_K_APPID,
+ AUL_K_EXEC,
+ AUL_K_PKGID,
+ AUL_K_STATUS,
+ AUL_K_IS_SUBAPP,
+};
+
+constexpr const char kPathAmdReady[] = "/run/.amd_ready";
+
+class ResultInfo {
+ public:
+ ResultInfo(pid_t pid, int fd, aul_appid_cb callback, void* user_data)
+ : pid_(pid), fd_(fd), callback_(callback), user_data_(user_data) {}
+
+ ResultInfo(const ResultInfo&) = delete;
+ ResultInfo& operator = (const ResultInfo&) = delete;
+
+ ~ResultInfo() {
+ if (source_ != 0)
+ g_source_remove(source_);
+
+ if (fd_ > -1)
+ close(fd_);
+ }
+
+ bool Watch() {
+ source_ = g_unix_fd_add(fd_,
+ static_cast<GIOCondition>(G_IO_IN | G_IO_HUP | G_IO_ERR),
+ FdSourceFunc, this);
+ if (source_ == 0) {
+ _E("g_unix_fd_add() is failed");
+ return false;
+ }
+
+ return true;
+ }
+
+ private:
+ void ProcessReadEvent() {
+ app_pkt_t* pkt = nullptr;
+ int ret = aul_sock_recv_reply_pkt(fd_, &pkt);
+ fd_ = -1;
+ if (ret < 0 || pkt == nullptr) {
+ ProcessErrorEvent();
+ return;
+ }
+
+ auto pkt_auto = std::unique_ptr<app_pkt_t, decltype(std::free)*>(
+ pkt, std::free);
+ if (pkt->cmd != APP_GET_INFO_OK) {
+ ProcessErrorEvent();
+ return;
+ }
+
+ char appid[256] = { 0, };
+ snprintf(appid, sizeof(appid), "%s", pkt->data);
+ SECURE_LOGD("pid: %d, appid: %s", pid_, appid);
+ callback_(AUL_R_OK, pid_, appid, user_data_);
+ }
+
+ void ProcessErrorEvent() {
+ callback_(AUL_R_ERROR, pid_, "", user_data_);
+ }
+
+ static gboolean FdSourceFunc(int fd, GIOCondition condition,
+ gpointer user_data) {
+ auto* info = static_cast<ResultInfo*>(user_data);
+ _E("GIOCondition: %d", static_cast<int>(condition));
+ if (condition & G_IO_IN)
+ info->ProcessReadEvent();
+ else
+ info->ProcessErrorEvent();
+
+ info->source_ = 0;
+ delete info;
+ return G_SOURCE_REMOVE;
+ }
+
+ private:
+ pid_t pid_;
+ int fd_;
+ aul_appid_cb callback_;
+ void* user_data_;
+ guint source_ = 0;
+};
+
+bool IsAmdReady() {
+ static std::atomic<bool> amd_ready = false;
+ if (amd_ready)
+ return amd_ready;
+
+ if (access(kPathAmdReady, F_OK) == 0) {
+ amd_ready.exchange(true);
+ return amd_ready;
+ }
+
+ return false;
+}
+
+class Context {
+ public:
+ Context() = default;
+
+ void Initialize() {
+ if (initialized_)
+ return;
+
+ auto* appid = getenv("AUL_APPID");
+ if (appid != nullptr)
+ appid_ = std::string(appid);
+
+ auto* pkgid = getenv("AUL_PKGID");
+ if (pkgid != nullptr)
+ pkgid_ = std::string(pkgid);
+
+ auto* root_path = getenv("AUL_ROOT_PATH");
+ if (root_path != nullptr)
+ root_path_ = std::string(root_path);
+
+ initialized_ = true;
+ }
+
+ const std::string& GetPreInitAppId() const {
+ return appid_;
+ }
+
+ const std::string& GetPreInitPkgId() const {
+ return pkgid_;
+ }
+
+ const std::string& GetPreInitRootPath() const {
+ return root_path_;
+ }
+
+ void SetPreInitAppId(std::string appid) {
+ appid_ = std::move(appid);
+ }
+
+ void SetPreInitPkgId(std::string pkgid) {
+ pkgid_ = std::move(pkgid);
+ }
+
+ void SetPreInitRootPath(std::string root_path) {
+ root_path_ = std::move(root_path);
+ }
+
+ private:
+ bool initialized_ = false;
+ std::string appid_;
+ std::string pkgid_;
+ std::string root_path_;
+};
+
+int SendAndReceive(int cmd, uid_t uid,
+ std::vector<tizen_base::Bundle>* results) {
+ int fd = AppRequest(cmd, uid).SendSimply(AUL_SOCK_ASYNC);
+ if (fd < 0)
+ return fd;
+
+ int ret = aul_sock_recv_pkt_with_cb(fd,
+ [](app_pkt_t* pkt, void* user_data) {
+ if (pkt == nullptr) {
+ _E("Invalid parameter");
+ return;
+ }
+
+ bundle* b = nullptr;
+ if (pkt->opt & AUL_SOCK_BUNDLE)
+ b = bundle_decode(pkt->data, pkt->len);
+
+ if (b == nullptr)
+ return;
+
+ auto* res = static_cast<std::vector<tizen_base::Bundle>*>(user_data);
+ res->push_back(tizen_base::Bundle(b, false, true));
+ }, results);
+ if (ret < 0)
+ return aul_error_convert(ret);
+
+ return AUL_R_OK;
+}
+
+int SetAppInfo(aul_app_info* info, const tizen_base::Bundle& b) {
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
+ for (unsigned int i = 0; i < ARRAY_SIZE(kAppInfoKeys); ++i) {
+ if (b.GetType(kAppInfoKeys[i]) == BUNDLE_TYPE_NONE)
+ return -1;
+ }
+
+ info->pid = std::stoi(b.GetString(AUL_K_PID));
+ info->appid = const_cast<char*>(bundle_get_val(b.GetHandle(), AUL_K_APPID));
+ info->app_path = const_cast<char*>(bundle_get_val(b.GetHandle(), AUL_K_EXEC));
+ info->pkgid = const_cast<char*>(bundle_get_val(b.GetHandle(), AUL_K_PKGID));
+ info->instance_id = const_cast<char*>(
+ bundle_get_val(b.GetHandle(), AUL_K_INSTANCE_ID));
+ info->status = std::stoi(b.GetString(AUL_K_STATUS));
+ info->is_sub_app = std::stoi(b.GetString(AUL_K_IS_SUBAPP));
+ info->pkg_name = info->appid;
+ return 0;
+}
+
+thread_local bool calling_appinfo_cb = false;
+thread_local aul_app_info* current_info = nullptr;
+int GetRunningAppInfoWithCb(int cmd, uid_t uid, aul_app_info_iter_fn cb,
+ void* user_data) {
+ if (cb == nullptr)
+ return AUL_R_EINVAL;
+
+ std::vector<tizen_base::Bundle> results;
+ int ret = SendAndReceive(cmd, uid, &results);
+ if (ret != AUL_R_OK)
+ return ret;
+
+ calling_appinfo_cb = true;
+ aul_app_info info;
+ for (auto const& b : results) {
+ if (SetAppInfo(&info, b) != 0)
+ break;
+
+ current_info = &info;
+ cb(&info, user_data);
+ current_info = nullptr;
+ }
+ calling_appinfo_cb = false;
+
+ return AUL_R_OK;
+}
+
+Context context;
+
+int GetPkgIdFromDB(int pid, char* buf, int len, uid_t uid) {
+ const auto& appid = context.GetPreInitAppId();
+ if (appid.empty()) {
+ _E("Failed to get pre-initialized appid");
+ return -1;
+ }
+
+ auto* menu_info = _get_app_info_from_db_by_appid_user(appid.c_str(), uid);
+ if (menu_info == nullptr) {
+ _E("Failed to get app info. appid(%s)", appid.c_str());
+ return -1;
+ }
+
+ snprintf(buf, len, "%s", _get_pkgid(menu_info));
+ _free_app_info_from_db(menu_info);
+ return 0;
+}
+
+} // namespace
+
+extern "C" bool aul_is_calling_appinfo_cb() {
+ return calling_appinfo_cb;
+}
+
+extern "C" int aul_app_get_status_from_current_appinfo(const char* appid,
+ int* status) {
+ if (appid == nullptr || status == nullptr)
+ return AUL_R_EINVAL;
+
+ if (current_info == nullptr)
+ return AUL_R_ERROR;
+
+ if (strcmp(appid, current_info->appid) != 0)
+ return AUL_R_ERROR;
+
+ *status = current_info->status;
+ return AUL_R_OK;
+}
+
+extern "C" int aul_app_get_status_bypid_from_current_appinfo(int pid,
+ int* status) {
+ if (pid < 1 || status == nullptr)
+ return AUL_R_EINVAL;
+
+ if (current_info == nullptr)
+ return AUL_R_ERROR;
+
+ if (current_info->pid != pid)
+ return AUL_R_ERROR;
+
+ *status = current_info->status;
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_app_get_pid(const char* appid) {
+ return aul_app_get_pid_for_uid(appid, getuid());
+}
+
+extern "C" API int aul_app_get_pid_for_uid(const char* appid, uid_t uid) {
+ if (appid == nullptr)
+ return -1;
+
+ return AppRequest(APP_GET_PID, uid)
+ .SetAppId(appid)
+ .SendSimply();
+}
+
+extern "C" API int aul_app_is_running(const char* appid) {
+ return aul_app_is_running_for_uid(appid, getuid());
+}
+
+extern "C" API int aul_app_is_running_for_uid(const char* appid, uid_t uid) {
+ if (appid == nullptr)
+ return 0;
+
+ int ret = AppRequest(APP_IS_RUNNING, uid)
+ .SetAppId(appid)
+ .SendSimply();
+ return ret > 0;
+}
+
+extern "C" API int aul_app_get_running_app_info(aul_app_info_iter_fn iter_fn,
+ void* user_data) {
+ return aul_app_get_running_app_info_for_uid(iter_fn, user_data, getuid());
+}
+
+extern "C" API int aul_app_get_running_app_info_for_uid(
+ aul_app_info_iter_fn iter_fn, void* user_data, uid_t uid) {
+ return GetRunningAppInfoWithCb(APP_RUNNING_INFO, uid, iter_fn, user_data);
+}
+
+extern "C" API int aul_app_get_all_running_app_info(
+ aul_app_info_iter_fn iter_fn, void* user_data) {
+ return aul_app_get_all_running_app_info_for_uid(iter_fn, user_data, getuid());
+}
+
+extern "C" API int aul_app_get_all_running_app_info_for_uid(
+ aul_app_info_iter_fn iter_fn, void* user_data, uid_t uid) {
+ return GetRunningAppInfoWithCb(APP_ALL_RUNNING_INFO, uid, iter_fn, user_data);
+}
+
+extern "C" API int aul_app_get_running_app_instance_info(
+ aul_app_info_iter_fn iter_fn, void* user_data) {
+ return aul_app_get_running_app_instance_info_for_uid(iter_fn, user_data,
+ getuid());
+}
+
+extern "C" API int aul_app_get_running_app_instance_info_for_uid(
+ aul_app_info_iter_fn iter_fn, void *user_data, uid_t uid) {
+ return GetRunningAppInfoWithCb(APP_RUNNING_INSTANCE_INFO, uid, iter_fn,
+ user_data);
+}
+
+extern "C" API void aul_set_preinit_appid(const char* appid) {
+ context.Initialize();
+ context.SetPreInitAppId(appid ? appid : "");
+}
+
+extern "C" API void aul_set_preinit_pkgid(const char* pkgid) {
+ context.Initialize();
+ context.SetPreInitPkgId(pkgid ? pkgid : "");
+}
+
+extern "C" API void aul_set_preinit_root_path(const char* root_path) {
+ context.Initialize();
+ context.SetPreInitRootPath(root_path ? root_path : "");
+}
+
+extern "C" API const char* aul_get_preinit_root_path(void) {
+ context.Initialize();
+ return context.GetPreInitRootPath().c_str();
+}
+
+extern "C" API int aul_app_get_pkgname_bypid(int pid, char* pkgname, int len) {
+ return aul_app_get_appid_bypid(pid, pkgname, len);
+}
+
+extern "C" API int aul_app_get_appid_bypid(int pid, char* appid, int len) {
+ return aul_app_get_appid_bypid_for_uid(pid, appid, len, getuid());
+}
+
+extern "C" API int aul_app_get_appid_bypid_for_uid(int pid, char* appid,
+ int len, uid_t uid) {
+ if (pid < 1 || appid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ if (getpid() == pid || getpgid(getpid()) == pid) {
+ context.Initialize();
+ const auto& preinit_appid = context.GetPreInitAppId();
+ if (!preinit_appid.empty()) {
+ snprintf(appid, len, "%s", preinit_appid.c_str());
+ return AUL_R_OK;
+ }
+ }
+
+ int fd = AppRequest(APP_GET_APPID_BYPID, uid)
+ .SetPid(pid)
+ .SendSimply(AUL_SOCK_ASYNC);
+ if (fd < 0)
+ return AUL_R_ERROR;
+
+ app_pkt_t* pkt = nullptr;
+ int ret = aul_sock_recv_reply_pkt(fd, &pkt);
+ if (ret < 0 || pkt == nullptr)
+ return AUL_R_ERROR;
+
+ auto pkt_auto = std::unique_ptr<app_pkt_t, decltype(std::free)*>(
+ pkt, std::free);
+ if (pkt->cmd != APP_GET_INFO_OK)
+ return AUL_R_ERROR;
+
+ snprintf(appid, len, "%s", pkt->data);
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_app_get_pkgid_bypid(int pid, char* pkgid, int len) {
+ return aul_app_get_pkgid_bypid_for_uid(pid, pkgid, len, getuid());
+}
+
+extern "C" API int aul_app_get_pkgid_bypid_for_uid(int pid, char* pkgid,
+ int len, uid_t uid) {
+ if (pid < 1 || pkgid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ if (getpid() == pid || getpgid(getpid()) == pid) {
+ context.Initialize();
+ const auto& preinit_pkgid = context.GetPreInitPkgId();
+ if (!preinit_pkgid.empty()) {
+ snprintf(pkgid, len, "%s", preinit_pkgid.c_str());
+ return AUL_R_OK;
+ }
+
+ if (GetPkgIdFromDB(pid, pkgid, len, uid) == 0)
+ return AUL_R_OK;
+ }
+
+ int fd = AppRequest(APP_GET_PKGID_BYPID, uid)
+ .SetPid(pid)
+ .SendSimply(AUL_SOCK_ASYNC);
+ if (fd < 0)
+ return AUL_R_ERROR;
+
+ app_pkt_t* pkt = nullptr;
+ int ret = aul_sock_recv_reply_pkt(fd, &pkt);
+ if (ret < 0 || pkt == nullptr)
+ return AUL_R_ERROR;
+
+ auto pkt_auto = std::unique_ptr<app_pkt_t, decltype(std::free)*>(
+ pkt, std::free);
+ if (pkt->cmd != APP_GET_INFO_OK)
+ return AUL_R_ERROR;
+
+ snprintf(pkgid, len, "%s", pkt->data);
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_update_rua_stat_for_uid(bundle* b, uid_t uid) {
+ if (b == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ return AppRequest(APP_UPDATE_RUA_STAT, uid)
+ .With(b)
+ .SendSimply();
+}
+
+extern "C" API int aul_add_rua_history_for_uid(bundle* b, uid_t uid) {
+ if (b == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ return AppRequest(APP_ADD_HISTORY, uid)
+ .With(b)
+ .SendSimply();
+}
+
+extern "C" API int aul_delete_rua_history_for_uid(bundle* b, uid_t uid) {
+ tizen_base::Bundle kb;
+ if (b != nullptr)
+ kb = std::move(tizen_base::Bundle(b, false, false));
+
+ return AppRequest(APP_REMOVE_HISTORY, uid)
+ .With(std::move(kb))
+ .SendSimply();
+}
+
+extern "C" API int aul_set_default_app_by_operation(bundle* b) {
+ if (b == nullptr)
+ return AUL_R_EINVAL;
+
+ return AppRequest(APP_SET_APP_CONTROL_DEFAULT_APP, getuid())
+ .With(b)
+ .SendSimply();
+}
+
+extern "C" API int aul_unset_default_app_by_operation(const char* appid) {
+ if (appid == nullptr)
+ return AUL_R_EINVAL;
+
+ int ret = aul_sock_send_raw(AUL_UTIL_PID, getuid(),
+ APP_UNSET_APP_CONTROL_DEFAULT_APP,
+ reinterpret_cast<unsigned char*>(const_cast<char*>(appid)),
+ strlen(appid), AUL_SOCK_NONE);
+ if (ret != 0)
+ return aul_error_convert(ret);
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_app_get_last_caller_pid(int pid) {
+ return aul_app_get_last_caller_pid_for_uid(pid, getuid());
+}
+
+extern "C" API int aul_app_get_last_caller_pid_for_uid(int pid, uid_t uid) {
+ if (pid < 1) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ return AppRequest(APP_GET_LAST_CALLER_PID, uid)
+ .SetPid(pid)
+ .SendSimply();
+}
+
+extern "C" API int aul_set_alias_appid(const char* alias_appid,
+ const char* appid) {
+ if (alias_appid == nullptr || appid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ tizen_base::Bundle b { { AUL_K_ALIAS_APPID, alias_appid } };
+
+ return AppRequest(APP_SET_ALIAS_APPID, getuid())
+ .With(std::move(b))
+ .SetAppId(appid)
+ .SendSimply();
+}
+
+extern "C" API int aul_unset_alias_appid(const char* alias_appid) {
+ if (alias_appid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ tizen_base::Bundle b { { AUL_K_ALIAS_APPID, alias_appid } };
+ return AppRequest(APP_UNSET_ALIAS_APPID, getuid())
+ .With(std::move(b))
+ .SendSimply();
+}
+
+extern "C" API int aul_enable_alias_info(const char* appid) {
+ if (appid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ return AppRequest(APP_ENABLE_ALIAS_INFO, getuid())
+ .SetAppId(appid)
+ .SendSimply();
+}
+
+extern "C" API int aul_disable_alias_info(const char* appid) {
+ if (appid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ return AppRequest(APP_DISABLE_ALIAS_INFO, getuid())
+ .SetAppId(appid)
+ .SendSimply();
+}
+
+extern "C" API int aul_set_auto_restart(bundle* b) {
+ tizen_base::Bundle kb { { AUL_K_AUTO_RESTART, "true" } };
+ if (b != nullptr) {
+ bundle_raw* raw;
+ int len;
+ if (bundle_encode(b, &raw, &len) != BUNDLE_ERROR_NONE)
+ return AUL_R_EINVAL;
+
+ kb.Add(AUL_K_RESTART_EXTRA, reinterpret_cast<char*>(raw));
+ bundle_free_encoded_rawdata(&raw);
+ }
+
+ return AppRequest(APP_SET_AUTO_RESTART, getuid())
+ .With(std::move(kb))
+ .SendSimply();
+}
+
+extern "C" API int aul_unset_auto_restart(void) {
+ tizen_base::Bundle kb { { AUL_K_AUTO_RESTART, "false" } };
+ return AppRequest(APP_SET_AUTO_RESTART, getuid())
+ .With(std::move(kb))
+ .SendSimply();
+}
+
+extern "C" API int aul_app_get_instance_id_bypid(int pid, char* instance_id,
+ int len) {
+ return aul_app_get_instance_id_bypid_for_uid(pid, instance_id, len, getuid());
+}
+
+extern "C" API int aul_app_get_instance_id_bypid_for_uid(int pid,
+ char* instance_id, int len, uid_t uid) {
+ if (pid < 1 || instance_id == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ int fd = AppRequest(APP_GET_INSTANCE_ID_BYPID, uid)
+ .SetPid(pid)
+ .SendSimply(AUL_SOCK_ASYNC);
+ if (fd < 0)
+ return AUL_R_ERROR;
+
+ app_pkt_t* pkt = nullptr;
+ int ret = aul_sock_recv_reply_pkt(fd, &pkt);
+ if (ret < 0 || pkt == nullptr)
+ return AUL_R_ERROR;
+
+ auto pkt_auto = std::unique_ptr<app_pkt_t, decltype(std::free)*>(
+ pkt, std::free);
+ if (pkt->cmd != APP_GET_INFO_OK)
+ return AUL_R_ERROR;
+
+ snprintf(instance_id, len, "%s", pkt->data);
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_app_is_running_with_instance_id(const char* appid,
+ const char* instance_id, bool* running) {
+ if (appid == nullptr || instance_id == nullptr || running == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ int ret = AppRequest(APP_IS_RUNNING, getuid())
+ .SetAppId(appid)
+ .SetInstId(instance_id)
+ .SendSimply();
+ if (ret < 0)
+ return ret;
+
+ *running = ret ? true : false;
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_get_default_app(bundle* b, char** appid) {
+ if (b == nullptr || appid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ int fd = AppRequest(APP_GET_APP_CONTROL_DEFAULT_APP, getuid())
+ .With(b)
+ .SendSimply(AUL_SOCK_ASYNC);
+ if (fd < 0)
+ return fd;
+
+ app_pkt_t* pkt = nullptr;
+ int ret = aul_sock_recv_reply_pkt(fd, &pkt);
+ if (ret < 0 || pkt == nullptr) {
+ _E("aul_sock_recv_reply_pkt() is failed. error(%d)", ret);
+ return aul_error_convert(ret);
+ }
+
+ auto pkt_auto = std::unique_ptr<app_pkt_t, decltype(std::free)*>(
+ pkt, std::free);
+ if (pkt->cmd != APP_GET_INFO_OK) {
+ _E("Failed to get default app. error(%d)", pkt->cmd);
+ return aul_error_convert(pkt->cmd);
+ }
+
+ if (!(pkt->opt & AUL_SOCK_BUNDLE)) {
+ _E("Invalid protocol");
+ return AUL_R_ERROR;
+ }
+
+ bundle* res_b = bundle_decode(pkt->data, pkt->len);
+ if (res_b == nullptr) {
+ _E("bundle_decode() is failed");
+ return AUL_R_ERROR;
+ }
+
+ tizen_base::Bundle kb(res_b, false, true);
+ auto value = kb.GetString(AUL_K_APPID);
+ if (value.empty()) {
+ _E("Failed to get appid");
+ return AUL_R_ERROR;
+ }
+
+ *appid = strdup(value.c_str());
+ if (*appid == nullptr) {
+ _E("strdup() is failed. appid(%s)", value.c_str());
+ return AUL_R_ENOMEM;
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_package_pre_event_send(uid_t uid, bundle* b) {
+ if (b == nullptr) {
+ _E("Invalid paremeter");
+ return AUL_R_EINVAL;
+ }
+
+ if (!IsAmdReady())
+ return AUL_R_OK;
+
+ return AppRequest(PKG_PRE_EVENT_SEND, uid)
+ .With(b)
+ .SendSimply();
+}
+
+extern "C" API int aul_app_get_appid_bypid_async(pid_t pid,
+ aul_appid_cb callback, void* user_data) {
+ if (pid < 1 || callback == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ if (getpid() == pid || getpgid(getpid()) == pid) {
+ context.Initialize();
+ const auto& preinit_appid = context.GetPreInitAppId();
+ if (!preinit_appid.empty()) {
+ callback(AUL_R_OK, pid, preinit_appid.c_str(), user_data);
+ return AUL_R_OK;
+ }
+ }
+
+ int fd = AppRequest(APP_GET_APPID_BYPID, getuid())
+ .SetPid(pid)
+ .SendSimply(AUL_SOCK_ASYNC);
+ if (fd < 0)
+ return AUL_R_ERROR;
+
+ try {
+ auto* result_info = new ResultInfo(pid, fd, callback, user_data);
+ result_info->Watch();
+ } catch (const std::exception& e) {
+ _E("Exception occurs. error: %s", e.what());
+ close(fd);
+ return AUL_R_ERROR;
+ }
+
+ return AUL_R_OK;
+}
--- /dev/null
+/*
+ * Copyright (c) 2023 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 <stdbool.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+bool aul_is_calling_appinfo_cb();
+
+int aul_app_get_status_from_current_appinfo(const char *appid, int *status);
+
+int aul_app_get_status_bypid_from_current_appinfo(int pid, int *status);
+
+#ifdef __cplusplus
+}
+#endif
--- /dev/null
+/*
+ * Copyright (c) 2020 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 <unistd.h>
+
+#include <memory>
+#include <type_traits>
+
+#include "aul/common/exception.hh"
+#include "aul/common/log_private.hh"
+#include "aul/socket/client.hh"
+
+namespace aul {
+
+namespace {
+
+// POD type
+class Header {
+ public:
+ int cmd;
+ int len;
+ int opt;
+};
+
+} // namespace
+
+Client::Client(std::string path, int timeout_msec) : Socket(std::move(path)) {
+ int retry = 2;
+ do {
+ int ret = Connect();
+ if (ret == 0) {
+ break;
+ } else if (ret < -1) {
+ _E("Maybe peer not launched or peer dead. path(%s), fd(%d)",
+ GetPath().c_str(), GetFd());
+ usleep(100 * 1000);
+ --retry;
+ } else if (ret < 0) {
+ _E("Failed to connect to socket(%s), fd(%d)",
+ GetPath().c_str(), GetFd());
+ THROW(-ECOMM);
+ }
+ } while (retry > 0);
+
+ if (retry == 0)
+ THROW(-ECOMM);
+
+ SetTimeout(timeout_msec);
+}
+
+int Client::Send(const Packet& packet) {
+ _W("cmd(%d)", packet.GetCmd());
+ tizen_base::Parcel parcel;
+ parcel.WriteParcelable(packet);
+ return Socket::Send(parcel.GetData(), parcel.GetDataSize());
+}
+
+int Client::Recv(Packet** packet) {
+ Header header;
+ static_assert(std::is_standard_layout<Header>(),
+ "Header should be POD type");
+ static_assert(std::is_trivial<Header>(), "Header should be POD type");
+
+ int ret = Socket::Recv(&header, sizeof(Header));
+ if (ret < 0)
+ return ret;
+
+ if (header.len < 0 || header.len > MAX_PAYLOAD_SIZE) {
+ _E("Invalid size(%d)", header.len);
+ return -ECOMM;
+ }
+
+ std::vector<unsigned char> buf(header.len);
+ ret = Socket::Recv(buf.data(), header.len);
+ if (ret < 0) {
+ return ret;
+ }
+
+ *packet = new (std::nothrow) Packet(header.cmd, header.opt, std::move(buf));
+ if (*packet == nullptr) {
+ _E("Out of memory");
+ return -ENOMEM;
+ }
+
+ return 0;
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2020 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_SOCKET_CLIENT_HH_
+#define AUL_SOCKET_CLIENT_HH_
+
+#include "aul/socket/packet.hh"
+#include "aul/socket/socket.hh"
+
+namespace aul {
+
+class Client : public Socket {
+ public:
+ explicit Client(std::string path, int timeout_msec = 5000);
+ int Send(const Packet& packet);
+ int Recv(Packet** packet);
+};
+
+} // namespace aul
+
+#endif // AUL_SOCKET_CLIENT_HH_
--- /dev/null
+/*
+ * Copyright (c) 2022 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 "aul/socket/client_socket.hh"
+
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <sys/un.h>
+#include <unistd.h>
+
+namespace aul {
+namespace {
+
+constexpr const int MAX_RETRY_CNT = 2;
+
+} // namespace
+
+ClientSocket::ClientSocket() {
+ fd_ = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
+ if (fd_ < 0) {
+ int error = -errno;
+ _E("socket() is failed. errno(%d)", errno);
+ THROW(error);
+ }
+}
+
+ClientSocket::ClientSocket(int fd) : fd_(fd) {}
+
+ClientSocket::~ClientSocket() {
+ Close();
+}
+
+void ClientSocket::Close() {
+ if (fd_ > -1) {
+ close(fd_);
+ fd_ = -1;
+ }
+}
+
+void ClientSocket::Connect(const std::string& endpoint) {
+ int flag = fcntl(fd_, F_GETFL, 0);
+ if (flag == -1) {
+ int ret = -errno;
+ _E("Failed to fcntl(%d, F_GETFL, 0). errno(%d)", fd_, errno);
+ THROW(ret);
+ }
+
+ fcntl(fd_, F_SETFL, flag | O_NONBLOCK);
+ struct sockaddr_un sockaddr = { 0, };
+ sockaddr.sun_family = AF_UNIX;
+ snprintf(sockaddr.sun_path, sizeof(sockaddr.sun_path), "%s",
+ endpoint.c_str());
+ struct sockaddr* sockaddr_ptr = reinterpret_cast<struct sockaddr*>(&sockaddr);
+ socklen_t len = static_cast<socklen_t>(sizeof(sockaddr));
+
+ int ret;
+ int retry = 2;
+ do {
+ ret = connect(fd_, sockaddr_ptr, len);
+ if (ret == 0)
+ break;
+
+ retry--;
+ ret = -errno;
+ usleep(100 * 1000);
+ } while (retry > 0);
+
+ fcntl(fd_, F_SETFL, flag);
+ if (ret < 0) {
+ _E("connect() is failed. errno(%d)", -ret);
+ THROW(ret);
+ }
+}
+
+int ClientSocket::Send(const void* buf, unsigned int size) {
+ const unsigned char* buffer = static_cast<const unsigned char*>(buf);
+ size_t len = size;
+ int retry_cnt = MAX_RETRY_CNT;
+ while (len) {
+ ssize_t bytes = send(fd_, buffer, len, MSG_NOSIGNAL | MSG_DONTWAIT);
+ if (bytes < 0) {
+ if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) {
+ if (retry_cnt > 0) {
+ retry_cnt--;
+ _E("send(): fd(%d), errno(%d). sleep and retry ...", fd_, errno);
+ usleep(10 * 1000);
+ continue;
+ }
+ }
+
+ _E("send() is failed. fd(%d), errno(%d)", fd_, errno);
+ return -ECOMM;
+ }
+
+ len -= bytes;
+ buffer += bytes;
+ }
+
+ return 0;
+}
+
+int ClientSocket::Receive(void* buf, unsigned int size) {
+ bool is_blocking;
+ if (fcntl(fd_, F_GETFL, 0) & O_NONBLOCK)
+ is_blocking = false;
+ else
+ is_blocking = true;
+
+ int retry_count = 20;
+ unsigned char* buffer = static_cast<unsigned char*>(buf);
+ size_t len = size;
+ while (len) {
+ ssize_t bytes = recv(fd_, buffer, len, 0);
+ if (bytes == 0) {
+ _W("EOF. fd(%d)", fd_);
+ return -ECOMM;
+ }
+
+ if (bytes < 0) {
+ if (errno == EINTR || errno == EAGAIN) {
+ if (is_blocking && errno == EAGAIN) {
+ _E("Timed out. fd(%d)", fd_);
+ return -EAGAIN;
+ }
+
+ if (retry_count > 0) {
+ usleep(100 * 1000);
+ retry_count--;
+ continue;
+ }
+ }
+
+ _E("recv() is failed. fd(%d), errno(%d)", fd_, errno);
+ return -ECOMM;
+ }
+
+ len -= bytes;
+ buffer += bytes;
+ }
+
+ return 0;
+}
+
+int ClientSocket::GetReceiveBufferSize() {
+ int value;
+ socklen_t len = sizeof(int);
+ int ret = getsockopt(fd_, SOL_SOCKET, SO_RCVBUF,
+ reinterpret_cast<void*>(&value), &len);
+ if (ret < 0) {
+ ret = -errno;
+ _E("getsockopt() is failed. errno(%d)", errno);
+ THROW(ret);
+ }
+
+ return value;
+}
+
+int ClientSocket::GetSendBufferSize() {
+ int value;
+ socklen_t len = sizeof(int);
+ int ret = getsockopt(fd_, SOL_SOCKET, SO_SNDBUF,
+ reinterpret_cast<void*>(&value), &len);
+ if (ret < 0) {
+ ret = -errno;
+ _E("getsockopt() is failed. errno(%d)", errno);
+ THROW(ret);
+ }
+
+ return value;
+}
+
+int ClientSocket::GetReceiveTimeout() {
+ struct timeval timeout = { 0, };
+ socklen_t len = static_cast<socklen_t>(sizeof(struct timeval));
+ int ret = getsockopt(fd_, SOL_SOCKET, SO_RCVTIMEO,
+ reinterpret_cast<void*>(&timeout), &len);
+ if (ret < 0) {
+ ret = -errno;
+ _E("getsockopt() is failed. errno(%d)", errno);
+ THROW(ret);
+ }
+
+ int value = timeout.tv_sec * 1000 + timeout.tv_usec / 1000;
+ return value;
+}
+
+void ClientSocket::SetReceiveBufferSize(int size) {
+ socklen_t len = sizeof(size);
+ int ret = setsockopt(fd_, SOL_SOCKET, SO_RCVBUF, &size, len);
+ if (ret < 0) {
+ ret = -errno;
+ _E("setsockopt() is failed. errno(%d)", errno);
+ THROW(ret);
+ }
+}
+
+void ClientSocket::SetSendBufferSize(int size) {
+ socklen_t len = sizeof(size);
+ int ret = setsockopt(fd_, SOL_SOCKET, SO_SNDBUF, &size, len);
+ if (ret < 0) {
+ ret = -errno;
+ _E("setsockopt() is failed. errno(%d)", errno);
+ THROW(ret);
+ }
+}
+
+void ClientSocket::SetReceiveTimeout(int timeout) {
+ if (timeout == INT_MAX)
+ return;
+
+ if (timeout == -1)
+ timeout = 5000;
+
+ if (timeout < 0) {
+ _E("Invalid parameter");
+ THROW(-EINVAL);
+ }
+
+ struct timeval tv = {
+ .tv_sec = static_cast<time_t>(timeout / 1000),
+ .tv_usec = static_cast<suseconds_t>((timeout % 1000) * 1000)
+ };
+ socklen_t len = static_cast<socklen_t>(sizeof(struct timeval));
+ int ret = setsockopt(fd_, SOL_SOCKET, SO_RCVTIMEO, &tv, len);
+ if (ret < 0) {
+ ret = -errno;
+ _E("setsockopt() is failed. errno(%d)", errno);
+ THROW(ret);
+ }
+}
+
+bool ClientSocket::IsClosed() {
+ return fd_ < 0;
+}
+
+int ClientSocket::GetFd() const {
+ return fd_;
+}
+
+int ClientSocket::RemoveFd() {
+ int fd = fd_;
+ fd_ = -1;
+ return fd;
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2022 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_SOCKET_CLIENT_SOCKET_HH_
+#define AUL_SOCKET_CLIENT_SOCKET_HH_
+
+#include <memory>
+#include <string>
+
+#include "aul/common/exception.hh"
+
+namespace aul {
+
+class ClientSocket {
+ public:
+ ClientSocket();
+ explicit ClientSocket(int fd);
+ virtual ~ClientSocket();
+
+ void Close();
+ void Connect(const std::string& endpoint);
+ int Send(const void* buf, unsigned int size);
+ int Receive(void* buf, unsigned int size);
+ int GetReceiveBufferSize();
+ int GetSendBufferSize();
+ int GetReceiveTimeout();
+ void SetReceiveBufferSize(int size);
+ void SetSendBufferSize(int size);
+ void SetReceiveTimeout(int timeout);
+ bool IsClosed();
+ int GetFd() const;
+ int RemoveFd();
+
+ private:
+ int fd_;
+};
+
+} // namespace aul
+
+#endif // AUL_SOCKET_CLIENT_SOCKET_HH_
--- /dev/null
+/*
+ * Copyright (c) 2020 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 <memory>
+
+#include "aul/socket/packet.hh"
+
+namespace aul {
+
+Packet::Packet() : cmd_(0), opt_(0) {
+}
+
+Packet::Packet(int cmd, int opt, std::vector<unsigned char> data)
+ : cmd_(cmd), opt_(opt), data_(std::move(data)) {
+}
+
+Packet::Packet(int cmd, int opt, tizen_base::Bundle data)
+ : cmd_(cmd), opt_(opt) {
+ auto raw = data.ToRaw();
+ auto* raw_ptr = reinterpret_cast<unsigned char*>(raw.first.get());
+ data_.insert(data_.end(), raw_ptr, raw_ptr + raw.second);
+}
+
+Packet::Packet(const unsigned char* buf, unsigned int size)
+ : cmd_(-1), opt_(0) {
+ tizen_base::Parcel parcel(buf, size);
+ parcel.ReadParcelable(this);
+}
+
+int Packet::GetCmd() const {
+ return cmd_;
+}
+
+int Packet::GetOpt() const {
+ return opt_;
+}
+
+const std::vector<unsigned char>& Packet::GetData() {
+ return data_;
+}
+
+void Packet::SetCmd(int cmd) {
+ cmd_ = cmd;
+}
+
+void Packet::SetOpt(int opt) {
+ opt_ = opt;
+}
+
+void Packet::SetData(std::vector<unsigned char> data) {
+ data_ = std::move(data);
+}
+
+tizen_base::Bundle Packet::DataToBundle() {
+ const bundle_raw* raw = reinterpret_cast<const bundle_raw*>(&data_[0]);
+ bundle* b = bundle_decode(raw, data_.size());
+ return tizen_base::Bundle(b, false, true);
+}
+
+void Packet::WriteToParcel(tizen_base::Parcel* parcel) const {
+ parcel->WriteInt32(cmd_);
+ parcel->WriteInt32(data_.size());
+ parcel->WriteInt32(opt_);
+ if (data_.size() > 0) {
+ auto* p = reinterpret_cast<const void*>(&data_[0]);
+ parcel->Write(p, data_.size());
+ }
+}
+
+void Packet::ReadFromParcel(tizen_base::Parcel* parcel) {
+ parcel->ReadInt32(&cmd_);
+ int size = 0;
+ parcel->ReadInt32(&size);
+ parcel->ReadInt32(&opt_);
+ if (size > 0) {
+ auto* data = new (std::nothrow) unsigned char[size];
+ if (data == nullptr)
+ return;
+
+ std::unique_ptr<unsigned char[]> ptr(data);
+ parcel->Read(data, size);
+ data_.insert(data_.end(), data, data + size);
+ }
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2020 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_SOCKET_PACKET_HH_
+#define AUL_SOCKET_PACKET_HH_
+
+#include <bundle_cpp.h>
+#include <parcel.hh>
+#include <parcelable.hh>
+
+#include <vector>
+
+namespace aul {
+
+class Packet : public tizen_base::Parcelable {
+ public:
+ Packet();
+ Packet(int cmd, int opt, std::vector<unsigned char> data);
+ Packet(int cmd, int opt, tizen_base::Bundle data);
+ Packet(const unsigned char* buf, unsigned int size);
+ virtual ~Packet() = default;
+
+ int GetCmd() const;
+ int GetOpt() const;
+ const std::vector<unsigned char>& GetData();
+
+ void SetCmd(int cmd);
+ void SetOpt(int opt);
+ void SetData(std::vector<unsigned char> data);
+
+ tizen_base::Bundle DataToBundle();
+
+ void WriteToParcel(tizen_base::Parcel* parcel) const override;
+ void ReadFromParcel(tizen_base::Parcel* parcel) override;
+
+ private:
+ int cmd_;
+ int opt_;
+ std::vector<unsigned char> data_;
+};
+
+} // namespace aul
+
+#endif // AUL_SOCKET_PACKET_HH_
--- /dev/null
+/*
+ * Copyright (c) 2022 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 "aul/socket/server_socket.hh"
+
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <sys/un.h>
+#include <unistd.h>
+
+#include "aul/common/exception.hh"
+#include "aul/common/log_private.hh"
+
+namespace aul {
+
+ServerSocket::ServerSocket() {
+ fd_ = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
+ if (fd_ < 0) {
+ fd_ = -errno;
+ _E("socket() is failed. errno(%d)", errno);
+ THROW(fd_);
+ }
+}
+
+ServerSocket::ServerSocket(int fd) : fd_(fd) {}
+
+ServerSocket::~ServerSocket() {
+ Close();
+}
+
+ClientSocket* ServerSocket::Accept() {
+ struct sockaddr_un addr = { 0, };
+ socklen_t len = static_cast<socklen_t>(sizeof(struct sockaddr_un));
+ auto* addr_ptr = reinterpret_cast<struct sockaddr*>(&addr);
+ int client_fd = accept(GetFd(), addr_ptr, &len);
+ if (client_fd == -1) {
+ _E("accept() is failed. errno(%d)", errno);
+ return nullptr;
+ }
+
+ ClientSocket* client = new (std::nothrow) ClientSocket(client_fd);
+ if (client == nullptr) {
+ _E("Out of memory");
+ close(client_fd);
+ return nullptr;
+ }
+
+ return client;
+}
+
+void ServerSocket::Bind(const std::string& bindpoint) {
+ struct sockaddr_un sockaddr = { 0, };
+ sockaddr.sun_family = AF_UNIX;
+ snprintf(sockaddr.sun_path, sizeof(sockaddr.sun_path), "%s",
+ bindpoint.c_str());
+ struct sockaddr* sockaddr_ptr = reinterpret_cast<struct sockaddr*>(&sockaddr);
+ socklen_t len = static_cast<socklen_t>(sizeof(sockaddr));
+
+ unlink(bindpoint.c_str());
+ int ret = bind(GetFd(), sockaddr_ptr, len);
+ if (ret < 0) {
+ ret = -errno;
+ _E("bind() is failed. errno(%d)", errno);
+ THROW(ret);
+ }
+}
+
+void ServerSocket::Close() {
+ if (fd_ > -1) {
+ close(fd_);
+ fd_ = -1;
+ }
+}
+
+void ServerSocket::Listen(int backlog) {
+ int ret = listen(fd_, backlog);
+ if (ret < 0) {
+ ret = -errno;
+ _E("listen() is failed. errno(%d)", errno);
+ THROW(ret);
+ }
+}
+
+int ServerSocket::GetReceiveBufferSize() {
+ int value;
+ socklen_t len = sizeof(int);
+ int ret = getsockopt(fd_, SOL_SOCKET, SO_RCVBUF,
+ reinterpret_cast<void*>(&value), &len);
+ if (ret < 0) {
+ ret = -errno;
+ _E("getsockopt() is failed. errno(%d)", errno);
+ THROW(ret);
+ }
+
+ return value;
+}
+
+int ServerSocket::GetSendBufferSize() {
+ int value;
+ socklen_t len = sizeof(int);
+ int ret = getsockopt(fd_, SOL_SOCKET, SO_SNDBUF,
+ reinterpret_cast<void*>(&value), &len);
+ if (ret < 0) {
+ ret = -errno;
+ _E("getsockopt() is failed. errno(%d)", errno);
+ THROW(ret);
+ }
+
+ return value;
+}
+
+void ServerSocket::SetReceiveBufferSize(int size) {
+ socklen_t len = sizeof(size);
+ int ret = setsockopt(fd_, SOL_SOCKET, SO_RCVBUF, &size, len);
+ if (ret < 0) {
+ ret = -errno;
+ _E("setsockopt() is failed. errno(%d)", errno);
+ THROW(ret);
+ }
+}
+
+void ServerSocket::SetSendBufferSize(int size) {
+ socklen_t len = sizeof(size);
+ int ret = setsockopt(fd_, SOL_SOCKET, SO_SNDBUF, &size, len);
+ if (ret < 0) {
+ ret = -errno;
+ _E("setsockopt() is failed. errno(%d)", errno);
+ THROW(ret);
+ }
+}
+
+bool ServerSocket::IsClosed() {
+ return fd_ < 0;
+}
+
+int ServerSocket::GetFd() const {
+ return fd_;
+}
+
+int ServerSocket::RemoveFd() {
+ int fd = fd_;
+ fd_ = -1;
+ return fd;
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2022 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_SOCKET_SERVER_SOCKET_HH_
+#define AUL_SOCKET_SERVER_SOCKET_HH_
+
+#include <memory>
+#include <string>
+
+#include "aul/common/exception.hh"
+#include "aul/socket/client_socket.hh"
+
+namespace aul {
+
+class ServerSocket {
+ public:
+ ServerSocket();
+ explicit ServerSocket(int fd);
+ virtual ~ServerSocket();
+
+ ClientSocket* Accept();
+ void Bind(const std::string& bindpoint);
+ void Close();
+ void Listen(int backlog);
+ int GetReceiveBufferSize();
+ int GetSendBufferSize();
+ void SetReceiveBufferSize(int size);
+ void SetSendBufferSize(int size);
+ bool IsClosed();
+ int GetFd() const;
+ int RemoveFd();
+
+ private:
+ int fd_;
+};
+
+} // namespace aul
+
+#endif // AUL_SOCKET_SERVER_SOCKET_HH_
--- /dev/null
+/*
+ * Copyright (c) 2020 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 <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <unistd.h>
+
+#include <algorithm>
+
+#include "aul/common/log_private.hh"
+#include "aul/socket/socket.hh"
+
+namespace aul {
+
+Socket::Socket(std::string path) : path_(std::move(path)), fd_(0) {
+ Create();
+}
+
+Socket::Socket(int fd)
+ : fd_(fd) {
+}
+
+Socket::~Socket() {
+ if (fd_ > 0)
+ close(fd_);
+}
+
+int Socket::Send(const void* buf, unsigned int size) {
+ const unsigned char* buffer = static_cast<const unsigned char*>(buf);
+ unsigned int left = size;
+ while (left) {
+ ssize_t nb = send(fd_, buffer, left, MSG_NOSIGNAL);
+ if (nb < 0) {
+ _E("send() is failed. fd(%d), errno(%d)", fd_, errno);
+ return -ECOMM;
+ }
+
+ left -= nb;
+ buffer += nb;
+ }
+
+ return 0;
+}
+
+int Socket::Recv(void* buf, unsigned int size) {
+ bool is_blocking = true;
+ if (fcntl(fd_, F_GETFL, 0) & O_NONBLOCK)
+ is_blocking = false;
+
+ int retry_count = 20;
+ unsigned char* buffer = static_cast<unsigned char*>(buf);
+ unsigned int left = size;
+ while (left) {
+ ssize_t nb = recv(fd_, buffer, left, 0);
+ if (nb == 0) {
+ _W("Socket was disconnected. fd(%d)", fd_);
+ return -ECOMM;
+ } else if (nb < 0) {
+ if (errno == EINTR) {
+ continue;
+ } else if (errno == EAGAIN) {
+ if (is_blocking) {
+ _E("Timed out. fd(%d)", fd_);
+ return -EAGAIN;
+ }
+
+ if (retry_count > 0) {
+ usleep(100 * 1000);
+ retry_count--;
+ continue;
+ }
+ }
+
+ _E("recv() is failed. fd(%d), errno(%d)", fd_, errno);
+ return -ECOMM;
+ }
+
+ left -= nb;
+ buffer += nb;
+ }
+
+ return 0;
+}
+
+int Socket::Listen() {
+ int ret = bind(fd_, reinterpret_cast<struct sockaddr*>(&addr_),
+ sizeof(addr_));
+ if (ret < 0) {
+ _E("bind() is failed. fd(%d), errno(%d)", fd_, errno);
+ return -1;
+ }
+
+ SetOption();
+
+ ret = listen(fd_, 128);
+ if (ret < 0) {
+ _E("listen() is failed. fd(%d), errno(%d)", fd_, errno);
+ return -1;
+ }
+
+ return 0;
+}
+
+int Socket::Connect() {
+ int flags = fcntl(fd_, F_GETFL, 0);
+ fcntl(fd_, F_SETFL, flags | O_NONBLOCK);
+
+ int ret = connect(fd_, reinterpret_cast<struct sockaddr*>(&addr_),
+ sizeof(addr_));
+ fcntl(fd_, F_SETFL, flags);
+ if (ret < 0) {
+ if (errno != EAGAIN && errno != EINPROGRESS)
+ return -2;
+ } else if (ret == 0) {
+ SetOption();
+ return 0;
+ }
+
+ fd_set readfds;
+ FD_ZERO(&readfds);
+ FD_SET(fd_, &readfds);
+ fd_set writefds = readfds;
+ struct timeval timeout = { 0, 100 * 1000 };
+ ret = select(fd_ + 1, &readfds, &writefds, NULL, &timeout);
+ if (ret == 0) {
+ errno = ETIMEDOUT;
+ return -1;
+ }
+
+ if (FD_ISSET(fd_, &readfds) || FD_ISSET(fd_, &writefds)) {
+ int error = 0;
+ socklen_t len = sizeof(error);
+ if (getsockopt(fd_, SOL_SOCKET, SO_ERROR, &error, &len) < 0)
+ return -1;
+ }
+
+ return -1;
+}
+
+int Socket::GetFd() const {
+ return fd_;
+}
+
+const std::string& Socket::GetPath() const {
+ return path_;
+}
+
+int Socket::RemoveFd() {
+ int fd = fd_;
+ fd_ = -1;
+ return fd;
+}
+
+void Socket::SetOption() {
+ int size = MAX_AUL_BUFF_SIZE;
+ int ret = setsockopt(fd_, SOL_SOCKET, SO_SNDBUF, &size, sizeof(size));
+ if (ret < 0) {
+ _E("setsockopt() is failed. fd(%d), errno(%d)", fd_, errno);
+ return;
+ }
+
+ ret = setsockopt(fd_, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size));
+ if (ret < 0) {
+ _E("setsockopt() is failed. fd(%d), errno(%d)", fd_, errno);
+ return;
+ }
+}
+
+void Socket::SetTimeout(int timeout_msec) {
+ if (timeout_msec == INT_MAX)
+ return;
+
+ if (timeout_msec == -1)
+ timeout_msec = 5000;
+
+ if (timeout_msec < 0) {
+ _E("Invalid timeout_msec parameter");
+ return;
+ }
+
+ struct timeval timeout = {
+ .tv_sec = static_cast<time_t>(timeout_msec / 1000),
+ .tv_usec = static_cast<suseconds_t>((timeout_msec % 1000) * 1000)
+ };
+ int ret = setsockopt(fd_, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
+ if (ret < 0)
+ _E("setsockopt() is failed. fd(%d), errno(%d)", fd_, errno);
+}
+
+void Socket::Create() {
+ fd_ = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
+ if (fd_ < 0) {
+ _E("socket() is failed. errno(%d)", errno);
+ return;
+ }
+
+ addr_.sun_family = AF_UNIX;
+ snprintf(addr_.sun_path, sizeof(addr_.sun_path), "%s", path_.c_str());
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2020 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_SOCKET_SOCKET_HH_
+#define AUL_SOCKET_SOCKET_HH_
+
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <sys/un.h>
+
+#include <string>
+
+namespace aul {
+
+static const char PATH_AMD_SOCK[] = "/run/aul/daemons/.amd-sock";
+static const int MAX_PAYLOAD_SIZE = 1024 * 1024 * 1;
+static const int MAX_AUL_BUFF_SIZE = 131071;
+
+class Socket {
+ public:
+ explicit Socket(std::string path);
+ explicit Socket(int fd);
+ virtual ~Socket();
+
+ int Send(const void* buf, unsigned int len);
+ int Recv(void* buf, unsigned int len);
+ int Listen();
+ int Connect();
+
+ int GetFd() const;
+ void SetTimeout(int timeout_msec);
+ const std::string& GetPath() const;
+ int RemoveFd();
+
+ private:
+ void SetOption();
+ void Create();
+
+ private:
+ std::string path_;
+ int fd_;
+ struct sockaddr_un addr_ = { 0, };
+};
+
+} // namespace aul
+
+#endif // AUL_SOCKET_SOCKET_HH_
--- /dev/null
+/*
+ * Copyright (c) 2000 - 2022 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 <bundle_cpp.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <list>
+#include <memory>
+#include <mutex>
+
+#include "aul/app_request.h"
+#include "aul/aul_api.h"
+#include "aul/aul_util.h"
+#include "aul/common/exception.hh"
+#include "aul/include/aul.h"
+#include "aul/include/aul_app_com.h"
+#include "aul/include/aul_error.h"
+#include "aul/include/aul_sock.h"
+#include "aul/launch.h"
+#include "aul/pkginfo_internal.h"
+
+using namespace aul::internal;
+
+struct status_listen_s {
+ void* dummy;
+};
+
+namespace {
+using namespace aul;
+
+class AppStatusEvent {
+ public:
+ AppStatusEvent(std::string appid, uid_t uid, app_status_cb cb,
+ void* user_data)
+ : appid_(std::move(appid)),
+ uid_(uid),
+ cb_(cb),
+ user_data_(user_data) {
+ std::string endpoint = "app_status_event:" + appid_;
+ if (uid_ < REGULAR_UID_MIN)
+ endpoint += ":" + std::to_string(uid_);
+
+ int ret = aul_app_com_create(endpoint.c_str(), nullptr, OnAppComCb, this,
+ &connection_);
+ if (ret != AUL_R_OK) {
+ _E("aul_app_com_create() is failed. endpoint(%s), error(%d)",
+ endpoint.c_str(), ret);
+ THROW(ret);
+ }
+ }
+
+ ~AppStatusEvent() {
+ if (connection_ != nullptr)
+ aul_app_com_leave(connection_);
+ }
+
+ private:
+ static int OnAppComCb(const char* endpoint, aul_app_com_result_e res,
+ bundle* envelope, void* user_data) {
+ tizen_base::Bundle b(envelope);
+ aul_app_info app_info = { 0, };
+ app_info.appid = const_cast<char*>(b.GetString(AUL_K_APPID).c_str());
+ app_info.pkgid = const_cast<char*>(b.GetString(AUL_K_PKGID).c_str());
+ app_info.app_path = const_cast<char*>(b.GetString(AUL_K_EXEC).c_str());
+ app_info.instance_id = const_cast<char*>(
+ b.GetString(AUL_K_INSTANCE_ID).c_str());
+ app_info.pid = std::stoi(b.GetString(AUL_K_PID));
+ app_info.status = std::stoi(b.GetString(AUL_K_STATUS));
+ app_info.is_sub_app = std::stoi(b.GetString(AUL_K_IS_SUBAPP));
+ int context_status = std::stoi(b.GetString("__CONTEXT_STATUS__"));
+
+ auto* event = static_cast<AppStatusEvent*>(user_data);
+ event->cb_(&app_info, context_status, event->user_data_);
+ return 0;
+ }
+
+ private:
+ std::string appid_;
+ uid_t uid_;
+ app_status_cb cb_;
+ void* user_data_;
+ aul_app_com_connection_h connection_ = nullptr;
+};
+
+class StatusLocalCb {
+ public:
+ StatusLocalCb(aul_status_local_cb cb, void* user_data)
+ : cb_(cb), user_data_(user_data) {
+ }
+
+ aul_status_local_cb GetCb() const {
+ return cb_;
+ }
+
+ void* GetUserData() const {
+ return user_data_;
+ }
+
+ int Invoke(int status) {
+ if (cb_ != nullptr)
+ return cb_(status, user_data_);
+
+ return 0;
+ }
+
+ private:
+ aul_status_local_cb cb_;
+ void* user_data_;
+};
+
+class Context {
+ public:
+ Context() = default;
+
+ int GetStatus() const {
+ return status_;
+ }
+
+ void SetStatus(int status) {
+ status_ = status;
+ }
+
+ void AddLocalCb(aul_status_local_cb cb, void* user_data) {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ cbs_.emplace_back(new StatusLocalCb(cb, user_data));
+ }
+
+ std::size_t RemoveLocalCb(aul_status_local_cb cb, void* user_data) {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ auto count = cbs_.size();
+ cbs_.remove_if([&](const std::unique_ptr<StatusLocalCb>& local_cb) {
+ return local_cb->GetCb() == cb &&
+ local_cb->GetUserData() == user_data;
+ });
+ return count - cbs_.size();
+ }
+
+ void InvokeLocalCb(int status) {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ auto iter = cbs_.begin();
+ while (iter != cbs_.end()) {
+ if ((*iter)->Invoke(status) < 0)
+ iter = cbs_.erase(iter);
+ else
+ iter++;
+ }
+ }
+
+ private:
+ int status_ = STATUS_LAUNCHING;
+ std::list<std::unique_ptr<StatusLocalCb>> cbs_;
+ std::recursive_mutex mutex_;
+};
+
+Context context;
+
+} // namespace
+
+extern "C" API int aul_status_update(int status) {
+ if (status < STATUS_LAUNCHING || status > STATUS_TERMINATE) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ if (context.GetStatus() == status)
+ return AUL_R_OK;
+
+ context.SetStatus(status);
+
+ int ret = aul_sock_send_raw(AUL_UTIL_PID, getuid(), APP_STATUS_UPDATE,
+ reinterpret_cast<unsigned char*>(&status), sizeof(status),
+ AUL_SOCK_NOREPLY);
+ if (ret == 0)
+ context.InvokeLocalCb(status);
+ else
+ ret = aul_error_convert(ret);
+
+ return ret;
+}
+
+extern "C" API int aul_app_get_status_bypid(int pid) {
+ return aul_app_get_status_bypid_for_uid(pid, getuid());
+}
+
+extern "C" API int aul_app_get_status_bypid_for_uid(int pid, uid_t uid) {
+ if (pid < 0) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ if (pid == getpid())
+ return context.GetStatus();
+
+ if (aul_is_calling_appinfo_cb()) {
+ int status = -1;
+ aul_app_get_status_bypid_from_current_appinfo(pid, &status);
+ if (status != -1)
+ return status;
+ }
+
+ return AppRequest(APP_GET_STATUS, uid)
+ .SetPid(pid)
+ .SendSimply();
+}
+
+extern "C" API int aul_app_get_status(const char* appid) {
+ return aul_app_get_status_for_uid(appid, getuid());
+}
+
+extern "C" API int aul_app_get_status_for_uid(const char* appid, uid_t uid) {
+ if (appid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ if (aul_is_calling_appinfo_cb()) {
+ int status = -1;
+ aul_app_get_status_from_current_appinfo(appid, &status);
+ if (status != -1 && status != STATUS_VISIBLE)
+ return status;
+ }
+
+ return AppRequest(APP_GET_STATUS_BY_APPID, uid)
+ .SetAppId(appid)
+ .SendSimply();
+}
+
+extern "C" API int aul_add_status_local_cb(aul_status_local_cb callback,
+ void* user_data) {
+ if (callback == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_ERROR;
+ }
+
+ context.RemoveLocalCb(callback, user_data);
+ context.AddLocalCb(callback, user_data);
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_remove_status_local_cb(aul_status_local_cb callback,
+ void* user_data) {
+ if (callback == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_ERROR;
+ }
+
+ if (context.RemoveLocalCb(callback, user_data) > 0)
+ return AUL_R_OK;
+
+ return AUL_R_EINVAL;
+}
+
+extern "C" API int aul_invoke_status_local_cb(int status) {
+ if (status < STATUS_LAUNCHING || status > STATUS_TERMINATE) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ context.InvokeLocalCb(status);
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_set_process_group(int owner_pid, int child_pid) {
+ if (owner_pid < 1 || child_pid < 1) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ tizen_base::Bundle b {
+ { AUL_K_OWNER_PID, std::to_string(owner_pid) },
+ { AUL_K_CHILD_PID, std::to_string(child_pid) }
+ };
+
+ return AppRequest(APP_SET_PROCESS_GROUP, getuid())
+ .With(std::move(b))
+ .SendSimply();
+}
+
+extern "C" API int aul_listen_app_status(const char* appid,
+ app_status_cb callback, void* user_data, status_listen_h* handle) {
+ return aul_listen_app_status_for_uid(appid, callback, user_data, handle,
+ getuid());
+}
+
+extern "C" API int aul_listen_app_status_for_uid(const char* appid,
+ app_status_cb callback, void* user_data, status_listen_h* handle,
+ uid_t uid) {
+ if (appid == nullptr || callback == nullptr || handle == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ try {
+ auto* event = new (std::nothrow) AppStatusEvent(
+ appid, uid, callback, user_data);
+ if (event == nullptr) {
+ _E("Out of memory");
+ return AUL_R_ENOMEM;
+ }
+
+ *handle = reinterpret_cast<status_listen_h>(event);
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%s)", e.what());
+ return e.GetErrorCode();
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_ignore_app_status(status_listen_h handle) {
+ if (handle == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* event = reinterpret_cast<AppStatusEvent*>(handle);
+ delete event;
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_notify_exit(void) {
+ return AppRequest(APP_NOTIFY_EXIT, getuid())
+ .SendCmdOnly(AUL_SOCK_NOREPLY);
+}
+
+extern "C" API int aul_notify_start(void) {
+ return AppRequest(APP_NOTIFY_START, getuid())
+ .SendCmdOnly(AUL_SOCK_NOREPLY);
+}
+
+extern "C" API const char* aul_app_status_convert_to_string(int status) {
+ switch (status) {
+ case STATUS_LAUNCHING:
+ return "STATUS_LAUNCHING";
+ case STATUS_CREATED:
+ return "STATUS_CREATED";
+ case STATUS_FOCUS:
+ return "STATUS_FOCUS";
+ case STATUS_VISIBLE:
+ return "STATUS_VISIBLE";
+ case STATUS_BG:
+ return "STATUS_BG";
+ case STATUS_DYING:
+ return "STATUS_DYING";
+ case STATUS_HOME:
+ return "STATUS_HOME";
+ case STATUS_NORESTART:
+ return "STATUS_NORESTART";
+ case STATUS_SERVICE:
+ return "STATUS_SERVICE";
+ case STATUS_TERMINATE:
+ return "STATUS_TERMINATE";
+ default:
+ return "Unknown status";
+ }
+}
+
+extern "C" API int aul_status_update_v2(int status) {
+ if (status < STATUS_LAUNCHING || status > STATUS_TERMINATE) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ if (context.GetStatus() == status)
+ return AUL_R_OK;
+
+ context.SetStatus(status);
+
+ tizen_base::Bundle b { { AUL_K_STATUS, std::to_string(status) } };
+ int ret = AppRequest(APP_STATUS_UPDATE_V2, getuid())
+ .With(std::move(b))
+ .SendSimply();
+ if (ret != 0) {
+ _E("Failed to update app status. error(%d)", ret);
+ return ret;
+ }
+
+ context.InvokeLocalCb(status);
+ return AUL_R_OK;
+}
--- /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.
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <string.h>
+#include <ctype.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <glib.h>
+#include <bundle.h>
+#include <bundle_internal.h>
+#include <tzplatform_config.h>
+
+#include "aul.h"
+#include "aul_api.h"
+#include "aul_app_com.h"
+#include "aul_cmd.h"
+#include "aul_error.h"
+#include "aul_sock.h"
+#include "aul_util.h"
+#include "aul_widget.h"
+#include "launch.h"
+
+struct aul_widget_info_s {
+ char *widget_id;
+ char *instance_id;
+ char *app_id;
+ char *package_id;
+ char *app_path;
+ unsigned int surf;
+ pid_t pid;
+};
+
+struct widget_cb_info {
+ aul_widget_info_cb callback;
+ void *user_data;
+};
+
+struct widget_event_s {
+ aul_app_com_connection_h conn;
+ aul_widget_event_cb callback;
+ void *user_data;
+};
+
+#define WIDGET_LOG_BUFFER_SIZE 10000
+#define WIDGET_LOG_BUFFER_STRING_SIZE 256
+
+static int __log_index;
+static int __log_fd;
+static bool __log_init = false;
+static struct widget_event_s __event;
+
+static int __init_log(void)
+{
+ int offset;
+ char buffer[512] = {0, };
+ char caller[255] = {0, };
+ int ret;
+
+ ret = aul_app_get_appid_bypid(getpid(), caller, sizeof(caller));
+ if (ret != AUL_R_OK) {
+ _E("Failed to get appid by pid(%d)", getpid());
+ return -1;
+ }
+
+ snprintf(buffer, sizeof(buffer),
+ "/run/aul/log/widget/%d/widget_%s.log", getuid(), caller);
+ __log_fd = open(buffer, O_CREAT | O_WRONLY, 0644);
+ if (__log_fd < 0) {
+ _E("Failed to open %s - %d", buffer, errno);
+ return -1;
+ }
+
+ offset = lseek(__log_fd, 0, SEEK_END);
+ if (offset != 0) {
+ __log_index = (int)(offset / WIDGET_LOG_BUFFER_STRING_SIZE);
+ if (__log_index >= WIDGET_LOG_BUFFER_SIZE) {
+ __log_index = 0;
+ lseek(__log_fd, 0, SEEK_SET);
+ }
+ }
+ __log_init = true;
+
+ return 0;
+}
+
+API int aul_widget_write_log(const char *tag, const char *format, ...)
+{
+ int ret;
+ int offset;
+ time_t now;
+ char time_buf[32] = {0,};
+ char format_buffer[WIDGET_LOG_BUFFER_STRING_SIZE];
+ char buffer[WIDGET_LOG_BUFFER_SIZE];
+ va_list ap;
+
+ if (!__log_init)
+ __init_log();
+
+ if (__log_fd < 0) {
+ _E("Invalid file descriptor");
+ return -1;
+ }
+
+ time(&now);
+ ctime_r(&now, time_buf);
+ if (__log_index != 0)
+ offset = lseek(__log_fd, 0, SEEK_CUR);
+ else
+ offset = lseek(__log_fd, 0, SEEK_SET);
+
+ if (offset == -1)
+ _E("error in lseek: %d", errno);
+
+
+ va_start(ap, format);
+ vsnprintf(format_buffer, sizeof(format_buffer), format, ap);
+ va_end(ap);
+
+ snprintf(buffer, sizeof(buffer), "[%-6d][%-5d] %-15s %-50s %s",
+ getpid(), __log_index, tag, format_buffer, time_buf);
+
+ ret = write(__log_fd, buffer, strlen(buffer));
+ if (ret < 0) {
+ _E("Cannot write the amd log: %d", ret);
+ return -1;
+ }
+
+ if (++__log_index >= WIDGET_LOG_BUFFER_SIZE)
+ __log_index = 0;
+
+ return 0;
+}
+
+static const char *__to_appid(const char *widget_id)
+{
+ const char *appid;
+ appid = g_strstr_len(widget_id, strlen(widget_id), "@") + 1;
+ if (appid != (const char *)1) {
+ if (appid > widget_id + (sizeof(char) * strlen(widget_id)))
+ appid = (char *)widget_id;
+ } else {
+ appid = (char *)widget_id;
+ }
+
+ return appid;
+}
+
+API int aul_widget_instance_add(const char *widget_id, const char *instance_id)
+{
+ int ret;
+ bundle *kb;
+
+ if (widget_id == NULL || instance_id == NULL)
+ return AUL_R_EINVAL;
+
+ kb = bundle_create();
+ if (kb == NULL) {
+ _E("out of memory");
+ return AUL_R_ERROR;
+ }
+
+ bundle_add_str(kb, AUL_K_WIDGET_ID, widget_id);
+ bundle_add_str(kb, AUL_K_WIDGET_INSTANCE_ID, instance_id);
+
+ ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), WIDGET_ADD, kb,
+ AUL_SOCK_NONE);
+
+ bundle_free(kb);
+ if (ret < 0)
+ return aul_error_convert(ret);
+
+ return AUL_R_OK;
+}
+
+API int aul_widget_instance_del(const char *widget_id, const char *instance_id)
+{
+ int ret;
+ bundle *kb;
+
+ if (widget_id == NULL || instance_id == NULL)
+ return AUL_R_EINVAL;
+
+ kb = bundle_create();
+ if (kb == NULL) {
+ _E("out of memory");
+ return AUL_R_ERROR;
+ }
+
+ bundle_add_str(kb, AUL_K_WIDGET_ID, widget_id);
+ bundle_add_str(kb, AUL_K_WIDGET_INSTANCE_ID, instance_id);
+
+ ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), WIDGET_DEL, kb,
+ AUL_SOCK_NONE);
+
+ bundle_free(kb);
+ if (ret < 0)
+ return aul_error_convert(ret);
+
+ return AUL_R_OK;
+}
+
+struct __cb_data {
+ aul_widget_instance_foreach_cb cb;
+ void *data;
+};
+
+static void __foreach_cb(const char *key, const int type,
+ const bundle_keyval_t *kv, void *user_data)
+{
+ struct __cb_data *cb_data = (struct __cb_data *)user_data;
+
+ cb_data->cb(key, cb_data->data);
+}
+
+API int aul_widget_instance_foreach(const char *widget_id,
+ aul_widget_instance_foreach_cb cb, void *data)
+{
+ int ret;
+ int fd;
+ bundle *kb;
+ app_pkt_t *pkt = NULL;
+ bundle *list_kb = NULL;
+ struct __cb_data cb_data;
+
+ if (widget_id == NULL)
+ return AUL_R_EINVAL;
+
+ kb = bundle_create();
+ if (kb == NULL) {
+ _E("out of memory");
+ return AUL_R_ERROR;
+ }
+
+ bundle_add_str(kb, AUL_K_APPID, __to_appid(widget_id));
+ bundle_add_str(kb, AUL_K_WIDGET_ID, widget_id);
+
+ fd = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), WIDGET_LIST, kb,
+ AUL_SOCK_ASYNC);
+
+ if (fd > 0) {
+ ret = aul_sock_recv_reply_pkt(fd, &pkt);
+ if (ret < 0 || pkt == NULL) {
+ _E("failed to get instance list of %s", widget_id);
+ } else {
+ list_kb = bundle_decode(pkt->data, pkt->len);
+ if (list_kb) {
+ cb_data.cb = cb;
+ cb_data.data = data;
+ bundle_foreach(list_kb, __foreach_cb, &cb_data);
+ bundle_free(list_kb);
+ }
+ }
+ } else {
+ ret = fd;
+ }
+
+ if (pkt)
+ free(pkt);
+
+ bundle_free(kb);
+
+ if (ret < 0)
+ return aul_error_convert(ret);
+
+ return AUL_R_OK;
+}
+
+API int aul_widget_instance_update(const char *widget_id,
+ const char *instance_id, bundle *param)
+{
+ int ret;
+ bundle *kb = param;
+ const char *appid;
+
+ if (widget_id == NULL)
+ return AUL_R_EINVAL;
+
+ if (kb == NULL)
+ kb = bundle_create();
+
+ if (kb == NULL) {
+ _E("out of memory");
+ return AUL_R_ERROR;
+ }
+
+ appid = __to_appid(widget_id);
+
+ bundle_add_str(kb, AUL_K_WIDGET_ID, widget_id);
+
+ if (instance_id)
+ bundle_add_str(kb, AUL_K_WIDGET_INSTANCE_ID, instance_id);
+
+ ret = app_request_to_launchpad_for_uid(WIDGET_UPDATE, appid, kb,
+ getuid());
+
+ if (param == NULL)
+ bundle_free(kb);
+
+ return ret;
+}
+
+API int aul_widget_instance_get_content(const char *widget_id,
+ const char *instance_id, char **content)
+{
+ int ret;
+ bundle *kb;
+ int fd[2] = { 0, };
+ app_pkt_t *pkt = NULL;
+
+ if (widget_id == NULL || instance_id == NULL || content == NULL)
+ return AUL_R_EINVAL;
+
+ kb = bundle_create();
+ if (kb == NULL) {
+ _E("out of memory");
+ return AUL_R_ERROR;
+ }
+
+ bundle_add_str(kb, AUL_K_APPID, __to_appid(widget_id));
+ bundle_add_str(kb, AUL_K_WIDGET_ID, widget_id);
+ bundle_add_str(kb, AUL_K_WIDGET_INSTANCE_ID, instance_id);
+
+ ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), WIDGET_GET_CONTENT,
+ kb, AUL_SOCK_ASYNC);
+ if (ret > 0) {
+ ret = aul_sock_recv_reply_sock_fd(ret, &fd, 1);
+ if (ret == 0) {
+ ret = aul_sock_recv_reply_pkt(fd[0], &pkt);
+ if (ret == 0 && pkt && pkt->cmd == 0) {
+ *content = strdup((const char *)pkt->data);
+ _D("recieved content: %s", *content);
+ } else {
+ if (pkt)
+ ret = pkt->cmd;
+
+ _E("failed to get content");
+ }
+ } else {
+ _E("failed to get socket fd:%d", ret);
+ }
+ }
+
+ bundle_free(kb);
+
+ if (pkt)
+ free(pkt);
+ if (ret < 0)
+ ret = aul_error_convert(ret);
+
+ return ret;
+}
+
+API int aul_widget_instance_count(const char *widget_id)
+{
+ int ret;
+ bundle *kb;
+
+ if (widget_id == NULL)
+ return AUL_R_EINVAL;
+
+ kb = bundle_create();
+ if (kb == NULL) {
+ _E("out of memory");
+ return AUL_R_ERROR;
+ }
+
+ bundle_add_str(kb, AUL_K_WIDGET_ID, widget_id);
+ ret = app_send_cmd(AUL_UTIL_PID, WIDGET_COUNT, kb);
+ bundle_free(kb);
+
+ return ret;
+}
+
+static void __foreach_widget_info(app_pkt_t *pkt, void *user_data)
+{
+ struct widget_cb_info *cb_info = (struct widget_cb_info *)user_data;
+ struct aul_widget_info_s info = { 0, };
+ bundle *b = NULL;
+ const char *val;
+
+ if (pkt == NULL || cb_info == NULL) {
+ _E("Invalid parameter");
+ return;
+ }
+
+ if (pkt->cmd == APP_GET_INFO_ERROR) {
+ _E("Failed to get widget info");
+ return;
+ }
+
+ if (pkt->opt & AUL_SOCK_BUNDLE)
+ b = bundle_decode(pkt->data, pkt->len);
+
+ if (b == NULL)
+ return;
+
+ bundle_get_str(b, AUL_K_WIDGET_ID, &info.widget_id);
+ if (info.widget_id == NULL) {
+ bundle_free(b);
+ return;
+ }
+
+ bundle_get_str(b, AUL_K_WIDGET_INSTANCE_ID, &info.instance_id);
+ if (info.instance_id == NULL) {
+ bundle_free(b);
+ return;
+ }
+
+ bundle_get_str(b, AUL_K_APPID, &info.app_id);
+ if (info.app_id == NULL) {
+ bundle_free(b);
+ return;
+ }
+
+ bundle_get_str(b, AUL_K_PKGID, &info.package_id);
+ if (info.package_id == NULL) {
+ bundle_free(b);
+ return;
+ }
+
+ bundle_get_str(b, AUL_K_EXEC, &info.app_path);
+ if (info.app_path == NULL) {
+ bundle_free(b);
+ return;
+ }
+
+ val = bundle_get_val(b, AUL_K_WID);
+ if (val && isdigit(*val))
+ info.surf = strtoul(val, NULL, 10);
+
+ val = bundle_get_val(b, AUL_K_PID);
+ if (val && isdigit(*val))
+ info.pid = atoi(val);
+
+ cb_info->callback(&info, cb_info->user_data);
+
+ bundle_free(b);
+}
+
+API int aul_widget_info_foreach_for_uid(aul_widget_info_cb callback,
+ void *user_data, uid_t uid)
+{
+ struct widget_cb_info cb_info = {callback, user_data};
+ char buf[MAX_PID_STR_BUFSZ];
+ bundle *b;
+ int fd;
+ int r;
+
+ if (callback == NULL) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ b = bundle_create();
+ if (b == NULL) {
+ _E("Out of memory");
+ return AUL_R_ERROR;
+ }
+
+ snprintf(buf, sizeof(buf), "%u", uid);
+ r = bundle_add_str(b, AUL_K_TARGET_UID, buf);
+ if (r != BUNDLE_ERROR_NONE) {
+ _E("Failed to add target uid(%u)", uid);
+ bundle_free(b);
+ return AUL_R_ERROR;
+ }
+
+ fd = aul_sock_send_bundle(AUL_UTIL_PID, uid, WIDGET_RUNNING_INFO,
+ b, AUL_SOCK_ASYNC);
+ if (fd < 0) {
+ bundle_free(b);
+ return aul_error_convert(fd);
+ }
+ bundle_free(b);
+
+ r = aul_sock_recv_pkt_with_cb(fd, __foreach_widget_info, &cb_info);
+ if (r < 0)
+ return aul_error_convert(r);
+
+ return AUL_R_OK;
+}
+
+API int aul_widget_info_foreach(aul_widget_info_cb callback, void *user_data)
+{
+ return aul_widget_info_foreach_for_uid(callback, user_data, getuid());
+}
+
+API int aul_widget_info_get_pid(aul_widget_info_h info, pid_t *pid)
+{
+ if (info == NULL || pid == NULL) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ *pid = info->pid;
+
+ return AUL_R_OK;
+}
+
+API int aul_widget_info_get_surface_id(aul_widget_info_h info,
+ unsigned int *surf)
+{
+ if (info == NULL || surf == NULL) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ *surf = info->surf;
+
+ return AUL_R_OK;
+}
+
+API int aul_widget_info_get_widget_id(aul_widget_info_h info, char **widget_id)
+{
+ if (info == NULL || widget_id == NULL) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ *widget_id = strdup(info->widget_id);
+ if (*widget_id == NULL) {
+ _E("Out of memory");
+ return AUL_R_ERROR;
+ }
+
+ return AUL_R_OK;
+}
+
+API int aul_widget_info_get_instance_id(aul_widget_info_h info,
+ char **instance_id)
+{
+ if (info == NULL || instance_id == NULL) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ *instance_id = strdup(info->instance_id);
+ if (*instance_id == NULL) {
+ _E("Out of memory");
+ return AUL_R_ERROR;
+ }
+
+ return AUL_R_OK;
+}
+
+API int aul_widget_info_get_app_id(aul_widget_info_h info, char **app_id)
+{
+ if (info == NULL || app_id == NULL) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ *app_id = strdup(info->app_id);
+ if (*app_id == NULL) {
+ _E("Out of memory");
+ return AUL_R_ERROR;
+ }
+
+ return AUL_R_OK;
+}
+
+API int aul_widget_info_get_package_id(aul_widget_info_h info,
+ char **package_id)
+{
+ if (info == NULL || package_id == NULL) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ *package_id = strdup(info->package_id);
+ if (*package_id == NULL) {
+ _E("Out of memory");
+ return AUL_R_ERROR;
+ }
+
+ return AUL_R_OK;
+}
+
+API int aul_widget_info_get_app_path(aul_widget_info_h info, char **app_path)
+{
+ if (info == NULL || app_path == NULL) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ *app_path = strdup(info->app_path);
+ if (*app_path == NULL) {
+ _E("Out of memory");
+ return AUL_R_ERROR;
+ }
+
+ return AUL_R_OK;
+}
+
+API int aul_widget_instance_change_status(const char *widget_id,
+ const char *status)
+{
+ int ret;
+ bundle *kb;
+
+ kb = bundle_create();
+ if (kb == NULL) {
+ _E("out of memory");
+ return AUL_R_ERROR;
+ }
+
+ bundle_add_str(kb, AUL_K_STATUS, status);
+ bundle_add_str(kb, AUL_K_WIDGET_ID, widget_id);
+ ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(),
+ WIDGET_CHANGE_STATUS, kb, AUL_SOCK_NOREPLY);
+
+ bundle_free(kb);
+ if (ret < 0) {
+ _E("send error %d, %s", ret, status);
+ return aul_error_convert(ret);
+ }
+
+ return AUL_R_OK;
+}
+
+API int aul_widget_service_set_disable(const char *widget_id, bool is_disable)
+{
+ int ret;
+ bundle *kb;
+ char ambient_mode[32] = {0, };
+
+ if (widget_id == NULL)
+ return AUL_R_EINVAL;
+
+ kb = bundle_create();
+ if (kb == NULL) {
+ _E("out of memory");
+ return AUL_R_ERROR;
+ }
+
+ snprintf(ambient_mode, sizeof(ambient_mode), "%d", (int)is_disable);
+
+ bundle_add_str(kb, AUL_K_APPID, __to_appid(widget_id));
+ bundle_add_str(kb, AUL_K_WIDGET_ID, widget_id);
+ bundle_add_str(kb, AUL_K_WIDGET_DISABLE, ambient_mode);
+
+ ret = app_send_cmd(AUL_UTIL_PID, WIDGET_DISABLE, kb);
+ if (ret)
+ _E("widget disable send cmd error");
+
+ bundle_free(kb);
+
+ return ret;
+}
+
+static int __aul_widget_event_cb(const char *endpoint,
+ aul_app_com_result_e result,
+ bundle *envelope,
+ void *user_data)
+{
+ const char *event_name;
+ const char *event_data_raw;
+ bundle *event_data;
+
+ event_name = bundle_get_val(envelope, AUL_K_EVENT_NAME);
+ if (!event_name) {
+ _E("Failed to get event name");
+ return -1;
+ }
+
+ event_data_raw = bundle_get_val(envelope, AUL_K_EVENT_DATA);
+ if (!event_data_raw) {
+ _E("Failed to get event data");
+ return -1;
+ }
+
+ event_data = bundle_decode((const bundle_raw *)event_data_raw,
+ strlen(event_data_raw));
+ if (!event_data) {
+ _E("Failed to decode event data");
+ return -1;
+ }
+
+ if (__event.callback)
+ __event.callback(event_name, event_data, __event.user_data);
+
+ bundle_free(event_data);
+
+ return 0;
+}
+
+static int __register_widget_event(void)
+{
+ int ret;
+
+ if (!__event.conn) {
+ ret = aul_app_com_create("widget.event", NULL,
+ __aul_widget_event_cb, NULL,
+ &__event.conn);
+ if (ret != AUL_R_OK) {
+ _E("Failed to join aul app com");
+ return ret;
+ }
+ }
+
+ return AUL_R_OK;
+}
+
+static int __unregister_widget_event(void)
+{
+ if (__event.conn) {
+ aul_app_com_leave(__event.conn);
+ __event.conn = NULL;
+ }
+
+ return AUL_R_OK;
+}
+
+API int aul_widget_set_event_cb(aul_widget_event_cb callback, void *user_data)
+{
+ if (!callback) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ __event.callback = callback;
+ __event.user_data = user_data;
+
+ return __register_widget_event();
+}
+
+API int aul_widget_unset_event_cb(void)
+{
+ __event.callback = NULL;
+ __event.user_data = NULL;
+
+ return __unregister_widget_event();
+}
+
+API int aul_widget_send_event(const char *event_name, bundle *event_data)
+{
+ bundle *b;
+ bundle_raw *raw = NULL;
+ int len = 0;
+ int ret;
+
+ if (!event_name || !event_data) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ b = bundle_create();
+ if (!b) {
+ _E("Out of memory");
+ return AUL_R_ENOMEM;
+ }
+
+ bundle_add(b, AUL_K_EVENT_NAME, event_name);
+
+ bundle_encode(event_data, &raw, &len);
+ if (!raw) {
+ _E("Failed to encode event data");
+ bundle_free(b);
+ return AUL_R_ERROR;
+ }
+
+ bundle_add(b, AUL_K_EVENT_DATA, (const char *)raw);
+ free(raw);
+
+ ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), WIDGET_EVENT, b,
+ AUL_SOCK_NOREPLY);
+ bundle_free(b);
+ if (ret != 0) {
+ _E("Failed to send widget event. error(%d)", ret);
+ return aul_error_convert(ret);
+ }
+
+ return AUL_R_OK;
+}
+
+API int aul_widget_send_status_to_viewer(const char *class_id,
+ const char *instance_id, const char *viewer_endpoint,
+ int status, int err, bundle *extra)
+{
+ bundle *data;
+ bundle_raw *raw = NULL;
+ int len;
+ char err_str[256];
+ int ret;
+
+ data = bundle_create();
+ if (!data) {
+ _E("out of memory");
+ return -1;
+ }
+
+ if (err < 0) {
+ snprintf(err_str, sizeof(err_str), "%d", err);
+ bundle_add_str(data, AUL_K_WIDGET_ERROR_CODE, err_str);
+ }
+
+ bundle_add_str(data, AUL_K_WIDGET_ID, class_id);
+ bundle_add_str(data, AUL_K_WIDGET_INSTANCE_ID, instance_id);
+ bundle_add_byte(data, AUL_K_WIDGET_STATUS, &status, sizeof(int));
+
+ if (extra) {
+ bundle_encode(extra, &raw, &len);
+ bundle_add_str(data,
+ "__WIDGET_CONTENT_INFO__", (const char *)raw);
+ free(raw);
+ ret = aul_widget_instance_add(class_id, instance_id);
+ if (ret != 0) {
+ _E("Failed to add instance. error(%d)", ret);
+ bundle_free(data);
+ return aul_error_convert(ret);
+ }
+ }
+
+ LOGD("send update %s(%d) to %s", instance_id, status, viewer_endpoint);
+ ret = aul_app_com_send(viewer_endpoint, data);
+ bundle_free(data);
+ if (ret != 0) {
+ _E("Failed to add instance. error(%d)", ret);
+ return aul_error_convert(ret);
+ }
+
+ return 0;
+}
+
+API int aul_widget_send_status_to_service(const char *class_id,
+ const char *instance_id, const char *sender_pkgid, int status)
+{
+ bundle *data = bundle_create();
+ int ret;
+
+ if (data == NULL) {
+ _E("out of memory");
+ return -1;
+ }
+
+ bundle_add_str(data, AUL_K_WIDGET_ID, class_id);
+ bundle_add_str(data, AUL_K_WIDGET_INSTANCE_ID, instance_id);
+ bundle_add_byte(data, AUL_K_WIDGET_STATUS, &status, sizeof(int));
+ bundle_add_str(data, AUL_K_PKGID, sender_pkgid);
+
+ LOGD("send lifecycle %s(%d)", instance_id, status);
+ ret = aul_app_com_send("widget.status", data);
+ if (ret < 0)
+ _E("send lifecycle error:%d", ret);
+
+ bundle_free(data);
+ 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.
- */
-
-#ifndef API
-#define API __attribute__ ((visibility("default")))
-#endif
+++ /dev/null
-/*
- * Copyright (c) 2018 - 2020 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 "aul_api.h"
-#include "aul_cmd.h"
-
-API const char *aul_cmd_convert_to_string(int cmd)
-{
- static const char *cmd_string_table[] = {
- "APP_START",
-
- "APP_OPEN",
- "APP_RESUME",
- "APP_RESUME_BY_PID",
- "APP_TERM_BY_PID",
- "APP_TERM_BY_PID_WITHOUT_RESTART",
- "APP_RESULT",
- "APP_START_RES",
- "APP_CANCEL",
- "APP_KILL_BY_PID",
- "APP_UPDATE_RUA_STAT",
-
- "APP_ADD_HISTORY",
- "APP_REMOVE_HISTORY",
- "APP_RUNNING_INFO",
- "APP_RUNNING_INFO_RESULT",
- "APP_IS_RUNNING",
- "APP_GET_APPID_BYPID",
- "APP_GET_PKGID_BYPID",
- "APP_GET_INFO_OK",
- "APP_GET_INFO_ERROR",
- "APP_KEY_EVENT",
-
- "APP_KEY_RESERVE",
- "APP_KEY_RELEASE",
- "APP_STATUS_UPDATE",
- "APP_RUNNING_LIST_UPDATE",
- "APP_TERM_REQ_BY_PID",
- "APP_TERM_BY_PID_ASYNC",
- "APP_TERM_BGAPP_BY_PID",
- "APP_PAUSE",
- "APP_PAUSE_BY_PID",
- "APP_GROUP_GET_WINDOW",
-
- "APP_GROUP_SET_WINDOW",
- "APP_GROUP_GET_FG",
- "APP_GROUP_GET_LEADER_PID",
- "APP_GROUP_GET_LEADER_PIDS",
- "APP_GROUP_GET_GROUP_PIDS",
- "APP_GROUP_GET_IDLE_PIDS",
- "APP_GROUP_LOWER",
- "APP_GROUP_CLEAR_TOP",
- "APP_GROUP_ACTIVATE_BELOW",
- "APP_GET_STATUS",
-
- "APP_ADD_LOADER",
- "APP_REMOVE_LOADER",
- "APP_GET_PID",
- "APP_GET_DC_SOCKET_PAIR",
- "APP_GET_MP_SOCKET_PAIR",
- "APP_COM_CREATE",
- "APP_COM_JOIN",
- "APP_COM_SEND",
- "APP_COM_LEAVE",
- "APP_COM_MESSAGE",
-
- "WIDGET_ADD",
- "WIDGET_DEL",
- "WIDGET_LIST",
- "WIDGET_UPDATE",
- "WIDGET_COUNT",
- "WIDGET_GET_CONTENT",
- "APP_REGISTER_PID",
- "APP_WAKE",
- "APP_SUSPEND",
- "AMD_RELOAD_APPINFO",
-
- "LAUNCHPAD_DEAD_SIGNAL",
- "APP_ALL_RUNNING_INFO",
- "APP_SET_APP_CONTROL_DEFAULT_APP",
- "APP_UNSET_APP_CONTROL_DEFAULT_APP",
- "APP_START_ASYNC",
- "APP_SET_PROCESS_GROUP",
- "APP_PREPARE_CANDIDATE_PROCESS",
- "APP_TERM_BY_PID_SYNC",
- "APP_GET_STATUS_BY_APPID",
- "APP_GET_LAST_CALLER_PID",
-
- "APP_TERM_BY_PID_SYNC_WITHOUT_RESTART",
- "APP_RESUME_BY_PID_ASYNC",
- "APP_SET_ALIAS_APPID",
- "APP_UNSET_ALIAS_APPID",
- "APP_ENABLE_ALIAS_INFO",
- "APP_DISABLE_ALIAS_INFO",
- "APP_GROUP_ACTIVATE_ABOVE",
- "ADD_APP_SCREEN",
- "REMOVE_APP_SCREEN",
- "APP_UPDATE_REQUESTED",
-
- "ADD_SCREEN_VIEWER",
- "REMOVE_SCREEN_VIEWER",
- "LAUNCHPAD_LAUNCH_SIGNAL",
- "APP_RUNNING_INSTANCE_INFO",
- "APP_GET_INSTANCE_ID_BYPID",
- "APP_SET_CACHE",
- "APP_GET_APPID_FROM_CACHE",
- "APP_INVALIDATE_CACHE",
- "APP_STARTUP_SIGNAL",
- "APP_WINDOW_ATTACH",
-
- "APP_WINDOW_DETACH",
- "APP_START_RES_ASYNC",
- "APP_NOTIFY_EXIT",
- "APP_GET_APPID_BY_SURFACE_ID",
- "APP_GET_INSTANCE_ID_BY_SURFACE_ID",
- "UPDATE_SCREEN_VIEWER_STATUS",
- "WIDGET_RUNNING_INFO",
- "JOB_STATUS_UPDATE",
- "WIDGET_CHANGE_STATUS",
- "RPC_PORT_PREPARE_STUB",
-
- "RPC_PORT_CREATE_SOCKET_PAIR",
- "RPC_PORT_NOTIFY_RPC_FINISHED",
- "COMPLICATION_UPDATE_REQUEST",
- "APP_NOTIFY_START",
- "WATCHDOG_ENABLE",
- "WATCHDOG_DISABLE",
- "WATCHDOG_PING",
- "WATCHDOG_KICK",
- "APP_SEND_LAUNCH_REQUEST",
- "APP_SEND_LAUNCH_REQUEST_SYNC",
-
- "COMP_NOTIFY_START",
- "COMP_NOTIFY_EXIT",
- "COMP_STATUS_UPDATE",
- "APP_TERM_INSTANCE_ASYNC",
- "APP_GROUP_SET_WINDOW_V2",
- "APP_GROUP_LOWER_V2",
- "APP_GROUP_GET_LEADER_IDS",
- "APP_GROUP_GET_GROUP_INFO",
- "APP_GROUP_GET_IDLE_INFO",
- "COMP_CONTEXT_FOREACH",
-
- "COMP_CONTEXT_GET",
- "COMP_CONTEXT_IS_RUNNING",
- "COMP_CONTEXT_RESUME",
- "COMP_CONTEXT_PAUSE",
- "COMP_CONTEXT_TERMINATE_BG_COMP",
- "COMP_CONTEXT_TERMINATE",
- "APP_RESUME_INSTANCE",
- "APP_PAUSE_INSTANCE",
- "APP_TERM_BG_INSTANCE",
- "LAUNCHPAD_CHILD_PROCESS", /* unused */
-
- "COMP_INFO_GET",
- "COMP_INFO_FOREACH",
- "APP_TERMINATE",
- "APP_IS_RUNNING_V2",
- "ANR_NOTIFY",
- "APP_GET_RUNNING_CONTEXT",
- "LAUNCHER_SERVICE_NOTIFY_ANIMATION_STARTED",
- "LAUNCHER_SERVICE_NOTIFY_ANIMATION_FINISHED",
- "APP_SEND_RESUME_REQUEST",
- "APP_PREPARE_APP_DEFINED_LOADER",
-
- "WIDGET_DISABLE",
- "TRIGGER_APP_SCREEN_FOCUSED_FORCE",
- "WIDGET_EVENT",
- "SET_PRIVATE_SHARING",
- "UNSET_PRIVATE_SHARING",
- "APP_CONTEXT_GET",
- "APP_CONTEXT_GET_BY_INSTANCE_ID",
- "APP_CONTEXT_GET_BY_PID",
- "APP_GROUP_ADD",
- "APP_GROUP_REMOVE",
-
- "APP_GET_APPID_LIST",
- "COMP_PORT_EXIST",
- "COMP_PORT_CREATE",
- "COMP_PORT_DESTROY",
- "APP_LIFECYCLE_UPDATE_STATE",
-
- "APP_STATUS_UPDATE_V2",
- "APP_GET_APP_CONTROL_DEFAULT_APPS",
- "APP_GET_APPID_BY_ALIAS_APPID",
- "APP_GET_APP_CONTROL_DEFAULT_APP",
- "APP_LIFECYCLE_GET_STATE",
-
- "PROC_REGISTER",
- "PROC_DEREGISTER",
- "PROC_GET_NAME",
- "PROC_GET_EXTRA",
- "RPC_PORT_CREATE",
-
- "RPC_PORT_DESTROY",
- "RPC_PORT_EXIST",
- "APP_WINDOW_ATTACH_BELOW",
- "PROC_GROUP_ADD",
- "PROC_GROUP_REMOVE",
-
- "APP_CONNECT",
- "APP_SET_AUTO_RESTART",
- "BOOT_SEQUENCE_START_APP",
- "BOOT_SEQUENCE_GET_APPINFO_LIST",
- "BOOT_SEQUENCE_RELOAD",
-
- "PKG_PRE_EVENT_SEND",
- "PROC_GROUP_FOREACH",
- "PROC_GROUP_GET",
-
- "CUSTOM_COMMAND"
- };
-
- if (cmd < 0 || cmd >= APP_CMD_MAX)
- return cmd_string_table[APP_CMD_MAX];
-
- return cmd_string_table[cmd];
-}
+++ /dev/null
-/*
- * Copyright (c) 2019 - 2022 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul_comp_context.h"
-
-#include <bundle_cpp.h>
-
-#include <memory>
-#include <string>
-#include <vector>
-
-#include "app_request.h"
-#include "aul_api.h"
-#include "aul_util.h"
-#include "include/aul.h"
-#include "include/aul_error.h"
-
-#include "aul/common/exception.hh"
-#include "aul/component/component_running_context.hh"
-
-using namespace aul;
-
-struct aul_comp_context_s {
- void* dummy;
-};
-
-namespace {
-using namespace aul::internal;
-
-ComponentRunningContext* CreateComponentRunningContext(
- const tizen_base::Bundle& b) {
- return ComponentRunningContext::Builder()
- .SetComponentId(b)
- .SetInstanceId(b)
- .SetAppId(b)
- .SetType(b)
- .SetPid(b)
- .SetStatus(b)
- .SetSubComponent(b);
-}
-
-ComponentRunningContext* GetComponentRunningContext(
- const std::string& component_id, uid_t uid) {
- tizen_base::Bundle b { { AUL_K_COMPONENT_ID, component_id } };
- int fd = AppRequest(COMP_CONTEXT_GET, uid)
- .With(std::move(b))
- .SendSimply(AUL_SOCK_ASYNC);
- if (fd < 0)
- THROW(fd);
-
- app_pkt_t* pkt;
- int ret = aul_sock_recv_reply_pkt(fd, &pkt);
- if (ret < 0)
- THROW(aul_error_convert(fd));
-
- auto pkt_auto = std::unique_ptr<app_pkt_t, decltype(std::free)*>(
- pkt, std::free);
-
- if (pkt->cmd != APP_GET_INFO_OK) {
- _E("Failed to get component running context. error(%d)", pkt->cmd);
- THROW(pkt->cmd);
- }
-
- bundle* kb = nullptr;
- if (pkt->opt & AUL_SOCK_BUNDLE) {
- kb = bundle_decode(pkt->data, pkt->len);
- if (kb == nullptr)
- THROW(AUL_R_ENOMEM);
- } else {
- _E("Wrong packet");
- THROW(AUL_R_ERROR);
- }
-
- return CreateComponentRunningContext(tizen_base::Bundle(kb, false, true));
-}
-
-std::vector<std::unique_ptr<ComponentRunningContext>>
-GetComponentRunningContexts() {
- int fd = AppRequest(COMP_CONTEXT_FOREACH, getuid())
- .SendSimply(AUL_SOCK_ASYNC);
- if (fd < 0)
- THROW(fd);
-
- std::vector<std::unique_ptr<ComponentRunningContext>> contexts;
- int ret = aul_sock_recv_pkt_with_cb(fd,
- [](app_pkt_t* pkt, void* user_data) {
- if (pkt == nullptr) {
- _E("pkt is nullptr");
- return;
- }
-
- if (pkt->cmd == APP_GET_INFO_ERROR) {
- _E("Failed to get component running context");
- return;
- }
-
- bundle* kb = nullptr;
- if (pkt->opt & AUL_SOCK_BUNDLE)
- kb = bundle_decode(pkt->data, pkt->len);
-
- if (kb == nullptr)
- return;
-
- tizen_base::Bundle b(kb, false, true);
- auto* context_array =
- static_cast<std::vector<std::unique_ptr<ComponentRunningContext>>*>(
- user_data);
-
- try {
- context_array->emplace_back(CreateComponentRunningContext(b));
- } catch (const Exception& e) {
- _E("Exception occurs. error(%s)", e.what());
- }
- }, &contexts);
- if (ret < 0)
- THROW(aul_error_convert(ret));
-
- return contexts;
-}
-
-int SendRequest(ComponentRunningContext* context, int cmd) {
- tizen_base::Bundle b {
- { AUL_K_COMPONENT_ID, context->GetComponentId() },
- { AUL_K_INSTANCE_ID, context->GetInstanceId() }
- };
-
- int ret = AppRequest(cmd, getuid())
- .With(std::move(b))
- .SendSimply();
- if (ret < 0)
- THROW(ret);
-
- return ret;
-}
-
-} // namespace
-
-extern "C" API int aul_comp_context_foreach_comp_context(
- aul_comp_context_cb callback, void* user_data) {
- if (callback == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- try {
- for (auto const& context : GetComponentRunningContexts()) {
- auto* handle = reinterpret_cast<aul_comp_context_h>(context.get());
- if (!callback(handle, user_data))
- break;
- }
- } catch (const Exception& e) {
- _E("Exception occurs. error(%d)", e.GetErrorCode());
- return e.GetErrorCode();
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_comp_context_get_comp_id(aul_comp_context_h handle,
- const char** comp_id) {
- if (handle == nullptr || comp_id == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* context = reinterpret_cast<ComponentRunningContext*>(handle);
- *comp_id = context->GetComponentId().c_str();
- return AUL_R_OK;
-}
-
-extern "C" API int aul_comp_context_get_instance_id(aul_comp_context_h handle,
- const char** instance_id) {
- if (handle == nullptr || instance_id == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* context = reinterpret_cast<ComponentRunningContext*>(handle);
- *instance_id = context->GetInstanceId().c_str();
- return AUL_R_OK;
-}
-
-extern "C" API int aul_comp_context_get_app_id(aul_comp_context_h handle,
- const char** app_id) {
- if (handle == nullptr || app_id == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* context = reinterpret_cast<ComponentRunningContext*>(handle);
- *app_id = context->GetAppId().c_str();
- return AUL_R_OK;
-}
-
-extern "C" API int aul_comp_context_get_type(aul_comp_context_h handle,
- const char** type) {
- if (handle == nullptr || type == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* context = reinterpret_cast<ComponentRunningContext*>(handle);
- *type = context->GetType().c_str();
- return AUL_R_OK;
-}
-
-extern "C" API int aul_comp_context_get_pid(aul_comp_context_h handle,
- pid_t* pid) {
- if (handle == nullptr || pid == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* context = reinterpret_cast<ComponentRunningContext*>(handle);
- *pid = context->GetPid();
- return AUL_R_OK;
-}
-
-extern "C" API int aul_comp_context_get_status(aul_comp_context_h handle,
- int* status) {
- if (handle == nullptr || status == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* context = reinterpret_cast<ComponentRunningContext*>(handle);
- *status = context->GetStatus();
- return AUL_R_OK;
-}
-
-extern "C" API int aul_comp_context_is_sub_comp(aul_comp_context_h handle,
- bool* is_sub_comp) {
- if (handle == nullptr || is_sub_comp == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* context = reinterpret_cast<ComponentRunningContext*>(handle);
- *is_sub_comp = context->IsSubComponent();
- return AUL_R_OK;
-}
-
-extern "C" API int aul_comp_context_create(const char* comp_id,
- aul_comp_context_h* handle) {
- return aul_comp_context_usr_create(comp_id, getuid(), handle);
-}
-
-extern "C" API int aul_comp_context_usr_create(const char* comp_id,
- uid_t uid, aul_comp_context_h* handle) {
- if (comp_id == nullptr || handle == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- try {
- auto* context = GetComponentRunningContext(comp_id, uid);
- if (context == nullptr)
- return AUL_R_ENOMEM;
-
- *handle = reinterpret_cast<aul_comp_context_h>(context);
- } catch (const Exception& e) {
- _E("Exception occurs. error(%d)", e.GetErrorCode());
- return e.GetErrorCode();
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_comp_context_destroy(aul_comp_context_h handle) {
- if (handle == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* context = reinterpret_cast<ComponentRunningContext*>(handle);
- delete context;
- return AUL_R_OK;
-}
-
-extern "C" API int aul_comp_context_clone(aul_comp_context_h handle,
- aul_comp_context_h* clone) {
- if (handle == nullptr || clone == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* context = reinterpret_cast<ComponentRunningContext*>(handle);
- auto* cloned_context = new (std::nothrow) ComponentRunningContext(*context);
- if (cloned_context == nullptr) {
- _E("Out of memory");
- return AUL_R_ENOMEM;
- }
-
- *clone = reinterpret_cast<aul_comp_context_h>(cloned_context);
- return AUL_R_OK;
-}
-
-extern "C" API int aul_comp_context_is_running(aul_comp_context_h handle,
- bool* running) {
- if (handle == nullptr || running == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- try {
- auto* context = reinterpret_cast<ComponentRunningContext*>(handle);
- int ret = SendRequest(context, COMP_CONTEXT_IS_RUNNING);
- *running = (ret == 0) ? false : true;
- } catch (const Exception& e) {
- _E("Exception occurs. error(%d)", e.GetErrorCode());
- return e.GetErrorCode();
- }
-
- return AUL_R_OK;
-}
-
-extern "C" int aul_comp_context_resume(aul_comp_context_h handle) {
- if (handle == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- try {
- auto* context = reinterpret_cast<ComponentRunningContext*>(handle);
- SendRequest(context, COMP_CONTEXT_RESUME);
- } catch (const Exception& e) {
- _E("Exception occurs. error(%d)", e.GetErrorCode());
- return e.GetErrorCode();
- }
-
- return AUL_R_OK;
-}
-
-extern "C" int aul_comp_context_pause(aul_comp_context_h handle) {
- if (handle == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- try {
- auto* context = reinterpret_cast<ComponentRunningContext*>(handle);
- SendRequest(context, COMP_CONTEXT_PAUSE);
- } catch (const Exception& e) {
- _E("Exception occurs. error(%d)", e.GetErrorCode());
- return e.GetErrorCode();
- }
-
- return AUL_R_OK;
-}
-
-extern "C" int aul_comp_context_terminate_bg_comp(aul_comp_context_h handle) {
- if (handle == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- try {
- auto* context = reinterpret_cast<ComponentRunningContext*>(handle);
- SendRequest(context, COMP_CONTEXT_TERMINATE_BG_COMP);
- } catch (const Exception& e) {
- _E("Exception occurs. error(%d)", e.GetErrorCode());
- return e.GetErrorCode();
- }
-
- return AUL_R_OK;
-}
-
-extern "C" int aul_comp_context_terminate(aul_comp_context_h handle) {
- if (handle == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- try {
- auto* context = reinterpret_cast<ComponentRunningContext*>(handle);
- SendRequest(context, COMP_CONTEXT_TERMINATE);
- } catch (const Exception& e) {
- _E("Exception occurs. error(%d)", e.GetErrorCode());
- return e.GetErrorCode();
- }
-
- return AUL_R_OK;
-}
+++ /dev/null
-/*
- * Copyright (c) 2019 - 2022 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul_comp_info.h"
-
-#include <vconf.h>
-
-#include <cctype>
-#include <memory>
-#include <string>
-#include <vector>
-
-#include "app_request.h"
-#include "aul_api.h"
-#include "aul_util.h"
-#include "include/aul.h"
-#include "include/aul_error.h"
-#include "include/aul_sock.h"
-
-#include "aul/common/exception.hh"
-#include "aul/component/component_info.hh"
-
-using namespace aul;
-
-namespace {
-using namespace aul::internal;
-
-constexpr const char kDefaultLocale[] = "No Locale";
-
-std::string GetSystemLocale() {
- char* lang = vconf_get_str(VCONFKEY_LANGSET);
- if (lang == nullptr) {
- lang = strdup(kDefaultLocale);
- if (lang == nullptr) {
- _E("strdup() is failed");
- THROW(AUL_R_ENOMEM);
- }
- }
-
- auto lang_auto = std::unique_ptr<char, decltype(std::free)*>(lang, std::free);
-
- return std::string({
- lang[0],
- lang[1],
- '-',
- static_cast<char>(std::tolower(static_cast<int>(lang[3]))),
- static_cast<char>(std::tolower(static_cast<int>(lang[4])))
- });
-}
-
-ComponentInfo* CreateComponentInfoFromAppPacket(
- app_pkt_t* pkt) {
- if (pkt->cmd != APP_GET_INFO_OK)
- THROW(aul_error_convert(pkt->cmd));
-
- bundle* kb = nullptr;
- if (pkt->opt & AUL_SOCK_BUNDLE) {
- kb = bundle_decode(pkt->data, pkt->len);
- if (kb == nullptr)
- THROW(AUL_R_ENOMEM);
- } else {
- THROW(AUL_R_ERROR);
- }
-
- tizen_base::Bundle b(kb, false, true);
- return ComponentInfo::Builder()
- .SetAppId(b)
- .SetComponentId(b)
- .SetType(b)
- .SetLaunchMode(b)
- .SetMainComponent(b)
- .SetIconDisplay(b)
- .SetTaskmanage(b)
- .SetLocalizedInfo(b);
-}
-
-ComponentInfo* GetComponentInfo(const char* comp_id,
- uid_t uid) {
- tizen_base::Bundle b { { AUL_K_COMPONENT_ID, comp_id } };
- int fd = AppRequest(COMP_INFO_GET, uid)
- .With(std::move(b))
- .SendSimply(AUL_SOCK_ASYNC);
- if (fd < 0)
- THROW(fd);
-
- app_pkt_t* pkt = nullptr;
- int ret = aul_sock_recv_reply_pkt(fd, &pkt);
- if (ret < 0)
- THROW(aul_error_convert(ret));
-
- auto pkt_auto = std::unique_ptr<app_pkt_t, decltype(std::free)*>(
- pkt, std::free);
- return CreateComponentInfoFromAppPacket(pkt);
-}
-
-std::vector<std::shared_ptr<ComponentInfo>> GetComponentInfos(uid_t uid) {
- int fd = AppRequest(COMP_INFO_FOREACH, uid)
- .SendSimply(AUL_SOCK_ASYNC);
- if (fd < 0)
- THROW(fd);
-
- std::vector<std::shared_ptr<ComponentInfo>> component_infos;
- int ret = aul_sock_recv_pkt_with_cb(fd,
- [](app_pkt_t* pkt, void* user_data) {
- if (pkt == nullptr)
- return;
-
- try {
- auto* infos =
- static_cast<std::vector<std::shared_ptr<ComponentInfo>>*>(
- user_data);
- infos->emplace_back(CreateComponentInfoFromAppPacket(pkt));
- } catch (const Exception& e) {
- _E("Exception occurs. error(%s)", e.what());
- }
- }, &component_infos);
- if (ret < 0)
- THROW(aul_error_convert(ret));
-
- return component_infos;
-}
-
-} // namespace
-
-extern "C" API int aul_comp_info_create(const char* comp_id,
- aul_comp_info_h* handle) {
- return aul_comp_info_usr_create(comp_id, getuid(), handle);
-}
-
-extern "C" API int aul_comp_info_usr_create(const char* comp_id, uid_t uid,
- aul_comp_info_h* handle) {
- if(comp_id == nullptr || handle == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- try {
- auto* info = GetComponentInfo(comp_id, uid);
- *handle = static_cast<aul_comp_info_h>(info);
- } catch (const Exception& e) {
- _E("Exception occurs. error(%s)", e.what());
- return e.GetErrorCode();
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_comp_info_destroy(aul_comp_info_h handle) {
- if (handle == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* info = static_cast<ComponentInfo*>(handle);
- delete info;
- return AUL_R_OK;
-}
-
-extern "C" API int aul_comp_info_clone(aul_comp_info_h handle,
- aul_comp_info_h* clone) {
- if (handle == nullptr || clone == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* info = static_cast<ComponentInfo*>(handle);
- auto* cloned_info = new (std::nothrow) ComponentInfo(*info);
- if (cloned_info == nullptr) {
- _E("Out of memory");
- return AUL_R_ENOMEM;
- }
-
- *clone = static_cast<aul_comp_info_h>(cloned_info);
- return AUL_R_OK;
-}
-
-extern "C" API int aul_comp_info_get_app_id(aul_comp_info_h handle,
- const char** app_id) {
- if (handle == nullptr || app_id == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* info = static_cast<ComponentInfo*>(handle);
- *app_id = info->GetAppId().c_str();
- return AUL_R_OK;
-}
-
-extern "C" API int aul_comp_info_get_comp_id(aul_comp_info_h handle,
- const char** comp_id) {
- if (handle == nullptr || comp_id == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* info = static_cast<ComponentInfo*>(handle);
- *comp_id = info->GetComponentId().c_str();
- return AUL_R_OK;
-}
-
-extern "C" API int aul_comp_info_get_type(aul_comp_info_h handle,
- const char** type) {
- if (handle == nullptr || type == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* info = static_cast<ComponentInfo*>(handle);
- *type = info->GetType().c_str();
- return AUL_R_OK;
-}
-
-extern "C" API int aul_comp_info_get_launch_mode(aul_comp_info_h handle,
- const char** launch_mode) {
- if (handle == nullptr || launch_mode == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* info = static_cast<ComponentInfo*>(handle);
- *launch_mode = info->GetLaunchMode().c_str();
- return AUL_R_OK;
-}
-
-extern "C" API int aul_comp_info_is_main_comp(aul_comp_info_h handle,
- bool* main_comp) {
- if (handle == nullptr || main_comp == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* info = static_cast<ComponentInfo*>(handle);
- *main_comp = info->IsMainComponent();
- return AUL_R_OK;
-}
-
-extern "C" API int aul_comp_info_is_icon_display(aul_comp_info_h handle,
- bool* icon_display) {
- if (handle == nullptr || icon_display == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* info = static_cast<ComponentInfo*>(handle);
- *icon_display = info->IsIconDisplay();
- return AUL_R_OK;
-}
-
-extern "C" API int aul_comp_info_is_taskmanage(aul_comp_info_h handle,
- bool* taskmanage) {
- if (handle == nullptr || taskmanage == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* info = static_cast<ComponentInfo*>(handle);
- *taskmanage = info->IsTaskmanage();
- return AUL_R_OK;
-}
-
-extern "C" API int aul_comp_info_get_icon(aul_comp_info_h handle,
- const char** icon) {
- if (handle == nullptr || icon == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* info = static_cast<ComponentInfo*>(handle);
- try {
- auto* localized_info = info->GetLocalizedInfo(GetSystemLocale());
- if (localized_info == nullptr) {
- localized_info = info->GetLocalizedInfo(kDefaultLocale);
- if (localized_info == nullptr)
- return AUL_R_ENOENT;
- }
-
- *icon = localized_info->GetIcon().c_str();
- } catch (const Exception& e) {
- _E("Exception occurs. error(%s)", e.what());
- return e.GetErrorCode();
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_comp_info_get_label(aul_comp_info_h handle,
- const char** label) {
- if (handle == nullptr || label == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* info = static_cast<ComponentInfo*>(handle);
- try {
- auto* localized_info = info->GetLocalizedInfo(GetSystemLocale());
- if (localized_info == nullptr) {
- localized_info = info->GetLocalizedInfo(kDefaultLocale);
- if (localized_info == nullptr)
- return AUL_R_ENOENT;
- }
-
- *label = localized_info->GetLabel().c_str();
- } catch (const Exception& e) {
- _E("Exception occurs. error(%s)", e.what());
- return e.GetErrorCode();
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_comp_info_get_localed_label(aul_comp_info_h handle,
- const char* locale, const char** label) {
- if (handle == nullptr || locale == nullptr || label == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* info = static_cast<ComponentInfo*>(handle);
- auto* localized_info = info->GetLocalizedInfo(locale);
- if (localized_info == nullptr) {
- localized_info = info->GetLocalizedInfo(kDefaultLocale);
- if (localized_info == nullptr)
- return AUL_R_ENOENT;
- }
-
- *label = localized_info->GetLabel().c_str();
- return AUL_R_OK;
-}
-
-extern "C" API int aul_comp_info_foreach_comp_info_from_app(const char* app_id,
- aul_comp_info_cb callback, void* user_data) {
- return aul_comp_info_usr_foreach_comp_info_from_app(app_id, getuid(),
- callback, user_data);
-}
-
-extern "C" API int aul_comp_info_usr_foreach_comp_info_from_app(
- const char* app_id, uid_t uid, aul_comp_info_cb callback, void* user_data) {
- if (app_id == nullptr || callback == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- try {
- for (auto const& info : GetComponentInfos(uid)) {
- if (info->GetAppId().compare(app_id) != 0)
- continue;
-
- if (!callback(info.get(), user_data))
- break;
- }
- } catch (const Exception& e) {
- _E("Exception occurs. error(%s)", e.what());
- return e.GetErrorCode();
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_comp_info_foreach_comp_info(aul_comp_info_cb callback,
- void* user_data) {
- return aul_comp_info_usr_foreach_comp_info(getuid(), callback, user_data);
-}
-
-extern "C" API int aul_comp_info_usr_foreach_comp_info(uid_t uid,
- aul_comp_info_cb callback, void* user_data) {
- if (callback == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- try {
- for (auto const& info : GetComponentInfos(uid)) {
- if (!callback(info.get(), user_data))
- break;
- }
- } catch (const Exception& e) {
- _E("Exception occurs. error(%s)", e.what());
- return e.GetErrorCode();
- }
-
- return AUL_R_OK;
-}
+++ /dev/null
-/*
- * Copyright (c) 2019 - 2022 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul_comp_status.h"
-
-#include <bundle_cpp.h>
-
-#include "include/aul.h"
-#include "include/aul_sock.h"
-#include "include/aul_error.h"
-#include "aul_util.h"
-#include "aul_api.h"
-
-#include "app_request.h"
-
-using namespace aul::internal;
-
-extern "C" API int aul_comp_status_update(const char* instance_id, int status) {
- if (instance_id == nullptr ||
- status < STATUS_LAUNCHING ||
- status > STATUS_TERMINATE) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- tizen_base::Bundle b {
- { AUL_K_INSTANCE_ID, instance_id },
- { AUL_K_STATUS, std::to_string(status) },
- };
-
- return AppRequest(COMP_STATUS_UPDATE, getuid())
- .With(std::move(b))
- .SendSimply(AUL_SOCK_NOREPLY);
-}
-
-extern "C" API int aul_comp_notify_start(const char* instance_id) {
- if (instance_id == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- return AppRequest(COMP_NOTIFY_START, getuid())
- .SetInstId(instance_id)
- .SendSimply(AUL_SOCK_NOREPLY);
-}
-
-extern "C" API int aul_comp_notify_exit(const char* instance_id) {
- if (instance_id == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- return AppRequest(COMP_NOTIFY_EXIT, getuid())
- .SetInstId(instance_id)
- .SendSimply(AUL_SOCK_NOREPLY);
-}
-
-extern "C" API int aul_comp_resume(const char* instance_id) {
- if (instance_id == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- return AppRequest(COMP_CONTEXT_RESUME, getuid())
- .SetInstId(instance_id)
- .SendSimply();
-}
-
-extern "C" API int aul_comp_terminate(const char* instance_id) {
- if (instance_id == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- return AppRequest(COMP_CONTEXT_TERMINATE, getuid())
- .SetInstId(instance_id)
- .SendSimply();
-}
-
-extern "C" API int aul_comp_is_running(const char* instance_id, bool* running) {
- if (instance_id == nullptr || running == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- int ret = AppRequest(COMP_CONTEXT_IS_RUNNING, getuid())
- .SetInstId(instance_id)
- .SendSimply();
- if (ret < 0)
- return ret;
-
- *running = (ret == 0) ? false : true;
- return AUL_R_OK;
-}
+++ /dev/null
-/*
- * Copyright (c) 2018 - 2022 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul_complication.h"
-
-#include <bundle_cpp.h>
-
-#include <string>
-
-#include "app_request.h"
-#include "aul_api.h"
-#include "aul_util.h"
-#include "include/aul.h"
-#include "include/aul_sock.h"
-
-using namespace aul::internal;
-
-namespace {
-
-constexpr const char kUpdateRequest[] = "__UPDATE_REQUEST__";
-constexpr const char kLaunchRequest[] = "__LAUNCH_REQUEST__";
-
-} // namespace
-
-extern "C" API int aul_complication_update_request(const char* appid,
- const char* provider_appid, uid_t uid) {
- if (appid == nullptr || provider_appid == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- tizen_base::Bundle b {
- { AUL_K_CALLER_APPID, appid },
- { AUL_K_COMPLICATION_MODE, kUpdateRequest}
- };
-
- int ret = AppRequest(COMPLICATION_UPDATE_REQUEST, uid)
- .With(std::move(b))
- .SetAppId(provider_appid)
- .Send();
- if (ret < 0)
- return ret;
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_complication_launch_with_extra_data(const char* appid,
- const char* provider_appid, uid_t uid, const char* key, const char* value) {
- if (appid == nullptr ||
- provider_appid == nullptr ||
- key == nullptr ||
- value == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- tizen_base::Bundle b {
- { AUL_K_CALLER_APPID, appid },
- { AUL_K_COMPLICATION_MODE, kLaunchRequest },
- { key, value }
- };
-
- int ret = AppRequest(COMPLICATION_UPDATE_REQUEST, uid)
- .With(std::move(b))
- .SetAppId(provider_appid)
- .Send();
- if (ret < 0)
- return ret;
-
- return AUL_R_OK;
-}
+++ /dev/null
-/*
- * Copyright (c) 2018 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 <stdbool.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <dirent.h>
-#include <unistd.h>
-#include <glib.h>
-#include <bundle_internal.h>
-
-#include "aul.h"
-#include "aul_api.h"
-#include "aul_util.h"
-#include "aul_debug_info.h"
-
-#define PATH_AUL "/usr/share/aul"
-#define TAG_DEBUGGER "[DEBUGGER]"
-#define TAG_NAME "NAME"
-#define TAG_EXTRA_KEY "EXTRA_KEY"
-#define TAG_EXTRA_ENV "EXTRA_ENV"
-#define TAG_UNLINK "UNLINK"
-#define TAG_ATTACH "ATTACH"
-#define TAG_LAST_EXTRA_KEY "LAST_EXTRA_KEY"
-#define TAG_DEFAULT_OPT "DEFAULT_OPT"
-
-#define FREE_AND_NULL(x) do { \
- if (x) { \
- free(x); \
- x = NULL; \
- } \
-} while (0)
-
-struct debugger_info_s {
- char *name;
- char *attach;
- GList *extra_key_list;
- GList *extra_env_list;
- GList *unlink_list;
- GList *last_extra_key_list;
- GList *default_opt_list;
-};
-
-struct debug_info_s {
- bool initialized;
- GList *debugger_list;
-};
-
-struct cb_data_s {
- bundle *src;
- bundle *dst;
-};
-
-static struct debug_info_s __info;
-
-static struct debugger_info_s *__create_debugger_info(void)
-{
- struct debugger_info_s *info;
-
- info = calloc(1, sizeof(struct debugger_info_s));
- if (info == NULL) {
- _E("out of memory");
- return NULL;
- }
-
- return info;
-}
-
-static void __destroy_debugger_info(gpointer data)
-{
- struct debugger_info_s *info = (struct debugger_info_s *)data;
-
- if (info == NULL)
- return;
-
- if (info->default_opt_list)
- g_list_free_full(info->default_opt_list, free);
- if (info->last_extra_key_list)
- g_list_free_full(info->last_extra_key_list, free);
- if (info->attach)
- free(info->attach);
- if (info->unlink_list)
- g_list_free_full(info->unlink_list, free);
- if (info->extra_env_list)
- g_list_free_full(info->extra_env_list, free);
- if (info->extra_key_list)
- g_list_free_full(info->extra_key_list, free);
- if (info->name)
- free(info->name);
- free(info);
-}
-
-static struct debugger_info_s *__find_debugger_info(const char *name)
-{
- struct debugger_info_s *debugger;
- GList *iter;
-
- iter = __info.debugger_list;
- while (iter) {
- debugger = (struct debugger_info_s *)iter->data;
- if (debugger && debugger->name &&
- !strcmp(debugger->name, name))
- return debugger;
-
- iter = g_list_next(iter);
- }
-
- return NULL;
-}
-
-static GList *__parse_file(GList *list, const char *path)
-{
- FILE *fp;
- char buf[LINE_MAX];
- char *tok1 = NULL;
- char *tok2 = NULL;
- struct debugger_info_s *info = NULL;
-
- fp = fopen(path, "rt");
- if (fp == NULL)
- return list;
-
- while (fgets(buf, sizeof(buf), fp) != NULL) {
- FREE_AND_NULL(tok1);
- FREE_AND_NULL(tok2);
- sscanf(buf, "%ms %ms", &tok1, &tok2);
- if (tok1 && strcasecmp(TAG_DEBUGGER, tok1) == 0) {
- if (info) {
- _D("name: %s", info->name);
- list = g_list_append(list, info);
- }
-
- info = __create_debugger_info();
- if (info == NULL)
- break;
-
- continue;
- }
-
- if (!tok1 || !tok2)
- continue;
- if (tok1[0] == '\0' || tok2[0] == '\0' || tok1[0] == '#')
- continue;
- if (info == NULL)
- continue;
-
- if (strcasecmp(TAG_NAME, tok1) == 0) {
- info->name = strdup(tok2);
- if (info->name == NULL) {
- _E("out of memory");
- __destroy_debugger_info(info);
- info = NULL;
- break;
- }
- } else if (strcasecmp(TAG_EXTRA_KEY, tok1) == 0) {
- info->extra_key_list = g_list_append(
- info->extra_key_list, strdup(tok2));
- } else if (strcasecmp(TAG_EXTRA_ENV, tok1) == 0) {
- info->extra_env_list = g_list_append(
- info->extra_env_list, strdup(tok2));
- } else if (strcasecmp(TAG_UNLINK, tok1) == 0) {
- info->unlink_list = g_list_append(info->unlink_list,
- strdup(tok2));
- } else if (strcasecmp(TAG_ATTACH, tok1) == 0) {
- info->attach = strdup(tok2);
- if (info->attach == NULL) {
- _E("attach is NULL");
- __destroy_debugger_info(info);
- info = NULL;
- break;
- }
- } else if (strcasecmp(TAG_LAST_EXTRA_KEY, tok1) == 0) {
- info->last_extra_key_list = g_list_append(
- info->last_extra_key_list,
- strdup(tok2));
- } else if (strcasecmp(TAG_DEFAULT_OPT, tok1) == 0) {
- info->default_opt_list = g_list_append(
- info->default_opt_list,
- strdup(tok2));
- }
- }
- fclose(fp);
-
- if (info) {
- _D("name: %s", info->name);
- list = g_list_append(list, info);
- }
-
- if (tok1)
- free(tok1);
- if (tok2)
- free(tok2);
-
- return list;
-}
-
-static int __load_debugger_info(const char *path)
-{
- DIR *dp;
- struct dirent *dentry = NULL;
- char buf[PATH_MAX];
- char *ext;
-
- if (path == NULL)
- return -1;
-
- dp = opendir(path);
- if (dp == NULL)
- return -1;
-
- while ((dentry = readdir(dp)) != NULL) {
- if (dentry->d_name[0] == '.')
- continue;
-
- ext = strrchr(dentry->d_name, '.');
- if (ext && strcmp(ext, ".debugger") == 0) {
- snprintf(buf, sizeof(buf), "%s/%s",
- path, dentry->d_name);
- __info.debugger_list = __parse_file(
- __info.debugger_list, buf);
- }
- }
- closedir(dp);
-
- return 0;
-}
-
-static void __unload_debugger_info(void)
-{
- if (__info.debugger_list == NULL)
- return;
-
- g_list_free_full(__info.debugger_list, __destroy_debugger_info);
- __info.debugger_list = NULL;
-}
-
-API int aul_debug_info_init(void)
-{
- int r;
-
- if (__info.initialized)
- return AUL_R_OK;
-
- r = __load_debugger_info(PATH_AUL);
- if (r != 0) {
- _E("Failed to loader debugger information");
- return AUL_R_ERROR;
- }
-
- __info.initialized = true;
- return AUL_R_OK;
-}
-
-API int aul_debug_info_fini(void)
-{
- if (!__info.initialized)
- return AUL_R_OK;
-
- __unload_debugger_info();
-
- __info.initialized = false;
- return AUL_R_OK;
-}
-
-static void __copy_data(bundle *src, bundle *dst, const char *key)
-{
- const char **str_arr;
- char *str = NULL;
- int len = 0;
-
- if (bundle_get_type(src, key) == BUNDLE_TYPE_STR_ARRAY) {
- str_arr = bundle_get_str_array(src, key, &len);
- if (str_arr) {
- bundle_del(dst, key);
- bundle_add_str_array(dst, key, str_arr, len);
- }
- } else {
- bundle_get_str(src, key, &str);
- if (str) {
- bundle_del(dst, key);
- bundle_add_str(dst, key, str);
- }
- }
-}
-
-static void __foreach_cb(gpointer data, gpointer user_data)
-{
- struct cb_data_s *cb_data = (struct cb_data_s *)user_data;
- const char *key = (const char *)data;
-
- if (!key || !cb_data) {
- _E("Critical error!");
- return;
- }
-
- __copy_data(cb_data->src, cb_data->dst, key);
- _D("[__DEBUG_INFO__] key(%s)", key);
-}
-
-static void __set_debug_info(struct debugger_info_s *debugger,
- bundle *src, bundle *dst)
-{
- const char *val;
- struct cb_data_s cb_data = {
- .src = src,
- .dst = dst
- };
-
- __copy_data(src, dst, AUL_K_SDK);
- if (debugger->extra_key_list)
- g_list_foreach(debugger->extra_key_list, __foreach_cb, &cb_data);
- if (debugger->extra_env_list)
- g_list_foreach(debugger->extra_env_list, __foreach_cb, &cb_data);
- if (debugger->unlink_list)
- g_list_foreach(debugger->unlink_list, __foreach_cb, &cb_data);
- if (debugger->last_extra_key_list)
- g_list_foreach(debugger->last_extra_key_list, __foreach_cb, &cb_data);
- if (debugger->default_opt_list)
- g_list_foreach(debugger->default_opt_list, __foreach_cb, &cb_data);
-
- val = bundle_get_val(src, AUL_K_ORG_CALLER_PID);
- if (!val)
- val = bundle_get_val(src, AUL_K_CALLER_PID);
-
- if (val) {
- bundle_del(dst, AUL_K_ORG_CALLER_PID);
- bundle_add(dst, AUL_K_ORG_CALLER_PID, val);
- }
-
- _D("[__DEBUG_INFO__] Debugger(%s)", debugger->name);
-}
-
-API int aul_debug_info_set(bundle *src, bundle *dst)
-{
- const char *name;
- struct debugger_info_s *debugger;
-
- if (!src || !dst) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- if (!__info.initialized) {
- _E("Debug info is not initilaized");
- return AUL_R_ERROR;
- }
-
- name = bundle_get_val(src, AUL_K_SDK);
- if (!name) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- debugger = __find_debugger_info(name);
- if (!debugger) {
- _E("Failed to find debugger(%s)", name);
- return AUL_R_EINVAL;
- }
-
- __set_debug_info(debugger, src, dst);
-
- return AUL_R_OK;
-}
+++ /dev/null
-/*
- * Copyright (c) 2016 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 <errno.h>
-
-#include "aul_util.h"
-#include "aul_error.h"
-#include "aul_sock.h"
-#include "aul.h"
-
-int aul_error_convert(int res)
-{
- int ret;
-
- switch (res) {
- case -ENOMEM:
- ret = AUL_R_ENOMEM;
- break;
- case -EREJECTED:
- ret = AUL_R_EREJECTED;
- break;
- case -ENOENT:
- ret = AUL_R_ENOAPP;
- break;
- case -ETERMINATING:
- ret = AUL_R_ETERMINATING;
- break;
- case -EILLEGALACCESS:
- ret = AUL_R_EILLACC;
- break;
- case -ELOCALLAUNCH_ID:
- ret = AUL_R_LOCAL;
- break;
- case -EAGAIN:
- ret = AUL_R_ETIMEOUT;
- break;
- case -EINVAL:
- ret = AUL_R_EINVAL;
- break;
- case -ECOMM:
- ret = AUL_R_ECOMM;
- break;
- case -ECANCELED:
- ret = AUL_R_ECANCELED;
- break;
- default:
- ret = AUL_R_ERROR;
- break;
- }
-
- return ret;
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2017 - 2022 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul_job_scheduler.h"
-
-#include <bundle_cpp.h>
-
-#include "app_request.h"
-#include "aul_api.h"
-#include "aul_util.h"
-#include "include/aul.h"
-#include "include/aul_sock.h"
-
-extern "C" API int aul_job_scheduler_update_job_status(const char* job_id,
- aul_job_status_e job_status) {
- if (job_id == nullptr ||
- job_status < JOB_STATUS_START ||
- job_status > JOB_STATUS_FINISHED) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- tizen_base::Bundle b {
- { AUL_K_JOB_ID, job_id },
- { AUL_K_JOB_STATUS, std::to_string(job_status) }
- };
-
- return aul::internal::AppRequest(JOB_STATUS_UPDATE, getuid())
- .With(std::move(b))
- .SendSimply(AUL_SOCK_NOREPLY);
-}
+++ /dev/null
-/*
- * Copyright (c) 2018 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 _GNU_SOURCE
-#define _GNU_SOURCE
-#endif
-
-#include <stdio.h>
-#include <stdbool.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <ctype.h>
-#include <glib.h>
-#include <bundle_internal.h>
-
-#include "aul_api.h"
-#include "aul_cmd.h"
-#include "aul_util.h"
-#include "aul.h"
-#include "aul_sock.h"
-#include "launch.h"
-#include "aul_watch_control_internal.h"
-#include "aul_worker.h"
-#include "aul_watchdog.h"
-
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
-
-#define K_SERVICE_THREAD "__K_SERVICE_THREAD"
-
-#define AUL_CTOR __attribute__ ((constructor))
-#define AUL_DTOR __attribute__ ((destructor))
-
-typedef struct client_channel_s {
- int fd;
- pid_t pid;
- uid_t uid;
-} client_channel_t;
-
-struct aul_request_s {
- int cmd;
- int clifd;
- bundle *b;
- int req_id;
-};
-
-typedef struct aul_request_s *aul_request_h;
-
-typedef void (*dispatcher)(aul_request_h req);
-
-typedef struct aul_handler_s {
- aul_handler_fn callback;
- void *user_data;
-} aul_handler;
-
-typedef struct subapp_handler_s {
- bool is_subapp;
- subapp_fn callback;
- void *user_data;
-} subapp_handler;
-
-typedef struct data_control_provider_handler_s {
- data_control_provider_handler_fn callback;
-} data_control_provider_handler;
-
-typedef struct launch_context_s {
- bool initialized;
- aul_worker_h worker;
- aul_handler aul;
- subapp_handler subapp;
- data_control_provider_handler dcp;
- GList* clients;
- GRecMutex init_mutex;
- GRecMutex mutex;
- GMainContext *tizen_context;
- bool touch_argv_handler;
-} launch_context;
-
-static launch_context __context;
-
-AUL_CTOR static void __aul_constructor(void)
-{
- g_rec_mutex_init(&__context.init_mutex);
-}
-
-AUL_DTOR static void __aul_destructor(void)
-{
- if (g_rec_mutex_trylock(&__context.init_mutex))
- g_rec_mutex_unlock(&__context.init_mutex);
-
- g_rec_mutex_clear(&__context.init_mutex);
-}
-
-static void __destroy_client_channel(gpointer data)
-{
- client_channel_t *channel = data;
- free(channel);
-}
-
-static client_channel_t *__create_client_channel(int fd, pid_t pid, uid_t uid)
-{
- client_channel_t *channel;
-
- channel = calloc(1, sizeof(client_channel_t));
- if (!channel) {
- _E("Out of memory");
- return NULL;
- }
-
- channel->fd = fd;
- channel->pid = pid;
- channel->uid = uid;
-
- return channel;
-}
-
-static void __add_client_channel(client_channel_t *channel)
-{
- g_rec_mutex_lock(&__context.mutex);
- __context.clients = g_list_append(__context.clients, channel);
- g_rec_mutex_unlock(&__context.mutex);
-}
-
-static void __remove_client_channel(client_channel_t *channel)
-{
- g_rec_mutex_lock(&__context.mutex);
- __context.clients = g_list_remove(__context.clients, channel);
- g_rec_mutex_unlock(&__context.mutex);
-}
-
-static client_channel_t *__find_client_channel(int fd)
-{
- client_channel_t *channel;
- GList *iter;
-
- g_rec_mutex_lock(&__context.mutex);
- iter = __context.clients;
- while (iter) {
- channel = iter->data;
- if (channel->fd == fd) {
- g_rec_mutex_unlock(&__context.mutex);
- return channel;
- }
-
- iter = g_list_next(iter);
- }
- g_rec_mutex_unlock(&__context.mutex);
-
- return NULL;
-}
-
-static void __invoke_aul_handler(aul_type type, bundle *b)
-{
- if (__context.aul.callback)
- __context.aul.callback(type, b, __context.aul.user_data);
-}
-
-static void __dispatch_app_start(aul_request_h req)
-{
- const char *str;
-
- aul_watch_control_invoke(req->b);
- __invoke_aul_handler(AUL_START, req->b);
- str = bundle_get_val(req->b, AUL_K_DATA_CONTROL_TYPE);
- if (str && !strcmp(str, "CORE")) {
- if (__context.dcp.callback)
- __context.dcp.callback(req->b, 0, NULL);
- }
-}
-
-static void __dispatch_app_resume(aul_request_h req)
-{
- __invoke_aul_handler(AUL_RESUME, NULL);
-}
-
-static void __dispatch_app_term_by_pid(aul_request_h req)
-{
- __invoke_aul_handler(AUL_TERMINATE, NULL);
-}
-
-static void __dispatch_app_term_bgapp_by_pid(aul_request_h req)
-{
- __invoke_aul_handler(AUL_TERMINATE_BGAPP, NULL);
-}
-
-static void __dispatch_app_term_req_by_pid(aul_request_h req)
-{
- if (__context.subapp.is_subapp) {
- if (__context.subapp.callback)
- __context.subapp.callback(__context.subapp.user_data);
- } else {
- __invoke_aul_handler(AUL_TERMINATE, NULL);
- }
-}
-
-static void __dispatch_app_result(aul_request_h req)
-{
- const char *pid_str;
- int pid = -1;
-
- pid_str = bundle_get_val(req->b, AUL_K_CALLEE_PID);
- if (pid_str)
- pid = atoi(pid_str);
-
- app_result(req->cmd, req->b, pid);
-}
-
-static void __dispatch_app_pause_by_pid(aul_request_h req)
-{
- __invoke_aul_handler(AUL_PAUSE, req->b);
-}
-
-static void __dispatch_app_com_message(aul_request_h req)
-{
- app_com_recv(req->b);
-}
-
-static void __dispatch_app_wake(aul_request_h req)
-{
- __invoke_aul_handler(AUL_WAKE, req->b);
-}
-
-static void __dispatch_app_suspend(aul_request_h req)
-{
- __invoke_aul_handler(AUL_SUSPEND, req->b);
-}
-
-static void __dispatch_widget_get_content(aul_request_h req)
-{
- const char *widget_id;
- const char *instance_id;
- const char *content_info;
- int fds[2] = { 0, };
- int r;
-
- r = aul_sock_recv_reply_sock_fd(req->clifd, &fds, 1);
- if (r < 0) {
- _E("Failed to receive fds");
- return;
- }
-
- widget_id = bundle_get_val(req->b, AUL_K_WIDGET_ID);
- if (!widget_id) {
- _E("Failed to get widget ID");
- aul_sock_send_raw_with_fd(fds[0], -EINVAL, 0, 0,
- AUL_SOCK_NOREPLY);
- return;
- }
-
- instance_id = bundle_get_val(req->b, AUL_K_WIDGET_INSTANCE_ID);
- if (!instance_id) {
- _E("Failed to get instance ID");
- aul_sock_send_raw_with_fd(fds[0], -EINVAL, 0, 0,
- AUL_SOCK_NOREPLY);
- return;
- }
-
- __invoke_aul_handler(AUL_WIDGET_CONTENT, req->b);
-
- content_info = bundle_get_val(req->b, AUL_K_WIDGET_CONTENT_INFO);
- if (content_info) {
- r = aul_sock_send_raw_with_fd(fds[0], 0,
- (unsigned char *)content_info,
- strlen(content_info) + 1, AUL_SOCK_NOREPLY);
- } else {
- r = aul_sock_send_raw_with_fd(fds[0], -ENOENT,
- NULL, 0, AUL_SOCK_NOREPLY);
- }
-
- if (r < 0) {
- _E("Failed to send content info. fd(%d), result(%d)",
- fds[0], r);
- }
-}
-
-static void __dispatch_app_update_requested(aul_request_h req)
-{
- __invoke_aul_handler(AUL_UPDATE_REQUESTED, req->b);
-}
-
-static void __dispatch_app_term_inst(aul_request_h req)
-{
- __invoke_aul_handler(AUL_TERMINATE_INST, req->b);
-}
-
-static void __dispatch_app_resume_inst(aul_request_h req)
-{
- __invoke_aul_handler(AUL_RESUME, req->b);
-}
-
-static void __dispatch_app_pause_inst(aul_request_h req)
-{
- __invoke_aul_handler(AUL_PAUSE, req->b);
-}
-
-static void __dispatch_app_term_bg_inst(aul_request_h req)
-{
- __invoke_aul_handler(AUL_TERMINATE_BG_INST, req->b);
-}
-
-static void __dispatch_watchdog_enable(aul_request_h req)
-{
- const char *interval_str;
- unsigned int interval;
-
- interval_str = bundle_get_val(req->b, AUL_K_INTERVAL);
- if (!interval_str) {
- _E("Invalid request");
- return;
- }
-
- interval = strtoul(interval_str, NULL, 10);
- aul_watchdog_start(interval);
-}
-
-static void __dispatch_watchdog_disable(aul_request_h req)
-{
- aul_watchdog_stop();
-}
-
-static void __dispatch_app_connect(aul_request_h req)
-{
-}
-
-static dispatcher __dispatcher[] = {
- [APP_START] = __dispatch_app_start,
- [APP_START_RES] = __dispatch_app_start,
- [APP_START_ASYNC] = __dispatch_app_start,
- [APP_START_RES_ASYNC] = __dispatch_app_start,
- [APP_OPEN] = __dispatch_app_resume,
- [APP_RESUME] = __dispatch_app_resume,
- [APP_RESUME_BY_PID] = __dispatch_app_resume,
- [APP_TERM_BY_PID] = __dispatch_app_term_by_pid,
- [APP_TERM_BY_PID_ASYNC] = __dispatch_app_term_by_pid,
- [APP_TERM_BY_PID_SYNC] = __dispatch_app_term_by_pid,
- [APP_TERM_BGAPP_BY_PID] = __dispatch_app_term_bgapp_by_pid,
- [APP_TERM_REQ_BY_PID] = __dispatch_app_term_req_by_pid,
- [APP_RESULT] = __dispatch_app_result,
- [APP_CANCEL] = __dispatch_app_result,
- [APP_PAUSE_BY_PID] = __dispatch_app_pause_by_pid,
- [APP_COM_MESSAGE] = __dispatch_app_com_message,
- [APP_WAKE] = __dispatch_app_wake,
- [APP_SUSPEND] = __dispatch_app_suspend,
- [WIDGET_GET_CONTENT] = __dispatch_widget_get_content,
- [APP_UPDATE_REQUESTED] = __dispatch_app_update_requested,
- [APP_SEND_LAUNCH_REQUEST] = __dispatch_app_start,
- [APP_SEND_LAUNCH_REQUEST_SYNC] = __dispatch_app_start,
- [APP_TERM_INSTANCE_ASYNC] = __dispatch_app_term_inst,
- [APP_RESUME_INSTANCE] = __dispatch_app_resume_inst,
- [APP_PAUSE_INSTANCE] = __dispatch_app_pause_inst,
- [APP_TERM_BG_INSTANCE] = __dispatch_app_term_bg_inst,
- [WATCHDOG_ENABLE] = __dispatch_watchdog_enable,
- [WATCHDOG_DISABLE] = __dispatch_watchdog_disable,
- [APP_CONNECT] = __dispatch_app_connect,
-};
-
-static void __destroy_request(struct aul_request_s *req)
-{
- if (req->b)
- bundle_free(req->b);
- free(req);
-}
-
-static struct aul_request_s *__create_request(int cmd, int clifd, bundle *b)
-{
- struct aul_request_s *req;
- const char *val;
-
- req = malloc(sizeof(struct aul_request_s));
- if (!req) {
- _E("Out of memory");
- return NULL;
- }
-
- req->cmd = cmd;
- req->clifd = clifd;
- req->b = b;
- val = bundle_get_val(b, AUL_K_REQUEST_ID);
- req->req_id = val ? atoi(val) : -1;
-
- return req;
-}
-
-static int __send_result(struct aul_request_s *req, int res)
-{
- int ret;
- int buf[2];
-
- if (req->cmd != WIDGET_GET_CONTENT && req->clifd >= 0) {
- g_rec_mutex_lock(&__context.mutex);
- if (__find_client_channel(req->clifd) == NULL) {
- _E("Failed to find client channel. fd(%d), cmd(%s:%d)",
- req->clifd,
- aul_cmd_convert_to_string(req->cmd),
- req->cmd);
- g_rec_mutex_unlock(&__context.mutex);
- return -1;
- }
-
- buf[0] = req->req_id;
- buf[1] = res;
- ret = aul_sock_send_raw_data(req->clifd, (unsigned char *)&buf,
- sizeof(int) + sizeof(int), false);
- g_rec_mutex_unlock(&__context.mutex);
- if (ret < 0) {
- _E("Failed to send result. cmd(%s:%d), seq(%d)",
- aul_cmd_convert_to_string(req->cmd),
- req->cmd, req->req_id);
- return ret;
- }
- }
-
- return 0;
-}
-
-static gboolean __dispatch_request(gpointer data)
-{
- struct aul_request_s *req = (struct aul_request_s *)data;
- int ret;
-
- if (!__context.initialized) {
- _W("Ignore request(%d)", req->cmd);
- __destroy_request(req);
- return G_SOURCE_REMOVE;
- }
-
- aul_worker_remove_anr_timer(__context.worker);
-
- ret = __send_result(req, 0);
- if (ret < 0) {
- __destroy_request(req);
- return G_SOURCE_REMOVE;
- }
-
- if (req->cmd >= APP_START && req->cmd < ARRAY_SIZE(__dispatcher) &&
- __dispatcher[req->cmd]) {
- _W("[%d] Command(%s:%d)",
- req->req_id,
- aul_cmd_convert_to_string(req->cmd), req->cmd);
- __dispatcher[req->cmd](req);
- } else {
- _E("[%d] Command(%s:%d) is not available",
- req->req_id,
- aul_cmd_convert_to_string(req->cmd), req->cmd);
- }
-
- __destroy_request(req);
-
- return G_SOURCE_REMOVE;
-}
-
-static guint __g_idle_add_full(GMainContext *context, gint priority,
- GSourceFunc func, gpointer data)
-{
- GSource *source;
- guint tag;
-
- source = g_idle_source_new();
- if (!source)
- return 0;
-
- g_source_set_callback(source, (GSourceFunc)func, data, NULL);
- g_source_set_priority(source, priority);
- tag = g_source_attach(source, context);
- g_source_unref(source);
-
- return tag;
-}
-
-static GMainContext *__get_glib_context(int cmd, bundle *b)
-{
- GMainContext *context;
-
- if (b && bundle_get_type(b, K_SERVICE_THREAD) != BUNDLE_TYPE_NONE)
- return NULL;
-
- switch (cmd) {
- case APP_START:
- case APP_START_RES:
- case APP_START_ASYNC:
- case APP_START_RES_ASYNC:
- case APP_OPEN:
- case APP_RESUME:
- case APP_RESUME_BY_PID:
- case APP_PAUSE_BY_PID:
- case APP_SEND_LAUNCH_REQUEST:
- case APP_SEND_LAUNCH_REQUEST_SYNC:
- case APP_RESUME_INSTANCE:
- case APP_PAUSE_INSTANCE:
- context = __context.tizen_context;
- break;
- default:
- context = NULL;
- break;
- }
-
- return context;
-}
-
-static void __process_app_pkt(app_pkt_t *pkt, int clifd, aul_worker_h worker)
-{
- struct aul_request_s *req;
- bundle *b = NULL;
- char *timeout_str;
- unsigned int timeout = 5000;
- int ret;
-
- if (pkt->opt & AUL_SOCK_BUNDLE) {
- b = bundle_decode(pkt->data, pkt->len);
- if (!b) {
- _E("Failed to decode the packet");
- return;
- }
-
- ret = bundle_get_str(b, AUL_K_SOCKET_TIMEOUT, &timeout_str);
- if (ret == BUNDLE_ERROR_NONE && isdigit(timeout_str[0])) {
- timeout = atoi(timeout_str);
- _I("timeout: %ums", timeout);
- }
- }
-
- req = __create_request(pkt->cmd, clifd, b);
- if (!req) {
- bundle_free(b);
- return;
- }
-
- aul_worker_add_anr_timer(worker, pkt->cmd, timeout);
- __g_idle_add_full(__get_glib_context(pkt->cmd, b), G_PRIORITY_DEFAULT,
- __dispatch_request, req);
-}
-
-static bool __received_event_cb(int fd, int condition, void *user_data)
-{
- aul_worker_h worker = user_data;
- client_channel_t *channel;
- app_pkt_t *pkt;
- int ret;
-
- g_rec_mutex_lock(&__context.mutex);
- channel = __find_client_channel(fd);
- if (!channel) {
- _E("Failed to find client channel. fd(%d)", fd);
- g_rec_mutex_unlock(&__context.mutex);
- return false;
- }
-
- if (condition & (AUL_IO_HUP | AUL_IO_ERR | AUL_IO_NVAL)) {
- _E("IO error occurred. condition(%d), fd(%d)", condition, fd);
- aul_worker_remove_io_job(worker, fd);
- __remove_client_channel(channel);
- __destroy_client_channel(channel);
- g_rec_mutex_unlock(&__context.mutex);
- return true;
- }
-
- ret = aul_sock_recv_reply_pkt_v2(fd, &pkt, false);
- g_rec_mutex_unlock(&__context.mutex);
- if (ret != 0) {
- _E("Failed to receive the packet. error(%d)", ret);
- return true;
- }
-
- __process_app_pkt(pkt, fd, worker);
- free(pkt);
-
- return true;
-}
-
-static bool __connected_event_cb(int fd, int condition, void *user_data)
-{
- int cond = AUL_IO_IN | AUL_IO_HUP | AUL_IO_ERR | AUL_IO_NVAL;
- aul_worker_h worker = user_data;
- client_channel_t *channel = NULL;
- struct ucred cr;
- int clifd;
- app_pkt_t *pkt;
- int ret;
-
- pkt = aul_sock_recv_pkt(fd, &clifd, &cr);
- if (!pkt) {
- _E("Failed to receive the packet");
- return true;
- }
-
- _W("pid(%d), clifd(%d), cmd(%d)", cr.pid, clifd, pkt->cmd);
- if (pkt->cmd != WIDGET_GET_CONTENT) {
- if (pkt->opt & AUL_SOCK_NOREPLY) {
- close(clifd);
- clifd = -1;
- } else {
- channel = __create_client_channel(clifd,
- cr.pid, cr.uid);
- if (!channel) {
- free(pkt);
- close(clifd);
- return true;
- }
-
- __add_client_channel(channel);
- }
- }
-
- __process_app_pkt(pkt, clifd, worker);
-
- if (pkt->cmd == WIDGET_GET_CONTENT)
- clifd = -1;
-
- free(pkt);
-
- if (clifd < 0)
- return true;
-
- ret = aul_worker_add_io_job(worker, "client", clifd, cond, true,
- __received_event_cb, worker);
- if (ret < 0) {
- _E("Failed to add io job. error(%d)", ret);
- __remove_client_channel(channel);
- __destroy_client_channel(channel);
- return true;
- }
-
- return true;
-}
-
-static void __finalize_context(void)
-{
- g_rec_mutex_lock(&__context.init_mutex);
- if (!__context.initialized) {
- g_rec_mutex_unlock(&__context.init_mutex);
- return;
- }
-
- __context.touch_argv_handler = false;
-
- aul_launch_worker_fini();
-
- if (__context.tizen_context) {
- g_main_context_unref(__context.tizen_context);
- __context.tizen_context = NULL;
- }
-
- if (__context.clients) {
- g_list_free_full(__context.clients, __destroy_client_channel);
- __context.clients = NULL;
- }
-
- if (g_rec_mutex_trylock(&__context.mutex))
- g_rec_mutex_unlock(&__context.mutex);
-
- g_rec_mutex_clear(&__context.mutex);
-
- __context.initialized = false;
- g_rec_mutex_unlock(&__context.init_mutex);
-}
-
-static GMainContext *__get_tizen_glib_context(void)
-{
- GMainContext *context;
- const char *env;
-
- env = getenv("TIZEN_GLIB_CONTEXT");
- if (env)
- context = (GMainContext *)strtoul(env, NULL, 10);
- else
- context = NULL;
-
- return context;
-}
-
-static int __initialize_context(void)
-{
- GMainContext *context;
- int ret;
- int fd;
-
- if (__context.initialized) {
- _E("Already initialized");
- context = __get_tizen_glib_context();
- if (context)
- __context.tizen_context = g_main_context_ref(context);
-
- return AUL_R_OK;
- }
-
- fd = aul_initialize();
- if (fd < 0) {
- _E("Failed to initialize aul");
- return fd;
- }
-
- g_rec_mutex_init(&__context.mutex);
-
- context = __get_tizen_glib_context();
- if (context)
- __context.tizen_context = g_main_context_ref(context);
- else
- __context.tizen_context = NULL;
-
- if (aul_launch_worker_init() != AUL_R_OK) {
- __finalize_context();
- return AUL_R_ERROR;
- }
-
- ret = aul_worker_add_io_job(__context.worker, "server", fd, AUL_IO_IN,
- false, __connected_event_cb, __context.worker);
- if (ret < 0) {
- __finalize_context();
- return ret;
- }
-
- __context.initialized = true;
-
- return AUL_R_OK;
-}
-
-API int aul_launch_worker_init(void)
-{
- if (__context.worker != NULL)
- return AUL_R_OK;
-
- __context.worker = aul_worker_create("aul+");
- if (__context.worker == NULL)
- return AUL_R_ERROR;
-
- return AUL_R_OK;
-}
-
-API void aul_launch_worker_fini(void)
-{
- if (__context.worker == NULL)
- return;
-
- aul_worker_destroy(__context.worker);
- __context.worker = NULL;
-}
-
-API int aul_launch_init(aul_handler_fn callback, void *user_data)
-{
- int ret;
-
- g_rec_mutex_lock(&__context.init_mutex);
- if (callback) {
- __context.aul.callback = callback;
- __context.aul.user_data = user_data;
- }
-
- ret = __initialize_context();
- g_rec_mutex_unlock(&__context.init_mutex);
-
- return ret;
-}
-
-API int aul_launch_fini(void)
-{
- __finalize_context();
- return AUL_R_OK;
-}
-
-static gboolean __app_start_cb(gpointer data)
-{
- bundle *b = (bundle *)data;
- struct aul_request_s req = {
- .cmd = APP_START,
- .clifd = 0,
- .b = b
- };
-
- __dispatch_app_start(&req);
-
- if (req.b)
- bundle_free(req.b);
-
- return G_SOURCE_REMOVE;
-}
-
-API int aul_launch_argv_handler(int argc, char **argv)
-{
- bundle *b;
-
- if (!aul_is_initialized()) {
- _E("AUL is not initialized");
- return AUL_R_ENOINIT;
- }
-
- if (__context.touch_argv_handler) {
- _E("Already registered");
- return AUL_R_OK;
- }
-
- b = bundle_import_from_argv(argc, argv);
- if (!b)
- _E("Bundle is nullptr");
-
- if (!__g_idle_add_full(__get_glib_context(APP_START, b),
- G_PRIORITY_HIGH, __app_start_cb, b)) {
- _E("Failed to add idler");
- return AUL_R_ERROR;
- }
-
- __context.touch_argv_handler = true;
- return AUL_R_OK;
-}
-
-API int aul_launch_local(bundle *b)
-{
- if (!aul_is_initialized()) {
- _E("AUL is not initialized");
- return AUL_R_ENOINIT;
- }
-
- if (!b)
- _E("Bundle is nullptr");
-
- if (!__g_idle_add_full(__get_glib_context(APP_START, b),
- G_PRIORITY_DEFAULT, __app_start_cb, b)) {
- _E("Failed to add idler");
- return AUL_R_ERROR;
- }
-
- return AUL_R_OK;
-}
-
-int aul_resume_local(void)
-{
- if (!aul_is_initialized()) {
- _E("AUL is not initialized");
- return AUL_R_ENOINIT;
- }
-
- __dispatch_app_resume(NULL);
-
- return AUL_R_OK;
-}
-
-API int aul_set_subapp(subapp_fn callback, void *user_data)
-{
- __context.subapp.is_subapp = true;
- __context.subapp.callback = callback;
- __context.subapp.user_data = user_data;
-
- return AUL_R_OK;
-}
-
-API int aul_is_subapp(void)
-{
- return (int)__context.subapp.is_subapp;
-}
-
-API int aul_set_data_control_provider_cb(data_control_provider_handler_fn cb)
-{
- __context.dcp.callback = cb;
-
- return AUL_R_OK;
-}
-
-API int aul_unset_data_control_provider_cb(void)
-{
- __context.dcp.callback = NULL;
-
- return AUL_R_OK;
-}
+++ /dev/null
-/*
- * Copyright (c) 2019 - 2022 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include "include/aul_launcher_service.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <glib.h>
-#include <bundle_internal.h>
-
-#include "aul_api.h"
-#include "aul_util.h"
-#include "include/aul_app_com.h"
-#include "include/aul_error.h"
-#include "include/aul_sock.h"
-
-#include "app_request.h"
-
-struct aul_launcher_serivce_s {
- void* dummy;
-};
-
-using namespace aul::internal;
-namespace {
-
-class LauncherService {
- public:
- LauncherService(std::string name, aul_launcher_service_cb cb,
- void* user_data)
- : name_(std::move(name)), cb_(cb), user_data_(user_data) {
- }
-
- ~LauncherService() {
- if (conn_ != nullptr)
- aul_app_com_leave(conn_);
- }
-
- int Listen() {
- if (conn_ != nullptr)
- return AUL_R_OK;
-
- std::string endpoint = "launcher_service:" + name_ + ":" +
- std::to_string(getpid());
- int ret = aul_app_com_create(endpoint.c_str(), nullptr, AppComCb,
- this, &conn_);
- if (ret < 0) {
- _E("Failed to create app com. error(%d)", ret);
- return AUL_R_ERROR;
- }
-
- return AUL_R_OK;
- }
-
- private:
- static int AppComCb(const char* endpoint, aul_app_com_result_e result,
- bundle* envelope, void* user_data) {
- const char* appid = bundle_get_val(envelope, AUL_K_APPID);
- if (appid == nullptr) {
- _E("Failed to get application ID");
- return -1;
- }
-
- const char* instance_id = bundle_get_val(envelope, AUL_K_INSTANCE_ID);
- if (instance_id == nullptr) {
- _E("Failed to get instance ID");
- return -1;
- }
-
- const char* pid_str = bundle_get_val(envelope, AUL_K_PID);
- if (pid_str == nullptr) {
- _E("Failed to get process ID");
- return -1;
- }
- int pid = atoi(pid_str);
-
- const char* serial_str = bundle_get_val(envelope,
- AUL_K_LAUNCHER_SERVICE_SERIAL);
- if (serial_str == nullptr) {
- _E("Failed to get serial");
- return -1;
- }
- uint32_t serial = strtoul(serial_str, NULL, 10);
-
- auto* launcher_service = static_cast<LauncherService*>(user_data);
- launcher_service->cb_(appid, instance_id, pid, serial,
- launcher_service->user_data_);
- return 0;
- }
-
- private:
- std::string name_;
- aul_launcher_service_cb cb_;
- void* user_data_;
- aul_app_com_connection_h conn_ = nullptr;
-};
-
-} // namespace
-
-extern "C" API int aul_launcher_service_create(const char* name,
- aul_launcher_service_cb callback, void* user_data,
- aul_launcher_service_h* handle) {
- if (callback == nullptr || name == nullptr || handle == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* service = new (std::nothrow) LauncherService(name, callback, user_data);
- if (service == nullptr) {
- _E("Out of memory");
- return AUL_R_ENOMEM;
- }
-
- *handle = reinterpret_cast<aul_launcher_service_h>(service);
- return AUL_R_OK;
-}
-
-extern "C" API int aul_launcher_service_listen(aul_launcher_service_h handle) {
- if (handle == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* service = reinterpret_cast<LauncherService*>(handle);
- return service->Listen();
-}
-
-extern "C" API int aul_launcher_service_destroy(aul_launcher_service_h handle) {
- if (handle == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* service = reinterpret_cast<LauncherService*>(handle);
- delete service;
- return AUL_R_OK;
-}
-
-extern "C" API int aul_launcher_service_notify_animation_started(void) {
- return AppRequest(LAUNCHER_SERVICE_NOTIFY_ANIMATION_STARTED, getuid())
- .SendCmdOnly(AUL_SOCK_NOREPLY);
-}
-
-extern "C" API int aul_launcher_service_notify_animation_finished(void) {
- return AppRequest(LAUNCHER_SERVICE_NOTIFY_ANIMATION_FINISHED, getuid())
- .SendCmdOnly(AUL_SOCK_NOREPLY);
-}
+++ /dev/null
-/*
- * Copyright (c) 2021 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 <memory>
-#include <mutex>
-#include <string>
-
-#include "aul/app_info/directory_info.hh"
-#include "aul/app_info/external_directory_info.hh"
-#include "aul_api.h"
-#include "aul_util.h"
-#include "include/aul.h"
-
-#undef AUL_API
-#define AUL_API extern "C" API
-
-namespace {
-std::unique_ptr<aul::DirectoryInfo> context(nullptr);
-std::unique_ptr<aul::ExternalDirectoryInfo> ext_context(nullptr);
-std::mutex mutex;
-std::mutex ext_mutex;
-
-const aul::DirectoryInfo* GetCurrentContext() {
- std::unique_lock<std::mutex> lock(mutex);
- if (context.get() == nullptr)
- context.reset(aul::DirectoryInfo::Get());
-
- return context.get();
-}
-
-const aul::ExternalDirectoryInfo* GetCurrentExtContext() {
- std::unique_lock<std::mutex> lock(ext_mutex);
- if (ext_context.get() == nullptr)
- ext_context.reset(aul::ExternalDirectoryInfo::Get());
-
- return ext_context.get();
-}
-
-} // namespace
-
-AUL_API const char* aul_get_app_external_root_path(void) {
- auto* context = GetCurrentExtContext();
- if (context == nullptr)
- return nullptr;
-
- return context->GetRootPath().c_str();
-}
-
-AUL_API const char* aul_get_app_root_path(void) {
- auto* context = GetCurrentContext();
- if (context == nullptr)
- return nullptr;
-
- return context->GetRootPath().c_str();
-}
-
-AUL_API const char* aul_get_app_data_path(void) {
- auto* context = GetCurrentContext();
- if (context == nullptr)
- return nullptr;
-
- return context->GetDataPath().c_str();
-}
-
-AUL_API const char* aul_get_app_cache_path(void) {
- auto* context = GetCurrentContext();
- if (context == nullptr)
- return nullptr;
-
- return context->GetCachePath().c_str();
-}
-
-AUL_API const char* aul_get_app_resource_path(void) {
- auto* context = GetCurrentContext();
- if (context == nullptr)
- return nullptr;
-
- return context->GetResourcePath().c_str();
-}
-
-AUL_API const char* aul_get_app_tep_resource_path(void) {
- auto* context = GetCurrentContext();
- if (context == nullptr)
- return nullptr;
-
- return context->GetTepResourcePath().c_str();
-}
-
-AUL_API int aul_get_app_shared_data_path(char** path) {
- auto* context = GetCurrentContext();
- if (context == nullptr)
- return AUL_R_ERROR;
-
- if (access(context->GetSharedDataPath().c_str(), F_OK) != 0)
- return AUL_R_EREJECTED;
-
- *path = strdup(context->GetSharedDataPath().c_str());
- return AUL_R_OK;
-}
-
-AUL_API const char* aul_get_app_shared_resource_path(void) {
- auto* context = GetCurrentContext();
- if (context == nullptr)
- return nullptr;
-
- return context->GetSharedResourcePath().c_str();
-}
-
-AUL_API const char* aul_get_app_shared_trusted_path(void) {
- auto* context = GetCurrentContext();
- if (context == nullptr)
- return nullptr;
-
- return context->GetSharedTrustedPath().c_str();
-}
-
-AUL_API const char* aul_get_app_external_data_path(void) {
- auto* context = GetCurrentExtContext();
- if (context == nullptr)
- return nullptr;
-
- return context->GetDataPath().c_str();
-}
-
-AUL_API const char* aul_get_app_external_cache_path(void) {
- auto* context = GetCurrentExtContext();
- if (context == nullptr)
- return nullptr;
-
- return context->GetCachePath().c_str();
-}
-
-AUL_API const char* aul_get_app_external_shared_data_path(void) {
- auto* context = GetCurrentExtContext();
- if (context == nullptr)
- return nullptr;
-
- return context->GetSharedDataPath().c_str();
-}
-
-AUL_API const char* aul_get_app_specific_path(void) {
- if (GetCurrentContext() == nullptr)
- return nullptr;
-
- return tzplatform_getenv(TZ_USER_APP);
-}
-
-AUL_API int aul_get_app_res_control_allowed_resource_path(const char* res_type,
- char** path) {
- if (res_type == nullptr || path == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* context = GetCurrentContext();
- if (context == nullptr)
- return AUL_R_ERROR;
-
- std::string result = context->GetResControlAllowedResPath() + res_type + "/";
-
- if (access(result.c_str(), F_OK) != 0)
- return AUL_R_EREJECTED;
-
- *path = strdup(result.c_str());
- if (*path == nullptr) {
- LOGE("Out of memory");
- return AUL_R_ENOMEM;
- }
-
- return AUL_R_OK;
-}
-
-AUL_API int aul_get_app_res_control_global_resource_path(const char* res_type,
- char** path) {
- if (res_type == nullptr || path == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* context = GetCurrentContext();
- if (context == nullptr)
- return AUL_R_ERROR;
-
- std::string result = context->GetResControlGlobalResPath() + res_type + "/";
-
- if (access(result.c_str(), F_OK) != 0)
- return AUL_R_EREJECTED;
-
- *path = strdup(result.c_str());
- if (*path == nullptr) {
- LOGE("Out of memory");
- return AUL_R_ENOMEM;
- }
-
- return AUL_R_OK;
-}
-
-AUL_API int aul_get_app_shared_data_path_by_appid(const char* appid,
- char** path) {
- if (path == nullptr)
- return AUL_R_EINVAL;
-
- if (appid == nullptr)
- return aul_get_app_shared_data_path(path);
-
- std::unique_ptr<aul::DirectoryInfo> info(
- aul::DirectoryInfo::Get(appid, getuid()));
- if (info.get() == nullptr)
- return AUL_R_ENOAPP;
-
- if (access(info->GetSharedDataPath().c_str(), F_OK) != 0)
- return AUL_R_EREJECTED;
-
- *path = strdup(info->GetSharedDataPath().c_str());
- return AUL_R_OK;
-}
-
-AUL_API int aul_get_app_shared_resource_path_by_appid(const char* appid,
- char** path) {
- if (appid == nullptr || path == nullptr)
- return AUL_R_EINVAL;
-
- std::unique_ptr<aul::DirectoryInfo> info(
- aul::DirectoryInfo::Get(appid, getuid()));
- if (info.get() == nullptr)
- return AUL_R_ENOAPP;
-
- *path = strdup(info->GetSharedResourcePath().c_str());
- return AUL_R_OK;
-}
-
-AUL_API int aul_get_app_shared_trusted_path_by_appid(const char* appid,
- char** path) {
- if (appid == nullptr || path == nullptr)
- return AUL_R_EINVAL;
-
- std::unique_ptr<aul::DirectoryInfo> info(
- aul::DirectoryInfo::Get(appid, getuid()));
- if (info.get() == nullptr)
- return AUL_R_ENOAPP;
-
- *path = strdup(info->GetSharedTrustedPath().c_str());
- return AUL_R_OK;
-}
-
-AUL_API int aul_get_app_external_shared_data_path_by_appid(const char* appid,
- char** path) {
- if (appid == nullptr || path == nullptr)
- return AUL_R_EINVAL;
-
- std::unique_ptr<aul::ExternalDirectoryInfo> info(
- aul::ExternalDirectoryInfo::Get(appid, getuid()));
- if (info.get() == nullptr)
- return AUL_R_ENOAPP;
-
- *path = strdup(info->GetSharedDataPath().c_str());
- return AUL_R_OK;
-}
-
-AUL_API int aul_get_usr_app_shared_data_path_by_appid(const char* appid,
- char** path, uid_t uid) {
- if (appid == nullptr || path == nullptr)
- return AUL_R_EINVAL;
-
- std::unique_ptr<aul::DirectoryInfo> info(
- aul::DirectoryInfo::Get(appid, uid));
- if (info.get() == nullptr)
- return AUL_R_ENOAPP;
-
- if (access(info->GetSharedDataPath().c_str(), F_OK) != 0)
- return AUL_R_EREJECTED;
-
- *path = strdup(info->GetSharedDataPath().c_str());
- return AUL_R_OK;
-}
-
-AUL_API int aul_get_usr_app_shared_resource_path_by_appid(const char* appid,
- char** path, uid_t uid) {
- if (appid == nullptr || path == nullptr)
- return AUL_R_EINVAL;
-
- std::unique_ptr<aul::DirectoryInfo> info(
- aul::DirectoryInfo::Get(appid, uid));
- if (info.get() == nullptr)
- return AUL_R_ENOAPP;
-
- *path = strdup(info->GetSharedResourcePath().c_str());
- return AUL_R_OK;
-}
-
-AUL_API int aul_get_usr_app_shared_trusted_path_by_appid(const char* appid,
- char** path, uid_t uid) {
- if (appid == nullptr || path == nullptr)
- return AUL_R_EINVAL;
-
- std::unique_ptr<aul::DirectoryInfo> info(
- aul::DirectoryInfo::Get(appid, uid));
- if (info.get() == nullptr)
- return AUL_R_ENOAPP;
-
- *path = strdup(info->GetSharedTrustedPath().c_str());
- return AUL_R_OK;
-}
-
-AUL_API int aul_get_usr_app_external_shared_data_path_by_appid(
- const char* appid, char** path, uid_t uid) {
- if (appid == nullptr || path == nullptr)
- return AUL_R_EINVAL;
-
- std::unique_ptr<aul::ExternalDirectoryInfo> info(
- aul::ExternalDirectoryInfo::Get(appid, uid));
- if (info.get() == nullptr)
- return AUL_R_ENOAPP;
-
- *path = strdup(info->GetSharedDataPath().c_str());
- return AUL_R_OK;
-}
+++ /dev/null
-/*
- * Copyright (c) 2000 - 2021 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 <bundle_internal.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include <bundle_cpp.h>
-
-#include <string>
-#include <memory>
-#include <mutex>
-
-#include "app_request.h"
-#include "aul_api.h"
-#include "aul_util.h"
-#include "include/aul_proc.h"
-#include "include/aul_sock.h"
-
-#include "aul/common/file_descriptor.hh"
-
-using namespace aul;
-using namespace aul::internal;
-
-namespace {
-
-class ProcContext {
- public:
- ProcContext() {}
- ~ProcContext() {}
-
- void SetName(std::string name) {
- std::lock_guard<std::mutex> lock(mutex_);
- name_ = std::move(name);
- }
-
- const std::string& GetName() {
- std::lock_guard<std::mutex> lock(mutex_);
- return name_;
- }
-
- void SetExtra(tizen_base::Bundle extra) {
- std::lock_guard<std::mutex> lock(mutex_);
- extra_ = std::move(extra);
- }
-
- tizen_base::Bundle& GetExtra() {
- std::lock_guard<std::mutex> lock(mutex_);
- return extra_;
- }
-
- void SetFd(int fd) {
- std::lock_guard<std::mutex> lock(mutex_);
- fd_.Set(fd);
- }
-
- void Close() {
- std::lock_guard<std::mutex> lock(mutex_);
- fd_.Close();
- }
-
- bool IsClosed() {
- std::lock_guard<std::mutex> lock(mutex_);
- return fd_.IsClosed();
- }
-
- private:
- FileDescriptor fd_;
- std::string name_;
- tizen_base::Bundle extra_;
- mutable std::mutex mutex_;
-};
-
-int ReadFromPath(const std::string& path, char* buf, size_t buf_size) {
- int fd = open(path.c_str(), O_RDONLY);
- if (fd < 0) {
- _E("open() is failed. path(%s), errno(%d)", path.c_str(), errno);
- return AUL_R_ERROR;
- }
-
- FileDescriptor fd_closer(fd);
- ssize_t bytes = read(fd, buf, buf_size - 1);
- if (bytes <= 0) {
- _E("read() is failed. errno(%d)", errno);
- return AUL_R_ERROR;
- }
-
- buf[bytes] = '\0';
- return AUL_R_OK;
-}
-
-int SendAndReceive(int cmd, pid_t pid, uid_t uid, bundle** response) {
- int fd = AppRequest(cmd, uid)
- .SetPid(pid)
- .SendSimply(AUL_SOCK_ASYNC);
- if (fd < 0 || fd >= sysconf(_SC_OPEN_MAX)) {
- _E("Failed to send request. error(%d)", fd);
- return fd;
- }
-
- FileDescriptor fd_closer(fd);
- app_pkt_t* pkt = nullptr;
- int ret = aul_sock_recv_reply_pkt(fd, &pkt);
- if (ret < 0) {
- _E("Failed to receive reply packet. error(%d)", ret);
- return AUL_R_ECOMM;
- }
-
- std::unique_ptr<app_pkt_t, decltype(std::free)*> pkt_auto(pkt, std::free);
- if (!(pkt->opt & AUL_SOCK_BUNDLE)) {
- _E("Invalid protocol");
- return AUL_R_ECOMM;
- }
-
- if (pkt->cmd != APP_GET_INFO_OK) {
- _E("Failed to get name by pid(%d)", pid);
- return AUL_R_ERROR;
- }
-
- *response = bundle_decode(pkt->data, pkt->len);
- if (*response == nullptr) {
- _E("bundle_decode() is failed");
- return AUL_R_ERROR;
- }
-
- return AUL_R_OK;
-}
-
-ProcContext context;
-
-} // namespace
-
-extern "C" API int aul_proc_get_uid(pid_t pid, uid_t* uid) {
- if (pid < 1 || uid == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- std::string path = "/proc/" + std::to_string(pid);
- struct stat stat_buf;
- int ret = stat(path.c_str(), &stat_buf);
- if (ret < 0) {
- _E("stat() is failed. path(%s), errno(%d)", path.c_str(), errno);
- return AUL_R_ERROR;
- }
-
- *uid = stat_buf.st_uid;
- return AUL_R_OK;
-}
-
-extern "C" API int aul_proc_get_attr(pid_t pid, char* buf, size_t buf_size) {
- if (pid < 1 || buf == nullptr || buf_size <= 0) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- std::string path = "/proc/" + std::to_string(pid) + "/attr/current";
- return ReadFromPath(path, buf, buf_size);
-}
-
-extern "C" API int aul_proc_get_cmdline(pid_t pid, char* buf, size_t buf_size) {
- if (pid < 1 || buf == nullptr || buf_size <= 0) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- std::string path = "/proc/" + std::to_string(pid) + "/cmdline";
- return ReadFromPath(path, buf, buf_size);
-}
-
-extern "C" API int aul_proc_register(const char* name, bundle* extra) {
- if (name == nullptr || name[0] == '\0') {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- if (!context.IsClosed()) {
- _E("Already registered. Please call aul_proc_deregister() first");
- return AUL_R_ERROR;
- }
-
- tizen_base::Bundle b {{AUL_K_PROC_NAME, name}};
- if (extra) {
- tizen_base::Bundle extra_data(extra, false, false);
- auto raw = extra_data.ToRaw();
- b.Add(AUL_K_PROC_EXTRA, reinterpret_cast<const char*>(raw.first.get()));
- }
-
- int ret = AppRequest(PROC_REGISTER, getuid())
- .With(b)
- .SendSimply(AUL_SOCK_ASYNC);
- if (ret < 0) {
- _E("Failed to send request. name(%s), error(%d)", name, ret);
- return ret;
- }
-
- int res = aul_sock_recv_result_with_fd(ret);
- if (res != 0) {
- _E("Failed to receive the result. fd(%d)", res);
- close(ret);
- return AUL_R_ERROR;
- }
-
- context.SetFd(ret);
- context.SetName(name);
- if (extra)
- context.SetExtra(tizen_base::Bundle(extra, true, true));
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_proc_deregister(void) {
- if (context.IsClosed()) {
- _E("Invalid context");
- return AUL_R_ERROR;
- }
-
- int ret = AppRequest(PROC_DEREGISTER, getuid())
- .SendSimply(AUL_SOCK_NOREPLY);
- if (ret < 0) {
- _E("Failed to send request. error(%d)", ret);
- return ret;
- }
-
- context.Close();
- return AUL_R_OK;
-}
-
-extern "C" API int aul_proc_get_name(pid_t pid, char** name) {
- if (pid < 1 || name == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- if (pid == getpid() && !context.IsClosed() && !context.GetName().empty()) {
- *name = strdup(context.GetName().c_str());
- if (*name == nullptr) {
- _E("strdup() is failed");
- return AUL_R_ENOMEM;
- }
-
- return AUL_R_OK;
- }
-
- bundle* response;
- int ret = SendAndReceive(PROC_GET_NAME, pid, getuid(), &response);
- if (ret != AUL_R_OK)
- return ret;
-
- tizen_base::Bundle b(response, false, true);
- std::string val = b.GetString(AUL_K_PROC_NAME);
- if (val.empty()) {
- _E("Failed to get name");
- return AUL_R_ERROR;
- }
-
- *name = strdup(val.c_str());
- if (*name == nullptr) {
- _E("strdup() is failed");
- return AUL_R_ENOMEM;
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_proc_get_extra(pid_t pid, bundle** extra) {
- if (pid < 1 || extra == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- if (pid == getpid() && !context.IsClosed()) {
- auto& extra_data = context.GetExtra();
- *extra = bundle_dup(extra_data.GetHandle());
- if (*extra == nullptr) {
- _E("bundle_dup() is failed");
- return AUL_R_ENOMEM;
- }
-
- return AUL_R_OK;
- }
-
- bundle* response;
- int ret = SendAndReceive(PROC_GET_EXTRA, pid, getuid(), &response);
- if (ret != AUL_R_OK)
- return ret;
-
- tizen_base::Bundle b(response, false, true);
- std::string raw = b.GetString(AUL_K_PROC_EXTRA);
- if (raw.empty()) {
- _E("Failed to get extra");
- return AUL_R_ERROR;
- }
-
- tizen_base::Bundle extra_data(raw);
- *extra = extra_data.Detach();
- return AUL_R_OK;
-}
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul_proc_group.h"
-
-#include <fcntl.h>
-#include <stdio.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include "app_request.h"
-#include "aul_api.h"
-#include "aul_util.h"
-#include "include/aul_error.h"
-#include "include/aul_sock.h"
-
-#include "aul/common/file_descriptor.hh"
-
-using namespace aul;
-using namespace aul::internal;
-
-namespace {
-
-class ProcGroupInfo {
- public:
- ProcGroupInfo(pid_t leader_pid, std::vector<pid_t> sub_pids)
- : leader_pid_(leader_pid), sub_pids_(std::move(sub_pids)) {}
-
- pid_t GetLeaderPid() const {
- return leader_pid_;
- }
-
- const std::vector<pid_t>& GetSubPids() const {
- return sub_pids_;
- }
-
- private:
- pid_t leader_pid_;
- std::vector<pid_t> sub_pids_;
-};
-
-int SendAndReceive(int cmd, pid_t pid, bundle** response) {
- int fd = AppRequest(cmd, getuid())
- .SetPid(pid)
- .SendSimply(AUL_SOCK_ASYNC);
- if (fd < 0 || fd >= sysconf(_SC_OPEN_MAX)) {
- _E("Failed to send request. error(%d)", fd);
- return fd;
- }
-
- FileDescriptor fd_closer(fd);
- app_pkt_t* pkt = nullptr;
- int ret = aul_sock_recv_reply_pkt(fd, &pkt);
- if (ret < 0) {
- _E("Failed to receive reply packet. error(%d)", ret);
- return AUL_R_ECOMM;
- }
-
- std::unique_ptr<app_pkt_t, decltype(std::free)*> pkt_auto(pkt, std::free);
- if (!(pkt->opt & AUL_SOCK_BUNDLE)) {
- _E("Invalid protocol");
- return AUL_R_ECOMM;
- }
-
- if (pkt->cmd != APP_GET_INFO_OK) {
- _E("Failed to get result");
- return AUL_R_ERROR;
- }
-
- *response = bundle_decode(pkt->data, pkt->len);
- if (*response == nullptr) {
- _E("bundle_decode() is failed");
- return AUL_R_ERROR;
- }
-
- return AUL_R_OK;
-}
-
-} // namespace
-
-extern "C" API int aul_proc_group_add(pid_t pid) {
- if (pid < 1) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- int ret = AppRequest(PROC_GROUP_ADD, getuid())
- .SetPid(pid)
- .SendSimply();
- if (ret < 0) {
- _E("Failed to send the request. error(%d)", ret);
- return aul_error_convert(ret);
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_proc_group_remove(pid_t pid) {
- if (pid < 1) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- int ret = AppRequest(PROC_GROUP_REMOVE, getuid())
- .SetPid(pid)
- .SendSimply();
- if (ret < 0) {
- _E("Failed to send the request. error(%d)", ret);
- return aul_error_convert(ret);
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_proc_group_foreach(aul_proc_group_cb callback,
- void *user_data) {
- if (callback == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- bundle* response = nullptr;
- int ret = SendAndReceive(PROC_GROUP_FOREACH, 0, &response);
- if (ret != AUL_R_OK)
- return ret;
-
- tizen_base::Bundle b(response, false, true);
- auto length_str = b.GetString("__K_LENGTH");
- int length = std::stoi(length_str);
- for (int i = 0; i < length; ++i) {
- auto group = b.GetStringArray(std::to_string(i));
- if (group.size() == 0) {
- _E("Invalid size. index(%d)", i);
- continue;
- }
-
- pid_t leader_pid = std::stoi(group[0]);
- std::vector<pid_t> sub_pids;
- for (size_t index = 1; index < group.size(); ++index)
- sub_pids.push_back(std::stoi(group[index]));
-
- ProcGroupInfo info(leader_pid, std::move(sub_pids));
- callback(static_cast<aul_proc_group_info_h>(&info), user_data);
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_proc_group_info_get_leader_pid(aul_proc_group_info_h h,
- pid_t* leader_pid) {
- if (h == nullptr || leader_pid == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* info = static_cast<ProcGroupInfo*>(h);
- *leader_pid = info->GetLeaderPid();
- return AUL_R_OK;
-}
-
-extern "C" API int aul_proc_group_info_get_sub_pids(aul_proc_group_info_h h,
- const pid_t** sub_pids, size_t* length) {
- if (h == nullptr || sub_pids == nullptr || length == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* info = static_cast<ProcGroupInfo*>(h);
- auto& pids = info->GetSubPids();
- *sub_pids = const_cast<pid_t*>(pids.data());
- *length = pids.size();
- return AUL_R_OK;
-}
-
-extern "C" API int aul_proc_group_get(pid_t pid,
- aul_proc_group_info_h *h) {
- if (pid < 2 || h == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- bundle* response = nullptr;
- int ret = SendAndReceive(PROC_GROUP_GET, pid, &response);
- if (ret != AUL_R_OK)
- return ret;
-
- tizen_base::Bundle b(response, false, true);
- auto group = b.GetStringArray("__K_GROUP_INFO");
- if (group.size() == 0) {
- _E("There is no group info. pid(%d)", pid);
- return AUL_R_ENOENT;
- }
-
- pid_t leader_pid = std::stoi(group[0]);
- std::vector<pid_t> sub_pids;
- for (size_t index = 1; index < group.size(); ++index)
- sub_pids.push_back(std::stoi(group[index]));
-
- auto* info = new (std::nothrow) ProcGroupInfo(leader_pid,
- std::move(sub_pids));
- if (info == nullptr) {
- _E("Out of memory");
- return AUL_R_ENOMEM;
- }
-
- *h = static_cast<aul_proc_group_info_h>(info);
- return AUL_R_OK;
-}
-
-extern "C" API int aul_proc_group_info_destroy(aul_proc_group_info_h h) {
- if (h == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* handle = static_cast<ProcGroupInfo*>(h);
- delete handle;
- return AUL_R_OK;
-}
+++ /dev/null
-/*
- * Copyright (c) 2018 - 2021 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 <bundle_cpp.h>
-#include <bundle_internal.h>
-#include <glib.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include <memory>
-#include <string>
-
-#include "app_request.h"
-#include "aul_api.h"
-#include "aul_util.h"
-#include "include/aul.h"
-#include "include/aul_app_com.h"
-#include "include/aul_error.h"
-#include "include/aul_rpc_port.h"
-#include "include/aul_sock.h"
-#include "include/aul_svc.h"
-
-using namespace aul::internal;
-
-namespace {
-
-constexpr const char kEndpoint[] = "org.tizen.rpcport";
-constexpr const char kInterfacePrefix[] = "org.tizen.rpcport._";
-constexpr const char kPathRunAulRpcPort[] = "/run/aul/rpcport/";
-
-class WatchInfo {
- public:
- WatchInfo(std::string app_id, std::string port_name,
- aul_rpc_port_appeared_cb appeared_cb,
- aul_rpc_port_vanished_cb vanished_cb,
- void* user_data, uid_t uid)
- : app_id_(std::move(app_id)),
- port_name_(std::move(port_name)),
- appeared_cb_(appeared_cb),
- vanished_cb_(vanished_cb),
- user_data_(user_data),
- uid_(uid) {
- }
-
- ~WatchInfo() {}
-
- int Watch() {
- int ret = aul_app_com_create(kEndpoint, nullptr, AppComCb, this, &conn_);
- if (ret != AUL_R_OK)
- _E("aul_app_com_create() is failed. error(%d)", ret);
-
- return ret;
- }
-
- void Unwatch() {
- if (conn_) {
- aul_app_com_leave(conn_);
- conn_ = nullptr;
- }
- }
-
- private:
- static int AppComCb(const char* endpoint, aul_app_com_result_e result,
- bundle* envelope, void* user_data) {
- auto* info = static_cast<WatchInfo*>(user_data);
- tizen_base::Bundle b(envelope, false, false);
- std::string app_id = b.GetString(AUL_K_APPID);
- if (info->app_id_ != app_id)
- return -1;
-
- std::string port_name = b.GetString(AUL_K_RPC_PORT);
- if (info->port_name_ != port_name)
- return -1;
-
- std::string uid_str = b.GetString(AUL_K_CALLER_UID);
- uid_t uid =
- static_cast<uid_t>(std::stoul(uid_str, nullptr, 10) & UINT32_MAX);
- if (info->uid_ != uid)
- return -1;
-
- std::string pid_str = b.GetString(AUL_K_PID);
- int pid = std::stoi(pid_str);
- std::string event_name = b.GetString(AUL_K_EVENT_NAME);
- if (event_name == "Appeared") {
- info->appeared_cb_(app_id.c_str(), port_name.c_str(), pid,
- info->user_data_);
- } else {
- info->vanished_cb_(app_id.c_str(), port_name.c_str(), pid,
- info->user_data_);
- }
-
- return 0;
- }
-
- private:
- std::string app_id_;
- std::string port_name_;
- aul_rpc_port_appeared_cb appeared_cb_;
- aul_rpc_port_vanished_cb vanished_cb_;
- void* user_data_;
- uid_t uid_;
- aul_app_com_connection_h conn_ = nullptr;
-};
-
-std::string GetInterfaceName(const std::string& app_id,
- const std::string& port_name, uid_t uid) {
- std::string name = kInterfacePrefix + app_id + "_" + port_name;
- char* checksum = g_compute_checksum_for_string(G_CHECKSUM_SHA1,
- name.c_str(), name.length());
- std::unique_ptr<char, decltype(g_free)*> checksum_auto(checksum, g_free);
- return std::to_string(uid) + "@" + std::string(checksum);
-}
-
-std::string GetPath(const std::string& interface_name) {
- return std::string(kPathRunAulRpcPort) + "." + interface_name;
-}
-
-} // namespace
-
-extern "C" API int aul_rpc_port_prepare_stub(const char* app_id,
- const char* port_name) {
- return aul_rpc_port_usr_prepare_stub(app_id, port_name, getuid());
-}
-
-extern "C" API int aul_rpc_port_usr_prepare_stub(const char* app_id,
- const char* port_name, uid_t uid) {
- if (app_id == nullptr || port_name == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- tizen_base::Bundle b {{AUL_K_RPC_PORT, port_name}};
- int ret = AppRequest(RPC_PORT_PREPARE_STUB, uid)
- .With(b)
- .SetAppId(app_id)
- .SendSimply(AUL_SOCK_QUEUE);
- if (ret < 0) {
- _E("Failed to send request. app_id(%s), port_name(%s)", app_id, port_name);
- return ret;
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_rpc_port_create_socket_pair(const char* app_id,
- const char* port_name, int (*fds)[2]) {
- if (app_id == nullptr || port_name == nullptr || fds == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- tizen_base::Bundle b {{AUL_K_RPC_PORT, port_name}};
- int fd = AppRequest(RPC_PORT_CREATE_SOCKET_PAIR, getuid())
- .With(b)
- .SetAppId(app_id)
- .SendSimply(AUL_SOCK_ASYNC);
- if (fd <= 0 || fd >= sysconf(_SC_OPEN_MAX)) {
- _E("Failed to send socket pair creation request. error(%d)", fd);
- return fd;
- }
-
- int ret = aul_sock_recv_reply_sock_fd(fd, fds, 2);
- if (ret != 0) {
- _E("Failed to receive socket fds. error(%d)", ret);
- return aul_error_convert(ret);
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_rpc_port_notify_rpc_finished(void) {
- int ret = AppRequest(RPC_PORT_NOTIFY_RPC_FINISHED, getuid())
- .SetPid(getpid())
- .SendSimply(AUL_SOCK_NOREPLY);
- if (ret != 0) {
- _E("Failed to notify rpc finished. error(%d)", ret);
- return ret;
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_rpc_port_set_private_sharing(const char* app_id,
- const char* paths[], unsigned int size) {
- if (app_id == nullptr || paths == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- tizen_base::Bundle b {{AUL_K_CALLEE_APPID, app_id}};
- std::vector<std::string> v;
- for (unsigned int i = 0; i < size; ++i)
- v.push_back(paths[i]);
- b.Add(AUL_SVC_DATA_PATH, v);
-
- int ret = AppRequest(SET_PRIVATE_SHARING, getuid())
- .With(b)
- .SetPid(getpid())
- .SendSimply(AUL_SOCK_NOREPLY);
- if (ret != 0) {
- _E("Failed to set private sharing. error(%d)", ret);
- return ret;
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_rpc_port_unset_private_sharing(const char* app_id) {
- if (app_id == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- tizen_base::Bundle b {{AUL_K_CALLEE_APPID, app_id}};
- int ret = AppRequest(UNSET_PRIVATE_SHARING, getuid())
- .With(b)
- .SetPid(getpid())
- .SendSimply(AUL_SOCK_NOREPLY);
- if (ret != 0) {
- _E("Failed to unset private sharing. error(%d)", ret);
- return ret;
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_rpc_port_create(const char* port_name, int* fd) {
- return aul_rpc_port_usr_create(port_name, getuid(), fd);
-}
-
-extern "C" API int aul_rpc_port_usr_create(const char* port_name, uid_t uid,
- int* fd) {
- if (port_name == nullptr || fd == nullptr) {
- _E("Invalid paramter");
- return AUL_R_EINVAL;
- }
-
- tizen_base::Bundle b {{AUL_K_RPC_PORT, port_name}};
- int req_fd = AppRequest(RPC_PORT_CREATE, uid)
- .With(b)
- .SendSimply(AUL_SOCK_ASYNC);
- if (req_fd <= 0 || req_fd >= sysconf(_SC_OPEN_MAX)) {
- _E("Failed to send socket creation request. error(%d)", req_fd);
- return req_fd;
- }
-
- int fds[2] = { -1, };
- int ret = aul_sock_recv_reply_sock_fd(req_fd, &fds, 1);
- if (ret != 0) {
- _E("Failed to receive socket fds. error(%d)", ret);
- return aul_error_convert(ret);
- }
-
- *fd = fds[0];
- return AUL_R_OK;
-}
-
-extern "C" API int aul_rpc_port_destroy(const char* port_name) {
- return aul_rpc_port_usr_destroy(port_name, getuid());
-}
-
-extern "C" API int aul_rpc_port_usr_destroy(const char* port_name, uid_t uid) {
- if (port_name == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- tizen_base::Bundle b {{AUL_K_RPC_PORT, port_name}};
- int ret = AppRequest(RPC_PORT_DESTROY, uid)
- .With(b)
- .SendSimply(AUL_SOCK_NOREPLY);
- if (ret != 0) {
- _E("Failed to send socket desctruction request. error(%d)", ret);
- return ret;
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_rpc_port_add_watch(const char* app_id,
- const char* port_name, aul_rpc_port_appeared_cb appeared_cb,
- aul_rpc_port_vanished_cb vanished_cb, void* user_data,
- aul_rpc_port_watch_h* handle) {
- return aul_rpc_port_usr_add_watch(app_id, port_name, appeared_cb, vanished_cb,
- user_data, getuid(), handle);
-}
-
-extern "C" API int aul_rpc_port_usr_add_watch(const char* app_id,
- const char* port_name, aul_rpc_port_appeared_cb appeared_cb,
- aul_rpc_port_vanished_cb vanished_cb, void* user_data, uid_t uid,
- aul_rpc_port_watch_h* handle) {
- if (app_id == nullptr || port_name == nullptr || appeared_cb == nullptr ||
- vanished_cb == nullptr || handle == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* info = new (std::nothrow) WatchInfo(app_id, port_name, appeared_cb,
- vanished_cb, user_data, uid);
- if (info == nullptr) {
- _E("Out of memory");
- return AUL_R_ENOMEM;
- }
-
- int ret = info->Watch();
- if (ret != AUL_R_OK) {
- delete info;
- return ret;
- }
-
- *handle = static_cast<aul_rpc_port_watch_h>(info);
- return AUL_R_OK;
-}
-
-extern "C" API int aul_rpc_port_remove_watch(aul_rpc_port_watch_h handle) {
- if (handle == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* info = static_cast<WatchInfo*>(handle);
- info->Unwatch();
- delete info;
- return AUL_R_OK;
-}
-
-extern "C" API int aul_rpc_port_exist(const char* app_id, const char* port_name,
- bool* exist) {
- return aul_rpc_port_usr_exist(app_id, port_name, getuid(), exist);
-}
-
-extern "C" API int aul_rpc_port_usr_exist(const char* app_id,
- const char* port_name, uid_t uid, bool* exist) {
- if (app_id == nullptr || port_name == nullptr || exist == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- char* port_path;
- if (aul_rpc_port_usr_get_path(app_id, port_name, uid, &port_path) != AUL_R_OK)
- return AUL_R_ENOMEM;
-
- int ret = access(port_path, F_OK);
- free(port_path);
- *exist = (ret == 0) ? true : false;
- return AUL_R_OK;
-}
-
-extern "C" API int aul_rpc_port_get_path(const char* app_id,
- const char* port_name, char** path) {
- return aul_rpc_port_usr_get_path(app_id, port_name, getuid(), path);
-}
-
-extern "C" API int aul_rpc_port_usr_get_path(const char* app_id,
- const char* port_name, uid_t uid, char** path) {
- if (app_id == nullptr || port_name == nullptr || path == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- std::string interface_name = GetInterfaceName(app_id, port_name, uid);
- std::string port_path = GetPath(interface_name);
- struct sockaddr_un addr = { 0, };
- snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", port_path.c_str());
- *path = strdup(addr.sun_path);
- if (*path == nullptr) {
- _E("Out of memory");
- return AUL_R_ENOMEM;
- }
-
- return AUL_R_OK;
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#define _GNU_SOURCE
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdint.h>
-#include <glib/gstdio.h>
-#include <bundle_internal.h>
-#include <assert.h>
-#include <dlog.h>
-#include <vconf.h>
-#include <system_info.h>
-
-#include "aul.h"
-#include "aul_api.h"
-#include "aul_rsc_mgr.h"
-#include "aul_rsc_mgr_internal.h"
-
-#define WEIGHT_SCREEN_DPI 10000
-#define WEIGHT_SCREEN_DPI_RANGE 10000
-#define WEIGHT_SCREEN_BPP 1000
-#define WEIGHT_SCREEN_WIDTH_RANGE 100
-#define WEIGHT_SCREEN_LARGE 10
-#define WEIGHT_PLATFORM_VERSION 1000000
-#define WEIGHT_LANGUAGE 100000
-
-#define THRESHOLD_TO_CLEAN 50 /* app_resource_manager_trim_cache */
-
-#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))
-#define MAX_PATH 1024
-
-typedef struct {
- resource_data_t *data;
- GHashTable *cache;
-} resource_manager_t;
-
-typedef struct {
- char *output;
- int hit_cnt;
- bool remove;
-} resource_cache_context_t;
-
-typedef struct {
- const char *bundle_attr_key;
- unsigned int bundle_attr_value;
-} resource_node_attr_t;
-
-typedef struct {
- char *folder;
- char *type;
-} resource_node_list_t;
-
-enum {
- NODE_ATTR_MIN = 0,
- NODE_ATTR_SCREEN_DPI,
- NODE_ATTR_SCREEN_DPI_RANGE,
- NODE_ATTR_SCREEN_WIDTH_RANGE,
- NODE_ATTR_SCREEN_LARGE,
- NODE_ATTR_SCREEN_BPP,
- NODE_ATTR_PLATFORM_VER,
- NODE_ATTR_LANGUAGE,
- NODE_ATTR_MAX
-};
-
-static resource_manager_t *resource_handle = NULL;
-
-static resource_node_attr_t map[] = {
- { RSC_NODE_ATTR_SCREEN_DPI, NODE_ATTR_SCREEN_DPI },
- { RSC_NODE_ATTR_SCREEN_DPI_RANGE, NODE_ATTR_SCREEN_DPI_RANGE },
- { RSC_NODE_ATTR_SCREEN_WIDTH_RANGE, NODE_ATTR_SCREEN_WIDTH_RANGE },
- { RSC_NODE_ATTR_SCREEN_LARGE, NODE_ATTR_SCREEN_LARGE },
- { RSC_NODE_ATTR_SCREEN_BPP, NODE_ATTR_SCREEN_BPP },
- { RSC_NODE_ATTR_PLATFORM_VER, NODE_ATTR_PLATFORM_VER },
- { RSC_NODE_ATTR_LANGUAGE, NODE_ATTR_LANGUAGE },
-};
-
-static GHashTable *attr_key = NULL;
-static const char *res_path = NULL;
-static char *cur_language = NULL;
-static bool is_slice = FALSE;
-
-static GHashTable *valid_path_list = NULL;
-static GHashTable *supported_lang_list = NULL;
-static GHashTable *id_list = NULL;
-static GList *all_node_list = NULL;
-static bundle *given_attr_list = NULL;
-
-static gint __resource_manager_comp(gconstpointer a, gconstpointer b)
-{
- resource_group_t *rsc_group = (resource_group_t *) a;
-
- return strcmp(rsc_group->type, b);
-}
-
-static gint __compare_path(gconstpointer a, gconstpointer b)
-{
- char tmp_path[MAX_PATH] = {0, };
- resource_node_list_t *tmp_node_info = (resource_node_list_t *)a;
-
- snprintf(tmp_path, MAX_PATH - 1, "%s%s", res_path, tmp_node_info->folder);
- return strncmp(tmp_path, (char *)b, strlen(tmp_path));
-}
-
-static int __get_dpi(void)
-{
- int dpi = 0;
- char *tmp = NULL;
-
- if (is_slice) {
- bundle_get_str(given_attr_list, RSC_NODE_ATTR_SCREEN_DPI, &tmp);
- if (tmp == NULL) {
- LOGE("Failed to retrieve DPI");
- dpi = 0;
- } else {
- dpi = atoi(tmp);
- }
- } else {
- system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
- }
-
- return dpi;
-}
-
-static int __get_screen_width(void)
-{
- int screen_width = 0;
- char *tmp = NULL;
-
- if (is_slice) {
- bundle_get_str(given_attr_list, RSC_NODE_ATTR_SCREEN_WIDTH_RANGE, &tmp);
- if (tmp == NULL) {
- LOGE("Failed to retrieve screen width");
- screen_width = 0;
- } else
- screen_width = atoi(tmp);
- } else
- system_info_get_platform_int("http://tizen.org/feature/screen.width", &screen_width);
-
- return screen_width;
-}
-
-static bool __get_screen_large(void)
-{
- bool screen_large = true;
- char *tmp = NULL;
-
- if (is_slice) {
- bundle_get_str(given_attr_list, RSC_NODE_ATTR_SCREEN_LARGE, &tmp);
- if (tmp == NULL) {
- LOGE("Failed to retrieve screen large");
- screen_large = false;
- } else
- screen_large = atoi(tmp);
- } else {
- if (system_info_get_platform_bool("http://tizen.org/feature/screen.size.large", &screen_large) != SYSTEM_INFO_ERROR_NONE) {
- LOGE("Failed to get info of screen.size.large");
- screen_large = false;
- }
- }
-
- return screen_large;
-}
-
-static int __get_screen_bpp(void)
-{
- int screen_bpp = 0;
- char *tmp = NULL;
-
- if (is_slice) {
- bundle_get_str(given_attr_list, RSC_NODE_ATTR_SCREEN_BPP, &tmp);
- if (tmp == NULL) {
- LOGE("Failed to retrieve screen bpp");
- screen_bpp = 0;
- } else
- screen_bpp = atoi(tmp);
- } else
- system_info_get_platform_int("http://tizen.org/feature/screen.bpp", &screen_bpp);
-
- return screen_bpp;
-}
-
-static char *__get_platform_version(void)
-{
- char *version = NULL;
- if (is_slice)
- bundle_get_str(given_attr_list, RSC_NODE_ATTR_PLATFORM_VER, &version);
- else
- system_info_get_platform_string("http://tizen.org/feature/platform.version", &version);
-
- return version;
-}
-
-static void __bundle_iterator_get_valid_nodes(const char *key, const int type,
- const bundle_keyval_t *kv, void *data)
-{
- unsigned int node_attr;
- bool *invalid = (bool *) data;
- bool ret_bool = true;
- int min, max;
- char *from = NULL;
- char *to = NULL;
- bool t_val;
- char *val;
- size_t size;
- static int screen_dpi = -1;
- static int screen_width = -1;
- static int screen_size_large = -1;
- static char *version = NULL;
- static int screen_bpp = -1;
-
- if (*invalid)
- return;
-
- bundle_keyval_get_basic_val((bundle_keyval_t *) kv, (void**) &val, &size);
-
- node_attr = (uintptr_t)g_hash_table_lookup(attr_key, key);
- if (node_attr <= NODE_ATTR_MIN || node_attr >= NODE_ATTR_MAX) {
- LOGE("INVALID_PARAMETER(0x%08x), node_attr(%d)",
- AUL_RESOURCE_ERROR_INVALID_PARAMETER, node_attr);
- *invalid = true;
- return;
- }
-
- switch (node_attr) {
- case NODE_ATTR_SCREEN_DPI:
- if (screen_dpi == -1)
- screen_dpi = __get_dpi();
- if (screen_dpi != atoi(val))
- *invalid = true;
- break;
- case NODE_ATTR_SCREEN_DPI_RANGE:
- sscanf(val, "%ms %d %ms %d", &from, &min, &to, &max);
- if (screen_dpi == -1)
- screen_dpi = __get_dpi();
- if (!(min <= screen_dpi && screen_dpi <= max))
- *invalid = true;
- if (from)
- free(from);
- if (to)
- free(to);
- break;
- case NODE_ATTR_SCREEN_WIDTH_RANGE:
- sscanf(val, "%ms %d %ms %d", &from, &min, &to, &max);
- if (screen_width == -1)
- screen_width = __get_screen_width();
- if (!(min <= screen_width && screen_width <= max))
- *invalid = true;
- if (from)
- free(from);
- if (to)
- free(to);
- break;
- case NODE_ATTR_SCREEN_LARGE:
- if (!(strcmp(val, "true")))
- t_val = true;
- else
- t_val = false;
- if (screen_size_large == -1) {
- ret_bool = __get_screen_large();
- if (ret_bool)
- screen_size_large = 1;
- else
- screen_size_large = 0;
- }
- if (((bool)screen_size_large) != t_val)
- *invalid = true;
- break;
- case NODE_ATTR_SCREEN_BPP:
- if (screen_bpp == -1)
- screen_bpp = __get_screen_bpp();
- if (screen_bpp != atoi(val))
- *invalid = true;
- break;
- case NODE_ATTR_PLATFORM_VER:
- if (version == NULL)
- version = __get_platform_version();
- if (strcmp(version, val))
- *invalid = true;
- break;
- case NODE_ATTR_LANGUAGE:
- if (cur_language == NULL) {
- cur_language = vconf_get_str(VCONFKEY_LANGSET);
- if (cur_language == NULL)
- *invalid = true;
- }
- if (cur_language && strncmp(cur_language, val, strlen(val)))
- *invalid = true;
- break;
- }
-}
-
-static void __bundle_iterator_get_best_node(const char *key, const char *val,
- void *data)
-{
- unsigned int node_attr;
- unsigned int *weight = (unsigned int *)data;
-
- node_attr = (uintptr_t)g_hash_table_lookup(attr_key, key);
- if (node_attr <= NODE_ATTR_MIN || node_attr >= NODE_ATTR_MAX) {
- LOGE("INVALID_PARAMETER(0x%08x), node_attr(%d)",
- AUL_RESOURCE_ERROR_INVALID_PARAMETER, node_attr);
- return;
- }
-
- switch (node_attr) {
- case NODE_ATTR_SCREEN_DPI:
- *weight += WEIGHT_SCREEN_DPI;
- break;
- case NODE_ATTR_SCREEN_DPI_RANGE:
- *weight += WEIGHT_SCREEN_DPI_RANGE;
- break;
- case NODE_ATTR_SCREEN_WIDTH_RANGE:
- *weight += WEIGHT_SCREEN_WIDTH_RANGE;
- break;
- case NODE_ATTR_SCREEN_LARGE:
- *weight += WEIGHT_SCREEN_LARGE;
- break;
- case NODE_ATTR_SCREEN_BPP:
- *weight += WEIGHT_SCREEN_BPP;
- break;
- case NODE_ATTR_PLATFORM_VER:
- *weight += WEIGHT_PLATFORM_VERSION;
- break;
- case NODE_ATTR_LANGUAGE:
- *weight += WEIGHT_LANGUAGE;
- break;
- }
-}
-
-static const char *__get_cache(aul_resource_e type,
- const char *id)
-{
- unsigned int total_len = 0;
- char *key = NULL;
- char *rsc_type;
- resource_cache_context_t *resource_cache = NULL;
-
- if (is_slice == TRUE)
- return NULL;
-
- if (id == NULL) {
- LOGW("(0x%08x), id",
- AUL_RESOURCE_ERROR_INVALID_PARAMETER);
- return NULL;
- }
-
- if (type < AUL_RESOURCE_TYPE_MIN || type > AUL_RESOURCE_TYPE_MAX) {
- LOGW("(0x%08x), type(%d)",
- AUL_RESOURCE_ERROR_INVALID_PARAMETER, type);
- return NULL;
- } else {
- switch (type) {
- case AUL_RESOURCE_TYPE_IMAGE:
- rsc_type = RSC_GROUP_TYPE_IMAGE;
- break;
- case AUL_RESOURCE_TYPE_LAYOUT:
- rsc_type = RSC_GROUP_TYPE_LAYOUT;
- break;
- case AUL_RESOURCE_TYPE_SOUND:
- rsc_type = RSC_GROUP_TYPE_SOUND;
- break;
- case AUL_RESOURCE_TYPE_BIN:
- rsc_type = RSC_GROUP_TYPE_BIN;
- break;
- }
- }
-
- if (resource_handle->cache == NULL) {
- LOGW("(0x%08x), hashtable",
- AUL_RESOURCE_ERROR_INVALID_PARAMETER);
- return NULL;
- } else {
- total_len = (unsigned int)(strlen(rsc_type) + strlen(id) + 2);
- key = (char *)calloc(1, total_len);
- if (key == NULL) {
- LOGE("OOM!, failed to create a resource_cache(0x%08x)",
- AUL_RESOURCE_ERROR_OUT_OF_MEMORY);
- free(resource_cache);
- return NULL;
- }
-
- snprintf(key, total_len, "%s:%s", rsc_type, id);
- LOGD("key : %s", key);
-
- resource_cache = g_hash_table_lookup(resource_handle->cache, key);
- free(key);
- if (resource_cache == NULL) {
- LOGW("(0x%08x), find list resource_cache",
- AUL_RESOURCE_ERROR_IO_ERROR);
- return NULL;
- }
-
- resource_cache->hit_cnt++;
- }
-
- return resource_cache->output;
-}
-
-static gint __cache_hit_compare(gconstpointer a, gconstpointer b)
-{
- const resource_cache_context_t *lhs = (const resource_cache_context_t *) a;
- const resource_cache_context_t *rhs = (const resource_cache_context_t *) b;
-
- return lhs->hit_cnt - rhs->hit_cnt;
-}
-
-static gboolean __cache_remove(gpointer key, gpointer value, gpointer user_data)
-{
- resource_cache_context_t *c = (resource_cache_context_t *) (value);
-
- if (c->remove) {
- free(key);
- free(c->output);
- free(c);
- return TRUE;
- }
-
- return FALSE;
-}
-
-static void __trim_cache(void)
-{
- GList *values = g_hash_table_get_values(resource_handle->cache);
- values = g_list_sort(values, __cache_hit_compare);
-
- int i = 0;
- GList *iter_list = values;
- while (iter_list != NULL) {
- if (i >= (THRESHOLD_TO_CLEAN / 2))
- break;
-
- resource_cache_context_t *c =
- (resource_cache_context_t *) (iter_list->data);
- c->remove = true;
- iter_list = g_list_next(iter_list);
- i++;
- }
-
- g_list_free(values);
- g_hash_table_foreach_remove(resource_handle->cache, __cache_remove, NULL);
-
-}
-
-static void __put_cache(aul_resource_e type, const char *id,
- const char *val)
-{
- unsigned int total_len = 0;
- char *key;
- char *rsc_type;
- resource_cache_context_t *resource_cache;
-
- if (is_slice == TRUE)
- return;
-
- /* To remove chache from the low frequency of use. */
- if (val == NULL) {
- LOGE("INVALID_PARAMETER(0x%08x), fname",
- AUL_RESOURCE_ERROR_INVALID_PARAMETER);
- return;
- }
-
- if (id == NULL) {
- LOGE("INVALID_PARAMETER(0x%08x), id",
- AUL_RESOURCE_ERROR_INVALID_PARAMETER);
- return;
- }
-
- if (type < AUL_RESOURCE_TYPE_MIN || type > AUL_RESOURCE_TYPE_MAX) {
- LOGE("INVALID_PARAMETER(0x%08x), type(%d)",
- AUL_RESOURCE_ERROR_INVALID_PARAMETER, type);
- return;
- } else {
- switch (type) {
- case AUL_RESOURCE_TYPE_IMAGE:
- rsc_type = RSC_GROUP_TYPE_IMAGE;
- break;
- case AUL_RESOURCE_TYPE_LAYOUT:
- rsc_type = RSC_GROUP_TYPE_LAYOUT;
- break;
- case AUL_RESOURCE_TYPE_SOUND:
- rsc_type = RSC_GROUP_TYPE_SOUND;
- break;
- case AUL_RESOURCE_TYPE_BIN:
- rsc_type = RSC_GROUP_TYPE_BIN;
- break;
- }
- }
-
- if (g_hash_table_size(resource_handle->cache) > THRESHOLD_TO_CLEAN)
- __trim_cache();
-
- resource_cache = (resource_cache_context_t *)calloc(1,
- sizeof(resource_cache_context_t));
- if (resource_cache == NULL) {
- LOGE("failed to create a resource_group(0x%08x)",
- AUL_RESOURCE_ERROR_OUT_OF_MEMORY);
- return;
- }
-
- total_len = (unsigned int)(strlen(rsc_type) + strlen(id) + 2);
- key = (char *)calloc(1, total_len);
- if (key == NULL) {
- LOGE("failed to create a resource_cache(0x%08x)",
- AUL_RESOURCE_ERROR_OUT_OF_MEMORY);
- free(resource_cache);
- return;
- }
-
- snprintf(key, total_len, "%s:%s", rsc_type, id);
- LOGD("key : %s", key);
-
- resource_cache->output = strdup(val);
- resource_cache->hit_cnt = 0;
- resource_cache->remove = false;
-
- g_hash_table_insert(resource_handle->cache, key, resource_cache);
-}
-
-static resource_group_t *__find_group(resource_data_t *data,
- int type)
-{
- resource_group_t *rsc_group = NULL;
- char *rsc_type;
-
- if (data == NULL) {
- LOGE("INVALID_PARAMETER(0x%08x), resource_data_t",
- AUL_RESOURCE_ERROR_INVALID_PARAMETER);
- return NULL;
- }
-
- if (type < AUL_RESOURCE_TYPE_MIN || type > AUL_RESOURCE_TYPE_MAX) {
- LOGE("INVALID_PARAMETER(0x%08x), type(%d)",
- AUL_RESOURCE_ERROR_INVALID_PARAMETER, type);
- return NULL;
- } else {
- switch (type) {
- case AUL_RESOURCE_TYPE_IMAGE:
- rsc_type = RSC_GROUP_TYPE_IMAGE;
- break;
- case AUL_RESOURCE_TYPE_LAYOUT:
- rsc_type = RSC_GROUP_TYPE_LAYOUT;
- break;
- case AUL_RESOURCE_TYPE_SOUND:
- rsc_type = RSC_GROUP_TYPE_SOUND;
- break;
- case AUL_RESOURCE_TYPE_BIN:
- rsc_type = RSC_GROUP_TYPE_BIN;
- break;
- }
- }
-
- GList* found = g_list_find_custom(data->group_list, rsc_type,
- __resource_manager_comp);
- if (found == NULL) {
- LOGE("IO_ERROR(0x%08x), find list resource_group %s",
- AUL_RESOURCE_ERROR_IO_ERROR, rsc_type);
- return NULL;
- }
-
- rsc_group = (resource_group_t *) (found->data);
-
- return rsc_group;
-}
-
-static GList *__get_valid_nodes(resource_group_t *group,
- const char *id)
-{
- GList *list = NULL;
- GList *valid_list = NULL;
- resource_node_t *valid_node = NULL;
- resource_node_t *rsc_node = NULL;
-
- if (group->node_list == NULL) {
- LOGE("INVALID_PARAMETER(0x%08x), resource_group",
- AUL_RESOURCE_ERROR_INVALID_PARAMETER);
- return NULL;
- }
-
- list = g_list_first(group->node_list);
-
- char path_buf[MAX_PATH] = { 0, };
- while (list) {
- bool invalid = false;
- rsc_node = (resource_node_t *) list->data;
-
- snprintf(path_buf, MAX_PATH - 1, "%s%s/%s", res_path,
- rsc_node->folder, id);
- if (access(path_buf, R_OK) == 0) {
- bundle_foreach(rsc_node->attr, __bundle_iterator_get_valid_nodes,
- &invalid);
-
- if (!invalid) {
- valid_node = (resource_node_t *) list->data;
- valid_list = g_list_append(valid_list, valid_node);
- }
- }
-
- list = g_list_next(list);
- }
-
- return valid_list;
-}
-
-static resource_node_t *__get_best_node(GList *nodes)
-{
- unsigned int weight_tmp = 0;
- resource_node_t *best_node = NULL;
- GList *list = NULL;
-
- if (nodes == NULL) {
- LOGE("INVALID_PARAMETER(0x%08x), resource_node lists",
- AUL_RESOURCE_ERROR_INVALID_PARAMETER);
- return NULL;
- }
-
- list = g_list_first(nodes);
-
- while (list != NULL) {
- unsigned int weight = 0;
- resource_node_t *res_node = (resource_node_t *) (list->data);
-
- bundle_iterate(res_node->attr, __bundle_iterator_get_best_node, &weight);
- if (weight > weight_tmp) {
- best_node = res_node;
- weight_tmp = weight;
- }
- list = g_list_next(list);
- }
-
- return best_node;
-}
-
-static int __open(resource_manager_t **handle)
-{
- int retval = AUL_RESOURCE_ERROR_NONE;
- resource_manager_t *rsc_manager = NULL;
- char buf[MAX_PATH] = { 0, };
-
- rsc_manager = (resource_manager_t *) calloc(1, sizeof(resource_manager_t));
- if (!rsc_manager) {
- LOGE("failed to create a resource_manager(0x%08x)",
- AUL_RESOURCE_ERROR_OUT_OF_MEMORY);
- return AUL_RESOURCE_ERROR_OUT_OF_MEMORY;
- }
-
- snprintf(buf, MAX_PATH - 1, "%sres.xml", res_path);
- retval = _resource_open(buf, &(rsc_manager->data));
- if (retval) {
- LOGE("IO_ERROR(0x%08x), failed to get db for resource manager",
- AUL_RESOURCE_ERROR_IO_ERROR);
- free(rsc_manager);
- return AUL_RESOURCE_ERROR_IO_ERROR;
- }
-
- rsc_manager->cache = g_hash_table_new(g_str_hash, g_str_equal);
- *handle = rsc_manager;
-
- return AUL_RESOURCE_ERROR_NONE;
-}
-
-static void __invalidate_cache()
-{
- if (resource_handle != NULL) {
- if (resource_handle->cache != NULL) {
- GHashTableIter iter;
- gpointer key, value;
-
- g_hash_table_iter_init(&iter, resource_handle->cache);
- while (g_hash_table_iter_next(&iter, &key, &value)) {
- free(key);
- resource_cache_context_t *c = (resource_cache_context_t *) value;
- free(c->output);
- free(value);
- }
- g_hash_table_remove_all(resource_handle->cache);
- if (cur_language) {
- free(cur_language);
- cur_language = NULL;
- }
- }
- }
-}
-
-static int __close(resource_manager_t *handle)
-{
- if (handle == NULL) {
- LOGE("INVALID_PARAMETER(0x%08x), resource_manager",
- AUL_RESOURCE_ERROR_INVALID_PARAMETER);
- return AUL_RESOURCE_ERROR_INVALID_PARAMETER;
- }
-
- __invalidate_cache();
- if (handle->cache != NULL)
- g_hash_table_destroy(handle->cache);
-
- if (handle->data != NULL)
- _resource_close(handle->data);
-
- free(handle);
-
- return AUL_RESOURCE_ERROR_NONE;
-}
-
-static void __vconf_cb(keynode_t *key, void *data)
-{
- char *val;
-
- val = vconf_keynode_get_str(key);
- if (val && cur_language && !strcmp(val, cur_language))
- return;
-
- __invalidate_cache();
-}
-
-static const char *_get_app_resource_path(const char *rsc_folder_path)
-{
- if (is_slice == FALSE)
- return aul_get_app_resource_path();
-
- if (rsc_folder_path == NULL)
- return NULL;
-
- return rsc_folder_path;
-}
-
-static void path_callback(char *path)
-{
- char orig_path[PATH_MAX] = {0, };
- char *path_ptr = NULL;
- int path_len = 0;
- GList *tmp_list = g_list_find_custom(all_node_list, path, __compare_path);
-
- resource_node_list_t *tmp_node_info = NULL;
- if (tmp_list == NULL)
- g_hash_table_add(valid_path_list, strdup(path));
- else {
- tmp_node_info = (resource_node_list_t *)tmp_list->data;
- path_len = strlen(path);
- if (path_len >= PATH_MAX) {
- LOGE("path[%s] is too long", path);
- return;
- }
- strncpy(orig_path, path, sizeof(orig_path) - path_len - 1);
- path_ptr = &orig_path[strlen(res_path) + strlen(tmp_node_info->folder)];
- g_hash_table_insert(id_list, strdup(path_ptr), strdup(tmp_node_info->type));
- }
-}
-
-static void __scan_dir(const char *path, void (*func)(char *))
-{
- struct dirent **items;
- int nitems, i;
- struct stat fstat;
- char abs_path[PATH_MAX] = {0, };
- char cwd[MAX_PATH] = {0, };
- char *tmp = NULL;
-
- if (chdir(path) < 0) {
- LOGE("failed to chdir[%s]", path);
- return;
- }
-
- tmp = getcwd(cwd, MAX_PATH - 1);
- if (tmp == NULL) {
- LOGE("failed to get cwd");
- return;
- }
- nitems = scandir("./", &items, NULL, alphasort);
-
- for (i = 0; i < nitems; i++) {
- if (items[i]->d_name[0] == '.')
- continue;
-
- snprintf(abs_path, sizeof(abs_path), "%s/%s", cwd, items[i]->d_name);
-
- if (g_lstat(abs_path, &fstat) != 0) {
- LOGE("failed to retrieve info[%s]", abs_path);
- return;
- }
- if ((fstat.st_mode & S_IFDIR) == S_IFDIR)
- __scan_dir(abs_path, path_callback);
- else
- func(abs_path);
- }
-
-}
-
-static aul_resource_e __get_resource_type(char *type)
-{
- if (type == NULL)
- return -1;
-
- if (strcmp(type, RSC_GROUP_TYPE_IMAGE) == 0)
- return AUL_RESOURCE_TYPE_IMAGE;
- else if (strcmp(type, RSC_GROUP_TYPE_LAYOUT) == 0)
- return AUL_RESOURCE_TYPE_LAYOUT;
- else if (strcmp(type, RSC_GROUP_TYPE_SOUND) == 0)
- return AUL_RESOURCE_TYPE_SOUND;
- else if (strcmp(type, RSC_GROUP_TYPE_BIN) == 0)
- return AUL_RESOURCE_TYPE_BIN;
- else
- return -1;
-}
-
-static int __set_valid_filelist(bundle *b)
-{
- if (b == NULL || supported_lang_list == NULL) {
- LOGE("INVALID_PARAMETER(0x%08x), bundle",
- AUL_RESOURCE_ERROR_INVALID_PARAMETER);
- return AUL_RESOURCE_ERROR_INVALID_PARAMETER;
- }
-
- int retval = AUL_RESOURCE_ERROR_NONE;
- char *path = NULL;
- GHashTableIter id_list_iter;
- GHashTableIter lang_list_iter;
- gpointer id_key, lang_key, id_type;
- aul_resource_e rsc_type = AUL_RESOURCE_TYPE_MIN;
-
- given_attr_list = b;
- g_hash_table_iter_init(&id_list_iter, id_list);
-
- while (g_hash_table_iter_next(&id_list_iter, &id_key, &id_type)) {
- rsc_type = __get_resource_type((char *)id_type);
- if (rsc_type == -1) {
- LOGE("failed to get resource type[%s]", (char *)id_type);
- return AUL_RESOURCE_ERROR_IO_ERROR;
- }
-
- g_hash_table_iter_init(&lang_list_iter, supported_lang_list);
- while (g_hash_table_iter_next(&lang_list_iter, &lang_key, NULL)) {
- cur_language = strdup(lang_key);
- if (cur_language == NULL) {
- LOGE("failed to strdup");
- return AUL_RESOURCE_ERROR_OUT_OF_MEMORY;
- }
-
- retval = aul_resource_manager_get(rsc_type, id_key, &path);
- if (retval == AUL_RESOURCE_ERROR_NONE)
- g_hash_table_add(valid_path_list, path);
- else
- LOGE("failed to get value with given type[%d], key[%s]", rsc_type, (const char *)id_key);
-
- if (cur_language) {
- free(cur_language);
- cur_language = NULL;
- }
- }
- }
- return AUL_RESOURCE_ERROR_NONE;
-}
-
-static int __make_list(void)
-{
- resource_group_t *tmp_group = NULL;
- resource_node_t *tmp_node = NULL;
- resource_node_list_t *tmp_node_struct = NULL;
- char *group_type = NULL;
- char folder[MAX_PATH] = {0 ,};
- char *node_lang = NULL;
- GList *group_list = NULL;
- GList *node_list = NULL;
- bundle *b = NULL;
-
-
- /* make node folder list */
- group_list = resource_handle->data->group_list;
- if (group_list == NULL)
- return AUL_RESOURCE_ERROR_IO_ERROR;
-
- while (group_list != NULL) {
- tmp_group = (resource_group_t *)group_list->data;
- if (tmp_group == NULL)
- return AUL_RESOURCE_ERROR_IO_ERROR;
-
- group_type = tmp_group->type;
- node_list = tmp_group->node_list;
- memset(folder, '\0', MAX_PATH);
- snprintf(folder, MAX_PATH - 1, "%s/", tmp_group->folder);
-
- /* make struct and put it into all node list */
- tmp_node_struct = (resource_node_list_t *)calloc(1, sizeof(resource_node_list_t));
- if (tmp_node_struct == NULL) {
- LOGE("calloc failed");
- return AUL_RESOURCE_ERROR_OUT_OF_MEMORY;
- }
-
- tmp_node_struct->folder = strdup(folder);
- tmp_node_struct->type = strdup(group_type);
- all_node_list = g_list_append(all_node_list, tmp_node_struct);
-
- while (node_list != NULL) {
- tmp_node = (resource_node_t *)node_list->data;
- if (tmp_node == NULL)
- return AUL_RESOURCE_ERROR_IO_ERROR;
-
- /* retrieve language value from each node */
- b = tmp_node->attr;
- if (b == NULL)
- return AUL_RESOURCE_ERROR_IO_ERROR;
- bundle_get_str(b, RSC_NODE_ATTR_LANGUAGE, &node_lang);
- if (node_lang != NULL)
- g_hash_table_add(supported_lang_list, strdup(node_lang));
-
- memset(folder, '\0', MAX_PATH);
- snprintf(folder, MAX_PATH - 1, "%s/", tmp_node->folder);
-
- /* make struct and put it into all node list */
- tmp_node_struct = (resource_node_list_t *)calloc(1, sizeof(resource_node_list_t));
- if (tmp_node_struct == NULL) {
- LOGE("calloc failed");
- return AUL_RESOURCE_ERROR_OUT_OF_MEMORY;
- }
-
- tmp_node_struct->folder = strdup(folder);
- tmp_node_struct->type = strdup(group_type);
- all_node_list = g_list_prepend(all_node_list, tmp_node_struct);
-
- node_list = g_list_next(node_list);
- }
- group_list = g_list_next(group_list);
- }
-
- __scan_dir(res_path, path_callback);
-
- /* add language which is not existed to find default resources */
- g_hash_table_add(supported_lang_list, strdup("NoLang"));
- return AUL_RESOURCE_ERROR_NONE;
-}
-
-static void __free_str(gpointer data)
-{
- if (data == NULL)
- return;
-
- char *char_data = (char *)data;
- free(char_data);
- data = NULL;
-}
-
-static int __init(const char *rsc_folder_path, bundle *b)
-{
- if (rsc_folder_path != NULL && b != NULL)
- is_slice = TRUE;
- else
- is_slice = FALSE;
-
- if (resource_handle != NULL)
- return AUL_RESOURCE_ERROR_NONE;
-
- int retval = AUL_RESOURCE_ERROR_NONE;
-
- res_path = _get_app_resource_path(rsc_folder_path);
- if (res_path == NULL) {
- LOGE("IO_ERROR(0x%08x), failed to get resource path",
- AUL_RESOURCE_ERROR_IO_ERROR);
- return AUL_RESOURCE_ERROR_IO_ERROR;
- }
-
- retval = __open(&resource_handle);
- if (retval != AUL_RESOURCE_ERROR_NONE) {
- LOGE("IO_ERROR(0x%08x), failed to get resource_handle(%d)",
- AUL_RESOURCE_ERROR_IO_ERROR, retval);
- return AUL_RESOURCE_ERROR_IO_ERROR;
- }
-
- if (attr_key == NULL) {
- attr_key = g_hash_table_new(g_str_hash, g_str_equal);
-
- if (attr_key == NULL)
- return AUL_RESOURCE_ERROR_OUT_OF_MEMORY;
-
- unsigned int i;
- for (i = 0; i < ARRAY_SIZE(map); i++) {
- g_hash_table_insert(attr_key, (char *)map[i].bundle_attr_key,
- (gpointer)((uintptr_t)(map[i].bundle_attr_value)));
- }
- }
-
- if (is_slice == FALSE) {
- int r = vconf_notify_key_changed(VCONFKEY_LANGSET, __vconf_cb, NULL);
-
- if (r < 0) {
- LOGE("IO_ERROR(0x%08x), failed to register vconf(%d)",
- AUL_RESOURCE_ERROR_IO_ERROR, r);
- return AUL_RESOURCE_ERROR_IO_ERROR;
- }
- } else {
- /* make ID list */
- if (id_list == NULL)
- id_list = g_hash_table_new_full(g_str_hash, g_str_equal, __free_str, __free_str);
-
- if (supported_lang_list == NULL)
- supported_lang_list = g_hash_table_new_full(g_str_hash, g_str_equal, __free_str, NULL);
-
- if (valid_path_list == NULL)
- valid_path_list = g_hash_table_new_full(g_str_hash, g_str_equal, __free_str, NULL);
-
- retval = __make_list();
- if (retval < 0) {
- LOGE("Failed to initialize filelist");
- return AUL_RESOURCE_ERROR_IO_ERROR;
- }
-
- retval = __set_valid_filelist(b);
- if (retval < 0) {
- LOGE("Failed to get valid filelist");
- return AUL_RESOURCE_ERROR_IO_ERROR;
- }
-
- }
-
- return AUL_RESOURCE_ERROR_NONE;
-}
-
-API int aul_resource_manager_init(void)
-{
- return __init(NULL, NULL);
-}
-
-API int aul_resource_manager_init_slice(const char *rsc_folder_path, bundle *b)
-{
- if (rsc_folder_path == NULL || b == NULL)
- return AUL_RESOURCE_ERROR_INVALID_PARAMETER;
-
- return __init(rsc_folder_path, b);
-}
-
-
-API int aul_resource_manager_get_path_list(GHashTable **list)
-{
- if (is_slice == FALSE)
- return AUL_RESOURCE_ERROR_IO_ERROR;
-
- if (valid_path_list != NULL)
- *list = valid_path_list;
- else
- return AUL_RESOURCE_ERROR_IO_ERROR;
-
- return AUL_RESOURCE_ERROR_NONE;
-}
-
-static bool __verify_current_language(void)
-{
- char *lang;
-
- lang = vconf_get_str(VCONFKEY_LANGSET);
- if (!lang)
- return false;
-
- if (cur_language && !strcmp(lang, cur_language)) {
- free(lang);
- return true;
- }
-
- free(lang);
-
- return false;
-}
-
-API int aul_resource_manager_get(aul_resource_e type, const char *id, char **path)
-{
- int retval = AUL_RESOURCE_ERROR_NONE;
- char *put_fname = NULL;
- const char *cached_path = NULL;
- GList *list = NULL;
- resource_group_t *resource_group = NULL;
- resource_node_t *resource_node = NULL;
-
- *path = NULL;
-
- if (id == NULL) {
- LOGE("INVALID_PARAMETER(0x%08x), resource_data_t",
- AUL_RESOURCE_ERROR_INVALID_PARAMETER);
- return AUL_RESOURCE_ERROR_INVALID_PARAMETER;
- }
-
- if (type < AUL_RESOURCE_TYPE_MIN || type > AUL_RESOURCE_TYPE_MAX) {
- LOGE("INVALID_PARAMETER(0x%08x), type(%d)",
- AUL_RESOURCE_ERROR_INVALID_PARAMETER, type);
- return AUL_RESOURCE_ERROR_INVALID_PARAMETER;
- }
-
- if (is_slice == FALSE) {
- if (resource_handle == NULL) {
- retval = aul_resource_manager_init();
- if (retval != AUL_RESOURCE_ERROR_NONE)
- return retval;
- }
-
- if (__verify_current_language()) {
- /* To get fname from cache */
- cached_path = __get_cache(type, id);
- if (cached_path != NULL) {
- *path = strdup(cached_path);
- return AUL_RESOURCE_ERROR_NONE;
- }
- } else {
- __invalidate_cache();
- }
- }
-
- if (resource_handle == NULL)
- return AUL_RESOURCE_ERROR_IO_ERROR;
-
- resource_group = __find_group(resource_handle->data, type);
- if (resource_group == NULL) {
- LOGE("IO_ERROR(0x%08x), failed to get resource_group",
- AUL_RESOURCE_ERROR_IO_ERROR);
- retval = AUL_RESOURCE_ERROR_IO_ERROR;
- goto Exception;
- }
-
- list = __get_valid_nodes(resource_group, id);
- if (list == NULL) {
- retval = AUL_RESOURCE_ERROR_IO_ERROR;
- goto Exception;
- }
-
- resource_node = __get_best_node(list);
- if (resource_node == NULL) {
- retval = AUL_RESOURCE_ERROR_IO_ERROR;
- goto Exception;
- } else {
- unsigned int total_len = (unsigned int)(strlen(res_path)
- + strlen(resource_node->folder)
- + strlen(id) + 3);
- put_fname = (char *) calloc(1, total_len);
- if (!put_fname) {
- if (list != NULL)
- g_list_free(list);
- return AUL_RESOURCE_ERROR_OUT_OF_MEMORY;
- }
- snprintf(put_fname, total_len, "%s%s/%s", res_path,
- resource_node->folder, id);
- *path = strdup(put_fname);
- }
-
- __put_cache(type, id, put_fname);
-
-
-Exception:
- if (list != NULL)
- g_list_free(list);
-
- if (put_fname == NULL && resource_group != NULL) {
- char path_buf[MAX_PATH] = { 0, };
- char group_path_buf[MAX_PATH] = { 0, };
-
- snprintf(path_buf, MAX_PATH - 1, "%s%s/%s", res_path,
- resource_group->folder, id);
- snprintf(group_path_buf, MAX_PATH - 1, "%s/%s", resource_group->folder, id);
-
- list = g_list_first(resource_group->node_list);
- while (list) {
- resource_node = (resource_node_t *) list->data;
- if (strncmp(group_path_buf, resource_node->folder, strlen(resource_node->folder)) == 0) {
- *path = NULL;
- return AUL_RESOURCE_ERROR_IO_ERROR;
- }
- list = g_list_next(list);
- }
-
- if (access(path_buf, R_OK) == 0) {
- __put_cache(type, id, path_buf);
- *path = strdup(path_buf);
- retval = AUL_RESOURCE_ERROR_NONE;
- }
- }
-
- if (put_fname != NULL)
- free(put_fname);
-
- return retval;
-}
-
-static void __free_node_folder_list(gpointer data)
-{
- resource_node_list_t *node_data = (resource_node_list_t *)data;
- if (node_data == NULL)
- return;
-
- if (node_data->folder != NULL) {
- free(node_data->folder);
- node_data->folder = NULL;
- }
-
- if (node_data->type != NULL) {
- free(node_data->type);
- node_data->type = NULL;
- }
-
- free(node_data);
-}
-
-API int aul_resource_manager_release(void)
-{
- if (resource_handle != NULL) {
- __close(resource_handle);
- resource_handle = NULL;
- }
-
- if (attr_key != NULL) {
- g_hash_table_destroy(attr_key);
- attr_key = NULL;
- }
-
- if (cur_language) {
- free(cur_language);
- cur_language = NULL;
- }
-
- if (is_slice == FALSE)
- vconf_ignore_key_changed(VCONFKEY_LANGSET, __vconf_cb);
- else {
- if (valid_path_list != NULL) {
- g_hash_table_destroy(valid_path_list);
- valid_path_list = NULL;
- }
-
- if (supported_lang_list != NULL) {
- g_hash_table_destroy(supported_lang_list);
- supported_lang_list = NULL;
- }
-
- if (id_list != NULL) {
- g_hash_table_destroy(id_list);
- id_list = NULL;
- }
-
- if (all_node_list != NULL) {
- g_list_free_full(all_node_list, __free_node_folder_list);
- all_node_list = NULL;
- }
- }
- return AUL_RESOURCE_ERROR_NONE;
-}
+++ /dev/null
-/*
- * Copyright (c) 2016 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 <stdlib.h>
-#include <string.h>
-
-#include <glib.h>
-#include <libxml/tree.h>
-#include <libxml/xmlschemas.h>
-
-#include <dlog.h>
-#include <bundle.h>
-
-#include "aul_rsc_mgr_internal.h"
-#include "aul_rsc_mgr_schema.h"
-
-static char *__get_attribute(xmlNode *xml_node, const char *name)
-{
- xmlChar *val;
- char *attr = NULL;
-
- val = xmlGetProp(xml_node, (const xmlChar *)name);
- if (val) {
- attr = strdup((const char *)val);
- xmlFree(val);
- }
-
- return attr;
-}
-
-static void __get_attribute_into_bundle(xmlNode *xml_node, const char *name,
- bundle *b)
-{
- char *attr;
-
- attr = __get_attribute(xml_node, name);
- if (attr) {
- bundle_add_str(b, name, attr);
- free(attr);
- }
-}
-
-static int __parse_node(xmlNode *xml_node, GList **nodes)
-{
- resource_node_t *node;
-
- if (strcmp((char *)xml_node->name, "node"))
- return -1;
-
- node = calloc(1, sizeof(resource_node_t));
- if (!node) {
- LOGE("Out of memory");
- return -1;
- }
-
- node->folder = __get_attribute(xml_node, "folder");
- /* why we should use bundle here? */
- node->attr = bundle_create();
- if (node->attr == NULL) {
- LOGE("Out of memory");
- free(node->folder);
- free(node);
- return -1;
- }
-
- __get_attribute_into_bundle(xml_node, RSC_NODE_ATTR_SCREEN_DPI,
- node->attr);
- __get_attribute_into_bundle(xml_node, RSC_NODE_ATTR_SCREEN_DPI_RANGE,
- node->attr);
- __get_attribute_into_bundle(xml_node, RSC_NODE_ATTR_SCREEN_WIDTH_RANGE,
- node->attr);
- __get_attribute_into_bundle(xml_node, RSC_NODE_ATTR_SCREEN_LARGE,
- node->attr);
- __get_attribute_into_bundle(xml_node, RSC_NODE_ATTR_SCREEN_BPP,
- node->attr);
- __get_attribute_into_bundle(xml_node, RSC_NODE_ATTR_PLATFORM_VER,
- node->attr);
- __get_attribute_into_bundle(xml_node, RSC_NODE_ATTR_LANGUAGE,
- node->attr);
-
- *nodes = g_list_append(*nodes, node);
-
- return 0;
-}
-
-static char *_get_group_type(xmlNode *xml_node)
-{
- static const char delim[] = "-";
- char *str;
- char *tok;
- char *ptr;
-
- /* copy original string */
- str = strdup((const char *)xml_node->name);
- if (str == NULL) {
- LOGE("Out of memory");
- return NULL;
- }
-
- tok = strtok_r(str, delim, &ptr);
- /* not a group element */
- if (tok == NULL || strcmp(tok, "group")) {
- free(str);
- return NULL;
- }
-
- tok = strtok_r(NULL, delim, &ptr);
- /* invalid element */
- if (tok == NULL) {
- free(str);
- return NULL;
- }
-
- ptr = strdup(tok);
- free(str);
-
- return ptr;
-}
-
-static int __parse_group(xmlNode *xml_node, GList **groups)
-{
- xmlNode *tmp;
- char *type;
- resource_group_t *group;
-
- type = _get_group_type(xml_node);
- if (type == NULL)
- return -1;
-
- group = calloc(1, sizeof(resource_group_t));
- if (group == NULL) {
- LOGE("Out of memory");
- free(type);
- return -1;
- }
-
- group->type = type;
- group->folder = __get_attribute(xml_node, "folder");
-
- for (tmp = xml_node->children; tmp; tmp = tmp->next) {
- if (xml_node->type != XML_ELEMENT_NODE)
- continue;
- if (__parse_node(tmp, &group->node_list))
- continue;
- }
-
- *groups = g_list_append(*groups, group);
-
- return 0;
-}
-
-static int __parse_resource(xmlNode *xml_node, resource_data_t **data)
-{
- xmlNode *tmp;
-
- *data = calloc(1, sizeof(resource_data_t));
- if (*data == NULL) {
- LOGE("out of memory");
- return -1;
- }
-
- for (tmp = xml_node->children; tmp; tmp = tmp->next) {
- if (tmp->type != XML_ELEMENT_NODE)
- continue;
- __parse_group(tmp, &(*data)->group_list);
- }
-
- return 0;
-}
-
-static int __validate_schema(const char *path)
-{
- xmlSchemaParserCtxt *parser_ctxt;
- xmlSchema *schema;
- xmlSchemaValidCtxt *valid_ctxt;
- int ret;
-
- parser_ctxt = xmlSchemaNewMemParserCtxt(res_schema, sizeof(res_schema));
- if (parser_ctxt == NULL) {
- LOGE("failed to create parser context");
- return -1;
- }
-
- schema = xmlSchemaParse(parser_ctxt);
- if (schema == NULL) {
- LOGE("failed to create schema");
- xmlSchemaFreeParserCtxt(parser_ctxt);
- return -1;
- }
-
- valid_ctxt = xmlSchemaNewValidCtxt(schema);
- if (valid_ctxt == NULL) {
- LOGE("failed to create valid context");
- xmlSchemaFree(schema);
- xmlSchemaFreeParserCtxt(parser_ctxt);
- return -1;
- }
-
- ret = xmlSchemaValidateFile(valid_ctxt, path, 0);
- if (ret)
- LOGE("%s: validation failed(%d)", path, ret);
-
- xmlSchemaFreeValidCtxt(valid_ctxt);
- xmlSchemaFree(schema);
- xmlSchemaFreeParserCtxt(parser_ctxt);
-
- return ret;
-}
-
-int _resource_open(const char *path, resource_data_t **data)
-{
- int ret;
- xmlDoc *doc;
- xmlNode *root;
-
- if (__validate_schema(path))
- return -1;
- doc = xmlReadFile(path, NULL, 0);
- if (doc == NULL)
- return -1;
- root = xmlDocGetRootElement(doc);
- if (!root) {
- xmlFreeDoc(doc);
- return -1;
- }
-
- ret = __parse_resource(root, data);
-
- xmlFreeDoc(doc);
-
- return ret;
-}
-
-static void __free_resource_node(gpointer data)
-{
- resource_node_t *node = (resource_node_t *)data;
-
- free(node->folder);
- bundle_free(node->attr);
- free(node);
-}
-
-static void __free_resource_group(gpointer data)
-{
- resource_group_t *group = (resource_group_t *)data;
-
- free(group->folder);
- free(group->type);
-
- g_list_free_full(group->node_list, __free_resource_node);
-
- free(group);
-}
-
-int _resource_close(resource_data_t *data)
-{
- /*
- free(data->package);
- */
- g_list_free_full(data->group_list, __free_resource_group);
-
- free(data);
-
- return 0;
-}
+++ /dev/null
-/*
- * Copyright (c) 2016 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_RSC_MGR_INTERNAL_H__
-#define __AUL_RSC_MGR_INTERNAL_H__
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-
-#define LOG_TAG "AUL_RESOURCE_MANAGER"
-
-#define RSC_GROUP_TYPE_IMAGE "image"
-#define RSC_GROUP_TYPE_LAYOUT "layout"
-#define RSC_GROUP_TYPE_SOUND "sound"
-#define RSC_GROUP_TYPE_BIN "bin"
-
-#define RSC_NODE_ATTR_SCREEN_DPI "screen-dpi"
-#define RSC_NODE_ATTR_SCREEN_DPI_RANGE "screen-dpi-range"
-#define RSC_NODE_ATTR_SCREEN_WIDTH_RANGE "screen-width-range"
-#define RSC_NODE_ATTR_SCREEN_LARGE "screen-large"
-#define RSC_NODE_ATTR_SCREEN_BPP "screen-bpp"
-#define RSC_NODE_ATTR_PLATFORM_VER "platform-version"
-#define RSC_NODE_ATTR_LANGUAGE "language"
-
-typedef struct {
- char *folder;
- bundle *attr;
-} resource_node_t;
-
-typedef struct {
- char *folder;
- char *type;
- GList *node_list;
-} resource_group_t;
-
-typedef struct {
- char *package;
- GList *group_list;
-} resource_data_t;
-
-int _resource_open(const char *path, resource_data_t **data);
-int _resource_close(resource_data_t *data);
-
-#endif
+++ /dev/null
-#ifndef __AUL_RSC_MGR_SCHEMA_H__
-#define __AUL_RSC_MGR_SCHEMA_H__
-
-static const char res_schema[] =
-"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
-"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" elementFormDefault=\"qualified\" targetNamespace=\"http://tizen.org/ns/rm\" xmlns:packages=\"http://tizen.org/ns/rm\">"
-" <xs:import namespace=\"http://www.w3.org/XML/1998/namespace\"/>"
-" <xs:element name=\"res\">"
-" <xs:complexType>"
-" <xs:all>"
-" <xs:element name=\"group-image\" type=\"packages:GroupContainer\" maxOccurs=\"1\" minOccurs=\"0\"/>"
-" <xs:element name=\"group-layout\" type=\"packages:GroupContainer\" maxOccurs=\"1\" minOccurs=\"0\"/>"
-" <xs:element name=\"group-sound\" type=\"packages:GroupContainer\" maxOccurs=\"1\" minOccurs=\"0\"/>"
-" <xs:element name=\"group-bin\" type=\"packages:GroupContainer\" maxOccurs=\"1\" minOccurs=\"0\"/>"
-" </xs:all>"
-" </xs:complexType>"
-" </xs:element>"
-" <xs:complexType name=\"GroupContainer\">"
-" <xs:sequence>"
-" <xs:element name=\"node\" maxOccurs=\"unbounded\" minOccurs=\"0\">"
-" <xs:complexType>"
-" <xs:attribute name=\"folder\" type=\"xs:string\" use=\"required\"/>"
-" <xs:attribute name=\"screen-dpi\" type=\"xs:integer\"/>"
-" <xs:attribute name=\"screen-dpi-range\" type=\"xs:string\"/>"
-" <xs:attribute name=\"screen-width-range\" type=\"xs:string\"/>"
-" <xs:attribute name=\"screen-large\" type=\"xs:boolean\"/>"
-" <xs:attribute name=\"screen-bpp\" type=\"xs:integer\"/>"
-" <xs:attribute name=\"platform-version\" type=\"xs:string\"/>"
-" <xs:attribute name=\"language\" type=\"xs:string\"/>"
-" </xs:complexType>"
-" </xs:element>"
-" </xs:sequence>"
-" <xs:attribute name=\"folder\" type=\"xs:string\" use=\"required\"/>"
-" </xs:complexType>"
-"</xs:schema>";
-
-#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.
- *
- */
-
-#define _GNU_SOURCE
-#include <stdio.h>
-#include <stdlib.h>
-#include <bundle_internal.h>
-#include <glib.h>
-
-#include "aul_api.h"
-#include "aul_cmd.h"
-#include "aul_error.h"
-#include "aul_running_context.h"
-#include "aul_sock.h"
-#include "aul_util.h"
-
-struct aul_running_context_s {
- char *app_id;
- char *comp_id;
- char *inst_id;
- int pid;
-};
-
-static void __destroy_running_context(gpointer data)
-{
- struct aul_running_context_s *context = data;
-
- free(context->inst_id);
- free(context->comp_id);
- free(context->app_id);
- free(context);
-}
-
-static struct aul_running_context_s *__create_running_context(bundle *b)
-{
- struct aul_running_context_s *context;
- const char *val;
-
- context = calloc(1, sizeof(struct aul_running_context_s));
- if (!context) {
- _E("Out of memory");
- return NULL;
- }
-
- val = bundle_get_val(b, AUL_K_APPID);
- if (val)
- context->app_id = strdup(val);
-
- val = bundle_get_val(b, AUL_K_COMPONENT_ID);
- if (val)
- context->comp_id = strdup(val);
-
- val = bundle_get_val(b, AUL_K_INSTANCE_ID);
- if (val)
- context->inst_id = strdup(val);
-
- val = bundle_get_val(b, AUL_K_PID);
- if (val)
- context->pid = atoi(val);
-
- return context;
-}
-
-static bundle *__create_bundle(const char *app_id,
- const char *comp_id,
- const char *inst_id)
-{
- bundle *b;
-
- b = bundle_create();
- if (!b) {
- _E("Out of memory");
- return NULL;
- }
-
- bundle_add(b, AUL_K_APPID, app_id);
-
- if (comp_id)
- bundle_add(b, AUL_K_COMPONENT_ID, comp_id);
-
- if (inst_id)
- bundle_add(b, AUL_K_INSTANCE_ID, inst_id);
-
- return b;
-}
-
-API int aul_running_context_create(const char *app_id,
- const char *comp_id,
- const char *inst_id,
- aul_running_context_h *handle)
-{
- struct aul_running_context_s *context;
- app_pkt_t *pkt = NULL;
- bundle *b;
- int ret;
- int fd;
-
- if (!app_id || !handle) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- b = __create_bundle(app_id, comp_id, inst_id);
- if (!b)
- return AUL_R_ENOMEM;
-
- fd = aul_sock_send_bundle(AUL_UTIL_PID, getuid(),
- APP_GET_RUNNING_CONTEXT,
- b, AUL_SOCK_ASYNC);
- bundle_free(b);
- if (fd <= 0) {
- _E("Failed to send the request. error(%d)", fd);
- return aul_error_convert(fd);
- }
-
- ret = aul_sock_recv_reply_pkt(fd, &pkt);
- if (ret < 0 || pkt == NULL) {
- _E("Failed to get reply. error(%d)", ret);
- return aul_error_convert(ret);
- }
-
- if (pkt->cmd != APP_GET_INFO_OK) {
- _E("Failed to get running context. error(%d)", pkt->cmd);
- ret = aul_error_convert(pkt->cmd);
- free(pkt);
- return ret;
- }
-
- if (!(pkt->opt & AUL_SOCK_BUNDLE)) {
- _E("Invalid protocol");
- free(pkt);
- return AUL_R_ERROR;
- }
-
- b = bundle_decode(pkt->data, pkt->len);
- free(pkt);
- if (!b) {
- _E("Failed to decode bundle data");
- return AUL_R_ERROR;
- }
-
- context = __create_running_context(b);
- bundle_free(b);
- if (!context) {
- _E("Failed to create running context");
- return AUL_R_ENOMEM;
- }
-
- *handle = context;
-
- return AUL_R_OK;
-}
-
-API int aul_running_context_destroy(aul_running_context_h handle)
-{
- if (!handle) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- __destroy_running_context(handle);
-
- return AUL_R_OK;
-}
-
-API int aul_running_context_get_app_id(aul_running_context_h handle,
- const char **app_id)
-{
- if (!handle || !app_id) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- *app_id = handle->app_id;
-
- return AUL_R_OK;
-}
-
-API int aul_running_context_get_comp_id(aul_running_context_h handle,
- const char **comp_id)
-{
- if (!handle || !comp_id) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- *comp_id = handle->comp_id;
-
- return AUL_R_OK;
-}
-
-API int aul_running_context_get_inst_id(aul_running_context_h handle,
- const char **inst_id)
-{
- if (!handle || !inst_id) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- *inst_id = handle->inst_id;
-
- return AUL_R_OK;
-}
-
-API int aul_running_context_get_pid(aul_running_context_h handle,
- int *pid)
-{
- if (!handle || !pid) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- *pid = handle->pid;
-
- return AUL_R_OK;
-}
+++ /dev/null
-/*
- * Copyright (c) 2016 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 <stdbool.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <glib.h>
-#include <bundle.h>
-#include <bundle_internal.h>
-
-#include "aul_util.h"
-#include "aul_api.h"
-#include "aul.h"
-#include "aul_sock.h"
-#include "aul_app_com.h"
-#include "aul_screen_connector.h"
-
-struct aul_screen_viewer_s {
- aul_app_com_connection_h conn;
- aul_screen_viewer_cb callback;
- aul_screen_type_e type;
- bool priv;
- unsigned int ref;
- void *user_data;
-};
-
-static unsigned int ref;
-
-static unsigned int __get_ref(void)
-{
- return ++ref;
-}
-
-static int __add_screen_viewer(int type, bool priv, unsigned int ref)
-{
- int ret;
- bundle *b;
- char buf[MAX_PID_STR_BUFSZ];
-
- b = bundle_create();
- if (b == NULL) {
- _E("out of memory");
- return -1;
- }
-
- snprintf(buf, sizeof(buf), "%d", type);
- ret = bundle_add(b, AUL_K_SCREEN_TYPE, buf);
- if (ret != BUNDLE_ERROR_NONE) {
- _E("Failed to add screen type(%d)", type);
- bundle_free(b);
- return -1;
- }
-
- snprintf(buf, sizeof(buf), "%u", ref);
- ret = bundle_add(b, AUL_K_VIEWER_REF, buf);
- if (ret != BUNDLE_ERROR_NONE) {
- _E("Failed to add viewer reference(%u)", ref);
- bundle_free(b);
- return -1;
- }
-
- if (priv) {
- ret = bundle_add(b, AUL_K_PRIVATE, "true");
- if (ret != BUNDLE_ERROR_NONE) {
- _E("Failed to add bundle data");
- bundle_free(b);
- return -1;
- }
- }
-
- ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(),
- ADD_SCREEN_VIEWER, b, AUL_SOCK_NOREPLY);
- bundle_free(b);
- if (ret < 0)
- return -1;
-
- return 0;
-}
-
-static int __remove_screen_viewer(int type, bool priv, unsigned int ref)
-{
- int ret;
- bundle *b;
- char buf[MAX_PID_STR_BUFSZ];
-
- b = bundle_create();
- if (b == NULL) {
- _E("out of memory");
- return -1;
- }
-
- snprintf(buf, sizeof(buf), "%d", type);
- ret = bundle_add(b, AUL_K_SCREEN_TYPE, buf);
- if (ret != BUNDLE_ERROR_NONE) {
- _E("Failed to add view mode");
- bundle_free(b);
- return -1;
- }
-
- snprintf(buf, sizeof(buf), "%u", ref);
- ret = bundle_add(b, AUL_K_VIEWER_REF, buf);
- if (ret != BUNDLE_ERROR_NONE) {
- _E("Failed to add viewer reference(%u)", ref);
- bundle_free(b);
- return -1;
- }
-
- if (priv) {
- ret = bundle_add(b, AUL_K_PRIVATE, "true");
- if (ret != BUNDLE_ERROR_NONE) {
- _E("Failed to add bundle data");
- bundle_free(b);
- return -1;
- }
- }
-
- ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(),
- REMOVE_SCREEN_VIEWER, b, AUL_SOCK_NOREPLY);
- bundle_free(b);
- if (ret < 0)
- return -1;
-
- return 0;
-}
-
-static int __app_screen_event_cb(const char *endpoint, aul_app_com_result_e res,
- bundle *envelope, void *user_data)
-{
- aul_screen_viewer_h handle = (aul_screen_viewer_h)user_data;
- char *appid = NULL;
- char *instance_id = NULL;
- unsigned int *surf = NULL;
- int *pid = NULL;
- size_t size;
- char *event = NULL;
- aul_screen_connector_event_type_e event_type;
-
- bundle_get_str(envelope, "__AUL_SC_EVENT__", &event);
- if (event == NULL) {
- _E("Failed to get screen connector event");
- return -1;
- } else if (strcmp(event, "add_screen") == 0) {
- event_type = AUL_SCREEN_CONNECTOR_EVENT_TYPE_ADD;
- } else if (strcmp(event, "remove_screen") == 0) {
- event_type = AUL_SCREEN_CONNECTOR_EVENT_TYPE_REMOVE;
- } else if (strcmp(event, "update_screen") == 0) {
- event_type = AUL_SCREEN_CONNECTOR_EVENT_TYPE_UPDATE;
- } else if (strcmp(event, "focus_screen") == 0) {
- event_type = AUL_SCREEN_CONNECTOR_EVENT_TYPE_FOCUS;
- } else {
- _E("Unknown event type(%s)", event);
- return -1;
- }
-
- bundle_get_str(envelope, "__AUL_SC_APPID__", &appid);
- if (appid == NULL) {
- _E("Failed to get appid");
- return -1;
- }
-
- bundle_get_byte(envelope, "__AUL_SC_SURFACE__",
- (void **)&surf, &size);
- if (surf == NULL) {
- _E("Failed to get surface");
- return -1;
- }
-
- bundle_get_byte(envelope, "__AUL_SC_PID__", (void **)&pid, &size);
- if (pid == NULL) {
- _E("Failed to get pid");
- return -1;
- }
- bundle_get_str(envelope, "__AUL_SC_INSTANCE_ID__", &instance_id);
-
- if (handle->callback) {
- handle->callback(appid, instance_id, *pid, *surf,
- event_type, handle->user_data);
- }
- _D("appid(%s), instance_id(%s), pid(%d), surface(%d), event_type(%d)",
- appid, instance_id, *pid, *surf, event_type);
-
- return 0;
-}
-
-static int __screen_viewer_fini(aul_screen_viewer_h screen_viewer)
-{
- int ret;
-
- if (screen_viewer->conn) {
- aul_app_com_leave(screen_viewer->conn);
- screen_viewer->conn = NULL;
- }
-
- ret = __remove_screen_viewer(screen_viewer->type, screen_viewer->priv,
- screen_viewer->ref);
- if (ret < 0) {
- _E("Failed to remove screen watcher");
- return -1;
- }
-
- return 0;
-}
-
-static int __screen_viewer_init(aul_screen_viewer_h screen_viewer)
-{
- int ret;
- char endpoint[128];
- pid_t pid = getpid();
-
- snprintf(endpoint, sizeof(endpoint), "app_screen_event:%u:%d",
- screen_viewer->ref, pid);
- aul_app_com_create(endpoint, NULL, __app_screen_event_cb,
- screen_viewer, &screen_viewer->conn);
- if (screen_viewer->conn == NULL) {
- _E("Failed to create app com");
- return -1;
- }
-
- ret = __add_screen_viewer(screen_viewer->type, screen_viewer->priv,
- screen_viewer->ref);
- if (ret < 0) {
- _E("Failed to add screen watcher");
- return -1;
- }
-
- return 0;
-}
-
-API int aul_screen_connector_add_screen_viewer(aul_screen_viewer_cb callback,
- aul_screen_type_e type, bool priv,
- void *data, aul_screen_viewer_h *handle)
-{
- struct aul_screen_viewer_s *screen_viewer;
-
- if (handle == NULL || callback == NULL ||
- !(type & AUL_SCREEN_TYPE_ALL)) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- screen_viewer = (struct aul_screen_viewer_s *)calloc(1,
- sizeof(struct aul_screen_viewer_s));
- if (screen_viewer == NULL) {
- _E("Out of memory");
- return AUL_R_EINVAL;
- }
-
- screen_viewer->callback = callback;
- screen_viewer->type = type;
- screen_viewer->priv = priv;
- screen_viewer->ref = __get_ref();
- screen_viewer->user_data = data;
-
- if (__screen_viewer_init(screen_viewer) < 0) {
- __screen_viewer_fini(screen_viewer);
- free(screen_viewer);
- return AUL_R_ERROR;
- }
- *handle = screen_viewer;
-
- return AUL_R_OK;
-}
-
-API int aul_screen_connector_remove_screen_viewer(aul_screen_viewer_h handle)
-{
- if (handle == NULL)
- return AUL_R_EINVAL;
-
- __screen_viewer_fini(handle);
- free(handle);
-
- return AUL_R_OK;
-}
-
-API int aul_screen_connector_add_app_screen(const char *instance_id,
- unsigned int surf)
-{
- int ret;
- bundle *b;
- char buf[MAX_PID_STR_BUFSZ];
-
- b = bundle_create();
- if (b == NULL) {
- _E("out of memory");
- return AUL_R_ERROR;
- }
-
- snprintf(buf, sizeof(buf), "%d", surf);
- ret = bundle_add(b, AUL_K_WID, buf);
- if (ret != BUNDLE_ERROR_NONE) {
- _E("Failed to add surf");
- bundle_free(b);
- return AUL_R_ERROR;
- }
-
- if (instance_id) {
- ret = bundle_add(b, AUL_K_INSTANCE_ID, instance_id);
- if (ret != BUNDLE_ERROR_NONE) {
- _E("Failed to add instance id");
- bundle_free(b);
- return AUL_R_ERROR;
- }
- }
-
- ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(),
- ADD_APP_SCREEN, b, AUL_SOCK_NOREPLY);
- bundle_free(b);
- if (ret < 0) {
- _E("Failed to add app screen");
- return ret;
- }
-
- return AUL_R_OK;
-}
-
-API int aul_screen_connector_remove_app_screen(const char *instance_id)
-{
- int ret;
- bundle *b;
-
- b = bundle_create();
- if (b == NULL) {
- _E("out of memory");
- return AUL_R_ERROR;
- }
-
- if (instance_id) {
- ret = bundle_add(b, AUL_K_INSTANCE_ID, instance_id);
- if (ret != BUNDLE_ERROR_NONE) {
- _E("Failed to add instance id");
- bundle_free(b);
- return AUL_R_ERROR;
- }
- }
-
- ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(),
- REMOVE_APP_SCREEN, b, AUL_SOCK_NOREPLY);
- bundle_free(b);
- if (ret < 0) {
- _E("Failed to remove app screen");
- return ret;
- }
-
- return AUL_R_OK;
-}
-
-API int aul_screen_connector_send_update_request(const char *appid,
- const char *instance_id)
-{
- int ret;
- bundle *b;
-
- if (appid == NULL) {
- _E("Invalid parameter");
- return -1;
- }
-
- b = bundle_create();
- if (b == NULL) {
- _E("out of memory");
- return AUL_R_ERROR;
- }
-
- ret = bundle_add(b, AUL_K_APPID, appid);
- if (ret != BUNDLE_ERROR_NONE) {
- _E("Failed to add appid");
- bundle_free(b);
- return AUL_R_ERROR;
- }
-
- if (instance_id) {
- ret = bundle_add(b, AUL_K_INSTANCE_ID, instance_id);
- if (ret != BUNDLE_ERROR_NONE) {
- _E("Failed to add instance id");
- bundle_free(b);
- return AUL_R_ERROR;
- }
- }
-
- ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(),
- APP_UPDATE_REQUESTED, b, AUL_SOCK_NOREPLY);
- bundle_free(b);
- if (ret < 0) {
- _E("Failed to update app screen");
- return ret;
- }
-
- return AUL_R_OK;
-}
-
-static bundle *__send_request_with_surface_id(int cmd, unsigned int surface_id)
-{
- app_pkt_t *pkt = NULL;
- bundle *b;
- int fd;
- int r;
-
- b = bundle_create();
- if (b == NULL) {
- _E("Out of memory");
- return NULL;
- }
-
- r = bundle_add_byte(b, "__AUL_SC_SURFACE__",
- &surface_id, sizeof(unsigned int));
- if (r != BUNDLE_ERROR_NONE) {
- _E("Failed to add surface id(%u)", surface_id);
- bundle_free(b);
- return NULL;
- }
-
- fd = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), cmd, b,
- AUL_SOCK_ASYNC);
- bundle_free(b);
- if (fd < 0) {
- _E("Failed to send request(%d)", cmd);
- return NULL;
- }
-
- aul_sock_recv_reply_pkt(fd, &pkt);
- if (pkt == NULL) {
- _E("Failed to receive the packet");
- return NULL;
- }
-
- b = bundle_decode(pkt->data, pkt->len);
- free(pkt);
- if (b == NULL) {
- _E("Failed to decode bundle data");
- return NULL;
- }
-
- return b;
-}
-
-API int aul_screen_connector_get_appid_by_surface_id(unsigned int surface_id,
- char **appid)
-{
- const char *val;
- bundle *b;
-
- if (appid == NULL) {
- _E("Invalid parameter");
- return AUL_R_ERROR;
- }
-
- b = __send_request_with_surface_id(APP_GET_APPID_BY_SURFACE_ID,
- surface_id);
- if (b == NULL)
- return AUL_R_ERROR;
-
- val = bundle_get_val(b, AUL_K_APPID);
- if (val == NULL) {
- _E("Failed to get appid");
- bundle_free(b);
- return AUL_R_ERROR;
- }
-
- *appid = strdup(val);
- if (*appid == NULL) {
- _E("Out of memory");
- bundle_free(b);
- return AUL_R_ERROR;
- }
- bundle_free(b);
-
- return AUL_R_OK;
-}
-
-API int aul_screen_connector_get_instance_id_by_surface_id(
- unsigned int surface_id, char **instance_id)
-{
- const char *val;
- bundle *b;
-
- if (instance_id == NULL) {
- _E("Invalid parameter");
- return AUL_R_ERROR;
- }
-
- b = __send_request_with_surface_id(APP_GET_INSTANCE_ID_BY_SURFACE_ID,
- surface_id);
- if (b == NULL)
- return AUL_R_ERROR;
-
- val = bundle_get_val(b, AUL_K_INSTANCE_ID);
- if (val == NULL) {
- _E("Failed to get instance id");
- bundle_free(b);
- return AUL_R_ERROR;
- }
-
- *instance_id = strdup(val);
- if (*instance_id == NULL) {
- _E("Out of memory");
- bundle_free(b);
- return AUL_R_ERROR;
- }
- bundle_free(b);
-
- return AUL_R_OK;
-}
-
-
-API int aul_screen_connector_update_screen_viewer_status(
- aul_screen_status_e status, unsigned int provider_surf)
-{
- char buf[32];
- bundle *b;
- int ret;
-
- if (status < AUL_SCREEN_STATUS_RESUME ||
- status > AUL_SCREEN_STATUS_PAUSE) {
- _E("Invalid parameter");
- return AUL_R_ERROR;
- }
-
- b = bundle_create();
- if (b == NULL) {
- _E("Out of memory");
- return AUL_R_ERROR;
- }
-
- snprintf(buf, sizeof(buf), "%u", provider_surf);
- ret = bundle_add(b, AUL_K_WID, buf);
- if (ret != BUNDLE_ERROR_NONE) {
- _E("Failed to add provider surface id");
- bundle_free(b);
- return AUL_R_ERROR;
- }
-
- snprintf(buf, sizeof(buf), "%d", status);
- ret = bundle_add(b, "__AUL_SC_VIEWER_STATUS__", buf);
- if (ret != BUNDLE_ERROR_NONE) {
- _E("Failed to add screen status");
- bundle_free(b);
- return AUL_R_ERROR;
- }
-
- ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(),
- UPDATE_SCREEN_VIEWER_STATUS, b, AUL_SOCK_NOREPLY);
- bundle_free(b);
-
- return ret;
-}
-
-API int aul_screen_connector_trigger_focused_force(void)
-{
- int ret;
- char buf[MAX_PID_STR_BUFSZ];
- bundle *b;
-
- b = bundle_create();
- if (b == NULL) {
- _E("out of memory");
- return -1;
- }
-
- snprintf(buf, sizeof(buf), "%d", AUL_SCREEN_TYPE_UI);
- ret = bundle_add(b, AUL_K_SCREEN_TYPE, buf);
- if (ret != BUNDLE_ERROR_NONE) {
- _E("Failed to add view mode");
- bundle_free(b);
- return -1;
- }
-
- ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(),
- TRIGGER_APP_SCREEN_FOCUSED_FORCE, b, AUL_SOCK_NOREPLY);
- bundle_free(b);
-
- return ret;
-}
+++ /dev/null
-/*
- * Copyright (c) 2000 - 2022 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul_sock.h"
-
-#include <ctype.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <glib.h>
-#include <libgen.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <tzplatform_config.h>
-#include <unistd.h>
-#include <vconf.h>
-
-#include <bundle_cpp.h>
-
-#include "aul_api.h"
-#include "aul_key.h"
-#include "aul_util.h"
-
-#include "aul/socket/client_socket.hh"
-#include "aul/socket/packet.hh"
-#include "aul/socket/server_socket.hh"
-#include "cpu_inheritance.hh"
-
-using namespace aul;
-
-namespace {
-
-constexpr const int MAX_NR_OF_DESCRIPTORS = 2;
-constexpr const int MAX_PAYLOAD_SIZE = 1024 * 1024 * 1;
-constexpr const char PATH_AUL_SOCKET_TIMEOUT[] = "/run/aul/.socket_timeout";
-constexpr const char PATH_AMD_SOCK[] = "/run/aul/daemons/.amd-sock";
-
-constexpr unsigned int SOCKET_TIMEOUT_MIN = 5000U;
-constexpr unsigned int SOCKET_TIMEOUT_MAX = 30000U;
-
-// POD type
-struct PacketHeader {
- int cmd;
- int len;
- int opt;
-};
-
-class SocketTimeout {
- public:
- SocketTimeout() = default;
-
- ~SocketTimeout() {
- if (initialized_)
- vconf_ignore_key_changed(VCONFKEY_AUL_SOCKET_TIMEOUT, VconfCb);
- }
-
- timeval GetTimeval() const {
- return time_val_;
- }
-
- bool IsInitialized() const {
- return initialized_;
- }
-
- void Init() {
- if (access(PATH_AUL_SOCKET_TIMEOUT, F_OK) != 0) {
- initialized_ = true;
- return;
- }
-
- double timeout = 5.2f;
- int ret = vconf_get_dbl(VCONFKEY_AUL_SOCKET_TIMEOUT, &timeout);
- if (ret != VCONF_OK)
- _E("vconf_get_dbl() is failed. error(%d)", ret);
-
- ret = vconf_notify_key_changed(VCONFKEY_AUL_SOCKET_TIMEOUT, VconfCb, this);
- if (ret != VCONF_OK)
- _E("vconf_notify_key_changed() is failed. error(%d)", ret);
-
- SetTimeout(timeout);
- initialized_ = true;
- }
-
- private:
- static void VconfCb(keynode_t* node, void* user_data) {
- auto* h = static_cast<SocketTimeout*>(user_data);
- double timeout = vconf_keynode_get_dbl(node);
- h->SetTimeout(timeout);
- }
-
- void SetTimeout(double timeout) {
- char buf[12];
- snprintf(buf, sizeof(buf), "%.3f", timeout);
- gchar* ptr = nullptr;
- time_val_.tv_sec = g_ascii_strtoll(buf, &ptr, 10);
- time_val_.tv_usec = g_ascii_strtoll(ptr + 1, &ptr, 10) * 1000;
- }
-
- private:
- bool initialized_ = false;
- timeval time_val_ = { 5, 200 * 1000 };
-};
-
-std::string GetSocketPath(pid_t pid, uid_t uid) {
- if (pid == -2)
- return std::string(PATH_AMD_SOCK);
-
- char path[108];
- if (uid < REGULAR_UID_MIN)
- snprintf(path, sizeof(path), "/run/aul/daemons/%u/.app-sock-%d", uid, pid);
- else
- snprintf(path, sizeof(path), "/run/aul/apps/%u/%d/.app-sock", uid, pid);
-
- return std::string(path);
-}
-
-int CreateSocketDirectory(pid_t pid, uid_t uid) {
- std::string socket_path = GetSocketPath(pid, uid);
- std::string path = dirname(const_cast<char*>(socket_path.c_str()));
- if (mkdir(path.c_str(), 0700) != 0) {
- if (errno == EEXIST) {
- if (access(path.c_str(), R_OK) != 0) {
- _E("access() is failed. path(%s), errno(%d)", path.c_str(), errno);
- return -1;
- }
- } else {
- _E("mkdir() is failed. path(%s), errno(%d)", path.c_str(), errno);
- return -1;
- }
- }
-
- return 0;
-}
-
-class SocketLink {
- public:
- SocketLink() = default;
-
- void Create(const std::string& socket_path, pid_t pid, uid_t uid) {
- if (CreateSocketDirectory(pid, uid) != 0)
- return;
-
- path_ = GetSocketPath(pid, uid);
- if (link(socket_path.c_str(), path_.c_str()) != 0) {
- _E("link() is failed. old(%s), new(%s), errno(%d)",
- socket_path.c_str(), path_.c_str(), errno);
- }
-
- created_ = true;
- }
-
- void Delete() {
- if (!created_)
- return;
-
- unlink(path_.c_str());
- created_ = false;
- }
-
- private:
- bool created_ = false;
- std::string path_;
-};
-
-int SendAndReceive(ClientSocket* client, int cmd, unsigned char* data,
- int datalen, int opt) {
- _D("fd(%d), cmd(%d)", client->GetFd(), cmd);
-
- Packet packet(cmd, opt, { data, data + datalen });
- tizen_base::Parcel parcel;
- parcel.WriteParcelable(packet);
-
- int ret = client->Send(parcel.GetData(), parcel.GetDataSize());
- if (ret != 0 || opt & AUL_SOCK_NOREPLY) {
- if (!(opt & AUL_SOCK_ASYNC))
- client->Close();
-
- return ret;
- }
-
- if (opt & AUL_SOCK_ASYNC)
- return client->RemoveFd();
-
- int res;
- ret = client->Receive(reinterpret_cast<void*>(&res), sizeof(res));
- if (ret < 0)
- res = ret;
-
- return res;
-}
-
-int SendAndReceive(int fd, int cmd, unsigned char* data, int datalen,
- int opt) {
- ClientSocket client(fd);
- int ret = SendAndReceive(&client, cmd, data, datalen, opt);
- if (ret < 0) {
- if (opt & AUL_SOCK_ASYNC)
- client.RemoveFd();
- }
-
- return ret;
-}
-
-int SendAndReceive(int pid, uid_t uid, int cmd, unsigned char* data,
- int datalen, int opt) {
- int ret;
- try {
- ClientSocket client;
- std::string endpoint = GetSocketPath(pid, uid);
- client.Connect(endpoint);
- aul_sock_set_sock_option(client.GetFd(), 1);
-
- const auto& inherit = internal::CPUInheritance(pid, cmd);
- ret = SendAndReceive(&client, cmd, data, datalen, opt);
- } catch (const Exception& e) {
- _E("Exception occurs. error(%d)", e.GetErrorCode());
- return -ECOMM;
- }
-
- return ret;
-}
-
-int SendAndReceiveWithTimeout(int pid, uid_t uid, int cmd, unsigned char* data,
- int datalen, int opt, int timeout) {
- int ret;
- try {
- ClientSocket client;
- client.Connect(GetSocketPath(pid, uid));
- aul_sock_set_sock_option(client.GetFd(), 1);
- _W("timeout: %dms", timeout);
- client.SetReceiveTimeout(timeout);
-
- const auto& inherit = internal::CPUInheritance(pid, cmd);
- ret = SendAndReceive(&client, cmd, data, datalen, opt);
- } catch (const Exception& e) {
- _E("Exception occurs. error(%d)", e.GetErrorCode());
- return -ECOMM;
- }
-
- return ret;
-}
-
-int ReceiveAppPacket(ClientSocket* client, app_pkt_t** out_pkt) {
- PacketHeader header;
- static_assert(std::is_standard_layout<PacketHeader>(),
- "PacketHeader should be POD type");
- static_assert(std::is_trivial<PacketHeader>(),
- "Header should be POD type");
-
- *out_pkt = nullptr;
- int ret = client->Receive(&header, sizeof(header));
- if (ret < 0)
- return ret;
-
- if (header.len < 0 || header.len > MAX_PAYLOAD_SIZE) {
- _E("Invalid packet. length(%d)", header.len);
- return -ECOMM;
- }
-
- app_pkt_t* pkt = static_cast<app_pkt_t*>(
- calloc(1, sizeof(app_pkt_t) + header.len));
- if (pkt == nullptr) {
- _E("Out of memory");
- return -ENOMEM;
- }
-
- pkt->cmd = header.cmd;
- pkt->len = header.len;
- pkt->opt = header.opt;
-
- ret = client->Receive(pkt->data, pkt->len);
- if (ret < 0) {
- free(pkt);
- return ret;
- }
-
- *out_pkt = pkt;
- return 0;
-}
-
-int GetFileDescriptor(struct cmsghdr* cmsg, struct msghdr* msg, int* fds,
- int maxdesc) {
- if (cmsg == nullptr || msg == nullptr)
- return 0;
-
- if (cmsg->cmsg_type != SCM_RIGHTS)
- return 0;
-
- int retnr = 0;
- if (msg->msg_controllen > 0) {
- int payload = cmsg->cmsg_len - sizeof(*cmsg);
- int* recvdesc = reinterpret_cast<int*>(CMSG_DATA(cmsg));
- int nrdesc = payload / sizeof(int);
- retnr = nrdesc < maxdesc ? nrdesc : maxdesc;
- for (int i = 0; i < nrdesc; ++i) {
- if (maxdesc-- > 0)
- *fds++ = *recvdesc++;
- else
- close(*recvdesc++);
- }
- }
-
- return retnr;
-}
-
-int ReceiveMessage(int fd, struct iovec* vec, size_t vec_max_size,
- int* vec_size, int* fds, int* nr_fds) {
- if (vec == nullptr || vec_max_size < 1 || vec_size == nullptr)
- return -EINVAL;
-
- char buf[CMSG_SPACE(sizeof(int) * MAX_NR_OF_DESCRIPTORS) + CMSG_SPACE(50)] = { 0, };
- struct msghdr msg = { 0, };
- msg.msg_iov = vec;
- msg.msg_iovlen = vec_max_size;
- msg.msg_control = buf;
- msg.msg_controllen = sizeof(buf);
-
- bool is_blocking;
- if (fcntl(fd, F_GETFL, 0) & O_NONBLOCK)
- is_blocking = false;
- else
- is_blocking = true;
-
-retry:
- int ret = recvmsg(fd, &msg, 0);
- if (ret == 0) {
- _W("Socket was disconnected. fd(%d)", fd);
- return -ECOMM;
- }
-
- if (ret < 0) {
- if (errno == EINTR || errno == EAGAIN) {
- if (is_blocking && errno == EAGAIN) {
- _E("recvmsg() timed out. fd(%d)", fd);
- return -EAGAIN;
- }
-
- usleep(100 * 1000);
- goto retry;
- }
-
- ret = -errno;
- _E("recvmsg() is failed. fd(%d), errno(%d)", fd, errno);
- return ret;
- }
-
- *vec_size = msg.msg_iovlen;
-
- struct cmsghdr* cmsg = CMSG_FIRSTHDR(&msg);
- if (cmsg == nullptr) {
- if (nr_fds != nullptr)
- *nr_fds = 0;
- } else {
- for (int i = 0; cmsg != nullptr; cmsg = CMSG_NXTHDR(&msg, cmsg), ++i) {
- if (cmsg->cmsg_type == SCM_RIGHTS) {
- if (fds != nullptr) {
- int fdnum = GetFileDescriptor(cmsg, &msg, fds, MAX_NR_OF_DESCRIPTORS);
- if (nr_fds != nullptr)
- *nr_fds = fdnum;
- }
- }
- }
- }
-
- return 0;
-}
-
-void DeleteDirectories(const std::string& path) {
- if (path.empty())
- return;
-
- DIR* dp = opendir(path.c_str());
- if (dp == nullptr)
- return;
-
- struct stat statbuf;
- struct dirent* dentry = nullptr;
- while ((dentry = readdir(dp)) != nullptr) {
- if (!strcmp(dentry->d_name, ".") || !strcmp(dentry->d_name, ".."))
- continue;
-
- std::string entry = path + dentry->d_name;
- if (stat(entry.c_str(), &statbuf) == 0) {
- if (S_ISDIR(statbuf.st_mode))
- DeleteDirectories(entry);
- else
- unlink(entry.c_str());
- }
- }
-
- rmdir(path.c_str());
- closedir(dp);
-}
-
-unsigned int GetSocketTimeout(unsigned int timeout) {
- return std::min(std::max(timeout, SOCKET_TIMEOUT_MIN), SOCKET_TIMEOUT_MAX);
-}
-
-SocketTimeout socket_timeout;
-SocketLink socket_link;
-
-} // namespace
-
-extern "C" API struct timeval aul_sock_get_rcv_timeout(void) {
- return socket_timeout.GetTimeval();
-}
-
-extern "C" API int aul_sock_set_sock_option(int fd, int cli) {
- if (fd < 0 || fd >= sysconf(_SC_OPEN_MAX)) {
- _E("Invalid parameter");
- return -EINVAL;
- }
-
- int size = AUL_SOCK_MAXBUFF;
- int ret = setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &size, sizeof(size));
- if (ret != 0)
- return ret;
-
- ret = setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size));
- if (ret != 0)
- return ret;
-
- if (cli) {
- if (TIZEN_FEATURE_SOCKET_TIMEOUT && !socket_timeout.IsInitialized())
- socket_timeout.Init();
-
- auto timeout = socket_timeout.GetTimeval();
- ret = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
- if (ret != 0)
- return ret;
- }
-
- return 0;
-}
-
-extern "C" API int aul_sock_create_server(int pid, uid_t uid) {
- auto path = GetSocketPath(pid, uid);
- int fd = -1;
- try {
- if (CreateSocketDirectory(pid, uid) != 0)
- return -1;
-
- ServerSocket socket;
- socket.Bind(path);
- aul_sock_set_sock_option(socket.GetFd(), 0);
- socket.Listen(128);
- fd = socket.RemoveFd();
- } catch (const Exception& e) {
- _E("Exception occurs. error(%d)", e.GetErrorCode());
- return e.GetErrorCode();
- }
-
- if (pid > 0) {
- pid_t aul_pid;
- const char* aul_pid_str = getenv("AUL_PID");
- if (aul_pid_str != nullptr && isdigit(aul_pid_str[0]))
- aul_pid = atoi(aul_pid_str);
- else
- aul_pid = -1;
-
- if (aul_pid > 1 && aul_pid != pid)
- socket_link.Create(path.c_str(), aul_pid, uid);
- }
-
- return fd;
-}
-
-extern "C" API int aul_sock_send_raw_with_fd(int fd, int cmd,
- unsigned char* kb_data, int datalen, int opt) {
- if (fd < 0 || fd >= sysconf(_SC_OPEN_MAX)) {
- _E("Invalid parameter");
- return -EINVAL;
- }
-
- return SendAndReceive(fd, cmd, kb_data, datalen, opt);
-}
-
-extern "C" API int aul_sock_send_bundle_with_fd(int fd, int cmd, bundle* kb,
- int opt) {
- if (fd < 0 || fd >= sysconf(_SC_OPEN_MAX) || kb == nullptr) {
- _E("Invalid parameter");
- return -EINVAL;
- }
-
- tizen_base::Bundle b(kb, false, false);
- auto raw = b.ToRaw();
- return SendAndReceive(fd, cmd,
- reinterpret_cast<unsigned char*>(raw.first.get()),
- raw.second, opt | AUL_SOCK_BUNDLE);
-}
-
-extern "C" API int aul_sock_send_raw(int pid, uid_t uid, int cmd,
- unsigned char* kb_data, int datalen, int opt) {
- return SendAndReceive(pid, uid, cmd, kb_data, datalen, opt);
-}
-
-extern "C" API int aul_sock_send_bundle(int pid, uid_t uid, int cmd,
- bundle* kb, int opt) {
- if (kb == nullptr)
- return -EINVAL;
-
- tizen_base::Bundle b(kb, false, false);
- std::string timeout_str = b.GetString(AUL_K_SOCKET_TIMEOUT);
- if (timeout_str.empty() || !isdigit(timeout_str[0])) {
- auto [ptr, size] = b.ToRaw();
- return SendAndReceive(pid, uid, cmd,
- reinterpret_cast<unsigned char*>(ptr.get()),
- size, opt | AUL_SOCK_BUNDLE);
- }
-
- unsigned int timeout = static_cast<unsigned int>(std::stoi(timeout_str));
- if (timeout < SOCKET_TIMEOUT_MIN || timeout > SOCKET_TIMEOUT_MAX) {
- timeout = GetSocketTimeout(timeout);
- b.Delete(AUL_K_SOCKET_TIMEOUT);
- b.Add(AUL_K_SOCKET_TIMEOUT, std::to_string(timeout));
- }
-
- auto [ptr, size] = b.ToRaw();
- return SendAndReceiveWithTimeout(
- pid, uid, cmd, reinterpret_cast<unsigned char*>(ptr.get()), size,
- opt | AUL_SOCK_BUNDLE, timeout);
-}
-
-extern "C" API app_pkt_t* aul_sock_recv_pkt(int fd, int* clifd,
- struct ucred* cred) {
- if (fd < 0 || fd >= sysconf(_SC_OPEN_MAX)) {
- _E("Invalid parameter");
- return nullptr;
- }
-
- ServerSocket server(fd);
- auto client = std::unique_ptr<ClientSocket>(server.Accept());
- server.RemoveFd();
- if (client.get() == nullptr)
- return nullptr;
-
- socklen_t optlen = static_cast<socklen_t>(sizeof(struct ucred));
- int ret = getsockopt(client->GetFd(), SOL_SOCKET, SO_PEERCRED,
- cred, &optlen);
- if (ret < 0) {
- _E("getsockopt() is failed. errno(%d)", errno);
- return nullptr;
- }
-
- aul_sock_set_sock_option(client->GetFd(), 1);
-
- app_pkt_t* pkt = nullptr;
- ret = ReceiveAppPacket(client.get(), &pkt);
- if (ret < 0)
- return nullptr;
-
- *clifd = client->RemoveFd();
- return pkt;
-}
-
-extern "C" API int aul_sock_recv_reply_pkt(int fd, app_pkt_t** ret_pkt) {
- return aul_sock_recv_reply_pkt_v2(fd, ret_pkt, true);
-}
-
-extern "C" API int aul_sock_recv_reply_sock_fd(int fd, int (*ret_fd)[2],
- int fd_size) {
- if (fd < 0 || fd >= sysconf(_SC_OPEN_MAX)) {
- _E("Invalid parameter");
- return -EINVAL;
- }
-
- int fds[2] = { -1, -1 };
- int vec_len = 0;
- int fds_len = 0;
- char recv_buff[1024] = { 0, };;
- struct iovec vec[3] = { 0, };
- vec[0].iov_base = recv_buff;
- vec[0].iov_len = sizeof(recv_buff);
- int ret = ReceiveMessage(fd, vec, 1, &vec_len, fds, &fds_len);
- if (ret < 0) {
- _E("ReceiveMessage() is failed. error(%d)", ret);
- if (fds_len > 0)
- close(fds[0]);
-
- ret = -ECOMM;
- } else if (fds_len == fd_size && fds_len == 2) {
- (*ret_fd)[0] = fds[0];
- (*ret_fd)[1] = fds[1];
- } else if (fds_len == fd_size && fds_len == 1) {
- (*ret_fd)[0] = fds[0];
- } else {
- _E("Wrong number of FD received. Expected: %d, Actual: %d",
- fd_size, fds_len);
- ret = -ECOMM;
- }
-
- close(fd);
- return ret;
-}
-
-extern "C" API int aul_sock_create_launchpad_client_without_timeout(
- const char* pad_type, uid_t uid) {
- int fd = -1;
- try {
- ClientSocket client;
- std::string endpoint = "/run/aul/daemons/" + std::to_string(uid) + "/" +
- std::string(pad_type);
- client.Connect(endpoint);
- fd = client.RemoveFd();
- aul_sock_set_sock_option(fd, 0);
- } catch (const Exception& e) {
- _E("Exception occurs. error(%d)", e.GetErrorCode());
- return e.GetErrorCode();
- }
-
- return fd;
-}
-
-extern "C" API int aul_sock_create_launchpad_client(const char* pad_type,
- uid_t uid) {
- int fd = -1;
- try {
- ClientSocket client;
- std::string endpoint = "/run/aul/daemons/" + std::to_string(uid) + "/" +
- std::string(pad_type);
- client.Connect(endpoint);
- fd = client.RemoveFd();
- aul_sock_set_sock_option(fd, 1);
- } catch (const Exception& e) {
- _E("Exception occurs. error(%d)", e.GetErrorCode());
- return e.GetErrorCode();
- }
-
- return fd;
-}
-
-extern "C" API int aul_sock_recv_pkt_with_cb(int fd,
- void (*callback)(app_pkt_t* pkt, void* user_data),
- void* user_data) {
- if (fd < 0 || fd >= sysconf(_SC_OPEN_MAX)) {
- _E("Invalid parameter");
- return -1;
- }
-
- if (callback == nullptr) {
- _E("Invalid parameter");
- close(fd);
- return -1;
- }
-
- ClientSocket client(fd);
- int count = 0;
- int ret = client.Receive(&count, sizeof(count));
- if (ret != 0) {
- _E("Receive() is failed. error(%d)", ret);
- return ret;
- }
-
- if (count <= 0 || count > MAX_RUNNING_INSTANCE) {
- _E("Error occurs. count(%d)", count);
- return -ECOMM;
- }
-
- app_pkt_t** pkt = reinterpret_cast<app_pkt_t**>(
- calloc(count, sizeof(app_pkt_t*)));
- if (pkt == nullptr) {
- _E("Out of memory");
- return -ENOMEM;
- }
-
- for (int i = 0; i < count; ++i) {
- ret = ReceiveAppPacket(&client, &pkt[i]);
- if (ret != 0) {
- _E("ReceiveAppPacket() is failed. error(%d)", ret);
- break;
- }
- }
-
- for (int i = 0; i < count; ++i) {
- if (pkt[i] != nullptr) {
- callback(pkt[i], user_data);
- free(pkt[i]);
- }
- }
-
- free(pkt);
- return ret;
-}
-
-extern "C" API int aul_sock_recv_result_with_fd(int fd) {
- if (fd < 0 || fd >= sysconf(_SC_OPEN_MAX)) {
- _E("Invalid parameter");
- return -EINVAL;
- }
-
- ClientSocket client(fd);
- int res;
- int ret = client.Receive(&res, sizeof(res));
- client.RemoveFd();
- if (ret < 0) {
- _E("Receive() is failed. fd(%d), error(%d)", fd, ret);
- res = -ECOMM;
- }
-
- return res;
-}
-
-extern "C" API int aul_sock_destroy_server(int fd) {
- if (fd > -1 && fd < sysconf(_SC_OPEN_MAX))
- close(fd);
-
- if (getuid() < REGULAR_UID_MIN) {
- std::string path = "/run/aul/daemons/" + std::to_string(getuid()) +
- "/.app-sock-" + std::to_string(getpid());
- unlink(path.c_str());
- } else {
- std::string path = "/run/aul/apps/" + std::to_string(getuid()) + "/" +
- std::to_string(getpid());
- DeleteDirectories(path);
- }
- socket_link.Delete();
-
- return 0;
-}
-
-extern "C" API int aul_sock_send_result(int fd, int res) {
- return aul_sock_send_result_v2(fd, res, true);
-}
-
-extern "C" API int aul_sock_send_result_v2(int fd, int res, bool do_close) {
- if (fd < 0 || fd >= sysconf(_SC_OPEN_MAX)) {
- _E("Invalid parameter");
- return -EINVAL;
- }
-
- int ret = send(fd, &res, sizeof(res), MSG_NOSIGNAL);
- if (ret < 0)
- _E("send() is failed. fd(%d), errno(%d)", fd, errno);
-
- if (do_close)
- close(fd);
-
- return ret;
-}
-
-extern "C" API int aul_sock_recv_reply_pkt_v2(int fd, app_pkt_t** pkt,
- bool do_close) {
- if (fd < 0 || fd >= sysconf(_SC_OPEN_MAX)) {
- _E("Invalid parameter");
- return -EINVAL;
- }
-
- if (pkt == nullptr) {
- _E("Invalid parameter");
- if (do_close)
- close(fd);
-
- return -EINVAL;
- }
-
- ClientSocket client(fd);
- int ret = ReceiveAppPacket(&client, pkt);
- if (!do_close)
- client.RemoveFd();
-
- return ret;
-}
-
-extern "C" API int aul_sock_send_raw_data(int fd, unsigned char* raw_data,
- size_t length, bool do_close) {
- if (fd < 0 || fd >= sysconf(_SC_OPEN_MAX)) {
- _E("Invalid parameter");
- return -EINVAL;
- }
-
- int ret = send(fd, raw_data, length, MSG_NOSIGNAL);
- if (ret < 0)
- _E("send() is failed. fd(%d), errno(%d)", fd, errno);
-
- if (do_close)
- close(fd);
-
- return ret;
-}
+++ /dev/null
-/*
- * Copyright (c) 2021 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 <bundle.h>
-#include <bundle_cpp.h>
-#include <bundle_internal.h>
-#include <dlfcn.h>
-#include <glib.h>
-#include <iniparser.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-#include <atomic>
-#include <memory>
-#include <mutex>
-#include <string>
-#include <unordered_map>
-#include <vector>
-
-#include "aul/app_control/resolve_info.hh"
-#include "include/aul.h"
-#include "include/aul_app_group.h"
-#include "include/aul_error.h"
-#include "include/aul_sock.h"
-#include "include/aul_svc.h"
-#include "include/aul_svc_internal.h"
-#include "src/aul_api.h"
-#include "src/aul_svc_priv_key.h"
-#include "src/aul_util.h"
-#include "src/launch.h"
-
-#undef MAX_MIME_STR_SIZE
-#define MAX_MIME_STR_SIZE 256
-
-#undef MAX_SCHEME_STR_SIZE
-#define MAX_SCHEME_STR_SIZE 256
-
-#undef MAX_HOST_STR_SIZE
-#define MAX_HOST_STR_SIZE 256
-
-#undef DEPRECATION_WARNING
-#define DEPRECATION_WARNING() do { \
- dlog_print(DLOG_WARN, LOG_TAG, \
- "DEPRECATION WARNING: %s() is deprecated and " \
- "will be removed from next release.", __FUNCTION__); \
-} while (0)
-
-namespace {
-
-constexpr const char kPathAmdReady[] = "/run/.amd_ready";
-constexpr const char kPathLibAulServer[] = LIBDIR "/libaul-server.so.0";
-constexpr const char kAulServiceForeachUsrAliasInfo[] =
- "aul_service_foreach_usr_alias_info";
-
-class CbInfo {
- public:
- CbInfo(int request_code, aul_svc_res_fn res_fn,
- aul_svc_err_cb err_cb, void* user_data)
- : request_code_(request_code),
- res_fn_(res_fn),
- err_cb_(err_cb),
- user_data_(user_data) {
- }
-
- int request_code_;
- aul_svc_res_fn res_fn_;
- aul_svc_err_cb err_cb_;
- void* user_data_;
-};
-
-class AliasInfo {
- public:
- explicit AliasInfo(std::string alias_appid)
- : alias_appid_(std::move(alias_appid)) {
- }
-
- std::string alias_appid_;
- std::string appid_;
-};
-
-class AppSvcAlias {
- public:
- AppSvcAlias() = default;
-
- void Load() {
- std::lock_guard<std::mutex> lock(mutex_);
- if (loaded_)
- return;
-
- dictionary* dict = iniparser_load("/usr/share/appsvc/alias.ini");
- if (dict == nullptr) {
- loaded_ = true;
- return;
- }
-
- std::string delimiter = "Alias:";
- for (int i = 0; i < dict->n; ++i) {
- if (dict->key[i] == nullptr || dict->val[i] == nullptr)
- continue;
-
- std::string key = dict->key[i];
- key.erase(0, key.find(delimiter) + delimiter.length() + 1);
- std::string value = dict->val[i];
- map_[key] = value;
- }
-
- iniparser_freedict(dict);
- loaded_ = true;
- }
-
- std::string GetAliasAppId(const std::string& alias_appid) {
- auto found = map_.find(alias_appid);
- if (found == map_.end())
- return {};
-
- SECURE_LOGD("alias_appid: %s, appid: %s",
- alias_appid.c_str(), found->second.c_str());
- return found->second;
- }
-
- private:
- bool loaded_ = false;
- std::unordered_map<std::string, std::string> map_;
- std::mutex mutex_;
-};
-
-AppSvcAlias appsvc_alias;
-
-int SetBundle(bundle* b, const char* key, const char* value) {
- if (bundle_get_type(b, key) != BUNDLE_TYPE_NONE) {
- if (bundle_del(b, key) != BUNDLE_ERROR_NONE)
- return AUL_SVC_RET_ERROR;
- }
-
- if (value == nullptr)
- return AUL_SVC_RET_EINVAL;
-
- if (bundle_add(b, key, value) != BUNDLE_ERROR_NONE)
- return AUL_SVC_RET_ERROR;
-
- SECURE_LOGD("key(%s), value(%s)", key, value);
- return AUL_SVC_RET_OK;
-}
-
-int SetBundleArray(bundle* b, const char* key, const char** value,
- int len) {
- int is_array = aul_svc_data_is_array(b, key);
- if (is_array) {
- if (bundle_del(b, key) != BUNDLE_ERROR_NONE)
- return AUL_SVC_RET_ERROR;
- }
-
- if (value == nullptr)
- return AUL_SVC_RET_EINVAL;
-
- if (bundle_add_str_array(b, key, value, len) != BUNDLE_ERROR_NONE)
- return AUL_SVC_RET_ERROR;
-
- SECURE_LOGD("key(%s), length(%d)", key, len);
- return AUL_SVC_RET_OK;
-}
-
-std::string GetAliasAppId(const char* appid) {
- appsvc_alias.Load();
- return appsvc_alias.GetAliasAppId(appid);
-}
-
-bool IsSpecialApp(const char* appid) {
- if (!strcmp(appid, APP_SELECTOR) || !strcmp(appid, SHARE_PANEL))
- return true;
-
- return false;
-}
-
-bool IsSpecialOperation(const char* operation) {
- if (operation == nullptr)
- return false;
-
- int ret = strcmp(operation,
- "http://tizen.org/appcontrol/operation/guide_privacy_setting");
- if (ret == 0)
- return true;
-
- return false;
-}
-
-std::string GetAppId(bundle* request) {
- const char* appid = aul_svc_get_pkgname(request);
- if (appid == nullptr) {
- if (aul_svc_get_operation(request) == nullptr) {
- _E("Invalid request");
- return {};
- }
-
- appid = "@UNKNOWN";
- }
-
- int ret = bundle_get_type(request, AUL_SVC_K_SELECTOR_EXTRA_LIST);
- if (ret != BUNDLE_TYPE_NONE) {
- if (appid == nullptr || !strcmp(appid, "@UNKNOWN"))
- appid = APP_SELECTOR;
- }
-
- ret = bundle_get_type(request, AUL_K_FORCE_LAUNCH_APP_SELECTOR);
- if (ret != BUNDLE_TYPE_NONE)
- appid = APP_SELECTOR;
-
- return std::string(appid);
-}
-
-void SetLaunchData(bundle* request, const std::string& appid) {
- const char* operation = aul_svc_get_operation(request);
- if (operation == nullptr)
- aul_svc_set_operation(request, AUL_SVC_OPERATION_DEFAULT);
-
- if (IsSpecialApp(appid.c_str()) || IsSpecialOperation(operation)) {
- SetBundle(request, AUL_SVC_K_CAN_BE_LEADER, "true");
- SetBundle(request, AUL_SVC_K_REROUTE, "true");
- SetBundle(request, AUL_SVC_K_RECYCLE, "true");
- }
-
- const char* launch_mode = aul_svc_get_launch_mode(request);
- if (launch_mode && !strcmp(launch_mode, "group")) {
- int ret = bundle_get_type(request, AUL_K_INSTANCE_ID);
- if (ret == BUNDLE_TYPE_NONE)
- aul_set_instance_info(appid.c_str(), request);
- }
-}
-
-int AulErrorConvert(int res) {
- switch (res) {
- case AUL_R_EILLACC:
- return AUL_SVC_RET_EILLACC;
- case AUL_R_EINVAL:
- return AUL_SVC_RET_EINVAL;
- case AUL_R_ETERMINATING:
- return AUL_SVC_RET_ETERMINATING;
- case AUL_R_EREJECTED:
- return AUL_SVC_RET_EREJECTED;
- case AUL_R_ENOAPP:
- return AUL_SVC_RET_ENOMATCH;
- case AUL_R_ECANCELED:
- return AUL_SVC_RET_ECANCELED;
- case AUL_R_ETIMEOUT:
- return AUL_SVC_RET_ETIMEOUT;
- default:
- return AUL_SVC_RET_ELAUNCH;
- }
-}
-
-void LaunchWithResultCb(bundle* b, int is_cancel, void* data) {
- int res;
- if (is_cancel) {
- res = AUL_SVC_RES_CANCEL;
- } else {
- const char* val = bundle_get_val(b, AUL_SVC_K_RES_VAL);
- res = (val == nullptr) ? AUL_SVC_RES_NOT_OK : atoi(val);
- }
-
- bundle_del(b, AUL_SVC_K_RES_VAL);
- auto* cb_info = static_cast<CbInfo*>(data);
- if (cb_info == nullptr) {
- _E("Invalid parameter");
- return;
- }
-
- if (cb_info->res_fn_) {
- cb_info->res_fn_(b, cb_info->request_code_,
- static_cast<aul_svc_result_val>(res), cb_info->user_data_);
- cb_info->res_fn_ = nullptr;
- }
-
- if (cb_info->err_cb_ != nullptr)
- return;
-
- delete cb_info;
-}
-
-void ErrorCb(int error, void* data) {
- if (error < 0)
- error = AulErrorConvert(error);
-
- auto* cb_info = static_cast<CbInfo*>(data);
- if (cb_info == nullptr) {
- _E("Invalid parameter");
- return;
- }
-
- if (cb_info->err_cb_) {
- cb_info->err_cb_(cb_info->request_code_, error, cb_info->user_data_);
- cb_info->err_cb_ = nullptr;
- }
-
- if (cb_info->res_fn_)
- return;
-
- delete cb_info;
-}
-
-using SendLaunchRequestCb =
- int (*)(const std::string&, bundle*, uid_t, CbInfo*);
-using SendLaunchRequestSyncCb =
- int (*)(const std::string&, bundle*, uid_t, bundle**);
-
-template <typename T, typename A>
-int SendLaunchRequest(T cb, bundle* request, uid_t uid, A arg) {
- if (request == nullptr) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- std::string appid = GetAppId(request);
- if (appid.empty()) {
- _E("GetAppId() is failed");
- return AUL_SVC_RET_EINVAL;
- }
-
- SetLaunchData(request, appid);
- return cb(appid, request, uid, arg);
-}
-
-int SendAndReceive(int cmd, uid_t uid, bundle* request, bundle** response) {
- int fd = aul_sock_send_bundle(AUL_UTIL_PID, uid, cmd, request,
- AUL_SOCK_ASYNC);
- if (fd < 0)
- return AUL_SVC_RET_ERROR;
-
- app_pkt_t* pkt = nullptr;
- int ret = aul_sock_recv_reply_pkt(fd, &pkt);
- if (ret < 0) {
- _E("Failed to receive reply packet. error(%d)", ret);
- return AUL_SVC_RET_ERROR;
- }
-
- auto ptr = std::unique_ptr<app_pkt_t, decltype(std::free)*>(pkt, std::free);
- if (pkt->cmd != APP_GET_INFO_OK && pkt->cmd != cmd) {
- if (pkt->cmd == APP_GET_INFO_ERROR)
- return AUL_SVC_RET_ERROR;
-
- return AulErrorConvert(aul_error_convert(pkt->cmd));
- }
-
- bundle* b = nullptr;
- if (pkt->opt & AUL_SOCK_BUNDLE) {
- b = bundle_decode(pkt->data, pkt->len);
- if (b == nullptr) {
- _E("bundle_decode() is failed");
- return AUL_SVC_RET_ENOMEM;
- }
- } else {
- _E("Invalid packet");
- return AUL_SVC_RET_ERROR;
- }
-
- *response = b;
- return AUL_SVC_RET_OK;
-}
-
-std::atomic<bool> amd_ready { false };
-bool IsAmdReady() {
- if (amd_ready)
- return amd_ready;
-
- if (access(kPathAmdReady, F_OK) == 0) {
- amd_ready.exchange(true);
- return amd_ready;
- }
-
- return false;
-}
-
-using AulServiceAliasInfoCb =
- bool (*)(const char*, const char*, void*);
-using AulServiceForeachUsrAliasInfoFunc =
- int (*)(AulServiceAliasInfoCb, uid_t, void*);
-
-int GetAppIdByAliasAppIdFromDB(const char* alias_appid, char** app_id,
- uid_t uid) {
- void* handle = dlopen(kPathLibAulServer, RTLD_LAZY | RTLD_GLOBAL);
- if (handle == nullptr) {
- _E("dlopen() is failed. path(%s), error(%s)", kPathLibAulServer, dlerror());
- return AUL_SVC_RET_ERROR;
- }
-
- auto dl_closer = [](void* ptr) {
- dlclose(ptr);
- };
-
- std::unique_ptr<void, decltype(dl_closer)> handle_auto(handle, dl_closer);
- auto* func = reinterpret_cast<AulServiceForeachUsrAliasInfoFunc>(
- dlsym(handle, kAulServiceForeachUsrAliasInfo));
- if (func == nullptr) {
- _E("dlsym() is failed. error(%s)", dlerror());
- return AUL_SVC_RET_ERROR;
- }
-
- AliasInfo info(alias_appid);
- int ret = func(
- [](const char* alias_appid, const char* appid, void* user_data) -> bool {
- auto* info = static_cast<AliasInfo*>(user_data);
- if (info->alias_appid_ == alias_appid) {
- info->appid_ = appid;
- return false;
- }
-
- return true;
- }, uid, &info);
- if (ret != 0) {
- _E("%s() is failed. error(%d)", kAulServiceForeachUsrAliasInfo, ret);
- return AUL_SVC_RET_ERROR;
- }
-
- if (info.appid_.empty())
- return AUL_SVC_RET_ERROR;
-
- *app_id = strdup(info.appid_.c_str());
- if (*app_id == nullptr) {
- _E("strdup() is failed");
- return AUL_SVC_RET_ENOMEM;
- }
-
- return AUL_SVC_RET_OK;
-}
-
-} // namespace
-
-extern "C" API int aul_svc_set_operation(bundle* b, const char* operation) {
- if (b == nullptr) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- return ::SetBundle(b, AUL_SVC_K_OPERATION, operation);
-}
-
-extern "C" API int aul_svc_set_uri(bundle* b, const char* uri) {
- if (b == nullptr) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- return ::SetBundle(b, AUL_SVC_K_URI, uri);
-}
-
-extern "C" API int aul_svc_set_mime(bundle* b, const char* mime) {
- if (b == nullptr) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- return ::SetBundle(b, AUL_SVC_K_MIME, mime);
-}
-
-extern "C" API int aul_svc_add_data(bundle* b, const char* key,
- const char* value) {
- if (b == nullptr || key == nullptr)
- return AUL_SVC_RET_EINVAL;
-
- return ::SetBundle(b, key, value);
-}
-
-extern "C" API int aul_svc_add_data_array(bundle* b, const char* key,
- const char** value, int len) {
- if (b == nullptr || key == nullptr)
- return AUL_SVC_RET_EINVAL;
-
- return ::SetBundleArray(b, key, value, len);
-}
-
-extern "C" API int aul_svc_set_pkgname(bundle* b, const char* pkg_name) {
- if (b == nullptr) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- return ::SetBundle(b, AUL_SVC_K_PKG_NAME, pkg_name);
-}
-
-extern "C" API int aul_svc_set_appid(bundle* b, const char* appid) {
- if (b == nullptr || appid == nullptr) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- if (TIZEN_FEATURE_APPSVC_ALIAS) {
- std::string alias_id = ::GetAliasAppId(appid);
- if (!alias_id.empty())
- return ::SetBundle(b, AUL_SVC_K_PKG_NAME, alias_id.c_str());
- }
-
- return ::SetBundle(b, AUL_SVC_K_PKG_NAME, appid);
-}
-
-extern "C" API int aul_svc_set_category(bundle* b, const char* category) {
- if (b == nullptr) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- return ::SetBundle(b, AUL_SVC_K_CATEGORY, category);
-}
-
-extern "C" API int aul_svc_set_launch_mode(bundle* b, const char* mode) {
- if (b == nullptr) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- return ::SetBundle(b, AUL_SVC_K_LAUNCH_MODE, mode);
-}
-
-extern "C" API int aul_svc_resolve(bundle* b, uid_t uid, char*** appid_array,
- unsigned int* len) {
- return aul_svc_get_appid_array(b, uid, appid_array, len);
-}
-
-extern "C" API int aul_svc_run_service(bundle* b, int request_code,
- aul_svc_res_fn cbfunc, void* data) {
- return aul_svc_run_service_for_uid(b, request_code, cbfunc, data, getuid());
-}
-
-extern "C" API int aul_svc_run_service_for_uid(bundle* b, int request_code,
- aul_svc_res_fn cbfunc, void* data, uid_t uid) {
- CbInfo* cb_info = nullptr;
- if (cbfunc) {
- cb_info = new (std::nothrow) CbInfo(request_code, cbfunc, nullptr, data);
- if (cb_info == nullptr)
- LOGE("Out of memory");
- }
-
- std::tuple<aul_svc_res_fn, void*> param { cbfunc, data };
- int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
- [](const std::string& appid, bundle* request, uid_t uid,
- CbInfo* cb_info) -> int {
- int ret;
- if (cb_info) {
- ret = aul_launch_app_with_result_for_uid(appid.c_str(), request,
- LaunchWithResultCb, cb_info, uid);
- } else {
- ret = aul_launch_app_for_uid(appid.c_str(), request, uid);
- }
-
- return ret;
- }, b, uid, cb_info);
- if (ret < 0) {
- if (cb_info)
- delete cb_info;
-
- ret = AulErrorConvert(ret);
- }
-
- return ret;
-}
-
-extern "C" API int aul_svc_get_list(bundle* b, aul_svc_info_iter_fn iter_fn,
- void* data) {
- return aul_svc_get_list_for_uid(b, iter_fn, data, getuid());
-}
-
-extern "C" API int aul_svc_get_list_for_uid(bundle* b,
- aul_svc_info_iter_fn iter_fn, void* data, uid_t uid) {
- if (b == nullptr || iter_fn == nullptr) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- char** appid_array = nullptr;
- unsigned int len = 0;
- int ret = aul_svc_get_appid_array(b, uid, &appid_array, &len);
- if (ret != AUL_SVC_RET_OK)
- return ret;
-
- if (len == 0) {
- _E("Failed to find associated application");
- aul_svc_free_appid_array(appid_array, len);
- return AUL_SVC_RET_ENOMATCH;
- }
-
- for (unsigned int i = 0; i < len; ++i) {
- SECURE_LOGD("APPID: %s", appid_array[i]);
- if (iter_fn(appid_array[i], data) != 0)
- break;
- }
-
- aul_svc_free_appid_array(appid_array, len);
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API int aul_svc_get_all_defapps(aul_svc_info_iter_fn iter_fn,
- void* data) {
- return aul_svc_get_all_defapps_for_uid(iter_fn, data, getuid());
-}
-
-extern "C" API int aul_svc_get_all_defapps_for_uid(aul_svc_info_iter_fn iter_fn,
- void* data, uid_t uid) {
- if (iter_fn == nullptr) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- bundle* response;
- tizen_base::Bundle request;
- int ret = ::SendAndReceive(APP_GET_APP_CONTROL_DEFAULT_APPS, uid,
- request.GetHandle(), &response);
- if (ret != AUL_SVC_RET_OK)
- return ret;
-
- tizen_base::Bundle res(response, false, true);
- auto appid_array = res.GetStringArray(AUL_K_APPID_LIST);
- for (auto& appid : appid_array) {
- if (iter_fn(appid.c_str(), data) != 0)
- break;
- }
-
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API const char* aul_svc_get_operation(bundle* b) {
- return bundle_get_val(b, AUL_SVC_K_OPERATION);
-}
-
-extern "C" API const char* aul_svc_get_uri(bundle* b) {
- return bundle_get_val(b, AUL_SVC_K_URI);
-}
-
-extern "C" API const char* aul_svc_get_mime(bundle* b) {
- return bundle_get_val(b, AUL_SVC_K_MIME);
-}
-
-extern "C" API const char* aul_svc_get_data(bundle* b, const char* key) {
- return bundle_get_val(b, key);
-}
-
-extern "C" API const char** aul_svc_get_data_array(bundle* b, const char* key,
- int* len) {
- return bundle_get_str_array(b, key, len);
-}
-
-extern "C" API const char* aul_svc_get_pkgname(bundle* b) {
- return bundle_get_val(b, AUL_SVC_K_PKG_NAME);
-}
-
-extern "C" API const char* aul_svc_get_appid(bundle* b) {
- return bundle_get_val(b, AUL_SVC_K_PKG_NAME);
-}
-
-extern "C" API const char* aul_svc_get_category(bundle* b) {
- return bundle_get_val(b, AUL_SVC_K_CATEGORY);
-}
-
-extern "C" API const char* aul_svc_get_launch_mode(bundle* b) {
- return bundle_get_val(b, AUL_SVC_K_LAUNCH_MODE);
-}
-
-extern "C" API int aul_svc_create_result_bundle(bundle* inb, bundle** outb) {
- if (inb == nullptr || outb == nullptr) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- int ret = aul_create_result_bundle(inb, outb);
- if (ret != AUL_R_OK)
- return AulErrorConvert(ret);
-
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API int aul_svc_send_result(bundle* b, aul_svc_result_val result) {
- if (b == nullptr) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- int ret = ::SetBundle(b, AUL_SVC_K_RES_VAL, std::to_string(result).c_str());
- if (ret < 0)
- return AUL_SVC_RET_ERROR;
-
- if (result == AUL_SVC_RES_CANCEL)
- ret = aul_send_result(b, 1);
- else
- ret = aul_send_result(b, 0);
-
- bundle_del(b, AUL_SVC_K_RES_VAL);
- return ret;
-}
-
-extern "C" API int aul_svc_data_is_array(bundle* b, const char* key) {
- int type = bundle_get_type(b, key);
- if (type <= 0)
- return 0;
-
- if (type & BUNDLE_TYPE_ARRAY)
- return 1;
-
- return 0;
-}
-
-extern "C" API int aul_svc_allow_transient_app(bundle* b, int wid) {
- if (b == nullptr) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- return ::SetBundle(b, AUL_SVC_K_WIN_ID, std::to_string(wid).c_str());
-}
-
-extern "C" API int aul_svc_request_transient_app(bundle* b, int callee_wid,
- aul_svc_host_res_fn cbfunc, void* data) {
- return 0;
-}
-
-extern "C" API int aul_svc_subapp_terminate_request_pid(int pid) {
- int cpid = getpid();
- int lcnt;
- int* lpids = nullptr;
- aul_app_group_get_leader_pids(&lcnt, &lpids);
- for (int i = 0; i < lcnt; ++i) {
- if (lpids[i] == cpid) {
- int cnt;
- int* pids = nullptr;
- aul_app_group_get_group_pids(cpid, &cnt, &pids);
- if (cnt == 0) {
- free(lpids);
- if (pids)
- free(pids);
-
- return aul_subapp_terminate_request_pid(pid);
- }
-
- if (pids != nullptr)
- free(pids);
- break;
- }
- }
-
- if (lpids != nullptr)
- free(lpids);
-
- return aul_app_group_clear_top();
-}
-
-extern "C" API int aul_send_service_result(bundle* b) {
- return aul_send_result(b, 0);
-}
-
-extern "C" API int aul_svc_subscribe_launch_result(bundle* b,
- const char* result) {
- if (b == nullptr) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- return ::SetBundle(b, result, "1");
-}
-
-extern "C" API int aul_svc_set_loader_id(bundle* b, int loader_id) {
- if (b == nullptr || loader_id <= 0) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- return ::SetBundle(b, AUL_K_LOADER_ID, std::to_string(loader_id).c_str());
-}
-
-extern "C" API int aul_svc_set_loader_name(bundle* b, const char* loader_name) {
- if (b == nullptr || loader_name == nullptr) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- return ::SetBundle(b, AUL_K_LOADER_NAME, loader_name);
-}
-
-extern "C" API int aul_svc_set_background_launch(bundle* b, int enabled) {
- if (b == nullptr) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- return ::SetBundle(b, AUL_SVC_K_BG_LAUNCH, enabled ? "enable" : nullptr);
-}
-
-extern "C" API int aul_svc_get_appid_by_alias_appid(const char* alias_appid,
- char** appid) {
- return aul_svc_get_appid_by_alias_appid_for_uid(alias_appid, appid, getuid());
-}
-
-extern "C" API int aul_svc_get_appid_by_alias_appid_for_uid(
- const char* alias_appid, char** appid, uid_t uid) {
- if (alias_appid == nullptr || appid == nullptr) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- if (!IsAmdReady())
- return GetAppIdByAliasAppIdFromDB(alias_appid, appid, uid);
-
- bundle* response;
- tizen_base::Bundle request;
- request.Add(AUL_K_ALIAS_APPID, alias_appid);
- int ret = ::SendAndReceive(APP_GET_APPID_BY_ALIAS_APPID, uid,
- request.GetHandle(), &response);
- if (ret != AUL_SVC_RET_OK)
- return ret;
-
- tizen_base::Bundle res(response, false, true);
- auto val = res.GetString(AUL_K_APPID);
- if (val.empty())
- return AUL_SVC_RET_ERROR;
-
- *appid = strdup(val.c_str());
- if (*appid == nullptr) {
- _E("Out of memory");
- return AUL_SVC_RET_ENOMEM;
- }
-
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API const char *aul_svc_get_instance_id(bundle* b) {
- return bundle_get_val(b, AUL_K_INSTANCE_ID);
-}
-
-extern "C" API int aul_svc_set_instance_id(bundle* b, const char* instance_id) {
- if (b == nullptr) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- return ::SetBundle(b, AUL_K_INSTANCE_ID, instance_id);
-}
-
-extern "C" API int aul_svc_run_service_async(bundle* b, int request_code,
- aul_svc_res_fn cbfunc, void* data) {
- return aul_svc_run_service_async_for_uid(b, request_code, cbfunc, data,
- getuid());
-}
-
-extern "C" API int aul_svc_run_service_async_for_uid(bundle* b,
- int request_code, aul_svc_res_fn cbfunc, void* data, uid_t uid) {
- CbInfo* cb_info = nullptr;
- if (cbfunc)
- cb_info = new (std::nothrow) CbInfo(request_code, cbfunc, nullptr, data);
-
- int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
- [](const std::string& appid, bundle* request, uid_t uid,
- CbInfo* info) -> int {
- if (info) {
- return aul_launch_app_with_result_async_for_uid(appid.c_str(),
- request, LaunchWithResultCb, info, uid);
- }
-
- return aul_launch_app_async_for_uid(appid.c_str(), request, uid);
- }, b, uid, cb_info);
- if (ret < 0) {
- if (cb_info)
- delete cb_info;
-
- ret = AulErrorConvert(ret);
- }
-
- return ret;
-}
-
-extern "C" API int aul_svc_send_launch_request(bundle* b, int request_code,
- aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb, void* user_data) {
- return aul_svc_send_launch_request_for_uid(b, request_code,
- cbfunc, err_cb, user_data, getuid());
-}
-
-extern "C" API int aul_svc_send_launch_request_for_uid(bundle* b,
- int request_code, aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb,
- void* user_data, uid_t uid) {
- if (b == nullptr || err_cb == nullptr) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- CbInfo* cb_info = new (std::nothrow) CbInfo(request_code, cbfunc, err_cb,
- user_data);
- if (cb_info == nullptr)
- _E("Out of memory");
-
- int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
- [](const std::string& appid, bundle* request, uid_t uid,
- CbInfo* info) -> int {
- return aul_send_launch_request_for_uid(appid.c_str(), request, uid,
- info->res_fn_ ? ::LaunchWithResultCb : nullptr, ::ErrorCb, info);
- }, b, uid, cb_info);
- if (ret < 0) {
- delete cb_info;
- ret = ::AulErrorConvert(ret);
- }
-
- return ret;
-}
-
-extern "C" API int aul_svc_send_launch_request_sync_for_uid(bundle* b,
- int request_code, bundle** res_b, aul_svc_result_val* res, uid_t uid) {
- if (b == nullptr || res_b == nullptr || res == nullptr) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- int ret = ::SendLaunchRequest<::SendLaunchRequestSyncCb, bundle**>(
- [](const std::string& appid, bundle* request, uid_t uid,
- bundle** response) -> int {
- return aul_send_launch_request_sync_for_uid(appid.c_str(), request,
- uid, response);
- }, b, uid, res_b);
- if (ret > 0) {
- auto* val = bundle_get_val(*res_b, AUL_SVC_K_RES_VAL);
- *res = static_cast<aul_svc_result_val>(
- (val == nullptr) ? AUL_SVC_RES_NOT_OK : atoi(val));
- } else {
- ret = ::AulErrorConvert(ret);
- *res = AUL_SVC_RES_CANCEL;
- }
-
- return ret;
-}
-
-extern "C" API int aul_svc_info_create(bundle* b, aul_svc_info_h* h) {
- if (b == nullptr || h == nullptr) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- aul::ResolveInfo* resolve_info = nullptr;
- try {
- tizen_base::Bundle kb(b, false, false);
- resolve_info = aul::ResolveInfo::Manager::Create(kb);
- } catch (aul::Exception& e) {
- return AUL_SVC_RET_ERROR;
- }
-
- *h = static_cast<aul_svc_info_h>(resolve_info);
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API int aul_svc_info_get_operation(aul_svc_info_h h,
- char** operation) {
- if (h == nullptr || operation == nullptr) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- auto* info = static_cast<aul::ResolveInfo*>(h);
- auto& value = info->GetOperation();
- *operation = strdup(value.empty() ? "NULL" : value.c_str());
- if (*operation == nullptr) {
- _E("Failed to duplicate operation");
- return AUL_SVC_RET_ERROR;
- }
-
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API int aul_svc_info_get_uri(aul_svc_info_h h, char** uri) {
- if (h == nullptr || uri == nullptr) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- auto* info = static_cast<aul::ResolveInfo*>(h);
- auto& value = info->GetUri();
- *uri = strdup(value.empty() ? "NULL" : value.c_str());
- if (*uri == nullptr) {
- _E("Failed to duplicate URI");
- return AUL_SVC_RET_ERROR;
- }
-
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API int aul_svc_info_get_uri_scheme(aul_svc_info_h h,
- char** uri_scheme) {
- if (h == nullptr || uri_scheme == nullptr) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- auto* info = static_cast<aul::ResolveInfo*>(h);
- auto& value = info->GetScheme();
- *uri_scheme = strdup(value.empty() ? "NULL" : value.c_str());
- if (*uri_scheme == nullptr) {
- _E("Failed to duplicate URI scheme");
- return AUL_SVC_RET_ERROR;
- }
-
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API int aul_svc_info_get_uri_host(aul_svc_info_h h,
- char** uri_host) {
- if (h == nullptr || uri_host == nullptr) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- auto* info = static_cast<aul::ResolveInfo*>(h);
- auto& value = info->GetHost();
- *uri_host = strdup(value.empty() ? "NULL" : value.c_str());
- if (*uri_host == nullptr) {
- _E("Failed to duplicate URI host");
- return AUL_SVC_RET_ERROR;
- }
-
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API int aul_svc_info_get_mime(aul_svc_info_h h, char** mime) {
- if (h == nullptr || mime == nullptr) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- auto* info = static_cast<aul::ResolveInfo*>(h);
- auto& value = info->GetMime();
- *mime = strdup(value.empty() ? "NULL" : value.c_str());
- if (*mime == nullptr) {
- _E("Failed to duplicate MIME-Type");
- return AUL_SVC_RET_ERROR;
- }
-
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API int aul_svc_info_get_mime_type(aul_svc_info_h h,
- char** mime_type) {
- if (h == nullptr || mime_type == nullptr) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- auto* info = static_cast<aul::ResolveInfo*>(h);
- auto& value = info->GetMType();
- *mime_type = strdup(value.empty() ? "NULL" : value.c_str());
- if (*mime_type == nullptr) {
- _E("Failed to duplicate the type of MIME-Type");
- return AUL_SVC_RET_ERROR;
- }
-
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API int aul_svc_info_get_mime_subtype(aul_svc_info_h h,
- char** mime_subtype) {
- if (h == nullptr || mime_subtype == nullptr) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- auto* info = static_cast<aul::ResolveInfo*>(h);
- auto& value = info->GetSType();
- *mime_subtype = strdup(value.empty() ? "NULL" : value.c_str());
- if (*mime_subtype == nullptr) {
- _E("Failed to duplicate the subtype of MIME-Type");
- return AUL_SVC_RET_ERROR;
- }
-
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API int aul_svc_info_destroy(aul_svc_info_h h) {
- if (h == nullptr) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- auto* info = static_cast<aul::ResolveInfo*>(h);
- delete info;
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API int aul_svc_set_caller_instance_id(bundle* b,
- const char* instance_id) {
- if (b == nullptr) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- return ::SetBundle(b, AUL_K_CALLER_INSTANCE_ID, instance_id);
-}
-
-extern "C" API int aul_svc_set_comp_id(bundle* b, const char* comp_id) {
- if (b == nullptr) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- return ::SetBundle(b, AUL_K_COMPONENT_ID, comp_id);
-}
-
-extern "C" API const char *aul_svc_get_comp_id(bundle* b) {
- return bundle_get_val(b, AUL_K_COMPONENT_ID);
-}
-
-extern "C" API int aul_svc_subapp_terminate_request(bundle* b, int pid) {
- if (b == nullptr || pid < 0) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- const char* inst_id = bundle_get_val(b, AUL_K_INSTANCE_ID);
- if (inst_id == nullptr) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- char buf[512] = { 0, };
- const char* caller_inst_id = bundle_get_val(b, AUL_K_CALLER_INSTANCE_ID);
- if (caller_inst_id == nullptr) {
- int ret = aul_app_get_instance_id_bypid(getpid(), buf, sizeof(buf));
- if (ret != AUL_R_OK) {
- _E("aul_app_get_instance_id_bypid() is failed. error(%d)", ret);
- return AUL_SVC_RET_ERROR;
- }
-
- caller_inst_id = buf;
- }
-
- int cnt = 0;
- aul_app_group_foreach_group_info(caller_inst_id,
- [](aul_app_group_info_h info, void* data) {
- int* count = static_cast<int*>(data);
- (*count)++;
- }, static_cast<void*>(&cnt));
- if (cnt == 0)
- return aul_subapp_terminate_request(inst_id, pid);
-
- return aul_app_group_clear_top();
-}
-
-extern "C" API int aul_svc_send_resume_request(bundle* b, int request_code,
- aul_svc_err_cb err_cb, void *user_data) {
- return aul_svc_send_resume_request_for_uid(b, request_code, err_cb, user_data,
- getuid());
-}
-
-extern "C" API int aul_svc_send_resume_request_for_uid(bundle* b,
- int request_code, aul_svc_err_cb err_cb, void* user_data, uid_t uid) {
- if (b == nullptr || err_cb == nullptr) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- auto* cb_info = new (std::nothrow) CbInfo(request_code, nullptr, err_cb,
- user_data);
- if (cb_info == nullptr)
- _E("Out of memory");
-
- int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
- [](const std::string& appid, bundle* request, uid_t uid,
- CbInfo* info) -> int {
- return aul_send_resume_request_for_uid(appid.c_str(), request, uid,
- ErrorCb, info);
- }, b, uid, cb_info);
- if (ret < 0) {
- delete cb_info;
- ret = ::AulErrorConvert(ret);
- }
-
- return ret;
-}
-
-extern "C" API int aul_svc_get_appid_array(bundle* b, uid_t uid,
- char*** appid_array, unsigned int* len) {
- if (b == nullptr || appid_array == nullptr || len == nullptr) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- bundle_del(b, AUL_K_APPID);
- bundle_add(b, AUL_K_APPID, "@UNKNOWN");
-
- bundle* response;
- int ret = ::SendAndReceive(APP_GET_APPID_LIST, uid, b, &response);
- if (ret != AUL_SVC_RET_OK)
- return ret;
-
- tizen_base::Bundle res(response, false, true);
- auto str = res.GetString(AUL_SVC_K_URI_R_INFO);
- if (!str.empty())
- ::SetBundle(b, AUL_SVC_K_URI_R_INFO, str.c_str());
-
- auto str_arr = res.GetStringArray(AUL_K_APPID_LIST);
- if (str_arr.empty()) {
- _E("Failed to get appid list");
- return AUL_SVC_RET_ERROR;
- }
-
- *appid_array = reinterpret_cast<char**>(
- calloc(str_arr.size(), sizeof(char*)));
- if (*appid_array == nullptr) {
- _E("Out of memory");
- return AUL_SVC_RET_ENOMEM;
- }
-
- *len = str_arr.size();
-
- int i = 0;
- for (auto& appid : str_arr)
- (*appid_array)[i++] = strdup(appid.c_str());
-
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API void aul_svc_free_appid_array(char** appid_array,
- unsigned int len) {
- if (appid_array == nullptr)
- return;
-
- for (unsigned int i = 0; i < len; ++i)
- free(appid_array[i]);
-
- free(appid_array);
-}
-
-extern "C" API int aul_svc_set_window_position(bundle* b,
- int x, int y, int w, int h) {
- if (b == nullptr) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- ::SetBundle(b, AUL_K_HINT_SCREEN_POS_X, std::to_string(x).c_str());
- ::SetBundle(b, AUL_K_HINT_SCREEN_POS_Y, std::to_string(y).c_str());
- ::SetBundle(b, AUL_K_HINT_SCREEN_WIDTH, std::to_string(w).c_str());
- ::SetBundle(b, AUL_K_HINT_SCREEN_HEIGHT, std::to_string(h).c_str());
-
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API int aul_svc_get_window_position(bundle* b,
- int* x, int* y, int* w, int* h) {
- if (b == nullptr ||
- x == nullptr ||
- y == nullptr ||
- w == nullptr ||
- h == nullptr) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- char* x_str = nullptr;
- char* y_str = nullptr;
- char* w_str = nullptr;
- char* h_str = nullptr;
-
- bundle_get_str(b , AUL_K_HINT_SCREEN_POS_X, &x_str);
- bundle_get_str(b , AUL_K_HINT_SCREEN_POS_Y, &y_str);
- bundle_get_str(b , AUL_K_HINT_SCREEN_WIDTH, &w_str);
- bundle_get_str(b , AUL_K_HINT_SCREEN_HEIGHT, &h_str);
-
- if (x_str == nullptr ||
- y_str == nullptr ||
- w_str == nullptr ||
- h_str == nullptr) {
- _E("failed to get position");
- return AUL_SVC_RET_ERROR;
- }
-
- *x = atoi(x_str);
- *y = atoi(y_str);
- *w = atoi(w_str);
- *h = atoi(h_str);
-
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API int aul_svc_set_defapp(const char* op, const char* mime_type,
- const char* uri, const char* defapp) {
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API int aul_svc_set_defapp_for_uid(const char* op,
- const char* mime_type, const char* uri, const char* defapp, uid_t uid) {
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API int aul_svc_unset_defapp(const char* defapp) {
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API int aul_svc_unset_defapp_for_uid(const char* defapp, uid_t uid) {
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API int aul_svc_unset_all_defapps(void) {
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API int aul_svc_unset_all_defapps_for_uid(uid_t uid) {
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API int aul_svc_is_defapp(const char* pkg_name) {
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API int aul_svc_is_defapp_for_uid(const char* pkg_name, uid_t uid) {
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API int aul_svc_set_alias_appid(const char* alias_appid,
- const char* appid) {
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API int aul_svc_set_alias_appid_for_uid(const char* alias_appid,
- const char* appid, uid_t uid) {
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API int aul_svc_unset_alias_appid(const char* alias_appid) {
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API int aul_svc_unset_alias_appid_for_uid(const char* alias_appid,
- uid_t uid) {
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API int aul_svc_foreach_alias_info(
- void (*callback)(const char *, const char *, void *),
- void* user_data) {
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API int aul_svc_foreach_alias_info_for_uid(
- void (*callback)(const char *, const char *, void *),
- uid_t uid, void* user_data) {
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API int aul_svc_enable_alias_info(const char* appid) {
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API int aul_svc_enable_alias_info_for_uid(const char* appid,
- uid_t uid) {
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API int aul_svc_disable_alias_info(const char* appid) {
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API int aul_svc_disable_alias_info_for_uid(const char* appid,
- uid_t uid) {
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API int aul_svc_foreach_alias_info_by_appid(
- int (*callback)(const char *, const char *, void *),
- const char* appid, void* user_data) {
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API int aul_svc_foreach_alias_info_by_appid_for_uid(
- int (*callback)(const char *, const char *, void *),
- const char* appid, uid_t uid, void* user_data) {
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API int aul_svc_foreach_allowed_info(
- int (*callback)(const char *, const char *, void *),
- void* user_data) {
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API int aul_svc_foreach_allowed_info_for_uid(
- int (*callback)(const char *, const char *, void *),
- uid_t uid, void* user_data) {
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API int aul_svc_foreach_allowed_info_by_appid(
- int (*callback)(const char *, const char *, void *),
- const char* appid, void* user_data) {
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-extern "C" API int aul_svc_foreach_allowed_info_by_appid_for_uid(
- int (*callback)(const char *, const char *, void *),
- const char* appid, uid_t uid, void* user_data) {
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
+++ /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) 2016 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 <stdlib.h>
-#include <system_info.h>
-#include "aul_util.h"
-
-tizen_profile_t _get_tizen_profile(void)
-{
- static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
- char *profile_name = NULL;
-
- if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
- return profile;
-
- system_info_get_platform_string("http://tizen.org/feature/profile",
- &profile_name);
- if (profile_name == NULL)
- return profile;
-
- switch (*profile_name) {
- case 'm':
- case 'M':
- profile = TIZEN_PROFILE_MOBILE;
- break;
- case 'w':
- case 'W':
- profile = TIZEN_PROFILE_WEARABLE;
- break;
- case 't':
- case 'T':
- profile = TIZEN_PROFILE_TV;
- break;
- case 'i':
- case 'I':
- profile = TIZEN_PROFILE_IVI;
- break;
- default: /* common or unknown ==> ALL ARE COMMON. */
- profile = TIZEN_PROFILE_COMMON;
- break;
- }
- free(profile_name);
-
- return profile;
-}
+++ /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"
-
-#undef _E
-#define _E(fmt, arg...) LOGE(fmt, ##arg)
-
-#undef _D
-#define _D(fmt, arg...) LOGD(fmt, ##arg)
-
-#undef _W
-#define _W(fmt, arg...) LOGW(fmt, ##arg)
-
-#undef _I
-#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)
-#define TIZEN_FEATURE_APPSVC_ALIAS (!(_get_tizen_profile() & TIZEN_PROFILE_TV))
-
-#ifdef __cplusplus
-}
-#endif
+++ /dev/null
-/*
- * Copyright (c) 2019 - 2022 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul_watch_control.h"
-
-#include <algorithm>
-#include <list>
-#include <iterator>
-
-#include "aul_api.h"
-#include "aul_util.h"
-#include "aul_watch_control_internal.h"
-#include "include/aul.h"
-
-namespace {
-
-class WatchControl {
- public:
- WatchControl(aul_watch_control_cb cb, void* user_data)
- : cb_(cb), user_data_(user_data) {
- }
-
- void Invoke(bundle* b) {
- if (cb_)
- cb_(b, user_data_);
- }
-
- private:
- aul_watch_control_cb cb_;
- void* user_data_;
-};
-
-std::list<WatchControl*> controls;
-
-} // namespace
-
-extern "C" API int aul_watch_control_add_handler(aul_watch_control_cb callback,
- void* user_data, aul_watch_control_h* handle) {
- if (callback == nullptr || handle == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* control = new (std::nothrow) WatchControl(callback, user_data);
- if (control == nullptr) {
- _E("Out of memory");
- return AUL_R_ENOMEM;
- }
-
- controls.push_back(control);
- *handle = static_cast<aul_watch_control_h>(control);
- return AUL_R_OK;
-}
-
-extern "C" API int aul_watch_control_remove_handler(
- aul_watch_control_h handle) {
- if (handle == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* control = static_cast<WatchControl*>(handle);
- auto found = std::find(controls.begin(), controls.end(), control);
- if (found == controls.end()) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- controls.erase(found);
- delete control;
- return AUL_R_OK;
-}
-
-void aul_watch_control_invoke(bundle* b) {
- if (controls.empty())
- return;
-
- for (auto control : controls)
- control->Invoke(b);
-}
+++ /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_WATCH_CONTROL_INTERNAL_H__
-#define __AUL_WATCH_CONTROL_INTERNAL_H__
-
-#include <bundle.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void aul_watch_control_invoke(bundle *b);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __AUL_WATCH_CONTROL_INTERNAL_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2018 - 2022 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul_watchdog.h"
-
-#include <glib.h>
-
-#include "app_request.h"
-#include "aul_api.h"
-#include "aul_util.h"
-#include "include/aul.h"
-#include "include/aul_error.h"
-#include "aul/common/exception.hh"
-
-using namespace aul;
-
-namespace {
-using namespace aul::internal;
-
-class WatchdogContext {
- public:
- WatchdogContext() = default;
-
- ~WatchdogContext() {
- Stop();
-
- if (enabled_) {
- try {
- Disable();
- } catch (const Exception& e) {
- _E("Exception occurs. error(%d)", e.GetErrorCode());
- }
- }
- }
-
- void Enable() {
- if (enabled_) {
- _W("Already enabled");
- return;
- }
-
- int ret = AppRequest(WATCHDOG_ENABLE, getuid())
- .SendCmdOnly(AUL_SOCK_NOREPLY);
- if (ret < 0)
- THROW(aul_error_convert(ret));
-
- enabled_ = true;
- _D("Enabled");
- }
-
- void Disable() {
- if (!enabled_)
- THROW(AUL_R_ERROR);
-
- int ret = AppRequest(WATCHDOG_DISABLE, getuid())
- .SendCmdOnly(AUL_SOCK_NOREPLY);
- if (ret < 0)
- THROW(aul_error_convert(ret));
-
- enabled_ = false;
- _D("Disabled");
- }
-
- void Kick() {
- if (!enabled_)
- THROW(AUL_R_ERROR);
-
- int ret = AppRequest(WATCHDOG_KICK, getuid())
- .SendCmdOnly(AUL_SOCK_NOREPLY);
- if (ret < 0)
- THROW(aul_error_convert(ret));
-
- Stop();
- Start(interval_);
- _D("Kicked");
- }
-
- void Start(unsigned int interval) {
- _D("Interval: %u", interval);
- if (interval == 0) {
- _E("Invalid parameter");
- return;
- }
-
- if (timer_ != 0) {
- _E("Already started");
- return;
- }
-
- enabled_ = true;
- interval_ = interval;
- timer_ = g_timeout_add(interval,
- [](gpointer user_data) -> gboolean {
- auto* handle = static_cast<WatchdogContext*>(user_data);
- try {
- handle->Ping();
- } catch (const Exception& e) {
- _E("Exception occurs. error(%d)", e.GetErrorCode());
- }
-
- return G_SOURCE_CONTINUE;
- }, this);
-
- try {
- Ping();
- } catch (const Exception& e) {
- _E("Exception occurs. error(%d)", e.GetErrorCode());
- }
- }
-
- void Stop() {
- if (timer_ == 0)
- return;
-
- g_source_remove(timer_);
- timer_ = 0;
- }
-
- bool IsEnabled() const {
- return enabled_;
- }
-
- private:
- void Ping() {
- int ret = AppRequest(WATCHDOG_PING, getuid())
- .SendCmdOnly(AUL_SOCK_NOREPLY);
- if (ret < 0)
- THROW(aul_error_convert(ret));
-
- _D("Ping");
- }
-
- private:
- bool enabled_ = false;
- unsigned int interval_ = 0;
- guint timer_ = 0;
-};
-
-WatchdogContext context;
-
-} // namespace
-
-extern "C" API int aul_watchdog_enable(void) {
- try {
- context.Enable();
- } catch (const Exception& e) {
- _E("Exception occurs. error(%d)", e.GetErrorCode());
- return e.GetErrorCode();
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_watchdog_disable(void) {
- try {
- context.Disable();
- } catch (const Exception& e) {
- if (context.IsEnabled())
- _E("Exception occurs. error(%d)", e.GetErrorCode());
-
- return e.GetErrorCode();
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_watchdog_kick(void) {
- try {
- context.Kick();
- } catch (const Exception& e) {
- _E("Exception occurs. error(%d)", e.GetErrorCode());
- return e.GetErrorCode();
- }
-
- return AUL_R_OK;
-}
-
-extern "C" void aul_watchdog_start(unsigned int interval) {
- context.Start(interval);
-}
-
-extern "C" void aul_watchdog_stop(void) {
- context.Stop();
-}
+++ /dev/null
-/*
- * Copyright (c) 2017 - 2021 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 <gio/gio.h>
-#include <glib.h>
-#include <stdbool.h>
-#include <stdio.h>
-
-#include <bundle_cpp.h>
-
-#include <memory>
-#include <mutex>
-#include <string>
-
-#include "app_request.h"
-#include "aul_api.h"
-#include "aul_util.h"
-#include "include/aul.h"
-#include "include/aul_app_com.h"
-#include "include/aul_cmd.h"
-#include "include/aul_window.h"
-#include "launch.h"
-
-using namespace aul;
-using namespace aul::internal;
-
-namespace {
-
-constexpr const char kWmBusName[] = "org.enlightenment.wm";
-constexpr const char kWmObjectPath[] = "/org/enlightenment/wm";
-constexpr const char kWmInterfaceName[] = "org.enlightenment.wm.proc";
-constexpr const char kWmMethodNameInfo[] = "GetVisibleWinInfo";
-constexpr const char kWmMethodNameFocus[] = "GetFocusProc";
-constexpr const unsigned int kWmDbusTimeout = 5000;
-
-GDBusConnection* system_conn;
-
-GDBusConnection* GetConn() {
- if (system_conn == nullptr) {
- GError* error = nullptr;
- system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &error);
- if (system_conn == nullptr) {
- _E("g_bus_get_sync() is failed. error(%s)",
- error ? error->message : "Unknown");
- g_clear_error(&error);
- return nullptr;
- }
- }
-
- return system_conn;
-}
-
-class WindowInfo {
- public:
- WindowInfo(unsigned int rid, int x, int y, int w, int h,
- bool alpha, int visibility, bool focused, int pid, int ppid,
- int apid, int noti_level, bool opaque)
- : rid_(rid), x_(x), y_(y), w_(w), h_(h), alpha_(alpha),
- visibility_(visibility), focused_(focused), pid_(pid),
- ppid_(ppid), apid_(apid), noti_level_(noti_level), opaque_(opaque) {
- }
-
- unsigned int GetResourceId() const {
- return rid_;
- }
-
- int GetPositionX() const {
- return x_;
- }
-
- int GetPositionY() const {
- return y_;
- }
-
- int GetWidth() const {
- return w_;
- }
-
- int GetHeight() const {
- return h_;
- }
-
- bool HasAlpha() const {
- return alpha_;
- }
-
- int GetVisibility() const {
- return visibility_;
- }
-
- bool IsFocused() const {
- return focused_;
- }
-
- int GetPid() const {
- return pid_;
- }
-
- int GetParentPid() const {
- return ppid_;
- }
-
- int GetAncestorPid() const {
- return apid_;
- }
-
- int GetNotificationLevel() const {
- return noti_level_;
- }
-
- bool IsOpaque() const {
- return opaque_;
- }
-
- private:
- unsigned int rid_;
- int x_;
- int y_;
- int w_;
- int h_;
- bool alpha_;
- int visibility_;
- bool focused_;
- int pid_;
- int ppid_;
- int apid_;
- int noti_level_;
- bool opaque_;
-};
-
-void WindowInfoDestroyFunc(gpointer data) {
- auto* info = static_cast<WindowInfo*>(data);
- if (info == nullptr)
- return;
-
- delete info;
-}
-
-class WindowEventListener {
- public:
- WindowEventListener() = default;
-
- ~WindowEventListener() {
- Deregister();
- }
-
- int Register(aul_window_event_cb cb, void* user_data) {
- std::lock_guard<std::recursive_mutex> lock(GetMutex());
- cb_ = cb;
- user_data_ = user_data;
-
- if (conn_ != nullptr)
- return AUL_R_OK;
-
- int ret = aul_app_com_create_async("aul_window_event", nullptr,
- AppComMessageCb, this, &conn_);
- if (ret != AUL_R_OK) {
- _E("aul_app_com_create_async() is failed. error(%d)", ret);
- return ret;
- }
-
- return AUL_R_OK;
- }
-
- void Deregister() {
- std::lock_guard<std::recursive_mutex> lock(GetMutex());
- cb_ = nullptr;
- user_data_ = nullptr;
-
- if (conn_ == nullptr)
- return;
-
- aul_app_com_leave(conn_);
- conn_ = nullptr;
- }
-
- private:
- static int AppComMessageCb(const char* endpoint, aul_app_com_result_e res,
- bundle* envelope, void* user_data) {
- tizen_base::Bundle b(envelope, false, false);
- std::string event_name = b.GetString(AUL_K_EVENT_NAME);
- std::string appid = b.GetString(AUL_K_APPID);
- int wid = std::stoi(b.GetString(AUL_K_WID));
- int pid = std::stoi(b.GetString(AUL_K_PID));
-
- auto* handle = static_cast<WindowEventListener*>(user_data);
- std::lock_guard<std::recursive_mutex> lock(handle->GetMutex());
- if (handle->cb_) {
- handle->cb_(event_name.c_str(), appid.c_str(), wid, pid,
- handle->user_data_);
- }
-
- return 0;
- }
-
- std::recursive_mutex& GetMutex() const {
- return mutex_;
- }
-
- private:
- aul_app_com_connection_h conn_ = nullptr;
- aul_window_event_cb cb_ = nullptr;
- void* user_data_ = nullptr;
- mutable std::recursive_mutex mutex_;
-};
-
-WindowEventListener listener;
-
-} // namespace
-
-extern "C" API int aul_window_stack_get(aul_window_stack_h* handle) {
- if (handle == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- GDBusConnection* conn = GetConn();
- if (conn == nullptr)
- return AUL_R_ERROR;
-
- auto* msg = g_dbus_message_new_method_call(kWmBusName,
- kWmObjectPath, kWmInterfaceName, kWmMethodNameInfo);
- if (msg == nullptr) {
- _E("g_dbus_message_new_method_call() is faield");
- return AUL_R_ERROR;
- }
- std::unique_ptr<GDBusMessage, decltype(g_object_unref)*> msg_auto(
- msg, g_object_unref);
-
- GError* error = nullptr;
- auto* reply = g_dbus_connection_send_message_with_reply_sync(conn, msg,
- G_DBUS_SEND_MESSAGE_FLAGS_NONE, kWmDbusTimeout, nullptr, nullptr, &error);
- if (reply == nullptr || error != nullptr) {
- _E("g_dbus_connection_send_message_with_reply_sync() is failed. error(%s)",
- error ? error->message : "Unknown");
- g_clear_error(&error);
- return AUL_R_ERROR;
- }
- std::unique_ptr<GDBusMessage, decltype(g_object_unref)*> reply_auto(
- reply, g_object_unref);
-
- auto* body = g_dbus_message_get_body(reply);
- if (body == nullptr) {
- _E("g_dbus_message_get_body() is failed");
- return AUL_R_ERROR;
- }
-
- unsigned int rid = 0;
- int x = -1;
- int y = -1;
- int w = -1;
- int h = -1;
- gboolean alpha = FALSE;
- int visibility = -1;
- gboolean focused = FALSE;
- int pid = -1;
- int ppid = -1;
- int apid = -1;
- int noti_level = -1;
- gboolean opaque = FALSE;
-
- GVariantIter* iter = nullptr;
- g_variant_get(body, "(a(uiiiibibiiiib))", &iter);
- if (iter == nullptr)
- return AUL_R_ERROR;
-
- std::unique_ptr<GVariantIter, decltype(g_variant_iter_free)*> iter_auto(
- iter, g_variant_iter_free);
-
- GList* list = nullptr;
- while (g_variant_iter_loop(iter, "(uiiiibibiiiib)",
- &rid,
- &x,
- &y,
- &w,
- &h,
- &alpha,
- &visibility,
- &focused,
- &pid,
- &ppid,
- &apid,
- ¬i_level,
- &opaque)) {
- auto* info = new (std::nothrow) WindowInfo(rid, x, y, w, h,
- alpha ? true : false, visibility, focused ? true : false,
- pid, ppid, apid, noti_level, opaque ? true : false);
- if (info == nullptr) {
- _E("Out of memory");
- g_list_free_full(list, WindowInfoDestroyFunc);
- return AUL_R_ENOMEM;
- }
-
- list = g_list_append(list, info);
- }
-
- *handle = static_cast<aul_window_stack_h>(list);
- return AUL_R_OK;
-}
-
-extern "C" API int aul_window_stack_del(aul_window_stack_h handle) {
- if (handle == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* list = static_cast<GList*>(handle);
- g_list_free_full(list, WindowInfoDestroyFunc);
- return AUL_R_OK;
-}
-
-extern "C" API int aul_window_stack_foreach(aul_window_stack_h handle,
- void (*iter_cb)(aul_window_info_h info, void* data), void* data) {
- if (handle == nullptr || iter_cb == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* iter = static_cast<GList*>(handle);
- while (iter) {
- iter_cb(static_cast<aul_window_info_h>(iter->data), data);
- iter = g_list_next(iter);
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_window_stack_info_get_resource_id(aul_window_info_h info,
- unsigned int* rid) {
- if (info == nullptr || rid == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* handle = static_cast<WindowInfo*>(info);
- *rid = handle->GetResourceId();
- return AUL_R_OK;
-}
-
-extern "C" API int aul_window_info_get_pid(aul_window_info_h info, int* pid) {
- if (info == nullptr || pid == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* handle = static_cast<WindowInfo*>(info);
- *pid = handle->GetPid();
- return AUL_R_OK;
-}
-
-extern "C" API int aul_window_info_get_parent_pid(aul_window_info_h info,
- int* ppid) {
- if (info == nullptr || ppid == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* handle = static_cast<WindowInfo*>(info);
- *ppid = handle->GetParentPid();
- return AUL_R_OK;
-}
-
-extern "C" API int aul_window_info_get_ancestor_pid(aul_window_info_h info,
- int* apid) {
- if (info == nullptr || apid == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* handle = static_cast<WindowInfo*>(info);
- *apid = handle->GetAncestorPid();
- return AUL_R_OK;
-}
-
-extern "C" API int aul_window_info_get_visibility(aul_window_info_h info,
- int* visibility) {
- if (info == nullptr || visibility == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* handle = static_cast<WindowInfo*>(info);
- *visibility = handle->GetVisibility();
- return AUL_R_OK;
-}
-
-extern "C" API int aul_window_info_has_alpha(aul_window_info_h info,
- bool* alpha) {
- if (info == nullptr || alpha == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* handle = static_cast<WindowInfo*>(info);
- *alpha = handle->HasAlpha();
- return AUL_R_OK;
-}
-
-extern "C" API int aul_window_info_is_focused(aul_window_info_h info,
- bool* focused) {
- if (info == nullptr || focused == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* handle = static_cast<WindowInfo*>(info);
- *focused = handle->IsFocused();
- return AUL_R_OK;
-}
-
-extern "C" API int aul_window_info_get_geometry(aul_window_info_h info,
- int* x, int* y, int* w, int* h) {
- if (info == nullptr ||
- x == nullptr ||
- y == nullptr ||
- w == nullptr ||
- h == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* handle = static_cast<WindowInfo*>(info);
- *x = handle->GetPositionX();
- *y = handle->GetPositionY();
- *w = handle->GetWidth();
- *h = handle->GetHeight();
- return AUL_R_OK;
-}
-
-extern "C" API int aul_window_info_get_notification_level(
- aul_window_info_h info, aul_window_notification_level_e* level) {
- if (info == nullptr || level == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* handle = static_cast<WindowInfo*>(info);
- *level = static_cast<aul_window_notification_level_e>(
- handle->GetNotificationLevel());
- return AUL_R_OK;
-}
-
-extern "C" API int aul_window_info_get_opaque(aul_window_info_h info,
- bool* opaque) {
- if (info == nullptr || opaque == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* handle = static_cast<WindowInfo*>(info);
- *opaque = handle->IsOpaque();
- return AUL_R_OK;
-}
-
-extern "C" API int aul_window_get_focused_pid(pid_t* pid) {
- if (pid == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- GDBusConnection* conn = GetConn();
- if (conn == nullptr)
- return AUL_R_ERROR;
-
- auto* msg = g_dbus_message_new_method_call(kWmBusName,
- kWmObjectPath, kWmInterfaceName, kWmMethodNameFocus);
- if (msg == nullptr) {
- _E("g_dbus_message_new_method_call() is failed");
- return AUL_R_ERROR;
- }
- std::unique_ptr<GDBusMessage, decltype(g_object_unref)*> msg_auto(
- msg, g_object_unref);
-
- GError* error = nullptr;
- auto* reply = g_dbus_connection_send_message_with_reply_sync(conn, msg,
- G_DBUS_SEND_MESSAGE_FLAGS_NONE, kWmDbusTimeout, nullptr, nullptr,
- &error);
- if (reply == nullptr || error != nullptr) {
- _E("g_dbus_connection_send_message_with_reply_sync() is failed. error(%s)",
- error ? error->message : "Unknown");
- g_clear_error(&error);
- return AUL_R_ERROR;
- }
- std::unique_ptr<GDBusMessage, decltype(g_object_unref)*> reply_auto(
- reply, g_object_unref);
-
- auto* body = g_dbus_message_get_body(reply);
- if (body == nullptr) {
- _E("g_dbus_message_get_body() is failed");
- return AUL_R_ERROR;
- }
-
- gint focused_pid = -1;
- g_variant_get(body, "(i)", &focused_pid);
- *pid = static_cast<pid_t>(focused_pid);
- _W("Result = %d", focused_pid);
- return AUL_R_OK;
-}
-
-extern "C" API int aul_window_attach(const char* parent_appid,
- const char* child_appid) {
- if (parent_appid == nullptr || child_appid == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- tizen_base::Bundle b {
- { AUL_K_PARENT_APPID, parent_appid },
- { AUL_K_CHILD_APPID, child_appid }
- };
- int ret = AppRequest(APP_WINDOW_ATTACH, getuid())
- .With(b)
- .SendSimply();
- if (ret < 0) {
- _E("Failed to send request. error(%d)", ret);
- return ret;
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_window_detach(const char* child_appid) {
- if (child_appid == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- tizen_base::Bundle b {{ AUL_K_CHILD_APPID, child_appid }};
- int ret = AppRequest(APP_WINDOW_DETACH, getuid())
- .With(b)
- .SendSimply();
- if (ret < 0) {
- _E("Failed to send request. error(%d)", ret);
- return ret;
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_window_attach_below(const char* parent_appid,
- const char* child_appid) {
- if (parent_appid == nullptr || child_appid == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- tizen_base::Bundle b {
- { AUL_K_PARENT_APPID, parent_appid },
- { AUL_K_CHILD_APPID, child_appid }
- };
- int ret = AppRequest(APP_WINDOW_ATTACH_BELOW, getuid())
- .With(b)
- .SendSimply();
- if (ret < 0) {
- _E("Failed to send request. error(%d)", ret);
- return ret;
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_window_register_event_cb(aul_window_event_cb callback,
- void* user_data) {
- if (callback == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- int ret = listener.Register(callback, user_data);
- if (ret != AUL_R_OK)
- return ret;
-
- return AUL_R_OK;
-}
-
-extern "C" API void aul_window_deregister_event_cb(void) {
- listener.Deregister();
-}
+++ /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 <pthread.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/syscall.h>
-#include <fcntl.h>
-#include <glib.h>
-#include <gio/gio.h>
-
-#include "aul.h"
-#include "aul_util.h"
-#include "aul_sock.h"
-#include "aul_worker.h"
-
-#define DEFAULT_INTERVAL 5000
-
-struct job_s {
- char *name;
- GIOChannel *channel;
- guint tag;
- void *callback;
- void *user_data;
-};
-
-struct anr_timer_s {
- guint tag;
- gint64 start_time;
- GQueue *cmd_queue;
-};
-
-struct aul_worker_s {
- char *name;
- GThread *thread;
- GMutex mutex;
- GCond cond;
- GMainContext *context;
- GMainLoop *loop;
- GList *jobs;
- struct anr_timer_s *anr_timer;
-};
-
-static void __destroy_anr_timer(struct anr_timer_s *timer)
-{
- g_queue_free(timer->cmd_queue);
- free(timer);
-}
-
-static struct anr_timer_s *__create_anr_timer(void)
-{
- struct anr_timer_s *timer;
-
- timer = calloc(1, sizeof(struct anr_timer_s));
- if (!timer) {
- _E("Out of memory");
- return NULL;
- }
-
- timer->cmd_queue = g_queue_new();
- if (!timer->cmd_queue) {
- _E("Failed to create GQueue");
- __destroy_anr_timer(timer);
- return NULL;
- }
-
- return timer;
-}
-
-static void __destroy_job(gpointer data)
-{
- struct job_s *job = (struct job_s *)data;
- GSource *source;
- GMainContext *context;
-
- if (job->channel)
- g_io_channel_unref(job->channel);
-
- if (job->tag) {
- context = g_main_context_get_thread_default();
- source = g_main_context_find_source_by_id(context, job->tag);
- _W("GMainContext(%p), GSource(%p)", context, source);
- if (source && !g_source_is_destroyed(source)) {
- _W("Destroy GSource(%p)", source);
- g_source_destroy(source);
- }
- }
-
- free(job->name);
- free(job);
-}
-
-static struct job_s *__create_job(const char *name,
- GIOChannel *channel,
- void *callback,
- void *user_data)
-{
- struct job_s *job;
-
- job = calloc(1, sizeof(struct job_s));
- if (!job) {
- _E("Failed to create job");
- return NULL;
- }
-
- job->name = strdup(name);
- if (!job->name) {
- _E("Failed to duplicate job name");
- __destroy_job(job);
- return NULL;
- }
-
- job->channel = channel;
- job->callback = callback;
- job->user_data = user_data;
-
- return job;
-}
-
-static int __set_comm(const char *name)
-{
- int fd;
- ssize_t bytes_written;
- char path[PATH_MAX];
- pid_t tid = syscall(__NR_gettid);
-
- _I("[%s] TID(%d)", name, tid);
- snprintf(path, sizeof(path), "/proc/%d/comm", tid);
- fd = open(path, O_WRONLY);
- if (fd < 0) {
- _E("Failed to open %s. error(%d)", path, errno);
- return -1;
- }
-
- bytes_written = write(fd, name, strlen(name) + 1);
- if (bytes_written < 0) {
- _E("Failed to write name(%s)", name);
- close(fd);
- return -1;
- }
-
- close(fd);
-
- return 0;
-}
-
-static GIOCondition __convert_aul_io_condition(int condition)
-{
- GIOCondition cond = 0;
-
- if (condition & AUL_IO_IN)
- cond |= G_IO_IN;
- if (condition & AUL_IO_OUT)
- cond |= G_IO_OUT;
- if (condition & AUL_IO_PRI)
- cond |= G_IO_PRI;
- if (condition & AUL_IO_HUP)
- cond |= G_IO_HUP;
- if (condition & AUL_IO_ERR)
- cond |= G_IO_ERR;
- if (condition & AUL_IO_NVAL)
- cond |= G_IO_NVAL;
-
- return cond;
-}
-
-static int __convert_g_io_condition(GIOCondition condition)
-{
- int cond = 0;
-
- if (condition & G_IO_IN)
- cond |= AUL_IO_IN;
- if (condition & G_IO_OUT)
- cond |= AUL_IO_OUT;
- if (condition & G_IO_PRI)
- cond |= AUL_IO_PRI;
- if (condition & G_IO_HUP)
- cond |= AUL_IO_HUP;
- if (condition & G_IO_ERR)
- cond |= AUL_IO_ERR;
- if (condition & G_IO_NVAL)
- cond |= AUL_IO_NVAL;
-
- return cond;
-}
-
-static gboolean __io_job_handler(GIOChannel *io, GIOCondition condition,
- gpointer data)
-{
- int fd = g_io_channel_unix_get_fd(io);
- struct job_s *job = (struct job_s *)data;
- aul_worker_io_job_cb callback;
- GSource *source;
- int cond;
-
- source = g_main_current_source();
- if (!source || g_source_is_destroyed(source)) {
- _E("[__JOB__] GSource(%p) is destroyed", source);
- return G_SOURCE_REMOVE;
- }
-
- cond = __convert_g_io_condition(condition);
- callback = (aul_worker_io_job_cb)job->callback;
- if (callback(fd, cond, job->user_data))
- return G_SOURCE_CONTINUE;
-
- _I("[__JOB__] name(%s)", job->name);
- job->tag = 0;
-
- return G_SOURCE_REMOVE;
-}
-
-int aul_worker_add_io_job(aul_worker_h handle, const char *job_name,
- int fd, int condition, bool do_close,
- aul_worker_io_job_cb callback,
- void *user_data)
-{
- GIOCondition cond = __convert_aul_io_condition(condition);
- struct aul_worker_s *worker = (struct aul_worker_s *)handle;
- struct job_s *job;
- GIOChannel *channel;
- GSource *source;
-
- if (!worker || !job_name || fd < 0 || !callback) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- channel = g_io_channel_unix_new(fd);
- if (!channel) {
- _E("Failed to create GIOChannel");
- if (do_close)
- close(fd);
-
- return AUL_R_ENOMEM;
- }
-
- g_io_channel_set_close_on_unref(channel, do_close);
- source = g_io_create_watch(channel, cond);
- if (!source) {
- _E("Failed to create GSource");
- g_io_channel_unref(channel);
- return AUL_R_ENOMEM;
- }
-
- job = __create_job(job_name, channel, callback, user_data);
- if (!job) {
- _E("Failed to create job(%s)", job_name);
- g_source_unref(source);
- g_io_channel_unref(channel);
- return AUL_R_ENOMEM;
- }
-
- g_source_set_callback(source, (GSourceFunc)__io_job_handler, job, NULL);
- g_source_set_priority(source, G_PRIORITY_DEFAULT);
-
- g_mutex_lock(&worker->mutex);
- worker->jobs = g_list_append(worker->jobs, job);
- job->tag = g_source_attach(source, worker->context);
- _W("GMainContext(%p), GSource(%p)", worker->context, source);
- g_mutex_unlock(&worker->mutex);
-
- g_source_unref(source);
-
- return AUL_R_OK;
-}
-
-void aul_worker_remove_io_job(aul_worker_h handle, int fd)
-{
- struct aul_worker_s *worker = handle;
- struct job_s *job;
- GList *iter;
-
- if (worker == NULL || fd < 0) {
- _E("Invalid parameter");
- return;
- }
-
- g_mutex_lock(&worker->mutex);
- iter = worker->jobs;
- while (iter != NULL) {
- job = iter->data;
- iter = g_list_next(iter);
- if (job->channel == NULL)
- continue;
-
- if (g_io_channel_unix_get_fd(job->channel) == fd) {
- worker->jobs = g_list_remove(worker->jobs, job);
- __destroy_job(job);
- break;
- }
- }
- g_mutex_unlock(&worker->mutex);
-}
-
-void aul_worker_destroy(aul_worker_h handle)
-{
- struct aul_worker_s *worker = (struct aul_worker_s *)handle;
-
- if (!worker)
- return;
-
- if (worker->thread) {
- if (g_main_loop_is_running(worker->loop))
- g_main_loop_quit(worker->loop);
- else
- _E("GMainLoop is not running");
-
- g_thread_join(worker->thread);
- }
-
- if (worker->loop)
- g_main_loop_unref(worker->loop);
-
- if (worker->context)
- g_main_context_unref(worker->context);
-
- g_cond_clear(&worker->cond);
- g_mutex_clear(&worker->mutex);
-
- __destroy_anr_timer(worker->anr_timer);
- free(worker->name);
- free(worker);
-}
-
-static gboolean __notify_cb(gpointer data)
-{
- struct aul_worker_s *worker = (struct aul_worker_s *)data;
-
- _W("GMainLoop is started");
- g_mutex_lock(&worker->mutex);
- g_cond_signal(&worker->cond);
- g_mutex_unlock(&worker->mutex);
-
- return G_SOURCE_REMOVE;
-}
-
-static gpointer __worker_thread_loop(gpointer data)
-{
- struct aul_worker_s *worker = (struct aul_worker_s *)data;
- struct anr_timer_s *anr_timer = worker->anr_timer;
- GSource *source;
-
- g_mutex_lock(&worker->mutex);
- __set_comm(worker->name);
-
- source = g_idle_source_new();
- if (!source) {
- _E("Failed to create GSource");
- g_cond_signal(&worker->cond);
- g_mutex_unlock(&worker->mutex);
- return NULL;
- }
-
- g_source_set_callback(source, (GSourceFunc)__notify_cb, worker, NULL);
- g_source_set_priority(source, G_PRIORITY_HIGH);
- g_source_attach(source, worker->context);
- g_source_unref(source);
-
- g_main_context_push_thread_default(worker->context);
- g_mutex_unlock(&worker->mutex);
- g_main_loop_run(worker->loop);
-
- g_mutex_lock(&worker->mutex);
- if (anr_timer->tag) {
- source = g_main_context_find_source_by_id(worker->context,
- anr_timer->tag);
- if (source && !g_source_is_destroyed(source))
- g_source_destroy(source);
-
- anr_timer->tag = 0;
- }
-
- g_list_free_full(worker->jobs, __destroy_job);
- g_main_context_pop_thread_default(worker->context);
- g_mutex_unlock(&worker->mutex);
- _W("Shut down worker");
-
- return NULL;
-}
-
-aul_worker_h aul_worker_create(const char *name)
-{
- struct aul_worker_s *worker;
-
- if (!name) {
- _E("Invalid parameter");
- return NULL;
- }
-
- worker = calloc(1, sizeof(struct aul_worker_s));
- if (!worker) {
- _E("Out of memory");
- return NULL;
- }
-
- g_mutex_init(&worker->mutex);
- g_cond_init(&worker->cond);
-
- worker->name = strdup(name);
- if (!worker->name) {
- _E("Failed to duplicate name");
- aul_worker_destroy(worker);
- return NULL;
- }
-
- worker->anr_timer = __create_anr_timer();
- if (!worker->anr_timer) {
- _E("Failed to create ANR timer");
- aul_worker_destroy(worker);
- return NULL;
- }
-
- worker->context = g_main_context_new();
- if (!worker->context) {
- _E("Failed to create GMainContext");
- aul_worker_destroy(worker);
- return NULL;
- }
- _W("GMainContext(%p)", worker->context);
-
- worker->loop = g_main_loop_new(worker->context, FALSE);
- if (!worker->loop) {
- _E("Failed to create GMainLoop");
- aul_worker_destroy(worker);
- return NULL;
- }
-
- g_mutex_lock(&worker->mutex);
-
- worker->thread = g_thread_new(name, __worker_thread_loop, worker);
- if (!worker->thread) {
- _E("Failed to create worker thread");
- g_mutex_unlock(&worker->mutex);
- aul_worker_destroy(worker);
- return NULL;
- }
-
- while (!g_main_loop_is_running(worker->loop))
- g_cond_wait(&worker->cond, &worker->mutex);
-
- g_mutex_unlock(&worker->mutex);
-
- return worker;
-}
-
-static gboolean __timeout_cb(gpointer data)
-{
- struct aul_worker_s *worker = data;
- struct anr_timer_s *anr_timer;
- char buf[12];
- bundle *b;
- int cmd;
-
- _E("Application Not Responding");
- g_mutex_lock(&worker->mutex);
- anr_timer = worker->anr_timer;
- anr_timer->tag = 0;
- anr_timer->start_time = 0;
-
- b = bundle_create();
- while (!g_queue_is_empty(anr_timer->cmd_queue)) {
- cmd = GPOINTER_TO_INT(g_queue_pop_head(anr_timer->cmd_queue));
- snprintf(buf, sizeof(buf), "%d", cmd);
- bundle_del(b, AUL_K_COMMAND);
- bundle_add_str(b, AUL_K_COMMAND, buf);
- aul_sock_send_bundle(AUL_UTIL_PID, getuid(), ANR_NOTIFY, b,
- AUL_SOCK_NOREPLY);
- }
- bundle_free(b);
- g_mutex_unlock(&worker->mutex);
-
- return G_SOURCE_REMOVE;
-}
-
-int aul_worker_add_anr_timer(aul_worker_h handle, int cmd, unsigned int timeout)
-{
- struct aul_worker_s *worker = handle;
- struct anr_timer_s *anr_timer;
- unsigned int elapsed_time;
- unsigned int interval;
- gint64 current_time;
- GSource *source;
-
- if (!worker) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&worker->mutex);
-
- anr_timer = worker->anr_timer;
- if (anr_timer->tag) {
- source = g_main_context_find_source_by_id(worker->context,
- anr_timer->tag);
- g_source_destroy(source);
- anr_timer->tag = 0;
- }
-
- g_queue_push_tail(anr_timer->cmd_queue, GINT_TO_POINTER(cmd));
-
- current_time = g_get_monotonic_time();
- if (anr_timer->start_time == 0) {
- interval = timeout;
- anr_timer->start_time = current_time;
- } else {
- elapsed_time = (unsigned int)((current_time -
- anr_timer->start_time) / 1000);
- interval = timeout + (DEFAULT_INTERVAL - elapsed_time);
- anr_timer->start_time = current_time;
- }
-
- source = g_timeout_source_new(interval);
- g_source_set_callback(source, (GSourceFunc)__timeout_cb, worker, NULL);
- anr_timer->tag = g_source_attach(source, worker->context);
- g_source_unref(source);
-
- return AUL_R_OK;
-}
-
-int aul_worker_remove_anr_timer(aul_worker_h handle)
-{
- struct aul_worker_s *worker = handle;
- struct anr_timer_s *anr_timer;
- GSource *source;
-
- if (!worker) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&worker->mutex);
-
- anr_timer = worker->anr_timer;
- if (g_queue_is_empty(anr_timer->cmd_queue)) {
- _E("Queue is empty");
- return AUL_R_ERROR;
- }
-
- g_queue_pop_head(anr_timer->cmd_queue);
- if (!g_queue_is_empty(anr_timer->cmd_queue))
- return AUL_R_OK;
-
- if (anr_timer->tag) {
- source = g_main_context_find_source_by_id(worker->context,
- anr_timer->tag);
- if (source && !g_source_is_destroyed(source))
- g_source_destroy(source);
-
- anr_timer->tag = 0;
- anr_timer->start_time = 0;
- }
-
- return AUL_R_OK;
-}
+++ /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 enum {
- AUL_IO_IN = 0x01,
- AUL_IO_OUT = 0x02,
- AUL_IO_PRI = 0x04,
- AUL_IO_ERR = 0x10,
- AUL_IO_HUP = 0x20,
- AUL_IO_NVAL = 0x40,
-} aul_io_condition_e;
-
-typedef bool (*aul_worker_io_job_cb)(int fd, int condition, 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, int condition, bool do_close,
- aul_worker_io_job_cb callback, void *user_data);
-
-void aul_worker_remove_io_job(aul_worker_h handle, int fd);
-
-int aul_worker_add_anr_timer(aul_worker_h handle,
- int cmd, unsigned int timeout);
-
-int aul_worker_remove_anr_timer(aul_worker_h handle);
-
-#endif /* __AUL_WORKER_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2023 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 "cpu_inheritance.hh"
-
-#include <cpu-boosting.h>
-
-#include "include/aul_cmd.h"
-#include "aul_util.h"
-
-namespace aul {
-namespace internal {
-namespace {
-
-constexpr const char DEST_PROCESS[] = "amd";
-
-} // namespace
-
-CPUInheritance::CPUInheritance(pid_t pid, int cmd) {
- if (pid == -2 && IsLaunchRequest(cmd)) {
- int ret = resource_set_cpu_inheritance(gettid(),
- const_cast<char*>(DEST_PROCESS), -1);
- if (ret != 0)
- _E("resource_set_cpu_inheritance() is failed. error(%d)", ret);
- else
- inherited_ = true;
- }
-}
-
-CPUInheritance::CPUInheritance() {
- int ret = resource_set_cpu_inheritance(gettid(),
- const_cast<char*>(DEST_PROCESS), -1);
- if (ret != 0)
- _E("resource_set_cpu_inheritance() is failed. error(%d)", ret);
- else
- inherited_ = true;
-}
-
-CPUInheritance::~CPUInheritance() {
- if (inherited_) {
- int ret = resource_clear_cpu_inheritance(gettid(),
- const_cast<char*>(DEST_PROCESS));
- if (ret != 0)
- _E("resource_clear_cpu_inheritance() is failed. error(%d)", ret);
- }
-}
-
-bool CPUInheritance::IsLaunchRequest(int cmd) {
- switch (cmd) {
- case APP_START:
- case APP_OPEN:
- case APP_RESUME:
- case APP_START_RES:
- case APP_START_ASYNC:
- case APP_SEND_LAUNCH_REQUEST_SYNC:
- case RPC_PORT_PREPARE_STUB:
- return true;
- default:
- return false;
- }
-}
-
-} // namespace internal
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2023 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 CPU_INHERITANCE_HH_
-#define CPU_INHERITANCE_HH_
-
-#include <sys/types.h>
-
-namespace aul {
-namespace internal {
-
-class CPUInheritance {
- public:
- CPUInheritance(pid_t pid, int cmd);
- CPUInheritance();
- ~CPUInheritance();
-
- private:
- static bool IsLaunchRequest(int cmd);
-
- private:
- bool inherited_ = false;
-};
-
-} // namespace internal
-} // namespace aul
-
-#endif // CPU_INHERITANCE_HH_
+++ /dev/null
-/*
- * Copyright (c) 2000 - 2021 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 <bundle_internal.h>
-#include <ctype.h>
-#include <dirent.h>
-#include <fcntl.h>
-#include <gio/gio.h>
-#include <glib-unix.h>
-#include <glib.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <ttrace.h>
-
-#include <filesystem>
-#include <memory>
-#include <string>
-#include <utility>
-
-#include "app_request.h"
-#include "app_signal.h"
-#include "aul.h"
-#include "aul_api.h"
-#include "aul_app_com.h"
-#include "aul_error.h"
-#include "aul_sock.h"
-#include "aul_util.h"
-#include "launch.h"
-
-using namespace aul::internal;
-
-namespace {
-
-constexpr const char kRunAulDaemonsPath[] = "/run/aul/daemons/";
-constexpr const char kLaunchpadProcessPoolSock[] =
- ".launchpad-process-pool-sock";
-const int kPadCmdKillLoader = 19;
-const int kPadCmdRestartLoader = 20;
-constexpr const int TEP_ISMOUNT_MAX_RETRY_CNT = 20;
-
-class ResultInfo {
- public:
- ResultInfo(int fd, aul_result_cb callback, void* user_data)
- : fd_(fd), callback_(callback), user_data_(user_data) {}
-
- ResultInfo(const ResultInfo&) = delete;
- ResultInfo& operator = (const ResultInfo&) = delete;
-
- ~ResultInfo() {
- if (source_ != 0)
- g_source_remove(source_);
-
- if (fd_ > -1)
- close(fd_);
- }
-
- bool Watch() {
- source_ = g_unix_fd_add(fd_,
- static_cast<GIOCondition>(G_IO_IN | G_IO_HUP | G_IO_ERR),
- FdSourceFunc, this);
- if (source_ == 0) {
- _E("g_unix_fd_add() is failed");
- return false;
- }
-
- return true;
- }
-
- private:
- void ProcessReadEvent() {
- int res = aul_sock_recv_result_with_fd(fd_);
- if (res < 0)
- res = aul_error_convert(res);
- else
- res = AUL_R_OK;
-
- callback_(res, user_data_);
- }
-
- void ProcessErrorEvent() {
- callback_(AUL_R_ERROR, user_data_);
- }
-
- static gboolean FdSourceFunc(int fd, GIOCondition condition,
- void* user_data) {
- auto* info = static_cast<ResultInfo*>(user_data);
- if (condition & G_IO_IN)
- info->ProcessReadEvent();
- else
- info->ProcessErrorEvent();
-
- info->source_ = 0;
- delete info;
- return G_SOURCE_REMOVE;
- }
-
- private:
- int fd_;
- aul_result_cb callback_;
- void *user_data_;
- guint source_ = 0;
-};
-
-int aul_initialized = 0;
-int aul_fd;
-void* window_object = nullptr;
-void* bg_object = nullptr;
-void* conformant_object = nullptr;
-
-int SendCmdForUidOpt(int pid, uid_t uid, int cmd, bundle* kb, int opt) {
- int res = aul_sock_send_bundle(pid, uid, cmd, kb, opt);
- if (res < 0)
- res = aul_error_convert(res);
-
- return res;
-}
-
-int SendCmdNoReplyForUidOpt(int pid, uid_t uid, int cmd, bundle* kb, int opt) {
- int res = aul_sock_send_bundle(pid, uid, cmd, kb, opt | AUL_SOCK_NOREPLY);
- if (res < 0)
- res = aul_error_convert(res);
-
- return res;
-}
-
-int CheckEnvPid() {
- const char* env_str = getenv("AUL_PID");
- if (env_str && isdigit(*env_str)) {
- int env_pid = atoi(env_str);
- if (env_pid != getpid()) {
- _W("pid(%d) is not equal to AUL_PID(%d)",
- getpid(), env_pid);
- return -1;
- }
- }
-
- return 0;
-}
-
-int GetPreInitFd() {
- int fd = -1;
-
- if (CheckEnvPid() != 0)
- return fd;
-
- const char* listen_fd = getenv("AUL_LISTEN_FD");
- if (listen_fd) {
- if (isdigit(*listen_fd))
- fd = atoi(listen_fd);
- setenv("AUL_LISTEN_FD", "-1", 1);
- }
-
- return fd;
-}
-
-} // namespace
-
-extern "C" int aul_is_initialized() {
- return aul_initialized;
-}
-
-extern "C" API int app_send_cmd(int pid, int cmd, bundle* kb) {
- return SendCmdForUidOpt(pid, getuid(), cmd, kb, AUL_SOCK_NONE);
-}
-
-extern "C" API int app_send_cmd_for_uid(int pid, uid_t uid, int cmd,
- bundle* kb) {
- return SendCmdForUidOpt(pid, uid, cmd, kb, AUL_SOCK_NONE);
-}
-
-extern "C" API int app_send_cmd_with_queue_for_uid(int pid, uid_t uid, int cmd,
- bundle* kb) {
- return SendCmdForUidOpt(pid, uid, cmd, kb, AUL_SOCK_QUEUE);
-}
-
-extern "C" API int app_send_cmd_with_queue_noreply_for_uid(int pid, uid_t uid,
- int cmd, bundle* kb) {
- return SendCmdNoReplyForUidOpt(pid, uid, cmd, kb, AUL_SOCK_QUEUE);
-}
-
-extern "C" API int app_send_cmd_with_noreply(int pid, int cmd, bundle* kb) {
- return SendCmdForUidOpt(pid, getuid(), cmd, kb, AUL_SOCK_NOREPLY);
-}
-
-extern "C" API int app_send_cmd_to_launchpad(const char* pad_type, uid_t uid,
- int cmd, bundle* kb) {
- int fd = aul_sock_create_launchpad_client(pad_type, uid);
- if (fd < 0)
- return -1;
-
- int res = aul_sock_send_bundle_with_fd(fd, cmd, kb, AUL_SOCK_ASYNC);
- if (res < 0) {
- close(fd);
- return res;
- }
-
-retry_recv:
- int len = recv(fd, &res, sizeof(int), 0);
- if (len == -1) {
- if (errno == EAGAIN) {
- char buf[1024];
- _E("recv timeout: %d(%s)", errno, strerror_r(errno, buf, sizeof(buf)));
- res = -EAGAIN;
- } else if (errno == EINTR) {
- char buf[1024];
- _D("recv: %d(%s)", errno, strerror_r(errno, buf, sizeof(buf)));
- goto retry_recv;
- } else {
- char buf[1024];
- _E("recv error: %d(%s)", errno, strerror_r(errno, buf, sizeof(buf)));
- res = -ECOMM;
- }
- }
-
- close(fd);
- return res;
-}
-
-extern "C" int app_request_local(int cmd, bundle* kb) {
- _E("app_request_to_launchpad : Same Process Send Local");
- switch (cmd) {
- case APP_START:
- case APP_START_RES:
- case APP_START_ASYNC:
- case WIDGET_UPDATE:
- case APP_START_RES_ASYNC:
- case APP_SEND_LAUNCH_REQUEST:
- return aul_launch_local(bundle_dup(kb));
- case APP_OPEN:
- case APP_RESUME:
- case APP_RESUME_BY_PID:
- case APP_RESUME_BY_PID_ASYNC:
- case APP_SEND_RESUME_REQUEST:
- return aul_resume_local();
- default:
- _E("no support packet");
- return AUL_R_LOCAL;
- }
-}
-
-extern "C" int app_request_to_launchpad_for_uid(int cmd, const char* appid,
- bundle* kb, uid_t uid) {
- return AppRequest(cmd, uid)
- .With(kb)
- .SetAppId(appid)
- .Send();
-}
-
-extern "C" int aul_initialize() {
- if (aul_initialized)
- return AUL_R_ECANCELED;
-
- aul_fd = GetPreInitFd();
- if (aul_fd > 0 && aul_fd < sysconf(_SC_OPEN_MAX)) {
- int flag = fcntl(aul_fd, F_GETFD);
- flag |= FD_CLOEXEC;
- (void)fcntl(aul_fd, F_SETFD, flag);
- } else {
- _W("Failed to get preinit fd");
- aul_fd = aul_sock_create_server(getpid(), getuid());
- if (aul_fd < 0) {
- _E("aul_init create sock failed");
- return AUL_R_ECOMM;
- }
- }
- aul_notify_start();
-
- aul_initialized = 1;
- return aul_fd;
-}
-
-extern "C" API void aul_finalize() {
- aul_launch_fini();
-
- if (aul_initialized) {
- aul_sock_destroy_server(aul_fd);
- aul_fd = -1;
- }
-}
-
-extern "C" API int aul_request_data_control_socket_pair(bundle* kb, int* fd) {
- if (fd == nullptr)
- return AUL_R_EINVAL;
-
- int clifd = AppRequest(APP_GET_DC_SOCKET_PAIR)
- .With(kb)
- .SendSimply(AUL_SOCK_ASYNC);
- if (clifd <= 0)
- return AUL_R_ERROR;
-
- int ret = aul_sock_recv_result_with_fd(clifd);
- if (ret < 0) {
- close(clifd);
- if (ret == -EILLEGALACCESS) {
- _E("Illegal access in datacontrol socket pair request");
- return AUL_R_EILLACC;
- }
- return ret;
- }
-
- int fds[2] = { 0, };
- ret = aul_sock_recv_reply_sock_fd(clifd, &fds, 1);
- if (ret == 0)
- fd[0] = fds[0];
-
- return ret;
-}
-
-extern "C" API int aul_request_message_port_socket_pair(int* fd) {
- if (fd == nullptr)
- return AUL_R_EINVAL;
-
- int ret = AppRequest(APP_GET_MP_SOCKET_PAIR)
- .SendCmdOnly(AUL_SOCK_ASYNC);
- if (ret > 0) {
- int fds[2] = {0, };
- ret = aul_sock_recv_reply_sock_fd(ret, &fds, 2);
- if (ret == 0) {
- fd[0] = fds[0];
- fd[1] = fds[1];
- }
- }
-
- return ret;
-}
-
-extern "C" API int aul_launch_app(const char* appid, bundle* kb) {
- return aul_launch_app_for_uid(appid, kb, getuid());
-}
-
-extern "C" API int aul_launch_app_for_uid(const char* appid, bundle* kb,
- uid_t uid) {
- if (appid == nullptr)
- return AUL_R_EINVAL;
-
- return AppRequest(APP_START, uid)
- .With(kb)
- .SetAppId(appid)
- .Send();
-}
-
-extern "C" API int aul_open_app(const char* appid) {
- return aul_open_app_for_uid(appid, getuid());
-}
-
-extern "C" API int aul_open_app_for_uid(const char* appid, uid_t uid) {
- if (appid == nullptr)
- return AUL_R_EINVAL;
-
- return AppRequest(APP_OPEN, uid)
- .SetAppId(appid)
- .Send();
-}
-
-extern "C" API int aul_resume_app(const char* appid) {
- return aul_resume_app_for_uid(appid, getuid());
-}
-
-extern "C" API int aul_resume_app_for_uid(const char* appid, uid_t uid) {
- if (appid == nullptr)
- return AUL_R_EINVAL;
-
- return AppRequest(APP_RESUME, uid)
- .SetAppId(appid)
- .Send();
-}
-
-extern "C" API int aul_resume_pid(int pid) {
- return aul_resume_pid_for_uid(pid, getuid());
-}
-
-extern "C" API int aul_resume_pid_for_uid(int pid, uid_t uid) {
- if (pid <= 0)
- return AUL_R_EINVAL;
-
- return AppRequest(APP_RESUME_BY_PID, uid)
- .SetAppIdAsPid(pid)
- .Send();
-}
-
-extern "C" API int aul_terminate_pid(int pid) {
- return aul_terminate_pid_for_uid(pid, getuid());
-}
-
-extern "C" API int aul_terminate_pid_for_uid(int pid, uid_t uid) {
- if (pid <= 0)
- return AUL_R_EINVAL;
-
- int ret = AppRequest(APP_TERM_BY_PID, uid)
- .SetAppIdAsPid(pid)
- .Send();
- if (ret == pid)
- ret = AUL_R_OK;
-
- return ret;
-}
-
-extern "C" API int aul_terminate_bgapp_pid(int pid) {
- if (pid <= 0)
- return AUL_R_EINVAL;
-
- int ret = AppRequest(APP_TERM_BGAPP_BY_PID)
- .SetAppIdAsPid(pid)
- .Send();
- if (ret == pid)
- ret = AUL_R_OK;
-
- return ret;
-}
-
-extern "C" API int aul_terminate_pid_without_restart(int pid) {
- if (pid <= 0)
- return AUL_R_EINVAL;
-
- return AppRequest(APP_TERM_BY_PID_WITHOUT_RESTART)
- .SetAppIdAsPid(pid)
- .Send();
-}
-
-extern "C" API int aul_terminate_pid_sync_without_restart(int pid) {
- return aul_terminate_pid_sync_without_restart_for_uid(pid, getuid());
-}
-
-extern "C" API int aul_terminate_pid_sync_without_restart_for_uid(int pid,
- uid_t uid) {
- if (pid <= 0)
- return AUL_R_EINVAL;
-
- return AppRequest(APP_TERM_BY_PID_SYNC_WITHOUT_RESTART, uid)
- .SetAppIdAsPid(pid)
- .Send();
-}
-
-extern "C" API int aul_terminate_pid_async(int pid) {
- return aul_terminate_pid_async_for_uid(pid, getuid());
-}
-
-extern "C" API int aul_terminate_pid_async_for_uid(int pid, uid_t uid) {
- if (pid <= 0)
- return AUL_R_EINVAL;
-
- return AppRequest(APP_TERM_BY_PID_ASYNC, uid)
- .SetAppIdAsPid(pid)
- .Send();
-}
-
-extern "C" API int aul_kill_pid(int pid) {
- if (pid <= 0)
- return AUL_R_EINVAL;
-
- return AppRequest(APP_KILL_BY_PID)
- .SetAppIdAsPid(pid)
- .Send();
-}
-
-extern "C" API void aul_set_preinit_window(void* evas_object) {
- window_object = evas_object;
-}
-
-extern "C" API void* aul_get_preinit_window(const char* win_name) {
- return window_object;
-}
-
-extern "C" API void aul_set_preinit_background(void* evas_object) {
- bg_object = evas_object;
-}
-
-extern "C" API void* aul_get_preinit_background(void) {
- return bg_object;
-}
-
-extern "C" API void aul_set_preinit_conformant(void* evas_object) {
- conformant_object = evas_object;
-}
-
-extern "C" API void* aul_get_preinit_conformant(void) {
- return conformant_object;
-}
-
-extern "C" API int aul_pause_app(const char* appid) {
- return aul_pause_app_for_uid(appid, getuid());
-}
-
-extern "C" API int aul_pause_app_for_uid(const char* appid, uid_t uid) {
- if (appid == nullptr)
- return AUL_R_EINVAL;
-
- return AppRequest(APP_PAUSE, uid)
- .SetAppId(appid)
- .Send(AUL_SOCK_QUEUE | AUL_SOCK_NOREPLY);
-}
-
-extern "C" API int aul_pause_pid(int pid) {
- return aul_pause_pid_for_uid(pid, getuid());
-}
-
-extern "C" API int aul_pause_pid_for_uid(int pid, uid_t uid) {
- if (pid <= 0)
- return AUL_R_EINVAL;
-
- return AppRequest(APP_PAUSE_BY_PID, uid)
- .SetAppIdAsPid(pid)
- .Send(AUL_SOCK_QUEUE | AUL_SOCK_NOREPLY);
-}
-
-extern "C" API int aul_reload_appinfo(void) {
- return AppRequest(AMD_RELOAD_APPINFO)
- .SetAppIdAsPid(getpid())
- .Send();
-}
-
-extern "C" API int aul_is_tep_mount_dbus_done(const char* tep_string) {
- GError* err = nullptr;
- GDBusConnection* conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &err);
- if (conn == nullptr) {
- _E("g_bus_get_sync() is failed. error(%s)", err ? err->message : "Unknown");
- g_clear_error(&err);
- return AUL_R_ERROR;
- }
-
- std::unique_ptr<GDBusConnection, decltype(g_object_unref)*> conn_ptr(
- conn, g_object_unref);
-
- GDBusMessage* msg = g_dbus_message_new_method_call(TEP_BUS_NAME,
- TEP_OBJECT_PATH,
- TEP_INTERFACE_NAME,
- TEP_IS_MOUNTED_METHOD);
- if (msg == nullptr) {
- _E("g_dbus_message_new_method_call() is failed. error(%s)",
- err ? err->message : "Unknown");
- return AUL_R_ERROR;
- }
-
- std::unique_ptr<GDBusMessage, decltype(g_object_unref)*> msg_ptr(
- msg, g_object_unref);
- g_dbus_message_set_body(msg, g_variant_new("(s)", tep_string));
-
- GDBusMessage* reply = g_dbus_connection_send_message_with_reply_sync(conn,
- msg,
- G_DBUS_SEND_MESSAGE_FLAGS_NONE,
- 500,
- nullptr,
- nullptr,
- &err);
- if (reply == nullptr || err != nullptr) {
- _E("g_dbus_connection_send_message_with_reply_sync() is failed. error(%s)",
- err ? err->message : "Unknown");
- g_clear_error(&err);
- return AUL_R_ERROR;
- }
-
- std::unique_ptr<GDBusMessage, decltype(g_object_unref)*> reply_ptr(
- reply, g_object_unref);
-
- GVariant* body = g_dbus_message_get_body(reply);
- if (body == nullptr) {
- _E("g_dbus_message_get_body() is failed.");
- return AUL_R_ERROR;
- }
-
- int ret = AUL_R_ERROR;
- g_variant_get(body, "(i)", &ret);
- return ret;
-}
-
-extern "C" API int aul_check_tep_mount(const char* tep_path) {
- if (tep_path) {
- int ret = -1;
- int cnt = 0;
- while (cnt < TEP_ISMOUNT_MAX_RETRY_CNT) {
- ret = aul_is_tep_mount_dbus_done(tep_path);
- if (ret == 1)
- break;
- usleep(50 * 1000);
- cnt++;
- }
- /* incase after trying 1 sec, not getting mounted then quit */
- if (ret != 1) {
- _E("Not able to mount within 1 sec");
- return -1;
- }
- }
- return 0;
-}
-
-extern "C" API int aul_add_loader(const char* loader_path, bundle* kb) {
- return aul_add_loader_for_uid(loader_path, kb, getuid());
-}
-
-extern "C" API int aul_add_loader_for_uid(const char* loader_path, bundle* kb,
- uid_t uid) {
- if (loader_path == nullptr)
- return AUL_R_EINVAL;
-
- tizen_base::Bundle b = { {AUL_K_LOADER_PATH, loader_path} };
-
- if (kb) {
- try {
- tizen_base::Bundle extra(kb, false, false);
- auto raw = extra.ToRaw();
- b.Add(AUL_K_LOADER_EXTRA, (const char*)(raw.first.get()));
- } catch (const std::bad_alloc&) {
- return AUL_R_EINVAL;
- }
- }
-
- return AppRequest(APP_ADD_LOADER, uid)
- .With(std::move(b))
- .SendSimply();
-}
-
-extern "C" API int aul_remove_loader(int loader_id) {
- return aul_remove_loader_for_uid(loader_id, getuid());
-}
-
-extern "C" API int aul_remove_loader_for_uid(int loader_id, uid_t uid) {
- if (loader_id <= 0)
- return AUL_R_EINVAL;
-
- return AppRequest(APP_REMOVE_LOADER, uid)
- .With({{AUL_K_LOADER_ID, std::to_string(loader_id)}})
- .SendSimply();
-}
-
-extern "C" API int aul_app_register_pid(const char* appid, int pid) {
- if (appid == nullptr || pid <= 0)
- return AUL_R_EINVAL;
-
- return AppRequest(APP_REGISTER_PID)
- .SetAppId(appid)
- .SetPid(pid)
- .SendSimply(AUL_SOCK_NOREPLY);
-}
-
-extern "C" API int aul_launch_app_async(const char* appid, bundle* kb) {
- return aul_launch_app_async_for_uid(appid, kb, getuid());
-}
-
-extern "C" API int aul_launch_app_async_for_uid(const char* appid, bundle* kb,
- uid_t uid) {
- if (appid == nullptr)
- return AUL_R_EINVAL;
-
- return AppRequest(APP_START_ASYNC, uid)
- .With(kb)
- .SetAppId(appid)
- .Send();
-}
-
-extern "C" API int aul_prepare_candidate_process(void) {
- return AppRequest(APP_PREPARE_CANDIDATE_PROCESS)
- .SendCmdOnly();
-}
-
-extern "C" API int aul_terminate_pid_sync(int pid) {
- return aul_terminate_pid_sync_for_uid(pid, getuid());
-}
-
-extern "C" API int aul_terminate_pid_sync_for_uid(int pid, uid_t uid) {
- if (pid <= 0)
- return AUL_R_EINVAL;
-
- return AppRequest(APP_TERM_BY_PID_SYNC, uid)
- .SetAppIdAsPid(pid)
- .Send();
-}
-
-extern "C" API int aul_resume_pid_async(int pid) {
- return aul_resume_pid_async_for_uid(pid, getuid());
-}
-
-extern "C" API int aul_resume_pid_async_for_uid(int pid, uid_t uid) {
- if (pid <= 0)
- return AUL_R_EINVAL;
-
- return AppRequest(APP_RESUME_BY_PID_ASYNC, uid)
- .SetAppIdAsPid(pid)
- .Send();
-}
-
-extern "C" API int aul_resume_app_by_instance_id(const char* appid,
- const char *instance_id) {
- return aul_resume_app_by_instance_id_for_uid(appid, instance_id, getuid());
-}
-
-extern "C" API int aul_resume_app_by_instance_id_for_uid(const char* appid,
- const char* instance_id, uid_t uid) {
- if (appid == nullptr || instance_id == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- return AppRequest(APP_RESUME, uid)
- .SetAppId(appid)
- .SetInstId(instance_id)
- .Send();
-}
-
-extern "C" API int aul_terminate_instance_async(const char* instance_id,
- int pid) {
- return aul_terminate_instance_async_for_uid(instance_id, pid, getuid());
-}
-
-extern "C" API int aul_terminate_instance_async_for_uid(const char* instance_id,
- int pid, uid_t uid) {
- if (instance_id == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- return AppRequest(APP_TERM_INSTANCE_ASYNC, uid)
- .SetAppIdAsPid(pid)
- .SetInstId(instance_id)
- .Send();
-}
-
-extern "C" API int aul_terminate_app_with_instance_id(const char* appid,
- const char* instance_id) {
- return aul_terminate_app_with_instance_id_for_uid(appid, instance_id,
- getuid());
-}
-
-extern "C" API int aul_terminate_app_with_instance_id_for_uid(const char* appid,
- const char* instance_id, uid_t uid) {
- if (appid == nullptr || instance_id == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- return AppRequest(APP_TERMINATE, uid)
- .SetAppId(appid)
- .SetInstId(instance_id)
- .Send();
-}
-
-extern "C" API int aul_terminate_app(const char* appid) {
- return aul_terminate_app_for_uid(appid, getuid());
-}
-
-extern "C" API int aul_terminate_app_for_uid(const char* appid, uid_t uid) {
- if (appid == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- return AppRequest(APP_TERMINATE, uid)
- .SetAppId(appid)
- .Send();
-}
-
-extern "C" API int aul_prepare_app_defined_loader(const char* loader_name) {
- return aul_prepare_app_defined_loader_for_uid(loader_name, getuid());
-}
-
-extern "C" API int aul_prepare_app_defined_loader_for_uid(
- const char* loader_name, uid_t uid) {
- if (loader_name == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- int ret = AppRequest(APP_PREPARE_APP_DEFINED_LOADER, uid)
- .With({{AUL_K_LOADER_NAME, loader_name}})
- .SendSimply();
- if (ret < 0) {
- _E("Failed to prepare app-defined loader. error(%d)", ret);
- return ret;
- }
-
- _I("loader id(%d)", ret);
- return ret;
-}
-
-extern "C" API int aul_terminate_pid_async_v2(pid_t pid,
- aul_result_cb callback, void *user_data) {
- if (pid < 1 || callback == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- int fd = AppRequest(APP_TERM_BY_PID, getuid())
- .SetAppIdAsPid(pid)
- .SendSimply(AUL_SOCK_ASYNC);
- if (fd < 0) {
- _E("Failed to send request. error(%d)", fd);
- return fd;
- }
-
- try {
- auto* info = new ResultInfo(fd, callback, user_data);
- info->Watch();
- } catch (const std::exception& e) {
- _E("Exception occurs. error: %s", e.what());
- close(fd);
- return AUL_R_ERROR;
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_terminate_app_async(const char* appid,
- aul_result_cb callback, void *user_data) {
- if (appid == nullptr || callback == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- int fd = AppRequest(APP_TERMINATE, getuid())
- .SetAppId(appid)
- .SendSimply(AUL_SOCK_ASYNC);
- if (fd < 0) {
- _E("Failed to send request. error(%d)", fd);
- return fd;
- }
-
- try {
- auto* info = new ResultInfo(fd, callback, user_data);
- info->Watch();
- } catch (const std::exception& e) {
- _E("Exception occurs. error: %s", e.what());
- close(fd);
- return AUL_R_ERROR;
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_kill_pid_async(pid_t pid,
- aul_result_cb callback, void *user_data) {
- if (pid < 1 || callback == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- int fd = AppRequest(APP_KILL_BY_PID, getuid())
- .SetAppIdAsPid(pid)
- .SendSimply(AUL_SOCK_ASYNC);
- if (fd < 0) {
- _E("Failed to send request. error(%d)", fd);
- return fd;
- }
-
- try {
- auto* info = new ResultInfo(fd, callback, user_data);
- info->Watch();
- } catch (const std::exception& e) {
- _E("Exception occurs. error: %s", e.what());
- close(fd);
- return AUL_R_ERROR;
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_kill_loader(const char* loader_name) {
- return aul_kill_loader_for_uid(loader_name, getuid());
-}
-
-extern "C" API int aul_kill_loader_for_uid(const char* loader_name,
- uid_t uid) {
- if (loader_name == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- if (uid < REGULAR_UID_MIN) {
- uid = tzplatform_getuid(TZ_SYS_DEFAULT_USER);
- _W("Use system default user ID(%u)", uid);
- }
-
- std::string endpoint = kRunAulDaemonsPath + std::to_string(uid) + "/" +
- std::string(kLaunchpadProcessPoolSock);
- if (!std::filesystem::exists(endpoint)) {
- _E("launchpad socket is not prepared");
- return AUL_R_ENOENT;
- }
-
- int fd = aul_sock_create_launchpad_client(kLaunchpadProcessPoolSock, uid);
- if (fd < 0) {
- _E("Failed to create launchpad client socket. error(%d)", fd);
- return aul_error_convert(fd);
- }
-
- tizen_base::Bundle b = { {AUL_K_LOADER_NAME, loader_name} };
- int ret = aul_sock_send_bundle_with_fd(fd, kPadCmdKillLoader, b.GetHandle(),
- AUL_SOCK_NOREPLY);
- if (ret != AUL_R_OK)
- return aul_error_convert(ret);
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_restart_loader(const char* loader_name) {
- return aul_restart_loader_for_uid(loader_name, getuid());
-}
-
-extern "C" API int aul_restart_loader_for_uid(const char* loader_name,
- uid_t uid) {
- if (loader_name == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- if (uid < REGULAR_UID_MIN) {
- uid = tzplatform_getuid(TZ_SYS_DEFAULT_USER);
- _W("Use system default user ID(%u)", uid);
- }
-
- std::string endpoint = kRunAulDaemonsPath + std::to_string(uid) + "/" +
- std::string(kLaunchpadProcessPoolSock);
- if (!std::filesystem::exists(endpoint)) {
- _E("launchpad socket is not prepared");
- return AUL_R_ENOENT;
- }
-
- int fd = aul_sock_create_launchpad_client(kLaunchpadProcessPoolSock, uid);
- if (fd < 0) {
- _E("Failed to create launchpad client socket. error(%d)", fd);
- return aul_error_convert(fd);
- }
-
- tizen_base::Bundle b = { {AUL_K_LOADER_NAME, loader_name} };
- int ret = aul_sock_send_bundle_with_fd(fd, kPadCmdRestartLoader,
- b.GetHandle(), AUL_SOCK_NOREPLY);
- if (ret != AUL_R_OK)
- return aul_error_convert(ret);
-
- return AUL_R_OK;
-}
+++ /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>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int aul_initialize(void);
-int aul_is_initialized(void);
-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_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_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);
-void aul_set_instance_info(const char *app_id, bundle *kb);
-
-#ifdef __cplusplus
-}
-#endif
+++ /dev/null
-/*
-* Copyright (c) 2000 - 2021 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 <bundle_internal.h>
-#include <glib.h>
-#include <gio/gio.h>
-#include <uuid.h>
-
-#include <atomic>
-#include <functional>
-#include <list>
-#include <mutex>
-
-#include "app_request.h"
-#include "aul.h"
-#include "aul_api.h"
-#include "aul_error.h"
-#include "aul_sock.h"
-#include "aul_svc.h"
-#include "aul_svc_priv_key.h"
-#include "aul_util.h"
-#include "cpu_inheritance.hh"
-#include "launch.h"
-
-using namespace aul::internal;
-
-namespace {
-
-using ErrCb = std::function<void(int, void*)>;
-using ReplyCb = std::function<void(bundle*, int, void*)>;
-
-class ReplyList;
-class ReplyInfo {
- public:
- ReplyInfo(int pid, std::string seq_num,
- ReplyCb reply_cb, void* user_data)
- : seq_num_(std::move(seq_num)), launched_pid_(pid),
- reply_cb_(std::move(reply_cb)), user_data_(user_data) {}
-
- void SetCallerCb(ErrCb cb,
- void* caller_data) {
- caller_cb_ = std::move(cb);
- caller_data_ = caller_data;
- }
-
- void UnsetCallerCb() {
- caller_cb_ = nullptr;
- caller_data_ = nullptr;
- }
-
- int GetLaunchedPid() const {
- return launched_pid_;
- }
-
- const ErrCb& GetCallerCb() const {
- return caller_cb_;
- }
-
- void* GetCallerData() const {
- return caller_data_;
- }
-
- private:
- friend class ReplyList;
-
- std::string seq_num_;
- int launched_pid_;
- ReplyCb reply_cb_;
- void* user_data_;
- ErrCb caller_cb_;
- void* caller_data_ = nullptr;
-};
-
-class ReplyList {
- public:
- std::unique_ptr<ReplyInfo> FindByCallerData(void* caller_data) {
- std::unique_lock<std::mutex> lock(mutex_);
- for (auto& i : list_) {
- if (i->caller_data_ == caller_data)
- return std::unique_ptr<ReplyInfo>(new ReplyInfo(*i));
- }
-
- return {};
- }
-
- std::unique_ptr<ReplyInfo> Pop(const std::string& seq_num) {
- if (seq_num.empty())
- return nullptr;
-
- std::unique_lock<std::mutex> lock(mutex_);
- for (auto i = list_.begin(); i != list_.end(); ++i) {
- if ((*i)->seq_num_ == seq_num) {
- auto ret = std::move(*i);
- list_.erase(i);
- return ret;
- }
- }
-
- return nullptr;
- }
-
- void Remove(int pid) {
- std::unique_lock<std::mutex> lock(mutex_);
- for (auto i = list_.begin(); i != list_.end(); ) {
- if ((*i)->launched_pid_ == pid) {
- i = list_.erase(i);
- } else {
- ++i;
- }
- }
- }
-
- void Push(std::unique_ptr<ReplyInfo> info) {
- if (info == nullptr)
- return;
-
- std::unique_lock<std::mutex> lock(mutex_);
- list_.push_back(std::move(info));
- }
-
- void UpdatePid(const std::string& seq_num, int launched_pid) {
- std::unique_lock<std::mutex> lock(mutex_);
- auto* i = Find(seq_num);
- if (i == nullptr)
- return;
- i->launched_pid_ = launched_pid;
- }
-
- bool SetCallerCb(int pid, ErrCb cb,
- void* caller_data) {
- std::unique_lock<std::mutex> lock(mutex_);
- auto* i = Find(pid);
- if (i == nullptr)
- return false;
- i->SetCallerCb(std::move(cb), caller_data);
- return true;
- }
-
- bool UnsetCallerCb(int pid, void* caller_data) {
- std::unique_lock<std::mutex> lock(mutex_);
- auto* i = Find(pid, caller_data);
- if (i == nullptr)
- return false;
- i->UnsetCallerCb();
- return true;
- }
-
- int InvokeReplyCb(const tizen_base::Bundle& b, bool is_cancel,
- int launched_pid) {
- if (launched_pid < 0) {
- _E("Received pid(%d)", launched_pid);
- return -1;
- }
-
- auto seq_num = b.GetString(AUL_K_SEQ_NUM);
- if (seq_num.empty()) {
- _E("Failed to get seq num");
- return -1;
- }
-
- auto info = Pop(seq_num);
- if (info == nullptr) {
- _E("Failed to find reply info");
- return -1;
- }
-
- if (info->reply_cb_ == nullptr) {
- _E("Reply callback function is nullptr");
- return -1;
- }
-
- auto fwdpid_str = b.GetString(AUL_K_FWD_CALLEE_PID);
- if (is_cancel && !fwdpid_str.empty()) {
- launched_pid = atoi(fwdpid_str.c_str());
- auto new_info = std::make_unique<ReplyInfo>(launched_pid, seq_num,
- info->reply_cb_, info->user_data_);
- Push(std::move(new_info));
-
- if (info->caller_cb_ != nullptr)
- info->caller_cb_(launched_pid, info->caller_data_);
-
- _W("Change reply info. fwd pid: %d", launched_pid);
- return 0;
- }
-
- info->reply_cb_(b.GetHandle(), is_cancel ? 1 : 0, info->user_data_);
-
- return 0;
- }
-
- private:
- ReplyInfo* Find(const std::string& seq_num) {
- for (auto& i : list_) {
- if (i->seq_num_ == seq_num)
- return i.get();
- }
-
- return nullptr;
- }
-
- ReplyInfo* Find(int pid) {
- for (auto& i : list_) {
- if (i->launched_pid_ == pid && i->caller_cb_ == nullptr)
- return i.get();
- }
-
- return nullptr;
- }
-
- ReplyInfo* Find(int pid, void* caller_data) {
- for (auto& i : list_) {
- if (i->launched_pid_ == pid && i->caller_data_ == caller_data)
- return i.get();
- }
-
- return nullptr;
- }
-
- private:
- std::list<std::unique_ptr<ReplyInfo>> list_;
- std::mutex mutex_;
-};
-
-ReplyList __reply_list;
-
-class ErrorInfo {
- public:
- ErrorInfo(std::string seq_num, tizen_base::Bundle b, int cmd,
- ErrCb error_cb, void* user_data)
- : seq_num_(std::move(seq_num)),
- b_(std::move(b)), cmd_(cmd),
- error_cb_(std::move(error_cb)),
- user_data_(user_data) {
- }
-
- ErrorInfo(const ErrorInfo&) = delete;
- ErrorInfo& operator = (const ErrorInfo&) = delete;
-
- ~ErrorInfo() {
- if (io_ != nullptr)
- g_io_channel_unref(io_);
- }
-
- int AddWatch(int fd) {
- GIOCondition cond = static_cast<GIOCondition> (G_IO_IN | G_IO_PRI |
- G_IO_ERR | G_IO_HUP);
- io_ = g_io_channel_unix_new(fd);
- if (io_ == nullptr) {
- _E("Failed to create gio channel");
- return -1;
- }
-
- guint source = g_io_add_watch(io_, cond, ErrorHandlerCb, this);
- if (source == 0) {
- _E("Failed to add gio watch");
- return -1;
- }
- g_io_channel_set_close_on_unref(io_, TRUE);
-
- return 0;
- }
-
- static gboolean ErrorHandlerCb(GIOChannel* io, GIOCondition cond,
- gpointer user_data) {
- int fd = g_io_channel_unix_get_fd(io);
- auto* info = reinterpret_cast<ErrorInfo*>(user_data);
-
- if (info == nullptr) {
- _E("Critical error!");
- return G_SOURCE_REMOVE;
- }
-
- int res = aul_sock_recv_result_with_fd(fd);
- if (res < 1) {
- res = aul_error_convert(res);
- if (res == AUL_R_LOCAL)
- res = app_request_local(info->cmd_, info->b_.GetHandle());
- } else {
- __reply_list.UpdatePid(info->seq_num_, res);
- }
-
- _W("Sequence(%s), result(%d)", info->seq_num_.c_str(), res);
-
- if (info->error_cb_ != nullptr) {
- info->error_cb_(res, info->user_data_);
- info->error_cb_ = nullptr;
- }
-
- if (res < 1)
- __reply_list.Pop(info->seq_num_);
-
- delete info;
- return G_SOURCE_REMOVE;
- }
-
- private:
- GIOChannel* io_ = nullptr;
- std::string seq_num_;
- tizen_base::Bundle b_;
- int cmd_;
- ErrCb error_cb_;
- void* user_data_;
- CPUInheritance inheritance_;
-};
-
-std::string __gen_seq_num() {
- char uuid[37];
- uuid_t u;
- uuid_generate(u);
- uuid_unparse(u, uuid);
- return std::string(uuid);
-}
-
-int __get_caller_pid(const tizen_base::Bundle& b) {
- std::string pid_str = b.GetString(AUL_K_ORG_CALLER_PID);
- if (pid_str.empty())
- pid_str = b.GetString(AUL_K_CALLER_PID);
-
- if (pid_str.empty())
- return -1;
-
- int pid = atoi(pid_str.c_str());
- if (pid <= 1)
- return -1;
-
- return pid;
-}
-
-int __launch_app_with_result(int cmd, const char* appid, bundle* kb,
- void (*callback)(bundle*, int, void*), void* data, uid_t uid) {
- if (!aul_is_initialized()) {
- if (aul_launch_init(nullptr, nullptr) < 0)
- return AUL_R_ENOINIT;
- }
-
- if (appid == nullptr || callback == nullptr || kb == nullptr)
- return AUL_R_EINVAL;
-
- std::string seq_num = __gen_seq_num();
- bundle_del(kb, AUL_K_SEQ_NUM);
- bundle_add(kb, AUL_K_SEQ_NUM, seq_num.c_str());
-
- auto info = std::make_unique<ReplyInfo>(-1, seq_num, callback, data);
- __reply_list.Push(std::move(info));
-
- int ret = AppRequest(cmd, uid)
- .With(kb)
- .SetAppId(appid)
- .Send();
-
- if (ret > 0)
- __reply_list.UpdatePid(seq_num, ret);
- else
- __reply_list.Pop(seq_num);
-
- return ret;
-}
-
-int __set_caller_info(bundle* kb) {
- const char* caller_pid;
- const char* caller_uid;
-
- caller_pid = bundle_get_val(kb, AUL_K_CALLER_PID);
- if (caller_pid == nullptr) {
- _E("Failed to get caller pid");
- return AUL_R_EINVAL;
- }
-
- caller_uid = bundle_get_val(kb, AUL_K_CALLER_UID);
- if (caller_uid == nullptr) {
- _E("Failed to get caller uid");
- return AUL_R_EINVAL;
- }
-
- bundle_del(kb, AUL_K_ORG_CALLER_PID);
- bundle_add(kb, AUL_K_ORG_CALLER_PID, caller_pid);
- bundle_del(kb, AUL_K_ORG_CALLER_UID);
- bundle_add(kb, AUL_K_ORG_CALLER_UID, caller_uid);
-
- return AUL_R_OK;
-}
-
-int __recv_reply_bundle(int fd, bundle** reply_b) {
- app_pkt_t* pkt = nullptr;
- int ret = aul_sock_recv_reply_pkt(fd, &pkt);
- if (ret != 0) {
- _E("Failed to receive the packet. result(%d)", ret);
- if (ret == -EAGAIN)
- return AUL_R_ETIMEOUT;
-
- return AUL_R_ECOMM;
- }
-
- std::unique_ptr<app_pkt_t, decltype(free)*> pkt_auto(pkt, free);
- if (!(pkt_auto->opt & AUL_SOCK_BUNDLE)) {
- _E("Invalid protocol");
- return AUL_R_ECOMM;
- }
-
- ret = pkt_auto->cmd;
- if (ret < 0) {
- _E("The launch request is failed. result(%d)", ret);
- if (ret == -EAGAIN)
- return AUL_R_ETIMEOUT;
-
- return AUL_R_ERROR;
- }
-
- bundle* kb = bundle_decode(pkt_auto->data, pkt_auto->len);
- if (kb == nullptr) {
- _E("Out of memory");
- return AUL_R_ERROR;
- }
-
- *reply_b = kb;
- return ret;
-}
-
-int __send_request_with_callback(int cmd, const char* appid, bundle* b,
- uid_t uid,
- void (*reply_cb)(bundle* b, int, void*),
- void (*error_cb)(int, void*),
- void* user_data) {
- if (!aul_is_initialized()) {
- if (aul_launch_init(nullptr, nullptr) < 0) {
- _E("Failed to initialize aul launch");
- return AUL_R_ENOINIT;
- }
- }
-
- if (appid == nullptr || b == nullptr || error_cb == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- std::string seq_num = __gen_seq_num();
- bundle_del(b, AUL_K_SEQ_NUM);
- bundle_add(b, AUL_K_SEQ_NUM, seq_num.c_str());
-
- if (reply_cb != nullptr) {
- auto r_info = std::make_unique<ReplyInfo>(-1, seq_num, reply_cb,
- user_data);
- __reply_list.Push(std::move(r_info));
- }
-
- int fd = AppRequest(cmd, uid)
- .With(b)
- .SetAppId(appid)
- .Send();
- if (fd < 0 || fd >= sysconf(_SC_OPEN_MAX)) {
- _E("Failed to send launch request. appid(%s), result(%d)",
- appid, fd);
- if (reply_cb)
- __reply_list.Pop(seq_num);
- return AUL_R_ECOMM;
- }
-
- auto error_info = std::make_unique<ErrorInfo>(seq_num,
- tizen_base::Bundle(b, true, true), cmd, error_cb, user_data);
- if (error_info.get() == nullptr) {
- _E("Failed to create error info");
- if (reply_cb != nullptr)
- __reply_list.Pop(seq_num);
- return AUL_R_ERROR;
- }
-
- if (error_info->AddWatch(fd) < 0) {
- _E("Failed to add resultcb watch");
- if (reply_cb != nullptr)
- __reply_list.Pop(seq_num);
- close(fd);
- return AUL_R_ERROR;
- }
-
- error_info.release();
- return AUL_R_OK;
-}
-
-int __send_launch_request(const std::string& appid, bundle* kb, uid_t uid) {
- std::string seq_num = __gen_seq_num();
- tizen_base::Bundle b(kb, false, false);
- b.Delete(AUL_K_SEQ_NUM);
- b.Add(AUL_K_SEQ_NUM, seq_num);
-
- int fd = AppRequest(APP_SEND_LAUNCH_REQUEST_SYNC, uid)
- .With(b)
- .SetAppId(appid)
- .Send();
- if (fd < 0 || fd >= sysconf(_SC_OPEN_MAX)) {
- _E("Failed to send launch request. appid(%s), result(%d)",
- appid.c_str(), fd);
- return AUL_R_ECOMM;
- }
-
- return fd;
-}
-
-} // namespace
-
-extern "C" int app_result(int cmd, bundle* kb, int launched_pid) {
- switch (cmd) {
- case APP_RESULT:
- __reply_list.InvokeReplyCb(tizen_base::Bundle(kb, false, false), false,
- launched_pid);
- break;
- case APP_CANCEL:
- __reply_list.InvokeReplyCb(tizen_base::Bundle(kb, false, false), true,
- launched_pid);
- break;
- }
-
- return 0;
-}
-
-extern "C" API int aul_launch_app_with_result(const char* pkgname, bundle* kb,
- void (*cbfunc)(bundle*, int, void*), void* data) {
- return __launch_app_with_result(APP_START_RES, pkgname, kb, cbfunc,
- data, getuid());
-}
-
-extern "C" API int aul_launch_app_with_result_for_uid(const char* pkgname,
- bundle* kb, void (*cbfunc)(bundle*, int, void*), void* data, uid_t uid) {
- return __launch_app_with_result(APP_START_RES, pkgname, kb, cbfunc,
- data, uid);
-}
-
-extern "C" void aul_set_instance_info(const char* app_id, bundle* kb) {
- const char* component_id;
- char buf[1024];
- char uuid[37];
- uuid_t u;
-
- uuid_generate(u);
- uuid_unparse(u, uuid);
-
- component_id = bundle_get_val(kb, AUL_K_COMPONENT_ID);
- if (component_id != nullptr) {
- snprintf(buf, sizeof(buf), "%s:%s:%s",
- uuid, app_id, component_id);
- } else {
- snprintf(buf, sizeof(buf), "%s:%s", uuid, app_id);
- }
-
- bundle_del(kb, AUL_K_INSTANCE_ID);
- bundle_add(kb, AUL_K_INSTANCE_ID, buf);
-}
-
-extern "C" API int aul_forward_app(const char* pkgname, bundle* kb) {
- if (pkgname == nullptr || kb == nullptr)
- return AUL_R_EINVAL;
-
- if (__set_caller_info(kb) < 0)
- return AUL_R_EINVAL;
-
- bundle_del(kb, AUL_SVC_K_CAN_BE_LEADER);
- bundle_del(kb, AUL_SVC_K_REROUTE);
- bundle_del(kb, AUL_SVC_K_RECYCLE);
-
- const char* launch_mode = bundle_get_val(kb, AUL_SVC_K_LAUNCH_MODE);
- if (launch_mode != nullptr && !strcmp(launch_mode, "group"))
- aul_set_instance_info(pkgname, kb);
-
- int ret;
- tizen_base::Bundle dupb(kb, true, true);
- if (bundle_get_val(kb, AUL_K_WAIT_RESULT) != nullptr) {
- ret = AppRequest(APP_START_RES)
- .With(kb)
- .SetAppId(pkgname)
- .Send();
- if (ret < 0)
- return ret;
- } else {
- ret = AppRequest(APP_START)
- .With(kb)
- .SetAppId(pkgname)
- .Send();
- return ret;
- }
-
- bundle* outb = nullptr;
- int pid = ret;
- ret = aul_create_result_bundle(dupb.GetHandle(), &outb);
- if (ret < 0)
- return ret;
- tizen_base::Bundle outb_auto(outb, false, true);
-
- outb_auto.Delete(AUL_K_FWD_CALLEE_PID);
- outb_auto.Add(AUL_K_FWD_CALLEE_PID, std::to_string(pid));
- return aul_send_result(outb_auto.GetHandle(), 1);
-}
-
-extern "C" API int aul_create_result_bundle(bundle* inb, bundle** outb) {
- *outb = nullptr;
-
- if (inb == nullptr) {
- _E("return msg create fail");
- return AUL_R_EINVAL;
- }
-
- tizen_base::Bundle inb_auto(inb, false, false);
- tizen_base::Bundle outb_auto;
-
- if (!inb_auto.GetString(AUL_K_WAIT_RESULT).empty()) {
- outb_auto.Add(AUL_K_SEND_RESULT, "1");
- _D("original msg is msg with result");
- } else {
- _D("original msg is not msg with result");
- }
-
- std::string uid_str = inb_auto.GetString(AUL_K_ORG_CALLER_UID);
- if (uid_str.empty()) {
- uid_str = inb_auto.GetString(AUL_K_CALLER_UID);
- if (uid_str.empty()) {
- _E("Failed to find caller uid");
- return AUL_R_EINVAL;
- }
- }
-
- outb_auto.Add(AUL_K_ORG_CALLER_UID, uid_str);
- std::string pid_str = inb_auto.GetString(AUL_K_ORG_CALLER_PID);
- if (!pid_str.empty()) {
- outb_auto.Add(AUL_K_ORG_CALLER_PID, pid_str);
- goto end;
- }
-
- pid_str = inb_auto.GetString(AUL_K_CALLER_PID);
- if (pid_str.empty()) {
- _E("original msg does not have caller pid");
- return AUL_R_EINVAL;
- }
-
- outb_auto.Add(AUL_K_CALLER_PID, pid_str);
-
-end:
- std::string num_str = inb_auto.GetString(AUL_K_SEQ_NUM);
- if (num_str.empty()) {
- _E("original msg does not have seq num");
- return AUL_R_ECANCELED;
- }
-
- outb_auto.Add(AUL_K_SEQ_NUM, num_str);
- *outb = outb_auto.Detach();
- return AUL_R_OK;
-}
-
-extern "C" int aul_send_result(bundle* kb, int is_cancel) {
- int pid;
- int ret;
- int callee_pid;
- int callee_pgid;
- char callee_appid[256];
-
- if (kb == nullptr)
- return AUL_R_EINVAL;
-
- tizen_base::Bundle b(kb, false, false);
- if ((pid = __get_caller_pid(b)) < 0)
- return AUL_R_EINVAL;
-
- _D("caller pid : %d", pid);
-
- if (b.GetString(AUL_K_SEND_RESULT).empty()) {
- _D("original msg is not msg with result");
- return AUL_R_OK;
- }
-
- callee_pid = getpid();
- callee_pgid = getpgid(callee_pid);
- b.Add(AUL_K_CALLEE_PID, std::to_string(callee_pgid));
-
- ret = aul_app_get_appid_bypid(callee_pid, callee_appid,
- sizeof(callee_appid));
- if (ret == 0)
- b.Add(AUL_K_CALLEE_APPID, callee_appid);
- else
- _W("fail(%d) to get callee appid by pid", ret);
-
- ret = app_send_cmd_with_noreply(AUL_UTIL_PID,
- (is_cancel == 1) ? APP_CANCEL : APP_RESULT, b.GetHandle());
- _D("app_send_cmd_with_noreply : %d", ret);
-
- return ret;
-}
-
-extern "C" API int aul_subapp_terminate_request_pid(int pid) {
- if (pid <= 0)
- return AUL_R_EINVAL;
-
- __reply_list.Remove(pid);
- return AppRequest(APP_TERM_REQ_BY_PID)
- .SetAppIdAsPid(pid)
- .Send();
-}
-
-extern "C" int aul_subapp_terminate_request(const char* instance_id, int pid) {
- if (pid <= 0)
- return AUL_R_EINVAL;
-
- __reply_list.Remove(pid);
- return aul_terminate_instance_async(instance_id, pid);
-}
-
-extern "C" API int aul_add_caller_cb(int pid, void (*caller_cb)(int, void*),
- void* data) {
- if (pid <= 0)
- return AUL_R_EINVAL;
-
- if (__reply_list.SetCallerCb(pid, caller_cb, data))
- return AUL_R_OK;
-
- return AUL_R_ERROR;
-}
-
-extern "C" API int aul_remove_caller_cb(int pid, void* data) {
- if (pid <= 0)
- return AUL_R_EINVAL;
-
- if (__reply_list.UnsetCallerCb(pid, data))
- return AUL_R_OK;
-
- return AUL_R_ERROR;
-}
-
-extern "C" API int aul_invoke_caller_cb(void* data) {
- auto info = __reply_list.FindByCallerData(data);
- if (info == nullptr)
- return 0;
-
- g_idle_add_full(G_PRIORITY_DEFAULT, [](gpointer data) -> gboolean {
- auto* info = reinterpret_cast<ReplyInfo*>(data);
-
- if (info != nullptr && info->GetCallerCb() != nullptr)
- info->GetCallerCb()(info->GetLaunchedPid(), info->GetCallerData());
-
- delete info;
- return G_SOURCE_REMOVE;
- }, info.release(), nullptr);
-
- return 0;
-}
-
-extern "C" API int aul_launch_app_with_result_async(const char* appid,
- bundle* b, void (*callback)(bundle*, int, void*), void* data) {
- return __launch_app_with_result(APP_START_RES_ASYNC, appid, b, callback,
- data, getuid());
-}
-
-extern "C" API int aul_launch_app_with_result_async_for_uid(const char* appid,
- bundle* b, void (*callback)(bundle*, int, void*), void* data, uid_t uid) {
- return __launch_app_with_result(APP_START_RES_ASYNC, appid, b, callback,
- data, uid);
-}
-
-extern "C" API int aul_send_launch_request_for_uid(const char* appid,
- bundle* b, uid_t uid, aul_reply_cb reply_cb,
- aul_result_cb result_cb, void* user_data) {
- return __send_request_with_callback(APP_SEND_LAUNCH_REQUEST, appid, b,
- uid, reply_cb, result_cb, user_data);
-}
-
-extern "C" API int aul_send_launch_request_sync_for_uid(const char* appid,
- bundle* b, uid_t uid, bundle** res_b) {
- if (!aul_is_initialized()) {
- if (aul_launch_init(nullptr, nullptr) < 0) {
- _E("Failed to initialize aul launch");
- return AUL_R_ENOINIT;
- }
- }
-
- if (appid == nullptr || b == nullptr || res_b == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- int fd = __send_launch_request(appid, b, uid);
- if (fd < 0)
- return fd;
-
- return __recv_reply_bundle(fd, res_b);
-}
-
-extern "C" API int aul_send_resume_request_for_uid(const char* appid,
- bundle* b, uid_t uid, void (*error_cb)(int, void*), void* user_data) {
- return __send_request_with_callback(APP_SEND_RESUME_REQUEST, appid, b,
- uid, nullptr, error_cb, 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 <stdlib.h>
-
-#include "aul_util.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#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 = (char *)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 = (app_info_from_db *)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 = (app_info_from_db *)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);
-}
-
-#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.
- */
-
-#define _GNU_SOURCE
-#include <stdio.h>
-#include <string.h>
-
-#include <xdgmime.h>
-
-#include "aul.h"
-#include "aul_api.h"
-#include "miregex.h"
-#include "menu_db_util.h"
-#include "aul_util.h"
-
-static int __match_content_with_regex(const char *content, regex_t *regex_preg)
-{
- if (regexec(regex_preg, content, 0, NULL, 0) == 0)
- return 1;
- else
- return 0;
-}
-
-API int aul_get_mime_from_content(const char *content, char *mimetype,
- int len)
-{
- char *founded = NULL;
- regex_tbl *miregex_tbl = NULL;
-
- if (content == NULL)
- return AUL_R_EINVAL;
-
- if ((miregex_tbl = miregex_get_regex_table()) == NULL) {
- _E("load miregex_table fail");
- return AUL_R_ERROR;
- }
-
- while (miregex_tbl) {
- if (__match_content_with_regex(content,
- &(miregex_tbl->regex_preg))) {
- founded = miregex_tbl->mimetype;
- SECURE_LOGD("content %s => mimetype %s", content, founded);
- break;
- }
- miregex_tbl = miregex_tbl->next;
- }
-
- if (founded != NULL)
- snprintf(mimetype, len, "%s", founded);
- else {
- /* TODO : should to try to extract from share mime info's data*/
- return AUL_R_ERROR;
- }
-
- return AUL_R_OK;
-}
-
-API int aul_get_mime_description(const char *mimetype, char *desc, int len)
-{
- regex_tbl *miregex_tbl = NULL;
- char *founded = NULL;
-
- if (mimetype == NULL)
- return AUL_R_EINVAL;
-
- if ((miregex_tbl = miregex_get_regex_table()) == NULL) {
- _E("load miregex_table fail");
- return AUL_R_ERROR;
- }
-
- while (miregex_tbl) {
- if (strcmp(miregex_tbl->mimetype, mimetype) == 0) {
- founded = miregex_tbl->desc;
- _D("mimetype %s => desc %s", mimetype, founded);
- break;
- }
- miregex_tbl = miregex_tbl->next;
- }
-
- if (founded != NULL)
- snprintf(desc, len, "%s", founded);
- else {
- /* TODO : should to try to extract from share mime info's comment */
- return AUL_R_ERROR;
- }
-
- return AUL_R_OK;
-}
-
-API int aul_get_mime_extension(const char *mimetype, char *ext, int len)
-{
- const char **extlist;
- int totlen = 0;
- const char *unaliased_mimetype;
-
- if (mimetype == NULL || ext == NULL || len <= 0)
- return AUL_R_EINVAL;
-
- unaliased_mimetype = xdg_mime_unalias_mime_type(mimetype);
- if (unaliased_mimetype == NULL)
- return AUL_R_ERROR;
-
- extlist = xdg_mime_get_file_names_from_mime_type(unaliased_mimetype);
- if (extlist == NULL)
- return AUL_R_ERROR;
-
- if (extlist[0] == NULL)
- return AUL_R_ERROR;
-
- ext[0] = 0;
- while (*extlist != NULL) {
- if (*(extlist + 1) == NULL) {
- snprintf(&ext[totlen], len - totlen, "%s", *extlist);
- break;
- } else {
- snprintf(&ext[totlen], len - totlen, "%s,", *extlist);
- if (strlen(*extlist) > len - totlen - 1)
- break;
- totlen += strlen(*extlist) + 1;
- extlist++;
- }
- }
-
- return AUL_R_OK;
-}
-
-API int aul_get_mime_icon(const char *mimetype, char *iconname, int len)
-{
- const char *icon;
- const char *unaliased_mimetype;
-
- if (mimetype == NULL || iconname == NULL || len <= 0)
- return AUL_R_EINVAL;
-
- unaliased_mimetype = xdg_mime_unalias_mime_type(mimetype);
- if (unaliased_mimetype == NULL)
- return AUL_R_ERROR;
-
- icon = xdg_mime_get_icon(unaliased_mimetype);
- if (icon == NULL)
- icon = xdg_mime_get_generic_icon(unaliased_mimetype);
-
- if (icon != NULL) {
- snprintf(iconname, len, "%s", icon);
- return AUL_R_OK;
- } else
- return AUL_R_ERROR;
-}
-
-API int aul_get_mime_from_file(const char *filename, char *mimetype, int len)
-{
- const char *mime;
- if (filename == NULL)
- return AUL_R_EINVAL;
-
- if (access(filename, F_OK) != 0)
- return AUL_R_EINVAL;
-
- mime = xdg_mime_get_mime_type_for_file(filename, 0);
- if (strcmp(mime, "application/octet-stream") == 0)
- mime = xdg_mime_get_mime_type_from_file_name(filename);
-
- snprintf(mimetype, len, "%s", mime);
- return AUL_R_OK;
-}
-
-API int aul_set_defapp_with_mime(const char *mimetype, const char *defapp)
-{
- /* removed */
- return 0;
-}
-
-API int aul_get_defapp_from_mime(const char *mimetype, char *defapp, int len)
-{
- /* removed */
- return 0;
-}
-
-API int aul_open_content(const char *content)
-{
- /* removed */
- return 0;
-}
-
-API int aul_open_file_with_mimetype(const char *filename,
- const char *mimetype)
-{
- /* removed */
- return 0;
-}
-
-API int aul_open_file(const char *filename)
-{
- /* removed */
- 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.
- */
-
-#define _GNU_SOURCE
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <dirent.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <linux/limits.h>
-
-#include "miregex.h"
-#include "aul_util.h"
-
-#define MIREGEX_DIR SHARE_PREFIX"/miregex"
-#define ONELINE_BUF 1024
-
-typedef struct miregex_file_info_t {
- char *regex;
- char *desc;
-} miregex_file_info;
-
-regex_tbl *miregex_tbl = NULL;
-static time_t miregex_mtime = 0;
-
-static void __free_miregex_file_info(miregex_file_info *info);
-static miregex_file_info *__get_miregex_file_info(const char *path);
-static int __add_miregex(const char *name, const char *regex, const char *desc);
-static int __need_update_miregex_tbl();
-static void __miregex_free_regex_table();
-
-
-
-static void __free_miregex_file_info(miregex_file_info *info)
-{
- if (info == NULL)
- return;
-
- if (info->regex != NULL)
- free(info->regex);
-
- if (info->desc != NULL)
- free(info->desc);
-
- free(info);
-}
-
-static miregex_file_info *__get_miregex_file_info(const char *path)
-{
- FILE *f;
- char oneline[ONELINE_BUF];
- miregex_file_info *info;
-
- f = fopen(path, "r");
- if (f == NULL) {
- _E("miregex file %s is cannot open", path);
- return NULL;
- }
-
- info = (miregex_file_info *)malloc(sizeof(miregex_file_info));
- if (info == NULL) {
- fclose(f);
- return NULL;
- }
-
- info->regex = NULL;
- info->desc = NULL;
-
- while ((info->regex == NULL) || (info->desc == NULL)) {
- memset(oneline, 0, ONELINE_BUF);
- if (fgets(oneline, ONELINE_BUF, f) == NULL)
- break;
-
- oneline[strlen(oneline) - 1] = 0;
-
- if (info->regex == NULL)
- info->regex = strdup(oneline);
- else
- info->desc = strdup(oneline);
- }
-
- fclose(f);
-
- return info;
-}
-
-static int __add_miregex(const char *name, const char *regex, const char *desc)
-{
- regex_tbl *tbl = NULL;
- int error;
- int ret;
- char *msg = NULL;
-
- if (regex == NULL)
- return -1;
-
- tbl = (regex_tbl *)malloc(sizeof(regex_tbl));
- if (NULL == tbl) {
- _E("Malloc failed!");
- return -1;
- }
-
- if ((error = regcomp(&(tbl->regex_preg), regex,
- REG_EXTENDED | REG_NOSUB)) != 0) {
- ret = regerror(error, &(tbl->regex_preg), NULL, 0);
- msg = (char *)malloc(sizeof(char) * ret);
- if (NULL == msg) {
- _E("Malloc failed!");
- if (tbl) {
- free(tbl);
- tbl = NULL;
- }
-
- return -1;
- }
- regerror(error, &(tbl->regex_preg), msg, ret);
- _E("regex compile error - %s", msg);
- if (msg) {
- free(msg);
- msg = NULL;
- }
-
- if (tbl) {
- free(tbl);
- tbl = NULL;
- }
-
- return -1;
- }
-
- tbl->mimetype = strdup(name);
- tbl->regex = strdup(regex);
- if (desc != NULL)
- tbl->desc = strdup(desc);
- tbl->next = miregex_tbl;
- miregex_tbl = tbl;
-
- return 0;
-}
-
-static int __need_update_miregex_tbl()
-{
- struct stat st;
-
- if (stat(MIREGEX_DIR, &st) < 0) {
- _E("stat error - check miregex dir - %s", MIREGEX_DIR);
- return 1;
- }
-
- if (st.st_mtime != miregex_mtime) {
- miregex_mtime = st.st_mtime;
- return 1;
- }
-
- if (miregex_tbl == NULL) {
- miregex_mtime = st.st_mtime;
- return 1;
- }
-
- return 0;
-}
-
-static void __miregex_free_regex_table()
-{
- regex_tbl *tbl;
-
- while (miregex_tbl) {
- if (miregex_tbl->mimetype != NULL)
- free(miregex_tbl->mimetype);
- if (miregex_tbl->regex != NULL)
- free(miregex_tbl->regex);
- if (miregex_tbl->desc != NULL)
- free(miregex_tbl->desc);
- regfree(&(miregex_tbl->regex_preg));
-
- tbl = miregex_tbl;
- miregex_tbl = miregex_tbl->next;
- free(tbl);
- }
-
- miregex_tbl = NULL;
-}
-
-regex_tbl *miregex_get_regex_table()
-{
- DIR *dp;
- struct dirent *dentry = NULL;
- char buf[PATH_MAX];
- miregex_file_info *info;
-
- if (!__need_update_miregex_tbl())
- return miregex_tbl;
-
- _D("*** reload miregex tbl ***");
-
- if (miregex_tbl != NULL)
- __miregex_free_regex_table();
-
- dp = opendir(MIREGEX_DIR);
- if (dp == NULL)
- return NULL;
-
- while ((dentry = readdir(dp)) != NULL) {
- if (dentry->d_name[0] == '.')
- continue;
-
- snprintf(buf, sizeof(buf), "%s/%s", MIREGEX_DIR,
- dentry->d_name);
-
- info = __get_miregex_file_info(buf);
- if (info == NULL)
- continue;
-
- if (__add_miregex(dentry->d_name,
- info->regex, info->desc) < 0) {
- /* TODO : invalid regular expression - will be removed*/
- }
-
- __free_miregex_file_info(info);
- }
-
- closedir(dp);
-
- return miregex_tbl;
-}
+++ /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(boot-sequencer)
+ADD_SUBDIRECTORY(component)
+ADD_SUBDIRECTORY(exec-checker)
+ADD_SUBDIRECTORY(metadata)
--- /dev/null
+SET(TARGET_BOOT_SEQUENCER_PARSER_PLUGIN "boot-sequencer")
+
+SET(SHARED_DIR "${CMAKE_INSTALL_PREFIX}/share")
+
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall -Werror -Winline")
+
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}
+ BOOT_SEQUENCER_PARSER_PLUGIN_SRCS)
+
+ADD_LIBRARY(${TARGET_BOOT_SEQUENCER_PARSER_PLUGIN} SHARED
+ ${BOOT_SEQUENCER_PARSER_PLUGIN_SRCS})
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_BOOT_SEQUENCER_PARSER_PLUGIN}
+ PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
+
+TARGET_LINK_LIBRARIES(${TARGET_BOOT_SEQUENCER_PARSER_PLUGIN} PUBLIC "-ldl")
+
+APPLY_PKG_CONFIG(${TARGET_BOOT_SEQUENCER_PARSER_PLUGIN} PUBLIC
+ BUNDLE_DEPS
+ DLOG_DEPS
+ GLIB_DEPS
+ LIBTZPLATFORM_CONFIG_DEPS
+ LIBXML_DEPS
+ PKGMGR_INFO_DEPS
+ PKGMGR_INSTALLER_DEPS
+)
+
+INSTALL(TARGETS ${TARGET_BOOT_SEQUENCER_PARSER_PLUGIN}
+ DESTINATION ${SYSCONF_INSTALL_DIR}/package-manager/parserlib)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/boot-sequencer.info
+ DESTINATION ${SHARED_DIR}/parser-plugins)
--- /dev/null
+/*
+ * Copyright (c) 2022 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 "app_info.hh"
+
+namespace boot_sequencer {
+
+AppInfo::AppInfo(std::string appid) : appid_(std::move(appid)) {}
+
+const std::string& AppInfo::GetAppId() const {
+ return appid_;
+}
+
+const std::string& AppInfo::GetAfter() const {
+ return after_;
+}
+
+const std::string& AppInfo::GetBefore() const {
+ return before_;
+}
+
+const std::string& AppInfo::GetRequires() const {
+ return requires_;
+}
+
+const std::string& AppInfo::GetConflicts() const {
+ return conflicts_;
+}
+
+const std::string& AppInfo::GetArgs() const {
+ return args_;
+}
+
+const std::string& AppInfo::GetVconf() const {
+ return vconf_;
+}
+
+const std::string& AppInfo::GetPathExists() const {
+ return path_exists_;
+}
+
+const std::string& AppInfo::GetBackgroundLaunch() const {
+ return background_launch_;
+}
+
+const std::string& AppInfo::GetWaitUntilReady() const {
+ return wait_until_ready_;
+}
+
+const std::string& AppInfo::GetTimeout() const {
+ return timeout_;
+}
+
+void AppInfo::SetAfter(std::string after) {
+ if (after_.empty())
+ after_ = std::move(after);
+ else
+ after_ += "|" + std::move(after);
+}
+
+void AppInfo::SetBefore(std::string before) {
+ if (before_.empty())
+ before_ = std::move(before);
+ else
+ before_ += "|" + std::move(before);
+}
+
+void AppInfo::SetRequires(std::string requires_dep) {
+ if (requires_.empty())
+ requires_ = std::move(requires_dep);
+ else
+ requires_ += "|" + std::move(requires_dep);
+}
+
+void AppInfo::SetConflicts(std::string conflicts) {
+ if (conflicts_.empty())
+ conflicts_ = std::move(conflicts);
+ else
+ conflicts_ += "|" + std::move(conflicts);
+}
+
+void AppInfo::SetArgs(std::string args) {
+ args_ = std::move(args);
+}
+
+void AppInfo::SetVconf(std::string vconf) {
+ if (vconf_.empty())
+ vconf_ = std::move(vconf);
+ else
+ vconf_ += "|" + std::move(vconf);
+}
+
+void AppInfo::SetPathExists(std::string path_exists) {
+ if (path_exists_.empty())
+ path_exists_ = std::move(path_exists);
+ else
+ path_exists_ += "|" + std::move(path_exists);
+}
+
+void AppInfo::SetBackgroundLaunch(std::string background_launch) {
+ background_launch_ = std::move(background_launch);
+}
+
+void AppInfo::SetWaitUntilReady(std::string wait_until_ready) {
+ wait_until_ready_ = std::move(wait_until_ready);
+}
+
+void AppInfo::SetTimeout(std::string timeout) {
+ timeout_ = std::move(timeout);
+}
+
+} // namespace boot_sequencer
--- /dev/null
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef APP_INFO_HH_
+#define APP_INFO_HH_
+
+#include <string>
+
+namespace boot_sequencer {
+
+class AppInfo {
+ public:
+ explicit AppInfo(std::string appid);
+ virtual ~AppInfo() = default;
+
+ const std::string& GetAppId() const;
+ const std::string& GetAfter() const;
+ const std::string& GetBefore() const;
+ const std::string& GetRequires() const;
+ const std::string& GetConflicts() const;
+ const std::string& GetArgs() const;
+ const std::string& GetVconf() const;
+ const std::string& GetPathExists() const;
+ const std::string& GetBackgroundLaunch() const;
+ const std::string& GetWaitUntilReady() const;
+ const std::string& GetTimeout() const;
+
+ void SetAfter(std::string after);
+ void SetBefore(std::string before);
+ void SetRequires(std::string requires_dep);
+ void SetConflicts(std::string conflicts);
+ void SetArgs(std::string args);
+ void SetVconf(std::string vconf);
+ void SetPathExists(std::string path_exists);
+ void SetBackgroundLaunch(std::string background_launch);
+ void SetWaitUntilReady(std::string wait_until_ready);
+ void SetTimeout(std::string timeout);
+
+ private:
+ std::string appid_;
+ std::string after_;
+ std::string before_;
+ std::string requires_;
+ std::string conflicts_;
+ std::string args_;
+ std::string vconf_;
+ std::string path_exists_;
+ std::string background_launch_;
+ std::string wait_until_ready_;
+ std::string timeout_;
+};
+
+} // namespace boot_sequencer
+
+#endif // APP_INFO_HH_
--- /dev/null
+/*
+ * Copyright (c) 2022 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 <tzplatform_config.h>
+
+#include <memory>
+
+#include "appsvc_db.hh"
+#include "log_private.hh"
+
+namespace boot_sequencer {
+namespace {
+
+constexpr const uid_t ROOT_UID = 0;
+
+const uid_t GLOBAL_USER = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
+
+constexpr const char QUERY_SELECT[] =
+ "SELECT appid, after, before, requires, conflicts, vconf, path_exists, "
+ "args, background_launch, wait_until_ready, timeout "
+ "FROM boot_sequence WHERE package = ?;";
+constexpr const char QUERY_INSERT_OR_REPLACE[] =
+ "INSERT OR REPLACE INTO boot_sequence(package, appid, after, before, "
+ "requires, conflicts, vconf, path_exists, args, background_launch, "
+ "wait_until_ready, timeout) "
+ "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
+constexpr const char QUERY_DELETE[] =
+ "DELETE FROM boot_sequence WHERE package = ?;";
+
+} // namespace
+
+AppSvcDB::AppSvcDB(uid_t uid) : Database(GetDBPath(uid)) {
+}
+
+AppSvcDB::~AppSvcDB() = default;
+
+std::vector<std::shared_ptr<AppInfo>> AppSvcDB::Select(
+ const std::string& package) {
+ std::vector<std::string> bind_text { package };
+ auto cursor = Query(QUERY_SELECT, bind_text);
+ if (cursor == nullptr)
+ return {};
+
+ cursor->Execute();
+ int idx;
+ std::vector<std::shared_ptr<AppInfo>> app_infos;
+ while (!cursor->IsDone()) {
+ idx = 0;
+ auto appid = cursor->GetColumn(idx++);
+ auto app_info = std::make_shared<AppInfo>(std::move(appid));
+ app_info->SetAfter(cursor->GetColumn(idx++));
+ app_info->SetBefore(cursor->GetColumn(idx++));
+ app_info->SetRequires(cursor->GetColumn(idx++));
+ app_info->SetConflicts(cursor->GetColumn(idx++));
+ app_info->SetVconf(cursor->GetColumn(idx++));
+ app_info->SetPathExists(cursor->GetColumn(idx++));
+ app_info->SetArgs(cursor->GetColumn(idx++));
+ app_info->SetBackgroundLaunch(cursor->GetColumn(idx++));
+ app_info->SetWaitUntilReady(cursor->GetColumn(idx++));
+ app_info->SetTimeout(cursor->GetColumn(idx++));
+ app_infos.push_back(std::move(app_info));
+ cursor->Next();
+ }
+
+ return app_infos;
+}
+
+void AppSvcDB::Insert(const std::string& package,
+ const std::shared_ptr<AppInfo>& app_info) {
+ std::vector<std::string> bind_text {
+ package,
+ app_info->GetAppId(),
+ app_info->GetAfter(),
+ app_info->GetBefore(),
+ app_info->GetRequires(),
+ app_info->GetConflicts(),
+ app_info->GetVconf(),
+ app_info->GetPathExists(),
+ app_info->GetArgs(),
+ app_info->GetBackgroundLaunch(),
+ app_info->GetWaitUntilReady(),
+ app_info->GetTimeout()
+ };
+ auto cursor = Query(QUERY_INSERT_OR_REPLACE, bind_text);
+ if (cursor == nullptr)
+ THROW(-1);
+
+ if (!cursor->Execute())
+ THROW(-1);
+}
+
+void AppSvcDB::Delete(const std::string& package) {
+ std::vector<std::string> bind_text { package };
+ auto cursor = Query(QUERY_DELETE, bind_text);
+ if (cursor == nullptr)
+ THROW(-1);
+
+ if (!cursor->Execute())
+ THROW(-1);
+}
+
+std::string AppSvcDB::GetDBPath(uid_t uid) {
+ std::string db_path;
+ if (uid == ROOT_UID || uid == GLOBAL_USER) {
+ db_path = std::string(tzplatform_getenv(TZ_SYS_DB)) + "/.appsvc.db";
+ } else {
+ db_path = std::string(tzplatform_getenv(TZ_SYS_DB)) + "/user/" +
+ std::to_string(uid) + "/.appsvc.db";
+ }
+ return db_path;
+}
+
+} // namespace boot_sequencer
--- /dev/null
+/*
+ * Copyright (c) 2022 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 APPSVC_DB_HH_
+#define APPSVC_DB_HH_
+
+#include <unistd.h>
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "app_info.hh"
+#include "database.hh"
+
+namespace boot_sequencer {
+
+class AppSvcDB : public Database {
+ public:
+ explicit AppSvcDB(uid_t uid);
+ virtual ~AppSvcDB();
+
+ std::vector<std::shared_ptr<AppInfo>> Select(const std::string& package);
+ void Insert(const std::string& package,
+ const std::shared_ptr<AppInfo>& app_info);
+ void Delete(const std::string& package);
+
+ private:
+ static std::string GetDBPath(uid_t uid);
+};
+
+} // namespace boot_sequencer
+
+#endif // APPSVC_DB_HH_
--- /dev/null
+/*
+ * Copyright (c) 2022 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 "cert_checker.hh"
+
+#include <dlfcn.h>
+#include <pkgmgr-info.h>
+
+#include <memory>
+
+#include "log_private.hh"
+
+namespace boot_sequencer {
+namespace {
+
+constexpr const char LIBCERT_SVC_VCORE[] = "libcert-svc-vcore.so.2";
+
+typedef struct {
+ void* privatePtr;
+} CertSvcInstance;
+
+typedef struct {
+ size_t privateHandler;
+ CertSvcInstance privateInstance;
+} CertSvcCertificate;
+
+typedef enum {
+ CERTSVC_FORM_DER,
+ CERTSVC_FORM_DER_BASE64,
+} CertSvcCertificateFrom;
+
+typedef enum {
+ CERTSVC_VISIBILITY_DEVELOPER = 1,
+ CERTSVC_VISIBILITY_PUBLIC = 1 << 6,
+ CERTSVC_VISIBILITY_PARTNER = 1 << 7,
+ CERTSVC_VISIBILITY_PLATFORM = 1 << 10
+} CertSvcVisibility;
+
+class CertSvc {
+ public:
+ static CertSvc& GetInst() {
+ static CertSvc inst;
+ if (inst.disposed_)
+ inst.Init();
+
+ return inst;
+ }
+
+ void Dispose() {
+ if (disposed_)
+ return;
+
+ certsvc_certificate_free_ = nullptr;
+ certsvc_certificate_get_visibility_ = nullptr;
+ certsvc_certificate_new_from_memory_ = nullptr;
+ certsvc_instance_free_ = nullptr;
+ certsvc_instance_new_ = nullptr;
+
+ if (handle_ != nullptr) {
+ dlclose(handle_);
+ handle_ = nullptr;
+ }
+
+ disposed_ = true;
+ }
+
+ int GetVisibility(const std::string& cert_value) {
+ if (disposed_ || cert_value.empty())
+ return CERTSVC_VISIBILITY_PUBLIC;
+
+ CertSvcInstance instance;
+ int ret = certsvc_instance_new_(&instance);
+ if (ret != 1) {
+ _E("certsvc_instance_new() is failed. error(%d)", ret);
+ return CERTSVC_VISIBILITY_PUBLIC;
+ }
+
+ CertSvcCertificate certificate;
+ ret = certsvc_certificate_new_from_memory_(instance,
+ reinterpret_cast<const unsigned char*>(cert_value.c_str()),
+ cert_value.length(), CERTSVC_FORM_DER_BASE64, &certificate);
+ if (ret != 1) {
+ _E("certsvc_certificate_new_from_memory() is failed. error(%d)", ret);
+ certsvc_instance_free_(instance);
+ return CERTSVC_VISIBILITY_PUBLIC;
+ }
+
+ CertSvcVisibility visibility = CERTSVC_VISIBILITY_PUBLIC;
+ ret = certsvc_certificate_get_visibility_(certificate, &visibility);
+ if (ret != 1)
+ _E("certsvc_certificate_get_visibility() is failed. error(%d)", ret);
+
+ certsvc_certificate_free_(certificate);
+ certsvc_instance_free_(instance);
+ return static_cast<int>(visibility);
+ }
+
+ private:
+ using CertSvcInstanceNew = int (*)(CertSvcInstance*);
+ using CertSvcInstanceFree = int (*)(CertSvcInstance);
+ using CertSvcCertificateNewFromMemory =
+ int (*)(CertSvcInstance, const unsigned char*, size_t,
+ CertSvcCertificateFrom, CertSvcCertificate*);
+ using CertSvcCertificateGetVisibility =
+ int (*)(CertSvcCertificate, CertSvcVisibility*);
+ using CertSvcCertificateFree = int (*)(CertSvcCertificate);
+
+ CertSvc() = default;
+
+ ~CertSvc() {
+ Dispose();
+ }
+
+ void Init() {
+ std::string path = std::string(LIBDIR) + "/" +
+ std::string(LIBCERT_SVC_VCORE);
+ void* handle = dlopen(path.c_str(), RTLD_LAZY | RTLD_LOCAL);
+ if (handle == nullptr) {
+ _E("dlopen() is failed. error(%s)", dlerror());
+ return;
+ }
+ auto dlcloser = [](void* p) { dlclose(p); };
+ std::unique_ptr<void, decltype(dlcloser)> handle_auto(handle, dlcloser);
+
+ certsvc_instance_new_ = reinterpret_cast<CertSvcInstanceNew>(
+ dlsym(handle, "certsvc_instance_new"));
+ if (certsvc_instance_new_ == nullptr) {
+ _E("dlsym() is failed. 'certsvc_isntance_new'");
+ return;
+ }
+
+ certsvc_instance_free_ = reinterpret_cast<CertSvcInstanceFree>(
+ dlsym(handle, "certsvc_instance_free"));
+ if (certsvc_instance_free_ == nullptr) {
+ _E("dlsym() is failed. 'certsvc_instance_free'");
+ return;
+ }
+
+ certsvc_certificate_new_from_memory_ =
+ reinterpret_cast<CertSvcCertificateNewFromMemory>(
+ dlsym(handle, "certsvc_certificate_new_from_memory"));
+ if (certsvc_certificate_new_from_memory_ == nullptr) {
+ _E("dlsym() is failed. 'certsvc_certificate_new_from_memory'");
+ return;
+ }
+
+ certsvc_certificate_get_visibility_ =
+ reinterpret_cast<CertSvcCertificateGetVisibility>(
+ dlsym(handle, "certsvc_certificate_get_visibility"));
+ if (certsvc_certificate_get_visibility_ == nullptr) {
+ _E("dlsym() is failed. 'certsvc_certificate_get_visibility'");
+ return;
+ }
+
+ certsvc_certificate_free_ = reinterpret_cast<CertSvcCertificateFree>(
+ dlsym(handle, "certsvc_certificate_free"));
+ if (certsvc_certificate_free_ == nullptr) {
+ _E("dlsym() is failed. 'certsvc_certificate_free'");
+ return;
+ }
+
+ handle_ = handle_auto.release();
+ disposed_ = false;
+ }
+
+ private:
+ bool disposed_ = true;
+ void* handle_ = nullptr;
+ CertSvcInstanceNew certsvc_instance_new_ = nullptr;
+ CertSvcInstanceFree certsvc_instance_free_ = nullptr;
+ CertSvcCertificateNewFromMemory certsvc_certificate_new_from_memory_ = nullptr;
+ CertSvcCertificateGetVisibility certsvc_certificate_get_visibility_ = nullptr;
+ CertSvcCertificateFree certsvc_certificate_free_ = nullptr;
+};
+
+bool IsPreload(const std::string& pkgid, uid_t uid) {
+ pkgmgrinfo_pkginfo_h handle;
+ int ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid.c_str(), uid, &handle);
+ if (ret != PMINFO_R_OK) {
+ _E("pkgmgrinfo_pkginfo_get_usr_pkginfo() is failed. error(%d)", ret);
+ return false;
+ }
+
+ bool preload = false;
+ ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
+ if (ret != PMINFO_R_OK)
+ _E("pkgmgrinfo_pkginfo_is_preload() is failed. error(%d)", ret);
+
+ pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+ return preload;
+}
+
+std::string GetCertValueFromPkgInfo(const std::string& pkgid, uid_t uid) {
+ pkgmgrinfo_certinfo_h certinfo;
+ int ret = pkgmgrinfo_pkginfo_create_certinfo(&certinfo);
+ if (ret != PMINFO_R_OK) {
+ _E("pkgmgrinfo_pkginfo_create_certinfo() is failed. error(%d)", ret);
+ return {};
+ }
+ auto certinfo_auto = std::unique_ptr<
+ std::remove_pointer<pkgmgrinfo_certinfo_h>::type,
+ decltype(pkgmgrinfo_pkginfo_destroy_certinfo)*>(
+ certinfo, pkgmgrinfo_pkginfo_destroy_certinfo);
+
+ ret = pkgmgrinfo_pkginfo_load_certinfo(pkgid.c_str(), certinfo, uid);
+ if (ret != PMINFO_R_OK) {
+ _E("pkgmgrinfo_pkginfo_load_certinfo() is failed. error(%d)", ret);
+ return {};
+ }
+
+ const char* cert_value;
+ ret = pkgmgrinfo_pkginfo_get_cert_value(certinfo,
+ PMINFO_DISTRIBUTOR_ROOT_CERT, &cert_value);
+ if (ret != PMINFO_R_OK || cert_value == nullptr) {
+ _E("pkgmgrinfo_pkginfo_get_cert_value() is failed. error(%d)", ret);
+ return {};
+ }
+
+ return std::string(cert_value);
+}
+
+} // namespace
+
+
+bool CertChecker::IsPrivilegedPackage(const std::string& pkgid, uid_t uid) {
+ if (IsPreload(pkgid, uid)) {
+ _W("%s is preload package", pkgid.c_str());
+ return true;
+ }
+
+ int visibility = CertSvc::GetInst().GetVisibility(
+ GetCertValueFromPkgInfo(pkgid, uid));
+ _D("Visibility: %d", visibility);
+ if (visibility & CERTSVC_VISIBILITY_PLATFORM ||
+ visibility & CERTSVC_VISIBILITY_PARTNER)
+ return true;
+
+ return false;
+}
+
+} // namespace boot_sequencer
--- /dev/null
+/*
+ * Copyright (c) 2022 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 CERT_CHECKER_HH_
+#define CERT_CHECKER_HH_
+
+#include <sys/types.h>
+
+#include <string>
+
+namespace boot_sequencer {
+
+class CertChecker {
+ public:
+ static bool IsPrivilegedPackage(const std::string& pkgid, uid_t uid);
+};
+
+} // namespace boot_sequencer
+
+#endif // CERT_CHECKER_HH_
--- /dev/null
+type="tag";name="ui-application";path="/etc/package-manager/parserlib/libboot-sequencer.so"
+type="tag";name="service-application";path="/etc/package-manager/parserlib/libboot-sequencer.so"
--- /dev/null
+/*
+ * Copyright (c) 2022 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 <unistd.h>
+
+#include <memory>
+
+#include "database.hh"
+#include "exception.hh"
+#include "log_private.hh"
+
+namespace boot_sequencer {
+
+static const int BUSY_WAITING_USEC = 50000;
+static const int BUSY_WAITING_MAX = 40;
+
+Database::Cursor::~Cursor() {
+ if (stmt_ != nullptr)
+ sqlite3_finalize(stmt_);
+}
+
+Database::Cursor::Cursor(sqlite3* db, const std::string& query,
+ const std::vector<std::string>& bind_text) {
+ sqlite3_stmt* stmt;
+ int ret = sqlite3_prepare_v2(db, query.c_str(), query.length(), &stmt,
+ nullptr);
+ auto stmt_auto = std::unique_ptr<sqlite3_stmt, decltype(sqlite3_finalize)*>(
+ stmt, sqlite3_finalize);
+ if (ret != SQLITE_OK) {
+ _E("sqlite3_prepare_v2() is failed. error(%s:%d)", sqlite3_errmsg(db), ret);
+ THROW(-ret);
+ }
+
+ int index = 1;
+ for (auto const& text : bind_text) {
+ ret = sqlite3_bind_text(stmt, index++, text.c_str(), -1, SQLITE_TRANSIENT);
+ if (ret != SQLITE_OK) {
+ _E("sqlite3_bind_text() is failed. index(%d), error(%s:%d)",
+ index - 1, sqlite3_errmsg(db), ret);
+ THROW(-ret);
+ }
+ }
+
+ stmt_ = stmt_auto.release();
+}
+
+void Database::Cursor::Next() {
+ int ret = sqlite3_step(stmt_);
+ if (ret == SQLITE_ROW)
+ return;
+
+ if (ret == SQLITE_DONE)
+ _D("SQLITE_DONE");
+ else if (ret == SQLITE_BUSY)
+ _E("SQLITE_BUSY");
+ else if (ret == SQLITE_ERROR)
+ _E("SQLITE_ERROR");
+ else if (ret == SQLITE_MISUSE)
+ _E("SQLITE_MISUSE");
+
+ done_ = true;
+}
+
+bool Database::Cursor::IsDone() const {
+ return done_;
+}
+
+bool Database::Cursor::Execute() {
+ int ret = sqlite3_step(stmt_);
+ if (ret != SQLITE_DONE) {
+ _E("sqlite3_step() is failed. error(%d)", ret);
+ if (ret != SQLITE_ROW)
+ done_ = true;
+
+ return false;
+ }
+
+ done_ = true;
+ return true;
+}
+
+std::string Database::Cursor::GetColumn(int index) {
+ auto* text = reinterpret_cast<const char*>(sqlite3_column_text(stmt_, index));
+ if (text)
+ return std::string(text);
+
+ return {};
+}
+
+Database::Database(std::string path) : path_(std::move(path)) {}
+
+Database::~Database() {
+ Close();
+}
+
+void Database::BeginTransaction() {
+ int ret = sqlite3_exec(db_, "BEGIN TRANSACTION", nullptr, nullptr, nullptr);
+ if (ret != SQLITE_OK) {
+ _E("sqlite3_exec() is failed. error(%s:%d)", sqlite3_errmsg(db_), ret);
+ THROW(-ret);
+ }
+}
+
+void Database::EndTransaction() {
+ int ret = sqlite3_exec(db_, "END TRANSACTION", nullptr, nullptr, nullptr);
+ if (ret != SQLITE_OK) {
+ _E("sqlite3_exec() is failed. error(%s:%d)", sqlite3_errmsg(db_), ret);
+ THROW(-ret);
+ }
+}
+
+void Database::Rollback() {
+ int ret = sqlite3_exec(db_, "ROLLBACK", nullptr, nullptr, nullptr);
+ if (ret != SQLITE_OK) {
+ _E("sqlite3_exec() is failed. error(%s:%d", sqlite3_errmsg(db_), ret);
+ THROW(-ret);
+ }
+}
+
+void Database::Open() {
+ sqlite3* db;
+ int ret = sqlite3_open_v2(path_.c_str(), &db, SQLITE_OPEN_READWRITE, nullptr);
+ if (ret != SQLITE_OK) {
+ _E("sqlite3_open_v2() is failed. error(%d)", ret);
+ sqlite3_close_v2(db);
+ THROW(-ret);
+ }
+
+ ret = sqlite3_busy_handler(db, BusyHandler,
+ static_cast<void*>(const_cast<char*>(path_.c_str())));
+ if (ret != SQLITE_OK) {
+ _E("sqlite3_busy_handler() is failed. error(%s:%d)",
+ sqlite3_errmsg(db), ret);
+ sqlite3_close_v2(db);
+ THROW(-ret);
+ }
+
+ ret = sqlite3_exec(db, "PRAGMA foreign_keys=ON", nullptr, nullptr, nullptr);
+ if (ret != SQLITE_OK) {
+ _E("sqlite3_exec() is failed. error(%s:%d)", sqlite3_errmsg(db), ret);
+ sqlite3_close_v2(db);
+ THROW(-ret);
+ }
+
+ db_ = db;
+}
+
+void Database::Close() {
+ if (db_) {
+ sqlite3_close_v2(db_);
+ db_ = nullptr;
+ }
+}
+
+std::shared_ptr<Database::Cursor> Database::Query(const std::string& query,
+ const std::vector<std::string>& bind_text) {
+ try {
+ auto cursor = std::shared_ptr<Database::Cursor>(
+ new Database::Cursor(db_, query, bind_text));
+ return cursor;
+ } catch (const Exception& e) {
+ return nullptr;
+ }
+}
+
+int Database::BusyHandler(void* data, int count) {
+ if (count < BUSY_WAITING_MAX) {
+ usleep(BUSY_WAITING_USEC);
+ return 1;
+ }
+
+ auto* path = static_cast<char*>(data);
+ _E("Database(%s) is busy", path);
+ return 0;
+}
+
+} // namespace boot_sequencer
--- /dev/null
+/*
+ * Copyright (c) 2022 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 DATABASE_HH_
+#define DATABASE_HH_
+
+#include <sqlite3.h>
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "exception.hh"
+
+namespace boot_sequencer {
+
+class Database {
+ public:
+ class Cursor {
+ public:
+ ~Cursor();
+ Cursor(const Cursor&) = delete;
+ Cursor& operator=(const Cursor&) = delete;
+
+ void Next();
+ bool IsDone() const;
+ bool Execute();
+ std::string GetColumn(int index);
+
+ private:
+ friend class Database;
+ Cursor(sqlite3* db, const std::string& query,
+ const std::vector<std::string>& bind_text);
+
+ private:
+ sqlite3_stmt* stmt_ = nullptr;
+ bool done_ = false;
+ };
+
+ explicit Database(std::string path);
+ virtual ~Database();
+
+ void Open();
+ void Close();
+ void BeginTransaction();
+ void EndTransaction();
+ void Rollback();
+ std::shared_ptr<Cursor> Query(const std::string& query,
+ const std::vector<std::string>& bind_text);
+
+ private:
+ static int BusyHandler(void* data, int count);
+
+ private:
+ std::string path_;
+ sqlite3* db_ = nullptr;
+};
+
+} // namespace boot_sequencer
+
+#endif // DATABASE_HH_
--- /dev/null
+/*
+ * Copyright (c) 2022 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 EVENT_TYPE_HH_
+#define EVENT_TYPE_HH_
+
+namespace boot_sequencer {
+
+enum class EventType {
+ Install,
+ Uninstall,
+ Upgrade,
+ Undo,
+};
+
+} // namespace boot_sequencer
+
+#endif // EVENT_TYPE_HH_
--- /dev/null
+/*
+ * Copyright (c) 2022 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 "exception.hh"
+
+#include <libgen.h>
+
+namespace boot_sequencer {
+
+Exception::Exception(int error_code, std::string file, int line)
+ : error_code_(error_code) {
+ message_ = std::string(basename(const_cast<char*>(file.c_str()))) + ":" +
+ std::to_string(line) + " code:" + std::to_string(error_code_);
+}
+
+const char* Exception::what() const noexcept {
+ return message_.c_str();
+}
+
+int Exception::GetErrorCode() const {
+ return error_code_;
+}
+
+} // namespace boot_sequencer
--- /dev/null
+/*
+ * Copyright (c) 2022 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 EXCEPTION_HH_
+#define EXCEPTION_HH_
+
+#include <exception>
+#include <string>
+
+#define THROW(error_code) throw Exception(error_code, __FILE__, __LINE__)
+
+namespace boot_sequencer {
+
+class Exception : public std::exception {
+ public:
+ explicit Exception(int error_code, std::string file, int line);
+ virtual ~Exception() = default;
+
+ virtual const char* what() const noexcept;
+ int GetErrorCode() const;
+
+ private:
+ int error_code_;
+ std::string message_;
+};
+
+} // namespace boot_sequencer
+
+#endif // EXCEPTION_HH_
--- /dev/null
+/*
+ * Copyright (c) 2022 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 LOG_PRIVATE_HH_
+#define LOG_PRIVATE_HH_
+
+#include <dlog.h>
+
+#undef LOG_TAG
+#define LOG_TAG "BOOT_SEQUENCER_PLUGIN_PARSER"
+
+#undef _E
+#define _E LOGE
+
+#undef _W
+#define _W LOGW
+
+#undef _I
+#define _I LOGI
+
+#undef _D
+#define _D LOGD
+
+#endif // LOG_PRIVATE_HH_
--- /dev/null
+/*
+ * Copyright (c) 2022 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 "package_event_args.hh"
+
+namespace boot_sequencer {
+
+PackageEventArgs::PackageEventArgs(std::string package, EventType event_type)
+ : package_(std::move(package)),
+ event_type_(event_type) {
+}
+
+const std::string& PackageEventArgs::GetPackage() const {
+ return package_;
+}
+
+EventType PackageEventArgs::GetEventType() const {
+ return event_type_;
+}
+
+void PackageEventArgs::Push(std::shared_ptr<AppInfo> app_info) {
+ app_infos_.push_back(std::move(app_info));
+}
+
+const std::vector<std::shared_ptr<AppInfo>>&
+PackageEventArgs::GetAppInfos() const {
+ return app_infos_;
+}
+
+void PackageEventArgs::Reset(std::vector<std::shared_ptr<AppInfo>> app_infos) {
+ app_infos_ = std::move(app_infos);
+}
+
+} // namespace boot_sequencer
--- /dev/null
+/*
+ * Copyright (c) 2022 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 PACKAGE_EVENT_ARGS_HH_
+#define PACKAGE_EVENT_ARGS_HH_
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "app_info.hh"
+#include "event_type.hh"
+
+namespace boot_sequencer {
+
+class PackageEventArgs {
+ public:
+ PackageEventArgs(std::string package, EventType event_type);
+
+ const std::string& GetPackage() const;
+ EventType GetEventType() const;
+
+ void Push(std::shared_ptr<AppInfo> app_info);
+ const std::vector<std::shared_ptr<AppInfo>>& GetAppInfos() const;
+ void Reset(std::vector<std::shared_ptr<AppInfo>> app_infos);
+
+ private:
+ std::string package_;
+ EventType event_type_;
+ std::vector<std::shared_ptr<AppInfo>> app_infos_;
+};
+
+} // namespace boot_sequencer
+
+#endif // PACKAGE_EVENT_ARGS_HH_
--- /dev/null
+/*
+ * Copyright (c) 2022 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 "parser_plugin.hh"
+
+#include <pkgmgr-info.h>
+#include <pkgmgr_installer_info.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <bundle_cpp.h>
+
+#include <memory>
+
+#include "cert_checker.hh"
+#include "log_private.hh"
+
+namespace boot_sequencer {
+namespace {
+
+constexpr const char REQUIRED_API_VERSION[] = "7";
+
+std::string GetName(xmlNode* node) {
+ if (node == nullptr)
+ return {};
+
+ return std::string(reinterpret_cast<const char*>(node->name));
+}
+
+std::string GetAttribute(xmlNode* node, const char* key) {
+ xmlChar* val = xmlGetProp(node, reinterpret_cast<const xmlChar*>(key));
+ if (val != nullptr) {
+ std::string attr(reinterpret_cast<char*>(val));
+ xmlFree(val);
+ return attr;
+ }
+
+ return {};
+}
+
+uid_t GetTargetUid() {
+ uid_t target_uid;
+ pkgmgr_installer_info_get_target_uid(&target_uid);
+ return target_uid;
+}
+
+bool IsSupported(const std::string& appid, uid_t uid) {
+ pkgmgrinfo_appinfo_h handle;
+ int ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid.c_str(), uid, &handle);
+ if (ret != PMINFO_R_OK)
+ return false;
+
+ auto handle_auto = std::unique_ptr<
+ std::remove_pointer<pkgmgrinfo_appinfo_h>::type,
+ decltype(pkgmgrinfo_appinfo_destroy_appinfo)*>(
+ handle, pkgmgrinfo_appinfo_destroy_appinfo);
+
+ char* apptype;
+ ret = pkgmgrinfo_appinfo_get_apptype(handle, &apptype);
+ if (ret != PMINFO_R_OK)
+ return false;
+
+ char* api_version;
+ ret = pkgmgrinfo_appinfo_get_api_version(handle, &api_version);
+ if (ret != PMINFO_R_OK)
+ return false;
+
+ if (strverscmp(REQUIRED_API_VERSION, api_version) <= 0)
+ return true;
+
+ return false;
+}
+
+} // namespace
+
+ParserPlugin& ParserPlugin::GetInst() {
+ static ParserPlugin inst;
+ return inst;
+}
+
+void ParserPlugin::Init(xmlDocPtr doc, std::string package,
+ EventType event_type) {
+ doc_ = doc;
+ args_ = std::unique_ptr<PackageEventArgs>(
+ new PackageEventArgs(package, event_type));
+ backup_args_ = std::unique_ptr<PackageEventArgs>(
+ new PackageEventArgs(std::move(package), event_type));
+}
+
+int ParserPlugin::Process() {
+ int ret = Prepare();
+ if (ret != 0)
+ return ret;
+
+ ret = StepBackup();
+ if (ret != 0) {
+ Post();
+ return ret;
+ }
+
+ if (args_->GetEventType() == EventType::Install)
+ ret = StepInstall();
+ else if (args_->GetEventType() == EventType::Uninstall)
+ ret = StepUninstall();
+ else if (args_->GetEventType() == EventType::Upgrade)
+ ret = StepUpgrade();
+
+ if (ret != 0)
+ Rollback();
+
+ Post();
+ return ret;
+}
+
+int ParserPlugin::Undo() {
+ _E("Undo");
+ int ret = Prepare();
+ if (ret != 0)
+ return ret;
+
+ ret = StepUninstall();
+ if (ret != 0)
+ return ret;
+
+ ret = StepRestore();
+ Post();
+ return ret;
+}
+
+ParserPlugin::ParserPlugin() : db_(new AppSvcDB(GetTargetUid())) {}
+
+int ParserPlugin::Prepare() {
+ try {
+ db_->Open();
+ db_->BeginTransaction();
+ } catch (const Exception& e) {
+ _E("Exception(%s) occurs", e.what());
+ return e.GetErrorCode();
+ }
+
+ return 0;
+}
+
+int ParserPlugin::StepBackup() {
+ try {
+ auto app_infos = db_->Select(backup_args_->GetPackage());
+ backup_args_->Reset(std::move(app_infos));
+ } catch (const Exception& e) {
+ _E("Exception(%s) occurs", e.what());
+ return e.GetErrorCode();
+ }
+
+ return 0;
+}
+
+int ParserPlugin::StepInstall() {
+ if (!CertChecker::IsPrivilegedPackage(args_->GetPackage(), GetTargetUid())) {
+ _W("%s is not a platform package", args_->GetPackage().c_str());
+ return 0;
+ }
+
+ int ret = Parse();
+ if (ret != 0)
+ return ret;
+
+ for (auto& app_info : args_->GetAppInfos()) {
+ try {
+ db_->Insert(args_->GetPackage(), app_info);
+ } catch (const Exception& e) {
+ _E("Exception(%s) occurs", e.what());
+ return e.GetErrorCode();
+ }
+ }
+
+ return 0;
+}
+
+int ParserPlugin::StepUninstall() {
+ try {
+ db_->Delete(args_->GetPackage());
+ } catch (const Exception& e) {
+ _E("Exception(%s) occurs", e.what());
+ return e.GetErrorCode();
+ }
+
+ return 0;
+}
+
+int ParserPlugin::StepUpgrade() {
+ int ret = StepUninstall();
+ if (ret != 0)
+ return ret;
+
+ return StepInstall();
+}
+
+int ParserPlugin::StepRestore() {
+ _E("Restore");
+ for (auto& app_info : backup_args_->GetAppInfos()) {
+ try {
+ db_->Insert(backup_args_->GetPackage(), app_info);
+ } catch (const Exception& e) {
+ _E("Exception(%s) occurs", e.what());
+ return e.GetErrorCode();
+ }
+ }
+
+ return 0;
+}
+
+void ParserPlugin::Post() {
+ try {
+ db_->EndTransaction();
+ db_->Close();
+ } catch (const Exception& e) {
+ _E("Exception(%s) occurs", e.what());
+ }
+}
+
+void ParserPlugin::Rollback() {
+ try {
+ db_->Rollback();
+ } catch (const Exception& e) {
+ _E("Exception(%s) occurs", e.what());
+ }
+}
+
+int ParserPlugin::Parse() {
+ xmlNode* root = xmlDocGetRootElement(doc_);
+ if (root == nullptr) {
+ _E("xmlDocGetRootElement() is failed");
+ return -1;
+ }
+
+ for (xmlNode* node = root->children; node; node = node->next) {
+ std::string appid = GetAttribute(node, "appid");
+ if (appid.empty())
+ continue;
+
+ std::string comp_type = GetName(node);
+ if (comp_type == "widget-application" || comp_type == "watch-application")
+ continue;
+
+ if (!IsSupported(appid, GetTargetUid())) continue;
+
+ AppInfo* app_info = nullptr;
+ for (xmlNode* child_node = node->children; child_node;
+ child_node = child_node->next) {
+ std::string name = GetName(child_node);
+ if (name != "boot-sequence")
+ continue;
+
+ app_info = new (std::nothrow) AppInfo(appid);
+ if (app_info == nullptr) {
+ _E("Out of memory");
+ return -1;
+ }
+
+ ParseBootSequence(child_node, app_info);
+ break;
+ }
+
+ if (app_info == nullptr) continue;
+ args_->Push(std::shared_ptr<AppInfo>(app_info));
+ }
+
+ return 0;
+}
+
+void ParserPlugin::ParseBootSequence(xmlNode* node, AppInfo* app_info) {
+ for (xmlNode* child_node = node->children; child_node;
+ child_node = child_node->next) {
+ std::string name = GetName(child_node);
+ if (name == "dependency") {
+ auto after = GetAttribute(child_node, "after");
+ if (!after.empty())
+ app_info->SetAfter(std::move(after));
+
+ auto before = GetAttribute(child_node, "before");
+ if (!before.empty())
+ app_info->SetBefore(std::move(before));
+
+ auto requires_dep = GetAttribute(child_node, "requires");
+ if (!requires_dep.empty())
+ app_info->SetRequires(std::move(requires_dep));
+
+ auto conflicts = GetAttribute(child_node, "conflicts");
+ if (!conflicts.empty())
+ app_info->SetConflicts(std::move(conflicts));
+
+ auto vconf_key = GetAttribute(child_node, "vconf-key");
+ if (!vconf_key.empty()) {
+ auto vconf_value = GetAttribute(child_node, "vconf-value");
+ if (vconf_value.empty()) {
+ _E("vconf-value MUST be set");
+ continue;
+ }
+
+ // 'String', 'Int32', 'Boolean', 'Double'
+ auto vconf_type = GetAttribute(child_node, "vconf-type");
+ tizen_base::Bundle vconf {
+ { "__VCONF_KEY__", vconf_key },
+ { "__VCONF_VALUE__", vconf_value },
+ { "__VCONF_TYPE__", vconf_type.empty() ? "String" : vconf_type }
+ };
+
+ app_info->SetVconf(reinterpret_cast<char*>(vconf.ToRaw().first.get()));
+ }
+
+ auto path_exists = GetAttribute(child_node, "path-exists");
+ if (!path_exists.empty())
+ app_info->SetPathExists(std::move(path_exists));
+ } else if (name == "option") {
+ auto args = GetAttribute(child_node, "args");
+ if (!args.empty())
+ app_info->SetArgs(std::move(args));
+
+ auto background_launch = GetAttribute(child_node, "background-launch");
+ if (!background_launch.empty())
+ app_info->SetBackgroundLaunch(std::move(background_launch));
+
+ auto wait_until_ready = GetAttribute(child_node, "wait-until-ready");
+ if (!wait_until_ready.empty())
+ app_info->SetWaitUntilReady(std::move(wait_until_ready));
+
+ auto timeout = GetAttribute(child_node, "timeout");
+ if (!timeout.empty())
+ app_info->SetTimeout(std::move(timeout));
+ }
+ }
+
+ if (app_info->GetBackgroundLaunch() != "true" &&
+ app_info->GetBackgroundLaunch() != "false")
+ app_info->SetBackgroundLaunch("true");
+
+ if (app_info->GetWaitUntilReady() != "true" &&
+ app_info->GetWaitUntilReady() != "false")
+ app_info->SetWaitUntilReady("true");
+
+ // Default timeout: 5 seconds
+ if (app_info->GetTimeout().empty())
+ app_info->SetTimeout("5000");
+}
+
+} // namespace boot_sequencer
--- /dev/null
+/*
+ * Copyright (c) 2022 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 PARSER_PLUGIN_HH_
+#define PARSER_PLUGIN_HH_
+
+#include <libxml/tree.h>
+
+#include <memory>
+#include <string>
+
+#include "appsvc_db.hh"
+#include "package_event_args.hh"
+
+namespace boot_sequencer {
+
+class ParserPlugin {
+ public:
+ static ParserPlugin& GetInst();
+ void Init(xmlDocPtr doc, std::string package, EventType event_type);
+
+ int Process();
+ int Undo();
+
+ private:
+ ParserPlugin();
+ ~ParserPlugin() = default;
+
+ int Prepare();
+ int StepBackup();
+ int StepInstall();
+ int StepUninstall();
+ int StepUpgrade();
+ int StepRestore();
+ void Post();
+ void Rollback();
+
+ int Parse();
+ void ParseBootSequence(xmlNode* node, AppInfo* app_info);
+
+ private:
+ std::unique_ptr<AppSvcDB> db_;
+ xmlDocPtr doc_ = nullptr;
+ std::unique_ptr<PackageEventArgs> args_;
+ std::unique_ptr<PackageEventArgs> backup_args_;
+};
+
+} // namespace boot_sequencer
+
+#endif // PARSER_PLUGIN_HH_
--- /dev/null
+/*
+ * Copyright (c) 2022 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 <glib.h>
+#include <libxml/tree.h>
+
+#include "parser_plugin.hh"
+
+#undef EXPORT
+#define EXPORT __attribute__ ((visibility("default")))
+
+using namespace boot_sequencer;
+
+extern "C" EXPORT int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr doc,
+ const char* package) {
+ auto& plugin = ParserPlugin::GetInst();
+ plugin.Init(doc, package, EventType::Install);
+ return plugin.Process();
+}
+
+extern "C" EXPORT int PKGMGR_PARSER_PLUGIN_UPGRADE(xmlDocPtr doc,
+ const char* package) {
+ auto& plugin = ParserPlugin::GetInst();
+ plugin.Init(doc, package, EventType::Upgrade);
+ return plugin.Process();
+}
+
+extern "C" EXPORT int PKGMGR_PARSER_PLUGIN_UNINSTALL(xmlDocPtr doc,
+ const char* package) {
+ auto& plugin = ParserPlugin::GetInst();
+ plugin.Init(doc, package, EventType::Uninstall);
+ return plugin.Process();
+}
+
+extern "C" EXPORT int PKGMGR_PARSER_PLUGIN_RECOVERINSTALL(xmlDocPtr doc,
+ const char* package) {
+ auto& plugin = ParserPlugin::GetInst();
+ plugin.Init(doc, package, EventType::Uninstall);
+ return plugin.Process();
+}
+
+extern "C" EXPORT int PKGMGR_PARSER_PLUGIN_RECOVERUPGRADE(xmlDocPtr doc,
+ const char* package) {
+ auto& plugin = ParserPlugin::GetInst();
+ plugin.Init(doc, package, EventType::Upgrade);
+ return plugin.Process();
+}
+
+extern "C" EXPORT int PKGMGR_PARSER_PLUGIN_RECOVERUNINSTALL(xmlDocPtr doc,
+ const char* package) {
+ auto& plugin = ParserPlugin::GetInst();
+ plugin.Init(doc, package, EventType::Uninstall);
+ return plugin.Process();
+}
+
+extern "C" EXPORT int PKGMGR_PARSER_PLUGIN_UNDO(xmlDocPtr doc,
+ const char* package) {
+ auto& plugin = ParserPlugin::GetInst();
+ plugin.Init(doc, package, EventType::Undo);
+ return plugin.Undo();
+}
--- /dev/null
+SET(TARGET_COMPONENT_PLUGIN_PARSER "component-based-application")
+
+SET(SHARED_DIR "${CMAKE_INSTALL_PREFIX}/share")
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -Wall -Werror -Winline")
+
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src
+ COMPONENT_PLUGIN_PARSER_SRCS)
+
+ADD_LIBRARY(${TARGET_COMPONENT_PLUGIN_PARSER} SHARED ${COMPONENT_PLUGIN_PARSER_SRCS})
+TARGET_LINK_LIBRARIES(${TARGET_COMPONENT_PLUGIN_PARSER} PUBLIC dl)
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_COMPONENT_PLUGIN_PARSER}
+ PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/inc)
+
+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
+)
+
+CONFIGURE_FILE(data/component_db.sql.in data/component_db.sql @ONLY)
+CONFIGURE_FILE(script/14_component-add.post.in
+ script/14_component-add.post @ONLY)
+CONFIGURE_FILE(script/501.component_upgrade.sh.in
+ script/501.component_upgrade.sh @ONLY)
+CONFIGURE_FILE(script/upgrade/1_component_db_upgrade.sh.in
+ script/upgrade/1_component_db_upgrade.sh @ONLY)
+
+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)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/script/14_component-add.post
+ DESTINATION ${SYSCONF_INSTALL_DIR}/gumd/useradd.d)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/script/501.component_upgrade.sh
+ DESTINATION ${SHARE_INSTALL_PREFIX}/upgrade/scripts)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/script/upgrade/1_component_db_upgrade.sh
+ DESTINATION /etc/aul/component/upgrade/scripts)
--- /dev/null
+type="tag";name="component-based-application";path="/etc/package-manager/parserlib/libcomponent-based-application.so";vitalness="true"
--- /dev/null
+PRAGMA journal_mode = PERSIST;
+PRAGMA user_version = @COMPONENT_DB_VERSION@;
+
+CREATE TABLE IF NOT EXISTS component_info (
+ package TEXT NOT NULL,
+ app_id TEXT NOT NULL,
+ component_id TEXT NOT NULL,
+ component_type TEXT NOT NULL,
+ component_launch_mode TEXT NOT NULL,
+ component_main TEXT NOT NULL,
+ component_icon_display NOT NULL,
+ component_taskmanage NOT NULL,
+ PRIMARY KEY (component_id)
+);
+
+CREATE TABLE IF NOT EXISTS component_localized_info (
+ component_id TEXT NOT NULL,
+ component_locale TEXT NOT NULL DEFAULT 'No Locale',
+ component_label TEXT,
+ component_icon TEXT,
+ PRIMARY KEY (component_id, component_locale)
+ FOREIGN KEY (component_id)
+ REFERENCES component_info(component_id) ON DELETE CASCADE
+);
--- /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 __COMPONENT_PLUGIN_PARSER_H__
+#define __COMPONENT_PLUGIN_PARSER_H__
+
+#include <libxml/tree.h>
+
+int component_plugin_parser_install(xmlDocPtr doc, const char *package);
+
+int component_plugin_parser_uninstall(xmlDocPtr doc, const char *package);
+
+int component_plugin_parser_upgrade(xmlDocPtr doc, const char *package);
+
+#endif /* __COMPONENT_PLUGIN_PARSER_H__ */
--- /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 __COMPONENT_PLUGIN_PARSER_DB_H__
+#define __COMPONENT_PLUGIN_PARSER_DB_H__
+
+#include <sys/types.h>
+
+#include "component_plugin_parser_type.h"
+
+int component_plugin_parser_db_init(void);
+
+int component_plugin_parser_db_fini(void);
+
+int component_plugin_parser_db_begin_transaction(void);
+
+int component_plugin_parser_db_end_transaction(void);
+
+int component_plugin_parser_db_rollback(void);
+
+int component_plugin_parser_db_insert(component_t *component);
+
+int component_plugin_parser_db_delete(const char *package);
+
+uid_t component_plugin_parser_db_get_target_uid(void);
+
+#endif /* __COMPONENT_PLUGIN_PARSER_DB_H__ */
--- /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 __COMPONENT_PLUGIN_PARSER_HANDLER_H__
+#define __COMPONENT_PLUGIN_PARSER_HANDLER_H__
+
+#include <libxml/tree.h>
+
+int component_plugin_parser_handler_install(const char *package, xmlDocPtr doc);
+
+int component_plugin_parser_handler_uninstall(const char *package);
+
+int component_plugin_parser_handler_init(void);
+
+int component_plugin_parser_handler_fini(void);
+
+#endif /* __COMPONENT_PLUGIN_PARSER_HANDLER_H__ */
--- /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 __COMPONENT_PLUGIN_PARSER_PRIVATE_H__
+#define __COMPONENT_PLUGIN_PARSER_PRIVATE_H__
+
+#include <dlog.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "COMPONENT_PLUGIN_PARSER"
+
+#ifdef EXPORT
+#undef EXPORT
+#endif
+
+#define EXPORT __attribute__ ((visibility("default")))
+
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
+
+#define ROOT_UID 0
+
+#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
+
+#define FEATURE_SCREEN_DPI "http://tizen.org/feature/screen.dpi"
+
+#define DEFAULT_LOCALE "No Locale"
+
+#define LDPI "ldpi"
+#define MDPI "mdpi"
+#define HDPI "hdpi"
+#define XHDPI "xhdpi"
+#define XXHDPI "xxhdpi"
+
+#define LDPI_MIN 0
+#define LDPI_MAX 240
+#define MDPI_MIN 241
+#define MDPI_MAX 300
+#define HDPI_MIN 301
+#define HDPI_MAX 380
+#define XHDPI_MIN 381
+#define XHDPI_MAX 480
+#define XXHDPI_MIN 481
+#define XXHDPI_MAX 600
+
+#endif /* __COMPONENT_PLUGIN_PARSER_PRIVATE_H__ */
--- /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 __COMPONENT_PLUGIN_PARSER_TYPE_H__
+#define __COMPONENT_PLUGIN_PARSER_TYPE_H__
+
+#include <glib.h>
+
+typedef struct {
+ char *label;
+ char *lang;
+} label_t;
+
+typedef struct {
+ char *icon;
+ char *lang;
+ char *dpi;
+} icon_t;
+
+typedef struct {
+ char *package;
+ char *app_id;
+ char *id;
+ char *type;
+ char *launch_mode;
+ char *main;
+ char *icon_display;
+ char *taskmanage;
+ GList *icon;
+ GList *label;
+} component_t;
+
+#endif /* __COMPONENT_PLUGIN_PARSER_TYPE_H__ */
--- /dev/null
+#!/bin/sh
+
+#------------------------------------------#
+# Add Component DB #
+#------------------------------------------#
+
+# Macro
+PATH=/bin:/usr/bin:/sbin:/usr/sbin
+
+# Create DB Path
+mkdir -p -Z User::Home -m 755 /opt/dbspace/user
+export `tzplatform-get --user $2 TZ_USER_NAME`
+mkdir -p -Z User::Home -m 770 /opt/dbspace/user/$2
+chown $TZ_USER_NAME:system_share /opt/dbspace/user/$2
+
+# Create DB
+sqlite3 /opt/dbspace/user/$2/.component.db << EOF
+PRAGMA journal_mode = PERSIST;
+PAAGMA user_version = @COMPONENT_DB_VERSION@;
+
+CREATE TABLE IF NOT EXISTS component_info (
+ package TEXT NOT NULL,
+ app_id TEXT NOT NULL,
+ component_id TEXT NOT NULL,
+ component_type TEXT NOT NULL,
+ component_launch_mode TEXT NOT NULL,
+ component_main TEXT NOT NULL,
+ component_icon_display NOT NULL,
+ component_taskmanage NOT NULL,
+ PRIMARY KEY (component_id)
+);
+
+CREATE TABLE IF NOT EXISTS component_localized_info (
+ component_id TEXT NOT NULL,
+ component_locale TEXT NOT NULL DEFAULT 'No Locale',
+ component_label TEXT,
+ component_icon TEXT,
+ PRIMARY KEY (component_id, component_locale)
+ FOREIGN KEY (component_id)
+ REFERENCES component_info(component_id) ON DELETE CASCADE
+);
+
+EOF
+
+# Adjust Permission
+chmod 664 /opt/dbspace/user/$2/.component.db
+chmod 664 /opt/dbspace/user/$2/.component.db-journal
+
+chown $TZ_USER_NAME:system_share /opt/dbspace/user/$2/.component.db
+chown $TZ_USER_NAME:system_share /opt/dbspace/user/$2/.component.db-journal
+
+chsmack -a User::Home /opt/dbspace/user/$2/.component.db
+chsmack -a User::Home /opt/dbspace/user/$2/.component.db-journal
+
--- /dev/null
+#!/bin/sh
+PATH="/usr/bin:/bin:/usr/sbin:/sbin"
+
+DB_VERSION="@COMPONENT_DB_VERSION@"
+
+FILE_DB=".component.db"
+PATH_SYS_DB="/opt/dbspace/${FILE_DB}"
+PATH_USER_DB_DIR="/opt/dbspace/user"
+PATH_UPGRADE_SCRIPT_DIR="/etc/aul/component/upgrade/scripts"
+NAME_UPGRADE_SCRIPT="component_db_upgrade.sh"
+CURRENT_DB_VERSION=0
+
+CompareDBVersion() {
+ PATH_DB=$1
+ CURRENT_DB_VERSION=`sqlite3 ${PATH_DB} 'PRAGMA user_version;'`
+
+ echo "## Compare DB version"
+ echo " - Path: ${PATH_DB}"
+ echo " - Current DB version: ${CURRENT_DB_VERSION}"
+
+ if [ "${DB_VERSION}" -eq "${CURRENT_DB_VERSION}" ]; then
+ echo " - DB version[${DB_VERSION}] is equal to current DB version[${CURRENT_DB_VERSION}]"
+ return 0
+ elif [ "${DB_VERSION}" -gt "${CURRENT_DB_VERSION}" ]; then
+ echo " - DB version[${DB_VERSION}] is greater than current DB version[${CURRENT_DB_VERSION}]"
+ return 1
+ else
+ echo " - DB version[${DB_VERSION}] is less than current DB version[${CURRENT_DB_VERSION}]"
+ return 0
+ fi
+ echo "## Compare DB version [Done]"
+}
+
+UpgradeDB() {
+ PATH_DB=$1
+ VERSION=$2
+ echo "## UpgradeDB Path[${PATH_DB}] Version[${VERSION}]"
+ i=${VERSION}
+ while [ ${i} -le ${DB_VERSION} ]; do
+ FILE_SCRIPT="${i}_${NAME_UPGRADE_SCRIPT}"
+ PATH_SCRIPT="${PATH_UPGRADE_SCRIPT_DIR}/${FILE_SCRIPT}"
+ if [ -e "${PATH_SCRIPT}" ]; then
+ echo " - Script: ${PATH_SCRIPT}"
+ ${PATH_SCRIPT} ${PATH_DB}
+ fi
+
+ i=`expr ${i} + 1`
+ done
+ echo "## UpgradeDB Path[${PATH_DB}] Version[${VERSION}] [Done]"
+}
+
+CheckAndUpgradeDB() {
+ echo "### Check and upgrade DB"
+
+ CompareDBVersion ${PATH_SYS_DB}
+ RESULT=$?
+ if [ "${RESULT}" -eq 1 ]; then
+ VERSION=`expr ${CURRENT_DB_VERSION} + 1`
+ UpgradeDB ${PATH_SYS_DB} ${VERSION}
+ fi
+
+ for DIR in ${PATH_USER_DB_DIR}/*; do
+ echo " - Directory: ${DIR}"
+ if [ -d "${DIR}" ]; then
+ PATH_DB="${DIR}/${FILE_DB}"
+ CompareDBVersion ${PATH_DB}
+ RESULT=$?
+ if [ "${RESULT}" -eq 1 ]; then
+ VERSION=`expr ${CURRENT_DB_VERSION} + 1`
+ UpgradeDB ${PATH_DB} ${VERSION}
+ fi
+ fi
+ done
+ echo "### Check and upgrade DB [Done]"
+}
+
+echo "#### Upgrade component db ####"
+CheckAndUpgradeDB
+echo "#### Upgrade component db [Done] ####"
--- /dev/null
+#!/bin/sh
+
+#------------------------------------------#
+# component db upgrade ver.1 (4.0 -> 5.5) #
+#------------------------------------------#
+
+# Macro
+PATH=/bin:/usr/bin:/sbin:/usr/sbin
+
+PATH_DB="$1"
+PATH_NEW_DB="${PATH_DB}.new"
+PATH_BACKUP_DB="${PATH_DB}.bak"
+
+Init() {
+ echo "### Initialize"
+ cp ${PATH_DB} ${PATH_BACKUP_DB}
+ cp ${PATH_DB}-journal ${PATH_BACKUP_DB}-journal
+
+ if [ -e "${PATH_NEW_DB}" ]; then
+ rm ${PATH_NEW_DB}
+ fi
+
+ if [ -e "${PATH_NEW_DB}-journal" ]; then
+ rm ${PATH_NEW_DB}-journal
+ fi
+}
+
+# Create new DB
+CreateNewDB() {
+sqlite3 ${PATH_NEW_DB} << EOF
+PRAGMA journal_mode = PERSIST;
+PRAGMA user_version = @COMPONENT_DB_VERSION@;
+
+CREATE TABLE IF NOT EXISTS component_info (
+ package TEXT NOT NULL,
+ app_id TEXT NOT NULL,
+ component_id TEXT NOT NULL,
+ component_type TEXT NOT NULL,
+ component_launch_mode TEXT NOT NULL,
+ component_main TEXT NOT NULL,
+ component_icon_display NOT NULL,
+ component_taskmanage NOT NULL,
+ PRIMARY KEY (component_id)
+);
+
+CREATE TABLE IF NOT EXISTS component_localized_info (
+ component_id TEXT NOT NULL,
+ component_locale TEXT NOT NULL DEFAULT 'No Locale',
+ component_label TEXT,
+ component_icon TEXT,
+ PRIMARY KEY (component_id, component_locale)
+ FOREIGN KEY (component_id)
+ REFERENCES component_info(component_id) ON DELETE CASCADE
+);
+
+EOF
+}
+
+# Insert old data into new DB
+InsertComponentInfo() {
+ echo " - Insert component_info"
+ TABLE=`sqlite3 ${PATH_DB} 'SELECT package, app_id, component_id, component_type, component_launch_mode, component_main, component_icon_display, component_taskmanage FROM component_info;'`
+ for ROW in ${TABLE}; do
+ IFS='|' read -ra VALUE <<< "${ROW}";
+ QUERY="INSERT INTO component_info(package, app_id, component_id, component_type, component_launch_mode, component_main, component_icon_display, component_taskmanage) VALUES('${VALUE[0]}', '${VALUE[1]}', '${VALUE[2]}', '${VALUE[3]}', '${VALUE[4]}', '${VALUE[5]}', '${VALUE[6]}', '${VALUE[7]}');"
+ echo " + Query: ${QUERY}"
+ sqlite3 ${PATH_NEW_DB} "${QUERY}"
+ done
+}
+
+InsertComponentLocalizedInfo() {
+ echo " - Insert component_localized_info"
+ TABLE=`sqlite3 ${PATH_DB} 'SELECT component_id, component_locale, component_label, component_icon FROM component_localized_info;'`
+ for ROW in ${TABLE}; do
+ IFS='|' read -ra VALUE <<< "${ROW}";
+ QUERY="INSERT INTO component_localized_info(component_id, component_locale, component_label, component_icon) VALUES('${VALUE[0]}', '${VALUE[1]}', '${VALUE[2]}', '${VALUE[3]}');"
+ echo " + Query: ${QUERY}"
+ sqlite3 ${PATH_NEW_DB} "${QUERY}"
+ done
+}
+
+Upgrade() {
+ echo "### Upgrade"
+ CreateNewDB
+
+ InsertComponentInfo
+ InsertComponentLocalizedInfo
+
+ cp ${PATH_NEW_DB} ${PATH_DB}
+ cp ${PATH_NEW_DB}-journal ${PATH_DB}-journal
+
+ chown :system_share ${PATH_DB}
+ chown :system_share ${PATH_DB}-journal
+ chsmack -a User::Home ${PATH_DB}
+ chsmack -a User::Home ${PATH_DB}-journal
+ chmod 664 ${PATH_DB}
+ chmod 664 ${PATH_DB}-journal
+}
+
+Fini() {
+ echo "### Finish"
+ rm ${PATH_NEW_DB}
+ rm ${PATH_NEW_DB}-journal
+
+ rm ${PATH_BACKUP_DB}
+ rm ${PATH_BACKUP_DB}-journal
+}
+
+echo "#### 1. Upgrade component db ####"
+Init
+Upgrade
+Fini
+echo "#### 1. Upgrade component db [Done] ####"
--- /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 "component_plugin_parser.h"
+#include "component_plugin_parser_handler.h"
+#include "component_plugin_parser_private.h"
+
+int component_plugin_parser_install(xmlDocPtr doc, const char *package)
+{
+ int ret;
+
+ ret = component_plugin_parser_handler_init();
+ if (ret < 0) {
+ LOGE("Failed to initialize parser handler");
+ return -1;
+ }
+
+ ret = component_plugin_parser_handler_install(package, doc);
+ if (ret < 0) {
+ LOGE("Failed to intall components. package(%s)", package);
+ component_plugin_parser_handler_fini();
+ return -1;
+ }
+
+ component_plugin_parser_handler_fini();
+
+ return 0;
+}
+
+int component_plugin_parser_uninstall(xmlDocPtr doc, const char *package)
+{
+ int ret;
+
+ ret = component_plugin_parser_handler_init();
+ if (ret < 0) {
+ LOGE("Failed to initializer parser handler");
+ return -1;
+ }
+
+ ret = component_plugin_parser_handler_uninstall(package);
+ if (ret < 0) {
+ LOGE("Failed to uninstall components. package(%s)", package);
+ component_plugin_parser_handler_fini();
+ return 0;
+ }
+
+ component_plugin_parser_handler_fini();
+
+ return 0;
+}
+
+int component_plugin_parser_upgrade(xmlDocPtr doc, const char *package)
+{
+ int ret;
+
+ ret = component_plugin_parser_handler_init();
+ if (ret < 0) {
+ LOGE("Failed to initialize parser handler");
+ return -1;
+ }
+
+ ret = component_plugin_parser_handler_uninstall(package);
+ if (ret < 0)
+ LOGW("Failed to uninstall components. package(%s)", package);
+
+ ret = component_plugin_parser_handler_install(package, doc);
+ if (ret < 0) {
+ LOGE("Failed to install components. package(%s)", package);
+ component_plugin_parser_handler_fini();
+ return -1;
+ }
+
+ component_plugin_parser_handler_fini();
+
+ return 0;
+}
--- /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 <unistd.h>
+#include <dlfcn.h>
+#include <sys/types.h>
+#include <libgen.h>
+#include <linux/limits.h>
+#include <sqlite3.h>
+#include <tzplatform_config.h>
+#include <pkgmgr_installer_info.h>
+#include <dlog.h>
+
+#include "component_plugin_parser_db.h"
+#include "component_plugin_parser_private.h"
+
+#define LIBCAPI_SYSTEM_INFO LIBDIR"/libcapi-system-info.so.0"
+
+#define BUSY_WAITING_USEC 50000
+#define BUSY_WAITING_MAX 40
+
+#define BIND_TEXT(db, stmt, i, text) do { \
+ if (sqlite3_bind_text(stmt, i, text, -1, SQLITE_STATIC) != SQLITE_OK) {\
+ LOGE("sqlite3_bind_text() is failed. error(%s)", \
+ sqlite3_errmsg(db)); \
+ sqlite3_finalize(stmt); \
+ return -1; \
+ } \
+} while (0)
+
+struct cb_data_s {
+ const char *lang;
+ int dpi;
+};
+
+static sqlite3 *__db;
+static int (*__system_info_get_platform_int)(const char *, int *);
+
+static int __load_system_info(void)
+{
+ void *handle;
+
+ if (__system_info_get_platform_int)
+ return 0;
+
+ __system_info_get_platform_int = dlsym(RTLD_DEFAULT,
+ "system_info_get_platform_int");
+ if (__system_info_get_platform_int)
+ return 0;
+
+ handle = dlopen(LIBCAPI_SYSTEM_INFO, RTLD_LAZY | RTLD_LOCAL);
+ if (!handle) {
+ LOGE("Failed to open %s", LIBCAPI_SYSTEM_INFO);
+ return -1;
+ }
+
+ __system_info_get_platform_int = dlsym(handle,
+ "system_info_get_platform_int");
+ if (!__system_info_get_platform_int) {
+ LOGE("Failed to find system_info_get_platform_int");
+ return -1;
+ }
+
+ return 0;
+}
+
+uid_t component_plugin_parser_db_get_target_uid(void)
+{
+ static uid_t target_uid = (uid_t)-1;
+ int ret;
+
+ if (target_uid != (uid_t)-1)
+ return target_uid;
+
+ ret = pkgmgr_installer_info_get_target_uid(&target_uid);
+ if (ret < 0)
+ LOGE("Failed to get target uid. error(%d)", ret);
+
+ return target_uid;
+}
+
+static bool __is_global_user(uid_t uid)
+{
+ if (uid == ROOT_UID || uid == GLOBAL_USER)
+ return true;
+
+ return false;
+}
+
+static const char *__get_db_path(uid_t uid)
+{
+ static char db_path[PATH_MAX];
+ const char *path;
+
+ path = tzplatform_getenv(TZ_SYS_DB);
+ if (!path) {
+ LOGE("Failed to get TZ_SYS_DB path");
+ return NULL;
+ }
+
+ if (__is_global_user(uid)) {
+ snprintf(db_path, sizeof(db_path), "%s/.component.db", path);
+ } else {
+ snprintf(db_path, sizeof(db_path), "%s/user/%u/.component.db",
+ path, uid);
+ }
+
+ return db_path;
+}
+
+static int __db_busy_handler(void *data, int count)
+{
+ const char *path = (const char *)data;
+
+ if (count < BUSY_WAITING_MAX) {
+ usleep(BUSY_WAITING_USEC);
+ return 1;
+ }
+
+ LOGE("Database(%s) is busy", path);
+
+ return 0;
+}
+
+static sqlite3 *__open_db(const char *path)
+{
+ sqlite3 *db = NULL;
+ int ret;
+
+ ret = sqlite3_open_v2(path, &db, SQLITE_OPEN_READWRITE, NULL);
+ if (ret != SQLITE_OK) {
+ LOGE("sqlite3_open_v2() is failed. error(%d)", ret);
+ sqlite3_close_v2(db);
+ return NULL;
+ }
+
+ ret = sqlite3_busy_handler(db, __db_busy_handler, (void *)path);
+ if (ret != SQLITE_OK) {
+ LOGE("Failed to register busy handler. error(%s)",
+ sqlite3_errmsg(db));
+ sqlite3_close_v2(db);
+ return NULL;
+ }
+
+ ret = sqlite3_exec(db, "PRAGMA foreign_keys=ON", NULL, NULL, NULL);
+ if (ret != SQLITE_OK) {
+ LOGE("Failed to enable foreign key support. error(%s)",
+ sqlite3_errmsg(db));
+ sqlite3_close_v2(db);
+ return NULL;
+ }
+
+ return db;
+}
+
+void __close_db(sqlite3 *db)
+{
+ if (!db)
+ return;
+
+ sqlite3_close_v2(db);
+}
+
+static bool __integrity_check(sqlite3 *db)
+{
+ static const char query[] = "PRAGMA integrity_check";
+ sqlite3_stmt *stmt = NULL;
+ const char *res;
+ int ret;
+
+ ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ LOGE("sqlite3_prepare_v2() is failed. error(%s)",
+ sqlite3_errmsg(db));
+ return false;
+ }
+
+ ret = sqlite3_step(stmt);
+ if (ret != SQLITE_ROW) {
+ LOGE("sqlite3_step() is failed. error(%s)", sqlite3_errmsg(db));
+ sqlite3_finalize(stmt);
+ return false;
+ }
+
+ res = (const char *)sqlite3_column_text(stmt, 0);
+ if (!res) {
+ LOGE("Failed to check integrity db. error(%s)",
+ sqlite3_errmsg(db));
+ sqlite3_finalize(stmt);
+ return false;
+ }
+
+ if (strcmp(res, "ok") != 0) {
+ sqlite3_finalize(stmt);
+ return false;
+ }
+
+ sqlite3_finalize(stmt);
+
+ return true;
+}
+
+static gint __compare_lang(gconstpointer a, gconstpointer b,
+ gpointer user_data)
+{
+ const char *lang_a = (const char *)a;
+ const char *lang_b = (const char *)b;
+
+ if (lang_a == NULL || lang_b == NULL)
+ return 0;
+
+ return strcmp(lang_a, lang_b);
+}
+
+static gint __compare_label_with_lang(gconstpointer a, gconstpointer b)
+{
+ label_t *label = (label_t *)a;
+ const char *lang = (const char *)b;
+
+ return strcasecmp(label->lang, lang);
+}
+
+static int __check_screen_dpi(const char *dpi_str, int dpi_int)
+{
+ if (dpi_str == NULL)
+ return -1;
+
+ if (strcasecmp(dpi_str, LDPI) == 0) {
+ if (dpi_int >= LDPI_MIN && dpi_int <= LDPI_MAX)
+ return 0;
+ } else if (strcasecmp(dpi_str, MDPI) == 0) {
+ if (dpi_int >= MDPI_MIN && dpi_int <= MDPI_MAX)
+ return 0;
+ } else if (strcasecmp(dpi_str, HDPI) == 0) {
+ if (dpi_int >= HDPI_MIN && dpi_int <= HDPI_MAX)
+ return 0;
+ } else if (strcasecmp(dpi_str, XHDPI) == 0) {
+ if (dpi_int >= XHDPI_MIN && dpi_int <= XHDPI_MAX)
+ return 0;
+ } else if (strcasecmp(dpi_str, XXHDPI) == 0) {
+ if (dpi_int >= XXHDPI_MIN && dpi_int <= XXHDPI_MAX)
+ return 0;
+ }
+
+ return -1;
+}
+
+static int __get_screen_dpi_strings(int dpi, const char *(*dpi_str)[2])
+{
+ if (!dpi_str)
+ return -1;
+
+ if (dpi >= LDPI_MIN && dpi <= LDPI_MAX) {
+ (*dpi_str)[0] = "LDPI";
+ (*dpi_str)[1] = "ldpi";
+ } else if (dpi >= MDPI_MIN && dpi <= MDPI_MAX) {
+ (*dpi_str)[0] = "MDPI";
+ (*dpi_str)[1] = "mdpi";
+ } else if (dpi >= HDPI_MIN && dpi <= HDPI_MAX) {
+ (*dpi_str)[0] = "HDPI";
+ (*dpi_str)[1] = "hdpi";
+ } else if (dpi >= XHDPI_MIN && dpi <= XHDPI_MAX) {
+ (*dpi_str)[0] = "XHDPI";
+ (*dpi_str)[1] = "xhdpi";
+ } else if (dpi >= XXHDPI_MIN && dpi <= XXHDPI_MAX) {
+ (*dpi_str)[0] = "XXHDPI";
+ (*dpi_str)[1] = "xxhdpi";
+ } else {
+ LOGE("Unidentified dpi[%d]", dpi);
+ return -1;
+ }
+
+ return 0;
+}
+
+static int __check_icon_resolution(int dpi, const char *icon, char **new_icon)
+{
+ const char *dpi_str[2] = { NULL, };
+ char path[PATH_MAX];
+ char buf[PATH_MAX];
+ const char *file;
+ const char *dir;
+ int ret;
+
+ if (!icon || !new_icon)
+ return -1;
+
+ ret = __get_screen_dpi_strings(dpi, &dpi_str);
+ if (ret != 0)
+ return -1;
+
+ snprintf(buf, sizeof(buf), "%s", icon);
+ file = basename(buf);
+ if (!file)
+ return -1;
+
+ dir = dirname(buf);
+ if (!dir)
+ return -1;
+
+ snprintf(path, sizeof(path), "%s/%s%s", dir, dpi_str[0], file);
+ if (access(path, F_OK) == 0) {
+ *new_icon = strdup(path);
+ return 0;
+ }
+
+ snprintf(path, sizeof(path), "%s/%s%s", dir, dpi_str[1], file);
+ if (access(path, F_OK) == 0) {
+ *new_icon = strdup(path);
+ return 0;
+ }
+
+ return -1;
+}
+
+static gint __compare_icon_with_lang_dpi(gconstpointer a, gconstpointer b)
+{
+ icon_t *icon = (icon_t *)a;
+ struct cb_data_s *cb_data = (struct cb_data_s *)b;
+
+ if (strcasecmp(icon->lang, cb_data->lang) == 0 &&
+ __check_screen_dpi(icon->dpi, cb_data->dpi) == 0)
+ return 0;
+
+ return -1;
+}
+
+static gint __compare_icon_with_lang(gconstpointer a, gconstpointer b)
+{
+ icon_t *icon = (icon_t *)a;
+ struct cb_data_s *cb_data = (struct cb_data_s *)b;
+ char *new_icon = NULL;
+
+ if (strcasecmp(icon->lang, cb_data->lang) == 0) {
+ if (strcmp(icon->lang, DEFAULT_LOCALE) == 0) {
+ __check_icon_resolution(cb_data->dpi,
+ icon->icon, &new_icon);
+ if (new_icon) {
+ free(icon->icon);
+ icon->icon = new_icon;
+ }
+ }
+
+ return 0;
+ }
+
+ return -1;
+}
+
+static gint __compare_icon_with_dpi(gconstpointer a, gconstpointer b)
+{
+ icon_t *icon = (icon_t *)a;
+ struct cb_data_s *cb_data = (struct cb_data_s *)b;
+
+ if (icon->lang && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
+ return -1;
+
+ if (icon->dpi == NULL)
+ return -1;
+
+ if (__check_screen_dpi(icon->dpi, cb_data->dpi) == 0)
+ return 0;
+
+ return -1;
+}
+
+static gint __compare_icon_with_default_lang(gconstpointer a, gconstpointer b)
+{
+ icon_t *icon = (icon_t *)a;
+ struct cb_data_s *cb_data = (struct cb_data_s *)b;
+ char *new_icon = NULL;
+
+ if (icon->lang && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
+ return -1;
+
+ if (icon->dpi != NULL)
+ return -1;
+
+ __check_icon_resolution(cb_data->dpi, icon->icon, &new_icon);
+ if (new_icon) {
+ free(icon->icon);
+ icon->icon = new_icon;
+ }
+
+ return 0;
+}
+
+static void __foreach_label_lang(gpointer data, gpointer user_data)
+{
+ label_t *label = (label_t *)data;
+ GList **locales = (GList **)user_data;
+
+ if (!label)
+ return;
+
+ if (!label->lang)
+ return;
+
+ *locales = g_list_insert_sorted_with_data(*locales,
+ (gpointer)label->lang, __compare_lang, NULL);
+}
+
+static void __foreach_icon_lang(gpointer data, gpointer user_data)
+{
+ icon_t *icon = (icon_t *)data;
+ GList **locales = (GList **)user_data;
+
+ if (!icon)
+ return;
+
+ if (!icon->lang)
+ return;
+
+ *locales = g_list_insert_sorted_with_data(*locales,
+ (gpointer)icon->lang, __compare_lang, NULL);
+}
+
+static GList *__create_locale_list(GList *labels, GList *icons)
+{
+ const char *prev_locale = NULL;
+ const char *locale;
+ GList *locales = NULL;
+ GList *iter;
+
+ g_list_foreach(labels, __foreach_label_lang, &locales);
+ g_list_foreach(icons, __foreach_icon_lang, &locales);
+
+ iter = locales;
+ while (iter) {
+ locale = (const char *)iter->data;
+ iter = g_list_next(iter);
+ if (prev_locale) {
+ if (!strcmp(prev_locale, locale))
+ locales = g_list_remove(locales, locale);
+ else
+ prev_locale = locale;
+ } else {
+ prev_locale = locale;
+
+ }
+ }
+
+ return locales;
+}
+
+static const char *__find_label(GList *labels, const char *locale)
+{
+ label_t *label;
+ GList *found;
+
+ found = g_list_find_custom(labels, locale, __compare_label_with_lang);
+ if (!found)
+ return NULL;
+
+ label = (label_t *)found->data;
+ if (!label)
+ return NULL;
+
+ return label->label;
+}
+
+static const char *__find_icon(GList *icons, const char *locale)
+{
+ struct cb_data_s cb_data = { locale, -1};
+ icon_t *icon;
+ GList *found;
+ int ret;
+
+ ret = __load_system_info();
+ if (ret < 0)
+ return NULL;
+
+ ret = __system_info_get_platform_int(FEATURE_SCREEN_DPI, &cb_data.dpi);
+ if (ret != 0)
+ return NULL;
+
+ /* Step 1 */
+ found = g_list_find_custom(icons, &cb_data,
+ (GCompareFunc)__compare_icon_with_lang_dpi);
+ if (found) {
+ icon = (icon_t *)found->data;
+ return icon->icon;
+ }
+
+ /* Step 2 */
+ found = g_list_find_custom(icons, &cb_data,
+ (GCompareFunc)__compare_icon_with_lang);
+ if (found) {
+ icon = (icon_t *)found->data;
+ return icon->icon;
+ }
+
+ /* Step 3 */
+ found = g_list_find_custom(icons, &cb_data,
+ (GCompareFunc)__compare_icon_with_dpi);
+ if (found) {
+ icon = (icon_t *)found->data;
+ return icon->icon;
+ }
+
+ /* Step 4 */
+ found = g_list_find_custom(icons, &cb_data,
+ (GCompareFunc)__compare_icon_with_default_lang);
+ if (found) {
+ icon = (icon_t *)found->data;
+ return icon->icon;
+ }
+
+ return NULL;
+}
+
+static int __insert_component_localized_info(component_t *component,
+ GList *locales)
+{
+ static const char query[] =
+ "INSERT INTO component_localized_info "
+ "(component_id, component_locale, component_label, "
+ "component_icon) VALUES (?, ?, ?, ?)";
+ sqlite3_stmt *stmt = NULL;
+ const char *locale;
+ const char *label;
+ const char *icon;
+ GList *iter;
+ int idx;
+ int ret;
+
+ ret = sqlite3_prepare_v2(__db, query, strlen(query), &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ LOGE("sqlite3_prepare_v2() is failed. error(%s)",
+ sqlite3_errmsg(__db));
+ return -1;
+ }
+
+ iter = locales;
+ while (iter) {
+ locale = (const char *)iter->data;
+ iter = g_list_next(iter);
+
+ label = __find_label(component->label, locale);
+ icon = __find_icon(component->icon, locale);
+ if (!label && !icon)
+ continue;
+
+ idx = 1;
+ BIND_TEXT(__db, stmt, idx++, component->id);
+ BIND_TEXT(__db, stmt, idx++, locale);
+ BIND_TEXT(__db, stmt, idx++, label);
+ BIND_TEXT(__db, stmt, idx++, icon);
+
+ ret = sqlite3_step(stmt);
+ if (ret != SQLITE_DONE) {
+ LOGE("sqlite3_step() is failed. error(%s)",
+ sqlite3_errmsg(__db));
+ sqlite3_finalize(stmt);
+ return -1;
+ }
+
+ sqlite3_reset(stmt);
+ }
+
+ sqlite3_finalize(stmt);
+
+ return 0;
+}
+
+int component_plugin_parser_db_insert(component_t *component)
+{
+ static const char query[] =
+ "INSERT INTO component_info "
+ "(package, app_id, component_id, component_type, "
+ "component_launch_mode, component_main, "
+ "component_icon_display, component_taskmanage) "
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
+ sqlite3_stmt *stmt = NULL;
+ GList *locales = NULL;
+ int idx;
+ int ret;
+
+ if (!component) {
+ LOGE("Invalid parameter");
+ return -1;
+ }
+
+ if (!__db) {
+ LOGE("Database is not prepared");
+ return -1;
+ }
+
+ ret = sqlite3_prepare_v2(__db, query, strlen(query), &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ LOGE("sqlite3_prepare_v2() is failed. error(%s)",
+ sqlite3_errmsg(__db));
+ return -1;
+ }
+
+ idx = 1;
+ BIND_TEXT(__db, stmt, idx++, component->package);
+ BIND_TEXT(__db, stmt, idx++, component->app_id);
+ BIND_TEXT(__db, stmt, idx++, component->id);
+ BIND_TEXT(__db, stmt, idx++, component->type);
+ BIND_TEXT(__db, stmt, idx++, component->launch_mode);
+ BIND_TEXT(__db, stmt, idx++, component->main);
+ BIND_TEXT(__db, stmt, idx++, component->icon_display);
+ BIND_TEXT(__db, stmt, idx++, component->taskmanage);
+
+ ret = sqlite3_step(stmt);
+ if (ret != SQLITE_DONE) {
+ LOGE("sqlite3_step() is failed. error(%s)",
+ sqlite3_errmsg(__db));
+ sqlite3_finalize(stmt);
+ return -1;
+ }
+ sqlite3_finalize(stmt);
+
+ locales = __create_locale_list(component->label, component->icon);
+ ret = __insert_component_localized_info(component, locales);
+ if (ret < 0) {
+ LOGE("Failed to insert component localized info");
+ g_list_free(locales);
+ return -1;
+ }
+ g_list_free(locales);
+
+ return 0;
+}
+
+int component_plugin_parser_db_delete(const char *package)
+{
+ static const char query[] =
+ "DELETE FROM component_info WHERE package=?";
+ sqlite3_stmt *stmt = NULL;
+ int ret;
+
+ if (!package) {
+ LOGE("Invalid parameter");
+ return -1;
+ }
+
+ if (!__db) {
+ LOGE("Database is not prepared");
+ return -1;
+ }
+
+ ret = sqlite3_prepare_v2(__db, query, strlen(query), &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ LOGE("sqlite3_prepare_v2() is failed. error(%s)",
+ sqlite3_errmsg(__db));
+ return -1;
+ }
+
+ BIND_TEXT(__db, stmt, 1, package);
+
+ ret = sqlite3_step(stmt);
+ if (ret != SQLITE_DONE) {
+ LOGE("sqlite3_step() is failed. error(%s)",
+ sqlite3_errmsg(__db));
+ sqlite3_finalize(stmt);
+ return -1;
+ }
+
+ sqlite3_finalize(stmt);
+
+ return 0;
+}
+
+int component_plugin_parser_db_begin_transaction(void)
+{
+ int ret;
+
+ if (!__db) {
+ LOGE("Database is not prepared");
+ return -1;
+ }
+
+ ret = sqlite3_exec(__db, "BEGIN TRANSACTION", NULL, NULL, NULL);
+ if (ret != SQLITE_OK) {
+ LOGE("Transaction is failed. error(%s)", sqlite3_errmsg(__db));
+ return -1;
+ }
+
+ return 0;
+}
+
+int component_plugin_parser_db_end_transaction(void)
+{
+ int ret;
+
+ if (!__db) {
+ LOGE("Database is not prepared");
+ return -1;
+ }
+
+ ret = sqlite3_exec(__db, "END TRANSACTION", NULL, NULL, NULL);
+ if (ret != SQLITE_OK) {
+ LOGE("Transaction is failed. error(%s)", sqlite3_errmsg(__db));
+ return -1;
+ }
+
+ return 0;
+}
+
+int component_plugin_parser_db_rollback(void)
+{
+ int ret;
+
+ if (!__db) {
+ LOGE("Database is not prepared");
+ return -1;
+ }
+
+ ret = sqlite3_exec(__db, "ROLLBACK", NULL, NULL, NULL);
+ if (ret != SQLITE_OK) {
+ LOGE("Rollback is failed. error(%s)", sqlite3_errmsg(__db));
+ return -1;
+ }
+
+ return 0;
+}
+
+int component_plugin_parser_db_init(void)
+{
+ const char *path;
+ uid_t target_uid;
+ int ret;
+
+ target_uid = component_plugin_parser_db_get_target_uid();
+ path = __get_db_path(target_uid);
+ if (!path) {
+ LOGE("Failed to get db path. uid(%u)", target_uid);
+ return -1;
+ }
+
+ ret = access(path, F_OK);
+ if (ret != 0) {
+ LOGE("%s does not exists", path);
+ return -1;
+ }
+
+ __db = __open_db(path);
+ if (!__db) {
+ LOGE("Failed to open db(%s)", path);
+ return -1;
+ }
+
+ if (!__integrity_check(__db)) {
+ LOGE("Database(%s) is corrupted", path);
+ __close_db(__db);
+ __db = NULL;
+ return -1;
+ }
+
+ return 0;
+}
+
+int component_plugin_parser_db_fini(void)
+{
+ if (!__db)
+ return -1;
+
+ __close_db(__db);
+ __db = NULL;
+
+ return 0;
+}
--- /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.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <string.h>
+#include <stdint.h>
+#include <sys/types.h>
+
+#include <glib.h>
+#include <pkgmgr-info.h>
+
+#include "component_plugin_parser_handler.h"
+#include "component_plugin_parser_private.h"
+#include "component_plugin_parser_type.h"
+#include "component_plugin_parser_db.h"
+
+typedef enum {
+ COMPONENT_TYPE_NONE,
+ COMPONENT_TYPE_FRAME,
+ COMPONENT_TYPE_SERVICE,
+ COMPONENT_TYPE_WIDGET,
+ COMPONENT_TYPE_MAX,
+} component_type_e;
+
+typedef enum {
+ COMPONENT_ATTR_NONE,
+ COMPONENT_ATTR_ID,
+ COMPONENT_ATTR_LAUNCH_MODE,
+ COMPONENT_ATTR_MAIN,
+ COMPONENT_ATTR_ICON_DISPLAY,
+ COMPONENT_ATTR_TASKMANAGE,
+ COMPONENT_ATTR_MAX,
+} component_attr_e;
+
+typedef enum {
+ COMPONENT_ELM_NONE,
+ COMPONENT_ELM_ICON,
+ COMPONENT_ELM_LABEL,
+ COMPONENT_ELM_MAX,
+} component_elm_e;
+
+typedef enum {
+ COMPONENT_ICON_ATTR_NONE,
+ COMPONENT_ICON_ATTR_TEXT,
+ COMPONENT_ICON_ATTR_LANG,
+ COMPONENT_ICON_ATTR_DPI,
+ COMPONENT_ICON_ATTR_MAX,
+} component_icon_attr_e;
+
+typedef enum {
+ COMPONENT_LABEL_ATTR_NONE,
+ COMPONENT_LABEL_ATTR_TEXT,
+ COMPONENT_LABEL_ATTR_LANG,
+ COMPONENT_LABEL_ATTR_MAX,
+} component_label_attr_e;
+
+typedef struct {
+ uint32_t tag;
+ const char *name;
+} tag_map_t;
+
+static tag_map_t __component_type_map[] = {
+ { COMPONENT_TYPE_FRAME, "frame-component" },
+ { COMPONENT_TYPE_SERVICE, "service-component" },
+ { COMPONENT_TYPE_WIDGET, "widget-component" },
+};
+
+static const char *__component_type_string[] = {
+ [COMPONENT_TYPE_FRAME] = "frame",
+ [COMPONENT_TYPE_SERVICE] = "service",
+ [COMPONENT_TYPE_WIDGET] = "widget",
+};
+
+static const char *__component_attr_string[] = {
+ [COMPONENT_ATTR_ID] = "id",
+ [COMPONENT_ATTR_LAUNCH_MODE] = "launch_mode",
+ [COMPONENT_ATTR_MAIN] = "main",
+ [COMPONENT_ATTR_ICON_DISPLAY] = "icon-display",
+ [COMPONENT_ATTR_TASKMANAGE] = "taskmanage",
+};
+
+static const char *__component_elm_string[] = {
+ [COMPONENT_ELM_ICON] = "icon",
+ [COMPONENT_ELM_LABEL] = "label",
+};
+
+static const char *__component_icon_attr_string[] = {
+ [COMPONENT_ICON_ATTR_TEXT] = "#text",
+ [COMPONENT_ICON_ATTR_LANG] = "lang",
+ [COMPONENT_ICON_ATTR_DPI] = "dpi",
+};
+
+static const char *__component_label_attr_string[] = {
+ [COMPONENT_LABEL_ATTR_TEXT] = "#text",
+ [COMPONENT_LABEL_ATTR_LANG] = "lang",
+};
+
+typedef int (*component_plugin_parser_func)(xmlNode *node, void *data);
+
+static char __root_path[PATH_MAX];
+
+static uint32_t __get_component_type_tag(const char *name)
+{
+ uint32_t i;
+
+ for (i = 0; i < ARRAY_SIZE(__component_type_map); i++) {
+ if (!strcmp(__component_type_map[i].name, name))
+ return __component_type_map[i].tag;
+ }
+
+ return 0;
+}
+
+static bool __is_service_component(const char *type)
+{
+ if (!strcmp(type, __component_type_string[COMPONENT_TYPE_SERVICE]))
+ return true;
+
+ return false;
+}
+
+static bool __is_widget_component(const char *type)
+{
+ if (!strcmp(type, __component_type_string[COMPONENT_TYPE_WIDGET]))
+ return true;
+
+ return false;
+}
+
+static bool __is_boolean(const char *value)
+{
+ if (!strcmp(value, "true") || !strcmp(value, "false"))
+ return true;
+
+ return false;
+}
+
+static char *__get_attribute(xmlNode *node, const char *name)
+{
+ xmlChar *val;
+ char *attr = NULL;
+
+ val = xmlGetProp(node, (const xmlChar *)name);
+ if (val) {
+ attr = strdup((char *)val);
+ xmlFree(val);
+ }
+
+ return attr;
+}
+
+static char *__get_language(xmlNode *node)
+{
+ xmlChar *val;
+ char *lang = NULL;
+
+ val = xmlNodeGetLang(node);
+ if (val) {
+ lang = strdup((char *)val);
+ xmlFree(val);
+ }
+
+ return lang;
+}
+
+static const char *__get_name(xmlNode *node)
+{
+ if (!node)
+ return NULL;
+
+ return (const char *)node->name;
+}
+
+static void __set_root_path(const char *package)
+{
+ uid_t uid = component_plugin_parser_db_get_target_uid();
+ pkgmgrinfo_pkginfo_h handle = NULL;
+ char *root_path = NULL;
+ int ret;
+
+ ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(package, uid, &handle);
+ if (ret != PMINFO_R_OK) {
+ LOGE("Failed to get package(%s) info", package);
+ return;
+ }
+
+ ret = pkgmgrinfo_pkginfo_get_root_path(handle, &root_path);
+ if (ret != PMINFO_R_OK)
+ LOGE("Failed to get root path. package(%s)", package);
+
+ if (root_path)
+ snprintf(__root_path, sizeof(__root_path), "%s", root_path);
+
+ pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+}
+
+static void __destroy_label(gpointer data)
+{
+ label_t *info = (label_t *)data;
+
+ if (!info)
+ return;
+
+ if (info->label)
+ free(info->label);
+ if (info->lang)
+ free(info->lang);
+ free(info);
+}
+
+static void __destroy_icon(gpointer data)
+{
+ icon_t *info = (icon_t *)data;
+
+ if (!info)
+ return;
+
+ if (info->icon)
+ free(info->icon);
+ if (info->lang)
+ free(info->lang);
+ if (info->dpi)
+ free(info->dpi);
+ free(info);
+}
+
+static void __destroy_component(gpointer data)
+{
+ component_t *info = (component_t *)data;
+
+ if (!info)
+ return;
+
+ if (info->package)
+ free(info->package);
+ if (info->app_id)
+ free(info->app_id);
+ if (info->id)
+ free(info->id);
+ if (info->launch_mode)
+ free(info->launch_mode);
+ if (info->main)
+ free(info->main);
+ if (info->icon_display)
+ free(info->icon_display);
+ if (info->taskmanage)
+ free(info->taskmanage);
+ if (info->icon)
+ g_list_free_full(info->icon, __destroy_icon);
+ if (info->label)
+ g_list_free_full(info->label, __destroy_label);
+ free(info);
+}
+
+static component_t *__create_component(const char *package, const char *app_id,
+ const char *type)
+{
+ component_t *info;
+
+ info = calloc(1, sizeof(component_t));
+ if (!info) {
+ LOGE("Out of memory");
+ return NULL;
+ }
+
+ info->package = strdup(package);
+ if (!info->package) {
+ LOGE("Failed to duplicate package");
+ free(info);
+ return NULL;
+ }
+
+ info->app_id = strdup(app_id);
+ if (!info->app_id) {
+ LOGE("Failed to duplicate app_id");
+ __destroy_component(info);
+ return NULL;
+ }
+
+ info->type = strdup(type);
+ if (!info->type) {
+ LOGE("Failed to duplicate type");
+ __destroy_component(info);
+ return NULL;
+ }
+
+ return info;
+}
+
+static int __component_label_attr_text(xmlNode *node, void *data)
+{
+ label_t *info = (label_t *)data;
+
+ info->label = strdup((const char *)node->children->content);
+ if (!info->label) {
+ LOGE("Failed to duplicate label");
+ return -1;
+ }
+
+ return 0;
+}
+
+static int __component_label_attr_lang(xmlNode *node, void *data)
+{
+ label_t *info = (label_t *)data;
+ char *lang;
+
+ lang = __get_language(node);
+ if (!lang) {
+ info->lang = strdup(DEFAULT_LOCALE);
+ if (!info->lang) {
+ LOGE("Out of memory");
+ return -1;
+ }
+ } else {
+ info->lang = lang;
+ }
+
+ return 0;
+}
+
+static component_plugin_parser_func __label_attr_table[] = {
+ [COMPONENT_LABEL_ATTR_TEXT] = __component_label_attr_text,
+ [COMPONENT_LABEL_ATTR_LANG] = __component_label_attr_lang,
+};
+
+static int __component_icon_attr_text(xmlNode *node, void *data)
+{
+ icon_t *info = (icon_t *)data;
+ const char *file = (const char *)node->children->content;
+ char *path;
+ int size;
+
+ if (file[0] == '/') {
+ size = strlen(file) + 1;
+ path = (char *)malloc(size);
+ if (!path) {
+ LOGE("Out of memory");
+ return -1;
+ }
+
+ snprintf(path, size, "%s", file);
+ } else {
+ size = strlen(__root_path) + strlen("/shared/res/") +
+ strlen(file) + 1;
+ path = (char *)malloc(size);
+ if (!path) {
+ LOGE("Out of memory");
+ return -1;
+ }
+
+ snprintf(path, size, "%s/shared/res/%s", __root_path, file);
+ }
+
+ info->icon = path;
+
+ return 0;
+}
+
+static int __component_icon_attr_lang(xmlNode *node, void *data)
+{
+ icon_t *info = (icon_t *)data;
+ char *lang;
+
+ lang = __get_language(node);
+ if (!lang) {
+ info->lang = strdup(DEFAULT_LOCALE);
+ if (!info->lang) {
+ LOGE("Out of memory");
+ return -1;
+ }
+ } else {
+ info->lang = lang;
+ }
+
+ return 0;
+}
+
+static int __component_icon_attr_dpi(xmlNode *node, void *data)
+{
+ icon_t *info = (icon_t *)data;
+ const char *key;
+
+ key = __component_icon_attr_string[COMPONENT_ICON_ATTR_DPI];
+ info->dpi = __get_attribute(node, key);
+
+ return 0;
+}
+
+static component_plugin_parser_func __icon_attr_table[] = {
+ [COMPONENT_ICON_ATTR_TEXT] = __component_icon_attr_text,
+ [COMPONENT_ICON_ATTR_LANG] = __component_icon_attr_lang,
+ [COMPONENT_ICON_ATTR_DPI] = __component_icon_attr_dpi,
+};
+
+static int __component_elm_icon(xmlNode *node, void *data)
+{
+ component_t *info = (component_t *)data;
+ const char *key = __component_elm_string[COMPONENT_ELM_ICON];
+ icon_t *icon;
+ uint32_t i;
+ int ret;
+
+ if (strcmp(__get_name(node), key) != 0)
+ return 0;
+
+ if (!node->children || !node->children->content)
+ return 0;
+
+ icon = calloc(1, sizeof(icon_t));
+ if (!icon) {
+ LOGE("Out of memory");
+ return -1;
+ }
+
+ for (i = 0; i < ARRAY_SIZE(__icon_attr_table); i++) {
+ if (!__icon_attr_table[i])
+ continue;
+
+ ret = __icon_attr_table[i](node, icon);
+ if (ret < 0) {
+ LOGE("Failed to parse icon attribute %s",
+ __component_icon_attr_string[i]);
+ __destroy_icon(icon);
+ return -1;
+ }
+ }
+
+ info->icon = g_list_append(info->icon, icon);
+
+ return 0;
+}
+
+static int __component_elm_label(xmlNode *node, void *data)
+{
+ component_t *info = (component_t *)data;
+ const char *key = __component_elm_string[COMPONENT_ELM_LABEL];
+ label_t *label;
+ uint32_t i;
+ int ret;
+
+ if (strcmp(__get_name(node), key) != 0)
+ return 0;
+
+ if (!node->children || !node->children->content)
+ return 0;
+
+ label = calloc(1, sizeof(label_t));
+ if (!label) {
+ LOGE("Out of memory");
+ return -1;
+ }
+
+ for (i = 0; i < ARRAY_SIZE(__label_attr_table); i++) {
+ if (!__label_attr_table[i])
+ continue;
+
+ ret = __label_attr_table[i](node, label);
+ if (ret < 0) {
+ LOGE("Failed to parse label attribute %s",
+ __component_label_attr_string[i]);
+ __destroy_label(label);
+ return -1;
+ }
+ }
+
+ info->label = g_list_append(info->label, label);
+
+ return 0;
+}
+
+static component_plugin_parser_func __elm_table[] = {
+ [COMPONENT_ELM_ICON] = __component_elm_icon,
+ [COMPONENT_ELM_LABEL] = __component_elm_label,
+};
+
+/**
+ * @brief Parses the elements of the component.
+ */
+static int __parse_component_element(xmlNode *node, component_t *component)
+{
+ uint32_t i;
+ int ret;
+
+ for (i = 0; i < ARRAY_SIZE(__elm_table); i++) {
+ if (!__elm_table[i])
+ continue;
+
+ ret = __elm_table[i](node, component);
+ if (ret < 0) {
+ LOGE("Failed to parse element %s",
+ __component_elm_string[i]);
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+static int __component_attr_id(xmlNode *node, void *data)
+{
+ component_t *info = (component_t *)data;
+ const char *key = __component_attr_string[COMPONENT_ATTR_ID];
+ char *value;
+
+ value = __get_attribute(node, key);
+ if (!value) {
+ LOGE("Failed to get id attribute");
+ return -1;
+ }
+
+ info->id = value;
+
+ return 0;
+}
+
+static int __component_attr_launch_mode(xmlNode *node, void *data)
+{
+ component_t *info = (component_t *)data;
+ const char *key = __component_attr_string[COMPONENT_ATTR_LAUNCH_MODE];
+ char *value;
+
+ if (__is_service_component(info->type) ||
+ __is_widget_component(info->type)) {
+ info->launch_mode = strdup("single");
+ if (!info->launch_mode) {
+ LOGE("Failed to duplicate launch mode");
+ return -1;
+ }
+
+ return 0;
+ }
+
+ value = __get_attribute(node, key);
+ if (!value) {
+ info->launch_mode = strdup("single");
+ if (!info->launch_mode) {
+ LOGE("Failed to duplicate launch mode");
+ return -1;
+ }
+
+ return 0;
+ }
+
+ if (strcmp(value, "single") != 0 &&
+ strcmp(value, "caller") != 0 &&
+ strcmp(value, "group") != 0) {
+ LOGE("launch_mode should be 'single' or 'caller' or group'");
+ free(value);
+ return -1;
+ }
+
+ info->launch_mode = value;
+
+ return 0;
+}
+
+static int __component_attr_main(xmlNode *node, void *data)
+{
+ component_t *info = (component_t *)data;
+ const char *key = __component_attr_string[COMPONENT_ATTR_MAIN];
+ char *value;
+
+ value = __get_attribute(node, key);
+ if (!value) {
+ info->main = strdup("true");
+ if (!info->launch_mode) {
+ LOGE("Failed to duplicate main");
+ return -1;
+ }
+
+ return 0;
+ }
+
+ if (!__is_boolean(value)) {
+ LOGE("main should be 'true' or 'false'");
+ free(value);
+ return -1;
+ }
+
+ info->main = value;
+
+ return 0;
+}
+
+static int __component_attr_icon_display(xmlNode *node, void *data)
+{
+ component_t *info = (component_t *)data;
+ const char *key = __component_attr_string[COMPONENT_ATTR_ICON_DISPLAY];
+ char *value;
+
+ if (__is_service_component(info->type)) {
+ info->icon_display = strdup("false");
+ if (!info->icon_display) {
+ LOGE("Failed to duplicate icon display");
+ return -1;
+ }
+
+ return 0;
+ }
+
+ value = __get_attribute(node, key);
+ if (!value) {
+ info->icon_display = strdup("true");
+ if (!info->icon_display) {
+ LOGE("Failed to duplicate icon display");
+ return -1;
+ }
+
+ return 0;
+ }
+
+ if (!__is_boolean(value)) {
+ LOGE("icon-display should be 'true' or 'false'");
+ free(value);
+ return -1;
+ }
+
+ info->icon_display = value;
+
+ return 0;
+}
+
+static int __component_attr_taskmanage(xmlNode *node, void *data)
+{
+ component_t *info = (component_t *)data;
+ const char *key = __component_attr_string[COMPONENT_ATTR_TASKMANAGE];
+ char *value;
+
+ if (__is_service_component(info->type) ||
+ __is_widget_component(info->type)) {
+ info->taskmanage = strdup("false");
+ if (!info->taskmanage) {
+ LOGE("Failed to duplicate taskmanage");
+ return -1;
+ }
+
+ return 0;
+ }
+
+ value = __get_attribute(node, key);
+ if (!value) {
+ info->taskmanage = strdup("true");
+ if (!info->taskmanage) {
+ LOGE("Failed to duplicate taskmanage");
+ return -1;
+ }
+
+ return 0;
+ }
+
+ if (!__is_boolean(value)) {
+ LOGE("taskmanage should be 'true' or 'false'");
+ free(value);
+ return -1;
+ }
+
+ info->taskmanage = value;
+
+ return 0;
+}
+
+static component_plugin_parser_func __attr_table[] = {
+ [COMPONENT_ATTR_ID] = __component_attr_id,
+ [COMPONENT_ATTR_LAUNCH_MODE] = __component_attr_launch_mode,
+ [COMPONENT_ATTR_MAIN] = __component_attr_main,
+ [COMPONENT_ATTR_ICON_DISPLAY] = __component_attr_icon_display,
+ [COMPONENT_ATTR_TASKMANAGE] = __component_attr_taskmanage,
+};
+
+/**
+ * @brief Parses the attributes of the component.
+ */
+static int __parse_component_attribute(xmlNode *node, component_t *component)
+{
+ uint32_t i;
+ int ret;
+
+ for (i = 0; i < ARRAY_SIZE(__attr_table); i++) {
+ if (!__attr_table[i])
+ continue;
+
+ ret = __attr_table[i](node, component);
+ if (ret < 0) {
+ LOGE("Failed to parse attribute %s",
+ __component_attr_string[i]);
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+static int __parse_component(const char *package, const char *app_id,
+ xmlNode *node, component_t **component)
+{
+ component_t *info = NULL;
+ xmlNode *iter;
+ const char *type;
+ uint32_t tag;
+ int ret;
+
+ tag = __get_component_type_tag(__get_name(node));
+ if (tag == COMPONENT_TYPE_NONE || tag >= COMPONENT_TYPE_MAX)
+ return 0;
+
+ type = __component_type_string[tag];
+ info = __create_component(package, app_id, type);
+ if (!info)
+ return -1;
+
+ ret = __parse_component_attribute(node, info);
+ if (ret < 0) {
+ __destroy_component(info);
+ return -1;
+ }
+
+ for (iter = node->children; iter; iter = iter->next) {
+ if (!iter->name)
+ continue;
+
+ ret = __parse_component_element(iter, info);
+ if (ret < 0) {
+ __destroy_component(info);
+ return -1;
+ }
+ }
+
+ *component = info;
+
+ return 0;
+}
+
+/**
+ * @brief Parses component-based-application
+ *
+ * Structure of tizen-manifest.xml for xml elements:
+ * <component-based-application>
+ * \_ <icon>
+ * \_ <label>
+ * \_ <metadata>
+ * \_ <app-control>
+ * \_ <background-category>
+ * \_ <data-control>
+ * \_ <splash-screens>
+ * \_ <splash-screen>
+ * \_ <frame-component>
+ * \_ <icon>
+ * \_ <label>
+ * \_ <service-component>
+ */
+static int __parse_component_based_application(const char *package,
+ xmlNode *node, GList **list)
+{
+ component_t *info;
+ xmlNode *iter;
+ char *app_id;
+ int ret;
+
+ app_id = __get_attribute(node, "appid");
+ if (!app_id) {
+ LOGE("Failed to get appid");
+ return -1;
+ }
+
+ for (iter = node->children; iter; iter = iter->next) {
+ if (!iter->name)
+ continue;
+
+ info = NULL;
+ ret = __parse_component(package, app_id, iter, &info);
+ if (ret < 0) {
+ g_list_free_full(*list, __destroy_component);
+ *list = NULL;
+ free(app_id);
+ return -1;
+ }
+
+ if (info)
+ *list = g_list_append(*list, info);
+ }
+
+ free(app_id);
+
+ return 0;
+}
+
+static gint __compare_component_main(gconstpointer a, gconstpointer b)
+{
+ component_t *info = (component_t *)a;
+ const char *value = (const char *)b;
+
+ return strcmp(info->main, value);
+}
+
+static int __fill_extra_info(GList *components)
+{
+ component_t *main_info = NULL;
+ component_t *info;
+ GList *found;
+ GList *iter;
+
+ found = g_list_find_custom(components, "true",
+ __compare_component_main);
+ if (found)
+ main_info = (component_t *)found->data;
+
+ if (!main_info) {
+ main_info = (component_t *)components->data;
+ free(main_info->main);
+ main_info->main = strdup("true");
+ }
+
+ iter = components;
+ while (iter) {
+ info = (component_t *)iter->data;
+ iter = g_list_next(iter);
+ if (info == main_info)
+ continue;
+
+ free(info->main);
+ info->main = strdup("false");
+ }
+
+ return 0;
+}
+
+static int __insert_component_info(GList *components)
+{
+ component_t *info;
+ GList *iter;
+ int ret;
+
+ ret = component_plugin_parser_db_begin_transaction();
+ if (ret < 0) {
+ LOGE("Failed to initialize db");
+ return -1;
+ }
+
+ iter = components;
+ while (iter) {
+ info = (component_t *)iter->data;
+ iter = g_list_next(iter);
+ ret = component_plugin_parser_db_insert(info);
+ if (ret < 0) {
+ LOGE("Failed to insert component info(%s:%s)",
+ info->app_id, info->id);
+ component_plugin_parser_db_rollback();
+ return -1;
+ }
+ }
+
+ return component_plugin_parser_db_end_transaction();
+}
+
+int component_plugin_parser_handler_install(const char *package, xmlDocPtr doc)
+{
+ GList *list = NULL;
+ GList *tmp = NULL;
+ const char *name;
+ xmlNode *root;
+ xmlNode *node;
+ int ret;
+
+ if (!doc || !package) {
+ LOGE("Invalid parameter");
+ return -1;
+ }
+
+ root = xmlDocGetRootElement(doc);
+ if (!root) {
+ LOGE("Failed to get root element");
+ return -1;
+ }
+
+ __set_root_path(package);
+
+ for (node = root->children; node; node = node->next) {
+ name = __get_name(node);
+ if (!name)
+ continue;
+
+ if (strcmp(name, "component-based-application") != 0)
+ continue;
+
+ ret = __parse_component_based_application(package, node, &tmp);
+ if (ret < 0) {
+ LOGE("Failed to parse component-based-application");
+ g_list_free_full(list, __destroy_component);
+ return -1;
+ }
+
+ if (!tmp) {
+ LOGE("Component info is empty");
+ g_list_free_full(list, __destroy_component);
+ return -1;
+ }
+
+ __fill_extra_info(tmp);
+ list = g_list_concat(list, tmp);
+ tmp = NULL;
+ }
+
+ if (!list) {
+ LOGE("Component info is empty");
+ return -1;
+ }
+
+ ret = __insert_component_info(list);
+ g_list_free_full(list, __destroy_component);
+
+ return ret;
+}
+
+int component_plugin_parser_handler_uninstall(const char *package)
+{
+ int ret;
+
+ ret = component_plugin_parser_db_begin_transaction();
+ if (ret < 0) {
+ LOGE("Failed to initialize db");
+ return -1;
+ }
+
+ ret = component_plugin_parser_db_delete(package);
+ if (ret < 0) {
+ LOGE("Failed to delete component info(%s)", package);
+ component_plugin_parser_db_rollback();
+ return -1;
+ }
+
+ return component_plugin_parser_db_end_transaction();
+}
+
+int component_plugin_parser_handler_init(void)
+{
+ return component_plugin_parser_db_init();
+}
+
+int component_plugin_parser_handler_fini(void)
+{
+ return component_plugin_parser_db_fini();
+}
--- /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 <glib.h>
+#include <libxml/tree.h>
+
+#include "component_plugin_parser.h"
+#include "component_plugin_parser_private.h"
+
+EXPORT int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr doc, const char *package)
+{
+ return component_plugin_parser_install(doc, package);
+}
+
+EXPORT int PKGMGR_PARSER_PLUGIN_UNINSTALL(xmlDocPtr doc, const char *package)
+{
+ return component_plugin_parser_uninstall(doc, package);
+}
+
+EXPORT int PKGMGR_PARSER_PLUGIN_UPGRADE(xmlDocPtr doc, const char *package)
+{
+ return component_plugin_parser_upgrade(doc, package);
+}
+
+EXPORT int PKGMGR_PARSER_PLUGIN_RECOVERINSTALL(xmlDocPtr doc,
+ const char *package)
+{
+ return component_plugin_parser_uninstall(doc, package);
+}
+
+EXPORT int PKGMGR_PARSER_PLUGIN_RECOVERUNINSTALL(xmlDocPtr doc,
+ const char *package)
+{
+ return component_plugin_parser_uninstall(doc, package);
+}
+
+EXPORT int PKGMGR_PARSER_PLUGIN_RECOVERUPGRADE(xmlDocPtr doc,
+ const char *package)
+{
+ return component_plugin_parser_upgrade(doc, package);
+}
+
--- /dev/null
+SET(TARGET_CHECK_EXEC_PLUGIN_PARSER "exec-checker")
+
+SET(SHARED_DIR "${CMAKE_INSTALL_PREFIX}/share")
+
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall -Werror -Winline")
+
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src
+ CHECK_EXEC_PLUGIN_PARSER_SRCS)
+
+ADD_LIBRARY(${TARGET_CHECK_EXEC_PLUGIN_PARSER} SHARED ${CHECK_EXEC_PLUGIN_PARSER_SRCS})
+TARGET_LINK_LIBRARIES(${TARGET_CHECK_EXEC_PLUGIN_PARSER} PUBLIC dl)
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_CHECK_EXEC_PLUGIN_PARSER}
+ PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/inc)
+
+APPLY_PKG_CONFIG(${TARGET_CHECK_EXEC_PLUGIN_PARSER} PUBLIC
+ DLOG_DEPS
+ GLIB_DEPS
+ LIBTZPLATFORM_CONFIG_DEPS
+ LIBXML_DEPS
+ PKGMGR_INFO_DEPS
+ PKGMGR_INSTALLER_DEPS
+)
+
+INSTALL(TARGETS ${TARGET_CHECK_EXEC_PLUGIN_PARSER}
+ DESTINATION ${SYSCONF_INSTALL_DIR}/package-manager/parserlib)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/exec-checker.info
+ DESTINATION ${SHARED_DIR}/parser-plugins)
--- /dev/null
+type="tag";name="ui-application";path="/etc/package-manager/parserlib/libexec-checker.so"
+type="tag";name="service-application";path="/etc/package-manager/parserlib/libexec-checker.so"
+type="tag";name="widget-application";path="/etc/package-manager/parserlib/libexec-checker.so"
+type="tag";name="watch-application";path="/etc/package-manager/parserlib/libexec-checker.so"
+type="tag";name="component-based-application";path="/etc/package-manager/parserlib/libexec-checker.so"
--- /dev/null
+/*
+ * Copyright (c) 2021 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 EXEC_CHECKER_HH_
+#define EXEC_CHECKER_HH_
+
+#include <string>
+
+namespace plugin {
+
+class ExecChecker {
+ public:
+ explicit ExecChecker(std::string path);
+ ~ExecChecker() = default;
+ bool IsShared();
+ bool CheckMainSymbol();
+ bool CheckDependencyLibs();
+ bool IsSameArch(const ExecChecker& exe);
+
+ private:
+ std::string path_;
+ int class_bit_ = 0;
+ uint16_t arch_bit_ = 0;
+ uint16_t type_ = 0;
+};
+
+} // namespace plugin
+
+#endif // EXEC_CHECKER_HH_
--- /dev/null
+/*
+ * Copyright (c) 2021 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 EXEC_CEHCKER_PRIVATE_HH_
+#define EXEC_CEHCKER_PRIVATE_HH_
+
+#include <dlog.h>
+#include <stdio.h>
+
+#undef API
+#define API __attribute__((visibility("default")))
+
+#define ROOT_UID 0
+
+#undef LOG_TAG
+#define LOG_TAG "EXEC_CHECKER_PLUGIN_PARSER"
+
+#define LOGE_STD(fmt, arg...) \
+ fprintf(stderr, "[%s][ERROR] " fmt "\n", LOG_TAG, ##arg)
+#define LOGW_STD(fmt, arg...) \
+ fprintf(stderr, "[%s][WARNING] " fmt "\n", LOG_TAG, ##arg)
+#define LOGI_STD(fmt, arg...) printf("[%s][INFO] " fmt "\n", LOG_TAG, ##arg)
+
+#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
+
+#endif // EXEC_CEHCKER_PRIVATE_HH_
--- /dev/null
+/*
+ * Copyright (c) 2021 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 EXEC_CHECKER_PLUGIN_MANAGER_HH_
+#define EXEC_CHECKER_PLUGIN_MANAGER_HH_
+
+#include <libxml/tree.h>
+#include <memory>
+#include <string>
+
+#include "exec_checker.hh"
+
+namespace plugin {
+
+class PluginManager {
+ public:
+ static PluginManager& GetInst();
+ void Init(xmlDocPtr doc, std::string package);
+ int Process();
+ ~PluginManager() = default;
+
+ private:
+ PluginManager();
+
+ private:
+ std::unique_ptr<ExecChecker> self_;
+ std::string package_;
+ xmlDocPtr doc_ = nullptr;
+};
+
+} // namespace plugin
+
+#endif // EXEC_CHECKER_PLUGIN_MANAGER_HH_
--- /dev/null
+/*
+ * Copyright (c) 2021 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 <dlfcn.h>
+#include <elf.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include <uuid/uuid.h>
+
+#include <fstream>
+#include <memory>
+#include <string>
+#include <utility>
+
+#include "exec_checker.hh"
+#include "exec_checker_private.hh"
+
+namespace plugin {
+namespace {
+
+union header {
+ char c[4096];
+ Elf32_Ehdr ehdr32;
+ Elf64_Ehdr ehdr64;
+};
+
+template <typename Shdr>
+Shdr* GetSectionFromShdr(const char* name, Shdr* shdr,
+ const char* shdr_names, int e_shnum) {
+ for (int i = 0; i < e_shnum; ++i) {
+ if (shdr[i].sh_size) {
+ if (!strcmp(&shdr_names[shdr[i].sh_name], name))
+ return &shdr[i];
+ }
+ }
+
+ return nullptr;
+}
+
+int Read(FILE* fp, void* ptr, long offset, size_t size) {
+ if (offset < 0 || size == 0) {
+ LOGE_STD("Invalid parameter");
+ return -1;
+ }
+
+ if (fseek(fp, offset, SEEK_SET) < 0) {
+ LOGE_STD("fseek() is failed. errno(%d)", errno);
+ return -1;
+ }
+
+ auto nbytes = fread(ptr, 1, size, fp);
+ if (nbytes <= 0) {
+ LOGE_STD("fread() is failed. error(%zd)", nbytes);
+ return -1;
+ }
+
+ return 0;
+}
+
+char* GetDataFromFile(FILE* fp, unsigned long offset, size_t size) {
+ if (size == 0) {
+ LOGE_STD("Invalid parameter");
+ return nullptr;
+ }
+
+ void* ptr = malloc(size);
+ if (ptr == nullptr) {
+ LOGE_STD("Out of memory");
+ return nullptr;
+ }
+
+ if (Read(fp, ptr, static_cast<long>(offset & LONG_MAX), size) < 0) {
+ free(ptr);
+ return nullptr;
+ }
+
+ return static_cast<char*>(ptr);
+}
+
+template <typename Ehdr, typename Half, typename Shdr, typename Sym>
+bool FindMainSymbolFromEhdr(FILE* fp, Ehdr* ehdr) {
+ rewind(fp);
+ Half shdr_tab_size = ehdr->e_shentsize * ehdr->e_shnum;
+ Shdr shdr_tab[shdr_tab_size];
+ if (Read(fp, &shdr_tab, static_cast<long>(ehdr->e_shoff & LONG_MAX),
+ shdr_tab_size) < 0)
+ return false;
+
+ if (ehdr->e_shstrndx >= shdr_tab_size)
+ return false;
+
+ char* shdr_names = GetDataFromFile(fp, shdr_tab[ehdr->e_shstrndx].sh_offset,
+ shdr_tab[ehdr->e_shstrndx].sh_size);
+ if (shdr_names == nullptr)
+ return false;
+
+ std::unique_ptr<char, decltype(std::free)*> shdr_names_auto(
+ shdr_names, std::free);
+
+ auto* shdr_strtab = GetSectionFromShdr<Shdr>(
+ ".dynstr", shdr_tab, shdr_names, ehdr->e_shnum);
+ if (shdr_strtab == nullptr)
+ return false;
+
+ auto* shdr_symtab = GetSectionFromShdr<Shdr>(
+ ".dynsym", shdr_tab, shdr_names, ehdr->e_shnum);
+ if (shdr_symtab == nullptr)
+ return false;
+
+ if (shdr_symtab->sh_type == SHT_DYNSYM) {
+ auto* symtab = reinterpret_cast<Sym*>(GetDataFromFile(fp,
+ shdr_symtab->sh_offset, shdr_symtab->sh_size));
+ if (symtab == nullptr)
+ return false;
+
+ std::unique_ptr<Sym, decltype(std::free)*> symtab_auto(symtab, std::free);
+
+ auto* strtab = GetDataFromFile(fp, shdr_strtab->sh_offset,
+ shdr_strtab->sh_size);
+ if (strtab == nullptr)
+ return false;
+
+ std::unique_ptr<char, decltype(std::free)*> strtab_auto(strtab, std::free);
+
+ int size = shdr_symtab->sh_size / sizeof(Sym);
+ for (int i = 0; i < size; ++i) {
+ char* name = strtab + symtab[i].st_name;
+ if (name && !strcmp(name, "main"))
+ return true;
+ }
+ }
+
+ return false;
+}
+
+} // namespace
+
+ExecChecker::ExecChecker(std::string path) : path_(std::move(path)) {
+ int fd = open(path_.c_str(), O_RDONLY);
+ if (fd < 0) {
+ LOGE_STD("Failed to open file(%s). errno(%d)", path_.c_str(), errno);
+ return;
+ }
+
+ header h;
+ ssize_t nbyte = read(fd, h.c, sizeof(h));
+ close(fd);
+ if (nbyte < 2) {
+ LOGE_STD("Failed to read file(%s). errno(%d)", path_.c_str(), errno);
+ return;
+ }
+
+ if (nbyte < SELFMAG || memcmp(h.c, ELFMAG, SELFMAG) != 0) {
+ LOGE_STD("This binary is not elf format(%s)", path_.c_str());
+ return;
+ }
+
+ if (nbyte >= static_cast<int>(sizeof(Elf32_Ehdr)) &&
+ h.c[EI_CLASS] == ELFCLASS32) {
+ class_bit_ = 32;
+ arch_bit_ = h.ehdr32.e_machine;
+ type_ = h.ehdr32.e_type;
+ } else if (nbyte >= static_cast<int>(sizeof(Elf64_Ehdr)) &&
+ h.c[EI_CLASS] == ELFCLASS64) {
+ class_bit_ = 64;
+ arch_bit_ = h.ehdr64.e_machine;
+ type_ = h.ehdr64.e_type;
+ }
+ LOGI_STD("%s class: %dbit, e_machine: %hu, e_type : %hu",
+ path_.c_str(), class_bit_, arch_bit_, type_);
+}
+
+bool ExecChecker::IsShared() {
+ return type_ == ET_DYN;
+}
+
+bool ExecChecker::CheckMainSymbol() {
+ FILE* fp = fopen(path_.c_str(), "r");
+ if (fp == nullptr) {
+ LOGE_STD("fopen() is failed. errno(%d)", errno);
+ return false;
+ }
+
+ std::unique_ptr<FILE, decltype(fclose)*> fp_auto(fp, fclose);
+ header h;
+ size_t nbytes = fread(h.c, 1, sizeof(h), fp);
+ if (nbytes < 2) {
+ LOGE_STD("fread() is failed");
+ return false;
+ }
+
+ if (class_bit_ == 64) {
+ return FindMainSymbolFromEhdr<Elf64_Ehdr, Elf64_Half, Elf64_Shdr, Elf64_Sym>(
+ fp, &h.ehdr64);
+ }
+
+ return FindMainSymbolFromEhdr<Elf32_Ehdr, Elf32_Half, Elf32_Shdr, Elf32_Sym>(
+ fp, &h.ehdr32);
+}
+
+bool ExecChecker::CheckDependencyLibs() {
+ std::string root_path = path_.substr(0, path_.find_last_of('/') - 4);
+ char uuid[37];
+ uuid_t u;
+ uuid_generate(u);
+ uuid_unparse(u, uuid);
+
+ std::string tmp = std::string("/tmp/") +
+ path_.substr(path_.find_last_of('/') + 1) + "_" + uuid;
+ std::string cmd = "LD_LIBRARY_PATH=" + root_path + "/lib /usr/bin/ldd " +
+ path_ + " > " + tmp;
+
+ if (tmp.size() > PATH_MAX)
+ tmp = tmp.substr(0, PATH_MAX);
+
+ bool pass = true;
+ int ret = WEXITSTATUS(system(cmd.c_str()));
+ if (ret != 0) {
+ LOGE_STD("Failed to execute ldd %s, (%d)", cmd.c_str(), ret);
+ return false;
+ }
+
+ std::ifstream f(tmp);
+ char buf[1000];
+ while (!f.eof()) {
+ f.getline(buf, sizeof(buf));
+
+ std::string line = buf;
+ if (line.find("not found", 0) != line.npos) {
+ LOGE_STD("Not found library (%s)",
+ line.substr(0, line.find_first_of(' ', 0)).c_str());
+ pass = false;
+ break;
+ }
+ }
+
+ f.close();
+ remove(tmp.c_str());
+ return pass;
+}
+
+bool ExecChecker::IsSameArch(const ExecChecker& exe) {
+ return class_bit_ == exe.class_bit_ && arch_bit_ == exe.arch_bit_;
+}
+
+} // namespace plugin
--- /dev/null
+/*
+ * Copyright (c) 2021 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 <glib.h>
+#include <libxml/tree.h>
+
+#include "exec_checker_private.hh"
+#include "plugin_manager.hh"
+
+namespace {
+
+int Run(xmlDocPtr doc, const char* package) {
+ if (doc == nullptr || package == nullptr) {
+ LOGE_STD("Invalid parameter doc(%p) package(%p)", doc, package);
+ return -1;
+ }
+ auto& manager = plugin::PluginManager::GetInst();
+ manager.Init(doc, package);
+ return manager.Process();
+}
+
+} // namespace
+
+extern "C" API int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr doc,
+ const char* package) {
+ return Run(doc, package);
+}
+
+extern "C" API int PKGMGR_PARSER_PLUGIN_UPGRADE(xmlDocPtr doc,
+ const char* package) {
+ return Run(doc, package);
+}
+
+extern "C" API int PKGMGR_PARSER_PLUGIN_RECOVERINSTALL(xmlDocPtr doc,
+ const char* package) {
+ return Run(doc, package);
+}
+
+extern "C" API int PKGMGR_PARSER_PLUGIN_RECOVERUPGRADE(xmlDocPtr doc,
+ const char* package) {
+ return Run(doc, package);
+}
--- /dev/null
+/*
+ * Copyright (c) 2021 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 <libxml/tree.h>
+#include <pkgmgr-info.h>
+#include <pkgmgr_installer_info.h>
+#include <unistd.h>
+
+#include <memory>
+#include <string>
+#include <utility>
+
+#include "exec_checker.hh"
+#include "exec_checker_private.hh"
+#include "plugin_manager.hh"
+
+namespace plugin {
+namespace {
+
+std::string GetAttribute(xmlNode* node, const char* key) {
+ std::string ret;
+ xmlChar* val = xmlGetProp(node, reinterpret_cast<const xmlChar*>(key));
+ if (val != nullptr) {
+ ret = reinterpret_cast<char*>(val);
+ xmlFree(val);
+ }
+
+ return ret;
+}
+
+} // namespace
+
+PluginManager::PluginManager() {
+ char path[1024];
+ int nbyte = readlink("/proc/self/exe", path, sizeof(path) - 1);
+ if (nbyte == -1) {
+ LOGE_STD("Failed to get path. errno(%d)", errno);
+ return;
+ }
+
+ path[nbyte] = '\0';
+ self_ = std::unique_ptr<ExecChecker>(new (std::nothrow) ExecChecker(path));
+ if (self_ == nullptr)
+ LOGE_STD("Out of memory");
+}
+
+PluginManager& PluginManager::GetInst() {
+ static PluginManager inst;
+ return inst;
+}
+
+void PluginManager::Init(xmlDocPtr doc, std::string package) {
+ package_ = std::move(package);
+ doc_ = doc;
+}
+
+int PluginManager::Process() {
+ xmlNode* root = xmlDocGetRootElement(doc_);
+ if (root == nullptr) {
+ LOGE_STD("Failed to get root element");
+ return -1;
+ }
+ uid_t uid;
+ int ret = pkgmgr_installer_info_get_target_uid(&uid);
+ if (ret != PMINFO_R_OK) {
+ LOGE_STD("Failed to get target uid. (%s)", package_.c_str());
+ return -1;
+ }
+
+ for (xmlNode* node = root->children; node; node = node->next) {
+ auto* apptype = reinterpret_cast<const char*>(node->name);
+ if (apptype == nullptr)
+ continue;
+
+ std::string appid = GetAttribute(node, "appid");
+ if (appid.empty()) {
+ LOGE_STD("Failed to find appid. (%s)", appid.c_str());
+ return -1;
+ }
+
+ pkgmgrinfo_appinfo_h app_info;
+ ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid.c_str(), uid, &app_info);
+ if (ret < 0) {
+ LOGE_STD("Failed to get appinfo. (%s)", appid.c_str());
+ return -1;
+ }
+ auto app_info_auto =
+ std::unique_ptr<std::remove_pointer_t<pkgmgrinfo_appinfo_h>,
+ decltype(pkgmgrinfo_appinfo_destroy_appinfo)*>(
+ app_info, pkgmgrinfo_appinfo_destroy_appinfo);
+
+ char* exec = nullptr;
+ ret = pkgmgrinfo_appinfo_get_exec(app_info, &exec);
+ if (ret < 0) {
+ LOGE_STD("Failed to get app path. (%s)", package_.c_str());
+ return -1;
+ }
+
+ std::string app_type = GetAttribute(node, "type");
+ if (app_type != "capp" && app_type != "c++app")
+ continue;
+
+ LOGI_STD("Check binary: %s", exec);
+ ExecChecker checker(exec);
+
+ if (!self_->IsSameArch(checker))
+ return -1;
+
+ if (!checker.IsShared())
+ LOGW("%s is not shared object", exec);
+
+ if (!checker.CheckMainSymbol())
+ LOGW_STD("Failed to find main symbol");
+
+ if (!checker.CheckDependencyLibs())
+ return -1;
+ }
+
+ return 0;
+}
+
+} // namespace plugin
--- /dev/null
+ADD_SUBDIRECTORY(alias-appid)
+ADD_SUBDIRECTORY(allowed-appid)
--- /dev/null
+SET(TARGET_ALIAS_APPID_PLUGIN "alias-appid-plugin")
+
+SET(SHARED_DIR "${CMAKE_INSTALL_PREFIX}/share")
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
+
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} ALIAS_APPID_PLUGIN_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../common COMMON_SRCS)
+
+ADD_LIBRARY(${TARGET_ALIAS_APPID_PLUGIN} SHARED
+ ${ALIAS_APPID_PLUGIN_SRCS}
+ ${COMMON_SRCS})
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_ALIAS_APPID_PLUGIN} PUBLIC
+ "${CMAKE_CURRENT_SOURCE_DIR}/../")
+
+APPLY_PKG_CONFIG(${TARGET_ALIAS_APPID_PLUGIN} PUBLIC
+ DLOG_DEPS
+ GLIB_DEPS
+ LIBTZPLATFORM_CONFIG_DEPS
+ LIBXML_DEPS
+ PKGMGR_INSTALLER_DEPS
+ SQLITE3_DEPS
+)
+
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/alias-appid.info
+ DESTINATION ${SHARED_DIR}/parser-plugins)
+INSTALL(TARGETS ${TARGET_ALIAS_APPID_PLUGIN}
+ DESTINATION ${SYSCONF_INSTALL_DIR}/package-manager/parserlib/metadata)
--- /dev/null
+/*
+ * Copyright (c) 2020 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 ALIAS_APPID_ALIAS_INFO_HH_
+#define ALIAS_APPID_ALIAS_INFO_HH_
+
+#include <string>
+
+namespace plugin {
+
+class AliasInfo {
+ public:
+ AliasInfo(std::string alias_appid, std::string appid)
+ : alias_appid_(std::move(alias_appid)), appid_(std::move(appid)) {
+ }
+
+ virtual ~AliasInfo() = default;
+
+ const std::string& GetAliasAppId() const {
+ return alias_appid_;
+ }
+
+ const std::string& GetAppId() const {
+ return appid_;
+ }
+
+ private:
+ std::string alias_appid_;
+ std::string appid_;
+};
+
+} // namespace plugin
+
+#endif // ALIAS_APPID_ALIAS_INFO_HH_
--- /dev/null
+/*
+ * Copyright (c) 2020 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 <tzplatform_config.h>
+
+#include <memory>
+
+#include "alias-appid/appsvc_db.hh"
+#include "common/log_private.hh"
+
+namespace plugin {
+
+static const uid_t ROOT_UID = 0;
+static const uid_t GLOBAL_USER = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
+
+AppSvcDB::AppSvcDB(uid_t uid) : Database(GetDBPath(uid)) {
+}
+
+AppSvcDB::~AppSvcDB() = default;
+
+std::vector<std::shared_ptr<AliasInfo>> AppSvcDB::Select(
+ const std::string& appid) {
+ static const char query[] = "SELECT alias_appid FROM alias_info "
+ "WHERE appid = ?;";
+ sqlite3_stmt* stmt;
+ __PREPARE_V2(GetHandle(), query, strlen(query), stmt);
+ auto stmt_ptr = std::unique_ptr<sqlite3_stmt, decltype(sqlite3_finalize)*>(
+ stmt, sqlite3_finalize);
+ __BIND_TEXT(GetHandle(), stmt, 1, appid.c_str());
+
+ std::vector<std::shared_ptr<AliasInfo>> infos;
+ while (sqlite3_step(stmt) == SQLITE_ROW) {
+ std::string alias_appid = ColumnText(stmt, 0);
+ if (!alias_appid.empty())
+ infos.emplace_back(new (std::nothrow) AliasInfo(alias_appid, appid));
+ }
+
+ return infos;
+}
+
+void AppSvcDB::Insert(const std::string& alias_appid,
+ const std::string& appid) {
+ static const char query[] = "INSERT OR REPLACE INTO "
+ "alias_info(alias_appid, appid) VALUES(?, ?);";
+ sqlite3_stmt* stmt;
+ __PREPARE_V2(GetHandle(), query, strlen(query), stmt);
+ std::unique_ptr<sqlite3_stmt, decltype(sqlite3_finalize)*> stmt_ptr(
+ stmt, sqlite3_finalize);
+ __BIND_TEXT(GetHandle(), stmt, 1, alias_appid.c_str());
+ __BIND_TEXT(GetHandle(), stmt, 2, appid.c_str());
+ __STEP(GetHandle(), stmt);
+}
+
+void AppSvcDB::Delete(const std::string& alias_appid,
+ const std::string& appid) {
+ static const char query[] = "DELETE FROM alias_info WHERE "
+ "alias_appid = ? AND appid = ?;";
+ sqlite3_stmt* stmt;
+ __PREPARE_V2(GetHandle(), query, strlen(query), stmt);
+ std::unique_ptr<sqlite3_stmt, decltype(sqlite3_finalize)*> stmt_ptr(
+ stmt, sqlite3_finalize);
+ __BIND_TEXT(GetHandle(), stmt, 1, alias_appid.c_str());
+ __BIND_TEXT(GetHandle(), stmt, 2, appid.c_str());
+ __STEP(GetHandle(), stmt);
+}
+
+void AppSvcDB::Delete(const std::string& appid) {
+ static const char query[] = "DELETE FROM alias_info WHERE appid = ?;";
+ sqlite3_stmt* stmt;
+ __PREPARE_V2(GetHandle(), query, strlen(query), stmt);
+ std::unique_ptr<sqlite3_stmt, decltype(sqlite3_finalize)*> stmt_ptr(
+ stmt, sqlite3_finalize);
+ __BIND_TEXT(GetHandle(), stmt, 1, appid.c_str());
+ __STEP(GetHandle(), stmt);
+}
+
+std::string AppSvcDB::GetDBPath(uid_t uid) {
+ std::string db_path;
+ if (uid == ROOT_UID || uid == GLOBAL_USER) {
+ db_path = std::string(tzplatform_getenv(TZ_SYS_DB)) + "/.appsvc.db";
+ } else {
+ db_path = std::string(tzplatform_getenv(TZ_SYS_DB)) + "/user/" +
+ std::to_string(uid) + "/.appsvc.db";
+ }
+ return db_path;
+}
+
+} // namespace plugin
--- /dev/null
+/*
+ * Copyright (c) 2020 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 ALIAS_APPID_APPSVC_DB_HH_
+#define ALIAS_APPID_APPSVC_DB_HH_
+
+#include <unistd.h>
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "alias-appid/alias_info.hh"
+#include "common/database.hh"
+
+namespace plugin {
+
+class AppSvcDB : public Database {
+ public:
+ explicit AppSvcDB(uid_t uid);
+ virtual ~AppSvcDB();
+
+ std::vector<std::shared_ptr<AliasInfo>> Select(const std::string& appid);
+ void Insert(const std::string& alias_appid, const std::string& appid);
+ void Delete(const std::string& alias_appid, const std::string& appid);
+ void Delete(const std::string& appid);
+
+ private:
+ static std::string GetDBPath(uid_t uid);
+};
+
+} // namespace plugin
+
+#endif // ALIAS_APPID_APPSVC_DB_HH_
--- /dev/null
+type="metadata";name="http://tizen.org/metadata/aliasappid";path="/etc/package-manager/parserlib/metadata/libalias-appid-plugin.so"
--- /dev/null
+/*
+ * Copyright (c) 2020 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 <glib.h>
+
+#include "common/log_private.hh"
+#include "alias-appid/plugin_manager.hh"
+
+#undef API
+#define API __attribute__ ((visibility("default")))
+
+using namespace plugin;
+
+extern "C" API int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char* pkgid,
+ const char* appid, GList* list) {
+ _W("[__ALIAS_APPID__] pkgid(%s), appid(%s)", pkgid, appid);
+ PluginManager::GetInst().AddAppEventArgs(pkgid, appid,
+ EventType::Install, list);
+ PluginManager::GetInst().Do();
+ return 0;
+}
+
+extern "C" API int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char* pkgid,
+ const char* appid, GList* list) {
+ _W("[__ALIAS_APPID__] pkgid(%s), appid(%s)", pkgid, appid);
+ PluginManager::GetInst().AddAppEventArgs(pkgid, appid,
+ EventType::Uninstall, list);
+ PluginManager::GetInst().Do();
+ return 0;
+}
+
+extern "C" API int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char* pkgid,
+ const char* appid, GList* list) {
+ _W("[__ALIAS_APPID__] pkgid(%s), appid(%s)", pkgid, appid);
+ PluginManager::GetInst().AddAppEventArgs(pkgid, appid,
+ EventType::Upgrade, list);
+ PluginManager::GetInst().Do();
+ return 0;
+}
+
+extern "C" API int PKGMGR_MDPARSER_PLUGIN_RECOVERINSTALL(const char* pkgid,
+ const char* appid, GList* list) {
+ _W("[__ALIAS_APPID__] pkgid(%s), appid(%s)", pkgid, appid);
+ PluginManager::GetInst().AddAppEventArgs(pkgid, appid,
+ EventType::Uninstall, list);
+ PluginManager::GetInst().Do();
+ return 0;
+}
+
+extern "C" API int PKGMGR_MDPARSER_PLUGIN_RECOVERUNINSTALL(const char* pkgid,
+ const char* appid, GList* list) {
+ _W("[__ALIAS_APPID__] pkgid(%s), appid(%s)", pkgid, appid);
+ PluginManager::GetInst().AddAppEventArgs(pkgid, appid,
+ EventType::Uninstall, list);
+ PluginManager::GetInst().Do();
+ return 0;
+}
+
+extern "C" API int PKGMGR_MDPARSER_PLUGIN_RECOVERUPGRADE(const char* pkgid,
+ const char* appid, GList* list) {
+ _W("[__ALIAS_APPID__] pkgid(%s), appid(%s)", pkgid, appid);
+ PluginManager::GetInst().AddAppEventArgs(pkgid, appid,
+ EventType::Upgrade, list);
+ PluginManager::GetInst().Do();
+ return 0;
+}
+
+extern "C" API int PKGMGR_MDPARSER_PLUGIN_CLEAN(const char* pkgid,
+ const char* appid, GList* list) {
+ _W("[__ALIAS_APPID__] pkgid(%s), appid(%s)", pkgid, appid);
+ PluginManager::GetInst().Clean();
+ return 0;
+}
+
+extern "C" API int PKGMGR_MDPARSER_PLUGIN_UNDO(const char* pkgid,
+ const char* appid, GList* list) {
+ _W("[__ALIAS_APPID__] pkgid(%s), appid(%s)", pkgid, appid);
+ PluginManager::GetInst().Undo();
+ return 0;
+}
+
+extern "C" API int PKGMGR_MDPARSER_PLUGIN_REMOVED(const char* pkgid,
+ const char* appid, GList* list) {
+ _W("[__ALIAS_APPID__] pkgid(%s), appid(%s)", pkgid, appid);
+ return 0;
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 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 "alias-appid/appsvc_db.hh"
+#include "alias-appid/plugin_manager.hh"
+#include "common/exception.hh"
+#include "common/log_private.hh"
+
+namespace plugin {
+
+PluginManager::PluginManager()
+ : MetadataPlugin(std::unique_ptr<Database>(
+ new AppSvcDB(MetadataPlugin::GetUid()))) {
+}
+
+PluginManager::~PluginManager() = default;
+
+PluginManager& PluginManager::GetInst() {
+ static PluginManager inst;
+ return inst;
+}
+
+bool PluginManager::StepBackup(const std::unique_ptr<AppEventArgs>& args) {
+ auto* db = dynamic_cast<AppSvcDB*>(GetDB());
+ if (db == nullptr) {
+ _E("MetadataPlugin is not prepared");
+ return false;
+ }
+
+ try {
+ auto info_arr = db->Select(args->GetAppId());
+ if (info_arr.size() != 0)
+ infos_.insert(infos_.end(), info_arr.begin(), info_arr.end());
+ } catch (Exception& e) {
+ _E("Exception(%d) occurs", e.GetErrorCode());
+ return false;
+ }
+
+ return true;
+}
+
+bool PluginManager::StepInstall(const std::unique_ptr<AppEventArgs>& args) {
+ auto* db = dynamic_cast<AppSvcDB*>(GetDB());
+ if (db == nullptr) {
+ _E("MetadataPlugin is not prepared");
+ return false;
+ }
+
+ for (auto& metadata : args->GetMetadataList()) {
+ try {
+ db->Insert(metadata->GetValue(), args->GetAppId());
+ } catch (Exception& e) {
+ return false;
+ }
+ }
+ return true;
+}
+
+bool PluginManager::StepUninstall(const std::unique_ptr<AppEventArgs>& args) {
+ auto* db = dynamic_cast<AppSvcDB*>(GetDB());
+ if (db == nullptr) {
+ _E("MetadataPlugin is not prepared");
+ return false;
+ }
+
+ if (args->GetMetadataList().empty()) {
+ try {
+ db->Delete(args->GetAppId());
+ } catch (Exception& e) {
+ _W("Failed to delete alias info. appid(%s)", args->GetAppId().c_str());
+ }
+ return true;
+ }
+
+ for (auto& metadata : args->GetMetadataList()) {
+ try {
+ db->Delete(metadata->GetValue(), args->GetAppId());
+ } catch (Exception& e) {
+ return false;
+ }
+ }
+ return true;
+}
+
+bool PluginManager::StepUpgrade(const std::unique_ptr<AppEventArgs>& args) {
+ auto* db = dynamic_cast<AppSvcDB*>(GetDB());
+ if (db == nullptr) {
+ _E("MetadataPlugin is not prepared");
+ return false;
+ }
+
+ try {
+ db->Delete(args->GetAppId());
+ } catch (Exception& e) {
+ _W("Failed to delete alias info. appid(%s)", args->GetAppId().c_str());
+ }
+
+ return StepInstall(args);
+}
+
+bool PluginManager::StepRestore() {
+ _E("Restore");
+ auto* db = dynamic_cast<AppSvcDB*>(GetDB());
+ if (db == nullptr) {
+ _E("MetadataPlugin is not prepared");
+ return false;
+ }
+
+ for (auto& info : infos_) {
+ try {
+ db->Insert(info->GetAliasAppId(), info->GetAppId());
+ } catch (Exception& e) {
+ _E("Exception(%d) occurs", e.GetErrorCode());
+ return false;
+ }
+ }
+
+ return true;
+}
+
+} // namespace plugin
--- /dev/null
+/*
+ * Copyright (c) 2020 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 ALIAS_APPID_PLUGIN_MANAGER_HH_
+#define ALIAS_APPID_PLUGIN_MANAGER_HH_
+
+#include <vector>
+
+#include "alias-appid/alias_info.hh"
+#include "common/metadata_plugin.hh"
+
+namespace plugin {
+
+class PluginManager : public MetadataPlugin {
+ private:
+ PluginManager();
+ ~PluginManager();
+
+ public:
+ static PluginManager& GetInst();
+
+ bool StepBackup(const std::unique_ptr<AppEventArgs>& args) override;
+ bool StepInstall(const std::unique_ptr<AppEventArgs>& args) override;
+ bool StepUninstall(const std::unique_ptr<AppEventArgs>& args) override;
+ bool StepUpgrade(const std::unique_ptr<AppEventArgs>& args) override;
+ bool StepRestore() override;
+
+ private:
+ std::vector<std::shared_ptr<AliasInfo>> infos_;
+};
+
+} // namespace plugin
+
+#endif // ALIAS_APPID_PLUGIN_MANAGER_HH_
--- /dev/null
+SET(TARGET_ALLOWED_APPID_PLUGIN "allowed-appid-plugin")
+
+SET(SHARED_DIR "${CMAKE_INSTALL_PREFIX}/share")
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
+
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} ALLOWED_APPID_PLUGIN_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../common COMMON_SRCS)
+
+ADD_LIBRARY(${TARGET_ALLOWED_APPID_PLUGIN} SHARED
+ ${ALLOWED_APPID_PLUGIN_SRCS}
+ ${COMMON_SRCS})
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_ALLOWED_APPID_PLUGIN} PUBLIC
+ "${CMAKE_CURRENT_SOURCE_DIR}/../")
+
+APPLY_PKG_CONFIG(${TARGET_ALLOWED_APPID_PLUGIN} PUBLIC
+ DLOG_DEPS
+ GLIB_DEPS
+ LIBTZPLATFORM_CONFIG_DEPS
+ LIBXML_DEPS
+ PKGMGR_INSTALLER_DEPS
+ SQLITE3_DEPS
+)
+
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/allowed-appid.info
+ DESTINATION ${SHARED_DIR}/parser-plugins)
+INSTALL(TARGETS ${TARGET_ALLOWED_APPID_PLUGIN}
+ DESTINATION ${SYSCONF_INSTALL_DIR}/package-manager/parserlib/metadata)
--- /dev/null
+/*
+ * Copyright (c) 2020 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 ALLOWED_APPID_ALLOWED_INFO_HH_
+#define ALLOWED_APPID_ALLOWED_INFO_HH_
+
+#include <memory>
+#include <string>
+
+namespace plugin {
+
+class AllowedInfo {
+ public:
+ AllowedInfo(std::string appid, std::string allowed_appid)
+ : appid_(std::move(appid)), allowed_appid_(std::move(allowed_appid)) {
+ }
+
+ virtual ~AllowedInfo() = default;
+
+ const std::string& GetAppId() const {
+ return appid_;
+ }
+
+ const std::string& GetAllowedAppId() const {
+ return allowed_appid_;
+ }
+
+ private:
+ std::string appid_;
+ std::string allowed_appid_;
+};
+
+} // namespace plugin
+
+#endif // ALLOWED_APPID_ALLOWED_INFO_HH_
--- /dev/null
+/*
+ * Copyright (c) 2020 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 <tzplatform_config.h>
+
+#include <memory>
+
+#include "allowed-appid/appsvc_db.hh"
+#include "common/log_private.hh"
+
+namespace plugin {
+
+static const uid_t ROOT_UID = 0;
+static const uid_t GLOBAL_USER = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
+
+AppSvcDB::AppSvcDB(uid_t uid) : Database(GetDBPath(uid)) {
+}
+
+AppSvcDB::~AppSvcDB() = default;
+
+std::vector<std::shared_ptr<AllowedInfo>> AppSvcDB::Select(
+ const std::string& appid) {
+ static const char query[] = "SELECT allowed_appid FROM "
+ "allowed_info WHERE appid = ?;";
+ sqlite3_stmt* stmt;
+ __PREPARE_V2(GetHandle(), query, strlen(query), stmt);
+ auto stmt_ptr = std::unique_ptr<sqlite3_stmt, decltype(sqlite3_finalize)*>(
+ stmt, sqlite3_finalize);
+ __BIND_TEXT(GetHandle(), stmt, 1, appid.c_str());
+
+ std::vector<std::shared_ptr<AllowedInfo>> allowed_infos;
+ while (sqlite3_step(stmt) == SQLITE_ROW) {
+ std::string allowed_appid = ColumnText(stmt, 0);
+ if (!allowed_appid.empty()) {
+ allowed_infos.emplace_back(
+ new (std::nothrow) AllowedInfo(appid, allowed_appid));
+ }
+ }
+
+ return allowed_infos;
+}
+
+void AppSvcDB::Insert(const std::string& appid,
+ const std::string& allowed_appid) {
+ static const char query[] = "INSERT OR REPLACE INTO "
+ "allowed_info(appid, allowed_appid) VALUES(?, ?);";
+ sqlite3_stmt* stmt;
+ __PREPARE_V2(GetHandle(), query, strlen(query), stmt);
+ std::unique_ptr<sqlite3_stmt, decltype(sqlite3_finalize)*> stmt_ptr(
+ stmt, sqlite3_finalize);
+ __BIND_TEXT(GetHandle(), stmt, 1, appid.c_str());
+ __BIND_TEXT(GetHandle(), stmt, 2, allowed_appid.c_str());
+ __STEP(GetHandle(), stmt);
+}
+
+void AppSvcDB::Delete(const std::string& appid) {
+ static const char query[] = "DELETE FROM allowed_info WHERE appid = ?;";
+ sqlite3_stmt* stmt;
+ __PREPARE_V2(GetHandle(), query, strlen(query), stmt);
+ std::unique_ptr<sqlite3_stmt, decltype(sqlite3_finalize)*> stmt_ptr(
+ stmt, sqlite3_finalize);
+ __BIND_TEXT(GetHandle(), stmt, 1, appid.c_str());
+ __STEP(GetHandle(), stmt);
+}
+
+std::string AppSvcDB::GetDBPath(uid_t uid) {
+ std::string db_path;
+ if (uid == ROOT_UID || uid == GLOBAL_USER) {
+ db_path = std::string(tzplatform_getenv(TZ_SYS_DB)) + "/.appsvc.db";
+ } else {
+ db_path = std::string(tzplatform_getenv(TZ_SYS_DB)) + "/user/" +
+ std::to_string(uid) + "/.appsvc.db";
+ }
+ return db_path;
+}
+
+} // namespace plugin
--- /dev/null
+/*
+ * Copyright (c) 2020 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 ALLOWED_APPID_APPSVC_DB_HH_
+#define ALLOWED_APPID_APPSVC_DB_HH_
+
+#include <unistd.h>
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "allowed-appid/allowed_info.hh"
+#include "common/database.hh"
+
+namespace plugin {
+
+class AppSvcDB : public Database {
+ public:
+ explicit AppSvcDB(uid_t uid);
+ virtual ~AppSvcDB();
+
+ std::vector<std::shared_ptr<AllowedInfo>> Select(const std::string& appid);
+ void Insert(const std::string& appid, const std::string& allowed_appid);
+ void Delete(const std::string& appid);
+
+ private:
+ static std::string GetDBPath(uid_t uid);
+};
+
+} // namespace plugin
+
+#endif // ALLOWED_APPID_APPSVC_DB_HH_
--- /dev/null
+type="metadata";name="http://tizen.org/metadata/allowedappid";path="/etc/package-manager/parserlib/metadata/liballowed-appid-plugin.so"
--- /dev/null
+/*
+ * Copyright (c) 2020 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 <glib.h>
+
+#include "allowed-appid/plugin_manager.hh"
+#include "common/log_private.hh"
+
+#undef API
+#define API __attribute__ ((visibility("default")))
+
+using namespace plugin;
+
+extern "C" API int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char* pkgid,
+ const char* appid, GList* list) {
+ _W("[__ALLOWED_APPID__] pkgid(%s), appid(%s)", pkgid, appid);
+ PluginManager::GetInst().AddAppEventArgs(pkgid, appid,
+ EventType::Install, list);
+ PluginManager::GetInst().Do();
+ return 0;
+}
+
+extern "C" API int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char* pkgid,
+ const char* appid, GList* list) {
+ _W("[__ALLOWED_APPID__] pkgid(%s), appid(%s)", pkgid, appid);
+ PluginManager::GetInst().AddAppEventArgs(pkgid, appid,
+ EventType::Uninstall, list);
+ PluginManager::GetInst().Do();
+ return 0;
+}
+
+extern "C" API int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char* pkgid,
+ const char* appid, GList* list) {
+ _W("[__ALLOWED_APPID__] pkgid(%s), appid(%s)", pkgid, appid);
+ PluginManager::GetInst().AddAppEventArgs(pkgid, appid,
+ EventType::Upgrade, list);
+ PluginManager::GetInst().Do();
+ return 0;
+}
+
+extern "C" API int PKGMGR_MDPARSER_PLUGIN_RECOVERINSTALL(const char* pkgid,
+ const char* appid, GList* list) {
+ _W("[__ALLOWED_APPID__] pkgid(%s), appid(%s)", pkgid, appid);
+ PluginManager::GetInst().AddAppEventArgs(pkgid, appid,
+ EventType::Uninstall, list);
+ PluginManager::GetInst().Do();
+ return 0;
+}
+
+extern "C" API int PKGMGR_MDPARSER_PLUGIN_RECOVERUNINSTALL(const char* pkgid,
+ const char* appid, GList* list) {
+ _W("[__ALLOWED_APPID__] pkgid(%s), appid(%s)", pkgid, appid);
+ PluginManager::GetInst().AddAppEventArgs(pkgid, appid,
+ EventType::Uninstall, list);
+ PluginManager::GetInst().Do();
+ return 0;
+}
+
+extern "C" API int PKGMGR_MDPARSER_PLUGIN_RECOVERUPGRADE(const char* pkgid,
+ const char* appid, GList* list) {
+ _W("[__ALLOWED_APPID__] pkgid(%s), appid(%s)", pkgid, appid);
+ PluginManager::GetInst().AddAppEventArgs(pkgid, appid,
+ EventType::Upgrade, list);
+ PluginManager::GetInst().Do();
+ return 0;
+}
+
+extern "C" API int PKGMGR_MDPARSER_PLUGIN_CLEAN(const char* pkgid,
+ const char* appid, GList* list) {
+ _W("[__ALLOWED_APPID__] pkgid(%s), appid(%s)", pkgid, appid);
+ PluginManager::GetInst().Clean();
+ return 0;
+}
+
+extern "C" API int PKGMGR_MDPARSER_PLUGIN_UNDO(const char* pkgid,
+ const char* appid, GList* list) {
+ _W("[__ALLOWED_APPID__] pkgid(%s), appid(%s)", pkgid, appid);
+ PluginManager::GetInst().Undo();
+ return 0;
+}
+
+extern "C" API int PKGMGR_MDPARSER_PLUGIN_REMOVED(const char* pkgid,
+ const char* appid, GList* list) {
+ _W("[__ALLOWED_APPID__] pkgid(%s), appid(%s)", pkgid, appid);
+ return 0;
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 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 "allowed-appid/appsvc_db.hh"
+#include "allowed-appid/plugin_manager.hh"
+#include "common/exception.hh"
+#include "common/log_private.hh"
+
+namespace plugin {
+
+PluginManager::PluginManager()
+ : MetadataPlugin(std::unique_ptr<Database>(
+ new AppSvcDB(MetadataPlugin::GetUid()))) {
+}
+
+PluginManager::~PluginManager() = default;
+
+PluginManager& PluginManager::GetInst() {
+ static PluginManager inst;
+ return inst;
+}
+
+bool PluginManager::StepBackup(const std::unique_ptr<AppEventArgs>& args) {
+ auto* db = dynamic_cast<AppSvcDB*>(GetDB());
+ if (db == nullptr) {
+ _E("MetadataPlugin is not prepared");
+ return false;
+ }
+
+ try {
+ auto info_arr = db->Select(args->GetAppId());
+ if (info_arr.size() != 0)
+ infos_.insert(infos_.end(), info_arr.begin(), info_arr.end());
+ } catch (Exception& e) {
+ _E("Execption(%d) occurs", e.GetErrorCode());
+ return false;
+ }
+
+ return true;
+}
+
+std::vector<std::string> PluginManager::Split(const std::string& str,
+ const std::string& delim) {
+ std::string string(str);
+ std::vector<std::string> result;
+ std::size_t pos;
+ while ((pos = string.find(delim)) != std::string::npos) {
+ std::string token = string.substr(0, pos);
+ result.push_back(token);
+ string.erase(0, pos + delim.length());
+ }
+ result.push_back(string);
+ return result;
+}
+
+bool PluginManager::StepInstall(const std::unique_ptr<AppEventArgs>& args) {
+ auto* db = dynamic_cast<AppSvcDB*>(GetDB());
+ if (db == nullptr) {
+ _E("MetadataPlugin is not prepared");
+ return false;
+ }
+
+ for (auto& metadata : args->GetMetadataList()) {
+ for (auto& app_id : Split(metadata->GetValue(), "|")) {
+ try {
+ db->Insert(args->GetAppId(), app_id);
+ } catch (Exception& e) {
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+bool PluginManager::StepUninstall(const std::unique_ptr<AppEventArgs>& args) {
+ auto* db = dynamic_cast<AppSvcDB*>(GetDB());
+ if (db == nullptr) {
+ _E("MetadataPlugin is not prepared");
+ return false;
+ }
+
+ try {
+ db->Delete(args->GetAppId());
+ } catch (Exception& e) {
+ _W("Failed to delete alias info. appid(%s)", args->GetAppId().c_str());
+ }
+ return true;
+}
+
+bool PluginManager::StepUpgrade(const std::unique_ptr<AppEventArgs>& args) {
+ if (!StepUninstall(args))
+ return false;
+
+ return StepInstall(args);
+}
+
+bool PluginManager::StepRestore() {
+ _E("Restore");
+ auto* db = dynamic_cast<AppSvcDB*>(GetDB());
+ if (db == nullptr) {
+ _E("MetadataPlugin is not prepared");
+ return false;
+ }
+
+ for (auto& info : infos_) {
+ try {
+ db->Insert(info->GetAppId(), info->GetAllowedAppId());
+ } catch (Exception& e) {
+ _E("Exception(%d) occurs", e.GetErrorCode());
+ return false;
+ }
+ }
+
+ return true;
+}
+
+} // namespace plugin
--- /dev/null
+/*
+ * Copyright (c) 2020 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 ALLOWED_APPID_PLUGIN_MANAGER_HH_
+#define ALLOWED_APPID_PLUGIN_MANAGER_HH_
+
+#include <vector>
+
+#include "common/metadata_plugin.hh"
+#include "allowed-appid/allowed_info.hh"
+
+namespace plugin {
+
+class PluginManager : public MetadataPlugin {
+ private:
+ PluginManager();
+ ~PluginManager();
+
+ public:
+ static PluginManager& GetInst();
+
+ bool StepBackup(const std::unique_ptr<AppEventArgs>& args) override;
+ bool StepInstall(const std::unique_ptr<AppEventArgs>& args) override;
+ bool StepUninstall(const std::unique_ptr<AppEventArgs>& args) override;
+ bool StepUpgrade(const std::unique_ptr<AppEventArgs>& args) override;
+ bool StepRestore() override;
+
+ private:
+ std::vector<std::string> Split(const std::string& str,
+ const std::string& delim);
+
+ private:
+ std::vector<std::shared_ptr<AllowedInfo>> infos_;
+};
+
+} // namespace plugin
+
+#endif // ALLOWED_APPID_PLUGIN_MANAGER_HH_
--- /dev/null
+/*
+ * Copyright (c) 2020 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 COMMON_APP_EVENT_ARGS_HH_
+#define COMMON_APP_EVENT_ARGS_HH_
+
+#include <list>
+#include <memory>
+#include <string>
+
+#include "common/event_type.hh"
+#include "common/metadata.hh"
+
+namespace plugin {
+
+class AppEventArgs {
+ public:
+ AppEventArgs(std::string appid, std::string pkgid, EventType event_type)
+ : appid_(std::move(appid)),
+ pkgid_(std::move(pkgid)),
+ event_type_(event_type) {
+ }
+
+ virtual ~AppEventArgs() = default;
+
+ const std::string& GetAppId() {
+ return appid_;
+ }
+
+ const std::string& GetPkgId() {
+ return pkgid_;
+ }
+
+ EventType GetEventType() const {
+ return event_type_;
+ }
+
+ const std::list<std::unique_ptr<Metadata>>& GetMetadataList() {
+ return list_;
+ }
+
+ void AddMetadata(std::unique_ptr<Metadata> metadata) {
+ list_.push_back(std::move(metadata));
+ }
+
+ private:
+ std::string appid_;
+ std::string pkgid_;
+ EventType event_type_;
+ std::list<std::unique_ptr<Metadata>> list_;
+};
+
+} // namespace plugin
+
+#endif // COMMON_APP_EVENT_ARGS_HH_
--- /dev/null
+/*
+ * Copyright (c) 2020 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 <unistd.h>
+
+#include <memory>
+
+#include "common/database.hh"
+#include "common/exception.hh"
+#include "common/log_private.hh"
+
+namespace plugin {
+
+static const int BUSY_WAITING_USEC = 50000;
+static const int BUSY_WAITING_MAX = 40;
+
+Database::Database(std::string path) : path_(std::move(path)) {
+}
+
+Database::~Database() {
+ Close();
+}
+
+void Database::BeginTransaction() {
+ int ret = sqlite3_exec(db_, "BEGIN TRANSACTION", nullptr, nullptr, nullptr);
+ if (ret != SQLITE_OK) {
+ _E("sqlite3_exec() is failed. error(%s:%d)", sqlite3_errmsg(db_), ret);
+ THROW(-ret);
+ }
+}
+
+void Database::EndTransaction() {
+ int ret = sqlite3_exec(db_, "END TRANSACTION", nullptr, nullptr, nullptr);
+ if (ret != SQLITE_OK) {
+ _E("sqlite3_exec() is failed. error(%s:%d)", sqlite3_errmsg(db_), ret);
+ THROW(-ret);
+ }
+}
+
+void Database::Rollback() {
+ int ret = sqlite3_exec(db_, "ROLLBACK", nullptr, nullptr, nullptr);
+ if (ret != SQLITE_OK) {
+ _E("sqlite3_exec() is failed. error(%s:%d", sqlite3_errmsg(db_), ret);
+ THROW(-ret);
+ }
+}
+
+void Database::Open() {
+ sqlite3* db;
+ int ret = sqlite3_open_v2(path_.c_str(), &db, SQLITE_OPEN_READWRITE, nullptr);
+ if (ret != SQLITE_OK) {
+ _E("sqlite3_open_v2() is failed. error(%d)", ret);
+ THROW(-ret);
+ }
+
+ ret = sqlite3_busy_handler(db, BusyHandler,
+ static_cast<void*>(const_cast<char*>(path_.c_str())));
+ if (ret != SQLITE_OK) {
+ _E("sqlite3_busy_handler() is failed. error(%s:%d)",
+ sqlite3_errmsg(db), ret);
+ sqlite3_close_v2(db);
+ THROW(-ret);
+ }
+
+ ret = sqlite3_exec(db, "PRAGMA foreign_keys=ON", nullptr, nullptr, nullptr);
+ if (ret != SQLITE_OK) {
+ _E("sqlite3_exec() is failed. error(%s:%d)", sqlite3_errmsg(db), ret);
+ sqlite3_close_v2(db);
+ THROW(-ret);
+ }
+
+ db_ = db;
+}
+
+void Database::Close() {
+ if (db_) {
+ sqlite3_close_v2(db_);
+ db_ = nullptr;
+ }
+}
+
+sqlite3* Database::GetHandle() {
+ return db_;
+}
+
+std::string Database::ColumnText(sqlite3_stmt* stmt, int index) {
+ auto* text = reinterpret_cast<const char*>(sqlite3_column_text(stmt, index));
+ if (text)
+ return std::string(text);
+
+ return {};
+}
+
+bool Database::IntegrityCheck() {
+ static const char query[] = "PRAGMA integrity_check";
+ sqlite3_stmt* stmt;
+ int ret = sqlite3_prepare_v2(db_, query, strlen(query), &stmt, nullptr);
+ if (ret != SQLITE_OK) {
+ _E("sqlite3_prepare_v2() is failed. error(%s:%d)",
+ sqlite3_errmsg(db_), ret);
+ return false;
+ }
+
+ std::unique_ptr<sqlite3_stmt, decltype(sqlite3_finalize)*> stmt_ptr(
+ stmt, sqlite3_finalize);
+
+ ret = sqlite3_step(stmt);
+ if (ret != SQLITE_ROW) {
+ _E("sqlite3_step() is failed. error(%s:%d)", sqlite3_errmsg(db_), ret);
+ return false;
+ }
+
+ auto* res = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0));
+ if (res == nullptr) {
+ _E("sqlite3_column_text() is failed. error(%s)", sqlite3_errmsg(db_));
+ return false;
+ }
+
+ if (strcmp(res, "ok") != 0)
+ return false;
+
+ return true;
+}
+
+int Database::BusyHandler(void* data, int count) {
+ if (count < BUSY_WAITING_MAX) {
+ usleep(BUSY_WAITING_USEC);
+ return 1;
+ }
+ auto* path = static_cast<char*>(data);
+ _E("Database(%s) is busy", path);
+ return 0;
+}
+
+} // namespace plugin
--- /dev/null
+/*
+ * Copyright (c) 2020 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 COMMON_DATABASE_HH_
+#define COMMON_DATABASE_HH_
+
+#include <sqlite3.h>
+
+#include <string>
+
+#include "common/exception.hh"
+
+#define __PREPARE_V2(db, query, length, stmt) do { \
+ int ret = sqlite3_prepare_v2(db, query, length, &stmt, nullptr); \
+ if (ret != SQLITE_OK) { \
+ _E("sqlite3_prepare_v2() is failed. error(%s:%d)", \
+ sqlite3_errmsg(db), ret); \
+ THROW(-ret); \
+ } \
+} while (0)
+
+
+#define __BIND_TEXT(db, stmt, i, text) do { \
+ int ret = sqlite3_bind_text(stmt, i, text, -1, SQLITE_TRANSIENT); \
+ if (ret != SQLITE_OK) { \
+ _E("sqlite3_bind_text() is failed. index(%d), error(%s:%d)", \
+ i, sqlite3_errmsg(db), ret); \
+ THROW(-ret); \
+ } \
+} while (0)
+
+#define __STEP(db, stmt) do { \
+ int ret = sqlite3_step(stmt); \
+ if (ret != SQLITE_DONE) { \
+ _E("sqlite3_step() is failed. error(%s:%d)", sqlite3_errmsg(db), ret); \
+ THROW(-ret); \
+ } \
+} while (0)
+
+namespace plugin {
+
+class Database {
+ public:
+ explicit Database(std::string path);
+ virtual ~Database();
+
+ void Open();
+ void Close();
+ bool IntegrityCheck();
+ void BeginTransaction();
+ void EndTransaction();
+ void Rollback();
+ sqlite3* GetHandle();
+ std::string ColumnText(sqlite3_stmt* stmt, int index);
+
+ private:
+ static int BusyHandler(void* data, int count);
+
+ private:
+ std::string path_;
+ sqlite3* db_ = nullptr;
+};
+
+} // namespace plugin
+
+#endif // COMMON_DATABASE_HH_
--- /dev/null
+/*
+ * Copyright (c) 2020 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 COMMON_EVENT_TYPE_HH_
+#define COMMON_EVENT_TYPE_HH_
+
+namespace plugin {
+
+enum class EventType {
+ Install,
+ Uninstall,
+ Upgrade,
+};
+
+} // namespace plugin
+
+#endif // COMMON_EVENT_TYPE_HH_
--- /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 COMMON_EXCEPTION_HH_
+#define COMMON_EXCEPTION_HH_
+
+#include <libgen.h>
+
+#include <exception>
+#include <string>
+
+#include "common/log_private.hh"
+
+#define THROW(error_code) throw Exception(error_code, __FILE__, __LINE__)
+
+namespace plugin {
+
+class Exception : public std::exception {
+ public:
+ explicit Exception(int error_code, std::string file = __FILE__,
+ int line = __LINE__ ) {
+ error_code_ = error_code;
+ message_ = std::string(basename(const_cast<char*>(file.c_str()))) + ":" +
+ std::to_string(line) + " code:" + std::to_string(error_code_);
+ _E("%s", message_.c_str());
+ }
+
+ virtual ~Exception() {}
+
+ virtual const char* what(void) const noexcept {
+ return message_.c_str();
+ }
+
+ int GetErrorCode() {
+ return error_code_;
+ }
+
+ private:
+ int error_code_;
+ std::string message_;
+};
+
+} // namespace plugin
+
+#endif // COMMON_EXCEPTION_HH_
--- /dev/null
+/*
+ * Copyright (c) 2020 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 COMMON_LOG_PRIVATE_HH_
+#define COMMON_LOG_PRIVATE_HH_
+
+#include <dlog.h>
+
+#undef LOG_TAG
+#define LOG_TAG "METADATA_PLUGIN_PARSER"
+
+#undef _E
+#define _E LOGE
+
+#undef _W
+#define _W LOGW
+
+#undef _I
+#define _I LOGI
+
+#undef _D
+#define _D LOGD
+
+#endif // COMMON_LOG_PRIVATE_HH_
--- /dev/null
+/*
+ * Copyright (c) 2020 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 COMMON_METADATA_HH_
+#define COMMON_METADATA_HH_
+
+#include <string>
+
+namespace plugin {
+
+class Metadata {
+ public:
+ Metadata(std::string key, std::string value)
+ : key_(std::move(key)), value_(std::move(value)) {
+ }
+
+ virtual ~Metadata() = default;
+
+ const std::string& GetKey() {
+ return key_;
+ }
+
+ const std::string& GetValue() {
+ return value_;
+ }
+
+ private:
+ std::string key_;
+ std::string value_;
+};
+
+} // namespace plugin
+
+#endif // COMMON_METADATA_HH_
--- /dev/null
+/*
+ * Copyright (c) 2020 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 <unistd.h>
+#include <pkgmgr_installer_info.h>
+
+#include "common/database.hh"
+#include "common/exception.hh"
+#include "common/log_private.hh"
+#include "common/metadata_plugin.hh"
+#include "common/metadata_type.hh"
+
+namespace plugin {
+
+void MetadataPlugin::AddAppEventArgs(const std::string& pkgid,
+ const std::string& appid, EventType event_type, GList* list) {
+ auto args = new (std::nothrow) AppEventArgs(appid, pkgid, event_type);
+ if (args == nullptr) {
+ _E("Out of memory");
+ return;
+ }
+
+ GList* iter = list;
+ while (iter) {
+ metadata_t* md = static_cast<metadata_t*>(iter->data);
+ args->AddMetadata(std::unique_ptr<Metadata>(
+ new (std::nothrow) Metadata(md->key, md->value)));
+ iter = g_list_next(iter);
+ }
+
+ list_.emplace_back(args);
+}
+
+void MetadataPlugin::Do() {
+ _W("Do");
+ if (!Prepare())
+ return;
+
+ for (auto& args : list_) {
+ bool ret = StepBackup(args);
+ if (!ret) {
+ Post();
+ return;
+ }
+ }
+
+ for (auto& args : list_) {
+ bool ret = true;
+ if (args->GetEventType() == EventType::Install) {
+ ret = StepInstall(args);
+ } else if (args->GetEventType() == EventType::Uninstall) {
+ ret = StepUninstall(args);
+ } else if (args->GetEventType() == EventType::Upgrade) {
+ ret = StepUpgrade(args);
+ }
+
+ if (!ret) {
+ Rollback();
+ return;
+ }
+ }
+ Post();
+}
+
+void MetadataPlugin::Clean() {
+ _W("Clean");
+}
+
+Database* MetadataPlugin::GetDB() {
+ return db_.get();
+}
+
+uid_t MetadataPlugin::GetUid() {
+ uid_t target_uid;
+ pkgmgr_installer_info_get_target_uid(&target_uid);
+ return target_uid;
+}
+
+bool MetadataPlugin::Prepare() {
+ try {
+ db_->Open();
+ if (!db_->IntegrityCheck())
+ return false;
+ db_->BeginTransaction();
+ } catch (Exception& e) {
+ return false;
+ }
+ return true;
+}
+
+bool MetadataPlugin::StepBackup(const std::unique_ptr<AppEventArgs>& args) {
+ return true;
+}
+
+bool MetadataPlugin::StepInstall(const std::unique_ptr<AppEventArgs>& args) {
+ return true;
+}
+
+bool MetadataPlugin::StepUninstall(const std::unique_ptr<AppEventArgs>& args) {
+ return true;
+}
+
+bool MetadataPlugin::StepUpgrade(const std::unique_ptr<AppEventArgs>& args) {
+ return true;
+}
+
+bool MetadataPlugin::StepRestore() {
+ return true;
+}
+
+void MetadataPlugin::Post() {
+ try {
+ db_->EndTransaction();
+ db_->Close();
+ } catch (Exception& e) {
+ _E("Exception(%d) occurs", e.GetErrorCode());
+ }
+}
+
+void MetadataPlugin::Rollback() {
+ try {
+ db_->Rollback();
+ } catch (Exception& e) {
+ _E("Exception(%d) occurs", e.GetErrorCode());
+ }
+}
+
+void MetadataPlugin::Undo() {
+ _E("Undo");
+ if (!Prepare())
+ return;
+
+ for (auto& args : list_) {
+ if (!StepUninstall(args))
+ _E("StepUninstall() is failed");
+ }
+
+ if (!StepRestore())
+ _E("StepRestore() is failed");
+
+ Post();
+}
+
+} // namespace plugin
--- /dev/null
+/*
+ * Copyright (c) 2020 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 COMMON_METADATA_PLUGIN_HH_
+#define COMMON_METADATA_PLUGIN_HH_
+
+#include <glib.h>
+#include <unistd.h>
+
+#include <list>
+#include <memory>
+#include <string>
+
+#include "common/app_event_args.hh"
+#include "common/database.hh"
+
+namespace plugin {
+
+class MetadataPlugin {
+ public:
+ explicit MetadataPlugin(std::unique_ptr<Database> db) : db_(std::move(db)) { }
+ virtual ~MetadataPlugin() = default;
+
+ void AddAppEventArgs(const std::string& pkgid, const std::string& appid,
+ EventType event_type, GList* list);
+ Database* GetDB();
+
+ void Do();
+ void Clean();
+ void Undo();
+
+ virtual bool Prepare();
+ virtual bool StepBackup(const std::unique_ptr<AppEventArgs>& args);
+ virtual bool StepInstall(const std::unique_ptr<AppEventArgs>& args);
+ virtual bool StepUninstall(const std::unique_ptr<AppEventArgs>& args);
+ virtual bool StepUpgrade(const std::unique_ptr<AppEventArgs>& args);
+ virtual bool StepRestore();
+ virtual void Post();
+ virtual void Rollback();
+
+ static uid_t GetUid();
+
+ public:
+ std::unique_ptr<Database> db_;
+ std::list<std::unique_ptr<AppEventArgs>> list_;
+};
+
+} // namespace plugin
+
+#endif // COMMON_METADATA_PLUGIN_HH_
--- /dev/null
+/*
+ * Copyright (c) 2020 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 COMMON_METADATA_TYPE_HH_
+#define COMMON_METADATA_TYPE_HH_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct metadata_s {
+ const char* key;
+ const char* value;
+} metadata_t;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // COMMON_METADATA_TYPE_HH_
+++ /dev/null
-/*
- * Copyright (c) 2012 - 2022 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 "pkginfo_internal.h"
-
-#include <bundle_cpp.h>
-#include <bundle_internal.h>
-#include <glib-unix.h>
-#include <glib.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include <atomic>
-#include <exception>
-#include <memory>
-#include <string>
-#include <thread>
-
-#include "app_request.h"
-#include "aul_api.h"
-#include "aul_error.h"
-#include "aul_util.h"
-#include "menu_db_util.h"
-#include "include/aul.h"
-#include "include/aul_error.h"
-#include "include/aul_sock.h"
-
-using namespace aul::internal;
-
-namespace {
-
-constexpr const char* kAppInfoKeys[] = {
- AUL_K_PID,
- AUL_K_APPID,
- AUL_K_EXEC,
- AUL_K_PKGID,
- AUL_K_STATUS,
- AUL_K_IS_SUBAPP,
-};
-
-constexpr const char kPathAmdReady[] = "/run/.amd_ready";
-
-class ResultInfo {
- public:
- ResultInfo(pid_t pid, int fd, aul_appid_cb callback, void* user_data)
- : pid_(pid), fd_(fd), callback_(callback), user_data_(user_data) {}
-
- ResultInfo(const ResultInfo&) = delete;
- ResultInfo& operator = (const ResultInfo&) = delete;
-
- ~ResultInfo() {
- if (source_ != 0)
- g_source_remove(source_);
-
- if (fd_ > -1)
- close(fd_);
- }
-
- bool Watch() {
- source_ = g_unix_fd_add(fd_,
- static_cast<GIOCondition>(G_IO_IN | G_IO_HUP | G_IO_ERR),
- FdSourceFunc, this);
- if (source_ == 0) {
- _E("g_unix_fd_add() is failed");
- return false;
- }
-
- return true;
- }
-
- private:
- void ProcessReadEvent() {
- app_pkt_t* pkt = nullptr;
- int ret = aul_sock_recv_reply_pkt(fd_, &pkt);
- fd_ = -1;
- if (ret < 0 || pkt == nullptr) {
- ProcessErrorEvent();
- return;
- }
-
- auto pkt_auto = std::unique_ptr<app_pkt_t, decltype(std::free)*>(
- pkt, std::free);
- if (pkt->cmd != APP_GET_INFO_OK) {
- ProcessErrorEvent();
- return;
- }
-
- char appid[256] = { 0, };
- snprintf(appid, sizeof(appid), "%s", pkt->data);
- SECURE_LOGD("pid: %d, appid: %s", pid_, appid);
- callback_(AUL_R_OK, pid_, appid, user_data_);
- }
-
- void ProcessErrorEvent() {
- callback_(AUL_R_ERROR, pid_, "", user_data_);
- }
-
- static gboolean FdSourceFunc(int fd, GIOCondition condition,
- gpointer user_data) {
- auto* info = static_cast<ResultInfo*>(user_data);
- _E("GIOCondition: %d", static_cast<int>(condition));
- if (condition & G_IO_IN)
- info->ProcessReadEvent();
- else
- info->ProcessErrorEvent();
-
- info->source_ = 0;
- delete info;
- return G_SOURCE_REMOVE;
- }
-
- private:
- pid_t pid_;
- int fd_;
- aul_appid_cb callback_;
- void* user_data_;
- guint source_ = 0;
-};
-
-bool IsAmdReady() {
- static std::atomic<bool> amd_ready = false;
- if (amd_ready)
- return amd_ready;
-
- if (access(kPathAmdReady, F_OK) == 0) {
- amd_ready.exchange(true);
- return amd_ready;
- }
-
- return false;
-}
-
-class Context {
- public:
- Context() = default;
-
- void Initialize() {
- if (initialized_)
- return;
-
- auto* appid = getenv("AUL_APPID");
- if (appid != nullptr)
- appid_ = std::string(appid);
-
- auto* pkgid = getenv("AUL_PKGID");
- if (pkgid != nullptr)
- pkgid_ = std::string(pkgid);
-
- auto* root_path = getenv("AUL_ROOT_PATH");
- if (root_path != nullptr)
- root_path_ = std::string(root_path);
-
- initialized_ = true;
- }
-
- const std::string& GetPreInitAppId() const {
- return appid_;
- }
-
- const std::string& GetPreInitPkgId() const {
- return pkgid_;
- }
-
- const std::string& GetPreInitRootPath() const {
- return root_path_;
- }
-
- void SetPreInitAppId(std::string appid) {
- appid_ = std::move(appid);
- }
-
- void SetPreInitPkgId(std::string pkgid) {
- pkgid_ = std::move(pkgid);
- }
-
- void SetPreInitRootPath(std::string root_path) {
- root_path_ = std::move(root_path);
- }
-
- private:
- bool initialized_ = false;
- std::string appid_;
- std::string pkgid_;
- std::string root_path_;
-};
-
-int SendAndReceive(int cmd, uid_t uid,
- std::vector<tizen_base::Bundle>* results) {
- int fd = AppRequest(cmd, uid).SendSimply(AUL_SOCK_ASYNC);
- if (fd < 0)
- return fd;
-
- int ret = aul_sock_recv_pkt_with_cb(fd,
- [](app_pkt_t* pkt, void* user_data) {
- if (pkt == nullptr) {
- _E("Invalid parameter");
- return;
- }
-
- bundle* b = nullptr;
- if (pkt->opt & AUL_SOCK_BUNDLE)
- b = bundle_decode(pkt->data, pkt->len);
-
- if (b == nullptr)
- return;
-
- auto* res = static_cast<std::vector<tizen_base::Bundle>*>(user_data);
- res->push_back(tizen_base::Bundle(b, false, true));
- }, results);
- if (ret < 0)
- return aul_error_convert(ret);
-
- return AUL_R_OK;
-}
-
-int SetAppInfo(aul_app_info* info, const tizen_base::Bundle& b) {
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
- for (unsigned int i = 0; i < ARRAY_SIZE(kAppInfoKeys); ++i) {
- if (b.GetType(kAppInfoKeys[i]) == BUNDLE_TYPE_NONE)
- return -1;
- }
-
- info->pid = std::stoi(b.GetString(AUL_K_PID));
- info->appid = const_cast<char*>(bundle_get_val(b.GetHandle(), AUL_K_APPID));
- info->app_path = const_cast<char*>(bundle_get_val(b.GetHandle(), AUL_K_EXEC));
- info->pkgid = const_cast<char*>(bundle_get_val(b.GetHandle(), AUL_K_PKGID));
- info->instance_id = const_cast<char*>(
- bundle_get_val(b.GetHandle(), AUL_K_INSTANCE_ID));
- info->status = std::stoi(b.GetString(AUL_K_STATUS));
- info->is_sub_app = std::stoi(b.GetString(AUL_K_IS_SUBAPP));
- info->pkg_name = info->appid;
- return 0;
-}
-
-thread_local bool calling_appinfo_cb = false;
-thread_local aul_app_info* current_info = nullptr;
-int GetRunningAppInfoWithCb(int cmd, uid_t uid, aul_app_info_iter_fn cb,
- void* user_data) {
- if (cb == nullptr)
- return AUL_R_EINVAL;
-
- std::vector<tizen_base::Bundle> results;
- int ret = SendAndReceive(cmd, uid, &results);
- if (ret != AUL_R_OK)
- return ret;
-
- calling_appinfo_cb = true;
- aul_app_info info;
- for (auto const& b : results) {
- if (SetAppInfo(&info, b) != 0)
- break;
-
- current_info = &info;
- cb(&info, user_data);
- current_info = nullptr;
- }
- calling_appinfo_cb = false;
-
- return AUL_R_OK;
-}
-
-Context context;
-
-int GetPkgIdFromDB(int pid, char* buf, int len, uid_t uid) {
- const auto& appid = context.GetPreInitAppId();
- if (appid.empty()) {
- _E("Failed to get pre-initialized appid");
- return -1;
- }
-
- auto* menu_info = _get_app_info_from_db_by_appid_user(appid.c_str(), uid);
- if (menu_info == nullptr) {
- _E("Failed to get app info. appid(%s)", appid.c_str());
- return -1;
- }
-
- snprintf(buf, len, "%s", _get_pkgid(menu_info));
- _free_app_info_from_db(menu_info);
- return 0;
-}
-
-} // namespace
-
-extern "C" bool aul_is_calling_appinfo_cb() {
- return calling_appinfo_cb;
-}
-
-extern "C" int aul_app_get_status_from_current_appinfo(const char* appid,
- int* status) {
- if (appid == nullptr || status == nullptr)
- return AUL_R_EINVAL;
-
- if (current_info == nullptr)
- return AUL_R_ERROR;
-
- if (strcmp(appid, current_info->appid) != 0)
- return AUL_R_ERROR;
-
- *status = current_info->status;
- return AUL_R_OK;
-}
-
-extern "C" int aul_app_get_status_bypid_from_current_appinfo(int pid,
- int* status) {
- if (pid < 1 || status == nullptr)
- return AUL_R_EINVAL;
-
- if (current_info == nullptr)
- return AUL_R_ERROR;
-
- if (current_info->pid != pid)
- return AUL_R_ERROR;
-
- *status = current_info->status;
- return AUL_R_OK;
-}
-
-extern "C" API int aul_app_get_pid(const char* appid) {
- return aul_app_get_pid_for_uid(appid, getuid());
-}
-
-extern "C" API int aul_app_get_pid_for_uid(const char* appid, uid_t uid) {
- if (appid == nullptr)
- return -1;
-
- return AppRequest(APP_GET_PID, uid)
- .SetAppId(appid)
- .SendSimply();
-}
-
-extern "C" API int aul_app_is_running(const char* appid) {
- return aul_app_is_running_for_uid(appid, getuid());
-}
-
-extern "C" API int aul_app_is_running_for_uid(const char* appid, uid_t uid) {
- if (appid == nullptr)
- return 0;
-
- int ret = AppRequest(APP_IS_RUNNING, uid)
- .SetAppId(appid)
- .SendSimply();
- return ret > 0;
-}
-
-extern "C" API int aul_app_get_running_app_info(aul_app_info_iter_fn iter_fn,
- void* user_data) {
- return aul_app_get_running_app_info_for_uid(iter_fn, user_data, getuid());
-}
-
-extern "C" API int aul_app_get_running_app_info_for_uid(
- aul_app_info_iter_fn iter_fn, void* user_data, uid_t uid) {
- return GetRunningAppInfoWithCb(APP_RUNNING_INFO, uid, iter_fn, user_data);
-}
-
-extern "C" API int aul_app_get_all_running_app_info(
- aul_app_info_iter_fn iter_fn, void* user_data) {
- return aul_app_get_all_running_app_info_for_uid(iter_fn, user_data, getuid());
-}
-
-extern "C" API int aul_app_get_all_running_app_info_for_uid(
- aul_app_info_iter_fn iter_fn, void* user_data, uid_t uid) {
- return GetRunningAppInfoWithCb(APP_ALL_RUNNING_INFO, uid, iter_fn, user_data);
-}
-
-extern "C" API int aul_app_get_running_app_instance_info(
- aul_app_info_iter_fn iter_fn, void* user_data) {
- return aul_app_get_running_app_instance_info_for_uid(iter_fn, user_data,
- getuid());
-}
-
-extern "C" API int aul_app_get_running_app_instance_info_for_uid(
- aul_app_info_iter_fn iter_fn, void *user_data, uid_t uid) {
- return GetRunningAppInfoWithCb(APP_RUNNING_INSTANCE_INFO, uid, iter_fn,
- user_data);
-}
-
-extern "C" API void aul_set_preinit_appid(const char* appid) {
- context.Initialize();
- context.SetPreInitAppId(appid ? appid : "");
-}
-
-extern "C" API void aul_set_preinit_pkgid(const char* pkgid) {
- context.Initialize();
- context.SetPreInitPkgId(pkgid ? pkgid : "");
-}
-
-extern "C" API void aul_set_preinit_root_path(const char* root_path) {
- context.Initialize();
- context.SetPreInitRootPath(root_path ? root_path : "");
-}
-
-extern "C" API const char* aul_get_preinit_root_path(void) {
- context.Initialize();
- return context.GetPreInitRootPath().c_str();
-}
-
-extern "C" API int aul_app_get_pkgname_bypid(int pid, char* pkgname, int len) {
- return aul_app_get_appid_bypid(pid, pkgname, len);
-}
-
-extern "C" API int aul_app_get_appid_bypid(int pid, char* appid, int len) {
- return aul_app_get_appid_bypid_for_uid(pid, appid, len, getuid());
-}
-
-extern "C" API int aul_app_get_appid_bypid_for_uid(int pid, char* appid,
- int len, uid_t uid) {
- if (pid < 1 || appid == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- if (getpid() == pid || getpgid(getpid()) == pid) {
- context.Initialize();
- const auto& preinit_appid = context.GetPreInitAppId();
- if (!preinit_appid.empty()) {
- snprintf(appid, len, "%s", preinit_appid.c_str());
- return AUL_R_OK;
- }
- }
-
- int fd = AppRequest(APP_GET_APPID_BYPID, uid)
- .SetPid(pid)
- .SendSimply(AUL_SOCK_ASYNC);
- if (fd < 0)
- return AUL_R_ERROR;
-
- app_pkt_t* pkt = nullptr;
- int ret = aul_sock_recv_reply_pkt(fd, &pkt);
- if (ret < 0 || pkt == nullptr)
- return AUL_R_ERROR;
-
- auto pkt_auto = std::unique_ptr<app_pkt_t, decltype(std::free)*>(
- pkt, std::free);
- if (pkt->cmd != APP_GET_INFO_OK)
- return AUL_R_ERROR;
-
- snprintf(appid, len, "%s", pkt->data);
- return AUL_R_OK;
-}
-
-extern "C" API int aul_app_get_pkgid_bypid(int pid, char* pkgid, int len) {
- return aul_app_get_pkgid_bypid_for_uid(pid, pkgid, len, getuid());
-}
-
-extern "C" API int aul_app_get_pkgid_bypid_for_uid(int pid, char* pkgid,
- int len, uid_t uid) {
- if (pid < 1 || pkgid == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- if (getpid() == pid || getpgid(getpid()) == pid) {
- context.Initialize();
- const auto& preinit_pkgid = context.GetPreInitPkgId();
- if (!preinit_pkgid.empty()) {
- snprintf(pkgid, len, "%s", preinit_pkgid.c_str());
- return AUL_R_OK;
- }
-
- if (GetPkgIdFromDB(pid, pkgid, len, uid) == 0)
- return AUL_R_OK;
- }
-
- int fd = AppRequest(APP_GET_PKGID_BYPID, uid)
- .SetPid(pid)
- .SendSimply(AUL_SOCK_ASYNC);
- if (fd < 0)
- return AUL_R_ERROR;
-
- app_pkt_t* pkt = nullptr;
- int ret = aul_sock_recv_reply_pkt(fd, &pkt);
- if (ret < 0 || pkt == nullptr)
- return AUL_R_ERROR;
-
- auto pkt_auto = std::unique_ptr<app_pkt_t, decltype(std::free)*>(
- pkt, std::free);
- if (pkt->cmd != APP_GET_INFO_OK)
- return AUL_R_ERROR;
-
- snprintf(pkgid, len, "%s", pkt->data);
- return AUL_R_OK;
-}
-
-extern "C" API int aul_update_rua_stat_for_uid(bundle* b, uid_t uid) {
- if (b == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- return AppRequest(APP_UPDATE_RUA_STAT, uid)
- .With(b)
- .SendSimply();
-}
-
-extern "C" API int aul_add_rua_history_for_uid(bundle* b, uid_t uid) {
- if (b == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- return AppRequest(APP_ADD_HISTORY, uid)
- .With(b)
- .SendSimply();
-}
-
-extern "C" API int aul_delete_rua_history_for_uid(bundle* b, uid_t uid) {
- tizen_base::Bundle kb;
- if (b != nullptr)
- kb = std::move(tizen_base::Bundle(b, false, false));
-
- return AppRequest(APP_REMOVE_HISTORY, uid)
- .With(std::move(kb))
- .SendSimply();
-}
-
-extern "C" API int aul_set_default_app_by_operation(bundle* b) {
- if (b == nullptr)
- return AUL_R_EINVAL;
-
- return AppRequest(APP_SET_APP_CONTROL_DEFAULT_APP, getuid())
- .With(b)
- .SendSimply();
-}
-
-extern "C" API int aul_unset_default_app_by_operation(const char* appid) {
- if (appid == nullptr)
- return AUL_R_EINVAL;
-
- int ret = aul_sock_send_raw(AUL_UTIL_PID, getuid(),
- APP_UNSET_APP_CONTROL_DEFAULT_APP,
- reinterpret_cast<unsigned char*>(const_cast<char*>(appid)),
- strlen(appid), AUL_SOCK_NONE);
- if (ret != 0)
- return aul_error_convert(ret);
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_app_get_last_caller_pid(int pid) {
- return aul_app_get_last_caller_pid_for_uid(pid, getuid());
-}
-
-extern "C" API int aul_app_get_last_caller_pid_for_uid(int pid, uid_t uid) {
- if (pid < 1) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- return AppRequest(APP_GET_LAST_CALLER_PID, uid)
- .SetPid(pid)
- .SendSimply();
-}
-
-extern "C" API int aul_set_alias_appid(const char* alias_appid,
- const char* appid) {
- if (alias_appid == nullptr || appid == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- tizen_base::Bundle b { { AUL_K_ALIAS_APPID, alias_appid } };
-
- return AppRequest(APP_SET_ALIAS_APPID, getuid())
- .With(std::move(b))
- .SetAppId(appid)
- .SendSimply();
-}
-
-extern "C" API int aul_unset_alias_appid(const char* alias_appid) {
- if (alias_appid == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- tizen_base::Bundle b { { AUL_K_ALIAS_APPID, alias_appid } };
- return AppRequest(APP_UNSET_ALIAS_APPID, getuid())
- .With(std::move(b))
- .SendSimply();
-}
-
-extern "C" API int aul_enable_alias_info(const char* appid) {
- if (appid == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- return AppRequest(APP_ENABLE_ALIAS_INFO, getuid())
- .SetAppId(appid)
- .SendSimply();
-}
-
-extern "C" API int aul_disable_alias_info(const char* appid) {
- if (appid == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- return AppRequest(APP_DISABLE_ALIAS_INFO, getuid())
- .SetAppId(appid)
- .SendSimply();
-}
-
-extern "C" API int aul_set_auto_restart(bundle* b) {
- tizen_base::Bundle kb { { AUL_K_AUTO_RESTART, "true" } };
- if (b != nullptr) {
- bundle_raw* raw;
- int len;
- if (bundle_encode(b, &raw, &len) != BUNDLE_ERROR_NONE)
- return AUL_R_EINVAL;
-
- kb.Add(AUL_K_RESTART_EXTRA, reinterpret_cast<char*>(raw));
- bundle_free_encoded_rawdata(&raw);
- }
-
- return AppRequest(APP_SET_AUTO_RESTART, getuid())
- .With(std::move(kb))
- .SendSimply();
-}
-
-extern "C" API int aul_unset_auto_restart(void) {
- tizen_base::Bundle kb { { AUL_K_AUTO_RESTART, "false" } };
- return AppRequest(APP_SET_AUTO_RESTART, getuid())
- .With(std::move(kb))
- .SendSimply();
-}
-
-extern "C" API int aul_app_get_instance_id_bypid(int pid, char* instance_id,
- int len) {
- return aul_app_get_instance_id_bypid_for_uid(pid, instance_id, len, getuid());
-}
-
-extern "C" API int aul_app_get_instance_id_bypid_for_uid(int pid,
- char* instance_id, int len, uid_t uid) {
- if (pid < 1 || instance_id == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- int fd = AppRequest(APP_GET_INSTANCE_ID_BYPID, uid)
- .SetPid(pid)
- .SendSimply(AUL_SOCK_ASYNC);
- if (fd < 0)
- return AUL_R_ERROR;
-
- app_pkt_t* pkt = nullptr;
- int ret = aul_sock_recv_reply_pkt(fd, &pkt);
- if (ret < 0 || pkt == nullptr)
- return AUL_R_ERROR;
-
- auto pkt_auto = std::unique_ptr<app_pkt_t, decltype(std::free)*>(
- pkt, std::free);
- if (pkt->cmd != APP_GET_INFO_OK)
- return AUL_R_ERROR;
-
- snprintf(instance_id, len, "%s", pkt->data);
- return AUL_R_OK;
-}
-
-extern "C" API int aul_app_is_running_with_instance_id(const char* appid,
- const char* instance_id, bool* running) {
- if (appid == nullptr || instance_id == nullptr || running == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- int ret = AppRequest(APP_IS_RUNNING, getuid())
- .SetAppId(appid)
- .SetInstId(instance_id)
- .SendSimply();
- if (ret < 0)
- return ret;
-
- *running = ret ? true : false;
- return AUL_R_OK;
-}
-
-extern "C" API int aul_get_default_app(bundle* b, char** appid) {
- if (b == nullptr || appid == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- int fd = AppRequest(APP_GET_APP_CONTROL_DEFAULT_APP, getuid())
- .With(b)
- .SendSimply(AUL_SOCK_ASYNC);
- if (fd < 0)
- return fd;
-
- app_pkt_t* pkt = nullptr;
- int ret = aul_sock_recv_reply_pkt(fd, &pkt);
- if (ret < 0 || pkt == nullptr) {
- _E("aul_sock_recv_reply_pkt() is failed. error(%d)", ret);
- return aul_error_convert(ret);
- }
-
- auto pkt_auto = std::unique_ptr<app_pkt_t, decltype(std::free)*>(
- pkt, std::free);
- if (pkt->cmd != APP_GET_INFO_OK) {
- _E("Failed to get default app. error(%d)", pkt->cmd);
- return aul_error_convert(pkt->cmd);
- }
-
- if (!(pkt->opt & AUL_SOCK_BUNDLE)) {
- _E("Invalid protocol");
- return AUL_R_ERROR;
- }
-
- bundle* res_b = bundle_decode(pkt->data, pkt->len);
- if (res_b == nullptr) {
- _E("bundle_decode() is failed");
- return AUL_R_ERROR;
- }
-
- tizen_base::Bundle kb(res_b, false, true);
- auto value = kb.GetString(AUL_K_APPID);
- if (value.empty()) {
- _E("Failed to get appid");
- return AUL_R_ERROR;
- }
-
- *appid = strdup(value.c_str());
- if (*appid == nullptr) {
- _E("strdup() is failed. appid(%s)", value.c_str());
- return AUL_R_ENOMEM;
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_package_pre_event_send(uid_t uid, bundle* b) {
- if (b == nullptr) {
- _E("Invalid paremeter");
- return AUL_R_EINVAL;
- }
-
- if (!IsAmdReady())
- return AUL_R_OK;
-
- return AppRequest(PKG_PRE_EVENT_SEND, uid)
- .With(b)
- .SendSimply();
-}
-
-extern "C" API int aul_app_get_appid_bypid_async(pid_t pid,
- aul_appid_cb callback, void* user_data) {
- if (pid < 1 || callback == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- if (getpid() == pid || getpgid(getpid()) == pid) {
- context.Initialize();
- const auto& preinit_appid = context.GetPreInitAppId();
- if (!preinit_appid.empty()) {
- callback(AUL_R_OK, pid, preinit_appid.c_str(), user_data);
- return AUL_R_OK;
- }
- }
-
- int fd = AppRequest(APP_GET_APPID_BYPID, getuid())
- .SetPid(pid)
- .SendSimply(AUL_SOCK_ASYNC);
- if (fd < 0)
- return AUL_R_ERROR;
-
- try {
- auto* result_info = new ResultInfo(pid, fd, callback, user_data);
- result_info->Watch();
- } catch (const std::exception& e) {
- _E("Exception occurs. error: %s", e.what());
- close(fd);
- return AUL_R_ERROR;
- }
-
- return AUL_R_OK;
-}
+++ /dev/null
-/*
- * Copyright (c) 2023 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 <stdbool.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-bool aul_is_calling_appinfo_cb();
-
-int aul_app_get_status_from_current_appinfo(const char *appid, int *status);
-
-int aul_app_get_status_bypid_from_current_appinfo(int pid, int *status);
-
-#ifdef __cplusplus
-}
-#endif
--- /dev/null
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} AUL_SERVER_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/api AUL_SERVER_API_SRCS)
+
+ADD_LIBRARY(${TARGET_AUL_SERVER} SHARED
+ ${AUL_SERVER_SRCS}
+ ${AUL_SERVER_API_SRCS}
+)
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_AUL_SERVER} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/../
+ ${CMAKE_CURRENT_SOURCE_DIR}/api
+)
+
+SET_TARGET_PROPERTIES(${TARGET_AUL_SERVER} PROPERTIES SOVERSION ${MAJORVER})
+SET_TARGET_PROPERTIES(${TARGET_AUL_SERVER} PROPERTIES VERSION ${FULLVER})
+
+APPLY_PKG_CONFIG(${TARGET_AUL_SERVER} PUBLIC
+ SQLITE3_DEPS
+ DLOG_DEPS
+)
+
+CONFIGURE_FILE(${TARGET_AUL_SERVER}.pc.in ${TARGET_AUL_SERVER}.pc @ONLY)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_AUL_SERVER}.pc
+ DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
+
+INSTALL(TARGETS ${TARGET_AUL_SERVER} DESTINATION ${LIB_INSTALL_DIR}
+ COMPONENT RuntimeLibraries)
+
+INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/api/
+ DESTINATION include/aul/server
+ FILES_MATCHING
+ PATTERN "*.h"
+)
--- /dev/null
+/*
+ * Copyright (c) 2022 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 "server/api/aul_boot_sequence.h"
+
+#include <memory>
+#include <string>
+#include <tuple>
+#include <utility>
+#include <vector>
+
+#include "server/boot_sequence.hh"
+#include "server/common_private.hh"
+#include "server/database.hh"
+#include "server/log_private.hh"
+
+using namespace aul;
+
+namespace {
+
+constexpr const char APPSVC_DB[] = ".appsvc.db";
+constexpr const char QUERY_SELECT_FROM_BOOT_SEQUENCE[] =
+ "SELECT appid, after, before, requires, conflicts, vconf, path_exists, "
+ "args, background_launch, wait_until_ready, timeout FROM boot_sequence";
+
+using SelectBootSequenceCb =
+ int (*)(sqlite3*, sqlite3_stmt*,
+ std::tuple<std::vector<std::shared_ptr<BootSequence>>&>);
+
+template <typename T, typename ...ARGS>
+int Step(T cb, std::tuple<ARGS...> args,
+ bool readonly, const std::string& query, uid_t uid) {
+ std::string path = Database::GetPath(APPSVC_DB, uid);
+ Database db(path, false);
+ try {
+ db.Open(readonly ? SQLITE_OPEN_READONLY : SQLITE_OPEN_READWRITE);
+ } catch (Exception& e) {
+ return AUL_ERROR_IO_ERROR;
+ }
+
+ sqlite3_stmt* stmt;
+ __PREPARE_V2(db.GetHandle(), query.c_str(), query.length(), stmt);
+ auto stmt_ptr = std::unique_ptr<sqlite3_stmt, decltype(sqlite3_finalize)*>(
+ stmt, sqlite3_finalize);
+
+ int ret;
+ if (readonly) {
+ ret = cb(db.GetHandle(), stmt, args);
+ } else {
+ db.BeginTransaction();
+ ret = cb(db.GetHandle(), stmt, args);
+ if (ret < 0)
+ db.Rollback();
+ else
+ db.EndTransaction();
+ }
+
+ return ret;
+}
+
+int GetBootSequence(uid_t uid,
+ std::vector<std::shared_ptr<BootSequence>>& infos) {
+ std::string query(QUERY_SELECT_FROM_BOOT_SEQUENCE);
+ std::tuple<std::vector<std::shared_ptr<BootSequence>>&> param(infos);
+ int ret = Step<SelectBootSequenceCb,
+ std::vector<std::shared_ptr<BootSequence>>&>(
+ [](sqlite3* db, sqlite3_stmt* stmt,
+ std::tuple<std::vector<std::shared_ptr<BootSequence>>&> args)
+ -> int {
+ auto& infos = std::get<0>(args);
+ int idx;
+ while (sqlite3_step(stmt) == SQLITE_ROW) {
+ idx = 0;
+ std::string appid = Database::ColumnText(stmt, idx++);
+ auto info = std::make_shared<BootSequence>(std::move(appid));
+ info->SetAfter(Database::ColumnText(stmt, idx++));
+ info->SetBefore(Database::ColumnText(stmt, idx++));
+ info->SetRequires(Database::ColumnText(stmt, idx++));
+ info->SetConflicts(Database::ColumnText(stmt, idx++));
+ info->SetVconf(Database::ColumnText(stmt, idx++));
+ info->SetPathExists(Database::ColumnText(stmt, idx++));
+ info->SetArgs(Database::ColumnText(stmt, idx++));
+ info->SetBackgroundLaunch(Database::ColumnText(stmt, idx++));
+ info->SetWaitUntilReady(Database::ColumnText(stmt, idx++));
+ info->SetTimeout(Database::ColumnText(stmt, idx++));
+ infos.push_back(std::move(info));
+ }
+
+ return AUL_ERROR_NONE;
+ }, param, false, query, uid);
+ if (ret != AUL_ERROR_NONE)
+ return AUL_ERROR_IO_ERROR;
+
+ return AUL_ERROR_NONE;
+}
+
+} // namespace
+
+extern "C" API int aul_boot_sequence_foreach_usr(uid_t uid,
+ aul_boot_sequence_cb callback, void* user_data) {
+ if (callback == nullptr) {
+ _E("Invalid parameter");
+ return AUL_ERROR_INVALID_PARAMETER;
+ }
+
+ if (uid < REGULAR_UID_MIN)
+ uid = GLOBALAPP_UID;
+
+ std::vector<std::shared_ptr<BootSequence>> infos;
+ int ret = GetBootSequence(uid, infos);
+ if (ret == AUL_ERROR_NONE && uid != GLOBALAPP_UID)
+ ret = GetBootSequence(GLOBALAPP_UID, infos);
+
+ if (ret != AUL_ERROR_NONE) {
+ _E("Failed to get boot sequence. error(%d)", ret);
+ return ret;
+ }
+
+ for (auto& info : infos) {
+ if (!callback(info.get(), uid, user_data))
+ break;
+ }
+
+ return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_boot_sequence_get_appid(aul_boot_sequence_h handle,
+ const char** appid) {
+ if (handle == nullptr || appid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* h = static_cast<BootSequence*>(handle);
+ *appid = h->GetAppId().c_str();
+ return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_boot_sequence_get_after(aul_boot_sequence_h handle,
+ const char** after) {
+ if (handle == nullptr || after == nullptr) {
+ _E("Invalid parameter");
+ return AUL_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* h = static_cast<BootSequence*>(handle);
+ *after = h->GetAfter().c_str();
+ return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_boot_sequence_get_before(aul_boot_sequence_h handle,
+ const char** before) {
+ if (handle == nullptr || before == nullptr) {
+ _E("Invalid parameter");
+ return AUL_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* h = static_cast<BootSequence*>(handle);
+ *before = h->GetBefore().c_str();
+ return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_boot_sequence_get_requires(aul_boot_sequence_h handle,
+ const char** requires_dep) {
+ if (handle == nullptr || requires_dep == nullptr) {
+ _E("Invalid parameter");
+ return AUL_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* h = static_cast<BootSequence*>(handle);
+ *requires_dep = h->GetRequires().c_str();
+ return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_boot_sequence_get_conflicts(aul_boot_sequence_h handle,
+ const char** conflicts) {
+ if (handle == nullptr || conflicts == nullptr) {
+ _E("Invalid parameter");
+ return AUL_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* h = static_cast<BootSequence*>(handle);
+ *conflicts = h->GetConflicts().c_str();
+ return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_boot_sequence_get_vconf(aul_boot_sequence_h handle,
+ const char** vconf) {
+ if (handle == nullptr || vconf == nullptr) {
+ _E("Invalid parameter");
+ return AUL_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* h = static_cast<BootSequence*>(handle);
+ *vconf = h->GetVconf().c_str();
+ return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_boot_sequence_get_path_exists(aul_boot_sequence_h handle,
+ const char** path_exists) {
+ if (handle == nullptr || path_exists == nullptr) {
+ _E("Invalid parameter");
+ return AUL_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* h = static_cast<BootSequence*>(handle);
+ *path_exists = h->GetPathExists().c_str();
+ return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_boot_sequence_get_args(aul_boot_sequence_h handle,
+ const char** args) {
+ if (handle == nullptr || args == nullptr) {
+ _E("Invalid parameter");
+ return AUL_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* h = static_cast<BootSequence*>(handle);
+ *args = h->GetArgs().c_str();
+ return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_boot_sequence_get_background_launch(
+ aul_boot_sequence_h handle, const char** background_launch) {
+ if (handle == nullptr || background_launch == nullptr) {
+ _E("Invalid parameter");
+ return AUL_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* h = static_cast<BootSequence*>(handle);
+ *background_launch = h->GetBackgroundLaunch().c_str();
+ return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_boot_sequence_get_wait_until_ready(
+ aul_boot_sequence_h handle, const char** wait_until_ready) {
+ if (handle == nullptr || wait_until_ready == nullptr) {
+ _E("Invalid parameter");
+ return AUL_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* h = static_cast<BootSequence*>(handle);
+ *wait_until_ready = h->GetWaitUntilReady().c_str();
+ return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_boot_sequence_get_timeout(aul_boot_sequence_h handle,
+ const char** timeout) {
+ if (handle == nullptr || timeout == nullptr) {
+ _E("Invalid parameter");
+ return AUL_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* h = static_cast<BootSequence*>(handle);
+ *timeout = h->GetTimeout().c_str();
+ return AUL_ERROR_NONE;
+}
--- /dev/null
+/*
+ * Copyright (c) 2022 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_BOOT_SEQUENCE_H__
+#define __AUL_BOOT_SEQUENCE_H__
+
+#include <stdbool.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <aul_types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void *aul_boot_sequence_h;
+
+typedef bool (*aul_boot_sequence_cb)(aul_boot_sequence_h, uid_t, void *);
+
+int aul_boot_sequence_foreach_usr(uid_t uid, aul_boot_sequence_cb callback, void *user_data);
+
+int aul_boot_sequence_get_appid(aul_boot_sequence_h handle, const char **appid);
+
+int aul_boot_sequence_get_after(aul_boot_sequence_h handle, const char **after);
+
+int aul_boot_sequence_get_before(aul_boot_sequence_h handle, const char **before);
+
+int aul_boot_sequence_get_requires(aul_boot_sequence_h handle, const char **requires_dep);
+
+int aul_boot_sequence_get_conflicts(aul_boot_sequence_h handle, const char **conflicts);
+
+int aul_boot_sequence_get_vconf(aul_boot_sequence_h handle, const char **vconf);
+
+int aul_boot_sequence_get_path_exists(aul_boot_sequence_h handle, const char **path_exists);
+
+int aul_boot_sequence_get_args(aul_boot_sequence_h handle, const char **args);
+
+int aul_boot_sequence_get_background_launch(aul_boot_sequence_h handle, const char **background_launch);
+
+int aul_boot_sequence_get_wait_until_ready(aul_boot_sequence_h handle, const char **wait_until_ready);
+
+int aul_boot_sequence_get_timeout(aul_boot_sequence_h handle, const char** timeout);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __AUL_BOOT_SEQUENCE_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2019 - 2021 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 <errno.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <memory>
+#include <string>
+#include <vector>
+#include <tuple>
+
+#include "server/api/aul_comp_info_internal.h"
+#include "server/common_private.hh"
+#include "server/component_info.hh"
+#include "server/database.hh"
+#include "server/exception.hh"
+#include "server/localized_info.hh"
+#include "server/log_private.hh"
+
+using namespace aul;
+
+namespace {
+
+const char COMPONENT_DB[] = ".component.db";
+const char QUERY_COMPONENT_INFO[] = "SELECT app_id, component_id, "
+ "component_type, component_launch_mode, component_main, "
+ "component_icon_display, component_taskmanage FROM component_info";
+const char QUERY_LOCALIZED_INFO[] = "SELECT component_locale, "
+ "component_icon, component_label FROM component_localized_info";
+
+ComponentInfo* CreateComponentInfo(sqlite3_stmt* stmt) {
+ int idx = 0;
+ ComponentInfo::Builder builder;
+ builder.SetAppId(Database::ColumnText(stmt, idx++));
+ builder.SetCompId(Database::ColumnText(stmt, idx++));
+ builder.SetType(Database::ColumnText(stmt, idx++));
+ builder.SetLaunchMode(Database::ColumnText(stmt, idx++));
+ builder.SetMainComp(Database::ColumnText(stmt, idx++));
+ builder.SetIconDisplay(Database::ColumnText(stmt, idx++));
+ builder.SetTaskManage(Database::ColumnText(stmt, idx++));
+ return builder.Build();
+}
+
+LocalizedInfo* CreateLocalizedInfo(sqlite3_stmt* stmt) {
+ int idx = 0;
+ LocalizedInfo::Builder builder;
+ builder.SetLocale(Database::ColumnText(stmt, idx++));
+ builder.SetIcon(Database::ColumnText(stmt, idx++));
+ builder.SetLabel(Database::ColumnText(stmt, idx++));
+ return builder.Build();
+}
+
+template <typename T, typename ...ARGS>
+int Step(T cb, std::tuple<ARGS...> args, const std::string& query, uid_t uid) {
+ std::string path = Database::GetPath(COMPONENT_DB, uid);
+ Database db(path);
+ try {
+ db.Open(SQLITE_OPEN_READONLY);
+ } catch (Exception& e) {
+ return e.GetErrorCode();
+ }
+
+ sqlite3_stmt* stmt;
+ __PREPARE_V2(db.GetHandle(), query.c_str(), query.length(), stmt);
+ auto stmt_ptr = std::unique_ptr<sqlite3_stmt, decltype(sqlite3_finalize)*>(
+ stmt, sqlite3_finalize);
+ return cb(db.GetHandle(), stmt, args);
+}
+
+using GetComponentInfoCb =
+ int (*)(sqlite3*, sqlite3_stmt*, std::tuple<const char*, ComponentInfo**>);
+using GetComponentInfosCb =
+ int (*)(sqlite3*, sqlite3_stmt*,
+ std::tuple<const char*, std::vector<std::unique_ptr<ComponentInfo>>&>);
+using GetLocalizedInfosCb =
+ int (*)(sqlite3*, sqlite3_stmt*,
+ std::tuple<const char*, std::vector<std::unique_ptr<LocalizedInfo>>&>);
+
+int GetComponentInfo(const char* comp_id, uid_t uid,
+ ComponentInfo** info) {
+ std::string query = std::string(QUERY_COMPONENT_INFO) +
+ " WHERE component_id=?";
+ std::tuple<const char*, ComponentInfo**> param(comp_id, info);
+ return Step<GetComponentInfoCb, const char*, ComponentInfo**>(
+ [](sqlite3* db, sqlite3_stmt* stmt,
+ std::tuple<const char*, ComponentInfo**> args) -> int {
+ __BIND_TEXT(db, stmt, 1, std::get<0>(args));
+ int ret = sqlite3_step(stmt);
+ if (ret != SQLITE_ROW) {
+ _E("sqlite3_step() is failed");
+ return AUL_ERROR_NO_SUCH_APP;
+ }
+
+ auto** component_info = std::get<1>(args);
+ *component_info = CreateComponentInfo(stmt);
+ if (*component_info == nullptr)
+ return AUL_ERROR_OUT_OF_MEMORY;
+
+ return AUL_ERROR_NONE;
+ }, param, query, uid);
+}
+
+int GetComponentInfos(const char* app_id, uid_t uid,
+ std::vector<std::unique_ptr<ComponentInfo>>& infos) {
+ std::string query = std::string(QUERY_COMPONENT_INFO);
+ if (app_id != nullptr)
+ query += " WHERE app_id=?";
+
+ std::tuple<const char*, std::vector<std::unique_ptr<ComponentInfo>>&> param(
+ app_id, infos);
+ return Step<GetComponentInfosCb, const char*,
+ std::vector<std::unique_ptr<ComponentInfo>>&>(
+ [](sqlite3* db, sqlite3_stmt* stmt, std::tuple<const char*,
+ std::vector<std::unique_ptr<ComponentInfo>>&> args) -> int {
+ auto* id = std::get<0>(args);
+ if (id != nullptr)
+ __BIND_TEXT(db, stmt, 1, id);
+
+ auto& v = std::get<1>(args);
+ while (sqlite3_step(stmt) == SQLITE_ROW)
+ v.emplace_back(CreateComponentInfo(stmt));
+
+ if (v.empty())
+ return AUL_ERROR_NO_SUCH_APP;
+
+ return AUL_ERROR_NONE;
+ }, param, query, uid);
+}
+
+int GetLocalizedInfos(const char* comp_id, uid_t uid,
+ std::vector<std::unique_ptr<LocalizedInfo>>& infos) {
+ std::string query = std::string(QUERY_LOCALIZED_INFO);
+ if (comp_id != nullptr)
+ query += " WHERE component_id=?";
+
+ std::tuple<const char*, std::vector<std::unique_ptr<LocalizedInfo>>&> param(
+ comp_id, infos);
+ return Step<GetLocalizedInfosCb, const char*,
+ std::vector<std::unique_ptr<LocalizedInfo>>&>(
+ [](sqlite3* db, sqlite3_stmt* stmt, std::tuple<const char*,
+ std::vector<std::unique_ptr<LocalizedInfo>>&> args) -> int {
+ auto* id = std::get<0>(args);
+ if (id != nullptr)
+ __BIND_TEXT(db, stmt, 1, id);
+
+ auto& v = std::get<1>(args);
+ while (sqlite3_step(stmt) == SQLITE_ROW)
+ v.emplace_back(CreateLocalizedInfo(stmt));
+
+ if (v.empty())
+ return AUL_ERROR_NO_SUCH_APP;
+
+ return AUL_ERROR_NONE;
+ }, param, query, uid);
+}
+
+} // namespace
+
+extern "C" API int aul_compinfo_create(const char* comp_id,
+ aul_compinfo_h* handle) {
+ return aul_compinfo_usr_create(comp_id, getuid(), handle);
+}
+
+extern "C" API int aul_compinfo_usr_create(const char* comp_id, uid_t uid,
+ aul_compinfo_h* handle) {
+ if (comp_id == nullptr || handle == nullptr) {
+ _E("Invalid parameter");
+ return AUL_ERROR_INVALID_PARAMETER;
+ }
+
+ ComponentInfo* info;
+ int ret = ::GetComponentInfo(comp_id, uid, &info);
+ if (ret != AUL_ERROR_NONE && uid != GLOBALAPP_UID)
+ ret = ::GetComponentInfo(comp_id, GLOBALAPP_UID, &info);
+
+ if (ret != AUL_ERROR_NONE)
+ return ret;
+
+ *handle = static_cast<aul_compinfo_h>(info);
+ return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_compinfo_destroy(aul_compinfo_h handle) {
+ if (handle == nullptr) {
+ _E("Invalid parameter");
+ return AUL_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* info = static_cast<ComponentInfo*>(handle);
+ delete info;
+ return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_compinfo_clone(aul_compinfo_h handle,
+ aul_compinfo_h* clone) {
+ if (handle == nullptr || clone == nullptr) {
+ _E("Invalid parameter");
+ return AUL_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* info = static_cast<ComponentInfo*>(handle);
+ ComponentInfo::Builder builder;
+ builder.SetAppId(info->GetAppId());
+ builder.SetCompId(info->GetCompId());
+ builder.SetType(info->GetType());
+ builder.SetLaunchMode(info->GetLaunchMode());
+ builder.SetMainComp(info->GetMainComp());
+ builder.SetIconDisplay(info->GetIconDisplay());
+ builder.SetTaskManage(info->GetTaskManage());
+ auto* cloned_info = builder.Build();
+ if (cloned_info == nullptr) {
+ _E("Out of memory");
+ return AUL_ERROR_OUT_OF_MEMORY;
+ }
+
+ *clone = static_cast<aul_compinfo_h>(cloned_info);
+ return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_compinfo_get_app_id(aul_compinfo_h handle,
+ const char** app_id) {
+ if (handle == nullptr || app_id == nullptr) {
+ _E("Invalid parameter");
+ return AUL_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* info = static_cast<ComponentInfo*>(handle);
+ *app_id = info->GetAppId().c_str();
+ return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_compinfo_get_comp_id(aul_compinfo_h handle,
+ const char** comp_id) {
+ if (handle == nullptr || comp_id == nullptr) {
+ _E("Invalid parameter");
+ return AUL_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* info = static_cast<ComponentInfo*>(handle);
+ *comp_id = info->GetCompId().c_str();
+ return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_compinfo_get_type(aul_compinfo_h handle,
+ const char** type) {
+ if (handle == nullptr || type == nullptr) {
+ _E("Invalid parameter");
+ return AUL_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* info = static_cast<ComponentInfo*>(handle);
+ *type = info->GetType().c_str();
+ return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_compinfo_get_launch_mode(aul_compinfo_h handle,
+ const char** launch_mode) {
+ if (handle == nullptr || launch_mode == nullptr) {
+ _E("Invalid parameter");
+ return AUL_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* info = static_cast<ComponentInfo*>(handle);
+ *launch_mode = info->GetLaunchMode().c_str();
+ return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_compinfo_is_main_comp(aul_compinfo_h handle,
+ bool* main_comp) {
+ if (handle == nullptr || main_comp == nullptr) {
+ _E("Invalid parameter");
+ return AUL_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* info = static_cast<ComponentInfo*>(handle);
+ if (info->GetMainComp() == "true")
+ *main_comp = true;
+ else
+ *main_comp = false;
+
+ return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_compinfo_is_icon_display(aul_compinfo_h handle,
+ bool* icon_display) {
+ if (handle == nullptr || icon_display == nullptr) {
+ _E("Invalid parameter");
+ return AUL_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* info = static_cast<ComponentInfo*>(handle);
+ if (info->GetIconDisplay() == "true")
+ *icon_display = true;
+ else
+ *icon_display = false;
+
+ return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_compinfo_is_taskmanage(aul_compinfo_h handle,
+ bool* taskmanage) {
+ if (handle == nullptr || taskmanage == nullptr) {
+ _E("Invalid parameter");
+ return AUL_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* info = static_cast<ComponentInfo*>(handle);
+ if (info->GetTaskManage() == "true")
+ *taskmanage = true;
+ else
+ *taskmanage = false;
+
+ return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_compinfo_foreach_compinfo_from_app(const char* app_id,
+ aul_compinfo_cb callback, void* user_data) {
+ return aul_compinfo_usr_foreach_compinfo_from_app(app_id, getuid(),
+ callback, user_data);
+}
+
+extern "C" API int aul_compinfo_usr_foreach_compinfo_from_app(
+ const char* app_id, uid_t uid, aul_compinfo_cb callback, void* user_data) {
+ if (app_id == nullptr || callback == nullptr) {
+ _E("Invalid parameter");
+ return AUL_ERROR_INVALID_PARAMETER;
+ }
+
+ std::vector<std::unique_ptr<ComponentInfo>> infos;
+ int ret = ::GetComponentInfos(app_id, uid, infos);
+ if (ret != AUL_ERROR_NONE && uid != GLOBALAPP_UID)
+ ret = ::GetComponentInfos(app_id, GLOBALAPP_UID, infos);
+
+ if (ret != AUL_ERROR_NONE) {
+ _E("Failed to get component infos");
+ return ret;
+ }
+
+ for (auto& info : infos) {
+ aul_compinfo_h handle = static_cast<aul_compinfo_h>(info.get());
+ if (!callback(handle, user_data))
+ break;
+ }
+
+ return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_compinfo_foreach_compinfo(aul_compinfo_cb callback,
+ void* user_data) {
+ return aul_compinfo_usr_foreach_compinfo(getuid(), callback, user_data);
+}
+
+extern "C" API int aul_compinfo_usr_foreach_compinfo(uid_t uid,
+ aul_compinfo_cb callback, void* user_data) {
+ if (callback == nullptr) {
+ _E("Invalid parameter");
+ return AUL_ERROR_INVALID_PARAMETER;
+ }
+
+ std::vector<std::unique_ptr<ComponentInfo>> infos;
+ int ret = ::GetComponentInfos(nullptr, uid, infos);
+ if (ret != AUL_ERROR_NONE && uid != GLOBALAPP_UID)
+ ret = ::GetComponentInfos(nullptr, GLOBALAPP_UID, infos);
+
+ if (ret != AUL_ERROR_NONE) {
+ _E("Failed to get component infos");
+ return ret;
+ }
+
+ for (auto& info : infos) {
+ aul_compinfo_h handle = static_cast<aul_compinfo_h>(info.get());
+ if (!callback(handle, user_data))
+ break;
+ }
+
+ return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_compinfo_localized_info_get_locale(
+ aul_compinfo_localized_info_h handle, const char** locale) {
+ if (handle == nullptr || locale == nullptr) {
+ _E("Invalid parameter");
+ return AUL_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* info = static_cast<LocalizedInfo*>(handle);
+ *locale = info->GetLocale().c_str();
+ return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_compinfo_localized_info_get_icon(
+ aul_compinfo_localized_info_h handle, const char** icon) {
+ if (handle == nullptr || icon == nullptr) {
+ _E("Invalid parameter");
+ return AUL_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* info = static_cast<LocalizedInfo*>(handle);
+ *icon = info->GetIcon().c_str();
+ return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_compinfo_localized_info_get_label(
+ aul_compinfo_localized_info_h handle, const char** label) {
+ if (handle == nullptr || label == nullptr) {
+ _E("Invalid parameter");
+ return AUL_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* info = static_cast<LocalizedInfo*>(handle);
+ *label = info->GetLabel().c_str();
+ return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_compinfo_foreach_localized_info(const char* comp_id,
+ aul_compinfo_localized_info_cb callback, void* user_data) {
+ return aul_compinfo_usr_foreach_localized_info(comp_id, getuid(),
+ callback, user_data);
+}
+
+extern "C" API int aul_compinfo_usr_foreach_localized_info(const char* comp_id,
+ uid_t uid, aul_compinfo_localized_info_cb callback, void* user_data) {
+ if (comp_id == nullptr || callback == nullptr) {
+ _E("Invalid parameter");
+ return AUL_ERROR_INVALID_PARAMETER;
+ }
+
+ std::vector<std::unique_ptr<LocalizedInfo>> infos;
+ int ret = GetLocalizedInfos(comp_id, uid, infos);
+ if (ret != AUL_ERROR_NONE && uid != GLOBALAPP_UID)
+ ret = GetLocalizedInfos(comp_id, GLOBALAPP_UID, infos);
+
+ if (ret != AUL_ERROR_NONE) {
+ _E("Failed to get localized infos");
+ return ret;
+ }
+
+ for (auto& info : infos) {
+ auto handle = static_cast<aul_compinfo_localized_info_h>(info.get());
+ if (!callback(handle, user_data))
+ break;
+ }
+
+ return AUL_ERROR_NONE;
+}
--- /dev/null
+/*
+ * Copyright (c) 2019 - 2021 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_COMP_INFO_INTERNAL_H__
+#define __AUL_COMP_INFO_INTERNAL_H__
+
+#include <unistd.h>
+
+#include <aul_types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief The component information handle.
+ * @since_tizen 5.5
+ */
+typedef void *aul_compinfo_h;
+
+/**
+ * @brief The localized information handle of the component.
+ * @since_tizen 5.5
+ */
+typedef void *aul_compinfo_localized_info_h;
+
+/**
+ * @brief Called to get the component information once for each installed component.
+ * @since_tizen 5.5
+ *
+ * @param[in] handle The component information handle
+ * @param[in] user_data The user data passed from the foreach function
+ * @return @c true to continue with the next iteration of the loop, \n
+ * otherwise @ false to break out of the loop
+ * @see aul_compinfo_foreach_compinfo()
+ * @see aul_compinfo_usr_foreach_compinfo()
+ */
+typedef bool (*aul_compinfo_cb)(aul_compinfo_h handle, void *user_data);
+
+/**
+ * @brief Called to get the localized information once for each installed component.
+ * @since_tizen 5.5
+ *
+ * @param[in] handle The localized_information handle of the component
+ * @param[in] user_data The user data passed from the foreach function
+ * @return @c true to continue with the next iteration of the loop, \n
+ * otherwise @ false to break out of the loop
+ * @see aul_compinfo_foreach_localized_info()
+ * @see aul_compinfo_usr_foreach_localized_info()
+ */
+typedef bool (*aul_compinfo_localized_info_cb)(
+ aul_compinfo_localized_info_h handle, void *user_data);
+
+/**
+ * @brief Creates the component information handle.
+ * @since_tizen 5.5
+ * @remarks You MUST release @a handle using aul_compinfo_destroy().
+ *
+ * @param[in] comp_id The component ID
+ * @param[out] handle The component information handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_compinfo_create(const char *comp_id, aul_compinfo_h *handle);
+
+/**
+ * @brief Creates the component information handle.
+ * @since_tizen 5.5
+ * @remarks You MUST release @a handle using aul_comp_info_destroy().
+ *
+ * @param[in] comp_id The component ID
+ * @param[in] uid The user ID
+ * @param[out] handle The component information handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_compinfo_usr_create(const char *comp_id, uid_t uid,
+ aul_compinfo_h *handle);
+
+/**
+ * @brief Destroys the component information handle.
+ * @since_tizen 5.5
+ *
+ * @param[in] handle The component information handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_compinfo_destroy(aul_compinfo_h handle);
+
+/**
+ * @brief Clones the component information handle.
+ * @since_tizen 5.5
+ * @remarks You MUST release @a clone using aul_compinfo_destroy().
+ *
+ * @param[in] handle The component information handle
+ * @param[out] clone A newly created component information handle, if successfully cloned
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_compinfo_clone(aul_compinfo_h handle, aul_compinfo_h *clone);
+
+/**
+ * @brief Gets the application ID of the component.
+ * @since_tizen 5.5
+ * @remarks You MUST NOT release @a app_id using free().
+ *
+ * @param[in] handle The component information handle
+ * @param[out] app_id The application ID of the component
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_compinfo_get_app_id(aul_compinfo_h handle, const char **app_id);
+
+/**
+ * @brief Gets the ID of the component.
+ * @since_tizen 5.5
+ * @remarks You MUST NOT release @a comp_id using free().
+ *
+ * @param[in] handle The component information handle
+ * @param[out] comp_id The ID of the component
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_compinfo_get_comp_id(aul_compinfo_h handle, const char **comp_id);
+
+/**
+ * @brief Gets the type of the component.
+ * @since_tizen 5.5
+ * @remarks You MUST NOT release @a type using free().
+ *
+ * @param[in] handle The component information handle
+ * @param[out] type The type of the component
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_compinfo_get_type(aul_compinfo_h handle, const char **type);
+
+/**
+ * @brief Gets the launch mode of the component.
+ * @since_tizen 5.5
+ * @remarks You MUST NOT release @a launch_mode using free().
+ *
+ * @param[in] handle The component information handle
+ * @param[out] launch_mode The launch mode of the component
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_compinfo_get_launch_mode(aul_compinfo_h handle,
+ const char **launch_mode);
+
+/**
+ * @brief Checks whether the component is the main component or not.
+ * @since_tizen 5.5
+ *
+ * @param[in] handle The component information handle
+ * @param[out] main_comp @c true if the component is the main component, \n
+ * otherwise @c false
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_compinfo_is_main_comp(aul_compinfo_h handle, bool *main_comp);
+
+/**
+ * @brief Checks whether the icon of the component should be displayed or not.
+ * @since_tizen 5.5
+ *
+ * @param[in] handle The component information handle
+ * @param[out] icon_display @c true if the icon should be displayed, \n
+ * otherwise @c false
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_compinfo_is_icon_display(aul_compinfo_h handle, bool *icon_display);
+
+/**
+ * @brief Checks whether the component should be managed by task-manager or not.
+ * @since_tizen 5.5
+ *
+ * @param[in] handle The component information handle
+ * @param[out] taskmanage @c true if the component should be managed by task-manager, \n
+ * otherwise @c false
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_compinfo_is_taskmanage(aul_compinfo_h handle, bool *taskmanage);
+
+/**
+ * @brief Retrieves all installed components information of the specified application.
+ * @since_tizen 5.5
+ *
+ * @param[in] app_id The application ID
+ * @param[in] callback The callback function to invoke
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @see aul_comp_info_cb()
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_compinfo_foreach_compinfo_from_app(const char *app_id,
+ aul_compinfo_cb callback, void *user_data);
+
+/**
+ * @brief Retrieves all installed components information of the specified application.
+ * @since_tizen 5.5
+ *
+ * @param[in] app_id The application ID
+ * @param[in] uid The user ID
+ * @param[in] callback The callback function to invoke
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @see aul_compinfo_cb()
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_compinfo_usr_foreach_compinfo_from_app(const char *app_id, uid_t uid,
+ aul_compinfo_cb callback, void *user_data);
+
+/**
+ * @brief Retrieves all installed components information.
+ * @since_tizen 5.5
+ *
+ * @param[in] callback The callback function to invoke
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @see aul_compinfo_cb()
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_compinfo_foreach_compinfo(aul_compinfo_cb callback, void *user_data);
+
+/**
+ * @brief Retrieves all installed components information.
+ * @since_tizen 5.5
+ *
+ * @param[in] uid The user ID
+ * @param[in] callback The callback function to invoke
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @see aul_compinfo_cb()
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_compinfo_usr_foreach_compinfo(uid_t uid, aul_compinfo_cb callback,
+ void *user_data);
+
+/**
+ * @brief Gets the locale of the component.
+ * @since_tizen 5.5
+ * @details The @a handle is passed from the aul_compinfo_localized_info_cb() function.
+ * @remarks You MUST NOT release @a locale using free().
+ *
+ * @param[in] handle The localized information handle
+ * @param[out] locale The locale
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @see aul_compinfo_foreach_localized_info()
+ * @see aul_compinfo_localized_info_cb()
+ *
+ * @remarks This function is only for App Framework insternally.
+ */
+int aul_compinfo_localized_info_get_locale(aul_compinfo_localized_info_h handle,
+ const char **locale);
+
+/**
+ * @brief Gets the icon path of the component.
+ * @since_tizen 5.5
+ * @details The @a handle is passed from the aul_compinfo_localized_info_cb() function.
+ * @remarks You MUST NOT release @a icon using free().
+ *
+ * @param[in] handle The localized information handle
+ * @param[out] icon The icon path
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @see aul_compinfo_foreach_localized_info()
+ * @see aul_compinfo_localized_info_cb()
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_compinfo_localized_info_get_icon(aul_compinfo_localized_info_h handle,
+ const char **icon);
+
+/**
+ * @brief Gets the label of the component.
+ * @since_tizen 5.5
+ * @details The @a handle is passed from the aul_compinfo_localized_info_cb() function.
+ * @remarks You MUST NOT release @a label using free().
+ *
+ * @param[in] handle The localized information handle
+ * @param[out] label The label
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @see aul_compinfo_foreach_localized_info()
+ * @see aul_compinfo_localized_info_cb()
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_compinfo_localized_info_get_label(aul_compinfo_localized_info_h handle,
+ const char **label);
+
+/**
+ * @brief Retrieves all localized information of the specified component.
+ * @since_tizen 5.5
+ *
+ * @param[in] comp_id The component ID
+ * @param[in] callback The callback function to invoke
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @see aul_compinfo_localized_info_cb()
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_compinfo_foreach_localized_info(const char *comp_id,
+ aul_compinfo_localized_info_cb callback, void *user_data);
+
+/**
+ * @brief Retrieves all localized information of the specified component.
+ * @since_tizen 5.5
+ *
+ * @param[in] comp_id The component ID
+ * @param[in] uid The user ID
+ * @param[in] callback The callback function to invoke
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @see aul_compinfo_localized_info_cb()
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_compinfo_usr_foreach_localized_info(const char *comp_id, uid_t uid,
+ aul_compinfo_localized_info_cb callback, void *user_data);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __AUL_COMP_INFO_INTERNAL_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2021 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 <sys/types.h>
+#include <tzplatform_config.h>
+#include <unistd.h>
+
+#include <map>
+#include <memory>
+#include <string>
+#include <tuple>
+#include <utility>
+#include <vector>
+
+#include "server/api/aul_service.h"
+#include "server/common_private.hh"
+#include "server/database.hh"
+#include "server/log_private.hh"
+
+using namespace aul;
+
+namespace {
+
+const char APPSVC_DB[] = ".appsvc.db";
+const char QUERY_INSERT_OR_REPLACE_INTO_APPSVC[] = "INSERT OR REPLACE INTO "
+ "appsvc(operation, mime_type, uri, pkg_name) VALUES(?, ?, ?, ?)";
+const char QUERY_DELETE_FROM_APPSVC[] = "DELETE FROM appsvc";
+const char QUERY_INSERT_OR_REPLACE_INTO_ALIAS_INFO[] =
+ "INSERT OR REPLACE INTO alias_info(alias_appid, appid) VALUES(?, ?)";
+const char QUERY_DELETE_FROM_ALIAS_INFO[] = "DELETE FROM alias_info";
+const char QUERY_SELECT_FROM_ALIAS_INFO[] = "SELECT alias_appid, appid "
+ "FROM alias_info";
+const char QUERY_INSERT_OR_REPLACE_INTO_ALIAS_INFO_FOR_UID[] =
+ "INSERT OR REPLACE INTO alias_info_for_uid(appid, uid, is_enabled) "
+ "VALUES((SELECT appid FROM alias_info WHERE appid = ?), ?, ?)";
+const char QUERY_UPDATE_ALIAS_INFO_SET_ENABLE_WHERE_APPID[] =
+ "UPDATE alias_info set enable = ? WHERE appid = ?";
+const char QUERY_SELECT_APPID_FROM_ALIAS_INFO[] =
+ "SELECT appid FROM alias_info WHERE alias_info.alias_appid = ?";
+const char QUERY_SELECT_FROM_ALLOWED_INFO[] =
+ "SELECT appid, allowed_appid FROM allowed_info";
+
+using InsertDefaultAppTupleParam = std::vector<const char*>;
+using InsertDefaultAppCb =
+ int (*)(sqlite3*, sqlite3_stmt*, std::tuple<InsertDefaultAppTupleParam>);
+using DeleteDefaultAppCb =
+ int (*)(sqlite3*, sqlite3_stmt*, std::tuple<const char*>);
+using InsertAliasAppIdParam = std::vector<const char*>;
+using InsertAliasAppIdCb =
+ int (*)(sqlite3*, sqlite3_stmt*, std::tuple<InsertAliasAppIdParam>);
+using DeleteAliasAppIdCb =
+ int (*)(sqlite3*, sqlite3_stmt*, std::tuple<const char*>);
+using SelectAliasInfoCb =
+ int (*)(sqlite3*, sqlite3_stmt*,
+ std::tuple<uid_t, uid_t, std::map<std::string, std::string>&>);
+using EnableOrDisableAliasInfoCb =
+ int (*)(sqlite3*, sqlite3_stmt*,
+ std::tuple<uid_t, uid_t, const char*, bool>);
+using SelectAllowedInfoCb =
+ int (*)(sqlite3*, sqlite3_stmt*,
+ std::tuple<std::vector<std::pair<std::string, std::string>>&>);
+
+template <typename T, typename ...ARGS>
+int Step(T cb, std::tuple<ARGS...> args,
+ bool readonly, const std::string& query, uid_t uid) {
+ std::string path = Database::GetPath(APPSVC_DB, uid);
+ Database db(path, false);
+ try {
+ db.Open(readonly ? SQLITE_OPEN_READONLY : SQLITE_OPEN_READWRITE);
+ } catch (Exception& e) {
+ return AUL_ERROR_IO_ERROR;
+ }
+
+ sqlite3_stmt* stmt;
+ __PREPARE_V2(db.GetHandle(), query.c_str(), query.length(), stmt);
+ auto stmt_ptr = std::unique_ptr<sqlite3_stmt, decltype(sqlite3_finalize)*>(
+ stmt, sqlite3_finalize);
+
+ int ret;
+ if (readonly) {
+ ret = cb(db.GetHandle(), stmt, args);
+ } else {
+ db.BeginTransaction();
+ ret = cb(db.GetHandle(), stmt, args);
+ if (ret < 0)
+ db.Rollback();
+ else
+ db.EndTransaction();
+ }
+
+ return ret;
+}
+
+int GetAliasInfos(uid_t uid, uid_t db_uid,
+ std::map<std::string, std::string>& infos) {
+ std::string query(QUERY_SELECT_FROM_ALIAS_INFO);
+ if (db_uid == GLOBALAPP_UID) {
+ query += " WHERE alias_info.appid NOT IN (SELECT appid FROM";
+ query += " alias_info_for_uid WHERE uid = ?)";
+ } else {
+ query += " WHERE enable = 'true'";
+ }
+
+ std::tuple<uid_t, uid_t, std::map<std::string, std::string>&> param(
+ uid, db_uid, infos);
+ int ret = Step<SelectAliasInfoCb, uid_t, uid_t,
+ std::map<std::string, std::string>&>(
+ [](sqlite3* db, sqlite3_stmt* stmt,
+ std::tuple<uid_t, uid_t,
+ std::map<std::string, std::string>&> args) -> int {
+ uid_t db_uid = std::get<1>(args);
+ if (db_uid == GLOBALAPP_UID) {
+ uid_t uid = std::get<0>(args);
+ __BIND_INT(db, stmt, 1, uid);
+ }
+
+ auto& infos = std::get<2>(args);
+ while (sqlite3_step(stmt) == SQLITE_ROW) {
+ int idx = 0;
+ std::string alias_appid = Database::ColumnText(stmt, idx++);
+ std::string appid = Database::ColumnText(stmt, idx++);
+ infos[alias_appid] = appid;
+ }
+
+ return AUL_ERROR_NONE;
+ }, param, true, query, db_uid);
+ if (ret != AUL_ERROR_NONE)
+ return AUL_ERROR_IO_ERROR;
+
+ return AUL_ERROR_NONE;
+}
+
+int EnableOrDisableAliasInfo(uid_t uid, uid_t db_uid, const char* appid,
+ bool enable) {
+ std::string query;
+ if (db_uid == GLOBALAPP_UID)
+ query = QUERY_INSERT_OR_REPLACE_INTO_ALIAS_INFO_FOR_UID;
+ else
+ query = QUERY_UPDATE_ALIAS_INFO_SET_ENABLE_WHERE_APPID;
+
+ std::tuple<uid_t, uid_t, const char*, bool> param(uid, db_uid, appid, enable);
+ int ret = Step<EnableOrDisableAliasInfoCb, uid_t, uid_t, const char*, bool>(
+ [](sqlite3* db, sqlite3_stmt* stmt,
+ std::tuple<uid_t, uid_t, const char*, bool> args) -> int {
+ int idx = 1;
+ uid_t db_uid = std::get<1>(args);
+ if (db_uid == GLOBALAPP_UID) {
+ __BIND_TEXT(db, stmt, idx++, std::get<2>(args));
+ __BIND_INT(db, stmt, idx++, std::get<0>(args));
+ __BIND_TEXT(db, stmt, idx++, std::get<3>(args) ? "true" : "false");
+ } else {
+ __BIND_TEXT(db, stmt, idx++, std::get<3>(args) ? "true" : "false");
+ __BIND_TEXT(db, stmt, idx++, std::get<2>(args));
+ }
+
+ __STEP(db, stmt);
+ return AUL_ERROR_NONE;
+ }, param, false, query, db_uid);
+ if (ret != AUL_ERROR_NONE)
+ return AUL_ERROR_IO_ERROR;
+
+ return AUL_ERROR_NONE;
+}
+
+int GetAllowedInfos(uid_t uid,
+ std::vector<std::pair<std::string, std::string>>& infos) {
+ std::string query(QUERY_SELECT_FROM_ALLOWED_INFO);
+ std::tuple<std::vector<std::pair<std::string, std::string>>&> param(infos);
+ int ret = Step<SelectAllowedInfoCb,
+ std::vector<std::pair<std::string, std::string>>&>(
+ [](sqlite3* db, sqlite3_stmt* stmt,
+ std::tuple<std::vector<std::pair<std::string,
+ std::string>>&> args) -> int {
+ auto& infos = std::get<0>(args);
+ while (sqlite3_step(stmt) == SQLITE_ROW) {
+ int idx = 0;
+ std::string appid = Database::ColumnText(stmt, idx++);
+ std::string allowed_appid = Database::ColumnText(stmt, idx++);
+ infos.emplace_back(appid, allowed_appid);
+ }
+ return AUL_ERROR_NONE;
+ }, param, false, query, uid);
+ if (ret != AUL_ERROR_NONE)
+ return AUL_ERROR_IO_ERROR;
+
+ return AUL_ERROR_NONE;
+}
+
+} // namespace
+
+extern "C" API int aul_service_insert_usr_default_app(const char* operation,
+ const char* mime_type, const char* uri, const char* appid, uid_t uid) {
+ if (operation == nullptr || appid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_ERROR_INVALID_PARAMETER;
+ }
+
+ std::string query(QUERY_INSERT_OR_REPLACE_INTO_APPSVC);
+ std::vector<const char*> argv { operation, mime_type, uri, appid };
+ std::tuple<InsertDefaultAppTupleParam> param(argv);
+ int ret = Step<InsertDefaultAppCb, InsertDefaultAppTupleParam>(
+ [](sqlite3* db, sqlite3_stmt* stmt,
+ std::tuple<InsertDefaultAppTupleParam> args) -> int {
+ int idx = 1;
+ auto argv = std::get<0>(args);
+ __BIND_TEXT(db, stmt, idx++, argv[0]);
+ __BIND_TEXT(db, stmt, idx++, argv[1] ? argv[1] : "NULL");
+ __BIND_TEXT(db, stmt, idx++, argv[2] ? argv[2] : "NULL");
+ __BIND_TEXT(db, stmt, idx++, argv[3]);
+ __STEP(db, stmt);
+ return AUL_ERROR_NONE;
+ }, param, false, query, uid);
+ if (ret != AUL_ERROR_NONE)
+ return AUL_ERROR_IO_ERROR;
+
+ return AUL_ERROR_NONE;
+}
+
+static int __delete_usr_default_app(const char* appid, uid_t uid) {
+ std::string query(QUERY_DELETE_FROM_APPSVC);
+ if (appid != nullptr)
+ query += " WHERE pkg_name = ?";
+
+ std::tuple<const char*> param(appid);
+ int ret = Step<DeleteDefaultAppCb, const char*>(
+ [](sqlite3* db, sqlite3_stmt* stmt, std::tuple<const char*> args) -> int {
+ auto* appid = std::get<0>(args);
+ __BIND_TEXT(db, stmt, 1, appid);
+ __STEP(db, stmt);
+ return AUL_ERROR_NONE;
+ }, param, false, query, uid);
+ if (ret != AUL_ERROR_NONE)
+ return AUL_ERROR_IO_ERROR;
+
+ return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_service_delete_usr_default_app(const char* appid,
+ uid_t uid) {
+ if (appid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_ERROR_INVALID_PARAMETER;
+ }
+
+ return __delete_usr_default_app(appid, uid);
+}
+
+extern "C" API int aul_service_delete_usr_all_default_app(uid_t uid) {
+ return __delete_usr_default_app(nullptr, uid);
+}
+
+extern "C" API int aul_service_insert_usr_alias_appid(const char* alias_appid,
+ const char* appid, uid_t uid) {
+ if (alias_appid == nullptr || appid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_ERROR_INVALID_PARAMETER;
+ }
+
+ std::string query(QUERY_INSERT_OR_REPLACE_INTO_ALIAS_INFO);
+ std::vector<const char*> argv { alias_appid, appid };
+ std::tuple<InsertAliasAppIdParam> param(argv);
+ int ret = Step<InsertAliasAppIdCb, InsertAliasAppIdParam>(
+ [](sqlite3* db, sqlite3_stmt* stmt,
+ std::tuple<InsertAliasAppIdParam> args) -> int {
+ auto& argv = std::get<0>(args);
+ int idx = 1;
+ __BIND_TEXT(db, stmt, idx++, argv[0]);
+ __BIND_TEXT(db, stmt, idx++, argv[1]);
+ __STEP(db, stmt);
+ return AUL_ERROR_NONE;
+ }, param, false, query, uid);
+ if (ret != AUL_ERROR_NONE)
+ return AUL_ERROR_IO_ERROR;
+
+ return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_service_delete_usr_alias_appid(const char* alias_appid,
+ uid_t uid) {
+ if (alias_appid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_ERROR_INVALID_PARAMETER;
+ }
+
+ std::string query = std::string(QUERY_DELETE_FROM_ALIAS_INFO) +
+ " WHERE alias_appid = ?";
+ std::tuple<const char*> param(alias_appid);
+ int ret = Step<DeleteAliasAppIdCb, const char*>(
+ [](sqlite3* db, sqlite3_stmt* stmt, std::tuple<const char*> args) -> int {
+ auto* alias_appid = std::get<0>(args);
+ __BIND_TEXT(db, stmt, 1, alias_appid);
+ __STEP(db, stmt);
+ return AUL_ERROR_NONE;
+ }, param, false, query, uid);
+ if (ret != AUL_ERROR_NONE)
+ return AUL_ERROR_IO_ERROR;
+
+ return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_service_foreach_usr_alias_info(
+ aul_service_alias_info_cb callback, uid_t uid, void* user_data) {
+ if (callback == nullptr) {
+ _E("Invalid parameter");
+ return AUL_ERROR_INVALID_PARAMETER;
+ }
+
+
+ std::map<std::string, std::string> infos;
+ int ret = GetAliasInfos(uid, uid, infos);
+ if (ret == AUL_ERROR_NONE && uid != GLOBALAPP_UID)
+ ret = GetAliasInfos(uid, GLOBALAPP_UID, infos);
+
+ if (ret != AUL_ERROR_NONE) {
+ _E("Failed to get alias infos. error(%d)", ret);
+ return ret;
+ }
+
+ auto iter = infos.begin();
+ while (iter != infos.end()) {
+ if (!callback(iter->first.c_str(), iter->second.c_str(), user_data))
+ break;
+ iter++;
+ }
+
+ return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_service_enable_usr_alias_info(const char* appid,
+ uid_t uid) {
+ if (appid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_ERROR_INVALID_PARAMETER;
+ }
+
+ int ret = EnableOrDisableAliasInfo(uid, uid, appid, true);
+ if (ret != AUL_ERROR_NONE && uid != GLOBALAPP_UID)
+ ret = EnableOrDisableAliasInfo(uid, GLOBALAPP_UID, appid, true);
+
+ return ret;
+}
+
+extern "C" API int aul_service_disable_usr_alias_info(const char* appid,
+ uid_t uid) {
+ if (appid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_ERROR_INVALID_PARAMETER;
+ }
+
+ int ret = EnableOrDisableAliasInfo(uid, uid, appid, false);
+ if (ret != AUL_ERROR_NONE && uid != GLOBALAPP_UID)
+ ret = EnableOrDisableAliasInfo(uid, GLOBALAPP_UID, appid, false);
+
+ return ret;
+}
+
+extern "C" API int aul_service_foreach_usr_allowed_info(
+ aul_service_allowed_info_cb callback, uid_t uid, void* user_data) {
+ if (callback == nullptr) {
+ _E("Invalid parameter");
+ return AUL_ERROR_INVALID_PARAMETER;
+ }
+
+ std::vector<std::pair<std::string, std::string>> infos;
+ int ret = GetAllowedInfos(uid, infos);
+ if (ret == AUL_ERROR_NONE && uid != GLOBALAPP_UID)
+ ret = GetAllowedInfos(GLOBALAPP_UID, infos);
+
+ if (ret != AUL_ERROR_NONE) {
+ _E("Failed to get allowed infos. error(%d)", ret);
+ return ret;
+ }
+
+ for (auto& info : infos) {
+ if (!callback(info.first.c_str(), info.second.c_str(), user_data))
+ break;
+ }
+
+ return AUL_ERROR_NONE;
+}
--- /dev/null
+/*
+ * Copyright (c) 2021 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_SERVICE_H__
+#define __AUL_SERVICE_H__
+
+#include <stdbool.h>
+
+#include <aul_types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef bool (*aul_service_alias_info_cb)(const char *alias_appid, const char *appid, void *user_data);
+
+typedef bool (*aul_service_allowed_info_cb)(const char *appid, const char *allowed_appid, void *user_data);
+
+int aul_service_insert_usr_default_app(const char* operation, const char* mime_type, const char* uri, const char* appid, uid_t uid);
+
+int aul_service_delete_usr_default_app(const char* appid, uid_t uid);
+
+int aul_service_delete_usr_all_default_app(uid_t uid);
+
+int aul_service_insert_usr_alias_appid(const char* alias_appid, const char* appid, uid_t uid);
+
+int aul_service_delete_usr_alias_appid(const char* alias_appid, uid_t uid);
+
+int aul_service_foreach_usr_alias_info(aul_service_alias_info_cb callback, uid_t uid, void* user_data);
+
+int aul_service_enable_usr_alias_info(const char* appid, uid_t uid);
+
+int aul_service_disable_usr_alias_info(const char* appid, uid_t uid);
+
+int aul_service_foreach_usr_allowed_info(aul_service_allowed_info_cb callback, uid_t uid, void* user_data);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __AUL_SERVICE_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2021 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_TYPES_H__
+#define __AUL_TYPES_H__
+
+#include <errno.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Enumeration for errors of AUL.
+ * @since_tizen 6.5
+ */
+typedef enum {
+ AUL_ERROR_NONE = 0, /**< Successful */
+ AUL_ERROR_INVALID_PARAMETER = -EINVAL, /**< Invalid parameter */
+ AUL_ERROR_IO_ERROR = -EIO, /**< I/O error */
+ AUL_ERROR_NO_SUCH_APP = -ENOENT, /**< No such application */
+ AUL_ERROR_NO_DATA = -ENODATA, /**< No data */
+ AUL_ERROR_OUT_OF_MEMORY = -ENOMEM, /**< Out of memory */
+ AUL_ERROR_PERMISSION_DENIED = -EPERM, /**< Permission denied */
+} aul_error_e;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __AUL_TYPES_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2021 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 <sys/types.h>
+#include <tzplatform_config.h>
+#include <unistd.h>
+
+#include "server/api/aul_widget_service.h"
+#include "server/common_private.hh"
+#include "server/database.hh"
+#include "server/log_private.hh"
+
+using namespace aul;
+
+namespace {
+
+const char WIDGET_DB[] = ".widget.db";
+const char QUERY_SET_DISABLE[] = "UPDATE widget_class SET is_disable = ? "
+ "WHERE classid = ?";
+
+std::string GetWidgetDBPath(uid_t uid) {
+ std::string path;
+ if (uid == ROOT_UID || uid == GLOBALAPP_UID) {
+ path = tzplatform_mkpath(TZ_SYS_DB, WIDGET_DB);
+ } else {
+ tzplatform_set_user(uid);
+ path = tzplatform_mkpath(TZ_USER_DB, WIDGET_DB);
+ tzplatform_reset_user();
+ }
+
+ return path;
+}
+
+int SetDisable(sqlite3* db, const char* widget_id, bool is_disable) {
+ sqlite3_stmt* stmt;
+ __PREPARE_V2(db, QUERY_SET_DISABLE, strlen(QUERY_SET_DISABLE),
+ stmt);
+ auto stmt_ptr = std::unique_ptr<sqlite3_stmt, decltype(sqlite3_finalize)*>(
+ stmt, sqlite3_finalize);
+
+ int idx = 1;
+ __BIND_INT(db, stmt, idx++, is_disable ? 1 : 0);
+ __BIND_TEXT(db, stmt, idx++, widget_id);
+ __STEP(db, stmt);
+ return AUL_ERROR_NONE;
+}
+
+} // namespace
+
+extern "C" API int aul_widget_service_set_usr_disable_db(const char* widget_id,
+ bool is_disable, uid_t uid) {
+ if (widget_id == nullptr) {
+ _E("Invalid parameter");
+ return AUL_ERROR_INVALID_PARAMETER;
+ }
+
+ std::string path = ::GetWidgetDBPath(uid);
+ aul::Database db(path);
+ try {
+ db.Open();
+ if (!db.IntegrityCheck()) {
+ _E("database is corrupted");
+ return AUL_ERROR_IO_ERROR;
+ }
+ } catch (Exception& e) {
+ return AUL_ERROR_IO_ERROR;
+ }
+
+ db.BeginTransaction();
+ int ret = ::SetDisable(db.GetHandle(), widget_id, is_disable);
+ db.EndTransaction();
+ return ret;
+}
+
+extern "C" API int aul_widget_service_set_disable_db(const char *widget_id,
+ bool is_disable) {
+ return aul_widget_service_set_usr_disable_db(widget_id, is_disable, getuid());
+}
--- /dev/null
+/*
+ * Copyright (c) 2021 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_WIDGET_SERVICE_H__
+#define __AUL_WIDGET_SERVICE_H__
+
+#include <aul_types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int aul_widget_service_set_usr_disable_db(const char* widget_id, bool is_disable, uid_t uid);
+
+int aul_widget_service_set_disable_db(const char *widget_id, bool is_disable);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __AUL_WIDGET_SERVICE_H__ */
--- /dev/null
+# Package Information for pkg-config
+
+prefix=@PREFIX@
+exec_prefix=@EXEC_PREFIX@
+libdir=@LIB_INSTALL_DIR@
+includedir=@INCLUDE_INSTALL_DIR@
+
+Name: libaul-server
+Description: Application Utility Libarary (Server)
+Version: @VERSION@
+Requires:
+Libs: -L${libdir} -laul-server
+Cflags: -I${includedir} -I${includedir}/aul/server
--- /dev/null
+/*
+ * Copyright (c) 2022 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 "server/boot_sequence.hh"
+
+namespace aul {
+
+BootSequence::BootSequence(std::string appid) : appid_(std::move(appid)) {}
+
+const std::string& BootSequence::GetAppId() const {
+ return appid_;
+}
+
+const std::string& BootSequence::GetAfter() const {
+ return after_;
+}
+
+const std::string& BootSequence::GetBefore() const {
+ return before_;
+}
+
+const std::string& BootSequence::GetRequires() const {
+ return requires_;
+}
+
+const std::string& BootSequence::GetConflicts() const {
+ return conflicts_;
+}
+
+const std::string& BootSequence::GetArgs() const {
+ return args_;
+}
+
+const std::string& BootSequence::GetVconf() const {
+ return vconf_;
+}
+
+const std::string& BootSequence::GetPathExists() const {
+ return path_exists_;
+}
+
+const std::string& BootSequence::GetBackgroundLaunch() const {
+ return background_launch_;
+}
+
+const std::string& BootSequence::GetWaitUntilReady() const {
+ return wait_until_ready_;
+}
+
+const std::string& BootSequence::GetTimeout() const {
+ return timeout_;
+}
+
+void BootSequence::SetAfter(std::string after) {
+ after_ = std::move(after);
+}
+
+void BootSequence::SetBefore(std::string before) {
+ before_ = std::move(before);
+}
+
+void BootSequence::SetRequires(std::string requires_dep) {
+ requires_ = std::move(requires_dep);
+}
+
+void BootSequence::SetConflicts(std::string conflicts) {
+ conflicts_ = std::move(conflicts);
+}
+
+void BootSequence::SetArgs(std::string args) {
+ args_ = std::move(args);
+}
+
+void BootSequence::SetVconf(std::string vconf) {
+ vconf_ = std::move(vconf);
+}
+
+void BootSequence::SetPathExists(std::string path_exists) {
+ path_exists_ = std::move(path_exists);
+}
+
+void BootSequence::SetBackgroundLaunch(std::string background_launch) {
+ background_launch_ = std::move(background_launch);
+}
+
+void BootSequence::SetWaitUntilReady(std::string wait_until_ready) {
+ wait_until_ready_ = std::move(wait_until_ready);
+}
+
+void BootSequence::SetTimeout(std::string timeout) {
+ timeout_ = std::move(timeout);
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2022 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 SERVER_BOOT_SEQUENCE_HH_
+#define SERVER_BOOT_SEQUENCE_HH_
+
+#include <string>
+
+namespace aul {
+
+class BootSequence {
+ public:
+ explicit BootSequence(std::string appid);
+
+ const std::string& GetAppId() const;
+ const std::string& GetAfter() const;
+ const std::string& GetBefore() const;
+ const std::string& GetRequires() const;
+ const std::string& GetConflicts() const;
+ const std::string& GetArgs() const;
+ const std::string& GetVconf() const;
+ const std::string& GetPathExists() const;
+ const std::string& GetBackgroundLaunch() const;
+ const std::string& GetWaitUntilReady() const;
+ const std::string& GetTimeout() const;
+
+ void SetAfter(std::string after);
+ void SetBefore(std::string before);
+ void SetRequires(std::string requires_dep);
+ void SetConflicts(std::string conflicts);
+ void SetArgs(std::string args);
+ void SetVconf(std::string vconf);
+ void SetPathExists(std::string path_exists);
+ void SetBackgroundLaunch(std::string background_launch);
+ void SetWaitUntilReady(std::string wait_until_ready);
+ void SetTimeout(std::string timeout);
+
+ private:
+ std::string appid_;
+ std::string after_;
+ std::string before_;
+ std::string requires_;
+ std::string conflicts_;
+ std::string args_;
+ std::string vconf_;
+ std::string path_exists_;
+ std::string background_launch_;
+ std::string wait_until_ready_;
+ std::string timeout_;
+};
+
+} // namespace aul
+
+#endif // SERVER_BOOT_SEQUENCE_HH_
--- /dev/null
+/*
+ * Copyright (c) 2021 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 SERVER_COMMON_PRIVATE_HH_
+#define SERVER_COMMON_PRIVATE_HH_
+
+#include <tzplatform_config.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#undef API
+#define API __attribute__ ((visibility("default")))
+
+#undef ROOT_UID
+#define ROOT_UID 0
+
+#undef GLOBALAPP_UID
+#define GLOBALAPP_UID tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
+
+#undef REGULAR_UID_MIN
+#define REGULAR_UID_MIN 5000
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // SERVER_COMMON_PRIVATE_HH_
--- /dev/null
+/*
+ * Copyright (c) 2021 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 "server/component_info.hh"
+
+namespace aul {
+
+ComponentInfo::Builder& ComponentInfo::Builder::SetAppId(std::string app_id) {
+ app_id_ = std::move(app_id);
+ return *this;
+}
+
+ComponentInfo::Builder& ComponentInfo::Builder::SetCompId(std::string comp_id) {
+ comp_id_ = std::move(comp_id);
+ return *this;
+}
+
+ComponentInfo::Builder& ComponentInfo::Builder::SetType(std::string type) {
+ type_ = std::move(type);
+ return *this;
+}
+
+ComponentInfo::Builder& ComponentInfo::Builder::SetLaunchMode(
+ std::string launch_mode) {
+ launch_mode_ = std::move(launch_mode);
+ return *this;
+}
+
+ComponentInfo::Builder& ComponentInfo::Builder::SetMainComp(
+ std::string main_comp) {
+ main_comp_ = std::move(main_comp);
+ return *this;
+}
+
+ComponentInfo::Builder& ComponentInfo::Builder::SetIconDisplay(
+ std::string icon_display) {
+ icon_display_ = std::move(icon_display);
+ return *this;
+}
+
+ComponentInfo::Builder& ComponentInfo::Builder::SetTaskManage(
+ std::string taskmanage) {
+ taskmanage_ = std::move(taskmanage);
+ return *this;
+}
+
+ComponentInfo* ComponentInfo::Builder::Build() {
+ return new (std::nothrow) ComponentInfo(std::move(app_id_),
+ std::move(comp_id_), std::move(type_), std::move(launch_mode_),
+ std::move(main_comp_), std::move(icon_display_), std::move(taskmanage_));
+}
+
+ComponentInfo::ComponentInfo(std::string app_id,
+ std::string comp_id,
+ std::string type,
+ std::string launch_mode,
+ std::string main_comp,
+ std::string icon_display,
+ std::string taskmanage)
+ : app_id_(std::move(app_id)),
+ comp_id_(std::move(comp_id)),
+ type_(std::move(type)),
+ launch_mode_(std::move(launch_mode)),
+ main_comp_(std::move(main_comp)),
+ icon_display_(std::move(icon_display)),
+ taskmanage_(std::move(taskmanage)) {
+}
+
+const std::string& ComponentInfo::GetAppId() const {
+ return app_id_;
+}
+
+const std::string& ComponentInfo::GetCompId() const {
+ return comp_id_;
+}
+
+const std::string& ComponentInfo::GetType() const {
+ return type_;
+}
+
+const std::string& ComponentInfo::GetLaunchMode() const {
+ return launch_mode_;
+}
+
+const std::string& ComponentInfo::GetMainComp() const {
+ return main_comp_;
+}
+
+const std::string& ComponentInfo::GetIconDisplay() const {
+ return icon_display_;
+}
+
+const std::string& ComponentInfo::GetTaskManage() const {
+ return taskmanage_;
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2021 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 SERVER_COMPONENT_INFO_HH_
+#define SERVER_COMPONENT_INFO_HH_
+
+#include <string>
+
+namespace aul {
+
+class ComponentInfo {
+ public:
+ class Builder {
+ public:
+ Builder& SetAppId(std::string app_id);
+ Builder& SetCompId(std::string comp_id);
+ Builder& SetType(std::string type);
+ Builder& SetLaunchMode(std::string launch_mode);
+ Builder& SetMainComp(std::string main_comp);
+ Builder& SetIconDisplay(std::string icon_display);
+ Builder& SetTaskManage(std::string taskmanage);
+ ComponentInfo* Build();
+
+ private:
+ std::string app_id_;
+ std::string comp_id_;
+ std::string type_;
+ std::string launch_mode_;
+ std::string main_comp_;
+ std::string icon_display_;
+ std::string taskmanage_;
+ };
+
+ ComponentInfo(std::string app_id,
+ std::string comp_id,
+ std::string type,
+ std::string launch_mode,
+ std::string main_comp,
+ std::string icon_display,
+ std::string taskmanage);
+
+ const std::string& GetAppId() const;
+ const std::string& GetCompId() const;
+ const std::string& GetType() const;
+ const std::string& GetLaunchMode() const;
+ const std::string& GetMainComp() const;
+ const std::string& GetIconDisplay() const;
+ const std::string& GetTaskManage() const;
+
+ private:
+ std::string app_id_;
+ std::string comp_id_;
+ std::string type_;
+ std::string launch_mode_;
+ std::string main_comp_;
+ std::string icon_display_;
+ std::string taskmanage_;
+};
+
+} // namespace aul
+
+#endif // SERVER_COMPONENT_INFO_HH_
--- /dev/null
+/*
+ * Copyright (c) 2021 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 <unistd.h>
+
+#include <memory>
+
+#include "server/common_private.hh"
+#include "server/database.hh"
+#include "server/exception.hh"
+#include "server/log_private.hh"
+
+namespace aul {
+namespace {
+
+const int BUSY_WAITING_USEC = 50000;
+const int BUSY_WAITING_MAX = 40;
+
+} // namespace
+
+Database::Database(std::string path, bool enable_foreign_keys)
+ : path_(std::move(path)),
+ enable_foreign_keys_(enable_foreign_keys) {
+}
+
+Database::~Database() {
+ Close();
+}
+
+void Database::BeginTransaction() {
+ int ret = sqlite3_exec(db_, "BEGIN TRANSACTION", nullptr, nullptr, nullptr);
+ if (ret != SQLITE_OK)
+ _E("sqlite3_exec() is failed. error(%s:%d)", sqlite3_errmsg(db_), ret);
+}
+
+void Database::EndTransaction() {
+ int ret = sqlite3_exec(db_, "END TRANSACTION", nullptr, nullptr, nullptr);
+ if (ret != SQLITE_OK)
+ _E("sqlite3_exec() is failed. error(%s:%d)", sqlite3_errmsg(db_), ret);
+}
+
+void Database::Rollback() {
+ int ret = sqlite3_exec(db_, "ROLLBACK", nullptr, nullptr, nullptr);
+ if (ret != SQLITE_OK)
+ _E("sqlite3_exec() is failed. error(%s:%d", sqlite3_errmsg(db_), ret);
+}
+
+void Database::Open(int flags) {
+ sqlite3* db;
+ int ret = sqlite3_open_v2(path_.c_str(), &db, flags, nullptr);
+ if (ret != SQLITE_OK) {
+ _E("sqlite3_open_v2() is failed. path(%s), error(%d)", path_.c_str(), ret);
+ THROW(-ret);
+ }
+
+ ret = sqlite3_busy_handler(db, BusyHandler,
+ static_cast<void*>(const_cast<char*>(path_.c_str())));
+ if (ret != SQLITE_OK) {
+ _E("sqlite3_busy_handler() is failed. error(%s:%d)",
+ sqlite3_errmsg(db), ret);
+ sqlite3_close_v2(db);
+ THROW(-ret);
+ }
+
+ if (enable_foreign_keys_) {
+ ret = sqlite3_exec(db, "PRAGMA foreign_keys=ON", nullptr, nullptr, nullptr);
+ if (ret != SQLITE_OK) {
+ _E("sqlite3_exec() is failed. error(%s:%d)", sqlite3_errmsg(db), ret);
+ sqlite3_close_v2(db);
+ THROW(-ret);
+ }
+ }
+
+ db_ = db;
+}
+
+void Database::Close() {
+ if (db_) {
+ sqlite3_close_v2(db_);
+ db_ = nullptr;
+ }
+}
+
+sqlite3* Database::GetHandle() {
+ return db_;
+}
+
+std::string Database::ColumnText(sqlite3_stmt* stmt, int index) {
+ auto* text = reinterpret_cast<const char*>(sqlite3_column_text(stmt, index));
+ if (text)
+ return std::string(text);
+
+ return {};
+}
+
+bool Database::IntegrityCheck() {
+ static const char query[] = "PRAGMA integrity_check";
+ sqlite3_stmt* stmt;
+ int ret = sqlite3_prepare_v2(db_, query, strlen(query), &stmt, nullptr);
+ if (ret != SQLITE_OK) {
+ _E("sqlite3_prepare_v2() is failed. error(%s:%d)",
+ sqlite3_errmsg(db_), ret);
+ return false;
+ }
+
+ std::unique_ptr<sqlite3_stmt, decltype(sqlite3_finalize)*> stmt_ptr(
+ stmt, sqlite3_finalize);
+
+ ret = sqlite3_step(stmt);
+ if (ret != SQLITE_ROW) {
+ _E("sqlite3_step() is failed. error(%s:%d)", sqlite3_errmsg(db_), ret);
+ return false;
+ }
+
+ auto* res = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0));
+ if (res == nullptr) {
+ _E("sqlite3_column_text() is failed. error(%s)", sqlite3_errmsg(db_));
+ return false;
+ }
+
+ if (strcmp(res, "ok") != 0)
+ return false;
+
+ return true;
+}
+
+std::string Database::GetPath(const std::string& name, uid_t uid) {
+ std::string path = std::string(tzplatform_getenv(TZ_SYS_DB)) + "/";
+ if (uid >= REGULAR_UID_MIN)
+ path += "user/" + std::to_string(uid) + "/";
+
+ path += name;
+ return path;
+}
+
+int Database::BusyHandler(void* data, int count) {
+ if (count < BUSY_WAITING_MAX) {
+ usleep(BUSY_WAITING_USEC);
+ return 1;
+ }
+
+ auto* path = static_cast<char*>(data);
+ _E("Database(%s) is busy", path);
+ return 0;
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2021 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 SERVER_DATABASE_HH_
+#define SERVER_DATABASE_HH_
+
+#include <sqlite3.h>
+
+#include <memory>
+#include <string>
+
+#include "exception.hh"
+
+#define __PREPARE_V2(db, query, length, stmt) do { \
+ int ret = sqlite3_prepare_v2(db, query, length, &stmt, nullptr); \
+ if (ret != SQLITE_OK) { \
+ _E("sqlite3_prepare_v2() is failed. error(%s:%d)", \
+ sqlite3_errmsg(db), ret); \
+ return -1; \
+ } \
+} while (0)
+
+#define __BIND_INT(db, stmt, i, val) do { \
+ if (sqlite3_bind_int(stmt, i, val) != SQLITE_OK) { \
+ _E("sqlite3_bind_int() is failed. index(%d), error(%s)", \
+ i, sqlite3_errmsg(db)); \
+ return -1; \
+ } \
+} while (0)
+
+#define __BIND_TEXT(db, stmt, i, text) do { \
+ int ret = sqlite3_bind_text(stmt, i, text, -1, SQLITE_TRANSIENT); \
+ if (ret != SQLITE_OK) { \
+ _E("sqlite3_bind_text() is failed. index(%d), error(%s:%d)", \
+ i, sqlite3_errmsg(db), ret); \
+ return -1; \
+ } \
+} while (0)
+
+#define __STEP(db, stmt) do { \
+ int ret = sqlite3_step(stmt); \
+ if (ret != SQLITE_DONE) { \
+ _E("sqlite3_step() is failed. error(%s:%d)", sqlite3_errmsg(db), ret); \
+ return -1; \
+ } \
+} while (0)
+
+#define JOURNAL_MODE_WAL "WAL"
+
+#define JOURNAL_MODE_PERSIST "PERSIST"
+
+#define JOURNAL_MODE_MEMORY "MEMORY"
+
+namespace aul {
+
+class Database {
+ public:
+ explicit Database(std::string path, bool enable_foreign_keys = true);
+ virtual ~Database();
+
+ void Open(int flags = SQLITE_OPEN_READWRITE);
+ void Close();
+ bool IntegrityCheck();
+ void BeginTransaction();
+ void EndTransaction();
+ void Rollback();
+ sqlite3* GetHandle();
+
+ static std::string ColumnText(sqlite3_stmt* stmt, int index);
+ static std::string GetPath(const std::string& name, uid_t uid);
+
+ private:
+ static int BusyHandler(void* data, int count);
+
+ private:
+ std::string path_;
+ bool enable_foreign_keys_;
+ sqlite3* db_ = nullptr;
+};
+
+} // namespace aul
+
+#endif // SERVER_DATABASE_HH_
--- /dev/null
+/*
+ * Copyright (c) 2021 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 "server/exception.hh"
+
+#include <libgen.h>
+
+namespace aul {
+
+Exception::Exception(int error_code, std::string file, int line)
+ : error_code_(error_code) {
+ message_ = std::string(basename(const_cast<char*>(file.c_str()))) + ":" +
+ std::to_string(line) + " code:" + std::to_string(error_code_);
+}
+
+const char* Exception::what() const noexcept {
+ return message_.c_str();
+}
+
+int Exception::GetErrorCode() {
+ return error_code_;
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2021 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 SERVER_EXCEPTION_HH_
+#define SERVER_EXCEPTION_HH_
+
+#include <string>
+#include <exception>
+
+#define THROW(error_code) throw Exception(error_code, __FILE__, __LINE__)
+
+namespace aul {
+
+class Exception : public std::exception {
+ public:
+ explicit Exception(int error_code, std::string file, int line);
+ virtual ~Exception() = default;
+
+ virtual const char* what() const noexcept;
+ int GetErrorCode();
+
+ private:
+ int error_code_;
+ std::string message_;
+};
+
+} // namespace aul
+
+#endif // SERVER_EXCEPTION_HH_
--- /dev/null
+/*
+ * Copyright (c) 2021 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 "server/localized_info.hh"
+
+namespace aul {
+
+LocalizedInfo::Builder& LocalizedInfo::Builder::SetLocale(std::string locale) {
+ locale_ = std::move(locale);
+ return *this;
+}
+
+LocalizedInfo::Builder& LocalizedInfo::Builder::SetIcon(std::string icon) {
+ icon_ = std::move(icon);
+ return *this;
+}
+
+LocalizedInfo::Builder& LocalizedInfo::Builder::SetLabel(std::string label) {
+ label_ = std::move(label);
+ return *this;
+}
+
+LocalizedInfo* LocalizedInfo::Builder::Build() {
+ return new (std::nothrow) LocalizedInfo(std::move(locale_), std::move(icon_),
+ std::move(label_));
+}
+
+LocalizedInfo::LocalizedInfo(std::string locale,
+ std::string icon,
+ std::string label)
+ : locale_(std::move(locale)),
+ icon_(std::move(icon)),
+ label_(std::move(label)) {
+}
+
+const std::string& LocalizedInfo::GetLocale() const {
+ return locale_;
+}
+
+const std::string& LocalizedInfo::GetIcon() const {
+ return icon_;
+}
+
+const std::string& LocalizedInfo::GetLabel() const {
+ return label_;
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2021 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 SERVER_LOCALIZED_INFO_HH_
+#define SERVER_LOCALIZED_INFO_HH_
+
+#include <string>
+
+namespace aul {
+
+class LocalizedInfo {
+ public:
+ class Builder {
+ public:
+ Builder& SetLocale(std::string locale);
+ Builder& SetIcon(std::string icon);
+ Builder& SetLabel(std::string label);
+ LocalizedInfo* Build();
+
+ private:
+ std::string locale_;
+ std::string icon_;
+ std::string label_;
+ };
+
+ LocalizedInfo(std::string locale, std::string icon, std::string label);
+ const std::string& GetLocale() const;
+ const std::string& GetIcon() const;
+ const std::string& GetLabel() const;
+
+ private:
+ std::string locale_;
+ std::string icon_;
+ std::string label_;
+};
+
+} // namespace aul
+
+#endif // SERVER_LOCALIZED_INFO_HH_
--- /dev/null
+/*
+ * Copyright (c) 2021 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 SERVER_LOG_PRIVATE_HH_
+#define SERVER_LOG_PRIVATE_HH_
+
+#include <dlog.h>
+
+#undef LOG_TAG
+#define LOG_TAG "AUL"
+
+#undef _E
+#define _E LOGE
+
+#undef _W
+#define _W LOGW
+
+#undef _I
+#define _I LOGI
+
+#undef _D
+#define _D LOGD
+
+#endif // SERVER_LOG_PRIVATE_HH_
+++ /dev/null
-/*
- * Copyright (c) 2000 - 2022 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include <sys/types.h>
-#include <unistd.h>
-
-#include <bundle_cpp.h>
-
-#include <list>
-#include <memory>
-#include <mutex>
-
-#include "aul_api.h"
-#include "aul_util.h"
-#include "include/aul_app_com.h"
-#include "include/aul_error.h"
-#include "include/aul_sock.h"
-#include "launch.h"
-
-#include "app_request.h"
-#include "aul/common/exception.hh"
-#include "pkginfo_internal.h"
-
-using namespace aul::internal;
-
-struct status_listen_s {
- void* dummy;
-};
-
-namespace {
-using namespace aul;
-
-class AppStatusEvent {
- public:
- AppStatusEvent(std::string appid, uid_t uid, app_status_cb cb,
- void* user_data)
- : appid_(std::move(appid)),
- uid_(uid),
- cb_(cb),
- user_data_(user_data) {
- std::string endpoint = "app_status_event:" + appid_;
- if (uid_ < REGULAR_UID_MIN)
- endpoint += ":" + std::to_string(uid_);
-
- int ret = aul_app_com_create(endpoint.c_str(), nullptr, OnAppComCb, this,
- &connection_);
- if (ret != AUL_R_OK) {
- _E("aul_app_com_create() is failed. endpoint(%s), error(%d)",
- endpoint.c_str(), ret);
- THROW(ret);
- }
- }
-
- ~AppStatusEvent() {
- if (connection_ != nullptr)
- aul_app_com_leave(connection_);
- }
-
- private:
- static int OnAppComCb(const char* endpoint, aul_app_com_result_e res,
- bundle* envelope, void* user_data) {
- tizen_base::Bundle b(envelope);
- aul_app_info app_info = { 0, };
- app_info.appid = const_cast<char*>(b.GetString(AUL_K_APPID).c_str());
- app_info.pkgid = const_cast<char*>(b.GetString(AUL_K_PKGID).c_str());
- app_info.app_path = const_cast<char*>(b.GetString(AUL_K_EXEC).c_str());
- app_info.instance_id = const_cast<char*>(
- b.GetString(AUL_K_INSTANCE_ID).c_str());
- app_info.pid = std::stoi(b.GetString(AUL_K_PID));
- app_info.status = std::stoi(b.GetString(AUL_K_STATUS));
- app_info.is_sub_app = std::stoi(b.GetString(AUL_K_IS_SUBAPP));
- int context_status = std::stoi(b.GetString("__CONTEXT_STATUS__"));
-
- auto* event = static_cast<AppStatusEvent*>(user_data);
- event->cb_(&app_info, context_status, event->user_data_);
- return 0;
- }
-
- private:
- std::string appid_;
- uid_t uid_;
- app_status_cb cb_;
- void* user_data_;
- aul_app_com_connection_h connection_ = nullptr;
-};
-
-class StatusLocalCb {
- public:
- StatusLocalCb(aul_status_local_cb cb, void* user_data)
- : cb_(cb), user_data_(user_data) {
- }
-
- aul_status_local_cb GetCb() const {
- return cb_;
- }
-
- void* GetUserData() const {
- return user_data_;
- }
-
- int Invoke(int status) {
- if (cb_ != nullptr)
- return cb_(status, user_data_);
-
- return 0;
- }
-
- private:
- aul_status_local_cb cb_;
- void* user_data_;
-};
-
-class Context {
- public:
- Context() = default;
-
- int GetStatus() const {
- return status_;
- }
-
- void SetStatus(int status) {
- status_ = status;
- }
-
- void AddLocalCb(aul_status_local_cb cb, void* user_data) {
- std::lock_guard<std::recursive_mutex> lock(mutex_);
- cbs_.emplace_back(new StatusLocalCb(cb, user_data));
- }
-
- std::size_t RemoveLocalCb(aul_status_local_cb cb, void* user_data) {
- std::lock_guard<std::recursive_mutex> lock(mutex_);
- auto count = cbs_.size();
- cbs_.remove_if([&](const std::unique_ptr<StatusLocalCb>& local_cb) {
- return local_cb->GetCb() == cb &&
- local_cb->GetUserData() == user_data;
- });
- return count - cbs_.size();
- }
-
- void InvokeLocalCb(int status) {
- std::lock_guard<std::recursive_mutex> lock(mutex_);
- auto iter = cbs_.begin();
- while (iter != cbs_.end()) {
- if ((*iter)->Invoke(status) < 0)
- iter = cbs_.erase(iter);
- else
- iter++;
- }
- }
-
- private:
- int status_ = STATUS_LAUNCHING;
- std::list<std::unique_ptr<StatusLocalCb>> cbs_;
- std::recursive_mutex mutex_;
-};
-
-Context context;
-
-} // namespace
-
-extern "C" API int aul_status_update(int status) {
- if (status < STATUS_LAUNCHING || status > STATUS_TERMINATE) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- if (context.GetStatus() == status)
- return AUL_R_OK;
-
- context.SetStatus(status);
-
- int ret = aul_sock_send_raw(AUL_UTIL_PID, getuid(), APP_STATUS_UPDATE,
- reinterpret_cast<unsigned char*>(&status), sizeof(status),
- AUL_SOCK_NOREPLY);
- if (ret == 0)
- context.InvokeLocalCb(status);
- else
- ret = aul_error_convert(ret);
-
- return ret;
-}
-
-extern "C" API int aul_app_get_status_bypid(int pid) {
- return aul_app_get_status_bypid_for_uid(pid, getuid());
-}
-
-extern "C" API int aul_app_get_status_bypid_for_uid(int pid, uid_t uid) {
- if (pid < 0) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- if (pid == getpid())
- return context.GetStatus();
-
- if (aul_is_calling_appinfo_cb()) {
- int status = -1;
- aul_app_get_status_bypid_from_current_appinfo(pid, &status);
- if (status != -1)
- return status;
- }
-
- return AppRequest(APP_GET_STATUS, uid)
- .SetPid(pid)
- .SendSimply();
-}
-
-extern "C" API int aul_app_get_status(const char* appid) {
- return aul_app_get_status_for_uid(appid, getuid());
-}
-
-extern "C" API int aul_app_get_status_for_uid(const char* appid, uid_t uid) {
- if (appid == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- if (aul_is_calling_appinfo_cb()) {
- int status = -1;
- aul_app_get_status_from_current_appinfo(appid, &status);
- if (status != -1 && status != STATUS_VISIBLE)
- return status;
- }
-
- return AppRequest(APP_GET_STATUS_BY_APPID, uid)
- .SetAppId(appid)
- .SendSimply();
-}
-
-extern "C" API int aul_add_status_local_cb(aul_status_local_cb callback,
- void* user_data) {
- if (callback == nullptr) {
- _E("Invalid parameter");
- return AUL_R_ERROR;
- }
-
- context.RemoveLocalCb(callback, user_data);
- context.AddLocalCb(callback, user_data);
- return AUL_R_OK;
-}
-
-extern "C" API int aul_remove_status_local_cb(aul_status_local_cb callback,
- void* user_data) {
- if (callback == nullptr) {
- _E("Invalid parameter");
- return AUL_R_ERROR;
- }
-
- if (context.RemoveLocalCb(callback, user_data) > 0)
- return AUL_R_OK;
-
- return AUL_R_EINVAL;
-}
-
-extern "C" API int aul_invoke_status_local_cb(int status) {
- if (status < STATUS_LAUNCHING || status > STATUS_TERMINATE) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- context.InvokeLocalCb(status);
- return AUL_R_OK;
-}
-
-extern "C" API int aul_set_process_group(int owner_pid, int child_pid) {
- if (owner_pid < 1 || child_pid < 1) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- tizen_base::Bundle b {
- { AUL_K_OWNER_PID, std::to_string(owner_pid) },
- { AUL_K_CHILD_PID, std::to_string(child_pid) }
- };
-
- return AppRequest(APP_SET_PROCESS_GROUP, getuid())
- .With(std::move(b))
- .SendSimply();
-}
-
-extern "C" API int aul_listen_app_status(const char* appid,
- app_status_cb callback, void* user_data, status_listen_h* handle) {
- return aul_listen_app_status_for_uid(appid, callback, user_data, handle,
- getuid());
-}
-
-extern "C" API int aul_listen_app_status_for_uid(const char* appid,
- app_status_cb callback, void* user_data, status_listen_h* handle,
- uid_t uid) {
- if (appid == nullptr || callback == nullptr || handle == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- try {
- auto* event = new (std::nothrow) AppStatusEvent(
- appid, uid, callback, user_data);
- if (event == nullptr) {
- _E("Out of memory");
- return AUL_R_ENOMEM;
- }
-
- *handle = reinterpret_cast<status_listen_h>(event);
- } catch (const Exception& e) {
- _E("Exception occurs. error(%s)", e.what());
- return e.GetErrorCode();
- }
-
- return AUL_R_OK;
-}
-
-extern "C" API int aul_ignore_app_status(status_listen_h handle) {
- if (handle == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- auto* event = reinterpret_cast<AppStatusEvent*>(handle);
- delete event;
- return AUL_R_OK;
-}
-
-extern "C" API int aul_notify_exit(void) {
- return AppRequest(APP_NOTIFY_EXIT, getuid())
- .SendCmdOnly(AUL_SOCK_NOREPLY);
-}
-
-extern "C" API int aul_notify_start(void) {
- return AppRequest(APP_NOTIFY_START, getuid())
- .SendCmdOnly(AUL_SOCK_NOREPLY);
-}
-
-extern "C" API const char* aul_app_status_convert_to_string(int status) {
- switch (status) {
- case STATUS_LAUNCHING:
- return "STATUS_LAUNCHING";
- case STATUS_CREATED:
- return "STATUS_CREATED";
- case STATUS_FOCUS:
- return "STATUS_FOCUS";
- case STATUS_VISIBLE:
- return "STATUS_VISIBLE";
- case STATUS_BG:
- return "STATUS_BG";
- case STATUS_DYING:
- return "STATUS_DYING";
- case STATUS_HOME:
- return "STATUS_HOME";
- case STATUS_NORESTART:
- return "STATUS_NORESTART";
- case STATUS_SERVICE:
- return "STATUS_SERVICE";
- case STATUS_TERMINATE:
- return "STATUS_TERMINATE";
- default:
- return "Unknown status";
- }
-}
-
-extern "C" API int aul_status_update_v2(int status) {
- if (status < STATUS_LAUNCHING || status > STATUS_TERMINATE) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- if (context.GetStatus() == status)
- return AUL_R_OK;
-
- context.SetStatus(status);
-
- tizen_base::Bundle b { { AUL_K_STATUS, std::to_string(status) } };
- int ret = AppRequest(APP_STATUS_UPDATE_V2, getuid())
- .With(std::move(b))
- .SendSimply();
- if (ret != 0) {
- _E("Failed to update app status. error(%d)", ret);
- return ret;
- }
-
- context.InvokeLocalCb(status);
- return AUL_R_OK;
-}
--- /dev/null
+ADD_SUBDIRECTORY(app_com_tool)
+ADD_SUBDIRECTORY(app_launcher)
+ADD_SUBDIRECTORY(appgroup_info)
+ADD_SUBDIRECTORY(appid2pid)
+ADD_SUBDIRECTORY(aul_test)
+ADD_SUBDIRECTORY(aul_window)
+ADD_SUBDIRECTORY(aulctl)
+ADD_SUBDIRECTORY(compmgr_tool)
+ADD_SUBDIRECTORY(launch_app)
+ADD_SUBDIRECTORY(launch_debug)
+ADD_SUBDIRECTORY(open_app)
+ADD_SUBDIRECTORY(recovery)
--- /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}/../aul
+ ${CMAKE_CURRENT_SOURCE_DIR}/../aul/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
+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}/../aul)
+TARGET_INCLUDE_DIRECTORIES(${TARGET_APP_LAUNCHER} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/../aul/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 "aul_sock.h"
+#include "launch.h"
+
+#define LAUNCHPAD_PROCESS_POOL_SOCK ".launchpad-process-pool-sock"
+#define PATH_AUL_DAEMONS "/run/aul/daemons"
+#define PATH_AMD_READY "/run/.amd_ready"
+#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_init(struct launch_arg *arg)
+{
+ char buf[PATH_MAX];
+ int retry_count = 0;
+
+ if (__set_appinfo_for_launchpad(arg->b, arg->appid, arg->uid) < 0) {
+ fprintf(stderr, "Failed to set appinfo. appid(%s), uid(%u)\n",
+ arg->appid, arg->uid);
+ return -1;
+ }
+
+ snprintf(buf, sizeof(buf), "/run/aul/daemons/%u/%s",
+ arg->uid, LAUNCHPAD_PROCESS_POOL_SOCK);
+ while (access(buf, F_OK) != 0) {
+ usleep(100 * 1000);
+ if (++retry_count > 100) {
+ fprintf(stderr, "%s is not created\n", buf);
+ break;
+ }
+ }
+
+ return 0;
+}
+
+static int __cmd_fast_start_run(struct launch_arg *arg)
+{
+ int fd;
+
+ if (!access(PATH_AMD_READY, F_OK)) {
+ bundle_del(arg->b, AUL_K_FAST_LAUNCH);
+ return __cmd_start_run(arg);
+ }
+
+ fd = aul_sock_create_launchpad_client_without_timeout(
+ LAUNCHPAD_PROCESS_POOL_SOCK, arg->uid);
+ if (fd < 0) {
+ fprintf(stderr, "Failed to create client socket. error: %d\n",
+ fd);
+ return -1;
+ }
+
+ arg->pid = aul_sock_send_bundle_with_fd(fd, 0, arg->b, AUL_SOCK_NONE);
+ if (arg->pid <= 0) {
+ fprintf(stderr, "... 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_fast_start_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}/../aul
+ ${CMAKE_CURRENT_SOURCE_DIR}/../aul/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
+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}/../aul
+ ${CMAKE_CURRENT_SOURCE_DIR}/../aul/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
+SET(TARGET_AUL_TEST "aul_test")
+
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} AUL_TEST_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/tests TESTS_SRCS)
+
+ADD_EXECUTABLE(${TARGET_AUL_TEST}
+ ${AUL_TEST_SRCS}
+ ${TESTS_SRCS}
+)
+
+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}/
+ ${CMAKE_CURRENT_SOURCE_DIR}/../
+ ${CMAKE_CURRENT_SOURCE_DIR}/../aul/
+ ${CMAKE_CURRENT_SOURCE_DIR}/../aul/api
+ ${CMAKE_CURRENT_SOURCE_DIR}/../aul/include
+)
+
+INSTALL(TARGETS ${TARGET_AUL_TEST} DESTINATION bin)
--- /dev/null
+/*
+ * Copyright (c) 2021 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 "aul_test.hh"
+
+#include <iostream>
+
+#include "log_private.hh"
+
+namespace aul_test {
+
+AulTest::AulTest(std::string test_name, std::string func_name,
+ std::string usage, bool loop_quit)
+ : test_name_(std::move(test_name)),
+ func_name_(std::move(func_name)),
+ usage_(std::move(usage)),
+ loop_quit_(loop_quit) {
+ AulTestMgr::GetInst().AddTest(test_name_, this);
+}
+
+void AulTest::Usage() {
+ _E("\t%s : %s test", test_name_.c_str(), func_name_.c_str());
+ _E("\t\t[usage] %s", usage_.c_str());
+}
+
+tizen_base::Bundle AulTest::CreateBundleFromArgv(int argc, char** argv,
+ int start) {
+ tizen_base::Bundle b;
+ for (int i = start; i < argc - 1; ++i) {
+ if ((i + 1) > argc - 1)
+ b.Add(std::string(argv[i]), " ");
+ else
+ b.Add(std::string(argv[i]), std::string(argv[i + 1]));
+ }
+
+ return b;
+}
+
+bool AulTest::LoopQuit() const {
+ return loop_quit_;
+}
+
+AulTestMgr::AulTestMgr() {
+ loop_ = g_main_loop_new(nullptr, FALSE);
+}
+
+AulTestMgr::~AulTestMgr() {
+ if (loop_) {
+ if (g_main_loop_is_running(loop_))
+ g_main_loop_quit(loop_);
+
+ g_main_loop_unref(loop_);
+ }
+}
+
+AulTestMgr& AulTestMgr::GetInst() {
+ static AulTestMgr inst;
+ return inst;
+}
+
+void AulTestMgr::AddTest(const std::string& test_name, AulTest* aul_test) {
+ tests_[test_name] = aul_test;
+}
+
+int AulTestMgr::RunTest(int argc, char** argv) {
+ if (argc < 2) {
+ PrintUsage();
+ return -1;
+ }
+
+ argc_ = argc;
+ argv_ = argv;
+ g_idle_add(IdleCb, this);
+ g_main_loop_run(loop_);
+ return result_;
+}
+
+void AulTestMgr::PrintUsage() {
+ for (auto const& iter : tests_) {
+ auto* test = iter.second;
+ test->Usage();
+ }
+}
+
+int AulTestMgr::RunTest() {
+ std::string cmd(argv_[1]);
+ auto found = tests_.find(cmd);
+ if (found == tests_.end()) {
+ PrintUsage();
+ g_main_loop_quit(loop_);
+ return -1;
+ }
+
+ auto* test = found->second;
+ test->SetUp();
+ int ret = test->Test(argc_, argv_);
+ test->TearDown();
+ if (ret < 0) {
+ _E("... test failed");
+ g_main_loop_quit(loop_);
+ } else {
+ _E("... test successful ret = %d", ret);
+ if (test->LoopQuit())
+ g_main_loop_quit(loop_);
+ }
+
+ return ret;
+}
+
+gboolean AulTestMgr::IdleCb(gpointer user_data) {
+ auto* mgr = static_cast<AulTestMgr*>(user_data);
+ mgr->result_ = mgr->RunTest();
+ return G_SOURCE_REMOVE;
+}
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 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_TEST_AUL_TEST_HH_
+#define AUL_TEST_AUL_TEST_HH_
+
+#include <bundle_cpp.h>
+#include <bundle_internal.h>
+#include <glib.h>
+
+#include <map>
+#include <string>
+
+#include "aul_test_private.hh"
+
+namespace aul_test {
+
+class AulTest {
+ public:
+ explicit AulTest(std::string test_name, std::string func_name,
+ std::string usage, bool loop_quit = true);
+ virtual ~AulTest() = default;
+ virtual void SetUp() {}
+ virtual void TearDown() {}
+ virtual void Usage();
+ virtual int Test(int argc, char** argv) = 0;
+ tizen_base::Bundle CreateBundleFromArgv(int argc, char** argv, int start);
+ bool LoopQuit() const;
+
+ private:
+ std::string test_name_;
+ std::string func_name_;
+ std::string usage_;
+ bool loop_quit_;
+};
+
+class AulTestMgr {
+ private:
+ AulTestMgr();
+ ~AulTestMgr();
+
+ public:
+ static AulTestMgr& GetInst();
+
+ void AddTest(const std::string& test_name, AulTest* test);
+ int RunTest(int argc, char** argv);
+
+ private:
+ void PrintUsage();
+ int RunTest();
+ static gboolean IdleCb(gpointer user_data);
+
+ private:
+ std::map<std::string, AulTest*> tests_;
+ GMainLoop* loop_ = nullptr;
+ int argc_ = 0;
+ char** argv_ = nullptr;
+ int result_ = 0;
+};
+
+} // namespace aul_test
+
+#endif // AUL_TEST_AUL_TEST_HH_
--- /dev/null
+/*
+ * Copyright (c) 2021 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_TEST_AUL_TEST_PRIVATE_HH_
+#define AUL_TEST_AUL_TEST_PRIVATE_HH_
+
+#define AUL_TEST_REGISTER(test_case_name, test_name) \
+ test_case_name test_name
+
+#endif // AUL_TEST_AUL_TEST_PRIVATE_HH_
--- /dev/null
+/*
+ * Copyright (c) 2021 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_TEST_LOG_PRIVATE_HH_
+#define AUL_TEST_LOG_PRIVATE_HH_
+
+#include <stdio.h>
+
+#undef _E
+#define _E(fmt, arg...) fprintf(stderr, fmt "\n", ##arg)
+
+#undef _W
+#define _W(fmt, arg...) fprintf(stderr, fmt "\n", ##arg)
+
+#undef _I
+#define _I(fmt, arg...) fprintf(stdout, fmt "\n", ##arg)
+
+#undef _D
+#define _D(fmt, arg...) fprintf(stdout, fmt "\n", ##arg)
+
+#endif // AUL_TEST_LOG_PRIVATE_HH_
--- /dev/null
+/*
+ * Copyright (c) 2021 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 "aul_test.hh"
+#include "log_private.hh"
+
+int main(int argc, char** argv) {
+ return aul_test::AulTestMgr::GetInst().RunTest(argc, argv);
+}
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulAppGetAllRunningAppInfoForUidTest : public AulTest {
+ public:
+ AulAppGetAllRunningAppInfoForUidTest()
+ : AulTest("getallappstatus_for_uid",
+ "aul_app_get_all_running_app_info_for_uid",
+ "getallappstatus_for_uid <uid>") {}
+
+ virtual ~AulAppGetAllRunningAppInfoForUidTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_app_get_all_running_app_info_for_uid test] %s", argv[2]);
+ return aul_app_get_all_running_app_info_for_uid(AulAppInfoCb, nullptr,
+ atoi(argv[2]));
+ }
+
+ private:
+ static int AulAppInfoCb(const aul_app_info* info, void* user_data) {
+ _D("\t==========================");
+ _D("\t pid: %d", info->pid);
+ _D("\t appid: %s", info->appid);
+ _D("\t app_path: %s", info->app_path);
+ _D("\t pkgid: %s", info->pkgid);
+ _D("\t status: %d", info->status);
+ _D("\t is_sub_app: %d", info->is_sub_app);
+ _D("\t==========================");
+ return 0;
+ }
+};
+
+AUL_TEST_REGISTER(AulAppGetAllRunningAppInfoForUidTest,
+ getallappstatus_for_uid_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulAppGetAllRunningAppInfoTest : public AulTest {
+ public:
+ AulAppGetAllRunningAppInfoTest()
+ : AulTest("getallappstatus", "aul_app_get_all_running_app_info",
+ "getallappstatus") {}
+
+ virtual ~AulAppGetAllRunningAppInfoTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ _D("[aul_app_get_all_running_app_info test]");
+ return aul_app_get_all_running_app_info(AulAppInfoCb, nullptr);
+ }
+
+ private:
+ static int AulAppInfoCb(const aul_app_info* info, void* user_data) {
+ _D("\t==========================");
+ _D("\t pid: %d", info->pid);
+ _D("\t appid: %s", info->appid);
+ _D("\t app_path: %s", info->app_path);
+ _D("\t pkgid: %s", info->pkgid);
+ _D("\t status: %d", info->status);
+ _D("\t is_sub_app: %d", info->is_sub_app);
+ _D("\t==========================");
+ return 0;
+ }
+};
+
+AUL_TEST_REGISTER(AulAppGetAllRunningAppInfoTest, getallappstatus_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2023 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 <stdlib.h>
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulAppGetAppIdBypidAsyncTest : public AulTest {
+ public:
+ AulAppGetAppIdBypidAsyncTest()
+ : AulTest("get_appid_bypid_async", "aul_app_get_appid_bypid_async",
+ "get_appid_bypid_async <pid>", false) {}
+
+ virtual ~AulAppGetAppIdBypidAsyncTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_app_get_appid_bypid_async test] %s", argv[2]);
+ return aul_app_get_appid_bypid_async(atoi(argv[2]), AulAppIdCb,
+ this);
+ }
+
+ private:
+ static void AulAppIdCb(int result, pid_t pid, const char* appid,
+ void* user_data) {
+ _D("Result: %d, appid: %s", result, appid);
+ }
+};
+
+AUL_TEST_REGISTER(AulAppGetAppIdBypidAsyncTest, get_appid_bypid_async_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulAppGetAppidBypidTest : public AulTest {
+ public:
+ AulAppGetAppidBypidTest()
+ : AulTest("get_app_bypid", "aul_app_get_appid_bypid",
+ "get_app_bypid <pid>") {}
+
+ virtual ~AulAppGetAppidBypidTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_app_get_appid_bypid test] %s", argv[2]);
+ char buf[256] = { 0, };
+ int pid = atoi(argv[2]);
+ if (aul_app_get_appid_bypid(pid, buf, sizeof(buf)) < 0)
+ _E("no such pkg by %d", pid);
+ else
+ _D("pkgname = %s, pid = %d", buf, pid);
+
+ return 0;
+ }
+};
+
+AUL_TEST_REGISTER(AulAppGetAppidBypidTest, get_app_bypid_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulAppGetLastCallerPidForUidTest : public AulTest {
+ public:
+ AulAppGetLastCallerPidForUidTest()
+ : AulTest("get_last_caller_pid_for_uid",
+ "aul_app_get_last_caller_pid_for_uid",
+ "get_last_caller_pid_for_uid <pid> <uid>") {}
+
+ virtual ~AulAppGetLastCallerPidForUidTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 4) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_app_get_last_caller_pid_for_uid test] %s %s", argv[2], argv[3]);
+ return aul_app_get_last_caller_pid_for_uid(atoi(argv[2]), atoi(argv[3]));
+ }
+};
+
+AUL_TEST_REGISTER(AulAppGetLastCallerPidForUidTest,
+ get_last_caller_pid_for_uid_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulAppGetLastCallerPidTest : public AulTest {
+ public:
+ AulAppGetLastCallerPidTest()
+ : AulTest("get_last_caller_pid", "aul_app_get_last_caller_pid",
+ "get_last_caller_pid <pid>") {}
+
+ virtual ~AulAppGetLastCallerPidTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_app_get_last_caller_pid test] %s", argv[2]);
+ return aul_app_get_last_caller_pid(atoi(argv[2]));
+ }
+};
+
+AUL_TEST_REGISTER(AulAppGetLastCallerPidTest, get_last_caller_pid_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulAppGetPidForUidTest : public AulTest {
+ public:
+ AulAppGetPidForUidTest()
+ : AulTest("get_pid_for_uid", "aul_app_get_pid_for_uid",
+ "get_pid_for_uid <appid> <uid>") {}
+
+ virtual ~AulAppGetPidForUidTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 4) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_app_get_pid_for_uid test] %s %s", argv[2], argv[3]);
+ return aul_app_get_pid_for_uid(argv[2], atoi(argv[3]));
+ }
+};
+
+AUL_TEST_REGISTER(AulAppGetPidForUidTest, get_pid_for_uid_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulAppGetPidTest : public AulTest {
+ public:
+ AulAppGetPidTest()
+ : AulTest("get_pid", "aul_app_get_pid", "get_pid <appid>") {}
+
+ virtual ~AulAppGetPidTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_app_get_pid test] %s", argv[2]);
+ return aul_app_get_pid(argv[2]);
+ }
+};
+
+AUL_TEST_REGISTER(AulAppGetPidTest, get_pid_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulAppGetPkgidBypidTest : public AulTest {
+ public:
+ AulAppGetPkgidBypidTest()
+ : AulTest("get_pkg_bypid", "aul_app_get_pkgid_bypid",
+ "get_pkg_bypid <pid>") {}
+
+ virtual ~AulAppGetPkgidBypidTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_app_get_pkgid_bypid test] %s", argv[2]);
+ char buf[256] = { 0, };
+ int pid = atoi(argv[2]);
+ if (aul_app_get_pkgid_bypid(pid, buf, sizeof(buf)) < 0)
+ _E("no such pkg by %d", pid);
+ else
+ _D("pkgname = %s, pid = %d", buf, pid);
+
+ return 0;
+ }
+};
+
+AUL_TEST_REGISTER(AulAppGetPkgidBypidTest, get_pkg_bypid_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulAppGetRunningAppInfoForUidTest : public AulTest {
+ public:
+ AulAppGetRunningAppInfoForUidTest()
+ : AulTest("getallpkg_for_uid", "aul_app_get_running_app_info_for_uid",
+ "getallpkg_for_uid <uid>") {}
+
+ virtual ~AulAppGetRunningAppInfoForUidTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_app_get_running_app_info_for_uid test] %s", argv[2]);
+ return aul_app_get_running_app_info_for_uid(AulAppInfoCb, nullptr,
+ atoi(argv[2]));
+ }
+
+ private:
+ static int AulAppInfoCb(const aul_app_info* info, void* user_data) {
+ _D("\t==========================");
+ _D("\t appid: %s", info->appid);
+ _D("\t app_path: %s", info->app_path);
+ _D("\t running pid: %d", info->pid);
+ _D("\t==========================");
+ return 0;
+ }
+};
+
+AUL_TEST_REGISTER(AulAppGetRunningAppInfoForUidTest, getallpkg_for_uid_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulAppGetRunningAppInfoTest : public AulTest {
+ public:
+ AulAppGetRunningAppInfoTest()
+ : AulTest("getallpkg", "aul_app_get_running_app_info",
+ "getallpkg") {}
+
+ virtual ~AulAppGetRunningAppInfoTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ _D("[aul_app_get_running_app_info test]");
+ return aul_app_get_running_app_info(AulAppInfoCb, nullptr);
+ }
+
+ private:
+ static int AulAppInfoCb(const aul_app_info* info, void* user_data) {
+ _D("\t==========================");
+ _D("\t appid: %s", info->appid);
+ _D("\t app_path: %s", info->app_path);
+ _D("\t running pid: %d", info->pid);
+ _D("\t==========================");
+ return 0;
+ }
+};
+
+AUL_TEST_REGISTER(AulAppGetRunningAppInfoTest, getallpkg_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulAppGetStatusBypidForUidTest : public AulTest {
+ public:
+ AulAppGetStatusBypidForUidTest()
+ : AulTest("get_status_pid_for_uid", "aul_app_get_status_bypid_for_uid",
+ "get_status_pid_for_uid <pid> <uid>") {}
+
+ virtual ~AulAppGetStatusBypidForUidTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 4) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_app_get_status_bypid_for_uid test] %s %s", argv[2], argv[3]);
+ return aul_app_get_status_bypid_for_uid(atoi(argv[2]), atoi(argv[3]));
+ }
+};
+
+AUL_TEST_REGISTER(AulAppGetStatusBypidForUidTest, get_status_pid_for_uid_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulAppGetStatusBypidTest : public AulTest {
+ public:
+ AulAppGetStatusBypidTest()
+ : AulTest("get_status_pid", "aul_app_get_status_bypid",
+ "get_status_pid <pid>") {}
+
+ virtual ~AulAppGetStatusBypidTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_app_get_status_bypid test] %s", argv[2]);
+ int ret = aul_app_get_status_bypid(atoi(argv[2]));
+ if (ret >= 0) {
+ _D("==> pid: %s, status: %d(%s)",
+ argv[2], ret, aul_app_status_convert_to_string(ret));
+ }
+
+ return ret;
+ }
+};
+
+AUL_TEST_REGISTER(AulAppGetStatusBypidTest, get_status_pid_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulAppGetStatusForUidTest : public AulTest {
+ public:
+ AulAppGetStatusForUidTest()
+ : AulTest("get_status_for_uid", "aul_app_get_status_for_uid",
+ "get_status_for_uid <appid> <uid>") {}
+
+ virtual ~AulAppGetStatusForUidTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 4) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_app_get_status_for_uid test] %s %s", argv[2], argv[3]);
+ int ret = aul_app_get_status_for_uid(argv[2], atoi(argv[3]));
+ if (ret >= 0) {
+ _D("==> appid: %s, uid: %s, status: %d(%s)",
+ argv[2], argv[3], ret, aul_app_status_convert_to_string(ret));
+ }
+
+ return ret;
+ }
+};
+
+AUL_TEST_REGISTER(AulAppGetStatusForUidTest, get_status_for_uid_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulAppGetStatusTest : public AulTest {
+ public:
+ AulAppGetStatusTest()
+ : AulTest("get_status", "aul_app_get_status", "get_status <appid>") {}
+
+ virtual ~AulAppGetStatusTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_app_get_status test] %s", argv[2]);
+ int ret = aul_app_get_status(argv[2]);
+ if (ret >= 0) {
+ _D("==> appid: %s, status: %d(%s)",
+ argv[2], ret, aul_app_status_convert_to_string(ret));
+ }
+
+ return ret;
+ }
+};
+
+AUL_TEST_REGISTER(AulAppGetStatusTest, get_status_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulAppIsRunningTest : public AulTest {
+ public:
+ AulAppIsRunningTest()
+ : AulTest("is_run", "aul_app_is_running", "is_run <appid>") {}
+
+ virtual ~AulAppIsRunningTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_app_is_running test] %s", argv[2]);
+ if (aul_app_is_running(argv[2]))
+ _D("... %s is running", argv[2]);
+ else
+ _D("... %s is not running", argv[2]);
+
+ return 0;
+ }
+};
+
+AUL_TEST_REGISTER(AulAppIsRunningTest, is_run_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 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 "aul/api/aul_app_lifecycle.h"
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulAppLifecycleGetStateTest : public AulTest {
+ public:
+ AulAppLifecycleGetStateTest()
+ : AulTest("get_app_lifecycle", "aul_app_lifecycle_get_state",
+ "get_app_lifecycle <appid>") {}
+
+ virtual ~AulAppLifecycleGetStateTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_app_lifecycle_get_state test] %s", argv[2]);
+ aul_app_lifecycle_state_e state;
+ int ret = aul_app_lifecycle_get_state(argv[2], &state);
+ if (ret == AUL_R_OK)
+ _D("==> result: %d, state: %s", ret, LifecycleStateToString(state));
+
+ return ret;
+ }
+
+ private:
+ static const char* LifecycleStateToString(aul_app_lifecycle_state_e state) {
+ switch (state) {
+ case AUL_APP_LIFECYCLE_STATE_INITIALIZED:
+ return "INITIALIZED";
+ case AUL_APP_LIFECYCLE_STATE_CREATED:
+ return "CREATED";
+ case AUL_APP_LIFECYCLE_STATE_RESUMED:
+ return "RESUMED";
+ case AUL_APP_LIFECYCLE_STATE_PAUSED:
+ return "PAUSED";
+ default:
+ return "DESTROYED";
+ }
+ }
+};
+
+AUL_TEST_REGISTER(AulAppLifecycleGetStateTest, get_app_lifecycle_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 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 "aul/api/aul_app_lifecycle.h"
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulAppLifecycleRegisterStateChangedCbTest : public AulTest {
+ public:
+ AulAppLifecycleRegisterStateChangedCbTest()
+ : AulTest("listen_app_lifecycle",
+ "aul_app_lifecycle_register_state_changed_cb",
+ "listen_app_lifecycle", false) {}
+
+ virtual ~AulAppLifecycleRegisterStateChangedCbTest() {
+ aul_app_lifecycle_deregister_state_changed_cb();
+ }
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ _D("[aul_app_lifecycle_register_state_changed_cb test]");
+ return aul_app_lifecycle_register_state_changed_cb(
+ AppLifecycleStateChangedCb, nullptr);
+ }
+
+ private:
+ static const char* LifecycleStateToString(aul_app_lifecycle_state_e state) {
+ switch (state) {
+ case AUL_APP_LIFECYCLE_STATE_INITIALIZED:
+ return "INITIALIZED";
+ case AUL_APP_LIFECYCLE_STATE_CREATED:
+ return "CREATED";
+ case AUL_APP_LIFECYCLE_STATE_RESUMED:
+ return "RESUMED";
+ case AUL_APP_LIFECYCLE_STATE_PAUSED:
+ return "PAUSED";
+ default:
+ return "DESTROYED";
+ }
+ }
+
+ static void AppLifecycleStateChangedCb(const char* appid, pid_t pid,
+ aul_app_lifecycle_state_e state, bool has_focus, void* user_data) {
+ _D("appid: %s, pid: %d, state: %s, has_focus: %s",
+ appid, pid, LifecycleStateToString(state),
+ has_focus ? "true" : "false");
+ }
+};
+
+AUL_TEST_REGISTER(AulAppLifecycleRegisterStateChangedCbTest,
+ listen_app_lifecycle_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulDisableAliasInfoTest : public AulTest {
+ public:
+ AulDisableAliasInfoTest()
+ : AulTest("disable_alias_info", "aul_disable_alias_info",
+ "disable_alias_info <appid>") {}
+
+ virtual ~AulDisableAliasInfoTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_disable_alias_info test] %s", argv[2]);
+ return aul_disable_alias_info(argv[2]);
+ }
+};
+
+AUL_TEST_REGISTER(AulDisableAliasInfoTest, disable_alias_info_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulEnableAliasInfoTest : public AulTest {
+ public:
+ AulEnableAliasInfoTest()
+ : AulTest("enable_alias_info", "aul_enable_alias_info",
+ "enable_alias_info <appid>") {}
+
+ virtual ~AulEnableAliasInfoTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_enable_alias_info test] %s", argv[2]);
+ return aul_enable_alias_info(argv[2]);
+ }
+};
+
+AUL_TEST_REGISTER(AulEnableAliasInfoTest, enable_alias_info_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "menu_db_util.h"
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulGetAppInfoFromDbByPkgnameTest : public AulTest {
+ public:
+ AulGetAppInfoFromDbByPkgnameTest()
+ : AulTest("getpkg", "aul_get_app_info_from_db_by_pkgname",
+ "getpkg <appid>") {}
+
+ virtual ~AulGetAppInfoFromDbByPkgnameTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_get_app_info_from_db_by_pkgname test] %s", argv[2]);
+ app_info_from_db* info = _get_app_info_from_db_by_pkgname(argv[2]);
+ if (info == nullptr) {
+ _E("pkg %s no found", argv[2]);
+ return 0;
+ }
+
+ _D("\t==========================");
+ _D("\t appid: %s", info->appid);
+ _D("\t app_path: %s", info->app_path);
+ _D("\t is_minst: 0");
+ _D("\t==========================");
+ _free_app_info_from_db(info);
+ return 0;
+ }
+};
+
+AUL_TEST_REGISTER(AulGetAppInfoFromDbByPkgnameTest, getpkg_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulGetDefappFromMimeTest : public AulTest {
+ public:
+ AulGetDefappFromMimeTest()
+ : AulTest("get_defapp_mime", "aul_get_defapp_from_mime",
+ "get_defapp_mime <mime_type>") {}
+
+ virtual ~AulGetDefappFromMimeTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_get_defapp_from_mime test] %s", argv[2]);
+ char buf[256] = { 0, };
+ int ret = aul_get_defapp_from_mime(argv[2], buf, sizeof(buf));
+ if (ret == AUL_R_OK)
+ _D("==> defapp name = %s", buf);
+
+ return ret;
+ }
+};
+
+AUL_TEST_REGISTER(AulGetDefappFromMimeTest, get_defapp_mime_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+#include "include/aul_svc.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulGetDefaultAppTest : public AulTest {
+ public:
+ AulGetDefaultAppTest()
+ : AulTest("get_default_app", "aul_get_default_app",
+ "get_default_app <operation> <uri> <mime>") {}
+
+ virtual ~AulGetDefaultAppTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_get_default_app test] %s %s %s",
+ argv[2], argc > 3 ? argv[3] : "null", argc > 4 ? argv[4] : "null");
+
+ bundle* b = bundle_create();
+ if (b == nullptr) {
+ _E("bundle_create() is failed");
+ return -ENOMEM;
+ }
+
+ aul_svc_set_operation(b, argv[2]);
+ if (argc > 3)
+ aul_svc_set_uri(b, argv[3]);
+ if (argc > 4)
+ aul_svc_set_mime(b, argv[4]);
+
+ char* appid = nullptr;
+ int ret = aul_get_default_app(b, &appid);
+ bundle_free(b);
+ _D("result: %s", appid);
+ free(appid);
+ return ret;
+ }
+};
+
+AUL_TEST_REGISTER(AulGetDefaultAppTest, get_default_app_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulGetMimeDescriptionTest : public AulTest {
+ public:
+ AulGetMimeDescriptionTest()
+ : AulTest("get_mime_desc", "aul_get_mime_description",
+ "get_mime_desc <mimetype>") {}
+
+ virtual ~AulGetMimeDescriptionTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_get_mime_description test] %s", argv[2]);
+ char buf[256] = { 0, };
+ int ret = aul_get_mime_description(argv[2], buf, sizeof(buf));
+ if (ret == AUL_R_OK)
+ _D("==> mime type = %s : description = %s", argv[2], buf);
+
+ return ret;
+ }
+};
+
+AUL_TEST_REGISTER(AulGetMimeDescriptionTest, get_mime_desc_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulGetMimeExtensionTest : public AulTest {
+ public:
+ AulGetMimeExtensionTest()
+ : AulTest("get_mime_ext", "aul_get_mime_extension",
+ "get_mime_ext <mimetype>") {}
+
+ virtual ~AulGetMimeExtensionTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_get_mime_extension test] %s", argv[2]);
+ char buf[256] = { 0, };
+ int ret = aul_get_mime_extension(argv[2], buf, sizeof(buf));
+ if (ret == AUL_R_OK)
+ _D("==> mime type = %s : extension = %s", argv[2], buf);
+
+ return ret;
+ }
+};
+
+AUL_TEST_REGISTER(AulGetMimeExtensionTest, get_mime_ext_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulGetMimeFromContentTest : public AulTest {
+ public:
+ AulGetMimeFromContentTest()
+ : AulTest("get_mime_content", "aul_get_mime_from_content",
+ "get_mime_content <content>") {}
+
+ virtual ~AulGetMimeFromContentTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_get_mime_from_content test] %s", argv[2]);
+ char buf[256] = { 0, };
+ int ret = aul_get_mime_from_content(argv[2], buf, sizeof(buf));
+ if (ret == AUL_R_OK)
+ _D("==> mime type = %s", buf);
+
+ return ret;
+ }
+};
+
+AUL_TEST_REGISTER(AulGetMimeFromContentTest, get_mime_content_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulGetMimeFromFileTest : public AulTest {
+ public:
+ AulGetMimeFromFileTest()
+ : AulTest("get_mime_file", "aul_get_mime_from_file",
+ "get_mime_file <filename>") {}
+
+ virtual ~AulGetMimeFromFileTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_get_mime_from_file test] %s", argv[2]);
+ char buf[256] = { 0, };
+ int ret = aul_get_mime_from_file(argv[2], buf, sizeof(buf));
+ if (ret == AUL_R_OK)
+ _D("==> mime type = %s", buf);
+
+ return ret;
+ }
+};
+
+AUL_TEST_REGISTER(AulGetMimeFromFileTest, get_mime_file_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulGetMimeIconTest : public AulTest {
+ public:
+ AulGetMimeIconTest()
+ : AulTest("get_mime_icon", "aul_get_mime_icon",
+ "get_mime_icon <mimetype>") {}
+
+ virtual ~AulGetMimeIconTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_get_mime_icon test] %s", argv[2]);
+ char buf[256] = { 0, };
+ int ret = aul_get_mime_icon(argv[2], buf, sizeof(buf));
+ if (ret == AUL_R_OK)
+ _D("==> mime type = %s : iconname = %s", argv[2], buf);
+
+ return ret;
+ }
+};
+
+AUL_TEST_REGISTER(AulGetMimeIconTest, get_mime_icon_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2023 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 <stdlib.h>
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulKillLoaderTest : public AulTest {
+ public:
+ AulKillLoaderTest()
+ : AulTest("kill_loader", "aul_kill_loader", "kill_loader <loader_name>") {
+ }
+
+ virtual ~AulKillLoaderTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_kill_loader test] %s", argv[2]);
+ return aul_kill_loader(argv[2]);
+ }
+};
+
+AUL_TEST_REGISTER(AulKillLoaderTest, kill_loader_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2023 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 <stdlib.h>
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulKillPidAsyncTest : public AulTest {
+ public:
+ AulKillPidAsyncTest()
+ : AulTest("kill_pid_async", "aul_kill_pid_async",
+ "kill_pid_async <pid>", false) {}
+
+ virtual ~AulKillPidAsyncTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_kill_pid_async test] %s", argv[2]);
+ return aul_kill_pid_async(atoi(argv[2]), AulResultCb, this);
+ }
+
+ private:
+ static void AulResultCb(int result, void* user_data) {
+ _D("Result: %d", result);
+ }
+};
+
+AUL_TEST_REGISTER(AulKillPidAsyncTest, kill_pid_async_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulLaunchAppAsyncForUidTest : public AulTest {
+ public:
+ AulLaunchAppAsyncForUidTest()
+ : AulTest("launch_async_for_uid", "aul_launch_app_async_for_uid",
+ "launch_async_for_uid <appid> <uid> <key1> <val1> ...") {}
+
+ virtual ~AulLaunchAppAsyncForUidTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 4) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_launch_app_async_for_uid test] %s %s", argv[2], argv[3]);
+ tizen_base::Bundle b = CreateBundleFromArgv(argc, argv, 4);
+ return aul_launch_app_async_for_uid(argv[2], b.GetHandle(), atoi(argv[3]));
+ }
+};
+
+AUL_TEST_REGISTER(AulLaunchAppAsyncForUidTest, launch_async_for_uid_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulLaunchAppAsyncTest : public AulTest {
+ public:
+ AulLaunchAppAsyncTest()
+ : AulTest("launch_async", "aul_launch_app_async",
+ "launch_async <appid> <key1> <val1> <key2> <val2> ...") {}
+
+ virtual ~AulLaunchAppAsyncTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_launch_app_async test] %s", argv[2]);
+ tizen_base::Bundle b = CreateBundleFromArgv(argc, argv, 3);
+ return aul_launch_app_async(argv[2], b.GetHandle());
+ }
+};
+
+AUL_TEST_REGISTER(AulLaunchAppAsyncTest, launch_async_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulLaunchAppForUidTest : public AulTest {
+ public:
+ AulLaunchAppForUidTest()
+ : AulTest("launch_for_uid", "aul_launch_app_for_uid",
+ "launch_for_uid <app_id> <uid> <key1> <val1> ...") {}
+
+ virtual ~AulLaunchAppForUidTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 4) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_launch_app_for_uid test] %s %s", argv[2], argv[3]);
+ tizen_base::Bundle b = CreateBundleFromArgv(argc, argv, 4);
+ return aul_launch_app_for_uid(argv[2], b.GetHandle(), atoi(argv[3]));
+ }
+};
+
+AUL_TEST_REGISTER(AulLaunchAppForUidTest, launch_for_uid_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulLaunchAppTest : public AulTest {
+ public:
+ AulLaunchAppTest()
+ : AulTest("launch", "aul_launch_app",
+ "launch <app_id> <key1> <val1> <key2> <val2> ...") {}
+
+ virtual ~AulLaunchAppTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_launch_app test] %s", argv[2]);
+ tizen_base::Bundle b = CreateBundleFromArgv(argc, argv, 3);
+ return aul_launch_app(argv[2], b.GetHandle());
+ }
+};
+
+AUL_TEST_REGISTER(AulLaunchAppTest, launch_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulListenAppDeadSignalTest : public AulTest {
+ public:
+ AulListenAppDeadSignalTest()
+ : AulTest("listen_app_dead_signal", "aul_listen_app_dead_signal",
+ "listen_app_dead_signal", false) {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ _D("[aul_listen_app_dead_signal test]");
+ return aul_listen_app_dead_signal(AppDeadEventCb, this);
+ }
+
+ private:
+ static int AppDeadEventCb(int pid, void* user_data) {
+ _D("pid(%d) is dead", pid);
+ return 0;
+ }
+};
+
+AUL_TEST_REGISTER(AulListenAppDeadSignalTest, listen_app_dead_signal_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulListenAppLaunchSignalTest : public AulTest {
+ public:
+ AulListenAppLaunchSignalTest()
+ : AulTest("listen_app_launch_signal", "aul_listen_app_launch_signal",
+ "listen_app_launch_signal", false) {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ _D("[aul_listen_app_launch_signal test]");
+ return aul_listen_app_launch_signal(AppLaunchEventCb, this);
+ }
+
+ private:
+ static int AppLaunchEventCb(int pid, void* user_data) {
+ _D("pid(%d) is launched", pid);
+ return 0;
+ }
+};
+
+AUL_TEST_REGISTER(AulListenAppLaunchSignalTest, listen_app_launch_signal_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulListenAppLaunchSignalV2Test : public AulTest {
+ public:
+ AulListenAppLaunchSignalV2Test()
+ : AulTest("listen_app_launch_signal_v2",
+ "aul_listen_app_launch_signal_v2",
+ "listen_app_launch_signal_v2", false) {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ _D("[aul_listen_app_launch_signal_v2 test]");
+ return aul_listen_app_launch_signal_v2(AppLaunchEventCb, this);
+ }
+
+ private:
+ static int AppLaunchEventCb(int pid, const char* appid, void* user_data) {
+ _D("pid(%d) is launched. appid(%s)", pid, appid);
+ return 0;
+ }
+};
+
+AUL_TEST_REGISTER(AulListenAppLaunchSignalV2Test,
+ listen_app_launch_signal_v2_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulListenAppStatusForUidTest : public AulTest {
+ public:
+ AulListenAppStatusForUidTest()
+ : AulTest("listen_app_status_for_uid", "aul_listen_app_status_for_uid",
+ "listen_app_status_for_uid <appid> <uid>", false) {}
+
+ virtual ~AulListenAppStatusForUidTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 4) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_listen_app_status_for_uid test] %s %s", argv[2], argv[3]);
+ return aul_listen_app_status_for_uid(argv[2], AppStatusCb, this, &handle_,
+ atoi(argv[3]));
+ }
+
+ private:
+ static int AppStatusCb(aul_app_info* info, int ctx_status, void* user_data) {
+ _D("appid: %s, status: %d", info->appid, ctx_status);
+ return 0;
+ }
+
+ status_listen_h handle_ = nullptr;
+};
+
+AUL_TEST_REGISTER(AulListenAppStatusForUidTest, listen_app_status_for_uid_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulListenAppStatusSignalTest : public AulTest {
+ public:
+ AulListenAppStatusSignalTest()
+ : AulTest("listen_app_status_signal", "aul_listen_app_status_signal",
+ "listen_app_status_signal", false) {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ _D("[aul_listen_app_status_signal test]");
+ return aul_listen_app_status_signal(AppStatusEventCb, this);
+ }
+
+ private:
+ static const char* GetStatusString(int status) {
+ const char* status_str;
+ switch (status) {
+ case AUL_PROC_STATUS_LAUNCH:
+ status_str = "LAUNCH";
+ break;
+ case AUL_PROC_STATUS_FG:
+ status_str = "FG";
+ break;
+ case AUL_PROC_STATUS_BG:
+ status_str = "BG";
+ break;
+ case AUL_PROC_STATUS_FOCUS:
+ status_str = "FOCUS";
+ break;
+ case AUL_PROC_STATUS_HIDE:
+ status_str = "HIDE";
+ break;
+ default:
+ status_str = "UNKNOWN";
+ break;
+ }
+
+ return status_str;
+ }
+
+ static int AppStatusEventCb(int pid, int status, void* user_data) {
+ _D("pid: %d, status: %d(%s)", pid, status, GetStatusString(status));
+ return 0;
+ }
+};
+
+AUL_TEST_REGISTER(AulListenAppStatusSignalTest, listen_app_status_signal_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulListenAppStatusTest : public AulTest {
+ public:
+ AulListenAppStatusTest()
+ : AulTest("listen_app_status", "aul_listen_app_status",
+ "listen_app_status <appid>", false) {}
+
+ virtual ~AulListenAppStatusTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_listen_app_status test] %s", argv[2]);
+ return aul_listen_app_status(argv[2], AppStatusCb, this, &handle_);
+ }
+
+ private:
+ static int AppStatusCb(aul_app_info* info, int ctx_status, void* user_data) {
+ _D("appid: %s, status: %d", info->appid, ctx_status);
+ return 0;
+ }
+
+ status_listen_h handle_ = nullptr;
+};
+
+AUL_TEST_REGISTER(AulListenAppStatusTest, listen_app_status_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulOpenAppForUidTest : public AulTest {
+ public:
+ AulOpenAppForUidTest()
+ : AulTest("open_for_uid", "aul_open_app_for_uid",
+ "open_for_uid <appid> <uid>") {}
+
+ virtual ~AulOpenAppForUidTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 4) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_open_app_for_uid test] %s %s", argv[2], argv[3]);
+ return aul_open_app_for_uid(argv[2], atoi(argv[3]));
+ }
+};
+
+AUL_TEST_REGISTER(AulOpenAppForUidTest, open_for_uid_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulOpenAppTest : public AulTest {
+ public:
+ AulOpenAppTest() : AulTest("open", "aul_open_app", "open <appid>") {}
+
+ virtual ~AulOpenAppTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_open_app test] %s", argv[2]);
+ return aul_open_app(argv[2]);
+ }
+};
+
+AUL_TEST_REGISTER(AulOpenAppTest, open_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulOpenContentTest : public AulTest {
+ public:
+ AulOpenContentTest()
+ : AulTest("open_content", "aul_open_content", "open_content <content>") {}
+
+ virtual ~AulOpenContentTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_open_content test] %s", argv[2]);
+ return aul_open_content(argv[2]);
+ }
+};
+
+AUL_TEST_REGISTER(AulOpenContentTest, open_content_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulOpenFileTest : public AulTest {
+ public:
+ AulOpenFileTest()
+ : AulTest("open_file", "aul_open_file", "open_file <filename>") {}
+
+ virtual ~AulOpenFileTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_open_file test] %s", argv[2]);
+ return aul_open_file(argv[2]);
+ }
+};
+
+AUL_TEST_REGISTER(AulOpenFileTest, open_file_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulPauseAppForUidTest : public AulTest {
+ public:
+ AulPauseAppForUidTest()
+ : AulTest("pause_for_uid", "aul_pause_app_for_uid",
+ "pause_for_uid <appid> <uid>") {}
+
+ virtual ~AulPauseAppForUidTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 4) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_pause_app_for_uid test] %s %s", argv[2], argv[3]);
+ return aul_pause_app_for_uid(argv[2], atoi(argv[3]));
+ }
+};
+
+AUL_TEST_REGISTER(AulPauseAppForUidTest, pause_for_uid_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulPauseAppTest : public AulTest {
+ public:
+ AulPauseAppTest() : AulTest("pause", "aul_pause_app", "pause <app_id>") {}
+
+ virtual ~AulPauseAppTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_pause_app test] %s", argv[2]);
+ return aul_pause_app(argv[2]);
+ }
+};
+
+AUL_TEST_REGISTER(AulPauseAppTest, pause_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulPausePidForUidTest : public AulTest {
+ public:
+ AulPausePidForUidTest()
+ : AulTest("pause_pid_for_uid", "aul_pause_pid_for_uid",
+ "pause_pid_for_uid <pid> <uid>") {}
+
+ virtual ~AulPausePidForUidTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 4) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_pause_pid_for_uid test] %s %s", argv[2], argv[3]);
+ return aul_pause_pid_for_uid(atoi(argv[2]), atoi(argv[3]));
+ }
+};
+
+AUL_TEST_REGISTER(AulPausePidForUidTest, pause_pid_for_uid_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulPausePidTest : public AulTest {
+ public:
+ AulPausePidTest()
+ : AulTest("pause_pid", "aul_pause_pid", "pause_pid <pid>") {}
+
+ virtual ~AulPausePidTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_pause_pid test] %s", argv[2]);
+ return aul_pause_pid(atoi(argv[2]));
+ }
+};
+
+AUL_TEST_REGISTER(AulPausePidTest, pause_pid_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+#include "include/aul_proc.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulProcGetExtraTest : public AulTest {
+ public:
+ AulProcGetExtraTest()
+ : AulTest("get_proc_extra", "aul_proc_get_extra",
+ "get_proc_extra <pid>") {}
+
+ virtual ~AulProcGetExtraTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_proc_get_extra test] %s", argv[2]);
+ bundle* extra = nullptr;
+ int ret = aul_proc_get_extra(atoi(argv[2]), &extra);
+ if (ret == AUL_R_OK)
+ _D("==> result: %d", ret);
+
+ if (extra) {
+ bundle_foreach(extra, ForeachExtraCb, nullptr);
+ bundle_free(extra);
+ }
+
+ return ret;
+ }
+
+ private:
+ static void ForeachExtraCb(const char *key, const int type,
+ const bundle_keyval_t* kb, void* user_data) {
+ _D("key: %s, type: %d", key, type);
+ }
+};
+
+AUL_TEST_REGISTER(AulProcGetExtraTest, get_proc_extra_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+#include "include/aul_proc.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulProcGetNameTest : public AulTest {
+ public:
+ AulProcGetNameTest()
+ : AulTest("get_proc_name", "aul_proc_get_name", "get_proc_name <pid>") {}
+
+ virtual ~AulProcGetNameTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_proc_get_name test] %s", argv[2]);
+ char* name = nullptr;
+ int ret = aul_proc_get_name(atoi(argv[2]), &name);
+ if (ret == AUL_R_OK)
+ _D("==> result: %d, name: %s", ret, name);
+
+ free(name);
+ return ret;
+ }
+};
+
+AUL_TEST_REGISTER(AulProcGetNameTest, get_proc_name_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+#include "include/aul_proc_group.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulProcGroupAddTest : public AulTest {
+ public:
+ AulProcGroupAddTest()
+ : AulTest("add_proc_group", "aul_proc_group_add",
+ "add_proc_group <pid>") {}
+
+ virtual ~AulProcGroupAddTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_proc_group_add test] %s", argv[2]);
+ return aul_proc_group_add(atoi(argv[2]));
+ }
+};
+
+AUL_TEST_REGISTER(AulProcGroupAddTest, add_proc_group_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+#include "include/aul_proc_group.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulProcGroupForeachTest : public AulTest {
+ public:
+ AulProcGroupForeachTest()
+ : AulTest("foreach_proc_group", "aul_proc_group_foreach",
+ "foreach_proc_group") {}
+
+ virtual ~AulProcGroupForeachTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ _D("[aul_proc_group_foreach test]");
+ return aul_proc_group_foreach(AulProcGroupCb, this);
+ }
+
+ static void AulProcGroupCb(aul_proc_group_info_h info, void* user_data) {
+ pid_t leader_pid = -1;
+ aul_proc_group_info_get_leader_pid(info, &leader_pid);
+ const pid_t* sub_pids = nullptr;
+ size_t length = 0;
+ aul_proc_group_info_get_sub_pids(info, &sub_pids, &length);
+
+ _D("[GROUP]");
+ _D(" - Leader: %d", leader_pid);
+ for (size_t i = 0; i < length; ++i)
+ _D(" - Sub: %d", sub_pids[i]);
+ }
+};
+
+AUL_TEST_REGISTER(AulProcGroupForeachTest, foreach_proc_group_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+#include "include/aul_proc_group.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulProcGroupGetTest : public AulTest {
+ public:
+ AulProcGroupGetTest()
+ : AulTest("get_proc_group", "aul_proc_group_get",
+ "get_proc_group <pid>") {}
+
+ virtual ~AulProcGroupGetTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_proc_group_get test] %s", argv[2]);
+ aul_proc_group_info_h info = nullptr;
+ int ret = aul_proc_group_get(atoi(argv[2]), &info);
+ if (ret != AUL_R_OK)
+ return ret;
+
+ pid_t leader_pid = -1;
+ aul_proc_group_info_get_leader_pid(info, &leader_pid);
+ const pid_t* sub_pids = nullptr;
+ size_t length = 0;
+ aul_proc_group_info_get_sub_pids(info, &sub_pids, &length);
+
+ _D("[GROUP]");
+ _D(" - Leader: %d", leader_pid);
+ for (size_t i = 0; i < length; ++i)
+ _D(" - Sub: %d", sub_pids[i]);
+
+ return aul_proc_group_info_destroy(info);
+ }
+};
+
+AUL_TEST_REGISTER(AulProcGroupGetTest, get_proc_group_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+#include "include/aul_proc_group.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulProcGroupRemoveTest : public AulTest {
+ public:
+ AulProcGroupRemoveTest()
+ : AulTest("remove_proc_group", "aul_proc_group_remove",
+ "remove_proc_group <pid>") {}
+
+ virtual ~AulProcGroupRemoveTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_proc_group_remove test] %s", argv[2]);
+ return aul_proc_group_remove(atoi(argv[2]));
+ }
+};
+
+AUL_TEST_REGISTER(AulProcGroupRemoveTest, remove_proc_group_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+#include "include/aul_proc.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulProcRegisterTest : public AulTest {
+ public:
+ AulProcRegisterTest()
+ : AulTest("register_proc", "aul_proc_register",
+ "register_proc <name> <key1> <value1> <key2> <value2> ...") {}
+
+ virtual ~AulProcRegisterTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ tizen_base::Bundle b;
+ bundle* extra = nullptr;
+ if (argc > 3) {
+ b = CreateBundleFromArgv(argc, argv, 3);
+ extra = b.GetHandle();
+ }
+
+ _D("[aul_proc_register] %s", argv[2]);
+ int ret = aul_proc_register(argv[2], extra);
+ _D("result: %d", ret);
+ if (ret != AUL_R_OK)
+ return ret;
+
+ _D("[aul_proc_get_name] %d", getpid());
+ char* name = nullptr;
+ ret = aul_proc_get_name(getpid(), &name);
+ _D("result: %d, name: %s", ret, name);
+ free(name);
+
+ _D("[aul_proc_get_extra] %d", getpid());
+ extra = nullptr;
+ ret = aul_proc_get_extra(getpid(), &extra);
+ _D("result: %d", ret);
+ if (extra) {
+ bundle_foreach(extra, ForeachExtraCb, nullptr);
+ bundle_free(extra);
+ }
+
+ return ret;
+ }
+
+ private:
+ static void ForeachExtraCb(const char *key, const int type,
+ const bundle_keyval_t* kb, void* user_data) {
+ _D("key: %s, type: %d", key, type);
+ }
+};
+
+AUL_TEST_REGISTER(AulProcRegisterTest, register_proc_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulReloadAppinfoTest : public AulTest {
+ public:
+ AulReloadAppinfoTest() : AulTest("reload", "aul_reload_appinfo", "reload") {}
+
+ virtual ~AulReloadAppinfoTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ return aul_reload_appinfo();
+ }
+};
+
+AUL_TEST_REGISTER(AulReloadAppinfoTest, reload_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2023 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 <stdlib.h>
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulRestartLoaderTest : public AulTest {
+ public:
+ AulRestartLoaderTest()
+ : AulTest("restart_loader", "aul_restart_loader",
+ "restart_loader <loader_name>") {
+ }
+
+ virtual ~AulRestartLoaderTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_restart_loader test] %s", argv[2]);
+ return aul_restart_loader(argv[2]);
+ }
+};
+
+AUL_TEST_REGISTER(AulRestartLoaderTest, restart_loader_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulResumeAppForUidTest : public AulTest {
+ public:
+ AulResumeAppForUidTest()
+ : AulTest("resume_for_uid", "aul_resume_app_for_uid",
+ "resume_for_uid <appid> <uid>") {}
+
+ virtual ~AulResumeAppForUidTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 4) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_resume_app_for_uid test] %s %s", argv[2], argv[3]);
+ return aul_resume_app_for_uid(argv[2], atoi(argv[3]));
+ }
+};
+
+AUL_TEST_REGISTER(AulResumeAppForUidTest, resume_for_uid_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulResumeAppTest : public AulTest {
+ public:
+ AulResumeAppTest() : AulTest("resume", "aul_resume_app", "resume <appid>") {}
+
+ virtual ~AulResumeAppTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_resume_app test] %s", argv[2]);
+ return aul_resume_app(argv[2]);
+ }
+};
+
+AUL_TEST_REGISTER(AulResumeAppTest, resume_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 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 <stdlib.h>
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulResumePidAsyncForUidTest : public AulTest {
+ public:
+ AulResumePidAsyncForUidTest()
+ : AulTest("resume_pid_async_for_uid", "aul_resume_pid_async_for_uid",
+ "resume_pid_async_for_uid <pid> <uid>") {}
+
+ virtual ~AulResumePidAsyncForUidTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 4) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_resume_pid_async_for_uid test] %s %s", argv[2], argv[3]);
+ return aul_resume_pid_async_for_uid(atoi(argv[2]), atoi(argv[3]));
+ }
+};
+
+AUL_TEST_REGISTER(AulResumePidAsyncForUidTest, resume_pid_async_for_uid_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 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 <stdlib.h>
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulResumePidAsyncTest : public AulTest {
+ public:
+ AulResumePidAsyncTest()
+ : AulTest("resume_pid_async", "aul_resume_pid_async",
+ "resume_pid_async <pid>") {}
+
+ virtual ~AulResumePidAsyncTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_resume_pid_async test] %s", argv[2]);
+ return aul_resume_pid_async(atoi(argv[2]));
+ }
+};
+
+AUL_TEST_REGISTER(AulResumePidAsyncTest, resume_pid_async_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 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 <stdlib.h>
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulResumePidForUidTest : public AulTest {
+ public:
+ AulResumePidForUidTest()
+ : AulTest("resume_pid_for_uid", "aul_resume_pid_for_uid",
+ "resume_pid_for_uid <pid> <uid>") {}
+
+ virtual ~AulResumePidForUidTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 4) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_resume_pid_for_uid test] %s %s", argv[2], argv[3]);
+ return aul_resume_pid_for_uid(atoi(argv[2]), atoi(argv[3]));
+ }
+};
+
+AUL_TEST_REGISTER(AulResumePidForUidTest, resume_pid_for_uid_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 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 <stdlib.h>
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulResumePidTest : public AulTest {
+ public:
+ AulResumePidTest()
+ : AulTest("resume_pid", "aul_resume_pid", "resume_pid <pid>") {}
+
+ virtual ~AulResumePidTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_resume_pid test] %s", argv[2]);
+ return aul_resume_pid(atoi(argv[2]));
+ }
+};
+
+AUL_TEST_REGISTER(AulResumePidTest, resume_pid_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulSetAliasAppidTest : public AulTest {
+ public:
+ AulSetAliasAppidTest()
+ : AulTest("set_alias_appid", "aul_set_alias_appid",
+ "set_alias_appid <alias_appid> <appid>") {}
+
+ virtual ~AulSetAliasAppidTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 4) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_set_alias_appid test] %s %s", argv[2], argv[3]);
+ return aul_set_alias_appid(argv[2], argv[3]);
+ }
+};
+
+AUL_TEST_REGISTER(AulSetAliasAppidTest, set_alias_appid_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulSetDefappWithMimeTest : public AulTest {
+ public:
+ AulSetDefappWithMimeTest()
+ : AulTest("set_defapp_mime", "aul_set_defapp_with_mime",
+ "set_defapp_mime <mimetype> <appid>") {}
+
+ virtual ~AulSetDefappWithMimeTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 4) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_set_defapp_with_mime test] %s %s", argv[2], argv[3]);
+ return aul_set_defapp_with_mime(argv[2], argv[3]);
+ }
+};
+
+AUL_TEST_REGISTER(AulSetDefappWithMimeTest, set_defapp_mime_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+#include "include/aul_svc.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulSetDefaultAppByOperationTest : public AulTest {
+ public:
+ AulSetDefaultAppByOperationTest()
+ : AulTest("set_default_app_by_operation",
+ "aul_set_default_app_by_operation",
+ "set_default_app_by_operation <operation> <appid>") {}
+
+ virtual ~AulSetDefaultAppByOperationTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 4) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_set_default_app_by_operation test] %s %s", argv[2], argv[3]);
+ bundle* b = bundle_create();
+ if (b == nullptr) {
+ _E("bundle_create() is failed");
+ return -ENOMEM;
+ }
+
+ aul_svc_set_operation(b, argv[2]);
+ aul_svc_set_appid(b, argv[3]);
+ int ret = aul_set_default_app_by_operation(b);
+ bundle_free(b);
+ return ret;
+ }
+};
+
+AUL_TEST_REGISTER(AulSetDefaultAppByOperationTest,
+ set_default_app_by_operation_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 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 <stdlib.h>
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulSubappTerminateRequestPidTest : public AulTest {
+ public:
+ AulSubappTerminateRequestPidTest()
+ : AulTest("term_req_pid", "aul_subapp_terminate_request_pid",
+ "term_req_pid <pid>") {}
+
+ virtual ~AulSubappTerminateRequestPidTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_subapp_terminate_request_pid test] %s", argv[2]);
+ return aul_subapp_terminate_request_pid(atoi(argv[2]));
+ }
+};
+
+AUL_TEST_REGISTER(AulSubappTerminateRequestPidTest, term_req_pid_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2023 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 <stdlib.h>
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulTerminateAppAsyncTest : public AulTest {
+ public:
+ AulTerminateAppAsyncTest()
+ : AulTest("terminate_app_async", "aul_terminate_app_async",
+ "terminate_app_async <appid>", false) {}
+
+ virtual ~AulTerminateAppAsyncTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_terminate_app_async test] %s", argv[2]);
+ return aul_terminate_app_async(argv[2], AulResultCb, this);
+ }
+
+ private:
+ static void AulResultCb(int result, void* user_data) {
+ _D("Result: %d", result);
+ }
+};
+
+AUL_TEST_REGISTER(AulTerminateAppAsyncTest, terminate_app_async_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 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 <stdlib.h>
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulTerminateBgappPidTest : public AulTest {
+ public:
+ AulTerminateBgappPidTest()
+ : AulTest("term_bgapp", "aul_terminate_bgapp_pid", "term_bgapp <pid>") {}
+
+ virtual ~AulTerminateBgappPidTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_terminate_bgapp_pid test] %s", argv[2]);
+ return aul_terminate_bgapp_pid(atoi(argv[2]));
+ }
+};
+
+AUL_TEST_REGISTER(AulTerminateBgappPidTest, term_bgapp_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 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 <stdlib.h>
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulTerminatePidAsyncForUidTest : public AulTest {
+ public:
+ AulTerminatePidAsyncForUidTest()
+ : AulTest("term_pid_async_for_uid", "aul_terminate_pid_async_for_uid",
+ "term_pid_async_for_uid <pid> <uid>") {}
+
+ virtual ~AulTerminatePidAsyncForUidTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 4) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_terminate_pid_async_for_uid test] %s %s", argv[2], argv[3]);
+ return aul_terminate_pid_async_for_uid(atoi(argv[2]), atoi(argv[3]));
+ }
+};
+
+AUL_TEST_REGISTER(AulTerminatePidAsyncForUidTest, term_pid_async_for_uid_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2023 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 <stdlib.h>
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulTerminatePidAsyncV2Test : public AulTest {
+ public:
+ AulTerminatePidAsyncV2Test()
+ : AulTest("terminate_pid_async_v2", "aul_terminate_pid_async_v2",
+ "terminate_pid_async_v2 <pid>", false) {}
+
+ virtual ~AulTerminatePidAsyncV2Test() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_terminate_pid_async_v2 test] %s", argv[2]);
+ return aul_terminate_pid_async_v2(atoi(argv[2]), AulResultCb, this);
+ }
+
+ private:
+ static void AulResultCb(int result, void* user_data) {
+ _D("Result: %d", result);
+ }
+};
+
+AUL_TEST_REGISTER(AulTerminatePidAsyncV2Test, terminate_pid_async_v2_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 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 <stdlib.h>
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulTerminatePidForUidTest : public AulTest {
+ public:
+ AulTerminatePidForUidTest()
+ : AulTest("term_pid_for_uid", "aul_terminate_pid_for_uid",
+ "term_pid_for_uid <pid> <uid>") {}
+
+ virtual ~AulTerminatePidForUidTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 4) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_terminate_pid_for_uid test] %s %s", argv[2], argv[3]);
+ return aul_terminate_pid_for_uid(atoi(argv[2]), atoi(argv[3]));
+ }
+};
+
+AUL_TEST_REGISTER(AulTerminatePidForUidTest, term_pid_for_uid_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 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 <stdlib.h>
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulTerminatePidSyncForUidTest : public AulTest {
+ public:
+ AulTerminatePidSyncForUidTest()
+ : AulTest("term_pid_sync_for_uid", "aul_terminate_pid_sync_for_uid",
+ "term_pid_sync_for_uid <pid> <uid>") {}
+
+ virtual ~AulTerminatePidSyncForUidTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 4) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_terminate_pid_sync_for_uid test] %s %s", argv[2], argv[3]);
+ return aul_terminate_pid_sync_for_uid(atoi(argv[2]), atoi(argv[3]));
+ }
+};
+
+AUL_TEST_REGISTER(AulTerminatePidSyncForUidTest, term_pid_sync_for_uid_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 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 <stdlib.h>
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulTerminatePidSyncTest : public AulTest {
+ public:
+ AulTerminatePidSyncTest()
+ : AulTest("term_pid_sync", "aul_terminate_pid_sync",
+ "term_pid_sync <pid>") {}
+
+ virtual ~AulTerminatePidSyncTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_terminate_pid_sync test] %s", argv[2]);
+ return aul_terminate_pid_sync(atoi(argv[2]));
+ }
+};
+
+AUL_TEST_REGISTER(AulTerminatePidSyncTest, term_pid_sync_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 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 <stdlib.h>
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulTerminatePidTest : public AulTest {
+ public:
+ AulTerminatePidTest()
+ : AulTest("term_pid", "aul_terminate_pid", "term_pid <pid>") {}
+
+ virtual ~AulTerminatePidTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_terminate_pid test] %s", argv[2]);
+ return aul_terminate_pid(atoi(argv[2]));
+ }
+};
+
+AUL_TEST_REGISTER(AulTerminatePidTest, term_pid_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 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 <stdlib.h>
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulTerminatePidWithoutRestartTest : public AulTest {
+ public:
+ AulTerminatePidWithoutRestartTest()
+ : AulTest("term_pid_without_restart", "aul_terminate_pid_without_restart",
+ "term_pid_without_restart <pid>") {}
+
+ virtual ~AulTerminatePidWithoutRestartTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_terminate_pid_without_restart test] %s", argv[2]);
+ return aul_terminate_pid_without_restart(atoi(argv[2]));
+ }
+};
+
+AUL_TEST_REGISTER(AulTerminatePidWithoutRestartTest,
+ term_pid_without_restart_test);
+
+} // namespace aul_test
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulUnsetAliasAppidTest : public AulTest {
+ public:
+ AulUnsetAliasAppidTest()
+ : AulTest("unset_alias_appid", "aul_unset_alias_appid",
+ "unset_alias_appid <alias_appid>") {}
+
+ virtual ~AulUnsetAliasAppidTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_unset_alias_appid test] %s", argv[2]);
+ return aul_unset_alias_appid(argv[2]);
+ }
+};
+
+AUL_TEST_REGISTER(AulUnsetAliasAppidTest, unset_alias_appid_test);
+
+} // namespace aul_test
--- /dev/null
+SET(TARGET_AUL_WINDOW "aul_window")
+
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} AUL_WINDOW_SRCS)
+
+ADD_EXECUTABLE(${TARGET_AUL_WINDOW} ${AUL_WINDOW_SRCS})
+SET_TARGET_PROPERTIES(${TARGET_AUL_WINDOW} PROPERTIES
+ COMPILE_FLAGS ${CFLAGS} "-fPIE")
+SET_TARGET_PROPERTIES(${TARGET_AUL_WINDOW} PROPERTIES
+ LINK_FLAGS "-pie")
+TARGET_LINK_LIBRARIES(${TARGET_AUL_WINDOW} PRIVATE
+ ${TARGET_AUL})
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_AUL_WINDOW} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../
+ ${CMAKE_CURRENT_SOURCE_DIR}/../aul
+ ${CMAKE_CURRENT_SOURCE_DIR}/../aul/include)
+
+APPLY_PKG_CONFIG(${TARGET_AUL_WINDOW} PUBLIC
+ GLIB_DEPS
+)
+
+INSTALL(TARGETS ${TARGET_AUL_WINDOW} DESTINATION bin)
--- /dev/null
+/*
+ * Copyright (c) 2021 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 <aul.h>
+#include <aul_window.h>
+#include <glib.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <map>
+#include <string>
+
+namespace {
+
+using HandleFunc = int (*)(int argc, char** argv);
+
+void PrintUsage(const char* cmdline) {
+ printf("%s <command> ...\n", cmdline);
+ printf(" - command list\n");
+ printf(" foreach_window_stack\n");
+ printf(" get_focused_pid\n");
+ printf(" attach_window <parent_appid> <child_appid>\n");
+ printf(" detach_window <child_appid>\n");
+ printf(" attach_window_below <parent_appid> <child_appid>\n");
+ printf(" monitor_window_event\n");
+}
+
+const char* GetNotificationLevelString(aul_window_notification_level_e level) {
+ switch (level) {
+ case AUL_WINDOW_NOTIFICATION_LEVEL_DEFAULT:
+ return "AUL_WINDOW_NOTIFICATION_LEVEL_DEFAULT";
+ case AUL_WINDOW_NOTIFICATION_LEVEL_MEDIUM:
+ return "AUL_WINDOW_NOTIFICATION_LEVEL_MEDIUM";
+ case AUL_WINDOW_NOTIFICATION_LEVEL_HIGH:
+ return "AUL_WINDOW_NOTIFICATION_LEVEL_HIGH";
+ case AUL_WINDOW_NOTIFICATION_LEVEL_TOP:
+ return "AUL_WINDOW_NOTIFICATION_LEVEL_TOP";
+ case AUL_WINDOW_NOTIFICATION_LEVEL_PRIVILEGE:
+ return "AUL_WINDOW_NOTIFICATION_LEVEL_PRIVILEGE";
+ default:
+ return "AUL_WINDOW_NOTIFICATION_LEVEL_NONE";
+ }
+}
+
+void WindowStackIterCb(aul_window_info_h info, void* data) {
+ unsigned int rid = 0;
+ aul_window_stack_info_get_resource_id(info, &rid);
+ int pid = -1;
+ aul_window_info_get_pid(info, &pid);
+ int ppid = -1;
+ aul_window_info_get_parent_pid(info, &ppid);
+ int apid = -1;
+ aul_window_info_get_ancestor_pid(info, &apid);
+ int visibility = -1;
+ aul_window_info_get_visibility(info, &visibility);
+ bool has_alpha = false;
+ aul_window_info_has_alpha(info, &has_alpha);
+ bool is_focused = false;
+ aul_window_info_is_focused(info, &is_focused);
+ aul_window_notification_level_e level = AUL_WINDOW_NOTIFICATION_LEVEL_NONE;
+ aul_window_info_get_notification_level(info, &level);
+ int x = -1;
+ int y = -1;
+ int w = -1;
+ int h = -1;
+ aul_window_info_get_geometry(info, &x, &y, &w, &h);
+ bool opaque = false;
+ aul_window_info_get_opaque(info, &opaque);
+
+ printf("-----------------------------------------------------------------\n");
+ printf(" - Resource ID: %d\n", rid);
+ printf(" - Process ID: %d\n", pid);
+ printf(" - Parent Process ID: %d\n", ppid);
+ printf(" - Ancestor Process ID: %d\n", apid);
+ printf(" - Visibility: %d\n", visibility);
+ printf(" - Has Alpha: %s\n", has_alpha ? "true" : "false");
+ printf(" - Is Focused: %s\n", is_focused ? "true" : "false");
+ printf(" - Notification Level: %s\n", GetNotificationLevelString(level));
+ printf(" - Opaque: %s\n", opaque ? "true" : "false");
+}
+
+int HandleForeachWindowStack(int argc, char** argv) {
+ printf("[%s]\n", argv[1]);
+ aul_window_stack_h handle = nullptr;
+ int ret = aul_window_stack_get(&handle);
+ if (ret != AUL_R_OK) {
+ fprintf(stderr, "aul_window_stack() is failed. error(%d)\n", ret);
+ return ret;
+ }
+
+ printf("=================================================================\n");
+ ret = aul_window_stack_foreach(handle, WindowStackIterCb, nullptr);
+ printf("=================================================================\n");
+ aul_window_stack_del(handle);
+ printf("[%s] result: %d\n", argv[1], ret);
+ return ret;
+}
+
+int HandleGetFocusedPid(int argc, char** argv) {
+ printf("[%s]\n", argv[1]);
+ pid_t pid = -1;
+ int ret = aul_window_get_focused_pid(&pid);
+ printf("[%s] result: %d\n", argv[1], pid);
+ return ret;
+}
+
+int HandleAttachWindow(int argc, char** argv) {
+ if (argc < 4) {
+ PrintUsage(argv[0]);
+ return -1;
+ }
+
+ printf("[%s] parent_appid(%s), child_appid(%s)\n", argv[1], argv[2], argv[3]);
+ int ret = aul_window_attach(argv[2], argv[3]);
+ printf("[%s] result: %d\n", argv[1], ret);
+ return ret;
+}
+
+int HandleDetachWindow(int argc, char** argv) {
+ if (argc < 3) {
+ PrintUsage(argv[0]);
+ return -1;
+ }
+
+ printf("[%s] child_appid(%s)\n", argv[1], argv[2]);
+ int ret = aul_window_detach(argv[2]);
+ printf("[%s] result: %d\n", argv[1], ret);
+ return ret;
+}
+
+int HandleAttachWindowBelow(int argc, char** argv) {
+ if (argc < 4) {
+ PrintUsage(argv[0]);
+ return -1;
+ }
+
+ printf("[%s] parent_appid(%s), child_appid(%s)\n", argv[1], argv[2], argv[3]);
+ int ret = aul_window_attach_below(argv[2], argv[3]);
+ printf("[%s] result: %d\n", argv[1], ret);
+ return ret;
+}
+
+void WindowEventCb(const char* event_name, const char* appid, int wid, int pid,
+ void* user_data) {
+ printf("[Window Event]\n");
+ printf(" - Event_name: %s\n", event_name);
+ printf(" - Application ID: %s\n", appid);
+ printf(" - Window ID: %d\n", wid);
+ printf(" - Process ID: %d\n", pid);
+ printf("\n");
+}
+
+int HandleMonitorWindowEvent(int argc, char** argv) {
+ printf("[%s]\n", argv[1]);
+ int ret = aul_window_register_event_cb(WindowEventCb, nullptr);
+ printf("[%s] result: %d\n", argv[1], ret);
+ if (ret != AUL_R_OK)
+ return ret;
+
+ GMainLoop* loop = g_main_loop_new(nullptr, FALSE);
+ g_main_loop_run(loop);
+ g_main_loop_unref(loop);
+ return 0;
+}
+
+std::map<std::string, HandleFunc> handlers = {
+ { "foreach_window_stack", HandleForeachWindowStack },
+ { "get_focused_pid", HandleGetFocusedPid },
+ { "attach_window", HandleAttachWindow },
+ { "detach_window", HandleDetachWindow },
+ { "attach_window_below", HandleAttachWindowBelow },
+ { "monitor_window_event", HandleMonitorWindowEvent },
+};
+
+} // namespace
+
+int main(int argc, char** argv) {
+ if (argc < 2) {
+ PrintUsage(argv[0]);
+ return -1;
+ }
+
+ auto found = handlers.find(argv[1]);
+ if (found == handlers.end()) {
+ PrintUsage(argv[0]);
+ return -1;
+ }
+
+ return found->second(argc, argv);
+}
--- /dev/null
+SET(TARGET_AULCTL "aulctl")
+
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} AULCTL_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/boot_sequence BS_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/operation OP_SRCS)
+
+ADD_EXECUTABLE(${TARGET_AULCTL}
+ ${AULCTL_SRCS}
+ ${BS_SRCS}
+ ${OP_SRCS}
+)
+
+SET_TARGET_PROPERTIES(${TARGET_AULCTL} PROPERTIES
+ COMPILE_FLAGS ${CFLAGS} "-fPIE")
+SET_TARGET_PROPERTIES(${TARGET_AULCTL} PROPERTIES
+ LINK_FLAGS "-pie")
+TARGET_LINK_LIBRARIES(${TARGET_AULCTL} PRIVATE
+ ${TARGET_AUL}
+ ${TARGET_AUL_SERVER})
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_AULCTL} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../
+ ${CMAKE_CURRENT_SOURCE_DIR}/../aul
+ ${CMAKE_CURRENT_SOURCE_DIR}/../aul/include
+)
+
+APPLY_PKG_CONFIG(${TARGET_AULCTL} PUBLIC
+ GLIB_DEPS
+)
+
+INSTALL(TARGETS ${TARGET_AULCTL} DESTINATION bin)
--- /dev/null
+/*
+ * Copyright (c) 2022 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 <iostream>
+#include <vector>
+
+#include "operation/operation_factory.hh"
+
+int main(int argc, char* argv[]) {
+ std::vector<std::string> args(argv + 1, argv + argc);
+ aul::OperationFactory factory;
+ auto op = factory.CreateOperation(args);
+ if (op->Process() == false) {
+ std::cerr << "Failed operation." << std::endl;
+ exit(1);
+ }
+
+ return 0;
+}
--- /dev/null
+/*
+ * Copyright (c) 2022 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 "app_info.hh"
+
+#include <bundle_internal.h>
+
+#include "aul/aul_util.h"
+#include "aul/include/aul_key.h"
+
+namespace aul::internal {
+namespace boot_sequence {
+namespace {
+
+constexpr const char METADATA_KEY_ONBOOT_PRIORITY[] =
+ "http://tizen.org/metadata/on-boot/priority";
+constexpr const int MIN_PRIORITY = 1;
+constexpr const int MAX_PRIORITY = 99;
+constexpr const char K_BG_LAUNCH[] = "__K_BG_LAUNCH";
+constexpr const unsigned int DEFAULT_TIMEOUT = 5000;
+
+} // namespace
+
+AppInfo::Builder& AppInfo::Builder::SetAppId(const tizen_base::Bundle& args) {
+ appid_ = args.GetString(AUL_K_APPID);
+ return *this;
+}
+
+AppInfo::Builder& AppInfo::Builder::SetUid(const tizen_base::Bundle& args) {
+ uid_ = static_cast<uid_t>(std::stoi(args.GetString(AUL_K_TARGET_UID)));
+ return *this;
+}
+
+AppInfo::Builder& AppInfo::Builder::SetPriority(
+ const tizen_base::Bundle& args) {
+ priority_ = std::stoi(args.GetString(AUL_K_BOOT_SEQUENCE_PRIORITY));
+ return *this;
+}
+
+AppInfo::Builder& AppInfo::Builder::SetAfter(const tizen_base::Bundle& args) {
+ auto apps = args.GetStringArray(AUL_K_BOOT_SEQUENCE_AFTER);
+ after_.insert(apps.begin(), apps.end());
+ return *this;
+}
+
+AppInfo::Builder& AppInfo::Builder::SetBefore(const tizen_base::Bundle& args) {
+ auto apps = args.GetStringArray(AUL_K_BOOT_SEQUENCE_BEFORE);
+ before_.insert(apps.begin(), apps.end());
+ return *this;
+}
+
+AppInfo::Builder& AppInfo::Builder::SetRequires(
+ const tizen_base::Bundle& args) {
+ auto apps = args.GetStringArray(AUL_K_BOOT_SEQUENCE_REQUIRES);
+ requires_.insert(apps.begin(), apps.end());
+ return *this;
+}
+
+AppInfo::Builder& AppInfo::Builder::SetConflicts(
+ const tizen_base::Bundle& args) {
+ auto apps = args.GetStringArray(AUL_K_BOOT_SEQUENCE_CONFLICTS);
+ conflicts_.insert(apps.begin(), apps.end());
+ return *this;
+}
+
+AppInfo::Builder& AppInfo::Builder::SetVconf(const tizen_base::Bundle& args) {
+ vconf_ = args.GetStringArray(AUL_K_VCONF_DATA);
+ return *this;
+}
+
+AppInfo::Builder& AppInfo::Builder::SetArgs(
+ const tizen_base::Bundle& args) {
+ static const std::vector<std::string> internal_keys{
+ "__AUL_APPID__",
+ "__AUL_STARTTIME__",
+ "__K_BG_LAUNCH"
+ };
+ auto arg_json = args.GetString(AUL_K_ARGS);
+ bundle* b = nullptr;
+ if (bundle_from_json(arg_json.c_str(), &b) != BUNDLE_ERROR_NONE) {
+ _E("bundle_from_json() is failed");
+ } else {
+ args_ = tizen_base::Bundle(b, false, true);
+ for (auto& key : internal_keys)
+ args_.Delete(key);
+ }
+
+ return *this;
+}
+
+AppInfo::Builder& AppInfo::Builder::SetBackgroundLaunch(
+ const tizen_base::Bundle& args) {
+ background_launch_ = (args.GetString(AUL_K_ALLOWED_BG) == "true");
+ return *this;
+}
+
+AppInfo::Builder& AppInfo::Builder::SetWaitUntilReady(
+ const tizen_base::Bundle& args) {
+ wait_until_ready_ =
+ (args.GetString(AUL_K_BOOT_SEQUENCE_READY_WAIT) == "true");
+ return *this;
+}
+
+AppInfo::Builder& AppInfo::Builder::SetTimeout(
+ const tizen_base::Bundle& args) {
+ auto timeout_str = args.GetString(AUL_K_TIMEOUT);
+ if (isdigit(timeout_str[0]))
+ timeout_ = static_cast<unsigned int>(std::stoi(timeout_str));
+ else
+ timeout_ = DEFAULT_TIMEOUT;
+
+ return *this;
+}
+
+AppInfo::Builder& AppInfo::Builder::SetActiveState(
+ const tizen_base::Bundle& args) {
+ active_state_ = args.GetString(AUL_K_STATUS);
+ return *this;
+}
+
+AppInfo::Builder& AppInfo::Builder::SetSubState(
+ const tizen_base::Bundle& args) {
+ sub_state_ = args.GetString(AUL_K_SUB_STATUS);
+ return *this;
+}
+
+AppInfo::Builder& AppInfo::Builder::SetBeginTimestamp(
+ const tizen_base::Bundle& args) {
+ begin_timestamp_ = args.GetString(AUL_K_BEGIN_TIMESTAMP);
+ return *this;
+}
+
+AppInfo::Builder& AppInfo::Builder::SetEndTimestamp(
+ const tizen_base::Bundle& args) {
+ end_timestamp_ = args.GetString(AUL_K_END_TIMESTAMP);
+ return *this;
+}
+
+AppInfo::Builder& AppInfo::Builder::SetSocketReadyTimestamp(
+ const tizen_base::Bundle& args) {
+ socket_ready_timestamp_ = args.GetString(AUL_K_SOCKET_READY_TIMESTAMP);
+ return *this;
+}
+
+AppInfo::Builder& AppInfo::Builder::SetTerminatedTimestamp(
+ const tizen_base::Bundle& args) {
+ terminated_timestamp_ = args.GetString(AUL_K_TERMINATED_TIMESTAMP);
+ return *this;
+}
+
+AppInfo::Builder& AppInfo::Builder::SetStatusMessage(
+ const tizen_base::Bundle& args) {
+ status_msg_ = args.GetString(AUL_K_STATUS_MSG);
+ return *this;
+}
+
+AppInfo* AppInfo::Builder::Build() {
+ return new (std::nothrow) AppInfo(
+ std::move(appid_),
+ uid_,
+ priority_,
+ std::move(after_),
+ std::move(before_),
+ std::move(requires_),
+ std::move(conflicts_),
+ std::move(vconf_),
+ std::move(args_),
+ std::move(active_state_),
+ std::move(sub_state_),
+ std::move(begin_timestamp_),
+ std::move(end_timestamp_),
+ std::move(socket_ready_timestamp_),
+ std::move(terminated_timestamp_),
+ std::move(status_msg_),
+ background_launch_,
+ wait_until_ready_,
+ timeout_);
+}
+
+AppInfo::AppInfo(std::string appid, uid_t uid, int priority,
+ std::set<std::string> after, std::set<std::string> before,
+ std::set<std::string> requires_dep, std::set<std::string> conflicts,
+ std::vector<std::string> vconfs,
+ tizen_base::Bundle args,
+ std::string active_state, std::string sub_state,
+ std::string begin_timestamp, std::string end_timestamp,
+ std::string socket_ready_timestamp, std::string terminated_timestamp,
+ std::string status_msg,
+ bool background_launch, bool wait_until_ready, unsigned int timeout)
+ : appid_(std::move(appid)),
+ uid_(uid),
+ priority_(priority),
+ after_(std::move(after)),
+ before_(std::move(before)),
+ requires_(std::move(requires_dep)),
+ conflicts_(std::move(conflicts)),
+ vconf_(std::move(vconfs)),
+ args_(std::move(args)),
+ active_state_(std::move(active_state)),
+ sub_state_(std::move(sub_state)),
+ begin_timestamp_(std::move(begin_timestamp)),
+ end_timestamp_(std::move(end_timestamp)),
+ socket_ready_timestamp_(std::move(socket_ready_timestamp)),
+ terminated_timestamp_(std::move(terminated_timestamp)),
+ background_launch_(background_launch),
+ wait_until_ready_(wait_until_ready),
+ timeout_(timeout),
+ status_msg_(std::move(status_msg)) {
+}
+
+const std::string& AppInfo::GetAppId() const {
+ return appid_;
+}
+
+uid_t AppInfo::GetUid() const {
+ return uid_;
+}
+
+int AppInfo::GetPriority() const {
+ return priority_;
+}
+
+// After
+bool AppInfo::AfterContains(const std::string& appid) {
+ return after_.find(appid) != after_.end();
+}
+
+const std::set<std::string>& AppInfo::AfterGet() const {
+ return after_;
+}
+
+// Before
+bool AppInfo::BeforeContains(const std::string& appid) {
+ return before_.find(appid) != before_.end();
+}
+
+const std::set<std::string>& AppInfo::BeforeGet() const {
+ return before_;
+}
+
+// Requires
+bool AppInfo::RequiresContains(const std::string& appid) {
+ return requires_.find(appid) != requires_.end();
+}
+
+const std::set<std::string>& AppInfo::RequiresGet() const {
+ return requires_;
+}
+
+// Conflicts
+bool AppInfo::ConflictsContains(const std::string& appid) {
+ return conflicts_.find(appid) != conflicts_.end();
+}
+
+const std::set<std::string>& AppInfo::ConflictsGet() const {
+ return conflicts_;
+}
+
+const std::vector<std::string>& AppInfo::GetVconf() const {
+ return vconf_;
+}
+
+const tizen_base::Bundle& AppInfo::GetArgs() const {
+ return args_;
+}
+
+bool AppInfo::IsBackgroundLaunch() const {
+ return background_launch_;
+}
+
+bool AppInfo::WaitUntilReady() const {
+ return wait_until_ready_;
+}
+
+unsigned int AppInfo::GetTimeout() const {
+ return timeout_;
+}
+
+const std::string& AppInfo::GetActiveState() const {
+ return active_state_;
+}
+
+const std::string& AppInfo::GetSubState() const {
+ return sub_state_;
+}
+
+const std::string& AppInfo::GetBeginTimestamp() const {
+ return begin_timestamp_;
+}
+
+const std::string& AppInfo::GetEndTimestamp() const {
+ return end_timestamp_;
+}
+
+const std::string& AppInfo::GetSocketReadyTimestamp() const {
+ return socket_ready_timestamp_;
+}
+
+const std::string& AppInfo::GetTerminatedTimestamp() const {
+ return terminated_timestamp_;
+}
+
+const std::string& AppInfo::GetStatusMessage() const {
+ return status_msg_;
+}
+
+} // namespace boot_sequence
+} // namespace aul::internal
--- /dev/null
+/*
+ * Copyright (c) 2022 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 AULCTL_BOOT_SEQUENCE_APP_INFO_HH_
+#define AULCTL_BOOT_SEQUENCE_APP_INFO_HH_
+
+#include <bundle_cpp.h>
+
+#include <chrono>
+#include <map>
+#include <set>
+#include <string>
+#include <vector>
+
+namespace aul::internal {
+
+namespace boot_sequence {
+
+class AppInfo {
+ public:
+ class Builder {
+ public:
+ Builder& SetAppId(const tizen_base::Bundle& args);
+ Builder& SetUid(const tizen_base::Bundle& args);
+ Builder& SetPriority(const tizen_base::Bundle& args);
+ Builder& SetAfter(const tizen_base::Bundle& args);
+ Builder& SetBefore(const tizen_base::Bundle& args);
+ Builder& SetRequires(const tizen_base::Bundle& args);
+ Builder& SetConflicts(const tizen_base::Bundle& args);
+ Builder& SetVconf(const tizen_base::Bundle& args);
+ Builder& SetArgs(const tizen_base::Bundle& args);
+ Builder& SetBackgroundLaunch(const tizen_base::Bundle& args);
+ Builder& SetWaitUntilReady(const tizen_base::Bundle& args);
+ Builder& SetTimeout(const tizen_base::Bundle& args);
+ Builder& SetActiveState(const tizen_base::Bundle& args);
+ Builder& SetSubState(const tizen_base::Bundle& args);
+ Builder& SetBeginTimestamp(const tizen_base::Bundle& args);
+ Builder& SetEndTimestamp(const tizen_base::Bundle& args);
+ Builder& SetSocketReadyTimestamp(const tizen_base::Bundle& args);
+ Builder& SetTerminatedTimestamp(const tizen_base::Bundle& args);
+ Builder& SetStatusMessage(const tizen_base::Bundle& args);
+
+ AppInfo* Build();
+
+ private:
+ std::string appid_;
+ uid_t uid_ = 0;
+ int priority_ = 0;
+ std::set<std::string> after_;
+ std::set<std::string> before_;
+ std::set<std::string> requires_;
+ std::set<std::string> conflicts_;
+ std::vector<std::string> vconf_;
+ tizen_base::Bundle args_;
+ std::string active_state_;
+ std::string sub_state_;
+ std::string begin_timestamp_;
+ std::string end_timestamp_;
+ std::string socket_ready_timestamp_;
+ std::string terminated_timestamp_;
+ bool background_launch_ = false;
+ bool wait_until_ready_ = false;
+ unsigned int timeout_ = 0;
+ std::string status_msg_;
+ };
+
+ AppInfo(std::string appid, uid_t uid, int priority,
+ std::set<std::string> after, std::set<std::string> before,
+ std::set<std::string> requires_dep, std::set<std::string> conflicts,
+ std::vector<std::string> vconfs,
+ tizen_base::Bundle args,
+ std::string active_state, std::string sub_state,
+ std::string begin_timestamp, std::string end_timestamp,
+ std::string status_msg,
+ std::string socket_ready_timestamp, std::string terminated_timestamp,
+ bool background_launch, bool wait_until_ready, unsigned int timeout);
+
+ const std::string& GetAppId() const;
+ uid_t GetUid() const;
+ int GetPriority() const;
+
+ bool AfterContains(const std::string& appid);
+ const std::set<std::string>& AfterGet() const;
+
+ bool BeforeContains(const std::string& appid);
+ const std::set<std::string>& BeforeGet() const;
+
+ bool RequiresContains(const std::string& appid);
+ const std::set<std::string>& RequiresGet() const;
+
+ bool ConflictsContains(const std::string& appid);
+ const std::set<std::string>& ConflictsGet() const;
+
+ const std::vector<std::string>& GetVconf() const;
+ const tizen_base::Bundle& GetArgs() const;
+ bool IsBackgroundLaunch() const;
+ bool WaitUntilReady() const;
+ unsigned int GetTimeout() const;
+ const std::string& GetActiveState() const;
+ const std::string& GetSubState() const;
+ const std::string& GetBeginTimestamp() const;
+ const std::string& GetEndTimestamp() const;
+ const std::string& GetSocketReadyTimestamp() const;
+ const std::string& GetTerminatedTimestamp() const;
+ const std::string& GetStatusMessage() const;
+
+ private:
+ std::string appid_;
+ uid_t uid_;
+ int priority_;
+ std::set<std::string> after_;
+ std::set<std::string> before_;
+ std::set<std::string> requires_;
+ std::set<std::string> conflicts_;
+ std::vector<std::string> vconf_;
+ tizen_base::Bundle args_;
+ std::string active_state_;
+ std::string sub_state_;
+ std::string begin_timestamp_;
+ std::string end_timestamp_;
+ std::string socket_ready_timestamp_;
+ std::string terminated_timestamp_;
+ bool background_launch_;
+ bool wait_until_ready_;
+ unsigned int timeout_;
+ std::string status_msg_;
+};
+
+} // namespace boot_sequence
+
+} // namespace aul::internal
+
+#endif // AULCTL_BOOT_SEQUENCE_APP_INFO_HH_
--- /dev/null
+/*
+ * Copyright (c) 2021 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 "boot_sequence_manager.hh"
+
+#include <unistd.h>
+
+#include <utility>
+
+#include "aul/app_request.h"
+#include "aul/aul_util.h"
+#include "aul/common/file_descriptor.hh"
+#include "aul/include/aul_sock.h"
+
+namespace aul::internal {
+namespace boot_sequence {
+
+AppInfoPtr BootSequenceManager::CreateAppInfoFromBundle(tizen_base::Bundle b) {
+ auto builder = AppInfo::Builder()
+ .SetAppId(b)
+ .SetUid(b)
+ .SetPriority(b)
+ .SetBefore(b)
+ .SetAfter(b)
+ .SetRequires(b)
+ .SetConflicts(b)
+ .SetVconf(b)
+ .SetArgs(b)
+ .SetTimeout(b)
+ .SetActiveState(b)
+ .SetSubState(b)
+ .SetBackgroundLaunch(b)
+ .SetWaitUntilReady(b)
+ .SetBeginTimestamp(b)
+ .SetEndTimestamp(b)
+ .SetSocketReadyTimestamp(b)
+ .SetTerminatedTimestamp(b);
+
+ return std::shared_ptr<AppInfo>(builder.Build());
+}
+
+void BootSequenceManager::InsertAppInfoCb(app_pkt_t* pkt, void* data) {
+ if (pkt == nullptr) {
+ _E("Invalid parameter");
+ return;
+ }
+
+ auto& appinfo_list = *static_cast<std::vector<AppInfoPtr>*>(data);
+ if (pkt->cmd == APP_GET_INFO_ERROR) {
+ _E("Failed to get running component context");
+ return;
+ }
+
+ bundle* kb = nullptr;
+ if (pkt->opt & AUL_SOCK_BUNDLE)
+ kb = bundle_decode(pkt->data, pkt->len);
+
+ if (kb == nullptr)
+ return;
+
+ auto app = GetInst().CreateAppInfoFromBundle(
+ tizen_base::Bundle(kb, false, true));
+ if (app == nullptr) {
+ _E("Failed to create appinfo");
+ return;
+ }
+
+ appinfo_list.push_back(std::move(app));
+}
+
+BootSequenceManager& BootSequenceManager::GetInst() {
+ static BootSequenceManager inst;
+ return inst;
+}
+
+int BootSequenceManager::Reload(uid_t uid) const {
+ return AppRequest(BOOT_SEQUENCE_RELOAD, uid).SendSimply();
+}
+
+int BootSequenceManager::StartApp(const std::string& appid) const {
+ return AppRequest(BOOT_SEQUENCE_START_APP, getuid())
+ .SetAppId(appid)
+ .SendSimply();
+}
+
+std::vector<AppInfoPtr> BootSequenceManager::GetAppInfoList(uid_t uid) const {
+ int fd = AppRequest(BOOT_SEQUENCE_GET_APPINFO_LIST, uid)
+ .SendSimply(AUL_SOCK_ASYNC);
+
+ if (fd < 0 || fd >= sysconf(_SC_OPEN_MAX)) {
+ _E("Failed to send request. error(%d)", fd);
+ return {};
+ }
+
+ std::vector<AppInfoPtr> appinfo_list;
+ int ret = aul_sock_recv_pkt_with_cb(fd, InsertAppInfoCb, &appinfo_list);
+ if (ret < 0) {
+ _E("Failed to receive reply packet. error(%d)", ret);
+ return {};
+ }
+
+ return appinfo_list;
+}
+
+} // namespace boot_sequence
+} // namespace aul::internal
--- /dev/null
+/*
+ * Copyright (c) 2021 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 AULCTL_BOOT_SEQUENCE_BOOT_SEQUENCE_MANAGER_HH_
+#define AULCTL_BOOT_SEQUENCE_BOOT_SEQUENCE_MANAGER_HH_
+
+#include <bundle_cpp.h>
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "include/aul_sock.h"
+#include "app_info.hh"
+
+namespace aul::internal {
+namespace boot_sequence {
+
+using AppInfoPtr = std::shared_ptr<AppInfo>;
+
+class BootSequenceManager {
+ public:
+ static BootSequenceManager& GetInst();
+ BootSequenceManager(BootSequenceManager&) = delete;
+ BootSequenceManager& operator=(BootSequenceManager&) = delete;
+
+ int Reload(uid_t uid) const;
+ int StartApp(const std::string &appid) const;
+ std::vector<AppInfoPtr> GetAppInfoList(uid_t uid) const;
+ std::string GetLogs() const;
+
+ private:
+ BootSequenceManager() = default;
+ ~BootSequenceManager() = default;
+
+ static void InsertAppInfoCb(app_pkt_t* pkt, void* data);
+
+ AppInfoPtr CreateAppInfoFromBundle(tizen_base::Bundle b);
+};
+
+} // namespace boot_sequence
+} // namespace aul::internal
+
+#endif // AULCTL_BOOT_SEQUENCE_BOOT_SEQUENCE_MANAGER_HH_
--- /dev/null
+/*
+ * Copyright (c) 2022 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 "help_operation.hh"
+
+#include <iostream>
+
+namespace aul {
+namespace {
+
+constexpr const char HowTo[] =
+R"( - aulctl -
+ Application boot sequence management tool
+
+ usage: aulctl [cmd] [|args]
+
+ cmd list:
+
+ - list-apps [|uid] : Print list of boot sequence apps.
+
+ - is-active [appid] : Print whether the app is activated.([active|inactive])
+
+ - status [|appid] : Print status of the boot sequence app.
+
+ - list-dependencies [|uid]: Print dependencies of boot sequence apps.
+
+ - reload [|uid] : Reload the boot squence app's information.
+
+ - start [appid] : Start the app according to the dependencies.
+
+ - stop [appid] : Stop the app.
+)";
+
+} // namespace
+
+bool HelpOperation::Process() {
+ std::cout << HowTo << std::endl;
+
+ return true;
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2022 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 "operation.hh"
+
+namespace aul {
+
+class HelpOperation : public Operation {
+ public:
+ HelpOperation() = default;
+ ~HelpOperation() = default;
+ bool Process() override;
+};
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2022 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 "is_active_operation.hh"
+
+#include <iostream>
+#include <string>
+#include <utility>
+
+#include "boot_sequence/boot_sequence_manager.hh"
+
+namespace aul {
+
+IsActiveOperation::IsActiveOperation(std::string appid)
+ : appid_(std::move(appid)) {
+}
+
+bool IsActiveOperation::Process() {
+ auto& manager = internal::boot_sequence::BootSequenceManager::GetInst();
+ auto app_list = manager.GetAppInfoList(getuid());
+ if (app_list.empty()) {
+ std::cerr << "Failed to get boot sequence app list." << std::endl;
+ return false;
+ }
+
+ for (auto& app : app_list) {
+ if (app->GetAppId() == appid_) {
+ std::cout << app->GetActiveState() << std::endl;
+ return true;
+ }
+ }
+
+ std::cerr << "Not found app info." << std::endl;
+ return false;
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2022 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 <string>
+
+#include "operation.hh"
+
+namespace aul {
+
+class IsActiveOperation : public Operation {
+ public:
+ explicit IsActiveOperation(std::string appid);
+ ~IsActiveOperation() = default;
+ bool Process() override;
+
+ private:
+ std::string appid_;
+};
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2022 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 "list_apps_operation.hh"
+
+#include <aul_boot_sequence.h>
+
+#include <iostream>
+
+#include "boot_sequence/boot_sequence_manager.hh"
+
+namespace aul {
+
+ListAppsOperation::ListAppsOperation(uid_t uid) : uid_(uid) {
+}
+
+bool ListAppsOperation::Process() {
+ auto& manager = internal::boot_sequence::BootSequenceManager::GetInst();
+ auto app_list = manager.GetAppInfoList(uid_);
+ if (app_list.empty()) {
+ std::cerr << "Failed to get boot sequence app list." << std::endl;
+ return false;
+ }
+
+ std::cout << uid_ << " user boot sequence app list" << std::endl;
+ for (auto& app : app_list)
+ std::cout << app->GetAppId() << std::endl;
+
+ return true;
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2022 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 <sys/types.h>
+
+#include "operation.hh"
+
+namespace aul {
+
+class ListAppsOperation : public Operation {
+ public:
+ explicit ListAppsOperation(uid_t uid);
+ ~ListAppsOperation() = default;
+ bool Process() override;
+
+ private:
+ uid_t uid_;
+};
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2022 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 "list_dependencies_operation.hh"
+
+#include <aul_boot_sequence.h>
+
+#include <iostream>
+#include <map>
+#include <stack>
+#include <string>
+#include <vector>
+
+#include "boot_sequence/boot_sequence_manager.hh"
+
+namespace aul {
+
+ListDependenciesOperation::ListDependenciesOperation(uid_t uid) : uid_(uid) {
+}
+
+bool ListDependenciesOperation::Process() {
+ auto& manager = internal::boot_sequence::BootSequenceManager::GetInst();
+ auto app_list = manager.GetAppInfoList(uid_);
+ if (app_list.empty()) {
+ std::cerr << "Failed to get boot sequence app list." << std::endl;
+ return false;
+ }
+
+ std::map<std::string, internal::boot_sequence::AppInfoPtr> infos;
+ std::map<std::string, int> req_cnt;
+ for (auto& app : app_list) {
+ infos[app->GetAppId()] = app;
+ if (req_cnt.find(app->GetAppId()) == req_cnt.end())
+ req_cnt[app->GetAppId()] = 0;
+
+ for (auto &appid : app->BeforeGet())
+ req_cnt[appid]++;
+ }
+
+ std::stack<internal::boot_sequence::AppInfoPtr> stack;
+ for (auto& [appid, cnt] : req_cnt) {
+ if (cnt == 0 && infos.find(appid) != infos.end())
+ stack.push(infos[appid]);
+ }
+
+ while (!stack.empty()) {
+ auto app = std::move(stack.top());
+ stack.pop();
+
+ std::cout << app->GetAppId() << std::endl;
+ std::cout << " After: ";
+ for (auto& appid : app->AfterGet())
+ std::cout << appid << ' ';
+
+ std::cout << std::endl << " Before: ";
+ for (auto& appid : app->BeforeGet())
+ std::cout << appid << ' ';
+
+ std::cout << std::endl << " Conflicts: ";
+ for (auto& appid : app->ConflictsGet())
+ std::cout << appid << ' ';
+
+ std::cout << std::endl;
+ std::cout << "============================================" << std::endl;
+ for (auto& appid : app->BeforeGet()) {
+ if (--req_cnt[appid] == 0 && infos.find(appid) != infos.end())
+ stack.push(infos[appid]);
+ }
+ }
+
+ return true;
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2022 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 <sys/types.h>
+
+#include "operation.hh"
+
+namespace aul {
+
+class ListDependenciesOperation : public Operation {
+ public:
+ explicit ListDependenciesOperation(uid_t uid);
+ ~ListDependenciesOperation() = default;
+ bool Process() override;
+
+ private:
+ uid_t uid_;
+};
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2022 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 OPERATION_OPERATION_HH_
+#define OPERATION_OPERATION_HH_
+
+namespace aul {
+
+class Operation {
+ public:
+ virtual ~Operation() = default;
+ virtual bool Process() = 0;
+};
+
+} // namespace aul
+
+#endif // OPERATION_OPERATION_HH_
--- /dev/null
+/*
+ * Copyright (c) 2022 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 "operation_factory.hh"
+
+#include <unistd.h>
+
+#include <iostream>
+#include <memory>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "help_operation.hh"
+#include "is_active_operation.hh"
+#include "list_apps_operation.hh"
+#include "list_dependencies_operation.hh"
+#include "start_operation.hh"
+#include "status_all_operation.hh"
+#include "status_once_operation.hh"
+#include "stop_operation.hh"
+#include "reload_operation.hh"
+
+namespace aul {
+
+std::unique_ptr<Operation> OperationFactory::CreateOperation(
+ const std::vector<std::string>& args) const {
+ try {
+ if (args.empty())
+ return std::make_unique<HelpOperation>();
+
+ const auto& cmd = args[0];
+ if (cmd == "list-apps") {
+ if (args.size() == 1)
+ return std::make_unique<ListAppsOperation>(getuid());
+
+ return std::make_unique<ListAppsOperation>(
+ static_cast<uid_t>(std::stoi(args[1])));
+ } else if (cmd == "list-dependencies") {
+ if (args.size() == 1)
+ return std::make_unique<ListDependenciesOperation>(getuid());
+
+ return std::make_unique<ListDependenciesOperation>(
+ static_cast<uid_t>(std::stoi(args[1])));
+ } else if (cmd == "is-active") {
+ if (args.size() == 1)
+ return std::make_unique<HelpOperation>();
+
+ auto appid = args[1];
+ return std::make_unique<IsActiveOperation>(std::move(appid));
+ } else if (cmd == "status") {
+ if (args.size() == 1)
+ return std::make_unique<StatusAllOperation>();
+
+ auto appid = args[1];
+ return std::make_unique<StatusOnceOperation>(std::move(appid));
+ } else if (cmd == "reload") {
+ if (args.size() == 1)
+ return std::make_unique<ReloadOperation>(getuid());
+
+ return std::make_unique<ReloadOperation>(
+ static_cast<uid_t>(std::stoi(args[1])));
+ } else if (cmd == "start") {
+ if (args.size() == 1)
+ return std::make_unique<HelpOperation>();
+
+ auto appid = args[1];
+ return std::make_unique<StartOperation>(std::move(appid));
+ } else if (cmd == "stop") {
+ if (args.size() == 1)
+ return std::make_unique<HelpOperation>();
+
+ auto appid = args[1];
+ return std::make_unique<StopOperation>(std::move(appid));
+ } else {
+ return std::make_unique<HelpOperation>();
+ }
+ } catch (const std::invalid_argument& error) {
+ std::cerr << "Invalid patameter: " << error.what() << std::endl;
+ return std::make_unique<HelpOperation>();
+ }
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2022 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 <memory>
+#include <vector>
+
+#include "operation.hh"
+
+namespace aul {
+
+class OperationFactory {
+ public:
+ OperationFactory() = default;
+ ~OperationFactory() = default;
+ std::unique_ptr<Operation> CreateOperation(
+ const std::vector<std::string>& args) const;
+};
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2022 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 "reload_operation.hh"
+
+#include <iostream>
+
+#include "include/aul.h"
+#include "boot_sequence/boot_sequence_manager.hh"
+
+namespace aul {
+
+ReloadOperation::ReloadOperation(uid_t uid) : uid_(uid) {
+}
+
+bool ReloadOperation::Process() {
+ auto &manager = internal::boot_sequence::BootSequenceManager::GetInst();
+ int ret = manager.Reload(uid_);
+ std::cout << "Reload result: " << ret << std::endl;
+ return ret == AUL_R_OK;
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2022 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 <sys/types.h>
+
+#include "operation.hh"
+
+namespace aul {
+
+class ReloadOperation : public Operation {
+ public:
+ explicit ReloadOperation(uid_t uid);
+ ~ReloadOperation() = default;
+ bool Process() override;
+
+ private:
+ uid_t uid_;
+};
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2022 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 "start_operation.hh"
+
+#include <iostream>
+
+#include "include/aul.h"
+#include "boot_sequence/boot_sequence_manager.hh"
+
+namespace aul {
+
+StartOperation::StartOperation(std::string appid)
+ : appid_(std::move(appid)) {
+}
+
+bool StartOperation::Process() {
+ auto& manager = internal::boot_sequence::BootSequenceManager::GetInst();
+ int ret = manager.StartApp(appid_);
+ if (ret != AUL_R_OK) {
+ std::cerr << "Failed to start app(" << appid_ << ")" << std::endl;
+ return false;
+ }
+
+ return true;
+}
+
+} // namespace aul
--- /dev/null
+
+/*
+ * Copyright (c) 2022 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 <string>
+
+#include "operation.hh"
+
+namespace aul {
+
+class StartOperation : public Operation {
+ public:
+ explicit StartOperation(std::string appid);
+ ~StartOperation() = default;
+ bool Process() override;
+
+ private:
+ std::string appid_;
+};
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2022 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 "status_all_operation.hh"
+
+#include <bundle.h>
+#include <bundle_cpp.h>
+
+#include <iostream>
+#include <string>
+#include <utility>
+
+#include "aul/api/aul_app_context.h"
+#include "boot_sequence/boot_sequence_manager.hh"
+
+namespace aul {
+
+bool StatusAllOperation::Process() {
+ auto& manager = internal::boot_sequence::BootSequenceManager::GetInst();
+ auto app_list = manager.GetAppInfoList(getuid());
+ if (app_list.empty()) {
+ std::cerr << "Failed to get boot sequence app list." << std::endl;
+ return false;
+ }
+
+ for (const auto& app : app_list) {
+ std::cout << "===========================================" << std::endl;
+ std::cout << "appid: " << app->GetAppId() << std::endl;
+
+ std::cout << "status: " << app->GetActiveState() << std::endl;
+ std::cout << "sub status: " << app->GetSubState() << std::endl;
+ if (app->GetSubState() == "failed")
+ std::cout << " message: " << app->GetStatusMessage() << std::endl;
+
+ aul_app_context_h context;
+ int ret = aul_app_context_create(app->GetAppId().c_str(), &context);
+ if (ret == 0) {
+ const char* val = nullptr;
+ aul_app_context_get_app_path(context, const_cast<char**>(&val));
+ std::cout << "app path: " << val << std::endl;
+ std::free(const_cast<char*>(val));
+ pid_t pid = -1;
+ aul_app_context_get_pid(context, &pid);
+ std::cout << "pid: " << pid << std::endl;
+ aul_app_context_destroy(context);
+ }
+
+ std::cout << "begin: " << app->GetBeginTimestamp() << std::endl;
+ std::cout << "end: " << app->GetEndTimestamp() << std::endl;
+
+ std::cout << "started time: " << app->GetSocketReadyTimestamp()
+ << std::endl;
+
+ std::cout << "termiated time: " << app->GetTerminatedTimestamp()
+ << std::endl;
+
+ std::cout << "requires: ";
+ for (auto& appid : app->RequiresGet())
+ std::cout << appid << " ";
+
+ std::cout << std::endl;
+
+ std::cout << "before: ";
+ for (auto& appid : app->BeforeGet())
+ std::cout << appid << " ";
+
+ std::cout << std::endl;
+
+ std::cout << "after: ";
+ for (auto& appid : app->AfterGet())
+ std::cout << appid << " ";
+
+ std::cout << std::endl;
+
+ std::cout << "conflict: ";
+ for (auto& appid : app->ConflictsGet())
+ std::cout << appid << " ";
+
+ std::cout << std::endl;
+
+ std::cout << "vconf: {\n";
+ for (auto& vconf : app->GetVconf()) {
+ std::cout << vconf << std::endl;
+ }
+ std::cout << "}" << std::endl;
+
+ std::cout << "args: {\n";
+ auto& b = app->GetArgs();
+ bundle_foreach(
+ b.GetHandle(),
+ [](const char* key, const int type,
+ const bundle_keyval_t* kv, void* data) {
+ auto& kb = *static_cast<tizen_base::Bundle*>(data);
+ std::cout << key << ": ";
+ switch (type) {
+ case BUNDLE_TYPE_STR:
+ std::cout << kb.GetString(key) << std::endl;
+ break;
+ case BUNDLE_TYPE_STR_ARRAY:
+ std::cout << "[ ";
+ for (auto& val : kb.GetStringArray(key))
+ std::cout << val << ", ";
+
+ std::cout << "]" << std::endl;
+ break;
+ default:
+ break;
+ }
+ },
+ const_cast<tizen_base::Bundle*>(&b));
+ std::cout << "}" << std::endl;
+
+ std::cout << "bg-launch: " << (app->IsBackgroundLaunch() ? "true" : "false")
+ << std::endl;
+ std::cout << "===========================================" << std::endl;
+ }
+
+ return true;
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2022 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 "operation.hh"
+
+namespace aul {
+
+class StatusAllOperation : public Operation {
+ public:
+ StatusAllOperation() = default;
+ ~StatusAllOperation() = default;
+ bool Process() override;
+};
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2022 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 "status_once_operation.hh"
+
+#include <iostream>
+#include <string>
+#include <utility>
+
+#include "boot_sequence/boot_sequence_manager.hh"
+#include "aul_app_context.h"
+#include "aul_boot_sequence.h"
+
+namespace aul {
+
+StatusOnceOperation::StatusOnceOperation(std::string appid)
+ : appid_(std::move(appid)) {
+}
+
+bool StatusOnceOperation::Process() {
+ auto& manager = internal::boot_sequence::BootSequenceManager::GetInst();
+ auto app_list = manager.GetAppInfoList(getuid());
+ if (app_list.empty()) {
+ std::cerr << "Failed to get boot sequence app list." << std::endl;
+ return false;
+ }
+
+ for (const auto& app : app_list) {
+ if (app->GetAppId() != appid_)
+ continue;
+
+ std::cout << "appid: " << app->GetAppId() << std::endl;
+
+ std::cout << "status: " << app->GetActiveState() << std::endl;
+ std::cout << "sub status: " << app->GetSubState() << std::endl;
+ if (app->GetSubState() == "failed")
+ std::cout << " message: " << app->GetStatusMessage() << std::endl;
+
+ aul_app_context_h context;
+ int ret = aul_app_context_create(app->GetAppId().c_str(), &context);
+ if (ret == 0) {
+ const char* val = nullptr;
+ aul_app_context_get_app_path(context, const_cast<char**>(&val));
+ std::cout << "app path: " << val << std::endl;
+ std::free(const_cast<char*>(val));
+ pid_t pid = -1;
+ aul_app_context_get_pid(context, &pid);
+ std::cout << "pid: " << pid << std::endl;
+ aul_app_context_destroy(context);
+ }
+
+ std::cout << "begin: " << app->GetBeginTimestamp() << std::endl;
+ std::cout << "end: " << app->GetEndTimestamp() << std::endl;
+
+ std::cout << "started time: " << app->GetSocketReadyTimestamp()
+ << std::endl;
+
+ std::cout << "termiated time: " << app->GetTerminatedTimestamp()
+ << std::endl;
+
+ std::cout << "requires: ";
+ for (auto& appid : app->RequiresGet())
+ std::cout << appid << " ";
+
+ std::cout << std::endl;
+
+ std::cout << "before: ";
+ for (auto& appid : app->BeforeGet())
+ std::cout << appid << " ";
+
+ std::cout << std::endl;
+
+ std::cout << "after: ";
+ for (auto& appid : app->AfterGet())
+ std::cout << appid << " ";
+
+ std::cout << std::endl;
+
+ std::cout << "conflict: ";
+ for (auto& appid : app->ConflictsGet())
+ std::cout << appid << " ";
+
+ std::cout << std::endl;
+
+ std::cout << "vconf: {\n";
+ for (auto& vconf : app->GetVconf()) {
+ std::cout << vconf << std::endl;
+ }
+ std::cout << "}" << std::endl;
+
+ std::cout << "args: {\n";
+ auto& b = app->GetArgs();
+ bundle_foreach(
+ b.GetHandle(),
+ [](const char* key, const int type,
+ const bundle_keyval_t* kv, void* data) {
+ auto& kb = *static_cast<tizen_base::Bundle*>(data);
+ std::cout << key << ": ";
+ switch (type) {
+ case BUNDLE_TYPE_STR:
+ std::cout << kb.GetString(key) << std::endl;
+ break;
+ case BUNDLE_TYPE_STR_ARRAY:
+ std::cout << "[ ";
+ for (auto& val : kb.GetStringArray(key))
+ std::cout << val << ", ";
+
+ std::cout << "]" << std::endl;
+ break;
+ default:
+ break;
+ }
+ },
+ const_cast<tizen_base::Bundle*>(&b));
+ std::cout << "}" << std::endl;
+
+ std::cout << "bg-launch: " << (app->IsBackgroundLaunch() ? "true" : "false")
+ << std::endl;
+ return true;
+ }
+
+ std::cerr << "Not found app info." << std::endl;
+ return false;
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2022 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 <map>
+#include <string>
+
+#include "operation.hh"
+
+namespace aul {
+
+class StatusOnceOperation : public Operation {
+ public:
+ explicit StatusOnceOperation(std::string appid);
+ ~StatusOnceOperation() = default;
+ bool Process() override;
+
+ private:
+ std::string appid_;
+};
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2022 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 "stop_operation.hh"
+
+#include <iostream>
+
+#include "aul/api/aul_app_context.h"
+#include "include/aul.h"
+#include "boot_sequence/boot_sequence_manager.hh"
+
+namespace aul {
+
+StopOperation::StopOperation(std::string appid)
+ : appid_(std::move(appid)) {
+}
+
+bool StopOperation::Process() {
+ auto& manager = internal::boot_sequence::BootSequenceManager::GetInst();
+ auto app_list = manager.GetAppInfoList(getuid());
+ if (app_list.empty()) {
+ std::cerr << "Failed to get boot sequence app list." << std::endl;
+ return false;
+ }
+
+ for (auto& app : app_list) {
+ if (app->GetAppId() != appid_)
+ continue;
+
+ int ret = aul_terminate_app(appid_.c_str());
+ if (ret != AUL_R_OK) {
+ std::cerr << "Failed to terminate app." << std::endl;
+ return false;
+ }
+
+ std::cout << "Success to terminate app." << std::endl;
+ return true;
+ }
+
+ std::cerr << "Not found app info." << std::endl;
+ return false;
+}
+
+} // namespace aul
--- /dev/null
+
+/*
+ * Copyright (c) 2022 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 <string>
+
+#include "operation.hh"
+
+namespace aul {
+
+class StopOperation : public Operation {
+ public:
+ explicit StopOperation(std::string appid);
+ ~StopOperation() = default;
+ bool Process() override;
+
+ private:
+ std::string appid_;
+};
+
+} // namespace aul
--- /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}/../aul
+ ${CMAKE_CURRENT_SOURCE_DIR}/../aul/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
+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}/../aul
+ ${CMAKE_CURRENT_SOURCE_DIR}/../aul/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
+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}/../aul
+ ${CMAKE_CURRENT_SOURCE_DIR}/../aul/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
+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}/../aul
+ ${CMAKE_CURRENT_SOURCE_DIR}/../aul/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;
+}
+
--- /dev/null
+########################
+## 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}/db_internal.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})
+
+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}/db_internal.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})
+
+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)
--- /dev/null
+/*
+ * Copyright (c) 2020 - 2022 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 <tzplatform_config.h>
+
+#include "db_internal.h"
+
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
+#define ROOT_UID 0
+
+#define QUERY_CREATE_APPSVC \
+ "PRAGMA journal_mode = PERSIST;\n" \
+ "PRAGMA user_version = " APPSVC_DB_VERSION ";\n" \
+ "CREATE TABLE IF NOT EXISTS appsvc (\n" \
+ " operation TEXT,\n" \
+ " mime_type TEXT DEFAULT 'NULL',\n" \
+ " uri TEXT DEFAULT 'NULL',\n" \
+ " pkg_name TEXT,\n" \
+ " PRIMARY KEY (operation,mime_type,uri)\n" \
+ ");\n" \
+ "CREATE TABLE IF NOT EXISTS alias_info (\n" \
+ " alias_appid TEXT NOT NULL,\n" \
+ " appid TEXT NOT NULL,\n" \
+ " enable TEXT NOT NULL DEFAULT 'true',\n" \
+ " PRIMARY KEY (alias_appid)\n" \
+ ");\n" \
+ "CREATE TABLE IF NOT EXISTS alias_info_for_uid (\n" \
+ " appid TEXT NOT NULL,\n" \
+ " uid INTEGER NOT NULL,\n" \
+ " is_enabled TEXT NOT NULL DEFAULT 'false',\n" \
+ " PRIMARY KEY (appid, uid)\n" \
+ ");\n" \
+ "CREATE TRIGGER IF NOT EXISTS update_alias_info_for_uid\n" \
+ " AFTER UPDATE ON alias_info_for_uid\n" \
+ " BEGIN\n" \
+ " DELETE FROM alias_info_for_uid\n" \
+ " WHERE is_enabled='true';\n" \
+ " END;\n" \
+ "CREATE TABLE IF NOT EXISTS allowed_info (\n" \
+ " appid TEXT NOT NULL,\n" \
+ " allowed_appid TEXT NOT NULL,\n" \
+ " PRIMARY KEY (appid, allowed_appid)\n" \
+ ");\n" \
+ "CREATE TABLE IF NOT EXISTS boot_sequence (\n" \
+ " package TEXT NOT NULL,\n" \
+ " appid TEXT NOT NULL,\n" \
+ " after TEXT NOT NULL,\n" \
+ " before TEXT NOT NULL,\n" \
+ " requires TEXT NOT NULL,\n" \
+ " conflicts TEXT NOT NULL,\n" \
+ " vconf TEXT NOT NULL,\n" \
+ " path_exists TEXT NOT NULL,\n" \
+ " args TEXT NOT NULL,\n" \
+ " background_launch TEXT NOT NULL,\n" \
+ " wait_until_ready TEXT NOT NULL,\n" \
+ " timeout TEXT NOT NULL,\n" \
+ " PRIMARY KEY (appid)\n" \
+ ");"
+
+static int __check_db_integrity(uid_t uid)
+{
+ static const char *tables[] = {
+ "alias_info",
+ "alias_info_for_uid",
+ "allowed_info",
+ "appsvc",
+ "boot_sequence",
+ };
+ char *db_path;
+ int ret;
+
+ db_path = _db_get_path(".appsvc.db", uid);
+ if (!db_path) {
+ fprintf(stderr, "Failed to get appsvc db path\n");
+ return -1;
+ }
+
+ ret = _db_verify(db_path, tables, ARRAY_SIZE(tables));
+ if (ret == 0) {
+ free(db_path);
+ return 0;
+ }
+
+ ret = _db_recovery(db_path, QUERY_CREATE_APPSVC, uid);
+ if (ret != 0) {
+ fprintf(stderr, "Failed to recovery %s\n", db_path);
+ free(db_path);
+ return -1;
+ }
+ free(db_path);
+
+ printf("appsvc DB recovery process done\n");
+ return 1;
+}
+
+int main(int argc, char **argv)
+{
+ int ret;
+
+ if (getuid() != ROOT_UID) {
+ fprintf(stderr, "Only root user can run this tool\n");
+ return -1;
+ }
+
+ ret = __check_db_integrity(tzplatform_getuid(TZ_SYS_GLOBALAPP_USER));
+ if (ret < 0)
+ return -1;
+
+ ret = __check_db_integrity(tzplatform_getuid(TZ_SYS_DEFAULT_USER));
+ if (ret < 0)
+ return -1;
+
+ return ret;
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 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 <tzplatform_config.h>
+
+#include "db_internal.h"
+
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
+#define ROOT_UID 0
+
+#define QUERY_CREATE_COMPONENT \
+ "PRAGMA journal_mode = PERSIST;\n" \
+ "PRAGMA user_version = " COMPONENT_DB_VERSION ";\n" \
+ "CREATE TABLE IF NOT EXISTS component_info (\n" \
+ " package TEXT NOT NULL,\n" \
+ " app_id TEXT NOT NULL,\n" \
+ " component_id TEXT NOT NULL,\n" \
+ " component_type TEXT NOT NULL,\n" \
+ " component_launch_mode TEXT NOT NULL,\n" \
+ " component_main TEXT NOT NULL,\n" \
+ " component_icon_display NOT NULL,\n" \
+ " component_taskmanage NOT NULL,\n" \
+ " PRIMARY KEY (component_id)\n" \
+ ");\n" \
+ "CREATE TABLE IF NOT EXISTS component_localized_info (\n" \
+ " component_id TEXT NOT NULL,\n" \
+ " component_locale TEXT NOT NULL DEFAULT 'No Locale',\n" \
+ " component_label TEXT,\n" \
+ " component_icon TEXT,\n" \
+ " PRIMARY KEY (component_id, component_locale)\n" \
+ " FOREIGN KEY (component_id)\n" \
+ " REFERENCES component_info(component_id) ON DELETE CASCADE\n" \
+ ");"
+
+static int __check_db_integrity(uid_t uid)
+{
+ static const char *tables[] = {
+ "component_info",
+ "component_localized_info",
+ };
+ char *db_path;
+ int ret;
+
+ db_path = _db_get_path(".component.db", uid);
+ if (!db_path) {
+ fprintf(stderr, "Failed to get component db path\n");
+ return -1;
+ }
+
+ ret = _db_verify(db_path, tables, ARRAY_SIZE(tables));
+ if (ret == 0) {
+ free(db_path);
+ return 0;
+ }
+
+ ret = _db_recovery(db_path, QUERY_CREATE_COMPONENT, uid);
+ if (ret != 0) {
+ fprintf(stderr, "Failed to recovery %s\n", db_path);
+ free(db_path);
+ return -1;
+ }
+ free(db_path);
+
+ printf("component DB recovery process done\n");
+ return 1;
+}
+
+int main(int argc, char **argv)
+{
+ int ret;
+
+ if (getuid() != ROOT_UID) {
+ fprintf(stderr, "Only root user can run this tool\n");
+ return -1;
+ }
+
+ ret = __check_db_integrity(tzplatform_getuid(TZ_SYS_GLOBALAPP_USER));
+ if (ret < 0)
+ return -1;
+
+ ret = __check_db_integrity(tzplatform_getuid(TZ_SYS_DEFAULT_USER));
+ if (ret < 0)
+ return -1;
+
+ return ret;
+}
--- /dev/null
+/*
+ * Copyright (c) 2021 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 <errno.h>
+#include <linux/limits.h>
+#include <pwd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/smack.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <tzplatform_config.h>
+
+#include "db_internal.h"
+
+#define BUSY_WAITING_USEC 50000
+#define BUSY_WAITING_MAX 100
+#define REGULAR_UID_MIN 5000
+
+char *_db_get_path(const char *file, uid_t uid)
+{
+ char buf[PATH_MAX];
+
+ if (uid >= REGULAR_UID_MIN) {
+ snprintf(buf, sizeof(buf), "%s/user/%u/%s",
+ tzplatform_getenv(TZ_SYS_DB), uid, file);
+ } else {
+ snprintf(buf, sizeof(buf), "%s/%s",
+ tzplatform_getenv(TZ_SYS_DB), file);
+ }
+
+ return strdup(buf);
+}
+
+static int __db_busy_handler(void *data, int count)
+{
+ const char *path = (const char *)data;
+
+ if (count < BUSY_WAITING_MAX) {
+ usleep(BUSY_WAITING_USEC);
+ return 1;
+ }
+
+ _E("Database(%s) is busy", path);
+ return 0;
+}
+
+sqlite3 *_db_open(const char *path, bool readonly)
+{
+ sqlite3 *db;
+ int flags;
+ int ret;
+
+ flags = readonly ? SQLITE_OPEN_READONLY : SQLITE_OPEN_READWRITE;
+ ret = sqlite3_open_v2(path, &db, flags, NULL);
+ if (ret != SQLITE_OK) {
+ _E("sqlite3_open_v2() is failed. error(%d)", ret);
+ sqlite3_close_v2(db);
+ return NULL;
+ }
+
+ ret = sqlite3_busy_handler(db, __db_busy_handler, (void *)path);
+ if (ret != SQLITE_OK) {
+ _E("sqlite3_busy_handler() is failed. error(%s)",
+ sqlite3_errmsg(db));
+ sqlite3_close_v2(db);
+ return NULL;
+ }
+
+ return db;
+}
+
+sqlite3 *_db_create(const char *path)
+{
+ sqlite3 *db;
+ int ret;
+
+ ret = sqlite3_open_v2(path, &db,
+ SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, NULL);
+ if (ret != SQLITE_OK) {
+ _E("sqlite3_open_v2() is failed. error(%d)", ret);
+ sqlite3_close_v2(db);
+ return NULL;
+ }
+
+ return db;
+}
+
+void _db_close(sqlite3 *db)
+{
+ sqlite3_close_v2(db);
+}
+
+int _db_save_column_str(sqlite3_stmt *stmt, int idx, char **str)
+{
+ const char *val;
+
+ val = (const char *)sqlite3_column_text(stmt, idx);
+ if (val) {
+ *str = strdup(val);
+ if (*str == NULL) {
+ _E("Out of memory");
+ return -ENOMEM;
+ }
+ }
+
+ return 0;
+}
+
+static int __integrity_check(sqlite3 *db)
+{
+ const char query[] = "PRAGMA integrity_check";
+ sqlite3_stmt *stmt = NULL;
+ const char *res;
+ int ret;
+
+ ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ _E("sqlite3_prepare_v2() is failed. error(%s)",
+ sqlite3_errmsg(db));
+ return -1;
+ }
+
+ ret = sqlite3_step(stmt);
+ if (ret != SQLITE_ROW) {
+ _E("sqlite3_step() is failed. error(%s)", sqlite3_errmsg(db));
+ sqlite3_finalize(stmt);
+ return -1;
+ }
+
+ res = (const char *)sqlite3_column_text(stmt, 0);
+ if (!res) {
+ _E("Failed to check integrity db. error(%s)",
+ sqlite3_errmsg(db));
+ sqlite3_finalize(stmt);
+ return -1;
+ }
+
+ if (strcmp(res, "ok") != 0) {
+ sqlite3_finalize(stmt);
+ return -1;
+ }
+
+ sqlite3_finalize(stmt);
+
+ return 0;
+}
+
+static int __check_table(sqlite3 *db, const char **tables, int table_count)
+{
+ const char query[] = "SELECT name FROM sqlite_master "
+ "WHERE type='table' ORDER BY name ASC";
+ sqlite3_stmt *stmt = NULL;
+ const char *val;
+ int count = 0;
+
+ __PREPARE_V2(db, query, strlen(query), stmt);
+
+ while (sqlite3_step(stmt) == SQLITE_ROW && count < table_count) {
+ val = (const char *)sqlite3_column_text(stmt, 0);
+ if (val) {
+ _E("%s %s", val, tables[count]);
+ if (strcmp(tables[count], val) != 0)
+ continue;
+ count++;
+ }
+ }
+
+ sqlite3_finalize(stmt);
+
+ if (count != table_count) {
+ _E("Wrong table count(%d:%d)", count, table_count);
+ return -1;
+ }
+
+ return 0;
+}
+
+int _db_verify(const char *path, const char **tables, int table_count)
+{
+ sqlite3 *db;
+ int ret;
+
+ if (!path) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ ret = access(path, F_OK);
+ if (ret != 0) {
+ _E("%s does not exists. errno(%d)", path, errno);
+ return -1;
+ }
+
+ db = _db_open(path, true);
+ if (!db) {
+ _E("Failed to open database(%s)", path);
+ return -1;
+ }
+
+ ret = __integrity_check(db);
+ if (ret != 0) {
+ _E("Database(%s) is corrupted", path);
+ _db_close(db);
+ return -1;
+ }
+
+ ret = __check_table(db, tables, table_count);
+ _db_close(db);
+ if (ret != 0) {
+ _E("Database(%s) is corrupted", path);
+ return -1;
+ }
+
+ return 0;
+}
+
+static int __change_permission(const char *path)
+{
+ mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
+ char path_db_journal[PATH_MAX];
+ int ret;
+
+ ret = chmod(path, mode);
+ if (ret != 0) {
+ _E("chmod() is failed. errno(%d)", errno);
+ return -1;
+ }
+
+ snprintf(path_db_journal, sizeof(path_db_journal), "%s-journal", path);
+ ret = chmod(path_db_journal, mode);
+ if (ret != 0) {
+ _E("chmod() is failed. errno(%d)", errno);
+ return -1;
+ }
+
+ return 0;
+}
+
+static int __change_ownership(const char *path, uid_t uid)
+{
+#define ROOT_UID 0
+ struct passwd pwd;
+ struct passwd *result;
+ char path_db_journal[PATH_MAX];
+ char buf[PATH_MAX];
+ uid_t new_uid;
+ int ret;
+
+ ret = getpwuid_r(uid, &pwd, buf, sizeof(buf), &result);
+ if (result == NULL) {
+ if (ret == 0)
+ _E("No such user(%u)", uid);
+ else
+ _E("getpwuid_r() is failed. errno(%d)", errno);
+ return -1;
+ }
+
+ if (pwd.pw_uid == tzplatform_getuid(TZ_SYS_GLOBALAPP_USER))
+ new_uid = ROOT_UID;
+ else
+ new_uid = pwd.pw_uid;
+
+ ret = chown(path, new_uid, pwd.pw_gid);
+ if (ret != 0) {
+ _E("chown() is failed. errno(%d)", errno);
+ return -1;
+ }
+
+ snprintf(path_db_journal, sizeof(path_db_journal), "%s-journal", path);
+ ret = chown(path_db_journal, new_uid, pwd.pw_gid);
+ if (ret != 0) {
+ _E("chown() is failed. errno(%d)", errno);
+ return -1;
+ }
+
+ return 0;
+}
+
+static int __change_smack(const char *path)
+{
+#define DB_LABEL "User::Home"
+ char path_db_journal[PATH_MAX];
+ int ret;
+
+ ret = smack_setlabel(path, DB_LABEL, SMACK_LABEL_ACCESS);
+ if (ret != 0) {
+ _E("smack_setlabel() is failed. error(%d)", ret);
+ return -1;
+ }
+
+ snprintf(path_db_journal, sizeof(path_db_journal), "%s-journal", path);
+ ret = access(path_db_journal, F_OK);
+ if (ret == 0) {
+ ret = smack_setlabel(path_db_journal, DB_LABEL,
+ SMACK_LABEL_ACCESS);
+ if (ret != 0) {
+ _E("smack_setlabel() is failed. error(%d)", ret);
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+int _db_recovery(const char *path, const char *query, uid_t uid)
+{
+ char *errmsg = NULL;
+ sqlite3 *db;
+ int ret;
+
+ if (!path || !query) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ ret = access(path, F_OK);
+ if (ret == 0)
+ unlink(path);
+
+ db = _db_create(path);
+ if (!db) {
+ _E("Failed to open database(%s)", path);
+ return -1;
+ }
+
+ ret = sqlite3_exec(db, query, NULL, NULL, &errmsg);
+ _db_close(db);
+ if (ret != SQLITE_OK) {
+ _E("sqlite3_exec() is failed. error(%d:%s)", ret, errmsg);
+ sqlite3_free(errmsg);
+ return -1;
+ }
+
+ ret = __change_smack(path);
+ if (ret != 0) {
+ _E("Failed to change smack label of %s", path);
+ return -1;
+ }
+
+ ret = __change_ownership(path, uid);
+ if (ret != 0) {
+ _E("Failed to change ownership of %s", path);
+ return -1;
+ }
+
+ ret = __change_permission(path);
+ if (ret != 0) {
+ _E("Failed to change permissions of %s", path);
+ return -1;
+ }
+
+ return 0;
+}
--- /dev/null
+/*
+ * Copyright (c) 2021 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 __DB_INTERNAL_H__
+#define __DB_INTERNAL_H__
+
+#include <sqlite3.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define _E(fmt, ...) \
+ fprintf(stderr, "%s(%d): "fmt"\n", \
+ __FUNCTION__, __LINE__, ##__VA_ARGS__)
+
+#define __PREPARE_V2(db, query, length, stmt) do { \
+ if (sqlite3_prepare_v2(db, query, length, &stmt, NULL) != SQLITE_OK) { \
+ _E("sqlite3_prepare_v2() is failed. error(%s)", \
+ sqlite3_errmsg(db)); \
+ return -1; \
+ } \
+} while (0)
+
+#define __BIND_TEXT(db, stmt, i, text) do { \
+ if (sqlite3_bind_text(stmt, i, text, -1, SQLITE_STATIC) != SQLITE_OK) {\
+ _E("sqlite3_bind_text() is failed. index(%d), error(%s)", \
+ i, sqlite3_errmsg(db)); \
+ sqlite3_finalize(stmt); \
+ return -1; \
+ } \
+} while (0)
+
+#define __BIND_INT(db, stmt, i, val) do { \
+ if (sqlite3_bind_int(stmt, i, val) != SQLITE_OK) { \
+ _E("sqlite3_bind_int() is failed. index(%d), error(%s)", \
+ i, sqlite3_errmsg(db)); \
+ sqlite3_finalize(stmt); \
+ return -1; \
+ } \
+} while (0)
+
+#define __STEP(db, stmt) do { \
+ if (sqlite3_step(stmt) != SQLITE_DONE) { \
+ _E("sqlite3_step() is failed. error(%s)", \
+ sqlite3_errmsg(db)); \
+ sqlite3_finalize(stmt); \
+ return -1; \
+ } \
+} while (0)
+
+char *_db_get_path(const char *file, uid_t uid);
+
+sqlite3 *_db_open(const char *path, bool readonly);
+
+void _db_close(sqlite3* db);
+
+int _db_verify(const char *path, const char **tables, int table_count);
+
+int _db_recovery(const char *path, const char *query, uid_t uid);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __DB_INTERNAL_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.
- */
-
-#define _GNU_SOURCE
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdbool.h>
-#include <string.h>
-#include <ctype.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <glib.h>
-#include <bundle.h>
-#include <bundle_internal.h>
-#include <tzplatform_config.h>
-
-#include "aul.h"
-#include "aul_api.h"
-#include "aul_app_com.h"
-#include "aul_cmd.h"
-#include "aul_error.h"
-#include "aul_sock.h"
-#include "aul_util.h"
-#include "aul_widget.h"
-#include "launch.h"
-
-struct aul_widget_info_s {
- char *widget_id;
- char *instance_id;
- char *app_id;
- char *package_id;
- char *app_path;
- unsigned int surf;
- pid_t pid;
-};
-
-struct widget_cb_info {
- aul_widget_info_cb callback;
- void *user_data;
-};
-
-struct widget_event_s {
- aul_app_com_connection_h conn;
- aul_widget_event_cb callback;
- void *user_data;
-};
-
-#define WIDGET_LOG_BUFFER_SIZE 10000
-#define WIDGET_LOG_BUFFER_STRING_SIZE 256
-
-static int __log_index;
-static int __log_fd;
-static bool __log_init = false;
-static struct widget_event_s __event;
-
-static int __init_log(void)
-{
- int offset;
- char buffer[512] = {0, };
- char caller[255] = {0, };
- int ret;
-
- ret = aul_app_get_appid_bypid(getpid(), caller, sizeof(caller));
- if (ret != AUL_R_OK) {
- _E("Failed to get appid by pid(%d)", getpid());
- return -1;
- }
-
- snprintf(buffer, sizeof(buffer),
- "/run/aul/log/widget/%d/widget_%s.log", getuid(), caller);
- __log_fd = open(buffer, O_CREAT | O_WRONLY, 0644);
- if (__log_fd < 0) {
- _E("Failed to open %s - %d", buffer, errno);
- return -1;
- }
-
- offset = lseek(__log_fd, 0, SEEK_END);
- if (offset != 0) {
- __log_index = (int)(offset / WIDGET_LOG_BUFFER_STRING_SIZE);
- if (__log_index >= WIDGET_LOG_BUFFER_SIZE) {
- __log_index = 0;
- lseek(__log_fd, 0, SEEK_SET);
- }
- }
- __log_init = true;
-
- return 0;
-}
-
-API int aul_widget_write_log(const char *tag, const char *format, ...)
-{
- int ret;
- int offset;
- time_t now;
- char time_buf[32] = {0,};
- char format_buffer[WIDGET_LOG_BUFFER_STRING_SIZE];
- char buffer[WIDGET_LOG_BUFFER_SIZE];
- va_list ap;
-
- if (!__log_init)
- __init_log();
-
- if (__log_fd < 0) {
- _E("Invalid file descriptor");
- return -1;
- }
-
- time(&now);
- ctime_r(&now, time_buf);
- if (__log_index != 0)
- offset = lseek(__log_fd, 0, SEEK_CUR);
- else
- offset = lseek(__log_fd, 0, SEEK_SET);
-
- if (offset == -1)
- _E("error in lseek: %d", errno);
-
-
- va_start(ap, format);
- vsnprintf(format_buffer, sizeof(format_buffer), format, ap);
- va_end(ap);
-
- snprintf(buffer, sizeof(buffer), "[%-6d][%-5d] %-15s %-50s %s",
- getpid(), __log_index, tag, format_buffer, time_buf);
-
- ret = write(__log_fd, buffer, strlen(buffer));
- if (ret < 0) {
- _E("Cannot write the amd log: %d", ret);
- return -1;
- }
-
- if (++__log_index >= WIDGET_LOG_BUFFER_SIZE)
- __log_index = 0;
-
- return 0;
-}
-
-static const char *__to_appid(const char *widget_id)
-{
- const char *appid;
- appid = g_strstr_len(widget_id, strlen(widget_id), "@") + 1;
- if (appid != (const char *)1) {
- if (appid > widget_id + (sizeof(char) * strlen(widget_id)))
- appid = (char *)widget_id;
- } else {
- appid = (char *)widget_id;
- }
-
- return appid;
-}
-
-API int aul_widget_instance_add(const char *widget_id, const char *instance_id)
-{
- int ret;
- bundle *kb;
-
- if (widget_id == NULL || instance_id == NULL)
- return AUL_R_EINVAL;
-
- kb = bundle_create();
- if (kb == NULL) {
- _E("out of memory");
- return AUL_R_ERROR;
- }
-
- bundle_add_str(kb, AUL_K_WIDGET_ID, widget_id);
- bundle_add_str(kb, AUL_K_WIDGET_INSTANCE_ID, instance_id);
-
- ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), WIDGET_ADD, kb,
- AUL_SOCK_NONE);
-
- bundle_free(kb);
- if (ret < 0)
- return aul_error_convert(ret);
-
- return AUL_R_OK;
-}
-
-API int aul_widget_instance_del(const char *widget_id, const char *instance_id)
-{
- int ret;
- bundle *kb;
-
- if (widget_id == NULL || instance_id == NULL)
- return AUL_R_EINVAL;
-
- kb = bundle_create();
- if (kb == NULL) {
- _E("out of memory");
- return AUL_R_ERROR;
- }
-
- bundle_add_str(kb, AUL_K_WIDGET_ID, widget_id);
- bundle_add_str(kb, AUL_K_WIDGET_INSTANCE_ID, instance_id);
-
- ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), WIDGET_DEL, kb,
- AUL_SOCK_NONE);
-
- bundle_free(kb);
- if (ret < 0)
- return aul_error_convert(ret);
-
- return AUL_R_OK;
-}
-
-struct __cb_data {
- aul_widget_instance_foreach_cb cb;
- void *data;
-};
-
-static void __foreach_cb(const char *key, const int type,
- const bundle_keyval_t *kv, void *user_data)
-{
- struct __cb_data *cb_data = (struct __cb_data *)user_data;
-
- cb_data->cb(key, cb_data->data);
-}
-
-API int aul_widget_instance_foreach(const char *widget_id,
- aul_widget_instance_foreach_cb cb, void *data)
-{
- int ret;
- int fd;
- bundle *kb;
- app_pkt_t *pkt = NULL;
- bundle *list_kb = NULL;
- struct __cb_data cb_data;
-
- if (widget_id == NULL)
- return AUL_R_EINVAL;
-
- kb = bundle_create();
- if (kb == NULL) {
- _E("out of memory");
- return AUL_R_ERROR;
- }
-
- bundle_add_str(kb, AUL_K_APPID, __to_appid(widget_id));
- bundle_add_str(kb, AUL_K_WIDGET_ID, widget_id);
-
- fd = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), WIDGET_LIST, kb,
- AUL_SOCK_ASYNC);
-
- if (fd > 0) {
- ret = aul_sock_recv_reply_pkt(fd, &pkt);
- if (ret < 0 || pkt == NULL) {
- _E("failed to get instance list of %s", widget_id);
- } else {
- list_kb = bundle_decode(pkt->data, pkt->len);
- if (list_kb) {
- cb_data.cb = cb;
- cb_data.data = data;
- bundle_foreach(list_kb, __foreach_cb, &cb_data);
- bundle_free(list_kb);
- }
- }
- } else {
- ret = fd;
- }
-
- if (pkt)
- free(pkt);
-
- bundle_free(kb);
-
- if (ret < 0)
- return aul_error_convert(ret);
-
- return AUL_R_OK;
-}
-
-API int aul_widget_instance_update(const char *widget_id,
- const char *instance_id, bundle *param)
-{
- int ret;
- bundle *kb = param;
- const char *appid;
-
- if (widget_id == NULL)
- return AUL_R_EINVAL;
-
- if (kb == NULL)
- kb = bundle_create();
-
- if (kb == NULL) {
- _E("out of memory");
- return AUL_R_ERROR;
- }
-
- appid = __to_appid(widget_id);
-
- bundle_add_str(kb, AUL_K_WIDGET_ID, widget_id);
-
- if (instance_id)
- bundle_add_str(kb, AUL_K_WIDGET_INSTANCE_ID, instance_id);
-
- ret = app_request_to_launchpad_for_uid(WIDGET_UPDATE, appid, kb,
- getuid());
-
- if (param == NULL)
- bundle_free(kb);
-
- return ret;
-}
-
-API int aul_widget_instance_get_content(const char *widget_id,
- const char *instance_id, char **content)
-{
- int ret;
- bundle *kb;
- int fd[2] = { 0, };
- app_pkt_t *pkt = NULL;
-
- if (widget_id == NULL || instance_id == NULL || content == NULL)
- return AUL_R_EINVAL;
-
- kb = bundle_create();
- if (kb == NULL) {
- _E("out of memory");
- return AUL_R_ERROR;
- }
-
- bundle_add_str(kb, AUL_K_APPID, __to_appid(widget_id));
- bundle_add_str(kb, AUL_K_WIDGET_ID, widget_id);
- bundle_add_str(kb, AUL_K_WIDGET_INSTANCE_ID, instance_id);
-
- ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), WIDGET_GET_CONTENT,
- kb, AUL_SOCK_ASYNC);
- if (ret > 0) {
- ret = aul_sock_recv_reply_sock_fd(ret, &fd, 1);
- if (ret == 0) {
- ret = aul_sock_recv_reply_pkt(fd[0], &pkt);
- if (ret == 0 && pkt && pkt->cmd == 0) {
- *content = strdup((const char *)pkt->data);
- _D("recieved content: %s", *content);
- } else {
- if (pkt)
- ret = pkt->cmd;
-
- _E("failed to get content");
- }
- } else {
- _E("failed to get socket fd:%d", ret);
- }
- }
-
- bundle_free(kb);
-
- if (pkt)
- free(pkt);
- if (ret < 0)
- ret = aul_error_convert(ret);
-
- return ret;
-}
-
-API int aul_widget_instance_count(const char *widget_id)
-{
- int ret;
- bundle *kb;
-
- if (widget_id == NULL)
- return AUL_R_EINVAL;
-
- kb = bundle_create();
- if (kb == NULL) {
- _E("out of memory");
- return AUL_R_ERROR;
- }
-
- bundle_add_str(kb, AUL_K_WIDGET_ID, widget_id);
- ret = app_send_cmd(AUL_UTIL_PID, WIDGET_COUNT, kb);
- bundle_free(kb);
-
- return ret;
-}
-
-static void __foreach_widget_info(app_pkt_t *pkt, void *user_data)
-{
- struct widget_cb_info *cb_info = (struct widget_cb_info *)user_data;
- struct aul_widget_info_s info = { 0, };
- bundle *b = NULL;
- const char *val;
-
- if (pkt == NULL || cb_info == NULL) {
- _E("Invalid parameter");
- return;
- }
-
- if (pkt->cmd == APP_GET_INFO_ERROR) {
- _E("Failed to get widget info");
- return;
- }
-
- if (pkt->opt & AUL_SOCK_BUNDLE)
- b = bundle_decode(pkt->data, pkt->len);
-
- if (b == NULL)
- return;
-
- bundle_get_str(b, AUL_K_WIDGET_ID, &info.widget_id);
- if (info.widget_id == NULL) {
- bundle_free(b);
- return;
- }
-
- bundle_get_str(b, AUL_K_WIDGET_INSTANCE_ID, &info.instance_id);
- if (info.instance_id == NULL) {
- bundle_free(b);
- return;
- }
-
- bundle_get_str(b, AUL_K_APPID, &info.app_id);
- if (info.app_id == NULL) {
- bundle_free(b);
- return;
- }
-
- bundle_get_str(b, AUL_K_PKGID, &info.package_id);
- if (info.package_id == NULL) {
- bundle_free(b);
- return;
- }
-
- bundle_get_str(b, AUL_K_EXEC, &info.app_path);
- if (info.app_path == NULL) {
- bundle_free(b);
- return;
- }
-
- val = bundle_get_val(b, AUL_K_WID);
- if (val && isdigit(*val))
- info.surf = strtoul(val, NULL, 10);
-
- val = bundle_get_val(b, AUL_K_PID);
- if (val && isdigit(*val))
- info.pid = atoi(val);
-
- cb_info->callback(&info, cb_info->user_data);
-
- bundle_free(b);
-}
-
-API int aul_widget_info_foreach_for_uid(aul_widget_info_cb callback,
- void *user_data, uid_t uid)
-{
- struct widget_cb_info cb_info = {callback, user_data};
- char buf[MAX_PID_STR_BUFSZ];
- bundle *b;
- int fd;
- int r;
-
- if (callback == NULL) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- b = bundle_create();
- if (b == NULL) {
- _E("Out of memory");
- return AUL_R_ERROR;
- }
-
- snprintf(buf, sizeof(buf), "%u", uid);
- r = bundle_add_str(b, AUL_K_TARGET_UID, buf);
- if (r != BUNDLE_ERROR_NONE) {
- _E("Failed to add target uid(%u)", uid);
- bundle_free(b);
- return AUL_R_ERROR;
- }
-
- fd = aul_sock_send_bundle(AUL_UTIL_PID, uid, WIDGET_RUNNING_INFO,
- b, AUL_SOCK_ASYNC);
- if (fd < 0) {
- bundle_free(b);
- return aul_error_convert(fd);
- }
- bundle_free(b);
-
- r = aul_sock_recv_pkt_with_cb(fd, __foreach_widget_info, &cb_info);
- if (r < 0)
- return aul_error_convert(r);
-
- return AUL_R_OK;
-}
-
-API int aul_widget_info_foreach(aul_widget_info_cb callback, void *user_data)
-{
- return aul_widget_info_foreach_for_uid(callback, user_data, getuid());
-}
-
-API int aul_widget_info_get_pid(aul_widget_info_h info, pid_t *pid)
-{
- if (info == NULL || pid == NULL) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- *pid = info->pid;
-
- return AUL_R_OK;
-}
-
-API int aul_widget_info_get_surface_id(aul_widget_info_h info,
- unsigned int *surf)
-{
- if (info == NULL || surf == NULL) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- *surf = info->surf;
-
- return AUL_R_OK;
-}
-
-API int aul_widget_info_get_widget_id(aul_widget_info_h info, char **widget_id)
-{
- if (info == NULL || widget_id == NULL) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- *widget_id = strdup(info->widget_id);
- if (*widget_id == NULL) {
- _E("Out of memory");
- return AUL_R_ERROR;
- }
-
- return AUL_R_OK;
-}
-
-API int aul_widget_info_get_instance_id(aul_widget_info_h info,
- char **instance_id)
-{
- if (info == NULL || instance_id == NULL) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- *instance_id = strdup(info->instance_id);
- if (*instance_id == NULL) {
- _E("Out of memory");
- return AUL_R_ERROR;
- }
-
- return AUL_R_OK;
-}
-
-API int aul_widget_info_get_app_id(aul_widget_info_h info, char **app_id)
-{
- if (info == NULL || app_id == NULL) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- *app_id = strdup(info->app_id);
- if (*app_id == NULL) {
- _E("Out of memory");
- return AUL_R_ERROR;
- }
-
- return AUL_R_OK;
-}
-
-API int aul_widget_info_get_package_id(aul_widget_info_h info,
- char **package_id)
-{
- if (info == NULL || package_id == NULL) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- *package_id = strdup(info->package_id);
- if (*package_id == NULL) {
- _E("Out of memory");
- return AUL_R_ERROR;
- }
-
- return AUL_R_OK;
-}
-
-API int aul_widget_info_get_app_path(aul_widget_info_h info, char **app_path)
-{
- if (info == NULL || app_path == NULL) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- *app_path = strdup(info->app_path);
- if (*app_path == NULL) {
- _E("Out of memory");
- return AUL_R_ERROR;
- }
-
- return AUL_R_OK;
-}
-
-API int aul_widget_instance_change_status(const char *widget_id,
- const char *status)
-{
- int ret;
- bundle *kb;
-
- kb = bundle_create();
- if (kb == NULL) {
- _E("out of memory");
- return AUL_R_ERROR;
- }
-
- bundle_add_str(kb, AUL_K_STATUS, status);
- bundle_add_str(kb, AUL_K_WIDGET_ID, widget_id);
- ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(),
- WIDGET_CHANGE_STATUS, kb, AUL_SOCK_NOREPLY);
-
- bundle_free(kb);
- if (ret < 0) {
- _E("send error %d, %s", ret, status);
- return aul_error_convert(ret);
- }
-
- return AUL_R_OK;
-}
-
-API int aul_widget_service_set_disable(const char *widget_id, bool is_disable)
-{
- int ret;
- bundle *kb;
- char ambient_mode[32] = {0, };
-
- if (widget_id == NULL)
- return AUL_R_EINVAL;
-
- kb = bundle_create();
- if (kb == NULL) {
- _E("out of memory");
- return AUL_R_ERROR;
- }
-
- snprintf(ambient_mode, sizeof(ambient_mode), "%d", (int)is_disable);
-
- bundle_add_str(kb, AUL_K_APPID, __to_appid(widget_id));
- bundle_add_str(kb, AUL_K_WIDGET_ID, widget_id);
- bundle_add_str(kb, AUL_K_WIDGET_DISABLE, ambient_mode);
-
- ret = app_send_cmd(AUL_UTIL_PID, WIDGET_DISABLE, kb);
- if (ret)
- _E("widget disable send cmd error");
-
- bundle_free(kb);
-
- return ret;
-}
-
-static int __aul_widget_event_cb(const char *endpoint,
- aul_app_com_result_e result,
- bundle *envelope,
- void *user_data)
-{
- const char *event_name;
- const char *event_data_raw;
- bundle *event_data;
-
- event_name = bundle_get_val(envelope, AUL_K_EVENT_NAME);
- if (!event_name) {
- _E("Failed to get event name");
- return -1;
- }
-
- event_data_raw = bundle_get_val(envelope, AUL_K_EVENT_DATA);
- if (!event_data_raw) {
- _E("Failed to get event data");
- return -1;
- }
-
- event_data = bundle_decode((const bundle_raw *)event_data_raw,
- strlen(event_data_raw));
- if (!event_data) {
- _E("Failed to decode event data");
- return -1;
- }
-
- if (__event.callback)
- __event.callback(event_name, event_data, __event.user_data);
-
- bundle_free(event_data);
-
- return 0;
-}
-
-static int __register_widget_event(void)
-{
- int ret;
-
- if (!__event.conn) {
- ret = aul_app_com_create("widget.event", NULL,
- __aul_widget_event_cb, NULL,
- &__event.conn);
- if (ret != AUL_R_OK) {
- _E("Failed to join aul app com");
- return ret;
- }
- }
-
- return AUL_R_OK;
-}
-
-static int __unregister_widget_event(void)
-{
- if (__event.conn) {
- aul_app_com_leave(__event.conn);
- __event.conn = NULL;
- }
-
- return AUL_R_OK;
-}
-
-API int aul_widget_set_event_cb(aul_widget_event_cb callback, void *user_data)
-{
- if (!callback) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- __event.callback = callback;
- __event.user_data = user_data;
-
- return __register_widget_event();
-}
-
-API int aul_widget_unset_event_cb(void)
-{
- __event.callback = NULL;
- __event.user_data = NULL;
-
- return __unregister_widget_event();
-}
-
-API int aul_widget_send_event(const char *event_name, bundle *event_data)
-{
- bundle *b;
- bundle_raw *raw = NULL;
- int len = 0;
- int ret;
-
- if (!event_name || !event_data) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- b = bundle_create();
- if (!b) {
- _E("Out of memory");
- return AUL_R_ENOMEM;
- }
-
- bundle_add(b, AUL_K_EVENT_NAME, event_name);
-
- bundle_encode(event_data, &raw, &len);
- if (!raw) {
- _E("Failed to encode event data");
- bundle_free(b);
- return AUL_R_ERROR;
- }
-
- bundle_add(b, AUL_K_EVENT_DATA, (const char *)raw);
- free(raw);
-
- ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), WIDGET_EVENT, b,
- AUL_SOCK_NOREPLY);
- bundle_free(b);
- if (ret != 0) {
- _E("Failed to send widget event. error(%d)", ret);
- return aul_error_convert(ret);
- }
-
- return AUL_R_OK;
-}
-
-API int aul_widget_send_status_to_viewer(const char *class_id,
- const char *instance_id, const char *viewer_endpoint,
- int status, int err, bundle *extra)
-{
- bundle *data;
- bundle_raw *raw = NULL;
- int len;
- char err_str[256];
- int ret;
-
- data = bundle_create();
- if (!data) {
- _E("out of memory");
- return -1;
- }
-
- if (err < 0) {
- snprintf(err_str, sizeof(err_str), "%d", err);
- bundle_add_str(data, AUL_K_WIDGET_ERROR_CODE, err_str);
- }
-
- bundle_add_str(data, AUL_K_WIDGET_ID, class_id);
- bundle_add_str(data, AUL_K_WIDGET_INSTANCE_ID, instance_id);
- bundle_add_byte(data, AUL_K_WIDGET_STATUS, &status, sizeof(int));
-
- if (extra) {
- bundle_encode(extra, &raw, &len);
- bundle_add_str(data,
- "__WIDGET_CONTENT_INFO__", (const char *)raw);
- free(raw);
- ret = aul_widget_instance_add(class_id, instance_id);
- if (ret != 0) {
- _E("Failed to add instance. error(%d)", ret);
- bundle_free(data);
- return aul_error_convert(ret);
- }
- }
-
- LOGD("send update %s(%d) to %s", instance_id, status, viewer_endpoint);
- ret = aul_app_com_send(viewer_endpoint, data);
- bundle_free(data);
- if (ret != 0) {
- _E("Failed to add instance. error(%d)", ret);
- return aul_error_convert(ret);
- }
-
- return 0;
-}
-
-API int aul_widget_send_status_to_service(const char *class_id,
- const char *instance_id, const char *sender_pkgid, int status)
-{
- bundle *data = bundle_create();
- int ret;
-
- if (data == NULL) {
- _E("out of memory");
- return -1;
- }
-
- bundle_add_str(data, AUL_K_WIDGET_ID, class_id);
- bundle_add_str(data, AUL_K_WIDGET_INSTANCE_ID, instance_id);
- bundle_add_byte(data, AUL_K_WIDGET_STATUS, &status, sizeof(int));
- bundle_add_str(data, AUL_K_PKGID, sender_pkgid);
-
- LOGD("send lifecycle %s(%d)", instance_id, status);
- ret = aul_app_com_send("widget.status", data);
- if (ret < 0)
- _E("send lifecycle error:%d", ret);
-
- bundle_free(data);
- return 0;
-}
${APP_CONTROL_TESTS_SRCS})
TARGET_INCLUDE_DIRECTORIES(${TARGET_APP_CONTROL_TESTS} PUBLIC
- "${CMAKE_CURRENT_SOURCE_DIR}/mock"
- "${CMAKE_CURRENT_SOURCE_DIR}/../"
- "${CMAKE_CURRENT_SOURCE_DIR}/../../include"
- "${CMAKE_CURRENT_SOURCE_DIR}/../../src"
+ ${CMAKE_CURRENT_SOURCE_DIR}/mock
+ ${CMAKE_CURRENT_SOURCE_DIR}/../
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../src/aul/include
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../src/aul
)
APPLY_PKG_CONFIG(${TARGET_APP_CONTROL_TESTS} PUBLIC
)
TARGET_INCLUDE_DIRECTORIES(${TARGET_AUL_UNIT_TESTS} PUBLIC
- "${CMAKE_CURRENT_SOURCE_DIR}/../"
- "${CMAKE_CURRENT_SOURCE_DIR}/../../"
- "${CMAKE_CURRENT_SOURCE_DIR}/../../include"
- "${CMAKE_CURRENT_SOURCE_DIR}/../../src"
- "${CMAKE_CURRENT_SOURCE_DIR}/../../aul"
- "${CMAKE_CURRENT_SOURCE_DIR}/../../aul/api"
+ ${CMAKE_CURRENT_SOURCE_DIR}/../
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../src/aul/include
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../src/aul
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../src/aul/api
)
APPLY_PKG_CONFIG(${TARGET_AUL_UNIT_TESTS} PUBLIC
#include <aul_app_com.h>
#include <aul_cmd.h>
#include <aul_sock.h>
-#include <gtest/gtest.h>
-
#include <bundle_cpp.h>
+#include <gtest/gtest.h>
#include <memory>
+#include "aul/launch.h"
#include "mock/mock_hook.h"
#include "mock/socket_mock.h"
#include "mock/test_fixture.h"
-#include "src/launch.h"
using ::testing::_;
using ::testing::DoAll;
#include <aul_app_group.h>
#include <aul_cmd.h>
#include <aul_sock.h>
+#include <bundle_cpp.h>
#include <gtest/gtest.h>
#include <stdlib.h>
-#include <bundle_cpp.h>
-
#include <iostream>
#include <memory>
+#include "aul/launch.h"
#include "mock/mock_hook.h"
#include "mock/socket_mock.h"
#include "mock/test_fixture.h"
-#include "src/launch.h"
using ::testing::_;
using ::testing::DoAll;
* limitations under the License.
*/
-#include <aul_comp_context.h>
#include <aul_cmd.h>
+#include <aul_comp_context.h>
#include <aul_sock.h>
+#include <bundle_cpp.h>
#include <gtest/gtest.h>
#include <stdlib.h>
-#include <bundle_cpp.h>
-
#include <iostream>
#include <memory>
+#include "aul/launch.h"
#include "mock/mock_hook.h"
#include "mock/socket_mock.h"
#include "mock/test_fixture.h"
-#include "src/launch.h"
using ::testing::_;
using ::testing::DoAll;
#include <aul_cmd.h>
#include <aul_comp_info.h>
#include <aul_sock.h>
+#include <bundle_cpp.h>
#include <gtest/gtest.h>
#include <stdlib.h>
-#include <bundle_cpp.h>
-
#include <iostream>
#include <memory>
+#include "aul/launch.h"
#include "mock/mock_hook.h"
#include "mock/socket_mock.h"
#include "mock/test_fixture.h"
#include "mock/vconf_mock.h"
-#include "src/launch.h"
using ::testing::_;
using ::testing::DoAll;
#include <aul_cmd.h>
#include <aul_comp_status.h>
#include <aul_sock.h>
+#include <bundle_cpp.h>
#include <gtest/gtest.h>
#include <stdlib.h>
-#include <bundle_cpp.h>
-
#include <iostream>
#include <memory>
+#include "aul/launch.h"
#include "mock/mock_hook.h"
#include "mock/socket_mock.h"
#include "mock/test_fixture.h"
-#include "src/launch.h"
using ::testing::_;
using ::testing::DoAll;
#include <aul_cmd.h>
#include <aul_complication.h>
#include <aul_sock.h>
+#include <bundle_cpp.h>
#include <gtest/gtest.h>
#include <stdlib.h>
-#include <bundle_cpp.h>
-
+#include "aul/launch.h"
#include "mock/mock_hook.h"
#include "mock/socket_mock.h"
#include "mock/test_fixture.h"
-#include "src/launch.h"
using ::testing::_;
using ::testing::DoAll;
#include <aul_cmd.h>
#include <aul_job_scheduler.h>
#include <aul_sock.h>
+#include <bundle_cpp.h>
#include <gtest/gtest.h>
#include <stdlib.h>
-#include <bundle_cpp.h>
-
#include <iostream>
#include <memory>
+#include "aul/launch.h"
#include "mock/mock_hook.h"
#include "mock/socket_mock.h"
#include "mock/test_fixture.h"
-#include "src/launch.h"
using ::testing::_;
using ::testing::DoAll;
* limitations under the License.
*/
+#include <aul.h>
+#include <aul_cmd.h>
+#include <aul_sock.h>
#include <bundle_cpp.h>
#include <gtest/gtest.h>
#include <stdlib.h>
#include <iostream>
#include <memory>
-#include <aul.h>
-#include <aul_sock.h>
-#include <aul_cmd.h>
-#include "launch.h"
+#include "aul/launch.h"
#include "mock/dbus_mock.h"
#include "mock/glib_mock.h"
#include "mock/mock_hook.h"
* limitations under the License.
*/
-#include <stdlib.h>
+#include <aul.h>
+#include <aul_cmd.h>
+#include <aul_sock.h>
+#include <bundle_cpp.h>
#include <gtest/gtest.h>
+#include <stdlib.h>
-#include <bundle_cpp.h>
#include <iostream>
#include <memory>
-#include <aul.h>
-#include <aul_sock.h>
-#include <aul_cmd.h>
-#include "launch.h"
+#include "aul/launch.h"
#include "mock/dbus_mock.h"
#include "mock/glib_mock.h"
#include "mock/mock_hook.h"
#include <aul_cmd.h>
#include <aul_launcher_service.h>
#include <aul_sock.h>
+#include <bundle_cpp.h>
#include <glib.h>
#include <gtest/gtest.h>
-#include <bundle_cpp.h>
-
#include <string>
+#include "aul/launch.h"
#include "mock/mock_hook.h"
#include "mock/socket_mock.h"
#include "mock/test_fixture.h"
-#include "src/launch.h"
using ::testing::_;
using ::testing::DoAll;
#include <aul.h>
#include <aul_cmd.h>
#include <aul_sock.h>
+#include <bundle_cpp.h>
#include <gtest/gtest.h>
#include <stdlib.h>
-#include <bundle_cpp.h>
-
#include <iostream>
#include <memory>
-#include "mock/mock_hook.h"
+#include "aul/launch.h"
#include "mock/glib_mock.h"
+#include "mock/mock_hook.h"
#include "mock/socket_mock.h"
#include "mock/test_fixture.h"
-#include "src/launch.h"
using ::testing::_;
using ::testing::DoAll;
#include <aul.h>
#include <aul_cmd.h>
#include <aul_sock.h>
-#include <gtest/gtest.h>
-
#include <bundle_cpp.h>
+#include <gtest/gtest.h>
+#include "aul/launch.h"
#include "mock/mock_hook.h"
#include "mock/socket_mock.h"
#include "mock/test_fixture.h"
-#include "src/launch.h"
using ::testing::_;
using ::testing::DoAll;
*/
#include <aul.h>
-#include <aul_watchdog.h>
#include <aul_cmd.h>
#include <aul_sock.h>
+#include <aul_watchdog.h>
+#include <bundle_cpp.h>
#include <gtest/gtest.h>
#include <stdlib.h>
-#include <bundle_cpp.h>
-
#include <iostream>
#include <memory>
+#include "aul/launch.h"
#include "mock/mock_hook.h"
#include "mock/socket_mock.h"
#include "mock/test_fixture.h"
-#include "src/launch.h"
using ::testing::_;
using ::testing::DoAll;
+++ /dev/null
-ADD_SUBDIRECTORY(app_com_tool)
-ADD_SUBDIRECTORY(app_launcher)
-ADD_SUBDIRECTORY(appgroup_info)
-ADD_SUBDIRECTORY(appid2pid)
-ADD_SUBDIRECTORY(aul_test)
-ADD_SUBDIRECTORY(aul_window)
-ADD_SUBDIRECTORY(aulctl)
-ADD_SUBDIRECTORY(compmgr_tool)
-ADD_SUBDIRECTORY(launch_app)
-ADD_SUBDIRECTORY(launch_debug)
-ADD_SUBDIRECTORY(open_app)
-ADD_SUBDIRECTORY(recovery)
+++ /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
-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 "aul_sock.h"
-#include "launch.h"
-
-#define LAUNCHPAD_PROCESS_POOL_SOCK ".launchpad-process-pool-sock"
-#define PATH_AUL_DAEMONS "/run/aul/daemons"
-#define PATH_AMD_READY "/run/.amd_ready"
-#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_init(struct launch_arg *arg)
-{
- char buf[PATH_MAX];
- int retry_count = 0;
-
- if (__set_appinfo_for_launchpad(arg->b, arg->appid, arg->uid) < 0) {
- fprintf(stderr, "Failed to set appinfo. appid(%s), uid(%u)\n",
- arg->appid, arg->uid);
- return -1;
- }
-
- snprintf(buf, sizeof(buf), "/run/aul/daemons/%u/%s",
- arg->uid, LAUNCHPAD_PROCESS_POOL_SOCK);
- while (access(buf, F_OK) != 0) {
- usleep(100 * 1000);
- if (++retry_count > 100) {
- fprintf(stderr, "%s is not created\n", buf);
- break;
- }
- }
-
- return 0;
-}
-
-static int __cmd_fast_start_run(struct launch_arg *arg)
-{
- int fd;
-
- if (!access(PATH_AMD_READY, F_OK)) {
- bundle_del(arg->b, AUL_K_FAST_LAUNCH);
- return __cmd_start_run(arg);
- }
-
- fd = aul_sock_create_launchpad_client_without_timeout(
- LAUNCHPAD_PROCESS_POOL_SOCK, arg->uid);
- if (fd < 0) {
- fprintf(stderr, "Failed to create client socket. error: %d\n",
- fd);
- return -1;
- }
-
- arg->pid = aul_sock_send_bundle_with_fd(fd, 0, arg->b, AUL_SOCK_NONE);
- if (arg->pid <= 0) {
- fprintf(stderr, "... 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_fast_start_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
-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
-SET(TARGET_AUL_TEST "aul_test")
-
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} AUL_TEST_SRCS)
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/tests TESTS_SRCS)
-
-ADD_EXECUTABLE(${TARGET_AUL_TEST}
- ${AUL_TEST_SRCS}
- ${TESTS_SRCS}
-)
-
-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}/
- ${CMAKE_CURRENT_SOURCE_DIR}/../../
- ${CMAKE_CURRENT_SOURCE_DIR}/../../aul/api
- ${CMAKE_CURRENT_SOURCE_DIR}/../../include
- ${CMAKE_CURRENT_SOURCE_DIR}/../../src
-)
-
-INSTALL(TARGETS ${TARGET_AUL_TEST} DESTINATION bin)
+++ /dev/null
-/*
- * Copyright (c) 2021 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 "aul_test.hh"
-
-#include <iostream>
-
-#include "log_private.hh"
-
-namespace aul_test {
-
-AulTest::AulTest(std::string test_name, std::string func_name,
- std::string usage, bool loop_quit)
- : test_name_(std::move(test_name)),
- func_name_(std::move(func_name)),
- usage_(std::move(usage)),
- loop_quit_(loop_quit) {
- AulTestMgr::GetInst().AddTest(test_name_, this);
-}
-
-void AulTest::Usage() {
- _E("\t%s : %s test", test_name_.c_str(), func_name_.c_str());
- _E("\t\t[usage] %s", usage_.c_str());
-}
-
-tizen_base::Bundle AulTest::CreateBundleFromArgv(int argc, char** argv,
- int start) {
- tizen_base::Bundle b;
- for (int i = start; i < argc - 1; ++i) {
- if ((i + 1) > argc - 1)
- b.Add(std::string(argv[i]), " ");
- else
- b.Add(std::string(argv[i]), std::string(argv[i + 1]));
- }
-
- return b;
-}
-
-bool AulTest::LoopQuit() const {
- return loop_quit_;
-}
-
-AulTestMgr::AulTestMgr() {
- loop_ = g_main_loop_new(nullptr, FALSE);
-}
-
-AulTestMgr::~AulTestMgr() {
- if (loop_) {
- if (g_main_loop_is_running(loop_))
- g_main_loop_quit(loop_);
-
- g_main_loop_unref(loop_);
- }
-}
-
-AulTestMgr& AulTestMgr::GetInst() {
- static AulTestMgr inst;
- return inst;
-}
-
-void AulTestMgr::AddTest(const std::string& test_name, AulTest* aul_test) {
- tests_[test_name] = aul_test;
-}
-
-int AulTestMgr::RunTest(int argc, char** argv) {
- if (argc < 2) {
- PrintUsage();
- return -1;
- }
-
- argc_ = argc;
- argv_ = argv;
- g_idle_add(IdleCb, this);
- g_main_loop_run(loop_);
- return result_;
-}
-
-void AulTestMgr::PrintUsage() {
- for (auto const& iter : tests_) {
- auto* test = iter.second;
- test->Usage();
- }
-}
-
-int AulTestMgr::RunTest() {
- std::string cmd(argv_[1]);
- auto found = tests_.find(cmd);
- if (found == tests_.end()) {
- PrintUsage();
- g_main_loop_quit(loop_);
- return -1;
- }
-
- auto* test = found->second;
- test->SetUp();
- int ret = test->Test(argc_, argv_);
- test->TearDown();
- if (ret < 0) {
- _E("... test failed");
- g_main_loop_quit(loop_);
- } else {
- _E("... test successful ret = %d", ret);
- if (test->LoopQuit())
- g_main_loop_quit(loop_);
- }
-
- return ret;
-}
-
-gboolean AulTestMgr::IdleCb(gpointer user_data) {
- auto* mgr = static_cast<AulTestMgr*>(user_data);
- mgr->result_ = mgr->RunTest();
- return G_SOURCE_REMOVE;
-}
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 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_TEST_AUL_TEST_HH_
-#define AUL_TEST_AUL_TEST_HH_
-
-#include <bundle_cpp.h>
-#include <bundle_internal.h>
-#include <glib.h>
-
-#include <map>
-#include <string>
-
-#include "aul_test_private.hh"
-
-namespace aul_test {
-
-class AulTest {
- public:
- explicit AulTest(std::string test_name, std::string func_name,
- std::string usage, bool loop_quit = true);
- virtual ~AulTest() = default;
- virtual void SetUp() {}
- virtual void TearDown() {}
- virtual void Usage();
- virtual int Test(int argc, char** argv) = 0;
- tizen_base::Bundle CreateBundleFromArgv(int argc, char** argv, int start);
- bool LoopQuit() const;
-
- private:
- std::string test_name_;
- std::string func_name_;
- std::string usage_;
- bool loop_quit_;
-};
-
-class AulTestMgr {
- private:
- AulTestMgr();
- ~AulTestMgr();
-
- public:
- static AulTestMgr& GetInst();
-
- void AddTest(const std::string& test_name, AulTest* test);
- int RunTest(int argc, char** argv);
-
- private:
- void PrintUsage();
- int RunTest();
- static gboolean IdleCb(gpointer user_data);
-
- private:
- std::map<std::string, AulTest*> tests_;
- GMainLoop* loop_ = nullptr;
- int argc_ = 0;
- char** argv_ = nullptr;
- int result_ = 0;
-};
-
-} // namespace aul_test
-
-#endif // AUL_TEST_AUL_TEST_HH_
+++ /dev/null
-/*
- * Copyright (c) 2021 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_TEST_AUL_TEST_PRIVATE_HH_
-#define AUL_TEST_AUL_TEST_PRIVATE_HH_
-
-#define AUL_TEST_REGISTER(test_case_name, test_name) \
- test_case_name test_name
-
-#endif // AUL_TEST_AUL_TEST_PRIVATE_HH_
+++ /dev/null
-/*
- * Copyright (c) 2021 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_TEST_LOG_PRIVATE_HH_
-#define AUL_TEST_LOG_PRIVATE_HH_
-
-#include <stdio.h>
-
-#undef _E
-#define _E(fmt, arg...) fprintf(stderr, fmt "\n", ##arg)
-
-#undef _W
-#define _W(fmt, arg...) fprintf(stderr, fmt "\n", ##arg)
-
-#undef _I
-#define _I(fmt, arg...) fprintf(stdout, fmt "\n", ##arg)
-
-#undef _D
-#define _D(fmt, arg...) fprintf(stdout, fmt "\n", ##arg)
-
-#endif // AUL_TEST_LOG_PRIVATE_HH_
+++ /dev/null
-/*
- * Copyright (c) 2021 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 "aul_test.hh"
-#include "log_private.hh"
-
-int main(int argc, char** argv) {
- return aul_test::AulTestMgr::GetInst().RunTest(argc, argv);
-}
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulAppGetAllRunningAppInfoForUidTest : public AulTest {
- public:
- AulAppGetAllRunningAppInfoForUidTest()
- : AulTest("getallappstatus_for_uid",
- "aul_app_get_all_running_app_info_for_uid",
- "getallappstatus_for_uid <uid>") {}
-
- virtual ~AulAppGetAllRunningAppInfoForUidTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_app_get_all_running_app_info_for_uid test] %s", argv[2]);
- return aul_app_get_all_running_app_info_for_uid(AulAppInfoCb, nullptr,
- atoi(argv[2]));
- }
-
- private:
- static int AulAppInfoCb(const aul_app_info* info, void* user_data) {
- _D("\t==========================");
- _D("\t pid: %d", info->pid);
- _D("\t appid: %s", info->appid);
- _D("\t app_path: %s", info->app_path);
- _D("\t pkgid: %s", info->pkgid);
- _D("\t status: %d", info->status);
- _D("\t is_sub_app: %d", info->is_sub_app);
- _D("\t==========================");
- return 0;
- }
-};
-
-AUL_TEST_REGISTER(AulAppGetAllRunningAppInfoForUidTest,
- getallappstatus_for_uid_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulAppGetAllRunningAppInfoTest : public AulTest {
- public:
- AulAppGetAllRunningAppInfoTest()
- : AulTest("getallappstatus", "aul_app_get_all_running_app_info",
- "getallappstatus") {}
-
- virtual ~AulAppGetAllRunningAppInfoTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- _D("[aul_app_get_all_running_app_info test]");
- return aul_app_get_all_running_app_info(AulAppInfoCb, nullptr);
- }
-
- private:
- static int AulAppInfoCb(const aul_app_info* info, void* user_data) {
- _D("\t==========================");
- _D("\t pid: %d", info->pid);
- _D("\t appid: %s", info->appid);
- _D("\t app_path: %s", info->app_path);
- _D("\t pkgid: %s", info->pkgid);
- _D("\t status: %d", info->status);
- _D("\t is_sub_app: %d", info->is_sub_app);
- _D("\t==========================");
- return 0;
- }
-};
-
-AUL_TEST_REGISTER(AulAppGetAllRunningAppInfoTest, getallappstatus_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2023 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 <stdlib.h>
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulAppGetAppIdBypidAsyncTest : public AulTest {
- public:
- AulAppGetAppIdBypidAsyncTest()
- : AulTest("get_appid_bypid_async", "aul_app_get_appid_bypid_async",
- "get_appid_bypid_async <pid>", false) {}
-
- virtual ~AulAppGetAppIdBypidAsyncTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_app_get_appid_bypid_async test] %s", argv[2]);
- return aul_app_get_appid_bypid_async(atoi(argv[2]), AulAppIdCb,
- this);
- }
-
- private:
- static void AulAppIdCb(int result, pid_t pid, const char* appid,
- void* user_data) {
- _D("Result: %d, appid: %s", result, appid);
- }
-};
-
-AUL_TEST_REGISTER(AulAppGetAppIdBypidAsyncTest, get_appid_bypid_async_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulAppGetAppidBypidTest : public AulTest {
- public:
- AulAppGetAppidBypidTest()
- : AulTest("get_app_bypid", "aul_app_get_appid_bypid",
- "get_app_bypid <pid>") {}
-
- virtual ~AulAppGetAppidBypidTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_app_get_appid_bypid test] %s", argv[2]);
- char buf[256] = { 0, };
- int pid = atoi(argv[2]);
- if (aul_app_get_appid_bypid(pid, buf, sizeof(buf)) < 0)
- _E("no such pkg by %d", pid);
- else
- _D("pkgname = %s, pid = %d", buf, pid);
-
- return 0;
- }
-};
-
-AUL_TEST_REGISTER(AulAppGetAppidBypidTest, get_app_bypid_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulAppGetLastCallerPidForUidTest : public AulTest {
- public:
- AulAppGetLastCallerPidForUidTest()
- : AulTest("get_last_caller_pid_for_uid",
- "aul_app_get_last_caller_pid_for_uid",
- "get_last_caller_pid_for_uid <pid> <uid>") {}
-
- virtual ~AulAppGetLastCallerPidForUidTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 4) {
- Usage();
- return -1;
- }
-
- _D("[aul_app_get_last_caller_pid_for_uid test] %s %s", argv[2], argv[3]);
- return aul_app_get_last_caller_pid_for_uid(atoi(argv[2]), atoi(argv[3]));
- }
-};
-
-AUL_TEST_REGISTER(AulAppGetLastCallerPidForUidTest,
- get_last_caller_pid_for_uid_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulAppGetLastCallerPidTest : public AulTest {
- public:
- AulAppGetLastCallerPidTest()
- : AulTest("get_last_caller_pid", "aul_app_get_last_caller_pid",
- "get_last_caller_pid <pid>") {}
-
- virtual ~AulAppGetLastCallerPidTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_app_get_last_caller_pid test] %s", argv[2]);
- return aul_app_get_last_caller_pid(atoi(argv[2]));
- }
-};
-
-AUL_TEST_REGISTER(AulAppGetLastCallerPidTest, get_last_caller_pid_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulAppGetPidForUidTest : public AulTest {
- public:
- AulAppGetPidForUidTest()
- : AulTest("get_pid_for_uid", "aul_app_get_pid_for_uid",
- "get_pid_for_uid <appid> <uid>") {}
-
- virtual ~AulAppGetPidForUidTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 4) {
- Usage();
- return -1;
- }
-
- _D("[aul_app_get_pid_for_uid test] %s %s", argv[2], argv[3]);
- return aul_app_get_pid_for_uid(argv[2], atoi(argv[3]));
- }
-};
-
-AUL_TEST_REGISTER(AulAppGetPidForUidTest, get_pid_for_uid_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulAppGetPidTest : public AulTest {
- public:
- AulAppGetPidTest()
- : AulTest("get_pid", "aul_app_get_pid", "get_pid <appid>") {}
-
- virtual ~AulAppGetPidTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_app_get_pid test] %s", argv[2]);
- return aul_app_get_pid(argv[2]);
- }
-};
-
-AUL_TEST_REGISTER(AulAppGetPidTest, get_pid_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulAppGetPkgidBypidTest : public AulTest {
- public:
- AulAppGetPkgidBypidTest()
- : AulTest("get_pkg_bypid", "aul_app_get_pkgid_bypid",
- "get_pkg_bypid <pid>") {}
-
- virtual ~AulAppGetPkgidBypidTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_app_get_pkgid_bypid test] %s", argv[2]);
- char buf[256] = { 0, };
- int pid = atoi(argv[2]);
- if (aul_app_get_pkgid_bypid(pid, buf, sizeof(buf)) < 0)
- _E("no such pkg by %d", pid);
- else
- _D("pkgname = %s, pid = %d", buf, pid);
-
- return 0;
- }
-};
-
-AUL_TEST_REGISTER(AulAppGetPkgidBypidTest, get_pkg_bypid_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulAppGetRunningAppInfoForUidTest : public AulTest {
- public:
- AulAppGetRunningAppInfoForUidTest()
- : AulTest("getallpkg_for_uid", "aul_app_get_running_app_info_for_uid",
- "getallpkg_for_uid <uid>") {}
-
- virtual ~AulAppGetRunningAppInfoForUidTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_app_get_running_app_info_for_uid test] %s", argv[2]);
- return aul_app_get_running_app_info_for_uid(AulAppInfoCb, nullptr,
- atoi(argv[2]));
- }
-
- private:
- static int AulAppInfoCb(const aul_app_info* info, void* user_data) {
- _D("\t==========================");
- _D("\t appid: %s", info->appid);
- _D("\t app_path: %s", info->app_path);
- _D("\t running pid: %d", info->pid);
- _D("\t==========================");
- return 0;
- }
-};
-
-AUL_TEST_REGISTER(AulAppGetRunningAppInfoForUidTest, getallpkg_for_uid_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulAppGetRunningAppInfoTest : public AulTest {
- public:
- AulAppGetRunningAppInfoTest()
- : AulTest("getallpkg", "aul_app_get_running_app_info",
- "getallpkg") {}
-
- virtual ~AulAppGetRunningAppInfoTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- _D("[aul_app_get_running_app_info test]");
- return aul_app_get_running_app_info(AulAppInfoCb, nullptr);
- }
-
- private:
- static int AulAppInfoCb(const aul_app_info* info, void* user_data) {
- _D("\t==========================");
- _D("\t appid: %s", info->appid);
- _D("\t app_path: %s", info->app_path);
- _D("\t running pid: %d", info->pid);
- _D("\t==========================");
- return 0;
- }
-};
-
-AUL_TEST_REGISTER(AulAppGetRunningAppInfoTest, getallpkg_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulAppGetStatusBypidForUidTest : public AulTest {
- public:
- AulAppGetStatusBypidForUidTest()
- : AulTest("get_status_pid_for_uid", "aul_app_get_status_bypid_for_uid",
- "get_status_pid_for_uid <pid> <uid>") {}
-
- virtual ~AulAppGetStatusBypidForUidTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 4) {
- Usage();
- return -1;
- }
-
- _D("[aul_app_get_status_bypid_for_uid test] %s %s", argv[2], argv[3]);
- return aul_app_get_status_bypid_for_uid(atoi(argv[2]), atoi(argv[3]));
- }
-};
-
-AUL_TEST_REGISTER(AulAppGetStatusBypidForUidTest, get_status_pid_for_uid_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulAppGetStatusBypidTest : public AulTest {
- public:
- AulAppGetStatusBypidTest()
- : AulTest("get_status_pid", "aul_app_get_status_bypid",
- "get_status_pid <pid>") {}
-
- virtual ~AulAppGetStatusBypidTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_app_get_status_bypid test] %s", argv[2]);
- int ret = aul_app_get_status_bypid(atoi(argv[2]));
- if (ret >= 0) {
- _D("==> pid: %s, status: %d(%s)",
- argv[2], ret, aul_app_status_convert_to_string(ret));
- }
-
- return ret;
- }
-};
-
-AUL_TEST_REGISTER(AulAppGetStatusBypidTest, get_status_pid_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulAppGetStatusForUidTest : public AulTest {
- public:
- AulAppGetStatusForUidTest()
- : AulTest("get_status_for_uid", "aul_app_get_status_for_uid",
- "get_status_for_uid <appid> <uid>") {}
-
- virtual ~AulAppGetStatusForUidTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 4) {
- Usage();
- return -1;
- }
-
- _D("[aul_app_get_status_for_uid test] %s %s", argv[2], argv[3]);
- int ret = aul_app_get_status_for_uid(argv[2], atoi(argv[3]));
- if (ret >= 0) {
- _D("==> appid: %s, uid: %s, status: %d(%s)",
- argv[2], argv[3], ret, aul_app_status_convert_to_string(ret));
- }
-
- return ret;
- }
-};
-
-AUL_TEST_REGISTER(AulAppGetStatusForUidTest, get_status_for_uid_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulAppGetStatusTest : public AulTest {
- public:
- AulAppGetStatusTest()
- : AulTest("get_status", "aul_app_get_status", "get_status <appid>") {}
-
- virtual ~AulAppGetStatusTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_app_get_status test] %s", argv[2]);
- int ret = aul_app_get_status(argv[2]);
- if (ret >= 0) {
- _D("==> appid: %s, status: %d(%s)",
- argv[2], ret, aul_app_status_convert_to_string(ret));
- }
-
- return ret;
- }
-};
-
-AUL_TEST_REGISTER(AulAppGetStatusTest, get_status_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulAppIsRunningTest : public AulTest {
- public:
- AulAppIsRunningTest()
- : AulTest("is_run", "aul_app_is_running", "is_run <appid>") {}
-
- virtual ~AulAppIsRunningTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_app_is_running test] %s", argv[2]);
- if (aul_app_is_running(argv[2]))
- _D("... %s is running", argv[2]);
- else
- _D("... %s is not running", argv[2]);
-
- return 0;
- }
-};
-
-AUL_TEST_REGISTER(AulAppIsRunningTest, is_run_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 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 "aul/api/aul_app_lifecycle.h"
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulAppLifecycleGetStateTest : public AulTest {
- public:
- AulAppLifecycleGetStateTest()
- : AulTest("get_app_lifecycle", "aul_app_lifecycle_get_state",
- "get_app_lifecycle <appid>") {}
-
- virtual ~AulAppLifecycleGetStateTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_app_lifecycle_get_state test] %s", argv[2]);
- aul_app_lifecycle_state_e state;
- int ret = aul_app_lifecycle_get_state(argv[2], &state);
- if (ret == AUL_R_OK)
- _D("==> result: %d, state: %s", ret, LifecycleStateToString(state));
-
- return ret;
- }
-
- private:
- static const char* LifecycleStateToString(aul_app_lifecycle_state_e state) {
- switch (state) {
- case AUL_APP_LIFECYCLE_STATE_INITIALIZED:
- return "INITIALIZED";
- case AUL_APP_LIFECYCLE_STATE_CREATED:
- return "CREATED";
- case AUL_APP_LIFECYCLE_STATE_RESUMED:
- return "RESUMED";
- case AUL_APP_LIFECYCLE_STATE_PAUSED:
- return "PAUSED";
- default:
- return "DESTROYED";
- }
- }
-};
-
-AUL_TEST_REGISTER(AulAppLifecycleGetStateTest, get_app_lifecycle_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 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 "aul/api/aul_app_lifecycle.h"
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulAppLifecycleRegisterStateChangedCbTest : public AulTest {
- public:
- AulAppLifecycleRegisterStateChangedCbTest()
- : AulTest("listen_app_lifecycle",
- "aul_app_lifecycle_register_state_changed_cb",
- "listen_app_lifecycle", false) {}
-
- virtual ~AulAppLifecycleRegisterStateChangedCbTest() {
- aul_app_lifecycle_deregister_state_changed_cb();
- }
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- _D("[aul_app_lifecycle_register_state_changed_cb test]");
- return aul_app_lifecycle_register_state_changed_cb(
- AppLifecycleStateChangedCb, nullptr);
- }
-
- private:
- static const char* LifecycleStateToString(aul_app_lifecycle_state_e state) {
- switch (state) {
- case AUL_APP_LIFECYCLE_STATE_INITIALIZED:
- return "INITIALIZED";
- case AUL_APP_LIFECYCLE_STATE_CREATED:
- return "CREATED";
- case AUL_APP_LIFECYCLE_STATE_RESUMED:
- return "RESUMED";
- case AUL_APP_LIFECYCLE_STATE_PAUSED:
- return "PAUSED";
- default:
- return "DESTROYED";
- }
- }
-
- static void AppLifecycleStateChangedCb(const char* appid, pid_t pid,
- aul_app_lifecycle_state_e state, bool has_focus, void* user_data) {
- _D("appid: %s, pid: %d, state: %s, has_focus: %s",
- appid, pid, LifecycleStateToString(state),
- has_focus ? "true" : "false");
- }
-};
-
-AUL_TEST_REGISTER(AulAppLifecycleRegisterStateChangedCbTest,
- listen_app_lifecycle_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulDisableAliasInfoTest : public AulTest {
- public:
- AulDisableAliasInfoTest()
- : AulTest("disable_alias_info", "aul_disable_alias_info",
- "disable_alias_info <appid>") {}
-
- virtual ~AulDisableAliasInfoTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_disable_alias_info test] %s", argv[2]);
- return aul_disable_alias_info(argv[2]);
- }
-};
-
-AUL_TEST_REGISTER(AulDisableAliasInfoTest, disable_alias_info_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulEnableAliasInfoTest : public AulTest {
- public:
- AulEnableAliasInfoTest()
- : AulTest("enable_alias_info", "aul_enable_alias_info",
- "enable_alias_info <appid>") {}
-
- virtual ~AulEnableAliasInfoTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_enable_alias_info test] %s", argv[2]);
- return aul_enable_alias_info(argv[2]);
- }
-};
-
-AUL_TEST_REGISTER(AulEnableAliasInfoTest, enable_alias_info_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "menu_db_util.h"
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulGetAppInfoFromDbByPkgnameTest : public AulTest {
- public:
- AulGetAppInfoFromDbByPkgnameTest()
- : AulTest("getpkg", "aul_get_app_info_from_db_by_pkgname",
- "getpkg <appid>") {}
-
- virtual ~AulGetAppInfoFromDbByPkgnameTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_get_app_info_from_db_by_pkgname test] %s", argv[2]);
- app_info_from_db* info = _get_app_info_from_db_by_pkgname(argv[2]);
- if (info == nullptr) {
- _E("pkg %s no found", argv[2]);
- return 0;
- }
-
- _D("\t==========================");
- _D("\t appid: %s", info->appid);
- _D("\t app_path: %s", info->app_path);
- _D("\t is_minst: 0");
- _D("\t==========================");
- _free_app_info_from_db(info);
- return 0;
- }
-};
-
-AUL_TEST_REGISTER(AulGetAppInfoFromDbByPkgnameTest, getpkg_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulGetDefappFromMimeTest : public AulTest {
- public:
- AulGetDefappFromMimeTest()
- : AulTest("get_defapp_mime", "aul_get_defapp_from_mime",
- "get_defapp_mime <mime_type>") {}
-
- virtual ~AulGetDefappFromMimeTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_get_defapp_from_mime test] %s", argv[2]);
- char buf[256] = { 0, };
- int ret = aul_get_defapp_from_mime(argv[2], buf, sizeof(buf));
- if (ret == AUL_R_OK)
- _D("==> defapp name = %s", buf);
-
- return ret;
- }
-};
-
-AUL_TEST_REGISTER(AulGetDefappFromMimeTest, get_defapp_mime_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-#include "include/aul_svc.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulGetDefaultAppTest : public AulTest {
- public:
- AulGetDefaultAppTest()
- : AulTest("get_default_app", "aul_get_default_app",
- "get_default_app <operation> <uri> <mime>") {}
-
- virtual ~AulGetDefaultAppTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_get_default_app test] %s %s %s",
- argv[2], argc > 3 ? argv[3] : "null", argc > 4 ? argv[4] : "null");
-
- bundle* b = bundle_create();
- if (b == nullptr) {
- _E("bundle_create() is failed");
- return -ENOMEM;
- }
-
- aul_svc_set_operation(b, argv[2]);
- if (argc > 3)
- aul_svc_set_uri(b, argv[3]);
- if (argc > 4)
- aul_svc_set_mime(b, argv[4]);
-
- char* appid = nullptr;
- int ret = aul_get_default_app(b, &appid);
- bundle_free(b);
- _D("result: %s", appid);
- free(appid);
- return ret;
- }
-};
-
-AUL_TEST_REGISTER(AulGetDefaultAppTest, get_default_app_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulGetMimeDescriptionTest : public AulTest {
- public:
- AulGetMimeDescriptionTest()
- : AulTest("get_mime_desc", "aul_get_mime_description",
- "get_mime_desc <mimetype>") {}
-
- virtual ~AulGetMimeDescriptionTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_get_mime_description test] %s", argv[2]);
- char buf[256] = { 0, };
- int ret = aul_get_mime_description(argv[2], buf, sizeof(buf));
- if (ret == AUL_R_OK)
- _D("==> mime type = %s : description = %s", argv[2], buf);
-
- return ret;
- }
-};
-
-AUL_TEST_REGISTER(AulGetMimeDescriptionTest, get_mime_desc_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulGetMimeExtensionTest : public AulTest {
- public:
- AulGetMimeExtensionTest()
- : AulTest("get_mime_ext", "aul_get_mime_extension",
- "get_mime_ext <mimetype>") {}
-
- virtual ~AulGetMimeExtensionTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_get_mime_extension test] %s", argv[2]);
- char buf[256] = { 0, };
- int ret = aul_get_mime_extension(argv[2], buf, sizeof(buf));
- if (ret == AUL_R_OK)
- _D("==> mime type = %s : extension = %s", argv[2], buf);
-
- return ret;
- }
-};
-
-AUL_TEST_REGISTER(AulGetMimeExtensionTest, get_mime_ext_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulGetMimeFromContentTest : public AulTest {
- public:
- AulGetMimeFromContentTest()
- : AulTest("get_mime_content", "aul_get_mime_from_content",
- "get_mime_content <content>") {}
-
- virtual ~AulGetMimeFromContentTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_get_mime_from_content test] %s", argv[2]);
- char buf[256] = { 0, };
- int ret = aul_get_mime_from_content(argv[2], buf, sizeof(buf));
- if (ret == AUL_R_OK)
- _D("==> mime type = %s", buf);
-
- return ret;
- }
-};
-
-AUL_TEST_REGISTER(AulGetMimeFromContentTest, get_mime_content_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulGetMimeFromFileTest : public AulTest {
- public:
- AulGetMimeFromFileTest()
- : AulTest("get_mime_file", "aul_get_mime_from_file",
- "get_mime_file <filename>") {}
-
- virtual ~AulGetMimeFromFileTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_get_mime_from_file test] %s", argv[2]);
- char buf[256] = { 0, };
- int ret = aul_get_mime_from_file(argv[2], buf, sizeof(buf));
- if (ret == AUL_R_OK)
- _D("==> mime type = %s", buf);
-
- return ret;
- }
-};
-
-AUL_TEST_REGISTER(AulGetMimeFromFileTest, get_mime_file_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulGetMimeIconTest : public AulTest {
- public:
- AulGetMimeIconTest()
- : AulTest("get_mime_icon", "aul_get_mime_icon",
- "get_mime_icon <mimetype>") {}
-
- virtual ~AulGetMimeIconTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_get_mime_icon test] %s", argv[2]);
- char buf[256] = { 0, };
- int ret = aul_get_mime_icon(argv[2], buf, sizeof(buf));
- if (ret == AUL_R_OK)
- _D("==> mime type = %s : iconname = %s", argv[2], buf);
-
- return ret;
- }
-};
-
-AUL_TEST_REGISTER(AulGetMimeIconTest, get_mime_icon_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2023 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 <stdlib.h>
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulKillLoaderTest : public AulTest {
- public:
- AulKillLoaderTest()
- : AulTest("kill_loader", "aul_kill_loader", "kill_loader <loader_name>") {
- }
-
- virtual ~AulKillLoaderTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_kill_loader test] %s", argv[2]);
- return aul_kill_loader(argv[2]);
- }
-};
-
-AUL_TEST_REGISTER(AulKillLoaderTest, kill_loader_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2023 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 <stdlib.h>
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulKillPidAsyncTest : public AulTest {
- public:
- AulKillPidAsyncTest()
- : AulTest("kill_pid_async", "aul_kill_pid_async",
- "kill_pid_async <pid>", false) {}
-
- virtual ~AulKillPidAsyncTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_kill_pid_async test] %s", argv[2]);
- return aul_kill_pid_async(atoi(argv[2]), AulResultCb, this);
- }
-
- private:
- static void AulResultCb(int result, void* user_data) {
- _D("Result: %d", result);
- }
-};
-
-AUL_TEST_REGISTER(AulKillPidAsyncTest, kill_pid_async_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulLaunchAppAsyncForUidTest : public AulTest {
- public:
- AulLaunchAppAsyncForUidTest()
- : AulTest("launch_async_for_uid", "aul_launch_app_async_for_uid",
- "launch_async_for_uid <appid> <uid> <key1> <val1> ...") {}
-
- virtual ~AulLaunchAppAsyncForUidTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 4) {
- Usage();
- return -1;
- }
-
- _D("[aul_launch_app_async_for_uid test] %s %s", argv[2], argv[3]);
- tizen_base::Bundle b = CreateBundleFromArgv(argc, argv, 4);
- return aul_launch_app_async_for_uid(argv[2], b.GetHandle(), atoi(argv[3]));
- }
-};
-
-AUL_TEST_REGISTER(AulLaunchAppAsyncForUidTest, launch_async_for_uid_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulLaunchAppAsyncTest : public AulTest {
- public:
- AulLaunchAppAsyncTest()
- : AulTest("launch_async", "aul_launch_app_async",
- "launch_async <appid> <key1> <val1> <key2> <val2> ...") {}
-
- virtual ~AulLaunchAppAsyncTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_launch_app_async test] %s", argv[2]);
- tizen_base::Bundle b = CreateBundleFromArgv(argc, argv, 3);
- return aul_launch_app_async(argv[2], b.GetHandle());
- }
-};
-
-AUL_TEST_REGISTER(AulLaunchAppAsyncTest, launch_async_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulLaunchAppForUidTest : public AulTest {
- public:
- AulLaunchAppForUidTest()
- : AulTest("launch_for_uid", "aul_launch_app_for_uid",
- "launch_for_uid <app_id> <uid> <key1> <val1> ...") {}
-
- virtual ~AulLaunchAppForUidTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 4) {
- Usage();
- return -1;
- }
-
- _D("[aul_launch_app_for_uid test] %s %s", argv[2], argv[3]);
- tizen_base::Bundle b = CreateBundleFromArgv(argc, argv, 4);
- return aul_launch_app_for_uid(argv[2], b.GetHandle(), atoi(argv[3]));
- }
-};
-
-AUL_TEST_REGISTER(AulLaunchAppForUidTest, launch_for_uid_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulLaunchAppTest : public AulTest {
- public:
- AulLaunchAppTest()
- : AulTest("launch", "aul_launch_app",
- "launch <app_id> <key1> <val1> <key2> <val2> ...") {}
-
- virtual ~AulLaunchAppTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_launch_app test] %s", argv[2]);
- tizen_base::Bundle b = CreateBundleFromArgv(argc, argv, 3);
- return aul_launch_app(argv[2], b.GetHandle());
- }
-};
-
-AUL_TEST_REGISTER(AulLaunchAppTest, launch_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulListenAppDeadSignalTest : public AulTest {
- public:
- AulListenAppDeadSignalTest()
- : AulTest("listen_app_dead_signal", "aul_listen_app_dead_signal",
- "listen_app_dead_signal", false) {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- _D("[aul_listen_app_dead_signal test]");
- return aul_listen_app_dead_signal(AppDeadEventCb, this);
- }
-
- private:
- static int AppDeadEventCb(int pid, void* user_data) {
- _D("pid(%d) is dead", pid);
- return 0;
- }
-};
-
-AUL_TEST_REGISTER(AulListenAppDeadSignalTest, listen_app_dead_signal_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulListenAppLaunchSignalTest : public AulTest {
- public:
- AulListenAppLaunchSignalTest()
- : AulTest("listen_app_launch_signal", "aul_listen_app_launch_signal",
- "listen_app_launch_signal", false) {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- _D("[aul_listen_app_launch_signal test]");
- return aul_listen_app_launch_signal(AppLaunchEventCb, this);
- }
-
- private:
- static int AppLaunchEventCb(int pid, void* user_data) {
- _D("pid(%d) is launched", pid);
- return 0;
- }
-};
-
-AUL_TEST_REGISTER(AulListenAppLaunchSignalTest, listen_app_launch_signal_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulListenAppLaunchSignalV2Test : public AulTest {
- public:
- AulListenAppLaunchSignalV2Test()
- : AulTest("listen_app_launch_signal_v2",
- "aul_listen_app_launch_signal_v2",
- "listen_app_launch_signal_v2", false) {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- _D("[aul_listen_app_launch_signal_v2 test]");
- return aul_listen_app_launch_signal_v2(AppLaunchEventCb, this);
- }
-
- private:
- static int AppLaunchEventCb(int pid, const char* appid, void* user_data) {
- _D("pid(%d) is launched. appid(%s)", pid, appid);
- return 0;
- }
-};
-
-AUL_TEST_REGISTER(AulListenAppLaunchSignalV2Test,
- listen_app_launch_signal_v2_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulListenAppStatusForUidTest : public AulTest {
- public:
- AulListenAppStatusForUidTest()
- : AulTest("listen_app_status_for_uid", "aul_listen_app_status_for_uid",
- "listen_app_status_for_uid <appid> <uid>", false) {}
-
- virtual ~AulListenAppStatusForUidTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 4) {
- Usage();
- return -1;
- }
-
- _D("[aul_listen_app_status_for_uid test] %s %s", argv[2], argv[3]);
- return aul_listen_app_status_for_uid(argv[2], AppStatusCb, this, &handle_,
- atoi(argv[3]));
- }
-
- private:
- static int AppStatusCb(aul_app_info* info, int ctx_status, void* user_data) {
- _D("appid: %s, status: %d", info->appid, ctx_status);
- return 0;
- }
-
- status_listen_h handle_ = nullptr;
-};
-
-AUL_TEST_REGISTER(AulListenAppStatusForUidTest, listen_app_status_for_uid_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulListenAppStatusSignalTest : public AulTest {
- public:
- AulListenAppStatusSignalTest()
- : AulTest("listen_app_status_signal", "aul_listen_app_status_signal",
- "listen_app_status_signal", false) {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- _D("[aul_listen_app_status_signal test]");
- return aul_listen_app_status_signal(AppStatusEventCb, this);
- }
-
- private:
- static const char* GetStatusString(int status) {
- const char* status_str;
- switch (status) {
- case AUL_PROC_STATUS_LAUNCH:
- status_str = "LAUNCH";
- break;
- case AUL_PROC_STATUS_FG:
- status_str = "FG";
- break;
- case AUL_PROC_STATUS_BG:
- status_str = "BG";
- break;
- case AUL_PROC_STATUS_FOCUS:
- status_str = "FOCUS";
- break;
- case AUL_PROC_STATUS_HIDE:
- status_str = "HIDE";
- break;
- default:
- status_str = "UNKNOWN";
- break;
- }
-
- return status_str;
- }
-
- static int AppStatusEventCb(int pid, int status, void* user_data) {
- _D("pid: %d, status: %d(%s)", pid, status, GetStatusString(status));
- return 0;
- }
-};
-
-AUL_TEST_REGISTER(AulListenAppStatusSignalTest, listen_app_status_signal_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulListenAppStatusTest : public AulTest {
- public:
- AulListenAppStatusTest()
- : AulTest("listen_app_status", "aul_listen_app_status",
- "listen_app_status <appid>", false) {}
-
- virtual ~AulListenAppStatusTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_listen_app_status test] %s", argv[2]);
- return aul_listen_app_status(argv[2], AppStatusCb, this, &handle_);
- }
-
- private:
- static int AppStatusCb(aul_app_info* info, int ctx_status, void* user_data) {
- _D("appid: %s, status: %d", info->appid, ctx_status);
- return 0;
- }
-
- status_listen_h handle_ = nullptr;
-};
-
-AUL_TEST_REGISTER(AulListenAppStatusTest, listen_app_status_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulOpenAppForUidTest : public AulTest {
- public:
- AulOpenAppForUidTest()
- : AulTest("open_for_uid", "aul_open_app_for_uid",
- "open_for_uid <appid> <uid>") {}
-
- virtual ~AulOpenAppForUidTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 4) {
- Usage();
- return -1;
- }
-
- _D("[aul_open_app_for_uid test] %s %s", argv[2], argv[3]);
- return aul_open_app_for_uid(argv[2], atoi(argv[3]));
- }
-};
-
-AUL_TEST_REGISTER(AulOpenAppForUidTest, open_for_uid_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulOpenAppTest : public AulTest {
- public:
- AulOpenAppTest() : AulTest("open", "aul_open_app", "open <appid>") {}
-
- virtual ~AulOpenAppTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_open_app test] %s", argv[2]);
- return aul_open_app(argv[2]);
- }
-};
-
-AUL_TEST_REGISTER(AulOpenAppTest, open_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulOpenContentTest : public AulTest {
- public:
- AulOpenContentTest()
- : AulTest("open_content", "aul_open_content", "open_content <content>") {}
-
- virtual ~AulOpenContentTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_open_content test] %s", argv[2]);
- return aul_open_content(argv[2]);
- }
-};
-
-AUL_TEST_REGISTER(AulOpenContentTest, open_content_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulOpenFileTest : public AulTest {
- public:
- AulOpenFileTest()
- : AulTest("open_file", "aul_open_file", "open_file <filename>") {}
-
- virtual ~AulOpenFileTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_open_file test] %s", argv[2]);
- return aul_open_file(argv[2]);
- }
-};
-
-AUL_TEST_REGISTER(AulOpenFileTest, open_file_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulPauseAppForUidTest : public AulTest {
- public:
- AulPauseAppForUidTest()
- : AulTest("pause_for_uid", "aul_pause_app_for_uid",
- "pause_for_uid <appid> <uid>") {}
-
- virtual ~AulPauseAppForUidTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 4) {
- Usage();
- return -1;
- }
-
- _D("[aul_pause_app_for_uid test] %s %s", argv[2], argv[3]);
- return aul_pause_app_for_uid(argv[2], atoi(argv[3]));
- }
-};
-
-AUL_TEST_REGISTER(AulPauseAppForUidTest, pause_for_uid_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulPauseAppTest : public AulTest {
- public:
- AulPauseAppTest() : AulTest("pause", "aul_pause_app", "pause <app_id>") {}
-
- virtual ~AulPauseAppTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_pause_app test] %s", argv[2]);
- return aul_pause_app(argv[2]);
- }
-};
-
-AUL_TEST_REGISTER(AulPauseAppTest, pause_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulPausePidForUidTest : public AulTest {
- public:
- AulPausePidForUidTest()
- : AulTest("pause_pid_for_uid", "aul_pause_pid_for_uid",
- "pause_pid_for_uid <pid> <uid>") {}
-
- virtual ~AulPausePidForUidTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 4) {
- Usage();
- return -1;
- }
-
- _D("[aul_pause_pid_for_uid test] %s %s", argv[2], argv[3]);
- return aul_pause_pid_for_uid(atoi(argv[2]), atoi(argv[3]));
- }
-};
-
-AUL_TEST_REGISTER(AulPausePidForUidTest, pause_pid_for_uid_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulPausePidTest : public AulTest {
- public:
- AulPausePidTest()
- : AulTest("pause_pid", "aul_pause_pid", "pause_pid <pid>") {}
-
- virtual ~AulPausePidTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_pause_pid test] %s", argv[2]);
- return aul_pause_pid(atoi(argv[2]));
- }
-};
-
-AUL_TEST_REGISTER(AulPausePidTest, pause_pid_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-#include "include/aul_proc.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulProcGetExtraTest : public AulTest {
- public:
- AulProcGetExtraTest()
- : AulTest("get_proc_extra", "aul_proc_get_extra",
- "get_proc_extra <pid>") {}
-
- virtual ~AulProcGetExtraTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_proc_get_extra test] %s", argv[2]);
- bundle* extra = nullptr;
- int ret = aul_proc_get_extra(atoi(argv[2]), &extra);
- if (ret == AUL_R_OK)
- _D("==> result: %d", ret);
-
- if (extra) {
- bundle_foreach(extra, ForeachExtraCb, nullptr);
- bundle_free(extra);
- }
-
- return ret;
- }
-
- private:
- static void ForeachExtraCb(const char *key, const int type,
- const bundle_keyval_t* kb, void* user_data) {
- _D("key: %s, type: %d", key, type);
- }
-};
-
-AUL_TEST_REGISTER(AulProcGetExtraTest, get_proc_extra_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-#include "include/aul_proc.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulProcGetNameTest : public AulTest {
- public:
- AulProcGetNameTest()
- : AulTest("get_proc_name", "aul_proc_get_name", "get_proc_name <pid>") {}
-
- virtual ~AulProcGetNameTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_proc_get_name test] %s", argv[2]);
- char* name = nullptr;
- int ret = aul_proc_get_name(atoi(argv[2]), &name);
- if (ret == AUL_R_OK)
- _D("==> result: %d, name: %s", ret, name);
-
- free(name);
- return ret;
- }
-};
-
-AUL_TEST_REGISTER(AulProcGetNameTest, get_proc_name_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-#include "include/aul_proc_group.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulProcGroupAddTest : public AulTest {
- public:
- AulProcGroupAddTest()
- : AulTest("add_proc_group", "aul_proc_group_add",
- "add_proc_group <pid>") {}
-
- virtual ~AulProcGroupAddTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_proc_group_add test] %s", argv[2]);
- return aul_proc_group_add(atoi(argv[2]));
- }
-};
-
-AUL_TEST_REGISTER(AulProcGroupAddTest, add_proc_group_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-#include "include/aul_proc_group.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulProcGroupForeachTest : public AulTest {
- public:
- AulProcGroupForeachTest()
- : AulTest("foreach_proc_group", "aul_proc_group_foreach",
- "foreach_proc_group") {}
-
- virtual ~AulProcGroupForeachTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- _D("[aul_proc_group_foreach test]");
- return aul_proc_group_foreach(AulProcGroupCb, this);
- }
-
- static void AulProcGroupCb(aul_proc_group_info_h info, void* user_data) {
- pid_t leader_pid = -1;
- aul_proc_group_info_get_leader_pid(info, &leader_pid);
- const pid_t* sub_pids = nullptr;
- size_t length = 0;
- aul_proc_group_info_get_sub_pids(info, &sub_pids, &length);
-
- _D("[GROUP]");
- _D(" - Leader: %d", leader_pid);
- for (size_t i = 0; i < length; ++i)
- _D(" - Sub: %d", sub_pids[i]);
- }
-};
-
-AUL_TEST_REGISTER(AulProcGroupForeachTest, foreach_proc_group_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-#include "include/aul_proc_group.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulProcGroupGetTest : public AulTest {
- public:
- AulProcGroupGetTest()
- : AulTest("get_proc_group", "aul_proc_group_get",
- "get_proc_group <pid>") {}
-
- virtual ~AulProcGroupGetTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_proc_group_get test] %s", argv[2]);
- aul_proc_group_info_h info = nullptr;
- int ret = aul_proc_group_get(atoi(argv[2]), &info);
- if (ret != AUL_R_OK)
- return ret;
-
- pid_t leader_pid = -1;
- aul_proc_group_info_get_leader_pid(info, &leader_pid);
- const pid_t* sub_pids = nullptr;
- size_t length = 0;
- aul_proc_group_info_get_sub_pids(info, &sub_pids, &length);
-
- _D("[GROUP]");
- _D(" - Leader: %d", leader_pid);
- for (size_t i = 0; i < length; ++i)
- _D(" - Sub: %d", sub_pids[i]);
-
- return aul_proc_group_info_destroy(info);
- }
-};
-
-AUL_TEST_REGISTER(AulProcGroupGetTest, get_proc_group_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-#include "include/aul_proc_group.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulProcGroupRemoveTest : public AulTest {
- public:
- AulProcGroupRemoveTest()
- : AulTest("remove_proc_group", "aul_proc_group_remove",
- "remove_proc_group <pid>") {}
-
- virtual ~AulProcGroupRemoveTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_proc_group_remove test] %s", argv[2]);
- return aul_proc_group_remove(atoi(argv[2]));
- }
-};
-
-AUL_TEST_REGISTER(AulProcGroupRemoveTest, remove_proc_group_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-#include "include/aul_proc.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulProcRegisterTest : public AulTest {
- public:
- AulProcRegisterTest()
- : AulTest("register_proc", "aul_proc_register",
- "register_proc <name> <key1> <value1> <key2> <value2> ...") {}
-
- virtual ~AulProcRegisterTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- tizen_base::Bundle b;
- bundle* extra = nullptr;
- if (argc > 3) {
- b = CreateBundleFromArgv(argc, argv, 3);
- extra = b.GetHandle();
- }
-
- _D("[aul_proc_register] %s", argv[2]);
- int ret = aul_proc_register(argv[2], extra);
- _D("result: %d", ret);
- if (ret != AUL_R_OK)
- return ret;
-
- _D("[aul_proc_get_name] %d", getpid());
- char* name = nullptr;
- ret = aul_proc_get_name(getpid(), &name);
- _D("result: %d, name: %s", ret, name);
- free(name);
-
- _D("[aul_proc_get_extra] %d", getpid());
- extra = nullptr;
- ret = aul_proc_get_extra(getpid(), &extra);
- _D("result: %d", ret);
- if (extra) {
- bundle_foreach(extra, ForeachExtraCb, nullptr);
- bundle_free(extra);
- }
-
- return ret;
- }
-
- private:
- static void ForeachExtraCb(const char *key, const int type,
- const bundle_keyval_t* kb, void* user_data) {
- _D("key: %s, type: %d", key, type);
- }
-};
-
-AUL_TEST_REGISTER(AulProcRegisterTest, register_proc_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulReloadAppinfoTest : public AulTest {
- public:
- AulReloadAppinfoTest() : AulTest("reload", "aul_reload_appinfo", "reload") {}
-
- virtual ~AulReloadAppinfoTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- return aul_reload_appinfo();
- }
-};
-
-AUL_TEST_REGISTER(AulReloadAppinfoTest, reload_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2023 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 <stdlib.h>
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulRestartLoaderTest : public AulTest {
- public:
- AulRestartLoaderTest()
- : AulTest("restart_loader", "aul_restart_loader",
- "restart_loader <loader_name>") {
- }
-
- virtual ~AulRestartLoaderTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_restart_loader test] %s", argv[2]);
- return aul_restart_loader(argv[2]);
- }
-};
-
-AUL_TEST_REGISTER(AulRestartLoaderTest, restart_loader_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulResumeAppForUidTest : public AulTest {
- public:
- AulResumeAppForUidTest()
- : AulTest("resume_for_uid", "aul_resume_app_for_uid",
- "resume_for_uid <appid> <uid>") {}
-
- virtual ~AulResumeAppForUidTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 4) {
- Usage();
- return -1;
- }
-
- _D("[aul_resume_app_for_uid test] %s %s", argv[2], argv[3]);
- return aul_resume_app_for_uid(argv[2], atoi(argv[3]));
- }
-};
-
-AUL_TEST_REGISTER(AulResumeAppForUidTest, resume_for_uid_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulResumeAppTest : public AulTest {
- public:
- AulResumeAppTest() : AulTest("resume", "aul_resume_app", "resume <appid>") {}
-
- virtual ~AulResumeAppTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_resume_app test] %s", argv[2]);
- return aul_resume_app(argv[2]);
- }
-};
-
-AUL_TEST_REGISTER(AulResumeAppTest, resume_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 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 <stdlib.h>
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulResumePidAsyncForUidTest : public AulTest {
- public:
- AulResumePidAsyncForUidTest()
- : AulTest("resume_pid_async_for_uid", "aul_resume_pid_async_for_uid",
- "resume_pid_async_for_uid <pid> <uid>") {}
-
- virtual ~AulResumePidAsyncForUidTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 4) {
- Usage();
- return -1;
- }
-
- _D("[aul_resume_pid_async_for_uid test] %s %s", argv[2], argv[3]);
- return aul_resume_pid_async_for_uid(atoi(argv[2]), atoi(argv[3]));
- }
-};
-
-AUL_TEST_REGISTER(AulResumePidAsyncForUidTest, resume_pid_async_for_uid_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 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 <stdlib.h>
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulResumePidAsyncTest : public AulTest {
- public:
- AulResumePidAsyncTest()
- : AulTest("resume_pid_async", "aul_resume_pid_async",
- "resume_pid_async <pid>") {}
-
- virtual ~AulResumePidAsyncTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_resume_pid_async test] %s", argv[2]);
- return aul_resume_pid_async(atoi(argv[2]));
- }
-};
-
-AUL_TEST_REGISTER(AulResumePidAsyncTest, resume_pid_async_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 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 <stdlib.h>
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulResumePidForUidTest : public AulTest {
- public:
- AulResumePidForUidTest()
- : AulTest("resume_pid_for_uid", "aul_resume_pid_for_uid",
- "resume_pid_for_uid <pid> <uid>") {}
-
- virtual ~AulResumePidForUidTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 4) {
- Usage();
- return -1;
- }
-
- _D("[aul_resume_pid_for_uid test] %s %s", argv[2], argv[3]);
- return aul_resume_pid_for_uid(atoi(argv[2]), atoi(argv[3]));
- }
-};
-
-AUL_TEST_REGISTER(AulResumePidForUidTest, resume_pid_for_uid_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 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 <stdlib.h>
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulResumePidTest : public AulTest {
- public:
- AulResumePidTest()
- : AulTest("resume_pid", "aul_resume_pid", "resume_pid <pid>") {}
-
- virtual ~AulResumePidTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_resume_pid test] %s", argv[2]);
- return aul_resume_pid(atoi(argv[2]));
- }
-};
-
-AUL_TEST_REGISTER(AulResumePidTest, resume_pid_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulSetAliasAppidTest : public AulTest {
- public:
- AulSetAliasAppidTest()
- : AulTest("set_alias_appid", "aul_set_alias_appid",
- "set_alias_appid <alias_appid> <appid>") {}
-
- virtual ~AulSetAliasAppidTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 4) {
- Usage();
- return -1;
- }
-
- _D("[aul_set_alias_appid test] %s %s", argv[2], argv[3]);
- return aul_set_alias_appid(argv[2], argv[3]);
- }
-};
-
-AUL_TEST_REGISTER(AulSetAliasAppidTest, set_alias_appid_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulSetDefappWithMimeTest : public AulTest {
- public:
- AulSetDefappWithMimeTest()
- : AulTest("set_defapp_mime", "aul_set_defapp_with_mime",
- "set_defapp_mime <mimetype> <appid>") {}
-
- virtual ~AulSetDefappWithMimeTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 4) {
- Usage();
- return -1;
- }
-
- _D("[aul_set_defapp_with_mime test] %s %s", argv[2], argv[3]);
- return aul_set_defapp_with_mime(argv[2], argv[3]);
- }
-};
-
-AUL_TEST_REGISTER(AulSetDefappWithMimeTest, set_defapp_mime_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-#include "include/aul_svc.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulSetDefaultAppByOperationTest : public AulTest {
- public:
- AulSetDefaultAppByOperationTest()
- : AulTest("set_default_app_by_operation",
- "aul_set_default_app_by_operation",
- "set_default_app_by_operation <operation> <appid>") {}
-
- virtual ~AulSetDefaultAppByOperationTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 4) {
- Usage();
- return -1;
- }
-
- _D("[aul_set_default_app_by_operation test] %s %s", argv[2], argv[3]);
- bundle* b = bundle_create();
- if (b == nullptr) {
- _E("bundle_create() is failed");
- return -ENOMEM;
- }
-
- aul_svc_set_operation(b, argv[2]);
- aul_svc_set_appid(b, argv[3]);
- int ret = aul_set_default_app_by_operation(b);
- bundle_free(b);
- return ret;
- }
-};
-
-AUL_TEST_REGISTER(AulSetDefaultAppByOperationTest,
- set_default_app_by_operation_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 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 <stdlib.h>
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulSubappTerminateRequestPidTest : public AulTest {
- public:
- AulSubappTerminateRequestPidTest()
- : AulTest("term_req_pid", "aul_subapp_terminate_request_pid",
- "term_req_pid <pid>") {}
-
- virtual ~AulSubappTerminateRequestPidTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_subapp_terminate_request_pid test] %s", argv[2]);
- return aul_subapp_terminate_request_pid(atoi(argv[2]));
- }
-};
-
-AUL_TEST_REGISTER(AulSubappTerminateRequestPidTest, term_req_pid_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2023 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 <stdlib.h>
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulTerminateAppAsyncTest : public AulTest {
- public:
- AulTerminateAppAsyncTest()
- : AulTest("terminate_app_async", "aul_terminate_app_async",
- "terminate_app_async <appid>", false) {}
-
- virtual ~AulTerminateAppAsyncTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_terminate_app_async test] %s", argv[2]);
- return aul_terminate_app_async(argv[2], AulResultCb, this);
- }
-
- private:
- static void AulResultCb(int result, void* user_data) {
- _D("Result: %d", result);
- }
-};
-
-AUL_TEST_REGISTER(AulTerminateAppAsyncTest, terminate_app_async_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 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 <stdlib.h>
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulTerminateBgappPidTest : public AulTest {
- public:
- AulTerminateBgappPidTest()
- : AulTest("term_bgapp", "aul_terminate_bgapp_pid", "term_bgapp <pid>") {}
-
- virtual ~AulTerminateBgappPidTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_terminate_bgapp_pid test] %s", argv[2]);
- return aul_terminate_bgapp_pid(atoi(argv[2]));
- }
-};
-
-AUL_TEST_REGISTER(AulTerminateBgappPidTest, term_bgapp_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 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 <stdlib.h>
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulTerminatePidAsyncForUidTest : public AulTest {
- public:
- AulTerminatePidAsyncForUidTest()
- : AulTest("term_pid_async_for_uid", "aul_terminate_pid_async_for_uid",
- "term_pid_async_for_uid <pid> <uid>") {}
-
- virtual ~AulTerminatePidAsyncForUidTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 4) {
- Usage();
- return -1;
- }
-
- _D("[aul_terminate_pid_async_for_uid test] %s %s", argv[2], argv[3]);
- return aul_terminate_pid_async_for_uid(atoi(argv[2]), atoi(argv[3]));
- }
-};
-
-AUL_TEST_REGISTER(AulTerminatePidAsyncForUidTest, term_pid_async_for_uid_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2023 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 <stdlib.h>
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulTerminatePidAsyncV2Test : public AulTest {
- public:
- AulTerminatePidAsyncV2Test()
- : AulTest("terminate_pid_async_v2", "aul_terminate_pid_async_v2",
- "terminate_pid_async_v2 <pid>", false) {}
-
- virtual ~AulTerminatePidAsyncV2Test() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_terminate_pid_async_v2 test] %s", argv[2]);
- return aul_terminate_pid_async_v2(atoi(argv[2]), AulResultCb, this);
- }
-
- private:
- static void AulResultCb(int result, void* user_data) {
- _D("Result: %d", result);
- }
-};
-
-AUL_TEST_REGISTER(AulTerminatePidAsyncV2Test, terminate_pid_async_v2_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 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 <stdlib.h>
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulTerminatePidForUidTest : public AulTest {
- public:
- AulTerminatePidForUidTest()
- : AulTest("term_pid_for_uid", "aul_terminate_pid_for_uid",
- "term_pid_for_uid <pid> <uid>") {}
-
- virtual ~AulTerminatePidForUidTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 4) {
- Usage();
- return -1;
- }
-
- _D("[aul_terminate_pid_for_uid test] %s %s", argv[2], argv[3]);
- return aul_terminate_pid_for_uid(atoi(argv[2]), atoi(argv[3]));
- }
-};
-
-AUL_TEST_REGISTER(AulTerminatePidForUidTest, term_pid_for_uid_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 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 <stdlib.h>
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulTerminatePidSyncForUidTest : public AulTest {
- public:
- AulTerminatePidSyncForUidTest()
- : AulTest("term_pid_sync_for_uid", "aul_terminate_pid_sync_for_uid",
- "term_pid_sync_for_uid <pid> <uid>") {}
-
- virtual ~AulTerminatePidSyncForUidTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 4) {
- Usage();
- return -1;
- }
-
- _D("[aul_terminate_pid_sync_for_uid test] %s %s", argv[2], argv[3]);
- return aul_terminate_pid_sync_for_uid(atoi(argv[2]), atoi(argv[3]));
- }
-};
-
-AUL_TEST_REGISTER(AulTerminatePidSyncForUidTest, term_pid_sync_for_uid_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 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 <stdlib.h>
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulTerminatePidSyncTest : public AulTest {
- public:
- AulTerminatePidSyncTest()
- : AulTest("term_pid_sync", "aul_terminate_pid_sync",
- "term_pid_sync <pid>") {}
-
- virtual ~AulTerminatePidSyncTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_terminate_pid_sync test] %s", argv[2]);
- return aul_terminate_pid_sync(atoi(argv[2]));
- }
-};
-
-AUL_TEST_REGISTER(AulTerminatePidSyncTest, term_pid_sync_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 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 <stdlib.h>
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulTerminatePidTest : public AulTest {
- public:
- AulTerminatePidTest()
- : AulTest("term_pid", "aul_terminate_pid", "term_pid <pid>") {}
-
- virtual ~AulTerminatePidTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_terminate_pid test] %s", argv[2]);
- return aul_terminate_pid(atoi(argv[2]));
- }
-};
-
-AUL_TEST_REGISTER(AulTerminatePidTest, term_pid_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 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 <stdlib.h>
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulTerminatePidWithoutRestartTest : public AulTest {
- public:
- AulTerminatePidWithoutRestartTest()
- : AulTest("term_pid_without_restart", "aul_terminate_pid_without_restart",
- "term_pid_without_restart <pid>") {}
-
- virtual ~AulTerminatePidWithoutRestartTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_terminate_pid_without_restart test] %s", argv[2]);
- return aul_terminate_pid_without_restart(atoi(argv[2]));
- }
-};
-
-AUL_TEST_REGISTER(AulTerminatePidWithoutRestartTest,
- term_pid_without_restart_test);
-
-} // namespace aul_test
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/aul.h"
-
-#include "aul_test.hh"
-#include "log_private.hh"
-
-namespace aul_test {
-
-class AulUnsetAliasAppidTest : public AulTest {
- public:
- AulUnsetAliasAppidTest()
- : AulTest("unset_alias_appid", "aul_unset_alias_appid",
- "unset_alias_appid <alias_appid>") {}
-
- virtual ~AulUnsetAliasAppidTest() {}
-
- void SetUp() override {}
-
- void TearDown() override {}
-
- int Test(int argc, char** argv) override {
- if (argc < 3) {
- Usage();
- return -1;
- }
-
- _D("[aul_unset_alias_appid test] %s", argv[2]);
- return aul_unset_alias_appid(argv[2]);
- }
-};
-
-AUL_TEST_REGISTER(AulUnsetAliasAppidTest, unset_alias_appid_test);
-
-} // namespace aul_test
+++ /dev/null
-SET(TARGET_AUL_WINDOW "aul_window")
-
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} AUL_WINDOW_SRCS)
-
-ADD_EXECUTABLE(${TARGET_AUL_WINDOW} ${AUL_WINDOW_SRCS})
-SET_TARGET_PROPERTIES(${TARGET_AUL_WINDOW} PROPERTIES
- COMPILE_FLAGS ${CFLAGS} "-fPIE")
-SET_TARGET_PROPERTIES(${TARGET_AUL_WINDOW} PROPERTIES
- LINK_FLAGS "-pie")
-TARGET_LINK_LIBRARIES(${TARGET_AUL_WINDOW} PRIVATE
- ${TARGET_AUL})
-
-TARGET_INCLUDE_DIRECTORIES(${TARGET_AUL_WINDOW} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}/../../
- ${CMAKE_CURRENT_SOURCE_DIR}/../../src
- ${CMAKE_CURRENT_SOURCE_DIR}/../../include)
-
-APPLY_PKG_CONFIG(${TARGET_AUL_WINDOW} PUBLIC
- GLIB_DEPS
-)
-
-INSTALL(TARGETS ${TARGET_AUL_WINDOW} DESTINATION bin)
+++ /dev/null
-/*
- * Copyright (c) 2021 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 <aul.h>
-#include <aul_window.h>
-#include <glib.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <map>
-#include <string>
-
-namespace {
-
-using HandleFunc = int (*)(int argc, char** argv);
-
-void PrintUsage(const char* cmdline) {
- printf("%s <command> ...\n", cmdline);
- printf(" - command list\n");
- printf(" foreach_window_stack\n");
- printf(" get_focused_pid\n");
- printf(" attach_window <parent_appid> <child_appid>\n");
- printf(" detach_window <child_appid>\n");
- printf(" attach_window_below <parent_appid> <child_appid>\n");
- printf(" monitor_window_event\n");
-}
-
-const char* GetNotificationLevelString(aul_window_notification_level_e level) {
- switch (level) {
- case AUL_WINDOW_NOTIFICATION_LEVEL_DEFAULT:
- return "AUL_WINDOW_NOTIFICATION_LEVEL_DEFAULT";
- case AUL_WINDOW_NOTIFICATION_LEVEL_MEDIUM:
- return "AUL_WINDOW_NOTIFICATION_LEVEL_MEDIUM";
- case AUL_WINDOW_NOTIFICATION_LEVEL_HIGH:
- return "AUL_WINDOW_NOTIFICATION_LEVEL_HIGH";
- case AUL_WINDOW_NOTIFICATION_LEVEL_TOP:
- return "AUL_WINDOW_NOTIFICATION_LEVEL_TOP";
- case AUL_WINDOW_NOTIFICATION_LEVEL_PRIVILEGE:
- return "AUL_WINDOW_NOTIFICATION_LEVEL_PRIVILEGE";
- default:
- return "AUL_WINDOW_NOTIFICATION_LEVEL_NONE";
- }
-}
-
-void WindowStackIterCb(aul_window_info_h info, void* data) {
- unsigned int rid = 0;
- aul_window_stack_info_get_resource_id(info, &rid);
- int pid = -1;
- aul_window_info_get_pid(info, &pid);
- int ppid = -1;
- aul_window_info_get_parent_pid(info, &ppid);
- int apid = -1;
- aul_window_info_get_ancestor_pid(info, &apid);
- int visibility = -1;
- aul_window_info_get_visibility(info, &visibility);
- bool has_alpha = false;
- aul_window_info_has_alpha(info, &has_alpha);
- bool is_focused = false;
- aul_window_info_is_focused(info, &is_focused);
- aul_window_notification_level_e level = AUL_WINDOW_NOTIFICATION_LEVEL_NONE;
- aul_window_info_get_notification_level(info, &level);
- int x = -1;
- int y = -1;
- int w = -1;
- int h = -1;
- aul_window_info_get_geometry(info, &x, &y, &w, &h);
- bool opaque = false;
- aul_window_info_get_opaque(info, &opaque);
-
- printf("-----------------------------------------------------------------\n");
- printf(" - Resource ID: %d\n", rid);
- printf(" - Process ID: %d\n", pid);
- printf(" - Parent Process ID: %d\n", ppid);
- printf(" - Ancestor Process ID: %d\n", apid);
- printf(" - Visibility: %d\n", visibility);
- printf(" - Has Alpha: %s\n", has_alpha ? "true" : "false");
- printf(" - Is Focused: %s\n", is_focused ? "true" : "false");
- printf(" - Notification Level: %s\n", GetNotificationLevelString(level));
- printf(" - Opaque: %s\n", opaque ? "true" : "false");
-}
-
-int HandleForeachWindowStack(int argc, char** argv) {
- printf("[%s]\n", argv[1]);
- aul_window_stack_h handle = nullptr;
- int ret = aul_window_stack_get(&handle);
- if (ret != AUL_R_OK) {
- fprintf(stderr, "aul_window_stack() is failed. error(%d)\n", ret);
- return ret;
- }
-
- printf("=================================================================\n");
- ret = aul_window_stack_foreach(handle, WindowStackIterCb, nullptr);
- printf("=================================================================\n");
- aul_window_stack_del(handle);
- printf("[%s] result: %d\n", argv[1], ret);
- return ret;
-}
-
-int HandleGetFocusedPid(int argc, char** argv) {
- printf("[%s]\n", argv[1]);
- pid_t pid = -1;
- int ret = aul_window_get_focused_pid(&pid);
- printf("[%s] result: %d\n", argv[1], pid);
- return ret;
-}
-
-int HandleAttachWindow(int argc, char** argv) {
- if (argc < 4) {
- PrintUsage(argv[0]);
- return -1;
- }
-
- printf("[%s] parent_appid(%s), child_appid(%s)\n", argv[1], argv[2], argv[3]);
- int ret = aul_window_attach(argv[2], argv[3]);
- printf("[%s] result: %d\n", argv[1], ret);
- return ret;
-}
-
-int HandleDetachWindow(int argc, char** argv) {
- if (argc < 3) {
- PrintUsage(argv[0]);
- return -1;
- }
-
- printf("[%s] child_appid(%s)\n", argv[1], argv[2]);
- int ret = aul_window_detach(argv[2]);
- printf("[%s] result: %d\n", argv[1], ret);
- return ret;
-}
-
-int HandleAttachWindowBelow(int argc, char** argv) {
- if (argc < 4) {
- PrintUsage(argv[0]);
- return -1;
- }
-
- printf("[%s] parent_appid(%s), child_appid(%s)\n", argv[1], argv[2], argv[3]);
- int ret = aul_window_attach_below(argv[2], argv[3]);
- printf("[%s] result: %d\n", argv[1], ret);
- return ret;
-}
-
-void WindowEventCb(const char* event_name, const char* appid, int wid, int pid,
- void* user_data) {
- printf("[Window Event]\n");
- printf(" - Event_name: %s\n", event_name);
- printf(" - Application ID: %s\n", appid);
- printf(" - Window ID: %d\n", wid);
- printf(" - Process ID: %d\n", pid);
- printf("\n");
-}
-
-int HandleMonitorWindowEvent(int argc, char** argv) {
- printf("[%s]\n", argv[1]);
- int ret = aul_window_register_event_cb(WindowEventCb, nullptr);
- printf("[%s] result: %d\n", argv[1], ret);
- if (ret != AUL_R_OK)
- return ret;
-
- GMainLoop* loop = g_main_loop_new(nullptr, FALSE);
- g_main_loop_run(loop);
- g_main_loop_unref(loop);
- return 0;
-}
-
-std::map<std::string, HandleFunc> handlers = {
- { "foreach_window_stack", HandleForeachWindowStack },
- { "get_focused_pid", HandleGetFocusedPid },
- { "attach_window", HandleAttachWindow },
- { "detach_window", HandleDetachWindow },
- { "attach_window_below", HandleAttachWindowBelow },
- { "monitor_window_event", HandleMonitorWindowEvent },
-};
-
-} // namespace
-
-int main(int argc, char** argv) {
- if (argc < 2) {
- PrintUsage(argv[0]);
- return -1;
- }
-
- auto found = handlers.find(argv[1]);
- if (found == handlers.end()) {
- PrintUsage(argv[0]);
- return -1;
- }
-
- return found->second(argc, argv);
-}
+++ /dev/null
-SET(TARGET_AULCTL "aulctl")
-
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} AULCTL_SRCS)
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/boot_sequence BS_SRCS)
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/operation OP_SRCS)
-
-ADD_EXECUTABLE(${TARGET_AULCTL}
- ${AULCTL_SRCS}
- ${BS_SRCS}
- ${OP_SRCS}
-)
-
-SET_TARGET_PROPERTIES(${TARGET_AULCTL} PROPERTIES
- COMPILE_FLAGS ${CFLAGS} "-fPIE")
-SET_TARGET_PROPERTIES(${TARGET_AULCTL} PROPERTIES
- LINK_FLAGS "-pie")
-TARGET_LINK_LIBRARIES(${TARGET_AULCTL} PRIVATE
- ${TARGET_AUL}
- ${TARGET_AUL_SERVER})
-
-TARGET_INCLUDE_DIRECTORIES(${TARGET_AULCTL} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}
- ${CMAKE_CURRENT_SOURCE_DIR}/../../
- ${CMAKE_CURRENT_SOURCE_DIR}/../../src
- ${CMAKE_CURRENT_SOURCE_DIR}/../../include
-)
-
-APPLY_PKG_CONFIG(${TARGET_AULCTL} PUBLIC
- GLIB_DEPS
-)
-
-INSTALL(TARGETS ${TARGET_AULCTL} DESTINATION bin)
+++ /dev/null
-/*
- * Copyright (c) 2022 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 <iostream>
-#include <vector>
-
-#include "operation/operation_factory.hh"
-
-int main(int argc, char* argv[]) {
- std::vector<std::string> args(argv + 1, argv + argc);
- aul::OperationFactory factory;
- auto op = factory.CreateOperation(args);
- if (op->Process() == false) {
- std::cerr << "Failed operation." << std::endl;
- exit(1);
- }
-
- return 0;
-}
+++ /dev/null
-/*
- * Copyright (c) 2022 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 "app_info.hh"
-
-#include <bundle_internal.h>
-
-#include "include/aul_key.h"
-#include "src/aul_util.h"
-
-namespace aul::internal {
-namespace boot_sequence {
-namespace {
-
-constexpr const char METADATA_KEY_ONBOOT_PRIORITY[] =
- "http://tizen.org/metadata/on-boot/priority";
-constexpr const int MIN_PRIORITY = 1;
-constexpr const int MAX_PRIORITY = 99;
-constexpr const char K_BG_LAUNCH[] = "__K_BG_LAUNCH";
-constexpr const unsigned int DEFAULT_TIMEOUT = 5000;
-
-} // namespace
-
-AppInfo::Builder& AppInfo::Builder::SetAppId(const tizen_base::Bundle& args) {
- appid_ = args.GetString(AUL_K_APPID);
- return *this;
-}
-
-AppInfo::Builder& AppInfo::Builder::SetUid(const tizen_base::Bundle& args) {
- uid_ = static_cast<uid_t>(std::stoi(args.GetString(AUL_K_TARGET_UID)));
- return *this;
-}
-
-AppInfo::Builder& AppInfo::Builder::SetPriority(
- const tizen_base::Bundle& args) {
- priority_ = std::stoi(args.GetString(AUL_K_BOOT_SEQUENCE_PRIORITY));
- return *this;
-}
-
-AppInfo::Builder& AppInfo::Builder::SetAfter(const tizen_base::Bundle& args) {
- auto apps = args.GetStringArray(AUL_K_BOOT_SEQUENCE_AFTER);
- after_.insert(apps.begin(), apps.end());
- return *this;
-}
-
-AppInfo::Builder& AppInfo::Builder::SetBefore(const tizen_base::Bundle& args) {
- auto apps = args.GetStringArray(AUL_K_BOOT_SEQUENCE_BEFORE);
- before_.insert(apps.begin(), apps.end());
- return *this;
-}
-
-AppInfo::Builder& AppInfo::Builder::SetRequires(
- const tizen_base::Bundle& args) {
- auto apps = args.GetStringArray(AUL_K_BOOT_SEQUENCE_REQUIRES);
- requires_.insert(apps.begin(), apps.end());
- return *this;
-}
-
-AppInfo::Builder& AppInfo::Builder::SetConflicts(
- const tizen_base::Bundle& args) {
- auto apps = args.GetStringArray(AUL_K_BOOT_SEQUENCE_CONFLICTS);
- conflicts_.insert(apps.begin(), apps.end());
- return *this;
-}
-
-AppInfo::Builder& AppInfo::Builder::SetVconf(const tizen_base::Bundle& args) {
- vconf_ = args.GetStringArray(AUL_K_VCONF_DATA);
- return *this;
-}
-
-AppInfo::Builder& AppInfo::Builder::SetArgs(
- const tizen_base::Bundle& args) {
- static const std::vector<std::string> internal_keys{
- "__AUL_APPID__",
- "__AUL_STARTTIME__",
- "__K_BG_LAUNCH"
- };
- auto arg_json = args.GetString(AUL_K_ARGS);
- bundle* b = nullptr;
- if (bundle_from_json(arg_json.c_str(), &b) != BUNDLE_ERROR_NONE) {
- _E("bundle_from_json() is failed");
- } else {
- args_ = tizen_base::Bundle(b, false, true);
- for (auto& key : internal_keys)
- args_.Delete(key);
- }
-
- return *this;
-}
-
-AppInfo::Builder& AppInfo::Builder::SetBackgroundLaunch(
- const tizen_base::Bundle& args) {
- background_launch_ = (args.GetString(AUL_K_ALLOWED_BG) == "true");
- return *this;
-}
-
-AppInfo::Builder& AppInfo::Builder::SetWaitUntilReady(
- const tizen_base::Bundle& args) {
- wait_until_ready_ =
- (args.GetString(AUL_K_BOOT_SEQUENCE_READY_WAIT) == "true");
- return *this;
-}
-
-AppInfo::Builder& AppInfo::Builder::SetTimeout(
- const tizen_base::Bundle& args) {
- auto timeout_str = args.GetString(AUL_K_TIMEOUT);
- if (isdigit(timeout_str[0]))
- timeout_ = static_cast<unsigned int>(std::stoi(timeout_str));
- else
- timeout_ = DEFAULT_TIMEOUT;
-
- return *this;
-}
-
-AppInfo::Builder& AppInfo::Builder::SetActiveState(
- const tizen_base::Bundle& args) {
- active_state_ = args.GetString(AUL_K_STATUS);
- return *this;
-}
-
-AppInfo::Builder& AppInfo::Builder::SetSubState(
- const tizen_base::Bundle& args) {
- sub_state_ = args.GetString(AUL_K_SUB_STATUS);
- return *this;
-}
-
-AppInfo::Builder& AppInfo::Builder::SetBeginTimestamp(
- const tizen_base::Bundle& args) {
- begin_timestamp_ = args.GetString(AUL_K_BEGIN_TIMESTAMP);
- return *this;
-}
-
-AppInfo::Builder& AppInfo::Builder::SetEndTimestamp(
- const tizen_base::Bundle& args) {
- end_timestamp_ = args.GetString(AUL_K_END_TIMESTAMP);
- return *this;
-}
-
-AppInfo::Builder& AppInfo::Builder::SetSocketReadyTimestamp(
- const tizen_base::Bundle& args) {
- socket_ready_timestamp_ = args.GetString(AUL_K_SOCKET_READY_TIMESTAMP);
- return *this;
-}
-
-AppInfo::Builder& AppInfo::Builder::SetTerminatedTimestamp(
- const tizen_base::Bundle& args) {
- terminated_timestamp_ = args.GetString(AUL_K_TERMINATED_TIMESTAMP);
- return *this;
-}
-
-AppInfo::Builder& AppInfo::Builder::SetStatusMessage(
- const tizen_base::Bundle& args) {
- status_msg_ = args.GetString(AUL_K_STATUS_MSG);
- return *this;
-}
-
-AppInfo* AppInfo::Builder::Build() {
- return new (std::nothrow) AppInfo(
- std::move(appid_),
- uid_,
- priority_,
- std::move(after_),
- std::move(before_),
- std::move(requires_),
- std::move(conflicts_),
- std::move(vconf_),
- std::move(args_),
- std::move(active_state_),
- std::move(sub_state_),
- std::move(begin_timestamp_),
- std::move(end_timestamp_),
- std::move(socket_ready_timestamp_),
- std::move(terminated_timestamp_),
- std::move(status_msg_),
- background_launch_,
- wait_until_ready_,
- timeout_);
-}
-
-AppInfo::AppInfo(std::string appid, uid_t uid, int priority,
- std::set<std::string> after, std::set<std::string> before,
- std::set<std::string> requires_dep, std::set<std::string> conflicts,
- std::vector<std::string> vconfs,
- tizen_base::Bundle args,
- std::string active_state, std::string sub_state,
- std::string begin_timestamp, std::string end_timestamp,
- std::string socket_ready_timestamp, std::string terminated_timestamp,
- std::string status_msg,
- bool background_launch, bool wait_until_ready, unsigned int timeout)
- : appid_(std::move(appid)),
- uid_(uid),
- priority_(priority),
- after_(std::move(after)),
- before_(std::move(before)),
- requires_(std::move(requires_dep)),
- conflicts_(std::move(conflicts)),
- vconf_(std::move(vconfs)),
- args_(std::move(args)),
- active_state_(std::move(active_state)),
- sub_state_(std::move(sub_state)),
- begin_timestamp_(std::move(begin_timestamp)),
- end_timestamp_(std::move(end_timestamp)),
- socket_ready_timestamp_(std::move(socket_ready_timestamp)),
- terminated_timestamp_(std::move(terminated_timestamp)),
- background_launch_(background_launch),
- wait_until_ready_(wait_until_ready),
- timeout_(timeout),
- status_msg_(std::move(status_msg)) {
-}
-
-const std::string& AppInfo::GetAppId() const {
- return appid_;
-}
-
-uid_t AppInfo::GetUid() const {
- return uid_;
-}
-
-int AppInfo::GetPriority() const {
- return priority_;
-}
-
-// After
-bool AppInfo::AfterContains(const std::string& appid) {
- return after_.find(appid) != after_.end();
-}
-
-const std::set<std::string>& AppInfo::AfterGet() const {
- return after_;
-}
-
-// Before
-bool AppInfo::BeforeContains(const std::string& appid) {
- return before_.find(appid) != before_.end();
-}
-
-const std::set<std::string>& AppInfo::BeforeGet() const {
- return before_;
-}
-
-// Requires
-bool AppInfo::RequiresContains(const std::string& appid) {
- return requires_.find(appid) != requires_.end();
-}
-
-const std::set<std::string>& AppInfo::RequiresGet() const {
- return requires_;
-}
-
-// Conflicts
-bool AppInfo::ConflictsContains(const std::string& appid) {
- return conflicts_.find(appid) != conflicts_.end();
-}
-
-const std::set<std::string>& AppInfo::ConflictsGet() const {
- return conflicts_;
-}
-
-const std::vector<std::string>& AppInfo::GetVconf() const {
- return vconf_;
-}
-
-const tizen_base::Bundle& AppInfo::GetArgs() const {
- return args_;
-}
-
-bool AppInfo::IsBackgroundLaunch() const {
- return background_launch_;
-}
-
-bool AppInfo::WaitUntilReady() const {
- return wait_until_ready_;
-}
-
-unsigned int AppInfo::GetTimeout() const {
- return timeout_;
-}
-
-const std::string& AppInfo::GetActiveState() const {
- return active_state_;
-}
-
-const std::string& AppInfo::GetSubState() const {
- return sub_state_;
-}
-
-const std::string& AppInfo::GetBeginTimestamp() const {
- return begin_timestamp_;
-}
-
-const std::string& AppInfo::GetEndTimestamp() const {
- return end_timestamp_;
-}
-
-const std::string& AppInfo::GetSocketReadyTimestamp() const {
- return socket_ready_timestamp_;
-}
-
-const std::string& AppInfo::GetTerminatedTimestamp() const {
- return terminated_timestamp_;
-}
-
-const std::string& AppInfo::GetStatusMessage() const {
- return status_msg_;
-}
-
-} // namespace boot_sequence
-} // namespace aul::internal
+++ /dev/null
-/*
- * Copyright (c) 2022 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 AULCTL_BOOT_SEQUENCE_APP_INFO_HH_
-#define AULCTL_BOOT_SEQUENCE_APP_INFO_HH_
-
-#include <bundle_cpp.h>
-
-#include <chrono>
-#include <map>
-#include <set>
-#include <string>
-#include <vector>
-
-namespace aul::internal {
-
-namespace boot_sequence {
-
-class AppInfo {
- public:
- class Builder {
- public:
- Builder& SetAppId(const tizen_base::Bundle& args);
- Builder& SetUid(const tizen_base::Bundle& args);
- Builder& SetPriority(const tizen_base::Bundle& args);
- Builder& SetAfter(const tizen_base::Bundle& args);
- Builder& SetBefore(const tizen_base::Bundle& args);
- Builder& SetRequires(const tizen_base::Bundle& args);
- Builder& SetConflicts(const tizen_base::Bundle& args);
- Builder& SetVconf(const tizen_base::Bundle& args);
- Builder& SetArgs(const tizen_base::Bundle& args);
- Builder& SetBackgroundLaunch(const tizen_base::Bundle& args);
- Builder& SetWaitUntilReady(const tizen_base::Bundle& args);
- Builder& SetTimeout(const tizen_base::Bundle& args);
- Builder& SetActiveState(const tizen_base::Bundle& args);
- Builder& SetSubState(const tizen_base::Bundle& args);
- Builder& SetBeginTimestamp(const tizen_base::Bundle& args);
- Builder& SetEndTimestamp(const tizen_base::Bundle& args);
- Builder& SetSocketReadyTimestamp(const tizen_base::Bundle& args);
- Builder& SetTerminatedTimestamp(const tizen_base::Bundle& args);
- Builder& SetStatusMessage(const tizen_base::Bundle& args);
-
- AppInfo* Build();
-
- private:
- std::string appid_;
- uid_t uid_ = 0;
- int priority_ = 0;
- std::set<std::string> after_;
- std::set<std::string> before_;
- std::set<std::string> requires_;
- std::set<std::string> conflicts_;
- std::vector<std::string> vconf_;
- tizen_base::Bundle args_;
- std::string active_state_;
- std::string sub_state_;
- std::string begin_timestamp_;
- std::string end_timestamp_;
- std::string socket_ready_timestamp_;
- std::string terminated_timestamp_;
- bool background_launch_ = false;
- bool wait_until_ready_ = false;
- unsigned int timeout_ = 0;
- std::string status_msg_;
- };
-
- AppInfo(std::string appid, uid_t uid, int priority,
- std::set<std::string> after, std::set<std::string> before,
- std::set<std::string> requires_dep, std::set<std::string> conflicts,
- std::vector<std::string> vconfs,
- tizen_base::Bundle args,
- std::string active_state, std::string sub_state,
- std::string begin_timestamp, std::string end_timestamp,
- std::string status_msg,
- std::string socket_ready_timestamp, std::string terminated_timestamp,
- bool background_launch, bool wait_until_ready, unsigned int timeout);
-
- const std::string& GetAppId() const;
- uid_t GetUid() const;
- int GetPriority() const;
-
- bool AfterContains(const std::string& appid);
- const std::set<std::string>& AfterGet() const;
-
- bool BeforeContains(const std::string& appid);
- const std::set<std::string>& BeforeGet() const;
-
- bool RequiresContains(const std::string& appid);
- const std::set<std::string>& RequiresGet() const;
-
- bool ConflictsContains(const std::string& appid);
- const std::set<std::string>& ConflictsGet() const;
-
- const std::vector<std::string>& GetVconf() const;
- const tizen_base::Bundle& GetArgs() const;
- bool IsBackgroundLaunch() const;
- bool WaitUntilReady() const;
- unsigned int GetTimeout() const;
- const std::string& GetActiveState() const;
- const std::string& GetSubState() const;
- const std::string& GetBeginTimestamp() const;
- const std::string& GetEndTimestamp() const;
- const std::string& GetSocketReadyTimestamp() const;
- const std::string& GetTerminatedTimestamp() const;
- const std::string& GetStatusMessage() const;
-
- private:
- std::string appid_;
- uid_t uid_;
- int priority_;
- std::set<std::string> after_;
- std::set<std::string> before_;
- std::set<std::string> requires_;
- std::set<std::string> conflicts_;
- std::vector<std::string> vconf_;
- tizen_base::Bundle args_;
- std::string active_state_;
- std::string sub_state_;
- std::string begin_timestamp_;
- std::string end_timestamp_;
- std::string socket_ready_timestamp_;
- std::string terminated_timestamp_;
- bool background_launch_;
- bool wait_until_ready_;
- unsigned int timeout_;
- std::string status_msg_;
-};
-
-} // namespace boot_sequence
-
-} // namespace aul::internal
-
-#endif // AULCTL_BOOT_SEQUENCE_APP_INFO_HH_
+++ /dev/null
-/*
- * Copyright (c) 2021 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 "boot_sequence_manager.hh"
-
-#include <unistd.h>
-
-#include <utility>
-
-#include "common/file_descriptor.hh"
-#include "include/aul_sock.h"
-#include "src/app_request.h"
-#include "src/aul_util.h"
-
-namespace aul::internal {
-namespace boot_sequence {
-
-AppInfoPtr BootSequenceManager::CreateAppInfoFromBundle(tizen_base::Bundle b) {
- auto builder = AppInfo::Builder()
- .SetAppId(b)
- .SetUid(b)
- .SetPriority(b)
- .SetBefore(b)
- .SetAfter(b)
- .SetRequires(b)
- .SetConflicts(b)
- .SetVconf(b)
- .SetArgs(b)
- .SetTimeout(b)
- .SetActiveState(b)
- .SetSubState(b)
- .SetBackgroundLaunch(b)
- .SetWaitUntilReady(b)
- .SetBeginTimestamp(b)
- .SetEndTimestamp(b)
- .SetSocketReadyTimestamp(b)
- .SetTerminatedTimestamp(b);
-
- return std::shared_ptr<AppInfo>(builder.Build());
-}
-
-void BootSequenceManager::InsertAppInfoCb(app_pkt_t* pkt, void* data) {
- if (pkt == nullptr) {
- _E("Invalid parameter");
- return;
- }
-
- auto& appinfo_list = *static_cast<std::vector<AppInfoPtr>*>(data);
- if (pkt->cmd == APP_GET_INFO_ERROR) {
- _E("Failed to get running component context");
- return;
- }
-
- bundle* kb = nullptr;
- if (pkt->opt & AUL_SOCK_BUNDLE)
- kb = bundle_decode(pkt->data, pkt->len);
-
- if (kb == nullptr)
- return;
-
- auto app = GetInst().CreateAppInfoFromBundle(
- tizen_base::Bundle(kb, false, true));
- if (app == nullptr) {
- _E("Failed to create appinfo");
- return;
- }
-
- appinfo_list.push_back(std::move(app));
-}
-
-BootSequenceManager& BootSequenceManager::GetInst() {
- static BootSequenceManager inst;
- return inst;
-}
-
-int BootSequenceManager::Reload(uid_t uid) const {
- return AppRequest(BOOT_SEQUENCE_RELOAD, uid).SendSimply();
-}
-
-int BootSequenceManager::StartApp(const std::string& appid) const {
- return AppRequest(BOOT_SEQUENCE_START_APP, getuid())
- .SetAppId(appid)
- .SendSimply();
-}
-
-std::vector<AppInfoPtr> BootSequenceManager::GetAppInfoList(uid_t uid) const {
- int fd = AppRequest(BOOT_SEQUENCE_GET_APPINFO_LIST, uid)
- .SendSimply(AUL_SOCK_ASYNC);
-
- if (fd < 0 || fd >= sysconf(_SC_OPEN_MAX)) {
- _E("Failed to send request. error(%d)", fd);
- return {};
- }
-
- std::vector<AppInfoPtr> appinfo_list;
- int ret = aul_sock_recv_pkt_with_cb(fd, InsertAppInfoCb, &appinfo_list);
- if (ret < 0) {
- _E("Failed to receive reply packet. error(%d)", ret);
- return {};
- }
-
- return appinfo_list;
-}
-
-} // namespace boot_sequence
-} // namespace aul::internal
+++ /dev/null
-/*
- * Copyright (c) 2021 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 AULCTL_BOOT_SEQUENCE_BOOT_SEQUENCE_MANAGER_HH_
-#define AULCTL_BOOT_SEQUENCE_BOOT_SEQUENCE_MANAGER_HH_
-
-#include <bundle_cpp.h>
-
-#include <memory>
-#include <string>
-#include <vector>
-
-#include "include/aul_sock.h"
-#include "app_info.hh"
-
-namespace aul::internal {
-namespace boot_sequence {
-
-using AppInfoPtr = std::shared_ptr<AppInfo>;
-
-class BootSequenceManager {
- public:
- static BootSequenceManager& GetInst();
- BootSequenceManager(BootSequenceManager&) = delete;
- BootSequenceManager& operator=(BootSequenceManager&) = delete;
-
- int Reload(uid_t uid) const;
- int StartApp(const std::string &appid) const;
- std::vector<AppInfoPtr> GetAppInfoList(uid_t uid) const;
- std::string GetLogs() const;
-
- private:
- BootSequenceManager() = default;
- ~BootSequenceManager() = default;
-
- static void InsertAppInfoCb(app_pkt_t* pkt, void* data);
-
- AppInfoPtr CreateAppInfoFromBundle(tizen_base::Bundle b);
-};
-
-} // namespace boot_sequence
-} // namespace aul::internal
-
-#endif // AULCTL_BOOT_SEQUENCE_BOOT_SEQUENCE_MANAGER_HH_
+++ /dev/null
-/*
- * Copyright (c) 2022 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 "help_operation.hh"
-
-#include <iostream>
-
-namespace aul {
-namespace {
-
-constexpr const char HowTo[] =
-R"( - aulctl -
- Application boot sequence management tool
-
- usage: aulctl [cmd] [|args]
-
- cmd list:
-
- - list-apps [|uid] : Print list of boot sequence apps.
-
- - is-active [appid] : Print whether the app is activated.([active|inactive])
-
- - status [|appid] : Print status of the boot sequence app.
-
- - list-dependencies [|uid]: Print dependencies of boot sequence apps.
-
- - reload [|uid] : Reload the boot squence app's information.
-
- - start [appid] : Start the app according to the dependencies.
-
- - stop [appid] : Stop the app.
-)";
-
-} // namespace
-
-bool HelpOperation::Process() {
- std::cout << HowTo << std::endl;
-
- return true;
-}
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2022 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 "operation.hh"
-
-namespace aul {
-
-class HelpOperation : public Operation {
- public:
- HelpOperation() = default;
- ~HelpOperation() = default;
- bool Process() override;
-};
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2022 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 "is_active_operation.hh"
-
-#include <iostream>
-#include <string>
-#include <utility>
-
-#include "boot_sequence/boot_sequence_manager.hh"
-
-namespace aul {
-
-IsActiveOperation::IsActiveOperation(std::string appid)
- : appid_(std::move(appid)) {
-}
-
-bool IsActiveOperation::Process() {
- auto& manager = internal::boot_sequence::BootSequenceManager::GetInst();
- auto app_list = manager.GetAppInfoList(getuid());
- if (app_list.empty()) {
- std::cerr << "Failed to get boot sequence app list." << std::endl;
- return false;
- }
-
- for (auto& app : app_list) {
- if (app->GetAppId() == appid_) {
- std::cout << app->GetActiveState() << std::endl;
- return true;
- }
- }
-
- std::cerr << "Not found app info." << std::endl;
- return false;
-}
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2022 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 <string>
-
-#include "operation.hh"
-
-namespace aul {
-
-class IsActiveOperation : public Operation {
- public:
- explicit IsActiveOperation(std::string appid);
- ~IsActiveOperation() = default;
- bool Process() override;
-
- private:
- std::string appid_;
-};
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2022 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 "list_apps_operation.hh"
-
-#include <aul_boot_sequence.h>
-
-#include <iostream>
-
-#include "boot_sequence/boot_sequence_manager.hh"
-
-namespace aul {
-
-ListAppsOperation::ListAppsOperation(uid_t uid) : uid_(uid) {
-}
-
-bool ListAppsOperation::Process() {
- auto& manager = internal::boot_sequence::BootSequenceManager::GetInst();
- auto app_list = manager.GetAppInfoList(uid_);
- if (app_list.empty()) {
- std::cerr << "Failed to get boot sequence app list." << std::endl;
- return false;
- }
-
- std::cout << uid_ << " user boot sequence app list" << std::endl;
- for (auto& app : app_list)
- std::cout << app->GetAppId() << std::endl;
-
- return true;
-}
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2022 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 <sys/types.h>
-
-#include "operation.hh"
-
-namespace aul {
-
-class ListAppsOperation : public Operation {
- public:
- explicit ListAppsOperation(uid_t uid);
- ~ListAppsOperation() = default;
- bool Process() override;
-
- private:
- uid_t uid_;
-};
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2022 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 "list_dependencies_operation.hh"
-
-#include <aul_boot_sequence.h>
-
-#include <iostream>
-#include <map>
-#include <stack>
-#include <string>
-#include <vector>
-
-#include "boot_sequence/boot_sequence_manager.hh"
-
-namespace aul {
-
-ListDependenciesOperation::ListDependenciesOperation(uid_t uid) : uid_(uid) {
-}
-
-bool ListDependenciesOperation::Process() {
- auto& manager = internal::boot_sequence::BootSequenceManager::GetInst();
- auto app_list = manager.GetAppInfoList(uid_);
- if (app_list.empty()) {
- std::cerr << "Failed to get boot sequence app list." << std::endl;
- return false;
- }
-
- std::map<std::string, internal::boot_sequence::AppInfoPtr> infos;
- std::map<std::string, int> req_cnt;
- for (auto& app : app_list) {
- infos[app->GetAppId()] = app;
- if (req_cnt.find(app->GetAppId()) == req_cnt.end())
- req_cnt[app->GetAppId()] = 0;
-
- for (auto &appid : app->BeforeGet())
- req_cnt[appid]++;
- }
-
- std::stack<internal::boot_sequence::AppInfoPtr> stack;
- for (auto& [appid, cnt] : req_cnt) {
- if (cnt == 0 && infos.find(appid) != infos.end())
- stack.push(infos[appid]);
- }
-
- while (!stack.empty()) {
- auto app = std::move(stack.top());
- stack.pop();
-
- std::cout << app->GetAppId() << std::endl;
- std::cout << " After: ";
- for (auto& appid : app->AfterGet())
- std::cout << appid << ' ';
-
- std::cout << std::endl << " Before: ";
- for (auto& appid : app->BeforeGet())
- std::cout << appid << ' ';
-
- std::cout << std::endl << " Conflicts: ";
- for (auto& appid : app->ConflictsGet())
- std::cout << appid << ' ';
-
- std::cout << std::endl;
- std::cout << "============================================" << std::endl;
- for (auto& appid : app->BeforeGet()) {
- if (--req_cnt[appid] == 0 && infos.find(appid) != infos.end())
- stack.push(infos[appid]);
- }
- }
-
- return true;
-}
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2022 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 <sys/types.h>
-
-#include "operation.hh"
-
-namespace aul {
-
-class ListDependenciesOperation : public Operation {
- public:
- explicit ListDependenciesOperation(uid_t uid);
- ~ListDependenciesOperation() = default;
- bool Process() override;
-
- private:
- uid_t uid_;
-};
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2022 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 OPERATION_OPERATION_HH_
-#define OPERATION_OPERATION_HH_
-
-namespace aul {
-
-class Operation {
- public:
- virtual ~Operation() = default;
- virtual bool Process() = 0;
-};
-
-} // namespace aul
-
-#endif // OPERATION_OPERATION_HH_
+++ /dev/null
-/*
- * Copyright (c) 2022 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 "operation_factory.hh"
-
-#include <unistd.h>
-
-#include <iostream>
-#include <memory>
-#include <string>
-#include <utility>
-#include <vector>
-
-#include "help_operation.hh"
-#include "is_active_operation.hh"
-#include "list_apps_operation.hh"
-#include "list_dependencies_operation.hh"
-#include "start_operation.hh"
-#include "status_all_operation.hh"
-#include "status_once_operation.hh"
-#include "stop_operation.hh"
-#include "reload_operation.hh"
-
-namespace aul {
-
-std::unique_ptr<Operation> OperationFactory::CreateOperation(
- const std::vector<std::string>& args) const {
- try {
- if (args.empty())
- return std::make_unique<HelpOperation>();
-
- const auto& cmd = args[0];
- if (cmd == "list-apps") {
- if (args.size() == 1)
- return std::make_unique<ListAppsOperation>(getuid());
-
- return std::make_unique<ListAppsOperation>(
- static_cast<uid_t>(std::stoi(args[1])));
- } else if (cmd == "list-dependencies") {
- if (args.size() == 1)
- return std::make_unique<ListDependenciesOperation>(getuid());
-
- return std::make_unique<ListDependenciesOperation>(
- static_cast<uid_t>(std::stoi(args[1])));
- } else if (cmd == "is-active") {
- if (args.size() == 1)
- return std::make_unique<HelpOperation>();
-
- auto appid = args[1];
- return std::make_unique<IsActiveOperation>(std::move(appid));
- } else if (cmd == "status") {
- if (args.size() == 1)
- return std::make_unique<StatusAllOperation>();
-
- auto appid = args[1];
- return std::make_unique<StatusOnceOperation>(std::move(appid));
- } else if (cmd == "reload") {
- if (args.size() == 1)
- return std::make_unique<ReloadOperation>(getuid());
-
- return std::make_unique<ReloadOperation>(
- static_cast<uid_t>(std::stoi(args[1])));
- } else if (cmd == "start") {
- if (args.size() == 1)
- return std::make_unique<HelpOperation>();
-
- auto appid = args[1];
- return std::make_unique<StartOperation>(std::move(appid));
- } else if (cmd == "stop") {
- if (args.size() == 1)
- return std::make_unique<HelpOperation>();
-
- auto appid = args[1];
- return std::make_unique<StopOperation>(std::move(appid));
- } else {
- return std::make_unique<HelpOperation>();
- }
- } catch (const std::invalid_argument& error) {
- std::cerr << "Invalid patameter: " << error.what() << std::endl;
- return std::make_unique<HelpOperation>();
- }
-}
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2022 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 <memory>
-#include <vector>
-
-#include "operation.hh"
-
-namespace aul {
-
-class OperationFactory {
- public:
- OperationFactory() = default;
- ~OperationFactory() = default;
- std::unique_ptr<Operation> CreateOperation(
- const std::vector<std::string>& args) const;
-};
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2022 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 "reload_operation.hh"
-
-#include <iostream>
-
-#include "include/aul.h"
-#include "boot_sequence/boot_sequence_manager.hh"
-
-namespace aul {
-
-ReloadOperation::ReloadOperation(uid_t uid) : uid_(uid) {
-}
-
-bool ReloadOperation::Process() {
- auto &manager = internal::boot_sequence::BootSequenceManager::GetInst();
- int ret = manager.Reload(uid_);
- std::cout << "Reload result: " << ret << std::endl;
- return ret == AUL_R_OK;
-}
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2022 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 <sys/types.h>
-
-#include "operation.hh"
-
-namespace aul {
-
-class ReloadOperation : public Operation {
- public:
- explicit ReloadOperation(uid_t uid);
- ~ReloadOperation() = default;
- bool Process() override;
-
- private:
- uid_t uid_;
-};
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2022 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 "start_operation.hh"
-
-#include <iostream>
-
-#include "include/aul.h"
-#include "boot_sequence/boot_sequence_manager.hh"
-
-namespace aul {
-
-StartOperation::StartOperation(std::string appid)
- : appid_(std::move(appid)) {
-}
-
-bool StartOperation::Process() {
- auto& manager = internal::boot_sequence::BootSequenceManager::GetInst();
- int ret = manager.StartApp(appid_);
- if (ret != AUL_R_OK) {
- std::cerr << "Failed to start app(" << appid_ << ")" << std::endl;
- return false;
- }
-
- return true;
-}
-
-} // namespace aul
+++ /dev/null
-
-/*
- * Copyright (c) 2022 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 <string>
-
-#include "operation.hh"
-
-namespace aul {
-
-class StartOperation : public Operation {
- public:
- explicit StartOperation(std::string appid);
- ~StartOperation() = default;
- bool Process() override;
-
- private:
- std::string appid_;
-};
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2022 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 "status_all_operation.hh"
-
-#include <bundle.h>
-#include <bundle_cpp.h>
-
-#include <iostream>
-#include <string>
-#include <utility>
-
-#include "aul/api/aul_app_context.h"
-#include "boot_sequence/boot_sequence_manager.hh"
-
-namespace aul {
-
-bool StatusAllOperation::Process() {
- auto& manager = internal::boot_sequence::BootSequenceManager::GetInst();
- auto app_list = manager.GetAppInfoList(getuid());
- if (app_list.empty()) {
- std::cerr << "Failed to get boot sequence app list." << std::endl;
- return false;
- }
-
- for (const auto& app : app_list) {
- std::cout << "===========================================" << std::endl;
- std::cout << "appid: " << app->GetAppId() << std::endl;
-
- std::cout << "status: " << app->GetActiveState() << std::endl;
- std::cout << "sub status: " << app->GetSubState() << std::endl;
- if (app->GetSubState() == "failed")
- std::cout << " message: " << app->GetStatusMessage() << std::endl;
-
- aul_app_context_h context;
- int ret = aul_app_context_create(app->GetAppId().c_str(), &context);
- if (ret == 0) {
- const char* val = nullptr;
- aul_app_context_get_app_path(context, const_cast<char**>(&val));
- std::cout << "app path: " << val << std::endl;
- std::free(const_cast<char*>(val));
- pid_t pid = -1;
- aul_app_context_get_pid(context, &pid);
- std::cout << "pid: " << pid << std::endl;
- aul_app_context_destroy(context);
- }
-
- std::cout << "begin: " << app->GetBeginTimestamp() << std::endl;
- std::cout << "end: " << app->GetEndTimestamp() << std::endl;
-
- std::cout << "started time: " << app->GetSocketReadyTimestamp()
- << std::endl;
-
- std::cout << "termiated time: " << app->GetTerminatedTimestamp()
- << std::endl;
-
- std::cout << "requires: ";
- for (auto& appid : app->RequiresGet())
- std::cout << appid << " ";
-
- std::cout << std::endl;
-
- std::cout << "before: ";
- for (auto& appid : app->BeforeGet())
- std::cout << appid << " ";
-
- std::cout << std::endl;
-
- std::cout << "after: ";
- for (auto& appid : app->AfterGet())
- std::cout << appid << " ";
-
- std::cout << std::endl;
-
- std::cout << "conflict: ";
- for (auto& appid : app->ConflictsGet())
- std::cout << appid << " ";
-
- std::cout << std::endl;
-
- std::cout << "vconf: {\n";
- for (auto& vconf : app->GetVconf()) {
- std::cout << vconf << std::endl;
- }
- std::cout << "}" << std::endl;
-
- std::cout << "args: {\n";
- auto& b = app->GetArgs();
- bundle_foreach(
- b.GetHandle(),
- [](const char* key, const int type,
- const bundle_keyval_t* kv, void* data) {
- auto& kb = *static_cast<tizen_base::Bundle*>(data);
- std::cout << key << ": ";
- switch (type) {
- case BUNDLE_TYPE_STR:
- std::cout << kb.GetString(key) << std::endl;
- break;
- case BUNDLE_TYPE_STR_ARRAY:
- std::cout << "[ ";
- for (auto& val : kb.GetStringArray(key))
- std::cout << val << ", ";
-
- std::cout << "]" << std::endl;
- break;
- default:
- break;
- }
- },
- const_cast<tizen_base::Bundle*>(&b));
- std::cout << "}" << std::endl;
-
- std::cout << "bg-launch: " << (app->IsBackgroundLaunch() ? "true" : "false")
- << std::endl;
- std::cout << "===========================================" << std::endl;
- }
-
- return true;
-}
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2022 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 "operation.hh"
-
-namespace aul {
-
-class StatusAllOperation : public Operation {
- public:
- StatusAllOperation() = default;
- ~StatusAllOperation() = default;
- bool Process() override;
-};
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2022 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 "status_once_operation.hh"
-
-#include <iostream>
-#include <string>
-#include <utility>
-
-#include "boot_sequence/boot_sequence_manager.hh"
-#include "aul_app_context.h"
-#include "aul_boot_sequence.h"
-
-namespace aul {
-
-StatusOnceOperation::StatusOnceOperation(std::string appid)
- : appid_(std::move(appid)) {
-}
-
-bool StatusOnceOperation::Process() {
- auto& manager = internal::boot_sequence::BootSequenceManager::GetInst();
- auto app_list = manager.GetAppInfoList(getuid());
- if (app_list.empty()) {
- std::cerr << "Failed to get boot sequence app list." << std::endl;
- return false;
- }
-
- for (const auto& app : app_list) {
- if (app->GetAppId() != appid_)
- continue;
-
- std::cout << "appid: " << app->GetAppId() << std::endl;
-
- std::cout << "status: " << app->GetActiveState() << std::endl;
- std::cout << "sub status: " << app->GetSubState() << std::endl;
- if (app->GetSubState() == "failed")
- std::cout << " message: " << app->GetStatusMessage() << std::endl;
-
- aul_app_context_h context;
- int ret = aul_app_context_create(app->GetAppId().c_str(), &context);
- if (ret == 0) {
- const char* val = nullptr;
- aul_app_context_get_app_path(context, const_cast<char**>(&val));
- std::cout << "app path: " << val << std::endl;
- std::free(const_cast<char*>(val));
- pid_t pid = -1;
- aul_app_context_get_pid(context, &pid);
- std::cout << "pid: " << pid << std::endl;
- aul_app_context_destroy(context);
- }
-
- std::cout << "begin: " << app->GetBeginTimestamp() << std::endl;
- std::cout << "end: " << app->GetEndTimestamp() << std::endl;
-
- std::cout << "started time: " << app->GetSocketReadyTimestamp()
- << std::endl;
-
- std::cout << "termiated time: " << app->GetTerminatedTimestamp()
- << std::endl;
-
- std::cout << "requires: ";
- for (auto& appid : app->RequiresGet())
- std::cout << appid << " ";
-
- std::cout << std::endl;
-
- std::cout << "before: ";
- for (auto& appid : app->BeforeGet())
- std::cout << appid << " ";
-
- std::cout << std::endl;
-
- std::cout << "after: ";
- for (auto& appid : app->AfterGet())
- std::cout << appid << " ";
-
- std::cout << std::endl;
-
- std::cout << "conflict: ";
- for (auto& appid : app->ConflictsGet())
- std::cout << appid << " ";
-
- std::cout << std::endl;
-
- std::cout << "vconf: {\n";
- for (auto& vconf : app->GetVconf()) {
- std::cout << vconf << std::endl;
- }
- std::cout << "}" << std::endl;
-
- std::cout << "args: {\n";
- auto& b = app->GetArgs();
- bundle_foreach(
- b.GetHandle(),
- [](const char* key, const int type,
- const bundle_keyval_t* kv, void* data) {
- auto& kb = *static_cast<tizen_base::Bundle*>(data);
- std::cout << key << ": ";
- switch (type) {
- case BUNDLE_TYPE_STR:
- std::cout << kb.GetString(key) << std::endl;
- break;
- case BUNDLE_TYPE_STR_ARRAY:
- std::cout << "[ ";
- for (auto& val : kb.GetStringArray(key))
- std::cout << val << ", ";
-
- std::cout << "]" << std::endl;
- break;
- default:
- break;
- }
- },
- const_cast<tizen_base::Bundle*>(&b));
- std::cout << "}" << std::endl;
-
- std::cout << "bg-launch: " << (app->IsBackgroundLaunch() ? "true" : "false")
- << std::endl;
- return true;
- }
-
- std::cerr << "Not found app info." << std::endl;
- return false;
-}
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2022 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 <map>
-#include <string>
-
-#include "operation.hh"
-
-namespace aul {
-
-class StatusOnceOperation : public Operation {
- public:
- explicit StatusOnceOperation(std::string appid);
- ~StatusOnceOperation() = default;
- bool Process() override;
-
- private:
- std::string appid_;
-};
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2022 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 "stop_operation.hh"
-
-#include <iostream>
-
-#include "aul/api/aul_app_context.h"
-#include "include/aul.h"
-#include "boot_sequence/boot_sequence_manager.hh"
-
-namespace aul {
-
-StopOperation::StopOperation(std::string appid)
- : appid_(std::move(appid)) {
-}
-
-bool StopOperation::Process() {
- auto& manager = internal::boot_sequence::BootSequenceManager::GetInst();
- auto app_list = manager.GetAppInfoList(getuid());
- if (app_list.empty()) {
- std::cerr << "Failed to get boot sequence app list." << std::endl;
- return false;
- }
-
- for (auto& app : app_list) {
- if (app->GetAppId() != appid_)
- continue;
-
- int ret = aul_terminate_app(appid_.c_str());
- if (ret != AUL_R_OK) {
- std::cerr << "Failed to terminate app." << std::endl;
- return false;
- }
-
- std::cout << "Success to terminate app." << std::endl;
- return true;
- }
-
- std::cerr << "Not found app info." << std::endl;
- return false;
-}
-
-} // namespace aul
+++ /dev/null
-
-/*
- * Copyright (c) 2022 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 <string>
-
-#include "operation.hh"
-
-namespace aul {
-
-class StopOperation : public Operation {
- public:
- explicit StopOperation(std::string appid);
- ~StopOperation() = default;
- bool Process() override;
-
- private:
- std::string appid_;
-};
-
-} // namespace aul
+++ /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
-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
-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
-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;
-}
-
+++ /dev/null
-########################
-## 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}/db_internal.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})
-
-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}/db_internal.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})
-
-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)
+++ /dev/null
-/*
- * Copyright (c) 2020 - 2022 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 <tzplatform_config.h>
-
-#include "db_internal.h"
-
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
-#define ROOT_UID 0
-
-#define QUERY_CREATE_APPSVC \
- "PRAGMA journal_mode = PERSIST;\n" \
- "PRAGMA user_version = " APPSVC_DB_VERSION ";\n" \
- "CREATE TABLE IF NOT EXISTS appsvc (\n" \
- " operation TEXT,\n" \
- " mime_type TEXT DEFAULT 'NULL',\n" \
- " uri TEXT DEFAULT 'NULL',\n" \
- " pkg_name TEXT,\n" \
- " PRIMARY KEY (operation,mime_type,uri)\n" \
- ");\n" \
- "CREATE TABLE IF NOT EXISTS alias_info (\n" \
- " alias_appid TEXT NOT NULL,\n" \
- " appid TEXT NOT NULL,\n" \
- " enable TEXT NOT NULL DEFAULT 'true',\n" \
- " PRIMARY KEY (alias_appid)\n" \
- ");\n" \
- "CREATE TABLE IF NOT EXISTS alias_info_for_uid (\n" \
- " appid TEXT NOT NULL,\n" \
- " uid INTEGER NOT NULL,\n" \
- " is_enabled TEXT NOT NULL DEFAULT 'false',\n" \
- " PRIMARY KEY (appid, uid)\n" \
- ");\n" \
- "CREATE TRIGGER IF NOT EXISTS update_alias_info_for_uid\n" \
- " AFTER UPDATE ON alias_info_for_uid\n" \
- " BEGIN\n" \
- " DELETE FROM alias_info_for_uid\n" \
- " WHERE is_enabled='true';\n" \
- " END;\n" \
- "CREATE TABLE IF NOT EXISTS allowed_info (\n" \
- " appid TEXT NOT NULL,\n" \
- " allowed_appid TEXT NOT NULL,\n" \
- " PRIMARY KEY (appid, allowed_appid)\n" \
- ");\n" \
- "CREATE TABLE IF NOT EXISTS boot_sequence (\n" \
- " package TEXT NOT NULL,\n" \
- " appid TEXT NOT NULL,\n" \
- " after TEXT NOT NULL,\n" \
- " before TEXT NOT NULL,\n" \
- " requires TEXT NOT NULL,\n" \
- " conflicts TEXT NOT NULL,\n" \
- " vconf TEXT NOT NULL,\n" \
- " path_exists TEXT NOT NULL,\n" \
- " args TEXT NOT NULL,\n" \
- " background_launch TEXT NOT NULL,\n" \
- " wait_until_ready TEXT NOT NULL,\n" \
- " timeout TEXT NOT NULL,\n" \
- " PRIMARY KEY (appid)\n" \
- ");"
-
-static int __check_db_integrity(uid_t uid)
-{
- static const char *tables[] = {
- "alias_info",
- "alias_info_for_uid",
- "allowed_info",
- "appsvc",
- "boot_sequence",
- };
- char *db_path;
- int ret;
-
- db_path = _db_get_path(".appsvc.db", uid);
- if (!db_path) {
- fprintf(stderr, "Failed to get appsvc db path\n");
- return -1;
- }
-
- ret = _db_verify(db_path, tables, ARRAY_SIZE(tables));
- if (ret == 0) {
- free(db_path);
- return 0;
- }
-
- ret = _db_recovery(db_path, QUERY_CREATE_APPSVC, uid);
- if (ret != 0) {
- fprintf(stderr, "Failed to recovery %s\n", db_path);
- free(db_path);
- return -1;
- }
- free(db_path);
-
- printf("appsvc DB recovery process done\n");
- return 1;
-}
-
-int main(int argc, char **argv)
-{
- int ret;
-
- if (getuid() != ROOT_UID) {
- fprintf(stderr, "Only root user can run this tool\n");
- return -1;
- }
-
- ret = __check_db_integrity(tzplatform_getuid(TZ_SYS_GLOBALAPP_USER));
- if (ret < 0)
- return -1;
-
- ret = __check_db_integrity(tzplatform_getuid(TZ_SYS_DEFAULT_USER));
- if (ret < 0)
- return -1;
-
- return ret;
-}
+++ /dev/null
-/*
- * Copyright (c) 2020 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 <tzplatform_config.h>
-
-#include "db_internal.h"
-
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
-#define ROOT_UID 0
-
-#define QUERY_CREATE_COMPONENT \
- "PRAGMA journal_mode = PERSIST;\n" \
- "PRAGMA user_version = " COMPONENT_DB_VERSION ";\n" \
- "CREATE TABLE IF NOT EXISTS component_info (\n" \
- " package TEXT NOT NULL,\n" \
- " app_id TEXT NOT NULL,\n" \
- " component_id TEXT NOT NULL,\n" \
- " component_type TEXT NOT NULL,\n" \
- " component_launch_mode TEXT NOT NULL,\n" \
- " component_main TEXT NOT NULL,\n" \
- " component_icon_display NOT NULL,\n" \
- " component_taskmanage NOT NULL,\n" \
- " PRIMARY KEY (component_id)\n" \
- ");\n" \
- "CREATE TABLE IF NOT EXISTS component_localized_info (\n" \
- " component_id TEXT NOT NULL,\n" \
- " component_locale TEXT NOT NULL DEFAULT 'No Locale',\n" \
- " component_label TEXT,\n" \
- " component_icon TEXT,\n" \
- " PRIMARY KEY (component_id, component_locale)\n" \
- " FOREIGN KEY (component_id)\n" \
- " REFERENCES component_info(component_id) ON DELETE CASCADE\n" \
- ");"
-
-static int __check_db_integrity(uid_t uid)
-{
- static const char *tables[] = {
- "component_info",
- "component_localized_info",
- };
- char *db_path;
- int ret;
-
- db_path = _db_get_path(".component.db", uid);
- if (!db_path) {
- fprintf(stderr, "Failed to get component db path\n");
- return -1;
- }
-
- ret = _db_verify(db_path, tables, ARRAY_SIZE(tables));
- if (ret == 0) {
- free(db_path);
- return 0;
- }
-
- ret = _db_recovery(db_path, QUERY_CREATE_COMPONENT, uid);
- if (ret != 0) {
- fprintf(stderr, "Failed to recovery %s\n", db_path);
- free(db_path);
- return -1;
- }
- free(db_path);
-
- printf("component DB recovery process done\n");
- return 1;
-}
-
-int main(int argc, char **argv)
-{
- int ret;
-
- if (getuid() != ROOT_UID) {
- fprintf(stderr, "Only root user can run this tool\n");
- return -1;
- }
-
- ret = __check_db_integrity(tzplatform_getuid(TZ_SYS_GLOBALAPP_USER));
- if (ret < 0)
- return -1;
-
- ret = __check_db_integrity(tzplatform_getuid(TZ_SYS_DEFAULT_USER));
- if (ret < 0)
- return -1;
-
- return ret;
-}
+++ /dev/null
-/*
- * Copyright (c) 2021 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 <errno.h>
-#include <linux/limits.h>
-#include <pwd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/smack.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <tzplatform_config.h>
-
-#include "db_internal.h"
-
-#define BUSY_WAITING_USEC 50000
-#define BUSY_WAITING_MAX 100
-#define REGULAR_UID_MIN 5000
-
-char *_db_get_path(const char *file, uid_t uid)
-{
- char buf[PATH_MAX];
-
- if (uid >= REGULAR_UID_MIN) {
- snprintf(buf, sizeof(buf), "%s/user/%u/%s",
- tzplatform_getenv(TZ_SYS_DB), uid, file);
- } else {
- snprintf(buf, sizeof(buf), "%s/%s",
- tzplatform_getenv(TZ_SYS_DB), file);
- }
-
- return strdup(buf);
-}
-
-static int __db_busy_handler(void *data, int count)
-{
- const char *path = (const char *)data;
-
- if (count < BUSY_WAITING_MAX) {
- usleep(BUSY_WAITING_USEC);
- return 1;
- }
-
- _E("Database(%s) is busy", path);
- return 0;
-}
-
-sqlite3 *_db_open(const char *path, bool readonly)
-{
- sqlite3 *db;
- int flags;
- int ret;
-
- flags = readonly ? SQLITE_OPEN_READONLY : SQLITE_OPEN_READWRITE;
- ret = sqlite3_open_v2(path, &db, flags, NULL);
- if (ret != SQLITE_OK) {
- _E("sqlite3_open_v2() is failed. error(%d)", ret);
- sqlite3_close_v2(db);
- return NULL;
- }
-
- ret = sqlite3_busy_handler(db, __db_busy_handler, (void *)path);
- if (ret != SQLITE_OK) {
- _E("sqlite3_busy_handler() is failed. error(%s)",
- sqlite3_errmsg(db));
- sqlite3_close_v2(db);
- return NULL;
- }
-
- return db;
-}
-
-sqlite3 *_db_create(const char *path)
-{
- sqlite3 *db;
- int ret;
-
- ret = sqlite3_open_v2(path, &db,
- SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, NULL);
- if (ret != SQLITE_OK) {
- _E("sqlite3_open_v2() is failed. error(%d)", ret);
- sqlite3_close_v2(db);
- return NULL;
- }
-
- return db;
-}
-
-void _db_close(sqlite3 *db)
-{
- sqlite3_close_v2(db);
-}
-
-int _db_save_column_str(sqlite3_stmt *stmt, int idx, char **str)
-{
- const char *val;
-
- val = (const char *)sqlite3_column_text(stmt, idx);
- if (val) {
- *str = strdup(val);
- if (*str == NULL) {
- _E("Out of memory");
- return -ENOMEM;
- }
- }
-
- return 0;
-}
-
-static int __integrity_check(sqlite3 *db)
-{
- const char query[] = "PRAGMA integrity_check";
- sqlite3_stmt *stmt = NULL;
- const char *res;
- int ret;
-
- ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
- if (ret != SQLITE_OK) {
- _E("sqlite3_prepare_v2() is failed. error(%s)",
- sqlite3_errmsg(db));
- return -1;
- }
-
- ret = sqlite3_step(stmt);
- if (ret != SQLITE_ROW) {
- _E("sqlite3_step() is failed. error(%s)", sqlite3_errmsg(db));
- sqlite3_finalize(stmt);
- return -1;
- }
-
- res = (const char *)sqlite3_column_text(stmt, 0);
- if (!res) {
- _E("Failed to check integrity db. error(%s)",
- sqlite3_errmsg(db));
- sqlite3_finalize(stmt);
- return -1;
- }
-
- if (strcmp(res, "ok") != 0) {
- sqlite3_finalize(stmt);
- return -1;
- }
-
- sqlite3_finalize(stmt);
-
- return 0;
-}
-
-static int __check_table(sqlite3 *db, const char **tables, int table_count)
-{
- const char query[] = "SELECT name FROM sqlite_master "
- "WHERE type='table' ORDER BY name ASC";
- sqlite3_stmt *stmt = NULL;
- const char *val;
- int count = 0;
-
- __PREPARE_V2(db, query, strlen(query), stmt);
-
- while (sqlite3_step(stmt) == SQLITE_ROW && count < table_count) {
- val = (const char *)sqlite3_column_text(stmt, 0);
- if (val) {
- _E("%s %s", val, tables[count]);
- if (strcmp(tables[count], val) != 0)
- continue;
- count++;
- }
- }
-
- sqlite3_finalize(stmt);
-
- if (count != table_count) {
- _E("Wrong table count(%d:%d)", count, table_count);
- return -1;
- }
-
- return 0;
-}
-
-int _db_verify(const char *path, const char **tables, int table_count)
-{
- sqlite3 *db;
- int ret;
-
- if (!path) {
- _E("Invalid parameter");
- return -1;
- }
-
- ret = access(path, F_OK);
- if (ret != 0) {
- _E("%s does not exists. errno(%d)", path, errno);
- return -1;
- }
-
- db = _db_open(path, true);
- if (!db) {
- _E("Failed to open database(%s)", path);
- return -1;
- }
-
- ret = __integrity_check(db);
- if (ret != 0) {
- _E("Database(%s) is corrupted", path);
- _db_close(db);
- return -1;
- }
-
- ret = __check_table(db, tables, table_count);
- _db_close(db);
- if (ret != 0) {
- _E("Database(%s) is corrupted", path);
- return -1;
- }
-
- return 0;
-}
-
-static int __change_permission(const char *path)
-{
- mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
- char path_db_journal[PATH_MAX];
- int ret;
-
- ret = chmod(path, mode);
- if (ret != 0) {
- _E("chmod() is failed. errno(%d)", errno);
- return -1;
- }
-
- snprintf(path_db_journal, sizeof(path_db_journal), "%s-journal", path);
- ret = chmod(path_db_journal, mode);
- if (ret != 0) {
- _E("chmod() is failed. errno(%d)", errno);
- return -1;
- }
-
- return 0;
-}
-
-static int __change_ownership(const char *path, uid_t uid)
-{
-#define ROOT_UID 0
- struct passwd pwd;
- struct passwd *result;
- char path_db_journal[PATH_MAX];
- char buf[PATH_MAX];
- uid_t new_uid;
- int ret;
-
- ret = getpwuid_r(uid, &pwd, buf, sizeof(buf), &result);
- if (result == NULL) {
- if (ret == 0)
- _E("No such user(%u)", uid);
- else
- _E("getpwuid_r() is failed. errno(%d)", errno);
- return -1;
- }
-
- if (pwd.pw_uid == tzplatform_getuid(TZ_SYS_GLOBALAPP_USER))
- new_uid = ROOT_UID;
- else
- new_uid = pwd.pw_uid;
-
- ret = chown(path, new_uid, pwd.pw_gid);
- if (ret != 0) {
- _E("chown() is failed. errno(%d)", errno);
- return -1;
- }
-
- snprintf(path_db_journal, sizeof(path_db_journal), "%s-journal", path);
- ret = chown(path_db_journal, new_uid, pwd.pw_gid);
- if (ret != 0) {
- _E("chown() is failed. errno(%d)", errno);
- return -1;
- }
-
- return 0;
-}
-
-static int __change_smack(const char *path)
-{
-#define DB_LABEL "User::Home"
- char path_db_journal[PATH_MAX];
- int ret;
-
- ret = smack_setlabel(path, DB_LABEL, SMACK_LABEL_ACCESS);
- if (ret != 0) {
- _E("smack_setlabel() is failed. error(%d)", ret);
- return -1;
- }
-
- snprintf(path_db_journal, sizeof(path_db_journal), "%s-journal", path);
- ret = access(path_db_journal, F_OK);
- if (ret == 0) {
- ret = smack_setlabel(path_db_journal, DB_LABEL,
- SMACK_LABEL_ACCESS);
- if (ret != 0) {
- _E("smack_setlabel() is failed. error(%d)", ret);
- return -1;
- }
- }
-
- return 0;
-}
-
-int _db_recovery(const char *path, const char *query, uid_t uid)
-{
- char *errmsg = NULL;
- sqlite3 *db;
- int ret;
-
- if (!path || !query) {
- _E("Invalid parameter");
- return -1;
- }
-
- ret = access(path, F_OK);
- if (ret == 0)
- unlink(path);
-
- db = _db_create(path);
- if (!db) {
- _E("Failed to open database(%s)", path);
- return -1;
- }
-
- ret = sqlite3_exec(db, query, NULL, NULL, &errmsg);
- _db_close(db);
- if (ret != SQLITE_OK) {
- _E("sqlite3_exec() is failed. error(%d:%s)", ret, errmsg);
- sqlite3_free(errmsg);
- return -1;
- }
-
- ret = __change_smack(path);
- if (ret != 0) {
- _E("Failed to change smack label of %s", path);
- return -1;
- }
-
- ret = __change_ownership(path, uid);
- if (ret != 0) {
- _E("Failed to change ownership of %s", path);
- return -1;
- }
-
- ret = __change_permission(path);
- if (ret != 0) {
- _E("Failed to change permissions of %s", path);
- return -1;
- }
-
- return 0;
-}
+++ /dev/null
-/*
- * Copyright (c) 2021 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 __DB_INTERNAL_H__
-#define __DB_INTERNAL_H__
-
-#include <sqlite3.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <unistd.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define _E(fmt, ...) \
- fprintf(stderr, "%s(%d): "fmt"\n", \
- __FUNCTION__, __LINE__, ##__VA_ARGS__)
-
-#define __PREPARE_V2(db, query, length, stmt) do { \
- if (sqlite3_prepare_v2(db, query, length, &stmt, NULL) != SQLITE_OK) { \
- _E("sqlite3_prepare_v2() is failed. error(%s)", \
- sqlite3_errmsg(db)); \
- return -1; \
- } \
-} while (0)
-
-#define __BIND_TEXT(db, stmt, i, text) do { \
- if (sqlite3_bind_text(stmt, i, text, -1, SQLITE_STATIC) != SQLITE_OK) {\
- _E("sqlite3_bind_text() is failed. index(%d), error(%s)", \
- i, sqlite3_errmsg(db)); \
- sqlite3_finalize(stmt); \
- return -1; \
- } \
-} while (0)
-
-#define __BIND_INT(db, stmt, i, val) do { \
- if (sqlite3_bind_int(stmt, i, val) != SQLITE_OK) { \
- _E("sqlite3_bind_int() is failed. index(%d), error(%s)", \
- i, sqlite3_errmsg(db)); \
- sqlite3_finalize(stmt); \
- return -1; \
- } \
-} while (0)
-
-#define __STEP(db, stmt) do { \
- if (sqlite3_step(stmt) != SQLITE_DONE) { \
- _E("sqlite3_step() is failed. error(%s)", \
- sqlite3_errmsg(db)); \
- sqlite3_finalize(stmt); \
- return -1; \
- } \
-} while (0)
-
-char *_db_get_path(const char *file, uid_t uid);
-
-sqlite3 *_db_open(const char *path, bool readonly);
-
-void _db_close(sqlite3* db);
-
-int _db_verify(const char *path, const char **tables, int table_count);
-
-int _db_recovery(const char *path, const char *query, uid_t uid);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __DB_INTERNAL_H__ */