From 6540dd872d2f89cf11e6aeeabfd685c7ffe9692e Mon Sep 17 00:00:00 2001 From: Mayank Haarit Date: Thu, 14 Mar 2019 20:59:33 +0530 Subject: [PATCH 01/16] Remove VD_REQ for power plugin related part Change-Id: I22c77430f9c3b01aee1eb92c82a28c74d2ec5664 Signed-off-by: Mayank Haarit --- packaging/ua-manager.spec | 3 --- ua-daemon/CMakeLists.txt | 7 ++----- ua-daemon/include/ua-manager-common.h | 2 -- ua-daemon/src/ua-manager-core.c | 4 ---- 4 files changed, 2 insertions(+), 14 deletions(-) diff --git a/packaging/ua-manager.spec b/packaging/ua-manager.spec index 804937a..2ec5190 100644 --- a/packaging/ua-manager.spec +++ b/packaging/ua-manager.spec @@ -49,9 +49,6 @@ cp -a %{SOURCE3} . cp %{SOURCE1001} . %build -%if 0%{?vd_req:1} -export CFLAGS="$CFLAGS -DVD_REQ" -%endif MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} \ diff --git a/ua-daemon/CMakeLists.txt b/ua-daemon/CMakeLists.txt index cc833a8..f957f4f 100644 --- a/ua-daemon/CMakeLists.txt +++ b/ua-daemon/CMakeLists.txt @@ -20,13 +20,10 @@ SET(SRCS src/pm/ua-light-plugin-handler.c src/pm/ua-motion-plugin-handler.c src/pm/ua-cloud-plugin-handler.c + src/pm/ua-power-plugin-manager.c + src/pm/ua-power-plugin-handler.c ) -IF("$ENV{CFLAGS}" MATCHES "-DVD_REQ") - LIST(APPEND SRCS src/pm/ua-power-plugin-manager.c) - LIST(APPEND SRCS src/pm/ua-power-plugin-handler.c) -ENDIF() - IF("${CMAKE_BUILD_TYPE}" STREQUAL "") SET(CMAKE_BUILD_TYPE "Release") ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "") diff --git a/ua-daemon/include/ua-manager-common.h b/ua-daemon/include/ua-manager-common.h index 2e30d4b..0f32d21 100644 --- a/ua-daemon/include/ua-manager-common.h +++ b/ua-daemon/include/ua-manager-common.h @@ -55,9 +55,7 @@ extern "C" { #define FUNC_EXIT UAM_DBG("-") #define SENSOR_PLUGIN_DIR tzplatform_mkpath(TZ_SYS_GLOBALUSER_DATA, "network/ua/lib/sensor") -#ifdef VD_REQ #define POWER_PLUGIN_DIR tzplatform_mkpath(TZ_SYS_GLOBALUSER_DATA, "network/ua/lib/power") -#endif #define CLOUD_PLUGIN_DIR tzplatform_mkpath(TZ_SYS_GLOBALUSER_DATA, "network/ua/lib/cloud") #define UAM_VERSION "0.1" diff --git a/ua-daemon/src/ua-manager-core.c b/ua-daemon/src/ua-manager-core.c index 8e25ace..5b1a096 100644 --- a/ua-daemon/src/ua-manager-core.c +++ b/ua-daemon/src/ua-manager-core.c @@ -26,9 +26,7 @@ #include "ua-manager-config-parser.h" #include "ua-cloud-plugin-handler.h" -#ifdef VD_REQ #include "ua-power-plugin-manager.h" -#endif #define UAM_MAX_USERS 255 #define USER_ACCOUNT_DEFAULT "default@default.com" @@ -1645,9 +1643,7 @@ void _uam_core_handle_presence_detected(unsigned int sensor, UAM_INFO("sensor: 0x%8.8X, user_id: %d", sensor, user_id); -#ifdef VD_REQ _uam_ppm_send_presence_detection_event(sensor); -#endif if (NULL == dev_info) { _uam_manager_send_event(NULL, UAM_EVENT_PRESENCE_DETECTED, -- 2.7.4 From da289ee0615fe743443ff1c40b51b381f2578460 Mon Sep 17 00:00:00 2001 From: Atul Rai Date: Wed, 20 Mar 2019 16:39:11 +0530 Subject: [PATCH 02/16] Aligned OS type across all interface headers Change-Id: I2d6d44358f350e42d4846709c25a3441454adc04 Signed-off-by: Atul Rai --- include/ua-api.h | 5 +++-- ua-plugins/include/ua-plugin-type.h | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/ua-api.h b/include/ua-api.h index 9621b8e..12c0127 100644 --- a/include/ua-api.h +++ b/include/ua-api.h @@ -117,9 +117,10 @@ typedef enum { } uam_presence_state_e; typedef enum { - UAM_OS_TYPE_ANDROID = 0x00, - UAM_OS_TYPE_IOS, + UAM_OS_TYPE_UNDEFINED = 0x00, UAM_OS_TYPE_TIZEN, + UAM_OS_TYPE_ANDROID, + UAM_OS_TYPE_IOS, UAM_OS_TYPE_INVALID } uam_os_type_e; diff --git a/ua-plugins/include/ua-plugin-type.h b/ua-plugins/include/ua-plugin-type.h index d2c9d75..e91972b 100644 --- a/ua-plugins/include/ua-plugin-type.h +++ b/ua-plugins/include/ua-plugin-type.h @@ -29,9 +29,10 @@ extern "C" { #define UAP_IP_ADDRESS_MAX_STRING_LEN 50 typedef enum { - UAP_OS_TYPE_ANDROID = 0x00, - UAP_OS_TYPE_IOS, + UAP_OS_TYPE_UNDEFINED = 0x00, UAP_OS_TYPE_TIZEN, + UAP_OS_TYPE_ANDROID, + UAP_OS_TYPE_IOS, UAP_OS_TYPE_INVALID } uap_os_type_e; -- 2.7.4 From c7f8a7deb22fd212d97810bb492384daf7d88d42 Mon Sep 17 00:00:00 2001 From: Atul Rai Date: Wed, 20 Mar 2019 16:42:40 +0530 Subject: [PATCH 03/16] Handle NULL account in add_device_cb from cloud plugin Change-Id: Iebf37b1d4029d23f795f02d27d60ffe349bbcd92 Signed-off-by: Atul Rai --- ua-daemon/src/pm/ua-cloud-plugin-handler.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ua-daemon/src/pm/ua-cloud-plugin-handler.c b/ua-daemon/src/pm/ua-cloud-plugin-handler.c index 2d45b6e..1a98b54 100644 --- a/ua-daemon/src/pm/ua-cloud-plugin-handler.c +++ b/ua-daemon/src/pm/ua-cloud-plugin-handler.c @@ -97,8 +97,17 @@ static int add_device(const char *account, uap_device_info_t *dev_info) { FUNC_ENTRY; uam_device_info_t device; + uam_user_info_t user; + + if (NULL == account) { + if (UAM_ERROR_NONE != _uam_core_get_default_user(&user)) { + UAM_ERR("_uam_core_get_default_user failed"); + return UAP_STATUS_FAIL; + } + + account = user.account; + } - retv_if(NULL == account, UAP_STATUS_INVALID_PARAMS); retv_if(NULL == dev_info, UAP_STATUS_INVALID_PARAMS); memset(&device, 0x00, sizeof(uam_device_info_t)); -- 2.7.4 From ee816d515075aeee20bb72b69ca3023507b7bc82 Mon Sep 17 00:00:00 2001 From: Atul Rai Date: Tue, 26 Mar 2019 10:23:04 +0530 Subject: [PATCH 04/16] Added support for GET/SET detection parameters Change-Id: I7c8d3448fc31fbc7bed714240585a1bb043b04b6 Signed-off-by: Atul Rai --- include/ua-api.h | 10 +++++ include/ua-internal.h | 2 + packaging/ua-manager.spec | 4 +- ua-api/src/ua-api.c | 54 ++++++++++++++++++++++++ ua-daemon/include/ua-manager-config-parser.h | 2 + ua-daemon/include/ua-manager-core.h | 5 ++- ua-daemon/src/ua-manager-config-parser.c | 59 ++++++++++++++++++++++++++ ua-daemon/src/ua-manager-core.c | 62 ++++++++++++++++++++++++---- ua-daemon/src/ua-manager-request-handler.c | 22 ++++++++++ 9 files changed, 209 insertions(+), 11 deletions(-) diff --git a/include/ua-api.h b/include/ua-api.h index 12c0127..7b1245b 100644 --- a/include/ua-api.h +++ b/include/ua-api.h @@ -155,6 +155,12 @@ typedef struct { char name[UAM_USER_NAME_MAX_STRING_LEN]; } uam_user_event_data_t; +typedef struct { + int cycle; + int period; + int retries; +} uam_detection_params_t; + int _uam_get_registered_users(GPtrArray **user_list); int _uam_is_device_registered( @@ -202,6 +208,10 @@ int _uam_enable_low_power_mode(void); int _uam_disable_low_power_mode(void); +int _uam_get_detection_params(int *cycle, int *period, int *retries); + +int _uam_set_detection_params(int cycle, int period, int retries); + #ifdef __cplusplus } #endif diff --git a/include/ua-internal.h b/include/ua-internal.h index dfb3966..fd6c8d9 100644 --- a/include/ua-internal.h +++ b/include/ua-internal.h @@ -57,6 +57,8 @@ extern "C" { REQUEST(UAM_REQUEST_START_ABSENCE_DETECTION) \ REQUEST(UAM_REQUEST_STOP_ABSENCE_DETECTION) \ REQUEST(UAM_REQUEST_SET_LOW_POWER_MODE) \ + REQUEST(UAM_REQUEST_GET_DETECTION_PARAMS) \ + REQUEST(UAM_REQUEST_SET_DETECTION_PARAMS) \ REQUEST(UAM_REQUEST_MAX) #define GENERATE_REQUEST_ENUM(ENUM) ENUM, diff --git a/packaging/ua-manager.spec b/packaging/ua-manager.spec index 2ec5190..38c9cbc 100644 --- a/packaging/ua-manager.spec +++ b/packaging/ua-manager.spec @@ -68,7 +68,7 @@ sqlite3 %{buildroot}%{database_full_path} < %{buildroot}/usr/share/ua_db.sql rm %{buildroot}/usr/share/ua_db.sql mkdir -p %{buildroot}/opt/usr/data/ua -install -m 0644 config/uam-config.json %{buildroot}%{config_file_path}/uam-config.json +cp config/uam-config.json %{buildroot}%{config_file_path}/uam-config.json mkdir -p %{buildroot}%{_sysconfdir}/dbus-1/system.d cp ua-manager.conf %{buildroot}%{_sysconfdir}/dbus-1/system.d/ua-manager.conf @@ -90,7 +90,7 @@ cp ua-manager.service %{buildroot}%{_unitdir}/ua-manager.service %config %{_sysconfdir}/dbus-1/system.d/ua-manager.conf %attr(644,root,root) %{_datadir}/dbus-1/system-services/* %attr(644,root,root) %{_unitdir}/ua-manager.service -%{config_file_path}/uam-config.json +%config %attr(660, network_fw, network_fw) %{config_file_path}/uam-config.json %config %attr(660, network_fw, network_fw) %{database_full_path} %config %attr(660, network_fw, network_fw) %{database_full_path}-journal diff --git a/ua-api/src/ua-api.c b/ua-api/src/ua-api.c index 1f71b25..d9b2621 100644 --- a/ua-api/src/ua-api.c +++ b/ua-api/src/ua-api.c @@ -718,3 +718,57 @@ UAM_EXPORT_API int _uam_disable_low_power_mode(void) FUNC_EXIT; return ret; } + +UAM_EXPORT_API int _uam_get_detection_params(int *cycle, int *period, int *retries) +{ + FUNC_ENTRY; + int ret; + + UAM_VALIDATE_INPUT_PARAMETER(cycle); + UAM_VALIDATE_INPUT_PARAMETER(period); + UAM_VALIDATE_INPUT_PARAMETER(retries); + + UAM_INIT_PARAMS(); + UAM_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + ret = _uam_sync_request(UAM_REQUEST_GET_DETECTION_PARAMS, + in_param1, in_param2, in_param3, in_param4, &out_param); + if (UAM_ERROR_NONE == ret) { + uam_detection_params_t *detection_param; + + detection_param = &g_array_index(out_param, uam_detection_params_t, 0); + *cycle = detection_param->cycle; + *period = detection_param->period; + *retries = detection_param->retries; + UAM_INFO("Detection Params: cycle = %d, period = %d, retries = %d", + *cycle, *period, *retries); + } + + UAM_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + FUNC_EXIT; + return ret; +} + +UAM_EXPORT_API int _uam_set_detection_params(int cycle, int period, int retries) +{ + FUNC_ENTRY; + int ret; + uam_detection_params_t detection_param; + + detection_param.cycle = cycle; + detection_param.period = period; + detection_param.retries = retries; + + UAM_INIT_PARAMS(); + UAM_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + g_array_append_vals(in_param1, &detection_param, sizeof(uam_detection_params_t)); + ret = _uam_sync_request(UAM_REQUEST_SET_DETECTION_PARAMS, + in_param1, in_param2, in_param3, in_param4, &out_param); + + UAM_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + FUNC_EXIT; + return ret; +} diff --git a/ua-daemon/include/ua-manager-config-parser.h b/ua-daemon/include/ua-manager-config-parser.h index 231c096..5be98ab 100644 --- a/ua-daemon/include/ua-manager-config-parser.h +++ b/ua-daemon/include/ua-manager-config-parser.h @@ -24,6 +24,8 @@ extern "C" { int _uam_read_detection_params(int *cycle, int *period, int *retries); +int _uam_write_detection_params(int cycle, int period, int retries); + #ifdef __cplusplus } #endif diff --git a/ua-daemon/include/ua-manager-core.h b/ua-daemon/include/ua-manager-core.h index b1e168e..1ee5e31 100644 --- a/ua-daemon/include/ua-manager-core.h +++ b/ua-daemon/include/ua-manager-core.h @@ -120,8 +120,9 @@ int _uam_core_stop_absence_detection(char *sender, unsigned int sensors); int _uam_core_set_low_power_mode(gboolean mode); -int _uam_core_set_detection_parameters(unsigned int sensor, - int cycle, int period, int retries); +int _uam_core_get_detection_parameters(int *cycle, int *period, int *retries); + +int _uam_core_set_detection_parameters(int cycle, int period, int retries); int _uam_core_init(void); diff --git a/ua-daemon/src/ua-manager-config-parser.c b/ua-daemon/src/ua-manager-config-parser.c index 63fbc7b..77e8010 100644 --- a/ua-daemon/src/ua-manager-config-parser.c +++ b/ua-daemon/src/ua-manager-config-parser.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include "ua-internal.h" @@ -98,3 +99,61 @@ done: FUNC_EXIT; return ret; } + +int _uam_write_detection_params(int cycle, int period, int retries) +{ + FUNC_ENTRY; + int ret = UAM_ERROR_INTERNAL; + FILE *conf_file; + char *contents; + const char *out_content; + json_object *jmain; + json_object *jdparams; + json_object *jint; + + contents = __uam_get_file_content(UAM_CONFIG_FILE); + retv_if(NULL == contents, UAM_ERROR_INTERNAL); + + jmain = json_tokener_parse(contents); + if (!jmain) + goto done; + + /* Detection Parameters */ + json_object_object_get_ex(jmain, "DetectionParams", &jdparams); + if (!jdparams) + goto done; + + json_object_object_del(jdparams, "Cycle"); + jint = json_object_new_int(cycle); + json_object_object_add(jdparams, "Cycle", jint); + + json_object_object_del(jdparams, "Period"); + jint = json_object_new_int(period); + json_object_object_add(jdparams, "Period", jint); + + json_object_object_del(jdparams, "Retries"); + jint = json_object_new_int(retries); + json_object_object_add(jdparams, "Retries", jint); + + conf_file = fopen(UAM_CONFIG_FILE, "wr"); + if (!conf_file) { + char err_str[100]; + + strerror_r(errno, err_str, 100); + UAM_ERR("Failed to open file %s with error %s(%d)", + UAM_CONFIG_FILE, err_str, errno); + goto done; + } + + out_content = json_object_to_json_string_ext(jmain, JSON_C_TO_STRING_PRETTY); + fwrite(out_content, sizeof(char), strlen(out_content), conf_file); + fclose(conf_file); + ret = UAM_ERROR_NONE; +done: + g_free(contents); + if (jmain) + json_object_put(jmain); + + FUNC_EXIT; + return ret; +} diff --git a/ua-daemon/src/ua-manager-core.c b/ua-daemon/src/ua-manager-core.c index 5b1a096..b343b6d 100644 --- a/ua-daemon/src/ua-manager-core.c +++ b/ua-daemon/src/ua-manager-core.c @@ -1222,8 +1222,8 @@ static int __uam_core_start_detection(int detection_type, char *sender, unsigned { FUNC_ENTRY; int ret; - int active_sensors; - int inactive_sensors; + unsigned int active_sensors; + unsigned int inactive_sensors; uam_monitor_info_t *monitor; retv_if(NULL == sender, UAM_ERROR_INVALID_PARAM); @@ -1379,21 +1379,70 @@ int _uam_core_set_low_power_mode(gboolean mode) return UAM_ERROR_NONE; } -int _uam_core_set_detection_parameters(unsigned int sensor, - int cycle, int period, int retries) +int _uam_core_get_detection_parameters(int *cycle, int *period, int *retries) { FUNC_ENTRY; int ret; + retv_if(NULL == cycle, UAM_ERROR_INVALID_PARAM); + retv_if(NULL == period, UAM_ERROR_INVALID_PARAM); + retv_if(NULL == retries, UAM_ERROR_INVALID_PARAM); + + /* Read configuration */ + ret = _uam_read_detection_params(cycle, period, retries); + if (UAM_ERROR_NONE == ret) + UAM_INFO_C("Detection Params: [cycle = %d], [period = %d], " + "[retries = %d]", *cycle, *period, *retries); + + FUNC_EXIT; + return ret; +} + +int _uam_core_set_detection_parameters(int cycle, int period, int retries) +{ + FUNC_ENTRY; + int ret; + unsigned int presence_sensors; + unsigned int absence_sensors; + retv_if(cycle <= period, UAM_ERROR_INVALID_PARAM); - ret = _uam_pm_set_detection_params(sensor, cycle, period, retries); + /* Find sensors which are already monitoring and stop monitoring */ + presence_sensors = _uam_core_get_active_sensors(UAM_DETECT_PRESENCE); + UAM_DBG("UAM_DETECT_PRESENCE active_sensors: 0x%8.8X", presence_sensors); + if (0 != presence_sensors) + if (UAM_ERROR_NONE != _uam_pm_stop_detection( + UAM_DETECT_PRESENCE, presence_sensors)) + UAM_WARN("_uam_pm_stop_detection failed"); + + absence_sensors = _uam_core_get_active_sensors(UAM_DETECT_ABSENCE); + UAM_DBG("UAM_DETECT_ABSENCE active_sensors: 0x%8.8X", absence_sensors); + if (0 != absence_sensors) + if (UAM_ERROR_NONE != _uam_pm_stop_detection( + UAM_DETECT_ABSENCE, absence_sensors)) + UAM_WARN("_uam_pm_stop_detection failed"); + + ret = _uam_pm_set_detection_params(UAM_SENSOR_ALL, cycle, period, retries); if (UAM_ERROR_NONE != ret) { UAM_ERR("_uam_pm_set_detection_params failed with %s", _uam_manager_error_to_str(ret)); return ret; } + if (0 != presence_sensors) + if (UAM_ERROR_NONE != _uam_pm_start_detection( + UAM_DETECT_PRESENCE, presence_sensors)) + UAM_WARN("_uam_pm_start_detection failed"); + + if (0 != absence_sensors) + if (UAM_ERROR_NONE != _uam_pm_start_detection( + UAM_DETECT_ABSENCE, absence_sensors)) + UAM_WARN("_uam_pm_start_detection failed"); + + /* Update conf file */ + if (UAM_ERROR_NONE != _uam_write_detection_params(cycle, period, retries)) + UAM_WARN("_uam_write_detection_params failed"); + FUNC_EXIT; return UAM_ERROR_NONE; } @@ -1413,8 +1462,7 @@ int _uam_core_init(void) &cycle, &period, &retries)) { UAM_INFO_C("Detection Params: [cycle = %d], [period = %d], " "[retries = %d]", cycle, period, retries); - _uam_core_set_detection_parameters( - UAM_SENSOR_ALL, cycle, period, retries); + _uam_core_set_detection_parameters(cycle, period, retries); } /* Init database */ diff --git a/ua-daemon/src/ua-manager-request-handler.c b/ua-daemon/src/ua-manager-request-handler.c index f7e1860..5e775b1 100644 --- a/ua-daemon/src/ua-manager-request-handler.c +++ b/ua-daemon/src/ua-manager-request-handler.c @@ -370,6 +370,26 @@ static int __uam_manager_sync_request_handler( result = _uam_core_set_low_power_mode(mode); break; } + case UAM_REQUEST_GET_DETECTION_PARAMS: { + uam_detection_params_t detection_param; + + result = _uam_core_get_detection_parameters(&detection_param.cycle, + &detection_param.period, &detection_param.retries); + if (UAM_ERROR_NONE == result) + g_array_append_vals(*out_param1, + &detection_param, sizeof(uam_detection_params_t)); + break; + } + case UAM_REQUEST_SET_DETECTION_PARAMS: { + uam_detection_params_t detection_param; + + __uam_manager_copy_params(in_param1, + &detection_param, sizeof(uam_detection_params_t)); + + result = _uam_core_set_detection_parameters(detection_param.cycle, + detection_param.period, detection_param.retries); + break; + } default: UAM_WARN("UnSupported function [%s(0x%4.4X)]", _uam_manager_request_to_str(function), function); @@ -499,6 +519,8 @@ static gboolean __uam_manager_is_sync_function(int function) case UAM_REQUEST_START_ABSENCE_DETECTION: case UAM_REQUEST_STOP_ABSENCE_DETECTION: case UAM_REQUEST_SET_LOW_POWER_MODE: + case UAM_REQUEST_GET_DETECTION_PARAMS: + case UAM_REQUEST_SET_DETECTION_PARAMS: return TRUE; default: return FALSE; -- 2.7.4 From a81ffba108946c662074d37c732ef125561090f0 Mon Sep 17 00:00:00 2001 From: Jihoon Jung Date: Wed, 3 Apr 2019 13:32:55 +0900 Subject: [PATCH 05/16] Fix Svace issue : access memory after free Change-Id: I7cd057b2b6956161a34d2033878c52e05e1267e3 Signed-off-by: Jihoon Jung --- ua-daemon/src/pm/ua-power-plugin-manager.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ua-daemon/src/pm/ua-power-plugin-manager.c b/ua-daemon/src/pm/ua-power-plugin-manager.c index d1fd091..7b33e96 100644 --- a/ua-daemon/src/pm/ua-power-plugin-manager.c +++ b/ua-daemon/src/pm/ua-power-plugin-manager.c @@ -112,12 +112,14 @@ static int __load_power_plugin(const char *path, const char *name, const char *s UAM_DBG("Loading [%s]", filename); handle = dlopen(filename, RTLD_NOW); - g_free(filename); if (handle == NULL) { UAM_ERR("Can't load plugin %s: %s", filename, dlerror()); + g_free(filename); return UAM_ERROR_INTERNAL; } + g_free(filename); + module = (uap_module_t *)dlsym(handle, symbol); if (module == NULL) { UAM_ERR("Can't load power plugin module: %s", dlerror()); -- 2.7.4 From c3f3c30dd5b4676ab7cdb7dceba10cec7fa7249e Mon Sep 17 00:00:00 2001 From: Atul Rai Date: Wed, 3 Apr 2019 12:53:06 +0530 Subject: [PATCH 06/16] Fixed invalid memory access [SVACE ID: 414657] Change-Id: I98e5a6528da2c60916216b814ce4ca0fb146994b Signed-off-by: Atul Rai --- ua-daemon/src/pm/ua-power-plugin-manager.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ua-daemon/src/pm/ua-power-plugin-manager.c b/ua-daemon/src/pm/ua-power-plugin-manager.c index 7b33e96..e65cac0 100644 --- a/ua-daemon/src/pm/ua-power-plugin-manager.c +++ b/ua-daemon/src/pm/ua-power-plugin-manager.c @@ -112,14 +112,12 @@ static int __load_power_plugin(const char *path, const char *name, const char *s UAM_DBG("Loading [%s]", filename); handle = dlopen(filename, RTLD_NOW); + g_free(filename); if (handle == NULL) { - UAM_ERR("Can't load plugin %s: %s", filename, dlerror()); - g_free(filename); + UAM_ERR("Can't load plugin [Error: %s]", dlerror()); return UAM_ERROR_INTERNAL; } - g_free(filename); - module = (uap_module_t *)dlsym(handle, symbol); if (module == NULL) { UAM_ERR("Can't load power plugin module: %s", dlerror()); -- 2.7.4 From fa80109e0cc7bed516c73ecac68ce52ebe78b478 Mon Sep 17 00:00:00 2001 From: "saerome.kim" Date: Wed, 17 Apr 2019 14:50:11 +0900 Subject: [PATCH 07/16] Add dbus policy rule. - Allowed 'users' can access net.uamd/net.uamd.enabler dbus objects. Change-Id: Id11ed40ac918c2329b6a36bb96decb1585a2a4e9 Signed-off-by: saerome.kim --- packaging/ua-manager.conf | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packaging/ua-manager.conf b/packaging/ua-manager.conf index 0cde71b..5206e65 100644 --- a/packaging/ua-manager.conf +++ b/packaging/ua-manager.conf @@ -14,6 +14,10 @@ + + + + -- 2.7.4 From 53a3f531dada64bf0bdb26bb24f6925f9a30c972 Mon Sep 17 00:00:00 2001 From: "saerome.kim" Date: Thu, 18 Apr 2019 20:10:07 +0900 Subject: [PATCH 08/16] Fixed crash when UTC with Wi-Fi dummy plugin. Added error code UAM_ERROR_NOT_INITIALIZED Change-Id: I42542f5281a31a4d5f78b40e6b949cb90be4456d Signed-off-by: saerome.kim --- include/ua-api.h | 3 +- ua-api/src/ua-common.c | 1 + ua-api/src/ua-event-handler.c | 2 ++ ua-api/src/ua-request-sender.c | 19 ++++++------ ua-daemon/include/ua-manager-common.h | 2 ++ ua-daemon/src/ua-manager-request-handler.c | 46 +++++++++++++++++------------- 6 files changed, 44 insertions(+), 29 deletions(-) diff --git a/include/ua-api.h b/include/ua-api.h index 7b1245b..1f53432 100644 --- a/include/ua-api.h +++ b/include/ua-api.h @@ -72,13 +72,14 @@ typedef enum { ERROR(UAM_ERROR_TIMEOUT, TIZEN_ERROR_TIMED_OUT) \ ERROR(UAM_ERROR_NOW_IN_PROGRESS, TIZEN_ERROR_NOW_IN_PROGRESS) \ ERROR(UAM_ERROR_NOT_SUPPORTED, TIZEN_ERROR_NOT_SUPPORTED) \ - ERROR(UAM_ERROR_NOT_REGISTERED, TIZEN_ERROR_UA | 0x01) \ + ERROR(UAM_ERROR_NOT_INITIALIZED, TIZEN_ERROR_UA | 0x01) \ ERROR(UAM_ERROR_NOT_IN_OPERATION, TIZEN_ERROR_UA | 0x02) \ ERROR(UAM_ERROR_ALREADY_DONE, TIZEN_ERROR_UA | 0x03) \ ERROR(UAM_ERROR_INTERNAL, TIZEN_ERROR_UA | 0x04) \ ERROR(UAM_ERROR_NOT_FOUND, TIZEN_ERROR_UA | 0x10) \ ERROR(UAM_ERROR_ALREADY_REGISTERED, TIZEN_ERROR_UA | 0x11) \ ERROR(UAM_ERROR_DB_FAILED, TIZEN_ERROR_UA | 0x12) \ + ERROR(UAM_ERROR_NOT_REGISTERED, TIZEN_ERROR_UA | 0x13) \ #define GENERATE_ERROR_ENUM(ENUM, offset) ENUM = -offset, #define GENERATE_ERROR_STRING(STRING, offset) #STRING, diff --git a/ua-api/src/ua-common.c b/ua-api/src/ua-common.c index 65dd5be..d86197c 100644 --- a/ua-api/src/ua-common.c +++ b/ua-api/src/ua-common.c @@ -108,6 +108,7 @@ const char *_uam_error_to_str(int error) int err_id = -error; UAM_DBG("arr_size: %d, err_id: %d", arr_size, err_id); + retv_if(0 > err_id, NULL); retv_if(arr_size <= err_id, NULL); return error_string[err_id]; diff --git a/ua-api/src/ua-event-handler.c b/ua-api/src/ua-event-handler.c index 9a4af61..369d25a 100644 --- a/ua-api/src/ua-event-handler.c +++ b/ua-api/src/ua-event-handler.c @@ -274,7 +274,9 @@ int _uam_unregister_event_handler(void) retv_if(NULL == conn, UAM_ERROR_INTERNAL); g_dbus_connection_signal_unsubscribe(conn, event_handler_data->id); + memset(event_handler_data, 0, sizeof(uam_event_handler_data_t)); g_free(event_handler_data); + event_handler_data = NULL; FUNC_EXIT; return UAM_ERROR_NONE; diff --git a/ua-api/src/ua-request-sender.c b/ua-api/src/ua-request-sender.c index 940c1a8..312accf 100644 --- a/ua-api/src/ua-request-sender.c +++ b/ua-api/src/ua-request-sender.c @@ -285,24 +285,27 @@ static void __uam_async_request_cb( goto done; } - UAM_INFO("Event: %s [0x%4.4X], result= %s [0x%4.4X]", - _uam_event_to_str(event), event, - _uam_error_to_str(result), result); + UAM_INFO("result= %s [0x%4.4X]", _uam_error_to_str(result), result); event_data.result = result; - __uam_get_event_info(req_info->req_func, out_param, - &event, &event_data.data); - ((uam_event_callback)req_info->cb)( - event, &event_data, req_info->user_data); + if (req_info && req_info->req_func) { + __uam_get_event_info(req_info->req_func, out_param, + &event, &event_data.data); + + ((uam_event_callback)req_info->cb)( + event, &event_data, req_info->user_data); + } done: - if (out_param) + if (out_param) { g_array_free(out_param, TRUE); + } if (req_info) { pending_requests = g_slist_remove( pending_requests, (void *)req_info); g_free(req_info); + req_info = NULL; } FUNC_EXIT; } diff --git a/ua-daemon/include/ua-manager-common.h b/ua-daemon/include/ua-manager-common.h index 0f32d21..836e2a9 100644 --- a/ua-daemon/include/ua-manager-common.h +++ b/ua-daemon/include/ua-manager-common.h @@ -93,6 +93,8 @@ GSList *_uam_manager_get_request_list(void); void _uam_manager_remove_req_ctxt_from_list( uam_request_context_t *req_info); +void _uam_manager_cleanup_client(const char *name); + void _uam_manager_method_return( GDBusMethodInvocation *invocation, GArray *out_param, int result); diff --git a/ua-daemon/src/ua-manager-request-handler.c b/ua-daemon/src/ua-manager-request-handler.c index 5e775b1..538327c 100644 --- a/ua-daemon/src/ua-manager-request-handler.c +++ b/ua-daemon/src/ua-manager-request-handler.c @@ -802,32 +802,14 @@ static void __uam_manager_name_owner_changed_cb(GDBusConnection *connection, GVariant *parameters, gpointer user_data) { - int count = 1; const char *name = NULL; const char *old_owner = NULL; const char *new_owner = NULL; - GSList *list; g_variant_get(parameters, "(&s&s&s)", &name, &old_owner, &new_owner); - if ('\0' == *new_owner) { - /* Cleanup all pending request from this sender */ - __uam_manager_cleanup_requests_from_sender(name); - - g_mutex_lock(&uam_dbus_clients_mutex); - list = __uam_list_find_client(name); - if (list) { - /* found bus name in our bus list */ - __uamd_dbus_client_cleanup((gpointer)list->data); - uam_dbus_clients = g_slist_remove_link(uam_dbus_clients, list); - count = g_slist_length(uam_dbus_clients); - } - g_mutex_unlock(&uam_dbus_clients_mutex); - - if (0 == count) { - UAM_ERR("Quit ua-manager"); - g_main_loop_quit(main_loop); - } + /* Clean up client info */ + _uam_manager_cleanup_client(name); } } @@ -989,3 +971,27 @@ void _uam_manager_remove_req_ctxt_from_list(uam_request_context_t *req_info) } FUNC_EXIT; } + +void _uam_manager_cleanup_client(const char *name) +{ + int count = 1; + GSList *list = NULL; + + /* Cleanup all pending request from this sender */ + __uam_manager_cleanup_requests_from_sender(name); + + g_mutex_lock(&uam_dbus_clients_mutex); + list = __uam_list_find_client(name); + if (list) { + /* found bus name in our bus list */ + __uamd_dbus_client_cleanup((gpointer)list->data); + uam_dbus_clients = g_slist_remove_link(uam_dbus_clients, list); + count = g_slist_length(uam_dbus_clients); + } + g_mutex_unlock(&uam_dbus_clients_mutex); + + if (0 == count) { + UAM_ERR("Quit ua-manager"); + g_main_loop_quit(main_loop); + } +} -- 2.7.4 From 3f80fbaec8a687996c4e255792cdaa23bebc96ad Mon Sep 17 00:00:00 2001 From: Atul Rai Date: Wed, 24 Apr 2019 20:03:13 +0530 Subject: [PATCH 09/16] Added DETECTION STARTED/STOPPED event Change-Id: Idc03c7961c77cfc01d1b5bdf8fe724bc9a38ec4e Signed-off-by: Atul Rai --- include/ua-api.h | 2 ++ include/ua-internal.h | 2 ++ ua-api/src/ua-event-handler.c | 8 +++++ ua-daemon/include/ua-manager-core.h | 4 +++ ua-daemon/src/pm/ua-ble-plugin-handler.c | 13 +++++++ ua-daemon/src/pm/ua-light-plugin-handler.c | 13 +++++++ ua-daemon/src/pm/ua-motion-plugin-handler.c | 15 +++++++- ua-daemon/src/pm/ua-wifi-plugin-handler.c | 13 +++++++ ua-daemon/src/ua-manager-core.c | 55 ++++++++++++++++++++++++++++- ua-daemon/src/ua-manager-event-sender.c | 6 ++++ ua-plugins/include/ua-plugin.h | 7 ++++ 11 files changed, 136 insertions(+), 2 deletions(-) diff --git a/include/ua-api.h b/include/ua-api.h index 1f53432..f208e96 100644 --- a/include/ua-api.h +++ b/include/ua-api.h @@ -56,6 +56,8 @@ extern "C" { EVENT(UAM_EVENT_AMBIANT_MODE_DISABLED) \ EVENT(UAM_EVENT_SENSOR_STATE_READY) \ EVENT(UAM_EVENT_SENSOR_STATE_NOT_READY) \ + EVENT(UAM_EVENT_DETECTION_STARTED) \ + EVENT(UAM_EVENT_DETECTION_STOPPED) \ EVENT(UAM_EVENT_MAX) #define GENERATE_EVENT_ENUM(ENUM) ENUM, diff --git a/include/ua-internal.h b/include/ua-internal.h index fd6c8d9..cd508a7 100644 --- a/include/ua-internal.h +++ b/include/ua-internal.h @@ -78,6 +78,8 @@ typedef enum { #define UAM_SIGNAL_USER_ABSENCE_DETECTED "UserAbsenceDetected" #define UAM_SIGNAL_SENSOR_STATE_READY "SensorReady" #define UAM_SIGNAL_SENSOR_STATE_NOT_READY "SensorNotReady" +#define UAM_SIGNAL_DETECTION_STARTED "DetectionStarted" +#define UAM_SIGNAL_DETECTION_STOPPED "DetectionStopped" #ifdef __cplusplus } diff --git a/ua-api/src/ua-event-handler.c b/ua-api/src/ua-event-handler.c index 369d25a..5f2bae7 100644 --- a/ua-api/src/ua-event-handler.c +++ b/ua-api/src/ua-event-handler.c @@ -227,6 +227,14 @@ static void __uam_event_handler(GDBusConnection *connection, event = UAM_EVENT_DEVICE_REMOVED; __uam_send_event(event, result, &dev_info, event_info->cb, event_info->user_data); + } else if (0 == strncasecmp(signal_name, UAM_SIGNAL_DETECTION_STARTED, + strlen(UAM_SIGNAL_DETECTION_STARTED))) { + __uam_send_event(UAM_EVENT_DETECTION_STARTED, result, NULL, + event_info->cb, event_info->user_data); + } else if (0 == strncasecmp(signal_name, UAM_SIGNAL_DETECTION_STOPPED, + strlen(UAM_SIGNAL_DETECTION_STOPPED))) { + __uam_send_event(UAM_EVENT_DETECTION_STOPPED, result, NULL, + event_info->cb, event_info->user_data); } else { UAM_WARN("Unknown signal recieved: %s", signal_name); } diff --git a/ua-daemon/include/ua-manager-core.h b/ua-daemon/include/ua-manager-core.h index 1ee5e31..1ba8969 100644 --- a/ua-daemon/include/ua-manager-core.h +++ b/ua-daemon/include/ua-manager-core.h @@ -145,6 +145,10 @@ void _uam_core_reset_database(void); unsigned int _uam_core_get_active_sensors(int detection_mode); +void _uam_core_handle_detection_started(unsigned int sensor); + +void _uam_core_handle_detection_stopped(unsigned int sensor); + #ifdef __cplusplus } #endif diff --git a/ua-daemon/src/pm/ua-ble-plugin-handler.c b/ua-daemon/src/pm/ua-ble-plugin-handler.c index d2ffcdb..3e834d0 100644 --- a/ua-daemon/src/pm/ua-ble-plugin-handler.c +++ b/ua-daemon/src/pm/ua-ble-plugin-handler.c @@ -52,6 +52,18 @@ static void ble_lpm_detection_callback(uas_detection_type_e type) FUNC_EXIT; } +static void ble_detection_state_changed_cb(int state) +{ + FUNC_ENTRY; + + if (state) + _uam_core_handle_detection_started(UAM_SENSOR_BITMASK_BLE); + else + _uam_core_handle_detection_stopped(UAM_SENSOR_BITMASK_BLE); + + FUNC_EXIT; +} + static void ble_device_detection_callback(uas_detection_type_e type, uas_device_info_t *device) { FUNC_ENTRY; @@ -98,6 +110,7 @@ static void ble_device_added_callback(int status, uas_device_info_t *device) uas_callbacks_t ble_cbs = { .state_changed_cb = ble_state_changed_callback, + .detection_state_cb = ble_detection_state_changed_cb, .detected_cb = ble_lpm_detection_callback, .device_detected_cb = ble_device_detection_callback, .device_added_cb = ble_device_added_callback diff --git a/ua-daemon/src/pm/ua-light-plugin-handler.c b/ua-daemon/src/pm/ua-light-plugin-handler.c index 092f60d..ff962ac 100644 --- a/ua-daemon/src/pm/ua-light-plugin-handler.c +++ b/ua-daemon/src/pm/ua-light-plugin-handler.c @@ -30,6 +30,18 @@ void light_state_changed_callback(int state) FUNC_EXIT; } +static void light_detection_state_changed_cb(int state) +{ + FUNC_ENTRY; + + if (state) + _uam_core_handle_detection_started(UAM_SENSOR_BITMASK_LIGHT); + else + _uam_core_handle_detection_stopped(UAM_SENSOR_BITMASK_LIGHT); + + FUNC_EXIT; +} + void light_detection_callback(uas_detection_type_e type) { FUNC_ENTRY; @@ -49,6 +61,7 @@ void light_detection_callback(uas_detection_type_e type) uas_callbacks_t light_cbs = { .state_changed_cb = light_state_changed_callback, + .detection_state_cb = light_detection_state_changed_cb, .detected_cb = light_detection_callback, .device_detected_cb = NULL, .device_added_cb = NULL diff --git a/ua-daemon/src/pm/ua-motion-plugin-handler.c b/ua-daemon/src/pm/ua-motion-plugin-handler.c index 1dff18a..82bc6c6 100644 --- a/ua-daemon/src/pm/ua-motion-plugin-handler.c +++ b/ua-daemon/src/pm/ua-motion-plugin-handler.c @@ -30,6 +30,18 @@ void motion_state_changed_callback(int state) FUNC_EXIT; } +static void motion_detection_state_changed_cb(int state) +{ + FUNC_ENTRY; + + if (state) + _uam_core_handle_detection_started(UAM_SENSOR_BITMASK_MOTION); + else + _uam_core_handle_detection_stopped(UAM_SENSOR_BITMASK_MOTION); + + FUNC_EXIT; +} + void motion_detection_callback(uas_detection_type_e type) { FUNC_ENTRY; @@ -48,7 +60,8 @@ void motion_detection_callback(uas_detection_type_e type) } uas_callbacks_t motion_cbs = { - .state_changed_cb = motion_state_changed_callback, + .state_changed_cb = motion_detection_state_changed_cb, + .detection_state_cb = motion_state_changed_callback, .detected_cb = motion_detection_callback, .device_detected_cb = NULL, .device_added_cb = NULL diff --git a/ua-daemon/src/pm/ua-wifi-plugin-handler.c b/ua-daemon/src/pm/ua-wifi-plugin-handler.c index 1f6da6c..8630d80 100644 --- a/ua-daemon/src/pm/ua-wifi-plugin-handler.c +++ b/ua-daemon/src/pm/ua-wifi-plugin-handler.c @@ -52,6 +52,18 @@ static void wifi_lpm_detection_callback(uas_detection_type_e type) FUNC_EXIT; } +static void wifi_detection_state_changed_cb(int state) +{ + FUNC_ENTRY; + + if (state) + _uam_core_handle_detection_started(UAM_SENSOR_BITMASK_WIFI); + else + _uam_core_handle_detection_stopped(UAM_SENSOR_BITMASK_WIFI); + + FUNC_EXIT; +} + static void wifi_device_detection_callback(uas_detection_type_e type, uas_device_info_t *device) { FUNC_ENTRY; @@ -98,6 +110,7 @@ static void wifi_device_added_callback(int status, uas_device_info_t *device) uas_callbacks_t wifi_cbs = { .state_changed_cb = wifi_state_changed_callback, + .detection_state_cb = wifi_detection_state_changed_cb, .detected_cb = wifi_lpm_detection_callback, .device_detected_cb = wifi_device_detection_callback, .device_added_cb = wifi_device_added_callback diff --git a/ua-daemon/src/ua-manager-core.c b/ua-daemon/src/ua-manager-core.c index b343b6d..2f89739 100644 --- a/ua-daemon/src/ua-manager-core.c +++ b/ua-daemon/src/ua-manager-core.c @@ -44,6 +44,7 @@ GSList *devices; /* List of devices - uam_db_device_info_t */ static gboolean user_id_list[UAM_MAX_USERS]; static int next_user_id = 1; +static unsigned int detecting_sensors = 0; static int __uam_core_reserve_user_id(void) { @@ -1892,7 +1893,7 @@ void _uam_core_handle_absence_detected(unsigned int sensor, dev_info->type, dev_info->mac, tech->presence_state)) UAM_WARN("_ua_device_db_update_device_presence failed"); - __send_user_absence_event(user, dev_info->type, sensor); + //__send_user_absence_event(user, dev_info->type, sensor); FUNC_EXIT; } @@ -1949,3 +1950,55 @@ void _uam_core_reset_database(void) FUNC_EXIT; } + +void _uam_core_handle_detection_started(unsigned int sensor) +{ + FUNC_ENTRY; + unsigned int active_sensors = 0; + + UAM_DBG("Sensor: 0x%8.8X, detecting_sensors: 0x%8.8X", + sensor, detecting_sensors); + + detecting_sensors |= sensor; + active_sensors |= _uam_core_get_active_sensors(UAM_DETECT_PRESENCE); + active_sensors |= _uam_core_get_active_sensors(UAM_DETECT_ABSENCE); + if (active_sensors == detecting_sensors) { + /* Send detection started event */ + _uam_manager_send_event(NULL, UAM_EVENT_DETECTION_STARTED, NULL); + } + + FUNC_EXIT; +} + +void _uam_core_handle_detection_stopped(unsigned int sensor) +{ + FUNC_ENTRY; + uam_tech_type_e type = UAM_TECH_TYPE_NONE; + + UAM_DBG("Sensor: 0x%8.8X, detecting_sensors: 0x%8.8X", + sensor, detecting_sensors); + detecting_sensors &= ~sensor; + + if (UAM_SENSOR_BITMASK_BLE == sensor) + type = UAM_TECH_TYPE_BLE; + else if (UAM_SENSOR_BITMASK_WIFI == sensor) + type = UAM_TECH_TYPE_WIFI; + + if (UAM_TECH_TYPE_NONE != type) { + GSList *l; + + for (l = users; NULL != l; l = g_slist_next(l)) { + uam_db_user_info_t *user = l->data; + if (!user) + continue; + + __send_user_absence_event(user, type, sensor); + } + } + + if (0 == detecting_sensors) + /* Send detection stopped event */ + _uam_manager_send_event(NULL, UAM_EVENT_DETECTION_STOPPED, NULL); + + FUNC_EXIT; +} diff --git a/ua-daemon/src/ua-manager-event-sender.c b/ua-daemon/src/ua-manager-event-sender.c index 13db7e3..a709653 100644 --- a/ua-daemon/src/ua-manager-event-sender.c +++ b/ua-daemon/src/ua-manager-event-sender.c @@ -62,6 +62,12 @@ int _uam_manager_send_event( case UAM_EVENT_USER_ABSENCE_DETECTED: signal = UAM_SIGNAL_USER_ABSENCE_DETECTED; break; + case UAM_EVENT_DETECTION_STARTED: + signal = UAM_SIGNAL_DETECTION_STARTED; + break; + case UAM_EVENT_DETECTION_STOPPED: + signal = UAM_SIGNAL_DETECTION_STOPPED; + break; default: UAM_ERR("Unhandled event"); return UAM_ERROR_INTERNAL; diff --git a/ua-plugins/include/ua-plugin.h b/ua-plugins/include/ua-plugin.h index eb87268..8d2a836 100644 --- a/ua-plugins/include/ua-plugin.h +++ b/ua-plugins/include/ua-plugin.h @@ -113,6 +113,12 @@ typedef struct { typedef void (*uas_state_changed_callback)(int state); /* + * Callback to be invoked on Presen/Absence detection is started/stopped by plug-in's + * [Param] state - 0 = detection stopped, 1 = detection started. + */ +typedef void (*uas_detection_state_changed_callback)(int state); + +/* * Callback to be invoked on Presen/Absence detection by plug-in's which do * not support User identification. */ @@ -137,6 +143,7 @@ typedef void (*uas_device_added_callback)(int status, uas_device_info_t *device) /* UA plug-in callback structure */ typedef struct { uas_state_changed_callback state_changed_cb; + uas_detection_state_changed_callback detection_state_cb; uas_detection_callback detected_cb; uas_device_detection_callback device_detected_cb; uas_device_added_callback device_added_cb; -- 2.7.4 From 4569d0c0939c196783e2ee424b565abbf054fa28 Mon Sep 17 00:00:00 2001 From: Atul Rai Date: Tue, 7 May 2019 08:58:03 +0530 Subject: [PATCH 10/16] Added last seen timestamp in uam_device_info_t Change-Id: Id48102119eae0c2a536147eba3fea45e39d7a995 Signed-off-by: Atul Rai --- include/ua-api.h | 1 + ua-daemon/src/pm/ua-cloud-plugin-handler.c | 1 + ua-daemon/src/ua-manager-core.c | 1 + ua-plugins/include/ua-plugin-type.h | 1 + 4 files changed, 4 insertions(+) diff --git a/include/ua-api.h b/include/ua-api.h index f208e96..2669382 100644 --- a/include/ua-api.h +++ b/include/ua-api.h @@ -141,6 +141,7 @@ typedef struct { char mac[UAM_MAC_ADDRESS_STRING_LEN]; /* Device's MAC ADDRESS */ char ipv4_addr[UAM_IP_ADDRESS_MAX_STRING_LEN];/* Device's IPv4 address optional */ char device_id[UAM_DEVICE_ID_MAX_STRING_LEN]; /* Device's uniquie ID */ + long long int last_seen; /* Latest timestamp when device was discoverd */ } uam_device_info_t; typedef struct { diff --git a/ua-daemon/src/pm/ua-cloud-plugin-handler.c b/ua-daemon/src/pm/ua-cloud-plugin-handler.c index 1a98b54..8fd4b06 100644 --- a/ua-daemon/src/pm/ua-cloud-plugin-handler.c +++ b/ua-daemon/src/pm/ua-cloud-plugin-handler.c @@ -57,6 +57,7 @@ static void __uam_to_uap_device_info(uap_device_info_t *dest, dest->os = src->operating_system; dest->type = src->type; + dest->last_seen = src->last_seen; g_strlcpy(dest->device_id, src->device_id, UAP_DEVICE_ID_MAX_STRING_LEN); g_strlcpy(dest->mac, src->mac, UAP_MAC_ADDRESS_STRING_LEN); g_strlcpy(dest->ipv4_addr, src->ipv4_addr, UAP_IP_ADDRESS_MAX_STRING_LEN); diff --git a/ua-daemon/src/ua-manager-core.c b/ua-daemon/src/ua-manager-core.c index 2f89739..7820f59 100644 --- a/ua-daemon/src/ua-manager-core.c +++ b/ua-daemon/src/ua-manager-core.c @@ -390,6 +390,7 @@ static void __get_uam_db_dev_list_to_uam_dev_list( (*device_list)[indx].operating_system = db_info->os; g_strlcpy((*device_list)[indx].device_id, db_info->device_id, UAM_DEVICE_ID_MAX_STRING_LEN); + (*device_list)[indx].last_seen = tech->timestamp; (*device_list)[indx++].type = tech->tech_type; } } diff --git a/ua-plugins/include/ua-plugin-type.h b/ua-plugins/include/ua-plugin-type.h index e91972b..cf46efa 100644 --- a/ua-plugins/include/ua-plugin-type.h +++ b/ua-plugins/include/ua-plugin-type.h @@ -50,6 +50,7 @@ typedef struct { char mac[UAP_MAC_ADDRESS_STRING_LEN]; /* Device's MAC ADDRESS */ char ipv4_addr[UAP_IP_ADDRESS_MAX_STRING_LEN];/* Device's IPv4 address optional */ char device_id[UAP_DEVICE_ID_MAX_STRING_LEN]; /* Device's uniquie ID */ + long long int last_seen; } uap_device_info_t; /* UA plugin return status */ -- 2.7.4 From 544f259fa10c8c3fe5d307f341ac7a081a83be34 Mon Sep 17 00:00:00 2001 From: saerome kim Date: Thu, 16 May 2019 15:58:40 +0900 Subject: [PATCH 11/16] Fixed securiti issue. - Security team requested apply the smack rule to the db files so that only ua-manager can get access to the db files. Change-Id: I454153a5167a66d61003f947cc93d53aaba1a915 Signed-off-by: saerome kim --- packaging/ua-manager.spec | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packaging/ua-manager.spec b/packaging/ua-manager.spec index 38c9cbc..91b41b2 100644 --- a/packaging/ua-manager.spec +++ b/packaging/ua-manager.spec @@ -77,7 +77,11 @@ cp net.uamd.service %{buildroot}%{_datadir}/dbus-1/system-services/net.uamd.serv mkdir -p %{buildroot}%{_unitdir} cp ua-manager.service %{buildroot}%{_unitdir}/ua-manager.service -%post -p /sbin/ldconfig +%post +/sbin/ldconfig + +/usr/bin/chsmack -a 'System' %{database_full_path} +/usr/bin/chsmack -a 'System' %{database_full_path}-journal %postun -p /sbin/ldconfig -- 2.7.4 From 62a7aac0fdc19f04a6a804560f714837bda8c4ee Mon Sep 17 00:00:00 2001 From: Atul Rai Date: Mon, 20 May 2019 17:11:35 +0530 Subject: [PATCH 12/16] Add plugin APIs and cb to support active device scan This patch adds APIs and callback on sensor plugin interface to support immediate scanning for active devcies in proximity. Change-Id: I803a920f1aff0a67ba288cf8a573e8b6b9ae179b Signed-off-by: Atul Rai --- ua-daemon/src/pm/ua-ble-plugin-handler.c | 3 ++- ua-daemon/src/pm/ua-light-plugin-handler.c | 3 ++- ua-daemon/src/pm/ua-motion-plugin-handler.c | 3 ++- ua-daemon/src/pm/ua-wifi-plugin-handler.c | 11 +++++++++- ua-plugins/include/ua-plugin.h | 34 +++++++++++++++++++++++++++++ 5 files changed, 50 insertions(+), 4 deletions(-) diff --git a/ua-daemon/src/pm/ua-ble-plugin-handler.c b/ua-daemon/src/pm/ua-ble-plugin-handler.c index 3e834d0..0755c31 100644 --- a/ua-daemon/src/pm/ua-ble-plugin-handler.c +++ b/ua-daemon/src/pm/ua-ble-plugin-handler.c @@ -113,5 +113,6 @@ uas_callbacks_t ble_cbs = { .detection_state_cb = ble_detection_state_changed_cb, .detected_cb = ble_lpm_detection_callback, .device_detected_cb = ble_device_detection_callback, - .device_added_cb = ble_device_added_callback + .device_added_cb = ble_device_added_callback, + .active_scan_cb = NULL }; diff --git a/ua-daemon/src/pm/ua-light-plugin-handler.c b/ua-daemon/src/pm/ua-light-plugin-handler.c index ff962ac..fbf0ed4 100644 --- a/ua-daemon/src/pm/ua-light-plugin-handler.c +++ b/ua-daemon/src/pm/ua-light-plugin-handler.c @@ -64,5 +64,6 @@ uas_callbacks_t light_cbs = { .detection_state_cb = light_detection_state_changed_cb, .detected_cb = light_detection_callback, .device_detected_cb = NULL, - .device_added_cb = NULL + .device_added_cb = NULL, + .active_scan_cb = NULL, }; diff --git a/ua-daemon/src/pm/ua-motion-plugin-handler.c b/ua-daemon/src/pm/ua-motion-plugin-handler.c index 82bc6c6..3efd1c5 100644 --- a/ua-daemon/src/pm/ua-motion-plugin-handler.c +++ b/ua-daemon/src/pm/ua-motion-plugin-handler.c @@ -64,5 +64,6 @@ uas_callbacks_t motion_cbs = { .detection_state_cb = motion_state_changed_callback, .detected_cb = motion_detection_callback, .device_detected_cb = NULL, - .device_added_cb = NULL + .device_added_cb = NULL, + .active_scan_cb = NULL, }; diff --git a/ua-daemon/src/pm/ua-wifi-plugin-handler.c b/ua-daemon/src/pm/ua-wifi-plugin-handler.c index 8630d80..cb82201 100644 --- a/ua-daemon/src/pm/ua-wifi-plugin-handler.c +++ b/ua-daemon/src/pm/ua-wifi-plugin-handler.c @@ -108,10 +108,19 @@ static void wifi_device_added_callback(int status, uas_device_info_t *device) FUNC_EXIT; } +static void wifi_active_scan_callback(uas_active_scan_event_e event, + const uas_device_info_t *device) +{ + FUNC_ENTRY; + + FUNC_EXIT; +} + uas_callbacks_t wifi_cbs = { .state_changed_cb = wifi_state_changed_callback, .detection_state_cb = wifi_detection_state_changed_cb, .detected_cb = wifi_lpm_detection_callback, .device_detected_cb = wifi_device_detection_callback, - .device_added_cb = wifi_device_added_callback + .device_added_cb = wifi_device_added_callback, + .active_scan_cb = wifi_active_scan_callback }; diff --git a/ua-plugins/include/ua-plugin.h b/ua-plugins/include/ua-plugin.h index 8d2a836..7f3746f 100644 --- a/ua-plugins/include/ua-plugin.h +++ b/ua-plugins/include/ua-plugin.h @@ -109,6 +109,12 @@ typedef struct { uas_address_info_t *addr_list; } uas_device_info_t; +/* Active scan event types */ +typedef enum { + UAS_ACTIVE_DEVICE_FOUND = 0x01, + UAS_ACTIVE_SCAN_COMPLETED = 0x02 +} uas_active_scan_event_e; + /* Callback to be invoked on plug-in's state changes (Ready <-> Not Ready) */ typedef void (*uas_state_changed_callback)(int state); @@ -140,6 +146,16 @@ typedef void (*uas_device_detection_callback)(uas_detection_type_e type, uas_dev */ typedef void (*uas_device_added_callback)(int status, uas_device_info_t *device); +/* + * Callback to be invoked in response to search_active_devices() API + * + * [Param] scan_event - UAS_ACTIVE_DEVICE_FOUND or, UAS_ACTIVE_SCAN_COMPLETED. + * [Param] device - Found registerd device info if event is UAS_ACTIVE_DEVICE_FOUND + * or, NULL if event is UAS_ACTIVE_SCAN_COMPLETED. + */ +typedef void (*uas_active_device_scan_callback)( + uas_active_scan_event_e event, const uas_device_info_t *device); + /* UA plug-in callback structure */ typedef struct { uas_state_changed_callback state_changed_cb; @@ -147,6 +163,7 @@ typedef struct { uas_detection_callback detected_cb; uas_device_detection_callback device_detected_cb; uas_device_added_callback device_added_cb; + uas_active_device_scan_callback active_scan_cb; } uas_callbacks_t; typedef struct { @@ -249,6 +266,23 @@ typedef struct { * detecting absence. */ int (*set_detection_threshold)(int presence_threshold, int absence_threshold); + + /* + * [Async API] To search for currently active devices in proximity. + * + * [Param] detection_period - Time in second for which User detection procedure is + * executed. + * + * Once detection_period is over, list of current active devices will be returned using + * uas_active_devices_callback(). + * + */ + int (*scan_active_devices)(int detection_period); + + /* + * [Async API] To cancel the ongoing active devices search. + */ + int (*cancel_active_device_scan)(void); } uas_api_t; typedef enum { -- 2.7.4 From 7fb41162e8b57dd2585303d32047d1303c702ff8 Mon Sep 17 00:00:00 2001 From: Abhay agarwal Date: Fri, 24 May 2019 16:58:51 +0530 Subject: [PATCH 13/16] Added support for on_demand_scan Change-Id: I0f7c1fcceb920cbffabe864a1385c5b04612b1d0 Signed-off-by: Abhay agarwal --- include/ua-api.h | 6 ++ include/ua-internal.h | 4 + ua-api/src/ua-api.c | 37 +++++++ ua-api/src/ua-event-handler.c | 29 ++++++ ua-daemon/include/ua-manager-core.h | 12 +++ ua-daemon/include/ua-plugin-manager.h | 4 + ua-daemon/src/pm/ua-plugin-manager.c | 68 +++++++++++++ ua-daemon/src/pm/ua-pm-util.c | 13 +++ ua-daemon/src/pm/ua-pm-util.h | 2 + ua-daemon/src/pm/ua-wifi-plugin-handler.c | 16 +++ ua-daemon/src/ua-manager-core.c | 154 +++++++++++++++++++++++++++++ ua-daemon/src/ua-manager-event-sender.c | 6 ++ ua-daemon/src/ua-manager-request-handler.c | 24 +++++ 13 files changed, 375 insertions(+) diff --git a/include/ua-api.h b/include/ua-api.h index 2669382..cb85c46 100644 --- a/include/ua-api.h +++ b/include/ua-api.h @@ -58,6 +58,8 @@ extern "C" { EVENT(UAM_EVENT_SENSOR_STATE_NOT_READY) \ EVENT(UAM_EVENT_DETECTION_STARTED) \ EVENT(UAM_EVENT_DETECTION_STOPPED) \ + EVENT(UAM_EVENT_DEVICE_FOUND) \ + EVENT(UAM_EVENT_SCAN_COMPLETED) \ EVENT(UAM_EVENT_MAX) #define GENERATE_EVENT_ENUM(ENUM) ENUM, @@ -113,6 +115,10 @@ int _uam_start_absence_detection(unsigned int bitmask); int _uam_stop_absence_detection(unsigned int bitmask); +int _uam_start_search_active_devices(unsigned int bitmask, int detection_period); + +int _uam_stop_search_active_devices(unsigned int bitmask); + typedef enum { UAM_PRESENCE_STATE_INVALID = 0x00, UAM_PRESENCE_STATE_PRESENT, diff --git a/include/ua-internal.h b/include/ua-internal.h index cd508a7..f472921 100644 --- a/include/ua-internal.h +++ b/include/ua-internal.h @@ -59,6 +59,8 @@ extern "C" { REQUEST(UAM_REQUEST_SET_LOW_POWER_MODE) \ REQUEST(UAM_REQUEST_GET_DETECTION_PARAMS) \ REQUEST(UAM_REQUEST_SET_DETECTION_PARAMS) \ + REQUEST(UAM_REQUEST_START_SEARCH_ACTIVE_DEVICES) \ + REQUEST(UAM_REQUEST_STOP_SEARCH_ACTIVE_DEVICES) \ REQUEST(UAM_REQUEST_MAX) #define GENERATE_REQUEST_ENUM(ENUM) ENUM, @@ -80,6 +82,8 @@ typedef enum { #define UAM_SIGNAL_SENSOR_STATE_NOT_READY "SensorNotReady" #define UAM_SIGNAL_DETECTION_STARTED "DetectionStarted" #define UAM_SIGNAL_DETECTION_STOPPED "DetectionStopped" +#define UAM_SIGNAL_DEVICE_FOUND "DeviceFound" +#define UAM_SIGNAL_SCAN_COMPLETED "ScanCompleted" #ifdef __cplusplus } diff --git a/ua-api/src/ua-api.c b/ua-api/src/ua-api.c index d9b2621..4a7b354 100644 --- a/ua-api/src/ua-api.c +++ b/ua-api/src/ua-api.c @@ -772,3 +772,40 @@ UAM_EXPORT_API int _uam_set_detection_params(int cycle, int period, int retries) FUNC_EXIT; return ret; } + +UAM_EXPORT_API int _uam_start_search_active_devices(unsigned int bitmask, int detection_period) +{ + FUNC_ENTRY; + int ret; + + UAM_INIT_PARAMS(); + UAM_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + g_array_append_vals(in_param1, &bitmask, sizeof(unsigned int)); + g_array_append_vals(in_param2, &detection_period, sizeof(int)); + ret = _uam_sync_request(UAM_REQUEST_START_SEARCH_ACTIVE_DEVICES, + in_param1, in_param2, in_param3, in_param4, &out_param); + + UAM_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + FUNC_EXIT; + return ret; +} + +UAM_EXPORT_API int _uam_stop_search_active_devices(unsigned int bitmask) +{ + FUNC_ENTRY; + int ret; + + UAM_INIT_PARAMS(); + UAM_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + g_array_append_vals(in_param1, &bitmask, sizeof(unsigned int)); + ret = _uam_sync_request(UAM_REQUEST_STOP_SEARCH_ACTIVE_DEVICES, + in_param1, in_param2, in_param3, in_param4, &out_param); + + UAM_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + FUNC_EXIT; + return ret; +} diff --git a/ua-api/src/ua-event-handler.c b/ua-api/src/ua-event-handler.c index 5f2bae7..bf7df72 100644 --- a/ua-api/src/ua-event-handler.c +++ b/ua-api/src/ua-event-handler.c @@ -235,6 +235,35 @@ static void __uam_event_handler(GDBusConnection *connection, strlen(UAM_SIGNAL_DETECTION_STOPPED))) { __uam_send_event(UAM_EVENT_DETECTION_STOPPED, result, NULL, event_info->cb, event_info->user_data); + } else if (0 == strncasecmp(signal_name, UAM_SIGNAL_DEVICE_FOUND, + strlen(UAM_SIGNAL_DEVICE_FOUND))) { + uam_device_info_t dev_info; + int os, type; + char *mac = NULL; + char *ipv4_addr = NULL; + char *device_id = NULL; + + g_variant_get(parameters, "(iii&s&s&s)", &result, + &os, &type, &mac, &ipv4_addr, &device_id); + + dev_info.operating_system = os; + dev_info.type = type; + g_strlcpy(dev_info.mac, + mac, UAM_MAC_ADDRESS_STRING_LEN); + g_strlcpy(dev_info.ipv4_addr, + ipv4_addr, UAM_IP_ADDRESS_MAX_STRING_LEN); + g_strlcpy(dev_info.device_id, + device_id, UAM_DEVICE_ID_MAX_STRING_LEN); + + event = UAM_EVENT_DEVICE_FOUND; + __uam_send_event(event, result, &dev_info, + event_info->cb, event_info->user_data); + } else if (0 == strncasecmp(signal_name, UAM_SIGNAL_SCAN_COMPLETED, + strlen(UAM_SIGNAL_SCAN_COMPLETED))) { + + event = UAM_EVENT_SCAN_COMPLETED; + __uam_send_event(event, result, NULL, + event_info->cb, event_info->user_data); } else { UAM_WARN("Unknown signal recieved: %s", signal_name); } diff --git a/ua-daemon/include/ua-manager-core.h b/ua-daemon/include/ua-manager-core.h index 1ba8969..2d64e66 100644 --- a/ua-daemon/include/ua-manager-core.h +++ b/ua-daemon/include/ua-manager-core.h @@ -69,6 +69,12 @@ typedef struct uam_db_user_info { // long long int timestamp; } uam_db_user_info_t; + +typedef enum { + UAM_ACTIVE_DEVICE_FOUND = 0x01, + UAM_ACTIVE_SCAN_COMPLETED = 0x02 +} uam_active_scan_event_e; + int _uam_core_add_user(const char *account, const char *name); int _uam_core_remove_user(const char *account); @@ -149,6 +155,12 @@ void _uam_core_handle_detection_started(unsigned int sensor); void _uam_core_handle_detection_stopped(unsigned int sensor); +int _uam_core_start_search_active_devices(char *sender, unsigned int sensors, int detection_period); + +int _uam_core_stop_search_active_devices(char *sender, unsigned int sensors); + +void _uam_core_handle_active_device(uam_active_scan_event_e event, unsigned int sensor, const uam_device_info_t *dev_info); + #ifdef __cplusplus } #endif diff --git a/ua-daemon/include/ua-plugin-manager.h b/ua-daemon/include/ua-plugin-manager.h index e66eeb0..b26d354 100644 --- a/ua-daemon/include/ua-plugin-manager.h +++ b/ua-daemon/include/ua-plugin-manager.h @@ -58,6 +58,10 @@ int _uam_pm_set_detection_params(unsigned int sensor, int detection_cycle, int _uam_pm_set_detection_threshold(unsigned int sensor, int presence_threshold, int absence_threshold); +int _uam_pm_start_search_active_devices(unsigned int* bitmask, int detection_period); + +int _uam_pm_stop_search_active_devices(unsigned int bitmask); + #ifdef __cplusplus } #endif diff --git a/ua-daemon/src/pm/ua-plugin-manager.c b/ua-daemon/src/pm/ua-plugin-manager.c index 3a13745..a338bb3 100644 --- a/ua-daemon/src/pm/ua-plugin-manager.c +++ b/ua-daemon/src/pm/ua-plugin-manager.c @@ -668,3 +668,71 @@ int _uam_pm_set_detection_threshold(unsigned int sensor, FUNC_EXIT; return UAM_ERROR_NONE; } + +int _uam_pm_start_search_active_devices(unsigned int* bitmask, int detection_period) +{ + FUNC_ENTRY; + int id; + int status; + int ret = UAM_ERROR_INTERNAL; + + unsigned int scanning_sensor = 0; + + for (id = UAS_PLUGIN_ID_BLE; id < UAS_PLUGIN_ID_MAX; id++) { + uam_sensor_plugin_info_t *plugin = plugins[id]; + unsigned int sensor = _pm_util_uas_plugin_id_to_sensor_bitmask(id); + + if (!(sensor & (*bitmask))) + continue; + + if (!plugin || !plugin->api || !plugin->api->scan_active_devices) + continue; + + status = plugin->api->scan_active_devices(detection_period); + + if (UAS_STATUS_SUCCESS != status && UAS_STATUS_ALREADY_DONE != status) { + UAM_ERR("plugin->search_active_devices(%d) failed for %d", detection_period, id); + continue; + } + + scanning_sensor |= sensor; + /* Result success if scanning started for atleast 1 of the sensor */ + ret = UAM_ERROR_NONE; + } + + (*bitmask) &= scanning_sensor; + + FUNC_EXIT; + return ret; +} + +int _uam_pm_stop_search_active_devices(unsigned int bitmask) +{ + FUNC_ENTRY; + int id; + int status; + int ret = UAM_ERROR_INTERNAL; + + for (id = UAS_PLUGIN_ID_BLE; id < UAS_PLUGIN_ID_MAX; id++) { + uam_sensor_plugin_info_t *plugin = plugins[id]; + unsigned int sensor = _pm_util_uas_plugin_id_to_sensor_bitmask(id); + + if (!(sensor & bitmask)) + continue; + + if (!plugin || !plugin->api || !plugin->api->cancel_active_device_scan) + continue; + + status = plugin->api->cancel_active_device_scan(); + + if (UAS_STATUS_SUCCESS != status && UAS_STATUS_ALREADY_DONE != status) { + UAM_ERR("plugin->stop_search_active_devices() failed for %d", id); + continue; + } + + ret = UAM_ERROR_NONE; + } + + FUNC_EXIT; + return ret; +} diff --git a/ua-daemon/src/pm/ua-pm-util.c b/ua-daemon/src/pm/ua-pm-util.c index 58cf16e..08cc0fa 100644 --- a/ua-daemon/src/pm/ua-pm-util.c +++ b/ua-daemon/src/pm/ua-pm-util.c @@ -306,3 +306,16 @@ uam_device_info_t *_pm_util_uas_dev_info_to_uam_dev_info(const uas_device_info_t FUNC_EXIT; return device; } + +uam_active_scan_event_e _pm_util_uas_scan_event_to_uam_scan_event(uas_active_scan_event_e event) +{ + switch (event) { + case UAS_ACTIVE_DEVICE_FOUND : + return UAM_ACTIVE_DEVICE_FOUND; + case UAS_ACTIVE_SCAN_COMPLETED : + return UAM_ACTIVE_SCAN_COMPLETED; + default: + UAM_WARN("Unknown event 0x%8.8X", event); + return 0; + } +} diff --git a/ua-daemon/src/pm/ua-pm-util.h b/ua-daemon/src/pm/ua-pm-util.h index ec153df..7af480e 100644 --- a/ua-daemon/src/pm/ua-pm-util.h +++ b/ua-daemon/src/pm/ua-pm-util.h @@ -49,6 +49,8 @@ unsigned int _pm_util_uas_plugin_id_to_sensor_bitmask(uas_plugin_id_e id); const char *_pm_util_uas_status_to_str(int status); +uam_active_scan_event_e _pm_util_uas_scan_event_to_uam_scan_event(uas_active_scan_event_e event); + #ifdef __cplusplus } #endif diff --git a/ua-daemon/src/pm/ua-wifi-plugin-handler.c b/ua-daemon/src/pm/ua-wifi-plugin-handler.c index cb82201..2c95270 100644 --- a/ua-daemon/src/pm/ua-wifi-plugin-handler.c +++ b/ua-daemon/src/pm/ua-wifi-plugin-handler.c @@ -112,7 +112,23 @@ static void wifi_active_scan_callback(uas_active_scan_event_e event, const uas_device_info_t *device) { FUNC_ENTRY; + uam_device_info_t *dev_info = NULL; + uam_active_scan_event_e event_info; + if(UAS_ACTIVE_DEVICE_FOUND == event){ + ret_if(NULL == device); + + dev_info = _pm_util_uas_dev_info_to_uam_dev_info(device); + ret_if(NULL == dev_info); + + dev_info->type = UAM_TECH_TYPE_WIFI; + } + + event_info = _pm_util_uas_scan_event_to_uam_scan_event(event); + + _uam_core_handle_active_device(event_info, UAM_SENSOR_BITMASK_WIFI, dev_info); + + g_free(dev_info); FUNC_EXIT; } diff --git a/ua-daemon/src/ua-manager-core.c b/ua-daemon/src/ua-manager-core.c index 7820f59..9236abf 100644 --- a/ua-daemon/src/ua-manager-core.c +++ b/ua-daemon/src/ua-manager-core.c @@ -41,6 +41,7 @@ typedef struct { GSList *monitors; /* List of monitoring apps - uam_monitor_info_t */ GSList *users; /* List of users - uam_db_user_info_t */ GSList *devices; /* List of devices - uam_db_device_info_t */ +GSList *scanners; /* List of scanning apps - uam_monitor_info_t*/ static gboolean user_id_list[UAM_MAX_USERS]; static int next_user_id = 1; @@ -2003,3 +2004,156 @@ void _uam_core_handle_detection_stopped(unsigned int sensor) FUNC_EXIT; } + +static uam_monitor_info_t *__uam_find_scanner(const char *name) +{ +// FUNC_ENTRY; + GSList *l; + + retv_if(NULL == name, NULL); + + for (l = scanners; NULL != l; l = g_slist_next(l)) { + uam_monitor_info_t *scanner = l->data; + + if (!scanner || !scanner->name) + continue; + + if (0 == g_strcmp0(scanner->name, name)) { + UAM_DBG("Scanning application found in list"); + return scanner; + } + } + +// FUNC_EXIT; + return NULL; +} + +int _uam_core_start_search_active_devices(char *sender, unsigned int sensors, int detection_period) +{ + FUNC_ENTRY; + int ret; + uam_monitor_info_t *scanner; + GSList *l; + + retv_if(NULL == sender, UAM_ERROR_INVALID_PARAM); + + scanner = __uam_find_scanner(sender); + if (scanner) { + ret = UAM_ERROR_NOW_IN_PROGRESS; + UAM_ERR("Failed with error: %s (0x%4.4X)", + _uam_manager_error_to_str(ret), ret); + return ret; + } + + for (l = scanners; NULL != l; l = g_slist_next(l)) { + uam_monitor_info_t *scanner_data = l->data; + + if (!scanner_data || !scanner_data->name) + continue; + sensors &= ~(scanner_data->sensors); + } + + ret = _uam_pm_start_search_active_devices(&sensors, detection_period); + + if (UAM_ERROR_NONE != ret) { + UAM_ERR("Failed with error: %s (0x%4.4X)", + _uam_manager_error_to_str(ret), ret); + return ret; + } + + scanner = g_malloc0(sizeof(uam_monitor_info_t)); + scanner->name = g_strdup(sender); + scanner->sensors |= sensors; + scanners = g_slist_append(scanners, scanner); + + FUNC_EXIT; + return UAM_ERROR_NONE; +} + +int _uam_core_stop_search_active_devices(char *sender, unsigned int sensors) +{ + FUNC_ENTRY; + int ret; + + GSList *l; + retv_if(NULL == sender, UAM_ERROR_INVALID_PARAM); + + for (l = scanners; NULL != l; l = g_slist_next(l)) { + uam_monitor_info_t *scanner = l->data; + + if (!scanner || !scanner->name) + continue; + + if (scanner->sensors & sensors){ + ret = _uam_pm_stop_search_active_devices(sensors); + if (UAM_ERROR_NONE != ret) { + UAM_ERR("Failed with error: %s (0x%4.4X)", + _uam_manager_error_to_str(ret), ret); + return ret; + } + scanners = g_slist_remove(scanners,scanner); + g_free(scanner->name); + g_free(scanner); + } + } + + FUNC_EXIT; + return UAM_ERROR_NONE; +} + +void _uam_core_handle_active_device(uam_active_scan_event_e event, unsigned int sensor, const uam_device_info_t *dev_info) +{ + FUNC_ENTRY; + + GVariant *param = NULL; + GSList *l; + int done = 0; + char* name = NULL; + + for (l = scanners; NULL != l; l = g_slist_next(l)) { + uam_monitor_info_t *scanner = (uam_monitor_info_t *)l->data; + + if (!scanner || !scanner->name) + continue; + + if (scanner->sensors & sensor){ + + name = g_strdup(scanner->name); + if(event == UAM_ACTIVE_SCAN_COMPLETED){ + scanner->sensors &= ~(sensor); + if(scanner->sensors == 0){ + done = 1; + scanners = g_slist_remove(scanners, scanner); + g_free(scanner->name); + g_free(scanner); + } + } + break; + } + } + + if(event == UAM_ACTIVE_DEVICE_FOUND){ + param = g_variant_new("(iiisss)", + UAM_ERROR_NONE, + dev_info->operating_system, + dev_info->type, + dev_info->mac, + dev_info->ipv4_addr, + dev_info->device_id); + UAM_INFO_C("Send %s to applications", _uam_manager_event_to_str(UAM_EVENT_DEVICE_FOUND)); + /* Send device event to application */ + if (UAM_ERROR_NONE != _uam_manager_send_event(name, UAM_EVENT_DEVICE_FOUND, param)) + UAM_ERR("Failed to send %s", _uam_manager_event_to_str(event)); + } + else if(done == 1 && event == UAM_ACTIVE_SCAN_COMPLETED){ + UAM_INFO_C("Send %s to applications", _uam_manager_event_to_str(UAM_EVENT_SCAN_COMPLETED)); + /* Send device event to application */ + if (UAM_ERROR_NONE != _uam_manager_send_event(name, UAM_EVENT_SCAN_COMPLETED, param)) + UAM_ERR("Failed to send %s", _uam_manager_event_to_str(event)); + } + + if (name != NULL) + g_free(name); + + FUNC_EXIT; +} diff --git a/ua-daemon/src/ua-manager-event-sender.c b/ua-daemon/src/ua-manager-event-sender.c index a709653..2c064f6 100644 --- a/ua-daemon/src/ua-manager-event-sender.c +++ b/ua-daemon/src/ua-manager-event-sender.c @@ -68,6 +68,12 @@ int _uam_manager_send_event( case UAM_EVENT_DETECTION_STOPPED: signal = UAM_SIGNAL_DETECTION_STOPPED; break; + case UAM_EVENT_DEVICE_FOUND: + signal = UAM_SIGNAL_DEVICE_FOUND; + break; + case UAM_EVENT_SCAN_COMPLETED: + signal = UAM_SIGNAL_SCAN_COMPLETED; + break; default: UAM_ERR("Unhandled event"); return UAM_ERROR_INTERNAL; diff --git a/ua-daemon/src/ua-manager-request-handler.c b/ua-daemon/src/ua-manager-request-handler.c index 538327c..8435c78 100644 --- a/ua-daemon/src/ua-manager-request-handler.c +++ b/ua-daemon/src/ua-manager-request-handler.c @@ -390,6 +390,28 @@ static int __uam_manager_sync_request_handler( detection_param.period, detection_param.retries); break; } + case UAM_REQUEST_START_SEARCH_ACTIVE_DEVICES: { + unsigned int sensors; + int detection_period; + + __uam_manager_copy_params(in_param1, + &sensors, sizeof(unsigned int)); + + __uam_manager_copy_params(in_param2, + &detection_period, sizeof(int)); + + result = _uam_core_start_search_active_devices(sender, sensors, detection_period); + break; + } + case UAM_REQUEST_STOP_SEARCH_ACTIVE_DEVICES: { + unsigned int sensors; + + __uam_manager_copy_params(in_param1, + &sensors, sizeof(unsigned int)); + + result = _uam_core_stop_search_active_devices(sender, sensors); + break; + } default: UAM_WARN("UnSupported function [%s(0x%4.4X)]", _uam_manager_request_to_str(function), function); @@ -521,6 +543,8 @@ static gboolean __uam_manager_is_sync_function(int function) case UAM_REQUEST_SET_LOW_POWER_MODE: case UAM_REQUEST_GET_DETECTION_PARAMS: case UAM_REQUEST_SET_DETECTION_PARAMS: + case UAM_REQUEST_START_SEARCH_ACTIVE_DEVICES: + case UAM_REQUEST_STOP_SEARCH_ACTIVE_DEVICES: return TRUE; default: return FALSE; -- 2.7.4 From 4ebd5790ea36fd73e46046b3a2e358fd2f970ce5 Mon Sep 17 00:00:00 2001 From: Abhay agarwal Date: Tue, 28 May 2019 19:30:26 +0530 Subject: [PATCH 14/16] add app launcher Change-Id: Ie82336dfd5bb8d86174d8805bd45336aec38e7fe Signed-off-by: Abhay agarwal --- include/ua-api.h | 11 ++ include/ua-internal.h | 2 + packaging/ua-manager.spec | 2 + ua-api/src/ua-api.c | 44 ++++++++ ua-api/src/ua-event-handler.c | 1 - ua-daemon/CMakeLists.txt | 2 + ua-daemon/include/ua-manager-common.h | 4 + ua-daemon/src/pm/ua-pm-util.c | 4 +- ua-daemon/src/pm/ua-wifi-plugin-handler.c | 2 +- ua-daemon/src/ua-manager-core.c | 15 ++- ua-daemon/src/ua-manager-event-sender.c | 155 ++++++++++++++++++++++++++++- ua-daemon/src/ua-manager-request-handler.c | 20 ++++ 12 files changed, 249 insertions(+), 13 deletions(-) diff --git a/include/ua-api.h b/include/ua-api.h index cb85c46..c8453fa 100644 --- a/include/ua-api.h +++ b/include/ua-api.h @@ -42,6 +42,7 @@ extern "C" { #define UAM_IP_ADDRESS_MAX_STRING_LEN 50 #define UAM_USER_NAME_MAX_STRING_LEN 254 #define UAM_USER_ACCOUNT_MAX_STRING_LEN 254 +#define UAM_APP_ID_MAX_STRING_LEN 100 #define FOREACH_EVENT(EVENT) \ EVENT(UAM_EVENT_USER_ADDED) \ @@ -119,6 +120,10 @@ int _uam_start_search_active_devices(unsigned int bitmask, int detection_period) int _uam_stop_search_active_devices(unsigned int bitmask); +int _uam_register_app(const char *app_id, unsigned short uid); + +int _uam_deregister_app(const char *app_id, unsigned short uid); + typedef enum { UAM_PRESENCE_STATE_INVALID = 0x00, UAM_PRESENCE_STATE_PRESENT, @@ -171,6 +176,12 @@ typedef struct { int retries; } uam_detection_params_t; +typedef struct { + char* sender; + unsigned short uid; + char app_id[UAM_APP_ID_MAX_STRING_LEN]; +} uam_app_info_t; + int _uam_get_registered_users(GPtrArray **user_list); int _uam_is_device_registered( diff --git a/include/ua-internal.h b/include/ua-internal.h index f472921..6ff05bc 100644 --- a/include/ua-internal.h +++ b/include/ua-internal.h @@ -61,6 +61,8 @@ extern "C" { REQUEST(UAM_REQUEST_SET_DETECTION_PARAMS) \ REQUEST(UAM_REQUEST_START_SEARCH_ACTIVE_DEVICES) \ REQUEST(UAM_REQUEST_STOP_SEARCH_ACTIVE_DEVICES) \ + REQUEST(UAM_REQUEST_REGISTER_APP) \ + REQUEST(UAM_REQUEST_DEREGISTER_APP) \ REQUEST(UAM_REQUEST_MAX) #define GENERATE_REQUEST_ENUM(ENUM) ENUM, diff --git a/packaging/ua-manager.spec b/packaging/ua-manager.spec index 91b41b2..2b8eb1d 100644 --- a/packaging/ua-manager.spec +++ b/packaging/ua-manager.spec @@ -20,6 +20,8 @@ BuildRequires: pkgconfig(gio-unix-2.0) BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(sqlite3) BuildRequires: pkgconfig(json-c) +BuildRequires: pkgconfig(bundle) +BuildRequires: pkgconfig(aul) Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig diff --git a/ua-api/src/ua-api.c b/ua-api/src/ua-api.c index 4a7b354..6b97199 100644 --- a/ua-api/src/ua-api.c +++ b/ua-api/src/ua-api.c @@ -809,3 +809,47 @@ UAM_EXPORT_API int _uam_stop_search_active_devices(unsigned int bitmask) FUNC_EXIT; return ret; } + +UAM_EXPORT_API int _uam_register_app(const char *app_id, unsigned short uid) +{ + FUNC_ENTRY; + int ret; + uam_app_info_t app_info; + + UAM_INIT_PARAMS(); + UAM_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + g_strlcpy(app_info.app_id, app_id, UAM_APP_ID_MAX_STRING_LEN); + app_info.uid = uid; + + g_array_append_vals(in_param1, &app_info, sizeof(uam_app_info_t)); + ret = _uam_sync_request(UAM_REQUEST_REGISTER_APP, + in_param1, in_param2, in_param3, in_param4, &out_param); + + UAM_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + FUNC_EXIT; + return ret; +} + +UAM_EXPORT_API int _uam_deregister_app(const char *app_id, unsigned short uid) +{ + FUNC_ENTRY; + int ret; + uam_app_info_t app_info; + + UAM_INIT_PARAMS(); + UAM_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + g_strlcpy(app_info.app_id, app_id, UAM_APP_ID_MAX_STRING_LEN); + app_info.uid = uid; + + g_array_append_vals(in_param1, &app_info, sizeof(uam_app_info_t)); + ret = _uam_sync_request(UAM_REQUEST_DEREGISTER_APP, + in_param1, in_param2, in_param3, in_param4, &out_param); + + UAM_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + FUNC_EXIT; + return ret; +} diff --git a/ua-api/src/ua-event-handler.c b/ua-api/src/ua-event-handler.c index bf7df72..2e84f3e 100644 --- a/ua-api/src/ua-event-handler.c +++ b/ua-api/src/ua-event-handler.c @@ -17,7 +17,6 @@ #include "ua-api.h" #include "ua-internal.h" - #include "ua-common.h" typedef struct { diff --git a/ua-daemon/CMakeLists.txt b/ua-daemon/CMakeLists.txt index f957f4f..bb623bb 100644 --- a/ua-daemon/CMakeLists.txt +++ b/ua-daemon/CMakeLists.txt @@ -40,6 +40,8 @@ SET(PKG_MODULES libtzplatform-config sqlite3 json-c + bundle + aul ) INCLUDE(FindPkgConfig) diff --git a/ua-daemon/include/ua-manager-common.h b/ua-daemon/include/ua-manager-common.h index 836e2a9..c18e543 100644 --- a/ua-daemon/include/ua-manager-common.h +++ b/ua-daemon/include/ua-manager-common.h @@ -123,6 +123,10 @@ void _uam_remove_timer(guint id); const char* _uam_get_sensor_str(unsigned int ids); +int _uam_register_app_info(char* sender, uam_app_info_t app_info); + +int _uam_deregister_app_info(char* sender, uam_app_info_t app_info); + #ifdef __cplusplus } #endif diff --git a/ua-daemon/src/pm/ua-pm-util.c b/ua-daemon/src/pm/ua-pm-util.c index 08cc0fa..3467ea6 100644 --- a/ua-daemon/src/pm/ua-pm-util.c +++ b/ua-daemon/src/pm/ua-pm-util.c @@ -310,9 +310,9 @@ uam_device_info_t *_pm_util_uas_dev_info_to_uam_dev_info(const uas_device_info_t uam_active_scan_event_e _pm_util_uas_scan_event_to_uam_scan_event(uas_active_scan_event_e event) { switch (event) { - case UAS_ACTIVE_DEVICE_FOUND : + case UAS_ACTIVE_DEVICE_FOUND: return UAM_ACTIVE_DEVICE_FOUND; - case UAS_ACTIVE_SCAN_COMPLETED : + case UAS_ACTIVE_SCAN_COMPLETED: return UAM_ACTIVE_SCAN_COMPLETED; default: UAM_WARN("Unknown event 0x%8.8X", event); diff --git a/ua-daemon/src/pm/ua-wifi-plugin-handler.c b/ua-daemon/src/pm/ua-wifi-plugin-handler.c index 2c95270..d48c82d 100644 --- a/ua-daemon/src/pm/ua-wifi-plugin-handler.c +++ b/ua-daemon/src/pm/ua-wifi-plugin-handler.c @@ -115,7 +115,7 @@ static void wifi_active_scan_callback(uas_active_scan_event_e event, uam_device_info_t *dev_info = NULL; uam_active_scan_event_e event_info; - if(UAS_ACTIVE_DEVICE_FOUND == event){ + if (UAS_ACTIVE_DEVICE_FOUND == event) { ret_if(NULL == device); dev_info = _pm_util_uas_dev_info_to_uam_dev_info(device); diff --git a/ua-daemon/src/ua-manager-core.c b/ua-daemon/src/ua-manager-core.c index 9236abf..73a0c1a 100644 --- a/ua-daemon/src/ua-manager-core.c +++ b/ua-daemon/src/ua-manager-core.c @@ -2084,14 +2084,14 @@ int _uam_core_stop_search_active_devices(char *sender, unsigned int sensors) if (!scanner || !scanner->name) continue; - if (scanner->sensors & sensors){ + if (scanner->sensors & sensors) { ret = _uam_pm_stop_search_active_devices(sensors); if (UAM_ERROR_NONE != ret) { UAM_ERR("Failed with error: %s (0x%4.4X)", _uam_manager_error_to_str(ret), ret); return ret; } - scanners = g_slist_remove(scanners,scanner); + scanners = g_slist_remove(scanners, scanner); g_free(scanner->name); g_free(scanner); } @@ -2116,12 +2116,12 @@ void _uam_core_handle_active_device(uam_active_scan_event_e event, unsigned int if (!scanner || !scanner->name) continue; - if (scanner->sensors & sensor){ + if (scanner->sensors & sensor) { name = g_strdup(scanner->name); - if(event == UAM_ACTIVE_SCAN_COMPLETED){ + if (event == UAM_ACTIVE_SCAN_COMPLETED) { scanner->sensors &= ~(sensor); - if(scanner->sensors == 0){ + if (scanner->sensors == 0) { done = 1; scanners = g_slist_remove(scanners, scanner); g_free(scanner->name); @@ -2132,7 +2132,7 @@ void _uam_core_handle_active_device(uam_active_scan_event_e event, unsigned int } } - if(event == UAM_ACTIVE_DEVICE_FOUND){ + if (event == UAM_ACTIVE_DEVICE_FOUND) { param = g_variant_new("(iiisss)", UAM_ERROR_NONE, dev_info->operating_system, @@ -2144,8 +2144,7 @@ void _uam_core_handle_active_device(uam_active_scan_event_e event, unsigned int /* Send device event to application */ if (UAM_ERROR_NONE != _uam_manager_send_event(name, UAM_EVENT_DEVICE_FOUND, param)) UAM_ERR("Failed to send %s", _uam_manager_event_to_str(event)); - } - else if(done == 1 && event == UAM_ACTIVE_SCAN_COMPLETED){ + } else if (done == 1 && event == UAM_ACTIVE_SCAN_COMPLETED) { UAM_INFO_C("Send %s to applications", _uam_manager_event_to_str(UAM_EVENT_SCAN_COMPLETED)); /* Send device event to application */ if (UAM_ERROR_NONE != _uam_manager_send_event(name, UAM_EVENT_SCAN_COMPLETED, param)) diff --git a/ua-daemon/src/ua-manager-event-sender.c b/ua-daemon/src/ua-manager-event-sender.c index 2c064f6..bc8e629 100644 --- a/ua-daemon/src/ua-manager-event-sender.c +++ b/ua-daemon/src/ua-manager-event-sender.c @@ -17,9 +17,81 @@ #include "ua-api.h" #include "ua-internal.h" - #include "ua-manager-common.h" +#include +#include +#include + +GSList *apps; /* List of apps to launch - uam_app_info_t*/ + +# define APP_CONTROL_DATA_PUSH_LAUNCH_TYPE "http://tizen.org/appcontrol/data/push/launch_type" +# define EXTRA_DATA_FROM_REGISTRATION_CHANGE "registration_change" + +static void __uam_app_launcher(uam_app_info_t *app_info) +{ + FUNC_ENTRY; + int r = 0; + + r = aul_app_get_status_for_uid((const char *)app_info->app_id, app_info->uid); + UAM_INFO("returned r: [%d] ", r); + if (r == -1) { + /* Send launch request to wake application */ + UAM_INFO("[%s] will be launched for receiving registration change callback", (const char*)app_info->app_id); + + bundle *bund = NULL; + bund = bundle_create(); + + bundle_add(bund, APP_CONTROL_DATA_PUSH_LAUNCH_TYPE, EXTRA_DATA_FROM_REGISTRATION_CHANGE); + + int result; + result = aul_svc_set_background_launch(bund, TRUE); + if (result < AUL_R_OK) + UAM_ERR("ERROR : aul_svc_set_background_launch failed. app_id [%s] bundle[%p] result[%d : %s]", app_info->app_id, bund, result, get_error_message(result)); + + result = aul_launch_app_async_for_uid(app_info->app_id, bund, app_info->uid); + if (result < AUL_R_OK) + UAM_ERR("ERROR : aul_launch_app failed. app_id [%s] bundle[%p] result[%d : %s]", app_info->app_id, bund, result, get_error_message(result)); + + bundle_free(bund); + } + FUNC_EXIT; +} + +static void __uam_resume_app(const char* dest) +{ + FUNC_ENTRY; + GSList *l; + + UAM_INFO("dest: [%s] ", dest); + if (NULL == dest) { + for (l = apps; NULL != l; l = g_slist_next(l)) { + uam_app_info_t *app_info = l->data; + if (NULL == app_info) + continue; + + UAM_INFO("app_id: [%s] ", (const char*)app_info->app_id); + UAM_INFO("uid: [%d] ", app_info->uid); + __uam_app_launcher(app_info); + } + } else { + for (l = apps; NULL != l; l = g_slist_next(l)) { + uam_app_info_t *app_info = l->data; + if (NULL == app_info) + continue; + + UAM_INFO("app_id: [%s] ", (const char*)app_info->app_id); + UAM_INFO("uid: [%d] ", app_info->uid); + if (!g_strcmp0(app_info->sender, dest)) { + __uam_app_launcher(app_info); + break; + } + } + } + + FUNC_EXIT; +} + int _uam_manager_send_event( const char* dest, int event, GVariant *param) { @@ -82,6 +154,9 @@ int _uam_manager_send_event( UAM_INFO_C("Destination: [%s], event: [%s], signal: [%s]", dest, _uam_manager_event_to_str(event), signal); + /* Check if application requires resume before sending event */ + __uam_resume_app(dest); + if (!g_dbus_connection_emit_signal(conn, dest, UAM_EVENT_PATH, UAM_EVENT_INTERFACE, signal, param, &error)) { UAM_ERR("Error while sending Signal: %s", signal); @@ -97,3 +172,81 @@ int _uam_manager_send_event( FUNC_EXIT; return UAM_ERROR_NONE; } + +static uam_app_info_t *__uam_find_app(const char *name) +{ +// FUNC_ENTRY; + GSList *l; + + retv_if(NULL == name, NULL); + + for (l = apps; NULL != l; l = g_slist_next(l)) { + uam_app_info_t *app_info = l->data; + + if (!app_info || !app_info->sender) + continue; + + if (0 == g_strcmp0(app_info->sender, name)) { + UAM_DBG("Monitoring application found in list"); + return app_info; + } + } + +// FUNC_EXIT; + return NULL; +} + +int _uam_register_app_info(char* sender, uam_app_info_t app_info) +{ + FUNC_ENTRY; + + int ret; + uam_app_info_t *app; + + app = __uam_find_app(sender); + + if (app) { + ret = UAM_ERROR_ALREADY_DONE; + UAM_ERR("Failed with error: %s (0x%4.4X)", + _uam_manager_error_to_str(ret), ret); + return ret; + } + + app = g_malloc0(sizeof(uam_app_info_t)); + app->sender = g_strdup(sender); + g_strlcpy(app->app_id, app_info.app_id, UAM_APP_ID_MAX_STRING_LEN); + app->uid = app_info.uid; + + apps = g_slist_append(apps, app); + ret = UAM_ERROR_NONE; + + FUNC_EXIT; + return ret; +} + +int _uam_deregister_app_info(char* sender, uam_app_info_t app_info) +{ + FUNC_ENTRY; + + int ret; + uam_app_info_t *app; + + app = __uam_find_app(sender); + + if (!app) { + ret = UAM_ERROR_ALREADY_DONE; + UAM_ERR("Failed with error: %s (0x%4.4X)", + _uam_manager_error_to_str(ret), ret); + return ret; + } + + UAM_DBG("Remove app from list"); + apps = g_slist_remove(apps, app); + g_free(app->sender); + g_free(app); + + ret = UAM_ERROR_NONE; + + FUNC_EXIT; + return ret; +} diff --git a/ua-daemon/src/ua-manager-request-handler.c b/ua-daemon/src/ua-manager-request-handler.c index 8435c78..9d515e9 100644 --- a/ua-daemon/src/ua-manager-request-handler.c +++ b/ua-daemon/src/ua-manager-request-handler.c @@ -412,6 +412,24 @@ static int __uam_manager_sync_request_handler( result = _uam_core_stop_search_active_devices(sender, sensors); break; } + case UAM_REQUEST_REGISTER_APP: { + uam_app_info_t app_info; + + __uam_manager_copy_params(in_param1, + &app_info, sizeof(uam_app_info_t)); + + result = _uam_register_app_info(sender, app_info); + break; + } + case UAM_REQUEST_DEREGISTER_APP: { + uam_app_info_t app_info; + + __uam_manager_copy_params(in_param1, + &app_info, sizeof(uam_app_info_t)); + + result = _uam_deregister_app_info(sender, app_info); + break; + } default: UAM_WARN("UnSupported function [%s(0x%4.4X)]", _uam_manager_request_to_str(function), function); @@ -545,6 +563,8 @@ static gboolean __uam_manager_is_sync_function(int function) case UAM_REQUEST_SET_DETECTION_PARAMS: case UAM_REQUEST_START_SEARCH_ACTIVE_DEVICES: case UAM_REQUEST_STOP_SEARCH_ACTIVE_DEVICES: + case UAM_REQUEST_REGISTER_APP: + case UAM_REQUEST_DEREGISTER_APP: return TRUE; default: return FALSE; -- 2.7.4 From 72bfa6529331a6f31d09e7852bf33c4e03fddae4 Mon Sep 17 00:00:00 2001 From: saerome kim Date: Mon, 3 Jun 2019 20:30:24 +0900 Subject: [PATCH 15/16] Fixed Tizen coding rule violations Change-Id: I86eeae7d65d58398e1d4be3c10e48180c8a1decd Signed-off-by: saerome kim --- include/ua-api.h | 28 ++++++++--------- ua-api/src/ua-api.c | 42 +++++++++++++++----------- ua-api/src/ua-event-handler.c | 48 ++++++++++-------------------- ua-daemon/include/ua-manager-common.h | 6 ++-- ua-daemon/src/pm/ua-cloud-plugin-handler.c | 2 +- ua-daemon/src/ua-manager-core.c | 16 ++++------ ua-daemon/src/ua-manager-event-sender.c | 8 ++--- 7 files changed, 68 insertions(+), 82 deletions(-) diff --git a/include/ua-api.h b/include/ua-api.h index c8453fa..ad4fb43 100644 --- a/include/ua-api.h +++ b/include/ua-api.h @@ -177,7 +177,7 @@ typedef struct { } uam_detection_params_t; typedef struct { - char* sender; + char *sender; unsigned short uid; char app_id[UAM_APP_ID_MAX_STRING_LEN]; } uam_app_info_t; @@ -195,33 +195,33 @@ int _uam_deinit(void); int _uam_get_available_sensors(unsigned int *bitmask); -int _uam_get_default_user(uam_user_info_t* uam_user); +int _uam_get_default_user(uam_user_info_t * uam_user); -int _uam_add_user(uam_user_info_t* user); +int _uam_add_user(uam_user_info_t * user); -int _uam_remove_user(char* account); +int _uam_remove_user(char *account); -int _uam_request_get_user_by_account(char* account, uam_user_info_t* user); +int _uam_request_get_user_by_account(char *account, uam_user_info_t * user); -int _uam_request_get_user_by_deviceid(char* device_id, uam_user_info_t* user); +int _uam_request_get_user_by_deviceid(char *device_id, uam_user_info_t * user); -int _uam_request_get_user_by_mac(char* mac, uam_user_info_t* user); +int _uam_request_get_user_by_mac(char *mac, uam_user_info_t * user); -int _uam_request_add_device(char* account, uam_device_info_t* device); +int _uam_request_add_device(char *account, uam_device_info_t *device); -int _uam_request_remove_device(char* account, uam_device_info_t* device); +int _uam_request_remove_device(char *account, uam_device_info_t *device); -int _uam_request_remove_device_by_deviceid(const char* device_id, uam_tech_type_e tech_type); +int _uam_request_remove_device_by_deviceid(const char *device_id, uam_tech_type_e tech_type); -int _uam_request_remove_device_by_mac(const char* mac); +int _uam_request_remove_device_by_mac(const char *mac); -int _uam_request_get_device_by_deviceid(const char* device_id, uam_tech_type_e tech_type, uam_device_info_t* device); +int _uam_request_get_device_by_deviceid(const char *device_id, uam_tech_type_e tech_type, uam_device_info_t *device); -int _uam_request_get_device_by_mac(const char* mac, uam_device_info_t* device); +int _uam_request_get_device_by_mac(const char *mac, uam_device_info_t *device); int _uam_request_get_devices(GPtrArray **devices_list); -int _uam_request_get_user_devices(char* account, GPtrArray **devices_list); +int _uam_request_get_user_devices(char *account, GPtrArray **devices_list); int _uam_request_set_detection_threshold(unsigned int sensor_type, int presence_threshold, int absence_threshold); diff --git a/ua-api/src/ua-api.c b/ua-api/src/ua-api.c index 6b97199..900b142 100644 --- a/ua-api/src/ua-api.c +++ b/ua-api/src/ua-api.c @@ -144,7 +144,7 @@ UAM_EXPORT_API int _uam_is_device_registered(uam_device_info_t *dev_info, gboole return ret; } -UAM_EXPORT_API int _uam_get_default_user(uam_user_info_t* user) +UAM_EXPORT_API int _uam_get_default_user(uam_user_info_t *user) { FUNC_ENTRY; int ret; @@ -159,7 +159,7 @@ UAM_EXPORT_API int _uam_get_default_user(uam_user_info_t* user) if (UAM_ERROR_NONE == ret) { if (out_param->len > 0) { - uam_user_info_t* info; + uam_user_info_t *info; info = &g_array_index(out_param, uam_user_info_t, 0); memcpy(user, info, sizeof(uam_user_info_t)); @@ -174,7 +174,7 @@ UAM_EXPORT_API int _uam_get_default_user(uam_user_info_t* user) return ret; } -UAM_EXPORT_API int _uam_add_user(uam_user_info_t* user) +UAM_EXPORT_API int _uam_add_user(uam_user_info_t *user) { FUNC_ENTRY; int ret; @@ -202,7 +202,7 @@ UAM_EXPORT_API int _uam_add_user(uam_user_info_t* user) return ret; } -UAM_EXPORT_API int _uam_remove_user(char* account) +UAM_EXPORT_API int _uam_remove_user(char *account) { FUNC_ENTRY; int ret; @@ -224,7 +224,8 @@ UAM_EXPORT_API int _uam_remove_user(char* account) return ret; } -UAM_EXPORT_API int _uam_request_get_user_by_account(char* account, uam_user_info_t* user) +UAM_EXPORT_API int _uam_request_get_user_by_account(char *account, + uam_user_info_t *user) { FUNC_ENTRY; int ret; @@ -243,7 +244,7 @@ UAM_EXPORT_API int _uam_request_get_user_by_account(char* account, uam_user_info if (UAM_ERROR_NONE == ret) { if (out_param->len > 0) { - uam_user_info_t* info; + uam_user_info_t *info; info = &g_array_index(out_param, uam_user_info_t, 0); memcpy(user, info, sizeof(uam_user_info_t)); @@ -258,7 +259,8 @@ UAM_EXPORT_API int _uam_request_get_user_by_account(char* account, uam_user_info return ret; } -UAM_EXPORT_API int _uam_request_get_user_by_deviceid(char* device_id, uam_user_info_t* user) +UAM_EXPORT_API int _uam_request_get_user_by_deviceid(char *device_id, + uam_user_info_t *user) { FUNC_ENTRY; int ret; @@ -277,7 +279,7 @@ UAM_EXPORT_API int _uam_request_get_user_by_deviceid(char* device_id, uam_user_i if (UAM_ERROR_NONE == ret) { if (out_param->len > 0) { - uam_user_info_t* info; + uam_user_info_t * info; info = &g_array_index(out_param, uam_user_info_t, 0); memcpy(user, info, sizeof(uam_user_info_t)); @@ -292,7 +294,8 @@ UAM_EXPORT_API int _uam_request_get_user_by_deviceid(char* device_id, uam_user_i return ret; } -UAM_EXPORT_API int _uam_request_get_user_by_mac(char* mac, uam_user_info_t* user) +UAM_EXPORT_API int _uam_request_get_user_by_mac(char *mac, + uam_user_info_t *user) { FUNC_ENTRY; int ret; @@ -311,7 +314,7 @@ UAM_EXPORT_API int _uam_request_get_user_by_mac(char* mac, uam_user_info_t* user if (UAM_ERROR_NONE == ret) { if (out_param->len > 0) { - uam_user_info_t* info; + uam_user_info_t * info; info = &g_array_index(out_param, uam_user_info_t, 0); memcpy(user, info, sizeof(uam_user_info_t)); @@ -326,7 +329,8 @@ UAM_EXPORT_API int _uam_request_get_user_by_mac(char* mac, uam_user_info_t* user return ret; } -UAM_EXPORT_API int _uam_request_add_device(char* account, uam_device_info_t* device) +UAM_EXPORT_API int _uam_request_add_device(char *account, + uam_device_info_t *device) { FUNC_ENTRY; int ret; @@ -350,7 +354,8 @@ UAM_EXPORT_API int _uam_request_add_device(char* account, uam_device_info_t* dev return ret; } -UAM_EXPORT_API int _uam_request_remove_device(char* account, uam_device_info_t* device) +UAM_EXPORT_API int _uam_request_remove_device(char *account, + uam_device_info_t *device) { FUNC_ENTRY; int ret; @@ -374,7 +379,8 @@ UAM_EXPORT_API int _uam_request_remove_device(char* account, uam_device_info_t* return ret; } -UAM_EXPORT_API int _uam_request_remove_device_by_deviceid(const char* device_id, uam_tech_type_e tech_type) +UAM_EXPORT_API int _uam_request_remove_device_by_deviceid( + const char *device_id, uam_tech_type_e tech_type) { FUNC_ENTRY; int ret; @@ -397,7 +403,7 @@ UAM_EXPORT_API int _uam_request_remove_device_by_deviceid(const char* device_id, return ret; } -UAM_EXPORT_API int _uam_request_remove_device_by_mac(const char* mac) +UAM_EXPORT_API int _uam_request_remove_device_by_mac(const char *mac) { FUNC_ENTRY; int ret; @@ -419,7 +425,8 @@ UAM_EXPORT_API int _uam_request_remove_device_by_mac(const char* mac) return ret; } -UAM_EXPORT_API int _uam_request_get_device_by_deviceid(const char* device_id, uam_tech_type_e tech_type, uam_device_info_t* device) +UAM_EXPORT_API int _uam_request_get_device_by_deviceid(const char *device_id, + uam_tech_type_e tech_type, uam_device_info_t *device) { FUNC_ENTRY; int ret; @@ -454,7 +461,8 @@ UAM_EXPORT_API int _uam_request_get_device_by_deviceid(const char* device_id, ua return ret; } -UAM_EXPORT_API int _uam_request_get_device_by_mac(const char* mac, uam_device_info_t* device) +UAM_EXPORT_API int _uam_request_get_device_by_mac(const char *mac, + uam_device_info_t *device) { FUNC_ENTRY; int ret; @@ -525,7 +533,7 @@ UAM_EXPORT_API int _uam_request_get_devices(GPtrArray **devices_list) return ret; } -UAM_EXPORT_API int _uam_request_get_user_devices(char* account, GPtrArray **devices_list) +UAM_EXPORT_API int _uam_request_get_user_devices(char *account, GPtrArray **devices_list) { FUNC_ENTRY; int ret; diff --git a/ua-api/src/ua-event-handler.c b/ua-api/src/ua-event-handler.c index 2e84f3e..42fae20 100644 --- a/ua-api/src/ua-event-handler.c +++ b/ua-api/src/ua-event-handler.c @@ -65,16 +65,13 @@ static void __uam_event_handler(GDBusConnection *connection, ret_if(NULL == event_info); - if (0 != strncasecmp(object_path, - UAM_EVENT_PATH, strlen(UAM_EVENT_PATH))) + if (0 != strcasecmp(object_path, UAM_EVENT_PATH)) return; - if (0 != strncasecmp(interface_name, - UAM_EVENT_INTERFACE, strlen(UAM_EVENT_INTERFACE))) + if (0 != strcasecmp(interface_name, UAM_EVENT_INTERFACE)) return; - if (0 == strncasecmp(signal_name, UAM_SIGNAL_USER_PRESENCE_DETECTED, - strlen(UAM_SIGNAL_USER_PRESENCE_DETECTED))) { + if (0 == strcasecmp(signal_name, UAM_SIGNAL_USER_PRESENCE_DETECTED)) { uam_detection_event_data_t event_data; unsigned int sensor_bitmask; char *account = NULL; @@ -89,8 +86,7 @@ static void __uam_event_handler(GDBusConnection *connection, __uam_send_event(event, result, &event_data, event_info->cb, event_info->user_data); - } else if (0 == strncasecmp(signal_name, UAM_SIGNAL_USER_ABSENCE_DETECTED, - strlen(UAM_SIGNAL_USER_ABSENCE_DETECTED))) { + } else if (0 == strcasecmp(signal_name, UAM_SIGNAL_USER_ABSENCE_DETECTED)) { uam_detection_event_data_t event_data; unsigned int sensor_bitmask; char *account = NULL; @@ -105,8 +101,7 @@ static void __uam_event_handler(GDBusConnection *connection, __uam_send_event(event, result, &event_data, event_info->cb, event_info->user_data); - } else if (0 == strncasecmp(signal_name, UAM_SIGNAL_PRESENCE_DETECTED, - strlen(UAM_SIGNAL_PRESENCE_DETECTED))) { + } else if (0 == strcasecmp(signal_name, UAM_SIGNAL_PRESENCE_DETECTED)) { unsigned int sensor_bitmask; g_variant_get(parameters, "(u)", &sensor_bitmask); @@ -115,8 +110,7 @@ static void __uam_event_handler(GDBusConnection *connection, __uam_send_event(event, result, &sensor_bitmask, event_info->cb, event_info->user_data); - } else if (0 == strncasecmp(signal_name, UAM_SIGNAL_ABSENCE_DETECTED, - strlen(UAM_SIGNAL_ABSENCE_DETECTED))) { + } else if (0 == strcasecmp(signal_name, UAM_SIGNAL_ABSENCE_DETECTED)) { unsigned int sensor_bitmask; g_variant_get(parameters, "(u)", &sensor_bitmask); @@ -124,8 +118,7 @@ static void __uam_event_handler(GDBusConnection *connection, __uam_send_event(event, result, &sensor_bitmask, event_info->cb, event_info->user_data); - } else if (0 == strncasecmp(signal_name, UAM_SIGNAL_SENSOR_STATE_READY, - strlen(UAM_SIGNAL_SENSOR_STATE_READY))) { + } else if (0 == strcasecmp(signal_name, UAM_SIGNAL_SENSOR_STATE_READY)) { unsigned int sensor; g_variant_get(parameters, "(iu)", &result, @@ -134,8 +127,7 @@ static void __uam_event_handler(GDBusConnection *connection, event = UAM_EVENT_SENSOR_STATE_READY; __uam_send_event(event, result, &sensor, event_info->cb, event_info->user_data); - } else if (0 == strncasecmp(signal_name, UAM_SIGNAL_SENSOR_STATE_NOT_READY, - strlen(UAM_SIGNAL_SENSOR_STATE_NOT_READY))) { + } else if (0 == strcasecmp(signal_name, UAM_SIGNAL_SENSOR_STATE_NOT_READY)) { unsigned int sensor; g_variant_get(parameters, "(iu)", &result, @@ -144,8 +136,7 @@ static void __uam_event_handler(GDBusConnection *connection, event = UAM_EVENT_SENSOR_STATE_NOT_READY; __uam_send_event(event, result, &sensor, event_info->cb, event_info->user_data); - } else if (0 == strncasecmp(signal_name, UAM_SIGNAL_USER_ADDED, - strlen(UAM_SIGNAL_USER_ADDED))) { + } else if (0 == strcasecmp(signal_name, UAM_SIGNAL_USER_ADDED)) { uam_user_info_t user_info; char *account = NULL; char *name = NULL; @@ -162,8 +153,7 @@ static void __uam_event_handler(GDBusConnection *connection, event = UAM_EVENT_USER_ADDED; __uam_send_event(event, result, &user_info, event_info->cb, event_info->user_data); - } else if (0 == strncasecmp(signal_name, UAM_SIGNAL_USER_REMOVED, - strlen(UAM_SIGNAL_USER_REMOVED))) { + } else if (0 == strcasecmp(signal_name, UAM_SIGNAL_USER_REMOVED)) { uam_user_info_t user_info; char *account = NULL; char *name = NULL; @@ -180,8 +170,7 @@ static void __uam_event_handler(GDBusConnection *connection, event = UAM_EVENT_USER_REMOVED; __uam_send_event(event, result, &user_info, event_info->cb, event_info->user_data); - } else if (0 == strncasecmp(signal_name, UAM_SIGNAL_DEVICE_ADDED, - strlen(UAM_SIGNAL_DEVICE_ADDED))) { + } else if (0 == strcasecmp(signal_name, UAM_SIGNAL_DEVICE_ADDED)) { uam_device_info_t dev_info; int os, type; char *mac = NULL; @@ -203,8 +192,7 @@ static void __uam_event_handler(GDBusConnection *connection, event = UAM_EVENT_DEVICE_ADDED; __uam_send_event(event, result, &dev_info, event_info->cb, event_info->user_data); - } else if (0 == strncasecmp(signal_name, UAM_SIGNAL_DEVICE_REMOVED, - strlen(UAM_SIGNAL_DEVICE_REMOVED))) { + } else if (0 == strcasecmp(signal_name, UAM_SIGNAL_DEVICE_REMOVED)) { uam_device_info_t dev_info; int os, type; char *mac = NULL; @@ -226,16 +214,13 @@ static void __uam_event_handler(GDBusConnection *connection, event = UAM_EVENT_DEVICE_REMOVED; __uam_send_event(event, result, &dev_info, event_info->cb, event_info->user_data); - } else if (0 == strncasecmp(signal_name, UAM_SIGNAL_DETECTION_STARTED, - strlen(UAM_SIGNAL_DETECTION_STARTED))) { + } else if (0 == strcasecmp(signal_name, UAM_SIGNAL_DETECTION_STARTED)) { __uam_send_event(UAM_EVENT_DETECTION_STARTED, result, NULL, event_info->cb, event_info->user_data); - } else if (0 == strncasecmp(signal_name, UAM_SIGNAL_DETECTION_STOPPED, - strlen(UAM_SIGNAL_DETECTION_STOPPED))) { + } else if (0 == strcasecmp(signal_name, UAM_SIGNAL_DETECTION_STOPPED)) { __uam_send_event(UAM_EVENT_DETECTION_STOPPED, result, NULL, event_info->cb, event_info->user_data); - } else if (0 == strncasecmp(signal_name, UAM_SIGNAL_DEVICE_FOUND, - strlen(UAM_SIGNAL_DEVICE_FOUND))) { + } else if (0 == strcasecmp(signal_name, UAM_SIGNAL_DEVICE_FOUND)) { uam_device_info_t dev_info; int os, type; char *mac = NULL; @@ -257,8 +242,7 @@ static void __uam_event_handler(GDBusConnection *connection, event = UAM_EVENT_DEVICE_FOUND; __uam_send_event(event, result, &dev_info, event_info->cb, event_info->user_data); - } else if (0 == strncasecmp(signal_name, UAM_SIGNAL_SCAN_COMPLETED, - strlen(UAM_SIGNAL_SCAN_COMPLETED))) { + } else if (0 == strcasecmp(signal_name, UAM_SIGNAL_SCAN_COMPLETED)) { event = UAM_EVENT_SCAN_COMPLETED; __uam_send_event(event, result, NULL, diff --git a/ua-daemon/include/ua-manager-common.h b/ua-daemon/include/ua-manager-common.h index c18e543..21941b3 100644 --- a/ua-daemon/include/ua-manager-common.h +++ b/ua-daemon/include/ua-manager-common.h @@ -100,7 +100,7 @@ void _uam_manager_method_return( GArray *out_param, int result); int _uam_manager_send_event( - const char* dest, int event, GVariant *param); + const char *dest, int event, GVariant *param); GDBusConnection *_uam_manager_get_gdbus_conn(void); @@ -123,9 +123,9 @@ void _uam_remove_timer(guint id); const char* _uam_get_sensor_str(unsigned int ids); -int _uam_register_app_info(char* sender, uam_app_info_t app_info); +int _uam_register_app_info(char *sender, uam_app_info_t app_info); -int _uam_deregister_app_info(char* sender, uam_app_info_t app_info); +int _uam_deregister_app_info(char *sender, uam_app_info_t app_info); #ifdef __cplusplus } diff --git a/ua-daemon/src/pm/ua-cloud-plugin-handler.c b/ua-daemon/src/pm/ua-cloud-plugin-handler.c index 8fd4b06..b61a0f9 100644 --- a/ua-daemon/src/pm/ua-cloud-plugin-handler.c +++ b/ua-daemon/src/pm/ua-cloud-plugin-handler.c @@ -123,7 +123,7 @@ static int add_device(const char *account, uap_device_info_t *dev_info) return UAP_STATUS_SUCCESS; } -static int remove_device(const char* device_id, int type) +static int remove_device(const char *device_id, int type) { FUNC_ENTRY; diff --git a/ua-daemon/src/ua-manager-core.c b/ua-daemon/src/ua-manager-core.c index 73a0c1a..be48631 100644 --- a/ua-daemon/src/ua-manager-core.c +++ b/ua-daemon/src/ua-manager-core.c @@ -306,8 +306,7 @@ static uam_db_tech_info_t *__get_tech_info_by_mac(const char *mac) UAM_ADDR_TYPE_BT == addr->addr_type || UAM_ADDR_TYPE_P2P == addr->addr_type || UAM_ADDR_TYPE_WIFI == addr->addr_type) - if (!strncasecmp(addr->address, mac, - UAM_MAC_ADDRESS_STRING_LEN)) { + if (!strcasecmp(addr->address, mac)) { UAM_DBG("Device found Mac: %s, type: %d", addr->address, addr->addr_type); return tech; @@ -735,8 +734,7 @@ int _uam_core_is_device_added(uam_device_info_t *dev, gboolean *is_added) UAM_ADDR_TYPE_BT == addr->addr_type || UAM_ADDR_TYPE_P2P == addr->addr_type || UAM_ADDR_TYPE_WIFI == addr->addr_type) - if (!strncasecmp(addr->address, dev->mac, - UAM_MAC_ADDRESS_STRING_LEN)) { + if (!strcasecmp(addr->address, dev->mac)) { *is_added = TRUE; break; } @@ -1607,8 +1605,7 @@ void _uam_core_handle_device_added(int status, } if (dev->type != dev_info->type || - strncasecmp(dev->device_id, dev_info->device_id, - UAM_DEVICE_ID_MAX_STRING_LEN)) { + strcasecmp(dev->device_id, dev_info->device_id)) { UAM_WARN("[%d != %d] || [%s != %s]", dev->type, dev_info->type, dev->device_id, dev_info->device_id); _uam_manager_remove_req_ctxt_from_list(info); @@ -1749,8 +1746,7 @@ void _uam_core_handle_presence_detected(unsigned int sensor, if (!addr || (UAM_ADDR_TYPE_IPv4 != addr->addr_type)) continue; - if (!strncasecmp(addr->address, dev_info->ipv4_addr, - UAM_MAC_ADDRESS_STRING_LEN)) + if (!strcasecmp(addr->address, dev_info->ipv4_addr)) is_updated = FALSE; else UAM_DBG("Old IPv4: %s, New IPv4: %s", @@ -2054,7 +2050,6 @@ int _uam_core_start_search_active_devices(char *sender, unsigned int sensors, in } ret = _uam_pm_start_search_active_devices(&sensors, detection_period); - if (UAM_ERROR_NONE != ret) { UAM_ERR("Failed with error: %s (0x%4.4X)", _uam_manager_error_to_str(ret), ret); @@ -2108,7 +2103,7 @@ void _uam_core_handle_active_device(uam_active_scan_event_e event, unsigned int GVariant *param = NULL; GSList *l; int done = 0; - char* name = NULL; + char *name = NULL; for (l = scanners; NULL != l; l = g_slist_next(l)) { uam_monitor_info_t *scanner = (uam_monitor_info_t *)l->data; @@ -2117,7 +2112,6 @@ void _uam_core_handle_active_device(uam_active_scan_event_e event, unsigned int continue; if (scanner->sensors & sensor) { - name = g_strdup(scanner->name); if (event == UAM_ACTIVE_SCAN_COMPLETED) { scanner->sensors &= ~(sensor); diff --git a/ua-daemon/src/ua-manager-event-sender.c b/ua-daemon/src/ua-manager-event-sender.c index bc8e629..5f40dc5 100644 --- a/ua-daemon/src/ua-manager-event-sender.c +++ b/ua-daemon/src/ua-manager-event-sender.c @@ -58,7 +58,7 @@ static void __uam_app_launcher(uam_app_info_t *app_info) FUNC_EXIT; } -static void __uam_resume_app(const char* dest) +static void __uam_resume_app(const char *dest) { FUNC_ENTRY; GSList *l; @@ -93,7 +93,7 @@ static void __uam_resume_app(const char* dest) } int _uam_manager_send_event( - const char* dest, int event, GVariant *param) + const char *dest, int event, GVariant *param) { FUNC_ENTRY; char *signal; @@ -196,7 +196,7 @@ static uam_app_info_t *__uam_find_app(const char *name) return NULL; } -int _uam_register_app_info(char* sender, uam_app_info_t app_info) +int _uam_register_app_info(char *sender, uam_app_info_t app_info) { FUNC_ENTRY; @@ -224,7 +224,7 @@ int _uam_register_app_info(char* sender, uam_app_info_t app_info) return ret; } -int _uam_deregister_app_info(char* sender, uam_app_info_t app_info) +int _uam_deregister_app_info(char *sender, uam_app_info_t app_info) { FUNC_ENTRY; -- 2.7.4 From 0d3c7c94e8d2c8d1bd9ed0338e3a930402f5a538 Mon Sep 17 00:00:00 2001 From: Atul Rai Date: Tue, 4 Jun 2019 15:04:38 +0530 Subject: [PATCH 16/16] Fixed start/stop active scan functionality This patch adds support to handle start/stop active scan from multiple applications simultaneously. Change-Id: Ief32d9b9b743fc9d76731aee1829baf9b9536452 Signed-off-by: Atul Rai --- ua-api/src/ua-request-sender.c | 3 +- ua-daemon/include/ua-manager-core.h | 4 +- ua-daemon/include/ua-plugin-manager.h | 4 +- ua-daemon/src/pm/ua-plugin-manager.c | 4 +- ua-daemon/src/ua-manager-core.c | 196 +++++++++++++++++------------ ua-daemon/src/ua-manager-request-handler.c | 4 +- 6 files changed, 128 insertions(+), 87 deletions(-) diff --git a/ua-api/src/ua-request-sender.c b/ua-api/src/ua-request-sender.c index 312accf..dfe52da 100644 --- a/ua-api/src/ua-request-sender.c +++ b/ua-api/src/ua-request-sender.c @@ -297,9 +297,8 @@ static void __uam_async_request_cb( } done: - if (out_param) { + if (out_param) g_array_free(out_param, TRUE); - } if (req_info) { pending_requests = g_slist_remove( diff --git a/ua-daemon/include/ua-manager-core.h b/ua-daemon/include/ua-manager-core.h index 2d64e66..f56506a 100644 --- a/ua-daemon/include/ua-manager-core.h +++ b/ua-daemon/include/ua-manager-core.h @@ -155,9 +155,9 @@ void _uam_core_handle_detection_started(unsigned int sensor); void _uam_core_handle_detection_stopped(unsigned int sensor); -int _uam_core_start_search_active_devices(char *sender, unsigned int sensors, int detection_period); +int _uam_core_start_active_device_scan(char *sender, unsigned int sensors, int detection_period); -int _uam_core_stop_search_active_devices(char *sender, unsigned int sensors); +int _uam_core_stop_active_device_scan(char *sender, unsigned int sensors); void _uam_core_handle_active_device(uam_active_scan_event_e event, unsigned int sensor, const uam_device_info_t *dev_info); diff --git a/ua-daemon/include/ua-plugin-manager.h b/ua-daemon/include/ua-plugin-manager.h index b26d354..94b5080 100644 --- a/ua-daemon/include/ua-plugin-manager.h +++ b/ua-daemon/include/ua-plugin-manager.h @@ -58,9 +58,9 @@ int _uam_pm_set_detection_params(unsigned int sensor, int detection_cycle, int _uam_pm_set_detection_threshold(unsigned int sensor, int presence_threshold, int absence_threshold); -int _uam_pm_start_search_active_devices(unsigned int* bitmask, int detection_period); +int _uam_pm_start_active_device_scan(unsigned int* bitmask, int detection_period); -int _uam_pm_stop_search_active_devices(unsigned int bitmask); +int _uam_pm_stop_active_device_scan(unsigned int bitmask); #ifdef __cplusplus } diff --git a/ua-daemon/src/pm/ua-plugin-manager.c b/ua-daemon/src/pm/ua-plugin-manager.c index a338bb3..16da30d 100644 --- a/ua-daemon/src/pm/ua-plugin-manager.c +++ b/ua-daemon/src/pm/ua-plugin-manager.c @@ -669,7 +669,7 @@ int _uam_pm_set_detection_threshold(unsigned int sensor, return UAM_ERROR_NONE; } -int _uam_pm_start_search_active_devices(unsigned int* bitmask, int detection_period) +int _uam_pm_start_active_device_scan(unsigned int* bitmask, int detection_period) { FUNC_ENTRY; int id; @@ -706,7 +706,7 @@ int _uam_pm_start_search_active_devices(unsigned int* bitmask, int detection_per return ret; } -int _uam_pm_stop_search_active_devices(unsigned int bitmask) +int _uam_pm_stop_active_device_scan(unsigned int bitmask) { FUNC_ENTRY; int id; diff --git a/ua-daemon/src/ua-manager-core.c b/ua-daemon/src/ua-manager-core.c index be48631..355eb7e 100644 --- a/ua-daemon/src/ua-manager-core.c +++ b/ua-daemon/src/ua-manager-core.c @@ -38,6 +38,12 @@ typedef struct { uam_pm_detection_mode_e mode; } uam_monitor_info_t; +typedef struct { + char *name; + unsigned int sensors; + guint timer; +} uam_scanner_info_t; + GSList *monitors; /* List of monitoring apps - uam_monitor_info_t */ GSList *users; /* List of users - uam_db_user_info_t */ GSList *devices; /* List of devices - uam_db_device_info_t */ @@ -2001,15 +2007,14 @@ void _uam_core_handle_detection_stopped(unsigned int sensor) FUNC_EXIT; } -static uam_monitor_info_t *__uam_find_scanner(const char *name) +static uam_scanner_info_t *__uam_find_scanner(const char *name) { -// FUNC_ENTRY; GSList *l; retv_if(NULL == name, NULL); for (l = scanners; NULL != l; l = g_slist_next(l)) { - uam_monitor_info_t *scanner = l->data; + uam_scanner_info_t *scanner = l->data; if (!scanner || !scanner->name) continue; @@ -2020,75 +2025,105 @@ static uam_monitor_info_t *__uam_find_scanner(const char *name) } } -// FUNC_EXIT; return NULL; } -int _uam_core_start_search_active_devices(char *sender, unsigned int sensors, int detection_period) +static gboolean __scan_completed_cb(gpointer data) +{ + FUNC_ENTRY; + uam_scanner_info_t *scanner = data; + + retv_if(NULL == scanner, FALSE); + + if (UAM_ERROR_NONE != _uam_manager_send_event( + scanner->name, UAM_EVENT_SCAN_COMPLETED, NULL)) + UAM_ERR("Failed to send UAM_EVENT_SCAN_COMPLETED"); + else + UAM_INFO_C("Sent UAM_EVENT_SCAN_COMPLETED to [%s]", scanner->name); + + /* Free scanner */ + scanners = g_slist_remove(scanners, scanner); + g_free(scanner->name); + g_free(scanner); + + FUNC_EXIT; + return FALSE; +} + +int _uam_core_start_active_device_scan(char *sender, unsigned int sensors, int detection_period) { FUNC_ENTRY; int ret; - uam_monitor_info_t *scanner; - GSList *l; + uam_scanner_info_t *scanner; retv_if(NULL == sender, UAM_ERROR_INVALID_PARAM); + retv_if(0 == sensors, UAM_ERROR_INVALID_PARAM); scanner = __uam_find_scanner(sender); - if (scanner) { - ret = UAM_ERROR_NOW_IN_PROGRESS; - UAM_ERR("Failed with error: %s (0x%4.4X)", - _uam_manager_error_to_str(ret), ret); - return ret; - } + retv_if(NULL != scanner, UAM_ERROR_NOW_IN_PROGRESS); - for (l = scanners; NULL != l; l = g_slist_next(l)) { - uam_monitor_info_t *scanner_data = l->data; - - if (!scanner_data || !scanner_data->name) - continue; - sensors &= ~(scanner_data->sensors); - } - - ret = _uam_pm_start_search_active_devices(&sensors, detection_period); + ret = _uam_pm_start_active_device_scan(&sensors, detection_period); if (UAM_ERROR_NONE != ret) { UAM_ERR("Failed with error: %s (0x%4.4X)", _uam_manager_error_to_str(ret), ret); return ret; } - scanner = g_malloc0(sizeof(uam_monitor_info_t)); + scanner = g_malloc0(sizeof(uam_scanner_info_t)); scanner->name = g_strdup(sender); scanner->sensors |= sensors; + scanner->timer = g_timeout_add_seconds(detection_period, + __scan_completed_cb, scanner); scanners = g_slist_append(scanners, scanner); + UAM_DBG("sensors = 0x%8.8X - 0x%8.8X", scanner->sensors, sensors); FUNC_EXIT; return UAM_ERROR_NONE; } -int _uam_core_stop_search_active_devices(char *sender, unsigned int sensors) +int _uam_core_stop_active_device_scan(char *sender, unsigned int sensors) { FUNC_ENTRY; int ret; - + uam_scanner_info_t *scanner; GSList *l; + retv_if(NULL == sender, UAM_ERROR_INVALID_PARAM); + retv_if(0 == sensors, UAM_ERROR_INVALID_PARAM); + + scanner = __uam_find_scanner(sender); + retv_if(NULL == scanner, UAM_ERROR_NOT_IN_OPERATION); + + /* Trim sensors to a subset of active sensors for the scanner */ + sensors &= scanner->sensors; + + /* + * modify scanner's active sensors and if active sensors are NULL + * remove scanner from scanners list + */ + scanner->sensors &= ~sensors; + if (0 == scanner->sensors) { + scanners = g_slist_remove(scanners, scanner); + g_source_remove(scanner->timer); + g_free(scanner->name); + g_free(scanner); + } for (l = scanners; NULL != l; l = g_slist_next(l)) { - uam_monitor_info_t *scanner = l->data; + uam_scanner_info_t *scanner_data = l->data; - if (!scanner || !scanner->name) + if (!scanner_data || !scanner_data->name) continue; - if (scanner->sensors & sensors) { - ret = _uam_pm_stop_search_active_devices(sensors); - if (UAM_ERROR_NONE != ret) { - UAM_ERR("Failed with error: %s (0x%4.4X)", + sensors &= ~(scanner_data->sensors); + } + + if (0 != sensors) { + ret = _uam_pm_stop_active_device_scan(sensors); + if (UAM_ERROR_NONE != ret) { + UAM_ERR("Failed with error: %s (0x%4.4X)", _uam_manager_error_to_str(ret), ret); - return ret; - } - scanners = g_slist_remove(scanners, scanner); - g_free(scanner->name); - g_free(scanner); + return ret; } } @@ -2096,57 +2131,64 @@ int _uam_core_stop_search_active_devices(char *sender, unsigned int sensors) return UAM_ERROR_NONE; } -void _uam_core_handle_active_device(uam_active_scan_event_e event, unsigned int sensor, const uam_device_info_t *dev_info) +void _uam_core_handle_active_device(uam_active_scan_event_e event, + unsigned int sensor, const uam_device_info_t *dev_info) { FUNC_ENTRY; - - GVariant *param = NULL; GSList *l; - int done = 0; - char *name = NULL; - for (l = scanners; NULL != l; l = g_slist_next(l)) { - uam_monitor_info_t *scanner = (uam_monitor_info_t *)l->data; + ret_if((UAM_ACTIVE_SCAN_COMPLETED != event) && (NULL == dev_info)); - if (!scanner || !scanner->name) + for (l = scanners; NULL != l;) { + uam_scanner_info_t *scanner = l->data; + + if (!scanner || !scanner->name) { + l = g_slist_next(l); continue; + } - if (scanner->sensors & sensor) { - name = g_strdup(scanner->name); - if (event == UAM_ACTIVE_SCAN_COMPLETED) { - scanner->sensors &= ~(sensor); - if (scanner->sensors == 0) { - done = 1; - scanners = g_slist_remove(scanners, scanner); - g_free(scanner->name); - g_free(scanner); - } + if (0 == (scanner->sensors & sensor)) { + l = g_slist_next(l); + continue; + } + + if (event == UAM_ACTIVE_SCAN_COMPLETED) { + scanner->sensors &= ~(sensor); + UAM_DBG("sensors = 0x%8.8X", scanner->sensors); + if (0 != scanner->sensors) { + l = g_slist_next(l); + continue; } - break; + + if (UAM_ERROR_NONE != _uam_manager_send_event( + scanner->name, UAM_EVENT_SCAN_COMPLETED, NULL)) + UAM_ERR("Failed to send UAM_EVENT_SCAN_COMPLETED"); + else + UAM_INFO_C("Sent UAM_EVENT_SCAN_COMPLETED to [%s]", scanner->name); + + /* Free scanner */ + l = g_slist_next(l); + scanners = g_slist_remove(scanners, scanner); + g_source_remove(scanner->timer); + g_free(scanner->name); + g_free(scanner); + } else { + GVariant *param = g_variant_new("(iiisss)", + UAM_ERROR_NONE, + dev_info->operating_system, + dev_info->type, + dev_info->mac, + dev_info->ipv4_addr, + dev_info->device_id); + if (UAM_ERROR_NONE != _uam_manager_send_event( + scanner->name, UAM_EVENT_DEVICE_FOUND, param)) + UAM_ERR("Failed to send %s", _uam_manager_event_to_str(event)); + else + UAM_INFO_C("Sent UAM_EVENT_DEVICE_FOUND to [%s]", scanner->name); + + l = g_slist_next(l); } } - if (event == UAM_ACTIVE_DEVICE_FOUND) { - param = g_variant_new("(iiisss)", - UAM_ERROR_NONE, - dev_info->operating_system, - dev_info->type, - dev_info->mac, - dev_info->ipv4_addr, - dev_info->device_id); - UAM_INFO_C("Send %s to applications", _uam_manager_event_to_str(UAM_EVENT_DEVICE_FOUND)); - /* Send device event to application */ - if (UAM_ERROR_NONE != _uam_manager_send_event(name, UAM_EVENT_DEVICE_FOUND, param)) - UAM_ERR("Failed to send %s", _uam_manager_event_to_str(event)); - } else if (done == 1 && event == UAM_ACTIVE_SCAN_COMPLETED) { - UAM_INFO_C("Send %s to applications", _uam_manager_event_to_str(UAM_EVENT_SCAN_COMPLETED)); - /* Send device event to application */ - if (UAM_ERROR_NONE != _uam_manager_send_event(name, UAM_EVENT_SCAN_COMPLETED, param)) - UAM_ERR("Failed to send %s", _uam_manager_event_to_str(event)); - } - - if (name != NULL) - g_free(name); - FUNC_EXIT; } diff --git a/ua-daemon/src/ua-manager-request-handler.c b/ua-daemon/src/ua-manager-request-handler.c index 9d515e9..5f2fed3 100644 --- a/ua-daemon/src/ua-manager-request-handler.c +++ b/ua-daemon/src/ua-manager-request-handler.c @@ -400,7 +400,7 @@ static int __uam_manager_sync_request_handler( __uam_manager_copy_params(in_param2, &detection_period, sizeof(int)); - result = _uam_core_start_search_active_devices(sender, sensors, detection_period); + result = _uam_core_start_active_device_scan(sender, sensors, detection_period); break; } case UAM_REQUEST_STOP_SEARCH_ACTIVE_DEVICES: { @@ -409,7 +409,7 @@ static int __uam_manager_sync_request_handler( __uam_manager_copy_params(in_param1, &sensors, sizeof(unsigned int)); - result = _uam_core_stop_search_active_devices(sender, sensors); + result = _uam_core_stop_active_device_scan(sender, sensors); break; } case UAM_REQUEST_REGISTER_APP: { -- 2.7.4