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. Pass space character to account for |
rnephew (Reviews Here)
2017/04/26 00:28:25
Can this we slightly reworded? I dont think its cu
ssid
2017/04/26 00:36:46
Sorry for not being clear. The input text command
rnephew (Reviews Here)
2017/04/26 01:01:26
I dont think the added code complexity for gating
ssid
2017/04/26 01:12:45
Done.
| |
74 ['input', 'text', string], check_return=True) | 74 # strings with multiple spaces. |
75 words = string.split(' ') | |
76 for i in range(0, len(words)): | |
77 if i is not 0: | |
78 self.InputKeyEvent(keyevent.KEYCODE_SPACE) | |
79 self._platform_backend.device.RunShellCommand( | |
80 ['input', 'text', words[i]], check_return=True) | |
75 | 81 |
76 def InputKeyEvent(self, keycode): | 82 def InputKeyEvent(self, keycode): |
77 """Send a single key input to the device. | 83 """Send a single key input to the device. |
78 | 84 |
79 See the devil.android.sdk.keyevent module for suitable keycode values. | 85 See the devil.android.sdk.keyevent module for suitable keycode values. |
80 | 86 |
81 Args: | 87 Args: |
82 keycode: A key code number that will be sent to the device. | 88 keycode: A key code number that will be sent to the device. |
83 """ | 89 """ |
84 self._platform_backend.device.SendKeyEvent(keycode) | 90 self._platform_backend.device.SendKeyEvent(keycode) |
(...skipping 13 matching lines...) Expand all Loading... | |
98 """Perform a swipe input. | 104 """Perform a swipe input. |
99 | 105 |
100 Args: | 106 Args: |
101 left_start_coord: The horizontal starting coordinate of the gesture | 107 left_start_coord: The horizontal starting coordinate of the gesture |
102 top_start_coord: The vertical starting coordinate of the gesture | 108 top_start_coord: The vertical starting coordinate of the gesture |
103 left_end_coord: The horizontal ending coordinate of the gesture | 109 left_end_coord: The horizontal ending coordinate of the gesture |
104 top_end_coord: The vertical ending coordinate of the gesture | 110 top_end_coord: The vertical ending coordinate of the gesture |
105 duration: The length of time of the swipe in milliseconds | 111 duration: The length of time of the swipe in milliseconds |
106 """ | 112 """ |
107 cmd = ['input', 'swipe'] | 113 cmd = ['input', 'swipe'] |
108 cmd.expand(str(x) for x in (left_start_coord, top_start_coord, | 114 cmd.extend(str(x) for x in (left_start_coord, top_start_coord, |
109 left_end_coord, top_end_coord, duration)) | 115 left_end_coord, top_end_coord, duration)) |
110 self._platform_backend.device.RunShellCommand(cmd, check_return=True) | 116 self._platform_backend.device.RunShellCommand(cmd, check_return=True) |
111 | 117 |
112 def InputPress(self): | 118 def InputPress(self): |
113 """Perform a press input.""" | 119 """Perform a press input.""" |
114 self._platform_backend.device.RunShellCommand( | 120 self._platform_backend.device.RunShellCommand( |
115 ['input', 'press'], check_return=True) | 121 ['input', 'press'], check_return=True) |
116 | 122 |
117 def InputRoll(self, dx, dy): | 123 def InputRoll(self, dx, dy): |
118 """Perform a roll input. This sends a simple zero-pressure move event. | 124 """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(): | 165 def is_screen_unlocked(): |
160 return not self._platform_backend.IsScreenLocked() | 166 return not self._platform_backend.IsScreenLocked() |
161 | 167 |
162 if self._platform_backend.IsScreenLocked(): | 168 if self._platform_backend.IsScreenLocked(): |
163 self.InputKeyEvent(keyevent.KEYCODE_MENU) | 169 self.InputKeyEvent(keyevent.KEYCODE_MENU) |
164 else: | 170 else: |
165 logging.warning('Screen not locked when expected.') | 171 logging.warning('Screen not locked when expected.') |
166 return | 172 return |
167 | 173 |
168 py_utils.WaitFor(is_screen_unlocked, 5) | 174 py_utils.WaitFor(is_screen_unlocked, 5) |
OLD | NEW |