1import os 2import tempfile 3from xml.etree import ElementTree 4 5 6def set_supl_over_wifi_state(ad, turn_on): 7 """Enable / Disable supl over wifi features 8 9 Modify the gps xml file: /vendor/etc/gnss/gps.xml 10 Args: 11 ad: AndroidDevice object 12 turn_on: (bool) True -> enable / False -> disable 13 """ 14 ad.adb.remount() 15 folder = tempfile.mkdtemp() 16 xml_path_on_host = os.path.join(folder, "gps.xml") 17 xml_path_on_device = "/vendor/etc/gnss/gps.xml" 18 ad.pull_files(xml_path_on_device, xml_path_on_host) 19 20 # register namespance to aviod adding ns0 into xml attributes 21 ElementTree.register_namespace("", "http://www.glpals.com/") 22 xml_tree = ElementTree.parse(xml_path_on_host) 23 root = xml_tree.getroot() 24 for node in root: 25 if "hal" in node.tag: 26 if turn_on: 27 _enable_supl_over_wifi(ad, node) 28 else: 29 _disable_supl_over_wifi(ad, node) 30 xml_tree.write(xml_path_on_host, xml_declaration=True, encoding="utf-8", method="xml") 31 ad.push_system_file(xml_path_on_host, xml_path_on_device) 32 33 34def _enable_supl_over_wifi(ad, node): 35 """Enable supl over wifi 36 Detail setting: 37 <hal 38 SuplDummyCellInfo="true" 39 SuplUseApn="false" 40 SuplUseApnNI="true" 41 SuplUseFwCellInfo="false" 42 /> 43 Args: 44 ad: AndroidDevice object 45 node: ElementTree node 46 """ 47 ad.log.info("Enable SUPL over wifi") 48 attributes = {"SuplDummyCellInfo": "true", "SuplUseApn": "false", "SuplUseApnNI": "true", 49 "SuplUseFwCellInfo": "false"} 50 for key, value in attributes.items(): 51 node.set(key, value) 52 53 54def _disable_supl_over_wifi(ad, node): 55 """Disable supl over wifi 56 Detail setting: 57 <hal 58 SuplUseApn="true" 59 /> 60 Remove following setting 61 SuplDummyCellInfo="true" 62 SuplUseApnNI="true" 63 SuplUseFwCellInfo="false" 64 Args: 65 ad: AndroidDevice object 66 node: ElementTree node 67 """ 68 ad.log.info("Disable SUPL over wifi") 69 for attri in ["SuplDummyCellInfo", "SuplUseApnNI", "SuplUseFwCellInfo"]: 70 node.attrib.pop(attri, None) 71 node.set("SuplUseApn", "true") 72