Change the timestamp value to use the monotonic timer accepted/tizen/5.5/unified/20191118.084846 submit/tizen_5.5/20191115.102057
authorsaerome.kim <saerome.kim@samsung.com>
Thu, 14 Nov 2019 09:59:11 +0000 (18:59 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Fri, 15 Nov 2019 09:32:26 +0000 (18:32 +0900)
- Problem: real-time timestamp causes various problems.
- Cause: If the time zone is changed or the system time is initialized,
  the wrong timestamp may be generated.
- Solution:
  1. Change to use the monotonic timer when creating a timestamp.
  2. Add new plugin API that enables the BLE plugin can save real-time
  timestamp.

Change-Id: I2508ecdb15977f6278fb2eeec89dc5caba77537f
Signed-off-by: saerome.kim <saerome.kim@samsung.com>
12 files changed:
packaging/ua-manager.spec
ua-daemon/include/ua-manager-core.h
ua-daemon/include/ua-manager-database.h
ua-daemon/src/pm/ua-ble-plugin-handler.c
ua-daemon/src/pm/ua-light-plugin-handler.c
ua-daemon/src/pm/ua-motion-plugin-handler.c
ua-daemon/src/pm/ua-pm-util.c
ua-daemon/src/pm/ua-wifi-plugin-handler.c
ua-daemon/src/ua-manager-common.c
ua-daemon/src/ua-manager-core.c
ua-daemon/src/ua-manager-device-db.c
ua-plugins/include/ua-plugin.h

index 1ad90f1..a3d7ad9 100644 (file)
@@ -1,6 +1,6 @@
 Name:       ua-manager
 Summary:    User awareness manager
-Version:    0.12.19
+Version:    0.13.0
 Release:    1
 License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
index bc4e7f5..1742e67 100644 (file)
@@ -235,8 +235,6 @@ int _uam_core_add_ibeacon_adv(unsigned int adv_len, const char *iadv);
 
 void _uam_core_handle_status_changed(unsigned int sensor, void *info);
 
-void __send_sensor_absence_event(uam_sensor_info_s *sensor_info, unsigned int sensor);
-
 #ifdef __cplusplus
 }
 #endif
index d8c1805..6a8d96e 100644 (file)
@@ -134,7 +134,7 @@ int _uam_device_db_insert_device_info(
        unsigned long long timestamp);
 
 /* update */
-int _uam_device_db_update_device_timestamp(
+int _uam_device_db_update_device_lastseen(
        char *device_id, int tech_type, char *address, unsigned long long timestamp);
 int _uam_device_db_update_device_presence(
        char *device_id, int tech_type, char *address, int presence_state);
index 1450f07..da39bbe 100644 (file)
@@ -115,43 +115,6 @@ static void ble_device_added_callback(int status, uas_device_info_t *device)
        FUNC_EXIT;
 }
 
-void ble_device_update_timestamp_callback(
-       unsigned long long timestamp, uas_device_info_t *device)
-{
-       FUNC_ENTRY;
-
-       int ret;
-       uam_device_info_s *dev_info;
-
-       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_BLE;
-
-       ret = __uam_db_begin_transaction();
-       if (UAM_ERROR_NONE != ret) {
-               UAM_WARN("_uam_device_db_update_device_timestamp failed");
-               g_free(dev_info);
-               return;
-       }
-
-       /* Update database (presence state & timestamp) */
-       ret = _uam_device_db_update_device_timestamp(dev_info->device_id,
-                               dev_info->type, dev_info->mac, timestamp);
-
-       if (UAM_ERROR_NONE != ret) {
-               UAM_WARN("_uam_device_db_update_device_timestamp failed");
-               __uam_db_end_transaction(0);
-       }
-
-       __uam_db_end_transaction(1);
-       g_free(dev_info);
-
-       FUNC_EXIT;
-}
-
 uas_callbacks_t ble_cbs = {
        .state_changed_cb = ble_state_changed_callback,
        .detection_state_cb = ble_detection_state_changed_cb,
@@ -160,5 +123,4 @@ uas_callbacks_t ble_cbs = {
        .device_detected_cb = ble_device_detection_callback,
        .device_added_cb = ble_device_added_callback,
        .device_active_scan_cb = NULL,
-       .device_update_timestamp_cb = ble_device_update_timestamp_callback
 };
index f50ee78..ee5032d 100644 (file)
@@ -78,5 +78,4 @@ uas_callbacks_t light_cbs = {
        .device_detected_cb = NULL,
        .device_added_cb = NULL,
        .device_active_scan_cb = NULL,
-       .device_update_timestamp_cb = NULL
 };
index 4f95b9a..8dac1cf 100644 (file)
@@ -101,5 +101,4 @@ uas_callbacks_t motion_cbs = {
        .device_detected_cb = NULL,
        .device_added_cb = NULL,
        .device_active_scan_cb = NULL,
-       .device_update_timestamp_cb = NULL
 };
index 1375849..0e1cf89 100644 (file)
@@ -293,6 +293,7 @@ uam_device_info_s *_pm_util_uas_dev_info_to_uam_dev_info(const uas_device_info_t
 
        device->operating_system = dev->os;
        device->discriminant = dev->discriminant;
+       device->last_seen = dev->last_seen;
        g_strlcpy(device->device_id, dev->device_id, UAM_DEVICE_ID_MAX_STRING_LEN);
 
        memset(device->payload.duid, 0, UAM_BLE_PAYLOAD_DUID_LEN + 1);
index 14ba4e1..b81fa40 100644 (file)
@@ -147,5 +147,4 @@ uas_callbacks_t wifi_cbs = {
        .device_detected_cb = wifi_device_detection_callback,
        .device_added_cb = wifi_device_added_callback,
        .device_active_scan_cb = wifi_active_scan_callback,
-       .device_update_timestamp_cb = NULL
 };
index a6ba42f..c8125de 100644 (file)
@@ -14,7 +14,7 @@
  * limitations under the License.
  *
  */
-
+#include <error.h>
 #include <sys/stat.h>
 #include <sys/time.h>
 #include "ua-api.h"
@@ -230,10 +230,11 @@ unsigned long long _uam_get_timestamp(void)
 {
        int ret;
        struct timespec t;
+
        ret = clock_gettime(CLOCK_MONOTONIC, &t);
        if (-1 == ret) {
-               UAM_ERR("Failed to call clock_gettime [%d]", ret);
+               UAM_ERR("Failed to call clock_gettime [%d]", errno);
                return 0;
        }
-       return ((unsigned long long)(t.tv_sec)*1000000000LL + t.tv_nsec) / 1000;
-}
+       return ((unsigned long long)(t.tv_sec) * 1000000000LL + t.tv_nsec) / 1000000;
+}
\ No newline at end of file
index 396fefb..d91d918 100644 (file)
@@ -2451,7 +2451,6 @@ int _uam_core_handle_device_added(int status,
        int ret = UAM_ERROR_NONE;
        GSList *svc_list = NULL;
        uam_db_user_info_t *user = NULL;
-       unsigned long long timestamp;
 
        UAM_INFO("[%d]", user_id);
 
@@ -2530,14 +2529,13 @@ int _uam_core_handle_device_added(int status,
                svc_list = g_slist_append(svc_list, service);
        }
 
-       timestamp = _uam_get_timestamp();
        __uam_core_add_dev_to_list(user, dev_info,
-                       UAM_PRESENCE_STATE_PRESENT, timestamp, svc_list);
+                       UAM_PRESENCE_STATE_PRESENT, dev_info->last_seen, svc_list);
 
        retv_if(UAM_ERROR_NONE != __uam_db_begin_transaction(), UAM_ERROR_DB_FAILED);
        /* Add device to database */
        ret = _uam_device_db_insert_device_info(user->user_id,
-                               dev_info, UAM_PRESENCE_STATE_PRESENT, timestamp);
+                               dev_info, UAM_PRESENCE_STATE_PRESENT, dev_info->last_seen);
        if (UAM_ERROR_NONE != ret) {
                UAM_WARN("Device addition to persistent DB failed");
                __uam_db_end_transaction(0);
@@ -2652,7 +2650,8 @@ void __send_sensor_presence_event(uam_sensor_info_s *sensor_info, unsigned int s
        FUNC_EXIT;
 }
 
-void __send_sensor_absence_event(uam_sensor_info_s *sensor_info, unsigned int sensor)
+static void __send_sensor_absence_event(uam_sensor_info_s *sensor_info,
+       unsigned int sensor)
 {
        FUNC_ENTRY;
        GSList *l;
@@ -2767,10 +2766,11 @@ void __send_user_presence_event(uam_db_tech_info_t *tech, unsigned int sensor,
                                                user->account, svc->name,device_id));
                        UAM_DBG("Sent UAM_EVENT_USER_PRESENCE_DETECTED to %s"
                                        " on device %s"
-                                       " for 0x%8.8X, User: %s Service: %s",
+                                       " for 0x%8.8X, User: %s Service: %s Timestamp: %llu",
                                        mon->name, device_id,
                                        sensor, user->account,
-                                       svc->name);
+                                       svc->name,
+                                       user->timestamp);
                }
        }
 
@@ -2884,10 +2884,10 @@ int _uam_core_handle_presence_detected(unsigned int sensor,
        }
 
        /* Update database (presence state & timestamp) */
-       ret = _uam_device_db_update_device_timestamp(dev_info->device_id,
-                               dev_info->type, dev_info->mac, tech->timestamp);
+       ret = _uam_device_db_update_device_lastseen(dev_info->device_id,
+                               dev_info->type, dev_info->mac, dev_info->last_seen);
        if (UAM_ERROR_NONE != ret) {
-               UAM_WARN("_uam_device_db_update_device_timestamp failed");
+               UAM_WARN("_uam_device_db_update_device_lastseen failed");
                __uam_db_end_transaction(0);
                return ret;
        }
@@ -2911,7 +2911,6 @@ static void __send_user_absence_event(uam_tech_type_e type, unsigned int sensor)
 {
        FUNC_ENTRY;
        GSList *l;
-       long timestamp;
 
        /*
         * For each service, find users absent on given sensor. Then for each
@@ -2990,21 +2989,15 @@ static void __send_user_absence_event(uam_tech_type_e type, unsigned int sensor)
                                if (!user)
                                        continue;
 
-                               timestamp = time(NULL);
-                               if (-1 == timestamp)
-                                       UAM_ERR("time() return -1");
-                               else
-                                       user->timestamp = (unsigned long long)timestamp;
+                               user->timestamp = 0;
 
                                _uam_manager_send_event(mon->name,
                                                UAM_EVENT_USER_ABSENCE_DETECTED,
                                                g_variant_new("(utss)", sensor, user->timestamp,
                                                        user->account, svc->name));
                                UAM_DBG("Sent UAM_EVENT_USER_ABSENCE_DETECTED to %s"
-                                               " for 0x%8.8X, User: %s Service: %s"
-                                               " timestamp [%llu]",
-                                               mon->name, sensor, user->account,
-                                               svc->name, user->timestamp);
+                                               " for 0x%8.8X, User: %s Service: %s",
+                                               mon->name, sensor, user->account, svc->name);
                        }
                }
 
index 6305728..1532232 100644 (file)
@@ -343,7 +343,7 @@ handle_error:
        return error_code;
 }
 
-int _uam_device_db_update_device_timestamp(char *device_id, int tech_type,
+int _uam_device_db_update_device_lastseen(char *device_id, int tech_type,
                                          char *address, unsigned long long timestamp)
 {
        int error_code = UAM_ERROR_NONE;
index e0134dc..1909663 100644 (file)
@@ -83,20 +83,20 @@ typedef enum {
  *     - User detection supported,
  */
 typedef enum {
-       UAS_NOT_SUPPORT_USER,
-       UAS_SUPPORT_USER
+       UAS_NOT_SUPPORT_USER, /**< This means that not including user_id */
+       UAS_SUPPORT_USER /**< This means that including user_id */
 } uas_capability_e;
 
 /* Detection event types */
 typedef enum {
-       UAS_PRESENCE = 0x01,
-       UAS_ABSENCE = 0x02
+       UAS_PRESENCE = 0x01, /**< Presence event */
+       UAS_ABSENCE = 0x02 /**< Absence event */
 } uas_detection_type_e;
 
 /* Device address information structure */
 typedef struct {
-       uas_address_type_e type;
-       char *address;
+       uas_address_type_e type; /**< Address fype for the connectivity */
+       char *address; /**< Address data */
 } uas_address_info_t;
 
 /* Device ble payload information structure */
@@ -110,14 +110,15 @@ typedef struct {
 
 /* Device information structure */
 typedef struct {
-       int user_id;
-       unsigned int supported_techs;
-       char *device_id;
-       int os;
-       int num_addr;
-       uas_address_info_t *addr_list;
+       int user_id; /**< User ID for the DB */
+       unsigned int supported_techs; /**< Connectivity type */
+       char *device_id; /**< Device ID */
+       int os; /**< OS type (Tizen,Android, iOS) */
+       int num_addr; /**< The number of address list */
+       uas_address_info_t *addr_list; /**< Address list (IP, Subnet Mask, Gateway etc) */
        int discriminant; /**< Determines whether to judge PRESENCE/ABSENCE */
-       uas_ble_payload_t *payload;
+       unsigned long long last_seen; /**< Last seen time */
+       uas_ble_payload_t *payload; /**< BLE payload for BLE device filtering */
 } uas_device_info_t;
 
 /* Sensor information structure */
@@ -184,15 +185,6 @@ typedef void (*uas_device_added_callback)(int status, uas_device_info_t *device)
 typedef void (*uas_device_active_scan_callback)(
                uas_active_scan_event_e event, const uas_device_info_t *device);
 
-/*
- * Callback to be invoked in response to search_active_devices() API
- *
- * [Param] timestamp - Timestamp to update.
- * [Param] device - Device information to update.
- */
-typedef void (*uas_device_update_timestamp_callback)(unsigned long long timestamp,
-               uas_device_info_t *device);
-
 
 /* UA plug-in callback structure */
 typedef struct {
@@ -203,7 +195,6 @@ typedef struct {
        uas_device_detection_callback device_detected_cb; /**< For connectivity sensors */
        uas_device_added_callback device_added_cb; /**< For connectivity sensors */
        uas_device_active_scan_callback device_active_scan_cb; /**< For connectivity sensors */
-       uas_device_update_timestamp_callback device_update_timestamp_cb; /**< Update device timestamp */
 } uas_callbacks_t;
 
 typedef struct {