1/** 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 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 16import LogUtils from '../../../main/ets/common/utils/LogUtils'; 17import UserAuthExtensionAbility from '@ohos.app.ability.UserAuthExtensionAbility'; 18import WindowPrivacyUtils from '../../../main/ets/common/utils/WindowPrivacyUtils'; 19import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; 20import { WantParams } from '../../../main/ets/common/vm/Constants'; 21import common from '@ohos.app.ability.common'; 22 23const TAG = 'UserAuthAbility'; 24// The current interface only support string type 25const TRANSPARENT_COLOR = '#00000000'; 26const MASK_THIN_COLOR = '#33182431'; 27 28export default class UserAuthAbility extends UserAuthExtensionAbility { 29 onCreate(): void { 30 LogUtils.info(TAG, 'onCreate'); 31 AppStorage.setOrCreate('context', this.context as common.ExtensionContext); 32 33 } 34 35 onForeground(): void { 36 LogUtils.info(TAG, 'onForeground'); 37 } 38 39 onBackground(): void { 40 LogUtils.info(TAG, 'onBackground'); 41 (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); 42 } 43 44 onDestroy(): void | Promise<void> { 45 LogUtils.info(TAG, 'onDestroy'); 46 } 47 48 onSessionCreate(want, session): void { 49 LogUtils.info(TAG, 'onSessionCreate'); 50 AppStorage.setOrCreate('wantParams', want?.parameters?.useriamCmdData); 51 52 session?.loadContent('pages/Index'); 53 try { 54 if ((AppStorage.get('wantParams') as WantParams)?.windowModeType === 'DIALOG_BOX') { 55 session?.setWindowBackgroundColor(MASK_THIN_COLOR); 56 } else { 57 session?.setWindowBackgroundColor(TRANSPARENT_COLOR); 58 } 59 } catch (error) { 60 LogUtils.error(TAG, 'onSessionCreate error: ' + error?.code); 61 session?.terminateSelf(); 62 } 63 WindowPrivacyUtils.setWindowPrivacyMode(session, true); 64 } 65 66 onSessionDestroy(session): void { 67 LogUtils.info(TAG, 'onSessionDestroy'); 68 WindowPrivacyUtils.setWindowPrivacyMode(session, false); 69 } 70} 71