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 FormatVndkPath(pattern, bitness, version=""): 48 """Formats a VNDK path. 49 50 Args: 51 pattern: The path pattern containing {LIB} and {VER}. 52 bitness: A string or an integer, 32 or 64. 53 version: A string, the VNDK version. 54 55 Returns: 56 A string, the formatted path. 57 """ 58 return pattern.format( 59 LIB=("lib64" if str(bitness) == "64" else "lib"), 60 VER=("-" + version if version else "")) 61 62 63def GetVndkCoreDirectory(bitness, version): 64 """Returns the path to VNDK-core directory on device. 65 66 Args: 67 bitness: A string or an integer, 32 or 64. 68 version: A string, the VNDK version. 69 70 Returns: 71 A string, the path to VNDK-core directory. 72 """ 73 return FormatVndkPath("/system/{LIB}/vndk{VER}", bitness, version) 74 75 76def GetVndkSpDirectory(bitness, version): 77 """Returns the path to VNDK-SP directory on device. 78 79 Args: 80 bitness: A string or an integer, 32 or 64. 81 version: A string, the VNDK version. 82 83 Returns: 84 A string, the path to VNDK-SP directory. 85 """ 86 return FormatVndkPath("/system/{LIB}/vndk-sp{VER}", bitness, version) 87 88 89def GetVndkExtDirectories(bitness): 90 """Returns the paths to VNDK extension directories on device. 91 92 Args: 93 bitness: A string or an integer, 32 or 64. 94 95 Returns: 96 A list of strings, the paths to VNDK extension directories. 97 """ 98 return [FormatVndkPath("/odm/{LIB}/vndk", bitness), 99 FormatVndkPath("/vendor/{LIB}/vndk", bitness)] 100 101 102def GetVndkSpExtDirectories(bitness): 103 """Returns the paths to VNDK-SP extension directories on device. 104 105 Args: 106 bitness: A string or an integer, 32 or 64. 107 108 Returns: 109 A list of strings, the paths to VNDK-SP extension directories. 110 """ 111 return [FormatVndkPath("/odm/{LIB}/vndk-sp", bitness), 112 FormatVndkPath("/vendor/{LIB}/vndk-sp", bitness)] 113