Add charger status check feature 46/171146/2
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 27 Feb 2018 02:47:42 +0000 (11:47 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 27 Feb 2018 05:00:18 +0000 (14:00 +0900)
In the wearable profile, an application shouldn't use auto rotation
feature unless the battery status is charging.

Change-Id: I89689dddc027078215d1a7834b7e947e57609f10
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
CMakeLists.txt
packaging/app-core.spec
src/appcore-rotation.c

index 9e357fdd8b9fc1d8cef476cde4485e0cabdad6f8..f2e3f52d23fb23e5ee2c697422573eda22bb7e0f 100644 (file)
@@ -39,6 +39,10 @@ IF(_APPFW_FEATURE_BACKGROUND_MANAGEMENT)
         ADD_DEFINITIONS("-D_APPFW_FEATURE_BACKGROUND_MANAGEMENT")
 ENDIF(_APPFW_FEATURE_BACKGROUND_MANAGEMENT)
 
+IF(_TIZEN_FEATURE_CHARGER_STATUS)
+       ADD_DEFINITIONS("-DTIZEN_FEATURE_CHARGER_STATUS")
+ENDIF(_TIZEN_FEATURE_CHARGER_STATUS)
+
 SET(HEADERS_common appcore-common.h)
 
 INCLUDE(FindPkgConfig)
index d5f2513fe4a5a0889aecdfdf0b666d0235d03e62..1e48cc291e8b6f130b91f03ec0b5f8d81bc5873e 100644 (file)
@@ -94,12 +94,15 @@ Application basics template
 
 %if "%{?profile}" == "wearable"
 %define appfw_feature_background_management 1
+%define tizen_feature_charger_status 1
 %else
 %if "%{?profile}" == "mobile"
 %define appfw_feature_background_management 1
+%define tizen_feature_charger_status 0
 %else
 %if "%{?profile}" == "tv"
 %define appfw_feature_background_management 0
+%define tizen_feature_charger_status 0
 %endif
 %endif
 %endif
@@ -119,10 +122,15 @@ _WITH_X11=ON
 _APPFW_FEATURE_BACKGROUND_MANAGEMENT=ON
 %endif
 
+%if 0%{?tizen_feature_charger_status}
+_TIZEN_FEATURE_CHARGER_STATUS=ON
+%endif
+
 %cmake . \
        -D_WITH_WAYLAND:BOOL=${_WITH_WAYLAND} \
        -D_WITH_X11:BOOL=${_WITH_X11} \
        -D_APPFW_FEATURE_BACKGROUND_MANAGEMENT:BOOL=${_APPFW_FEATURE_BACKGROUND_MANAGEMENT} \
+       -D_TIZEN_FEATURE_CHARGER_STATUS:BOOL=${_TIZEN_FEATURE_CHARGER_STATUS} \
        -DENABLE_GTK=OFF
 
 make %{?_smp_mflags}
index 5d905260a7213d3d2b890a859e2ccde54ec34fd3..7265375c6b0563a6ab95dfc9bb66385d2b86913f 100644 (file)
@@ -55,6 +55,9 @@ struct rot_s {
        void *cbdata;
        int cb_set;
        int sensord_started;
+#ifdef TIZEN_FEATURE_CHARGER_STATUS
+       int charger_status;
+#endif
 
        struct ui_wm_rotate* wm_rotate;
 };
@@ -187,6 +190,33 @@ static void __del_rotlock(void)
        rot.lock = 0;
 }
 
+#ifdef TIZEN_FEATURE_CHARGER_STATUS
+static void __charger_status_changed_cb(keynode_t *keynode, void *user_data)
+{
+       rot.charger_status = vconf_keynode_get_int(keynode);
+       if (rot.charger_status)
+               appcore_resume_rotation_cb();
+       else
+               appcore_pause_rotation_cb();
+       _DBG("charger status(%d)", rot.charger_status);
+}
+#endif
+
+static int __connect_sensor(void)
+{
+       sensor_t sensor;
+       int handle;
+
+       sensor = sensord_get_sensor(AUTO_ROTATION_SENSOR);
+       handle = sensord_connect(sensor);
+       if (handle < 0) {
+               _ERR("Failed to connect sensor");
+               return -1;
+       }
+
+       return handle;
+}
+
 EXPORT_API int appcore_set_rotation_cb(int (*cb) (void *evnet_info, enum appcore_rm, void *),
                                       void *data)
 {
@@ -195,7 +225,6 @@ EXPORT_API int appcore_set_rotation_cb(int (*cb) (void *evnet_info, enum appcore
        else {
                bool r;
                int handle;
-               sensor_t sensor = sensord_get_sensor(AUTO_ROTATION_SENSOR);
 
                if (cb == NULL) {
                        errno = EINVAL;
@@ -207,9 +236,27 @@ EXPORT_API int appcore_set_rotation_cb(int (*cb) (void *evnet_info, enum appcore
                        return -1;
                }
 
-               handle = sensord_connect(sensor);
+               rot.callback = cb;
+               rot.cbdata = data;
+
+#ifdef TIZEN_FEATURE_CHARGER_STATUS
+               vconf_get_int(VCONFKEY_SYSMAN_CHARGER_STATUS,
+                               &rot.charger_status);
+               vconf_notify_key_changed(VCONFKEY_SYSMAN_CHARGER_STATUS,
+                               __charger_status_changed_cb, NULL);
+               if (!rot.charger_status) {
+                       _DBG("charger status(%d)", rot.charger_status);
+                       rot.handle = -1;
+                       return 0;
+               }
+#endif
+
+               handle = __connect_sensor();
                if (handle < 0) {
                        _ERR("sensord_connect failed: %d", handle);
+                       rot.callback = NULL;
+                       rot.cbdata = NULL;
+                       rot.cb_set = 0;
                        return -1;
                }
 
@@ -218,12 +265,12 @@ EXPORT_API int appcore_set_rotation_cb(int (*cb) (void *evnet_info, enum appcore
                if (!r) {
                        _ERR("sensord_register_event failed");
                        sensord_disconnect(handle);
+                       rot.callback = NULL;
+                       rot.cbdata = NULL;
+                       rot.cb_set = 0;
                        return -1;
                }
-
                rot.cb_set = 1;
-               rot.callback = cb;
-               rot.cbdata = data;
 
                r = sensord_start(handle, 0);
                if (!r) {
@@ -262,6 +309,11 @@ EXPORT_API int appcore_unset_rotation_cb(void)
 
                _retv_if(rot.callback == NULL, 0);
 
+#ifdef TIZEN_FEATURE_CHARGER_STATUS
+               vconf_ignore_key_changed(VCONFKEY_SYSMAN_CHARGER_STATUS,
+                               __charger_status_changed_cb);
+#endif
+
                __del_rotlock();
 
                if (rot.cb_set) {
@@ -350,6 +402,15 @@ EXPORT_API int appcore_pause_rotation_cb(void)
                        }
                        rot.sensord_started = 0;
                }
+
+               if (rot.handle >= 0) {
+                       r = sensord_disconnect(rot.handle);
+                       if (!r) {
+                               _ERR("Failed to disconnect sensor. err(%d)", r);
+                               return -1;
+                       }
+                       rot.handle = -1;
+               }
        }
 
        return 0;
@@ -366,12 +427,23 @@ EXPORT_API int appcore_resume_rotation_cb(void)
                _retv_if(rot.callback == NULL, 0);
                _DBG("[APP %d] appcore_resume_rotation_cb is called", getpid());
 
+               if (rot.handle < 0) {
+                       r = __connect_sensor();
+                       if (r < 0) {
+                               _ERR("Failed to connect sensor");
+                               return -1;
+                       }
+                       rot.handle = r;
+               }
+
                if (rot.cb_set == 0) {
                        r = sensord_register_event(rot.handle,
                                        AUTO_ROTATION_CHANGE_STATE_EVENT,
                                        SENSOR_INTERVAL_NORMAL, 0, __changed_cb, rot.cbdata);
                        if (!r) {
                                _ERR("sensord_register_event failed");
+                               sensord_disconnect(rot.handle);
+                               rot.handle = -1;
                                return -1;
                        }
                        rot.cb_set = 1;
@@ -386,6 +458,8 @@ EXPORT_API int appcore_resume_rotation_cb(void)
                                if (!r)
                                        _ERR("sensord_unregister_event failed");
                                rot.cb_set = 0;
+                               sensord_disconnect(rot.handle);
+                               rot.handle = -1;
                                return -1;
                        }
                        rot.sensord_started = 1;