Fix __ua_send_absence_detection() to store monitor->absence_detected_bitmask
authorLokesh <l.kasana@samsung.com>
Tue, 10 Sep 2019 11:38:20 +0000 (17:08 +0530)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 16 Sep 2019 12:05:28 +0000 (21:05 +0900)
1/ fix user_sensor_bitmask in __ua_monitor_send_user_absence_cb()
2/ _uam_to_ua_sensor() is newly named

Changed uat-detection menu.
1/ change default detection type: ANY
2/ removed stop presence/detection menu

Change-Id: I30c3df499d080a080f22186c412aab3e447aaa9d
Signed-off-by: Lokesh <l.kasana@samsung.com>
include/user-awareness-util.h
packaging/capi-network-ua.spec
src/user-awareness-monitors.c
src/user-awareness-util.c
test/uat-detections.c

index de20517d30b48911d615b3509e8438ec8477f885..0f93d13733f5a5b82174909dd2a323a9e42a69b0 100644 (file)
@@ -170,6 +170,33 @@ uam_tech_type_e _ua_to_uam_tech_type(ua_mac_type_e type);
  */
 ua_sensor_e _ua_dev_type_to_sensor(ua_mac_type_e type);
 
+/**
+ * @ingroup CAPI_NETWORK_UA_MODULE
+ * @internal
+ * @brief Converts uam sensor bitmask to ua sensor bitmask enum.
+ * @since_tizen 5.5
+ *
+ * @remarks The returned value can be used until return call function is valid.
+ *
+ * @param[in] bitmask Uam sensor bitmask to be converted.
+ *
+ * @return Sensor bitmask
+ *
+ * @retval #UA_SENSOR_BT Bluetooth
+ * @retval #UA_SENSOR_BLE Bluetooth Low Energy
+ * @retval #UA_SENSOR_WIFI Wi-Fi
+ * @retval #UA_SENSOR_MOTION Motion
+ * @retval #UA_SENSOR_LIGHT Light
+ * @retval #UA_SENSOR_AUDIO Audiio
+ * @retval #UA_SENSOR_MAX Invalid
+ *
+ * @exception
+ * @pre
+ * @post
+ *
+ */
+ua_sensor_e _uam_to_ua_sensor(uam_sensor_bitmask_e bitmask);
+
 #ifdef __cplusplus
 }
 #endif
index d8633260ad98190e362aeea7adc984fc0b4ee71b..cdcae692e25805019c74ba7c9e9e218bbcf58482 100644 (file)
@@ -1,6 +1,6 @@
 Name: capi-network-ua
 Summary: User Awareness Framework CAPI
-Version: 0.8.8
+Version: 0.8.9
 Release: 1
 License: Apache-2.0
 Source0: %{name}-%{version}.tar.gz
index 1408294c33622e011c59ecc705af85544aa2af7b..2cac2c2fddcff99dcae77b0e67eadf11a23aa6de 100644 (file)
@@ -138,32 +138,6 @@ static unsigned int __ua_sensor_type_to_bitmask(ua_sensor_e sensor_type)
        return bitmask;
 }
 
-/* LCOV_EXCL_START */
-static ua_sensor_e __ua_sensor_bitmask_to_type(unsigned int bitmask)
-{
-       FUNC_ENTRY;
-
-       switch (bitmask) {
-       case UAM_SENSOR_BITMASK_BT:
-               return UA_SENSOR_BT;
-       case UAM_SENSOR_BITMASK_BLE:
-               return UA_SENSOR_BLE;
-       case UAM_SENSOR_BITMASK_WIFI:
-               return UA_SENSOR_WIFI;
-       case UAM_SENSOR_BITMASK_MOTION:
-               return UA_SENSOR_MOTION;
-       case UAM_SENSOR_BITMASK_LIGHT:
-               return UA_SENSOR_LIGHT;
-       case UAM_SENSOR_BITMASK_AUDIO:
-               return UA_SENSOR_AUDIO;
-       default:
-               UA_WARN("Unknown sensor bitmask [0x%8.8X]", bitmask);
-               return UA_SENSOR_MAX;
-       }
-       FUNC_EXIT;
-}
-/* LCOV_EXCL_STOP */
-
 static void __ua_free_user_state_info_t(gpointer data)
 {
        FUNC_ENTRY;
@@ -356,7 +330,7 @@ static void __ua_monitor_send_user_presence_cb(ua_monitor_s *monitor,
 }
 
 static void __ua_sensor_presence_detected(ua_monitor_s *monitor,
-       unsigned int bitmask, char *account, long timestamp, char *device_id)
+               ua_sensor_e bitmask, char *account, long timestamp, char *device_id)
 {
        FUNC_ENTRY;
 
@@ -366,7 +340,6 @@ static void __ua_sensor_presence_detected(ua_monitor_s *monitor,
        int ret = UA_ERROR_NONE;
        ua_user_state_info_s *user_state;
        ua_device_h device_handle = NULL;
-//TODO convert bitmask from uam to ua type
 
        ret_if(NULL == monitor);
 
@@ -407,6 +380,12 @@ static void __ua_sensor_presence_detected(ua_monitor_s *monitor,
                _ua_set_user_last_presence_timestamp(user_handle, timestamp);
        }
 
+       /* For the case when internal_presence_started is running */
+       if (!monitor->presence_detection_started) {
+               FUNC_EXIT;
+               return;
+       }
+
        switch (monitor->presence_mode) {
        case UA_DETECT_MODE_ALL_SENSOR:
                /*
@@ -483,7 +462,8 @@ static void __ua_monitor_send_user_absence_cb(ua_monitor_s *monitor,
         * user_sensor_bitmask provides number of detected sensors,
         * so we need to invert the user_sensor_bitmask to calculate absence.
         */
-       user_sensor_bitmask = ~user_sensor_bitmask;
+       user_sensor_bitmask = ~user_sensor_bitmask & (UA_SENSOR_BT
+                       | UA_SENSOR_BLE | UA_SENSOR_WIFI);
        env_absence_bitmask = monitor->absence_detected_bitmask
                        & (UA_SENSOR_MOTION | UA_SENSOR_LIGHT);
 
@@ -560,33 +540,31 @@ static void __ua_send_absence_detection()
                        }
                }
 
-               monitor->absence_detected_bitmask = 0;
-
-               if (!monitor->absence_user_cb.callback)
-                       continue;
 
-               for (l1 = monitor->user_state; NULL != l1; l1 = g_slist_next(l1)) {
-                       ua_user_state_info_s *user_state = l1->data;
+               if (monitor->absence_user_cb.callback) {
+                       for (l1 = monitor->user_state; NULL != l1; l1 = g_slist_next(l1)) {
+                               ua_user_state_info_s *user_state = l1->data;
 
-                       UA_INFO("Scanning user list...");
-                       if (user_state)
-                               __ua_monitor_send_user_absence_cb(monitor, user_state);
+                               UA_INFO("Scanning user list...");
+                               if (user_state)
+                                       __ua_monitor_send_user_absence_cb(monitor, user_state);
+                       }
                }
+
+               monitor->absence_detected_bitmask = 0;
        }
 
        FUNC_EXIT;
 }
 
 static void __ua_sensor_absence_detected(ua_monitor_s *monitor,
-       unsigned int bitmask, char *account)
+               ua_sensor_e bitmask, char *account)
 {
        FUNC_ENTRY;
-       ua_sensor_e sensor_type;
        bool all_absence;
        GSList *l;
        int found = 0;
        ua_user_state_info_s *user_state = NULL;
-       sensor_type = __ua_sensor_bitmask_to_type(bitmask);
        ret_if(NULL == monitor);
 
        if (account) {
@@ -609,13 +587,12 @@ static void __ua_sensor_absence_detected(ua_monitor_s *monitor,
                }
 
                user_state->sensor_bitmask &= ~bitmask;
+       } else {
+               monitor->absence_detected_bitmask |= bitmask;
        }
 
        switch (monitor->absence_mode) {
        case UA_DETECT_MODE_ALL_SENSOR:
-               if (!account)
-                       monitor->absence_detected_bitmask |= bitmask;
-
                break;
        case UA_DETECT_MODE_ANY_SENSOR:
                /* First add user info to local users list and then invoke callback */
@@ -625,12 +602,12 @@ static void __ua_sensor_absence_detected(ua_monitor_s *monitor,
                        if (all_absence) {
                                if (monitor->absence_cb)
                                        monitor->absence_cb(UA_ERROR_NONE, monitor,
-                                               sensor_type, monitor->user_data);
+                                                       bitmask, monitor->user_data);
                        }
                } else {
                        if (monitor->absence_cb)
                                monitor->absence_cb(UA_ERROR_NONE, monitor,
-                                       sensor_type, monitor->user_data);
+                                               bitmask, monitor->user_data);
                }
                break;
 
@@ -699,11 +676,12 @@ void _ua_monitor_handle_scan_complete(int result)
        FUNC_EXIT;
 }
 
-void _ua_monitor_handle_user_presence_detected(unsigned int bitmask,
-       char *service, char *account, long timestamp, char *device_id)
+void _ua_monitor_handle_user_presence_detected(unsigned int uam_bitmask,
+               char *service, char *account, long timestamp, char *device_id)
 {
        FUNC_ENTRY;
        GSList *l;
+       ua_sensor_e bitmask = _uam_to_ua_sensor(uam_bitmask);
 
        for (l = ua_monitor_list; l; l = g_slist_next(l)) {
                ua_monitor_s *monitor = l->data;
@@ -725,11 +703,12 @@ void _ua_monitor_handle_user_presence_detected(unsigned int bitmask,
        FUNC_EXIT;
 }
 
-void _ua_monitor_handle_user_absence_detected(unsigned int bitmask,
-       char *service, char *account)
+void _ua_monitor_handle_user_absence_detected(unsigned int uam_bitmask,
+               char *service, char *account)
 {
        FUNC_ENTRY;
        GSList *l;
+       ua_sensor_e bitmask = _uam_to_ua_sensor(uam_bitmask);
 
        for (l = ua_monitor_list; l; l = g_slist_next(l)) {
                ua_monitor_s *monitor = l->data;
@@ -849,7 +828,7 @@ void _ua_monitor_handle_sensor_state(unsigned int bitmask, gboolean ready)
        ua_sensor_e sensor_type;
        GSList *l;
 
-       sensor_type = __ua_sensor_bitmask_to_type(bitmask);
+       sensor_type = _uam_to_ua_sensor(bitmask);
        for (l = ua_monitor_list; l; l = g_slist_next(l)) {
                ua_monitor_s *monitor = l->data;
 
index 3500a37ce0e966701a1192323c44d576b7106083..f16dbf3dcb73e2f7e830231e5a78e1747d930ed4 100644 (file)
@@ -189,3 +189,27 @@ ua_sensor_e _ua_dev_type_to_sensor(ua_mac_type_e type)
        }
        FUNC_EXIT;
 }
+
+ua_sensor_e _uam_to_ua_sensor(uam_sensor_bitmask_e bitmask)
+{
+       FUNC_ENTRY;
+
+       switch (bitmask) {
+       case UAM_SENSOR_BITMASK_BT:
+               return UA_SENSOR_BT;
+       case UAM_SENSOR_BITMASK_BLE:
+               return UA_SENSOR_BLE;
+       case UAM_SENSOR_BITMASK_WIFI:
+               return UA_SENSOR_WIFI;
+       case UAM_SENSOR_BITMASK_MOTION:
+               return UA_SENSOR_MOTION;
+       case UAM_SENSOR_BITMASK_LIGHT:
+               return UA_SENSOR_LIGHT;
+       case UAM_SENSOR_BITMASK_AUDIO:
+               return UA_SENSOR_AUDIO;
+       default:
+               UA_WARN("Unknown sensor bitmask [0x%8.8X]", bitmask);
+               return UA_SENSOR_MAX;
+       }
+       FUNC_EXIT;
+}
index 264b5c2103d53603af60df5d2728b95f8c58347b..b3a5d41fe5b3721fa2155b06e0f9d37f1f53177d 100644 (file)
@@ -44,8 +44,8 @@ static char g_absence_and_cond[MENU_DATA_SIZE + 1] = {"6",}; /**< ABSENCE AND co
 static char g_absence_or_cond[MENU_DATA_SIZE + 1] = {"16",}; /**< ABSENCE OR condition */
 static char g_absence_conjunction_op[MENU_DATA_SIZE + 1] = {"0",}; /**< logical conjunction operation */
 
-static char g_presence_type[MENU_DATA_SIZE + 1] = "1"; /**< Selected PRESENCE type */
-static char g_absence_type[MENU_DATA_SIZE + 1] = "1"; /**< Selected ABSENCE type */
+static char g_presence_type[MENU_DATA_SIZE + 1] = "2"; /**< Selected PRESENCE type */
+static char g_absence_type[MENU_DATA_SIZE + 1] = "2"; /**< Selected ABSENCE type */
 static char g_scan_time_multiplier[MENU_DATA_SIZE + 1] = {0,}; /**< 10ms * what number */
 
 static void __device_presence_detected_cb(int result, ua_monitor_h monitor,
@@ -622,8 +622,10 @@ static struct menu_data menu_ua_start_presence[] = {
                NULL, NULL, g_presence_type },
        { "5", "service(empty for default, else selected service)",
                NULL, NULL, g_service_str},
-       { "6", "run",
+       { "6", "start",
                NULL, run_ua_monitor_start_presence_detection, NULL },
+       { "7", "stop",
+               NULL, run_ua_monitor_stop_presence_detection, NULL },
        { NULL, NULL, },
 };
 
@@ -638,8 +640,10 @@ static struct menu_data menu_ua_start_absence[] = {
                NULL, NULL, g_absence_type },
        { "5", "service(empty for default, else selected service)",
                NULL, NULL, g_service_str},
-       { "6", "run",
+       { "6", "start",
                NULL, run_ua_monitor_start_absence_detection, NULL },
+       { "7", "stop",
+               NULL, run_ua_monitor_stop_absence_detection, NULL },
        { NULL, NULL, },
 };
 
@@ -670,27 +674,21 @@ struct menu_data menu_ua_detections[] = {
        { "6", "ua_monitor_set_user_absence_condition",
                menu_ua_set_absence_condition, NULL, NULL },
 
-       { "7", "ua_monitor_start_presence_detection",
+       { "7", "ua_monitor_start/stop_presence_detection",
                menu_ua_start_presence, NULL, NULL },
-       { "8", "ua_monitor_stop_presence_detection",
-               NULL, run_ua_monitor_stop_presence_detection, NULL },
-       { "9", "ua_monitor_start_absence_detection",
+       { "8", "ua_monitor_start/stop_absence_detection",
                menu_ua_start_absence, NULL, NULL },
-       { "10", "ua_monitor_stop_absence_detection",
-               NULL, run_ua_monitor_stop_absence_detection, NULL },
-
-       { "11", "start/stop absence/presence simulataneously",
+       { "9", "start/stop absence/presence simulataneously",
                menu_start_absence_presence, NULL, NULL },
 
-       { "12", "ua_monitor_start_device_scan",
+       { "10", "ua_monitor_start_device_scan",
                menu_start_device_scan, NULL, NULL },
-       { "13", "ua_monitor_cancel_scan_devices",
+       { "11", "ua_monitor_cancel_scan_devices",
                NULL, run_ua_monitor_cancel_scan_devices, NULL },
 
-
-       { "14", "ua_enable_low_power_mode",
+       { "12", "ua_enable_low_power_mode",
                NULL, run_ua_enable_low_power_mode, NULL },
-       { "15", "ua_disable_low_power_mode",
+       { "13", "ua_disable_low_power_mode",
                NULL, run_ua_disable_low_power_mode, NULL },
        { NULL, NULL, },
 };