4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Junsuk Oh <junsuk77.oh@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.
26 #include <dbus/dbus.h>
27 #include <dbus/dbus-glib-lowlevel.h>
29 #include "pkgmgrinfo_private.h"
30 #include "pkgmgrinfo_debug.h"
31 #include "pkgmgr-info.h"
36 #define LOG_TAG "PKGMGR_CLIENT"
38 #define SERVICE_NAME "org.tizen.system.deviced"
39 #define PATH_NAME "/Org/Tizen/System/DeviceD/Mmc"
40 #define INTERFACE_NAME "org.tizen.system.deviced.Mmc"
41 #define METHOD_NAME "RequestMountApp2ext"
43 static int __get_pkg_location(const char *pkgid)
45 retvm_if(pkgid == NULL, PMINFO_R_OK, "pkginfo handle is NULL");
48 char pkg_mmc_path[FILENAME_MAX] = { 0, };
49 snprintf(pkg_mmc_path, FILENAME_MAX, "%s%s", PKG_SD_PATH, pkgid);
51 /*check whether application is in external memory or not */
52 fp = fopen(pkg_mmc_path, "r");
56 return PMINFO_EXTERNAL_STORAGE;
59 return PMINFO_INTERNAL_STORAGE;
62 /* pkgmgrinfo client start*/
63 API pkgmgrinfo_client *pkgmgrinfo_client_new(pkgmgrinfo_client_type ctype)
68 pkgmgrinfo_client *(*__pkgmgr_client_new)(pkgmgrinfo_client_type ctype) = NULL;
70 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
71 retvm_if(!handle, NULL, "dlopen() failed. [%s]", dlerror());
73 __pkgmgr_client_new = dlsym(handle, "pkgmgr_client_new");
74 retvm_if(__pkgmgr_client_new == NULL, NULL, "__pkgmgr_client_new() failed");
77 retvm_if(errmsg != NULL, NULL, "dlsym() failed. [%s]", errmsg);
79 pc = __pkgmgr_client_new(ctype);
83 return (pkgmgrinfo_client *) pc;
86 API int pkgmgrinfo_client_set_status_type(pkgmgrinfo_client *pc, int status_type)
91 int (*__pkgmgr_client_set_status_type)(pkgmgrinfo_client *pc, int status_type) = NULL;
93 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
94 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
96 __pkgmgr_client_set_status_type = dlsym(handle, "pkgmgr_client_set_status_type");
98 tryvm_if((errmsg != NULL) || (__pkgmgr_client_set_status_type == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
100 ret = __pkgmgr_client_set_status_type(pc, status_type);
101 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
108 API int pkgmgrinfo_client_listen_status(pkgmgrinfo_client *pc, pkgmgrinfo_handler event_cb, void *data)
113 int (*__pkgmgr_client_listen_status)(pkgmgrinfo_client *pc, pkgmgrinfo_handler event_cb, void *data) = NULL;
115 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
116 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
118 __pkgmgr_client_listen_status = dlsym(handle, "pkgmgr_client_listen_status");
120 tryvm_if((errmsg != NULL) || (__pkgmgr_client_listen_status == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
122 ret = __pkgmgr_client_listen_status(pc, event_cb, data);
123 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
130 API int pkgmgrinfo_client_free(pkgmgrinfo_client *pc)
135 int (*__pkgmgr_client_free)(pkgmgrinfo_client *pc) = NULL;
137 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
138 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
140 __pkgmgr_client_free = dlsym(handle, "pkgmgr_client_free");
142 tryvm_if((errmsg != NULL) || (__pkgmgr_client_free == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
144 ret = __pkgmgr_client_free(pc);
145 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
152 API int pkgmgrinfo_client_request_enable_external_pkg(char *pkgid)
156 DBusMessage *message;
159 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
161 if(__get_pkg_location(pkgid) != PMINFO_EXTERNAL_STORAGE)
164 bus = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
165 retvm_if(bus == NULL, PMINFO_R_EINVAL, "dbus_bus_get() failed.");
167 message = dbus_message_new_method_call (SERVICE_NAME, PATH_NAME, INTERFACE_NAME, METHOD_NAME);
168 retvm_if(message == NULL, PMINFO_R_EINVAL, "dbus_message_new_method_call() failed.");
170 dbus_message_append_args(message, DBUS_TYPE_STRING, &pkgid, DBUS_TYPE_INVALID);
172 reply = dbus_connection_send_with_reply_and_block(bus, message, -1, NULL);
173 retvm_if(!reply, ret = PMINFO_R_EINVAL, "connection_send dbus fail");
175 dbus_connection_flush(bus);
176 dbus_message_unref(message);
177 dbus_message_unref(reply);
182 /* pkgmgrinfo client end*/