1#!/usr/bin/env python3 2# 3# Copyright 2020 - The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17import time 18 19from acts import asserts 20from acts import signals 21from acts.base_test import BaseTestClass 22from acts.libs.proc.job import Error 23 24TEST_TIME_SECONDS = 5 25TEST_POLL_TIME_SECONDS = 0.1 26 27 28class TouchTest(BaseTestClass): 29 def setup_class(self): 30 super().setup_class() 31 self.fd = self.fuchsia_devices[0] 32 33 def test_touch_reports(self): 34 """Prints touch events for the next 5 seconds. 35 36 This test requires a 'touch_test_params' object to be specified in the 37 device config. touch_test_params will be used by the facade to find the 38 touch device, and may include 'vendor_id' and 'product_id' values. 39 """ 40 asserts.skip_if('touch_tests_params' not in self.user_params, 41 'touch_tests_params not specified in the config') 42 43 # Make a call to the facade to get it to establish a connection to the 44 # touch device. This ensures that the first second of touch events don't 45 # get missed. 46 result = self.fd.input_report_lib.getDescriptor( 47 **self.user_params['touch_tests_params']) 48 49 self.log.info('Printing touch events for the next %d seconds...' % 50 TEST_TIME_SECONDS) 51 52 end_time = time.time() + TEST_TIME_SECONDS 53 while time.time() < end_time: 54 time.sleep(TEST_POLL_TIME_SECONDS) 55 56 result = self.fd.input_report_lib.getReports( 57 **self.user_params['touch_tests_params']) 58 asserts.assert_true(result['error'] is None, 59 'GetReports failed: %s' % result['error']) 60 61 for event in result['result']: 62 contacts = event['touch']['contacts'] 63 touch = ', '.join([ 64 '(%d, %d)' % (t['position_x'], t['position_y']) 65 for t in event['touch']['contacts'] 66 ]) or '(none)' 67 self.log.info('touch event @ %d: %s' % 68 (event['event_time'], touch)) 69