Support extcon counter using device-notifier 29/221129/9 accepted/tizen/unified/20191227.142559 submit/tizen/20191227.111333
authorYoungjae Cho <y0.cho@samsung.com>
Fri, 27 Dec 2019 09:01:11 +0000 (18:01 +0900)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Fri, 27 Dec 2019 11:11:56 +0000 (20:11 +0900)
Change-Id: If4c43890024c147561d31e41ade60066c3f321fa
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
Signed-off-by: Hyotaek Shim <hyotaek.shim@samsung.com>
CMakeLists.txt
packaging/deviced.spec
src/battery/power-supply.c
src/core/device-notifier.h
src/extcon/earjack.c
src/extcon/extcon-count.h [new file with mode: 0644]
src/extcon/extcon.c
src/extcon/extcon.h

index 315b542..3a318d2 100644 (file)
@@ -258,13 +258,9 @@ INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/deviced/ DESTINATION include/$
                PATTERN "*_doc.h" EXCLUDE
                PATTERN "*.h")
 
-INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/core/ DESTINATION include/${PROJECT_NAME}/core
-               FILES_MATCHING
-               PATTERN "*.h")
-
-INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/shared/ DESTINATION include/${PROJECT_NAME}/shared
-               FILES_MATCHING
-               PATTERN "*.h")
+INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/core/ DESTINATION include/${PROJECT_NAME}/core FILES_MATCHING PATTERN "*.h")
+INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/shared/ DESTINATION include/${PROJECT_NAME}/shared FILES_MATCHING PATTERN "*.h")
+INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/extcon/ DESTINATION include/${PROJECT_NAME}/extcon FILES_MATCHING PATTERN "*.h")
 
 IF(BATTERY_MODULE STREQUAL on)
        INSTALL_CONF(conf battery)
index cd1c67b..15b7ca5 100644 (file)
@@ -271,6 +271,7 @@ mv %{_libdir}/iot-display.so %{_libdir}/deviced/display.so
 %{_includedir}/deviced/*.h
 %{_includedir}/deviced/core/*.h
 %{_includedir}/deviced/shared/*.h
+%{_includedir}/deviced/extcon/*.h
 %{_libdir}/libdeviced.so
 %{_libdir}/pkgconfig/deviced.pc
 
index 876fc94..5c6fca2 100644 (file)
@@ -39,6 +39,7 @@
 #include "apps/apps.h"
 #include "power-supply.h"
 #include "battery.h"
+#include "extcon/extcon.h"
 
 #ifndef VCONFKEY_SETAPPL_BLOCKMODE_WEARABLE_BOOL
 #define VCONFKEY_SETAPPL_BLOCKMODE_WEARABLE_BOOL "db/setting/blockmode_wearable"
@@ -635,6 +636,7 @@ static bool update_online(void)
        if (battery.online > POWER_SUPPLY_TYPE_BATTERY &&
            online_status == VCONFKEY_SYSMAN_CHARGER_DISCONNECTED) {
                online_status = VCONFKEY_SYSMAN_CHARGER_CONNECTED;
+               extcon_update_count(EXTCON_TA, 1);
                check_power_supply(online_status);
                charger_state_send_system_event(CHARGE_STATUS_CONNECTED);
                if (old_battery.charge_status != battery.charge_status)
@@ -759,6 +761,45 @@ static void check_capacity_status(const char *env_value)
        battery.capacity = atoi(env_value);
 }
 
+static void update_capacity_full(void)
+{
+       static int old;
+       int delta;
+
+       if (battery.online <= POWER_SUPPLY_TYPE_BATTERY ||
+           old == 0 ||
+           old >= battery.capacity) {
+               old = battery.capacity;
+               return;
+       }
+       delta = battery.capacity - old;
+       old = battery.capacity;
+       extcon_update_count(EXTCON_BATTERY_FULL, delta);
+}
+
+static void update_battery_cycle(void)
+{
+       static int first = 1;
+       static int old;
+       int delta;
+
+       if (first) {
+               first = 0;
+               extcon_update_count(EXTCON_BATTERY_CYCLE, 0);
+               return;
+       }
+
+       if (battery.online > POWER_SUPPLY_TYPE_BATTERY ||
+           old == 0 ||
+           old <= battery.capacity) {
+               old = battery.capacity;
+               return;
+       }
+       delta = old - battery.capacity;
+       old = battery.capacity;
+       extcon_update_count(EXTCON_BATTERY_CYCLE, delta);
+}
+
 static void process_power_supply(void *data)
 {
        bool broadcasted = true;
@@ -858,9 +899,11 @@ static void process_power_supply(void *data)
 
        device_notify(DEVICE_NOTIFIER_POWER_SUPPLY, NULL);
        if (old_battery.charge_now != battery.charge_now) {
-       device_notify(DEVICE_NOTIFIER_BATTERY_CHARGING, &battery.charge_now);
+               device_notify(DEVICE_NOTIFIER_BATTERY_CHARGING, &battery.charge_now);
                old_battery.charge_now = battery.charge_now;
        }
+       update_capacity_full();
+       update_battery_cycle();
        if (lock == 0) {
                if (disp_plgn.pm_unlock_internal)
                        disp_plgn.pm_unlock_internal(INTERNAL_LOCK_BATTERY, LCD_OFF, PM_SLEEP_MARGIN);
index e1f7b65..98fca83 100644 (file)
@@ -60,6 +60,7 @@ enum device_notifier_type {
        DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS,
        DEVICE_NOTIFIER_ULTRAPOWERSAVING,
        DEVICE_NOTIFIER_CRITICAL_LOG,
+       DEVICE_NOTIFIER_EXTCON_COUNT,
        DEVICE_NOTIFIER_MAX,
 };
 
index aa40699..e639b9a 100644 (file)
@@ -79,6 +79,8 @@ static int earjack_update(int status)
        if (status != EARJACK_DICONNECTED) {
                if (disp_plgn.pm_change_internal)
                        disp_plgn.pm_change_internal(INTERNAL_LOCK_EARJACK, LCD_NORMAL);
+
+               extcon_update_count(EXTCON_EARJACK, 1);
        }
 
        return 0;
diff --git a/src/extcon/extcon-count.h b/src/extcon/extcon-count.h
new file mode 100644 (file)
index 0000000..cb8fde9
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * deviced
+ *
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __EXTCON_COUNT_H__
+#define __EXTCON_COUNT_H__
+
+#include "core/common.h"
+
+typedef enum {
+       EXTCON_TA                       = 0,
+       EXTCON_EARJACK,
+       EXTCON_BATTERY_FULL,
+       EXTCON_BATTERY_CYCLE,
+} extcon_index_type_e;
+
+struct extcon_notifier {
+       extcon_index_type_e index;
+       int count;
+};
+
+#endif /* __EXTCON_COUNT_H__ */
index 5bdfc45..810409d 100644 (file)
@@ -38,7 +38,6 @@
 #define BUF_MAX 256
 
 static dd_list *extcon_list;
-
 static struct external_connection_device *extcon_dev;
 
 void add_extcon(struct extcon_ops *dev)
@@ -84,6 +83,15 @@ int extcon_get_status(const char *name)
        return dev->status;
 }
 
+void extcon_update_count(extcon_index_type_e index, unsigned long count)
+{
+       struct extcon_notifier extcon;
+       extcon.index = index;
+       extcon.count = count;
+
+       device_notify(DEVICE_NOTIFIER_EXTCON_COUNT, (void *)&extcon);
+}
+
 static int extcon_update(const char *name, const char *value)
 {
        struct extcon_ops *dev;
index e6b3ab9..7369fb0 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "core/common.h"
 #include <hw/external_connection.h>
+#include "extcon-count.h"
 
 /**
  * Extcon cable name is shared with kernel extcon class.
@@ -92,4 +93,5 @@ void remove_extcon(struct extcon_ops *dev);
 int extcon_get_status(const char *name);
 int extcon_enable_device(const char *name);
 int extcon_disable_device(const char *name);
+void extcon_update_count(extcon_index_type_e index, unsigned long count);
 #endif /* __EXTCON_H__ */