Include the scan time for each app into battery info
[platform/core/connectivity/bluetooth-frwk.git] / bt-service-adaptation / services / bt-request-handler.c
index 93f75bb..4331c5c 100644 (file)
@@ -260,6 +260,24 @@ void _bt_save_invocation_context(GDBusMethodInvocation *invocation, int result,
 
 }
 
+static int __bt_service_get_sender_pid(const char *unique_name, pid_t *pid)
+{
+       int ret;
+       char err_msg[256] = {0, };
+
+       retv_if(bt_service_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       ret = cynara_creds_gdbus_get_pid(bt_service_conn, unique_name, pid);
+       if (ret != CYNARA_API_SUCCESS) {
+               cynara_strerror(ret, err_msg, sizeof(err_msg));
+               BT_ERR("Fail to get user credential: %s", err_msg);
+
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       return BLUETOOTH_ERROR_NONE;
+}
+
 static int __bt_bm_request_data(_bt_battery_data_t *latest)
 {
        int ret = _bt_bm_read_data(latest);
@@ -521,6 +539,7 @@ int __bt_bluez_request(int function_name,
                unsigned short max_response;
                unsigned short discovery_duration;
                unsigned int classOfDeviceMask;
+               uid_t uid;
 
                __bt_service_get_parameters(in_param1,
                                &max_response, sizeof(unsigned short));
@@ -528,8 +547,22 @@ int __bt_bluez_request(int function_name,
                                &discovery_duration, sizeof(unsigned short));
                __bt_service_get_parameters(in_param3,
                                &classOfDeviceMask, sizeof(unsigned int));
+               __bt_service_get_parameters(in_param4, &uid, sizeof(uid_t));
 
                result = _bt_start_discovery(max_response, discovery_duration, classOfDeviceMask);
+
+               if (result == BLUETOOTH_ERROR_NONE) {
+                       pid_t pid;
+
+                       sender = (char*)g_dbus_method_invocation_get_sender(context);
+
+                       if (__bt_service_get_sender_pid(sender, &pid) != BLUETOOTH_ERROR_NONE)
+                               BT_ERR("Fail to get the sender pid");
+
+                       BT_DBG("Remeber pid / uid for the scan operation");
+                       _bt_bm_add_scan_app(SCAN_REGACY, uid, pid);
+               }
+
                break;
        }
        case BT_START_CUSTOM_DISCOVERY: {
@@ -3117,21 +3150,46 @@ normal:
        }
 #endif
        case BT_START_LE_DISCOVERY: {
+               uid_t uid = 0;
+               pid_t pid = 0;
+
+               __bt_service_get_parameters(in_param1, &uid, sizeof(uid_t));
+
                sender = (char *)g_dbus_method_invocation_get_sender(context);
-               result = _bt_start_le_scan(sender);
+
+               if (__bt_service_get_sender_pid(sender, &pid) != BLUETOOTH_ERROR_NONE)
+                       BT_ERR("Fail to get the sender pid");
+
+               result = _bt_start_le_scan(sender, uid, pid);
                if (result == BLUETOOTH_ERROR_NONE) {
                        _bt_save_invocation_context(context, result, sender,
                                        function_name, NULL);
+
+                       BT_DBG("Remeber pid / uid for the scan operation");
+                       _bt_bm_add_scan_app(SCAN_LE, uid, pid);
                }
                break;
        }
        case BT_STOP_LE_DISCOVERY: {
+               uid_t uid = 0;
+               pid_t pid = 0;
+
+               __bt_service_get_parameters(in_param1, &uid, sizeof(uid_t));
+
                sender = (char *)g_dbus_method_invocation_get_sender(context);
+
+               if (__bt_service_get_sender_pid(sender, &pid) != BLUETOOTH_ERROR_NONE)
+                       BT_ERR("Fail to get the sender pid");
+
                result = _bt_stop_le_scan(sender);
                if (result == BLUETOOTH_ERROR_NONE) {
                        _bt_save_invocation_context(context, result, sender,
                                        function_name, NULL);
                }
+
+               BT_DBG("Remove pid / uid for the scan operation");
+               _bt_bm_remove_scan_app(SCAN_LE, uid, pid);
+
                break;
        }
        case BT_IS_LE_DISCOVERYING: {