Start continuous detection only on sensors present in monitor
authorAbhay agarwal <ay.agarwal@samsung.com>
Mon, 11 Nov 2019 06:10:05 +0000 (11:40 +0530)
committersaerome.kim <saerome.kim@samsung.com>
Fri, 15 Nov 2019 09:11:19 +0000 (18:11 +0900)
Instead of always starting continuous detection, start only when particular
environmental sensor is being detected by atleast one application.

Change-Id: I0e4baac40074fcd7b1cedf139dfe1e773b1c7049
Signed-off-by: Abhay agarwal <ay.agarwal@samsung.com>
ua-daemon/src/ua-manager-core.c

index ac90f95..4f2c3ae 100644 (file)
@@ -592,6 +592,28 @@ unsigned int _uam_core_get_env_sensors()
        return sensors;
 }
 
+unsigned int _uam_core_get_active_env_sensors(int detection_mode)
+{
+       FUNC_ENTRY;
+       unsigned int sensors = 0;
+       GSList *l;
+
+       retv_if((UAM_DETECT_PRESENCE != detection_mode) &&
+                       (UAM_DETECT_ABSENCE != detection_mode), 0);
+
+       for (l = monitors; NULL != l; l = g_slist_next(l)) {
+               uam_monitor_info_t *monitor = l->data;
+
+               if (!monitor || !monitor->name || (detection_mode != monitor->mode))
+                       continue;
+
+               sensors |= monitor->sensors & _uam_core_get_env_sensors();
+       }
+
+       FUNC_EXIT;
+       return sensors;
+}
+
 static GSList *__convert_db_svc_list_to_uam_svc_list(GSList *db_svc_list)
 {
        FUNC_ENTRY;
@@ -1893,10 +1915,14 @@ static gboolean __start_detection(gpointer data)
        unsigned int sensors;
        gboolean start_detection = FALSE;
        GSList *l;
-       unsigned int env_sensors;
+       unsigned int presence_env_sensors;
+       unsigned int absence_env_sensors;
+
+       presence_env_sensors = _uam_core_get_active_env_sensors(UAM_DETECT_PRESENCE);
+       UAM_DBG("Presence Envionmental sensors: 0x%8.8X", presence_env_sensors);
 
-       env_sensors = _uam_core_get_env_sensors();
-       UAM_DBG("Envionmental sensors: 0x%8.8X", env_sensors);
+       absence_env_sensors = _uam_core_get_active_env_sensors(UAM_DETECT_ABSENCE);
+       UAM_DBG("Absence Envionmental sensors: 0x%8.8X", absence_env_sensors);
 
        for (l = services; NULL != l; l = g_slist_next(l)) {
                service = l->data;
@@ -1920,8 +1946,8 @@ static gboolean __start_detection(gpointer data)
        UAM_DBG("PRESENCE sensors: 0x%8.8X", sensors);
 
        /* Remove env sensors from active sensors */
-       sensors &= ~env_sensors;
-       UAM_DBG("Connectivity sensors: 0x%8.8X", sensors);
+       sensors &= ~presence_env_sensors;
+       UAM_DBG("Presence Connectivity sensors: 0x%8.8X", sensors);
 
        if (0 != sensors) {
                /* Start PRESENCE detection */
@@ -1936,8 +1962,8 @@ static gboolean __start_detection(gpointer data)
        UAM_DBG("ABSENCE sensors: 0x%8.8X", sensors);
 
        /* Remove env sensors from active sensors */
-       sensors &= ~env_sensors;
-       UAM_DBG("Connectivity sensors: 0x%8.8X", sensors);
+       sensors &= ~absence_env_sensors;
+       UAM_DBG("ABSENCE Connectivity sensors: 0x%8.8X", sensors);
 
        if (0 != sensors) {
                /* Start ABSENCE detection */
@@ -1948,27 +1974,29 @@ static gboolean __start_detection(gpointer data)
        }
 
 done:
-       if (0 != env_sensors) {
-               /* Stop PRESENCE detection on envionmental sensors*/
-               ret = _uam_pm_stop_detection(UAM_DETECT_PRESENCE, env_sensors);
+       if (0 != presence_env_sensors) {
+               /* Stop PRESENCE detection on active envionmental sensors*/
+               ret = _uam_pm_stop_detection(UAM_DETECT_PRESENCE, presence_env_sensors);
                if (UAM_ERROR_NONE != ret)
                        UAM_ERR("Failed with error: %s (0x%4.4X)",
                                        _uam_manager_error_to_str(ret), ret);
 
-               /* Stop ABSENCE detection on envionmental sensors*/
-               ret = _uam_pm_stop_detection(UAM_DETECT_ABSENCE, env_sensors);
+               /* Always Start PRESENCE detection on active envionmental sensors*/
+               ret = _uam_pm_start_detection(UAM_DETECT_PRESENCE, presence_env_sensors);
                if (UAM_ERROR_NONE != ret)
                        UAM_ERR("Failed with error: %s (0x%4.4X)",
                                        _uam_manager_error_to_str(ret), ret);
+       }
 
-               /* Always Start PRESENCE detection on envionmental sensors*/
-               ret = _uam_pm_start_detection(UAM_DETECT_PRESENCE, env_sensors);
+       if (0 != absence_env_sensors) {
+               /* Stop ABSENCE detection on envionmental sensors*/
+               ret = _uam_pm_stop_detection(UAM_DETECT_ABSENCE, absence_env_sensors);
                if (UAM_ERROR_NONE != ret)
                        UAM_ERR("Failed with error: %s (0x%4.4X)",
                                        _uam_manager_error_to_str(ret), ret);
 
-               /* Always Start ABSENCE detection on envionmental sensors*/
-               ret = _uam_pm_start_detection(UAM_DETECT_ABSENCE, env_sensors);
+               /* Always Start ABSENCE detection on active envionmental sensors*/
+               ret = _uam_pm_start_detection(UAM_DETECT_ABSENCE, absence_env_sensors);
                if (UAM_ERROR_NONE != ret)
                        UAM_ERR("Failed with error: %s (0x%4.4X)",
                                        _uam_manager_error_to_str(ret), ret);