1# 2# Copyright (C) 2017 The Android Open Source Project 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# 16 17import logging 18 19from vts.utils.python.android import api 20 21 22def IsVndkRuntimeEnforced(dut): 23 """Returns whether VNDK run-time enforcement is enabled on the device. 24 25 VNDK run-time enforcement is optional in O-MR1 (API 27); mandatory after P. 26 If VNDK run-time enforcement is disabled, the system property named 27 ro.vndk.lite must be set to true. The usage of this function is to decide 28 whether to skip VNDK test cases. 29 30 Args: 31 dut: The AndroidDevice under test. 32 33 Returns: 34 A boolean, whether VNDK runtime should be enabled. 35 """ 36 api_level = dut.getLaunchApiLevel(strict=False) 37 if not api_level: 38 logging.error("Cannot get first API level. " 39 "Assume VNDK runtime to be enforced.") 40 return True 41 if api_level <= api.PLATFORM_API_LEVEL_O_MR1: 42 return not dut.vndk_lite 43 # For P-launching devices, VNDK run-time enforcement is mandatory. 44 return True 45 46 47def IsVndkRequired(dut): 48 """Returns whether the device's vendor partition requires VNDK. 49 50 VNDK libraries are moved from system to vendor partition in V version. If 51 a device does not require VNDK, it does not define ro.vndk.version. 52 53 Args: 54 dut: The AndroidDevice under test. 55 56 Returns: 57 A boolean, whether VNDK is required. 58 """ 59 return bool(dut.GetVndkVersion()) 60 61 62def IsVndkInstalledInVendor(dut): 63 """Returns whether the device's VNDK should be installed in vendor. 64 65 VNDK libraries are moved from system to vendor partition in V version. 66 VNDK 35 should be installed in vendor partiton. 67 68 Args: 69 dut: The AndroidDevice under test. 70 71 Returns: 72 A boolean, whether VNDK should be installed in vendor partition. 73 """ 74 try: 75 return int(dut.GetVndkVersion()) > 34 76 except ValueError: 77 return False 78 79 80def FormatVndkPath(pattern, bitness, version=""): 81 """Formats a VNDK path. 82 83 Args: 84 pattern: The path pattern containing {LIB} and {VER}. 85 bitness: A string or an integer, 32 or 64. 86 version: A string, the VNDK version. 87 88 Returns: 89 A string, the formatted path. 90 """ 91 return pattern.format(LIB=("lib64" if str(bitness) == "64" else "lib"), 92 VER=version) 93 94 95def GetVndkDirectory(bitness, version): 96 """Returns the path to VNDK directory on device. 97 98 Args: 99 bitness: A string or an integer, 32 or 64. 100 version: A string, the VNDK version. 101 102 Returns: 103 A string, the path to VNDK directory. 104 """ 105 return FormatVndkPath("/apex/com.android.vndk.v{VER}/{LIB}", 106 bitness, version) 107 108 109def GetVndkExtDirectories(bitness): 110 """Returns the paths to VNDK extension directories on device. 111 112 Args: 113 bitness: A string or an integer, 32 or 64. 114 115 Returns: 116 A list of strings, the paths to VNDK extension directories. 117 """ 118 return [FormatVndkPath("/odm/{LIB}/vndk", bitness), 119 FormatVndkPath("/vendor/{LIB}/vndk", bitness)] 120 121 122def GetVndkSpExtDirectories(bitness): 123 """Returns the paths to VNDK-SP extension directories on device. 124 125 Args: 126 bitness: A string or an integer, 32 or 64. 127 128 Returns: 129 A list of strings, the paths to VNDK-SP extension directories. 130 """ 131 return [FormatVndkPath("/odm/{LIB}/vndk-sp", bitness), 132 FormatVndkPath("/vendor/{LIB}/vndk-sp", bitness)] 133