OLD | NEW |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 import logging | 5 import logging |
6 import time | 6 import time |
7 | 7 |
8 from devil.android.sdk import keyevent | 8 from devil.android.sdk import keyevent |
9 | 9 |
10 import py_utils | 10 import py_utils |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 seconds: The number of seconds to wait. | 63 seconds: The number of seconds to wait. |
64 """ | 64 """ |
65 time.sleep(seconds) | 65 time.sleep(seconds) |
66 | 66 |
67 def InputText(self, string): | 67 def InputText(self, string): |
68 """Convert the characters of the string into key events and send to device. | 68 """Convert the characters of the string into key events and send to device. |
69 | 69 |
70 Args: | 70 Args: |
71 string: The string to send to the device. | 71 string: The string to send to the device. |
72 """ | 72 """ |
73 self._platform_backend.device.RunShellCommand( | 73 # Spaces should be input as keyevents since 'input text <text>' does not |
74 ['input', 'text', string], check_return=True) | 74 # work with space. Pass space character to account for strings with multiple |
| 75 # spaces. |
| 76 words = string.split(' ') |
| 77 for i in range(0, len(words)): |
| 78 if i is not 0: |
| 79 self.InputKeyEvent(keyevent.KEYCODE_SPACE) |
| 80 self._platform_backend.device.RunShellCommand( |
| 81 ['input', 'text', words[i]], check_return=True) |
75 | 82 |
76 def InputKeyEvent(self, keycode): | 83 def InputKeyEvent(self, keycode): |
77 """Send a single key input to the device. | 84 """Send a single key input to the device. |
78 | 85 |
79 See the devil.android.sdk.keyevent module for suitable keycode values. | 86 See the devil.android.sdk.keyevent module for suitable keycode values. |
80 | 87 |
81 Args: | 88 Args: |
82 keycode: A key code number that will be sent to the device. | 89 keycode: A key code number that will be sent to the device. |
83 """ | 90 """ |
84 self._platform_backend.device.SendKeyEvent(keycode) | 91 self._platform_backend.device.SendKeyEvent(keycode) |
(...skipping 13 matching lines...) Expand all Loading... |
98 """Perform a swipe input. | 105 """Perform a swipe input. |
99 | 106 |
100 Args: | 107 Args: |
101 left_start_coord: The horizontal starting coordinate of the gesture | 108 left_start_coord: The horizontal starting coordinate of the gesture |
102 top_start_coord: The vertical starting coordinate of the gesture | 109 top_start_coord: The vertical starting coordinate of the gesture |
103 left_end_coord: The horizontal ending coordinate of the gesture | 110 left_end_coord: The horizontal ending coordinate of the gesture |
104 top_end_coord: The vertical ending coordinate of the gesture | 111 top_end_coord: The vertical ending coordinate of the gesture |
105 duration: The length of time of the swipe in milliseconds | 112 duration: The length of time of the swipe in milliseconds |
106 """ | 113 """ |
107 cmd = ['input', 'swipe'] | 114 cmd = ['input', 'swipe'] |
108 cmd.expand(str(x) for x in (left_start_coord, top_start_coord, | 115 cmd.extend(str(x) for x in (left_start_coord, top_start_coord, |
109 left_end_coord, top_end_coord, duration)) | 116 left_end_coord, top_end_coord, duration)) |
110 self._platform_backend.device.RunShellCommand(cmd, check_return=True) | 117 self._platform_backend.device.RunShellCommand(cmd, check_return=True) |
111 | 118 |
112 def InputPress(self): | 119 def InputPress(self): |
113 """Perform a press input.""" | 120 """Perform a press input.""" |
114 self._platform_backend.device.RunShellCommand( | 121 self._platform_backend.device.RunShellCommand( |
115 ['input', 'press'], check_return=True) | 122 ['input', 'press'], check_return=True) |
116 | 123 |
117 def InputRoll(self, dx, dy): | 124 def InputRoll(self, dx, dy): |
118 """Perform a roll input. This sends a simple zero-pressure move event. | 125 """Perform a roll input. This sends a simple zero-pressure move event. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 def is_screen_unlocked(): | 166 def is_screen_unlocked(): |
160 return not self._platform_backend.IsScreenLocked() | 167 return not self._platform_backend.IsScreenLocked() |
161 | 168 |
162 if self._platform_backend.IsScreenLocked(): | 169 if self._platform_backend.IsScreenLocked(): |
163 self.InputKeyEvent(keyevent.KEYCODE_MENU) | 170 self.InputKeyEvent(keyevent.KEYCODE_MENU) |
164 else: | 171 else: |
165 logging.warning('Screen not locked when expected.') | 172 logging.warning('Screen not locked when expected.') |
166 return | 173 return |
167 | 174 |
168 py_utils.WaitFor(is_screen_unlocked, 5) | 175 py_utils.WaitFor(is_screen_unlocked, 5) |
OLD | NEW |