• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 base_test
23from vts.runners.host import test_runner
24from vts.utils.python.controllers import android_device
25from vts.utils.python.precondition import precondition_utils
26
27PASSTHROUGH_MODE_KEY = "passthrough_mode"
28
29
30class NfcHidlBasicTest(base_test.BaseTestClass):
31    """A simple testcase for the NFC HIDL HAL."""
32
33    def setUpClass(self):
34        """Creates a mirror and turns on the framework-layer NFC service."""
35        self.dut = self.registerController(android_device)[0]
36
37        self.getUserParams(opt_param_names=[PASSTHROUGH_MODE_KEY])
38
39        self.dut.shell.InvokeTerminal("one")
40        self.dut.shell.one.Execute("setenforce 0")  # SELinux permissive mode
41        if not precondition_utils.CanRunHidlHalTest(
42            self, self.dut, self.dut.shell.one):
43            self._skip_all_testcases = True
44            return
45
46        self.dut.shell.one.Execute("svc nfc disable")  # Turn off
47        time.sleep(5)
48
49        if getattr(self, PASSTHROUGH_MODE_KEY, True):
50            self.dut.shell.one.Execute(
51                "setprop vts.hal.vts.hidl.get_stub true")
52        else:
53            self.dut.shell.one.Execute(
54                "setprop vts.hal.vts.hidl.get_stub false")
55
56        self.dut.hal.InitHidlHal(
57            target_type="nfc",
58            target_basepaths=self.dut.libPaths,
59            target_version=1.0,
60            target_package="android.hardware.nfc",
61            target_component_name="INfc",
62            bits=int(self.abi_bitness))
63
64        if self.coverage.enabled:
65            self.coverage.LoadArtifacts()
66            self.coverage.InitializeDeviceCoverage(self._dut)
67
68    def tearDownClass(self):
69        """Turns off the framework-layer NFC service."""
70        # Ideally, we would want to store the nfc service's state before
71        # turning that off in setUpClass and restore the original state.
72        if not self._skip_all_testcases:
73            self.dut.shell.one.Execute("svc nfc disable")  # make sure it's off
74
75    def testBase(self):
76        """A simple test case which just calls each registered function."""
77        # TODO: extend to make realistic testcases
78        # For example, call after CORE_INIT_RSP is received.
79        # result = self.dut.hal.nfc.coreInitialized([1])
80        # logging.info("coreInitialized result: %s", result)
81
82        def send_event(NfcEvent, NfcStatus):
83            logging.info("callback send_event")
84            logging.info("arg0 %s", NfcEvent)
85            logging.info("arg1 %s", NfcStatus)
86
87        def send_data(NfcData):
88            logging.info("callback send_data")
89            logging.info("arg0 %s", NfcData)
90
91        client_callback = self.dut.hal.nfc.GetHidlCallbackInterface(
92            "INfcClientCallback",
93            sendEvent=send_event,
94            sendData=send_data)
95
96        result = self.dut.hal.nfc.open(client_callback)
97        logging.info("open result: %s", result)
98
99        result = self.dut.hal.nfc.prediscover()
100        logging.info("prediscover result: %s", result)
101
102        result = self.dut.hal.nfc.controlGranted()
103        logging.info("controlGranted result: %s", result)
104
105        result = self.dut.hal.nfc.powerCycle()
106        logging.info("powerCycle result: %s", result)
107
108        nfc_types = self.dut.hal.nfc.GetHidlTypeInterface("types")
109        logging.info("nfc_types: %s", nfc_types)
110
111        result = self.dut.hal.nfc.write([0, 1, 2, 3, 4, 5])
112        logging.info("write result: %s", result)
113
114        result = self.dut.hal.nfc.close()
115        logging.info("close result: %s", result)
116
117        if self.coverage.enabled:
118            self.coverage.SetCoverageData(dut=self.dut, isGlobal=True)
119
120if __name__ == "__main__":
121    test_runner.main()
122