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.
12 BUILD_ANDROID_DIR
= os
.path
.join(os
.path
.dirname(__file__
),
17 sys
.path
.append(BUILD_ANDROID_DIR
)
18 from pylib
import constants
19 from pylib
import flag_changer
20 from pylib
.device
import device_errors
21 from pylib
.device
import device_utils
22 from pylib
.device
import intent
25 DEFAULT_BROWSER
= 'chrome'
28 ACTION_PACKAGE
= 'org.chromium.base'
30 'moderate' : ACTION_PACKAGE
+ '.ACTION_TRIM_MEMORY_MODERATE',
31 'critical' : ACTION_PACKAGE
+ '.ACTION_TRIM_MEMORY_RUNNING_CRITICAL',
32 'complete' : ACTION_PACKAGE
+ '.ACTION_TRIM_MEMORY'
34 ACTION_LOW
= ACTION_PACKAGE
+ '.ACTION_LOW_MEMORY'
36 # Command Line Constants
37 ENABLE_TEST_INTENTS_FLAG
= '--enable-test-intents'
40 option_parser
= optparse
.OptionParser()
41 option_parser
.add_option('-l',
43 help='Simulate Activity#onLowMemory()',
45 option_parser
.add_option('-t',
47 help=('Simulate Activity#onTrimMemory(...) with ' +
48 ', '.join(ACTION_TRIM
.keys())),
50 option_parser
.add_option('-b',
52 default
=DEFAULT_BROWSER
,
53 help=('Which browser to use. One of ' +
54 ', '.join(constants
.PACKAGE_INFO
.keys()) +
55 ' [default: %default]'),
58 (options
, args
) = option_parser
.parse_args(argv
)
61 print 'Unknown argument: ', args
[1:]
62 option_parser
.print_help()
65 if options
.low
and options
.trim
:
66 option_parser
.error('options --low and --trim are mutually exclusive')
68 if not options
.low
and not options
.trim
:
69 option_parser
.print_help()
75 elif options
.trim
in ACTION_TRIM
.keys():
76 action
= ACTION_TRIM
[options
.trim
]
79 option_parser
.print_help()
82 if not options
.browser
in constants
.PACKAGE_INFO
.keys():
83 option_parser
.error('Unknown browser option ' + options
.browser
)
85 package_info
= constants
.PACKAGE_INFO
[options
.browser
]
87 package
= package_info
.package
88 activity
= package_info
.activity
90 devices
= device_utils
.DeviceUtils
.HealthyDevices()
92 raise device_errors
.NoDevicesError()
93 elif len(devices
) > 1:
94 logging
.warning('Multiple devices attached. Using %s.', str(devices
[0]))
99 except device_errors
.CommandFailedError
as e
:
100 # Try to change the flags and start the activity anyway.
101 # TODO(jbudorick) Handle this exception appropriately after interface
102 # conversions are finished.
103 logging
.error(str(e
))
104 flags
= flag_changer
.FlagChanger(device
, package_info
.cmdline_file
)
105 if ENABLE_TEST_INTENTS_FLAG
not in flags
.Get():
106 flags
.AddFlags([ENABLE_TEST_INTENTS_FLAG
])
108 device
.StartActivity(intent
.Intent(package
=package
, activity
=activity
,
111 if __name__
== '__main__':
112 sys
.exit(main(sys
.argv
))