blob: 82fe2206dfd252bf04f9cd05ceaca8a569f578b0 [file] [log] [blame]
[email protected]9aa79e362013-10-07 20:49:041#!/usr/bin/env python
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
4# found in the LICENSE file.
5
6import collections
7import optparse
8import os
9import sys
10
11BUILD_ANDROID_DIR = os.path.join(os.path.dirname(__file__),
12 os.pardir,
13 os.pardir,
14 'build',
15 'android')
16sys.path.append(BUILD_ANDROID_DIR)
[email protected]9aa79e362013-10-07 20:49:0417from pylib import constants
18from pylib import flag_changer
[email protected]f1ed1c92014-04-29 09:58:0219from pylib.device import device_utils
[email protected]9aa79e362013-10-07 20:49:0420
21# Browser Constants
22DEFAULT_BROWSER = 'chrome'
23
24# Action Constants
25ACTION_PACKAGE = 'org.chromium.base'
26ACTION_TRIM = {
27 'moderate' : ACTION_PACKAGE + '.ACTION_TRIM_MEMORY_MODERATE',
28 'critical' : ACTION_PACKAGE + '.ACTION_TRIM_MEMORY_RUNNING_CRITICAL',
29 'complete' : ACTION_PACKAGE + '.ACTION_TRIM_MEMORY'
30}
31ACTION_LOW = ACTION_PACKAGE + '.ACTION_LOW_MEMORY'
32
33# Command Line Constants
34ENABLE_TEST_INTENTS_FLAG = '--enable-test-intents'
35
36def main(argv):
37 option_parser = optparse.OptionParser()
38 option_parser.add_option('-l',
39 '--low',
40 help='Simulate Activity#onLowMemory()',
41 action='store_true')
42 option_parser.add_option('-t',
43 '--trim',
44 help=('Simulate Activity#onTrimMemory(...) with ' +
45 ', '.join(ACTION_TRIM.keys())),
46 type='string')
47 option_parser.add_option('-b',
48 '--browser',
49 default=DEFAULT_BROWSER,
50 help=('Which browser to use. One of ' +
51 ', '.join(constants.PACKAGE_INFO.keys()) +
52 ' [default: %default]'),
53 type='string')
54
55 (options, args) = option_parser.parse_args(argv)
56
57 if len(args) > 1:
58 print 'Unknown argument: ', args[1:]
59 option_parser.print_help()
60 sys.exit(1)
61
62 if options.low and options.trim:
63 option_parser.error('options --low and --trim are mutually exclusive')
64
65 if not options.low and not options.trim:
66 option_parser.print_help()
67 sys.exit(1)
68
69 action = None
70 if options.low:
71 action = ACTION_LOW
72 elif options.trim in ACTION_TRIM.keys():
73 action = ACTION_TRIM[options.trim]
74
75 if action is None:
76 option_parser.print_help()
77 sys.exit(1)
78
79 if not options.browser in constants.PACKAGE_INFO.keys():
80 option_parser.error('Unknown browser option ' + options.browser)
81
82 package_info = constants.PACKAGE_INFO[options.browser]
83
84 package = package_info.package
85 activity = package_info.activity
86
[email protected]f1ed1c92014-04-29 09:58:0287 device = device_utils.DeviceUtils(None)
[email protected]9aa79e362013-10-07 20:49:0488
[email protected]f1ed1c92014-04-29 09:58:0289 device.old_interface.EnableAdbRoot()
90 flags = flag_changer.FlagChanger(device, package_info.cmdline_file)
[email protected]9aa79e362013-10-07 20:49:0491 if ENABLE_TEST_INTENTS_FLAG not in flags.Get():
92 flags.AddFlags([ENABLE_TEST_INTENTS_FLAG])
93
[email protected]f1ed1c92014-04-29 09:58:0294 device.old_interface.StartActivity(package, activity, action=action)
[email protected]9aa79e362013-10-07 20:49:0495
96if __name__ == '__main__':
97 sys.exit(main(sys.argv))