2 * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <sensor_internal.h>
23 #include "appcore-internal.h"
27 int (*callback) (void *event_info, enum appcore_rm, void *);
34 struct ui_wm_rotate* wm_rotate;
36 static struct rot_s rot;
39 enum auto_rotation_state re;
43 static struct rot_evt re_to_rm[] = {
45 AUTO_ROTATION_DEGREE_0,
46 APPCORE_RM_PORTRAIT_NORMAL,
49 AUTO_ROTATION_DEGREE_90,
50 APPCORE_RM_LANDSCAPE_NORMAL,
53 AUTO_ROTATION_DEGREE_180,
54 APPCORE_RM_PORTRAIT_REVERSE,
57 AUTO_ROTATION_DEGREE_270,
58 APPCORE_RM_LANDSCAPE_REVERSE,
62 static enum appcore_rm __get_mode(sensor_data_t data)
68 m = APPCORE_RM_UNKNOWN;
69 if (data.value_count > 0) {
70 event = (int)data.values[0];
72 _ERR("Failed to get sensor data");
76 for (i = 0; i < sizeof(re_to_rm) / sizeof(re_to_rm[0]); i++) {
77 if (re_to_rm[i].re == event) {
86 static void __changed_cb(sensor_t sensor, unsigned int event_type,
87 sensor_data_t *data, void *user_data)
94 if (event_type != AUTO_ROTATION_CHANGE_STATE_EVENT) {
99 m = __get_mode(*data);
101 _DBG("[APP %d] Rotation: %d -> %d", getpid(), rot.mode, m);
104 if (rot.cb_set && rot.mode != m) {
105 _DBG("[APP %d] Rotation: %d -> %d", getpid(), rot.mode, m);
106 rot.callback((void *)&m, m, user_data);
112 static void __lock_cb(keynode_t *node, void *data)
117 rot.lock = !vconf_keynode_get_bool(node);
120 m = APPCORE_RM_PORTRAIT_NORMAL;
122 rot.callback((void *)&m, m, data);
125 _DBG("[APP %d] Rotation locked", getpid());
129 _DBG("[APP %d] Rotation unlocked", getpid());
132 r = appcore_get_rotation_state(&m);
133 _DBG("[APP %d] Rotmode prev %d -> curr %d", getpid(),
135 if (!r && rot.mode != m) {
136 rot.callback((void *)&m, m, data);
143 static void __add_rotlock(void *data)
149 r = vconf_get_bool(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, &lock);
151 _DBG("[APP %d] Rotation vconf get bool failed", getpid());
155 vconf_notify_key_changed(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, __lock_cb,
159 static void __del_rotlock(void)
161 vconf_ignore_key_changed(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, __lock_cb);
165 EXPORT_API int appcore_set_rotation_cb(int (*cb) (void *evnet_info, enum appcore_rm, void *),
169 return rot.wm_rotate->set_rotation_cb(cb, data);
173 sensor_t sensor = sensord_get_sensor(AUTO_ROTATION_SENSOR);
180 if (rot.callback != NULL) {
185 handle = sensord_connect(sensor);
187 _ERR("sensord_connect failed: %d", handle);
191 r = sensord_register_event(handle, AUTO_ROTATION_CHANGE_STATE_EVENT,
192 SENSOR_INTERVAL_NORMAL, 0, __changed_cb, data);
194 _ERR("sensord_register_event failed");
195 sensord_disconnect(handle);
203 r = sensord_start(handle, 0);
205 _ERR("sensord_start failed");
206 r = sensord_unregister_event(handle, AUTO_ROTATION_CHANGE_STATE_EVENT);
208 _ERR("sensord_unregister_event failed");
213 rot.sensord_started = 0;
214 sensord_disconnect(handle);
217 rot.sensord_started = 1;
225 EXPORT_API int appcore_unset_rotation_cb(void)
228 return rot.wm_rotate->unset_rotation_cb();
232 _retv_if(rot.callback == NULL, 0);
237 r = sensord_unregister_event(rot.handle,
238 AUTO_ROTATION_CHANGE_STATE_EVENT);
240 _ERR("sensord_unregister_event failed");
248 if (rot.sensord_started == 1) {
249 r = sensord_stop(rot.handle);
251 _ERR("sensord_stop failed");
254 rot.sensord_started = 0;
257 r = sensord_disconnect(rot.handle);
259 _ERR("sensord_disconnect failed");
267 EXPORT_API int appcore_get_rotation_state(enum appcore_rm *curr)
270 return rot.wm_rotate->get_rotation_state(curr);
280 r = sensord_get_data(rot.handle, AUTO_ROTATION_SENSOR, &data);
282 _ERR("sensord_get_data failed");
283 *curr = APPCORE_RM_UNKNOWN;
287 *curr = __get_mode(data);