From: Hwankyu Jhun Date: Tue, 27 Feb 2018 02:47:42 +0000 (+0900) Subject: Add charger status check feature X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c8eb8d60845199e22dc9f65289a24146764df0ce;p=platform%2Fcore%2Fappfw%2Fapp-core.git Add charger status check feature 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 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e357fd..f2e3f52 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/packaging/app-core.spec b/packaging/app-core.spec index d5f2513..1e48cc2 100644 --- a/packaging/app-core.spec +++ b/packaging/app-core.spec @@ -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} diff --git a/src/appcore-rotation.c b/src/appcore-rotation.c index 5d90526..7265375 100644 --- a/src/appcore-rotation.c +++ b/src/appcore-rotation.c @@ -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;