| 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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 def _HasClosed(self): | 307 def _HasClosed(self): |
| 308 """Must be called with the manager lock held.""" | 308 """Must be called with the manager lock held.""" |
| 309 if self._yielder: | 309 if self._yielder: |
| 310 self._yielder._Close() | 310 self._yielder._Close() |
| 311 self._yielder = None | 311 self._yielder = None |
| 312 self._manager._UnregisterLocked(self._local_id) | 312 self._manager._UnregisterLocked(self._local_id) |
| 313 | 313 |
| 314 def _OnRead(self, message): | 314 def _OnRead(self, message): |
| 315 """Calls from within ReadAndDispatch(), so the manager lock is held.""" | 315 """Calls from within ReadAndDispatch(), so the manager lock is held.""" |
| 316 # Can be CLSE, OKAY or WRTE. It's generally basically an ACK. | 316 # Can be CLSE, OKAY or WRTE. It's generally basically an ACK. |
| 317 if message.header.arg0 != self.remote_id: | 317 cmd_name = message.header.command_name |
| 318 if message.header.arg0 != self.remote_id and cmd_name != 'CLSE': |
| 318 # We can't assert that for now. TODO(maruel): Investigate the one-off | 319 # We can't assert that for now. TODO(maruel): Investigate the one-off |
| 319 # cases. | 320 # cases. |
| 320 logging.warning( | 321 logging.warning( |
| 321 'Unexpected remote ID: expected %d: %s', self.remote_id, message) | 322 'Unexpected remote ID: expected %d: %s', self.remote_id, message) |
| 322 if message.header.arg1 != self._local_id: | 323 if message.header.arg1 != self._local_id: |
| 323 raise InvalidResponseError( | 324 raise InvalidResponseError( |
| 324 'Unexpected local ID: expected %d' % self._local_id, message) | 325 'Unexpected local ID: expected %d' % self._local_id, message) |
| 325 cmd_name = message.header.command_name | |
| 326 if cmd_name == 'CLSE': | 326 if cmd_name == 'CLSE': |
| 327 self._HasClosed() | 327 self._HasClosed() |
| 328 return | 328 return |
| 329 if cmd_name == 'OKAY': | 329 if cmd_name == 'OKAY': |
| 330 return | 330 return |
| 331 if cmd_name == 'WRTE': | 331 if cmd_name == 'WRTE': |
| 332 try: | 332 try: |
| 333 self._Write('OKAY', '') | 333 self._Write('OKAY', '') |
| 334 except usb_exceptions.WriteFailedError as e: | 334 except usb_exceptions.WriteFailedError as e: |
| 335 _LOG.info('%s._OnRead(): Failed to reply OKAY: %s', self.port_path, e) | 335 _LOG.info('%s._OnRead(): Failed to reply OKAY: %s', self.port_path, e) |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 msg.Write(self._usb) | 581 msg.Write(self._usb) |
| 582 return _AdbMessage.Read(self._usb, auth_timeout_ms) | 582 return _AdbMessage.Read(self._usb, auth_timeout_ms) |
| 583 | 583 |
| 584 def _Unregister(self, conn_id): | 584 def _Unregister(self, conn_id): |
| 585 with self._lock: | 585 with self._lock: |
| 586 self._UnregisterLocked(conn_id) | 586 self._UnregisterLocked(conn_id) |
| 587 | 587 |
| 588 def _UnregisterLocked(self, conn_id): | 588 def _UnregisterLocked(self, conn_id): |
| 589 # self._lock must be held. | 589 # self._lock must be held. |
| 590 self._connections.pop(conn_id, None) | 590 self._connections.pop(conn_id, None) |
| OLD | NEW |