Commit faa44a45 authored by perezju's avatar perezju Committed by Commit bot

[Telemetry] Small fixes in android_app_backend

This CL includes two fixes:
- Ensure the app was not running after trying to launch.
- Be more specific when matching process names for the app.

These were split off from:
https://codereview.chromium.org/1510833002/

BUG=

Review URL: https://codereview.chromium.org/1606243002

Cr-Commit-Position: refs/heads/master@{#370704}
parent 9ab3e68a
......@@ -46,8 +46,11 @@ class AndroidAppBackend(app_backend.AppBackend):
# TODO(slamm): check if the wait for "ps" check is really needed, or
# whether the "blocking=True" fall back is sufficient.
has_ready_predicate = self._is_app_ready_predicate is not None
self.device.StartActivity(self._start_intent,
blocking=not has_ready_predicate)
self.device.StartActivity(
self._start_intent,
blocking=not has_ready_predicate,
force_stop=True, # Ensure app was not running.
)
if has_ready_predicate:
util.WaitFor(is_app_ready, timeout=60)
......@@ -87,7 +90,9 @@ class AndroidAppBackend(app_backend.AppBackend):
def GetProcesses(self, process_filter=None):
if process_filter is None:
process_filter = lambda n: re.match('^' + self._default_process_name, n)
# Match process names of the form: 'process_name[:subprocess]'.
process_filter = re.compile(
'^%s(:|$)' % re.escape(self._default_process_name)).match
processes = set()
ps_output = self.platform_backend.GetPsOutput(['pid', 'name'])
......
# Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import collections
import mock
import unittest
from telemetry.internal.backends import android_app_backend
from devil.android.sdk import intent as intent_module
_FakeAndroidProcess = collections.namedtuple(
'AndroidProcess', ['app_backend', 'pid', 'name'])
class AndroidAppBackendUnittest(unittest.TestCase):
def setUp(self):
self.platform_backend = mock.Mock()
self.start_intent = intent_module.Intent(
package='com.example.my_app',
activity='com.example.my_app.LaunchMyApp')
self.app_backend = android_app_backend.AndroidAppBackend(
self.platform_backend, self.start_intent)
@mock.patch('telemetry.internal.backends.android_app_backend'
'.android_process.AndroidProcess', _FakeAndroidProcess)
def testGetProcesses(self):
# Only processes belonging to 'com.example.my_app' should match.
self.platform_backend.GetPsOutput.return_value = [
['1111', 'com.example.my_app'],
['2222', 'com.example.my_appointments_helper'],
['3333', 'com.example.my_app:service'],
['4444', 'com.example.some_other_app'],
['5555', 'com_example_my_app'],
]
process_pids = set(p.pid for p in self.app_backend.GetProcesses())
self.assertEquals(process_pids, set(['1111', '3333']))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment