1 #!/usr/bin/env python 2 # 3 # Copyright (C) 2017 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 18 import logging 19 20 from vts.runners.host import asserts 21 from vts.runners.host import base_test 22 from vts.runners.host import keys 23 from vts.runners.host import test_runner 24 from vts.utils.python.precondition import precondition_utils 25 26 27 class VtsHalGnssV1_0HostTest(base_test.BaseTestClass): 28 """A simple testcase for the GNSS HIDL HAL.""" 29 SYSPROP_GETSTUB = "vts.hal.vts.hidl.get_stub" 30 31 def setUpClass(self): 32 """Creates a mirror and turns on the framework-layer GNSS service.""" 33 self.dut = self.android_devices[0] 34 35 self.passthrough_mode = self.getUserParam( 36 keys.ConfigKeys.IKEY_PASSTHROUGH_MODE, default_value=True) 37 38 self.dut.shell.Execute("setenforce 0") # SELinux permissive mode 39 if not precondition_utils.CanRunHidlHalTest( 40 self, self.dut, self.dut.shell.default): 41 self._skip_all_testcases = True 42 return 43 44 mode = "true" if self.passthrough_mode else "false" 45 self.dut.shell.Execute( 46 "setprop %s %s" % (self.SYSPROP_GETSTUB, mode)) 47 48 self.dut.hal.InitHidlHal( 49 target_type="gnss", 50 target_basepaths=self.dut.libPaths, 51 target_version=1.0, 52 target_package="android.hardware.gnss", 53 target_component_name="IGnss", 54 bits=int(self.abi_bitness)) 55 56 if self.coverage.enabled: 57 self.coverage.LoadArtifacts() 58 self.coverage.InitializeDeviceCoverage(self._dut) 59 60 def SetCallback(self): 61 """Utility function to set the callbacks.""" 62 63 def gnssLocationCb(location): 64 logging.info("callback gnssLocationCb") 65 66 def gnssStatusCb(status): 67 logging.info("callback gnssStatusCb") 68 69 def gnssSvStatusCb(svInfo): 70 logging.info("callback gnssSvStatusCb") 71 72 def gnssNmeaCb(timestamp, nmea): 73 logging.info("callback gnssNmeaCb") 74 75 def gnssSetCapabilitesCb(capabilities): 76 logging.info("callback gnssSetCapabilitesCb") 77 78 def gnssAcquireWakelockCb(): 79 logging.info("callback gnssAcquireWakelockCb") 80 81 def gnssReleaseWakelockCb(): 82 logging.info("callback gnssReleaseWakelockCb") 83 84 def gnssRequestTimeCb(): 85 logging.info("callback gnssRequestTimeCb") 86 87 def gnssSetSystemInfoCb(info): 88 logging.info("callback gnssSetSystemInfoCb") 89 90 client_callback = self.dut.hal.gnss.GetHidlCallbackInterface( 91 "IGnssCallback", 92 gnssLocationCb=gnssLocationCb, 93 gnssStatusCb=gnssStatusCb, 94 gnssSvStatusCb=gnssSvStatusCb, 95 gnssNmeaCb=gnssNmeaCb, 96 gnssSetCapabilitesCb=gnssSetCapabilitesCb, 97 gnssAcquireWakelockCb=gnssAcquireWakelockCb, 98 gnssReleaseWakelockCb=gnssReleaseWakelockCb, 99 gnssRequestTimeCb=gnssRequestTimeCb, 100 gnssSetSystemInfoCb=gnssSetSystemInfoCb) 101 102 result = self.dut.hal.gnss.setCallback(client_callback) 103 logging.info("setCallback result: %s", result) 104 105 def testExtensionPresence(self): 106 """A test case which checks whether each extension exists.""" 107 self.SetCallback() 108 109 nested_interface = self.dut.hal.gnss.getExtensionAGnssRil() 110 if not nested_interface: 111 logging.info("getExtensionAGnssRil returned None") 112 else: 113 result = nested_interface.updateNetworkAvailability(False, "test") 114 logging.info("updateNetworkAvailability result: %s", result) 115 116 nested_interface = self.dut.hal.gnss.getExtensionGnssGeofencing() 117 if not nested_interface: 118 logging.info("getExtensionGnssGeofencing returned None") 119 120 nested_interface = self.dut.hal.gnss.getExtensionAGnss() 121 if not nested_interface: 122 logging.info("getExtensionAGnss returned None") 123 else: 124 result = nested_interface.dataConnClosed() 125 logging.info("dataConnClosed result: %s", result) 126 127 nested_interface = self.dut.hal.gnss.getExtensionGnssNi() 128 if not nested_interface: 129 logging.info("getExtensionGnssNi returned None") 130 131 nested_interface = self.dut.hal.gnss.getExtensionGnssMeasurement() 132 if not nested_interface: 133 logging.info("getExtensionGnssMeasurement returned None") 134 135 nested_interface = self.dut.hal.gnss.getExtensionXtra() 136 if not nested_interface: 137 logging.info("getExtensionXtra returned None") 138 139 nested_interface = self.dut.hal.gnss.getExtensionGnssConfiguration() 140 if not nested_interface: 141 logging.info("getExtensionGnssConfiguration returned None") 142 143 nested_interface = self.dut.hal.gnss.getExtensionGnssBatching() 144 if not nested_interface: 145 logging.info("getExtensionGnssBatching returned None") 146 147 def testExtensionPresenceForUnimplementedOnes(self): 148 """A test case which checks whether each extension exists. 149 150 Separate test case for known failures. 151 """ 152 self.SetCallback() 153 154 nested_interface = self.dut.hal.gnss.getExtensionGnssNavigationMessage() 155 if not nested_interface: 156 logging.error("ExtensionGnssNavigationMessage not implemented") 157 158 nested_interface = self.dut.hal.gnss.getExtensionGnssDebug() 159 if not nested_interface: 160 logging.error("ExtensionGnssDebug not implemented") 161 162 if __name__ == "__main__": 163 test_runner.main() 164