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 #ifndef __APP2EXT_INTERFACE_H__
23 #define __APP2EXT_INTERFACE_H__
26 * @file app2ext_interface.h
28 * @brief This file declares API of app2ext library
31 * @addtogroup APPLICATION_FRAMEWORK
37 * @section Header to use them:
39 * #include <app2ext_interface.h>
49 #define API __attribute__ ((visibility("default")))
52 #include <dlog/dlog.h>
58 #define LOG_TAG "APP2EXT"
61 #define app2ext_print(fmt, arg...) LOGD(fmt,##arg)
63 #define app2ext_print(FMT, ARG...) SLOGD(FMT,##ARG);
66 #define APP2EXT_SUCCESS 0
67 #define MMC_PATH "/opt/storage/sdcard"
68 #define APP2SD_PATH MMC_PATH"/app2sd/"
69 #define APP_INSTALLATION_PATH "/opt/usr/apps/"
72 * Enum for application installation location
74 typedef enum app2ext_install_location_t {
75 APP2EXT_INTERNAL_MEM = 0,
80 } app2ext_install_location;
83 * Enum for installation/upgrade status[success/failure]
85 typedef enum app2ext_status_t {
86 APP2EXT_STATUS_FAILED = 1,
87 APP2EXT_STATUS_SUCCESS
91 * Enum for directory type
93 typedef enum app2ext_dir_type_t {
99 * Enum for move command
100 * @see app2sd_move_installed_app()
102 typedef enum app2ext_move_type_t {
103 APP2EXT_MOVE_TO_EXT = 1,
104 APP2EXT_MOVE_TO_PHONE
108 * Enum for error codes
110 typedef enum app2ext_error_t {
111 APP2EXT_ERROR_INVALID_ARGUMENTS = 2,
113 APP2EXT_ERROR_PRE_UNINSTALL,
114 APP2EXT_ERROR_MMC_STATUS,
115 APP2EXT_ERROR_DB_INITIALIZE,
116 APP2EXT_ERROR_SQLITE_REGISTRY,
117 APP2EXT_ERROR_PASSWD_GENERATION,
118 APP2EXT_ERROR_MMC_INFORMATION,
119 APP2EXT_ERROR_MMC_INSUFFICIENT_MEMORY,
120 APP2EXT_ERROR_DELETE_DIRECTORY,
121 APP2EXT_ERROR_CREATE_SYMLINK,
122 APP2EXT_ERROR_CREATE_DIRECTORY,
123 APP2EXT_ERROR_DELETE_LINK_FILE,
124 APP2EXT_ERROR_PKG_EXISTS,
125 APP2EXT_ERROR_ACCESS_FILE,
126 APP2EXT_ERROR_OPEN_DIR,
127 APP2EXT_ERROR_ALREADY_FILE_PRESENT,
128 APP2EXT_ERROR_FILE_ABSENT,
129 APP2EXT_ERROR_STRCMP_FAILED,
130 APP2EXT_ERROR_INVALID_PACKAGE,
131 APP2EXT_ERROR_CREATE_DIR_ENTRY,
132 APP2EXT_ERROR_PASSWORD_GENERATION,
133 APP2EXT_ERROR_COPY_DIRECTORY,
134 APP2EXT_ERROR_INVALID_CASE,
135 APP2EXT_ERROR_SYMLINK_ALREADY_EXISTS,
136 APP2EXT_ERROR_APPEND_HASH_TO_FILE,
137 APP2EXT_ERROR_CREATE_DEVICE,
138 APP2EXT_ERROR_DO_LOSETUP,
139 APP2EXT_ERROR_CREATE_FS,
140 APP2EXT_ERROR_MOUNT_PATH,
141 APP2EXT_ERROR_CLEANUP,
143 APP2EXT_ERROR_REMOUNT,
144 APP2EXT_ERROR_PIPE_CREATION,
145 APP2EXT_ERROR_LOOPBACK_DEVICE_UNAVAILABLE,
146 APP2EXT_ERROR_VCONF_REGISTRY,
147 APP2EXT_ERROR_FIND_ASSOCIATED_DEVICE_NODE,
148 APP2EXT_ERROR_UNMOUNT,
149 APP2EXT_ERROR_DELETE_LOOPBACK_DEVICE,
150 APP2EXT_ERROR_DETACH_LOOPBACK_DEVICE,
151 APP2EXT_ERROR_ALREADY_MOUNTED,
152 APP2EXT_ERROR_PLUGIN_INIT_FAILED,
153 APP2EXT_ERROR_PLUGIN_DEINIT_FAILED
157 * @brief :This function type is for a function that is implemented by plugin
158 * and called before application is to be installed.
160 * @param[in] appname application package name which is to be installed
161 * @param[in] dir_list directory structure of the application
162 * This should be polulated by the package manager
163 * before calling pre_install and should be freed after
164 * pre_install returns.
165 * Each node of dir_list is of type app2ext_dir_details
166 * which has members Name(dirname) and Type (RO/RW)
167 * For eg for rpm the dir_list should be populated with
168 * nodes like : (lib, APP2EXT_DIR_RO), (res, APP2EXT_DIR_RO),
169 (bin, APP2EXT_DIR_RO), (data, APP2EXT_DIR_RW)
170 * @param[in] size Size of the application
171 * @return 0 if success, error code(>0) if fail
173 typedef int (*app2ext_pre_install)(const char *appname, GList* dir_list, int size);
176 * @brief :This function type is for a function that is implemented by plugin
177 * and called after application installation.
179 * @param[in] appname application package name which is to be installed
180 * @param[in] install_status Installation status (Success/Failure)
181 * [ Enum :APP2EXT_STATUS_SUCCESS,
182 * APP2EXT_STATUS_FAILED]
183 * @return 0 if success, error code(>0) if fail
185 typedef int (*app2ext_post_install)(const char *appname, app2ext_status install_status);
188 * @brief :This function type is for a function that is implemented by plugin
189 * and called before application upgrade.
191 * @param[in] appname application package name which is to be upgraded
192 * @param[in] dir_list directory structure of the application
193 * This should be polulated by the package manager
194 * before calling pre_upgrade and should be freed after
195 * pre_upgrade returns.
196 * Each node of dir_list is of type app2ext_dir_details
197 * which has members Name(dirname) and Type (RO/RW)
198 * For eg for rpm the dir_list should be populated with
199 * nodes like : (lib, APP2EXT_DIR_RO), (res, APP2EXT_DIR_RO),
200 (bin, APP2EXT_DIR_RO), (data, APP2EXT_DIR_RW)
201 * @param[in] size Size of the application
202 * @return 0 if success, error code(>0) if fail
204 typedef int (*app2ext_pre_upgrade)(const char *appname, GList* dir_list, int size);
207 * @brief :This function type is for a function that is implemented by plugin
208 * and called before application upgradation.
210 * @param[in] appname application package name which is to be upgraded
211 * @param[in] upgrade_status Upgrade status (Success/Failure)
212 * [ Enum :APP2EXT_STATUS_SUCCESS,
213 * APP2EXT_STATUS_FAILED]
214 * @return 0 if success, error code(>0) if fail
216 typedef int (*app2ext_post_upgrade)(const char *appname, app2ext_status upgrade_status);
219 * @brief :This function type is for a function that is implemented by plugin
220 * and called before application uninstallation.
222 * @param[in] appname application package name which is to be uninstalled
223 * @return 0 if success, error code(>0) if fail
225 typedef int (*app2ext_pre_uninstall)(const char *appname);
228 * @brief :This function type is for a function that is implemented by plugin
229 * and called after application uninstallation.
231 * @param[in] appname application package name which is to be uninstalled
232 * @return 0 if success, error code(>0) if fail
234 typedef int (*app2ext_post_uninstall)(const char *appname);
237 * @brief :This function type is for a function that is implemented by plugin
238 * and called when application is to be moved from extrenal memory
239 *to internal memory or vice versa.
241 * @param[in] appname application package name which is to be moved
242 * @param[in] dir_list directory structure of the application
243 * This should be polulated by the package manager
244 * before calling move and should be freed after
246 * Each node of dir_list is of type app2ext_dir_details
247 * which has members Name(dirname) and Type (RO/RW)
248 * For eg for rpm the dir_list should be populated with
249 * nodes like : (lib, APP2EXT_DIR_RO), (res, APP2EXT_DIR_RO),
250 (bin, APP2EXT_DIR_RO), (data, APP2EXT_DIR_RW)
251 * @param[in] move_type move type
252 * [Enum: APP2EXT_MOVE_TO_EXT, APP2EXT_MOVE_TO_PHONE]
253 * @return 0 if success, error code(>0) if fail
255 typedef int (*app2ext_move)(const char *appname, GList* dir_list, app2ext_move_type move_type);
258 * @brief :This function type is for a function that is implemented by plugin
259 * and called to enable application before application launch.
261 * @param[in] appname application package name which is to be enabled
262 * @return 0 if success, error code(>0) if fail
264 typedef int (*app2ext_enable)(const char *appname);
267 * @brief :This function type is for a function that is implemented by plugin
268 * and called to disable application before application exit.
270 * @param[in] appname application package name which is to be disabled
271 * @return 0 if success, error code(>0) if fail
273 typedef int (*app2ext_disable)(const char *appname);
276 * This structure defines the app2ext interfaces. Plugins have to implement these functions
278 typedef struct app2ext_interface_t{
279 app2ext_pre_install pre_install;
280 app2ext_post_install post_install;
281 app2ext_pre_upgrade pre_upgrade;
282 app2ext_post_upgrade post_upgrade;
283 app2ext_pre_uninstall pre_uninstall;
284 app2ext_post_uninstall post_uninstall;
286 app2ext_enable enable;
287 app2ext_disable disable;
291 * This structure defines app2ext handle .Each storage type maps to a different plugin
292 * type : storage type
293 * plugin_handle : plugin handle
296 app2ext_install_location type;
298 app2ext_interface interface;
302 * This structure defines directory details
303 * name : directory name
304 * type : permission (rw/ro)
308 app2ext_dir_type type;
309 } app2ext_dir_details;
312 * @brief : This API initializes the appropriate plugin based on storage type.
313 * It should be called before installation/uninstallation/upgrade
314 * @param[in] storage_type Location where package should be installed
315 * [Ex: SD card, MicroUSB, Cloud]
316 * @return app2ext_handle pointer if success, NULL if fail
319 #include <app2ext_interface.h>
320 app2ext_handle *handle = NULL;
321 GLIst *dir_list = NULL;
322 handle = app2ext_init(APP2EXT_SD_CARD); //Initializes SD card plug-in
325 printf("\n SUCCESS");
326 // Perform package install/uninstall/upgrade/move here
327 // Packge install example
328 // Package manager should polulate dir_list with directory structure information of the package
329 ret = handle->interface.pre_install("com.samsung.calculator", dir_list, 20);
331 printf("\n TC : pre app install API fail. Reason %s", error_list[ret]);
335 // Package manager installs the package
337 ret = handle->interface.post_install("com.samsung.calculator", APP2EXT_STATUS_SUCCESS);
339 printf("\n TC : post app install API fail Reason %s", error_list[ret]);
343 // Package manager should free dir_list
346 printf("\n FAILURE");
349 API app2ext_handle *app2ext_init(int storage_type);
352 * @brief : This API deinitializes the plugin
353 * This should be called when use of the plugin is completed
354 * @param[in] handle pointer to app2ext_handle which is to be deinitialized
355 * @pre Initialization is done for the storage handle
356 * @return 0 if success, error code(>0) if fail
359 #include <app2ext_interface.h>
360 app2ext_handle *handle = NULL;
361 handle = app2ext_init(APP2EXT_SD_CARD); //Initializes SD card plug-in
363 ret = app2ext_deinit(handle); // De-initializes the SD plugin
366 printf("\n SUCCESS");
369 printf("\n FAILURE");
372 API int app2ext_deinit(app2ext_handle *handle);
375 * @brief : This API returns the application location
376 * by refering to package manager DB
377 * This should be called to know location of an application
378 * @param[in] appname name of the application
379 * @return APP2EXT_SD_CARD if app is in SD card,
380 * APP2EXT_INTERNAL_MEM if app is in internal memory
381 * error code(>0) if fail
382 *@remarks see app2ext_install_location for more details
384 #include <app2ext_interface.h>
387 ret = app2ext_get_app_location("com.samsung.calculator");
388 if (ret == APP2EXT_SD_CARD) {
389 printf("\n app is in sd card ");
390 } else if (ret == APP2EXT_INTERNAL_MEM) {
391 printf("\n app is in internal memory ");
393 printf("\napp is not installed");
397 API int app2ext_get_app_location(const char *appname);