Add charger status check feature 68/171068/2
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 26 Feb 2018 07:54:41 +0000 (16:54 +0900)
committerHwanKyu Jhun <h.jhun@samsung.com>
Mon, 26 Feb 2018 10:03:10 +0000 (10:03 +0000)
In the wearable profile, an application shouldn't use auto rotation
feature unless the battery status is charging.

Change-Id: I5db7ae47d24be371101c0356b3d492d65cf6274d
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/base/appcore_base.c
src/base/appcore_base_private.h

index 34d9278..1754f07 100644 (file)
@@ -70,6 +70,8 @@ typedef struct _appcore_base_rotation {
        int lock;
        int ref;
        enum appcore_base_rm rm;
+       int charger_status;
+       bool initialized;
 } appcore_base_rotation;
 
 struct lang_info_s {
@@ -243,13 +245,9 @@ static void __auto_rotation_changed_cb(sensor_t sensor, unsigned int event_type,
        __invoke_callback((void *)&__rotation.rm, APPCORE_BASE_EVENT_DEVICE_ORIENTATION_CHANGED);
 }
 
-static void __unregister_rotation_changed_event(void)
+static void __fini_rotation(void)
 {
-       if (!__rotation.ref)
-               return;
-
-       __rotation.ref--;
-       if (__rotation.ref > 1)
+       if (!__rotation.initialized)
                return;
 
        vconf_ignore_key_changed(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, __lock_cb);
@@ -258,19 +256,17 @@ static void __unregister_rotation_changed_event(void)
        sensord_disconnect(__rotation.conn);
 
        __rotation.lock = 0;
-       __rotation.ref = 0;
+       __rotation.initialized = false;
 }
 
-static void __register_rotation_changed_event(void)
+static void __init_rotation(void)
 {
        sensor_t sensor;
        int lock;
        bool r;
 
-       if (__rotation.ref) {
-               __rotation.ref++;
+       if (__rotation.initialized)
                return;
-       }
 
        sensor = sensord_get_sensor(AUTO_ROTATION_SENSOR);
        __rotation.conn = sensord_connect(sensor);
@@ -300,6 +296,60 @@ static void __register_rotation_changed_event(void)
        vconf_notify_key_changed(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, __lock_cb, NULL);
 
        __rotation.lock = !lock;
+       __rotation.initialized = true;
+}
+
+static void __charger_status_changed_cb(keynode_t *keynode, void *user_data)
+{
+       if (TIZEN_FEATURE_CHARGER_STATUS) {
+               __rotation.charger_status = vconf_keynode_get_int(keynode);
+               if (__rotation.charger_status) {
+                       if (__rotation.ref)
+                               __init_rotation();
+               } else {
+                       if (__rotation.ref)
+                               __fini_rotation();
+               }
+               _DBG("charger status(%d)", __rotation.charger_status);
+       }
+}
+
+static void __unregister_rotation_changed_event(void)
+{
+       if (!__rotation.ref)
+               return;
+
+       __rotation.ref--;
+       if (__rotation.ref > 1)
+               return;
+
+       __fini_rotation();
+       if (TIZEN_FEATURE_CHARGER_STATUS) {
+               vconf_ignore_key_changed(VCONFKEY_SYSMAN_CHARGER_STATUS,
+                               __charger_status_changed_cb);
+       }
+
+       __rotation.ref = 0;
+}
+
+static void __register_rotation_changed_event(void)
+{
+       if (__rotation.ref) {
+               __rotation.ref++;
+               return;
+       }
+
+       if (TIZEN_FEATURE_CHARGER_STATUS) {
+               vconf_get_int(VCONFKEY_SYSMAN_CHARGER_STATUS,
+                               &__rotation.charger_status);
+               vconf_notify_key_changed(VCONFKEY_SYSMAN_CHARGER_STATUS,
+                               __charger_status_changed_cb, NULL);
+               if (__rotation.charger_status)
+                       __init_rotation();
+       } else {
+               __init_rotation();
+       }
+
        __rotation.ref++;
 }
 
index 6c4b95d..003e747 100644 (file)
@@ -94,6 +94,8 @@ appcore_base_tizen_profile_t appcore_base_get_tizen_profile(void);
 
 #define TIZEN_FEATURE_BACKGROUND_MANAGEMENT \
        (!(appcore_base_get_tizen_profile() & TIZEN_PROFILE_TV))
+#define TIZEN_FEATURE_CHARGER_STATUS \
+       (appcore_base_get_tizen_profile() & TIZEN_PROFILE_WEARABLE)
 
 extern void aul_finalize();