* Copyright (c) Huawei Device Co., Ltd. 2024-2025. All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import lazy { HiLog } from '../utils/HiLog';
import camera from '@ohos.multimedia.camera';
import lazy { ModeType } from '../mode/ModeType';
import lazy { FunctionId } from '../function/core/functionproperty/FunctionId';
import lazy {
CameraProfilesJsonUtilV2
} from '../utils/LazyImportUtil';
import lazy { CapabilityInterface } from '../utils/jsonparseutil/CapabilityInterface';
import lazy { OutputType } from '../function/outputswitcher/OutputType';
import lazy { ContextManager } from '../service/context/ContextManager';
import lazy { FeatureManager } from '../function/core/FeatureManager';
import lazy { GlobalContext } from '../utils/GlobalContext';
import lazy { TREASURE_BOX_ORDER } from '../component/treasurebox/common/TreasureBoxOrder';
import { PhotoFormatMode } from '../function/enumbase/PhotoFormatMode';
const TAG: string = 'CameraAppCapability';
* 相机应用能力集查询器,对上屏蔽实现细节:不区分不同版本应用配置获取、相机底层能力上报
*/
export class CameraAppCapability extends CapabilityInterface {
private static sInstanceCapability: CameraAppCapability;
private mCapabilityVersion: string = 'v0';
private mCameraProfilesJsonUtil: CapabilityInterface;
private mCameraDevicesPC: camera.CameraDevice[] = [];
private constructor() {
super();
this.init();
HiLog.i(TAG, 'CameraAppCapability constructor E.');
}
public static getInstance(): CameraAppCapability {
if (!CameraAppCapability.sInstanceCapability) {
CameraAppCapability.sInstanceCapability = new CameraAppCapability();
}
return CameraAppCapability.sInstanceCapability;
}
public init(): boolean {
HiLog.i(TAG, 'init E.');
this.mCameraProfilesJsonUtil = new CameraProfilesJsonUtilV2();
let isSupportedV2 = this.mCameraProfilesJsonUtil.init();
if (isSupportedV2) {
this.mCapabilityVersion = 'v2';
GlobalContext.get().setPhotoBrowserDisabled(this.getPhotoBrowserDisabled());
return;
}
HiLog.i(TAG, 'init X.');
}
public paramAbnormal2MatchCapability(): void {
this.mCameraProfilesJsonUtil.paramAbnormal2MatchCapability();
}
public getPcSupportCameraPosition(): camera.CameraPosition {
const cameraManager = camera.getCameraManager(ContextManager.getInstance().getAbilityStageContext());
this.mCameraDevicesPC = cameraManager.getSupportedCameras();
if (this.mCameraDevicesPC.length >= 1) {
return this.mCameraDevicesPC[0].cameraPosition;
}
return camera.CameraPosition.CAMERA_POSITION_UNSPECIFIED;
}
public getPcCameraOrientation(): number {
if (this.mCameraDevicesPC.length >= 1) {
return this.mCameraDevicesPC[0].cameraOrientation;
}
return 0;
}
public queryCapability(position: camera.CameraPosition, mode: ModeType): void {
HiLog.i(TAG, `queryCapability position: ${position}, mode: ${mode} E.`);
this.mCameraProfilesJsonUtil.queryCapability(position, mode);
HiLog.i(TAG, 'queryCapability X.');
}
public getPhotoProfiles(position: camera.CameraPosition, mode: ModeType, photoFormat: PhotoFormatMode,
isPhysicalLens?: boolean): camera.Profile[] {
return this.mCameraProfilesJsonUtil.getPhotoProfiles(position, mode, photoFormat, isPhysicalLens);
}
public getPhotoPreviewProfiles(position: camera.CameraPosition, mode: ModeType): camera.Profile[] {
return this.mCameraProfilesJsonUtil.getPhotoPreviewProfiles(position, mode);
}
public getVideoProfiles(position: camera.CameraPosition, mode: ModeType, isHdrVivid?: boolean):
camera.VideoProfile[] {
return this.mCameraProfilesJsonUtil.getVideoProfiles(position, mode, isHdrVivid);
}
public getVideoPreviewProfiles(position: camera.CameraPosition, mode: ModeType, isHdrVivid?: boolean):
camera.Profile[] {
return this.mCameraProfilesJsonUtil.getVideoPreviewProfiles(position, mode, isHdrVivid);
}
public getVideoFrameRateArray(position: camera.CameraPosition, mode: ModeType): number[] {
const videoRatio: number = FeatureManager.getInstance().getFunction(FunctionId.VIDEO_RESOLUTION).getValue();
let frameArr = this.mCameraProfilesJsonUtil.getVideoFrameRateArray(position, mode, videoRatio - 1);
if (!frameArr || frameArr.length <= 0) {
frameArr = this.mCameraProfilesJsonUtil.getVideoFrameRateArray(position, ModeType.VIDEO, videoRatio - 1);
}
return frameArr;
}
public is60fpsSupport(position: camera.CameraPosition, mode: ModeType): boolean {
let index = this.getVideoFrameRateArray(position, mode).findIndex((value: number) => {
return value === 60;
});
if (index >= 0) {
return true;
}
return false;
}
public getQuickZoomArray(position: camera.CameraPosition, mode: ModeType, output: OutputType): number[] {
return this.mCameraProfilesJsonUtil.getQuickZoomArray(position, mode, output);
}
public getOpticalZoomArray(position: camera.CameraPosition, mode: ModeType, output: OutputType): number[] {
return this.mCameraProfilesJsonUtil.getOpticalZoomArray(position, mode, output);
}
public getZoomCycleList(mode: ModeType, index: number): number[] {
return this.mCameraProfilesJsonUtil.getZoomCycleList(mode, index);
}
public getModeBarList(): ModeType[] {
return this.mCameraProfilesJsonUtil.getModeBarList();
}
public getMoreModeList(): ModeType[] {
return this.mCameraProfilesJsonUtil.getMoreModeList();
}
public getFilteredModeList(): ModeType[] {
return this.mCameraProfilesJsonUtil.getFilteredModeList();
}
public getPhotoBrowserDisabled(): boolean {
return this.mCameraProfilesJsonUtil.getPhotoBrowserDisabled();
}
public getIsSupportedFrontZoomSlide(): boolean {
return this.mCameraProfilesJsonUtil.getIsSupportedFrontZoomSlide();
}
public getNotSupportedVideo60fpsWide(): boolean {
return this.mCameraProfilesJsonUtil.getNotSupportedVideo60fpsWide();
}
public getIsSupportedHighQualityPhotoFunction(): boolean {
return this.mCameraProfilesJsonUtil.getIsSupportedHighQualityPhotoFunction();
}
public getHighQualityPhotoFuncDefaultValue(): boolean {
return this.mCameraProfilesJsonUtil.getHighQualityPhotoFuncDefaultValue();
}
public getIsSupportedFestivalWatermark(): boolean {
return this.mCameraProfilesJsonUtil.getIsSupportedFestivalWatermark();
}
public getLimitTimeWatermarkDuration(): string {
return this.mCameraProfilesJsonUtil.getLimitTimeWatermarkDuration();
}
public getIsNeedRemoveFlashFunc(): boolean {
return this.mCameraProfilesJsonUtil.getIsNeedRemoveFlashFunc();
}
public getIsSupportedOverHotHidePip(): boolean {
return this.mCameraProfilesJsonUtil.getIsSupportedOverHotHidePip();
}
public getIsSupportedEnhancedBackSelfie(): boolean {
return this.mCameraProfilesJsonUtil.getIsSupportedEnhancedBackSelfie();
}
public getIsSupportedLowAngleShot(): boolean {
return this.mCameraProfilesJsonUtil.getIsSupportedLowAngleShot();
}
public getIsDeviceLowConfig(): boolean {
return this.mCameraProfilesJsonUtil.getIsDeviceLowConfig();
}
public getIsSupportedSmartBackSelfieFunction(): boolean {
return this.mCameraProfilesJsonUtil.getIsSupportedSmartBackSelfieFunction();
}
public getFrontSwingZoomRatio(): number {
return this.mCameraProfilesJsonUtil.getFrontSwingZoomRatio();
}
public getBackSwingZoomRatio(): number {
return this.mCameraProfilesJsonUtil.getBackSwingZoomRatio();
}
public getIsSupportedFrontHighPixelFunction(): boolean {
return this.mCameraProfilesJsonUtil.getIsSupportedFrontHighPixelFunction();
}
public needHidePreviewWhenBackground(): boolean {
return this.mCameraProfilesJsonUtil.needHidePreviewWhenBackground();
}
public getIsNotSupportedEfficientVideoFunction(): boolean {
return this.mCameraProfilesJsonUtil.getIsNotSupportedEfficientVideoFunction();
}
public getIsSupportGlobalExposure(): boolean {
return this.mCameraProfilesJsonUtil.getIsSupportGlobalExposure();
}
public getIsSupportRecordingFlowing(): boolean {
return this.mCameraProfilesJsonUtil.getIsSupportRecordingFlowing();
}
public getIsSupportedFrontSnapShotFunction(): boolean {
return this.mCameraProfilesJsonUtil.getIsSupportedFrontSnapShotFunction();
}
public getIsSupportedEquivalentFocalBigText(): boolean {
return this.mCameraProfilesJsonUtil.getIsSupportedEquivalentFocalBigText();
}
public getIsShowBeautySkinMode(): boolean {
return this.mCameraProfilesJsonUtil?.getIsShowBeautySkinMode();
}
public getVideoBitrateH264(): number {
return this.mCameraProfilesJsonUtil.getVideoBitrateH264();
}
public getVideoBitrateH265(): number {
return this.mCameraProfilesJsonUtil.getVideoBitrateH265();
}
public getIsSupportedEffectWhenNotEnableCapture(): boolean {
return this.mCameraProfilesJsonUtil.getIsSupportedEffectWhenNotEnableCapture();
}
public getIsOnlySupportAccelerometer(): boolean {
return this.mCameraProfilesJsonUtil.getIsOnlySupportAccelerometer();
}
public getIsSupportOnlyShowEye(): boolean {
return this.mCameraProfilesJsonUtil.getIsSupportOnlyShowEye();
}
public getIsNotSupportNearFocus(): boolean {
return this.mCameraProfilesJsonUtil.getIsNotSupportNearFocus();
}
public getIsSupportImmediatelyStopPreview(): boolean {
return this.mCameraProfilesJsonUtil.getIsSupportImmediatelyStopPreview();
}
public getIsNeedFixedBlurRadius(): boolean {
return this.mCameraProfilesJsonUtil.getIsNeedFixedBlurRadius();
}
public getIsSupportEnableStableQuality(): boolean {
return this.mCameraProfilesJsonUtil.getIsSupportEnableStableQuality();
}
public getTreasureBoxOrder(): number[] {
let treasureBoxOrder: number[] = this.mCameraProfilesJsonUtil.getTreasureBoxOrder() ?? TREASURE_BOX_ORDER
return treasureBoxOrder;
}
public getIsNotSupportAudioControl(): boolean {
return this.mCameraProfilesJsonUtil.getIsNotSupportAudioControl();
}
public getStartupGuidancePages(): string[] {
return this.mCameraProfilesJsonUtil.getStartupGuidancePages() ?? [];
}
public getPanGestureZoomVelocity(): number {
return this.mCameraProfilesJsonUtil.getPanGestureZoomVelocity();
}
public getIsSupportStopStreamToMultiTask(): boolean {
return this.mCameraProfilesJsonUtil.getIsSupportStopStreamToMultiTask();
}
public getIsSupportDefault1080PAnd60Fps(): boolean {
return this.mCameraProfilesJsonUtil.getIsSupportDefault1080PAnd60Fps();
}
public getIs60fpsDefaultCloseEfficientVideo(): boolean {
return this.mCameraProfilesJsonUtil.getIs60fpsDefaultCloseEfficientVideo();
}
public getIs60fpsSupportHdrVivid(): boolean {
return this.mCameraProfilesJsonUtil.getIs60fpsSupportHdrVivid();
}
public getIsSupportedFrontSnapShotSkinBeauty(): boolean {
return this.mCameraProfilesJsonUtil.getIsSupportedFrontSnapShotSkinBeauty();
}
public getIsSupportMovieFile(): boolean {
return this.mCameraProfilesJsonUtil.getIsSupportMovieFile();
}
public getIsSuspendPhotoBrowser(): boolean {
return this.mCameraProfilesJsonUtil.getIsSuspendPhotoBrowser();
}
public getIsDisAbleRealTimeLapsePro(): boolean {
return this.mCameraProfilesJsonUtil.getIsDisAbleRealTimeLapsePro();
}
public getIsPickerSupportedPortrait(): boolean {
return this.mCameraProfilesJsonUtil.getIsPickerSupportedPortrait();
}
public getIsSupportedIntervalPhotoCapture(): boolean {
return this.mCameraProfilesJsonUtil.getIsSupportedIntervalPhotoCapture();
}
public getIsSupportedCycleClickZoom(): boolean {
return this.mCameraProfilesJsonUtil.getIsSupportedCycleClickZoom();
}
public getIsDisableFrontVideoMirror(): boolean {
return this.mCameraProfilesJsonUtil.getIsDisableFrontVideoMirror();
}
public getIsNotSupportedWideZoom60fpsVideoBack() : boolean {
return this.mCameraProfilesJsonUtil.getIsNotSupportedWideZoom60fpsVideoBack()
}
public getIsChange3To4Zoom60fpsVideoBack() : boolean {
return this.mCameraProfilesJsonUtil.getIsChange3To4Zoom60fpsVideoBack()
}
public getIsSupportedHighColorSpace() :boolean {
return this.mCameraProfilesJsonUtil.getIsSupportedHighColorSpace();
}
}