add enalbe/disable function for entire packages. 79/74479/13 accepted/tizen/common/20160617.121122 accepted/tizen/ivi/20160617.082326 accepted/tizen/mobile/20160617.081821 accepted/tizen/tv/20160617.081838 accepted/tizen/wearable/20160617.081901 submit/tizen/20160616.065340
authorjongmyeongko <jongmyeong.ko@samsung.com>
Tue, 14 Jun 2016 10:05:03 +0000 (19:05 +0900)
committerjongmyeongko <jongmyeong.ko@samsung.com>
Wed, 15 Jun 2016 07:57:02 +0000 (16:57 +0900)
Change-Id: I8434dc46662ba15380d884eca3f0b0c149355c0f
Signed-off-by: jongmyeongko <jongmyeong.ko@samsung.com>
14 files changed:
common/inc/app2ext_utils.h
common/src/app2ext_utils.c
inc/app2ext_interface.h
plugin/app2sd/inc/app2sd_client_interface.h
plugin/app2sd/inc/app2sd_interface.h
plugin/app2sd/inc/app2sd_internals.h
plugin/app2sd/src/app2sd_client_interface.c
plugin/app2sd/src/app2sd_interface.c
plugin/app2sd/src/app2sd_internals.c
plugin/app2sd/src/app2sd_internals_registry.c
plugin/app2sd/src/app2sd_internals_utils.c
plugin/app2sd/src/app2sd_server.c
src/app2ext_interface.c
test/src/test_app2ext.c

index 8d77aa1..7dd62c7 100644 (file)
@@ -51,6 +51,7 @@ extern "C" {
 #define APP2EXT_SUCCESS 0
 
 #define OWNER_ROOT 0
+#define REGULAR_USER 5000
 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
 #define MMC_PATH tzplatform_mkpath(TZ_SYS_MEDIA, "SDCardA1")
 #define APP2SD_PATH tzplatform_mkpath(TZ_SYS_MEDIA, "SDCardA1/app2sd")
@@ -62,8 +63,11 @@ extern "C" {
 #define DIR_PERMS (S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
 
 int _is_global(uid_t uid);
+
 char *_app2sd_get_encoded_name(const char *pkgid, uid_t uid);
 
+int _app2sd_delete_directory(const char *dirname);
+
 #ifdef __cplusplus
 }
 #endif
index bec4c2c..d8c0845 100644 (file)
@@ -49,3 +49,52 @@ char *_app2sd_get_encoded_name(const char *pkgid, uid_t uid)
 
        return new_name;
 }
+
+int _app2sd_delete_directory(const char *dirname)
+{
+       DIR *dp = NULL;
+       struct dirent ep;
+       struct dirent *er = NULL;
+       char abs_filename[FILENAME_MAX] = { 0, };
+       int ret = 0;
+
+       dp = opendir(dirname);
+       if (dp != NULL) {
+               while (readdir_r(dp, &ep, &er) == 0 && er != NULL) {
+                       struct stat stFileInfo;
+
+                       snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
+                               ep.d_name);
+
+                       if (lstat(abs_filename, &stFileInfo) < 0) {
+                               perror(abs_filename);
+                               (void)closedir(dp);
+                               return -1;
+                       }
+
+                       if (S_ISDIR(stFileInfo.st_mode)) {
+                               if (strcmp(ep.d_name, ".")
+                                   && strcmp(ep.d_name, "..")) {
+                                       ret = _app2sd_delete_directory(abs_filename);
+                                       if (ret < 0) {
+                                               (void)closedir(dp);
+                                               return -1;
+                                       }
+                               }
+                       } else {
+                               ret = remove(abs_filename);
+                               if (ret < 0) {
+                                       (void)closedir(dp);
+                                       return -1;
+                               }
+                       }
+               }
+               (void)closedir(dp);
+               ret = remove(dirname);
+               if (ret < 0)
+                       return -1;
+       } else {
+               _W("couldn't open the directory[%s]", dirname);
+       }
+       return 0;
+}
index 1e37c95..3e75fcf 100644 (file)
@@ -130,7 +130,6 @@ typedef enum app2ext_error_t {
        APP2EXT_ERROR_STRCMP_FAILED,
        APP2EXT_ERROR_INVALID_PACKAGE,
        APP2EXT_ERROR_CREATE_DIR_ENTRY,
-       APP2EXT_ERROR_PASSWORD_GENERATION,
        APP2EXT_ERROR_COPY_DIRECTORY,
        APP2EXT_ERROR_INVALID_CASE,
        APP2EXT_ERROR_SYMLINK_ALREADY_EXISTS,
@@ -160,11 +159,11 @@ typedef enum app2ext_error_t {
 } app2ext_error;
 
 /**
- * @brief :This function type is for a function that is implemented by plugin
+ * @brief : This function type is for a function that is implemented by plugin
  * and called before application is to be installed.
  *
- * @param[in]  appname         application package name which is to be installed
- * @param[in]  dir_list        directory structure of the application
+ * @param[in]   appname         application package name which is to be installed
+ * @param[in]   dir_list        directory structure of the application
  *                              This should be polulated by the package manager
  *                              before calling pre_install and should be freed after
  *                              pre_install returns.
@@ -172,9 +171,9 @@ typedef enum app2ext_error_t {
  *                              which has members Name(dirname) and Type (RO/RW)
  *                              For eg for rpm the dir_list should be populated with
  *                              nodes like : (lib, APP2EXT_DIR_RO), (res, APP2EXT_DIR_RO),
                               (bin, APP2EXT_DIR_RO), (data, APP2EXT_DIR_RW)
- * @param[in]  size            Size of the application
- * @return     0 if success,  error code(>0) if fail
*                              (bin, APP2EXT_DIR_RO), (data, APP2EXT_DIR_RW)
+ * @param[in]   size            Size of the application
+ * @return      0 if success, error code(>0) if fail
  */
 typedef int (*app2ext_client_usr_pre_install)(const char *appname, GList* dir_list,
                int size, uid_t uid);
@@ -182,14 +181,14 @@ typedef int (*app2ext_client_pre_install)(const char *appname, GList* dir_list,
                int size);
 
 /**
- * @brief :This function type is for a function that is implemented by plugin
+ * @brief : This function type is for a function that is implemented by plugin
  * and called after application installation.
  *
- * @param[in]  appname         application package name which is to be installed
- * @param[in]  install_status  Installation status (Success/Failure)
- *                             [ Enum :APP2EXT_STATUS_SUCCESS,
- *                                     APP2EXT_STATUS_FAILED]
- * @return     0 if success,  error code(>0) if fail
+ * @param[in]   appname         application package name which is to be installed
+ * @param[in]   install_status  Installation status (Success/Failure)
+ *                              [ Enum :APP2EXT_STATUS_SUCCESS,
+ *                              APP2EXT_STATUS_FAILED]
+ * @return      0 if success, error code(>0) if fail
  */
 typedef int (*app2ext_client_usr_post_install)(const char *appname,
                app2ext_status install_status, uid_t uid);
@@ -197,11 +196,11 @@ typedef int (*app2ext_client_post_install)(const char *appname,
                app2ext_status install_status);
 
 /**
- * @brief :This function type is for a function that is implemented by plugin
+ * @brief : This function type is for a function that is implemented by plugin
  * and called before application upgrade.
  *
- * @param[in]  appname         application package name which is to be upgraded
- * @param[in]  dir_list        directory structure of the application
+ * @param[in]   appname         application package name which is to be upgraded
+ * @param[in]   dir_list        directory structure of the application
  *                              This should be polulated by the package manager
  *                              before calling pre_upgrade and should be freed after
  *                              pre_upgrade returns.
@@ -209,9 +208,9 @@ typedef int (*app2ext_client_post_install)(const char *appname,
  *                              which has members Name(dirname) and Type (RO/RW)
  *                              For eg for rpm the dir_list should be populated with
  *                              nodes like : (lib, APP2EXT_DIR_RO), (res, APP2EXT_DIR_RO),
                               (bin, APP2EXT_DIR_RO), (data, APP2EXT_DIR_RW)
- * @param[in]  size            Size of the application
- * @return     0 if success,  error code(>0) if fail
*                              (bin, APP2EXT_DIR_RO), (data, APP2EXT_DIR_RW)
+ * @param[in]   size            Size of the application
+ * @return      0 if success,  error code(>0) if fail
  */
 typedef int (*app2ext_client_usr_pre_upgrade)(const char *appname, GList* dir_list,
                int size, uid_t uid);
@@ -219,14 +218,14 @@ typedef int (*app2ext_client_pre_upgrade)(const char *appname, GList* dir_list,
                int size);
 
 /**
- * @brief :This function type is for a function that is implemented by plugin
+ * @brief : This function type is for a function that is implemented by plugin
  * and called before application upgradation.
  *
- * @param[in]  appname         application package name which is to be upgraded
- * @param[in]  upgrade_status  Upgrade status (Success/Failure)
- *                             [ Enum :APP2EXT_STATUS_SUCCESS,
- *                                     APP2EXT_STATUS_FAILED]
- * @return     0 if success,  error code(>0) if fail
+ * @param[in]   appname         application package name which is to be upgraded
+ * @param[in]   upgrade_status  Upgrade status (Success/Failure)
+ *                              [ Enum :APP2EXT_STATUS_SUCCESS,
+ *                                      APP2EXT_STATUS_FAILED]
+ * @return      0 if success, error code(>0) if fail
  */
 typedef int (*app2ext_client_usr_post_upgrade)(const char *appname,
                app2ext_status upgrade_status, uid_t uid);
@@ -234,32 +233,32 @@ typedef int (*app2ext_client_post_upgrade)(const char *appname,
                app2ext_status upgrade_status);
 
 /**
- * @brief :This function type is for a function that is implemented by plugin
+ * @brief : This function type is for a function that is implemented by plugin
  * and called before application uninstallation.
  *
- * @param[in]  appname         application package name which is to be uninstalled
- * @return     0 if success,  error code(>0) if fail
+ * @param[in]   appname         application package name which is to be uninstalled
+ * @return      0 if success, error code(>0) if fail
  */
 typedef int (*app2ext_client_usr_pre_uninstall)(const char *appname, uid_t uid);
 typedef int (*app2ext_client_pre_uninstall)(const char *appname);
 
 /**
- * @brief :This function type is for a function that is implemented by plugin
+ * @brief : This function type is for a function that is implemented by plugin
  * and called after application uninstallation.
  *
- * @param[in]  appname         application package name which is to be uninstalled
- * @return     0 if success,  error code(>0) if fail
+ * @param[in]   appname         application package name which is to be uninstalled
+ * @return      0 if success, error code(>0) if fail
  */
 typedef int (*app2ext_client_usr_post_uninstall)(const char *appname, uid_t uid);
 typedef int (*app2ext_client_post_uninstall)(const char *appname);
 
 /**
- * @brief :This function type is for a function that is implemented by plugin
+ * @brief : This function type is for a function that is implemented by plugin
  * and called when application is to be moved from extrenal memory
  *to internal memory or vice versa.
  *
- * @param[in]  appname         application package name which is to be moved
- * @param[in]  dir_list        directory structure of the application
+ * @param[in]   appname         application package name which is to be moved
+ * @param[in]   dir_list        directory structure of the application
  *                              This should be polulated by the package manager
  *                              before calling move and should be freed after
  *                              move returns.
@@ -267,10 +266,10 @@ typedef int (*app2ext_client_post_uninstall)(const char *appname);
  *                              which has members Name(dirname) and Type (RO/RW)
  *                              For eg for rpm the dir_list should be populated with
  *                              nodes like : (lib, APP2EXT_DIR_RO), (res, APP2EXT_DIR_RO),
                               (bin, APP2EXT_DIR_RO), (data, APP2EXT_DIR_RW)
- * @param[in]  move_type       move type
- *                             [Enum: APP2EXT_MOVE_TO_EXT, APP2EXT_MOVE_TO_PHONE]
- * @return     0 if success,  error code(>0) if fail
*                              (bin, APP2EXT_DIR_RO), (data, APP2EXT_DIR_RW)
+ * @param[in]   move_type       move type
+ *                              [Enum: APP2EXT_MOVE_TO_EXT, APP2EXT_MOVE_TO_PHONE]
+ * @return      0 if success, error code(>0) if fail
  */
 typedef int (*app2ext_client_usr_move)(const char *appname, GList* dir_list,
                app2ext_move_type move_type, uid_t uid);
@@ -278,31 +277,40 @@ typedef int (*app2ext_client_move)(const char *appname, GList* dir_list,
                app2ext_move_type move_type);
 
 /**
- * @brief :This function type is for a function that is implemented by plugin
+ * @brief : This function type is for a function that is implemented by plugin
  * and called to enable application before application launch.
  *
- * @param[in]  appname         application package name which is to be enabled
- * @return     0 if success,  error code(>0) if fail
+ * @param[in]   appname         application package name which is to be enabled
+ * @return      0 if success, error code(>0) if fail
  */
 typedef int (*app2ext_client_usr_enable)(const char *appname, uid_t uid);
 typedef int (*app2ext_client_enable)(const char *appname);
 
 /**
- * @brief :This function type is for a function that is implemented by plugin
+ * @brief : This function type is for a function that is implemented by plugin
+ * and called to enable/disable entire application packages.
+ *
+ * @return      0 if success, error code(>0) if fail
+ */
+typedef int (*app2ext_client_enable_full_pkg)(void);
+typedef int (*app2ext_client_disable_full_pkg)(void);
+
+/**
+ * @brief : This function type is for a function that is implemented by plugin
  * and called to disable application before application exit.
  *
- * @param[in]  appname         application package name which is to be disabled
- * @return     0 if success,  error code(>0) if fail
+ * @param[in]   appname         application package name which is to be disabled
+ * @return      0 if success, error code(>0) if fail
  */
 typedef int (*app2ext_client_usr_disable)(const char *appname, uid_t uid);
 typedef int (*app2ext_client_disable)(const char *appname);
 
 /**
- * @brief :This function type is for a function that is implemented by plugin
+ * @brief : This function type is for a function that is implemented by plugin
  * and called after application uninstallation.
  *
- * @param[in]  pkgid           application package name which is to be uninstalled
- * @return     0 if success,  error code(>0) if fail
+ * @param[in]   pkgid           application package name which is to be uninstalled
+ * @return      0 if success, error code(>0) if fail
  */
 typedef int (*app2ext_client_usr_force_clean)(const char *pkgid, uid_t uid);
 typedef int (*app2ext_client_force_clean)(const char *pkgid);
@@ -321,6 +329,8 @@ typedef struct app2ext_interface_t {
        app2ext_client_force_clean              client_force_clean;
        app2ext_client_enable                   client_enable;
        app2ext_client_disable                  client_disable;
+       app2ext_client_enable_full_pkg          client_enable_full_pkg;
+       app2ext_client_disable_full_pkg         client_disable_full_pkg;
        app2ext_client_move                     client_move;
 
        app2ext_client_usr_pre_install          client_usr_pre_install;
@@ -337,20 +347,20 @@ typedef struct app2ext_interface_t {
 
 /**
  * This structure defines app2ext handle .Each storage type maps to a different plugin
- * type                        : storage type,
- * plugin_handle       : plugin handle, need to close dlopen handle
- * interface           : inteface with plugin library
+ * type                 : storage type,
+ * plugin_handle        : plugin handle, need to close dlopen handle
+ * interface            : inteface with plugin library
  */
 typedef struct {
-       app2ext_install_location        type;
+       app2ext_install_location        type;
        void                            *plugin_handle;
-       app2ext_interface               interface;
+       app2ext_interface               interface;
 } app2ext_handle;
 
 /**
  * This structure defines directory details
- * name                        : directory name
- * type                        : permission (rw/ro)
+ * name                 : directory name
+ * type                 : permission (rw/ro)
  */
 typedef struct {
        char                    *name;
@@ -359,33 +369,33 @@ typedef struct {
 
 /**
  * @brief : This API initializes the appropriate plugin based on storage type.
- *     It should be called before installation/uninstallation/upgrade
- * @param[in] storage_type     Location where package should be installed
- *                             [Ex: SD card, MicroUSB, Cloud]
- * @return     app2ext_handle pointer if success, NULL if fail
+ *         It should be called before installation/uninstallation/upgrade
+ * @param[in] storage_type      Location where package should be installed
+ *                              [Ex: SD card, MicroUSB, Cloud]
+ * @return      app2ext_handle pointer if success, NULL if fail
  *
  */
 API app2ext_handle *app2ext_init(int storage_type);
 
 /**
  * @brief : This API deinitializes the plugin
- *         This should be called when use of the plugin is completed
- * @param[in] handle   pointer to app2ext_handle which is to be deinitialized
- * @pre                Initialization is done for the storage handle
- * @return     0 if success,  error < 0 if fail
+ *         This should be called when use of the plugin is completed
+ * @param[in] handle    pointer to app2ext_handle which is to be deinitialized
+ * @pre         Initialization is done for the storage handle
+ * @return      0 if success, error < 0 if fail
  *
  */
 API int app2ext_deinit(app2ext_handle *handle);
 
 /**
  * @brief : This API returns the application location by refering to package manager DB
- *     This should be called to know location of an application package
- * @param[in] pkgid    package id
- * @param[in] uid      target user id of this instruction
- * @return     APP2EXT_SD_CARD if pkg is in SD card,
- *             APP2EXT_INTERNAL_MEM if pkg is in internal memory,
- *             APP2EXT_NOT_INSTALLED if there is no valid pkg path
- *             error < 0 if fail
+ *         This should be called to know location of an application package
+ * @param[in] pkgid     package id
+ * @param[in] uid       target user id of this instruction
+ * @return      APP2EXT_SD_CARD if pkg is in SD card,
+ *              APP2EXT_INTERNAL_MEM if pkg is in internal memory,
+ *              APP2EXT_NOT_INSTALLED if there is no valid pkg path
+ *              error < 0 if fail
  *@remarks see app2ext_install_location for more details
  */
 API int app2ext_get_app_location(const char *pkgid);
@@ -393,31 +403,38 @@ API int app2ext_usr_get_app_location(const char *pkgid, uid_t uid);
 
 /**
  * @brief : This API enable the package which is located in external memory
- * @param[in] pkgid    package id
- * @param[in] uid      target user id of this instruction
- * @return     error < 0  if pkg enable fail ,
+ * @param[in] pkgid     package id
+ * @param[in] uid       target user id of this instruction
+ * @return      error < 0 if pkg enable fail
  */
 API int app2ext_enable_external_pkg(const char *pkgid);
 API int app2ext_usr_enable_external_pkg(const char *pkgid, uid_t uid);
 
 /**
  * @brief : This API disable the package which is located in external memory
- * @param[in] pkgid    package id
- * @param[in] uid      target user id of this instruction
- * @return     error < 0  if pkg enable fail ,
+ * @param[in] pkgid     package id
+ * @param[in] uid       target user id of this instruction
+ * @return      error < 0 if pkg disable fail
  */
 API int app2ext_disable_external_pkg(const char *pkgid);
 API int app2ext_usr_disable_external_pkg(const char *pkgid, uid_t uid);
 
 /**
  * @brief : This API clean the directory and symbolic link which are made by app2ext
- * @param[in] pkgid    package id
- * @param[in] uid      target user id of this instruction
- * @return     error < 0  if pkg enable fail ,
+ * @param[in] pkgid     package id
+ * @param[in] uid       target user id of this instruction
+ * @return      error < 0 if pkg clean fail
  */
 API int app2ext_force_clean_pkg(const char *pkgid);
 API int app2ext_usr_force_clean_pkg(const char *pkgid, uid_t uid);
 
+/**
+ * @brief : This API mount/unmount all entries which are located in external memory
+ * @return      error < 0 if fail to start enable/disable
+ */
+API int app2ext_enable_external_full_pkg(void);
+API int app2ext_disable_external_full_pkg(void);
+
 #ifdef __cplusplus
 }
 #endif
index ede5655..119faca 100644 (file)
@@ -55,9 +55,9 @@ extern "C" {
 /**
  * @brief : This API prepares the setup for installation in SD card.
  *             It should be called before actual installation is done.
- * @pre                        vfat type sd card must be present.
- * @post               Installation is done by package installer.
              Encryption password is saved in db TZ_SYS_DB/.app2sd.db
+ * @pre                vfat type sd card must be present.
+ * @post       Installation is done by package installer.
*             Encryption password is saved in db TZ_SYS_DB/.app2sd.db
  * @param[in] appname          application package name
  *                             [Ex: com.samsung.calculator]
  *This entry is parsed from application package control/manifest file.
@@ -68,9 +68,9 @@ extern "C" {
  * @remark     None.
  */
 int app2sd_client_usr_pre_app_install(const char *pkgid,
-               GListdir_list, int size, uid_t uid);
+               GList *dir_list, int size, uid_t uid);
 int app2sd_client_pre_app_install(const char *pkgid,
-               GListdir_list, int size);
+               GList *dir_list, int size);
 
 /**
  * @brief : This API does post installation operations after
@@ -104,9 +104,9 @@ int app2sd_client_post_app_install(const char *pkgid,
  * @remark     None.
  */
 int app2sd_client_usr_pre_app_upgrade(const char *pkgid,
-               GListdir_list, int size, uid_t uid);
+               GList *dir_list, int size, uid_t uid);
 int app2sd_client_pre_app_upgrade(const char *pkgid,
-               GListdir_list, int size);
+               GList *dir_list, int size);
 
 /**
  * @brief : This API does post upgradation operations after
@@ -165,9 +165,9 @@ int app2sd_client_post_app_uninstall(const char *pkgid);
  * @remark     None.
  */
 int app2sd_client_usr_move_installed_app(const char *pkgid,
-               GListdir_list, app2ext_move_type move_type, uid_t uid);
+               GList *dir_list, app2ext_move_type move_type, uid_t uid);
 int app2sd_client_move_installed_app(const char *pkgid,
-               GListdir_list, app2ext_move_type move_type);
+               GList *dir_list, app2ext_move_type move_type);
 
 /**
  * @brief : This API Enables the application in sd card
@@ -202,7 +202,7 @@ int app2sd_client_force_clean(const char *pkgid);
 
 /**
  * @brief : This is the plug-in load function.
        The plugin has to bind its functions to function pointers of storage handle
*     The plugin has to bind its functions to function pointers of storage handle
  * @param[in/out] st_interface         Specifies the storage interface.
  * @return     None
 */
index 23258e9..5d0cd8a 100644 (file)
@@ -32,13 +32,13 @@ extern "C" {
 #include "app2ext_utils.h"
 
 int app2sd_usr_pre_app_install(const char *pkgid,
-               GListdir_list, int size, uid_t uid);
+               GList *dir_list, int size, uid_t uid);
 
 int app2sd_usr_post_app_install(const char *pkgid,
                app2ext_status install_status, uid_t uid);
 
 int app2sd_usr_pre_app_upgrade(const char *pkgid,
-               GListdir_list, int size, uid_t uid);
+               GList *dir_list, int size, uid_t uid);
 
 int app2sd_usr_post_app_upgrade(const char *pkgid,
                app2ext_status upgrade_status, uid_t uid);
@@ -48,7 +48,7 @@ int app2sd_usr_pre_app_uninstall(const char *pkgid, uid_t uid);
 int app2sd_usr_post_app_uninstall(const char *pkgid, uid_t uid);
 
 int app2sd_usr_move_installed_app(const char *pkgid,
-               GListdir_list, app2ext_move_type move_type, uid_t uid);
+               GList *dir_list, app2ext_move_type move_type, uid_t uid);
 
 int app2sd_usr_on_demand_setup_init(const char *pkgid, uid_t uid);
 
@@ -56,6 +56,10 @@ int app2sd_usr_on_demand_setup_exit(const char *pkgid, uid_t uid);
 
 int app2sd_usr_force_clean(const char *pkgid, uid_t uid);
 
+int app2sd_enable_full_pkg(void);
+
+int app2sd_disable_full_pkg(void);
+
 #ifdef __cplusplus
 }
 #endif
index 9c6dfe9..66bdfd6 100644 (file)
 #include "app2sd_interface.h"
 
 #define BUF_SIZE 256
-#define MEM_BUF_SIZE   5       /*Memory buffer size in MB*/
-#define PKG_BUF_SIZE   2       /*Memory buffer size in MB*/
+#define MEM_BUF_SIZE 5 /* Memory buffer size in MB */
+#define PKG_BUF_SIZE 2 /* Memory buffer size in MB */
 
 /*Device entry defines*/
-#define DEV_MAJOR              7
+#define DEV_MAJOR 7
 
-#define FS_TYPE                "ext4"
+#define FS_TYPE "ext4"
 #define INTERNAL_STORAGE_PATH "/opt"
 
 typedef enum mount_type_t {
@@ -81,10 +81,7 @@ int _app2sd_get_available_free_memory(const char *sd_path, int *free_mem);
 
 /*Function to move the application from/to SD Card*/
 int _app2sd_usr_move_app(const char *pkgid, app2ext_move_type move_cmd,
-               GList* dir_list, uid_t uid);
-
-/*utility to delete the directory*/
-int _app2sd_delete_directory(const char *dirname);
+               GList *dir_list, uid_t uid);
 
 /*utility to delete symbolic link*/
 void _app2sd_delete_symlink(const char *dirname);
@@ -162,15 +159,18 @@ char *_app2sd_find_free_device(void);
 int _app2sd_initialize_db();
 
 /*This function is used to get password from db*/
-char *_app2sd_get_password_from_db(const char *pkgid);
+char *_app2sd_get_password_from_db(const char *pkgid, uid_t uid);
+
+/*This function removes info from db */
+int _app2sd_remove_info_from_db(const char *pkgid, uid_t uid);
 
-/*This function removes password from db */
-int _app2sd_remove_password_from_db(const char *pkgid);
+/* This functions save info in db */
+int _app2sd_set_info_in_db(const char *pkgid, const char *passwd,
+               const char *loopback_device, uid_t uid);
 
-/* This functions saved password in db */
-int _app2sd_set_password_in_db(const char *pkgid, const char *passwd);
+int _app2sd_get_info_from_db(const char *filename, char **pkgid, uid_t *uid);
 
 int _app2sd_force_clean(const char *pkgid, const char *application_path,
-               const char *loopback_device);
+               const char *loopback_device, uid_t uid);
 
 #endif
index 50cb569..7c4dbb1 100644 (file)
@@ -81,7 +81,7 @@ static int __app2sd_call_server_method(const gchar *method_name,
        }
 
        value = g_dbus_proxy_call_sync(proxy, method_name, param,
-               G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+               G_DBUS_CALL_FLAGS_NONE, G_MAXINT, NULL, &error);
        if (error != NULL) {
                _E("proxy call sync error(%s)", error->message);
                g_error_free(error);
@@ -111,6 +111,35 @@ static void __app2sd_create_dir_list_builder(gpointer data, gpointer user_data)
        g_variant_builder_add(builder, "(si)", item->name, item->type);
 }
 
+static int __app2sd_delete_temp_directories(const char *pkgid,
+               app2sd_cmd cmd, uid_t uid)
+{
+       int ret = 0;
+       char temp_path[FILENAME_MAX] = { 0, };
+
+       if (cmd != APP2SD_PRE_UPGRADE)
+               return APP2EXT_SUCCESS;
+
+       if (_is_global(uid)) {
+               snprintf(temp_path, FILENAME_MAX - 1, "%s/%s.new",
+                       tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
+       } else {
+               tzplatform_set_user(uid);
+               snprintf(temp_path, FILENAME_MAX - 1, "%s/%s.new",
+                       tzplatform_getenv(TZ_USER_APP), pkgid);
+               tzplatform_reset_user();
+       }
+
+       /* this will delete all files under temp_path */
+       ret = _app2sd_delete_directory(temp_path);
+       if (ret) {
+               _E("unable to delete (%s)", temp_path);
+               return APP2EXT_ERROR_DELETE_DIRECTORY;
+       }
+
+       return APP2EXT_SUCCESS;
+}
+
 static int __app2sd_create_default_directories(const char *pkgid,
                app2sd_cmd cmd, uid_t uid)
 {
@@ -118,6 +147,7 @@ static int __app2sd_create_default_directories(const char *pkgid,
        mode_t mode = DIR_PERMS;
        char application_path[FILENAME_MAX] = { 0, };
        char application_mmc_path[FILENAME_MAX] = { 0, };
+       char temp_path[FILENAME_MAX] = { 0, };
 
        if (_is_global(uid)) {
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
@@ -151,12 +181,34 @@ static int __app2sd_create_default_directories(const char *pkgid,
        }
 
        if (cmd == APP2SD_PRE_UPGRADE) {
+               /* application_path for {pkgid}.new */
+               snprintf(temp_path, FILENAME_MAX - 1, "%s.new",
+                       application_path);
+               ret = mkdir(temp_path, mode);
+               if (ret) {
+                       if (errno != EEXIST) {
+                               _E("create directory failed," \
+                                       " error no is (%d)", errno);
+                               return APP2EXT_ERROR_CREATE_DIRECTORY;
+                       }
+               }
+               /* application_mmc_path for {pkgid}.new */
+               snprintf(application_mmc_path, FILENAME_MAX - 1, "%s/.mmc",
+                       temp_path);
+               ret = mkdir(application_mmc_path, mode);
+               if (ret) {
+                       if (errno != EEXIST) {
+                               _E("create directory failed," \
+                                       " error no is (%d)", errno);
+                               return APP2EXT_ERROR_CREATE_DIRECTORY;
+                       }
+               }
        }
 
        return APP2EXT_SUCCESS;
 }
 
-int app2sd_client_usr_pre_app_install(const char *pkgid, GListdir_list,
+int app2sd_client_usr_pre_app_install(const char *pkgid, GList *dir_list,
                int size, uid_t uid)
 {
        int ret = 0;
@@ -185,7 +237,7 @@ int app2sd_client_usr_pre_app_install(const char *pkgid, GList* dir_list,
 
        return ret;
 }
-int app2sd_client_pre_app_install(const char *pkgid, GListdir_list,
+int app2sd_client_pre_app_install(const char *pkgid, GList *dir_list,
                int size)
 {
        int ret = 0;
@@ -225,7 +277,7 @@ int app2sd_client_post_app_install(const char *pkgid,
        return ret;
 }
 
-int app2sd_client_usr_pre_app_upgrade(const char *pkgid, GListdir_list,
+int app2sd_client_usr_pre_app_upgrade(const char *pkgid, GList *dir_list,
                int size, uid_t uid)
 {
        int ret = 0;
@@ -252,9 +304,12 @@ int app2sd_client_usr_pre_app_upgrade(const char *pkgid, GList* dir_list,
        if (builder)
                g_variant_builder_unref(builder);
 
+       ret = __app2sd_delete_temp_directories(pkgid,
+               APP2SD_PRE_UPGRADE, uid);
+
        return ret;
 }
-int app2sd_client_pre_app_upgrade(const char *pkgid, GListdir_list,
+int app2sd_client_pre_app_upgrade(const char *pkgid, GList *dir_list,
                int size)
 {
        int ret = 0;
@@ -371,6 +426,24 @@ int app2sd_client_force_clean(const char *pkgid)
        return ret;
 }
 
+int app2sd_client_enable_full_pkg(void)
+{
+       int ret = 0;
+
+       ret = __app2sd_call_server_method("EnableFullPkg", NULL);
+
+       return ret;
+}
+
+int app2sd_client_disable_full_pkg(void)
+{
+       int ret = 0;
+
+       ret = __app2sd_call_server_method("DisableFullPkg", NULL);
+
+       return ret;
+}
+
 int app2sd_client_usr_on_demand_setup_init(const char *pkgid, uid_t uid)
 {
        int ret = 0;
@@ -423,7 +496,7 @@ int app2sd_client_on_demand_setup_exit(const char *pkgid)
        return ret;
 }
 
-int app2sd_client_usr_move_installed_app(const char *pkgid, GListdir_list,
+int app2sd_client_usr_move_installed_app(const char *pkgid, GList *dir_list,
                app2ext_move_type move_type, uid_t uid)
 {
        int ret = 0;
@@ -457,7 +530,7 @@ int app2sd_client_usr_move_installed_app(const char *pkgid, GList* dir_list,
 
        return ret;
 }
-int app2sd_client_move_installed_app(const char *pkgid, GListdir_list,
+int app2sd_client_move_installed_app(const char *pkgid, GList *dir_list,
                app2ext_move_type move_type)
 {
        int ret = 0;
@@ -480,6 +553,8 @@ void app2ext_on_load(app2ext_interface *interface)
        interface->client_force_clean = app2sd_client_force_clean;
        interface->client_enable = app2sd_client_on_demand_setup_init;
        interface->client_disable = app2sd_client_on_demand_setup_exit;
+       interface->client_enable_full_pkg = app2sd_client_enable_full_pkg;
+       interface->client_disable_full_pkg = app2sd_client_disable_full_pkg;
        interface->client_move = app2sd_client_move_installed_app;
 
        interface->client_usr_pre_install = app2sd_client_usr_pre_app_install;
index d9b6dde..29d69bd 100644 (file)
@@ -42,7 +42,7 @@ static int __app2sd_create_app2sd_directories(uid_t uid)
        return APP2EXT_SUCCESS;
 }
 
-int app2sd_usr_pre_app_install(const char *pkgid, GListdir_list, int size, uid_t uid)
+int app2sd_usr_pre_app_install(const char *pkgid, GList *dir_list, int size, uid_t uid)
 {
        int ret = 0;
        int free_mmc_mem = 0;
@@ -88,9 +88,9 @@ int app2sd_usr_pre_app_install(const char *pkgid, GList* dir_list, int size, uid
        }
 
        encoded_id = _app2sd_get_encoded_name(pkgid, uid);
-       if (encoded_id == NULL) {
+       if (encoded_id == NULL)
                return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
-       }
+
        if (_is_global(uid)) {
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
@@ -153,7 +153,7 @@ int app2sd_usr_pre_app_install(const char *pkgid, GList* dir_list, int size, uid
        /* mount the loopback encrypted pseudo device on application
         * installation path as with Read Write permission
         */
-       ret =_app2sd_mount_app_content(application_path, pkgid,
+       ret = _app2sd_mount_app_content(application_path, pkgid,
                device_node, MOUNT_TYPE_RW, dir_list,
                APP2SD_PRE_INSTALL, uid);
        if (ret) {
@@ -216,9 +216,9 @@ int app2sd_usr_post_app_install(const char *pkgid,
        sync();
 
        encoded_id = _app2sd_get_encoded_name(pkgid, uid);
-       if (encoded_id == NULL) {
+       if (encoded_id == NULL)
                return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
-       }
+
        if (_is_global(uid)) {
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
@@ -236,9 +236,8 @@ int app2sd_usr_post_app_install(const char *pkgid,
 
        /* get the associated device node for SD card applicationer */
        device_name = _app2sd_find_associated_device_node(loopback_device);
-       if (NULL == device_name) {
+       if (NULL == device_name)
                return APP2EXT_ERROR_FIND_ASSOCIATED_DEVICE_NODE;
-       }
 
        ret = _app2sd_unmount_app_content(application_path);
        if (ret) {
@@ -276,10 +275,9 @@ int app2sd_usr_post_app_install(const char *pkgid,
                        _E("unable to delete the loopback device from the SD Card");
                        return APP2EXT_ERROR_DELETE_LOOPBACK_DEVICE;
                }
-               ret = _app2sd_remove_password_from_db(pkgid);
-
+               ret = _app2sd_remove_info_from_db(pkgid, uid);
                if (ret)
-                       _E("unable to delete the password");
+                       _E("unable to delete info");
 
                ret = _app2sd_delete_directory(application_path);
                if (ret)
@@ -325,9 +323,9 @@ int app2sd_usr_on_demand_setup_init(const char *pkgid, uid_t uid)
        }
 
        encoded_id = _app2sd_get_encoded_name(pkgid, uid);
-       if (encoded_id == NULL) {
+       if (encoded_id == NULL)
                return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
-       }
+
        /* check app entry is there in sd card or not. */
        if (_is_global(uid)) {
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
@@ -410,9 +408,9 @@ int app2sd_usr_on_demand_setup_exit(const char *pkgid, uid_t uid)
        }
 
        encoded_id = _app2sd_get_encoded_name(pkgid, uid);
-       if (encoded_id == NULL) {
+       if (encoded_id == NULL)
                return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
-       }
+
        /* check app entry is there in sd card or not. */
        if (_is_global(uid)) {
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
@@ -476,9 +474,9 @@ int app2sd_usr_pre_app_uninstall(const char *pkgid, uid_t uid)
        }
 
        encoded_id = _app2sd_get_encoded_name(pkgid, uid);
-       if (encoded_id == NULL) {
+       if (encoded_id == NULL)
                return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
-       }
+
        if (_is_global(uid)) {
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
@@ -574,9 +572,9 @@ int app2sd_usr_post_app_uninstall(const char *pkgid, uid_t uid)
        }
 
        encoded_id = _app2sd_get_encoded_name(pkgid, uid);
-       if (encoded_id == NULL) {
+       if (encoded_id == NULL)
                return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
-       }
+
        if (_is_global(uid)) {
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
@@ -634,9 +632,9 @@ int app2sd_usr_post_app_uninstall(const char *pkgid, uid_t uid)
                goto END;
        }
 
-       ret = _app2sd_remove_password_from_db(pkgid);
+       ret = _app2sd_remove_info_from_db(pkgid, uid);
        if (ret) {
-               _E("cannot remove password from db");
+               _E("cannot remove info from db");
                ret = APP2EXT_ERROR_SQLITE_REGISTRY;
                goto END;
        }
@@ -645,7 +643,7 @@ END:
        return ret;
 }
 
-int app2sd_usr_move_installed_app(const char *pkgid, GListdir_list,
+int app2sd_usr_move_installed_app(const char *pkgid, GList *dir_list,
                app2ext_move_type move_type, uid_t uid)
 {
        int ret = 0;
@@ -715,7 +713,7 @@ int app2sd_usr_move_installed_app(const char *pkgid, GList* dir_list,
        return APP2EXT_SUCCESS;
 }
 
-int app2sd_usr_pre_app_upgrade(const char *pkgid, GListdir_list,
+int app2sd_usr_pre_app_upgrade(const char *pkgid, GList *dir_list,
                int size, uid_t uid)
 {
        int ret = APP2EXT_SUCCESS;
@@ -734,7 +732,7 @@ int app2sd_usr_pre_app_upgrade(const char *pkgid, GList* dir_list,
        int reqd_disk_size = size + ceil(size * 0.2);
 
        /* validate function arguments*/
-       if (pkgid == NULL || dir_list == NULL || size<=0) {
+       if (pkgid == NULL || dir_list == NULL || size <= 0) {
                _E("invalid function arguments");
                return APP2EXT_ERROR_INVALID_ARGUMENTS;
        }
@@ -747,9 +745,9 @@ int app2sd_usr_pre_app_upgrade(const char *pkgid, GList* dir_list,
        }
 
        encoded_id = _app2sd_get_encoded_name(pkgid, uid);
-       if (encoded_id == NULL) {
+       if (encoded_id == NULL)
                return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
-       }
+
        if (_is_global(uid)) {
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
@@ -787,7 +785,7 @@ int app2sd_usr_pre_app_upgrade(const char *pkgid, GList* dir_list,
                        _E("memory alloc failed");
                        return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
                }
-               snprintf(temp_pkgid, len, "%s.new", pkgid);
+               snprintf(temp_pkgid, len + 1, "%s.new", pkgid);
 
                if (_is_global(uid)) {
                        len = strlen(tzplatform_getenv(TZ_SYS_RW_APP)) + strlen(temp_pkgid) + 1;
@@ -797,7 +795,7 @@ int app2sd_usr_pre_app_upgrade(const char *pkgid, GList* dir_list,
                                free(temp_pkgid);
                                return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
                        }
-                       snprintf(temp_application_path, len, "%s/%s",
+                       snprintf(temp_application_path, len + 1, "%s/%s",
                                tzplatform_getenv(TZ_SYS_RW_APP), temp_pkgid);
 
                        temp_encoded_id = _app2sd_get_encoded_name((const char *)temp_pkgid, uid);
@@ -815,7 +813,7 @@ int app2sd_usr_pre_app_upgrade(const char *pkgid, GList* dir_list,
                                free(temp_encoded_id);
                                return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
                        }
-                       snprintf(temp_loopback_device, len, "%s/%s",
+                       snprintf(temp_loopback_device, len + 1, "%s/%s",
                                APP2SD_PATH, temp_encoded_id);
                        free(temp_encoded_id);
                } else {
@@ -827,10 +825,10 @@ int app2sd_usr_pre_app_upgrade(const char *pkgid, GList* dir_list,
                                free(temp_pkgid);
                                return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
                        }
-                       snprintf(temp_application_path, len, "%s/%s",
+                       snprintf(temp_application_path, len + 1, "%s/%s",
                                tzplatform_getenv(TZ_USER_APP), temp_pkgid);
 
-                       temp_encoded_id = _app2sd_get_encoded_name((const char*)temp_pkgid, uid);
+                       temp_encoded_id = _app2sd_get_encoded_name((const char *)temp_pkgid, uid);
                        if (temp_encoded_id == NULL) {
                                free(temp_pkgid);
                                free(temp_application_path);
@@ -846,7 +844,7 @@ int app2sd_usr_pre_app_upgrade(const char *pkgid, GList* dir_list,
                                free(temp_encoded_id);
                                return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
                        }
-                       snprintf(temp_loopback_device, len, "%s/%s",
+                       snprintf(temp_loopback_device, len + 1, "%s/%s",
                                APP2SD_PATH, temp_encoded_id);
                        free(temp_encoded_id);
                        tzplatform_reset_user();
@@ -933,9 +931,9 @@ int app2sd_usr_post_app_upgrade(const char *pkgid,
        }
 
        encoded_id = _app2sd_get_encoded_name(pkgid, uid);
-       if (encoded_id == NULL) {
+       if (encoded_id == NULL)
                return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
-       }
+
        if (_is_global(uid)) {
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
@@ -953,9 +951,8 @@ int app2sd_usr_post_app_upgrade(const char *pkgid,
 
        /* get the associated device node for SD card applicationer */
        device_name = _app2sd_find_associated_device_node(loopback_device);
-       if (NULL == device_name) {
+       if (NULL == device_name)
                return APP2EXT_ERROR_FIND_ASSOCIATED_DEVICE_NODE;
-       }
 
        ret = _app2sd_unmount_app_content(application_path);
        if (ret) {
@@ -1002,9 +999,9 @@ int app2sd_usr_force_clean(const char *pkgid, uid_t uid)
        sync();
 
        encoded_id = _app2sd_get_encoded_name(pkgid, uid);
-       if (encoded_id == NULL) {
+       if (encoded_id == NULL)
                return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
-       }
+
        if (_is_global(uid)) {
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
@@ -1020,7 +1017,131 @@ int app2sd_usr_force_clean(const char *pkgid, uid_t uid)
        }
        free(encoded_id);
 
-       ret = _app2sd_force_clean(pkgid, application_path, loopback_device);
+       ret = _app2sd_force_clean(pkgid, application_path, loopback_device, uid);
+
+       return ret;
+}
+
+int app2sd_enable_full_pkg(void)
+{
+       int ret = APP2EXT_SUCCESS;
+       int rc = 0;
+       char buf[FILENAME_MAX] = { 0, };
+       char loopback_device[FILENAME_MAX] = { 0, };
+       DIR *dir = NULL;
+       struct dirent entry;
+       struct dirent *result = NULL;
+       char *pkgid = NULL;
+       uid_t uid = 0;
+
+       dir = opendir(APP2SD_PATH);
+       if (!dir) {
+               if (strerror_r(errno, buf, sizeof(buf)) == 0)
+                       _E("failed to opendir (%s)", buf);
+               return APP2EXT_ERROR_OPEN_DIR;
+       }
+
+       ret = _app2sd_initialize_db();
+       if (ret) {
+               _E("app2sd db initialize failed");
+               return APP2EXT_ERROR_SQLITE_REGISTRY;
+       }
+
+       for (rc = readdir_r(dir, &entry, &result);
+               rc == 0 && result != NULL;
+               rc = readdir_r(dir, &entry, &result)) {
+               if (strcmp(entry.d_name, ".") == 0 ||
+                       strcmp(entry.d_name, "..") == 0)
+                       continue;
+               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
+                       APP2SD_PATH, entry.d_name);
+               ret = _app2sd_get_info_from_db(loopback_device,
+                       &pkgid, &uid);
+               if (ret) {
+                       _E("failed to get info from db");
+                       break;;
+               }
+               if (pkgid && uid > 0) {
+                       _D("pkgid(%s), uid(%d)", pkgid, uid);
+                       ret = app2sd_usr_on_demand_setup_init(pkgid, uid);
+                       if (ret) {
+                               _E("error(%d)", ret);
+                               break;
+                       }
+               }
+               if (pkgid) {
+                       free(pkgid);
+                       pkgid = NULL;
+               }
+       }
+
+       if (pkgid) {
+               free(pkgid);
+               pkgid = NULL;
+       }
+       closedir(dir);
+
+       return ret;
+}
+
+int app2sd_disable_full_pkg(void)
+{
+       int ret = APP2EXT_SUCCESS;
+       int rc = 0;
+       char buf[FILENAME_MAX] = { 0, };
+       char loopback_device[FILENAME_MAX] = { 0, };
+       DIR *dir = NULL;
+       struct dirent entry;
+       struct dirent *result = NULL;
+       char *pkgid = NULL;
+       uid_t uid = 0;
+
+       dir = opendir(APP2SD_PATH);
+       if (!dir) {
+               if (strerror_r(errno, buf, sizeof(buf)) == 0)
+                       _E("failed to opendir (%s)", buf);
+               return APP2EXT_ERROR_OPEN_DIR;
+       }
+
+       ret = _app2sd_initialize_db();
+       if (ret) {
+               _E("app2sd db initialize failed");
+               return APP2EXT_ERROR_SQLITE_REGISTRY;
+       }
+
+       for (rc = readdir_r(dir, &entry, &result);
+               rc == 0 && result != NULL;
+               rc = readdir_r(dir, &entry, &result)) {
+               if (strcmp(entry.d_name, ".") == 0 ||
+                       strcmp(entry.d_name, "..") == 0)
+                       continue;
+               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
+                       APP2SD_PATH, entry.d_name);
+               ret = _app2sd_get_info_from_db(loopback_device,
+                       &pkgid, &uid);
+               if (ret) {
+                       _E("failed to get info from db");
+                       break;
+               }
+               if (pkgid && uid > 0) {
+                       _D("pkgid(%s), uid(%d)", pkgid, uid);
+                       ret = app2sd_usr_on_demand_setup_exit(pkgid, uid);
+                       if (ret) {
+                               _E("error(%d)", ret);
+                               break;
+                       }
+               }
+               if (pkgid) {
+                       free(pkgid);
+                       pkgid = NULL;
+               }
+       }
+
+       if (pkgid) {
+               free(pkgid);
+               pkgid = NULL;
+       }
+       closedir(dir);
 
        return ret;
 }
index 82e38cb..686073a 100644 (file)
@@ -28,7 +28,7 @@
 
 #include "app2sd_internals.h"
 
-static int _app2sd_make_directory(const charpath, uid_t uid)
+static int _app2sd_make_directory(const char *path, uid_t uid)
 {
        int ret = 0;
        int fd = -1;
@@ -173,9 +173,9 @@ char *_app2sd_create_loopdevice_node(void)
                        return NULL;
                }
                memset(ret_result, '\0', strlen(result) + 1);
-               if (strlen(result) > 0) {
+               if (strlen(result) > 0)
                        memcpy(ret_result, result, strlen(result) - 1);
-               }
+
                free(result);
                result = NULL;
 
@@ -203,15 +203,15 @@ char *_app2sd_do_loopback_encryption_setup(const char *pkgid,
                return NULL;
        }
 
-       if ((passwd = _app2sd_get_password_from_db(pkgid)) == NULL) {
+       if ((passwd = _app2sd_get_password_from_db(pkgid, uid)) == NULL) {
                passwd = (char *)_app2sd_generate_password(pkgid);
                if (NULL == passwd) {
                        _E("unable to generate password");
                        return NULL;
                } else {
-                       if ((ret = _app2sd_set_password_in_db(pkgid,
-                               passwd)) < 0) {
-                               _E("unable to save password");
+                       if ((ret = _app2sd_set_info_in_db(pkgid,
+                               passwd, loopback_device, uid)) < 0) {
+                               _E("unable to save info");
                                free(passwd);
                                passwd = NULL;
                                return NULL;
@@ -249,47 +249,20 @@ char *_app2sd_do_loopback_encryption_setup(const char *pkgid,
 
 char *_app2sd_do_loopback_duplicate_encryption_setup(const char *pkgid,
                const char *temp_pkgid, const char *temp_loopback_device,
-               uid_t uid)
+               char *passwd, uid_t uid)
 {
-       int ret = APP2EXT_SUCCESS;
-       char *passwd = NULL;
        char *result = NULL;
        char *device_node = NULL;
 
        if (pkgid == NULL || temp_pkgid == NULL ||
-               temp_loopback_device == NULL) {
+               temp_loopback_device == NULL || passwd == NULL) {
                _E("invalid argument");
                return NULL;
        }
 
-       /* get password for loopback encryption */
-       ret = _app2sd_initialize_db();
-       if (ret) {
-               _E("app2sd db initialize failed");
-               return NULL;
-       }
-
-       if ((passwd = _app2sd_get_password_from_db(pkgid)) == NULL) {
-               passwd = (char *)_app2sd_generate_password(pkgid);
-               if (NULL == passwd) {
-                       _E("unable to generate password");
-                       return NULL;
-               } else {
-                       if ((ret = _app2sd_set_password_in_db(pkgid,
-                               passwd)) < 0) {
-                               _E("unable to save password");
-                               free(passwd);
-                               passwd = NULL;
-                               return NULL;
-                       }
-               }
-       }
-
        /* get free device node*/
        device_node = _app2sd_create_loopdevice_node();
        if (NULL == device_node) {
-               free(passwd);
-               passwd = NULL;
                _E("unable to find free loopback node");
                return NULL;
        }
@@ -297,22 +270,16 @@ char *_app2sd_do_loopback_duplicate_encryption_setup(const char *pkgid,
                temp_loopback_device, passwd);
        if (result == NULL) {
                _E("encryption failed");
-               free(passwd);
-               passwd = NULL;
                return NULL;
        } else {
                if (strlen(result) == 0) {
                        free(result);
                        result = NULL;
-                       free(passwd);
-                       passwd = NULL;
                        return device_node;
                } else {
                        _E("error is (%s)", result);
                        free(result);
                        result = NULL;
-                       free(passwd);
-                       passwd = NULL;
                        return NULL;
                }
        }
@@ -354,7 +321,7 @@ int _app2sd_remove_all_loopback_encryption_setups(const char *loopback_device)
        int ret = APP2EXT_SUCCESS;
        char *result = NULL;
        char *dev_node = NULL;
-       while(1) {
+       while (1) {
                if ((dev_node =
                        _app2sd_find_associated_device_node(loopback_device))
                        == NULL) {
@@ -398,8 +365,8 @@ int _app2sd_create_loopback_device(const char *pkgid,
        snprintf(command, FILENAME_MAX - 1, "of=%s", loopback_device);
        snprintf(buff, BUF_SIZE - 1, "count=%d", size);
 
-       const char *argv1[] =
-           { "dd", "if=/dev/zero", command, "bs=1M", buff, NULL };
+       const char *argv1[] = { "dd", "if=/dev/zero",
+               command, "bs=1M", buff, NULL };
 
        if ((fp = fopen(loopback_device, "r+")) != NULL) {
                _W("encrypted file already exists (%s)",
@@ -422,14 +389,14 @@ int _app2sd_delete_loopback_device(const char *loopback_device)
        ret = unlink(loopback_device);
        if (ret) {
                if (errno == ENOENT) {
-                       _E("unable to access file (%s)", loopback_device);
+                       _W("unable to access file (%s)", loopback_device);
                } else {
                        _E("unable to delete (%s)", loopback_device);
                        return APP2EXT_ERROR_DELETE_LOOPBACK_DEVICE;
                }
        }
 
-       return ret;
+       return APP2EXT_SUCCESS;
 }
 
 int _app2sd_create_file_system(const char *device_path)
@@ -498,11 +465,11 @@ static int _app2sd_create_dir_with_link(const char *application_path,
 }
 
 static int _app2sd_create_directory_entry(const char *application_path,
-               const char *pkgid, GListdir_list, uid_t uid)
+               const char *pkgid, GList *dir_list, uid_t uid)
 {
        int ret = APP2EXT_SUCCESS;
        GList *list = NULL;
-       app2ext_dir_detailsdir_detail = NULL;
+       app2ext_dir_details *dir_detail = NULL;
 
        list = g_list_first(dir_list);
        while (list) {
@@ -511,9 +478,8 @@ static int _app2sd_create_directory_entry(const char *application_path,
                        && dir_detail->type == APP2EXT_DIR_RO) {
                        ret = _app2sd_create_dir_with_link(application_path,
                                pkgid, dir_detail->name, uid);
-                       if (ret) {
+                       if (ret)
                                return ret;
-                       }
                }
                list = g_list_next(list);
        }
@@ -521,7 +487,7 @@ static int _app2sd_create_directory_entry(const char *application_path,
 }
 
 int _app2sd_mount_app_content(const char *application_path, const char *pkgid,
-               const char *dev, int mount_type, GListdir_list,
+               const char *dev, int mount_type, GList *dir_list,
                app2sd_cmd cmd, uid_t uid)
 {
        int ret = APP2EXT_SUCCESS;
@@ -667,7 +633,7 @@ static int _app2sd_move_to_archive(const char *src_path, const char *arch_path)
        return ret;
 }
 
-int _app2sd_move_app_to_external(const char *pkgid, GListdir_list, uid_t uid)
+int _app2sd_move_app_to_external(const char *pkgid, GList *dir_list, uid_t uid)
 {
        int ret = APP2EXT_SUCCESS;
        mode_t mode = DIR_PERMS;
@@ -684,8 +650,8 @@ int _app2sd_move_app_to_external(const char *pkgid, GList* dir_list, uid_t uid)
        int free_mmc_mem = 0;
        FILE *fp = NULL;
        GList *list = NULL;
-       app2ext_dir_detailsdir_detail = NULL;
-       char err_buf[1024] = {0,};
+       app2ext_dir_details *dir_detail = NULL;
+       char err_buf[1024] = { 0,};
        char *encoded_id = NULL;
 
        /* check whether MMC is present or not */
@@ -696,9 +662,9 @@ int _app2sd_move_app_to_external(const char *pkgid, GList* dir_list, uid_t uid)
        }
 
        encoded_id = _app2sd_get_encoded_name(pkgid, uid);
-       if (encoded_id == NULL) {
+       if (encoded_id == NULL)
                return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
-       }
+
        snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
                        APP2SD_PATH, encoded_id);
        free(encoded_id);
@@ -718,7 +684,7 @@ int _app2sd_move_app_to_external(const char *pkgid, GList* dir_list, uid_t uid)
                _W("Already %s entry is present in the SD Card, " \
                        "delete entry and go on without return", pkgid);
                fclose(fp);
-               _app2sd_force_clean(pkgid, application_path, loopback_device);
+               _app2sd_force_clean(pkgid, application_path, loopback_device, uid);
        }
 
        snprintf(application_mmc_path, FILENAME_MAX - 1, "%s/.mmc",
@@ -752,7 +718,7 @@ int _app2sd_move_app_to_external(const char *pkgid, GList* dir_list, uid_t uid)
                list = g_list_next(list);
        }
 
-       reqd_size = ((total_size) / ( 1024 * 1024)) + 2;
+       reqd_size = ((total_size) / (1024 * 1024)) + 2;
        reqd_disk_size = reqd_size + ceil(reqd_size * 0.2);
 
        /* find avialable free memory in the MMC card */
@@ -898,7 +864,7 @@ int _app2sd_move_app_to_external(const char *pkgid, GList* dir_list, uid_t uid)
        return APP2EXT_SUCCESS;
 }
 
-int _app2sd_move_app_to_internal(const char *pkgid, GListdir_list, uid_t uid)
+int _app2sd_move_app_to_internal(const char *pkgid, GList *dir_list, uid_t uid)
 {
        int ret = APP2EXT_SUCCESS;
        mode_t mode = DIR_PERMS;
@@ -910,7 +876,7 @@ int _app2sd_move_app_to_internal(const char *pkgid, GList* dir_list, uid_t uid)
        char *device_node = NULL;
        FILE *fp = NULL;
        GList *list = NULL;
-       app2ext_dir_detailsdir_detail = NULL;
+       app2ext_dir_details *dir_detail = NULL;
        int reqd_size = 0;
        int free_internal_mem = 0;
        struct statvfs buf = {0,};
@@ -926,9 +892,9 @@ int _app2sd_move_app_to_internal(const char *pkgid, GList* dir_list, uid_t uid)
        }
 
        encoded_id = _app2sd_get_encoded_name(pkgid, uid);
-       if (encoded_id == NULL) {
+       if (encoded_id == NULL)
                return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
-       }
+
        snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
                        APP2SD_PATH, encoded_id);
        free(encoded_id);
@@ -955,7 +921,7 @@ int _app2sd_move_app_to_internal(const char *pkgid, GList* dir_list, uid_t uid)
 
        memset((void *)&buf, '\0', sizeof(struct statvfs));
        ret = statvfs(INTERNAL_STORAGE_PATH, &buf);
-       if (0 == ret){
+       if (0 == ret) {
                temp = (buf.f_bsize * buf.f_bavail) / (1024 * 1024);
                free_internal_mem = (int)temp;
        } else {
@@ -1136,11 +1102,20 @@ int _app2sd_move_app_to_internal(const char *pkgid, GList* dir_list, uid_t uid)
                return APP2EXT_ERROR_DELETE_DIRECTORY;
        }
 
+       /* remove passwrd from DB */
+       ret = _app2sd_initialize_db();
+       if (ret)
+               _E("app2sd db initialize failed");
+
+       ret = _app2sd_remove_info_from_db(pkgid, uid);
+       if (ret)
+               _E("cannot remove info from db");
+
        return APP2EXT_SUCCESS;
 }
 
 int _app2sd_usr_move_app(const char *pkgid, app2ext_move_type move_type,
-               GListdir_list, uid_t uid)
+               GList *dir_list, uid_t uid)
 {
        int ret = APP2EXT_SUCCESS;
 
@@ -1174,12 +1149,12 @@ int _app2sd_usr_move_app(const char *pkgid, app2ext_move_type move_type,
        return ret;
 }
 
-int _app2sd_copy_ro_content(const char *src, const char *dest, GListdir_list)
+int _app2sd_copy_ro_content(const char *src, const char *dest, GList *dir_list)
 {
        char path[FILENAME_MAX] = { 0, };
        int ret = APP2EXT_SUCCESS;
        GList *list = NULL;
-       app2ext_dir_detailsdir_detail = NULL;
+       app2ext_dir_details *dir_detail = NULL;
 
        list = g_list_first(dir_list);
        while (list) {
@@ -1212,13 +1187,14 @@ int _app2sd_duplicate_device(const char *pkgid,
                const char *temp_pkgid,
                const char *temp_application_path,
                const char *temp_loopback_device,
-               GListdir_list, char *dev_node, int size,
+               GList *dir_list, char *dev_node, int size,
                uid_t uid)
 {
        int ret = 0;
        char *devi = NULL;
        int err_res = 0;
        char *result = NULL;
+       char *passwd = NULL;
 
        /* create a new loopback device */
        ret = _app2sd_create_loopback_device(temp_pkgid,
@@ -1228,15 +1204,41 @@ int _app2sd_duplicate_device(const char *pkgid,
                return ret;
        }
 
+       /* get password for loopback encryption */
+       ret = _app2sd_initialize_db();
+       if (ret) {
+               _E("app2sd db initialize failed");
+               return APP2EXT_ERROR_DB_INITIALIZE;
+       }
+
+       if ((passwd = _app2sd_get_password_from_db(pkgid, uid)) == NULL) {
+               passwd = (char *)_app2sd_generate_password(pkgid);
+               if (NULL == passwd) {
+                       _E("unable to generate password");
+                       return APP2EXT_ERROR_PASSWD_GENERATION;
+               } else {
+                       if ((ret = _app2sd_set_info_in_db(pkgid,
+                               passwd, loopback_device, uid)) < 0) {
+                               _E("unable to save info");
+                               free(passwd);
+                               passwd = NULL;
+                               return APP2EXT_ERROR_SQLITE_REGISTRY;
+                       }
+               }
+       }
+
        /* perform loopback encryption setup */
        dev_node = _app2sd_do_loopback_duplicate_encryption_setup(pkgid,
-               temp_pkgid, temp_loopback_device, uid);
+               temp_pkgid, temp_loopback_device, passwd, uid);
        if (!dev_node) {
                _E("losetup failed, device node is (%s)", dev_node);
                _app2sd_delete_loopback_device(loopback_device);
-               _E("create ext filesystem failed");
+               free(passwd);
+               passwd = NULL;
                return APP2EXT_ERROR_DO_LOSETUP;
        }
+       free(passwd);
+       passwd = NULL;
        _D("duplicate setup SUCCESS");
 
        /* check whether loopback device is associated with
@@ -1301,7 +1303,7 @@ int _app2sd_update_loopback_device_size(const char *pkgid,
                const char *temp_pkgid,
                const char *temp_loopback_device,
                const char *temp_application_path,
-               int size, GListdir_list,
+               int size, GList *dir_list,
                uid_t uid)
 {
        int ret = 0;
@@ -1417,49 +1419,54 @@ FINISH_OFF:
        }
 
        ret = _app2sd_remove_loopback_encryption_setup(loopback_device);
-       if (ret) {
+       if (ret)
                _E("unable to remove loopback setup");
-               err_res = APP2EXT_ERROR_DELETE_LOOPBACK_DEVICE;
-       }
+
+       ret = _app2sd_remove_loopback_encryption_setup(temp_loopback_device);
+       if (ret)
+               _E("unable to remove loopback setup");
+
+       _app2sd_delete_loopback_device(temp_loopback_device);
+
+       ret = _app2sd_delete_directory(temp_application_path);
+       if (ret)
+               _E("unable to delete (%s)", temp_application_path);
 
        return err_res;
 }
 
 int _app2sd_force_clean(const char *pkgid, const char *application_path,
-               const char *loopback_device)
+               const char *loopback_device, uid_t uid)
 {
        int ret = APP2EXT_SUCCESS;
 
        /* unmount the loopback encrypted pseudo device from the application installation path */
        ret = _app2sd_unmount_app_content(application_path);
-       if (ret) {
+       if (ret)
                _E("unable to unmount the app content (%d)", ret);
-       }
 
        /* detach the loopback encryption setup for the application */
        ret = _app2sd_remove_all_loopback_encryption_setups(loopback_device);
-       if (ret) {
+       if (ret)
                _E("unable to detach the loopback encryption setup for the application");
-       }
 
        /* delete the loopback device from the SD card */
        ret = _app2sd_delete_loopback_device(loopback_device);
-       if (ret) {
+       if (ret)
                _E("unable to detach the loopback encryption setup for the application");
-       }
 
        /* delete symlink */
        _app2sd_delete_symlink(application_path);
 
        /* remove passwrd from DB */
        ret = _app2sd_initialize_db();
-       if (ret) {
+       if (ret)
                _E("app2sd db initialize failed");
-       }
-       ret = _app2sd_remove_password_from_db(pkgid);
-       if (ret) {
-               _E("cannot remove password from db");
-       }
+
+       ret = _app2sd_remove_info_from_db(pkgid, uid);
+       if (ret)
+               _E("cannot remove info from db");
+
 
        return ret;
 }
index 8ac0cbf..7d7da9b 100644 (file)
 /*sqlite  db code*/
 #define APP2SD_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".app2sd.db")
 sqlite3 *app2sd_db;
-#define QUERY_CREATE_TABLE_APP2SD "create table app2sd \
-       (pkgid text primary key,\
-        password text\
-       )"
+#define QUERY_CREATE_TABLE_APP2SD "CREATE TABLE IF NOT EXISTS app2sd_info " \
+       "(pkgid TEXT PRIMARY KEY NOT NULL, password TEXT NOT NULL, " \
+       "filename TEXT NOT NULL, uid INTEGER)"
 
 int _app2sd_initialize_db()
 {
        char *error_message = NULL;
        int ret;
-       FILE * fp = NULL;
+       FILE *fp = NULL;
 
        fp = fopen(APP2SD_DB_FILE, "r");
        if (fp != NULL) {
@@ -82,17 +81,61 @@ int _app2sd_initialize_db()
        return 0;
 }
 
-int _app2sd_set_password_in_db(const char *pkgid, const char *passwd)
+static int _app2sd_check_existing_info(const char *pkgid, uid_t uid)
+{
+       char *query = NULL;
+       const char *val = NULL;
+       sqlite3_stmt *stmt = NULL;
+       int ret = 0;
+
+       query = sqlite3_mprintf("select count(*) from app2sd_info " \
+               "where pkgid=%Q and uid=%d", pkgid, uid);
+
+       ret = sqlite3_prepare_v2(app2sd_db, query, strlen(query), &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               _E("prepare failed (%s)", sqlite3_errmsg(app2sd_db));
+               sqlite3_free(query);
+               return -1;
+       }
+
+       if (sqlite3_step(stmt) != SQLITE_ROW) {
+               _E("failed to step");
+               sqlite3_finalize(stmt);
+               return -1;
+       }
+
+       val = (const char *)sqlite3_column_text(stmt, 0);
+       ret = atoi(val);
+       sqlite3_finalize(stmt);
+
+       return ret;
+}
+
+int _app2sd_set_info_in_db(const char *pkgid, const char *passwd,
+               const char *loopback_device, uid_t uid)
 {
        char *error_message = NULL;
        char *query = NULL;
+       int ret = 0;
 
-       query = sqlite3_mprintf("insert into app2sd" \
-               "(pkgid, password) values (%Q, %Q)", pkgid, passwd);
+       ret = _app2sd_check_existing_info(pkgid, uid);
+       if (ret < 0) {
+               _E("failed to get existing info");
+               return APP2EXT_ERROR_SQLITE_REGISTRY;
+       }
 
-       if (SQLITE_OK != sqlite3_exec(app2sd_db, query, NULL, NULL,
-               &error_message)) {
-               _E("don't execute query = (%s), error message = (%s)",
+       if (ret == 0)
+               query = sqlite3_mprintf("insert into app2sd_info " \
+                       "(pkgid, password, filename, uid) values (%Q, %Q, %Q, %d)",
+                       pkgid, passwd, loopback_device, uid);
+       else
+               query = sqlite3_mprintf("update app2sd_info " \
+                       "set password=%Q, filename=%Q where pkgid=%Q and uid=%d",
+                       passwd, loopback_device, pkgid, uid);
+
+       ret = sqlite3_exec(app2sd_db, query, NULL, NULL, &error_message);
+       if (ret != SQLITE_OK) {
+               _E("failed to execute query(%s), error message(%s)",
                        query, error_message);
                sqlite3_free(query);
                return APP2EXT_ERROR_SQLITE_REGISTRY;
@@ -102,48 +145,109 @@ int _app2sd_set_password_in_db(const char *pkgid, const char *passwd)
        return APP2EXT_SUCCESS;
 }
 
-int _app2sd_remove_password_from_db(const char *pkgid)
+int _app2sd_remove_info_from_db(const char *pkgid, uid_t uid)
 {
        char *error_message = NULL;
        char *query = NULL;
+       int ret = 0;
+
+       query = sqlite3_mprintf("delete from app2sd_info " \
+               "where pkgid=%Q and uid=%d", pkgid, uid);
+
+       ret = sqlite3_exec(app2sd_db, query, NULL, NULL, &error_message);
+       if (ret != SQLITE_OK) {
+               _E("failed to execute query(%s), error message(%s)",
+                       query, error_message);
+               sqlite3_free(query);
+               return APP2EXT_ERROR_SQLITE_REGISTRY;
+       }
+       sqlite3_free(query);
+
+       return APP2EXT_SUCCESS;
+}
+
+int _app2sd_get_info_from_db(const char *filename, char **pkgid, uid_t *uid)
+{
+       char *query = NULL;
+       sqlite3_stmt *stmt = NULL;
+       int ret = APP2EXT_SUCCESS;
 
-       query = sqlite3_mprintf("delete from app2sd" \
-               " where pkgid=%Q", pkgid);
+       _D("filename(%s)", filename);
+       query = sqlite3_mprintf("select * from app2sd_info " \
+               "where filename=%Q", filename);
 
-       if (SQLITE_OK != sqlite3_exec(app2sd_db, query, NULL,
-               NULL, &error_message)) {
-               _E("don't execute query = (%s), "
-                       "error message = (%s)", query, error_message);
+       ret = sqlite3_prepare_v2(app2sd_db, query, strlen(query), &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               _E("prepare failed (%s)", sqlite3_errmsg(app2sd_db));
                sqlite3_free(query);
+               *pkgid = NULL;
+               *uid = 0;
                return APP2EXT_ERROR_SQLITE_REGISTRY;
        }
 
+       ret = sqlite3_step(stmt);
+       if (ret != SQLITE_ROW || ret == SQLITE_DONE) {
+               _W("no records found");
+               ret = APP2EXT_SUCCESS;
+               goto FINISH_OFF;
+       }
+
+       *pkgid = strdup((const char *)sqlite3_column_text(stmt, 0));
+       if (*pkgid == NULL) {
+               _E("out of memory");
+               ret = APP2EXT_ERROR_SQLITE_REGISTRY;
+               goto FINISH_OFF;
+       }
+
+       *uid = sqlite3_column_int(stmt, 3);
+       if (*uid != GLOBAL_USER && *uid < REGULAR_USER) {
+               _E("invalid uid");
+               ret = APP2EXT_ERROR_SQLITE_REGISTRY;
+               goto FINISH_OFF;
+       }
+
+       if (SQLITE_OK != sqlite3_finalize(stmt)) {
+               _E("error : sqlite3_finalize");
+               ret = APP2EXT_ERROR_SQLITE_REGISTRY;
+               goto FINISH_OFF;
+       }
        sqlite3_free(query);
 
        return APP2EXT_SUCCESS;
+
+FINISH_OFF:
+       if (*pkgid) {
+               free(*pkgid);
+               *pkgid = NULL;
+       }
+       *uid = 0;
+
+       sqlite3_finalize(stmt);
+       sqlite3_free(query);
+
+       return ret;
 }
 
-char *_app2sd_get_password_from_db(const char *pkgid)
+char *_app2sd_get_password_from_db(const char *pkgid, uid_t uid)
 {
        char *query = NULL;
        char *passwd = NULL;
-       const char *tail = NULL;
        sqlite3_stmt *stmt = NULL;
-       int rc = 0;
+       int ret = 0;
 
-       query = sqlite3_mprintf("select * from app2sd" \
-               " where pkgid=%Q", pkgid);
+       query = sqlite3_mprintf("select * from app2sd_info " \
+               "where pkgid=%Q and uid=%d", pkgid, uid);
 
-       if (SQLITE_OK != sqlite3_prepare(app2sd_db, query,
-               strlen(query), &stmt, &tail)) {
-               _E("sqlite3_prepare error");
+       ret = sqlite3_prepare_v2(app2sd_db, query, strlen(query), &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               _E("prepare failed (%s)", sqlite3_errmsg(app2sd_db));
                sqlite3_free(query);
                return NULL;
        }
 
-       rc = sqlite3_step(stmt);
-       if (rc != SQLITE_ROW || rc == SQLITE_DONE) {
-               _E("no records found");
+       ret = sqlite3_step(stmt);
+       if (ret != SQLITE_ROW || ret == SQLITE_DONE) {
+               _W("no records found");
                goto FINISH_OFF;
        }
        passwd = malloc(PASSWORD_LENGTH + 1);
@@ -152,7 +256,7 @@ char *_app2sd_get_password_from_db(const char *pkgid)
                goto FINISH_OFF;
        }
 
-       strncpy(passwd, (const char*)sqlite3_column_text(stmt, 1),
+       strncpy(passwd, (const char *)sqlite3_column_text(stmt, 1),
                PASSWORD_LENGTH);
        if (passwd == NULL) {
                _E("data is NULL");
@@ -167,14 +271,11 @@ char *_app2sd_get_password_from_db(const char *pkgid)
        return passwd;
 
 FINISH_OFF:
-       rc = sqlite3_finalize(stmt);
-       if (rc != SQLITE_OK) {
-               _E("sqlite3_finalize failed(%d)", rc);
-       }
-       sqlite3_free(query);
-
        if (passwd)
                free(passwd);
 
+       sqlite3_finalize(stmt);
+       sqlite3_free(query);
+
        return NULL;
 }
index cada8e3..0f01c46 100644 (file)
@@ -133,55 +133,6 @@ int _app2sd_get_available_free_memory(const char *sd_path, int *free_mem)
        return 0;
 }
 
-int _app2sd_delete_directory(const char *dirname)
-{
-       DIR *dp = NULL;
-       struct dirent ep;
-       struct dirent *er = NULL;
-       char abs_filename[FILENAME_MAX] = { 0, };
-       int ret = 0;
-
-       dp = opendir(dirname);
-       if (dp != NULL) {
-               while (readdir_r(dp, &ep, &er) == 0 && er != NULL) {
-                       struct stat stFileInfo;
-
-                       snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
-                               ep.d_name);
-
-                       if (lstat(abs_filename, &stFileInfo) < 0) {
-                               perror(abs_filename);
-                               (void)closedir(dp);
-                               return -1;
-                       }
-
-                       if (S_ISDIR(stFileInfo.st_mode)) {
-                               if (strcmp(ep.d_name, ".")
-                                   && strcmp(ep.d_name, "..")) {
-                                       ret = _app2sd_delete_directory(abs_filename);
-                                       if (ret <0) {
-                                               (void)closedir(dp);
-                                               return -1;
-                                       }
-                               }
-                       } else {
-                               ret = remove(abs_filename);
-                               if (ret <0) {
-                                       (void)closedir(dp);
-                                       return -1;
-                               }
-                       }
-               }
-               (void)closedir(dp);
-               ret = remove(dirname);
-               if (ret <0)
-                       return -1;
-       } else {
-               _W("couldn't open the directory[%s]", dirname);
-       }
-       return 0;
-}
-
 void _app2sd_delete_symlink(const char *dirname)
 {
        int ret = 0;
@@ -203,18 +154,16 @@ void _app2sd_delete_symlink(const char *dirname)
                        /*get realpath find symlink to ".mmc" and unlink it*/
                        snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname, ep.d_name);
                        char *path = realpath(abs_filename, mmc_path);
-                       if(!path){
+                       if (!path)
                                _E("realpath failed");
-                       }
 
-                       if (strstr(mmc_path,".mmc")) {
+                       if (strstr(mmc_path, ".mmc")) {
                                _E("force unlink [%s]", abs_filename);
                                if (unlink(abs_filename)) {
-                                       if (errno == ENOENT) {
+                                       if (errno == ENOENT)
                                                _E("Unable to access file %s", abs_filename);
-                                       } else {
+                                       else
                                                _E("Unable to delete %s", abs_filename);
-                                       }
                                }
                        }
 
@@ -224,9 +173,8 @@ void _app2sd_delete_symlink(const char *dirname)
                /*delete ".mmc" folder*/
                snprintf(abs_filename, FILENAME_MAX, "%s/.mmc", dirname);
                ret = remove(abs_filename);
-               if (ret == -1) {
+               if (ret == -1)
                        return;
-               }
        } else {
                _E("couldn't open the directory[%s]", dirname);
        }
@@ -314,14 +262,14 @@ char *_app2sd_encrypt_device(const char *device,
        const char *loopback_device, char *passwd)
 {
        /* TODO : change to dm-crypt */
-       const char *argv[] =
-           { "/sbin/losetup", device, loopback_device, NULL };
+       const char *argv[] = { "/sbin/losetup", device,
+               loopback_device, NULL };
        pid_t pid = 0;
        int my_pipe[2] = { 0, };
        char buf[FILENAME_MAX] = { 0, };
        char *ret_result = NULL;
        int result = 0;
-       char err_buf[1024] = {0,};
+       char err_buf[1024] = { 0,};
 
        if (pipe(my_pipe) < 0) {
                fprintf(stderr, "Unable to create pipe\n");
@@ -515,11 +463,10 @@ char *_app2sd_find_associated_device(const char *loopback_device)
        while (line) {
                if (strstr(line, loopback_device) != NULL) {
                        _D("found: (%s)", line);
-                       if (ret_result) {
+                       if (ret_result)
                                _D("duplicated device");
-                       } else {
+                       else
                                ret_result = strdup(line);
-                       }
                }
                line = strtok_r(NULL, "\n", &save_str);
        }
@@ -594,7 +541,7 @@ char *_app2sd_find_free_device(void)
        return ret_result;
 }
 
-/*@_app2sd_generate_password
+/*
 * This is a simple password generator
 * return: On success, it will return the password, else NULL.
 */
@@ -612,8 +559,8 @@ char *_app2sd_generate_password(const char *pkgid)
        int j = appname_len;
        unsigned int seed;
 
-       /* Length of the password */
-       ret_result = (char*)malloc(PASSWD_LEN + 1);
+       /* length of the password */
+       ret_result = (char *)malloc(PASSWD_LEN + 1);
        if (NULL == ret_result) {
                _E("unable to allocate memory");
                return NULL;
index 2188e6f..0837b70 100644 (file)
@@ -100,9 +100,8 @@ static int __app2sd_get_sender_uid(GDBusConnection *conn,
 
        uid = __app2sd_get_sender_unixinfo(conn, sender_name,
                "GetConnectionUnixUser");
-       if (uid < 0) {
+       if (uid < 0)
                _E("failed to get uid");
-       }
 
        _D("sender_name(%s), uid(%d)", sender_name, uid);
 
@@ -171,6 +170,12 @@ static const gchar introspection_xml[] =
 "                      <arg type='i' name='uid' direction='in'/>"
 "                      <arg type='i' name='result' direction='out'/>"
 "              </method>"
+"              <method name='EnableFullPkg'>"
+"                      <arg type='i' name='result' direction='out'/>"
+"              </method>"
+"              <method name='DisableFullPkg'>"
+"                      <arg type='i' name='result' direction='out'/>"
+"              </method>"
 "      </interface>"
 "</node>";
 
@@ -568,7 +573,7 @@ static void _app2sd_server_move_installed_app(GDBusConnection *connection, const
        g_dbus_method_invocation_return_value(invocation, param);
 }
 
-static void _app2sd_server_ondemand_force_clean(GDBusConnection *connection, const gchar *sender,
+static void _app2sd_server_force_clean(GDBusConnection *connection, const gchar *sender,
        GVariant *parameters, GDBusMethodInvocation *invocation, uid_t sender_uid)
 {
        GVariant *param = NULL;
@@ -599,6 +604,58 @@ static void _app2sd_server_ondemand_force_clean(GDBusConnection *connection, con
        g_dbus_method_invocation_return_value(invocation, param);
 }
 
+static void _app2sd_server_enable_full_pkg(GDBusConnection *connection, const gchar *sender,
+       GVariant *parameters, GDBusMethodInvocation *invocation, uid_t sender_uid)
+{
+       GVariant *param = NULL;
+       int result = APP2EXT_SUCCESS;
+       int ret = 0;
+
+       _D("sender_uid(%d)", sender_uid);
+
+       if (sender_uid >= REGULAR_USER) {
+               _E("Not permitted user!");
+               _app2sd_server_return_method_error(invocation,
+                       APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
+               return;
+       }
+
+       ret = app2sd_enable_full_pkg();
+       if (ret) {
+               _E("error(%d)", ret);
+               result = ret;
+       }
+
+       param = g_variant_new("(i)", result);
+       g_dbus_method_invocation_return_value(invocation, param);
+}
+
+static void _app2sd_server_disable_full_pkg(GDBusConnection *connection, const gchar *sender,
+       GVariant *parameters, GDBusMethodInvocation *invocation, uid_t sender_uid)
+{
+       GVariant *param = NULL;
+       int result = APP2EXT_SUCCESS;
+       int ret = 0;
+
+       _D("sender_uid(%d)", sender_uid);
+
+       if (sender_uid >= REGULAR_USER) {
+               _E("Not permitted user!");
+               _app2sd_server_return_method_error(invocation,
+                       APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
+               return;
+       }
+
+       ret = app2sd_disable_full_pkg();
+       if (ret) {
+               _E("error(%d)", ret);
+               result = ret;
+       }
+
+       param = g_variant_new("(i)", result);
+       g_dbus_method_invocation_return_value(invocation, param);
+}
+
 static void handle_method_call(GDBusConnection *connection,
        const gchar *sender, const gchar *object_path,
        const gchar *interface_name, const gchar *method_name,
@@ -637,7 +694,13 @@ static void handle_method_call(GDBusConnection *connection,
                _app2sd_server_move_installed_app(connection, sender,
                        parameters, invocation, sender_uid);
        } else if (g_strcmp0(method_name, "ForceClean") == 0) {
-               _app2sd_server_ondemand_force_clean(connection, sender,
+               _app2sd_server_force_clean(connection, sender,
+                       parameters, invocation, sender_uid);
+       } else if (g_strcmp0(method_name, "EnableFullPkg") == 0) {
+               _app2sd_server_enable_full_pkg(connection, sender,
+                       parameters, invocation, sender_uid);
+       } else if (g_strcmp0(method_name, "DisableFullPkg") == 0) {
+               _app2sd_server_disable_full_pkg(connection, sender,
                        parameters, invocation, sender_uid);
        }
 
index e0301f3..89ec0cd 100644 (file)
@@ -45,7 +45,7 @@ app2ext_handle *app2ext_init(int storage_type)
                _E("invalid function arguments");
                return NULL;
        }
-       if (storage_type != APP2EXT_SD_CARD ) {
+       if (storage_type != APP2EXT_SD_CARD) {
                _E("storage type currently not supported");
                return NULL;
        }
@@ -91,7 +91,7 @@ app2ext_handle *app2ext_init(int storage_type)
 int app2ext_deinit(app2ext_handle *handle)
 {
        /* validate the function parameter recieved */
-       if (handle == NULL || handle->plugin_handle == NULL){
+       if (handle == NULL || handle->plugin_handle == NULL) {
                _E("invalid function arguments");
                return -1;
        }
@@ -133,9 +133,9 @@ int app2ext_usr_get_app_location(const char *pkgid, uid_t uid)
                tzplatform_reset_user();
        }
        encoded_id = _app2sd_get_encoded_name(pkgid, uid);
-       if (encoded_id == NULL) {
+       if (encoded_id == NULL)
                return -1;
-       }
+
        snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
                APP2SD_PATH, encoded_id);
        free(encoded_id);
@@ -185,7 +185,7 @@ int app2ext_get_app_location(const char *pkgid)
 int app2ext_usr_enable_external_pkg(const char *pkgid, uid_t uid)
 {
        FILE *fp = NULL;
-       app2ext_handle *app2_handle = NULL;
+       app2ext_handle *handle = NULL;
        char loopback_device[FILENAME_MAX] = { 0, };
        char *encoded_id = NULL;
 
@@ -196,9 +196,9 @@ int app2ext_usr_enable_external_pkg(const char *pkgid, uid_t uid)
        }
 
        encoded_id = _app2sd_get_encoded_name(pkgid, uid);
-       if (encoded_id == NULL) {
+       if (encoded_id == NULL)
                return -1;
-       }
+
        snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
                APP2SD_PATH, encoded_id);
        free(encoded_id);
@@ -209,14 +209,14 @@ int app2ext_usr_enable_external_pkg(const char *pkgid, uid_t uid)
                fclose(fp);
                fp = NULL;
 
-               app2_handle = app2ext_init(APP2EXT_SD_CARD);
-               if (app2_handle == NULL) {
+               handle = app2ext_init(APP2EXT_SD_CARD);
+               if (handle == NULL) {
                        _E("app2ext init failed");
                        return -1;
                }
 
-               app2_handle->interface.client_usr_enable(pkgid, uid);
-               app2ext_deinit(app2_handle);
+               handle->interface.client_usr_enable(pkgid, uid);
+               app2ext_deinit(handle);
        }
 
        return 0;
@@ -234,7 +234,7 @@ int app2ext_enable_external_pkg(const char *pkgid)
 int app2ext_usr_disable_external_pkg(const char *pkgid, uid_t uid)
 {
        FILE *fp = NULL;
-       app2ext_handle *app2_handle = NULL;
+       app2ext_handle *handle = NULL;
        char loopback_device[FILENAME_MAX] = { 0, };
        char *encoded_id = NULL;
 
@@ -245,9 +245,9 @@ int app2ext_usr_disable_external_pkg(const char *pkgid, uid_t uid)
        }
 
        encoded_id = _app2sd_get_encoded_name(pkgid, uid);
-       if (encoded_id == NULL) {
+       if (encoded_id == NULL)
                return -1;
-       }
+
        snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
                APP2SD_PATH, encoded_id);
        free(encoded_id);
@@ -258,14 +258,14 @@ int app2ext_usr_disable_external_pkg(const char *pkgid, uid_t uid)
                fclose(fp);
                fp = NULL;
 
-               app2_handle = app2ext_init(APP2EXT_SD_CARD);
-               if (app2_handle == NULL) {
+               handle = app2ext_init(APP2EXT_SD_CARD);
+               if (handle == NULL) {
                        _E("app2ext init failed");
                        return -1;
                }
 
-               app2_handle->interface.client_usr_disable(pkgid, uid);
-               app2ext_deinit(app2_handle);
+               handle->interface.client_usr_disable(pkgid, uid);
+               app2ext_deinit(handle);
        }
 
        return 0;
@@ -280,9 +280,55 @@ int app2ext_disable_external_pkg(const char *pkgid)
        return ret;
 }
 
+int app2ext_enable_external_full_pkg(void)
+{
+       int ret = 0;
+       app2ext_handle *handle = NULL;
+
+       if (getuid() >= REGULAR_USER)
+               return 0;
+
+       handle = app2ext_init(APP2EXT_SD_CARD);
+       if (handle == NULL) {
+               _E("app2ext init failed");
+               return -1;
+       }
+
+       ret = handle->interface.client_enable_full_pkg();
+       if (ret != 0)
+               _E("failed to enable entire pkgs");
+
+       app2ext_deinit(handle);
+
+       return 0;
+}
+
+int app2ext_disable_external_full_pkg(void)
+{
+       int ret = 0;
+       app2ext_handle *handle = NULL;
+
+       if (getuid() >= REGULAR_USER)
+               return 0;
+
+       handle = app2ext_init(APP2EXT_SD_CARD);
+       if (handle == NULL) {
+               _E("app2ext init failed");
+               return -1;
+       }
+
+       ret = handle->interface.client_disable_full_pkg();
+       if (ret != 0)
+               _E("failed to disable entire pkgs");
+
+       app2ext_deinit(handle);
+
+       return 0;
+}
+
 int app2ext_usr_force_clean_pkg(const char *pkgid, uid_t uid)
 {
-       app2ext_handle *app2_handle = NULL;
+       app2ext_handle *handle = NULL;
 
        /* validate the function parameter received */
        if (pkgid == NULL || uid < 0) {
@@ -290,14 +336,14 @@ int app2ext_usr_force_clean_pkg(const char *pkgid, uid_t uid)
                return -1;
        }
 
-       app2_handle = app2ext_init(APP2EXT_SD_CARD);
-       if (app2_handle == NULL) {
+       handle = app2ext_init(APP2EXT_SD_CARD);
+       if (handle == NULL) {
                _E("app2ext init failed");
                return -1;
        }
 
-       app2_handle->interface.client_usr_force_clean(pkgid, uid);
-       app2ext_deinit(app2_handle);
+       handle->interface.client_usr_force_clean(pkgid, uid);
+       app2ext_deinit(handle);
 
        return 0;
 }
index 3c1c6f5..b587cf5 100644 (file)
@@ -43,7 +43,7 @@ app2ext_handle *handle = NULL;
 
 char pkg_ro_content_rpm[3][5] = { "bin", "res", "lib" };
 
-#define COUNT_OF_ERROR_LIST 50
+#define COUNT_OF_ERROR_LIST 49
 char error_list[COUNT_OF_ERROR_LIST][100] = {
        "SUCCESS",
        "APP2EXT_ERROR_UNKNOWN",
@@ -68,7 +68,6 @@ char error_list[COUNT_OF_ERROR_LIST][100] = {
        "APP2EXT_ERROR_STRCMP_FAILED",
        "APP2EXT_ERROR_INVALID_PACKAGE",
        "APP2EXT_ERROR_CREATE_DIR_ENTRY",
-       "APP2EXT_ERROR_PASSWORD_GENERATION",
        "APP2EXT_ERROR_COPY_DIRECTORY",
        "APP2EXT_ERROR_INVALID_CASE",
        "APP2EXT_ERROR_SYMLINK_ALREADY_EXISTS",
@@ -133,6 +132,8 @@ static void usage(void)
        printf("<ENABLE(mount)/DISABLE(umount) TEST W/ Installed PKG>\n");
        printf("(at target_user)$test_app2ext --enable\n");
        printf("(at target_user)$test_app2ext --disable\n");
+       printf("(at target_user)$test_app2ext --enable-full\n");
+       printf("(at target_user)$test_app2ext --disable-full\n");
        printf("------------------------------------------------\n");
        printf("**************************************************\n");
        printf("\n");
@@ -148,12 +149,14 @@ static void usage(void)
 #define OPTVAL_GET_LOCATION            1007
 #define OPTVAL_ENABLE_APP              1008
 #define OPTVAL_DISABLE_APP             1009
-#define OPTVAL_USAGE                   1010
+#define OPTVAL_ENABLE_FULL             1010
+#define OPTVAL_DISABLE_FULL            1011
+#define OPTVAL_USAGE                   1012
 
 /* Supported options */
 const struct option long_opts[] = {
-        { "pre-install", 0, NULL, OPTVAL_PRE_INSTALL },
-        { "post-install", 0, NULL, OPTVAL_POST_INSTALL },
+       { "pre-install", 0, NULL, OPTVAL_PRE_INSTALL },
+       { "post-install", 0, NULL, OPTVAL_POST_INSTALL },
        { "pre-uninstall", 0, NULL, OPTVAL_PRE_UNINSTALL },
        { "post-uninstall", 0, NULL, OPTVAL_POST_UNINSTALL },
        { "pre-upgrade", 0, NULL, OPTVAL_PRE_UPGRADE },
@@ -162,30 +165,32 @@ const struct option long_opts[] = {
        { "getlocation", 0, NULL, OPTVAL_GET_LOCATION },
        { "enable", 0, NULL, OPTVAL_ENABLE_APP },
        { "disable", 0, NULL, OPTVAL_DISABLE_APP },
+       { "enable-full", 0, NULL, OPTVAL_ENABLE_FULL },
+       { "disable-full", 0, NULL, OPTVAL_DISABLE_FULL },
        { "help", 0, NULL, OPTVAL_USAGE },
        { "usage", 0, NULL, OPTVAL_USAGE },
        { 0, 0, 0, 0 }  /* sentinel */
 };
 
-void clear_dir_list(GListdir_list)
+void clear_dir_list(GList *dir_list)
 {
        GList *list = NULL;
-       app2ext_dir_detailsdir_detail = NULL;
+       app2ext_dir_details *dir_detail = NULL;
 
        if (dir_list) {
                list = g_list_first(dir_list);
                while (list) {
                        dir_detail = (app2ext_dir_details *)list->data;
-                       if (dir_detail && dir_detail->name) {
+                       if (dir_detail && dir_detail->name)
                                free(dir_detail->name);
-                       }
+
                        list = g_list_next(list);
                }
                g_list_free(dir_list);
        }
 }
 
-GList * populate_dir_details()
+GList *populate_dir_details()
 {
        GList *dir_list = NULL;
        GList *list = NULL;
@@ -193,13 +198,13 @@ GList * populate_dir_details()
        int i;
 
        for (i = 0; i < 3; i++) {
-               dir_detail = (app2ext_dir_details*)calloc(1, sizeof(app2ext_dir_details));
+               dir_detail = (app2ext_dir_details *)calloc(1, sizeof(app2ext_dir_details));
                if (dir_detail == NULL) {
                        printf("memory allocation failed\n");
                        goto FINISH_OFF;
                }
 
-               dir_detail->name = (char*)calloc(1, sizeof(char) * (strlen(pkg_ro_content_rpm[i]) + 2));
+               dir_detail->name = (char *)calloc(1, sizeof(char) * (strlen(pkg_ro_content_rpm[i]) + 2));
                if (dir_detail->name == NULL) {
                        printf("memory allocation failed\n");
                        free(dir_detail);
@@ -279,11 +284,10 @@ static int get_unzip_size(const char *item, unsigned long long *size)
 
 static void print_error_code(const char *func_name, int ret)
 {
-       if (ret < 0 || ret > COUNT_OF_ERROR_LIST - 1) {
+       if (ret < 0 || ret > COUNT_OF_ERROR_LIST - 1)
                printf("%s failed : unknown error(%d)\n", func_name, ret);
-       } else {
+       else
                printf("%s return(%s)\n", func_name, error_list[ret]);
-       }
 }
 
 static int pre_app_install()
@@ -303,9 +307,9 @@ static int pre_app_install()
 
        /* size : in MB */
        ret = get_unzip_size(TEST_PKGNAME_PATH, &size_byte);
-       if (ret < 0 || size_byte == 0) {
+       if (ret < 0 || size_byte == 0)
                printf("wrong pkg size, ret(%d), size_byte(%llu)\n", ret, size_byte);
-       }
+
        size_mega = size_byte / (1024 * 1024) + 1;
        printf("get pkg size : (%d)MB\n", size_mega);
 
@@ -349,6 +353,26 @@ static int app_disable()
        return ret;
 }
 
+static int fullpkg_enable()
+{
+       int ret = -1;
+
+       ret = handle->interface.client_enable_full_pkg();
+       print_error_code(__func__, ret);
+
+       return ret;
+}
+
+static int fullpkg_disable()
+{
+       int ret = -1;
+
+       ret = handle->interface.client_disable_full_pkg();
+       print_error_code(__func__, ret);
+
+       return ret;
+}
+
 static int pre_app_uninstall()
 {
        int ret = -1;
@@ -388,9 +412,9 @@ static int pre_app_upgrade()
 
        /* size : in MB */
        ret = get_unzip_size(TEST_PKGNAME_PATH, &size_byte);
-       if (ret < 0 || size_byte == 0) {
+       if (ret < 0 || size_byte == 0)
                printf("wrong pkg size, ret(%d), size_byte(%llu)\n", ret, size_byte);
-       }
+
        size_mega = size_byte / (1024 * 1024) + 1;
        printf("get pkg size : (%d)MB\n", size_mega);
 
@@ -464,13 +488,12 @@ static void app_get_location()
        int ret = -1;
 
        ret = app2ext_usr_get_app_location(TEST_PKGNAME, getuid());
-       if (ret == APP2EXT_SD_CARD) {
+       if (ret == APP2EXT_SD_CARD)
                printf("pkg is in sd card\n");
-       } else if (ret == APP2EXT_INTERNAL_MEM) {
+        else if (ret == APP2EXT_INTERNAL_MEM)
                printf("pkg is in internal memory\n");
-       } else {
+        else
                printf("pkg is not installed\n");
-       }
 }
 
 int main(int argc, char **argv)
@@ -536,6 +559,12 @@ int main(int argc, char **argv)
                case OPTVAL_DISABLE_APP:
                        app_disable();
                        break;
+               case OPTVAL_ENABLE_FULL:
+                       fullpkg_enable();
+                       break;
+               case OPTVAL_DISABLE_FULL:
+                       fullpkg_disable();
+                       break;
                case OPTVAL_USAGE:
                default:
                        usage();