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): 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) 59 60 def clear_input_events(self): 61 """Clear the event list.""" 62 self._input_proxy.clear_input_events() 63 64 65 def start_input_recorder(self): 66 """Start the recording thread.""" 67 self._input_proxy.start_input_recorder() 68 69 70 def stop_input_recorder(self): 71 """Stop the recording thread.""" 72 self._input_proxy.stop_input_recorder() 73 74 75 def get_input_events(self): 76 """Get the bluetooth device events. 77 78 @returns: the recorded input events. 79 80 """ 81 return json.loads(self._input_proxy.get_input_events()) 82 83 84 def press_keys(self, key_list): 85 """ Simulating key press 86 87 @param key_list: A list of key strings, e.g. ['LEFTCTRL', 'F4'] 88 """ 89 self._input_proxy.press_keys(key_list) 90