1# Copyright 2024 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"""Check if the default camera app capture is Ultra HDR or not. 15""" 16import logging 17import os 18 19from mobly import test_runner 20 21import its_base_test 22import camera_properties_utils 23import its_device_utils 24import its_session_utils 25import ui_interaction_utils 26from snippet_uiautomator import uiautomator 27 28 29class DefaultCapturePerfClassTest(its_base_test.ItsBaseTest): 30 """Checks if the default camera capture is Ultra HDR or not. 31 32 Test default camera capture is Ultra HDR for VIC performance class as 33 specified in CDD. 34 35 [2.2.7.2/7.5/H-1-20] MUST by default output JPEG_R for the primary rear 36 and primary front cameras in the default camera app. 37 """ 38 39 def setup_class(self): 40 super().setup_class() 41 self.dut.services.register( 42 uiautomator.ANDROID_SERVICE_NAME, uiautomator.UiAutomatorService 43 ) 44 45 def on_fail(self, record): 46 super().on_fail(record) 47 self.dut.take_screenshot(self.log_path, prefix='on_test_fail') 48 49 def test_default_camera_launch(self): 50 with its_session_utils.ItsSession( 51 device_id=self.dut.serial, 52 camera_id=self.camera_id, 53 hidden_physical_id=self.hidden_physical_id) as cam: 54 55 device_id = self.dut.serial 56 # Check SKIP conditions 57 first_api_level = its_session_utils.get_first_api_level(self.dut.serial) 58 camera_properties_utils.skip_unless( 59 first_api_level >= its_session_utils.ANDROID15_API_LEVEL and 60 cam.is_primary_camera()) 61 62 # Load chart for scene 63 props = cam.get_camera_properties() 64 its_session_utils.load_scene( 65 cam, props, self.scene, self.tablet, self.chart_distance) 66 67 # Get default camera app pkg name 68 pkg_name = cam.get_default_camera_pkg() 69 logging.debug('Default camera pkg name: %s', pkg_name) 70 71 ui_interaction_utils.default_camera_app_dut_setup(device_id, pkg_name) 72 73 # Launch ItsTestActivity 74 its_device_utils.start_its_test_activity(device_id) 75 device_img_path = ui_interaction_utils.launch_and_take_capture( 76 self.dut, pkg_name) 77 ui_interaction_utils.pull_img_files( 78 device_id, device_img_path, self.log_path) 79 80 # Analyze the captured image 81 gainmap_present = cam.check_gain_map_present(device_img_path) 82 logging.debug('gainmap_present: %s', gainmap_present) 83 84 # Log has_gainmap so that the corresponding MPC level can be written 85 # to report log. Text must match HAS_GAINMAP_PATTERN in 86 # ItsTestActivity.java. 87 # Note: Do not change from print to logging. 88 print(f'has_gainmap:{gainmap_present}') 89 90 # Assert gainmap_present if device claims performance class 91 if (cam.is_vic_performance_class and not gainmap_present): 92 raise AssertionError(f'has_gainmap: {gainmap_present}') 93 94if __name__ == '__main__': 95 test_runner.main() 96