refactoring for model-config
[framework/api/system-info.git] / src / system_info_device.c
1 /*
2  * Copyright (c) 2011 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 <unistd.h>
21
22 #include <dlog.h>
23
24 #include <system_info.h>
25 #include <system_info_private.h>
26
27 #ifdef LOG_TAG
28 #undef LOG_TAG
29 #endif
30
31 #define LOG_TAG "CAPI_SYSTEM_INFO"
32
33 #define TETHERING_INFO_FILE_PATH "/etc/config/connectivity/sysinfo-tethering.xml"
34
35 int system_info_get_camera_count(system_info_key_e key, system_info_data_type_e data_type, void **value)
36 {
37         bool camera;
38         int *count = 0;
39
40         count = (int *)value;
41         *count = 0;
42
43         if (system_info_get_platform_bool("tizen.org/feature/camera.back", &camera) == SYSTEM_INFO_ERROR_NONE
44                 && camera == true)
45                 (*count)++;
46         if (system_info_get_platform_bool("tizen.org/feature/camera.front", &camera) == SYSTEM_INFO_ERROR_NONE
47                 && camera == true)
48                 (*count)++;
49
50         return SYSTEM_INFO_ERROR_NONE;
51 }
52
53 int system_info_get_bluetooth_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
54 {
55         return system_info_get_platform_bool("tizen.org/feature/network.bluetooth", (bool *)value);
56 }
57
58 int system_info_get_fmradio_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
59 {
60         return system_info_get_platform_bool("tizen.org/feature/fmradio", (bool *)value);
61 }
62
63 int system_info_get_gps_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
64 {
65         return system_info_get_platform_bool("tizen.org/feature/location.gps", (bool *)value);
66 }
67
68 int system_info_get_wps_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
69 {
70         return system_info_get_platform_bool("tizen.org/feature/location.wps", (bool *)value);
71 }
72
73 int system_info_get_keyboard_type(system_info_key_e key, system_info_data_type_e data_type, void **value)
74 {
75         return system_info_get_platform_string("tizen.org/feature/input.keyboard.layout", (char**)value);
76 }
77
78 int system_info_get_multi_point_touch_count(system_info_key_e key, system_info_data_type_e data_type, void **value)
79 {
80         return system_info_get_platform_int("tizen.org/feature/multi_point_touch.point_count", (int *)value);
81 }
82
83 int system_info_get_nfc_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
84 {
85         return system_info_get_platform_bool("tizen.org/feature/network.nfc", (bool *)value);
86 }
87
88 int system_info_get_wifi_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
89 {
90         return system_info_get_platform_bool("tizen.org/feature/network.wifi", (bool *)value);
91 }
92
93 int system_info_get_wifi_direct_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
94 {
95         return system_info_get_platform_bool("tizen.org/feature/network.wifi.direct", (bool *)value);
96 }
97
98 int system_info_get_usb_host_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
99 {
100         return system_info_get_platform_bool("tizen.org/feature/usb.host", (bool *)value);
101 }
102
103 int system_info_get_usb_accessory_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
104 {
105         return system_info_get_platform_bool("tizen.org/feature/usb.accessory", (bool *)value);
106 }
107
108 int system_info_get_front_camera_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
109 {
110         return system_info_get_platform_bool("tizen.org/feature/camera.front", (bool *)value);
111 }
112
113 int system_info_get_front_camera_flash_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
114 {
115         return system_info_get_platform_bool("tizen.org/feature/camera.front.flash", (bool *)value);
116 }
117
118 int system_info_get_back_camera_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
119 {
120         return system_info_get_platform_bool("tizen.org/feature/camera.back", (bool *)value);
121 }
122
123 int system_info_get_back_camera_flash_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
124 {
125         return system_info_get_platform_bool("tizen.org/feature/camera.back.flash", (bool *)value);
126 }
127
128 int system_info_get_sip_voip_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
129 {
130         return system_info_get_platform_bool("tizen.org/feature/sip.voip", (bool *)value);
131 }
132
133 int system_info_get_microphone_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
134 {
135         return system_info_get_platform_bool("tizen.org/feature/microphone", (bool *)value);
136 }
137
138 int system_info_get_speech_recognition_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
139 {
140         return system_info_get_platform_bool("tizen.org/feature/speech.recognition", (bool *)value);
141 }
142
143 int system_info_get_speech_synthesis_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
144 {
145         return system_info_get_platform_bool("tizen.org/feature/speech.synthesis", (bool *)value);
146 }
147
148 int system_info_get_barometer_sensor_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
149 {
150         return system_info_get_platform_bool("tizen.org/feature/sensor.barometer", (bool *)value);
151 }
152
153 int system_info_get_manufacturer(system_info_key_e key, system_info_data_type_e data_type, void **value)
154 {
155         char *manufacturer = NULL;
156
157         manufacturer = strdup("samsung");
158         if (manufacturer == NULL) {
159                 LOGE("OUT_OF_MEMORY(0x%08x)", SYSTEM_INFO_ERROR_OUT_OF_MEMORY);
160                 return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
161 }
162
163         *value = manufacturer;
164
165         return SYSTEM_INFO_ERROR_NONE;
166 }
167
168 int system_info_get_tethering_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
169 {
170         bool *supported;
171         char *string = NULL;
172         char *model = "default";
173
174         supported = (bool *)value;
175
176         if (access(TETHERING_INFO_FILE_PATH, R_OK)) {
177                 *supported = false;
178                 return SYSTEM_INFO_ERROR_NONE;
179         }
180
181         if (system_info_get_value_from_xml(TETHERING_INFO_FILE_PATH, model, "tethering-support", &string)) {
182                 LOGE("cannot get tethering-support info from %s!!!", TETHERING_INFO_FILE_PATH);
183                 return SYSTEM_INFO_ERROR_IO_ERROR;
184         }
185
186         if (!strcmp(string, "true") || !strcmp(string, "TRUE"))
187                 *supported = true;
188         else
189                 *supported = false;
190
191         free(string);
192
193         return SYSTEM_INFO_ERROR_NONE;
194 }
195
196 int system_info_get_nfc_reserved_push_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
197 {
198         return system_info_get_platform_bool("tizen.org/feature/network.nfc.reserved_push", (bool *)value);
199 }