Go to file
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
adb adb: win32: fix USB device hang when resuming from sleep/hibernation 2015-08-01 19:19:09 -07:00
adf Adf: Remove unused variable 2015-07-27 22:08:16 -07:00
base Write mkdirs in more idiomatic C++ style. 2015-07-30 15:08:53 -07:00
cpio makebootfs: use libcutils shared libraries 2015-04-15 10:32:19 -07:00
crash_reporter crash_reporter: Add license information. 2015-07-28 17:31:05 -07:00
debuggerd bionic no longer sends SIGPIPE to debuggerd. 2015-07-30 08:15:57 -07:00
fastboot Document the current MAX_USBFS_BULK_SIZE situation. 2015-07-28 14:18:50 -07:00
fs_mgr Merge "Use fsck.f2fs -a instead of -f for faster boot" 2015-07-21 16:06:40 +00:00
healthd Move away from gr_surface. 2015-04-15 10:25:55 -07:00
include Reserve new UID range for OEM. 2015-07-31 14:13:49 -07:00
init Merge "Stop calling fsck on shutdown by default" 2015-07-31 23:13:15 +00:00
libbacktrace Use delete[] to de-allocate pointers from new[] 2015-07-09 10:50:04 -07:00
libcutils Merge "Use __ANDROID__ instead of HAVE_ANDROID_OS." 2015-07-30 16:34:47 +00:00
libdiskconfig am eb075e28: am c8179498: am 2f62edf7: Merge "libdiskconfig: Turn on -Werror" 2014-05-21 21:19:27 +00:00
libion Remove LOCAL_ADDITIONAL_DEPENDENCIES in cases where it's not needed. 2015-04-02 14:31:07 -07:00
liblog Use _WIN32 rather than HAVE_WINSOCK. 2015-07-29 17:45:24 -07:00
libmemtrack Add missing <malloc.h> and <string.h> includes. 2015-01-28 11:37:57 -08:00
libmincrypt Enable clang compilation. 2015-05-14 10:53:48 -07:00
libnativebridge Use __ANDROID__ instead of HAVE_ANDROID_OS. 2015-07-30 09:33:43 -07:00
libnetutils Use __ANDROID__ instead of HAVE_ANDROID_OS. 2015-07-30 09:33:43 -07:00
libpixelflinger pixelflinger: make self-contained 2015-03-19 12:34:35 -07:00
libprocessgroup Remove uses of libcxx.mk. 2015-03-27 11:24:04 -07:00
libsparse libsparse: Wrap sparse_crc32.h to be C++ compatible. 2015-07-11 12:48:42 -07:00
libsuspend Libsuspend: Remove unused variable 2014-11-24 18:53:44 -08:00
libsync Remove LOCAL_ADDITIONAL_DEPENDENCIES in cases where it's not needed. 2015-04-02 14:31:07 -07:00
libsysutils Add missing <malloc.h> and <string.h> includes. 2015-01-28 11:37:57 -08:00
libusbhost am 0d8943c2: am e4c5b614: Merge "libusbhost: Fix IOCTL call during usb_request_cancel" 2014-08-12 21:05:43 +00:00
libutils Merge "Use __ANDROID__ instead of HAVE_ANDROID_OS." 2015-07-30 16:34:47 +00:00
libziparchive Fix ODR issues in ART. 2015-06-29 16:27:44 -07:00
lmkd Lmkd: Fix unused variables 2014-11-24 20:32:42 -08:00
logcat Lower the priority of the threads in logd/logcat. 2015-06-09 12:40:20 -07:00
logd logd: deprecate TARGET_USES_LOGD 2015-07-28 09:37:07 -07:00
logwrapper Use fsck.f2fs -a instead of -f for faster boot 2015-07-15 10:13:51 -07:00
metrics metrics: Add license information. 2015-07-28 17:30:08 -07:00
mkbootimg mkbootimg: misc typo fixes 2015-06-04 09:59:01 -07:00
reboot reboot: Turn on -Werror 2014-05-21 12:58:38 -07:00
rootdir Introduce a mechanism to trace boot sequence. 2015-07-29 12:53:05 +09:00
run-as package missing include for string.h 2015-04-01 11:15:37 -07:00
sdcard Move sdcard off PAGESIZE and onto PAGE_SIZE. 2015-07-28 16:36:47 -07:00
toolbox Toolbox: Disable unused-const-variable warning 2015-07-30 11:52:11 -07:00
tzdatacheck Executable to run on boot that removes old tzdata if needed 2015-04-13 11:38:32 +01:00
.gitignore Don't compile abort_socket.c for host targets. It is only intended to run on Linux targets. 2009-05-26 13:23:23 -07:00
Android.mk Remove the simulator target from all makefiles. 2011-07-11 22:12:32 -07:00
CleanSpec.mk Add a CleanSpec for grep/toolbox. 2015-03-22 18:04:54 -07:00
MODULE_LICENSE_APACHE2 auto import from //depot/cupcake/@135843 2013-07-30 13:56:49 -07:00
NOTICE Fix omission in NOTICE file. 2013-07-30 13:56:55 -07:00