#include <glib.h>
+#include "package-manager.h"
+
typedef struct comm_client comm_client;
typedef void (*status_cb) (void *cb_data, uid_t target_uid, const char *req_id,
const char *pkg_type, const char *pkgid,
const char *appid, const char *key,
const char *val);
-comm_client *comm_client_new(void);
+comm_client *comm_client_new(client_type type);
int comm_client_free(comm_client *cc);
int comm_client_request(comm_client *cc, const char *method, GVariant *params, GVariant **result);
free(sig_cb_data);
}
+#define REGULAR_USER 5000
+static int _is_system_user(void)
+{
+ uid_t uid = getuid();
+
+ if (uid < REGULAR_USER)
+ return 1;
+ else
+ return 0;
+}
+
+static GBusType _get_bus_type(client_type type)
+{
+ if (type == PC_REQUEST || _is_system_user())
+ return G_BUS_TYPE_SYSTEM;
+ else
+ return G_BUS_TYPE_SESSION;
+}
+
/*******************
* API description
*/
/**
* Create a new comm_client object
*/
-comm_client *comm_client_new(void)
+comm_client *comm_client_new(client_type type)
{
GError *error = NULL;
comm_client *cc = NULL;
}
/* Connect to gdbus. Gets shared BUS */
- cc->conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+ cc->conn = g_bus_get_sync(_get_bus_type(type), NULL, &error);
if (error) {
ERR("gdbus connection error (%s)", error->message);
g_error_free(error);
mpc->status_type = PKGMGR_CLIENT_STATUS_GET_SIZE;
- mpc->info.request.cc = comm_client_new();
+ mpc->info.request.cc = comm_client_new(PC_REQUEST);
retvm_if(mpc->info.request.cc == NULL, PKGMGR_R_ERROR, "client creation failed");
ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_GET_SIZE, mpc->info.request.cc, __operation_callback, pc);
mpc->status_type = PKGMGR_CLIENT_STATUS_ENABLE_APP;
- mpc->info.request.cc = comm_client_new();
+ mpc->info.request.cc = comm_client_new(PC_REQUEST);
retvm_if(mpc->info.request.cc == NULL, PKGMGR_R_ERROR, "client creation failed");
if (is_disable)
pc->tep_path = NULL;
if (pc->ctype == PC_REQUEST) {
- pc->info.request.cc = comm_client_new();
+ pc->info.request.cc = comm_client_new(PC_REQUEST);
trym_if(pc->info.request.cc == NULL, "client creation failed");
ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_ALL, pc->info.request.cc, __operation_callback, pc);
trym_if(ret < 0L, "comm_client_set_status_callback() failed - %d", ret);
} else if (pc->ctype == PC_LISTENING) {
- pc->info.listening.cc = comm_client_new();
+ pc->info.listening.cc = comm_client_new(PC_LISTENING);
trym_if(pc->info.listening.cc == NULL, "client creation failed");
ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_ALL, pc->info.listening.cc, __status_callback, pc);
else
mpc->status_type = PKGMGR_CLIENT_STATUS_DISABLE_APP_SPLASH_SCREEN;
- mpc->info.request.cc = comm_client_new();
+ mpc->info.request.cc = comm_client_new(PC_REQUEST);
if (mpc->info.request.cc == NULL) {
ERR("client creation failed");
return PKGMGR_R_ENOMEM;
mpc->ctype = PC_LISTENING;
mpc->status_type = status_type;
- mpc->info.listening.cc = comm_client_new();
+ mpc->info.listening.cc = comm_client_new(PC_LISTENING);
retvm_if(mpc->info.listening.cc == NULL, PKGMGR_R_EINVAL, "client creation failed");
if ((mpc->status_type & PKGMGR_CLIENT_STATUS_INSTALL) == PKGMGR_CLIENT_STATUS_INSTALL) {