/* * deviced * * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. * * 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 #include #include #include "include/ss_data.h" #include "core/list.h" #include "ss_log.h" #define APP2EXT_PLUGIN_PATH LIBDIR"/libapp2ext.so.0" static void *app2ext_dl; static int (*app2ext_enable)(const char *pkgid); static int (*app2ext_disable)(const char *pkgid); static dd_list *pkgid_head; static int app2ext_mount(const char *pkgid) { int r; if (!app2ext_enable) return -ENOENT; PRT_TRACE_ERR("Attempt mount %s app to sdcard", pkgid); r = app2ext_enable(pkgid); if (r < 0) return r; PRT_TRACE_ERR("Mount %s app to sdcard", pkgid); DD_LIST_APPEND(pkgid_head, strdup(pkgid)); return 0; } int app2ext_unmount(void) { char *str; dd_list *elem; int r, n, i; if (!app2ext_disable) return -ENOENT; /* if there is no mounted pkg */ if (!pkgid_head) return 0; n = DD_LIST_LENGTH(pkgid_head); PRT_TRACE_ERR("pkgid_head count : %d", n); for (i = 0; i < n; ++i) { str = DD_LIST_NTH(pkgid_head, 0); PRT_TRACE_ERR("Attempt unmount %s app from sdcard", str); r = app2ext_disable(str); if (r < 0) return r; PRT_TRACE_ERR("Unmount %s app from sdcard", str); DD_LIST_REMOVE(pkgid_head, str); free(str); } return 0; } static int mmc_mount_app2ext(int argc, char **argv) { char *pkgid; if (argc < 1) return -EINVAL; if (!mmc_check_mounted(MMC_MOUNT_POINT)) { PRT_TRACE_ERR("Do not mounted"); return -ENODEV; } pkgid = argv[0]; return app2ext_mount(pkgid); } void app2ext_init(void) { int ret; app2ext_dl = dlopen(APP2EXT_PLUGIN_PATH, RTLD_LAZY|RTLD_GLOBAL); if (!app2ext_dl) { PRT_TRACE_ERR("dlopen error (%s)", dlerror()); return; } app2ext_enable = dlsym(app2ext_dl, "app2ext_enable_external_pkg"); if (!app2ext_enable) { PRT_TRACE_ERR("dlsym error (%s)", dlerror()); dlclose(app2ext_dl); app2ext_dl = NULL; return; } app2ext_disable = dlsym(app2ext_dl, "app2ext_disable_external_pkg"); if (!app2ext_disable) { PRT_TRACE_ERR("dlsym error (%s)", dlerror()); dlclose(app2ext_dl); app2ext_dl = NULL; return; } ss_action_entry_add_internal(PREDEF_MOUNT_APP2EXT, mmc_mount_app2ext, NULL, NULL); } void app2ext_exit(void) { if(!app2ext_dl) return; dlclose(app2ext_dl); app2ext_dl = NULL; }