OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Provides a variety of device interactions based on adb. | 5 """Provides a variety of device interactions based on adb. |
6 | 6 |
7 Eventually, this will be based on adb_wrapper. | 7 Eventually, this will be based on adb_wrapper. |
8 """ | 8 """ |
9 # pylint: disable=unused-argument | 9 # pylint: disable=unused-argument |
10 | 10 |
(...skipping 1127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1138 dir_file_count += sum(len(f) for _r, _d, f in os.walk(h)) | 1138 dir_file_count += sum(len(f) for _r, _d, f in os.walk(h)) |
1139 else: | 1139 else: |
1140 dir_file_count += 1 | 1140 dir_file_count += 1 |
1141 | 1141 |
1142 push_duration = self._ApproximateDuration( | 1142 push_duration = self._ApproximateDuration( |
1143 file_count, file_count, size, False) | 1143 file_count, file_count, size, False) |
1144 dir_push_duration = self._ApproximateDuration( | 1144 dir_push_duration = self._ApproximateDuration( |
1145 len(host_device_tuples), dir_file_count, dir_size, False) | 1145 len(host_device_tuples), dir_file_count, dir_size, False) |
1146 zip_duration = self._ApproximateDuration(1, 1, size, True) | 1146 zip_duration = self._ApproximateDuration(1, 1, size, True) |
1147 | 1147 |
1148 self._InstallCommands() | |
1149 | |
1150 if dir_push_duration < push_duration and ( | 1148 if dir_push_duration < push_duration and ( |
1151 dir_push_duration < zip_duration or not self._commands_installed): | 1149 dir_push_duration < zip_duration or not self._MaybeInstallCommands()): |
1152 self._PushChangedFilesIndividually(host_device_tuples) | 1150 self._PushChangedFilesIndividually(host_device_tuples) |
1153 elif push_duration < zip_duration or not self._commands_installed: | 1151 elif push_duration < zip_duration or not self._MaybeInstallCommands(): |
1154 self._PushChangedFilesIndividually(files) | 1152 self._PushChangedFilesIndividually(files) |
1155 else: | 1153 else: |
1156 self._PushChangedFilesZipped(files) | 1154 self._PushChangedFilesZipped(files) |
1157 self.RunShellCommand( | 1155 self.RunShellCommand( |
1158 ['chmod', '-R', '777'] + [d for _, d in host_device_tuples], | 1156 ['chmod', '-R', '777'] + [d for _, d in host_device_tuples], |
1159 as_root=True, check_return=True) | 1157 as_root=True, check_return=True) |
1160 | 1158 |
1161 def _InstallCommands(self): | 1159 def _MaybeInstallCommands(self): |
1162 if self._commands_installed is None: | 1160 if self._commands_installed is None: |
1163 try: | 1161 try: |
1164 if not install_commands.Installed(self): | 1162 if not install_commands.Installed(self): |
1165 install_commands.InstallCommands(self) | 1163 install_commands.InstallCommands(self) |
1166 self._commands_installed = True | 1164 self._commands_installed = True |
1167 except Exception as e: | 1165 except Exception as e: |
1168 logging.warning('unzip not available: %s' % str(e)) | 1166 logging.warning('unzip not available: %s' % str(e)) |
1169 self._commands_installed = False | 1167 self._commands_installed = False |
| 1168 return self._commands_installed |
1170 | 1169 |
1171 @staticmethod | 1170 @staticmethod |
1172 def _ApproximateDuration(adb_calls, file_count, byte_count, is_zipping): | 1171 def _ApproximateDuration(adb_calls, file_count, byte_count, is_zipping): |
1173 # We approximate the time to push a set of files to a device as: | 1172 # We approximate the time to push a set of files to a device as: |
1174 # t = c1 * a + c2 * f + c3 + b / c4 + b / (c5 * c6), where | 1173 # t = c1 * a + c2 * f + c3 + b / c4 + b / (c5 * c6), where |
1175 # t: total time (sec) | 1174 # t: total time (sec) |
1176 # c1: adb call time delay (sec) | 1175 # c1: adb call time delay (sec) |
1177 # a: number of times adb is called (unitless) | 1176 # a: number of times adb is called (unitless) |
1178 # c2: push time delay (sec) | 1177 # c2: push time delay (sec) |
1179 # f: number of files pushed via adb (unitless) | 1178 # f: number of files pushed via adb (unitless) |
(...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1930 return [cls(adb, **kwargs) for adb in adb_wrapper.AdbWrapper.Devices() | 1929 return [cls(adb, **kwargs) for adb in adb_wrapper.AdbWrapper.Devices() |
1931 if not blacklisted(adb)] | 1930 if not blacklisted(adb)] |
1932 | 1931 |
1933 @decorators.WithTimeoutAndRetriesFromInstance() | 1932 @decorators.WithTimeoutAndRetriesFromInstance() |
1934 def RestartAdbd(self, timeout=None, retries=None): | 1933 def RestartAdbd(self, timeout=None, retries=None): |
1935 logging.info('Restarting adbd on device.') | 1934 logging.info('Restarting adbd on device.') |
1936 with device_temp_file.DeviceTempFile(self.adb, suffix='.sh') as script: | 1935 with device_temp_file.DeviceTempFile(self.adb, suffix='.sh') as script: |
1937 self.WriteFile(script.name, _RESTART_ADBD_SCRIPT) | 1936 self.WriteFile(script.name, _RESTART_ADBD_SCRIPT) |
1938 self.RunShellCommand(['source', script.name], as_root=True) | 1937 self.RunShellCommand(['source', script.name], as_root=True) |
1939 self.adb.WaitForDevice() | 1938 self.adb.WaitForDevice() |
OLD | NEW |