| OLD | NEW |
| 1 # Copyright 2014 Google Inc. All rights reserved. | 1 # Copyright 2014 Google Inc. All rights reserved. |
| 2 # | 2 # |
| 3 # Licensed under the Apache License, Version 2.0 (the "License"); | 3 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 # you may not use this file except in compliance with the License. | 4 # you may not use this file except in compliance with the License. |
| 5 # You may obtain a copy of the License at | 5 # You may obtain a copy of the License at |
| 6 # | 6 # |
| 7 # http://www.apache.org/licenses/LICENSE-2.0 | 7 # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 # | 8 # |
| 9 # Unless required by applicable law or agreed to in writing, software | 9 # Unless required by applicable law or agreed to in writing, software |
| 10 # distributed under the License is distributed on an "AS IS" BASIS, | 10 # distributed under the License is distributed on an "AS IS" BASIS, |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 cmd_id, header, data = self.Read(expected_ids + finish_ids) | 200 cmd_id, header, data = self.Read(expected_ids + finish_ids) |
| 201 yield cmd_id, header, data | 201 yield cmd_id, header, data |
| 202 if cmd_id in finish_ids: | 202 if cmd_id in finish_ids: |
| 203 break | 203 break |
| 204 | 204 |
| 205 def _Flush(self): | 205 def _Flush(self): |
| 206 while self.send_buffer: | 206 while self.send_buffer: |
| 207 chunk = self.send_buffer[:self.adb.max_packet_size] | 207 chunk = self.send_buffer[:self.adb.max_packet_size] |
| 208 try: | 208 try: |
| 209 self.adb.Write(chunk) | 209 self.adb.Write(chunk) |
| 210 # Wait for ack from device, ignoring these for too long causes things |
| 211 # to explode. |
| 212 self.adb.ReadUntil('OKAY') |
| 210 except libusb1.USBError as e: | 213 except libusb1.USBError as e: |
| 211 self.send_buffer = '' | 214 self.send_buffer = '' |
| 212 raise usb_exceptions.WriteFailedError('Could not write %r' % chunk, e) | 215 raise usb_exceptions.WriteFailedError('Could not write %r' % chunk, e) |
| 213 self.send_buffer = self.send_buffer[self.adb.max_packet_size:] | 216 self.send_buffer = self.send_buffer[self.adb.max_packet_size:] |
| 214 | 217 |
| 215 def _ReadBuffered(self, size): | 218 def _ReadBuffered(self, size): |
| 216 # Ensure recv buffer has enough data. | 219 # Ensure recv buffer has enough data. |
| 217 while len(self.recv_buffer) < size: | 220 while len(self.recv_buffer) < size: |
| 218 try: | 221 try: |
| 219 _, data = self.adb.ReadUntil('WRTE') | 222 msg = self.adb.ReadUntil('WRTE') |
| 220 except adb_protocol.InvalidResponseError as e: | 223 except adb_protocol.InvalidResponseError as e: |
| 221 raise usb_exceptions.AdbCommandFailureException( | 224 raise usb_exceptions.AdbCommandFailureException( |
| 222 'Command failed: %s' % e) | 225 'Command failed: %s' % e) |
| 223 self.recv_buffer += data | 226 self.recv_buffer += msg.data |
| 224 | 227 |
| 225 result = self.recv_buffer[:size] | 228 result = self.recv_buffer[:size] |
| 226 self.recv_buffer = self.recv_buffer[size:] | 229 self.recv_buffer = self.recv_buffer[size:] |
| 227 return result | 230 return result |
| 228 | 231 |
| 229 @classmethod | 232 @classmethod |
| 230 def _VerifyReplyCommand(cls, header, expected_ids): | 233 def _VerifyReplyCommand(cls, header, expected_ids): |
| 231 # Header is (ID, ...). | 234 # Header is (ID, ...). |
| 232 command_id = adb_protocol.Wire2ID(header[0]) | 235 command_id = adb_protocol.Wire2ID(header[0]) |
| 233 if command_id not in cls._VALID_IDS: | 236 if command_id not in cls._VALID_IDS: |
| 234 raise usb_exceptions.AdbCommandFailureException( | 237 raise usb_exceptions.AdbCommandFailureException( |
| 235 'Command failed; incorrect header: %s' % header) | 238 'Command failed; incorrect header: %s' % header) |
| 236 if command_id not in expected_ids: | 239 if command_id not in expected_ids: |
| 237 if command_id == 'FAIL': | 240 if command_id == 'FAIL': |
| 238 raise usb_exceptions.AdbCommandFailureException('Command failed.') | 241 raise usb_exceptions.AdbCommandFailureException('Command failed.') |
| 239 raise adb_protocol.InvalidResponseError( | 242 raise adb_protocol.InvalidResponseError( |
| 240 'Expected one of %s, got %s' % (expected_ids, command_id)) | 243 'Expected one of %s, got %s' % (expected_ids, command_id)) |
| 241 return command_id | 244 return command_id |
| OLD | NEW |