{
int state;
- if (vconf_get_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, &state)) {
+ if (vconf_get_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, &state) != VCONF_OK) {
_E("Failed to get vconf value for usb debug mode: %d", vconf_get_ext_errno());
return -1;
}
void set_usb_debug_state(bool on)
{
int state = on ? 1 : 0;
- int ret;
- ret = vconf_set_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, state);
- if (ret == 0)
+ /*
+ * VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL can also be written outside of deviced.
+ * So you should always write regardless of the internal debug_state of deviced.
+ */
+ if (vconf_set_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, state) == VCONF_OK)
debug_state = on;
else
_E("Failed to set vconf value for usb debug mode: %d", vconf_get_ext_errno());
mode = vconf_keynode_get_bool(key);
- if (mode == debug_state)
+ /* This also prevents vconf self-loop by set_usb_debug_state(). */
+ if (mode == debug_state) {
+ _I("USB debug is already %s.", mode ? "ON" : "OFF");
return;
+ }
debug_state = mode;
static int usb_debug_mode_changed(void *data)
{
int on;
- unsigned mode;
- int ret;
+ int ret = 0;
+ unsigned int mode;
on = *(int *)data;
- mode = usb_state_get_current_mode();
- if (mode == 0)
- mode = usb_state_get_selected_mode();
-
- _I("Previous mode(%d).", mode);
-
+ /*
+ * It is not always possible to add sdb mode to an existing mode.
+ * The newly changed mode is not always possible and meaningful.
+ * So, You use the predefined mode for sdb mode only.
+ *
+ * Example:
+ * - Current mode: USB_FUNCTION_RNDIS | USB_FUNCTION_DIAG
+ * - Adding SDB : USB_FUNCTION_SDB | USB_FUNCTION_RNDIS | USB_FUNCTION_DIAG ==> this mode does not exist.
+ */
if (on)
- mode |= USB_FUNCTION_SDB;
+ mode = USB_FUNCTION_MTP | USB_FUNCTION_ACM | USB_FUNCTION_SDB; /* SET_USB_SDB */
else
- mode &= ~USB_FUNCTION_SDB;
+ mode = USB_FUNCTION_MTP | USB_FUNCTION_ACM; /* SET_USB_DEFAULT */
- _I("New mode(%d).", mode);
-
- ret = usb_change_mode(mode);
- if (ret < 0)
- _E("Failed to change usb mode to (%d).", mode);
+ 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;
}
void add_usb_debug_handler(void)
{
- int state = 0, ret;
+ int state = 0;
if (vconf_notify_key_changed(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL,
- usb_debug_changed, NULL) != 0)
+ usb_debug_changed, NULL) != VCONF_OK)
_E("Failed to add usb debug handler.");
- register_notifier(DEVICE_NOTIFIER_USB_DEBUG_MODE,
- usb_debug_mode_changed);
+ register_notifier(DEVICE_NOTIFIER_USB_DEBUG_MODE, usb_debug_mode_changed);
- ret = vconf_get_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, &state);
- if (ret == 0)
+ if (vconf_get_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, &state) == VCONF_OK)
debug_state = (state == 0 ? false : true);
- else if (ret < 0)
+ else
_E("Failed to get vconf value for usb debug mode: %d", vconf_get_ext_errno());
}
void remove_usb_debug_handler(void)
{
- vconf_ignore_key_changed(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL,
- usb_debug_changed);
-
- unregister_notifier(DEVICE_NOTIFIER_USB_DEBUG_MODE,
- usb_debug_mode_changed);
+ vconf_ignore_key_changed(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, usb_debug_changed);
+ unregister_notifier(DEVICE_NOTIFIER_USB_DEBUG_MODE, usb_debug_mode_changed);
}