1#!/usr/bin/env python 2# 3# Copyright (C) 2016 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# 17 18import logging 19import time 20 21from vts.runners.host import asserts 22from vts.runners.host import test_runner 23from vts.testcases.template.hal_hidl_host_test import hal_hidl_host_test 24 25PASSTHROUGH_MODE_KEY = "passthrough_mode" 26 27 28class NfcHidlBasicTest(hal_hidl_host_test.HalHidlHostTest): 29 """A simple testcase for the NFC HIDL HAL.""" 30 31 TEST_HAL_SERVICES = {"android.hardware.nfc@1.0::INfc"} 32 def setUpClass(self): 33 """Creates a mirror and turns on the framework-layer VIBRATOR service.""" 34 super(NfcHidlBasicTest, self).setUpClass() 35 36 self.shell.Execute("svc nfc disable") # Turn off 37 time.sleep(5) 38 39 self.getUserParams(opt_param_names=[PASSTHROUGH_MODE_KEY]) 40 if getattr(self, PASSTHROUGH_MODE_KEY, True): 41 self.shell.Execute( 42 "setprop vts.hal.vts.hidl.get_stub true") 43 else: 44 self.shell.Execute( 45 "setprop vts.hal.vts.hidl.get_stub false") 46 47 self.dut.hal.InitHidlHal( 48 target_type="nfc", 49 target_basepaths=self.dut.libPaths, 50 target_version=1.0, 51 target_package="android.hardware.nfc", 52 target_component_name="INfc", 53 bits=int(self.abi_bitness)) 54 55 def tearDownClass(self): 56 """Turns off the framework-layer NFC service.""" 57 # Ideally, we would want to store the nfc service's state before 58 # turning that off in setUpClass and restore the original state. 59 if not self.isSkipAllTests(): 60 self.shell.Execute("svc nfc disable") # make sure it's off 61 super(NfcHidlBasicTest, self).tearDownClass() 62 63 def testBase(self): 64 """A simple test case which just calls each registered function.""" 65 # TODO: extend to make realistic testcases 66 # For example, call after CORE_INIT_RSP is received. 67 # result = self.dut.hal.nfc.coreInitialized([1]) 68 # logging.info("coreInitialized result: %s", result) 69 70 def send_event(NfcEvent, NfcStatus): 71 logging.info("callback send_event") 72 logging.info("arg0 %s", NfcEvent) 73 logging.info("arg1 %s", NfcStatus) 74 75 def send_data(NfcData): 76 logging.info("callback send_data") 77 logging.info("arg0 %s", NfcData) 78 79 client_callback = self.dut.hal.nfc.GetHidlCallbackInterface( 80 "INfcClientCallback", 81 sendEvent=send_event, 82 sendData=send_data) 83 84 result = self.dut.hal.nfc.open(client_callback) 85 logging.info("open result: %s", result) 86 87 result = self.dut.hal.nfc.prediscover() 88 logging.info("prediscover result: %s", result) 89 90 result = self.dut.hal.nfc.controlGranted() 91 logging.info("controlGranted result: %s", result) 92 93 result = self.dut.hal.nfc.powerCycle() 94 logging.info("powerCycle result: %s", result) 95 96 nfc_types = self.dut.hal.nfc.GetHidlTypeInterface("types") 97 logging.info("nfc_types: %s", nfc_types) 98 99 result = self.dut.hal.nfc.write([0, 1, 2, 3, 4, 5]) 100 logging.info("write result: %s", result) 101 102 result = self.dut.hal.nfc.close() 103 logging.info("close result: %s", result) 104 105 if self.coverage.enabled: 106 self.coverage.SetCoverageData(dut=self.dut, isGlobal=True) 107 108if __name__ == "__main__": 109 test_runner.main() 110