From 5031d711a29e41ce22ceafbe6bea21a81b9c1371 Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Fri, 10 Jan 2020 14:00:10 +0900 Subject: [PATCH] Enable usb_mode udev event for factory mode. Factory jig internally disconnects only signal cable(in Blue and White) of USB cable. It makes a strange state. In general, when the USB cable is disconnected, switch udev event and usb_mode udev event occur. But, in factory jig case, usb_mode udev event only occurs. Without luck, data-router.service crashs on factory jig because of one's own problems. So, we have to restart data-router.service when usb_mode udev event happens. And, sdbd.service and mtp-response.service also restart as a preventive measure. Change-Id: Ia538383aefd82bad9eaf976fc4dedef605c60026 --- src/usb/usb.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/usb/usb.c b/src/usb/usb.c index 65a33d0..367aa21 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -21,9 +21,11 @@ #include #include #include +#include #include "core/log.h" #include "core/list.h" +#include "core/udev.h" #include "core/common.h" #include "core/device-notifier.h" #include "display/poll.h" @@ -397,6 +399,34 @@ static int usb_state_changed(int status) return ret; } +static void uevent_usb_mode_handler(struct udev_device *dev) +{ + const char *state = NULL; + + state = udev_device_get_property_value(dev, "USB_STATE"); + if (!state) + return; + + if (strncmp(state, "CONFIGURED", strlen(state) + 1)) + return; + + _I("usb_mode udev event happend : CONFIGURED"); + + if (usb_state_get_selected_mode() | USB_FUNCTION_ACM) + systemd_start_unit_wait_started ("data-router.service", NULL, -1); + + if (usb_state_get_selected_mode() | USB_FUNCTION_SDB) + systemd_start_unit_wait_started ("sdbd.service", NULL, -1); + + if (usb_state_get_selected_mode() | USB_FUNCTION_MTP) + systemd_start_unit_wait_started ("mtp-responder.service", NULL, -1); +} + +static struct uevent_handler uh = { + .subsystem = "usb_mode", + .uevent_func = uevent_usb_mode_handler, +}; + static void usb_init(void *data) { int ret; @@ -413,6 +443,10 @@ static void usb_init(void *data) ret = usb_config_init(); if (ret < 0) _E("Failed to initialize usb configuation."); + + ret = register_udev_uevent_control(&uh); + if (ret < 0) + _E("Failed to register udev event(%d)", ret); } ret = usb_dbus_init(); @@ -434,6 +468,7 @@ static void usb_exit(void *data) usb_state_update_state(USB_DISCONNECTED, USB_FUNCTION_NONE); if (!is_emulator()) { + unregister_udev_uevent_control(&uh); usb_config_deinit(); usb_release(); } -- 2.7.4