OLD | NEW |
1 # Copyright 2012 The Chromium Authors. All rights reserved. | 1 # Copyright 2012 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 import time |
| 6 |
5 from telemetry.core.backends import app_backend | 7 from telemetry.core.backends import app_backend |
| 8 from telemetry.core.platform import android_platform_backend as \ |
| 9 android_platform_backend_module |
6 | 10 |
7 | 11 |
8 class AndroidAppBackend(app_backend.AppBackend): | 12 class AndroidAppBackend(app_backend.AppBackend): |
9 def __init__(self): | 13 def __init__(self, android_platform_backend, start_intent): |
10 super(AndroidAppBackend, self).__init__() | 14 super(AndroidAppBackend, self).__init__(app_type=start_intent.package) |
| 15 assert isinstance(android_platform_backend, |
| 16 android_platform_backend_module.AndroidPlatformBackend) |
| 17 self._android_platform_backend = android_platform_backend |
| 18 self._start_intent = start_intent |
| 19 self._is_running = False |
11 | 20 |
12 @property | 21 @property |
13 def pid(self): | 22 def pid(self): |
14 raise NotImplementedError | 23 raise NotImplementedError |
15 | 24 |
| 25 @property |
| 26 def _adb(self): |
| 27 return self._android_platform_backend.adb |
| 28 |
16 def Start(self): | 29 def Start(self): |
17 raise NotImplementedError | 30 """Start an Android app and wait for it to finish launching. |
| 31 |
| 32 AppStory derivations can customize the wait-for-ready-state to wait |
| 33 for a more specific event if needed. |
| 34 """ |
| 35 # TODO(slamm): check if can use "blocking=True" instead of needing to sleep. |
| 36 # If "blocking=True" does not work, switch sleep to "ps" check. |
| 37 self._adb.device().StartActivity(self._start_intent, blocking=False) |
| 38 time.sleep(9) |
| 39 self._is_running = True |
18 | 40 |
19 def Close(self): | 41 def Close(self): |
20 raise NotImplementedError | 42 self._is_running = False |
| 43 self._android_platform_backend.KillApplication(self._start_intent.package) |
21 | 44 |
22 def IsAppRunning(self): | 45 def IsAppRunning(self): |
23 raise NotImplementedError | 46 return self._is_running |
24 | 47 |
25 def GetStandardOutput(self): | 48 def GetStandardOutput(self): |
26 raise NotImplementedError | 49 raise NotImplementedError |
27 | 50 |
28 def GetStackTrace(self): | 51 def GetStackTrace(self): |
29 raise NotImplementedError | 52 raise NotImplementedError |
OLD | NEW |