class MulticameraApkHelper: MULTI_CAMERA_CONFIG_DICT = { "camera0_input_field": 1, "camera0_input_resolution": 3, "camera0_input_format": 4, "camera0_input_default": 5, "camera0_output_resolution": 0, "camera0_output_format": 2, "camera1_input_field": 7, "camera1_input_resolution": 9, "camera1_input_format": 10, "camera1_input_default": 11, "camera1_output_resolution": 6, "camera1_output_format": 8 } def __init__(self): self.d = g_common_obj.get_device() self.camera_common = CameraCommon() self.get_cfg_file_helper = GetConfigFileHelper( "", "multicamera_apk_helper.conf") self.multimedia_setting = MultiMediaSetting( self.get_cfg_file_helper.cfg_file) need_install_result = self.multimedia_setting.install_apk( "multicamera_apk") if need_install_result: adb32._adb_reboot() time.sleep(15) self.multicamera_apk_package_name, _ = self.multimedia_setting.get_package_and_activity_name( "multicamera_apk") MULTI_CAMERA_PERMISSION_LIST = ["android.permission.CAMERA"] self.camera_common.grantPermission(self.multicamera_apk_package_name, MULTI_CAMERA_PERMISSION_LIST) def launch_multicamera_apk(self): return self.multimedia_setting.launch_apk("multicamera_apk") def stop_multicamera_apk(self): return self.multimedia_setting.stop_apk("multicamera_apk") def set_multicamera_config(self, config_list): logger.debug("set_multicamera_config start. config_list=%s" % config_list) for config_str in config_list: config_item, config_value = config_str.split(":") if config_item not in self.MULTI_CAMERA_CONFIG_DICT.keys(): continue logger.debug("config_item:%s, config_value:%s" % (config_item, config_value)) self.d(className="android.widget.Spinner")[ self.MULTI_CAMERA_CONFIG_DICT[config_item]].click.wait() time.sleep(1) self.d(textContains=config_value).click.wait() time.sleep(1) logger.debug("set_multicamera_config end.")
class CameraTest(CameraTestBase): """ @summary: This test used to test camera function """ MULTI_CAMERA_CONFIG_DICT = {"input_field" : 1 ,"input_resolution" :3 ,"input_format" : 4 ,"input_default" : 5 ,"output_resolution" : 0 ,"output_format" : 2} def setUp(self): """ @summary: set up @return: None """ super(CameraTest, self).setUp() self._test_name = __name__ self.logger.debug("[Setup]: %s" % self._test_name) g_common_obj.root_on_device() self.camera_common = CameraCommon() self.host_path = self.camera_common.getTmpDir() self.rvc_camera = MultiMediaSwitchCameraHelper().camera self.camera_common.removeDeivceFile() self.camera_common.removeFile(self.host_path + "/*") self.camera_common.unlockScreen() self.rvc_camera.skipAccountLoginLyout() self.rvc_camera.backHome() self.d = g_common_obj.get_device() if self.d(text="Got it").exists: self.d(text="Got it").click.wait() self.multimedia_setting = MultiMediaSetting(self.camera_common.DEFAULT_CONFIG_FILE) need_install_result = self.multimedia_setting.install_apk("multi_camera_apk") if need_install_result: self.reboot_device() self.multi_camera_package_name, _ = self.multimedia_setting.get_package_and_activity_name("multi_camera_apk") MULTI_CAMERA_PERMISSION_LIST = ["android.permission.CAMERA"] self.camera_common.grantPermission(self.multi_camera_package_name, MULTI_CAMERA_PERMISSION_LIST) def tearDown(self): """ @summary: tearDown @return: None """ super(CameraTest, self).tearDown() self.logger.debug("[Teardown]: %s" % self._test_name) g_common_obj.stop_exp_handle() self.camera_common.removeDeivceFile() self.camera_common.clean_app_data(self.multi_camera_package_name) time.sleep(3) self.rvc_camera.backHome() def reboot_device(self): self.rvc_camera.pressPowerKey(10) time.sleep(5) self.rvc_camera.pressPowerKey(2) time.sleep(30) g_common_obj.root_on_device() self.camera_common.unlockScreen() self.rvc_camera.backHome() self.check_home_or_lock_layout() def set_multicamera_input_config_format(self, input_config_format): if "multicamera_input_config_format" in os.environ: previous_input_config_format = os.environ["multicamera_input_config_format"] if previous_input_config_format == input_config_format: self.logger.debug("skip set multicamera_input_config_format") return False g_common_obj.adb_cmd("setprop camera.input.config.format %s" % input_config_format) os.environ["multicamera_input_config_format"] = input_config_format self.logger.debug("set multicamera_input_config_format = %s" % input_config_format) return True def launch_multi_camera_apk(self): return self.multimedia_setting.launch_apk("multi_camera_apk") def stop_multi_camera_apk(self): return self.multimedia_setting.stop_apk("multi_camera_apk") def check_home_or_lock_layout(self, check_exist=True): if self.d(text="Got it").exists: self.d(text="Got it").click.wait() assert self.rvc_camera.isHomeLayoutExists() or self.rvc_camera.isLockLayoutExists(), "Home or Lock layout not exist!" def check_logcat_data(self, data_list, fps): self.logger.debug("check_logcat_data data_list=%s" % data_list) for t_fps in data_list: t_fps = float(t_fps) if fps * 0.97 > t_fps or t_fps > fps * 1.03: return False, t_fps return True, 1 def set_multi_camera_config(self, config_list): self.logger.debug("set_multi_camera_config start. config_list=%s" % config_list) for config_str in config_list: config_item, config_value = config_str.split(":") self.logger.debug("config_item:%s, config_value:%s" % (config_item, config_value)) self.d(className="android.widget.Spinner")[self.MULTI_CAMERA_CONFIG_DICT[config_item]].click.wait() time.sleep(1) self.d(textContains=config_value).click.wait() time.sleep(1) self.logger.debug("set_multi_camera_config end.") def check_multi_camera(self, input_size, output_size): config_list = ["input_field:interlaced" ,"input_resolution:%s" % input_size ,"input_format:default" ,"input_default:HW_Weaving" ,"output_resolution:%s" % output_size ,"output_format:NV21" ] self.set_multicamera_input_config_format("uyvy") self.launch_multi_camera_apk() self.set_multi_camera_config(config_list) self.d(textContains="Camera0:OFF").click.wait() time.sleep(10) self.camera_common.checkCameraCrash() assert self.d(packageName="com.example.tim.multicamera").exists, "Can't find multicamera in layout, maybe apk crashed." self.stop_multi_camera_apk() def check_multi_camera_with_fps(self, input_size, output_size): config_list = ["input_field:interlaced" ,"input_resolution:%s" % input_size ,"input_format:default" ,"input_default:HW_Weaving" ,"output_resolution:%s" % output_size ,"output_format:NV21" ] expect_fps = 50 self.set_multicamera_input_config_format("uyvy") self.launch_multi_camera_apk() self.set_multi_camera_config(config_list) g_common_obj.adb_cmd("setprop camera.hal.perf 3") time.sleep(2) self.d(textContains="Camera0:OFF").click.wait() self.camera_common.checkCameraCrash() self.multimedia_logcat_helper = MultiMediaLogcatHelper("adb logcat CameraHardwareSoc:D *:S") self.multimedia_logcat_helper.get_logcat_data_start() time.sleep(5*60) result_list = self.multimedia_logcat_helper.get_logcat_data_end("total fps is (.*),") check_logcat_data_result, error_fps = self.check_logcat_data(result_list, expect_fps) assert check_logcat_data_result, "Fps error! error_fps=%s, expect_fps=%s, result_list=%s" % (error_fps, expect_fps, result_list) self.camera_common.checkCameraCrash() self.stop_multi_camera_apk() def test_Camera_Scale_AVM737_720x480_to_1280x720(self): self.check_multi_camera("720x480", "1280x720") def test_Camera_Scale_AVM737_720x480_to_1920x1080(self): self.check_multi_camera("720x480", "1920x1080") def test_Camera_Scale_AVM737_720x480_to_640x480(self): self.check_multi_camera("720x480", "640x480") def test_Camera_Scale_AVM737_720x480_to_720x480(self): self.check_multi_camera("720x480", "720x480") def test_Camera_Scale_AVM737_720x480_to_320x240(self): self.check_multi_camera("720x480", "320x240") def test_Camera_Scale_AVM737_720x480_to_176x144(self): self.check_multi_camera("720x480", "176x144") def test_Camera_Scale_AVM737_720x480_to_1280x720_50fps(self): self.check_multi_camera_with_fps("720x480", "1280x720") def test_Camera_Scale_AVM737_720x480_to_1920x1080_50fps(self): self.check_multi_camera_with_fps("720x480", "1920x1080") def test_Camera_Scale_AVM737_720x480_to_640x480_50fps(self): self.check_multi_camera_with_fps("720x480", "640x480") def test_Camera_Scale_AVM737_720x480_to_720x480_50fps(self): self.check_multi_camera_with_fps("720x480", "720x480") def test_Camera_Scale_TP_UYVY_640x480_Progressive_fps_60(self): pass
class RefCamCamera(CameraAppInterface, CameraTestBase): PACKAGE_NAME_REFCAMCAMERA = "com.intel.refcam" ACTIVITY_NAME_REFCAMCAMERA = ".CameraActivity" PERMISSION_LIST = [ "android.permission.ACCESS_FINE_LOCATION", "android.permission.CAMERA", "android.permission.WRITE_EXTERNAL_STORAGE", "android.permission.READ_EXTERNAL_STORAGE", "android.permission.RECORD_AUDIO" ] def __init__(self, cfg=None): if cfg == None: self.cfg = self.config.read(CameraCommon.DEFAULT_CONFIG_FILE, "multimedia_camera") else: self.cfg = cfg self.d = g_common_obj.get_device() self.logger = CameraLogger.instance() self.x = self.d.info["displayWidth"] self.y = self.d.info["displayHeight"] self.camera_widget = self.CameraWidget() self.camera_common = CameraCommon() self.multimedia_setting = MultiMediaSetting( self.camera_common.DEFAULT_CONFIG_FILE) self.multimedia_setting.install_apk("ref_camera_1_apk") self.camera_common.grantPermission(self.PACKAGE_NAME_REFCAMCAMERA, self.PERMISSION_LIST) class CameraWidget: def __init__(self): self.d = g_common_obj.get_device() def frontback(self): ''' front back button ''' return self.d(resourceId="com.intel.refcam:id/switch_frontback") def itemChildMenu(self): ''' item clild menu ''' return self.d( resourceId="com.intel.refcam:id/setting_item_child_menu_text") def seekBar(self): ''' menu seek bar ''' return self.d( resourceId="com.intel.refcam:id/setting_item_child_menu_seekbar" ) def shutterBtn(self): ''' shutter button ''' return self.d(resourceId="com.intel.refcam:id/shutter") def shotlist(self): ''' front back button ''' return self.d(resourceId="com.intel.refcam:id/open_shot_list") def settingsBtn(self): ''' settings ''' return self.d(resourceId="com.intel.refcam:id/setting") def text(self, _text): ''' page text ''' return self.d(textContains=_text) def itemChildMenuText(self, _text): ''' page text ''' return self.d( resourceId="com.intel.refcam:id/setting_item_child_menu_text", textContains=_text) def zoomLayer(self): ''' zoom layer ''' return self.d(resourceId="com.intel.refcam:id/zoom_layer") #============================================================= def clickScreen(self): d = g_common_obj.get_device() x = d.info["displayWidth"] self.camera_common.clickBtn(x - 100, 300) def isShutterBtnExists(self): return self.camera_common.isWidgetExists( self.camera_widget.shutterBtn()) def setCaptureMode(self, value): self.camera_common.waitForWidgetToAppear(self.camera_widget.shotlist(), "mode button") self.camera_widget.shotlist().click.wait() self.camera_widget.text(value).click.wait() self.logger.debug("set capture mode to %s successfully" % value) self.camera_common.clickScreenCenter() #------------------------------------------------------------ # Interfaces' implementations are from here def cleanMediaFiles(self): """ Used to clean the media files in some folders; eg. /mnt/sdcard/DCIM/Camera """ self.logger.debug("clean media files start") g_common_obj.stop_app_am(self.PACKAGE_NAME_REFCAMCAMERA) g_common_obj.adb_cmd("pm clear %s" % self.PACKAGE_NAME_REFCAMCAMERA) self.logger.debug("clean media files successfully") def startCameraApp(self): """ Used to start the camera application """ self.camera_common.unlockScreen() self.logger.debug("launch refcam2 camera start") os.system( "adb shell am start -S %s/%s" % (self.PACKAGE_NAME_REFCAMCAMERA, self.ACTIVITY_NAME_REFCAMCAMERA)) time_left = 0 start = time.time() success = False while time_left < self.camera_common.waitStartAppTime + 15: if self.isShutterBtnExists() or self.camera_widget.shotlist( ).exists: success = True break if self.camera_widget.text( "Allow").exists or self.camera_widget.text("ALLOW").exists: self.camera_common.checkGuide() if self.camera_common.getAndroidVersion() == "N": self.stopCameraApp() os.system("adb shell am start -S %s/%s" % (self.PACKAGE_NAME_REFCAMCAMERA, self.ACTIVITY_NAME_REFCAMCAMERA)) time_left = time.time() - start time.sleep(0.5) self.camera_common.checkCameraCrash() if (not success ) or time_left > self.camera_common.waitStartAppTime + 15: scname = g_common_obj.get_user_log_dir() + "/assert.png" g_common_obj.take_screenshot(scname) assert False, "refcam2 camera launch fail,launch time is greater than " \ + str(self.camera_common.waitStartAppTime + 15) + " seconds" self.logger.debug("launch refcam2 camera successfully") def stopCameraApp(self): """ Used to stop the camera application """ g_common_obj.stop_app_am(self.PACKAGE_NAME_REFCAMCAMERA) self.logger.debug("stop arcsoft camera app successfully") def selectMode(self, mode="Camera"): """ Used to select a mode such as camera, video, panorama, lens blur, photo sphere and so on... """ self.camera_common.waitForWidgetToAppear( self.camera_widget.shutterBtn(), "shutter button") self.camera_widget.shotlist().click.wait() self.camera_widget.text(mode).click.wait() self.camera_common.clickScreenCenter() self.logger.debug("Change to %s mode" % mode) def switchRearOrFront(self, lens="Back"): """ Used to switch rear or front camera lens = Back / Front """ self.camera_common.waitForWidgetToAppear( self.camera_widget.shutterBtn(), "shutter button") if lens == "Front": self.camera_widget.frontback().click.wait() self.logger.debug("change to " + str(lens) + " camera") if lens == "Back" or lens == "Rear": self.logger.debug("change to " + str(lens) + " camera") time.sleep(2) def setExposure(self, value): pass def setFlash(self, flash="off"): """ Used to control the flash; on, off, auto """ pass def setGrid(self, grid="off"): """ Used to control the grid; on, off """ pass def setTimer(self, timer="off"): """ Used to control the timer value: off/2s/3s/10s """ pass def getAllVideoResolutions(self, lens): """ Return all of the video resolutions """ pass def setVideoResolution(self, resolution, lens): """ Used to control the video resolution, used with the getAllVideoResolutions """ pass def getAllCameraMode(self): pass def getAllPhotoResolutions(self, lens, type="Capture Size (JPEG)"): """ Return all of the photo resolutions """ self.camera_common.waitForWidgetToAppear( self.camera_widget.settingsBtn(), "setting button") self.camera_widget.settingsBtn().click.wait() if not self.camera_widget.text(type).exists: self.d(scrollable=True).scroll.vert.to(textContains=type) self.camera_common.waitForWidgetToAppear(self.camera_widget.text(type), "capture size button") self.camera_widget.text(type).click.wait() mCount = self.camera_widget.itemChildMenu().count mList = [] for i in range(mCount): mList.append(self.camera_widget.itemChildMenu()[i].info["text"]) self.clickScreen() self.logger.debug("mList=%s" % mList) if mList == []: self.logger.debug( "can't find photo resolutions with \"%s\" type!" % type) return [], -1, -1 else: return mList, mList[0], mList[mCount - 1] def setSettingsButton(self, main_click_button, sub_click_button): self.camera_common.waitForWidgetToAppear( self.camera_widget.settingsBtn(), "setting button") self.camera_widget.settingsBtn().click.wait() if not self.camera_widget.text(main_click_button).exists: self.d(scrollable=True).scroll.vert.to( textContains=main_click_button) self.camera_common.waitForWidgetToAppear( self.camera_widget.text(main_click_button), "click main button: %s" % main_click_button) self.camera_widget.text(main_click_button).click.wait() self.camera_widget.itemChildMenuText(sub_click_button).click.wait() self.logger.debug("click sub button: %s" % sub_click_button) self.clickScreen() def setPhotoResolution(self, resolution, lens, type="Capture Size (JPEG)"): """ Used to control the photo resolution, used with the getAllPhotoResolutions """ self.camera_common.waitForWidgetToAppear( self.camera_widget.settingsBtn(), "setting button") self.camera_widget.settingsBtn().click.wait() if not self.camera_widget.text(type).exists: self.d(scrollable=True).scroll.vert.to(textContains=type) self.camera_common.waitForWidgetToAppear(self.camera_widget.text(type), "capture size button") self.camera_widget.text(type).click.wait() self.camera_widget.itemChildMenuText(resolution).click.wait() self.logger.debug("set resolution to " + resolution) self.clickScreen() def capturePhoto(self, num=1, generated=True): """ Used to capture num photos """ self.camera_common.waitForWidgetToAppear( self.camera_widget.shutterBtn(), "shutter button") for i in range(int(num)): if self.camera_widget.shutterBtn().exists: self.camera_widget.shutterBtn().click.wait() self.logger.debug("capture photo %d" % (i + 1)) if generated: self.camera_common.waitForTheFilesAreGenerated() time.sleep(1.5) else: self.camera_common.checkCameraCrash() def reviewPhoto(self, num=1): """ Used to review num photos """ pass def reviewPhotoAndVideo(self, num=1, timeout=10): """ Used to review num photos """ pass def recordVideo(self, videoNum=1, duration=5): """ Used to capture num duration videos """ pass def reviewVideo(self, num=1, duration=1): """ Used to review num duration videos """ pass def snapShotDuringVideo(self, videoNum=1, duration=5, snapShotNum=1): """ Used to snapshot num pictures during a duration videos """ pass