Add the session timer to handle the exception case 95/229695/1
authorDoHyun Pyun <dh79.pyun@samsung.com>
Fri, 3 Apr 2020 02:12:52 +0000 (11:12 +0900)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Fri, 3 Apr 2020 02:12:52 +0000 (11:12 +0900)
After starting session if 'data read function' is not
called, the session's data is continously increasing.
So it is possible to excced the limit of the data size.

Change-Id: I3a9d3b9ffcc43f78b28f9abc492347de0ecce2cb
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
bt-service-adaptation/services/bt-service-battery-monitor.c

index 4fe89b3..2069a54 100644 (file)
 #define VCONFKEY_BATTERY_MONITOR_STATUS "db/bluetooth/bmstatus"
 #endif
 
+/* 10 minutes */
+#define BT_BM_SESSION_TIMEOUT 600
+
 static struct timeval scan_start;
 static struct timeval connect_start;
 static struct timeval app_scan_base;
 static int scan_cnt = 0;
 static int connect_cnt = 0;
 static gboolean is_session_started = FALSE;
+static guint session_timer = 0;
 
 static GSList *scan_app_list = NULL;
 
@@ -57,6 +61,8 @@ _bt_battery_data_t *current_session_data = NULL;
 
 static void __bt_bm_add_prev_time(uint32_t scan_time);
 static int __bt_start_session_time(void);
+static void __bt_stop_session_time(void);
+static bool __bt_bm_session_timeout_cb(void);
 
 uint32_t static __bt_dm_time_diff_msec(struct timeval prev, struct timeval cur)
 {
@@ -158,6 +164,13 @@ int _bt_bm_read_data(_bt_battery_data_t *data)
                BT_DBG("%ld %ld %d %d %u", (long int)(t->uid), (long int)(t->pid), t->rx_bytes, t->tx_bytes, t->time);
        }
 
+       /* Reset the session timer */
+       if (session_timer)
+               g_source_remove(session_timer);
+
+       session_timer = g_timeout_add_seconds(BT_BM_SESSION_TIMEOUT,
+                               (GSourceFunc)__bt_bm_session_timeout_cb, NULL);
+
        return BLUETOOTH_ERROR_NONE;
 }
 
@@ -213,6 +226,16 @@ void _bt_bm_add_transaction_details(uid_t uid, pid_t pid, int value, data_transa
        }
 }
 
+static bool __bt_bm_session_timeout_cb(void)
+{
+       BT_INFO("No data read calls during the time.");
+
+       __bt_stop_session_time();
+
+       return FALSE;
+}
+
+
 static int __bt_start_session_time(void)
 {
        int state = 0;
@@ -244,26 +267,40 @@ static int __bt_start_session_time(void)
        current_session_data->session_scan_time = 0;
        current_session_data->atm_list = NULL;
 
+       /* After starting session if there is no read data call during the specific time,
+        * stop the session time to avoid the exceed of session data.
+       */
+       if (session_timer)
+               g_source_remove(session_timer);
+
+       session_timer = g_timeout_add_seconds(BT_BM_SESSION_TIMEOUT,
+                               (GSourceFunc)__bt_bm_session_timeout_cb, NULL);
+
        return BLUETOOTH_ERROR_NONE;
 }
 
-void _bt_stop_session_time(void)
+static void __bt_stop_session_time(void)
 {
+       if (session_timer) {
+               g_source_remove(session_timer);
+               session_timer = 0;
+       }
+
        if (is_session_started == FALSE) {
                BT_DBG("BT session not in progress... Returning");
                return;
        }
 
+       __bt_display_session_data();
+
        BT_DBG("Bt session ending...");
        is_session_started = FALSE;
 
-       if (current_session_data == NULL) {
-               BT_ERR("Session in progress but data structure is not initialized");
-               return;
+       if (current_session_data != NULL) {
+               g_slist_free_full(current_session_data->atm_list, g_free);
+               g_free(current_session_data);
+               current_session_data = NULL;
        }
-
-       current_session_data->session_end_time = time(NULL);
-       __bt_display_session_data();
 }
 
 /* 1 app can operate the regacy and ble scan at the same time */
@@ -559,8 +596,8 @@ void _bt_bm_event_handler(gpointer data)
        case OAL_EVENT_ADAPTER_DISABLED:
                BT_DBG("Handling Adapter Disabled");
                if (is_session_started == TRUE) {
-                       _bt_stop_session_time();
                        __bt_notify_battery_data();
+                       __bt_stop_session_time();
                }
                break;
        case OAL_EVENT_ADAPTER_INQUIRY_STARTED: