1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 from telemetry
.internal
.backends
.chrome_inspector
import devtools_client_backend
6 from telemetry
.internal
.browser
import web_contents
9 from devil
.android
import ports
13 class WebViewNotFoundException(Exception):
16 class AndroidProcess(object):
17 """Represents a single android process."""
19 def __init__(self
, app_backend
, pid
, name
):
20 self
._app
_backend
= app_backend
23 self
._local
_port
= ports
.AllocateTestServerPort()
24 self
._devtools
_client
= None
35 def _remote_devtools_port(self
):
36 return 'localabstract:webview_devtools_remote_%s' % str(self
.pid
)
38 def _UpdateDevToolsClient(self
):
39 if self
._devtools
_client
is None:
40 self
._app
_backend
.platform_backend
.ForwardHostToDevice(
41 self
._local
_port
, self
._remote
_devtools
_port
)
42 if devtools_client_backend
.IsDevToolsAgentAvailable(
43 self
._local
_port
, self
._app
_backend
):
44 self
._devtools
_client
= devtools_client_backend
.DevToolsClientBackend(
45 self
._local
_port
, self
._remote
_devtools
_port
, self
._app
_backend
)
47 def GetWebViews(self
):
49 self
._UpdateDevToolsClient
()
50 if self
._devtools
_client
is not None:
51 devtools_context_map
= (
52 self
._devtools
_client
.GetUpdatedInspectableContexts())
53 for context
in devtools_context_map
.contexts
:
54 webviews
.append(web_contents
.WebContents(
55 devtools_context_map
.GetInspectorBackend(context
['id'])))