1 # Copyright 2017 - The Android Open Source Project 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 15 """Runs Treble compatibility check between /system and /vendor. 16 17 One of the major goal of project Treble is to do system-only OTA across 18 major Android releases (e.g., O -> P). VINTF check is to ensure a given 19 system.img can work well on a vendor.img, including HALs versions match, 20 kernel version match, SEPolicy version match, etc. See the following link 21 for more details: 22 23 https://source.android.com/devices/architecture/vintf/ 24 """ 25 26 from gsi_util.checkers import check_result 27 from gsi_util.utils import vintf_utils 28 29 30 class VintfChecker(object): # pylint: disable=too-few-public-methods 31 """The checker to perform VINTF check between /system and /vendor.""" 32 33 # A dict to specify required VINTF checks. 34 # Each item is a tuple containing a (manifest, matrix) pair for the match 35 # check. 36 _REQUIRED_CHECKS = { 37 'Framework manifest match': ('/system/manifest.xml', 38 '/vendor/compatibility_matrix.xml'), 39 'Device manifest match': ('/vendor/manifest.xml', 40 '/system/compatibility_matrix.xml'), 41 } 42 43 def __init__(self, file_accessor): 44 """Inits a VINTF checker with a given file_accessor. 45 46 Args: 47 file_accessor: Provides file access to get files that are installed 48 on /system and /vendor partition of a device. 49 """ 50 self._file_accessor = file_accessor 51 52 def check(self): 53 """Performs the Treble VINTF compatibility check. 54 55 Returns: 56 A list of check_result.CheckResultItem() tuples. 57 58 Raises: 59 RuntimeError: An error occurred when accessing required files. 60 """ 61 check_result_items = [] 62 63 for title in self._REQUIRED_CHECKS: 64 manifest_filename, matrix_filename = self._REQUIRED_CHECKS[title] 65 66 with self._file_accessor.prepare_multi_files( 67 [manifest_filename, matrix_filename]) as [manifest, matrix]: 68 if not manifest: 69 raise RuntimeError('Failed to open: {}'.format(manifest_filename)) 70 if not matrix: 71 raise RuntimeError('Failed to open: {}'.format(matrix_filename)) 72 73 # Runs the check item and appends the result. 74 result_ok, stderr = vintf_utils.checkvintf(manifest, matrix) 75 check_result_items.append( 76 check_result.CheckResultItem(title, result_ok, stderr)) 77 78 return check_result_items 79