Resolved ASAN issues
[platform/core/api/location-manager.git] / src / location_internal.c
1 /*
2  * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <system_info.h>
21 #include "location_internal.h"
22
23 int __convert_error_code(int code)
24 {
25         int ret;
26         const char *msg = NULL;
27         switch (code) {
28         case LOCATION_ERROR_NONE:
29                 ret = LOCATIONS_ERROR_NONE;
30                 msg = "LOCATIONS_ERROR_NONE";
31                 break;
32         case LOCATION_ERROR_PARAMETER:
33                 ret = LOCATIONS_ERROR_INVALID_PARAMETER;
34                 msg = "LOCATIONS_ERROR_INVALID_PARAMETER";
35                 break;
36         //LCOV_EXCL_START
37         case LOCATION_ERROR_NOT_ALLOWED:
38                 ret = LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
39                 msg = "LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED";
40                 break;
41         case LOCATION_ERROR_NOT_SUPPORTED:
42                 ret = LOCATIONS_ERROR_NOT_SUPPORTED;
43                 msg = "LOCATIONS_ERROR_NOT_SUPPORTED";
44                 break;
45         case LOCATION_ERROR_NETWORK_FAILED:
46         case LOCATION_ERROR_NETWORK_NOT_CONNECTED:
47                 ret = LOCATIONS_ERROR_NETWORK_FAILED;
48                 msg = "LOCATIONS_ERROR_NETWORK_FAILED";
49                 break;
50         case LOCATION_ERROR_SETTING_OFF:
51                 ret = LOCATIONS_ERROR_SETTING_OFF;
52                 msg = "LOCATIONS_ERROR_SETTING_OFF";
53                 break;
54         case LOCATION_ERROR_SECURITY_DENIED:
55                 ret = LOCATIONS_ERROR_SECURITY_RESTRICTED;
56                 msg = "LOCATIONS_ERROR_SECURITY_RESTRICTED";
57                 break;
58         case LOCATION_ERROR_NOT_AVAILABLE:
59         case LOCATION_ERROR_CONFIGURATION:
60         case LOCATION_ERROR_UNKNOWN:
61         default:
62                 msg = "LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE";
63                 ret = LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
64         //LCOV_EXCL_STOP
65         }
66
67         if (ret != LOCATIONS_ERROR_NONE)
68                 LOCATIONS_LOGE("%s(0x%08x) : core fw error(0x%x)", msg, ret, code);
69
70         return ret;
71 }
72
73 int __is_gps_supported(void)
74 {
75         bool is_supported = false;
76         int retval = 0;
77
78         retval = system_info_get_platform_bool("http://tizen.org/feature/location.gps", &is_supported);
79         if (retval != SYSTEM_INFO_ERROR_NONE)
80                 LOCATIONS_LOGW("system_info_get_platform_bool failed: retval = %d", retval);    //LCOV_EXCL_LINE
81
82         if (is_supported == false)
83                 return LOCATIONS_ERROR_NOT_SUPPORTED;
84
85         return LOCATIONS_ERROR_NONE;
86 }
87
88 int __is_gps_satellite_supported(void)
89 {
90         bool is_supported = false;
91         int retval = 0;
92
93         retval = system_info_get_platform_bool("http://tizen.org/feature/location.gps.satellite", &is_supported);
94         if (retval != SYSTEM_INFO_ERROR_NONE)
95                 LOCATIONS_LOGW("system_info_get_platform_bool failed: retval = %d", retval);    //LCOV_EXCL_LINE
96
97         if (is_supported == false)
98                 return LOCATIONS_ERROR_NOT_SUPPORTED;
99
100         return LOCATIONS_ERROR_NONE;
101 }
102
103 int __is_wps_supported(void)
104 {
105         bool is_supported = false;
106         int retval = 0;
107
108         retval = system_info_get_platform_bool("http://tizen.org/feature/location.wps", &is_supported);
109         if (retval != SYSTEM_INFO_ERROR_NONE)
110         //LCOV_EXCL_START
111                 LOCATIONS_LOGW("system_info_get_platform_bool failed: retval = %d", retval);
112
113         if (is_supported == false)
114                 return LOCATIONS_ERROR_NOT_SUPPORTED;
115
116         return LOCATIONS_ERROR_NONE;
117         //LCOV_EXCL_STOP
118 }
119
120 int __is_location_supported(void)
121 {
122         if (__is_gps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
123                 //LCOV_EXCL_START
124                 if (__is_wps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED)
125                         return LOCATIONS_ERROR_NOT_SUPPORTED;
126                 else
127                         return LOCATIONS_ERROR_NONE;
128                 //LCOV_EXCL_STOP
129         }
130
131         return LOCATIONS_ERROR_NONE;
132 }
133
134 int __is_batch_supported(void)
135 {
136         bool is_supported = false;
137         int retval = 0;
138
139         retval = system_info_get_platform_bool("http://tizen.org/feature/location.batch", &is_supported);
140         if (retval != SYSTEM_INFO_ERROR_NONE)
141                 LOCATIONS_LOGW("system_info_get_platform_bool failed: retval = %d", retval);
142
143         if (is_supported == false)
144                 return LOCATIONS_ERROR_NOT_SUPPORTED;
145
146         return LOCATIONS_ERROR_NONE;    //LCOV_EXCL_LINE
147 }
148
149 int __is_fused_supported(void)
150 {
151         bool is_supported = false;
152         bool is_accelerometer = false;
153         bool is_gyroscope = false;
154         int retval = 0;
155
156         retval = system_info_get_platform_bool("http://tizen.org/feature/location.fused", &is_supported);
157         if (retval != SYSTEM_INFO_ERROR_NONE)
158                 LOCATIONS_LOGW("system_info_get_platform_bool failed: retval = %d", retval);
159         if (is_supported == false)
160                 return LOCATIONS_ERROR_NOT_SUPPORTED;
161
162         retval = system_info_get_platform_bool("http://tizen.org/feature/sensor.accelerometer", &is_accelerometer);
163         if (retval != SYSTEM_INFO_ERROR_NONE)
164                 LOCATIONS_LOGW("system_info_get_platform_bool failed: retval = %d", retval);
165         if (is_accelerometer == false)
166                 return LOCATIONS_ERROR_NOT_SUPPORTED;
167
168         retval = system_info_get_platform_bool("http://tizen.org/feature/sensor.gyroscope", &is_gyroscope);
169         if (retval != SYSTEM_INFO_ERROR_NONE)
170                 LOCATIONS_LOGW("system_info_get_platform_bool failed: retval = %d", retval);
171         if (is_gyroscope == false)
172                 return LOCATIONS_ERROR_NOT_SUPPORTED;
173
174         return LOCATIONS_ERROR_NONE;    //LCOV_EXCL_LINE
175 }
176
177 int __set_callback(_location_event_e type, location_manager_h manager, void *callback, void *user_data)
178 {
179         LOCATIONS_NULL_ARG_CHECK(manager);
180         LOCATIONS_NULL_ARG_CHECK(callback);
181         location_manager_s *handle = (location_manager_s *) manager;
182         if (handle != NULL){
183                 handle->user_cb[type] = callback;
184                 handle->user_data[type] = user_data;
185         }
186         else
187                 LOCATIONS_LOGE("Null Handle");
188         LOCATIONS_LOGD("event type : %d", type);
189         return LOCATIONS_ERROR_NONE;
190 }
191
192 int __unset_callback(_location_event_e type, location_manager_h manager)
193 {
194         LOCATIONS_NULL_ARG_CHECK(manager);
195         location_manager_s *handle = (location_manager_s *) manager;
196         if (handle != NULL){
197                 handle->user_cb[type] = NULL;
198                 handle->user_data[type] = NULL;
199         }
200         else
201                 LOCATIONS_LOGE("Null Handle");
202         LOCATIONS_LOGD("event type : %d", type);
203         return LOCATIONS_ERROR_NONE;
204 }
205