Fix the problem of not getting the dev_list 28/306328/2 accepted/tizen_7.0_unified tizen_7.0 accepted/tizen/7.0/unified/20240222.070148
authorJiyong <jiyong.min@samsung.com>
Tue, 20 Feb 2024 06:43:42 +0000 (15:43 +0900)
committerJiyong Min <jiyong.min@samsung.com>
Wed, 21 Feb 2024 01:26:01 +0000 (01:26 +0000)
- The format of 'reply_var' is tuple, "(a(issssssisibii))".
  The 'iter' is initialized for tuple by g_variant_iter_init(&iter, reply_var).
  Thus, the 'iter' could not iterate the array.
  So g_variant_get_child_value() is added to get devices(array) from tuple.

Change-Id: Iae074445f4105342ec1b9347e2d4b240cd6b39ab

src/common/media-common-system.c

index 76a88a6ae5eb1aa9d8807ce74c81bf19b9aab584..95d30f85e4592861d63aebfa8b0e7f722d1caa6b 100644 (file)
@@ -166,9 +166,10 @@ void ms_sys_unset_device_block_event_cb(void)
 #ifdef _USE_DEVICED_DBUS
 int ms_sys_get_device_list(GSList **dev_list)
 {
-       GDBusConnection *g_bus = NULL;
-       GError *error = NULL;
-       GVariant *reply_var = NULL;
+       g_autoptr(GDBusConnection) g_bus = NULL;
+       g_autoptr(GError) error = NULL;
+       g_autoptr(GVariant) reply_var = NULL;
+       g_autoptr(GVariant) devices_var = NULL;
        GVariantIter iter;
        GVariant *block_device = NULL;
        int state = 0;
@@ -179,7 +180,6 @@ int ms_sys_get_device_list(GSList **dev_list)
        g_bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
        if (!g_bus) {
                MS_DBG_ERR("Failed to connect to the g D-BUS daemon: %s", error->message);
-               g_error_free(error);
                return MS_MEDIA_ERR_INTERNAL;
        }
 
@@ -190,28 +190,25 @@ int ms_sys_get_device_list(GSList **dev_list)
                                                                                        BLOCK_DEVICE_METHOD,
                                                                                        g_variant_new("(s)", BLOCK_DEVICE_ALL),
                                                                                        NULL,
-                                                                                       G_DBUS_SEND_MESSAGE_FLAGS_NONE,
+                                                                                       G_DBUS_CALL_FLAGS_NONE,
                                                                                        -1,
                                                                                        NULL,
                                                                                        &error);
        if (!reply_var) {
                MS_DBG_ERR("Failed to get GVariant[%s]", error->message);
-               g_error_free(error);
-               g_object_unref(g_bus);
                return MS_MEDIA_ERR_INTERNAL;
        }
 
-       g_variant_iter_init(&iter, reply_var);
+       devices_var = g_variant_get_child_value(reply_var, 0);
+       if (g_variant_iter_init(&iter, devices_var) == 0) {
+               MS_DBG_INFO("There is no external storage mounted..");
+               return MS_MEDIA_ERR_NONE;
+       }
 
        while ((block_device = g_variant_iter_next_value(&iter))) {
-               if (g_variant_n_children(block_device) == 0) {
-                       MS_DBG_INFO("There is no external storage mounted..");
-                       g_variant_unref(block_device);
-                       break;
-               }
-
                g_variant_get_child(block_device, 9, "i", &state);
                if (state == 0) {
+                       MS_DBG_INFO("invalid state");
                        g_variant_unref(block_device);
                        continue;
                }
@@ -229,9 +226,6 @@ int ms_sys_get_device_list(GSList **dev_list)
                g_variant_unref(block_device);
        }
 
-       g_variant_unref(reply_var);
-       g_object_unref(g_bus);
-
        MS_DBG_FLEAVE();
 
        return MS_MEDIA_ERR_NONE;