usb: change usb initialization - skip usb hal operation when usb is disconnected. 20/248520/5 accepted/tizen/unified/20201202.124927 submit/tizen/20201201.235753
authorINSUN PYO <insun.pyo@samsung.com>
Fri, 27 Nov 2020 10:06:00 +0000 (19:06 +0900)
committerINSUN PYO <insun.pyo@samsung.com>
Tue, 1 Dec 2020 01:49:04 +0000 (10:49 +0900)
If USB is initialized without a USB connection, only initialize the internal usb state and skip usb hal operation.

To support sdb over BT, sdbd.service should start automatically at boot time.
If usb cable is not connected, usb hal stops sdbd.service when initializing usb.

Change-Id: I936d0a62b5d3a0e8229ff02760e1a6d23081a003

src/usb/usb.c

index 407edde..f85bba3 100644 (file)
@@ -386,7 +386,7 @@ int usb_change_mode(unsigned int new_mode, bool change_debug_mode)
 static int usb_state_changed(const char *index, int new_status)
 {
        int ret = -1;
-       static int old_status = -1;
+       static int old_status = -1; /* -1: Uninitialized, 0: disconnected, 1: connected */
 
        /* For debugging. Do not move the location. */
        _I("USB state is changed by extcon from (%d) to (%d).", old_status, new_status);
@@ -400,7 +400,21 @@ static int usb_state_changed(const char *index, int new_status)
                break;
 
        case USB_DISCONNECTED:
-               ret = usb_disconnected();
+               if (old_status == -1) {
+                       /* only initialize the internal data state and skip usb hal operation. */
+                       _I("USB is initialized without USB connection");
+
+                       /* From usb_disconnected() */
+                       usb_state_set_connection(USB_DISCONNECTED);
+                       send_usb_state_changed_event(VCONFKEY_SYSMAN_USB_DISCONNECTED);
+
+                       /*  From usb_disable() */
+                       (void)usb_state_set_current_mode(USB_FUNCTION_NONE);
+                       change_usb_state_notification_handler(USB_FUNCTION_NONE);
+
+                       ret = 0;
+               } else
+                       ret = usb_disconnected();
                break;
 
        default: