4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jyotsna Dhumale <jyotsna.a@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
24 #include <sys/types.h>
32 #include "app2ext_interface.h"
33 #include "app2ext_debug.h"
35 #define APP2EXT_SD_PLUGIN_PATH LIBPREFIX "/libapp2sd.so"
36 #define REGULAR_USER 5000
38 app2ext_handle *app2ext_init(int storage_type)
40 void *dl_handle = NULL;
41 int (*dl_on_load)(app2ext_interface *) = NULL;
43 /* validate the function parameter recieved */
44 if (storage_type < APP2EXT_INTERNAL_MEM ||
45 storage_type > APP2EXT_CLOUD) {
46 _E("invalid function arguments");
49 if (storage_type != APP2EXT_SD_CARD) {
50 _E("storage type currently not supported");
54 /* allocate memory for app2ext handle*/
55 app2ext_handle *handle = (app2ext_handle *)calloc(1, sizeof(app2ext_handle));
57 _E("memory allocation failed");
62 handle->type = APP2EXT_SD_CARD;
63 dl_handle = dlopen(APP2EXT_SD_PLUGIN_PATH, RTLD_LAZY|RTLD_GLOBAL);
64 if (NULL == dl_handle) {
65 _E("dlopen(%s) failed", APP2EXT_SD_PLUGIN_PATH);
70 handle->plugin_handle = dl_handle;
71 dl_on_load = dlsym(dl_handle, "app2ext_on_load");
72 if (NULL == dl_on_load) {
73 _E("cannot find app2ext_on_load symbol in (%s)", APP2EXT_SD_PLUGIN_PATH);
79 /* initialize the SD plugin*/
80 if (!dl_on_load(&(handle->interface))) {
81 _E("app2ext_on_load() failed in (%s)", APP2EXT_SD_PLUGIN_PATH);
87 _D("plugin(%s) loaded", APP2EXT_SD_PLUGIN_PATH);
92 int app2ext_deinit(app2ext_handle *handle)
94 /* validate the function parameter recieved */
95 if (handle == NULL || handle->plugin_handle == NULL) {
96 _E("invalid function arguments");
100 /* close the plugin handle*/
101 dlclose(handle->plugin_handle);
103 /* free allocated memory during installation*/
109 int app2ext_usr_enable_external_pkg(const char *pkgid, uid_t uid)
111 app2ext_handle *handle = NULL;
113 /* validate the function parameter received */
115 _E("invalid func parameters");
119 handle = app2ext_init(APP2EXT_SD_CARD);
120 if (handle == NULL) {
121 _E("app2ext init failed");
125 handle->interface.client_usr_enable(pkgid, uid);
126 app2ext_deinit(handle);
131 int app2ext_enable_external_pkg(const char *pkgid)
135 ret = app2ext_usr_enable_external_pkg(pkgid, getuid());
140 int app2ext_usr_disable_external_pkg(const char *pkgid, uid_t uid)
142 app2ext_handle *handle = NULL;
144 /* validate the function parameter received */
146 _E("invalid func parameters");
150 handle = app2ext_init(APP2EXT_SD_CARD);
151 if (handle == NULL) {
152 _E("app2ext init failed");
155 handle->interface.client_usr_disable(pkgid, uid);
156 app2ext_deinit(handle);
161 int app2ext_disable_external_pkg(const char *pkgid)
165 ret = app2ext_usr_disable_external_pkg(pkgid, getuid());
170 int app2ext_enable_all_external_pkgs(void)
173 app2ext_handle *handle = NULL;
175 if (getuid() >= REGULAR_USER)
178 handle = app2ext_init(APP2EXT_SD_CARD);
179 if (handle == NULL) {
180 _E("app2ext init failed");
184 ret = handle->interface.client_enable_full_pkg();
186 _E("failed to enable entire pkgs");
188 app2ext_deinit(handle);
193 int app2ext_disable_all_external_pkgs(void)
196 app2ext_handle *handle = NULL;
198 if (getuid() >= REGULAR_USER)
201 handle = app2ext_init(APP2EXT_SD_CARD);
202 if (handle == NULL) {
203 _E("app2ext init failed");
207 ret = handle->interface.client_disable_full_pkg();
209 _E("failed to disable entire pkgs");
211 app2ext_deinit(handle);
216 int app2ext_usr_force_clean_pkg(const char *pkgid, uid_t uid)
218 app2ext_handle *handle = NULL;
220 /* validate the function parameter received */
222 _E("invalid func parameters");
226 handle = app2ext_init(APP2EXT_SD_CARD);
227 if (handle == NULL) {
228 _E("app2ext init failed");
232 handle->interface.client_usr_force_clean(pkgid, uid);
233 app2ext_deinit(handle);
238 int app2ext_force_clean_pkg(const char *pkgid)
242 ret = app2ext_usr_force_clean_pkg(pkgid, getuid());
247 int app2ext_migrate_legacy_all(void)
249 app2ext_handle *handle = NULL;
251 handle = app2ext_init(APP2EXT_SD_CARD);
252 if (handle == NULL) {
253 _E("app2ext init failed");
257 handle->interface.client_migrate_legacy_all();
258 app2ext_deinit(handle);
263 char *app2ext_usr_getname_image(const char *pkgid, uid_t uid)
265 app2ext_handle *handle = NULL;
266 char *image_name = NULL;
268 /* validate the function parameter received */
270 _E("invalid func parameters");
274 handle = app2ext_init(APP2EXT_SD_CARD);
275 if (handle == NULL) {
276 _E("app2ext init failed");
280 image_name = handle->interface.client_usr_getname_image(pkgid, uid);
281 app2ext_deinit(handle);
286 char *app2ext_usr_get_image_path(const char *pkgid, uid_t uid)
288 app2ext_handle *handle;
291 /* validate the function parameter received */
293 _E("invalid func parameters");
297 handle = app2ext_init(APP2EXT_SD_CARD);
298 if (handle == NULL) {
299 _E("app2ext init failed");
303 image_path = handle->interface.client_usr_get_image_path(pkgid, uid);
304 app2ext_deinit(handle);