summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorINSUN PYO <insun.pyo@samsung.com>2020-03-10 09:36:48 +0900
committerHyotaek Shim <hyotaek.shim@samsung.com>2020-03-10 04:01:17 +0000
commit84e46c8f674b58a020d0742ff22b08c5e3b255fd (patch)
treeab3d7f8ebd720509dde812b5a23936722cff6af6
parentae94dbea1c7eb8dd10b41d60cf6a5bba620cf929 (diff)
downloaddeviced-84e46c8f674b58a020d0742ff22b08c5e3b255fd.tar.gz
deviced-84e46c8f674b58a020d0742ff22b08c5e3b255fd.tar.bz2
deviced-84e46c8f674b58a020d0742ff22b08c5e3b255fd.zip
Improve handling of the usb tethering mode
On: Use predefined mode (USB_FUNCTION_ACM | USB_FUNCTION_SDB | USB_FUNCTION_RNDIS) Off: Use predefined mode (USB_FUNCTION_MTP | USB_FUNCTION_ACM) + USB_FUNCTION_SDB(conditional) Caution: If usb debug menu was enabled, add USB_FUNCTION_SDB to new mode to use. When tethering is enabled, additionally enable usb debug(USB_FUNCTION_SDB) unconditionally. Since usb debug is always enabled when you turn off usb tethering, there is no way to know if usb debug was enabled or not. So before enabling usb tethering, save the previous state. This saved value is used to check if the debug menu was enabled or not when you turn off usb tethering. In addition, if someone changes the usb mode while tethering on, use the latest usb mode to determine the usb debug mode instead of using the saved value. Change-Id: I20cf762f4d45b96cd7142cf3e6e43a402213a415 (cherry picked from commit 4e120c0961742d7cb4e0dd0c0833f16635c41fee)
-rw-r--r--src/usb/usb-tethering.c66
1 files changed, 42 insertions, 24 deletions
diff --git a/src/usb/usb-tethering.c b/src/usb/usb-tethering.c
index 5b22da07..884bc255 100644
--- a/src/usb/usb-tethering.c
+++ b/src/usb/usb-tethering.c
@@ -52,36 +52,54 @@ static void usb_tethering_changed(keynode_t *key, void *data)
device_notify(DEVICE_NOTIFIER_USB_TETHERING_MODE, (void *)curr);
}
-static int usb_tethering_mode_changed(void *data)
+static int usb_tethering_mode_changed(void *on)
{
- bool on;
- int ret = 0;
- unsigned mode;
-
- on = (bool)data;
+ int ret;
+ unsigned new_mode;
+ static unsigned int saved_prev_mode = USB_FUNCTION_NONE;
+ const unsigned int curr_mode = usb_state_get_selected_mode();
+ const unsigned int predefined_rndis_mode_off = USB_FUNCTION_ACM | USB_FUNCTION_MTP;
+ const unsigned int predefined_rndis_mode_on = USB_FUNCTION_ACM | USB_FUNCTION_SDB | USB_FUNCTION_RNDIS;
/*
- * 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.
+ * On: Use predefined mode (USB_FUNCTION_ACM | USB_FUNCTION_SDB | USB_FUNCTION_RNDIS)
+ * Off: Use predefined mode (USB_FUNCTION_MTP | USB_FUNCTION_ACM) + USB_FUNCTION_SDB(conditional)
+ *
+ * Caution: If usb debug menu was enabled, add USB_FUNCTION_SDB to new mode to use.
+ *
+ * When tethering is enabled, additionally enable usb debug(USB_FUNCTION_SDB) unconditionally.
+ * Since usb debug is always enabled when you turn off usb tethering, there is no way to know if usb debug was enabled or not.
+ * So before enabling usb tethering, save the previous state.
+ * This saved value is used to check if the debug menu was enabled or not when you turn off usb tethering.
*
- * 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.
+ * In addition, if someone changes the usb mode while tethering on,
+ * use the latest usb mode to determine the usb debug mode instead of using the saved value.
*
- * TODO. You should consider removing USB_FUNCTION_SDB mode.
*/
- if (on)
- 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; /* 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);
+
+ if ((bool)on) {
+ new_mode = predefined_rndis_mode_on;
+ saved_prev_mode = curr_mode;
+ } else {
+ new_mode = predefined_rndis_mode_off;
+
+ if (curr_mode != predefined_rndis_mode_on) /* someone changes the usb mode while tethering on, use latest usb mode */
+ saved_prev_mode = curr_mode;
+
+ if(saved_prev_mode & USB_FUNCTION_SDB)
+ new_mode |= USB_FUNCTION_SDB;
+
+ saved_prev_mode = USB_FUNCTION_NONE;
+ }
+
+ if (curr_mode == new_mode) {
+ _I("already USB mode(0x%x) was used", new_mode);
+ return 0;
+ }
+
+ ret = usb_change_mode(new_mode);
+ if (ret < 0)
+ _E("Failed to change USB mode to (0x%x).", new_mode);
return ret;
}