test_app2ext usage has been changed.
now, all the test can be tried to.
install example)
pre-condition: prepare /tmp/org.example.basicuiapplication-1.0.0-arm.tpk
1. (tizenglobalapp)$test_app2ext --pre-install
2. (tizenglobalapp)$pkgcmd -it tpk -p {pkg_path}
3. (tizenglobalapp)$test_app2ext --post-install
4. (tizenglobalapp)$test_app2ext --enable (mount external part)
5. (tizenglobalapp)$test_app2ext --disable (unmount external part)
Change-Id: I8d4d3c07f4632228d7cb15c015012c095a365c4d
Signed-off-by: jongmyeongko <jongmyeong.ko@samsung.com>
#Add your submodule directory name
ADD_SUBDIRECTORY(plugin/app2sd)
+
### Required packages
INCLUDE(FindPkgConfig)
pkg_check_modules(pkgs REQUIRED dlog)
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
ENDFOREACH(flag)
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
### Local include directories
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/inc ${CMAKE_SOURCE_DIR}/src)
<manifest>
- <request>
- <domain name="_"/>
- </request>
+ <request>
+ <domain name="_"/>
+ </request>
</manifest>
Name: app2sd
Description: The app2sd Library
Version: 1.1.0
-Requires: vconf dlog libtzplatform-config
+Requires:
Cflags: -I${includedir}
Libs: -L${libdir} -lapp2sd -lapp2ext
+++ /dev/null
-/*
- * app2ext
- *
- * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jyotsna Dhumale <jyotsna.a@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-/**
- *
- * @ingroup SLP_PG
- * @defgroup app2ext_PG App2Ext
- * @{
-
-<h1 class="pg">Introduction</h1>
-App2Ext is a feature that enables package installers to install applications on external storage like SD card, Micro USB flash drive or Cloud.
-It also provides option to move installed applications from external memory to internal memory and vice versa.
-
-<h1 class="pg">App2Ext process view</h1>
-\image html app2ext_diag.png "Picture 1. App2Ext Process View Diagram"
-\image rtf app2ext_diag.png "Picture 1. App2Ext Process View Diagram"
-
-<h1 class="pg">Installation to SD Card</h1>
-Package installer should call the App2Ext's Init API to initialize SD plug-in. Once the plug-in initialization is done App2Ext returns a storage handle to the Package installer. Package installer should then call the pre-install setup API with respect to the storage handle which will be mapped to app2sd's pre-install API. The App2Ext Pre-install API performs the setup required for the installation based on the external storage type.
-After pre-install setup is done Package installer can proceed with the installation of the application. When package installation is completed by the package installer, post-install setup API should be called. This API removes the setup created for installation during pre-install API.
-
-Refer to Picture 2. for flow diagram.
-
-<h1 class="pg">Installation Setup Flow for App2SD plug-in</h1>
-\image html app2ext_install_diag.png "Picture 2. Installation on SD card Flow Diagram"
-\image rtf app2ext_install_diag.png "Picture 2. Installation on SD card Flow Diagram"
-
-<h1 class="pg">Un-installation from SD Card</h1>
-Package installer should call the App2Ext's Init API to initialize SD plug-in. Once the plug-in initialization is done App2Ext returns a storage handle to the Package installer. Package installer should then call the pre-uninstall setup API with respect to the storage handle which will be mapped to app2sd's pre-uninstall API. Pre-uninstall API performs the setup required for the package un-installation based on the external storage type.
-After pre-uninstall setup is done Package installer can proceed with un-installation of the package. When package un-installation is completed by the package installer, post-uninstall setup API should be called. This API removes the setup created for un-installation during pre-uninstall API.
-
-Refer to Picture 3. for flow diagram.
-
-<h1 class="pg">Un-installation Setup Flow for App2SD plug-in</h1>
-\image html app2ext_uninstall_diag.png "Picture 3. Un-installation from SD card Flow Diagram"
-\image rtf app2ext_uninstall_diag.png "Picture 3. Un-installation from SD card Flow Diagram"
-
-
-<h1 class="pg">API list and description</h1>
-<ul>
- <li>app2ext_init() : Initialize plug-in based on storage type </li>
- <li>app2ext_deinit() : De-initialize plug-in</li>
- <li>app2ext_get_app_location() : Returns application current location</li>
-</ul>
-
- * @}
- */
#include <dlog/dlog.h>
#include <glib.h>
-/* For multi-user support */
+/* for multi-user support */
#include <tzplatform_config.h>
#ifdef LOG_TAG
#define LOG_TAG "APP2EXT"
-#ifdef _DEBUG_MODE_
-#define app2ext_print(fmt, arg...) LOGD(fmt,##arg)
-#else
-#define app2ext_print(FMT, ARG...) SLOGD(FMT,##ARG);
-#endif
+#define _E(fmt, arg...) LOGE(fmt, ##arg)
+#define _D(fmt, arg...) LOGD(fmt, ##arg)
+#define _W(fmt, arg...) LOGW(fmt, ##arg)
+#define _I(fmt, arg...) LOGI(fmt, ##arg)
#define APP2EXT_SUCCESS 0
-#define MMC_PATH tzplatform_mkpath(TZ_SYS_MEDIA, "sdcard")
-#define APP2SD_PATH tzplatform_mkpath(TZ_SYS_MEDIA, "sdcard/app2sd/")
-/* user app */
-#define APP_INSTALLATION_USER_PATH tzplatform_mkpath(TZ_USER_APP, "/")
-/* gloabl app */
-#define APP_INSTALLATION_PATH tzplatform_mkpath(TZ_SYS_RW_APP, "/")
+
+#define OWNER_ROOT 0
+#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")
+
+#define APP2SD_BUS_NAME "org.tizen.app2sd"
+#define APP2SD_OBJECT_PATH "/org/tizen/app2sd"
+#define APP2SD_INTERFACE_NAME "org.tizen.app2sd"
/**
* Enum for application installation location
APP2EXT_ERROR_DETACH_LOOPBACK_DEVICE,
APP2EXT_ERROR_ALREADY_MOUNTED,
APP2EXT_ERROR_PLUGIN_INIT_FAILED,
- APP2EXT_ERROR_PLUGIN_DEINIT_FAILED
+ APP2EXT_ERROR_PLUGIN_DEINIT_FAILED,
+ APP2EXT_ERROR_DBUS_FAILED,
+ APP2EXT_ERROR_MEMORY_ALLOC_FAILED,
+ APP2EXT_ERROR_OPERATION_NOT_PERMITTED,
+ APP2EXT_ERROR_SAME_LOOPBACK_DEVICE_EXISTS,
+ APP2EXT_ERROR_PKGMGR_ERROR
} app2ext_error;
/**
* @param[in] size Size of the application
* @return 0 if success, error code(>0) if fail
*/
-typedef int (*app2ext_pre_install)(const char *appname, GList* dir_list, int size);
+typedef int (*app2ext_client_usr_pre_install)(const char *appname, GList* dir_list,
+ int size, uid_t uid);
+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
* APP2EXT_STATUS_FAILED]
* @return 0 if success, error code(>0) if fail
*/
-typedef int (*app2ext_post_install)(const char *appname, app2ext_status install_status);
+typedef int (*app2ext_client_usr_post_install)(const char *appname,
+ app2ext_status install_status, uid_t uid);
+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
* @param[in] size Size of the application
* @return 0 if success, error code(>0) if fail
*/
-typedef int (*app2ext_pre_upgrade)(const char *appname, GList* dir_list, int size);
+typedef int (*app2ext_client_usr_pre_upgrade)(const char *appname, GList* dir_list,
+ int size, uid_t uid);
+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
* APP2EXT_STATUS_FAILED]
* @return 0 if success, error code(>0) if fail
*/
-typedef int (*app2ext_post_upgrade)(const char *appname, app2ext_status upgrade_status);
+typedef int (*app2ext_client_usr_post_upgrade)(const char *appname,
+ app2ext_status upgrade_status, uid_t uid);
+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
* @param[in] appname application package name which is to be uninstalled
* @return 0 if success, error code(>0) if fail
*/
-typedef int (*app2ext_pre_uninstall)(const char *appname);
+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
* @param[in] appname application package name which is to be uninstalled
* @return 0 if success, error code(>0) if fail
*/
-typedef int (*app2ext_post_uninstall)(const char *appname);
+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
* [Enum: APP2EXT_MOVE_TO_EXT, APP2EXT_MOVE_TO_PHONE]
* @return 0 if success, error code(>0) if fail
*/
-typedef int (*app2ext_move)(const char *appname, GList* dir_list, app2ext_move_type move_type);
+typedef int (*app2ext_client_usr_move)(const char *appname, GList* dir_list,
+ app2ext_move_type move_type, uid_t uid);
+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
* @param[in] appname application package name which is to be enabled
* @return 0 if success, error code(>0) if fail
*/
-typedef int (*app2ext_enable)(const char *appname);
+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
* @param[in] appname application package name which is to be disabled
* @return 0 if success, error code(>0) if fail
*/
-typedef int (*app2ext_disable)(const char *appname);
+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
* @param[in] pkgid application package name which is to be uninstalled
* @return 0 if success, error code(>0) if fail
*/
-typedef int (*app2ext_force_clean)(const char *pkgid);
+typedef int (*app2ext_client_usr_force_clean)(const char *pkgid, uid_t uid);
+typedef int (*app2ext_client_force_clean)(const char *pkgid);
/**
* This structure defines the app2ext interfaces. Plugins have to implement these functions
*/
typedef struct app2ext_interface_t{
- app2ext_pre_install pre_install;
- app2ext_post_install post_install;
- app2ext_pre_upgrade pre_upgrade;
- app2ext_post_upgrade post_upgrade;
- app2ext_pre_uninstall pre_uninstall;
- app2ext_post_uninstall post_uninstall;
- app2ext_move move;
- app2ext_force_clean force_clean;
- app2ext_enable enable;
- app2ext_disable disable;
+ /* for library function */
+ app2ext_client_pre_install client_pre_install;
+ app2ext_client_post_install client_post_install;
+ app2ext_client_pre_upgrade client_pre_upgrade;
+ app2ext_client_post_upgrade client_post_upgrade;
+ app2ext_client_pre_uninstall client_pre_uninstall;
+ app2ext_client_post_uninstall client_post_uninstall;
+ app2ext_client_force_clean client_force_clean;
+ app2ext_client_enable client_enable;
+ app2ext_client_disable client_disable;
+ app2ext_client_move client_move;
+
+ app2ext_client_usr_pre_install client_usr_pre_install;
+ app2ext_client_usr_post_install client_usr_post_install;
+ app2ext_client_usr_pre_upgrade client_usr_pre_upgrade;
+ app2ext_client_usr_post_upgrade client_usr_post_upgrade;
+ app2ext_client_usr_pre_uninstall client_usr_pre_uninstall;
+ app2ext_client_usr_post_uninstall client_usr_post_uninstall;
+ app2ext_client_usr_force_clean client_usr_force_clean;
+ app2ext_client_usr_enable client_usr_enable;
+ app2ext_client_usr_disable client_usr_disable;
+ app2ext_client_usr_move client_usr_move;
} app2ext_interface;
/**
* This structure defines app2ext handle .Each storage type maps to a different plugin
- * type : storage type
- * plugin_handle : plugin handle
+ * type : storage type,
+ * plugin_handle : plugin handle, need to close dlopen handle
+ * interface : inteface with plugin library
*/
typedef struct {
app2ext_install_location type;
- void *plugin_handle;
+ void *plugin_handle;
app2ext_interface interface;
} app2ext_handle;
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
- * @param[in] appname name of the application
- * @return APP2EXT_SD_CARD if app is in SD card,
+ * @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 app is in internal memory
* error code(>0) if fail
*@remarks see app2ext_install_location for more details
- @code
- #include <app2ext_interface.h>
-int ret = -1;
-
-ret = app2ext_get_app_location("com.samsung.calculator");
-if (ret == APP2EXT_SD_CARD) {
- printf("\n app is in sd card ");
-} else if (ret == APP2EXT_INTERNAL_MEM) {
- printf("\n app is in internal memory ");
-} else {
- printf("\napp is not installed");
-}
- @endcode
*/
-API int app2ext_get_app_location(const char *appname);
+API int app2ext_get_app_location(const char *pkgid);
+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 ,
- @code
- #include <app2ext_interface.h>
-int ret = -1;
-
-ret = app2ext_enable_external_pkg("com.samsung.calculator");
-if (ret < 0) {
- printf("\n pkg is not enabled ");
-} else {
- printf("\n pkg is enabled ");
-}
- @endcode
*/
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 ,
- @code
- #include <app2ext_interface.h>
-int ret = -1;
-
-ret = app2ext_disable_external_pkg("com.samsung.calculator");
-if (ret < 0) {
- printf("\n pkg is not enabled ");
-} else {
- printf("\n pkg is enabled ");
-}
- @endcode
*/
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);
+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 ,
- @code
- #include <app2ext_interface.h>
-int ret = -1;
-
-ret = app2ext_force_clean_pkg("docomo6002");
-if (ret < 0) {
- printf("\n force_clean fail ");
-} else {
- printf("\n force_clean success");
-}
- @endcode
*/
API int app2ext_force_clean_pkg(const char *pkgid);
+API int app2ext_usr_force_clean_pkg(const char *pkgid, uid_t uid);
#ifdef __cplusplus
}
Source0: %{name}-%{version}.tar.gz
BuildRequires: pkgconfig(libssl)
-BuildRequires: pkgconfig(vconf)
BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(openssl)
BuildRequires: pkgconfig(db-util)
BuildRequires: pkgconfig(pkgmgr-info)
+BuildRequires: pkgconfig(minizip)
BuildRequires: pkgconfig(libtzplatform-config)
+BuildRequires: pkgconfig(gio-2.0)
+BuildRequires: pkgconfig(glib-2.0)
BuildRequires: cmake
%description
%defattr(-,root,root,-)
%{_libdir}/libapp2ext.so.*
%{_libdir}/libapp2sd.so*
+%{_bindir}/app2sd-server
+%{_datadir}/dbus-1/system-services/org.tizen.app2sd.service
+%config %{_sysconfdir}/dbus-1/system.d/org.tizen.app2sd.conf
/usr/share/license/%{name}
-
%files devel
%defattr(-,root,root,-)
%{_includedir}/app2ext_interface.h
### Required packages
INCLUDE(FindPkgConfig)
-pkg_check_modules(pkgs REQUIRED libssl dlog openssl db-util pkgmgr-info vconf libtzplatform-config)
+pkg_check_modules(pkgs REQUIRED libssl dlog openssl pkgmgr-info libtzplatform-config gio-2.0 glib-2.0 minizip)
FOREACH(flag ${pkgs_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
ENDFOREACH(flag)
-pkg_check_modules(libpkgs REQUIRED libssl dlog openssl db-util pkgmgr-info vconf)
+pkg_check_modules(libpkgs REQUIRED libssl dlog openssl pkgmgr-info db-util gio-2.0 glib-2.0 minizip)
FOREACH(flag ${libpkgs_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
ENDFOREACH(flag)
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wno-unused-result")
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
### Local include directories
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/inc ${CMAKE_SOURCE_DIR}/src)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/inc
+ ${CMAKE_SOURCE_DIR}/src)
-## build app2sd library
SET(app2sd_dir "${CMAKE_SOURCE_DIR}/plugin/app2sd")
SET(app2sd_inc_dir "${app2sd_dir}/inc")
SET(app2sd_src_dir "${app2sd_dir}/src")
+
+## build app2sd library
SET(APP2SD "app2sd")
-SET(libapp2sd_SOURCES ${app2sd_src_dir}/app2sd_internals.c ${app2sd_src_dir}/app2sd_interface.c ${app2sd_src_dir}/app2sd_internals_registry.c ${app2sd_src_dir}/app2sd_internals_utils.c)
+SET(libapp2sd_SOURCES
+ ${app2sd_src_dir}/app2sd_client_interface.c)
SET(libapp2sd_LDFLAGS " -L${LIB_INSTALL_DIR} -lcrypto -module -avoid-version ")
SET(libapp2sd_CFLAGS " ${CFLAGS} -fPIC -I${app2sd_inc_dir} ")
SET_TARGET_PROPERTIES(${APP2SD} PROPERTIES COMPILE_FLAGS "${libapp2sd_CFLAGS}")
TARGET_LINK_LIBRARIES(${APP2SD} ${libpkgs_LDFLAGS} "-lm")
+## devel package
+
SET(CMAKE_INSTALL_PREFIX "/usr")
SET(PREFIX ${CMAKE_INSTALL_PREFIX})
-
INSTALL(TARGETS ${APP2SD} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries)
+## build app2sd-server binary
+SET(APP2SD_SERVER "app2sd-server")
+SET(app2sd_server_SOURCES
+ ${app2sd_src_dir}/app2sd_internals.c
+ ${app2sd_src_dir}/app2sd_interface.c
+ ${app2sd_src_dir}/app2sd_internals_registry.c
+ ${app2sd_src_dir}/app2sd_internals_utils.c
+ ${app2sd_src_dir}/app2sd_server.c)
+ADD_EXECUTABLE(${APP2SD_SERVER} ${app2sd_server_SOURCES})
+SET_TARGET_PROPERTIES(${APP2SD_SERVER} PROPERTIES COMPILE_FLAGS ${CFLAGS} "-fPIE -I${app2sd_inc_dir} ")
+SET_TARGET_PROPERTIES(${APP2SD_SERVER} PROPERTIES LINK_FLAGS "-pie")
+TARGET_LINK_LIBRARIES(${APP2SD_SERVER} app2sd ${pkgs_LDFLAGS})
+
+CONFIGURE_FILE(org.tizen.app2sd.service.in org.tizen.app2sd.service @ONLY)
+CONFIGURE_FILE(org.tizen.app2sd.conf.in org.tizen.app2sd.conf @ONLY)
+INSTALL(TARGETS ${APP2SD_SERVER} DESTINATION bin)
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.tizen.app2sd.service DESTINATION
+ ${PREFIX}/share/dbus-1/system-services/)
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.tizen.app2sd.conf DESTINATION
+ ${SYSCONF_INSTALL_DIR}/dbus-1/system.d/)
+++ /dev/null
-/*
- * app2sd
- *
- * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Garima Shrivastava<garima.s@samsung.com>
- * Jyotsna Dhumale <jyotsna.a@samsung.com>
- * Venkatesha Sarpangala <sarpangala.v@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-/**
- *
- * @ingroup SLP_PG
- * @defgroup app2sd_PG App2sd
- * @{
-
-<h1 class="pg">Introduction</h1>
-App2sd is a feature that enables package installers to install applications on sdcard.
-It also provides API to move installed applications from sd card to internal memory and vice versa.
-App2sd provides an API for validating the integrity of the package before launching by the launchpad.
-
-<h1 class="pg">App2sd process view</h1>
-\image html app2sd_diag.png "Picture 1. Process View Diagram"
-\image rtf app2sd_diag.png "Picture 1. Process View Diagram"
-
-<h1 class="pg">Installation to SD Card</h1>
-Package installer should call the App2sd pre-install setup API before installation.
-This API creates directory structure in SD card.
-Refer to Picture 2. for flow diagram.
-
-<h1 class="pg">App2sd Installation Setup Flow</h1>
-\image html app2sd_install_diag.png "Picture 2. Installation Flow Diagram"
-\image rtf app2sd_install_diag.png "Picture 2. Installation Flow Diagram"
-
-<h1 class="pg">Uninstallation to SD Card</h1>
-Package installer should call the App2sd pre-uninstall setup API before uninstallation.
-Once the uninstallation is done by the package installer
-then App2sd post-uninstall setup API should be called.
-This API will clean up the directory structure and remove password from sqlite db.
-Refer to Picture 3. for flow diagram.
-<h1 class="pg">App2sd Uninstallation Setup Flow</h1>
-\image html app2sd_uninstall_diag.png "Picture 3. Uninstallation Flow Diagram"
-\image rtf app2sd_uninstall_diag.png "Picture 3. Uninstallation Flow Diagram"
-
-<h1 class="pg">API list and description</h1>
-<ul>
- <li>app2sd_pre_app_install() : Pre app installation setup.</li>
- <li>app2sd_post_app_install() : Post app installation setup.</li>
- <li>app2sd_pre_app_upgrade() : Pre app upgrade setup.</li>
- <li>app2sd_post_app_upgrade() : Post app upgarde setup.</li>
- <li>app2sd_pre_app_uninstall() : Pre app uninstall setup.</li>
- <li>app2sd_post_app_uninstall() : Post app uninstall setup.</li>
- <li>app2sd_move_installed_app() : Move installed application to/from sdcard</li>
- <li>app2sd_get_app_install_location() : Get application installation location[external\internal memory].</li>
- <li>app2sd_on_demand_setup_init() : Enables the application installed in sdcard.</li>
- <li>app2sd_on_demand_setup_exit() : Disables the application installed in sdcard.</li>
- <li></li>
-</ul>
-
- * @}
- */
--- /dev/null
+/*
+ * app2ext
+ *
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Garima Shrivastava<garima.s@samsung.com>
+ * Jyotsna Dhumale <jyotsna.a@samsung.com>
+ * Venkatesha Sarpangala <sarpangala.v@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __APPTOSD_INTERFACE_H__
+#define __APPTOSD_INTERFACE_H__
+
+/**
+ * @file app2sd_client_interface.h
+ * @version 0.2
+ * @brief This file declares API of app2sd library
+ */
+/**
+ * @addtogroup APPLICATION_FRAMEWORK
+ * @{
+ *
+ * @defgroup app2sd
+ * @version 0.2
+ *
+ * @section Header to use them:
+ * @code
+ * #include <app2sd_client_interface.h>
+ * @endcode
+ *
+ * @addtogroup app2sd
+ * @{
+ */
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <app2ext_interface.h>
+
+/**
+ * @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
+ * @param[in] appname application package name
+ * [Ex: com.samsung.calculator]
+ *This entry is parsed from application package control/manifest file.
+ * @param[in] dir_list directory structure of the application
+ * @param[in] size size of memory required by application(in MB).
+ *This entry is parsed from application package control/manifest file.
+ * @return 0 if success, error code(>0) if fail
+ * @remark None.
+ */
+int app2sd_client_usr_pre_app_install(const char *pkgid,
+ GList* dir_list, int size, uid_t uid);
+int app2sd_client_pre_app_install(const char *pkgid,
+ GList* dir_list, int size);
+
+/**
+ * @brief : This API does post installation operations after
+ * the installation in SD card
+ * @param[in] appname application package name
+ * [Ex: com.samsung.calculator]
+ * @param[in] install_status Status of installation of package
+ *[ enum app2ext_status].If package installation failed then
+ * install_status= APP2EXT_STATUS_FAILURE else if installation
+ * was successful then install_status = APP2EXT_ISTATUS_SUCCESS.
+ * @pre Installation should be done by package installer.
+ * @return 0 if success, error code(>0) if fail
+ * @remark @see enum app2sd_install_status
+ */
+int app2sd_client_usr_post_app_install(const char *pkgid,
+ app2ext_status install_status, uid_t uid);
+int app2sd_client_post_app_install(const char *pkgid,
+ app2ext_status install_status);
+
+/**
+ * @brief : This API prepares the setup for upgradation of
+ * application package
+ * @pre vfat type sd card must be present.
+ * @post Upgradation is done by package installer.
+ * @param[in] appname application package name
+ * [Ex: com.samsung.calculator]
+ * @param[in] dir_list directory structure of the application
+ * @param[in] size size of memory required by application(in MB).
+ *This entry is parsed from application package control/manifest file.
+ * @return 0 if success, error code(>0) if fail
+ * @remark None.
+ */
+int app2sd_client_usr_pre_app_upgrade(const char *pkgid,
+ GList* dir_list, int size, uid_t uid);
+int app2sd_client_pre_app_upgrade(const char *pkgid,
+ GList* dir_list, int size);
+
+/**
+ * @brief : This API does post upgradation operations after
+ * the installation in SD card
+ * @param[in] appname application package name
+ * [Ex: com.samsung.calculator]
+ * @param[in] install_status Status of installation of package
+ *[ enum app2extl_status].If package upgradation failed then
+ * upgrade_status= APP2EXT_STATUS_FAILURE else if upgradation
+ * was successful then upgrade_status = APP2EXT_STATUS_SUCCESS.
+ * @pre Upgradation should be done by package installer.
+ * @return 0 if success, error code(>0) if fail
+ * @remark @see enum app2ext_status
+ */
+int app2sd_client_usr_post_app_upgrade(const char *pkgid,
+ app2ext_status upgrade_status, uid_t uid);
+int app2sd_client_post_app_upgrade(const char *pkgid,
+ app2ext_status upgrade_status);
+/**
+ * @brief: This API prepares the setup for uninstallation
+ * @pre Package must be installed in sdcard.
+ * @post Package is uninstalled by the package installer.
+ * @param[in] appname application package name
+ * [Ex: com.samsung.calculator]
+ * @return 0 if success, error code(>0) if fail
+ * @remark None.
+ */
+int app2sd_client_usr_pre_app_uninstall(const char *pkgid, uid_t uid);
+int app2sd_client_pre_app_uninstall(const char *pkgid);
+
+/**
+ * @brief This API removes the resources created during
+ app2sd setup.It is called after uninstallation.
+ * @pre Package must be uninstalled .
+ * @post Encryption password is removed from sqlite db.
+ * @param[in] appname application package name
+ * [Ex: com.samsung.calculator]
+ * @return 0 if success, error code(>0) if fail
+ * @remark None.
+ */
+int app2sd_client_usr_post_app_uninstall(const char *pkgid, uid_t uid);
+int app2sd_client_post_app_uninstall(const char *pkgid);
+
+/**
+ * @brief : This API moves the package from sd card
+ to internal memory and vice versa.
+ * @param[in] pkgid application package id
+ * [Ex: com.samsung.calculator]
+ * @param[in] move_type Move type[enum app2ext_move_type]
+ * [sd card to internal/internal to sd card]
+ * @param[in] dir_list directory structure of the application
+ * @pre Package must be installed and its installation
+ * location should be known. Use dedicated API to get installation location.
+ * @post Package is moved to new location.
+ * @return 0 if success, error code(>0) if fail
+ * @remark None.
+ */
+int app2sd_client_usr_move_installed_app(const char *pkgid,
+ GList* dir_list, app2ext_move_type move_type, uid_t uid);
+int app2sd_client_move_installed_app(const char *pkgid,
+ GList* dir_list, app2ext_move_type move_type);
+
+/**
+ * @brief : This API Enables the application in sd card
+ for use. This API should be called by AUL.
+ * @param[in] pkgid application package id
+* [Ex: com.samsung.calculator]
+ * @pre Package must be installed
+ * @post application is enabled in SD card.
+ * @return 0 if success, error code(>0) if fail
+ * @remark None.
+ */
+int app2sd_client_usr_on_demand_setup_init(const char *pkgid, uid_t uid);
+int app2sd_client_on_demand_setup_init(const char *pkgid);
+
+/**
+ * @brief : This API Disables the application in sd card
+ . This API should be called by Launchpad callback which will be registered
+ during app launch for exit action of the application
+ * @param[in] pkgid application package id
+* [Ex: com.samsung.calculator]
+ * @pre Package must be installed and enabled
+ * and application must be running in SD card
+ * @post application is disabked in SD card.
+ * @return 0 if success, error code(>0) if fail
+ * @remark None.
+ */
+int app2sd_client_usr_on_demand_setup_exit(const char *pkgid, uid_t uid);
+int app2sd_client_on_demand_setup_exit(const char *pkgid);
+
+int app2sd_client_usr_force_clean(const char *pkgid, uid_t uid);
+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
+ * @param[in/out] st_interface Specifies the storage interface.
+ * @return None
+*/
+API void app2ext_on_load(app2ext_interface *st_interface);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
#ifndef __APPTOSD_INTERFACE_H__
#define __APPTOSD_INTERFACE_H__
-/**
- * @file app2sd_interface.h
- * @version 0.2
- * @brief This file declares API of app2sd library
- */
-/**
- * @addtogroup APPLICATION_FRAMEWORK
- * @{
- *
- * @defgroup app2sd
- * @version 0.2
- *
- * @section Header to use them:
- * @code
- * #include <app2sd_interface.h>
- * @endcode
- *
- * @addtogroup app2sd
- * @{
- */
-
-
#ifdef __cplusplus
extern "C" {
#endif
#include <app2ext_interface.h>
+int app2sd_usr_pre_app_install(const char *pkgid,
+ GList* dir_list, int size, uid_t uid);
- /**
- * @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
- * @param[in] appname application package name
- * [Ex: com.samsung.calculator]
- *This entry is parsed from application package control/manifest file.
- * @param[in] dir_list directory structure of the application
- * @param[in] size size of memory required by application(in MB).
- *This entry is parsed from application package control/manifest file.
- * @return 0 if success, error code(>0) if fail
- * @remark None.
- *
- *
- @code
- #include <app2sd_interface.h>
- int ret = -1;
- GList* dir_list = NULL;
- // Package manager populates dir_list with directory structure information
- ret= app2sd_pre_app_install
- ("com.samsung.calculotor", dir_list, 10);
- if(!ret)
- {
- printf("\n SUCCESS");
- // Package installer performs installation
- // app2sd_post_app_install() API should be called
- return;
- }
- else
- printf("\n FAILURE");
- @endcode
- */
- API int app2sd_pre_app_install(const char *appname,
- GList* dir_list, int size);
-
- /**
- * @brief : This API does post installation operations after
- * the installation in SD card
- * @param[in] appname application package name
- * [Ex: com.samsung.calculator]
- * @param[in] install_status Status of installation of package
- *[ enum app2ext_status].If package installation failed then
- * install_status= APP2EXT_STATUS_FAILURE else if installation
- * was successful then install_status = APP2EXT_ISTATUS_SUCCESS.
- * @pre Installation should be done by package installer.
- * @return 0 if success, error code(>0) if fail
- * @remark @see enum app2sd_install_status
- *
- *
- @code
- #include <app2sd_interface.h>
- int ret = -1;
- ret= app2sd_pre_app_install
- ("com.samsung.calculotor", APP2EXT_NATIVE_APP, 10);
- if(!ret)
- {
- printf("\n SUCCESS");
- // Package installer performs installation
- //Package was installed successfully.
- if(package_installation _success)
- {
- ret = app2sd_post_app_install
- ("com.samsung.calculator",APP2EXT_STATUS_SUCCESS);
- if(!ret)
- printf("\n SUCCESS");
- else
- printf("\n FAILURE");
- return;
- }
- else
- {
- //Package installation failed
- ret = app2sd_post_app_install
- ("com.samsung.calculator",APP2EXT_STATUS_FAILURE);
- if(!ret)
- printf("\n SUCCESS");
- else
- printf("\n FAILURE");
- return;
- }
- }
- else
- printf("\n FAILURE");
- @endcode
- */
- API int app2sd_post_app_install(const char *appname,
- app2ext_status install_status);
-
- /**
- * @brief : This API prepares the setup for upgradation of
- * application package
- * @pre vfat type sd card must be present.
- * @post Upgradation is done by package installer.
- * @param[in] appname application package name
- * [Ex: com.samsung.calculator]
- * @param[in] dir_list directory structure of the application
- * @param[in] size size of memory required by application(in MB).
- *This entry is parsed from application package control/manifest file.
- * @return 0 if success, error code(>0) if fail
- * @remark None.
- *
- *
- @code
- #include <app2sd_interface.h>
- int ret = -1;
- GList* dir_list = NULL;
- // Package manager populates dir_list with directory structure information
- ret= app2sd_pre_app_upgrade
- ("com.samsung.calculator", dir_list, 10);
- if(!ret)
- {
- printf("\n SUCCESS");
- // Package installer performs upgradation
- // app2sd_post_app_upgrade() API should be called
- return;
- }
- else
- printf("\n FAILURE");
- @endcode
- */
- API int app2sd_pre_app_upgrade(const char *appname,
- GList* dir_list, int size);
-
- /**
- * @brief : This API does post upgradation operations after
- * the installation in SD card
- * @param[in] appname application package name
- * [Ex: com.samsung.calculator]
- * @param[in] install_status Status of installation of package
- *[ enum app2extl_status].If package upgradation failed then
- * upgrade_status= APP2EXT_STATUS_FAILURE else if upgradation
- * was successful then upgrade_status = APP2EXT_STATUS_SUCCESS.
- * @pre Upgradation should be done by package installer.
- * @return 0 if success, error code(>0) if fail
- * @remark @see enum app2ext_status
- *
- *
- @code
- #include <app2sd_interface.h>
- int ret = -1;
- ret= app2sd_pre_app_upgrade
- ("com.samsung.calculator", APP2EXT_NATIVE_APP, 10);
- if(!ret)
- {
- printf("\n SUCCESS");
- // Package installer performs upgradation
- //Package was upgraded successfully.
- if(package_upgradation _success)
- {
- ret = app2sd_post_app_upgrade
- ("com.samsung.calculator",APP2EXT_STATUS_SUCCESS);
- if(!ret)
- printf("\n SUCCESS");
- else
- printf("\n FAILURE");
- return;
- }
- else
- {
- //Package upgradation failed
- ret = app2sd_post_app_upgrade
- ("com.samsung.calculator",APP2EXT_STATUS_FAILURE);
- if(!ret)
- printf("\n SUCCESS");
- else
- printf("\n FAILURE");
- return;
- }
- }
- else
- printf("\n FAILURE");
- @endcode
- */
- API int app2sd_post_app_upgrade(const char *appname,
- app2ext_status upgrade_status);
+int app2sd_usr_post_app_install(const char *pkgid,
+ app2ext_status install_status, uid_t uid);
- /**
- * @brief: This API prepares the setup for uninstallation
- * @pre Package must be installed in sdcard.
- * @post Package is uninstalled by the package installer.
- * @param[in] appname application package name
- * [Ex: com.samsung.calculator]
- * @return 0 if success, error code(>0) if fail
- * @remark None.
- *
- *
- @code
- #include <app2sd_interface.h>
- int ret = -1;
- ret= app2sd_pre_app_uninstall
- ("com.samsung.calculator");
- if(!ret)
- {
- printf("\n SUCCESS");
- // Package installer performs uninstallation
- // app2sd_post_app_uninstall() API should be called
- return;
- }
- else
- printf("\n FAILURE");
- @endcode
- */
- API int app2sd_pre_app_uninstall(const char *appname);
+int app2sd_usr_pre_app_upgrade(const char *pkgid,
+ GList* dir_list, int size, uid_t uid);
- /**
- * @brief This API removes the resources created during
- app2sd setup.It is called after uninstallation.
- * @pre Package must be uninstalled .
- * @post Encryption password is removed from sqlite db.
- * @param[in] appname application package name
- * [Ex: com.samsung.calculator]
- * @return 0 if success, error code(>0) if fail
- * @remark None.
- *
- *
- @code
- #include <app2sd_interface.h>
- int ret = -1;
- ret= app2sd_pre_app_uninstall
- ("com.samsung.calculator");
- if(!ret)
- {
- printf("\n SUCCESS");
- // Package installer performs uninstallation
- ret = app2sd_post_app_uninstall("com.samsung.calculator");
- if(!ret)
- printf("\n SUCCESS");
- else
- printf("\n FAILURE");
- return;
- }
- else
- printf("\n FAILURE");
- @endcode
- */
- API int app2sd_post_app_uninstall(const char *appname);
+int app2sd_usr_post_app_upgrade(const char *pkgid,
+ app2ext_status upgrade_status, uid_t uid);
- /**
- * @brief : This API moves the package from sd card
- to internal memory and vice versa.
- * @param[in] pkgid application package id
- * [Ex: com.samsung.calculator]
- * @param[in] move_type Move type[enum app2ext_move_type]
- * [sd card to internal/internal to sd card]
- * @param[in] dir_list directory structure of the application
- * @pre Package must be installed and its installation
- * location should be known.Use app2sd_get_app_install_location()
- * to get installation location.
- * @see app2sd_get_app_install_location().
- * @post Package is moved to new location.
- * @return 0 if success, error code(>0) if fail
- * @remark None.
- *
- *
- @code
- #include <app2sd_interface.h>
- int ret = -1;
- GList* dir_list = NULL;
- // Package manager populates dir_list with directory structure information
- ret = app2sd_get_app_install_location("com.samsung.calculator");
- if(ret == APP2SD_INTERNAL_MEM)
- {
- ret= app2sd_move_installed_app("com.samsung.calculator",
- dir_list, APP2EXT_MOVE_TO_EXT);
- if(!ret)
- printf("\n SUCCESS");
- else
- printf("\n FAILURE");
- }
- else if(ret == APP2SD_EXTERNAL_MEM)
- {
- ret= app2sd_move_installed_app("com.samsung.calculator",
- dir_list, APP2SD_MOVE_TO PHONE);
- if(!ret)
- printf("\n SUCCESS");
- else
- printf("\n FAILURE");
- }
- @endcode
- */
- API int app2sd_move_installed_app(const char *pkgid,
- GList* dir_list, app2ext_move_type move_type);
+int app2sd_usr_pre_app_uninstall(const char *pkgid, uid_t uid);
- /**
- * @brief : This API Enables the application in sd card
- for use. This API should be called by AUL.
- * @param[in] pkgid application package id
- * [Ex: com.samsung.calculator]
- * @pre Package must be installed
- * @post application is enabled in SD card.
- * @return 0 if success, error code(>0) if fail
- * @remark None.
- *
- *
- @code
- #include <app2sd_interface.h>
- int ret = -1;
- ret= app2sd_on_demand_setup_init("com.samsung.calculator");
- if(!ret)
- printf("\n SUCCESS");
- else
- printf("\n FAILURE");
- }
- @endcode
- */
- API int app2sd_on_demand_setup_init(const char *pkgid);
+int app2sd_usr_post_app_uninstall(const char *pkgid, uid_t uid);
+int app2sd_usr_move_installed_app(const char *pkgid,
+ GList* dir_list, app2ext_move_type move_type, uid_t uid);
- /**
- * @brief : This API Disables the application in sd card
- . This API should be called by Launchpad callback which will be registered
- during app launch for exit action of the application
- * @param[in] pkgid application package id
- * [Ex: com.samsung.calculator]
- * @pre Package must be installed and enabled
- * and application must be running in SD card
- * @post application is disabked in SD card.
- * @return 0 if success, error code(>0) if fail
- * @remark None.
- *
- *
- @code
- #include <app2sd_interface.h>
- int ret = -1;
- ret= app2sd_on_demand_setup_exit("com.samsung.calculator");
- if(!ret)
- printf("\n SUCCESS");
- else
- printf("\n FAILURE");
- }
- @endcode
- */
- API int app2sd_on_demand_setup_exit(const char *pkgid);
+int app2sd_usr_on_demand_setup_init(const char *pkgid, uid_t uid);
- /**
- * @brief : This is the plug-in load function.
- The plugin has to bind its functions to function pointers of storage handle
- * @param[in/out] st_interface Specifies the storage interface.
- * @return None
- */
- API void app2ext_on_load(app2ext_interface *st_interface);
+int app2sd_usr_on_demand_setup_exit(const char *pkgid, uid_t uid);
+int app2sd_usr_force_clean(const char *pkgid, uid_t uid);
#ifdef __cplusplus
}
#define DEV_MAJOR 7
#define FS_TYPE "ext4"
-#define INTERNAL_STORAGE_PATH "/opt/usr"
+#define INTERNAL_STORAGE_PATH "/opt"
typedef enum mount_type_t {
MOUNT_TYPE_RD = 0,
int _app2sd_get_available_free_memory(const char *sd_path, int *free_mem);
/*Function to move the application from/to SD Card*/
-int _app2sd_move_app(const char *pkgid, app2ext_move_type move_cmd, GList* dir_list);
+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(char *dirname);
+int _app2sd_delete_directory(const char *dirname);
/*utility to delete symbolic link*/
void _app2sd_delete_symlink(const char *dirname);
/*Utility to rename a directory*/
int _app2sd_rename_dir(const char *old_name, const char *new_name);
-/*Utility to create application directory structure entry as per package type*/
-int _app2sd_create_directory_entry(const char *pkgid, GList* dir_list);
-
/* Utility to create symlinks */
int _app2sd_create_symlink(char *pkgid);
/*This function finds the associated device node for the app*/
-char *_app2sd_find_associated_device_node(const char *pkgid);
+char *_app2sd_find_associated_device_node(const char *loopback_device);
/*This function does the loopback encryption for app*/
-char *_app2sd_do_loopback_encryption_setup(const char *pkgid);
+char *_app2sd_do_loopback_encryption_setup(const char *pkgid,
+ const char *loopback_device);
/*This function detaches the loopback device*/
char *_app2sd_detach_loop_device(const char *device);
char *_app2sd_find_associated_device(const char *mmc_app_path);
/*This function creates loopback device*/
-int _app2sd_create_loopback_device(const char *pkgid, int size);
+int _app2sd_create_loopback_device(const char *pkgid,
+ const char *loopback_device, int size);
/*This function deletes loopback device associated with the app*/
-int _app2sd_delete_loopback_device(const char *pkgid);
+int _app2sd_delete_loopback_device(const char *loopback_device);
/*This function creates ext4 FS on the device path*/
int _app2sd_create_file_system(const char *device_path);
/*This function mounts the app content on the device node*/
-int _app2sd_mount_app_content(const char *pkgid, const char *dev,
- int mount_type, GList* dir_list, app2sd_cmd cmd);
+int _app2sd_mount_app_content(const char *application_path, const char *pkgid,
+ const char *dev, int mount_type, GList* dir_list,
+ app2sd_cmd cmd, uid_t uid);
/*This function unmounts the app content */
-int _app2sd_unmount_app_content(const char *pkgid);
+int _app2sd_unmount_app_content(const char *application_path);
/*This function removes the loopbck encryption setup for the app*/
-int _app2sd_remove_loopback_encryption_setup(const char *pkgid);
+int _app2sd_remove_loopback_encryption_setup(const char *loopback_device);
/*This function removes all of loopbck encryption setup for the app*/
-int _app2sd_remove_all_loopback_encryption_setups(const char *pkgid);
+int _app2sd_remove_all_loopback_encryption_setups(const char *loopback_device);
/*This function updates loopback device size*/
int _app2sd_update_loopback_device_size(const char *pkgid,
- int size, GList* dir_list);
+ const char *loopback_device, const char *application_path,
+ const char *temp_pkgid, const char *temp_loopback_device,
+ const char *temp_application_path, int size, GList* dir_list,
+ uid_t uid);
/* This generates password */
char *_app2sd_generate_password(const char *pkgid);
/*This function encrypts device*/
-char *_app2sd_encrypt_device(const char *device, const char *pkgid,
- char *passwd);
+char *_app2sd_encrypt_device(const char *device, const char *loopback_device,
+ char *passwd);
/*This function finds free device*/
char *_app2sd_find_free_device(void);
int _app2sd_remove_password_from_db(const char *pkgid);
/* This functions saved password in db */
-int _app2sd_set_password_in_db(const char *pkgid,
- const char *passwd);
+int _app2sd_set_password_in_db(const char *pkgid, const char *passwd);
/* This functions make result file */
-void _app2sd_make_result_info_file(char *pkgid, int size);
+void _app2sd_make_result_info_file(char *pkgid, int size, uid_t uid);
+
+int _is_global(uid_t uid);
#endif
--- /dev/null
+<!DOCTYPE busconfig PUBLIC
+"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
+"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
+
+<busconfig>
+ <policy user="root">
+ <allow own="org.tizen.app2sd"/>
+ </policy>
+ <policy context="default">
+ <deny own="org.tizen.app2sd"/>
+ <check send_destination="org.tizen.app2sd" send_interface="org.tizen.app2sd" privilege="http://tizen.org/privilege/packagemanager.admin"/>
+ </policy>
+</busconfig>
--- /dev/null
+[D-BUS Service]
+User=root
+Name=org.tizen.app2sd
+Exec=@PREFIX@/bin/app2sd-server
--- /dev/null
+/*
+ * app2ext
+ *
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Garima Shrivastava<garima.s@samsung.com>
+ * Jyotsna Dhumale <jyotsna.a@samsung.com>
+ * Venkatesha Sarpangala <sarpangala.v@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <glib.h>
+#include <gio/gio.h>
+#include <app2sd_client_interface.h>
+
+static int app2sd_gdbus_shared_connection(GDBusConnection **connection)
+{
+ GError *error = NULL;
+
+#if (GLIB_MAJOR_VERSION <= 2 && GLIB_MINOR_VERSION < 36)
+ g_type_init();
+#endif
+
+ *connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+ if (*connection == NULL) {
+ if (error != NULL) {
+ _E("app2sd error : failed to get "
+ "system dbus [%s]", error->message);
+ g_error_free(error);
+ }
+ return APP2EXT_ERROR_DBUS_FAILED;
+ }
+
+ return APP2EXT_SUCCESS;
+}
+
+static int __app2sd_call_server_method(const gchar *method_name,
+ GVariant *param)
+{
+ int ret = APP2EXT_SUCCESS;
+ int result = 0;
+ GDBusConnection *conn = NULL;
+ GDBusProxy *proxy = NULL;
+ GError *error = NULL;
+ GVariant *value = NULL;
+
+ /* get gdbus connection */
+ ret = app2sd_gdbus_shared_connection(&conn);
+ if (ret) {
+ _E("app2sd error : dbus connection error");
+ return ret;
+ }
+
+ /* method call */
+ proxy = g_dbus_proxy_new_sync(conn,
+ G_DBUS_PROXY_FLAGS_NONE, NULL,
+ APP2SD_BUS_NAME, APP2SD_OBJECT_PATH, APP2SD_INTERFACE_NAME,
+ NULL, &error);
+ if (proxy == NULL) {
+ _E("failed to create new proxy, error(%s)", error->message);
+ g_error_free(error);
+ ret = APP2EXT_ERROR_DBUS_FAILED;
+ goto out;
+ }
+
+ value = g_dbus_proxy_call_sync(proxy, method_name, param,
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+ if (error != NULL) {
+ _E("proxy call sync error(%s)", error->message);
+ g_error_free(error);
+ ret = APP2EXT_ERROR_DBUS_FAILED;
+ goto out;
+ }
+
+ g_variant_get(value, "(i)", &result);
+ g_variant_unref(value);
+
+ _D("result(%d)", result);
+ if (result)
+ ret = result;
+
+out:
+ if (conn)
+ g_object_unref(conn);
+
+ return ret;
+}
+
+static void __app2sd_create_dir_list_builder(gpointer data, gpointer user_data)
+{
+ app2ext_dir_details *item = (app2ext_dir_details *)data;
+ GVariantBuilder *builder = (GVariantBuilder *)user_data;
+
+ g_variant_builder_add(builder, "(si)", item->name, item->type);
+}
+
+int app2sd_client_usr_pre_app_install(const char *pkgid, GList* dir_list,
+ int size, uid_t uid)
+{
+ int ret = 0;
+ GVariantBuilder *builder = NULL;
+ GVariant *param = NULL;
+
+ /* validate the function parameter recieved */
+ if (pkgid == NULL || dir_list == NULL || size <= 0) {
+ _E("invalid function arguments");
+ return APP2EXT_ERROR_INVALID_ARGUMENTS;
+ }
+
+ builder = g_variant_builder_new(G_VARIANT_TYPE("a(si)"));
+ g_list_foreach(dir_list, __app2sd_create_dir_list_builder, builder);
+
+ param = g_variant_new("(sia(si)i)", pkgid, size, builder, uid);
+ ret = __app2sd_call_server_method("PreAppInstall", param);
+
+ if (builder)
+ g_variant_builder_unref(builder);
+
+ return ret;
+}
+int app2sd_client_pre_app_install(const char *pkgid, GList* dir_list,
+ int size)
+{
+ int ret = 0;
+
+ ret = app2sd_client_usr_pre_app_install(pkgid,
+ dir_list, size, getuid());
+
+ return ret;
+}
+
+int app2sd_client_usr_post_app_install(const char *pkgid,
+ app2ext_status install_status, uid_t uid)
+{
+ int ret = 0;
+ GVariant *param = NULL;
+
+ /* validate the function parameter recieved */
+ if (pkgid == NULL || install_status < APP2EXT_STATUS_FAILED
+ || install_status > APP2EXT_STATUS_SUCCESS) {
+ _E("invalid func parameters");
+ return APP2EXT_ERROR_INVALID_ARGUMENTS;
+ }
+
+ param = g_variant_new("(sii)", pkgid, install_status, uid);
+ ret = __app2sd_call_server_method("PostAppInstall", param);
+
+ return ret;
+}
+int app2sd_client_post_app_install(const char *pkgid,
+ app2ext_status install_status)
+{
+ int ret = 0;
+
+ ret = app2sd_client_usr_post_app_install(pkgid,
+ install_status, getuid());
+
+ return ret;
+}
+
+int app2sd_client_usr_pre_app_upgrade(const char *pkgid, GList* dir_list,
+ int size, uid_t uid)
+{
+ int ret = 0;
+ GVariantBuilder *builder = NULL;
+ GVariant *param = NULL;
+
+ /* validate the function parameter recieved */
+ if (pkgid == NULL || dir_list == NULL || size <= 0) {
+ _E("invalid function arguments");
+ return APP2EXT_ERROR_INVALID_ARGUMENTS;
+ }
+
+ builder = g_variant_builder_new(G_VARIANT_TYPE("a(si)"));
+ g_list_foreach(dir_list, __app2sd_create_dir_list_builder, builder);
+
+ param = g_variant_new("(sia(si)i)", pkgid, size, builder, uid);
+ ret = __app2sd_call_server_method("PreAppUpgrade", param);
+
+ if (builder)
+ g_variant_builder_unref(builder);
+
+ return ret;
+}
+int app2sd_client_pre_app_upgrade(const char *pkgid, GList* dir_list,
+ int size)
+{
+ int ret = 0;
+
+ ret = app2sd_client_usr_pre_app_upgrade(pkgid,
+ dir_list, size, getuid());
+
+ return ret;
+}
+
+int app2sd_client_usr_post_app_upgrade(const char *pkgid,
+ app2ext_status install_status, uid_t uid)
+{
+ int ret = 0;
+ GVariant *param = NULL;
+
+ /* validate the function parameter recieved */
+ if (pkgid == NULL || install_status < APP2EXT_STATUS_FAILED
+ || install_status > APP2EXT_STATUS_SUCCESS) {
+ _E("invalid func parameters");
+ return APP2EXT_ERROR_INVALID_ARGUMENTS;
+ }
+
+ param = g_variant_new("(sii)", pkgid, install_status, uid);
+ ret = __app2sd_call_server_method("PostAppUpgrade", param);
+
+ return ret;
+}
+int app2sd_client_post_app_upgrade(const char *pkgid,
+ app2ext_status install_status)
+{
+ int ret = 0;
+
+ ret = app2sd_client_usr_post_app_upgrade(pkgid,
+ install_status, getuid());
+
+ return ret;
+}
+
+int app2sd_client_usr_pre_app_uninstall(const char *pkgid, uid_t uid)
+{
+ int ret = 0;
+ GVariant *param = NULL;
+
+ /* validate the function parameter recieved */
+ if (pkgid == NULL) {
+ _E("invalid func parameters");
+ return APP2EXT_ERROR_INVALID_ARGUMENTS;
+ }
+
+ param = g_variant_new("(si)", pkgid, uid);
+ ret = __app2sd_call_server_method("PreAppUninstall", param);
+
+ return ret;
+}
+int app2sd_client_pre_app_uninstall(const char *pkgid)
+{
+ int ret = 0;
+
+ ret = app2sd_client_usr_pre_app_uninstall(pkgid,
+ getuid());
+
+ return ret;
+}
+
+int app2sd_client_usr_post_app_uninstall(const char *pkgid, uid_t uid)
+{
+ int ret = 0;
+ GVariant *param = NULL;
+
+ /* validate the function parameter recieved */
+ if (pkgid == NULL) {
+ _E("invalid func parameters");
+ return APP2EXT_ERROR_INVALID_ARGUMENTS;
+ }
+
+ param = g_variant_new("(si)", pkgid, uid);
+ ret = __app2sd_call_server_method("PostAppUninstall", param);
+
+ return ret;
+}
+int app2sd_client_post_app_uninstall(const char *pkgid)
+{
+ int ret = 0;
+
+ ret = app2sd_client_usr_post_app_uninstall(pkgid,
+ getuid());
+
+ return ret;
+}
+
+int app2sd_client_usr_force_clean(const char *pkgid, uid_t uid)
+{
+ int ret = 0;
+ GVariant *param = NULL;
+
+ /* validate the function parameter recieved */
+ if (pkgid == NULL) {
+ _E("invalid func parameters");
+ return APP2EXT_ERROR_INVALID_ARGUMENTS;
+ }
+
+ param = g_variant_new("(si)", pkgid, uid);
+ ret = __app2sd_call_server_method("ForceClean", param);
+
+ return ret;
+}
+int app2sd_client_force_clean(const char *pkgid)
+{
+ int ret = 0;
+
+ ret = app2sd_client_usr_force_clean(pkgid, getuid());
+
+ return ret;
+}
+
+int app2sd_client_usr_on_demand_setup_init(const char *pkgid, uid_t uid)
+{
+ int ret = 0;
+ GVariant *param = NULL;
+
+ /* validate the function parameter recieved */
+ if (pkgid == NULL) {
+ _E("invalid func parameters");
+ return APP2EXT_ERROR_INVALID_ARGUMENTS;
+ }
+
+ param = g_variant_new("(si)", pkgid, uid);
+ ret = __app2sd_call_server_method("OndemandSetupInit", param);
+
+ return ret;
+}
+int app2sd_client_on_demand_setup_init(const char *pkgid)
+{
+ int ret = 0;
+
+ ret = app2sd_client_usr_on_demand_setup_init(pkgid,
+ getuid());
+
+ return ret;
+}
+
+int app2sd_client_usr_on_demand_setup_exit(const char *pkgid, uid_t uid)
+{
+ int ret = 0;
+ GVariant *param = NULL;
+
+ /* validate the function parameter recieved */
+ if (pkgid == NULL) {
+ _E("invalid func parameters");
+ return APP2EXT_ERROR_INVALID_ARGUMENTS;
+ }
+
+ param = g_variant_new("(si)", pkgid, uid);
+ ret = __app2sd_call_server_method("OndemandSetupExit", param);
+
+ return ret;
+}
+int app2sd_client_on_demand_setup_exit(const char *pkgid)
+{
+ int ret = 0;
+
+ ret = app2sd_client_usr_on_demand_setup_exit(pkgid,
+ getuid());
+
+ return ret;
+}
+
+int app2sd_client_usr_move_installed_app(const char *pkgid, GList* dir_list,
+ app2ext_move_type move_type, uid_t uid)
+{
+ int ret = 0;
+ GVariantBuilder *builder = NULL;
+ GVariant *param = NULL;
+
+ /* validate the function parameter recieved */
+ if (pkgid == NULL || dir_list == NULL
+ || move_type < APP2EXT_MOVE_TO_EXT
+ || move_type > APP2EXT_MOVE_TO_PHONE) {
+ _E("invalid function arguments");
+ return APP2EXT_ERROR_INVALID_ARGUMENTS;
+ }
+
+ builder = g_variant_builder_new(G_VARIANT_TYPE("a(si)"));
+ g_list_foreach(dir_list, __app2sd_create_dir_list_builder, builder);
+
+ param = g_variant_new("(sia(si)i)", pkgid, move_type, builder, uid);
+ ret = __app2sd_call_server_method("MoveInstalledApp", param);
+
+ if (builder)
+ g_variant_builder_unref(builder);
+
+ return ret;
+}
+int app2sd_client_move_installed_app(const char *pkgid, GList* dir_list,
+ app2ext_move_type move_type)
+{
+ int ret = 0;
+
+ ret = app2sd_client_usr_move_installed_app(pkgid,
+ dir_list, move_type, getuid());
+
+ return ret;
+}
+
+void app2ext_on_load(app2ext_interface *interface)
+{
+ /* Plug-in Binding.*/
+ interface->client_pre_install = app2sd_client_pre_app_install;
+ interface->client_post_install = app2sd_client_post_app_install;
+ interface->client_pre_upgrade = app2sd_client_pre_app_upgrade;
+ interface->client_post_upgrade = app2sd_client_post_app_upgrade;
+ interface->client_pre_uninstall = app2sd_client_pre_app_uninstall;
+ interface->client_post_uninstall = app2sd_client_post_app_uninstall;
+ 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_move = app2sd_client_move_installed_app;
+
+ interface->client_usr_pre_install = app2sd_client_usr_pre_app_install;
+ interface->client_usr_post_install = app2sd_client_usr_post_app_install;
+ interface->client_usr_pre_upgrade = app2sd_client_usr_pre_app_upgrade;
+ interface->client_usr_post_upgrade = app2sd_client_usr_post_app_upgrade;
+ interface->client_usr_pre_uninstall = app2sd_client_usr_pre_app_uninstall;
+ interface->client_usr_post_uninstall = app2sd_client_usr_post_app_uninstall;
+ interface->client_usr_force_clean = app2sd_client_usr_force_clean;
+ interface->client_usr_enable = app2sd_client_usr_on_demand_setup_init;
+ interface->client_usr_disable = app2sd_client_usr_on_demand_setup_exit;
+ interface->client_usr_move = app2sd_client_usr_move_installed_app;
+}
#include <sys/types.h>
#include <sys/wait.h>
#include <pkgmgr-info.h>
-#include <vconf.h>
-#define MAX_BUF_LEN 1024
+static int __app2sd_create_app2sd_directories(uid_t uid)
+{
+ int ret = 0;
+ char app2sd_user_path[FILENAME_MAX] = { 0, };
+ mode_t mode = DIR_PERMS;
+
+ ret = mkdir(APP2SD_PATH, mode);
+ if (ret) {
+ if (errno != EEXIST) {
+ _E("create directory failed," \
+ " error no is (%d)", errno);
+ return APP2EXT_ERROR_CREATE_DIRECTORY;
+ }
+ }
+
+ if (!_is_global(uid)) {
+ tzplatform_set_user(uid);
+ snprintf(app2sd_user_path, FILENAME_MAX - 1, "%s/%s",
+ APP2SD_PATH, tzplatform_getenv(TZ_USER_NAME));
+ tzplatform_reset_user();
+
+ ret = mkdir(app2sd_user_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_pre_app_install(const char *pkgid, GList* dir_list,
- int size)
+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;
char *device_node = NULL;
char *devi = NULL;
char *result = NULL;
- int reqd_disk_size = size + ceil(size*0.2);
+ char application_path[FILENAME_MAX] = { 0, };
+ char loopback_device[FILENAME_MAX] = { 0, };
+ int reqd_disk_size = size + ceil(size * 0.2);
- /* debug path */
- app2ext_print("MMC_PATH = (%s)\n", MMC_PATH);
- app2ext_print("APP2SD_PATH = (%s)\n", APP2SD_PATH);
- app2ext_print("APP_INSTALLATION_PATH = (%s)\n", APP_INSTALLATION_PATH);
- app2ext_print("APP_INSTALLATION_USER_PATH = (%s)\n", APP_INSTALLATION_USER_PATH);
-
- /* Validate the function parameter recieved */
+ /* validate the function parameter recieved */
if (pkgid == NULL || dir_list == NULL || size <= 0) {
- app2ext_print("App2Sd Error : Invalid function arguments\n");
+ _E("invalid function arguments");
return APP2EXT_ERROR_INVALID_ARGUMENTS;
}
- /* Check whether MMC is present or not */
+
+ /* check whether MMC is present or not */
ret = _app2sd_check_mmc_status();
if (ret) {
- app2ext_print("App2Sd Error : MMC not preset OR Not ready %d\n",
- ret);
+ _E("MMC not preset OR Not ready (%d)", ret);
return APP2EXT_ERROR_MMC_STATUS;
}
- /* Find available free memory in the MMC card */
- ret = _app2sd_get_available_free_memory(MMC_PATH,
- &free_mmc_mem);
+
+ /* find available free memory in the MMC card */
+ ret = _app2sd_get_available_free_memory(MMC_PATH, &free_mmc_mem);
if (ret) {
- app2ext_print("App2Sd Error : Unable to get available free memory in MMC %d\n", ret);
+ _E("unable to get available free memory in MMC (%d)",
+ ret);
return APP2EXT_ERROR_MMC_STATUS;
}
- app2ext_print("Size details for application installation:size=%dMB, reqd_disk_size=%dMB, free_mmc_size=%dMB\n",
- size, reqd_disk_size, free_mmc_mem);
- /* If avaialalbe free memory in MMC is less than required size + 5MB , return error */
+ _D("size details for application installation:" \
+ " size=(%d)MB, reqd_disk_size=(%d)MB, free_mmc_size=(%d)MB",
+ size, reqd_disk_size, free_mmc_mem);
+
+ /* if avaialalbe free memory in MMC is less than required size + 5MB,
+ * return error
+ */
if ((reqd_disk_size + PKG_BUF_SIZE + MEM_BUF_SIZE) > free_mmc_mem) {
- app2ext_print("Insufficient memory in MMC for application installation %d\n", ret);
+ _E("insufficient memory in MMC for"
+ " application installation (%d)", ret);
return APP2EXT_ERROR_MMC_INSUFFICIENT_MEMORY;
}
- /* Create a loopback device */
- ret = _app2sd_create_loopback_device(pkgid, (reqd_disk_size+PKG_BUF_SIZE));
+
+ if (_is_global(uid)) {
+ snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
+ tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
+ snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
+ APP2SD_PATH, pkgid);
+ } else {
+ tzplatform_set_user(uid);
+ snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
+ tzplatform_getenv(TZ_USER_APP), pkgid);
+ snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
+ APP2SD_PATH, tzplatform_getenv(TZ_USER_NAME), pkgid);
+ tzplatform_reset_user();
+ }
+ _D("application_path = (%s)", application_path);
+ _D("loopback_device = (%s)", loopback_device);
+
+ ret = __app2sd_create_app2sd_directories(uid);
+ if (ret) {
+ _E("failed to create app2sd dirs");
+ return ret;
+ }
+
+ /* check same loopback_device existence */
+ result = (char *)_app2sd_find_associated_device(loopback_device);
+ if (result != NULL) {
+ _E("there is same associated File (%s)", loopback_device);
+ return APP2EXT_ERROR_SAME_LOOPBACK_DEVICE_EXISTS;
+ }
+
+ /* create a loopback device */
+ ret = _app2sd_create_loopback_device(pkgid, loopback_device,
+ (reqd_disk_size + PKG_BUF_SIZE));
if (ret) {
- app2ext_print("App2Sd Error : Package already present\n");
- char buf_dir[FILENAME_MAX] = { 0, };
- memset((void *)&buf_dir, '\0', FILENAME_MAX);
- snprintf(buf_dir, FILENAME_MAX, "%s%s", APP_INSTALLATION_PATH, pkgid);
- ret = _app2sd_delete_directory(buf_dir);
+ _W("package already present, delete app directory");
+ ret = _app2sd_delete_directory(application_path);
if (ret) {
- app2ext_print
- ("App2Sd Error : Unable to delete the directory %s\n",
- buf_dir);
+ _E("unable to delete the directory (%s)",
+ application_path);
+ return ret;
}
}
- /* Perform Loopback encryption setup */
- device_node = _app2sd_do_loopback_encryption_setup(pkgid);
+
+ /* perform loopback encryption setup */
+ device_node = _app2sd_do_loopback_encryption_setup(pkgid,
+ loopback_device);
if (!device_node) {
- app2ext_print("App2Sd Error : Loopback encryption setup failed\n");
- _app2sd_delete_loopback_device(pkgid);
+ _E("loopback encryption setup failed");
+ _app2sd_delete_loopback_device(loopback_device);
return APP2EXT_ERROR_DO_LOSETUP;
}
- /* Check whether loopback device is associated with device node or not */
- devi = _app2sd_find_associated_device_node(pkgid);
+
+ /* check whether loopback device is associated
+ * with device node or not
+ */
+ devi = _app2sd_find_associated_device_node(loopback_device);
if (devi == NULL) {
- app2ext_print("App2Sd Error : finding associated device node failed\n");
+ _E("finding associated device node failed");
ret = APP2EXT_ERROR_DO_LOSETUP;
goto FINISH_OFF;
}
- /* Format the loopback file system */
+ /* format the loopback file system */
ret = _app2sd_create_file_system(device_node);
if (ret) {
- app2ext_print("App2Sd Error : creating FS failed failed\n");
+ _E("creating FS failed failed");
ret = APP2EXT_ERROR_CREATE_FS;
goto FINISH_OFF;
}
- /* Mount the loopback encrypted pseudo device on application installation path as with Read Write permission */
- ret =_app2sd_mount_app_content(pkgid, device_node, MOUNT_TYPE_RW,
- dir_list, APP2SD_PRE_INSTALL);
+ /* mount the loopback encrypted pseudo device on application
+ * installation path as with Read Write permission
+ */
+ ret =_app2sd_mount_app_content(application_path, pkgid,
+ device_node, MOUNT_TYPE_RW, dir_list,
+ APP2SD_PRE_INSTALL, uid);
if (ret) {
- app2ext_print("App2Sd Error : mounting dev path to app install path failed\n");
+ _E("mounting dev path to app install path failed");
ret = APP2EXT_ERROR_MOUNT_PATH;
goto FINISH_OFF;
}
goto END;
FINISH_OFF:
-
if (device_node) {
result = _app2sd_detach_loop_device(device_node);
if (result) {
free(result);
result = NULL;
}
- _app2sd_delete_loopback_device(pkgid);
+ _app2sd_delete_loopback_device(loopback_device);
}
+
END:
if (device_node) {
free(device_node);
device_node = NULL;
}
+
if (devi) {
free(devi);
devi = NULL;
}
+
return ret;
}
-int app2sd_post_app_install(const char *pkgid,
- app2ext_status install_status)
+int app2sd_usr_post_app_install(const char *pkgid,
+ app2ext_status install_status, uid_t uid)
{
char *device_name = NULL;
- char buf_dir[FILENAME_MAX] = { 0, };
+ char application_path[FILENAME_MAX] = { 0, };
+ char loopback_device[FILENAME_MAX] = { 0, };
int ret = APP2EXT_SUCCESS;
- /*Validate the function parameter recieved */
+ int pkgmgr_ret = 0;
+
+ /* validate the function parameter recieved */
if (pkgid == NULL || install_status < APP2EXT_STATUS_FAILED
|| install_status > APP2EXT_STATUS_SUCCESS) {
- app2ext_print("Invalid func parameters\n");
+ _E("invalid func parameters");
return APP2EXT_ERROR_INVALID_ARGUMENTS;
}
- /*Check whether MMC is present or not */
+ /* check whether MMC is present or not */
ret = _app2sd_check_mmc_status();
if (ret) {
- app2ext_print("App2Sd Error : MMC not preset OR Not ready %d\n",
- ret);
+ _E("MMC not present OR Not ready (%d)", ret);
return APP2EXT_ERROR_MMC_STATUS;
}
- sync(); //2
- /*Get the associated device node for SD card applicationer */
- device_name = _app2sd_find_associated_device_node(pkgid);
+ sync();
+
+ if (_is_global(uid)) {
+ snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
+ tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
+ snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
+ APP2SD_PATH, pkgid);
+ } else {
+ tzplatform_set_user(uid);
+ snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
+ tzplatform_getenv(TZ_USER_APP), pkgid);
+ snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
+ APP2SD_PATH, tzplatform_getenv(TZ_USER_NAME), pkgid);
+ tzplatform_reset_user();
+ }
+ _D("application_path = (%s)", application_path);
+ _D("loopback_device = (%s)", loopback_device);
+
+ /* get the associated device node for SD card applicationer */
+ device_name = _app2sd_find_associated_device_node(loopback_device);
if (NULL == device_name) {
return APP2EXT_ERROR_FIND_ASSOCIATED_DEVICE_NODE;
}
- ret = _app2sd_unmount_app_content(pkgid);
+
+ ret = _app2sd_unmount_app_content(application_path);
if (ret) {
if (device_name) {
free(device_name);
device_name = NULL;
}
- app2ext_print("Unable to unmount the app content %d\n", ret);
+ _E("unable to unmount the app content (%d)", ret);
return APP2EXT_ERROR_UNMOUNT;
}
- ret = _app2sd_remove_loopback_encryption_setup(pkgid);
+
+ ret = _app2sd_remove_loopback_encryption_setup(loopback_device);
if (ret) {
if (device_name) {
free(device_name);
device_name = NULL;
}
- app2ext_print
- ("Unable to Detach the loopback encryption setup for the application");
+ _E("unable to detach the loopback encryption setup" \
+ " for the application");
return APP2EXT_ERROR_UNMOUNT;
}
+
if (device_name) {
free(device_name);
device_name = NULL;
}
- /*Take appropriate action based on installation
- status of application package */
+ /* take appropriate action based on
+ * installation status of application package
+ */
if (install_status == APP2EXT_STATUS_FAILED) {
- /*Delete the loopback device from the SD card */
- ret = _app2sd_delete_loopback_device(pkgid);
+ /* delete the loopback device from the SD card */
+ ret = _app2sd_delete_loopback_device(loopback_device);
if (ret) {
- app2ext_print
- ("App2Sd Error : Unable to delete the loopback device from the SD Card\n");
+ _E("unable to delete the loopback device from the SD Card");
return APP2EXT_ERROR_DELETE_LOOPBACK_DEVICE;
}
ret = _app2sd_remove_password_from_db(pkgid);
- if (ret) {
- app2ext_print
- ("App2Sd Error : Unable to delete the password\n");
- }
-
- snprintf(buf_dir, FILENAME_MAX, "%s%s", APP_INSTALLATION_PATH, pkgid);
+ if (ret)
+ _E("unable to delete the password");
- ret = _app2sd_delete_directory(buf_dir);
-
- if (ret) {
- app2ext_print
- ("App2Sd Error : Unable to delete the directory %s\n",
- buf_dir);
- }
+ ret = _app2sd_delete_directory(application_path);
+ if (ret)
+ _E("unable to delete the directory (%s)", application_path);
} else {
- /*If the status is success, then update installed storage to pkgmgr_parser db*/
- int rt = 0;
- rt = pkgmgrinfo_pkginfo_set_installed_storage(pkgid, INSTALL_EXTERNAL);
- if (rt < 0) {
- app2ext_print("fail to update installed location to db[%s, %d]\n", pkgid, INSTALL_EXTERNAL);
+ /* if the status is success, then update installed storage
+ * to pkgmgr_parser db
+ */
+ pkgmgr_ret = pkgmgrinfo_pkginfo_set_usr_installed_storage(pkgid,
+ INSTALL_EXTERNAL, uid);
+ if (pkgmgr_ret < 0) {
+ _E("fail to update installed location " \
+ "to db[%s, %d] of uid(%d), pkgmgr ret(%d)",
+ pkgid, INSTALL_EXTERNAL, uid, pkgmgr_ret);
+ return APP2EXT_ERROR_PKGMGR_ERROR;
}
}
+
return ret;
}
-int app2sd_on_demand_setup_init(const char *pkgid)
+int app2sd_usr_on_demand_setup_init(const char *pkgid, uid_t uid)
{
int ret = APP2EXT_SUCCESS;
- char app_path[FILENAME_MAX] = { 0, };
+ char application_path[FILENAME_MAX] = { 0, };
+ char loopback_device[FILENAME_MAX] = { 0, };
char *device_node = NULL;
char *result = NULL;
FILE *fp = NULL;
- /*Validate the function parameter recieved */
+ /* validate the function parameter recieved */
if (pkgid == NULL) {
- app2ext_print
- ("App2Sd Error : Invalid function arguments to app launch setup\n");
+ _E("invalid function arguments to app launch setup");
return APP2EXT_ERROR_INVALID_ARGUMENTS;
}
- /*Check whether MMC is present or not */
+ /* check whether MMC is present or not */
ret = _app2sd_check_mmc_status();
if (ret) {
- app2ext_print("App2Sd Error : MMC not preset OR Not ready %d\n",
- ret);
+ _E("MMC not preset OR Not ready (%d)", ret);
return APP2EXT_ERROR_MMC_STATUS;
}
- /*check app entry is there in sd card or not. */
- snprintf(app_path, FILENAME_MAX, "%s%s", APP2SD_PATH,
- pkgid);
- fp = fopen(app_path, "r+");
+ /* check app entry is there in sd card or not. */
+ if (_is_global(uid)) {
+ snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
+ tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
+ snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
+ APP2SD_PATH, pkgid);
+ } else {
+ tzplatform_set_user(uid);
+ snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
+ tzplatform_getenv(TZ_USER_APP), pkgid);
+ snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
+ APP2SD_PATH, tzplatform_getenv(TZ_USER_NAME), pkgid);
+ tzplatform_reset_user();
+ }
+ _D("application_path = (%s)", application_path);
+ _D("loopback_device = (%s)", loopback_device);
+
+ fp = fopen(loopback_device, "r+");
if (fp == NULL) {
- app2ext_print
- ("App2SD Error: App Entry is not present in SD Card\n");
+ _E("app entry is not present in SD Card");
return APP2EXT_ERROR_INVALID_PACKAGE;
}
fclose(fp);
- result = (char *)_app2sd_find_associated_device(app_path);
- /*process the string */
- if ((result!=NULL) && strstr(result, "/dev") != NULL) {
- app2ext_print("App2SD Error! Already associated\n");
+
+ result = (char *)_app2sd_find_associated_device(loopback_device);
+ /* process the string */
+ if ((result != NULL) && strstr(result, "/dev") != NULL) {
+ _E("already associated");
free(result);
result = NULL;
return APP2EXT_ERROR_ALREADY_MOUNTED;
}
- /*Do loopback setup */
- device_node = _app2sd_do_loopback_encryption_setup(pkgid);
+ /* do loopback setup */
+ device_node = _app2sd_do_loopback_encryption_setup(pkgid,
+ loopback_device);
if (device_node == NULL) {
- app2ext_print
- ("App2Sd Error : loopback encryption setup failed\n");
+ _E("loopback encryption setup failed");
return APP2EXT_ERROR_DO_LOSETUP;
}
- /*Do mounting */
- ret =
- _app2sd_mount_app_content(pkgid, device_node, MOUNT_TYPE_RD,
- NULL, APP2SD_APP_LAUNCH);
+ /* do mounting */
+ ret = _app2sd_mount_app_content(application_path, pkgid,
+ device_node, MOUNT_TYPE_RD, NULL, APP2SD_APP_LAUNCH, uid);
if (ret) {
- app2ext_print("App2Sd Error : Re-mount failed\n");
+ _E("mount failed");
if (device_node) {
free(device_node);
device_node = NULL;
}
return APP2EXT_ERROR_MOUNT_PATH;
}
+
if (device_node) {
free(device_node);
device_node = NULL;
}
+
return ret;
}
-int app2sd_on_demand_setup_exit(const char *pkgid)
+int app2sd_usr_on_demand_setup_exit(const char *pkgid, uid_t uid)
{
int ret = APP2EXT_SUCCESS;
- char app_path[FILENAME_MAX] = { 0, };
+ char application_path[FILENAME_MAX] = { 0, };
+ char loopback_device[FILENAME_MAX] = { 0, };
FILE *fp = NULL;
- /*Validate the function parameter recieved */
+ /* validate the function parameter recieved */
if (pkgid == NULL) {
- app2ext_print
- ("App2Sd Error : Invalid function arguments to app launch setup\n");
+ _E("invalid function arguments to app launch setup");
return APP2EXT_ERROR_INVALID_ARGUMENTS;
}
- /*Check whether MMC is present or not */
+ /* check whether MMC is present or not */
ret = _app2sd_check_mmc_status();
if (ret) {
- app2ext_print("App2Sd Error : MMC not preset OR Not ready %d\n",
- ret);
+ _E("MMC not preset OR Not ready (%d)", ret);
return APP2EXT_ERROR_MMC_STATUS;
}
- /*check app entry is there in sd card or not. */
- snprintf(app_path, FILENAME_MAX, "%s%s", APP2SD_PATH,
- pkgid);
- fp = fopen(app_path, "r+");
+
+ /* check app entry is there in sd card or not. */
+ if (_is_global(uid)) {
+ snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
+ tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
+ snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
+ APP2SD_PATH, pkgid);
+ } else {
+ tzplatform_set_user(uid);
+ snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
+ tzplatform_getenv(TZ_USER_APP), pkgid);
+ snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
+ APP2SD_PATH, tzplatform_getenv(TZ_USER_NAME), pkgid);
+ tzplatform_reset_user();
+ }
+ _D("application_path = (%s)", application_path);
+ _D("loopback_device = (%s)", loopback_device);
+
+ fp = fopen(loopback_device, "r+");
if (fp == NULL) {
- app2ext_print
- ("App2SD Error: App Entry is not present in SD Card\n");
+ _E("app entry is not present in SD Card");
return APP2EXT_ERROR_INVALID_PACKAGE;
}
fclose(fp);
- ret = _app2sd_unmount_app_content(pkgid);
+
+ ret = _app2sd_unmount_app_content(application_path);
if (ret) {
- app2ext_print
- ("App2SD Error: Unable to unmount the SD application\n");
+ _E("unable to unmount the SD application");
return APP2EXT_ERROR_UNMOUNT;
}
- ret = _app2sd_remove_loopback_encryption_setup(pkgid);
+
+ ret = _app2sd_remove_loopback_encryption_setup(loopback_device);
if (ret) {
- app2ext_print("App2SD Error: Unable to remove loopback setup\n");
+ _E("unable to remove loopback setup");
return APP2EXT_ERROR_DELETE_LOOPBACK_DEVICE;
}
+
return ret;
}
-int app2sd_pre_app_uninstall(const char *pkgid)
+int app2sd_usr_pre_app_uninstall(const char *pkgid, uid_t uid)
{
int ret = APP2EXT_SUCCESS;
- char app_path[FILENAME_MAX] = { 0, };
+ char application_path[FILENAME_MAX] = { 0, };
+ char loopback_device[FILENAME_MAX] = { 0, };
char *device_node = NULL;
- FILE*fp = NULL;
+ FILE *fp = NULL;
- /*Validate the function parameter recieved */
+ /* validate the function parameter recieved */
if (pkgid == NULL) {
- app2ext_print
- ("App2Sd Error : Invalid function arguments to app launch setup\n");
+ _E("invalid function arguments to app launch setup");
ret = APP2EXT_ERROR_INVALID_ARGUMENTS;
goto END;
}
- /*Check whether MMC is present or not */
+
+ /* check whether MMC is present or not */
ret = _app2sd_check_mmc_status();
if (ret) {
- app2ext_print("App2Sd Error : MMC not preset OR Not ready %d\n",
- ret);
+ _E("MMC not preset OR Not ready (%d)", ret);
ret = APP2EXT_ERROR_MMC_STATUS;
goto END;
}
- /*check app entry is there in sd card or not. */
- snprintf(app_path, FILENAME_MAX, "%s%s", APP2SD_PATH, pkgid);
- fp = fopen(app_path, "r+");
+
+ if (_is_global(uid)) {
+ snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
+ tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
+ snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
+ APP2SD_PATH, pkgid);
+ } else {
+ tzplatform_set_user(uid);
+ snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
+ tzplatform_getenv(TZ_USER_APP), pkgid);
+ snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
+ APP2SD_PATH, tzplatform_getenv(TZ_USER_NAME), pkgid);
+ tzplatform_reset_user();
+ }
+ _D("application_path = (%s)", application_path);
+ _D("loopback_device = (%s)", loopback_device);
+
+ /* check app entry is there in sd card or not. */
+ fp = fopen(loopback_device, "r+");
if (fp == NULL) {
- app2ext_print
- ("App2SD Error: App Entry is not present in SD Card\n");
+ _E("app entry is not present in SD Card");
ret = APP2EXT_ERROR_INVALID_PACKAGE;
goto END;
}
fclose(fp);
- /*Get the associated device node for SD card applicationer */
- device_node = _app2sd_find_associated_device_node(pkgid);
+ /* get the associated device node for SD card applicationer */
+ device_node = _app2sd_find_associated_device_node(loopback_device);
if (NULL == device_node) {
- /*Do loopback setup */
- device_node = _app2sd_do_loopback_encryption_setup(pkgid);
-
+ /* do loopback setup */
+ device_node = _app2sd_do_loopback_encryption_setup(pkgid,
+ loopback_device);
if (device_node == NULL) {
- app2ext_print
- ("App2Sd Error : loopback encryption setup failed\n");
+ _E("loopback encryption setup failed");
ret = APP2EXT_ERROR_DO_LOSETUP;
goto END;
}
- /*Do mounting */
- ret =
- _app2sd_mount_app_content(pkgid, device_node,
- MOUNT_TYPE_RW, NULL,
- APP2SD_PRE_UNINSTALL);
-
+ /* do mounting */
+ ret = _app2sd_mount_app_content(application_path, pkgid,
+ device_node, MOUNT_TYPE_RW, NULL,
+ APP2SD_PRE_UNINSTALL, uid);
if (ret) {
- app2ext_print("App2Sd Error : RW-mount failed\n");
+ _E("mount failed");
if (device_node) {
free(device_node);
device_node = NULL;
goto END;
}
} else {
- /*Do re-mounting */
- ret =
- _app2sd_mount_app_content(pkgid, device_node,
- MOUNT_TYPE_RW_REMOUNT, NULL,
- APP2SD_PRE_UNINSTALL);
-
+ /* do re-mounting */
+ ret = _app2sd_mount_app_content(application_path, pkgid,
+ device_node, MOUNT_TYPE_RW_REMOUNT, NULL,
+ APP2SD_PRE_UNINSTALL, uid);
if (ret) {
- app2ext_print("App2Sd Error : Re-mount failed\n");
+ _E("remount failed");
if (device_node) {
free(device_node);
device_node = NULL;
}
END:
- if (ret != APP2EXT_SUCCESS)
- app2ext_print("App2Sd Error : app2sd has [%d]error, but return success for uninstallation\n", ret);
return ret;
}
-/*
-* app2sd_post_app_uninstall_setup
-* Uninstall Application and free all the allocated resources
-* Called after dpkg remove, It deallocates dev node and loopback
-*/
-int app2sd_post_app_uninstall(const char *pkgid)
+int app2sd_usr_post_app_uninstall(const char *pkgid, uid_t uid)
{
- char buf_dir[FILENAME_MAX] = { 0, };
+ char application_path[FILENAME_MAX] = { 0, };
+ char loopback_device[FILENAME_MAX] = { 0, };
int ret = APP2EXT_SUCCESS;
- int ret1 = APP2EXT_SUCCESS;
- /*Validate the function parameter recieved */
+
+ /* validate the function parameter recieved */
if (pkgid == NULL) {
- app2ext_print
- ("App2Sd Error : Invalid function arguments to Post Uninstall\n");
+ _E("invalid function arguments");
ret = APP2EXT_ERROR_INVALID_ARGUMENTS;
goto END;
}
- /*Check whether MMC is present or not */
+
+ /* check whether MMC is present or not */
ret = _app2sd_check_mmc_status();
if (ret) {
- app2ext_print("App2Sd Error : MMC not preset OR Not ready %d\n",
- ret);
+ _E("MMC not preset OR Not ready (%d)", ret);
ret = APP2EXT_ERROR_MMC_STATUS;
goto END;
}
- /*Unmount the loopback encrypted pseudo device from the application installation path */
- ret = _app2sd_unmount_app_content(pkgid);
- if (ret) {
- app2ext_print("Unable to unmount the app content %d\n", ret);
+
+ if (_is_global(uid)) {
+ snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
+ tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
+ snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
+ APP2SD_PATH, pkgid);
+ } else {
+ tzplatform_set_user(uid);
+ snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
+ tzplatform_getenv(TZ_USER_APP), pkgid);
+ snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
+ APP2SD_PATH, tzplatform_getenv(TZ_USER_NAME), pkgid);
+ tzplatform_reset_user();
+ }
+ _D("application_path = (%s)", application_path);
+ _D("loopback_device = (%s)", loopback_device);
+
+ /* unmount the loopback encrypted pseudo device from
+ * the application installation path
+ */
+ ret = _app2sd_unmount_app_content(application_path);
+ if (ret) {
+ _E("unable to unmount the app content (%d)", ret);
ret = APP2EXT_ERROR_UNMOUNT;
goto END;
}
- /*Detach the loopback encryption setup for the application */
- ret = _app2sd_remove_loopback_encryption_setup(pkgid);
+ /* detach the loopback encryption setup for the application */
+ ret = _app2sd_remove_loopback_encryption_setup(loopback_device);
if (ret) {
- app2ext_print
- ("Unable to Detach the loopback encryption setup for the application");
+ _E("unable to Detach the loopback encryption setup" \
+ " for the application");
ret = APP2EXT_ERROR_DETACH_LOOPBACK_DEVICE;
goto END;
}
- /*Delete the loopback device from the SD card */
- ret = _app2sd_delete_loopback_device(pkgid);
+
+ /* delete the loopback device from the SD card */
+ ret = _app2sd_delete_loopback_device(loopback_device);
if (ret) {
- app2ext_print
- ("App2Sd Error : Unable to delete the loopback device from the SD Card\n");
+ _E("unable to delete the " \
+ "loopback device from the SD Card");
ret = APP2EXT_ERROR_DELETE_LOOPBACK_DEVICE;
goto END;
}
- memset((void *)&buf_dir, '\0', FILENAME_MAX);
- snprintf(buf_dir, FILENAME_MAX, "%s%s", APP_INSTALLATION_PATH, pkgid);
- ret1 = _app2sd_delete_directory(buf_dir);
- if (ret1) {
- app2ext_print
- ("App2Sd Error : Unable to delete the directory %s\n",
- buf_dir);
+
+ ret = _app2sd_delete_directory(application_path);
+ if (ret) {
+ _E("unable to delete the directory (%s)",
+ application_path);
+ goto END;
}
- /*remove encryption password from DB */
+
+ /* remove encryption password from DB */
ret = _app2sd_initialize_db();
if (ret) {
- app2ext_print("\n app2sd db initialize failed");
+ _E("app2sd db initialize failed");
ret = APP2EXT_ERROR_SQLITE_REGISTRY;
goto END;
}
+
ret = _app2sd_remove_password_from_db(pkgid);
if (ret) {
- app2ext_print("cannot remove password from db \n");
+ _E("cannot remove password from db");
ret = APP2EXT_ERROR_SQLITE_REGISTRY;
goto END;
}
END:
- if (ret != APP2EXT_SUCCESS)
- app2ext_print("App2Sd Error : app2sd has [%d]error, but return success for uninstallation\n", ret);
return ret;
}
-int app2sd_move_installed_app(const char *pkgid, GList* dir_list,
- app2ext_move_type move_type)
+int app2sd_usr_move_installed_app(const char *pkgid, GList* dir_list,
+ app2ext_move_type move_type, uid_t uid)
{
int ret = 0;
- int pkgmgrinfo_ret = 0;
+ int pkgmgr_ret = 0;
- /*Validate function arguments*/
+ /* validate function arguments */
if (pkgid == NULL || dir_list == NULL
|| move_type < APP2EXT_MOVE_TO_EXT
|| move_type > APP2EXT_MOVE_TO_PHONE) {
- app2ext_print("App2Sd Error : Invalid function arguments\n");
+ _E("invalid function arguments");
ret = APP2EXT_ERROR_INVALID_ARGUMENTS;
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);
+ pkgmgr_ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &info_handle);
+ if (pkgmgr_ret < 0) {
+ _E("failed to get pkginfo for pkg(%s), uid(%d), pkgmgr_ret(%d)",
+ pkgid, uid, pkgmgr_ret);
+ }
+ pkgmgr_ret = pkgmgrinfo_pkginfo_get_installed_storage(info_handle, &storage);
+ if (pkgmgr_ret < 0) {
+ _E("failed to get installed storage for pkg(%s) of uid(%d), pkgmgr_ret(%d)",
+ pkgid, uid, pkgmgr_ret);
+ pkgmgrinfo_pkginfo_destroy_pkginfo(info_handle);
+ goto END;
}
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);
+ _E("PKG_EXISTS in [%d] STORAGE", storage);
pkgmgrinfo_pkginfo_destroy_pkginfo(info_handle);
goto END;
} else {
- app2ext_print("App2Sd info : pkgid[%s] move to STORAGE[%d]\n", pkgid, storage);
+ _D("pkgid[%s] move to STORAGE [%d]", pkgid, storage);
}
pkgmgrinfo_pkginfo_destroy_pkginfo(info_handle);
- ret = _app2sd_move_app(pkgid, move_type, dir_list);
+ ret = _app2sd_usr_move_app(pkgid, move_type, dir_list, uid);
if (ret) {
- app2ext_print("App2Sd Error : Unable to move application\n");
+ _D("unable to move application");
goto END;
}
- /* If move is completed, then update installed storage to pkgmgr_parser db */
+ /* if move is completed, then update installed storage to pkgmgr_parser db */
if (move_type == APP2EXT_MOVE_TO_EXT) {
- pkgmgrinfo_ret = pkgmgrinfo_pkginfo_set_installed_storage(pkgid, INSTALL_EXTERNAL);
- if (pkgmgrinfo_ret < 0) {
- app2ext_print("App2Sd Error : fail to update installed location to db[%s, %s]\n", pkgid, INSTALL_EXTERNAL);
+ pkgmgr_ret = pkgmgrinfo_pkginfo_set_usr_installed_storage(pkgid,
+ INSTALL_EXTERNAL, uid);
+ if (pkgmgr_ret < 0) {
+ _E("failed to update installed location to db " \
+ "[%s, %s] of uid(%d), pkgmgr_ret(%d)",
+ pkgid, INSTALL_EXTERNAL, uid, pkgmgr_ret);
+ return APP2EXT_ERROR_PKGMGR_ERROR;
}
} else {
- pkgmgrinfo_ret = pkgmgrinfo_pkginfo_set_installed_storage(pkgid, INSTALL_INTERNAL);
- if (pkgmgrinfo_ret < 0) {
- app2ext_print("App2Sd Error : fail to update installed location to db[%s, %s]\n", pkgid, INSTALL_INTERNAL);
+ pkgmgr_ret = pkgmgrinfo_pkginfo_set_usr_installed_storage(pkgid,
+ INSTALL_INTERNAL, uid);
+ if (pkgmgr_ret < 0) {
+ _E("failed to update installed location to db " \
+ "[%s, %s] of uid(%d), pkgmgr_ret(%d)",
+ pkgid, INSTALL_INTERNAL, uid, pkgmgr_ret);
+ return APP2EXT_ERROR_PKGMGR_ERROR;
}
}
-END:
- _app2sd_make_result_info_file((char*)pkgid, ret);
+END:
+ _app2sd_make_result_info_file((char*)pkgid, ret, uid);
return ret;
}
-int app2sd_pre_app_upgrade(const char *pkgid, GList* dir_list,
- int size)
+int app2sd_usr_pre_app_upgrade(const char *pkgid, GList* dir_list,
+ int size, uid_t uid)
{
int ret = APP2EXT_SUCCESS;
- char app_path[FILENAME_MAX] = { 0, };
+ char loopback_device[FILENAME_MAX] = { 0, };
+ char application_path[FILENAME_MAX] = { 0, };
+ char temp_pkgid[FILENAME_MAX] = { 0, };
+ char temp_loopback_device[FILENAME_MAX] = { 0, };
+ char temp_application_path[FILENAME_MAX] = { 0, };
char *device_node = NULL;
unsigned long long curr_size = 0;
FILE *fp = NULL;
- int reqd_disk_size = size + ceil(size*0.2);
+ int reqd_disk_size = size + ceil(size * 0.2);
- /*Validate function arguments*/
+ /* validate function arguments*/
if (pkgid == NULL || dir_list == NULL || size<=0) {
- app2ext_print
- ("App2Sd Error : Invalid function arguments \n");
+ _E("invalid function arguments");
return APP2EXT_ERROR_INVALID_ARGUMENTS;
}
- /*Check whether MMC is present or not */
+
+ /* check whether MMC is present or not */
ret = _app2sd_check_mmc_status();
if (ret) {
- app2ext_print("App2Sd Error : MMC not preset OR Not ready %d\n",
- ret);
+ _E("MMC not preset OR Not ready (%d)", ret);
return APP2EXT_ERROR_MMC_STATUS;
}
- /*check app entry is there in sd card or not. */
- snprintf(app_path, FILENAME_MAX, "%s%s", APP2SD_PATH,
- pkgid);
- app2ext_print("App2Sd Log : Checking path %s\n", app_path);
- fp = fopen(app_path, "r+");
+
+ if (_is_global(uid)) {
+ snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
+ tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
+ snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
+ APP2SD_PATH, pkgid);
+ } else {
+ tzplatform_set_user(uid);
+ snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
+ tzplatform_getenv(TZ_USER_APP), pkgid);
+ snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
+ APP2SD_PATH, tzplatform_getenv(TZ_USER_NAME), pkgid);
+ tzplatform_reset_user();
+ }
+ _D("application_path = (%s)", application_path);
+ _D("loopback_device = (%s)", loopback_device);
+
+ /* check app entry is there in sd card or not. */
+ fp = fopen(loopback_device, "r+");
if (fp == NULL) {
- app2ext_print
- ("App2SD Error: App Entry is not present in SD Card\n");
+ _E("app entry is not present in SD Card");
return APP2EXT_ERROR_INVALID_PACKAGE;
}
fclose(fp);
- /*Get installed app size*/
- curr_size = _app2sd_calculate_file_size(app_path);
- curr_size = (curr_size)/(1024 * 1024);
- if (curr_size==0) {
- app2ext_print
- ("App2SD Error: App Entry is not present in SD Card\n");
+ /* get installed app size*/
+ curr_size = _app2sd_calculate_file_size(loopback_device);
+ curr_size = (curr_size) / (1024 * 1024);
+ if (curr_size == 0) {
+ _E("app entry is not present in SD Card");
return APP2EXT_ERROR_LOOPBACK_DEVICE_UNAVAILABLE;
}
if ((int)curr_size < reqd_disk_size) {
- ret = _app2sd_update_loopback_device_size(pkgid, reqd_disk_size, dir_list);
- if(APP2EXT_SUCCESS !=ret) {
- app2ext_print
- ("App2SD Error: _app2sd_update_loopback_device_size() failed\n");
+ snprintf(temp_pkgid, FILENAME_MAX - 1, "%s.new", pkgid);
+ if (_is_global(uid)) {
+ snprintf(temp_application_path, FILENAME_MAX - 1,
+ "%s/%s", tzplatform_getenv(TZ_SYS_RW_APP), temp_pkgid);
+ snprintf(temp_loopback_device, FILENAME_MAX - 1,
+ "%s/%s", APP2SD_PATH, temp_pkgid);
+ } else {
+ tzplatform_set_user(uid);
+ snprintf(temp_application_path, FILENAME_MAX - 1,
+ "%s/%s", tzplatform_getenv(TZ_USER_APP), temp_pkgid);
+ snprintf(temp_loopback_device, FILENAME_MAX - 1,
+ "%s/%s/%s", APP2SD_PATH,
+ tzplatform_getenv(TZ_USER_NAME), temp_pkgid);
+ tzplatform_reset_user();
+ }
+ ret = _app2sd_update_loopback_device_size(pkgid,
+ loopback_device, application_path, temp_pkgid,
+ temp_loopback_device, temp_application_path,
+ reqd_disk_size, dir_list, uid);
+ if (APP2EXT_SUCCESS != ret) {
+ _E("failed to update loopback device size");
return ret;
}
}
- /*Get the associated device node for SD card applicationer */
- device_node = _app2sd_find_associated_device_node(pkgid);
+ /* get the associated device node for SD card applicationer */
+ device_node = _app2sd_find_associated_device_node(loopback_device);
if (NULL == device_node) {
- /*Do loopback setup */
- device_node = _app2sd_do_loopback_encryption_setup(pkgid);
+ /* do loopback setup */
+ device_node = _app2sd_do_loopback_encryption_setup(pkgid,
+ loopback_device);
if (device_node == NULL) {
- app2ext_print
- ("App2Sd Error : loopback encryption setup failed\n");
+ _E("loopback encryption setup failed");
return APP2EXT_ERROR_DO_LOSETUP;
}
- /*Do mounting */
- ret =
- _app2sd_mount_app_content(pkgid, device_node,
- MOUNT_TYPE_RW, dir_list,
- APP2SD_PRE_UPGRADE);
+
+ /* do mounting */
+ ret = _app2sd_mount_app_content(application_path, pkgid,
+ device_node, MOUNT_TYPE_RW, dir_list,
+ APP2SD_PRE_UPGRADE, uid);
if (ret) {
- app2ext_print("App2Sd Error : Re-mount failed\n");
+ _E("mount failed");
if (device_node) {
free(device_node);
device_node = NULL;
return APP2EXT_ERROR_MOUNT_PATH;
}
} else {
- /*Do re-mounting */
- ret =
- _app2sd_mount_app_content(pkgid, device_node,
- MOUNT_TYPE_RW_REMOUNT, NULL,
- APP2SD_PRE_UPGRADE);
+ /* do re-mounting */
+ ret = _app2sd_mount_app_content(application_path, pkgid,
+ device_node, MOUNT_TYPE_RW_REMOUNT, NULL,
+ APP2SD_PRE_UPGRADE, uid);
if (ret) {
- app2ext_print("App2Sd Error : Re-mount failed\n");
+ _E("remount failed");
if (device_node) {
free(device_node);
device_node = NULL;
return ret;
}
-
-int app2sd_post_app_upgrade(const char *pkgid,
- app2ext_status install_status)
+int app2sd_usr_post_app_upgrade(const char *pkgid,
+ app2ext_status install_status, uid_t uid)
{
char *device_name = NULL;
+ char loopback_device[FILENAME_MAX] = { 0, };
+ char application_path[FILENAME_MAX] = { 0, };
int ret = APP2EXT_SUCCESS;
- /*Validate the function parameter recieved */
+
+ /* validate the function parameter recieved */
if (pkgid == NULL || install_status < APP2EXT_STATUS_FAILED
|| install_status > APP2EXT_STATUS_SUCCESS) {
- app2ext_print("Invalid func parameters\n");
+ _E("invalid func parameters");
return APP2EXT_ERROR_INVALID_ARGUMENTS;
}
- /*Check whether MMC is present or not */
+
+ /* check whether MMC is present or not */
ret = _app2sd_check_mmc_status();
if (ret) {
- app2ext_print("App2Sd Error : MMC not preset OR Not ready %d\n",
- ret);
+ _E("MMC not preset OR Not ready (%d)", ret);
return APP2EXT_ERROR_MMC_STATUS;
}
- /*Get the associated device node for SD card applicationer */
- device_name = _app2sd_find_associated_device_node(pkgid);
+ if (_is_global(uid)) {
+ snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
+ tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
+ snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
+ APP2SD_PATH, pkgid);
+ } else {
+ tzplatform_set_user(uid);
+ snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
+ tzplatform_getenv(TZ_USER_APP), pkgid);
+ snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
+ APP2SD_PATH, tzplatform_getenv(TZ_USER_NAME), pkgid);
+ tzplatform_reset_user();
+ }
+ _D("application_path = (%s)", application_path);
+ _D("loopback_device = (%s)", loopback_device);
+
+ /* get the associated device node for SD card applicationer */
+ device_name = _app2sd_find_associated_device_node(loopback_device);
if (NULL == device_name) {
return APP2EXT_ERROR_FIND_ASSOCIATED_DEVICE_NODE;
}
- ret = _app2sd_unmount_app_content(pkgid);
+
+ ret = _app2sd_unmount_app_content(application_path);
if (ret) {
if (device_name) {
free(device_name);
device_name = NULL;
}
- app2ext_print("Unable to unmount the app content %d\n", ret);
+ _E("unable to unmount the app content (%d)", ret);
return APP2EXT_ERROR_UNMOUNT;
}
- ret = _app2sd_remove_loopback_encryption_setup(pkgid);
+
+ ret = _app2sd_remove_loopback_encryption_setup(loopback_device);
if (ret) {
if (device_name) {
free(device_name);
device_name = NULL;
}
- app2ext_print
- ("Unable to Detach the loopback encryption setup for the application");
+ _E("unable to detach the loopback encryption " \
+ "setup for the application");
return APP2EXT_ERROR_UNMOUNT;
}
+
if (device_name) {
free(device_name);
device_name = NULL;
}
+
return ret;
}
-#if 0
-/**
- * Reserved API for forced cleanup
- *
- */
-int app2sd_force_cleanup(const char *pkgid){
- char *device_name = NULL;
- char buf_dir[FILENAME_MAX] = { 0, };
+int app2sd_usr_force_clean(const char *pkgid, uid_t uid)
+{
+ char loopback_device[FILENAME_MAX] = { 0, };
+ char application_path[FILENAME_MAX] = { 0, };
int ret = APP2EXT_SUCCESS;
- FILE *fp = NULL;
- /*Validate the function parameter recieved */
+ _D("start force_clean [%s]", pkgid);
+
+ /* validate the function parameter recieved */
if (pkgid == NULL) {
- app2ext_print("invalid func parameters\n");
+ _E("invalid func parameters");
return APP2EXT_ERROR_INVALID_ARGUMENTS;
}
- memset((void *)&buf_dir, '\0', FILENAME_MAX);
- snprintf(buf_dir, FILENAME_MAX, "%s%s", APP2SD_PATH, pkgid);
- fp = fopen(buf_dir, "r+");
- if (fp == NULL) {
- app2ext_print("\"%s\" not installed on SD Card\n", pkgid);
- return APP2EXT_ERROR_INVALID_PACKAGE;
- }
- fclose(fp);
- /*Check whether MMC is present or not */
- ret = _app2sd_check_mmc_status();
- if (ret) {
- app2ext_print("App2Sd Error : MMC not preset OR Not ready %d\n",
- ret);
- return APP2EXT_ERROR_MMC_STATUS;
- }
-
- /*Get the associated device node for SD card applicationer */
- device_name = _app2sd_find_associated_device_node(pkgid);
- if (NULL != device_name) {
- free(device_name);
- device_name = NULL;
- ret = _app2sd_unmount_app_content(pkgid);
- if (ret) {
- app2ext_print("Unable to unmount the app content %d\n", ret);
- return APP2EXT_ERROR_UNMOUNT;
- }
- ret = _app2sd_remove_loopback_encryption_setup(pkgid);
- if (ret) {
- app2ext_print
- ("Unable to Detach the loopback encryption setup for the application");
- return APP2EXT_ERROR_UNMOUNT;
- }
- }
- memset((void *)&buf_dir, '\0', FILENAME_MAX);
- snprintf(buf_dir, FILENAME_MAX, "%s%s", APP_INSTALLATION_PATH, pkgid);
- ret = _app2sd_delete_directory(buf_dir);
- if (ret) {
- app2ext_print
- ("App2Sd Error : Unable to delete the directory %s\n",
- buf_dir);
- }
+ sync();
- /*remove passwrd from DB*/
- ret = _app2sd_initialize_db();
- if (ret) {
- app2ext_print("\n app2sd db initialize failed");
- return APP2EXT_ERROR_SQLITE_REGISTRY;
- }
- ret = _app2sd_remove_password_from_db(pkgid);
- if (ret) {
- app2ext_print("cannot remove password from db \n");
- return APP2EXT_ERROR_SQLITE_REGISTRY;
- }
- return ret;
-}
-#endif
-
-int app2sd_force_clean(const char *pkgid)
-{
- char buf_dir[FILENAME_MAX] = { 0, };
- int ret = APP2EXT_SUCCESS;
-
- /*Validate the function parameter recieved */
- if (pkgid == NULL) {
- app2ext_print("Invalid func parameters\n");
- return APP2EXT_ERROR_INVALID_ARGUMENTS;
+ if (_is_global(uid)) {
+ snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
+ tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
+ snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
+ APP2SD_PATH, pkgid);
+ } else {
+ tzplatform_set_user(uid);
+ snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
+ tzplatform_getenv(TZ_USER_APP), pkgid);
+ snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
+ APP2SD_PATH, tzplatform_getenv(TZ_USER_NAME), pkgid);
+ tzplatform_reset_user();
}
- app2ext_print("star force_clean [%s]", pkgid);
+ _D("application_path = (%s)", application_path);
+ _D("loopback_device = (%s)", loopback_device);
- sync(); //2
- /*Unmount the loopback encrypted pseudo device from the application installation path */
- ret = _app2sd_unmount_app_content(pkgid);
+ /* unmount the loopback encrypted pseudo device from the application installation path */
+ ret = _app2sd_unmount_app_content(application_path);
if (ret) {
- app2ext_print("Unable to unmount the app content %d\n", ret);
+ _E("unable to unmount the app content (%d)", ret);
}
- /*Detach the loopback encryption setup for the application */
+ /* detach the loopback encryption setup for the application */
ret = _app2sd_remove_all_loopback_encryption_setups(pkgid);
if (ret) {
- app2ext_print("Unable to Detach the loopback encryption setup for the application");
+ _E("unable to detach the loopback encryption setup for the application");
}
- /*Delete the loopback device from the SD card */
- ret = _app2sd_delete_loopback_device(pkgid);
+ /* delete the loopback device from the SD card */
+ ret = _app2sd_delete_loopback_device(loopback_device);
if (ret) {
- app2ext_print("Unable to Detach the loopback encryption setup for the application");
+ _E("unable to detach the loopback encryption setup for the application");
}
- /*Delete symlink*/
- memset((void *)&buf_dir, '\0', FILENAME_MAX);
- snprintf(buf_dir, FILENAME_MAX, "%s%s", APP_INSTALLATION_PATH, pkgid);
+ /* delete symlink */
+ _app2sd_delete_symlink(application_path);
- _app2sd_delete_symlink(buf_dir);
-
- /*remove passwrd from DB*/
+ /* remove passwrd from DB */
ret = _app2sd_initialize_db();
if (ret) {
- app2ext_print("\n app2sd db initialize failed");
+ _E("app2sd db initialize failed");
}
ret = _app2sd_remove_password_from_db(pkgid);
if (ret) {
- app2ext_print("cannot remove password from db \n");
+ _E("cannot remove password from db");
}
- app2ext_print("finish force_clean");
- return 0;
-}
+ _D("finish force_clean");
-/* This is the plug-in load function. The plugin has to bind its functions to function pointers of handle
- @param[in/out] st_interface Specifies the storage interface.
-*/
-void
-app2ext_on_load(app2ext_interface *st_interface)
-{
- /*Plug-in Binding.*/
- st_interface->pre_install= app2sd_pre_app_install;
- st_interface->post_install= app2sd_post_app_install;
- st_interface->pre_uninstall= app2sd_pre_app_uninstall;
- st_interface->post_uninstall= app2sd_post_app_uninstall;
- st_interface->pre_upgrade= app2sd_pre_app_upgrade;
- st_interface->post_upgrade= app2sd_post_app_upgrade;
- st_interface->move= app2sd_move_installed_app;
- st_interface->force_clean= app2sd_force_clean;
- st_interface->enable= app2sd_on_demand_setup_init;
- st_interface->disable= app2sd_on_demand_setup_exit;
+ return 0;
}
-
*
*/
-#include <app2sd_internals.h>
-#include <app2sd_interface.h>
-
#include <sys/xattr.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <time.h>
#include <dlog.h>
#include <sys/statvfs.h>
+#include <pwd.h>
-extern int app2sd_force_clean(const char *pkgid);
-
-/*
-########### Internal APIs ##################
+#include <app2sd_internals.h>
+#include <app2sd_interface.h>
-static int _app2sd_setup_path(const char *pkgid, const char *dirpath,
- int apppathtype, const char *groupid)
+int _is_global(uid_t uid)
{
- int ret = 0;
-
- if (groupid == NULL) {
- ret = perm_app_setup_path(pkgid, dirpath, apppathtype);
- app2ext_print( "[smack] app_setup_path(), result = [%d]", ret);
- } else {
- ret = perm_app_setup_path(pkgid, dirpath, apppathtype, groupid);
- app2ext_print( "[smack] app_setup_path(), result = [%d]", ret);
- }
-
- return ret;
+ if (uid == OWNER_ROOT || uid == GLOBAL_USER)
+ return 1;
+ else
+ return 0;
}
-*/
-/*
-static int _app2sd_apply_app_smack(const char *pkgid, GList* dir_list, const char *groupid)
+static int _app2sd_setup_path(const char* path, const char *label, uid_t uid)
{
int ret = APP2EXT_SUCCESS;
- GList *list = NULL;
- app2ext_dir_details* dir_detail = NULL;
- char path[FILENAME_MAX] = { 0, };
+ struct passwd pwd;
+ struct passwd *pwd_result;
+ char buf[1024] = { 0, };
- list = g_list_first(dir_list);
- while (list) {
- dir_detail = (app2ext_dir_details *)list->data;
- if (dir_detail && dir_detail->name
- && dir_detail->type == APP2EXT_DIR_RO) {
- snprintf(path, FILENAME_MAX, "%s%s/%s",APP_INSTALLATION_PATH, pkgid, dir_detail->name);
- ret = _app2sd_setup_path(pkgid, path, PERM_APP_PATH_ANY_LABEL, groupid);
- if (ret) {
- app2ext_print ("App2Sd Error : unable to smack %s\n", path);
- return APP2EXT_ERROR_MOVE;
- }
- }
- list = g_list_next(list);
+ ret = lsetxattr(path, "security.SMACK64TRANSMUTE", "TRUE", 4, 0);
+ if (ret < 0) {
+ _E("set transmute error");
+ return APP2EXT_ERROR_ACCESS_FILE;
+ }
+ ret = lsetxattr(path, "security.SMACK64", label, strlen(label), 0);
+ if (ret < 0) {
+ _E("set label(%s) error", label);
+ return APP2EXT_ERROR_ACCESS_FILE;
+ }
+ ret = chmod(path, 0755);
+ if (ret < 0) {
+ _E("change file permission error");
+ return APP2EXT_ERROR_ACCESS_FILE;
}
- return APP2EXT_SUCCESS;
+ ret = getpwuid_r(uid, &pwd, buf, sizeof(buf), &pwd_result);
+ if (ret != 0 || pwd_result == NULL) {
+ _E("get uid failed(%d)", ret);
+ return APP2EXT_ERROR_ACCESS_FILE;
+ }
+
+ _D("uid(%d), gid(%d)", uid, pwd.pw_gid);
+ ret = chown(path, uid, pwd.pw_gid);
+ if (ret < 0) {
+ _E("change file owner error");
+ return APP2EXT_ERROR_ACCESS_FILE;
+ }
+
+ return ret;
}
-*/
-/*
-static int _app2sd_apply_mmc_smack(const char *pkgid, GList* dir_list, const char *groupid)
+static int _app2sd_apply_app_smack(const char *application_path,
+ const char *pkgid, GList* dir_list, uid_t uid)
{
int ret = APP2EXT_SUCCESS;
GList *list = NULL;
app2ext_dir_details* dir_detail = NULL;
- char path[FILENAME_MAX] = { 0, };
+ char temp_dir_path[FILENAME_MAX] = { 0, };
+ char label[FILENAME_MAX] = { 0, };
+ snprintf(label, FILENAME_MAX, "User::Pkg::%s::RO", pkgid);
list = g_list_first(dir_list);
while (list) {
dir_detail = (app2ext_dir_details *)list->data;
if (dir_detail && dir_detail->name
&& dir_detail->type == APP2EXT_DIR_RO) {
- snprintf(path, FILENAME_MAX, "%s%s/.mmc/%s",APP_INSTALLATION_PATH, pkgid, dir_detail->name);
-
- ret = _app2sd_setup_path(pkgid, path, PERM_APP_PATH_ANY_LABEL, groupid);
+ memset(temp_dir_path, '\0', FILENAME_MAX);
+ snprintf(temp_dir_path, FILENAME_MAX,
+ "%s/%s", application_path,
+ dir_detail->name);
+ _D("set label(%s) to path(%s)",
+ label, temp_dir_path);
+ ret = _app2sd_setup_path(temp_dir_path, /* label */ "*", uid);
if (ret) {
- app2ext_print ("App2Sd Error : unable to smack %s\n", path);
+ _E("unable to smack (%s)", label);
return APP2EXT_ERROR_MOVE;
}
}
return APP2EXT_SUCCESS;
}
-*/
-char *_app2sd_find_associated_device_node(const char *pkgid)
+char *_app2sd_find_associated_device_node(const char *loopback_device)
{
char *ret_result = NULL;
char delims[] = ":";
char *result = NULL;
- char app_path[FILENAME_MAX] = { '\0' };
- char dev[FILENAME_MAX] = {0,};
+ char dev[FILENAME_MAX] = { 0, };
char *devnode = NULL;
- snprintf(app_path, FILENAME_MAX, "%s%s", APP2SD_PATH,
- pkgid);
- app2ext_print("sdcard app_path = (%s)\n", app_path);
- result = (char *)_app2sd_find_associated_device(app_path);
+
+ result = (char *)_app2sd_find_associated_device(loopback_device);
if (result == NULL) {
- app2ext_print("App2SD info! there is no the associated File with [%s]\n", pkgid);
+ _D("there is no the associated file (%s)", loopback_device);
return NULL;
}
+
/* process the string*/
- app2ext_print("result = (%s)\n", result);
- snprintf(dev, FILENAME_MAX-1, "%s", result);
- if (strstr(dev, "/dev") == NULL) {
- app2ext_print("App2SD Error! Unable to find the associated File\n");
+ snprintf(dev, FILENAME_MAX - 1, "%s", result);
+ if (strstr(dev, "dev") == NULL) {
+ _E("unable to find the associated file");
free(result);
return NULL;
} else {
if (ret_result)
devnode = strdup(ret_result);
}
+
free(result);
+
return devnode;
}
FILE *fp = NULL;
result = (char *)_app2sd_find_free_device();
+ _D("find_free_device(%s)", result);
+
/* validate the result */
if (result == NULL || strstr(result, "/dev") == NULL) {
- app2ext_print("No device found, creating device node...\n");
+ _D("no device found, creating device node");
if (result) {
free(result);
while ((fp = fopen(dev_path, "r+")) != NULL) {
count = count + 1;
snprintf(dev_path, BUF_SIZE, "/dev/loop%d", count);
- app2ext_print("next dev path for checking is %s\n",
+ _D("next dev path for checking is (%s)",
dev_path);
fclose(fp);
}
- app2ext_print("Device node candidate is %s \n", dev_path);
+ _D("device node candidate is (%s)", dev_path);
dev_t dev_node;
dev_node = makedev(DEV_MAJOR, count);
ret = mknod(dev_path, S_IFBLK | mode, dev_node);
if (ret < 0) {
- app2ext_print
- ("Error while creating the device node: errno is %d\n",
+ _E("error while creating the device node: errno is (%d)",
errno);
return NULL;
}
ret_result = (char *)malloc(strlen(dev_path) + 1);
if (ret_result == NULL) {
- app2ext_print("Unable to allocate memory\n");
+ _E("unable to allocate memory");
return NULL;
}
memset(ret_result, '\0', strlen(dev_path) + 1);
} else {
ret_result = (char *)malloc(strlen(result) + 1);
if (ret_result == NULL) {
- app2ext_print("Malloc failed!\n");
+ _E("malloc failed");
free(result);
result = NULL;
return NULL;
return ret_result;
}
-char *_app2sd_do_loopback_encryption_setup(const char *pkgid)
+char *_app2sd_do_loopback_encryption_setup(const char *pkgid,
+ const char *loopback_device)
{
int ret = APP2EXT_SUCCESS;
char *passwd = NULL;
- char app_path[FILENAME_MAX] = { '\0' };
char *result = NULL;
char *device_node = NULL;
+
if (pkgid == NULL) {
- app2ext_print("App2Sd Error: Invalid argument\n");
+ _E("invalid argument");
return NULL;
}
- snprintf(app_path, FILENAME_MAX, "%s%s", APP2SD_PATH,
- pkgid);
/* Get password for loopback encryption */
ret = _app2sd_initialize_db();
if (ret) {
- app2ext_print("\n app2sd db initialize failed");
+ _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) {
- app2ext_print
- ("App2Sd Error: Unable to generate password\n");
+ _E("unable to generate password");
return NULL;
} else {
- app2ext_print("Password is %s\n", passwd);
if ((ret = _app2sd_set_password_in_db(pkgid,
- passwd)) < 0) {
- app2ext_print
- ("App2Sd Error: Unable to save password\n");
+ passwd)) < 0) {
+ _E("unable to save password");
free(passwd);
passwd = NULL;
return NULL;
if (NULL == device_node) {
free(passwd);
passwd = NULL;
- app2ext_print
- ("App2Sd Error: Unable to find free loopback node\n");
+ _E("unable to find free loopback node");
return NULL;
}
- result = (char *)_app2sd_encrypt_device(device_node, app_path, passwd);
+
+ _D("device_node (%s)", device_node);
+
+ result = (char *)_app2sd_encrypt_device(device_node,
+ loopback_device, passwd);
if (result == NULL) {
- app2ext_print("App2Sd Error: Encryption failed!\n\n");
+ _E("encryption failed");
free(passwd);
passwd = NULL;
return NULL;
} else {
+ _D("result (%s)", result);
free(result);
result = NULL;
free(passwd);
}
}
-char *_app2sd_do_loopback_duplicate_encryption_setup(const char *pkgid, const char * dup_appname)
+char *_app2sd_do_loopback_duplicate_encryption_setup(const char *pkgid,
+ const char *temp_pkgid,
+ const char *temp_loopback_device)
{
int ret = APP2EXT_SUCCESS;
char *passwd = NULL;
- char app_path[FILENAME_MAX] = { '\0' };
char *result = NULL;
char *device_node = NULL;
- if (pkgid == NULL || dup_appname == NULL) {
- app2ext_print("App2Sd Error: Invalid argument\n");
+
+ if (pkgid == NULL || temp_pkgid == NULL ||
+ temp_loopback_device == NULL) {
+ _E("invalid argument");
return NULL;
}
- snprintf(app_path, FILENAME_MAX, "%s%s", APP2SD_PATH,
- dup_appname);
- /* Get password for loopback encryption */
+ /* get password for loopback encryption */
ret = _app2sd_initialize_db();
if (ret) {
- app2ext_print("\n app2sd db initialize failed");
+ _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) {
- app2ext_print
- ("App2Sd Error: Unable to generate password\n");
+ _E("unable to generate password");
return NULL;
} else {
- app2ext_print("Password is %s\n", passwd);
+ _E("password is (%s)", passwd);
if ((ret = _app2sd_set_password_in_db(pkgid,
- passwd)) < 0) {
- app2ext_print
- ("App2Sd Error: Unable to save password\n");
+ passwd)) < 0) {
+ _E("unable to save password");
free(passwd);
passwd = NULL;
return NULL;
}
}
- /* Get Free device node*/
+
+ /* get free device node*/
device_node = _app2sd_create_loopdevice_node();
if (NULL == device_node) {
free(passwd);
passwd = NULL;
- app2ext_print
- ("App2Sd Error: Unable to find free loopback node\n");
+ _E("unable to find free loopback node");
return NULL;
}
- result = (char *)_app2sd_encrypt_device(device_node, app_path, passwd);
+ result = (char *)_app2sd_encrypt_device(device_node,
+ temp_loopback_device, passwd);
if (result == NULL) {
- app2ext_print("App2Sd Error: Encryption failed!\n\n");
+ _E("encryption failed");
free(passwd);
passwd = NULL;
return NULL;
passwd = NULL;
return device_node;
} else {
- app2ext_print("App2Sd Error: Error is %s\n", result);
+ _E("error is (%s)", result);
free(result);
result = NULL;
free(passwd);
return NULL;
}
}
+
return device_node;
}
-int _app2sd_remove_loopback_encryption_setup(const char *pkgid)
+int _app2sd_remove_loopback_encryption_setup(const char *loopback_device)
{
int ret = APP2EXT_SUCCESS;
char *result = NULL;
char *dev_node = NULL;
- if ((dev_node = _app2sd_find_associated_device_node(pkgid)) == NULL) {
- app2ext_print("Unable to find the association\n");
+
+ if ((dev_node = _app2sd_find_associated_device_node(loopback_device))
+ == NULL) {
+ _E("Unable to find the association");
ret = APP2EXT_ERROR_FIND_ASSOCIATED_DEVICE_NODE;
}
+
result = (char *)_app2sd_detach_loop_device(dev_node);
if (result == NULL) {
- app2ext_print("App2sd Error: Error in detaching\n");
+ _E("error in detaching");
ret = APP2EXT_ERROR_DETACH_LOOPBACK_DEVICE;
} else {
free(result);
result = NULL;
}
+
if (dev_node) {
free(dev_node);
dev_node = NULL;
}
+
return ret;
}
-int _app2sd_remove_all_loopback_encryption_setups(const char *pkgid)
+int _app2sd_remove_all_loopback_encryption_setups(const char *loopback_device)
{
int ret = APP2EXT_SUCCESS;
char *result = NULL;
char *dev_node = NULL;
while(1) {
- if ((dev_node = _app2sd_find_associated_device_node(pkgid)) == NULL) {
- app2ext_print("finish to find the association\n");
+ if ((dev_node =
+ _app2sd_find_associated_device_node(loopback_device))
+ == NULL) {
+ _E("finish to find the association");
ret = APP2EXT_SUCCESS;
break;
}
- app2ext_print("find node :: %s \n", dev_node);
+ _D("find node (%s)", dev_node);
result = (char *)_app2sd_detach_loop_device(dev_node);
if (result == NULL) {
- app2ext_print("App2sd Error: Error in detaching\n");
+ _E("error in detaching");
ret = APP2EXT_ERROR_DETACH_LOOPBACK_DEVICE;
break;
} else {
dev_node = NULL;
}
}
+
return ret;
}
-int _app2sd_create_loopback_device(const char *pkgid, int size)
+int _app2sd_create_loopback_device(const char *pkgid,
+ const char *loopback_device, int size)
{
int ret = APP2EXT_SUCCESS;
char command[FILENAME_MAX] = { 0, };
- mode_t mode = DIR_PERMS;
- char external_storage_path[FILENAME_MAX] = { 0, };
char buff[BUF_SIZE] = { 0, };
- char app_path[FILENAME_MAX] = { 0, };
FILE *fp = NULL;
if (NULL == pkgid || size <= 0) {
- app2ext_print("App2Sd Error: Invalid argument\n");
+ _E("invalid argument");
return APP2EXT_ERROR_INVALID_ARGUMENTS;
}
- snprintf(command, FILENAME_MAX, "of=%s%s", APP2SD_PATH,
- pkgid);
- snprintf(buff, BUF_SIZE, "count=%d", size);
+ 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 };
- snprintf(external_storage_path, FILENAME_MAX, "%s",
- APP2SD_PATH);
- ret = mkdir(external_storage_path, mode);
- if (ret) {
- if (errno != EEXIST) {
- app2ext_print
- ("App2sd Error : Create directory failed, error no is %d\n",
- errno);
- return APP2EXT_ERROR_CREATE_DIRECTORY;
- }
- }
- snprintf(app_path, FILENAME_MAX, "%s%s", APP2SD_PATH,
- pkgid);
- if ((fp = fopen(app_path, "r+")) != NULL) {
- app2ext_print("Application already exists %s\n", app_path);
+
+ if ((fp = fopen(loopback_device, "r+")) != NULL) {
+ _E("encrypted file already exists (%s)",
+ loopback_device);
fclose(fp);
return APP2EXT_ERROR_PKG_EXISTS;
}
ret = _xsystem(argv1);
- if (ret) {
- app2ext_print("App2Sd Error : command \"%s\" failed \n",
- command);
- return ret;
- }
+ if (ret)
+ _E("command (%s) failed", command);
+
return ret;
}
-int _app2sd_delete_loopback_device(const char *pkgid)
+int _app2sd_delete_loopback_device(const char *loopback_device)
{
int ret = APP2EXT_SUCCESS;
- char loopback_device[FILENAME_MAX] = { 0, };
-
- snprintf(loopback_device, FILENAME_MAX, "%s%s", APP2SD_PATH,
- pkgid);
ret = unlink(loopback_device);
if (ret) {
if (errno == ENOENT) {
- app2ext_print("Unable to access file %s\n", loopback_device);
+ _E("unable to access file (%s)", loopback_device);
} else {
- app2ext_print("Unable to delete %s\n", loopback_device);
+ _E("unable to delete (%s)", loopback_device);
return APP2EXT_ERROR_DELETE_LOOPBACK_DEVICE;
}
}
+
return ret;
}
char err_buf[1024] = {0,};
if (device_path == NULL) {
- app2ext_print("App2Sd Error: invalid param [NULL]\n");
+ _E("invalid param");
return APP2EXT_ERROR_INVALID_ARGUMENTS;
}
fp = fopen(device_path, "r+");
if (fp == NULL) {
strerror_r(errno, err_buf, sizeof(err_buf));
- app2ext_print
- ("App2sd Error: Unable to access %s [System errono is %d.....%s]\n",
+ _E("unable to access (%s) error is (%d, %s)",
device_path, errno, err_buf);
return APP2EXT_ERROR_ACCESS_FILE;
} else {
ret = _xsystem(argv);
if (ret) {
strerror_r(errno, err_buf, sizeof(err_buf));
- app2ext_print
- ("App2Sd Error : creating file system failed [System error is %s\n",
+ _E("creating file system failed, error is (%s)",
err_buf);
return APP2EXT_ERROR_CREATE_FS;
}
return ret;
}
-static int _app2sd_create_dir_with_link(const char *pkgid,
- const char *dir_name)
+static int _app2sd_create_dir_with_link(const char *application_path,
+ const char *pkgid, const char *dir_name, uid_t uid)
{
mode_t mode = DIR_PERMS;
int ret = APP2EXT_SUCCESS;
- char app_dir_mmc_path[FILENAME_MAX] = { 0, };
- char app_dir_path[FILENAME_MAX] = { 0, };
- snprintf(app_dir_mmc_path, FILENAME_MAX, "%s%s/.mmc/%s",APP_INSTALLATION_PATH,
- pkgid, dir_name);
- snprintf(app_dir_path, FILENAME_MAX, "%s%s/%s", APP_INSTALLATION_PATH, pkgid,
- dir_name);
-
- ret = mkdir(app_dir_mmc_path, mode);
+ char application_dir_mmc_path[FILENAME_MAX] = { 0, };
+ char application_dir_path[FILENAME_MAX] = { 0, };
+ char label[FILENAME_MAX] = { 0, };
+
+ snprintf(application_dir_mmc_path, FILENAME_MAX - 1, "%s/.mmc/%s",
+ application_path, dir_name);
+ snprintf(application_dir_path, FILENAME_MAX, "%s/%s",
+ application_path, dir_name);
+ snprintf(label, FILENAME_MAX, "User::Pkg::%s::RO", pkgid);
+
+ ret = mkdir(application_dir_mmc_path, mode);
if (ret) {
if (errno != EEXIST) {
- app2ext_print
- ("App2sd Error : Create directory failed, error no is %d\n",
- errno);
+ _E("create directory failed," \
+ " error no is (%d)", errno);
return APP2EXT_ERROR_CREATE_DIRECTORY;
}
}
- if ((ret = symlink(app_dir_mmc_path, app_dir_path)) < 0) {
+ if ((ret = symlink(application_dir_mmc_path,
+ application_dir_path)) < 0) {
if (errno == EEXIST) {
- app2ext_print
- ("App2sd : File with Symlink name present %s\n",
- app_dir_path);
+ _D("file with symlink name present (%s)",
+ application_dir_path);
} else {
- app2ext_print
- ("A2Sd Error : Symbolic link creation failed, error no is %d\n",
- errno);
+ _E("symbolic link creation "
+ "failed, error no is (%d)", errno);
return APP2EXT_ERROR_CREATE_SYMLINK;
}
}
- /* TODO */
- /*
- ret = _app2sd_setup_path(pkgid, app_dir_path, PERM_APP_PATH_ANY_LABEL, pkgid);
+ ret = _app2sd_setup_path(application_dir_path, /* label */ "*", uid);
if (ret) {
- app2ext_print ("App2Sd Error : unable to smack %s\n", app_dir_path);
+ _E ("unable to smack (%s)", application_dir_path);
return APP2EXT_ERROR_MOVE;
}
- ret = _app2sd_setup_path(pkgid, app_dir_mmc_path, PERM_APP_PATH_ANY_LABEL, pkgid);
+ ret = _app2sd_setup_path(application_dir_mmc_path, /* label */ "*", uid);
if (ret) {
- app2ext_print ("App2Sd Error : unable to smack %s\n", app_dir_mmc_path);
+ _E ("unable to smack (%s)", application_dir_mmc_path);
return APP2EXT_ERROR_MOVE;
}
- */
return ret;
}
-int _app2sd_create_directory_entry(const char *pkgid, GList* dir_list)
+static int _app2sd_create_directory_entry(const char *application_path,
+ const char *pkgid, GList* dir_list, uid_t uid)
{
int ret = APP2EXT_SUCCESS;
- char app_dir_path[FILENAME_MAX] = { 0, };
GList *list = NULL;
app2ext_dir_details* dir_detail = NULL;
- snprintf(app_dir_path, FILENAME_MAX, "%s%s", APP_INSTALLATION_PATH,
- pkgid);
-
list = g_list_first(dir_list);
while (list) {
dir_detail = (app2ext_dir_details *)list->data;
if (dir_detail && dir_detail->name
&& dir_detail->type == APP2EXT_DIR_RO) {
- ret = _app2sd_create_dir_with_link(pkgid, dir_detail->name);
+ ret = _app2sd_create_dir_with_link(application_path,
+ pkgid, dir_detail->name, uid);
if (ret) {
return ret;
}
return APP2EXT_SUCCESS;
}
-
-/*
- *
- * _app2sd_mount_app_content
- This function is to create the path for mmc and mount the content
-Example usage: _app2sd_mount_app_content("deb.com.samsung.helloworld","/dev/loop0",MOUNT_TYPE_RD)
-*/
-int _app2sd_mount_app_content(const char *pkgid, const char *dev,
- int mount_type, GList* dir_list, app2sd_cmd cmd)
+int _app2sd_mount_app_content(const char *application_path, const char *pkgid,
+ const char *dev, int mount_type, GList* dir_list,
+ app2sd_cmd cmd, uid_t uid)
{
int ret = APP2EXT_SUCCESS;
mode_t mode = DIR_PERMS;
- char app_dir_path[FILENAME_MAX] = { 0, };
- char app_dir_mmc_path[FILENAME_MAX] = { 0, };
+ char application_mmc_path[FILENAME_MAX] = { 0, };
+ char temp_path[FILENAME_MAX] = { 0, };
+ char label[FILENAME_MAX] = { 0, };
struct timespec time = {
.tv_sec = 0,
.tv_nsec = 1000 * 1000 * 200
};
- if (NULL == pkgid || NULL == dev) {
- app2ext_print("App2Sd Error : Input param is NULL %s %s \n",
- pkgid, dev);
+ if (NULL == dev) {
+ _E("input param is NULL (%s)",
+ dev);
return APP2EXT_ERROR_INVALID_ARGUMENTS;
}
- snprintf(app_dir_path, FILENAME_MAX, "%s%s", APP_INSTALLATION_PATH, pkgid);
- ret = mkdir(app_dir_path, mode);
+
+ ret = mkdir(application_path, mode);
if (ret) {
if (errno != EEXIST) {
- app2ext_print
- ("App2Sd Error : Create directory failed, error no is %d\n",
- errno);
+ _E("create directory failed," \
+ " error no is (%d)", errno);
return APP2EXT_ERROR_CREATE_DIRECTORY;
}
+ } else {
+ ret = _app2sd_setup_path(application_path, "*", uid);
+ if (ret) {
+ _E ("unable to smack (%s)", application_path);
+ return APP2EXT_ERROR_ACCESS_FILE;
+ }
}
- snprintf(app_dir_mmc_path, FILENAME_MAX, "%s%s/.mmc", APP_INSTALLATION_PATH, pkgid);
- ret = mkdir(app_dir_mmc_path, mode);
+
+ snprintf(application_mmc_path, FILENAME_MAX - 1, "%s/.mmc",
+ application_path);
+ ret = mkdir(application_mmc_path, mode);
if (ret) {
if (errno != EEXIST) {
- app2ext_print
- ("App2Sd Error : Create directory failed, error no is %d\n",
- errno);
+ _E("create directory failed," \
+ " error no is (%d)", errno);
return APP2EXT_ERROR_CREATE_DIRECTORY;
}
+ } else {
+ snprintf(label, FILENAME_MAX, "User::Pkg::%s::RO", pkgid);
+ ret = _app2sd_setup_path(application_mmc_path, /* label */ "*", uid);
+ if (ret) {
+ _E ("unable to smack (%s)", application_mmc_path);
+ return APP2EXT_ERROR_ACCESS_FILE;
+ }
}
nanosleep(&time, NULL); /* 200ms sleep */
- app2ext_print ("App2Sd info : give a delay for mount\n");
+ _D("give a delay for mount");
switch (mount_type) {
case MOUNT_TYPE_RD:
- {
- if ((ret =
- mount(dev, app_dir_mmc_path, FS_TYPE,
- MS_MGC_VAL | MS_RDONLY | MS_NOSUID, NULL)) < 0) {
- app2ext_print
- ("App2Sd Error : Read Only Mount failed [System Erro no is %d], dev is %s path is %s\n",
- errno, dev, app_dir_mmc_path);
- ret = APP2EXT_ERROR_MOUNT;
- }
- break;
+ if ((ret = mount(dev, application_mmc_path, FS_TYPE,
+ MS_MGC_VAL | MS_RDONLY | MS_NOSUID, NULL)) < 0) {
+ _E("read only mount failed, " \
+ "errono is (%d), " \
+ "dev is (%s) path is (%s)",
+ errno, dev, application_mmc_path);
+ ret = APP2EXT_ERROR_MOUNT;
}
+ break;
case MOUNT_TYPE_RW:
- {
- if ((ret =
- mount(dev, app_dir_mmc_path, FS_TYPE, MS_MGC_VAL | MS_NOSUID,
- NULL)) < 0) {
- app2ext_print
- ("App2Sd Error : Read Write Mount failed [System Erro no is %d]\n",
- errno);
- ret = APP2EXT_ERROR_MOUNT;
- }
- break;
+ if ((ret = mount(dev, application_mmc_path, FS_TYPE,
+ MS_MGC_VAL | MS_NOSUID, NULL)) < 0) {
+ _E("read write mount failed, " \
+ "errono is (%d)", errno);
+ ret = APP2EXT_ERROR_MOUNT;
}
+ break;
case MOUNT_TYPE_RW_NOEXEC:
- {
- if ((ret =
- mount(dev, app_dir_mmc_path, FS_TYPE,
- MS_MGC_VAL | MS_NOEXEC | MS_NOSUID, NULL)) < 0) {
- app2ext_print
- ("App2Sd Error : RWX Mount failed [System Erro no is %d]\n",
- errno);
- ret = APP2EXT_ERROR_MOUNT;
- }
- break;
+ if ((ret = mount(dev, application_mmc_path, FS_TYPE,
+ MS_MGC_VAL | MS_NOEXEC | MS_NOSUID, NULL)) < 0) {
+ _E("rwnx mount failed " \
+ "errono is (%d)", errno);
+ ret = APP2EXT_ERROR_MOUNT;
}
+ break;
case MOUNT_TYPE_RD_REMOUNT:
- {
- if ((ret =
- mount(dev, app_dir_mmc_path, FS_TYPE,
- MS_MGC_VAL | MS_RDONLY | MS_REMOUNT | MS_NOSUID,
- NULL)) < 0) {
- app2ext_print
- ("App2Sd Error : RWX Mount failed [System Erro no is %d]\n",
- errno);
- ret = APP2EXT_ERROR_MOUNT;
- }
- break;
+ if ((ret = mount(dev, application_mmc_path, FS_TYPE,
+ MS_MGC_VAL | MS_RDONLY | MS_REMOUNT | MS_NOSUID,
+ NULL)) < 0) {
+ _E("read remount failed "
+ "errono is (%d)", errno);
+ ret = APP2EXT_ERROR_MOUNT;
}
+ break;
case MOUNT_TYPE_RW_REMOUNT:
- {
- if ((ret =
- mount(dev, app_dir_mmc_path, FS_TYPE,
- MS_MGC_VAL | MS_REMOUNT | MS_NOSUID, NULL)) < 0) {
- app2ext_print
- ("App2Sd Error : RWX Mount failed [System Erro no is %d]\n",
- errno);
+ if ((ret = mount(dev, application_mmc_path, FS_TYPE,
+ MS_MGC_VAL | MS_REMOUNT | MS_NOSUID, NULL)) < 0) {
+ _E("read write remount failed "
+ "erro no is (%d)", errno);
ret = APP2EXT_ERROR_MOUNT;
- }
- break;
}
-
+ break;
default:
- {
- app2ext_print("App2Sd Error: Invalid mount type\n");
- break;
+ _E("invalid mount type");
+ break;
+ }
+
+ if (cmd == APP2SD_PRE_UNINSTALL || cmd == APP2SD_PRE_UPGRADE) {
+ /* delete lost+found dir */
+ snprintf(temp_path, FILENAME_MAX - 1, "%s/lost+found",
+ application_mmc_path);
+ ret = _app2sd_delete_directory(temp_path);
+ if (ret && ret != APP2EXT_ERROR_ACCESS_FILE) {
+ _E("unable to delete (%s)", temp_path);
+ return APP2EXT_ERROR_DELETE_DIRECTORY;
}
}
- if (cmd == APP2SD_PRE_INSTALL || cmd == APP2SD_MOVE_APP_TO_MMC || cmd == APP2SD_PRE_UPGRADE) {
- ret = _app2sd_create_directory_entry(pkgid, dir_list);
+
+ if (cmd == APP2SD_PRE_INSTALL || cmd == APP2SD_MOVE_APP_TO_MMC ||
+ cmd == APP2SD_PRE_UPGRADE) {
+ ret = _app2sd_create_directory_entry(application_path,
+ pkgid, dir_list, uid);
}
+
return ret;
}
-int _app2sd_unmount_app_content(const char *pkgid)
+int _app2sd_unmount_app_content(const char *application_path)
{
int ret = APP2EXT_SUCCESS;
- char app_dir_mmc_path[FILENAME_MAX] = { 0, };
+ char application_dir_mmc_path[FILENAME_MAX] = { 0, };
+ char err_buf[1024] = {0,};
- snprintf(app_dir_mmc_path, FILENAME_MAX, "%s%s/.mmc", APP_INSTALLATION_PATH, pkgid);
- if ((ret = umount(app_dir_mmc_path)) < 0) {
- char err_buf[1024] = {0,};
+ snprintf(application_dir_mmc_path, FILENAME_MAX - 1, "%s/.mmc",
+ application_path);
+ if ((ret = umount(application_dir_mmc_path)) < 0) {
strerror_r(errno, err_buf, sizeof(err_buf));
- app2ext_print("Unable to umount the dir %s\n", err_buf);
+ _E("unable to umount the dir, ret(%d) error(%d, %s)",
+ ret, errno, err_buf);
}
+
return ret;
}
if (ret && ret != APP2EXT_ERROR_ACCESS_FILE) {
char err_buf[1024] = {0,};
strerror_r(errno, err_buf, sizeof(err_buf));
- app2ext_print("App2Sd Error : unable to copy from %s to %s .....err is %s\n",
- src_path, arch_path, err_buf);
+ _E("unable to copy from (%s) to (%s), err is (%s)",
+ src_path, arch_path, err_buf);
return APP2EXT_ERROR_MOVE;
}
ret = _app2sd_delete_directory((char *)src_path);
if (ret && ret != APP2EXT_ERROR_ACCESS_FILE) {
- app2ext_print("App2Sd Error : unable to delete %s \n", src_path);
+ _E("unable to delete (%s)", src_path);
return APP2EXT_ERROR_DELETE_DIRECTORY;
}
return ret;
}
-int _app2sd_move_app_to_external(const char *pkgid, GList* dir_list)
+int _app2sd_move_app_to_external(const char *pkgid, GList* dir_list, uid_t uid)
{
int ret = APP2EXT_SUCCESS;
- char app_path[FILENAME_MAX] = { 0, };
- char path[FILENAME_MAX] = { 0, };
- char app_mmc_path[FILENAME_MAX] = { 0, };
- char app_archive_path[FILENAME_MAX] = { 0, };
- char mmc_path[FILENAME_MAX] = { 0, };
+ char temp_dir_path[FILENAME_MAX] = { 0, };
+ char application_mmc_path[FILENAME_MAX] = { 0, };
+ char application_archive_path[FILENAME_MAX] = { 0, };
+ char application_path[FILENAME_MAX] = { 0, };
+ char loopback_device[FILENAME_MAX] = { 0, };
unsigned long long total_size = 0;
int reqd_size = 0;
int reqd_disk_size = 0;
FILE *fp = NULL;
GList *list = NULL;
app2ext_dir_details* dir_detail = NULL;
+ char err_buf[1024] = {0,};
- /* Check whether MMC is present or not */
+ /* check whether MMC is present or not */
ret = _app2sd_check_mmc_status();
if (ret) {
- app2ext_print
- ("App2Sd Error : MMC not preset OR Not ready %d\n",
- ret);
+ _E("MMC not preset OR Not ready(%d)", ret);
return APP2EXT_ERROR_MMC_STATUS;
}
- snprintf(mmc_path, FILENAME_MAX,
- "%s%s", APP2SD_PATH, pkgid);
+ if (_is_global(uid)) {
+ snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
+ tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
+ snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
+ APP2SD_PATH, pkgid);
+ } else {
+ tzplatform_set_user(uid);
+ snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
+ tzplatform_getenv(TZ_USER_APP), pkgid);
+ snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
+ APP2SD_PATH, tzplatform_getenv(TZ_USER_NAME), pkgid);
+ tzplatform_reset_user();
+ }
+ _D("application_path = (%s)", application_path);
+ _D("loopback_device = (%s)", loopback_device);
/* check whether application is in external memory or not */
- fp = fopen(mmc_path, "r+");
+ fp = fopen(loopback_device, "r+");
if (fp != NULL) {
- app2ext_print
- ("Already %s entry is present in the SD Card, delete entry and go on without return\n",
- pkgid);
+ _W("Already %s entry is present in the SD Card, " \
+ "delete entry and go on without return", pkgid);
fclose(fp);
- app2sd_force_clean(pkgid);
+ app2sd_usr_force_clean(pkgid, uid);
}
- snprintf(app_mmc_path, FILENAME_MAX,
- "%s%s/.mmc", APP_INSTALLATION_PATH, pkgid);
- snprintf(app_archive_path, FILENAME_MAX,
- "%s%s/.archive", APP_INSTALLATION_PATH, pkgid);
+ snprintf(application_mmc_path, FILENAME_MAX - 1, "%s/.mmc",
+ application_path);
+ snprintf(application_archive_path, FILENAME_MAX - 1, "%s/.archive",
+ application_path);
+ _D("application_mmc_path = (%s)", application_mmc_path);
+ _D("application_archive_path = (%s)", application_archive_path);
- ret = mkdir(app_archive_path, mode);
+ ret = mkdir(application_archive_path, mode);
if (ret) {
if (errno != EEXIST) {
- app2ext_print
- ("App2sd Error: Unable to create directory for archiving, error no is %d\n",
- errno);
+ _E("unable to create directory for archiving," \
+ " error(%d)", errno);
+ return APP2EXT_ERROR_CREATE_DIRECTORY;
}
}
dir_detail = (app2ext_dir_details *)list->data;
if (dir_detail && dir_detail->name
&& dir_detail->type == APP2EXT_DIR_RO) {
- memset((void *)&app_path, '\0',
- FILENAME_MAX);
- snprintf(app_path, FILENAME_MAX,
- "%s%s/%s",APP_INSTALLATION_PATH,
- pkgid,
+ memset(temp_dir_path, '\0', FILENAME_MAX);
+ snprintf(temp_dir_path, FILENAME_MAX,
+ "%s/%s", application_path,
dir_detail->name);
+ _D("cal size of app dirs, temp_dir_path(%s)",
+ temp_dir_path);
total_size +=
- _app2sd_calculate_dir_size
- (app_path);
+ _app2sd_calculate_dir_size(temp_dir_path);
}
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 */
- ret =
- _app2sd_get_available_free_memory
- (MMC_PATH, &free_mmc_mem);
+ /* find avialable free memory in the MMC card */
+ ret = _app2sd_get_available_free_memory(MMC_PATH, &free_mmc_mem);
if (ret) {
- app2ext_print
- ("App2Sd Error : Unable to get available free memory in MMC %d\n",
- ret);
+ _E("unable to get available free memory in MMC (%d)", ret);
return APP2EXT_ERROR_MMC_STATUS;
}
- /* If avaialalbe free memory in MMC is less than required size + 5MB , return error */
+ /* if avaialalbe free memory in MMC is less than
+ * required size + 5MB, return error
+ */
if (reqd_disk_size > free_mmc_mem) {
- app2ext_print
- ("App2Sd Error : Insufficient memory in MMC for application installation %d\n",
- ret);
+ _E("insufficient memory in MMC for application installation (%d)",
+ ret);
return APP2EXT_ERROR_MMC_INSUFFICIENT_MEMORY;
}
- /* Create a loopback device */
- ret =
- _app2sd_create_loopback_device(pkgid, (reqd_disk_size+PKG_BUF_SIZE));
+ /* create a loopback device */
+ ret = _app2sd_create_loopback_device(pkgid, loopback_device,
+ (reqd_disk_size + PKG_BUF_SIZE));
if (ret) {
- app2ext_print
- ("App2Sd Error : loopback node creation failed\n");
+ _E("loopback node creation failed");
+ return ret;
}
- /* Perform Loopback encryption setup */
- device_node =
- _app2sd_do_loopback_encryption_setup(pkgid);
+ /* perform loopback encryption setup */
+ device_node = _app2sd_do_loopback_encryption_setup(pkgid,
+ loopback_device);
if (!device_node) {
- app2ext_print
- ("App2Sd Error : losetup failed, device node is %s\n",
- device_node);
+ _E("loopback encryption setup failed");
return APP2EXT_ERROR_DO_LOSETUP;
}
- /* Check whether loopback device is associated with device node or not */
- devi = _app2sd_find_associated_device_node(pkgid);
+ _D("device_node (%s)", device_node);
+ /* check whether loopback device is associated with device node or not */
+ devi = _app2sd_find_associated_device_node(loopback_device);
if (devi == NULL) {
- app2ext_print
- ("App2Sd Error : _app2sd_find_associated_device_node losetup failed\n");
+ _E("finding associated device node failed");
return APP2EXT_ERROR_DO_LOSETUP;
} else {
free(devi);
devi = NULL;
}
- /* Format the loopback file system */
+ /* format the loopback file system */
ret = _app2sd_create_file_system(device_node);
if (ret) {
- app2ext_print
- ("App2Sd Error : create ext4 filesystem failed\n");
+ _E("create ext4 filesystem failed");
return APP2EXT_ERROR_CREATE_FS;
}
- /********Archiving code begin***********/
+
list = g_list_first(dir_list);
while (list) {
dir_detail = (app2ext_dir_details *)list->data;
if (dir_detail && dir_detail->name
&& dir_detail->type == APP2EXT_DIR_RO) {
- snprintf(path, FILENAME_MAX,
- "%s%s/%s",APP_INSTALLATION_PATH,
- pkgid,
- dir_detail->name);
- ret =
- _app2sd_move_to_archive
- (path,
- app_archive_path);
+ memset(temp_dir_path, '\0', FILENAME_MAX);
+ snprintf(temp_dir_path, FILENAME_MAX,
+ "%s/%s", application_path,
+ dir_detail->name);
+ _D("app2archive, temp_dir_path(%s)",
+ temp_dir_path);
+ ret = _app2sd_move_to_archive(temp_dir_path,
+ application_archive_path);
if (ret) {
if (ret == APP2EXT_ERROR_ACCESS_FILE) {
- app2ext_print
- ("App2Sd Error : unable to access %s\n",
- path);
+ _E("unable to access (%s)",
+ temp_dir_path);
} else {
- app2ext_print
- ("App2Sd Error : unable to copy from %s to %s \n",
- path,
- app_archive_path);
+ _E("unable to copy from (%s) to (%s)",
+ temp_dir_path,
+ application_archive_path);
}
+ return ret;
}
}
list = g_list_next(list);
}
- /********Archiving code ends***********/
- /* mount the loopback encrypted pseudo device on application installation path as with Read Write permission */
- ret =
- _app2sd_mount_app_content(pkgid, device_node,
- MOUNT_TYPE_RW, dir_list,
- APP2SD_MOVE_APP_TO_MMC);
+ /* mount the loopback encrypted pseudo device on application installation path
+ * as with Read Write permission
+ */
+ ret = _app2sd_mount_app_content(application_path, pkgid, device_node,
+ MOUNT_TYPE_RW, dir_list, APP2SD_MOVE_APP_TO_MMC, uid);
if (ret) {
+ _E("mount failed");
return ret;
}
- /********restore Archive begin***********/
+
list = g_list_first(dir_list);
while (list) {
dir_detail = (app2ext_dir_details *)list->data;
if (dir_detail && dir_detail->name
&& dir_detail->type == APP2EXT_DIR_RO) {
- memset((void *)&path, '\0',
- FILENAME_MAX);
- snprintf(path, FILENAME_MAX,
- "%s%s/.archive/%s",APP_INSTALLATION_PATH,
- pkgid,
- dir_detail->name);
- ret =
- _app2sd_copy_dir
- (path,
- app_mmc_path);
+ memset(temp_dir_path, '\0', FILENAME_MAX);
+ snprintf(temp_dir_path, FILENAME_MAX,
+ "%s/%s", application_archive_path,
+ dir_detail->name);
+ _D("archive2mmc, temp_dir_path(%s)",
+ temp_dir_path);
+ ret = _app2sd_copy_dir(temp_dir_path,
+ application_mmc_path);
if (ret) {
if (ret == APP2EXT_ERROR_ACCESS_FILE) {
- app2ext_print("App2Sd Error : unable to access %s\n", path);
+ _E("unable to access (%s)",
+ temp_dir_path);
} else {
- char err_buf[1024] = {0,};
- strerror_r(errno, err_buf, sizeof(err_buf));
- app2ext_print("App2Sd Error : unable to copy from %s to %s .....err is %s\n",
- path, app_mmc_path, err_buf);
+ strerror_r(errno,
+ err_buf, sizeof(err_buf));
+ _E("unable to copy from (%s) to (%s)," \
+ " error is (%s)",
+ temp_dir_path,
+ application_mmc_path, err_buf);
}
+ return ret;
}
- ret =
- _app2sd_delete_directory
- (path);
+ ret = _app2sd_delete_directory(temp_dir_path);
if (ret) {
if (ret == APP2EXT_ERROR_ACCESS_FILE) {
- app2ext_print
- ("App2Sd Error : unable to access %s\n",
- path);
+ _E("unable to access (%s)",
+ temp_dir_path);
} else {
- app2ext_print
- ("App2Sd Error : unable to delete %s \n",
- path);
- return
- APP2EXT_ERROR_DELETE_DIRECTORY;
+ _E("unable to delete (%s)",
+ temp_dir_path);
}
+ return ret;
}
}
list = g_list_next(list);
}
- ret = _app2sd_delete_directory(app_archive_path);
+ ret = _app2sd_delete_directory(application_archive_path);
if (ret) {
- app2ext_print
- ("App2Sd Error : unable to delete %s \n",
- app_archive_path);
+ _E("unable to delete (%s)", application_archive_path);
+ return APP2EXT_ERROR_DELETE_DIRECTORY;
}
- /* TODO */
- /*
- ret = _app2sd_apply_mmc_smack(pkgid, dir_list, pkgid);
- */
+ ret = _app2sd_apply_app_smack(application_path, pkgid, dir_list, uid);
if (ret) {
- app2ext_print("App2Sd Error : unable to apply app smack\n");
+ _E("unable to apply app smack");
return APP2EXT_ERROR_MOVE;
}
- /* Restore archive ends */
- /* Re-mount the loopback encrypted pseudo device on application installation path as with Read Only permission */
- ret = _app2sd_unmount_app_content(pkgid);
+ /* re-mount the loopback encrypted pseudo device on application installation path
+ * as with Read Only permission
+ */
+ ret = _app2sd_unmount_app_content(application_path);
if (ret) {
- return APP2EXT_ERROR_REMOUNT;
+ _E("unmount error (%d)", ret);
+ return APP2EXT_ERROR_UNMOUNT;
}
- ret =
- _app2sd_remove_loopback_encryption_setup(pkgid);
+ ret = _app2sd_remove_loopback_encryption_setup(loopback_device);
if (ret) {
- app2ext_print
- ("App2Sd Error : unable to detach loopback setup for %s\n",
- pkgid);
+ _E("unable to detach loopback setup for (%s)",
+ loopback_device);
return APP2EXT_ERROR_DETACH_LOOPBACK_DEVICE;
}
+
return APP2EXT_SUCCESS;
}
-int _app2sd_move_app_to_internal(const char *pkgid, GList* dir_list)
+int _app2sd_move_app_to_internal(const char *pkgid, GList* dir_list, uid_t uid)
{
int ret = APP2EXT_SUCCESS;
mode_t mode = DIR_PERMS;
- char path[FILENAME_MAX] = { 0, };
- char app_mmc_path[FILENAME_MAX] = { 0, };
- char app_path[FILENAME_MAX] = { 0, };
- char mmc_path[FILENAME_MAX] = { 0, };
- char app_archive_path[FILENAME_MAX] = { 0, };
+ char temp_dir_path[FILENAME_MAX] = { 0, };
+ char application_mmc_path[FILENAME_MAX] = { 0, };
+ char application_archive_path[FILENAME_MAX] = { 0, };
+ char application_path[FILENAME_MAX] = { 0, };
+ char loopback_device[FILENAME_MAX] = { 0, };
char *device_node = NULL;
FILE *fp = NULL;
GList *list = NULL;
unsigned long long temp = 0;
char err_buf[1024] = {0,};
- snprintf(app_mmc_path, FILENAME_MAX,
- "%s%s/.mmc", APP_INSTALLATION_PATH, pkgid);
- snprintf(app_path, FILENAME_MAX, "%s%s/", APP_INSTALLATION_PATH,
- pkgid);
- snprintf(app_archive_path, FILENAME_MAX,
- "%s%s/.archive", APP_INSTALLATION_PATH, pkgid);
- snprintf(mmc_path, FILENAME_MAX,
- "%s%s", APP2SD_PATH, pkgid);
-
- /* Check whether MMC is present or not */
+ /* check whether MMC is present or not */
ret = _app2sd_check_mmc_status();
if (ret) {
- app2ext_print
- ("App2Sd Error : MMC not preset OR Not ready %d\n",
- ret);
+ _E("MMC not preset OR Not ready(%d)", ret);
return APP2EXT_ERROR_MMC_STATUS;
}
+ if (_is_global(uid)) {
+ snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
+ tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
+ snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
+ APP2SD_PATH, pkgid);
+ } else {
+ tzplatform_set_user(uid);
+ snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
+ tzplatform_getenv(TZ_USER_APP), pkgid);
+ snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
+ APP2SD_PATH, tzplatform_getenv(TZ_USER_NAME), pkgid);
+ tzplatform_reset_user();
+ }
+ _D("application_path = (%s)", application_path);
+ _D("loopback_device = (%s)", loopback_device);
+
/* check whether application is in external memory or not */
- fp = fopen(mmc_path, "r+");
+ fp = fopen(loopback_device, "r+");
if (fp == NULL) {
- app2ext_print
- ("Application %s is not installed on SD Card\n",
+ _E("application (%s) is not installed on SD Card",
pkgid);
return APP2EXT_ERROR_FILE_ABSENT;
} else {
memset((void *)&buf, '\0', sizeof(struct statvfs));
ret = statvfs(INTERNAL_STORAGE_PATH, &buf);
if (0 == ret){
- temp = (buf.f_bsize * buf.f_bavail)/(1024*1024);
+ temp = (buf.f_bsize * buf.f_bavail) / (1024 * 1024);
free_internal_mem = (int)temp;
- }else{
- app2ext_print("App2SD Error: Unable to get internal storage size\n");
- return APP2EXT_ERROR_MMC_INSUFFICIENT_MEMORY; /* TODO: new error no for internal? */
+ } else {
+ _E("unable to get internal storage size");
+ return APP2EXT_ERROR_MMC_INSUFFICIENT_MEMORY;
}
- /* check app entry is there in sd card or not. */
- snprintf(app_path, FILENAME_MAX, "%s%s", APP2SD_PATH,
- pkgid);
- app2ext_print("App2Sd Log : Checking path %s\n", app_path);
- fp = fopen(app_path, "r+");
+ fp = fopen(loopback_device, "r+");
if (fp == NULL) {
- app2ext_print
- ("App2SD Error: App Entry is not present in SD Card\n");
+ _E("app entry is not present in SD card");
return APP2EXT_ERROR_INVALID_PACKAGE;
}
fclose(fp);
- /* Get installed app size*/
- temp = _app2sd_calculate_file_size(app_path);
- reqd_size = (int)((temp)/(1024 * 1024));
- app2ext_print("App2Sd Log : Reqd size is %d\n", reqd_size);
+
+ /* get installed app size*/
+ temp = _app2sd_calculate_file_size(loopback_device);
+ reqd_size = (int)((temp) / (1024 * 1024));
+ _D("reqd size is (%d)", reqd_size);
if (reqd_size == 0) {
- app2ext_print
- ("App2SD Error: App Entry is not present in SD Card\n");
+ _E("app entry is not present in SD Card");
return APP2EXT_ERROR_LOOPBACK_DEVICE_UNAVAILABLE;
}
- app2ext_print("Reqd Size: %d MB, free internal mem %d MB\n", reqd_size, free_internal_mem);
- /* If avaialalbe free memory in internal storage is less than required size, return error */
+ _D("reqd size: (%d)MB, free internal mem: (%d)MB",
+ reqd_size, free_internal_mem);
+
+ /* if avaialalbe free memory in internal storage is
+ * less than required size, return error
+ */
if (reqd_size > free_internal_mem) {
- app2ext_print
- ("App2Sd Error : Insufficient memory in internal storage for application installation %d\n",
- ret);
- return APP2EXT_ERROR_MMC_INSUFFICIENT_MEMORY; /* TODO: new error no for internal? */
+ _E("innsufficient memory in internal storage" \
+ " for application installation (%d)", ret);
+ return APP2EXT_ERROR_MMC_INSUFFICIENT_MEMORY;
}
- /* Get the associated device node for SD card applicationer */
- snprintf(app_path, FILENAME_MAX, "%s%s/", APP_INSTALLATION_PATH,
- pkgid);
- device_node =
- _app2sd_find_associated_device_node(pkgid);
+ device_node = _app2sd_find_associated_device_node(loopback_device);
if (NULL == device_node) {
- /* Do loopback setup */
- device_node =
- _app2sd_do_loopback_encryption_setup
- (pkgid);
+ /* do loopback setup */
+ device_node = _app2sd_do_loopback_encryption_setup(pkgid,
+ loopback_device);
if (device_node == NULL) {
- app2ext_print
- ("App2Sd Error : loopback encryption setup failed\n");
+ _E("loopback encryption setup failed");
return APP2EXT_ERROR_DO_LOSETUP;
}
- /* Do mounting */
- ret =
- _app2sd_mount_app_content(pkgid,
- device_node,
- MOUNT_TYPE_RW,
- dir_list,
- APP2SD_MOVE_APP_TO_PHONE);
+ /* do mounting */
+ ret = _app2sd_mount_app_content(application_path,
+ pkgid, device_node, MOUNT_TYPE_RW,
+ dir_list, APP2SD_MOVE_APP_TO_PHONE, uid);
if (ret) {
- app2ext_print
- ("App2Sd Error : Re-mount failed\n");
+ _E("mount failed");
return APP2EXT_ERROR_MOUNT_PATH;
}
} else {
- /* Do re-mounting */
- ret =
- _app2sd_mount_app_content(pkgid,
- device_node,
- MOUNT_TYPE_RW_REMOUNT,
- dir_list,
- APP2SD_MOVE_APP_TO_PHONE);
+ /* do re-mounting */
+ ret = _app2sd_mount_app_content(application_path,
+ pkgid, device_node, MOUNT_TYPE_RW_REMOUNT,
+ dir_list, APP2SD_MOVE_APP_TO_PHONE, uid);
if (ret) {
- app2ext_print
- ("App2Sd Error : Re-mount failed\n");
+ _E("re-mount failed");
return APP2EXT_ERROR_MOUNT_PATH;
}
}
- ret = mkdir(app_archive_path, mode);
+
+ snprintf(application_mmc_path, FILENAME_MAX - 1, "%s/.mmc",
+ application_path);
+ snprintf(application_archive_path, FILENAME_MAX - 1, "%s/.archive",
+ application_path);
+ _D("application_mmc_path = (%s)", application_mmc_path);
+ _D("application_archive_path = (%s)", application_archive_path);
+
+ ret = mkdir(application_archive_path, mode);
if (ret) {
- app2ext_print
- ("App2Sd Error : unable to create directory%s\n",
- app_archive_path);
+ if (errno != EEXIST) {
+ _E("unable to create directory for archiving," \
+ " error(%d)", errno);
+ return APP2EXT_ERROR_CREATE_DIRECTORY;
+ }
}
-
list = g_list_first(dir_list);
while (list) {
dir_detail = (app2ext_dir_details *)list->data;
if (dir_detail && dir_detail->name
&& dir_detail->type == APP2EXT_DIR_RO) {
- /* Archiving code */
- memset((void *)&path, '\0',
- FILENAME_MAX);
- snprintf(path, FILENAME_MAX,
- "%s%s/.mmc/%s", APP_INSTALLATION_PATH,
- pkgid,
- dir_detail->name);
- ret =
- _app2sd_copy_dir
- (path,
- app_archive_path);
- if (ret) {
- if (ret == APP2EXT_ERROR_ACCESS_FILE) {
- app2ext_print("App2Sd Error : unable to access %s\n", path);
- } else {
- strerror_r(errno, err_buf, sizeof(err_buf));
- app2ext_print("App2Sd Error : unable to copy from %s to %s .....err is %s\n",
- path, app_archive_path, err_buf);
- }
+ /* archiving code */
+ memset(temp_dir_path, '\0', FILENAME_MAX);
+ snprintf(temp_dir_path, FILENAME_MAX,
+ "%s/%s", application_mmc_path,
+ dir_detail->name);
+ _D("mmc2archive, temp_dir_path(%s)", temp_dir_path);
+ ret = _app2sd_copy_dir(temp_dir_path,
+ application_archive_path);
+ if (ret) {
+ if (ret == APP2EXT_ERROR_ACCESS_FILE) {
+ _E("unable to access (%s)",
+ temp_dir_path);
+ } else {
+ strerror_r(errno,
+ err_buf, sizeof(err_buf));
+ _E("unable to copy from (%s) to (%s),"
+ " error is (%s)",
+ temp_dir_path,
+ application_archive_path, err_buf);
}
+ return ret;
+ }
- /* Delete the symbolic link files [bin, lib, res]*/
- memset((void *)&path, '\0',
- FILENAME_MAX);
- snprintf(path, FILENAME_MAX,
- "%s%s/%s", APP_INSTALLATION_PATH,
- pkgid,
- dir_detail->name);
- ret = unlink(path);
- if (ret) {
- if (errno == ENOENT) {
- app2ext_print("App2Sd Error : Directory %s does not exist\n", path);
- } else {
- app2ext_print("App2Sd Error : unable to remove the symbolic link file %s,"
- " it is already unlinked!!!\n", path);
- }
+ /* delete the symbolic link files [bin, lib, res]*/
+ memset(temp_dir_path, '\0', FILENAME_MAX);
+ snprintf(temp_dir_path, FILENAME_MAX,
+ "%s/%s", application_path,
+ dir_detail->name);
+ _D("unlink, temp_dir_path(%s)", temp_dir_path);
+ ret = unlink(temp_dir_path);
+ if (ret) {
+ if (errno == ENOENT) {
+ _E("directory (%s) does not exist",
+ temp_dir_path);
+ } else {
+ _E("unable to remove the symbolic link file (%s)," \
+ " it is already unlinked",
+ temp_dir_path);
}
+ return ret;
+ }
- /* Copy content to destination */
- memset((void *)&path, '\0',
- FILENAME_MAX);
- snprintf(path, FILENAME_MAX,
- "%s%s/.archive/%s", APP_INSTALLATION_PATH,
- pkgid, dir_detail->name);
- ret = _app2sd_copy_dir(path, app_path);
- if (ret) {
- if (ret == APP2EXT_ERROR_ACCESS_FILE) {
- app2ext_print("App2Sd Error : unable to access %s\n", path);
- } else {
- strerror_r(errno, err_buf, sizeof(err_buf));
- app2ext_print("App2Sd Error : unable to copy from %s to %s .....err is %s\n",
- path, app_path, err_buf);
- }
+ /* Copy content to destination */
+ memset(temp_dir_path, '\0', FILENAME_MAX);
+ snprintf(temp_dir_path, FILENAME_MAX,
+ "%s/%s", application_archive_path,
+ dir_detail->name);
+ _D("archive2app, temp_dir_path(%s)", temp_dir_path);
+ ret = _app2sd_copy_dir(temp_dir_path, application_path);
+ if (ret) {
+ if (ret == APP2EXT_ERROR_ACCESS_FILE) {
+ _E("unable to access (%s)",
+ temp_dir_path);
+ } else {
+ strerror_r(errno,
+ err_buf, sizeof(err_buf));
+ _E("unable to copy from (%s) to (%s) " \
+ ", error is (%s)",
+ temp_dir_path,
+ application_path, err_buf);
}
+ return ret;
+ }
}
list = g_list_next(list);
}
- app2ext_print("App2Sd info : Copying file completed\n");
- ret = _app2sd_unmount_app_content(pkgid);
+ _D("copying file completed");
+ ret = _app2sd_unmount_app_content(application_path);
if (ret) {
- app2ext_print
- ("App2Sd Error : unable to unmount SD directory for app %s\n",
+ _E("unable to unmount SD directory for app (%s)",
pkgid);
return APP2EXT_ERROR_UNMOUNT;
}
- ret =
- _app2sd_remove_loopback_encryption_setup(pkgid);
+ ret = _app2sd_remove_loopback_encryption_setup(loopback_device);
if (ret) {
- app2ext_print
- ("App2Sd Error : unable to detach loopback setup for %s\n",
+ _E("unable to detach loopback setup for (%s)",
pkgid);
return APP2EXT_ERROR_DETACH_LOOPBACK_DEVICE;
}
- ret = _app2sd_delete_loopback_device(pkgid);
+ ret = _app2sd_delete_loopback_device(loopback_device);
if (ret) {
- app2ext_print
- ("App2Sd Error : unable to delete the loopback device for %s\n",
+ _E("unable to delete the loopback device for (%s)",
pkgid);
return APP2EXT_ERROR_DELETE_LOOPBACK_DEVICE;
}
- ret = _app2sd_delete_directory(app_mmc_path);
+ ret = _app2sd_delete_directory(application_mmc_path);
if (ret) {
- app2ext_print
- ("App2Sd Error : unable to delete %s \n",
- app_mmc_path);
- }
- ret = _app2sd_delete_directory(app_archive_path);
- if (ret) {
- app2ext_print
- ("App2Sd Error : unable to delete %s \n",
- app_archive_path);
+ _E("unable to delete (%s)", application_mmc_path);
+ return APP2EXT_ERROR_DELETE_DIRECTORY;
}
-
- /* TODO */
- /*
- ret = _app2sd_apply_app_smack(pkgid, dir_list, pkgid);
- */
+ ret = _app2sd_delete_directory(application_archive_path);
if (ret) {
- app2ext_print("App2Sd Error : unable to apply app smack\n");
- return APP2EXT_ERROR_MOVE;
+ _E("unable to delete (%s)", application_archive_path);
+ return APP2EXT_ERROR_DELETE_DIRECTORY;
}
return APP2EXT_SUCCESS;
}
-int _app2sd_move_app(const char *pkgid, app2ext_move_type move_cmd, GList* dir_list)
+int _app2sd_usr_move_app(const char *pkgid, app2ext_move_type move_type,
+ GList* dir_list, uid_t uid)
{
int ret = APP2EXT_SUCCESS;
/* Check whether MMC is present or not */
ret = _app2sd_check_mmc_status();
if (ret) {
- app2ext_print
- ("App2Sd Error : MMC not preset OR Not ready %d\n",
- ret);
+ _E("MMC not preset OR Not ready(%d)", ret);
return APP2EXT_ERROR_MMC_STATUS;
}
- switch (move_cmd) {
+ switch (move_type) {
case APP2EXT_MOVE_TO_EXT:
- {
- ret = _app2sd_move_app_to_external(pkgid, dir_list);
- if (ret) {
- app2ext_print
- ("App2Sd Error : move app to external memory failed %d\n",
- ret);
- return ret;
- }
- break;
+ ret = _app2sd_move_app_to_external(pkgid, dir_list, uid);
+ if (ret) {
+ _E("move app to external memory failed(%d)", ret);
+ return ret;
}
+ break;
case APP2EXT_MOVE_TO_PHONE:
- {
- ret = _app2sd_move_app_to_internal(pkgid, dir_list);
- if (ret) {
- app2ext_print
- ("App2Sd Error : move app to internal memory failed %d\n",
- ret);
- return ret;
- }
- break;
+ ret = _app2sd_move_app_to_internal(pkgid, dir_list, uid);
+ if (ret) {
+ _E("move app to internal memory failed(%d)", ret);
+ return ret;
}
+ break;
default:
- {
- app2ext_print("App2Sd Error : invalid argument\n");
- return APP2EXT_ERROR_INVALID_ARGUMENTS;
- }
+ _E("invalid argument");
+ return APP2EXT_ERROR_INVALID_ARGUMENTS;
}
return ret;
-
}
int _app2sd_copy_ro_content(const char *src, const char *dest, GList* dir_list)
{
char path[FILENAME_MAX] = { 0, };
- int ret = APP2EXT_SUCCESS;
+ int ret = APP2EXT_SUCCESS;
GList *list = NULL;
app2ext_dir_details* dir_detail = NULL;
dir_detail = (app2ext_dir_details *)list->data;
if (dir_detail && dir_detail->name
&& dir_detail->type == APP2EXT_DIR_RO) {
- memset((void *)&path, '\0',
- FILENAME_MAX);
- snprintf(path, FILENAME_MAX,
- "%s/%s", src,
+ memset((void *)&path, '\0', FILENAME_MAX);
+ snprintf(path, FILENAME_MAX - 1, "%s/%s", src,
dir_detail->name);
- ret =
- _app2sd_copy_dir
- (path,
- dest);
+ ret = _app2sd_copy_dir(path, dest);
if (ret) {
if (ret == APP2EXT_ERROR_ACCESS_FILE) {
- app2ext_print
- ("App2Sd Error : unable to access %s\n",
- path);
+ _E("unable to access (%s)", path);
} else {
- app2ext_print
- ("App2Sd Error : unable to copy from %s to %s .....errno is %d\n",
- path,
- dest,
- errno);
- return
- APP2EXT_ERROR_MOVE;
+ _E("unable to copy from (%s) " \
+ "to (%s), errno is (%d)",
+ path, dest, errno);
+ return APP2EXT_ERROR_MOVE;
}
}
}
return APP2EXT_SUCCESS;
}
-int _app2sd_duplicate_device(const char *pkgid, GList* dir_list, char *dev_node, int size)
+int _app2sd_duplicate_device(const char *pkgid,
+ const char *loopback_device,
+ const char *temp_pkgid,
+ const char *temp_application_path,
+ const char *temp_loopback_device,
+ GList* dir_list, char *dev_node, int size,
+ uid_t uid)
{
int ret = 0;
- char temp_pkgid[FILENAME_MAX] = { 0, };
char *devi = NULL;
int err_res = 0;
char *result = NULL;
- /* Create a new loopback device */
- snprintf(temp_pkgid, FILENAME_MAX,
- "%s.new", pkgid);
- ret = _app2sd_create_loopback_device(temp_pkgid, (size+PKG_BUF_SIZE));
+ /* create a new loopback device */
+ ret = _app2sd_create_loopback_device(temp_pkgid,
+ temp_loopback_device, (size + PKG_BUF_SIZE));
if (ret) {
- app2ext_print("App2Sd Error : Package already present\n");
+ _E("package already present");
return ret;
}
- app2ext_print("App2Sd : _app2sd_create_loopback_device SUCCESS\n");
- /* Perform Loopback encryption setup */
- dev_node = _app2sd_do_loopback_duplicate_encryption_setup(pkgid, temp_pkgid);
+
+ /* perform loopback encryption setup */
+ dev_node = _app2sd_do_loopback_duplicate_encryption_setup(pkgid,
+ temp_pkgid, temp_loopback_device);
if (!dev_node) {
- app2ext_print("App2Sd Error : losetup failed, device node is %s\n", dev_node);
- _app2sd_delete_loopback_device(pkgid);
- app2ext_print("App2Sd Error : create ext filesystem failed\n");
+ _E("losetup failed, device node is (%s)", dev_node);
+ _app2sd_delete_loopback_device(loopback_device);
+ _E("create ext filesystem failed");
return APP2EXT_ERROR_DO_LOSETUP;
}
- app2ext_print("App2Sd : _app2sd_do_loopback_duplicate_encryption_setup SUCCESS\n");
- /* Check whether loopback device is associated with device node or not */
- devi = _app2sd_find_associated_device_node(temp_pkgid);
+ _D("duplicate setup SUCCESS");
+
+ /* check whether loopback device is associated with
+ * device node or not
+ */
+ devi = _app2sd_find_associated_device_node(temp_loopback_device);
if (devi == NULL) {
- app2ext_print("App2Sd Error : finding associated device node failed\n");
+ _E("finding associated device node failed");
err_res = APP2EXT_ERROR_DO_LOSETUP;
goto FINISH_OFF;
}
- app2ext_print("App2Sd : _app2sd_find_associated_device_node SUCCESS\n");
- /* Format the loopback file system */
+ _D("losetup SUCCESS");
+
+ /* format the loopback file system */
ret = _app2sd_create_file_system(dev_node);
if (ret) {
- app2ext_print("App2Sd Error : creating FS failed failed\n");
+ _E("creating fs failed");
err_res = APP2EXT_ERROR_CREATE_FS;
goto FINISH_OFF;
}
- app2ext_print("App2Sd : _app2sd_create_file_system SUCCESS\n");
- /* Do mounting for new dev*/
- ret =
- _app2sd_mount_app_content(temp_pkgid, dev_node, MOUNT_TYPE_RW,
- dir_list, APP2SD_PRE_UPGRADE);
+ _D("create filesystem SUCCESS");
+
+ /* do mounting for new dev*/
+ ret = _app2sd_mount_app_content(temp_application_path, pkgid,
+ dev_node, MOUNT_TYPE_RW, dir_list,
+ APP2SD_PRE_UPGRADE, uid);
if (ret) {
- app2ext_print("App2Sd Error : Re-mount failed\n");
+ _E("remount failed");
err_res = APP2EXT_ERROR_MOUNT_PATH;
goto FINISH_OFF;
}
+
if (devi) {
free(devi);
devi = NULL;
}
+
return APP2EXT_SUCCESS;
FINISH_OFF:
free(result);
result = NULL;
}
- _app2sd_delete_loopback_device(pkgid);
+ _app2sd_delete_loopback_device(loopback_device);
free(dev_node);
dev_node = NULL;
}
}
int _app2sd_update_loopback_device_size(const char *pkgid,
- int size, GList* dir_list)
+ const char *loopback_device,
+ const char *application_path,
+ const char *temp_pkgid,
+ const char *temp_loopback_device,
+ const char *temp_application_path,
+ int size, GList* dir_list,
+ uid_t uid)
{
int ret = 0;
char *device_node = NULL;
char *old_device_node = NULL;
int err_res = 0;
- char app_mmc_path[FILENAME_MAX] = { 0, };
- char app_archive_path[FILENAME_MAX] = { 0, };
- char temp_pkgid[FILENAME_MAX] = { 0, };
- char app_path[FILENAME_MAX] = { 0, };
+ char application_mmc_path[FILENAME_MAX] = { 0, };
+ char temp_application_mmc_path[FILENAME_MAX] = { 0, };
- snprintf(temp_pkgid, FILENAME_MAX,
- "%s.new", pkgid);
-
- ret = _app2sd_duplicate_device(pkgid, dir_list, device_node, size);
+ ret = _app2sd_duplicate_device(pkgid, loopback_device,
+ temp_pkgid, temp_application_path, temp_loopback_device,
+ dir_list, device_node, size, uid);
if (ret) {
- app2ext_print("App2Sd Error : Creating duplicate device failed\n");
+ _E("creating duplicate device failed");
return ret;
}
- app2ext_print("App2Sd : _app2sd_mount_app_content SUCCESS\n");
- /* check app entry is there in sd card or not. */
- snprintf(app_path, FILENAME_MAX, "%s%s", APP2SD_PATH,
- pkgid);
-
- /* Get the associated device node for SD card applicatione */
- old_device_node = _app2sd_find_associated_device_node(pkgid);
+ /* get the associated device node for SD card applicatione */
+ old_device_node = _app2sd_find_associated_device_node(loopback_device);
if (NULL == old_device_node) {
- /* Do loopback setup */
- old_device_node = _app2sd_do_loopback_encryption_setup(pkgid);
+ /* do loopback setup */
+ old_device_node = _app2sd_do_loopback_encryption_setup(pkgid,
+ loopback_device);
if (old_device_node == NULL) {
- app2ext_print
- ("App2Sd Error : loopback encryption setup failed\n");
+ _E("loopback encryption setup failed");
err_res = APP2EXT_ERROR_DO_LOSETUP;
goto FINISH_OFF;
}
- /* Do mounting */
- ret =
- _app2sd_mount_app_content(pkgid, old_device_node,
- MOUNT_TYPE_RW, dir_list,
- APP2SD_PRE_UPGRADE);
+ /* do mounting */
+ ret = _app2sd_mount_app_content(application_path, pkgid,
+ old_device_node, MOUNT_TYPE_RW, dir_list,
+ APP2SD_PRE_UPGRADE, uid);
if (ret) {
- app2ext_print("App2Sd Error : Re-mount failed\n");
+ _E("remount failed");
err_res = APP2EXT_ERROR_MOUNT_PATH;
}
} else {
- /* Do re-mounting */
- ret =
- _app2sd_mount_app_content(pkgid, old_device_node,
- MOUNT_TYPE_RW_REMOUNT, dir_list,
- APP2SD_PRE_UPGRADE);
+ /* do re-mounting */
+ ret = _app2sd_mount_app_content(application_path, pkgid,
+ old_device_node, MOUNT_TYPE_RW_REMOUNT, dir_list,
+ APP2SD_PRE_UPGRADE, uid);
if (ret) {
- app2ext_print("App2Sd Error : Re-mount failed\n");
+ _E("remount failed");
err_res = APP2EXT_ERROR_MOUNT_PATH;
}
}
- snprintf(app_mmc_path, FILENAME_MAX,
- "%s%s/.mmc", APP_INSTALLATION_PATH, pkgid);
- snprintf(app_archive_path, FILENAME_MAX,
- "%s%s/.mmc", APP_INSTALLATION_PATH, temp_pkgid);
+ snprintf(application_mmc_path, FILENAME_MAX - 1,
+ "%s/.mmc", application_path);
+ snprintf(temp_application_mmc_path, FILENAME_MAX - 1,
+ "%s/.mmc", temp_application_path);
- ret = _app2sd_copy_ro_content(app_mmc_path, app_archive_path, dir_list);
+ ret = _app2sd_copy_ro_content(application_mmc_path,
+ temp_application_mmc_path, dir_list);
if (ret) {
- app2ext_print("App2Sd Error : copy ro content failed\n");
+ _E("copy ro content failed");
err_res = ret;
}
- ret = _app2sd_unmount_app_content(pkgid);
+ ret = _app2sd_unmount_app_content(application_path);
if (ret) {
- app2ext_print
- ("App2SD Error: Unable to unmount the SD application\n");
+ _E("unable to unmount the SD application");
err_res = APP2EXT_ERROR_UNMOUNT;
}
- ret = _app2sd_remove_loopback_encryption_setup(pkgid);
+
+ ret = _app2sd_remove_loopback_encryption_setup(loopback_device);
if (ret) {
- app2ext_print("App2SD Error: Unable to remove loopback setup\n");
+ _E("unable to remove loopback setup");
err_res = APP2EXT_ERROR_DELETE_LOOPBACK_DEVICE;
}
- ret = _app2sd_unmount_app_content(temp_pkgid);
+
+ ret = _app2sd_unmount_app_content(temp_application_path);
if (ret) {
- app2ext_print
- ("App2SD Error: Unable to unmount the SD application\n");
+ _E("unable to unmount the SD application");
err_res = APP2EXT_ERROR_UNMOUNT;
goto FINISH_OFF;
}
- ret = _app2sd_remove_loopback_encryption_setup(temp_pkgid);
+
+ ret = _app2sd_remove_loopback_encryption_setup(temp_loopback_device);
if (ret) {
- app2ext_print("App2SD Error: Unable to remove loopback setup\n");
+ _E("unable to remove loopback setup");
err_res = APP2EXT_ERROR_DELETE_LOOPBACK_DEVICE;
goto FINISH_OFF;
}
- snprintf(app_archive_path, FILENAME_MAX,
- "%s%s", APP2SD_PATH, temp_pkgid);
- ret = _app2sd_delete_directory(app_path);
+
+ ret = _app2sd_delete_directory(loopback_device);
if (ret) {
- app2ext_print
- ("App2Sd Error : unable to delete %s \n",
- app_path);
+ _E("unable to delete (%s)", loopback_device);
err_res = APP2EXT_ERROR_DELETE_DIRECTORY;
goto FINISH_OFF;
}
- ret = _app2sd_rename_dir(app_archive_path, app_path);
+
+ ret = _app2sd_rename_dir(temp_loopback_device, loopback_device);
if (ret) {
- app2ext_print
- ("App2Sd Error : unable to rename %s \n",
- app_archive_path);
+ _E("unable to rename (%s)", temp_loopback_device);
err_res = APP2EXT_ERROR_MOVE;
goto FINISH_OFF;
}
- snprintf(app_path, FILENAME_MAX,
- "%s%s", APP_INSTALLATION_PATH, temp_pkgid);
- ret = _app2sd_delete_directory(app_path);
+
+ ret = _app2sd_delete_directory(temp_application_path);
if (ret) {
- app2ext_print
- ("App2Sd Error : unable to delete %s \n",
- app_path);
+ _E("unable to delete (%s)", temp_application_path);
err_res = APP2EXT_ERROR_DELETE_DIRECTORY;
goto FINISH_OFF;
}
+
return APP2EXT_SUCCESS;
FINISH_OFF:
old_device_node = NULL;
}
- ret = _app2sd_remove_loopback_encryption_setup(pkgid);
+ ret = _app2sd_remove_loopback_encryption_setup(loopback_device);
if (ret) {
- app2ext_print("App2SD Error: Unable to remove loopback setup\n");
+ _E("unable to remove loopback setup");
err_res = APP2EXT_ERROR_DELETE_LOOPBACK_DEVICE;
}
+
return err_res;
}
-void _app2sd_make_result_info_file(char *pkgid, int size)
+void _app2sd_make_result_info_file(char *pkgid, int size, uid_t uid)
{
int ret = 0;
FILE* file = NULL;
char buf[FILENAME_MAX] = {0};
const char* app_info_label = "*";
char info_file[FILENAME_MAX] = {'\0', };
+ struct passwd pwd;
+ struct passwd *pwd_result;
if(pkgid == NULL)
return;
- snprintf(info_file, FILENAME_MAX, "/tmp/%s", pkgid);
- app2ext_print("App2SD info : File path = %s\n", info_file);
+ snprintf(info_file, FILENAME_MAX - 1, "/tmp/%s", pkgid);
+ _D("file path = %s", info_file);
file = fopen(info_file, "w");
if (file == NULL) {
- app2ext_print("App2SD Error: Couldn't open the file %s \n", info_file);
+ _E("couldn't open the file (%s)", info_file);
return;
}
- snprintf(buf, 128, "%d\n", size);
+ snprintf(buf, FILENAME_MAX - 1, "%d\n", size);
fwrite(buf, 1, strlen(buf), file);
fflush(file);
fclose(file);
if(lsetxattr(info_file, "security.SMACK64", app_info_label, strlen(app_info_label), 0)) {
- app2ext_print("App2SD Error: error(%d) in setting smack label",errno);
+ _E("error(%d) in setting smack label", errno);
}
- ret = chmod(info_file, 0777);
+
+ ret = chmod(info_file, 0755);
if (ret == -1) {
return;
}
- ret = chown(info_file, 5000, 5000);
+ memset(buf, '\0', FILENAME_MAX);
+ ret = getpwuid_r(uid, &pwd, buf, FILENAME_MAX, &pwd_result);
+ if (ret != 0 || pwd_result == NULL) {
+ _E("get uid failed(%d)", ret);
+ }
+
+ ret = chown(info_file, uid, pwd.pw_gid);
if (ret == -1) {
return;
}
#include <dlog.h>
#include <time.h>
#include <db-util.h>
-
-/* For multi-user support */
#include <tzplatform_config.h>
#define MAX_QUERY_LEN 4096
password text\
)"
-/*
- *@_app2sd_initialize_db
- *This function is to initialize sqlite db.
- * return: On success, it will return zero else if fail then return val<0.
- */
int _app2sd_initialize_db()
{
char *error_message = NULL;
fp = fopen(APP2SD_DB_FILE, "r");
if (fp != NULL) {
fclose(fp);
- ret =
- db_util_open(APP2SD_DB_FILE, &app2sd_db,
- DB_UTIL_REGISTER_HOOK_METHOD);
+ ret = db_util_open(APP2SD_DB_FILE, &app2sd_db,
+ DB_UTIL_REGISTER_HOOK_METHOD);
if (ret != SQLITE_OK) {
- app2ext_print("====>>>> connect menu_db [%s] failed!\n",
- APP2SD_DB_FILE);
+ _E("connect menu_db [%s] failed",
+ APP2SD_DB_FILE);
return -1;
}
return 0;
}
- ret =
- db_util_open(APP2SD_DB_FILE, &app2sd_db,
- DB_UTIL_REGISTER_HOOK_METHOD);
+ ret = db_util_open(APP2SD_DB_FILE, &app2sd_db,
+ DB_UTIL_REGISTER_HOOK_METHOD);
if (ret != SQLITE_OK) {
- app2ext_print("====>>>> connect menu_db [%s] failed!\n",
- APP2SD_DB_FILE);
+ _E("connect menu_db [%s] failed",
+ APP2SD_DB_FILE);
return -1;
}
- if (SQLITE_OK !=
- sqlite3_exec(app2sd_db, QUERY_CREATE_TABLE_APP2SD,
- NULL, NULL, &error_message)) {
- app2ext_print("Don't execute query = %s, "
- "error message = %s\n",
- QUERY_CREATE_TABLE_APP2SD, error_message);
+ if (SQLITE_OK != sqlite3_exec(app2sd_db,
+ QUERY_CREATE_TABLE_APP2SD, NULL, NULL,
+ &error_message)) {
+ _E("don't execute query = (%s), " \
+ "error message = (%s)",
+ QUERY_CREATE_TABLE_APP2SD, error_message);
return -1;
}
- app2ext_print("\n db_initialize_done ");
+ _D("db_initialize_done");
+
return 0;
}
-/*
- *@_app2sd_set_password_in_db
- *This function is to store password into db.
- * param[in]: pkgid: package id
- * param[in]: password: password string
- * return: On success, it will return 0.
- * Else appropriate error will be returned.
- */
int _app2sd_set_password_in_db(const char *pkgid,
const char *passwd)
{
char *error_message = NULL;
- char *query = sqlite3_mprintf("insert into app2sd(pkgid,password) values (%Q, %Q)", pkgid, passwd);
+ char *query = sqlite3_mprintf("insert into app2sd(pkgid,password) values (%Q, %Q)",
+ pkgid, passwd);
if (SQLITE_OK != sqlite3_exec(app2sd_db, query, NULL, NULL,
- &error_message)) {
- app2ext_print("Don't execute query = %s, error message = %s\n",
- query, error_message);
-
+ &error_message)) {
+ _E("don't execute query = (%s), error message = (%s)",
+ query, error_message);
sqlite3_free(query);
return APP2EXT_ERROR_SQLITE_REGISTRY;
}
sqlite3_free(query);
- app2ext_print("\n sqlite insertion done ");
+ _D("sqlite insertion done");
+
return APP2EXT_SUCCESS;
}
-/*
- *@_app2sd_remove_password_from_db
- *This function is to remove passwod from db.
- * param[in]: pkgid: package id
- * return: On success, it will return 0.
- * Else appropriate error will be returned.
- */
int _app2sd_remove_password_from_db(const char *pkgid)
{
char *error_message = NULL;
-
- char *query = sqlite3_mprintf("delete from app2sd where pkgid LIKE %Q", pkgid);
- app2ext_print("\n deletion querys is %s ", query);
+ char *query = sqlite3_mprintf("delete from app2sd"
+ " where pkgid LIKE %Q", pkgid);
+ _D("deletion querys is (%s)", query);
if (SQLITE_OK != sqlite3_exec(app2sd_db, query, NULL,
- NULL, &error_message)) {
- app2ext_print("Don't execute query = %s, error message = %s\n",
- query, error_message);
+ NULL, &error_message)) {
+ _E("don't execute query = (%s), "
+ "error message = (%s)", query, error_message);
sqlite3_free(query);
return APP2EXT_ERROR_SQLITE_REGISTRY;
}
sqlite3_free(query);
- app2ext_print("\n app2sd password deletion done ");
- return APP2EXT_SUCCESS;
+ return APP2EXT_SUCCESS;
}
-/*
- *@_app2sd_get_password_from_db
- *This function is to retrive password from DB
- * param[in]: pkgid: package id
- * return: On success, it will return the password, else NULL.
- */
char *_app2sd_get_password_from_db(const char *pkgid)
{
char query[MAX_QUERY_LEN] = { 0 };
char *passwd = NULL;
sqlite3_snprintf(MAX_QUERY_LEN, query,
- "select * from app2sd where pkgid LIKE '%s'", pkgid);
- app2ext_print("\n access querys is %s ", query);
+ "select * from app2sd where pkgid LIKE '%s'", pkgid);
+ _D("access querys is (%s)", query);
if (SQLITE_OK != sqlite3_prepare(app2sd_db, query,
- strlen(query), &stmt, &tail)) {
- app2ext_print("sqlite3_prepare error\n");
+ strlen(query), &stmt, &tail)) {
+ _E("sqlite3_prepare error");
+
return NULL;
}
rc = sqlite3_step(stmt);
if (rc != SQLITE_ROW || rc == SQLITE_DONE) {
- app2ext_print("No records found");
+ _E("no records found");
goto FINISH_OFF;
}
passwd = malloc(PASSWORD_LENGTH + 1);
if (passwd == NULL) {
- app2ext_print("memory allocation failed\n");
+ _E("memory allocation failed");
goto FINISH_OFF;
}
- app2ext_print("\n entry available in sqlite");
+ _D("entry available in sqlite");
strncpy(passwd, (const char*)sqlite3_column_text(stmt, 1),
PASSWORD_LENGTH);
if (passwd == NULL) {
- app2ext_print("\n password is NULL ");
+ _E("data is NULL");
goto FINISH_OFF;
}
- app2ext_print("\n passwd is %s ", passwd);
if (SQLITE_OK != sqlite3_finalize(stmt)) {
- app2ext_print("error : sqlite3_finalize\n");
+ _E("error : sqlite3_finalize");
goto FINISH_OFF;
}
+
return passwd;
FINISH_OFF:
rc = sqlite3_finalize(stmt);
if (rc != SQLITE_OK) {
- app2ext_print(" sqlite3_finalize failed - %d", rc);
+ _E("sqlite3_finalize failed(%d)", rc);
}
+
if (passwd)
free(passwd);
+
return NULL;
}
#include <sys/statvfs.h>
#include <errno.h>
-#define PASSWD_LEN 8
+#define PASSWD_LEN 21
#define ASCII_PASSWD_CHAR 93
/*
/*
-* @_app2sd_check_mmc_status
-* This function checks and returns MMC status
-*/
+ * @_app2sd_check_mmc_status
+ * This function checks and returns MMC status
+ */
+/* TODO : another possible way ? */
int _app2sd_check_mmc_status(void)
{
FILE *fp1 = NULL;
fp1 = fopen("/etc/mtab", "r");
if (fp1 == NULL) {
fprintf(stderr, "failed to open file\n");
- app2ext_print("failed to open file /etc/mtab\n");
+ _E("failed to open file /etc/mtab");
return APP2EXT_ERROR_MMC_STATUS;
}
while (fgets(line, 512, fp1) != NULL) {
struct statvfs buf;
int ret = 0;
unsigned long long temp = 0;
+
if (sd_path == NULL || free_mem == NULL) {
- app2ext_print("App2Sd Error : Invalid input parameter\n");
+ _E("invalid input parameter");
return -1;
}
+
memset((void *)&buf, '\0', sizeof(struct statvfs));
+
ret = statvfs(sd_path, &buf);
if (ret) {
- app2ext_print("App2SD Error: Unable to get SD Card memory information\n");
+ _E("unable to get SD Card memory information");
return APP2EXT_ERROR_MMC_INFORMATION;
}
+
temp = (unsigned long long)buf.f_bsize*buf.f_bavail;
*free_mem = (int)(temp/(1024*1024));
+
return 0;
}
-int _app2sd_delete_directory(char *dirname)
+int _app2sd_delete_directory(const char *dirname)
{
DIR *dp = NULL;
struct dirent ep;
if (ret <0)
return -1;
} else {
- app2ext_print("Couldn't open the directory[%s]\n", dirname);
+ _E("couldn't open the directory[%s]", dirname);
}
return 0;
}
struct dirent *er = NULL;
char abs_filename[FILENAME_MAX] = { 0, };
- app2ext_print("star clean_symlink [%s]", dirname);
+ _D("start clean_symlink [%s]", dirname);
dp = opendir(dirname);
if (dp != NULL) {
snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname, ep.d_name);
char *path = realpath(abs_filename, mmc_path);
if(!path){
- app2ext_print("realpath failed\n");
+ _E("realpath failed");
}
if (strstr(mmc_path,".mmc")) {
- app2ext_print("force unlink [%s]", abs_filename);
+ _E("force unlink [%s]", abs_filename);
if (unlink(abs_filename)) {
if (errno == ENOENT) {
- app2ext_print("Unable to access file %s\n", abs_filename);
+ _E("Unable to access file %s", abs_filename);
} else {
- app2ext_print("Unable to delete %s\n", abs_filename);
+ _E("Unable to delete %s", abs_filename);
}
}
}
return;
}
} else {
- app2ext_print("Couldn't open the directory[%s]\n", dirname);
+ _E("couldn't open the directory[%s]", dirname);
}
- app2ext_print("finish clean_symlink");
+ _D("finish clean_symlink");
}
int _app2sd_copy_dir(const char *src, const char *dest)
const char *argv_bin[] = { "/bin/cp", "-raf", src, dest, NULL };
ret = _xsystem(argv_bin);
if (ret) {
- app2ext_print("copy fail\n");
+ _E("copy fail");
return APP2EXT_ERROR_MOVE;
}
return ret;
const char *argv_bin[] = { "/bin/mv", old_name, new_name, NULL };
ret = _xsystem(argv_bin);
if (ret) {
- app2ext_print("mv/rename fail\n");
+ _E("mv/rename fail");
return APP2EXT_ERROR_MOVE;
}
return ret;
}
(void)closedir(dp);
} else {
- app2ext_print("\n error in opening directory ");
+ _E("error in opening directory");
}
return total;
}
unsigned long long _app2sd_calculate_file_size(const char *filename)
{
struct stat stFileInfo;
- app2ext_print("\n Calculating file size for %s\n", filename);
+ _D("calculating file size for (%s)", filename);
if (stat(filename, &stFileInfo) < 0) {
perror(filename);
}
/*Note: Don't use any printf statement inside this function*/
-char *_app2sd_encrypt_device(const char *device, const char *pkgid,
- char *passwd)
+char *_app2sd_encrypt_device(const char *device,
+ const char *loopback_device, char *passwd)
{
+ /* TODO : change to dm-crypt */
const char *argv[] =
- { "/sbin/losetup", "-e", "aes", device, pkgid, "-k", passwd, NULL };
+ { "/sbin/losetup", device, loopback_device, NULL };
pid_t pid = 0;
int my_pipe[2] = { 0, };
char buf[FILENAME_MAX] = { 0, };
result = dup(my_pipe[1]);
if (result < 0) {
strerror_r(errno, err_buf, sizeof(err_buf));
- fprintf(stderr, "dup failed %d....%s\n", errno, err_buf);
+ fprintf(stderr, "dup failed %d....%s\n",
+ errno, err_buf);
_exit(-1);
}
result = dup(my_pipe[1]);
if (result < 0) {
strerror_r(errno, err_buf, sizeof(err_buf));
- fprintf(stderr, "dup failed %d....%s\n", errno, err_buf);
+ fprintf(stderr, "dup failed %d....%s\n",
+ errno, err_buf);
_exit(-1);
}
if (execvp(argv[0], (char *const *)argv) < 0) {
strerror_r(errno, err_buf, sizeof(err_buf));
- fprintf(stderr, "execvp failed %d....%s\n", errno, err_buf); /*Don't use d_msg_app2sd */
+ fprintf(stderr, "execvp failed %d....%s\n",
+ errno, err_buf); /*Don't use d_msg_app2sd */
}
_exit(-1);
default:
result = read(my_pipe[0], buf, FILENAME_MAX);
if (result < 0) {
strerror_r(errno, err_buf, sizeof(err_buf));
- fprintf(stderr, "read failed %d....%s\n", errno, err_buf);
+ fprintf(stderr, "read failed %d....%s\n",
+ errno, err_buf);
}
break;
}
ret_result = (char *)malloc(strlen(buf) + 1);
if (ret_result == NULL) {
- app2ext_print("Malloc failed!\n");
+ _E("malloc failed");
return NULL;
}
memset(ret_result, '\0', strlen(buf) + 1);
memcpy(ret_result, buf, strlen(buf));
+
return ret_result;
}
result = dup(my_pipe[1]);
if (result < 0) {
strerror_r(errno, err_buf, sizeof(err_buf));
- fprintf(stderr, "dup failed %d....%s\n", errno, err_buf);
+ fprintf(stderr, "dup failed %d....%s\n",
+ errno, err_buf);
_exit(-1);
}
result = dup(my_pipe[1]);
if (result < 0) {
strerror_r(errno, err_buf, sizeof(err_buf));
- fprintf(stderr, "dup failed %d....%s\n", errno, err_buf);
+ fprintf(stderr, "dup failed %d....%s\n",
+ errno, err_buf);
_exit(-1);
}
if (execvp(argv[0], (char *const *)argv) < 0) {
- fprintf(stderr, "execvp failed\n"); /*Don't use d_msg_app2sd */
+ fprintf(stderr, "execvp failed\n");
+ /* Don't use d_msg_app2sd */
}
_exit(-1);
default:
result = read(my_pipe[0], buf, FILENAME_MAX);
if (result < 0) {
strerror_r(errno, err_buf, sizeof(err_buf));
- fprintf(stderr, "read failed %d....%s\n", errno, err_buf);
+ fprintf(stderr, "read failed %d....%s\n",
+ errno, err_buf);
}
break;
}
ret_result = (char *)malloc(strlen(buf) + 1);
if (ret_result == NULL) {
- app2ext_print("Malloc failed!\n");
+ _E("malloc failed");
return NULL;
}
memset(ret_result, '\0', strlen(buf) + 1);
}
/* Note: Don't use any printf statement inside this function*/
-char *_app2sd_find_associated_device(const char *mmc_app_path)
+char *_app2sd_find_associated_device(const char *loopback_device)
{
- const char *argv[] = { "/sbin/losetup", "-j", mmc_app_path, NULL };
+ const char *argv[] = { "/sbin/losetup", "-a", NULL };
pid_t pid;
int my_pipe[2] = { 0, };
char buf[FILENAME_MAX] = { 0, };
+ char *ret_result_temp = NULL;
char *ret_result = NULL;
+ char *line = NULL;;
+ char *save_str = NULL;
int result = 0;
char err_buf[1024] = {0,};
result = dup(my_pipe[1]);
if (result < 0) {
strerror_r(errno, err_buf, sizeof(err_buf));
- fprintf(stderr, "dup failed %d....%s\n", errno, err_buf);
+ fprintf(stderr, "dup failed %d....%s\n",
+ errno, err_buf);
_exit(-1);
}
result = dup(my_pipe[1]);
if (result < 0) {
strerror_r(errno, err_buf, sizeof(err_buf));
- fprintf(stderr, "dup failed %d....%s\n", errno, err_buf);
+ fprintf(stderr, "dup failed %d....%s\n",
+ errno, err_buf);
_exit(-1);
}
if (execvp(argv[0], (char *const *)argv) < 0) {
- fprintf(stderr, "execvp failed\n"); /* Don't use d_msg_app2sd */
+ fprintf(stderr, "execvp failed\n");
+ /* Don't use d_msg_app2sd */
}
_exit(-1);
default:
result = read(my_pipe[0], buf, FILENAME_MAX);
if (result < 0) {
strerror_r(errno, err_buf, sizeof(err_buf));
- fprintf(stderr, "read failed %d....%s\n", errno, err_buf);
+ fprintf(stderr, "read failed %d....%s\n",
+ errno, err_buf);
}
break;
}
- ret_result = (char *)malloc(strlen(buf) + 1);
- if (ret_result == NULL) {
- app2ext_print("Malloc failed!\n");
+ ret_result_temp = (char *)malloc(strlen(buf) + 1);
+ if (ret_result_temp == NULL) {
+ _E("malloc failed");
return NULL;
}
- memset(ret_result, '\0', strlen(buf) + 1);
- memcpy(ret_result, buf, strlen(buf));
+ memset(ret_result_temp, '\0', strlen(buf) + 1);
+ memcpy(ret_result_temp, buf, strlen(buf));
+
+ line = strtok_r(ret_result_temp, "\n", &save_str);
+ while (line) {
+ if (strstr(line, loopback_device) != NULL) {
+ _D("found: (%s)", line);
+ if (ret_result) {
+ _D("duplicated device");
+ } else {
+ ret_result = strdup(line);
+ }
+ }
+ line = strtok_r(NULL, "\n", &save_str);
+ }
+ free(ret_result_temp);
return ret_result;
}
result = dup(my_pipe[1]);
if (result < 0) {
strerror_r(errno, err_buf, sizeof(err_buf));
- fprintf(stderr, "dup failed %d....%s\n", errno, err_buf);
+ fprintf(stderr, "dup failed %d....%s\n",
+ errno, err_buf);
_exit(-1);
}
result = dup(my_pipe[1]);
if (result < 0) {
strerror_r(errno, err_buf, sizeof(err_buf));
- fprintf(stderr, "dup failed %d....%s\n", errno, err_buf);
+ fprintf(stderr, "dup failed %d....%s\n",
+ errno, err_buf);
_exit(-1);
}
if (execvp(argv[0], (char *const *)argv) < 0) {
- fprintf(stderr, "execvp failed\n"); /*Don't use d_msg_app2sd */
+ fprintf(stderr, "execvp failed\n");
+ /* Don't use d_msg_app2sd */
}
_exit(-1);
default:
result = read(my_pipe[0], buf, FILENAME_MAX);
if (result < 0) {
strerror_r(errno, err_buf, sizeof(err_buf));
- fprintf(stderr, "read failed %d....%s\n", errno, err_buf);
+ fprintf(stderr, "read failed %d....%s\n",
+ errno, err_buf);
}
break;
}
ret_result = (char *)malloc(strlen(buf) + 1);
if (ret_result == NULL) {
- app2ext_print("Malloc failed!\n");
+ _E("malloc failed");
return NULL;
}
memset(ret_result, '\0', strlen(buf) + 1);
{
char passwd[PASSWD_LEN+1] = { 0, };
char *ret_result = NULL;
- char set[ASCII_PASSWD_CHAR+1] = "!\"#$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
+ char set[ASCII_PASSWD_CHAR+1] =
+ "!\"#$%&()*+,-./0123456789:;<=>?@ABCDE" \
+ "FGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
unsigned char char_1;
unsigned char char_2;
int i = 0;
unsigned int seed;
/* Length of the password */
- ret_result = (char*)malloc(PASSWD_LEN+1);
+ ret_result = (char*)malloc(PASSWD_LEN + 1);
if (NULL == ret_result) {
- app2ext_print("Unable to Allocate memory\n");
+ _E("unable to allocate memory");
return NULL;
}
- memset((void *)ret_result, '\0', PASSWD_LEN+1);
+ memset((void *)ret_result, '\0', PASSWD_LEN + 1);
- while(i < PASSWD_LEN) {
+ while (i < PASSWD_LEN) {
seed = time(NULL);
- char_1 = (rand_r(&seed)+pkgid[j--])%ASCII_PASSWD_CHAR;
- char_2 = rand_r(&seed)%ASCII_PASSWD_CHAR;
+ char_1 = (rand_r(&seed) + pkgid[j--]) % ASCII_PASSWD_CHAR;
+ char_2 = rand_r(&seed) % ASCII_PASSWD_CHAR;
passwd[i] = set[char_1];
- passwd[i+1] = set[(pkgid[j--])*2];
- if (i<PASSWD_LEN-3)
- passwd[i+2] = set[char_2];
+ passwd[i + 1] = set[(pkgid[j--]) * 2];
+ if (i < PASSWD_LEN - 3)
+ passwd[i + 2] = set[char_2];
i++;
}
- app2ext_print("Password is %s\n", passwd);
- memcpy(ret_result, passwd, PASSWD_LEN+1);
+ memcpy(ret_result, passwd, PASSWD_LEN + 1);
+
return ret_result;
}
--- /dev/null
+/*
+ * app2sd-server
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <app2sd_internals.h>
+#include <app2sd_interface.h>
+#include <glib.h>
+#include <gio/gio.h>
+
+GMainLoop *app2sd_mainloop = NULL;
+
+gboolean __exit_app2sd_server(void *data)
+{
+ _D("exit app2sd_server");
+
+ g_main_loop_quit(app2sd_mainloop);
+
+ return FALSE;
+}
+
+static int __app2sd_get_sender_unixinfo(GDBusConnection *conn,
+ const char *sender_name, const char *type)
+{
+ GDBusMessage *msg = NULL;
+ GDBusMessage *reply = NULL;
+ GError *err = NULL;
+ GVariant *body;
+ int ret = -1;
+ unsigned int value;
+
+ msg = g_dbus_message_new_method_call("org.freedesktop.DBus",
+ "/org/freedesktop/DBus", "org.freedesktop.DBus", type);
+ if (!msg) {
+ _E("Can't allocate new method call");
+ goto out;
+ }
+
+ g_dbus_message_set_body(msg, g_variant_new("(s)", sender_name));
+ reply = g_dbus_connection_send_message_with_reply_sync(conn, msg,
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &err);
+
+ if (!reply) {
+ if (err != NULL) {
+ _E("Failed to get info [%s]", err->message);
+ g_error_free(err);
+ }
+ goto out;
+ }
+
+ body = g_dbus_message_get_body(reply);
+ g_variant_get(body, "(u)", &value);
+ ret = (int)value;
+
+out:
+ if (msg)
+ g_object_unref(msg);
+ if (reply)
+ g_object_unref(reply);
+
+ return ret;
+}
+
+static int __app2sd_get_sender_pid(GDBusConnection *conn,
+ const char *sender_name)
+{
+ int pid = 0;
+
+ pid = __app2sd_get_sender_unixinfo(conn, sender_name,
+ "GetConnectionUnixProcessID");
+ if (pid < 0) {
+ _E("failed to get pid");
+ pid = 0;
+ }
+
+ _D("sender_name(%s), pid(%d)", sender_name, pid);
+
+ return pid;
+}
+
+static int __app2sd_get_sender_uid(GDBusConnection *conn,
+ const char *sender_name)
+{
+ int uid = -1;
+
+ uid = __app2sd_get_sender_unixinfo(conn, sender_name,
+ "GetConnectionUnixUser");
+ if (uid < 0) {
+ _E("failed to get uid");
+ }
+
+ _D("sender_name(%s), uid(%d)", sender_name, uid);
+
+ return uid;
+}
+
+static GDBusNodeInfo *introspection_data;
+static const gchar introspection_xml[] =
+"<node>"
+" <interface name='org.tizen.app2sd'>"
+" <method name='PreAppInstall'>"
+" <arg type='s' name='pkgid' direction='in'/>"
+" <arg type='i' name='size' direction='in'/>"
+" <arg type='a(si)' name='dir_list' direction='in'/>"
+" <arg type='i' name='uid' direction='in'/>"
+" <arg type='i' name='result' direction='out'/>"
+" </method>"
+" <method name='PostAppInstall'>"
+" <arg type='s' name='pkgid' direction='in'/>"
+" <arg type='i' name='install_status' direction='in'/>"
+" <arg type='i' name='uid' direction='in'/>"
+" <arg type='i' name='result' direction='out'/>"
+" </method>"
+" <method name='PreAppUpgrade'>"
+" <arg type='s' name='pkgid' direction='in'/>"
+" <arg type='i' name='size' direction='in'/>"
+" <arg type='a(si)' name='dir_list' direction='in'/>"
+" <arg type='i' name='uid' direction='in'/>"
+" <arg type='i' name='result' direction='out'/>"
+" </method>"
+" <method name='PostAppUpgrade'>"
+" <arg type='s' name='pkgid' direction='in'/>"
+" <arg type='i' name='install_status' direction='in'/>"
+" <arg type='i' name='uid' direction='in'/>"
+" <arg type='i' name='result' direction='out'/>"
+" </method>"
+" <method name='PreAppUninstall'>"
+" <arg type='s' name='pkgid' direction='in'/>"
+" <arg type='i' name='uid' direction='in'/>"
+" <arg type='i' name='result' direction='out'/>"
+" </method>"
+" <method name='PostAppUninstall'>"
+" <arg type='s' name='pkgid' direction='in'/>"
+" <arg type='i' name='uid' direction='in'/>"
+" <arg type='i' name='result' direction='out'/>"
+" </method>"
+" <method name='OndemandSetupInit'>"
+" <arg type='s' name='pkgid' direction='in'/>"
+" <arg type='i' name='uid' direction='in'/>"
+" <arg type='i' name='result' direction='out'/>"
+" </method>"
+" <method name='OndemandSetupExit'>"
+" <arg type='s' name='pkgid' direction='in'/>"
+" <arg type='i' name='uid' direction='in'/>"
+" <arg type='i' name='result' direction='out'/>"
+" </method>"
+" <method name='MoveInstalledApp'>"
+" <arg type='s' name='pkgid' direction='in'/>"
+" <arg type='i' name='move_type' direction='in'/>"
+" <arg type='a(si)' name='dir_list' direction='in'/>"
+" <arg type='i' name='uid' direction='in'/>"
+" <arg type='i' name='result' direction='out'/>"
+" </method>"
+" </interface>"
+"</node>";
+
+static void _app2sd_server_return_method_error(GDBusMethodInvocation *invocation, int result)
+{
+ GVariant *param = NULL;
+
+ param = g_variant_new("(i)", result);
+ g_dbus_method_invocation_return_value(invocation, param);
+}
+
+static void _app2sd_server_pre_app_install(GDBusConnection *connection, const gchar *sender,
+ GVariant *parameters, GDBusMethodInvocation *invocation, uid_t sender_uid)
+{
+ GVariant *param = NULL;
+ int result = APP2EXT_SUCCESS;
+ int size;
+ char *pkgid = NULL;
+ GVariantIter *iter;
+ gchar *str = NULL;
+ int type;
+ int ret = 0;
+ uid_t target_uid = -1;
+ GList *dir_list = NULL;
+ GList *list = NULL;
+ app2ext_dir_details *dir_detail = NULL;
+
+ g_variant_get(parameters, "(&sia(si)i)", &pkgid, &size, &iter, &target_uid);
+
+ _D("pkgid(%s), size(%d),sender_uid(%d), target_uid(%d)",
+ pkgid, size, sender_uid, target_uid);
+
+ if (sender_uid != 0 && sender_uid != target_uid) {
+ _E("Not permitted user!");
+ g_variant_iter_free(iter);
+ _app2sd_server_return_method_error(invocation,
+ APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
+ return;
+ }
+
+ while (g_variant_iter_loop(iter, "(si)", &str, &type)) {
+ if (str) {
+ _D("str(%s), type(%d)", str, type);
+
+ /* generate dir_list */
+ dir_detail = (app2ext_dir_details *)calloc(1, sizeof(app2ext_dir_details));
+ if (dir_detail == NULL) {
+ _E("memory allocation failed");
+ result = APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
+ break;
+ }
+
+ dir_detail->name = strdup((char *)str);
+ if (dir_detail->name == NULL) {
+ _E("out of memory");
+ free(dir_detail);
+ result = APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
+ break;
+ }
+
+ dir_detail->type = type;
+ list = g_list_append(list, dir_detail);
+ }
+ }
+ g_variant_iter_free(iter);
+
+ dir_list = g_list_first(list);
+ ret = app2sd_usr_pre_app_install(pkgid, dir_list, size, target_uid);
+ 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_post_app_install(GDBusConnection *connection, const gchar *sender,
+ GVariant *parameters, GDBusMethodInvocation *invocation, uid_t sender_uid)
+{
+ GVariant *param = NULL;
+ int result = APP2EXT_SUCCESS;
+ char *pkgid = NULL;
+ int install_status = 0;
+ int target_uid = -1;
+ int ret = 0;
+
+ g_variant_get(parameters, "(&sii)", &pkgid, &install_status, &target_uid);
+
+ _D("pkgid(%s), install_status(%d), sender_uid(%d), target_uid(%d)",
+ pkgid, install_status, sender_uid, target_uid);
+
+ if (sender_uid != 0 && sender_uid != target_uid) {
+ _E("Not permitted user!");
+ _app2sd_server_return_method_error(invocation,
+ APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
+ return;
+ }
+
+ ret = app2sd_usr_post_app_install(pkgid, install_status, target_uid);
+ 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_pre_app_upgrade(GDBusConnection *connection, const gchar *sender,
+ GVariant *parameters, GDBusMethodInvocation *invocation, uid_t sender_uid)
+{
+ GVariant *param = NULL;
+ int result = APP2EXT_SUCCESS;
+ int size;
+ char *pkgid = NULL;
+ GVariantIter *iter;
+ gchar *str = NULL;
+ int type;
+ uid_t target_uid = -1;
+ int ret = 0;
+ GList *dir_list = NULL;
+ GList *list = NULL;
+ app2ext_dir_details *dir_detail = NULL;
+
+ g_variant_get(parameters, "(&sia(si)i)", &pkgid, &size, &iter, &target_uid);
+
+ _D("pkgid(%s), size(%d), sender_uid(%d), target_uid(%d)",
+ pkgid, size, sender_uid, target_uid);
+
+ if (sender_uid != 0 && sender_uid != target_uid) {
+ _E("Not permitted user!");
+ g_variant_iter_free(iter);
+ _app2sd_server_return_method_error(invocation,
+ APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
+ return;
+ }
+
+ while (g_variant_iter_loop(iter, "(si)", &str, &type)) {
+ if (str) {
+ _D("str(%s), type(%d)", str, type);
+
+ /* generate dir_list */
+ dir_detail = (app2ext_dir_details *)calloc(1, sizeof(app2ext_dir_details));
+ if (dir_detail == NULL) {
+ _E("memory allocation failed");
+ result = APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
+ break;
+ }
+
+ dir_detail->name = strdup((char *)str);
+ if (dir_detail->name == NULL) {
+ _E("out of memory");
+ free(dir_detail);
+ result = APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
+ break;
+ }
+
+ dir_detail->type = type;
+ list = g_list_append(list, dir_detail);
+ }
+ }
+ g_variant_iter_free(iter);
+
+ dir_list = g_list_first(list);
+ ret = app2sd_usr_pre_app_upgrade(pkgid, dir_list, size, target_uid);
+ 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_post_app_upgrade(GDBusConnection *connection, const gchar *sender,
+ GVariant *parameters, GDBusMethodInvocation *invocation, uid_t sender_uid)
+{
+ GVariant *param = NULL;
+ int result = APP2EXT_SUCCESS;
+ char *pkgid = NULL;
+ int install_status = 0;
+ uid_t target_uid = -1;
+ int ret = 0;
+
+ g_variant_get(parameters, "(&sii)", &pkgid, &install_status, &target_uid);
+
+ _D("pkgid(%s), install_status(%d), sender_uid(%d), target_uid(%d)",
+ pkgid, install_status, sender_uid, target_uid);
+
+ if (sender_uid != 0 && sender_uid != target_uid) {
+ _E("Not permitted user!");
+ _app2sd_server_return_method_error(invocation,
+ APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
+ return;
+ }
+
+ ret = app2sd_usr_post_app_upgrade(pkgid, install_status, target_uid);
+ 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_pre_app_uninstall(GDBusConnection *connection, const gchar *sender,
+ GVariant *parameters, GDBusMethodInvocation *invocation, uid_t sender_uid)
+{
+ GVariant *param = NULL;
+ int result = APP2EXT_SUCCESS;
+ char *pkgid = NULL;
+ uid_t target_uid = -1;
+ int ret = 0;
+
+ g_variant_get(parameters, "(&si)", &pkgid, &target_uid);
+
+ _D("pkgid(%s), sender_uid(%d), target_uid(%d)",
+ pkgid, sender_uid, target_uid);
+
+ if (sender_uid != 0 && sender_uid != target_uid) {
+ _E("Not permitted user!");
+ _app2sd_server_return_method_error(invocation,
+ APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
+ return;
+ }
+
+ ret = app2sd_usr_pre_app_uninstall(pkgid, target_uid);
+ 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_post_app_uninstall(GDBusConnection *connection, const gchar *sender,
+ GVariant *parameters, GDBusMethodInvocation *invocation, uid_t sender_uid)
+{
+ GVariant *param = NULL;
+ int result = APP2EXT_SUCCESS;
+ char *pkgid = NULL;
+ uid_t target_uid = -1;
+ int ret = 0;
+
+ g_variant_get(parameters, "(&si)", &pkgid, &target_uid);
+
+ _D("pkgid(%s), sender_uid(%d), target_uid(%d)",
+ pkgid, sender_uid, target_uid);
+
+ if (sender_uid != 0 && sender_uid != target_uid) {
+ _E("Not permitted user!");
+ _app2sd_server_return_method_error(invocation,
+ APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
+ return;
+ }
+
+ ret = app2sd_usr_post_app_uninstall(pkgid, target_uid);
+ 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_ondemand_setup_init(GDBusConnection *connection, const gchar *sender,
+ GVariant *parameters, GDBusMethodInvocation *invocation, uid_t sender_uid)
+{
+ GVariant *param = NULL;
+ int result = APP2EXT_SUCCESS;
+ char *pkgid = NULL;
+ uid_t target_uid = -1;
+ int ret = 0;
+
+ g_variant_get(parameters, "(&si)", &pkgid, &target_uid);
+
+ _D("pkgid(%s), sender_uid(%d), target_uid(%d)",
+ pkgid, sender_uid, target_uid);
+
+ if (sender_uid != 0 && sender_uid != target_uid) {
+ _E("Not permitted user!");
+ _app2sd_server_return_method_error(invocation,
+ APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
+ return;
+ }
+
+ ret = app2sd_usr_on_demand_setup_init(pkgid, target_uid);
+ 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_ondemand_setup_exit(GDBusConnection *connection, const gchar *sender,
+ GVariant *parameters, GDBusMethodInvocation *invocation, uid_t sender_uid)
+{
+ GVariant *param = NULL;
+ int result = APP2EXT_SUCCESS;
+ char *pkgid = NULL;
+ uid_t target_uid = -1;
+ int ret = 0;
+
+ g_variant_get(parameters, "(&si)", &pkgid, &target_uid);
+
+ _D("pkgid(%s), sender_uid(%d), target_uid(%d)",
+ pkgid, sender_uid, target_uid);
+
+ if (sender_uid != 0 && sender_uid != target_uid) {
+ _E("Not permitted user!");
+ _app2sd_server_return_method_error(invocation,
+ APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
+ return;
+ }
+
+ ret = app2sd_usr_on_demand_setup_exit(pkgid, target_uid);
+ 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_move_installed_app(GDBusConnection *connection, const gchar *sender,
+ GVariant *parameters, GDBusMethodInvocation *invocation, uid_t sender_uid)
+{
+ GVariant *param = NULL;
+ int result = APP2EXT_SUCCESS;
+ int move_type;
+ char *pkgid = NULL;
+ GVariantIter *iter;
+ gchar *str = NULL;
+ int type;
+ int ret = 0;
+ uid_t target_uid = -1;
+ GList *dir_list = NULL;
+ GList *list = NULL;
+ app2ext_dir_details *dir_detail = NULL;
+
+ g_variant_get(parameters, "(&sia(si)i)", &pkgid, &move_type, &iter, &target_uid);
+
+ _D("pkgid(%s), move_type(%d),sender_uid(%d), target_uid(%d)",
+ pkgid, move_type, sender_uid, target_uid);
+
+ if (sender_uid != 0 && sender_uid != target_uid) {
+ _E("Not permitted user!");
+ g_variant_iter_free(iter);
+ _app2sd_server_return_method_error(invocation,
+ APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
+ return;
+ }
+
+ while (g_variant_iter_loop(iter, "(si)", &str, &type)) {
+ if (str) {
+ _D("str(%s), type(%d)", str, type);
+
+ /* generate dir_list */
+ dir_detail = (app2ext_dir_details *)calloc(1, sizeof(app2ext_dir_details));
+ if (dir_detail == NULL) {
+ _E("memory allocation failed");
+ result = APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
+ break;
+ }
+
+ dir_detail->name = strdup((char *)str);
+ if (dir_detail->name == NULL) {
+ _E("out of memory");
+ free(dir_detail);
+ result = APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
+ break;
+ }
+
+ dir_detail->type = type;
+ list = g_list_append(list, dir_detail);
+ }
+ }
+ g_variant_iter_free(iter);
+
+ dir_list = g_list_first(list);
+ ret = app2sd_usr_move_installed_app(pkgid, dir_list, move_type, target_uid);
+ if (ret) {
+ _E("usr_move 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,
+ GVariant *parameters, GDBusMethodInvocation *invocation,
+ gpointer user_data)
+{
+ uid_t sender_uid = -1;
+
+ sender_uid = (uid_t)__app2sd_get_sender_uid(connection, sender);
+
+ if (g_strcmp0(method_name, "PreAppInstall") == 0) {
+ _app2sd_server_pre_app_install(connection, sender,
+ parameters, invocation, sender_uid);
+ } else if (g_strcmp0(method_name, "PostAppInstall") == 0) {
+ _app2sd_server_post_app_install(connection, sender,
+ parameters, invocation, sender_uid);
+ } else if (g_strcmp0(method_name, "PreAppUpgrade") == 0) {
+ _app2sd_server_pre_app_upgrade(connection, sender,
+ parameters, invocation, sender_uid);
+ } else if (g_strcmp0(method_name, "PostAppUpgrade") == 0) {
+ _app2sd_server_post_app_upgrade(connection, sender,
+ parameters, invocation, sender_uid);
+ } else if (g_strcmp0(method_name, "PreAppUninstall") == 0) {
+ _app2sd_server_pre_app_uninstall(connection, sender,
+ parameters, invocation, sender_uid);
+ } else if (g_strcmp0(method_name, "PostAppUninstall") == 0) {
+ _app2sd_server_post_app_uninstall(connection, sender,
+ parameters, invocation, sender_uid);
+ } else if (g_strcmp0(method_name, "OndemandSetupInit") == 0) {
+ _app2sd_server_ondemand_setup_init(connection, sender,
+ parameters, invocation, sender_uid);
+ } else if (g_strcmp0(method_name, "OndemandSetupExit") == 0) {
+ _app2sd_server_ondemand_setup_exit(connection, sender,
+ parameters, invocation, sender_uid);
+ } else if (g_strcmp0(method_name, "MoveInstalledApp") == 0) {
+ _app2sd_server_move_installed_app(connection, sender,
+ parameters, invocation, sender_uid);
+ }
+
+ g_timeout_add_seconds(5, __exit_app2sd_server, NULL);
+}
+
+static const GDBusInterfaceVTable interface_vtable = {
+ handle_method_call,
+ NULL,
+ NULL
+};
+
+static void __app2sd_on_bus_acquired(GDBusConnection *connection,
+ const gchar *name, gpointer user_data)
+{
+ _I("bus acquired(%s)", name);
+
+ guint reg_id = 0;
+ GError *error = NULL;
+
+ reg_id = g_dbus_connection_register_object(connection,
+ APP2SD_OBJECT_PATH,
+ introspection_data->interfaces[0],
+ &interface_vtable,
+ NULL, NULL, &error);
+ if (reg_id == 0) {
+ _E("g_dbus_connection_register_object error(%s)", error->message);
+ g_error_free(error);
+ }
+}
+
+static void __app2sd_on_name_acquired(GDBusConnection *connection,
+ const gchar *name, gpointer user_data)
+{
+ _I("name acquired(%s)", name);
+}
+
+static void __app2sd_on_name_lost(GDBusConnection *connection,
+ const gchar *name, gpointer user_data)
+{
+ _E("name lost(%s)", name);
+}
+
+static int __app2sd_server_init()
+{
+ GError *error = NULL;
+ guint owner_id = 0;
+
+ /* gdbus setup for method call */
+ introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, &error);
+ if (!introspection_data) {
+ _E("g_dbus_node_info_new_for_xml error(%s)", error->message);
+ g_error_free(error);
+ return -1;
+ }
+
+ owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
+ APP2SD_BUS_NAME,
+ G_BUS_NAME_OWNER_FLAGS_NONE,
+ __app2sd_on_bus_acquired,
+ __app2sd_on_name_acquired,
+ __app2sd_on_name_lost,
+ NULL, NULL);
+ if (!owner_id) {
+ _E("g_bus_own_name error");
+ g_dbus_node_info_unref(introspection_data);
+ return -1;
+ }
+
+ /* add timer */
+
+ return 0;
+}
+
+static void __app2sd_finalize(void)
+{
+ _D("app2sd finalize");
+
+ if (introspection_data)
+ g_dbus_node_info_unref(introspection_data);
+
+ _D("app2sd finalize end");
+}
+
+int main(int argc, char *argv[])
+{
+ int ret = 0;
+
+ _I("app2sd_server : start");
+
+ ret = __app2sd_server_init();
+ if (ret) {
+ _E("app2sd_server init failed(%d)", ret);
+ return -1;
+ }
+
+ app2sd_mainloop = g_main_loop_new(NULL, FALSE);
+ if (!app2sd_mainloop) {
+ _E("g_main_loop_new failed");
+ return -1;
+ }
+
+ g_main_loop_run(app2sd_mainloop);
+
+ __app2sd_finalize();
+
+ _I("app2sd_server : end");
+
+ return 0;
+}
#define APP2EXT_SD_PLUGIN_PATH LIBPREFIX "/libapp2sd.so"
+int _is_global(uid_t uid)
+{
+ if (uid == OWNER_ROOT || uid == GLOBAL_USER)
+ return 1;
+ else
+ return 0;
+}
+
app2ext_handle *app2ext_init(int storage_type)
{
- /*Validate the function parameter recieved */
+ void *dl_handle = NULL;
+ int (*dl_on_load)(app2ext_interface *) = NULL;
+
+ /* validate the function parameter recieved */
if (storage_type < APP2EXT_INTERNAL_MEM ||
storage_type > APP2EXT_CLOUD) {
- app2ext_print("App2Ext Error : Invalid function arguments\n");
+ _E("invalid function arguments");
return NULL;
}
if (storage_type != APP2EXT_SD_CARD ) {
- app2ext_print("App2Ext Error : Storage type currently not supported\n");
+ _E("storage type currently not supported");
return NULL;
}
/* allocate memory for app2ext handle*/
app2ext_handle *handle = (app2ext_handle *)calloc(1, sizeof(app2ext_handle));
if (handle == NULL) {
- app2ext_print("App2Ext Error : Memory allocation failure\n");
+ _E("memory allocation failed");
return NULL;
}
- void *dl_handle = NULL;
- int (*dl_on_load)(app2ext_interface *)=NULL;
- /* Load SD plugin*/
+ /* load SD plugin*/
handle->type = APP2EXT_SD_CARD;
dl_handle = dlopen(APP2EXT_SD_PLUGIN_PATH, RTLD_LAZY|RTLD_GLOBAL);
- if (NULL == dl_handle)
- {
- app2ext_print("App2Ext Error : dlopen(%s) failed.\n", APP2EXT_SD_PLUGIN_PATH);
+ if (NULL == dl_handle) {
+ _E("dlopen(%s) failed", APP2EXT_SD_PLUGIN_PATH);
free(handle);
return NULL;
}
+
handle->plugin_handle = dl_handle;
dl_on_load = dlsym(dl_handle, "app2ext_on_load");
- if (NULL == dl_on_load)
- {
- app2ext_print("App2Ext Error : Cannot find app2ext_on_load symbol in %s.", APP2EXT_SD_PLUGIN_PATH);
+ if (NULL == dl_on_load) {
+ _E("cannot find app2ext_on_load symbol in (%s)", APP2EXT_SD_PLUGIN_PATH);
dlclose(dl_handle);
free(handle);
return NULL;
}
- /*Initialize the SD plugin*/
- if(!dl_on_load(&(handle->interface)))
- {
- app2ext_print("App2Ext Error : [%s] app2ext_on_load() failed.", APP2EXT_SD_PLUGIN_PATH);
+ /* initialize the SD plugin*/
+ if (!dl_on_load(&(handle->interface))) {
+ _E("app2ext_on_load() failed in (%s)", APP2EXT_SD_PLUGIN_PATH);
dlclose(dl_handle);
free(handle);
return NULL;
}
- app2ext_print("App2Ext: %s plugin loaded\n", APP2EXT_SD_PLUGIN_PATH);
+ _D("plugin(%s) loaded", APP2EXT_SD_PLUGIN_PATH);
return handle;
}
int app2ext_deinit(app2ext_handle *handle)
{
- /*Validate the function parameter recieved */
+ /* validate the function parameter recieved */
if (handle == NULL || handle->plugin_handle == NULL){
- app2ext_print("App2Ext Error : Invalid function arguments\n");
+ _E("invalid function arguments");
return APP2EXT_ERROR_INVALID_ARGUMENTS;
}
- /* Close the plugin handle*/
+ /* close the plugin handle*/
dlclose(handle->plugin_handle);
- /* Free allocated memory during installtion*/
+ /* free allocated memory during installtion*/
free(handle);
+
return APP2EXT_SUCCESS;
}
-int app2ext_get_app_location(const char *appname)
+int app2ext_usr_get_app_location(const char *pkgid, uid_t uid)
{
- /*Validate the function parameter received */
- if (appname == NULL) {
- app2ext_print("invalid func parameters\n");
+ FILE *fp = NULL;
+ char loopback_device[FILENAME_MAX] = { 0, };
+ char application_path[FILENAME_MAX] = { 0, };
+ char application_mmc_path[FILENAME_MAX] = { 0, };
+
+ /* validate the function parameter received */
+ if (pkgid == NULL) {
+ _E("invalid func parameters");
return APP2EXT_ERROR_INVALID_ARGUMENTS;
}
- FILE *fp = NULL;
- char app_mmc_path[FILENAME_MAX] = { 0, };
- char app_dir_path[FILENAME_MAX] = { 0, };
- char app_mmc_internal_path[FILENAME_MAX] = { 0, };
- snprintf(app_dir_path, FILENAME_MAX,
- "%s%s", APP_INSTALLATION_PATH, appname);
- snprintf(app_mmc_path, FILENAME_MAX,
- "%s%s", APP2SD_PATH, appname);
- snprintf(app_mmc_internal_path, FILENAME_MAX,
- "%s%s/.mmc", APP_INSTALLATION_PATH, appname);
-
- app2ext_print("MMC_PATH = (%s)\n", MMC_PATH);
- app2ext_print("APP2SD_PATH = (%s)\n", APP2SD_PATH);
- app2ext_print("APP_INSTALLATION_PATH = (%s)\n", APP_INSTALLATION_PATH);
- app2ext_print("APP_INSTALLATION_USER_PATH = (%s)\n", APP_INSTALLATION_USER_PATH);
- app2ext_print("app_dir_path = (%s)\n", app_dir_path);
- app2ext_print("app_mmc_path = (%s)\n", app_mmc_path);
- app2ext_print("app_mmc_internal_path = (%s)\n", app_mmc_internal_path);
+
+ if (_is_global(uid)) {
+ snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
+ tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
+ snprintf(application_mmc_path, FILENAME_MAX - 1, "%s/%s/.mmc",
+ tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
+ snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
+ APP2SD_PATH, pkgid);
+ } else {
+ tzplatform_set_user(uid);
+ snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
+ tzplatform_getenv(TZ_USER_APP), pkgid);
+ snprintf(application_mmc_path, FILENAME_MAX - 1, "%s/%s/.mmc",
+ tzplatform_getenv(TZ_USER_APP), pkgid);
+ snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
+ APP2SD_PATH, tzplatform_getenv(TZ_USER_NAME), pkgid);
+ tzplatform_reset_user();
+ }
+ _D("application_path = (%s)", application_path);
+ _D("application_mmc_path = (%s)", application_mmc_path);
+ _D("loopback_device = (%s)", loopback_device);
/*check whether application is in external memory or not */
- fp = fopen(app_mmc_path, "r");
+ fp = fopen(loopback_device, "r");
if (fp != NULL) {
fclose(fp);
fp = NULL;
+ _D("sd card");
return APP2EXT_SD_CARD;
}
/*check whether application is in internal or not */
- fp = fopen(app_dir_path, "r");
+ fp = fopen(application_path, "r");
if (fp == NULL) {
- app2ext_print("app_dir_path open failed, package not installed\n");
+ _D("app_dir_path open failed, " \
+ "package not installed");
return APP2EXT_NOT_INSTALLED;
} else {
fclose(fp);
- /*check whether the application is installed in SD card
- but SD card is not present*/
- fp = fopen(app_mmc_internal_path, "r");
+ /* check whether the application is installed in SD card
+ * but SD card is not present
+ */
+ fp = fopen(application_mmc_path, "r");
if (fp == NULL) {
- app2ext_print("internal mem\n");
+ _D("internal mem");
return APP2EXT_INTERNAL_MEM;
} else {
fclose(fp);
- app2ext_print("app_mmc_internal_path exists, error mmc status\n");
+ _E("app_mmc_internal_path exists, " \
+ "error mmc status");
return APP2EXT_ERROR_MMC_STATUS;
}
}
}
+int app2ext_get_app_location(const char *pkgid)
+{
+ int ret = 0;
-int app2ext_enable_external_pkg(const char *pkgid)
+ ret = app2ext_usr_get_app_location(pkgid, getuid());
+
+ return ret;
+}
+
+int app2ext_usr_enable_external_pkg(const char *pkgid, uid_t uid)
{
- /*Validate the function parameter received */
+ FILE *fp = NULL;
+ app2ext_handle *app2_handle = NULL;
+ char loopback_device[FILENAME_MAX] = { 0, };
+
+ /* validate the function parameter received */
if (pkgid == NULL) {
- app2ext_print("invalid func parameters\n");
+ _E("invalid func parameters");
return -1;
}
- FILE *fp = NULL;
- app2ext_handle *app2_handle = NULL;
- char app_mmc_path[FILENAME_MAX] = { 0, };
- snprintf(app_mmc_path, FILENAME_MAX, "%s%s", APP2SD_PATH, pkgid);
- /*check whether application is in external memory or not */
- fp = fopen(app_mmc_path, "r");
+ if (_is_global(uid)) {
+ snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
+ APP2SD_PATH, pkgid);
+ } else {
+ tzplatform_set_user(uid);
+ snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
+ APP2SD_PATH, tzplatform_getenv(TZ_USER_NAME), pkgid);
+ tzplatform_reset_user();
+ }
+
+ _D("loopback_device = (%s)", loopback_device);
+
+ /* check whether application is in external memory or not */
+ fp = fopen(loopback_device, "r");
if (fp != NULL) {
fclose(fp);
fp = NULL;
app2_handle = app2ext_init(APP2EXT_SD_CARD);
if (app2_handle == NULL) {
- app2ext_print("app2_handle : app2ext init failed\n");
+ _E("app2ext init failed");
return -2;
}
- app2_handle->interface.enable(pkgid);
+ app2_handle->interface.client_usr_enable(pkgid, uid);
app2ext_deinit(app2_handle);
- app2ext_print("App2Ext enable_external_pkg [%s]\n", pkgid);
}
return 0;
}
+int app2ext_enable_external_pkg(const char *pkgid)
+{
+ int ret = 0;
-int app2ext_disable_external_pkg(const char *pkgid)
+ ret = app2ext_usr_enable_external_pkg(pkgid, getuid());
+
+ return ret;
+}
+
+int app2ext_usr_disable_external_pkg(const char *pkgid, uid_t uid)
{
- /*Validate the function parameter received */
+ FILE *fp = NULL;
+ app2ext_handle *app2_handle = NULL;
+ char loopback_device[FILENAME_MAX] = { 0, };
+
+ /* validate the function parameter received */
if (pkgid == NULL) {
- app2ext_print("invalid func parameters\n");
+ _E("invalid func parameters");
return -1;
}
- FILE *fp = NULL;
- app2ext_handle *app2_handle = NULL;
- char app_mmc_path[FILENAME_MAX] = { 0, };
- snprintf(app_mmc_path, FILENAME_MAX, "%s%s", APP2SD_PATH, pkgid);
- /*check whether application is in external memory or not */
- fp = fopen(app_mmc_path, "r");
+ if (_is_global(uid)) {
+ snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
+ APP2SD_PATH, pkgid);
+ } else {
+ tzplatform_set_user(uid);
+ snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
+ APP2SD_PATH, tzplatform_getenv(TZ_USER_NAME), pkgid);
+ tzplatform_reset_user();
+ }
+
+ _D("loopback_device = (%s)", loopback_device);
+
+ /* check whether application is in external memory or not */
+ fp = fopen(loopback_device, "r");
if (fp != NULL) {
fclose(fp);
fp = NULL;
app2_handle = app2ext_init(APP2EXT_SD_CARD);
if (app2_handle == NULL) {
- app2ext_print("app2_handle : app2ext init failed\n");
+ _E("app2_handle : app2ext init failed");
return -2;
}
- app2_handle->interface.disable(pkgid);
+ app2_handle->interface.client_usr_disable(pkgid, uid);
app2ext_deinit(app2_handle);
- app2ext_print("App2Ext disable_external_pkg [%s]\n", pkgid);
- }
- return 0;
-}
-
-int app2ext_enable_external_dir(void)
-{
- int ret = 0;
- DIR *dir = NULL;
- char buf[FILENAME_MAX] = { 0, };
- struct dirent entry, *result = NULL;
-
- 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 app2ext_disable_external_pkg(const char *pkgid)
{
int ret = 0;
- DIR *dir = NULL;
- char buf[FILENAME_MAX] = { 0, };
- struct dirent entry, *result = NULL;
-
- 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);
- }
+ ret = app2ext_usr_disable_external_pkg(pkgid, getuid());
- closedir(dir);
- return 0;
+ return ret;
}
-int app2ext_force_clean_pkg(const char *pkgid)
+int app2ext_usr_force_clean_pkg(const char *pkgid, uid_t uid)
{
- /*Validate the function parameter received */
+ FILE *fp = NULL;
+ app2ext_handle *app2_handle = NULL;
+ char application_mmc_path[FILENAME_MAX] = { 0, };
+
+ /* validate the function parameter received */
if (pkgid == NULL) {
- app2ext_print("invalid func parameters\n");
+ _E("invalid func parameters");
return 0;
}
- FILE *fp = NULL;
- app2ext_handle *app2_handle = NULL;
- char app_mmc_path[FILENAME_MAX] = { 0, };
- snprintf(app_mmc_path, FILENAME_MAX, "%s%s/.mmc", APP_INSTALLATION_PATH, pkgid);
+ if (_is_global(uid)) {
+ snprintf(application_mmc_path, FILENAME_MAX - 1, "%s/%s/.mmc",
+ tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
+ } else {
+ tzplatform_set_user(uid);
+ snprintf(application_mmc_path, FILENAME_MAX - 1, "%s/%s/.mmc",
+ tzplatform_getenv(TZ_USER_APP), pkgid);
+ tzplatform_reset_user();
+ }
+ _D("application_mmc_path = (%s)", application_mmc_path);
- fp = fopen(app_mmc_path, "r");
+ fp = fopen(application_mmc_path, "r");
if (fp == NULL) {
return 0;
} else {
app2_handle = app2ext_init(APP2EXT_SD_CARD);
if (app2_handle == NULL) {
- app2ext_print("app2_handle : app2ext init failed\n");
+ _E("app2ext init failed");
return 0;
}
- app2_handle->interface.force_clean(pkgid);
+ app2_handle->interface.client_usr_force_clean(pkgid, uid);
app2ext_deinit(app2_handle);
- app2ext_print("App2Ext force_clean_pkg [%s]\n", pkgid);
+
return 0;
}
+int app2ext_force_clean_pkg(const char *pkgid)
+{
+ int ret = 0;
+ ret = app2ext_usr_force_clean_pkg(pkgid, getuid());
+
+ return ret;
+}
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
ENDFOREACH(flag)
-pkg_check_modules(libpkgs REQUIRED dlog)
-
-FOREACH(flag ${libpkgs_CFLAGS})
- SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
-ENDFOREACH(flag)
-
### Local include directories
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/inc)
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE ${EXTRA_CFLAGS}")
-SET(CMAKE_C_FLAGS_DEBUG "-O0 -g -Wall -Wextra -fPIE")
-SET(CMAKE_C_FLAGS_RELEASE "-O3 -fPIE")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -Wall -Werror")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
ADD_EXECUTABLE(test_app2ext ${SRCS})
-TARGET_LINK_LIBRARIES(test_app2ext app2ext -ldl ${pkgs_LDFLAGS} "-pie")
+TARGET_LINK_LIBRARIES(test_app2ext app2ext ${pkgs_LDFLAGS})
+SET_TARGET_PROPERTIES(test_app2ext PROPERTIES COMPILE_FLAGS ${CFLAGS} "-fPIE")
+SET_TARGET_PROPERTIES(test_app2ext PROPERTIES LINK_FLAGS "-pie")
INSTALL(TARGETS test_app2ext DESTINATION /usr/bin COMPONENT Runtime)
#include <errno.h>
#include <sys/wait.h>
#include <sys/types.h>
+#include <getopt.h>
+#include <unzip.h>
+#include <tzplatform_config.h>
#include <app2ext_interface.h>
#define SUCCESS 0
#define FAIL 1
#define CMD_LEN 256
+#define TEST_PKGNAME "org.example.basicuiapplication"
+#define TEST_PKGNAME_PATH "/tmp/org.example.basicuiapplication-1.0.0-arm.tpk"
app2ext_handle *handle = NULL;
-#define TEST_PKGNAME "org.example.basicuiapplication"
-
char pkg_ro_content_rpm[3][5] = { "bin", "res", "lib" };
-char error_list[45][100] = {
+#define COUNT_OF_ERROR_LIST 50
+char error_list[COUNT_OF_ERROR_LIST][100] = {
"SUCCESS",
- "APP2EXT_ERROR_UNKNOW",
+ "APP2EXT_ERROR_UNKNOWN",
"APP2EXT_ERROR_INVALID_ARGUMENTS",
"APP2EXT_ERROR_MOVE",
"APP2EXT_ERROR_PRE_UNINSTALL",
"APP2EXT_ERROR_DETACH_LOOPBACK_DEVICE",
"APP2EXT_ERROR_ALREADY_MOUNTED",
"APP2EXT_ERROR_PLUGIN_INIT_FAILED",
- "APP2EXT_ERROR_PLUGIN_DEINIT_FAILED"
+ "APP2EXT_ERROR_PLUGIN_DEINIT_FAILED",
+ "APP2EXT_ERROR_DBUS_FAILED",
+ "APP2EXT_ERROR_MEMORY_ALLOC_FAILED",
+ "APP2EXT_ERROR_OPERATION_NOT_PERMITTED",
+ "APP2EXT_ERROR_SAME_LOOPBACK_DEVICE_EXISTS",
+ "APP2EXT_ERROR_PKGMGR_ERROR"
};
-static int __get_integer_input_data(void);
-
-static int __get_integer_input_data(void)
+static void usage(void)
{
- char input_str[32] = { 0, };
- int data = 0;
-
- if (fgets(input_str, 32, stdin) == NULL) {
- printf("Input buffer overflow....\n");
- return -1;
- }
-
- if (sscanf(input_str, "%4d", &data) != 1) {
- printf("Input only integer option....\n");
- return -1;
- }
-
- return data;
+ printf("\n");
+ printf("*************************************************\n");
+ printf("app2sd test usage:\n");
+ printf("pre-condition: /tmp/org.example.basicuiapplication-1.0.0-arm.tpk\n");
+ printf("\n");
+ printf("<INSTALL>\n");
+ printf("1.(at target_user)$test_app2ext --pre-install\n");
+ printf("2.(at target_user)$pkgcmd -it tpk {pkg-path}\n");
+ printf("3.(at target_user)$test_app2ext --post-install\n");
+ printf("------------------------------------------------\n");
+ printf("\n");
+ printf("<UPGRADE>\n");
+ printf("1.(at target_user)$test_app2ext --pre-upgrade\n");
+ printf("2.(at target_user)$pkgcmd -it tpk {pkg-path}\n");
+ printf("3.(at target_user)$test_app2ext --post-upgrade\n");
+ printf("------------------------------------------------\n");
+ printf("\n");
+ printf("<INSTALL>\n");
+ printf("1.(at target_user)$test_app2ext --pre-uninstall\n");
+ printf("2.(at target_user)$pkgcmd -un {pkg-id}\n");
+ printf("3.(at target_user)$test_app2ext --post-uninstall\n");
+ printf("------------------------------------------------\n");
+ printf("\n");
+ printf("<MOVE PKG TEST>\n");
+ printf("(at target_user)$test_app2ext --move\n");
+ printf("------------------------------------------------\n");
+ printf("\n");
+ printf("<GET INSTALLED LOCATION (Ext/Internal)>\n");
+ printf("(at target_user)$test_app2ext --getlocation\n");
+ printf("------------------------------------------------\n");
+ printf("\n");
+ 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("------------------------------------------------\n");
+ printf("**************************************************\n");
+ printf("\n");
}
-static void usage(void)
+#define OPTVAL_PRE_INSTALL 1000
+#define OPTVAL_POST_INSTALL 1001
+#define OPTVAL_PRE_UNINSTALL 1002
+#define OPTVAL_POST_UNINSTALL 1003
+#define OPTVAL_PRE_UPGRADE 1004
+#define OPTVAL_POST_UPGRADE 1005
+#define OPTVAL_MOVE 1006
+#define OPTVAL_GET_LOCATION 1007
+#define OPTVAL_ENABLE_APP 1008
+#define OPTVAL_DISABLE_APP 1009
+#define OPTVAL_USAGE 1010
+
+/* Supported options */
+const struct option long_opts[] = {
+ { "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 },
+ { "post-upgrade", 0, NULL, OPTVAL_POST_UPGRADE },
+ { "move", 0, NULL, OPTVAL_MOVE },
+ { "getlocation", 0, NULL, OPTVAL_GET_LOCATION },
+ { "enable", 0, NULL, OPTVAL_ENABLE_APP },
+ { "disable", 0, NULL, OPTVAL_DISABLE_APP },
+ { "help", 0, NULL, OPTVAL_USAGE },
+ { "usage", 0, NULL, OPTVAL_USAGE },
+ { 0, 0, 0, 0 } /* sentinel */
+};
+
+void clear_dir_list(GList* dir_list)
{
- printf("\n*********************************************\n");
- printf("app2sd test\n");
- printf("test_case\n");
- printf("<1> app_install (pre-install, install, post-install, enable, launch, disable)\n");
- printf("<2> app_uninstall (pre-uninstall, uninstall, post-uninstall)\n");
- printf("<3> app_upgrade (pre-upgrade, upgrade, post-Upgrade)\n");
- printf("<4> app_move\n");
- printf("<5> app_get_location\n");
- printf("<6> enable_external_dir\n");
- printf("<7> disable_external_dir\n");
- printf("<8> exit\n");
+ GList *list = 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) {
+ free(dir_detail->name);
+ }
+ list = g_list_next(list);
+ }
+ g_list_free(dir_list);
+ }
}
GList * populate_dir_details()
{
GList *dir_list = NULL;
GList *list = NULL;
- app2ext_dir_details* dir_detail = NULL;
+ app2ext_dir_details *dir_detail = NULL;
int i;
-
- for (i=0; i<3; i++) {
- dir_detail = (app2ext_dir_details*) calloc(1, sizeof(app2ext_dir_details));
+ for (i = 0; i < 3; i++) {
+ dir_detail = (app2ext_dir_details*)calloc(1, sizeof(app2ext_dir_details));
if (dir_detail == NULL) {
- printf("\nMemory allocation failed\n");
+ 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("\nMemory allocation failed\n");
+ printf("memory allocation failed\n");
free(dir_detail);
goto FINISH_OFF;
}
- snprintf(dir_detail->name, (strlen(pkg_ro_content_rpm[i])+1), "%s", pkg_ro_content_rpm[i]);
+ snprintf(dir_detail->name, (strlen(pkg_ro_content_rpm[i]) + 1), "%s", pkg_ro_content_rpm[i]);
dir_detail->type = APP2EXT_DIR_RO;
dir_list = g_list_append(dir_list, dir_detail);
}
+
if (dir_list) {
list = g_list_first(dir_list);
while (list) {
list = g_list_next(list);
}
}
+
return dir_list;
+
FINISH_OFF:
- if (dir_list) {
- list = g_list_first(dir_list);
- while (list) {
- dir_detail = (app2ext_dir_details *)list->data;
- if (dir_detail && dir_detail->name) {
- free(dir_detail->name);
- }
- list = g_list_next(list);
- }
- g_list_free(dir_list);
- }
+
+ clear_dir_list(dir_list);
+
return NULL;
}
-void clear_dir_list(GList* dir_list)
+static int get_unzip_size(const char *item, unsigned long long *size)
{
- GList *list = 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) {
- free(dir_detail->name);
- }
- list = g_list_next(list);
+ if (!item || !size) {
+ printf("get size : invalid argument\n");
+ return -1;
+ }
+ int ret = 0;
+ unzFile uzf = unzOpen64(item);
+ if (uzf == NULL) {
+ printf("get size : failed to open item : [%s]\n", item);
+ *size = 0;
+ return -1;
+ } else {
+ ret = unzGoToFirstFile(uzf);
+ if (ret != UNZ_OK) {
+ printf("get size : error get first zip file\n");
+ unzClose(uzf);
+ *size = 0;
+ return -1;
+ } else {
+ do {
+ ret = unzOpenCurrentFile(uzf);
+ if (ret != UNZ_OK) {
+ printf("get size : error unzOpenCurrentFile\n");
+ unzClose(uzf);
+ *size = 0;
+ return -1;
+ }
+
+ unz_file_info fileInfo = { 0 };
+ char *filename = (char *)calloc(1, 4096);
+ ret = unzGetCurrentFileInfo(uzf, &fileInfo, filename, (4096 - 1), NULL, 0, NULL, 0);
+ *size = (unsigned long long)fileInfo.uncompressed_size + *size;
+ if (ret != UNZ_OK) {
+ printf("get size : error get current file info\n");
+ unzCloseCurrentFile(uzf);
+ *size = 0;
+ break;
+ }
+
+ free(filename);
+ filename = NULL;
+ } while (unzGoToNextFile(uzf) == UNZ_OK);
}
- g_list_free(dir_list);
}
+ unzClose(uzf);
+
+ return 0;
}
-int app_install()
+static void print_error_code(const char *func_name, int ret)
+{
+ if (ret < 0 || ret > COUNT_OF_ERROR_LIST - 1) {
+ printf("%s failed : unknown error(%d)\n", func_name, ret);
+ } else {
+ printf("%s return(%s)\n", func_name, error_list[ret]);
+ }
+}
+
+static int pre_app_install()
{
- printf("app_install %s\n", TEST_PKGNAME);
GList *dir_list = NULL;
int ret = -1;
+ unsigned long long size_byte = 0;
+ int size_mega = 0;
- //char cmd_install[CMD_LEN+1];
- //snprintf(cmd_install, CMD_LEN,"tpk-backend -y %s", TEST_PKGNAME);
+ printf("pre_app_install for [%s]\n", TEST_PKGNAME_PATH);
dir_list = populate_dir_details();
if (dir_list == NULL) {
- printf("Error in populating the directory list\n");
+ printf("error in populating the directory list\n");
return -1;
}
- ret = handle->interface.pre_install(TEST_PKGNAME, dir_list, 20);
- if (ret) {
- printf("pre_install failed(%s)\n", error_list[ret]);
- clear_dir_list(dir_list);
- return -1;
+
+ /* size : in MB */
+ ret = get_unzip_size(TEST_PKGNAME_PATH, &size_byte);
+ 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);
- /*
- printf("\n cmd_install is %s ", cmd_install);
- ret = system(cmd_install);
- if (ret) {
+ ret = handle->interface.client_pre_install(TEST_PKGNAME,
+ dir_list, size_mega);
+ print_error_code(__func__, ret);
- printf("tpk-backend install command fail %d ", ret);
- ret = handle->interface.post_install(TEST_PKGNAME, 1);
- if (ret) {
- printf("post_install failed(%s)\n", error_list[ret]);
- }
- clear_dir_list(dir_list);
- return -1;
- }
- */
+ clear_dir_list(dir_list);
- ret = handle->interface.post_install(TEST_PKGNAME, 2);
- if (ret) {
- printf("post_install failed(%s)\n", error_list[ret]);
- clear_dir_list(dir_list);
- return -1;
- }
+ return ret;
+}
- ret = handle->interface.enable(TEST_PKGNAME);
- if (ret) {
- printf("enable failed(%s)\n", error_list[ret]);
- clear_dir_list(dir_list);
- return -1;
- }
+static int post_app_install()
+{
+ int ret = -1;
- /*
- printf("\nLaunching application after install");
- ret = aul_open_app(TEST_PKGNAME);
+ ret = handle->interface.client_post_install(TEST_PKGNAME,
+ APP2EXT_STATUS_SUCCESS);
+ print_error_code(__func__, ret);
- if (ret < 0)
- printf("\n launch fail");
- else
- printf("\n application launched");
+ return ret;
+}
- sleep(5);
+static int app_enable()
+{
+ int ret = -1;
- ret = system("killall -9 basicuiapplication");
- if (ret < 0)
- printf("\n app exit fail");
- else
- printf("\n application exited");
+ ret = handle->interface.client_enable(TEST_PKGNAME);
+ print_error_code(__func__, ret);
- sleep(5);
- */
+ return ret;
+}
- ret = handle->interface.disable(TEST_PKGNAME);
- if (ret < 0 || ret > 44) {
- printf("disable failed : unknown error\n");
- } else {
- printf("disable return(%s)\n", error_list[ret]);
- }
+static int app_disable()
+{
+ int ret = -1;
- clear_dir_list(dir_list);
+ ret = handle->interface.client_disable(TEST_PKGNAME);
+ print_error_code(__func__, ret);
return ret;
}
-int app_uninstall()
+static int pre_app_uninstall()
{
- printf("app_uninstall %s\n", TEST_PKGNAME);
int ret = -1;
- //char cmd_uninstall[CMD_LEN+1];
- //snprintf(cmd_uninstall, CMD_LEN, "tpk-backend -y %s", TEST_PKGNAME);
- ret = handle->interface.pre_uninstall(TEST_PKGNAME);
- if (ret) {
- printf("pre_uninstall failed(%s)", error_list[ret]);
- return -1;
- }
+ printf("pre_app_uninstall for [%s]\n", TEST_PKGNAME);
- /*
- printf("\n cmd_uninstall is %s ", cmd_uninstall);
- ret = system(cmd_uninstall);
- if (ret) {
- printf("\nrpm uninstall command fail Reason %s", error_list[ret]);
- return -1;
- }
- */
+ ret = handle->interface.client_pre_uninstall(TEST_PKGNAME);
+ print_error_code(__func__, ret);
- ret = handle->interface.post_uninstall(TEST_PKGNAME);
- if (ret) {
- printf("post app uninstall API fail Reason %s\n", error_list[ret]);
- return -1;
- }
+ return ret;
+}
+
+static int post_app_uninstall()
+{
+ int ret = -1;
+
+ ret = handle->interface.client_post_uninstall(TEST_PKGNAME);
+ print_error_code(__func__, ret);
return ret;
}
-int app_upgrade()
+static int pre_app_upgrade()
{
- printf("app_upgrade %s\n", TEST_PKGNAME);
+ GList *dir_list = NULL;
int ret = -1;
- //char cmd_uninstall[CMD_LEN+1];
- //snprintf(cmd_uninstall, CMD_LEN, "rpm -U %s", TEST_PKGNAME);
+ unsigned long long size_byte = 0;
+ int size_mega = 0;
- GList *dir_list = populate_dir_details();
+ printf("pre_app_upgrade for [%s]\n", TEST_PKGNAME);
+
+ dir_list = populate_dir_details();
if (dir_list == NULL) {
printf("Error in populating the directory list\n");
return -1;
}
- ret = handle->interface.pre_upgrade(TEST_PKGNAME, dir_list, 40);
- if (ret) {
- printf("pre app upgrade API fail. Reason %s\n", error_list[ret]);
- clear_dir_list(dir_list);
- return -1;
+ /* size : in MB */
+ ret = get_unzip_size(TEST_PKGNAME_PATH, &size_byte);
+ 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);
- /*
- printf("\n cmd_uninstall is %s ", cmd_uninstall);
- ret = system(cmd_uninstall);
- if (ret) {
- printf("\nrpm upgrade command fail Reason %s", error_list[ret]);
- ret = handle->interface.post_upgrade(TEST_PKGNAME_RPM, 1);
- if (ret) {
- printf("post app upgrade API fail Reason %s\n", error_list[ret]);
- }
- clear_dir_list(dir_list);
- return -1;
- }
- */
+ ret = handle->interface.client_pre_upgrade(TEST_PKGNAME, dir_list,
+ size_mega);
+ print_error_code(__func__, ret);
- ret = handle->interface.post_upgrade(TEST_PKGNAME, 2);
- if (ret) {
- printf("\n TC : post app upgrade API fail Reason %s", error_list[ret]);
- clear_dir_list(dir_list);
- return -1;
- }
clear_dir_list(dir_list);
+
return ret;
}
-int app_move()
+static int post_app_upgrade()
{
- printf("app_move %s\n", TEST_PKGNAME);
+ int ret = -1;
+
+ ret = handle->interface.client_post_upgrade(TEST_PKGNAME,
+ APP2EXT_STATUS_SUCCESS);
+ print_error_code(__func__, ret);
+
+ return ret;
+}
+
+static int app_move()
+{
+ GList *dir_list = NULL;
int ret = -1;
int ret_check = -1;
- GList *dir_list = populate_dir_details();
+
+ printf("app_move %s\n", TEST_PKGNAME);
+
+ dir_list = populate_dir_details();
if (dir_list == NULL) {
- printf("\nError in populating the directory list\n");
+ printf("Error in populating the directory list\n");
return -1;
}
- ret = app2ext_get_app_location(TEST_PKGNAME);
- printf("return value = (%d)", ret);
+ ret = app2ext_usr_get_app_location(TEST_PKGNAME, getuid());
+ printf("return value = (%d)\n", ret);
if (ret == APP2EXT_SD_CARD) {
- printf("\n app %s is in sd card ", TEST_PKGNAME);
- printf("\n app %s will be moved to internal memory ",
- TEST_PKGNAME);
- ret = handle->interface.move(TEST_PKGNAME, dir_list, APP2EXT_MOVE_TO_PHONE);
- if (ret) {
- printf("\n TC: move API failed Reason %s", error_list[ret]);
- clear_dir_list(dir_list);
- return -1;
- }
- ret = app2ext_get_app_location(TEST_PKGNAME);
+ printf("pkg %s is in sd card\n", TEST_PKGNAME);
+ printf("pkg %s will be moved to internal memory\n", TEST_PKGNAME);
+ ret = handle->interface.client_move(TEST_PKGNAME,
+ dir_list, APP2EXT_MOVE_TO_PHONE);
+ print_error_code(__func__, ret);
+ ret = app2ext_usr_get_app_location(TEST_PKGNAME, getuid());
if (ret_check == APP2EXT_INTERNAL_MEM)
- printf("\n app %s is moved to internal memory ",
- TEST_PKGNAME);
+ printf("pkg %s is moved to internal memory\n", TEST_PKGNAME);
} else if (ret == APP2EXT_INTERNAL_MEM) {
- printf("\n app %s is in internal memory ", TEST_PKGNAME);
- printf("\n app %s will be moved to sd card", TEST_PKGNAME);
-
- ret = handle->interface.move(TEST_PKGNAME, dir_list, APP2EXT_MOVE_TO_EXT);
- if (ret) {
- printf("\n TC: move API failed Reason %s", error_list[ret]);
- clear_dir_list(dir_list);
- return -1;
- }
- ret = app2ext_get_app_location(TEST_PKGNAME);
+ printf("pkg %s is in internal memory\n", TEST_PKGNAME);
+ printf("pkg %s will be moved to sd card\n", TEST_PKGNAME);
+ ret = handle->interface.client_move(TEST_PKGNAME,
+ dir_list, APP2EXT_MOVE_TO_EXT);
+ print_error_code(__func__, ret);
+ ret = app2ext_usr_get_app_location(TEST_PKGNAME, getuid());
if (ret_check == APP2EXT_SD_CARD)
- printf("\n app %s is moved to sd card ",
- TEST_PKGNAME);
+ printf("pkg %s is moved to sd card\n", TEST_PKGNAME);
} else {
ret = APP2EXT_ERROR_INVALID_PACKAGE;
- printf("\n errorReason %s", error_list[ret]);
- clear_dir_list(dir_list);
- return ret;
+ printf("app_move failed (%s)\n", error_list[ret]);
}
+
clear_dir_list(dir_list);
+
return ret;
}
-void app_get_location()
+static void app_get_location()
{
- printf("app_get_location %s \n", TEST_PKGNAME);
+ printf("app_get_location for pkg(%s)\n", TEST_PKGNAME);
int ret = -1;
- ret = app2ext_get_app_location(TEST_PKGNAME);
+ ret = app2ext_usr_get_app_location(TEST_PKGNAME, getuid());
if (ret == APP2EXT_SD_CARD) {
- printf("\n app %s is in sd card ", TEST_PKGNAME);
+ printf("pkg is in sd card\n");
} else if (ret == APP2EXT_INTERNAL_MEM) {
- printf("\n app %s is in internal memory ", TEST_PKGNAME);
+ printf("pkg is in internal memory\n");
} else {
- printf("\napp %s is not installed", TEST_PKGNAME);
- }
-}
-
-void enable_external_dir()
-{
- printf("enable_external_dir\n");
- int ret = -1;
-
- ret = app2ext_enable_external_dir();
- if (ret == 0) {
- printf("\n app2ext_enable_external_dir() success");
- } else {
- printf("\n app2ext_enable_external_dir() failed");
- }
-}
-
-void disable_external_dir()
-{
- printf("disable_external_dir\n");
- int ret = -1;
-
- ret = app2ext_disable_external_dir();
- if (ret == 0) {
- printf("\n app2ext_disable_external_dir() success");
- } else {
- printf("\n app2ext_disable_external_dir() failed");
+ printf("pkg is not installed\n");
}
}
int main(int argc, char **argv)
{
int ret = 0;
-
- /* check authorized user */
+ int opt_idx = 0;
+ int c;
+ uid_t uid = getuid();
+
+ /* check user */
+ if (uid == GLOBAL_USER) {
+ printf("test for global app\n");
+ } else if (uid == OWNER_ROOT) {
+ printf("for root user, a test isn't supproted yet\n");
+ return 0;
+ } else {
+ printf("test for user(%d) app\n", uid);
+ }
handle = app2ext_init(APP2EXT_SD_CARD);
if (handle == NULL) {
return -1;
}
- do {
- usage();
- printf("enter testcase\n");
- int option = __get_integer_input_data();
- switch (option) {
- case 1:
- app_install();
+ /* Parse argv */
+ optind = 1; /* Initialize optind to clear prev. index */
+ while (1) {
+ c = getopt_long(argc, argv, "", long_opts, &opt_idx);
+ if (-1 == c) {
+ usage();
+ break; /* Parse is end */
+ }
+ switch (c) {
+ case OPTVAL_PRE_INSTALL:
+ pre_app_install();
break;
- case 2:
- app_uninstall();
+ case OPTVAL_POST_INSTALL:
+ post_app_install();
break;
- case 3:
- app_upgrade();
+ case OPTVAL_PRE_UNINSTALL:
+ pre_app_uninstall();
break;
- case 4:
+ case OPTVAL_POST_UNINSTALL:
+ post_app_uninstall();
+ break;
+ case OPTVAL_PRE_UPGRADE:
+ pre_app_upgrade();
+ break;
+ case OPTVAL_POST_UPGRADE:
+ post_app_upgrade();
+ break;
+ case OPTVAL_MOVE:
app_move();
break;
- case 5:
+ case OPTVAL_GET_LOCATION:
app_get_location();
break;
- case 6:
- enable_external_dir();
+ case OPTVAL_ENABLE_APP:
+ app_enable();
break;
- case 7:
- disable_external_dir();
+ case OPTVAL_DISABLE_APP:
+ app_disable();
break;
- case 8:
- app2ext_deinit(handle);
- printf("Exit!\n");
- return 0;
+ case OPTVAL_USAGE:
default:
- printf("\nInvalid test id\n");
+ usage();
break;
}
- } while(1);
+
+ break;
+ }
app2ext_deinit(handle);