Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: tools/android/mempressure.py

Issue 420273006: [Android] Fix DeviceUtils.__str__ when no serial is provided. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/test/chromedriver/test/test_environment.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2013 The Chromium Authors. All rights reserved. 2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import collections 6 import collections
7 import logging 7 import logging
8 import optparse 8 import optparse
9 import os 9 import os
10 import sys 10 import sys
11 11
12 BUILD_ANDROID_DIR = os.path.join(os.path.dirname(__file__), 12 BUILD_ANDROID_DIR = os.path.join(os.path.dirname(__file__),
13 os.pardir, 13 os.pardir,
14 os.pardir, 14 os.pardir,
15 'build', 15 'build',
16 'android') 16 'android')
17 sys.path.append(BUILD_ANDROID_DIR) 17 sys.path.append(BUILD_ANDROID_DIR)
18 from pylib import android_commands
18 from pylib import constants 19 from pylib import constants
19 from pylib import flag_changer 20 from pylib import flag_changer
21 from pylib.device import device_errors
20 from pylib.device import device_utils 22 from pylib.device import device_utils
21 23
22 # Browser Constants 24 # Browser Constants
23 DEFAULT_BROWSER = 'chrome' 25 DEFAULT_BROWSER = 'chrome'
24 26
25 # Action Constants 27 # Action Constants
26 ACTION_PACKAGE = 'org.chromium.base' 28 ACTION_PACKAGE = 'org.chromium.base'
27 ACTION_TRIM = { 29 ACTION_TRIM = {
28 'moderate' : ACTION_PACKAGE + '.ACTION_TRIM_MEMORY_MODERATE', 30 'moderate' : ACTION_PACKAGE + '.ACTION_TRIM_MEMORY_MODERATE',
29 'critical' : ACTION_PACKAGE + '.ACTION_TRIM_MEMORY_RUNNING_CRITICAL', 31 'critical' : ACTION_PACKAGE + '.ACTION_TRIM_MEMORY_RUNNING_CRITICAL',
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 sys.exit(1) 80 sys.exit(1)
79 81
80 if not options.browser in constants.PACKAGE_INFO.keys(): 82 if not options.browser in constants.PACKAGE_INFO.keys():
81 option_parser.error('Unknown browser option ' + options.browser) 83 option_parser.error('Unknown browser option ' + options.browser)
82 84
83 package_info = constants.PACKAGE_INFO[options.browser] 85 package_info = constants.PACKAGE_INFO[options.browser]
84 86
85 package = package_info.package 87 package = package_info.package
86 activity = package_info.activity 88 activity = package_info.activity
87 89
88 device = device_utils.DeviceUtils(None) 90 devices = android_commands.GetAttachedDevices()
91 if not devices:
92 raise device_errors.NoDevicesError()
93 elif len(devices) > 1:
94 logging.warning('Multiple devices attached. Using %s.' % devices[0])
95 device = device_utils.DeviceUtils(devices[0])
89 96
90 try: 97 try:
91 device.EnableRoot() 98 device.EnableRoot()
92 except device_errors.CommandFailedError as e: 99 except device_errors.CommandFailedError as e:
93 # Try to change the flags and start the activity anyway. 100 # Try to change the flags and start the activity anyway.
94 # TODO(jbudorick) Handle this exception appropriately after interface 101 # TODO(jbudorick) Handle this exception appropriately after interface
95 # conversions are finished. 102 # conversions are finished.
96 logging.error(str(e)) 103 logging.error(str(e))
97 flags = flag_changer.FlagChanger(device, package_info.cmdline_file) 104 flags = flag_changer.FlagChanger(device, package_info.cmdline_file)
98 if ENABLE_TEST_INTENTS_FLAG not in flags.Get(): 105 if ENABLE_TEST_INTENTS_FLAG not in flags.Get():
99 flags.AddFlags([ENABLE_TEST_INTENTS_FLAG]) 106 flags.AddFlags([ENABLE_TEST_INTENTS_FLAG])
100 107
101 device.StartActivity(intent.Intent(package=package, activity=activity, 108 device.StartActivity(intent.Intent(package=package, activity=activity,
102 action=action)) 109 action=action))
103 110
104 if __name__ == '__main__': 111 if __name__ == '__main__':
105 sys.exit(main(sys.argv)) 112 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « chrome/test/chromedriver/test/test_environment.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698