def post_processing_after_browser(chrome): """ Called when a new browser instance has been initialized. Note that this hook function is called regardless of arc_mode. @param chrome: Chrome object. """ # Remove any stale dumpstate files. if os.path.isfile(_DUMPSTATE_PATH): os.unlink(_DUMPSTATE_PATH) # Wait for Android container ready if ARC is enabled. if chrome.arc_mode == arc_common.ARC_MODE_ENABLED: try: arc_common.wait_for_android_boot() except Exception: # Save dumpstate so that we can figure out why boot does not # complete. _save_android_dumpstate() raise
def wait_for_adb_ready(timeout=_WAIT_FOR_ADB_READY): """Wait for the ADB client to connect to the ARC container. @param timeout: Timeout in seconds. """ # Although adbd is started at login screen, we still need /data to be # mounted to set up key-based authentication. /data should be mounted # once the user has logged in. initial_timeout = timeout start_time = time.time() _wait_for_data_mounted(timeout) timeout -= (time.time() - start_time) start_time = time.time() arc_common.wait_for_android_boot(timeout) timeout -= (time.time() - start_time) setup_adb_host() if is_adb_connected(): return # Push keys for adb. pubkey_path = os.environ[_ADB_VENDOR_KEYS] + '.pub' with open(pubkey_path, 'r') as f: _write_android_file(_ANDROID_ADB_KEYS_PATH, f.read()) _android_shell('chown shell ' + pipes.quote(_ANDROID_ADB_KEYS_PATH)) _android_shell('restorecon ' + pipes.quote(_ANDROID_ADB_KEYS_PATH)) attempt_count = 3 timeout = timeout / attempt_count for i in range(attempt_count): if _restart_adb_and_wait_for_ready(timeout): return raise error.TestFail('Failed to connect to adb in %d seconds.' % initial_timeout)
def wait_for_android_boot(timeout=None): """Sleep until Android has completed booting or timeout occurs. @param timeout: Timeout in seconds. """ arc_common.wait_for_android_boot(timeout)
def wait_for_adb_ready(timeout=_WAIT_FOR_ADB_READY): """Wait for the ADB client to connect to the ARC container. @param timeout: Timeout in seconds. """ # Although adbd is started at login screen, we still need /data to be # mounted to set up key-based authentication. /data should be mounted # once the user has logged in. start_time = time.time() _wait_for_data_mounted(timeout) timeout -= (time.time() - start_time) start_time = time.time() arc_common.wait_for_android_boot(timeout) timeout -= (time.time() - start_time) setup_adb_host() if is_adb_connected(): return # Push keys for adb. pubkey_path = os.environ[_ADB_VENDOR_KEYS] + '.pub' with open(pubkey_path, 'r') as f: _write_android_file(_ANDROID_ADB_KEYS_PATH, f.read()) _android_shell('chown shell ' + pipes.quote(_ANDROID_ADB_KEYS_PATH)) _android_shell('restorecon ' + pipes.quote(_ANDROID_ADB_KEYS_PATH)) # This starts adbd, restarting it if needed so it can read the updated key. _android_shell('setprop sys.usb.config mtp') _android_shell('setprop sys.usb.config mtp,adb') exception = error.TestFail('Failed to connect to adb in %d seconds.' % timeout) # Keeps track of how many times adb has attempted to establish a # connection. def _adb_connect_wrapper(): _adb_connect_wrapper.attempts += 1 return adb_connect(_adb_connect_wrapper.attempts) _adb_connect_wrapper.attempts = 0 try: utils.poll_for_condition(_adb_connect_wrapper, exception, timeout) except (utils.TimeoutError, error.TestFail): # The operation has failed, but let's try to clarify the failure to # avoid shifting blame to adb. # First, collect some information and log it. arc_alive = is_android_container_alive() arc_booted = _android_shell('getprop sys.boot_completed', ignore_status=True) arc_system_events = _android_shell( 'logcat -d -b events *:S arc_system_event', ignore_status=True) adbd_pid = _android_shell('pidof -s adbd', ignore_status=True) adbd_port_reachable = _is_tcp_port_reachable(_ADBD_ADDRESS) adb_state = utils.system_output('adb get-state', ignore_status=True) logging.debug('ARC alive: %s', arc_alive) logging.debug('ARC booted: %s', arc_booted) logging.debug('ARC system events: %s', arc_system_events) logging.debug('adbd process: %s', adbd_pid) logging.debug('adbd port reachable: %s', adbd_port_reachable) logging.debug('adb state: %s', adb_state) # Now go through the usual suspects and raise nicer errors to make the # actual failure clearer. if not arc_alive: raise error.TestFail('ARC is not alive.') if not adbd_pid: raise error.TestFail('adbd is not running.') if arc_booted != '1': raise error.TestFail('ARC did not finish booting.') if not adbd_port_reachable: raise error.TestFail('adbd TCP port is not reachable.') # We exhausted all possibilities. Fall back to printing the generic # error. raise