1# Copyright 2017 The Chromium OS Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5"""An adapter to remotely access the input facade on DUT.""" 6 7import json 8 9 10class InputFacadeRemoteAdapter(object): 11 """This is an adapter to remotely capture the DUT's input events. 12 13 The Autotest host object representing the remote DUT, passed to this 14 class on initialization, can be accessed from its _client property. 15 16 """ 17 18 def __init__(self, remote_facade_proxy): 19 """Constructs an InputFacadeRemoteAdapter. 20 21 @param remote_facade_proxy: RemoteFacadeProxy object. 22 23 """ 24 self._proxy = remote_facade_proxy 25 26 @property 27 def _input_proxy(self): 28 """Gets the proxy to DUT input facade. 29 30 @return XML RPC proxy to DUT input facade. 31 32 """ 33 return self._proxy.input 34 35 def initialize_input_playback(self, input_type, property_file=None): 36 """Initialize for input events simulation. 37 38 @param input_type: input device either 'keyboard' or 'touchpad' etc. 39 @param property_file: Property file of device to be emulated. 40 """ 41 self._input_proxy.initialize_input_playback(input_type, property_file) 42 43 def blocking_playback_of_default_file(self, input_type, filename): 44 """Simulate event 45 46 @param input_type: input device either 'keyboard' or 'touchpad' etc. 47 @param filename: input events. 48 """ 49 self._input_proxy.blocking_playback_of_default_file(input_type, 50 filename) 51 52 def initialize_input_recorder(self, device_name, uniq=None): 53 """Initialize an input event recorder object. 54 55 @param device_name: the name of the input device to record. 56 57 """ 58 self._input_proxy.initialize_input_recorder(device_name, uniq) 59 60 def clear_input_events(self, device_name): 61 """Clear the event list. 62 63 @param device_name: the name of the input device to record. 64 65 """ 66 self._input_proxy.clear_input_events(device_name) 67 68 69 def start_input_recorder(self, device_name): 70 """Start the recording thread. 71 72 @param device_name: the name of the input device to record. 73 74 """ 75 self._input_proxy.start_input_recorder(device_name) 76 77 78 def stop_input_recorder(self, device_name): 79 """Stop the recording thread. 80 81 @param device_name: the name of the input device to record. 82 83 """ 84 self._input_proxy.stop_input_recorder(device_name) 85 86 87 def get_input_events(self, device_name): 88 """Get the bluetooth device events. 89 90 @param device_name: the name of the input device to record. 91 92 @returns: the recorded input events. 93 94 """ 95 return json.loads(self._input_proxy.get_input_events(device_name)) 96 97 98 def press_keys(self, key_list): 99 """ Simulating key press 100 101 @param key_list: A list of key strings, e.g. ['LEFTCTRL', 'F4'] 102 """ 103 self._input_proxy.press_keys(key_list) 104