SET(TARGET_ESD "esd")
SET(TARGET_LIB_ESD "libesd")
-## Target modules
-SET(TARGET_ESD_MOD_CION "esd-mod-cion")
-SET(TARGET_ESD_MOD_DBUS_EVENT "esd-mod-dbus-event")
-SET(TARGET_ESD_MOD_CION_UNITTESTS "esd-mod-cion-unittests")
-SET(TARGET_ESD_MOD_DBUS_EVENT_UNITTESTS "esd-mod-dbus-event-unittests")
-
-#ENABLE_TESTING()
-#SET(TARGET_ESD_UNIT_TESTS "esd-unit-tests")
-
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
INCLUDE(FindPkgConfig)
INCLUDE(ApplyPkgConfig)
-PKG_CHECK_MODULES(AUL_DEPS REQUIRED aul)
-PKG_CHECK_MODULES(BUNDLE_DEPS REQUIRED bundle)
-PKG_CHECK_MODULES(CAPI_SYSTEM_INFO_DEPS REQUIRED capi-system-info)
-PKG_CHECK_MODULES(CERT_SVC_VCORE_DEPS REQUIRED cert-svc-vcore)
-PKG_CHECK_MODULES(CYNARA_CLIENT_DEPS REQUIRED cynara-client)
-PKG_CHECK_MODULES(CYNARA_CREDS_DBUS_DEPS REQUIRED cynara-creds-gdbus)
-PKG_CHECK_MODULES(CYNARA_SESSION_DEPS REQUIRED cynara-session)
PKG_CHECK_MODULES(DLOG_DEPS REQUIRED dlog)
-PKG_CHECK_MODULES(GIO_DEPS REQUIRED gio-2.0)
PKG_CHECK_MODULES(GLIB_DEPS REQUIRED glib-2.0)
-PKG_CHECK_MODULES(LIBTZPLATFORM_CONFIG_DEPS REQUIRED libtzplatform-config)
-PKG_CHECK_MODULES(PARCEL_DEPS REQUIRED parcel)
-PKG_CHECK_MODULES(PKGMGR_INFO_DEPS REQUIRED pkgmgr-info)
-PKG_CHECK_MODULES(SECURITY_MANAGER_DEPS REQUIRED security-manager)
-PKG_CHECK_MODULES(SQLITE3_DEPS REQUIRED sqlite3)
-PKG_CHECK_MODULES(CION_DEPS REQUIRED cion)
-PKG_CHECK_MODULES(UUID_DEPS REQUIRED uuid)
-PKG_CHECK_MODULES(VCONF_DEPS REQUIRED vconf)
-PKG_CHECK_MODULES(PKGMGR_DEPS REQUIRED pkgmgr)
-PKG_CHECK_MODULES(EVENTSYSTEM_DEPS REQUIRED eventsystem)
-PKG_CHECK_MODULES(DATABASE_DEPS REQUIRED tizen-database)
-PKG_CHECK_MODULES(GMOCK_DEPS REQUIRED gmock)
-PKG_CHECK_MODULES(APPSVC_DEPS REQUIRED appsvc)
+PKG_CHECK_MODULES(RPC_PORT_DEPS REQUIRED rpc-port)
ADD_SUBDIRECTORY(src)
-
-IF(NOT DEFINED MINIMUM_BUILD)
-ADD_SUBDIRECTORY(tests)
-ENABLE_TESTING()
-
-ADD_TEST(NAME ${TARGET_ESD_MOD_CION_UNITTESTS} COMMAND ${TARGET_ESD_MOD_CION_UNITTESTS})
-ADD_DEPENDENCIES(${TARGET_ESD_MOD_CION_UNITTESTS} ${PROJECT_NAME})
-
-ADD_TEST(NAME ${TARGET_ESD_MOD_DBUS_EVENT_UNITTESTS} COMMAND ${TARGET_ESD_MOD_DBUS_EVENT_UNITTESTS})
-ADD_DEPENDENCIES(${TARGET_ESD_MOD_DBUS_EVENT_UNITTESTS} ${PROJECT_NAME})
-ENDIF(NOT DEFINED MINIMUM_BUILD)
[Unit]
Description=Start the Event System Daemon
-Requires=buxton2.service dbus.socket
-After=buxton2.service dbus.socket
+Requires=buxton2.service
+After=buxton2.service
DefaultDependencies=no
[Service]
User=app_fw
Group=app_fw
-Type=dbus
+Type=simple
SmackProcessLabel=System
-BusName=tizen.system.event.app2esd
Environment=AUL_BLINK=1
ExecStart=/usr/bin/esd
Restart=on-failure
Source1: esd.service
Source1001: %{name}.manifest
BuildRequires: cmake
-BuildRequires: pkgconfig(aul)
-BuildRequires: pkgconfig(bundle)
-BuildRequires: pkgconfig(parcel)
BuildRequires: pkgconfig(dlog)
-BuildRequires: pkgconfig(pkgmgr-info)
-BuildRequires: pkgconfig(appsvc)
-BuildRequires: pkgconfig(gio-2.0)
BuildRequires: pkgconfig(glib-2.0)
-BuildRequires: pkgconfig(pkgmgr)
-BuildRequires: pkgconfig(eventsystem)
-BuildRequires: pkgconfig(vconf)
-BuildRequires: pkgconfig(libtzplatform-config)
-BuildRequires: pkgconfig(systemd)
-BuildRequires: pkgconfig(cert-svc-vcore)
-BuildRequires: pkgconfig(cynara-client)
-BuildRequires: pkgconfig(cynara-creds-gdbus)
-BuildRequires: pkgconfig(cynara-session)
-BuildRequires: pkgconfig(security-manager)
-BuildRequires: pkgconfig(uuid)
-BuildRequires: pkgconfig(sqlite3)
-BuildRequires: pkgconfig(cion)
-BuildRequires: pkgconfig(capi-system-info)
-BuildRequires: pkgconfig(tizen-database)
-BuildRequires: pkgconfig(gmock)
+BuildRequires: pkgconfig(rpc-port)
+BuildRequires: pkgconfig(bundle)
%if 0%{?gcov:1}
BuildRequires: lcov
Requires(post): /sbin/ldconfig
Requires(postun): /sbin/ldconfig
+Recommends: esd-mod-group
+Recommends: esd-mod-cion
+
%description
Event System Daemon
%description devel
Event system Daemon (devel)
-%package -n esd-mod-cion
-Summary: ESD module for cion
-Group: Application Framework/Service
-
-%description -n esd-mod-cion
-This module is for cion
-
-%package -n esd-mod-dbus-event
-Summary: ESD module for dbus-event
-Group: Application Framework/Service
-
-%description -n esd-mod-dbus-event
-This module is for event system using dbus
-
-%define _moddir %{_datadir}/esd
-
#################################################
# unittests
#################################################
%description -n %{name}-unittests
GTest for API
-%if 0%{?gcov:1}
-%package gcov
-Summary: Event system daemon(gcov)
-Group: Application Framework/Service
-
-%description gcov
-gcov objects of a Event System
-%endif
-
%prep
%setup -q
cp %{SOURCE1001} .
%build
-%if 0%{?gcov:1}
-export CFLAGS+=" -fprofile-arcs -ftest-coverage"
-export CXXFLAGS+=" -fprofile-arcs -ftest-coverage"
-export FFLAGS+=" -fprofile-arcs -ftest-coverage"
-export LDFLAGS+=" -lgcov"
-%endif
-
export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE"
export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE"
export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE"
%cmake \
-DFULLVER=%{version} \
-DMAJORVER=${MAJORVER} \
- -DESD_MODULES_DIR=%{_moddir} \
.
make %{?jobs:-j%jobs}
-%check
-ctest -V
-
-%if 0%{?gcov:1}
-lcov -c --ignore-errors mismatch,graph,unused --no-external -b . -d . -o %{name}.info
-genhtml %{name}.info -o out --legend --show-details
-%endif
-
%install
rm -rf %{buildroot}
%make_install
-cat << EOF > run-unittest.sh
-#!/bin/sh
-setup() {
- echo "setup start"
-}
-
-test_main() {
- echo "test_main start"
- /usr/bin/esd-mod-cion-unittests
- /usr/bin/esd-mod-dbus_event-unittests
-}
-
-teardown() {
- echo "teardown start"
-}
-
-main() {
- setup
- test_main
- teardown
-}
-
-main "\$*"
-EOF
-
-mkdir -p %{buildroot}%{_bindir}/tizen-unittests/%{name}
-install -m 0755 run-unittest.sh %{buildroot}%{_bindir}/tizen-unittests/%{name}/
-
mkdir -p %{buildroot}%{_unitdir}/basic.target.wants
install -m 0644 %SOURCE1 %{buildroot}%{_unitdir}/esd.service
ln -sf ../esd.service %{buildroot}%{_unitdir}/basic.target.wants/esd.service
-%if 0%{?gcov:1}
-builddir=$(basename $PWD)
-gcno_obj_dir=%{buildroot}%{_datadir}/gcov/obj/%{name}/"$builddir"
-mkdir -p "$gcno_obj_dir"
-find . -name '*.gcno' -exec cp --parents '{}' "$gcno_obj_dir" ';'
-%endif
-
%post -p /sbin/ldconfig
%postun -p /sbin/ldconfig
%files
%manifest %{name}.manifest
-%config %{_sysconfdir}/dbus-1/system.d/eventsystem.conf
%defattr(-,root,root,-)
%{_bindir}/esd
%{_libdir}/libesd.so.*
%{_unitdir}/esd.service
%{_unitdir}/basic.target.wants/esd.service
-%attr(0644,root,root) %{_datadir}/dbus-1/system-services/tizen.system.event.app2esd.service
%license LICENSE
%files devel
%{_includedir}/esd/*.hh
%{_libdir}/libesd.so
%{_libdir}/pkgconfig/*pc
-
-%files -n esd-mod-cion
-%manifest %{name}.manifest
-%license LICENSE
-%{_moddir}/mod/libesd-mod-cion.so
-
-%files -n esd-mod-dbus-event
-%manifest %{name}.manifest
-%license LICENSE
-%{_moddir}/mod/libesd-mod-dbus-event.so
-
-#################################################
-# unittests
-#################################################
-%files -n %{name}-unittests
-%{_bindir}/esd-*-unittests
-%{_bindir}/tizen-unittests/%{name}/run-unittest.sh
-
-%if 0%{?gcov:1}
-%files gcov
-%{_datadir}/gcov/*
-%endif
ADD_SUBDIRECTORY(esd)
ADD_SUBDIRECTORY(lib)
-ADD_SUBDIRECTORY(modules)
APPLY_PKG_CONFIG(${TARGET_ESD} PUBLIC
DLOG_DEPS
GLIB_DEPS
+ RPC_PORT_DEPS
)
INSTALL(TARGETS ${TARGET_ESD} DESTINATION bin)
-CONFIGURE_FILE(tizen.system.event.app2esd.service.in tizen.system.event.app2esd.service @ONLY)
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/tizen.system.event.app2esd.service DESTINATION ${SHARE_INSTALL_PREFIX}/dbus-1/system-services/)
* limitations under the License.
*/
+#include <stdlib.h>
+
+#include <log.hh>
+
#include "module_runner.hh"
constexpr const char MODULE_PATH[] = "/usr/share/esd/mod/";
int main(int argc, char* argv[]) {
+ _W("main");
+ setenv("AUL_APPID", "d::org.tizen.appfw.service.esd", 1);
esd::ModuleRunner runner;
if (runner.Run(MODULE_PATH))
#include <dirent.h>
#include <fcntl.h>
#include <glib.h>
+#include <rpc-port-internal.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
bool ModuleRunner::InitModules(const std::string& module_path) {
DIR* dp = opendir(module_path.c_str());
- if (dp == nullptr)
- return false;
+ if (dp == nullptr) return false;
+
+ int ret =
+ rpc_port_register_proc_info("d::org.tizen.appfw.service.esd", nullptr);
+ if (ret != RPC_PORT_ERROR_NONE) {
+ _I("rpc_port_register_proc_info() failed (%d)", ret);
+ }
dirent* dentry;
while ((dentry = readdir(dp)) != nullptr) {
- if (dentry->d_name[0] == '.')
- continue;
+ if (dentry->d_name[0] == '.') continue;
char* extension = strrchr(dentry->d_name, '.');
- if (extension == nullptr || strcmp(extension, ".so") != 0)
- continue;
+ if (extension == nullptr || strcmp(extension, ".so") != 0) continue;
- std::string path = module_path + "/" +
- std::string(dentry->d_name);
+ std::string path = module_path + "/" + std::string(dentry->d_name);
if (!InitModule(path)) {
closedir(dp);
dlopen(module_path.c_str(), RTLD_LAZY | RTLD_GLOBAL));
if (!handle) {
_E("dlopen() is failed. path(%s), error(%s)", module_path.c_str(),
- dlerror());
+ dlerror());
return false;
}
using esd_mod_func = esd::api::IModule* (*)();
- auto* get_mod = reinterpret_cast<esd_mod_func>(
- dlsym(handle.get(), "ESD_GET_MODULE"));
+ auto* get_mod =
+ reinterpret_cast<esd_mod_func>(dlsym(handle.get(), "ESD_GET_MODULE"));
if (get_mod == nullptr) {
_E("dlsym() is failed");
return false;
}
void ModuleRunner::FiniModules() {
- for (auto& mod : modules_)
- mod->Shutdown();
+ for (auto& mod : modules_) mod->Shutdown();
}
} // namespace esd
\ No newline at end of file
+++ /dev/null
-[D-BUS Service]
-Name=tizen.system.event.app2esd\r
-Exec=/bin/false
-SystemdService=esd.service
\ No newline at end of file
${CMAKE_CURRENT_SOURCE_DIR}/)
APPLY_PKG_CONFIG(${TARGET_LIB_ESD} PUBLIC
- AUL_DEPS
DLOG_DEPS
- GIO_DEPS
- GLIB_DEPS
)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig/${TARGET_LIB_ESD}.pc.in
+++ /dev/null
-ADD_SUBDIRECTORY(cion)
-ADD_SUBDIRECTORY(dbus_event)
+++ /dev/null
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} ESD_MOD_CION_SRCS)
-
-ADD_LIBRARY(${TARGET_ESD_MOD_CION} ${ESD_MOD_CION_SRCS})
-
-TARGET_INCLUDE_DIRECTORIES(${TARGET_ESD_MOD_CION} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}/../../lib)
-
-TARGET_LINK_LIBRARIES(${TARGET_ESD_MOD_CION} PRIVATE ${TARGET_LIB_ESD})
-
-APPLY_PKG_CONFIG(${TARGET_ESD_MOD_CION} PUBLIC
- AUL_DEPS
- BUNDLE_DEPS
- PARCEL_DEPS
- PKGMGR_INFO_DEPS
- DLOG_DEPS
- GIO_DEPS
- GLIB_DEPS
- CION_DEPS
- VCONF_DEPS
- CAPI_SYSTEM_INFO_DEPS
- LIBTZPLATFORM_CONFIG_DEPS
- UUID_DEPS
- SQLITE3_DEPS
- DATABASE_DEPS
-)
-
-INSTALL(TARGETS ${TARGET_ESD_MOD_CION} DESTINATION ${ESD_MODULES_DIR}/mod
- COMPONENT RuntimeLibraries)
+++ /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 "cion_module.hh"
-
-#undef EXPORT_API
-#define EXPORT_API __attribute__((visibility("default")))
-
-extern "C" EXPORT_API esd::api::IModule* ESD_GET_MODULE() {
- return new esd::module::CionModule();
-}
\ No newline at end of file
+++ /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 "cion_module.hh"
-
-#include <uuid/uuid.h>
-#include <unistd.h>
-#include <tzplatform_config.h>
-#include <stdbool.h>
-
-#include "log.hh"
-
-#define DBPATH tzplatform_mkpath(TZ_SYS_DB, ".cion.db")
-
-namespace esd::module {
-
-using tizen_base::_;
-
-namespace {
-
-constexpr const char CREATE_CION_TABLE[] = R"__cion(
-PRAGMA user_version = 50;
-PRAGMA journal_mode = PERSIST;
-PRAGMA foreign_keys = ON;
-CREATE TABLE IF NOT EXISTS cion_uuid (
- appid TEXT NOT NULL,
- uuid TEXT NOT NULL,
- PRIMARY KEY(appid)
-);
-CREATE TABLE IF NOT EXISTS cion_display_name (
- service_name TEXT NOT NULL,
- appid TEXT NOT NULL,
- display_name TEXT NULL,
- enabled INTEGER DEFAULT 0,
- PRIMARY KEY(service_name, appid) ,
- FOREIGN KEY(appid) REFERENCES cion_uuid (appid) ON DELETE CASCADE
-);
-)__cion";
-
-constexpr const char PRAGMA_FOREIGN_KEYS[] = "PRAGMA foreign_keys;";
-
-bool CreateTable(const tizen_base::Database& db) {
- try {
- auto q = tizen_base::Database::Sql(CREATE_CION_TABLE);
- db.OneStepExec(q);
- } catch (const tizen_base::DbException& e) {
- _E("Exception(%s) occurs", e.msg());
- return false;
- }
-
- return true;
-}
-
-bool IsEnabledForeignKeys(const tizen_base::Database& db) {
- try {
- auto sql = tizen_base::Database::Sql(PRAGMA_FOREIGN_KEYS);
- auto result = db.Exec(sql);
- for (const auto& i : result)
- return static_cast<int>(i.Get(0)) ? true : false;
- } catch (const tizen_base::DbException& e) {
- _E("Exception(%s) occurs", e.msg());
- }
-
- return false;
-}
-
-} // namespace
-
-bool CionModule::Startup(api::ToolBox* tools) {
- tools_ = tools;
- tools->GetMethodBroker().Register("Cion.GetUuidWithGenerate",
- api::Params<const std::string&, std::optional<std::string>&>(
- [this](const std::string& appid, std::optional<std::string>& uuid) {
- GetUuidWithGenerate(appid, uuid);
- }));
- tools->GetMethodBroker().Register("Cion.SetDisplayName",
- api::Params<const std::string&, const std::string&,
- const std::string&, int&>(
- [this](const std::string& appid, const std::string& service_name,
- const std::string& display_name, int& ret) {
- SetDisplayName(appid, service_name, display_name, ret);
- }));
- tools->GetMethodBroker().Register("Cion.GetDisplayName",
- api::Params<const std::string&, const std::string&, std::string&, int&>(
- [this](const std::string& appid, const std::string& service_name,
- std::string& display_name, int& ret) {
- GetDisplayName(appid, service_name, display_name, ret);
- }));
- tools->GetMethodBroker().Register("Cion.SetEnabled",
- api::Params<const std::string&, const std::string&, bool, int&>(
- [this](const std::string& appid, const std::string& service_name,
- bool enabled, int& ret) {
- SetEnabled(appid, service_name, enabled, ret);
- }));
- tools->GetMethodBroker().Register("Cion.GetEnabled",
- api::Params<const std::string&, const std::string&, bool&, int&>(
- [this](const std::string& appid, const std::string& service_name,
- bool& enabled, int& ret) {
- GetEnabled(appid, service_name, enabled, ret);
- }));
-
- return Init();
-}
-
-void CionModule::Shutdown() {
- if (!tools_)
- return;
- tools_->GetMethodBroker().Unregister("Cion.GetUuidWithGenerate");
- tools_->GetMethodBroker().Unregister("Cion.SetDisplayName");
- tools_->GetMethodBroker().Unregister("Cion.GetDisplayName");
- tools_->GetMethodBroker().Unregister("Cion.SetEnabled");
- tools_->GetMethodBroker().Unregister("Cion.GetEnabled");
- tools_ = nullptr;
-}
-
-bool CionModule::Init() {
- try {
- esd_cion_server_ =
- std::make_shared<CionOndemandServer>("__CION_INTERNAL_DAEMON__",
- "", this);
- } catch (const cion::Exception& e) {
- _D("cion_init failed : %s", e.what());
- return false;
- }
-
- _D("cion_init done");
- ChangeListenStatusCionServer();
-
- return DbInit();
-}
-
-void CionModule::ChangeListenStatusCionServer() {
- try {
- auto ret = GetEnabledServiceList();
- if (!ret) {
- _D("Get list error");
- } else if (ret->empty() && is_listening_) {
- esd_cion_server_->Stop();
- is_listening_ = false;
- _D("esd_cion_server stop listen");
- } else if (!ret->empty() && !is_listening_) {
- esd_cion_server_->Listen();
- is_listening_ = true;
- _D("esd_cion_server start listen");
- }
- } catch (const cion::Exception& e) {
- _E("cion_init failed : %s", e.what());
- }
-
- return;
-}
-
-void CionModule::AddEnabledApp(const std::string& service_name,
- const std::string& app_id, const std::string& display_name) {
- if (esd_cion_server_ == nullptr) {
- _E("Call init function at first");
- return;
- }
-
- esd_cion_server_->AddOndemandServiceList(service_name, app_id, display_name);
- if (!is_listening_)
- ChangeListenStatusCionServer();
-}
-
-void CionModule::RemoveEnabledApp(const std::string& service_name,
- const std::string& app_id) {
- if (esd_cion_server_ == nullptr) {
- _E("Call init function at first");
- return;
- }
-
- esd_cion_server_->RemoveOndemandServiceList(service_name, app_id);
-
- if (is_listening_)
- ChangeListenStatusCionServer();
-}
-
-bool CionModule::DbInit() {
- try {
- tizen_base::Database db(DBPATH, SQLITE_OPEN_READWRITE);
- if (!CreateTable(db)) {
- _E("Fail to create table");
- return false;
- }
-
- _W("foreign_keys: %s", IsEnabledForeignKeys(db) ? "ON" : "OFF");
- } catch (const tizen_base::DbException& e) {
- _E("runtime error(%s) occurs", e.msg());
- unlink(DBPATH);
- try {
- tizen_base::Database db(DBPATH, SQLITE_OPEN_CREATE |
- SQLITE_OPEN_READWRITE);
- if (!CreateTable(db)) {
- _E("Fail to create table");
- return false;
- }
-
- _W("foreign_keys: %s", IsEnabledForeignKeys(db) ? "ON" : "OFF");
- } catch (const tizen_base::DbException& e) {
- _E("runtime error(%s) occurs", e.msg());
- unlink(DBPATH);
- return false;
- }
- }
-
- return true;
-}
-
-std::string CionModule::GenUuid() {
- uuid_t uu;
- char _uuid[37];
-
- uuid_generate_random(uu);
- uuid_unparse(uu, _uuid);
-
- return _uuid;
-}
-
-bool CionModule::GetUuidFromDb(const tizen_base::Database& db,
- const std::string& appid, std::string& uuid) {
- auto q = tizen_base::Database::Sql(
- "SELECT uuid FROM cion_uuid WHERE appid = ?")
- .Bind(appid);
- auto r = db.Exec(q);
- if (!static_cast<bool>(r))
- return false;
-
- for (const auto& i : r) {
- uuid = static_cast<std::string>(i.Get(0));
- return true;
- }
-
- return false;
-}
-
-bool CionModule::SetUuidToDb(const tizen_base::Database& db,
- const std::string& appid, const std::string& uuid) {
- auto q = tizen_base::Database::Sql(
- "INSERT INTO cion_uuid (appid, uuid) VALUES (?, ?)")
- .Bind(appid)
- .Bind(uuid);
- auto r = db.Exec(q);
- if (!static_cast<bool>(r))
- return false;
- return true;
-}
-
-void CionModule::GetUuidWithGenerate(const std::string& appid,
- std::optional<std::string>& uuid) {
- try {
- tizen_base::Database db(DBPATH, SQLITE_OPEN_READWRITE);
- std::string uuid_str;
- bool ret = true;
-
- if (!GetUuidFromDb(db, appid, uuid_str)) {
- uuid_str = GenUuid();
- ret = SetUuidToDb(db, appid, uuid_str);
- _E("get uuid generate");
- }
-
- if (ret)
- uuid = std::move(uuid_str);
- else
- uuid = std::nullopt;
- } catch(const std::runtime_error&) {
- uuid = std::nullopt;
- }
-}
-
-void CionModule::SetDisplayName(const std::string& appid,
- const std::string& service_name, const std::string& display_name,
- int& ret) {
- try {
- tizen_base::Database db(DBPATH, SQLITE_OPEN_READWRITE);
- std::string uuid;
-
- bool result;
- ret = -1;
- if (!GetUuidFromDb(db, appid, uuid)) {
- uuid = GenUuid();
- result = SetUuidToDb(db, appid, uuid);
- if (!result) {
- return;
- }
- }
-
- auto q = tizen_base::Database::Sql(
- "INSERT INTO cion_display_name(service_name, appid, display_name) "
- "VALUES (?, ?, ?) ON CONFLICT(service_name, appid) "
- "DO UPDATE SET display_name = ? "
- "WHERE service_name = ? AND appid = ? ")
- .Bind(service_name)
- .Bind(appid)
- .Bind(display_name)
- .Bind(display_name)
- .Bind(service_name)
- .Bind(appid);
- auto r = db.Exec(q);
- if (static_cast<bool>(r))
- ret = 0;
- } catch(const std::runtime_error&) {
- ret = -1;
- }
-}
-
-void CionModule::GetDisplayName(const std::string& appid,
- const std::string& service_name, std::string& display_name, int& ret) {
- try {
- tizen_base::Database db(DBPATH, SQLITE_OPEN_READWRITE);
-
- ret = -1;
- auto q = tizen_base::Database::Sql(
- "SELECT display_name FROM cion_display_name "
- "WHERE appid = ? AND service_name = ?")
- .Bind(appid)
- .Bind(service_name);
-
- auto r = db.Exec(q);
- if (!static_cast<bool>(r))
- return;
-
- for (const auto& i : r) {
- display_name = static_cast<std::string>(i.Get(0));
- ret = 0;
- break;
- }
- } catch(const std::runtime_error&) {
- ret = -1;
- }
-}
-
-void CionModule::SetEnabled(const std::string& appid,
- const std::string& service_name, bool enabled, int& ret) {
- try {
- tizen_base::Database db(DBPATH, SQLITE_OPEN_READWRITE);
-
- ret = -1;
- auto q = tizen_base::Database::Sql(
- "UPDATE cion_display_name SET enabled = ? "
- "WHERE appid = ? AND service_name = ?")
- .Bind(enabled? 1 : 0)
- .Bind(appid)
- .Bind(service_name);
-
- auto r = db.Exec(q);
- if (!static_cast<bool>(r))
- return;
-
- auto q2 = tizen_base::Database::Sql(
- "SELECT display_name FROM cion_display_name "
- "WHERE appid = ? AND service_name = ?")
- .Bind(appid)
- .Bind(service_name);
-
- auto r2 = db.Exec(q2);
- if (!static_cast<bool>(r2))
- return;
-
- for (const auto& i : r2) {
- auto display_name = static_cast<std::string>(i.Get(0));
- if (enabled)
- AddEnabledApp(service_name, appid, display_name);
- else
- RemoveEnabledApp(service_name, appid);
- ret = 0;
- break;
- }
- } catch(const std::runtime_error&) {
- ret = -1;
- }
-}
-
-void CionModule::GetEnabled(const std::string& appid,
- const std::string& service_name, bool& enabled, int& ret) {
- try {
- tizen_base::Database db(DBPATH, SQLITE_OPEN_READWRITE);
-
- ret = -1;
- auto q = tizen_base::Database::Sql(
- "SELECT enabled FROM cion_display_name "
- "WHERE appid = ? AND service_name = ?")
- .Bind(appid)
- .Bind(service_name);
-
- auto r = db.Exec(q);
- if (!static_cast<bool>(r))
- return;
-
- for (const auto& i : r) {
- enabled = static_cast<bool>(static_cast<int>(i.Get(0)));
- ret = 0;
- break;
- }
- } catch(const std::runtime_error&) {
- ret = -1;
- }
-}
-
-std::optional<std::list<CionServiceInfo>> CionModule::GetEnabledServiceList() {
- try {
- tizen_base::Database db(DBPATH, SQLITE_OPEN_READWRITE);
- auto q = tizen_base::Database::Sql(
- "SELECT service_name, appid, display_name "
- "FROM cion_display_name WHERE enabled = 1");
-
- auto r = db.Exec(q);
- if (!static_cast<bool>(r))
- return std::nullopt;
-
- std::list<CionServiceInfo> info_list;
- for (const auto& i : r) {
- auto [service_name, appid, display_name] = i.Get<_, _, _>();
- info_list.push_back(
- CionServiceInfo(static_cast<std::string>(service_name),
- static_cast<std::string>(appid),
- static_cast<std::string>(display_name)));
- }
-
- return info_list;
- } catch(const std::runtime_error&) {
- return std::nullopt;
- }
-}
-
-} //namespace esd::module
+++ /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 EVENTSYSTEM_MODULES_CION_CION_MODULE_HH_
-#define EVENTSYSTEM_MODULES_CION_CION_MODULE_HH_
-
-#include <list>
-#include <memory>
-#include <optional>
-#include <string>
-#include <imodule.hh>
-#include <database.hpp>
-
-#include "cion_ondemand_server.h"
-#include "cion_service_info.hh"
-
-namespace esd::module {
-
-class CionModule : public api::IModule {
- public:
- CionModule() = default;
- virtual ~CionModule() = default;
-
- bool Startup(api::ToolBox* tools) override;
- void Shutdown() override;
- std::optional<std::list<CionServiceInfo>> GetEnabledServiceList();
- void GetUuidWithGenerate(const std::string& appid,
- std::optional<std::string>& uuid);
-
- private:
- bool Init();
- bool DbInit();
- void AddEnabledApp(const std::string& service_name,
- const std::string& app_id, const std::string& display_name);
- void RemoveEnabledApp(const std::string& service_name,
- const std::string& app_id);
- void ChangeListenStatusCionServer();
- void SetDisplayName(const std::string& appid,
- const std::string& service_name,
- const std::string& display_name, int& ret);
- void GetDisplayName(const std::string& appid,
- const std::string& service_name,
- std::string& display_name, int& ret);
- void SetEnabled(const std::string& appid, const std::string& service_name,
- bool enabled, int& ret);
- void GetEnabled(const std::string& appid, const std::string& service_name,
- bool& enabled, int& ret);
- bool GetUuidFromDb(const tizen_base::Database& db,
- const std::string& appid, std::string& uuid);
- bool SetUuidToDb(const tizen_base::Database& db,
- const std::string& appid, const std::string& uuid);
- std::string GenUuid();
-
- private:
- std::shared_ptr<CionOndemandServer> esd_cion_server_;
- bool is_listening_ = false;
- api::ToolBox* tools_ = nullptr;
-};
-
-} // namespace esd::module
-
-#endif // EVENTSYSTEM_MODULES_CION_CION_MODULE_HH_
\ No newline at end of file
+++ /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 <glib.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <aul.h>
-#include <aul_svc.h>
-#include <bundle_cpp.h>
-#include <parcel.hh>
-#include <pkgmgr-info.h>
-#include <vconf.h>
-#include <system_info.h>
-#include <cion/common/data_payload.hh>
-
-#include <log.hh>
-#include "cion_ondemand_server.h"
-#include "cion_peer_info.h"
-#include "cion_module.hh"
-
-namespace {
-
-std::string GetAppVersion(const std::string& appid) {
- char *pkgid;
- char *pkg_version = NULL;
- pkgmgrinfo_appinfo_h appinfo = NULL;
-
- int retval = pkgmgrinfo_appinfo_get_usr_appinfo(appid.c_str(),
- getuid(), &appinfo);
- if (retval != PMINFO_R_OK)
- return {};
-
- retval = pkgmgrinfo_appinfo_get_pkgid(appinfo, &pkgid);
- if (retval != PMINFO_R_OK) {
- pkgmgrinfo_appinfo_destroy_appinfo(appinfo);
- return {};
- }
-
- pkgmgrinfo_pkginfo_h pkginfo = NULL;
- retval = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &pkginfo);
- if (retval != PMINFO_R_OK) {
- pkgmgrinfo_appinfo_destroy_appinfo(appinfo);
- return {};
- }
-
- retval = pkgmgrinfo_pkginfo_get_version(pkginfo, &pkg_version);
- if (retval != PMINFO_R_OK) {
- pkgmgrinfo_appinfo_destroy_appinfo(appinfo);
- pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
- return {};
- }
-
- std::string version(pkg_version);
- pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
- pkgmgrinfo_appinfo_destroy_appinfo(appinfo);
-
- return version;
-}
-
-std::string GetSystemInfoPlatformString(const char* key) {
- char* val = nullptr;
- int ret = system_info_get_platform_string(key, &val);
- if (ret != SYSTEM_INFO_ERROR_NONE || !val)
- return {};
-
- std::string val_str = val;
- free(val);
-
- return val_str;
-}
-
-std::string GetVconfString(const char* key) {
- char* val = vconf_get_str(key);
- if (val == nullptr)
- return {};
-
- std::string val_str = val;
- free(val);
-
- return val_str;
-}
-
-std::string device_id =
- GetSystemInfoPlatformString("http://tizen.org/system/tizenid");
-std::string device_name = GetVconfString(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
-std::string device_platform = "Tizen";
-std::string device_platform_version =
- GetSystemInfoPlatformString("http://tizen.org/feature/platform.version");
-std::string device_type =
- GetSystemInfoPlatformString("http://tizen.org/system/device_type");
-
-} // namespace
-
-CionOndemandServer::CionOndemandServer(std::string service_name,
- std::string display_name, esd::api::IModule* module)
- : cion::channel::ServerChannel(service_name, display_name),
- module_(module) {
- LoadOndemandServiceList();
-}
-
-CionOndemandServer::CionOndemandServer(std::string service_name,
- std::string display_name, cion::SecurityInfo security) :
- cion::channel::ServerChannel(service_name, display_name,
- std::move(security)) {
- LoadOndemandServiceList();
-}
-
-void CionOndemandServer::OnConnectionResult(
- std::shared_ptr<cion::PeerInfo> info,
- const cion::ConnectionResult& result) {
-}
-
-void CionOndemandServer::OnDisconnected(std::shared_ptr<cion::PeerInfo> peer) {
-}
-
-std::vector<char> CionOndemandServer::OnDataReceived(
- const std::vector<char>& data, std::shared_ptr<cion::PeerInfo> peer) {
- std::string return_data("returned");
-
- std::vector<char> v(return_data.begin(), return_data.end());
- return v;
-}
-
-void CionOndemandServer::OnPayloadReceived(
- std::shared_ptr<cion::IPayload> data,
- std::shared_ptr<cion::PeerInfo> peer,
- IPayloadReceiver::PayloadTransferStatus status) {
-}
-
-void CionOndemandServer::OnConnectionRequest(
- std::shared_ptr<cion::PeerInfo> peer) {
-}
-
-void CionOndemandServer::OnOndemandListRequested(
- std::shared_ptr<cion::IPayload> data,
- std::shared_ptr<cion::PeerInfo> peer) {
- std::vector<uint8_t> raw;
-
- _D("[Request Ondemand List]");
-
- if (data->GetType() == cion::IPayload::PayloadType::File)
- return;
-
- std::shared_ptr<cion::DataPayload> data_payload =
- std::dynamic_pointer_cast<cion::DataPayload>(data);
- std::vector<char> requested_data = data_payload->GetData();
- tizen_base::Parcel ondemand_parcel(requested_data.data(),
- requested_data.size());
-
- std::string list_header = ondemand_parcel.ReadString();
- std::string list_service_name = ondemand_parcel.ReadString();
- _D("Ondemand Service_name : %s", list_service_name.c_str());
- if (list_header == std::string("OndemandList")) {
- raw = GetOndemandList(list_service_name).ToRaw();
- if (raw.size() == 0)
- return;
- }
-
- auto dpl = std::make_unique<cion::DataPayload>();
- std::vector<char> listdata_vector(raw.begin(), raw.end());
- dpl->SetData(listdata_vector);
-
- SendPayloadAsync(dpl.get(), peer, [] (
- std::shared_ptr<cion::PayloadAsyncResult> result) {
- _I("result received !!! %s", result->GetPayloadID().c_str());
- });
-}
-
-int CionOndemandServer::OnOndemandLaunchRequested(
- std::shared_ptr<cion::IPayload> data,
- std::shared_ptr<cion::PeerInfo> peer) {
- //TODO check privilege app_id
- std::string app_id = peer->GetAppID();
- int ret = -20;
-
- cion::IPayload::PayloadType type = data->GetType();
- if (type == cion::IPayload::PayloadType::File)
- return ret;
-
- std::shared_ptr<cion::DataPayload> data_payload =
- std::dynamic_pointer_cast<cion::DataPayload>(data);
-
- std::vector<char> getdata = data_payload->GetData();
- std::string launch_requested(getdata.begin(), getdata.end());
-
- ret = OndemandLaunchApp(launch_requested);
- if (ret != 0) {
- _E("Faled to __esd_cion_launch_ondemand : %d", ret);
- }
-
- return ret;
-}
-
-int CionOndemandServer::OndemandLaunchApp(std::string appid) {
- uid_t uid = getuid();
- tizen_base::Bundle b;
- int ret = -20;
- bool found = false;
-
- for (std::shared_ptr<CionPeerInfo> cs : ondemand_peer_list_) {
- if (cs->GetAppID() == appid) {
- found = true;
- break;
- }
- }
-
- if (found == false) {
- _E("%s is not found", appid.c_str());
- return ret;
- }
-
- _D("cion launch ondemand: app_id(%s)", appid.c_str());
-
- if (!aul_app_is_running_for_uid(appid.c_str(), uid)) {
- aul_svc_set_operation(b.GetHandle(), AUL_SVC_OPERATION_DEFAULT);
- aul_svc_set_appid(b.GetHandle(), appid.c_str());
-
- ret = aul_svc_run_service_async_for_uid(b.GetHandle(), 0,
- nullptr, nullptr, uid);
- if (ret < 0)
- _E("Failed to launch app : %s", appid.c_str());
-
- } else {
- _D("already is running or launch failed");
- }
-
- return ret;
-}
-
-void CionOndemandServer::LoadOndemandServiceList() {
- auto* mod = static_cast<esd::module::CionModule*>(module_);
- auto ret = mod->GetEnabledServiceList();
-
- if (!ret)
- return;
-
- for (const auto& i : *ret) {
- std::optional<std::string> uuid;
- mod->GetUuidWithGenerate(i.GetAppId(), uuid);
- if (!uuid) {
- _E("Get uuid for %s", i.GetAppId().c_str());
- }
-
- std::string app_version = GetAppVersion(i.GetAppId());
- tizen_base::Parcel parcel;
- parcel.WriteString(device_id);
- parcel.WriteString(device_name);
- parcel.WriteString(device_platform);
- parcel.WriteString(device_platform_version);
- parcel.WriteString(device_type);
- parcel.WriteString(i.GetAppId());
- parcel.WriteString(app_version);
- parcel.WriteString(*uuid);
- parcel.WriteString(i.GetDisplayName());
-
- std::shared_ptr<CionPeerInfo> pi =
- std::make_shared<CionPeerInfo>(i.GetServiceName(),
- parcel.GetData(), parcel.GetDataSize());
- ondemand_peer_list_.emplace_back(pi);
- }
-}
-
-void CionOndemandServer::AddOndemandServiceList(std::string service_name,
- std::string appid, std::string display_name) {
- for (auto const& peer : ondemand_peer_list_) {
- if (peer->GetServiceName() == service_name &&
- peer->GetAppID() == appid) {
- _W("%s is already exist", appid.c_str());
- return;
- }
- }
-
- std::optional<std::string> uuid;
- auto* mod = static_cast<esd::module::CionModule*>(module_);
- mod->GetUuidWithGenerate(appid, uuid);
- if (!uuid) {
- _E("Get uuid for %s", appid.c_str());
- return;
- }
-
- std::string app_version = GetAppVersion(appid);
-
- tizen_base::Parcel parcel;
- parcel.WriteString(device_id);
- parcel.WriteString(device_name);
- parcel.WriteString(device_platform);
- parcel.WriteString(device_platform_version);
- parcel.WriteString(device_type);
- parcel.WriteString(appid);
- parcel.WriteString(app_version);
- parcel.WriteString(*uuid);
- parcel.WriteString(display_name);
-
- std::shared_ptr<CionPeerInfo> pi =
- std::make_shared<CionPeerInfo>(service_name, parcel.GetData(),
- parcel.GetDataSize());
- ondemand_peer_list_.emplace_back(pi);
-
- _D("[%s:%s] is added to list", appid.c_str(), service_name.c_str());
-}
-
-void CionOndemandServer::RemoveOndemandServiceList(std::string service_name,
- std::string appid) {
- for (auto peer = ondemand_peer_list_.begin();
- peer != ondemand_peer_list_.end(); peer++) {
- if (peer->get()->GetServiceName() == service_name &&
- peer->get()->GetAppID() == appid) {
- ondemand_peer_list_.erase(peer);
- _D("[%s:%s] is removed from list", appid.c_str(), service_name.c_str());
- break;
- }
- }
-}
-
-tizen_base::Parcel CionOndemandServer::GetOndemandList(
- std::string service_name) {
- if (ondemand_peer_list_.size() == 0) {
- _W("ondemand peer list is empty");
- return {};
- }
-
- std::string header("ODL:");
- tizen_base::Parcel parcel;
- parcel.WriteString(header);
-
- for (auto& peer : ondemand_peer_list_) {
- if (peer->GetServiceName() != service_name ||
- aul_app_is_running(peer->GetAppID().c_str()))
- continue;
-
- parcel.WriteBool(true);
- std::vector<uint8_t> peer_raw = peer->Serialize();
- parcel.WriteUInt32(peer_raw.size());
- parcel.Write(peer_raw.data(), peer_raw.size());
- }
-
- parcel.WriteBool(false);
-
- return parcel;
-}
+++ /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 EVENTSYSTEM_DAEMON_CION_ONDEMAND_SERVER_H_
-#define EVENTSYSTEM_DAEMON_CION_ONDEMAND_SERVER_H_
-
-#include <list>
-
-#include <cion/channel/server_channel.hh>
-#include <cion/common/ipayload.hh>
-#include <cion/common/exception.hh>
-#include <imodule.hh>
-
-#include "cion_peer_info.h"
-
-class CionOndemandServer : public cion::channel::ServerChannel {
- public:
- explicit CionOndemandServer(std::string service_name,
- std::string display_name, esd::api::IModule* module);
- explicit CionOndemandServer(std::string service_name,
- std::string display_name, cion::SecurityInfo security);
-
- void AddOndemandServiceList(std::string service_name, std::string appid,
- std::string display_name);
- void RemoveOndemandServiceList(std::string service_name, std::string appid);
-
- protected:
- void OnConnectionResult(std::shared_ptr<cion::PeerInfo> info,
- const cion::ConnectionResult& result) override;
- void OnDisconnected(std::shared_ptr<cion::PeerInfo> peer) override;
- std::vector<char> OnDataReceived(const std::vector<char>& data,
- std::shared_ptr<cion::PeerInfo> peer) override;
- void OnPayloadReceived(std::shared_ptr<cion::IPayload> data,
- std::shared_ptr<cion::PeerInfo> peer,
- IPayloadReceiver::PayloadTransferStatus status) override;
- void OnConnectionRequest(std::shared_ptr<cion::PeerInfo> peer) override;
- void OnOndemandListRequested(std::shared_ptr<cion::IPayload> data,
- std::shared_ptr<cion::PeerInfo> peer) override;
- int OnOndemandLaunchRequested(std::shared_ptr<cion::IPayload> data,
- std::shared_ptr<cion::PeerInfo> peer) override;
-
- int OndemandLaunchApp(std::string appid);
- void LoadOndemandServiceList();
- tizen_base::Parcel GetOndemandList(std::string service_name);
-
- private:
- std::list<std::shared_ptr<CionPeerInfo>> ondemand_peer_list_;
- esd::api::IModule* module_ = nullptr;
-};
-
-#endif /* EVENTSYSTEM_DAEMON_CION_ONDEMAND_SERVER_H_ */
+++ /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 "cion_peer_info.h"
-
-CionPeerInfo::CionPeerInfo(std::string service_name) : cion::PeerInfo(),
- service_name_(service_name) {
-}
-
-CionPeerInfo::CionPeerInfo(std::string service_name,
- const void* buf, uint32_t size) : cion::PeerInfo(buf, size),
- service_name_(service_name){
-
-}
-
-void CionPeerInfo::SetServiceName(std::string service_name) {
- service_name_ = service_name;
-}
-
-std::string CionPeerInfo::GetServiceName() const {
- return service_name_;
-}
\ No newline at end of file
+++ /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 EVENTSYSTEM_DAEMON_CION_PEER_INFO_H_
-#define EVENTSYSTEM_DAEMON_CION_PEER_INFO_H_
-
-#include <string>
-
-#include <cion/common/peer_info.hh>
-
-class CionPeerInfo : public cion::PeerInfo {
- public:
- CionPeerInfo(std::string service_name);
- CionPeerInfo(std::string service_name, const void* buf, uint32_t size);
-
- std::string GetServiceName() const;
- void SetServiceName(std::string service_name);
-
- private:
- std::string service_name_;
-};
-
-#endif /* EVENTSYSTEM_DAEMON_CION_PEER_INFO_H_ */
\ No newline at end of file
+++ /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 EVENTSYSTEM_MODULES_CION_CION_SERVICE_INFO_HH_
-#define EVENTSYSTEM_MODULES_CION_CION_SERVICE_INFO_HH_
-
-#include <memory>
-#include <string>
-
-#include <cion/common/peer_info.hh>
-
-class CionServiceInfo {
-public:
- CionServiceInfo(std::string service_name, std::string appid,
- std::string display_name) : service_name_(std::move(service_name)),
- appid_(std::move(appid)), display_name_(std::move(display_name)) {}
-
- const std::string& GetServiceName() const {
- return service_name_;
- }
-
- const std::string& GetAppId() const {
- return appid_;
- }
-
- const std::string& GetDisplayName() const {
- return display_name_;
- }
-
-private:
- std::string service_name_;
- std::string appid_;
- std::string display_name_;
-};
-
-#endif // EVENTSYSTEM_MODULES_CION_CION_SERVICE_INFO_HH_
\ No newline at end of file
+++ /dev/null
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} ESD_MOD_DBUS_EVENT_SRC)
-
-ADD_LIBRARY(${TARGET_ESD_MOD_DBUS_EVENT} ${ESD_MOD_DBUS_EVENT_SRC})
-
-TARGET_INCLUDE_DIRECTORIES(${TARGET_ESD_MOD_DBUS_EVENT} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}/../../lib)
-
-TARGET_LINK_LIBRARIES(${TARGET_ESD_MOD_DBUS_EVENT} PRIVATE ${TARGET_LIB_ESD})
-
-APPLY_PKG_CONFIG(${TARGET_ESD_MOD_DBUS_EVENT} PUBLIC
- AUL_DEPS
- DLOG_DEPS
- GIO_DEPS
- GLIB_DEPS
- VCONF_DEPS
- PKGMGR_INFO_DEPS
- SECURITY_MANAGER_DEPS
- CYNARA_CLIENT_DEPS
- CYNARA_CREDS_DBUS_DEPS
- CYNARA_SESSION_DEPS
- LIBTZPLATFORM_CONFIG_DEPS
- CERT_SVC_VCORE_DEPS
- CAPI_SYSTEM_INFO_DEPS
- PKGMGR_DEPS
- EVENTSYSTEM_DEPS
- APPSVC_DEPS
-)
-
-INSTALL(TARGETS ${TARGET_ESD_MOD_DBUS_EVENT} DESTINATION ${ESD_MODULES_DIR}/mod
- COMPONENT RuntimeLibraries)
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/eventsystem.conf DESTINATION /etc/dbus-1/system.d)
+++ /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 "certificate_matcher.hh"
-
-#include <bundle.h>
-#include <cert-svc/ccert.h>
-#include <cert-svc/cinstance.h>
-#include <eventsystem.h>
-#include <pkgmgr-info.h>
-
-#include <memory>
-
-#include "log.hh"
-
-namespace esd::module {
-
-int CertificateMatcher::Match(uid_t uid, const std::string& appid,
- uid_t from_uid, const std::string& from_appid) {
- _D("uid(%d), appid(%s), from_uid(%d), from_appid(%s)", uid, appid.c_str(),
- from_uid, from_appid.c_str());
-
- pkgmgrinfo_cert_compare_result_type_e res;
- int ret = pkgmgrinfo_pkginfo_compare_usr_app_cert_info(appid.c_str(),
- from_appid.c_str(), from_uid, &res);
- if (ret < 0) {
- _E("failed to check certificate");
- return ES_R_ERROR;
- }
-
- if (res != PMINFO_CERT_COMPARE_MATCH) {
- _D("certificat not match (%s)", appid.c_str());
- return ES_R_EINVAL;
- }
-
- return ES_R_OK;
-}
-
-bool CertificateMatcher::IsPlatformCert(const std::string& pkgid, uid_t uid) {
- _D("Checking if %s has a platform certification", pkgid.c_str());
-
- int r;
- const char *cert_value;
- pkgmgrinfo_certinfo_h certinfo;
- CertSvcInstance instance;
- CertSvcCertificate certificate;
- CertSvcVisibility visibility = CERTSVC_VISIBILITY_PUBLIC;
-
- r = pkgmgrinfo_pkginfo_create_certinfo(&certinfo);
- std::unique_ptr<std::remove_pointer<pkgmgrinfo_certinfo_h>::type,
- decltype(pkgmgrinfo_pkginfo_destroy_certinfo)*>
- certinfo_auto(certinfo, pkgmgrinfo_pkginfo_destroy_certinfo);
- if (r != PMINFO_R_OK) {
- _E("Failed to create certinfo");
- return false;
- }
-
- r = pkgmgrinfo_pkginfo_load_certinfo(pkgid.c_str(), certinfo, uid);
- if (r != PMINFO_R_OK) {
- _E("Failed to load certinfo");
- return false;
- }
-
- r = pkgmgrinfo_pkginfo_get_cert_value(certinfo,
- PMINFO_DISTRIBUTOR_ROOT_CERT, &cert_value);
- if (r != PMINFO_R_OK || cert_value == nullptr) {
- _E("Failed to get cert value");
- return false;
- }
-
- r = certsvc_instance_new(&instance);
- if (r != CERTSVC_SUCCESS) {
- _E("certsvc_instance_new() is failed.");
- return false;
- }
-
- r = certsvc_certificate_new_from_memory(instance,
- reinterpret_cast<const unsigned char*>(cert_value),
- strlen(cert_value),
- CERTSVC_FORM_DER_BASE64,
- &certificate);
- if (r != CERTSVC_SUCCESS) {
- _E("certsvc_certificate_new_from_memory() is failed.");
- certsvc_instance_free(instance);
- return false;
- }
-
- r = certsvc_certificate_get_visibility(certificate, &visibility);
- if (r != CERTSVC_SUCCESS)
- _E("certsvc_certificate_get_visibility() is failed.");
-
- certsvc_instance_free(instance);
- certsvc_certificate_free(certificate);
-
- _D("visibility is %d", visibility);
- if (visibility & CERTSVC_VISIBILITY_PLATFORM) {
- _D("%s has a platform certification", pkgid.c_str());
- return true;
- }
-
- return false;
-}
-
-} // namespace esd::module
+++ /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 EVENTSYSTEM_MODULES_DBUS_EVENT_CERTIFICATE_MATCHER_HH_
-#define EVENTSYSTEM_MODULES_DBUS_EVENT_CERTIFICATE_MATCHER_HH_
-
-#include <unistd.h>
-
-#include <string>
-
-namespace esd::module {
-
-class CertificateMatcher {
- public:
- static int Match(uid_t uid, const std::string& appid,
- uid_t from_uid, const std::string& from_appid);
- static bool IsPlatformCert(const std::string& pkgid, uid_t uid);
-};
-
-} // namespace esd::module
-
-#endif // EVENTSYSTEM_MODULES_DBUS_EVENT_CERTIFICATE_MATCHER_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 "dbus_event_module.hh"
-
-#undef EXPORT_API
-#define EXPORT_API __attribute__((visibility("default")))
-
-extern "C" EXPORT_API esd::api::IModule* ESD_GET_MODULE() {
- return new esd::module::DbusEventModule();
-}
\ No newline at end of file
+++ /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 "dbus_event_module.hh"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <glib.h>
-#include <aul.h>
-#include <aul_svc.h>
-#include <unistd.h>
-#include <ctype.h>
-#include <gio/gio.h>
-#include <pkgmgr-info.h>
-#include <appsvc/appsvc.h>
-#include <eventsystem.h>
-#include <bundle_internal.h>
-#include <fcntl.h>
-#include <vconf.h>
-#include <tzplatform_config.h>
-#include <bundle_cpp.h>
-
-#include <set>
-#include <tuple>
-#include <utility>
-
-#include "certificate_matcher.hh"
-#include "log.hh"
-
-namespace {
-
-#include "introspection_cb.hh"
-
-constexpr const char ESD_BOOT_COMPLETED[] = "/tmp/esd_ready";
-constexpr const char SYSTEMD_DBUS_DEST[] = "org.freedesktop.systemd1";
-constexpr const char SYSTEMD_DBUS_IFACE_MANAGER[] =
- "org.freedesktop.systemd1.Manager";
-constexpr const char SYSTEMD_DBUS_PATH[] = "/org/freedesktop/systemd1";
-constexpr const char SYSTEMD_DBUS_SIGNAL_STARTUP_FINISHED[] =
- "StartupFinished";
-constexpr const char SYSTEMD_DBUS_SIGNAL_USER_STARTUP_FINISHED[] =
- "UserSessionStartupFinished";
-
-const uid_t DEFAULT_USER = tzplatform_getuid(TZ_SYS_DEFAULT_USER);
-const uid_t GLOBAL_USER = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
-
-constexpr const char SYS_EVENT_NAME_PREFIX[] = "tizen.system.event";
-constexpr const char SYS_EVENT_OBJ_PATH[] = "/tizen/system/event";
-constexpr const char REQUEST_LAST_DATA[] = "request_last_data";
-
-const std::set<std::string_view> event_launch_support_list = {
- SYS_EVENT_BATTERY_CHARGER_STATUS,
- SYS_EVENT_USB_STATUS,
- SYS_EVENT_EARJACK_STATUS,
- SYS_EVENT_INCOMMING_MSG,
- SYS_EVENT_OUTGOING_MSG,
- SYS_EVENT_WIFI_STATE
-};
-
-std::map<std::string,
- std::tuple<std::string, int, uid_t>> trusted_busname_table;
-
-std::map<std::string,
- std::unique_ptr<esd::module::EventLaunch>> event_launch_table;
-
-struct AppCtrlData {
- AppCtrlData(std::string_view appid, std::string_view pkgid, uid_t uid)
- : appid_(appid), pkgid_(pkgid), uid_(uid) {
- }
-
- std::string_view appid_;
- std::string_view pkgid_;
- uid_t uid_;
-};
-
-int __esd_add_appinfo_handler(const pkgmgrinfo_appinfo_h handle, void *data);
-
-int __get_sender_unixinfo(GDBusConnection *conn, const char *sender_name,
- const char *type) {
- GDBusMessage *msg = nullptr;
- GDBusMessage *reply = nullptr;
- GError *err = nullptr;
- GVariant *body;
- int ret = -1;
- unsigned int value;
-
- msg = g_dbus_message_new_method_call(
- "org.freedesktop.DBus", "/org/freedesktop/DBus",
- "org.freedesktop.DBus", type);
- if (!msg) {
- _E("Can't allocate new method call");
- goto out;
- }
-
- g_dbus_message_set_body(msg, g_variant_new("(s)", sender_name));
- reply = g_dbus_connection_send_message_with_reply_sync(conn, msg,
- G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, nullptr, nullptr, &err);
-
- if (!reply) {
- if (err != nullptr) {
- _E("Failed to get info [%s]", err->message);
- g_error_free(err);
- }
- goto out;
- }
-
- body = g_dbus_message_get_body(reply);
- g_variant_get(body, "(u)", &value);
- ret = static_cast<int>(value);
-
-out:
- if (msg)
- g_object_unref(msg);
- if (reply)
- g_object_unref(reply);
-
- return ret;
-}
-
-int __get_sender_pid(GDBusConnection *conn, const char *sender_name) {
- int pid = 0;
-
- pid = __get_sender_unixinfo(conn, sender_name,
- "GetConnectionUnixProcessID");
- if (pid < 0) {
- _E("failed to get pid");
- pid = 0;
- }
-
- _D("sender_name(%s), pid(%d)", sender_name, pid);
-
- return pid;
-}
-
-int __get_sender_uid(GDBusConnection *conn, const char *sender_name) {
- int uid = -1;
-
- uid = __get_sender_unixinfo(conn, sender_name, "GetConnectionUnixUser");
- if (uid < 0)
- _E("failed to get uid");
-
- _D("sender_name(%s), uid(%d)", sender_name, uid);
-
- return uid;
-}
-
-bool __esd_check_application_validation(uid_t uid, const char *appid) {
- int ret = 0;
- pkgmgrinfo_appinfo_h handle;
-
- ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, uid, &handle);
- if (ret != PMINFO_R_OK)
- return false;
-
- pkgmgrinfo_appinfo_destroy_appinfo(handle);
-
- if (!aul_app_is_running_for_uid(appid, uid))
- return false;
-
- return true;
-}
-
-void __esd_trusted_busname_print_items() {
- for (const auto& i : trusted_busname_table) {
- auto [bus_name, pid, uid] = i.second;
- _D("uid(%d), appid(%s), pid(%d), busname(%s)", uid,
- i.first.c_str(), pid, bus_name.c_str());
- }
-}
-
-int __esd_trusted_busname_add_item(uid_t uid, const char *appid,
- const char *busname, int pid) {
- if (trusted_busname_table.find(appid) != trusted_busname_table.end()) {
- _D("already exist (%s, %s)", appid, busname);
- return ES_R_OK;
- }
-
- trusted_busname_table[appid] = std::make_tuple(busname, pid, uid);
- return ES_R_OK;
-}
-
-int __esd_check_trusted_events(GDBusConnection *conn, const char *list_name) {
- GVariant *result;
- GError *error = nullptr;
- GVariantIter *iter;
- gchar *str;
- char tmp_appid[128] = {0, };
- int pid = 0;
- int uid = 0;
- int ret = 0;
-
- result = g_dbus_connection_call_sync(conn,
- "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus",
- list_name, nullptr, G_VARIANT_TYPE("(as)"), G_DBUS_CALL_FLAGS_NONE,
- -1, nullptr, &error);
-
- if (result == nullptr) {
- _E("get (%s) error(%s)", list_name, error ? error->message : "");
- g_error_free(error);
- return ES_R_ERROR;
- }
-
- g_variant_get(result, "(as)", &iter);
- while (g_variant_iter_loop(iter, "s", &str)) {
- if (!strstr(reinterpret_cast<const char*>(str), "event.busname.session"))
- continue;
-
- _D("list(%s), name(%s)", list_name, str);
- pid = __get_sender_pid(conn, reinterpret_cast<const char*>(str));
- if (pid <= 0) {
- _E("failed to get pid(%d)", pid);
- continue;
- }
-
- uid = __get_sender_uid(conn, reinterpret_cast<const char*>(str));
- if (uid < 0) {
- _E("failed to get uid(%d)", uid);
- continue;
- }
- _D("uid(%d)", uid);
-
- memset(tmp_appid, 0, sizeof(tmp_appid));
- ret = aul_app_get_appid_bypid_for_uid(pid, tmp_appid, sizeof(tmp_appid),
- (uid_t)uid);
- if (ret != AUL_R_OK) {
- _E("failed to get appid by pid(%d)", pid);
- continue;
- }
-
- _D("appid(%s)", tmp_appid);
- if (__esd_check_application_validation((uid_t)uid, tmp_appid)) {
- _D("add to table");
- ret = __esd_trusted_busname_add_item((uid_t)uid, tmp_appid,
- reinterpret_cast<const char*>(str), pid);
- if (ret < 0)
- _E("failed to add item");
- }
- }
- g_variant_iter_free(iter);
- g_variant_unref(result);
-
- return ES_R_OK;
-}
-
-void __esd_launch_table_print_items() {
- for (auto& i : event_launch_table)
- i.second->Print(i.first);
-}
-
-int __esd_add_launch_item(uid_t uid, const char* event_name,
- const char* appid, const char* pkgid) {
- auto it = event_launch_table.find(event_name);
-
- if (it != event_launch_table.end()) {
- auto& el = (*it).second;
- el->GetAppListEventLaunch().push_back(esd::module::EsdListItem(
- pkgid, appid, uid));
- } else {
- _D("add new item (all)");
- auto el = std::make_unique<esd::module::EventLaunch>(pkgid, appid, uid);
- if (!el->Register(event_name)) {
- _E("signal subscription error, event_name(%s), app_id(%s)",
- event_name, appid);
- return ES_R_ERROR;
- }
-
- event_launch_table[event_name] = std::move(el);
- }
-
- return ES_R_OK;
-}
-
-int __esd_launch_table_remove_private_usr_items() {
- event_launch_table.clear();
- return ES_R_OK;
-}
-
-int __esd_launch_table_remove_items(uid_t uid, const char *pkg_id) {
- for (auto& i : event_launch_table) {
- if (uid != GLOBAL_USER && i.second->GetUid() == uid &&
- i.second->GetPackageName() == pkg_id) {
- event_launch_table.erase(i.first);
- break;
- }
- }
-
- return ES_R_OK;
-}
-
-void __esd_trusted_busname_remove_item(const char* bus_name) {
- for (auto it = trusted_busname_table.begin();
- it != trusted_busname_table.end();) {
- auto [bus_name_org, pid, uid] = (*it).second;
- if (bus_name_org == bus_name) {
- _D("remove trusted busname item(%s, %s)", (*it).first.c_str(),
- bus_name_org.c_str());
- it = trusted_busname_table.erase(it);
- __esd_trusted_busname_print_items();
- } else {
- ++it;
- }
- }
-}
-
-void __esd_filter_name_owner_changed(GDBusConnection *connection,
- const gchar *sender_name, const gchar *object_path,
- const gchar *interface_name, const gchar *signal_name,
- GVariant *parameters, gpointer user_data) {
- char *name = nullptr;
- char *old_owner = nullptr;
- char *new_owner = nullptr;
- int old_len = 0;
- int new_len = 0;
-
- g_variant_get(parameters, "(&s&s&s)", &name, &old_owner, &new_owner);
-
- if (strstr(name, "event.busname.session")) {
- old_len = strlen(old_owner);
- new_len = strlen(new_owner);
-
- _D("changed name(%s), old_onwer(%s)(%d) -> new_onwer(%s)(%d)",
- name, old_owner, old_len, new_owner, new_len);
-
- if (old_len > 0 && new_len == 0)
- __esd_trusted_busname_remove_item(name);
- else if (old_len == 0 && new_len > 0)
- _D("new name owned");
- else
- _E("not-expected name change");
- }
-}
-
-int __esd_dbus_name_monitor(GDBusConnection *connection) {
- guint name_owner_changed_id = 0;
-
- name_owner_changed_id = g_dbus_connection_signal_subscribe(connection,
- "org.freedesktop.DBus", "org.freedesktop.DBus",
- "NameOwnerChanged", "/org/freedesktop/DBus", nullptr,
- G_DBUS_SIGNAL_FLAGS_NONE,
- __esd_filter_name_owner_changed, nullptr, nullptr);
-
- _I("name_owner_changed_id(%d)", name_owner_changed_id);
-
- return ES_R_OK;
-}
-
-int __esd_get_user_items(uid_t uid) {
- int ret = 0;
- pkgmgrinfo_appinfo_filter_h handle = nullptr;
-
- _I("get user items for uid(%d)", uid);
- /* reset user's item */
- __esd_launch_table_remove_private_usr_items();
-
- ret = pkgmgrinfo_appinfo_filter_create(&handle);
- if (ret < 0) {
- _E("failed to create appinfo filter");
- return ES_R_ERROR;
- }
- ret = pkgmgrinfo_appinfo_filter_add_string(handle,
- PMINFO_APPINFO_PROP_APP_COMPONENT, "svcapp");
- if (ret < 0) {
- _E("failed to add appinfo filter string");
- pkgmgrinfo_appinfo_filter_destroy(handle);
- return ES_R_ERROR;
- }
- ret = pkgmgrinfo_appinfo_filter_add_string(handle,
- PMINFO_APPINFO_PROP_APP_OPERATION, APPSVC_OPERATION_LAUNCH_ON_EVENT);
- if (ret < 0) {
- _E("failed to add appinfo filter string");
- pkgmgrinfo_appinfo_filter_destroy(handle);
- return ES_R_ERROR;
- }
- ret = pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle,
- __esd_add_appinfo_handler, &uid, uid);
- if (ret < 0) {
- _E("appinfo filter foreach error");
- pkgmgrinfo_appinfo_filter_destroy(handle);
- return ES_R_ERROR;
- }
- pkgmgrinfo_appinfo_filter_destroy(handle);
-
- __esd_launch_table_print_items();
-
- return ES_R_OK;
-}
-
-void __esd_signal_handler(GDBusConnection *connection,
- const gchar *sender_name,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *signal_name,
- GVariant *parameters,
- gpointer user_data) {
- int handle;
- guint64 uid = 0;
-
- if (!g_strcmp0(signal_name,
- SYSTEMD_DBUS_SIGNAL_STARTUP_FINISHED)) {
- _I("System session finished");
-
- tizen_base::Bundle b;
- b.Add(EVT_KEY_BOOT_COMPLETED, EVT_VAL_BOOT_COMPLETED_TRUE);
- eventsystem_send_system_event(SYS_EVENT_BOOT_COMPLETED, b.GetHandle());
-
- handle = creat(ESD_BOOT_COMPLETED, 0640);
- if (handle != -1)
- close(handle);
- } else if (!g_strcmp0(signal_name,
- SYSTEMD_DBUS_SIGNAL_USER_STARTUP_FINISHED)) {
- g_variant_get(parameters, "(t)", &uid);
- _I("User session finished uid : %d", (int)uid);
- if ((uid_t)uid != DEFAULT_USER)
- __esd_get_user_items((uid_t)uid);
- }
-}
-
-static GDBusNodeInfo *introspection_data;
-
-int __esd_get_appid_by_pid_for_uid(int pid, uid_t uid, char *app_id,
- int buf_size) {
- int retval = ES_R_OK;
- int ret = 0;
-
- if (pid <= 0) {
- _E("invalid pid(%d)", pid);
- retval = ES_R_ERROR;
- } else if (uid <= 0) {
- _E("invalid uid(%d)", uid);
- retval = ES_R_ERROR;
- } else {
- ret = aul_app_get_appid_bypid_for_uid(pid, app_id, buf_size, (uid_t)uid);
- if (ret != AUL_R_OK) {
- _E("failed to get appid by pid");
- retval = ES_R_ERROR;
- }
- _D("pid(%d)-uid(%d)-appid(%s)", pid, uid, app_id);
- }
-
- return retval;
-}
-
-int __esd_get_appid_by_pid(int pid, char *app_id, int buf_size) {
- int ret;
- int fd;
- char buf[128] = { 0, };
-
- ret = aul_app_get_appid_bypid(pid, app_id, buf_size);
- if (ret != AUL_R_OK) {
- snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
-
- fd = open(buf, O_RDONLY);
- if (fd < 0)
- return ES_R_ERROR;
-
- ret = read(fd, app_id, buf_size - 1);
- close(fd);
-
- if (ret <= 0)
- return ES_R_ERROR;
-
- app_id[ret] = '\0';
- ret = ES_R_OK;
- }
-
- return ret;
-}
-
-static const GDBusInterfaceVTable interface_vtable = {
- esd::module::DbusEventModule::HandleMethodCallCb,
- nullptr,
- nullptr
-};
-
-void __esd_on_bus_acquired(GDBusConnection *connection,
- const gchar *name, gpointer user_data) {
- _I("bus acquired(%s)", name);
-
- guint reg_id = 0;
- guint boot_id = 0;
- guint user_boot_id = 0;
- GError *error = nullptr;
-
- reg_id = g_dbus_connection_register_object(connection,
- ESD_OBJECT_PATH,
- introspection_data->interfaces[0],
- &interface_vtable,
- user_data, nullptr, &error);
- if (reg_id == 0) {
- _E("g_dbus_connection_register_object error(%s)", error ? error->message : "");
- g_error_free(error);
- }
-
- boot_id = g_dbus_connection_signal_subscribe(connection,
- nullptr,
- SYSTEMD_DBUS_IFACE_MANAGER,
- SYSTEMD_DBUS_SIGNAL_STARTUP_FINISHED,
- SYSTEMD_DBUS_PATH,
- nullptr,
- G_DBUS_SIGNAL_FLAGS_NONE,
- __esd_signal_handler,
- nullptr,
- nullptr);
-
- if (boot_id == 0)
- _E("g_dbus_connection_signal_subscribe() is failed.");
-
- user_boot_id = g_dbus_connection_signal_subscribe(connection,
- nullptr,
- SYSTEMD_DBUS_IFACE_MANAGER,
- SYSTEMD_DBUS_SIGNAL_USER_STARTUP_FINISHED,
- SYSTEMD_DBUS_PATH,
- nullptr,
- G_DBUS_SIGNAL_FLAGS_NONE,
- __esd_signal_handler,
- nullptr,
- nullptr);
-
- if (user_boot_id == 0)
- _E("g_dbus_connection_signal_subscribe() is failed.");
-}
-
-void __esd_on_name_acquired(GDBusConnection *connection,
- const gchar *name, gpointer user_data) {
- tizen_base::Bundle b;
-
- __esd_check_trusted_events(connection, "ListNames");
- __esd_check_trusted_events(connection, "ListActivatableNames");
-
- b.Add(EVT_KEY_ESD_STATUS, EVT_VAL_ESD_STARTED);
- eventsystem_send_system_event(SYS_EVENT_ESD_STATUS, b.GetHandle());
-
- esd::module::DbusEventModule* mod =
- static_cast<esd::module::DbusEventModule*>(user_data);
- mod->SetVconfHandler();
-
- __esd_trusted_busname_print_items();
- __esd_get_user_items(DEFAULT_USER);
- __esd_dbus_name_monitor(connection);
-}
-
-void __esd_on_name_lost(GDBusConnection *connection,
- const gchar *name, gpointer user_data) {
-}
-
-int __esd_appcontrol_cb(const char* operation,
- const char* uri, const char* mime, void* data) {
- if (data == nullptr) {
- _E("invalid data");
- return 0;
- }
-
- AppCtrlData* cb_data = reinterpret_cast<AppCtrlData*>(data);
- std::string_view appid = cb_data->appid_;
- std::string_view pkgid = cb_data->pkgid_;
- std::string event_name;
- uid_t uid = cb_data->uid_;
-
- _D("uid(%d), appid(%s), pkgid(%s), operation(%s), uri(%s), mime(%s)",
- uid, appid.data(), pkgid.data(), operation, uri, mime);
-
- if (!strcmp(operation, APPSVC_OPERATION_LAUNCH_ON_EVENT)) {
- if (uri && !strncmp(uri, SYSTEM_EVENT_NAME_PREFIX,
- strlen(SYSTEM_EVENT_NAME_PREFIX))) {
- event_name = &uri[8];
- _D("appid(%s), event_name(%s)", appid.data(), event_name.c_str());
- if (event_launch_support_list.find(event_name) ==
- event_launch_support_list.end()) {
- _E("failed to add item (not support event)");
- } else if (!esd::module::PrivilegeChecker::AppHasPrivilege(
- uid, std::string(appid), event_name)) {
- _E("failed to add item (no privilege)");
- } else if (__esd_add_launch_item(uid, event_name.c_str(), appid.data(),
- pkgid.data())) {
- _E("failed to add item");
- }
- } else if (uri && !strncmp(uri, USER_EVENT_NAME_PREFIX,
- strlen(USER_EVENT_NAME_PREFIX))) {
- event_name = uri;
- _D("appid(%s), event_name(%s)", appid.data(), event_name.c_str());
- if (esd::module::CertificateMatcher::IsPlatformCert(std::string(pkgid),
- uid)) {
- if (__esd_add_launch_item(uid, event_name.c_str(), appid.data(),
- pkgid.data())) {
- _E("failed to add item");
- }
- }
- }
- }
-
- return 0;
-}
-
-int __esd_add_appinfo_handler(const pkgmgrinfo_appinfo_h handle, void *data) {
- if (data == nullptr) {
- _E("invalid data");
- return ES_R_ERROR;
- }
-
- char* appid = nullptr;
- char* pkgid = nullptr;
- uid_t* p_uid = reinterpret_cast<uid_t*>(data);
- int ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
- if (ret < 0) {
- _E("failed to get appid");
- return ES_R_ERROR;
- }
-
- ret = pkgmgrinfo_appinfo_get_appid(handle, &appid);
- if (ret < 0) {
- _E("failed to get appid");
- return ES_R_ERROR;
- }
-
- AppCtrlData cb_data(appid, pkgid, *p_uid);
- ret = pkgmgrinfo_appinfo_foreach_appcontrol(handle, __esd_appcontrol_cb,
- &cb_data);
-
- if (ret < 0) {
- _E("failed to get appcontrol info");
- return ES_R_ERROR;
- }
-
- return ES_R_OK;
-}
-
-} // namespace
-
-namespace esd::module {
-
-bool DbusEventModule::Startup(api::ToolBox* tools) {
- tools_ = tools;
- if (!Init())
- return false;
- return BeforeLoop();
-}
-
-void DbusEventModule::Shutdown() {
- Fini();
-}
-
-bool DbusEventModule::Init() {
- auto checker = std::make_unique<PrivilegeChecker>();
- pkgmgr_client_ = pkgmgr_client_new(PC_LISTENING);
- if (pkgmgr_client_ == nullptr) {
- _E("set pkgmgr client failed");
- return false;
- }
-
- int req_id = pkgmgr_client_listen_status(pkgmgr_client_,
- PkgmgrEventCb, this);
- if (req_id < 0) {
- _E("pkgmgr client listen failed");
- int ret = pkgmgr_client_free(pkgmgr_client_);
- pkgmgr_client_ = nullptr;
- if (ret != PKGMGR_R_OK)
- _E("pkgmgr_client_free failed(%d)", ret);
- return false;
- }
-
- checker_ = std::move(checker);
- _I("esd init done");
-
- return true;
-}
-
-void DbusEventModule::Fini() {
- _D("esd finalize");
-
- trusted_busname_table.clear();
- earlier_event_table_.clear();
- user_last_event_table_.clear();
- event_launch_table.clear();
-
- if (introspection_data)
- g_dbus_node_info_unref(introspection_data);
-
- if (pkgmgr_client_) {
- int ret = pkgmgr_client_free(pkgmgr_client_);
- pkgmgr_client_ = nullptr;
- if (ret != PKGMGR_R_OK)
- _E("pkgmgr_client_free failed(%d)", ret);
- }
-
- checker_->Reset();
- _D("esd finalize end");
-}
-
-bool DbusEventModule::BeforeLoop() {
- GError* error = nullptr;
- earlier_event_table_ = EarlierItem::CreateMap();
-
- event_launch_table.clear();
- introspection_data = g_dbus_node_info_new_for_xml(INTROSPECTION_XML, &error);
- if (!introspection_data) {
- _E("g_dbus_node_info_new_for_xml error(%s)", error ? error->message : "");
- g_error_free(error);
- return false;
- }
-
- guint owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
- ESD_BUS_NAME,
- G_BUS_NAME_OWNER_FLAGS_NONE,
- __esd_on_bus_acquired,
- __esd_on_name_acquired,
- __esd_on_name_lost,
- this, nullptr);
-
- if (!owner_id) {
- _E("g_bus_own_name error");
- g_dbus_node_info_unref(introspection_data);
- return false;
- }
-
- _I("esd before_loop done");
- return true;
-}
-
-void DbusEventModule::SetVconfHandler() {
- vconf_handler_ = std::make_unique<VconfEventHandler>();
- vconf_handler_->SetDefaultEvents();
-}
-
-void DbusEventModule::HandleMethodCallCb(GDBusConnection *connection,
- const gchar *sender, const gchar *object_path,
- const gchar *interface_name, const gchar *method_name,
- GVariant *parameters, GDBusMethodInvocation *invocation,
- gpointer user_data) {
- static std::map<std::string,
- std::function<void(DbusEventModule&, GDBusConnection*,
- const gchar*, GVariant*, GDBusMethodInvocation*)>> dispatcher = {
- { "CheckSenderValidation",
- &DbusEventModule::CheckSenderValidMethodCall },
- { "GetTrustedPeerList",
- &DbusEventModule::GetTrustedPeerMethodCall },
- { "SetupTrustedPeer",
- &DbusEventModule::SetupTrustedPeerMethodCall },
- { "CheckPrivilegeValidation",
- &DbusEventModule::CheckPrivilegeValidMethodCall },
- { "CheckUserSendValidation",
- &DbusEventModule::CheckSendEventValidMethodCall },
- { "GetEarlierData",
- &DbusEventModule::GetEarlierDataMethodCall },
- { "KeepLastData",
- &DbusEventModule::KeepLastDataMethodCall },
- { "CheckLastData",
- &DbusEventModule::CheckLastDataMethodCall },
- { "LaunchOnEventFromUserEvent",
- &DbusEventModule::LaunchOnEventFromUserEventMethodCall },
- { "CionGetUuid", &DbusEventModule::GetUuidMethodCall },
- { "CionSetDisplayName",
- &DbusEventModule::SetDisplayNameMethodCall },
- { "CionGetDisplayName",
- &DbusEventModule::GetDisplayNameMethodCall },
- { "CionSetEnabled", &DbusEventModule::SetEnabledMethodCall },
- { "CionGetEnabled", &DbusEventModule::GetEnabledMethodCall }
- };
-
- if (dispatcher.find(method_name) == dispatcher.end())
- return;
-
- auto* mod = reinterpret_cast<esd::module::DbusEventModule*>(user_data);
- dispatcher[method_name](*mod, connection, sender, parameters, invocation);
-}
-
-std::string DbusEventModule::GetSenderAppId(GDBusConnection* connection,
- const gchar* sender) {
- int sender_pid = __get_sender_pid(connection, sender);
- char app_id[128] = { 0, };
- if (__esd_get_appid_by_pid(sender_pid, app_id, sizeof(app_id)) < 0) {
- _E("failed to get appid by pid");
- return "";
- }
-
- return app_id;
-}
-
-void DbusEventModule::CheckSendEventValidMethodCall(
- GDBusConnection* connection, const gchar* sender, GVariant* parameters,
- GDBusMethodInvocation* invocation) {
- GVariant *param = nullptr;
- int result = 0;
- char *event_name = nullptr;
- char app_id[128] = {0, };
- int sender_pid = 0;
- uid_t sender_uid = 0;
-
- g_variant_get(parameters, "(&s)", &event_name);
- _D("event_name(%s)", event_name);
-
- sender_pid = __get_sender_pid(connection, sender);
- sender_uid = (uid_t)__get_sender_uid(connection, sender);
- if (__esd_get_appid_by_pid_for_uid(sender_pid, sender_uid, app_id,
- sizeof(app_id)) < 0) {
- result = ES_R_ERROR;
- } else {
- if (CheckUserEventSenderValid(event_name, app_id) < 0) {
- _E("invalid sender");
- result = ES_R_EINVAL;
- } else {
- result = 1;
- }
- }
-
- param = g_variant_new("(i)", result);
- _D("event_name(%s), result(%d)", event_name, result);
- g_dbus_method_invocation_return_value(invocation, param);
-}
-
-void DbusEventModule::CheckSenderValidMethodCall(GDBusConnection* connection,
- const gchar* sender, GVariant* parameters,
- GDBusMethodInvocation* invocation) {
- GVariant *param = nullptr;
- int result = 0;
- char *event_name = nullptr;
- char app_id[128] = {0, };
- int event_sender_pid = 0;
- uid_t sender_uid = 0;
-
- g_variant_get(parameters, "(i&s)", &event_sender_pid, &event_name);
- _D("event_sender_pid(%d), event_name(%s)", event_sender_pid, event_name);
-
- sender_uid = (uid_t)__get_sender_uid(connection, sender);
- if (__esd_get_appid_by_pid_for_uid(event_sender_pid, sender_uid, app_id,
- sizeof(app_id)) < 0) {
- result = ES_R_ERROR;
- } else {
- if (CheckUserEventSenderValid(event_name, app_id) < 0) {
- _E("invalid sender");
- result = ES_R_EINVAL;
- } else {
- result = 1;
- }
- }
-
- param = g_variant_new("(is)", result, app_id);
- _D("event_name(%s), result(%d)", event_name, result);
- g_dbus_method_invocation_return_value(invocation, param);
-}
-
-void DbusEventModule::GetTrustedPeerMethodCall(GDBusConnection* connection,
- const gchar* sender, GVariant* parameters,
- GDBusMethodInvocation* invocation) {
- GVariant *param = nullptr;
- int result = 0;
- GVariantBuilder *builder = nullptr;
- char *event_name = nullptr;
- char app_id[128] = {0, };
-
- g_variant_get(parameters, "(&s)", &event_name);
- _D("event_name(%s)", event_name);
-
- int sender_pid = __get_sender_pid(connection, sender);
- uid_t sender_uid = (uid_t)__get_sender_uid(connection, sender);
- if (__esd_get_appid_by_pid_for_uid(sender_pid, sender_uid, app_id,
- sizeof(app_id)) < 0) {
- result = ES_R_ERROR;
- } else {
- builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
-
- for (const auto& i : trusted_busname_table) {
- auto [busname, pid, uid] = i.second;
- if (uid != GLOBAL_USER && uid != sender_uid)
- continue;
-
- int ret = CertificateMatcher::Match(uid, i.first, sender_uid, app_id);
- if (ret == ES_R_OK)
- g_variant_builder_add(builder, "s", busname.c_str());
- }
-
- result = 1;
- }
-
- param = g_variant_new("(ias)", result, builder);
- _D("result(%d)", result);
- g_dbus_method_invocation_return_value(invocation, param);
- if (builder)
- g_variant_builder_unref(builder);
-}
-
-void DbusEventModule::SetupTrustedPeerMethodCall(GDBusConnection* connection,
- const gchar* sender, GVariant* parameters,
- GDBusMethodInvocation* invocation) {
- GVariant *param = nullptr;
- int result = 0;
- char *event_name = nullptr;
- char *destination_name = nullptr;
- char app_id[128] = {0, };
- int sender_pid = 0;
- uid_t sender_uid = 0;
- int ret = 0;
-
- g_variant_get(parameters, "(&s&s)", &event_name, &destination_name);
- _D("event_name(%s), destination_name(%s)", event_name, destination_name);
-
- if (destination_name && destination_name[0] != '\0') {
- sender_pid = __get_sender_pid(connection, sender);
- sender_uid = (uid_t)__get_sender_uid(connection, sender);
- if (__esd_get_appid_by_pid_for_uid(sender_pid, sender_uid, app_id,
- sizeof(app_id)) < 0) {
- result = ES_R_ERROR;
- } else {
- ret = __esd_trusted_busname_add_item(sender_uid, app_id,
- destination_name,
- sender_pid);
- if (ret < 0) {
- _E("failed to add trusted busname item");
- result = ES_R_ERROR;
- } else {
- result = 1;
- }
- }
- } else {
- _E("invalid destination name");
- result = ES_R_ERROR;
- }
-
- param = g_variant_new("(i)", result);
- _D("event_name(%s), result(%d)", event_name, result);
- g_dbus_method_invocation_return_value(invocation, param);
-}
-
-void DbusEventModule::CheckPrivilegeValidMethodCall(
- GDBusConnection* connection, const gchar* sender, GVariant* parameters,
- GDBusMethodInvocation* invocation) {
- GVariant *param = nullptr;
- int result = 1;
- char *event_name = nullptr;
- char app_id[128] = {0, };
- int sender_pid = 0;
- uid_t sender_uid = 0;
- std::string privilege_name;
-
- g_variant_get(parameters, "(&s)", &event_name);
- privilege_name = checker_->CheckPrivilegeName(std::string(event_name));
- _D("event_name(%s), privilege_name(%s)", event_name, privilege_name.c_str());
-
- if (!privilege_name.empty()) {
- sender_pid = __get_sender_pid(connection, sender);
- sender_uid = (uid_t)__get_sender_uid(connection, sender);
- if (__esd_get_appid_by_pid_for_uid(sender_pid, sender_uid, app_id,
- sizeof(app_id)) < 0) {
- result = ES_R_ERROR;
- } else {
- if (checker_->Check(connection, sender, sender_pid, privilege_name))
- result = 1;
- else
- result = ES_R_EINVAL;
- }
- }
-
- param = g_variant_new("(i)", result);
- _D("event_name(%s), result(%d)", event_name, result);
- g_dbus_method_invocation_return_value(invocation, param);
-}
-
-void DbusEventModule::GetEarlierDataMethodCall(GDBusConnection* connection,
- const gchar* sender, GVariant* parameters,
- GDBusMethodInvocation* invocation) {
- GVariant *param = nullptr;
- int result = ES_R_ERROR;
- char* event_name = nullptr;
- tizen_base::Bundle b;
-
- g_variant_get(parameters, "(&s)", &event_name);
- _D("event_name(%s)", event_name);
-
- auto it = earlier_event_table_.find(event_name);
- if (it != earlier_event_table_.end()) {
- b = (*it).second->GetData();
- b.Add("is_earlier_data", "true");
- result = ES_R_OK;
- }
-
- auto raw = b.ToRaw();
- param = g_variant_new("(iis)", result, raw.second, raw.first.get());
-
- _D("result(%d), len(%d)", result, raw.second);
- g_dbus_method_invocation_return_value(invocation, param);
-}
-
-void DbusEventModule::KeepLastDataMethodCall(GDBusConnection* connection,
- const gchar* sender, GVariant* parameters,
- GDBusMethodInvocation* invocation) {
- GVariant *param;
- int result = ES_R_OK;
- char* event_name;
- char* own_name;
- char app_id[128];
- int sender_pid;
- uid_t sender_uid;
-
- g_variant_get(parameters, "(&s&s)", &event_name, &own_name);
-
- if (!event_name || !own_name) {
- result = ES_R_ERROR;
- _E("invalid event_name and own_name");
- param = g_variant_new("(i)", result);
- g_dbus_method_invocation_return_value(invocation, param);
- return;
- }
-
- sender_pid = __get_sender_pid(connection, sender);
- sender_uid = (uid_t)__get_sender_uid(connection, sender);
- if (__esd_get_appid_by_pid_for_uid(sender_pid, sender_uid, app_id,
- sizeof(app_id)) < 0) {
- _E("failed to get appid by pid");
- result = ES_R_ERROR;
- param = g_variant_new("(i)", result);
- g_dbus_method_invocation_return_value(invocation, param);
- return;
- }
-
- std::string key(event_name);
- key += "_" + std::to_string(sender_uid);
- auto it = user_last_event_table_.find(key);
- if (it == user_last_event_table_.end()) {
- user_last_event_table_[key] = LastEventItem(app_id, event_name,
- own_name, sender_uid);
- } else {
- user_last_event_table_[key].SetOwnName(own_name);
- }
-
- param = g_variant_new("(i)", result);
- g_dbus_method_invocation_return_value(invocation, param);
-}
-
-void DbusEventModule::CheckLastDataMethodCall(GDBusConnection* connection,
- const gchar* sender, GVariant* parameters,
- GDBusMethodInvocation* invocation) {
- GVariant* param;
- int result = ES_R_OK;
- char* event_name;
- char* own_name;
- char app_id[128];
- int sender_pid;
- uid_t sender_uid;
-
- g_variant_get(parameters, "(&s&s)", &event_name, &own_name);
-
- if (!event_name || !own_name) {
- result = ES_R_ERROR;
- _E("invalid event_name and own_name");
- param = g_variant_new("(i)", result);
- g_dbus_method_invocation_return_value(invocation, param);
- return;
- }
-
- sender_pid = __get_sender_pid(connection, sender);
- sender_uid = (uid_t)__get_sender_uid(connection, sender);
- if (__esd_get_appid_by_pid_for_uid(sender_pid, sender_uid, app_id,
- sizeof(app_id)) < 0) {
- result = ES_R_ERROR;
- _E("failed to get appid by pid");
- param = g_variant_new("(i)", result);
- g_dbus_method_invocation_return_value(invocation, param);
- return;
- }
-
- std::string key(event_name);
- key += "_" + std::to_string(sender_uid);
- auto it = user_last_event_table_.find(key);
- if (it != user_last_event_table_.end()) {
- GVariant *gv;
- tizen_base::Bundle b;
- int ret;
- GError *error = nullptr;
-
- b.Add(EVT_KEY_KEPT_EVENT_NAME, event_name);
- b.Add(EVT_KEY_KEPT_OWN_NAME, own_name);
- if (CertificateMatcher::Match((*it).second.GetUid(),
- (*it).second.GetAppId(), sender_uid, app_id) == ES_R_OK)
- b.Add(EVT_KEY_KEPT_IS_TRUSTED, "true");
- else
- b.Add(EVT_KEY_KEPT_IS_TRUSTED, "false");
-
- auto raw = b.ToRaw();
- gv = g_variant_new("(us)", raw.second, raw.first.get());
- ret = g_dbus_connection_emit_signal(connection,
- (*it).second.GetOwnName().c_str(),
- SYS_EVENT_OBJ_PATH,
- SYS_EVENT_NAME_PREFIX,
- REQUEST_LAST_DATA,
- gv,
- &error);
- if (ret == FALSE) {
- _E("Unable to emit signal: %s", error ? error->message : "");
- g_error_free(error);
- }
- }
-
- param = g_variant_new("(i)", result);
- g_dbus_method_invocation_return_value(invocation, param);
-}
-
-void DbusEventModule::LaunchOnEventFromUserEventMethodCall(
- GDBusConnection* connection, const gchar* sender, GVariant* parameters,
- GDBusMethodInvocation* invocation) {
- GVariant *param;
- int result = ES_R_OK;
- int len;
- gboolean trusted;
- int sender_pid;
- uid_t sender_uid;
- char *event_name;
- char app_id[128];
- char *buf;
-
- g_variant_get(parameters, "(&s&sib)", &event_name, &buf, &len, &trusted);
-
- if (!event_name) {
- result = ES_R_ERROR;
- _E("invalid event_name");
- param = g_variant_new("(i)", result);
- g_dbus_method_invocation_return_value(invocation, param);
- return;
- }
-
- sender_pid = __get_sender_pid(connection, sender);
- sender_uid = (uid_t)__get_sender_uid(connection, sender);
- if (__esd_get_appid_by_pid_for_uid(sender_pid, sender_uid, app_id,
- sizeof(app_id)) < 0) {
- _E("failed to get appid by pid");
- result = ES_R_ERROR;
- param = g_variant_new("(i)", result);
- g_dbus_method_invocation_return_value(invocation, param);
- return;
- }
-
- tizen_base::Bundle b(buf);
- auto it = event_launch_table.find(event_name);
- if (it != event_launch_table.end()) {
- (*it).second->Notify(event_name, b, true, static_cast<bool>(trusted),
- sender_uid, app_id);
- }
-
- param = g_variant_new("(i)", result);
- g_dbus_method_invocation_return_value(invocation, param);
-}
-
-void DbusEventModule::GetUuidMethodCall(GDBusConnection* connection,
- const gchar* sender, GVariant* parameters,
- GDBusMethodInvocation* invocation) {
- GVariant* param = nullptr;
- int result = ES_R_OK;
- std::optional<std::string> uuid;
-
- std::string app_id = GetSenderAppId(connection, sender);
- if (app_id.empty()) {
- param = g_variant_new("(is)", ES_R_ERROR, "");
- g_dbus_method_invocation_return_value(invocation, param);
- return;
- }
-
- if (tools_->GetMethodBroker()
- .Invoke<const std::string&, std::optional<std::string>&>(
- "Cion.GetUuidWithGenerate", app_id, uuid)) {
- param = g_variant_new("(is)", ES_R_OK, (*uuid).c_str());
- } else {
- result = ES_R_ERROR;
- }
-
- if (param == nullptr)
- param = g_variant_new("(is)", result, "");
-
- g_dbus_method_invocation_return_value(invocation, param);
-}
-
-void DbusEventModule::SetDisplayNameMethodCall(GDBusConnection* connection,
- const gchar* sender, GVariant* parameters,
- GDBusMethodInvocation* invocation) {
- GVariant* param = nullptr;
- int result = ES_R_OK;
- char* display_name = nullptr;
- char* service_name = nullptr;
- int ret = 0;
-
- std::string app_id = GetSenderAppId(connection, sender);
- if (app_id.empty()) {
- param = g_variant_new("(i)", ES_R_ERROR);
- g_dbus_method_invocation_return_value(invocation, param);
- return;
- }
-
- g_variant_get(parameters, "(&s&s)", &service_name, &display_name);
-
- if (!tools_->GetMethodBroker()
- .Invoke<const std::string&, const std::string&, const std::string&,
- int&>("Cion.SetDisplayName", app_id, service_name, display_name,
- ret)) {
- result = ES_R_ERROR;
- }
-
- if (ret != 0)
- result = ES_R_ERROR;
-
- param = g_variant_new("(i)", result);
- g_dbus_method_invocation_return_value(invocation, param);
-}
-
-void DbusEventModule::GetDisplayNameMethodCall(GDBusConnection* connection,
- const gchar* sender, GVariant* parameters,
- GDBusMethodInvocation* invocation) {
- GVariant* param = nullptr;
- int result = ES_R_OK;
- char* service_name = nullptr;
- std::string display_name;
- int ret = -1;
-
- std::string app_id = GetSenderAppId(connection, sender);
- if (app_id.empty()) {
- param = g_variant_new("(is)", ES_R_ERROR, "");
- g_dbus_method_invocation_return_value(invocation, param);
- return;
- }
-
- g_variant_get(parameters, "(&s)", &service_name);
-
- if (tools_->GetMethodBroker()
- .Invoke<const std::string&, const std::string&, std::string&, int&>(
- "Cion.GetDisplayName", app_id, service_name, display_name,
- ret)) {
- if (ret == 0)
- param = g_variant_new("(is)", result, display_name);
- } else {
- result = ES_R_ERROR;
- }
-
- if (param == nullptr)
- param = g_variant_new("(is)", result, "");
-
- g_dbus_method_invocation_return_value(invocation, param);
-}
-
-void DbusEventModule::SetEnabledMethodCall(GDBusConnection* connection,
- const gchar* sender, GVariant* parameters,
- GDBusMethodInvocation* invocation) {
- GVariant* param = nullptr;
- int result = ES_R_OK;
- gboolean enabled;
- char* service_name = nullptr;
- int ret = -1;
-
- std::string app_id = GetSenderAppId(connection, sender);
- if (app_id.empty()) {
- param = g_variant_new("(i)", ES_R_ERROR);
- g_dbus_method_invocation_return_value(invocation, param);
- return;
- }
-
- g_variant_get(parameters, "(&sb)", &service_name, &enabled);
-
- if (!tools_->GetMethodBroker()
- .Invoke<const std::string&, const std::string&, bool, int&>(
- "Cion.SetEnabled", app_id, service_name, static_cast<bool>(enabled),
- ret)) {
- result = ES_R_ERROR;
- }
-
- if (ret != 0)
- result = ES_R_ERROR;
-
- param = g_variant_new("(i)", result);
- g_dbus_method_invocation_return_value(invocation, param);
-}
-
-void DbusEventModule::GetEnabledMethodCall(GDBusConnection* connection,
- const gchar* sender, GVariant* parameters,
- GDBusMethodInvocation* invocation) {
- GVariant* param = nullptr;
- int result = ES_R_OK;
- char* service_name = nullptr;
- bool enabled = false;
- int ret = -1;
-
- std::string app_id = GetSenderAppId(connection, sender);
- if (app_id.empty()) {
- param = g_variant_new("(ib)", ES_R_ERROR, false);
- g_dbus_method_invocation_return_value(invocation, param);
- return;
- }
-
- g_variant_get(parameters, "(&s)", &service_name);
- if (!tools_->GetMethodBroker()
- .Invoke<const std::string&, const std::string&, bool&, int&>(
- "Cion.GetEnabled", app_id, service_name, enabled, ret)) {
- result = ES_R_ERROR;
- } else if (ret != 0) {
- result = ES_R_ERROR;
- } else {
- param = g_variant_new("(ib)", result, enabled);
- }
-
- if (param == nullptr)
- param = g_variant_new("(ib)", result, false);
-
- g_dbus_method_invocation_return_value(invocation, param);
-}
-
-int DbusEventModule::PkgmgrEventCb(uid_t target_uid, int req_id,
- const char *pkg_type, const char *pkgid, const char *key,
- const char *val, const void *pmsg, void *data) {
- DbusEventModule* obj = reinterpret_cast<DbusEventModule*>(data);
- pkgmgrinfo_pkginfo_h handle = nullptr;
- int ret = 0;
-
- _D("target_uid(%d), req_id(%d), pkg_type(%s), pkgid(%s), key(%s), val(%s)",
- target_uid, req_id, pkg_type, pkgid, key, val);
-
- if (strcmp(key, "start") == 0) {
- if (strcmp(val, "install") == 0) {
- _D("install start");
- obj->pkg_event_type_ = INSTALL;
- } else if (strcmp(val, "uninstall") == 0) {
- _D("unistall start");
- obj->pkg_event_type_ = UNINSTALL;
- } else if (strcmp(val, "update") == 0) {
- _D("update start");
- obj->pkg_event_type_ = UPDATE;
- } else {
- _D("val(%s) start", val);
- }
- } else if (strcmp(key, "end") == 0 && strcmp(val, "ok") == 0) {
- if (obj->pkg_event_type_ == INSTALL || obj->pkg_event_type_ == UPDATE) {
- _D("install end (ok)");
- ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, target_uid, &handle);
- if (ret < 0) {
- _E("failed to get pkginfo");
- return 0;
- }
-
- ret = pkgmgrinfo_appinfo_get_usr_list(handle,
- PMINFO_SVC_APP, __esd_add_appinfo_handler, &target_uid, target_uid);
- if (ret < 0) {
- _E("failed to get appinfo");
- pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
- return 0;
- }
-
- ret = pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
- if (ret < 0) {
- _E("failed to destroy pkginfo");
- return 0;
- }
- } else if (obj->pkg_event_type_ == UNINSTALL) {
- _D("uninstall end (ok)");
- __esd_launch_table_remove_items(target_uid, pkgid);
- __esd_launch_table_print_items();
- }
- } else if (strcmp(key, "end") == 0 && strcmp(val, "fail") == 0) {
- _E("pkg_event(%d) falied", obj->pkg_event_type_);
- }
-
- return 0;
-}
-
-int DbusEventModule::CheckUserEventSenderValid(std::string_view event_name,
- std::string_view app_id) {
- auto it = event_name.rfind('.');
-
- if (it == std::string::npos) {
- _E("invalid event name");
- return ES_R_EINVAL;
- }
-
- event_name = event_name.substr(0, it);
- auto len = event_name.length();
- if (len <= 1 || len > 128) {
- _E("invalid length(%zu) of user-defined name", len);
- return ES_R_EINVAL;
- }
-
- _D("app_id(%s), len(%zu)", app_id.data(), app_id.length());
-
- std::string valid_name = USER_EVENT_NAME_PREFIX + std::string(app_id);
- _D("valid_name(%s)", valid_name.c_str());
-
- if (valid_name != event_name) {
- _E("appid misamatch");
- return ES_R_EINVAL;
- }
-
- return ES_R_OK;
-}
-
-} // namespace esd::module
+++ /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 EVENTSYSTEM_MODULES_DBUS_EVENT_DBUS_EVENT_MODULE_HH_
-#define EVENTSYSTEM_MODULES_DBUS_EVENT_DBUS_EVENT_MODULE_HH_
-
-#include <glib.h>
-#include <gio/gio.h>
-#include <package-manager.h>
-
-#include <map>
-#include <memory>
-#include <string>
-#include <string_view>
-
-#include "earlier_item.hh"
-#include "event_launch.hh"
-#include <imodule.hh>
-#include "last_event_item.hh"
-#include "vconf_event_handler.hh"
-#include "privilege_checker.hh"
-#include <optional>
-
-namespace esd::module {
-
-class DbusEventModule : public api::IModule {
- public:
- DbusEventModule() = default;
- virtual ~DbusEventModule() = default;
-
- bool Startup(api::ToolBox* tools) override;
- void Shutdown() override;
-
- void SetVconfHandler();
-
- static void HandleMethodCallCb(GDBusConnection *connection,
- const gchar *sender, const gchar *object_path,
- const gchar *interface_name, const gchar *method_name,
- GVariant *parameters, GDBusMethodInvocation *invocation,
- gpointer user_data);
-
- private:
- enum PkgEventType {
- UNKNOWN = 0,
- INSTALL,
- UNINSTALL,
- UPDATE,
- };
-
- bool Init();
- void Fini();
- bool BeforeLoop();
- void GetUuidMethodCall(GDBusConnection* connection, const gchar* sender,
- GVariant* parameters, GDBusMethodInvocation* invocation);
- void SetDisplayNameMethodCall(GDBusConnection* connection,
- const gchar* sender, GVariant* parameters,
- GDBusMethodInvocation* invocation);
- void GetDisplayNameMethodCall(GDBusConnection* connection,
- const gchar* sender, GVariant* parameters,
- GDBusMethodInvocation* invocation);
- void SetEnabledMethodCall(GDBusConnection* connection,
- const gchar* sender, GVariant* parameters,
- GDBusMethodInvocation* invocation);
- void GetEnabledMethodCall(GDBusConnection* connection,
- const gchar* sender, GVariant* parameters,
- GDBusMethodInvocation* invocation);
- void CheckSenderValidMethodCall(GDBusConnection* connection,
- const gchar* sender, GVariant* parameters,
- GDBusMethodInvocation* invocation);
- void GetTrustedPeerMethodCall(GDBusConnection* connection,
- const gchar* sender, GVariant* parameters,
- GDBusMethodInvocation* invocation);
- void SetupTrustedPeerMethodCall(GDBusConnection* connection,
- const gchar* sender, GVariant* parameters,
- GDBusMethodInvocation* invocation);
- void CheckPrivilegeValidMethodCall(GDBusConnection* connection,
- const gchar* sender, GVariant* parameters,
- GDBusMethodInvocation* invocation);
- void GetEarlierDataMethodCall(GDBusConnection* connection,
- const gchar* sender, GVariant* parameters,
- GDBusMethodInvocation* invocation);
- void KeepLastDataMethodCall(GDBusConnection* connection,
- const gchar* sender, GVariant* parameters,
- GDBusMethodInvocation* invocation);
- void CheckLastDataMethodCall(GDBusConnection* connection,
- const gchar* sender, GVariant* parameters,
- GDBusMethodInvocation* invocation);
- void LaunchOnEventFromUserEventMethodCall(GDBusConnection* connection,
- const gchar* sender, GVariant* parameters,
- GDBusMethodInvocation* invocation);
- void CheckSendEventValidMethodCall(GDBusConnection* connection,
- const gchar* sender, GVariant* parameters,
- GDBusMethodInvocation* invocation);
- std::string GetSenderAppId(GDBusConnection* connection, const gchar* sender);
- int CheckUserEventSenderValid(std::string_view event_name,
- std::string_view app_id);
-
- static int PkgmgrEventCb(uid_t target_uid, int req_id, const char* pkg_type,
- const char* pkgid, const char* key, const char* val, const void* pmsg,
- void* data);
-
- private:
- api::ToolBox* tools_ = nullptr;
- std::unique_ptr<VconfEventHandler> vconf_handler_;
- std::unique_ptr<PrivilegeChecker> checker_;
- std::map<std::string, std::unique_ptr<EarlierItem>> earlier_event_table_;
- std::map<std::string, LastEventItem> user_last_event_table_;
- pkgmgr_client* pkgmgr_client_ = nullptr;
- std::string pkg_event_pkgid_;
- int pkg_event_type_;
-};
-
-} // namespace esd::module
-
-#endif // EVENTSYSTEM_MODULES_DBUS_EVENT_DBUS_EVENT_MODULE_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 "earlier_item.hh"
-
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <eventsystem.h>
-#include <vconf.h>
-
-#include <set>
-
-#include "log.hh"
-
-namespace {
-
-constexpr const char ESD_BOOT_COMPLETED[] = "/tmp/esd_ready";
-
-const std::set<std::string_view> earlier_event_list = {
- SYS_EVENT_ESD_STATUS,
- SYS_EVENT_LOW_MEMORY,
- SYS_EVENT_BOOT_COMPLETED,
- SYS_EVENT_SYSTEM_SHUTDOWN,
- SYS_EVENT_BATTERY_CHARGER_STATUS
-};
-
-} // namespace
-
-namespace esd::module {
-
-EarlierItem::EarlierItem(tizen_base::Bundle data)
- : data_(std::move(data)) {
-}
-
-EarlierItem::~EarlierItem() {
- if (reg_id_)
- eventsystem_unregister_event(reg_id_);
-}
-
-bool EarlierItem::Register(std::string_view event_name) {
- if (eventsystem_register_event(event_name.data(), ®_id_,
- EsdEventHandlerCb, this) != 0) {
- return false;
- }
-
- return true;
-}
-
-const tizen_base::Bundle& EarlierItem::GetData() const {
- return data_;
-}
-
-void EarlierItem::OnEvent(const char* event_name, bundle* data) {
- _D("event_name(%s)", event_name);
- data_ = tizen_base::Bundle(data);
-}
-
-void EarlierItem::EsdEventHandlerCb(const char* event_name, bundle* data,
- void* user_data) {
- _D("event_name(%s)", event_name);
- EarlierItem* ei = reinterpret_cast<EarlierItem*>(user_data);
- if (earlier_event_list.find(event_name) != earlier_event_list.end())
- ei->OnEvent(event_name, data);
-}
-
-std::map<std::string, std::unique_ptr<EarlierItem>> EarlierItem::CreateMap() {
- int fd;
- int ret;
- std::map<std::string, std::unique_ptr<EarlierItem>> events;
- int val;
- int status;
- int charger_status;
- int charge_now;
-
- _I("register events for earlier_data");
- for (const auto& event_name : earlier_event_list) {
- _I("event_name(%s)", event_name.data());
-
- tizen_base::Bundle b;
- if (event_name == SYS_EVENT_BOOT_COMPLETED) {
- fd = open(ESD_BOOT_COMPLETED, O_RDONLY);
- if (fd < 0) {
- _D("open file error(%d)", fd);
- } else {
- b.Add(EVT_KEY_BOOT_COMPLETED, EVT_VAL_BOOT_COMPLETED_TRUE);
- close(fd);
- }
- } else if (event_name == SYS_EVENT_SYSTEM_SHUTDOWN) {
- ret = vconf_get_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, &val);
- if (ret != VCONF_OK) {
- _E("failed to get power_off status (%d)", ret);
- } else {
- if (val == VCONFKEY_SYSMAN_POWER_OFF_DIRECT ||
- val == VCONFKEY_SYSMAN_POWER_OFF_RESTART) {
- b.Add(EVT_KEY_SYSTEM_SHUTDOWN, EVT_VAL_SYSTEM_SHUTDOWN_TRUE);
- }
- }
- } else if (event_name == SYS_EVENT_LOW_MEMORY) {
- ret = vconf_get_int(VCONFKEY_SYSMAN_LOW_MEMORY, &status);
- if (ret != VCONF_OK) {
- _E("failed to get low_memory status (%d)", ret);
- } else {
- if (status == VCONFKEY_SYSMAN_LOW_MEMORY_SOFT_WARNING)
- b.Add(EVT_KEY_LOW_MEMORY, EVT_VAL_MEMORY_SOFT_WARNING);
- else if (status == VCONFKEY_SYSMAN_LOW_MEMORY_HARD_WARNING)
- b.Add(EVT_KEY_LOW_MEMORY, EVT_VAL_MEMORY_HARD_WARNING);
- else
- b.Add(EVT_KEY_LOW_MEMORY, EVT_VAL_MEMORY_NORMAL);
- }
- } else if (event_name == SYS_EVENT_BATTERY_CHARGER_STATUS) {
- ret = vconf_get_int(VCONFKEY_SYSMAN_CHARGER_STATUS, &charger_status);
- if (ret != VCONF_OK) {
- _E("failed to get charger_status (%d)", ret);
- } else {
- ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, &charge_now);
- if (ret != VCONF_OK)
- _E("failed to get charge_now (%d)", ret);
- }
-
- if (ret == VCONF_OK) {
- if (charger_status == VCONFKEY_SYSMAN_CHARGER_CONNECTED) {
- if (charge_now == 0) {
- b.Add(EVT_KEY_BATTERY_CHARGER_STATUS,
- EVT_VAL_BATTERY_CHARGER_DISCHARGING);
- } else {
- b.Add(EVT_KEY_BATTERY_CHARGER_STATUS,
- EVT_VAL_BATTERY_CHARGER_CHARGING);
- }
- } else {
- b.Add(EVT_KEY_BATTERY_CHARGER_STATUS,
- EVT_VAL_BATTERY_CHARGER_DISCONNECTED);
- }
- }
- }
-
- auto ei = std::make_unique<EarlierItem>(std::move(b));
- if (!ei->Register(event_name)) {
- _E("signal subscription error, event_name(%s)", event_name.data());
- continue;
- }
-
- events[std::string(event_name)] = std::move(ei);
- }
-
- return events;
-}
-
-} // namespace esd::module
+++ /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 EVENTSYSTEM_MODULES_DBUS_EVENT_EARLIER_ITEM_HH_
-#define EVENTSYSTEM_MODULES_DBUS_EVENT_EARLIER_ITEM_HH_
-
-#include <bundle_cpp.h>
-#include <glib.h>
-
-#include <list>
-#include <map>
-#include <memory>
-#include <tuple>
-#include <string_view>
-#include <utility>
-
-namespace esd::module {
-
-class EarlierItem {
- public:
- EarlierItem() = default;
- explicit EarlierItem(tizen_base::Bundle data);
- EarlierItem(const EarlierItem&) = delete;
- EarlierItem& operator = (const EarlierItem&) = delete;
- ~EarlierItem();
-
- bool Register(std::string_view event_name);
- const tizen_base::Bundle& GetData() const;
-
- static std::map<std::string, std::unique_ptr<EarlierItem>> CreateMap();
-
- private:
- void OnEvent(const char* event_name, bundle* data);
- static void EsdEventHandlerCb(const char* event_name, bundle* data,
- void* user_data);
-
- private:
- guint reg_id_ = 0;
- tizen_base::Bundle data_;
-};
-
-} // namespace esd::module
-
-#endif // EVENTSYSTEM_MODULES_DBUS_EVENT_EARLIER_ITEM_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 "esd_list_item.hh"
-
-#include "log.hh"
-
-namespace esd::module {
-
-EsdListItem::EsdListItem(std::string pkg_id, std::string app_id, uid_t uid)
- : pkg_id_(std::move(pkg_id)), app_id_(std::move(app_id)), uid_(uid) {
-}
-
-void EsdListItem::Print(const std::string& event_name) {
- _D("event_name(%s)-uid(%d)-app_id(%s)-pkg_id(%s)",
- event_name.c_str(), uid_, app_id_.c_str(), pkg_id_.c_str());
-}
-
-const std::string& EsdListItem::GetAppId() const {
- return app_id_;
-}
-
-int EsdListItem::GetTrustedInfo() const {
- return trusted_info_;
-}
-
-void EsdListItem::SetTrustedInfo(int info) {
- trusted_info_ = info;
-}
-
-uid_t EsdListItem::GetUid() const {
- return uid_;
-}
-
-} // namespace esd::module
+++ /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 EVENTSYSTEM_MODULES_DBUS_EVENT_ESD_LIST_ITEM_HH_
-#define EVENTSYSTEM_MODULES_DBUS_EVENT_ESD_LIST_ITEM_HH_
-
-#include <bundle_cpp.h>
-
-#include <list>
-#include <map>
-#include <tuple>
-#include <string>
-#include <utility>
-
-namespace esd::module {
-
-class EsdListItem {
- public:
- enum TrustedResult {
- TRUSTED_UNKNOWN,
- TRUSTED_ALLOWED,
- TRUSTED_DENIED,
- };
-
- EsdListItem() = default;
- EsdListItem(std::string pkg_id, std::string app_id, uid_t uid);
-
- void Print(const std::string& event_name);
- const std::string& GetAppId() const;
- int GetTrustedInfo() const;
- void SetTrustedInfo(int info);
- uid_t GetUid() const;
-
- private:
- std::string pkg_id_;
- std::string app_id_;
- int trusted_info_ = TRUSTED_UNKNOWN;
- uid_t uid_ = 0;
-};
-
-} // namespace esd::module
-
-#endif // EVENTSYSTEM_MODULES_DBUS_EVENT_ESD_LIST_ITEM_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 "event_launch.hh"
-
-#include <appsvc/appsvc.h>
-#include <aul.h>
-#include <aul_svc.h>
-#include <bundle_internal.h>
-#include <eventsystem.h>
-
-#include <set>
-
-#include "certificate_matcher.hh"
-#include "log.hh"
-
-namespace {
-
-constexpr const int ROOT_USER = 0;
-
-const std::set<std::string_view> event_launch_support_list = {
- SYS_EVENT_BATTERY_CHARGER_STATUS,
- SYS_EVENT_USB_STATUS,
- SYS_EVENT_EARJACK_STATUS,
- SYS_EVENT_INCOMMING_MSG,
- SYS_EVENT_OUTGOING_MSG,
- SYS_EVENT_WIFI_STATE
-};
-
-} // namespace
-
-namespace esd::module {
-
-EventLaunch::EventLaunch(std::string pkgid, std::string appid, uid_t uid)
- : package_name_(std::move(pkgid)),
- uid_(uid) {
- app_list_evtlaunch_.push_back(EsdListItem(package_name_, std::move(appid),
- uid));
-}
-
-EventLaunch::~EventLaunch() {
- if (reg_id_)
- eventsystem_unregister_event(reg_id_);
-}
-
-bool EventLaunch::Register(std::string_view event_name) {
- if (eventsystem_register_event(event_name.data(), ®_id_,
- EsdEventHandlerCb, this) != 0) {
- return false;
- }
-
- return true;
-}
-
-void EventLaunch::Print(const std::string& event_name) {
- for (auto& i : app_list_evtlaunch_)
- i.Print(event_name);
-}
-
-uid_t EventLaunch::GetUid() const {
- return uid_;
-}
-
-const std::string& EventLaunch::GetPackageName() const {
- return package_name_;
-}
-
-std::list<EsdListItem>& EventLaunch::GetAppListEventLaunch() {
- return app_list_evtlaunch_;
-}
-
-void EventLaunch::EsdEventHandlerCb(const char* event_name, bundle* data,
- void* user_data) {
- _D("event_name(%s)", event_name);
- EventLaunch* el = reinterpret_cast<EventLaunch*>(user_data);
- if (event_launch_support_list.find(event_name) !=
- event_launch_support_list.end()) {
- el->OnEvent(event_name, tizen_base::Bundle(data, false, false), false,
- true, ROOT_USER, "");
- }
-}
-
-bool EventLaunch::CheckEvent(std::string_view event_name,
- const tizen_base::Bundle& data) {
- if (event_name == SYS_EVENT_BATTERY_CHARGER_STATUS) {
- auto val = data.GetString(EVT_KEY_BATTERY_CHARGER_STATUS);
- _D("charger val(%s)", val.c_str());
- if (val != EVT_VAL_BATTERY_CHARGER_CONNECTED)
- return false;
- } else if (event_name == SYS_EVENT_USB_STATUS) {
- auto val = data.GetString(EVT_KEY_USB_STATUS);
- _D("usb val(%s)", val.c_str());
- if (val != EVT_VAL_USB_CONNECTED)
- return false;
- } else if (event_name == SYS_EVENT_EARJACK_STATUS) {
- auto val = data.GetString(EVT_KEY_EARJACK_STATUS);
- _D("earjack val(%s)", val.c_str());
- if (val != EVT_VAL_EARJACK_CONNECTED)
- return false;
- } else if (event_name == SYS_EVENT_INCOMMING_MSG) {
- auto msg_type = data.GetString(EVT_KEY_MSG_TYPE);
- _D("msg_type(%s)", msg_type.c_str());
- if (msg_type.empty())
- return false;
- auto msg_id = data.GetString(EVT_KEY_MSG_ID);
- _D("msg_id(%s)", msg_id.c_str());
- if (msg_id.empty())
- return false;
- } else if (event_name == SYS_EVENT_OUTGOING_MSG) {
- auto msg_type = data.GetString(EVT_KEY_OUT_MSG_TYPE);
- _D("msg_type(%s)", msg_type.c_str());
- if (msg_type.empty())
- return false;
- auto msg_id = data.GetString(EVT_KEY_OUT_MSG_ID);
- _D("msg_id(%s)", msg_id.c_str());
- if (msg_id.empty())
- return false;
- } else if (event_name == SYS_EVENT_WIFI_STATE) {
- auto val = data.GetString(EVT_KEY_WIFI_STATE);
- if (val.empty())
- return false;
- _D("wifi_state(%s)", val.c_str());
- if (val != EVT_VAL_WIFI_CONNECTED)
- return false;
- }
-
- return true;
-}
-
-void EventLaunch::Notify(std::string_view event_name,
- const tizen_base::Bundle& data, bool is_user_event, bool trusted,
- uid_t sender_uid, std::string_view sender_appid) {
- OnEvent(event_name, data, is_user_event, trusted, sender_uid, sender_appid);
-}
-
-void EventLaunch::OnEvent(std::string_view event_name,
- const tizen_base::Bundle& data, bool is_user_event, bool trusted,
- uid_t sender_uid, std::string_view sender_appid) {
- _D("event_name(%s)", event_name.data());
-
- if (app_list_evtlaunch_.empty())
- return;
-
- if (!is_user_event && !CheckEvent(event_name, data))
- return;
-
- static int req_id;
- for (auto& i : app_list_evtlaunch_) {
- _D("launch_on_event: app_id(%s), event_name(%s), uid(%d), is_user(%d),"
- " trusted(%d)",
- i.GetAppId().c_str(), event_name.data(), i.GetUid(),
- is_user_event, trusted);
-
- if (is_user_event && trusted) {
- if (i.GetTrustedInfo() == EsdListItem::TRUSTED_UNKNOWN) {
- int ret = CertificateMatcher::Match(i.GetUid(),
- i.GetAppId(), sender_uid, sender_appid.data());
- if (ret == ES_R_EINVAL) {
- i.SetTrustedInfo(EsdListItem::TRUSTED_DENIED);
- continue;
- } else if (ret == ES_R_ERROR) {
- continue;
- } else {
- i.SetTrustedInfo(EsdListItem::TRUSTED_ALLOWED);
- }
- } else if (i.GetTrustedInfo() == EsdListItem::TRUSTED_DENIED) {
- continue;
- }
- }
-
- if (aul_app_is_running_for_uid(i.GetAppId().c_str(), i.GetUid())) {
- _D("already is running or launch failed");
- continue;
- }
-
- tizen_base::Bundle b(data);
- std::string event_uri;
- if (is_user_event) {
- event_uri = USER_EVENT_NAME_PREFIX + std::string(event_name);
- } else {
- event_uri = SYSTEM_EVENT_NAME_PREFIX + std::string(event_name);
- }
-
- appsvc_set_operation(b.GetHandle(), APPSVC_OPERATION_LAUNCH_ON_EVENT);
- appsvc_set_uri(b.GetHandle(), event_uri.c_str());
- appsvc_set_appid(b.GetHandle(), i.GetAppId().c_str());
-
- int pid = aul_svc_run_service_async_for_uid(b.GetHandle(), req_id++,
- nullptr, nullptr, i.GetUid());
- _D("uid(%d), pid(%d)", i.GetUid(), pid);
- }
-}
-
-} // namespace esd::module
+++ /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 EVENTSYSTEM_MODULES_DBUS_EVENT_EVENT_LAUNCH_HH_
-#define EVENTSYSTEM_MODULES_DBUS_EVENT_EVENT_LAUNCH_HH_
-
-#include <bundle_cpp.h>
-#include <glib.h>
-
-#include <list>
-#include <map>
-#include <tuple>
-#include <string>
-#include <string_view>
-#include <utility>
-
-#include "esd_list_item.hh"
-
-namespace esd::module {
-
-class EventLaunch {
- public:
- EventLaunch() = default;
- EventLaunch(std::string pkgid, std::string appid, uid_t uid);
- EventLaunch(const EventLaunch&) = delete;
- EventLaunch& operator = (const EventLaunch&) = delete;
- ~EventLaunch();
-
- bool Register(std::string_view event_name);
- void Print(const std::string& event_name);
- uid_t GetUid() const;
- const std::string& GetPackageName() const;
- std::list<EsdListItem>& GetAppListEventLaunch();
- void Notify(std::string_view event_name, const tizen_base::Bundle& data,
- bool is_user_event, bool trusted, uid_t sender_uid,
- std::string_view sender_appid);
-
- private:
- bool CheckEvent(std::string_view event_name, const tizen_base::Bundle& data);
- void OnEvent(std::string_view event_name, const tizen_base::Bundle& data,
- bool is_user_event, bool trusted, uid_t sender_uid,
- std::string_view sender_appid);
-
- static void EsdEventHandlerCb(const char* event_name, bundle* data,
- void* user_data);
-
- private:
- std::string package_name_;
- std::list<EsdListItem> app_list_evtlaunch_;
- guint reg_id_ = 0;
- uid_t uid_ = 0;
-};
-
-} // namespace esd::module
-
-#endif // EVENTSYSTEM_MODULES_DBUS_EVENT_EVENT_LAUNCH_HH_
+++ /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="tizen.system.event.app2esd" />
- <deny send_destination="tizen.system.event.app2esd" />
- <deny own_prefix="event.busname.system" />
- <deny own_prefix="event.busname.session" />
- <deny send_interface="tizen.system.event" send_type="signal" />
- <allow send_destination="tizen.system.event.app2esd" send_interface="tizen.system.event.app2esd" send_type="method_call" />
- </policy>
- <policy user="root">
- <allow own="tizen.system.event.app2esd" />
- <allow own_prefix="event.busname.system" />
- <allow own_prefix="event.busname.session" />
- <allow send_interface="tizen.system.event" send_type="signal" />
- <allow send_destination="tizen.system.event.app2esd" send_type="signal"/>
- </policy>
- <policy user="app_fw">
- <allow own="tizen.system.event.app2esd" />
- <allow own_prefix="event.busname.system" />
- <allow own_prefix="event.busname.session" />
- <allow send_interface="tizen.system.event" send_type="signal" />
- <allow send_destination="tizen.system.event.app2esd" send_type="signal" />
- </policy>
- <policy group="system_share">
- <allow own_prefix="event.busname.system" />
- <allow send_interface="tizen.system.event" send_type="signal" />
- </policy>
- <policy group="users">
- <allow own_prefix="event.busname.system" />
- <allow own_prefix="event.busname.session" />
- <check send_destination="tizen.system.event.app2esd" send_type="signal" privilege="http://tizen.org/privilege/internal/default/platform"/>
- </policy>
-</busconfig>
+++ /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.
-*/
-
-constexpr const char INTROSPECTION_XML[] = R"__esd(
-<node>
- <interface name='tizen.system.event.app2esd'>
- <method name='CheckSenderValidation'>
- <arg type='i' name='senderpid' direction='in'/>
- <arg type='s' name='eventname' direction='in'/>
- <arg type='i' name='ret' direction='out'/>
- <arg type='s' name='senderid' direction='out'/>
- </method>
- <method name='GetTrustedPeerList'>
- <arg type='s' name='eventname' direction='in'/>
- <arg type='i' name='ret' direction='out'/>
- <arg type='as' name='dest_list' direction='out'/>
- </method>
- <method name='SetupTrustedPeer'>
- <arg type='s' name='eventname' direction='in'/>
- <arg type='s' name='destination' direction='in'/>
- <arg type='i' name='ret' direction='out'/>
- </method>
- <method name='CheckPrivilegeValidation'>
- <arg type='s' name='eventname' direction='in'/>
- <arg type='i' name='ret' direction='out'/>
- </method>
- <method name='CheckUserSendValidation'>
- <arg type='s' name='eventname' direction='in'/>
- <arg type='i' name='ret' direction='out'/>
- </method>
- <method name='RequestTrustedEventLaunch'>
- <arg type='s' name='eventname' direction='in'/>
- <arg type='s' name='eventdata' direction='in'/>
- <arg type='i' name='datalen' direction='in'/>
- <arg type='i' name='ret' direction='out'/>
- </method>
- <method name='RequestEventLaunch'>
- <arg type='s' name='eventname' direction='in'/>
- <arg type='s' name='eventdata' direction='in'/>
- <arg type='i' name='datalen' direction='in'/>
- <arg type='i' name='ret' direction='out'/>
- </method>
- <method name='RequestSendingEvent'>
- <arg type='s' name='eventname' direction='in'/>
- <arg type='s' name='eventdata' direction='in'/>
- <arg type='i' name='datalen' direction='in'/>
- <arg type='i' name='ret' direction='out'/>
- </method>
- <method name='GetEarlierData'>
- <arg type='s' name='appid' direction='in'/>
- <arg type='i' name='ret' direction='out'/>
- <arg type='i' name='len' direction='out'/>
- <arg type='s' name='earlier_data' direction='out'/>
- </method>
- <method name='KeepLastData'>
- <arg type='s' name='eventname' direction='in'/>
- <arg type='s' name='own_name' direction='in'/>
- <arg type='i' name='ret' direction='out'/>
- </method>
- <method name='CheckLastData'>
- <arg type='s' name='eventname' direction='in'/>
- <arg type='s' name='own_name' direction='in'/>
- <arg type='i' name='ret' direction='out'/>
- </method>
- <method name='LaunchOnEventFromUserEvent'>
- <arg type='s' name='eventname' direction='in'/>
- <arg type='s' name='eventdata' direction='in'/>
- <arg type='i' name='datalen' direction='in'/>
- <arg type='b' name='trusted' direction='in'/>
- <arg type='i' name='ret' direction='out'/>
- </method>
- <method name='CionGetUuid'>
- <arg type='i' name='ret' direction='out'/>
- <arg type='s' name='uuid' direction='out'/>
- </method>
- <method name='CionSetDisplayName'>
- <arg type='s' name='service_name' direction='in'/>
- <arg type='s' name='display_name' direction='in'/>
- <arg type='i' name='ret' direction='out'/>
- </method>
- <method name='CionGetDisplayName'>
- <arg type='s' name='service_name' direction='in'/>
- <arg type='i' name='ret' direction='out'/>
- <arg type='s' name='display_name' direction='out'/>
- </method>
- <method name='CionSetEnabled'>
- <arg type='s' name='service_name' direction='in'/>
- <arg type='b' name='enabled' direction='in'/>
- <arg type='i' name='ret' direction='out'/>
- </method>
- <method name='CionGetEnabled'>
- <arg type='s' name='service_name' direction='in'/>
- <arg type='i' name='ret' direction='out'/>
- <arg type='b' name='enabled' direction='out'/>
- </method>
- </interface>
-</node>
-)__esd";
+++ /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 EVENTSYSTEM_MODULES_DBUS_EVENT_LAST_EVENT_ITEM_HH_
-#define EVENTSYSTEM_MODULES_DBUS_EVENT_LAST_EVENT_ITEM_HH_
-
-#include <string>
-#include <utility>
-
-namespace esd::module {
-
-class LastEventItem {
- public:
- LastEventItem() = default;
- LastEventItem(std::string app_id, std::string event_name,
- std::string own_name, uid_t uid)
- : app_id_(std::move(app_id)), event_name_(std::move(event_name)),
- own_name_(std::move(own_name)), uid_(uid) {
- }
-
- const std::string& GetAppId() const {
- return app_id_;
- }
-
- const std::string& GetEventName() const {
- return event_name_;
- }
-
- const std::string& GetOwnName() const {
- return own_name_;
- }
-
- uid_t GetUid() const {
- return uid_;
- }
-
- void SetOwnName(std::string own_name) {
- own_name_ = std::move(own_name);
- }
-
- private:
- std::string app_id_;
- std::string event_name_;
- std::string own_name_;
- uid_t uid_;
-};
-
-} // namespace esd::module
-
-#endif // EVENTSYSTEM_MODULES_DBUS_EVENT_LAST_EVENT_ITEM_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 "privilege_checker.hh"
-
-#include <cynara-client.h>
-#include <cynara-creds-gdbus.h>
-#include <cynara-session.h>
-#include <eventsystem_internal.h>
-#include <security-manager.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include <fstream>
-#include <string>
-#include <iostream>
-#include <map>
-
-#include <log.hh>
-
-namespace {
-
-const std::map<std::string, std::string> kPrivilegeInfoMap = {
- {std::string(SYS_EVENT_DISPLAY_STATE), std::string("http://tizen.org/privilege/display")},
- {std::string(SYS_EVENT_WIFI_STATE), std::string("http://tizen.org/privilege/network.get")},
- {std::string(SYS_EVENT_INCOMMING_MSG), std::string("http://tizen.org/privilege/message.read")},
- {std::string(SYS_EVENT_OUTGOING_MSG), std::string("http://tizen.org/privilege/message.read")},
- {std::string(RESERVED_NAME_FOR_SYSTEM_PKGMGRSIGNAL), // This is for pkgmgr-server signal
- std::string("http://tizen.org/privilege/packagemanager.info")},
-};
-
-} // namespace
-
-namespace esd::module {
-
-PrivilegeChecker::PrivilegeChecker() : cynara_(nullptr, cynara_finish) {
- cynara* _cynara = nullptr;
- int ret = cynara_initialize(&_cynara, nullptr);
- if (ret != CYNARA_API_SUCCESS)
- _E("init cynara failed: %d", ret);
- else
- cynara_.reset(_cynara);
-}
-
-PrivilegeChecker::~PrivilegeChecker() = default;
-
-bool PrivilegeChecker::Check(GDBusConnection* connection,
- const gchar* sender, int sender_pid, std::string privilege) {
- char *client = nullptr;
- char *session = nullptr;
- char *user = nullptr;
- bool allowed = false;
-
- if (!cynara_.get())
- return allowed;
-
- int ret = cynara_creds_gdbus_get_client(connection, sender,
- CLIENT_METHOD_DEFAULT, &client);
- if (ret != CYNARA_API_SUCCESS) {
- _E("failed to get client");
- return allowed;
- }
- std::unique_ptr<char, decltype(g_free)*> client_auto(client, g_free);
-
- ret = cynara_creds_gdbus_get_user(connection, sender, USER_METHOD_DEFAULT,
- &user);
- if (ret != CYNARA_API_SUCCESS) {
- _E("failed to get user");
- return allowed;
- }
- std::unique_ptr<char, decltype(g_free)*> user_auto(user, g_free);
-
- session = cynara_session_from_pid(sender_pid);
- if (session == NULL) {
- _E("failed to get session");
- return allowed;
- }
- std::unique_ptr<char, decltype(g_free)*> session_auto(session, g_free);
-
- ret = cynara_check(cynara_.get(), client, session, user, privilege.c_str());
- if (ret == CYNARA_API_ACCESS_ALLOWED)
- allowed = true;
- else
- _E("cynara access check(%s) failed: %d", privilege.c_str(), ret);
-
- return allowed;
-}
-
-void PrivilegeChecker::Reset() {
- cynara_.reset();
-}
-
-bool PrivilegeChecker::AppHasPrivilege(uid_t uid, std::string appid,
- std::string event_name) {
- int ret = 0;
- int result = 0;
-
- _D("event_name(%s), uid(%d), appid(%s)", event_name.c_str(), uid, appid.c_str());
-
- std::string privilege_name = CheckPrivilegeName(event_name);
- if (!privilege_name.empty()) {
- ret = security_manager_app_has_privilege(appid.c_str(), privilege_name.c_str(),
- uid, &result);
- if (ret != SECURITY_MANAGER_SUCCESS)
- _E("failed to check privilege(%d)", ret);
- _D("result(%d)", result);
- } else {
- result = 1;
- }
-
- return result;
-}
-
-std::string PrivilegeChecker::CheckPrivilegeName(std::string event_name) {
- const auto& it = kPrivilegeInfoMap.find(event_name);
- if (it == kPrivilegeInfoMap.end())
- return "";
- else
- return std::string(it->second);
-}
-
-} // namespace esd::module
\ No newline at end of file
+++ /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 EVENTSYSTEM_MODULES_DBUS_EVENT_PRIVILEGE_CHECKER_HH_
-#define EVENTSYSTEM_MODULES_DBUS_EVENT_PRIVILEGE_CHECKER_HH_
-
-#include <gio/gio.h>
-#include <cynara-client.h>
-
-#include <string>
-#include <memory>
-
-namespace esd::module {
-
-class PrivilegeChecker {
- public:
- PrivilegeChecker();
- PrivilegeChecker(const PrivilegeChecker&) = delete;
- PrivilegeChecker& operator=(const PrivilegeChecker&) = delete;
- ~PrivilegeChecker();
- bool Check(GDBusConnection* connection,
- const gchar* sender, int sender_pid, std::string privilege);
- void Reset();
-
- static bool AppHasPrivilege(uid_t uid, std::string appid, std::string event_name);
- static std::string CheckPrivilegeName(std::string event_name);
-
- private:
- std::unique_ptr<cynara, decltype(cynara_finish)*> cynara_;
-};
-
-} // namespace esd::module
-
-#endif // EVENTSYSTEM_MODULES_DBUS_EVENT_PRIVILEGE_CHECKER_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 "vconf_event_handler.hh"
-
-#include <memory>
-#include <log.hh>
-#include <eventsystem.h>
-
-namespace esd::module {
-
-void VconfEventHandler::LocationUseMyLocationCb(keynode_t *node, void *user_data) {
- int ret = 0;
- int enabled = 0;
- bundle *b = NULL;
- const char *key = NULL;
- const char *val = NULL;
-
- _D("vconfcb called");
-
- ret = vconf_get_int(VCONFKEY_LOCATION_USE_MY_LOCATION, &enabled);
- if (ret != VCONF_OK) {
- _E("failed to get vconf (%d)", ret);
- return;
- }
-
- key = EVT_KEY_LOCATION_ENABLE_STATE;
-
- if (enabled)
- val = EVT_VAL_LOCATION_ENABLED;
- else
- val = EVT_VAL_LOCATION_DISABLED;
-
- b = bundle_create();
- bundle_add_str(b, key, val);
-
- if (SendSytemEvent(std::string(SYS_EVENT_LOCATION_ENABLE_STATE), b,
- std::string(key)) != ES_R_OK)
- _E("failed to send event");
-
- if (b)
- bundle_free(b);
-};
-
-void VconfEventHandler::LocationEnabledCb(keynode_t *node, void *user_data) {
- int ret = 0;
- int enabled = 0;
- bundle *b = NULL;
- const char *key = NULL;
- const char *val = NULL;
-
- _D("vconfcb called");
-
- ret = vconf_get_int(VCONFKEY_LOCATION_ENABLED, &enabled);
- if (ret != VCONF_OK) {
- _E("failed to get vconf (%d)", ret);
- return;
- }
-
- key = EVT_KEY_GPS_ENABLE_STATE;
-
- if (enabled)
- val = EVT_VAL_GPS_ENABLED;
- else
- val = EVT_VAL_GPS_DISABLED;
-
- b = bundle_create();
- bundle_add_str(b, key, val);
-
- if (SendSytemEvent(std::string(SYS_EVENT_GPS_ENABLE_STATE), b,
- std::string(key)) != ES_R_OK)
- _E("failed to send event");
-
- if (b)
- bundle_free(b);
-};
-
-void VconfEventHandler::LocationNetworkEnabledCb(keynode_t *node, void *user_data) {
- int ret = 0;
- int enabled = 0;
- bundle *b = NULL;
- const char *key = NULL;
- const char *val = NULL;
-
- _D("vconfcb called");
-
- ret = vconf_get_int(VCONFKEY_LOCATION_NETWORK_ENABLED, &enabled);
- if (ret != VCONF_OK) {
- _E("failed to get vconf (%d)", ret);
- return;
- }
-
- key = EVT_KEY_NPS_ENABLE_STATE;
-
- if (enabled)
- val = EVT_VAL_NPS_ENABLED;
- else
- val = EVT_VAL_NPS_DISABLED;
-
- b = bundle_create();
- bundle_add_str(b, key, val);
-
- if (SendSytemEvent(std::string(SYS_EVENT_NPS_ENABLE_STATE), b,
- std::string(key)) != ES_R_OK)
- _E("failed to send event");
-
- if (b)
- bundle_free(b);
-};
-
-void VconfEventHandler::LangsetCb(keynode_t *node, void *user_data) {
- char *str = 0;
- bundle *b = NULL;
- const char *key = NULL;
-
- _D("vconfcb called");
-
- str = vconf_get_str(VCONFKEY_LANGSET);
- if (str == NULL) {
- _E("failed to get vconf str");
- return;
- }
-
- key = EVT_KEY_LANGUAGE_SET;
-
- b = bundle_create();
- bundle_add_str(b, key, str);
-
- if (SendSytemEvent(std::string(SYS_EVENT_LANGUAGE_SET), b,
- std::string(key)) != ES_R_OK)
- _E("failed to send event");
-
- if (b)
- bundle_free(b);
- if (str)
- free(str);
-};
-
-void VconfEventHandler::RegionFormatHourCb(keynode_t *node, void *user_data) {
- int ret = 0;
- int hours = 0;
- bundle *b = NULL;
- const char *key = NULL;
- const char *val = NULL;
-
- _D("vconfcb called");
-
- ret = vconf_get_int(VCONFKEY_REGIONFORMAT_TIME1224, &hours);
- if (ret != VCONF_OK) {
- _E("failed to get vconf (%d)", ret);
- return;
- }
-
- key = EVT_KEY_HOUR_FORMAT;
-
- if (hours == VCONFKEY_TIME_FORMAT_24)
- val = EVT_VAL_HOURFORMAT_24;
- else
- val = EVT_VAL_HOURFORMAT_12;
-
- b = bundle_create();
- bundle_add_str(b, key, val);
-
- if (SendSytemEvent(std::string(SYS_EVENT_HOUR_FORMAT), b,
- std::string(key)) != ES_R_OK)
- _E("failed to send event");
-
- if (b)
- bundle_free(b);
-};
-
-void VconfEventHandler::RegionFormatCb(keynode_t *node, void *user_data) {
- char *str = 0;
- bundle *b = NULL;
- const char *key = NULL;
-
- _D("vconfcb called");
-
- str = vconf_get_str(VCONFKEY_REGIONFORMAT);
- if (str == NULL) {
- _E("failed to get vconf str");
- return;
- }
-
- key = EVT_KEY_REGION_FORMAT;
-
- b = bundle_create();
- bundle_add_str(b, key, str);
-
- if (SendSytemEvent(std::string(SYS_EVENT_REGION_FORMAT), b,
- std::string(key)) != ES_R_OK)
- _E("failed to send event");
-
- if (b)
- bundle_free(b);
- if (str)
- free(str);
-};
-
-void VconfEventHandler::VibrationStatusCb(keynode_t *node, void *user_data) {
- int ret = 0;
- int vibration_on = 0;
- int sound_on = 0;
- bundle *b = NULL;
- char *key = NULL;
- char *val = NULL;
-
- _D("vconfcb called");
-
- ret = vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &vibration_on);
- if (ret != VCONF_OK) {
- _E("failed to get vconf (%d)", ret);
- return;
- }
-
- ret = vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &sound_on);
- if (ret != VCONF_OK) {
- _E("failed to get vconf (%d)", ret);
- return;
- }
-
- if (vibration_on) {
- key = EVT_KEY_VIBRATION_STATE;
- val = EVT_VAL_VIBRATION_ON;
- b = bundle_create();
- bundle_add_str(b, key, val);
- if (SendSytemEvent(std::string(SYS_EVENT_VIBRATION_STATE), b,
- std::string(key)) != ES_R_OK)
- _E("failed to send event");
-
- if (b)
- bundle_free(b);
-
- key = EVT_KEY_SILENT_MODE;
- val = EVT_VAL_SILENTMODE_OFF;
- b = bundle_create();
- bundle_add_str(b, key, val);
- if (SendSytemEvent(std::string(SYS_EVENT_SILENT_MODE), b,
- std::string(key)) != ES_R_OK)
- _E("failed to send event");
-
- if (b)
- bundle_free(b);
- } else {
- key = EVT_KEY_VIBRATION_STATE;
- val = EVT_VAL_VIBRATION_OFF;
- b = bundle_create();
- bundle_add_str(b, key, val);
- if (SendSytemEvent(std::string(SYS_EVENT_VIBRATION_STATE), b,
- std::string(key)) != ES_R_OK)
- _E("failed to send event");
-
- if (b)
- bundle_free(b);
-
- if (!sound_on) {
- key = EVT_KEY_SILENT_MODE;
- val = EVT_VAL_SILENTMODE_ON;
- b = bundle_create();
- bundle_add_str(b, key, val);
- if (SendSytemEvent(std::string(SYS_EVENT_SILENT_MODE), b,
- std::string(key)) != ES_R_OK)
- _E("failed to send event");
-
- if (b)
- bundle_free(b);
- }
- }
-};
-
-void VconfEventHandler::SoundStatusCb(keynode_t *node, void *user_data) {
- int ret = 0;
- int vibration_on = 0;
- int sound_on = 0;
- bundle *b = NULL;
- char *key = NULL;
- char *val = NULL;
-
- _D("vconfcb called");
-
- ret = vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &vibration_on);
- if (ret != VCONF_OK) {
- _E("failed to get vconf (%d)", ret);
- return;
- }
-
- ret = vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &sound_on);
- if (ret != VCONF_OK) {
- _E("failed to get vconf (%d)", ret);
- return;
- }
-
- if (sound_on) {
- key = EVT_KEY_VIBRATION_STATE;
- val = EVT_VAL_VIBRATION_OFF;
- b = bundle_create();
- bundle_add_str(b, key, val);
- if (SendSytemEvent(std::string(SYS_EVENT_VIBRATION_STATE), b,
- std::string(key)) != ES_R_OK)
- _E("failed to send event");
-
- if (b)
- bundle_free(b);
-
- key = EVT_KEY_SILENT_MODE;
- val = EVT_VAL_SILENTMODE_OFF;
- b = bundle_create();
- bundle_add_str(b, key, val);
- if (SendSytemEvent(std::string(SYS_EVENT_SILENT_MODE), b,
- std::string(key)) != ES_R_OK)
- _E("failed to send event");
-
- if (b)
- bundle_free(b);
- } else {
- if (!vibration_on) {
- key = EVT_KEY_SILENT_MODE;
- val = EVT_VAL_SILENTMODE_ON;
- b = bundle_create();
- bundle_add_str(b, key, val);
- if (SendSytemEvent(std::string(SYS_EVENT_SILENT_MODE), b,
- std::string(key)) != ES_R_OK)
- _E("failed to send event");
-
- if (b)
- bundle_free(b);
- }
- }
-};
-
-void VconfEventHandler::AutoRotateCb(keynode_t *node, void *user_data) {
- int ret = 0;
- int enabled = 0;
- bundle *b = NULL;
- const char *key = NULL;
- const char *val = NULL;
-
- _D("vconfcb called");
-
- ret = vconf_get_bool(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, &enabled);
- if (ret != VCONF_OK) {
- _E("failed to get vconf (%d)", ret);
- return;
- }
-
- key = EVT_KEY_SCREEN_AUTOROTATE_STATE;
-
- if (enabled)
- val = EVT_VAL_SCREEN_AUTOROTATE_ON;
- else
- val = EVT_VAL_SCREEN_AUTOROTATE_OFF;
-
- b = bundle_create();
- bundle_add_str(b, key, val);
-
- if (SendSytemEvent(std::string(SYS_EVENT_SCREEN_AUTOROTATE_STATE), b,
- std::string(key)) != ES_R_OK)
- _E("failed to send event");
-
- if (b)
- bundle_free(b);
-};
-
-void VconfEventHandler::MobileDataStateCb(keynode_t *node, void *user_data) {
- int ret = 0;
- int enabled = 0;
- bundle *b = NULL;
- const char *key = NULL;
- const char *val = NULL;
-
- _D("vconfcb called");
-
- ret = vconf_get_bool(VCONFKEY_3G_ENABLE, &enabled);
- if (ret != VCONF_OK) {
- _E("failed to get vconf (%d)", ret);
- return;
- }
-
- key = EVT_KEY_MOBILE_DATA_STATE;
-
- if (enabled)
- val = EVT_VAL_MOBILE_DATA_ON;
- else
- val = EVT_VAL_MOBILE_DATA_OFF;
-
- b = bundle_create();
- bundle_add_str(b, key, val);
-
- if (SendSytemEvent(std::string(SYS_EVENT_MOBILE_DATA_STATE), b,
- std::string(key)) != ES_R_OK)
- _E("failed to send event");
-
- if (b)
- bundle_free(b);
-};
-
-void VconfEventHandler::RoamingStateCb(keynode_t *node, void *user_data) {
- int ret = 0;
- int enabled = 0;
- bundle *b = NULL;
- const char *key = NULL;
- const char *val = NULL;
-
- _D("vconfcb called");
-
- ret = vconf_get_bool(VCONFKEY_SETAPPL_STATE_DATA_ROAMING_BOOL, &enabled);
- if (ret != VCONF_OK) {
- _E("failed to get vconf (%d)", ret);
- return;
- }
-
- key = EVT_KEY_DATA_ROAMING_STATE;
-
- if (enabled)
- val = EVT_VAL_DATA_ROAMING_ON;
- else
- val = EVT_VAL_DATA_ROAMING_OFF;
-
- b = bundle_create();
- bundle_add_str(b, key, val);
-
- if (SendSytemEvent(std::string(SYS_EVENT_DATA_ROAMING_STATE), b,
- std::string(key)) != ES_R_OK)
- _E("failed to send event");
-
- if (b)
- bundle_free(b);
-};
-
-void VconfEventHandler::FontSetCb(keynode_t *node, void *user_data) {
- char *str = 0;
- bundle *b = NULL;
- const char *key = NULL;
-
- _D("vconfcb called");
-
- str = vconf_get_str(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME);
- if (str == NULL) {
- _E("failed to get vconf str");
- return;
- }
-
- key = EVT_KEY_FONT_SET;
-
- b = bundle_create();
- bundle_add_str(b, key, str);
-
- if (SendSytemEvent(std::string(SYS_EVENT_FONT_SET), b,
- std::string(key)) != ES_R_OK)
- _E("failed to send event");
-
- if (b)
- bundle_free(b);
- if (str)
- free(str);
-};
-
-void VconfEventHandler::SetDefaultEvents() {
- vconf_notify_key_changed(VCONFKEY_LOCATION_USE_MY_LOCATION, LocationUseMyLocationCb, NULL);
- vconf_notify_key_changed(VCONFKEY_LOCATION_ENABLED, LocationEnabledCb, NULL);
- vconf_notify_key_changed(VCONFKEY_LOCATION_NETWORK_ENABLED, LocationNetworkEnabledCb, NULL);
- vconf_notify_key_changed(VCONFKEY_LANGSET, LangsetCb, NULL);
- vconf_notify_key_changed(VCONFKEY_REGIONFORMAT_TIME1224, RegionFormatHourCb, NULL);
- vconf_notify_key_changed(VCONFKEY_REGIONFORMAT, RegionFormatCb, NULL);
- vconf_notify_key_changed(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, VibrationStatusCb, NULL);
- vconf_notify_key_changed(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, SoundStatusCb, NULL);
- vconf_notify_key_changed(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, AutoRotateCb, NULL);
- vconf_notify_key_changed(VCONFKEY_3G_ENABLE, MobileDataStateCb, NULL);
- vconf_notify_key_changed(VCONFKEY_SETAPPL_STATE_DATA_ROAMING_BOOL, RoamingStateCb, NULL);
- vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, FontSetCb, NULL);
-}
-
-std::map<std::string, bundle*> VconfEventHandler::event_table_;
-
-int VconfEventHandler::SendSytemEvent(std::string event_name, bundle *b, std::string key) {
- int ret = ES_R_OK;
- bundle* data = nullptr;
- const auto& it = event_table_.find(event_name);
- if (it != event_table_.end())
- data = it->second;
-
- if (data && EventDataCompare(data, b, key) == 0) {
- _D("skip send: same with previous data");
- } else {
- ret = eventsystem_send_system_event(event_name.c_str(), b);
- if (ret != ES_R_OK) {
- _E("failed to send event");
- return ret;
- }
-
- if (data)
- bundle_free(data);
-
- event_table_[event_name] = bundle_dup(b);
- }
-
- return ret;
-}
-
-int VconfEventHandler::EventDataCompare(bundle* b1, bundle* b2, std::string key) {
- int ret = 0;
- int tmp1 = 0;
- int tmp2 = 0;
- char *str1 = NULL;
- char *str2 = NULL;
-
- if (bundle_get_count(b1) == bundle_get_count(b2)) {
- tmp1 = bundle_get_str(b1, key.c_str(), &str1);
- tmp2 = bundle_get_str(b2, key.c_str(), &str2);
- if (tmp1 == BUNDLE_ERROR_NONE && tmp2 == BUNDLE_ERROR_NONE) {
- if (strcmp(str1, str2) != 0) {
- _D("new event_data : value check");
- ret = 1;
- }
- }
- } else {
- _D("new event_data : bundle_count check");
- ret = 1;
- }
-
- if (ret == 0)
- _D("same event_data");
-
- return ret;
-}
-
-} // namespace
\ No newline at end of file
+++ /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 EVENTSYSTEM_MODULES_DBUS_EVENT_VCONF_EVENT_HANDLER_HH_
-#define EVENTSYSTEM_MODULES_DBUS_EVENT_VCONF_EVENT_HANDLER_HH_
-
-#include <map>
-#include <string>
-#include <vconf.h>
-#include <bundle.h>
-
-namespace esd::module {
-
-class VconfEventHandler {
- public:
- static int SendSytemEvent(std::string event_name, bundle *b, std::string key);
- static int EventDataCompare(bundle *b1, bundle *b2, std::string key);
- void SetDefaultEvents();
-
- private:
- static void LocationUseMyLocationCb(keynode_t *node, void *user_data);
- static void LocationEnabledCb(keynode_t *node, void *user_data);
- static void LocationNetworkEnabledCb(keynode_t *node, void *user_data);
- static void LangsetCb(keynode_t *node, void *user_data);
- static void RegionFormatHourCb(keynode_t *node, void *user_data);
- static void RegionFormatCb(keynode_t *node, void *user_data);
- static void VibrationStatusCb(keynode_t *node, void *user_data);
- static void SoundStatusCb(keynode_t *node, void *user_data);
- static void AutoRotateCb(keynode_t *node, void *user_data);
- static void MobileDataStateCb(keynode_t *node, void *user_data);
- static void RoamingStateCb(keynode_t *node, void *user_data);
- static void FontSetCb(keynode_t *node, void *user_data);
-
- private:
- static std::map<std::string, bundle*> event_table_;
-};
-
-} // namespace
-
-#endif // EVENTSYSTEM_MODULES_DBUS_EVENT_VCONF_EVENT_HANDLER_HH_
\ No newline at end of file
+++ /dev/null
-ADD_SUBDIRECTORY(cion_unit_tests)
-ADD_SUBDIRECTORY(dbus_event_unit_tests)
+++ /dev/null
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../src/modules/cion/ ESD_MOD_CION_SRCS)\r
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../src/lib/ ESD_LIB_SRCS)\r
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src/ ESD_MOD_CION_TEST_SRCS)\r
-\r
-SET(MOCK_SRCS\r
- ${CMAKE_CURRENT_SOURCE_DIR}/../mock/tzplatform_config_mock.cc\r
- ${CMAKE_CURRENT_SOURCE_DIR}/../mock/pkgmgr_info_mock.cc\r
- ${CMAKE_CURRENT_SOURCE_DIR}/../mock/test_fixture.cc\r
- ${CMAKE_CURRENT_SOURCE_DIR}/../mock/cion_mock.cc\r
-)\r
-\r
-ADD_EXECUTABLE(${TARGET_ESD_MOD_CION_UNITTESTS}\r
- ${ESD_MOD_CION_SRCS}\r
- ${ESD_LIB_SRCS}\r
- ${ESD_MOD_CION_TEST_SRCS}\r
- ${MOCK_SRCS}\r
-)\r
-\r
-TARGET_INCLUDE_DIRECTORIES(${TARGET_ESD_MOD_CION_UNITTESTS} PUBLIC\r
- ${CMAKE_CURRENT_SOURCE_DIR}/../../src/modules)\r
-TARGET_INCLUDE_DIRECTORIES(${TARGET_ESD_MOD_CION_UNITTESTS} PUBLIC\r
- ${CMAKE_CURRENT_SOURCE_DIR}/../)\r
-TARGET_INCLUDE_DIRECTORIES(${TARGET_ESD_MOD_CION_UNITTESTS} PUBLIC\r
- ${CMAKE_CURRENT_SOURCE_DIR}/../mock/)\r
-TARGET_LINK_LIBRARIES(${TARGET_ESD_MOD_CION_UNITTESTS} PRIVATE ${TARGET_LIB_ESD})\r
-\r
-APPLY_PKG_CONFIG(${TARGET_ESD_MOD_CION_UNITTESTS} PUBLIC\r
- AUL_DEPS\r
- BUNDLE_DEPS\r
- PARCEL_DEPS\r
- PKGMGR_INFO_DEPS\r
- DLOG_DEPS\r
- GIO_DEPS\r
- GLIB_DEPS\r
- CION_DEPS\r
- VCONF_DEPS\r
- CAPI_SYSTEM_INFO_DEPS\r
- LIBTZPLATFORM_CONFIG_DEPS\r
- UUID_DEPS\r
- SQLITE3_DEPS\r
- DATABASE_DEPS\r
- SECURITY_MANAGER_DEPS\r
- GMOCK_DEPS\r
-)\r
-\r
-INSTALL(TARGETS ${TARGET_ESD_MOD_CION_UNITTESTS} DESTINATION bin)\r
+++ /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 <gtest/gtest.h>
-#include <gmock/gmock.h>
-
-int main(int argc, char** argv) {
- int ret = -1;
-
- try {
- testing::InitGoogleTest(&argc, argv);
- } catch(...) {
- std::cout << "Exception occurred" << std::endl;
- }
-
- try {
- ret = RUN_ALL_TESTS();
- } catch (const ::testing::internal::GoogleTestFailureException& e) {
- ret = -1;
- std::cout << "GoogleTestFailureException was thrown:" << e.what() << std::endl;
- }
-
- return ret;
-}
+++ /dev/null
-/*
- * Copyright (c) 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 <gtest/gtest.h>
-
-#include "cion/cion_module.hh"
-#include "mock/pkgmgr_info_mock.h"
-#include "mock/tzplatform_config_mock.h"
-#include "mock/test_fixture.h"
-
-using ::testing::_;
-using ::testing::DoAll;
-using ::testing::Invoke;
-using ::testing::Return;
-using ::testing::SetArgPointee;
-
-namespace {
-
-class Mocks : public ::testing::NiceMock<TzplatformConfigMock>,
- public ::testing::NiceMock<PkgmgrInfoMock> {};
-
-const char *__fake_tzplatform_mkpath(enum tzplatform_variable id, const char *path) {
- return ".cion_test.db";
-}
-
-} //namespace
-
-class CionModuleTest : public TestFixture {
- public:
- CionModuleTest() : TestFixture(std::make_unique<Mocks>()) {}
- virtual ~CionModuleTest() {}
-
- virtual void SetUp() {
- remove(".cion_test.db");
- tools_ = std::make_unique<esd::api::ToolBox>();
- mod_ = std::make_unique<esd::module::CionModule>();
- EXPECT_CALL(GetMock<TzplatformConfigMock>(), tzplatform_mkpath(_, _))
- .WillRepeatedly(Invoke(__fake_tzplatform_mkpath));
- mod_->Startup(tools_.get());
- }
-
- virtual void TearDown() {
- mod_->Shutdown();
- mod_.reset();
- tools_.reset();
- }
-
- std::unique_ptr<esd::module::CionModule> mod_;
- std::unique_ptr<esd::api::ToolBox> tools_;
-};
-
-TEST_F(CionModuleTest, GetUuidWithGenerate) {
- EXPECT_CALL(GetMock<TzplatformConfigMock>(), tzplatform_mkpath(_, _))
- .WillRepeatedly(Invoke(__fake_tzplatform_mkpath));
-
- std::string app_id = "org.tizen.test";
- std::optional<std::string> uuid;
- bool ret = tools_->GetMethodBroker()
- .Invoke<const std::string&, std::optional<std::string>&>(
- "Cion.GetUuidWithGenerate", app_id, uuid);
- EXPECT_TRUE(ret);
- EXPECT_TRUE(static_cast<bool>(uuid));
-}
-
-TEST_F(CionModuleTest, SetDisplayNameGetDisplayName) {
- EXPECT_CALL(GetMock<TzplatformConfigMock>(), tzplatform_mkpath(_, _))
- .WillRepeatedly(Invoke(__fake_tzplatform_mkpath));
-
- std::string app_id = "org.tizen.test";
- std::string service_name = "test_service";
- std::string display_name = "TEST_SERVICE";
- int ret = -1;
- bool r = tools_->GetMethodBroker()
- .Invoke<const std::string&, const std::string&,
- const std::string&, int&>(
- "Cion.SetDisplayName", app_id, service_name, display_name, ret);
- EXPECT_TRUE(r);
- EXPECT_EQ(ret, 0);
-
- ret = -1;
- std::string result_display_name;
- r = tools_->GetMethodBroker()
- .Invoke<const std::string&, const std::string&,
- std::string&, int&>(
- "Cion.GetDisplayName", app_id, service_name, result_display_name,
- ret);
- EXPECT_TRUE(r);
- EXPECT_EQ(ret, 0);
- EXPECT_EQ(display_name, result_display_name);
-}
-
-TEST_F(CionModuleTest, SetEnabledGetEnabled) {
- EXPECT_CALL(GetMock<TzplatformConfigMock>(), tzplatform_mkpath(_, _))
- .WillRepeatedly(Invoke(__fake_tzplatform_mkpath));
- EXPECT_CALL(GetMock<PkgmgrInfoMock>(), pkgmgrinfo_pkginfo_get_version(_, _))
- .WillRepeatedly(Invoke([](pkgmgrinfo_pkginfo_h handle, char** version) {
- *version = const_cast<char*>("1.0.0");
- return PMINFO_R_OK;
- }));
-
- std::string app_id = "org.tizen.test";
- std::string service_name = "test_service";
- std::string display_name = "TEST_SERVICE";
- int ret = -1;
- bool r = tools_->GetMethodBroker()
- .Invoke<const std::string&, const std::string&,
- const std::string&, int&>(
- "Cion.SetDisplayName", app_id, service_name, display_name, ret);
- ASSERT_EQ(ret, 0);
-
- bool enabled = true;
- ret = -1;
- r = tools_->GetMethodBroker()
- .Invoke<const std::string&, const std::string&, bool, int&>(
- "Cion.SetEnabled", app_id, service_name, enabled, ret);
- EXPECT_TRUE(r);
- EXPECT_EQ(ret, 0);
-
- ret = -1;
- std::string result_display_name;
- bool result_enabled = false;
- r = tools_->GetMethodBroker()
- .Invoke<const std::string&, const std::string&, bool&, int&>(
- "Cion.GetEnabled", app_id, service_name, result_enabled, ret);
- EXPECT_TRUE(r);
- EXPECT_EQ(ret, 0);
- EXPECT_EQ(enabled, result_enabled);
-}
+++ /dev/null
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../src/modules/dbus_event/ ESD_MOD_DBUS_EVENT_SRC)\r
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../src/lib/ ESD_LIB_SRCS)\r
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src/ ESD_MOD_DBUS_EVENT_TEST_SRCS)\r
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../mock/ ESD_MOD_DBUS_EVENT_MOCK_SRCS)\r
-ADD_EXECUTABLE(${TARGET_ESD_MOD_DBUS_EVENT_UNITTESTS}\r
- ${ESD_MOD_DBUS_EVENT_SRC}\r
- ${ESD_LIB_SRCS}\r
- ${ESD_MOD_DBUS_EVENT_TEST_SRCS}\r
- ${ESD_MOD_DBUS_EVENT_MOCK_SRCS}\r
-)\r
-\r
-TARGET_INCLUDE_DIRECTORIES(${TARGET_ESD_MOD_DBUS_EVENT_UNITTESTS} PUBLIC\r
- ${CMAKE_CURRENT_SOURCE_DIR}/../../src/modules)\r
-TARGET_INCLUDE_DIRECTORIES(${TARGET_ESD_MOD_DBUS_EVENT_UNITTESTS} PUBLIC\r
- ${CMAKE_CURRENT_SOURCE_DIR}/..)\r
-\r
-TARGET_LINK_LIBRARIES(${TARGET_ESD_MOD_DBUS_EVENT_UNITTESTS} PRIVATE ${TARGET_LIB_ESD})\r
-\r
-APPLY_PKG_CONFIG(${TARGET_ESD_MOD_DBUS_EVENT_UNITTESTS} PUBLIC\r
- AUL_DEPS\r
- DLOG_DEPS\r
- GIO_DEPS\r
- GLIB_DEPS\r
- VCONF_DEPS\r
- PKGMGR_INFO_DEPS\r
- SECURITY_MANAGER_DEPS\r
- CYNARA_CLIENT_DEPS\r
- CYNARA_CREDS_DBUS_DEPS\r
- CYNARA_SESSION_DEPS\r
- LIBTZPLATFORM_CONFIG_DEPS\r
- CERT_SVC_VCORE_DEPS\r
- CAPI_SYSTEM_INFO_DEPS\r
- PKGMGR_DEPS\r
- EVENTSYSTEM_DEPS\r
- GMOCK_DEPS\r
- APPSVC_DEPS\r
-)\r
-\r
-INSTALL(TARGETS ${TARGET_ESD_MOD_DBUS_EVENT_UNITTESTS} DESTINATION bin)\r
+++ /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 <gtest/gtest.h>
-#include <gmock/gmock.h>
-
-int main(int argc, char** argv) {
- int ret = -1;
-
- try {
- testing::InitGoogleTest(&argc, argv);
- } catch(...) {
- std::cout << "Exception occurred" << std::endl;
- }
-
- try {
- ret = RUN_ALL_TESTS();
- } catch (const ::testing::internal::GoogleTestFailureException& e) {
- ret = -1;
- std::cout << "GoogleTestFailureException was thrown:" << e.what() << std::endl;
- }
-
- return ret;
-}
+++ /dev/null
-/*
- * Copyright (c) 2023 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 <gtest/gtest.h>
-
-#include <bundle_cpp.h>
-#include <eventsystem_internal.h>
-
-#include "mock/test_fixture.h"
-#include "mock/aul_mock.h"
-#include "mock/cynara_mock.h"
-#include "mock/eventsystem_mock.h"
-#include "mock/gio_mock.h"
-#include "mock/pkgmgr_info_mock.h"
-#include "mock/vconf_mock.h"
-#include "dbus_event/dbus_event_module.hh"
-
-using ::testing::_;
-using ::testing::DoAll;
-using ::testing::Invoke;
-using ::testing::InvokeArgument;
-using ::testing::Return;
-
-namespace {
-
-struct AppCtrlData {
- AppCtrlData(std::string_view appid, std::string_view pkgid, uid_t uid)
- : appid_(appid), pkgid_(pkgid), uid_(uid) {
- }
-
- std::string_view appid_;
- std::string_view pkgid_;
- uid_t uid_;
-};
-
-std::string pkgid_str("pkgid");
-
-class Mocks : public ::testing::NiceMock<AulMock>,
- public ::testing::NiceMock<CynaraMock>,
- public ::testing::NiceMock<EventSystemMock>,
- public ::testing::NiceMock<PkgmgrInfoMock>,
- public ::testing::NiceMock<GioMock>,
- public ::testing::NiceMock<VconfMock> {};
-
-} // namespace
-
-class DbusEventMoudleTest : public TestFixture {
- public:
- DbusEventMoudleTest() : TestFixture(std::make_unique<Mocks>()) {}
- virtual ~DbusEventMoudleTest() {}
-
- virtual void SetUp() {
- info_ = reinterpret_cast<GDBusNodeInfo*>(malloc(sizeof(GDBusNodeInfo)));
- pc_ = reinterpret_cast<pkgmgr_client*>(malloc(sizeof(pkgmgr_client*)));
-
- EXPECT_CALL(GetMock<GioMock>(), g_dbus_node_info_new_for_xml(_, _))
- .WillOnce(Return(info_));
- EXPECT_CALL(GetMock<GioMock>(), g_dbus_method_invocation_return_value(_, _))
- .WillRepeatedly(Return());
- EXPECT_CALL(GetMock<EventSystemMock>(), eventsystem_register_event(_, _, _, _))
- .WillRepeatedly(Return(ES_R_OK));
-
- module_ = std::make_unique<esd::module::DbusEventModule>();
- tools_ = std::make_unique<esd::api::ToolBox>();
- }
-
- virtual void TearDown() {
- module_->Shutdown();
- module_.reset();
- tools_.reset();
- free(info_);
- free(pc_);
- }
-
- std::unique_ptr<esd::module::DbusEventModule> module_;
- std::unique_ptr<esd::api::ToolBox> tools_;
- GDBusNodeInfo* info_;
- pkgmgr_client* pc_;
-};
-
-TEST_F(DbusEventMoudleTest, Startup) {
- EXPECT_CALL(GetMock<PkgmgrInfoMock>(), pkgmgr_client_listen_status(_, _, _))
- .WillOnce(Return(1));
- EXPECT_CALL(GetMock<PkgmgrInfoMock>(), pkgmgr_client_new(_))
- .WillOnce(Return(pc_));
- EXPECT_CALL(GetMock<GioMock>(), g_bus_own_name(_, _, _, _, _, _, _, _))
- .WillOnce(Return(1));
- EXPECT_CALL(GetMock<VconfMock>(), vconf_get_int(_, _))
- .WillRepeatedly(Return(VCONF_OK));
- EXPECT_CALL(GetMock<VconfMock>(), vconf_get_bool(_, _))
- .WillRepeatedly(Return(VCONF_OK));
- EXPECT_CALL(GetMock<VconfMock>(), vconf_notify_key_changed(_, _, _))
- .WillRepeatedly(Return(1));
-
- bool ret = module_->Startup(tools_.get());
- EXPECT_EQ(ret, true);
- module_->SetVconfHandler();
-}
-
-TEST_F(DbusEventMoudleTest, HandleMethodCallCb) {
- EXPECT_CALL(GetMock<PkgmgrInfoMock>(), pkgmgr_client_listen_status(_, _, _))
- .WillOnce(Return(1));
- EXPECT_CALL(GetMock<PkgmgrInfoMock>(), pkgmgr_client_new(_))
- .WillOnce(Return(pc_));
- EXPECT_CALL(GetMock<GioMock>(), g_bus_own_name(_, _, _, _, _, _, _, _))
- .WillOnce(Return(1));
- bool ret = module_->Startup(tools_.get());
- ASSERT_EQ(ret, true);
-
- GDBusMessage* msg = g_dbus_message_new();
- GDBusMessage* reply = g_dbus_message_new();
- GVariant* body = g_variant_new("(u)", 5001);
- EXPECT_CALL(GetMock<GioMock>(), g_dbus_message_new_method_call(_, _, _, _))
- .WillRepeatedly(Return(msg));
- EXPECT_CALL(GetMock<GioMock>(), g_dbus_connection_send_message_with_reply_sync(
- _, _, _, _, _, _, _)).WillRepeatedly(Return(reply));
- EXPECT_CALL(GetMock<GioMock>(), g_dbus_message_get_body(_))
- .WillRepeatedly(Return(body));
- EXPECT_CALL(GetMock<GioMock>(), g_dbus_connection_emit_signal(_, _, _, _, _,
- _, _)).WillOnce(Return(1));
- EXPECT_CALL(GetMock<AulMock>(), aul_app_get_appid_bypid_for_uid(_, _, _, _))
- .WillRepeatedly(Invoke([](int pid, char* appid, int size, uid_t uid) {
- snprintf(appid, size, "%s", "org.tizen.helloworld");
- return AUL_R_OK;
- }));
- EXPECT_CALL(GetMock<AulMock>(), aul_app_get_appid_bypid(_, _, _))
- .WillRepeatedly(Invoke([](int pid, char* appid, int size) {
- snprintf(appid, size, "%s", "org.tizen.helloworld");
- return AUL_R_OK;
- }));
-
- GVariant* var = g_variant_new("(is)", 5001, SYS_EVENT_DISPLAY_STATE);
- module_->HandleMethodCallCb(nullptr, nullptr, nullptr, nullptr,
- "CheckSenderValidation", var, nullptr, module_.get());
-
- GVariant* var2 = g_variant_new("(s)", SYS_EVENT_DISPLAY_STATE);
- module_->HandleMethodCallCb(nullptr, nullptr, nullptr, nullptr,
- "GetTrustedPeerList", var2, nullptr, module_.get());
-
- GVariant* var3 = g_variant_new("(ss)", SYS_EVENT_DISPLAY_STATE, "dest");
- module_->HandleMethodCallCb(nullptr, nullptr, nullptr, nullptr,
- "SetupTrustedPeer", var3, nullptr, module_.get());
-
- GVariant* var5 = g_variant_new("(s)", SYS_EVENT_DISPLAY_STATE);
- module_->HandleMethodCallCb(nullptr, nullptr, nullptr, nullptr,
- "CheckUserSendValidation", var5, nullptr, module_.get());
-
- module_->HandleMethodCallCb(nullptr, nullptr, nullptr, nullptr,
- "CionGetUuid", nullptr, nullptr, module_.get());
-
- GVariant* var10 = g_variant_new("(ss)", "service", "display");
- module_->HandleMethodCallCb(nullptr, nullptr, nullptr, nullptr,
- "CionSetDisplayName", var10, nullptr, module_.get());
-
- GVariant* var11 = g_variant_new("(s)", "service");
- module_->HandleMethodCallCb(nullptr, nullptr, nullptr, nullptr,
- "CionGetDisplayName", var11, nullptr, module_.get());
-
- GVariant* var12 = g_variant_new("(sb)", "service", true);
- module_->HandleMethodCallCb(nullptr, nullptr, nullptr, nullptr,
- "CionSetEnabled", var12, nullptr, module_.get());
-
- GVariant* var13 = g_variant_new("(s)", "service");
- module_->HandleMethodCallCb(nullptr, nullptr, nullptr, nullptr,
- "CionGetEnabled", var13, nullptr, module_.get());
-
- GVariant* var4 = g_variant_new("(s)", SYS_EVENT_DISPLAY_STATE);
- module_->HandleMethodCallCb(nullptr, nullptr, nullptr, nullptr,
- "CheckPrivilegeValidation", var4, nullptr, module_.get());
-
- GVariant* var6 = g_variant_new("(s)", SYS_EVENT_BOOT_COMPLETED);
- module_->HandleMethodCallCb(nullptr, nullptr, nullptr, nullptr,
- "GetEarlierData", var6, nullptr, module_.get());
-
- GVariant* var7 = g_variant_new("(ss)", SYS_EVENT_DISPLAY_STATE, "own");
- module_->HandleMethodCallCb(nullptr, nullptr, nullptr, nullptr,
- "KeepLastData", var7, nullptr, module_.get());
-
- GVariant* var8 = g_variant_new("(ss)", SYS_EVENT_DISPLAY_STATE, "own");
- module_->HandleMethodCallCb(nullptr, nullptr, nullptr, nullptr,
- "CheckLastData", var8, nullptr, module_.get());
-
- tizen_base::Bundle b;
- b.Add("key", "value");
- auto raw = b.ToRaw();
- GVariant* var9 = g_variant_new("(ssib)", SYS_EVENT_DISPLAY_STATE,
- raw.first.get(), raw.second, true);
- module_->HandleMethodCallCb(nullptr, nullptr, nullptr, nullptr,
- "LaunchOnEventFromUserEvent", var9, nullptr, module_.get());
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2023 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 <gtest/gtest.h>
-
-#include <bundle.h>
-#include <eventsystem_internal.h>
-
-#include "mock/test_fixture.h"
-#include "mock/eventsystem_mock.h"
-#include "mock/vconf_mock.h"
-#include "dbus_event/earlier_item.hh"
-
-using ::testing::_;
-using ::testing::Return;
-
-namespace {
-
-class Mocks : public ::testing::NiceMock<EventSystemMock>,
- public ::testing::NiceMock<VconfMock> {};
-
-} // namespace
-
-class EarlierItemTest : public TestFixture {
- public:
- EarlierItemTest() : TestFixture(std::make_unique<Mocks>()) {}
- virtual ~EarlierItemTest() {}
-
- virtual void SetUp() {
- tizen_base::Bundle b;
- b.Add("key", "value");
- item_ = std::make_unique<esd::module::EarlierItem>(b);
- }
-
- virtual void TearDown() {
- }
-
- std::unique_ptr<esd::module::EarlierItem> item_;
-};
-
-TEST_F(EarlierItemTest, Register) {
- EXPECT_CALL(GetMock<EventSystemMock>(), eventsystem_register_event(_, _, _, _))
- .WillOnce(Return(ES_R_OK));
- bool ret = item_->Register(std::string_view("str"));
- EXPECT_EQ(ret, true);
-}
-
-TEST_F(EarlierItemTest, GetData) {
- tizen_base::Bundle b = item_->GetData();
- EXPECT_STREQ(b.GetString("key").c_str(), "value");
-}
-
-TEST_F(EarlierItemTest, CreateMap) {
- EXPECT_CALL(GetMock<VconfMock>(), vconf_get_int(_, _))
- .WillRepeatedly(Return(VCONF_OK));
- std::map<std::string, std::unique_ptr<esd::module::EarlierItem>> items =
- item_->CreateMap();
- EXPECT_EQ(items.size(), 5);
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2023 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 <gtest/gtest.h>
-
-#include <bundle.h>
-#include <eventsystem_internal.h>
-
-#include "mock/test_fixture.h"
-#include "mock/aul_mock.h"
-#include "mock/eventsystem_mock.h"
-#include "dbus_event/event_launch.hh"
-
-using ::testing::_;
-using ::testing::DoAll;
-using ::testing::InvokeArgument;
-using ::testing::Return;
-
-namespace {
-
-class Mocks : public ::testing::NiceMock<EventSystemMock>,
- public ::testing::NiceMock<AulMock> {};
-
-} // namespace
-
-class EventLaunchTest : public TestFixture {
- public:
- EventLaunchTest() : TestFixture(std::make_unique<Mocks>()) {}
- virtual ~EventLaunchTest() {}
-
- virtual void SetUp() {
- event_launch_ = std::make_unique<esd::module::EventLaunch>(
- std::string("pkgid"), std::string("appid"), 5001);
- }
-
- virtual void TearDown() {
- }
-
- std::unique_ptr<esd::module::EventLaunch> event_launch_;
-};
-
-TEST_F(EventLaunchTest, Register) {
- EXPECT_CALL(GetMock<EventSystemMock>(), eventsystem_register_event(_, _, _, _))
- .WillOnce(DoAll(InvokeArgument<2>("event_name", nullptr,
- event_launch_.get()), Return(0)));
- bool ret = event_launch_->Register(SYS_EVENT_OUTGOING_MSG);
- EXPECT_EQ(ret, true);
-}
-
-TEST_F(EventLaunchTest, GetUid) {
- uid_t ret = event_launch_->GetUid();
- EXPECT_EQ(ret, 5001);
-}
-
-TEST_F(EventLaunchTest, GetPackageName) {
- std::string pkg_name = event_launch_->GetPackageName();
- EXPECT_STREQ(pkg_name.c_str(), "pkgid");
-}
-
-TEST_F(EventLaunchTest, GetAppListEventLaunch) {
- std::list<esd::module::EsdListItem> list =
- event_launch_->GetAppListEventLaunch();
- EXPECT_NE(list.size(), 0);
-}
-
-TEST_F(EventLaunchTest, Notify) {
- EXPECT_CALL(GetMock<AulMock>(), aul_app_is_running_for_uid(_, _))
- .WillOnce(Return(0));
- EXPECT_CALL(GetMock<AulMock>(), aul_svc_run_service_async_for_uid(_, _, _, _, _))
- .WillOnce(Return(0));
-
- tizen_base::Bundle b;
- event_launch_->Notify(std::string_view(SYS_EVENT_BATTERY_CHARGER_STATUS),
- b, false, false, 5001, std::string_view("sender"));
- event_launch_->Notify(std::string_view(SYS_EVENT_USB_STATUS),
- b, false, false, 5001, std::string_view("sender"));
- event_launch_->Notify(std::string_view(SYS_EVENT_EARJACK_STATUS),
- b, false, false, 5001, std::string_view("sender"));
- event_launch_->Notify(std::string_view(SYS_EVENT_INCOMMING_MSG),
- b, false, false, 5001, std::string_view("sender"));
- event_launch_->Notify(std::string_view(SYS_EVENT_OUTGOING_MSG),
- b, false, false, 5001, std::string_view("sender"));
- event_launch_->Notify(std::string_view(SYS_EVENT_WIFI_STATE),
- b, false, false, 5001, std::string_view("sender"));
- event_launch_->Notify(std::string_view("User"),
- b, false, true, 5001, std::string_view("sender"));
-}
\ No newline at end of file
+++ /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 <gtest/gtest.h>
-
-#include <eventsystem_internal.h>
-#include <security-manager.h>
-
-#include "mock/cynara_mock.h"
-#include "mock/security_manager_mock.h"
-#include "mock/test_fixture.h"
-#include "dbus_event/privilege_checker.hh"
-
-
-// using namespace tizen_base;
-using ::testing::_;
-using ::testing::DoAll;
-using ::testing::Invoke;
-using ::testing::Return;
-using ::testing::SetArgPointee;
-
-namespace {
-
-class Mocks : public ::testing::NiceMock<CynaraMock>,
- public ::testing::NiceMock<SecurityManagerMock>{};
-
-} //namespace
-
-class PrivilegeCheckerTest : public TestFixture {
- public:
- PrivilegeCheckerTest() : TestFixture(std::make_unique<Mocks>()) {}
- virtual ~PrivilegeCheckerTest() {}
-
- virtual void SetUp() {
- EXPECT_CALL(GetMock<CynaraMock>(),
- cynara_initialize(_, _)).WillRepeatedly(
- Invoke([this](cynara** cynara, const cynara_configuration* conf) {
- *cynara = this->cynara_;
- return CYNARA_API_SUCCESS;
- }));
-
- cynara_ = (cynara*)malloc(1);
- checker_ = std::make_unique<esd::module::PrivilegeChecker>();
- }
-
- virtual void TearDown() {
- EXPECT_CALL(GetMock<CynaraMock>(),
- cynara_finish(_)).WillRepeatedly(Return(CYNARA_API_SUCCESS));
- checker_.reset();
- free(cynara_);
- }
-
- cynara* cynara_;
- std::unique_ptr<esd::module::PrivilegeChecker> checker_;
-};
-
-TEST_F(PrivilegeCheckerTest, CheckPrivilegeName) {
- std::string priv = checker_->CheckPrivilegeName(std::string(SYS_EVENT_WIFI_STATE));
- EXPECT_NE(priv, "");
-}
-
-TEST_F(PrivilegeCheckerTest, CheckPrivilegeName_N) {
- std::string event_name("wifi_state");
- std::string priv = checker_->CheckPrivilegeName(event_name);
- EXPECT_EQ(priv, "");
-}
-
-TEST_F(PrivilegeCheckerTest, AppHasPrivilege) {
- EXPECT_CALL(GetMock<SecurityManagerMock>(),
- security_manager_app_has_privilege(_, _, _, _))
- .WillOnce(DoAll(SetArgPointee<3>(1), Return(SECURITY_MANAGER_SUCCESS)));
- uid_t uid = 5001;
- std::string app_id("app_id");
- std::string pkg_id("pkg_id");
- bool ret = checker_->AppHasPrivilege(uid, app_id, SYS_EVENT_WIFI_STATE);
- EXPECT_EQ(ret, true);
-}
-
-TEST_F(PrivilegeCheckerTest, Check) {
- char* session = strdup("session");
- EXPECT_CALL(GetMock<CynaraMock>(),
- cynara_creds_gdbus_get_client(_, _, _, _))
- .WillOnce(Return(CYNARA_API_SUCCESS));
- EXPECT_CALL(GetMock<CynaraMock>(),
- cynara_creds_gdbus_get_user(_, _, _, _))
- .WillOnce(Return(CYNARA_API_SUCCESS));
- EXPECT_CALL(GetMock<CynaraMock>(),
- cynara_session_from_pid(_))
- .WillOnce(Return(session));
- EXPECT_CALL(GetMock<CynaraMock>(),
- cynara_check(_, _, _, _, _))
- .WillOnce(Return(CYNARA_API_ACCESS_ALLOWED));
-
- std::string privilege("test");
- bool ret = checker_->Check(nullptr, nullptr, 10, privilege);
- EXPECT_EQ(ret, true);
-}
\ No newline at end of file
+++ /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 <gtest/gtest.h>
-
-#include <bundle.h>
-#include <eventsystem_internal.h>
-#include <vconf.h>
-
-#include "mock/test_fixture.h"
-#include "mock/eventsystem_mock.h"
-#include "mock/vconf_mock.h"
-#include "dbus_event/vconf_event_handler.hh"
-
-// using namespace tizen_base;
-using ::testing::_;
-using ::testing::DoAll;
-using ::testing::InvokeArgument;
-using ::testing::Return;
-
-namespace {
-
-class Mocks : public ::testing::NiceMock<EventSystemMock>,
- public ::testing::NiceMock<VconfMock> {};
-
-} // namespace
-
-class VconfHandlerTest : public TestFixture {
- public:
- VconfHandlerTest() : TestFixture(std::make_unique<Mocks>()) {}
- virtual ~VconfHandlerTest() {}
-
- virtual void SetUp() {
- handler_ = std::make_unique<esd::module::VconfEventHandler>();
- }
-
- virtual void TearDown() {
- }
-
- std::unique_ptr<esd::module::VconfEventHandler> handler_;
-};
-
-TEST_F(VconfHandlerTest, SendSytemEvent) {
- EXPECT_CALL(GetMock<EventSystemMock>(), eventsystem_send_system_event(_, _))
- .WillOnce(Return(ES_R_OK));
- bundle* b = bundle_create();
- int ret = handler_->SendSytemEvent(SYS_EVENT_WIFI_STATE, b,
- std::string("key"));
- EXPECT_EQ(ret, ES_R_OK);
-}
-
-TEST_F(VconfHandlerTest, EventDataCompare) {
- bundle* b1 = bundle_create();
- bundle* b2 = bundle_create();
- bundle_add_str(b1, "test_key", "val");
- bundle_add_str(b2, "test_key", "val");
- int ret = handler_->EventDataCompare(b1, b2, std::string("test_key"));
- EXPECT_NE(ret, 1);
- bundle_free(b1);
- bundle_free(b2);
-}
\ No newline at end of file
+++ /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 "aul_mock.h"
-#include "mock_hook.h"
-#include "test_fixture.h"
-
-extern "C" int aul_svc_run_service_async_for_uid(bundle* arg0,
- int arg1, aul_svc_res_fn arg2, void* arg3, uid_t arg4) {
- return MOCK_HOOK_P5(AulMock, aul_svc_run_service_async_for_uid, arg0, arg1,
- arg2, arg3, arg4);
-}
-
-extern "C" int aul_app_is_running_for_uid(const char* arg0, uid_t arg1) {
- return MOCK_HOOK_P2(AulMock, aul_app_is_running_for_uid, arg0, arg1);
-}
-
-extern "C" int aul_app_get_appid_bypid_for_uid(int arg0, char* arg1, int arg2,
- uid_t arg3) {
- return MOCK_HOOK_P4(AulMock, aul_app_get_appid_bypid_for_uid, arg0, arg1,
- arg2, arg3);
-}
-
-extern "C" int aul_app_get_appid_bypid(int pid, char* appid, int size) {
- return MOCK_HOOK_P3(AulMock, aul_app_get_appid_bypid, pid, appid, size);
-}
-
+++ /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 MOCK_AUL_MOCK_H_
-#define MOCK_AUL_MOCK_H_
-
-#include <aul.h>
-#include <aul_svc.h>
-#include <gmock/gmock.h>
-
-#include "module_mock.h"
-
-class AulMock : public virtual ModuleMock {
- public:
- virtual ~AulMock() {}
-
- MOCK_METHOD5(aul_svc_run_service_async_for_uid, int(bundle*,
- int, aul_svc_res_fn, void*, uid_t));
- MOCK_METHOD2(aul_app_is_running_for_uid, int(const char*, uid_t));
- MOCK_METHOD4(aul_app_get_appid_bypid_for_uid, int (int, char*, int, uid_t));
- MOCK_METHOD3(aul_app_get_appid_bypid, int (int, char*, int));
-};
-
-#endif // MOCK_AUL_MOCK_H_
+++ /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 <cion/channel/server_channel.hh>
-#include <cion/common/ipayload.hh>
-#include <cion/common/exception.hh>
-
-namespace cion {
-namespace channel {
-
-class ServerChannel::Impl {
-};
-
-ServerChannel::ServerChannel(std::string service_name, std::string display_name) {
-}
-
-ServerChannel::ServerChannel(std::string service_name, std::string display_name,
- SecurityInfo security) {
-}
-
-ServerChannel::~ServerChannel() = default;
-
-void ServerChannel::Listen() {
-
-}
-
-void ServerChannel::Stop() {
-
-}
-
-void ServerChannel::Disconnect(std::shared_ptr<PeerInfo>) {
-
-}
-
-void ServerChannel::Accept(std::shared_ptr<PeerInfo> peer) {
-
-}
-
-void ServerChannel::Reject(std::shared_ptr<PeerInfo> peer, std::string reason) {
-
-}
-
-void ServerChannel::SendPayloadAsync(IPayload* data,
- PayloadAsyncResult::PayloadAsyncResultCallback func) {
-}
-
-void ServerChannel::SendPayloadAsync(IPayload* data, std::shared_ptr<PeerInfo> peer,
- PayloadAsyncResult::PayloadAsyncResultCallback func) {
-}
-
-std::list<std::shared_ptr<PeerInfo>> ServerChannel::GetConnectedPeerList() {
- return {};
-}
-
-std::string GetServiceName() {
- return "";
-}
-
-std::string GetDisplayName() {
- return "";
-}
-
-void SetDisplayName(std::string display_name) {
-}
-
-void SetOndemandLaunchEnable(bool enable) {
-}
-
-}
-}
+++ /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 "cynara_mock.h"
-#include "mock_hook.h"
-#include "test_fixture.h"
-
-extern "C" int cynara_finish(cynara* arg0) {
- return MOCK_HOOK_P1(CynaraMock, cynara_finish, arg0);
-}
-
-extern "C" int cynara_check(cynara* arg0, const char* arg1, const char* arg2,
- const char* arg3, const char* arg4) {
- return MOCK_HOOK_P5(CynaraMock, cynara_check, arg0, arg1, arg2, arg3, arg4);
-}
-
-extern "C" int cynara_initialize(cynara** arg0, const cynara_configuration* arg1) {
- return MOCK_HOOK_P2(CynaraMock, cynara_initialize, arg0, arg1);
-}
-
-extern "C" int cynara_creds_gdbus_get_user(GDBusConnection* arg0,
- const gchar* arg1, enum cynara_user_creds arg2, gchar** arg3) {
- return MOCK_HOOK_P4(CynaraMock, cynara_creds_gdbus_get_user, arg0, arg1,
- arg2, arg3);
-}
-
-extern "C" int cynara_creds_gdbus_get_client(GDBusConnection* arg0,
- const gchar* arg1, enum cynara_client_creds arg2, gchar** arg3) {
- return MOCK_HOOK_P4(CynaraMock, cynara_creds_gdbus_get_client, arg0, arg1,
- arg2, arg3);
-}
-
-extern "C" char* cynara_session_from_pid(pid_t arg0) {
- return MOCK_HOOK_P1(CynaraMock, cynara_session_from_pid, arg0);
-}
-
+++ /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 MOCK_CYNARA_MOCK_H_
-#define MOCK_CYNARA_MOCK_H_
-
-#include <cynara-client.h>
-#include <cynara-creds-gdbus.h>
-#include <gmock/gmock.h>
-
-#include "module_mock.h"
-
-class CynaraMock : public virtual ModuleMock {
- public:
- virtual ~CynaraMock() {}
-
- MOCK_METHOD1(cynara_finish, int (cynara*));
- MOCK_METHOD5(cynara_check,
- int (cynara*, const char*, const char*, const char*, const char*));
- MOCK_METHOD2(cynara_initialize, int (cynara**, const cynara_configuration*));
- MOCK_METHOD4(cynara_creds_gdbus_get_user, int (GDBusConnection*,
- const gchar*, enum cynara_user_creds, gchar**));
- MOCK_METHOD4(cynara_creds_gdbus_get_client, int (GDBusConnection*,
- const gchar*, enum cynara_client_creds, gchar**));
- MOCK_METHOD1(cynara_session_from_pid, char* (pid_t));
-};
-
-#endif // MOCK_CYNARA_MOCK_H_
\ No newline at end of file
+++ /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 "eventsystem_mock.h"
-#include "mock_hook.h"
-#include "test_fixture.h"
-
-extern "C" int eventsystem_send_system_event(const char* arg0, bundle* arg1) {
- return MOCK_HOOK_P2(EventSystemMock, eventsystem_send_system_event, arg0, arg1);
-}
-
-extern "C" int eventsystem_register_event(const char* arg0, unsigned int* arg1,
- eventsystem_handler arg2, void* arg3) {
- return MOCK_HOOK_P4(EventSystemMock, eventsystem_register_event, arg0, arg1,
- arg2, arg3);
-}
+++ /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 MOCK_EVENTSYSTEM_MOCK_H_
-#define MOCK_EVENTSYSTEM_MOCK_H_
-
-#include <bundle.h>
-#include <eventsystem.h>
-#include <gmock/gmock.h>
-
-#include "module_mock.h"
-
-class EventSystemMock : public virtual ModuleMock {
- public:
- virtual ~EventSystemMock() {}
-
- MOCK_METHOD2(eventsystem_send_system_event, int(const char*, bundle*));
- MOCK_METHOD4(eventsystem_register_event, int(const char*, unsigned int*,
- eventsystem_handler, void*));
-};
-
-#endif // MOCK_EVENTSYSTEM_MOCK_H_
\ No newline at end of file
+++ /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 <gio/gio.h>
-
-#include "gio_mock.h"
-#include "mock_hook.h"
-#include "test_fixture.h"
-
-extern "C" guint g_dbus_connection_register_object(GDBusConnection* arg0,
- const gchar* arg1, GDBusInterfaceInfo* arg2,
- const GDBusInterfaceVTable* arg3, gpointer arg4,
- GDestroyNotify arg5, GError** arg6) {
- return MOCK_HOOK_P7(GioMock, g_dbus_connection_register_object,
- arg0, arg1, arg2, arg3, arg4, arg5, arg6);
-}
-
-extern "C" guint g_dbus_connection_signal_subscribe(GDBusConnection* arg0,
- const gchar* arg1, const gchar* arg2, const gchar* arg3, const gchar* arg4,
- const gchar* arg5, GDBusSignalFlags arg6, GDBusSignalCallback arg7,
- gpointer arg8, GDestroyNotify arg9) {
- return MOCK_HOOK_P10(GioMock, g_dbus_connection_signal_subscribe,
- arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
-}
-
-extern "C" guint g_bus_own_name(GBusType arg0, const gchar* arg1,
- GBusNameOwnerFlags arg2, GBusAcquiredCallback arg3,
- GBusNameAcquiredCallback arg4, GBusNameLostCallback arg5, gpointer arg6,
- GDestroyNotify arg7) {
- return MOCK_HOOK_P8(GioMock, g_bus_own_name, arg0, arg1, arg2, arg3, arg4,
- arg5, arg6, arg7);
-}
-
-extern "C" GDBusMessage* g_dbus_connection_send_message_with_reply_sync(
- GDBusConnection* conn, GDBusMessage* msg, GDBusSendMessageFlags flags,
- gint timeout, volatile guint32* out_serial, GCancellable* cancellable,
- GError** error) {
- return MOCK_HOOK_P7(GioMock, g_dbus_connection_send_message_with_reply_sync,
- conn, msg, flags, timeout, out_serial, cancellable, error);
-}
-
-extern "C" GVariant* g_dbus_message_get_body(GDBusMessage* arg0) {
- return MOCK_HOOK_P1(GioMock, g_dbus_message_get_body, arg0);
-}
-
-extern "C" gboolean g_dbus_connection_emit_signal(GDBusConnection* arg1,
- const gchar* arg2, const gchar* arg3, const gchar* arg4, const gchar* arg5,
- GVariant* arg6, GError** arg7) {
- return MOCK_HOOK_P7(GioMock, g_dbus_connection_emit_signal, arg1, arg2,
- arg3, arg4, arg5, arg6, arg7);
-}
-
-extern "C" GDBusNodeInfo* g_dbus_node_info_new_for_xml(const gchar* arg0,
- GError** arg1) {
- return MOCK_HOOK_P2(GioMock, g_dbus_node_info_new_for_xml, arg0, arg1);
-}
-
-extern "C" void g_dbus_method_invocation_return_value(
- GDBusMethodInvocation* arg0, GVariant* arg1) {
- MOCK_HOOK_P2(GioMock, g_dbus_method_invocation_return_value, arg0, arg1);
-}
-
-extern "C" void g_dbus_message_set_body(GDBusMessage* arg0, GVariant* arg1) {
- return MOCK_HOOK_P2(GioMock, g_dbus_message_set_body, arg0, arg1);
-}
-
-extern "C" void g_object_unref(gpointer arg0) {
- return MOCK_HOOK_P1(GioMock, g_object_unref, arg0);
-}
-
-extern "C" GDBusMessage* g_dbus_message_new_method_call(const gchar* arg0,
- const gchar* arg1, const gchar* arg2, const gchar* arg3) {
- return MOCK_HOOK_P4(GioMock, g_dbus_message_new_method_call, arg0, arg1, arg2,
- arg3);
-}
-
+++ /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 MOCK_GIO_MOCK_H_
-#define MOCK_GIO_MOCK_H_
-
-#include <gio/gio.h>
-#include <gmock/gmock.h>
-
-#include "module_mock.h"
-
-class GioMock : public virtual ModuleMock {
- public:
- virtual ~GioMock() {}
-
- MOCK_METHOD7(g_dbus_connection_register_object, guint (GDBusConnection*,
- const gchar*, GDBusInterfaceInfo*, const GDBusInterfaceVTable*, gpointer,
- GDestroyNotify, GError**));
-
- MOCK_METHOD10(g_dbus_connection_signal_subscribe,
- guint(GDBusConnection*, const gchar*, const gchar*, const gchar*,
- const gchar*, const gchar*, GDBusSignalFlags, GDBusSignalCallback,
- gpointer, GDestroyNotify));
-
- MOCK_METHOD8(g_bus_own_name,
- guint(GBusType, const gchar*,
- GBusNameOwnerFlags, GBusAcquiredCallback, GBusNameAcquiredCallback,
- GBusNameLostCallback, gpointer, GDestroyNotify));
-
- MOCK_METHOD7(g_dbus_connection_send_message_with_reply_sync,
- GDBusMessage*(GDBusConnection*, GDBusMessage*, GDBusSendMessageFlags,
- gint, volatile guint32*, GCancellable*, GError**));
-
- MOCK_METHOD1(g_dbus_message_get_body, GVariant*(GDBusMessage*));
-
- MOCK_METHOD7(g_dbus_connection_emit_signal, gboolean (GDBusConnection*,
- const gchar*, const gchar*, const gchar*, const gchar*, GVariant*,
- GError**));
-
- MOCK_METHOD2(g_dbus_node_info_new_for_xml, GDBusNodeInfo* (const gchar*,
- GError**));
-
- MOCK_METHOD2(g_dbus_method_invocation_return_value,
- void (GDBusMethodInvocation*, GVariant*));
-
- MOCK_METHOD2(g_dbus_message_set_body, void(GDBusMessage*, GVariant*));
-
- MOCK_METHOD1(g_object_unref, void(gpointer));
-
- MOCK_METHOD4(g_dbus_message_new_method_call,
- GDBusMessage*(const gchar*, const gchar*, const gchar*, const gchar*));
-
-};
-
-#endif // MOCK_GIO_MOCK_H_
\ No newline at end of file
+++ /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 MOCK_MOCK_HOOK_H_
-#define MOCK_MOCK_HOOK_H_
-
-#define MOCK_HOOK_P0(MOCK_CLASS, f) \
- TestFixture::GetMock<MOCK_CLASS>().f()
-#define MOCK_HOOK_P1(MOCK_CLASS, f, p1) \
- TestFixture::GetMock<MOCK_CLASS>().f(p1)
-#define MOCK_HOOK_P2(MOCK_CLASS, f, p1, p2) \
- TestFixture::GetMock<MOCK_CLASS>().f(p1, p2)
-#define MOCK_HOOK_P3(MOCK_CLASS, f, p1, p2, p3) \
- TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3)
-#define MOCK_HOOK_P4(MOCK_CLASS, f, p1, p2, p3, p4) \
- TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3, p4)
-#define MOCK_HOOK_P5(MOCK_CLASS, f, p1, p2, p3, p4, p5) \
- TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3, p4, p5)
-#define MOCK_HOOK_P6(MOCK_CLASS, f, p1, p2, p3, p4, p5, p6) \
- TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3, p4, p5, p6)
-#define MOCK_HOOK_P7(MOCK_CLASS, f, p1, p2, p3, p4, p5, p6, p7) \
- TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3, p4, p5, p6, p7)
-#define MOCK_HOOK_P8(MOCK_CLASS, f, p1, p2, p3, p4, p5, p6, p7, p8) \
- TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3, p4, p5, p6, p7, p8)
-#define MOCK_HOOK_P10(MOCK_CLASS, f, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10) \
- TestFixture::GetMock<MOCK_CLASS>().f( \
- p1, p2, p3, p4, p5, p6, p7, p8, p9, p10)
-
-#endif // MOCK_MOCK_HOOK_H_
+++ /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 MOCK_MODULE_MOCK_H_
-#define MOCK_MODULE_MOCK_H_
-
-class ModuleMock {
- public:
- virtual ~ModuleMock() {}
-};
-
-#endif // MOCK_MODULE_MOCK_H_
+++ /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 "pkgmgr_info_mock.h"
-#include "mock_hook.h"
-#include "test_fixture.h"
-
-extern "C" int pkgmgr_client_free(pkgmgr_client* arg0) {
- return MOCK_HOOK_P1(PkgmgrInfoMock, pkgmgr_client_free, arg0);
-}
-
-extern "C" int pkgmgrinfo_appinfo_get_appid(
- pkgmgrinfo_appinfo_h arg0, char** arg1) {
- return MOCK_HOOK_P2(PkgmgrInfoMock, pkgmgrinfo_appinfo_get_appid,
- arg0, arg1);
-}
-
-extern "C" int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h arg0) {
- return MOCK_HOOK_P1(PkgmgrInfoMock, pkgmgrinfo_pkginfo_destroy_pkginfo,
- arg0);
-}
-
-extern "C" int pkgmgrinfo_pkginfo_compare_usr_app_cert_info(const char* arg0,
- const char* arg1, uid_t arg2, pkgmgrinfo_cert_compare_result_type_e* arg3) {
- return MOCK_HOOK_P4(PkgmgrInfoMock, pkgmgrinfo_pkginfo_compare_usr_app_cert_info,
- arg0, arg1, arg2, arg3);
-}
-
-extern "C" int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h arg0,
- pkgmgrinfo_app_control_list_cb arg1, void* arg2) {
- return MOCK_HOOK_P3(PkgmgrInfoMock, pkgmgrinfo_appinfo_foreach_appcontrol,
- arg0, arg1, arg2);
-}
-
-extern "C" int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h arg0,
- char **arg1) {
- return MOCK_HOOK_P2(PkgmgrInfoMock, pkgmgrinfo_pkginfo_get_version,
- arg0, arg1);
-}
-
-extern "C" int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h arg0,
- pkgmgrinfo_app_component arg1, pkgmgrinfo_app_list_cb arg2, void* arg3,
- uid_t arg4) {
- return MOCK_HOOK_P5(PkgmgrInfoMock, pkgmgrinfo_appinfo_get_usr_list, arg0,
- arg1, arg2, arg3, arg4);
-}
-
-extern "C" int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char* arg0, uid_t arg1,
- pkgmgrinfo_pkginfo_h* arg2) {
- return MOCK_HOOK_P3(PkgmgrInfoMock, pkgmgrinfo_pkginfo_get_usr_pkginfo, arg0,
- arg1, arg2);
-}
-
-extern "C" pkgmgr_client* pkgmgr_client_new(pkgmgr_client_type arg0) {
- return MOCK_HOOK_P1(PkgmgrInfoMock, pkgmgr_client_new, arg0);
-}
-
-extern "C" int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_pkginfo_h arg0,
- char** arg1) {
- return MOCK_HOOK_P2(PkgmgrInfoMock, pkgmgrinfo_appinfo_get_pkgid, arg0,
- arg1);
-}
-
-extern "C" int pkgmgr_client_listen_status(pkgmgr_client* arg0,
- pkgmgr_handler arg1, void* arg2) {
- return MOCK_HOOK_P3(PkgmgrInfoMock, pkgmgr_client_listen_status, arg0, arg1,
- arg2);
-}
-
-extern "C" int pkgmgrinfo_appinfo_destroy_appinfo(
- pkgmgrinfo_appinfo_h arg0) {
- return MOCK_HOOK_P1(PkgmgrInfoMock, pkgmgrinfo_appinfo_destroy_appinfo,
- arg0);
-}
-
-extern "C" int pkgmgrinfo_appinfo_get_usr_appinfo(const char* arg0, uid_t arg1,
- pkgmgrinfo_appinfo_h* arg2) {
- return MOCK_HOOK_P3(PkgmgrInfoMock, pkgmgrinfo_appinfo_get_usr_appinfo, arg0,
- arg1, arg2);
-}
-
+++ /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 MOCK_PKGMGR_INFO_MOCK_H_
-#define MOCK_PKGMGR_INFO_MOCK_H_
-
-#include <pkgmgr-info.h>
-#include <package-manager.h>
-#include <gmock/gmock.h>
-
-#include "module_mock.h"
-
-class PkgmgrInfoMock : public virtual ModuleMock {
- public:
- virtual ~PkgmgrInfoMock() {}
-
- MOCK_METHOD1(pkgmgr_client_free, int (pkgmgr_client*));
- MOCK_METHOD2(pkgmgrinfo_appinfo_get_appid, int (pkgmgrinfo_appinfo_h,
- char**));
- MOCK_METHOD1(pkgmgrinfo_pkginfo_destroy_pkginfo,
- int (pkgmgrinfo_pkginfo_h));
- MOCK_METHOD4(pkgmgrinfo_pkginfo_compare_usr_app_cert_info, int (const char*,
- const char*, uid_t, pkgmgrinfo_cert_compare_result_type_e*));
- MOCK_METHOD3(pkgmgrinfo_appinfo_foreach_appcontrol, int (
- pkgmgrinfo_appinfo_h , pkgmgrinfo_app_control_list_cb, void*));
- MOCK_METHOD2(pkgmgrinfo_pkginfo_get_version, int (pkgmgrinfo_pkginfo_h,
- char**));
- MOCK_METHOD5(pkgmgrinfo_appinfo_get_usr_list, int (pkgmgrinfo_pkginfo_h,
- pkgmgrinfo_app_component, pkgmgrinfo_app_list_cb, void*, uid_t));
- MOCK_METHOD3(pkgmgrinfo_pkginfo_get_usr_pkginfo,
- int (const char *, uid_t, pkgmgrinfo_pkginfo_h*));
- MOCK_METHOD1(pkgmgr_client_new, pkgmgr_client* (pkgmgr_client_type));
- MOCK_METHOD2(pkgmgrinfo_appinfo_get_pkgid,
- int (pkgmgrinfo_pkginfo_h, char **));
- MOCK_METHOD3(pkgmgr_client_listen_status, int (pkgmgr_client*,
- pkgmgr_handler, void*));
- MOCK_METHOD1(pkgmgrinfo_appinfo_destroy_appinfo,
- int (pkgmgrinfo_appinfo_h));
- MOCK_METHOD3(pkgmgrinfo_appinfo_get_usr_appinfo,
- int (const char *, uid_t, pkgmgrinfo_appinfo_h*));
-};
-
-#endif // MOCK_PKMGR_INFO_MOCK_H_
\ No newline at end of file
+++ /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 "security_manager_mock.h"
-#include "mock_hook.h"
-#include "test_fixture.h"
-
-extern "C" int security_manager_app_has_privilege(const char* arg0,
- const char* arg1, uid_t arg2, int* arg3) {
- return MOCK_HOOK_P4(SecurityManagerMock, security_manager_app_has_privilege,
- arg0, arg1, arg2, arg3);
-}
\ No newline at end of file
+++ /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 MOCK_SECURITY_MANAGER_MOCK_H_
-#define MOCK_SECURITY_MANAGER_MOCK_H_
-
-#include <security-manager.h>
-#include <gmock/gmock.h>
-
-#include "module_mock.h"
-
-class SecurityManagerMock : public virtual ModuleMock {
- public:
- virtual ~SecurityManagerMock() {}
-
- MOCK_METHOD4(security_manager_app_has_privilege, int (const char*,
- const char*, uid_t, int*));
-};
-
-#endif // MOCK_SECURITY_MANAGER_MOCK_H_
\ No newline at end of file
+++ /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 "test_fixture.h"
-
-#include <memory>
-
-std::unique_ptr<ModuleMock> TestFixture::mock_;
+++ /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 MOCK_TEST_FIXTURE_H_
-#define MOCK_TEST_FIXTURE_H_
-
-#include <gtest/gtest.h>
-
-#include <memory>
-#include <stdexcept>
-#include <string>
-#include <utility>
-
-#include "module_mock.h"
-
-class TestFixture : public ::testing::Test {
- public:
- explicit TestFixture(std::unique_ptr<ModuleMock>&& mock) {
- mock_ = std::move(mock);
- }
- virtual ~TestFixture() {
- mock_.reset();
- }
-
- virtual void SetUp() {}
- virtual void TearDown() {}
-
- template <typename T>
- static T& GetMock() {
- auto ptr = dynamic_cast<T*>(mock_.get());
- return *ptr;
- }
-
- static std::unique_ptr<ModuleMock> mock_;
-};
-
-#endif // MOCK_TEST_FIXTURE_H_
+++ /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 "tzplatform_config_mock.h"
-
-#include "mock_hook.h"
-#include "test_fixture.h"
-
-extern "C" const char* tzplatform_mkpath(enum tzplatform_variable arg1, const char* arg2) {
- return MOCK_HOOK_P2(TzplatformConfigMock, tzplatform_mkpath, arg1, arg2);
-}
\ No newline at end of file
+++ /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 UNIT_TESTS_MOCK_TZPLATFORM_CONFIG_MOCK_H_
-#define UNIT_TESTS_MOCK_TZPLATFORM_CONFIG_MOCK_H_
-
-#include <tzplatform_config.h>
-#include <gmock/gmock.h>
-
-#include "module_mock.h"
-
-class TzplatformConfigMock : public virtual ModuleMock {
- public:
- virtual ~TzplatformConfigMock() {}
-
- MOCK_METHOD2(tzplatform_mkpath, const char* (enum tzplatform_variable,
- const char*));
-};
-
-#endif // UNIT_TESTS_MOCK_TZPLATFORM_CONFIG_MOCK_H_
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2023 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 "vconf_mock.h"
-#include "mock_hook.h"
-#include "test_fixture.h"
-
-extern "C" int vconf_get_int(const char* arg0, int* arg1) {
- return MOCK_HOOK_P2(VconfMock, vconf_get_int, arg0, arg1);
-}
-
-extern "C" int vconf_get_bool(const char* arg0, int* arg1) {
- return MOCK_HOOK_P2(VconfMock, vconf_get_bool, arg0, arg1);
-}
-
-extern "C" int vconf_notify_key_changed(const char* arg0,
- vconf_callback_fn arg1, void* arg2) {
- return MOCK_HOOK_P3(VconfMock, vconf_notify_key_changed, arg0, arg1, arg2);
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2023 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 MOCK_VCONF_MOCK_H_
-#define MOCK_VCONF_MOCK_H_
-
-#include <vconf.h>
-#include <gmock/gmock.h>
-
-#include "module_mock.h"
-
-class VconfMock : public virtual ModuleMock {
- public:
- virtual ~VconfMock() {}
-
- MOCK_METHOD2(vconf_get_int, int (const char*, int*));
- MOCK_METHOD2(vconf_get_bool, int (const char*, int*));
- MOCK_METHOD3(vconf_notify_key_changed, int (const char*,
- vconf_callback_fn, void*));
-};
-
-#endif // MOCK_VCONF_MOCK_H_
\ No newline at end of file