Battery listeners for GPS, Charging, capacity,signal strenght added 14/226614/4
authorkamaljeet chauhan <kamal.jc@samsung.com>
Wed, 4 Mar 2020 06:46:50 +0000 (12:16 +0530)
committerKichan Kwon <k_c.kwon@samsung.com>
Thu, 5 Mar 2020 05:14:30 +0000 (14:14 +0900)
Change-Id: I7736712af3d4a237acb2f9f803901dfb24d6578f
Signed-off-by: kamaljeet chauhan <kamal.jc@samsung.com>
CMakeLists.txt
include/bm_listeners.h
packaging/batterymonitor.spec
src/battery_dump/bm_listeners.c

index ea42ad4..10299eb 100644 (file)
@@ -23,6 +23,7 @@ pkg_check_modules(pkgs REQUIRED
        capi-network-bluetooth
        capi-network-connection
        vconf
+       tapi
 )
 
 ADD_CUSTOM_COMMAND(
index 4e317e3..cc9b1b1 100644 (file)
 #define        LISTEN_WIFI_SCAN_STATE 5
 #define        LISTEN_DEVICE_DISPLAY_STATE 6
 #define        LISTEN_BRIGHTNESS_CHANGE 7
+#define        LISTEN_BATTERY_CAPACITY_CHANGE 8
+#define        LISTEN_LOCATION_CHANGE 9
+#define        LISTEN_CHARGING_STATUS_CHANGE 10
+#define        LISTEN_SIGNAL_STRENGTH_CHANGE 11
+
 
 
 int bd_initialize_listeners(void);
index ffcf15c..832b79d 100644 (file)
@@ -30,6 +30,7 @@ BuildRequires:  pkgconfig(capi-network-wifi-manager)
 BuildRequires:  pkgconfig(capi-network-bluetooth)
 BuildRequires:  pkgconfig(capi-network-connection)
 BuildRequires:  pkgconfig(vconf)
+BuildRequires:  pkgconfig(tapi)
 
 Requires(post): /sbin/ldconfig
 Requires(postun): /sbin/ldconfig
index e9fa8d5..b7e8411 100644 (file)
 #include <vconf.h>
 #include <pthread.h>
 #include <sys/time.h>
+#include <TapiUtility.h>
+#include <ITapiNetwork.h>
 
 wifi_manager_h wifi = NULL;
 static bool display_on;
 static int brightness_val = 0;
 static int brightness_flag = 0;
+static int ss_val = 0;
+static int ss_flag = 0;
 static history_item_s *data_obj = NULL;
 
 static int listener_hsp =0;
@@ -41,6 +45,8 @@ static int wifi_hsp=0;
 static int wifi_scan_hsp=0;
 static int wifi_connected_hsp=0;
 static int display_hsp=0;
+static int gps_hsp=0;
+static int charging_hsp=0;
 static event_pool events_buf[10];
 static int buff_count = 0;
 static pthread_cond_t fill = PTHREAD_COND_INITIALIZER;
@@ -48,6 +54,7 @@ static pthread_cond_t empty = PTHREAD_COND_INITIALIZER;
 static pthread_mutex_t battery_lister_mutex = PTHREAD_MUTEX_INITIALIZER;
 static int fill_ptr = 0;
 static int use_ptr = 0;
+static TapiHandle *handle = NULL;
 
 
 
@@ -665,47 +672,159 @@ static void fill_display_brightness_change(int brightness_level)
        ENTER;
 
        _INFO(" device brightness changed =%d ",brightness_level);
-
-
-       if(brightness_level >0 && brightness_level <=10)
+       if(data_obj)
        {
                data_obj->state_1 &= ~brightness_val;
-               brightness_val=0;
+               brightness_val = brightness_level;
                data_obj->state_1 |= brightness_val;
                data_obj->event_code = ET_NONE;
                data_obj->event_tag = NULL;
        }
-       else if(brightness_level >10 && brightness_level <=25)
+
+       EXIT;
+}
+
+
+static void fill_battery_capacity_change(int charging_level)
+{
+       ENTER;
+
+       _INFO(" device battery_capacity changed =%d ",charging_level);
+       if(data_obj)
        {
-               data_obj->state_1 &= ~brightness_val;
-               brightness_val=1;
-               data_obj->state_1 |= brightness_val;
                data_obj->event_code = ET_NONE;
                data_obj->event_tag = NULL;
        }
-       else if(brightness_level >25 && brightness_level <=50)
+
+       EXIT;
+}
+
+
+
+static void fill_charging_status_change(int charging)
+{
+       ENTER;
+
+       _INFO(" device charging_status changed =%d ",charging);
+       if(data_obj)
        {
-               data_obj->state_1 &= ~brightness_val;
-               brightness_val=2;
-               data_obj->state_1 |= brightness_val;
-               data_obj->event_code = ET_NONE;
-               data_obj->event_tag = NULL;
+               if(charging)
+               {
+                       data_obj->event_code = ET_NONE;
+                       data_obj->event_code |= ET_FLAG_START;
+                       data_obj->event_tag = NULL;
+                       data_obj->event_tag = (history_tag_s *)calloc(1, sizeof(history_tag_s));
+                       if(data_obj->event_tag)
+                       {
+                               listener_hsp++;
+                               charging_hsp = listener_hsp;
+                               _INFO("event Tag creation succeeded \n");
+                               data_obj->event_tag->sp_idx = charging_hsp;
+                       }
+                       else
+                       {
+                               _ERR("  data_obj->event_tag object creation fails ");
+                               return;
+                       }
+
+                       data_obj->state_2 |= ST2_CHARGING_FLAG;
+               }
+               else
+               {
+                       data_obj->event_code = ET_NONE;
+                       data_obj->event_code |= ET_FLAG_FINISH;
+                       data_obj->event_tag = NULL;
+                       data_obj->event_tag = (history_tag_s *)calloc(1, sizeof(history_tag_s));
+                       if(data_obj->event_tag)
+                       {
+                               _INFO("event Tag creation succeeded \n");
+                               data_obj->event_tag->sp_idx = charging_hsp;
+                       }
+                       else
+                       {
+                               _ERR("  data_obj->event_tag object creation fails ");
+                               return ;
+                       }
+
+                       data_obj->state_2 &= ~(ST2_CHARGING_FLAG);
+               }
        }
-       else if(brightness_level >50 && brightness_level <=75)
+
+       EXIT;
+}
+
+
+
+
+static void fill_signal_strength_change(int ss)
+{
+       ENTER;
+
+       _INFO(" device signal_strength changed =%d ",ss);
+       if(data_obj)
        {
-               data_obj->state_1 &= ~brightness_val;
-               brightness_val=3;
-               data_obj->state_1 |= brightness_val;
+               data_obj->state_1 &= ~ss_val << ST1_PHONE_SIGNAL_STRENGTH_SHIFT;
+               ss_val = ss;
+               data_obj->state_1 |= ss_val << ST1_PHONE_SIGNAL_STRENGTH_SHIFT;
                data_obj->event_code = ET_NONE;
                data_obj->event_tag = NULL;
        }
-       else if(brightness_level >75 && brightness_level <=100)
+
+       EXIT;
+}
+
+
+
+
+static void fill_location_change(int gps)
+{
+       ENTER;
+
+       _INFO(" maps location changed =%d ",gps);
+       if(data_obj)
        {
-               data_obj->state_1 &= ~brightness_val;
-               brightness_val=4;
-               data_obj->state_1 |= brightness_val;
-               data_obj->event_code = ET_NONE;
-               data_obj->event_tag = NULL;
+               if(gps)
+               {
+                       data_obj->event_code = ET_NONE;
+                       data_obj->event_code |= ET_ACTIVE;
+                       data_obj->event_code |= ET_FLAG_START;
+                       data_obj->event_tag = NULL;
+                       data_obj->event_tag = (history_tag_s *)calloc(1, sizeof(history_tag_s));
+                       if(data_obj->event_tag)
+                       {
+                               listener_hsp++;
+                               gps_hsp = listener_hsp;
+                               _INFO("event Tag creation succeeded \n");
+                               data_obj->event_tag->sp_idx = gps_hsp;
+                       }
+                       else
+                       {
+                               _ERR("  data_obj->event_tag object creation fails ");
+                               return;
+                       }
+
+                       data_obj->state_1 |= ST1_GPS_ON_FLAG;
+               }
+               else
+               {
+                       data_obj->event_code = ET_NONE;
+                       data_obj->event_code |= ET_ACTIVE;
+                       data_obj->event_code |= ET_FLAG_FINISH;
+                       data_obj->event_tag = NULL;
+                       data_obj->event_tag = (history_tag_s *)calloc(1, sizeof(history_tag_s));
+                       if(data_obj->event_tag)
+                       {
+                               _INFO("event Tag creation succeeded \n");
+                               data_obj->event_tag->sp_idx = gps_hsp;
+                       }
+                       else
+                       {
+                               _ERR("  data_obj->event_tag object creation fails ");
+                               return ;
+                       }
+
+                       data_obj->state_1 &= ~(ST1_GPS_ON_FLAG);
+               }
        }
 
 
@@ -714,8 +833,6 @@ static void fill_display_brightness_change(int brightness_level)
 
 
 
-
-
 static void bm_create_event_data(int type,int val)
 {
        ENTER;
@@ -748,6 +865,18 @@ static void bm_create_event_data(int type,int val)
        case LISTEN_BRIGHTNESS_CHANGE:
                fill_display_brightness_change(val);
                break;
+       case LISTEN_BATTERY_CAPACITY_CHANGE:
+               fill_battery_capacity_change(val);
+               break;
+       case LISTEN_LOCATION_CHANGE:
+               fill_location_change(val);
+               break;
+       case LISTEN_CHARGING_STATUS_CHANGE:
+               fill_charging_status_change(val);
+               break;
+       case LISTEN_SIGNAL_STRENGTH_CHANGE:
+               fill_signal_strength_change(val);
+               break;
        default:
                return;
        }
@@ -849,10 +978,11 @@ void* event_producer(void *data)
        pthread_cond_signal(&fill);
        pthread_mutex_unlock(&battery_lister_mutex);
 
-        BM_FREE(event);
-        EXIT;
+       BM_FREE(event);
+       EXIT;
        pthread_exit(NULL);
 
+
 }
 
 
@@ -1155,7 +1285,7 @@ static void __bm_display_brightness_change(keynode_t *key, void* data)
                return;
        }
        display_event->type = LISTEN_BRIGHTNESS_CHANGE;
-       display_event->val = brightness_level;
+       display_event->val = brightness_flag;
 
 
        pthread_t producer ;
@@ -1171,6 +1301,256 @@ static void __bm_display_brightness_change(keynode_t *key, void* data)
 
 
 
+static void __bm_battery_capacity_change(keynode_t *key, void* data)
+{
+       ENTER;
+       _INFO("device battery_capacity changed succeeded\n");
+       int charging =0;
+       vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CAPACITY, &charging);
+
+       _INFO(" device battery_capacity changed =%d ",charging);
+
+       event_pool *charging_event = (event_pool *)calloc(1, sizeof(event_pool));
+       if(!charging_event)
+       {
+               _ERR("Failed to allocated memory ");
+               return;
+       }
+       charging_event->type = LISTEN_BATTERY_CAPACITY_CHANGE;
+       charging_event->val = charging;
+
+
+       pthread_t producer ;
+       if(pthread_create(&producer, NULL, event_producer, charging_event))
+       {
+               _ERR("Failed to pthread_create.");
+               return;
+       }
+
+
+       EXIT;
+}
+
+
+static void __bm_charging_status_change(keynode_t *key, void* data)
+{
+       ENTER;
+       _INFO("device charging_status changed succeeded\n");
+       int charging =0;
+       vconf_get_int(VCONFKEY_SYSMAN_CHARGER_STATUS, &charging);
+
+       _INFO(" device charging_status changed =%d ",charging);
+
+       event_pool *charging_event = (event_pool *)calloc(1, sizeof(event_pool));
+       if(!charging_event)
+       {
+               _ERR("Failed to allocated memory ");
+               return;
+       }
+       charging_event->type = LISTEN_CHARGING_STATUS_CHANGE;
+       charging_event->val = charging;
+
+
+       pthread_t producer ;
+       if(pthread_create(&producer, NULL, event_producer, charging_event))
+       {
+               _ERR("Failed to pthread_create.");
+               return;
+       }
+
+
+       EXIT;
+}
+
+
+
+static void __bm_location_change(keynode_t *key, void* data)
+{
+       ENTER;
+       _INFO("device location changed succeeded\n");
+       int charging =0;
+       vconf_get_int(VCONFKEY_LOCATION_ENABLED, &charging);
+
+       _INFO(" device location changed =%d ",charging);
+
+       event_pool *location_event = (event_pool *)calloc(1, sizeof(event_pool));
+       if(!location_event)
+       {
+               _ERR("Failed to allocated memory ");
+               return;
+       }
+       location_event->type = LISTEN_LOCATION_CHANGE;
+       location_event->val = charging;
+
+
+       pthread_t producer ;
+       if(pthread_create(&producer, NULL, event_producer, location_event))
+       {
+               _ERR("Failed to pthread_create.");
+               return;
+       }
+
+
+       EXIT;
+}
+
+
+
+
+static void __bm_noti_signal_strength(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
+{
+       ENTER;
+       _INFO("device signal strength changed succeeded\n");
+       struct tel_noti_network_signal_strength *noti = data;
+       int sig_strength = noti->dbm;
+
+       _INFO(" device signal strength changed =%d ",sig_strength);
+
+       int flag;
+       if(sig_strength >0 && sig_strength <=12)
+       {
+               flag = 0;
+               if(ss_flag == flag)
+                       return;
+               else
+                       ss_flag = flag;
+       }
+       else if(sig_strength >12 && sig_strength <=25)
+       {
+               flag = 1;
+               if(ss_flag == flag)
+                       return;
+               else
+                       ss_flag = flag;
+       }
+       else if(sig_strength >25 && sig_strength <=37)
+       {
+               flag = 2;
+               if(ss_flag == flag)
+                       return;
+               else
+                       ss_flag = flag;
+       }
+       else if(sig_strength >37 && sig_strength <=50)
+       {
+               flag = 3;
+               if(ss_flag == flag)
+                       return;
+               else
+                       ss_flag = flag;
+       }
+       else if(sig_strength >50 && sig_strength <=62)
+       {
+               flag = 4;
+               if(ss_flag == flag)
+                       return;
+               else
+                       ss_flag = flag;
+       }
+       else if(sig_strength >62 && sig_strength <=75)
+       {
+               flag = 5;
+               if(ss_flag == flag)
+                       return;
+               else
+                       ss_flag = flag;
+       }
+       else if(sig_strength >75 && sig_strength <=87)
+       {
+               flag = 6;
+               if(ss_flag == flag)
+                       return;
+               else
+                       ss_flag = flag;
+       }
+       else if(sig_strength >87 && sig_strength <=100)
+       {
+               flag = 7;
+               if(ss_flag == flag)
+                       return;
+               else
+                       ss_flag = flag;
+       }
+
+       event_pool *signal_event = (event_pool *)calloc(1, sizeof(event_pool));
+       if(!signal_event)
+       {
+               _ERR("Failed to allocated memory ");
+               return;
+       }
+       signal_event->type = LISTEN_SIGNAL_STRENGTH_CHANGE;
+       signal_event->val = ss_flag;
+
+
+       pthread_t producer ;
+       if(pthread_create(&producer, NULL, event_producer, signal_event))
+       {
+               _ERR("Failed to pthread_create.");
+               return;
+       }
+
+
+       EXIT;
+}
+
+
+
+static int  bm_charging_status_listeners()
+{
+       ENTER;
+
+       /*      Charging callbacks */
+       int ret = 0;
+       ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_CHARGER_STATUS, __bm_charging_status_change, NULL);
+       if (ret != 0) {
+               _ERR("failed to register a cb key:%s err:%d","VCONFKEY_SYSMAN_CHARGER_STATUS", ret);
+               return 1;
+       }
+
+       EXIT;
+       return 0;
+
+}
+
+
+
+static int  bm_battery_capacity_listeners()
+{
+       ENTER;
+
+       /*      Charging callbacks */
+       int ret = 0;
+       ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, __bm_battery_capacity_change, NULL);
+       if (ret != 0) {
+               _ERR("failed to register a cb key:%s err:%d","VCONFKEY_SYSMAN_BATTERY_CAPACITY", ret);
+               return 1;
+       }
+
+       EXIT;
+       return 0;
+
+}
+
+
+
+static int  bm_location_listeners()
+{
+       ENTER;
+
+       /*      Charging callbacks */
+       int ret = 0;
+       ret = vconf_notify_key_changed(VCONFKEY_LOCATION_ENABLED, __bm_location_change, NULL);
+       if (ret != 0) {
+               _ERR("failed to register a cb key:%s err:%d","VCONFKEY_LOCATION_ENABLED", ret);
+               return 1;
+       }
+
+       EXIT;
+       return 0;
+
+}
+
+
 static int  bm_screen_subscribe_listeners()
 {
        ENTER;
@@ -1189,6 +1569,27 @@ static int  bm_screen_subscribe_listeners()
 
 
 
+static int  bm_signal_strength_listeners()
+{
+       ENTER;
+       /*      Screen callbacks */
+       handle = tel_init(NULL);
+       if(handle)
+       {
+               int ret = tel_register_noti_event(handle,TAPI_NOTI_NETWORK_SIGNALSTRENGTH, __bm_noti_signal_strength, NULL);
+               if (ret != BATTERY_MONITOR_ERROR_NONE) {
+                       _ERR("device_add_callback failed: %s", get_error_message(ret));
+                       return 1;
+               }
+       }
+
+       EXIT;
+       return 0;
+
+}
+
+
+
 static int  bm_display_brightness_listeners()
 {
        ENTER;
@@ -1392,6 +1793,32 @@ int bd_initialize_listeners(void)
        else
                _ERR("Brightness listeners failed to subscribed\n");
 
+
+       /*      battery_capacity change callbacks */
+       if(!bm_battery_capacity_listeners())
+               _INFO("battery_capacity listeners succeeded to subscribed\n");
+       else
+               _ERR("battery_capacity listeners failed to subscribed\n");
+
+       /*      battery charging change callbacks */
+       if(!bm_charging_status_listeners())
+               _INFO("battery charging listeners succeeded to subscribed\n");
+       else
+               _ERR("battery charging listeners failed to subscribed\n");
+
+       /*      GPS change callbacks */
+       if(!bm_location_listeners())
+               _INFO("location listeners succeeded to subscribed\n");
+       else
+               _ERR("location listeners failed to subscribed\n");
+
+
+       /*      Signal strength callbacks */
+       if(!bm_signal_strength_listeners())
+               _INFO("Signal strength listeners succeeded to subscribed\n");
+       else
+               _ERR("Signal strength listeners failed to subscribed\n");
+
        EXIT;
        return BATTERY_MONITOR_ERROR_NONE;
 }
@@ -1440,11 +1867,33 @@ int bd_deinitialize_listeners()
 
 
        //Brightness
-       if (vconf_ignore_key_changed(VCONFKEY_SETAPPL_LCD_BRIGHTNESS,__bm_display_brightness_change) < 0)
+       if (vconf_ignore_key_changed(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, __bm_display_brightness_change) < 0)
        {
                _ERR("failed to de-register vconf callback");
        }
 
+       //Battery capacity
+       if (vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, __bm_battery_capacity_change) < 0)
+       {
+               _ERR("failed to de-register vconf callback");
+       }
+
+       //Battery charging
+       if (vconf_ignore_key_changed(VCONFKEY_SYSMAN_CHARGER_STATUS, __bm_charging_status_change) < 0)
+       {
+               _ERR("failed to de-register vconf callback");
+       }
+
+       if(handle)
+       {
+               int ret = tel_deregister_noti_event(handle,TAPI_NOTI_NETWORK_SIGNALSTRENGTH);
+               if (ret != BATTERY_MONITOR_ERROR_NONE) {
+                       _ERR("tel_deregister_noti_event failed: %s", get_error_message(ret));
+                       return 1;
+               }
+               tel_deinit(handle);
+       }
+
        if(data_obj)
        {
                BM_FREE(data_obj);