2 * Copyright (c) 2011 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.
22 #include <sys/types.h>
27 #include <appcore-common.h>
28 #include <appcore-efl.h>
32 #include <Elementary.h>
34 #include <app_private.h>
35 #include <app_service_private.h>
41 #define LOG_TAG "CAPI_APPFW_APPLICATION"
43 static const char *INSTALLED_PATH = "/opt/usr/apps";
44 static const char *RO_INSTALLED_PATH = "/usr/apps";
45 static const char *RES_DIRECTORY_NAME = "res";
46 static const char *DATA_DIRECTORY_NAME = "data";
48 static char * app_get_root_directory(char *buffer, int size)
51 char root_directory[TIZEN_PATH_MAX] = {0, };
52 char bin_directory[TIZEN_PATH_MAX] = {0, };
53 ail_appinfo_h ail_app_info;
56 if (app_get_id(&appid) != APP_ERROR_NONE)
58 app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the appid");
62 if (ail_get_appinfo(appid, &ail_app_info) != AIL_ERROR_OK)
64 app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the appinfo");
69 if (ail_appinfo_get_str(ail_app_info, AIL_PROP_X_SLP_PKGID_STR, &pkgid) != AIL_ERROR_OK)
71 app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the pkgid");
73 ail_destroy_appinfo(ail_app_info);
80 appid = strdup(pkgid);
83 ail_destroy_appinfo(ail_app_info);
85 snprintf(root_directory, sizeof(root_directory), "%s/%s", INSTALLED_PATH, appid);
86 snprintf(bin_directory, sizeof(bin_directory), "%s/bin", root_directory);
88 if (access(bin_directory, R_OK) != 0) {
89 snprintf(root_directory, sizeof(root_directory), "%s/%s", RO_INSTALLED_PATH, appid);
94 if (size < strlen(root_directory)+1)
96 app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "the buffer is not big enough");
100 snprintf(buffer, size, "%s", root_directory);
105 static char* app_get_resource_directory(char *buffer, int size)
107 char root_directory[TIZEN_PATH_MAX] = {0, };
108 char resource_directory[TIZEN_PATH_MAX] = {0, };
110 if (app_get_root_directory(root_directory, sizeof(root_directory)) == NULL)
112 app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the root directory of the application");
116 snprintf(resource_directory, sizeof(resource_directory), "%s/%s", root_directory, RES_DIRECTORY_NAME);
118 if (size < strlen(resource_directory) +1)
120 app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "the buffer is not big enough");
124 snprintf(buffer, size, "%s", resource_directory);
129 char* app_get_data_directory(char *buffer, int size)
131 static char data_directory[TIZEN_PATH_MAX] = {0, };
132 static int data_directory_length = 0;
133 ail_appinfo_h ail_app_info;
136 if (data_directory[0] == '\0')
138 char *root_directory = NULL;
141 root_directory = calloc(1, TIZEN_PATH_MAX);
143 if (root_directory == NULL)
145 app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
149 if (app_get_id(&appid) != APP_ERROR_NONE)
151 app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the package");
152 free(root_directory);
156 if (ail_get_appinfo(appid, &ail_app_info) != AIL_ERROR_OK)
158 app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the package");
159 free(root_directory);
164 if (ail_appinfo_get_str(ail_app_info, AIL_PROP_X_SLP_PKGID_STR, &pkgid) != AIL_ERROR_OK)
166 app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the package");
167 free(root_directory);
169 ail_destroy_appinfo(ail_app_info);
176 appid = strdup(pkgid);
179 ail_destroy_appinfo(ail_app_info);
181 snprintf(root_directory, TIZEN_PATH_MAX, "%s/%s", INSTALLED_PATH, appid);
185 snprintf(data_directory, sizeof(data_directory), "%s/%s", root_directory, DATA_DIRECTORY_NAME);
187 data_directory_length = strlen(data_directory);
189 free(root_directory);
192 if (size < data_directory_length+1)
194 app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "the buffer is not big enough");
198 snprintf(buffer, size, "%s", data_directory);
203 char* app_get_resource(const char *resource, char *buffer, int size)
205 static char resource_directory[TIZEN_PATH_MAX] = {0, };
206 static int resource_directory_length = 0;
208 int resource_path_length = 0;
210 if (resource == NULL)
212 app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
216 if (buffer == NULL || size <= 0)
218 app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
222 if (resource_directory[0] == '\0')
224 if (app_get_resource_directory(resource_directory, sizeof(resource_directory)) == NULL)
226 app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the path to the resource directory");
230 resource_directory_length = strlen(resource_directory);
233 resource_path_length = resource_directory_length + strlen("/") + strlen(resource);
235 if (size < resource_path_length+1)
237 app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "the buffer is not big enough");
241 snprintf(buffer, size, "%s/%s", resource_directory, resource);
247 void app_set_reclaiming_system_cache_on_pause(bool enable)
249 appcore_set_system_resource_reclaiming(enable);
252 void* app_get_preinitizlized_window(void)
254 Evas_Object* win = (Evas_Object*)aul_get_preinit_window();