ua-daemon: Add support for start/stop location detection 86/260386/1
authorAbhay Agarwal <ay.agarwal@samsung.com>
Thu, 24 Jun 2021 04:14:13 +0000 (09:44 +0530)
committerAbhay Agarwal <ay.agarwal@samsung.com>
Thu, 24 Jun 2021 05:26:39 +0000 (10:56 +0530)
Change-Id: Id9b51720b4918f32e5ed679940743c66844873f5
Signed-off-by: Abhay Agarwal <ay.agarwal@samsung.com>
ua-daemon/include/ua-manager-core.h
ua-daemon/include/ua-plugin-manager.h
ua-daemon/src/ua-manager-core.c
ua-daemon/src/ua-manager-request-handler.c

index 6339e5e..d9b72ff 100644 (file)
@@ -299,6 +299,12 @@ int _uam_core_get_payloads(int *count, uam_ble_payload_s **payload_list, const i
 
 void _uam_core_get_app_num_from_app_key(const char* app_key, int *app_num);
 
+int _uam_core_start_location_detection(const char *svc_name, char *sender,
+       unsigned int sensors, int app_num);
+
+int _uam_core_stop_location_detection(const char *svc_name, char *sender,
+       unsigned int sensors, int app_num);
+
 #ifdef __cplusplus
 }
 #endif
index 26126fd..5f57199 100644 (file)
@@ -30,6 +30,7 @@ extern "C" {
 typedef enum {
        UAM_DETECT_PRESENCE = 0x01,
        UAM_DETECT_ABSENCE = 0x02,
+       UAM_DETECT_LOCATION = 0x03,
 } uam_pm_detection_mode_e;
 
 int _uam_pm_init(void);
index 7f57132..da316e5 100755 (executable)
@@ -2775,6 +2775,7 @@ static gboolean __start_detection(gpointer data)
        gboolean start_detection = FALSE;
        GSList *l;
        unsigned int env_sensors;
+       unsigned int loc_sensors;
 
        env_sensors = _uam_core_get_active_env_sensors(UAM_DETECT_PRESENCE) |
                        _uam_core_get_active_env_sensors(UAM_DETECT_ABSENCE);
@@ -2826,6 +2827,18 @@ done:
                                        _uam_manager_error_to_str(ret), ret);
        }
 
+       /* location detection */
+       loc_sensors = _uam_core_get_active_sensors(UAM_DETECT_LOCATION);
+       UAM_DBG("Active sensors for location detection: 0x%8.8X", loc_sensors);
+
+       if (0 != loc_sensors) {
+               /* Start location detection */
+               ret = _uam_pm_start_detection(UAM_DETECT_LOCATION, loc_sensors);
+               if (UAM_ERROR_NONE != ret)
+                       UAM_ERR("Failed with error: %s (0x%4.4X)",
+                                       _uam_manager_error_to_str(ret), ret);
+       }
+
        FUNC_EXIT;
        return TRUE;
 }
@@ -2892,6 +2905,8 @@ static int __uam_core_stop_detection(int detection_type,
        int ret = UAM_ERROR_NONE;
        unsigned int remaining_sensors;
        unsigned int active_sensors;
+       unsigned int remaining_sensors_loc;
+       unsigned int active_sensors_loc;
        uam_monitor_info_t *monitor;
        uam_db_service_info_t *service;
 
@@ -2906,8 +2921,11 @@ static int __uam_core_stop_detection(int detection_type,
        /* Find sensors which are already monitoring */
        active_sensors = _uam_core_get_active_sensors(UAM_DETECT_PRESENCE) |
                                _uam_core_get_active_sensors(UAM_DETECT_ABSENCE);
-       UAM_DBG("sensors: 0x%8.8X, Active sensors: 0x%8.8X",
-                       sensors, active_sensors);
+       active_sensors_loc = _uam_core_get_active_sensors(UAM_DETECT_LOCATION);
+
+       UAM_DBG("sensors: 0x%8.8X, Active sensors: 0x%8.8X " \
+                       "Active sensors location 0x%8.8X",
+                       sensors, active_sensors, active_sensors_loc);
 
        /* Update monitor info for application */
        monitor->sensors &= ~sensors;
@@ -2934,7 +2952,22 @@ static int __uam_core_stop_detection(int detection_type,
        /* Find sensors which are already monitoring */
        remaining_sensors = _uam_core_get_active_sensors(UAM_DETECT_PRESENCE) |
                                _uam_core_get_active_sensors(UAM_DETECT_ABSENCE);
-       UAM_DBG("Remaining sensors: 0x%8.8X", remaining_sensors);
+       remaining_sensors_loc = _uam_core_get_active_sensors(UAM_DETECT_LOCATION);
+
+       UAM_DBG("Remaining sensors: 0x%8.8X Remaining sensors location: 0x%8.8X",
+                       remaining_sensors, remaining_sensors_loc);
+
+       /* Stop location detection */
+       if (detection_type == UAM_DETECT_LOCATION &&
+               (active_sensors_loc != remaining_sensors_loc)) {
+
+               ret = _uam_pm_stop_detection(UAM_DETECT_LOCATION,
+                       active_sensors_loc & ~remaining_sensors_loc);
+               if (UAM_ERROR_NONE != ret)
+                       UAM_ERR("Failed with error: %s (0x%4.4X)",
+                                       _uam_manager_error_to_str(ret), ret);
+               return ret;
+       }
 
        if (active_sensors == remaining_sensors) {
                UAM_INFO("No need to stop monitoring");
@@ -3004,6 +3037,32 @@ int _uam_core_stop_absence_detection(const char *svc_name, char *sender,
        return ret;
 }
 
+int _uam_core_start_location_detection(const char *svc_name, char *sender,
+                                               unsigned int sensors, int app_num)
+{
+       FUNC_ENTRY;
+       int ret;
+
+       ret = __uam_core_start_detection(UAM_DETECT_LOCATION,
+                               svc_name, sender, sensors, app_num);
+
+       FUNC_EXIT;
+       return ret;
+}
+
+int _uam_core_stop_location_detection(const char *svc_name, char *sender,
+                                       unsigned int sensors, int app_num)
+{
+       FUNC_ENTRY;
+       int ret;
+
+       ret = __uam_core_stop_detection(UAM_DETECT_LOCATION,
+                               svc_name, sender, sensors, app_num);
+
+       FUNC_EXIT;
+       return ret;
+}
+
 int _uam_core_set_low_power_mode(unsigned int bitmask, gboolean mode)
 {
        FUNC_ENTRY;
index 9a6cc7b..1e27032 100755 (executable)
@@ -94,6 +94,8 @@ static uam_request_table_s request_table[] = {
        { UAM_REQUEST_STOP_PRESENCE_DETECTION, UAM_PRIVTYPE_DEVICE | UAM_PRIVTYPE_LOCATION, UAM_SYNC_FUNCTION },
        { UAM_REQUEST_START_ABSENCE_DETECTION, UAM_PRIVTYPE_DEVICE | UAM_PRIVTYPE_LOCATION, UAM_SYNC_FUNCTION },
        { UAM_REQUEST_STOP_ABSENCE_DETECTION, UAM_PRIVTYPE_DEVICE | UAM_PRIVTYPE_LOCATION, UAM_SYNC_FUNCTION },
+       { UAM_REQUEST_START_LOCATION_DETECTION, UAM_PRIVTYPE_DEVICE | UAM_PRIVTYPE_LOCATION, UAM_SYNC_FUNCTION },
+       { UAM_REQUEST_STOP_LOCATION_DETECTION, UAM_PRIVTYPE_DEVICE | UAM_PRIVTYPE_LOCATION, UAM_SYNC_FUNCTION },
        { UAM_REQUEST_SET_LOW_POWER_MODE, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION },
        { UAM_REQUEST_START_SEARCH_ACTIVE_DEVICES, UAM_PRIVTYPE_DEVICE | UAM_PRIVTYPE_LOCATION, UAM_SYNC_FUNCTION },
        { UAM_REQUEST_STOP_SEARCH_ACTIVE_DEVICES, UAM_PRIVTYPE_DEVICE | UAM_PRIVTYPE_LOCATION, UAM_SYNC_FUNCTION },
@@ -715,6 +717,30 @@ static int __uam_manager_sync_request_handler(
                result = _uam_core_stop_absence_detection(svc_name, sender, sensors, app_num);
                break;
        }
+       case UAM_REQUEST_START_LOCATION_DETECTION: {
+                       const char *svc_name;
+                       unsigned int sensors;
+       
+                       __uam_manager_copy_params(in_param1,
+                                                       &sensors, sizeof(unsigned int));
+                       svc_name = (char *)g_variant_get_data(in_param2);
+       
+                       result = _uam_core_start_location_detection(svc_name,
+                                                       sender, sensors, app_num);
+                       break;
+       }
+       case UAM_REQUEST_STOP_LOCATION_DETECTION: {
+                       unsigned int sensors;
+                       const char *svc_name;
+       
+                       __uam_manager_copy_params(in_param1,
+                                                       &sensors, sizeof(unsigned int));
+                       svc_name = (char *)g_variant_get_data(in_param2);
+       
+                       result = _uam_core_stop_location_detection(svc_name,
+                                                       sender, sensors, app_num);
+                       break;
+       }
        case UAM_REQUEST_SET_LOW_POWER_MODE: {
                gboolean mode = FALSE;
                unsigned int bitmask = 0;
@@ -1378,7 +1404,9 @@ static unsigned int __uam_manager_get_device_type(
        case UAM_REQUEST_START_PRESENCE_DETECTION:
        case UAM_REQUEST_STOP_PRESENCE_DETECTION:
        case UAM_REQUEST_START_ABSENCE_DETECTION:
-       case UAM_REQUEST_STOP_ABSENCE_DETECTION: {
+       case UAM_REQUEST_STOP_ABSENCE_DETECTION:
+       case UAM_REQUEST_START_LOCATION_DETECTION:
+       case UAM_REQUEST_STOP_LOCATION_DETECTION: {
                unsigned int bitmask = 0;
 
                __uam_manager_copy_params(in_param1,