* 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 { getStates } from '../redux';
import lazy { HiLog } from './HiLog';
const TAG: string = 'FrameLockScene';
const CAMERA_PREVIEW: string = 'CAMERA_PREVIEW';
export class FrameLockScene {
private static sInstance: FrameLockScene;
private mDeliveryState: boolean = false;
public static getInstance(): FrameLockScene {
if (!FrameLockScene.sInstance) {
FrameLockScene.sInstance = new FrameLockScene();
}
return FrameLockScene.sInstance;
}
public backGroundClearScene(): void {
if (this.mDeliveryState !== true) {
HiLog.e(TAG, `backGroundClearScene ret: ${this.mDeliveryState}.`);
return;
}
this.setScene(false);
}
public apsSetScene(sceneName: string, sceneState: boolean): void {
if (!getStates().get<boolean>('contextReducer', 'isForeground')) {
HiLog.e(TAG, `apsSetScene isBackground true ret: ${sceneName}, ${sceneState}.`);
return;
}
let lockSceneName: string = this.getCameraSceneName(sceneName);
let isShowSettingView: boolean = getStates().get<boolean>('settingViewReducer', 'isShowSettingView');
let isOpenTreasureBox: boolean = getStates().get<boolean>('treasureBoxReducer', 'isOpen');
let isShowPhotoBrowser: boolean = AppStorage.get<boolean>('isShowPhotoBrowser');
HiLog.d(TAG, `setApsScene${sceneName},${sceneState}-${isShowSettingView},${isOpenTreasureBox},${isShowPhotoBrowser}|${this.mDeliveryState}.`);
if (lockSceneName === CAMERA_PREVIEW && sceneState && !this.mDeliveryState &&
(isShowSettingView || isOpenTreasureBox || isShowPhotoBrowser)) {
return;
}
if (lockSceneName === CAMERA_PREVIEW && !sceneState && this.mDeliveryState &&
(!isShowSettingView && !isOpenTreasureBox && !isShowPhotoBrowser)) {
return;
}
if (this.getIsInterruptDelivery(lockSceneName, sceneState, isShowSettingView, isOpenTreasureBox,
isShowPhotoBrowser)) {
return;
}
let lockSceneState: boolean = lockSceneName === CAMERA_PREVIEW ? sceneState : !sceneState;
HiLog.d(TAG, `setApsScene start: ${lockSceneName}, ${lockSceneState}.`);
this.setScene(lockSceneState);
}
private getIsInterruptDelivery(lockSceneName: string, sceneState: boolean, isShowSettingView: boolean,
isOpenTreasureBox: boolean, isShowPhotoBrowser: boolean): boolean {
if (lockSceneName === 'CAMERA_SETTING_VIEW' && !sceneState && !this.mDeliveryState &&
(isOpenTreasureBox || isShowPhotoBrowser)) {
return true;
}
if (lockSceneName === 'CAMERA_TREASURE_BOX' && !sceneState && !this.mDeliveryState &&
(isShowSettingView || isShowPhotoBrowser)) {
return true;
}
if (lockSceneName === 'CAMERA_PHOTO_BROWSER' && !sceneState && !this.mDeliveryState &&
(isShowSettingView || isOpenTreasureBox)) {
return true;
}
return false;
}
private setScene(lockSceneState: boolean): void {
if (this.mDeliveryState === lockSceneState) {
HiLog.i(TAG, `setScene isSameState true ret: ${lockSceneState}.`);
return;
}
try {
HiLog.i(TAG, `setScene start: ${CAMERA_PREVIEW}, ${lockSceneState}.`);
this.mDeliveryState = lockSceneState;
} catch (error) {
HiLog.e(TAG, `setScene error: ${error}.`);
}
}
private getCameraSceneName(sceneName: string): string {
switch (sceneName) {
case 'PreviewArea':
case 'PreviewAreaLand':
case 'CAMERA_PREVIEW':
return 'CAMERA_PREVIEW';
case 'SettingView':
return 'CAMERA_SETTING_VIEW';
case 'TreasureBox':
return 'CAMERA_TREASURE_BOX';
case 'PhotoBrowser':
case 'PhotoBrowserLand':
return 'CAMERA_PHOTO_BROWSER';
default:
return '';
}
}
}