Stop scan on sensor when no monitoring application 53/225153/1 accepted/tizen/unified/20200218.145853 submit/tizen/20200218.012430
authorAbhay Agarwal <ay.agarwal@samsung.com>
Mon, 17 Feb 2020 08:43:39 +0000 (14:13 +0530)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Tue, 18 Feb 2020 00:36:57 +0000 (09:36 +0900)
Issue: Presence/absence scanning on BLE/wifi plugin was not able to
stop in case only presence or only absence was started by application.

Reason: Even if only presence or only absence is started by application
ua-manager simultaneoulsy starts both presence and absence to keep their
detection cycle in sync.

Solution: Stop both presence and absence detection when stop detection
is called, if no application is monitioring on this sensor.

Change-Id: I1e54bad283932dfe3128628e98369a0070f9e623
Signed-off-by: Abhay Agarwal <ay.agarwal@samsung.com>
packaging/ua-manager.spec
ua-daemon/src/pm/ua-plugin-manager.c
ua-daemon/src/ua-manager-core.c

index de9539e..ac7d5b5 100644 (file)
@@ -1,6 +1,6 @@
 Name:       ua-manager
 Summary:    User awareness manager
-Version:    0.13.21
+Version:    0.13.22
 Release:    1
 License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
index 8a7ac40..48faa00 100644 (file)
@@ -31,9 +31,6 @@ extern const uas_callbacks_t wifi_cbs;
 extern const uas_callbacks_t light_cbs;
 extern const uas_callbacks_t motion_cbs;
 
-static int ble_detection_type = 0;
-static int wifi_detection_type = 0;
-
 typedef struct {
        void *handle;
        uas_module_t *module;
@@ -538,25 +535,13 @@ int _uam_pm_start_detection(unsigned int detection_mode, unsigned int bitmask)
                if (!plugin || !plugin->api)
                        continue;
 
-               /*
-                * For User/device detection capable plugins, need to start both, PRESENCE
-                * as well as ABSENCE detection, to keep UA database updated.
-                */
-               if (UAS_PLUGIN_ID_BLE == id || UAS_PLUGIN_ID_WIFI == id)
-                       status = plugin->api->start_detection(UAS_PRESENCE | UAS_ABSENCE);
-               else
-                       status = plugin->api->start_detection(type);
+               status = plugin->api->start_detection(type);
 
                if (UAS_STATUS_SUCCESS != status && UAS_STATUS_ALREADY_DONE != status) {
                        UAM_ERR("plugin->start_detection(%d) failed for %d", type, id);
                        continue;
                }
 
-               if (UAS_PLUGIN_ID_BLE == id)
-                       ble_detection_type |= type;
-               if (UAS_PLUGIN_ID_WIFI == id)
-                       wifi_detection_type |= type;
-
                /* Result success if detection started for atleast 1 of the sensor */
                ret = UAM_ERROR_NONE;
        }
@@ -594,24 +579,7 @@ int _uam_pm_stop_detection(unsigned int detection_mode, unsigned int bitmask)
                if (!plugin || !plugin->api)
                        continue;
 
-               if (UAS_PLUGIN_ID_BLE == id) {
-                       ble_detection_type &= ~type;
-                       ret = UAM_ERROR_NONE;
-                       if (0 != ble_detection_type)
-                               continue;
-               }
-
-               if (UAS_PLUGIN_ID_WIFI == id) {
-                       wifi_detection_type &= ~type;
-                       ret = UAM_ERROR_NONE;
-                       if (0 != wifi_detection_type)
-                               continue;
-               }
-
-               if (UAS_PLUGIN_ID_BLE == id || UAS_PLUGIN_ID_WIFI == id)
-                       status = plugin->api->stop_detection(UAS_PRESENCE | UAS_ABSENCE);
-               else
-                       status = plugin->api->stop_detection(type);
+               status = plugin->api->stop_detection(type);
 
                if (UAS_STATUS_SUCCESS != status && UAS_STATUS_ALREADY_DONE != status) {
                        UAM_ERR("plugin->stop_detection(%d) failed for %d", type, id);
index 1a170f6..149bb03 100644 (file)
@@ -2251,7 +2251,8 @@ static int __uam_core_stop_detection(int detection_type,
        retv_if(0 != g_strcmp0(service->name, svc_name), UAM_ERROR_NOT_IN_OPERATION);
 
        /* Find sensors which are already monitoring */
-       active_sensors = _uam_core_get_active_sensors(detection_type);
+       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);
 
@@ -2278,17 +2279,18 @@ static int __uam_core_stop_detection(int detection_type,
        }
 
        /* Find sensors which are already monitoring */
-       remaining_sensors = _uam_core_get_active_sensors(detection_type);
+       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);
 
        if (active_sensors == remaining_sensors) {
-               UAM_INFO("NO need to stop monitoring");
+               UAM_INFO("No need to stop monitoring");
                return UAM_ERROR_NONE;
        }
 
        /* Stop monitoring only for sensors which aren't required anymore */
        sensors = (active_sensors & ~remaining_sensors);
-       ret = _uam_pm_stop_detection(detection_type, sensors);
+       ret = _uam_pm_stop_detection(UAM_DETECT_PRESENCE | UAM_DETECT_ABSENCE, sensors);
        if (UAM_ERROR_NONE != ret)
                UAM_ERR("Failed with error: %s (0x%4.4X)",
                                _uam_manager_error_to_str(ret), ret);