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>
31 #define APP2EXT_SD_PLUGIN_PATH LIBPREFIX "/libapp2sd.so"
33 app2ext_handle *app2ext_init(int storage_type)
35 /*Validate the function parameter recieved */
36 if (storage_type < APP2EXT_INTERNAL_MEM ||
37 storage_type > APP2EXT_CLOUD) {
38 app2ext_print("App2Ext Error : Invalid function arguments\n");
41 if (storage_type != APP2EXT_SD_CARD ) {
42 app2ext_print("App2Ext Error : Storage type currently not supported\n");
46 /* allocate memory for app2ext handle*/
47 app2ext_handle *handle = (app2ext_handle *)calloc(1, sizeof(app2ext_handle));
49 app2ext_print("App2Ext Error : Memory allocation failure\n");
52 void *dl_handle = NULL;
53 int (*dl_on_load)(app2ext_interface *)=NULL;
56 handle->type = APP2EXT_SD_CARD;
57 dl_handle = dlopen(APP2EXT_SD_PLUGIN_PATH, RTLD_LAZY|RTLD_GLOBAL);
58 if (NULL == dl_handle)
60 app2ext_print("App2Ext Error : dlopen(%s) failed.\n", APP2EXT_SD_PLUGIN_PATH);
64 handle->plugin_handle = dl_handle;
65 dl_on_load = dlsym(dl_handle, "app2ext_on_load");
66 if (NULL == dl_on_load)
68 app2ext_print("App2Ext Error : Cannot find app2ext_on_load symbol in %s.", APP2EXT_SD_PLUGIN_PATH);
74 /*Initialize the SD plugin*/
75 if(!dl_on_load(&(handle->interface)))
77 app2ext_print("App2Ext Error : [%s] app2ext_on_load() failed.", APP2EXT_SD_PLUGIN_PATH);
83 app2ext_print("App2Ext: %s plugin loaded\n", APP2EXT_SD_PLUGIN_PATH);
88 int app2ext_deinit(app2ext_handle *handle)
90 /*Validate the function parameter recieved */
91 if (handle == NULL || handle->plugin_handle == NULL){
92 app2ext_print("App2Ext Error : Invalid function arguments\n");
93 return APP2EXT_ERROR_INVALID_ARGUMENTS;
96 /* Close the plugin handle*/
97 dlclose(handle->plugin_handle);
99 /* Free allocated memory during installtion*/
101 return APP2EXT_SUCCESS;
104 int app2ext_get_app_location(const char *appname)
106 /*Validate the function parameter received */
107 if (appname == NULL) {
108 app2ext_print("invalid func parameters\n");
109 return APP2EXT_ERROR_INVALID_ARGUMENTS;
112 char app_mmc_path[FILENAME_MAX] = { 0, };
113 char app_dir_path[FILENAME_MAX] = { 0, };
114 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
115 snprintf(app_dir_path, FILENAME_MAX,
116 "%s%s", APP_INSTALLATION_PATH, appname);
117 snprintf(app_mmc_path, FILENAME_MAX,
118 "%s%s", APP2SD_PATH, appname);
119 snprintf(app_mmc_internal_path, FILENAME_MAX,
120 "%s%s/.mmc", APP_INSTALLATION_PATH, appname);
123 /*check whether application is in external memory or not */
124 fp = fopen(app_mmc_path, "r");
127 (" app path in external memory not accesible\n");
131 return APP2EXT_SD_CARD;
134 /*check whether application is in internal or not */
135 fp = fopen(app_dir_path, "r");
138 (" app path in internal memory not accesible\n");
139 return APP2EXT_NOT_INSTALLED;
142 /*check whether the application is installed in SD card
143 but SD card is not present*/
144 fp = fopen(app_mmc_internal_path, "r");
146 return APP2EXT_INTERNAL_MEM;
149 return APP2EXT_ERROR_MMC_STATUS;
154 int app2ext_enable_external_pkg(const char *pkgid)
156 /*Validate the function parameter received */
158 app2ext_print("invalid func parameters\n");
162 app2ext_handle *app2_handle = NULL;
163 char app_mmc_path[FILENAME_MAX] = { 0, };
164 snprintf(app_mmc_path, FILENAME_MAX, "%s%s", APP2SD_PATH, pkgid);
166 /*check whether application is in external memory or not */
167 fp = fopen(app_mmc_path, "r");
172 app2_handle = app2ext_init(APP2EXT_SD_CARD);
173 if (app2_handle == NULL) {
174 app2ext_print("app2_handle : app2ext init failed\n");
178 app2_handle->interface.enable(pkgid);
179 app2ext_deinit(app2_handle);
184 int app2ext_disable_external_pkg(const char *pkgid)
186 /*Validate the function parameter received */
188 app2ext_print("invalid func parameters\n");
192 app2ext_handle *app2_handle = NULL;
193 char app_mmc_path[FILENAME_MAX] = { 0, };
194 snprintf(app_mmc_path, FILENAME_MAX, "%s%s", APP2SD_PATH, pkgid);
196 /*check whether application is in external memory or not */
197 fp = fopen(app_mmc_path, "r");
202 app2_handle = app2ext_init(APP2EXT_SD_CARD);
203 if (app2_handle == NULL) {
204 app2ext_print("app2_handle : app2ext init failed\n");
208 app2_handle->interface.disable(pkgid);
209 app2ext_deinit(app2_handle);