{
bool on;
unsigned mode;
- int ret;
+ int ret = 0;
on = (bool)data;
/*
- * TODO.
- * Preserve gadget mode when tethering is being turned on
- * and restore it later when tethering is being turned off/
+ * It is not always possible to add rndis mode to an existing mode.
+ * The newly changed mode is not always possible and meaningful.
+ * So, You use the predefined mode for rndis mode only.
+ *
+ * Example:
+ * - Current mode: USB_FUNCTION_MTP | USB_FUNCTION_SDB
+ * - Adding RNDIS: USB_FUNCTION_MTP | USB_FUNCTION_SDB | USB_FUNCTION_RNDIS ==> this mode does not exist.
+ *
+ * TODO. You should consider removing USB_FUNCTION_SDB mode.
*/
if (on)
- mode = USB_FUNCTION_RNDIS | USB_FUNCTION_SDB;
+ mode = USB_FUNCTION_ACM | USB_FUNCTION_SDB | USB_FUNCTION_RNDIS; /* SET_USB_RNDIS_SDB */
else
- mode = USB_FUNCTION_MTP | USB_FUNCTION_ACM | USB_FUNCTION_SDB;
-
- ret = usb_change_mode(mode);
- if (ret < 0)
- _E("Failed to change usb mode to (%d).", mode);
+ mode = USB_FUNCTION_MTP | USB_FUNCTION_ACM | USB_FUNCTION_SDB; /* SET_USB_SDB */
+
+ if (usb_state_get_selected_mode() != mode) {
+ ret = usb_change_mode(mode);
+ if (ret < 0)
+ _E("Failed to change usb mode to (%d).", mode);
+ } else
+ _I("already mode(%d) was enabled", mode);
return ret;
}