1 /* Copyright (c) 2010-2014 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.
19 #include <system_info.h> /* system_info_get_platform_bool */
20 #include <maps_util.h> /* log */
21 #include <maps_error.h>
22 #include <maps_condition.h>
23 #if (TIZEN_VER < VERSION(3, 0, 0))
24 #include <privacy_checker_client.h>
25 #include <sys/smack.h>
27 #define MAPSERVICE_PRIVILEGE "privilege::tizen::mapservice"
28 #define MAPSERVICE_PERMISSION "rw"
30 #define MAPS_FEATURE "http://tizen.org/feature/maps"
31 #define INTERNET_FEATURE "http://tizen.org/feature/network.internet"
34 void *_maps_view_get_maps_service_ptr(maps_view_h view);
37 #if (TIZEN_VER < VERSION(3, 0, 0))
38 static int __maps_condition_check_privilege(const char *privilege_name, const char *permission)
40 if (!privilege_name || !permission)
41 return MAPS_ERROR_INVALID_PARAMETER;
46 if (smack_new_label_from_self(&label) == -1) {
47 MAPS_LOGE("smack_new_label_from_self error");
48 return MAPS_ERROR_INVALID_OPERATION;
50 ret = smack_have_access(label, privilege_name, permission);
52 ret = MAPS_ERROR_NONE;
53 } else if (ret == 0) {
54 ret = MAPS_ERROR_PERMISSION_DENIED;
56 ret = MAPS_ERROR_INVALID_OPERATION;
63 bool maps_condition_check_privilege(void)
65 static bool is_permitted = true;
66 static bool is_read = false;
69 #if (TIZEN_VER < VERSION(3, 0, 0))
70 int ret = __maps_condition_check_privilege(MAPSERVICE_PRIVILEGE, MAPSERVICE_PERMISSION);
71 is_permitted = (ret == MAPS_ERROR_NONE);
73 /* to check for Tizen 3.x privilege */
74 is_permitted = (access(MAPS_PLUGINS_PATH_PREFIX, F_OK) != 0) || /* not exist */
75 (access(MAPS_PLUGINS_PATH_PREFIX, R_OK) == 0); /* readable */
78 MAPS_LOGD("mapservice privilege is%sconsented", (is_permitted ? " " : " not "));
83 bool maps_condition_check_maps_feature(void)
85 static bool is_supported = false;
86 static bool is_read = false;
89 system_info_get_platform_bool(MAPS_FEATURE, &is_supported);
90 MAPS_LOGD("maps feature is%ssupported", (is_supported ? " " : " not "));
96 bool maps_condition_check_internet_feature(void)
98 static bool is_supported = false;
99 static bool is_read = false;
102 system_info_get_platform_bool(INTERNET_FEATURE, &is_supported);
103 MAPS_LOGD("internet feature is%ssupported", (is_supported ? " " : " not "));
109 bool maps_condition_check_service_supported(maps_service_h maps, maps_service_e service)
113 bool supported = false;
114 if (maps_service_provider_is_service_supported(maps, service, &supported) != MAPS_ERROR_NONE)
119 bool maps_condition_check_data_supported(maps_service_h maps, maps_service_data_e data)
123 bool supported = false;
124 if (maps_service_provider_is_data_supported(maps, data, &supported) != MAPS_ERROR_NONE)
129 bool maps_condition_check_view_service_supported(maps_view_h view, maps_service_e service)
133 maps_service_h maps = _maps_view_get_maps_service_ptr(view);
134 bool supported = false;
135 if (maps_service_provider_is_service_supported(maps, service, &supported) != MAPS_ERROR_NONE)
140 bool maps_condition_check_view_data_supported(maps_view_h view, maps_service_data_e data)
144 maps_service_h maps = _maps_view_get_maps_service_ptr(view);
145 bool supported = false;
146 if (maps_service_provider_is_data_supported(maps, data, &supported) != MAPS_ERROR_NONE)