fixup! Move volume vconf set to pulseaudio 21/142221/3 accepted/tizen/4.0/unified/20170816.011816 accepted/tizen/unified/20170804.025631 submit/tizen/20170803.072523 submit/tizen_4.0/20170811.094300
authorSeungbae Shin <seungbae.shin@samsung.com>
Thu, 3 Aug 2017 05:54:43 +0000 (14:54 +0900)
committerSeungbae Shin <seungbae.shin@samsung.com>
Thu, 3 Aug 2017 06:42:18 +0000 (15:42 +0900)
- Fix for returning permission error properly if set_volume without privilege
- Revise codes based on coding rule

[Version] 0.11.15
[Profile] Common
[Issue Type] Bug

Change-Id: I37a8171de8382aa011659d8fd2ac3212d3becd0e

common/mm_sound_dbus.c
mm_sound.c
mm_sound_client.c
packaging/libmm-sound.spec

index 8687db4..17799fa 100644 (file)
@@ -8,11 +8,6 @@
 #include "../include/mm_sound_dbus.h"
 #include "../include/mm_sound_intf.h"
 
-#define INTERFACE_DBUS                 "org.freedesktop.DBus.Properties"
-#define SIGNAL_PROP_CHANGED             "PropertiesChanged"
-#define METHOD_GET                     "Get"
-#define METHOD_SET                     "Set"
-
 struct callback_data {
        mm_sound_dbus_callback user_cb;
        void *user_data;
@@ -189,6 +184,7 @@ static const GDBusErrorEntry mm_sound_error_entries[] =
        {MM_ERROR_SOUND_FILE_NOT_FOUND, "org.tizen.multimedia.audio.FileNotFound"},
        {MM_ERROR_SOUND_NO_DATA, "org.tizen.multimedia.audio.NoData"},
        {MM_ERROR_SOUND_INVALID_PATH, "org.tizen.multimedia.audio.InvalidPath"},
+       {MM_ERROR_SOUND_PERMISSION_DENIED, "org.freedesktop.DBus.Error.AccessDenied"},
 };
 
 
@@ -223,6 +219,8 @@ static int _convert_error_name(const char *err_name)
 {
        int i = 0;
 
+       debug_error("error name is [%s]", err_name);
+
        for (i = 0; i < G_N_ELEMENTS(mm_sound_error_entries); i++) {
                if (!strcmp(mm_sound_error_entries[i].dbus_error_name, err_name)) {
                        return mm_sound_error_entries[i].error_code;
@@ -232,12 +230,12 @@ static int _convert_error_name(const char *err_name)
        return MM_ERROR_COMMON_UNKNOWN;
 }
 
-static int _dbus_method_call(GDBusConnection* conn, const char* bus_name, const char* object, const char* intf,
-                                                       const char* method, GVariant* args, GVariant** result)
+static int _dbus_method_call(GDBusConnection *conn, const char *bus_name, const char *object, const char *intf,
+                                                       const char *method, GVariant *args, GVariant **result)
 {
        int ret = MM_ERROR_NONE;
        GError *err = NULL;
-       GVariantdbus_reply = NULL;
+       GVariant *dbus_reply = NULL;
 
        if (!conn || !object || !intf || !method) {
                debug_error("Invalid Argument");
@@ -255,14 +253,14 @@ static int _dbus_method_call(GDBusConnection* conn, const char* bus_name, const
        debug_log("Dbus call with obj'%s' intf'%s' method'%s'", object, intf, method);
 
        dbus_reply = g_dbus_connection_call_sync(conn, bus_name, object , intf,
-                            method, args ,
-                            NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err );
+                                                                                       method, args ,
+                                                                                       NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
 
        if (!dbus_reply) {
                char *err_name = NULL, *err_msg = NULL;
                debug_error("Method Call '%s.%s' Failed, %s", intf, method, err->message);
 
-               if (_parse_error_msg(err->message,  &err_name, &err_msg) < 0) {
+               if (_parse_error_msg(err->message, &err_name, &err_msg) < 0) {
                        debug_error("failed to parse error message");
                        g_error_free(err);
                        return MM_ERROR_SOUND_INTERNAL;
@@ -278,51 +276,9 @@ static int _dbus_method_call(GDBusConnection* conn, const char* bus_name, const
        return ret;
 }
 
-#if 0
-static int _dbus_set_property(GDBusConnection* conn, const char* bus_name, const char* object, const char* intf,
-                                                       const char* prop, GVariant* args, GVariant** result)
-{
-       int ret = MM_ERROR_NONE;
-
-       if (!conn || !object || !intf || !prop) {
-               debug_error("Invalid Argument");
-               return MM_ERROR_INVALID_ARGUMENT;
-       }
-
-       debug_log("Dbus set property with obj'%s' intf'%s' prop'%s'", object, intf, prop);
-
-       if ((ret = _dbus_method_call(conn, bus_name, object, INTERFACE_DBUS, METHOD_SET,
-                                                               g_variant_new("(ssv)", intf, prop, args), result)) != MM_ERROR_NONE) {
-               debug_error("Dbus call for set property failed");
-       }
-
-       return ret;
-}
-
-static int _dbus_get_property(GDBusConnection *conn, const char* bus_name, const char* object_name,
-                                                       const char* intf_name, const char* prop, GVariant** result)
-{
-       int ret = MM_ERROR_NONE;
-
-       if (!conn || !object_name || !intf_name || !prop) {
-               debug_error("Invalid Argument");
-               return MM_ERROR_INVALID_ARGUMENT;
-       }
-
-       debug_log("Dbus get property with obj'%s' intf'%s' prop'%s'", object_name, intf_name, prop);
-
-       if ((ret = _dbus_method_call(conn,
-                                      bus_name, object_name, INTERFACE_DBUS, METHOD_GET,
-                                      g_variant_new("(ss)", intf_name, prop), result)) != MM_ERROR_NONE) {
-               debug_error("Dbus call for get property failed");
-       }
-
-       return ret;
-}
-#endif
-
-static int _dbus_subscribe_signal(GDBusConnection *conn, const char* object_name, const char* intf_name,
-                                       const char* signal_name, GDBusSignalCallback signal_cb, guint *subscribe_id, void* userdata, GDestroyNotify freefunc)
+static int _dbus_subscribe_signal(GDBusConnection *conn, const char *object_name, const char *intf_name,
+                                                               const char *signal_name, GDBusSignalCallback signal_cb, guint *subscribe_id,
+                                                               void *userdata, GDestroyNotify freefunc)
 {
        guint subs_id = 0;
 
@@ -337,7 +293,7 @@ static int _dbus_subscribe_signal(GDBusConnection *conn, const char* object_name
                                                                                                NULL, G_DBUS_SIGNAL_FLAGS_NONE , signal_cb, userdata, freefunc);
 
        if (!subs_id) {
-               debug_error ("g_dbus_connection_signal_subscribe() failed ");
+               debug_error("g_dbus_connection_signal_subscribe() failed ");
                return MM_ERROR_SOUND_INTERNAL;
        }
        if (subscribe_id)
@@ -356,7 +312,7 @@ static void _dbus_unsubscribe_signal(GDBusConnection *conn, guint subs_id)
        g_dbus_connection_signal_unsubscribe(conn, subs_id);
 }
 
-static GDBusConnection* _dbus_get_connection(GBusType bustype)
+static GDBusConnection * _dbus_get_connection(GBusType bustype)
 {
        static GDBusConnection *conn_system = NULL;
        static GDBusConnection *conn_session = NULL;
@@ -368,7 +324,7 @@ static GDBusConnection* _dbus_get_connection(GBusType bustype)
                } else {
                        debug_log("Get new connection on system bus");
                        if (!(conn_system = g_bus_get_sync(bustype, NULL, &err))) {
-                               debug_error ("g_dbus_get_sync() error (%s)", err->message);
+                               debug_error("g_dbus_get_sync() error (%s)", err->message);
                                g_error_free(err);
                        }
                }
@@ -379,7 +335,7 @@ static GDBusConnection* _dbus_get_connection(GBusType bustype)
                } else {
                        debug_log("Get new connection on session bus");
                        if (!(conn_session = g_bus_get_sync(bustype, NULL, &err))) {
-                               debug_error ("g_dbus_get_sync() error (%s)", err->message);
+                               debug_error("g_dbus_get_sync() error (%s)", err->message);
                                g_error_free(err);
                        }
                }
@@ -391,15 +347,6 @@ static GDBusConnection* _dbus_get_connection(GBusType bustype)
 
 }
 
-#if 0
-static void _dbus_disconnect(GDBusConnection* conn)
-{
-       debug_fenter ();
-       g_object_unref(conn);
-       debug_fleave ();
-}
-#endif
-
 /******************************************************************************************
                Simple Functions For Communicate with Sound-Server
 ******************************************************************************************/
@@ -410,11 +357,11 @@ int mm_sound_dbus_method_call_to(audio_provider_t provider, audio_method_t metho
        int ret = MM_ERROR_NONE;
        GDBusConnection *conn = NULL;
 
-       if (method_type < 0 || method_type >= AUDIO_METHOD_MAX) {
+       if (method_type >= AUDIO_METHOD_MAX) {
                debug_error("Invalid method type : %d", method_type);
                return MM_ERROR_INVALID_ARGUMENT;
        }
-       if (provider < 0 || provider >= AUDIO_PROVIDER_MAX) {
+       if (provider >= AUDIO_PROVIDER_MAX) {
                debug_error("Invalid provider : %d", provider);
                return MM_ERROR_INVALID_ARGUMENT;
        }
@@ -425,10 +372,10 @@ int mm_sound_dbus_method_call_to(audio_provider_t provider, audio_method_t metho
        }
 
        if ((ret = _dbus_method_call(conn, g_paths[provider].bus_name,
-                                     g_paths[provider].object,
-                                     g_paths[provider].interface,
-                                     g_methods[method_type].name,
-                                     args, result)) != MM_ERROR_NONE) {
+                                                               g_paths[provider].object,
+                                                               g_paths[provider].interface,
+                                                               g_methods[method_type].name,
+                                                               args, result)) != MM_ERROR_NONE) {
                debug_error("Dbus Call on Client Error");
        }
 
@@ -436,17 +383,17 @@ int mm_sound_dbus_method_call_to(audio_provider_t provider, audio_method_t metho
 }
 
 /* This callback only transform signal-callback to dbus non-related form (mm_sound_dbus_callback) */
-static void _dbus_signal_callback(GDBusConnection  *connection,
-                                     const gchar      *sender_name,
-                                     const gchar      *object_path,
-                                     const gchar      *interface_name,
-                                     const gchar      *signal_name,
-                                     GVariant         *params,
-                                     gpointer          userdata)
+static void _dbus_signal_callback(GDBusConnection *connection,
+                                                               const gchar *sender_name,
+                                                               const gchar *object_path,
+                                                               const gchar *interface_name,
+                                                               const gchar *signal_name,
+                                                               GVariant *params,
+                                                               gpointer userdata)
 {
-       struct callback_data *cb_data = (struct callback_data*) userdata;
+       struct callback_data *cb_data = (struct callback_data *)userdata;
 
-       debug_log("Signal(%s.%s) Received , Let's call Wrapper-Callback", interface_name, signal_name);
+       debug_log("Signal(%s.%s) Received, Let's call Wrapper-Callback", interface_name, signal_name);
 
        if (!strcmp(signal_name, g_events[AUDIO_EVENT_VOLUME_CHANGED].name)) {
                (cb_data->user_cb)(AUDIO_EVENT_VOLUME_CHANGED, params, cb_data->user_data);
@@ -469,7 +416,7 @@ static void _dbus_signal_callback(GDBusConnection  *connection,
 
 static void callback_data_free_func(gpointer data)
 {
-       struct callback_data *cb_data = (struct callback_data *) data;
+       struct callback_data *cb_data = (struct callback_data *)data;
 
        if (cb_data->free_func)
                cb_data->free_func(cb_data->user_data);
@@ -477,7 +424,8 @@ static void callback_data_free_func(gpointer data)
 }
 
 EXPORT_API
-int mm_sound_dbus_signal_subscribe_to(audio_provider_t provider, audio_event_t event, mm_sound_dbus_callback callback, void *userdata, mm_sound_dbus_userdata_free freefunc, unsigned *subs_id)
+int mm_sound_dbus_signal_subscribe_to(audio_provider_t provider, audio_event_t event, mm_sound_dbus_callback callback,
+                                                                       void *userdata, mm_sound_dbus_userdata_free freefunc, unsigned *subs_id)
 {
        GDBusConnection *conn = NULL;
        guint _subs_id = 0;
@@ -488,12 +436,12 @@ int mm_sound_dbus_signal_subscribe_to(audio_provider_t provider, audio_event_t e
                return MM_ERROR_INVALID_ARGUMENT;
        }
 
-       if (event < 0 || event >= AUDIO_EVENT_MAX) {
+       if (event >= AUDIO_EVENT_MAX) {
                debug_error("Wrong event Type : %d", event);
                return MM_ERROR_INVALID_ARGUMENT;
        }
 
-       if (provider < 0 || provider >= AUDIO_PROVIDER_MAX) {
+       if (provider >= AUDIO_PROVIDER_MAX) {
                debug_error("Invalid provider : %d", provider);
                return MM_ERROR_INVALID_ARGUMENT;
        }
@@ -503,7 +451,7 @@ int mm_sound_dbus_signal_subscribe_to(audio_provider_t provider, audio_event_t e
                return MM_ERROR_SOUND_INTERNAL;
        }
 
-       if (!(cb_data = (struct callback_data*) g_malloc0(sizeof(struct callback_data)))) {
+       if (!(cb_data = (struct callback_data*)g_malloc0(sizeof(struct callback_data)))) {
                debug_error("Allocate for callback data failed");
                return MM_ERROR_SOUND_INTERNAL;
        }
@@ -537,7 +485,7 @@ int mm_sound_dbus_signal_unsubscribe(unsigned int subs_id)
                return MM_ERROR_SOUND_INTERNAL;
        }
 
-       _dbus_unsubscribe_signal(conn, (guint) subs_id);
+       _dbus_unsubscribe_signal(conn, (guint)subs_id);
 
        return MM_ERROR_NONE;
 }
@@ -549,8 +497,8 @@ int mm_sound_dbus_emit_signal(audio_provider_t provider, audio_event_t event, GV
        GError *err = NULL;
        gboolean dbus_ret;
 
-       if (event < 0 || event >= AUDIO_EVENT_MAX) {
-               debug_error ("emit signal failed, invalid argument, event_type(%d)", event);
+       if (event >= AUDIO_EVENT_MAX) {
+               debug_error("emit signal failed, invalid argument, event_type(%d)", event);
                return MM_ERROR_INVALID_ARGUMENT;
        }
 
@@ -559,18 +507,18 @@ int mm_sound_dbus_emit_signal(audio_provider_t provider, audio_event_t event, GV
                return MM_ERROR_SOUND_INTERNAL;
        }
 
-       dbus_ret = g_dbus_connection_emit_signal (conn,
-                                                 NULL, g_paths[provider].object,
-                                                 g_paths[provider].interface, g_events[event].name,
-                                                 param, &err);
+       dbus_ret = g_dbus_connection_emit_signal(conn,
+                                                                                       NULL, g_paths[provider].object,
+                                                                                       g_paths[provider].interface, g_events[event].name,
+                                                                                       param, &err);
        if (!dbus_ret) {
-               debug_error ("g_dbus_connection_emit_signal() error (%s)", err->message);
+               debug_error("g_dbus_connection_emit_signal() error (%s)", err->message);
                g_error_free(err);
                return MM_ERROR_SOUND_INTERNAL;
        }
        g_dbus_connection_flush_sync(conn, NULL, NULL);
 
-       debug_msg ("emit signal for [%s]  success", g_events[event].name);
+       debug_msg("emit signal for [%s] success", g_events[event].name);
        return MM_ERROR_NONE;
 }
 
@@ -581,7 +529,7 @@ int mm_sound_dbus_get_event_name(audio_event_t event, const char **event_name)
                debug_error("Invalid Parameter, event_name NULL");
                return MM_ERROR_INVALID_ARGUMENT;
        }
-       if (event < 0 || event >= AUDIO_EVENT_MAX) {
+       if (event >= AUDIO_EVENT_MAX) {
                debug_error("invalid event : %d", event);
                return MM_ERROR_INVALID_ARGUMENT;
        }
@@ -597,7 +545,7 @@ int mm_sound_dbus_get_method_name(audio_method_t method, const char **method_nam
                debug_error("Invalid Parameter, method_name NULL");
                return MM_ERROR_INVALID_ARGUMENT;
        }
-       if (method < 0 || method >= AUDIO_METHOD_MAX) {
+       if (method >= AUDIO_METHOD_MAX) {
                debug_error("invalid method : %d", method);
                return MM_ERROR_INVALID_ARGUMENT;
        }
index b29da0f..5c7953f 100644 (file)
@@ -414,7 +414,7 @@ int mm_sound_play_tone_ex (MMSoundTone_t num, int volume_config, const double vo
                debug_error("number is invalid %d", duration);
                return MM_ERROR_INVALID_ARGUMENT;
        }
-       if (num < MM_SOUND_TONE_DTMF_0 || num >= MM_SOUND_TONE_NUM) {
+       if (num >= MM_SOUND_TONE_NUM) {
                debug_error("TONE Value is invalid %d", num);
                return MM_ERROR_INVALID_ARGUMENT;
        }
@@ -614,7 +614,7 @@ int mm_sound_subscribe_signal(mm_sound_signal_name_t signal_type, unsigned int *
 
        MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_subscribe_cb_list_mutex, MM_ERROR_SOUND_INTERNAL);
 
-       if (signal_type < 0 || signal_type >= MM_SOUND_SIGNAL_MAX || !subscribe_id) {
+       if (signal_type >= MM_SOUND_SIGNAL_MAX || !subscribe_id) {
                debug_error ("invalid argument, signal(%d), subscribe_id(%p)", signal_type, subscribe_id);
                ret = MM_ERROR_INVALID_ARGUMENT;
                goto error;
@@ -679,7 +679,7 @@ int mm_sound_subscribe_signal_for_daemon(mm_sound_signal_name_t signal_type, int
 
        MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_subscribe_cb_list_mutex, MM_ERROR_SOUND_INTERNAL);
 
-       if (signal_type < 0 || signal_type >= MM_SOUND_SIGNAL_MAX || !client_pid || !subscribe_id) {
+       if (signal_type >= MM_SOUND_SIGNAL_MAX || !client_pid || !subscribe_id) {
                debug_error ("invalid argument, signal(%d), client_pid(%d), subscribe_id(%p)", signal_type, client_pid, subscribe_id);
                ret = MM_ERROR_INVALID_ARGUMENT;
                goto error;
@@ -760,7 +760,7 @@ int mm_sound_send_signal(mm_sound_signal_name_t signal_type, int value)
 
        MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_subscribe_cb_list_mutex, MM_ERROR_SOUND_INTERNAL);
 
-       if (signal_type < 0 || signal_type >= MM_SOUND_SIGNAL_MAX) {
+       if (signal_type >= MM_SOUND_SIGNAL_MAX) {
                debug_error ("invalid argument, signal(%d)", signal_type);
                ret = MM_ERROR_INVALID_ARGUMENT;
                goto error;
index 433f780..0c626ac 100644 (file)
@@ -2255,7 +2255,7 @@ int mm_sound_client_execute_focus_func_in_main_context(focus_idle_event_type_e t
 {
        focus_idle_event_t *idle_event_data = NULL;
 
-       if (IDLE_EVENT_TYPE_UNSET_FOCUS_WATCH_CB > type || IDLE_EVENT_TYPE_MAX < type)
+       if (IDLE_EVENT_TYPE_MAX < type)
                return MM_ERROR_INVALID_ARGUMENT;
 
        MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_event_mutex, MM_ERROR_SOUND_INTERNAL);
index ed9cb81..8442393 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-sound
 Summary:    MMSound Package contains client lib and sound_server binary
-Version:    0.11.14
+Version:    0.11.15
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0