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