Wait up to 2 seconds for get_device operation while preparing MTP device 53/316153/2 accepted/tizen_9.0_unified accepted/tizen/9.0/unified/20241212.022108
authorJihoon Jung <jh8801.jung@samsung.com>
Wed, 11 Dec 2024 02:13:05 +0000 (11:13 +0900)
committerJihoon Jung <jh8801.jung@samsung.com>
Wed, 11 Dec 2024 03:41:08 +0000 (12:41 +0900)
Change-Id: I7caf2791f4f570e4d5bf8f28c7abc86eadce8990
Signed-off-by: Jihoon Jung <jh8801.jung@samsung.com>
src/daemon/include/mtp_daemon.h
src/daemon/mtp_daemon.c
src/daemon/mtp_daemon_event.c
src/daemon/mtp_daemon_gdbus_manager.c

index dc7f0376763bbb3ac55d1900888eed66ca1a7ca5..ac14b852e4e60abb9317962aea93f760d4d31198 100644 (file)
@@ -164,6 +164,7 @@ struct _mtp_context {
        GThread *usb_event_thread;
 
        gint quit_timer;
+       bool is_device_preparing;
 };
 
 struct _mtp_queue_data {
index 8c2253810b8bd0936e81ea873fdbbec8e08c7cdb..4c620444646f6ef494e1b90033ce8a331d8b255a 100644 (file)
@@ -184,6 +184,7 @@ int main(int argc, char *argv[])
        mtp_ctx->device_list->device_num = 0;
        mtp_ctx->is_processing = false;
        mtp_ctx->is_releasing = false;
+       mtp_ctx->is_device_preparing = false;
 
        _mtp_ctx = mtp_ctx;
 
index 65cc9b5913e52ee635a96fb0fb97179b43902947..2d086f3abc7a6d901eda6771fa8557fe1559ecd4 100644 (file)
@@ -112,6 +112,8 @@ int __usb_host_status_changed_cb(struct libusb_context *ctx,
        if (event == LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED) {
                MTP_LOGI("USB device added");
 
+               mtp_ctx->is_device_preparing = true;
+
                LIBMTP_Detect_Raw_Devices(&raw_devices, &num_of_devices);
                MTP_LOGI("LIBMTP_Detect_Raw_Devices completed : %d", num_of_devices);
                for (slot = 0; slot < num_of_devices; slot++) {
@@ -153,11 +155,14 @@ int __usb_host_status_changed_cb(struct libusb_context *ctx,
                                g_thread_pool_push(mtp_ctx->device_list->threads, (gpointer)device, NULL);
                                g_source_remove(mtp_ctx->quit_timer);
 
-                               MTP_LOGI("MTP device added");
+                               MTP_LOGI("MTP device added : %s", device_info->model_name);
                                mtp_daemon_gdbus_emit_event(MTP_INITIATOR_EVENT_DEVICE_ADDED, empty_slot, mtp_ctx);
                                __print_device_list(mtp_ctx);
                        }
                }
+
+               mtp_ctx->is_device_preparing = false;
+
                g_free(raw_devices);
        } else if (event == LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT) {
                MTP_LOGI("device removed");
index 2d958998eef5bca379a42c1ebf75fec4cc14ac23..9ff2d5d75cb3f3479deba465a632fe758979e0ca 100644 (file)
@@ -37,6 +37,7 @@ static void __manager_get_devices_thread_func(gpointer user_data)
 {
        /* variable definition */
        int count = 0;
+       int pending_count = 0;
        mtp_param *param = (mtp_param *)user_data;
        mtp_error_e result = MTP_ERROR_NONE;
        mtpgdbuslibManager *object;
@@ -57,6 +58,11 @@ static void __manager_get_devices_thread_func(gpointer user_data)
        /* do process */
        g_variant_builder_init(&b, G_VARIANT_TYPE("aa{sv}"));
 
+       while (param->mtp_ctx->is_device_preparing && pending_count < 10) {
+               MTP_LOGI("The device is being prepared... wait for 2 seconds (%d/10)", ++pending_count);
+               usleep(200000);
+       }
+
        count = param->mtp_ctx->device_list->device_num;
 
        for (slot = 1; slot < MTP_MAX_SLOT; slot++) {