adjust log level
[platform/core/messaging/msg-service.git] / utils / MsgUtilFunction.cpp
index 3bf80da..0174373 100755 (executable)
@@ -30,6 +30,7 @@
 #include <ctype.h>
 #include <aul.h>
 #include <aul_svc.h>
+#include <gio/gio.h>
 
 typedef struct _msg_launch_app_data {
        char *app_id;
@@ -38,6 +39,11 @@ typedef struct _msg_launch_app_data {
 
 #define DEFAULT_MIN_MATCH_DIGIT 8
 
+#define SYSPOPUP_BUS_NAME "org.tizen.DevicePolicyManager"
+#define SYSPOPUP_OBJECT_PATH "/org/tizen/DevicePolicyManager/Syspopup"
+#define SYSPOPUP_INTERFACE "org.tizen.DevicePolicyManager.Syspopup"
+#define SYSPOPUP_METHOD_SHOW "show"
+
 enum _FEATURE_INDEX_E {
        FEATURE_INDEX_SMS = 0,
        FEATURE_INDEX_MMS = 1,
@@ -59,6 +65,8 @@ static int dpm_policy_enable[] = {
 static int phonenumberMinMatchDigit = -1;
 #endif
 
+pthread_mutex_t mx = PTHREAD_MUTEX_INITIALIZER;
+
 /*==================================================================================================
                                      FUNCTION IMPLEMENTATION
 ==================================================================================================*/
@@ -1226,30 +1234,20 @@ gchar * msg_replace_non_ascii_char(const gchar *pszText, gunichar replacementCha
 static int __find_login_user(uid_t *uid)
 {
        uid_t *uids = NULL;
-       char *state = NULL;
 
-       int uids_len = sd_get_uids(&uids);
-       if (uids_len <= 0)
+       int uids_len = sd_get_active_uids(&uids);
+       if (uids == NULL)
                return -1;
 
-       for (int i = 0; i < uids_len; i++) {
-               if (sd_uid_get_state(uids[i], &state) < 0) {
-                       free(uids);
-                       return -1;
-               } else {
-                       if (g_strcmp0(state, "online") == 0) {
-                               *uid = uids[i];
-                               free(uids);
-                               free(state);
-                               return 0;
-                       }
-               }
-
-               free(state);
+       if (uids_len != 1) {
+               free(uids);
+               return -1;
        }
 
+       *uid = uids[0];
+
        free(uids);
-       return -1;
+       return 0;
 }
 
 
@@ -1269,17 +1267,19 @@ uid_t msg_get_login_user()
 
 void* _msg_launch_app(void *data)
 {
+       pthread_mutex_lock(&mx);
        if (data) {
                msg_launch_app_data *ad = (msg_launch_app_data *)data;
                int ret = aul_launch_app_for_uid(ad->app_id, ad->bundle_data, msg_get_login_user());
                if (ret <= 0) {
-                       MSG_DEBUG("aul_launch_app_for_uid() is failed : %d", ret);
+                       MSG_ERR("aul_launch_app_for_uid() is failed : %d", ret);
                }
 
                g_free(ad->app_id);
                bundle_free(ad->bundle_data);
                g_free(ad);
        }
+       pthread_mutex_unlock(&mx);
 
        return NULL;
 }
@@ -1287,12 +1287,17 @@ void* _msg_launch_app(void *data)
 msg_error_t msg_launch_app(const char *app_id, bundle *bundle_data)
 {
        msg_launch_app_data *data = (msg_launch_app_data *)calloc(1, sizeof(msg_launch_app_data));
+       if (data == NULL) {
+               MSG_ERR("Memory alloc failed!");
+               return MSG_ERR_MEMORY_ERROR;
+       }
+
        data->app_id = g_strdup(app_id);
        data->bundle_data = bundle_dup(bundle_data);
        pthread_t thd;
 
        if (pthread_create(&thd, NULL, &_msg_launch_app, data) < 0) {
-               MSG_DEBUG("pthread_create() error");
+               MSG_ERR("pthread_create() error");
        }
 
        pthread_detach(thd);
@@ -1304,7 +1309,7 @@ msg_error_t msg_aul_svc_set_operation(bundle *bundle_data, const char *operation
 {
        int ret = aul_svc_set_operation(bundle_data, operation);
        if (ret < 0) {
-               MSG_DEBUG("aul_svc_set_operation() is failed : %d", ret);
+               MSG_ERR("aul_svc_set_operation() is failed : %d", ret);
                return MSG_ERR_UNKNOWN;
        }
 
@@ -1316,7 +1321,7 @@ msg_error_t msg_aul_svc_set_uri(bundle *bundle_data, char *uri)
 {
        int ret = aul_svc_set_uri(bundle_data, uri);
        if (ret < 0) {
-               MSG_DEBUG("aul_svc_set_uri() is failed : %d", ret);
+               MSG_ERR("aul_svc_set_uri() is failed : %d", ret);
                return MSG_ERR_UNKNOWN;
        }
 
@@ -1336,3 +1341,55 @@ bool msg_check_dpm_policy(int type)
 //     return dpm_policy_enable[type];
 }
 
+
+void msg_syspopup_message(bool is_sending)
+{
+       MSG_INFO("popup toast for dpm restriction. is_sending [%d]", is_sending);
+
+       GDBusConnection *connection = NULL;
+       GDBusProxy *dbus_proxy = NULL;
+       GVariant *result = NULL;
+       GError *error = NULL;
+
+       connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+       if (error) {
+               MSG_ERR("Connecting to system bus failed: %s\n", error->message);
+               goto _DBUS_ERROR;
+       }
+
+       dbus_proxy = g_dbus_proxy_new_sync(connection, G_DBUS_PROXY_FLAGS_NONE, NULL,
+                                                               SYSPOPUP_BUS_NAME, SYSPOPUP_OBJECT_PATH, SYSPOPUP_INTERFACE, NULL, &error);
+       if (error) {
+               MSG_ERR("Connecting to proxy failed: %s\n", error->message);
+               goto _DBUS_ERROR;
+       }
+
+       result = g_dbus_proxy_call_sync(dbus_proxy, SYSPOPUP_METHOD_SHOW,
+                                                       g_variant_new("(s)", is_sending ? "message-sending" : "message-retrieving"),
+                                                       G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+       if (error) {
+               MSG_ERR("invoking proxy call failed: %s\n", error->message);
+               goto _DBUS_ERROR;
+       }
+
+_DBUS_ERROR:
+       if (error) {
+               g_error_free(error);
+               error = NULL;
+       }
+
+       if (connection) {
+               g_object_unref(connection);
+               connection = NULL;
+       }
+
+       if (dbus_proxy) {
+               g_object_unref(dbus_proxy);
+               dbus_proxy = NULL;
+       }
+
+       if (result) {
+               g_object_unref(result);
+               result = NULL;
+       }
+}