4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jyotsna Dhumale <jyotsna.a@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 #include <app2ext_interface.h>
24 #include <sys/types.h>
32 #define APP2EXT_SD_PLUGIN_PATH LIBPREFIX "/libapp2sd.so"
34 app2ext_handle *app2ext_init(int storage_type)
36 /*Validate the function parameter recieved */
37 if (storage_type < APP2EXT_INTERNAL_MEM ||
38 storage_type > APP2EXT_CLOUD) {
39 app2ext_print("App2Ext Error : Invalid function arguments\n");
42 if (storage_type != APP2EXT_SD_CARD ) {
43 app2ext_print("App2Ext Error : Storage type currently not supported\n");
47 /* allocate memory for app2ext handle*/
48 app2ext_handle *handle = (app2ext_handle *)calloc(1, sizeof(app2ext_handle));
50 app2ext_print("App2Ext Error : Memory allocation failure\n");
53 void *dl_handle = NULL;
54 int (*dl_on_load)(app2ext_interface *)=NULL;
57 handle->type = APP2EXT_SD_CARD;
58 dl_handle = dlopen(APP2EXT_SD_PLUGIN_PATH, RTLD_LAZY|RTLD_GLOBAL);
59 if (NULL == dl_handle)
61 app2ext_print("App2Ext Error : dlopen(%s) failed.\n", APP2EXT_SD_PLUGIN_PATH);
65 handle->plugin_handle = dl_handle;
66 dl_on_load = dlsym(dl_handle, "app2ext_on_load");
67 if (NULL == dl_on_load)
69 app2ext_print("App2Ext Error : Cannot find app2ext_on_load symbol in %s.", APP2EXT_SD_PLUGIN_PATH);
75 /*Initialize the SD plugin*/
76 if(!dl_on_load(&(handle->interface)))
78 app2ext_print("App2Ext Error : [%s] app2ext_on_load() failed.", APP2EXT_SD_PLUGIN_PATH);
84 app2ext_print("App2Ext: %s plugin loaded\n", APP2EXT_SD_PLUGIN_PATH);
89 int app2ext_deinit(app2ext_handle *handle)
91 /*Validate the function parameter recieved */
92 if (handle == NULL || handle->plugin_handle == NULL){
93 app2ext_print("App2Ext Error : Invalid function arguments\n");
94 return APP2EXT_ERROR_INVALID_ARGUMENTS;
97 /* Close the plugin handle*/
98 dlclose(handle->plugin_handle);
100 /* Free allocated memory during installtion*/
102 return APP2EXT_SUCCESS;
105 int app2ext_get_app_location(const char *appname)
107 /*Validate the function parameter received */
108 if (appname == NULL) {
109 app2ext_print("invalid func parameters\n");
110 return APP2EXT_ERROR_INVALID_ARGUMENTS;
113 char app_mmc_path[FILENAME_MAX] = { 0, };
114 char app_dir_path[FILENAME_MAX] = { 0, };
115 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
116 snprintf(app_dir_path, FILENAME_MAX,
117 "%s%s", APP_INSTALLATION_PATH, appname);
118 snprintf(app_mmc_path, FILENAME_MAX,
119 "%s%s", APP2SD_PATH, appname);
120 snprintf(app_mmc_internal_path, FILENAME_MAX,
121 "%s%s/.mmc", APP_INSTALLATION_PATH, appname);
124 /*check whether application is in external memory or not */
125 fp = fopen(app_mmc_path, "r");
129 return APP2EXT_SD_CARD;
132 /*check whether application is in internal or not */
133 fp = fopen(app_dir_path, "r");
135 return APP2EXT_NOT_INSTALLED;
138 /*check whether the application is installed in SD card
139 but SD card is not present*/
140 fp = fopen(app_mmc_internal_path, "r");
142 return APP2EXT_INTERNAL_MEM;
145 return APP2EXT_ERROR_MMC_STATUS;
150 int app2ext_enable_external_pkg(const char *pkgid)
152 /*Validate the function parameter received */
154 app2ext_print("invalid func parameters\n");
158 app2ext_handle *app2_handle = NULL;
159 char app_mmc_path[FILENAME_MAX] = { 0, };
160 snprintf(app_mmc_path, FILENAME_MAX, "%s%s", APP2SD_PATH, pkgid);
162 /*check whether application is in external memory or not */
163 fp = fopen(app_mmc_path, "r");
168 app2_handle = app2ext_init(APP2EXT_SD_CARD);
169 if (app2_handle == NULL) {
170 app2ext_print("app2_handle : app2ext init failed\n");
174 app2_handle->interface.enable(pkgid);
175 app2ext_deinit(app2_handle);
176 app2ext_print("App2Ext enable_external_pkg [%s]\n", pkgid);
181 int app2ext_disable_external_pkg(const char *pkgid)
183 /*Validate the function parameter received */
185 app2ext_print("invalid func parameters\n");
189 app2ext_handle *app2_handle = NULL;
190 char app_mmc_path[FILENAME_MAX] = { 0, };
191 snprintf(app_mmc_path, FILENAME_MAX, "%s%s", APP2SD_PATH, pkgid);
193 /*check whether application is in external memory or not */
194 fp = fopen(app_mmc_path, "r");
199 app2_handle = app2ext_init(APP2EXT_SD_CARD);
200 if (app2_handle == NULL) {
201 app2ext_print("app2_handle : app2ext init failed\n");
205 app2_handle->interface.disable(pkgid);
206 app2ext_deinit(app2_handle);
207 app2ext_print("App2Ext disable_external_pkg [%s]\n", pkgid);
212 int app2ext_enable_external_dir(void)
216 char buf[FILENAME_MAX] = { 0, };
217 struct dirent entry, *result = NULL;
219 dir = opendir(APP2SD_PATH);
221 if (strerror_r(errno, buf, sizeof(buf)) == 0)
222 app2ext_print("App2Ext Error :Failed to access the because %s", buf);
226 for (ret = readdir_r(dir, &entry, &result); ret == 0 && result != NULL; ret = readdir_r(dir, &entry, &result)) {
227 ret = app2ext_enable_external_pkg(entry.d_name);
229 app2ext_print("App2Ext Error : fail enable pkg[%s]\n", entry.d_name);
236 int app2ext_disable_external_dir(void)
240 char buf[FILENAME_MAX] = { 0, };
241 struct dirent entry, *result = NULL;
243 dir = opendir(APP2SD_PATH);
245 if (strerror_r(errno, buf, sizeof(buf)) == 0)
246 app2ext_print("App2Ext Error :Failed to access the because %s", buf);
250 for (ret = readdir_r(dir, &entry, &result); ret == 0 && result != NULL; ret = readdir_r(dir, &entry, &result)) {
251 ret = app2ext_disable_external_pkg(entry.d_name);
253 app2ext_print("App2Ext Error : fail disable pkg[%s]\n", entry.d_name);
260 int app2ext_force_clean_pkg(const char *pkgid)
262 /*Validate the function parameter received */
264 app2ext_print("invalid func parameters\n");
269 app2ext_handle *app2_handle = NULL;
270 char app_mmc_path[FILENAME_MAX] = { 0, };
271 snprintf(app_mmc_path, FILENAME_MAX, "%s%s/.mmc", APP_INSTALLATION_PATH, pkgid);
273 fp = fopen(app_mmc_path, "r");
280 app2_handle = app2ext_init(APP2EXT_SD_CARD);
281 if (app2_handle == NULL) {
282 app2ext_print("app2_handle : app2ext init failed\n");
286 app2_handle->interface.force_clean(pkgid);
287 app2ext_deinit(app2_handle);
288 app2ext_print("App2Ext force_clean_pkg [%s]\n", pkgid);