OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 """Manages intents and associated information. | 5 """Manages intents and associated information. |
6 | 6 |
7 This is generally intended to be used with functions that calls Android's | 7 This is generally intended to be used with functions that calls Android's |
8 Am command. | 8 Am command. |
9 """ | 9 """ |
10 | 10 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 return self._extras | 70 return self._extras |
71 | 71 |
72 @property | 72 @property |
73 def flags(self): | 73 def flags(self): |
74 return self._flags | 74 return self._flags |
75 | 75 |
76 @property | 76 @property |
77 def package(self): | 77 def package(self): |
78 return self._package | 78 return self._package |
79 | 79 |
| 80 @property |
| 81 def am_args(self): |
| 82 """Returns the intent as a list of arguments for the activity manager. |
| 83 |
| 84 For details refer to the specification at: |
| 85 - http://developer.android.com/tools/help/adb.html#IntentSpec |
| 86 """ |
| 87 args = [] |
| 88 if self.action: |
| 89 args.extend(['-a', self.action]) |
| 90 if self.data: |
| 91 args.extend(['-d', self.data]) |
| 92 if self.category: |
| 93 args.extend(arg for cat in self.category for arg in ('-c', cat)) |
| 94 if self.component: |
| 95 args.extend(['-n', self.component]) |
| 96 if self.flags: |
| 97 args.extend(['-f', self.flags]) |
| 98 if self.extras: |
| 99 for key, value in self.extras.iteritems(): |
| 100 if value is None: |
| 101 args.extend(['--esn', key]) |
| 102 elif isinstance(value, str): |
| 103 args.extend(['--es', key, value]) |
| 104 elif isinstance(value, bool): |
| 105 args.extend(['--ez', key, str(value)]) |
| 106 elif isinstance(value, int): |
| 107 args.extend(['--ei', key, str(value)]) |
| 108 elif isinstance(value, float): |
| 109 args.extend(['--ef', key, str(value)]) |
| 110 else: |
| 111 raise NotImplementedError( |
| 112 'Intent does not know how to pass %s extras' % type(value)) |
| 113 return args |
OLD | NEW |