system/core
Revisão | 6c78e3ba1b7f8b5d54c36d240efb89418a964957 (tree) |
---|---|
Hora | 2019-05-30 08:35:22 |
Autor | chihhao.chen <chihhao.chen@medi...> |
Commiter | android-build-merger |
Merge "Fix non-aio USB read issue for fastbootd" into qt-dev
am: 9122289a97
Change-Id: Id416f267f477d04ed5d71f2158ebc35183befa22
@@ -43,7 +43,7 @@ struct usb_handle { | ||
43 | 43 | bool open_new_connection = true; |
44 | 44 | |
45 | 45 | int (*write)(usb_handle* h, const void* data, int len); |
46 | - int (*read)(usb_handle* h, void* data, int len); | |
46 | + int (*read)(usb_handle* h, void* data, int len, bool allow_partial); | |
47 | 47 | void (*kick)(usb_handle* h); |
48 | 48 | void (*close)(usb_handle* h); |
49 | 49 |
@@ -142,11 +142,12 @@ static int usb_ffs_write(usb_handle* h, const void* data, int len) { | ||
142 | 142 | return orig_len; |
143 | 143 | } |
144 | 144 | |
145 | -static int usb_ffs_read(usb_handle* h, void* data, int len) { | |
145 | +static int usb_ffs_read(usb_handle* h, void* data, int len, bool allow_partial) { | |
146 | 146 | D("about to read (fd=%d, len=%d)", h->bulk_out.get(), len); |
147 | 147 | |
148 | 148 | char* buf = static_cast<char*>(data); |
149 | 149 | int orig_len = len; |
150 | + unsigned count = 0; | |
150 | 151 | while (len > 0) { |
151 | 152 | int read_len = std::min(USB_FFS_BULK_SIZE, len); |
152 | 153 | int n = adb_read(h->bulk_out, buf, read_len); |
@@ -156,6 +157,16 @@ static int usb_ffs_read(usb_handle* h, void* data, int len) { | ||
156 | 157 | } |
157 | 158 | buf += n; |
158 | 159 | len -= n; |
160 | + count += n; | |
161 | + | |
162 | + // For fastbootd command such as "getvar all", len parameter is always set 64. | |
163 | + // But what we read is actually less than 64. | |
164 | + // For example, length 10 for "getvar all" command. | |
165 | + // If we get less data than expected, this means there should be no more data. | |
166 | + if (allow_partial && n < read_len) { | |
167 | + orig_len = count; | |
168 | + break; | |
169 | + } | |
159 | 170 | } |
160 | 171 | |
161 | 172 | D("[ done fd=%d ]", h->bulk_out.get()); |
@@ -221,7 +232,7 @@ static int usb_ffs_do_aio(usb_handle* h, const void* data, int len, bool read) { | ||
221 | 232 | } |
222 | 233 | } |
223 | 234 | |
224 | -static int usb_ffs_aio_read(usb_handle* h, void* data, int len) { | |
235 | +static int usb_ffs_aio_read(usb_handle* h, void* data, int len, bool allow_partial) { | |
225 | 236 | return usb_ffs_do_aio(h, data, len, true); |
226 | 237 | } |
227 | 238 |
@@ -299,7 +310,7 @@ int usb_write(usb_handle* h, const void* data, int len) { | ||
299 | 310 | } |
300 | 311 | |
301 | 312 | int usb_read(usb_handle* h, void* data, int len) { |
302 | - return h->read(h, data, len); | |
313 | + return h->read(h, data, len, false /* allow_partial */); | |
303 | 314 | } |
304 | 315 | |
305 | 316 | int usb_close(usb_handle* h) { |
@@ -255,7 +255,8 @@ ssize_t ClientUsbTransport::Read(void* data, size_t len) { | ||
255 | 255 | size_t bytes_read_total = 0; |
256 | 256 | while (bytes_read_total < len) { |
257 | 257 | auto bytes_to_read = std::min(len - bytes_read_total, kFbFfsNumBufs * kFbFfsBufSize); |
258 | - auto bytes_read_now = handle_->read(handle_.get(), char_data, bytes_to_read); | |
258 | + auto bytes_read_now = | |
259 | + handle_->read(handle_.get(), char_data, bytes_to_read, true /* allow_partial */); | |
259 | 260 | if (bytes_read_now < 0) { |
260 | 261 | return bytes_read_total; |
261 | 262 | } |