sync with private master 42/17742/3
authorjunsuk77.oh <junsuk77.oh@samsung.com>
Thu, 10 Oct 2013 05:34:45 +0000 (14:34 +0900)
committerJiwoong Im <jiwoong.im@samsung.com>
Wed, 12 Mar 2014 01:01:09 +0000 (10:01 +0900)
Change-Id: I1ab8bff0a025b50163e7a8764447ad7b06f802fc
Signed-off-by: junsuk77.oh <junsuk77.oh@samsung.com>
inc/app2ext_interface.h
packaging/app2sd.spec
plugin/app2sd/src/app2sd_interface.c
plugin/app2sd/src/app2sd_internals.c
src/app2ext_interface.c

index 2d8ec43..2177ddc 100755 (executable)
@@ -432,6 +432,40 @@ if (ret < 0) {
  */
 API int app2ext_disable_external_pkg(const char *pkgid);
 
+/**
+ * @brief : This API enable the directory which has package that is located in external memory
+ * @return     error < 0  if pkg enable fail ,
+ @code
+ #include <app2ext_interface.h>
+int ret = -1;
+
+ret = app2ext_enable_external_dir();
+if (ret < 0) {
+       printf("\n app2sd dir is not enabled ");
+} else {
+       printf("\n app2sd dir is enabled ");
+}
+ @endcode
+ */
+API int app2ext_enable_external_dir(void);
+
+/**
+ * @brief : This API disable the directory which has package that is located in external memory
+ * @return     error < 0  if pkg enable fail ,
+ @code
+ #include <app2ext_interface.h>
+int ret = -1;
+
+ret = app2ext_enable_external_dir();
+if (ret < 0) {
+       printf("\n app2sd dir is not enabled ");
+} else {
+       printf("\n app2sd dir is enabled ");
+}
+ @endcode
+ */
+API int app2ext_disable_external_dir(void);
+
 #ifdef __cplusplus
 }
 #endif
index de04548..843b028 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       app2sd
 Summary:    Application installation on external memory
-Version:    0.5.23
+Version:    0.5.24
 Release:    1
 Group:      Application Framework/Application Installer
 License:    Apache-2.0
@@ -46,6 +46,7 @@ make %{?_smp_mflags}
 %{_libdir}/libapp2ext.so.*
 %{_libdir}/libapp2sd.so*
 
+
 %files devel
 %manifest %{name}.manifest
 %defattr(-,root,root,-)
index ee1c9ba..f1a356a 100755 (executable)
@@ -519,6 +519,7 @@ int app2sd_move_installed_app(const char *pkgid, GList* dir_list,
                        app2ext_move_type move_type)
 {
        int ret = 0;
+       int pkgmgrinfo_ret = 0;
 
        /*Validate function arguments*/
        if (pkgid == NULL || dir_list == NULL
@@ -529,6 +530,29 @@ int app2sd_move_installed_app(const char *pkgid, GList* dir_list,
                goto END;
        }
 
+       /*If  move is completed, then update installed storage to pkgmgr_parser db*/
+       pkgmgrinfo_pkginfo_h info_handle = NULL;
+       pkgmgrinfo_installed_storage storage = PMINFO_INTERNAL_STORAGE;
+       pkgmgrinfo_ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &info_handle);
+       if (pkgmgrinfo_ret < 0) {
+               app2ext_print("App2Sd Error : pkgmgrinfo_pkginfo_get_pkginfo[%s] fail.. \n", pkgid);
+       }
+       pkgmgrinfo_ret = pkgmgrinfo_pkginfo_get_installed_storage(info_handle, &storage);
+       if (pkgmgrinfo_ret < 0) {
+               app2ext_print("App2Sd Error : pkgmgrinfo_pkginfo_get_installed_storage[%s] fail.. \n", pkgid);
+       }
+
+       if ((move_type == APP2EXT_MOVE_TO_EXT && storage == PMINFO_EXTERNAL_STORAGE)
+               || (move_type == APP2EXT_MOVE_TO_PHONE && storage == PMINFO_INTERNAL_STORAGE)) {
+                       ret = APP2EXT_ERROR_PKG_EXISTS;
+                       app2ext_print("App2Sd Error : PKG_EXISTS in [%d]STORAGE\n", storage);
+                       pkgmgrinfo_pkginfo_destroy_pkginfo(info_handle);
+                       goto END;
+       } else {
+               app2ext_print("App2Sd Error : okokkokin [%d]STORAGE\n", storage);
+       }
+       pkgmgrinfo_pkginfo_destroy_pkginfo(info_handle);
+
        ret = _app2sd_move_app(pkgid, move_type, dir_list);
        if (ret) {
                app2ext_print("App2Sd Error : Unable to move application\n");
@@ -536,30 +560,29 @@ int app2sd_move_installed_app(const char *pkgid, GList* dir_list,
        }
 
        /*If  move is completed, then update installed storage to pkgmgr_parser db*/
-       int rt = 0;
        pkgmgrinfo_pkgdbinfo_h handle = NULL;
-       rt = pkgmgrinfo_create_pkgdbinfo(pkgid, &handle);
-       if (rt < 0) {
+       pkgmgrinfo_ret = pkgmgrinfo_create_pkgdbinfo(pkgid, &handle);
+       if (pkgmgrinfo_ret < 0) {
                app2ext_print("App2Sd Error : pkgmgrinfo_create_pkgdbinfo[%s] fail.. \n", pkgid);
        }
 
        if (move_type == APP2EXT_MOVE_TO_EXT) {
-               rt = pkgmgrinfo_set_installed_storage_to_pkgdbinfo(handle, INSTALL_EXTERNAL);
-               if (rt < 0) {
+               pkgmgrinfo_ret = pkgmgrinfo_set_installed_storage_to_pkgdbinfo(handle, INSTALL_EXTERNAL);
+               if (pkgmgrinfo_ret < 0) {
                        app2ext_print("App2Sd Error : fail to update installed location to db[%s, %s]\n", pkgid, INSTALL_EXTERNAL);
                }
        } else {
-               rt = pkgmgrinfo_set_installed_storage_to_pkgdbinfo(handle, INSTALL_INTERNAL);
-               if (rt < 0) {
+               pkgmgrinfo_ret = pkgmgrinfo_set_installed_storage_to_pkgdbinfo(handle, INSTALL_INTERNAL);
+               if (pkgmgrinfo_ret < 0) {
                        app2ext_print("App2Sd Error : fail to update installed location to db[%s, %s]\n", pkgid, INSTALL_INTERNAL);
                }
        }
-       rt =pkgmgrinfo_save_pkgdbinfo(handle);
-       if (rt < 0) {
+       pkgmgrinfo_ret =pkgmgrinfo_save_pkgdbinfo(handle);
+       if (pkgmgrinfo_ret < 0) {
                app2ext_print("pkgmgrinfo_save_pkgdbinfo[%s] failed\n", pkgid);
        }
-       rt =pkgmgrinfo_destroy_pkgdbinfo(handle);
-       if (rt < 0) {
+       pkgmgrinfo_ret =pkgmgrinfo_destroy_pkgdbinfo(handle);
+       if (pkgmgrinfo_ret < 0) {
                app2ext_print("pkgmgrinfo_destroy_pkgdbinfo failed\n");
        }
 
index d9edb4d..663c489 100755 (executable)
@@ -705,18 +705,11 @@ int _app2sd_move_app_to_external(const char *pkgid, GList* dir_list)
        /*check whether application is in external memory or not */
        fp = fopen(mmc_path, "r+");
        if (fp != NULL) {
-               const char *argv[] = { "/bin/rm", "-rf", mmc_path, NULL };
                app2ext_print
                    ("Already %s entry is present in the SD Card, delete entry and go on without return\n",
                     pkgid);
                fclose(fp);
 //             return APP2EXT_ERROR_ALREADY_FILE_PRESENT;
-               ret = _xsystem(argv);
-               if (ret) {
-                       app2ext_print
-                               ("delete fail[%s]\n",
-                               mmc_path);
-               }
        }
 
        snprintf(app_mmc_path, FILENAME_MAX,
@@ -730,7 +723,7 @@ int _app2sd_move_app_to_external(const char *pkgid, GList* dir_list)
                        app2ext_print
                            ("App2sd Error: Unable to create directory for archiving, error no is %d\n",
                             errno);
-                       return APP2EXT_ERROR_CREATE_DIRECTORY;
+//                     return APP2EXT_ERROR_CREATE_DIRECTORY;
                }
        }
 
@@ -777,7 +770,7 @@ int _app2sd_move_app_to_external(const char *pkgid, GList* dir_list)
        if (ret) {
                app2ext_print
                    ("App2Sd Error : loopback node creation failed\n");
-               return APP2EXT_ERROR_CREATE_DEVICE;
+//             return APP2EXT_ERROR_CREATE_DEVICE;
        }
        /*Perform Loopback encryption setup */
        device_node =
@@ -829,8 +822,7 @@ int _app2sd_move_app_to_external(const char *pkgid, GList* dir_list)
                                            ("App2Sd Error : unable to copy from %s to %s \n",
                                             path,
                                             app_archive_path);
-                                       return
-                                           APP2EXT_ERROR_MOVE;
+//                                     return APP2EXT_ERROR_MOVE;
                                }
                        }
                }
@@ -874,8 +866,7 @@ int _app2sd_move_app_to_external(const char *pkgid, GList* dir_list)
                                             app_mmc_path,
                                             strerror
                                             (errno));
-                                       return
-                                           APP2EXT_ERROR_MOVE;
+//                                     return APP2EXT_ERROR_MOVE;
                                }
                        }
                        ret =
@@ -903,7 +894,7 @@ int _app2sd_move_app_to_external(const char *pkgid, GList* dir_list)
                app2ext_print
                    ("App2Sd Error : unable to delete %s \n",
                     app_archive_path);
-               return APP2EXT_ERROR_DELETE_DIRECTORY;
+//             return APP2EXT_ERROR_DELETE_DIRECTORY;
        }
 
        ret = _app2sd_apply_mmc_smack(pkgid, dir_list, pkgid);
@@ -1017,7 +1008,7 @@ int _app2sd_move_app_to_internal(const char *pkgid, GList* dir_list)
                app2ext_print
                    ("App2Sd Error : unable to create directory%s\n",
                     app_archive_path);
-               return APP2EXT_ERROR_CREATE_DIRECTORY;
+//             return APP2EXT_ERROR_CREATE_DIRECTORY;
        }
 
 
@@ -1049,8 +1040,7 @@ int _app2sd_move_app_to_internal(const char *pkgid, GList* dir_list)
                                                     app_archive_path,
                                                     strerror
                                                     (errno));
-                                               return
-                                                   APP2EXT_ERROR_MOVE;
+//                                             return APP2EXT_ERROR_MOVE;
                                        }
                                }
 
@@ -1069,10 +1059,9 @@ int _app2sd_move_app_to_internal(const char *pkgid, GList* dir_list)
                                                     path);
                                        } else {
                                                app2ext_print
-                                                   ("App2Sd Error : unable to remove the symbolic link file %s\n",
+                                                   ("App2Sd Error : unable to remove the symbolic link file %s, it is already unlinked!!!\n",
                                                     path);
-                                               return
-                                                   APP2EXT_ERROR_DELETE_LINK_FILE;
+//                                             return APP2EXT_ERROR_DELETE_LINK_FILE;
                                        }
                                }
 
@@ -1098,8 +1087,7 @@ int _app2sd_move_app_to_internal(const char *pkgid, GList* dir_list)
                                                     app_path,
                                                     strerror
                                                     (errno));
-                                               return
-                                                   APP2EXT_ERROR_MOVE;
+//                                             return APP2EXT_ERROR_MOVE;
                                        }
                                }
                }
@@ -1133,14 +1121,14 @@ int _app2sd_move_app_to_internal(const char *pkgid, GList* dir_list)
                app2ext_print
                    ("App2Sd Error : unable to delete %s \n",
                     app_mmc_path);
-               return APP2EXT_ERROR_DELETE_DIRECTORY;
+//             return APP2EXT_ERROR_DELETE_DIRECTORY;
        }
        ret = _app2sd_delete_directory(app_archive_path);
        if (ret) {
                app2ext_print
                    ("App2Sd Error : unable to delete %s \n",
                     app_archive_path);
-               return APP2EXT_ERROR_DELETE_DIRECTORY;
+//             return APP2EXT_ERROR_DELETE_DIRECTORY;
        }
 
        ret = _app2sd_apply_app_smack(pkgid, dir_list, pkgid);
index 24fa434..e075417 100755 (executable)
@@ -27,6 +27,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <dirent.h>
 
 #define APP2EXT_SD_PLUGIN_PATH LIBPREFIX "/libapp2sd.so"
 
@@ -205,3 +206,51 @@ int app2ext_disable_external_pkg(const char *pkgid)
        }
        return 0;
 }
+
+int app2ext_enable_external_dir(void)
+{
+       int ret = 0;
+       DIR *dir = NULL;
+       char buf[FILENAME_MAX] = { 0, };
+       struct dirent entry, *result;
+
+       dir = opendir(APP2SD_PATH);
+       if (!dir) {
+               if (strerror_r(errno, buf, sizeof(buf)) == 0)
+                       app2ext_print("App2Ext Error :Failed to access the because %s", buf);
+               return -1;
+       }
+
+       for (ret = readdir_r(dir, &entry, &result); ret == 0 && result != NULL; ret = readdir_r(dir, &entry, &result)) {
+               ret = app2ext_enable_external_pkg(entry.d_name);
+               if (ret != 0)
+                       app2ext_print("App2Ext Error : fail enable pkg[%s]\n", entry.d_name);
+       }
+
+       closedir(dir);
+       return 0;
+}
+
+int app2ext_disable_external_dir(void)
+{
+       int ret = 0;
+       DIR *dir = NULL;
+       char buf[FILENAME_MAX] = { 0, };
+       struct dirent entry, *result;
+
+       dir = opendir(APP2SD_PATH);
+       if (!dir) {
+               if (strerror_r(errno, buf, sizeof(buf)) == 0)
+                       app2ext_print("App2Ext Error :Failed to access the because %s", buf);
+               return -1;
+       }
+
+       for (ret = readdir_r(dir, &entry, &result); ret == 0 && result != NULL; ret = readdir_r(dir, &entry, &result)) {
+               ret = app2ext_disable_external_pkg(entry.d_name);
+               if (ret != 0)
+                       app2ext_print("App2Ext Error : fail disable pkg[%s]\n", entry.d_name);
+       }
+
+       closedir(dir);
+       return 0;
+}