platform_system_core/adb
Spencer Low a5b06b0ff8 adb: win32: fix USB device hang when resuming from sleep/hibernation
After resuming Windows from sleep or hibernation, USB connections are not
automatically disconnected. Writing to the USB connections does not return any
errors, but read never returns. My theory is that the device saw the host
sleep/hibernation as a disconnect, so the device is waiting for re-auth from the
host as if the host was just connected.

To solve this, detect resume from sleep/hibernation, disconnect all USB
connections and let the device poll thread re-detect the USB devices in 1 sec.

This is done by using a hidden window that receives power notifications. The
hidden window code is based on Chromium's similar code (platform-tools already
includes the Chromium Authors license).

This depends on a change to AdbWinUsbApi.dll that makes AdbCloseHandle(endpoint)
abort any pending IOs and wait for those IOs to be aborted.

I expect that this should solve many adb and Android Studio related bugs
regarding hangs or errors.

Also in this change:

 - Add D() logging for any errors from AdbWinApi.dll API calls.

 - Stop setting errno to Win32 error values which the caller can't really do
   anything with. Stop calling SetLastError() because the callers don't check
   GetLastError() anyway.

 - Check the return value from writing zero length packets.

 - If the full amount of data isn't written, return an error.

 - Upon any usb_read/usb_write error, kick the connection instead of only
   kicking when ERROR_INVALID_HANDLE is encountered.

 - Restructure some code from nested-if-trees to goto-fail to make it easier
   to follow.

 - Delete usb_name() since it isn't thread-safe and it isn't used.

Change-Id: Iffcf5315ad8593d0c7e93012afaabe6fae354ac1
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-08-01 19:19:09 -07:00
..
client adb: win32: Unicode path names, env vars, some console support 2015-07-31 13:30:41 -07:00
daemon adb: poll for emulator connection. 2015-07-31 14:25:19 -07:00
.clang-format Fix clang-format file for correct indent settings. 2015-03-19 13:27:20 -07:00
Android.mk adb: win32: Unicode path names, env vars, some console support 2015-07-31 13:30:41 -07:00
CPPLINT.cfg Ignore whitespace/indent issues from cpplint. 2015-05-18 16:49:07 -07:00
MODULE_LICENSE_APACHE2 eclair snapshot 2009-11-12 18:46:23 -08:00
NOTICE eclair snapshot 2009-11-12 18:46:23 -08:00
OVERVIEW.TXT Fixing spelling errors in adb docs 2010-04-28 11:38:39 -04:00
SERVICES.TXT adb: implement "adb reverse <local> <remote>" 2014-05-27 16:42:13 +02:00
SYNC.TXT Adding documentation on the sync part of the adb protocol previously missing. 2014-03-20 20:36:46 +01:00
__init__.py Create adb Python package. 2015-07-27 15:52:15 -07:00
adb.cpp adb: win32: Unicode path names, env vars, some console support 2015-07-31 13:30:41 -07:00
adb.h Report getaddrinfo failures correctly. 2015-07-23 21:14:38 -07:00
adb_auth.cpp Increase size of the the adb packets sent over the wire 2015-07-22 13:06:06 -07:00
adb_auth.h Ignore ro.adb.secure in user builds. 2015-06-18 10:19:30 -07:00
adb_auth_client.cpp Increase size of the the adb packets sent over the wire 2015-07-22 13:06:06 -07:00
adb_auth_host.cpp adb: win32: Unicode path names, env vars, some console support 2015-07-31 13:30:41 -07:00
adb_client.cpp adb: win32: initial IPv6 support and improved Winsock error reporting 2015-07-30 23:07:55 -07:00
adb_client.h Fix error handling/reporting for "adb forward" and "adb reverse". 2015-05-29 18:03:57 -07:00
adb_io.cpp Add WriteFdFmt and clean up more code. 2015-05-01 17:36:46 -07:00
adb_io.h Revert "Turn on -Wformat-nonliteral." 2015-07-09 20:35:09 +00:00
adb_io_test.cpp Write mkdirs in more idiomatic C++ style. 2015-07-30 15:08:53 -07:00
adb_listeners.cpp adb: win32: initial IPv6 support and improved Winsock error reporting 2015-07-30 23:07:55 -07:00
adb_listeners.h adb: win32: initial IPv6 support and improved Winsock error reporting 2015-07-30 23:07:55 -07:00
adb_trace.h Improve logging. 2015-05-21 16:25:57 -07:00
adb_utils.cpp adb: win32: initial IPv6 support and improved Winsock error reporting 2015-07-30 23:07:55 -07:00
adb_utils.h adb: win32: initial IPv6 support and improved Winsock error reporting 2015-07-30 23:07:55 -07:00
adb_utils_test.cpp More adb cleanup. 2015-07-30 17:46:58 -07:00
commandline.cpp Clean up -p handling slightly. 2015-07-31 13:18:22 -07:00
console.cpp adb: win32: initial IPv6 support and improved Winsock error reporting 2015-07-30 23:07:55 -07:00
device.py Add a script to record Android boot time. 2015-07-30 14:16:15 +09:00
fdevent.cpp Use _WIN32 rather than HAVE_WINSOCK. 2015-07-29 17:45:24 -07:00
fdevent.h Remove extern "C" barriers to using C++. 2015-04-17 09:47:42 -07:00
file_sync_client.cpp More adb cleanup. 2015-07-30 17:46:58 -07:00
file_sync_service.cpp More adb cleanup. 2015-07-30 17:46:58 -07:00
file_sync_service.h More adb cleanup. 2015-07-30 17:46:58 -07:00
framebuffer_service.cpp Move adb to C++. 2015-03-09 14:06:11 -07:00
get_my_path_darwin.cpp Move get_my_path_darwin to C++. 2015-04-16 13:24:58 -07:00
get_my_path_linux.cpp Move adb to C++. 2015-03-09 14:06:11 -07:00
get_my_path_windows.cpp adb: win32: Unicode path names, env vars, some console support 2015-07-31 13:30:41 -07:00
jdwp_service.cpp Report getaddrinfo failures correctly. 2015-07-23 21:14:38 -07:00
mutex_list.h adb: Cleanup dead code 2013-04-24 21:31:45 -07:00
protocol.txt Increase size of the the adb packets sent over the wire 2015-07-22 13:06:06 -07:00
qemu_tracing.cpp Move adb to C++. 2015-03-09 14:06:11 -07:00
qemu_tracing.h Revert "Turn on -Wformat-nonliteral." 2015-07-09 20:35:09 +00:00
remount_service.cpp Fix "adb remount" for when the root directory is in system.img 2015-07-08 19:36:19 +00:00
remount_service.h Failure to find an oem partition should not be a remount failure. 2015-05-11 13:28:22 -07:00
services.cpp adb: win32: initial IPv6 support and improved Winsock error reporting 2015-07-30 23:07:55 -07:00
set_verity_enable_state_service.cpp Failure to find an oem partition should not be a remount failure. 2015-05-11 13:28:22 -07:00
sockets.cpp Increase size of the the adb packets sent over the wire 2015-07-22 13:06:06 -07:00
sockets.dia auto import from //depot/cupcake/@135843 2009-03-03 19:32:55 -08:00
sysdeps.h adb: win32: Unicode path names, env vars, some console support 2015-07-31 13:30:41 -07:00
sysdeps_win32.cpp adb: win32: Unicode path names, env vars, some console support 2015-07-31 13:30:41 -07:00
test_adb.py Create adb Python package. 2015-07-27 15:52:15 -07:00
test_device.py adb/test_device.py fixes for win32 and no use of ANDROID_SERIAL 2015-07-30 01:19:52 -07:00
test_track_devices.cpp Make test_track_devices.cpp output easier to read. 2015-05-04 15:51:50 -07:00
transport.cpp Make clear of the data length sent by write_packet. 2015-07-30 20:01:10 -07:00
transport.h Increase size of the the adb packets sent over the wire 2015-07-22 13:06:06 -07:00
transport_local.cpp adb: poll for emulator connection. 2015-07-31 14:25:19 -07:00
transport_test.cpp Make atransport be a real class. 2015-05-21 15:49:05 -07:00
transport_usb.cpp Increase size of the the adb packets sent over the wire 2015-07-22 13:06:06 -07:00
usb_linux.cpp Fix const-ness of strrchr callers. 2015-07-28 08:07:21 -07:00
usb_linux_client.cpp Increase size of the the adb packets sent over the wire 2015-07-22 13:06:06 -07:00
usb_osx.cpp Revert "Revert "Split adb_main.cpp into client and daemon."" 2015-05-08 17:33:21 -07:00
usb_windows.cpp adb: win32: fix USB device hang when resuming from sleep/hibernation 2015-08-01 19:19:09 -07:00